eth: fbnic: Read module EEPROM
Subsystems (3)
PATCH v2 1/1 eth: fbnic: Read module EEPROM
Add support to read module EEPROM for fbnic. Towards this, add required support to issue a new command to the firmware and to receive the response to the corresponding command.
Create a local copy of the data in the completion struct before writing to ethtool_module_eeprom to avoid writing to data in case it is freed. Given that EEPROM pages are small, the overhead of additional copy is negligible.
Do not block API with explicit checks since API has appropriate checks in place for length, offset, and page.
Explicitly check bank, page, offset, and length in fbnic_fw_parse_qsfp_read_resp() to match EEPROM read responses to the correct request. This is important because if the driver times out waiting for an EEPROM read response, a subsequent read request with different values is susceptible to receiving an erroneous response (i.e., the response to the previous request).
---
Changelog:
V2:
- Drop bank checking in fbnic_get_module_eeprom_by_page()
- Update commit message
V1: https://lore.kernel.org/netdev/[email protected]/
--- .../net/ethernet/meta/fbnic/fbnic_ethtool.c | 60 ++++++++ drivers/net/ethernet/meta/fbnic/fbnic_fw.c | 135 ++++++++++++++++++ drivers/net/ethernet/meta/fbnic/fbnic_fw.h | 22 +++ 3 files changed, 217 insertions(+)
drivers/net/ethernet/meta/fbnic/fbnic_ethtool.c +60 -0
@@ -1635,6 +1635,65 @@ static void fbnic_get_ts_stats(struct net_device *netdev, } } +static int +fbnic_get_module_eeprom_by_page (struct net_device *netdev, +const struct ethtool_module_eeprom *page_data, +struct netlink_ext_ack *extack) +{ +struct fbnic_net *fbn =netdev_priv (netdev); +struct fbnic_fw_completion *fw_cmpl; +struct fbnic_dev *fbd = fbn->fbd; +int err; + +if (page_data->i2c_address !=0x50 ) { +NL_SET_ERR_MSG_MOD (extack, +"Invalid i2c address. Only 0x50 is supported" ); +return -EINVAL ; + } + + fw_cmpl =__fbnic_fw_alloc_cmpl (FBNIC_TLV_MSG_ID_QSFP_READ_RESP , + page_data->length); +if (!fw_cmpl) +return -ENOMEM ; + +/* Initialize completion and queue it for FW to process */ + fw_cmpl->u.qsfp.length = page_data->length; + fw_cmpl->u.qsfp.offset = page_data->offset; + fw_cmpl->u.qsfp.page = page_data->page; + fw_cmpl->u.qsfp.bank = page_data->bank; + + err =fbnic_fw_xmit_qsfp_read_msg (fbd, fw_cmpl, page_data->page, + page_data->bank, page_data->offset, + page_data->length); +if (err) { +NL_SET_ERR_MSG_MOD (extack, +"Failed to transmit EEPROM read request" ); + goto exit_free; + } + +if (!wait_for_completion_timeout (&fw_cmpl->done,2 *HZ )) { + err = -ETIMEDOUT ; +NL_SET_ERR_MSG_MOD (extack, +"Timed out waiting for firmware response" ); + goto exit_cleanup; + } + +if (fw_cmpl->result) { + err = fw_cmpl->result; +NL_SET_ERR_MSG_MOD (extack,"Failed to read EEPROM" ); + goto exit_cleanup; + } + +memcpy (page_data->data, fw_cmpl->u.qsfp.data, page_data->length); + +exit_cleanup: +fbnic_mbx_clear_cmpl (fbd, fw_cmpl); +exit_free: +fbnic_fw_put_cmpl (fw_cmpl); + +return err ? : page_data->length; +} +static void fbnic_set_counter (u64 *stat,struct fbnic_stat_counter *counter) {if (counter->reported)
@@ -1841,6 +1900,7 @@ static const struct ethtool_ops fbnic_ethtool_ops = { .get_link_ksettings = fbnic_phylink_ethtool_ksettings_get, .get_fec_stats = fbnic_get_fec_stats, .get_fecparam = fbnic_phylink_get_fecparam, + .get_module_eeprom_by_page = fbnic_get_module_eeprom_by_page, .get_eth_phy_stats = fbnic_get_eth_phy_stats, .get_eth_mac_stats = fbnic_get_eth_mac_stats, .get_eth_ctrl_stats = fbnic_get_eth_ctrl_stats,
drivers/net/ethernet/meta/fbnic/fbnic_fw.c +135 -0
147 lines not on this page · raw message
drivers/net/ethernet/meta/fbnic/fbnic_fw.h +22 -0
@@ -78,6 +78,13 @@ struct fbnic_fw_completion {u32 offset;u32 length; } fw_update; +struct { +u16 length; +u8 offset; +u8 page; +u8 bank; + u8 data[] __aligned(sizeof(u32)) __counted_by(length); + } qsfp;struct {s32 millivolts;s32 millidegrees;
@@ -109,6 +116,9 @@ int fbnic_fw_xmit_fw_start_upgrade(struct fbnic_dev *fbd,int fbnic_fw_xmit_fw_write_chunk (struct fbnic_dev *fbd,const u8 *data,u32 offset,u16 length,int cancel_error); +int fbnic_fw_xmit_qsfp_read_msg (struct fbnic_dev *fbd, +struct fbnic_fw_completion *cmpl_data, +u32 page,u32 bank,u32 offset,u32 length);int fbnic_fw_xmit_tsene_read_msg (struct fbnic_dev *fbd,struct fbnic_fw_completion *cmpl_data); int fbnic_fw_xmit_send_logs(struct fbnic_dev *fbd, bool enable,
@@ -161,6 +171,8 @@ enum {FBNIC_TLV_MSG_ID_FW_WRITE_CHUNK_RESP =0x25 ,FBNIC_TLV_MSG_ID_FW_FINISH_UPGRADE_REQ =0x28 ,FBNIC_TLV_MSG_ID_FW_FINISH_UPGRADE_RESP =0x29 , +FBNIC_TLV_MSG_ID_QSFP_READ_REQ =0x38 , +FBNIC_TLV_MSG_ID_QSFP_READ_RESP =0x39 ,FBNIC_TLV_MSG_ID_TSENE_READ_REQ =0x3C ,FBNIC_TLV_MSG_ID_TSENE_READ_RESP =0x3D , FBNIC_TLV_MSG_ID_LOG_SEND_LOGS_REQ = 0x43,
@@ -209,6 +221,16 @@ enum { FBNIC_FW_LINK_FEC_BASER = 3, }; +enum { +FBNIC_FW_QSFP_BANK =0x0 , +FBNIC_FW_QSFP_PAGE =0x1 , +FBNIC_FW_QSFP_OFFSET =0x2 , +FBNIC_FW_QSFP_LENGTH =0x3 , +FBNIC_FW_QSFP_ERROR =0x4 , +FBNIC_FW_QSFP_DATA =0x5 , +FBNIC_FW_QSFP_MSG_MAX +}; +enum {FBNIC_FW_TSENE_THERM =0x0 ,FBNIC_FW_TSENE_VOLT =0x1 ,
Signature · 1 line
2.47.3
This patch was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:
Hello:
This patch was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:
Quoted 10 lines · On Mon, 22 Sep 2025 16:18:55 -0700 you wrote:
Add support to read module EEPROM for fbnic. Towards this, add required support to issue a new command to the firmware and to receive the response to the corresponding command.
Create a local copy of the data in the completion struct before writing to
ethtool_module_eepromto avoid writing to data in case it is freed. Given that EEPROM pages are small, the overhead of additional copy is negligible.[...]
Here is the summary with links:
- [net-next,V2] eth: fbnic: Read module EEPROM
https://git.kernel.org/netdev/net-next/c/bb6a22651b89
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html