author: Russell King (Oracle) <rmk+kernel@armlinux.org.uk> 2022-06-18 11:28:32 +0100
committer: Genevieve Chan <genevieve.chan@starfivetech.com> 2022-11-03 22:07:04 +0800
commit: 6d584f9d559a5322e3287287cd25edbc6835b653
parent: 972c49717ff4894bf3813aba15d8a8d7ba23f035
Commit Summary:
Diffstat:
1 file changed, 30 insertions, 0 deletions
diff --git a/include/linux/mii.h b/include/linux/mii.h
index 12ea29e04293..599b56766a51 100644
--- a/include/linux/mii.h
+++ b/include/linux/mii.h
@@ -595,4 +595,39 @@ static inline u8 mii_resolve_flowctrl_fdx(u16 lcladv, u16 rmtadv)
return cap;
}
+/**
+ * mii_bmcr_encode_fixed - encode fixed speed/duplex settings to a BMCR value
+ * @speed: a SPEED_* value
+ * @duplex: a DUPLEX_* value
+ *
+ * Encode the speed and duplex to a BMCR value. 2500, 1000, 100 and 10 Mbps are
+ * supported. 2500Mbps is encoded to 1000Mbps. Other speeds are encoded as 10
+ * Mbps. Unknown duplex values are encoded to half-duplex.
+ */
+static inline u16 mii_bmcr_encode_fixed(int speed, int duplex)
+{
+ u16 bmcr;
+
+ switch (speed) {
+ case SPEED_2500:
+ case SPEED_1000:
+ bmcr = BMCR_SPEED1000;
+ break;
+
+ case SPEED_100:
+ bmcr = BMCR_SPEED100;
+ break;
+
+ case SPEED_10:
+ default:
+ bmcr = BMCR_SPEED10;
+ break;
+ }
+
+ if (duplex == DUPLEX_FULL)
+ bmcr |= BMCR_FULLDPLX;
+
+ return bmcr;
+}
+
#endif /* __LINUX_MII_H__ */