r8169: implement get_module functions for rtl8127atf
PATCH 1/1 r8169: implement get_module functions for rtl8127atf
Implement get_module_info and get_module_eeprom for supported devices, right now that's the rtl8127atf.
This enables using ethtool to retrieve the transceiver identification and diagnostic data.
---
Hi,
Realtek released a new out of tree driver for the rtl8127 and it includes some code that exposes the I2C controller connected to the SFP port.
This patch implements get_module_info and get_module_eeprom based on the information found on that driver, it allows ethtool to fetch the SFP module information, which is useful both to identify the module and to track the health of fiber optic transceivers.
The logic for the SFF standard and i2c address selection is borrowed directly from the aquantia/atlantic driver, I don't have a lot of stuff to test it but I was able to trigger all code paths from a fiber optic transceiver and an SFP cable I have available.
Demo:
# Fiber transceiver
$ sudo ethtool -m eth1
Identifier : 0x03 (SFP)
Extended identifier : 0x04 (GBIC/SFP defined by 2-wire interface ID)
Connector : 0x07 (LC)
Transceiver codes : 0x10 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
Transceiver type : 10G Ethernet: 10G Base-SR
Encoding : 0x06 (64B/66B)
BR Nominal : 10300MBd
Rate identifier : 0x00 (unspecified)
Length (SMF) : 0km
Length (OM2) : 80m
Length (OM1) : 30m
Length (Copper or Active cable) : 0m
Length (OM3) : 300m
Laser wavelength : 850nm
Vendor name : QSFPTEK
Vendor OUI : 00:0a:0d
Vendor PN : QT-SFP+-SR
Vendor rev :
Option values : 0x00 0x1a
Option : TX_DISABLE implemented
BR margin max : 10%
BR margin min : 88%
Vendor SN : QT8250805131
Date code : 250806
Optical diagnostics support : Yes
Laser bias current : 5.880 mA
Laser output power : 0.5431 mW / -2.65 dBm
Receiver signal average optical power : 0.6912 mW / -1.60 dBm
Module temperature : 20.70 degrees C / 69.25 degrees F
Module voltage : 3.3000 V
...# DAC
$ sudo ethtool -m eth1
Identifier : 0x03 (SFP)
Extended identifier : 0x04 (GBIC/SFP defined by 2-wire interface ID)
Connector : 0x21 (Copper pigtail)
Transceiver codes : 0x00 0x00 0x00 0x00 0x00 0x04 0x00 0x00 0x00
Transceiver type : Passive Cable
Encoding : 0x00 (unspecified)
BR Nominal : 10300MBd
Rate identifier : 0x00 (unspecified)
Length (SMF) : 0km
Length (OM2) : 0m
Length (OM1) : 0m
Length (Copper or Active cable) : 1m
Length (OM3) : 0m
Passive Cu cmplnce. : 0x01 (SFF-8431 appendix E [SFF-8472 rev10.4 only])
Vendor name : OEM
Vendor OUI : 00:40:20
Vendor PN : SFP-H10GB-CU1M
Vendor rev : R
Option values : 0x00 0x00
BR margin max : 0%
BR margin min : 0%
Vendor SN : CSC240415030053
Date code : 240508
...# No module
$ sudo ethtool -m eth1 netlink error: Input/output error
Cheers,
Fabio
drivers/net/ethernet/realtek/r8169_main.c | 177 ++++++++++++++++++++++ 1 file changed, 177 insertions(+)
drivers/net/ethernet/realtek/r8169_main.c +177 -0
@@ -2411,6 +2411,181 @@ static int rtl8169_set_link_ksettings(struct net_device *ndev,return 0 ; } +#define R8127_SDS_I2C_CON 0xe200 +#define R8127_SDS_I2C_TAR 0xe204 +#define R8127_SDS_I2C_DATA_CMD 0xe210 +#define R8127_SDS_I2C_FS_SCL_HCNT 0xe21c +#define R8127_SDS_I2C_FS_SCL_LCNT 0xe220 +#define R8127_SDS_I2C_INTR_STAT 0xe22c +#define R8127_SDS_I2C_EN 0xe26c +#define R8127_SDS_I2C_STATUS 0xe270 + +#define R8127_SDS_I2C_STATUS_ACTIVITY BIT(0) +#define R8127_SDS_I2C_RX_FIFO_NOT_EMPTY BIT(3) +#define R8127_SDS_I2C_STAT_TX_ABRT BIT(6) + +#define R8127_SDS_I2C_CMD_READ BIT(8) +#define R8127_SDS_I2C_CMD_STOP BIT(9) +#define R8127_SDS_I2C_CMD_RESTART BIT(10) + +#define SFF_8472_ID_ADDR 0x50 +#define SFF_8472_DIAGNOSTICS_ADDR 0x51 + +#define SFF_8472_COMP_ADDR 0x5e +#define SFF_8472_DOM_TYPE_ADDR 0x5c + +#define SFF_8472_ADDRESS_CHANGE_REQ_MASK 0x4 + +static void r8127_sfp_sds_i2c_init (struct rtl8169_private *tp,u8 addr) +{ +r8168_mac_ocp_write (tp,R8127_SDS_I2C_EN ,0 ); +r8168_mac_ocp_write (tp,R8127_SDS_I2C_CON ,0x65 ); +r8168_mac_ocp_write (tp,R8127_SDS_I2C_TAR , addr); +r8168_mac_ocp_write (tp,R8127_SDS_I2C_FS_SCL_HCNT ,0x23a ); +r8168_mac_ocp_write (tp,R8127_SDS_I2C_FS_SCL_LCNT ,0x23a ); +r8168_mac_ocp_write (tp,R8127_SDS_I2C_EN ,1 ); +} + +static void r8127_sfp_sds_i2c_disable (struct rtl8169_private *tp) +{ +r8168_mac_ocp_write (tp,R8127_SDS_I2C_EN ,0 ); +} + +DECLARE_RTL_COND (r8127_sfp_sds_i2c_idle_cond) +{ +u16 val; + + val =r8168_mac_ocp_read (tp,R8127_SDS_I2C_STATUS ); + +return val &R8127_SDS_I2C_STATUS_ACTIVITY ; +} + +DECLARE_RTL_COND (r8127_sfp_sds_i2c_rx_fifo_cond) +{ +u16 val; + + val =r8168_mac_ocp_read (tp,R8127_SDS_I2C_STATUS ); + +return val &R8127_SDS_I2C_RX_FIFO_NOT_EMPTY ; +} + +static int r8127_sfp_sds_i2c_read (struct rtl8169_private *tp, +u8 addr,u8 off,u8 *buf,u16 len) +{ +u16 intr_stat; +int ret =0 ; + +r8127_sfp_sds_i2c_init (tp, addr); + +r8168_mac_ocp_write (tp,R8127_SDS_I2C_DATA_CMD , off); + +if (!rtl_loop_wait_low (tp, &r8127_sfp_sds_i2c_idle_cond,10 ,100 )) { + ret = -EIO ; + goto out; + } + + intr_stat =r8168_mac_ocp_read (tp,R8127_SDS_I2C_INTR_STAT ); +if (intr_stat &R8127_SDS_I2C_STAT_TX_ABRT ) { +/* NACK */ + ret = -EIO ; + goto out; + } + +for (int i =0 ; i < len; i++) { +u16 data =R8127_SDS_I2C_CMD_READ ; + +if (i == len -1 ) + data |=R8127_SDS_I2C_CMD_STOP ; +if (i ==0 ) + data |=R8127_SDS_I2C_CMD_RESTART ; + +r8168_mac_ocp_write (tp,R8127_SDS_I2C_DATA_CMD , data); + +if (!rtl_loop_wait_high (tp, &r8127_sfp_sds_i2c_rx_fifo_cond, +10 ,1000 )) { + ret = -ETIMEDOUT ; + goto out; + } + + buf[i] =r8168_mac_ocp_read (tp,R8127_SDS_I2C_DATA_CMD ); + } + +out: +r8127_sfp_sds_i2c_disable (tp); + +return ret; +} + +static int rtl8169_get_module_info (struct net_device *ndev, +struct ethtool_modinfo *modinfo) +{ +struct rtl8169_private *tp =netdev_priv (ndev); +u8 compliance_val, dom_type; +int ret; + +if (!tp->sfp_mode) +return -EOPNOTSUPP ; + + ret =r8127_sfp_sds_i2c_read (tp,SFF_8472_ID_ADDR , +SFF_8472_COMP_ADDR , &compliance_val,1 ); +if (ret) +return ret; + + ret =r8127_sfp_sds_i2c_read (tp,SFF_8472_ID_ADDR , +SFF_8472_DOM_TYPE_ADDR , &dom_type,1 ); +if (ret) +return ret; + +if (dom_type &SFF_8472_ADDRESS_CHANGE_REQ_MASK || compliance_val ==0x00 ) { + modinfo->type =ETH_MODULE_SFF_8079 ; + modinfo->eeprom_len =ETH_MODULE_SFF_8079_LEN ; + }else { + modinfo->type =ETH_MODULE_SFF_8472 ; + modinfo->eeprom_len =ETH_MODULE_SFF_8472_LEN ; + } + +return 0 ; +} + +static int rtl8169_get_module_eeprom (struct net_device *ndev, +struct ethtool_eeprom *ee,unsigned char *data) +{ +struct rtl8169_private *tp =netdev_priv (ndev); +unsigned int first, last, len; +int ret; + +if (!tp->sfp_mode) +return -EOPNOTSUPP ; + + first = ee->offset; + last = ee->offset + ee->len; + +if (first <ETH_MODULE_SFF_8079_LEN ) { + len =min (last,ETH_MODULE_SFF_8079_LEN ); + len -= first; + + ret =r8127_sfp_sds_i2c_read (tp,SFF_8472_ID_ADDR , + first, data, len); +if (ret) +return ret; + + first += len; + data += len; + } +if (first <ETH_MODULE_SFF_8472_LEN && last >ETH_MODULE_SFF_8079_LEN ) { + len =min (last,ETH_MODULE_SFF_8472_LEN ); + len -= first; + first -=ETH_MODULE_SFF_8079_LEN ; + + ret =r8127_sfp_sds_i2c_read (tp,SFF_8472_DIAGNOSTICS_ADDR , + first, data, len); +if (ret) +return ret; + } + +return 0 ; +} +static const struct ethtool_ops rtl8169_ethtool_ops = { .supported_coalesce_params =ETHTOOL_COALESCE_USECS |ETHTOOL_COALESCE_MAX_FRAMES ,
@@ -2437,6 +2612,8 @@ static const struct ethtool_ops rtl8169_ethtool_ops = { .set_pauseparam = rtl8169_set_pauseparam, .get_eth_mac_stats = rtl8169_get_eth_mac_stats, .get_eth_ctrl_stats = rtl8169_get_eth_ctrl_stats, + .get_module_info = rtl8169_get_module_info, + .get_module_eeprom = rtl8169_get_module_eeprom, };static const struct rtl_chip_info *rtl8169_get_chip_version (u32 xid,bool gmii)
Signature · 1 line
2.47.3
Heiner Kallweit
maintainerQuoted 20 lines · Fabio Baltieri
Implement
get_module_infoandget_module_eepromfor supported devices, right now that's the rtl8127atf.This enables using ethtool to retrieve the transceiver identification and diagnostic data.
Signed-off-by Fabio Baltieri <[email protected]>---
Hi,
Realtek released a new out of tree driver for the rtl8127 and it includes some code that exposes the I2C controller connected to the SFP port.
This patch implements
get_module_infoandget_module_eeprombased on the information found on that driver, it allows ethtool to fetch the SFP module information, which is useful both to identify the module and to track the health of fiber optic transceivers.
Quoted 5 lines
The logic for the SFF standard and i2c address selection is borrowed directly from the aquantia/atlantic driver, I don't have a lot of stuff to test it but I was able to trigger all code paths from a fiber optic transceiver and an SFP cable I have available.
Hi Fabio, thanks for the patch. Being able to access the SFP I2C bus is an important step towards future phylink/SFP support.
@Russell/@Andrew
I'm not really familiar with the phylink and sfp code. And I would like to have the functionality being implemented here reusable once we do further steps towards phylink support in r8169. So how shall the code be modeled, which components are needed?
- Shall the SFP I2C bus be modeled as a struct i2c_adapter?
- Shall we (partially?) implement a struct sfp, so that functions like sfp_module_eeprom() can be used (implicitly)?
I assume this patch includes logic which duplicates what is available in phylink/sfp already. I'd a appreciate any hints you can provide.
Thanks, Heiner
Quoted 269 lines
Demo:
# Fiber transceiver
$ sudo ethtool -m eth1 Identifier : 0x03 (SFP) Extended identifier : 0x04 (GBIC/SFP defined by 2-wire interface ID) Connector : 0x07 (LC) Transceiver codes : 0x10 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 Transceiver type : 10G Ethernet: 10G Base-SR Encoding : 0x06 (64B/66B) BR Nominal : 10300MBd Rate identifier : 0x00 (unspecified) Length (SMF) : 0km Length (OM2) : 80m Length (OM1) : 30m Length (Copper or Active cable) : 0m Length (OM3) : 300m Laser wavelength : 850nm Vendor name : QSFPTEK Vendor OUI : 00:0a:0d Vendor PN : QT-SFP+-SR Vendor rev : Option values : 0x00 0x1a Option : TX_DISABLE implemented BR margin max : 10% BR margin min : 88% Vendor SN : QT8250805131 Date code : 250806 Optical diagnostics support : Yes Laser bias current : 5.880 mA Laser output power : 0.5431 mW / -2.65 dBm Receiver signal average optical power : 0.6912 mW / -1.60 dBm Module temperature : 20.70 degrees C / 69.25 degrees F Module voltage : 3.3000 V ...# DAC
$ sudo ethtool -m eth1 Identifier : 0x03 (SFP) Extended identifier : 0x04 (GBIC/SFP defined by 2-wire interface ID) Connector : 0x21 (Copper pigtail) Transceiver codes : 0x00 0x00 0x00 0x00 0x00 0x04 0x00 0x00 0x00 Transceiver type : Passive Cable Encoding : 0x00 (unspecified) BR Nominal : 10300MBd Rate identifier : 0x00 (unspecified) Length (SMF) : 0km Length (OM2) : 0m Length (OM1) : 0m Length (Copper or Active cable) : 1m Length (OM3) : 0m Passive Cu cmplnce. : 0x01 (SFF-8431 appendix E [SFF-8472 rev10.4 only]) Vendor name : OEM Vendor OUI : 00:40:20 Vendor PN : SFP-H10GB-CU1M Vendor rev : R Option values : 0x00 0x00 BR margin max : 0% BR margin min : 0% Vendor SN : CSC240415030053 Date code : 240508 ...# No module
$ sudo ethtool -m eth1 netlink error: Input/output errorCheers,
Fabiodrivers/net/ethernet/realtek/r8169_main.c | 177 ++++++++++++++++++++++ 1 file changed, 177 insertions(+)drivers/net/ethernet/realtek/r8169_main.c +177
-0@@ -2411,6 +2411,181 @@ static int rtl8169_set_link_ksettings(struct net_device *ndev,return 0 ; } +#define R8127_SDS_I2C_CON 0xe200 +#define R8127_SDS_I2C_TAR 0xe204 +#define R8127_SDS_I2C_DATA_CMD 0xe210 +#define R8127_SDS_I2C_FS_SCL_HCNT 0xe21c +#define R8127_SDS_I2C_FS_SCL_LCNT 0xe220 +#define R8127_SDS_I2C_INTR_STAT 0xe22c +#define R8127_SDS_I2C_EN 0xe26c +#define R8127_SDS_I2C_STATUS 0xe270 + +#define R8127_SDS_I2C_STATUS_ACTIVITY BIT(0) +#define R8127_SDS_I2C_RX_FIFO_NOT_EMPTY BIT(3) +#define R8127_SDS_I2C_STAT_TX_ABRT BIT(6) + +#define R8127_SDS_I2C_CMD_READ BIT(8) +#define R8127_SDS_I2C_CMD_STOP BIT(9) +#define R8127_SDS_I2C_CMD_RESTART BIT(10) + +#define SFF_8472_ID_ADDR 0x50 +#define SFF_8472_DIAGNOSTICS_ADDR 0x51 + +#define SFF_8472_COMP_ADDR 0x5e +#define SFF_8472_DOM_TYPE_ADDR 0x5c + +#define SFF_8472_ADDRESS_CHANGE_REQ_MASK 0x4 + +static void r8127_sfp_sds_i2c_init (struct rtl8169_private *tp,u8 addr) +{ +r8168_mac_ocp_write (tp,R8127_SDS_I2C_EN ,0 ); +r8168_mac_ocp_write (tp,R8127_SDS_I2C_CON ,0x65 ); +r8168_mac_ocp_write (tp,R8127_SDS_I2C_TAR , addr); +r8168_mac_ocp_write (tp,R8127_SDS_I2C_FS_SCL_HCNT ,0x23a ); +r8168_mac_ocp_write (tp,R8127_SDS_I2C_FS_SCL_LCNT ,0x23a ); +r8168_mac_ocp_write (tp,R8127_SDS_I2C_EN ,1 ); +} + +static void r8127_sfp_sds_i2c_disable (struct rtl8169_private *tp) +{ +r8168_mac_ocp_write (tp,R8127_SDS_I2C_EN ,0 ); +} + +DECLARE_RTL_COND (r8127_sfp_sds_i2c_idle_cond) +{ +u16 val; + + val =r8168_mac_ocp_read (tp,R8127_SDS_I2C_STATUS ); + +return val &R8127_SDS_I2C_STATUS_ACTIVITY ; +} + +DECLARE_RTL_COND (r8127_sfp_sds_i2c_rx_fifo_cond) +{ +u16 val; + + val =r8168_mac_ocp_read (tp,R8127_SDS_I2C_STATUS ); + +return val &R8127_SDS_I2C_RX_FIFO_NOT_EMPTY ; +} + +static int r8127_sfp_sds_i2c_read (struct rtl8169_private *tp, +u8 addr,u8 off,u8 *buf,u16 len) +{ +u16 intr_stat; +int ret =0 ; + +r8127_sfp_sds_i2c_init (tp, addr); + +r8168_mac_ocp_write (tp,R8127_SDS_I2C_DATA_CMD , off); + +if (!rtl_loop_wait_low (tp, &r8127_sfp_sds_i2c_idle_cond,10 ,100 )) { + ret = -EIO ; + goto out; + } + + intr_stat =r8168_mac_ocp_read (tp,R8127_SDS_I2C_INTR_STAT ); +if (intr_stat &R8127_SDS_I2C_STAT_TX_ABRT ) { +/* NACK */ + ret = -EIO ; + goto out; + } + +for (int i =0 ; i < len; i++) { +u16 data =R8127_SDS_I2C_CMD_READ ; + +if (i == len -1 ) + data |=R8127_SDS_I2C_CMD_STOP ; +if (i ==0 ) + data |=R8127_SDS_I2C_CMD_RESTART ; + +r8168_mac_ocp_write (tp,R8127_SDS_I2C_DATA_CMD , data); + +if (!rtl_loop_wait_high (tp, &r8127_sfp_sds_i2c_rx_fifo_cond, +10 ,1000 )) { + ret = -ETIMEDOUT ; + goto out; + } + + buf[i] =r8168_mac_ocp_read (tp,R8127_SDS_I2C_DATA_CMD ); + } + +out: +r8127_sfp_sds_i2c_disable (tp); + +return ret; +} + +static int rtl8169_get_module_info (struct net_device *ndev, +struct ethtool_modinfo *modinfo) +{ +struct rtl8169_private *tp =netdev_priv (ndev); +u8 compliance_val, dom_type; +int ret; + +if (!tp->sfp_mode) +return -EOPNOTSUPP ; + + ret =r8127_sfp_sds_i2c_read (tp,SFF_8472_ID_ADDR , +SFF_8472_COMP_ADDR , &compliance_val,1 ); +if (ret) +return ret; + + ret =r8127_sfp_sds_i2c_read (tp,SFF_8472_ID_ADDR , +SFF_8472_DOM_TYPE_ADDR , &dom_type,1 ); +if (ret) +return ret; + +if (dom_type &SFF_8472_ADDRESS_CHANGE_REQ_MASK || compliance_val ==0x00 ) { + modinfo->type =ETH_MODULE_SFF_8079 ; + modinfo->eeprom_len =ETH_MODULE_SFF_8079_LEN ; + }else { + modinfo->type =ETH_MODULE_SFF_8472 ; + modinfo->eeprom_len =ETH_MODULE_SFF_8472_LEN ; + } + +return 0 ; +} + +static int rtl8169_get_module_eeprom (struct net_device *ndev, +struct ethtool_eeprom *ee,unsigned char *data) +{ +struct rtl8169_private *tp =netdev_priv (ndev); +unsigned int first, last, len; +int ret; + +if (!tp->sfp_mode) +return -EOPNOTSUPP ; + + first = ee->offset; + last = ee->offset + ee->len; + +if (first <ETH_MODULE_SFF_8079_LEN ) { + len =min (last,ETH_MODULE_SFF_8079_LEN ); + len -= first; + + ret =r8127_sfp_sds_i2c_read (tp,SFF_8472_ID_ADDR , + first, data, len); +if (ret) +return ret; + + first += len; + data += len; + } +if (first <ETH_MODULE_SFF_8472_LEN && last >ETH_MODULE_SFF_8079_LEN ) { + len =min (last,ETH_MODULE_SFF_8472_LEN ); + len -= first; + first -=ETH_MODULE_SFF_8079_LEN ; + + ret =r8127_sfp_sds_i2c_read (tp,SFF_8472_DIAGNOSTICS_ADDR , + first, data, len); +if (ret) +return ret; + } + +return 0 ; +} +static const struct ethtool_ops rtl8169_ethtool_ops = { .supported_coalesce_params =ETHTOOL_COALESCE_USECS |ETHTOOL_COALESCE_MAX_FRAMES ,@@ -2437,6 +2612,8 @@ static const struct ethtool_ops rtl8169_ethtool_ops = { .set_pauseparam = rtl8169_set_pauseparam, .get_eth_mac_stats = rtl8169_get_eth_mac_stats, .get_eth_ctrl_stats = rtl8169_get_eth_ctrl_stats, + .get_module_info = rtl8169_get_module_info, + .get_module_eeprom = rtl8169_get_module_eeprom, };static const struct rtl_chip_info *rtl8169_get_chip_version (u32 xid,bool gmii)
Quoted 30 lines · Heiner Kallweit
Quoted 20 lines · Fabio Baltieri
Implement
get_module_infoandget_module_eepromfor supported devices, right now that's the rtl8127atf.This enables using ethtool to retrieve the transceiver identification and diagnostic data.
Signed-off-by Fabio Baltieri <[email protected]>---
Hi,
Realtek released a new out of tree driver for the rtl8127 and it includes some code that exposes the I2C controller connected to the SFP port.
This patch implements
get_module_infoandget_module_eeprombased on the information found on that driver, it allows ethtool to fetch the SFP module information, which is useful both to identify the module and to track the health of fiber optic transceivers.Quoted 5 lines
The logic for the SFF standard and i2c address selection is borrowed directly from the aquantia/atlantic driver, I don't have a lot of stuff to test it but I was able to trigger all code paths from a fiber optic transceiver and an SFP cable I have available.
Hi Fabio, thanks for the patch. Being able to access the SFP I2C bus is an important step towards future phylink/SFP support.
Quoted 8 lines
@Russell/@Andrew
I'm not really familiar with the phylink and sfp code. And I would like to have the functionality being implemented here reusable once we do further steps towards phylink support in r8169. So how shall the code be modeled, which components are needed?
- Shall the SFP I2C bus be modeled as a structi2c_adapter?
- Shall we (partially?) implement a struct sfp, so that functions likesfp_module_eeprom()can be used (implicitly)?
Yeah happy to hear any input on it, the controller actually seems to be a designware IP and there is some reusable code for it but what I've seen done for other drivers for this functionality is to implement a minimum i2c "read bulk" functionality in the driver itself, so that's what I proposed here too, the code is fairly simple after all. However I did borrow some logic much verbatim from the atlantis driver as I mentioned, happy to hear if there's a path to reuse.
Quoted 5 lines
I assume this patch includes logic which duplicates what is available in phylink/sfp already. I'd a appreciate any hints you can provide.
Thanks, Heiner
Quoted 2 lines
Yeah happy to hear any input on it, the controller actually seems to be a designware IP
Ah, interesting. Ideally you want to use the existing designware driver. Take a look at txgbe_i2c_register().
Andrew
Quoted 30 lines · Heiner Kallweit
Quoted 20 lines · Fabio Baltieri
Implement
get_module_infoandget_module_eepromfor supported devices, right now that's the rtl8127atf.This enables using ethtool to retrieve the transceiver identification and diagnostic data.
Signed-off-by Fabio Baltieri <[email protected]>---
Hi,
Realtek released a new out of tree driver for the rtl8127 and it includes some code that exposes the I2C controller connected to the SFP port.
This patch implements
get_module_infoandget_module_eeprombased on the information found on that driver, it allows ethtool to fetch the SFP module information, which is useful both to identify the module and to track the health of fiber optic transceivers.Quoted 5 lines
The logic for the SFF standard and i2c address selection is borrowed directly from the aquantia/atlantic driver, I don't have a lot of stuff to test it but I was able to trigger all code paths from a fiber optic transceiver and an SFP cable I have available.
Hi Fabio, thanks for the patch. Being able to access the SFP I2C bus is an important step towards future phylink/SFP support.
Quoted 6 lines
@Russell/@Andrew
I'm not really familiar with the phylink and sfp code. And I would like to have the functionality being implemented here reusable once we do further steps towards phylink support in r8169. So how shall the code be modeled, which components are needed?
- Shall the SFP I2C bus be modeled as a structi2c_adapter?
Yes, that would be best. Call i2c_add_adapter() to add it to the I2C core. The SFP code in drivers/net/phy can then make use of it.
Quoted 5 lines
- Shall we (partially?) implement a struct sfp, so that functions like
sfp_module_eeprom()can be used (implicitly)?I assume this patch includes logic which duplicates what is available in phylink/sfp already. I'd a appreciate any hints you can provide.
No. phylink etc will end up populating netdev->sfp_bus, and then get_module_eeprom_by_page() should then just make the module work in ethtool.
The interesting bit if gluing it all together, without DT. But txgbe_phy.c should be something you can copy from.
Does the out of tree driver give access to GPIOs connected to the SFP cage pins? Ideally you want those as well, for loss of signal, transmitter disable, knowing when a module has been inserted into the cage, etc.
And you will need a PCS driver.
But first step is probably to work with the existing Base-T devices and convert the driver to phylink.
Andrew
---
pw-bot: cr
Quoted 51 lines · Andrew Lunn
Quoted 30 lines · Heiner Kallweit
Quoted 20 lines · Fabio Baltieri
Implement
get_module_infoandget_module_eepromfor supported devices, right now that's the rtl8127atf.This enables using ethtool to retrieve the transceiver identification and diagnostic data.
Signed-off-by Fabio Baltieri <[email protected]>---
Hi,
Realtek released a new out of tree driver for the rtl8127 and it includes some code that exposes the I2C controller connected to the SFP port.
This patch implements
get_module_infoandget_module_eeprombased on the information found on that driver, it allows ethtool to fetch the SFP module information, which is useful both to identify the module and to track the health of fiber optic transceivers.Quoted 5 lines
The logic for the SFF standard and i2c address selection is borrowed directly from the aquantia/atlantic driver, I don't have a lot of stuff to test it but I was able to trigger all code paths from a fiber optic transceiver and an SFP cable I have available.
Hi Fabio, thanks for the patch. Being able to access the SFP I2C bus is an important step towards future phylink/SFP support.
Quoted 6 lines
@Russell/@Andrew
I'm not really familiar with the phylink and sfp code. And I would like to have the functionality being implemented here reusable once we do further steps towards phylink support in r8169. So how shall the code be modeled, which components are needed?
- Shall the SFP I2C bus be modeled as a structi2c_adapter?Yes, that would be best. Call
i2c_add_adapter()to add it to the I2C core. The SFP code indrivers/net/phycan then make use of it.Quoted 5 lines
- Shall we (partially?) implement a struct sfp, so that functions like
sfp_module_eeprom()can be used (implicitly)?I assume this patch includes logic which duplicates what is available in phylink/sfp already. I'd a appreciate any hints you can provide.
No. phylink etc will end up populating
netdev->sfp_bus, and thenget_module_eeprom_by_page()should then just make the module work in ethtool.
Quoted 7 lines
The interesting bit if gluing it all together, without DT. But
txgbe_phy.cshould be something you can copy from.Does the out of tree driver give access to GPIOs connected to the SFP cage pins? Ideally you want those as well, for loss of signal, transmitter disable, knowing when a module has been inserted into the cage, etc.
The current version does not seem to do that, maybe the Realtek folks can chime in about it.
I'll look into the dw driver, thanks for the pointer.
Quoted 4 lines
And you will need a PCS driver.
But first step is probably to work with the existing Base-T devices and convert the driver to phylink.
Quoted 10 lines · Andrew Lunn
Quoted 9 lines
Hi Fabio, thanks for the patch. Being able to access the SFP I2C bus is an important step towards future phylink/SFP support.
@Russell/@Andrew
I'm not really familiar with the phylink and sfp code. And I would like to have the functionality being implemented here reusable once we do further steps towards phylink support in r8169. So how shall the code be modeled, which components are needed?
- Shall the SFP I2C bus be modeled as a structi2c_adapter?
Quoted 2 lines
Yes, that would be best. Call
i2c_add_adapter()to add it to the I2C core. The SFP code indrivers/net/phycan then make use of it.
Hey Andrew, thanks for the pointers, I was able to instantiate the dw i2c controller, same as txgbe/txgbe_phy.c really.
For some reasons I had to revert 560072246088, was getting a "spurious STOP detected" but I'll follow up on that separately. Also find an issue in the txgbe driver (I think?), sent
https://lore.kernel.org/netdev/[email protected]/
for it.
Quoted 10 lines
Quoted 5 lines
- Shall we (partially?) implement a struct sfp, so that functions like
sfp_module_eeprom()can be used (implicitly)?I assume this patch includes logic which duplicates what is available in phylink/sfp already. I'd a appreciate any hints you can provide.
No. phylink etc will end up populating
netdev->sfp_bus, and thenget_module_eeprom_by_page()should then just make the module work in ethtool.
Quoted 7 lines
The interesting bit if gluing it all together, without DT. But
txgbe_phy.cshould be something you can copy from.Does the out of tree driver give access to GPIOs connected to the SFP cage pins? Ideally you want those as well, for loss of signal, transmitter disable, knowing when a module has been inserted into the cage, etc.
It doesn't, but I was able to find them anyway, just dumping registers randomly. :-) It looks like that is a bit more than "Ideally", the sfp driver probes happily with no gpios defined but then it doesn't have any ways to detect module changes (insertion/removal), it doesn't even go into polling mode but even then it seems like it doesn't do detection without a detect pin. I think the sfp probe function could be a bit more defensive to inoperable configurations.
Anyway I was able to make detection and los work, so I have some code with gpio, i2c and the sfp module detect and showing up in hwmon, and sitting in waitdev state.
Quoted 5 lines
And you will need a PCS driver.
But first step is probably to work with the existing Base-T devices and convert the driver to phylink.
Ok I was going to ask how to connect the one above with the ethtool handlers, so you are saying that first the whole driver needs to be converted to use phylink/pcs and then that should work automatically-ish right?
Can I send the current code I have as an RFC in the meantime to get some early feedback? And then I guess it'll have to be reworked on top of the phylink stuff (which I did not try to implement).
It's a pretty substantial amount of boilerplate code so I suspect Heiner may want to refactor things about it, feels like it could live in its own file.
Thanks for the help so far,
Fabio
Quoted 5 lines
Quoted 2 lines
Yes, that would be best. Call
i2c_add_adapter()to add it to the I2C core. The SFP code indrivers/net/phycan then make use of it.Hey Andrew, thanks for the pointers, I was able to instantiate the dw i2c controller, same as
txgbe/txgbe_phy.creally.
Cool.
Quoted 2 lines
For some reasons I had to revert 560072246088, was getting a "spurious STOP detected" but I'll follow up on that separately.
I2C transfers need to be multiples of 2 bytes, in order for the HWMON to work correctly. You need to read the 16 bits in a single operation. If they get chopped up into multiple transfers they become unreliable. So it would be good to get to the bottom of this.
Quoted 3 lines
Anyway I was able to make detection and los work, so I have some code with gpio, i2c and the sfp module detect and showing up in hwmon, and sitting in waitdev state.
Nice.
Quoted 10 lines
Quoted 5 lines
And you will need a PCS driver.
But first step is probably to work with the existing Base-T devices and convert the driver to phylink.
Ok I was going to ask how to connect the one above with the ethtool handlers, so you are saying that first the whole driver needs to be converted to use phylink/pcs and then that should work automatically-ish right?
Yes, once phylink is coordinating all the parts, accessing the module via ethtool should just start working.
Quoted 2 lines
Can I send the current code I have as an RFC in the meantime to get some early feedback?
Sure.
Quoted 3 lines
It's a pretty substantial amount of boilerplate code so I suspect Heiner may want to refactor things about it, feels like it could live in its own file.
How much is identical to the txgbe? I wounder if it makes sense to add some helpers which can be shared by both drivers?
Andrew
Quoted 4 lines
Also find an issue
in the txgbe driver (I think?), sent
https://lore.kernel.org/netdev/[email protected]/
for it.
I looked at that, and it seems like you are correct, but i also don't understand why it has not crashed. So it would be good to get some feedback from the trustnetic and net-swift people.
Andrew