net: ethernet: fs_enet: Cleanup and phylink conversion
Subsystems (3)
v2 cover net: ethernet: fs_enet: Cleanup and phylink conversion
Hi everyone,
This is V2 of the fs_enet cleanup and phylink conversion series. The main difference from V1 is the introduction of patch 6, that uses devm_get_clk_enabled to manage the register clock, a cleanup of the probe error sequence, and the removal of the netif_running checks.
I also gathered Christophe's reviews and Acks (except on patch 6 that is new).
This series is made of some cosmetic and cleanup patches to FS enet, the last patch converts it to phylink for the PHY handling.
Link to V1: https://lore.kernel.org/netdev/[email protected]/
Thanks,
Maxime
Maxime Chevallier (7):
net: ethernet: fs_enet: convert to SPDX
net: ethernet: fs_enet: cosmetic cleanups
net: ethernet: fs_enet: drop the .adjust_link custom fs_ops
net: ethernet: fs_enet: drop unused phy_info and mii_if_info
net: ethernet: fs_enet: fcc: use macros for speed and duplex values
net: ethernet: fs_enet: simplify clock handling with devm accessors
net: ethernet: fs_enet: phylink conversion
.../net/ethernet/freescale/fs_enet/Kconfig | 2 +- .../ethernet/freescale/fs_enet/fs_enet-main.c | 434 ++++++++---------- .../net/ethernet/freescale/fs_enet/fs_enet.h | 26 +- .../net/ethernet/freescale/fs_enet/mac-fcc.c | 16 +- .../net/ethernet/freescale/fs_enet/mac-fec.c | 14 +- .../net/ethernet/freescale/fs_enet/mac-scc.c | 10 +- .../ethernet/freescale/fs_enet/mii-bitbang.c | 5 +- .../net/ethernet/freescale/fs_enet/mii-fec.c | 5 +- 8 files changed, 210 insertions(+), 302 deletions(-)
Signature · 1 line
2.45.2
PATCH v2 1/7 net: ethernet: fs_enet: convert to SPDX
The ENET driver has SPDX tags in the header files, but they were missing in the C files. Change the licence information to SPDX format.
--- drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c | 5 +---- drivers/net/ethernet/freescale/fs_enet/mac-fcc.c | 5 +---- drivers/net/ethernet/freescale/fs_enet/mac-fec.c | 5 +---- drivers/net/ethernet/freescale/fs_enet/mac-scc.c | 5 +---- drivers/net/ethernet/freescale/fs_enet/mii-bitbang.c | 5 +---- drivers/net/ethernet/freescale/fs_enet/mii-fec.c | 5 +---- 6 files changed, 6 insertions(+), 24 deletions(-)
drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c +1 -4
@@ -1,3 +1,4 @@ +// SPDX-License-Identifier: GPL-2.0-only /* * Combined Ethernet driver for Motorola MPC8xx and MPC82xx. *
@@ -9,10 +10,6 @@* * Heavily based on original FEC driver by Dan Malek <[email protected]> * and modifications by Joakim Tjernlund <[email protected]> -* -* This file is licensed under the terms of the GNU General Public License -* version 2. This program is licensed "as is" without any warranty of any -* kind, whether express or implied. */ #include <linux/module.h>
drivers/net/ethernet/freescale/fs_enet/mac-fcc.c +1 -4
@@ -1,3 +1,4 @@ +// SPDX-License-Identifier: GPL-2.0-only /* * FCC driver for Motorola MPC82xx (PQ2). *
@@ -6,10 +7,6 @@* * 2005 (c) MontaVista Software, Inc. * Vitaly Bordug <[email protected]> -* -* This file is licensed under the terms of the GNU General Public License -* version 2. This program is licensed "as is" without any warranty of any -* kind, whether express or implied. */ #include <linux/module.h>
drivers/net/ethernet/freescale/fs_enet/mac-fec.c +1 -4
@@ -1,3 +1,4 @@ +// SPDX-License-Identifier: GPL-2.0-only /* * Freescale Ethernet controllers *
@@ -6,10 +7,6 @@* * 2005 (c) MontaVista Software, Inc. * Vitaly Bordug <[email protected]> -* -* This file is licensed under the terms of the GNU General Public License -* version 2. This program is licensed "as is" without any warranty of any -* kind, whether express or implied. */ #include <linux/module.h>
drivers/net/ethernet/freescale/fs_enet/mac-scc.c +1 -4
@@ -1,3 +1,4 @@ +// SPDX-License-Identifier: GPL-2.0-only /* * Ethernet on Serial Communications Controller (SCC) driver for Motorola MPC8xx and MPC82xx. *
@@ -6,10 +7,6 @@* * 2005 (c) MontaVista Software, Inc. * Vitaly Bordug <[email protected]> -* -* This file is licensed under the terms of the GNU General Public License -* version 2. This program is licensed "as is" without any warranty of any -* kind, whether express or implied. */ #include <linux/module.h>
drivers/net/ethernet/freescale/fs_enet/mii-bitbang.c +1 -4
@@ -1,3 +1,4 @@ +// SPDX-License-Identifier: GPL-2.0-only /* * Combined Ethernet driver for Motorola MPC8xx and MPC82xx. *
@@ -6,10 +7,6 @@* * 2005 (c) MontaVista Software, Inc. * Vitaly Bordug <[email protected]> -* -* This file is licensed under the terms of the GNU General Public License -* version 2. This program is licensed "as is" without any warranty of any -* kind, whether express or implied. */ #include <linux/module.h>
drivers/net/ethernet/freescale/fs_enet/mii-fec.c +1 -4
@@ -1,3 +1,4 @@ +// SPDX-License-Identifier: GPL-2.0-only /* * Combined Ethernet driver for Motorola MPC8xx and MPC82xx. *
@@ -6,10 +7,6 @@* * 2005 (c) MontaVista Software, Inc. * Vitaly Bordug <[email protected]> -* -* This file is licensed under the terms of the GNU General Public License -* version 2. This program is licensed "as is" without any warranty of any -* kind, whether express or implied. */ #include <linux/module.h>
Signature · 1 line
2.45.2
Re: [PATCH net-next v2 1/7] net: ethernet: fs_enet: convert to SPDX
Quoted 6 lines · Maxime Chevallier
The ENET driver has SPDX tags in the header files, but they were missing in the C files. Change the licence information to SPDX format.
Acked-by Christophe Leroy <[email protected]>Reviewed-by Christophe Leroy <[email protected]>Signed-off-by Maxime Chevallier <[email protected]>
Andrew
PATCH v2 2/7 net: ethernet: fs_enet: cosmetic cleanups
In reply to Maxime ChevallierDue to the age of the driver and the slow recent activity on it, the code has taken some layers of dust. Clean the main driver file up so that it passes checkpatch and also conforms with the net coding style.
Changes include :
- Re-ordering of the variable declarations for RCT
- Fixing the comment styles to either one-line comments, or net-style comments
- Adding braces around single-statement 'else' clauses
- Aligning function/macro parameters on the opening parenthesis
- Simplifying checks for NULL pointers
- Splitting cascaded assignments into individual assignments
- Fixing some typos
- Fixing whitespace issues
This is a cosmetic change and doesn't introduce any change in behaviour.
--- .../ethernet/freescale/fs_enet/fs_enet-main.c | 220 +++++++----------- 1 file changed, 89 insertions(+), 131 deletions(-)
drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c +89 -131
@@ -81,15 +81,14 @@ static void skb_align(struct sk_buff *skb, int align)static int fs_enet_napi (struct napi_struct *napi,int budget) { struct fs_enet_private *fep = container_of(napi, struct fs_enet_private, napi); -struct net_device *dev = fep->ndev;const struct fs_platform_info *fpi = fep->fpi; -cbd_t __iomem *bdp; +struct net_device *dev = fep->ndev; +int curidx, dirtyidx, received =0 ; +int do_wake =0 , do_restart =0 ; +int tx_left =TX_RING_SIZE ;struct sk_buff *skb, *skbn; -int received =0 ; +cbd_t __iomem *bdp;u16 pkt_len, sc; -int curidx; -int dirtyidx, do_wake, do_restart; -int tx_left =TX_RING_SIZE ;spin_lock (&fep->tx_lock); bdp = fep->dirty_tx;
@@ -97,7 +96,6 @@ static int fs_enet_napi(struct napi_struct *napi, int budget)/* clear status bits for napi*/ (*fep->ops->napi_clear_event)(dev); - do_wake = do_restart =0 ;while (((sc =CBDR_SC (bdp)) &BD_ENET_TX_READY ) ==0 && tx_left) { dirtyidx = bdp - fep->tx_bd_base;
@@ -106,12 +104,9 @@ static int fs_enet_napi(struct napi_struct *napi, int budget) skb = fep->tx_skbuff[dirtyidx]; -/* -* Check for errors. -*/ +/* Check for errors. */ if (sc & (BD_ENET_TX_HB |BD_ENET_TX_LC |BD_ENET_TX_RL |BD_ENET_TX_UN |BD_ENET_TX_CSL )) { -if (sc &BD_ENET_TX_HB )/* No heartbeat */ dev->stats.tx_heartbeat_errors++;if (sc &BD_ENET_TX_LC )/* Late collision */
@@ -127,16 +122,16 @@ static int fs_enet_napi(struct napi_struct *napi, int budget) dev->stats.tx_errors++; do_restart =1 ; } - }else + }else { dev->stats.tx_packets++; + }if (sc &BD_ENET_TX_READY ) {dev_warn (fep->dev,"HEY! Enet xmit interrupt and TX_READY.\n" ); } -/* -* Deferred means some collisions occurred during transmit, +/* Deferred means some collisions occurred during transmit, * but we eventually sent the packet OK. */ if (sc &BD_ENET_TX_DEF )
@@ -150,25 +145,20 @@ static int fs_enet_napi(struct napi_struct *napi, int budget)dma_unmap_single (fep->dev,CBDR_BUFADDR (bdp),CBDR_DATLEN (bdp),DMA_TO_DEVICE ); -/* -* Free the sk buffer associated with this last transmit. -*/ +/* Free the sk buffer associated with this last transmit. */ if (skb) {dev_kfree_skb (skb); fep->tx_skbuff[dirtyidx] =NULL ; } -/* -* Update pointer to next buffer descriptor to be transmitted. +/* Update pointer to next buffer descriptor to be transmitted. */ if ((sc &BD_ENET_TX_WRAP ) ==0 ) bdp++;else bdp = fep->tx_bd_base; -/* -* Since we have freed up a buffer, the ring is no longer -* full. +/* Since we have freed up a buffer, the ring is no longer full. */ if (++fep->tx_free ==MAX_SKB_FRAGS ) do_wake =1 ;
@@ -185,8 +175,7 @@ static int fs_enet_napi(struct napi_struct *napi, int budget)if (do_wake)netif_wake_queue (dev); -/* -* First, grab all of the stats for the incoming packet. +/* First, grab all of the stats for the incoming packet. * These get messed up if we get called due to a busy condition. */ bdp = fep->cur_rx;
@@ -195,16 +184,13 @@ static int fs_enet_napi(struct napi_struct *napi, int budget) received < budget) { curidx = bdp - fep->rx_bd_base; -/* -* Since we have allocated space to hold a complete frame, +/* Since we have allocated space to hold a complete frame, * the last indicator should be set. */ if ((sc &BD_ENET_RX_LAST ) ==0 )dev_warn (fep->dev,"rcv is not +last\n" ); -/* -* Check for errors. -*/ +/* Check for errors. */ if (sc & (BD_ENET_RX_LG |BD_ENET_RX_SH |BD_ENET_RX_CL |BD_ENET_RX_NO |BD_ENET_RX_CR |BD_ENET_RX_OV )) { dev->stats.rx_errors++;
@@ -225,9 +211,7 @@ static int fs_enet_napi(struct napi_struct *napi, int budget) }else { skb = fep->rx_skbuff[curidx]; -/* -* Process the incoming frame. -*/ +/* Process the incoming frame */ dev->stats.rx_packets++; pkt_len =CBDR_DATLEN (bdp) -4 ;/* remove CRC */ dev->stats.rx_bytes += pkt_len +4 ;
@@ -235,15 +219,15 @@ static int fs_enet_napi(struct napi_struct *napi, int budget)if (pkt_len <= fpi->rx_copybreak) {/* +2 to make IP header L1 cache aligned */ skbn =netdev_alloc_skb (dev, pkt_len +2 ); -if (skbn !=NULL ) { +if (skbn) {skb_reserve (skbn,2 );/* align IP header */ -skb_copy_from_linear_data (skb, - skbn->data, pkt_len); +skb_copy_from_linear_data (skb, skbn->data, + pkt_len);swap (skb, skbn);dma_sync_single_for_cpu (fep->dev, -CBDR_BUFADDR (bdp), -L1_CACHE_ALIGN (pkt_len), -DMA_FROM_DEVICE ); +CBDR_BUFADDR (bdp), +L1_CACHE_ALIGN (pkt_len), +DMA_FROM_DEVICE ); } }else { skbn =netdev_alloc_skb (dev,ENET_RX_FRSIZE );
@@ -253,20 +237,18 @@ static int fs_enet_napi(struct napi_struct *napi, int budget)skb_align (skbn,ENET_RX_ALIGN ); -dma_unmap_single (fep->dev, -CBDR_BUFADDR (bdp), -L1_CACHE_ALIGN (PKT_MAXBUF_SIZE ), -DMA_FROM_DEVICE ); +dma_unmap_single (fep->dev,CBDR_BUFADDR (bdp), +L1_CACHE_ALIGN (PKT_MAXBUF_SIZE ), +DMA_FROM_DEVICE ); - dma =dma_map_single (fep->dev, - skbn->data, -L1_CACHE_ALIGN (PKT_MAXBUF_SIZE ), -DMA_FROM_DEVICE ); + dma =dma_map_single (fep->dev, skbn->data, +L1_CACHE_ALIGN (PKT_MAXBUF_SIZE ), +DMA_FROM_DEVICE );CBDW_BUFADDR (bdp, dma); } } -if (skbn !=NULL ) { +if (skbn) {skb_put (skb, pkt_len);/* Make room */ skb->protocol =eth_type_trans (skb, dev); received++;
@@ -281,9 +263,7 @@ static int fs_enet_napi(struct napi_struct *napi, int budget)CBDW_DATLEN (bdp,0 );CBDW_SC (bdp, (sc & ~BD_ENET_RX_STATS ) |BD_ENET_RX_EMPTY ); -/* -* Update BD pointer to next entry. -*/ +/* Update BD pointer to next entry */ if ((sc &BD_ENET_RX_WRAP ) ==0 ) bdp++;else
@@ -305,19 +285,16 @@ static int fs_enet_napi(struct napi_struct *napi, int budget)return budget; } -/* -* The interrupt handler. +/* The interrupt handler. * This is called from the MPC core interrupt. */ static irqreturn_t fs_enet_interrupt (int irq,void *dev_id) {struct net_device *dev = dev_id; +u32 int_events, int_clr_events;struct fs_enet_private *fep; -u32 int_events; -u32 int_clr_events; -int nr, napi_ok; -int handled; +int nr, napi_ok, handled; fep =netdev_priv (dev);
@@ -339,12 +316,12 @@ fs_enet_interrupt(int irq, void *dev_id) (*fep->ops->napi_disable)(dev); (*fep->ops->clear_int_events)(dev, fep->ev_napi); -/* NOTE: it is possible for FCCs in NAPI mode */ -/* to submit a spurious interrupt while in poll */ +/* NOTE: it is possible for FCCs in NAPI mode +* to submit a spurious interrupt while in poll +*/ if (napi_ok)__napi_schedule (&fep->napi); } - } handled = nr >0 ;
@@ -354,45 +331,40 @@ fs_enet_interrupt(int irq, void *dev_id)void fs_init_bds (struct net_device *dev) {struct fs_enet_private *fep =netdev_priv (dev); -cbd_t __iomem *bdp;struct sk_buff *skb; +cbd_t __iomem *bdp;int i;fs_cleanup_bds (dev); - fep->dirty_tx = fep->cur_tx = fep->tx_bd_base; + fep->dirty_tx = fep->tx_bd_base; + fep->cur_tx = fep->tx_bd_base; fep->tx_free = fep->tx_ring; fep->cur_rx = fep->rx_bd_base; -/* -* Initialize the receive buffer descriptors. -*/ +/* Initialize the receive buffer descriptors */ for (i =0 , bdp = fep->rx_bd_base; i < fep->rx_ring; i++, bdp++) { skb =netdev_alloc_skb (dev,ENET_RX_FRSIZE ); -if (skb ==NULL ) +if (!skb)break ;skb_align (skb,ENET_RX_ALIGN ); fep->rx_skbuff[i] = skb; -CBDW_BUFADDR (bdp, -dma_map_single (fep->dev, skb->data, -L1_CACHE_ALIGN (PKT_MAXBUF_SIZE ), -DMA_FROM_DEVICE )); +CBDW_BUFADDR (bdp,dma_map_single (fep->dev, skb->data, +L1_CACHE_ALIGN (PKT_MAXBUF_SIZE ), +DMA_FROM_DEVICE ));CBDW_DATLEN (bdp,0 );/* zero */ CBDW_SC (bdp,BD_ENET_RX_EMPTY | ((i < fep->rx_ring -1 ) ?0 :BD_SC_WRAP )); } -/* -* if we failed, fillup remainder -*/ + +/* if we failed, fillup remainder */ for (; i < fep->rx_ring; i++, bdp++) { fep->rx_skbuff[i] =NULL ;CBDW_SC (bdp, (i < fep->rx_ring -1 ) ?0 :BD_SC_WRAP ); } -/* -* ...and the same for transmit. -*/ +/* ...and the same for transmit. */ for (i =0 , bdp = fep->tx_bd_base; i < fep->tx_ring; i++, bdp++) { fep->tx_skbuff[i] =NULL ;CBDW_BUFADDR (bdp,0 );
@@ -408,32 +380,30 @@ void fs_cleanup_bds(struct net_device *dev)cbd_t __iomem *bdp;int i; -/* -* Reset SKB transmit buffers. -*/ +/* Reset SKB transmit buffers. */ for (i =0 , bdp = fep->tx_bd_base; i < fep->tx_ring; i++, bdp++) { -if ((skb = fep->tx_skbuff[i]) ==NULL ) + skb = fep->tx_skbuff[i]; +if (!skb)continue ;/* unmap */ dma_unmap_single (fep->dev,CBDR_BUFADDR (bdp), - skb->len,DMA_TO_DEVICE ); + skb->len,DMA_TO_DEVICE ); fep->tx_skbuff[i] =NULL ;dev_kfree_skb (skb); } -/* -* Reset SKB receive buffers -*/ +/* Reset SKB receive buffers */ for (i =0 , bdp = fep->rx_bd_base; i < fep->rx_ring; i++, bdp++) { -if ((skb = fep->rx_skbuff[i]) ==NULL ) + skb = fep->rx_skbuff[i]; +if (!skb)continue ;/* unmap */ dma_unmap_single (fep->dev,CBDR_BUFADDR (bdp), -L1_CACHE_ALIGN (PKT_MAXBUF_SIZE ), -DMA_FROM_DEVICE ); +L1_CACHE_ALIGN (PKT_MAXBUF_SIZE ), +DMA_FROM_DEVICE ); fep->rx_skbuff[i] =NULL ;
@@ -441,12 +411,8 @@ void fs_cleanup_bds(struct net_device *dev) } } -/**********************************************************************************/ -#ifdef CONFIG_FS_ENET_MPC5121_FEC -/* -* MPC5121 FEC requeries 4-byte alignment for TX data buffer! -*/ +/* MPC5121 FEC requires 4-byte alignment for TX data buffer! */ static struct sk_buff *tx_skb_align_workaround (struct net_device *dev,struct sk_buff *skb) {
@@ -478,15 +444,12 @@ static netdev_tx_t fs_enet_start_xmit(struct sk_buff *skb, struct net_device *dev) { struct fs_enet_private *fep = netdev_priv(dev); +int curidx, nr_frags, len;cbd_t __iomem *bdp; -int curidx; -u16 sc; -int nr_frags;skb_frag_t *frag; -int len; +u16 sc; #ifdef CONFIG_FS_ENET_MPC5121_FEC - int is_aligned = 1; - int i; + int i, is_aligned = 1; if (!IS_ALIGNED((unsigned long)skb->data, 4)) { is_aligned = 0;
@@ -504,8 +467,7 @@ fs_enet_start_xmit(struct sk_buff *skb, struct net_device *dev)if (!is_aligned) { skb =tx_skb_align_workaround (dev, skb);if (!skb) { -/* -* We have lost packet due to memory allocation error +/* We have lost packet due to memory allocation error * in tx_skb_align_workaround(). Hopefully original * skb is still valid, so try transmit it later. */
@@ -516,9 +478,7 @@ fs_enet_start_xmit(struct sk_buff *skb, struct net_device *dev)spin_lock (&fep->tx_lock); -/* -* Fill in a Tx ring entry -*/ +/* Fill in a Tx ring entry */ bdp = fep->cur_tx; nr_frags =skb_shinfo (skb)->nr_frags;
@@ -526,8 +486,7 @@ fs_enet_start_xmit(struct sk_buff *skb, struct net_device *dev)netif_stop_queue (dev);spin_unlock (&fep->tx_lock); -/* -* Ooops. All transmit buffers are full. Bail out. +/* Ooops. All transmit buffers are full. Bail out. * This should not happen, since the tx queue should be stopped. */ dev_warn (fep->dev,"tx queue full!.\n" );
@@ -540,12 +499,12 @@ fs_enet_start_xmit(struct sk_buff *skb, struct net_device *dev) dev->stats.tx_bytes += len;if (nr_frags) len -= skb->data_len; + fep->tx_free -= nr_frags +1 ; -/* -* Push the data cache so the CPM does not get stale memory data. +/* Push the data cache so the CPM does not get stale memory data. */ CBDW_BUFADDR (bdp,dma_map_single (fep->dev, - skb->data, len,DMA_TO_DEVICE )); + skb->data, len,DMA_TO_DEVICE ));CBDW_DATLEN (bdp, len); fep->mapped_as_page[curidx] =0 ;
@@ -582,9 +541,11 @@ fs_enet_start_xmit(struct sk_buff *skb, struct net_device *dev)/* note that while FEC does not have this bit * it marks it as available for software use -* yay for hw reuse :) */ +* yay for hw reuse :) +*/ if (skb->len <=60 ) sc |=BD_ENET_TX_PAD ; +CBDC_SC (bdp,BD_ENET_TX_STATS );CBDS_SC (bdp, sc);
@@ -596,6 +557,7 @@ fs_enet_start_xmit(struct sk_buff *skb, struct net_device *dev) bdp++; else bdp = fep->tx_bd_base; + fep->cur_tx = bdp;if (fep->tx_free <MAX_SKB_FRAGS )
@@ -644,9 +606,7 @@ static void fs_timeout(struct net_device *dev, unsigned int txqueue)schedule_work (&fep->timeout_work); } -/*----------------------------------------------------------------------------- -* generic link-change handler - should be sufficient for most cases -*-----------------------------------------------------------------------------*/ +/* generic link-change handler - should be sufficient for most cases */ static void generic_adjust_link (struct net_device *dev) {struct fs_enet_private *fep =netdev_priv (dev);
@@ -683,7 +643,6 @@ static void generic_adjust_link(struct net_device *dev)phy_print_status (phydev); } -static void fs_adjust_link (struct net_device *dev) {struct fs_enet_private *fep =netdev_priv (dev);
@@ -691,7 +650,7 @@ static void fs_adjust_link(struct net_device *dev)spin_lock_irqsave (&fep->lock, flags); -if (fep->ops->adjust_link) +if (fep->ops->adjust_link) fep->ops->adjust_link (dev);else generic_adjust_link (dev);
@@ -728,8 +687,9 @@ static int fs_enet_open(struct net_device *dev)int r;int err; -/* to initialize the fep->cur_rx,... */ -/* not doing this, will cause a crash in fs_enet_napi */ +/* to initialize the fep->cur_rx,... +* not doing this, will cause a crash in fs_enet_napi +*/ fs_init_bds (fep->ndev);napi_enable (&fep->napi);
@@ -780,10 +740,8 @@ static int fs_enet_close(struct net_device *dev)return 0 ; } -/*************************************************************************/ -static void fs_get_drvinfo (struct net_device *dev, -struct ethtool_drvinfo *info) +struct ethtool_drvinfo *info) {strscpy (info->driver,DRV_MODULE_NAME ,sizeof (info->driver)); }
@@ -796,7 +754,7 @@ static int fs_get_regs_len(struct net_device *dev) }static void fs_get_regs (struct net_device *dev,struct ethtool_regs *regs, -void *p) +void *p) {struct fs_enet_private *fep =netdev_priv (dev);unsigned long flags;
@@ -815,12 +773,14 @@ static void fs_get_regs(struct net_device *dev, struct ethtool_regs *regs,static u32 fs_get_msglevel (struct net_device *dev) {struct fs_enet_private *fep =netdev_priv (dev); +return fep->msg_enable; }static void fs_set_msglevel (struct net_device *dev,u32 value) {struct fs_enet_private *fep =netdev_priv (dev); + fep->msg_enable = value; }
@@ -877,8 +837,6 @@ static const struct ethtool_ops fs_ethtool_ops = { .set_tunable = fs_set_tunable, }; -/**************************************************************************************/ -#ifdef CONFIG_FS_ENET_HAS_FEC #define IS_FEC (ops) ((ops) == &fs_fec_ops)#else
@@ -901,15 +859,14 @@ static const struct net_device_ops fs_enet_netdev_ops = {static int fs_enet_probe (struct platform_device *ofdev) { +int err, privsize, len, ret = -ENODEV ; +const char *phy_connection_type; +struct fs_platform_info *fpi; +struct fs_enet_private *fep;const struct fs_ops *ops;struct net_device *ndev; -struct fs_enet_private *fep; -struct fs_platform_info *fpi;const u32 *data;struct clk *clk; -int err; -const char *phy_connection_type; -int privsize, len, ret = -ENODEV ; ops =device_get_match_data (&ofdev->dev);if (!ops)
@@ -945,7 +902,8 @@ static int fs_enet_probe(struct platform_device *ofdev)if (of_device_is_compatible (ofdev->dev.of_node,"fsl,mpc5125-fec" )) { phy_connection_type =of_get_property (ofdev->dev.of_node, -"phy-connection-type" ,NULL ); +"phy-connection-type" , +NULL );if (phy_connection_type && !strcmp ("rmii" , phy_connection_type)) fpi->use_rmii =1 ; }
@@ -964,7 +922,7 @@ static int fs_enet_probe(struct platform_device *ofdev) } privsize =sizeof (*fep) + -sizeof (struct sk_buff **) * +sizeof (struct sk_buff **) * (fpi->rx_ring + fpi->tx_ring) +sizeof (char ) * fpi->tx_ring;
@@ -1111,9 +1069,9 @@ static struct platform_driver fs_enet_driver = {#ifdef CONFIG_NET_POLL_CONTROLLER static void fs_enet_netpoll (struct net_device *dev) { -disable_irq (dev->irq); -fs_enet_interrupt (dev->irq, dev); -enable_irq (dev->irq); +disable_irq (dev->irq); +fs_enet_interrupt (dev->irq, dev); +enable_irq (dev->irq); }#endif
Signature · 1 line
2.45.2
Re: [PATCH net-next v2 2/7] net: ethernet: fs_enet: cosmetic cleanups
Quoted 9 lines
drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c +1
-3@@ -235,15 +219,15 @@ static int fs_enet_napi(struct napi_struct *napi, int budget)if (pkt_len <= fpi->rx_copybreak) {/* +2 to make IP header L1 cache aligned */ skbn =netdev_alloc_skb (dev, pkt_len +2 ); -if (skbn !=NULL ) { +if (skbn) {skb_reserve (skbn,2 );/* align IP header */ -skb_copy_from_linear_data (skb, - skbn->data, pkt_len);
drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c static int fs_enet_napi(struct napi_struct *napi, int budget) · line 230
Quoted 10 lines
drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c +5
-3+skb_copy_from_linear_data (skb, skbn->data, + pkt_len);swap (skb, skbn);dma_sync_single_for_cpu (fep->dev, -CBDR_BUFADDR (bdp), -L1_CACHE_ALIGN (pkt_len), -DMA_FROM_DEVICE ); +CBDR_BUFADDR (bdp), +L1_CACHE_ALIGN (pkt_len), +DMA_FROM_DEVICE );
The indentation level here suggest refactoring into helpers might be nice. But not a prerequisite for merging.
Andrew
PATCH v2 3/7 net: ethernet: fs_enet: drop the .adjust_link custom fs_ops
In reply to Maxime ChevallierThere's no in-tree user for the fs_ops .adjust_link() function, so we can always use the generic one in fe_enet-main.
--- drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c | 7 +------ drivers/net/ethernet/freescale/fs_enet/fs_enet.h | 1 - 2 files changed, 1 insertion(+), 7 deletions(-)
drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c +1 -6
@@ -649,12 +649,7 @@ static void fs_adjust_link(struct net_device *dev)unsigned long flags;spin_lock_irqsave (&fep->lock, flags); - -if (fep->ops->adjust_link) - fep->ops->adjust_link (dev); -else -generic_adjust_link (dev); - +generic_adjust_link (dev);spin_unlock_irqrestore (&fep->lock, flags); }
drivers/net/ethernet/freescale/fs_enet/fs_enet.h +0 -1
@@ -77,7 +77,6 @@ struct fs_ops {void (*free_bd)(struct net_device *dev);void (*cleanup_data)(struct net_device *dev);void (*set_multicast_list)(struct net_device *dev); -void (*adjust_link)(struct net_device *dev);void (*restart)(struct net_device *dev);void (*stop)(struct net_device *dev);void (*napi_clear_event)(struct net_device *dev);
Signature · 1 line
2.45.2
Re: [PATCH net-next v2 3/7] net: ethernet: fs_enet: drop the .adjust_link custom fs_ops
Quoted 4 lines
drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c +0
-0@@ -649,12 +649,7 @@ static void fs_adjust_link(struct net_device *dev)unsigned long flags;
drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c static void fs_adjust_link(struct net_device *dev) · line 653
Quoted 10 lines
drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c +1
-6spin_lock_irqsave (&fep->lock, flags); - -if (fep->ops->adjust_link) - fep->ops->adjust_link (dev); -else -generic_adjust_link (dev); - +generic_adjust_link (dev);spin_unlock_irqrestore (&fep->lock, flags);
Holding a spinlock is pretty unusual. We are in thread context, and the phydev mutex is held. Looking at generic_adjust_link, do any of the fep->foo variables actually need protecting, particularly from changes in interrupts context?
Andrew
Re: [PATCH net-next v2 3/7] net: ethernet: fs_enet: drop the .adjust_link custom fs_ops
Hi Andrew,
Quoted 5 lines · On Fri, 30 Aug 2024 23:06:08 +0200 Andrew Lunn <[email protected]> wrote:
Quoted 5 lines
drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c +0
-0@@ -649,12 +649,7 @@ static void fs_adjust_link(struct net_device *dev)unsigned long flags;
Quoted 14 lines
drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c static void fs_adjust_link(struct net_device *dev) · line 653
Quoted 9 lines
drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c +1
-6spin_lock_irqsave (&fep->lock, flags); - -if (fep->ops->adjust_link) - fep->ops->adjust_link (dev); -else -generic_adjust_link (dev); - +generic_adjust_link (dev);spin_unlock_irqrestore (&fep->lock, flags);Holding a spinlock is pretty unusual. We are in thread context, and the phydev mutex is held. Looking at
generic_adjust_link, do any of thefep->foovariables actually need protecting, particularly from changes in interrupts context?
Yes there are, the interrupt mask/event registers are being accessed from the interrupt handler and the ->restart() hook. I can try to rework this a bit for a cleaner interrupt handling, but I don't have means to test this on all mac flavors (fec/fcc/scc) :(
Thanks for reviewing this,
Maxime
Re: [PATCH net-next v2 3/7] net: ethernet: fs_enet: drop the .adjust_link custom fs_ops
Quoted 25 lines · Maxime Chevallier
Hi Andrew,
Quoted 5 lines · On Fri, 30 Aug 2024 23:06:08 +0200 Andrew Lunn <[email protected]> wrote:
Quoted 5 lines
drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c +0
-0@@ -649,12 +649,7 @@ static void fs_adjust_link(struct net_device *dev)unsigned long flags;Quoted 14 lines
drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c static void fs_adjust_link(struct net_device *dev) · line 653
Quoted 9 lines
drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c +1
-6spin_lock_irqsave (&fep->lock, flags); - -if (fep->ops->adjust_link) - fep->ops->adjust_link (dev); -else -generic_adjust_link (dev); - +generic_adjust_link (dev);spin_unlock_irqrestore (&fep->lock, flags);Holding a spinlock is pretty unusual. We are in thread context, and the phydev mutex is held. Looking at
generic_adjust_link, do any of thefep->foovariables actually need protecting, particularly from changes in interrupts context?
Quoted 4 lines
Yes there are, the interrupt mask/event registers are being accessed from the interrupt handler and the ->restart() hook. I can try to rework this a bit for a cleaner interrupt handling, but I don't have means to test this on all mac flavors (fec/fcc/scc) :(
As far as i can see, none of the fep->old* members are accessed outside of fs_enet-main.c. There values are not important for the restart call. So the spinlock has nothing to do with adjust_link as such, but restart. So maybe narrow down the lock to just the restart call? But it is not a big issues, just unusual.
Andrew
Re: [PATCH net-next v2 3/7] net: ethernet: fs_enet: drop the .adjust_link custom fs_ops
Quoted 31 lines · On Wed, 4 Sep 2024 14:36:58 +0200 Andrew Lunn <[email protected]> wrote:
Quoted 25 lines · Maxime Chevallier
Hi Andrew,
Quoted 5 lines · On Fri, 30 Aug 2024 23:06:08 +0200 Andrew Lunn <[email protected]> wrote:
Quoted 5 lines
drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c +0
-0@@ -649,12 +649,7 @@ static void fs_adjust_link(struct net_device *dev)unsigned long flags;Quoted 14 lines
drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c static void fs_adjust_link(struct net_device *dev) · line 653
Quoted 9 lines
drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c +1
-6spin_lock_irqsave (&fep->lock, flags); - -if (fep->ops->adjust_link) - fep->ops->adjust_link (dev); -else -generic_adjust_link (dev); - +generic_adjust_link (dev);spin_unlock_irqrestore (&fep->lock, flags);Holding a spinlock is pretty unusual. We are in thread context, and the phydev mutex is held. Looking at
generic_adjust_link, do any of thefep->foovariables actually need protecting, particularly from changes in interrupts context?Quoted 4 lines
Yes there are, the interrupt mask/event registers are being accessed from the interrupt handler and the ->restart() hook. I can try to rework this a bit for a cleaner interrupt handling, but I don't have means to test this on all mac flavors (fec/fcc/scc) :(
Quoted 5 lines
As far as i can see, none of the fep->old* members are accessed outside of
fs_enet-main.c. There values are not important for the restart call. So the spinlock has nothing to do withadjust_linkas such, but restart. So maybe narrow down the lock to just the restart call? But it is not a big issues, just unusual.
I agree with you on that, and this is actually what end-up happening in the final phylink conversion patch (only the restart() call gets called wthin the spinlock).
I'll however include a patch that does exactly what you suggest as part of the phylink conversion, both to make the big port-to-phylink patch smaller, but also to better document why we only need to care about the restart() part, if that's ok :)
Thanks,
Maxime
PATCH v2 4/7 net: ethernet: fs_enet: drop unused phy_info and mii_if_info
In reply to Maxime ChevallierThere's no user of the struct phy_info, the 'phy' field and the mii_if_info in the fs_enet driver, probably dating back when phylib wasn't as widely used. Drop these from the driver code.
--- drivers/net/ethernet/freescale/fs_enet/fs_enet.h | 11 ----------- 1 file changed, 11 deletions(-)
drivers/net/ethernet/freescale/fs_enet/fs_enet.h +0 -11
@@ -92,14 +92,6 @@ struct fs_ops {void (*tx_restart)(struct net_device *dev); }; -struct phy_info { -unsigned int id; -const char *name; -void (*startup) (struct net_device * dev); -void (*shutdown) (struct net_device * dev); -void (*ack_int) (struct net_device * dev); -}; -/* The FEC stores dest/src/type, data, and checksum for receive packets. */ #define MAX_MTU 1508/* Allow fullsized pppoe packets over VLAN */
@@ -153,10 +145,7 @@ struct fs_enet_private {cbd_t __iomem *cur_rx;cbd_t __iomem *cur_tx;int tx_free; -const struct phy_info *phy;u32 msg_enable; -struct mii_if_info mii_if; -unsigned int last_mii_status;int interrupt;int oldduplex, oldspeed, oldlink;/* current settings */
Signature · 1 line
2.45.2
Re: [PATCH net-next v2 4/7] net: ethernet: fs_enet: drop unused phy_info and mii_if_info
Quoted 7 lines · Maxime Chevallier
There's no user of the struct
phy_info, the 'phy' field and themii_if_infoin thefs_enetdriver, probably dating back when phylib wasn't as widely used. Drop these from the driver code.Acked-by Christophe Leroy <[email protected]>Reviewed-by Christophe Leroy <[email protected]>Signed-off-by Maxime Chevallier <[email protected]>
Andrew
Re: [PATCH net-next v2 4/7] net: ethernet: fs_enet: drop unused phy_info and mii_if_info
In reply to Maxime ChevallierQuoted 3 lines · Maxime Chevallier
There's no user of the struct
phy_info, the 'phy' field and themii_if_infoin thefs_enetdriver, probably dating back when phylib wasn't as widely used. Drop these from the driver code.
There might be an include of linux/mii.h you can also drop?
Andrew
Re: [PATCH net-next v2 4/7] net: ethernet: fs_enet: drop unused phy_info and mii_if_info
Hi Andrew,
Quoted 6 lines · On Fri, 30 Aug 2024 23:07:56 +0200 Andrew Lunn <[email protected]> wrote:
Quoted 3 lines · Maxime Chevallier
There's no user of the struct
phy_info, the 'phy' field and themii_if_infoin thefs_enetdriver, probably dating back when phylib wasn't as widely used. Drop these from the driver code.There might be an include of
linux/mii.hyou can also drop?
Oh nice catch ! They are indeed no longer useful, I'll add that in V3.
Thanks,
Maxime
PATCH v2 5/7 net: ethernet: fs_enet: fcc: use macros for speed and duplex values
In reply to Maxime ChevallierThe PHY speed and duplex should be manipulated using the SPEED_XXX and DUPLEX_XXX macros available. Use it in the fcc, fec and scc MAC for fs_enet.
--- drivers/net/ethernet/freescale/fs_enet/mac-fcc.c | 4 ++-- drivers/net/ethernet/freescale/fs_enet/mac-fec.c | 2 +- drivers/net/ethernet/freescale/fs_enet/mac-scc.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-)
drivers/net/ethernet/freescale/fs_enet/mac-fcc.c +2 -2
@@ -361,7 +361,7 @@ static void restart(struct net_device *dev)/* adjust to speed (for RMII mode) */ if (fpi->use_rmii) { -if (dev->phydev->speed ==100 ) +if (dev->phydev->speed ==SPEED_100 )C8 (fcccp, fcc_gfemr,0x20 );else S8 (fcccp, fcc_gfemr,0x20 );
@@ -387,7 +387,7 @@ static void restart(struct net_device *dev)S32 (fccp, fcc_fpsmr,FCC_PSMR_RMII );/* adjust to duplex mode */ -if (dev->phydev->duplex) +if (dev->phydev->duplex ==DUPLEX_FULL )S32 (fccp, fcc_fpsmr,FCC_PSMR_FDE |FCC_PSMR_LPB );else C32 (fccp, fcc_fpsmr,FCC_PSMR_FDE |FCC_PSMR_LPB );
drivers/net/ethernet/freescale/fs_enet/mac-fec.c +1 -1
@@ -309,7 +309,7 @@ static void restart(struct net_device *dev)/* * adjust to duplex mode */ -if (dev->phydev->duplex) { +if (dev->phydev->duplex ==DUPLEX_FULL ) {FC (fecp, r_cntrl,FEC_RCNTRL_DRT );FS (fecp, x_cntrl,FEC_TCNTRL_FDEN );/* FD enable */ }else {
drivers/net/ethernet/freescale/fs_enet/mac-scc.c +1 -1
@@ -338,7 +338,7 @@ static void restart(struct net_device *dev)W16 (sccp, scc_psmr,SCC_PSMR_ENCRC |SCC_PSMR_NIB22 );/* Set full duplex mode if needed */ -if (dev->phydev->duplex) +if (dev->phydev->duplex ==DUPLEX_FULL )S16 (sccp, scc_psmr,SCC_PSMR_LPB |SCC_PSMR_FDE );/* Restore multicast and promiscuous settings */
Signature · 1 line
2.45.2
Re: [PATCH net-next v2 5/7] net: ethernet: fs_enet: fcc: use macros for speed and duplex values
Quoted 6 lines · Maxime Chevallier
The PHY speed and duplex should be manipulated using the
SPEED_XXXandDUPLEX_XXXmacros available. Use it in the fcc, fec and scc MAC forfs_enet.Acked-by Christophe Leroy <[email protected]>Reviewed-by Christophe Leroy <[email protected]>Signed-off-by Maxime Chevallier <[email protected]>
Andrew
PATCH v2 6/7 net: ethernet: fs_enet: simplify clock handling with devm accessors
In reply to Maxime Chevallierdevm_clock_get_enabled() can be used to simplify clock handling for the PER register clock.
---
- v2: new patch
.../ethernet/freescale/fs_enet/fs_enet-main.c | 16 ++++------------ drivers/net/ethernet/freescale/fs_enet/fs_enet.h | 2 -- 2 files changed, 4 insertions(+), 14 deletions(-)
drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c +4 -12
@@ -907,14 +907,9 @@ static int fs_enet_probe(struct platform_device *ofdev)* but require enable to succeed when a clock was specified/found, * keep a reference to the clock upon successful acquisition */ - clk =devm_clk_get (&ofdev->dev,"per" ); -if (!IS_ERR (clk)) { - ret =clk_prepare_enable (clk); -if (ret) - goto out_deregister_fixed_link; - - fpi->clk_per = clk; - } + clk =devm_clk_get_enabled (&ofdev->dev,"per" ); +if (IS_ERR (clk)) + goto out_deregister_fixed_link; privsize =sizeof (*fep) + sizeof(struct sk_buff **) *
@@ -924,7 +919,7 @@ static int fs_enet_probe(struct platform_device *ofdev) ndev =alloc_etherdev (privsize);if (!ndev) { ret = -ENOMEM ; - goto out_put; + goto out_deregister_fixed_link; }SET_NETDEV_DEV (ndev, &ofdev->dev);
@@ -986,8 +981,6 @@ static int fs_enet_probe(struct platform_device *ofdev) fep->ops->cleanup_data (ndev); out_free_dev:free_netdev (ndev); -out_put: -clk_disable_unprepare (fpi->clk_per); out_deregister_fixed_link:of_node_put (fpi->phy_node);if (of_phy_is_fixed_link (ofdev->dev.of_node))
@@ -1008,7 +1001,6 @@ static void fs_enet_remove(struct platform_device *ofdev) fep->ops->cleanup_data (ndev);dev_set_drvdata (fep->dev,NULL );of_node_put (fep->fpi->phy_node); -clk_disable_unprepare (fep->fpi->clk_per);if (of_phy_is_fixed_link (ofdev->dev.of_node))of_phy_deregister_fixed_link (ofdev->dev.of_node);free_netdev (ndev);
drivers/net/ethernet/freescale/fs_enet/fs_enet.h +0 -2
@@ -120,8 +120,6 @@ struct fs_platform_info {int napi_weight;/* NAPI weight */ int use_rmii;/* use RMII mode */ - -struct clk *clk_per;/* 'per' clock for register access */ };struct fs_enet_private {
Signature · 1 line
2.45.2
Re: [PATCH net-next v2 6/7] net: ethernet: fs_enet: simplify clock handling with devm accessors
Quoted 4 lines · Maxime Chevallier
devm_clock_get_enabled()can be used to simplify clock handling for the PER register clock.Signed-off-by Maxime Chevallier <[email protected]>
Andrew
PATCH v2 7/7 net: ethernet: fs_enet: phylink conversion
In reply to Maxime Chevallierfs_enet is a quite old but still used Ethernet driver found on some NXP devices. It has support for 10/100 Mbps ethernet, with half and full duplex. Some variants of it can use RMII, while other integrations are MII-only.
Add phylink support, thus removing custom fixed-link hanldling.
This also allows removing some internal flags such as the use_rmii flag.
---
V2: - Drop the netif_running check in the ioctl() handler, following Russell's review
- Fix the probe cleanup sequence, thanks to Simon's review
.../net/ethernet/freescale/fs_enet/Kconfig | 2 +- .../ethernet/freescale/fs_enet/fs_enet-main.c | 204 +++++++++--------- .../net/ethernet/freescale/fs_enet/fs_enet.h | 12 +- .../net/ethernet/freescale/fs_enet/mac-fcc.c | 11 +- .../net/ethernet/freescale/fs_enet/mac-fec.c | 9 +- .../net/ethernet/freescale/fs_enet/mac-scc.c | 5 +- 6 files changed, 119 insertions(+), 124 deletions(-)
drivers/net/ethernet/freescale/fs_enet/Kconfig +1 -1
@@ -3,7 +3,7 @@ config FS_ENET tristate "Freescale Ethernet Driver" depends on NET_VENDOR_FREESCALE && (CPM1 || CPM2 || PPC_MPC512x) select MII - select PHYLIB + select PHYLINK config FS_ENET_MPC5121_FEC def_bool y if (FS_ENET && PPC_MPC512x)
drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c +99 -105
353 lines not on this page · raw message
drivers/net/ethernet/freescale/fs_enet/fs_enet.h +5 -7
@@ -8,6 +8,7 @@#include <linux/types.h> #include <linux/list.h> #include <linux/phy.h> +#include <linux/phylink.h> #include <linux/dma-mapping.h> #ifdef CONFIG_CPM1
@@ -77,7 +78,8 @@ struct fs_ops {void (*free_bd)(struct net_device *dev);void (*cleanup_data)(struct net_device *dev);void (*set_multicast_list)(struct net_device *dev); -void (*restart)(struct net_device *dev); +void (*restart)(struct net_device *dev,phy_interface_t interface, +int speed,int duplex);void (*stop)(struct net_device *dev);void (*napi_clear_event)(struct net_device *dev);void (*napi_enable)(struct net_device *dev);
@@ -113,13 +115,9 @@ struct fs_platform_info {u32 dpram_offset; -struct device_node *phy_node; -int rx_ring, tx_ring;/* number of buffers on rx */ int rx_copybreak;/* limit we copy small frames */ int napi_weight;/* NAPI weight */ - -int use_rmii;/* use RMII mode */ };struct fs_enet_private {
@@ -144,10 +142,10 @@ struct fs_enet_private {cbd_t __iomem *cur_tx;int tx_free;u32 msg_enable; +struct phylink *phylink; +struct phylink_config phylink_config;int interrupt; -int oldduplex, oldspeed, oldlink;/* current settings */ -/* event masks */ u32 ev_napi;/* mask of NAPI events */ u32 ev;/* event mask */
drivers/net/ethernet/freescale/fs_enet/mac-fcc.c +6 -5
@@ -236,7 +236,8 @@ static void set_multicast_list(struct net_device *dev)set_promiscuous_mode (dev); } -static void restart (struct net_device *dev) +static void restart (struct net_device *dev,phy_interface_t interface, +int speed,int duplex) {struct fs_enet_private *fep =netdev_priv (dev);const struct fs_platform_info *fpi = fep->fpi;
@@ -360,8 +361,8 @@ static void restart(struct net_device *dev)fs_init_bds (dev);/* adjust to speed (for RMII mode) */ -if (fpi->use_rmii) { -if (dev->phydev->speed ==SPEED_100 ) +if (interface ==PHY_INTERFACE_MODE_RMII ) { +if (speed ==SPEED_100 )C8 (fcccp, fcc_gfemr,0x20 );else S8 (fcccp, fcc_gfemr,0x20 );
@@ -383,11 +384,11 @@ static void restart(struct net_device *dev)W32 (fccp, fcc_fpsmr,FCC_PSMR_ENCRC ); -if (fpi->use_rmii) +if (interface ==PHY_INTERFACE_MODE_RMII )S32 (fccp, fcc_fpsmr,FCC_PSMR_RMII );/* adjust to duplex mode */ -if (dev->phydev->duplex ==DUPLEX_FULL ) +if (duplex ==DUPLEX_FULL )S32 (fccp, fcc_fpsmr,FCC_PSMR_FDE |FCC_PSMR_LPB );else C32 (fccp, fcc_fpsmr,FCC_PSMR_FDE |FCC_PSMR_LPB );
drivers/net/ethernet/freescale/fs_enet/mac-fec.c +5 -4
@@ -221,7 +221,8 @@ static void set_multicast_list(struct net_device *dev)set_promiscuous_mode (dev); } -static void restart (struct net_device *dev) +static void restart (struct net_device *dev,phy_interface_t interface, +int speed,int duplex) {struct fs_enet_private *fep =netdev_priv (dev);struct fec __iomem *fecp = fep->fec.fecp;
@@ -303,13 +304,13 @@ static void restart(struct net_device *dev)* Only set MII/RMII mode - do not touch maximum frame length * configured before. */ -FS (fecp, r_cntrl, fpi->use_rmii ? -FEC_RCNTRL_RMII_MODE :FEC_RCNTRL_MII_MODE ); +FS (fecp, r_cntrl, interface ==PHY_INTERFACE_MODE_RMII ? +FEC_RCNTRL_RMII_MODE :FEC_RCNTRL_MII_MODE );#endif /* * adjust to duplex mode */ -if (dev->phydev->duplex ==DUPLEX_FULL ) { +if (duplex ==DUPLEX_FULL ) {FC (fecp, r_cntrl,FEC_RCNTRL_DRT );FS (fecp, x_cntrl,FEC_TCNTRL_FDEN );/* FD enable */ }else {
drivers/net/ethernet/freescale/fs_enet/mac-scc.c +3 -2
@@ -227,7 +227,8 @@ static void set_multicast_list(struct net_device *dev)* change. This only happens when switching between half and full * duplex. */ -static void restart (struct net_device *dev) +static void restart (struct net_device *dev,phy_interface_t interface, +int speed,int duplex) {struct fs_enet_private *fep =netdev_priv (dev);scc_t __iomem *sccp = fep->scc.sccp;
@@ -338,7 +339,7 @@ static void restart(struct net_device *dev)W16 (sccp, scc_psmr,SCC_PSMR_ENCRC |SCC_PSMR_NIB22 );/* Set full duplex mode if needed */ -if (dev->phydev->duplex ==DUPLEX_FULL ) +if (duplex ==DUPLEX_FULL )S16 (sccp, scc_psmr,SCC_PSMR_LPB |SCC_PSMR_FDE );/* Restore multicast and promiscuous settings */
Signature · 1 line
2.45.2
Jakub Kicinski
maintainerRe: [PATCH net-next v2 7/7] net: ethernet: fs_enet: phylink conversion
drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c static void fs_timeout_work(struct work_struct *work) · line 594
Quoted 12 lines · On Thu, 29 Aug 2024 18:15:30 +0200 Maxime Chevallier wrote:
drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c +1
-7@@ -582,15 +591,12 @@ static void fs_timeout_work(struct work_struct *work) dev->stats.tx_errors++; -spin_lock_irqsave (&fep->lock, flags); - -if (dev->flags &IFF_UP ) { -phy_stop (dev->phydev); - (*fep->ops->stop)(dev); - (*fep->ops->restart)(dev); - } +rtnl_lock ();
so we take rtnl_lock here..
Quoted 11 lines
drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c +4
-1+phylink_stop (fep->phylink); +phylink_start (fep->phylink); +rtnl_unlock (); -phy_start (dev->phydev); +spin_lock_irqsave (&fep->lock, flags); wake = fep->tx_free >=MAX_SKB_FRAGS && !(CBDR_SC (fep->cur_tx) &BD_ENET_TX_READY );spin_unlock_irqrestore (&fep->lock, flags);
drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c static int fs_enet_close(struct net_device *dev) · line 690
Quoted 6 lines
drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c +0
-1@@ -717,19 +686,18 @@ static int fs_enet_close(struct net_device *dev)unsigned long flags;netif_stop_queue (dev); -netif_carrier_off (dev);napi_disable (&fep->napi);cancel_work_sync (&fep->timeout_work);
..and cancel_work_sync() under rtnl_lock here?
IDK if removing the the "dev->flags & IFF_UP" check counts as meaningfully making it worse, but we're going in the wrong direction. The _sync() has to go, and the timeout work needs to check if device has been closed under rtnl_lock ?
Quoted 15 lines
drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c +2
-2-phy_stop (dev->phydev); +phylink_stop (fep->phylink);spin_lock_irqsave (&fep->lock, flags);spin_lock (&fep->tx_lock); (*fep->ops->stop)(dev);spin_unlock (&fep->tx_lock);spin_unlock_irqrestore (&fep->lock, flags); +phylink_disconnect_phy (fep->phylink);/* release any irqs */ -phy_disconnect (dev->phydev);free_irq (fep->interrupt, dev);return 0 ;
Re: [PATCH net-next v2 7/7] net: ethernet: fs_enet: phylink conversion
Hi Jakub,
Quoted 36 lines · On Mon, 2 Sep 2024 18:55:43 -0700 Jakub Kicinski <[email protected]> wrote:
drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c static void fs_timeout_work(struct work_struct *work) · line 594
Quoted 12 lines · On Thu, 29 Aug 2024 18:15:30 +0200 Maxime Chevallier wrote:
drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c +1
-7@@ -582,15 +591,12 @@ static void fs_timeout_work(struct work_struct *work) dev->stats.tx_errors++; -spin_lock_irqsave (&fep->lock, flags); - -if (dev->flags &IFF_UP ) { -phy_stop (dev->phydev); - (*fep->ops->stop)(dev); - (*fep->ops->restart)(dev); - } +rtnl_lock ();so we take
rtnl_lockhere..Quoted 11 lines
drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c +4
-1+phylink_stop (fep->phylink); +phylink_start (fep->phylink); +rtnl_unlock (); -phy_start (dev->phydev); +spin_lock_irqsave (&fep->lock, flags); wake = fep->tx_free >=MAX_SKB_FRAGS && !(CBDR_SC (fep->cur_tx) &BD_ENET_TX_READY );spin_unlock_irqrestore (&fep->lock, flags);drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c static int fs_enet_close(struct net_device *dev) · line 690
Quoted 6 lines
drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c +0
-1@@ -717,19 +686,18 @@ static int fs_enet_close(struct net_device *dev)unsigned long flags;netif_stop_queue (dev); -netif_carrier_off (dev);napi_disable (&fep->napi);cancel_work_sync (&fep->timeout_work);..and
cancel_work_sync()underrtnl_lockhere?
Quoted 4 lines
IDK if removing the the "
dev->flags&IFF_UP" check counts as meaningfully making it worse, but we're going in the wrong direction. The_sync()has to go, and the timeout work needs to check if device has been closed underrtnl_lock?
Arg that's true, I didn't consider that call path at all... Sorry about that, I'll indeed rework that to address this deadlock waiting to happen.
Thanks,
Maxime