Add ethtool to mii advertisment conversion helpers
Subsystems (5)
PATCH v2 1/1 Add ethtool to mii advertisment conversion helpers
Translating between ethtool advertisement settings and MII advertisements are common operations for ethernet drivers. This patch adds a set of helper functions that implements the conversion. The patch then modifies a couple of the drivers to use the new functions.
---
Changes in V2:
* Added '#include <linux/ethtool.h>' to mii.h
drivers/net/ethernet/broadcom/bnx2.c | 15 +--- drivers/net/ethernet/broadcom/tg3.c | 53 +++-------- drivers/net/ethernet/sun/niu.c | 15 +--- drivers/net/mii.c | 48 ++-------- drivers/net/phy/phy_device.c | 20 +---- include/linux/mii.h | 166 ++++++++++++++++++++++++++++++++++ 6 files changed, 197 insertions(+), 120 deletions(-)
drivers/net/ethernet/broadcom/bnx2.c +3 -12
@@ -2064,21 +2064,12 @@ __acquires(&bp->phy_lock)bnx2_read_phy (bp,MII_CTRL1000 , &adv1000_reg); adv1000_reg &=PHY_ALL_1000_SPEED ; -if (bp->advertising & ADVERTISED_10baseT_Half) - new_adv_reg |=ADVERTISE_10HALF ; -if (bp->advertising & ADVERTISED_10baseT_Full) - new_adv_reg |=ADVERTISE_10FULL ; -if (bp->advertising & ADVERTISED_100baseT_Half) - new_adv_reg |=ADVERTISE_100HALF ; -if (bp->advertising & ADVERTISED_100baseT_Full) - new_adv_reg |=ADVERTISE_100FULL ; -if (bp->advertising & ADVERTISED_1000baseT_Full) - new_adv1000_reg |=ADVERTISE_1000FULL ; - + new_adv_reg =ethtool_adv_to_mii_100bt (bp->advertising); new_adv_reg |=ADVERTISE_CSMA ; - new_adv_reg |=bnx2_phy_get_pause_adv (bp); + new_adv1000_reg |=ethtool_adv_to_mii_1000T (bp->advertising); +if ((adv1000_reg != new_adv1000_reg) || (adv_reg != new_adv_reg) || ((bmcr &BMCR_ANENABLE ) ==0 )) {
drivers/net/ethernet/broadcom/tg3.c +13 -40
87 lines not on this page · raw message
drivers/net/ethernet/sun/niu.c +2 -13
@@ -1151,19 +1151,8 @@ static int link_status_mii(struct niu *np, int *link_up_p) supported |= SUPPORTED_1000baseT_Full; lp->supported = supported; - advertising =0 ; -if (advert &ADVERTISE_10HALF ) - advertising |= ADVERTISED_10baseT_Half; -if (advert &ADVERTISE_10FULL ) - advertising |= ADVERTISED_10baseT_Full; -if (advert &ADVERTISE_100HALF ) - advertising |= ADVERTISED_100baseT_Half; -if (advert &ADVERTISE_100FULL ) - advertising |= ADVERTISED_100baseT_Full; -if (ctrl1000 &ADVERTISE_1000HALF ) - advertising |= ADVERTISED_1000baseT_Half; -if (ctrl1000 &ADVERTISE_1000FULL ) - advertising |= ADVERTISED_1000baseT_Full; + advertising =mii_adv_to_ethtool_100bt (advert); + advertising |=mii_adv_to_ethtool_1000T (ctrl1000);if (bmcr &BMCR_ANENABLE ) {int neg, neg1000;
drivers/net/mii.c +10 -38
69 lines not on this page · raw message
drivers/net/phy/phy_device.c +3 -17
@@ -563,20 +563,9 @@ static int genphy_config_advert(struct phy_device *phydev)if (adv <0 )return adv; - adv &= ~(ADVERTISE_ALL |ADVERTISE_100BASE4 |ADVERTISE_PAUSE_CAP | + adv &= ~(ADVERTISE_ALL |ADVERTISE_100BASE4 |ADVERTISE_PAUSE_CAP |ADVERTISE_PAUSE_ASYM ); -if (advertise & ADVERTISED_10baseT_Half) - adv |=ADVERTISE_10HALF ; -if (advertise & ADVERTISED_10baseT_Full) - adv |=ADVERTISE_10FULL ; -if (advertise & ADVERTISED_100baseT_Half) - adv |=ADVERTISE_100HALF ; -if (advertise & ADVERTISED_100baseT_Full) - adv |=ADVERTISE_100FULL ; -if (advertise & ADVERTISED_Pause) - adv |=ADVERTISE_PAUSE_CAP ; -if (advertise & ADVERTISED_Asym_Pause) - adv |=ADVERTISE_PAUSE_ASYM ; + adv |=ethtool_adv_to_mii_100bt (advertise);if (adv != oldadv) { err =phy_write (phydev,MII_ADVERTISE , adv);
@@ -595,10 +584,7 @@ static int genphy_config_advert(struct phy_device *phydev)return adv; adv &= ~(ADVERTISE_1000FULL |ADVERTISE_1000HALF ); -if (advertise & SUPPORTED_1000baseT_Half) - adv |=ADVERTISE_1000HALF ; -if (advertise & SUPPORTED_1000baseT_Full) - adv |=ADVERTISE_1000FULL ; + adv |=ethtool_adv_to_mii_1000T (advertise);if (adv != oldadv) { err =phy_write (phydev,MII_CTRL1000 , adv);
include/linux/mii.h +166 -0
178 lines not on this page · raw message
Signature · 1 line
1.7.3.4
David Miller
maintainerFrom: "Matt Carlson" <[email protected]>
Date: Wed, 16 Nov 2011 15:27:37 -0800
Quoted 7 lines
Translating between ethtool advertisement settings and MII advertisements are common operations for ethernet drivers. This patch adds a set of helper functions that implements the conversion. The patch then modifies a couple of the drivers to use the new functions.
Signed-off-by Matt Carlson <[email protected]>Signed-off-by Michael Chan <[email protected]>
Looks better, applied, thanks :)
Quoted 8 lines · David Miller
From: "Matt Carlson" <[email protected]>
Date: Wed, 16 Nov 2011 15:27:37 -0800Quoted 5 lines
Translating between ethtool advertisement settings and MII advertisements are common operations for ethernet drivers. This patch adds a set of helper functions that implements the conversion. The patch then modifies a couple of the drivers to use the new functions.
Quoted 4 lines
Quoted 2 lines
Signed-off-by Matt Carlson <[email protected]>Signed-off-by Michael Chan <[email protected]>Looks better, applied, thanks :)
For an unknown reason I had to revert this commit to make my tg3 working again on my laptop connected with a cross cable to one IGB NIC.
Before my revert, link was constantly flapping
(Should be running at 1000Mbps, full duplex)
09:00.0 Ethernet controller: Broadcom Corporation NetXtreme BCM5755M Gigabit Ethernet PCI Express (rev 02)
Subsystem: Dell Device 01f9
Control: I/O- Mem+ BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR+ FastB2B- DisINTx+
Status: Cap+ 66MHz- UDF- FastB2B- ParErr- DEVSEL=fast >TAbort- <TAbort- <MAbort- >SERR- <PERR- INTx-
Latency: 0, Cache Line Size: 64 bytes
Interrupt: pin A routed to IRQ 45
Region 0: Memory at f1ef0000 (64-bit, non-prefetchable) [size=64K]
Expansion ROM at <ignored> [disabled]
Capabilities: [48] Power Management version 3
Flags: PMEClk- DSI- D1- D2- AuxCurrent=0mA PME(D0-,D1-,D2-,D3hot+,D3cold+)
Status: D0 NoSoftRst+ PME-Enable- DSel=0 DScale=1 PME-
Capabilities: [50] Vital Product Data
Product Name: Broadcom NetXtreme Gigabit Ethernet Controller
Read-only fields:
[PN] Part number: BCM95755m
[EC] Engineering changes: 01f9.004
[SN] Serial number: 0123456789
[MN] Manufacture ID: 31 34 65 34
[RV] Reserved: checksum good, 28 byte(s) reserved
Read/write fields:
[YA] Asset tag: XYZ01234567
[RW] Read-write area: 107 byte(s) free
End
Capabilities: [58] Vendor Specific Information: Len=78 <?>
Capabilities: [e8] MSI: Enable+ Count=1/1 Maskable- 64bit+
Address: 00000000fee0300c Data: 41b1
Capabilities: [d0] Express (v1) Endpoint, MSI 00
DevCap: MaxPayload 128 bytes, PhantFunc 0, Latency L0s <4us, L1 unlimited
ExtTag+ AttnBtn- AttnInd- PwrInd- RBE+ FLReset-
DevCtl: Report errors: Correctable- Non-Fatal- Fatal- Unsupported-
RlxdOrd- ExtTag- PhantFunc- AuxPwr- NoSnoop-
MaxPayload 128 bytes, MaxReadReq 4096 bytes
DevSta: CorrErr+ UncorrErr- FatalErr- UnsuppReq- AuxPwr+ TransPend-
LnkCap: Port #0, Speed 2.5GT/s, Width x1, ASPM L0s L1, Latency L0 <4us, L1 <64us
ClockPM+ Surprise- LLActRep- BwNot-
LnkCtl: ASPM L0s Enabled; RCB 64 bytes Disabled- Retrain- CommClk+
ExtSynch- ClockPM+ AutWidDis- BWInt- AutBWInt-
LnkSta: Speed 2.5GT/s, Width x1, TrErr- Train- SlotClk+ DLActive- BWMgmt- ABWMgmt-
Capabilities: [100 v1] Advanced Error Reporting
UESta: DLP- SDES- TLP- FCP- CmpltTO+ CmpltAbrt- UnxCmplt- RxOF- MalfTLP- ECRC- UnsupReq- ACSViol-
UEMsk: DLP- SDES- TLP- FCP- CmpltTO- CmpltAbrt- UnxCmplt- RxOF- MalfTLP- ECRC- UnsupReq- ACSViol-
UESvrt: DLP+ SDES- TLP- FCP+ CmpltTO- CmpltAbrt- UnxCmplt- RxOF+ MalfTLP+ ECRC- UnsupReq- ACSViol-
CESta: RxErr+ BadTLP+ BadDLLP+ Rollover- Timeout+ NonFatalErr+
CEMsk: RxErr- BadTLP- BadDLLP- Rollover- Timeout- NonFatalErr+
AERCap: First Error Pointer: 0e, GenCap+ CGenEn- ChkCap+ ChkEn-
Capabilities: [13c v1] Virtual Channel
Caps: LPEVC=0 RefClk=100ns PATEntryBits=1
Arb: Fixed- WRR32- WRR64- WRR128-
Ctrl: ArbSelect=Fixed
Status: InProgress-
VC0: Caps: PATOffset=00 MaxTimeSlots=1 RejSnoopTrans-
Arb: Fixed- WRR32- WRR64- WRR128- TWRR128- WRR256-
Ctrl: Enable+ ID=0 ArbSelect=Fixed TC/VC=01
Status: NegoPending- InProgress-
Capabilities: [160 v1] Device Serial Number 00-21-70-ff-fe-b0-e4-89
Capabilities: [16c v1] Power Budgeting <?>
Kernel driver in use: tg3
Kernel modules: tg3
For reference, the revert on tg3 :
drivers/net/ethernet/broadcom/tg3.c +40 -13
@@ -3594,7 +3594,15 @@ static int tg3_phy_autoneg_cfg(struct tg3 *tp, u32 advertise, u32 flowctrl)u32 val, new_adv; new_adv =ADVERTISE_CSMA ; - new_adv |=ethtool_adv_to_mii_100bt (advertise); +if (advertise & ADVERTISED_10baseT_Half) + new_adv |=ADVERTISE_10HALF ; +if (advertise & ADVERTISED_10baseT_Full) + new_adv |=ADVERTISE_10FULL ; +if (advertise & ADVERTISED_100baseT_Half) + new_adv |=ADVERTISE_100HALF ; +if (advertise & ADVERTISED_100baseT_Full) + new_adv |=ADVERTISE_100FULL ; + new_adv |=tg3_advert_flowctrl_1000T (flowctrl); err =tg3_writephy (tp,MII_ADVERTISE , new_adv);
@@ -3604,7 +3612,11 @@ static int tg3_phy_autoneg_cfg(struct tg3 *tp, u32 advertise, u32 flowctrl)if (tp->phy_flags &TG3_PHYFLG_10_100_ONLY ) goto done; - new_adv =ethtool_adv_to_mii_1000T (advertise); + new_adv =0 ; +if (advertise & ADVERTISED_1000baseT_Half) + new_adv |=ADVERTISE_1000HALF ; +if (advertise & ADVERTISED_1000baseT_Full) + new_adv |=ADVERTISE_1000FULL ;if (tp->pci_chip_rev_id ==CHIPREV_ID_5701_A0 || tp->pci_chip_rev_id ==CHIPREV_ID_5701_B0 )
@@ -3778,7 +3790,14 @@ static int tg3_copper_is_advertising_all(struct tg3 *tp, u32 mask) {u32 adv_reg, all_mask =0 ; - all_mask =ethtool_adv_to_mii_100bt (mask); +if (mask & ADVERTISED_10baseT_Half) + all_mask |=ADVERTISE_10HALF ; +if (mask & ADVERTISED_10baseT_Full) + all_mask |=ADVERTISE_10FULL ; +if (mask & ADVERTISED_100baseT_Half) + all_mask |=ADVERTISE_100HALF ; +if (mask & ADVERTISED_100baseT_Full) + all_mask |=ADVERTISE_100FULL ;if (tg3_readphy (tp,MII_ADVERTISE , &adv_reg))return 0 ;
@@ -3789,7 +3808,11 @@ static int tg3_copper_is_advertising_all(struct tg3 *tp, u32 mask)if (!(tp->phy_flags &TG3_PHYFLG_10_100_ONLY )) {u32 tg3_ctrl; - all_mask =ethtool_adv_to_mii_1000T (mask); + all_mask =0 ; +if (mask & ADVERTISED_1000baseT_Half) + all_mask |=ADVERTISE_1000HALF ; +if (mask & ADVERTISED_1000baseT_Full) + all_mask |=ADVERTISE_1000FULL ;if (tg3_readphy (tp,MII_CTRL1000 , &tg3_ctrl))return 0 ;
@@ -4880,19 +4903,23 @@ static int tg3_setup_fiber_mii_phy(struct tg3 *tp, int force_reset) (tp->phy_flags & TG3_PHYFLG_PARALLEL_DETECT)) {/* do nothing, just check for link up at the end */ } else if (tp->link_config.autoneg == AUTONEG_ENABLE) { -u32 adv, newadv; +u32 adv, new_adv; err |=tg3_readphy (tp,MII_ADVERTISE , &adv); - newadv = adv & ~(ADVERTISE_1000XFULL |ADVERTISE_1000XHALF | -ADVERTISE_1000XPAUSE | -ADVERTISE_1000XPSE_ASYM | -ADVERTISE_SLCT ); + new_adv = adv & ~(ADVERTISE_1000XFULL |ADVERTISE_1000XHALF | +ADVERTISE_1000XPAUSE | +ADVERTISE_1000XPSE_ASYM | +ADVERTISE_SLCT ); + + new_adv |=tg3_advert_flowctrl_1000X (tp->link_config.flowctrl); - newadv |=tg3_advert_flowctrl_1000X (tp->link_config.flowctrl); - newadv |=ethtool_adv_to_mii_1000X (tp->link_config.advertising); +if (tp->link_config.advertising & ADVERTISED_1000baseT_Half) + new_adv |=ADVERTISE_1000XHALF ; +if (tp->link_config.advertising & ADVERTISED_1000baseT_Full) + new_adv |=ADVERTISE_1000XFULL ; -if ((newadv != adv) || !(bmcr &BMCR_ANENABLE )) { -tg3_writephy (tp,MII_ADVERTISE , newadv); +if ((new_adv != adv) || !(bmcr &BMCR_ANENABLE )) { +tg3_writephy (tp,MII_ADVERTISE , new_adv); bmcr |=BMCR_ANENABLE |BMCR_ANRESTART ;tg3_writephy (tp,MII_BMCR , bmcr);
David Miller
maintainerFrom: Eric Dumazet <[email protected]>
Date: Sun, 20 Nov 2011 22:11:37 +0100
Quoted 12 lines
For reference, the revert on tg3 :
drivers/net/ethernet/broadcom/tg3.c +1
-1@@ -3594,7 +3594,15 @@ static int tg3_phy_autoneg_cfg(struct tg3 *tp, u32 advertise, u32 flowctrl)u32 val, new_adv; new_adv =ADVERTISE_CSMA ; - new_adv |=ethtool_adv_to_mii_100bt (advertise); +if (advertise & ADVERTISED_10baseT_Half)
drivers/net/ethernet/broadcom/tg3.c static int tg3_phy_autoneg_cfg(struct tg3 *tp, u32 advertise, u32 flowctrl) · line 3607
Quoted 10 lines
drivers/net/ethernet/broadcom/tg3.c +8
-0+ new_adv |=ADVERTISE_10HALF ; +if (advertise & ADVERTISED_10baseT_Full) + new_adv |=ADVERTISE_10FULL ; +if (advertise & ADVERTISED_100baseT_Half) + new_adv |=ADVERTISE_100HALF ; +if (advertise & ADVERTISED_100baseT_Full) + new_adv |=ADVERTISE_100FULL ; + new_adv |=tg3_advert_flowctrl_1000T (flowctrl);
Well, for one thing the flow control handling is subtly changed here.
ethtool_adv_to_mii_100bt() does it's own setting of the flow control advertisement bits. It sets ADVERTISE_PAUSE_CAP and ADVERTISE_PAUSE_ASYM.
But here in tg3, tg3_advert_flowctrl_1000T() has it's own seperate logic for setting those bits.
I cannot say for certain that this is what it causing your problems, but it is clear now that these transformations were not done carefully enough.