2005-10-29 04:25:58 +08:00
|
|
|
/*
|
|
|
|
* Combined Ethernet driver for Motorola MPC8xx and MPC82xx.
|
|
|
|
*
|
2007-09-19 00:05:35 +08:00
|
|
|
* Copyright (c) 2003 Intracom S.A.
|
2005-10-29 04:25:58 +08:00
|
|
|
* by Pantelis Antoniou <panto@intracom.gr>
|
2007-09-19 00:05:35 +08:00
|
|
|
*
|
|
|
|
* 2005 (c) MontaVista Software, Inc.
|
2005-10-29 04:25:58 +08:00
|
|
|
* Vitaly Bordug <vbordug@ru.mvista.com>
|
|
|
|
*
|
|
|
|
* Heavily based on original FEC driver by Dan Malek <dan@embeddededge.com>
|
|
|
|
* and modifications by Joakim Tjernlund <joakim.tjernlund@lumentis.se>
|
|
|
|
*
|
2007-09-19 00:05:35 +08:00
|
|
|
* 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
|
2005-10-29 04:25:58 +08:00
|
|
|
* kind, whether express or implied.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/ptrace.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/ioport.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/netdevice.h>
|
|
|
|
#include <linux/etherdevice.h>
|
|
|
|
#include <linux/skbuff.h>
|
|
|
|
#include <linux/spinlock.h>
|
|
|
|
#include <linux/mii.h>
|
|
|
|
#include <linux/ethtool.h>
|
|
|
|
#include <linux/bitops.h>
|
|
|
|
#include <linux/fs.h>
|
2005-11-09 21:00:16 +08:00
|
|
|
#include <linux/platform_device.h>
|
2006-08-15 14:00:30 +08:00
|
|
|
#include <linux/phy.h>
|
2009-04-25 20:53:33 +08:00
|
|
|
#include <linux/of.h>
|
|
|
|
#include <linux/of_mdio.h>
|
2008-06-12 21:32:13 +08:00
|
|
|
#include <linux/of_platform.h>
|
2008-07-22 15:12:37 +08:00
|
|
|
#include <linux/of_gpio.h>
|
2005-10-29 04:25:58 +08:00
|
|
|
|
|
|
|
#include <linux/vmalloc.h>
|
|
|
|
#include <asm/pgtable.h>
|
|
|
|
#include <asm/irq.h>
|
|
|
|
#include <asm/uaccess.h>
|
|
|
|
|
|
|
|
#include "fs_enet.h"
|
|
|
|
|
|
|
|
/*************************************************/
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Pantelis Antoniou <panto@intracom.gr>");
|
|
|
|
MODULE_DESCRIPTION("Freescale Ethernet Driver");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_VERSION(DRV_MODULE_VERSION);
|
|
|
|
|
2007-10-02 03:20:58 +08:00
|
|
|
static int fs_enet_debug = -1; /* -1 == use FS_ENET_DEF_MSG_ENABLE as value */
|
2006-03-25 19:07:05 +08:00
|
|
|
module_param(fs_enet_debug, int, 0);
|
2005-10-29 04:25:58 +08:00
|
|
|
MODULE_PARM_DESC(fs_enet_debug,
|
|
|
|
"Freescale bitmapped debugging message enable value");
|
|
|
|
|
2007-09-19 00:05:35 +08:00
|
|
|
#ifdef CONFIG_NET_POLL_CONTROLLER
|
|
|
|
static void fs_enet_netpoll(struct net_device *dev);
|
|
|
|
#endif
|
2005-10-29 04:25:58 +08:00
|
|
|
|
|
|
|
static void fs_set_multicast_list(struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct fs_enet_private *fep = netdev_priv(dev);
|
|
|
|
|
|
|
|
(*fep->ops->set_multicast_list)(dev);
|
|
|
|
}
|
|
|
|
|
2007-10-02 03:20:52 +08:00
|
|
|
static void skb_align(struct sk_buff *skb, int align)
|
|
|
|
{
|
|
|
|
int off = ((unsigned long)skb->data) & (align - 1);
|
|
|
|
|
|
|
|
if (off)
|
|
|
|
skb_reserve(skb, align - off);
|
|
|
|
}
|
|
|
|
|
2005-10-29 04:25:58 +08:00
|
|
|
/* NAPI receive function */
|
[NET]: Make NAPI polling independent of struct net_device objects.
Several devices have multiple independant RX queues per net
device, and some have a single interrupt doorbell for several
queues.
In either case, it's easier to support layouts like that if the
structure representing the poll is independant from the net
device itself.
The signature of the ->poll() call back goes from:
int foo_poll(struct net_device *dev, int *budget)
to
int foo_poll(struct napi_struct *napi, int budget)
The caller is returned the number of RX packets processed (or
the number of "NAPI credits" consumed if you want to get
abstract). The callee no longer messes around bumping
dev->quota, *budget, etc. because that is all handled in the
caller upon return.
The napi_struct is to be embedded in the device driver private data
structures.
Furthermore, it is the driver's responsibility to disable all NAPI
instances in it's ->stop() device close handler. Since the
napi_struct is privatized into the driver's private data structures,
only the driver knows how to get at all of the napi_struct instances
it may have per-device.
With lots of help and suggestions from Rusty Russell, Roland Dreier,
Michael Chan, Jeff Garzik, and Jamal Hadi Salim.
Bug fixes from Thomas Graf, Roland Dreier, Peter Zijlstra,
Joseph Fannin, Scott Wood, Hans J. Koch, and Michael Chan.
[ Ported to current tree and all drivers converted. Integrated
Stephen's follow-on kerneldoc additions, and restored poll_list
handling to the old style to fix mutual exclusion issues. -DaveM ]
Signed-off-by: Stephen Hemminger <shemminger@linux-foundation.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-10-04 07:41:36 +08:00
|
|
|
static int fs_enet_rx_napi(struct napi_struct *napi, int budget)
|
2005-10-29 04:25:58 +08:00
|
|
|
{
|
[NET]: Make NAPI polling independent of struct net_device objects.
Several devices have multiple independant RX queues per net
device, and some have a single interrupt doorbell for several
queues.
In either case, it's easier to support layouts like that if the
structure representing the poll is independant from the net
device itself.
The signature of the ->poll() call back goes from:
int foo_poll(struct net_device *dev, int *budget)
to
int foo_poll(struct napi_struct *napi, int budget)
The caller is returned the number of RX packets processed (or
the number of "NAPI credits" consumed if you want to get
abstract). The callee no longer messes around bumping
dev->quota, *budget, etc. because that is all handled in the
caller upon return.
The napi_struct is to be embedded in the device driver private data
structures.
Furthermore, it is the driver's responsibility to disable all NAPI
instances in it's ->stop() device close handler. Since the
napi_struct is privatized into the driver's private data structures,
only the driver knows how to get at all of the napi_struct instances
it may have per-device.
With lots of help and suggestions from Rusty Russell, Roland Dreier,
Michael Chan, Jeff Garzik, and Jamal Hadi Salim.
Bug fixes from Thomas Graf, Roland Dreier, Peter Zijlstra,
Joseph Fannin, Scott Wood, Hans J. Koch, and Michael Chan.
[ Ported to current tree and all drivers converted. Integrated
Stephen's follow-on kerneldoc additions, and restored poll_list
handling to the old style to fix mutual exclusion issues. -DaveM ]
Signed-off-by: Stephen Hemminger <shemminger@linux-foundation.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-10-04 07:41:36 +08:00
|
|
|
struct fs_enet_private *fep = container_of(napi, struct fs_enet_private, napi);
|
2007-10-18 01:42:43 +08:00
|
|
|
struct net_device *dev = fep->ndev;
|
2005-10-29 04:25:58 +08:00
|
|
|
const struct fs_platform_info *fpi = fep->fpi;
|
2007-10-02 03:20:58 +08:00
|
|
|
cbd_t __iomem *bdp;
|
2005-10-29 04:25:58 +08:00
|
|
|
struct sk_buff *skb, *skbn, *skbt;
|
|
|
|
int received = 0;
|
|
|
|
u16 pkt_len, sc;
|
|
|
|
int curidx;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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;
|
|
|
|
|
|
|
|
/* clear RX status bits for napi*/
|
|
|
|
(*fep->ops->napi_clear_rx_event)(dev);
|
|
|
|
|
|
|
|
while (((sc = CBDR_SC(bdp)) & BD_ENET_RX_EMPTY) == 0) {
|
|
|
|
curidx = bdp - fep->rx_bd_base;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Since we have allocated space to hold a complete frame,
|
|
|
|
* the last indicator should be set.
|
|
|
|
*/
|
|
|
|
if ((sc & BD_ENET_RX_LAST) == 0)
|
2010-02-26 20:00:47 +08:00
|
|
|
dev_warn(fep->dev, "rcv is not +last\n");
|
2005-10-29 04:25:58 +08:00
|
|
|
|
|
|
|
/*
|
2007-09-19 00:05:35 +08:00
|
|
|
* Check for errors.
|
2005-10-29 04:25:58 +08:00
|
|
|
*/
|
|
|
|
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)) {
|
|
|
|
fep->stats.rx_errors++;
|
|
|
|
/* Frame too long or too short. */
|
|
|
|
if (sc & (BD_ENET_RX_LG | BD_ENET_RX_SH))
|
|
|
|
fep->stats.rx_length_errors++;
|
|
|
|
/* Frame alignment */
|
|
|
|
if (sc & (BD_ENET_RX_NO | BD_ENET_RX_CL))
|
|
|
|
fep->stats.rx_frame_errors++;
|
|
|
|
/* CRC Error */
|
|
|
|
if (sc & BD_ENET_RX_CR)
|
|
|
|
fep->stats.rx_crc_errors++;
|
|
|
|
/* FIFO overrun */
|
|
|
|
if (sc & BD_ENET_RX_OV)
|
|
|
|
fep->stats.rx_crc_errors++;
|
|
|
|
|
|
|
|
skb = fep->rx_skbuff[curidx];
|
|
|
|
|
2005-10-30 06:22:40 +08:00
|
|
|
dma_unmap_single(fep->dev, CBDR_BUFADDR(bdp),
|
2005-10-29 04:25:58 +08:00
|
|
|
L1_CACHE_ALIGN(PKT_MAXBUF_SIZE),
|
|
|
|
DMA_FROM_DEVICE);
|
|
|
|
|
|
|
|
skbn = skb;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
skb = fep->rx_skbuff[curidx];
|
|
|
|
|
2005-10-30 06:22:40 +08:00
|
|
|
dma_unmap_single(fep->dev, CBDR_BUFADDR(bdp),
|
2005-10-29 04:25:58 +08:00
|
|
|
L1_CACHE_ALIGN(PKT_MAXBUF_SIZE),
|
|
|
|
DMA_FROM_DEVICE);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Process the incoming frame.
|
|
|
|
*/
|
|
|
|
fep->stats.rx_packets++;
|
|
|
|
pkt_len = CBDR_DATLEN(bdp) - 4; /* remove CRC */
|
|
|
|
fep->stats.rx_bytes += pkt_len + 4;
|
|
|
|
|
|
|
|
if (pkt_len <= fpi->rx_copybreak) {
|
|
|
|
/* +2 to make IP header L1 cache aligned */
|
|
|
|
skbn = dev_alloc_skb(pkt_len + 2);
|
|
|
|
if (skbn != NULL) {
|
|
|
|
skb_reserve(skbn, 2); /* align IP header */
|
2007-03-28 05:55:52 +08:00
|
|
|
skb_copy_from_linear_data(skb,
|
|
|
|
skbn->data, pkt_len);
|
2005-10-29 04:25:58 +08:00
|
|
|
/* swap */
|
|
|
|
skbt = skb;
|
|
|
|
skb = skbn;
|
|
|
|
skbn = skbt;
|
|
|
|
}
|
2007-10-02 03:20:52 +08:00
|
|
|
} else {
|
2005-10-29 04:25:58 +08:00
|
|
|
skbn = dev_alloc_skb(ENET_RX_FRSIZE);
|
|
|
|
|
2007-10-02 03:20:52 +08:00
|
|
|
if (skbn)
|
|
|
|
skb_align(skbn, ENET_RX_ALIGN);
|
|
|
|
}
|
|
|
|
|
2005-10-29 04:25:58 +08:00
|
|
|
if (skbn != NULL) {
|
|
|
|
skb_put(skb, pkt_len); /* Make room */
|
|
|
|
skb->protocol = eth_type_trans(skb, dev);
|
|
|
|
received++;
|
|
|
|
netif_receive_skb(skb);
|
|
|
|
} else {
|
2010-02-26 20:00:47 +08:00
|
|
|
dev_warn(fep->dev,
|
|
|
|
"Memory squeeze, dropping packet.\n");
|
2005-10-29 04:25:58 +08:00
|
|
|
fep->stats.rx_dropped++;
|
|
|
|
skbn = skb;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fep->rx_skbuff[curidx] = skbn;
|
|
|
|
CBDW_BUFADDR(bdp, dma_map_single(fep->dev, skbn->data,
|
|
|
|
L1_CACHE_ALIGN(PKT_MAXBUF_SIZE),
|
|
|
|
DMA_FROM_DEVICE));
|
|
|
|
CBDW_DATLEN(bdp, 0);
|
|
|
|
CBDW_SC(bdp, (sc & ~BD_ENET_RX_STATS) | BD_ENET_RX_EMPTY);
|
|
|
|
|
|
|
|
/*
|
2007-09-19 00:05:35 +08:00
|
|
|
* Update BD pointer to next entry.
|
2005-10-29 04:25:58 +08:00
|
|
|
*/
|
|
|
|
if ((sc & BD_ENET_RX_WRAP) == 0)
|
|
|
|
bdp++;
|
|
|
|
else
|
|
|
|
bdp = fep->rx_bd_base;
|
|
|
|
|
|
|
|
(*fep->ops->rx_bd_done)(dev);
|
[NET]: Make NAPI polling independent of struct net_device objects.
Several devices have multiple independant RX queues per net
device, and some have a single interrupt doorbell for several
queues.
In either case, it's easier to support layouts like that if the
structure representing the poll is independant from the net
device itself.
The signature of the ->poll() call back goes from:
int foo_poll(struct net_device *dev, int *budget)
to
int foo_poll(struct napi_struct *napi, int budget)
The caller is returned the number of RX packets processed (or
the number of "NAPI credits" consumed if you want to get
abstract). The callee no longer messes around bumping
dev->quota, *budget, etc. because that is all handled in the
caller upon return.
The napi_struct is to be embedded in the device driver private data
structures.
Furthermore, it is the driver's responsibility to disable all NAPI
instances in it's ->stop() device close handler. Since the
napi_struct is privatized into the driver's private data structures,
only the driver knows how to get at all of the napi_struct instances
it may have per-device.
With lots of help and suggestions from Rusty Russell, Roland Dreier,
Michael Chan, Jeff Garzik, and Jamal Hadi Salim.
Bug fixes from Thomas Graf, Roland Dreier, Peter Zijlstra,
Joseph Fannin, Scott Wood, Hans J. Koch, and Michael Chan.
[ Ported to current tree and all drivers converted. Integrated
Stephen's follow-on kerneldoc additions, and restored poll_list
handling to the old style to fix mutual exclusion issues. -DaveM ]
Signed-off-by: Stephen Hemminger <shemminger@linux-foundation.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-10-04 07:41:36 +08:00
|
|
|
|
|
|
|
if (received >= budget)
|
|
|
|
break;
|
2005-10-29 04:25:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
fep->cur_rx = bdp;
|
|
|
|
|
2007-10-18 01:42:43 +08:00
|
|
|
if (received < budget) {
|
[NET]: Make NAPI polling independent of struct net_device objects.
Several devices have multiple independant RX queues per net
device, and some have a single interrupt doorbell for several
queues.
In either case, it's easier to support layouts like that if the
structure representing the poll is independant from the net
device itself.
The signature of the ->poll() call back goes from:
int foo_poll(struct net_device *dev, int *budget)
to
int foo_poll(struct napi_struct *napi, int budget)
The caller is returned the number of RX packets processed (or
the number of "NAPI credits" consumed if you want to get
abstract). The callee no longer messes around bumping
dev->quota, *budget, etc. because that is all handled in the
caller upon return.
The napi_struct is to be embedded in the device driver private data
structures.
Furthermore, it is the driver's responsibility to disable all NAPI
instances in it's ->stop() device close handler. Since the
napi_struct is privatized into the driver's private data structures,
only the driver knows how to get at all of the napi_struct instances
it may have per-device.
With lots of help and suggestions from Rusty Russell, Roland Dreier,
Michael Chan, Jeff Garzik, and Jamal Hadi Salim.
Bug fixes from Thomas Graf, Roland Dreier, Peter Zijlstra,
Joseph Fannin, Scott Wood, Hans J. Koch, and Michael Chan.
[ Ported to current tree and all drivers converted. Integrated
Stephen's follow-on kerneldoc additions, and restored poll_list
handling to the old style to fix mutual exclusion issues. -DaveM ]
Signed-off-by: Stephen Hemminger <shemminger@linux-foundation.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-10-04 07:41:36 +08:00
|
|
|
/* done */
|
2009-01-20 08:43:59 +08:00
|
|
|
napi_complete(napi);
|
[NET]: Make NAPI polling independent of struct net_device objects.
Several devices have multiple independant RX queues per net
device, and some have a single interrupt doorbell for several
queues.
In either case, it's easier to support layouts like that if the
structure representing the poll is independant from the net
device itself.
The signature of the ->poll() call back goes from:
int foo_poll(struct net_device *dev, int *budget)
to
int foo_poll(struct napi_struct *napi, int budget)
The caller is returned the number of RX packets processed (or
the number of "NAPI credits" consumed if you want to get
abstract). The callee no longer messes around bumping
dev->quota, *budget, etc. because that is all handled in the
caller upon return.
The napi_struct is to be embedded in the device driver private data
structures.
Furthermore, it is the driver's responsibility to disable all NAPI
instances in it's ->stop() device close handler. Since the
napi_struct is privatized into the driver's private data structures,
only the driver knows how to get at all of the napi_struct instances
it may have per-device.
With lots of help and suggestions from Rusty Russell, Roland Dreier,
Michael Chan, Jeff Garzik, and Jamal Hadi Salim.
Bug fixes from Thomas Graf, Roland Dreier, Peter Zijlstra,
Joseph Fannin, Scott Wood, Hans J. Koch, and Michael Chan.
[ Ported to current tree and all drivers converted. Integrated
Stephen's follow-on kerneldoc additions, and restored poll_list
handling to the old style to fix mutual exclusion issues. -DaveM ]
Signed-off-by: Stephen Hemminger <shemminger@linux-foundation.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-10-04 07:41:36 +08:00
|
|
|
(*fep->ops->napi_enable_rx)(dev);
|
|
|
|
}
|
|
|
|
return received;
|
2005-10-29 04:25:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* non NAPI receive function */
|
|
|
|
static int fs_enet_rx_non_napi(struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct fs_enet_private *fep = netdev_priv(dev);
|
|
|
|
const struct fs_platform_info *fpi = fep->fpi;
|
2007-10-02 03:20:58 +08:00
|
|
|
cbd_t __iomem *bdp;
|
2005-10-29 04:25:58 +08:00
|
|
|
struct sk_buff *skb, *skbn, *skbt;
|
|
|
|
int received = 0;
|
|
|
|
u16 pkt_len, sc;
|
|
|
|
int curidx;
|
|
|
|
/*
|
|
|
|
* 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;
|
|
|
|
|
|
|
|
while (((sc = CBDR_SC(bdp)) & BD_ENET_RX_EMPTY) == 0) {
|
|
|
|
|
|
|
|
curidx = bdp - fep->rx_bd_base;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Since we have allocated space to hold a complete frame,
|
|
|
|
* the last indicator should be set.
|
|
|
|
*/
|
|
|
|
if ((sc & BD_ENET_RX_LAST) == 0)
|
2010-02-26 20:00:47 +08:00
|
|
|
dev_warn(fep->dev, "rcv is not +last\n");
|
2005-10-29 04:25:58 +08:00
|
|
|
|
|
|
|
/*
|
2007-09-19 00:05:35 +08:00
|
|
|
* Check for errors.
|
2005-10-29 04:25:58 +08:00
|
|
|
*/
|
|
|
|
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)) {
|
|
|
|
fep->stats.rx_errors++;
|
|
|
|
/* Frame too long or too short. */
|
|
|
|
if (sc & (BD_ENET_RX_LG | BD_ENET_RX_SH))
|
|
|
|
fep->stats.rx_length_errors++;
|
|
|
|
/* Frame alignment */
|
|
|
|
if (sc & (BD_ENET_RX_NO | BD_ENET_RX_CL))
|
|
|
|
fep->stats.rx_frame_errors++;
|
|
|
|
/* CRC Error */
|
|
|
|
if (sc & BD_ENET_RX_CR)
|
|
|
|
fep->stats.rx_crc_errors++;
|
|
|
|
/* FIFO overrun */
|
|
|
|
if (sc & BD_ENET_RX_OV)
|
|
|
|
fep->stats.rx_crc_errors++;
|
|
|
|
|
|
|
|
skb = fep->rx_skbuff[curidx];
|
|
|
|
|
2005-10-30 06:22:40 +08:00
|
|
|
dma_unmap_single(fep->dev, CBDR_BUFADDR(bdp),
|
2005-10-29 04:25:58 +08:00
|
|
|
L1_CACHE_ALIGN(PKT_MAXBUF_SIZE),
|
|
|
|
DMA_FROM_DEVICE);
|
|
|
|
|
|
|
|
skbn = skb;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
skb = fep->rx_skbuff[curidx];
|
|
|
|
|
2005-10-30 06:22:40 +08:00
|
|
|
dma_unmap_single(fep->dev, CBDR_BUFADDR(bdp),
|
2005-10-29 04:25:58 +08:00
|
|
|
L1_CACHE_ALIGN(PKT_MAXBUF_SIZE),
|
|
|
|
DMA_FROM_DEVICE);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Process the incoming frame.
|
|
|
|
*/
|
|
|
|
fep->stats.rx_packets++;
|
|
|
|
pkt_len = CBDR_DATLEN(bdp) - 4; /* remove CRC */
|
|
|
|
fep->stats.rx_bytes += pkt_len + 4;
|
|
|
|
|
|
|
|
if (pkt_len <= fpi->rx_copybreak) {
|
|
|
|
/* +2 to make IP header L1 cache aligned */
|
|
|
|
skbn = dev_alloc_skb(pkt_len + 2);
|
|
|
|
if (skbn != NULL) {
|
|
|
|
skb_reserve(skbn, 2); /* align IP header */
|
2007-03-28 05:55:52 +08:00
|
|
|
skb_copy_from_linear_data(skb,
|
|
|
|
skbn->data, pkt_len);
|
2005-10-29 04:25:58 +08:00
|
|
|
/* swap */
|
|
|
|
skbt = skb;
|
|
|
|
skb = skbn;
|
|
|
|
skbn = skbt;
|
|
|
|
}
|
2007-10-02 03:20:52 +08:00
|
|
|
} else {
|
2005-10-29 04:25:58 +08:00
|
|
|
skbn = dev_alloc_skb(ENET_RX_FRSIZE);
|
|
|
|
|
2007-10-02 03:20:52 +08:00
|
|
|
if (skbn)
|
|
|
|
skb_align(skbn, ENET_RX_ALIGN);
|
|
|
|
}
|
|
|
|
|
2005-10-29 04:25:58 +08:00
|
|
|
if (skbn != NULL) {
|
|
|
|
skb_put(skb, pkt_len); /* Make room */
|
|
|
|
skb->protocol = eth_type_trans(skb, dev);
|
|
|
|
received++;
|
|
|
|
netif_rx(skb);
|
|
|
|
} else {
|
2010-02-26 20:00:47 +08:00
|
|
|
dev_warn(fep->dev,
|
|
|
|
"Memory squeeze, dropping packet.\n");
|
2005-10-29 04:25:58 +08:00
|
|
|
fep->stats.rx_dropped++;
|
|
|
|
skbn = skb;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fep->rx_skbuff[curidx] = skbn;
|
|
|
|
CBDW_BUFADDR(bdp, dma_map_single(fep->dev, skbn->data,
|
|
|
|
L1_CACHE_ALIGN(PKT_MAXBUF_SIZE),
|
|
|
|
DMA_FROM_DEVICE));
|
|
|
|
CBDW_DATLEN(bdp, 0);
|
|
|
|
CBDW_SC(bdp, (sc & ~BD_ENET_RX_STATS) | BD_ENET_RX_EMPTY);
|
|
|
|
|
|
|
|
/*
|
2007-09-19 00:05:35 +08:00
|
|
|
* Update BD pointer to next entry.
|
2005-10-29 04:25:58 +08:00
|
|
|
*/
|
|
|
|
if ((sc & BD_ENET_RX_WRAP) == 0)
|
|
|
|
bdp++;
|
|
|
|
else
|
|
|
|
bdp = fep->rx_bd_base;
|
|
|
|
|
|
|
|
(*fep->ops->rx_bd_done)(dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
fep->cur_rx = bdp;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void fs_enet_tx(struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct fs_enet_private *fep = netdev_priv(dev);
|
2007-10-02 03:20:58 +08:00
|
|
|
cbd_t __iomem *bdp;
|
2005-10-29 04:25:58 +08:00
|
|
|
struct sk_buff *skb;
|
|
|
|
int dirtyidx, do_wake, do_restart;
|
|
|
|
u16 sc;
|
|
|
|
|
2007-09-19 00:05:27 +08:00
|
|
|
spin_lock(&fep->tx_lock);
|
2005-10-29 04:25:58 +08:00
|
|
|
bdp = fep->dirty_tx;
|
|
|
|
|
|
|
|
do_wake = do_restart = 0;
|
|
|
|
while (((sc = CBDR_SC(bdp)) & BD_ENET_TX_READY) == 0) {
|
|
|
|
dirtyidx = bdp - fep->tx_bd_base;
|
|
|
|
|
|
|
|
if (fep->tx_free == fep->tx_ring)
|
|
|
|
break;
|
|
|
|
|
|
|
|
skb = fep->tx_skbuff[dirtyidx];
|
|
|
|
|
|
|
|
/*
|
2007-09-19 00:05:35 +08:00
|
|
|
* Check for errors.
|
2005-10-29 04:25:58 +08:00
|
|
|
*/
|
|
|
|
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 */
|
|
|
|
fep->stats.tx_heartbeat_errors++;
|
|
|
|
if (sc & BD_ENET_TX_LC) /* Late collision */
|
|
|
|
fep->stats.tx_window_errors++;
|
|
|
|
if (sc & BD_ENET_TX_RL) /* Retrans limit */
|
|
|
|
fep->stats.tx_aborted_errors++;
|
|
|
|
if (sc & BD_ENET_TX_UN) /* Underrun */
|
|
|
|
fep->stats.tx_fifo_errors++;
|
|
|
|
if (sc & BD_ENET_TX_CSL) /* Carrier lost */
|
|
|
|
fep->stats.tx_carrier_errors++;
|
|
|
|
|
|
|
|
if (sc & (BD_ENET_TX_LC | BD_ENET_TX_RL | BD_ENET_TX_UN)) {
|
|
|
|
fep->stats.tx_errors++;
|
|
|
|
do_restart = 1;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
fep->stats.tx_packets++;
|
|
|
|
|
2010-02-26 20:00:47 +08:00
|
|
|
if (sc & BD_ENET_TX_READY) {
|
|
|
|
dev_warn(fep->dev,
|
|
|
|
"HEY! Enet xmit interrupt and TX_READY.\n");
|
|
|
|
}
|
2005-10-29 04:25:58 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Deferred means some collisions occurred during transmit,
|
|
|
|
* but we eventually sent the packet OK.
|
|
|
|
*/
|
|
|
|
if (sc & BD_ENET_TX_DEF)
|
|
|
|
fep->stats.collisions++;
|
|
|
|
|
|
|
|
/* unmap */
|
2005-10-30 06:22:40 +08:00
|
|
|
dma_unmap_single(fep->dev, CBDR_BUFADDR(bdp),
|
|
|
|
skb->len, DMA_TO_DEVICE);
|
2005-10-29 04:25:58 +08:00
|
|
|
|
|
|
|
/*
|
2007-09-19 00:05:35 +08:00
|
|
|
* Free the sk buffer associated with this last transmit.
|
2005-10-29 04:25:58 +08:00
|
|
|
*/
|
|
|
|
dev_kfree_skb_irq(skb);
|
|
|
|
fep->tx_skbuff[dirtyidx] = NULL;
|
|
|
|
|
|
|
|
/*
|
2007-09-19 00:05:35 +08:00
|
|
|
* Update pointer to next buffer descriptor to be transmitted.
|
2005-10-29 04:25:58 +08:00
|
|
|
*/
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
if (!fep->tx_free++)
|
|
|
|
do_wake = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
fep->dirty_tx = bdp;
|
|
|
|
|
|
|
|
if (do_restart)
|
|
|
|
(*fep->ops->tx_restart)(dev);
|
|
|
|
|
2007-09-19 00:05:27 +08:00
|
|
|
spin_unlock(&fep->tx_lock);
|
2005-10-29 04:25:58 +08:00
|
|
|
|
|
|
|
if (do_wake)
|
|
|
|
netif_wake_queue(dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The interrupt handler.
|
|
|
|
* This is called from the MPC core interrupt.
|
|
|
|
*/
|
|
|
|
static irqreturn_t
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 21:55:46 +08:00
|
|
|
fs_enet_interrupt(int irq, void *dev_id)
|
2005-10-29 04:25:58 +08:00
|
|
|
{
|
|
|
|
struct net_device *dev = dev_id;
|
|
|
|
struct fs_enet_private *fep;
|
|
|
|
const struct fs_platform_info *fpi;
|
|
|
|
u32 int_events;
|
|
|
|
u32 int_clr_events;
|
|
|
|
int nr, napi_ok;
|
|
|
|
int handled;
|
|
|
|
|
|
|
|
fep = netdev_priv(dev);
|
|
|
|
fpi = fep->fpi;
|
|
|
|
|
|
|
|
nr = 0;
|
|
|
|
while ((int_events = (*fep->ops->get_int_events)(dev)) != 0) {
|
|
|
|
nr++;
|
|
|
|
|
|
|
|
int_clr_events = int_events;
|
|
|
|
if (fpi->use_napi)
|
|
|
|
int_clr_events &= ~fep->ev_napi_rx;
|
|
|
|
|
|
|
|
(*fep->ops->clear_int_events)(dev, int_clr_events);
|
|
|
|
|
|
|
|
if (int_events & fep->ev_err)
|
|
|
|
(*fep->ops->ev_error)(dev, int_events);
|
|
|
|
|
|
|
|
if (int_events & fep->ev_rx) {
|
|
|
|
if (!fpi->use_napi)
|
|
|
|
fs_enet_rx_non_napi(dev);
|
|
|
|
else {
|
[NET]: Make NAPI polling independent of struct net_device objects.
Several devices have multiple independant RX queues per net
device, and some have a single interrupt doorbell for several
queues.
In either case, it's easier to support layouts like that if the
structure representing the poll is independant from the net
device itself.
The signature of the ->poll() call back goes from:
int foo_poll(struct net_device *dev, int *budget)
to
int foo_poll(struct napi_struct *napi, int budget)
The caller is returned the number of RX packets processed (or
the number of "NAPI credits" consumed if you want to get
abstract). The callee no longer messes around bumping
dev->quota, *budget, etc. because that is all handled in the
caller upon return.
The napi_struct is to be embedded in the device driver private data
structures.
Furthermore, it is the driver's responsibility to disable all NAPI
instances in it's ->stop() device close handler. Since the
napi_struct is privatized into the driver's private data structures,
only the driver knows how to get at all of the napi_struct instances
it may have per-device.
With lots of help and suggestions from Rusty Russell, Roland Dreier,
Michael Chan, Jeff Garzik, and Jamal Hadi Salim.
Bug fixes from Thomas Graf, Roland Dreier, Peter Zijlstra,
Joseph Fannin, Scott Wood, Hans J. Koch, and Michael Chan.
[ Ported to current tree and all drivers converted. Integrated
Stephen's follow-on kerneldoc additions, and restored poll_list
handling to the old style to fix mutual exclusion issues. -DaveM ]
Signed-off-by: Stephen Hemminger <shemminger@linux-foundation.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-10-04 07:41:36 +08:00
|
|
|
napi_ok = napi_schedule_prep(&fep->napi);
|
2005-10-29 04:25:58 +08:00
|
|
|
|
|
|
|
(*fep->ops->napi_disable_rx)(dev);
|
|
|
|
(*fep->ops->clear_int_events)(dev, fep->ev_napi_rx);
|
|
|
|
|
|
|
|
/* NOTE: it is possible for FCCs in NAPI mode */
|
|
|
|
/* to submit a spurious interrupt while in poll */
|
|
|
|
if (napi_ok)
|
2009-01-20 08:43:59 +08:00
|
|
|
__napi_schedule(&fep->napi);
|
2005-10-29 04:25:58 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (int_events & fep->ev_tx)
|
|
|
|
fs_enet_tx(dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
handled = nr > 0;
|
|
|
|
return IRQ_RETVAL(handled);
|
|
|
|
}
|
|
|
|
|
|
|
|
void fs_init_bds(struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct fs_enet_private *fep = netdev_priv(dev);
|
2007-10-02 03:20:58 +08:00
|
|
|
cbd_t __iomem *bdp;
|
2005-10-29 04:25:58 +08:00
|
|
|
struct sk_buff *skb;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
fs_cleanup_bds(dev);
|
|
|
|
|
|
|
|
fep->dirty_tx = fep->cur_tx = fep->tx_bd_base;
|
|
|
|
fep->tx_free = fep->tx_ring;
|
|
|
|
fep->cur_rx = fep->rx_bd_base;
|
|
|
|
|
|
|
|
/*
|
2007-09-19 00:05:35 +08:00
|
|
|
* Initialize the receive buffer descriptors.
|
2005-10-29 04:25:58 +08:00
|
|
|
*/
|
|
|
|
for (i = 0, bdp = fep->rx_bd_base; i < fep->rx_ring; i++, bdp++) {
|
|
|
|
skb = dev_alloc_skb(ENET_RX_FRSIZE);
|
|
|
|
if (skb == NULL) {
|
2010-02-26 20:00:47 +08:00
|
|
|
dev_warn(fep->dev,
|
|
|
|
"Memory squeeze, unable to allocate skb\n");
|
2005-10-29 04:25:58 +08:00
|
|
|
break;
|
|
|
|
}
|
2007-10-02 03:20:52 +08:00
|
|
|
skb_align(skb, ENET_RX_ALIGN);
|
2005-10-29 04:25:58 +08:00
|
|
|
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_DATLEN(bdp, 0); /* zero */
|
|
|
|
CBDW_SC(bdp, BD_ENET_RX_EMPTY |
|
|
|
|
((i < fep->rx_ring - 1) ? 0 : BD_SC_WRAP));
|
|
|
|
}
|
|
|
|
/*
|
2007-09-19 00:05:35 +08:00
|
|
|
* if we failed, fillup remainder
|
2005-10-29 04:25:58 +08:00
|
|
|
*/
|
|
|
|
for (; i < fep->rx_ring; i++, bdp++) {
|
|
|
|
fep->rx_skbuff[i] = NULL;
|
|
|
|
CBDW_SC(bdp, (i < fep->rx_ring - 1) ? 0 : BD_SC_WRAP);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2007-09-19 00:05:35 +08:00
|
|
|
* ...and the same for transmit.
|
2005-10-29 04:25:58 +08:00
|
|
|
*/
|
|
|
|
for (i = 0, bdp = fep->tx_bd_base; i < fep->tx_ring; i++, bdp++) {
|
|
|
|
fep->tx_skbuff[i] = NULL;
|
|
|
|
CBDW_BUFADDR(bdp, 0);
|
|
|
|
CBDW_DATLEN(bdp, 0);
|
|
|
|
CBDW_SC(bdp, (i < fep->tx_ring - 1) ? 0 : BD_SC_WRAP);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void fs_cleanup_bds(struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct fs_enet_private *fep = netdev_priv(dev);
|
|
|
|
struct sk_buff *skb;
|
2007-10-02 03:20:58 +08:00
|
|
|
cbd_t __iomem *bdp;
|
2005-10-29 04:25:58 +08:00
|
|
|
int i;
|
|
|
|
|
|
|
|
/*
|
2007-09-19 00:05:35 +08:00
|
|
|
* Reset SKB transmit buffers.
|
2005-10-29 04:25:58 +08:00
|
|
|
*/
|
2005-10-30 06:22:40 +08:00
|
|
|
for (i = 0, bdp = fep->tx_bd_base; i < fep->tx_ring; i++, bdp++) {
|
2005-10-29 04:25:58 +08:00
|
|
|
if ((skb = fep->tx_skbuff[i]) == NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* unmap */
|
2005-10-30 06:22:40 +08:00
|
|
|
dma_unmap_single(fep->dev, CBDR_BUFADDR(bdp),
|
|
|
|
skb->len, DMA_TO_DEVICE);
|
2005-10-29 04:25:58 +08:00
|
|
|
|
|
|
|
fep->tx_skbuff[i] = NULL;
|
|
|
|
dev_kfree_skb(skb);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2007-09-19 00:05:35 +08:00
|
|
|
* Reset SKB receive buffers
|
2005-10-29 04:25:58 +08:00
|
|
|
*/
|
2005-10-30 06:22:40 +08:00
|
|
|
for (i = 0, bdp = fep->rx_bd_base; i < fep->rx_ring; i++, bdp++) {
|
2005-10-29 04:25:58 +08:00
|
|
|
if ((skb = fep->rx_skbuff[i]) == NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* unmap */
|
2005-10-30 06:22:40 +08:00
|
|
|
dma_unmap_single(fep->dev, CBDR_BUFADDR(bdp),
|
2005-10-29 04:25:58 +08:00
|
|
|
L1_CACHE_ALIGN(PKT_MAXBUF_SIZE),
|
|
|
|
DMA_FROM_DEVICE);
|
|
|
|
|
|
|
|
fep->rx_skbuff[i] = NULL;
|
|
|
|
|
|
|
|
dev_kfree_skb(skb);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************************/
|
|
|
|
|
2010-02-26 20:00:49 +08:00
|
|
|
#ifdef CONFIG_FS_ENET_MPC5121_FEC
|
|
|
|
/*
|
|
|
|
* MPC5121 FEC requeries 4-byte alignment for TX data buffer!
|
|
|
|
*/
|
|
|
|
static struct sk_buff *tx_skb_align_workaround(struct net_device *dev,
|
|
|
|
struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
struct sk_buff *new_skb;
|
|
|
|
struct fs_enet_private *fep = netdev_priv(dev);
|
|
|
|
|
|
|
|
/* Alloc new skb */
|
|
|
|
new_skb = dev_alloc_skb(skb->len + 4);
|
|
|
|
if (!new_skb) {
|
|
|
|
if (net_ratelimit()) {
|
|
|
|
dev_warn(fep->dev,
|
|
|
|
"Memory squeeze, dropping tx packet.\n");
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Make sure new skb is properly aligned */
|
|
|
|
skb_align(new_skb, 4);
|
|
|
|
|
|
|
|
/* Copy data to new skb ... */
|
|
|
|
skb_copy_from_linear_data(skb, new_skb->data, skb->len);
|
|
|
|
skb_put(new_skb, skb->len);
|
|
|
|
|
|
|
|
/* ... and free an old one */
|
|
|
|
dev_kfree_skb_any(skb);
|
|
|
|
|
|
|
|
return new_skb;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2005-10-29 04:25:58 +08:00
|
|
|
static int fs_enet_start_xmit(struct sk_buff *skb, struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct fs_enet_private *fep = netdev_priv(dev);
|
2007-10-02 03:20:58 +08:00
|
|
|
cbd_t __iomem *bdp;
|
2005-10-29 04:25:58 +08:00
|
|
|
int curidx;
|
|
|
|
u16 sc;
|
|
|
|
unsigned long flags;
|
|
|
|
|
2010-02-26 20:00:49 +08:00
|
|
|
#ifdef CONFIG_FS_ENET_MPC5121_FEC
|
|
|
|
if (((unsigned long)skb->data) & 0x3) {
|
|
|
|
skb = tx_skb_align_workaround(dev, skb);
|
|
|
|
if (!skb) {
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
return NETDEV_TX_BUSY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2005-10-29 04:25:58 +08:00
|
|
|
spin_lock_irqsave(&fep->tx_lock, flags);
|
|
|
|
|
|
|
|
/*
|
2007-09-19 00:05:35 +08:00
|
|
|
* Fill in a Tx ring entry
|
2005-10-29 04:25:58 +08:00
|
|
|
*/
|
|
|
|
bdp = fep->cur_tx;
|
|
|
|
|
|
|
|
if (!fep->tx_free || (CBDR_SC(bdp) & BD_ENET_TX_READY)) {
|
|
|
|
netif_stop_queue(dev);
|
|
|
|
spin_unlock_irqrestore(&fep->tx_lock, flags);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Ooops. All transmit buffers are full. Bail out.
|
|
|
|
* This should not happen, since the tx queue should be stopped.
|
|
|
|
*/
|
2010-02-26 20:00:47 +08:00
|
|
|
dev_warn(fep->dev, "tx queue full!.\n");
|
2005-10-29 04:25:58 +08:00
|
|
|
return NETDEV_TX_BUSY;
|
|
|
|
}
|
|
|
|
|
|
|
|
curidx = bdp - fep->tx_bd_base;
|
|
|
|
/*
|
2007-09-19 00:05:35 +08:00
|
|
|
* Clear all of the status flags.
|
2005-10-29 04:25:58 +08:00
|
|
|
*/
|
|
|
|
CBDC_SC(bdp, BD_ENET_TX_STATS);
|
|
|
|
|
|
|
|
/*
|
2007-09-19 00:05:35 +08:00
|
|
|
* Save skb pointer.
|
2005-10-29 04:25:58 +08:00
|
|
|
*/
|
|
|
|
fep->tx_skbuff[curidx] = skb;
|
|
|
|
|
|
|
|
fep->stats.tx_bytes += skb->len;
|
|
|
|
|
|
|
|
/*
|
2007-09-19 00:05:35 +08:00
|
|
|
* Push the data cache so the CPM does not get stale memory data.
|
2005-10-29 04:25:58 +08:00
|
|
|
*/
|
|
|
|
CBDW_BUFADDR(bdp, dma_map_single(fep->dev,
|
|
|
|
skb->data, skb->len, DMA_TO_DEVICE));
|
|
|
|
CBDW_DATLEN(bdp, skb->len);
|
|
|
|
|
|
|
|
/*
|
2007-09-19 00:05:35 +08:00
|
|
|
* If this was the last BD in the ring, start at the beginning again.
|
2005-10-29 04:25:58 +08:00
|
|
|
*/
|
|
|
|
if ((CBDR_SC(bdp) & BD_ENET_TX_WRAP) == 0)
|
|
|
|
fep->cur_tx++;
|
|
|
|
else
|
|
|
|
fep->cur_tx = fep->tx_bd_base;
|
|
|
|
|
|
|
|
if (!--fep->tx_free)
|
|
|
|
netif_stop_queue(dev);
|
|
|
|
|
|
|
|
/* Trigger transmission start */
|
|
|
|
sc = BD_ENET_TX_READY | BD_ENET_TX_INTR |
|
|
|
|
BD_ENET_TX_LAST | BD_ENET_TX_TC;
|
|
|
|
|
|
|
|
/* note that while FEC does not have this bit
|
|
|
|
* it marks it as available for software use
|
|
|
|
* yay for hw reuse :) */
|
|
|
|
if (skb->len <= 60)
|
|
|
|
sc |= BD_ENET_TX_PAD;
|
|
|
|
CBDS_SC(bdp, sc);
|
|
|
|
|
|
|
|
(*fep->ops->tx_kickstart)(dev);
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&fep->tx_lock, flags);
|
|
|
|
|
|
|
|
return NETDEV_TX_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void fs_timeout(struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct fs_enet_private *fep = netdev_priv(dev);
|
|
|
|
unsigned long flags;
|
|
|
|
int wake = 0;
|
|
|
|
|
|
|
|
fep->stats.tx_errors++;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&fep->lock, flags);
|
|
|
|
|
|
|
|
if (dev->flags & IFF_UP) {
|
2006-08-15 14:00:30 +08:00
|
|
|
phy_stop(fep->phydev);
|
2005-10-29 04:25:58 +08:00
|
|
|
(*fep->ops->stop)(dev);
|
|
|
|
(*fep->ops->restart)(dev);
|
2006-08-15 14:00:30 +08:00
|
|
|
phy_start(fep->phydev);
|
2005-10-29 04:25:58 +08:00
|
|
|
}
|
|
|
|
|
2006-08-15 14:00:30 +08:00
|
|
|
phy_start(fep->phydev);
|
2005-10-29 04:25:58 +08:00
|
|
|
wake = fep->tx_free && !(CBDR_SC(fep->cur_tx) & BD_ENET_TX_READY);
|
|
|
|
spin_unlock_irqrestore(&fep->lock, flags);
|
|
|
|
|
|
|
|
if (wake)
|
|
|
|
netif_wake_queue(dev);
|
|
|
|
}
|
|
|
|
|
2006-08-15 14:00:30 +08:00
|
|
|
/*-----------------------------------------------------------------------------
|
|
|
|
* generic link-change handler - should be sufficient for most cases
|
|
|
|
*-----------------------------------------------------------------------------*/
|
|
|
|
static void generic_adjust_link(struct net_device *dev)
|
|
|
|
{
|
2007-10-02 03:20:17 +08:00
|
|
|
struct fs_enet_private *fep = netdev_priv(dev);
|
|
|
|
struct phy_device *phydev = fep->phydev;
|
|
|
|
int new_state = 0;
|
|
|
|
|
|
|
|
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))
|
|
|
|
phy_print_status(phydev);
|
2006-08-15 14:00:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void fs_adjust_link(struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct fs_enet_private *fep = netdev_priv(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);
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&fep->lock, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int fs_init_phy(struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct fs_enet_private *fep = netdev_priv(dev);
|
|
|
|
struct phy_device *phydev;
|
|
|
|
|
|
|
|
fep->oldlink = 0;
|
|
|
|
fep->oldspeed = 0;
|
|
|
|
fep->oldduplex = -1;
|
2009-07-17 05:31:36 +08:00
|
|
|
|
|
|
|
phydev = of_phy_connect(dev, fep->fpi->phy_node, &fs_adjust_link, 0,
|
|
|
|
PHY_INTERFACE_MODE_MII);
|
|
|
|
if (!phydev) {
|
|
|
|
phydev = of_phy_connect_fixed_link(dev, &fs_adjust_link,
|
|
|
|
PHY_INTERFACE_MODE_MII);
|
2006-08-15 14:00:30 +08:00
|
|
|
}
|
2009-07-17 05:31:36 +08:00
|
|
|
if (!phydev) {
|
|
|
|
dev_err(&dev->dev, "Could not attach to PHY\n");
|
|
|
|
return -ENODEV;
|
2006-08-15 14:00:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
fep->phydev = phydev;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-10-29 04:25:58 +08:00
|
|
|
static int fs_enet_open(struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct fs_enet_private *fep = netdev_priv(dev);
|
|
|
|
int r;
|
2006-08-15 14:00:30 +08:00
|
|
|
int err;
|
2005-10-29 04:25:58 +08:00
|
|
|
|
2008-08-26 09:20:53 +08:00
|
|
|
/* to initialize the fep->cur_rx,... */
|
|
|
|
/* not doing this, will cause a crash in fs_enet_rx_napi */
|
|
|
|
fs_init_bds(fep->ndev);
|
|
|
|
|
2007-10-18 01:42:43 +08:00
|
|
|
if (fep->fpi->use_napi)
|
|
|
|
napi_enable(&fep->napi);
|
[NET]: Make NAPI polling independent of struct net_device objects.
Several devices have multiple independant RX queues per net
device, and some have a single interrupt doorbell for several
queues.
In either case, it's easier to support layouts like that if the
structure representing the poll is independant from the net
device itself.
The signature of the ->poll() call back goes from:
int foo_poll(struct net_device *dev, int *budget)
to
int foo_poll(struct napi_struct *napi, int budget)
The caller is returned the number of RX packets processed (or
the number of "NAPI credits" consumed if you want to get
abstract). The callee no longer messes around bumping
dev->quota, *budget, etc. because that is all handled in the
caller upon return.
The napi_struct is to be embedded in the device driver private data
structures.
Furthermore, it is the driver's responsibility to disable all NAPI
instances in it's ->stop() device close handler. Since the
napi_struct is privatized into the driver's private data structures,
only the driver knows how to get at all of the napi_struct instances
it may have per-device.
With lots of help and suggestions from Rusty Russell, Roland Dreier,
Michael Chan, Jeff Garzik, and Jamal Hadi Salim.
Bug fixes from Thomas Graf, Roland Dreier, Peter Zijlstra,
Joseph Fannin, Scott Wood, Hans J. Koch, and Michael Chan.
[ Ported to current tree and all drivers converted. Integrated
Stephen's follow-on kerneldoc additions, and restored poll_list
handling to the old style to fix mutual exclusion issues. -DaveM ]
Signed-off-by: Stephen Hemminger <shemminger@linux-foundation.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-10-04 07:41:36 +08:00
|
|
|
|
2005-10-29 04:25:58 +08:00
|
|
|
/* Install our interrupt handler. */
|
2008-09-23 05:52:18 +08:00
|
|
|
r = request_irq(fep->interrupt, fs_enet_interrupt, IRQF_SHARED,
|
|
|
|
"fs_enet-mac", dev);
|
2005-10-29 04:25:58 +08:00
|
|
|
if (r != 0) {
|
2010-02-26 20:00:47 +08:00
|
|
|
dev_err(fep->dev, "Could not allocate FS_ENET IRQ!");
|
2007-10-18 01:42:43 +08:00
|
|
|
if (fep->fpi->use_napi)
|
|
|
|
napi_disable(&fep->napi);
|
2005-10-29 04:25:58 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2006-08-15 14:00:30 +08:00
|
|
|
err = fs_init_phy(dev);
|
2007-10-18 01:42:43 +08:00
|
|
|
if (err) {
|
2009-01-15 12:43:43 +08:00
|
|
|
free_irq(fep->interrupt, dev);
|
2007-10-18 01:42:43 +08:00
|
|
|
if (fep->fpi->use_napi)
|
|
|
|
napi_disable(&fep->napi);
|
2006-08-15 14:00:30 +08:00
|
|
|
return err;
|
[NET]: Make NAPI polling independent of struct net_device objects.
Several devices have multiple independant RX queues per net
device, and some have a single interrupt doorbell for several
queues.
In either case, it's easier to support layouts like that if the
structure representing the poll is independant from the net
device itself.
The signature of the ->poll() call back goes from:
int foo_poll(struct net_device *dev, int *budget)
to
int foo_poll(struct napi_struct *napi, int budget)
The caller is returned the number of RX packets processed (or
the number of "NAPI credits" consumed if you want to get
abstract). The callee no longer messes around bumping
dev->quota, *budget, etc. because that is all handled in the
caller upon return.
The napi_struct is to be embedded in the device driver private data
structures.
Furthermore, it is the driver's responsibility to disable all NAPI
instances in it's ->stop() device close handler. Since the
napi_struct is privatized into the driver's private data structures,
only the driver knows how to get at all of the napi_struct instances
it may have per-device.
With lots of help and suggestions from Rusty Russell, Roland Dreier,
Michael Chan, Jeff Garzik, and Jamal Hadi Salim.
Bug fixes from Thomas Graf, Roland Dreier, Peter Zijlstra,
Joseph Fannin, Scott Wood, Hans J. Koch, and Michael Chan.
[ Ported to current tree and all drivers converted. Integrated
Stephen's follow-on kerneldoc additions, and restored poll_list
handling to the old style to fix mutual exclusion issues. -DaveM ]
Signed-off-by: Stephen Hemminger <shemminger@linux-foundation.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-10-04 07:41:36 +08:00
|
|
|
}
|
2006-08-15 14:00:30 +08:00
|
|
|
phy_start(fep->phydev);
|
2005-10-29 04:25:58 +08:00
|
|
|
|
2008-07-23 06:41:24 +08:00
|
|
|
netif_start_queue(dev);
|
|
|
|
|
2005-10-29 04:25:58 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int fs_enet_close(struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct fs_enet_private *fep = netdev_priv(dev);
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
netif_stop_queue(dev);
|
|
|
|
netif_carrier_off(dev);
|
2008-04-11 20:05:50 +08:00
|
|
|
if (fep->fpi->use_napi)
|
|
|
|
napi_disable(&fep->napi);
|
2006-08-15 14:00:30 +08:00
|
|
|
phy_stop(fep->phydev);
|
2005-10-29 04:25:58 +08:00
|
|
|
|
|
|
|
spin_lock_irqsave(&fep->lock, flags);
|
2007-09-19 00:05:27 +08:00
|
|
|
spin_lock(&fep->tx_lock);
|
2005-10-29 04:25:58 +08:00
|
|
|
(*fep->ops->stop)(dev);
|
2007-09-19 00:05:27 +08:00
|
|
|
spin_unlock(&fep->tx_lock);
|
2005-10-29 04:25:58 +08:00
|
|
|
spin_unlock_irqrestore(&fep->lock, flags);
|
|
|
|
|
|
|
|
/* release any irqs */
|
2006-08-15 14:00:30 +08:00
|
|
|
phy_disconnect(fep->phydev);
|
|
|
|
fep->phydev = NULL;
|
2008-09-23 05:52:18 +08:00
|
|
|
free_irq(fep->interrupt, dev);
|
2005-10-29 04:25:58 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct net_device_stats *fs_enet_get_stats(struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct fs_enet_private *fep = netdev_priv(dev);
|
|
|
|
return &fep->stats;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
static void fs_get_drvinfo(struct net_device *dev,
|
|
|
|
struct ethtool_drvinfo *info)
|
|
|
|
{
|
|
|
|
strcpy(info->driver, DRV_MODULE_NAME);
|
|
|
|
strcpy(info->version, DRV_MODULE_VERSION);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int fs_get_regs_len(struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct fs_enet_private *fep = netdev_priv(dev);
|
|
|
|
|
|
|
|
return (*fep->ops->get_regs_len)(dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void fs_get_regs(struct net_device *dev, struct ethtool_regs *regs,
|
|
|
|
void *p)
|
|
|
|
{
|
|
|
|
struct fs_enet_private *fep = netdev_priv(dev);
|
|
|
|
unsigned long flags;
|
|
|
|
int r, len;
|
|
|
|
|
|
|
|
len = regs->len;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&fep->lock, flags);
|
|
|
|
r = (*fep->ops->get_regs)(dev, p, &len);
|
|
|
|
spin_unlock_irqrestore(&fep->lock, flags);
|
|
|
|
|
|
|
|
if (r == 0)
|
|
|
|
regs->version = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int fs_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
|
|
|
|
{
|
|
|
|
struct fs_enet_private *fep = netdev_priv(dev);
|
2008-01-09 03:05:55 +08:00
|
|
|
|
|
|
|
if (!fep->phydev)
|
|
|
|
return -ENODEV;
|
|
|
|
|
2006-08-15 14:00:30 +08:00
|
|
|
return phy_ethtool_gset(fep->phydev, cmd);
|
2005-10-29 04:25:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int fs_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
|
|
|
|
{
|
|
|
|
struct fs_enet_private *fep = netdev_priv(dev);
|
2008-01-09 03:05:55 +08:00
|
|
|
|
|
|
|
if (!fep->phydev)
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
return phy_ethtool_sset(fep->phydev, cmd);
|
2005-10-29 04:25:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int fs_nway_reset(struct net_device *dev)
|
|
|
|
{
|
2006-08-15 14:00:30 +08:00
|
|
|
return 0;
|
2005-10-29 04:25:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2006-09-14 02:30:00 +08:00
|
|
|
static const struct ethtool_ops fs_ethtool_ops = {
|
2005-10-29 04:25:58 +08:00
|
|
|
.get_drvinfo = fs_get_drvinfo,
|
|
|
|
.get_regs_len = fs_get_regs_len,
|
|
|
|
.get_settings = fs_get_settings,
|
|
|
|
.set_settings = fs_set_settings,
|
|
|
|
.nway_reset = fs_nway_reset,
|
|
|
|
.get_link = ethtool_op_get_link,
|
|
|
|
.get_msglevel = fs_get_msglevel,
|
|
|
|
.set_msglevel = fs_set_msglevel,
|
|
|
|
.set_tx_csum = ethtool_op_set_tx_csum, /* local! */
|
|
|
|
.set_sg = ethtool_op_set_sg,
|
|
|
|
.get_regs = fs_get_regs,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int fs_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
|
|
|
|
{
|
|
|
|
struct fs_enet_private *fep = netdev_priv(dev);
|
|
|
|
struct mii_ioctl_data *mii = (struct mii_ioctl_data *)&rq->ifr_data;
|
|
|
|
|
|
|
|
if (!netif_running(dev))
|
|
|
|
return -EINVAL;
|
|
|
|
|
2008-02-16 05:08:04 +08:00
|
|
|
return phy_mii_ioctl(fep->phydev, mii, cmd);
|
2005-10-29 04:25:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
extern int fs_mii_connect(struct net_device *dev);
|
|
|
|
extern void fs_mii_disconnect(struct net_device *dev);
|
|
|
|
|
|
|
|
/**************************************************************************************/
|
|
|
|
|
2007-10-02 23:55:58 +08:00
|
|
|
#ifdef CONFIG_FS_ENET_HAS_FEC
|
|
|
|
#define IS_FEC(match) ((match)->data == &fs_fec_ops)
|
|
|
|
#else
|
|
|
|
#define IS_FEC(match) 0
|
|
|
|
#endif
|
|
|
|
|
2009-04-09 12:46:53 +08:00
|
|
|
static const struct net_device_ops fs_enet_netdev_ops = {
|
|
|
|
.ndo_open = fs_enet_open,
|
|
|
|
.ndo_stop = fs_enet_close,
|
|
|
|
.ndo_get_stats = fs_enet_get_stats,
|
|
|
|
.ndo_start_xmit = fs_enet_start_xmit,
|
|
|
|
.ndo_tx_timeout = fs_timeout,
|
|
|
|
.ndo_set_multicast_list = fs_set_multicast_list,
|
|
|
|
.ndo_do_ioctl = fs_ioctl,
|
|
|
|
.ndo_validate_addr = eth_validate_addr,
|
|
|
|
.ndo_set_mac_address = eth_mac_addr,
|
|
|
|
.ndo_change_mtu = eth_change_mtu,
|
|
|
|
#ifdef CONFIG_NET_POLL_CONTROLLER
|
|
|
|
.ndo_poll_controller = fs_enet_netpoll,
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2007-10-02 23:55:58 +08:00
|
|
|
static int __devinit fs_enet_probe(struct of_device *ofdev,
|
|
|
|
const struct of_device_id *match)
|
|
|
|
{
|
|
|
|
struct net_device *ndev;
|
|
|
|
struct fs_enet_private *fep;
|
|
|
|
struct fs_platform_info *fpi;
|
|
|
|
const u32 *data;
|
|
|
|
const u8 *mac_addr;
|
|
|
|
int privsize, len, ret = -ENODEV;
|
|
|
|
|
|
|
|
fpi = kzalloc(sizeof(*fpi), GFP_KERNEL);
|
|
|
|
if (!fpi)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
if (!IS_FEC(match)) {
|
2010-04-14 07:12:29 +08:00
|
|
|
data = of_get_property(ofdev->dev.of_node, "fsl,cpm-command", &len);
|
2007-10-02 23:55:58 +08:00
|
|
|
if (!data || len != 4)
|
|
|
|
goto out_free_fpi;
|
|
|
|
|
|
|
|
fpi->cp_command = *data;
|
|
|
|
}
|
|
|
|
|
|
|
|
fpi->rx_ring = 32;
|
|
|
|
fpi->tx_ring = 32;
|
|
|
|
fpi->rx_copybreak = 240;
|
2007-10-18 01:42:43 +08:00
|
|
|
fpi->use_napi = 1;
|
2007-10-02 23:55:58 +08:00
|
|
|
fpi->napi_weight = 17;
|
2010-04-14 07:12:29 +08:00
|
|
|
fpi->phy_node = of_parse_phandle(ofdev->dev.of_node, "phy-handle", 0);
|
|
|
|
if ((!fpi->phy_node) && (!of_get_property(ofdev->dev.of_node, "fixed-link",
|
2009-04-25 20:53:33 +08:00
|
|
|
NULL)))
|
2007-10-02 23:55:58 +08:00
|
|
|
goto out_free_fpi;
|
|
|
|
|
|
|
|
privsize = sizeof(*fep) +
|
|
|
|
sizeof(struct sk_buff **) *
|
|
|
|
(fpi->rx_ring + fpi->tx_ring);
|
|
|
|
|
|
|
|
ndev = alloc_etherdev(privsize);
|
|
|
|
if (!ndev) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto out_free_fpi;
|
|
|
|
}
|
|
|
|
|
2009-07-17 05:31:36 +08:00
|
|
|
SET_NETDEV_DEV(ndev, &ofdev->dev);
|
2007-10-02 23:55:58 +08:00
|
|
|
dev_set_drvdata(&ofdev->dev, ndev);
|
|
|
|
|
|
|
|
fep = netdev_priv(ndev);
|
|
|
|
fep->dev = &ofdev->dev;
|
2007-10-18 01:42:43 +08:00
|
|
|
fep->ndev = ndev;
|
2007-10-02 23:55:58 +08:00
|
|
|
fep->fpi = fpi;
|
|
|
|
fep->ops = match->data;
|
|
|
|
|
|
|
|
ret = fep->ops->setup_data(ndev);
|
|
|
|
if (ret)
|
|
|
|
goto out_free_dev;
|
|
|
|
|
|
|
|
fep->rx_skbuff = (struct sk_buff **)&fep[1];
|
|
|
|
fep->tx_skbuff = fep->rx_skbuff + fpi->rx_ring;
|
|
|
|
|
|
|
|
spin_lock_init(&fep->lock);
|
|
|
|
spin_lock_init(&fep->tx_lock);
|
|
|
|
|
2010-04-14 07:12:29 +08:00
|
|
|
mac_addr = of_get_mac_address(ofdev->dev.of_node);
|
2007-10-02 23:55:58 +08:00
|
|
|
if (mac_addr)
|
|
|
|
memcpy(ndev->dev_addr, mac_addr, 6);
|
|
|
|
|
|
|
|
ret = fep->ops->allocate_bd(ndev);
|
|
|
|
if (ret)
|
|
|
|
goto out_cleanup_data;
|
|
|
|
|
|
|
|
fep->rx_bd_base = fep->ring_base;
|
|
|
|
fep->tx_bd_base = fep->rx_bd_base + fpi->rx_ring;
|
|
|
|
|
|
|
|
fep->tx_ring = fpi->tx_ring;
|
|
|
|
fep->rx_ring = fpi->rx_ring;
|
|
|
|
|
2009-04-09 12:46:53 +08:00
|
|
|
ndev->netdev_ops = &fs_enet_netdev_ops;
|
2007-10-02 23:55:58 +08:00
|
|
|
ndev->watchdog_timeo = 2 * HZ;
|
2007-10-18 01:42:43 +08:00
|
|
|
if (fpi->use_napi)
|
|
|
|
netif_napi_add(ndev, &fep->napi, fs_enet_rx_napi,
|
|
|
|
fpi->napi_weight);
|
|
|
|
|
2007-10-02 23:55:58 +08:00
|
|
|
ndev->ethtool_ops = &fs_ethtool_ops;
|
|
|
|
|
|
|
|
init_timer(&fep->phy_timer_list);
|
|
|
|
|
|
|
|
netif_carrier_off(ndev);
|
|
|
|
|
|
|
|
ret = register_netdev(ndev);
|
|
|
|
if (ret)
|
|
|
|
goto out_free_bd;
|
|
|
|
|
2010-02-26 20:00:47 +08:00
|
|
|
pr_info("%s: fs_enet: %pM\n", ndev->name, ndev->dev_addr);
|
2007-10-02 23:55:58 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
out_free_bd:
|
|
|
|
fep->ops->free_bd(ndev);
|
|
|
|
out_cleanup_data:
|
|
|
|
fep->ops->cleanup_data(ndev);
|
|
|
|
out_free_dev:
|
|
|
|
free_netdev(ndev);
|
|
|
|
dev_set_drvdata(&ofdev->dev, NULL);
|
2009-04-25 20:53:33 +08:00
|
|
|
of_node_put(fpi->phy_node);
|
2007-10-02 23:55:58 +08:00
|
|
|
out_free_fpi:
|
|
|
|
kfree(fpi);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int fs_enet_remove(struct of_device *ofdev)
|
|
|
|
{
|
|
|
|
struct net_device *ndev = dev_get_drvdata(&ofdev->dev);
|
|
|
|
struct fs_enet_private *fep = netdev_priv(ndev);
|
|
|
|
|
|
|
|
unregister_netdev(ndev);
|
|
|
|
|
|
|
|
fep->ops->free_bd(ndev);
|
|
|
|
fep->ops->cleanup_data(ndev);
|
|
|
|
dev_set_drvdata(fep->dev, NULL);
|
2009-04-25 20:53:33 +08:00
|
|
|
of_node_put(fep->fpi->phy_node);
|
2007-10-02 23:55:58 +08:00
|
|
|
free_netdev(ndev);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct of_device_id fs_enet_match[] = {
|
|
|
|
#ifdef CONFIG_FS_ENET_HAS_SCC
|
|
|
|
{
|
|
|
|
.compatible = "fsl,cpm1-scc-enet",
|
|
|
|
.data = (void *)&fs_scc_ops,
|
|
|
|
},
|
2008-08-26 09:20:53 +08:00
|
|
|
{
|
|
|
|
.compatible = "fsl,cpm2-scc-enet",
|
|
|
|
.data = (void *)&fs_scc_ops,
|
|
|
|
},
|
2007-10-02 23:55:58 +08:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_FS_ENET_HAS_FCC
|
|
|
|
{
|
|
|
|
.compatible = "fsl,cpm2-fcc-enet",
|
|
|
|
.data = (void *)&fs_fcc_ops,
|
|
|
|
},
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_FS_ENET_HAS_FEC
|
2010-02-26 20:00:48 +08:00
|
|
|
#ifdef CONFIG_FS_ENET_MPC5121_FEC
|
|
|
|
{
|
|
|
|
.compatible = "fsl,mpc5121-fec",
|
|
|
|
.data = (void *)&fs_fec_ops,
|
|
|
|
},
|
|
|
|
#else
|
2007-10-02 23:55:58 +08:00
|
|
|
{
|
|
|
|
.compatible = "fsl,pq1-fec-enet",
|
|
|
|
.data = (void *)&fs_fec_ops,
|
|
|
|
},
|
2010-02-26 20:00:48 +08:00
|
|
|
#endif
|
2007-10-02 23:55:58 +08:00
|
|
|
#endif
|
|
|
|
{}
|
|
|
|
};
|
2009-10-15 05:54:52 +08:00
|
|
|
MODULE_DEVICE_TABLE(of, fs_enet_match);
|
2007-10-02 23:55:58 +08:00
|
|
|
|
|
|
|
static struct of_platform_driver fs_enet_driver = {
|
2010-04-14 07:13:02 +08:00
|
|
|
.driver = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.name = "fs_enet",
|
|
|
|
.of_match_table = fs_enet_match,
|
|
|
|
},
|
2007-10-02 23:55:58 +08:00
|
|
|
.probe = fs_enet_probe,
|
|
|
|
.remove = fs_enet_remove,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init fs_init(void)
|
|
|
|
{
|
2009-04-28 17:05:21 +08:00
|
|
|
return of_register_platform_driver(&fs_enet_driver);
|
2007-10-02 23:55:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit fs_cleanup(void)
|
|
|
|
{
|
|
|
|
of_unregister_platform_driver(&fs_enet_driver);
|
|
|
|
}
|
2005-10-29 04:25:58 +08:00
|
|
|
|
2007-09-19 00:05:35 +08:00
|
|
|
#ifdef CONFIG_NET_POLL_CONTROLLER
|
|
|
|
static void fs_enet_netpoll(struct net_device *dev)
|
|
|
|
{
|
|
|
|
disable_irq(dev->irq);
|
2008-11-02 22:49:59 +08:00
|
|
|
fs_enet_interrupt(dev->irq, dev);
|
2007-09-19 00:05:35 +08:00
|
|
|
enable_irq(dev->irq);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2005-10-29 04:25:58 +08:00
|
|
|
/**************************************************************************************/
|
|
|
|
|
|
|
|
module_init(fs_init);
|
|
|
|
module_exit(fs_cleanup);
|