Xilinx axienet driver updates (v5)
Subsystems (5)
v5 cover Xilinx axienet driver updates (v5)
This is a series of enhancements and bug fixes in order to get the mainline version of this driver into a more generally usable state, including on x86 or ARM platforms. It also converts the driver to use the phylink API in order to provide support for SFP modules.
Changes since v4:
-Use reverse christmas tree variable order
Robert Hancock (20):
net: axienet: Fix casting of pointers to u32
net: axienet: Use standard IO accessors
net: axienet: fix MDIO bus naming
net: axienet: add X86 and ARM as supported platforms
net: axienet: Use clock framework to get device clock rate
net: axienet: fix teardown order of MDIO bus
net: axienet: Re-initialize MDIO registers properly after reset
net: axienet: Cleanup DMA device reset and halt process
net: axienet: Make RX/TX ring sizes configurable
net: axienet: Add DMA registers to ethtool register dump
net: axienet: Support shared interrupts
net: axienet: Add optional support for Ethernet core interrupt
net: axienet: Fix race condition causing TX hang
net: axienet: Make missing MAC address non-fatal
net: axienet: stop interface during shutdown
net: axienet: document device tree mdio child node
net: axienet: Fix MDIO bus parent node detection
net: axienet: document axistream-connected attribute
net: axienet: make use of axistream-connected attribute optional
net: axienet: convert to phylink API
.../devicetree/bindings/net/xilinx_axienet.txt | 29 +- drivers/net/ethernet/xilinx/Kconfig | 6 +- drivers/net/ethernet/xilinx/xilinx_axienet.h | 35 +- drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 677 ++++++++++++++------- drivers/net/ethernet/xilinx/xilinx_axienet_mdio.c | 111 ++-- 5 files changed, 593 insertions(+), 265 deletions(-)
Signature · 1 line
1.8.3.1
PATCH v5 6/20 net: axienet: fix teardown order of MDIO bus
Since the MDIO is is brought up before the netdev is registered, it should be torn down after the netdev is removed. Otherwise, PHY accesses can potentially access freed MDIO bus references and cause a crash.
--- drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +1 -1
@@ -1651,8 +1651,8 @@ static int axienet_remove(struct platform_device *pdev)struct net_device *ndev =platform_get_drvdata (pdev);struct axienet_local *lp =netdev_priv (ndev); -axienet_mdio_teardown (lp);unregister_netdev (ndev); +axienet_mdio_teardown (lp);if (lp->clk)clk_disable_unprepare (lp->clk);
Signature · 1 line
1.8.3.1
PATCH v5 11/20 net: axienet: Support shared interrupts
In reply to Robert HancockSpecify IRQF_SHARED to support shared interrupts. If the interrupt handler is called and the device is not indicating an interrupt, just return IRQ_NONE rather than spewing error messages.
--- drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +8 -6
@@ -809,7 +809,7 @@ static void axienet_recv(struct net_device *ndev)* @irq: irq number * @_ndev: net_device pointer * -* Return: IRQ_HANDLED for all cases. +* Return: IRQ_HANDLED if device generated a TX interrupt, IRQ_NONE otherwise. * * This is the Axi DMA Tx done Isr. It invokes "axienet_start_xmit_done" * to complete the BD processing.
@@ -828,7 +828,7 @@ static irqreturn_t axienet_tx_irq(int irq, void *_ndev) goto out; }if (!(status &XAXIDMA_IRQ_ALL_MASK )) -dev_err (&ndev->dev,"No interrupts asserted in Tx path\n" ); +return IRQ_NONE ;if (status &XAXIDMA_IRQ_ERROR_MASK ) {dev_err (&ndev->dev,"DMA Tx error 0x%x\n" , status); dev_err(&ndev->dev, "Current BD is at: 0x%x\n",
@@ -858,7 +858,7 @@ static irqreturn_t axienet_tx_irq(int irq, void *_ndev)* @irq: irq number * @_ndev: net_device pointer * -* Return: IRQ_HANDLED for all cases. +* Return: IRQ_HANDLED if device generated a RX interrupt, IRQ_NONE otherwise. * * This is the Axi DMA Rx Isr. It invokes "axienet_recv" to complete the BD * processing.
@@ -877,7 +877,7 @@ static irqreturn_t axienet_rx_irq(int irq, void *_ndev) goto out; }if (!(status &XAXIDMA_IRQ_ALL_MASK )) -dev_err (&ndev->dev,"No interrupts asserted in Rx path\n" ); +return IRQ_NONE ;if (status &XAXIDMA_IRQ_ERROR_MASK ) {dev_err (&ndev->dev,"DMA Rx error 0x%x\n" , status); dev_err(&ndev->dev, "Current BD is at: 0x%x\n",
@@ -953,11 +953,13 @@ static int axienet_open(struct net_device *ndev) (unsigned long) lp);/* Enable interrupts for Axi DMA Tx */ - ret =request_irq (lp->tx_irq, axienet_tx_irq,0 , ndev->name, ndev); + ret =request_irq (lp->tx_irq, axienet_tx_irq,IRQF_SHARED , + ndev->name, ndev);if (ret) goto err_tx_irq;/* Enable interrupts for Axi DMA Rx */ - ret =request_irq (lp->rx_irq, axienet_rx_irq,0 , ndev->name, ndev); + ret =request_irq (lp->rx_irq, axienet_rx_irq,IRQF_SHARED , + ndev->name, ndev);if (ret) goto err_rx_irq;
Signature · 1 line
1.8.3.1
PATCH v5 7/20 net: axienet: Re-initialize MDIO registers properly after reset
In reply to Robert HancockThe MDIO clock divisor register setting was only applied on the initial startup when the driver was loaded. However, this setting is cleared when the device is reset, such as would occur when the interface was taken down and brought up again, and so the MDIO bus would be non-functional afterwards.
Split up the MDIO bus setup and enable into separate functions and re-enable the bus after a device reset, to ensure that the MDIO registers are set properly. This also allows us to remove direct access to MDIO registers in xilinx_axienet_main.c and centralize them all in xilinx_axienet_mdio.c.
Also, lock the MDIO bus lock around the device reset process, to avoid MDIO accesses from occurring while the MDIO is disabled during the reset.
--- drivers/net/ethernet/xilinx/xilinx_axienet.h | 3 +- drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 38 +++++++--------- drivers/net/ethernet/xilinx/xilinx_axienet_mdio.c | 54 +++++++++++++++++------ 3 files changed, 57 insertions(+), 38 deletions(-)
drivers/net/ethernet/xilinx/xilinx_axienet.h +2 -1
@@ -505,8 +505,9 @@ static inline void axienet_iow(struct axienet_local *lp, off_t offset, }/* Function prototypes visible in xilinx_axienet_mdio.c for other files */ +int axienet_mdio_enable (struct axienet_local *lp); +void axienet_mdio_disable (struct axienet_local *lp);int axienet_mdio_setup (struct axienet_local *lp); -int axienet_mdio_wait_until_ready (struct axienet_local *lp);void axienet_mdio_teardown (struct axienet_local *lp);#endif /* XILINX_AXI_ENET_H */
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +15 -23
@@ -914,27 +914,23 @@ static irqreturn_t axienet_rx_irq(int irq, void *_ndev)*/ static int axienet_open (struct net_device *ndev) { -int ret, mdio_mcreg; +int ret;struct axienet_local *lp =netdev_priv (ndev);struct phy_device *phydev =NULL ;dev_dbg (&ndev->dev,"axienet_open()\n" ); - mdio_mcreg =axienet_ior (lp,XAE_MDIO_MC_OFFSET ); - ret =axienet_mdio_wait_until_ready (lp); -if (ret <0 ) -return ret;/* Disable the MDIO interface till Axi Ethernet Reset is completed. * When we do an Axi Ethernet reset, it resets the complete core -* including the MDIO. If MDIO is not disabled when the reset -* process is started, MDIO will be broken afterwards. +* including the MDIO. MDIO must be disabled before resetting +* and re-enabled afterwards. +* Hold MDIO bus lock to avoid MDIO accesses during the reset. */ -axienet_iow (lp,XAE_MDIO_MC_OFFSET , - (mdio_mcreg & (~XAE_MDIO_MC_MDIOEN_MASK ))); +mutex_lock (&lp->mii_bus->mdio_lock); +axienet_mdio_disable (lp);axienet_device_reset (ndev); -/* Enable the MDIO */ -axienet_iow (lp,XAE_MDIO_MC_OFFSET , mdio_mcreg); - ret =axienet_mdio_wait_until_ready (lp); + ret =axienet_mdio_enable (lp); +mutex_unlock (&lp->mii_bus->mdio_lock);if (ret <0 )return ret;
@@ -1316,28 +1312,24 @@ static void axienet_dma_err_handler(unsigned long data) {u32 axienet_status;u32 cr, i; -int mdio_mcreg;struct axienet_local *lp = (struct axienet_local *) data;struct net_device *ndev = lp->ndev;struct axidma_bd *cur_p;axienet_setoptions (ndev, lp->options & ~(XAE_OPTION_TXEN |XAE_OPTION_RXEN )); - mdio_mcreg =axienet_ior (lp,XAE_MDIO_MC_OFFSET ); -axienet_mdio_wait_until_ready (lp);/* Disable the MDIO interface till Axi Ethernet Reset is completed. * When we do an Axi Ethernet reset, it resets the complete core -* including the MDIO. So if MDIO is not disabled when the reset -* process is started, MDIO will be broken afterwards. +* including the MDIO. MDIO must be disabled before resetting +* and re-enabled afterwards. +* Hold MDIO bus lock to avoid MDIO accesses during the reset. */ -axienet_iow (lp,XAE_MDIO_MC_OFFSET , (mdio_mcreg & - ~XAE_MDIO_MC_MDIOEN_MASK )); - +mutex_lock (&lp->mii_bus->mdio_lock); +axienet_mdio_disable (lp);__axienet_device_reset (lp,XAXIDMA_TX_CR_OFFSET );__axienet_device_reset (lp,XAXIDMA_RX_CR_OFFSET ); - -axienet_iow (lp,XAE_MDIO_MC_OFFSET , mdio_mcreg); -axienet_mdio_wait_until_ready (lp); +axienet_mdio_enable (lp); +mutex_unlock (&lp->mii_bus->mdio_lock);for (i =0 ; i <TX_BD_NUM ; i++) { cur_p = &lp->tx_bd_v[i];
drivers/net/ethernet/xilinx/xilinx_axienet_mdio.c +40 -14
92 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v5 13/20 net: axienet: Fix race condition causing TX hang
In reply to Robert HancockIt is possible that the interrupt handler fires and frees up space in the TX ring in between checking for sufficient TX ring space and stopping the TX queue in axienet_start_xmit. If this happens, the queue wake from the interrupt handler will occur before the queue is stopped, causing a lost wakeup and the adapter's transmit hanging.
To avoid this, after stopping the queue, check again whether there is sufficient space in the TX ring. If so, wake up the queue again.
--- drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-)
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +17 -3
@@ -622,6 +622,10 @@ static void axienet_start_xmit_done(struct net_device *ndev) ndev->stats.tx_packets += packets; ndev->stats.tx_bytes += size; + +/* Matches barrier in axienet_start_xmit */ +smp_mb (); +netif_wake_queue (ndev); }
@@ -677,9 +681,19 @@ static inline int axienet_check_tx_bd_space(struct axienet_local *lp, cur_p = &lp->tx_bd_v[lp->tx_bd_tail];if (axienet_check_tx_bd_space (lp, num_frag)) { -if (!netif_queue_stopped (ndev)) -netif_stop_queue (ndev); -return NETDEV_TX_BUSY ; +if (netif_queue_stopped (ndev)) +return NETDEV_TX_BUSY ; + +netif_stop_queue (ndev); + +/* Matches barrier in axienet_start_xmit_done */ +smp_mb (); + +/* Space might have just been freed - check again */ +if (axienet_check_tx_bd_space (lp, num_frag)) +return NETDEV_TX_BUSY ; + +netif_wake_queue (ndev); }if (skb->ip_summed ==CHECKSUM_PARTIAL ) {
Signature · 1 line
1.8.3.1
PATCH v5 8/20 net: axienet: Cleanup DMA device reset and halt process
In reply to Robert HancockThe Xilinx DMA blocks each have their own reset register, but they both reset the entire DMA engine, so only one of them needs to be reset.
Also, when stopping the device, we need to not just command the DMA blocks to stop, but wait for them to stop, and trigger a device reset to ensure that they are completely stopped.
--- drivers/net/ethernet/xilinx/xilinx_axienet.h | 2 + drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 54 +++++++++++++++++------ 2 files changed, 42 insertions(+), 14 deletions(-)
drivers/net/ethernet/xilinx/xilinx_axienet.h +2 -0
@@ -83,6 +83,8 @@#define XAXIDMA_CR_RUNSTOP_MASK 0x00000001/* Start/stop DMA channel */ #define XAXIDMA_CR_RESET_MASK 0x00000004/* Reset DMA engine */ +#define XAXIDMA_SR_HALT_MASK 0x00000001/* Indicates DMA channel halted */ +#define XAXIDMA_BD_NDESC_OFFSET 0x00/* Next descriptor pointer */ #define XAXIDMA_BD_BUFA_OFFSET 0x08/* Buffer address */ #define XAXIDMA_BD_CTRL_LEN_OFFSET 0x18/* Control/buffer length */
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +40 -14
93 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v5 19/20 net: axienet: make use of axistream-connected attribute optional
In reply to Robert HancockCurrently the axienet driver requires the use of a second devicetree node, referenced by an axistream-connected attribute on the Ethernet device node, which contains the resources for the AXI DMA block used by the device. This setup is problematic for a use case we have where the Ethernet and DMA cores are behind a PCIe to AXI bridge and the memory resources for the nodes are injected into the platform devices using the multifunction device subsystem - it's not easily possible for the driver to obtain the platform-level resources from the linked device.
In order to simplify that usage model, and simplify the overall use of this driver in general, allow for all of the resources to be kept on one node where the resources are retrieved using platform device APIs rather than device-tree-specific ones. The previous usage setup is still supported if the axistream-connected attribute is specified.
--- drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 43 +++++++++++++++-------- 1 file changed, 28 insertions(+), 15 deletions(-)
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +28 -15
@@ -1580,7 +1580,7 @@ static int axienet_probe(struct platform_device *pdev)struct axienet_local *lp;struct net_device *ndev;const void *mac_addr; -struct resource *ethres, dmares; +struct resource *ethres;u32 value; ndev =alloc_etherdev (sizeof (*lp));
@@ -1698,28 +1698,41 @@ static int axienet_probe(struct platform_device *pdev)/* Find the DMA node, map the DMA registers, and decode the DMA IRQs */ np =of_parse_phandle (pdev->dev.of_node,"axistream-connected" ,0 ); -if (!np) { -dev_err (&pdev->dev,"could not find DMA node\n" ); - ret = -ENODEV ; - goto free_netdev; - } - ret =of_address_to_resource (np,0 , &dmares); -if (ret) { -dev_err (&pdev->dev,"unable to get DMA resource\n" ); +if (np) { +struct resource dmares; + + ret =of_address_to_resource (np,0 , &dmares); +if (ret) { +dev_err (&pdev->dev, +"unable to get DMA resource\n" ); +of_node_put (np); + goto free_netdev; + } + lp->dma_regs =devm_ioremap_resource (&pdev->dev, + &dmares); + lp->rx_irq =irq_of_parse_and_map (np,1 ); + lp->tx_irq =irq_of_parse_and_map (np,0 );of_node_put (np); - goto free_netdev; + lp->eth_irq =platform_get_irq (pdev,0 ); + }else { +/* Check for these resources directly on the Ethernet node. */ +struct resource *res =platform_get_resource (pdev, +IORESOURCE_MEM ,1 ); +if (!res) { +dev_err (&pdev->dev,"unable to get DMA memory resource\n" ); + goto free_netdev; + } + lp->dma_regs =devm_ioremap_resource (&pdev->dev, res); + lp->rx_irq =platform_get_irq (pdev,1 ); + lp->tx_irq =platform_get_irq (pdev,0 ); + lp->eth_irq =platform_get_irq (pdev,2 ); } - lp->dma_regs =devm_ioremap_resource (&pdev->dev, &dmares);if (IS_ERR (lp->dma_regs)) {dev_err (&pdev->dev,"could not map DMA regs\n" ); ret =PTR_ERR (lp->dma_regs);of_node_put (np); goto free_netdev; } - lp->rx_irq =irq_of_parse_and_map (np,1 ); - lp->tx_irq =irq_of_parse_and_map (np,0 ); - lp->eth_irq =irq_of_parse_and_map (np,2 ); -of_node_put (np);if ((lp->rx_irq <=0 ) || (lp->tx_irq <=0 )) {dev_err (&pdev->dev,"could not determine irqs\n" ); ret = -ENOMEM ;
Signature · 1 line
1.8.3.1
PATCH v5 2/20 net: axienet: Use standard IO accessors
In reply to Robert HancockThis driver was using in_be32 and out_be32 IO accessors which do not exist on most platforms. Also, the use of big-endian accessors does not seem correct as this hardware is accessed over an AXI bus which, to the extent it has an endian-ness, is little-endian. Switch to standard ioread32/iowrite32 accessors.
--- drivers/net/ethernet/xilinx/xilinx_axienet.h | 4 ++-- drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)
drivers/net/ethernet/xilinx/xilinx_axienet.h +2 -2
@@ -476,7 +476,7 @@ struct axienet_option {*/ static inline u32 axienet_ior (struct axienet_local *lp,off_t offset) { -return in_be32 (lp->regs + offset); +return ioread32 (lp->regs + offset); }static inline u32 axinet_ior_read_mcr (struct axienet_local *lp)
@@ -496,7 +496,7 @@ static inline u32 axinet_ior_read_mcr(struct axienet_local *lp)static inline void axienet_iow (struct axienet_local *lp,off_t offset,u32 value) { -out_be32 ((lp->regs + offset), value); +iowrite32 (value, lp->regs + offset); }/* Function prototypes visible in xilinx_axienet_mdio.c for other files */
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +2 -2
@@ -125,7 +125,7 @@*/ static inline u32 axienet_dma_in32 (struct axienet_local *lp,off_t reg) { -return in_be32 (lp->dma_regs + reg); +return ioread32 (lp->dma_regs + reg); }/**
@@ -140,7 +140,7 @@ static inline u32 axienet_dma_in32(struct axienet_local *lp, off_t reg)static inline void axienet_dma_out32 (struct axienet_local *lp,off_t reg,u32 value) { -out_be32 ((lp->dma_regs + reg), value); +iowrite32 (value, lp->dma_regs + reg); }/**
Signature · 1 line
1.8.3.1
PATCH v5 16/20 net: axienet: document device tree mdio child node
In reply to Robert HancockThe mdio child node for the MDIO bus is generally required when using this driver but was not documented other than being shown in the example. Document it as an optional (but usually required) parameter.
--- Documentation/devicetree/bindings/net/xilinx_axienet.txt | 3 +++ 1 file changed, 3 insertions(+)
Documentation/devicetree/bindings/net/xilinx_axienet.txt +3 -0
@@ -37,6 +37,9 @@ Optional properties: auto-detected from the CPU clock (but only on platforms where this is possible). New device trees should specify this - the auto detection is only for backward compatibility. + - mdio : Child node for MDIO bus. Must be defined if PHY access is + required through the core's MDIO interface (i.e. always, + unless the PHY is accessed through a different bus). Example: axi_ethernet_eth: ethernet@40c00000 {
Signature · 1 line
1.8.3.1
PATCH v5 12/20 net: axienet: Add optional support for Ethernet core interrupt
In reply to Robert HancockPreviously this driver only handled interrupts from the DMA RX and TX blocks, not from the Ethernet core itself. Add optional support for the Ethernet core interrupt, which is used to detect rx_missed and framing errors signalled by the hardware. In order to use this interrupt, a third interrupt needs to be specified in the device tree.
--- .../devicetree/bindings/net/xilinx_axienet.txt | 3 +- drivers/net/ethernet/xilinx/xilinx_axienet.h | 1 + drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 49 ++++++++++++++++++++++ 3 files changed, 52 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/net/xilinx_axienet.txt +2 -1
@@ -18,7 +18,8 @@ Required properties: - compatible : Must be one of "xlnx,axi-ethernet-1.00.a", "xlnx,axi-ethernet-1.01.a", "xlnx,axi-ethernet-2.01.a" - reg : Address and length of the IO space. -- interrupts : Should be a list of two interrupt, TX and RX. +- interrupts : Should be a list of 2 or 3 interrupts: TX DMA, RX DMA, + and optionally Ethernet core. - phy-handle : Should point to the external phy device. See ethernet.txt file in the same directory. - xlnx,rxmem : Set to allocated memory buffer for Rx/Tx in the hardware
drivers/net/ethernet/xilinx/xilinx_axienet.h +1 -0
@@ -435,6 +435,7 @@ struct axienet_local {int tx_irq;int rx_irq; +int eth_irq;phy_interface_t phy_mode;u32 options;/* Current options word */
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +49 -0
94 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v5 17/20 net: axienet: Fix MDIO bus parent node detection
In reply to Robert HancockThis driver was previously using the parent node of the specified PHY node as the device node to register the MDIO bus on. Andrew Lunn pointed out this is wrong as the PHY node is potentially not even underneath the MDIO bus for the current device instance. Find the MDIO node explicitly by looking it up by name under the controller's device node instead.
This could potentially break existing device trees if they don't use "mdio" as the name for the MDIO bus, but I did not find any with various searches and Xilinx's examples all use mdio as the name so it seems like this should be relatively safe.
--- drivers/net/ethernet/xilinx/xilinx_axienet_mdio.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/ethernet/xilinx/xilinx_axienet_mdio.c +2 -1
@@ -228,7 +228,6 @@ int axienet_mdio_setup(struct axienet_local *lp)if (!bus)return -ENOMEM ; - mdio_node =of_get_parent (lp->phy_node);snprintf (bus->id,MII_BUS_ID_SIZE ,"axienet-%.8llx" , (unsigned long long )lp->regs_start);
@@ -239,7 +238,9 @@ int axienet_mdio_setup(struct axienet_local *lp) bus->parent = lp->dev; lp->mii_bus = bus; + mdio_node =of_get_child_by_name (lp->dev->of_node,"mdio" ); ret =of_mdiobus_register (bus, mdio_node); +of_node_put (mdio_node);if (ret) {mdiobus_free (bus); lp->mii_bus =NULL ;
Signature · 1 line
1.8.3.1
PATCH v5 1/20 net: axienet: Fix casting of pointers to u32
In reply to Robert HancockThis driver was casting skb pointers to u32 and storing them as such in the DMA buffer descriptor, which is obviously broken on 64-bit. The area of the buffer descriptor being used is not accessed by the hardware and has sufficient room for a 32 or 64-bit pointer, so just store the skb pointer as such.
--- drivers/net/ethernet/xilinx/xilinx_axienet.h | 11 +++------- drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 26 ++++++++++++----------- 2 files changed, 17 insertions(+), 20 deletions(-)
drivers/net/ethernet/xilinx/xilinx_axienet.h +3 -8
@@ -356,9 +356,6 @@* @app2: MM2S/S2MM User Application Field 2. * @app3: MM2S/S2MM User Application Field 3. * @app4: MM2S/S2MM User Application Field 4. -* @sw_id_offset: MM2S/S2MM Sw ID -* @reserved5: Reserved and not used -* @reserved6: Reserved and not used */ struct axidma_bd {u32 next;/* Physical address of next buffer descriptor */
@@ -373,11 +370,9 @@ struct axidma_bd {u32 app1;/* TX start << 16 | insert */ u32 app2;/* TX csum seed */ u32 app3; -u32 app4; -u32 sw_id_offset; -u32 reserved5; -u32 reserved6; -}; +u32 app4;/* Last field used by HW */ +struct sk_buff *skb; +}__aligned(XAXIDMA_BD_MINIMUM_ALIGNMENT) ;/** * struct axienet_local - axienet private per device data
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +14 -12
@@ -159,8 +159,7 @@ static void axienet_dma_bd_release(struct net_device *ndev)for (i =0 ; i <RX_BD_NUM ; i++) {dma_unmap_single (ndev->dev.parent, lp->rx_bd_v[i].phys, lp->max_frm_size,DMA_FROM_DEVICE ); -dev_kfree_skb ((struct sk_buff *) - (lp->rx_bd_v[i].sw_id_offset)); +dev_kfree_skb (lp->rx_bd_v[i].skb); }if (lp->rx_bd_v) {
@@ -227,7 +226,7 @@ static int axienet_dma_bd_init(struct net_device *ndev)if (!skb) goto out; - lp->rx_bd_v[i].sw_id_offset = (u32 ) skb; + lp->rx_bd_v[i].skb = skb; lp->rx_bd_v[i].phys = dma_map_single(ndev->dev.parent, skb->data, lp->max_frm_size,
@@ -595,14 +594,15 @@ static void axienet_start_xmit_done(struct net_device *ndev)dma_unmap_single (ndev->dev.parent, cur_p->phys, (cur_p->cntrl &XAXIDMA_BD_CTRL_LENGTH_MASK ),DMA_TO_DEVICE ); -if (cur_p->app4) -dev_consume_skb_irq ((struct sk_buff *)cur_p->app4); +if (cur_p->skb) +dev_consume_skb_irq (cur_p->skb);/*cur_p->phys = 0;*/ cur_p->app0 =0 ; cur_p->app1 =0 ; cur_p->app2 =0 ; cur_p->app4 =0 ; cur_p->status =0 ; + cur_p->skb =NULL ; size += status &XAXIDMA_BD_STS_ACTUAL_LEN_MASK ; packets++;
@@ -707,7 +707,7 @@ static inline int axienet_check_tx_bd_space(struct axienet_local *lp, } cur_p->cntrl |=XAXIDMA_BD_CTRL_TXEOF_MASK ; - cur_p->app4 = (unsigned long )skb; + cur_p->skb = skb; tail_p = lp->tx_bd_p +sizeof (*lp->tx_bd_v) * lp->tx_bd_tail;/* Start the transfer */
@@ -742,13 +742,15 @@ static void axienet_recv(struct net_device *ndev)while ((cur_p->status &XAXIDMA_BD_STS_COMPLETE_MASK )) { tail_p = lp->rx_bd_p +sizeof (*lp->rx_bd_v) * lp->rx_bd_ci; - skb = (struct sk_buff *) (cur_p->sw_id_offset); - length = cur_p->app4 &0x0000FFFF ;dma_unmap_single (ndev->dev.parent, cur_p->phys, lp->max_frm_size,DMA_FROM_DEVICE ); + skb = cur_p->skb; + cur_p->skb =NULL ; + length = cur_p->app4 &0x0000FFFF ; +skb_put (skb, length); skb->protocol =eth_type_trans (skb, ndev);/*skb_checksum_none_assert(skb);*/
@@ -783,7 +785,7 @@ static void axienet_recv(struct net_device *ndev) DMA_FROM_DEVICE); cur_p->cntrl = lp->max_frm_size; cur_p->status =0 ; - cur_p->sw_id_offset = (u32 ) new_skb; + cur_p->skb = new_skb; ++lp->rx_bd_ci; lp->rx_bd_ci %=RX_BD_NUM ;
@@ -1343,8 +1345,8 @@ static void axienet_dma_err_handler(unsigned long data) (cur_p->cntrl &XAXIDMA_BD_CTRL_LENGTH_MASK ), DMA_TO_DEVICE); -if (cur_p->app4) -dev_kfree_skb_irq ((struct sk_buff *) cur_p->app4); +if (cur_p->skb) +dev_kfree_skb_irq (cur_p->skb); cur_p->phys =0 ; cur_p->cntrl =0 ; cur_p->status =0 ;
@@ -1353,7 +1355,7 @@ static void axienet_dma_err_handler(unsigned long data) cur_p->app2 =0 ; cur_p->app3 =0 ; cur_p->app4 =0 ; - cur_p->sw_id_offset =0 ; + cur_p->skb =NULL ; }for (i =0 ; i <RX_BD_NUM ; i++) {
Signature · 1 line
1.8.3.1
PATCH v5 4/20 net: axienet: add X86 and ARM as supported platforms
In reply to Robert HancockThis driver should now build on (at least) X86 and ARM platforms, so add them as supported platforms for the driver in Kconfig.
--- drivers/net/ethernet/xilinx/Kconfig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/xilinx/Kconfig +2 -2
@@ -6,7 +6,7 @@ config NET_VENDOR_XILINX bool "Xilinx devices" default y - depends on PPC || PPC32 || MICROBLAZE || ARCH_ZYNQ || MIPS || X86 || COMPILE_TEST + depends on PPC || PPC32 || MICROBLAZE || ARCH_ZYNQ || MIPS || X86 || ARM || COMPILE_TEST ---help--- If you have a network (Ethernet) card belonging to this class, say Y.
@@ -26,7 +26,7 @@ config XILINX_EMACLITE config XILINX_AXI_EMAC tristate "Xilinx 10/100/1000 AXI Ethernet support" - depends on MICROBLAZE + depends on MICROBLAZE || X86 || ARM || COMPILE_TEST select PHYLIB ---help--- This driver supports the 10/100/1000 Ethernet from Xilinx for the
Signature · 1 line
1.8.3.1
PATCH v5 14/20 net: axienet: Make missing MAC address non-fatal
In reply to Robert HancockFailing initialization on a missing MAC address property is excessive. We can just fall back to using a random MAC instead, which at least leaves the interface in a functioning state.
--- drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +3 -2
@@ -1733,8 +1733,9 @@ static int axienet_probe(struct platform_device *pdev)/* Retrieve the MAC address */ mac_addr =of_get_mac_address (pdev->dev.of_node);if (IS_ERR (mac_addr)) { -dev_err (&pdev->dev,"could not find MAC address\n" ); - goto free_netdev; +dev_warn (&pdev->dev,"could not find MAC address property: %ld\n" , +PTR_ERR (mac_addr)); + mac_addr =NULL ; }axienet_set_mac_address (ndev, mac_addr);
Signature · 1 line
1.8.3.1
PATCH v5 15/20 net: axienet: stop interface during shutdown
In reply to Robert HancockOn some platforms, such as iMX6 with PCIe devices, crashes or hangs can occur if the axienet device continues to perform DMA transfers after parent devices/busses have been shut down. Shut down the axienet interface during its shutdown callback in order to avoid this.
--- drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +14 -0
@@ -1797,9 +1797,23 @@ static int axienet_remove(struct platform_device *pdev)return 0 ; } +static void axienet_shutdown (struct platform_device *pdev) +{ +struct net_device *ndev =platform_get_drvdata (pdev); + +rtnl_lock (); +netif_device_detach (ndev); + +if (netif_running (ndev)) +dev_close (ndev); + +rtnl_unlock (); +} +static struct platform_driver axienet_driver = { .probe = axienet_probe, .remove = axienet_remove, + .shutdown = axienet_shutdown, .driver = { .name ="xilinx_axienet" , .of_match_table = axienet_of_match,
Signature · 1 line
1.8.3.1
PATCH v5 20/20 net: axienet: convert to phylink API
In reply to Robert HancockConvert this driver to use the phylink API rather than the legacy PHY API. This allows for better support for SFP modules connected using a 1000BaseX or SGMII interface.
--- drivers/net/ethernet/xilinx/Kconfig | 2 +- drivers/net/ethernet/xilinx/xilinx_axienet.h | 5 +- drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 286 ++++++++++++++-------- 3 files changed, 192 insertions(+), 101 deletions(-)
drivers/net/ethernet/xilinx/Kconfig +1 -1
@@ -27,7 +27,7 @@ config XILINX_EMACLITE config XILINX_AXI_EMAC tristate "Xilinx 10/100/1000 AXI Ethernet support" depends on MICROBLAZE || X86 || ARM || COMPILE_TEST - select PHYLIB + select PHYLINK ---help--- This driver supports the 10/100/1000 Ethernet from Xilinx for the AXI bus interface used in Xilinx Virtex FPGAs.
drivers/net/ethernet/xilinx/xilinx_axienet.h +4 -1
@@ -13,6 +13,7 @@#include <linux/spinlock.h> #include <linux/interrupt.h> #include <linux/if_vlan.h> +#include <linux/phylink.h> /* Packet size info */ #define XAE_HDR_SIZE 14/* Size of Ethernet header */
@@ -420,6 +421,9 @@ struct axienet_local {/* Connection to PHY device */ struct device_node *phy_node; +struct phylink *phylink; +struct phylink_config phylink_config; +/* Clock for AXI bus */ struct clk *clk;
@@ -439,7 +443,6 @@ struct axienet_local {phy_interface_t phy_mode;u32 options;/* Current options word */ -u32 last_link;u32 features;/* Buffer descriptors */
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +187 -99
381 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v5 3/20 net: axienet: fix MDIO bus naming
In reply to Robert HancockThe MDIO bus for this driver was being named using the result of of_address_to_resource on a node which may not have any resource on it, but the return value of that call was not checked so it was using some random value in the bus name. Change to name the MDIO bus based on the resource start of the actual Ethernet register block.
--- drivers/net/ethernet/xilinx/xilinx_axienet.h | 2 ++ drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 1 + drivers/net/ethernet/xilinx/xilinx_axienet_mdio.c | 11 +++++------ 3 files changed, 8 insertions(+), 6 deletions(-)
drivers/net/ethernet/xilinx/xilinx_axienet.h +2 -0
@@ -380,6 +380,7 @@ struct axidma_bd {* @dev: Pointer to device structure * @phy_node: Pointer to device node structure * @mii_bus: Pointer to MII bus structure +* @regs_start: Resource start for axienet device addresses * @regs: Base address for the axienet_local device address space * @dma_regs: Base address for the axidma device address space * @dma_err_tasklet: Tasklet structure to process Axi DMA errors
@@ -421,6 +422,7 @@ struct axienet_local {struct mii_bus *mii_bus;/* MII bus reference */ /* IO registers, dma functions and IRQs */ +resource_size_t regs_start;void __iomem *regs;void __iomem *dma_regs;
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +1 -0
@@ -1480,6 +1480,7 @@ static int axienet_probe(struct platform_device *pdev) lp->options =XAE_OPTION_DEFAULTS ;/* Map device registers */ ethres =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); + lp->regs_start = ethres->start; lp->regs =devm_ioremap_resource (&pdev->dev, ethres);if (IS_ERR (lp->regs)) {dev_err (&pdev->dev,"could not map Axi Ethernet regs.\n" );
drivers/net/ethernet/xilinx/xilinx_axienet_mdio.c +5 -6
@@ -127,7 +127,7 @@ int axienet_mdio_setup(struct axienet_local *lp, struct device_node *np)int ret;u32 clk_div, host_clock;struct mii_bus *bus; -struct resource res; +struct device_node *mdio_node;struct device_node *np1;/* clk_div can be calculated by deriving it from the equation:
@@ -199,10 +199,9 @@ int axienet_mdio_setup(struct axienet_local *lp, struct device_node *np)if (!bus)return -ENOMEM ; - np1 =of_get_parent (lp->phy_node); -of_address_to_resource (np1,0 , &res); -snprintf (bus->id,MII_BUS_ID_SIZE ,"%.8llx" , - (unsigned long long ) res.start); + mdio_node =of_get_parent (lp->phy_node); +snprintf (bus->id,MII_BUS_ID_SIZE ,"axienet-%.8llx" , + (unsigned long long )lp->regs_start); bus->priv = lp; bus->name ="Xilinx Axi Ethernet MDIO" ;
@@ -211,7 +210,7 @@ int axienet_mdio_setup(struct axienet_local *lp, struct device_node *np) bus->parent = lp->dev; lp->mii_bus = bus; - ret =of_mdiobus_register (bus, np1); + ret =of_mdiobus_register (bus, mdio_node);if (ret) {mdiobus_free (bus); lp->mii_bus =NULL ;
Signature · 1 line
1.8.3.1
PATCH v5 9/20 net: axienet: Make RX/TX ring sizes configurable
In reply to Robert HancockAdd support for setting the RX and TX ring sizes for this driver using ethtool. Also increase the default RX ring size as the previous default was far too low for good performance in some configurations.
--- drivers/net/ethernet/xilinx/xilinx_axienet.h | 2 + drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 90 ++++++++++++++++------- 2 files changed, 67 insertions(+), 25 deletions(-)
drivers/net/ethernet/xilinx/xilinx_axienet.h +2 -0
@@ -444,8 +444,10 @@ struct axienet_local {/* Buffer descriptors */ struct axidma_bd *tx_bd_v;dma_addr_t tx_bd_p; +u32 tx_bd_num;struct axidma_bd *rx_bd_v;dma_addr_t rx_bd_p; +u32 rx_bd_num;u32 tx_bd_ci;u32 tx_bd_tail;u32 rx_bd_ci;
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +65 -25
206 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v5 18/20 net: axienet: document axistream-connected attribute
In reply to Robert HancockThe axienet driver requires the use of an axistream-connected attribute, but this isn't documented in the devicetree bindings. Document how this attribute is supposed to be used, including the upcoming change to make the usage of this attribute optional.
--- .../devicetree/bindings/net/xilinx_axienet.txt | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-)
Documentation/devicetree/bindings/net/xilinx_axienet.txt +15 -4
@@ -17,9 +17,15 @@ For more details about mdio please refer phy.txt file in the same directory. Required properties: - compatible : Must be one of "xlnx,axi-ethernet-1.00.a", "xlnx,axi-ethernet-1.01.a", "xlnx,axi-ethernet-2.01.a" -- reg : Address and length of the IO space. +- reg : Address and length of the IO space, as well as the address + and length of the AXI DMA controller IO space, unless + axistream-connected is specified, in which case the reg + attribute of the node referenced by it is used. - interrupts : Should be a list of 2 or 3 interrupts: TX DMA, RX DMA, - and optionally Ethernet core. + and optionally Ethernet core. If axistream-connected is + specified, the TX/RX DMA interrupts should be on that node + instead, and only the Ethernet core interrupt is optionally + specified here. - phy-handle : Should point to the external phy device. See ethernet.txt file in the same directory. - xlnx,rxmem : Set to allocated memory buffer for Rx/Tx in the hardware
@@ -37,6 +43,11 @@ Optional properties: auto-detected from the CPU clock (but only on platforms where this is possible). New device trees should specify this - the auto detection is only for backward compatibility. +- axistream-connected: Reference to another node which contains the resources + for the AXI DMA controller used by this device. + If this is specified, the DMA-related resources from that + device (DMA registers and DMA TX/RX interrupts) rather + than this one will be used. - mdio : Child node for MDIO bus. Must be defined if PHY access is required through the core's MDIO interface (i.e. always, unless the PHY is accessed through a different bus).
@@ -46,10 +57,10 @@ Example: compatible = "xlnx,axi-ethernet-1.00.a"; device_type = "network"; interrupt-parent = <µblaze_0_axi_intc>; - interrupts = <2 0>; + interrupts = <2 0 1>; clocks = <&axi_clk>; phy-mode = "mii"; - reg = <0x40c00000 0x40000>; + reg = <0x40c00000 0x40000 0x50c00000 0x40000>; xlnx,rxcsum = <0x2>; xlnx,rxmem = <0x800>; xlnx,txcsum = <0x2>;
Signature · 1 line
1.8.3.1
PATCH v5 5/20 net: axienet: Use clock framework to get device clock rate
In reply to Robert HancockThis driver was previously always calculating the MDIO clock divisor (from AXI bus clock to MDIO bus clock) based on the CPU clock frequency, assuming that it is the same as the AXI bus frequency, but that simplistic method only works on the MicroBlaze platform.
Add support for specifying the clock used for the device in the device tree using the clock framework. If the clock is specified then it will be used when calculating the clock divisor. The previous CPU clock detection method is left for backward compatibility if no clock is specified.
--- .../devicetree/bindings/net/xilinx_axienet.txt | 6 +++ drivers/net/ethernet/xilinx/xilinx_axienet.h | 5 +- drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 23 +++++++++- drivers/net/ethernet/xilinx/xilinx_axienet_mdio.c | 53 ++++++++++++---------- 4 files changed, 59 insertions(+), 28 deletions(-)
Documentation/devicetree/bindings/net/xilinx_axienet.txt +6 -0
@@ -31,6 +31,11 @@ Optional properties: 1 to enable partial TX checksum offload, 2 to enable full TX checksum offload - xlnx,rxcsum : Same values as xlnx,txcsum but for RX checksum offload +- clocks : AXI bus clock for the device. Refer to common clock bindings. + Used to calculate MDIO clock divisor. If not specified, it is + auto-detected from the CPU clock (but only on platforms where + this is possible). New device trees should specify this - the + auto detection is only for backward compatibility. Example: axi_ethernet_eth: ethernet@40c00000 {
@@ -38,6 +43,7 @@ Example: device_type = "network"; interrupt-parent = <µblaze_0_axi_intc>; interrupts = <2 0>; + clocks = <&axi_clk>; phy-mode = "mii"; reg = <0x40c00000 0x40000>; xlnx,rxcsum = <0x2>;
drivers/net/ethernet/xilinx/xilinx_axienet.h +4 -1
@@ -418,6 +418,9 @@ struct axienet_local {/* Connection to PHY device */ struct device_node *phy_node; +/* Clock for AXI bus */ +struct clk *clk; +/* MDIO bus data */ struct mii_bus *mii_bus;/* MII bus reference */
@@ -502,7 +505,7 @@ static inline void axienet_iow(struct axienet_local *lp, off_t offset, }/* Function prototypes visible in xilinx_axienet_mdio.c for other files */ -int axienet_mdio_setup (struct axienet_local *lp,struct device_node *np); +int axienet_mdio_setup (struct axienet_local *lp);int axienet_mdio_wait_until_ready (struct axienet_local *lp);void axienet_mdio_teardown (struct axienet_local *lp);
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +21 -2
@@ -21,6 +21,7 @@* - Add support for extended VLAN support. */ +#include <linux/clk.h> #include <linux/delay.h> #include <linux/etherdevice.h> #include <linux/module.h>
@@ -1611,9 +1612,24 @@ static int axienet_probe(struct platform_device *pdev) lp->phy_node =of_parse_phandle (pdev->dev.of_node,"phy-handle" ,0 );if (lp->phy_node) { - ret =axienet_mdio_setup (lp, pdev->dev.of_node); + lp->clk =devm_clk_get (&pdev->dev,NULL ); +if (IS_ERR (lp->clk)) { +dev_warn (&pdev->dev,"Failed to get clock: %ld\n" , +PTR_ERR (lp->clk)); + lp->clk =NULL ; + }else { + ret =clk_prepare_enable (lp->clk); +if (ret) { +dev_err (&pdev->dev,"Unable to enable clock: %d\n" , + ret); + goto free_netdev; + } + } + + ret =axienet_mdio_setup (lp);if (ret) -dev_warn (&pdev->dev,"error registering MDIO bus\n" ); +dev_warn (&pdev->dev, +"error registering MDIO bus: %d\n" , ret); } ret =register_netdev (lp->ndev);
@@ -1638,6 +1654,9 @@ static int axienet_remove(struct platform_device *pdev)axienet_mdio_teardown (lp);unregister_netdev (ndev); +if (lp->clk) +clk_disable_unprepare (lp->clk); +of_node_put (lp->phy_node); lp->phy_node =NULL ;
drivers/net/ethernet/xilinx/xilinx_axienet_mdio.c +28 -25
94 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v5 10/20 net: axienet: Add DMA registers to ethtool register dump
In reply to Robert HancockThese registers are important for troubleshooting the state of the DMA cores.
--- drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +9 -1
@@ -50,7 +50,7 @@#define DRIVER_DESCRIPTION "Xilinx Axi Ethernet driver"#define DRIVER_VERSION "1.00a" -#define AXIENET_REGS_N 32 +#define AXIENET_REGS_N 40/* Match table for of_platform binding */ static const struct of_device_id axienet_of_match[] = {
@@ -1179,6 +1179,14 @@ static void axienet_ethtools_get_regs(struct net_device *ndev, data[29 ] =axienet_ior (lp,XAE_FMI_OFFSET ); data[30 ] =axienet_ior (lp,XAE_AF0_OFFSET ); data[31 ] =axienet_ior (lp,XAE_AF1_OFFSET ); + data[32 ] =axienet_dma_in32 (lp,XAXIDMA_TX_CR_OFFSET ); + data[33 ] =axienet_dma_in32 (lp,XAXIDMA_TX_SR_OFFSET ); + data[34 ] =axienet_dma_in32 (lp,XAXIDMA_TX_CDESC_OFFSET ); + data[35 ] =axienet_dma_in32 (lp,XAXIDMA_TX_TDESC_OFFSET ); + data[36 ] =axienet_dma_in32 (lp,XAXIDMA_RX_CR_OFFSET ); + data[37 ] =axienet_dma_in32 (lp,XAXIDMA_RX_SR_OFFSET ); + data[38 ] =axienet_dma_in32 (lp,XAXIDMA_RX_CDESC_OFFSET ); + data[39 ] =axienet_dma_in32 (lp,XAXIDMA_RX_TDESC_OFFSET ); } static void axienet_ethtools_get_ringparam(struct net_device *ndev,
Signature · 1 line
1.8.3.1
David Miller
maintainerFrom: Robert Hancock <[email protected]>
Date: Thu, 6 Jun 2019 16:28:04 -0600
Quoted 7 lines
This is a series of enhancements and bug fixes in order to get the mainline version of this driver into a more generally usable state, including on x86 or ARM platforms. It also converts the driver to use the phylink API in order to provide support for SFP modules.
Changes since v4:
-Use reverse christmas tree variable order
Series applied, thanks.