octeontx2-pf: report port connector type in ethtool link ksettings
Ratheesh Kannoth
maintainerPATCH v3 1/1 octeontx2-pf: report port connector type in ethtool link ksettings
From: Hariprasad Kelam <[email protected]>
otx2_get_link_ksettings() already reports speed, duplex, autoneg, link modes and FEC from CGX firmware shared data, but never fills cmd->base.port. As a result, ethtool does not show the physical connector type even though firmware provides it in fwdata.port.
Read the connector type from shared firmware data and expose it via ethtool. Extract only the low 8 bits of the firmware field and validate the value against the standard ethtool PORT_* definitions before publishing it to userspace.
---
v2 -> v3:
- Extract only the connector type bits with FIELD_GET(GENMASK(7, 0), ...) instead of casting the full 64-bit firmware field to u8.
- Validate firmware values against the ethtool PORT_* whitelist before exposing them to userspace, per Jakub's review.
- Map unrecognized firmware values to PORT_OTHER instead of passing them through blindly.
v1 -> v2:
- Addressed Sashiko review comments.
https://lore.kernel.org/netdev/[email protected]/
--- .../marvell/octeontx2/nic/otx2_ethtool.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
drivers/net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c +18 -0
@@ -1209,6 +1209,7 @@ static int otx2_get_link_ksettings(struct net_device *netdev, {struct otx2_nic *pfvf =netdev_priv (netdev);struct cgx_fw_data *rsp =NULL ; +u8 port; cmd->base.duplex = pfvf->linfo.full_duplex; cmd->base.speed = pfvf->linfo.speed;
@@ -1231,6 +1232,23 @@ static int otx2_get_link_ksettings(struct net_device *netdev, OTX2_MODE_SUPPORTED, cmd);otx2_get_fec_info (rsp->fwdata.supported_fec,OTX2_MODE_SUPPORTED , cmd); + + port =FIELD_GET (GENMASK (7 ,0 ), rsp->fwdata.port); +switch (port) { +case PORT_TP : +case PORT_AUI : +case PORT_MII : +case PORT_FIBRE : +case PORT_BNC : +case PORT_DA : +case PORT_NONE : + cmd->base.port = port; +break ; +default : + cmd->base.port =PORT_OTHER ; +break ; + } +return 0 ; }
Signature · 1 line
2.43.0
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Critical: 0 · High: 0 · Medium: 1 · Low: 0
- [Medium] otx2_get_link_ksettings() (drivers/net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c:1236)…
--
octeontx2-pf: report port connector type in ethtool link ksettings
otx2_get_link_ksettings() now reads the connector type out of the CGX firmware shared data (struct cgx_lmac_fwdata_s.port), masks the low eight bits, checks the result against a list of ethtool PORT_* values and stores it into cmd->base.port. Unrecognized values become PORT_OTHER.
Quoted 4 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c +0
-0
[ ... ]
Quoted 10 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c +6
-0@@ -1231,6 +1232,23 @@ static int otx2_get_link_ksettings(struct net_device *netdev, OTX2_MODE_SUPPORTED, cmd);otx2_get_fec_info (rsp->fwdata.supported_fec,OTX2_MODE_SUPPORTED , cmd); + + port =FIELD_GET (GENMASK (7 ,0 ), rsp->fwdata.port); +switch (port) { +case PORT_TP : +case PORT_AUI : +case PORT_MII :
drivers/net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c static int otx2_get_link_ksettings(struct net_device *netdev, · line 1250
Quoted 10 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c +10
-0+case PORT_FIBRE : +case PORT_BNC : +case PORT_DA : +case PORT_NONE : + cmd->base.port = port; +break ; +default : + cmd->base.port =PORT_OTHER ; +break ; + }
[Severity: Medium]
Can this report a wrong connector type when firmware never populated the field?
PORT_TP is 0x00 in include/uapi/linux/ethtool.h, and the ethtool core zero-fills the settings before calling into the driver:
net/ethtool/ioctl.c:netif_get_link_ksettings() {
memset(link_ksettings, 0, sizeof(*link_ksettings));
return dev->ethtool_ops->get_link_ksettings(dev, link_ksettings);
}So a zero firmware word takes the "case PORT_TP:" arm rather than the default PORT_OTHER arm, and ethtool prints "Port: Twisted Pair" on a fibre, DAC or backplane board.
Is a zero word possible here? The member was carved out of the previously reserved (zero-filled) tail of struct cgx_lmac_fwdata_s by commit 49f02e6877d1b, which shrank LMAC_FWDATA_RESERVED_MEM from 1021 to 1018:
drivers/net/ethernet/marvell/octeontx2/af/mbox.h:
u64 mgmt_port:1; u64 advertised_an:1; u64 port; #define LMAC_FWDATA_RESERVED_MEM 1018 u64 reserved[LMAC_FWDATA_RESERVED_MEM];
RVU_FWDATA_VERSION was not bumped at the same time, and is_rvu_fwdata_valid() in af/rvu.h only compares header_magic and version, so firmware images that predate the field still pass the ABI gate and hand back zeros for this word.
Would it make sense to also consult rw_valid from the same struct? It is the per-LMAC validity flag, and grep shows it is currently only referenced in mbox.h and rvu_debugfs.c, never by this new consumer. Note also that the debugfs dumper added alongside the field prints rw_valid, lmac_type, portm_idx and mgmt_port, but not port.
Separately, does the masking defeat part of the validation? FIELD_GET() with GENMASK(7, 0) drops bits 63:8 before the switch runs, so firmware values such as 0x100 or 0x103 are published as PORT_TP and PORT_FIBRE respectively. mbox.h documents no bitfield layout, mask or reserved-bit contract for this bare u64, so it isn't clear the upper bits can be discarded rather than treated as "not a valid connector code".
Related to that, the commit message says:
"Extract only the low 8 bits of the firmware field and validate the
value against the standard ethtool PORT_* definitions before publishing it to userspace."
Given that neither the unpopulated (zero) case nor invalid values living in bits 63:8 can be rejected by this check, could the description be made more precise about what is actually validated?
One more question on the encoding itself: is there an in-tree statement that fwdata.port uses ethtool PORT_* numbering? The only other firmware description of a "port" value is struct cgx_lnk_sts.port:8 with RESP_LINKSTAT_PORT in af/cgx_fw_if.h, and that macro is defined but never decoded by cgx.c, so the mapping to PORT_TP/PORT_FIBRE/... appears undocumented here.
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260909040621.397255-1-rkannoth%40marvell.com
Ratheesh Kannoth
maintainerQuoted 7 lines · On 2026-09-10 at 10:02:43, [email protected]…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Critical: 0 · High: 0 · Medium: 1 · Low: 0
- [Medium]
otx2_get_link_ksettings()(drivers/net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c:1236)…
FW is setting it properly.
Quoted 102 lines
--
octeontx2-pf: report port connector type in ethtool link ksettings
otx2_get_link_ksettings()now reads the connector type out of the CGX firmware shared data (struct cgx_lmac_fwdata_s.port), masks the low eight bits, checks the result against a list of ethtool PORT_* values and stores it intocmd->base.port. Unrecognized values becomePORT_OTHER.Quoted 4 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c +0
-0[ ... ]
Quoted 10 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c +6
-0@@ -1231,6 +1232,23 @@ static int otx2_get_link_ksettings(struct net_device *netdev, OTX2_MODE_SUPPORTED, cmd);otx2_get_fec_info (rsp->fwdata.supported_fec,OTX2_MODE_SUPPORTED , cmd); + + port =FIELD_GET (GENMASK (7 ,0 ), rsp->fwdata.port); +switch (port) { +case PORT_TP : +case PORT_AUI : +case PORT_MII :drivers/net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c static int otx2_get_link_ksettings(struct net_device *netdev, · line 1250
Quoted 10 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c +10
-0+case PORT_FIBRE : +case PORT_BNC : +case PORT_DA : +case PORT_NONE : + cmd->base.port = port; +break ; +default : + cmd->base.port =PORT_OTHER ; +break ; + }[Severity: Medium]
Can this report a wrong connector type when firmware never populated the field?
PORT_TPis0x00ininclude/uapi/linux/ethtool.h, and the ethtool core zero-fills the settings before calling into the driver:net/ethtool/ioctl.c:netif_get_link_ksettings() { memset(link_ksettings, 0, sizeof(*link_ksettings)); return dev->ethtool_ops->get_link_ksettings(dev, link_ksettings); }So a zero firmware word takes the "case
PORT_TP:" arm rather than the defaultPORT_OTHERarm, and ethtool prints "Port: Twisted Pair" on a fibre, DAC or backplane board.Is a zero word possible here? The member was carved out of the previously reserved (zero-filled) tail of struct
cgx_lmac_fwdata_sby commit49f02e6877d1b, which shrankLMAC_FWDATA_RESERVED_MEMfrom 1021 to 1018:
drivers/net/ethernet/marvell/octeontx2/af/mbox.h:u64 mgmt_port:1; u64 advertised_an:1; u64 port; #define LMAC_FWDATA_RESERVED_MEM 1018 u64 reserved[LMAC_FWDATA_RESERVED_MEM];
RVU_FWDATA_VERSIONwas not bumped at the same time, andis_rvu_fwdata_valid()inaf/rvu.honly comparesheader_magicand version, so firmware images that predate the field still pass the ABI gate and hand back zeros for this word.Would it make sense to also consult
rw_validfrom the same struct? It is the per-LMAC validity flag, and grep shows it is currently only referenced inmbox.handrvu_debugfs.c, never by this new consumer. Note also that the debugfs dumper added alongside the field printsrw_valid,lmac_type,portm_idxandmgmt_port, but not port.Separately, does the masking defeat part of the validation?
FIELD_GET()withGENMASK(7, 0)drops bits 63:8 before the switch runs, so firmware values such as0x100or0x103are published asPORT_TPandPORT_FIBRErespectively.mbox.hdocuments no bitfield layout, mask or reserved-bit contract for this bare u64, so it isn't clear the upper bits can be discarded rather than treated as "not a valid connector code".Related to that, the commit message says:
"Extract only the low 8 bits of the firmware field and validate the
value against the standard ethtool PORT_* definitions before publishing it to userspace."Given that neither the unpopulated (zero) case nor invalid values living in bits 63:8 can be rejected by this check, could the description be made more precise about what is actually validated?
One more question on the encoding itself: is there an in-tree statement that fwdata.port uses ethtool PORT_* numbering? The only other firmware description of a "port" value is struct cgx_lnk_sts.port:8 with
RESP_LINKSTAT_PORTinaf/cgx_fw_if.h, and that macro is defined but never decoded bycgx.c, so the mapping to PORT_TP/PORT_FIBRE/... appears undocumented here.--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260909040621.397255-1-rkannoth%40marvell.com
Quoted 9 lines · Ratheesh Kannoth
Quoted 7 lines · On 2026-09-10 at 10:02:43, [email protected]…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Critical: 0 · High: 0 · Medium: 1 · Low: 0
- [Medium]
otx2_get_link_ksettings()(drivers/net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c:1236)…FW is setting it properly.
Fair enough.
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 8 lines · On Wed, 9 Sep 2026 09:36:20 +0530 you wrote:
From: Hariprasad Kelam <[email protected]>
otx2_get_link_ksettings()already reports speed, duplex, autoneg, link modes and FEC from CGX firmware shared data, but never fillscmd->base.port. As a result, ethtool does not show the physical connector type even though firmware provides it in fwdata.port.[...]
Here is the summary with links:
- [v3,net-next] octeontx2-pf: report port connector type in ethtool link ksettings
https://git.kernel.org/netdev/net-next/c/afabe5e67b67
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html