2007-10-27 00:07:49 +08:00
|
|
|
/*
|
|
|
|
* Driver for the MPC5200 Fast Ethernet Controller
|
|
|
|
*
|
|
|
|
* Originally written by Dale Farnsworth <dfarnsworth@mvista.com> and
|
|
|
|
* now maintained by Sylvain Munaut <tnt@246tNt.com>
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007 Domen Puncer, Telargo, Inc.
|
|
|
|
* Copyright (C) 2007 Sylvain Munaut <tnt@246tNt.com>
|
|
|
|
* Copyright (C) 2003-2004 MontaVista, Software, Inc.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2013-04-14 03:03:17 +08:00
|
|
|
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
|
|
|
|
2011-06-16 19:01:34 +08:00
|
|
|
#include <linux/dma-mapping.h>
|
2007-10-27 00:07:49 +08:00
|
|
|
#include <linux/module.h>
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/spinlock.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2007-10-27 00:07:49 +08:00
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/init.h>
|
2011-06-06 18:43:46 +08:00
|
|
|
#include <linux/interrupt.h>
|
2007-10-27 00:07:49 +08:00
|
|
|
#include <linux/crc32.h>
|
|
|
|
#include <linux/hardirq.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/of_device.h>
|
2009-04-25 20:53:02 +08:00
|
|
|
#include <linux/of_mdio.h>
|
2013-02-12 11:05:38 +08:00
|
|
|
#include <linux/of_net.h>
|
2007-10-27 00:07:49 +08:00
|
|
|
#include <linux/of_platform.h>
|
|
|
|
|
|
|
|
#include <linux/netdevice.h>
|
|
|
|
#include <linux/etherdevice.h>
|
|
|
|
#include <linux/ethtool.h>
|
|
|
|
#include <linux/skbuff.h>
|
|
|
|
|
|
|
|
#include <asm/io.h>
|
|
|
|
#include <asm/delay.h>
|
|
|
|
#include <asm/mpc52xx.h>
|
|
|
|
|
2012-10-12 23:52:45 +08:00
|
|
|
#include <linux/fsl/bestcomm/bestcomm.h>
|
|
|
|
#include <linux/fsl/bestcomm/fec.h>
|
2007-10-27 00:07:49 +08:00
|
|
|
|
|
|
|
#include "fec_mpc52xx.h"
|
|
|
|
|
|
|
|
#define DRIVER_NAME "mpc52xx-fec"
|
|
|
|
|
2008-05-02 01:05:58 +08:00
|
|
|
/* Private driver data structure */
|
|
|
|
struct mpc52xx_fec_priv {
|
2009-04-25 20:53:02 +08:00
|
|
|
struct net_device *ndev;
|
2008-05-02 01:05:58 +08:00
|
|
|
int duplex;
|
|
|
|
int speed;
|
|
|
|
int r_irq;
|
|
|
|
int t_irq;
|
|
|
|
struct mpc52xx_fec __iomem *fec;
|
|
|
|
struct bcom_task *rx_dmatsk;
|
|
|
|
struct bcom_task *tx_dmatsk;
|
|
|
|
spinlock_t lock;
|
|
|
|
int msg_enable;
|
|
|
|
|
|
|
|
/* MDIO link details */
|
2009-04-25 20:53:02 +08:00
|
|
|
unsigned int mdio_speed;
|
|
|
|
struct device_node *phy_node;
|
2008-05-02 01:05:58 +08:00
|
|
|
enum phy_state link;
|
2009-04-25 20:53:02 +08:00
|
|
|
int seven_wire_mode;
|
2008-05-02 01:05:58 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2007-10-27 00:07:49 +08:00
|
|
|
static irqreturn_t mpc52xx_fec_interrupt(int, void *);
|
|
|
|
static irqreturn_t mpc52xx_fec_rx_interrupt(int, void *);
|
|
|
|
static irqreturn_t mpc52xx_fec_tx_interrupt(int, void *);
|
|
|
|
static void mpc52xx_fec_stop(struct net_device *dev);
|
|
|
|
static void mpc52xx_fec_start(struct net_device *dev);
|
|
|
|
static void mpc52xx_fec_reset(struct net_device *dev);
|
|
|
|
|
|
|
|
#define MPC52xx_MESSAGES_DEFAULT ( NETIF_MSG_DRV | NETIF_MSG_PROBE | \
|
2008-06-10 07:33:51 +08:00
|
|
|
NETIF_MSG_LINK | NETIF_MSG_IFDOWN | NETIF_MSG_IFUP)
|
2007-10-27 00:07:49 +08:00
|
|
|
static int debug = -1; /* the above default */
|
|
|
|
module_param(debug, int, 0);
|
|
|
|
MODULE_PARM_DESC(debug, "debugging messages level");
|
|
|
|
|
|
|
|
static void mpc52xx_fec_tx_timeout(struct net_device *dev)
|
|
|
|
{
|
2009-12-09 12:29:10 +08:00
|
|
|
struct mpc52xx_fec_priv *priv = netdev_priv(dev);
|
|
|
|
unsigned long flags;
|
|
|
|
|
2007-10-27 00:07:49 +08:00
|
|
|
dev_warn(&dev->dev, "transmit timed out\n");
|
|
|
|
|
2009-12-09 12:29:10 +08:00
|
|
|
spin_lock_irqsave(&priv->lock, flags);
|
2007-10-27 00:07:49 +08:00
|
|
|
mpc52xx_fec_reset(dev);
|
|
|
|
dev->stats.tx_errors++;
|
2009-12-09 12:29:10 +08:00
|
|
|
spin_unlock_irqrestore(&priv->lock, flags);
|
2007-10-27 00:07:49 +08:00
|
|
|
|
|
|
|
netif_wake_queue(dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mpc52xx_fec_set_paddr(struct net_device *dev, u8 *mac)
|
|
|
|
{
|
|
|
|
struct mpc52xx_fec_priv *priv = netdev_priv(dev);
|
|
|
|
struct mpc52xx_fec __iomem *fec = priv->fec;
|
|
|
|
|
|
|
|
out_be32(&fec->paddr1, *(u32 *)(&mac[0]));
|
|
|
|
out_be32(&fec->paddr2, (*(u16 *)(&mac[4]) << 16) | FEC_PADDR2_TYPE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mpc52xx_fec_set_mac_address(struct net_device *dev, void *addr)
|
|
|
|
{
|
|
|
|
struct sockaddr *sock = addr;
|
|
|
|
|
|
|
|
memcpy(dev->dev_addr, sock->sa_data, dev->addr_len);
|
|
|
|
|
|
|
|
mpc52xx_fec_set_paddr(dev, sock->sa_data);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mpc52xx_fec_free_rx_buffers(struct net_device *dev, struct bcom_task *s)
|
|
|
|
{
|
|
|
|
while (!bcom_queue_empty(s)) {
|
|
|
|
struct bcom_fec_bd *bd;
|
|
|
|
struct sk_buff *skb;
|
|
|
|
|
|
|
|
skb = bcom_retrieve_buffer(s, NULL, (struct bcom_bd **)&bd);
|
2009-04-01 04:16:52 +08:00
|
|
|
dma_unmap_single(dev->dev.parent, bd->skb_pa, skb->len,
|
|
|
|
DMA_FROM_DEVICE);
|
2007-10-27 00:07:49 +08:00
|
|
|
kfree_skb(skb);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-09 12:29:10 +08:00
|
|
|
static void
|
|
|
|
mpc52xx_fec_rx_submit(struct net_device *dev, struct sk_buff *rskb)
|
|
|
|
{
|
|
|
|
struct mpc52xx_fec_priv *priv = netdev_priv(dev);
|
|
|
|
struct bcom_fec_bd *bd;
|
|
|
|
|
|
|
|
bd = (struct bcom_fec_bd *) bcom_prepare_next_buffer(priv->rx_dmatsk);
|
|
|
|
bd->status = FEC_RX_BUFFER_SIZE;
|
|
|
|
bd->skb_pa = dma_map_single(dev->dev.parent, rskb->data,
|
|
|
|
FEC_RX_BUFFER_SIZE, DMA_FROM_DEVICE);
|
|
|
|
bcom_submit_next_buffer(priv->rx_dmatsk, rskb);
|
|
|
|
}
|
|
|
|
|
2007-10-27 00:07:49 +08:00
|
|
|
static int mpc52xx_fec_alloc_rx_buffers(struct net_device *dev, struct bcom_task *rxtsk)
|
|
|
|
{
|
2009-12-09 12:29:10 +08:00
|
|
|
struct sk_buff *skb;
|
2007-10-27 00:07:49 +08:00
|
|
|
|
2009-12-09 12:29:10 +08:00
|
|
|
while (!bcom_queue_full(rxtsk)) {
|
2012-02-05 10:50:10 +08:00
|
|
|
skb = netdev_alloc_skb(dev, FEC_RX_BUFFER_SIZE);
|
2009-12-09 12:29:10 +08:00
|
|
|
if (!skb)
|
2007-10-27 00:07:49 +08:00
|
|
|
return -EAGAIN;
|
|
|
|
|
|
|
|
/* zero out the initial receive buffers to aid debugging */
|
|
|
|
memset(skb->data, 0, FEC_RX_BUFFER_SIZE);
|
2009-12-09 12:29:10 +08:00
|
|
|
mpc52xx_fec_rx_submit(dev, skb);
|
2007-10-27 00:07:49 +08:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* based on generic_adjust_link from fs_enet-main.c */
|
|
|
|
static void mpc52xx_fec_adjust_link(struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct mpc52xx_fec_priv *priv = netdev_priv(dev);
|
2016-05-17 06:32:33 +08:00
|
|
|
struct phy_device *phydev = dev->phydev;
|
2007-10-27 00:07:49 +08:00
|
|
|
int new_state = 0;
|
|
|
|
|
|
|
|
if (phydev->link != PHY_DOWN) {
|
|
|
|
if (phydev->duplex != priv->duplex) {
|
|
|
|
struct mpc52xx_fec __iomem *fec = priv->fec;
|
|
|
|
u32 rcntrl;
|
|
|
|
u32 tcntrl;
|
|
|
|
|
|
|
|
new_state = 1;
|
|
|
|
priv->duplex = phydev->duplex;
|
|
|
|
|
|
|
|
rcntrl = in_be32(&fec->r_cntrl);
|
|
|
|
tcntrl = in_be32(&fec->x_cntrl);
|
|
|
|
|
|
|
|
rcntrl &= ~FEC_RCNTRL_DRT;
|
|
|
|
tcntrl &= ~FEC_TCNTRL_FDEN;
|
|
|
|
if (phydev->duplex == DUPLEX_FULL)
|
|
|
|
tcntrl |= FEC_TCNTRL_FDEN; /* FD enable */
|
|
|
|
else
|
|
|
|
rcntrl |= FEC_RCNTRL_DRT; /* disable Rx on Tx (HD) */
|
|
|
|
|
|
|
|
out_be32(&fec->r_cntrl, rcntrl);
|
|
|
|
out_be32(&fec->x_cntrl, tcntrl);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (phydev->speed != priv->speed) {
|
|
|
|
new_state = 1;
|
|
|
|
priv->speed = phydev->speed;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (priv->link == PHY_DOWN) {
|
|
|
|
new_state = 1;
|
|
|
|
priv->link = phydev->link;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (priv->link) {
|
|
|
|
new_state = 1;
|
|
|
|
priv->link = PHY_DOWN;
|
|
|
|
priv->speed = 0;
|
|
|
|
priv->duplex = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (new_state && netif_msg_link(priv))
|
|
|
|
phy_print_status(phydev);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mpc52xx_fec_open(struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct mpc52xx_fec_priv *priv = netdev_priv(dev);
|
2016-05-17 06:32:33 +08:00
|
|
|
struct phy_device *phydev = NULL;
|
2007-10-27 00:07:49 +08:00
|
|
|
int err = -EBUSY;
|
|
|
|
|
2009-04-25 20:53:02 +08:00
|
|
|
if (priv->phy_node) {
|
2016-05-17 06:32:33 +08:00
|
|
|
phydev = of_phy_connect(priv->ndev, priv->phy_node,
|
|
|
|
mpc52xx_fec_adjust_link, 0, 0);
|
|
|
|
if (!phydev) {
|
2009-04-25 20:53:02 +08:00
|
|
|
dev_err(&dev->dev, "of_phy_connect failed\n");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
2016-05-17 06:32:33 +08:00
|
|
|
phy_start(phydev);
|
2009-04-25 20:53:02 +08:00
|
|
|
}
|
|
|
|
|
2009-11-19 15:29:17 +08:00
|
|
|
if (request_irq(dev->irq, mpc52xx_fec_interrupt, IRQF_SHARED,
|
2007-10-27 00:07:49 +08:00
|
|
|
DRIVER_NAME "_ctrl", dev)) {
|
|
|
|
dev_err(&dev->dev, "ctrl interrupt request failed\n");
|
2009-04-25 20:53:02 +08:00
|
|
|
goto free_phy;
|
2007-10-27 00:07:49 +08:00
|
|
|
}
|
2009-11-19 15:29:17 +08:00
|
|
|
if (request_irq(priv->r_irq, mpc52xx_fec_rx_interrupt, 0,
|
2007-10-27 00:07:49 +08:00
|
|
|
DRIVER_NAME "_rx", dev)) {
|
|
|
|
dev_err(&dev->dev, "rx interrupt request failed\n");
|
|
|
|
goto free_ctrl_irq;
|
|
|
|
}
|
2009-11-19 15:29:17 +08:00
|
|
|
if (request_irq(priv->t_irq, mpc52xx_fec_tx_interrupt, 0,
|
2007-10-27 00:07:49 +08:00
|
|
|
DRIVER_NAME "_tx", dev)) {
|
|
|
|
dev_err(&dev->dev, "tx interrupt request failed\n");
|
|
|
|
goto free_2irqs;
|
|
|
|
}
|
|
|
|
|
|
|
|
bcom_fec_rx_reset(priv->rx_dmatsk);
|
|
|
|
bcom_fec_tx_reset(priv->tx_dmatsk);
|
|
|
|
|
|
|
|
err = mpc52xx_fec_alloc_rx_buffers(dev, priv->rx_dmatsk);
|
|
|
|
if (err) {
|
|
|
|
dev_err(&dev->dev, "mpc52xx_fec_alloc_rx_buffers failed\n");
|
|
|
|
goto free_irqs;
|
|
|
|
}
|
|
|
|
|
|
|
|
bcom_enable(priv->rx_dmatsk);
|
|
|
|
bcom_enable(priv->tx_dmatsk);
|
|
|
|
|
|
|
|
mpc52xx_fec_start(dev);
|
|
|
|
|
|
|
|
netif_start_queue(dev);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
free_irqs:
|
|
|
|
free_irq(priv->t_irq, dev);
|
|
|
|
free_2irqs:
|
|
|
|
free_irq(priv->r_irq, dev);
|
|
|
|
free_ctrl_irq:
|
|
|
|
free_irq(dev->irq, dev);
|
2009-04-25 20:53:02 +08:00
|
|
|
free_phy:
|
2016-05-17 06:32:33 +08:00
|
|
|
if (phydev) {
|
|
|
|
phy_stop(phydev);
|
|
|
|
phy_disconnect(phydev);
|
2009-04-25 20:53:02 +08:00
|
|
|
}
|
2007-10-27 00:07:49 +08:00
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mpc52xx_fec_close(struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct mpc52xx_fec_priv *priv = netdev_priv(dev);
|
2016-05-17 06:32:33 +08:00
|
|
|
struct phy_device *phydev = dev->phydev;
|
2007-10-27 00:07:49 +08:00
|
|
|
|
|
|
|
netif_stop_queue(dev);
|
|
|
|
|
|
|
|
mpc52xx_fec_stop(dev);
|
|
|
|
|
|
|
|
mpc52xx_fec_free_rx_buffers(dev, priv->rx_dmatsk);
|
|
|
|
|
|
|
|
free_irq(dev->irq, dev);
|
|
|
|
free_irq(priv->r_irq, dev);
|
|
|
|
free_irq(priv->t_irq, dev);
|
|
|
|
|
2016-05-17 06:32:33 +08:00
|
|
|
if (phydev) {
|
2009-04-25 20:53:02 +08:00
|
|
|
/* power down phy */
|
2016-05-17 06:32:33 +08:00
|
|
|
phy_stop(phydev);
|
|
|
|
phy_disconnect(phydev);
|
2009-04-25 20:53:02 +08:00
|
|
|
}
|
2007-10-27 00:07:49 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This will only be invoked if your driver is _not_ in XOFF state.
|
|
|
|
* What this means is that you need not check it, and that this
|
|
|
|
* invariant will hold if you make sure that the netif_*_queue()
|
|
|
|
* calls are done at the proper times.
|
|
|
|
*/
|
2009-04-01 04:16:57 +08:00
|
|
|
static int mpc52xx_fec_start_xmit(struct sk_buff *skb, struct net_device *dev)
|
2007-10-27 00:07:49 +08:00
|
|
|
{
|
|
|
|
struct mpc52xx_fec_priv *priv = netdev_priv(dev);
|
|
|
|
struct bcom_fec_bd *bd;
|
2009-08-24 10:49:07 +08:00
|
|
|
unsigned long flags;
|
2007-10-27 00:07:49 +08:00
|
|
|
|
|
|
|
if (bcom_queue_full(priv->tx_dmatsk)) {
|
|
|
|
if (net_ratelimit())
|
|
|
|
dev_err(&dev->dev, "transmit queue overrun\n");
|
2009-04-01 04:16:57 +08:00
|
|
|
return NETDEV_TX_BUSY;
|
2007-10-27 00:07:49 +08:00
|
|
|
}
|
|
|
|
|
2009-08-24 10:49:07 +08:00
|
|
|
spin_lock_irqsave(&priv->lock, flags);
|
2007-10-27 00:07:49 +08:00
|
|
|
|
|
|
|
bd = (struct bcom_fec_bd *)
|
|
|
|
bcom_prepare_next_buffer(priv->tx_dmatsk);
|
|
|
|
|
|
|
|
bd->status = skb->len | BCOM_FEC_TX_BD_TFD | BCOM_FEC_TX_BD_TC;
|
2009-04-01 04:16:52 +08:00
|
|
|
bd->skb_pa = dma_map_single(dev->dev.parent, skb->data, skb->len,
|
|
|
|
DMA_TO_DEVICE);
|
2007-10-27 00:07:49 +08:00
|
|
|
|
2011-06-20 05:51:27 +08:00
|
|
|
skb_tx_timestamp(skb);
|
2007-10-27 00:07:49 +08:00
|
|
|
bcom_submit_next_buffer(priv->tx_dmatsk, skb);
|
2009-12-09 12:29:10 +08:00
|
|
|
spin_unlock_irqrestore(&priv->lock, flags);
|
2007-10-27 00:07:49 +08:00
|
|
|
|
|
|
|
if (bcom_queue_full(priv->tx_dmatsk)) {
|
|
|
|
netif_stop_queue(dev);
|
|
|
|
}
|
|
|
|
|
2009-04-01 04:16:57 +08:00
|
|
|
return NETDEV_TX_OK;
|
2007-10-27 00:07:49 +08:00
|
|
|
}
|
|
|
|
|
2008-10-18 19:40:59 +08:00
|
|
|
#ifdef CONFIG_NET_POLL_CONTROLLER
|
|
|
|
static void mpc52xx_fec_poll_controller(struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct mpc52xx_fec_priv *priv = netdev_priv(dev);
|
|
|
|
|
|
|
|
disable_irq(priv->t_irq);
|
|
|
|
mpc52xx_fec_tx_interrupt(priv->t_irq, dev);
|
|
|
|
enable_irq(priv->t_irq);
|
|
|
|
disable_irq(priv->r_irq);
|
|
|
|
mpc52xx_fec_rx_interrupt(priv->r_irq, dev);
|
|
|
|
enable_irq(priv->r_irq);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2007-10-27 00:07:49 +08:00
|
|
|
/* This handles BestComm transmit task interrupts
|
|
|
|
*/
|
|
|
|
static irqreturn_t mpc52xx_fec_tx_interrupt(int irq, void *dev_id)
|
|
|
|
{
|
|
|
|
struct net_device *dev = dev_id;
|
|
|
|
struct mpc52xx_fec_priv *priv = netdev_priv(dev);
|
|
|
|
|
2010-11-03 13:56:38 +08:00
|
|
|
spin_lock(&priv->lock);
|
2007-10-27 00:07:49 +08:00
|
|
|
while (bcom_buffer_done(priv->tx_dmatsk)) {
|
|
|
|
struct sk_buff *skb;
|
|
|
|
struct bcom_fec_bd *bd;
|
|
|
|
skb = bcom_retrieve_buffer(priv->tx_dmatsk, NULL,
|
|
|
|
(struct bcom_bd **)&bd);
|
2009-04-01 04:16:52 +08:00
|
|
|
dma_unmap_single(dev->dev.parent, bd->skb_pa, skb->len,
|
|
|
|
DMA_TO_DEVICE);
|
2007-10-27 00:07:49 +08:00
|
|
|
|
|
|
|
dev_kfree_skb_irq(skb);
|
|
|
|
}
|
2010-11-03 13:56:38 +08:00
|
|
|
spin_unlock(&priv->lock);
|
2007-10-27 00:07:49 +08:00
|
|
|
|
|
|
|
netif_wake_queue(dev);
|
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static irqreturn_t mpc52xx_fec_rx_interrupt(int irq, void *dev_id)
|
|
|
|
{
|
|
|
|
struct net_device *dev = dev_id;
|
|
|
|
struct mpc52xx_fec_priv *priv = netdev_priv(dev);
|
2009-12-09 12:29:10 +08:00
|
|
|
struct sk_buff *rskb; /* received sk_buff */
|
|
|
|
struct sk_buff *skb; /* new sk_buff to enqueue in its place */
|
|
|
|
struct bcom_fec_bd *bd;
|
|
|
|
u32 status, physaddr;
|
|
|
|
int length;
|
|
|
|
|
2010-11-03 13:56:38 +08:00
|
|
|
spin_lock(&priv->lock);
|
2007-10-27 00:07:49 +08:00
|
|
|
|
|
|
|
while (bcom_buffer_done(priv->rx_dmatsk)) {
|
|
|
|
|
|
|
|
rskb = bcom_retrieve_buffer(priv->rx_dmatsk, &status,
|
2009-12-09 12:29:10 +08:00
|
|
|
(struct bcom_bd **)&bd);
|
|
|
|
physaddr = bd->skb_pa;
|
2007-10-27 00:07:49 +08:00
|
|
|
|
|
|
|
/* Test for errors in received frame */
|
|
|
|
if (status & BCOM_FEC_RX_BD_ERRORS) {
|
|
|
|
/* Drop packet and reuse the buffer */
|
2009-12-09 12:29:10 +08:00
|
|
|
mpc52xx_fec_rx_submit(dev, rskb);
|
2007-10-27 00:07:49 +08:00
|
|
|
dev->stats.rx_dropped++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* skbs are allocated on open, so now we allocate a new one,
|
|
|
|
* and remove the old (with the packet) */
|
2012-02-05 10:50:10 +08:00
|
|
|
skb = netdev_alloc_skb(dev, FEC_RX_BUFFER_SIZE);
|
2009-12-09 12:29:10 +08:00
|
|
|
if (!skb) {
|
2007-10-27 00:07:49 +08:00
|
|
|
/* Can't get a new one : reuse the same & drop pkt */
|
2009-12-09 12:29:10 +08:00
|
|
|
dev_notice(&dev->dev, "Low memory - dropped packet.\n");
|
|
|
|
mpc52xx_fec_rx_submit(dev, rskb);
|
2007-10-27 00:07:49 +08:00
|
|
|
dev->stats.rx_dropped++;
|
2009-12-09 12:29:10 +08:00
|
|
|
continue;
|
2007-10-27 00:07:49 +08:00
|
|
|
}
|
|
|
|
|
2009-12-09 12:29:10 +08:00
|
|
|
/* Enqueue the new sk_buff back on the hardware */
|
|
|
|
mpc52xx_fec_rx_submit(dev, skb);
|
2007-10-27 00:07:49 +08:00
|
|
|
|
2009-12-09 12:29:10 +08:00
|
|
|
/* Process the received skb - Drop the spin lock while
|
|
|
|
* calling into the network stack */
|
2010-11-03 13:56:38 +08:00
|
|
|
spin_unlock(&priv->lock);
|
2007-10-27 00:07:49 +08:00
|
|
|
|
2009-12-09 12:29:10 +08:00
|
|
|
dma_unmap_single(dev->dev.parent, physaddr, rskb->len,
|
|
|
|
DMA_FROM_DEVICE);
|
|
|
|
length = status & BCOM_FEC_RX_BD_LEN_MASK;
|
|
|
|
skb_put(rskb, length - 4); /* length without CRC32 */
|
|
|
|
rskb->protocol = eth_type_trans(rskb, dev);
|
2012-06-02 11:04:06 +08:00
|
|
|
if (!skb_defer_rx_timestamp(rskb))
|
2011-06-20 05:51:27 +08:00
|
|
|
netif_rx(rskb);
|
2009-12-09 12:29:10 +08:00
|
|
|
|
2010-11-03 13:56:38 +08:00
|
|
|
spin_lock(&priv->lock);
|
2007-10-27 00:07:49 +08:00
|
|
|
}
|
|
|
|
|
2010-11-03 13:56:38 +08:00
|
|
|
spin_unlock(&priv->lock);
|
2009-12-09 12:29:10 +08:00
|
|
|
|
2007-10-27 00:07:49 +08:00
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static irqreturn_t mpc52xx_fec_interrupt(int irq, void *dev_id)
|
|
|
|
{
|
|
|
|
struct net_device *dev = dev_id;
|
|
|
|
struct mpc52xx_fec_priv *priv = netdev_priv(dev);
|
|
|
|
struct mpc52xx_fec __iomem *fec = priv->fec;
|
|
|
|
u32 ievent;
|
|
|
|
|
|
|
|
ievent = in_be32(&fec->ievent);
|
|
|
|
|
|
|
|
ievent &= ~FEC_IEVENT_MII; /* mii is handled separately */
|
|
|
|
if (!ievent)
|
|
|
|
return IRQ_NONE;
|
|
|
|
|
|
|
|
out_be32(&fec->ievent, ievent); /* clear pending events */
|
|
|
|
|
2008-04-15 23:44:39 +08:00
|
|
|
/* on fifo error, soft-reset fec */
|
|
|
|
if (ievent & (FEC_IEVENT_RFIFO_ERROR | FEC_IEVENT_XFIFO_ERROR)) {
|
|
|
|
|
|
|
|
if (net_ratelimit() && (ievent & FEC_IEVENT_RFIFO_ERROR))
|
|
|
|
dev_warn(&dev->dev, "FEC_IEVENT_RFIFO_ERROR\n");
|
|
|
|
if (net_ratelimit() && (ievent & FEC_IEVENT_XFIFO_ERROR))
|
|
|
|
dev_warn(&dev->dev, "FEC_IEVENT_XFIFO_ERROR\n");
|
|
|
|
|
2010-11-03 13:56:38 +08:00
|
|
|
spin_lock(&priv->lock);
|
2008-04-15 23:44:39 +08:00
|
|
|
mpc52xx_fec_reset(dev);
|
2010-11-03 13:56:38 +08:00
|
|
|
spin_unlock(&priv->lock);
|
2008-04-15 23:44:39 +08:00
|
|
|
|
2007-10-27 00:07:49 +08:00
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
2008-04-15 23:44:39 +08:00
|
|
|
if (ievent & ~FEC_IEVENT_TFINT)
|
|
|
|
dev_dbg(&dev->dev, "ievent: %08x\n", ievent);
|
2007-10-27 00:07:49 +08:00
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the current statistics.
|
|
|
|
* This may be called with the card open or closed.
|
|
|
|
*/
|
|
|
|
static struct net_device_stats *mpc52xx_fec_get_stats(struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct mpc52xx_fec_priv *priv = netdev_priv(dev);
|
|
|
|
struct net_device_stats *stats = &dev->stats;
|
|
|
|
struct mpc52xx_fec __iomem *fec = priv->fec;
|
|
|
|
|
|
|
|
stats->rx_bytes = in_be32(&fec->rmon_r_octets);
|
|
|
|
stats->rx_packets = in_be32(&fec->rmon_r_packets);
|
|
|
|
stats->rx_errors = in_be32(&fec->rmon_r_crc_align) +
|
|
|
|
in_be32(&fec->rmon_r_undersize) +
|
|
|
|
in_be32(&fec->rmon_r_oversize) +
|
|
|
|
in_be32(&fec->rmon_r_frag) +
|
|
|
|
in_be32(&fec->rmon_r_jab);
|
|
|
|
|
|
|
|
stats->tx_bytes = in_be32(&fec->rmon_t_octets);
|
|
|
|
stats->tx_packets = in_be32(&fec->rmon_t_packets);
|
|
|
|
stats->tx_errors = in_be32(&fec->rmon_t_crc_align) +
|
|
|
|
in_be32(&fec->rmon_t_undersize) +
|
|
|
|
in_be32(&fec->rmon_t_oversize) +
|
|
|
|
in_be32(&fec->rmon_t_frag) +
|
|
|
|
in_be32(&fec->rmon_t_jab);
|
|
|
|
|
|
|
|
stats->multicast = in_be32(&fec->rmon_r_mc_pkt);
|
|
|
|
stats->collisions = in_be32(&fec->rmon_t_col);
|
|
|
|
|
|
|
|
/* detailed rx_errors: */
|
|
|
|
stats->rx_length_errors = in_be32(&fec->rmon_r_undersize)
|
|
|
|
+ in_be32(&fec->rmon_r_oversize)
|
|
|
|
+ in_be32(&fec->rmon_r_frag)
|
|
|
|
+ in_be32(&fec->rmon_r_jab);
|
|
|
|
stats->rx_over_errors = in_be32(&fec->r_macerr);
|
|
|
|
stats->rx_crc_errors = in_be32(&fec->ieee_r_crc);
|
|
|
|
stats->rx_frame_errors = in_be32(&fec->ieee_r_align);
|
|
|
|
stats->rx_fifo_errors = in_be32(&fec->rmon_r_drop);
|
|
|
|
stats->rx_missed_errors = in_be32(&fec->rmon_r_drop);
|
|
|
|
|
|
|
|
/* detailed tx_errors: */
|
|
|
|
stats->tx_aborted_errors = 0;
|
|
|
|
stats->tx_carrier_errors = in_be32(&fec->ieee_t_cserr);
|
|
|
|
stats->tx_fifo_errors = in_be32(&fec->rmon_t_drop);
|
|
|
|
stats->tx_heartbeat_errors = in_be32(&fec->ieee_t_sqe);
|
|
|
|
stats->tx_window_errors = in_be32(&fec->ieee_t_lcol);
|
|
|
|
|
|
|
|
return stats;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read MIB counters in order to reset them,
|
|
|
|
* then zero all the stats fields in memory
|
|
|
|
*/
|
|
|
|
static void mpc52xx_fec_reset_stats(struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct mpc52xx_fec_priv *priv = netdev_priv(dev);
|
|
|
|
struct mpc52xx_fec __iomem *fec = priv->fec;
|
|
|
|
|
|
|
|
out_be32(&fec->mib_control, FEC_MIB_DISABLE);
|
2007-12-23 02:56:53 +08:00
|
|
|
memset_io(&fec->rmon_t_drop, 0,
|
|
|
|
offsetof(struct mpc52xx_fec, reserved10) -
|
|
|
|
offsetof(struct mpc52xx_fec, rmon_t_drop));
|
2007-10-27 00:07:49 +08:00
|
|
|
out_be32(&fec->mib_control, 0);
|
|
|
|
|
|
|
|
memset(&dev->stats, 0, sizeof(dev->stats));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set or clear the multicast filter for this adaptor.
|
|
|
|
*/
|
|
|
|
static void mpc52xx_fec_set_multicast_list(struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct mpc52xx_fec_priv *priv = netdev_priv(dev);
|
|
|
|
struct mpc52xx_fec __iomem *fec = priv->fec;
|
|
|
|
u32 rx_control;
|
|
|
|
|
|
|
|
rx_control = in_be32(&fec->r_cntrl);
|
|
|
|
|
|
|
|
if (dev->flags & IFF_PROMISC) {
|
|
|
|
rx_control |= FEC_RCNTRL_PROM;
|
|
|
|
out_be32(&fec->r_cntrl, rx_control);
|
|
|
|
} else {
|
|
|
|
rx_control &= ~FEC_RCNTRL_PROM;
|
|
|
|
out_be32(&fec->r_cntrl, rx_control);
|
|
|
|
|
|
|
|
if (dev->flags & IFF_ALLMULTI) {
|
|
|
|
out_be32(&fec->gaddr1, 0xffffffff);
|
|
|
|
out_be32(&fec->gaddr2, 0xffffffff);
|
|
|
|
} else {
|
|
|
|
u32 crc;
|
2010-04-02 05:22:57 +08:00
|
|
|
struct netdev_hw_addr *ha;
|
2007-10-27 00:07:49 +08:00
|
|
|
u32 gaddr1 = 0x00000000;
|
|
|
|
u32 gaddr2 = 0x00000000;
|
|
|
|
|
2010-04-02 05:22:57 +08:00
|
|
|
netdev_for_each_mc_addr(ha, dev) {
|
|
|
|
crc = ether_crc_le(6, ha->addr) >> 26;
|
2007-10-27 00:07:49 +08:00
|
|
|
if (crc >= 32)
|
|
|
|
gaddr1 |= 1 << (crc-32);
|
|
|
|
else
|
|
|
|
gaddr2 |= 1 << crc;
|
|
|
|
}
|
|
|
|
out_be32(&fec->gaddr1, gaddr1);
|
|
|
|
out_be32(&fec->gaddr2, gaddr2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* mpc52xx_fec_hw_init
|
|
|
|
* @dev: network device
|
|
|
|
*
|
|
|
|
* Setup various hardware setting, only needed once on start
|
|
|
|
*/
|
|
|
|
static void mpc52xx_fec_hw_init(struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct mpc52xx_fec_priv *priv = netdev_priv(dev);
|
|
|
|
struct mpc52xx_fec __iomem *fec = priv->fec;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Whack a reset. We should wait for this. */
|
|
|
|
out_be32(&fec->ecntrl, FEC_ECNTRL_RESET);
|
|
|
|
for (i = 0; i < FEC_RESET_DELAY; ++i) {
|
|
|
|
if ((in_be32(&fec->ecntrl) & FEC_ECNTRL_RESET) == 0)
|
|
|
|
break;
|
|
|
|
udelay(1);
|
|
|
|
}
|
|
|
|
if (i == FEC_RESET_DELAY)
|
|
|
|
dev_err(&dev->dev, "FEC Reset timeout!\n");
|
|
|
|
|
|
|
|
/* set pause to 0x20 frames */
|
|
|
|
out_be32(&fec->op_pause, FEC_OP_PAUSE_OPCODE | 0x20);
|
|
|
|
|
|
|
|
/* high service request will be deasserted when there's < 7 bytes in fifo
|
|
|
|
* low service request will be deasserted when there's < 4*7 bytes in fifo
|
|
|
|
*/
|
|
|
|
out_be32(&fec->rfifo_cntrl, FEC_FIFO_CNTRL_FRAME | FEC_FIFO_CNTRL_LTG_7);
|
|
|
|
out_be32(&fec->tfifo_cntrl, FEC_FIFO_CNTRL_FRAME | FEC_FIFO_CNTRL_LTG_7);
|
|
|
|
|
|
|
|
/* alarm when <= x bytes in FIFO */
|
|
|
|
out_be32(&fec->rfifo_alarm, 0x0000030c);
|
|
|
|
out_be32(&fec->tfifo_alarm, 0x00000100);
|
|
|
|
|
|
|
|
/* begin transmittion when 256 bytes are in FIFO (or EOF or FIFO full) */
|
|
|
|
out_be32(&fec->x_wmrk, FEC_FIFO_WMRK_256B);
|
|
|
|
|
|
|
|
/* enable crc generation */
|
|
|
|
out_be32(&fec->xmit_fsm, FEC_XMIT_FSM_APPEND_CRC | FEC_XMIT_FSM_ENABLE_CRC);
|
|
|
|
out_be32(&fec->iaddr1, 0x00000000); /* No individual filter */
|
|
|
|
out_be32(&fec->iaddr2, 0x00000000); /* No individual filter */
|
|
|
|
|
|
|
|
/* set phy speed.
|
|
|
|
* this can't be done in phy driver, since it needs to be called
|
|
|
|
* before fec stuff (even on resume) */
|
2009-04-25 20:53:02 +08:00
|
|
|
out_be32(&fec->mii_speed, priv->mdio_speed);
|
2007-10-27 00:07:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* mpc52xx_fec_start
|
|
|
|
* @dev: network device
|
|
|
|
*
|
|
|
|
* This function is called to start or restart the FEC during a link
|
|
|
|
* change. This happens on fifo errors or when switching between half
|
|
|
|
* and full duplex.
|
|
|
|
*/
|
|
|
|
static void mpc52xx_fec_start(struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct mpc52xx_fec_priv *priv = netdev_priv(dev);
|
|
|
|
struct mpc52xx_fec __iomem *fec = priv->fec;
|
|
|
|
u32 rcntrl;
|
|
|
|
u32 tcntrl;
|
|
|
|
u32 tmp;
|
|
|
|
|
|
|
|
/* clear sticky error bits */
|
|
|
|
tmp = FEC_FIFO_STATUS_ERR | FEC_FIFO_STATUS_UF | FEC_FIFO_STATUS_OF;
|
|
|
|
out_be32(&fec->rfifo_status, in_be32(&fec->rfifo_status) & tmp);
|
|
|
|
out_be32(&fec->tfifo_status, in_be32(&fec->tfifo_status) & tmp);
|
|
|
|
|
|
|
|
/* FIFOs will reset on mpc52xx_fec_enable */
|
|
|
|
out_be32(&fec->reset_cntrl, FEC_RESET_CNTRL_ENABLE_IS_RESET);
|
|
|
|
|
|
|
|
/* Set station address. */
|
|
|
|
mpc52xx_fec_set_paddr(dev, dev->dev_addr);
|
|
|
|
|
|
|
|
mpc52xx_fec_set_multicast_list(dev);
|
|
|
|
|
|
|
|
/* set max frame len, enable flow control, select mii mode */
|
|
|
|
rcntrl = FEC_RX_BUFFER_SIZE << 16; /* max frame length */
|
|
|
|
rcntrl |= FEC_RCNTRL_FCE;
|
|
|
|
|
2009-04-25 20:53:02 +08:00
|
|
|
if (!priv->seven_wire_mode)
|
2007-10-27 00:07:49 +08:00
|
|
|
rcntrl |= FEC_RCNTRL_MII_MODE;
|
|
|
|
|
|
|
|
if (priv->duplex == DUPLEX_FULL)
|
|
|
|
tcntrl = FEC_TCNTRL_FDEN; /* FD enable */
|
|
|
|
else {
|
|
|
|
rcntrl |= FEC_RCNTRL_DRT; /* disable Rx on Tx (HD) */
|
|
|
|
tcntrl = 0;
|
|
|
|
}
|
|
|
|
out_be32(&fec->r_cntrl, rcntrl);
|
|
|
|
out_be32(&fec->x_cntrl, tcntrl);
|
|
|
|
|
|
|
|
/* Clear any outstanding interrupt. */
|
|
|
|
out_be32(&fec->ievent, 0xffffffff);
|
|
|
|
|
|
|
|
/* Enable interrupts we wish to service. */
|
|
|
|
out_be32(&fec->imask, FEC_IMASK_ENABLE);
|
|
|
|
|
|
|
|
/* And last, enable the transmit and receive processing. */
|
|
|
|
out_be32(&fec->ecntrl, FEC_ECNTRL_ETHER_EN);
|
|
|
|
out_be32(&fec->r_des_active, 0x01000000);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* mpc52xx_fec_stop
|
|
|
|
* @dev: network device
|
|
|
|
*
|
|
|
|
* stop all activity on fec and empty dma buffers
|
|
|
|
*/
|
|
|
|
static void mpc52xx_fec_stop(struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct mpc52xx_fec_priv *priv = netdev_priv(dev);
|
|
|
|
struct mpc52xx_fec __iomem *fec = priv->fec;
|
|
|
|
unsigned long timeout;
|
|
|
|
|
|
|
|
/* disable all interrupts */
|
|
|
|
out_be32(&fec->imask, 0);
|
|
|
|
|
|
|
|
/* Disable the rx task. */
|
|
|
|
bcom_disable(priv->rx_dmatsk);
|
|
|
|
|
|
|
|
/* Wait for tx queue to drain, but only if we're in process context */
|
|
|
|
if (!in_interrupt()) {
|
|
|
|
timeout = jiffies + msecs_to_jiffies(2000);
|
|
|
|
while (time_before(jiffies, timeout) &&
|
|
|
|
!bcom_queue_empty(priv->tx_dmatsk))
|
|
|
|
msleep(100);
|
|
|
|
|
|
|
|
if (time_after_eq(jiffies, timeout))
|
|
|
|
dev_err(&dev->dev, "queues didn't drain\n");
|
|
|
|
#if 1
|
|
|
|
if (time_after_eq(jiffies, timeout)) {
|
|
|
|
dev_err(&dev->dev, " tx: index: %i, outdex: %i\n",
|
|
|
|
priv->tx_dmatsk->index,
|
|
|
|
priv->tx_dmatsk->outdex);
|
|
|
|
dev_err(&dev->dev, " rx: index: %i, outdex: %i\n",
|
|
|
|
priv->rx_dmatsk->index,
|
|
|
|
priv->rx_dmatsk->outdex);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
bcom_disable(priv->tx_dmatsk);
|
|
|
|
|
|
|
|
/* Stop FEC */
|
|
|
|
out_be32(&fec->ecntrl, in_be32(&fec->ecntrl) & ~FEC_ECNTRL_ETHER_EN);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* reset fec and bestcomm tasks */
|
|
|
|
static void mpc52xx_fec_reset(struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct mpc52xx_fec_priv *priv = netdev_priv(dev);
|
|
|
|
struct mpc52xx_fec __iomem *fec = priv->fec;
|
|
|
|
|
|
|
|
mpc52xx_fec_stop(dev);
|
|
|
|
|
|
|
|
out_be32(&fec->rfifo_status, in_be32(&fec->rfifo_status));
|
|
|
|
out_be32(&fec->reset_cntrl, FEC_RESET_CNTRL_RESET_FIFO);
|
|
|
|
|
|
|
|
mpc52xx_fec_free_rx_buffers(dev, priv->rx_dmatsk);
|
|
|
|
|
|
|
|
mpc52xx_fec_hw_init(dev);
|
|
|
|
|
|
|
|
bcom_fec_rx_reset(priv->rx_dmatsk);
|
|
|
|
bcom_fec_tx_reset(priv->tx_dmatsk);
|
|
|
|
|
|
|
|
mpc52xx_fec_alloc_rx_buffers(dev, priv->rx_dmatsk);
|
|
|
|
|
|
|
|
bcom_enable(priv->rx_dmatsk);
|
|
|
|
bcom_enable(priv->tx_dmatsk);
|
|
|
|
|
|
|
|
mpc52xx_fec_start(dev);
|
2009-12-09 12:29:10 +08:00
|
|
|
|
|
|
|
netif_wake_queue(dev);
|
2007-10-27 00:07:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* ethtool interface */
|
|
|
|
|
|
|
|
static u32 mpc52xx_fec_get_msglevel(struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct mpc52xx_fec_priv *priv = netdev_priv(dev);
|
|
|
|
return priv->msg_enable;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mpc52xx_fec_set_msglevel(struct net_device *dev, u32 level)
|
|
|
|
{
|
|
|
|
struct mpc52xx_fec_priv *priv = netdev_priv(dev);
|
|
|
|
priv->msg_enable = level;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct ethtool_ops mpc52xx_fec_ethtool_ops = {
|
|
|
|
.get_link = ethtool_op_get_link,
|
|
|
|
.get_msglevel = mpc52xx_fec_get_msglevel,
|
|
|
|
.set_msglevel = mpc52xx_fec_set_msglevel,
|
2012-04-04 06:59:27 +08:00
|
|
|
.get_ts_info = ethtool_op_get_ts_info,
|
2016-05-17 06:32:34 +08:00
|
|
|
.get_link_ksettings = phy_ethtool_get_link_ksettings,
|
|
|
|
.set_link_ksettings = phy_ethtool_set_link_ksettings,
|
2007-10-27 00:07:49 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static int mpc52xx_fec_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
|
|
|
|
{
|
2016-05-17 06:32:33 +08:00
|
|
|
struct phy_device *phydev = dev->phydev;
|
2007-10-27 00:07:49 +08:00
|
|
|
|
2016-05-17 06:32:33 +08:00
|
|
|
if (!phydev)
|
2009-04-01 04:17:03 +08:00
|
|
|
return -ENOTSUPP;
|
|
|
|
|
2016-05-17 06:32:33 +08:00
|
|
|
return phy_mii_ioctl(phydev, rq, cmd);
|
2007-10-27 00:07:49 +08:00
|
|
|
}
|
|
|
|
|
2009-04-01 04:16:57 +08:00
|
|
|
static const struct net_device_ops mpc52xx_fec_netdev_ops = {
|
|
|
|
.ndo_open = mpc52xx_fec_open,
|
|
|
|
.ndo_stop = mpc52xx_fec_close,
|
|
|
|
.ndo_start_xmit = mpc52xx_fec_start_xmit,
|
2011-08-16 14:29:01 +08:00
|
|
|
.ndo_set_rx_mode = mpc52xx_fec_set_multicast_list,
|
2009-04-01 04:16:57 +08:00
|
|
|
.ndo_set_mac_address = mpc52xx_fec_set_mac_address,
|
|
|
|
.ndo_validate_addr = eth_validate_addr,
|
|
|
|
.ndo_do_ioctl = mpc52xx_fec_ioctl,
|
|
|
|
.ndo_tx_timeout = mpc52xx_fec_tx_timeout,
|
|
|
|
.ndo_get_stats = mpc52xx_fec_get_stats,
|
|
|
|
#ifdef CONFIG_NET_POLL_CONTROLLER
|
|
|
|
.ndo_poll_controller = mpc52xx_fec_poll_controller,
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2007-10-27 00:07:49 +08:00
|
|
|
/* ======================================================================== */
|
|
|
|
/* OF Driver */
|
|
|
|
/* ======================================================================== */
|
|
|
|
|
2012-12-03 22:23:58 +08:00
|
|
|
static int mpc52xx_fec_probe(struct platform_device *op)
|
2007-10-27 00:07:49 +08:00
|
|
|
{
|
|
|
|
int rv;
|
|
|
|
struct net_device *ndev;
|
|
|
|
struct mpc52xx_fec_priv *priv = NULL;
|
|
|
|
struct resource mem;
|
2008-05-02 01:05:58 +08:00
|
|
|
const u32 *prop;
|
|
|
|
int prop_size;
|
2013-02-12 11:05:38 +08:00
|
|
|
struct device_node *np = op->dev.of_node;
|
|
|
|
const char *mac_addr;
|
2007-10-27 00:07:49 +08:00
|
|
|
|
|
|
|
phys_addr_t rx_fifo;
|
|
|
|
phys_addr_t tx_fifo;
|
|
|
|
|
|
|
|
/* Get the ether ndev & it's private zone */
|
|
|
|
ndev = alloc_etherdev(sizeof(struct mpc52xx_fec_priv));
|
|
|
|
if (!ndev)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
priv = netdev_priv(ndev);
|
2009-04-25 20:53:02 +08:00
|
|
|
priv->ndev = ndev;
|
2007-10-27 00:07:49 +08:00
|
|
|
|
|
|
|
/* Reserve FEC control zone */
|
2013-02-12 11:05:38 +08:00
|
|
|
rv = of_address_to_resource(np, 0, &mem);
|
2007-10-27 00:07:49 +08:00
|
|
|
if (rv) {
|
2013-04-14 03:03:17 +08:00
|
|
|
pr_err("Error while parsing device node resource\n");
|
2010-07-09 14:44:26 +08:00
|
|
|
goto err_netdev;
|
2007-10-27 00:07:49 +08:00
|
|
|
}
|
2011-06-10 00:13:32 +08:00
|
|
|
if (resource_size(&mem) < sizeof(struct mpc52xx_fec)) {
|
2013-04-14 03:03:17 +08:00
|
|
|
pr_err("invalid resource size (%lx < %x), check mpc52xx_devices.c\n",
|
2011-06-10 00:13:32 +08:00
|
|
|
(unsigned long)resource_size(&mem),
|
|
|
|
sizeof(struct mpc52xx_fec));
|
2010-07-09 14:44:26 +08:00
|
|
|
rv = -EINVAL;
|
|
|
|
goto err_netdev;
|
2007-10-27 00:07:49 +08:00
|
|
|
}
|
|
|
|
|
2010-07-09 14:44:26 +08:00
|
|
|
if (!request_mem_region(mem.start, sizeof(struct mpc52xx_fec),
|
|
|
|
DRIVER_NAME)) {
|
|
|
|
rv = -EBUSY;
|
|
|
|
goto err_netdev;
|
|
|
|
}
|
2007-10-27 00:07:49 +08:00
|
|
|
|
|
|
|
/* Init ether ndev with what we have */
|
2009-04-01 04:16:57 +08:00
|
|
|
ndev->netdev_ops = &mpc52xx_fec_netdev_ops;
|
2007-10-27 00:07:49 +08:00
|
|
|
ndev->ethtool_ops = &mpc52xx_fec_ethtool_ops;
|
|
|
|
ndev->watchdog_timeo = FEC_WATCHDOG_TIMEOUT;
|
|
|
|
ndev->base_addr = mem.start;
|
2009-04-25 20:53:02 +08:00
|
|
|
SET_NETDEV_DEV(ndev, &op->dev);
|
2007-10-27 00:07:49 +08:00
|
|
|
|
|
|
|
spin_lock_init(&priv->lock);
|
|
|
|
|
|
|
|
/* ioremap the zones */
|
|
|
|
priv->fec = ioremap(mem.start, sizeof(struct mpc52xx_fec));
|
|
|
|
|
|
|
|
if (!priv->fec) {
|
|
|
|
rv = -ENOMEM;
|
2010-07-09 14:44:26 +08:00
|
|
|
goto err_mem_region;
|
2007-10-27 00:07:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Bestcomm init */
|
|
|
|
rx_fifo = ndev->base_addr + offsetof(struct mpc52xx_fec, rfifo_data);
|
|
|
|
tx_fifo = ndev->base_addr + offsetof(struct mpc52xx_fec, tfifo_data);
|
|
|
|
|
|
|
|
priv->rx_dmatsk = bcom_fec_rx_init(FEC_RX_NUM_BD, rx_fifo, FEC_RX_BUFFER_SIZE);
|
|
|
|
priv->tx_dmatsk = bcom_fec_tx_init(FEC_TX_NUM_BD, tx_fifo);
|
|
|
|
|
|
|
|
if (!priv->rx_dmatsk || !priv->tx_dmatsk) {
|
2013-04-14 03:03:17 +08:00
|
|
|
pr_err("Can not init SDMA tasks\n");
|
2007-10-27 00:07:49 +08:00
|
|
|
rv = -ENOMEM;
|
2010-07-09 14:44:26 +08:00
|
|
|
goto err_rx_tx_dmatsk;
|
2007-10-27 00:07:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the IRQ we need one by one */
|
|
|
|
/* Control */
|
2013-02-12 11:05:38 +08:00
|
|
|
ndev->irq = irq_of_parse_and_map(np, 0);
|
2007-10-27 00:07:49 +08:00
|
|
|
|
|
|
|
/* RX */
|
|
|
|
priv->r_irq = bcom_get_task_irq(priv->rx_dmatsk);
|
|
|
|
|
|
|
|
/* TX */
|
|
|
|
priv->t_irq = bcom_get_task_irq(priv->tx_dmatsk);
|
|
|
|
|
2013-02-12 11:05:38 +08:00
|
|
|
/*
|
|
|
|
* MAC address init:
|
|
|
|
*
|
|
|
|
* First try to read MAC address from DT
|
|
|
|
*/
|
|
|
|
mac_addr = of_get_mac_address(np);
|
|
|
|
if (mac_addr) {
|
|
|
|
memcpy(ndev->dev_addr, mac_addr, ETH_ALEN);
|
|
|
|
} else {
|
|
|
|
struct mpc52xx_fec __iomem *fec = priv->fec;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the MAC addresse is not provided via DT then read
|
|
|
|
* it back from the controller regs
|
|
|
|
*/
|
|
|
|
*(u32 *)(&ndev->dev_addr[0]) = in_be32(&fec->paddr1);
|
|
|
|
*(u16 *)(&ndev->dev_addr[4]) = in_be32(&fec->paddr2) >> 16;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check if the MAC address is valid, if not get a random one
|
|
|
|
*/
|
|
|
|
if (!is_valid_ether_addr(ndev->dev_addr)) {
|
|
|
|
eth_hw_addr_random(ndev);
|
|
|
|
dev_warn(&ndev->dev, "using random MAC address %pM\n",
|
|
|
|
ndev->dev_addr);
|
|
|
|
}
|
2007-10-27 00:07:49 +08:00
|
|
|
|
|
|
|
priv->msg_enable = netif_msg_init(debug, MPC52xx_MESSAGES_DEFAULT);
|
|
|
|
|
2008-05-02 01:05:58 +08:00
|
|
|
/*
|
|
|
|
* Link mode configuration
|
|
|
|
*/
|
2007-10-27 00:07:49 +08:00
|
|
|
|
2008-05-02 01:05:58 +08:00
|
|
|
/* Start with safe defaults for link connection */
|
|
|
|
priv->speed = 100;
|
|
|
|
priv->duplex = DUPLEX_HALF;
|
2013-02-12 11:05:38 +08:00
|
|
|
priv->mdio_speed = ((mpc5xxx_get_bus_frequency(np) >> 20) / 5) << 1;
|
2008-05-02 01:05:58 +08:00
|
|
|
|
|
|
|
/* The current speed preconfigures the speed of the MII link */
|
2013-02-12 11:05:38 +08:00
|
|
|
prop = of_get_property(np, "current-speed", &prop_size);
|
2008-05-02 01:05:58 +08:00
|
|
|
if (prop && (prop_size >= sizeof(u32) * 2)) {
|
|
|
|
priv->speed = prop[0];
|
|
|
|
priv->duplex = prop[1] ? DUPLEX_FULL : DUPLEX_HALF;
|
|
|
|
}
|
2007-10-27 00:07:49 +08:00
|
|
|
|
2009-04-25 20:53:02 +08:00
|
|
|
/* If there is a phy handle, then get the PHY node */
|
2013-02-12 11:05:38 +08:00
|
|
|
priv->phy_node = of_parse_phandle(np, "phy-handle", 0);
|
2009-04-25 20:53:02 +08:00
|
|
|
|
|
|
|
/* the 7-wire property means don't use MII mode */
|
2013-02-12 11:05:38 +08:00
|
|
|
if (of_find_property(np, "fsl,7-wire-mode", NULL)) {
|
2009-04-25 20:53:02 +08:00
|
|
|
priv->seven_wire_mode = 1;
|
|
|
|
dev_info(&ndev->dev, "using 7-wire PHY mode\n");
|
2007-10-27 00:07:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Hardware init */
|
|
|
|
mpc52xx_fec_hw_init(ndev);
|
|
|
|
mpc52xx_fec_reset_stats(ndev);
|
|
|
|
|
|
|
|
rv = register_netdev(ndev);
|
|
|
|
if (rv < 0)
|
2010-07-09 14:44:26 +08:00
|
|
|
goto err_node;
|
2007-10-27 00:07:49 +08:00
|
|
|
|
|
|
|
/* We're done ! */
|
2013-05-23 08:52:31 +08:00
|
|
|
platform_set_drvdata(op, ndev);
|
2013-04-14 03:03:17 +08:00
|
|
|
netdev_info(ndev, "%s MAC %pM\n",
|
|
|
|
op->dev.of_node->full_name, ndev->dev_addr);
|
2007-10-27 00:07:49 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
2010-07-09 14:44:26 +08:00
|
|
|
err_node:
|
|
|
|
of_node_put(priv->phy_node);
|
2007-10-27 00:07:49 +08:00
|
|
|
irq_dispose_mapping(ndev->irq);
|
2010-07-09 14:44:26 +08:00
|
|
|
err_rx_tx_dmatsk:
|
2007-10-27 00:07:49 +08:00
|
|
|
if (priv->rx_dmatsk)
|
|
|
|
bcom_fec_rx_release(priv->rx_dmatsk);
|
|
|
|
if (priv->tx_dmatsk)
|
|
|
|
bcom_fec_tx_release(priv->tx_dmatsk);
|
2010-07-09 14:44:26 +08:00
|
|
|
iounmap(priv->fec);
|
|
|
|
err_mem_region:
|
2007-10-27 00:07:49 +08:00
|
|
|
release_mem_region(mem.start, sizeof(struct mpc52xx_fec));
|
2010-07-09 14:44:26 +08:00
|
|
|
err_netdev:
|
2007-10-27 00:07:49 +08:00
|
|
|
free_netdev(ndev);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2010-08-06 23:25:50 +08:00
|
|
|
mpc52xx_fec_remove(struct platform_device *op)
|
2007-10-27 00:07:49 +08:00
|
|
|
{
|
|
|
|
struct net_device *ndev;
|
|
|
|
struct mpc52xx_fec_priv *priv;
|
|
|
|
|
2013-05-23 08:52:31 +08:00
|
|
|
ndev = platform_get_drvdata(op);
|
2007-10-27 00:07:49 +08:00
|
|
|
priv = netdev_priv(ndev);
|
|
|
|
|
|
|
|
unregister_netdev(ndev);
|
|
|
|
|
2014-08-08 18:07:54 +08:00
|
|
|
of_node_put(priv->phy_node);
|
2009-04-25 20:53:02 +08:00
|
|
|
priv->phy_node = NULL;
|
|
|
|
|
2007-10-27 00:07:49 +08:00
|
|
|
irq_dispose_mapping(ndev->irq);
|
|
|
|
|
|
|
|
bcom_fec_rx_release(priv->rx_dmatsk);
|
|
|
|
bcom_fec_tx_release(priv->tx_dmatsk);
|
|
|
|
|
|
|
|
iounmap(priv->fec);
|
|
|
|
|
|
|
|
release_mem_region(ndev->base_addr, sizeof(struct mpc52xx_fec));
|
|
|
|
|
|
|
|
free_netdev(ndev);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_PM
|
2010-08-06 23:25:50 +08:00
|
|
|
static int mpc52xx_fec_of_suspend(struct platform_device *op, pm_message_t state)
|
2007-10-27 00:07:49 +08:00
|
|
|
{
|
2013-05-23 08:52:31 +08:00
|
|
|
struct net_device *dev = platform_get_drvdata(op);
|
2007-10-27 00:07:49 +08:00
|
|
|
|
|
|
|
if (netif_running(dev))
|
|
|
|
mpc52xx_fec_close(dev);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-08-06 23:25:50 +08:00
|
|
|
static int mpc52xx_fec_of_resume(struct platform_device *op)
|
2007-10-27 00:07:49 +08:00
|
|
|
{
|
2013-05-23 08:52:31 +08:00
|
|
|
struct net_device *dev = platform_get_drvdata(op);
|
2007-10-27 00:07:49 +08:00
|
|
|
|
|
|
|
mpc52xx_fec_hw_init(dev);
|
|
|
|
mpc52xx_fec_reset_stats(dev);
|
|
|
|
|
|
|
|
if (netif_running(dev))
|
|
|
|
mpc52xx_fec_open(dev);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-03-18 02:37:34 +08:00
|
|
|
static const struct of_device_id mpc52xx_fec_match[] = {
|
2009-02-04 03:30:25 +08:00
|
|
|
{ .compatible = "fsl,mpc5200b-fec", },
|
|
|
|
{ .compatible = "fsl,mpc5200-fec", },
|
|
|
|
{ .compatible = "mpc5200-fec", },
|
2007-10-27 00:07:49 +08:00
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
MODULE_DEVICE_TABLE(of, mpc52xx_fec_match);
|
|
|
|
|
2011-02-23 12:05:51 +08:00
|
|
|
static struct platform_driver mpc52xx_fec_driver = {
|
2010-04-14 07:13:02 +08:00
|
|
|
.driver = {
|
|
|
|
.name = DRIVER_NAME,
|
|
|
|
.of_match_table = mpc52xx_fec_match,
|
|
|
|
},
|
2007-10-27 00:07:49 +08:00
|
|
|
.probe = mpc52xx_fec_probe,
|
|
|
|
.remove = mpc52xx_fec_remove,
|
|
|
|
#ifdef CONFIG_PM
|
|
|
|
.suspend = mpc52xx_fec_of_suspend,
|
|
|
|
.resume = mpc52xx_fec_of_resume,
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* ======================================================================== */
|
|
|
|
/* Module */
|
|
|
|
/* ======================================================================== */
|
|
|
|
|
2015-12-03 00:30:28 +08:00
|
|
|
static struct platform_driver * const drivers[] = {
|
|
|
|
#ifdef CONFIG_FEC_MPC52xx_MDIO
|
|
|
|
&mpc52xx_fec_mdio_driver,
|
|
|
|
#endif
|
|
|
|
&mpc52xx_fec_driver,
|
|
|
|
};
|
|
|
|
|
2007-10-27 00:07:49 +08:00
|
|
|
static int __init
|
|
|
|
mpc52xx_fec_init(void)
|
|
|
|
{
|
2015-12-03 00:30:28 +08:00
|
|
|
return platform_register_drivers(drivers, ARRAY_SIZE(drivers));
|
2007-10-27 00:07:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit
|
|
|
|
mpc52xx_fec_exit(void)
|
|
|
|
{
|
2015-12-03 00:30:28 +08:00
|
|
|
platform_unregister_drivers(drivers, ARRAY_SIZE(drivers));
|
2007-10-27 00:07:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
module_init(mpc52xx_fec_init);
|
|
|
|
module_exit(mpc52xx_fec_exit);
|
|
|
|
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_AUTHOR("Dale Farnsworth");
|
|
|
|
MODULE_DESCRIPTION("Ethernet driver for the Freescale MPC52xx FEC");
|