kernel: 5.15: update Aquantia PHY driver to v6.1 code
[openwrt/openwrt.git] / target / linux / generic / backport-5.15 / 790-v6.0-net-mii-add-mii_bmcr_encode_fixed.patch
1 From bdb6cfe7512f7a214815a3092f0be50963dcacbc Mon Sep 17 00:00:00 2001
2 From: "Russell King (Oracle)" <rmk+kernel@armlinux.org.uk>
3 Date: Sat, 18 Jun 2022 11:28:32 +0100
4 Subject: [PATCH] net: mii: add mii_bmcr_encode_fixed()
5
6 Add a function to encode a fixed speed/duplex to a BMCR value.
7
8 Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
9 Signed-off-by: David S. Miller <davem@davemloft.net>
10 ---
11 include/linux/mii.h | 35 +++++++++++++++++++++++++++++++++++
12 1 file changed, 35 insertions(+)
13
14 --- a/include/linux/mii.h
15 +++ b/include/linux/mii.h
16 @@ -595,4 +595,39 @@ static inline u8 mii_resolve_flowctrl_fd
17 return cap;
18 }
19
20 +/**
21 + * mii_bmcr_encode_fixed - encode fixed speed/duplex settings to a BMCR value
22 + * @speed: a SPEED_* value
23 + * @duplex: a DUPLEX_* value
24 + *
25 + * Encode the speed and duplex to a BMCR value. 2500, 1000, 100 and 10 Mbps are
26 + * supported. 2500Mbps is encoded to 1000Mbps. Other speeds are encoded as 10
27 + * Mbps. Unknown duplex values are encoded to half-duplex.
28 + */
29 +static inline u16 mii_bmcr_encode_fixed(int speed, int duplex)
30 +{
31 + u16 bmcr;
32 +
33 + switch (speed) {
34 + case SPEED_2500:
35 + case SPEED_1000:
36 + bmcr = BMCR_SPEED1000;
37 + break;
38 +
39 + case SPEED_100:
40 + bmcr = BMCR_SPEED100;
41 + break;
42 +
43 + case SPEED_10:
44 + default:
45 + bmcr = BMCR_SPEED10;
46 + break;
47 + }
48 +
49 + if (duplex == DUPLEX_FULL)
50 + bmcr |= BMCR_FULLDPLX;
51 +
52 + return bmcr;
53 +}
54 +
55 #endif /* __LINUX_MII_H__ */