net: atlantic: support reading SFP module info
Subsystems (3)
PATCH v3 1/1 net: atlantic: support reading SFP module info
Add support for reading SFP module info and digital diagnostic monitoring data if supported by the module. The only Aquantia controller without an integrated PHY is the AQC100 which belongs to the B0 revision, that's why it's only implemented there.
The register information was extracted from a diagnostic tool made publicly available by Dell, but all code was written from scratch by me.
This has been tested to work with a variety of both optical and direct attach modules I had lying around and seems to work fine with all of them, including the diagnostics if supported by an optical module. All tests have been done with an AQC100 on an TL-NT521F card on firmware version 3.1.121 (current at the time of this patch).
---
No content changes, thus resent as v3 with just the target tree changed.
--- .../ethernet/aquantia/atlantic/aq_ethtool.c | 73 ++++++++++ .../ethernet/aquantia/atlantic/aq_ethtool.h | 8 ++ .../net/ethernet/aquantia/atlantic/aq_hw.h | 3 + .../aquantia/atlantic/hw_atl/hw_atl_b0.c | 132 ++++++++++++++++++ .../aquantia/atlantic/hw_atl/hw_atl_llh.c | 43 ++++++ .../aquantia/atlantic/hw_atl/hw_atl_llh.h | 21 +++ .../atlantic/hw_atl/hw_atl_llh_internal.h | 32 +++++ 7 files changed, 312 insertions(+)
drivers/net/ethernet/aquantia/atlantic/aq_ethtool.c +73 -0
@@ -15,6 +15,7 @@#include "aq_macsec.h" #include "aq_main.h" +#include <linux/ethtool.h> #include <linux/linkmode.h> #include <linux/ptp_clock_kernel.h>
@@ -977,6 +978,76 @@ static int aq_ethtool_set_phy_tunable(struct net_device *ndev,return err; } +static int aq_ethtool_get_module_info (struct net_device *ndev, +struct ethtool_modinfo *modinfo) +{ +struct aq_nic_s *aq_nic =netdev_priv (ndev); +u8 compliance_val, dom_type; +int err; + +/* Module EEPROM is only supported for controllers with external PHY */ +if (aq_nic->aq_nic_cfg.aq_hw_caps->media_type !=AQ_HW_MEDIA_TYPE_FIBRE || + !aq_nic->aq_hw_ops->hw_read_module_eeprom) +return -EOPNOTSUPP ; + + err = aq_nic->aq_hw_ops->hw_read_module_eeprom (aq_nic->aq_hw, +SFF_8472_ID_ADDR ,SFF_8472_COMP_ADDR ,1 , &compliance_val); +if (err) +return err; + + err = aq_nic->aq_hw_ops->hw_read_module_eeprom (aq_nic->aq_hw, +SFF_8472_ID_ADDR ,SFF_8472_DOM_TYPE_ADDR ,1 , &dom_type); +if (err) +return err; + +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 aq_ethtool_get_module_eeprom (struct net_device *ndev, +struct ethtool_eeprom *ee,unsigned char *data) +{ +struct aq_nic_s *aq_nic =netdev_priv (ndev); +unsigned int first, last, len; +int err; + +if (!aq_nic->aq_hw_ops->hw_read_module_eeprom) +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; + + err = aq_nic->aq_hw_ops->hw_read_module_eeprom (aq_nic->aq_hw, +SFF_8472_ID_ADDR , first, len, data); +if (err) +return err; + + 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 ; + + err = aq_nic->aq_hw_ops->hw_read_module_eeprom (aq_nic->aq_hw, +SFF_8472_DIAGNOSTICS_ADDR , first, len, data); +if (err) +return err; + } +return 0 ; +} +const struct ethtool_ops aq_ethtool_ops = { .supported_coalesce_params =ETHTOOL_COALESCE_USECS |ETHTOOL_COALESCE_MAX_FRAMES ,
@@ -1014,4 +1085,6 @@ const struct ethtool_ops aq_ethtool_ops = { .get_ts_info = aq_ethtool_get_ts_info, .get_phy_tunable = aq_ethtool_get_phy_tunable, .set_phy_tunable = aq_ethtool_set_phy_tunable, + .get_module_info = aq_ethtool_get_module_info, + .get_module_eeprom = aq_ethtool_get_module_eeprom, };
drivers/net/ethernet/aquantia/atlantic/aq_ethtool.h +8 -0
@@ -14,4 +14,12 @@extern const struct ethtool_ops aq_ethtool_ops;#define AQ_PRIV_FLAGS_MASK (AQ_HW_LOOPBACK_MASK) +#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 +#endif /* AQ_ETHTOOL_H */
drivers/net/ethernet/aquantia/atlantic/aq_hw.h +3 -0
@@ -340,6 +340,9 @@ struct aq_hw_ops {int (*hw_set_loopback)(struct aq_hw_s *self,u32 mode,bool enable);int (*hw_get_mac_temp)(struct aq_hw_s *self,u32 *temp); + +int (*hw_read_module_eeprom)(struct aq_hw_s *self,u8 dev_addr, +u8 reg_start_addr,int len,u8 *data); };struct aq_fw_ops {
drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_b0.c +132 -0
142 lines not on this page · raw message
drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_llh.c +43 -0
49 lines not on this page · raw message
drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_llh.h +21 -0
@@ -34,6 +34,27 @@ u32 hw_atl_ts_ready_latch_high_get(struct aq_hw_s *aq_hw);/* get temperature sense data */ u32 hw_atl_ts_data_get (struct aq_hw_s *aq_hw); +/* SMBUS0 bus busy */ +u32 hw_atl_smb0_bus_busy_get (struct aq_hw_s *aq_hw); + +/* SMBUS0 byte transfer complete */ +u32 hw_atl_smb0_byte_transfer_complete_get (struct aq_hw_s *aq_hw); + +/* SMBUS0 receive acknowledged */ +u32 hw_atl_smb0_receive_acknowledged_get (struct aq_hw_s *aq_hw); + +/* SMBUS0 set transmitted data (only leftmost byte of data valid) */ +void hw_atl_smb0_tx_data_set (struct aq_hw_s *aq_hw,u32 data); + +/* SMBUS0 provisioning2 command register */ +void hw_atl_smb0_provisioning2_set (struct aq_hw_s *aq_hw,u32 data); + +/* SMBUS0 repeated start detect */ +u32 hw_atl_smb0_repeated_start_detect_get (struct aq_hw_s *aq_hw); + +/* SMBUS0 received data register */ +u32 hw_atl_smb0_rx_data_get (struct aq_hw_s *aq_hw); +/* global */ /* set global microprocessor semaphore */
drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_llh_internal.h +32 -0
@@ -42,6 +42,38 @@#define HW_ATL_TS_DATA_OUT_SHIFT 0#define HW_ATL_TS_DATA_OUT_WIDTH 12 +/* SMBUS0 Received Data register */ +#define HW_ATL_SMB0_RECEIVED_DATA_ADR 0x00000748 +/* SMBUS0 Transmitted Data register */ +#define HW_ATL_SMB0_TRANSMITTED_DATA_ADR 0x00000608 + +/* SMBUS0 Global Provisioning 2 register */ +#define HW_ATL_SMB0_PROVISIONING2_ADR 0x00000604 + +/* SMBUS0 Bus Busy Bitfield Definitions */ +#define HW_ATL_SMB0_BUS_BUSY_ADR 0x00000744 +#define HW_ATL_SMB0_BUS_BUSY_MSK 0x00000080 +#define HW_ATL_SMB0_BUS_BUSY_SHIFT 7 +#define HW_ATL_SMB0_BUS_BUSY_WIDTH 1 + +/* SMBUS0 Byte Transfer Complete Bitfield Definitions */ +#define HW_ATL_SMB0_BYTE_TRANSFER_COMPLETE_ADR 0x00000744 +#define HW_ATL_SMB0_BYTE_TRANSFER_COMPLETE_MSK 0x00000002 +#define HW_ATL_SMB0_BYTE_TRANSFER_COMPLETE_SHIFT 1 +#define HW_ATL_SMB0_BYTE_TRANSFER_COMPLETE_WIDTH 1 + +/* SMBUS0 Receive Acknowledge Bitfield Definitions */ +#define HW_ATL_SMB0_RX_ACKNOWLEDGED_ADR 0x00000744 +#define HW_ATL_SMB0_RX_ACKNOWLEDGED_MSK 0x00000100 +#define HW_ATL_SMB0_RX_ACKNOWLEDGED_SHIFT 8 +#define HW_ATL_SMB0_RX_ACKNOWLEDGED_WIDTH 1 + +/* SMBUS0 Repeated Start Detect Bitfield Definitions */ +#define HW_ATL_SMB0_REPEATED_START_DETECT_ADR 0x00000744 +#define HW_ATL_SMB0_REPEATED_START_DETECT_MSK 0x00000004 +#define HW_ATL_SMB0_REPEATED_START_DETECT_SHIFT 2 +#define HW_ATL_SMB0_REPEATED_START_DETECT_WIDTH 1 +/* global microprocessor semaphore definitions * base address: 0x000003a0 * parameter: semaphore {s} | stride size 0x4 | range [0, 15]
Signature · 1 line
2.44.1
Quoted 14 lines · Lorenz Brun
Add support for reading SFP module info and digital diagnostic monitoring data if supported by the module. The only Aquantia controller without an integrated PHY is the AQC100 which belongs to the B0 revision, that's why it's only implemented there.
The register information was extracted from a diagnostic tool made publicly available by Dell, but all code was written from scratch by me.
This has been tested to work with a variety of both optical and direct attach modules I had lying around and seems to work fine with all of them, including the diagnostics if supported by an optical module. All tests have been done with an AQC100 on an TL-NT521F card on firmware version 3.1.121 (current at the time of this patch).
Quoted 3 lines
Signed-off-by Lorenz Brun <[email protected]>---
No content changes, thus resent as v3 with just the target tree changed.
This patch was applied to netdev/net-next.git (main) by Andrew Lunn <[email protected]>:
Hello:
This patch was applied to netdev/net-next.git (main) by Andrew Lunn <[email protected]>:
Quoted 9 lines · On Fri, 18 Oct 2024 19:17:18 +0200 you wrote:
Add support for reading SFP module info and digital diagnostic monitoring data if supported by the module. The only Aquantia controller without an integrated PHY is the AQC100 which belongs to the B0 revision, that's why it's only implemented there.
The register information was extracted from a diagnostic tool made publicly available by Dell, but all code was written from scratch by me.
[...]
Here is the summary with links:
- [net-next,v3] net: atlantic: support reading SFP module info
https://git.kernel.org/netdev/net-next/c/853a2944aaf3
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html