2019-05-27 14:55:01 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2012-06-05 11:42:12 +08:00
|
|
|
/* drivers/net/ethernet/freescale/gianfar.c
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
|
|
|
* Gianfar Ethernet Driver
|
2005-11-12 02:38:59 +08:00
|
|
|
* This driver is designed for the non-CPM ethernet controllers
|
|
|
|
* on the 85xx and 83xx family of integrated processors
|
2005-04-17 06:20:36 +08:00
|
|
|
* Based on 8260_io/fcc_enet.c
|
|
|
|
*
|
|
|
|
* Author: Andy Fleming
|
2005-11-14 08:06:30 +08:00
|
|
|
* Maintainer: Kumar Gala
|
2009-11-02 15:03:00 +08:00
|
|
|
* Modifier: Sandeep Gopalpet <sandeep.kumar@freescale.com>
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
2014-02-17 18:53:14 +08:00
|
|
|
* Copyright 2002-2009, 2011-2013 Freescale Semiconductor, Inc.
|
2009-11-02 15:03:00 +08:00
|
|
|
* Copyright 2007 MontaVista Software, Inc.
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
|
|
|
* Gianfar: AKA Lambda Draconis, "Dragon"
|
|
|
|
* RA 11 31 24.2
|
|
|
|
* Dec +69 19 52
|
|
|
|
* V 3.84
|
|
|
|
* B-V +1.62
|
|
|
|
*
|
|
|
|
* Theory of operation
|
2005-06-20 23:54:21 +08:00
|
|
|
*
|
2008-12-17 07:29:15 +08:00
|
|
|
* The driver is initialized through of_device. Configuration information
|
|
|
|
* is therefore conveyed through an OF-style device tree.
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
|
|
|
* The Gianfar Ethernet Controller uses a ring of buffer
|
|
|
|
* descriptors. The beginning is indicated by a register
|
2005-06-20 23:54:21 +08:00
|
|
|
* pointing to the physical address of the start of the ring.
|
|
|
|
* The end is determined by a "wrap" bit being set in the
|
2005-04-17 06:20:36 +08:00
|
|
|
* last descriptor of the ring.
|
|
|
|
*
|
|
|
|
* When a packet is received, the RXF bit in the
|
2005-06-20 23:54:21 +08:00
|
|
|
* IEVENT register is set, triggering an interrupt when the
|
2005-04-17 06:20:36 +08:00
|
|
|
* corresponding bit in the IMASK register is also set (if
|
|
|
|
* interrupt coalescing is active, then the interrupt may not
|
|
|
|
* happen immediately, but will wait until either a set number
|
2005-09-24 10:54:21 +08:00
|
|
|
* of frames or amount of time have passed). In NAPI, the
|
2005-04-17 06:20:36 +08:00
|
|
|
* interrupt handler will signal there is work to be done, and
|
2008-07-11 06:33:52 +08:00
|
|
|
* exit. This method will start at the last known empty
|
2005-06-20 23:54:21 +08:00
|
|
|
* descriptor, and process every subsequent descriptor until there
|
2005-04-17 06:20:36 +08:00
|
|
|
* are none left with data (NAPI will stop after a set number of
|
|
|
|
* packets to give time to other tasks, but will eventually
|
|
|
|
* process all the packets). The data arrives inside a
|
|
|
|
* pre-allocated skb, and so after the skb is passed up to the
|
|
|
|
* stack, a new skb must be allocated, and the address field in
|
|
|
|
* the buffer descriptor must be updated to indicate this new
|
|
|
|
* skb.
|
|
|
|
*
|
|
|
|
* When the kernel requests that a packet be transmitted, the
|
|
|
|
* driver starts where it left off last time, and points the
|
|
|
|
* descriptor at the buffer which was passed in. The driver
|
|
|
|
* then informs the DMA engine that there are packets ready to
|
|
|
|
* be transmitted. Once the controller is finished transmitting
|
|
|
|
* the packet, an interrupt may be triggered (under the same
|
|
|
|
* conditions as for reception, but depending on the TXF bit).
|
|
|
|
* The driver then cleans up the buffer.
|
|
|
|
*/
|
|
|
|
|
2011-06-14 16:57:47 +08:00
|
|
|
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/errno.h>
|
2005-09-24 10:54:21 +08:00
|
|
|
#include <linux/unistd.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/netdevice.h>
|
|
|
|
#include <linux/etherdevice.h>
|
|
|
|
#include <linux/skbuff.h>
|
2005-06-20 23:54:21 +08:00
|
|
|
#include <linux/if_vlan.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/spinlock.h>
|
|
|
|
#include <linux/mm.h>
|
2013-09-18 03:28:33 +08:00
|
|
|
#include <linux/of_address.h>
|
|
|
|
#include <linux/of_irq.h>
|
2009-04-25 20:53:12 +08:00
|
|
|
#include <linux/of_mdio.h>
|
2008-12-17 07:29:15 +08:00
|
|
|
#include <linux/of_platform.h>
|
2005-06-20 23:54:21 +08:00
|
|
|
#include <linux/ip.h>
|
|
|
|
#include <linux/tcp.h>
|
|
|
|
#include <linux/udp.h>
|
2006-01-12 03:26:25 +08:00
|
|
|
#include <linux/in.h>
|
2010-04-09 07:10:03 +08:00
|
|
|
#include <linux/net_tstamp.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#include <asm/io.h>
|
2014-10-07 15:44:32 +08:00
|
|
|
#ifdef CONFIG_PPC
|
2010-06-30 14:39:12 +08:00
|
|
|
#include <asm/reg.h>
|
2013-10-10 01:20:41 +08:00
|
|
|
#include <asm/mpc85xx.h>
|
2014-10-07 15:44:32 +08:00
|
|
|
#endif
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <asm/irq.h>
|
2016-12-25 03:46:01 +08:00
|
|
|
#include <linux/uaccess.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/dma-mapping.h>
|
|
|
|
#include <linux/crc32.h>
|
2005-09-24 10:54:21 +08:00
|
|
|
#include <linux/mii.h>
|
|
|
|
#include <linux/phy.h>
|
2008-12-17 07:29:15 +08:00
|
|
|
#include <linux/phy_fixed.h>
|
|
|
|
#include <linux/of.h>
|
2010-10-27 06:07:13 +08:00
|
|
|
#include <linux/of_net.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#include "gianfar.h"
|
|
|
|
|
2015-10-27 16:47:43 +08:00
|
|
|
#define TX_TIMEOUT (5*HZ)
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
MODULE_AUTHOR("Freescale Semiconductor, Inc");
|
|
|
|
MODULE_DESCRIPTION("Gianfar Ethernet Driver");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|
2009-11-02 15:03:00 +08:00
|
|
|
static void gfar_init_rxbdp(struct gfar_priv_rx_q *rx_queue, struct rxbd8 *bdp,
|
2009-10-12 14:00:37 +08:00
|
|
|
dma_addr_t buf)
|
|
|
|
{
|
|
|
|
u32 lstatus;
|
|
|
|
|
2015-03-13 16:36:28 +08:00
|
|
|
bdp->bufPtr = cpu_to_be32(buf);
|
2009-10-12 14:00:37 +08:00
|
|
|
|
|
|
|
lstatus = BD_LFLAG(RXBD_EMPTY | RXBD_INTERRUPT);
|
2009-11-02 15:03:00 +08:00
|
|
|
if (bdp == rx_queue->rx_bd_base + rx_queue->rx_ring_size - 1)
|
2009-10-12 14:00:37 +08:00
|
|
|
lstatus |= BD_LFLAG(RXBD_WRAP);
|
|
|
|
|
2014-10-07 15:44:35 +08:00
|
|
|
gfar_wmb();
|
2009-10-12 14:00:37 +08:00
|
|
|
|
2015-03-13 16:36:28 +08:00
|
|
|
bdp->lstatus = cpu_to_be32(lstatus);
|
2009-10-12 14:00:37 +08:00
|
|
|
}
|
|
|
|
|
2009-11-02 15:03:15 +08:00
|
|
|
static void gfar_init_tx_rx_base(struct gfar_private *priv)
|
|
|
|
{
|
2009-11-02 15:03:34 +08:00
|
|
|
struct gfar __iomem *regs = priv->gfargrp[0].regs;
|
2009-11-04 20:53:00 +08:00
|
|
|
u32 __iomem *baddr;
|
2009-11-02 15:03:15 +08:00
|
|
|
int i;
|
|
|
|
|
|
|
|
baddr = ®s->tbase0;
|
2012-06-05 11:42:13 +08:00
|
|
|
for (i = 0; i < priv->num_tx_queues; i++) {
|
2009-11-02 15:03:15 +08:00
|
|
|
gfar_write(baddr, priv->tx_queue[i]->tx_bd_dma_base);
|
2012-06-05 11:42:13 +08:00
|
|
|
baddr += 2;
|
2009-11-02 15:03:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
baddr = ®s->rbase0;
|
2012-06-05 11:42:13 +08:00
|
|
|
for (i = 0; i < priv->num_rx_queues; i++) {
|
2009-11-02 15:03:15 +08:00
|
|
|
gfar_write(baddr, priv->rx_queue[i]->rx_bd_dma_base);
|
2012-06-05 11:42:13 +08:00
|
|
|
baddr += 2;
|
2009-11-02 15:03:15 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-27 16:42:44 +08:00
|
|
|
static void gfar_init_rqprm(struct gfar_private *priv)
|
|
|
|
{
|
|
|
|
struct gfar __iomem *regs = priv->gfargrp[0].regs;
|
|
|
|
u32 __iomem *baddr;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
baddr = ®s->rqprm0;
|
|
|
|
for (i = 0; i < priv->num_rx_queues; i++) {
|
|
|
|
gfar_write(baddr, priv->rx_queue[i]->rx_ring_size |
|
|
|
|
(DEFAULT_RX_LFC_THR << FBTHR_SHIFT));
|
|
|
|
baddr++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
gianfar: Add paged allocation and Rx S/G
The eTSEC h/w is capable of scatter/gather on the receive side
too if MAXFRM > MRBLR, when the allowed maximum Rx frame size
is set to be greater than the maximum Rx buffer size (MRBLR).
It's about time the driver makes use of this h/w capability,
by supporting fixed buffer sizes and Rx S/G.
The buffer size given to eTSEC for reception is fixed to
1536B (must be multiple of 64), which is the same default
buffer size as before, used to accommodate standard MTU
(1500B) size frames. As before, eTSEC can receive frames of
up to 9600B. Individual Rx buffers are mapped to page halves
(page size for eTSEC systems is 4KB). The skb is built around
the first buffer of a frame (using build_skb()). In case the
frame spans multiple buffers, the trailing buffers are added
as Rx fragments to the skb. The last buffer in frame is marked
by the L status flag. A mechanism is in place to reuse the pages
owned by the driver (for Rx) for subsequent receptions.
Supporting fixed size buffers allows the implementation of Rx S/G,
which in turn removes the memory pressure issues the driver had
before when MTU was set for jumbo frame reception.
Also, in most cases, the Rx path becomes faster due to Rx page
reusal, since the overhead of allocating new rx buffers is removed
from the fast path.
Signed-off-by: Claudiu Manoil <claudiu.manoil@freescale.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2015-07-13 21:22:06 +08:00
|
|
|
static void gfar_rx_offload_en(struct gfar_private *priv)
|
2009-10-12 14:00:34 +08:00
|
|
|
{
|
gianfar: Fix and cleanup Rx FCB indication
This fixes a less obvious error on one hand, and prevents futher
similar errors by disambiguating and optimizing RxFCB indication,
on the other hand.
The error consists in NETIF_F_HW_VLAN_TX flag being used as an
indication of Rx FCB insertion. This happened as soon gfar_uses_fcb(),
which despite its name indicates Rx FCB insertion, started
incorporating is_vlan_on().
is_vlan_on(), on the other hand, is also a misleading construct because
we need to differentiate b/w hw VLAN extraction/VLEX (marked by VLAN_RX
flag) and hw VLAN insertion/VLINS (VLAN_TX flag), which are different
mechanisms using different types of FCBs.
The hw spec for the RxFCB feature is as follows:
In the case of RxBD rings, FCBs (Frame Control Block) are inserted by
the eTSEC whenever RCTRL[PRSDEP] is set to a non-zero value. Only one
FCB is inserted per frame (in the buffer pointed to by the RxBD with
bit F set). TOE acceleration for receive is enabled for all rx frames
in this case.
This patch introduces priv->uses_rxfcb field to quickly signal RxFCB
insertion in accordance with the specification above.
The dependency on FSL_GIANFAR_DEV_HAS_TIMER was also eliminated as
another source of confusion. The actual dependency is to priv->hwts_rx_en.
Upon changing priv->hwts_rx_en via IOCTL, the gfar device is being
restarted and on init_mac() the priv->hwts_rx_en flag determines RxFCB
insertion, and rctrl is programmed accordingly. The patch takes care
of this case too.
Though maybe not as self documenting as the inlining version uses_fcb(),
priv->uses_rxfcb has the main purpose to quickly signal, on the hot path,
that the incoming frame has a *Rx* FCB block inserted which needs to be
pulled out before passing the skb to the stack. This is a performance
critical operation, it needs to happen fast, that's why uses_rxfcb is
placed in the first cacheline of gfar_private.
This is also why a cached rctrl cannot be used instead: 1) because
we don't have 32 bits available in the first cacheline of gfar_priv
(but only 16); 2) bit operations are expensive on the hot path.
Signed-off-by: Claudiu Manoil <claudiu.manoil@freescale.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2013-02-14 13:00:07 +08:00
|
|
|
/* set this when rx hw offload (TOE) functions are being used */
|
|
|
|
priv->uses_rxfcb = 0;
|
|
|
|
|
gianfar: Fix on-the-fly vlan and mtu updates
The RCTRL and TCTRL registers should not be changed
on-the-fly, while the controller is running, otherwise
unexpected behaviour occurs. But that's exactly what
gfar_vlan_mode() does, updating the VLAN acceleration
bits inside RCTRL/TCTRL. The attempt to lock these
operations doesn't help, but only adds to the confusion.
There's also a dependency for Rx FCB insertion (activating
/de-activating the TOE offload block on Rx) which might
change the required rx buffer size. This makes matters
worse as gfar_vlan_mode() ends up calling gfar_change_mtu(),
though the MTU size remains the same. Note that there are
other situations that may affect the required rx buffer size,
like changing RXCSUM or rx hw timestamping, but errorneously
the rx buffer size is not recomputed/ updated in the process.
To fix this, do the vlan updates properly inside the MAC
reset and reconfiguration procedure, which takes care of
the rx buffer size dependecy and the rx TOE block (PRSDEP)
activation/deactivation as well (in the correct order).
As a consequence, MTU/ rx buff size updates are done now
by the same MAC reset and reconfig procedure, so that out
of context updates to MAXFRM, MRBLR, and MACCFG inside
change_mtu() are no longer needed. The rx buffer size
dependecy to Rx FCB is now handled for the other cases too
(RXCSUM and rx hw timestamping).
Signed-off-by: Claudiu Manoil <claudiu.manoil@freescale.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-02-24 18:13:43 +08:00
|
|
|
if (priv->ndev->features & (NETIF_F_RXCSUM | NETIF_F_HW_VLAN_CTAG_RX))
|
|
|
|
priv->uses_rxfcb = 1;
|
|
|
|
|
2015-10-23 16:41:59 +08:00
|
|
|
if (priv->hwts_rx_en || priv->rx_filer_enable)
|
gianfar: Fix on-the-fly vlan and mtu updates
The RCTRL and TCTRL registers should not be changed
on-the-fly, while the controller is running, otherwise
unexpected behaviour occurs. But that's exactly what
gfar_vlan_mode() does, updating the VLAN acceleration
bits inside RCTRL/TCTRL. The attempt to lock these
operations doesn't help, but only adds to the confusion.
There's also a dependency for Rx FCB insertion (activating
/de-activating the TOE offload block on Rx) which might
change the required rx buffer size. This makes matters
worse as gfar_vlan_mode() ends up calling gfar_change_mtu(),
though the MTU size remains the same. Note that there are
other situations that may affect the required rx buffer size,
like changing RXCSUM or rx hw timestamping, but errorneously
the rx buffer size is not recomputed/ updated in the process.
To fix this, do the vlan updates properly inside the MAC
reset and reconfiguration procedure, which takes care of
the rx buffer size dependecy and the rx TOE block (PRSDEP)
activation/deactivation as well (in the correct order).
As a consequence, MTU/ rx buff size updates are done now
by the same MAC reset and reconfig procedure, so that out
of context updates to MAXFRM, MRBLR, and MACCFG inside
change_mtu() are no longer needed. The rx buffer size
dependecy to Rx FCB is now handled for the other cases too
(RXCSUM and rx hw timestamping).
Signed-off-by: Claudiu Manoil <claudiu.manoil@freescale.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-02-24 18:13:43 +08:00
|
|
|
priv->uses_rxfcb = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gfar_mac_rx_config(struct gfar_private *priv)
|
|
|
|
{
|
|
|
|
struct gfar __iomem *regs = priv->gfargrp[0].regs;
|
|
|
|
u32 rctrl = 0;
|
|
|
|
|
2009-12-16 09:14:58 +08:00
|
|
|
if (priv->rx_filer_enable) {
|
2015-10-23 16:41:59 +08:00
|
|
|
rctrl |= RCTRL_FILREN | RCTRL_PRSDEP_INIT;
|
2009-12-16 09:14:58 +08:00
|
|
|
/* Program the RIR0 reg with the required distribution */
|
gianfar: Drop GFAR_MQ_POLLING support
Gianfar used to enable all 8 Rx queues (DMA rings) per
ethernet device, even though the controller can only
support 2 interrupt lines at most. This meant that
multiple Rx queues would have to be grouped per NAPI poll
routine, and the CPU would have to split the budget and
service them in a round robin manner. The overhead of
this scheme proved to outweight the potential benefits.
The alternative was to introduce the "Single Queue" polling
mode, supporting one Rx queue per NAPI, which became the
default packet processing option and helped improve the
performance of the driver.
MQ_POLLING also relies on undocumeted device tree properties
to specify how to map the 8 Rx and Tx queues to a given
interrupt line (aka "interrupt group"). Using module parameters
to enable this mode wasn't an option either. Long story short,
MQ_POLLING became obsolete, now it is just dead code, and no
one asked for it so far.
For the Tx queues, multi-queue support (more than 1 Tx queue
per CPU) could be revisited by adding tc MQPRIO support, but
again, one has to consider that there are only 2 interrupt lines.
So the NAPI poll routine would have to service multiple Tx rings.
Signed-off-by: Claudiu Manoil <claudiu.manoil@nxp.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2021-04-17 01:11:22 +08:00
|
|
|
gfar_write(®s->rir0, DEFAULT_2RXQ_RIR0);
|
2009-12-16 09:14:58 +08:00
|
|
|
}
|
2009-10-12 14:00:34 +08:00
|
|
|
|
2013-01-23 08:18:36 +08:00
|
|
|
/* Restore PROMISC mode */
|
gianfar: Implement MAC reset and reconfig procedure
The main MAC config registers like: RCTRL/TCTRL, MRBLR,
MAXFRM, RXIC/TXIC, most fields of MACCFG1/2, should not
be changed on-the-fly, but at least after stopping the
DMA and disabling the Rx/Tx blocks and, for increased
reliability, after a MAC soft reset.
Impelement a complete MAC soft reset and reconfig procedure
following the latest HW advisories - gfar_mac_reset() - to
replace gfar_mac_init() and (the confusing) init_registers()
functions.
Factor out separate config functions for RCTRL and TCTRL,
insure programming order of the relevant config regs after
MAC soft reset.
Split gfar_hw_init() into gfar_mac_reset() and the remaining
global regs that don't need to be reconfigured after MAC soft
reset (FIFOCFG, ATTRELI, HW counters a.s.o).
As gfar_hw_init() now makes all the register writes @probe()
time, based on all the device flags and config options, it
must be moved further down, just before register_netdev(),
as the last config step when the config values are comitted
to HW. Also, move netif_carrier_off() after register_netdev(),
because it has no effect if called before.
Signed-off-by: Claudiu Manoil <claudiu.manoil@freescale.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-02-24 18:13:42 +08:00
|
|
|
if (priv->ndev->flags & IFF_PROMISC)
|
2013-01-23 08:18:36 +08:00
|
|
|
rctrl |= RCTRL_PROM;
|
|
|
|
|
gianfar: Fix on-the-fly vlan and mtu updates
The RCTRL and TCTRL registers should not be changed
on-the-fly, while the controller is running, otherwise
unexpected behaviour occurs. But that's exactly what
gfar_vlan_mode() does, updating the VLAN acceleration
bits inside RCTRL/TCTRL. The attempt to lock these
operations doesn't help, but only adds to the confusion.
There's also a dependency for Rx FCB insertion (activating
/de-activating the TOE offload block on Rx) which might
change the required rx buffer size. This makes matters
worse as gfar_vlan_mode() ends up calling gfar_change_mtu(),
though the MTU size remains the same. Note that there are
other situations that may affect the required rx buffer size,
like changing RXCSUM or rx hw timestamping, but errorneously
the rx buffer size is not recomputed/ updated in the process.
To fix this, do the vlan updates properly inside the MAC
reset and reconfiguration procedure, which takes care of
the rx buffer size dependecy and the rx TOE block (PRSDEP)
activation/deactivation as well (in the correct order).
As a consequence, MTU/ rx buff size updates are done now
by the same MAC reset and reconfig procedure, so that out
of context updates to MAXFRM, MRBLR, and MACCFG inside
change_mtu() are no longer needed. The rx buffer size
dependecy to Rx FCB is now handled for the other cases too
(RXCSUM and rx hw timestamping).
Signed-off-by: Claudiu Manoil <claudiu.manoil@freescale.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-02-24 18:13:43 +08:00
|
|
|
if (priv->ndev->features & NETIF_F_RXCSUM)
|
2009-10-12 14:00:34 +08:00
|
|
|
rctrl |= RCTRL_CHECKSUMMING;
|
|
|
|
|
gianfar: Fix on-the-fly vlan and mtu updates
The RCTRL and TCTRL registers should not be changed
on-the-fly, while the controller is running, otherwise
unexpected behaviour occurs. But that's exactly what
gfar_vlan_mode() does, updating the VLAN acceleration
bits inside RCTRL/TCTRL. The attempt to lock these
operations doesn't help, but only adds to the confusion.
There's also a dependency for Rx FCB insertion (activating
/de-activating the TOE offload block on Rx) which might
change the required rx buffer size. This makes matters
worse as gfar_vlan_mode() ends up calling gfar_change_mtu(),
though the MTU size remains the same. Note that there are
other situations that may affect the required rx buffer size,
like changing RXCSUM or rx hw timestamping, but errorneously
the rx buffer size is not recomputed/ updated in the process.
To fix this, do the vlan updates properly inside the MAC
reset and reconfiguration procedure, which takes care of
the rx buffer size dependecy and the rx TOE block (PRSDEP)
activation/deactivation as well (in the correct order).
As a consequence, MTU/ rx buff size updates are done now
by the same MAC reset and reconfig procedure, so that out
of context updates to MAXFRM, MRBLR, and MACCFG inside
change_mtu() are no longer needed. The rx buffer size
dependecy to Rx FCB is now handled for the other cases too
(RXCSUM and rx hw timestamping).
Signed-off-by: Claudiu Manoil <claudiu.manoil@freescale.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-02-24 18:13:43 +08:00
|
|
|
if (priv->extended_hash)
|
|
|
|
rctrl |= RCTRL_EXTHASH | RCTRL_EMEN;
|
2009-10-12 14:00:34 +08:00
|
|
|
|
|
|
|
if (priv->padding) {
|
|
|
|
rctrl &= ~RCTRL_PAL_MASK;
|
|
|
|
rctrl |= RCTRL_PADDING(priv->padding);
|
|
|
|
}
|
|
|
|
|
2010-06-11 09:49:05 +08:00
|
|
|
/* Enable HW time stamping if requested from user space */
|
gianfar: Fix on-the-fly vlan and mtu updates
The RCTRL and TCTRL registers should not be changed
on-the-fly, while the controller is running, otherwise
unexpected behaviour occurs. But that's exactly what
gfar_vlan_mode() does, updating the VLAN acceleration
bits inside RCTRL/TCTRL. The attempt to lock these
operations doesn't help, but only adds to the confusion.
There's also a dependency for Rx FCB insertion (activating
/de-activating the TOE offload block on Rx) which might
change the required rx buffer size. This makes matters
worse as gfar_vlan_mode() ends up calling gfar_change_mtu(),
though the MTU size remains the same. Note that there are
other situations that may affect the required rx buffer size,
like changing RXCSUM or rx hw timestamping, but errorneously
the rx buffer size is not recomputed/ updated in the process.
To fix this, do the vlan updates properly inside the MAC
reset and reconfiguration procedure, which takes care of
the rx buffer size dependecy and the rx TOE block (PRSDEP)
activation/deactivation as well (in the correct order).
As a consequence, MTU/ rx buff size updates are done now
by the same MAC reset and reconfig procedure, so that out
of context updates to MAXFRM, MRBLR, and MACCFG inside
change_mtu() are no longer needed. The rx buffer size
dependecy to Rx FCB is now handled for the other cases too
(RXCSUM and rx hw timestamping).
Signed-off-by: Claudiu Manoil <claudiu.manoil@freescale.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-02-24 18:13:43 +08:00
|
|
|
if (priv->hwts_rx_en)
|
2010-06-11 09:49:05 +08:00
|
|
|
rctrl |= RCTRL_PRSDEP_INIT | RCTRL_TS_ENABLE;
|
|
|
|
|
gianfar: Fix on-the-fly vlan and mtu updates
The RCTRL and TCTRL registers should not be changed
on-the-fly, while the controller is running, otherwise
unexpected behaviour occurs. But that's exactly what
gfar_vlan_mode() does, updating the VLAN acceleration
bits inside RCTRL/TCTRL. The attempt to lock these
operations doesn't help, but only adds to the confusion.
There's also a dependency for Rx FCB insertion (activating
/de-activating the TOE offload block on Rx) which might
change the required rx buffer size. This makes matters
worse as gfar_vlan_mode() ends up calling gfar_change_mtu(),
though the MTU size remains the same. Note that there are
other situations that may affect the required rx buffer size,
like changing RXCSUM or rx hw timestamping, but errorneously
the rx buffer size is not recomputed/ updated in the process.
To fix this, do the vlan updates properly inside the MAC
reset and reconfiguration procedure, which takes care of
the rx buffer size dependecy and the rx TOE block (PRSDEP)
activation/deactivation as well (in the correct order).
As a consequence, MTU/ rx buff size updates are done now
by the same MAC reset and reconfig procedure, so that out
of context updates to MAXFRM, MRBLR, and MACCFG inside
change_mtu() are no longer needed. The rx buffer size
dependecy to Rx FCB is now handled for the other cases too
(RXCSUM and rx hw timestamping).
Signed-off-by: Claudiu Manoil <claudiu.manoil@freescale.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-02-24 18:13:43 +08:00
|
|
|
if (priv->ndev->features & NETIF_F_HW_VLAN_CTAG_RX)
|
2011-07-26 08:03:13 +08:00
|
|
|
rctrl |= RCTRL_VLEX | RCTRL_PRSDEP_INIT;
|
2009-10-12 14:00:34 +08:00
|
|
|
|
2014-10-27 16:42:44 +08:00
|
|
|
/* Clear the LFC bit */
|
|
|
|
gfar_write(®s->rctrl, rctrl);
|
|
|
|
/* Init flow control threshold values */
|
|
|
|
gfar_init_rqprm(priv);
|
|
|
|
gfar_write(®s->ptv, DEFAULT_LFC_PTVVAL);
|
|
|
|
rctrl |= RCTRL_LFC;
|
|
|
|
|
2009-10-12 14:00:34 +08:00
|
|
|
/* Init rctrl based on our settings */
|
|
|
|
gfar_write(®s->rctrl, rctrl);
|
gianfar: Implement MAC reset and reconfig procedure
The main MAC config registers like: RCTRL/TCTRL, MRBLR,
MAXFRM, RXIC/TXIC, most fields of MACCFG1/2, should not
be changed on-the-fly, but at least after stopping the
DMA and disabling the Rx/Tx blocks and, for increased
reliability, after a MAC soft reset.
Impelement a complete MAC soft reset and reconfig procedure
following the latest HW advisories - gfar_mac_reset() - to
replace gfar_mac_init() and (the confusing) init_registers()
functions.
Factor out separate config functions for RCTRL and TCTRL,
insure programming order of the relevant config regs after
MAC soft reset.
Split gfar_hw_init() into gfar_mac_reset() and the remaining
global regs that don't need to be reconfigured after MAC soft
reset (FIFOCFG, ATTRELI, HW counters a.s.o).
As gfar_hw_init() now makes all the register writes @probe()
time, based on all the device flags and config options, it
must be moved further down, just before register_netdev(),
as the last config step when the config values are comitted
to HW. Also, move netif_carrier_off() after register_netdev(),
because it has no effect if called before.
Signed-off-by: Claudiu Manoil <claudiu.manoil@freescale.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-02-24 18:13:42 +08:00
|
|
|
}
|
2009-10-12 14:00:34 +08:00
|
|
|
|
gianfar: Implement MAC reset and reconfig procedure
The main MAC config registers like: RCTRL/TCTRL, MRBLR,
MAXFRM, RXIC/TXIC, most fields of MACCFG1/2, should not
be changed on-the-fly, but at least after stopping the
DMA and disabling the Rx/Tx blocks and, for increased
reliability, after a MAC soft reset.
Impelement a complete MAC soft reset and reconfig procedure
following the latest HW advisories - gfar_mac_reset() - to
replace gfar_mac_init() and (the confusing) init_registers()
functions.
Factor out separate config functions for RCTRL and TCTRL,
insure programming order of the relevant config regs after
MAC soft reset.
Split gfar_hw_init() into gfar_mac_reset() and the remaining
global regs that don't need to be reconfigured after MAC soft
reset (FIFOCFG, ATTRELI, HW counters a.s.o).
As gfar_hw_init() now makes all the register writes @probe()
time, based on all the device flags and config options, it
must be moved further down, just before register_netdev(),
as the last config step when the config values are comitted
to HW. Also, move netif_carrier_off() after register_netdev(),
because it has no effect if called before.
Signed-off-by: Claudiu Manoil <claudiu.manoil@freescale.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-02-24 18:13:42 +08:00
|
|
|
static void gfar_mac_tx_config(struct gfar_private *priv)
|
|
|
|
{
|
|
|
|
struct gfar __iomem *regs = priv->gfargrp[0].regs;
|
|
|
|
u32 tctrl = 0;
|
|
|
|
|
|
|
|
if (priv->ndev->features & NETIF_F_IP_CSUM)
|
2009-10-12 14:00:34 +08:00
|
|
|
tctrl |= TCTRL_INIT_CSUM;
|
|
|
|
|
2012-09-24 06:39:08 +08:00
|
|
|
if (priv->prio_sched_en)
|
|
|
|
tctrl |= TCTRL_TXSCHED_PRIO;
|
|
|
|
else {
|
|
|
|
tctrl |= TCTRL_TXSCHED_WRRS;
|
|
|
|
gfar_write(®s->tr03wt, DEFAULT_WRRS_WEIGHT);
|
|
|
|
gfar_write(®s->tr47wt, DEFAULT_WRRS_WEIGHT);
|
|
|
|
}
|
2009-11-02 15:03:15 +08:00
|
|
|
|
gianfar: Fix on-the-fly vlan and mtu updates
The RCTRL and TCTRL registers should not be changed
on-the-fly, while the controller is running, otherwise
unexpected behaviour occurs. But that's exactly what
gfar_vlan_mode() does, updating the VLAN acceleration
bits inside RCTRL/TCTRL. The attempt to lock these
operations doesn't help, but only adds to the confusion.
There's also a dependency for Rx FCB insertion (activating
/de-activating the TOE offload block on Rx) which might
change the required rx buffer size. This makes matters
worse as gfar_vlan_mode() ends up calling gfar_change_mtu(),
though the MTU size remains the same. Note that there are
other situations that may affect the required rx buffer size,
like changing RXCSUM or rx hw timestamping, but errorneously
the rx buffer size is not recomputed/ updated in the process.
To fix this, do the vlan updates properly inside the MAC
reset and reconfiguration procedure, which takes care of
the rx buffer size dependecy and the rx TOE block (PRSDEP)
activation/deactivation as well (in the correct order).
As a consequence, MTU/ rx buff size updates are done now
by the same MAC reset and reconfig procedure, so that out
of context updates to MAXFRM, MRBLR, and MACCFG inside
change_mtu() are no longer needed. The rx buffer size
dependecy to Rx FCB is now handled for the other cases too
(RXCSUM and rx hw timestamping).
Signed-off-by: Claudiu Manoil <claudiu.manoil@freescale.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-02-24 18:13:43 +08:00
|
|
|
if (priv->ndev->features & NETIF_F_HW_VLAN_CTAG_TX)
|
|
|
|
tctrl |= TCTRL_VLINS;
|
|
|
|
|
2009-10-12 14:00:34 +08:00
|
|
|
gfar_write(®s->tctrl, tctrl);
|
|
|
|
}
|
|
|
|
|
gianfar: Fix Tx int miss, dont write IC on-the-fly
Programming the interrupt coalescing (IC) registers while
the controller/DMA is on may incur the loss of one Tx
confirmation interrupt, under certain conditions. This is
a subtle hw race because it does not occur during a burst
of Tx packets. It has been observed on p2020 devices that,
if just one packet is being xmit'ed, the Tx confirmation
doesn't trigger and BQL evetually blocks the Tx queues,
followed by Tx timeout and an un-responsive device.
This issue was not apparent prior to introducing BQL
support, as a late Tx confirmation was not an issue back then
and the next burst of Tx frames would have triggered the
Tx confirmation/ Tx ring cleanup anyway.
Bottom line, the hw specifications state that the IC registers
should not be programmed while the Rx/Tx blocks (the DMA) are
enabled. Further more, these registers are currently re-written
with the same values on the processing path, over and over again.
To fix this, rewriting the IC registers has been removed from
the processing path (napi poll). A complete MAC reset procedure
has been implemented for the ethtool -c option instead, to
reliably update these registers while the controller is stopped.
Signed-off-by: Claudiu Manoil <claudiu.manoil@freescale.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-02-24 18:13:46 +08:00
|
|
|
static void gfar_configure_coalescing(struct gfar_private *priv,
|
|
|
|
unsigned long tx_mask, unsigned long rx_mask)
|
|
|
|
{
|
|
|
|
struct gfar __iomem *regs = priv->gfargrp[0].regs;
|
|
|
|
u32 __iomem *baddr;
|
|
|
|
|
|
|
|
if (priv->mode == MQ_MG_MODE) {
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
baddr = ®s->txic0;
|
|
|
|
for_each_set_bit(i, &tx_mask, priv->num_tx_queues) {
|
|
|
|
gfar_write(baddr + i, 0);
|
|
|
|
if (likely(priv->tx_queue[i]->txcoalescing))
|
|
|
|
gfar_write(baddr + i, priv->tx_queue[i]->txic);
|
|
|
|
}
|
|
|
|
|
|
|
|
baddr = ®s->rxic0;
|
|
|
|
for_each_set_bit(i, &rx_mask, priv->num_rx_queues) {
|
|
|
|
gfar_write(baddr + i, 0);
|
|
|
|
if (likely(priv->rx_queue[i]->rxcoalescing))
|
|
|
|
gfar_write(baddr + i, priv->rx_queue[i]->rxic);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Backward compatible case -- even if we enable
|
|
|
|
* multiple queues, there's only single reg to program
|
|
|
|
*/
|
|
|
|
gfar_write(®s->txic, 0);
|
|
|
|
if (likely(priv->tx_queue[0]->txcoalescing))
|
|
|
|
gfar_write(®s->txic, priv->tx_queue[0]->txic);
|
|
|
|
|
|
|
|
gfar_write(®s->rxic, 0);
|
|
|
|
if (unlikely(priv->rx_queue[0]->rxcoalescing))
|
|
|
|
gfar_write(®s->rxic, priv->rx_queue[0]->rxic);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-04 21:52:20 +08:00
|
|
|
static void gfar_configure_coalescing_all(struct gfar_private *priv)
|
gianfar: Fix Tx int miss, dont write IC on-the-fly
Programming the interrupt coalescing (IC) registers while
the controller/DMA is on may incur the loss of one Tx
confirmation interrupt, under certain conditions. This is
a subtle hw race because it does not occur during a burst
of Tx packets. It has been observed on p2020 devices that,
if just one packet is being xmit'ed, the Tx confirmation
doesn't trigger and BQL evetually blocks the Tx queues,
followed by Tx timeout and an un-responsive device.
This issue was not apparent prior to introducing BQL
support, as a late Tx confirmation was not an issue back then
and the next burst of Tx frames would have triggered the
Tx confirmation/ Tx ring cleanup anyway.
Bottom line, the hw specifications state that the IC registers
should not be programmed while the Rx/Tx blocks (the DMA) are
enabled. Further more, these registers are currently re-written
with the same values on the processing path, over and over again.
To fix this, rewriting the IC registers has been removed from
the processing path (napi poll). A complete MAC reset procedure
has been implemented for the ethtool -c option instead, to
reliably update these registers while the controller is stopped.
Signed-off-by: Claudiu Manoil <claudiu.manoil@freescale.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-02-24 18:13:46 +08:00
|
|
|
{
|
|
|
|
gfar_configure_coalescing(priv, 0xFF, 0xFF);
|
|
|
|
}
|
|
|
|
|
2021-06-17 17:49:15 +08:00
|
|
|
static void gfar_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats)
|
2009-12-16 09:15:07 +08:00
|
|
|
{
|
|
|
|
struct gfar_private *priv = netdev_priv(dev);
|
2012-06-05 11:42:14 +08:00
|
|
|
int i;
|
2009-12-16 09:15:07 +08:00
|
|
|
|
|
|
|
for (i = 0; i < priv->num_rx_queues; i++) {
|
2021-06-17 17:49:15 +08:00
|
|
|
stats->rx_packets += priv->rx_queue[i]->stats.rx_packets;
|
|
|
|
stats->rx_bytes += priv->rx_queue[i]->stats.rx_bytes;
|
|
|
|
stats->rx_dropped += priv->rx_queue[i]->stats.rx_dropped;
|
2009-12-16 09:15:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < priv->num_tx_queues; i++) {
|
2021-06-17 17:49:15 +08:00
|
|
|
stats->tx_bytes += priv->tx_queue[i]->stats.tx_bytes;
|
|
|
|
stats->tx_packets += priv->tx_queue[i]->stats.tx_packets;
|
2009-12-16 09:15:07 +08:00
|
|
|
}
|
2021-06-17 17:49:28 +08:00
|
|
|
|
|
|
|
if (priv->device_flags & FSL_GIANFAR_DEV_HAS_RMON) {
|
|
|
|
struct rmon_mib __iomem *rmon = &priv->gfargrp[0].regs->rmon;
|
|
|
|
unsigned long flags;
|
|
|
|
u32 rdrp, car, car_before;
|
|
|
|
u64 rdrp_offset;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&priv->rmon_overflow.lock, flags);
|
|
|
|
car = gfar_read(&rmon->car1) & CAR1_C1RDR;
|
|
|
|
do {
|
|
|
|
car_before = car;
|
|
|
|
rdrp = gfar_read(&rmon->rdrp);
|
|
|
|
car = gfar_read(&rmon->car1) & CAR1_C1RDR;
|
|
|
|
} while (car != car_before);
|
|
|
|
if (car) {
|
|
|
|
priv->rmon_overflow.rdrp++;
|
|
|
|
gfar_write(&rmon->car1, car);
|
|
|
|
}
|
|
|
|
rdrp_offset = priv->rmon_overflow.rdrp;
|
|
|
|
spin_unlock_irqrestore(&priv->rmon_overflow.lock, flags);
|
|
|
|
|
|
|
|
stats->rx_missed_errors = rdrp + (rdrp_offset << 16);
|
|
|
|
}
|
2009-12-16 09:15:07 +08:00
|
|
|
}
|
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
/* Set the appropriate hash bit for the given addr */
|
|
|
|
/* The algorithm works like so:
|
|
|
|
* 1) Take the Destination Address (ie the multicast address), and
|
|
|
|
* do a CRC on it (little endian), and reverse the bits of the
|
|
|
|
* result.
|
|
|
|
* 2) Use the 8 most significant bits as a hash into a 256-entry
|
|
|
|
* table. The table is controlled through 8 32-bit registers:
|
|
|
|
* gaddr0-7. gaddr0's MSB is entry 0, and gaddr7's LSB is
|
|
|
|
* gaddr7. This means that the 3 most significant bits in the
|
|
|
|
* hash index which gaddr register to use, and the 5 other bits
|
|
|
|
* indicate which bit (assuming an IBM numbering scheme, which
|
|
|
|
* for PowerPC (tm) is usually the case) in the register holds
|
|
|
|
* the entry.
|
|
|
|
*/
|
|
|
|
static void gfar_set_hash_for_addr(struct net_device *dev, u8 *addr)
|
|
|
|
{
|
|
|
|
u32 tempval;
|
|
|
|
struct gfar_private *priv = netdev_priv(dev);
|
|
|
|
u32 result = ether_crc(ETH_ALEN, addr);
|
|
|
|
int width = priv->hash_width;
|
|
|
|
u8 whichbit = (result >> (32 - width)) & 0x1f;
|
|
|
|
u8 whichreg = result >> (32 - width + 5);
|
|
|
|
u32 value = (1 << (31-whichbit));
|
|
|
|
|
|
|
|
tempval = gfar_read(priv->hash_regs[whichreg]);
|
|
|
|
tempval |= value;
|
|
|
|
gfar_write(priv->hash_regs[whichreg], tempval);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* There are multiple MAC Address register pairs on some controllers
|
|
|
|
* This function sets the numth pair to a given address
|
|
|
|
*/
|
|
|
|
static void gfar_set_mac_for_addr(struct net_device *dev, int num,
|
|
|
|
const u8 *addr)
|
|
|
|
{
|
|
|
|
struct gfar_private *priv = netdev_priv(dev);
|
|
|
|
struct gfar __iomem *regs = priv->gfargrp[0].regs;
|
|
|
|
u32 tempval;
|
|
|
|
u32 __iomem *macptr = ®s->macstnaddr1;
|
|
|
|
|
|
|
|
macptr += num*2;
|
|
|
|
|
|
|
|
/* For a station address of 0x12345678ABCD in transmission
|
|
|
|
* order (BE), MACnADDR1 is set to 0xCDAB7856 and
|
|
|
|
* MACnADDR2 is set to 0x34120000.
|
|
|
|
*/
|
|
|
|
tempval = (addr[5] << 24) | (addr[4] << 16) |
|
|
|
|
(addr[3] << 8) | addr[2];
|
|
|
|
|
|
|
|
gfar_write(macptr, tempval);
|
|
|
|
|
|
|
|
tempval = (addr[1] << 24) | (addr[0] << 16);
|
|
|
|
|
|
|
|
gfar_write(macptr+1, tempval);
|
|
|
|
}
|
|
|
|
|
2015-05-06 23:07:30 +08:00
|
|
|
static int gfar_set_mac_addr(struct net_device *dev, void *p)
|
|
|
|
{
|
2021-03-29 22:08:47 +08:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = eth_mac_addr(dev, p);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2015-05-06 23:07:30 +08:00
|
|
|
|
|
|
|
gfar_set_mac_for_addr(dev, 0, dev->dev_addr);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-02-17 18:53:17 +08:00
|
|
|
static void gfar_ints_disable(struct gfar_private *priv)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < priv->num_grps; i++) {
|
|
|
|
struct gfar __iomem *regs = priv->gfargrp[i].regs;
|
|
|
|
/* Clear IEVENT */
|
|
|
|
gfar_write(®s->ievent, IEVENT_INIT_CLEAR);
|
|
|
|
|
|
|
|
/* Initialize IMASK */
|
|
|
|
gfar_write(®s->imask, IMASK_INIT_CLEAR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gfar_ints_enable(struct gfar_private *priv)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < priv->num_grps; i++) {
|
|
|
|
struct gfar __iomem *regs = priv->gfargrp[i].regs;
|
|
|
|
/* Unmask the interrupts we look for */
|
2021-06-17 17:49:28 +08:00
|
|
|
gfar_write(®s->imask,
|
|
|
|
IMASK_DEFAULT | priv->rmon_overflow.imask);
|
2014-02-17 18:53:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-17 18:53:14 +08:00
|
|
|
static int gfar_alloc_tx_queues(struct gfar_private *priv)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < priv->num_tx_queues; i++) {
|
|
|
|
priv->tx_queue[i] = kzalloc(sizeof(struct gfar_priv_tx_q),
|
|
|
|
GFP_KERNEL);
|
|
|
|
if (!priv->tx_queue[i])
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
priv->tx_queue[i]->tx_skbuff = NULL;
|
|
|
|
priv->tx_queue[i]->qindex = i;
|
|
|
|
priv->tx_queue[i]->dev = priv->ndev;
|
|
|
|
spin_lock_init(&(priv->tx_queue[i]->txlock));
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int gfar_alloc_rx_queues(struct gfar_private *priv)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < priv->num_rx_queues; i++) {
|
|
|
|
priv->rx_queue[i] = kzalloc(sizeof(struct gfar_priv_rx_q),
|
|
|
|
GFP_KERNEL);
|
|
|
|
if (!priv->rx_queue[i])
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
priv->rx_queue[i]->qindex = i;
|
2015-07-13 21:22:05 +08:00
|
|
|
priv->rx_queue[i]->ndev = priv->ndev;
|
2014-02-17 18:53:14 +08:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gfar_free_tx_queues(struct gfar_private *priv)
|
2009-11-02 15:03:15 +08:00
|
|
|
{
|
2012-06-05 11:42:14 +08:00
|
|
|
int i;
|
2009-11-02 15:03:15 +08:00
|
|
|
|
|
|
|
for (i = 0; i < priv->num_tx_queues; i++)
|
|
|
|
kfree(priv->tx_queue[i]);
|
|
|
|
}
|
|
|
|
|
2014-02-17 18:53:14 +08:00
|
|
|
static void gfar_free_rx_queues(struct gfar_private *priv)
|
2009-11-02 15:03:15 +08:00
|
|
|
{
|
2012-06-05 11:42:14 +08:00
|
|
|
int i;
|
2009-11-02 15:03:15 +08:00
|
|
|
|
|
|
|
for (i = 0; i < priv->num_rx_queues; i++)
|
|
|
|
kfree(priv->rx_queue[i]);
|
|
|
|
}
|
|
|
|
|
2009-11-02 15:03:34 +08:00
|
|
|
static void unmap_group_regs(struct gfar_private *priv)
|
|
|
|
{
|
2012-06-05 11:42:14 +08:00
|
|
|
int i;
|
2009-11-02 15:03:34 +08:00
|
|
|
|
|
|
|
for (i = 0; i < MAXGROUPS; i++)
|
|
|
|
if (priv->gfargrp[i].regs)
|
|
|
|
iounmap(priv->gfargrp[i].regs);
|
|
|
|
}
|
|
|
|
|
2013-01-29 11:55:12 +08:00
|
|
|
static void free_gfar_dev(struct gfar_private *priv)
|
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
for (i = 0; i < priv->num_grps; i++)
|
|
|
|
for (j = 0; j < GFAR_NUM_IRQS; j++) {
|
|
|
|
kfree(priv->gfargrp[i].irqinfo[j]);
|
|
|
|
priv->gfargrp[i].irqinfo[j] = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
free_netdev(priv->ndev);
|
|
|
|
}
|
|
|
|
|
2009-11-02 15:03:34 +08:00
|
|
|
static void disable_napi(struct gfar_private *priv)
|
|
|
|
{
|
2012-06-05 11:42:14 +08:00
|
|
|
int i;
|
2009-11-02 15:03:34 +08:00
|
|
|
|
2014-03-07 20:42:45 +08:00
|
|
|
for (i = 0; i < priv->num_grps; i++) {
|
|
|
|
napi_disable(&priv->gfargrp[i].napi_rx);
|
|
|
|
napi_disable(&priv->gfargrp[i].napi_tx);
|
|
|
|
}
|
2009-11-02 15:03:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void enable_napi(struct gfar_private *priv)
|
|
|
|
{
|
2012-06-05 11:42:14 +08:00
|
|
|
int i;
|
2009-11-02 15:03:34 +08:00
|
|
|
|
2014-03-07 20:42:45 +08:00
|
|
|
for (i = 0; i < priv->num_grps; i++) {
|
|
|
|
napi_enable(&priv->gfargrp[i].napi_rx);
|
|
|
|
napi_enable(&priv->gfargrp[i].napi_tx);
|
|
|
|
}
|
2009-11-02 15:03:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int gfar_parse_group(struct device_node *np,
|
2012-06-05 11:42:13 +08:00
|
|
|
struct gfar_private *priv, const char *model)
|
2009-11-02 15:03:34 +08:00
|
|
|
{
|
2013-01-29 11:55:11 +08:00
|
|
|
struct gfar_priv_grp *grp = &priv->gfargrp[priv->num_grps];
|
2013-01-29 11:55:12 +08:00
|
|
|
int i;
|
|
|
|
|
2013-02-04 17:49:42 +08:00
|
|
|
for (i = 0; i < GFAR_NUM_IRQS; i++) {
|
|
|
|
grp->irqinfo[i] = kzalloc(sizeof(struct gfar_irqinfo),
|
|
|
|
GFP_KERNEL);
|
|
|
|
if (!grp->irqinfo[i])
|
2013-01-29 11:55:12 +08:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
2009-11-02 15:03:34 +08:00
|
|
|
|
2013-01-29 11:55:11 +08:00
|
|
|
grp->regs = of_iomap(np, 0);
|
|
|
|
if (!grp->regs)
|
2009-11-02 15:03:34 +08:00
|
|
|
return -ENOMEM;
|
|
|
|
|
2013-01-29 11:55:12 +08:00
|
|
|
gfar_irq(grp, TX)->irq = irq_of_parse_and_map(np, 0);
|
2009-11-02 15:03:34 +08:00
|
|
|
|
|
|
|
/* If we aren't the FEC we have multiple interrupts */
|
|
|
|
if (model && strcasecmp(model, "FEC")) {
|
2013-01-29 11:55:12 +08:00
|
|
|
gfar_irq(grp, RX)->irq = irq_of_parse_and_map(np, 1);
|
|
|
|
gfar_irq(grp, ER)->irq = irq_of_parse_and_map(np, 2);
|
2015-11-26 19:59:45 +08:00
|
|
|
if (!gfar_irq(grp, TX)->irq ||
|
|
|
|
!gfar_irq(grp, RX)->irq ||
|
|
|
|
!gfar_irq(grp, ER)->irq)
|
2009-11-02 15:03:34 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2013-01-29 11:55:11 +08:00
|
|
|
grp->priv = priv;
|
|
|
|
spin_lock_init(&grp->grplock);
|
2012-06-05 11:42:13 +08:00
|
|
|
if (priv->mode == MQ_MG_MODE) {
|
gianfar: Drop GFAR_MQ_POLLING support
Gianfar used to enable all 8 Rx queues (DMA rings) per
ethernet device, even though the controller can only
support 2 interrupt lines at most. This meant that
multiple Rx queues would have to be grouped per NAPI poll
routine, and the CPU would have to split the budget and
service them in a round robin manner. The overhead of
this scheme proved to outweight the potential benefits.
The alternative was to introduce the "Single Queue" polling
mode, supporting one Rx queue per NAPI, which became the
default packet processing option and helped improve the
performance of the driver.
MQ_POLLING also relies on undocumeted device tree properties
to specify how to map the 8 Rx and Tx queues to a given
interrupt line (aka "interrupt group"). Using module parameters
to enable this mode wasn't an option either. Long story short,
MQ_POLLING became obsolete, now it is just dead code, and no
one asked for it so far.
For the Tx queues, multi-queue support (more than 1 Tx queue
per CPU) could be revisited by adding tc MQPRIO support, but
again, one has to consider that there are only 2 interrupt lines.
So the NAPI poll routine would have to service multiple Tx rings.
Signed-off-by: Claudiu Manoil <claudiu.manoil@nxp.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2021-04-17 01:11:22 +08:00
|
|
|
/* One Q per interrupt group: Q0 to G0, Q1 to G1 */
|
2015-03-13 16:52:32 +08:00
|
|
|
grp->rx_bit_map = (DEFAULT_MAPPING >> priv->num_grps);
|
|
|
|
grp->tx_bit_map = (DEFAULT_MAPPING >> priv->num_grps);
|
2009-11-02 15:03:34 +08:00
|
|
|
} else {
|
2013-01-29 11:55:11 +08:00
|
|
|
grp->rx_bit_map = 0xFF;
|
|
|
|
grp->tx_bit_map = 0xFF;
|
2009-11-02 15:03:34 +08:00
|
|
|
}
|
2014-02-17 18:53:14 +08:00
|
|
|
|
|
|
|
/* bit_map's MSB is q0 (from q0 to q7) but, for_each_set_bit parses
|
|
|
|
* right to left, so we need to revert the 8 bits to get the q index
|
|
|
|
*/
|
|
|
|
grp->rx_bit_map = bitrev8(grp->rx_bit_map);
|
|
|
|
grp->tx_bit_map = bitrev8(grp->tx_bit_map);
|
|
|
|
|
|
|
|
/* Calculate RSTAT, TSTAT, RQUEUE and TQUEUE values,
|
|
|
|
* also assign queues to groups
|
|
|
|
*/
|
|
|
|
for_each_set_bit(i, &grp->rx_bit_map, priv->num_rx_queues) {
|
gianfar: Use Single-Queue polling for "fsl,etsec2"
For the "fsl,etsec2" compatible models the driver currently
supports 8 Tx and Rx DMA rings (aka HW queues). However, there
are only 2 pairs of Rx/Tx interrupt lines, as these controllers
are integrated in low power SoCs with 2 CPUs at most. As a result,
there are at most 2 NAPI instances that have to service multiple
Tx and Rx queues for these devices. This complicates the NAPI
polling routine having to iterate over the mutiple Rx/Tx queues
hooked to the same interrupt lines. And there's also an overhead
at HW level, as the controller needs to service all the 8 Tx rings
in a round robin manner. The combined overhead shows up for multi
parallel Tx flows transmitted by the kernel stack, when the driver
usually starts returning NETDEV_TX_BUSY leading to NETDEV WATCHDOG
Tx timeout triggering if the Tx path is congested for too long.
As an alternative, this patch makes the driver support only one
Tx/Rx DMA ring per NAPI instance (per interrupt group or pair
of Tx/Rx interrupt lines) by default. The simplified single queue
polling routine (gfar_poll_sq) will be the default napi poll routine
for the etsec2 devices too. Some adjustments needed to be made to
link the Tx/Rx HW queues with each NAPI instance (2 in this case).
The gfar_poll_sq() is already successfully used by older SQ_SG_MODE
(single interrupt group) controllers.
This patch fixes Tx timeout triggering under heavy Tx traffic load
(i.e. iperf -c -P 8) for the "fsl,etsec2" (currently the only
MQ_MG_MODE devices). There's also a significant memory footprint
reduction by supporting 2 Rx/Tx DMA rings (at most), instead of 8,
for these devices.
Signed-off-by: Claudiu Manoil <claudiu.manoil@freescale.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-03-07 20:42:46 +08:00
|
|
|
if (!grp->rx_queue)
|
|
|
|
grp->rx_queue = priv->rx_queue[i];
|
2014-02-17 18:53:14 +08:00
|
|
|
grp->num_rx_queues++;
|
|
|
|
grp->rstat |= (RSTAT_CLEAR_RHALT >> i);
|
|
|
|
priv->rqueue |= ((RQUEUE_EN0 | RQUEUE_EX0) >> i);
|
|
|
|
priv->rx_queue[i]->grp = grp;
|
|
|
|
}
|
|
|
|
|
|
|
|
for_each_set_bit(i, &grp->tx_bit_map, priv->num_tx_queues) {
|
gianfar: Use Single-Queue polling for "fsl,etsec2"
For the "fsl,etsec2" compatible models the driver currently
supports 8 Tx and Rx DMA rings (aka HW queues). However, there
are only 2 pairs of Rx/Tx interrupt lines, as these controllers
are integrated in low power SoCs with 2 CPUs at most. As a result,
there are at most 2 NAPI instances that have to service multiple
Tx and Rx queues for these devices. This complicates the NAPI
polling routine having to iterate over the mutiple Rx/Tx queues
hooked to the same interrupt lines. And there's also an overhead
at HW level, as the controller needs to service all the 8 Tx rings
in a round robin manner. The combined overhead shows up for multi
parallel Tx flows transmitted by the kernel stack, when the driver
usually starts returning NETDEV_TX_BUSY leading to NETDEV WATCHDOG
Tx timeout triggering if the Tx path is congested for too long.
As an alternative, this patch makes the driver support only one
Tx/Rx DMA ring per NAPI instance (per interrupt group or pair
of Tx/Rx interrupt lines) by default. The simplified single queue
polling routine (gfar_poll_sq) will be the default napi poll routine
for the etsec2 devices too. Some adjustments needed to be made to
link the Tx/Rx HW queues with each NAPI instance (2 in this case).
The gfar_poll_sq() is already successfully used by older SQ_SG_MODE
(single interrupt group) controllers.
This patch fixes Tx timeout triggering under heavy Tx traffic load
(i.e. iperf -c -P 8) for the "fsl,etsec2" (currently the only
MQ_MG_MODE devices). There's also a significant memory footprint
reduction by supporting 2 Rx/Tx DMA rings (at most), instead of 8,
for these devices.
Signed-off-by: Claudiu Manoil <claudiu.manoil@freescale.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-03-07 20:42:46 +08:00
|
|
|
if (!grp->tx_queue)
|
|
|
|
grp->tx_queue = priv->tx_queue[i];
|
2014-02-17 18:53:14 +08:00
|
|
|
grp->num_tx_queues++;
|
|
|
|
grp->tstat |= (TSTAT_CLEAR_THALT >> i);
|
|
|
|
priv->tqueue |= (TQUEUE_EN0 >> i);
|
|
|
|
priv->tx_queue[i]->grp = grp;
|
|
|
|
}
|
|
|
|
|
2009-11-02 15:03:34 +08:00
|
|
|
priv->num_grps++;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-03-05 21:48:23 +08:00
|
|
|
static int gfar_of_group_count(struct device_node *np)
|
|
|
|
{
|
|
|
|
struct device_node *child;
|
|
|
|
int num = 0;
|
|
|
|
|
|
|
|
for_each_available_child_of_node(np, child)
|
2018-12-06 03:50:32 +08:00
|
|
|
if (of_node_name_eq(child, "queue-group"))
|
2015-03-05 21:48:23 +08:00
|
|
|
num++;
|
|
|
|
|
|
|
|
return num;
|
|
|
|
}
|
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
/* Reads the controller's registers to determine what interface
|
|
|
|
* connects it to the PHY.
|
|
|
|
*/
|
|
|
|
static phy_interface_t gfar_get_interface(struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct gfar_private *priv = netdev_priv(dev);
|
|
|
|
struct gfar __iomem *regs = priv->gfargrp[0].regs;
|
|
|
|
u32 ecntrl;
|
|
|
|
|
|
|
|
ecntrl = gfar_read(®s->ecntrl);
|
|
|
|
|
|
|
|
if (ecntrl & ECNTRL_SGMII_MODE)
|
|
|
|
return PHY_INTERFACE_MODE_SGMII;
|
|
|
|
|
|
|
|
if (ecntrl & ECNTRL_TBI_MODE) {
|
|
|
|
if (ecntrl & ECNTRL_REDUCED_MODE)
|
|
|
|
return PHY_INTERFACE_MODE_RTBI;
|
|
|
|
else
|
|
|
|
return PHY_INTERFACE_MODE_TBI;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ecntrl & ECNTRL_REDUCED_MODE) {
|
|
|
|
if (ecntrl & ECNTRL_REDUCED_MII_MODE) {
|
|
|
|
return PHY_INTERFACE_MODE_RMII;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
phy_interface_t interface = priv->interface;
|
|
|
|
|
|
|
|
/* This isn't autodetected right now, so it must
|
|
|
|
* be set by the device tree or platform code.
|
|
|
|
*/
|
|
|
|
if (interface == PHY_INTERFACE_MODE_RGMII_ID)
|
|
|
|
return PHY_INTERFACE_MODE_RGMII_ID;
|
|
|
|
|
|
|
|
return PHY_INTERFACE_MODE_RGMII;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (priv->device_flags & FSL_GIANFAR_DEV_HAS_GIGABIT)
|
|
|
|
return PHY_INTERFACE_MODE_GMII;
|
|
|
|
|
|
|
|
return PHY_INTERFACE_MODE_MII;
|
|
|
|
}
|
|
|
|
|
2010-08-06 23:25:50 +08:00
|
|
|
static int gfar_of_init(struct platform_device *ofdev, struct net_device **pdev)
|
2008-12-17 07:29:15 +08:00
|
|
|
{
|
|
|
|
const char *model;
|
2009-11-02 15:03:15 +08:00
|
|
|
int err = 0, i;
|
net: of_get_phy_mode: Change API to solve int/unit warnings
Before this change of_get_phy_mode() returned an enum,
phy_interface_t. On error, -ENODEV etc, is returned. If the result of
the function is stored in a variable of type phy_interface_t, and the
compiler has decided to represent this as an unsigned int, comparision
with -ENODEV etc, is a signed vs unsigned comparision.
Fix this problem by changing the API. Make the function return an
error, or 0 on success, and pass a pointer, of type phy_interface_t,
where the phy mode should be stored.
v2:
Return with *interface set to PHY_INTERFACE_MODE_NA on error.
Add error checks to all users of of_get_phy_mode()
Fixup a few reverse christmas tree errors
Fixup a few slightly malformed reverse christmas trees
v3:
Fix 0-day reported errors.
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: David S. Miller <davem@davemloft.net>
2019-11-04 09:40:33 +08:00
|
|
|
phy_interface_t interface;
|
2009-11-02 15:03:15 +08:00
|
|
|
struct net_device *dev = NULL;
|
|
|
|
struct gfar_private *priv = NULL;
|
2010-04-14 07:12:29 +08:00
|
|
|
struct device_node *np = ofdev->dev.of_node;
|
2009-11-02 15:03:34 +08:00
|
|
|
struct device_node *child = NULL;
|
2015-03-13 16:52:32 +08:00
|
|
|
u32 stash_len = 0;
|
|
|
|
u32 stash_idx = 0;
|
2009-11-02 15:03:15 +08:00
|
|
|
unsigned int num_tx_qs, num_rx_qs;
|
gianfar: Drop GFAR_MQ_POLLING support
Gianfar used to enable all 8 Rx queues (DMA rings) per
ethernet device, even though the controller can only
support 2 interrupt lines at most. This meant that
multiple Rx queues would have to be grouped per NAPI poll
routine, and the CPU would have to split the budget and
service them in a round robin manner. The overhead of
this scheme proved to outweight the potential benefits.
The alternative was to introduce the "Single Queue" polling
mode, supporting one Rx queue per NAPI, which became the
default packet processing option and helped improve the
performance of the driver.
MQ_POLLING also relies on undocumeted device tree properties
to specify how to map the 8 Rx and Tx queues to a given
interrupt line (aka "interrupt group"). Using module parameters
to enable this mode wasn't an option either. Long story short,
MQ_POLLING became obsolete, now it is just dead code, and no
one asked for it so far.
For the Tx queues, multi-queue support (more than 1 Tx queue
per CPU) could be revisited by adding tc MQPRIO support, but
again, one has to consider that there are only 2 interrupt lines.
So the NAPI poll routine would have to service multiple Tx rings.
Signed-off-by: Claudiu Manoil <claudiu.manoil@nxp.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2021-04-17 01:11:22 +08:00
|
|
|
unsigned short mode;
|
2008-12-17 07:29:15 +08:00
|
|
|
|
2015-01-28 20:06:48 +08:00
|
|
|
if (!np)
|
2008-12-17 07:29:15 +08:00
|
|
|
return -ENODEV;
|
|
|
|
|
gianfar: Drop GFAR_MQ_POLLING support
Gianfar used to enable all 8 Rx queues (DMA rings) per
ethernet device, even though the controller can only
support 2 interrupt lines at most. This meant that
multiple Rx queues would have to be grouped per NAPI poll
routine, and the CPU would have to split the budget and
service them in a round robin manner. The overhead of
this scheme proved to outweight the potential benefits.
The alternative was to introduce the "Single Queue" polling
mode, supporting one Rx queue per NAPI, which became the
default packet processing option and helped improve the
performance of the driver.
MQ_POLLING also relies on undocumeted device tree properties
to specify how to map the 8 Rx and Tx queues to a given
interrupt line (aka "interrupt group"). Using module parameters
to enable this mode wasn't an option either. Long story short,
MQ_POLLING became obsolete, now it is just dead code, and no
one asked for it so far.
For the Tx queues, multi-queue support (more than 1 Tx queue
per CPU) could be revisited by adding tc MQPRIO support, but
again, one has to consider that there are only 2 interrupt lines.
So the NAPI poll routine would have to service multiple Tx rings.
Signed-off-by: Claudiu Manoil <claudiu.manoil@nxp.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2021-04-17 01:11:22 +08:00
|
|
|
if (of_device_is_compatible(np, "fsl,etsec2"))
|
2014-03-12 00:01:24 +08:00
|
|
|
mode = MQ_MG_MODE;
|
gianfar: Drop GFAR_MQ_POLLING support
Gianfar used to enable all 8 Rx queues (DMA rings) per
ethernet device, even though the controller can only
support 2 interrupt lines at most. This meant that
multiple Rx queues would have to be grouped per NAPI poll
routine, and the CPU would have to split the budget and
service them in a round robin manner. The overhead of
this scheme proved to outweight the potential benefits.
The alternative was to introduce the "Single Queue" polling
mode, supporting one Rx queue per NAPI, which became the
default packet processing option and helped improve the
performance of the driver.
MQ_POLLING also relies on undocumeted device tree properties
to specify how to map the 8 Rx and Tx queues to a given
interrupt line (aka "interrupt group"). Using module parameters
to enable this mode wasn't an option either. Long story short,
MQ_POLLING became obsolete, now it is just dead code, and no
one asked for it so far.
For the Tx queues, multi-queue support (more than 1 Tx queue
per CPU) could be revisited by adding tc MQPRIO support, but
again, one has to consider that there are only 2 interrupt lines.
So the NAPI poll routine would have to service multiple Tx rings.
Signed-off-by: Claudiu Manoil <claudiu.manoil@nxp.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2021-04-17 01:11:22 +08:00
|
|
|
else
|
2014-03-12 00:01:24 +08:00
|
|
|
mode = SQ_SG_MODE;
|
|
|
|
|
|
|
|
if (mode == SQ_SG_MODE) {
|
gianfar: Use Single-Queue polling for "fsl,etsec2"
For the "fsl,etsec2" compatible models the driver currently
supports 8 Tx and Rx DMA rings (aka HW queues). However, there
are only 2 pairs of Rx/Tx interrupt lines, as these controllers
are integrated in low power SoCs with 2 CPUs at most. As a result,
there are at most 2 NAPI instances that have to service multiple
Tx and Rx queues for these devices. This complicates the NAPI
polling routine having to iterate over the mutiple Rx/Tx queues
hooked to the same interrupt lines. And there's also an overhead
at HW level, as the controller needs to service all the 8 Tx rings
in a round robin manner. The combined overhead shows up for multi
parallel Tx flows transmitted by the kernel stack, when the driver
usually starts returning NETDEV_TX_BUSY leading to NETDEV WATCHDOG
Tx timeout triggering if the Tx path is congested for too long.
As an alternative, this patch makes the driver support only one
Tx/Rx DMA ring per NAPI instance (per interrupt group or pair
of Tx/Rx interrupt lines) by default. The simplified single queue
polling routine (gfar_poll_sq) will be the default napi poll routine
for the etsec2 devices too. Some adjustments needed to be made to
link the Tx/Rx HW queues with each NAPI instance (2 in this case).
The gfar_poll_sq() is already successfully used by older SQ_SG_MODE
(single interrupt group) controllers.
This patch fixes Tx timeout triggering under heavy Tx traffic load
(i.e. iperf -c -P 8) for the "fsl,etsec2" (currently the only
MQ_MG_MODE devices). There's also a significant memory footprint
reduction by supporting 2 Rx/Tx DMA rings (at most), instead of 8,
for these devices.
Signed-off-by: Claudiu Manoil <claudiu.manoil@freescale.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-03-07 20:42:46 +08:00
|
|
|
num_tx_qs = 1;
|
|
|
|
num_rx_qs = 1;
|
|
|
|
} else { /* MQ_MG_MODE */
|
2014-03-21 15:33:17 +08:00
|
|
|
/* get the actual number of supported groups */
|
2015-03-05 21:48:23 +08:00
|
|
|
unsigned int num_grps = gfar_of_group_count(np);
|
2014-03-21 15:33:17 +08:00
|
|
|
|
|
|
|
if (num_grps == 0 || num_grps > MAXGROUPS) {
|
|
|
|
dev_err(&ofdev->dev, "Invalid # of int groups(%d)\n",
|
|
|
|
num_grps);
|
|
|
|
pr_err("Cannot do alloc_etherdev, aborting\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
gianfar: Drop GFAR_MQ_POLLING support
Gianfar used to enable all 8 Rx queues (DMA rings) per
ethernet device, even though the controller can only
support 2 interrupt lines at most. This meant that
multiple Rx queues would have to be grouped per NAPI poll
routine, and the CPU would have to split the budget and
service them in a round robin manner. The overhead of
this scheme proved to outweight the potential benefits.
The alternative was to introduce the "Single Queue" polling
mode, supporting one Rx queue per NAPI, which became the
default packet processing option and helped improve the
performance of the driver.
MQ_POLLING also relies on undocumeted device tree properties
to specify how to map the 8 Rx and Tx queues to a given
interrupt line (aka "interrupt group"). Using module parameters
to enable this mode wasn't an option either. Long story short,
MQ_POLLING became obsolete, now it is just dead code, and no
one asked for it so far.
For the Tx queues, multi-queue support (more than 1 Tx queue
per CPU) could be revisited by adding tc MQPRIO support, but
again, one has to consider that there are only 2 interrupt lines.
So the NAPI poll routine would have to service multiple Tx rings.
Signed-off-by: Claudiu Manoil <claudiu.manoil@nxp.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2021-04-17 01:11:22 +08:00
|
|
|
num_tx_qs = num_grps; /* one txq per int group */
|
|
|
|
num_rx_qs = num_grps; /* one rxq per int group */
|
gianfar: Use Single-Queue polling for "fsl,etsec2"
For the "fsl,etsec2" compatible models the driver currently
supports 8 Tx and Rx DMA rings (aka HW queues). However, there
are only 2 pairs of Rx/Tx interrupt lines, as these controllers
are integrated in low power SoCs with 2 CPUs at most. As a result,
there are at most 2 NAPI instances that have to service multiple
Tx and Rx queues for these devices. This complicates the NAPI
polling routine having to iterate over the mutiple Rx/Tx queues
hooked to the same interrupt lines. And there's also an overhead
at HW level, as the controller needs to service all the 8 Tx rings
in a round robin manner. The combined overhead shows up for multi
parallel Tx flows transmitted by the kernel stack, when the driver
usually starts returning NETDEV_TX_BUSY leading to NETDEV WATCHDOG
Tx timeout triggering if the Tx path is congested for too long.
As an alternative, this patch makes the driver support only one
Tx/Rx DMA ring per NAPI instance (per interrupt group or pair
of Tx/Rx interrupt lines) by default. The simplified single queue
polling routine (gfar_poll_sq) will be the default napi poll routine
for the etsec2 devices too. Some adjustments needed to be made to
link the Tx/Rx HW queues with each NAPI instance (2 in this case).
The gfar_poll_sq() is already successfully used by older SQ_SG_MODE
(single interrupt group) controllers.
This patch fixes Tx timeout triggering under heavy Tx traffic load
(i.e. iperf -c -P 8) for the "fsl,etsec2" (currently the only
MQ_MG_MODE devices). There's also a significant memory footprint
reduction by supporting 2 Rx/Tx DMA rings (at most), instead of 8,
for these devices.
Signed-off-by: Claudiu Manoil <claudiu.manoil@freescale.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-03-07 20:42:46 +08:00
|
|
|
}
|
2009-11-02 15:03:15 +08:00
|
|
|
|
|
|
|
if (num_tx_qs > MAX_TX_QS) {
|
2011-06-14 16:57:47 +08:00
|
|
|
pr_err("num_tx_qs(=%d) greater than MAX_TX_QS(=%d)\n",
|
|
|
|
num_tx_qs, MAX_TX_QS);
|
|
|
|
pr_err("Cannot do alloc_etherdev, aborting\n");
|
2009-11-02 15:03:15 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (num_rx_qs > MAX_RX_QS) {
|
2011-06-14 16:57:47 +08:00
|
|
|
pr_err("num_rx_qs(=%d) greater than MAX_RX_QS(=%d)\n",
|
|
|
|
num_rx_qs, MAX_RX_QS);
|
|
|
|
pr_err("Cannot do alloc_etherdev, aborting\n");
|
2009-11-02 15:03:15 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
*pdev = alloc_etherdev_mq(sizeof(*priv), num_tx_qs);
|
|
|
|
dev = *pdev;
|
|
|
|
if (NULL == dev)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
priv = netdev_priv(dev);
|
|
|
|
priv->ndev = dev;
|
|
|
|
|
2014-03-12 00:01:24 +08:00
|
|
|
priv->mode = mode;
|
|
|
|
|
2009-11-02 15:03:15 +08:00
|
|
|
priv->num_tx_queues = num_tx_qs;
|
2010-09-27 16:27:37 +08:00
|
|
|
netif_set_real_num_rx_queues(dev, num_rx_qs);
|
2009-11-02 15:03:15 +08:00
|
|
|
priv->num_rx_queues = num_rx_qs;
|
2014-02-17 18:53:14 +08:00
|
|
|
|
|
|
|
err = gfar_alloc_tx_queues(priv);
|
|
|
|
if (err)
|
|
|
|
goto tx_alloc_failed;
|
|
|
|
|
|
|
|
err = gfar_alloc_rx_queues(priv);
|
|
|
|
if (err)
|
|
|
|
goto rx_alloc_failed;
|
2008-12-17 07:29:15 +08:00
|
|
|
|
2015-03-13 16:52:32 +08:00
|
|
|
err = of_property_read_string(np, "model", &model);
|
|
|
|
if (err) {
|
|
|
|
pr_err("Device model property missing, aborting\n");
|
|
|
|
goto rx_alloc_failed;
|
|
|
|
}
|
|
|
|
|
2012-06-05 11:42:12 +08:00
|
|
|
/* Init Rx queue filer rule set linked list */
|
2011-06-21 04:57:59 +08:00
|
|
|
INIT_LIST_HEAD(&priv->rx_list.list);
|
|
|
|
priv->rx_list.count = 0;
|
|
|
|
mutex_init(&priv->rx_queue_access);
|
|
|
|
|
2009-11-02 15:03:34 +08:00
|
|
|
for (i = 0; i < MAXGROUPS; i++)
|
|
|
|
priv->gfargrp[i].regs = NULL;
|
2008-12-17 07:29:15 +08:00
|
|
|
|
2009-11-02 15:03:34 +08:00
|
|
|
/* Parse and initialize group specific information */
|
2014-03-12 00:01:24 +08:00
|
|
|
if (priv->mode == MQ_MG_MODE) {
|
2015-03-05 21:48:23 +08:00
|
|
|
for_each_available_child_of_node(np, child) {
|
2018-12-06 03:50:32 +08:00
|
|
|
if (!of_node_name_eq(child, "queue-group"))
|
2015-03-05 21:48:23 +08:00
|
|
|
continue;
|
|
|
|
|
2009-11-02 15:03:34 +08:00
|
|
|
err = gfar_parse_group(child, priv, model);
|
2020-08-19 02:52:41 +08:00
|
|
|
if (err) {
|
|
|
|
of_node_put(child);
|
2009-11-02 15:03:34 +08:00
|
|
|
goto err_grp_init;
|
2020-08-19 02:52:41 +08:00
|
|
|
}
|
2008-12-17 07:29:15 +08:00
|
|
|
}
|
2014-03-12 00:01:24 +08:00
|
|
|
} else { /* SQ_SG_MODE */
|
2009-11-02 15:03:34 +08:00
|
|
|
err = gfar_parse_group(np, priv, model);
|
2012-06-05 11:42:13 +08:00
|
|
|
if (err)
|
2009-11-02 15:03:34 +08:00
|
|
|
goto err_grp_init;
|
2008-12-17 07:29:15 +08:00
|
|
|
}
|
|
|
|
|
2015-11-21 01:53:58 +08:00
|
|
|
if (of_property_read_bool(np, "bd-stash")) {
|
2009-02-05 08:43:44 +08:00
|
|
|
priv->device_flags |= FSL_GIANFAR_DEV_HAS_BD_STASHING;
|
|
|
|
priv->bd_stash_en = 1;
|
|
|
|
}
|
|
|
|
|
2015-03-13 16:52:32 +08:00
|
|
|
err = of_property_read_u32(np, "rx-stash-len", &stash_len);
|
2009-02-05 08:43:44 +08:00
|
|
|
|
2015-03-13 16:52:32 +08:00
|
|
|
if (err == 0)
|
|
|
|
priv->rx_stash_size = stash_len;
|
2009-02-05 08:43:44 +08:00
|
|
|
|
2015-03-13 16:52:32 +08:00
|
|
|
err = of_property_read_u32(np, "rx-stash-idx", &stash_idx);
|
2009-02-05 08:43:44 +08:00
|
|
|
|
2015-03-13 16:52:32 +08:00
|
|
|
if (err == 0)
|
|
|
|
priv->rx_stash_index = stash_idx;
|
2009-02-05 08:43:44 +08:00
|
|
|
|
|
|
|
if (stash_len || stash_idx)
|
|
|
|
priv->device_flags |= FSL_GIANFAR_DEV_HAS_BUF_STASHING;
|
|
|
|
|
2021-10-07 09:06:56 +08:00
|
|
|
err = of_get_ethdev_address(np, dev);
|
of: net: pass the dst buffer to of_get_mac_address()
of_get_mac_address() returns a "const void*" pointer to a MAC address.
Lately, support to fetch the MAC address by an NVMEM provider was added.
But this will only work with platform devices. It will not work with
PCI devices (e.g. of an integrated root complex) and esp. not with DSA
ports.
There is an of_* variant of the nvmem binding which works without
devices. The returned data of a nvmem_cell_read() has to be freed after
use. On the other hand the return of_get_mac_address() points to some
static data without a lifetime. The trick for now, was to allocate a
device resource managed buffer which is then returned. This will only
work if we have an actual device.
Change it, so that the caller of of_get_mac_address() has to supply a
buffer where the MAC address is written to. Unfortunately, this will
touch all drivers which use the of_get_mac_address().
Usually the code looks like:
const char *addr;
addr = of_get_mac_address(np);
if (!IS_ERR(addr))
ether_addr_copy(ndev->dev_addr, addr);
This can then be simply rewritten as:
of_get_mac_address(np, ndev->dev_addr);
Sometimes is_valid_ether_addr() is used to test the MAC address.
of_get_mac_address() already makes sure, it just returns a valid MAC
address. Thus we can just test its return code. But we have to be
careful if there are still other sources for the MAC address before the
of_get_mac_address(). In this case we have to keep the
is_valid_ether_addr() call.
The following coccinelle patch was used to convert common cases to the
new style. Afterwards, I've manually gone over the drivers and fixed the
return code variable: either used a new one or if one was already
available use that. Mansour Moufid, thanks for that coccinelle patch!
<spml>
@a@
identifier x;
expression y, z;
@@
- x = of_get_mac_address(y);
+ x = of_get_mac_address(y, z);
<...
- ether_addr_copy(z, x);
...>
@@
identifier a.x;
@@
- if (<+... x ...+>) {}
@@
identifier a.x;
@@
if (<+... x ...+>) {
...
}
- else {}
@@
identifier a.x;
expression e;
@@
- if (<+... x ...+>@e)
- {}
- else
+ if (!(e))
{...}
@@
expression x, y, z;
@@
- x = of_get_mac_address(y, z);
+ of_get_mac_address(y, z);
... when != x
</spml>
All drivers, except drivers/net/ethernet/aeroflex/greth.c, were
compile-time tested.
Suggested-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: Michael Walle <michael@walle.cc>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: David S. Miller <davem@davemloft.net>
2021-04-13 01:47:17 +08:00
|
|
|
if (err) {
|
2020-07-14 20:01:04 +08:00
|
|
|
eth_hw_addr_random(dev);
|
|
|
|
dev_info(&ofdev->dev, "Using random MAC address: %pM\n", dev->dev_addr);
|
|
|
|
}
|
2008-12-17 07:29:15 +08:00
|
|
|
|
|
|
|
if (model && !strcasecmp(model, "TSEC"))
|
2014-02-17 18:53:15 +08:00
|
|
|
priv->device_flags |= FSL_GIANFAR_DEV_HAS_GIGABIT |
|
2012-06-05 11:42:13 +08:00
|
|
|
FSL_GIANFAR_DEV_HAS_COALESCE |
|
|
|
|
FSL_GIANFAR_DEV_HAS_RMON |
|
|
|
|
FSL_GIANFAR_DEV_HAS_MULTI_INTR;
|
|
|
|
|
2008-12-17 07:29:15 +08:00
|
|
|
if (model && !strcasecmp(model, "eTSEC"))
|
2014-02-17 18:53:15 +08:00
|
|
|
priv->device_flags |= FSL_GIANFAR_DEV_HAS_GIGABIT |
|
2012-06-05 11:42:13 +08:00
|
|
|
FSL_GIANFAR_DEV_HAS_COALESCE |
|
|
|
|
FSL_GIANFAR_DEV_HAS_RMON |
|
|
|
|
FSL_GIANFAR_DEV_HAS_MULTI_INTR |
|
|
|
|
FSL_GIANFAR_DEV_HAS_CSUM |
|
|
|
|
FSL_GIANFAR_DEV_HAS_VLAN |
|
|
|
|
FSL_GIANFAR_DEV_HAS_MAGIC_PACKET |
|
|
|
|
FSL_GIANFAR_DEV_HAS_EXTENDED_HASH |
|
2015-12-15 09:14:50 +08:00
|
|
|
FSL_GIANFAR_DEV_HAS_TIMER |
|
|
|
|
FSL_GIANFAR_DEV_HAS_RX_FILER;
|
2008-12-17 07:29:15 +08:00
|
|
|
|
2019-09-04 21:52:22 +08:00
|
|
|
/* Use PHY connection type from the DT node if one is specified there.
|
|
|
|
* rgmii-id really needs to be specified. Other types can be
|
|
|
|
* detected by hardware
|
|
|
|
*/
|
net: of_get_phy_mode: Change API to solve int/unit warnings
Before this change of_get_phy_mode() returned an enum,
phy_interface_t. On error, -ENODEV etc, is returned. If the result of
the function is stored in a variable of type phy_interface_t, and the
compiler has decided to represent this as an unsigned int, comparision
with -ENODEV etc, is a signed vs unsigned comparision.
Fix this problem by changing the API. Make the function return an
error, or 0 on success, and pass a pointer, of type phy_interface_t,
where the phy mode should be stored.
v2:
Return with *interface set to PHY_INTERFACE_MODE_NA on error.
Add error checks to all users of of_get_phy_mode()
Fixup a few reverse christmas tree errors
Fixup a few slightly malformed reverse christmas trees
v3:
Fix 0-day reported errors.
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: David S. Miller <davem@davemloft.net>
2019-11-04 09:40:33 +08:00
|
|
|
err = of_get_phy_mode(np, &interface);
|
|
|
|
if (!err)
|
|
|
|
priv->interface = interface;
|
2008-12-17 07:29:15 +08:00
|
|
|
else
|
2019-09-04 21:52:22 +08:00
|
|
|
priv->interface = gfar_get_interface(dev);
|
2008-12-17 07:29:15 +08:00
|
|
|
|
2015-03-13 16:52:32 +08:00
|
|
|
if (of_find_property(np, "fsl,magic-packet", NULL))
|
2008-12-17 07:29:15 +08:00
|
|
|
priv->device_flags |= FSL_GIANFAR_DEV_HAS_MAGIC_PACKET;
|
|
|
|
|
2015-10-05 22:19:59 +08:00
|
|
|
if (of_get_property(np, "fsl,wake-on-filer", NULL))
|
|
|
|
priv->device_flags |= FSL_GIANFAR_DEV_HAS_WAKE_ON_FILER;
|
|
|
|
|
2009-04-25 20:53:12 +08:00
|
|
|
priv->phy_node = of_parse_phandle(np, "phy-handle", 0);
|
2008-12-17 07:29:15 +08:00
|
|
|
|
2014-05-23 00:47:48 +08:00
|
|
|
/* In the case of a fixed PHY, the DT node associated
|
|
|
|
* to the PHY is the Ethernet MAC DT node.
|
|
|
|
*/
|
2014-08-08 04:17:07 +08:00
|
|
|
if (!priv->phy_node && of_phy_is_fixed_link(np)) {
|
2014-05-23 00:47:48 +08:00
|
|
|
err = of_phy_register_fixed_link(np);
|
|
|
|
if (err)
|
|
|
|
goto err_grp_init;
|
|
|
|
|
2014-08-08 04:17:07 +08:00
|
|
|
priv->phy_node = of_node_get(np);
|
2014-05-23 00:47:48 +08:00
|
|
|
}
|
|
|
|
|
2008-12-17 07:29:15 +08:00
|
|
|
/* Find the TBI PHY. If it's not there, we don't support SGMII */
|
2009-04-25 20:53:12 +08:00
|
|
|
priv->tbi_node = of_parse_phandle(np, "tbi-handle", 0);
|
2008-12-17 07:29:15 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
2009-11-02 15:03:34 +08:00
|
|
|
err_grp_init:
|
|
|
|
unmap_group_regs(priv);
|
2014-02-17 18:53:14 +08:00
|
|
|
rx_alloc_failed:
|
|
|
|
gfar_free_rx_queues(priv);
|
|
|
|
tx_alloc_failed:
|
|
|
|
gfar_free_tx_queues(priv);
|
2013-01-29 11:55:12 +08:00
|
|
|
free_gfar_dev(priv);
|
2008-12-17 07:29:15 +08:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2009-11-04 20:53:00 +08:00
|
|
|
static u32 cluster_entry_per_class(struct gfar_private *priv, u32 rqfar,
|
|
|
|
u32 class)
|
2009-11-02 15:03:40 +08:00
|
|
|
{
|
|
|
|
u32 rqfpr = FPR_FILER_MASK;
|
|
|
|
u32 rqfcr = 0x0;
|
|
|
|
|
|
|
|
rqfar--;
|
|
|
|
rqfcr = RQFCR_CLE | RQFCR_PID_MASK | RQFCR_CMP_EXACT;
|
2011-06-08 05:46:51 +08:00
|
|
|
priv->ftp_rqfpr[rqfar] = rqfpr;
|
|
|
|
priv->ftp_rqfcr[rqfar] = rqfcr;
|
2009-11-02 15:03:40 +08:00
|
|
|
gfar_write_filer(priv, rqfar, rqfcr, rqfpr);
|
|
|
|
|
|
|
|
rqfar--;
|
|
|
|
rqfcr = RQFCR_CMP_NOMATCH;
|
2011-06-08 05:46:51 +08:00
|
|
|
priv->ftp_rqfpr[rqfar] = rqfpr;
|
|
|
|
priv->ftp_rqfcr[rqfar] = rqfcr;
|
2009-11-02 15:03:40 +08:00
|
|
|
gfar_write_filer(priv, rqfar, rqfcr, rqfpr);
|
|
|
|
|
|
|
|
rqfar--;
|
|
|
|
rqfcr = RQFCR_CMP_EXACT | RQFCR_PID_PARSE | RQFCR_CLE | RQFCR_AND;
|
|
|
|
rqfpr = class;
|
2011-06-08 05:46:51 +08:00
|
|
|
priv->ftp_rqfcr[rqfar] = rqfcr;
|
|
|
|
priv->ftp_rqfpr[rqfar] = rqfpr;
|
2009-11-02 15:03:40 +08:00
|
|
|
gfar_write_filer(priv, rqfar, rqfcr, rqfpr);
|
|
|
|
|
|
|
|
rqfar--;
|
|
|
|
rqfcr = RQFCR_CMP_EXACT | RQFCR_PID_MASK | RQFCR_AND;
|
|
|
|
rqfpr = class;
|
2011-06-08 05:46:51 +08:00
|
|
|
priv->ftp_rqfcr[rqfar] = rqfcr;
|
|
|
|
priv->ftp_rqfpr[rqfar] = rqfpr;
|
2009-11-02 15:03:40 +08:00
|
|
|
gfar_write_filer(priv, rqfar, rqfcr, rqfpr);
|
|
|
|
|
|
|
|
return rqfar;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gfar_init_filer_table(struct gfar_private *priv)
|
|
|
|
{
|
|
|
|
int i = 0x0;
|
|
|
|
u32 rqfar = MAX_FILER_IDX;
|
|
|
|
u32 rqfcr = 0x0;
|
|
|
|
u32 rqfpr = FPR_FILER_MASK;
|
|
|
|
|
|
|
|
/* Default rule */
|
|
|
|
rqfcr = RQFCR_CMP_MATCH;
|
2011-06-08 05:46:51 +08:00
|
|
|
priv->ftp_rqfcr[rqfar] = rqfcr;
|
|
|
|
priv->ftp_rqfpr[rqfar] = rqfpr;
|
2009-11-02 15:03:40 +08:00
|
|
|
gfar_write_filer(priv, rqfar, rqfcr, rqfpr);
|
|
|
|
|
|
|
|
rqfar = cluster_entry_per_class(priv, rqfar, RQFPR_IPV6);
|
|
|
|
rqfar = cluster_entry_per_class(priv, rqfar, RQFPR_IPV6 | RQFPR_UDP);
|
|
|
|
rqfar = cluster_entry_per_class(priv, rqfar, RQFPR_IPV6 | RQFPR_TCP);
|
|
|
|
rqfar = cluster_entry_per_class(priv, rqfar, RQFPR_IPV4);
|
|
|
|
rqfar = cluster_entry_per_class(priv, rqfar, RQFPR_IPV4 | RQFPR_UDP);
|
|
|
|
rqfar = cluster_entry_per_class(priv, rqfar, RQFPR_IPV4 | RQFPR_TCP);
|
|
|
|
|
2010-06-11 18:16:55 +08:00
|
|
|
/* cur_filer_idx indicated the first non-masked rule */
|
2009-11-02 15:03:40 +08:00
|
|
|
priv->cur_filer_idx = rqfar;
|
|
|
|
|
|
|
|
/* Rest are masked rules */
|
|
|
|
rqfcr = RQFCR_CMP_NOMATCH;
|
|
|
|
for (i = 0; i < rqfar; i++) {
|
2011-06-08 05:46:51 +08:00
|
|
|
priv->ftp_rqfcr[i] = rqfcr;
|
|
|
|
priv->ftp_rqfpr[i] = rqfpr;
|
2009-11-02 15:03:40 +08:00
|
|
|
gfar_write_filer(priv, i, rqfcr, rqfpr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-07 15:44:32 +08:00
|
|
|
#ifdef CONFIG_PPC
|
2013-10-10 01:20:41 +08:00
|
|
|
static void __gfar_detect_errata_83xx(struct gfar_private *priv)
|
2010-06-30 14:39:12 +08:00
|
|
|
{
|
|
|
|
unsigned int pvr = mfspr(SPRN_PVR);
|
|
|
|
unsigned int svr = mfspr(SPRN_SVR);
|
|
|
|
unsigned int mod = (svr >> 16) & 0xfff6; /* w/o E suffix */
|
|
|
|
unsigned int rev = svr & 0xffff;
|
|
|
|
|
|
|
|
/* MPC8313 Rev 2.0 and higher; All MPC837x */
|
|
|
|
if ((pvr == 0x80850010 && mod == 0x80b0 && rev >= 0x0020) ||
|
2012-06-05 11:42:13 +08:00
|
|
|
(pvr == 0x80861010 && (mod & 0xfff9) == 0x80c0))
|
2010-06-30 14:39:12 +08:00
|
|
|
priv->errata |= GFAR_ERRATA_74;
|
|
|
|
|
2010-06-30 14:39:13 +08:00
|
|
|
/* MPC8313 and MPC837x all rev */
|
|
|
|
if ((pvr == 0x80850010 && mod == 0x80b0) ||
|
2012-06-05 11:42:13 +08:00
|
|
|
(pvr == 0x80861010 && (mod & 0xfff9) == 0x80c0))
|
2010-06-30 14:39:13 +08:00
|
|
|
priv->errata |= GFAR_ERRATA_76;
|
|
|
|
|
2013-10-10 01:20:41 +08:00
|
|
|
/* MPC8313 Rev < 2.0 */
|
|
|
|
if (pvr == 0x80850010 && mod == 0x80b0 && rev < 0x0020)
|
|
|
|
priv->errata |= GFAR_ERRATA_12;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __gfar_detect_errata_85xx(struct gfar_private *priv)
|
|
|
|
{
|
|
|
|
unsigned int svr = mfspr(SPRN_SVR);
|
|
|
|
|
|
|
|
if ((SVR_SOC_VER(svr) == SVR_8548) && (SVR_REV(svr) == 0x20))
|
2011-03-17 01:57:13 +08:00
|
|
|
priv->errata |= GFAR_ERRATA_12;
|
2016-03-03 08:07:51 +08:00
|
|
|
/* P2020/P1010 Rev 1; MPC8548 Rev 2 */
|
2013-10-10 01:20:42 +08:00
|
|
|
if (((SVR_SOC_VER(svr) == SVR_P2020) && (SVR_REV(svr) < 0x20)) ||
|
2016-03-03 08:07:51 +08:00
|
|
|
((SVR_SOC_VER(svr) == SVR_P2010) && (SVR_REV(svr) < 0x20)) ||
|
|
|
|
((SVR_SOC_VER(svr) == SVR_8548) && (SVR_REV(svr) < 0x31)))
|
2013-10-10 01:20:42 +08:00
|
|
|
priv->errata |= GFAR_ERRATA_76; /* aka eTSEC 20 */
|
2013-10-10 01:20:41 +08:00
|
|
|
}
|
2014-10-07 15:44:32 +08:00
|
|
|
#endif
|
2013-10-10 01:20:41 +08:00
|
|
|
|
|
|
|
static void gfar_detect_errata(struct gfar_private *priv)
|
|
|
|
{
|
|
|
|
struct device *dev = &priv->ofdev->dev;
|
|
|
|
|
|
|
|
/* no plans to fix */
|
|
|
|
priv->errata |= GFAR_ERRATA_A002;
|
|
|
|
|
2014-10-07 15:44:32 +08:00
|
|
|
#ifdef CONFIG_PPC
|
2013-10-10 01:20:41 +08:00
|
|
|
if (pvr_version_is(PVR_VER_E500V1) || pvr_version_is(PVR_VER_E500V2))
|
|
|
|
__gfar_detect_errata_85xx(priv);
|
|
|
|
else /* non-mpc85xx parts, i.e. e300 core based */
|
|
|
|
__gfar_detect_errata_83xx(priv);
|
2014-10-07 15:44:32 +08:00
|
|
|
#endif
|
2011-03-17 01:57:13 +08:00
|
|
|
|
2010-06-30 14:39:12 +08:00
|
|
|
if (priv->errata)
|
|
|
|
dev_info(dev, "enabled errata workarounds, flags: 0x%x\n",
|
|
|
|
priv->errata);
|
|
|
|
}
|
|
|
|
|
2014-06-04 16:49:16 +08:00
|
|
|
static void gfar_init_addr_hash_table(struct gfar_private *priv)
|
2014-02-17 18:53:14 +08:00
|
|
|
{
|
|
|
|
struct gfar __iomem *regs = priv->gfargrp[0].regs;
|
|
|
|
|
|
|
|
if (priv->device_flags & FSL_GIANFAR_DEV_HAS_EXTENDED_HASH) {
|
|
|
|
priv->extended_hash = 1;
|
|
|
|
priv->hash_width = 9;
|
|
|
|
|
|
|
|
priv->hash_regs[0] = ®s->igaddr0;
|
|
|
|
priv->hash_regs[1] = ®s->igaddr1;
|
|
|
|
priv->hash_regs[2] = ®s->igaddr2;
|
|
|
|
priv->hash_regs[3] = ®s->igaddr3;
|
|
|
|
priv->hash_regs[4] = ®s->igaddr4;
|
|
|
|
priv->hash_regs[5] = ®s->igaddr5;
|
|
|
|
priv->hash_regs[6] = ®s->igaddr6;
|
|
|
|
priv->hash_regs[7] = ®s->igaddr7;
|
|
|
|
priv->hash_regs[8] = ®s->gaddr0;
|
|
|
|
priv->hash_regs[9] = ®s->gaddr1;
|
|
|
|
priv->hash_regs[10] = ®s->gaddr2;
|
|
|
|
priv->hash_regs[11] = ®s->gaddr3;
|
|
|
|
priv->hash_regs[12] = ®s->gaddr4;
|
|
|
|
priv->hash_regs[13] = ®s->gaddr5;
|
|
|
|
priv->hash_regs[14] = ®s->gaddr6;
|
|
|
|
priv->hash_regs[15] = ®s->gaddr7;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
priv->extended_hash = 0;
|
|
|
|
priv->hash_width = 8;
|
|
|
|
|
|
|
|
priv->hash_regs[0] = ®s->gaddr0;
|
|
|
|
priv->hash_regs[1] = ®s->gaddr1;
|
|
|
|
priv->hash_regs[2] = ®s->gaddr2;
|
|
|
|
priv->hash_regs[3] = ®s->gaddr3;
|
|
|
|
priv->hash_regs[4] = ®s->gaddr4;
|
|
|
|
priv->hash_regs[5] = ®s->gaddr5;
|
|
|
|
priv->hash_regs[6] = ®s->gaddr6;
|
|
|
|
priv->hash_regs[7] = ®s->gaddr7;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
static int __gfar_is_rx_idle(struct gfar_private *priv)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2019-09-04 21:52:19 +08:00
|
|
|
u32 res;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
/* Normaly TSEC should not hang on GRS commands, so we should
|
|
|
|
* actually wait for IEVENT_GRSC flag.
|
|
|
|
*/
|
|
|
|
if (!gfar_has_errata(priv, GFAR_ERRATA_A002))
|
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
/* Read the eTSEC register at offset 0xD1C. If bits 7-14 are
|
|
|
|
* the same as bits 23-30, the eTSEC Rx is assumed to be idle
|
|
|
|
* and the Rx can be safely reset.
|
|
|
|
*/
|
|
|
|
res = gfar_read((void __iomem *)priv->gfargrp[0].regs + 0xd1c);
|
|
|
|
res &= 0x7f807f80;
|
|
|
|
if ((res & 0xffff) == (res >> 16))
|
|
|
|
return 1;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
/* Halt the receive and transmit queues */
|
|
|
|
static void gfar_halt_nodisable(struct gfar_private *priv)
|
|
|
|
{
|
|
|
|
struct gfar __iomem *regs = priv->gfargrp[0].regs;
|
|
|
|
u32 tempval;
|
|
|
|
unsigned int timeout;
|
|
|
|
int stopped;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
gfar_ints_disable(priv);
|
2010-06-30 14:39:12 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
if (gfar_is_dma_stopped(priv))
|
|
|
|
return;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
/* Stop the DMA, and wait for it to stop */
|
|
|
|
tempval = gfar_read(®s->dmactrl);
|
|
|
|
tempval |= (DMACTRL_GRS | DMACTRL_GTS);
|
|
|
|
gfar_write(®s->dmactrl, tempval);
|
2005-06-20 23:54:21 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
retry:
|
|
|
|
timeout = 1000;
|
|
|
|
while (!(stopped = gfar_is_dma_stopped(priv)) && timeout) {
|
|
|
|
cpu_relax();
|
|
|
|
timeout--;
|
2014-03-07 20:42:45 +08:00
|
|
|
}
|
2009-11-02 15:03:00 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
if (!timeout)
|
|
|
|
stopped = gfar_is_dma_stopped(priv);
|
2005-06-20 23:54:21 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
if (!stopped && !gfar_is_rx_dma_stopped(priv) &&
|
|
|
|
!__gfar_is_rx_idle(priv))
|
|
|
|
goto retry;
|
|
|
|
}
|
2005-06-20 23:54:21 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
/* Halt the receive and transmit queues */
|
2019-09-04 21:52:20 +08:00
|
|
|
static void gfar_halt(struct gfar_private *priv)
|
2019-09-04 21:52:19 +08:00
|
|
|
{
|
|
|
|
struct gfar __iomem *regs = priv->gfargrp[0].regs;
|
|
|
|
u32 tempval;
|
2015-05-06 23:07:30 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
/* Dissable the Rx/Tx hw queues */
|
|
|
|
gfar_write(®s->rqueue, 0);
|
|
|
|
gfar_write(®s->tqueue, 0);
|
2005-06-20 23:54:21 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
mdelay(10);
|
2005-06-20 23:54:21 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
gfar_halt_nodisable(priv);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
/* Disable Rx/Tx DMA */
|
|
|
|
tempval = gfar_read(®s->maccfg1);
|
|
|
|
tempval &= ~(MACCFG1_RX_EN | MACCFG1_TX_EN);
|
|
|
|
gfar_write(®s->maccfg1, tempval);
|
|
|
|
}
|
2009-11-02 15:03:00 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
static void free_skb_tx_queue(struct gfar_priv_tx_q *tx_queue)
|
|
|
|
{
|
|
|
|
struct txbd8 *txbdp;
|
|
|
|
struct gfar_private *priv = netdev_priv(tx_queue->dev);
|
|
|
|
int i, j;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
txbdp = tx_queue->tx_bd_base;
|
2005-06-20 23:54:21 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
for (i = 0; i < tx_queue->tx_ring_size; i++) {
|
|
|
|
if (!tx_queue->tx_skbuff[i])
|
|
|
|
continue;
|
gianfar: Fix device reset races (oops) for Tx
The device reset procedure, stop_gfar()/startup_gfar(), has
concurrency issues.
"Kernel access of bad area" oopses show up during Tx timeout
device reset or other reset cases (like changing MTU) that
happen while the interface still has traffic. The oopses
happen in start_xmit and clean_tx_ring when accessing tx_queue->
tx_skbuff which is NULL. The race comes from de-allocating the
tx_skbuff while transmission and napi processing are still
active. Though the Tx queues get temoprarily stopped when Tx
timeout occurs, they get re-enabled as a result of Tx congestion
handling inside the napi context (see clean_tx_ring()). Not
disabling the napi during reset is also a bug, because
clean_tx_ring() will try to access tx_skbuff while it is being
de-alloc'ed and re-alloc'ed.
To fix this, stop_gfar() needs to disable napi processing
after stopping the Tx queues. However, in order to prevent
clean_tx_ring() to re-enable the Tx queue before the napi
gets disabled, the device state DOWN has been introduced.
It prevents the Tx congestion management from re-enabling the
de-congested Tx queue while the device is brought down.
An additional locking state, RESETTING, has been introduced
to prevent simultaneous resets or to prevent configuring the
device while it is resetting.
The bogus 'rxlock's (for each Rx queue) have been removed since
their purpose is not justified, as they don't prevent nor are
suited to prevent device reset/reconfig races (such as this one).
Signed-off-by: Claudiu Manoil <claudiu.manoil@freescale.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-02-24 18:13:45 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
dma_unmap_single(priv->dev, be32_to_cpu(txbdp->bufPtr),
|
|
|
|
be16_to_cpu(txbdp->length), DMA_TO_DEVICE);
|
|
|
|
txbdp->lstatus = 0;
|
|
|
|
for (j = 0; j < skb_shinfo(tx_queue->tx_skbuff[i])->nr_frags;
|
|
|
|
j++) {
|
|
|
|
txbdp++;
|
|
|
|
dma_unmap_page(priv->dev, be32_to_cpu(txbdp->bufPtr),
|
|
|
|
be16_to_cpu(txbdp->length),
|
|
|
|
DMA_TO_DEVICE);
|
|
|
|
}
|
|
|
|
txbdp++;
|
|
|
|
dev_kfree_skb_any(tx_queue->tx_skbuff[i]);
|
|
|
|
tx_queue->tx_skbuff[i] = NULL;
|
|
|
|
}
|
|
|
|
kfree(tx_queue->tx_skbuff);
|
|
|
|
tx_queue->tx_skbuff = NULL;
|
|
|
|
}
|
2008-10-02 19:12:24 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
static void free_skb_rx_queue(struct gfar_priv_rx_q *rx_queue)
|
|
|
|
{
|
|
|
|
int i;
|
2014-06-04 06:55:38 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
struct rxbd8 *rxbdp = rx_queue->rx_bd_base;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
dev_kfree_skb(rx_queue->skb);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
for (i = 0; i < rx_queue->rx_ring_size; i++) {
|
|
|
|
struct gfar_rx_buff *rxb = &rx_queue->rx_buff[i];
|
2015-10-05 22:19:59 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
rxbdp->lstatus = 0;
|
|
|
|
rxbdp->bufPtr = 0;
|
|
|
|
rxbdp++;
|
2015-10-05 22:19:59 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
if (!rxb->page)
|
|
|
|
continue;
|
2009-02-01 16:52:34 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
dma_unmap_page(rx_queue->dev, rxb->dma,
|
|
|
|
PAGE_SIZE, DMA_FROM_DEVICE);
|
|
|
|
__free_page(rxb->page);
|
|
|
|
|
|
|
|
rxb->page = NULL;
|
2009-11-02 15:03:34 +08:00
|
|
|
}
|
2008-12-18 08:51:32 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
kfree(rx_queue->rx_buff);
|
|
|
|
rx_queue->rx_buff = NULL;
|
|
|
|
}
|
2009-11-02 15:03:40 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
/* If there are any tx skbs or rx skbs still around, free them.
|
|
|
|
* Then free tx_skbuff and rx_skbuff
|
|
|
|
*/
|
|
|
|
static void free_skb_resources(struct gfar_private *priv)
|
|
|
|
{
|
|
|
|
struct gfar_priv_tx_q *tx_queue = NULL;
|
|
|
|
struct gfar_priv_rx_q *rx_queue = NULL;
|
|
|
|
int i;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
/* Go through all the buffer descriptors and free their data buffers */
|
|
|
|
for (i = 0; i < priv->num_tx_queues; i++) {
|
|
|
|
struct netdev_queue *txq;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
tx_queue = priv->tx_queue[i];
|
|
|
|
txq = netdev_get_tx_queue(tx_queue->dev, tx_queue->qindex);
|
|
|
|
if (tx_queue->tx_skbuff)
|
|
|
|
free_skb_tx_queue(tx_queue);
|
|
|
|
netdev_tx_reset_queue(txq);
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
for (i = 0; i < priv->num_rx_queues; i++) {
|
|
|
|
rx_queue = priv->rx_queue[i];
|
|
|
|
if (rx_queue->rx_buff)
|
|
|
|
free_skb_rx_queue(rx_queue);
|
|
|
|
}
|
|
|
|
|
|
|
|
dma_free_coherent(priv->dev,
|
|
|
|
sizeof(struct txbd8) * priv->total_tx_ring_size +
|
|
|
|
sizeof(struct rxbd8) * priv->total_rx_ring_size,
|
|
|
|
priv->tx_queue[0]->tx_bd_base,
|
|
|
|
priv->tx_queue[0]->tx_bd_dma_base);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
void stop_gfar(struct net_device *dev)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2019-09-04 21:52:19 +08:00
|
|
|
struct gfar_private *priv = netdev_priv(dev);
|
2016-11-29 02:25:02 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
netif_tx_stop_all_queues(dev);
|
2016-11-29 02:25:02 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
smp_mb__before_atomic();
|
|
|
|
set_bit(GFAR_DOWN, &priv->state);
|
|
|
|
smp_mb__after_atomic();
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
disable_napi(priv);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
/* disable ints and gracefully shut down Rx/Tx DMA */
|
|
|
|
gfar_halt(priv);
|
2009-10-12 14:00:42 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
phy_stop(dev->phydev);
|
2015-10-05 22:19:59 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
free_skb_resources(priv);
|
2015-10-05 22:19:59 +08:00
|
|
|
}
|
|
|
|
|
2019-09-04 21:52:20 +08:00
|
|
|
static void gfar_start(struct gfar_private *priv)
|
2015-10-05 22:19:59 +08:00
|
|
|
{
|
|
|
|
struct gfar __iomem *regs = priv->gfargrp[0].regs;
|
|
|
|
u32 tempval;
|
|
|
|
int i = 0;
|
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
/* Enable Rx/Tx hw queues */
|
2015-10-05 22:19:59 +08:00
|
|
|
gfar_write(®s->rqueue, priv->rqueue);
|
2019-09-04 21:52:19 +08:00
|
|
|
gfar_write(®s->tqueue, priv->tqueue);
|
2015-10-05 22:19:59 +08:00
|
|
|
|
|
|
|
/* Initialize DMACTRL to have WWR and WOP */
|
|
|
|
tempval = gfar_read(®s->dmactrl);
|
|
|
|
tempval |= DMACTRL_INIT_SETTINGS;
|
|
|
|
gfar_write(®s->dmactrl, tempval);
|
|
|
|
|
|
|
|
/* Make sure we aren't stopped */
|
|
|
|
tempval = gfar_read(®s->dmactrl);
|
2019-09-04 21:52:19 +08:00
|
|
|
tempval &= ~(DMACTRL_GRS | DMACTRL_GTS);
|
2015-10-05 22:19:59 +08:00
|
|
|
gfar_write(®s->dmactrl, tempval);
|
|
|
|
|
|
|
|
for (i = 0; i < priv->num_grps; i++) {
|
|
|
|
regs = priv->gfargrp[i].regs;
|
2019-09-04 21:52:19 +08:00
|
|
|
/* Clear THLT/RHLT, so that the DMA starts polling now */
|
|
|
|
gfar_write(®s->tstat, priv->gfargrp[i].tstat);
|
2015-10-05 22:19:59 +08:00
|
|
|
gfar_write(®s->rstat, priv->gfargrp[i].rstat);
|
|
|
|
}
|
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
/* Enable Rx/Tx DMA */
|
2015-10-05 22:19:59 +08:00
|
|
|
tempval = gfar_read(®s->maccfg1);
|
2019-09-04 21:52:19 +08:00
|
|
|
tempval |= (MACCFG1_RX_EN | MACCFG1_TX_EN);
|
2015-10-05 22:19:59 +08:00
|
|
|
gfar_write(®s->maccfg1, tempval);
|
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
gfar_ints_enable(priv);
|
2008-07-12 07:04:45 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
netif_trans_update(priv->ndev); /* prevent tx timeout */
|
|
|
|
}
|
2015-07-31 23:38:32 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
static bool gfar_new_page(struct gfar_priv_rx_q *rxq, struct gfar_rx_buff *rxb)
|
|
|
|
{
|
|
|
|
struct page *page;
|
|
|
|
dma_addr_t addr;
|
2008-07-12 07:04:45 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
page = dev_alloc_page();
|
|
|
|
if (unlikely(!page))
|
|
|
|
return false;
|
2009-11-02 15:03:15 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
addr = dma_map_page(rxq->dev, page, 0, PAGE_SIZE, DMA_FROM_DEVICE);
|
|
|
|
if (unlikely(dma_mapping_error(rxq->dev, addr))) {
|
|
|
|
__free_page(page);
|
2008-07-12 07:04:45 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
return false;
|
|
|
|
}
|
2008-07-12 07:04:45 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
rxb->dma = addr;
|
|
|
|
rxb->page = page;
|
|
|
|
rxb->page_offset = 0;
|
2008-07-12 07:04:45 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
return true;
|
|
|
|
}
|
2015-10-05 22:19:59 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
static void gfar_rx_alloc_err(struct gfar_priv_rx_q *rx_queue)
|
|
|
|
{
|
|
|
|
struct gfar_private *priv = netdev_priv(rx_queue->ndev);
|
|
|
|
struct gfar_extra_stats *estats = &priv->extra_stats;
|
2008-07-12 07:04:45 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
netdev_err(rx_queue->ndev, "Can't alloc RX buffers\n");
|
|
|
|
atomic64_inc(&estats->rx_alloc_err);
|
2008-07-12 07:04:45 +08:00
|
|
|
}
|
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
static void gfar_alloc_rx_buffs(struct gfar_priv_rx_q *rx_queue,
|
|
|
|
int alloc_cnt)
|
2008-07-12 07:04:45 +08:00
|
|
|
{
|
2019-09-04 21:52:19 +08:00
|
|
|
struct rxbd8 *bdp;
|
|
|
|
struct gfar_rx_buff *rxb;
|
|
|
|
int i;
|
2008-07-12 07:04:45 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
i = rx_queue->next_to_use;
|
|
|
|
bdp = &rx_queue->rx_bd_base[i];
|
|
|
|
rxb = &rx_queue->rx_buff[i];
|
2015-10-05 22:19:59 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
while (alloc_cnt--) {
|
|
|
|
/* try reuse page */
|
|
|
|
if (unlikely(!rxb->page)) {
|
|
|
|
if (unlikely(!gfar_new_page(rx_queue, rxb))) {
|
|
|
|
gfar_rx_alloc_err(rx_queue);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-10-05 22:19:59 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
/* Setup the new RxBD */
|
|
|
|
gfar_init_rxbdp(rx_queue, bdp,
|
|
|
|
rxb->dma + rxb->page_offset + RXBUF_ALIGNMENT);
|
2008-07-12 07:04:45 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
/* Update to the next pointer */
|
|
|
|
bdp++;
|
|
|
|
rxb++;
|
2008-07-12 07:04:45 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
if (unlikely(++i == rx_queue->rx_ring_size)) {
|
|
|
|
i = 0;
|
|
|
|
bdp = rx_queue->rx_bd_base;
|
|
|
|
rxb = rx_queue->rx_buff;
|
|
|
|
}
|
|
|
|
}
|
2009-10-12 14:00:42 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
rx_queue->next_to_use = i;
|
|
|
|
rx_queue->next_to_alloc = i;
|
2009-10-12 14:00:42 +08:00
|
|
|
}
|
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
static void gfar_init_bds(struct net_device *ndev)
|
2009-10-12 14:00:42 +08:00
|
|
|
{
|
2019-09-04 21:52:19 +08:00
|
|
|
struct gfar_private *priv = netdev_priv(ndev);
|
|
|
|
struct gfar __iomem *regs = priv->gfargrp[0].regs;
|
|
|
|
struct gfar_priv_tx_q *tx_queue = NULL;
|
|
|
|
struct gfar_priv_rx_q *rx_queue = NULL;
|
|
|
|
struct txbd8 *txbdp;
|
|
|
|
u32 __iomem *rfbptr;
|
|
|
|
int i, j;
|
2012-11-09 06:11:41 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
for (i = 0; i < priv->num_tx_queues; i++) {
|
|
|
|
tx_queue = priv->tx_queue[i];
|
|
|
|
/* Initialize some variables in our dev structure */
|
|
|
|
tx_queue->num_txbdfree = tx_queue->tx_ring_size;
|
|
|
|
tx_queue->dirty_tx = tx_queue->tx_bd_base;
|
|
|
|
tx_queue->cur_tx = tx_queue->tx_bd_base;
|
|
|
|
tx_queue->skb_curtx = 0;
|
|
|
|
tx_queue->skb_dirtytx = 0;
|
gianfar: Implement MAC reset and reconfig procedure
The main MAC config registers like: RCTRL/TCTRL, MRBLR,
MAXFRM, RXIC/TXIC, most fields of MACCFG1/2, should not
be changed on-the-fly, but at least after stopping the
DMA and disabling the Rx/Tx blocks and, for increased
reliability, after a MAC soft reset.
Impelement a complete MAC soft reset and reconfig procedure
following the latest HW advisories - gfar_mac_reset() - to
replace gfar_mac_init() and (the confusing) init_registers()
functions.
Factor out separate config functions for RCTRL and TCTRL,
insure programming order of the relevant config regs after
MAC soft reset.
Split gfar_hw_init() into gfar_mac_reset() and the remaining
global regs that don't need to be reconfigured after MAC soft
reset (FIFOCFG, ATTRELI, HW counters a.s.o).
As gfar_hw_init() now makes all the register writes @probe()
time, based on all the device flags and config options, it
must be moved further down, just before register_netdev(),
as the last config step when the config values are comitted
to HW. Also, move netif_carrier_off() after register_netdev(),
because it has no effect if called before.
Signed-off-by: Claudiu Manoil <claudiu.manoil@freescale.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-02-24 18:13:42 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
/* Initialize Transmit Descriptor Ring */
|
|
|
|
txbdp = tx_queue->tx_bd_base;
|
|
|
|
for (j = 0; j < tx_queue->tx_ring_size; j++) {
|
|
|
|
txbdp->lstatus = 0;
|
|
|
|
txbdp->bufPtr = 0;
|
|
|
|
txbdp++;
|
|
|
|
}
|
gianfar: Implement MAC reset and reconfig procedure
The main MAC config registers like: RCTRL/TCTRL, MRBLR,
MAXFRM, RXIC/TXIC, most fields of MACCFG1/2, should not
be changed on-the-fly, but at least after stopping the
DMA and disabling the Rx/Tx blocks and, for increased
reliability, after a MAC soft reset.
Impelement a complete MAC soft reset and reconfig procedure
following the latest HW advisories - gfar_mac_reset() - to
replace gfar_mac_init() and (the confusing) init_registers()
functions.
Factor out separate config functions for RCTRL and TCTRL,
insure programming order of the relevant config regs after
MAC soft reset.
Split gfar_hw_init() into gfar_mac_reset() and the remaining
global regs that don't need to be reconfigured after MAC soft
reset (FIFOCFG, ATTRELI, HW counters a.s.o).
As gfar_hw_init() now makes all the register writes @probe()
time, based on all the device flags and config options, it
must be moved further down, just before register_netdev(),
as the last config step when the config values are comitted
to HW. Also, move netif_carrier_off() after register_netdev(),
because it has no effect if called before.
Signed-off-by: Claudiu Manoil <claudiu.manoil@freescale.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-02-24 18:13:42 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
/* Set the last descriptor in the ring to indicate wrap */
|
|
|
|
txbdp--;
|
|
|
|
txbdp->status = cpu_to_be16(be16_to_cpu(txbdp->status) |
|
|
|
|
TXBD_WRAP);
|
|
|
|
}
|
2009-10-12 14:00:42 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
rfbptr = ®s->rfbptr0;
|
|
|
|
for (i = 0; i < priv->num_rx_queues; i++) {
|
|
|
|
rx_queue = priv->rx_queue[i];
|
2009-10-12 14:00:42 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
rx_queue->next_to_clean = 0;
|
|
|
|
rx_queue->next_to_use = 0;
|
|
|
|
rx_queue->next_to_alloc = 0;
|
2008-07-12 07:04:45 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
/* make sure next_to_clean != next_to_use after this
|
|
|
|
* by leaving at least 1 unused descriptor
|
|
|
|
*/
|
|
|
|
gfar_alloc_rx_buffs(rx_queue, gfar_rxbd_unused(rx_queue));
|
2008-07-12 07:04:45 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
rx_queue->rfbptr = rfbptr;
|
|
|
|
rfbptr += 2;
|
|
|
|
}
|
2008-07-12 07:04:45 +08:00
|
|
|
}
|
2009-10-12 14:00:42 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
static int gfar_alloc_skb_resources(struct net_device *ndev)
|
|
|
|
{
|
|
|
|
void *vaddr;
|
|
|
|
dma_addr_t addr;
|
|
|
|
int i, j;
|
|
|
|
struct gfar_private *priv = netdev_priv(ndev);
|
|
|
|
struct device *dev = priv->dev;
|
|
|
|
struct gfar_priv_tx_q *tx_queue = NULL;
|
|
|
|
struct gfar_priv_rx_q *rx_queue = NULL;
|
2009-10-12 14:00:42 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
priv->total_tx_ring_size = 0;
|
|
|
|
for (i = 0; i < priv->num_tx_queues; i++)
|
|
|
|
priv->total_tx_ring_size += priv->tx_queue[i]->tx_ring_size;
|
2009-10-12 14:00:42 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
priv->total_rx_ring_size = 0;
|
|
|
|
for (i = 0; i < priv->num_rx_queues; i++)
|
|
|
|
priv->total_rx_ring_size += priv->rx_queue[i]->rx_ring_size;
|
2009-10-12 14:00:42 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
/* Allocate memory for the buffer descriptors */
|
|
|
|
vaddr = dma_alloc_coherent(dev,
|
|
|
|
(priv->total_tx_ring_size *
|
|
|
|
sizeof(struct txbd8)) +
|
|
|
|
(priv->total_rx_ring_size *
|
|
|
|
sizeof(struct rxbd8)),
|
|
|
|
&addr, GFP_KERNEL);
|
|
|
|
if (!vaddr)
|
|
|
|
return -ENOMEM;
|
2009-10-12 14:00:42 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
for (i = 0; i < priv->num_tx_queues; i++) {
|
|
|
|
tx_queue = priv->tx_queue[i];
|
|
|
|
tx_queue->tx_bd_base = vaddr;
|
|
|
|
tx_queue->tx_bd_dma_base = addr;
|
|
|
|
tx_queue->dev = ndev;
|
|
|
|
/* enet DMA only understands physical addresses */
|
|
|
|
addr += sizeof(struct txbd8) * tx_queue->tx_ring_size;
|
|
|
|
vaddr += sizeof(struct txbd8) * tx_queue->tx_ring_size;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
/* Start the rx descriptor ring where the tx ring leaves off */
|
|
|
|
for (i = 0; i < priv->num_rx_queues; i++) {
|
|
|
|
rx_queue = priv->rx_queue[i];
|
|
|
|
rx_queue->rx_bd_base = vaddr;
|
|
|
|
rx_queue->rx_bd_dma_base = addr;
|
|
|
|
rx_queue->ndev = ndev;
|
|
|
|
rx_queue->dev = dev;
|
|
|
|
addr += sizeof(struct rxbd8) * rx_queue->rx_ring_size;
|
|
|
|
vaddr += sizeof(struct rxbd8) * rx_queue->rx_ring_size;
|
|
|
|
}
|
2009-11-02 15:03:09 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
/* Setup the skbuff rings */
|
|
|
|
for (i = 0; i < priv->num_tx_queues; i++) {
|
|
|
|
tx_queue = priv->tx_queue[i];
|
|
|
|
tx_queue->tx_skbuff =
|
|
|
|
kmalloc_array(tx_queue->tx_ring_size,
|
|
|
|
sizeof(*tx_queue->tx_skbuff),
|
|
|
|
GFP_KERNEL);
|
|
|
|
if (!tx_queue->tx_skbuff)
|
|
|
|
goto cleanup;
|
2006-12-02 02:01:06 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
for (j = 0; j < tx_queue->tx_ring_size; j++)
|
|
|
|
tx_queue->tx_skbuff[j] = NULL;
|
|
|
|
}
|
2006-12-02 02:01:06 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
for (i = 0; i < priv->num_rx_queues; i++) {
|
|
|
|
rx_queue = priv->rx_queue[i];
|
|
|
|
rx_queue->rx_buff = kcalloc(rx_queue->rx_ring_size,
|
|
|
|
sizeof(*rx_queue->rx_buff),
|
|
|
|
GFP_KERNEL);
|
|
|
|
if (!rx_queue->rx_buff)
|
|
|
|
goto cleanup;
|
2006-12-02 02:01:06 +08:00
|
|
|
}
|
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
gfar_init_bds(ndev);
|
2007-07-12 00:43:07 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
return 0;
|
2007-07-12 00:43:07 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
cleanup:
|
|
|
|
free_skb_resources(priv);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
2006-12-02 02:01:06 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
/* Bring the controller up and running */
|
|
|
|
int startup_gfar(struct net_device *ndev)
|
|
|
|
{
|
|
|
|
struct gfar_private *priv = netdev_priv(ndev);
|
|
|
|
int err;
|
2006-12-02 02:01:06 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
gfar_mac_reset(priv);
|
2006-12-02 02:01:06 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
err = gfar_alloc_skb_resources(ndev);
|
|
|
|
if (err)
|
|
|
|
return err;
|
2006-12-02 02:01:06 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
gfar_init_tx_rx_base(priv);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
smp_mb__before_atomic();
|
|
|
|
clear_bit(GFAR_DOWN, &priv->state);
|
|
|
|
smp_mb__after_atomic();
|
|
|
|
|
|
|
|
/* Start Rx/Tx DMA and enable the interrupts */
|
|
|
|
gfar_start(priv);
|
2018-11-11 06:43:33 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
/* force link state update after mac reset */
|
2005-04-17 06:20:36 +08:00
|
|
|
priv->oldlink = 0;
|
|
|
|
priv->oldspeed = 0;
|
|
|
|
priv->oldduplex = -1;
|
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
phy_start(ndev->phydev);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
enable_napi(priv);
|
2014-10-27 16:42:42 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
netif_tx_wake_all_queues(ndev);
|
2017-12-08 00:44:23 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
static u32 gfar_get_flowctrl_cfg(struct gfar_private *priv)
|
2007-05-12 07:25:11 +08:00
|
|
|
{
|
2019-09-04 21:52:19 +08:00
|
|
|
struct net_device *ndev = priv->ndev;
|
|
|
|
struct phy_device *phydev = ndev->phydev;
|
|
|
|
u32 val = 0;
|
2009-04-25 20:53:12 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
if (!phydev->duplex)
|
|
|
|
return val;
|
gianfar: Fix race in TBI/SerDes configuration
The init_phy() function attaches to the PHY, then configures the
SerDes<->TBI link (in SGMII mode). The TBI is on the MDIO bus with the PHY
(sort of) and is accessed via the gianfar's MDIO registers, using the
functions gfar_local_mdio_read/write(), which don't do any locking.
The previously attached PHY will start a work-queue on a timer, and
probably an irq handler as well, which will talk to the PHY and thus use
the MDIO bus. This uses phy_read/write(), which have locking, but not
against the gfar_local_mdio versions.
The result is that PHY code will try to use the MDIO bus at the same time
as the SerDes setup code, corrupting the transfers.
Setting up the SerDes before attaching to the PHY will insure that there is
no race between the SerDes code and *our* PHY, but doesn't fix everything.
Typically the PHYs for all gianfar devices are on the same MDIO bus, which
is associated with the first gianfar device. This means that the first
gianfar's SerDes code could corrupt the MDIO transfers for a different
gianfar's PHY.
The lock used by phy_read/write() is contained in the mii_bus structure,
which is pointed to by the PHY. This is difficult to access from the
gianfar drivers, as there is no link between a gianfar device and the
mii_bus which shares the same MDIO registers. As far as the device layer
and drivers are concerned they are two unrelated devices (which happen to
share registers).
Generally all gianfar devices' PHYs will be on the bus associated with the
first gianfar. But this might not be the case, so simply locking the
gianfar's PHY's mii bus might not lock the mii bus that the SerDes setup
code is going to use.
We solve this by having the code that creates the gianfar platform device
look in the device tree for an mdio device that shares the gianfar's
registers. If one is found the ID of its platform device is saved in the
gianfar's platform data.
A new function in the gianfar mii code, gfar_get_miibus(), can use the bus
ID to search through the platform devices for a gianfar_mdio device with
the right ID. The platform device's driver data is the mii_bus structure,
which the SerDes setup code can use to lock the current bus.
Signed-off-by: Trent Piepho <tpiepho@freescale.com>
CC: Andy Fleming <afleming@freescale.com>
Signed-off-by: Jeff Garzik <jgarzik@redhat.com>
2008-10-31 09:17:06 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
if (!priv->pause_aneg_en) {
|
|
|
|
if (priv->tx_pause_en)
|
|
|
|
val |= MACCFG1_TX_FLOW;
|
|
|
|
if (priv->rx_pause_en)
|
|
|
|
val |= MACCFG1_RX_FLOW;
|
|
|
|
} else {
|
|
|
|
u16 lcl_adv, rmt_adv;
|
|
|
|
u8 flowctrl;
|
|
|
|
/* get link partner capabilities */
|
|
|
|
rmt_adv = 0;
|
|
|
|
if (phydev->pause)
|
|
|
|
rmt_adv = LPA_PAUSE_CAP;
|
|
|
|
if (phydev->asym_pause)
|
|
|
|
rmt_adv |= LPA_PAUSE_ASYM;
|
2007-05-12 07:25:11 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
lcl_adv = linkmode_adv_to_lcl_adv_t(phydev->advertising);
|
|
|
|
flowctrl = mii_resolve_flowctrl_fdx(lcl_adv, rmt_adv);
|
|
|
|
if (flowctrl & FLOW_CTRL_TX)
|
|
|
|
val |= MACCFG1_TX_FLOW;
|
|
|
|
if (flowctrl & FLOW_CTRL_RX)
|
|
|
|
val |= MACCFG1_RX_FLOW;
|
2015-09-25 03:36:28 +08:00
|
|
|
}
|
2007-05-12 07:25:11 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
return val;
|
2007-05-12 07:25:11 +08:00
|
|
|
}
|
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
static noinline void gfar_update_link_state(struct gfar_private *priv)
|
2010-06-30 14:39:15 +08:00
|
|
|
{
|
2019-09-04 21:52:19 +08:00
|
|
|
struct gfar __iomem *regs = priv->gfargrp[0].regs;
|
|
|
|
struct net_device *ndev = priv->ndev;
|
|
|
|
struct phy_device *phydev = ndev->phydev;
|
|
|
|
struct gfar_priv_rx_q *rx_queue = NULL;
|
|
|
|
int i;
|
2010-06-30 14:39:15 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
if (unlikely(test_bit(GFAR_RESETTING, &priv->state)))
|
|
|
|
return;
|
2010-06-30 14:39:15 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
if (phydev->link) {
|
|
|
|
u32 tempval1 = gfar_read(®s->maccfg1);
|
|
|
|
u32 tempval = gfar_read(®s->maccfg2);
|
|
|
|
u32 ecntrl = gfar_read(®s->ecntrl);
|
|
|
|
u32 tx_flow_oldval = (tempval1 & MACCFG1_TX_FLOW);
|
2010-06-30 14:39:15 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
if (phydev->duplex != priv->oldduplex) {
|
|
|
|
if (!(phydev->duplex))
|
|
|
|
tempval &= ~(MACCFG2_FULL_DUPLEX);
|
|
|
|
else
|
|
|
|
tempval |= MACCFG2_FULL_DUPLEX;
|
2005-06-20 23:54:21 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
priv->oldduplex = phydev->duplex;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
if (phydev->speed != priv->oldspeed) {
|
|
|
|
switch (phydev->speed) {
|
|
|
|
case 1000:
|
|
|
|
tempval =
|
|
|
|
((tempval & ~(MACCFG2_IF)) | MACCFG2_GMII);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
ecntrl &= ~(ECNTRL_R100);
|
|
|
|
break;
|
|
|
|
case 100:
|
|
|
|
case 10:
|
|
|
|
tempval =
|
|
|
|
((tempval & ~(MACCFG2_IF)) | MACCFG2_MII);
|
2014-10-07 15:44:34 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
/* Reduced mode distinguishes
|
|
|
|
* between 10 and 100
|
|
|
|
*/
|
|
|
|
if (phydev->speed == SPEED_100)
|
|
|
|
ecntrl |= ECNTRL_R100;
|
|
|
|
else
|
|
|
|
ecntrl &= ~(ECNTRL_R100);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
netif_warn(priv, link, priv->ndev,
|
|
|
|
"Ack! Speed (%d) is not 10/100/1000!\n",
|
|
|
|
phydev->speed);
|
|
|
|
break;
|
|
|
|
}
|
2014-10-07 15:44:34 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
priv->oldspeed = phydev->speed;
|
|
|
|
}
|
2014-10-07 15:44:34 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
tempval1 &= ~(MACCFG1_TX_FLOW | MACCFG1_RX_FLOW);
|
|
|
|
tempval1 |= gfar_get_flowctrl_cfg(priv);
|
2014-10-07 15:44:34 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
/* Turn last free buffer recording on */
|
|
|
|
if ((tempval1 & MACCFG1_TX_FLOW) && !tx_flow_oldval) {
|
|
|
|
for (i = 0; i < priv->num_rx_queues; i++) {
|
|
|
|
u32 bdp_dma;
|
2008-07-12 07:04:45 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
rx_queue = priv->rx_queue[i];
|
|
|
|
bdp_dma = gfar_rxbd_dma_lastfree(rx_queue);
|
|
|
|
gfar_write(rx_queue->rfbptr, bdp_dma);
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
priv->tx_actual_en = 1;
|
|
|
|
}
|
2008-08-13 04:10:46 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
if (unlikely(!(tempval1 & MACCFG1_TX_FLOW) && tx_flow_oldval))
|
|
|
|
priv->tx_actual_en = 0;
|
2014-02-17 18:53:18 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
gfar_write(®s->maccfg1, tempval1);
|
|
|
|
gfar_write(®s->maccfg2, tempval);
|
|
|
|
gfar_write(®s->ecntrl, ecntrl);
|
2014-02-17 18:53:18 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
if (!priv->oldlink)
|
|
|
|
priv->oldlink = 1;
|
|
|
|
|
|
|
|
} else if (priv->oldlink) {
|
|
|
|
priv->oldlink = 0;
|
|
|
|
priv->oldspeed = 0;
|
|
|
|
priv->oldduplex = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (netif_msg_link(priv))
|
|
|
|
phy_print_status(phydev);
|
2005-06-20 23:54:21 +08:00
|
|
|
}
|
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
/* Called every time the controller might need to be made
|
|
|
|
* aware of new link state. The PHY code conveys this
|
|
|
|
* information through variables in the phydev structure, and this
|
|
|
|
* function converts those variables into the appropriate
|
|
|
|
* register values, and can bring down the device if needed.
|
|
|
|
*/
|
|
|
|
static void adjust_link(struct net_device *dev)
|
2005-06-20 23:54:21 +08:00
|
|
|
{
|
|
|
|
struct gfar_private *priv = netdev_priv(dev);
|
2019-09-04 21:52:19 +08:00
|
|
|
struct phy_device *phydev = dev->phydev;
|
2005-06-20 23:54:21 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
if (unlikely(phydev->link != priv->oldlink ||
|
|
|
|
(phydev->link && (phydev->duplex != priv->oldduplex ||
|
|
|
|
phydev->speed != priv->oldspeed))))
|
|
|
|
gfar_update_link_state(priv);
|
|
|
|
}
|
2009-11-02 15:03:00 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
/* Initialize TBI PHY interface for communicating with the
|
|
|
|
* SERDES lynx PHY on the chip. We communicate with this PHY
|
|
|
|
* through the MDIO bus on each controller, treating it as a
|
|
|
|
* "normal" PHY at the address found in the TBIPA register. We assume
|
|
|
|
* that the TBIPA register is valid. Either the MDIO bus code will set
|
|
|
|
* it to a value that doesn't conflict with other PHYs on the bus, or the
|
|
|
|
* value doesn't matter, as there are no other PHYs on the bus.
|
|
|
|
*/
|
|
|
|
static void gfar_configure_serdes(struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct gfar_private *priv = netdev_priv(dev);
|
|
|
|
struct phy_device *tbiphy;
|
2005-06-20 23:54:21 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
if (!priv->tbi_node) {
|
|
|
|
dev_warn(&dev->dev, "error: SGMII mode requires that the "
|
|
|
|
"device tree specify a tbi-handle\n");
|
|
|
|
return;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
tbiphy = of_phy_find_device(priv->tbi_node);
|
|
|
|
if (!tbiphy) {
|
|
|
|
dev_err(&dev->dev, "error: Could not get TBI device\n");
|
|
|
|
return;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
/* If the link is already up, we must already be ok, and don't need to
|
|
|
|
* configure and reset the TBI<->SerDes link. Maybe U-Boot configured
|
|
|
|
* everything for us? Resetting it takes the link down and requires
|
|
|
|
* several seconds for it to come back.
|
|
|
|
*/
|
|
|
|
if (phy_read(tbiphy, MII_BMSR) & BMSR_LSTATUS) {
|
|
|
|
put_device(&tbiphy->mdio.dev);
|
|
|
|
return;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
/* Single clk mode, mii mode off(for serdes communication) */
|
|
|
|
phy_write(tbiphy, MII_TBICON, TBICON_CLK_SELECT);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
phy_write(tbiphy, MII_ADVERTISE,
|
|
|
|
ADVERTISE_1000XFULL | ADVERTISE_1000XPAUSE |
|
|
|
|
ADVERTISE_1000XPSE_ASYM);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
phy_write(tbiphy, MII_BMCR,
|
|
|
|
BMCR_ANENABLE | BMCR_ANRESTART | BMCR_FULLDPLX |
|
|
|
|
BMCR_SPEED1000);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
put_device(&tbiphy->mdio.dev);
|
2009-11-02 15:03:15 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
/* Initializes driver's PHY state, and attaches to the PHY.
|
|
|
|
* Returns 0 on success.
|
|
|
|
*/
|
|
|
|
static int init_phy(struct net_device *dev)
|
2009-11-02 15:03:15 +08:00
|
|
|
{
|
2019-09-04 21:52:19 +08:00
|
|
|
__ETHTOOL_DECLARE_LINK_MODE_MASK(mask) = { 0, };
|
|
|
|
struct gfar_private *priv = netdev_priv(dev);
|
2019-09-04 21:52:22 +08:00
|
|
|
phy_interface_t interface = priv->interface;
|
2019-09-04 21:52:19 +08:00
|
|
|
struct phy_device *phydev;
|
|
|
|
struct ethtool_eee edata;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
linkmode_set_bit_array(phy_10_100_features_array,
|
|
|
|
ARRAY_SIZE(phy_10_100_features_array),
|
|
|
|
mask);
|
|
|
|
linkmode_set_bit(ETHTOOL_LINK_MODE_Autoneg_BIT, mask);
|
|
|
|
linkmode_set_bit(ETHTOOL_LINK_MODE_MII_BIT, mask);
|
|
|
|
if (priv->device_flags & FSL_GIANFAR_DEV_HAS_GIGABIT)
|
|
|
|
linkmode_set_bit(ETHTOOL_LINK_MODE_1000baseT_Full_BIT, mask);
|
gianfar: Add paged allocation and Rx S/G
The eTSEC h/w is capable of scatter/gather on the receive side
too if MAXFRM > MRBLR, when the allowed maximum Rx frame size
is set to be greater than the maximum Rx buffer size (MRBLR).
It's about time the driver makes use of this h/w capability,
by supporting fixed buffer sizes and Rx S/G.
The buffer size given to eTSEC for reception is fixed to
1536B (must be multiple of 64), which is the same default
buffer size as before, used to accommodate standard MTU
(1500B) size frames. As before, eTSEC can receive frames of
up to 9600B. Individual Rx buffers are mapped to page halves
(page size for eTSEC systems is 4KB). The skb is built around
the first buffer of a frame (using build_skb()). In case the
frame spans multiple buffers, the trailing buffers are added
as Rx fragments to the skb. The last buffer in frame is marked
by the L status flag. A mechanism is in place to reuse the pages
owned by the driver (for Rx) for subsequent receptions.
Supporting fixed size buffers allows the implementation of Rx S/G,
which in turn removes the memory pressure issues the driver had
before when MTU was set for jumbo frame reception.
Also, in most cases, the Rx path becomes faster due to Rx page
reusal, since the overhead of allocating new rx buffers is removed
from the fast path.
Signed-off-by: Claudiu Manoil <claudiu.manoil@freescale.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2015-07-13 21:22:06 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
priv->oldlink = 0;
|
|
|
|
priv->oldspeed = 0;
|
|
|
|
priv->oldduplex = -1;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
phydev = of_phy_connect(dev, priv->phy_node, &adjust_link, 0,
|
|
|
|
interface);
|
|
|
|
if (!phydev) {
|
|
|
|
dev_err(&dev->dev, "could not attach to PHY\n");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
gianfar: Add paged allocation and Rx S/G
The eTSEC h/w is capable of scatter/gather on the receive side
too if MAXFRM > MRBLR, when the allowed maximum Rx frame size
is set to be greater than the maximum Rx buffer size (MRBLR).
It's about time the driver makes use of this h/w capability,
by supporting fixed buffer sizes and Rx S/G.
The buffer size given to eTSEC for reception is fixed to
1536B (must be multiple of 64), which is the same default
buffer size as before, used to accommodate standard MTU
(1500B) size frames. As before, eTSEC can receive frames of
up to 9600B. Individual Rx buffers are mapped to page halves
(page size for eTSEC systems is 4KB). The skb is built around
the first buffer of a frame (using build_skb()). In case the
frame spans multiple buffers, the trailing buffers are added
as Rx fragments to the skb. The last buffer in frame is marked
by the L status flag. A mechanism is in place to reuse the pages
owned by the driver (for Rx) for subsequent receptions.
Supporting fixed size buffers allows the implementation of Rx S/G,
which in turn removes the memory pressure issues the driver had
before when MTU was set for jumbo frame reception.
Also, in most cases, the Rx path becomes faster due to Rx page
reusal, since the overhead of allocating new rx buffers is removed
from the fast path.
Signed-off-by: Claudiu Manoil <claudiu.manoil@freescale.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2015-07-13 21:22:06 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
if (interface == PHY_INTERFACE_MODE_SGMII)
|
|
|
|
gfar_configure_serdes(dev);
|
gianfar: Add paged allocation and Rx S/G
The eTSEC h/w is capable of scatter/gather on the receive side
too if MAXFRM > MRBLR, when the allowed maximum Rx frame size
is set to be greater than the maximum Rx buffer size (MRBLR).
It's about time the driver makes use of this h/w capability,
by supporting fixed buffer sizes and Rx S/G.
The buffer size given to eTSEC for reception is fixed to
1536B (must be multiple of 64), which is the same default
buffer size as before, used to accommodate standard MTU
(1500B) size frames. As before, eTSEC can receive frames of
up to 9600B. Individual Rx buffers are mapped to page halves
(page size for eTSEC systems is 4KB). The skb is built around
the first buffer of a frame (using build_skb()). In case the
frame spans multiple buffers, the trailing buffers are added
as Rx fragments to the skb. The last buffer in frame is marked
by the L status flag. A mechanism is in place to reuse the pages
owned by the driver (for Rx) for subsequent receptions.
Supporting fixed size buffers allows the implementation of Rx S/G,
which in turn removes the memory pressure issues the driver had
before when MTU was set for jumbo frame reception.
Also, in most cases, the Rx path becomes faster due to Rx page
reusal, since the overhead of allocating new rx buffers is removed
from the fast path.
Signed-off-by: Claudiu Manoil <claudiu.manoil@freescale.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2015-07-13 21:22:06 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
/* Remove any features not supported by the controller */
|
|
|
|
linkmode_and(phydev->supported, phydev->supported, mask);
|
|
|
|
linkmode_copy(phydev->advertising, phydev->supported);
|
gianfar: Add paged allocation and Rx S/G
The eTSEC h/w is capable of scatter/gather on the receive side
too if MAXFRM > MRBLR, when the allowed maximum Rx frame size
is set to be greater than the maximum Rx buffer size (MRBLR).
It's about time the driver makes use of this h/w capability,
by supporting fixed buffer sizes and Rx S/G.
The buffer size given to eTSEC for reception is fixed to
1536B (must be multiple of 64), which is the same default
buffer size as before, used to accommodate standard MTU
(1500B) size frames. As before, eTSEC can receive frames of
up to 9600B. Individual Rx buffers are mapped to page halves
(page size for eTSEC systems is 4KB). The skb is built around
the first buffer of a frame (using build_skb()). In case the
frame spans multiple buffers, the trailing buffers are added
as Rx fragments to the skb. The last buffer in frame is marked
by the L status flag. A mechanism is in place to reuse the pages
owned by the driver (for Rx) for subsequent receptions.
Supporting fixed size buffers allows the implementation of Rx S/G,
which in turn removes the memory pressure issues the driver had
before when MTU was set for jumbo frame reception.
Also, in most cases, the Rx path becomes faster due to Rx page
reusal, since the overhead of allocating new rx buffers is removed
from the fast path.
Signed-off-by: Claudiu Manoil <claudiu.manoil@freescale.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2015-07-13 21:22:06 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
/* Add support for flow control */
|
|
|
|
phy_support_asym_pause(phydev);
|
gianfar: Add paged allocation and Rx S/G
The eTSEC h/w is capable of scatter/gather on the receive side
too if MAXFRM > MRBLR, when the allowed maximum Rx frame size
is set to be greater than the maximum Rx buffer size (MRBLR).
It's about time the driver makes use of this h/w capability,
by supporting fixed buffer sizes and Rx S/G.
The buffer size given to eTSEC for reception is fixed to
1536B (must be multiple of 64), which is the same default
buffer size as before, used to accommodate standard MTU
(1500B) size frames. As before, eTSEC can receive frames of
up to 9600B. Individual Rx buffers are mapped to page halves
(page size for eTSEC systems is 4KB). The skb is built around
the first buffer of a frame (using build_skb()). In case the
frame spans multiple buffers, the trailing buffers are added
as Rx fragments to the skb. The last buffer in frame is marked
by the L status flag. A mechanism is in place to reuse the pages
owned by the driver (for Rx) for subsequent receptions.
Supporting fixed size buffers allows the implementation of Rx S/G,
which in turn removes the memory pressure issues the driver had
before when MTU was set for jumbo frame reception.
Also, in most cases, the Rx path becomes faster due to Rx page
reusal, since the overhead of allocating new rx buffers is removed
from the fast path.
Signed-off-by: Claudiu Manoil <claudiu.manoil@freescale.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2015-07-13 21:22:06 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
/* disable EEE autoneg, EEE not supported by eTSEC */
|
|
|
|
memset(&edata, 0, sizeof(struct ethtool_eee));
|
|
|
|
phy_ethtool_set_eee(phydev, &edata);
|
gianfar: Fix device reset races (oops) for Tx
The device reset procedure, stop_gfar()/startup_gfar(), has
concurrency issues.
"Kernel access of bad area" oopses show up during Tx timeout
device reset or other reset cases (like changing MTU) that
happen while the interface still has traffic. The oopses
happen in start_xmit and clean_tx_ring when accessing tx_queue->
tx_skbuff which is NULL. The race comes from de-allocating the
tx_skbuff while transmission and napi processing are still
active. Though the Tx queues get temoprarily stopped when Tx
timeout occurs, they get re-enabled as a result of Tx congestion
handling inside the napi context (see clean_tx_ring()). Not
disabling the napi during reset is also a bug, because
clean_tx_ring() will try to access tx_skbuff while it is being
de-alloc'ed and re-alloc'ed.
To fix this, stop_gfar() needs to disable napi processing
after stopping the Tx queues. However, in order to prevent
clean_tx_ring() to re-enable the Tx queue before the napi
gets disabled, the device state DOWN has been introduced.
It prevents the Tx congestion management from re-enabling the
de-congested Tx queue while the device is brought down.
An additional locking state, RESETTING, has been introduced
to prevent simultaneous resets or to prevent configuring the
device while it is resetting.
The bogus 'rxlock's (for each Rx queue) have been removed since
their purpose is not justified, as they don't prevent nor are
suited to prevent device reset/reconfig races (such as this one).
Signed-off-by: Claudiu Manoil <claudiu.manoil@freescale.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-02-24 18:13:45 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-03-27 15:38:45 +08:00
|
|
|
static inline struct txfcb *gfar_add_fcb(struct sk_buff *skb)
|
2005-06-20 23:54:21 +08:00
|
|
|
{
|
networking: make skb_push & __skb_push return void pointers
It seems like a historic accident that these return unsigned char *,
and in many places that means casts are required, more often than not.
Make these functions return void * and remove all the casts across
the tree, adding a (u8 *) cast only where the unsigned char pointer
was used directly, all done with the following spatch:
@@
expression SKB, LEN;
typedef u8;
identifier fn = { skb_push, __skb_push, skb_push_rcsum };
@@
- *(fn(SKB, LEN))
+ *(u8 *)fn(SKB, LEN)
@@
expression E, SKB, LEN;
identifier fn = { skb_push, __skb_push, skb_push_rcsum };
type T;
@@
- E = ((T *)(fn(SKB, LEN)))
+ E = fn(SKB, LEN)
@@
expression SKB, LEN;
identifier fn = { skb_push, __skb_push, skb_push_rcsum };
@@
- fn(SKB, LEN)[0]
+ *(u8 *)fn(SKB, LEN)
Note that the last part there converts from push(...)[0] to the
more idiomatic *(u8 *)push(...).
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2017-06-16 20:29:23 +08:00
|
|
|
struct txfcb *fcb = skb_push(skb, GMAC_FCB_LEN);
|
2009-04-28 23:04:10 +08:00
|
|
|
|
|
|
|
memset(fcb, 0, GMAC_FCB_LEN);
|
2005-06-20 23:54:21 +08:00
|
|
|
|
|
|
|
return fcb;
|
|
|
|
}
|
|
|
|
|
2012-01-10 07:26:51 +08:00
|
|
|
static inline void gfar_tx_checksum(struct sk_buff *skb, struct txfcb *fcb,
|
2012-06-05 11:42:13 +08:00
|
|
|
int fcb_length)
|
2005-06-20 23:54:21 +08:00
|
|
|
{
|
|
|
|
/* If we're here, it's a IP packet with a TCP or UDP
|
|
|
|
* payload. We set it to checksum, using a pseudo-header
|
|
|
|
* we provide
|
|
|
|
*/
|
2012-06-05 11:42:14 +08:00
|
|
|
u8 flags = TXFCB_DEFAULT;
|
2005-06-20 23:54:21 +08:00
|
|
|
|
2012-06-05 11:42:12 +08:00
|
|
|
/* Tell the controller what the protocol is
|
|
|
|
* And provide the already calculated phcs
|
|
|
|
*/
|
2007-04-21 13:47:35 +08:00
|
|
|
if (ip_hdr(skb)->protocol == IPPROTO_UDP) {
|
2005-11-12 02:38:59 +08:00
|
|
|
flags |= TXFCB_UDP;
|
2015-03-13 16:36:29 +08:00
|
|
|
fcb->phcs = (__force __be16)(udp_hdr(skb)->check);
|
2005-11-12 02:38:59 +08:00
|
|
|
} else
|
2015-03-13 16:36:29 +08:00
|
|
|
fcb->phcs = (__force __be16)(tcp_hdr(skb)->check);
|
2005-06-20 23:54:21 +08:00
|
|
|
|
|
|
|
/* l3os is the distance between the start of the
|
|
|
|
* frame (skb->data) and the start of the IP hdr.
|
|
|
|
* l4os is the distance between the start of the
|
2012-06-05 11:42:12 +08:00
|
|
|
* l3 hdr and the l4 hdr
|
|
|
|
*/
|
2015-03-13 16:36:29 +08:00
|
|
|
fcb->l3os = (u8)(skb_network_offset(skb) - fcb_length);
|
2007-03-17 04:26:39 +08:00
|
|
|
fcb->l4os = skb_network_header_len(skb);
|
2005-06-20 23:54:21 +08:00
|
|
|
|
2005-11-12 02:38:59 +08:00
|
|
|
fcb->flags = flags;
|
2005-06-20 23:54:21 +08:00
|
|
|
}
|
|
|
|
|
2016-06-16 21:52:13 +08:00
|
|
|
static inline void gfar_tx_vlan(struct sk_buff *skb, struct txfcb *fcb)
|
2005-06-20 23:54:21 +08:00
|
|
|
{
|
2005-11-12 02:38:59 +08:00
|
|
|
fcb->flags |= TXFCB_VLN;
|
2015-03-13 16:36:29 +08:00
|
|
|
fcb->vlctl = cpu_to_be16(skb_vlan_tag_get(skb));
|
2005-06-20 23:54:21 +08:00
|
|
|
}
|
|
|
|
|
2008-12-18 08:51:04 +08:00
|
|
|
static inline struct txbd8 *skip_txbd(struct txbd8 *bdp, int stride,
|
2012-06-05 11:42:13 +08:00
|
|
|
struct txbd8 *base, int ring_size)
|
2008-12-18 08:51:04 +08:00
|
|
|
{
|
|
|
|
struct txbd8 *new_bd = bdp + stride;
|
|
|
|
|
|
|
|
return (new_bd >= (base + ring_size)) ? (new_bd - ring_size) : new_bd;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline struct txbd8 *next_txbd(struct txbd8 *bdp, struct txbd8 *base,
|
2012-06-05 11:42:13 +08:00
|
|
|
int ring_size)
|
2008-12-18 08:51:04 +08:00
|
|
|
{
|
|
|
|
return skip_txbd(bdp, 1, base, ring_size);
|
|
|
|
}
|
|
|
|
|
2013-08-05 22:20:09 +08:00
|
|
|
/* eTSEC12: csum generation not supported for some fcb offsets */
|
|
|
|
static inline bool gfar_csum_errata_12(struct gfar_private *priv,
|
|
|
|
unsigned long fcb_addr)
|
|
|
|
{
|
|
|
|
return (gfar_has_errata(priv, GFAR_ERRATA_12) &&
|
|
|
|
(fcb_addr % 0x20) > 0x18);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* eTSEC76: csum generation for frames larger than 2500 may
|
|
|
|
* cause excess delays before start of transmission
|
|
|
|
*/
|
|
|
|
static inline bool gfar_csum_errata_76(struct gfar_private *priv,
|
|
|
|
unsigned int len)
|
|
|
|
{
|
|
|
|
return (gfar_has_errata(priv, GFAR_ERRATA_76) &&
|
|
|
|
(len > 2500));
|
|
|
|
}
|
|
|
|
|
2012-06-05 11:42:12 +08:00
|
|
|
/* This is called by the kernel when a frame is ready for transmission.
|
|
|
|
* It is pointed to by the dev->hard_start_xmit function pointer
|
|
|
|
*/
|
2018-09-21 10:50:32 +08:00
|
|
|
static netdev_tx_t gfar_start_xmit(struct sk_buff *skb, struct net_device *dev)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct gfar_private *priv = netdev_priv(dev);
|
2009-11-02 15:03:00 +08:00
|
|
|
struct gfar_priv_tx_q *tx_queue = NULL;
|
2009-11-02 15:03:15 +08:00
|
|
|
struct netdev_queue *txq;
|
2009-11-02 15:03:09 +08:00
|
|
|
struct gfar __iomem *regs = NULL;
|
2005-06-20 23:54:21 +08:00
|
|
|
struct txfcb *fcb = NULL;
|
2010-04-09 07:10:35 +08:00
|
|
|
struct txbd8 *txbdp, *txbdp_start, *base, *txbdp_tstamp = NULL;
|
2008-12-17 07:34:50 +08:00
|
|
|
u32 lstatus;
|
2016-02-23 17:48:38 +08:00
|
|
|
skb_frag_t *frag;
|
2013-08-05 22:20:10 +08:00
|
|
|
int i, rq = 0;
|
|
|
|
int do_tstamp, do_csum, do_vlan;
|
2008-12-18 08:51:04 +08:00
|
|
|
u32 bufaddr;
|
2013-08-30 20:01:15 +08:00
|
|
|
unsigned int nr_frags, nr_txbds, bytes_sent, fcb_len = 0;
|
2009-11-02 15:03:15 +08:00
|
|
|
|
|
|
|
rq = skb->queue_mapping;
|
|
|
|
tx_queue = priv->tx_queue[rq];
|
|
|
|
txq = netdev_get_tx_queue(dev, rq);
|
2009-11-02 15:03:00 +08:00
|
|
|
base = tx_queue->tx_bd_base;
|
2009-11-02 15:03:34 +08:00
|
|
|
regs = tx_queue->grp->regs;
|
2010-04-09 07:10:35 +08:00
|
|
|
|
2013-08-05 22:20:10 +08:00
|
|
|
do_csum = (CHECKSUM_PARTIAL == skb->ip_summed);
|
2015-01-14 00:13:44 +08:00
|
|
|
do_vlan = skb_vlan_tag_present(skb);
|
2013-08-05 22:20:10 +08:00
|
|
|
do_tstamp = (skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) &&
|
|
|
|
priv->hwts_tx_en;
|
|
|
|
|
|
|
|
if (do_csum || do_vlan)
|
|
|
|
fcb_len = GMAC_FCB_LEN;
|
|
|
|
|
2010-04-09 07:10:35 +08:00
|
|
|
/* check if time stamp should be generated */
|
2013-08-05 22:20:10 +08:00
|
|
|
if (unlikely(do_tstamp))
|
|
|
|
fcb_len = GMAC_FCB_LEN + GMAC_TXPAL_LEN;
|
2008-12-18 08:51:04 +08:00
|
|
|
|
2009-03-28 06:54:30 +08:00
|
|
|
/* make space for additional header when fcb is needed */
|
2020-10-29 16:10:56 +08:00
|
|
|
if (fcb_len) {
|
|
|
|
if (unlikely(skb_cow_head(skb, fcb_len))) {
|
2009-03-27 15:38:45 +08:00
|
|
|
dev->stats.tx_errors++;
|
2014-03-12 05:20:26 +08:00
|
|
|
dev_kfree_skb_any(skb);
|
2009-03-27 15:38:45 +08:00
|
|
|
return NETDEV_TX_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-18 08:51:04 +08:00
|
|
|
/* total number of fragments in the SKB */
|
|
|
|
nr_frags = skb_shinfo(skb)->nr_frags;
|
|
|
|
|
2010-04-09 07:10:35 +08:00
|
|
|
/* calculate the required number of TxBDs for this skb */
|
|
|
|
if (unlikely(do_tstamp))
|
|
|
|
nr_txbds = nr_frags + 2;
|
|
|
|
else
|
|
|
|
nr_txbds = nr_frags + 1;
|
|
|
|
|
2008-12-18 08:51:04 +08:00
|
|
|
/* check if there is space to queue this packet */
|
2010-04-09 07:10:35 +08:00
|
|
|
if (nr_txbds > tx_queue->num_txbdfree) {
|
2008-12-18 08:51:04 +08:00
|
|
|
/* no space, stop the queue */
|
2009-11-02 15:03:15 +08:00
|
|
|
netif_tx_stop_queue(txq);
|
2008-12-18 08:51:04 +08:00
|
|
|
dev->stats.tx_fifo_errors++;
|
|
|
|
return NETDEV_TX_BUSY;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Update transmit stats */
|
2013-08-30 20:01:15 +08:00
|
|
|
bytes_sent = skb->len;
|
|
|
|
tx_queue->stats.tx_bytes += bytes_sent;
|
|
|
|
/* keep Tx bytes on wire for BQL accounting */
|
|
|
|
GFAR_CB(skb)->bytes_sent = bytes_sent;
|
2011-01-12 20:13:14 +08:00
|
|
|
tx_queue->stats.tx_packets++;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-11-02 15:03:00 +08:00
|
|
|
txbdp = txbdp_start = tx_queue->cur_tx;
|
2015-03-13 16:36:28 +08:00
|
|
|
lstatus = be32_to_cpu(txbdp->lstatus);
|
2010-04-09 07:10:35 +08:00
|
|
|
|
2012-01-10 07:26:51 +08:00
|
|
|
/* Add TxPAL between FCB and frame if required */
|
|
|
|
if (unlikely(do_tstamp)) {
|
|
|
|
skb_push(skb, GMAC_TXPAL_LEN);
|
|
|
|
memset(skb->data, 0, GMAC_TXPAL_LEN);
|
|
|
|
}
|
|
|
|
|
2013-08-05 22:20:10 +08:00
|
|
|
/* Add TxFCB if required */
|
|
|
|
if (fcb_len) {
|
2009-03-27 15:38:45 +08:00
|
|
|
fcb = gfar_add_fcb(skb);
|
2013-08-05 22:20:09 +08:00
|
|
|
lstatus |= BD_LFLAG(TXBD_TOE);
|
2013-08-05 22:20:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Set up checksumming */
|
|
|
|
if (do_csum) {
|
|
|
|
gfar_tx_checksum(skb, fcb, fcb_len);
|
2013-08-05 22:20:09 +08:00
|
|
|
|
|
|
|
if (unlikely(gfar_csum_errata_12(priv, (unsigned long)fcb)) ||
|
|
|
|
unlikely(gfar_csum_errata_76(priv, skb->len))) {
|
2011-03-17 01:57:13 +08:00
|
|
|
__skb_pull(skb, GMAC_FCB_LEN);
|
|
|
|
skb_checksum_help(skb);
|
2013-08-05 22:20:10 +08:00
|
|
|
if (do_vlan || do_tstamp) {
|
|
|
|
/* put back a new fcb for vlan/tstamp TOE */
|
|
|
|
fcb = gfar_add_fcb(skb);
|
|
|
|
} else {
|
|
|
|
/* Tx TOE not used */
|
|
|
|
lstatus &= ~(BD_LFLAG(TXBD_TOE));
|
|
|
|
fcb = NULL;
|
|
|
|
}
|
2011-03-17 01:57:13 +08:00
|
|
|
}
|
2005-06-20 23:54:21 +08:00
|
|
|
}
|
|
|
|
|
2013-08-05 22:20:10 +08:00
|
|
|
if (do_vlan)
|
2009-03-27 15:38:45 +08:00
|
|
|
gfar_tx_vlan(skb, fcb);
|
2005-06-20 23:54:21 +08:00
|
|
|
|
2014-12-11 14:08:41 +08:00
|
|
|
bufaddr = dma_map_single(priv->dev, skb->data, skb_headlen(skb),
|
|
|
|
DMA_TO_DEVICE);
|
|
|
|
if (unlikely(dma_mapping_error(priv->dev, bufaddr)))
|
|
|
|
goto dma_map_err;
|
|
|
|
|
2015-03-13 16:36:28 +08:00
|
|
|
txbdp_start->bufPtr = cpu_to_be32(bufaddr);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-04-09 07:10:35 +08:00
|
|
|
/* Time stamp insertion requires one additional TxBD */
|
|
|
|
if (unlikely(do_tstamp))
|
|
|
|
txbdp_tstamp = txbdp = next_txbd(txbdp, base,
|
2012-06-05 11:42:13 +08:00
|
|
|
tx_queue->tx_ring_size);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2016-02-23 17:48:39 +08:00
|
|
|
if (likely(!nr_frags)) {
|
2016-06-02 17:36:28 +08:00
|
|
|
if (likely(!do_tstamp))
|
|
|
|
lstatus |= BD_LFLAG(TXBD_LAST | TXBD_INTERRUPT);
|
2008-12-18 08:51:04 +08:00
|
|
|
} else {
|
2016-02-23 17:48:37 +08:00
|
|
|
u32 lstatus_start = lstatus;
|
|
|
|
|
2008-12-18 08:51:04 +08:00
|
|
|
/* Place the fragment addresses and lengths into the TxBDs */
|
2016-02-23 17:48:38 +08:00
|
|
|
frag = &skb_shinfo(skb)->frags[0];
|
|
|
|
for (i = 0; i < nr_frags; i++, frag++) {
|
|
|
|
unsigned int size;
|
|
|
|
|
2008-12-18 08:51:04 +08:00
|
|
|
/* Point at the next BD, wrapping as needed */
|
2009-11-02 15:03:00 +08:00
|
|
|
txbdp = next_txbd(txbdp, base, tx_queue->tx_ring_size);
|
2008-12-18 08:51:04 +08:00
|
|
|
|
2016-02-23 17:48:38 +08:00
|
|
|
size = skb_frag_size(frag);
|
2008-12-18 08:51:04 +08:00
|
|
|
|
2016-02-23 17:48:38 +08:00
|
|
|
lstatus = be32_to_cpu(txbdp->lstatus) | size |
|
2012-06-05 11:42:13 +08:00
|
|
|
BD_LFLAG(TXBD_READY);
|
2008-12-18 08:51:04 +08:00
|
|
|
|
|
|
|
/* Handle the last BD specially */
|
|
|
|
if (i == nr_frags - 1)
|
|
|
|
lstatus |= BD_LFLAG(TXBD_LAST | TXBD_INTERRUPT);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2016-02-23 17:48:38 +08:00
|
|
|
bufaddr = skb_frag_dma_map(priv->dev, frag, 0,
|
|
|
|
size, DMA_TO_DEVICE);
|
2014-12-11 14:08:41 +08:00
|
|
|
if (unlikely(dma_mapping_error(priv->dev, bufaddr)))
|
|
|
|
goto dma_map_err;
|
2008-12-18 08:51:04 +08:00
|
|
|
|
|
|
|
/* set the TxBD length and buffer pointer */
|
2015-03-13 16:36:28 +08:00
|
|
|
txbdp->bufPtr = cpu_to_be32(bufaddr);
|
|
|
|
txbdp->lstatus = cpu_to_be32(lstatus);
|
2008-12-18 08:51:04 +08:00
|
|
|
}
|
|
|
|
|
2016-02-23 17:48:37 +08:00
|
|
|
lstatus = lstatus_start;
|
2008-12-18 08:51:04 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-06-05 11:42:12 +08:00
|
|
|
/* If time stamping is requested one additional TxBD must be set up. The
|
2010-04-09 07:10:35 +08:00
|
|
|
* first TxBD points to the FCB and must have a data length of
|
|
|
|
* GMAC_FCB_LEN. The second TxBD points to the actual frame data with
|
|
|
|
* the full frame length.
|
|
|
|
*/
|
|
|
|
if (unlikely(do_tstamp)) {
|
2015-03-13 16:36:28 +08:00
|
|
|
u32 lstatus_ts = be32_to_cpu(txbdp_tstamp->lstatus);
|
|
|
|
|
|
|
|
bufaddr = be32_to_cpu(txbdp_start->bufPtr);
|
|
|
|
bufaddr += fcb_len;
|
2016-02-23 17:48:39 +08:00
|
|
|
|
2015-03-13 16:36:28 +08:00
|
|
|
lstatus_ts |= BD_LFLAG(TXBD_READY) |
|
|
|
|
(skb_headlen(skb) - fcb_len);
|
2016-02-23 17:48:39 +08:00
|
|
|
if (!nr_frags)
|
|
|
|
lstatus_ts |= BD_LFLAG(TXBD_LAST | TXBD_INTERRUPT);
|
2015-03-13 16:36:28 +08:00
|
|
|
|
|
|
|
txbdp_tstamp->bufPtr = cpu_to_be32(bufaddr);
|
|
|
|
txbdp_tstamp->lstatus = cpu_to_be32(lstatus_ts);
|
2010-04-09 07:10:35 +08:00
|
|
|
lstatus |= BD_LFLAG(TXBD_CRC | TXBD_READY) | GMAC_FCB_LEN;
|
2016-02-23 17:48:37 +08:00
|
|
|
|
|
|
|
/* Setup tx hardware time stamping */
|
|
|
|
skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
|
|
|
|
fcb->ptp = 1;
|
2010-04-09 07:10:35 +08:00
|
|
|
} else {
|
|
|
|
lstatus |= BD_LFLAG(TXBD_CRC | TXBD_READY) | skb_headlen(skb);
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2013-08-30 20:01:15 +08:00
|
|
|
netdev_tx_sent_queue(txq, bytes_sent);
|
2012-01-07 02:51:03 +08:00
|
|
|
|
2014-10-07 15:44:35 +08:00
|
|
|
gfar_wmb();
|
2005-11-12 02:38:59 +08:00
|
|
|
|
2015-03-13 16:36:28 +08:00
|
|
|
txbdp_start->lstatus = cpu_to_be32(lstatus);
|
2008-12-18 08:51:04 +08:00
|
|
|
|
2014-10-07 15:44:35 +08:00
|
|
|
gfar_wmb(); /* force lstatus write before tx_skbuff */
|
gianfar: Fix TX ring processing on SMP machines
Starting with commit a3bc1f11e9b867a4f49505 ("gianfar: Revive SKB
recycling") gianfar driver sooner or later stops transmitting any
packets on SMP machines.
start_xmit() prepares new skb for transmitting, generally it does
three things:
1. sets up all BDs (marks them ready to send), except the first one.
2. stores skb into tx_queue->tx_skbuff so that clean_tx_ring()
would cleanup it later.
3. sets up the first BD, i.e. marks it ready.
Here is what clean_tx_ring() does:
1. reads skbs from tx_queue->tx_skbuff
2. checks if the *last* BD is ready. If it's still ready [to send]
then it it isn't transmitted, so clean_tx_ring() returns.
Otherwise it actually cleanups BDs. All is OK.
Now, if there is just one BD, code flow:
- start_xmit(): stores skb into tx_skbuff. Note that the first BD
(which is also the last one) isn't marked as ready, yet.
- clean_tx_ring(): sees that skb is not null, *and* its lstatus
says that it is NOT ready (like if BD was sent), so it cleans
it up (bad!)
- start_xmit(): marks BD as ready [to send], but it's too late.
We can fix this simply by reordering lstatus/tx_skbuff writes.
Reported-by: Martyn Welch <martyn.welch@ge.com>
Bisected-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Signed-off-by: Anton Vorontsov <avorontsov@ru.mvista.com>
Tested-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Tested-by: Martyn Welch <martyn.welch@ge.com>
Cc: Sandeep Gopalpet <Sandeep.Kumar@freescale.com>
Cc: Stable <stable@vger.kernel.org> [2.6.33]
Signed-off-by: David S. Miller <davem@davemloft.net>
2010-03-03 16:18:58 +08:00
|
|
|
|
|
|
|
tx_queue->tx_skbuff[tx_queue->skb_curtx] = skb;
|
|
|
|
|
2008-12-18 08:51:04 +08:00
|
|
|
/* Update the current skb pointer to the next entry we will use
|
2012-06-05 11:42:12 +08:00
|
|
|
* (wrapping if necessary)
|
|
|
|
*/
|
2009-11-02 15:03:00 +08:00
|
|
|
tx_queue->skb_curtx = (tx_queue->skb_curtx + 1) &
|
2012-06-05 11:42:13 +08:00
|
|
|
TX_RING_MOD_MASK(tx_queue->tx_ring_size);
|
2008-12-18 08:51:04 +08:00
|
|
|
|
2009-11-02 15:03:00 +08:00
|
|
|
tx_queue->cur_tx = next_txbd(txbdp, base, tx_queue->tx_ring_size);
|
2008-12-18 08:51:04 +08:00
|
|
|
|
2015-05-06 23:07:29 +08:00
|
|
|
/* We can work in parallel with gfar_clean_tx_ring(), except
|
|
|
|
* when modifying num_txbdfree. Note that we didn't grab the lock
|
|
|
|
* when we were reading the num_txbdfree and checking for available
|
|
|
|
* space, that's because outside of this function it can only grow.
|
|
|
|
*/
|
|
|
|
spin_lock_bh(&tx_queue->txlock);
|
2008-12-18 08:51:04 +08:00
|
|
|
/* reduce TxBD free count */
|
2010-04-09 07:10:35 +08:00
|
|
|
tx_queue->num_txbdfree -= (nr_txbds);
|
2015-05-06 23:07:29 +08:00
|
|
|
spin_unlock_bh(&tx_queue->txlock);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* If the next BD still needs to be cleaned up, then the bds
|
2012-06-05 11:42:12 +08:00
|
|
|
* are full. We need to tell the kernel to stop sending us stuff.
|
|
|
|
*/
|
2009-11-02 15:03:00 +08:00
|
|
|
if (!tx_queue->num_txbdfree) {
|
2009-11-02 15:03:15 +08:00
|
|
|
netif_tx_stop_queue(txq);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-10-04 08:41:50 +08:00
|
|
|
dev->stats.tx_fifo_errors++;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Tell the DMA to go go go */
|
2009-11-02 15:03:15 +08:00
|
|
|
gfar_write(®s->tstat, TSTAT_CLEAR_THALT >> tx_queue->qindex);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-03-27 15:38:45 +08:00
|
|
|
return NETDEV_TX_OK;
|
2014-12-11 14:08:41 +08:00
|
|
|
|
|
|
|
dma_map_err:
|
|
|
|
txbdp = next_txbd(txbdp_start, base, tx_queue->tx_ring_size);
|
|
|
|
if (do_tstamp)
|
|
|
|
txbdp = next_txbd(txbdp, base, tx_queue->tx_ring_size);
|
|
|
|
for (i = 0; i < nr_frags; i++) {
|
2015-03-13 16:36:28 +08:00
|
|
|
lstatus = be32_to_cpu(txbdp->lstatus);
|
2014-12-11 14:08:41 +08:00
|
|
|
if (!(lstatus & BD_LFLAG(TXBD_READY)))
|
|
|
|
break;
|
|
|
|
|
2015-03-13 16:36:28 +08:00
|
|
|
lstatus &= ~BD_LFLAG(TXBD_READY);
|
|
|
|
txbdp->lstatus = cpu_to_be32(lstatus);
|
|
|
|
bufaddr = be32_to_cpu(txbdp->bufPtr);
|
|
|
|
dma_unmap_page(priv->dev, bufaddr, be16_to_cpu(txbdp->length),
|
2014-12-11 14:08:41 +08:00
|
|
|
DMA_TO_DEVICE);
|
|
|
|
txbdp = next_txbd(txbdp, base, tx_queue->tx_ring_size);
|
|
|
|
}
|
|
|
|
gfar_wmb();
|
|
|
|
dev_kfree_skb_any(skb);
|
|
|
|
return NETDEV_TX_OK;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Changes the mac address if the controller is not running. */
|
2008-05-03 02:00:30 +08:00
|
|
|
static int gfar_set_mac_address(struct net_device *dev)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-11-12 02:38:59 +08:00
|
|
|
gfar_set_mac_for_addr(dev, 0, dev->dev_addr);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int gfar_change_mtu(struct net_device *dev, int new_mtu)
|
|
|
|
{
|
|
|
|
struct gfar_private *priv = netdev_priv(dev);
|
|
|
|
|
gianfar: Fix device reset races (oops) for Tx
The device reset procedure, stop_gfar()/startup_gfar(), has
concurrency issues.
"Kernel access of bad area" oopses show up during Tx timeout
device reset or other reset cases (like changing MTU) that
happen while the interface still has traffic. The oopses
happen in start_xmit and clean_tx_ring when accessing tx_queue->
tx_skbuff which is NULL. The race comes from de-allocating the
tx_skbuff while transmission and napi processing are still
active. Though the Tx queues get temoprarily stopped when Tx
timeout occurs, they get re-enabled as a result of Tx congestion
handling inside the napi context (see clean_tx_ring()). Not
disabling the napi during reset is also a bug, because
clean_tx_ring() will try to access tx_skbuff while it is being
de-alloc'ed and re-alloc'ed.
To fix this, stop_gfar() needs to disable napi processing
after stopping the Tx queues. However, in order to prevent
clean_tx_ring() to re-enable the Tx queue before the napi
gets disabled, the device state DOWN has been introduced.
It prevents the Tx congestion management from re-enabling the
de-congested Tx queue while the device is brought down.
An additional locking state, RESETTING, has been introduced
to prevent simultaneous resets or to prevent configuring the
device while it is resetting.
The bogus 'rxlock's (for each Rx queue) have been removed since
their purpose is not justified, as they don't prevent nor are
suited to prevent device reset/reconfig races (such as this one).
Signed-off-by: Claudiu Manoil <claudiu.manoil@freescale.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-02-24 18:13:45 +08:00
|
|
|
while (test_and_set_bit_lock(GFAR_RESETTING, &priv->state))
|
|
|
|
cpu_relax();
|
|
|
|
|
gianfar: Fix on-the-fly vlan and mtu updates
The RCTRL and TCTRL registers should not be changed
on-the-fly, while the controller is running, otherwise
unexpected behaviour occurs. But that's exactly what
gfar_vlan_mode() does, updating the VLAN acceleration
bits inside RCTRL/TCTRL. The attempt to lock these
operations doesn't help, but only adds to the confusion.
There's also a dependency for Rx FCB insertion (activating
/de-activating the TOE offload block on Rx) which might
change the required rx buffer size. This makes matters
worse as gfar_vlan_mode() ends up calling gfar_change_mtu(),
though the MTU size remains the same. Note that there are
other situations that may affect the required rx buffer size,
like changing RXCSUM or rx hw timestamping, but errorneously
the rx buffer size is not recomputed/ updated in the process.
To fix this, do the vlan updates properly inside the MAC
reset and reconfiguration procedure, which takes care of
the rx buffer size dependecy and the rx TOE block (PRSDEP)
activation/deactivation as well (in the correct order).
As a consequence, MTU/ rx buff size updates are done now
by the same MAC reset and reconfig procedure, so that out
of context updates to MAXFRM, MRBLR, and MACCFG inside
change_mtu() are no longer needed. The rx buffer size
dependecy to Rx FCB is now handled for the other cases too
(RXCSUM and rx hw timestamping).
Signed-off-by: Claudiu Manoil <claudiu.manoil@freescale.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-02-24 18:13:43 +08:00
|
|
|
if (dev->flags & IFF_UP)
|
2005-04-17 06:20:36 +08:00
|
|
|
stop_gfar(dev);
|
|
|
|
|
|
|
|
dev->mtu = new_mtu;
|
|
|
|
|
gianfar: Fix on-the-fly vlan and mtu updates
The RCTRL and TCTRL registers should not be changed
on-the-fly, while the controller is running, otherwise
unexpected behaviour occurs. But that's exactly what
gfar_vlan_mode() does, updating the VLAN acceleration
bits inside RCTRL/TCTRL. The attempt to lock these
operations doesn't help, but only adds to the confusion.
There's also a dependency for Rx FCB insertion (activating
/de-activating the TOE offload block on Rx) which might
change the required rx buffer size. This makes matters
worse as gfar_vlan_mode() ends up calling gfar_change_mtu(),
though the MTU size remains the same. Note that there are
other situations that may affect the required rx buffer size,
like changing RXCSUM or rx hw timestamping, but errorneously
the rx buffer size is not recomputed/ updated in the process.
To fix this, do the vlan updates properly inside the MAC
reset and reconfiguration procedure, which takes care of
the rx buffer size dependecy and the rx TOE block (PRSDEP)
activation/deactivation as well (in the correct order).
As a consequence, MTU/ rx buff size updates are done now
by the same MAC reset and reconfig procedure, so that out
of context updates to MAXFRM, MRBLR, and MACCFG inside
change_mtu() are no longer needed. The rx buffer size
dependecy to Rx FCB is now handled for the other cases too
(RXCSUM and rx hw timestamping).
Signed-off-by: Claudiu Manoil <claudiu.manoil@freescale.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-02-24 18:13:43 +08:00
|
|
|
if (dev->flags & IFF_UP)
|
2005-04-17 06:20:36 +08:00
|
|
|
startup_gfar(dev);
|
|
|
|
|
gianfar: Fix device reset races (oops) for Tx
The device reset procedure, stop_gfar()/startup_gfar(), has
concurrency issues.
"Kernel access of bad area" oopses show up during Tx timeout
device reset or other reset cases (like changing MTU) that
happen while the interface still has traffic. The oopses
happen in start_xmit and clean_tx_ring when accessing tx_queue->
tx_skbuff which is NULL. The race comes from de-allocating the
tx_skbuff while transmission and napi processing are still
active. Though the Tx queues get temoprarily stopped when Tx
timeout occurs, they get re-enabled as a result of Tx congestion
handling inside the napi context (see clean_tx_ring()). Not
disabling the napi during reset is also a bug, because
clean_tx_ring() will try to access tx_skbuff while it is being
de-alloc'ed and re-alloc'ed.
To fix this, stop_gfar() needs to disable napi processing
after stopping the Tx queues. However, in order to prevent
clean_tx_ring() to re-enable the Tx queue before the napi
gets disabled, the device state DOWN has been introduced.
It prevents the Tx congestion management from re-enabling the
de-congested Tx queue while the device is brought down.
An additional locking state, RESETTING, has been introduced
to prevent simultaneous resets or to prevent configuring the
device while it is resetting.
The bogus 'rxlock's (for each Rx queue) have been removed since
their purpose is not justified, as they don't prevent nor are
suited to prevent device reset/reconfig races (such as this one).
Signed-off-by: Claudiu Manoil <claudiu.manoil@freescale.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-02-24 18:13:45 +08:00
|
|
|
clear_bit_unlock(GFAR_RESETTING, &priv->state);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-09-23 14:16:03 +08:00
|
|
|
static void reset_gfar(struct net_device *ndev)
|
gianfar: Fix device reset races (oops) for Tx
The device reset procedure, stop_gfar()/startup_gfar(), has
concurrency issues.
"Kernel access of bad area" oopses show up during Tx timeout
device reset or other reset cases (like changing MTU) that
happen while the interface still has traffic. The oopses
happen in start_xmit and clean_tx_ring when accessing tx_queue->
tx_skbuff which is NULL. The race comes from de-allocating the
tx_skbuff while transmission and napi processing are still
active. Though the Tx queues get temoprarily stopped when Tx
timeout occurs, they get re-enabled as a result of Tx congestion
handling inside the napi context (see clean_tx_ring()). Not
disabling the napi during reset is also a bug, because
clean_tx_ring() will try to access tx_skbuff while it is being
de-alloc'ed and re-alloc'ed.
To fix this, stop_gfar() needs to disable napi processing
after stopping the Tx queues. However, in order to prevent
clean_tx_ring() to re-enable the Tx queue before the napi
gets disabled, the device state DOWN has been introduced.
It prevents the Tx congestion management from re-enabling the
de-congested Tx queue while the device is brought down.
An additional locking state, RESETTING, has been introduced
to prevent simultaneous resets or to prevent configuring the
device while it is resetting.
The bogus 'rxlock's (for each Rx queue) have been removed since
their purpose is not justified, as they don't prevent nor are
suited to prevent device reset/reconfig races (such as this one).
Signed-off-by: Claudiu Manoil <claudiu.manoil@freescale.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-02-24 18:13:45 +08:00
|
|
|
{
|
|
|
|
struct gfar_private *priv = netdev_priv(ndev);
|
|
|
|
|
|
|
|
while (test_and_set_bit_lock(GFAR_RESETTING, &priv->state))
|
|
|
|
cpu_relax();
|
|
|
|
|
|
|
|
stop_gfar(ndev);
|
|
|
|
startup_gfar(ndev);
|
|
|
|
|
|
|
|
clear_bit_unlock(GFAR_RESETTING, &priv->state);
|
|
|
|
}
|
|
|
|
|
2008-08-20 03:12:45 +08:00
|
|
|
/* gfar_reset_task gets scheduled when a packet has not been
|
2005-04-17 06:20:36 +08:00
|
|
|
* transmitted after a set amount of time.
|
|
|
|
* For now, assume that clearing out all the structures, and
|
2008-08-20 03:12:45 +08:00
|
|
|
* starting over will fix the problem.
|
|
|
|
*/
|
|
|
|
static void gfar_reset_task(struct work_struct *work)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-08-20 03:12:45 +08:00
|
|
|
struct gfar_private *priv = container_of(work, struct gfar_private,
|
2012-06-05 11:42:13 +08:00
|
|
|
reset_task);
|
gianfar: Fix device reset races (oops) for Tx
The device reset procedure, stop_gfar()/startup_gfar(), has
concurrency issues.
"Kernel access of bad area" oopses show up during Tx timeout
device reset or other reset cases (like changing MTU) that
happen while the interface still has traffic. The oopses
happen in start_xmit and clean_tx_ring when accessing tx_queue->
tx_skbuff which is NULL. The race comes from de-allocating the
tx_skbuff while transmission and napi processing are still
active. Though the Tx queues get temoprarily stopped when Tx
timeout occurs, they get re-enabled as a result of Tx congestion
handling inside the napi context (see clean_tx_ring()). Not
disabling the napi during reset is also a bug, because
clean_tx_ring() will try to access tx_skbuff while it is being
de-alloc'ed and re-alloc'ed.
To fix this, stop_gfar() needs to disable napi processing
after stopping the Tx queues. However, in order to prevent
clean_tx_ring() to re-enable the Tx queue before the napi
gets disabled, the device state DOWN has been introduced.
It prevents the Tx congestion management from re-enabling the
de-congested Tx queue while the device is brought down.
An additional locking state, RESETTING, has been introduced
to prevent simultaneous resets or to prevent configuring the
device while it is resetting.
The bogus 'rxlock's (for each Rx queue) have been removed since
their purpose is not justified, as they don't prevent nor are
suited to prevent device reset/reconfig races (such as this one).
Signed-off-by: Claudiu Manoil <claudiu.manoil@freescale.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-02-24 18:13:45 +08:00
|
|
|
reset_gfar(priv->ndev);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
netdev: pass the stuck queue to the timeout handler
This allows incrementing the correct timeout statistic without any mess.
Down the road, devices can learn to reset just the specific queue.
The patch was generated with the following script:
use strict;
use warnings;
our $^I = '.bak';
my @work = (
["arch/m68k/emu/nfeth.c", "nfeth_tx_timeout"],
["arch/um/drivers/net_kern.c", "uml_net_tx_timeout"],
["arch/um/drivers/vector_kern.c", "vector_net_tx_timeout"],
["arch/xtensa/platforms/iss/network.c", "iss_net_tx_timeout"],
["drivers/char/pcmcia/synclink_cs.c", "hdlcdev_tx_timeout"],
["drivers/infiniband/ulp/ipoib/ipoib_main.c", "ipoib_timeout"],
["drivers/infiniband/ulp/ipoib/ipoib_main.c", "ipoib_timeout"],
["drivers/message/fusion/mptlan.c", "mpt_lan_tx_timeout"],
["drivers/misc/sgi-xp/xpnet.c", "xpnet_dev_tx_timeout"],
["drivers/net/appletalk/cops.c", "cops_timeout"],
["drivers/net/arcnet/arcdevice.h", "arcnet_timeout"],
["drivers/net/arcnet/arcnet.c", "arcnet_timeout"],
["drivers/net/arcnet/com20020.c", "arcnet_timeout"],
["drivers/net/ethernet/3com/3c509.c", "el3_tx_timeout"],
["drivers/net/ethernet/3com/3c515.c", "corkscrew_timeout"],
["drivers/net/ethernet/3com/3c574_cs.c", "el3_tx_timeout"],
["drivers/net/ethernet/3com/3c589_cs.c", "el3_tx_timeout"],
["drivers/net/ethernet/3com/3c59x.c", "vortex_tx_timeout"],
["drivers/net/ethernet/3com/3c59x.c", "vortex_tx_timeout"],
["drivers/net/ethernet/3com/typhoon.c", "typhoon_tx_timeout"],
["drivers/net/ethernet/8390/8390.h", "ei_tx_timeout"],
["drivers/net/ethernet/8390/8390.h", "eip_tx_timeout"],
["drivers/net/ethernet/8390/8390.c", "ei_tx_timeout"],
["drivers/net/ethernet/8390/8390p.c", "eip_tx_timeout"],
["drivers/net/ethernet/8390/ax88796.c", "ax_ei_tx_timeout"],
["drivers/net/ethernet/8390/axnet_cs.c", "axnet_tx_timeout"],
["drivers/net/ethernet/8390/etherh.c", "__ei_tx_timeout"],
["drivers/net/ethernet/8390/hydra.c", "__ei_tx_timeout"],
["drivers/net/ethernet/8390/mac8390.c", "__ei_tx_timeout"],
["drivers/net/ethernet/8390/mcf8390.c", "__ei_tx_timeout"],
["drivers/net/ethernet/8390/lib8390.c", "__ei_tx_timeout"],
["drivers/net/ethernet/8390/ne2k-pci.c", "ei_tx_timeout"],
["drivers/net/ethernet/8390/pcnet_cs.c", "ei_tx_timeout"],
["drivers/net/ethernet/8390/smc-ultra.c", "ei_tx_timeout"],
["drivers/net/ethernet/8390/wd.c", "ei_tx_timeout"],
["drivers/net/ethernet/8390/zorro8390.c", "__ei_tx_timeout"],
["drivers/net/ethernet/adaptec/starfire.c", "tx_timeout"],
["drivers/net/ethernet/agere/et131x.c", "et131x_tx_timeout"],
["drivers/net/ethernet/allwinner/sun4i-emac.c", "emac_timeout"],
["drivers/net/ethernet/alteon/acenic.c", "ace_watchdog"],
["drivers/net/ethernet/amazon/ena/ena_netdev.c", "ena_tx_timeout"],
["drivers/net/ethernet/amd/7990.h", "lance_tx_timeout"],
["drivers/net/ethernet/amd/7990.c", "lance_tx_timeout"],
["drivers/net/ethernet/amd/a2065.c", "lance_tx_timeout"],
["drivers/net/ethernet/amd/am79c961a.c", "am79c961_timeout"],
["drivers/net/ethernet/amd/amd8111e.c", "amd8111e_tx_timeout"],
["drivers/net/ethernet/amd/ariadne.c", "ariadne_tx_timeout"],
["drivers/net/ethernet/amd/atarilance.c", "lance_tx_timeout"],
["drivers/net/ethernet/amd/au1000_eth.c", "au1000_tx_timeout"],
["drivers/net/ethernet/amd/declance.c", "lance_tx_timeout"],
["drivers/net/ethernet/amd/lance.c", "lance_tx_timeout"],
["drivers/net/ethernet/amd/mvme147.c", "lance_tx_timeout"],
["drivers/net/ethernet/amd/ni65.c", "ni65_timeout"],
["drivers/net/ethernet/amd/nmclan_cs.c", "mace_tx_timeout"],
["drivers/net/ethernet/amd/pcnet32.c", "pcnet32_tx_timeout"],
["drivers/net/ethernet/amd/sunlance.c", "lance_tx_timeout"],
["drivers/net/ethernet/amd/xgbe/xgbe-drv.c", "xgbe_tx_timeout"],
["drivers/net/ethernet/apm/xgene-v2/main.c", "xge_timeout"],
["drivers/net/ethernet/apm/xgene/xgene_enet_main.c", "xgene_enet_timeout"],
["drivers/net/ethernet/apple/macmace.c", "mace_tx_timeout"],
["drivers/net/ethernet/atheros/ag71xx.c", "ag71xx_tx_timeout"],
["drivers/net/ethernet/atheros/alx/main.c", "alx_tx_timeout"],
["drivers/net/ethernet/atheros/atl1c/atl1c_main.c", "atl1c_tx_timeout"],
["drivers/net/ethernet/atheros/atl1e/atl1e_main.c", "atl1e_tx_timeout"],
["drivers/net/ethernet/atheros/atlx/atl.c", "atlx_tx_timeout"],
["drivers/net/ethernet/atheros/atlx/atl1.c", "atlx_tx_timeout"],
["drivers/net/ethernet/atheros/atlx/atl2.c", "atl2_tx_timeout"],
["drivers/net/ethernet/broadcom/b44.c", "b44_tx_timeout"],
["drivers/net/ethernet/broadcom/bcmsysport.c", "bcm_sysport_tx_timeout"],
["drivers/net/ethernet/broadcom/bnx2.c", "bnx2_tx_timeout"],
["drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h", "bnx2x_tx_timeout"],
["drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c", "bnx2x_tx_timeout"],
["drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c", "bnx2x_tx_timeout"],
["drivers/net/ethernet/broadcom/bnxt/bnxt.c", "bnxt_tx_timeout"],
["drivers/net/ethernet/broadcom/genet/bcmgenet.c", "bcmgenet_timeout"],
["drivers/net/ethernet/broadcom/sb1250-mac.c", "sbmac_tx_timeout"],
["drivers/net/ethernet/broadcom/tg3.c", "tg3_tx_timeout"],
["drivers/net/ethernet/calxeda/xgmac.c", "xgmac_tx_timeout"],
["drivers/net/ethernet/cavium/liquidio/lio_main.c", "liquidio_tx_timeout"],
["drivers/net/ethernet/cavium/liquidio/lio_vf_main.c", "liquidio_tx_timeout"],
["drivers/net/ethernet/cavium/liquidio/lio_vf_rep.c", "lio_vf_rep_tx_timeout"],
["drivers/net/ethernet/cavium/thunder/nicvf_main.c", "nicvf_tx_timeout"],
["drivers/net/ethernet/cirrus/cs89x0.c", "net_timeout"],
["drivers/net/ethernet/cisco/enic/enic_main.c", "enic_tx_timeout"],
["drivers/net/ethernet/cisco/enic/enic_main.c", "enic_tx_timeout"],
["drivers/net/ethernet/cortina/gemini.c", "gmac_tx_timeout"],
["drivers/net/ethernet/davicom/dm9000.c", "dm9000_timeout"],
["drivers/net/ethernet/dec/tulip/de2104x.c", "de_tx_timeout"],
["drivers/net/ethernet/dec/tulip/tulip_core.c", "tulip_tx_timeout"],
["drivers/net/ethernet/dec/tulip/winbond-840.c", "tx_timeout"],
["drivers/net/ethernet/dlink/dl2k.c", "rio_tx_timeout"],
["drivers/net/ethernet/dlink/sundance.c", "tx_timeout"],
["drivers/net/ethernet/emulex/benet/be_main.c", "be_tx_timeout"],
["drivers/net/ethernet/ethoc.c", "ethoc_tx_timeout"],
["drivers/net/ethernet/faraday/ftgmac100.c", "ftgmac100_tx_timeout"],
["drivers/net/ethernet/fealnx.c", "fealnx_tx_timeout"],
["drivers/net/ethernet/freescale/dpaa/dpaa_eth.c", "dpaa_tx_timeout"],
["drivers/net/ethernet/freescale/fec_main.c", "fec_timeout"],
["drivers/net/ethernet/freescale/fec_mpc52xx.c", "mpc52xx_fec_tx_timeout"],
["drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c", "fs_timeout"],
["drivers/net/ethernet/freescale/gianfar.c", "gfar_timeout"],
["drivers/net/ethernet/freescale/ucc_geth.c", "ucc_geth_timeout"],
["drivers/net/ethernet/fujitsu/fmvj18x_cs.c", "fjn_tx_timeout"],
["drivers/net/ethernet/google/gve/gve_main.c", "gve_tx_timeout"],
["drivers/net/ethernet/hisilicon/hip04_eth.c", "hip04_timeout"],
["drivers/net/ethernet/hisilicon/hix5hd2_gmac.c", "hix5hd2_net_timeout"],
["drivers/net/ethernet/hisilicon/hns/hns_enet.c", "hns_nic_net_timeout"],
["drivers/net/ethernet/hisilicon/hns3/hns3_enet.c", "hns3_nic_net_timeout"],
["drivers/net/ethernet/huawei/hinic/hinic_main.c", "hinic_tx_timeout"],
["drivers/net/ethernet/i825xx/82596.c", "i596_tx_timeout"],
["drivers/net/ethernet/i825xx/ether1.c", "ether1_timeout"],
["drivers/net/ethernet/i825xx/lib82596.c", "i596_tx_timeout"],
["drivers/net/ethernet/i825xx/sun3_82586.c", "sun3_82586_timeout"],
["drivers/net/ethernet/ibm/ehea/ehea_main.c", "ehea_tx_watchdog"],
["drivers/net/ethernet/ibm/emac/core.c", "emac_tx_timeout"],
["drivers/net/ethernet/ibm/emac/core.c", "emac_tx_timeout"],
["drivers/net/ethernet/ibm/ibmvnic.c", "ibmvnic_tx_timeout"],
["drivers/net/ethernet/intel/e100.c", "e100_tx_timeout"],
["drivers/net/ethernet/intel/e1000/e1000_main.c", "e1000_tx_timeout"],
["drivers/net/ethernet/intel/e1000e/netdev.c", "e1000_tx_timeout"],
["drivers/net/ethernet/intel/fm10k/fm10k_netdev.c", "fm10k_tx_timeout"],
["drivers/net/ethernet/intel/i40e/i40e_main.c", "i40e_tx_timeout"],
["drivers/net/ethernet/intel/iavf/iavf_main.c", "iavf_tx_timeout"],
["drivers/net/ethernet/intel/ice/ice_main.c", "ice_tx_timeout"],
["drivers/net/ethernet/intel/ice/ice_main.c", "ice_tx_timeout"],
["drivers/net/ethernet/intel/igb/igb_main.c", "igb_tx_timeout"],
["drivers/net/ethernet/intel/igbvf/netdev.c", "igbvf_tx_timeout"],
["drivers/net/ethernet/intel/ixgb/ixgb_main.c", "ixgb_tx_timeout"],
["drivers/net/ethernet/intel/ixgbe/ixgbe_debugfs.c", "adapter->netdev->netdev_ops->ndo_tx_timeout(adapter->netdev);"],
["drivers/net/ethernet/intel/ixgbe/ixgbe_main.c", "ixgbe_tx_timeout"],
["drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c", "ixgbevf_tx_timeout"],
["drivers/net/ethernet/jme.c", "jme_tx_timeout"],
["drivers/net/ethernet/korina.c", "korina_tx_timeout"],
["drivers/net/ethernet/lantiq_etop.c", "ltq_etop_tx_timeout"],
["drivers/net/ethernet/marvell/mv643xx_eth.c", "mv643xx_eth_tx_timeout"],
["drivers/net/ethernet/marvell/pxa168_eth.c", "pxa168_eth_tx_timeout"],
["drivers/net/ethernet/marvell/skge.c", "skge_tx_timeout"],
["drivers/net/ethernet/marvell/sky2.c", "sky2_tx_timeout"],
["drivers/net/ethernet/marvell/sky2.c", "sky2_tx_timeout"],
["drivers/net/ethernet/mediatek/mtk_eth_soc.c", "mtk_tx_timeout"],
["drivers/net/ethernet/mellanox/mlx4/en_netdev.c", "mlx4_en_tx_timeout"],
["drivers/net/ethernet/mellanox/mlx4/en_netdev.c", "mlx4_en_tx_timeout"],
["drivers/net/ethernet/mellanox/mlx5/core/en_main.c", "mlx5e_tx_timeout"],
["drivers/net/ethernet/micrel/ks8842.c", "ks8842_tx_timeout"],
["drivers/net/ethernet/micrel/ksz884x.c", "netdev_tx_timeout"],
["drivers/net/ethernet/microchip/enc28j60.c", "enc28j60_tx_timeout"],
["drivers/net/ethernet/microchip/encx24j600.c", "encx24j600_tx_timeout"],
["drivers/net/ethernet/natsemi/sonic.h", "sonic_tx_timeout"],
["drivers/net/ethernet/natsemi/sonic.c", "sonic_tx_timeout"],
["drivers/net/ethernet/natsemi/jazzsonic.c", "sonic_tx_timeout"],
["drivers/net/ethernet/natsemi/macsonic.c", "sonic_tx_timeout"],
["drivers/net/ethernet/natsemi/natsemi.c", "ns_tx_timeout"],
["drivers/net/ethernet/natsemi/ns83820.c", "ns83820_tx_timeout"],
["drivers/net/ethernet/natsemi/xtsonic.c", "sonic_tx_timeout"],
["drivers/net/ethernet/neterion/s2io.h", "s2io_tx_watchdog"],
["drivers/net/ethernet/neterion/s2io.c", "s2io_tx_watchdog"],
["drivers/net/ethernet/neterion/vxge/vxge-main.c", "vxge_tx_watchdog"],
["drivers/net/ethernet/netronome/nfp/nfp_net_common.c", "nfp_net_tx_timeout"],
["drivers/net/ethernet/nvidia/forcedeth.c", "nv_tx_timeout"],
["drivers/net/ethernet/nvidia/forcedeth.c", "nv_tx_timeout"],
["drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c", "pch_gbe_tx_timeout"],
["drivers/net/ethernet/packetengines/hamachi.c", "hamachi_tx_timeout"],
["drivers/net/ethernet/packetengines/yellowfin.c", "yellowfin_tx_timeout"],
["drivers/net/ethernet/pensando/ionic/ionic_lif.c", "ionic_tx_timeout"],
["drivers/net/ethernet/qlogic/netxen/netxen_nic_main.c", "netxen_tx_timeout"],
["drivers/net/ethernet/qlogic/qla3xxx.c", "ql3xxx_tx_timeout"],
["drivers/net/ethernet/qlogic/qlcnic/qlcnic_main.c", "qlcnic_tx_timeout"],
["drivers/net/ethernet/qualcomm/emac/emac.c", "emac_tx_timeout"],
["drivers/net/ethernet/qualcomm/qca_spi.c", "qcaspi_netdev_tx_timeout"],
["drivers/net/ethernet/qualcomm/qca_uart.c", "qcauart_netdev_tx_timeout"],
["drivers/net/ethernet/rdc/r6040.c", "r6040_tx_timeout"],
["drivers/net/ethernet/realtek/8139cp.c", "cp_tx_timeout"],
["drivers/net/ethernet/realtek/8139too.c", "rtl8139_tx_timeout"],
["drivers/net/ethernet/realtek/atp.c", "tx_timeout"],
["drivers/net/ethernet/realtek/r8169_main.c", "rtl8169_tx_timeout"],
["drivers/net/ethernet/renesas/ravb_main.c", "ravb_tx_timeout"],
["drivers/net/ethernet/renesas/sh_eth.c", "sh_eth_tx_timeout"],
["drivers/net/ethernet/renesas/sh_eth.c", "sh_eth_tx_timeout"],
["drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c", "sxgbe_tx_timeout"],
["drivers/net/ethernet/seeq/ether3.c", "ether3_timeout"],
["drivers/net/ethernet/seeq/sgiseeq.c", "timeout"],
["drivers/net/ethernet/sfc/efx.c", "efx_watchdog"],
["drivers/net/ethernet/sfc/falcon/efx.c", "ef4_watchdog"],
["drivers/net/ethernet/sgi/ioc3-eth.c", "ioc3_timeout"],
["drivers/net/ethernet/sgi/meth.c", "meth_tx_timeout"],
["drivers/net/ethernet/silan/sc92031.c", "sc92031_tx_timeout"],
["drivers/net/ethernet/sis/sis190.c", "sis190_tx_timeout"],
["drivers/net/ethernet/sis/sis900.c", "sis900_tx_timeout"],
["drivers/net/ethernet/smsc/epic100.c", "epic_tx_timeout"],
["drivers/net/ethernet/smsc/smc911x.c", "smc911x_timeout"],
["drivers/net/ethernet/smsc/smc9194.c", "smc_timeout"],
["drivers/net/ethernet/smsc/smc91c92_cs.c", "smc_tx_timeout"],
["drivers/net/ethernet/smsc/smc91x.c", "smc_timeout"],
["drivers/net/ethernet/stmicro/stmmac/stmmac_main.c", "stmmac_tx_timeout"],
["drivers/net/ethernet/sun/cassini.c", "cas_tx_timeout"],
["drivers/net/ethernet/sun/ldmvsw.c", "sunvnet_tx_timeout_common"],
["drivers/net/ethernet/sun/niu.c", "niu_tx_timeout"],
["drivers/net/ethernet/sun/sunbmac.c", "bigmac_tx_timeout"],
["drivers/net/ethernet/sun/sungem.c", "gem_tx_timeout"],
["drivers/net/ethernet/sun/sunhme.c", "happy_meal_tx_timeout"],
["drivers/net/ethernet/sun/sunqe.c", "qe_tx_timeout"],
["drivers/net/ethernet/sun/sunvnet.c", "sunvnet_tx_timeout_common"],
["drivers/net/ethernet/sun/sunvnet_common.c", "sunvnet_tx_timeout_common"],
["drivers/net/ethernet/sun/sunvnet_common.h", "sunvnet_tx_timeout_common"],
["drivers/net/ethernet/synopsys/dwc-xlgmac-net.c", "xlgmac_tx_timeout"],
["drivers/net/ethernet/ti/cpmac.c", "cpmac_tx_timeout"],
["drivers/net/ethernet/ti/cpsw.c", "cpsw_ndo_tx_timeout"],
["drivers/net/ethernet/ti/cpsw_priv.c", "cpsw_ndo_tx_timeout"],
["drivers/net/ethernet/ti/cpsw_priv.h", "cpsw_ndo_tx_timeout"],
["drivers/net/ethernet/ti/davinci_emac.c", "emac_dev_tx_timeout"],
["drivers/net/ethernet/ti/netcp_core.c", "netcp_ndo_tx_timeout"],
["drivers/net/ethernet/ti/tlan.c", "tlan_tx_timeout"],
["drivers/net/ethernet/toshiba/ps3_gelic_net.h", "gelic_net_tx_timeout"],
["drivers/net/ethernet/toshiba/ps3_gelic_net.c", "gelic_net_tx_timeout"],
["drivers/net/ethernet/toshiba/ps3_gelic_wireless.c", "gelic_net_tx_timeout"],
["drivers/net/ethernet/toshiba/spider_net.c", "spider_net_tx_timeout"],
["drivers/net/ethernet/toshiba/tc35815.c", "tc35815_tx_timeout"],
["drivers/net/ethernet/via/via-rhine.c", "rhine_tx_timeout"],
["drivers/net/ethernet/wiznet/w5100.c", "w5100_tx_timeout"],
["drivers/net/ethernet/wiznet/w5300.c", "w5300_tx_timeout"],
["drivers/net/ethernet/xilinx/xilinx_emaclite.c", "xemaclite_tx_timeout"],
["drivers/net/ethernet/xircom/xirc2ps_cs.c", "xirc_tx_timeout"],
["drivers/net/fjes/fjes_main.c", "fjes_tx_retry"],
["drivers/net/slip/slip.c", "sl_tx_timeout"],
["include/linux/usb/usbnet.h", "usbnet_tx_timeout"],
["drivers/net/usb/aqc111.c", "usbnet_tx_timeout"],
["drivers/net/usb/asix_devices.c", "usbnet_tx_timeout"],
["drivers/net/usb/asix_devices.c", "usbnet_tx_timeout"],
["drivers/net/usb/asix_devices.c", "usbnet_tx_timeout"],
["drivers/net/usb/ax88172a.c", "usbnet_tx_timeout"],
["drivers/net/usb/ax88179_178a.c", "usbnet_tx_timeout"],
["drivers/net/usb/catc.c", "catc_tx_timeout"],
["drivers/net/usb/cdc_mbim.c", "usbnet_tx_timeout"],
["drivers/net/usb/cdc_ncm.c", "usbnet_tx_timeout"],
["drivers/net/usb/dm9601.c", "usbnet_tx_timeout"],
["drivers/net/usb/hso.c", "hso_net_tx_timeout"],
["drivers/net/usb/int51x1.c", "usbnet_tx_timeout"],
["drivers/net/usb/ipheth.c", "ipheth_tx_timeout"],
["drivers/net/usb/kaweth.c", "kaweth_tx_timeout"],
["drivers/net/usb/lan78xx.c", "lan78xx_tx_timeout"],
["drivers/net/usb/mcs7830.c", "usbnet_tx_timeout"],
["drivers/net/usb/pegasus.c", "pegasus_tx_timeout"],
["drivers/net/usb/qmi_wwan.c", "usbnet_tx_timeout"],
["drivers/net/usb/r8152.c", "rtl8152_tx_timeout"],
["drivers/net/usb/rndis_host.c", "usbnet_tx_timeout"],
["drivers/net/usb/rtl8150.c", "rtl8150_tx_timeout"],
["drivers/net/usb/sierra_net.c", "usbnet_tx_timeout"],
["drivers/net/usb/smsc75xx.c", "usbnet_tx_timeout"],
["drivers/net/usb/smsc95xx.c", "usbnet_tx_timeout"],
["drivers/net/usb/sr9700.c", "usbnet_tx_timeout"],
["drivers/net/usb/sr9800.c", "usbnet_tx_timeout"],
["drivers/net/usb/usbnet.c", "usbnet_tx_timeout"],
["drivers/net/vmxnet3/vmxnet3_drv.c", "vmxnet3_tx_timeout"],
["drivers/net/wan/cosa.c", "cosa_net_timeout"],
["drivers/net/wan/farsync.c", "fst_tx_timeout"],
["drivers/net/wan/fsl_ucc_hdlc.c", "uhdlc_tx_timeout"],
["drivers/net/wan/lmc/lmc_main.c", "lmc_driver_timeout"],
["drivers/net/wan/x25_asy.c", "x25_asy_timeout"],
["drivers/net/wimax/i2400m/netdev.c", "i2400m_tx_timeout"],
["drivers/net/wireless/intel/ipw2x00/ipw2100.c", "ipw2100_tx_timeout"],
["drivers/net/wireless/intersil/hostap/hostap_main.c", "prism2_tx_timeout"],
["drivers/net/wireless/intersil/hostap/hostap_main.c", "prism2_tx_timeout"],
["drivers/net/wireless/intersil/hostap/hostap_main.c", "prism2_tx_timeout"],
["drivers/net/wireless/intersil/orinoco/main.c", "orinoco_tx_timeout"],
["drivers/net/wireless/intersil/orinoco/orinoco_usb.c", "orinoco_tx_timeout"],
["drivers/net/wireless/intersil/orinoco/orinoco.h", "orinoco_tx_timeout"],
["drivers/net/wireless/intersil/prism54/islpci_dev.c", "islpci_eth_tx_timeout"],
["drivers/net/wireless/intersil/prism54/islpci_eth.c", "islpci_eth_tx_timeout"],
["drivers/net/wireless/intersil/prism54/islpci_eth.h", "islpci_eth_tx_timeout"],
["drivers/net/wireless/marvell/mwifiex/main.c", "mwifiex_tx_timeout"],
["drivers/net/wireless/quantenna/qtnfmac/core.c", "qtnf_netdev_tx_timeout"],
["drivers/net/wireless/quantenna/qtnfmac/core.h", "qtnf_netdev_tx_timeout"],
["drivers/net/wireless/rndis_wlan.c", "usbnet_tx_timeout"],
["drivers/net/wireless/wl3501_cs.c", "wl3501_tx_timeout"],
["drivers/net/wireless/zydas/zd1201.c", "zd1201_tx_timeout"],
["drivers/s390/net/qeth_core.h", "qeth_tx_timeout"],
["drivers/s390/net/qeth_core_main.c", "qeth_tx_timeout"],
["drivers/s390/net/qeth_l2_main.c", "qeth_tx_timeout"],
["drivers/s390/net/qeth_l2_main.c", "qeth_tx_timeout"],
["drivers/s390/net/qeth_l3_main.c", "qeth_tx_timeout"],
["drivers/s390/net/qeth_l3_main.c", "qeth_tx_timeout"],
["drivers/staging/ks7010/ks_wlan_net.c", "ks_wlan_tx_timeout"],
["drivers/staging/qlge/qlge_main.c", "qlge_tx_timeout"],
["drivers/staging/rtl8192e/rtl8192e/rtl_core.c", "_rtl92e_tx_timeout"],
["drivers/staging/rtl8192u/r8192U_core.c", "tx_timeout"],
["drivers/staging/unisys/visornic/visornic_main.c", "visornic_xmit_timeout"],
["drivers/staging/wlan-ng/p80211netdev.c", "p80211knetdev_tx_timeout"],
["drivers/tty/n_gsm.c", "gsm_mux_net_tx_timeout"],
["drivers/tty/synclink.c", "hdlcdev_tx_timeout"],
["drivers/tty/synclink_gt.c", "hdlcdev_tx_timeout"],
["drivers/tty/synclinkmp.c", "hdlcdev_tx_timeout"],
["net/atm/lec.c", "lec_tx_timeout"],
["net/bluetooth/bnep/netdev.c", "bnep_net_timeout"]
);
for my $p (@work) {
my @pair = @$p;
my $file = $pair[0];
my $func = $pair[1];
print STDERR $file , ": ", $func,"\n";
our @ARGV = ($file);
while (<ARGV>) {
if (m/($func\s*\(struct\s+net_device\s+\*[A-Za-z_]?[A-Za-z-0-9_]*)(\))/) {
print STDERR "found $1+$2 in $file\n";
}
if (s/($func\s*\(struct\s+net_device\s+\*[A-Za-z_]?[A-Za-z-0-9_]*)(\))/$1, unsigned int txqueue$2/) {
print STDERR "$func found in $file\n";
}
print;
}
}
where the list of files and functions is simply from:
git grep ndo_tx_timeout, with manual addition of headers
in the rare cases where the function is from a header,
then manually changing the few places which actually
call ndo_tx_timeout.
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Acked-by: Heiner Kallweit <hkallweit1@gmail.com>
Acked-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Acked-by: Shannon Nelson <snelson@pensando.io>
Reviewed-by: Martin Habets <mhabets@solarflare.com>
changes from v9:
fixup a forward declaration
changes from v9:
more leftovers from v3 change
changes from v8:
fix up a missing direct call to timeout
rebased on net-next
changes from v7:
fixup leftovers from v3 change
changes from v6:
fix typo in rtl driver
changes from v5:
add missing files (allow any net device argument name)
changes from v4:
add a missing driver header
changes from v3:
change queue # to unsigned
Changes from v2:
added headers
Changes from v1:
Fix errors found by kbuild:
generalize the pattern a bit, to pick up
a couple of instances missed by the previous
version.
Signed-off-by: David S. Miller <davem@davemloft.net>
2019-12-10 22:23:51 +08:00
|
|
|
static void gfar_timeout(struct net_device *dev, unsigned int txqueue)
|
2008-08-20 03:12:45 +08:00
|
|
|
{
|
|
|
|
struct gfar_private *priv = netdev_priv(dev);
|
|
|
|
|
|
|
|
dev->stats.tx_errors++;
|
|
|
|
schedule_work(&priv->reset_task);
|
|
|
|
}
|
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
static int gfar_hwtstamp_set(struct net_device *netdev, struct ifreq *ifr)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2019-09-04 21:52:19 +08:00
|
|
|
struct hwtstamp_config config;
|
|
|
|
struct gfar_private *priv = netdev_priv(netdev);
|
|
|
|
|
|
|
|
if (copy_from_user(&config, ifr->ifr_data, sizeof(config)))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
switch (config.tx_type) {
|
|
|
|
case HWTSTAMP_TX_OFF:
|
|
|
|
priv->hwts_tx_en = 0;
|
|
|
|
break;
|
|
|
|
case HWTSTAMP_TX_ON:
|
|
|
|
if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_TIMER))
|
|
|
|
return -ERANGE;
|
|
|
|
priv->hwts_tx_en = 1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -ERANGE;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (config.rx_filter) {
|
|
|
|
case HWTSTAMP_FILTER_NONE:
|
|
|
|
if (priv->hwts_rx_en) {
|
|
|
|
priv->hwts_rx_en = 0;
|
|
|
|
reset_gfar(netdev);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_TIMER))
|
|
|
|
return -ERANGE;
|
|
|
|
if (!priv->hwts_rx_en) {
|
|
|
|
priv->hwts_rx_en = 1;
|
|
|
|
reset_gfar(netdev);
|
|
|
|
}
|
|
|
|
config.rx_filter = HWTSTAMP_FILTER_ALL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return copy_to_user(ifr->ifr_data, &config, sizeof(config)) ?
|
|
|
|
-EFAULT : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int gfar_hwtstamp_get(struct net_device *netdev, struct ifreq *ifr)
|
|
|
|
{
|
|
|
|
struct hwtstamp_config config;
|
|
|
|
struct gfar_private *priv = netdev_priv(netdev);
|
|
|
|
|
|
|
|
config.flags = 0;
|
|
|
|
config.tx_type = priv->hwts_tx_en ? HWTSTAMP_TX_ON : HWTSTAMP_TX_OFF;
|
|
|
|
config.rx_filter = (priv->hwts_rx_en ?
|
|
|
|
HWTSTAMP_FILTER_ALL : HWTSTAMP_FILTER_NONE);
|
|
|
|
|
|
|
|
return copy_to_user(ifr->ifr_data, &config, sizeof(config)) ?
|
|
|
|
-EFAULT : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int gfar_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
|
|
|
|
{
|
|
|
|
struct phy_device *phydev = dev->phydev;
|
|
|
|
|
|
|
|
if (!netif_running(dev))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (cmd == SIOCSHWTSTAMP)
|
|
|
|
return gfar_hwtstamp_set(dev, rq);
|
|
|
|
if (cmd == SIOCGHWTSTAMP)
|
|
|
|
return gfar_hwtstamp_get(dev, rq);
|
|
|
|
|
|
|
|
if (!phydev)
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
return phy_mii_ioctl(phydev, rq, cmd);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Interrupt Handler for Transmit complete */
|
|
|
|
static void gfar_clean_tx_ring(struct gfar_priv_tx_q *tx_queue)
|
|
|
|
{
|
|
|
|
struct net_device *dev = tx_queue->dev;
|
|
|
|
struct netdev_queue *txq;
|
|
|
|
struct gfar_private *priv = netdev_priv(dev);
|
|
|
|
struct txbd8 *bdp, *next = NULL;
|
|
|
|
struct txbd8 *lbdp = NULL;
|
|
|
|
struct txbd8 *base = tx_queue->tx_bd_base;
|
|
|
|
struct sk_buff *skb;
|
|
|
|
int skb_dirtytx;
|
|
|
|
int tx_ring_size = tx_queue->tx_ring_size;
|
|
|
|
int frags = 0, nr_txbds = 0;
|
2008-12-18 08:51:04 +08:00
|
|
|
int i;
|
2008-04-10 08:37:51 +08:00
|
|
|
int howmany = 0;
|
2012-01-07 02:51:03 +08:00
|
|
|
int tqi = tx_queue->qindex;
|
|
|
|
unsigned int bytes_sent = 0;
|
2008-12-18 08:51:04 +08:00
|
|
|
u32 lstatus;
|
2010-04-09 07:10:35 +08:00
|
|
|
size_t buflen;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-01-07 02:51:03 +08:00
|
|
|
txq = netdev_get_tx_queue(dev, tqi);
|
2009-11-02 15:03:00 +08:00
|
|
|
bdp = tx_queue->dirty_tx;
|
|
|
|
skb_dirtytx = tx_queue->skb_dirtytx;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-11-02 15:03:00 +08:00
|
|
|
while ((skb = tx_queue->tx_skbuff[skb_dirtytx])) {
|
gianfar: Fix TX timestamping with a stacked DSA driver
The driver wrongly assumes that it is the only entity that can set the
SKBTX_IN_PROGRESS bit of the current skb. Therefore, in the
gfar_clean_tx_ring function, where the TX timestamp is collected if
necessary, the aforementioned bit is used to discriminate whether or not
the TX timestamp should be delivered to the socket's error queue.
But a stacked driver such as a DSA switch can also set the
SKBTX_IN_PROGRESS bit, which is actually exactly what it should do in
order to denote that the hardware timestamping process is undergoing.
Therefore, gianfar would misinterpret the "in progress" bit as being its
own, and deliver a second skb clone in the socket's error queue,
completely throwing off a PTP process which is not expecting to receive
it, _even though_ TX timestamping is not enabled for gianfar.
There have been discussions [0] as to whether non-MAC drivers need or
not to set SKBTX_IN_PROGRESS at all (whose purpose is to avoid sending 2
timestamps, a sw and a hw one, to applications which only expect one).
But as of this patch, there are at least 2 PTP drivers that would break
in conjunction with gianfar: the sja1105 DSA switch and the felix
switch, by way of its ocelot core driver.
So regardless of that conclusion, fix the gianfar driver to not do stuff
based on flags set by others and not intended for it.
[0]: https://www.spinics.net/lists/netdev/msg619699.html
Fixes: f0ee7acfcdd4 ("gianfar: Add hardware TX timestamping support")
Signed-off-by: Vladimir Oltean <olteanv@gmail.com>
Acked-by: Richard Cochran <richardcochran@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2019-12-28 21:30:45 +08:00
|
|
|
bool do_tstamp;
|
|
|
|
|
|
|
|
do_tstamp = (skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) &&
|
|
|
|
priv->hwts_tx_en;
|
2009-11-10 22:11:10 +08:00
|
|
|
|
2008-12-18 08:51:04 +08:00
|
|
|
frags = skb_shinfo(skb)->nr_frags;
|
2010-04-09 07:10:35 +08:00
|
|
|
|
2012-06-05 11:42:12 +08:00
|
|
|
/* When time stamping, one additional TxBD must be freed.
|
2010-04-09 07:10:35 +08:00
|
|
|
* Also, we need to dma_unmap_single() the TxPAL.
|
|
|
|
*/
|
gianfar: Fix TX timestamping with a stacked DSA driver
The driver wrongly assumes that it is the only entity that can set the
SKBTX_IN_PROGRESS bit of the current skb. Therefore, in the
gfar_clean_tx_ring function, where the TX timestamp is collected if
necessary, the aforementioned bit is used to discriminate whether or not
the TX timestamp should be delivered to the socket's error queue.
But a stacked driver such as a DSA switch can also set the
SKBTX_IN_PROGRESS bit, which is actually exactly what it should do in
order to denote that the hardware timestamping process is undergoing.
Therefore, gianfar would misinterpret the "in progress" bit as being its
own, and deliver a second skb clone in the socket's error queue,
completely throwing off a PTP process which is not expecting to receive
it, _even though_ TX timestamping is not enabled for gianfar.
There have been discussions [0] as to whether non-MAC drivers need or
not to set SKBTX_IN_PROGRESS at all (whose purpose is to avoid sending 2
timestamps, a sw and a hw one, to applications which only expect one).
But as of this patch, there are at least 2 PTP drivers that would break
in conjunction with gianfar: the sja1105 DSA switch and the felix
switch, by way of its ocelot core driver.
So regardless of that conclusion, fix the gianfar driver to not do stuff
based on flags set by others and not intended for it.
[0]: https://www.spinics.net/lists/netdev/msg619699.html
Fixes: f0ee7acfcdd4 ("gianfar: Add hardware TX timestamping support")
Signed-off-by: Vladimir Oltean <olteanv@gmail.com>
Acked-by: Richard Cochran <richardcochran@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2019-12-28 21:30:45 +08:00
|
|
|
if (unlikely(do_tstamp))
|
2010-04-09 07:10:35 +08:00
|
|
|
nr_txbds = frags + 2;
|
|
|
|
else
|
|
|
|
nr_txbds = frags + 1;
|
|
|
|
|
|
|
|
lbdp = skip_txbd(bdp, nr_txbds - 1, base, tx_ring_size);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2015-03-13 16:36:28 +08:00
|
|
|
lstatus = be32_to_cpu(lbdp->lstatus);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-12-18 08:51:04 +08:00
|
|
|
/* Only clean completed frames */
|
|
|
|
if ((lstatus & BD_LFLAG(TXBD_READY)) &&
|
2012-06-05 11:42:13 +08:00
|
|
|
(lstatus & BD_LENGTH_MASK))
|
2008-12-18 08:51:04 +08:00
|
|
|
break;
|
|
|
|
|
gianfar: Fix TX timestamping with a stacked DSA driver
The driver wrongly assumes that it is the only entity that can set the
SKBTX_IN_PROGRESS bit of the current skb. Therefore, in the
gfar_clean_tx_ring function, where the TX timestamp is collected if
necessary, the aforementioned bit is used to discriminate whether or not
the TX timestamp should be delivered to the socket's error queue.
But a stacked driver such as a DSA switch can also set the
SKBTX_IN_PROGRESS bit, which is actually exactly what it should do in
order to denote that the hardware timestamping process is undergoing.
Therefore, gianfar would misinterpret the "in progress" bit as being its
own, and deliver a second skb clone in the socket's error queue,
completely throwing off a PTP process which is not expecting to receive
it, _even though_ TX timestamping is not enabled for gianfar.
There have been discussions [0] as to whether non-MAC drivers need or
not to set SKBTX_IN_PROGRESS at all (whose purpose is to avoid sending 2
timestamps, a sw and a hw one, to applications which only expect one).
But as of this patch, there are at least 2 PTP drivers that would break
in conjunction with gianfar: the sja1105 DSA switch and the felix
switch, by way of its ocelot core driver.
So regardless of that conclusion, fix the gianfar driver to not do stuff
based on flags set by others and not intended for it.
[0]: https://www.spinics.net/lists/netdev/msg619699.html
Fixes: f0ee7acfcdd4 ("gianfar: Add hardware TX timestamping support")
Signed-off-by: Vladimir Oltean <olteanv@gmail.com>
Acked-by: Richard Cochran <richardcochran@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2019-12-28 21:30:45 +08:00
|
|
|
if (unlikely(do_tstamp)) {
|
2010-04-09 07:10:35 +08:00
|
|
|
next = next_txbd(bdp, base, tx_ring_size);
|
2015-03-13 16:36:28 +08:00
|
|
|
buflen = be16_to_cpu(next->length) +
|
|
|
|
GMAC_FCB_LEN + GMAC_TXPAL_LEN;
|
2010-04-09 07:10:35 +08:00
|
|
|
} else
|
2015-03-13 16:36:28 +08:00
|
|
|
buflen = be16_to_cpu(bdp->length);
|
2010-04-09 07:10:35 +08:00
|
|
|
|
2015-03-13 16:36:28 +08:00
|
|
|
dma_unmap_single(priv->dev, be32_to_cpu(bdp->bufPtr),
|
2012-06-05 11:42:13 +08:00
|
|
|
buflen, DMA_TO_DEVICE);
|
2010-04-09 07:10:35 +08:00
|
|
|
|
gianfar: Fix TX timestamping with a stacked DSA driver
The driver wrongly assumes that it is the only entity that can set the
SKBTX_IN_PROGRESS bit of the current skb. Therefore, in the
gfar_clean_tx_ring function, where the TX timestamp is collected if
necessary, the aforementioned bit is used to discriminate whether or not
the TX timestamp should be delivered to the socket's error queue.
But a stacked driver such as a DSA switch can also set the
SKBTX_IN_PROGRESS bit, which is actually exactly what it should do in
order to denote that the hardware timestamping process is undergoing.
Therefore, gianfar would misinterpret the "in progress" bit as being its
own, and deliver a second skb clone in the socket's error queue,
completely throwing off a PTP process which is not expecting to receive
it, _even though_ TX timestamping is not enabled for gianfar.
There have been discussions [0] as to whether non-MAC drivers need or
not to set SKBTX_IN_PROGRESS at all (whose purpose is to avoid sending 2
timestamps, a sw and a hw one, to applications which only expect one).
But as of this patch, there are at least 2 PTP drivers that would break
in conjunction with gianfar: the sja1105 DSA switch and the felix
switch, by way of its ocelot core driver.
So regardless of that conclusion, fix the gianfar driver to not do stuff
based on flags set by others and not intended for it.
[0]: https://www.spinics.net/lists/netdev/msg619699.html
Fixes: f0ee7acfcdd4 ("gianfar: Add hardware TX timestamping support")
Signed-off-by: Vladimir Oltean <olteanv@gmail.com>
Acked-by: Richard Cochran <richardcochran@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2019-12-28 21:30:45 +08:00
|
|
|
if (unlikely(do_tstamp)) {
|
2010-04-09 07:10:35 +08:00
|
|
|
struct skb_shared_hwtstamps shhwtstamps;
|
2015-07-29 21:13:06 +08:00
|
|
|
u64 *ns = (u64 *)(((uintptr_t)skb->data + 0x10) &
|
|
|
|
~0x7UL);
|
2012-06-05 11:42:13 +08:00
|
|
|
|
2010-04-09 07:10:35 +08:00
|
|
|
memset(&shhwtstamps, 0, sizeof(shhwtstamps));
|
2016-02-24 17:26:56 +08:00
|
|
|
shhwtstamps.hwtstamp = ns_to_ktime(be64_to_cpu(*ns));
|
2012-01-10 07:26:51 +08:00
|
|
|
skb_pull(skb, GMAC_FCB_LEN + GMAC_TXPAL_LEN);
|
2010-04-09 07:10:35 +08:00
|
|
|
skb_tstamp_tx(skb, &shhwtstamps);
|
2015-03-13 16:36:28 +08:00
|
|
|
gfar_clear_txbd_status(bdp);
|
2010-04-09 07:10:35 +08:00
|
|
|
bdp = next;
|
|
|
|
}
|
2008-11-13 00:07:11 +08:00
|
|
|
|
2015-03-13 16:36:28 +08:00
|
|
|
gfar_clear_txbd_status(bdp);
|
2008-12-18 08:51:04 +08:00
|
|
|
bdp = next_txbd(bdp, base, tx_ring_size);
|
2008-04-10 08:37:51 +08:00
|
|
|
|
2008-12-18 08:51:04 +08:00
|
|
|
for (i = 0; i < frags; i++) {
|
2015-03-13 16:36:28 +08:00
|
|
|
dma_unmap_page(priv->dev, be32_to_cpu(bdp->bufPtr),
|
|
|
|
be16_to_cpu(bdp->length),
|
|
|
|
DMA_TO_DEVICE);
|
|
|
|
gfar_clear_txbd_status(bdp);
|
2008-12-18 08:51:04 +08:00
|
|
|
bdp = next_txbd(bdp, base, tx_ring_size);
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2013-08-30 20:01:15 +08:00
|
|
|
bytes_sent += GFAR_CB(skb)->bytes_sent;
|
2012-01-07 02:51:03 +08:00
|
|
|
|
2012-10-05 14:23:55 +08:00
|
|
|
dev_kfree_skb_any(skb);
|
2009-02-05 08:43:16 +08:00
|
|
|
|
2009-11-02 15:03:00 +08:00
|
|
|
tx_queue->tx_skbuff[skb_dirtytx] = NULL;
|
2008-04-10 08:37:51 +08:00
|
|
|
|
2008-12-18 08:51:04 +08:00
|
|
|
skb_dirtytx = (skb_dirtytx + 1) &
|
2012-06-05 11:42:13 +08:00
|
|
|
TX_RING_MOD_MASK(tx_ring_size);
|
2008-12-18 08:51:04 +08:00
|
|
|
|
|
|
|
howmany++;
|
2015-05-06 23:07:29 +08:00
|
|
|
spin_lock(&tx_queue->txlock);
|
2010-04-09 07:10:35 +08:00
|
|
|
tx_queue->num_txbdfree += nr_txbds;
|
2015-05-06 23:07:29 +08:00
|
|
|
spin_unlock(&tx_queue->txlock);
|
2008-12-18 08:51:04 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-12-18 08:51:04 +08:00
|
|
|
/* If we freed a buffer, we can restart transmission, if necessary */
|
gianfar: Fix device reset races (oops) for Tx
The device reset procedure, stop_gfar()/startup_gfar(), has
concurrency issues.
"Kernel access of bad area" oopses show up during Tx timeout
device reset or other reset cases (like changing MTU) that
happen while the interface still has traffic. The oopses
happen in start_xmit and clean_tx_ring when accessing tx_queue->
tx_skbuff which is NULL. The race comes from de-allocating the
tx_skbuff while transmission and napi processing are still
active. Though the Tx queues get temoprarily stopped when Tx
timeout occurs, they get re-enabled as a result of Tx congestion
handling inside the napi context (see clean_tx_ring()). Not
disabling the napi during reset is also a bug, because
clean_tx_ring() will try to access tx_skbuff while it is being
de-alloc'ed and re-alloc'ed.
To fix this, stop_gfar() needs to disable napi processing
after stopping the Tx queues. However, in order to prevent
clean_tx_ring() to re-enable the Tx queue before the napi
gets disabled, the device state DOWN has been introduced.
It prevents the Tx congestion management from re-enabling the
de-congested Tx queue while the device is brought down.
An additional locking state, RESETTING, has been introduced
to prevent simultaneous resets or to prevent configuring the
device while it is resetting.
The bogus 'rxlock's (for each Rx queue) have been removed since
their purpose is not justified, as they don't prevent nor are
suited to prevent device reset/reconfig races (such as this one).
Signed-off-by: Claudiu Manoil <claudiu.manoil@freescale.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-02-24 18:13:45 +08:00
|
|
|
if (tx_queue->num_txbdfree &&
|
|
|
|
netif_tx_queue_stopped(txq) &&
|
|
|
|
!(test_bit(GFAR_DOWN, &priv->state)))
|
|
|
|
netif_wake_subqueue(priv->ndev, tqi);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-12-18 08:51:04 +08:00
|
|
|
/* Update dirty indicators */
|
2009-11-02 15:03:00 +08:00
|
|
|
tx_queue->skb_dirtytx = skb_dirtytx;
|
|
|
|
tx_queue->dirty_tx = bdp;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-01-07 02:51:03 +08:00
|
|
|
netdev_tx_completed_queue(txq, howmany, bytes_sent);
|
2008-04-10 08:37:51 +08:00
|
|
|
}
|
|
|
|
|
2015-07-13 21:22:05 +08:00
|
|
|
static void count_errors(u32 lstatus, struct net_device *ndev)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2015-07-13 21:22:05 +08:00
|
|
|
struct gfar_private *priv = netdev_priv(ndev);
|
|
|
|
struct net_device_stats *stats = &ndev->stats;
|
2005-04-17 06:20:36 +08:00
|
|
|
struct gfar_extra_stats *estats = &priv->extra_stats;
|
|
|
|
|
2012-06-05 11:42:12 +08:00
|
|
|
/* If the packet was truncated, none of the other errors matter */
|
2015-07-13 21:22:04 +08:00
|
|
|
if (lstatus & BD_LFLAG(RXBD_TRUNCATED)) {
|
2005-04-17 06:20:36 +08:00
|
|
|
stats->rx_length_errors++;
|
|
|
|
|
2013-02-13 04:38:19 +08:00
|
|
|
atomic64_inc(&estats->rx_trunc);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* Count the errors, if there were any */
|
2015-07-13 21:22:04 +08:00
|
|
|
if (lstatus & BD_LFLAG(RXBD_LARGE | RXBD_SHORT)) {
|
2005-04-17 06:20:36 +08:00
|
|
|
stats->rx_length_errors++;
|
|
|
|
|
2015-07-13 21:22:04 +08:00
|
|
|
if (lstatus & BD_LFLAG(RXBD_LARGE))
|
2013-02-13 04:38:19 +08:00
|
|
|
atomic64_inc(&estats->rx_large);
|
2005-04-17 06:20:36 +08:00
|
|
|
else
|
2013-02-13 04:38:19 +08:00
|
|
|
atomic64_inc(&estats->rx_short);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2015-07-13 21:22:04 +08:00
|
|
|
if (lstatus & BD_LFLAG(RXBD_NONOCTET)) {
|
2005-04-17 06:20:36 +08:00
|
|
|
stats->rx_frame_errors++;
|
2013-02-13 04:38:19 +08:00
|
|
|
atomic64_inc(&estats->rx_nonoctet);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2015-07-13 21:22:04 +08:00
|
|
|
if (lstatus & BD_LFLAG(RXBD_CRCERR)) {
|
2013-02-13 04:38:19 +08:00
|
|
|
atomic64_inc(&estats->rx_crcerr);
|
2005-04-17 06:20:36 +08:00
|
|
|
stats->rx_crc_errors++;
|
|
|
|
}
|
2015-07-13 21:22:04 +08:00
|
|
|
if (lstatus & BD_LFLAG(RXBD_OVERRUN)) {
|
2013-02-13 04:38:19 +08:00
|
|
|
atomic64_inc(&estats->rx_overrun);
|
2015-07-13 21:22:04 +08:00
|
|
|
stats->rx_over_errors++;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-04 21:52:20 +08:00
|
|
|
static irqreturn_t gfar_receive(int irq, void *grp_id)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2014-03-07 20:42:45 +08:00
|
|
|
struct gfar_priv_grp *grp = (struct gfar_priv_grp *)grp_id;
|
|
|
|
unsigned long flags;
|
2015-10-05 22:19:59 +08:00
|
|
|
u32 imask, ievent;
|
|
|
|
|
|
|
|
ievent = gfar_read(&grp->regs->ievent);
|
|
|
|
|
|
|
|
if (unlikely(ievent & IEVENT_FGPI)) {
|
|
|
|
gfar_write(&grp->regs->ievent, IEVENT_FGPI);
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
2014-03-07 20:42:45 +08:00
|
|
|
|
|
|
|
if (likely(napi_schedule_prep(&grp->napi_rx))) {
|
|
|
|
spin_lock_irqsave(&grp->grplock, flags);
|
|
|
|
imask = gfar_read(&grp->regs->imask);
|
2021-06-17 17:49:28 +08:00
|
|
|
imask &= IMASK_RX_DISABLED | grp->priv->rmon_overflow.imask;
|
2014-03-07 20:42:45 +08:00
|
|
|
gfar_write(&grp->regs->imask, imask);
|
|
|
|
spin_unlock_irqrestore(&grp->grplock, flags);
|
|
|
|
__napi_schedule(&grp->napi_rx);
|
|
|
|
} else {
|
|
|
|
/* Clear IEVENT, so interrupts aren't called again
|
|
|
|
* because of the packets that have already arrived.
|
|
|
|
*/
|
|
|
|
gfar_write(&grp->regs->ievent, IEVENT_RX_MASK);
|
|
|
|
}
|
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Interrupt Handler for Transmit complete */
|
|
|
|
static irqreturn_t gfar_transmit(int irq, void *grp_id)
|
|
|
|
{
|
|
|
|
struct gfar_priv_grp *grp = (struct gfar_priv_grp *)grp_id;
|
|
|
|
unsigned long flags;
|
|
|
|
u32 imask;
|
|
|
|
|
|
|
|
if (likely(napi_schedule_prep(&grp->napi_tx))) {
|
|
|
|
spin_lock_irqsave(&grp->grplock, flags);
|
|
|
|
imask = gfar_read(&grp->regs->imask);
|
2021-06-17 17:49:28 +08:00
|
|
|
imask &= IMASK_TX_DISABLED | grp->priv->rmon_overflow.imask;
|
2014-03-07 20:42:45 +08:00
|
|
|
gfar_write(&grp->regs->imask, imask);
|
|
|
|
spin_unlock_irqrestore(&grp->grplock, flags);
|
|
|
|
__napi_schedule(&grp->napi_tx);
|
|
|
|
} else {
|
|
|
|
/* Clear IEVENT, so interrupts aren't called again
|
|
|
|
* because of the packets that have already arrived.
|
|
|
|
*/
|
|
|
|
gfar_write(&grp->regs->ievent, IEVENT_TX_MASK);
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
gianfar: Add paged allocation and Rx S/G
The eTSEC h/w is capable of scatter/gather on the receive side
too if MAXFRM > MRBLR, when the allowed maximum Rx frame size
is set to be greater than the maximum Rx buffer size (MRBLR).
It's about time the driver makes use of this h/w capability,
by supporting fixed buffer sizes and Rx S/G.
The buffer size given to eTSEC for reception is fixed to
1536B (must be multiple of 64), which is the same default
buffer size as before, used to accommodate standard MTU
(1500B) size frames. As before, eTSEC can receive frames of
up to 9600B. Individual Rx buffers are mapped to page halves
(page size for eTSEC systems is 4KB). The skb is built around
the first buffer of a frame (using build_skb()). In case the
frame spans multiple buffers, the trailing buffers are added
as Rx fragments to the skb. The last buffer in frame is marked
by the L status flag. A mechanism is in place to reuse the pages
owned by the driver (for Rx) for subsequent receptions.
Supporting fixed size buffers allows the implementation of Rx S/G,
which in turn removes the memory pressure issues the driver had
before when MTU was set for jumbo frame reception.
Also, in most cases, the Rx path becomes faster due to Rx page
reusal, since the overhead of allocating new rx buffers is removed
from the fast path.
Signed-off-by: Claudiu Manoil <claudiu.manoil@freescale.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2015-07-13 21:22:06 +08:00
|
|
|
static bool gfar_add_rx_frag(struct gfar_rx_buff *rxb, u32 lstatus,
|
|
|
|
struct sk_buff *skb, bool first)
|
|
|
|
{
|
2018-01-26 11:37:50 +08:00
|
|
|
int size = lstatus & BD_LENGTH_MASK;
|
gianfar: Add paged allocation and Rx S/G
The eTSEC h/w is capable of scatter/gather on the receive side
too if MAXFRM > MRBLR, when the allowed maximum Rx frame size
is set to be greater than the maximum Rx buffer size (MRBLR).
It's about time the driver makes use of this h/w capability,
by supporting fixed buffer sizes and Rx S/G.
The buffer size given to eTSEC for reception is fixed to
1536B (must be multiple of 64), which is the same default
buffer size as before, used to accommodate standard MTU
(1500B) size frames. As before, eTSEC can receive frames of
up to 9600B. Individual Rx buffers are mapped to page halves
(page size for eTSEC systems is 4KB). The skb is built around
the first buffer of a frame (using build_skb()). In case the
frame spans multiple buffers, the trailing buffers are added
as Rx fragments to the skb. The last buffer in frame is marked
by the L status flag. A mechanism is in place to reuse the pages
owned by the driver (for Rx) for subsequent receptions.
Supporting fixed size buffers allows the implementation of Rx S/G,
which in turn removes the memory pressure issues the driver had
before when MTU was set for jumbo frame reception.
Also, in most cases, the Rx path becomes faster due to Rx page
reusal, since the overhead of allocating new rx buffers is removed
from the fast path.
Signed-off-by: Claudiu Manoil <claudiu.manoil@freescale.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2015-07-13 21:22:06 +08:00
|
|
|
struct page *page = rxb->page;
|
|
|
|
|
2016-08-22 21:58:12 +08:00
|
|
|
if (likely(first)) {
|
gianfar: Add paged allocation and Rx S/G
The eTSEC h/w is capable of scatter/gather on the receive side
too if MAXFRM > MRBLR, when the allowed maximum Rx frame size
is set to be greater than the maximum Rx buffer size (MRBLR).
It's about time the driver makes use of this h/w capability,
by supporting fixed buffer sizes and Rx S/G.
The buffer size given to eTSEC for reception is fixed to
1536B (must be multiple of 64), which is the same default
buffer size as before, used to accommodate standard MTU
(1500B) size frames. As before, eTSEC can receive frames of
up to 9600B. Individual Rx buffers are mapped to page halves
(page size for eTSEC systems is 4KB). The skb is built around
the first buffer of a frame (using build_skb()). In case the
frame spans multiple buffers, the trailing buffers are added
as Rx fragments to the skb. The last buffer in frame is marked
by the L status flag. A mechanism is in place to reuse the pages
owned by the driver (for Rx) for subsequent receptions.
Supporting fixed size buffers allows the implementation of Rx S/G,
which in turn removes the memory pressure issues the driver had
before when MTU was set for jumbo frame reception.
Also, in most cases, the Rx path becomes faster due to Rx page
reusal, since the overhead of allocating new rx buffers is removed
from the fast path.
Signed-off-by: Claudiu Manoil <claudiu.manoil@freescale.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2015-07-13 21:22:06 +08:00
|
|
|
skb_put(skb, size);
|
2016-08-22 21:58:12 +08:00
|
|
|
} else {
|
|
|
|
/* the last fragments' length contains the full frame length */
|
2018-02-23 03:05:33 +08:00
|
|
|
if (lstatus & BD_LFLAG(RXBD_LAST))
|
2016-08-22 21:58:12 +08:00
|
|
|
size -= skb->len;
|
|
|
|
|
gianfar: fix jumbo packets+napi+rx overrun crash
When using jumbo packets and overrunning rx queue with napi enabled,
the following sequence is observed in gfar_add_rx_frag:
| lstatus | | skb |
t | lstatus, size, flags | first | len, data_len, *ptr |
---+--------------------------------------+-------+-----------------------+
13 | 18002348, 9032, INTERRUPT LAST | 0 | 9600, 8000, f554c12e |
12 | 10000640, 1600, INTERRUPT | 0 | 8000, 6400, f554c12e |
11 | 10000640, 1600, INTERRUPT | 0 | 6400, 4800, f554c12e |
10 | 10000640, 1600, INTERRUPT | 0 | 4800, 3200, f554c12e |
09 | 10000640, 1600, INTERRUPT | 0 | 3200, 1600, f554c12e |
08 | 14000640, 1600, INTERRUPT FIRST | 0 | 1600, 0, f554c12e |
07 | 14000640, 1600, INTERRUPT FIRST | 1 | 0, 0, f554c12e |
06 | 1c000080, 128, INTERRUPT LAST FIRST | 1 | 0, 0, abf3bd6e |
05 | 18002348, 9032, INTERRUPT LAST | 0 | 8000, 6400, c5a57780 |
04 | 10000640, 1600, INTERRUPT | 0 | 6400, 4800, c5a57780 |
03 | 10000640, 1600, INTERRUPT | 0 | 4800, 3200, c5a57780 |
02 | 10000640, 1600, INTERRUPT | 0 | 3200, 1600, c5a57780 |
01 | 10000640, 1600, INTERRUPT | 0 | 1600, 0, c5a57780 |
00 | 14000640, 1600, INTERRUPT FIRST | 1 | 0, 0, c5a57780 |
So at t=7 a new packets is started but not finished, probably due to rx
overrun - but rx overrun is not indicated in the flags. Instead a new
packets starts at t=8. This results in skb->len to exceed size for the LAST
fragment at t=13 and thus a negative fragment size added to the skb.
This then crashes:
kernel BUG at include/linux/skbuff.h:2277!
Oops: Exception in kernel mode, sig: 5 [#1]
...
NIP [c04689f4] skb_pull+0x2c/0x48
LR [c03f62ac] gfar_clean_rx_ring+0x2e4/0x844
Call Trace:
[ec4bfd38] [c06a84c4] _raw_spin_unlock_irqrestore+0x60/0x7c (unreliable)
[ec4bfda8] [c03f6a44] gfar_poll_rx_sq+0x48/0xe4
[ec4bfdc8] [c048d504] __napi_poll+0x54/0x26c
[ec4bfdf8] [c048d908] net_rx_action+0x138/0x2c0
[ec4bfe68] [c06a8f34] __do_softirq+0x3a4/0x4fc
[ec4bfed8] [c0040150] run_ksoftirqd+0x58/0x70
[ec4bfee8] [c0066ecc] smpboot_thread_fn+0x184/0x1cc
[ec4bff08] [c0062718] kthread+0x140/0x144
[ec4bff38] [c0012350] ret_from_kernel_thread+0x14/0x1c
This patch fixes this by checking for computed LAST fragment size, so a
negative sized fragment is never added.
In order to prevent the newer rx frame from getting corrupted, the FIRST
flag is checked to discard the incomplete older frame.
Signed-off-by: Michael Braun <michael-dev@fami-braun.de>
Signed-off-by: David S. Miller <davem@davemloft.net>
2021-03-05 03:52:52 +08:00
|
|
|
WARN(size < 0, "gianfar: rx fragment size underflow");
|
|
|
|
if (size < 0)
|
|
|
|
return false;
|
|
|
|
|
2018-02-23 03:05:33 +08:00
|
|
|
skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, page,
|
|
|
|
rxb->page_offset + RXBUF_ALIGNMENT,
|
|
|
|
size, GFAR_RXB_TRUESIZE);
|
2016-08-22 21:58:12 +08:00
|
|
|
}
|
gianfar: Add paged allocation and Rx S/G
The eTSEC h/w is capable of scatter/gather on the receive side
too if MAXFRM > MRBLR, when the allowed maximum Rx frame size
is set to be greater than the maximum Rx buffer size (MRBLR).
It's about time the driver makes use of this h/w capability,
by supporting fixed buffer sizes and Rx S/G.
The buffer size given to eTSEC for reception is fixed to
1536B (must be multiple of 64), which is the same default
buffer size as before, used to accommodate standard MTU
(1500B) size frames. As before, eTSEC can receive frames of
up to 9600B. Individual Rx buffers are mapped to page halves
(page size for eTSEC systems is 4KB). The skb is built around
the first buffer of a frame (using build_skb()). In case the
frame spans multiple buffers, the trailing buffers are added
as Rx fragments to the skb. The last buffer in frame is marked
by the L status flag. A mechanism is in place to reuse the pages
owned by the driver (for Rx) for subsequent receptions.
Supporting fixed size buffers allows the implementation of Rx S/G,
which in turn removes the memory pressure issues the driver had
before when MTU was set for jumbo frame reception.
Also, in most cases, the Rx path becomes faster due to Rx page
reusal, since the overhead of allocating new rx buffers is removed
from the fast path.
Signed-off-by: Claudiu Manoil <claudiu.manoil@freescale.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2015-07-13 21:22:06 +08:00
|
|
|
|
|
|
|
/* try reuse page */
|
2017-01-19 11:44:42 +08:00
|
|
|
if (unlikely(page_count(page) != 1 || page_is_pfmemalloc(page)))
|
gianfar: Add paged allocation and Rx S/G
The eTSEC h/w is capable of scatter/gather on the receive side
too if MAXFRM > MRBLR, when the allowed maximum Rx frame size
is set to be greater than the maximum Rx buffer size (MRBLR).
It's about time the driver makes use of this h/w capability,
by supporting fixed buffer sizes and Rx S/G.
The buffer size given to eTSEC for reception is fixed to
1536B (must be multiple of 64), which is the same default
buffer size as before, used to accommodate standard MTU
(1500B) size frames. As before, eTSEC can receive frames of
up to 9600B. Individual Rx buffers are mapped to page halves
(page size for eTSEC systems is 4KB). The skb is built around
the first buffer of a frame (using build_skb()). In case the
frame spans multiple buffers, the trailing buffers are added
as Rx fragments to the skb. The last buffer in frame is marked
by the L status flag. A mechanism is in place to reuse the pages
owned by the driver (for Rx) for subsequent receptions.
Supporting fixed size buffers allows the implementation of Rx S/G,
which in turn removes the memory pressure issues the driver had
before when MTU was set for jumbo frame reception.
Also, in most cases, the Rx path becomes faster due to Rx page
reusal, since the overhead of allocating new rx buffers is removed
from the fast path.
Signed-off-by: Claudiu Manoil <claudiu.manoil@freescale.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2015-07-13 21:22:06 +08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
/* change offset to the other half */
|
|
|
|
rxb->page_offset ^= GFAR_RXB_TRUESIZE;
|
|
|
|
|
2016-03-18 05:19:26 +08:00
|
|
|
page_ref_inc(page);
|
gianfar: Add paged allocation and Rx S/G
The eTSEC h/w is capable of scatter/gather on the receive side
too if MAXFRM > MRBLR, when the allowed maximum Rx frame size
is set to be greater than the maximum Rx buffer size (MRBLR).
It's about time the driver makes use of this h/w capability,
by supporting fixed buffer sizes and Rx S/G.
The buffer size given to eTSEC for reception is fixed to
1536B (must be multiple of 64), which is the same default
buffer size as before, used to accommodate standard MTU
(1500B) size frames. As before, eTSEC can receive frames of
up to 9600B. Individual Rx buffers are mapped to page halves
(page size for eTSEC systems is 4KB). The skb is built around
the first buffer of a frame (using build_skb()). In case the
frame spans multiple buffers, the trailing buffers are added
as Rx fragments to the skb. The last buffer in frame is marked
by the L status flag. A mechanism is in place to reuse the pages
owned by the driver (for Rx) for subsequent receptions.
Supporting fixed size buffers allows the implementation of Rx S/G,
which in turn removes the memory pressure issues the driver had
before when MTU was set for jumbo frame reception.
Also, in most cases, the Rx path becomes faster due to Rx page
reusal, since the overhead of allocating new rx buffers is removed
from the fast path.
Signed-off-by: Claudiu Manoil <claudiu.manoil@freescale.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2015-07-13 21:22:06 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gfar_reuse_rx_page(struct gfar_priv_rx_q *rxq,
|
|
|
|
struct gfar_rx_buff *old_rxb)
|
|
|
|
{
|
|
|
|
struct gfar_rx_buff *new_rxb;
|
|
|
|
u16 nta = rxq->next_to_alloc;
|
|
|
|
|
|
|
|
new_rxb = &rxq->rx_buff[nta];
|
|
|
|
|
|
|
|
/* find next buf that can reuse a page */
|
|
|
|
nta++;
|
|
|
|
rxq->next_to_alloc = (nta < rxq->rx_ring_size) ? nta : 0;
|
|
|
|
|
|
|
|
/* copy page reference */
|
|
|
|
*new_rxb = *old_rxb;
|
|
|
|
|
|
|
|
/* sync for use by the device */
|
|
|
|
dma_sync_single_range_for_device(rxq->dev, old_rxb->dma,
|
|
|
|
old_rxb->page_offset,
|
|
|
|
GFAR_RXB_TRUESIZE, DMA_FROM_DEVICE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct sk_buff *gfar_get_next_rxbuff(struct gfar_priv_rx_q *rx_queue,
|
|
|
|
u32 lstatus, struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
struct gfar_rx_buff *rxb = &rx_queue->rx_buff[rx_queue->next_to_clean];
|
|
|
|
struct page *page = rxb->page;
|
|
|
|
bool first = false;
|
|
|
|
|
|
|
|
if (likely(!skb)) {
|
|
|
|
void *buff_addr = page_address(page) + rxb->page_offset;
|
|
|
|
|
|
|
|
skb = build_skb(buff_addr, GFAR_SKBFRAG_SIZE);
|
|
|
|
if (unlikely(!skb)) {
|
|
|
|
gfar_rx_alloc_err(rx_queue);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
skb_reserve(skb, RXBUF_ALIGNMENT);
|
|
|
|
first = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
dma_sync_single_range_for_cpu(rx_queue->dev, rxb->dma, rxb->page_offset,
|
|
|
|
GFAR_RXB_TRUESIZE, DMA_FROM_DEVICE);
|
|
|
|
|
|
|
|
if (gfar_add_rx_frag(rxb, lstatus, skb, first)) {
|
|
|
|
/* reuse the free half of the page */
|
|
|
|
gfar_reuse_rx_page(rx_queue, rxb);
|
|
|
|
} else {
|
|
|
|
/* page cannot be reused, unmap it */
|
|
|
|
dma_unmap_page(rx_queue->dev, rxb->dma,
|
|
|
|
PAGE_SIZE, DMA_FROM_DEVICE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* clear rxb content */
|
|
|
|
rxb->page = NULL;
|
|
|
|
|
|
|
|
return skb;
|
|
|
|
}
|
|
|
|
|
2005-06-20 23:54:21 +08:00
|
|
|
static inline void gfar_rx_checksum(struct sk_buff *skb, struct rxfcb *fcb)
|
|
|
|
{
|
|
|
|
/* If valid headers were found, and valid sums
|
|
|
|
* were verified, then we tell the kernel that no
|
2012-06-05 11:42:12 +08:00
|
|
|
* checksumming is necessary. Otherwise, it is [FIXME]
|
|
|
|
*/
|
2015-03-13 16:36:29 +08:00
|
|
|
if ((be16_to_cpu(fcb->flags) & RXFCB_CSUM_MASK) ==
|
|
|
|
(RXFCB_CIP | RXFCB_CTU))
|
2005-06-20 23:54:21 +08:00
|
|
|
skb->ip_summed = CHECKSUM_UNNECESSARY;
|
|
|
|
else
|
2010-09-03 04:07:41 +08:00
|
|
|
skb_checksum_none_assert(skb);
|
2005-06-20 23:54:21 +08:00
|
|
|
}
|
|
|
|
|
2012-06-05 11:42:12 +08:00
|
|
|
/* gfar_process_frame() -- handle one incoming packet if skb isn't NULL. */
|
2015-07-13 21:22:05 +08:00
|
|
|
static void gfar_process_frame(struct net_device *ndev, struct sk_buff *skb)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2015-07-13 21:22:05 +08:00
|
|
|
struct gfar_private *priv = netdev_priv(ndev);
|
2005-06-20 23:54:21 +08:00
|
|
|
struct rxfcb *fcb = NULL;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-12-17 07:31:15 +08:00
|
|
|
/* fcb is at the beginning if exists */
|
|
|
|
fcb = (struct rxfcb *)skb->data;
|
2005-06-20 23:54:21 +08:00
|
|
|
|
2012-06-05 11:42:12 +08:00
|
|
|
/* Remove the FCB from the skb
|
|
|
|
* Remove the padded bytes, if there are any
|
|
|
|
*/
|
2015-07-13 21:22:05 +08:00
|
|
|
if (priv->uses_rxfcb)
|
2015-07-13 21:22:03 +08:00
|
|
|
skb_pull(skb, GMAC_FCB_LEN);
|
2005-06-20 23:54:21 +08:00
|
|
|
|
2010-04-09 07:10:03 +08:00
|
|
|
/* Get receive timestamp from the skb */
|
|
|
|
if (priv->hwts_rx_en) {
|
|
|
|
struct skb_shared_hwtstamps *shhwtstamps = skb_hwtstamps(skb);
|
|
|
|
u64 *ns = (u64 *) skb->data;
|
2012-06-05 11:42:13 +08:00
|
|
|
|
2010-04-09 07:10:03 +08:00
|
|
|
memset(shhwtstamps, 0, sizeof(*shhwtstamps));
|
2016-02-24 17:26:56 +08:00
|
|
|
shhwtstamps->hwtstamp = ns_to_ktime(be64_to_cpu(*ns));
|
2010-04-09 07:10:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (priv->padding)
|
|
|
|
skb_pull(skb, priv->padding);
|
|
|
|
|
2018-02-23 03:05:33 +08:00
|
|
|
/* Trim off the FCS */
|
|
|
|
pskb_trim(skb, skb->len - ETH_FCS_LEN);
|
|
|
|
|
2015-07-13 21:22:05 +08:00
|
|
|
if (ndev->features & NETIF_F_RXCSUM)
|
2008-12-17 07:31:15 +08:00
|
|
|
gfar_rx_checksum(skb, fcb);
|
2005-06-20 23:54:21 +08:00
|
|
|
|
2013-04-19 10:04:27 +08:00
|
|
|
/* There's need to check for NETIF_F_HW_VLAN_CTAG_RX here.
|
2011-08-10 09:19:48 +08:00
|
|
|
* Even if vlan rx accel is disabled, on some chips
|
|
|
|
* RXFCB_VLN is pseudo randomly set.
|
|
|
|
*/
|
2015-07-13 21:22:05 +08:00
|
|
|
if (ndev->features & NETIF_F_HW_VLAN_CTAG_RX &&
|
2015-03-13 16:36:29 +08:00
|
|
|
be16_to_cpu(fcb->flags) & RXFCB_VLN)
|
|
|
|
__vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q),
|
|
|
|
be16_to_cpu(fcb->vlctl));
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* gfar_clean_rx_ring() -- Processes each frame in the rx ring
|
2012-06-05 11:42:11 +08:00
|
|
|
* until the budget/quota has been reached. Returns the number
|
|
|
|
* of frames handled
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2019-09-04 21:52:20 +08:00
|
|
|
static int gfar_clean_rx_ring(struct gfar_priv_rx_q *rx_queue,
|
|
|
|
int rx_work_limit)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2015-07-13 21:22:05 +08:00
|
|
|
struct net_device *ndev = rx_queue->ndev;
|
gianfar: Add paged allocation and Rx S/G
The eTSEC h/w is capable of scatter/gather on the receive side
too if MAXFRM > MRBLR, when the allowed maximum Rx frame size
is set to be greater than the maximum Rx buffer size (MRBLR).
It's about time the driver makes use of this h/w capability,
by supporting fixed buffer sizes and Rx S/G.
The buffer size given to eTSEC for reception is fixed to
1536B (must be multiple of 64), which is the same default
buffer size as before, used to accommodate standard MTU
(1500B) size frames. As before, eTSEC can receive frames of
up to 9600B. Individual Rx buffers are mapped to page halves
(page size for eTSEC systems is 4KB). The skb is built around
the first buffer of a frame (using build_skb()). In case the
frame spans multiple buffers, the trailing buffers are added
as Rx fragments to the skb. The last buffer in frame is marked
by the L status flag. A mechanism is in place to reuse the pages
owned by the driver (for Rx) for subsequent receptions.
Supporting fixed size buffers allows the implementation of Rx S/G,
which in turn removes the memory pressure issues the driver had
before when MTU was set for jumbo frame reception.
Also, in most cases, the Rx path becomes faster due to Rx page
reusal, since the overhead of allocating new rx buffers is removed
from the fast path.
Signed-off-by: Claudiu Manoil <claudiu.manoil@freescale.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2015-07-13 21:22:06 +08:00
|
|
|
struct gfar_private *priv = netdev_priv(ndev);
|
|
|
|
struct rxbd8 *bdp;
|
2015-07-13 21:22:03 +08:00
|
|
|
int i, howmany = 0;
|
gianfar: Add paged allocation and Rx S/G
The eTSEC h/w is capable of scatter/gather on the receive side
too if MAXFRM > MRBLR, when the allowed maximum Rx frame size
is set to be greater than the maximum Rx buffer size (MRBLR).
It's about time the driver makes use of this h/w capability,
by supporting fixed buffer sizes and Rx S/G.
The buffer size given to eTSEC for reception is fixed to
1536B (must be multiple of 64), which is the same default
buffer size as before, used to accommodate standard MTU
(1500B) size frames. As before, eTSEC can receive frames of
up to 9600B. Individual Rx buffers are mapped to page halves
(page size for eTSEC systems is 4KB). The skb is built around
the first buffer of a frame (using build_skb()). In case the
frame spans multiple buffers, the trailing buffers are added
as Rx fragments to the skb. The last buffer in frame is marked
by the L status flag. A mechanism is in place to reuse the pages
owned by the driver (for Rx) for subsequent receptions.
Supporting fixed size buffers allows the implementation of Rx S/G,
which in turn removes the memory pressure issues the driver had
before when MTU was set for jumbo frame reception.
Also, in most cases, the Rx path becomes faster due to Rx page
reusal, since the overhead of allocating new rx buffers is removed
from the fast path.
Signed-off-by: Claudiu Manoil <claudiu.manoil@freescale.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2015-07-13 21:22:06 +08:00
|
|
|
struct sk_buff *skb = rx_queue->skb;
|
2015-07-13 21:22:03 +08:00
|
|
|
int cleaned_cnt = gfar_rxbd_unused(rx_queue);
|
gianfar: Add paged allocation and Rx S/G
The eTSEC h/w is capable of scatter/gather on the receive side
too if MAXFRM > MRBLR, when the allowed maximum Rx frame size
is set to be greater than the maximum Rx buffer size (MRBLR).
It's about time the driver makes use of this h/w capability,
by supporting fixed buffer sizes and Rx S/G.
The buffer size given to eTSEC for reception is fixed to
1536B (must be multiple of 64), which is the same default
buffer size as before, used to accommodate standard MTU
(1500B) size frames. As before, eTSEC can receive frames of
up to 9600B. Individual Rx buffers are mapped to page halves
(page size for eTSEC systems is 4KB). The skb is built around
the first buffer of a frame (using build_skb()). In case the
frame spans multiple buffers, the trailing buffers are added
as Rx fragments to the skb. The last buffer in frame is marked
by the L status flag. A mechanism is in place to reuse the pages
owned by the driver (for Rx) for subsequent receptions.
Supporting fixed size buffers allows the implementation of Rx S/G,
which in turn removes the memory pressure issues the driver had
before when MTU was set for jumbo frame reception.
Also, in most cases, the Rx path becomes faster due to Rx page
reusal, since the overhead of allocating new rx buffers is removed
from the fast path.
Signed-off-by: Claudiu Manoil <claudiu.manoil@freescale.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2015-07-13 21:22:06 +08:00
|
|
|
unsigned int total_bytes = 0, total_pkts = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Get the first full descriptor */
|
2015-07-13 21:22:03 +08:00
|
|
|
i = rx_queue->next_to_clean;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2015-07-13 21:22:03 +08:00
|
|
|
while (rx_work_limit--) {
|
2015-07-13 21:22:04 +08:00
|
|
|
u32 lstatus;
|
2008-12-17 07:31:15 +08:00
|
|
|
|
2015-07-13 21:22:03 +08:00
|
|
|
if (cleaned_cnt >= GFAR_RX_BUFF_ALLOC) {
|
|
|
|
gfar_alloc_rx_buffs(rx_queue, cleaned_cnt);
|
|
|
|
cleaned_cnt = 0;
|
|
|
|
}
|
2012-06-05 11:42:13 +08:00
|
|
|
|
2015-07-13 21:22:03 +08:00
|
|
|
bdp = &rx_queue->rx_bd_base[i];
|
2015-07-13 21:22:04 +08:00
|
|
|
lstatus = be32_to_cpu(bdp->lstatus);
|
|
|
|
if (lstatus & BD_LFLAG(RXBD_EMPTY))
|
2015-07-13 21:22:03 +08:00
|
|
|
break;
|
2008-04-23 06:18:29 +08:00
|
|
|
|
gianfar: fix jumbo packets+napi+rx overrun crash
When using jumbo packets and overrunning rx queue with napi enabled,
the following sequence is observed in gfar_add_rx_frag:
| lstatus | | skb |
t | lstatus, size, flags | first | len, data_len, *ptr |
---+--------------------------------------+-------+-----------------------+
13 | 18002348, 9032, INTERRUPT LAST | 0 | 9600, 8000, f554c12e |
12 | 10000640, 1600, INTERRUPT | 0 | 8000, 6400, f554c12e |
11 | 10000640, 1600, INTERRUPT | 0 | 6400, 4800, f554c12e |
10 | 10000640, 1600, INTERRUPT | 0 | 4800, 3200, f554c12e |
09 | 10000640, 1600, INTERRUPT | 0 | 3200, 1600, f554c12e |
08 | 14000640, 1600, INTERRUPT FIRST | 0 | 1600, 0, f554c12e |
07 | 14000640, 1600, INTERRUPT FIRST | 1 | 0, 0, f554c12e |
06 | 1c000080, 128, INTERRUPT LAST FIRST | 1 | 0, 0, abf3bd6e |
05 | 18002348, 9032, INTERRUPT LAST | 0 | 8000, 6400, c5a57780 |
04 | 10000640, 1600, INTERRUPT | 0 | 6400, 4800, c5a57780 |
03 | 10000640, 1600, INTERRUPT | 0 | 4800, 3200, c5a57780 |
02 | 10000640, 1600, INTERRUPT | 0 | 3200, 1600, c5a57780 |
01 | 10000640, 1600, INTERRUPT | 0 | 1600, 0, c5a57780 |
00 | 14000640, 1600, INTERRUPT FIRST | 1 | 0, 0, c5a57780 |
So at t=7 a new packets is started but not finished, probably due to rx
overrun - but rx overrun is not indicated in the flags. Instead a new
packets starts at t=8. This results in skb->len to exceed size for the LAST
fragment at t=13 and thus a negative fragment size added to the skb.
This then crashes:
kernel BUG at include/linux/skbuff.h:2277!
Oops: Exception in kernel mode, sig: 5 [#1]
...
NIP [c04689f4] skb_pull+0x2c/0x48
LR [c03f62ac] gfar_clean_rx_ring+0x2e4/0x844
Call Trace:
[ec4bfd38] [c06a84c4] _raw_spin_unlock_irqrestore+0x60/0x7c (unreliable)
[ec4bfda8] [c03f6a44] gfar_poll_rx_sq+0x48/0xe4
[ec4bfdc8] [c048d504] __napi_poll+0x54/0x26c
[ec4bfdf8] [c048d908] net_rx_action+0x138/0x2c0
[ec4bfe68] [c06a8f34] __do_softirq+0x3a4/0x4fc
[ec4bfed8] [c0040150] run_ksoftirqd+0x58/0x70
[ec4bfee8] [c0066ecc] smpboot_thread_fn+0x184/0x1cc
[ec4bff08] [c0062718] kthread+0x140/0x144
[ec4bff38] [c0012350] ret_from_kernel_thread+0x14/0x1c
This patch fixes this by checking for computed LAST fragment size, so a
negative sized fragment is never added.
In order to prevent the newer rx frame from getting corrupted, the FIRST
flag is checked to discard the incomplete older frame.
Signed-off-by: Michael Braun <michael-dev@fami-braun.de>
Signed-off-by: David S. Miller <davem@davemloft.net>
2021-03-05 03:52:52 +08:00
|
|
|
/* lost RXBD_LAST descriptor due to overrun */
|
|
|
|
if (skb &&
|
|
|
|
(lstatus & BD_LFLAG(RXBD_FIRST))) {
|
|
|
|
/* discard faulty buffer */
|
|
|
|
dev_kfree_skb(skb);
|
|
|
|
skb = NULL;
|
|
|
|
rx_queue->stats.rx_dropped++;
|
|
|
|
|
|
|
|
/* can continue normally */
|
|
|
|
}
|
|
|
|
|
2015-07-13 21:22:03 +08:00
|
|
|
/* order rx buffer descriptor reads */
|
|
|
|
rmb();
|
2008-04-23 06:18:29 +08:00
|
|
|
|
2015-07-13 21:22:03 +08:00
|
|
|
/* fetch next to clean buffer from the ring */
|
gianfar: Add paged allocation and Rx S/G
The eTSEC h/w is capable of scatter/gather on the receive side
too if MAXFRM > MRBLR, when the allowed maximum Rx frame size
is set to be greater than the maximum Rx buffer size (MRBLR).
It's about time the driver makes use of this h/w capability,
by supporting fixed buffer sizes and Rx S/G.
The buffer size given to eTSEC for reception is fixed to
1536B (must be multiple of 64), which is the same default
buffer size as before, used to accommodate standard MTU
(1500B) size frames. As before, eTSEC can receive frames of
up to 9600B. Individual Rx buffers are mapped to page halves
(page size for eTSEC systems is 4KB). The skb is built around
the first buffer of a frame (using build_skb()). In case the
frame spans multiple buffers, the trailing buffers are added
as Rx fragments to the skb. The last buffer in frame is marked
by the L status flag. A mechanism is in place to reuse the pages
owned by the driver (for Rx) for subsequent receptions.
Supporting fixed size buffers allows the implementation of Rx S/G,
which in turn removes the memory pressure issues the driver had
before when MTU was set for jumbo frame reception.
Also, in most cases, the Rx path becomes faster due to Rx page
reusal, since the overhead of allocating new rx buffers is removed
from the fast path.
Signed-off-by: Claudiu Manoil <claudiu.manoil@freescale.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2015-07-13 21:22:06 +08:00
|
|
|
skb = gfar_get_next_rxbuff(rx_queue, lstatus, skb);
|
|
|
|
if (unlikely(!skb))
|
|
|
|
break;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
gianfar: Add paged allocation and Rx S/G
The eTSEC h/w is capable of scatter/gather on the receive side
too if MAXFRM > MRBLR, when the allowed maximum Rx frame size
is set to be greater than the maximum Rx buffer size (MRBLR).
It's about time the driver makes use of this h/w capability,
by supporting fixed buffer sizes and Rx S/G.
The buffer size given to eTSEC for reception is fixed to
1536B (must be multiple of 64), which is the same default
buffer size as before, used to accommodate standard MTU
(1500B) size frames. As before, eTSEC can receive frames of
up to 9600B. Individual Rx buffers are mapped to page halves
(page size for eTSEC systems is 4KB). The skb is built around
the first buffer of a frame (using build_skb()). In case the
frame spans multiple buffers, the trailing buffers are added
as Rx fragments to the skb. The last buffer in frame is marked
by the L status flag. A mechanism is in place to reuse the pages
owned by the driver (for Rx) for subsequent receptions.
Supporting fixed size buffers allows the implementation of Rx S/G,
which in turn removes the memory pressure issues the driver had
before when MTU was set for jumbo frame reception.
Also, in most cases, the Rx path becomes faster due to Rx page
reusal, since the overhead of allocating new rx buffers is removed
from the fast path.
Signed-off-by: Claudiu Manoil <claudiu.manoil@freescale.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2015-07-13 21:22:06 +08:00
|
|
|
cleaned_cnt++;
|
|
|
|
howmany++;
|
2008-11-13 00:07:11 +08:00
|
|
|
|
gianfar: Add paged allocation and Rx S/G
The eTSEC h/w is capable of scatter/gather on the receive side
too if MAXFRM > MRBLR, when the allowed maximum Rx frame size
is set to be greater than the maximum Rx buffer size (MRBLR).
It's about time the driver makes use of this h/w capability,
by supporting fixed buffer sizes and Rx S/G.
The buffer size given to eTSEC for reception is fixed to
1536B (must be multiple of 64), which is the same default
buffer size as before, used to accommodate standard MTU
(1500B) size frames. As before, eTSEC can receive frames of
up to 9600B. Individual Rx buffers are mapped to page halves
(page size for eTSEC systems is 4KB). The skb is built around
the first buffer of a frame (using build_skb()). In case the
frame spans multiple buffers, the trailing buffers are added
as Rx fragments to the skb. The last buffer in frame is marked
by the L status flag. A mechanism is in place to reuse the pages
owned by the driver (for Rx) for subsequent receptions.
Supporting fixed size buffers allows the implementation of Rx S/G,
which in turn removes the memory pressure issues the driver had
before when MTU was set for jumbo frame reception.
Also, in most cases, the Rx path becomes faster due to Rx page
reusal, since the overhead of allocating new rx buffers is removed
from the fast path.
Signed-off-by: Claudiu Manoil <claudiu.manoil@freescale.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2015-07-13 21:22:06 +08:00
|
|
|
if (unlikely(++i == rx_queue->rx_ring_size))
|
|
|
|
i = 0;
|
|
|
|
|
|
|
|
rx_queue->next_to_clean = i;
|
|
|
|
|
|
|
|
/* fetch next buffer if not the last in frame */
|
|
|
|
if (!(lstatus & BD_LFLAG(RXBD_LAST)))
|
|
|
|
continue;
|
2010-06-11 18:51:03 +08:00
|
|
|
|
gianfar: Add paged allocation and Rx S/G
The eTSEC h/w is capable of scatter/gather on the receive side
too if MAXFRM > MRBLR, when the allowed maximum Rx frame size
is set to be greater than the maximum Rx buffer size (MRBLR).
It's about time the driver makes use of this h/w capability,
by supporting fixed buffer sizes and Rx S/G.
The buffer size given to eTSEC for reception is fixed to
1536B (must be multiple of 64), which is the same default
buffer size as before, used to accommodate standard MTU
(1500B) size frames. As before, eTSEC can receive frames of
up to 9600B. Individual Rx buffers are mapped to page halves
(page size for eTSEC systems is 4KB). The skb is built around
the first buffer of a frame (using build_skb()). In case the
frame spans multiple buffers, the trailing buffers are added
as Rx fragments to the skb. The last buffer in frame is marked
by the L status flag. A mechanism is in place to reuse the pages
owned by the driver (for Rx) for subsequent receptions.
Supporting fixed size buffers allows the implementation of Rx S/G,
which in turn removes the memory pressure issues the driver had
before when MTU was set for jumbo frame reception.
Also, in most cases, the Rx path becomes faster due to Rx page
reusal, since the overhead of allocating new rx buffers is removed
from the fast path.
Signed-off-by: Claudiu Manoil <claudiu.manoil@freescale.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2015-07-13 21:22:06 +08:00
|
|
|
if (unlikely(lstatus & BD_LFLAG(RXBD_ERR))) {
|
2015-07-13 21:22:05 +08:00
|
|
|
count_errors(lstatus, ndev);
|
2008-04-23 06:18:29 +08:00
|
|
|
|
2015-07-13 21:22:03 +08:00
|
|
|
/* discard faulty buffer */
|
|
|
|
dev_kfree_skb(skb);
|
gianfar: Add paged allocation and Rx S/G
The eTSEC h/w is capable of scatter/gather on the receive side
too if MAXFRM > MRBLR, when the allowed maximum Rx frame size
is set to be greater than the maximum Rx buffer size (MRBLR).
It's about time the driver makes use of this h/w capability,
by supporting fixed buffer sizes and Rx S/G.
The buffer size given to eTSEC for reception is fixed to
1536B (must be multiple of 64), which is the same default
buffer size as before, used to accommodate standard MTU
(1500B) size frames. As before, eTSEC can receive frames of
up to 9600B. Individual Rx buffers are mapped to page halves
(page size for eTSEC systems is 4KB). The skb is built around
the first buffer of a frame (using build_skb()). In case the
frame spans multiple buffers, the trailing buffers are added
as Rx fragments to the skb. The last buffer in frame is marked
by the L status flag. A mechanism is in place to reuse the pages
owned by the driver (for Rx) for subsequent receptions.
Supporting fixed size buffers allows the implementation of Rx S/G,
which in turn removes the memory pressure issues the driver had
before when MTU was set for jumbo frame reception.
Also, in most cases, the Rx path becomes faster due to Rx page
reusal, since the overhead of allocating new rx buffers is removed
from the fast path.
Signed-off-by: Claudiu Manoil <claudiu.manoil@freescale.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2015-07-13 21:22:06 +08:00
|
|
|
skb = NULL;
|
|
|
|
rx_queue->stats.rx_dropped++;
|
|
|
|
continue;
|
|
|
|
}
|
2015-07-13 21:22:03 +08:00
|
|
|
|
2018-02-27 23:33:10 +08:00
|
|
|
gfar_process_frame(ndev, skb);
|
|
|
|
|
gianfar: Add paged allocation and Rx S/G
The eTSEC h/w is capable of scatter/gather on the receive side
too if MAXFRM > MRBLR, when the allowed maximum Rx frame size
is set to be greater than the maximum Rx buffer size (MRBLR).
It's about time the driver makes use of this h/w capability,
by supporting fixed buffer sizes and Rx S/G.
The buffer size given to eTSEC for reception is fixed to
1536B (must be multiple of 64), which is the same default
buffer size as before, used to accommodate standard MTU
(1500B) size frames. As before, eTSEC can receive frames of
up to 9600B. Individual Rx buffers are mapped to page halves
(page size for eTSEC systems is 4KB). The skb is built around
the first buffer of a frame (using build_skb()). In case the
frame spans multiple buffers, the trailing buffers are added
as Rx fragments to the skb. The last buffer in frame is marked
by the L status flag. A mechanism is in place to reuse the pages
owned by the driver (for Rx) for subsequent receptions.
Supporting fixed size buffers allows the implementation of Rx S/G,
which in turn removes the memory pressure issues the driver had
before when MTU was set for jumbo frame reception.
Also, in most cases, the Rx path becomes faster due to Rx page
reusal, since the overhead of allocating new rx buffers is removed
from the fast path.
Signed-off-by: Claudiu Manoil <claudiu.manoil@freescale.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2015-07-13 21:22:06 +08:00
|
|
|
/* Increment the number of packets */
|
|
|
|
total_pkts++;
|
|
|
|
total_bytes += skb->len;
|
2008-12-17 07:31:15 +08:00
|
|
|
|
gianfar: Add paged allocation and Rx S/G
The eTSEC h/w is capable of scatter/gather on the receive side
too if MAXFRM > MRBLR, when the allowed maximum Rx frame size
is set to be greater than the maximum Rx buffer size (MRBLR).
It's about time the driver makes use of this h/w capability,
by supporting fixed buffer sizes and Rx S/G.
The buffer size given to eTSEC for reception is fixed to
1536B (must be multiple of 64), which is the same default
buffer size as before, used to accommodate standard MTU
(1500B) size frames. As before, eTSEC can receive frames of
up to 9600B. Individual Rx buffers are mapped to page halves
(page size for eTSEC systems is 4KB). The skb is built around
the first buffer of a frame (using build_skb()). In case the
frame spans multiple buffers, the trailing buffers are added
as Rx fragments to the skb. The last buffer in frame is marked
by the L status flag. A mechanism is in place to reuse the pages
owned by the driver (for Rx) for subsequent receptions.
Supporting fixed size buffers allows the implementation of Rx S/G,
which in turn removes the memory pressure issues the driver had
before when MTU was set for jumbo frame reception.
Also, in most cases, the Rx path becomes faster due to Rx page
reusal, since the overhead of allocating new rx buffers is removed
from the fast path.
Signed-off-by: Claudiu Manoil <claudiu.manoil@freescale.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2015-07-13 21:22:06 +08:00
|
|
|
skb_record_rx_queue(skb, rx_queue->qindex);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2018-02-27 23:33:10 +08:00
|
|
|
skb->protocol = eth_type_trans(skb, ndev);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
gianfar: Add paged allocation and Rx S/G
The eTSEC h/w is capable of scatter/gather on the receive side
too if MAXFRM > MRBLR, when the allowed maximum Rx frame size
is set to be greater than the maximum Rx buffer size (MRBLR).
It's about time the driver makes use of this h/w capability,
by supporting fixed buffer sizes and Rx S/G.
The buffer size given to eTSEC for reception is fixed to
1536B (must be multiple of 64), which is the same default
buffer size as before, used to accommodate standard MTU
(1500B) size frames. As before, eTSEC can receive frames of
up to 9600B. Individual Rx buffers are mapped to page halves
(page size for eTSEC systems is 4KB). The skb is built around
the first buffer of a frame (using build_skb()). In case the
frame spans multiple buffers, the trailing buffers are added
as Rx fragments to the skb. The last buffer in frame is marked
by the L status flag. A mechanism is in place to reuse the pages
owned by the driver (for Rx) for subsequent receptions.
Supporting fixed size buffers allows the implementation of Rx S/G,
which in turn removes the memory pressure issues the driver had
before when MTU was set for jumbo frame reception.
Also, in most cases, the Rx path becomes faster due to Rx page
reusal, since the overhead of allocating new rx buffers is removed
from the fast path.
Signed-off-by: Claudiu Manoil <claudiu.manoil@freescale.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2015-07-13 21:22:06 +08:00
|
|
|
/* Send the packet up the stack */
|
|
|
|
napi_gro_receive(&rx_queue->grp->napi_rx, skb);
|
|
|
|
|
|
|
|
skb = NULL;
|
2015-07-13 21:22:03 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
gianfar: Add paged allocation and Rx S/G
The eTSEC h/w is capable of scatter/gather on the receive side
too if MAXFRM > MRBLR, when the allowed maximum Rx frame size
is set to be greater than the maximum Rx buffer size (MRBLR).
It's about time the driver makes use of this h/w capability,
by supporting fixed buffer sizes and Rx S/G.
The buffer size given to eTSEC for reception is fixed to
1536B (must be multiple of 64), which is the same default
buffer size as before, used to accommodate standard MTU
(1500B) size frames. As before, eTSEC can receive frames of
up to 9600B. Individual Rx buffers are mapped to page halves
(page size for eTSEC systems is 4KB). The skb is built around
the first buffer of a frame (using build_skb()). In case the
frame spans multiple buffers, the trailing buffers are added
as Rx fragments to the skb. The last buffer in frame is marked
by the L status flag. A mechanism is in place to reuse the pages
owned by the driver (for Rx) for subsequent receptions.
Supporting fixed size buffers allows the implementation of Rx S/G,
which in turn removes the memory pressure issues the driver had
before when MTU was set for jumbo frame reception.
Also, in most cases, the Rx path becomes faster due to Rx page
reusal, since the overhead of allocating new rx buffers is removed
from the fast path.
Signed-off-by: Claudiu Manoil <claudiu.manoil@freescale.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2015-07-13 21:22:06 +08:00
|
|
|
/* Store incomplete frames for completion */
|
|
|
|
rx_queue->skb = skb;
|
|
|
|
|
|
|
|
rx_queue->stats.rx_packets += total_pkts;
|
|
|
|
rx_queue->stats.rx_bytes += total_bytes;
|
2014-10-27 16:42:44 +08:00
|
|
|
|
2015-07-13 21:22:03 +08:00
|
|
|
if (cleaned_cnt)
|
|
|
|
gfar_alloc_rx_buffs(rx_queue, cleaned_cnt);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2015-07-13 21:22:03 +08:00
|
|
|
/* Update Last Free RxBD pointer for LFC */
|
|
|
|
if (unlikely(priv->tx_actual_en)) {
|
2015-07-29 21:13:06 +08:00
|
|
|
u32 bdp_dma = gfar_rxbd_dma_lastfree(rx_queue);
|
|
|
|
|
|
|
|
gfar_write(rx_queue->rfbptr, bdp_dma);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return howmany;
|
|
|
|
}
|
|
|
|
|
2014-03-07 20:42:45 +08:00
|
|
|
static int gfar_poll_rx_sq(struct napi_struct *napi, int budget)
|
2013-06-11 01:19:48 +08:00
|
|
|
{
|
|
|
|
struct gfar_priv_grp *gfargrp =
|
2014-03-07 20:42:45 +08:00
|
|
|
container_of(napi, struct gfar_priv_grp, napi_rx);
|
2013-06-11 01:19:48 +08:00
|
|
|
struct gfar __iomem *regs = gfargrp->regs;
|
gianfar: Use Single-Queue polling for "fsl,etsec2"
For the "fsl,etsec2" compatible models the driver currently
supports 8 Tx and Rx DMA rings (aka HW queues). However, there
are only 2 pairs of Rx/Tx interrupt lines, as these controllers
are integrated in low power SoCs with 2 CPUs at most. As a result,
there are at most 2 NAPI instances that have to service multiple
Tx and Rx queues for these devices. This complicates the NAPI
polling routine having to iterate over the mutiple Rx/Tx queues
hooked to the same interrupt lines. And there's also an overhead
at HW level, as the controller needs to service all the 8 Tx rings
in a round robin manner. The combined overhead shows up for multi
parallel Tx flows transmitted by the kernel stack, when the driver
usually starts returning NETDEV_TX_BUSY leading to NETDEV WATCHDOG
Tx timeout triggering if the Tx path is congested for too long.
As an alternative, this patch makes the driver support only one
Tx/Rx DMA ring per NAPI instance (per interrupt group or pair
of Tx/Rx interrupt lines) by default. The simplified single queue
polling routine (gfar_poll_sq) will be the default napi poll routine
for the etsec2 devices too. Some adjustments needed to be made to
link the Tx/Rx HW queues with each NAPI instance (2 in this case).
The gfar_poll_sq() is already successfully used by older SQ_SG_MODE
(single interrupt group) controllers.
This patch fixes Tx timeout triggering under heavy Tx traffic load
(i.e. iperf -c -P 8) for the "fsl,etsec2" (currently the only
MQ_MG_MODE devices). There's also a significant memory footprint
reduction by supporting 2 Rx/Tx DMA rings (at most), instead of 8,
for these devices.
Signed-off-by: Claudiu Manoil <claudiu.manoil@freescale.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-03-07 20:42:46 +08:00
|
|
|
struct gfar_priv_rx_q *rx_queue = gfargrp->rx_queue;
|
2013-06-11 01:19:48 +08:00
|
|
|
int work_done = 0;
|
|
|
|
|
|
|
|
/* Clear IEVENT, so interrupts aren't called again
|
|
|
|
* because of the packets that have already arrived
|
|
|
|
*/
|
2014-03-07 20:42:45 +08:00
|
|
|
gfar_write(®s->ievent, IEVENT_RX_MASK);
|
2013-06-11 01:19:48 +08:00
|
|
|
|
|
|
|
work_done = gfar_clean_rx_ring(rx_queue, budget);
|
|
|
|
|
|
|
|
if (work_done < budget) {
|
2014-03-07 20:42:45 +08:00
|
|
|
u32 imask;
|
2017-01-31 00:22:01 +08:00
|
|
|
napi_complete_done(napi, work_done);
|
2013-06-11 01:19:48 +08:00
|
|
|
/* Clear the halt bit in RSTAT */
|
|
|
|
gfar_write(®s->rstat, gfargrp->rstat);
|
|
|
|
|
2014-03-07 20:42:45 +08:00
|
|
|
spin_lock_irq(&gfargrp->grplock);
|
|
|
|
imask = gfar_read(®s->imask);
|
|
|
|
imask |= IMASK_RX_DEFAULT;
|
|
|
|
gfar_write(®s->imask, imask);
|
|
|
|
spin_unlock_irq(&gfargrp->grplock);
|
2013-06-11 01:19:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return work_done;
|
|
|
|
}
|
|
|
|
|
2014-03-07 20:42:45 +08:00
|
|
|
static int gfar_poll_tx_sq(struct napi_struct *napi, int budget)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2012-06-05 11:42:13 +08:00
|
|
|
struct gfar_priv_grp *gfargrp =
|
2014-03-07 20:42:45 +08:00
|
|
|
container_of(napi, struct gfar_priv_grp, napi_tx);
|
|
|
|
struct gfar __iomem *regs = gfargrp->regs;
|
gianfar: Use Single-Queue polling for "fsl,etsec2"
For the "fsl,etsec2" compatible models the driver currently
supports 8 Tx and Rx DMA rings (aka HW queues). However, there
are only 2 pairs of Rx/Tx interrupt lines, as these controllers
are integrated in low power SoCs with 2 CPUs at most. As a result,
there are at most 2 NAPI instances that have to service multiple
Tx and Rx queues for these devices. This complicates the NAPI
polling routine having to iterate over the mutiple Rx/Tx queues
hooked to the same interrupt lines. And there's also an overhead
at HW level, as the controller needs to service all the 8 Tx rings
in a round robin manner. The combined overhead shows up for multi
parallel Tx flows transmitted by the kernel stack, when the driver
usually starts returning NETDEV_TX_BUSY leading to NETDEV WATCHDOG
Tx timeout triggering if the Tx path is congested for too long.
As an alternative, this patch makes the driver support only one
Tx/Rx DMA ring per NAPI instance (per interrupt group or pair
of Tx/Rx interrupt lines) by default. The simplified single queue
polling routine (gfar_poll_sq) will be the default napi poll routine
for the etsec2 devices too. Some adjustments needed to be made to
link the Tx/Rx HW queues with each NAPI instance (2 in this case).
The gfar_poll_sq() is already successfully used by older SQ_SG_MODE
(single interrupt group) controllers.
This patch fixes Tx timeout triggering under heavy Tx traffic load
(i.e. iperf -c -P 8) for the "fsl,etsec2" (currently the only
MQ_MG_MODE devices). There's also a significant memory footprint
reduction by supporting 2 Rx/Tx DMA rings (at most), instead of 8,
for these devices.
Signed-off-by: Claudiu Manoil <claudiu.manoil@freescale.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-03-07 20:42:46 +08:00
|
|
|
struct gfar_priv_tx_q *tx_queue = gfargrp->tx_queue;
|
2014-03-07 20:42:45 +08:00
|
|
|
u32 imask;
|
|
|
|
|
|
|
|
/* Clear IEVENT, so interrupts aren't called again
|
|
|
|
* because of the packets that have already arrived
|
|
|
|
*/
|
|
|
|
gfar_write(®s->ievent, IEVENT_TX_MASK);
|
|
|
|
|
|
|
|
/* run Tx cleanup to completion */
|
|
|
|
if (tx_queue->tx_skbuff[tx_queue->skb_dirtytx])
|
|
|
|
gfar_clean_tx_ring(tx_queue);
|
|
|
|
|
|
|
|
napi_complete(napi);
|
|
|
|
|
|
|
|
spin_lock_irq(&gfargrp->grplock);
|
|
|
|
imask = gfar_read(®s->imask);
|
|
|
|
imask |= IMASK_TX_DEFAULT;
|
|
|
|
gfar_write(®s->imask, imask);
|
|
|
|
spin_unlock_irq(&gfargrp->grplock);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
/* GFAR error interrupt handler */
|
|
|
|
static irqreturn_t gfar_error(int irq, void *grp_id)
|
|
|
|
{
|
|
|
|
struct gfar_priv_grp *gfargrp = grp_id;
|
|
|
|
struct gfar __iomem *regs = gfargrp->regs;
|
|
|
|
struct gfar_private *priv= gfargrp->priv;
|
|
|
|
struct net_device *dev = priv->ndev;
|
|
|
|
|
|
|
|
/* Save ievent for future reference */
|
|
|
|
u32 events = gfar_read(®s->ievent);
|
|
|
|
|
|
|
|
/* Clear IEVENT */
|
|
|
|
gfar_write(®s->ievent, events & IEVENT_ERR_MASK);
|
|
|
|
|
|
|
|
/* Magic Packet is not an error. */
|
|
|
|
if ((priv->device_flags & FSL_GIANFAR_DEV_HAS_MAGIC_PACKET) &&
|
|
|
|
(events & IEVENT_MAG))
|
|
|
|
events &= ~IEVENT_MAG;
|
|
|
|
|
|
|
|
/* Hmm... */
|
|
|
|
if (netif_msg_rx_err(priv) || netif_msg_tx_err(priv))
|
|
|
|
netdev_dbg(dev,
|
|
|
|
"error interrupt (ievent=0x%08x imask=0x%08x)\n",
|
|
|
|
events, gfar_read(®s->imask));
|
|
|
|
|
|
|
|
/* Update the error counters */
|
|
|
|
if (events & IEVENT_TXE) {
|
|
|
|
dev->stats.tx_errors++;
|
|
|
|
|
|
|
|
if (events & IEVENT_LC)
|
|
|
|
dev->stats.tx_window_errors++;
|
|
|
|
if (events & IEVENT_CRL)
|
|
|
|
dev->stats.tx_aborted_errors++;
|
|
|
|
if (events & IEVENT_XFUN) {
|
|
|
|
netif_dbg(priv, tx_err, dev,
|
|
|
|
"TX FIFO underrun, packet dropped\n");
|
|
|
|
dev->stats.tx_dropped++;
|
|
|
|
atomic64_inc(&priv->extra_stats.tx_underrun);
|
|
|
|
|
|
|
|
schedule_work(&priv->reset_task);
|
|
|
|
}
|
|
|
|
netif_dbg(priv, tx_err, dev, "Transmit Error\n");
|
|
|
|
}
|
2021-06-17 17:49:28 +08:00
|
|
|
if (events & IEVENT_MSRO) {
|
|
|
|
struct rmon_mib __iomem *rmon = ®s->rmon;
|
|
|
|
u32 car;
|
|
|
|
|
|
|
|
spin_lock(&priv->rmon_overflow.lock);
|
|
|
|
car = gfar_read(&rmon->car1) & CAR1_C1RDR;
|
|
|
|
if (car) {
|
|
|
|
priv->rmon_overflow.rdrp++;
|
|
|
|
gfar_write(&rmon->car1, car);
|
|
|
|
}
|
|
|
|
spin_unlock(&priv->rmon_overflow.lock);
|
|
|
|
}
|
2019-09-04 21:52:19 +08:00
|
|
|
if (events & IEVENT_BSY) {
|
|
|
|
dev->stats.rx_over_errors++;
|
|
|
|
atomic64_inc(&priv->extra_stats.rx_bsy);
|
|
|
|
|
|
|
|
netif_dbg(priv, rx_err, dev, "busy error (rstat: %x)\n",
|
|
|
|
gfar_read(®s->rstat));
|
|
|
|
}
|
|
|
|
if (events & IEVENT_BABR) {
|
|
|
|
dev->stats.rx_errors++;
|
|
|
|
atomic64_inc(&priv->extra_stats.rx_babr);
|
|
|
|
|
|
|
|
netif_dbg(priv, rx_err, dev, "babbling RX error\n");
|
|
|
|
}
|
|
|
|
if (events & IEVENT_EBERR) {
|
|
|
|
atomic64_inc(&priv->extra_stats.eberr);
|
|
|
|
netif_dbg(priv, rx_err, dev, "bus error\n");
|
|
|
|
}
|
|
|
|
if (events & IEVENT_RXC)
|
|
|
|
netif_dbg(priv, rx_status, dev, "control frame\n");
|
|
|
|
|
|
|
|
if (events & IEVENT_BABT) {
|
|
|
|
atomic64_inc(&priv->extra_stats.tx_babt);
|
|
|
|
netif_dbg(priv, tx_err, dev, "babbling TX error\n");
|
|
|
|
}
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The interrupt handler for devices with one interrupt */
|
|
|
|
static irqreturn_t gfar_interrupt(int irq, void *grp_id)
|
|
|
|
{
|
|
|
|
struct gfar_priv_grp *gfargrp = grp_id;
|
|
|
|
|
|
|
|
/* Save ievent for future reference */
|
|
|
|
u32 events = gfar_read(&gfargrp->regs->ievent);
|
|
|
|
|
|
|
|
/* Check for reception */
|
|
|
|
if (events & IEVENT_RX_MASK)
|
|
|
|
gfar_receive(irq, grp_id);
|
|
|
|
|
|
|
|
/* Check for transmit completion */
|
|
|
|
if (events & IEVENT_TX_MASK)
|
|
|
|
gfar_transmit(irq, grp_id);
|
|
|
|
|
|
|
|
/* Check for errors */
|
|
|
|
if (events & IEVENT_ERR_MASK)
|
|
|
|
gfar_error(irq, grp_id);
|
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
2014-03-07 20:42:45 +08:00
|
|
|
|
2006-11-07 18:27:02 +08:00
|
|
|
#ifdef CONFIG_NET_POLL_CONTROLLER
|
2012-06-05 11:42:12 +08:00
|
|
|
/* Polling 'interrupt' - used by things like netconsole to send skbs
|
2006-11-07 18:27:02 +08:00
|
|
|
* without having to re-enable interrupts. It's not called while
|
|
|
|
* the interrupt routine is executing.
|
|
|
|
*/
|
|
|
|
static void gfar_netpoll(struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct gfar_private *priv = netdev_priv(dev);
|
2012-06-05 11:42:14 +08:00
|
|
|
int i;
|
2006-11-07 18:27:02 +08:00
|
|
|
|
|
|
|
/* If the device has multiple interrupts, run tx/rx */
|
2008-12-17 07:29:15 +08:00
|
|
|
if (priv->device_flags & FSL_GIANFAR_DEV_HAS_MULTI_INTR) {
|
2009-11-02 15:03:34 +08:00
|
|
|
for (i = 0; i < priv->num_grps; i++) {
|
2013-02-24 13:38:31 +08:00
|
|
|
struct gfar_priv_grp *grp = &priv->gfargrp[i];
|
|
|
|
|
|
|
|
disable_irq(gfar_irq(grp, TX)->irq);
|
|
|
|
disable_irq(gfar_irq(grp, RX)->irq);
|
|
|
|
disable_irq(gfar_irq(grp, ER)->irq);
|
|
|
|
gfar_interrupt(gfar_irq(grp, TX)->irq, grp);
|
|
|
|
enable_irq(gfar_irq(grp, ER)->irq);
|
|
|
|
enable_irq(gfar_irq(grp, RX)->irq);
|
|
|
|
enable_irq(gfar_irq(grp, TX)->irq);
|
2009-11-02 15:03:34 +08:00
|
|
|
}
|
2006-11-07 18:27:02 +08:00
|
|
|
} else {
|
2009-11-02 15:03:34 +08:00
|
|
|
for (i = 0; i < priv->num_grps; i++) {
|
2013-02-24 13:38:31 +08:00
|
|
|
struct gfar_priv_grp *grp = &priv->gfargrp[i];
|
|
|
|
|
|
|
|
disable_irq(gfar_irq(grp, TX)->irq);
|
|
|
|
gfar_interrupt(gfar_irq(grp, TX)->irq, grp);
|
|
|
|
enable_irq(gfar_irq(grp, TX)->irq);
|
2009-12-09 18:52:19 +08:00
|
|
|
}
|
2006-11-07 18:27:02 +08:00
|
|
|
}
|
|
|
|
}
|
2019-09-04 21:52:19 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
static void free_grp_irqs(struct gfar_priv_grp *grp)
|
|
|
|
{
|
|
|
|
free_irq(gfar_irq(grp, TX)->irq, grp);
|
|
|
|
free_irq(gfar_irq(grp, RX)->irq, grp);
|
|
|
|
free_irq(gfar_irq(grp, ER)->irq, grp);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int register_grp_irqs(struct gfar_priv_grp *grp)
|
|
|
|
{
|
|
|
|
struct gfar_private *priv = grp->priv;
|
|
|
|
struct net_device *dev = priv->ndev;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
/* If the device has multiple interrupts, register for
|
|
|
|
* them. Otherwise, only register for the one
|
|
|
|
*/
|
|
|
|
if (priv->device_flags & FSL_GIANFAR_DEV_HAS_MULTI_INTR) {
|
|
|
|
/* Install our interrupt handlers for Error,
|
|
|
|
* Transmit, and Receive
|
|
|
|
*/
|
|
|
|
err = request_irq(gfar_irq(grp, ER)->irq, gfar_error, 0,
|
|
|
|
gfar_irq(grp, ER)->name, grp);
|
|
|
|
if (err < 0) {
|
|
|
|
netif_err(priv, intr, dev, "Can't get IRQ %d\n",
|
|
|
|
gfar_irq(grp, ER)->irq);
|
|
|
|
|
|
|
|
goto err_irq_fail;
|
|
|
|
}
|
|
|
|
enable_irq_wake(gfar_irq(grp, ER)->irq);
|
|
|
|
|
|
|
|
err = request_irq(gfar_irq(grp, TX)->irq, gfar_transmit, 0,
|
|
|
|
gfar_irq(grp, TX)->name, grp);
|
|
|
|
if (err < 0) {
|
|
|
|
netif_err(priv, intr, dev, "Can't get IRQ %d\n",
|
|
|
|
gfar_irq(grp, TX)->irq);
|
|
|
|
goto tx_irq_fail;
|
|
|
|
}
|
|
|
|
err = request_irq(gfar_irq(grp, RX)->irq, gfar_receive, 0,
|
|
|
|
gfar_irq(grp, RX)->name, grp);
|
|
|
|
if (err < 0) {
|
|
|
|
netif_err(priv, intr, dev, "Can't get IRQ %d\n",
|
|
|
|
gfar_irq(grp, RX)->irq);
|
|
|
|
goto rx_irq_fail;
|
|
|
|
}
|
|
|
|
enable_irq_wake(gfar_irq(grp, RX)->irq);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
err = request_irq(gfar_irq(grp, TX)->irq, gfar_interrupt, 0,
|
|
|
|
gfar_irq(grp, TX)->name, grp);
|
|
|
|
if (err < 0) {
|
|
|
|
netif_err(priv, intr, dev, "Can't get IRQ %d\n",
|
|
|
|
gfar_irq(grp, TX)->irq);
|
|
|
|
goto err_irq_fail;
|
|
|
|
}
|
|
|
|
enable_irq_wake(gfar_irq(grp, TX)->irq);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
rx_irq_fail:
|
|
|
|
free_irq(gfar_irq(grp, TX)->irq, grp);
|
|
|
|
tx_irq_fail:
|
|
|
|
free_irq(gfar_irq(grp, ER)->irq, grp);
|
|
|
|
err_irq_fail:
|
|
|
|
return err;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gfar_free_irq(struct gfar_private *priv)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Free the IRQs */
|
|
|
|
if (priv->device_flags & FSL_GIANFAR_DEV_HAS_MULTI_INTR) {
|
|
|
|
for (i = 0; i < priv->num_grps; i++)
|
|
|
|
free_grp_irqs(&priv->gfargrp[i]);
|
|
|
|
} else {
|
|
|
|
for (i = 0; i < priv->num_grps; i++)
|
|
|
|
free_irq(gfar_irq(&priv->gfargrp[i], TX)->irq,
|
|
|
|
&priv->gfargrp[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int gfar_request_irq(struct gfar_private *priv)
|
|
|
|
{
|
|
|
|
int err, i, j;
|
|
|
|
|
|
|
|
for (i = 0; i < priv->num_grps; i++) {
|
|
|
|
err = register_grp_irqs(&priv->gfargrp[i]);
|
|
|
|
if (err) {
|
|
|
|
for (j = 0; j < i; j++)
|
|
|
|
free_grp_irqs(&priv->gfargrp[j]);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Called when something needs to use the ethernet device
|
|
|
|
* Returns 0 for success.
|
|
|
|
*/
|
|
|
|
static int gfar_enet_open(struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct gfar_private *priv = netdev_priv(dev);
|
|
|
|
int err;
|
|
|
|
|
|
|
|
err = init_phy(dev);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
err = gfar_request_irq(priv);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
err = startup_gfar(dev);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Stops the kernel queue, and halts the controller */
|
|
|
|
static int gfar_close(struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct gfar_private *priv = netdev_priv(dev);
|
|
|
|
|
|
|
|
cancel_work_sync(&priv->reset_task);
|
|
|
|
stop_gfar(dev);
|
|
|
|
|
|
|
|
/* Disconnect from the PHY */
|
|
|
|
phy_disconnect(dev->phydev);
|
|
|
|
|
|
|
|
gfar_free_irq(priv);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Clears each of the exact match registers to zero, so they
|
|
|
|
* don't interfere with normal reception
|
|
|
|
*/
|
|
|
|
static void gfar_clear_exact_match(struct net_device *dev)
|
|
|
|
{
|
|
|
|
int idx;
|
|
|
|
static const u8 zero_arr[ETH_ALEN] = {0, 0, 0, 0, 0, 0};
|
|
|
|
|
|
|
|
for (idx = 1; idx < GFAR_EM_NUM + 1; idx++)
|
|
|
|
gfar_set_mac_for_addr(dev, idx, zero_arr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Update the hash table based on the current list of multicast
|
|
|
|
* addresses we subscribe to. Also, change the promiscuity of
|
|
|
|
* the device based on the flags (this function is called
|
|
|
|
* whenever dev->flags is changed
|
|
|
|
*/
|
|
|
|
static void gfar_set_multi(struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct netdev_hw_addr *ha;
|
|
|
|
struct gfar_private *priv = netdev_priv(dev);
|
|
|
|
struct gfar __iomem *regs = priv->gfargrp[0].regs;
|
|
|
|
u32 tempval;
|
|
|
|
|
|
|
|
if (dev->flags & IFF_PROMISC) {
|
|
|
|
/* Set RCTRL to PROM */
|
|
|
|
tempval = gfar_read(®s->rctrl);
|
|
|
|
tempval |= RCTRL_PROM;
|
|
|
|
gfar_write(®s->rctrl, tempval);
|
|
|
|
} else {
|
|
|
|
/* Set RCTRL to not PROM */
|
|
|
|
tempval = gfar_read(®s->rctrl);
|
|
|
|
tempval &= ~(RCTRL_PROM);
|
|
|
|
gfar_write(®s->rctrl, tempval);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dev->flags & IFF_ALLMULTI) {
|
|
|
|
/* Set the hash to rx all multicast frames */
|
|
|
|
gfar_write(®s->igaddr0, 0xffffffff);
|
|
|
|
gfar_write(®s->igaddr1, 0xffffffff);
|
|
|
|
gfar_write(®s->igaddr2, 0xffffffff);
|
|
|
|
gfar_write(®s->igaddr3, 0xffffffff);
|
|
|
|
gfar_write(®s->igaddr4, 0xffffffff);
|
|
|
|
gfar_write(®s->igaddr5, 0xffffffff);
|
|
|
|
gfar_write(®s->igaddr6, 0xffffffff);
|
|
|
|
gfar_write(®s->igaddr7, 0xffffffff);
|
|
|
|
gfar_write(®s->gaddr0, 0xffffffff);
|
|
|
|
gfar_write(®s->gaddr1, 0xffffffff);
|
|
|
|
gfar_write(®s->gaddr2, 0xffffffff);
|
|
|
|
gfar_write(®s->gaddr3, 0xffffffff);
|
|
|
|
gfar_write(®s->gaddr4, 0xffffffff);
|
|
|
|
gfar_write(®s->gaddr5, 0xffffffff);
|
|
|
|
gfar_write(®s->gaddr6, 0xffffffff);
|
|
|
|
gfar_write(®s->gaddr7, 0xffffffff);
|
|
|
|
} else {
|
|
|
|
int em_num;
|
|
|
|
int idx;
|
|
|
|
|
|
|
|
/* zero out the hash */
|
|
|
|
gfar_write(®s->igaddr0, 0x0);
|
|
|
|
gfar_write(®s->igaddr1, 0x0);
|
|
|
|
gfar_write(®s->igaddr2, 0x0);
|
|
|
|
gfar_write(®s->igaddr3, 0x0);
|
|
|
|
gfar_write(®s->igaddr4, 0x0);
|
|
|
|
gfar_write(®s->igaddr5, 0x0);
|
|
|
|
gfar_write(®s->igaddr6, 0x0);
|
|
|
|
gfar_write(®s->igaddr7, 0x0);
|
|
|
|
gfar_write(®s->gaddr0, 0x0);
|
|
|
|
gfar_write(®s->gaddr1, 0x0);
|
|
|
|
gfar_write(®s->gaddr2, 0x0);
|
|
|
|
gfar_write(®s->gaddr3, 0x0);
|
|
|
|
gfar_write(®s->gaddr4, 0x0);
|
|
|
|
gfar_write(®s->gaddr5, 0x0);
|
|
|
|
gfar_write(®s->gaddr6, 0x0);
|
|
|
|
gfar_write(®s->gaddr7, 0x0);
|
|
|
|
|
|
|
|
/* If we have extended hash tables, we need to
|
|
|
|
* clear the exact match registers to prepare for
|
|
|
|
* setting them
|
|
|
|
*/
|
|
|
|
if (priv->extended_hash) {
|
|
|
|
em_num = GFAR_EM_NUM + 1;
|
|
|
|
gfar_clear_exact_match(dev);
|
|
|
|
idx = 1;
|
|
|
|
} else {
|
|
|
|
idx = 0;
|
|
|
|
em_num = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (netdev_mc_empty(dev))
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Parse the list, and set the appropriate bits */
|
|
|
|
netdev_for_each_mc_addr(ha, dev) {
|
|
|
|
if (idx < em_num) {
|
|
|
|
gfar_set_mac_for_addr(dev, idx, ha->addr);
|
|
|
|
idx++;
|
|
|
|
} else
|
|
|
|
gfar_set_hash_for_addr(dev, ha->addr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void gfar_mac_reset(struct gfar_private *priv)
|
|
|
|
{
|
|
|
|
struct gfar __iomem *regs = priv->gfargrp[0].regs;
|
|
|
|
u32 tempval;
|
|
|
|
|
|
|
|
/* Reset MAC layer */
|
|
|
|
gfar_write(®s->maccfg1, MACCFG1_SOFT_RESET);
|
|
|
|
|
|
|
|
/* We need to delay at least 3 TX clocks */
|
|
|
|
udelay(3);
|
|
|
|
|
|
|
|
/* the soft reset bit is not self-resetting, so we need to
|
|
|
|
* clear it before resuming normal operation
|
|
|
|
*/
|
|
|
|
gfar_write(®s->maccfg1, 0);
|
|
|
|
|
|
|
|
udelay(3);
|
|
|
|
|
|
|
|
gfar_rx_offload_en(priv);
|
|
|
|
|
|
|
|
/* Initialize the max receive frame/buffer lengths */
|
|
|
|
gfar_write(®s->maxfrm, GFAR_JUMBO_FRAME_SIZE);
|
|
|
|
gfar_write(®s->mrblr, GFAR_RXB_SIZE);
|
|
|
|
|
|
|
|
/* Initialize the Minimum Frame Length Register */
|
|
|
|
gfar_write(®s->minflr, MINFLR_INIT_SETTINGS);
|
|
|
|
|
|
|
|
/* Initialize MACCFG2. */
|
|
|
|
tempval = MACCFG2_INIT_SETTINGS;
|
|
|
|
|
|
|
|
/* eTSEC74 erratum: Rx frames of length MAXFRM or MAXFRM-1
|
|
|
|
* are marked as truncated. Avoid this by MACCFG2[Huge Frame]=1,
|
|
|
|
* and by checking RxBD[LG] and discarding larger than MAXFRM.
|
|
|
|
*/
|
|
|
|
if (gfar_has_errata(priv, GFAR_ERRATA_74))
|
|
|
|
tempval |= MACCFG2_HUGEFRAME | MACCFG2_LENGTHCHECK;
|
|
|
|
|
|
|
|
gfar_write(®s->maccfg2, tempval);
|
|
|
|
|
|
|
|
/* Clear mac addr hash registers */
|
|
|
|
gfar_write(®s->igaddr0, 0);
|
|
|
|
gfar_write(®s->igaddr1, 0);
|
|
|
|
gfar_write(®s->igaddr2, 0);
|
|
|
|
gfar_write(®s->igaddr3, 0);
|
|
|
|
gfar_write(®s->igaddr4, 0);
|
|
|
|
gfar_write(®s->igaddr5, 0);
|
|
|
|
gfar_write(®s->igaddr6, 0);
|
|
|
|
gfar_write(®s->igaddr7, 0);
|
|
|
|
|
|
|
|
gfar_write(®s->gaddr0, 0);
|
|
|
|
gfar_write(®s->gaddr1, 0);
|
|
|
|
gfar_write(®s->gaddr2, 0);
|
|
|
|
gfar_write(®s->gaddr3, 0);
|
|
|
|
gfar_write(®s->gaddr4, 0);
|
|
|
|
gfar_write(®s->gaddr5, 0);
|
|
|
|
gfar_write(®s->gaddr6, 0);
|
|
|
|
gfar_write(®s->gaddr7, 0);
|
|
|
|
|
|
|
|
if (priv->extended_hash)
|
|
|
|
gfar_clear_exact_match(priv->ndev);
|
|
|
|
|
|
|
|
gfar_mac_rx_config(priv);
|
|
|
|
|
|
|
|
gfar_mac_tx_config(priv);
|
|
|
|
|
|
|
|
gfar_set_mac_address(priv->ndev);
|
|
|
|
|
|
|
|
gfar_set_multi(priv->ndev);
|
|
|
|
|
|
|
|
/* clear ievent and imask before configuring coalescing */
|
|
|
|
gfar_ints_disable(priv);
|
|
|
|
|
|
|
|
/* Configure the coalescing support */
|
|
|
|
gfar_configure_coalescing_all(priv);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gfar_hw_init(struct gfar_private *priv)
|
|
|
|
{
|
|
|
|
struct gfar __iomem *regs = priv->gfargrp[0].regs;
|
|
|
|
u32 attrs;
|
|
|
|
|
|
|
|
/* Stop the DMA engine now, in case it was running before
|
|
|
|
* (The firmware could have used it, and left it running).
|
|
|
|
*/
|
|
|
|
gfar_halt(priv);
|
|
|
|
|
|
|
|
gfar_mac_reset(priv);
|
|
|
|
|
|
|
|
/* Zero out the rmon mib registers if it has them */
|
|
|
|
if (priv->device_flags & FSL_GIANFAR_DEV_HAS_RMON) {
|
2021-06-17 17:49:23 +08:00
|
|
|
memset_io(®s->rmon, 0, offsetof(struct rmon_mib, car1));
|
2019-09-04 21:52:19 +08:00
|
|
|
|
|
|
|
/* Mask off the CAM interrupts */
|
|
|
|
gfar_write(®s->rmon.cam1, 0xffffffff);
|
|
|
|
gfar_write(®s->rmon.cam2, 0xffffffff);
|
2021-06-17 17:49:20 +08:00
|
|
|
/* Clear the CAR registers (w1c style) */
|
|
|
|
gfar_write(®s->rmon.car1, 0xffffffff);
|
|
|
|
gfar_write(®s->rmon.car2, 0xffffffff);
|
2019-09-04 21:52:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize ECNTRL */
|
|
|
|
gfar_write(®s->ecntrl, ECNTRL_INIT_SETTINGS);
|
|
|
|
|
|
|
|
/* Set the extraction length and index */
|
|
|
|
attrs = ATTRELI_EL(priv->rx_stash_size) |
|
|
|
|
ATTRELI_EI(priv->rx_stash_index);
|
|
|
|
|
|
|
|
gfar_write(®s->attreli, attrs);
|
|
|
|
|
|
|
|
/* Start with defaults, and add stashing
|
|
|
|
* depending on driver parameters
|
|
|
|
*/
|
|
|
|
attrs = ATTR_INIT_SETTINGS;
|
|
|
|
|
|
|
|
if (priv->bd_stash_en)
|
|
|
|
attrs |= ATTR_BDSTASH;
|
|
|
|
|
|
|
|
if (priv->rx_stash_size != 0)
|
|
|
|
attrs |= ATTR_BUFSTASH;
|
|
|
|
|
|
|
|
gfar_write(®s->attr, attrs);
|
|
|
|
|
|
|
|
/* FIFO configs */
|
|
|
|
gfar_write(®s->fifo_tx_thr, DEFAULT_FIFO_TX_THR);
|
|
|
|
gfar_write(®s->fifo_tx_starve, DEFAULT_FIFO_TX_STARVE);
|
|
|
|
gfar_write(®s->fifo_tx_starve_shutoff, DEFAULT_FIFO_TX_STARVE_OFF);
|
|
|
|
|
|
|
|
/* Program the interrupt steering regs, only for MG devices */
|
|
|
|
if (priv->num_grps > 1)
|
|
|
|
gfar_write_isrg(priv);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct net_device_ops gfar_netdev_ops = {
|
|
|
|
.ndo_open = gfar_enet_open,
|
|
|
|
.ndo_start_xmit = gfar_start_xmit,
|
|
|
|
.ndo_stop = gfar_close,
|
|
|
|
.ndo_change_mtu = gfar_change_mtu,
|
|
|
|
.ndo_set_features = gfar_set_features,
|
|
|
|
.ndo_set_rx_mode = gfar_set_multi,
|
|
|
|
.ndo_tx_timeout = gfar_timeout,
|
2021-07-27 21:45:13 +08:00
|
|
|
.ndo_eth_ioctl = gfar_ioctl,
|
2021-06-17 17:49:15 +08:00
|
|
|
.ndo_get_stats64 = gfar_get_stats64,
|
2019-09-04 21:52:19 +08:00
|
|
|
.ndo_change_carrier = fixed_phy_change_carrier,
|
|
|
|
.ndo_set_mac_address = gfar_set_mac_addr,
|
|
|
|
.ndo_validate_addr = eth_validate_addr,
|
|
|
|
#ifdef CONFIG_NET_POLL_CONTROLLER
|
|
|
|
.ndo_poll_controller = gfar_netpoll,
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Set up the ethernet device structure, private data,
|
|
|
|
* and anything else we need before we start
|
|
|
|
*/
|
|
|
|
static int gfar_probe(struct platform_device *ofdev)
|
|
|
|
{
|
|
|
|
struct device_node *np = ofdev->dev.of_node;
|
|
|
|
struct net_device *dev = NULL;
|
|
|
|
struct gfar_private *priv = NULL;
|
|
|
|
int err = 0, i;
|
|
|
|
|
|
|
|
err = gfar_of_init(ofdev, &dev);
|
|
|
|
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
priv = netdev_priv(dev);
|
|
|
|
priv->ndev = dev;
|
|
|
|
priv->ofdev = ofdev;
|
|
|
|
priv->dev = &ofdev->dev;
|
|
|
|
SET_NETDEV_DEV(dev, &ofdev->dev);
|
|
|
|
|
|
|
|
INIT_WORK(&priv->reset_task, gfar_reset_task);
|
|
|
|
|
|
|
|
platform_set_drvdata(ofdev, priv);
|
|
|
|
|
|
|
|
gfar_detect_errata(priv);
|
|
|
|
|
|
|
|
/* Set the dev->base_addr to the gfar reg region */
|
|
|
|
dev->base_addr = (unsigned long) priv->gfargrp[0].regs;
|
|
|
|
|
|
|
|
/* Fill in the dev structure */
|
|
|
|
dev->watchdog_timeo = TX_TIMEOUT;
|
|
|
|
/* MTU range: 50 - 9586 */
|
|
|
|
dev->mtu = 1500;
|
|
|
|
dev->min_mtu = 50;
|
|
|
|
dev->max_mtu = GFAR_JUMBO_FRAME_SIZE - ETH_HLEN;
|
|
|
|
dev->netdev_ops = &gfar_netdev_ops;
|
|
|
|
dev->ethtool_ops = &gfar_ethtool_ops;
|
|
|
|
|
|
|
|
/* Register for napi ...We are registering NAPI for each grp */
|
|
|
|
for (i = 0; i < priv->num_grps; i++) {
|
gianfar: Drop GFAR_MQ_POLLING support
Gianfar used to enable all 8 Rx queues (DMA rings) per
ethernet device, even though the controller can only
support 2 interrupt lines at most. This meant that
multiple Rx queues would have to be grouped per NAPI poll
routine, and the CPU would have to split the budget and
service them in a round robin manner. The overhead of
this scheme proved to outweight the potential benefits.
The alternative was to introduce the "Single Queue" polling
mode, supporting one Rx queue per NAPI, which became the
default packet processing option and helped improve the
performance of the driver.
MQ_POLLING also relies on undocumeted device tree properties
to specify how to map the 8 Rx and Tx queues to a given
interrupt line (aka "interrupt group"). Using module parameters
to enable this mode wasn't an option either. Long story short,
MQ_POLLING became obsolete, now it is just dead code, and no
one asked for it so far.
For the Tx queues, multi-queue support (more than 1 Tx queue
per CPU) could be revisited by adding tc MQPRIO support, but
again, one has to consider that there are only 2 interrupt lines.
So the NAPI poll routine would have to service multiple Tx rings.
Signed-off-by: Claudiu Manoil <claudiu.manoil@nxp.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2021-04-17 01:11:22 +08:00
|
|
|
netif_napi_add(dev, &priv->gfargrp[i].napi_rx,
|
|
|
|
gfar_poll_rx_sq, GFAR_DEV_WEIGHT);
|
|
|
|
netif_tx_napi_add(dev, &priv->gfargrp[i].napi_tx,
|
|
|
|
gfar_poll_tx_sq, 2);
|
2019-09-04 21:52:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (priv->device_flags & FSL_GIANFAR_DEV_HAS_CSUM) {
|
|
|
|
dev->hw_features = NETIF_F_IP_CSUM | NETIF_F_SG |
|
|
|
|
NETIF_F_RXCSUM;
|
|
|
|
dev->features |= NETIF_F_IP_CSUM | NETIF_F_SG |
|
|
|
|
NETIF_F_RXCSUM | NETIF_F_HIGHDMA;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (priv->device_flags & FSL_GIANFAR_DEV_HAS_VLAN) {
|
|
|
|
dev->hw_features |= NETIF_F_HW_VLAN_CTAG_TX |
|
|
|
|
NETIF_F_HW_VLAN_CTAG_RX;
|
|
|
|
dev->features |= NETIF_F_HW_VLAN_CTAG_RX;
|
|
|
|
}
|
|
|
|
|
|
|
|
dev->priv_flags |= IFF_LIVE_ADDR_CHANGE;
|
|
|
|
|
|
|
|
gfar_init_addr_hash_table(priv);
|
|
|
|
|
|
|
|
/* Insert receive time stamps into padding alignment bytes, and
|
|
|
|
* plus 2 bytes padding to ensure the cpu alignment.
|
|
|
|
*/
|
|
|
|
if (priv->device_flags & FSL_GIANFAR_DEV_HAS_TIMER)
|
|
|
|
priv->padding = 8 + DEFAULT_PADDING;
|
|
|
|
|
|
|
|
if (dev->features & NETIF_F_IP_CSUM ||
|
|
|
|
priv->device_flags & FSL_GIANFAR_DEV_HAS_TIMER)
|
gianfar: Account for Tx PTP timestamp in the skb headroom
When PTP timestamping is enabled on Tx, the controller
inserts the Tx timestamp at the beginning of the frame
buffer, between SFD and the L2 frame header. This means
that the skb provided by the stack is required to have
enough headroom otherwise a new skb needs to be created
by the driver to accommodate the timestamp inserted by h/w.
Up until now the driver was relying on the second option,
using skb_realloc_headroom() to create a new skb to accommodate
PTP frames. Turns out that this method is not reliable, as
reallocation of skbs for PTP frames along with the required
overhead (skb_set_owner_w, consume_skb) is causing random
crashes in subsequent skb_*() calls, when multiple concurrent
TCP streams are run at the same time on the same device
(as seen in James' report).
Note that these crashes don't occur with a single TCP stream,
nor with multiple concurrent UDP streams, but only when multiple
TCP streams are run concurrently with the PTP packet flow
(doing skb reallocation).
This patch enforces the first method, by requesting enough
headroom from the stack to accommodate PTP frames, and so avoiding
skb_realloc_headroom() & co, and the crashes no longer occur.
There's no reason not to set needed_headroom to a large enough
value to accommodate PTP frames, so in this regard this patch
is a fix.
Reported-by: James Jurack <james.jurack@ametek.com>
Fixes: bee9e58c9e98 ("gianfar:don't add FCB length to hard_header_len")
Signed-off-by: Claudiu Manoil <claudiu.manoil@nxp.com>
Link: https://lore.kernel.org/r/20201020173605.1173-1-claudiu.manoil@nxp.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2020-10-21 01:36:05 +08:00
|
|
|
dev->needed_headroom = GMAC_FCB_LEN + GMAC_TXPAL_LEN;
|
2019-09-04 21:52:19 +08:00
|
|
|
|
|
|
|
/* Initializing some of the rx/tx queue level parameters */
|
|
|
|
for (i = 0; i < priv->num_tx_queues; i++) {
|
|
|
|
priv->tx_queue[i]->tx_ring_size = DEFAULT_TX_RING_SIZE;
|
|
|
|
priv->tx_queue[i]->num_txbdfree = DEFAULT_TX_RING_SIZE;
|
|
|
|
priv->tx_queue[i]->txcoalescing = DEFAULT_TX_COALESCE;
|
|
|
|
priv->tx_queue[i]->txic = DEFAULT_TXIC;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < priv->num_rx_queues; i++) {
|
|
|
|
priv->rx_queue[i]->rx_ring_size = DEFAULT_RX_RING_SIZE;
|
|
|
|
priv->rx_queue[i]->rxcoalescing = DEFAULT_RX_COALESCE;
|
|
|
|
priv->rx_queue[i]->rxic = DEFAULT_RXIC;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Always enable rx filer if available */
|
|
|
|
priv->rx_filer_enable =
|
|
|
|
(priv->device_flags & FSL_GIANFAR_DEV_HAS_RX_FILER) ? 1 : 0;
|
|
|
|
/* Enable most messages by default */
|
|
|
|
priv->msg_enable = (NETIF_MSG_IFUP << 1 ) - 1;
|
|
|
|
/* use pritority h/w tx queue scheduling for single queue devices */
|
|
|
|
if (priv->num_tx_queues == 1)
|
|
|
|
priv->prio_sched_en = 1;
|
|
|
|
|
|
|
|
set_bit(GFAR_DOWN, &priv->state);
|
|
|
|
|
|
|
|
gfar_hw_init(priv);
|
|
|
|
|
2021-06-17 17:49:28 +08:00
|
|
|
if (priv->device_flags & FSL_GIANFAR_DEV_HAS_RMON) {
|
|
|
|
struct rmon_mib __iomem *rmon = &priv->gfargrp[0].regs->rmon;
|
|
|
|
|
|
|
|
spin_lock_init(&priv->rmon_overflow.lock);
|
|
|
|
priv->rmon_overflow.imask = IMASK_MSRO;
|
|
|
|
gfar_write(&rmon->cam1, gfar_read(&rmon->cam1) & ~CAM1_M1RDR);
|
|
|
|
}
|
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
/* Carrier starts down, phylib will bring it up */
|
|
|
|
netif_carrier_off(dev);
|
|
|
|
|
|
|
|
err = register_netdev(dev);
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
pr_err("%s: Cannot register net device, aborting\n", dev->name);
|
|
|
|
goto register_fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (priv->device_flags & FSL_GIANFAR_DEV_HAS_MAGIC_PACKET)
|
|
|
|
priv->wol_supported |= GFAR_WOL_MAGIC;
|
|
|
|
|
|
|
|
if ((priv->device_flags & FSL_GIANFAR_DEV_HAS_WAKE_ON_FILER) &&
|
|
|
|
priv->rx_filer_enable)
|
|
|
|
priv->wol_supported |= GFAR_WOL_FILER_UCAST;
|
|
|
|
|
|
|
|
device_set_wakeup_capable(&ofdev->dev, priv->wol_supported);
|
|
|
|
|
|
|
|
/* fill out IRQ number and name fields */
|
|
|
|
for (i = 0; i < priv->num_grps; i++) {
|
|
|
|
struct gfar_priv_grp *grp = &priv->gfargrp[i];
|
|
|
|
if (priv->device_flags & FSL_GIANFAR_DEV_HAS_MULTI_INTR) {
|
|
|
|
sprintf(gfar_irq(grp, TX)->name, "%s%s%c%s",
|
|
|
|
dev->name, "_g", '0' + i, "_tx");
|
|
|
|
sprintf(gfar_irq(grp, RX)->name, "%s%s%c%s",
|
|
|
|
dev->name, "_g", '0' + i, "_rx");
|
|
|
|
sprintf(gfar_irq(grp, ER)->name, "%s%s%c%s",
|
|
|
|
dev->name, "_g", '0' + i, "_er");
|
|
|
|
} else
|
|
|
|
strcpy(gfar_irq(grp, TX)->name, dev->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize the filer table */
|
|
|
|
gfar_init_filer_table(priv);
|
|
|
|
|
|
|
|
/* Print out the device info */
|
|
|
|
netdev_info(dev, "mac: %pM\n", dev->dev_addr);
|
|
|
|
|
|
|
|
/* Even more device info helps when determining which kernel
|
|
|
|
* provided which set of benchmarks.
|
|
|
|
*/
|
|
|
|
netdev_info(dev, "Running with NAPI enabled\n");
|
|
|
|
for (i = 0; i < priv->num_rx_queues; i++)
|
|
|
|
netdev_info(dev, "RX BD ring size for Q[%d]: %d\n",
|
|
|
|
i, priv->rx_queue[i]->rx_ring_size);
|
|
|
|
for (i = 0; i < priv->num_tx_queues; i++)
|
|
|
|
netdev_info(dev, "TX BD ring size for Q[%d]: %d\n",
|
|
|
|
i, priv->tx_queue[i]->tx_ring_size);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
register_fail:
|
|
|
|
if (of_phy_is_fixed_link(np))
|
|
|
|
of_phy_deregister_fixed_link(np);
|
|
|
|
unmap_group_regs(priv);
|
|
|
|
gfar_free_rx_queues(priv);
|
|
|
|
gfar_free_tx_queues(priv);
|
|
|
|
of_node_put(priv->phy_node);
|
|
|
|
of_node_put(priv->tbi_node);
|
|
|
|
free_gfar_dev(priv);
|
|
|
|
return err;
|
|
|
|
}
|
2006-11-07 18:27:02 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
static int gfar_remove(struct platform_device *ofdev)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2019-09-04 21:52:19 +08:00
|
|
|
struct gfar_private *priv = platform_get_drvdata(ofdev);
|
|
|
|
struct device_node *np = ofdev->dev.of_node;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
of_node_put(priv->phy_node);
|
|
|
|
of_node_put(priv->tbi_node);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
unregister_netdev(priv->ndev);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
if (of_phy_is_fixed_link(np))
|
|
|
|
of_phy_deregister_fixed_link(np);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
unmap_group_regs(priv);
|
|
|
|
gfar_free_rx_queues(priv);
|
|
|
|
gfar_free_tx_queues(priv);
|
|
|
|
free_gfar_dev(priv);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
#ifdef CONFIG_PM
|
|
|
|
|
|
|
|
static void __gfar_filer_disable(struct gfar_private *priv)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2019-09-04 21:52:19 +08:00
|
|
|
struct gfar __iomem *regs = priv->gfargrp[0].regs;
|
|
|
|
u32 temp;
|
2005-09-24 10:54:21 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
temp = gfar_read(®s->rctrl);
|
|
|
|
temp &= ~(RCTRL_FILREN | RCTRL_PRSDEP_INIT);
|
|
|
|
gfar_write(®s->rctrl, temp);
|
2005-09-24 10:54:21 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
static void __gfar_filer_enable(struct gfar_private *priv)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2009-11-02 15:03:34 +08:00
|
|
|
struct gfar __iomem *regs = priv->gfargrp[0].regs;
|
2019-09-04 21:52:19 +08:00
|
|
|
u32 temp;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
temp = gfar_read(®s->rctrl);
|
|
|
|
temp |= RCTRL_FILREN | RCTRL_PRSDEP_INIT;
|
|
|
|
gfar_write(®s->rctrl, temp);
|
|
|
|
}
|
2006-09-14 01:24:59 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
/* Filer rules implementing wol capabilities */
|
|
|
|
static void gfar_filer_config_wol(struct gfar_private *priv)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
u32 rqfcr;
|
2005-11-12 02:38:59 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
__gfar_filer_disable(priv);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
/* clear the filer table, reject any packet by default */
|
|
|
|
rqfcr = RQFCR_RJE | RQFCR_CMP_MATCH;
|
|
|
|
for (i = 0; i <= MAX_FILER_IDX; i++)
|
|
|
|
gfar_write_filer(priv, i, rqfcr, 0);
|
2005-11-12 02:38:59 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
i = 0;
|
|
|
|
if (priv->wol_opts & GFAR_WOL_FILER_UCAST) {
|
|
|
|
/* unicast packet, accept it */
|
|
|
|
struct net_device *ndev = priv->ndev;
|
|
|
|
/* get the default rx queue index */
|
|
|
|
u8 qindex = (u8)priv->gfargrp[0].rx_queue->qindex;
|
|
|
|
u32 dest_mac_addr = (ndev->dev_addr[0] << 16) |
|
|
|
|
(ndev->dev_addr[1] << 8) |
|
|
|
|
ndev->dev_addr[2];
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
rqfcr = (qindex << 10) | RQFCR_AND |
|
|
|
|
RQFCR_CMP_EXACT | RQFCR_PID_DAH;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
gfar_write_filer(priv, i++, rqfcr, dest_mac_addr);
|
2005-11-12 02:38:59 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
dest_mac_addr = (ndev->dev_addr[3] << 16) |
|
|
|
|
(ndev->dev_addr[4] << 8) |
|
|
|
|
ndev->dev_addr[5];
|
|
|
|
rqfcr = (qindex << 10) | RQFCR_GPI |
|
|
|
|
RQFCR_CMP_EXACT | RQFCR_PID_DAL;
|
|
|
|
gfar_write_filer(priv, i++, rqfcr, dest_mac_addr);
|
|
|
|
}
|
2005-11-12 02:38:59 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
__gfar_filer_enable(priv);
|
2005-11-12 02:38:59 +08:00
|
|
|
}
|
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
static void gfar_filer_restore_table(struct gfar_private *priv)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2019-09-04 21:52:19 +08:00
|
|
|
u32 rqfcr, rqfpr;
|
|
|
|
unsigned int i;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
__gfar_filer_disable(priv);
|
|
|
|
|
|
|
|
for (i = 0; i <= MAX_FILER_IDX; i++) {
|
|
|
|
rqfcr = priv->ftp_rqfcr[i];
|
|
|
|
rqfpr = priv->ftp_rqfpr[i];
|
|
|
|
gfar_write_filer(priv, i, rqfcr, rqfpr);
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
__gfar_filer_enable(priv);
|
|
|
|
}
|
2005-11-12 02:38:59 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
/* gfar_start() for Rx only and with the FGPI filer interrupt enabled */
|
|
|
|
static void gfar_start_wol_filer(struct gfar_private *priv)
|
2005-11-12 02:38:59 +08:00
|
|
|
{
|
2009-11-02 15:03:34 +08:00
|
|
|
struct gfar __iomem *regs = priv->gfargrp[0].regs;
|
2005-11-12 02:38:59 +08:00
|
|
|
u32 tempval;
|
2019-09-04 21:52:19 +08:00
|
|
|
int i = 0;
|
2005-11-12 02:38:59 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
/* Enable Rx hw queues */
|
|
|
|
gfar_write(®s->rqueue, priv->rqueue);
|
2005-11-12 02:38:59 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
/* Initialize DMACTRL to have WWR and WOP */
|
|
|
|
tempval = gfar_read(®s->dmactrl);
|
|
|
|
tempval |= DMACTRL_INIT_SETTINGS;
|
|
|
|
gfar_write(®s->dmactrl, tempval);
|
2005-11-12 02:38:59 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
/* Make sure we aren't stopped */
|
|
|
|
tempval = gfar_read(®s->dmactrl);
|
|
|
|
tempval &= ~DMACTRL_GRS;
|
|
|
|
gfar_write(®s->dmactrl, tempval);
|
2005-11-12 02:38:59 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
for (i = 0; i < priv->num_grps; i++) {
|
|
|
|
regs = priv->gfargrp[i].regs;
|
|
|
|
/* Clear RHLT, so that the DMA starts polling now */
|
|
|
|
gfar_write(®s->rstat, priv->gfargrp[i].rstat);
|
|
|
|
/* enable the Filer General Purpose Interrupt */
|
|
|
|
gfar_write(®s->imask, IMASK_FGPI);
|
|
|
|
}
|
2005-11-12 02:38:59 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
/* Enable Rx DMA */
|
|
|
|
tempval = gfar_read(®s->maccfg1);
|
|
|
|
tempval |= MACCFG1_RX_EN;
|
|
|
|
gfar_write(®s->maccfg1, tempval);
|
2005-11-12 02:38:59 +08:00
|
|
|
}
|
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
static int gfar_suspend(struct device *dev)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2019-09-04 21:52:19 +08:00
|
|
|
struct gfar_private *priv = dev_get_drvdata(dev);
|
|
|
|
struct net_device *ndev = priv->ndev;
|
|
|
|
struct gfar __iomem *regs = priv->gfargrp[0].regs;
|
|
|
|
u32 tempval;
|
|
|
|
u16 wol = priv->wol_opts;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
if (!netif_running(ndev))
|
|
|
|
return 0;
|
2008-07-12 07:04:45 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
disable_napi(priv);
|
|
|
|
netif_tx_lock(ndev);
|
|
|
|
netif_device_detach(ndev);
|
|
|
|
netif_tx_unlock(ndev);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
gfar_halt(priv);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
if (wol & GFAR_WOL_MAGIC) {
|
|
|
|
/* Enable interrupt on Magic Packet */
|
|
|
|
gfar_write(®s->imask, IMASK_MAG);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
/* Enable Magic Packet mode */
|
|
|
|
tempval = gfar_read(®s->maccfg2);
|
|
|
|
tempval |= MACCFG2_MPEN;
|
|
|
|
gfar_write(®s->maccfg2, tempval);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
/* re-enable the Rx block */
|
|
|
|
tempval = gfar_read(®s->maccfg1);
|
|
|
|
tempval |= MACCFG1_RX_EN;
|
|
|
|
gfar_write(®s->maccfg1, tempval);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
} else if (wol & GFAR_WOL_FILER_UCAST) {
|
|
|
|
gfar_filer_config_wol(priv);
|
|
|
|
gfar_start_wol_filer(priv);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
} else {
|
|
|
|
phy_stop(ndev->phydev);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
static int gfar_resume(struct device *dev)
|
2014-04-30 19:27:21 +08:00
|
|
|
{
|
2019-09-04 21:52:19 +08:00
|
|
|
struct gfar_private *priv = dev_get_drvdata(dev);
|
2016-05-16 07:30:08 +08:00
|
|
|
struct net_device *ndev = priv->ndev;
|
2019-09-04 21:52:19 +08:00
|
|
|
struct gfar __iomem *regs = priv->gfargrp[0].regs;
|
|
|
|
u32 tempval;
|
|
|
|
u16 wol = priv->wol_opts;
|
2014-04-30 19:27:21 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
if (!netif_running(ndev))
|
|
|
|
return 0;
|
2014-04-30 19:27:21 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
if (wol & GFAR_WOL_MAGIC) {
|
|
|
|
/* Disable Magic Packet mode */
|
|
|
|
tempval = gfar_read(®s->maccfg2);
|
|
|
|
tempval &= ~MACCFG2_MPEN;
|
|
|
|
gfar_write(®s->maccfg2, tempval);
|
2014-04-30 19:27:21 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
} else if (wol & GFAR_WOL_FILER_UCAST) {
|
|
|
|
/* need to stop rx only, tx is already down */
|
|
|
|
gfar_halt(priv);
|
|
|
|
gfar_filer_restore_table(priv);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
phy_start(ndev->phydev);
|
2014-04-30 19:27:21 +08:00
|
|
|
}
|
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
gfar_start(priv);
|
|
|
|
|
|
|
|
netif_device_attach(ndev);
|
|
|
|
enable_napi(priv);
|
|
|
|
|
|
|
|
return 0;
|
2014-04-30 19:27:21 +08:00
|
|
|
}
|
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
static int gfar_restore(struct device *dev)
|
2014-04-30 19:27:21 +08:00
|
|
|
{
|
2019-09-04 21:52:19 +08:00
|
|
|
struct gfar_private *priv = dev_get_drvdata(dev);
|
2016-05-16 07:30:08 +08:00
|
|
|
struct net_device *ndev = priv->ndev;
|
2014-04-30 19:27:21 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
if (!netif_running(ndev)) {
|
|
|
|
netif_device_attach(ndev);
|
2014-04-30 19:27:21 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2014-04-30 19:27:21 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
gfar_init_bds(ndev);
|
2014-04-30 19:27:21 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
gfar_mac_reset(priv);
|
2014-04-30 19:27:21 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
gfar_init_tx_rx_base(priv);
|
2014-04-30 19:27:21 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
gfar_start(priv);
|
2014-04-30 19:27:21 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
priv->oldlink = 0;
|
|
|
|
priv->oldspeed = 0;
|
|
|
|
priv->oldduplex = -1;
|
2014-04-30 19:27:21 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
if (ndev->phydev)
|
|
|
|
phy_start(ndev->phydev);
|
2015-07-29 21:13:06 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
netif_device_attach(ndev);
|
|
|
|
enable_napi(priv);
|
2014-10-27 16:42:44 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2014-10-27 16:42:44 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
static const struct dev_pm_ops gfar_pm_ops = {
|
|
|
|
.suspend = gfar_suspend,
|
|
|
|
.resume = gfar_resume,
|
|
|
|
.freeze = gfar_suspend,
|
|
|
|
.thaw = gfar_resume,
|
|
|
|
.restore = gfar_restore,
|
|
|
|
};
|
2014-10-27 16:42:44 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
#define GFAR_PM_OPS (&gfar_pm_ops)
|
2014-04-30 19:27:21 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
#else
|
2014-04-30 19:27:21 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
#define GFAR_PM_OPS NULL
|
2014-04-30 19:27:21 +08:00
|
|
|
|
2019-09-04 21:52:19 +08:00
|
|
|
#endif
|
2014-04-30 19:27:21 +08:00
|
|
|
|
2015-03-18 02:37:34 +08:00
|
|
|
static const struct of_device_id gfar_match[] =
|
2008-12-17 07:29:15 +08:00
|
|
|
{
|
|
|
|
{
|
|
|
|
.type = "network",
|
|
|
|
.compatible = "gianfar",
|
|
|
|
},
|
2009-11-02 15:03:34 +08:00
|
|
|
{
|
|
|
|
.compatible = "fsl,etsec2",
|
|
|
|
},
|
2008-12-17 07:29:15 +08:00
|
|
|
{},
|
|
|
|
};
|
2009-10-15 05:54:52 +08:00
|
|
|
MODULE_DEVICE_TABLE(of, gfar_match);
|
2008-12-17 07:29:15 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Structure for a device driver */
|
2011-02-23 12:05:51 +08:00
|
|
|
static struct platform_driver gfar_driver = {
|
2010-04-14 07:13:02 +08:00
|
|
|
.driver = {
|
|
|
|
.name = "fsl-gianfar",
|
|
|
|
.pm = GFAR_PM_OPS,
|
|
|
|
.of_match_table = gfar_match,
|
|
|
|
},
|
2005-04-17 06:20:36 +08:00
|
|
|
.probe = gfar_probe,
|
|
|
|
.remove = gfar_remove,
|
|
|
|
};
|
|
|
|
|
2011-11-28 00:44:17 +08:00
|
|
|
module_platform_driver(gfar_driver);
|