2010-02-15 10:33:44 +07:00
|
|
|
/*
|
|
|
|
* Aeroflex Gaisler GRETH 10/100/1G Ethernet MAC.
|
|
|
|
*
|
GRETH: resolve SMP issues and other problems
Fixes the following:
1. POLL should not enable IRQ when work is not completed
2. No locking between TX descriptor cleaning and XMIT descriptor handling
3. No locking between RX POLL and XMIT modifying control register
4. Since TX cleaning (called from POLL) is running in parallel with XMIT
unnecessary locking is needed.
5. IRQ handler looks at RX frame status solely, this is wrong when IRQ is
temporarily disabled (in POLL), and when IRQ is shared.
6. IRQ handler clears IRQ status, which is unnecessary
7. TX queue was stopped in preventing cause when not MAX_SKB_FRAGS+1
descriptors were available after a SKB been scheduled by XMIT. Instead
the TX queue is stopped first when not enough descriptors are available
upon entering XMIT.
It was hard to split up this patch in smaller pieces since all are tied
together somehow.
Note the RX flag used in the interrupt handler does not signal that
interrupt was asserted, but that a frame was received. Same goes for TX.
Also, IRQ is not asserted when the RX flag is set before enabling IRQ
enable until a new frame is received. So extra care must be taken to
avoid enabling IRQ and all descriptors are already used, hence dead lock
will upon us. See new POLL implementation that enableds IRQ then look at
the RX flag to determine if one or more IRQs may have been missed. TX/RX
flags are cleared before handling previously enabled descriptors, this
ensures that the RX/TX flags are valid when determining if IRQ should be
turned on again.
By moving TX cleaning from POLL to XMIT in the standard case, removes some
locking trouble. Enabling TX cleaning from poll only when not enough TX
descriptors are available is safe because the TX queue is at the same time
stopped, thus XMIT will not be called. The TX queue is woken up again when
enough descriptrs are available.
TX Frames are always enabled with IRQ, however the TX IRQ Enable flag will
not be enabled until XMIT must wait for free descriptors.
Locking RX and XMIT parts of the driver from each other is needed because
the RX/TX enable bits share the same register.
Signed-off-by: Daniel Hellstrom <daniel@gaisler.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2011-01-14 10:02:43 +07:00
|
|
|
* 2005-2010 (c) Aeroflex Gaisler AB
|
2010-02-15 10:33:44 +07:00
|
|
|
*
|
|
|
|
* This driver supports GRETH 10/100 and GRETH 10/100/1G Ethernet MACs
|
|
|
|
* available in the GRLIB VHDL IP core library.
|
|
|
|
*
|
|
|
|
* Full documentation of both cores can be found here:
|
|
|
|
* http://www.gaisler.com/products/grlib/grip.pdf
|
|
|
|
*
|
|
|
|
* The Gigabit version supports scatter/gather DMA, any alignment of
|
|
|
|
* buffers and checksum offloading.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation; either version 2 of the License, or (at your
|
|
|
|
* option) any later version.
|
|
|
|
*
|
|
|
|
* Contributors: Kristoffer Glembo
|
|
|
|
* Daniel Hellstrom
|
|
|
|
* Marko Isomaki
|
|
|
|
*/
|
|
|
|
|
2011-06-16 18:01:34 +07:00
|
|
|
#include <linux/dma-mapping.h>
|
2010-02-15 10:33:44 +07:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/uaccess.h>
|
2011-06-06 17:43:46 +07:00
|
|
|
#include <linux/interrupt.h>
|
2010-02-15 10:33:44 +07:00
|
|
|
#include <linux/netdevice.h>
|
|
|
|
#include <linux/etherdevice.h>
|
|
|
|
#include <linux/ethtool.h>
|
|
|
|
#include <linux/skbuff.h>
|
|
|
|
#include <linux/io.h>
|
|
|
|
#include <linux/crc32.h>
|
|
|
|
#include <linux/mii.h>
|
|
|
|
#include <linux/of_device.h>
|
|
|
|
#include <linux/of_platform.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 15:04:11 +07:00
|
|
|
#include <linux/slab.h>
|
2010-02-15 10:33:44 +07:00
|
|
|
#include <asm/cacheflush.h>
|
|
|
|
#include <asm/byteorder.h>
|
|
|
|
|
|
|
|
#ifdef CONFIG_SPARC
|
|
|
|
#include <asm/idprom.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "greth.h"
|
|
|
|
|
|
|
|
#define GRETH_DEF_MSG_ENABLE \
|
|
|
|
(NETIF_MSG_DRV | \
|
|
|
|
NETIF_MSG_PROBE | \
|
|
|
|
NETIF_MSG_LINK | \
|
|
|
|
NETIF_MSG_IFDOWN | \
|
|
|
|
NETIF_MSG_IFUP | \
|
|
|
|
NETIF_MSG_RX_ERR | \
|
|
|
|
NETIF_MSG_TX_ERR)
|
|
|
|
|
|
|
|
static int greth_debug = -1; /* -1 == use GRETH_DEF_MSG_ENABLE as value */
|
|
|
|
module_param(greth_debug, int, 0);
|
|
|
|
MODULE_PARM_DESC(greth_debug, "GRETH bitmapped debugging message enable value");
|
|
|
|
|
|
|
|
/* Accept MAC address of the form macaddr=0x08,0x00,0x20,0x30,0x40,0x50 */
|
|
|
|
static int macaddr[6];
|
|
|
|
module_param_array(macaddr, int, NULL, 0);
|
|
|
|
MODULE_PARM_DESC(macaddr, "GRETH Ethernet MAC address");
|
|
|
|
|
|
|
|
static int greth_edcl = 1;
|
|
|
|
module_param(greth_edcl, int, 0);
|
|
|
|
MODULE_PARM_DESC(greth_edcl, "GRETH EDCL usage indicator. Set to 1 if EDCL is used.");
|
|
|
|
|
|
|
|
static int greth_open(struct net_device *dev);
|
2010-02-24 17:25:33 +07:00
|
|
|
static netdev_tx_t greth_start_xmit(struct sk_buff *skb,
|
|
|
|
struct net_device *dev);
|
|
|
|
static netdev_tx_t greth_start_xmit_gbit(struct sk_buff *skb,
|
|
|
|
struct net_device *dev);
|
2010-02-15 10:33:44 +07:00
|
|
|
static int greth_rx(struct net_device *dev, int limit);
|
|
|
|
static int greth_rx_gbit(struct net_device *dev, int limit);
|
|
|
|
static void greth_clean_tx(struct net_device *dev);
|
|
|
|
static void greth_clean_tx_gbit(struct net_device *dev);
|
|
|
|
static irqreturn_t greth_interrupt(int irq, void *dev_id);
|
|
|
|
static int greth_close(struct net_device *dev);
|
|
|
|
static int greth_set_mac_add(struct net_device *dev, void *p);
|
|
|
|
static void greth_set_multicast_list(struct net_device *dev);
|
|
|
|
|
|
|
|
#define GRETH_REGLOAD(a) (be32_to_cpu(__raw_readl(&(a))))
|
|
|
|
#define GRETH_REGSAVE(a, v) (__raw_writel(cpu_to_be32(v), &(a)))
|
|
|
|
#define GRETH_REGORIN(a, v) (GRETH_REGSAVE(a, (GRETH_REGLOAD(a) | (v))))
|
|
|
|
#define GRETH_REGANDIN(a, v) (GRETH_REGSAVE(a, (GRETH_REGLOAD(a) & (v))))
|
|
|
|
|
|
|
|
#define NEXT_TX(N) (((N) + 1) & GRETH_TXBD_NUM_MASK)
|
|
|
|
#define SKIP_TX(N, C) (((N) + C) & GRETH_TXBD_NUM_MASK)
|
|
|
|
#define NEXT_RX(N) (((N) + 1) & GRETH_RXBD_NUM_MASK)
|
|
|
|
|
|
|
|
static void greth_print_rx_packet(void *addr, int len)
|
|
|
|
{
|
|
|
|
print_hex_dump(KERN_DEBUG, "RX: ", DUMP_PREFIX_OFFSET, 16, 1,
|
|
|
|
addr, len, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void greth_print_tx_packet(struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int length;
|
|
|
|
|
|
|
|
if (skb_shinfo(skb)->nr_frags == 0)
|
|
|
|
length = skb->len;
|
|
|
|
else
|
|
|
|
length = skb_headlen(skb);
|
|
|
|
|
|
|
|
print_hex_dump(KERN_DEBUG, "TX: ", DUMP_PREFIX_OFFSET, 16, 1,
|
|
|
|
skb->data, length, true);
|
|
|
|
|
|
|
|
for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
|
|
|
|
|
|
|
|
print_hex_dump(KERN_DEBUG, "TX: ", DUMP_PREFIX_OFFSET, 16, 1,
|
2011-08-30 06:18:30 +07:00
|
|
|
skb_frag_address(&skb_shinfo(skb)->frags[i]),
|
|
|
|
skb_shinfo(skb)->frags[i].size, true);
|
2010-02-15 10:33:44 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void greth_enable_tx(struct greth_private *greth)
|
|
|
|
{
|
|
|
|
wmb();
|
|
|
|
GRETH_REGORIN(greth->regs->control, GRETH_TXEN);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void greth_disable_tx(struct greth_private *greth)
|
|
|
|
{
|
|
|
|
GRETH_REGANDIN(greth->regs->control, ~GRETH_TXEN);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void greth_enable_rx(struct greth_private *greth)
|
|
|
|
{
|
|
|
|
wmb();
|
|
|
|
GRETH_REGORIN(greth->regs->control, GRETH_RXEN);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void greth_disable_rx(struct greth_private *greth)
|
|
|
|
{
|
|
|
|
GRETH_REGANDIN(greth->regs->control, ~GRETH_RXEN);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void greth_enable_irqs(struct greth_private *greth)
|
|
|
|
{
|
|
|
|
GRETH_REGORIN(greth->regs->control, GRETH_RXI | GRETH_TXI);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void greth_disable_irqs(struct greth_private *greth)
|
|
|
|
{
|
|
|
|
GRETH_REGANDIN(greth->regs->control, ~(GRETH_RXI|GRETH_TXI));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void greth_write_bd(u32 *bd, u32 val)
|
|
|
|
{
|
|
|
|
__raw_writel(cpu_to_be32(val), bd);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline u32 greth_read_bd(u32 *bd)
|
|
|
|
{
|
|
|
|
return be32_to_cpu(__raw_readl(bd));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void greth_clean_rings(struct greth_private *greth)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
struct greth_bd *rx_bdp = greth->rx_bd_base;
|
|
|
|
struct greth_bd *tx_bdp = greth->tx_bd_base;
|
|
|
|
|
|
|
|
if (greth->gbit_mac) {
|
|
|
|
|
|
|
|
/* Free and unmap RX buffers */
|
|
|
|
for (i = 0; i < GRETH_RXBD_NUM; i++, rx_bdp++) {
|
|
|
|
if (greth->rx_skbuff[i] != NULL) {
|
|
|
|
dev_kfree_skb(greth->rx_skbuff[i]);
|
|
|
|
dma_unmap_single(greth->dev,
|
|
|
|
greth_read_bd(&rx_bdp->addr),
|
|
|
|
MAX_FRAME_SIZE+NET_IP_ALIGN,
|
|
|
|
DMA_FROM_DEVICE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* TX buffers */
|
|
|
|
while (greth->tx_free < GRETH_TXBD_NUM) {
|
|
|
|
|
|
|
|
struct sk_buff *skb = greth->tx_skbuff[greth->tx_last];
|
|
|
|
int nr_frags = skb_shinfo(skb)->nr_frags;
|
|
|
|
tx_bdp = greth->tx_bd_base + greth->tx_last;
|
|
|
|
greth->tx_last = NEXT_TX(greth->tx_last);
|
|
|
|
|
|
|
|
dma_unmap_single(greth->dev,
|
|
|
|
greth_read_bd(&tx_bdp->addr),
|
|
|
|
skb_headlen(skb),
|
|
|
|
DMA_TO_DEVICE);
|
|
|
|
|
|
|
|
for (i = 0; i < nr_frags; i++) {
|
|
|
|
skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
|
|
|
|
tx_bdp = greth->tx_bd_base + greth->tx_last;
|
|
|
|
|
|
|
|
dma_unmap_page(greth->dev,
|
|
|
|
greth_read_bd(&tx_bdp->addr),
|
2011-10-19 04:00:24 +07:00
|
|
|
skb_frag_size(frag),
|
2010-02-15 10:33:44 +07:00
|
|
|
DMA_TO_DEVICE);
|
|
|
|
|
|
|
|
greth->tx_last = NEXT_TX(greth->tx_last);
|
|
|
|
}
|
|
|
|
greth->tx_free += nr_frags+1;
|
|
|
|
dev_kfree_skb(skb);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} else { /* 10/100 Mbps MAC */
|
|
|
|
|
|
|
|
for (i = 0; i < GRETH_RXBD_NUM; i++, rx_bdp++) {
|
|
|
|
kfree(greth->rx_bufs[i]);
|
|
|
|
dma_unmap_single(greth->dev,
|
|
|
|
greth_read_bd(&rx_bdp->addr),
|
|
|
|
MAX_FRAME_SIZE,
|
|
|
|
DMA_FROM_DEVICE);
|
|
|
|
}
|
|
|
|
for (i = 0; i < GRETH_TXBD_NUM; i++, tx_bdp++) {
|
|
|
|
kfree(greth->tx_bufs[i]);
|
|
|
|
dma_unmap_single(greth->dev,
|
|
|
|
greth_read_bd(&tx_bdp->addr),
|
|
|
|
MAX_FRAME_SIZE,
|
|
|
|
DMA_TO_DEVICE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int greth_init_rings(struct greth_private *greth)
|
|
|
|
{
|
|
|
|
struct sk_buff *skb;
|
|
|
|
struct greth_bd *rx_bd, *tx_bd;
|
|
|
|
u32 dma_addr;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
rx_bd = greth->rx_bd_base;
|
|
|
|
tx_bd = greth->tx_bd_base;
|
|
|
|
|
|
|
|
/* Initialize descriptor rings and buffers */
|
|
|
|
if (greth->gbit_mac) {
|
|
|
|
|
|
|
|
for (i = 0; i < GRETH_RXBD_NUM; i++) {
|
|
|
|
skb = netdev_alloc_skb(greth->netdev, MAX_FRAME_SIZE+NET_IP_ALIGN);
|
|
|
|
if (skb == NULL) {
|
|
|
|
if (netif_msg_ifup(greth))
|
|
|
|
dev_err(greth->dev, "Error allocating DMA ring.\n");
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
skb_reserve(skb, NET_IP_ALIGN);
|
|
|
|
dma_addr = dma_map_single(greth->dev,
|
|
|
|
skb->data,
|
|
|
|
MAX_FRAME_SIZE+NET_IP_ALIGN,
|
|
|
|
DMA_FROM_DEVICE);
|
|
|
|
|
|
|
|
if (dma_mapping_error(greth->dev, dma_addr)) {
|
|
|
|
if (netif_msg_ifup(greth))
|
|
|
|
dev_err(greth->dev, "Could not create initial DMA mapping\n");
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
greth->rx_skbuff[i] = skb;
|
|
|
|
greth_write_bd(&rx_bd[i].addr, dma_addr);
|
|
|
|
greth_write_bd(&rx_bd[i].stat, GRETH_BD_EN | GRETH_BD_IE);
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
/* 10/100 MAC uses a fixed set of buffers and copy to/from SKBs */
|
|
|
|
for (i = 0; i < GRETH_RXBD_NUM; i++) {
|
|
|
|
|
|
|
|
greth->rx_bufs[i] = kmalloc(MAX_FRAME_SIZE, GFP_KERNEL);
|
|
|
|
|
|
|
|
if (greth->rx_bufs[i] == NULL) {
|
|
|
|
if (netif_msg_ifup(greth))
|
|
|
|
dev_err(greth->dev, "Error allocating DMA ring.\n");
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
dma_addr = dma_map_single(greth->dev,
|
|
|
|
greth->rx_bufs[i],
|
|
|
|
MAX_FRAME_SIZE,
|
|
|
|
DMA_FROM_DEVICE);
|
|
|
|
|
|
|
|
if (dma_mapping_error(greth->dev, dma_addr)) {
|
|
|
|
if (netif_msg_ifup(greth))
|
|
|
|
dev_err(greth->dev, "Could not create initial DMA mapping\n");
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
greth_write_bd(&rx_bd[i].addr, dma_addr);
|
|
|
|
greth_write_bd(&rx_bd[i].stat, GRETH_BD_EN | GRETH_BD_IE);
|
|
|
|
}
|
|
|
|
for (i = 0; i < GRETH_TXBD_NUM; i++) {
|
|
|
|
|
|
|
|
greth->tx_bufs[i] = kmalloc(MAX_FRAME_SIZE, GFP_KERNEL);
|
|
|
|
|
|
|
|
if (greth->tx_bufs[i] == NULL) {
|
|
|
|
if (netif_msg_ifup(greth))
|
|
|
|
dev_err(greth->dev, "Error allocating DMA ring.\n");
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
dma_addr = dma_map_single(greth->dev,
|
|
|
|
greth->tx_bufs[i],
|
|
|
|
MAX_FRAME_SIZE,
|
|
|
|
DMA_TO_DEVICE);
|
|
|
|
|
|
|
|
if (dma_mapping_error(greth->dev, dma_addr)) {
|
|
|
|
if (netif_msg_ifup(greth))
|
|
|
|
dev_err(greth->dev, "Could not create initial DMA mapping\n");
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
greth_write_bd(&tx_bd[i].addr, dma_addr);
|
|
|
|
greth_write_bd(&tx_bd[i].stat, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
greth_write_bd(&rx_bd[GRETH_RXBD_NUM - 1].stat,
|
|
|
|
greth_read_bd(&rx_bd[GRETH_RXBD_NUM - 1].stat) | GRETH_BD_WR);
|
|
|
|
|
|
|
|
/* Initialize pointers. */
|
|
|
|
greth->rx_cur = 0;
|
|
|
|
greth->tx_next = 0;
|
|
|
|
greth->tx_last = 0;
|
|
|
|
greth->tx_free = GRETH_TXBD_NUM;
|
|
|
|
|
|
|
|
/* Initialize descriptor base address */
|
|
|
|
GRETH_REGSAVE(greth->regs->tx_desc_p, greth->tx_bd_base_phys);
|
|
|
|
GRETH_REGSAVE(greth->regs->rx_desc_p, greth->rx_bd_base_phys);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
greth_clean_rings(greth);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int greth_open(struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct greth_private *greth = netdev_priv(dev);
|
|
|
|
int err;
|
|
|
|
|
|
|
|
err = greth_init_rings(greth);
|
|
|
|
if (err) {
|
|
|
|
if (netif_msg_ifup(greth))
|
|
|
|
dev_err(&dev->dev, "Could not allocate memory for DMA rings\n");
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = request_irq(greth->irq, greth_interrupt, 0, "eth", (void *) dev);
|
|
|
|
if (err) {
|
|
|
|
if (netif_msg_ifup(greth))
|
|
|
|
dev_err(&dev->dev, "Could not allocate interrupt %d\n", dev->irq);
|
|
|
|
greth_clean_rings(greth);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (netif_msg_ifup(greth))
|
|
|
|
dev_dbg(&dev->dev, " starting queue\n");
|
|
|
|
netif_start_queue(dev);
|
|
|
|
|
2011-01-14 10:02:38 +07:00
|
|
|
GRETH_REGSAVE(greth->regs->status, 0xFF);
|
|
|
|
|
2010-02-15 10:33:44 +07:00
|
|
|
napi_enable(&greth->napi);
|
|
|
|
|
|
|
|
greth_enable_irqs(greth);
|
|
|
|
greth_enable_tx(greth);
|
|
|
|
greth_enable_rx(greth);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static int greth_close(struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct greth_private *greth = netdev_priv(dev);
|
|
|
|
|
|
|
|
napi_disable(&greth->napi);
|
|
|
|
|
2011-01-14 10:02:38 +07:00
|
|
|
greth_disable_irqs(greth);
|
2010-02-15 10:33:44 +07:00
|
|
|
greth_disable_tx(greth);
|
2011-01-14 10:02:38 +07:00
|
|
|
greth_disable_rx(greth);
|
2010-02-15 10:33:44 +07:00
|
|
|
|
|
|
|
netif_stop_queue(dev);
|
|
|
|
|
|
|
|
free_irq(greth->irq, (void *) dev);
|
|
|
|
|
|
|
|
greth_clean_rings(greth);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-02-24 17:25:33 +07:00
|
|
|
static netdev_tx_t
|
|
|
|
greth_start_xmit(struct sk_buff *skb, struct net_device *dev)
|
2010-02-15 10:33:44 +07:00
|
|
|
{
|
|
|
|
struct greth_private *greth = netdev_priv(dev);
|
|
|
|
struct greth_bd *bdp;
|
|
|
|
int err = NETDEV_TX_OK;
|
GRETH: resolve SMP issues and other problems
Fixes the following:
1. POLL should not enable IRQ when work is not completed
2. No locking between TX descriptor cleaning and XMIT descriptor handling
3. No locking between RX POLL and XMIT modifying control register
4. Since TX cleaning (called from POLL) is running in parallel with XMIT
unnecessary locking is needed.
5. IRQ handler looks at RX frame status solely, this is wrong when IRQ is
temporarily disabled (in POLL), and when IRQ is shared.
6. IRQ handler clears IRQ status, which is unnecessary
7. TX queue was stopped in preventing cause when not MAX_SKB_FRAGS+1
descriptors were available after a SKB been scheduled by XMIT. Instead
the TX queue is stopped first when not enough descriptors are available
upon entering XMIT.
It was hard to split up this patch in smaller pieces since all are tied
together somehow.
Note the RX flag used in the interrupt handler does not signal that
interrupt was asserted, but that a frame was received. Same goes for TX.
Also, IRQ is not asserted when the RX flag is set before enabling IRQ
enable until a new frame is received. So extra care must be taken to
avoid enabling IRQ and all descriptors are already used, hence dead lock
will upon us. See new POLL implementation that enableds IRQ then look at
the RX flag to determine if one or more IRQs may have been missed. TX/RX
flags are cleared before handling previously enabled descriptors, this
ensures that the RX/TX flags are valid when determining if IRQ should be
turned on again.
By moving TX cleaning from POLL to XMIT in the standard case, removes some
locking trouble. Enabling TX cleaning from poll only when not enough TX
descriptors are available is safe because the TX queue is at the same time
stopped, thus XMIT will not be called. The TX queue is woken up again when
enough descriptrs are available.
TX Frames are always enabled with IRQ, however the TX IRQ Enable flag will
not be enabled until XMIT must wait for free descriptors.
Locking RX and XMIT parts of the driver from each other is needed because
the RX/TX enable bits share the same register.
Signed-off-by: Daniel Hellstrom <daniel@gaisler.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2011-01-14 10:02:43 +07:00
|
|
|
u32 status, dma_addr, ctrl;
|
|
|
|
unsigned long flags;
|
2010-02-15 10:33:44 +07:00
|
|
|
|
GRETH: resolve SMP issues and other problems
Fixes the following:
1. POLL should not enable IRQ when work is not completed
2. No locking between TX descriptor cleaning and XMIT descriptor handling
3. No locking between RX POLL and XMIT modifying control register
4. Since TX cleaning (called from POLL) is running in parallel with XMIT
unnecessary locking is needed.
5. IRQ handler looks at RX frame status solely, this is wrong when IRQ is
temporarily disabled (in POLL), and when IRQ is shared.
6. IRQ handler clears IRQ status, which is unnecessary
7. TX queue was stopped in preventing cause when not MAX_SKB_FRAGS+1
descriptors were available after a SKB been scheduled by XMIT. Instead
the TX queue is stopped first when not enough descriptors are available
upon entering XMIT.
It was hard to split up this patch in smaller pieces since all are tied
together somehow.
Note the RX flag used in the interrupt handler does not signal that
interrupt was asserted, but that a frame was received. Same goes for TX.
Also, IRQ is not asserted when the RX flag is set before enabling IRQ
enable until a new frame is received. So extra care must be taken to
avoid enabling IRQ and all descriptors are already used, hence dead lock
will upon us. See new POLL implementation that enableds IRQ then look at
the RX flag to determine if one or more IRQs may have been missed. TX/RX
flags are cleared before handling previously enabled descriptors, this
ensures that the RX/TX flags are valid when determining if IRQ should be
turned on again.
By moving TX cleaning from POLL to XMIT in the standard case, removes some
locking trouble. Enabling TX cleaning from poll only when not enough TX
descriptors are available is safe because the TX queue is at the same time
stopped, thus XMIT will not be called. The TX queue is woken up again when
enough descriptrs are available.
TX Frames are always enabled with IRQ, however the TX IRQ Enable flag will
not be enabled until XMIT must wait for free descriptors.
Locking RX and XMIT parts of the driver from each other is needed because
the RX/TX enable bits share the same register.
Signed-off-by: Daniel Hellstrom <daniel@gaisler.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2011-01-14 10:02:43 +07:00
|
|
|
/* Clean TX Ring */
|
|
|
|
greth_clean_tx(greth->netdev);
|
2010-02-15 10:33:44 +07:00
|
|
|
|
|
|
|
if (unlikely(greth->tx_free <= 0)) {
|
GRETH: resolve SMP issues and other problems
Fixes the following:
1. POLL should not enable IRQ when work is not completed
2. No locking between TX descriptor cleaning and XMIT descriptor handling
3. No locking between RX POLL and XMIT modifying control register
4. Since TX cleaning (called from POLL) is running in parallel with XMIT
unnecessary locking is needed.
5. IRQ handler looks at RX frame status solely, this is wrong when IRQ is
temporarily disabled (in POLL), and when IRQ is shared.
6. IRQ handler clears IRQ status, which is unnecessary
7. TX queue was stopped in preventing cause when not MAX_SKB_FRAGS+1
descriptors were available after a SKB been scheduled by XMIT. Instead
the TX queue is stopped first when not enough descriptors are available
upon entering XMIT.
It was hard to split up this patch in smaller pieces since all are tied
together somehow.
Note the RX flag used in the interrupt handler does not signal that
interrupt was asserted, but that a frame was received. Same goes for TX.
Also, IRQ is not asserted when the RX flag is set before enabling IRQ
enable until a new frame is received. So extra care must be taken to
avoid enabling IRQ and all descriptors are already used, hence dead lock
will upon us. See new POLL implementation that enableds IRQ then look at
the RX flag to determine if one or more IRQs may have been missed. TX/RX
flags are cleared before handling previously enabled descriptors, this
ensures that the RX/TX flags are valid when determining if IRQ should be
turned on again.
By moving TX cleaning from POLL to XMIT in the standard case, removes some
locking trouble. Enabling TX cleaning from poll only when not enough TX
descriptors are available is safe because the TX queue is at the same time
stopped, thus XMIT will not be called. The TX queue is woken up again when
enough descriptrs are available.
TX Frames are always enabled with IRQ, however the TX IRQ Enable flag will
not be enabled until XMIT must wait for free descriptors.
Locking RX and XMIT parts of the driver from each other is needed because
the RX/TX enable bits share the same register.
Signed-off-by: Daniel Hellstrom <daniel@gaisler.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2011-01-14 10:02:43 +07:00
|
|
|
spin_lock_irqsave(&greth->devlock, flags);/*save from poll/irq*/
|
|
|
|
ctrl = GRETH_REGLOAD(greth->regs->control);
|
|
|
|
/* Enable TX IRQ only if not already in poll() routine */
|
|
|
|
if (ctrl & GRETH_RXI)
|
|
|
|
GRETH_REGSAVE(greth->regs->control, ctrl | GRETH_TXI);
|
2010-02-15 10:33:44 +07:00
|
|
|
netif_stop_queue(dev);
|
GRETH: resolve SMP issues and other problems
Fixes the following:
1. POLL should not enable IRQ when work is not completed
2. No locking between TX descriptor cleaning and XMIT descriptor handling
3. No locking between RX POLL and XMIT modifying control register
4. Since TX cleaning (called from POLL) is running in parallel with XMIT
unnecessary locking is needed.
5. IRQ handler looks at RX frame status solely, this is wrong when IRQ is
temporarily disabled (in POLL), and when IRQ is shared.
6. IRQ handler clears IRQ status, which is unnecessary
7. TX queue was stopped in preventing cause when not MAX_SKB_FRAGS+1
descriptors were available after a SKB been scheduled by XMIT. Instead
the TX queue is stopped first when not enough descriptors are available
upon entering XMIT.
It was hard to split up this patch in smaller pieces since all are tied
together somehow.
Note the RX flag used in the interrupt handler does not signal that
interrupt was asserted, but that a frame was received. Same goes for TX.
Also, IRQ is not asserted when the RX flag is set before enabling IRQ
enable until a new frame is received. So extra care must be taken to
avoid enabling IRQ and all descriptors are already used, hence dead lock
will upon us. See new POLL implementation that enableds IRQ then look at
the RX flag to determine if one or more IRQs may have been missed. TX/RX
flags are cleared before handling previously enabled descriptors, this
ensures that the RX/TX flags are valid when determining if IRQ should be
turned on again.
By moving TX cleaning from POLL to XMIT in the standard case, removes some
locking trouble. Enabling TX cleaning from poll only when not enough TX
descriptors are available is safe because the TX queue is at the same time
stopped, thus XMIT will not be called. The TX queue is woken up again when
enough descriptrs are available.
TX Frames are always enabled with IRQ, however the TX IRQ Enable flag will
not be enabled until XMIT must wait for free descriptors.
Locking RX and XMIT parts of the driver from each other is needed because
the RX/TX enable bits share the same register.
Signed-off-by: Daniel Hellstrom <daniel@gaisler.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2011-01-14 10:02:43 +07:00
|
|
|
spin_unlock_irqrestore(&greth->devlock, flags);
|
2010-02-15 10:33:44 +07:00
|
|
|
return NETDEV_TX_BUSY;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (netif_msg_pktdata(greth))
|
|
|
|
greth_print_tx_packet(skb);
|
|
|
|
|
|
|
|
|
|
|
|
if (unlikely(skb->len > MAX_FRAME_SIZE)) {
|
|
|
|
dev->stats.tx_errors++;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
GRETH: resolve SMP issues and other problems
Fixes the following:
1. POLL should not enable IRQ when work is not completed
2. No locking between TX descriptor cleaning and XMIT descriptor handling
3. No locking between RX POLL and XMIT modifying control register
4. Since TX cleaning (called from POLL) is running in parallel with XMIT
unnecessary locking is needed.
5. IRQ handler looks at RX frame status solely, this is wrong when IRQ is
temporarily disabled (in POLL), and when IRQ is shared.
6. IRQ handler clears IRQ status, which is unnecessary
7. TX queue was stopped in preventing cause when not MAX_SKB_FRAGS+1
descriptors were available after a SKB been scheduled by XMIT. Instead
the TX queue is stopped first when not enough descriptors are available
upon entering XMIT.
It was hard to split up this patch in smaller pieces since all are tied
together somehow.
Note the RX flag used in the interrupt handler does not signal that
interrupt was asserted, but that a frame was received. Same goes for TX.
Also, IRQ is not asserted when the RX flag is set before enabling IRQ
enable until a new frame is received. So extra care must be taken to
avoid enabling IRQ and all descriptors are already used, hence dead lock
will upon us. See new POLL implementation that enableds IRQ then look at
the RX flag to determine if one or more IRQs may have been missed. TX/RX
flags are cleared before handling previously enabled descriptors, this
ensures that the RX/TX flags are valid when determining if IRQ should be
turned on again.
By moving TX cleaning from POLL to XMIT in the standard case, removes some
locking trouble. Enabling TX cleaning from poll only when not enough TX
descriptors are available is safe because the TX queue is at the same time
stopped, thus XMIT will not be called. The TX queue is woken up again when
enough descriptrs are available.
TX Frames are always enabled with IRQ, however the TX IRQ Enable flag will
not be enabled until XMIT must wait for free descriptors.
Locking RX and XMIT parts of the driver from each other is needed because
the RX/TX enable bits share the same register.
Signed-off-by: Daniel Hellstrom <daniel@gaisler.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2011-01-14 10:02:43 +07:00
|
|
|
bdp = greth->tx_bd_base + greth->tx_next;
|
2010-02-15 10:33:44 +07:00
|
|
|
dma_addr = greth_read_bd(&bdp->addr);
|
|
|
|
|
|
|
|
memcpy((unsigned char *) phys_to_virt(dma_addr), skb->data, skb->len);
|
|
|
|
|
|
|
|
dma_sync_single_for_device(greth->dev, dma_addr, skb->len, DMA_TO_DEVICE);
|
|
|
|
|
GRETH: resolve SMP issues and other problems
Fixes the following:
1. POLL should not enable IRQ when work is not completed
2. No locking between TX descriptor cleaning and XMIT descriptor handling
3. No locking between RX POLL and XMIT modifying control register
4. Since TX cleaning (called from POLL) is running in parallel with XMIT
unnecessary locking is needed.
5. IRQ handler looks at RX frame status solely, this is wrong when IRQ is
temporarily disabled (in POLL), and when IRQ is shared.
6. IRQ handler clears IRQ status, which is unnecessary
7. TX queue was stopped in preventing cause when not MAX_SKB_FRAGS+1
descriptors were available after a SKB been scheduled by XMIT. Instead
the TX queue is stopped first when not enough descriptors are available
upon entering XMIT.
It was hard to split up this patch in smaller pieces since all are tied
together somehow.
Note the RX flag used in the interrupt handler does not signal that
interrupt was asserted, but that a frame was received. Same goes for TX.
Also, IRQ is not asserted when the RX flag is set before enabling IRQ
enable until a new frame is received. So extra care must be taken to
avoid enabling IRQ and all descriptors are already used, hence dead lock
will upon us. See new POLL implementation that enableds IRQ then look at
the RX flag to determine if one or more IRQs may have been missed. TX/RX
flags are cleared before handling previously enabled descriptors, this
ensures that the RX/TX flags are valid when determining if IRQ should be
turned on again.
By moving TX cleaning from POLL to XMIT in the standard case, removes some
locking trouble. Enabling TX cleaning from poll only when not enough TX
descriptors are available is safe because the TX queue is at the same time
stopped, thus XMIT will not be called. The TX queue is woken up again when
enough descriptrs are available.
TX Frames are always enabled with IRQ, however the TX IRQ Enable flag will
not be enabled until XMIT must wait for free descriptors.
Locking RX and XMIT parts of the driver from each other is needed because
the RX/TX enable bits share the same register.
Signed-off-by: Daniel Hellstrom <daniel@gaisler.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2011-01-14 10:02:43 +07:00
|
|
|
status = GRETH_BD_EN | GRETH_BD_IE | (skb->len & GRETH_BD_LEN);
|
2011-09-08 10:14:35 +07:00
|
|
|
greth->tx_bufs_length[greth->tx_next] = skb->len & GRETH_BD_LEN;
|
2010-02-15 10:33:44 +07:00
|
|
|
|
|
|
|
/* Wrap around descriptor ring */
|
|
|
|
if (greth->tx_next == GRETH_TXBD_NUM_MASK) {
|
|
|
|
status |= GRETH_BD_WR;
|
|
|
|
}
|
|
|
|
|
|
|
|
greth->tx_next = NEXT_TX(greth->tx_next);
|
|
|
|
greth->tx_free--;
|
|
|
|
|
|
|
|
/* Write descriptor control word and enable transmission */
|
|
|
|
greth_write_bd(&bdp->stat, status);
|
GRETH: resolve SMP issues and other problems
Fixes the following:
1. POLL should not enable IRQ when work is not completed
2. No locking between TX descriptor cleaning and XMIT descriptor handling
3. No locking between RX POLL and XMIT modifying control register
4. Since TX cleaning (called from POLL) is running in parallel with XMIT
unnecessary locking is needed.
5. IRQ handler looks at RX frame status solely, this is wrong when IRQ is
temporarily disabled (in POLL), and when IRQ is shared.
6. IRQ handler clears IRQ status, which is unnecessary
7. TX queue was stopped in preventing cause when not MAX_SKB_FRAGS+1
descriptors were available after a SKB been scheduled by XMIT. Instead
the TX queue is stopped first when not enough descriptors are available
upon entering XMIT.
It was hard to split up this patch in smaller pieces since all are tied
together somehow.
Note the RX flag used in the interrupt handler does not signal that
interrupt was asserted, but that a frame was received. Same goes for TX.
Also, IRQ is not asserted when the RX flag is set before enabling IRQ
enable until a new frame is received. So extra care must be taken to
avoid enabling IRQ and all descriptors are already used, hence dead lock
will upon us. See new POLL implementation that enableds IRQ then look at
the RX flag to determine if one or more IRQs may have been missed. TX/RX
flags are cleared before handling previously enabled descriptors, this
ensures that the RX/TX flags are valid when determining if IRQ should be
turned on again.
By moving TX cleaning from POLL to XMIT in the standard case, removes some
locking trouble. Enabling TX cleaning from poll only when not enough TX
descriptors are available is safe because the TX queue is at the same time
stopped, thus XMIT will not be called. The TX queue is woken up again when
enough descriptrs are available.
TX Frames are always enabled with IRQ, however the TX IRQ Enable flag will
not be enabled until XMIT must wait for free descriptors.
Locking RX and XMIT parts of the driver from each other is needed because
the RX/TX enable bits share the same register.
Signed-off-by: Daniel Hellstrom <daniel@gaisler.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2011-01-14 10:02:43 +07:00
|
|
|
spin_lock_irqsave(&greth->devlock, flags); /*save from poll/irq*/
|
2010-02-15 10:33:44 +07:00
|
|
|
greth_enable_tx(greth);
|
GRETH: resolve SMP issues and other problems
Fixes the following:
1. POLL should not enable IRQ when work is not completed
2. No locking between TX descriptor cleaning and XMIT descriptor handling
3. No locking between RX POLL and XMIT modifying control register
4. Since TX cleaning (called from POLL) is running in parallel with XMIT
unnecessary locking is needed.
5. IRQ handler looks at RX frame status solely, this is wrong when IRQ is
temporarily disabled (in POLL), and when IRQ is shared.
6. IRQ handler clears IRQ status, which is unnecessary
7. TX queue was stopped in preventing cause when not MAX_SKB_FRAGS+1
descriptors were available after a SKB been scheduled by XMIT. Instead
the TX queue is stopped first when not enough descriptors are available
upon entering XMIT.
It was hard to split up this patch in smaller pieces since all are tied
together somehow.
Note the RX flag used in the interrupt handler does not signal that
interrupt was asserted, but that a frame was received. Same goes for TX.
Also, IRQ is not asserted when the RX flag is set before enabling IRQ
enable until a new frame is received. So extra care must be taken to
avoid enabling IRQ and all descriptors are already used, hence dead lock
will upon us. See new POLL implementation that enableds IRQ then look at
the RX flag to determine if one or more IRQs may have been missed. TX/RX
flags are cleared before handling previously enabled descriptors, this
ensures that the RX/TX flags are valid when determining if IRQ should be
turned on again.
By moving TX cleaning from POLL to XMIT in the standard case, removes some
locking trouble. Enabling TX cleaning from poll only when not enough TX
descriptors are available is safe because the TX queue is at the same time
stopped, thus XMIT will not be called. The TX queue is woken up again when
enough descriptrs are available.
TX Frames are always enabled with IRQ, however the TX IRQ Enable flag will
not be enabled until XMIT must wait for free descriptors.
Locking RX and XMIT parts of the driver from each other is needed because
the RX/TX enable bits share the same register.
Signed-off-by: Daniel Hellstrom <daniel@gaisler.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2011-01-14 10:02:43 +07:00
|
|
|
spin_unlock_irqrestore(&greth->devlock, flags);
|
2010-02-15 10:33:44 +07:00
|
|
|
|
|
|
|
out:
|
|
|
|
dev_kfree_skb(skb);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-24 17:25:33 +07:00
|
|
|
static netdev_tx_t
|
|
|
|
greth_start_xmit_gbit(struct sk_buff *skb, struct net_device *dev)
|
2010-02-15 10:33:44 +07:00
|
|
|
{
|
|
|
|
struct greth_private *greth = netdev_priv(dev);
|
|
|
|
struct greth_bd *bdp;
|
GRETH: resolve SMP issues and other problems
Fixes the following:
1. POLL should not enable IRQ when work is not completed
2. No locking between TX descriptor cleaning and XMIT descriptor handling
3. No locking between RX POLL and XMIT modifying control register
4. Since TX cleaning (called from POLL) is running in parallel with XMIT
unnecessary locking is needed.
5. IRQ handler looks at RX frame status solely, this is wrong when IRQ is
temporarily disabled (in POLL), and when IRQ is shared.
6. IRQ handler clears IRQ status, which is unnecessary
7. TX queue was stopped in preventing cause when not MAX_SKB_FRAGS+1
descriptors were available after a SKB been scheduled by XMIT. Instead
the TX queue is stopped first when not enough descriptors are available
upon entering XMIT.
It was hard to split up this patch in smaller pieces since all are tied
together somehow.
Note the RX flag used in the interrupt handler does not signal that
interrupt was asserted, but that a frame was received. Same goes for TX.
Also, IRQ is not asserted when the RX flag is set before enabling IRQ
enable until a new frame is received. So extra care must be taken to
avoid enabling IRQ and all descriptors are already used, hence dead lock
will upon us. See new POLL implementation that enableds IRQ then look at
the RX flag to determine if one or more IRQs may have been missed. TX/RX
flags are cleared before handling previously enabled descriptors, this
ensures that the RX/TX flags are valid when determining if IRQ should be
turned on again.
By moving TX cleaning from POLL to XMIT in the standard case, removes some
locking trouble. Enabling TX cleaning from poll only when not enough TX
descriptors are available is safe because the TX queue is at the same time
stopped, thus XMIT will not be called. The TX queue is woken up again when
enough descriptrs are available.
TX Frames are always enabled with IRQ, however the TX IRQ Enable flag will
not be enabled until XMIT must wait for free descriptors.
Locking RX and XMIT parts of the driver from each other is needed because
the RX/TX enable bits share the same register.
Signed-off-by: Daniel Hellstrom <daniel@gaisler.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2011-01-14 10:02:43 +07:00
|
|
|
u32 status = 0, dma_addr, ctrl;
|
2010-02-15 10:33:44 +07:00
|
|
|
int curr_tx, nr_frags, i, err = NETDEV_TX_OK;
|
GRETH: resolve SMP issues and other problems
Fixes the following:
1. POLL should not enable IRQ when work is not completed
2. No locking between TX descriptor cleaning and XMIT descriptor handling
3. No locking between RX POLL and XMIT modifying control register
4. Since TX cleaning (called from POLL) is running in parallel with XMIT
unnecessary locking is needed.
5. IRQ handler looks at RX frame status solely, this is wrong when IRQ is
temporarily disabled (in POLL), and when IRQ is shared.
6. IRQ handler clears IRQ status, which is unnecessary
7. TX queue was stopped in preventing cause when not MAX_SKB_FRAGS+1
descriptors were available after a SKB been scheduled by XMIT. Instead
the TX queue is stopped first when not enough descriptors are available
upon entering XMIT.
It was hard to split up this patch in smaller pieces since all are tied
together somehow.
Note the RX flag used in the interrupt handler does not signal that
interrupt was asserted, but that a frame was received. Same goes for TX.
Also, IRQ is not asserted when the RX flag is set before enabling IRQ
enable until a new frame is received. So extra care must be taken to
avoid enabling IRQ and all descriptors are already used, hence dead lock
will upon us. See new POLL implementation that enableds IRQ then look at
the RX flag to determine if one or more IRQs may have been missed. TX/RX
flags are cleared before handling previously enabled descriptors, this
ensures that the RX/TX flags are valid when determining if IRQ should be
turned on again.
By moving TX cleaning from POLL to XMIT in the standard case, removes some
locking trouble. Enabling TX cleaning from poll only when not enough TX
descriptors are available is safe because the TX queue is at the same time
stopped, thus XMIT will not be called. The TX queue is woken up again when
enough descriptrs are available.
TX Frames are always enabled with IRQ, however the TX IRQ Enable flag will
not be enabled until XMIT must wait for free descriptors.
Locking RX and XMIT parts of the driver from each other is needed because
the RX/TX enable bits share the same register.
Signed-off-by: Daniel Hellstrom <daniel@gaisler.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2011-01-14 10:02:43 +07:00
|
|
|
unsigned long flags;
|
2010-02-15 10:33:44 +07:00
|
|
|
|
|
|
|
nr_frags = skb_shinfo(skb)->nr_frags;
|
|
|
|
|
GRETH: resolve SMP issues and other problems
Fixes the following:
1. POLL should not enable IRQ when work is not completed
2. No locking between TX descriptor cleaning and XMIT descriptor handling
3. No locking between RX POLL and XMIT modifying control register
4. Since TX cleaning (called from POLL) is running in parallel with XMIT
unnecessary locking is needed.
5. IRQ handler looks at RX frame status solely, this is wrong when IRQ is
temporarily disabled (in POLL), and when IRQ is shared.
6. IRQ handler clears IRQ status, which is unnecessary
7. TX queue was stopped in preventing cause when not MAX_SKB_FRAGS+1
descriptors were available after a SKB been scheduled by XMIT. Instead
the TX queue is stopped first when not enough descriptors are available
upon entering XMIT.
It was hard to split up this patch in smaller pieces since all are tied
together somehow.
Note the RX flag used in the interrupt handler does not signal that
interrupt was asserted, but that a frame was received. Same goes for TX.
Also, IRQ is not asserted when the RX flag is set before enabling IRQ
enable until a new frame is received. So extra care must be taken to
avoid enabling IRQ and all descriptors are already used, hence dead lock
will upon us. See new POLL implementation that enableds IRQ then look at
the RX flag to determine if one or more IRQs may have been missed. TX/RX
flags are cleared before handling previously enabled descriptors, this
ensures that the RX/TX flags are valid when determining if IRQ should be
turned on again.
By moving TX cleaning from POLL to XMIT in the standard case, removes some
locking trouble. Enabling TX cleaning from poll only when not enough TX
descriptors are available is safe because the TX queue is at the same time
stopped, thus XMIT will not be called. The TX queue is woken up again when
enough descriptrs are available.
TX Frames are always enabled with IRQ, however the TX IRQ Enable flag will
not be enabled until XMIT must wait for free descriptors.
Locking RX and XMIT parts of the driver from each other is needed because
the RX/TX enable bits share the same register.
Signed-off-by: Daniel Hellstrom <daniel@gaisler.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2011-01-14 10:02:43 +07:00
|
|
|
/* Clean TX Ring */
|
|
|
|
greth_clean_tx_gbit(dev);
|
|
|
|
|
2010-02-15 10:33:44 +07:00
|
|
|
if (greth->tx_free < nr_frags + 1) {
|
GRETH: resolve SMP issues and other problems
Fixes the following:
1. POLL should not enable IRQ when work is not completed
2. No locking between TX descriptor cleaning and XMIT descriptor handling
3. No locking between RX POLL and XMIT modifying control register
4. Since TX cleaning (called from POLL) is running in parallel with XMIT
unnecessary locking is needed.
5. IRQ handler looks at RX frame status solely, this is wrong when IRQ is
temporarily disabled (in POLL), and when IRQ is shared.
6. IRQ handler clears IRQ status, which is unnecessary
7. TX queue was stopped in preventing cause when not MAX_SKB_FRAGS+1
descriptors were available after a SKB been scheduled by XMIT. Instead
the TX queue is stopped first when not enough descriptors are available
upon entering XMIT.
It was hard to split up this patch in smaller pieces since all are tied
together somehow.
Note the RX flag used in the interrupt handler does not signal that
interrupt was asserted, but that a frame was received. Same goes for TX.
Also, IRQ is not asserted when the RX flag is set before enabling IRQ
enable until a new frame is received. So extra care must be taken to
avoid enabling IRQ and all descriptors are already used, hence dead lock
will upon us. See new POLL implementation that enableds IRQ then look at
the RX flag to determine if one or more IRQs may have been missed. TX/RX
flags are cleared before handling previously enabled descriptors, this
ensures that the RX/TX flags are valid when determining if IRQ should be
turned on again.
By moving TX cleaning from POLL to XMIT in the standard case, removes some
locking trouble. Enabling TX cleaning from poll only when not enough TX
descriptors are available is safe because the TX queue is at the same time
stopped, thus XMIT will not be called. The TX queue is woken up again when
enough descriptrs are available.
TX Frames are always enabled with IRQ, however the TX IRQ Enable flag will
not be enabled until XMIT must wait for free descriptors.
Locking RX and XMIT parts of the driver from each other is needed because
the RX/TX enable bits share the same register.
Signed-off-by: Daniel Hellstrom <daniel@gaisler.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2011-01-14 10:02:43 +07:00
|
|
|
spin_lock_irqsave(&greth->devlock, flags);/*save from poll/irq*/
|
|
|
|
ctrl = GRETH_REGLOAD(greth->regs->control);
|
|
|
|
/* Enable TX IRQ only if not already in poll() routine */
|
|
|
|
if (ctrl & GRETH_RXI)
|
|
|
|
GRETH_REGSAVE(greth->regs->control, ctrl | GRETH_TXI);
|
2010-02-15 10:33:44 +07:00
|
|
|
netif_stop_queue(dev);
|
GRETH: resolve SMP issues and other problems
Fixes the following:
1. POLL should not enable IRQ when work is not completed
2. No locking between TX descriptor cleaning and XMIT descriptor handling
3. No locking between RX POLL and XMIT modifying control register
4. Since TX cleaning (called from POLL) is running in parallel with XMIT
unnecessary locking is needed.
5. IRQ handler looks at RX frame status solely, this is wrong when IRQ is
temporarily disabled (in POLL), and when IRQ is shared.
6. IRQ handler clears IRQ status, which is unnecessary
7. TX queue was stopped in preventing cause when not MAX_SKB_FRAGS+1
descriptors were available after a SKB been scheduled by XMIT. Instead
the TX queue is stopped first when not enough descriptors are available
upon entering XMIT.
It was hard to split up this patch in smaller pieces since all are tied
together somehow.
Note the RX flag used in the interrupt handler does not signal that
interrupt was asserted, but that a frame was received. Same goes for TX.
Also, IRQ is not asserted when the RX flag is set before enabling IRQ
enable until a new frame is received. So extra care must be taken to
avoid enabling IRQ and all descriptors are already used, hence dead lock
will upon us. See new POLL implementation that enableds IRQ then look at
the RX flag to determine if one or more IRQs may have been missed. TX/RX
flags are cleared before handling previously enabled descriptors, this
ensures that the RX/TX flags are valid when determining if IRQ should be
turned on again.
By moving TX cleaning from POLL to XMIT in the standard case, removes some
locking trouble. Enabling TX cleaning from poll only when not enough TX
descriptors are available is safe because the TX queue is at the same time
stopped, thus XMIT will not be called. The TX queue is woken up again when
enough descriptrs are available.
TX Frames are always enabled with IRQ, however the TX IRQ Enable flag will
not be enabled until XMIT must wait for free descriptors.
Locking RX and XMIT parts of the driver from each other is needed because
the RX/TX enable bits share the same register.
Signed-off-by: Daniel Hellstrom <daniel@gaisler.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2011-01-14 10:02:43 +07:00
|
|
|
spin_unlock_irqrestore(&greth->devlock, flags);
|
2010-02-15 10:33:44 +07:00
|
|
|
err = NETDEV_TX_BUSY;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (netif_msg_pktdata(greth))
|
|
|
|
greth_print_tx_packet(skb);
|
|
|
|
|
|
|
|
if (unlikely(skb->len > MAX_FRAME_SIZE)) {
|
|
|
|
dev->stats.tx_errors++;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Save skb pointer. */
|
|
|
|
greth->tx_skbuff[greth->tx_next] = skb;
|
|
|
|
|
|
|
|
/* Linear buf */
|
|
|
|
if (nr_frags != 0)
|
|
|
|
status = GRETH_TXBD_MORE;
|
|
|
|
|
2011-09-09 12:17:54 +07:00
|
|
|
if (skb->ip_summed == CHECKSUM_PARTIAL)
|
|
|
|
status |= GRETH_TXBD_CSALL;
|
2010-02-15 10:33:44 +07:00
|
|
|
status |= skb_headlen(skb) & GRETH_BD_LEN;
|
|
|
|
if (greth->tx_next == GRETH_TXBD_NUM_MASK)
|
|
|
|
status |= GRETH_BD_WR;
|
|
|
|
|
|
|
|
|
|
|
|
bdp = greth->tx_bd_base + greth->tx_next;
|
|
|
|
greth_write_bd(&bdp->stat, status);
|
|
|
|
dma_addr = dma_map_single(greth->dev, skb->data, skb_headlen(skb), DMA_TO_DEVICE);
|
|
|
|
|
|
|
|
if (unlikely(dma_mapping_error(greth->dev, dma_addr)))
|
|
|
|
goto map_error;
|
|
|
|
|
|
|
|
greth_write_bd(&bdp->addr, dma_addr);
|
|
|
|
|
|
|
|
curr_tx = NEXT_TX(greth->tx_next);
|
|
|
|
|
|
|
|
/* Frags */
|
|
|
|
for (i = 0; i < nr_frags; i++) {
|
|
|
|
skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
|
|
|
|
greth->tx_skbuff[curr_tx] = NULL;
|
|
|
|
bdp = greth->tx_bd_base + curr_tx;
|
|
|
|
|
2011-09-09 12:17:54 +07:00
|
|
|
status = GRETH_BD_EN;
|
|
|
|
if (skb->ip_summed == CHECKSUM_PARTIAL)
|
|
|
|
status |= GRETH_TXBD_CSALL;
|
2011-10-19 04:00:24 +07:00
|
|
|
status |= skb_frag_size(frag) & GRETH_BD_LEN;
|
2010-02-15 10:33:44 +07:00
|
|
|
|
|
|
|
/* Wrap around descriptor ring */
|
|
|
|
if (curr_tx == GRETH_TXBD_NUM_MASK)
|
|
|
|
status |= GRETH_BD_WR;
|
|
|
|
|
|
|
|
/* More fragments left */
|
|
|
|
if (i < nr_frags - 1)
|
|
|
|
status |= GRETH_TXBD_MORE;
|
GRETH: resolve SMP issues and other problems
Fixes the following:
1. POLL should not enable IRQ when work is not completed
2. No locking between TX descriptor cleaning and XMIT descriptor handling
3. No locking between RX POLL and XMIT modifying control register
4. Since TX cleaning (called from POLL) is running in parallel with XMIT
unnecessary locking is needed.
5. IRQ handler looks at RX frame status solely, this is wrong when IRQ is
temporarily disabled (in POLL), and when IRQ is shared.
6. IRQ handler clears IRQ status, which is unnecessary
7. TX queue was stopped in preventing cause when not MAX_SKB_FRAGS+1
descriptors were available after a SKB been scheduled by XMIT. Instead
the TX queue is stopped first when not enough descriptors are available
upon entering XMIT.
It was hard to split up this patch in smaller pieces since all are tied
together somehow.
Note the RX flag used in the interrupt handler does not signal that
interrupt was asserted, but that a frame was received. Same goes for TX.
Also, IRQ is not asserted when the RX flag is set before enabling IRQ
enable until a new frame is received. So extra care must be taken to
avoid enabling IRQ and all descriptors are already used, hence dead lock
will upon us. See new POLL implementation that enableds IRQ then look at
the RX flag to determine if one or more IRQs may have been missed. TX/RX
flags are cleared before handling previously enabled descriptors, this
ensures that the RX/TX flags are valid when determining if IRQ should be
turned on again.
By moving TX cleaning from POLL to XMIT in the standard case, removes some
locking trouble. Enabling TX cleaning from poll only when not enough TX
descriptors are available is safe because the TX queue is at the same time
stopped, thus XMIT will not be called. The TX queue is woken up again when
enough descriptrs are available.
TX Frames are always enabled with IRQ, however the TX IRQ Enable flag will
not be enabled until XMIT must wait for free descriptors.
Locking RX and XMIT parts of the driver from each other is needed because
the RX/TX enable bits share the same register.
Signed-off-by: Daniel Hellstrom <daniel@gaisler.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2011-01-14 10:02:43 +07:00
|
|
|
else
|
|
|
|
status |= GRETH_BD_IE; /* enable IRQ on last fragment */
|
2010-02-15 10:33:44 +07:00
|
|
|
|
|
|
|
greth_write_bd(&bdp->stat, status);
|
|
|
|
|
2011-10-19 04:00:24 +07:00
|
|
|
dma_addr = skb_frag_dma_map(greth->dev, frag, 0, skb_frag_size(frag),
|
2011-08-30 06:18:30 +07:00
|
|
|
DMA_TO_DEVICE);
|
2010-02-15 10:33:44 +07:00
|
|
|
|
|
|
|
if (unlikely(dma_mapping_error(greth->dev, dma_addr)))
|
|
|
|
goto frag_map_error;
|
|
|
|
|
|
|
|
greth_write_bd(&bdp->addr, dma_addr);
|
|
|
|
|
|
|
|
curr_tx = NEXT_TX(curr_tx);
|
|
|
|
}
|
|
|
|
|
|
|
|
wmb();
|
|
|
|
|
2011-01-14 10:02:39 +07:00
|
|
|
/* Enable the descriptor chain by enabling the first descriptor */
|
|
|
|
bdp = greth->tx_bd_base + greth->tx_next;
|
|
|
|
greth_write_bd(&bdp->stat, greth_read_bd(&bdp->stat) | GRETH_BD_EN);
|
|
|
|
greth->tx_next = curr_tx;
|
|
|
|
greth->tx_free -= nr_frags + 1;
|
|
|
|
|
|
|
|
wmb();
|
2010-02-15 10:33:44 +07:00
|
|
|
|
GRETH: resolve SMP issues and other problems
Fixes the following:
1. POLL should not enable IRQ when work is not completed
2. No locking between TX descriptor cleaning and XMIT descriptor handling
3. No locking between RX POLL and XMIT modifying control register
4. Since TX cleaning (called from POLL) is running in parallel with XMIT
unnecessary locking is needed.
5. IRQ handler looks at RX frame status solely, this is wrong when IRQ is
temporarily disabled (in POLL), and when IRQ is shared.
6. IRQ handler clears IRQ status, which is unnecessary
7. TX queue was stopped in preventing cause when not MAX_SKB_FRAGS+1
descriptors were available after a SKB been scheduled by XMIT. Instead
the TX queue is stopped first when not enough descriptors are available
upon entering XMIT.
It was hard to split up this patch in smaller pieces since all are tied
together somehow.
Note the RX flag used in the interrupt handler does not signal that
interrupt was asserted, but that a frame was received. Same goes for TX.
Also, IRQ is not asserted when the RX flag is set before enabling IRQ
enable until a new frame is received. So extra care must be taken to
avoid enabling IRQ and all descriptors are already used, hence dead lock
will upon us. See new POLL implementation that enableds IRQ then look at
the RX flag to determine if one or more IRQs may have been missed. TX/RX
flags are cleared before handling previously enabled descriptors, this
ensures that the RX/TX flags are valid when determining if IRQ should be
turned on again.
By moving TX cleaning from POLL to XMIT in the standard case, removes some
locking trouble. Enabling TX cleaning from poll only when not enough TX
descriptors are available is safe because the TX queue is at the same time
stopped, thus XMIT will not be called. The TX queue is woken up again when
enough descriptrs are available.
TX Frames are always enabled with IRQ, however the TX IRQ Enable flag will
not be enabled until XMIT must wait for free descriptors.
Locking RX and XMIT parts of the driver from each other is needed because
the RX/TX enable bits share the same register.
Signed-off-by: Daniel Hellstrom <daniel@gaisler.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2011-01-14 10:02:43 +07:00
|
|
|
spin_lock_irqsave(&greth->devlock, flags); /*save from poll/irq*/
|
2010-02-15 10:33:44 +07:00
|
|
|
greth_enable_tx(greth);
|
GRETH: resolve SMP issues and other problems
Fixes the following:
1. POLL should not enable IRQ when work is not completed
2. No locking between TX descriptor cleaning and XMIT descriptor handling
3. No locking between RX POLL and XMIT modifying control register
4. Since TX cleaning (called from POLL) is running in parallel with XMIT
unnecessary locking is needed.
5. IRQ handler looks at RX frame status solely, this is wrong when IRQ is
temporarily disabled (in POLL), and when IRQ is shared.
6. IRQ handler clears IRQ status, which is unnecessary
7. TX queue was stopped in preventing cause when not MAX_SKB_FRAGS+1
descriptors were available after a SKB been scheduled by XMIT. Instead
the TX queue is stopped first when not enough descriptors are available
upon entering XMIT.
It was hard to split up this patch in smaller pieces since all are tied
together somehow.
Note the RX flag used in the interrupt handler does not signal that
interrupt was asserted, but that a frame was received. Same goes for TX.
Also, IRQ is not asserted when the RX flag is set before enabling IRQ
enable until a new frame is received. So extra care must be taken to
avoid enabling IRQ and all descriptors are already used, hence dead lock
will upon us. See new POLL implementation that enableds IRQ then look at
the RX flag to determine if one or more IRQs may have been missed. TX/RX
flags are cleared before handling previously enabled descriptors, this
ensures that the RX/TX flags are valid when determining if IRQ should be
turned on again.
By moving TX cleaning from POLL to XMIT in the standard case, removes some
locking trouble. Enabling TX cleaning from poll only when not enough TX
descriptors are available is safe because the TX queue is at the same time
stopped, thus XMIT will not be called. The TX queue is woken up again when
enough descriptrs are available.
TX Frames are always enabled with IRQ, however the TX IRQ Enable flag will
not be enabled until XMIT must wait for free descriptors.
Locking RX and XMIT parts of the driver from each other is needed because
the RX/TX enable bits share the same register.
Signed-off-by: Daniel Hellstrom <daniel@gaisler.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2011-01-14 10:02:43 +07:00
|
|
|
spin_unlock_irqrestore(&greth->devlock, flags);
|
2010-02-15 10:33:44 +07:00
|
|
|
|
|
|
|
return NETDEV_TX_OK;
|
|
|
|
|
|
|
|
frag_map_error:
|
2011-01-14 10:02:39 +07:00
|
|
|
/* Unmap SKB mappings that succeeded and disable descriptor */
|
2010-02-15 10:33:44 +07:00
|
|
|
for (i = 0; greth->tx_next + i != curr_tx; i++) {
|
|
|
|
bdp = greth->tx_bd_base + greth->tx_next + i;
|
|
|
|
dma_unmap_single(greth->dev,
|
|
|
|
greth_read_bd(&bdp->addr),
|
|
|
|
greth_read_bd(&bdp->stat) & GRETH_BD_LEN,
|
|
|
|
DMA_TO_DEVICE);
|
2011-01-14 10:02:39 +07:00
|
|
|
greth_write_bd(&bdp->stat, 0);
|
2010-02-15 10:33:44 +07:00
|
|
|
}
|
|
|
|
map_error:
|
|
|
|
if (net_ratelimit())
|
|
|
|
dev_warn(greth->dev, "Could not create TX DMA mapping\n");
|
|
|
|
dev_kfree_skb(skb);
|
|
|
|
out:
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static irqreturn_t greth_interrupt(int irq, void *dev_id)
|
|
|
|
{
|
|
|
|
struct net_device *dev = dev_id;
|
|
|
|
struct greth_private *greth;
|
GRETH: resolve SMP issues and other problems
Fixes the following:
1. POLL should not enable IRQ when work is not completed
2. No locking between TX descriptor cleaning and XMIT descriptor handling
3. No locking between RX POLL and XMIT modifying control register
4. Since TX cleaning (called from POLL) is running in parallel with XMIT
unnecessary locking is needed.
5. IRQ handler looks at RX frame status solely, this is wrong when IRQ is
temporarily disabled (in POLL), and when IRQ is shared.
6. IRQ handler clears IRQ status, which is unnecessary
7. TX queue was stopped in preventing cause when not MAX_SKB_FRAGS+1
descriptors were available after a SKB been scheduled by XMIT. Instead
the TX queue is stopped first when not enough descriptors are available
upon entering XMIT.
It was hard to split up this patch in smaller pieces since all are tied
together somehow.
Note the RX flag used in the interrupt handler does not signal that
interrupt was asserted, but that a frame was received. Same goes for TX.
Also, IRQ is not asserted when the RX flag is set before enabling IRQ
enable until a new frame is received. So extra care must be taken to
avoid enabling IRQ and all descriptors are already used, hence dead lock
will upon us. See new POLL implementation that enableds IRQ then look at
the RX flag to determine if one or more IRQs may have been missed. TX/RX
flags are cleared before handling previously enabled descriptors, this
ensures that the RX/TX flags are valid when determining if IRQ should be
turned on again.
By moving TX cleaning from POLL to XMIT in the standard case, removes some
locking trouble. Enabling TX cleaning from poll only when not enough TX
descriptors are available is safe because the TX queue is at the same time
stopped, thus XMIT will not be called. The TX queue is woken up again when
enough descriptrs are available.
TX Frames are always enabled with IRQ, however the TX IRQ Enable flag will
not be enabled until XMIT must wait for free descriptors.
Locking RX and XMIT parts of the driver from each other is needed because
the RX/TX enable bits share the same register.
Signed-off-by: Daniel Hellstrom <daniel@gaisler.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2011-01-14 10:02:43 +07:00
|
|
|
u32 status, ctrl;
|
2010-02-15 10:33:44 +07:00
|
|
|
irqreturn_t retval = IRQ_NONE;
|
|
|
|
|
|
|
|
greth = netdev_priv(dev);
|
|
|
|
|
|
|
|
spin_lock(&greth->devlock);
|
|
|
|
|
|
|
|
/* Get the interrupt events that caused us to be here. */
|
|
|
|
status = GRETH_REGLOAD(greth->regs->status);
|
|
|
|
|
GRETH: resolve SMP issues and other problems
Fixes the following:
1. POLL should not enable IRQ when work is not completed
2. No locking between TX descriptor cleaning and XMIT descriptor handling
3. No locking between RX POLL and XMIT modifying control register
4. Since TX cleaning (called from POLL) is running in parallel with XMIT
unnecessary locking is needed.
5. IRQ handler looks at RX frame status solely, this is wrong when IRQ is
temporarily disabled (in POLL), and when IRQ is shared.
6. IRQ handler clears IRQ status, which is unnecessary
7. TX queue was stopped in preventing cause when not MAX_SKB_FRAGS+1
descriptors were available after a SKB been scheduled by XMIT. Instead
the TX queue is stopped first when not enough descriptors are available
upon entering XMIT.
It was hard to split up this patch in smaller pieces since all are tied
together somehow.
Note the RX flag used in the interrupt handler does not signal that
interrupt was asserted, but that a frame was received. Same goes for TX.
Also, IRQ is not asserted when the RX flag is set before enabling IRQ
enable until a new frame is received. So extra care must be taken to
avoid enabling IRQ and all descriptors are already used, hence dead lock
will upon us. See new POLL implementation that enableds IRQ then look at
the RX flag to determine if one or more IRQs may have been missed. TX/RX
flags are cleared before handling previously enabled descriptors, this
ensures that the RX/TX flags are valid when determining if IRQ should be
turned on again.
By moving TX cleaning from POLL to XMIT in the standard case, removes some
locking trouble. Enabling TX cleaning from poll only when not enough TX
descriptors are available is safe because the TX queue is at the same time
stopped, thus XMIT will not be called. The TX queue is woken up again when
enough descriptrs are available.
TX Frames are always enabled with IRQ, however the TX IRQ Enable flag will
not be enabled until XMIT must wait for free descriptors.
Locking RX and XMIT parts of the driver from each other is needed because
the RX/TX enable bits share the same register.
Signed-off-by: Daniel Hellstrom <daniel@gaisler.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2011-01-14 10:02:43 +07:00
|
|
|
/* Must see if interrupts are enabled also, INT_TX|INT_RX flags may be
|
|
|
|
* set regardless of whether IRQ is enabled or not. Especially
|
|
|
|
* important when shared IRQ.
|
|
|
|
*/
|
|
|
|
ctrl = GRETH_REGLOAD(greth->regs->control);
|
2010-02-15 10:33:44 +07:00
|
|
|
|
GRETH: resolve SMP issues and other problems
Fixes the following:
1. POLL should not enable IRQ when work is not completed
2. No locking between TX descriptor cleaning and XMIT descriptor handling
3. No locking between RX POLL and XMIT modifying control register
4. Since TX cleaning (called from POLL) is running in parallel with XMIT
unnecessary locking is needed.
5. IRQ handler looks at RX frame status solely, this is wrong when IRQ is
temporarily disabled (in POLL), and when IRQ is shared.
6. IRQ handler clears IRQ status, which is unnecessary
7. TX queue was stopped in preventing cause when not MAX_SKB_FRAGS+1
descriptors were available after a SKB been scheduled by XMIT. Instead
the TX queue is stopped first when not enough descriptors are available
upon entering XMIT.
It was hard to split up this patch in smaller pieces since all are tied
together somehow.
Note the RX flag used in the interrupt handler does not signal that
interrupt was asserted, but that a frame was received. Same goes for TX.
Also, IRQ is not asserted when the RX flag is set before enabling IRQ
enable until a new frame is received. So extra care must be taken to
avoid enabling IRQ and all descriptors are already used, hence dead lock
will upon us. See new POLL implementation that enableds IRQ then look at
the RX flag to determine if one or more IRQs may have been missed. TX/RX
flags are cleared before handling previously enabled descriptors, this
ensures that the RX/TX flags are valid when determining if IRQ should be
turned on again.
By moving TX cleaning from POLL to XMIT in the standard case, removes some
locking trouble. Enabling TX cleaning from poll only when not enough TX
descriptors are available is safe because the TX queue is at the same time
stopped, thus XMIT will not be called. The TX queue is woken up again when
enough descriptrs are available.
TX Frames are always enabled with IRQ, however the TX IRQ Enable flag will
not be enabled until XMIT must wait for free descriptors.
Locking RX and XMIT parts of the driver from each other is needed because
the RX/TX enable bits share the same register.
Signed-off-by: Daniel Hellstrom <daniel@gaisler.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2011-01-14 10:02:43 +07:00
|
|
|
/* Handle rx and tx interrupts through poll */
|
|
|
|
if (((status & (GRETH_INT_RE | GRETH_INT_RX)) && (ctrl & GRETH_RXI)) ||
|
|
|
|
((status & (GRETH_INT_TE | GRETH_INT_TX)) && (ctrl & GRETH_TXI))) {
|
2010-02-15 10:33:44 +07:00
|
|
|
retval = IRQ_HANDLED;
|
|
|
|
|
|
|
|
/* Disable interrupts and schedule poll() */
|
|
|
|
greth_disable_irqs(greth);
|
|
|
|
napi_schedule(&greth->napi);
|
|
|
|
}
|
|
|
|
|
|
|
|
mmiowb();
|
|
|
|
spin_unlock(&greth->devlock);
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void greth_clean_tx(struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct greth_private *greth;
|
|
|
|
struct greth_bd *bdp;
|
|
|
|
u32 stat;
|
|
|
|
|
|
|
|
greth = netdev_priv(dev);
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
bdp = greth->tx_bd_base + greth->tx_last;
|
GRETH: resolve SMP issues and other problems
Fixes the following:
1. POLL should not enable IRQ when work is not completed
2. No locking between TX descriptor cleaning and XMIT descriptor handling
3. No locking between RX POLL and XMIT modifying control register
4. Since TX cleaning (called from POLL) is running in parallel with XMIT
unnecessary locking is needed.
5. IRQ handler looks at RX frame status solely, this is wrong when IRQ is
temporarily disabled (in POLL), and when IRQ is shared.
6. IRQ handler clears IRQ status, which is unnecessary
7. TX queue was stopped in preventing cause when not MAX_SKB_FRAGS+1
descriptors were available after a SKB been scheduled by XMIT. Instead
the TX queue is stopped first when not enough descriptors are available
upon entering XMIT.
It was hard to split up this patch in smaller pieces since all are tied
together somehow.
Note the RX flag used in the interrupt handler does not signal that
interrupt was asserted, but that a frame was received. Same goes for TX.
Also, IRQ is not asserted when the RX flag is set before enabling IRQ
enable until a new frame is received. So extra care must be taken to
avoid enabling IRQ and all descriptors are already used, hence dead lock
will upon us. See new POLL implementation that enableds IRQ then look at
the RX flag to determine if one or more IRQs may have been missed. TX/RX
flags are cleared before handling previously enabled descriptors, this
ensures that the RX/TX flags are valid when determining if IRQ should be
turned on again.
By moving TX cleaning from POLL to XMIT in the standard case, removes some
locking trouble. Enabling TX cleaning from poll only when not enough TX
descriptors are available is safe because the TX queue is at the same time
stopped, thus XMIT will not be called. The TX queue is woken up again when
enough descriptrs are available.
TX Frames are always enabled with IRQ, however the TX IRQ Enable flag will
not be enabled until XMIT must wait for free descriptors.
Locking RX and XMIT parts of the driver from each other is needed because
the RX/TX enable bits share the same register.
Signed-off-by: Daniel Hellstrom <daniel@gaisler.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2011-01-14 10:02:43 +07:00
|
|
|
GRETH_REGSAVE(greth->regs->status, GRETH_INT_TE | GRETH_INT_TX);
|
|
|
|
mb();
|
2010-02-15 10:33:44 +07:00
|
|
|
stat = greth_read_bd(&bdp->stat);
|
|
|
|
|
|
|
|
if (unlikely(stat & GRETH_BD_EN))
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (greth->tx_free == GRETH_TXBD_NUM)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Check status for errors */
|
|
|
|
if (unlikely(stat & GRETH_TXBD_STATUS)) {
|
|
|
|
dev->stats.tx_errors++;
|
|
|
|
if (stat & GRETH_TXBD_ERR_AL)
|
|
|
|
dev->stats.tx_aborted_errors++;
|
|
|
|
if (stat & GRETH_TXBD_ERR_UE)
|
|
|
|
dev->stats.tx_fifo_errors++;
|
|
|
|
}
|
|
|
|
dev->stats.tx_packets++;
|
2011-09-08 10:14:35 +07:00
|
|
|
dev->stats.tx_bytes += greth->tx_bufs_length[greth->tx_last];
|
2010-02-15 10:33:44 +07:00
|
|
|
greth->tx_last = NEXT_TX(greth->tx_last);
|
|
|
|
greth->tx_free++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (greth->tx_free > 0) {
|
|
|
|
netif_wake_queue(dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void greth_update_tx_stats(struct net_device *dev, u32 stat)
|
|
|
|
{
|
|
|
|
/* Check status for errors */
|
|
|
|
if (unlikely(stat & GRETH_TXBD_STATUS)) {
|
|
|
|
dev->stats.tx_errors++;
|
|
|
|
if (stat & GRETH_TXBD_ERR_AL)
|
|
|
|
dev->stats.tx_aborted_errors++;
|
|
|
|
if (stat & GRETH_TXBD_ERR_UE)
|
|
|
|
dev->stats.tx_fifo_errors++;
|
|
|
|
if (stat & GRETH_TXBD_ERR_LC)
|
|
|
|
dev->stats.tx_aborted_errors++;
|
|
|
|
}
|
|
|
|
dev->stats.tx_packets++;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void greth_clean_tx_gbit(struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct greth_private *greth;
|
|
|
|
struct greth_bd *bdp, *bdp_last_frag;
|
|
|
|
struct sk_buff *skb;
|
|
|
|
u32 stat;
|
|
|
|
int nr_frags, i;
|
|
|
|
|
|
|
|
greth = netdev_priv(dev);
|
|
|
|
|
|
|
|
while (greth->tx_free < GRETH_TXBD_NUM) {
|
|
|
|
|
|
|
|
skb = greth->tx_skbuff[greth->tx_last];
|
|
|
|
|
|
|
|
nr_frags = skb_shinfo(skb)->nr_frags;
|
|
|
|
|
|
|
|
/* We only clean fully completed SKBs */
|
|
|
|
bdp_last_frag = greth->tx_bd_base + SKIP_TX(greth->tx_last, nr_frags);
|
GRETH: resolve SMP issues and other problems
Fixes the following:
1. POLL should not enable IRQ when work is not completed
2. No locking between TX descriptor cleaning and XMIT descriptor handling
3. No locking between RX POLL and XMIT modifying control register
4. Since TX cleaning (called from POLL) is running in parallel with XMIT
unnecessary locking is needed.
5. IRQ handler looks at RX frame status solely, this is wrong when IRQ is
temporarily disabled (in POLL), and when IRQ is shared.
6. IRQ handler clears IRQ status, which is unnecessary
7. TX queue was stopped in preventing cause when not MAX_SKB_FRAGS+1
descriptors were available after a SKB been scheduled by XMIT. Instead
the TX queue is stopped first when not enough descriptors are available
upon entering XMIT.
It was hard to split up this patch in smaller pieces since all are tied
together somehow.
Note the RX flag used in the interrupt handler does not signal that
interrupt was asserted, but that a frame was received. Same goes for TX.
Also, IRQ is not asserted when the RX flag is set before enabling IRQ
enable until a new frame is received. So extra care must be taken to
avoid enabling IRQ and all descriptors are already used, hence dead lock
will upon us. See new POLL implementation that enableds IRQ then look at
the RX flag to determine if one or more IRQs may have been missed. TX/RX
flags are cleared before handling previously enabled descriptors, this
ensures that the RX/TX flags are valid when determining if IRQ should be
turned on again.
By moving TX cleaning from POLL to XMIT in the standard case, removes some
locking trouble. Enabling TX cleaning from poll only when not enough TX
descriptors are available is safe because the TX queue is at the same time
stopped, thus XMIT will not be called. The TX queue is woken up again when
enough descriptrs are available.
TX Frames are always enabled with IRQ, however the TX IRQ Enable flag will
not be enabled until XMIT must wait for free descriptors.
Locking RX and XMIT parts of the driver from each other is needed because
the RX/TX enable bits share the same register.
Signed-off-by: Daniel Hellstrom <daniel@gaisler.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2011-01-14 10:02:43 +07:00
|
|
|
|
|
|
|
GRETH_REGSAVE(greth->regs->status, GRETH_INT_TE | GRETH_INT_TX);
|
|
|
|
mb();
|
|
|
|
stat = greth_read_bd(&bdp_last_frag->stat);
|
2010-02-15 10:33:44 +07:00
|
|
|
|
|
|
|
if (stat & GRETH_BD_EN)
|
|
|
|
break;
|
|
|
|
|
|
|
|
greth->tx_skbuff[greth->tx_last] = NULL;
|
|
|
|
|
|
|
|
greth_update_tx_stats(dev, stat);
|
2011-09-08 10:14:35 +07:00
|
|
|
dev->stats.tx_bytes += skb->len;
|
2010-02-15 10:33:44 +07:00
|
|
|
|
|
|
|
bdp = greth->tx_bd_base + greth->tx_last;
|
|
|
|
|
|
|
|
greth->tx_last = NEXT_TX(greth->tx_last);
|
|
|
|
|
|
|
|
dma_unmap_single(greth->dev,
|
|
|
|
greth_read_bd(&bdp->addr),
|
|
|
|
skb_headlen(skb),
|
|
|
|
DMA_TO_DEVICE);
|
|
|
|
|
|
|
|
for (i = 0; i < nr_frags; i++) {
|
|
|
|
skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
|
|
|
|
bdp = greth->tx_bd_base + greth->tx_last;
|
|
|
|
|
|
|
|
dma_unmap_page(greth->dev,
|
|
|
|
greth_read_bd(&bdp->addr),
|
2011-10-19 04:00:24 +07:00
|
|
|
skb_frag_size(frag),
|
2010-02-15 10:33:44 +07:00
|
|
|
DMA_TO_DEVICE);
|
|
|
|
|
|
|
|
greth->tx_last = NEXT_TX(greth->tx_last);
|
|
|
|
}
|
|
|
|
greth->tx_free += nr_frags+1;
|
|
|
|
dev_kfree_skb(skb);
|
|
|
|
}
|
|
|
|
|
GRETH: resolve SMP issues and other problems
Fixes the following:
1. POLL should not enable IRQ when work is not completed
2. No locking between TX descriptor cleaning and XMIT descriptor handling
3. No locking between RX POLL and XMIT modifying control register
4. Since TX cleaning (called from POLL) is running in parallel with XMIT
unnecessary locking is needed.
5. IRQ handler looks at RX frame status solely, this is wrong when IRQ is
temporarily disabled (in POLL), and when IRQ is shared.
6. IRQ handler clears IRQ status, which is unnecessary
7. TX queue was stopped in preventing cause when not MAX_SKB_FRAGS+1
descriptors were available after a SKB been scheduled by XMIT. Instead
the TX queue is stopped first when not enough descriptors are available
upon entering XMIT.
It was hard to split up this patch in smaller pieces since all are tied
together somehow.
Note the RX flag used in the interrupt handler does not signal that
interrupt was asserted, but that a frame was received. Same goes for TX.
Also, IRQ is not asserted when the RX flag is set before enabling IRQ
enable until a new frame is received. So extra care must be taken to
avoid enabling IRQ and all descriptors are already used, hence dead lock
will upon us. See new POLL implementation that enableds IRQ then look at
the RX flag to determine if one or more IRQs may have been missed. TX/RX
flags are cleared before handling previously enabled descriptors, this
ensures that the RX/TX flags are valid when determining if IRQ should be
turned on again.
By moving TX cleaning from POLL to XMIT in the standard case, removes some
locking trouble. Enabling TX cleaning from poll only when not enough TX
descriptors are available is safe because the TX queue is at the same time
stopped, thus XMIT will not be called. The TX queue is woken up again when
enough descriptrs are available.
TX Frames are always enabled with IRQ, however the TX IRQ Enable flag will
not be enabled until XMIT must wait for free descriptors.
Locking RX and XMIT parts of the driver from each other is needed because
the RX/TX enable bits share the same register.
Signed-off-by: Daniel Hellstrom <daniel@gaisler.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2011-01-14 10:02:43 +07:00
|
|
|
if (netif_queue_stopped(dev) && (greth->tx_free > (MAX_SKB_FRAGS+1)))
|
|
|
|
netif_wake_queue(dev);
|
2010-02-15 10:33:44 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static int greth_rx(struct net_device *dev, int limit)
|
|
|
|
{
|
|
|
|
struct greth_private *greth;
|
|
|
|
struct greth_bd *bdp;
|
|
|
|
struct sk_buff *skb;
|
|
|
|
int pkt_len;
|
|
|
|
int bad, count;
|
|
|
|
u32 status, dma_addr;
|
GRETH: resolve SMP issues and other problems
Fixes the following:
1. POLL should not enable IRQ when work is not completed
2. No locking between TX descriptor cleaning and XMIT descriptor handling
3. No locking between RX POLL and XMIT modifying control register
4. Since TX cleaning (called from POLL) is running in parallel with XMIT
unnecessary locking is needed.
5. IRQ handler looks at RX frame status solely, this is wrong when IRQ is
temporarily disabled (in POLL), and when IRQ is shared.
6. IRQ handler clears IRQ status, which is unnecessary
7. TX queue was stopped in preventing cause when not MAX_SKB_FRAGS+1
descriptors were available after a SKB been scheduled by XMIT. Instead
the TX queue is stopped first when not enough descriptors are available
upon entering XMIT.
It was hard to split up this patch in smaller pieces since all are tied
together somehow.
Note the RX flag used in the interrupt handler does not signal that
interrupt was asserted, but that a frame was received. Same goes for TX.
Also, IRQ is not asserted when the RX flag is set before enabling IRQ
enable until a new frame is received. So extra care must be taken to
avoid enabling IRQ and all descriptors are already used, hence dead lock
will upon us. See new POLL implementation that enableds IRQ then look at
the RX flag to determine if one or more IRQs may have been missed. TX/RX
flags are cleared before handling previously enabled descriptors, this
ensures that the RX/TX flags are valid when determining if IRQ should be
turned on again.
By moving TX cleaning from POLL to XMIT in the standard case, removes some
locking trouble. Enabling TX cleaning from poll only when not enough TX
descriptors are available is safe because the TX queue is at the same time
stopped, thus XMIT will not be called. The TX queue is woken up again when
enough descriptrs are available.
TX Frames are always enabled with IRQ, however the TX IRQ Enable flag will
not be enabled until XMIT must wait for free descriptors.
Locking RX and XMIT parts of the driver from each other is needed because
the RX/TX enable bits share the same register.
Signed-off-by: Daniel Hellstrom <daniel@gaisler.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2011-01-14 10:02:43 +07:00
|
|
|
unsigned long flags;
|
2010-02-15 10:33:44 +07:00
|
|
|
|
|
|
|
greth = netdev_priv(dev);
|
|
|
|
|
|
|
|
for (count = 0; count < limit; ++count) {
|
|
|
|
|
|
|
|
bdp = greth->rx_bd_base + greth->rx_cur;
|
GRETH: resolve SMP issues and other problems
Fixes the following:
1. POLL should not enable IRQ when work is not completed
2. No locking between TX descriptor cleaning and XMIT descriptor handling
3. No locking between RX POLL and XMIT modifying control register
4. Since TX cleaning (called from POLL) is running in parallel with XMIT
unnecessary locking is needed.
5. IRQ handler looks at RX frame status solely, this is wrong when IRQ is
temporarily disabled (in POLL), and when IRQ is shared.
6. IRQ handler clears IRQ status, which is unnecessary
7. TX queue was stopped in preventing cause when not MAX_SKB_FRAGS+1
descriptors were available after a SKB been scheduled by XMIT. Instead
the TX queue is stopped first when not enough descriptors are available
upon entering XMIT.
It was hard to split up this patch in smaller pieces since all are tied
together somehow.
Note the RX flag used in the interrupt handler does not signal that
interrupt was asserted, but that a frame was received. Same goes for TX.
Also, IRQ is not asserted when the RX flag is set before enabling IRQ
enable until a new frame is received. So extra care must be taken to
avoid enabling IRQ and all descriptors are already used, hence dead lock
will upon us. See new POLL implementation that enableds IRQ then look at
the RX flag to determine if one or more IRQs may have been missed. TX/RX
flags are cleared before handling previously enabled descriptors, this
ensures that the RX/TX flags are valid when determining if IRQ should be
turned on again.
By moving TX cleaning from POLL to XMIT in the standard case, removes some
locking trouble. Enabling TX cleaning from poll only when not enough TX
descriptors are available is safe because the TX queue is at the same time
stopped, thus XMIT will not be called. The TX queue is woken up again when
enough descriptrs are available.
TX Frames are always enabled with IRQ, however the TX IRQ Enable flag will
not be enabled until XMIT must wait for free descriptors.
Locking RX and XMIT parts of the driver from each other is needed because
the RX/TX enable bits share the same register.
Signed-off-by: Daniel Hellstrom <daniel@gaisler.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2011-01-14 10:02:43 +07:00
|
|
|
GRETH_REGSAVE(greth->regs->status, GRETH_INT_RE | GRETH_INT_RX);
|
|
|
|
mb();
|
2010-02-15 10:33:44 +07:00
|
|
|
status = greth_read_bd(&bdp->stat);
|
|
|
|
|
|
|
|
if (unlikely(status & GRETH_BD_EN)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
GRETH: resolve SMP issues and other problems
Fixes the following:
1. POLL should not enable IRQ when work is not completed
2. No locking between TX descriptor cleaning and XMIT descriptor handling
3. No locking between RX POLL and XMIT modifying control register
4. Since TX cleaning (called from POLL) is running in parallel with XMIT
unnecessary locking is needed.
5. IRQ handler looks at RX frame status solely, this is wrong when IRQ is
temporarily disabled (in POLL), and when IRQ is shared.
6. IRQ handler clears IRQ status, which is unnecessary
7. TX queue was stopped in preventing cause when not MAX_SKB_FRAGS+1
descriptors were available after a SKB been scheduled by XMIT. Instead
the TX queue is stopped first when not enough descriptors are available
upon entering XMIT.
It was hard to split up this patch in smaller pieces since all are tied
together somehow.
Note the RX flag used in the interrupt handler does not signal that
interrupt was asserted, but that a frame was received. Same goes for TX.
Also, IRQ is not asserted when the RX flag is set before enabling IRQ
enable until a new frame is received. So extra care must be taken to
avoid enabling IRQ and all descriptors are already used, hence dead lock
will upon us. See new POLL implementation that enableds IRQ then look at
the RX flag to determine if one or more IRQs may have been missed. TX/RX
flags are cleared before handling previously enabled descriptors, this
ensures that the RX/TX flags are valid when determining if IRQ should be
turned on again.
By moving TX cleaning from POLL to XMIT in the standard case, removes some
locking trouble. Enabling TX cleaning from poll only when not enough TX
descriptors are available is safe because the TX queue is at the same time
stopped, thus XMIT will not be called. The TX queue is woken up again when
enough descriptrs are available.
TX Frames are always enabled with IRQ, however the TX IRQ Enable flag will
not be enabled until XMIT must wait for free descriptors.
Locking RX and XMIT parts of the driver from each other is needed because
the RX/TX enable bits share the same register.
Signed-off-by: Daniel Hellstrom <daniel@gaisler.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2011-01-14 10:02:43 +07:00
|
|
|
dma_addr = greth_read_bd(&bdp->addr);
|
|
|
|
bad = 0;
|
|
|
|
|
2010-02-15 10:33:44 +07:00
|
|
|
/* Check status for errors. */
|
|
|
|
if (unlikely(status & GRETH_RXBD_STATUS)) {
|
|
|
|
if (status & GRETH_RXBD_ERR_FT) {
|
|
|
|
dev->stats.rx_length_errors++;
|
|
|
|
bad = 1;
|
|
|
|
}
|
|
|
|
if (status & (GRETH_RXBD_ERR_AE | GRETH_RXBD_ERR_OE)) {
|
|
|
|
dev->stats.rx_frame_errors++;
|
|
|
|
bad = 1;
|
|
|
|
}
|
|
|
|
if (status & GRETH_RXBD_ERR_CRC) {
|
|
|
|
dev->stats.rx_crc_errors++;
|
|
|
|
bad = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (unlikely(bad)) {
|
|
|
|
dev->stats.rx_errors++;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
pkt_len = status & GRETH_BD_LEN;
|
|
|
|
|
|
|
|
skb = netdev_alloc_skb(dev, pkt_len + NET_IP_ALIGN);
|
|
|
|
|
|
|
|
if (unlikely(skb == NULL)) {
|
|
|
|
|
|
|
|
if (net_ratelimit())
|
|
|
|
dev_warn(&dev->dev, "low on memory - " "packet dropped\n");
|
|
|
|
|
|
|
|
dev->stats.rx_dropped++;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
skb_reserve(skb, NET_IP_ALIGN);
|
|
|
|
|
|
|
|
dma_sync_single_for_cpu(greth->dev,
|
|
|
|
dma_addr,
|
|
|
|
pkt_len,
|
|
|
|
DMA_FROM_DEVICE);
|
|
|
|
|
|
|
|
if (netif_msg_pktdata(greth))
|
|
|
|
greth_print_rx_packet(phys_to_virt(dma_addr), pkt_len);
|
|
|
|
|
|
|
|
memcpy(skb_put(skb, pkt_len), phys_to_virt(dma_addr), pkt_len);
|
|
|
|
|
|
|
|
skb->protocol = eth_type_trans(skb, dev);
|
2011-09-08 10:14:35 +07:00
|
|
|
dev->stats.rx_bytes += pkt_len;
|
2010-02-15 10:33:44 +07:00
|
|
|
dev->stats.rx_packets++;
|
|
|
|
netif_receive_skb(skb);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
status = GRETH_BD_EN | GRETH_BD_IE;
|
|
|
|
if (greth->rx_cur == GRETH_RXBD_NUM_MASK) {
|
|
|
|
status |= GRETH_BD_WR;
|
|
|
|
}
|
|
|
|
|
|
|
|
wmb();
|
|
|
|
greth_write_bd(&bdp->stat, status);
|
|
|
|
|
|
|
|
dma_sync_single_for_device(greth->dev, dma_addr, MAX_FRAME_SIZE, DMA_FROM_DEVICE);
|
|
|
|
|
GRETH: resolve SMP issues and other problems
Fixes the following:
1. POLL should not enable IRQ when work is not completed
2. No locking between TX descriptor cleaning and XMIT descriptor handling
3. No locking between RX POLL and XMIT modifying control register
4. Since TX cleaning (called from POLL) is running in parallel with XMIT
unnecessary locking is needed.
5. IRQ handler looks at RX frame status solely, this is wrong when IRQ is
temporarily disabled (in POLL), and when IRQ is shared.
6. IRQ handler clears IRQ status, which is unnecessary
7. TX queue was stopped in preventing cause when not MAX_SKB_FRAGS+1
descriptors were available after a SKB been scheduled by XMIT. Instead
the TX queue is stopped first when not enough descriptors are available
upon entering XMIT.
It was hard to split up this patch in smaller pieces since all are tied
together somehow.
Note the RX flag used in the interrupt handler does not signal that
interrupt was asserted, but that a frame was received. Same goes for TX.
Also, IRQ is not asserted when the RX flag is set before enabling IRQ
enable until a new frame is received. So extra care must be taken to
avoid enabling IRQ and all descriptors are already used, hence dead lock
will upon us. See new POLL implementation that enableds IRQ then look at
the RX flag to determine if one or more IRQs may have been missed. TX/RX
flags are cleared before handling previously enabled descriptors, this
ensures that the RX/TX flags are valid when determining if IRQ should be
turned on again.
By moving TX cleaning from POLL to XMIT in the standard case, removes some
locking trouble. Enabling TX cleaning from poll only when not enough TX
descriptors are available is safe because the TX queue is at the same time
stopped, thus XMIT will not be called. The TX queue is woken up again when
enough descriptrs are available.
TX Frames are always enabled with IRQ, however the TX IRQ Enable flag will
not be enabled until XMIT must wait for free descriptors.
Locking RX and XMIT parts of the driver from each other is needed because
the RX/TX enable bits share the same register.
Signed-off-by: Daniel Hellstrom <daniel@gaisler.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2011-01-14 10:02:43 +07:00
|
|
|
spin_lock_irqsave(&greth->devlock, flags); /* save from XMIT */
|
2010-02-15 10:33:44 +07:00
|
|
|
greth_enable_rx(greth);
|
GRETH: resolve SMP issues and other problems
Fixes the following:
1. POLL should not enable IRQ when work is not completed
2. No locking between TX descriptor cleaning and XMIT descriptor handling
3. No locking between RX POLL and XMIT modifying control register
4. Since TX cleaning (called from POLL) is running in parallel with XMIT
unnecessary locking is needed.
5. IRQ handler looks at RX frame status solely, this is wrong when IRQ is
temporarily disabled (in POLL), and when IRQ is shared.
6. IRQ handler clears IRQ status, which is unnecessary
7. TX queue was stopped in preventing cause when not MAX_SKB_FRAGS+1
descriptors were available after a SKB been scheduled by XMIT. Instead
the TX queue is stopped first when not enough descriptors are available
upon entering XMIT.
It was hard to split up this patch in smaller pieces since all are tied
together somehow.
Note the RX flag used in the interrupt handler does not signal that
interrupt was asserted, but that a frame was received. Same goes for TX.
Also, IRQ is not asserted when the RX flag is set before enabling IRQ
enable until a new frame is received. So extra care must be taken to
avoid enabling IRQ and all descriptors are already used, hence dead lock
will upon us. See new POLL implementation that enableds IRQ then look at
the RX flag to determine if one or more IRQs may have been missed. TX/RX
flags are cleared before handling previously enabled descriptors, this
ensures that the RX/TX flags are valid when determining if IRQ should be
turned on again.
By moving TX cleaning from POLL to XMIT in the standard case, removes some
locking trouble. Enabling TX cleaning from poll only when not enough TX
descriptors are available is safe because the TX queue is at the same time
stopped, thus XMIT will not be called. The TX queue is woken up again when
enough descriptrs are available.
TX Frames are always enabled with IRQ, however the TX IRQ Enable flag will
not be enabled until XMIT must wait for free descriptors.
Locking RX and XMIT parts of the driver from each other is needed because
the RX/TX enable bits share the same register.
Signed-off-by: Daniel Hellstrom <daniel@gaisler.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2011-01-14 10:02:43 +07:00
|
|
|
spin_unlock_irqrestore(&greth->devlock, flags);
|
2010-02-15 10:33:44 +07:00
|
|
|
|
|
|
|
greth->rx_cur = NEXT_RX(greth->rx_cur);
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int hw_checksummed(u32 status)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (status & GRETH_RXBD_IP_FRAG)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (status & GRETH_RXBD_IP && status & GRETH_RXBD_IP_CSERR)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (status & GRETH_RXBD_UDP && status & GRETH_RXBD_UDP_CSERR)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (status & GRETH_RXBD_TCP && status & GRETH_RXBD_TCP_CSERR)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int greth_rx_gbit(struct net_device *dev, int limit)
|
|
|
|
{
|
|
|
|
struct greth_private *greth;
|
|
|
|
struct greth_bd *bdp;
|
|
|
|
struct sk_buff *skb, *newskb;
|
|
|
|
int pkt_len;
|
|
|
|
int bad, count = 0;
|
|
|
|
u32 status, dma_addr;
|
GRETH: resolve SMP issues and other problems
Fixes the following:
1. POLL should not enable IRQ when work is not completed
2. No locking between TX descriptor cleaning and XMIT descriptor handling
3. No locking between RX POLL and XMIT modifying control register
4. Since TX cleaning (called from POLL) is running in parallel with XMIT
unnecessary locking is needed.
5. IRQ handler looks at RX frame status solely, this is wrong when IRQ is
temporarily disabled (in POLL), and when IRQ is shared.
6. IRQ handler clears IRQ status, which is unnecessary
7. TX queue was stopped in preventing cause when not MAX_SKB_FRAGS+1
descriptors were available after a SKB been scheduled by XMIT. Instead
the TX queue is stopped first when not enough descriptors are available
upon entering XMIT.
It was hard to split up this patch in smaller pieces since all are tied
together somehow.
Note the RX flag used in the interrupt handler does not signal that
interrupt was asserted, but that a frame was received. Same goes for TX.
Also, IRQ is not asserted when the RX flag is set before enabling IRQ
enable until a new frame is received. So extra care must be taken to
avoid enabling IRQ and all descriptors are already used, hence dead lock
will upon us. See new POLL implementation that enableds IRQ then look at
the RX flag to determine if one or more IRQs may have been missed. TX/RX
flags are cleared before handling previously enabled descriptors, this
ensures that the RX/TX flags are valid when determining if IRQ should be
turned on again.
By moving TX cleaning from POLL to XMIT in the standard case, removes some
locking trouble. Enabling TX cleaning from poll only when not enough TX
descriptors are available is safe because the TX queue is at the same time
stopped, thus XMIT will not be called. The TX queue is woken up again when
enough descriptrs are available.
TX Frames are always enabled with IRQ, however the TX IRQ Enable flag will
not be enabled until XMIT must wait for free descriptors.
Locking RX and XMIT parts of the driver from each other is needed because
the RX/TX enable bits share the same register.
Signed-off-by: Daniel Hellstrom <daniel@gaisler.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2011-01-14 10:02:43 +07:00
|
|
|
unsigned long flags;
|
2010-02-15 10:33:44 +07:00
|
|
|
|
|
|
|
greth = netdev_priv(dev);
|
|
|
|
|
|
|
|
for (count = 0; count < limit; ++count) {
|
|
|
|
|
|
|
|
bdp = greth->rx_bd_base + greth->rx_cur;
|
|
|
|
skb = greth->rx_skbuff[greth->rx_cur];
|
GRETH: resolve SMP issues and other problems
Fixes the following:
1. POLL should not enable IRQ when work is not completed
2. No locking between TX descriptor cleaning and XMIT descriptor handling
3. No locking between RX POLL and XMIT modifying control register
4. Since TX cleaning (called from POLL) is running in parallel with XMIT
unnecessary locking is needed.
5. IRQ handler looks at RX frame status solely, this is wrong when IRQ is
temporarily disabled (in POLL), and when IRQ is shared.
6. IRQ handler clears IRQ status, which is unnecessary
7. TX queue was stopped in preventing cause when not MAX_SKB_FRAGS+1
descriptors were available after a SKB been scheduled by XMIT. Instead
the TX queue is stopped first when not enough descriptors are available
upon entering XMIT.
It was hard to split up this patch in smaller pieces since all are tied
together somehow.
Note the RX flag used in the interrupt handler does not signal that
interrupt was asserted, but that a frame was received. Same goes for TX.
Also, IRQ is not asserted when the RX flag is set before enabling IRQ
enable until a new frame is received. So extra care must be taken to
avoid enabling IRQ and all descriptors are already used, hence dead lock
will upon us. See new POLL implementation that enableds IRQ then look at
the RX flag to determine if one or more IRQs may have been missed. TX/RX
flags are cleared before handling previously enabled descriptors, this
ensures that the RX/TX flags are valid when determining if IRQ should be
turned on again.
By moving TX cleaning from POLL to XMIT in the standard case, removes some
locking trouble. Enabling TX cleaning from poll only when not enough TX
descriptors are available is safe because the TX queue is at the same time
stopped, thus XMIT will not be called. The TX queue is woken up again when
enough descriptrs are available.
TX Frames are always enabled with IRQ, however the TX IRQ Enable flag will
not be enabled until XMIT must wait for free descriptors.
Locking RX and XMIT parts of the driver from each other is needed because
the RX/TX enable bits share the same register.
Signed-off-by: Daniel Hellstrom <daniel@gaisler.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2011-01-14 10:02:43 +07:00
|
|
|
GRETH_REGSAVE(greth->regs->status, GRETH_INT_RE | GRETH_INT_RX);
|
|
|
|
mb();
|
2010-02-15 10:33:44 +07:00
|
|
|
status = greth_read_bd(&bdp->stat);
|
|
|
|
bad = 0;
|
|
|
|
|
|
|
|
if (status & GRETH_BD_EN)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Check status for errors. */
|
|
|
|
if (unlikely(status & GRETH_RXBD_STATUS)) {
|
|
|
|
|
|
|
|
if (status & GRETH_RXBD_ERR_FT) {
|
|
|
|
dev->stats.rx_length_errors++;
|
|
|
|
bad = 1;
|
|
|
|
} else if (status &
|
|
|
|
(GRETH_RXBD_ERR_AE | GRETH_RXBD_ERR_OE | GRETH_RXBD_ERR_LE)) {
|
|
|
|
dev->stats.rx_frame_errors++;
|
|
|
|
bad = 1;
|
|
|
|
} else if (status & GRETH_RXBD_ERR_CRC) {
|
|
|
|
dev->stats.rx_crc_errors++;
|
|
|
|
bad = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-14 10:02:40 +07:00
|
|
|
/* Allocate new skb to replace current, not needed if the
|
|
|
|
* current skb can be reused */
|
|
|
|
if (!bad && (newskb=netdev_alloc_skb(dev, MAX_FRAME_SIZE + NET_IP_ALIGN))) {
|
2010-02-15 10:33:44 +07:00
|
|
|
skb_reserve(newskb, NET_IP_ALIGN);
|
|
|
|
|
|
|
|
dma_addr = dma_map_single(greth->dev,
|
|
|
|
newskb->data,
|
|
|
|
MAX_FRAME_SIZE + NET_IP_ALIGN,
|
|
|
|
DMA_FROM_DEVICE);
|
|
|
|
|
|
|
|
if (!dma_mapping_error(greth->dev, dma_addr)) {
|
|
|
|
/* Process the incoming frame. */
|
|
|
|
pkt_len = status & GRETH_BD_LEN;
|
|
|
|
|
|
|
|
dma_unmap_single(greth->dev,
|
|
|
|
greth_read_bd(&bdp->addr),
|
|
|
|
MAX_FRAME_SIZE + NET_IP_ALIGN,
|
|
|
|
DMA_FROM_DEVICE);
|
|
|
|
|
|
|
|
if (netif_msg_pktdata(greth))
|
|
|
|
greth_print_rx_packet(phys_to_virt(greth_read_bd(&bdp->addr)), pkt_len);
|
|
|
|
|
|
|
|
skb_put(skb, pkt_len);
|
|
|
|
|
2011-04-17 07:15:47 +07:00
|
|
|
if (dev->features & NETIF_F_RXCSUM && hw_checksummed(status))
|
2010-02-15 10:33:44 +07:00
|
|
|
skb->ip_summed = CHECKSUM_UNNECESSARY;
|
|
|
|
else
|
2010-09-03 03:07:41 +07:00
|
|
|
skb_checksum_none_assert(skb);
|
2010-02-15 10:33:44 +07:00
|
|
|
|
|
|
|
skb->protocol = eth_type_trans(skb, dev);
|
|
|
|
dev->stats.rx_packets++;
|
2011-09-08 10:14:35 +07:00
|
|
|
dev->stats.rx_bytes += pkt_len;
|
2010-02-15 10:33:44 +07:00
|
|
|
netif_receive_skb(skb);
|
|
|
|
|
|
|
|
greth->rx_skbuff[greth->rx_cur] = newskb;
|
|
|
|
greth_write_bd(&bdp->addr, dma_addr);
|
|
|
|
} else {
|
|
|
|
if (net_ratelimit())
|
|
|
|
dev_warn(greth->dev, "Could not create DMA mapping, dropping packet\n");
|
|
|
|
dev_kfree_skb(newskb);
|
2011-01-14 10:02:40 +07:00
|
|
|
/* reusing current skb, so it is a drop */
|
2010-02-15 10:33:44 +07:00
|
|
|
dev->stats.rx_dropped++;
|
|
|
|
}
|
2011-01-14 10:02:40 +07:00
|
|
|
} else if (bad) {
|
|
|
|
/* Bad Frame transfer, the skb is reused */
|
|
|
|
dev->stats.rx_dropped++;
|
2010-02-15 10:33:44 +07:00
|
|
|
} else {
|
2011-01-14 10:02:40 +07:00
|
|
|
/* Failed Allocating a new skb. This is rather stupid
|
|
|
|
* but the current "filled" skb is reused, as if
|
|
|
|
* transfer failure. One could argue that RX descriptor
|
|
|
|
* table handling should be divided into cleaning and
|
|
|
|
* filling as the TX part of the driver
|
|
|
|
*/
|
2010-02-15 10:33:44 +07:00
|
|
|
if (net_ratelimit())
|
|
|
|
dev_warn(greth->dev, "Could not allocate SKB, dropping packet\n");
|
2011-01-14 10:02:40 +07:00
|
|
|
/* reusing current skb, so it is a drop */
|
2010-02-15 10:33:44 +07:00
|
|
|
dev->stats.rx_dropped++;
|
|
|
|
}
|
|
|
|
|
|
|
|
status = GRETH_BD_EN | GRETH_BD_IE;
|
|
|
|
if (greth->rx_cur == GRETH_RXBD_NUM_MASK) {
|
|
|
|
status |= GRETH_BD_WR;
|
|
|
|
}
|
|
|
|
|
|
|
|
wmb();
|
|
|
|
greth_write_bd(&bdp->stat, status);
|
GRETH: resolve SMP issues and other problems
Fixes the following:
1. POLL should not enable IRQ when work is not completed
2. No locking between TX descriptor cleaning and XMIT descriptor handling
3. No locking between RX POLL and XMIT modifying control register
4. Since TX cleaning (called from POLL) is running in parallel with XMIT
unnecessary locking is needed.
5. IRQ handler looks at RX frame status solely, this is wrong when IRQ is
temporarily disabled (in POLL), and when IRQ is shared.
6. IRQ handler clears IRQ status, which is unnecessary
7. TX queue was stopped in preventing cause when not MAX_SKB_FRAGS+1
descriptors were available after a SKB been scheduled by XMIT. Instead
the TX queue is stopped first when not enough descriptors are available
upon entering XMIT.
It was hard to split up this patch in smaller pieces since all are tied
together somehow.
Note the RX flag used in the interrupt handler does not signal that
interrupt was asserted, but that a frame was received. Same goes for TX.
Also, IRQ is not asserted when the RX flag is set before enabling IRQ
enable until a new frame is received. So extra care must be taken to
avoid enabling IRQ and all descriptors are already used, hence dead lock
will upon us. See new POLL implementation that enableds IRQ then look at
the RX flag to determine if one or more IRQs may have been missed. TX/RX
flags are cleared before handling previously enabled descriptors, this
ensures that the RX/TX flags are valid when determining if IRQ should be
turned on again.
By moving TX cleaning from POLL to XMIT in the standard case, removes some
locking trouble. Enabling TX cleaning from poll only when not enough TX
descriptors are available is safe because the TX queue is at the same time
stopped, thus XMIT will not be called. The TX queue is woken up again when
enough descriptrs are available.
TX Frames are always enabled with IRQ, however the TX IRQ Enable flag will
not be enabled until XMIT must wait for free descriptors.
Locking RX and XMIT parts of the driver from each other is needed because
the RX/TX enable bits share the same register.
Signed-off-by: Daniel Hellstrom <daniel@gaisler.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2011-01-14 10:02:43 +07:00
|
|
|
spin_lock_irqsave(&greth->devlock, flags);
|
2010-02-15 10:33:44 +07:00
|
|
|
greth_enable_rx(greth);
|
GRETH: resolve SMP issues and other problems
Fixes the following:
1. POLL should not enable IRQ when work is not completed
2. No locking between TX descriptor cleaning and XMIT descriptor handling
3. No locking between RX POLL and XMIT modifying control register
4. Since TX cleaning (called from POLL) is running in parallel with XMIT
unnecessary locking is needed.
5. IRQ handler looks at RX frame status solely, this is wrong when IRQ is
temporarily disabled (in POLL), and when IRQ is shared.
6. IRQ handler clears IRQ status, which is unnecessary
7. TX queue was stopped in preventing cause when not MAX_SKB_FRAGS+1
descriptors were available after a SKB been scheduled by XMIT. Instead
the TX queue is stopped first when not enough descriptors are available
upon entering XMIT.
It was hard to split up this patch in smaller pieces since all are tied
together somehow.
Note the RX flag used in the interrupt handler does not signal that
interrupt was asserted, but that a frame was received. Same goes for TX.
Also, IRQ is not asserted when the RX flag is set before enabling IRQ
enable until a new frame is received. So extra care must be taken to
avoid enabling IRQ and all descriptors are already used, hence dead lock
will upon us. See new POLL implementation that enableds IRQ then look at
the RX flag to determine if one or more IRQs may have been missed. TX/RX
flags are cleared before handling previously enabled descriptors, this
ensures that the RX/TX flags are valid when determining if IRQ should be
turned on again.
By moving TX cleaning from POLL to XMIT in the standard case, removes some
locking trouble. Enabling TX cleaning from poll only when not enough TX
descriptors are available is safe because the TX queue is at the same time
stopped, thus XMIT will not be called. The TX queue is woken up again when
enough descriptrs are available.
TX Frames are always enabled with IRQ, however the TX IRQ Enable flag will
not be enabled until XMIT must wait for free descriptors.
Locking RX and XMIT parts of the driver from each other is needed because
the RX/TX enable bits share the same register.
Signed-off-by: Daniel Hellstrom <daniel@gaisler.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2011-01-14 10:02:43 +07:00
|
|
|
spin_unlock_irqrestore(&greth->devlock, flags);
|
2010-02-15 10:33:44 +07:00
|
|
|
greth->rx_cur = NEXT_RX(greth->rx_cur);
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static int greth_poll(struct napi_struct *napi, int budget)
|
|
|
|
{
|
|
|
|
struct greth_private *greth;
|
|
|
|
int work_done = 0;
|
GRETH: resolve SMP issues and other problems
Fixes the following:
1. POLL should not enable IRQ when work is not completed
2. No locking between TX descriptor cleaning and XMIT descriptor handling
3. No locking between RX POLL and XMIT modifying control register
4. Since TX cleaning (called from POLL) is running in parallel with XMIT
unnecessary locking is needed.
5. IRQ handler looks at RX frame status solely, this is wrong when IRQ is
temporarily disabled (in POLL), and when IRQ is shared.
6. IRQ handler clears IRQ status, which is unnecessary
7. TX queue was stopped in preventing cause when not MAX_SKB_FRAGS+1
descriptors were available after a SKB been scheduled by XMIT. Instead
the TX queue is stopped first when not enough descriptors are available
upon entering XMIT.
It was hard to split up this patch in smaller pieces since all are tied
together somehow.
Note the RX flag used in the interrupt handler does not signal that
interrupt was asserted, but that a frame was received. Same goes for TX.
Also, IRQ is not asserted when the RX flag is set before enabling IRQ
enable until a new frame is received. So extra care must be taken to
avoid enabling IRQ and all descriptors are already used, hence dead lock
will upon us. See new POLL implementation that enableds IRQ then look at
the RX flag to determine if one or more IRQs may have been missed. TX/RX
flags are cleared before handling previously enabled descriptors, this
ensures that the RX/TX flags are valid when determining if IRQ should be
turned on again.
By moving TX cleaning from POLL to XMIT in the standard case, removes some
locking trouble. Enabling TX cleaning from poll only when not enough TX
descriptors are available is safe because the TX queue is at the same time
stopped, thus XMIT will not be called. The TX queue is woken up again when
enough descriptrs are available.
TX Frames are always enabled with IRQ, however the TX IRQ Enable flag will
not be enabled until XMIT must wait for free descriptors.
Locking RX and XMIT parts of the driver from each other is needed because
the RX/TX enable bits share the same register.
Signed-off-by: Daniel Hellstrom <daniel@gaisler.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2011-01-14 10:02:43 +07:00
|
|
|
unsigned long flags;
|
|
|
|
u32 mask, ctrl;
|
2010-02-15 10:33:44 +07:00
|
|
|
greth = container_of(napi, struct greth_private, napi);
|
|
|
|
|
GRETH: resolve SMP issues and other problems
Fixes the following:
1. POLL should not enable IRQ when work is not completed
2. No locking between TX descriptor cleaning and XMIT descriptor handling
3. No locking between RX POLL and XMIT modifying control register
4. Since TX cleaning (called from POLL) is running in parallel with XMIT
unnecessary locking is needed.
5. IRQ handler looks at RX frame status solely, this is wrong when IRQ is
temporarily disabled (in POLL), and when IRQ is shared.
6. IRQ handler clears IRQ status, which is unnecessary
7. TX queue was stopped in preventing cause when not MAX_SKB_FRAGS+1
descriptors were available after a SKB been scheduled by XMIT. Instead
the TX queue is stopped first when not enough descriptors are available
upon entering XMIT.
It was hard to split up this patch in smaller pieces since all are tied
together somehow.
Note the RX flag used in the interrupt handler does not signal that
interrupt was asserted, but that a frame was received. Same goes for TX.
Also, IRQ is not asserted when the RX flag is set before enabling IRQ
enable until a new frame is received. So extra care must be taken to
avoid enabling IRQ and all descriptors are already used, hence dead lock
will upon us. See new POLL implementation that enableds IRQ then look at
the RX flag to determine if one or more IRQs may have been missed. TX/RX
flags are cleared before handling previously enabled descriptors, this
ensures that the RX/TX flags are valid when determining if IRQ should be
turned on again.
By moving TX cleaning from POLL to XMIT in the standard case, removes some
locking trouble. Enabling TX cleaning from poll only when not enough TX
descriptors are available is safe because the TX queue is at the same time
stopped, thus XMIT will not be called. The TX queue is woken up again when
enough descriptrs are available.
TX Frames are always enabled with IRQ, however the TX IRQ Enable flag will
not be enabled until XMIT must wait for free descriptors.
Locking RX and XMIT parts of the driver from each other is needed because
the RX/TX enable bits share the same register.
Signed-off-by: Daniel Hellstrom <daniel@gaisler.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2011-01-14 10:02:43 +07:00
|
|
|
restart_txrx_poll:
|
|
|
|
if (netif_queue_stopped(greth->netdev)) {
|
|
|
|
if (greth->gbit_mac)
|
|
|
|
greth_clean_tx_gbit(greth->netdev);
|
|
|
|
else
|
|
|
|
greth_clean_tx(greth->netdev);
|
2010-02-15 10:33:44 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (greth->gbit_mac) {
|
|
|
|
work_done += greth_rx_gbit(greth->netdev, budget - work_done);
|
|
|
|
} else {
|
|
|
|
work_done += greth_rx(greth->netdev, budget - work_done);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (work_done < budget) {
|
|
|
|
|
GRETH: resolve SMP issues and other problems
Fixes the following:
1. POLL should not enable IRQ when work is not completed
2. No locking between TX descriptor cleaning and XMIT descriptor handling
3. No locking between RX POLL and XMIT modifying control register
4. Since TX cleaning (called from POLL) is running in parallel with XMIT
unnecessary locking is needed.
5. IRQ handler looks at RX frame status solely, this is wrong when IRQ is
temporarily disabled (in POLL), and when IRQ is shared.
6. IRQ handler clears IRQ status, which is unnecessary
7. TX queue was stopped in preventing cause when not MAX_SKB_FRAGS+1
descriptors were available after a SKB been scheduled by XMIT. Instead
the TX queue is stopped first when not enough descriptors are available
upon entering XMIT.
It was hard to split up this patch in smaller pieces since all are tied
together somehow.
Note the RX flag used in the interrupt handler does not signal that
interrupt was asserted, but that a frame was received. Same goes for TX.
Also, IRQ is not asserted when the RX flag is set before enabling IRQ
enable until a new frame is received. So extra care must be taken to
avoid enabling IRQ and all descriptors are already used, hence dead lock
will upon us. See new POLL implementation that enableds IRQ then look at
the RX flag to determine if one or more IRQs may have been missed. TX/RX
flags are cleared before handling previously enabled descriptors, this
ensures that the RX/TX flags are valid when determining if IRQ should be
turned on again.
By moving TX cleaning from POLL to XMIT in the standard case, removes some
locking trouble. Enabling TX cleaning from poll only when not enough TX
descriptors are available is safe because the TX queue is at the same time
stopped, thus XMIT will not be called. The TX queue is woken up again when
enough descriptrs are available.
TX Frames are always enabled with IRQ, however the TX IRQ Enable flag will
not be enabled until XMIT must wait for free descriptors.
Locking RX and XMIT parts of the driver from each other is needed because
the RX/TX enable bits share the same register.
Signed-off-by: Daniel Hellstrom <daniel@gaisler.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2011-01-14 10:02:43 +07:00
|
|
|
spin_lock_irqsave(&greth->devlock, flags);
|
2010-02-15 10:33:44 +07:00
|
|
|
|
GRETH: resolve SMP issues and other problems
Fixes the following:
1. POLL should not enable IRQ when work is not completed
2. No locking between TX descriptor cleaning and XMIT descriptor handling
3. No locking between RX POLL and XMIT modifying control register
4. Since TX cleaning (called from POLL) is running in parallel with XMIT
unnecessary locking is needed.
5. IRQ handler looks at RX frame status solely, this is wrong when IRQ is
temporarily disabled (in POLL), and when IRQ is shared.
6. IRQ handler clears IRQ status, which is unnecessary
7. TX queue was stopped in preventing cause when not MAX_SKB_FRAGS+1
descriptors were available after a SKB been scheduled by XMIT. Instead
the TX queue is stopped first when not enough descriptors are available
upon entering XMIT.
It was hard to split up this patch in smaller pieces since all are tied
together somehow.
Note the RX flag used in the interrupt handler does not signal that
interrupt was asserted, but that a frame was received. Same goes for TX.
Also, IRQ is not asserted when the RX flag is set before enabling IRQ
enable until a new frame is received. So extra care must be taken to
avoid enabling IRQ and all descriptors are already used, hence dead lock
will upon us. See new POLL implementation that enableds IRQ then look at
the RX flag to determine if one or more IRQs may have been missed. TX/RX
flags are cleared before handling previously enabled descriptors, this
ensures that the RX/TX flags are valid when determining if IRQ should be
turned on again.
By moving TX cleaning from POLL to XMIT in the standard case, removes some
locking trouble. Enabling TX cleaning from poll only when not enough TX
descriptors are available is safe because the TX queue is at the same time
stopped, thus XMIT will not be called. The TX queue is woken up again when
enough descriptrs are available.
TX Frames are always enabled with IRQ, however the TX IRQ Enable flag will
not be enabled until XMIT must wait for free descriptors.
Locking RX and XMIT parts of the driver from each other is needed because
the RX/TX enable bits share the same register.
Signed-off-by: Daniel Hellstrom <daniel@gaisler.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2011-01-14 10:02:43 +07:00
|
|
|
ctrl = GRETH_REGLOAD(greth->regs->control);
|
|
|
|
if (netif_queue_stopped(greth->netdev)) {
|
|
|
|
GRETH_REGSAVE(greth->regs->control,
|
|
|
|
ctrl | GRETH_TXI | GRETH_RXI);
|
|
|
|
mask = GRETH_INT_RX | GRETH_INT_RE |
|
|
|
|
GRETH_INT_TX | GRETH_INT_TE;
|
|
|
|
} else {
|
|
|
|
GRETH_REGSAVE(greth->regs->control, ctrl | GRETH_RXI);
|
|
|
|
mask = GRETH_INT_RX | GRETH_INT_RE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GRETH_REGLOAD(greth->regs->status) & mask) {
|
|
|
|
GRETH_REGSAVE(greth->regs->control, ctrl);
|
|
|
|
spin_unlock_irqrestore(&greth->devlock, flags);
|
|
|
|
goto restart_txrx_poll;
|
|
|
|
} else {
|
|
|
|
__napi_complete(napi);
|
|
|
|
spin_unlock_irqrestore(&greth->devlock, flags);
|
2010-02-15 10:33:44 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return work_done;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int greth_set_mac_add(struct net_device *dev, void *p)
|
|
|
|
{
|
|
|
|
struct sockaddr *addr = p;
|
|
|
|
struct greth_private *greth;
|
|
|
|
struct greth_regs *regs;
|
|
|
|
|
2010-02-19 12:00:52 +07:00
|
|
|
greth = netdev_priv(dev);
|
2012-06-04 19:44:16 +07:00
|
|
|
regs = greth->regs;
|
2010-02-15 10:33:44 +07:00
|
|
|
|
|
|
|
if (!is_valid_ether_addr(addr->sa_data))
|
2012-02-21 09:07:49 +07:00
|
|
|
return -EADDRNOTAVAIL;
|
2010-02-15 10:33:44 +07:00
|
|
|
|
|
|
|
memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
|
2011-07-05 11:39:10 +07:00
|
|
|
GRETH_REGSAVE(regs->esa_msb, dev->dev_addr[0] << 8 | dev->dev_addr[1]);
|
|
|
|
GRETH_REGSAVE(regs->esa_lsb, dev->dev_addr[2] << 24 | dev->dev_addr[3] << 16 |
|
|
|
|
dev->dev_addr[4] << 8 | dev->dev_addr[5]);
|
2010-02-15 10:33:44 +07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static u32 greth_hash_get_index(__u8 *addr)
|
|
|
|
{
|
|
|
|
return (ether_crc(6, addr)) & 0x3F;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void greth_set_hash_filter(struct net_device *dev)
|
|
|
|
{
|
2010-04-02 04:22:57 +07:00
|
|
|
struct netdev_hw_addr *ha;
|
2010-02-19 12:00:52 +07:00
|
|
|
struct greth_private *greth = netdev_priv(dev);
|
2012-06-04 19:44:16 +07:00
|
|
|
struct greth_regs *regs = greth->regs;
|
2010-02-15 10:33:44 +07:00
|
|
|
u32 mc_filter[2];
|
2010-02-19 12:00:52 +07:00
|
|
|
unsigned int bitnr;
|
2010-02-15 10:33:44 +07:00
|
|
|
|
|
|
|
mc_filter[0] = mc_filter[1] = 0;
|
|
|
|
|
2010-04-02 04:22:57 +07:00
|
|
|
netdev_for_each_mc_addr(ha, dev) {
|
|
|
|
bitnr = greth_hash_get_index(ha->addr);
|
2010-02-15 10:33:44 +07:00
|
|
|
mc_filter[bitnr >> 5] |= 1 << (bitnr & 31);
|
|
|
|
}
|
|
|
|
|
|
|
|
GRETH_REGSAVE(regs->hash_msb, mc_filter[1]);
|
|
|
|
GRETH_REGSAVE(regs->hash_lsb, mc_filter[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void greth_set_multicast_list(struct net_device *dev)
|
|
|
|
{
|
|
|
|
int cfg;
|
|
|
|
struct greth_private *greth = netdev_priv(dev);
|
2012-06-04 19:44:16 +07:00
|
|
|
struct greth_regs *regs = greth->regs;
|
2010-02-15 10:33:44 +07:00
|
|
|
|
|
|
|
cfg = GRETH_REGLOAD(regs->control);
|
|
|
|
if (dev->flags & IFF_PROMISC)
|
|
|
|
cfg |= GRETH_CTRL_PR;
|
|
|
|
else
|
|
|
|
cfg &= ~GRETH_CTRL_PR;
|
|
|
|
|
|
|
|
if (greth->multicast) {
|
|
|
|
if (dev->flags & IFF_ALLMULTI) {
|
|
|
|
GRETH_REGSAVE(regs->hash_msb, -1);
|
|
|
|
GRETH_REGSAVE(regs->hash_lsb, -1);
|
|
|
|
cfg |= GRETH_CTRL_MCEN;
|
|
|
|
GRETH_REGSAVE(regs->control, cfg);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-02-19 12:00:52 +07:00
|
|
|
if (netdev_mc_empty(dev)) {
|
2010-02-15 10:33:44 +07:00
|
|
|
cfg &= ~GRETH_CTRL_MCEN;
|
|
|
|
GRETH_REGSAVE(regs->control, cfg);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Setup multicast filter */
|
|
|
|
greth_set_hash_filter(dev);
|
|
|
|
cfg |= GRETH_CTRL_MCEN;
|
|
|
|
}
|
|
|
|
GRETH_REGSAVE(regs->control, cfg);
|
|
|
|
}
|
|
|
|
|
|
|
|
static u32 greth_get_msglevel(struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct greth_private *greth = netdev_priv(dev);
|
|
|
|
return greth->msg_enable;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void greth_set_msglevel(struct net_device *dev, u32 value)
|
|
|
|
{
|
|
|
|
struct greth_private *greth = netdev_priv(dev);
|
|
|
|
greth->msg_enable = value;
|
|
|
|
}
|
|
|
|
static int greth_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
|
|
|
|
{
|
|
|
|
struct greth_private *greth = netdev_priv(dev);
|
|
|
|
struct phy_device *phy = greth->phy;
|
|
|
|
|
|
|
|
if (!phy)
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
return phy_ethtool_gset(phy, cmd);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int greth_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
|
|
|
|
{
|
|
|
|
struct greth_private *greth = netdev_priv(dev);
|
|
|
|
struct phy_device *phy = greth->phy;
|
|
|
|
|
|
|
|
if (!phy)
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
return phy_ethtool_sset(phy, cmd);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int greth_get_regs_len(struct net_device *dev)
|
|
|
|
{
|
|
|
|
return sizeof(struct greth_regs);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void greth_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
|
|
|
|
{
|
|
|
|
struct greth_private *greth = netdev_priv(dev);
|
|
|
|
|
2013-01-06 07:44:26 +07:00
|
|
|
strlcpy(info->driver, dev_driver_string(greth->dev),
|
|
|
|
sizeof(info->driver));
|
|
|
|
strlcpy(info->version, "revision: 1.0", sizeof(info->version));
|
|
|
|
strlcpy(info->bus_info, greth->dev->bus->name, sizeof(info->bus_info));
|
|
|
|
strlcpy(info->fw_version, "N/A", sizeof(info->fw_version));
|
2010-02-15 10:33:44 +07:00
|
|
|
info->eedump_len = 0;
|
|
|
|
info->regdump_len = sizeof(struct greth_regs);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void greth_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *p)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
struct greth_private *greth = netdev_priv(dev);
|
|
|
|
u32 __iomem *greth_regs = (u32 __iomem *) greth->regs;
|
|
|
|
u32 *buff = p;
|
|
|
|
|
|
|
|
for (i = 0; i < sizeof(struct greth_regs) / sizeof(u32); i++)
|
|
|
|
buff[i] = greth_read_bd(&greth_regs[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct ethtool_ops greth_ethtool_ops = {
|
|
|
|
.get_msglevel = greth_get_msglevel,
|
|
|
|
.set_msglevel = greth_set_msglevel,
|
|
|
|
.get_settings = greth_get_settings,
|
|
|
|
.set_settings = greth_set_settings,
|
|
|
|
.get_drvinfo = greth_get_drvinfo,
|
|
|
|
.get_regs_len = greth_get_regs_len,
|
|
|
|
.get_regs = greth_get_regs,
|
|
|
|
.get_link = ethtool_op_get_link,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct net_device_ops greth_netdev_ops = {
|
GRETH: resolve SMP issues and other problems
Fixes the following:
1. POLL should not enable IRQ when work is not completed
2. No locking between TX descriptor cleaning and XMIT descriptor handling
3. No locking between RX POLL and XMIT modifying control register
4. Since TX cleaning (called from POLL) is running in parallel with XMIT
unnecessary locking is needed.
5. IRQ handler looks at RX frame status solely, this is wrong when IRQ is
temporarily disabled (in POLL), and when IRQ is shared.
6. IRQ handler clears IRQ status, which is unnecessary
7. TX queue was stopped in preventing cause when not MAX_SKB_FRAGS+1
descriptors were available after a SKB been scheduled by XMIT. Instead
the TX queue is stopped first when not enough descriptors are available
upon entering XMIT.
It was hard to split up this patch in smaller pieces since all are tied
together somehow.
Note the RX flag used in the interrupt handler does not signal that
interrupt was asserted, but that a frame was received. Same goes for TX.
Also, IRQ is not asserted when the RX flag is set before enabling IRQ
enable until a new frame is received. So extra care must be taken to
avoid enabling IRQ and all descriptors are already used, hence dead lock
will upon us. See new POLL implementation that enableds IRQ then look at
the RX flag to determine if one or more IRQs may have been missed. TX/RX
flags are cleared before handling previously enabled descriptors, this
ensures that the RX/TX flags are valid when determining if IRQ should be
turned on again.
By moving TX cleaning from POLL to XMIT in the standard case, removes some
locking trouble. Enabling TX cleaning from poll only when not enough TX
descriptors are available is safe because the TX queue is at the same time
stopped, thus XMIT will not be called. The TX queue is woken up again when
enough descriptrs are available.
TX Frames are always enabled with IRQ, however the TX IRQ Enable flag will
not be enabled until XMIT must wait for free descriptors.
Locking RX and XMIT parts of the driver from each other is needed because
the RX/TX enable bits share the same register.
Signed-off-by: Daniel Hellstrom <daniel@gaisler.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2011-01-14 10:02:43 +07:00
|
|
|
.ndo_open = greth_open,
|
|
|
|
.ndo_stop = greth_close,
|
|
|
|
.ndo_start_xmit = greth_start_xmit,
|
|
|
|
.ndo_set_mac_address = greth_set_mac_add,
|
|
|
|
.ndo_validate_addr = eth_validate_addr,
|
2010-02-15 10:33:44 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
static inline int wait_for_mdio(struct greth_private *greth)
|
|
|
|
{
|
|
|
|
unsigned long timeout = jiffies + 4*HZ/100;
|
|
|
|
while (GRETH_REGLOAD(greth->regs->mdio) & GRETH_MII_BUSY) {
|
|
|
|
if (time_after(jiffies, timeout))
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int greth_mdio_read(struct mii_bus *bus, int phy, int reg)
|
|
|
|
{
|
|
|
|
struct greth_private *greth = bus->priv;
|
|
|
|
int data;
|
|
|
|
|
|
|
|
if (!wait_for_mdio(greth))
|
|
|
|
return -EBUSY;
|
|
|
|
|
|
|
|
GRETH_REGSAVE(greth->regs->mdio, ((phy & 0x1F) << 11) | ((reg & 0x1F) << 6) | 2);
|
|
|
|
|
|
|
|
if (!wait_for_mdio(greth))
|
|
|
|
return -EBUSY;
|
|
|
|
|
|
|
|
if (!(GRETH_REGLOAD(greth->regs->mdio) & GRETH_MII_NVALID)) {
|
|
|
|
data = (GRETH_REGLOAD(greth->regs->mdio) >> 16) & 0xFFFF;
|
|
|
|
return data;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int greth_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
|
|
|
|
{
|
|
|
|
struct greth_private *greth = bus->priv;
|
|
|
|
|
|
|
|
if (!wait_for_mdio(greth))
|
|
|
|
return -EBUSY;
|
|
|
|
|
|
|
|
GRETH_REGSAVE(greth->regs->mdio,
|
|
|
|
((val & 0xFFFF) << 16) | ((phy & 0x1F) << 11) | ((reg & 0x1F) << 6) | 1);
|
|
|
|
|
|
|
|
if (!wait_for_mdio(greth))
|
|
|
|
return -EBUSY;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void greth_link_change(struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct greth_private *greth = netdev_priv(dev);
|
|
|
|
struct phy_device *phydev = greth->phy;
|
|
|
|
unsigned long flags;
|
|
|
|
int status_change = 0;
|
2011-01-14 10:02:41 +07:00
|
|
|
u32 ctrl;
|
2010-02-15 10:33:44 +07:00
|
|
|
|
|
|
|
spin_lock_irqsave(&greth->devlock, flags);
|
|
|
|
|
|
|
|
if (phydev->link) {
|
|
|
|
|
|
|
|
if ((greth->speed != phydev->speed) || (greth->duplex != phydev->duplex)) {
|
2011-01-14 10:02:41 +07:00
|
|
|
ctrl = GRETH_REGLOAD(greth->regs->control) &
|
|
|
|
~(GRETH_CTRL_FD | GRETH_CTRL_SP | GRETH_CTRL_GB);
|
2010-02-15 10:33:44 +07:00
|
|
|
|
|
|
|
if (phydev->duplex)
|
2011-01-14 10:02:41 +07:00
|
|
|
ctrl |= GRETH_CTRL_FD;
|
2010-02-15 10:33:44 +07:00
|
|
|
|
2011-01-14 10:02:41 +07:00
|
|
|
if (phydev->speed == SPEED_100)
|
|
|
|
ctrl |= GRETH_CTRL_SP;
|
2010-02-15 10:33:44 +07:00
|
|
|
else if (phydev->speed == SPEED_1000)
|
2011-01-14 10:02:41 +07:00
|
|
|
ctrl |= GRETH_CTRL_GB;
|
2010-02-15 10:33:44 +07:00
|
|
|
|
2011-01-14 10:02:41 +07:00
|
|
|
GRETH_REGSAVE(greth->regs->control, ctrl);
|
2010-02-15 10:33:44 +07:00
|
|
|
greth->speed = phydev->speed;
|
|
|
|
greth->duplex = phydev->duplex;
|
|
|
|
status_change = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (phydev->link != greth->link) {
|
|
|
|
if (!phydev->link) {
|
|
|
|
greth->speed = 0;
|
|
|
|
greth->duplex = -1;
|
|
|
|
}
|
|
|
|
greth->link = phydev->link;
|
|
|
|
|
|
|
|
status_change = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&greth->devlock, flags);
|
|
|
|
|
|
|
|
if (status_change) {
|
|
|
|
if (phydev->link)
|
|
|
|
pr_debug("%s: link up (%d/%s)\n",
|
|
|
|
dev->name, phydev->speed,
|
|
|
|
DUPLEX_FULL == phydev->duplex ? "Full" : "Half");
|
|
|
|
else
|
|
|
|
pr_debug("%s: link down\n", dev->name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int greth_mdio_probe(struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct greth_private *greth = netdev_priv(dev);
|
|
|
|
struct phy_device *phy = NULL;
|
2010-02-19 12:00:52 +07:00
|
|
|
int ret;
|
2010-02-15 10:33:44 +07:00
|
|
|
|
|
|
|
/* Find the first PHY */
|
2010-02-19 12:00:52 +07:00
|
|
|
phy = phy_find_first(greth->mdio);
|
|
|
|
|
2010-02-15 10:33:44 +07:00
|
|
|
if (!phy) {
|
|
|
|
if (netif_msg_probe(greth))
|
|
|
|
dev_err(&dev->dev, "no PHY found\n");
|
|
|
|
return -ENXIO;
|
|
|
|
}
|
|
|
|
|
2010-02-19 12:00:52 +07:00
|
|
|
ret = phy_connect_direct(dev, phy, &greth_link_change,
|
2013-01-14 07:52:52 +07:00
|
|
|
greth->gbit_mac ? PHY_INTERFACE_MODE_GMII : PHY_INTERFACE_MODE_MII);
|
2010-02-19 12:00:52 +07:00
|
|
|
if (ret) {
|
|
|
|
if (netif_msg_ifup(greth))
|
|
|
|
dev_err(&dev->dev, "could not attach to PHY\n");
|
|
|
|
return ret;
|
|
|
|
}
|
2010-02-15 10:33:44 +07:00
|
|
|
|
|
|
|
if (greth->gbit_mac)
|
|
|
|
phy->supported &= PHY_GBIT_FEATURES;
|
|
|
|
else
|
|
|
|
phy->supported &= PHY_BASIC_FEATURES;
|
|
|
|
|
|
|
|
phy->advertising = phy->supported;
|
|
|
|
|
|
|
|
greth->link = 0;
|
|
|
|
greth->speed = 0;
|
|
|
|
greth->duplex = -1;
|
|
|
|
greth->phy = phy;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int phy_aneg_done(struct phy_device *phydev)
|
|
|
|
{
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
retval = phy_read(phydev, MII_BMSR);
|
|
|
|
|
|
|
|
return (retval < 0) ? retval : (retval & BMSR_ANEGCOMPLETE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int greth_mdio_init(struct greth_private *greth)
|
|
|
|
{
|
|
|
|
int ret, phy;
|
|
|
|
unsigned long timeout;
|
|
|
|
|
|
|
|
greth->mdio = mdiobus_alloc();
|
|
|
|
if (!greth->mdio) {
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
greth->mdio->name = "greth-mdio";
|
|
|
|
snprintf(greth->mdio->id, MII_BUS_ID_SIZE, "%s-%d", greth->mdio->name, greth->irq);
|
|
|
|
greth->mdio->read = greth_mdio_read;
|
|
|
|
greth->mdio->write = greth_mdio_write;
|
|
|
|
greth->mdio->priv = greth;
|
|
|
|
|
|
|
|
greth->mdio->irq = greth->mdio_irqs;
|
|
|
|
|
|
|
|
for (phy = 0; phy < PHY_MAX_ADDR; phy++)
|
|
|
|
greth->mdio->irq[phy] = PHY_POLL;
|
|
|
|
|
|
|
|
ret = mdiobus_register(greth->mdio);
|
|
|
|
if (ret) {
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = greth_mdio_probe(greth->netdev);
|
|
|
|
if (ret) {
|
|
|
|
if (netif_msg_probe(greth))
|
|
|
|
dev_err(&greth->netdev->dev, "failed to probe MDIO bus\n");
|
|
|
|
goto unreg_mdio;
|
|
|
|
}
|
|
|
|
|
|
|
|
phy_start(greth->phy);
|
|
|
|
|
|
|
|
/* If Ethernet debug link is used make autoneg happen right away */
|
|
|
|
if (greth->edcl && greth_edcl == 1) {
|
|
|
|
phy_start_aneg(greth->phy);
|
|
|
|
timeout = jiffies + 6*HZ;
|
|
|
|
while (!phy_aneg_done(greth->phy) && time_before(jiffies, timeout)) {
|
|
|
|
}
|
2013-12-07 04:01:32 +07:00
|
|
|
phy_read_status(greth->phy);
|
2010-02-15 10:33:44 +07:00
|
|
|
greth_link_change(greth->netdev);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
unreg_mdio:
|
|
|
|
mdiobus_unregister(greth->mdio);
|
|
|
|
error:
|
|
|
|
mdiobus_free(greth->mdio);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize the GRETH MAC */
|
2012-12-03 21:22:55 +07:00
|
|
|
static int greth_of_probe(struct platform_device *ofdev)
|
2010-02-15 10:33:44 +07:00
|
|
|
{
|
|
|
|
struct net_device *dev;
|
|
|
|
struct greth_private *greth;
|
|
|
|
struct greth_regs *regs;
|
|
|
|
|
|
|
|
int i;
|
|
|
|
int err;
|
|
|
|
int tmp;
|
|
|
|
unsigned long timeout;
|
|
|
|
|
|
|
|
dev = alloc_etherdev(sizeof(struct greth_private));
|
|
|
|
|
|
|
|
if (dev == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
greth = netdev_priv(dev);
|
|
|
|
greth->netdev = dev;
|
|
|
|
greth->dev = &ofdev->dev;
|
|
|
|
|
|
|
|
if (greth_debug > 0)
|
|
|
|
greth->msg_enable = greth_debug;
|
|
|
|
else
|
|
|
|
greth->msg_enable = GRETH_DEF_MSG_ENABLE;
|
|
|
|
|
|
|
|
spin_lock_init(&greth->devlock);
|
|
|
|
|
|
|
|
greth->regs = of_ioremap(&ofdev->resource[0], 0,
|
|
|
|
resource_size(&ofdev->resource[0]),
|
|
|
|
"grlib-greth regs");
|
|
|
|
|
|
|
|
if (greth->regs == NULL) {
|
|
|
|
if (netif_msg_probe(greth))
|
|
|
|
dev_err(greth->dev, "ioremap failure.\n");
|
|
|
|
err = -EIO;
|
|
|
|
goto error1;
|
|
|
|
}
|
|
|
|
|
2012-06-04 19:44:16 +07:00
|
|
|
regs = greth->regs;
|
2010-08-08 13:23:26 +07:00
|
|
|
greth->irq = ofdev->archdata.irqs[0];
|
2010-02-15 10:33:44 +07:00
|
|
|
|
|
|
|
dev_set_drvdata(greth->dev, dev);
|
|
|
|
SET_NETDEV_DEV(dev, greth->dev);
|
|
|
|
|
|
|
|
if (netif_msg_probe(greth))
|
2012-02-09 11:23:33 +07:00
|
|
|
dev_dbg(greth->dev, "resetting controller.\n");
|
2010-02-15 10:33:44 +07:00
|
|
|
|
|
|
|
/* Reset the controller. */
|
|
|
|
GRETH_REGSAVE(regs->control, GRETH_RESET);
|
|
|
|
|
|
|
|
/* Wait for MAC to reset itself */
|
|
|
|
timeout = jiffies + HZ/100;
|
|
|
|
while (GRETH_REGLOAD(regs->control) & GRETH_RESET) {
|
|
|
|
if (time_after(jiffies, timeout)) {
|
|
|
|
err = -EIO;
|
|
|
|
if (netif_msg_probe(greth))
|
|
|
|
dev_err(greth->dev, "timeout when waiting for reset.\n");
|
|
|
|
goto error2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get default PHY address */
|
|
|
|
greth->phyaddr = (GRETH_REGLOAD(regs->mdio) >> 11) & 0x1F;
|
|
|
|
|
|
|
|
/* Check if we have GBIT capable MAC */
|
|
|
|
tmp = GRETH_REGLOAD(regs->control);
|
|
|
|
greth->gbit_mac = (tmp >> 27) & 1;
|
|
|
|
|
|
|
|
/* Check for multicast capability */
|
|
|
|
greth->multicast = (tmp >> 25) & 1;
|
|
|
|
|
|
|
|
greth->edcl = (tmp >> 31) & 1;
|
|
|
|
|
|
|
|
/* If we have EDCL we disable the EDCL speed-duplex FSM so
|
|
|
|
* it doesn't interfere with the software */
|
|
|
|
if (greth->edcl != 0)
|
|
|
|
GRETH_REGORIN(regs->control, GRETH_CTRL_DISDUPLEX);
|
|
|
|
|
|
|
|
/* Check if MAC can handle MDIO interrupts */
|
|
|
|
greth->mdio_int_en = (tmp >> 26) & 1;
|
|
|
|
|
|
|
|
err = greth_mdio_init(greth);
|
|
|
|
if (err) {
|
|
|
|
if (netif_msg_probe(greth))
|
|
|
|
dev_err(greth->dev, "failed to register MDIO bus\n");
|
|
|
|
goto error2;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Allocate TX descriptor ring in coherent memory */
|
2013-08-27 12:45:23 +07:00
|
|
|
greth->tx_bd_base = dma_zalloc_coherent(greth->dev, 1024,
|
|
|
|
&greth->tx_bd_base_phys,
|
|
|
|
GFP_KERNEL);
|
2010-02-15 10:33:44 +07:00
|
|
|
if (!greth->tx_bd_base) {
|
|
|
|
err = -ENOMEM;
|
|
|
|
goto error3;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Allocate RX descriptor ring in coherent memory */
|
2013-08-27 12:45:23 +07:00
|
|
|
greth->rx_bd_base = dma_zalloc_coherent(greth->dev, 1024,
|
|
|
|
&greth->rx_bd_base_phys,
|
|
|
|
GFP_KERNEL);
|
2010-02-15 10:33:44 +07:00
|
|
|
if (!greth->rx_bd_base) {
|
|
|
|
err = -ENOMEM;
|
|
|
|
goto error4;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get MAC address from: module param, OF property or ID prom */
|
|
|
|
for (i = 0; i < 6; i++) {
|
|
|
|
if (macaddr[i] != 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (i == 6) {
|
|
|
|
const unsigned char *addr;
|
|
|
|
int len;
|
2010-04-14 06:12:29 +07:00
|
|
|
addr = of_get_property(ofdev->dev.of_node, "local-mac-address",
|
|
|
|
&len);
|
2010-02-15 10:33:44 +07:00
|
|
|
if (addr != NULL && len == 6) {
|
|
|
|
for (i = 0; i < 6; i++)
|
|
|
|
macaddr[i] = (unsigned int) addr[i];
|
|
|
|
} else {
|
|
|
|
#ifdef CONFIG_SPARC
|
|
|
|
for (i = 0; i < 6; i++)
|
|
|
|
macaddr[i] = (unsigned int) idprom->id_ethaddr[i];
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < 6; i++)
|
|
|
|
dev->dev_addr[i] = macaddr[i];
|
|
|
|
|
|
|
|
macaddr[5]++;
|
|
|
|
|
|
|
|
if (!is_valid_ether_addr(&dev->dev_addr[0])) {
|
|
|
|
if (netif_msg_probe(greth))
|
|
|
|
dev_err(greth->dev, "no valid ethernet address, aborting.\n");
|
|
|
|
err = -EINVAL;
|
|
|
|
goto error5;
|
|
|
|
}
|
|
|
|
|
|
|
|
GRETH_REGSAVE(regs->esa_msb, dev->dev_addr[0] << 8 | dev->dev_addr[1]);
|
|
|
|
GRETH_REGSAVE(regs->esa_lsb, dev->dev_addr[2] << 24 | dev->dev_addr[3] << 16 |
|
|
|
|
dev->dev_addr[4] << 8 | dev->dev_addr[5]);
|
|
|
|
|
|
|
|
/* Clear all pending interrupts except PHY irq */
|
|
|
|
GRETH_REGSAVE(regs->status, 0xFF);
|
|
|
|
|
|
|
|
if (greth->gbit_mac) {
|
2011-04-17 07:15:47 +07:00
|
|
|
dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM |
|
|
|
|
NETIF_F_RXCSUM;
|
|
|
|
dev->features = dev->hw_features | NETIF_F_HIGHDMA;
|
2010-02-15 10:33:44 +07:00
|
|
|
greth_netdev_ops.ndo_start_xmit = greth_start_xmit_gbit;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (greth->multicast) {
|
2011-08-16 13:29:01 +07:00
|
|
|
greth_netdev_ops.ndo_set_rx_mode = greth_set_multicast_list;
|
2010-02-15 10:33:44 +07:00
|
|
|
dev->flags |= IFF_MULTICAST;
|
|
|
|
} else {
|
|
|
|
dev->flags &= ~IFF_MULTICAST;
|
|
|
|
}
|
|
|
|
|
|
|
|
dev->netdev_ops = &greth_netdev_ops;
|
|
|
|
dev->ethtool_ops = &greth_ethtool_ops;
|
|
|
|
|
2010-08-17 13:11:24 +07:00
|
|
|
err = register_netdev(dev);
|
|
|
|
if (err) {
|
2010-02-15 10:33:44 +07:00
|
|
|
if (netif_msg_probe(greth))
|
|
|
|
dev_err(greth->dev, "netdevice registration failed.\n");
|
|
|
|
goto error5;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* setup NAPI */
|
|
|
|
netif_napi_add(dev, &greth->napi, greth_poll, 64);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
error5:
|
|
|
|
dma_free_coherent(greth->dev, 1024, greth->rx_bd_base, greth->rx_bd_base_phys);
|
|
|
|
error4:
|
|
|
|
dma_free_coherent(greth->dev, 1024, greth->tx_bd_base, greth->tx_bd_base_phys);
|
|
|
|
error3:
|
|
|
|
mdiobus_unregister(greth->mdio);
|
|
|
|
error2:
|
|
|
|
of_iounmap(&ofdev->resource[0], greth->regs, resource_size(&ofdev->resource[0]));
|
|
|
|
error1:
|
|
|
|
free_netdev(dev);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2012-12-03 21:22:55 +07:00
|
|
|
static int greth_of_remove(struct platform_device *of_dev)
|
2010-02-15 10:33:44 +07:00
|
|
|
{
|
2013-05-23 07:52:31 +07:00
|
|
|
struct net_device *ndev = platform_get_drvdata(of_dev);
|
2010-02-15 10:33:44 +07:00
|
|
|
struct greth_private *greth = netdev_priv(ndev);
|
|
|
|
|
|
|
|
/* Free descriptor areas */
|
|
|
|
dma_free_coherent(&of_dev->dev, 1024, greth->rx_bd_base, greth->rx_bd_base_phys);
|
|
|
|
|
|
|
|
dma_free_coherent(&of_dev->dev, 1024, greth->tx_bd_base, greth->tx_bd_base_phys);
|
|
|
|
|
|
|
|
if (greth->phy)
|
|
|
|
phy_stop(greth->phy);
|
|
|
|
mdiobus_unregister(greth->mdio);
|
|
|
|
|
|
|
|
unregister_netdev(ndev);
|
|
|
|
free_netdev(ndev);
|
|
|
|
|
|
|
|
of_iounmap(&of_dev->resource[0], greth->regs, resource_size(&of_dev->resource[0]));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct of_device_id greth_of_match[] = {
|
|
|
|
{
|
|
|
|
.name = "GAISLER_ETHMAC",
|
|
|
|
},
|
2011-01-14 10:02:37 +07:00
|
|
|
{
|
|
|
|
.name = "01_01d",
|
|
|
|
},
|
2010-02-15 10:33:44 +07:00
|
|
|
{},
|
|
|
|
};
|
|
|
|
|
|
|
|
MODULE_DEVICE_TABLE(of, greth_of_match);
|
|
|
|
|
2011-02-23 11:05:51 +07:00
|
|
|
static struct platform_driver greth_of_driver = {
|
2010-05-31 19:47:32 +07:00
|
|
|
.driver = {
|
|
|
|
.name = "grlib-greth",
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.of_match_table = greth_of_match,
|
|
|
|
},
|
2010-02-15 10:33:44 +07:00
|
|
|
.probe = greth_of_probe,
|
2012-12-03 21:22:55 +07:00
|
|
|
.remove = greth_of_remove,
|
2010-02-15 10:33:44 +07:00
|
|
|
};
|
|
|
|
|
2011-11-27 23:44:17 +07:00
|
|
|
module_platform_driver(greth_of_driver);
|
2010-02-15 10:33:44 +07:00
|
|
|
|
|
|
|
MODULE_AUTHOR("Aeroflex Gaisler AB.");
|
|
|
|
MODULE_DESCRIPTION("Aeroflex Gaisler Ethernet MAC driver");
|
|
|
|
MODULE_LICENSE("GPL");
|