net: xilinx: axienet: Add 10G/25G (XXV) ethernet support
Subsystems (5)
v5 cover net: xilinx: axienet: Add 10G/25G (XXV) ethernet support
This patch series extends the AXI Ethernet driver to support the XXV Ethernet subsystem.
- Refactor through struct axienet_config so per-MAC behaviour is expressed as capability flags and callbacks instead of runtime MAC-type checks in the shared code.
- Document the XXV IP in Devicetree.
- Propagate a device reset failure out of ndo_open, which XXV bring-up needs, and keep a later ndo_stop safe after a failed resume.
- Add support for the XXV Ethernet subsystem.
- Refactor the statistics into struct axienet_config ops, and add ethtool / ndo_get_stats64 counter reporting for XXV.
---
Notes:
- This series is developed on top of [1]. Only "net: xilinx: axienet:
Derive RX frame length from residue in dmaengine path" from that series is still outstanding; the rest is already in net-next. This series builds and applies without it, but that change is required to get the correct RX completion length on the dmaengine path, which is the only path XXV supports. It is not included here to avoid duplication.
- The series advertises the core's active 10G or 25G rate only. Runtime switching between 10GBASE-R and 25GBASE-R is not supported and can be added later.
- Pause/flow control is not advertised for XXV yet; it is not validated on this IP and will be enabled in a later change.
[1]: https://lore.kernel.org/all/[email protected]/
Changes in v5:
- Patch 1/6:
* Move the comment on why axienet_dma_err_handler() ignores the mac_init() return value into the patch that adds the call.
* Explain the lp->mii_bus NULL guard in the commit message, and fix the axienet_config kernel-doc for pcs_ops, stats_update and internal_pcs.
* Keep a single axienet_setoptions() and put the option table in axienet_config instead of adding a setoptions callback, which every MAC would have implemented identically.
- Patch 2/6:
* Constrain "managed" to in-band-status and disallow phy-handle, pcs-handle and the deprecated phy and phy-device spellings.
* Add an optional "ref" GT reference clock, clarify that the second clock is the GT helper (dclk), and require the first Tx/Rx DMA channel pair. Note that dmas and dma-names pair up by position.
* Add xlnx,has-statistics-counters: the counters are a PG210 build option and no ability register reports whether they were included.
* Explain in the commit message why xlnx,rxmem is required: probe reads it unconditionally and it bounds the largest frame accepted.
* Drop Rob Herring's Reviewed-by, as the binding has changed since v3.
- Patch 3/6 (new):
* Split the ndo_open / ndo_stop / resume changes out of the XXV patch, as they change 1G behaviour and are a prerequisite for it.
* Propagate the axienet_device_reset() error, previously overwritten by phylink_fwnode_phy_connect() before being checked.
* Clear reset_in_progress on the __axienet_device_reset() error paths, which the propagated error would otherwise leave set, freezing the 1G statistics readers.
* Make axienet_stop() a no-op after a failed open, replacing the per-pointer NULL checks posted earlier, which covered neither the NAPI and interrupt paths nor a failed dma_request_chan().
- Patch 4/6:
* Derive the line rate from phy-mode instead of STAT_CORE_SPEED, which PG210 provides only on 64-bit AXI4-Stream builds.
* Program the MAC RX max packet length from max_frm_size so oversized frames are truncated rather than spilling across descriptors, and finalize max_mtu from the MAC's jumbo capability.
* Set default_an_inband, request the optional "ref" clock, and skip the GT registers in ethtool -d on IP versions that lack them.
* Stop advertising pause until flow control is validated, and demote the RX block-lock timeout to a debug message.
* Name the XXV status registers after PG210; two of them described the
wrong register (0x0400 is STAT_TX_STATUS, 0x0408 is STAT_STATUS).
- Drop the "Make axienet_rmon_ranges non-static for reuse" patch. The XXV RMON callback reports only aggregate counters and leaves ranges NULL, so the table was never reused and can stay static.
- Patch 6/6:
* Gate XAE_FEATURE_STATS on xlnx,has-statistics-counters, and gate the TICK drain, the periodic work and the final snapshot on it, so a design without the block is never touched.
* Move the draining tick after GT reset-done, as the readable STAT_* registers hold unknown data until the first TICK.
* Mask the counter MSB to its low 16 bits, so bits outside the 48-bit counter are not accumulated.
* Report FrameCheckSequenceErrors / rx_crc_errors from stat_rx_packet_bad_fcs, and drop "TX Bad FCS" and "TX Frame Error" from ethtool -S, as both are already folded into tx_errors.
* Keep collection on the periodic work; queries copy the software accumulator and can therefore lag it.
V4: https://lore.kernel.org/all/[email protected]/
Changes in v4:
- Drop the "legacy" nomenclature and use dmaengine / non-dmaengine terminology as it might confuse with MAC instead of driver flow (Andrew Lunn).
- Patch 1/6: Gate the "xlnx,txcsum" DT property behind the MAC's tx_csum capability, so TX checksum offload is not advertised for a MAC whose hardware cannot complete checksums.
- Patch 2/6: Reword the binding description to state that the PCS/PMA is integrated into the IP, and that MDIO bus unavailability and SFP module (I2C) management are detailed in the IP (Andrew Lunn).
- Patch 3/6: Reword the dma_err_handler comment from "legacy embedded-DMA (1G) path" to "non-dmaengine flow (1G MAC)" (Andrew Lunn).
- Advertise only the core's active line rate.
V3: https://lore.kernel.org/all/[email protected]/
Changes in v3:
- Dropped patch 1/7 ("clk: Add devm_clk_bulk_get_enable()"); it has been applied to mainline as commit b698927accb1.
- Patch 2/6 (dt-bindings):
* Added Reviewed-by from Rob Herring. Thanks Rob!
V2: https://lore.kernel.org/all/[email protected]/
Changes in v2:
- Patch 1/7:
* Add Reviewed-by: Brian Masney <[email protected]>. Thanks Brian!
- Patch 3/7:
* Split the XXV binding into its own schema file (xlnx,xxv-ethernet.yaml) instead of extending xlnx,axi-ethernet.yaml with if/then branches, per Rob Herring's review.
* Add a multichannel (MCDMA) example.
- Patch 4/7:
* Require both GT reset-done bits in axienet_xxv_poll_link_ready() so polling does not exit before both the TX and RX resets complete.
V1: https://lore.kernel.org/all/[email protected]/
Suraj Gupta (6):
net: xilinx: axienet: Introduce axienet_config for MAC-specific ops
dt-bindings: net: xlnx,xxv-ethernet: Add Xilinx XXV 10G/25G Ethernet
net: xilinx: axienet: Propagate device reset failure from ndo_open
net: xilinx: axienet: Add 10G/25G (XXV) ethernet support
net: xilinx: axienet: Dispatch statistics through axienet_config ops
net: xilinx: axienet: Add statistics support for XXV ethernet
.../bindings/net/xlnx,xxv-ethernet.yaml | 146 ++++ MAINTAINERS | 1 + drivers/net/ethernet/xilinx/Makefile | 3 +- drivers/net/ethernet/xilinx/xilinx_axienet.h | 96 ++- .../net/ethernet/xilinx/xilinx_axienet_main.c | 659 +++++++++++++----- .../net/ethernet/xilinx/xilinx_axienet_xxv.c | 633 +++++++++++++++++ .../net/ethernet/xilinx/xilinx_axienet_xxv.h | 151 ++++ 7 files changed, 1506 insertions(+), 183 deletions(-) create mode 100644 Documentation/devicetree/bindings/net/xlnx,xxv-ethernet.yaml create mode 100644 drivers/net/ethernet/xilinx/xilinx_axienet_xxv.c create mode 100644 drivers/net/ethernet/xilinx/xilinx_axienet_xxv.h
Signature · 1 line
2.25.1
PATCH v5 1/6 net: xilinx: axienet: Introduce axienet_config for MAC-specific ops
Introduce an axienet_config structure to abstract MAC-type-specific operations, preparing the driver for supporting additional MAC types beyond the existing 1G Ethernet.
Add axienet_config with capability flags (mdio, mac_irq, non_dmaengine, uc_filter, mc_filter, vlan, jumbo, tx_csum, sw_padding, internal_pcs), the register-dump count, the MAC option table and callbacks (clk_init, probe_init, gt_reset, mac_init, mac_link_up, get_regs, phylink_set_caps, pcs_ops, stats_update), and populate it from the OF match table. Convert the common code to consult these capabilities and callbacks instead of open-coding 1G behavior, so a new MAC type can be added without adding MAC-specific conditionals to the shared paths.
The MDIO teardown in axienet_remove() is now guarded by a NULL check on lp->mii_bus. This is required by the refactor, because MAC types that do not provide an MDIO bus (such as the XXV MAC added later in this series) leave lp->mii_bus NULL. It also hardens the existing 1G path: a failed axienet_mdio_setup() already left lp->mii_bus NULL while probe only warns and continues (e.g. a 1G device using a fixed-link), so unbinding such a device would dereference NULL in mdiobus_unregister(). Apart from this guard, no functional change is intended for the existing 1G path.
--- drivers/net/ethernet/xilinx/xilinx_axienet.h | 56 +++ .../net/ethernet/xilinx/xilinx_axienet_main.c | 387 ++++++++++++------ 2 files changed, 324 insertions(+), 119 deletions(-)
drivers/net/ethernet/xilinx/xilinx_axienet.h +56 -0
@@ -547,6 +547,7 @@ struct skbuf_dma_descriptor {* @rx_ring_head: RX skb ring buffer head index. * @rx_ring_tail: RX skb ring buffer tail index. * @rx_submit_lock: Protects RX ring resubmission vs teardown in dmaengine path. +* @axienet_config: MAC-type specific configuration and operations. */ struct axienet_local {struct net_device *ndev;
@@ -629,6 +630,61 @@ struct axienet_local {int rx_ring_head;int rx_ring_tail;spinlock_t rx_submit_lock; +const struct axienet_config *axienet_config; +}; + +/** +* struct axienet_config - MAC-type specific configuration and operations +* @mdio: MAC has an MDIO bus for external PHY management +* @mac_irq: MAC has a dedicated core interrupt +* @non_dmaengine: MAC supports the non-dmaengine flow +* @uc_filter: MAC has unicast address filter registers +* @mc_filter: MAC has multicast address filter registers +* @vlan: MAC supports VLAN frames by default +* @jumbo: MAC supports jumbo frames +* @tx_csum: MAC supports TX checksum offload +* @sw_padding: Short frames must be padded in software before transmit +* @internal_pcs: MAC has an internal PCS that phylink should poll; when set, +* the PCS is registered in poll mode at probe +* @regs_n: Number of MAC registers exposed through ethtool -d +* @options: Table mapping the XAE_OPTION_* flags to the MAC register bits +* that enable them, terminated by a zero @opt entry +* @clk_init: Callback to get and enable the MAC-specific clocks +* @probe_init: Callback for MAC-specific probe-time init, or NULL if unused +* @gt_reset: Callback to reset the serial transceiver (GT), or NULL if unused +* @mac_init: Callback for MAC-specific bring-up after the DMA reset +* @mac_link_up: Callback to program link speed and pause on link up, or NULL +* @get_regs: Callback to dump the MAC registers for ethtool -d +* @phylink_set_caps: Callback to set phylink MAC capabilities +* @pcs_ops: phylink PCS operations for this MAC; required when @internal_pcs +* is set, as the PCS is registered without a further NULL check +* @stats_update: Callback to latch/accumulate the periodic MAC counters, or +* NULL if the MAC has no periodic statistics counters +*/ +struct axienet_config { +bool mdio; +bool mac_irq; +bool non_dmaengine; +bool uc_filter; +bool mc_filter; +bool vlan; +bool jumbo; +bool tx_csum; +bool sw_padding; +bool internal_pcs; +unsigned int regs_n; +const struct axienet_option *options; +int (*clk_init)(struct axienet_local *lp); +void (*probe_init)(struct axienet_local *lp); +void (*gt_reset)(struct axienet_local *lp); +int (*mac_init)(struct net_device *ndev); +void (*mac_link_up)(struct net_device *ndev,int speed, +bool tx_pause,bool rx_pause); +void (*get_regs)(struct axienet_local *lp,u32 *data); +void (*phylink_set_caps)(struct axienet_local *lp, +struct phylink_config *config); +const struct phylink_pcs_ops *pcs_ops; +void (*stats_update)(struct axienet_local *lp); };/**
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +268 -119
576 lines not on this page · raw message
Signature · 1 line
2.25.1
[email protected]
AI reviewRe: [PATCH net-next v5 1/6] net: xilinx: axienet: Introduce axienet_config for MAC-specific ops
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [High] net: xilinx: axienet: axienet_probe() fails on software-node devices --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [High] net: xilinx: axienet: axienet_probe() fails on software-node devices
--
commit 783576cb6315304b083793b1e0a0ea48b15baa81
Author: Suraj Gupta <[email protected]>
net: xilinx: axienet: Introduce axienet_config for MAC-specific ops
This commit introduces struct axienet_config to abstract MAC-specific capabilities and callbacks, populating it from axienet_of_match and converting the shared paths to use it.
Quoted 4 lines
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +0
-0
[ ... ]
Quoted 12 lines
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +0
-8@@ -2898,27 +3046,13 @@ static int axienet_probe(struct platform_device *pdev)seqcount_mutex_init (&lp->hw_stats_seqcount, &lp->stats_lock);INIT_DEFERRABLE_WORK (&lp->stats_work, axienet_refresh_stats); - lp->axi_clk =devm_clk_get_optional_enabled (&pdev->dev, -"s_axi_lite_clk" ); -if (!lp->axi_clk) { -/* For backward compatibility, if named AXI clock is not present, -* treat the first clock specified as the AXI clock. -*/ - lp->axi_clk =devm_clk_get_optional_enabled (&pdev->dev,NULL ); - }
drivers/net/ethernet/xilinx/xilinx_axienet_main.c static int axienet_probe(struct platform_device *pdev) · line 3051
Quoted 10 lines
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +3
-7-if (IS_ERR (lp->axi_clk)) -return dev_err_probe (&pdev->dev,PTR_ERR (lp->axi_clk), -"could not get AXI clock\n" ); - - lp->misc_clks[0 ].id ="axis_clk" ; - lp->misc_clks[1 ].id ="ref_clk" ; - lp->misc_clks[2 ].id ="mgt_clk" ; + lp->axienet_config =device_get_match_data (&pdev->dev); +if (!lp->axienet_config) +return -ENODEV ;
[Severity: High]
Does this break probing for platform devices matched by driver name and backed by a software_node, such as those registered after commits f5185ec79dac ("net: axienet: use device_property and fwnode APIs for probe-time config") and 418149559ef3 ("net: axienet: add a MODULE_ALIAS for platform instantiation")?
software_node_ops does not implement .device_get_match_data and axienet_driver has no id_table, so device_get_match_data() returns NULL on non-OF platform devices and axienet_probe() now fails with -ENODEV instead of defaulting to axienet_1g_config.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
[email protected]
AI reviewRe: [PATCH net-next v5 1/6] net: xilinx: axienet: Introduce axienet_config for MAC-specific ops
In reply to Suraj GuptaThank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.
Critical: 0 · High: 1 · Medium: 1 · Low: 0
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [High] net: xilinx: axienet: axienet_probe() fails on software-node devices
- [Medium] This commit is presented as a no-functional-change refactor, but it also contains a real fix for a NULL pointer dereference.
--
net: xilinx: axienet: Introduce axienet_config for MAC-specific ops
This commit adds struct axienet_config, which holds MAC capability flags and MAC-specific callbacks. It is filled in from the OF match table, and the shared 1G code paths now use it. It also puts a NULL check on lp->mii_bus around the MDIO teardown in axienet_remove().
Quoted 4 lines
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +0
-0
[ ... ]
Quoted 17 lines
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +6
-4@@ -3149,10 +3297,12 @@ static int axienet_probe(struct platform_device *pdev) lp->tx_dma_cr =axienet_calc_cr (lp,XAXIDMA_DFT_TX_THRESHOLD ,XAXIDMA_DFT_TX_USEC ); - ret =axienet_mdio_setup (lp); -if (ret) -dev_warn (&pdev->dev, -"error registering MDIO bus: %d\n" , ret); +if (lp->axienet_config->mdio) { + ret =axienet_mdio_setup (lp); +if (ret) +dev_warn (&pdev->dev, +"error registering MDIO bus: %d\n" , ret); + }if (lp->phy_mode ==PHY_INTERFACE_MODE_SGMII || lp->phy_mode ==PHY_INTERFACE_MODE_1000BASEX ) {
[ ... ]
drivers/net/ethernet/xilinx/xilinx_axienet_main.c static void axienet_remove(struct platform_device *pdev) · line 3388
Quoted 8 lines
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +2
-1@@ -3235,7 +3383,8 @@ static void axienet_remove(struct platform_device *pdev)if (lp->pcs_phy)put_device (&lp->pcs_phy->dev); -axienet_mdio_teardown (lp); +if (lp->mii_bus) +axienet_mdio_teardown (lp); }
[Severity: Medium]
Could this NULL check go to net as its own fix, with a Fixes: tag and
Cc: stable, and this refactor then be based on it?
Without the guard, the current 1G driver can oops on unbind. Every failure path in axienet_mdio_setup() frees the bus and sets lp->mii_bus to NULL. The failure paths are an MDC divisor overflow, a timeout in axienet_mdio_wait_until_ready(), and a failed of_mdiobus_register():
drivers/net/ethernet/xilinx/xilinx_axienet_mdio.c:axienet_mdio_setup() {
...
unregister:
of_node_put(mdio_node);
mdiobus_free(bus);
lp->mii_bus = NULL;
return ret;
}axienet_probe() only warns and continues, so the device binds with lp->mii_bus == NULL. Then, on unbind or remove:
axienet_remove()
axienet_mdio_teardown(lp)
mdiobus_unregister(lp->mii_bus)
reads bus->state on a NULL busThe commit message already describes this:
It also hardens the existing 1G path: a failed axienet_mdio_setup() already left lp->mii_bus NULL while probe only warns and continues (e.g. a 1G device using a fixed-link), so unbinding such a device would dereference NULL in mdiobus_unregister().
The fix is part of a large refactor and has no Fixes: tag, so stable and LTS kernels can't backport it. No other patch in the series carries it on its own. Two candidates for the Fixes: tag are the commit that made MDIO setup failure non-fatal in probe and the commit that clears lp->mii_bus on failure.
[ ... ]
Quoted 23 lines
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +3
-15@@ -2894,27 +3042,13 @@ static int axienet_probe(struct platform_device *pdev)seqcount_mutex_init (&lp->hw_stats_seqcount, &lp->stats_lock);INIT_DEFERRABLE_WORK (&lp->stats_work, axienet_refresh_stats); - lp->axi_clk =devm_clk_get_optional_enabled (&pdev->dev, -"s_axi_lite_clk" ); -if (!lp->axi_clk) { -/* For backward compatibility, if named AXI clock is not present, -* treat the first clock specified as the AXI clock. -*/ - lp->axi_clk =devm_clk_get_optional_enabled (&pdev->dev,NULL ); - } -if (IS_ERR (lp->axi_clk)) -return dev_err_probe (&pdev->dev,PTR_ERR (lp->axi_clk), -"could not get AXI clock\n" ); - - lp->misc_clks[0 ].id ="axis_clk" ; - lp->misc_clks[1 ].id ="ref_clk" ; - lp->misc_clks[2 ].id ="mgt_clk" ; + lp->axienet_config =device_get_match_data (&pdev->dev); +if (!lp->axienet_config) +return -ENODEV ;
drivers/net/ethernet/xilinx/xilinx_axienet_main.c static int axienet_probe(struct platform_device *pdev) · line 3054
Quoted 10 lines
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +2
-4- ret =devm_clk_bulk_get_optional_enable (&pdev->dev,XAE_NUM_MISC_CLOCKS , - lp->misc_clks); + ret = lp->axienet_config->clk_init (lp);if (ret) -return dev_err_probe (&pdev->dev, ret, -"could not get/enable misc. clocks\n" ); +return ret;/* Map device registers */ lp->regs =devm_platform_get_and_ioremap_resource (pdev,0 , ðres);
[Severity: High]
This makes missing match data a hard probe failure. Doesn't that break devices that are not instantiated from DT?
device_get_match_data() only asks the device's fwnode, through fwnode_call_ptr_op(dev_fwnode(dev), device_get_match_data, dev). For an OF node that resolves through axienet_of_match. software_node_ops does not implement .device_get_match_data, though, and axienet_driver has no id_table either.
The driver still carries MODULE_ALIAS("platform:" AXIENET_DRIVER_NAME). Probe also reads its configuration through device_property_read_u32() and the fwnode helpers, so a parent driver can create the AXI Ethernet device by name with a software_node attached. The ptp_ocp TimeCard child device is one example. Such a device has no OF match, so device_get_match_data() returns NULL. axienet_probe() then returns -ENODEV before it touches the hardware. Before this patch the same device probed fine as a 1G MAC.
The commit message says no functional change is intended for the existing 1G path, and this is one. As far as I can see the later patches in the series keep this lookup as is, so the regression is still there at the end of the series.
Since every device bound by name today is a 1G MAC, would it be enough to fall back to &axienet_1g_config when device_get_match_data() returns NULL? Or would you rather add a platform_device_id table whose driver_data points at axienet_1g_config, and have probe use platform_get_device_id() when there is no fwnode match data?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261114182947.2908628-1-suraj.gupta2%40amd.com
PATCH v5 2/6 dt-bindings: net: xlnx,xxv-ethernet: Add Xilinx XXV 10G/25G Ethernet
In reply to Suraj GuptaThe XXV Ethernet IP integrates a 10G/25G Ethernet MAC with an in-core PCS/PMA driving a high-speed serial transceiver. Its payload is moved by an external AXI DMA (or multichannel DMA) controller referenced through the dmas/dma-names properties. Document the IP in a dedicated schema file.
Add the "xlnx,xxv-ethernet-1.0" compatible with the 10gbase-r and 25gbase-r phy-modes, the rx_core/drp/s_axi clocks and the AXI DMA channel properties. The GT transceiver reference clock is described as an optional fourth "ref" clock, for boards where it is supplied by a Linux-managed clock provider rather than a fixed oscillator.
Add "xlnx,has-statistics-counters" as well. The statistics counters are an optional part of the IP, selected by the "Include Statistics Counters" build option (PG210), and unlike the 1G MAC the subsystem has no ability register that reports whether they were included, so the devicetree has to describe it.
Require "xlnx,rxmem". The driver reads it unconditionally at probe time and fails if it is absent, and the value is what bounds the largest frame the device accepts, both when validating a new MTU and when deciding whether jumbo frames can be enabled.
Disallow phy-handle, its deprecated phy and phy-device spellings, and pcs-handle. All are inherited from ethernet-controller.yaml, so unevaluatedProperties does not reject them, but the subsystem has no MDIO bus master and its PCS is in-core, so neither an external PHY nor an external PCS can be attached. Constrain managed to in-band-status for the same reason; it stays optional, as the link is always managed in-band.
--- .../bindings/net/xlnx,xxv-ethernet.yaml | 146 ++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 147 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/xlnx,xxv-ethernet.yaml
Documentation/devicetree/bindings/net/xlnx,xxv-ethernet.yaml new file +146 -0
@@ -0,0 +1,146 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/net/xlnx,xxv-ethernet.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Xilinx XXV 10G/25G Ethernet Subsystem + +maintainers: + - Radhey Shyam Pandey <[email protected]> + - Suraj Gupta <[email protected]> + +description: + The Xilinx XXV Ethernet Subsystem implements a 10G/25G Ethernet MAC with an + in-core PCS/PMA driving a high-speed serial transceiver. It supports the + 10GBASE-R and 25GBASE-R line rates, with 25G operation following the 25G + Ethernet Consortium specification. Because the PCS/PMA is integrated into + the IP, the subsystem has no MDIO bus master and is not managed through an + external MDIO PHY; link state is read from the MAC's own status registers. + As there is no PHY to manage, the link is always managed in-band. + Any SFP module management (e.g. I2C) is handled by separate IP outside this + binding. Its payload is moved by an external AXI DMA (or multichannel DMA) + controller referenced through the "dmas" property. + +properties: + compatible: + const: xlnx,xxv-ethernet-1.0 + + reg: + maxItems: 1 + description: MAC control and status register space. + + clocks: + minItems: 3 + items: + - description: RX AXI4-Stream clock. + - description: GT helper (dclk) stable clock. + - description: AXI4-Lite register clock. + - description: GT transceiver reference clock (refclk). + + clock-names: + minItems: 3 + items: + - const: rx_core + - const: drp + - const: s_axi + - const: ref + + phy-mode: + enum: + - 10gbase-r + - 25gbase-r + + # The subsystem has no MDIO bus master and its PCS is in-core, so neither + # an external PHY nor an external PCS can be attached. phy and phy-device + # are the deprecated spellings of phy-handle. + phy-handle: false + phy: false + phy-device: false + pcs-handle: false + + managed: + const: in-band-status + + xlnx,rxmem: + description: + Size in bytes of the Rx/Tx packet buffer memory built into the IP. It is + fixed by the hardware design and bounds the largest frame (jumbo MTU) the + device can accept. + $ref: /schemas/types.yaml#/definitions/uint32 + + xlnx,has-statistics-counters: + description: + The statistics counters are an optional part of the IP, selected by the + "Include Statistics Counters" build option, and the subsystem does not + advertise whether they were included. Present when the design was built + with them, in which case the driver reports the MAC counters through + ethtool and ndo_get_stats64. + type: boolean + + dmas: + minItems: 2 + maxItems: 32 + description: + TX and RX DMA channel phandles, one per entry in "dma-names". + + dma-names: + minItems: 2 + maxItems: 32 + items: + pattern: "^[tr]x_chan([0-9]|1[0-5])$" + allOf: + - contains: + const: tx_chan0 + - contains: + const: rx_chan0 + description: + Should be "tx_chan0", "tx_chan1" ... "tx_chan15" for DMA Tx channel and + "rx_chan0", "rx_chan1" ... "rx_chan15" for DMA Rx channel. The first + Tx/Rx channel pair ("tx_chan0" and "rx_chan0") is always required. There + is one name per entry in "dmas", in the same order. + +required: + - compatible + - reg + - clocks + - clock-names + - phy-mode + - xlnx,rxmem + - dmas + - dma-names + +allOf: + - $ref: /schemas/net/ethernet-controller.yaml# + +unevaluatedProperties: false + +examples: + # Single AXI DMA channel pair + - | + ethernet@80000000 { + compatible = "xlnx,xxv-ethernet-1.0"; + reg = <0x80000000 0x10000>; + clock-names = "rx_core", "drp", "s_axi"; + clocks = <&rx_clk>, <&drp_clk>, <&axi_clk>; + dma-names = "tx_chan0", "rx_chan0"; + dmas = <&axi_dma 0>, <&axi_dma 1>; + phy-mode = "25gbase-r"; + managed = "in-band-status"; + xlnx,rxmem = <0x8000>; + xlnx,has-statistics-counters; + }; + # Multichannel DMA (MCDMA) with multiple Tx/Rx channels + - | + ethernet@80010000 { + compatible = "xlnx,xxv-ethernet-1.0"; + reg = <0x80010000 0x10000>; + clock-names = "rx_core", "drp", "s_axi"; + clocks = <&rx_clk>, <&drp_clk>, <&axi_clk>; + dma-names = "tx_chan0", "tx_chan1", "rx_chan0", "rx_chan1"; + dmas = <&axi_mcdma 0>, <&axi_mcdma 1>, + <&axi_mcdma 16>, <&axi_mcdma 17>; + phy-mode = "10gbase-r"; + managed = "in-band-status"; + xlnx,rxmem = <0x8000>; + };
MAINTAINERS +1 -0
@@ -30683,6 +30683,7 @@ XILINX AXI ETHERNET DRIVER M: Radhey Shyam Pandey <[email protected]> S: Maintained F: Documentation/devicetree/bindings/net/xlnx,axi-ethernet.yaml +F: Documentation/devicetree/bindings/net/xlnx,xxv-ethernet.yaml F: drivers/net/ethernet/xilinx/xilinx_axienet* XILINX CAN DRIVER
Signature · 1 line
2.25.1
[email protected]
AI reviewRe: [PATCH net-next v5 2/6] dt-bindings: net: xlnx,xxv-ethernet: Add Xilinx XXV 10G/25G Ethernet
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] Documentation/devicetree/bindings/net/xlnx,xxv-ethernet.yaml blocks the inherited properties that conflict with its stated design:…
--
dt-bindings: net: xlnx,xxv-ethernet: Add Xilinx XXV 10G/25G Ethernet
This commit adds a dedicated schema for the Xilinx XXV 10G/25G Ethernet subsystem, which has an in-core PCS/PMA and uses an external AXI DMA or MCDMA controller. It requires xlnx,rxmem and adds the optional xlnx,has-statistics-counters property. It also disallows phy-handle, phy, phy-device and pcs-handle, and restricts managed to in-band-status.
Quoted 5 lines
Documentation/devicetree/bindings/net/xlnx,xxv-ethernet.yaml new file +0
-0
[ ... ]
Quoted 5 lines
Documentation/devicetree/bindings/net/xlnx,xxv-ethernet.yaml new file +5
-0+ phy-mode: + enum: + - 10gbase-r + - 25gbase-r +
Documentation/devicetree/bindings/net/xlnx,xxv-ethernet.yaml line 63
Quoted 10 lines
Documentation/devicetree/bindings/net/xlnx,xxv-ethernet.yaml new file +10
-0+ # The subsystem has no MDIO bus master and its PCS is in-core, so neither + # an external PHY nor an external PCS can be attached. phy and phy-device + # are the deprecated spellings of phy-handle. + phy-handle: false + phy: false + phy-device: false + pcs-handle: false + + managed: + const: in-band-status
[Severity: Low]
Should fixed-link also be set to false here?
fixed-link comes in through the ethernet-controller.yaml $ref in the same way as the other blocked properties, so unevaluatedProperties: false does not reject it. ethernet-controller.yaml also does not make fixed-link and managed mutually exclusive. Its only dependencies entry is pcs-handle-names requiring pcs-handle.
The commit message and the binding description both say "the link is always managed in-band". Even so, this schema accepts two configurations that go against that.
The first is a node with fixed-link alone. In drivers/net/phy/phylink.c, phylink_parse_mode() checks fixed-link after the in-band default:
if (pl->config->default_an_inband) pl->cfg_link_an_mode = MLO_AN_INBAND; dn = fwnode_get_named_child_node(fwnode, "fixed-link"); if (dn || fwnode_property_present(fwnode, "fixed-link")) pl->cfg_link_an_mode = MLO_AN_FIXED;
This overrides the default_an_inband = true that axienet_xxv_phylink_set_capabilities() sets in the XXV driver patch later in this series. Carrier would then come from the emulated fixed state, not from the PCS status that axienet_xxv_pcs_get_state() reads.
The second is a node with fixed-link plus managed = "in-band-status". The binding allows both properties, but phylink_parse_mode() rejects the combination:
if (pl->cfg_link_an_mode == MLO_AN_FIXED) {
phylink_err(pl,
"can't use both fixed-link and in-band-status\n");
return -EINVAL;
}So the device fails to probe from axienet_probe()->phylink_create(), even though dt_binding_check accepted the node.
Later patches in the series don't change this binding file, so the gap is still there at the end of the series. Adding "fixed-link: false" next to the other blocked properties would close it.
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261114182947.2908628-1-suraj.gupta2%40amd.com
Rob Herring
maintainerRe: [PATCH net-next v5 2/6] dt-bindings: net: xlnx,xxv-ethernet: Add Xilinx XXV 10G/25G Ethernet
In reply to Suraj GuptaQuoted 60 lines · Suraj Gupta
The XXV Ethernet IP integrates a 10G/25G Ethernet MAC with an in-core PCS/PMA driving a high-speed serial transceiver. Its payload is moved by an external AXI DMA (or multichannel DMA) controller referenced through the dmas/dma-names properties. Document the IP in a dedicated schema file.
Add the "xlnx,xxv-ethernet-1.0" compatible with the 10gbase-r and 25gbase-r phy-modes, the rx_core/drp/s_axi clocks and the AXI DMA channel properties. The GT transceiver reference clock is described as an optional fourth "ref" clock, for boards where it is supplied by a Linux-managed clock provider rather than a fixed oscillator.
Add "xlnx,has-statistics-counters" as well. The statistics counters are an optional part of the IP, selected by the "Include Statistics Counters" build option (PG210), and unlike the 1G MAC the subsystem has no ability register that reports whether they were included, so the devicetree has to describe it.
Require "xlnx,rxmem". The driver reads it unconditionally at probe time and fails if it is absent, and the value is what bounds the largest frame the device accepts, both when validating a new MTU and when deciding whether jumbo frames can be enabled.
Disallow phy-handle, its deprecated phy and phy-device spellings, and pcs-handle. All are inherited from
ethernet-controller.yaml, so unevaluatedProperties does not reject them, but the subsystem has no MDIO bus master and its PCS is in-core, so neither an external PHY nor an external PCS can be attached. Constrain managed to in-band-status for the same reason; it stays optional, as the link is always managed in-band.Signed-off-by Suraj Gupta <[email protected]>--- .../bindings/net/xlnx,xxv-ethernet.yaml | 146 ++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 147 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/xlnx,xxv-ethernet.yamlDocumentation/devicetree/bindings/net/xlnx,xxv-ethernet.yaml new file +17
-0@@ -0,0 +1,146 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/net/xlnx,xxv-ethernet.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Xilinx XXV 10G/25G Ethernet Subsystem + +maintainers: + - Radhey Shyam Pandey <[email protected]> + - Suraj Gupta <[email protected]> + +description: + The Xilinx XXV Ethernet Subsystem implements a 10G/25G Ethernet MAC with an + in-core PCS/PMA driving a high-speed serial transceiver. It supports the + 10GBASE-R and 25GBASE-R line rates, with 25G operation following the 25G + Ethernet Consortium specification. Because the PCS/PMA is integrated into
Documentation/devicetree/bindings/net/xlnx,xxv-ethernet.yaml line 27
Quoted 10 lines
Documentation/devicetree/bindings/net/xlnx,xxv-ethernet.yaml new file +10
-0+ the IP, the subsystem has no MDIO bus master and is not managed through an + external MDIO PHY; link state is read from the MAC's own status registers. + As there is no PHY to manage, the link is always managed in-band. + Any SFP module management (e.g. I2C) is handled by separate IP outside this + binding. Its payload is moved by an external AXI DMA (or multichannel DMA) + controller referenced through the "dmas" property. + +properties: + compatible: + const: xlnx,xxv-ethernet-1.0
I hope you based 1.0 on something? Looks made up to me.
From here[1], looks like you are missing some versions:
The offset of user configuration registers in the IP was updated (and removed in case of USER_REG_1) which breaks backward compatibility of any custom user config application code with newer versions of the IP. Please make sure to use the correct offset as per the IP version as specific below and ignore "XXE_USR0_OFFSET". Please note that this has NO impact on the example as this definition is not used.
Upto IP Version 2.2 https://docs.xilinx.com/v/u/2.2-English/pg210-25g-ethernet, USER_REG_0 is at offset 0x184 and USER_REG_1 is at offset 0x188 IP Version 2.3 and above https://docs.xilinx.com/v/u/2.3-English/pg210-25g-ethernet, USER_REG_0 is at offset 0x134 and USER_REG_1 is removed
Rob
[1] https://xilinx-wiki.atlassian.net/wiki/spaces/A/pages/18842542/Baremetal+XXV+Ethernet+driver
Re: [PATCH net-next v5 2/6] dt-bindings: net: xlnx,xxv-ethernet: Add Xilinx XXV 10G/25G Ethernet
Hi Rob,
Quoted 83 lines · Rob Herring
Quoted 60 lines · Suraj Gupta
The XXV Ethernet IP integrates a 10G/25G Ethernet MAC with an in-core PCS/PMA driving a high-speed serial transceiver. Its payload is moved by an external AXI DMA (or multichannel DMA) controller referenced through the dmas/dma-names properties. Document the IP in a dedicated schema file.
Add the "xlnx,xxv-ethernet-1.0" compatible with the 10gbase-r and 25gbase-r phy-modes, the rx_core/drp/s_axi clocks and the AXI DMA channel properties. The GT transceiver reference clock is described as an optional fourth "ref" clock, for boards where it is supplied by a Linux-managed clock provider rather than a fixed oscillator.
Add "xlnx,has-statistics-counters" as well. The statistics counters are an optional part of the IP, selected by the "Include Statistics Counters" build option (PG210), and unlike the 1G MAC the subsystem has no ability register that reports whether they were included, so the devicetree has to describe it.
Require "xlnx,rxmem". The driver reads it unconditionally at probe time and fails if it is absent, and the value is what bounds the largest frame the device accepts, both when validating a new MTU and when deciding whether jumbo frames can be enabled.
Disallow phy-handle, its deprecated phy and phy-device spellings, and pcs-handle. All are inherited from
ethernet-controller.yaml, so unevaluatedProperties does not reject them, but the subsystem has no MDIO bus master and its PCS is in-core, so neither an external PHY nor an external PCS can be attached. Constrain managed to in-band-status for the same reason; it stays optional, as the link is always managed in-band.Signed-off-by Suraj Gupta <[email protected]>--- .../bindings/net/xlnx,xxv-ethernet.yaml | 146 ++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 147 insertions(+)create mode 100644
Documentation/devicetree/bindings/net/xlnx,xxv-ethernet.yamlDocumentation/devicetree/bindings/net/xlnx,xxv-ethernet.yaml new file +17
-0@@ -0,0 +1,146 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/net/xlnx,xxv-ethernet.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Xilinx XXV 10G/25G Ethernet Subsystem + +maintainers: + - Radhey Shyam Pandey <[email protected]> + - Suraj Gupta <[email protected]> + +description: + The Xilinx XXV Ethernet Subsystem implements a 10G/25G Ethernet MAC with an + in-core PCS/PMA driving a high-speed serial transceiver. It supports the + 10GBASE-R and 25GBASE-R line rates, with 25G operation following the 25G + Ethernet Consortium specification. Because the PCS/PMA is integrated intoDocumentation/devicetree/bindings/net/xlnx,xxv-ethernet.yaml line 27
Quoted 10 lines
Documentation/devicetree/bindings/net/xlnx,xxv-ethernet.yaml new file +10
-0+ the IP, the subsystem has no MDIO bus master and is not managed through an + external MDIO PHY; link state is read from the MAC's own status registers. + As there is no PHY to manage, the link is always managed in-band. + Any SFP module management (e.g. I2C) is handled by separate IP outside this + binding. Its payload is moved by an external AXI DMA (or multichannel DMA) + controller referenced through the "dmas" property. + +properties: + compatible: + const: xlnx,xxv-ethernet-1.0I hope you based 1.0 on something? Looks made up to me.
From here[1], looks like you are missing some versions:
The offset of user configuration registers in the IP was updated (and removed in case of
USER_REG_1) which breaks backward compatibility of any custom user config application code with newer versions of the IP. Please make sure to use the correct offset as per the IP version as specific below and ignore "XXE_USR0_OFFSET". Please note that this has NO impact on the example as this definition is not used.
Quoted 7 lines
Upto IP Version 2.2 https://docs.xilinx.com/v/u/2.2-English/pg210-25g-ethernet, USER_REG_0 is at offset 0x184 and USER_REG_1 is at offset 0x188 IP Version 2.3 and above https://docs.xilinx.com/v/u/2.3-English/pg210-25g-ethernet, USER_REG_0 is at offset 0x134 and USER_REG_1 is removedRob
[1] https://xilinx-wiki.atlassian.net/wiki/spaces/A/pages/18842542/Baremetal+XXV+Ethernet+driver
1.0 is the initial release of this IP: PG210 v1.0, 2015-09-30, "Initial release" [1]. The compatible names that version. Newer cores are handled from the revision register (CONFIGURATION_REVISION_REG, 0x24), read into lp->xxv_ip_version. Today that gates only the GT status registers, which PG210 adds in v3.2. The same v3.2 changelog adds bit 0 of STAT_RX_STATUS_REG1 (0x404). v5 reads that bit unconditionally for the link state, so I will gate it on v3.2 and later in v6.
The driver does not use USER_REG_0, so the v2.3 move (0x184 to 0x134) and the removal of USER_REG_1 do not affect it. The wiki pointed above describes the baremetal XXV driver.
[1] https://docs.amd.com/r/en-US/pg210-25g-ethernet/Revision-History
Regards,
Suraj
PATCH v5 3/6 net: xilinx: axienet: Propagate device reset failure from ndo_open
In reply to Suraj Guptaaxienet_open() overwrites the axienet_device_reset() return value with the phylink_fwnode_phy_connect() one before it is ever checked, so a failed reset brings the device up anyway. Check and propagate it.
That makes a failed ndo_open reachable, which matters for axienet_resume():
it calls ndo_open directly, so unlike the netdev core it leaves the device running when open fails. A later ndo_stop then tears down resources that open had already unwound and never re-created. For the dmaengine flow that is a double free of the skb rings and a second dma_release_channel(); for the non-dmaengine flow it is napi_disable() on an already disabled NAPI, which never returns, and free_irq() on interrupts that were never requested.
Track whether ndo_open completed and make axienet_stop() a no-op otherwise.
axienet_resume() now propagates the error, but it still has to undo the netif_device_detach() that axienet_suspend() did. Leaving the device detached while it is still IFF_UP wedges the interface: ndo_stop is a no-op, so bringing it down appears to work, while bringing it up again fails with -ENODEV because the device is not present. Drop IFF_UP with netif_close() before reattaching, so the interface can be brought up again once the cause of the failure is resolved, and so the stack cannot transmit on the datapath open has already torn down.
Clearing the error path of __axienet_device_reset() goes with this: it jumps over the block that clears lp->reset_in_progress, and the statistics work that used to clear it on the next run is no longer scheduled once the reset error is propagated. Without this, axienet_stat() would keep returning the frozen base after a reset timeout.
--- drivers/net/ethernet/xilinx/xilinx_axienet.h | 2 + .../net/ethernet/xilinx/xilinx_axienet_main.c | 44 +++++++++++++++++-- 2 files changed, 42 insertions(+), 4 deletions(-)
drivers/net/ethernet/xilinx/xilinx_axienet.h +2 -0
@@ -526,6 +526,7 @@ struct skbuf_dma_descriptor {* @stopping: Set when we are about to stop the device: makes @dma_err_task * a no-op (legacy DMA path) and fences RX descriptor * resubmission in axienet_dma_rx_cb() (dmaengine path). +* @datapath_up: Set while the resources allocated by ndo_open are live. * @tx_irq: Axidma TX IRQ number * @rx_irq: Axidma RX IRQ number * @eth_irq: Ethernet core IRQ number
@@ -608,6 +609,7 @@ struct axienet_local {struct work_struct dma_err_task;bool stopping; +bool datapath_up;int tx_irq;int rx_irq;
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +40 -4
81 lines not on this page · raw message
Signature · 1 line
2.25.1
[email protected]
AI reviewRe: [PATCH net-next v5 3/6] net: xilinx: axienet: Propagate device reset failure from ndo_open
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Medium] net: xilinx: axienet: u32 stats underflow on __axienet_device_reset() failure - [Medium] net…
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [Medium] net: xilinx: axienet: u32 stats underflow on __axienet_device_reset() failure
- [Medium] net: xilinx: axienet: leaked legacy DMA rings and active DMA on open failure
--
commit 13e0ec7cb747f36a50832556f5abcdb18558f153
Author: Suraj Gupta <[email protected]>
net: xilinx: axienet: Propagate device reset failure from ndo_open
This commit checks and propagates the return value of axienet_device_reset() in axienet_open(), tracks whether ndo_open completed via lp->datapath_up so axienet_stop() is a no-op otherwise, handles reopen failures in axienet_resume(), and clears lp->reset_in_progress on __axienet_device_reset() failure.
Quoted 12 lines
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +4
-0@@ -703,6 +703,17 @@ static int __axienet_device_reset(struct axienet_local *lp) } out: +/* On failure the block above is skipped, so clear the flag here. +* axienet_open() now returns on a reset error without scheduling the +* statistics work that used to clear it, which would otherwise leave +* axienet_stat() returning the frozen base until a reset succeeds.
drivers/net/ethernet/xilinx/xilinx_axienet_main.c static int __axienet_device_reset(struct axienet_local *lp) · line 719
Quoted 10 lines
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +7
-0+*/ +if (ret && (lp->features &XAE_FEATURE_STATS )) { +write_seqcount_begin (&lp->hw_stats_seqcount); + lp->reset_in_progress = false; +write_seqcount_end (&lp->hw_stats_seqcount); + } +mutex_unlock (&lp->stats_lock);return ret; }
[Severity: Medium]
Can clearing lp->reset_in_progress here without updating lp->hw_last_counter[] cause a 32-bit unsigned underflow in axienet_stat() and axienet_stats_update()?
At the start of __axienet_device_reset(), axienet_stats_update(lp, true) saves the pre-reset counter values in lp->hw_last_counter[], and writing XAXIDMA_CR_RESET_MASK resets the Axi Ethernet core and zeroes the hardware statistics registers. If the subsequent PhyRstCmplt poll times out and jumps to out, the loop that resynchronizes lp->hw_last_counter[] is skipped. With lp->reset_in_progress cleared, axienet_stat() reads zero from the hardware counter and subtracts the non-zero pre-reset lp->hw_last_counter[stat] in 32-bit unsigned arithmetic, inflating the reported 64-bit statistics by ~2^32 (and permanently folding that underflow into lp->hw_stat_base[] on the next axienet_stats_update()):
drivers/net/ethernet/xilinx/xilinx_axienet_main.c:axienet_stat() {
...
if (lp->reset_in_progress)
return lp->hw_stat_base[stat];
counter = axienet_ior(lp, XAE_STATS_OFFSET + stat * 8);
return lp->hw_stat_base[stat] + (counter - lp->hw_last_counter[stat]);
}Quoted 23 lines
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +6
-0@@ -1776,6 +1787,10 @@ static int axienet_open(struct net_device *ndev)axienet_lock_mii (lp); ret =axienet_device_reset (ndev);axienet_unlock_mii (lp); +if (ret) { +dev_err (lp->dev,"axienet_device_reset() failed: %d\n" , ret); +return ret; + } ret =phylink_fwnode_phy_connect (lp->phylink,dev_fwnode (lp->dev),0 );if (ret) {@@ -1806,6 +1821,8 @@ static int axienet_open(struct net_device *ndev) goto err_phy; } + lp->datapath_up = true; +return 0 ; err_free_eth_irq:@@ -1834,6 +1851,16 @@ static int axienet_stop(struct net_device *ndev)struct axienet_local *lp =netdev_priv (ndev);int i;
drivers/net/ethernet/xilinx/xilinx_axienet_main.c static int axienet_stop(struct net_device *ndev) · line 1862
Quoted 10 lines
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +9
-0+/* axienet_resume() calls ndo_open directly, so unlike the netdev core +* it can leave the device running after a failed open. Tearing down +* below would then stop a phylink that open already stopped and +* disconnected, and free interrupts it never requested. +*/ +if (!lp->datapath_up) +return 0 ; + + lp->datapath_up = false;
[Severity: Medium]
When axienet_open() fails on the non-dmaengine path after axienet_dma_bd_init() succeeds, does returning with lp->datapath_up set to false leak the DMA descriptor rings and leave DMA running?
In the !lp->use_dmaengine path, axienet_device_reset() calls axienet_dma_bd_init(), which allocates lp->tx_bd_v, lp->rx_bd_v and RX skbs and starts DMA, and then enables XAE_OPTION_TXEN | XAE_OPTION_RXEN. If phylink_fwnode_phy_connect() or axienet_init_legacy_dma() then fails (or if lp->axienet_config->mac_init() fails inside axienet_device_reset()), axienet_open() returns an error without calling axienet_dma_stop() or axienet_dma_bd_release(). Because lp->datapath_up remains false, axienet_stop() (including via netif_close() in axienet_resume()) now returns early as well, leaving hardware DMA active and leaking the coherent rings and mapped RX skbs, which are overwritten on the next axienet_open().
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
[email protected]
AI reviewRe: [PATCH net-next v5 3/6] net: xilinx: axienet: Propagate device reset failure from ndo_open
In reply to Suraj GuptaThank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 3 · Low: 2
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] The patch fixes user-visible bugs in existing kernels but has no Fixes: tag, and it is sent as the third patch of an XXV feature…
- [Medium] net: xilinx: axienet: u32 stats underflow on __axienet_device_reset() failure
- [Medium] net: xilinx: axienet: leaked legacy DMA rings and active DMA on open failure
- [Low] The commit message presents the resume/stop changes as a side effect of the new reset check.
- [Low] The comment added to axienet_stop() justifies the datapath_up guard with "axienet_resume() calls ndo_open directly, so unlike the…
--
net: xilinx: axienet: Propagate device reset failure from ndo_open
With this patch, axienet_open() now returns the error from axienet_device_reset(). A new datapath_up flag makes axienet_stop() a no-op when ndo_open did not complete. axienet_resume() now propagates the open failure and calls netif_close() before it reattaches the device. The patch also clears reset_in_progress on the error path of __axienet_device_reset().
Quoted 3 lines
That makes a failed
ndo_openreachable, which matters foraxienet_resume():
it callsndo_opendirectly, so unlike the netdev core it leaves the device running when open fails.
[Severity: Low]
Is this description accurate? Before this patch, axienet_open() could already fail without the reset being involved:
- phylink_fwnode_phy_connect() failure returns directly
- request_irq(lp->eth_irq) failure on the dmaengine path goes to err_phy
- axienet_init_dmaengine() failure (dma_request_chan() or the ring allocations) goes to err_free_eth_irq
- request_irq() failures inside axienet_init_legacy_dma() go to err_phy, after napi_disable()
Since a3de357b087e ("net: axiemac: add PM callbacks to support suspend/resume"), axienet_resume() has ignored the axienet_open() return value and always called netif_device_attach(). The device stayed IFF_UP after any of those failures.
A later ndo_stop then ran the full teardown. On the legacy path that is napi_disable() on an already disabled NAPI with RTNL held, plus free_irq() on IRQs that were never requested. On the dmaengine path it is dma_release_channel() on released channels and a second kfree() of tx_skb_ring/rx_skb_ring.
Could the commit message describe these as existing bugs, rather than as a consequence of the new reset check?
Quoted 4 lines
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +0
-0
[ ... ]
drivers/net/ethernet/xilinx/xilinx_axienet_main.c static int axienet_stop(struct net_device *ndev) · line 1860
Quoted 11 lines
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +7
-0@@ -1834,6 +1851,16 @@ static int axienet_stop(struct net_device *ndev)struct axienet_local *lp =netdev_priv (ndev);int i; +/* axienet_resume() calls ndo_open directly, so unlike the netdev core +* it can leave the device running after a failed open. Tearing down +* below would then stop a phylink that open already stopped and +* disconnected, and free interrupts it never requested. +*/ +if (!lp->datapath_up) +return 0 ;
[Severity: Low]
This comment says axienet_resume() can leave the device running after a failed open. The same patch changes axienet_resume() to call netif_close() on that failure.
Isn't that netif_close() call the path that actually reaches axienet_stop() with datapath_up == false?
axienet_resume()
axienet_open() <- fails
netif_close()
netif_close_many()
__dev_close_many()
ops->ndo_stop() -> axienet_stop()The device is still IFF_UP at this point, because axienet_suspend() calls axienet_stop() directly.
Could the comment describe the netif_close() path instead, so the guard is not later mistaken for dead code and removed?
Quoted 3 lines
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +3
-0+ + lp->datapath_up = false; +
[ ... ]
Quoted 19 lines
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +7
-3@@ -3419,17 +3446,26 @@ static int axienet_suspend(struct device *dev)static int axienet_resume (struct device *dev) {struct net_device *ndev =dev_get_drvdata (dev); +int ret;if (!netif_running (ndev))return 0 ;rtnl_lock (); -axienet_open (ndev); -rtnl_unlock (); - + ret =axienet_open (ndev); +if (ret) { +netdev_err (ndev,"failed to reopen device on resume: %d\n" , ret); +/* Drop IFF_UP before reattaching, so that the interface can be +* brought up again once whatever made open fail is resolved. +* Reattaching while still up would also let the stack transmit
drivers/net/ethernet/xilinx/xilinx_axienet_main.c static int axienet_suspend(struct device *dev) · line 3469
Quoted 10 lines
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +6
-1+* on the datapath open has already torn down. +*/ +netif_close (ndev); + }netif_device_attach (ndev); +rtnl_unlock (); -return 0 ; +return ret; }
[Severity: Medium]
Does this leave the legacy DMA rings allocated and the DMA running when open fails after the reset?
On the non-dmaengine path, axienet_device_reset() calls axienet_dma_bd_init(). That allocates lp->tx_bd_v and lp->rx_bd_v with dma_alloc_coherent(), allocates and maps lp->rx_bd_num RX skbs, and starts both DMA channels. axienet_device_reset() then runs mac_init() and enables XAE_OPTION_TXEN | XAE_OPTION_RXEN.
None of the failure exits that follow undo that:
- mac_init() failing inside axienet_device_reset(), which this patch turns into an open failure
- phylink_fwnode_phy_connect() failing, which returns directly
- axienet_init_legacy_dma() failing, which goes to err_phy
err_phy only cancels the work items and stops and disconnects phylink. Nothing calls axienet_dma_stop() or axienet_dma_bd_release(), and TXEN and RXEN stay set.
With the new datapath_up guard, axienet_stop() will not clean this up either. That includes the case where it is reached through netif_close() in axienet_resume():
axienet_resume()
axienet_open() <- fails after axienet_dma_bd_init()
netif_close()
axienet_stop() <- datapath_up == false, returns 0
The descriptor rings and the mapped RX skbs are therefore never freed, and the DMA engine and the MAC keep running while the interface is down. The next axienet_open() calls axienet_dma_bd_init() again and overwrites lp->tx_bd_v and lp->rx_bd_v, which leaks the previous rings.
Should the error paths in axienet_open() unwind axienet_device_reset() on the legacy path, by stopping the DMA and calling axienet_dma_bd_release()? Then datapath_up == false would really mean there is nothing left to tear down.
[Severity: Medium]
This fixes bugs that exist in released kernels. Should it carry Fixes:
tags and go to net as a standalone fix, instead of being the third patch of the XXV feature series?
The reset return value being overwritten by the phylink_fwnode_phy_connect() result goes back at least to:
The resume handling that leaves the device IFF_UP after a failed reopen comes from:
Without a Fixes: tag, the stable tooling will not pick up the datapath_up guard or the netif_close() handling here. In stable kernels, an ifdown after a failed resume can then hang in napi_disable() with RTNL held on the legacy DMA path. On the dmaengine path it can release the DMA channels again and free tx_skb_ring/rx_skb_ring a second time.
[ ... ]
Quoted 8 lines
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +4
-0@@ -702,6 +702,17 @@ static int __axienet_device_reset(struct axienet_local *lp) } out: +/* On failure the block above is skipped, so clear the flag here. +* axienet_open() now returns on a reset error without scheduling the +* statistics work that used to clear it, which would otherwise leave +* axienet_stat() returning the frozen base until a reset succeeds.
drivers/net/ethernet/xilinx/xilinx_axienet_main.c static int __axienet_device_reset(struct axienet_local *lp) · line 718
Quoted 10 lines
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +7
-0+*/ +if (ret && (lp->features &XAE_FEATURE_STATS )) { +write_seqcount_begin (&lp->hw_stats_seqcount); + lp->reset_in_progress = false; +write_seqcount_end (&lp->hw_stats_seqcount); + } +mutex_unlock (&lp->stats_lock);return ret; }
[Severity: Medium]
Does clearing reset_in_progress here leave hw_last_counter[] stale?
At the top of this function, axienet_stats_update(lp, true) stores the pre-reset counter values in lp->hw_last_counter[] and sets lp->reset_in_progress. The XAXIDMA_CR_RESET_MASK write that follows resets the Ethernet core along with the DMA, which zeroes the statistics counters. On either timeout, the goto out skips the loop that folds the reset into hw_stat_base[] and reloads hw_last_counter[].
With reset_in_progress now cleared, axienet_stat() computes
lp->hw_stat_base[stat] + (counter - lp->hw_last_counter[stat])
where counter is the u32 read back from the core. That value is 0 after the reset. If the DMA reset poll is the one that timed out, it is whatever the core returns while still held in reset.
For every counter that was non-zero before the reset, the u32 subtraction wraps. ndo_get_stats64 and the ethtool stats then report values close to 2^32 too high. The next axienet_stats_update(), from the stats work or the next reset, adds the same wrapped delta into hw_stat_base[], so the error becomes permanent.
The statistics work this replaces would have hit the same wrap through axienet_stats_update(lp, false). This patch makes it the explicit outcome of a failed reset, though.
Should the error path resynchronise hw_last_counter[] from the hardware when the counters are readable? Or is keeping the frozen base the safer choice when the core may not have come out of reset?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261114182947.2908628-1-suraj.gupta2%40amd.com
PATCH v5 4/6 net: xilinx: axienet: Add 10G/25G (XXV) ethernet support
In reply to Suraj GuptaThe AXI Ethernet driver currently supports only the AXI 1G Ethernet IP. Add support for the Xilinx XXV Ethernet IP[1], which implements a 10G/25G Ethernet MAC with PCS/PMA driving a high-speed serial transceiver, as specified by the 25G Ethernet Consortium.
Add the XXV-specific logic in new xilinx_axienet_xxv.c/.h files and describe the MAC through an axienet_10g25g_config that provides the capability flags, the MAC option table and callbacks (GT reset, link-ready polling, phylink caps, PCS ops, register dump and probe-time init). The shared paths consult those capabilities and callbacks instead of MAC-type checks; the only interface-specific addition is handling the 10GBASER and 25GBASER modes in axienet_mac_select_pcs().
The register, RX and GT DRP clocks are required. The GT reference clock is requested as optional, because it is usually a fixed oscillator that Linux does not model; where a board does describe it as a gated provider it has to be enabled, as the GT otherwise never reports reset-done.
The advertised rate comes from the required phy-mode property rather than from the STAT_CORE_SPEED register, which PG210 provides only on the 64-bit AXI4-Stream builds; a node declaring any other phy-mode is rejected at probe. Cores built with runtime rate switching are not reconfigured to the other rate, and flow control is not wired up, so pause support is not advertised either.
The XXV mac_init() can fail on a GT reset-done timeout, which is why ndo_open has to propagate a device reset failure as of the preceding patch.
[1]: https://docs.amd.com/r/en-US/pg210-25g-ethernet
--- drivers/net/ethernet/xilinx/Makefile | 3 +- drivers/net/ethernet/xilinx/xilinx_axienet.h | 9 + .../net/ethernet/xilinx/xilinx_axienet_main.c | 23 +- .../net/ethernet/xilinx/xilinx_axienet_xxv.c | 351 ++++++++++++++++++ .../net/ethernet/xilinx/xilinx_axienet_xxv.h | 93 +++++ 5 files changed, 470 insertions(+), 9 deletions(-) create mode 100644 drivers/net/ethernet/xilinx/xilinx_axienet_xxv.c create mode 100644 drivers/net/ethernet/xilinx/xilinx_axienet_xxv.h
drivers/net/ethernet/xilinx/Makefile +2 -1
@@ -6,5 +6,6 @@ ll_temac-objs := ll_temac_main.o ll_temac_mdio.o obj-$(CONFIG_XILINX_LL_TEMAC) += ll_temac.o obj-$(CONFIG_XILINX_EMACLITE) += xilinx_emaclite.o -xilinx_emac-objs := xilinx_axienet_main.o xilinx_axienet_mdio.o +xilinx_emac-objs := xilinx_axienet_main.o xilinx_axienet_mdio.o \ + xilinx_axienet_xxv.o obj-$(CONFIG_XILINX_AXI_EMAC) += xilinx_emac.o
drivers/net/ethernet/xilinx/xilinx_axienet.h +9 -0
@@ -17,6 +17,8 @@#include <linux/phylink.h> #include <linux/skbuff.h> +#include "xilinx_axienet_xxv.h" +/* Packet size info */ #define XAE_HDR_SIZE 14/* Size of Ethernet header */ #define XAE_TRL_SIZE 4/* Size of Ethernet trailer (FCS) */
@@ -548,6 +550,7 @@ struct skbuf_dma_descriptor {* @rx_ring_head: RX skb ring buffer head index. * @rx_ring_tail: RX skb ring buffer tail index. * @rx_submit_lock: Protects RX ring resubmission vs teardown in dmaengine path. +* @xxv_ip_version: XXV IP version. * @axienet_config: MAC-type specific configuration and operations. */ struct axienet_local {
@@ -632,6 +635,7 @@ struct axienet_local {int rx_ring_head;int rx_ring_tail;spinlock_t rx_submit_lock; +u32 xxv_ip_version;const struct axienet_config *axienet_config; };
@@ -689,6 +693,11 @@ struct axienet_config {void (*stats_update)(struct axienet_local *lp); }; +static inline struct axienet_local *pcs_to_axienet_local (struct phylink_pcs *pcs) +{ + return container_of(pcs, struct axienet_local, pcs); +} +/** * struct axienet_option - Used to set axi ethernet hardware options * @opt: Option to be set.
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +15 -8
@@ -800,6 +800,12 @@ static int axienet_1g_mac_init(struct net_device *ndev)* Ethernet core. No separate hardware reset is done for the Axi Ethernet * core. * +* It also recomputes @max_frm_size from the current MTU and runs the +* MAC-specific mac_init() callback, so it is the point at which length-related +* MAC configuration (such as the XXV RX max-packet-length) is reprogrammed. +* Because it is reached from the open path, a new MTU takes effect on the next +* interface up. +* * Return: 0 on success or a negative error number otherwise. */ static int axienet_device_reset (struct net_device *ndev)
@@ -2720,11 +2726,6 @@ static const struct ethtool_ops axienet_ethtool_dmaengine_ops = { .get_rmon_stats = axienet_ethtool_get_rmon_stats, }; -static struct axienet_local *pcs_to_axienet_local (struct phylink_pcs *pcs) -{ - return container_of(pcs, struct axienet_local, pcs); -} -static void axienet_pcs_get_state (struct phylink_pcs *pcs,unsigned int neg_mode,struct phylink_link_state *state)
@@ -2784,7 +2785,9 @@ static struct phylink_pcs *axienet_mac_select_pcs(struct phylink_config *config,struct axienet_local *lp =netdev_priv (ndev);if (interface ==PHY_INTERFACE_MODE_1000BASEX || - interface ==PHY_INTERFACE_MODE_SGMII ) + interface ==PHY_INTERFACE_MODE_SGMII || + interface ==PHY_INTERFACE_MODE_10GBASER || + interface ==PHY_INTERFACE_MODE_25GBASER )return &lp->pcs;return NULL ;
@@ -3014,6 +3017,7 @@ static const struct of_device_id axienet_of_match[] = { { .compatible = "xlnx,axi-ethernet-1.00.a", .data = &axienet_1g_config }, { .compatible = "xlnx,axi-ethernet-1.01.a", .data = &axienet_1g_config }, { .compatible = "xlnx,axi-ethernet-2.01.a", .data = &axienet_1g_config }, + { .compatible = "xlnx,xxv-ethernet-1.0", .data = &axienet_10g25g_config }, {}, };
@@ -3051,9 +3055,10 @@ static int axienet_probe(struct platform_device *pdev)SET_NETDEV_DEV (ndev, &pdev->dev); ndev->features =NETIF_F_SG ; -/* MTU range: 64 - 9000 */ +/* MTU range: min is 64; max is finalized once the MAC config (which +* tells us whether jumbo frames are supported) is known, see below. +*/ ndev->min_mtu =64 ; - ndev->max_mtu =XAE_JUMBO_MTU ; lp =netdev_priv (ndev); lp->ndev = ndev;
@@ -3073,6 +3078,8 @@ static int axienet_probe(struct platform_device *pdev)if (!lp->axienet_config)return -ENODEV ; + ndev->max_mtu = lp->axienet_config->jumbo ?XAE_JUMBO_MTU :XAE_MTU ; + ret = lp->axienet_config->clk_init (lp);if (ret)return ret;
drivers/net/ethernet/xilinx/xilinx_axienet_xxv.c new file +351 -0
351 lines not on this page · raw message
drivers/net/ethernet/xilinx/xilinx_axienet_xxv.h new file +93 -0
93 lines not on this page · raw message
Signature · 1 line
2.25.1
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [High] net: xilinx: axienet: XXV RX path reads length from unpopulated DMA metadata --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [High] net: xilinx: axienet: XXV RX path reads length from unpopulated DMA metadata
--
commit 24a43162ada4308aadc24cc61461a6b384478cc3
Author: Suraj Gupta <[email protected]>
net: xilinx: axienet: Add 10G/25G (XXV) ethernet support
This commit adds support for the Xilinx 10G/25G (XXV) Ethernet MAC and PCS/PMA to the AXI Ethernet driver via a new axienet_10g25g_config.
Quoted 5 lines
drivers/net/ethernet/xilinx/xilinx_axienet_xxv.c new file +0
-0
[ ... ]
Quoted 4 lines
drivers/net/ethernet/xilinx/xilinx_axienet_xxv.c new file +4
-0+const struct axienet_config axienet_10g25g_config = { + .jumbo = true, + .sw_padding = true, + .internal_pcs = true,
drivers/net/ethernet/xilinx/xilinx_axienet_xxv.c line 351
Quoted 10 lines
drivers/net/ethernet/xilinx/xilinx_axienet_xxv.c new file +10
-0+ .regs_n = XXV_REGS_N, + .options = xxvenet_options, + .clk_init = axienet_10g25g_clk_init, + .probe_init = axienet_xxv_probe_init, + .gt_reset = axienet_xxv_gt_reset, + .mac_init = axienet_xxv_mac_init, + .get_regs = axienet_xxv_get_regs, + .phylink_set_caps = axienet_xxv_phylink_set_capabilities, + .pcs_ops = &axienet_xxv_pcs_ops, +};
[Severity: High]
How does the XXV RX path determine the received frame length on the dmaengine path?
axienet_10g25g_config leaves .non_dmaengine false, so XXV always uses axienet_dma_rx_cb(), which gets the frame length from DMA metadata word LEN_APP (APP word 4):
drivers/net/ethernet/xilinx/xilinx_axienet_main.c:axienet_dma_rx_cb() {
...
app_metadata = dmaengine_desc_get_metadata_ptr(skbuf_dma->desc, &meta_len,
&meta_max_len);
...
if (IS_ERR(app_metadata)) {
...
dev_kfree_skb_any(skb);
lp->ndev->stats.rx_dropped++;
goto rx_submit;
}
/* TODO: Derive app word index programmatically */
rx_len = (app_metadata[LEN_APP] & 0xFFFF);
skb_put(skb, rx_len);
...
}Unlike the 1G AXI Ethernet IP, the XXV Ethernet IP has no AXI4-Stream status/control stream to populate APP word 4. Without xlnx,axistream-connected on the DMA node, dmaengine_desc_get_metadata_ptr() returns ERR_PTR(-ENOTSUPP) and every received frame is dropped; even if that property is set, APP word 4 is never written by the XXV MAC, so skb_put() uses 0 or stale descriptor data instead of the actual transfer length (such as lp->max_frm_size - result->residue from dmaengine_tx_status()).
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 7 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 7 potential issue(s) to consider.
Critical: 0 · High: 1 · Medium: 2 · Low: 4
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [High] XXV receive is routed through the shared dmaengine RX callback, axienet_dma_rx_cb()…
- [Medium] axienet_mac_select_pcs() is shared by all MAC types.
- [Medium] PG210's XXV MAC flags bad-FCS, oversize/length-error and truncated frames only through rx_axis_tuser at end of packet, and…
- [Low] axienet_xxv_get_regs() reads every STAT_* status register on each 'ethtool -d'.
- [Low] axienet_ethtools_get_regs() always sets regs->version = 0 and regs->len = sizeof(u32) * regs_n, then dispatches to…
- [Low] The patch builds xilinx_axienet_xxv.o into xilinx_emac under CONFIG_XILINX_AXI_EMAC, adding 10G/25G XXV support to that option, but…
- [Low] In axienet_open(), axienet_device_reset() runs first.
--
net: xilinx: axienet: Add 10G/25G (XXV) ethernet support
This commit adds support for the Xilinx XXV 10G/25G Ethernet MAC to the axienet driver. The XXV-specific code goes into new xilinx_axienet_xxv.c/.h files and is described by an axienet_10g25g_config. The shared paths use the callbacks from that config, and axienet_mac_select_pcs() now also handles 10GBASER and 25GBASER.
drivers/net/ethernet/xilinx/Makefile line 11
Quoted 12 lines
drivers/net/ethernet/xilinx/Makefile +2
-1@@ -6,5 +6,6 @@ ll_temac-objs := ll_temac_main.o ll_temac_mdio.o obj-$(CONFIG_XILINX_LL_TEMAC) += ll_temac.o obj-$(CONFIG_XILINX_EMACLITE) += xilinx_emaclite.o -xilinx_emac-objs := xilinx_axienet_main.o xilinx_axienet_mdio.o +xilinx_emac-objs := xilinx_axienet_main.o xilinx_axienet_mdio.o \ + xilinx_axienet_xxv.o obj-$(CONFIG_XILINX_AXI_EMAC) += xilinx_emac.o
[Severity: Low]
This isn't a bug, but should the XILINX_AXI_EMAC Kconfig entry be updated too? XXV support now builds under this option, but the prompt still reads:
tristate "Xilinx 10/100/1000 AXI Ethernet support"
The help text also still says "This driver supports the 10/100/1000 Ethernet from Xilinx...". It is unchanged at the end of the series, so nothing points someone configuring an XXV-based board at this option.
Quoted 7 lines
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +0
-0@@ -801,6 +801,12 @@ static int axienet_1g_mac_init(struct net_device *ndev)* Ethernet core. No separate hardware reset is done for the Axi Ethernet * core.
drivers/net/ethernet/xilinx/xilinx_axienet_main.c static int axienet_1g_mac_init(struct net_device *ndev) · line 812
Quoted 10 lines
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +6
-0* +* It also recomputes @max_frm_size from the current MTU and runs the +* MAC-specific mac_init() callback, so it is the point at which length-related +* MAC configuration (such as the XXV RX max-packet-length) is reprogrammed. +* Because it is reached from the open path, a new MTU takes effect on the next +* interface up. +* * Return: 0 on success or a negative error number otherwise. */ static int axienet_device_reset (struct net_device *ndev)
[Severity: Low]
Is the ordering in axienet_open() safe for XXV? The XXV receiver is enabled before any RX DMA buffer is posted:
axienet_open()
axienet_device_reset()
axienet_setoptions(ndev, lp->options) <- sets XXV_RCW1_RX_MASK
phylink_start()
axienet_init_dmaengine() <- RX channel and buffers
PG210 describes the XXV RX AXI4-Stream as having no tready backpressure. If a frame arrives before the S2MM channel accepts data, could the first RX buffer capture only the tail of that frame (ending at tlast) and pass it up as a frame?
On the 1G core, its internal RX FIFO made this ordering safe. With XXV it depends on the FPGA logic between the MAC and the DMA.
[ ... ]
drivers/net/ethernet/xilinx/xilinx_axienet_main.c static struct phylink_pcs *axienet_mac_select_pcs(struct phylink_config *config, · line 2797
Quoted 11 lines
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +3
-1@@ -2788,7 +2789,9 @@ static struct phylink_pcs *axienet_mac_select_pcs(struct phylink_config *config,struct axienet_local *lp =netdev_priv (ndev);if (interface ==PHY_INTERFACE_MODE_1000BASEX || - interface ==PHY_INTERFACE_MODE_SGMII ) + interface ==PHY_INTERFACE_MODE_SGMII || + interface ==PHY_INTERFACE_MODE_10GBASER || + interface ==PHY_INTERFACE_MODE_25GBASER )return &lp->pcs;return NULL ;
[Severity: Medium]
Can this hand phylink a PCS with NULL ops on a 1G MAC?
axienet_mac_select_pcs() is shared by all MAC types. On the 1G config, axienet_probe() sets lp->pcs.ops only for SGMII/1000BASEX, and axienet_1g_config has no internal_pcs.
axienet_1g_phylink_set_caps() still does this for any phy_mode:
__set_bit(lp->phy_mode, config->supported_interfaces);
So a 1G compatible node with phy-mode = "10gbase-r" or "25gbase-r" is not rejected at probe.
With fixed-link, probe still succeeds. phylink_validate() prints "uninitialised PCS" with a dump_stack() and returns -EINVAL, but both phylink_create() and phylink_parse_fixedlink() ignore that result. Then on ifup:
axienet_open()
phylink_start()
phylink_major_config()
pl->pcs = &lp->pcs;
phylink_pcs_pre_config(pl->pcs, ...)
if (pcs && pcs->ops->pcs_pre_config) <- pcs->ops is NULLBefore this patch, these modes returned NULL here. Should &lp->pcs only be returned when lp->pcs.ops is set?
[ ... ]
Quoted 6 lines
drivers/net/ethernet/xilinx/xilinx_axienet_xxv.c new file +0
-0@@ -0,0 +1,351 @@
[ ... ]
Quoted 6 lines
drivers/net/ethernet/xilinx/xilinx_axienet_xxv.c new file +6
-0+static int axienet_xxv_mac_init (struct net_device *ndev) +{ +struct axienet_local *lp =netdev_priv (ndev); +int ret; + + ret =axienet_xxv_poll_link_ready (ndev);
drivers/net/ethernet/xilinx/xilinx_axienet_xxv.c line 203
Quoted 10 lines
drivers/net/ethernet/xilinx/xilinx_axienet_xxv.c new file +10
-0+if (ret) +return ret; + +/* Bound the MAC's RX max packet length to the posted buffer size so an +* oversized frame is truncated to a single buffer instead of spilling +* across several DMA descriptors (PG210 CONFIGURATION_RX_MTU). +*/ +axienet_iow (lp,XXV_JUM_OFFSET , +FIELD_PREP (XXV_RX_MAX_LEN_MASK , lp->max_frm_size) | +XXV_RX_MIN_LEN_DEFAULT );
[Severity: High]
Where does XXV get the RX frame length from? axienet_10g25g_config does not set non_dmaengine, so every XXV RX completion goes through the shared dmaengine callback:
drivers/net/ethernet/xilinx/xilinx_axienet_main.c:axienet_dma_rx_cb() {
...
if (IS_ERR(app_metadata)) {
if (net_ratelimit())
netdev_err(lp->ndev, "Failed to get RX metadata pointer\n");
dev_kfree_skb_any(skb);
lp->ndev->stats.rx_dropped++;
goto rx_submit;
}
/* TODO: Derive app word index programmatically */
rx_len = (app_metadata[LEN_APP] & 0xFFFF);
skb_put(skb, rx_len);
...
}app_metadata[LEN_APP] is APP4. Only the 1G AXI Ethernet IP fills that word, through its RX status stream. The PG210 MAC has no status stream, and nothing in the XXV config or binding provides one.
In xilinx_dma.c, software never writes the S2MM app words: hw->app is copied only for DMA_MEM_TO_DEV, and segments are zeroed. For MCDMA, which the XXV binding example uses, xilinx_dma_get_metadata_ptr() returns &seg->hw.s2mm_status for DEV_TO_MEM, so index 4 lands on app[2] and not on a length field.
What happens then depends on the DMA setup:
- Without xlnx,axistream-connected on the DMA, no metadata_ops are attached. Every frame is dropped with "Failed to get RX metadata pointer".
- With it, rx_len comes from a zeroed or unrelated word. Each frame becomes a zero-length skb and rx_bytes stays at 0.
- If that word ever holds a stale non-zero value, rx_len is not checked against lp->max_frm_size. Anything above the skb tailroom (up to 0xFFFF) reaches skb_put() and hits skb_over_panic().
The DMA does report the real transfer count, via xilinx_dma_get_residue() into result->residue, but the callback ignores it.
The comment above says CONFIGURATION_RX_MTU keeps frames within one buffer. However, the length passed to skb_put() never comes from the MAC.
The last patch in the series ("net: xilinx: axienet: Add statistics support for XXV ethernet") does not change axienet_dma_rx_cb() either. Does XXV receive work on any of the documented DMA configurations?
drivers/net/ethernet/xilinx/xilinx_axienet_xxv.c line 209
Quoted 6 lines
drivers/net/ethernet/xilinx/xilinx_axienet_xxv.c new file +6
-0+ + lp->options |=XAE_OPTION_FCS_STRIP ; + lp->options |=XAE_OPTION_FCS_INSERT ; + +return 0 ; +}
[Severity: Medium]
How are errored frames dropped on XXV? Per PG210, the XXV MAC reports bad-FCS, length-error and truncated frames only through rx_axis_tuser at end of packet. It still forwards those frames on the stream.
AXI DMA S2MM does not record tuser. axienet_dma_rx_cb() also checks no per-frame error status before it calls __netif_rx().
With XAE_OPTION_FCS_STRIP set here, the FCS is gone before software could check it. The oversized frames that ctl_rx_max_packet_len truncates, per the comment above, would also go up as valid packets.
The 1G core drops errored frames in its own RX FIFO and raises XAE_INT_RXRJECT, so the shared datapath never needed this check.
Does the FPGA design need a tuser-aware drop stage between the MAC and the DMA? If so, should that be documented or detected?
[ ... ]
Quoted 7 lines
drivers/net/ethernet/xilinx/xilinx_axienet_xxv.c new file +7
-0+static void axienet_xxv_get_regs (struct axienet_local *lp,u32 *data) +{ +bool has_gt_status =axienet_xxv_ip_has_gt_status (lp->xxv_ip_version); +unsigned int i; + +for (i =0 ; i <ARRAY_SIZE (axienet_xxv_reg_dump_offsets); i++) { +u32 off = axienet_xxv_reg_dump_offsets[i];
drivers/net/ethernet/xilinx/xilinx_axienet_xxv.c line 299
Quoted 10 lines
drivers/net/ethernet/xilinx/xilinx_axienet_xxv.c new file +10
-0+ +/* The GT registers only exist on the IP versions that report +* reset-done. Leave their slots zero on the others so the +* dump keeps a fixed layout. +*/ +if (!has_gt_status && (off ==XXV_GT_CTRL_OFFSET || + off ==XXV_STAT_GT_OFFSET )) +continue ; + + data[i] =axienet_ior (lp, off);
[Severity: Low]
Can an ethtool -d dump interfere with link reporting? This reads every STAT_* register, including XXV_STAT_RX_STATUS_OFFSET. PG210 describes that register's bit 0 as latched and cleared on read. axienet_xxv_pcs_get_state() uses the same bit for the link:
state->link = axienet_ior(lp, XXV_STAT_RX_STATUS_OFFSET) & XXV_STAT_RX_STATUS_MASK;
lp->pcs.poll is true for internal_pcs. A dump taken between two phylink polls could therefore clear a latched link-down event, and phylink would never see the flap. STAT_RX_BLOCK_LOCK, STAT_TX_STATUS and the AN/LT/FEC status registers are read the same way.
The skip logic is also uneven. GT_CTRL/STAT_GT are skipped on IP older than v3.2. But STAT_CORE_SPEED is read unconditionally, and the commit message says it exists only on 64-bit AXI4-Stream builds. The same goes for the build-optional RS-FEC/AN/LT/1588 registers.
drivers/net/ethernet/xilinx/xilinx_axienet_xxv.c
Quoted 2 lines
drivers/net/ethernet/xilinx/xilinx_axienet_xxv.c new file +2
-0+ } +}
[Severity: Low]
Should the dump version tell the two layouts apart? The caller reports version 0 for every MAC type:
drivers/net/ethernet/xilinx/xilinx_axienet_main.c:axienet_ethtools_get_regs() {
...
len = sizeof(u32) * lp->axienet_config->regs_n;
regs->version = 0;
regs->len = len;
...
}After this patch, the driver produces both the 1G layout (AXIENET_REGS_N words with the DMA registers at fixed indices) and this 46-word PG210 layout, both under version 0. That leaves userspace decoders no way to tell which format they have.
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261114182947.2908628-1-suraj.gupta2%40amd.com
PATCH v5 5/6 net: xilinx: axienet: Dispatch statistics through axienet_config ops
In reply to Suraj GuptaThe ndo_get_stats64() and ethtool statistics callbacks read the 1G MAC hardware counters directly. Supporting a second MAC type this way would require an "if (mactype == ...)" dispatch branch in each of the eight statistics callbacks.
Add statistics operation function pointers to struct axienet_config and route get_stats64, get_ethtool_stats, get_strings, get_sset_count, get_pause_stats, get_eth_mac_stats, get_eth_ctrl_stats and get_rmon_stats through them. Factor the existing 1G counter reads into axienet_1g_*() helpers and populate axienet_1g_config with them.
A NULL op means the MAC does not expose that statistics group, so a MAC without control-frame counters simply leaves get_eth_ctrl_stats unset instead of open-coding the special case in the callback.
No functional change intended.
--- drivers/net/ethernet/xilinx/xilinx_axienet.h | 23 +++ .../net/ethernet/xilinx/xilinx_axienet_main.c | 171 +++++++++++++----- 2 files changed, 146 insertions(+), 48 deletions(-)
drivers/net/ethernet/xilinx/xilinx_axienet.h +23 -0
@@ -666,6 +666,15 @@ struct axienet_local {* is set, as the PCS is registered without a further NULL check * @stats_update: Callback to latch/accumulate the periodic MAC counters, or * NULL if the MAC has no periodic statistics counters +* @get_stats64: Callback to read MAC counters into rtnl_link_stats64 +* @get_ethtool_stats: Callback to read MAC counters for ethtool -S +* @get_strings: Callback to fill the ethtool -S statistic name strings +* @get_sset_count: Callback returning the number of ethtool -S statistics +* @get_pause_stats: Callback to read MAC pause-frame counters +* @get_eth_mac_stats: Callback to read IEEE 802.3 MAC counters +* @get_eth_ctrl_stats: Callback to read MAC-control frame counters, or NULL +* if the MAC exposes no control-frame counters +* @get_rmon_stats: Callback to read RMON counters and histogram ranges */ struct axienet_config {bool mdio;
@@ -691,6 +700,20 @@ struct axienet_config { struct phylink_config *config);const struct phylink_pcs_ops *pcs_ops;void (*stats_update)(struct axienet_local *lp); +void (*get_stats64)(struct axienet_local *lp, +struct rtnl_link_stats64 *stats); +void (*get_ethtool_stats)(struct axienet_local *lp,u64 *data); +void (*get_strings)(u8 *data); +int (*get_sset_count)(void ); +void (*get_pause_stats)(struct axienet_local *lp, +struct ethtool_pause_stats *pause_stats); +void (*get_eth_mac_stats)(struct axienet_local *lp, +struct ethtool_eth_mac_stats *mac_stats); +void (*get_eth_ctrl_stats)(struct axienet_local *lp, +struct ethtool_eth_ctrl_stats *ctrl_stats); +void (*get_rmon_stats)(struct axienet_local *lp, +struct ethtool_rmon_stats *rmon_stats, +const struct ethtool_rmon_hist_range **ranges); };static inline struct axienet_local *pcs_to_axienet_local (struct phylink_pcs *pcs)
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +123 -48
275 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v5 6/6 net: xilinx: axienet: Add statistics support for XXV ethernet
In reply to Suraj GuptaThe XXV ethernet exposes a dedicated statistics block whose counters are clear-on-tick (PG210): writing TICK_REG latches the internal accumulators into the readable registers and clears them, so each post-TICK read yields the count for the interval since the previous TICK. Software accumulates those intervals, so no last-counter delta (as used by the 1G MAC) is needed. The readable registers are not reset along with the accumulators and hold unknown data until the first TICK, so axienet_xxv_mac_init() drains them once the GT is ready and before RX/TX are enabled.
Feed both ndo_get_stats64() and the ethtool statistics (-S, pause, MAC and RMON) from this accumulator path through the axienet_config statistics ops. MAC control statistics stay unsupported as the hardware exposes no matching counters.
The counters are an optional part of the IP, selected by the "Include Statistics Counters" build option. Unlike the 1G MAC, which advertises XAE_ABILITY_STATS, the XXV register map does not report whether they were included, so gate XAE_FEATURE_STATS on the "xlnx,has-statistics-counters" devicetree property instead. Gate the TICK_REG drain and the periodic statistics work on that same flag, so that a design built without the block is never touched in the statistics register range. The work previously keyed off the presence of the stats_update hook alone, which a config installs unconditionally.
Readers copy the software accumulator and do not tick. The periodic statistics work latches it, and axienet_stop() takes a final snapshot. ethtool -S and the pause, MAC and RMON callbacks use that same copy, so they can lag the work interval; the work is deferrable, so on an idle CPU the lag can exceed it. ndo_get_stats64() may run atomically and cannot tick these clear-on-tick counters itself. PG210 defines the counters as 48 bits (LSB [31:0], MSB [15:0] holds [47:32]), saturating at 0xFFFFFFFFFFFF, so the existing work interval cannot wrap them at 25 Gbit/s. Mask the MSB register to those 16 bits when a counter is read, so that bits outside the counter cannot be accumulated into the software base.
The final statistics snapshot added to axienet_stop() is gated on XAE_FEATURE_STATS, so it also runs on the 1G MAC when that MAC implements the statistics block; it is therefore not strictly XXV-only.
--- drivers/net/ethernet/xilinx/xilinx_axienet.h | 6 +- .../net/ethernet/xilinx/xilinx_axienet_main.c | 36 ++- .../net/ethernet/xilinx/xilinx_axienet_xxv.c | 282 ++++++++++++++++++ .../net/ethernet/xilinx/xilinx_axienet_xxv.h | 58 ++++ 4 files changed, 378 insertions(+), 4 deletions(-)
drivers/net/ethernet/xilinx/xilinx_axienet.h +5 -1
@@ -520,7 +520,7 @@ struct skbuf_dma_descriptor {* @reset_in_progress: Set while we are performing a reset and statistics * counters may be invalid * @hw_stats_seqcount: Sequence counter for @hw_stat_base, @hw_last_counter, -* and @reset_in_progress. +* @reset_in_progress and, on XXV, @xxv_stat_base. * @stats_lock: Lock for @hw_stats_seqcount * @stats_work: Work for reading the hardware statistics counters often enough * to catch overflows.
@@ -551,6 +551,9 @@ struct skbuf_dma_descriptor {* @rx_ring_tail: RX skb ring buffer tail index. * @rx_submit_lock: Protects RX ring resubmission vs teardown in dmaengine path. * @xxv_ip_version: XXV IP version. +* @xxv_stat_base: Software accumulators for the XXV clear-on-tick counters. +* Serialized by @stats_lock and published under +* @hw_stats_seqcount. * @axienet_config: MAC-type specific configuration and operations. */ struct axienet_local {
@@ -605,6 +608,7 @@ struct axienet_local {u64 hw_stat_base[STAT_COUNT ];u32 hw_last_counter[STAT_COUNT ]; +u64 xxv_stat_base[XXV_STAT_COUNT ];seqcount_mutex_t hw_stats_seqcount;struct mutex stats_lock;struct delayed_work stats_work;
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +33 -3
@@ -637,13 +637,23 @@ static void axienet_refresh_stats(struct work_struct *work) struct axienet_local *lp = container_of(work, struct axienet_local, stats_work.work); -if (lp->axienet_config->stats_update) { +/* Gate on XAE_FEATURE_STATS as axienet_stop() does: a config installs +* the hook unconditionally, but the counters themselves are optional, +* and on XXV the registers are absent when they were not built in. +*/ +if (lp->features &XAE_FEATURE_STATS && lp->axienet_config->stats_update) {mutex_lock (&lp->stats_lock); lp->axienet_config->stats_update (lp);mutex_unlock (&lp->stats_lock); } -/* Just less than 2^32 bytes at 2.5 GBit/s */ +/* Re-arm the poll before any counter can overflow between updates: the +* 1G byte counter reaches just under 2^32 in this interval at 2.5 Gbit/s. +* The XXV counters are 48 bits (PG210): the LSB register holds [31:0] and +* MSB[15:0] holds [47:32]. They saturate at 0xFFFFFFFFFFFF and clear on +* tick, so this interval cannot wrap them at 25 Gbit/s. This work is +* what latches them between queries. +*/ schedule_delayed_work (&lp->stats_work,13 *HZ ); }
@@ -652,7 +662,16 @@ static int __axienet_device_reset(struct axienet_local *lp)u32 value;int ret; -/* Save statistics counters in case they will be reset */ +/* Save statistics counters in case they will be reset. +* +* The XAE_FEATURE_STATS blocks in this function read the TEMAC +* statistics registers at XAE_STATS_OFFSET, i.e. they assume the 1G +* counter layout. This is safe because __axienet_device_reset() is +* only reached on the non-dmaengine path, which the +* non_dmaengine capability restricts to the 1G MAC. MACs that use their +* own statistics mechanism (e.g. XXV, which is dmaengine-only) never +* execute this path. +*/ mutex_lock (&lp->stats_lock);if (lp->features &XAE_FEATURE_STATS )axienet_stats_update (lp, true);
@@ -1880,6 +1899,17 @@ static int axienet_stop(struct net_device *ndev)axienet_setoptions (ndev, lp->options & ~(XAE_OPTION_TXEN |XAE_OPTION_RXEN )); +/* Final snapshot after RX/TX is disabled, so no frames are missed. +* Gate on XAE_FEATURE_STATS rather than the stats_update hook: a config +* always installs the hook, but the counters are optional in both MACs, +* so only probe_init() knows whether they are there. +*/ +if (lp->features &XAE_FEATURE_STATS && lp->axienet_config->stats_update) { +mutex_lock (&lp->stats_lock); + lp->axienet_config->stats_update (lp); +mutex_unlock (&lp->stats_lock); + } +if (!lp->use_dmaengine) {axienet_dma_stop (lp);cancel_work_sync (&lp->dma_err_task);
drivers/net/ethernet/xilinx/xilinx_axienet_xxv.c +282 -0
319 lines not on this page · raw message
drivers/net/ethernet/xilinx/xilinx_axienet_xxv.h +58 -0
76 lines not on this page · raw message
Signature · 1 line
2.25.1
[email protected]
AI reviewRe: [PATCH net-next v5 6/6] net: xilinx: axienet: Add statistics support for XXV ethernet
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] net: xilinx: axienet: wrong RX bad-FCS offset in axienet_xxv_get_stats64() --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] net: xilinx: axienet: wrong RX bad-FCS offset in axienet_xxv_get_stats64()
--
commit 460172ab6de68521ff2c9e9d0c5b3adf14de408f
Author: Suraj Gupta <[email protected]>
net: xilinx: axienet: Add statistics support for XXV ethernet
This commit adds hardware statistics collection and reporting for the Xilinx 10G/25G (XXV) Ethernet MAC via ndo_get_stats64() and ethtool statistics callbacks, gated on the "xlnx,has-statistics-counters" devicetree property.
Quoted 4 lines
drivers/net/ethernet/xilinx/xilinx_axienet_xxv.c +0
-0
[ ... ]
Quoted 3 lines
drivers/net/ethernet/xilinx/xilinx_axienet_xxv.c +0
-0@@ -335,6 +411,204 @@ static int axienet_10g25g_clk_init(struct axienet_local *lp)return 0 ; }
[ ... ]
Quoted 23 lines
drivers/net/ethernet/xilinx/xilinx_axienet_xxv.c +23
-0+static void axienet_xxv_get_stats64 (struct axienet_local *lp, +struct rtnl_link_stats64 *stats) +{ +unsigned int start; +u64 tx_hw_errors; + + do { + start = read_seqcount_begin(&lp->hw_stats_seqcount); + stats->rx_crc_errors = + lp->xxv_stat_base[XXV_STAT_RX_PACKET_BAD_FCS]; + /* Both in-range length errors and frame-too-long (oversize) + * frames are IEEE 802.3 length errors, so fold them together + * into rx_length_errors; rx_over_errors is reserved for receiver + * FIFO/ring overflow, which the XXV MAC does not expose. + */ + stats->rx_length_errors = + lp->xxv_stat_base[XXV_STAT_RX_INRANGEERR] + + lp->xxv_stat_base[XXV_STAT_RX_OVERSIZE]; + stats->rx_errors = lp->xxv_stat_base[XXV_STAT_RX_UNDERSIZE] + + lp->xxv_stat_base[XXV_STAT_RX_FRAGMENT] + + lp->xxv_stat_base[XXV_STAT_RX_JABBER] + + stats->rx_crc_errors + + stats->rx_length_errors;
[ ... ]
Quoted 17 lines
drivers/net/ethernet/xilinx/xilinx_axienet_xxv.c +17
-0+static void axienet_xxv_get_eth_mac_stats (struct axienet_local *lp, +struct ethtool_eth_mac_stats *mac_stats) +{ +unsigned int start; + + do { + start = read_seqcount_begin(&lp->hw_stats_seqcount); + mac_stats->FramesTransmittedOK = + lp->xxv_stat_base[XXV_STAT_TX_TOTAL_GOOD_PACKETS]; + mac_stats->FramesReceivedOK = + lp->xxv_stat_base[XXV_STAT_RX_TOTAL_GOOD_PACKETS]; + mac_stats->OctetsTransmittedOK = + lp->xxv_stat_base[XXV_STAT_TX_TOTAL_GOOD_BYTES]; + mac_stats->OctetsReceivedOK = + lp->xxv_stat_base[XXV_STAT_RX_TOTAL_GOOD_BYTES]; + mac_stats->FrameCheckSequenceErrors = + lp->xxv_stat_base[XXV_STAT_RX_PACKET_BAD_FCS];
[ ... ]
Quoted 5 lines
drivers/net/ethernet/xilinx/xilinx_axienet_xxv.h +0
-0@@ -66,6 +66,36 @@ struct axienet_config;
[ ... ]
drivers/net/ethernet/xilinx/xilinx_axienet_xxv.h struct axienet_config; · line 93
Quoted 5 lines
drivers/net/ethernet/xilinx/xilinx_axienet_xxv.h +5
-0+#define XXV_STAT_RX_UNDERSIZE_OFFSET 0x00000898 +#define XXV_STAT_RX_FRAGMENT_OFFSET 0x000008A0 +#define XXV_STAT_RX_OVERSIZE_OFFSET 0x000008A8 +#define XXV_STAT_RX_JABBER_OFFSET 0x000008B8 +#define XXV_STAT_RX_PACKET_BAD_FCS_OFFSET 0x000008C8
[Severity: Medium]
Should this read STAT_RX_BAD_FCS at offset 0x08C0 instead of STAT_RX_PACKET_BAD_FCS at 0x08C8?
Per PG210, STAT_RX_PACKET_BAD_FCS (0x08C8) counts all received packets with bad FCS regardless of length, which includes frames shorter than 64 bytes with bad FCS (STAT_RX_FRAGMENT at 0x08A0) and frames longer than the configured maximum length with bad FCS (STAT_RX_JABBER at 0x08B8). Using 0x08C8 causes axienet_xxv_get_stats64() to double-count received fragments and jabbers in stats->rx_errors, and includes undersize and oversize bad-FCS frames in stats->rx_crc_errors and mac_stats->FrameCheckSequenceErrors, whereas STAT_RX_BAD_FCS (0x08C0) counts only valid-length frames with bad FCS.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
[email protected]
AI reviewRe: [PATCH net-next v5 6/6] net: xilinx: axienet: Add statistics support for XXV ethernet
In reply to Suraj GuptaThank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 2 · Low: 4
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] None of the XXV statistics readers in drivers/net/ethernet/xilinx/xilinx_axienet_xxv.c latch the clear-on-…
- [Medium] The new XXV ndo_get_stats64 reader, axienet_xxv_get_stats64(), runs read_seqcount_begin()/read_seqcount_retry() on…
- [Low] The kernel-doc of axienet_xxv_get_rmon_stats() (xxv.c:585-586) says "XXV exposes aggregate RMON counters only, not per-bin histogram…
- [Low] axienet_xxv_get_stats64() treats XXV_STAT_RX_OVERSIZE as an IEEE 802.3 frame-too-long error and folds it into rx_length_errors.
- [Low] The patch updates the @hw_stats_seqcount kernel-doc in struct axienet_local for XXV but leaves @stats_work saying "Work for reading…
- [Low] axienet_stop() writes TICK_REG for the final XXV statistics snapshot (via axienet_xxv_stats_update) right after…
--
net: xilinx: axienet: Add statistics support for XXV ethernet
This patch adds support for the clear-on-tick XXV (PG210) statistics block. The counters are accumulated in software by the periodic stats work and by a final snapshot in axienet_stop(). The result feeds ndo_get_stats64() and the ethtool -S, pause, MAC and RMON callbacks, gated on the "xlnx,has-statistics-counters" devicetree property.
drivers/net/ethernet/xilinx/xilinx_axienet.h struct skbuf_dma_descriptor { · line 526
Quoted 13 lines
drivers/net/ethernet/xilinx/xilinx_axienet.h +1
-1@@ -520,7 +520,7 @@ struct skbuf_dma_descriptor {* @reset_in_progress: Set while we are performing a reset and statistics * counters may be invalid * @hw_stats_seqcount: Sequence counter for @hw_stat_base, @hw_last_counter, -* and @reset_in_progress. +* @reset_in_progress and, on XXV, @xxv_stat_base. * @stats_lock: Lock for @hw_stats_seqcount * @stats_work: Work for reading the hardware statistics counters often enough * to catch overflows.
[Severity: Low]
This isn't a bug, but should the @stats_work description be updated as well? On XXV this work is now the only latch for the clear-on-tick counters. The new comment in axienet_refresh_stats() says:
This work is
what latches them between queries.
The @stats_update kernel-doc in struct axienet_config has not changed either:
* @stats_update: Callback to latch/accumulate the periodic MAC counters, or
* NULL if the MAC has no periodic statistics counters
The new comments in axienet_refresh_stats() and axienet_stop() say something different: a config installs the hook unconditionally, and XAE_FEATURE_STATS decides whether the counters exist.
Could these two descriptions be updated to match?
[ ... ]
Quoted 4 lines
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +0
-0
[ ... ]
Quoted 4 lines
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +0
-0@@ -1884,6 +1903,17 @@ static int axienet_stop(struct net_device *ndev)axienet_setoptions (ndev, lp->options & ~(XAE_OPTION_TXEN |XAE_OPTION_RXEN ));
drivers/net/ethernet/xilinx/xilinx_axienet_main.c static int axienet_stop(struct net_device *ndev) · line 1915
Quoted 10 lines
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +10
-0+/* Final snapshot after RX/TX is disabled, so no frames are missed. +* Gate on XAE_FEATURE_STATS rather than the stats_update hook: a config +* always installs the hook, but the counters are optional in both MACs, +* so only probe_init() knows whether they are there. +*/ +if (lp->features &XAE_FEATURE_STATS && lp->axienet_config->stats_update) { +mutex_lock (&lp->stats_lock); + lp->axienet_config->stats_update (lp); +mutex_unlock (&lp->stats_lock); + }
[Severity: Low]
Is "no frames are missed" guaranteed here? axienet_setoptions() only does a few posted read-modify-write MMIO accesses to clear ctl_tx_enable and ctl_rx_enable. Nothing waits for the MAC to go idle before axienet_xxv_stats_update() writes TICK_REG.
Suppose the MAC finishes a frame that is already in flight after the enable is cleared. A jumbo frame takes about 7.7 us at 10G and about 3 us at 25G. Could that frame be counted into the internal accumulator after this final tick?
On the next open, axienet_xxv_mac_init() does:
if (lp->features & XAE_FEATURE_STATS) axienet_iow(lp, XXV_TICKREG_OFFSET, XXV_TICKREG_STATEN_MASK);
This latches the late count into the readable registers. The first stats_update tick then overwrites those registers without reading them.
Would up to one frame per direction per stop then never reach xxv_stat_base?
This depends on how PG210 behaves when the enable is deasserted, which could not be checked from the tree.
Quoted 4 lines
drivers/net/ethernet/xilinx/xilinx_axienet_xxv.c +0
-0
[ ... ]
Quoted 6 lines
drivers/net/ethernet/xilinx/xilinx_axienet_xxv.c +2
-0@@ -335,6 +411,204 @@ static int axienet_10g25g_clk_init(struct axienet_local *lp)return 0 ; } +/** +* axienet_xxv_stats_update - Latch and accumulate XXV hardware counters
[ ... ]
Quoted 6 lines
+ * Readers copy @xxv_stat_base and do not tick.
ndo_get_stats64()may run in
+ * atomic context, so it cannot take @stats_lock and tick itself. The periodic
+ * statistics work, and the final snapshot inaxienet_stop(), are the latches.
+ */drivers/net/ethernet/xilinx/xilinx_axienet_xxv.c +2
-0+static void axienet_xxv_stats_update (struct axienet_local *lp) +{
[ ... ]
Quoted 9 lines
drivers/net/ethernet/xilinx/xilinx_axienet_xxv.c +9
-0+write_seqcount_begin (&lp->hw_stats_seqcount); +for (stat =0 ; stat <XXV_STAT_COUNT ; stat++) + lp->xxv_stat_base[stat] += counter[stat]; +write_seqcount_end (&lp->hw_stats_seqcount); +} + +/** +* axienet_xxv_get_stats64 - Fill rtnl_link_stats64 from XXV counters +* @lp: Pointer to the axienet_local structure
drivers/net/ethernet/xilinx/xilinx_axienet_xxv.c static int axienet_10g25g_clk_init(struct axienet_local *lp) · line 460
Quoted 10 lines
drivers/net/ethernet/xilinx/xilinx_axienet_xxv.c +10
-0+* @stats: Output rtnl_link_stats64 structure to populate +*/ +static void axienet_xxv_get_stats64 (struct axienet_local *lp, +struct rtnl_link_stats64 *stats) +{ +unsigned int start; +u64 tx_hw_errors; + + do { + start = read_seqcount_begin(&lp->hw_stats_seqcount);
[Severity: Medium]
Can this reader sleep on PREEMPT_RT? hw_stats_seqcount is a seqcount_mutex_t bound to stats_lock in axienet_probe():
seqcount_mutex_init(&lp->hw_stats_seqcount, &lp->stats_lock);
With CONFIG_PREEMPT_RT, read_seqcount_begin() on a seqcount_mutex_t calls mutex_lock(s->lock) and then mutex_unlock() when it sees an odd sequence. On RT the writer also stays preemptible between write_seqcount_begin() and write_seqcount_end().
The write section in axienet_xxv_stats_update() runs with stats_lock held, from the stats work or from axienet_stop(). A reader that overlaps it would block on stats_lock. ndo_get_stats64 can be called under rcu_read_lock(), for example from /proc/net/dev, where dev_seq_start() takes rcu_read_lock():
dev_seq_show()
dev_seq_printf_stats()
dev_get_stats()
axienet_get_stats64()
axienet_xxv_get_stats64()
read_seqcount_begin()
mutex_lock(&lp->stats_lock)Bonding also calls it under its stats spinlock plus RCU.
Would this trigger a "sleeping function called from invalid context" splat on RT kernels? The kernel-doc above says ndo_get_stats64() cannot take @stats_lock, but on RT the seqcount takes it anyway.
The 1G reader axienet_1g_get_stats64() already uses the same pattern. This patch adds a new atomic-context reader whose design assumes that readers never take stats_lock.
[ ... ]
drivers/net/ethernet/xilinx/xilinx_axienet_xxv.c static int axienet_10g25g_clk_init(struct axienet_local *lp) · line 505
Quoted 10 lines
drivers/net/ethernet/xilinx/xilinx_axienet_xxv.c +10
-0+static void axienet_xxv_get_ethtool_stats (struct axienet_local *lp,u64 *data) +{ +unsigned int i, start; + +do { + start =read_seqcount_begin (&lp->hw_stats_seqcount); +for (i =0 ; i <ARRAY_SIZE (axienet_xxv_priv_stats); i++) + data[i] = lp->xxv_stat_base[axienet_xxv_priv_stats[i]]; + }while (read_seqcount_retry (&lp->hw_stats_seqcount, start)); +}
[Severity: Medium]
Will ethtool -S on XXV return values that are at least one work interval old? This reader only copies lp->xxv_stat_base. So do axienet_xxv_get_pause_stats(), axienet_xxv_get_eth_mac_stats(), axienet_xxv_get_rmon_stats() and axienet_xxv_get_stats64().
The base only changes in axienet_xxv_stats_update(), which is called from axienet_refresh_stats() and axienet_stop(). The work is set up with INIT_DEFERRABLE_WORK() and re-armed every 13 * HZ, so on an idle CPU the lag can go well past 13 seconds. After a traffic burst, the ethtool -S totals and the pause, eth-mac and RMON groups would not change until the work runs.
The commit message explains why ndo_get_stats64() cannot tick. The ethtool callbacks, though, run in process context under RTNL.
Could they take stats_lock and call stats_update so they return current values?
For comparison, the 1G readers go through axienet_stat(), which adds the live register to the software base:
counter = axienet_ior(lp, XAE_STATS_OFFSET + stat * 8); return lp->hw_stat_base[stat] + (counter - lp->hw_last_counter[stat]);
so the 1G ethtool and stats64 values are current.
In ndo_get_stats64 the software rx/tx packet and byte counters are live, while the XXV hardware error and multicast counters come from the cached base. A single snapshot therefore mixes values from different points in time.
[ ... ]
drivers/net/ethernet/xilinx/xilinx_axienet_xxv.c static int axienet_10g25g_clk_init(struct axienet_local *lp) · line 579
Quoted 4 lines
drivers/net/ethernet/xilinx/xilinx_axienet_xxv.c +4
-0+ mac_stats->InRangeLengthErrors = + lp->xxv_stat_base[XXV_STAT_RX_INRANGEERR ]; + }while (read_seqcount_retry (&lp->hw_stats_seqcount, start)); +}
[Severity: Low]
Should FrameTooLongErrors be filled in here too? axienet_xxv_get_stats64() treats XXV_STAT_RX_OVERSIZE as a frame-too-long error and folds it into rx_length_errors:
/* Both in-range length errors and frame-too-long (oversize) * frames are IEEE 802.3 length errors, so fold them together
axienet_xxv_get_rmon_stats() also reports it as oversize_pkts.
struct ethtool_eth_mac_stats has a FrameTooLongErrors field, but it is never set here. As a result, ethtool -S <dev> --groups eth-mac shows it as unsupported, even though the driver already accumulates the counter.
Quoted 8 lines
drivers/net/ethernet/xilinx/xilinx_axienet_xxv.c +8
-0+ +/** +* axienet_xxv_get_rmon_stats - Fill RMON statistics and histogram ranges +* @lp: Pointer to the axienet_local structure +* @rmon_stats: Output ethtool_rmon_stats structure to populate +* @ranges: Set to NULL; XXV exposes aggregate RMON counters only, not +* per-bin histogram ranges. +*/
[ ... ]
drivers/net/ethernet/xilinx/xilinx_axienet_xxv.c static int axienet_10g25g_clk_init(struct axienet_local *lp) · line 610
Quoted 5 lines
drivers/net/ethernet/xilinx/xilinx_axienet_xxv.c +5
-0+/* XXV currently exposes only aggregate RMON counters, not per-bin +* histogram buckets. Keep ranges NULL until histogram bins are wired. +*/ + *ranges =NULL ; +}
[Severity: Low]
Is the kernel-doc accurate about the hardware? The register map this patch adds in xilinx_axienet_xxv.h has a gap here:
#define XXV_STAT_RX_TOTAL_GOOD_BYTES_OFFSET 0x00000820
#define XXV_STAT_RX_UNDERSIZE_OFFSET 0x00000898
That gap is 14 skipped 8-byte counter slots, 0x828 to 0x890. There is a similar gap here:
#define XXV_STAT_TX_TOTAL_GOOD_BYTES_OFFSET 0x00000718
#define XXV_STAT_TX_BAD_FCS_OFFSET 0x000007B8
These look like the PG210 per-size-bin packet counters (64, 65-127, ... 8192-9215 bytes, plus large and small). This could not be checked against the PG210 datasheet from the tree. The inline comment ("currently ... until histogram bins are wired") reads like a driver limitation rather than missing hardware.
The commit message says the RMON statistics come from this path. It does not mention that the RX and TX histograms are left out.
Could the kernel-doc and the commit message say that the histogram counters exist but are not wired up yet?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261114182947.2908628-1-suraj.gupta2%40amd.com