Commit 4897313b authored by David S. Miller's avatar David S. Miller

Merge branch 'fs_enet-cleanup'

Maxime Chevallier says:

====================
net: ethernet: fs_enet: Cleanup and phylink conversion

This is V3 of a series that cleans-up fs_enet, with the ultimate goal of
converting it to phylink (patch 8).

The main changes compared to V2 are :
 - Reviewed-by tags from Andrew were gathered
 - Patch 5 now includes the removal of now unused includes, thanks
   Andrew for spotting this
 - Patch 4 is new, it reworks the adjust_link to move the spinlock
   acquisition to a more suitable location. Although this dissapears in
   the actual phylink port, it makes the phylink conversion clearer on
   that point
 - Patch 8 includes fixes in the tx_timeout cancellation, to prevent
   taking rtnl twice when canceling a pending tx_timeout. Thanks Jakub
   for spotting this.

Link to V2: https://lore.kernel.org/netdev/20240829161531.610874-1-maxime.chevallier@bootlin.com/
Link to V1: https://lore.kernel.org/netdev/20240828095103.132625-1-maxime.chevallier@bootlin.com/
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents c259acab 41f5fbff
...@@ -3,7 +3,7 @@ config FS_ENET ...@@ -3,7 +3,7 @@ config FS_ENET
tristate "Freescale Ethernet Driver" tristate "Freescale Ethernet Driver"
depends on NET_VENDOR_FREESCALE && (CPM1 || CPM2 || PPC_MPC512x) depends on NET_VENDOR_FREESCALE && (CPM1 || CPM2 || PPC_MPC512x)
select MII select MII
select PHYLIB select PHYLINK
config FS_ENET_MPC5121_FEC config FS_ENET_MPC5121_FEC
def_bool y if (FS_ENET && PPC_MPC512x) def_bool y if (FS_ENET && PPC_MPC512x)
......
// SPDX-License-Identifier: GPL-2.0-only
/* /*
* Combined Ethernet driver for Motorola MPC8xx and MPC82xx. * Combined Ethernet driver for Motorola MPC8xx and MPC82xx.
* *
...@@ -9,10 +10,6 @@ ...@@ -9,10 +10,6 @@
* *
* Heavily based on original FEC driver by Dan Malek <dan@embeddededge.com> * Heavily based on original FEC driver by Dan Malek <dan@embeddededge.com>
* and modifications by Joakim Tjernlund <joakim.tjernlund@lumentis.se> * and modifications by Joakim Tjernlund <joakim.tjernlund@lumentis.se>
*
* 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> #include <linux/module.h>
...@@ -29,17 +26,18 @@ ...@@ -29,17 +26,18 @@
#include <linux/etherdevice.h> #include <linux/etherdevice.h>
#include <linux/skbuff.h> #include <linux/skbuff.h>
#include <linux/spinlock.h> #include <linux/spinlock.h>
#include <linux/mii.h>
#include <linux/ethtool.h> #include <linux/ethtool.h>
#include <linux/bitops.h> #include <linux/bitops.h>
#include <linux/fs.h> #include <linux/fs.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/phy.h> #include <linux/phy.h>
#include <linux/phylink.h>
#include <linux/property.h> #include <linux/property.h>
#include <linux/of.h> #include <linux/of.h>
#include <linux/of_mdio.h> #include <linux/of_mdio.h>
#include <linux/of_net.h> #include <linux/of_net.h>
#include <linux/pgtable.h> #include <linux/pgtable.h>
#include <linux/rtnetlink.h>
#include <linux/vmalloc.h> #include <linux/vmalloc.h>
#include <asm/irq.h> #include <asm/irq.h>
...@@ -72,6 +70,13 @@ static void fs_set_multicast_list(struct net_device *dev) ...@@ -72,6 +70,13 @@ static void fs_set_multicast_list(struct net_device *dev)
(*fep->ops->set_multicast_list)(dev); (*fep->ops->set_multicast_list)(dev);
} }
static int fs_eth_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
{
struct fs_enet_private *fep = netdev_priv(dev);
return phylink_mii_ioctl(fep->phylink, ifr, cmd);
}
static void skb_align(struct sk_buff *skb, int align) static void skb_align(struct sk_buff *skb, int align)
{ {
int off = ((unsigned long)skb->data) & (align - 1); int off = ((unsigned long)skb->data) & (align - 1);
...@@ -84,15 +89,14 @@ static void skb_align(struct sk_buff *skb, int align) ...@@ -84,15 +89,14 @@ static void skb_align(struct sk_buff *skb, int align)
static int fs_enet_napi(struct napi_struct *napi, int budget) 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 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; 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; struct sk_buff *skb, *skbn;
int received = 0; cbd_t __iomem *bdp;
u16 pkt_len, sc; u16 pkt_len, sc;
int curidx;
int dirtyidx, do_wake, do_restart;
int tx_left = TX_RING_SIZE;
spin_lock(&fep->tx_lock); spin_lock(&fep->tx_lock);
bdp = fep->dirty_tx; bdp = fep->dirty_tx;
...@@ -100,7 +104,6 @@ static int fs_enet_napi(struct napi_struct *napi, int budget) ...@@ -100,7 +104,6 @@ static int fs_enet_napi(struct napi_struct *napi, int budget)
/* clear status bits for napi*/ /* clear status bits for napi*/
(*fep->ops->napi_clear_event)(dev); (*fep->ops->napi_clear_event)(dev);
do_wake = do_restart = 0;
while (((sc = CBDR_SC(bdp)) & BD_ENET_TX_READY) == 0 && tx_left) { while (((sc = CBDR_SC(bdp)) & BD_ENET_TX_READY) == 0 && tx_left) {
dirtyidx = bdp - fep->tx_bd_base; dirtyidx = bdp - fep->tx_bd_base;
...@@ -109,12 +112,9 @@ static int fs_enet_napi(struct napi_struct *napi, int budget) ...@@ -109,12 +112,9 @@ static int fs_enet_napi(struct napi_struct *napi, int budget)
skb = fep->tx_skbuff[dirtyidx]; skb = fep->tx_skbuff[dirtyidx];
/* /* Check for errors. */
* Check for errors.
*/
if (sc & (BD_ENET_TX_HB | BD_ENET_TX_LC | if (sc & (BD_ENET_TX_HB | BD_ENET_TX_LC |
BD_ENET_TX_RL | BD_ENET_TX_UN | BD_ENET_TX_CSL)) { BD_ENET_TX_RL | BD_ENET_TX_UN | BD_ENET_TX_CSL)) {
if (sc & BD_ENET_TX_HB) /* No heartbeat */ if (sc & BD_ENET_TX_HB) /* No heartbeat */
dev->stats.tx_heartbeat_errors++; dev->stats.tx_heartbeat_errors++;
if (sc & BD_ENET_TX_LC) /* Late collision */ if (sc & BD_ENET_TX_LC) /* Late collision */
...@@ -130,16 +130,16 @@ static int fs_enet_napi(struct napi_struct *napi, int budget) ...@@ -130,16 +130,16 @@ static int fs_enet_napi(struct napi_struct *napi, int budget)
dev->stats.tx_errors++; dev->stats.tx_errors++;
do_restart = 1; do_restart = 1;
} }
} else } else {
dev->stats.tx_packets++; dev->stats.tx_packets++;
}
if (sc & BD_ENET_TX_READY) { if (sc & BD_ENET_TX_READY) {
dev_warn(fep->dev, dev_warn(fep->dev,
"HEY! Enet xmit interrupt and TX_READY.\n"); "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. * but we eventually sent the packet OK.
*/ */
if (sc & BD_ENET_TX_DEF) if (sc & BD_ENET_TX_DEF)
...@@ -153,25 +153,20 @@ static int fs_enet_napi(struct napi_struct *napi, int budget) ...@@ -153,25 +153,20 @@ static int fs_enet_napi(struct napi_struct *napi, int budget)
dma_unmap_single(fep->dev, CBDR_BUFADDR(bdp), dma_unmap_single(fep->dev, CBDR_BUFADDR(bdp),
CBDR_DATLEN(bdp), DMA_TO_DEVICE); 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) { if (skb) {
dev_kfree_skb(skb); dev_kfree_skb(skb);
fep->tx_skbuff[dirtyidx] = NULL; 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) if ((sc & BD_ENET_TX_WRAP) == 0)
bdp++; bdp++;
else else
bdp = fep->tx_bd_base; 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) if (++fep->tx_free == MAX_SKB_FRAGS)
do_wake = 1; do_wake = 1;
...@@ -188,8 +183,7 @@ static int fs_enet_napi(struct napi_struct *napi, int budget) ...@@ -188,8 +183,7 @@ static int fs_enet_napi(struct napi_struct *napi, int budget)
if (do_wake) if (do_wake)
netif_wake_queue(dev); 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. * These get messed up if we get called due to a busy condition.
*/ */
bdp = fep->cur_rx; bdp = fep->cur_rx;
...@@ -198,16 +192,13 @@ static int fs_enet_napi(struct napi_struct *napi, int budget) ...@@ -198,16 +192,13 @@ static int fs_enet_napi(struct napi_struct *napi, int budget)
received < budget) { received < budget) {
curidx = bdp - fep->rx_bd_base; 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. * the last indicator should be set.
*/ */
if ((sc & BD_ENET_RX_LAST) == 0) if ((sc & BD_ENET_RX_LAST) == 0)
dev_warn(fep->dev, "rcv is not +last\n"); 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 | 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)) { BD_ENET_RX_NO | BD_ENET_RX_CR | BD_ENET_RX_OV)) {
dev->stats.rx_errors++; dev->stats.rx_errors++;
...@@ -228,9 +219,7 @@ static int fs_enet_napi(struct napi_struct *napi, int budget) ...@@ -228,9 +219,7 @@ static int fs_enet_napi(struct napi_struct *napi, int budget)
} else { } else {
skb = fep->rx_skbuff[curidx]; skb = fep->rx_skbuff[curidx];
/* /* Process the incoming frame */
* Process the incoming frame.
*/
dev->stats.rx_packets++; dev->stats.rx_packets++;
pkt_len = CBDR_DATLEN(bdp) - 4; /* remove CRC */ pkt_len = CBDR_DATLEN(bdp) - 4; /* remove CRC */
dev->stats.rx_bytes += pkt_len + 4; dev->stats.rx_bytes += pkt_len + 4;
...@@ -238,15 +227,15 @@ static int fs_enet_napi(struct napi_struct *napi, int budget) ...@@ -238,15 +227,15 @@ static int fs_enet_napi(struct napi_struct *napi, int budget)
if (pkt_len <= fpi->rx_copybreak) { if (pkt_len <= fpi->rx_copybreak) {
/* +2 to make IP header L1 cache aligned */ /* +2 to make IP header L1 cache aligned */
skbn = netdev_alloc_skb(dev, pkt_len + 2); skbn = netdev_alloc_skb(dev, pkt_len + 2);
if (skbn != NULL) { if (skbn) {
skb_reserve(skbn, 2); /* align IP header */ skb_reserve(skbn, 2); /* align IP header */
skb_copy_from_linear_data(skb, skb_copy_from_linear_data(skb, skbn->data,
skbn->data, pkt_len); pkt_len);
swap(skb, skbn); swap(skb, skbn);
dma_sync_single_for_cpu(fep->dev, dma_sync_single_for_cpu(fep->dev,
CBDR_BUFADDR(bdp), CBDR_BUFADDR(bdp),
L1_CACHE_ALIGN(pkt_len), L1_CACHE_ALIGN(pkt_len),
DMA_FROM_DEVICE); DMA_FROM_DEVICE);
} }
} else { } else {
skbn = netdev_alloc_skb(dev, ENET_RX_FRSIZE); skbn = netdev_alloc_skb(dev, ENET_RX_FRSIZE);
...@@ -256,20 +245,18 @@ static int fs_enet_napi(struct napi_struct *napi, int budget) ...@@ -256,20 +245,18 @@ static int fs_enet_napi(struct napi_struct *napi, int budget)
skb_align(skbn, ENET_RX_ALIGN); skb_align(skbn, ENET_RX_ALIGN);
dma_unmap_single(fep->dev, dma_unmap_single(fep->dev, CBDR_BUFADDR(bdp),
CBDR_BUFADDR(bdp), L1_CACHE_ALIGN(PKT_MAXBUF_SIZE),
L1_CACHE_ALIGN(PKT_MAXBUF_SIZE), DMA_FROM_DEVICE);
DMA_FROM_DEVICE);
dma = dma_map_single(fep->dev, dma = dma_map_single(fep->dev, skbn->data,
skbn->data, L1_CACHE_ALIGN(PKT_MAXBUF_SIZE),
L1_CACHE_ALIGN(PKT_MAXBUF_SIZE), DMA_FROM_DEVICE);
DMA_FROM_DEVICE);
CBDW_BUFADDR(bdp, dma); CBDW_BUFADDR(bdp, dma);
} }
} }
if (skbn != NULL) { if (skbn) {
skb_put(skb, pkt_len); /* Make room */ skb_put(skb, pkt_len); /* Make room */
skb->protocol = eth_type_trans(skb, dev); skb->protocol = eth_type_trans(skb, dev);
received++; received++;
...@@ -284,9 +271,7 @@ static int fs_enet_napi(struct napi_struct *napi, int budget) ...@@ -284,9 +271,7 @@ static int fs_enet_napi(struct napi_struct *napi, int budget)
CBDW_DATLEN(bdp, 0); CBDW_DATLEN(bdp, 0);
CBDW_SC(bdp, (sc & ~BD_ENET_RX_STATS) | BD_ENET_RX_EMPTY); 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) if ((sc & BD_ENET_RX_WRAP) == 0)
bdp++; bdp++;
else else
...@@ -308,19 +293,16 @@ static int fs_enet_napi(struct napi_struct *napi, int budget) ...@@ -308,19 +293,16 @@ static int fs_enet_napi(struct napi_struct *napi, int budget)
return budget; return budget;
} }
/* /* The interrupt handler.
* The interrupt handler.
* This is called from the MPC core interrupt. * This is called from the MPC core interrupt.
*/ */
static irqreturn_t static irqreturn_t
fs_enet_interrupt(int irq, void *dev_id) fs_enet_interrupt(int irq, void *dev_id)
{ {
struct net_device *dev = dev_id; struct net_device *dev = dev_id;
u32 int_events, int_clr_events;
struct fs_enet_private *fep; struct fs_enet_private *fep;
u32 int_events; int nr, napi_ok, handled;
u32 int_clr_events;
int nr, napi_ok;
int handled;
fep = netdev_priv(dev); fep = netdev_priv(dev);
...@@ -342,12 +324,12 @@ fs_enet_interrupt(int irq, void *dev_id) ...@@ -342,12 +324,12 @@ fs_enet_interrupt(int irq, void *dev_id)
(*fep->ops->napi_disable)(dev); (*fep->ops->napi_disable)(dev);
(*fep->ops->clear_int_events)(dev, fep->ev_napi); (*fep->ops->clear_int_events)(dev, fep->ev_napi);
/* NOTE: it is possible for FCCs in NAPI mode */ /* NOTE: it is possible for FCCs in NAPI mode
/* to submit a spurious interrupt while in poll */ * to submit a spurious interrupt while in poll
*/
if (napi_ok) if (napi_ok)
__napi_schedule(&fep->napi); __napi_schedule(&fep->napi);
} }
} }
handled = nr > 0; handled = nr > 0;
...@@ -357,45 +339,40 @@ fs_enet_interrupt(int irq, void *dev_id) ...@@ -357,45 +339,40 @@ fs_enet_interrupt(int irq, void *dev_id)
void fs_init_bds(struct net_device *dev) void fs_init_bds(struct net_device *dev)
{ {
struct fs_enet_private *fep = netdev_priv(dev); struct fs_enet_private *fep = netdev_priv(dev);
cbd_t __iomem *bdp;
struct sk_buff *skb; struct sk_buff *skb;
cbd_t __iomem *bdp;
int i; int i;
fs_cleanup_bds(dev); 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->tx_free = fep->tx_ring;
fep->cur_rx = fep->rx_bd_base; 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++) { for (i = 0, bdp = fep->rx_bd_base; i < fep->rx_ring; i++, bdp++) {
skb = netdev_alloc_skb(dev, ENET_RX_FRSIZE); skb = netdev_alloc_skb(dev, ENET_RX_FRSIZE);
if (skb == NULL) if (!skb)
break; break;
skb_align(skb, ENET_RX_ALIGN); skb_align(skb, ENET_RX_ALIGN);
fep->rx_skbuff[i] = skb; fep->rx_skbuff[i] = skb;
CBDW_BUFADDR(bdp, CBDW_BUFADDR(bdp, dma_map_single(fep->dev, skb->data,
dma_map_single(fep->dev, skb->data, L1_CACHE_ALIGN(PKT_MAXBUF_SIZE),
L1_CACHE_ALIGN(PKT_MAXBUF_SIZE), DMA_FROM_DEVICE));
DMA_FROM_DEVICE));
CBDW_DATLEN(bdp, 0); /* zero */ CBDW_DATLEN(bdp, 0); /* zero */
CBDW_SC(bdp, BD_ENET_RX_EMPTY | CBDW_SC(bdp, BD_ENET_RX_EMPTY |
((i < fep->rx_ring - 1) ? 0 : BD_SC_WRAP)); ((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++) { for (; i < fep->rx_ring; i++, bdp++) {
fep->rx_skbuff[i] = NULL; fep->rx_skbuff[i] = NULL;
CBDW_SC(bdp, (i < fep->rx_ring - 1) ? 0 : BD_SC_WRAP); 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++) { for (i = 0, bdp = fep->tx_bd_base; i < fep->tx_ring; i++, bdp++) {
fep->tx_skbuff[i] = NULL; fep->tx_skbuff[i] = NULL;
CBDW_BUFADDR(bdp, 0); CBDW_BUFADDR(bdp, 0);
...@@ -411,32 +388,30 @@ void fs_cleanup_bds(struct net_device *dev) ...@@ -411,32 +388,30 @@ void fs_cleanup_bds(struct net_device *dev)
cbd_t __iomem *bdp; cbd_t __iomem *bdp;
int i; int i;
/* /* Reset SKB transmit buffers. */
* Reset SKB transmit buffers.
*/
for (i = 0, bdp = fep->tx_bd_base; i < fep->tx_ring; i++, bdp++) { 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; continue;
/* unmap */ /* unmap */
dma_unmap_single(fep->dev, CBDR_BUFADDR(bdp), dma_unmap_single(fep->dev, CBDR_BUFADDR(bdp),
skb->len, DMA_TO_DEVICE); skb->len, DMA_TO_DEVICE);
fep->tx_skbuff[i] = NULL; fep->tx_skbuff[i] = NULL;
dev_kfree_skb(skb); 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++) { 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; continue;
/* unmap */ /* unmap */
dma_unmap_single(fep->dev, CBDR_BUFADDR(bdp), dma_unmap_single(fep->dev, CBDR_BUFADDR(bdp),
L1_CACHE_ALIGN(PKT_MAXBUF_SIZE), L1_CACHE_ALIGN(PKT_MAXBUF_SIZE),
DMA_FROM_DEVICE); DMA_FROM_DEVICE);
fep->rx_skbuff[i] = NULL; fep->rx_skbuff[i] = NULL;
...@@ -444,12 +419,8 @@ void fs_cleanup_bds(struct net_device *dev) ...@@ -444,12 +419,8 @@ void fs_cleanup_bds(struct net_device *dev)
} }
} }
/**********************************************************************************/
#ifdef CONFIG_FS_ENET_MPC5121_FEC #ifdef CONFIG_FS_ENET_MPC5121_FEC
/* /* MPC5121 FEC requires 4-byte alignment for TX data buffer! */
* MPC5121 FEC requeries 4-byte alignment for TX data buffer!
*/
static struct sk_buff *tx_skb_align_workaround(struct net_device *dev, static struct sk_buff *tx_skb_align_workaround(struct net_device *dev,
struct sk_buff *skb) struct sk_buff *skb)
{ {
...@@ -481,15 +452,12 @@ static netdev_tx_t ...@@ -481,15 +452,12 @@ static netdev_tx_t
fs_enet_start_xmit(struct sk_buff *skb, struct net_device *dev) fs_enet_start_xmit(struct sk_buff *skb, struct net_device *dev)
{ {
struct fs_enet_private *fep = netdev_priv(dev); struct fs_enet_private *fep = netdev_priv(dev);
int curidx, nr_frags, len;
cbd_t __iomem *bdp; cbd_t __iomem *bdp;
int curidx;
u16 sc;
int nr_frags;
skb_frag_t *frag; skb_frag_t *frag;
int len; u16 sc;
#ifdef CONFIG_FS_ENET_MPC5121_FEC #ifdef CONFIG_FS_ENET_MPC5121_FEC
int is_aligned = 1; int i, is_aligned = 1;
int i;
if (!IS_ALIGNED((unsigned long)skb->data, 4)) { if (!IS_ALIGNED((unsigned long)skb->data, 4)) {
is_aligned = 0; is_aligned = 0;
...@@ -507,8 +475,7 @@ fs_enet_start_xmit(struct sk_buff *skb, struct net_device *dev) ...@@ -507,8 +475,7 @@ fs_enet_start_xmit(struct sk_buff *skb, struct net_device *dev)
if (!is_aligned) { if (!is_aligned) {
skb = tx_skb_align_workaround(dev, skb); skb = tx_skb_align_workaround(dev, skb);
if (!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 * in tx_skb_align_workaround(). Hopefully original
* skb is still valid, so try transmit it later. * skb is still valid, so try transmit it later.
*/ */
...@@ -519,9 +486,7 @@ fs_enet_start_xmit(struct sk_buff *skb, struct net_device *dev) ...@@ -519,9 +486,7 @@ fs_enet_start_xmit(struct sk_buff *skb, struct net_device *dev)
spin_lock(&fep->tx_lock); spin_lock(&fep->tx_lock);
/* /* Fill in a Tx ring entry */
* Fill in a Tx ring entry
*/
bdp = fep->cur_tx; bdp = fep->cur_tx;
nr_frags = skb_shinfo(skb)->nr_frags; nr_frags = skb_shinfo(skb)->nr_frags;
...@@ -529,8 +494,7 @@ fs_enet_start_xmit(struct sk_buff *skb, struct net_device *dev) ...@@ -529,8 +494,7 @@ fs_enet_start_xmit(struct sk_buff *skb, struct net_device *dev)
netif_stop_queue(dev); netif_stop_queue(dev);
spin_unlock(&fep->tx_lock); 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. * This should not happen, since the tx queue should be stopped.
*/ */
dev_warn(fep->dev, "tx queue full!.\n"); dev_warn(fep->dev, "tx queue full!.\n");
...@@ -543,12 +507,12 @@ fs_enet_start_xmit(struct sk_buff *skb, struct net_device *dev) ...@@ -543,12 +507,12 @@ fs_enet_start_xmit(struct sk_buff *skb, struct net_device *dev)
dev->stats.tx_bytes += len; dev->stats.tx_bytes += len;
if (nr_frags) if (nr_frags)
len -= skb->data_len; len -= skb->data_len;
fep->tx_free -= nr_frags + 1; 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, CBDW_BUFADDR(bdp, dma_map_single(fep->dev,
skb->data, len, DMA_TO_DEVICE)); skb->data, len, DMA_TO_DEVICE));
CBDW_DATLEN(bdp, len); CBDW_DATLEN(bdp, len);
fep->mapped_as_page[curidx] = 0; fep->mapped_as_page[curidx] = 0;
...@@ -585,9 +549,11 @@ fs_enet_start_xmit(struct sk_buff *skb, struct net_device *dev) ...@@ -585,9 +549,11 @@ fs_enet_start_xmit(struct sk_buff *skb, struct net_device *dev)
/* note that while FEC does not have this bit /* note that while FEC does not have this bit
* it marks it as available for software use * it marks it as available for software use
* yay for hw reuse :) */ * yay for hw reuse :)
*/
if (skb->len <= 60) if (skb->len <= 60)
sc |= BD_ENET_TX_PAD; sc |= BD_ENET_TX_PAD;
CBDC_SC(bdp, BD_ENET_TX_STATS); CBDC_SC(bdp, BD_ENET_TX_STATS);
CBDS_SC(bdp, sc); CBDS_SC(bdp, sc);
...@@ -599,6 +565,7 @@ fs_enet_start_xmit(struct sk_buff *skb, struct net_device *dev) ...@@ -599,6 +565,7 @@ fs_enet_start_xmit(struct sk_buff *skb, struct net_device *dev)
bdp++; bdp++;
else else
bdp = fep->tx_bd_base; bdp = fep->tx_bd_base;
fep->cur_tx = bdp; fep->cur_tx = bdp;
if (fep->tx_free < MAX_SKB_FRAGS) if (fep->tx_free < MAX_SKB_FRAGS)
...@@ -623,15 +590,21 @@ static void fs_timeout_work(struct work_struct *work) ...@@ -623,15 +590,21 @@ static void fs_timeout_work(struct work_struct *work)
dev->stats.tx_errors++; dev->stats.tx_errors++;
spin_lock_irqsave(&fep->lock, flags); /* In the event a timeout was detected, but the netdev is brought down
* shortly after, it no longer makes sense to try to recover from the
* timeout. netif_running() will return false when called from the
* .ndo_close() callback. Calling the following recovery code while
* called from .ndo_close() could deadlock on rtnl.
*/
if (!netif_running(dev))
return;
if (dev->flags & IFF_UP) { rtnl_lock();
phy_stop(dev->phydev); phylink_stop(fep->phylink);
(*fep->ops->stop)(dev); phylink_start(fep->phylink);
(*fep->ops->restart)(dev); rtnl_unlock();
}
phy_start(dev->phydev); spin_lock_irqsave(&fep->lock, flags);
wake = fep->tx_free >= MAX_SKB_FRAGS && wake = fep->tx_free >= MAX_SKB_FRAGS &&
!(CBDR_SC(fep->cur_tx) & BD_ENET_TX_READY); !(CBDR_SC(fep->cur_tx) & BD_ENET_TX_READY);
spin_unlock_irqrestore(&fep->lock, flags); spin_unlock_irqrestore(&fep->lock, flags);
...@@ -647,82 +620,37 @@ static void fs_timeout(struct net_device *dev, unsigned int txqueue) ...@@ -647,82 +620,37 @@ static void fs_timeout(struct net_device *dev, unsigned int txqueue)
schedule_work(&fep->timeout_work); schedule_work(&fep->timeout_work);
} }
/*----------------------------------------------------------------------------- static void fs_mac_link_up(struct phylink_config *config,
* generic link-change handler - should be sufficient for most cases struct phy_device *phy,
*-----------------------------------------------------------------------------*/ unsigned int mode, phy_interface_t interface,
static void generic_adjust_link(struct net_device *dev) int speed, int duplex,
bool tx_pause, bool rx_pause)
{ {
struct fs_enet_private *fep = netdev_priv(dev); struct net_device *ndev = to_net_dev(config->dev);
struct phy_device *phydev = dev->phydev; struct fs_enet_private *fep = netdev_priv(ndev);
int new_state = 0; unsigned long flags;
if (phydev->link) {
/* adjust to duplex mode */
if (phydev->duplex != fep->oldduplex) {
new_state = 1;
fep->oldduplex = phydev->duplex;
}
if (phydev->speed != fep->oldspeed) {
new_state = 1;
fep->oldspeed = phydev->speed;
}
if (!fep->oldlink) {
new_state = 1;
fep->oldlink = 1;
}
if (new_state)
fep->ops->restart(dev);
} else if (fep->oldlink) {
new_state = 1;
fep->oldlink = 0;
fep->oldspeed = 0;
fep->oldduplex = -1;
}
if (new_state && netif_msg_link(fep)) spin_lock_irqsave(&fep->lock, flags);
phy_print_status(phydev); fep->ops->restart(ndev, interface, speed, duplex);
spin_unlock_irqrestore(&fep->lock, flags);
} }
static void fs_mac_link_down(struct phylink_config *config,
static void fs_adjust_link(struct net_device *dev) unsigned int mode, phy_interface_t interface)
{ {
struct fs_enet_private *fep = netdev_priv(dev); struct net_device *ndev = to_net_dev(config->dev);
struct fs_enet_private *fep = netdev_priv(ndev);
unsigned long flags; unsigned long flags;
spin_lock_irqsave(&fep->lock, flags); spin_lock_irqsave(&fep->lock, flags);
fep->ops->stop(ndev);
if(fep->ops->adjust_link)
fep->ops->adjust_link(dev);
else
generic_adjust_link(dev);
spin_unlock_irqrestore(&fep->lock, flags); spin_unlock_irqrestore(&fep->lock, flags);
} }
static int fs_init_phy(struct net_device *dev) static void fs_mac_config(struct phylink_config *config, unsigned int mode,
const struct phylink_link_state *state)
{ {
struct fs_enet_private *fep = netdev_priv(dev); /* Nothing to do */
struct phy_device *phydev;
phy_interface_t iface;
fep->oldlink = 0;
fep->oldspeed = 0;
fep->oldduplex = -1;
iface = fep->fpi->use_rmii ?
PHY_INTERFACE_MODE_RMII : PHY_INTERFACE_MODE_MII;
phydev = of_phy_connect(dev, fep->fpi->phy_node, &fs_adjust_link, 0,
iface);
if (!phydev) {
dev_err(&dev->dev, "Could not attach to PHY\n");
return -ENODEV;
}
return 0;
} }
static int fs_enet_open(struct net_device *dev) static int fs_enet_open(struct net_device *dev)
...@@ -731,8 +659,9 @@ static int fs_enet_open(struct net_device *dev) ...@@ -731,8 +659,9 @@ static int fs_enet_open(struct net_device *dev)
int r; int r;
int err; int err;
/* to initialize the fep->cur_rx,... */ /* to initialize the fep->cur_rx,...
/* not doing this, will cause a crash in fs_enet_napi */ * not doing this, will cause a crash in fs_enet_napi
*/
fs_init_bds(fep->ndev); fs_init_bds(fep->ndev);
napi_enable(&fep->napi); napi_enable(&fep->napi);
...@@ -746,13 +675,13 @@ static int fs_enet_open(struct net_device *dev) ...@@ -746,13 +675,13 @@ static int fs_enet_open(struct net_device *dev)
return -EINVAL; return -EINVAL;
} }
err = fs_init_phy(dev); err = phylink_of_phy_connect(fep->phylink, fep->dev->of_node, 0);
if (err) { if (err) {
free_irq(fep->interrupt, dev); free_irq(fep->interrupt, dev);
napi_disable(&fep->napi); napi_disable(&fep->napi);
return err; return err;
} }
phy_start(dev->phydev); phylink_start(fep->phylink);
netif_start_queue(dev); netif_start_queue(dev);
...@@ -765,28 +694,25 @@ static int fs_enet_close(struct net_device *dev) ...@@ -765,28 +694,25 @@ static int fs_enet_close(struct net_device *dev)
unsigned long flags; unsigned long flags;
netif_stop_queue(dev); netif_stop_queue(dev);
netif_carrier_off(dev);
napi_disable(&fep->napi); napi_disable(&fep->napi);
cancel_work_sync(&fep->timeout_work); cancel_work(&fep->timeout_work);
phy_stop(dev->phydev); phylink_stop(fep->phylink);
spin_lock_irqsave(&fep->lock, flags); spin_lock_irqsave(&fep->lock, flags);
spin_lock(&fep->tx_lock); spin_lock(&fep->tx_lock);
(*fep->ops->stop)(dev); (*fep->ops->stop)(dev);
spin_unlock(&fep->tx_lock); spin_unlock(&fep->tx_lock);
spin_unlock_irqrestore(&fep->lock, flags); spin_unlock_irqrestore(&fep->lock, flags);
phylink_disconnect_phy(fep->phylink);
/* release any irqs */ /* release any irqs */
phy_disconnect(dev->phydev);
free_irq(fep->interrupt, dev); free_irq(fep->interrupt, dev);
return 0; return 0;
} }
/*************************************************************************/
static void fs_get_drvinfo(struct net_device *dev, 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)); strscpy(info->driver, DRV_MODULE_NAME, sizeof(info->driver));
} }
...@@ -799,7 +725,7 @@ static int fs_get_regs_len(struct net_device *dev) ...@@ -799,7 +725,7 @@ static int fs_get_regs_len(struct net_device *dev)
} }
static void fs_get_regs(struct net_device *dev, struct ethtool_regs *regs, 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); struct fs_enet_private *fep = netdev_priv(dev);
unsigned long flags; unsigned long flags;
...@@ -818,12 +744,14 @@ static void fs_get_regs(struct net_device *dev, struct ethtool_regs *regs, ...@@ -818,12 +744,14 @@ static void fs_get_regs(struct net_device *dev, struct ethtool_regs *regs,
static u32 fs_get_msglevel(struct net_device *dev) static u32 fs_get_msglevel(struct net_device *dev)
{ {
struct fs_enet_private *fep = netdev_priv(dev); struct fs_enet_private *fep = netdev_priv(dev);
return fep->msg_enable; return fep->msg_enable;
} }
static void fs_set_msglevel(struct net_device *dev, u32 value) static void fs_set_msglevel(struct net_device *dev, u32 value)
{ {
struct fs_enet_private *fep = netdev_priv(dev); struct fs_enet_private *fep = netdev_priv(dev);
fep->msg_enable = value; fep->msg_enable = value;
} }
...@@ -865,6 +793,22 @@ static int fs_set_tunable(struct net_device *dev, ...@@ -865,6 +793,22 @@ static int fs_set_tunable(struct net_device *dev,
return ret; return ret;
} }
static int fs_ethtool_set_link_ksettings(struct net_device *dev,
const struct ethtool_link_ksettings *cmd)
{
struct fs_enet_private *fep = netdev_priv(dev);
return phylink_ethtool_ksettings_set(fep->phylink, cmd);
}
static int fs_ethtool_get_link_ksettings(struct net_device *dev,
struct ethtool_link_ksettings *cmd)
{
struct fs_enet_private *fep = netdev_priv(dev);
return phylink_ethtool_ksettings_get(fep->phylink, cmd);
}
static const struct ethtool_ops fs_ethtool_ops = { static const struct ethtool_ops fs_ethtool_ops = {
.get_drvinfo = fs_get_drvinfo, .get_drvinfo = fs_get_drvinfo,
.get_regs_len = fs_get_regs_len, .get_regs_len = fs_get_regs_len,
...@@ -874,14 +818,12 @@ static const struct ethtool_ops fs_ethtool_ops = { ...@@ -874,14 +818,12 @@ static const struct ethtool_ops fs_ethtool_ops = {
.set_msglevel = fs_set_msglevel, .set_msglevel = fs_set_msglevel,
.get_regs = fs_get_regs, .get_regs = fs_get_regs,
.get_ts_info = ethtool_op_get_ts_info, .get_ts_info = ethtool_op_get_ts_info,
.get_link_ksettings = phy_ethtool_get_link_ksettings, .get_link_ksettings = fs_ethtool_get_link_ksettings,
.set_link_ksettings = phy_ethtool_set_link_ksettings, .set_link_ksettings = fs_ethtool_set_link_ksettings,
.get_tunable = fs_get_tunable, .get_tunable = fs_get_tunable,
.set_tunable = fs_set_tunable, .set_tunable = fs_set_tunable,
}; };
/**************************************************************************************/
#ifdef CONFIG_FS_ENET_HAS_FEC #ifdef CONFIG_FS_ENET_HAS_FEC
#define IS_FEC(ops) ((ops) == &fs_fec_ops) #define IS_FEC(ops) ((ops) == &fs_fec_ops)
#else #else
...@@ -894,7 +836,7 @@ static const struct net_device_ops fs_enet_netdev_ops = { ...@@ -894,7 +836,7 @@ static const struct net_device_ops fs_enet_netdev_ops = {
.ndo_start_xmit = fs_enet_start_xmit, .ndo_start_xmit = fs_enet_start_xmit,
.ndo_tx_timeout = fs_timeout, .ndo_tx_timeout = fs_timeout,
.ndo_set_rx_mode = fs_set_multicast_list, .ndo_set_rx_mode = fs_set_multicast_list,
.ndo_eth_ioctl = phy_do_ioctl_running, .ndo_eth_ioctl = fs_eth_ioctl,
.ndo_validate_addr = eth_validate_addr, .ndo_validate_addr = eth_validate_addr,
.ndo_set_mac_address = eth_mac_addr, .ndo_set_mac_address = eth_mac_addr,
#ifdef CONFIG_NET_POLL_CONTROLLER #ifdef CONFIG_NET_POLL_CONTROLLER
...@@ -902,17 +844,23 @@ static const struct net_device_ops fs_enet_netdev_ops = { ...@@ -902,17 +844,23 @@ static const struct net_device_ops fs_enet_netdev_ops = {
#endif #endif
}; };
static const struct phylink_mac_ops fs_enet_phylink_mac_ops = {
.mac_config = fs_mac_config,
.mac_link_down = fs_mac_link_down,
.mac_link_up = fs_mac_link_up,
};
static int fs_enet_probe(struct platform_device *ofdev) static int fs_enet_probe(struct platform_device *ofdev)
{ {
int privsize, len, ret = -ENODEV;
struct fs_platform_info *fpi;
struct fs_enet_private *fep;
phy_interface_t phy_mode;
const struct fs_ops *ops; const struct fs_ops *ops;
struct net_device *ndev; struct net_device *ndev;
struct fs_enet_private *fep; struct phylink *phylink;
struct fs_platform_info *fpi;
const u32 *data; const u32 *data;
struct clk *clk; struct clk *clk;
int err;
const char *phy_connection_type;
int privsize, len, ret = -ENODEV;
ops = device_get_match_data(&ofdev->dev); ops = device_get_match_data(&ofdev->dev);
if (!ops) if (!ops)
...@@ -930,51 +878,36 @@ static int fs_enet_probe(struct platform_device *ofdev) ...@@ -930,51 +878,36 @@ static int fs_enet_probe(struct platform_device *ofdev)
fpi->cp_command = *data; fpi->cp_command = *data;
} }
ret = of_get_phy_mode(ofdev->dev.of_node, &phy_mode);
if (ret) {
/* For compatibility, if the mode isn't specified in DT,
* assume MII
*/
phy_mode = PHY_INTERFACE_MODE_MII;
}
fpi->rx_ring = RX_RING_SIZE; fpi->rx_ring = RX_RING_SIZE;
fpi->tx_ring = TX_RING_SIZE; fpi->tx_ring = TX_RING_SIZE;
fpi->rx_copybreak = 240; fpi->rx_copybreak = 240;
fpi->napi_weight = 17; fpi->napi_weight = 17;
fpi->phy_node = of_parse_phandle(ofdev->dev.of_node, "phy-handle", 0);
if (!fpi->phy_node && of_phy_is_fixed_link(ofdev->dev.of_node)) {
err = of_phy_register_fixed_link(ofdev->dev.of_node);
if (err)
goto out_free_fpi;
/* In the case of a fixed PHY, the DT node associated
* to the PHY is the Ethernet MAC DT node.
*/
fpi->phy_node = of_node_get(ofdev->dev.of_node);
}
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);
if (phy_connection_type && !strcmp("rmii", phy_connection_type))
fpi->use_rmii = 1;
}
/* make clock lookup non-fatal (the driver is shared among platforms), /* make clock lookup non-fatal (the driver is shared among platforms),
* but require enable to succeed when a clock was specified/found, * but require enable to succeed when a clock was specified/found,
* keep a reference to the clock upon successful acquisition * keep a reference to the clock upon successful acquisition
*/ */
clk = devm_clk_get(&ofdev->dev, "per"); clk = devm_clk_get_enabled(&ofdev->dev, "per");
if (!IS_ERR(clk)) { if (IS_ERR(clk))
ret = clk_prepare_enable(clk); goto out_free_fpi;
if (ret)
goto out_deregister_fixed_link;
fpi->clk_per = clk;
}
privsize = sizeof(*fep) + privsize = sizeof(*fep) +
sizeof(struct sk_buff **) * sizeof(struct sk_buff **) *
(fpi->rx_ring + fpi->tx_ring) + (fpi->rx_ring + fpi->tx_ring) +
sizeof(char) * fpi->tx_ring; sizeof(char) * fpi->tx_ring;
ndev = alloc_etherdev(privsize); ndev = alloc_etherdev(privsize);
if (!ndev) { if (!ndev) {
ret = -ENOMEM; ret = -ENOMEM;
goto out_put; goto out_free_fpi;
} }
SET_NETDEV_DEV(ndev, &ofdev->dev); SET_NETDEV_DEV(ndev, &ofdev->dev);
...@@ -986,9 +919,29 @@ static int fs_enet_probe(struct platform_device *ofdev) ...@@ -986,9 +919,29 @@ static int fs_enet_probe(struct platform_device *ofdev)
fep->fpi = fpi; fep->fpi = fpi;
fep->ops = ops; fep->ops = ops;
fep->phylink_config.dev = &ndev->dev;
fep->phylink_config.type = PHYLINK_NETDEV;
fep->phylink_config.mac_capabilities = MAC_10 | MAC_100;
__set_bit(PHY_INTERFACE_MODE_MII,
fep->phylink_config.supported_interfaces);
if (of_device_is_compatible(ofdev->dev.of_node, "fsl,mpc5125-fec"))
__set_bit(PHY_INTERFACE_MODE_RMII,
fep->phylink_config.supported_interfaces);
phylink = phylink_create(&fep->phylink_config, dev_fwnode(fep->dev),
phy_mode, &fs_enet_phylink_mac_ops);
if (IS_ERR(phylink)) {
ret = PTR_ERR(phylink);
goto out_free_dev;
}
fep->phylink = phylink;
ret = fep->ops->setup_data(ndev); ret = fep->ops->setup_data(ndev);
if (ret) if (ret)
goto out_free_dev; goto out_phylink;
fep->rx_skbuff = (struct sk_buff **)&fep[1]; fep->rx_skbuff = (struct sk_buff **)&fep[1];
fep->tx_skbuff = fep->rx_skbuff + fpi->rx_ring; fep->tx_skbuff = fep->rx_skbuff + fpi->rx_ring;
...@@ -1018,8 +971,6 @@ static int fs_enet_probe(struct platform_device *ofdev) ...@@ -1018,8 +971,6 @@ static int fs_enet_probe(struct platform_device *ofdev)
ndev->ethtool_ops = &fs_ethtool_ops; ndev->ethtool_ops = &fs_ethtool_ops;
netif_carrier_off(ndev);
ndev->features |= NETIF_F_SG; ndev->features |= NETIF_F_SG;
ret = register_netdev(ndev); ret = register_netdev(ndev);
...@@ -1034,14 +985,10 @@ static int fs_enet_probe(struct platform_device *ofdev) ...@@ -1034,14 +985,10 @@ static int fs_enet_probe(struct platform_device *ofdev)
fep->ops->free_bd(ndev); fep->ops->free_bd(ndev);
out_cleanup_data: out_cleanup_data:
fep->ops->cleanup_data(ndev); fep->ops->cleanup_data(ndev);
out_phylink:
phylink_destroy(fep->phylink);
out_free_dev: out_free_dev:
free_netdev(ndev); 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))
of_phy_deregister_fixed_link(ofdev->dev.of_node);
out_free_fpi: out_free_fpi:
kfree(fpi); kfree(fpi);
return ret; return ret;
...@@ -1057,10 +1004,7 @@ static void fs_enet_remove(struct platform_device *ofdev) ...@@ -1057,10 +1004,7 @@ static void fs_enet_remove(struct platform_device *ofdev)
fep->ops->free_bd(ndev); fep->ops->free_bd(ndev);
fep->ops->cleanup_data(ndev); fep->ops->cleanup_data(ndev);
dev_set_drvdata(fep->dev, NULL); dev_set_drvdata(fep->dev, NULL);
of_node_put(fep->fpi->phy_node); phylink_destroy(fep->phylink);
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); free_netdev(ndev);
} }
...@@ -1114,9 +1058,9 @@ static struct platform_driver fs_enet_driver = { ...@@ -1114,9 +1058,9 @@ static struct platform_driver fs_enet_driver = {
#ifdef CONFIG_NET_POLL_CONTROLLER #ifdef CONFIG_NET_POLL_CONTROLLER
static void fs_enet_netpoll(struct net_device *dev) static void fs_enet_netpoll(struct net_device *dev)
{ {
disable_irq(dev->irq); disable_irq(dev->irq);
fs_enet_interrupt(dev->irq, dev); fs_enet_interrupt(dev->irq, dev);
enable_irq(dev->irq); enable_irq(dev->irq);
} }
#endif #endif
......
...@@ -3,11 +3,11 @@ ...@@ -3,11 +3,11 @@
#define FS_ENET_H #define FS_ENET_H
#include <linux/clk.h> #include <linux/clk.h>
#include <linux/mii.h>
#include <linux/netdevice.h> #include <linux/netdevice.h>
#include <linux/types.h> #include <linux/types.h>
#include <linux/list.h> #include <linux/list.h>
#include <linux/phy.h> #include <linux/phy.h>
#include <linux/phylink.h>
#include <linux/dma-mapping.h> #include <linux/dma-mapping.h>
#ifdef CONFIG_CPM1 #ifdef CONFIG_CPM1
...@@ -77,8 +77,8 @@ struct fs_ops { ...@@ -77,8 +77,8 @@ struct fs_ops {
void (*free_bd)(struct net_device *dev); void (*free_bd)(struct net_device *dev);
void (*cleanup_data)(struct net_device *dev); void (*cleanup_data)(struct net_device *dev);
void (*set_multicast_list)(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, phy_interface_t interface,
void (*restart)(struct net_device *dev); int speed, int duplex);
void (*stop)(struct net_device *dev); void (*stop)(struct net_device *dev);
void (*napi_clear_event)(struct net_device *dev); void (*napi_clear_event)(struct net_device *dev);
void (*napi_enable)(struct net_device *dev); void (*napi_enable)(struct net_device *dev);
...@@ -93,14 +93,6 @@ struct fs_ops { ...@@ -93,14 +93,6 @@ struct fs_ops {
void (*tx_restart)(struct net_device *dev); 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. /* The FEC stores dest/src/type, data, and checksum for receive packets.
*/ */
#define MAX_MTU 1508 /* Allow fullsized pppoe packets over VLAN */ #define MAX_MTU 1508 /* Allow fullsized pppoe packets over VLAN */
...@@ -122,15 +114,9 @@ struct fs_platform_info { ...@@ -122,15 +114,9 @@ struct fs_platform_info {
u32 dpram_offset; u32 dpram_offset;
struct device_node *phy_node;
int rx_ring, tx_ring; /* number of buffers on rx */ int rx_ring, tx_ring; /* number of buffers on rx */
int rx_copybreak; /* limit we copy small frames */ int rx_copybreak; /* limit we copy small frames */
int napi_weight; /* NAPI weight */ int napi_weight; /* NAPI weight */
int use_rmii; /* use RMII mode */
struct clk *clk_per; /* 'per' clock for register access */
}; };
struct fs_enet_private { struct fs_enet_private {
...@@ -154,14 +140,11 @@ struct fs_enet_private { ...@@ -154,14 +140,11 @@ struct fs_enet_private {
cbd_t __iomem *cur_rx; cbd_t __iomem *cur_rx;
cbd_t __iomem *cur_tx; cbd_t __iomem *cur_tx;
int tx_free; int tx_free;
const struct phy_info *phy;
u32 msg_enable; u32 msg_enable;
struct mii_if_info mii_if; struct phylink *phylink;
unsigned int last_mii_status; struct phylink_config phylink_config;
int interrupt; int interrupt;
int oldduplex, oldspeed, oldlink; /* current settings */
/* event masks */ /* event masks */
u32 ev_napi; /* mask of NAPI events */ u32 ev_napi; /* mask of NAPI events */
u32 ev; /* event mask */ u32 ev; /* event mask */
......
// SPDX-License-Identifier: GPL-2.0-only
/* /*
* FCC driver for Motorola MPC82xx (PQ2). * FCC driver for Motorola MPC82xx (PQ2).
* *
...@@ -6,10 +7,6 @@ ...@@ -6,10 +7,6 @@
* *
* 2005 (c) MontaVista Software, Inc. * 2005 (c) MontaVista Software, Inc.
* Vitaly Bordug <vbordug@ru.mvista.com> * Vitaly Bordug <vbordug@ru.mvista.com>
*
* 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> #include <linux/module.h>
...@@ -25,7 +22,6 @@ ...@@ -25,7 +22,6 @@
#include <linux/etherdevice.h> #include <linux/etherdevice.h>
#include <linux/skbuff.h> #include <linux/skbuff.h>
#include <linux/spinlock.h> #include <linux/spinlock.h>
#include <linux/mii.h>
#include <linux/ethtool.h> #include <linux/ethtool.h>
#include <linux/bitops.h> #include <linux/bitops.h>
#include <linux/fs.h> #include <linux/fs.h>
...@@ -239,7 +235,8 @@ static void set_multicast_list(struct net_device *dev) ...@@ -239,7 +235,8 @@ static void set_multicast_list(struct net_device *dev)
set_promiscuous_mode(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 fs_enet_private *fep = netdev_priv(dev);
const struct fs_platform_info *fpi = fep->fpi; const struct fs_platform_info *fpi = fep->fpi;
...@@ -363,8 +360,8 @@ static void restart(struct net_device *dev) ...@@ -363,8 +360,8 @@ static void restart(struct net_device *dev)
fs_init_bds(dev); fs_init_bds(dev);
/* adjust to speed (for RMII mode) */ /* adjust to speed (for RMII mode) */
if (fpi->use_rmii) { if (interface == PHY_INTERFACE_MODE_RMII) {
if (dev->phydev->speed == 100) if (speed == SPEED_100)
C8(fcccp, fcc_gfemr, 0x20); C8(fcccp, fcc_gfemr, 0x20);
else else
S8(fcccp, fcc_gfemr, 0x20); S8(fcccp, fcc_gfemr, 0x20);
...@@ -386,11 +383,11 @@ static void restart(struct net_device *dev) ...@@ -386,11 +383,11 @@ static void restart(struct net_device *dev)
W32(fccp, fcc_fpsmr, FCC_PSMR_ENCRC); W32(fccp, fcc_fpsmr, FCC_PSMR_ENCRC);
if (fpi->use_rmii) if (interface == PHY_INTERFACE_MODE_RMII)
S32(fccp, fcc_fpsmr, FCC_PSMR_RMII); S32(fccp, fcc_fpsmr, FCC_PSMR_RMII);
/* adjust to duplex mode */ /* adjust to duplex mode */
if (dev->phydev->duplex) if (duplex == DUPLEX_FULL)
S32(fccp, fcc_fpsmr, FCC_PSMR_FDE | FCC_PSMR_LPB); S32(fccp, fcc_fpsmr, FCC_PSMR_FDE | FCC_PSMR_LPB);
else else
C32(fccp, fcc_fpsmr, FCC_PSMR_FDE | FCC_PSMR_LPB); C32(fccp, fcc_fpsmr, FCC_PSMR_FDE | FCC_PSMR_LPB);
......
// SPDX-License-Identifier: GPL-2.0-only
/* /*
* Freescale Ethernet controllers * Freescale Ethernet controllers
* *
...@@ -6,10 +7,6 @@ ...@@ -6,10 +7,6 @@
* *
* 2005 (c) MontaVista Software, Inc. * 2005 (c) MontaVista Software, Inc.
* Vitaly Bordug <vbordug@ru.mvista.com> * Vitaly Bordug <vbordug@ru.mvista.com>
*
* 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> #include <linux/module.h>
...@@ -26,7 +23,6 @@ ...@@ -26,7 +23,6 @@
#include <linux/etherdevice.h> #include <linux/etherdevice.h>
#include <linux/skbuff.h> #include <linux/skbuff.h>
#include <linux/spinlock.h> #include <linux/spinlock.h>
#include <linux/mii.h>
#include <linux/ethtool.h> #include <linux/ethtool.h>
#include <linux/bitops.h> #include <linux/bitops.h>
#include <linux/fs.h> #include <linux/fs.h>
...@@ -224,7 +220,8 @@ static void set_multicast_list(struct net_device *dev) ...@@ -224,7 +220,8 @@ static void set_multicast_list(struct net_device *dev)
set_promiscuous_mode(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 fs_enet_private *fep = netdev_priv(dev);
struct fec __iomem *fecp = fep->fec.fecp; struct fec __iomem *fecp = fep->fec.fecp;
...@@ -306,13 +303,13 @@ static void restart(struct net_device *dev) ...@@ -306,13 +303,13 @@ static void restart(struct net_device *dev)
* Only set MII/RMII mode - do not touch maximum frame length * Only set MII/RMII mode - do not touch maximum frame length
* configured before. * configured before.
*/ */
FS(fecp, r_cntrl, fpi->use_rmii ? FS(fecp, r_cntrl, interface == PHY_INTERFACE_MODE_RMII ?
FEC_RCNTRL_RMII_MODE : FEC_RCNTRL_MII_MODE); FEC_RCNTRL_RMII_MODE : FEC_RCNTRL_MII_MODE);
#endif #endif
/* /*
* adjust to duplex mode * adjust to duplex mode
*/ */
if (dev->phydev->duplex) { if (duplex == DUPLEX_FULL) {
FC(fecp, r_cntrl, FEC_RCNTRL_DRT); FC(fecp, r_cntrl, FEC_RCNTRL_DRT);
FS(fecp, x_cntrl, FEC_TCNTRL_FDEN); /* FD enable */ FS(fecp, x_cntrl, FEC_TCNTRL_FDEN); /* FD enable */
} else { } else {
......
// SPDX-License-Identifier: GPL-2.0-only
/* /*
* Ethernet on Serial Communications Controller (SCC) driver for Motorola MPC8xx and MPC82xx. * Ethernet on Serial Communications Controller (SCC) driver for Motorola MPC8xx and MPC82xx.
* *
...@@ -6,10 +7,6 @@ ...@@ -6,10 +7,6 @@
* *
* 2005 (c) MontaVista Software, Inc. * 2005 (c) MontaVista Software, Inc.
* Vitaly Bordug <vbordug@ru.mvista.com> * Vitaly Bordug <vbordug@ru.mvista.com>
*
* 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> #include <linux/module.h>
...@@ -25,7 +22,6 @@ ...@@ -25,7 +22,6 @@
#include <linux/etherdevice.h> #include <linux/etherdevice.h>
#include <linux/skbuff.h> #include <linux/skbuff.h>
#include <linux/spinlock.h> #include <linux/spinlock.h>
#include <linux/mii.h>
#include <linux/ethtool.h> #include <linux/ethtool.h>
#include <linux/bitops.h> #include <linux/bitops.h>
#include <linux/fs.h> #include <linux/fs.h>
...@@ -230,7 +226,8 @@ static void set_multicast_list(struct net_device *dev) ...@@ -230,7 +226,8 @@ static void set_multicast_list(struct net_device *dev)
* change. This only happens when switching between half and full * change. This only happens when switching between half and full
* duplex. * 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); struct fs_enet_private *fep = netdev_priv(dev);
scc_t __iomem *sccp = fep->scc.sccp; scc_t __iomem *sccp = fep->scc.sccp;
...@@ -341,7 +338,7 @@ static void restart(struct net_device *dev) ...@@ -341,7 +338,7 @@ static void restart(struct net_device *dev)
W16(sccp, scc_psmr, SCC_PSMR_ENCRC | SCC_PSMR_NIB22); W16(sccp, scc_psmr, SCC_PSMR_ENCRC | SCC_PSMR_NIB22);
/* Set full duplex mode if needed */ /* Set full duplex mode if needed */
if (dev->phydev->duplex) if (duplex == DUPLEX_FULL)
S16(sccp, scc_psmr, SCC_PSMR_LPB | SCC_PSMR_FDE); S16(sccp, scc_psmr, SCC_PSMR_LPB | SCC_PSMR_FDE);
/* Restore multicast and promiscuous settings */ /* Restore multicast and promiscuous settings */
......
// SPDX-License-Identifier: GPL-2.0-only
/* /*
* Combined Ethernet driver for Motorola MPC8xx and MPC82xx. * Combined Ethernet driver for Motorola MPC8xx and MPC82xx.
* *
...@@ -6,10 +7,6 @@ ...@@ -6,10 +7,6 @@
* *
* 2005 (c) MontaVista Software, Inc. * 2005 (c) MontaVista Software, Inc.
* Vitaly Bordug <vbordug@ru.mvista.com> * Vitaly Bordug <vbordug@ru.mvista.com>
*
* 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> #include <linux/module.h>
......
// SPDX-License-Identifier: GPL-2.0-only
/* /*
* Combined Ethernet driver for Motorola MPC8xx and MPC82xx. * Combined Ethernet driver for Motorola MPC8xx and MPC82xx.
* *
...@@ -6,10 +7,6 @@ ...@@ -6,10 +7,6 @@
* *
* 2005 (c) MontaVista Software, Inc. * 2005 (c) MontaVista Software, Inc.
* Vitaly Bordug <vbordug@ru.mvista.com> * Vitaly Bordug <vbordug@ru.mvista.com>
*
* 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> #include <linux/module.h>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment