2019-06-04 08:11:33 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2009-03-27 07:12:24 +00:00
|
|
|
/*
|
2012-01-27 13:36:01 +00:00
|
|
|
* linux/drivers/net/ethernet/ethoc.c
|
2009-03-27 07:12:24 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 2007-2008 Avionic Design Development GmbH
|
|
|
|
* Copyright (C) 2008-2009 Avionic Design GmbH
|
|
|
|
*
|
|
|
|
* Written by Thierry Reding <thierry.reding@avionic-design.de>
|
|
|
|
*/
|
|
|
|
|
2011-06-16 11:01:34 +00:00
|
|
|
#include <linux/dma-mapping.h>
|
2009-03-27 07:12:24 +00:00
|
|
|
#include <linux/etherdevice.h>
|
2014-02-03 23:33:10 +00:00
|
|
|
#include <linux/clk.h>
|
2009-03-27 07:12:24 +00:00
|
|
|
#include <linux/crc32.h>
|
2011-06-06 10:43:46 +00:00
|
|
|
#include <linux/interrupt.h>
|
2009-03-27 07:12:24 +00:00
|
|
|
#include <linux/io.h>
|
|
|
|
#include <linux/mii.h>
|
|
|
|
#include <linux/phy.h>
|
|
|
|
#include <linux/platform_device.h>
|
2009-10-07 13:09:06 +00:00
|
|
|
#include <linux/sched.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 08:04:11 +00:00
|
|
|
#include <linux/slab.h>
|
2010-11-25 02:30:25 +00:00
|
|
|
#include <linux/of.h>
|
2016-12-04 20:40:29 +00:00
|
|
|
#include <linux/of_net.h>
|
2011-07-03 19:21:01 +00:00
|
|
|
#include <linux/module.h>
|
2009-03-27 07:12:24 +00:00
|
|
|
#include <net/ethoc.h>
|
|
|
|
|
2009-10-04 23:33:20 +00:00
|
|
|
static int buffer_size = 0x8000; /* 32 KBytes */
|
|
|
|
module_param(buffer_size, int, 0);
|
|
|
|
MODULE_PARM_DESC(buffer_size, "DMA buffer allocation size");
|
|
|
|
|
2009-03-27 07:12:24 +00:00
|
|
|
/* register offsets */
|
|
|
|
#define MODER 0x00
|
|
|
|
#define INT_SOURCE 0x04
|
|
|
|
#define INT_MASK 0x08
|
|
|
|
#define IPGT 0x0c
|
|
|
|
#define IPGR1 0x10
|
|
|
|
#define IPGR2 0x14
|
|
|
|
#define PACKETLEN 0x18
|
|
|
|
#define COLLCONF 0x1c
|
|
|
|
#define TX_BD_NUM 0x20
|
|
|
|
#define CTRLMODER 0x24
|
|
|
|
#define MIIMODER 0x28
|
|
|
|
#define MIICOMMAND 0x2c
|
|
|
|
#define MIIADDRESS 0x30
|
|
|
|
#define MIITX_DATA 0x34
|
|
|
|
#define MIIRX_DATA 0x38
|
|
|
|
#define MIISTATUS 0x3c
|
|
|
|
#define MAC_ADDR0 0x40
|
|
|
|
#define MAC_ADDR1 0x44
|
|
|
|
#define ETH_HASH0 0x48
|
|
|
|
#define ETH_HASH1 0x4c
|
|
|
|
#define ETH_TXCTRL 0x50
|
2014-01-31 05:41:06 +00:00
|
|
|
#define ETH_END 0x54
|
2009-03-27 07:12:24 +00:00
|
|
|
|
|
|
|
/* mode register */
|
|
|
|
#define MODER_RXEN (1 << 0) /* receive enable */
|
|
|
|
#define MODER_TXEN (1 << 1) /* transmit enable */
|
|
|
|
#define MODER_NOPRE (1 << 2) /* no preamble */
|
|
|
|
#define MODER_BRO (1 << 3) /* broadcast address */
|
|
|
|
#define MODER_IAM (1 << 4) /* individual address mode */
|
|
|
|
#define MODER_PRO (1 << 5) /* promiscuous mode */
|
|
|
|
#define MODER_IFG (1 << 6) /* interframe gap for incoming frames */
|
|
|
|
#define MODER_LOOP (1 << 7) /* loopback */
|
|
|
|
#define MODER_NBO (1 << 8) /* no back-off */
|
|
|
|
#define MODER_EDE (1 << 9) /* excess defer enable */
|
|
|
|
#define MODER_FULLD (1 << 10) /* full duplex */
|
|
|
|
#define MODER_RESET (1 << 11) /* FIXME: reset (undocumented) */
|
|
|
|
#define MODER_DCRC (1 << 12) /* delayed CRC enable */
|
|
|
|
#define MODER_CRC (1 << 13) /* CRC enable */
|
|
|
|
#define MODER_HUGE (1 << 14) /* huge packets enable */
|
|
|
|
#define MODER_PAD (1 << 15) /* padding enabled */
|
|
|
|
#define MODER_RSM (1 << 16) /* receive small packets */
|
|
|
|
|
|
|
|
/* interrupt source and mask registers */
|
|
|
|
#define INT_MASK_TXF (1 << 0) /* transmit frame */
|
|
|
|
#define INT_MASK_TXE (1 << 1) /* transmit error */
|
|
|
|
#define INT_MASK_RXF (1 << 2) /* receive frame */
|
|
|
|
#define INT_MASK_RXE (1 << 3) /* receive error */
|
|
|
|
#define INT_MASK_BUSY (1 << 4)
|
|
|
|
#define INT_MASK_TXC (1 << 5) /* transmit control frame */
|
|
|
|
#define INT_MASK_RXC (1 << 6) /* receive control frame */
|
|
|
|
|
|
|
|
#define INT_MASK_TX (INT_MASK_TXF | INT_MASK_TXE)
|
|
|
|
#define INT_MASK_RX (INT_MASK_RXF | INT_MASK_RXE)
|
|
|
|
|
|
|
|
#define INT_MASK_ALL ( \
|
|
|
|
INT_MASK_TXF | INT_MASK_TXE | \
|
|
|
|
INT_MASK_RXF | INT_MASK_RXE | \
|
|
|
|
INT_MASK_TXC | INT_MASK_RXC | \
|
|
|
|
INT_MASK_BUSY \
|
|
|
|
)
|
|
|
|
|
|
|
|
/* packet length register */
|
|
|
|
#define PACKETLEN_MIN(min) (((min) & 0xffff) << 16)
|
|
|
|
#define PACKETLEN_MAX(max) (((max) & 0xffff) << 0)
|
|
|
|
#define PACKETLEN_MIN_MAX(min, max) (PACKETLEN_MIN(min) | \
|
|
|
|
PACKETLEN_MAX(max))
|
|
|
|
|
|
|
|
/* transmit buffer number register */
|
|
|
|
#define TX_BD_NUM_VAL(x) (((x) <= 0x80) ? (x) : 0x80)
|
|
|
|
|
|
|
|
/* control module mode register */
|
|
|
|
#define CTRLMODER_PASSALL (1 << 0) /* pass all receive frames */
|
|
|
|
#define CTRLMODER_RXFLOW (1 << 1) /* receive control flow */
|
|
|
|
#define CTRLMODER_TXFLOW (1 << 2) /* transmit control flow */
|
|
|
|
|
|
|
|
/* MII mode register */
|
|
|
|
#define MIIMODER_CLKDIV(x) ((x) & 0xfe) /* needs to be an even number */
|
|
|
|
#define MIIMODER_NOPRE (1 << 8) /* no preamble */
|
|
|
|
|
|
|
|
/* MII command register */
|
|
|
|
#define MIICOMMAND_SCAN (1 << 0) /* scan status */
|
|
|
|
#define MIICOMMAND_READ (1 << 1) /* read status */
|
|
|
|
#define MIICOMMAND_WRITE (1 << 2) /* write control data */
|
|
|
|
|
|
|
|
/* MII address register */
|
|
|
|
#define MIIADDRESS_FIAD(x) (((x) & 0x1f) << 0)
|
|
|
|
#define MIIADDRESS_RGAD(x) (((x) & 0x1f) << 8)
|
|
|
|
#define MIIADDRESS_ADDR(phy, reg) (MIIADDRESS_FIAD(phy) | \
|
|
|
|
MIIADDRESS_RGAD(reg))
|
|
|
|
|
|
|
|
/* MII transmit data register */
|
|
|
|
#define MIITX_DATA_VAL(x) ((x) & 0xffff)
|
|
|
|
|
|
|
|
/* MII receive data register */
|
|
|
|
#define MIIRX_DATA_VAL(x) ((x) & 0xffff)
|
|
|
|
|
|
|
|
/* MII status register */
|
|
|
|
#define MIISTATUS_LINKFAIL (1 << 0)
|
|
|
|
#define MIISTATUS_BUSY (1 << 1)
|
|
|
|
#define MIISTATUS_INVALID (1 << 2)
|
|
|
|
|
|
|
|
/* TX buffer descriptor */
|
|
|
|
#define TX_BD_CS (1 << 0) /* carrier sense lost */
|
|
|
|
#define TX_BD_DF (1 << 1) /* defer indication */
|
|
|
|
#define TX_BD_LC (1 << 2) /* late collision */
|
|
|
|
#define TX_BD_RL (1 << 3) /* retransmission limit */
|
|
|
|
#define TX_BD_RETRY_MASK (0x00f0)
|
|
|
|
#define TX_BD_RETRY(x) (((x) & 0x00f0) >> 4)
|
|
|
|
#define TX_BD_UR (1 << 8) /* transmitter underrun */
|
|
|
|
#define TX_BD_CRC (1 << 11) /* TX CRC enable */
|
|
|
|
#define TX_BD_PAD (1 << 12) /* pad enable for short packets */
|
|
|
|
#define TX_BD_WRAP (1 << 13)
|
|
|
|
#define TX_BD_IRQ (1 << 14) /* interrupt request enable */
|
|
|
|
#define TX_BD_READY (1 << 15) /* TX buffer ready */
|
|
|
|
#define TX_BD_LEN(x) (((x) & 0xffff) << 16)
|
|
|
|
#define TX_BD_LEN_MASK (0xffff << 16)
|
|
|
|
|
|
|
|
#define TX_BD_STATS (TX_BD_CS | TX_BD_DF | TX_BD_LC | \
|
|
|
|
TX_BD_RL | TX_BD_RETRY_MASK | TX_BD_UR)
|
|
|
|
|
|
|
|
/* RX buffer descriptor */
|
|
|
|
#define RX_BD_LC (1 << 0) /* late collision */
|
|
|
|
#define RX_BD_CRC (1 << 1) /* RX CRC error */
|
|
|
|
#define RX_BD_SF (1 << 2) /* short frame */
|
|
|
|
#define RX_BD_TL (1 << 3) /* too long */
|
|
|
|
#define RX_BD_DN (1 << 4) /* dribble nibble */
|
|
|
|
#define RX_BD_IS (1 << 5) /* invalid symbol */
|
|
|
|
#define RX_BD_OR (1 << 6) /* receiver overrun */
|
|
|
|
#define RX_BD_MISS (1 << 7)
|
|
|
|
#define RX_BD_CF (1 << 8) /* control frame */
|
|
|
|
#define RX_BD_WRAP (1 << 13)
|
|
|
|
#define RX_BD_IRQ (1 << 14) /* interrupt request enable */
|
|
|
|
#define RX_BD_EMPTY (1 << 15)
|
|
|
|
#define RX_BD_LEN(x) (((x) & 0xffff) << 16)
|
|
|
|
|
|
|
|
#define RX_BD_STATS (RX_BD_LC | RX_BD_CRC | RX_BD_SF | RX_BD_TL | \
|
|
|
|
RX_BD_DN | RX_BD_IS | RX_BD_OR | RX_BD_MISS)
|
|
|
|
|
|
|
|
#define ETHOC_BUFSIZ 1536
|
|
|
|
#define ETHOC_ZLEN 64
|
|
|
|
#define ETHOC_BD_BASE 0x400
|
|
|
|
#define ETHOC_TIMEOUT (HZ / 2)
|
|
|
|
#define ETHOC_MII_TIMEOUT (1 + (HZ / 5))
|
|
|
|
|
|
|
|
/**
|
|
|
|
* struct ethoc - driver-private device structure
|
|
|
|
* @iobase: pointer to I/O memory region
|
|
|
|
* @membase: pointer to buffer memory region
|
drivers/net/ethernet: clean up mis-targeted comments
As part of the W=1 cleanups for ethernet, a million [*] driver
comments had to be cleaned up to get the W=1 compilation to
succeed. This change finally makes the drivers/net/ethernet tree
compile with W=1 set on the command line. NOTE: The kernel uses
kdoc style (see Documentation/process/kernel-doc.rst) when
documenting code, not doxygen or other styles.
After this patch the x86_64 build has no warnings from W=1, however
scripts/kernel-doc says there are 1545 more warnings in source files, that
I need to develop a script to fix in a followup patch.
The errors fixed here are all kdoc of a few classes, with a few outliers:
In file included from drivers/net/ethernet/qlogic/netxen/netxen_nic_hw.c:10:
drivers/net/ethernet/qlogic/netxen/netxen_nic.h:1193:18: warning: ‘FW_DUMP_LEVELS’ defined but not used [-Wunused-const-variable=]
1193 | static const u32 FW_DUMP_LEVELS[] = { 0x3, 0x7, 0xf, 0x1f, 0x3f, 0x7f, 0xff };
| ^~~~~~~~~~~~~~
... repeats 4 times...
drivers/net/ethernet/sun/cassini.c:2084:24: warning: suggest braces around empty body in an ‘else’ statement [-Wempty-body]
2084 | RX_USED_ADD(page, i);
drivers/net/ethernet/natsemi/ns83820.c: In function ‘phy_intr’:
drivers/net/ethernet/natsemi/ns83820.c:603:6: warning: variable ‘tbisr’ set but not used [-Wunused-but-set-variable]
603 | u32 tbisr, tanar, tanlpar;
| ^~~~~
drivers/net/ethernet/natsemi/ns83820.c: In function ‘ns83820_get_link_ksettings’:
drivers/net/ethernet/natsemi/ns83820.c:1207:11: warning: variable ‘tanar’ set but not used [-Wunused-but-set-variable]
1207 | u32 cfg, tanar, tbicr;
| ^~~~~
drivers/net/ethernet/packetengines/yellowfin.c:1063:18: warning: variable ‘yf_size’ set but not used [-Wunused-but-set-variable]
1063 | int data_size, yf_size;
| ^~~~~~~
Normal kdoc fixes:
warning: Function parameter or member 'x' not described in 'y'
warning: Excess function parameter 'x' description in 'y'
warning: Cannot understand <string> on line <NNN> - I thought it was a doc line
[*] - ok it wasn't quite a million, but it felt like it.
Signed-off-by: Jesse Brandeburg <jesse.brandeburg@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2020-09-25 22:24:45 +00:00
|
|
|
* @big_endian: just big or little (endian)
|
2014-01-31 05:41:07 +00:00
|
|
|
* @num_bd: number of buffer descriptors
|
2009-03-27 07:12:24 +00:00
|
|
|
* @num_tx: number of send buffers
|
|
|
|
* @cur_tx: last send buffer written
|
|
|
|
* @dty_tx: last buffer actually sent
|
|
|
|
* @num_rx: number of receive buffers
|
|
|
|
* @cur_rx: current receive buffer
|
2010-06-11 02:47:35 +00:00
|
|
|
* @vma: pointer to array of virtual memory addresses for buffers
|
2009-03-27 07:12:24 +00:00
|
|
|
* @netdev: pointer to network device structure
|
|
|
|
* @napi: NAPI structure
|
|
|
|
* @msg_enable: device state flags
|
|
|
|
* @lock: device lock
|
|
|
|
* @mdio: MDIO bus for PHY access
|
drivers/net/ethernet: clean up mis-targeted comments
As part of the W=1 cleanups for ethernet, a million [*] driver
comments had to be cleaned up to get the W=1 compilation to
succeed. This change finally makes the drivers/net/ethernet tree
compile with W=1 set on the command line. NOTE: The kernel uses
kdoc style (see Documentation/process/kernel-doc.rst) when
documenting code, not doxygen or other styles.
After this patch the x86_64 build has no warnings from W=1, however
scripts/kernel-doc says there are 1545 more warnings in source files, that
I need to develop a script to fix in a followup patch.
The errors fixed here are all kdoc of a few classes, with a few outliers:
In file included from drivers/net/ethernet/qlogic/netxen/netxen_nic_hw.c:10:
drivers/net/ethernet/qlogic/netxen/netxen_nic.h:1193:18: warning: ‘FW_DUMP_LEVELS’ defined but not used [-Wunused-const-variable=]
1193 | static const u32 FW_DUMP_LEVELS[] = { 0x3, 0x7, 0xf, 0x1f, 0x3f, 0x7f, 0xff };
| ^~~~~~~~~~~~~~
... repeats 4 times...
drivers/net/ethernet/sun/cassini.c:2084:24: warning: suggest braces around empty body in an ‘else’ statement [-Wempty-body]
2084 | RX_USED_ADD(page, i);
drivers/net/ethernet/natsemi/ns83820.c: In function ‘phy_intr’:
drivers/net/ethernet/natsemi/ns83820.c:603:6: warning: variable ‘tbisr’ set but not used [-Wunused-but-set-variable]
603 | u32 tbisr, tanar, tanlpar;
| ^~~~~
drivers/net/ethernet/natsemi/ns83820.c: In function ‘ns83820_get_link_ksettings’:
drivers/net/ethernet/natsemi/ns83820.c:1207:11: warning: variable ‘tanar’ set but not used [-Wunused-but-set-variable]
1207 | u32 cfg, tanar, tbicr;
| ^~~~~
drivers/net/ethernet/packetengines/yellowfin.c:1063:18: warning: variable ‘yf_size’ set but not used [-Wunused-but-set-variable]
1063 | int data_size, yf_size;
| ^~~~~~~
Normal kdoc fixes:
warning: Function parameter or member 'x' not described in 'y'
warning: Excess function parameter 'x' description in 'y'
warning: Cannot understand <string> on line <NNN> - I thought it was a doc line
[*] - ok it wasn't quite a million, but it felt like it.
Signed-off-by: Jesse Brandeburg <jesse.brandeburg@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2020-09-25 22:24:45 +00:00
|
|
|
* @clk: clock
|
2009-03-27 07:12:24 +00:00
|
|
|
* @phy_id: address of attached PHY
|
drivers/net/ethernet: clean up mis-targeted comments
As part of the W=1 cleanups for ethernet, a million [*] driver
comments had to be cleaned up to get the W=1 compilation to
succeed. This change finally makes the drivers/net/ethernet tree
compile with W=1 set on the command line. NOTE: The kernel uses
kdoc style (see Documentation/process/kernel-doc.rst) when
documenting code, not doxygen or other styles.
After this patch the x86_64 build has no warnings from W=1, however
scripts/kernel-doc says there are 1545 more warnings in source files, that
I need to develop a script to fix in a followup patch.
The errors fixed here are all kdoc of a few classes, with a few outliers:
In file included from drivers/net/ethernet/qlogic/netxen/netxen_nic_hw.c:10:
drivers/net/ethernet/qlogic/netxen/netxen_nic.h:1193:18: warning: ‘FW_DUMP_LEVELS’ defined but not used [-Wunused-const-variable=]
1193 | static const u32 FW_DUMP_LEVELS[] = { 0x3, 0x7, 0xf, 0x1f, 0x3f, 0x7f, 0xff };
| ^~~~~~~~~~~~~~
... repeats 4 times...
drivers/net/ethernet/sun/cassini.c:2084:24: warning: suggest braces around empty body in an ‘else’ statement [-Wempty-body]
2084 | RX_USED_ADD(page, i);
drivers/net/ethernet/natsemi/ns83820.c: In function ‘phy_intr’:
drivers/net/ethernet/natsemi/ns83820.c:603:6: warning: variable ‘tbisr’ set but not used [-Wunused-but-set-variable]
603 | u32 tbisr, tanar, tanlpar;
| ^~~~~
drivers/net/ethernet/natsemi/ns83820.c: In function ‘ns83820_get_link_ksettings’:
drivers/net/ethernet/natsemi/ns83820.c:1207:11: warning: variable ‘tanar’ set but not used [-Wunused-but-set-variable]
1207 | u32 cfg, tanar, tbicr;
| ^~~~~
drivers/net/ethernet/packetengines/yellowfin.c:1063:18: warning: variable ‘yf_size’ set but not used [-Wunused-but-set-variable]
1063 | int data_size, yf_size;
| ^~~~~~~
Normal kdoc fixes:
warning: Function parameter or member 'x' not described in 'y'
warning: Excess function parameter 'x' description in 'y'
warning: Cannot understand <string> on line <NNN> - I thought it was a doc line
[*] - ok it wasn't quite a million, but it felt like it.
Signed-off-by: Jesse Brandeburg <jesse.brandeburg@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2020-09-25 22:24:45 +00:00
|
|
|
* @old_link: previous link info
|
|
|
|
* @old_duplex: previous duplex info
|
2009-03-27 07:12:24 +00:00
|
|
|
*/
|
|
|
|
struct ethoc {
|
|
|
|
void __iomem *iobase;
|
|
|
|
void __iomem *membase;
|
2015-09-22 11:27:16 +00:00
|
|
|
bool big_endian;
|
2009-03-27 07:12:24 +00:00
|
|
|
|
2014-01-31 05:41:07 +00:00
|
|
|
unsigned int num_bd;
|
2009-03-27 07:12:24 +00:00
|
|
|
unsigned int num_tx;
|
|
|
|
unsigned int cur_tx;
|
|
|
|
unsigned int dty_tx;
|
|
|
|
|
|
|
|
unsigned int num_rx;
|
|
|
|
unsigned int cur_rx;
|
|
|
|
|
2013-01-27 18:44:36 +00:00
|
|
|
void **vma;
|
2010-06-11 02:47:35 +00:00
|
|
|
|
2009-03-27 07:12:24 +00:00
|
|
|
struct net_device *netdev;
|
|
|
|
struct napi_struct napi;
|
|
|
|
u32 msg_enable;
|
|
|
|
|
|
|
|
spinlock_t lock;
|
|
|
|
|
|
|
|
struct mii_bus *mdio;
|
2014-02-03 23:33:10 +00:00
|
|
|
struct clk *clk;
|
2009-03-27 07:12:24 +00:00
|
|
|
s8 phy_id;
|
2016-12-04 20:40:28 +00:00
|
|
|
|
|
|
|
int old_link;
|
|
|
|
int old_duplex;
|
2009-03-27 07:12:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* struct ethoc_bd - buffer descriptor
|
|
|
|
* @stat: buffer statistics
|
|
|
|
* @addr: physical memory address
|
|
|
|
*/
|
|
|
|
struct ethoc_bd {
|
|
|
|
u32 stat;
|
|
|
|
u32 addr;
|
|
|
|
};
|
|
|
|
|
2009-10-07 14:16:42 +00:00
|
|
|
static inline u32 ethoc_read(struct ethoc *dev, loff_t offset)
|
2009-03-27 07:12:24 +00:00
|
|
|
{
|
2015-09-22 11:27:16 +00:00
|
|
|
if (dev->big_endian)
|
|
|
|
return ioread32be(dev->iobase + offset);
|
|
|
|
else
|
|
|
|
return ioread32(dev->iobase + offset);
|
2009-03-27 07:12:24 +00:00
|
|
|
}
|
|
|
|
|
2009-10-07 14:16:42 +00:00
|
|
|
static inline void ethoc_write(struct ethoc *dev, loff_t offset, u32 data)
|
2009-03-27 07:12:24 +00:00
|
|
|
{
|
2015-09-22 11:27:16 +00:00
|
|
|
if (dev->big_endian)
|
|
|
|
iowrite32be(data, dev->iobase + offset);
|
|
|
|
else
|
|
|
|
iowrite32(data, dev->iobase + offset);
|
2009-03-27 07:12:24 +00:00
|
|
|
}
|
|
|
|
|
2009-10-07 14:16:42 +00:00
|
|
|
static inline void ethoc_read_bd(struct ethoc *dev, int index,
|
|
|
|
struct ethoc_bd *bd)
|
2009-03-27 07:12:24 +00:00
|
|
|
{
|
|
|
|
loff_t offset = ETHOC_BD_BASE + (index * sizeof(struct ethoc_bd));
|
|
|
|
bd->stat = ethoc_read(dev, offset + 0);
|
|
|
|
bd->addr = ethoc_read(dev, offset + 4);
|
|
|
|
}
|
|
|
|
|
2009-10-07 14:16:42 +00:00
|
|
|
static inline void ethoc_write_bd(struct ethoc *dev, int index,
|
2009-03-27 07:12:24 +00:00
|
|
|
const struct ethoc_bd *bd)
|
|
|
|
{
|
|
|
|
loff_t offset = ETHOC_BD_BASE + (index * sizeof(struct ethoc_bd));
|
|
|
|
ethoc_write(dev, offset + 0, bd->stat);
|
|
|
|
ethoc_write(dev, offset + 4, bd->addr);
|
|
|
|
}
|
|
|
|
|
2009-10-07 14:16:42 +00:00
|
|
|
static inline void ethoc_enable_irq(struct ethoc *dev, u32 mask)
|
2009-03-27 07:12:24 +00:00
|
|
|
{
|
|
|
|
u32 imask = ethoc_read(dev, INT_MASK);
|
|
|
|
imask |= mask;
|
|
|
|
ethoc_write(dev, INT_MASK, imask);
|
|
|
|
}
|
|
|
|
|
2009-10-07 14:16:42 +00:00
|
|
|
static inline void ethoc_disable_irq(struct ethoc *dev, u32 mask)
|
2009-03-27 07:12:24 +00:00
|
|
|
{
|
|
|
|
u32 imask = ethoc_read(dev, INT_MASK);
|
|
|
|
imask &= ~mask;
|
|
|
|
ethoc_write(dev, INT_MASK, imask);
|
|
|
|
}
|
|
|
|
|
2009-10-07 14:16:42 +00:00
|
|
|
static inline void ethoc_ack_irq(struct ethoc *dev, u32 mask)
|
2009-03-27 07:12:24 +00:00
|
|
|
{
|
|
|
|
ethoc_write(dev, INT_SOURCE, mask);
|
|
|
|
}
|
|
|
|
|
2009-10-07 14:16:42 +00:00
|
|
|
static inline void ethoc_enable_rx_and_tx(struct ethoc *dev)
|
2009-03-27 07:12:24 +00:00
|
|
|
{
|
|
|
|
u32 mode = ethoc_read(dev, MODER);
|
|
|
|
mode |= MODER_RXEN | MODER_TXEN;
|
|
|
|
ethoc_write(dev, MODER, mode);
|
|
|
|
}
|
|
|
|
|
2009-10-07 14:16:42 +00:00
|
|
|
static inline void ethoc_disable_rx_and_tx(struct ethoc *dev)
|
2009-03-27 07:12:24 +00:00
|
|
|
{
|
|
|
|
u32 mode = ethoc_read(dev, MODER);
|
|
|
|
mode &= ~(MODER_RXEN | MODER_TXEN);
|
|
|
|
ethoc_write(dev, MODER, mode);
|
|
|
|
}
|
|
|
|
|
2010-07-08 01:23:19 +00:00
|
|
|
static int ethoc_init_ring(struct ethoc *dev, unsigned long mem_start)
|
2009-03-27 07:12:24 +00:00
|
|
|
{
|
|
|
|
struct ethoc_bd bd;
|
|
|
|
int i;
|
2013-01-27 18:44:36 +00:00
|
|
|
void *vma;
|
2009-03-27 07:12:24 +00:00
|
|
|
|
|
|
|
dev->cur_tx = 0;
|
|
|
|
dev->dty_tx = 0;
|
|
|
|
dev->cur_rx = 0;
|
|
|
|
|
2010-06-11 02:47:36 +00:00
|
|
|
ethoc_write(dev, TX_BD_NUM, dev->num_tx);
|
|
|
|
|
2009-03-27 07:12:24 +00:00
|
|
|
/* setup transmission buffers */
|
2010-06-11 02:47:35 +00:00
|
|
|
bd.addr = mem_start;
|
2009-03-27 07:12:24 +00:00
|
|
|
bd.stat = TX_BD_IRQ | TX_BD_CRC;
|
2010-06-11 02:47:35 +00:00
|
|
|
vma = dev->membase;
|
2009-03-27 07:12:24 +00:00
|
|
|
|
|
|
|
for (i = 0; i < dev->num_tx; i++) {
|
|
|
|
if (i == dev->num_tx - 1)
|
|
|
|
bd.stat |= TX_BD_WRAP;
|
|
|
|
|
|
|
|
ethoc_write_bd(dev, i, &bd);
|
|
|
|
bd.addr += ETHOC_BUFSIZ;
|
2010-06-11 02:47:35 +00:00
|
|
|
|
|
|
|
dev->vma[i] = vma;
|
|
|
|
vma += ETHOC_BUFSIZ;
|
2009-03-27 07:12:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bd.stat = RX_BD_EMPTY | RX_BD_IRQ;
|
|
|
|
|
|
|
|
for (i = 0; i < dev->num_rx; i++) {
|
|
|
|
if (i == dev->num_rx - 1)
|
|
|
|
bd.stat |= RX_BD_WRAP;
|
|
|
|
|
|
|
|
ethoc_write_bd(dev, dev->num_tx + i, &bd);
|
|
|
|
bd.addr += ETHOC_BUFSIZ;
|
2010-06-11 02:47:35 +00:00
|
|
|
|
|
|
|
dev->vma[dev->num_tx + i] = vma;
|
|
|
|
vma += ETHOC_BUFSIZ;
|
2009-03-27 07:12:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ethoc_reset(struct ethoc *dev)
|
|
|
|
{
|
|
|
|
u32 mode;
|
|
|
|
|
|
|
|
/* TODO: reset controller? */
|
|
|
|
|
|
|
|
ethoc_disable_rx_and_tx(dev);
|
|
|
|
|
|
|
|
/* TODO: setup registers */
|
|
|
|
|
|
|
|
/* enable FCS generation and automatic padding */
|
|
|
|
mode = ethoc_read(dev, MODER);
|
|
|
|
mode |= MODER_CRC | MODER_PAD;
|
|
|
|
ethoc_write(dev, MODER, mode);
|
|
|
|
|
|
|
|
/* set full-duplex mode */
|
|
|
|
mode = ethoc_read(dev, MODER);
|
|
|
|
mode |= MODER_FULLD;
|
|
|
|
ethoc_write(dev, MODER, mode);
|
|
|
|
ethoc_write(dev, IPGT, 0x15);
|
|
|
|
|
|
|
|
ethoc_ack_irq(dev, INT_MASK_ALL);
|
|
|
|
ethoc_enable_irq(dev, INT_MASK_ALL);
|
|
|
|
ethoc_enable_rx_and_tx(dev);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned int ethoc_update_rx_stats(struct ethoc *dev,
|
|
|
|
struct ethoc_bd *bd)
|
|
|
|
{
|
|
|
|
struct net_device *netdev = dev->netdev;
|
|
|
|
unsigned int ret = 0;
|
|
|
|
|
|
|
|
if (bd->stat & RX_BD_TL) {
|
|
|
|
dev_err(&netdev->dev, "RX: frame too long\n");
|
2010-07-05 02:13:31 +00:00
|
|
|
netdev->stats.rx_length_errors++;
|
2009-03-27 07:12:24 +00:00
|
|
|
ret++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bd->stat & RX_BD_SF) {
|
|
|
|
dev_err(&netdev->dev, "RX: frame too short\n");
|
2010-07-05 02:13:31 +00:00
|
|
|
netdev->stats.rx_length_errors++;
|
2009-03-27 07:12:24 +00:00
|
|
|
ret++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bd->stat & RX_BD_DN) {
|
|
|
|
dev_err(&netdev->dev, "RX: dribble nibble\n");
|
2010-07-05 02:13:31 +00:00
|
|
|
netdev->stats.rx_frame_errors++;
|
2009-03-27 07:12:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (bd->stat & RX_BD_CRC) {
|
|
|
|
dev_err(&netdev->dev, "RX: wrong CRC\n");
|
2010-07-05 02:13:31 +00:00
|
|
|
netdev->stats.rx_crc_errors++;
|
2009-03-27 07:12:24 +00:00
|
|
|
ret++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bd->stat & RX_BD_OR) {
|
|
|
|
dev_err(&netdev->dev, "RX: overrun\n");
|
2010-07-05 02:13:31 +00:00
|
|
|
netdev->stats.rx_over_errors++;
|
2009-03-27 07:12:24 +00:00
|
|
|
ret++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bd->stat & RX_BD_MISS)
|
2010-07-05 02:13:31 +00:00
|
|
|
netdev->stats.rx_missed_errors++;
|
2009-03-27 07:12:24 +00:00
|
|
|
|
|
|
|
if (bd->stat & RX_BD_LC) {
|
|
|
|
dev_err(&netdev->dev, "RX: late collision\n");
|
2010-07-05 02:13:31 +00:00
|
|
|
netdev->stats.collisions++;
|
2009-03-27 07:12:24 +00:00
|
|
|
ret++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ethoc_rx(struct net_device *dev, int limit)
|
|
|
|
{
|
|
|
|
struct ethoc *priv = netdev_priv(dev);
|
|
|
|
int count;
|
|
|
|
|
|
|
|
for (count = 0; count < limit; ++count) {
|
|
|
|
unsigned int entry;
|
|
|
|
struct ethoc_bd bd;
|
|
|
|
|
2010-11-25 02:30:32 +00:00
|
|
|
entry = priv->num_tx + priv->cur_rx;
|
2009-03-27 07:12:24 +00:00
|
|
|
ethoc_read_bd(priv, entry, &bd);
|
2010-11-25 02:30:28 +00:00
|
|
|
if (bd.stat & RX_BD_EMPTY) {
|
|
|
|
ethoc_ack_irq(priv, INT_MASK_RX);
|
|
|
|
/* If packet (interrupt) came in between checking
|
|
|
|
* BD_EMTPY and clearing the interrupt source, then we
|
|
|
|
* risk missing the packet as the RX interrupt won't
|
|
|
|
* trigger right away when we reenable it; hence, check
|
|
|
|
* BD_EMTPY here again to make sure there isn't such a
|
|
|
|
* packet waiting for us...
|
|
|
|
*/
|
|
|
|
ethoc_read_bd(priv, entry, &bd);
|
|
|
|
if (bd.stat & RX_BD_EMPTY)
|
|
|
|
break;
|
|
|
|
}
|
2009-03-27 07:12:24 +00:00
|
|
|
|
|
|
|
if (ethoc_update_rx_stats(priv, &bd) == 0) {
|
|
|
|
int size = bd.stat >> 16;
|
2009-10-13 05:34:20 +00:00
|
|
|
struct sk_buff *skb;
|
2009-10-04 23:33:19 +00:00
|
|
|
|
|
|
|
size -= 4; /* strip the CRC */
|
2009-10-13 05:34:20 +00:00
|
|
|
skb = netdev_alloc_skb_ip_align(dev, size);
|
2009-10-04 23:33:19 +00:00
|
|
|
|
2009-03-27 07:12:24 +00:00
|
|
|
if (likely(skb)) {
|
2010-06-11 02:47:35 +00:00
|
|
|
void *src = priv->vma[entry];
|
2009-03-27 07:12:24 +00:00
|
|
|
memcpy_fromio(skb_put(skb, size), src, size);
|
|
|
|
skb->protocol = eth_type_trans(skb, dev);
|
2010-07-05 02:13:31 +00:00
|
|
|
dev->stats.rx_packets++;
|
|
|
|
dev->stats.rx_bytes += size;
|
2009-03-27 07:12:24 +00:00
|
|
|
netif_receive_skb(skb);
|
|
|
|
} else {
|
|
|
|
if (net_ratelimit())
|
2013-01-27 18:44:36 +00:00
|
|
|
dev_warn(&dev->dev,
|
|
|
|
"low on memory - packet dropped\n");
|
2009-03-27 07:12:24 +00:00
|
|
|
|
2010-07-05 02:13:31 +00:00
|
|
|
dev->stats.rx_dropped++;
|
2009-03-27 07:12:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* clear the buffer descriptor so it can be reused */
|
|
|
|
bd.stat &= ~RX_BD_STATS;
|
|
|
|
bd.stat |= RX_BD_EMPTY;
|
|
|
|
ethoc_write_bd(priv, entry, &bd);
|
2010-11-25 02:30:32 +00:00
|
|
|
if (++priv->cur_rx == priv->num_rx)
|
|
|
|
priv->cur_rx = 0;
|
2009-03-27 07:12:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2010-11-25 02:30:31 +00:00
|
|
|
static void ethoc_update_tx_stats(struct ethoc *dev, struct ethoc_bd *bd)
|
2009-03-27 07:12:24 +00:00
|
|
|
{
|
|
|
|
struct net_device *netdev = dev->netdev;
|
|
|
|
|
|
|
|
if (bd->stat & TX_BD_LC) {
|
|
|
|
dev_err(&netdev->dev, "TX: late collision\n");
|
2010-07-05 02:13:31 +00:00
|
|
|
netdev->stats.tx_window_errors++;
|
2009-03-27 07:12:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (bd->stat & TX_BD_RL) {
|
|
|
|
dev_err(&netdev->dev, "TX: retransmit limit\n");
|
2010-07-05 02:13:31 +00:00
|
|
|
netdev->stats.tx_aborted_errors++;
|
2009-03-27 07:12:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (bd->stat & TX_BD_UR) {
|
|
|
|
dev_err(&netdev->dev, "TX: underrun\n");
|
2010-07-05 02:13:31 +00:00
|
|
|
netdev->stats.tx_fifo_errors++;
|
2009-03-27 07:12:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (bd->stat & TX_BD_CS) {
|
|
|
|
dev_err(&netdev->dev, "TX: carrier sense lost\n");
|
2010-07-05 02:13:31 +00:00
|
|
|
netdev->stats.tx_carrier_errors++;
|
2009-03-27 07:12:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (bd->stat & TX_BD_STATS)
|
2010-07-05 02:13:31 +00:00
|
|
|
netdev->stats.tx_errors++;
|
2009-03-27 07:12:24 +00:00
|
|
|
|
2010-07-05 02:13:31 +00:00
|
|
|
netdev->stats.collisions += (bd->stat >> 4) & 0xf;
|
|
|
|
netdev->stats.tx_bytes += bd->stat >> 16;
|
|
|
|
netdev->stats.tx_packets++;
|
2009-03-27 07:12:24 +00:00
|
|
|
}
|
|
|
|
|
2010-11-25 02:30:29 +00:00
|
|
|
static int ethoc_tx(struct net_device *dev, int limit)
|
2009-03-27 07:12:24 +00:00
|
|
|
{
|
|
|
|
struct ethoc *priv = netdev_priv(dev);
|
2010-11-25 02:30:29 +00:00
|
|
|
int count;
|
|
|
|
struct ethoc_bd bd;
|
2009-03-27 07:12:24 +00:00
|
|
|
|
2010-11-25 02:30:29 +00:00
|
|
|
for (count = 0; count < limit; ++count) {
|
|
|
|
unsigned int entry;
|
2009-03-27 07:12:24 +00:00
|
|
|
|
2010-11-25 02:30:32 +00:00
|
|
|
entry = priv->dty_tx & (priv->num_tx-1);
|
2009-03-27 07:12:24 +00:00
|
|
|
|
|
|
|
ethoc_read_bd(priv, entry, &bd);
|
|
|
|
|
2010-11-25 02:30:29 +00:00
|
|
|
if (bd.stat & TX_BD_READY || (priv->dty_tx == priv->cur_tx)) {
|
|
|
|
ethoc_ack_irq(priv, INT_MASK_TX);
|
|
|
|
/* If interrupt came in between reading in the BD
|
|
|
|
* and clearing the interrupt source, then we risk
|
|
|
|
* missing the event as the TX interrupt won't trigger
|
|
|
|
* right away when we reenable it; hence, check
|
|
|
|
* BD_EMPTY here again to make sure there isn't such an
|
|
|
|
* event pending...
|
|
|
|
*/
|
|
|
|
ethoc_read_bd(priv, entry, &bd);
|
|
|
|
if (bd.stat & TX_BD_READY ||
|
|
|
|
(priv->dty_tx == priv->cur_tx))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-11-25 02:30:31 +00:00
|
|
|
ethoc_update_tx_stats(priv, &bd);
|
2010-11-25 02:30:29 +00:00
|
|
|
priv->dty_tx++;
|
2009-03-27 07:12:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((priv->cur_tx - priv->dty_tx) <= (priv->num_tx / 2))
|
|
|
|
netif_wake_queue(dev);
|
|
|
|
|
2010-11-25 02:30:29 +00:00
|
|
|
return count;
|
2009-03-27 07:12:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static irqreturn_t ethoc_interrupt(int irq, void *dev_id)
|
|
|
|
{
|
2010-07-05 02:13:31 +00:00
|
|
|
struct net_device *dev = dev_id;
|
2009-03-27 07:12:24 +00:00
|
|
|
struct ethoc *priv = netdev_priv(dev);
|
|
|
|
u32 pending;
|
2010-11-25 02:30:29 +00:00
|
|
|
u32 mask;
|
|
|
|
|
|
|
|
/* Figure out what triggered the interrupt...
|
|
|
|
* The tricky bit here is that the interrupt source bits get
|
2011-03-31 01:57:33 +00:00
|
|
|
* set in INT_SOURCE for an event regardless of whether that
|
2010-11-25 02:30:29 +00:00
|
|
|
* event is masked or not. Thus, in order to figure out what
|
|
|
|
* triggered the interrupt, we need to remove the sources
|
|
|
|
* for all events that are currently masked. This behaviour
|
|
|
|
* is not particularly well documented but reasonable...
|
|
|
|
*/
|
|
|
|
mask = ethoc_read(priv, INT_MASK);
|
2009-03-27 07:12:24 +00:00
|
|
|
pending = ethoc_read(priv, INT_SOURCE);
|
2010-11-25 02:30:29 +00:00
|
|
|
pending &= mask;
|
|
|
|
|
2013-01-27 18:44:36 +00:00
|
|
|
if (unlikely(pending == 0))
|
2009-03-27 07:12:24 +00:00
|
|
|
return IRQ_NONE;
|
|
|
|
|
2009-10-07 14:16:43 +00:00
|
|
|
ethoc_ack_irq(priv, pending);
|
2009-03-27 07:12:24 +00:00
|
|
|
|
2010-11-25 02:30:29 +00:00
|
|
|
/* We always handle the dropped packet interrupt */
|
2009-03-27 07:12:24 +00:00
|
|
|
if (pending & INT_MASK_BUSY) {
|
2016-12-04 20:40:30 +00:00
|
|
|
dev_dbg(&dev->dev, "packet dropped\n");
|
2010-07-05 02:13:31 +00:00
|
|
|
dev->stats.rx_dropped++;
|
2009-03-27 07:12:24 +00:00
|
|
|
}
|
|
|
|
|
2010-11-25 02:30:29 +00:00
|
|
|
/* Handle receive/transmit event by switching to polling */
|
|
|
|
if (pending & (INT_MASK_TX | INT_MASK_RX)) {
|
|
|
|
ethoc_disable_irq(priv, INT_MASK_TX | INT_MASK_RX);
|
|
|
|
napi_schedule(&priv->napi);
|
2009-03-27 07:12:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ethoc_get_mac_address(struct net_device *dev, void *addr)
|
|
|
|
{
|
|
|
|
struct ethoc *priv = netdev_priv(dev);
|
|
|
|
u8 *mac = (u8 *)addr;
|
|
|
|
u32 reg;
|
|
|
|
|
|
|
|
reg = ethoc_read(priv, MAC_ADDR0);
|
|
|
|
mac[2] = (reg >> 24) & 0xff;
|
|
|
|
mac[3] = (reg >> 16) & 0xff;
|
|
|
|
mac[4] = (reg >> 8) & 0xff;
|
|
|
|
mac[5] = (reg >> 0) & 0xff;
|
|
|
|
|
|
|
|
reg = ethoc_read(priv, MAC_ADDR1);
|
|
|
|
mac[0] = (reg >> 8) & 0xff;
|
|
|
|
mac[1] = (reg >> 0) & 0xff;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ethoc_poll(struct napi_struct *napi, int budget)
|
|
|
|
{
|
|
|
|
struct ethoc *priv = container_of(napi, struct ethoc, napi);
|
2010-11-25 02:30:29 +00:00
|
|
|
int rx_work_done = 0;
|
|
|
|
int tx_work_done = 0;
|
|
|
|
|
|
|
|
rx_work_done = ethoc_rx(priv->netdev, budget);
|
|
|
|
tx_work_done = ethoc_tx(priv->netdev, budget);
|
2009-03-27 07:12:24 +00:00
|
|
|
|
2010-11-25 02:30:29 +00:00
|
|
|
if (rx_work_done < budget && tx_work_done < budget) {
|
2017-01-30 16:22:01 +00:00
|
|
|
napi_complete_done(napi, rx_work_done);
|
2010-11-25 02:30:29 +00:00
|
|
|
ethoc_enable_irq(priv, INT_MASK_TX | INT_MASK_RX);
|
2009-03-27 07:12:24 +00:00
|
|
|
}
|
|
|
|
|
2010-11-25 02:30:29 +00:00
|
|
|
return rx_work_done;
|
2009-03-27 07:12:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int ethoc_mdio_read(struct mii_bus *bus, int phy, int reg)
|
|
|
|
{
|
|
|
|
struct ethoc *priv = bus->priv;
|
2010-11-25 02:30:30 +00:00
|
|
|
int i;
|
2009-03-27 07:12:24 +00:00
|
|
|
|
|
|
|
ethoc_write(priv, MIIADDRESS, MIIADDRESS_ADDR(phy, reg));
|
|
|
|
ethoc_write(priv, MIICOMMAND, MIICOMMAND_READ);
|
|
|
|
|
2013-01-27 18:44:36 +00:00
|
|
|
for (i = 0; i < 5; i++) {
|
2009-03-27 07:12:24 +00:00
|
|
|
u32 status = ethoc_read(priv, MIISTATUS);
|
|
|
|
if (!(status & MIISTATUS_BUSY)) {
|
|
|
|
u32 data = ethoc_read(priv, MIIRX_DATA);
|
|
|
|
/* reset MII command register */
|
|
|
|
ethoc_write(priv, MIICOMMAND, 0);
|
|
|
|
return data;
|
|
|
|
}
|
2013-01-27 18:44:36 +00:00
|
|
|
usleep_range(100, 200);
|
2009-03-27 07:12:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ethoc_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
|
|
|
|
{
|
|
|
|
struct ethoc *priv = bus->priv;
|
2010-11-25 02:30:30 +00:00
|
|
|
int i;
|
2009-03-27 07:12:24 +00:00
|
|
|
|
|
|
|
ethoc_write(priv, MIIADDRESS, MIIADDRESS_ADDR(phy, reg));
|
|
|
|
ethoc_write(priv, MIITX_DATA, val);
|
|
|
|
ethoc_write(priv, MIICOMMAND, MIICOMMAND_WRITE);
|
|
|
|
|
2013-01-27 18:44:36 +00:00
|
|
|
for (i = 0; i < 5; i++) {
|
2009-03-27 07:12:24 +00:00
|
|
|
u32 stat = ethoc_read(priv, MIISTATUS);
|
2010-06-11 02:47:39 +00:00
|
|
|
if (!(stat & MIISTATUS_BUSY)) {
|
|
|
|
/* reset MII command register */
|
|
|
|
ethoc_write(priv, MIICOMMAND, 0);
|
2009-03-27 07:12:24 +00:00
|
|
|
return 0;
|
2010-06-11 02:47:39 +00:00
|
|
|
}
|
2013-01-27 18:44:36 +00:00
|
|
|
usleep_range(100, 200);
|
2009-03-27 07:12:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ethoc_mdio_poll(struct net_device *dev)
|
|
|
|
{
|
2016-12-04 20:40:28 +00:00
|
|
|
struct ethoc *priv = netdev_priv(dev);
|
|
|
|
struct phy_device *phydev = dev->phydev;
|
|
|
|
bool changed = false;
|
|
|
|
u32 mode;
|
|
|
|
|
|
|
|
if (priv->old_link != phydev->link) {
|
|
|
|
changed = true;
|
|
|
|
priv->old_link = phydev->link;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (priv->old_duplex != phydev->duplex) {
|
|
|
|
changed = true;
|
|
|
|
priv->old_duplex = phydev->duplex;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!changed)
|
|
|
|
return;
|
|
|
|
|
|
|
|
mode = ethoc_read(priv, MODER);
|
|
|
|
if (phydev->duplex == DUPLEX_FULL)
|
|
|
|
mode |= MODER_FULLD;
|
|
|
|
else
|
|
|
|
mode &= ~MODER_FULLD;
|
|
|
|
ethoc_write(priv, MODER, mode);
|
|
|
|
|
|
|
|
phy_print_status(phydev);
|
2009-03-27 07:12:24 +00:00
|
|
|
}
|
|
|
|
|
2012-12-03 14:24:09 +00:00
|
|
|
static int ethoc_mdio_probe(struct net_device *dev)
|
2009-03-27 07:12:24 +00:00
|
|
|
{
|
|
|
|
struct ethoc *priv = netdev_priv(dev);
|
|
|
|
struct phy_device *phy;
|
2010-06-11 02:47:37 +00:00
|
|
|
int err;
|
2009-03-27 07:12:24 +00:00
|
|
|
|
2013-01-27 18:44:36 +00:00
|
|
|
if (priv->phy_id != -1)
|
2016-01-06 19:11:18 +00:00
|
|
|
phy = mdiobus_get_phy(priv->mdio, priv->phy_id);
|
2013-01-27 18:44:36 +00:00
|
|
|
else
|
2010-06-11 02:47:37 +00:00
|
|
|
phy = phy_find_first(priv->mdio);
|
2009-03-27 07:12:24 +00:00
|
|
|
|
|
|
|
if (!phy) {
|
|
|
|
dev_err(&dev->dev, "no PHY found\n");
|
|
|
|
return -ENXIO;
|
|
|
|
}
|
|
|
|
|
2016-12-04 20:40:28 +00:00
|
|
|
priv->old_duplex = -1;
|
|
|
|
priv->old_link = -1;
|
|
|
|
|
2013-01-14 00:52:52 +00:00
|
|
|
err = phy_connect_direct(dev, phy, ethoc_mdio_poll,
|
|
|
|
PHY_INTERFACE_MODE_GMII);
|
2010-06-11 02:47:37 +00:00
|
|
|
if (err) {
|
2009-03-27 07:12:24 +00:00
|
|
|
dev_err(&dev->dev, "could not attach to PHY\n");
|
2010-06-11 02:47:37 +00:00
|
|
|
return err;
|
2009-03-27 07:12:24 +00:00
|
|
|
}
|
|
|
|
|
2018-09-11 23:53:11 +00:00
|
|
|
phy_set_max_speed(phy, SPEED_100);
|
2014-02-03 23:33:09 +00:00
|
|
|
|
2009-03-27 07:12:24 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ethoc_open(struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct ethoc *priv = netdev_priv(dev);
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = request_irq(dev->irq, ethoc_interrupt, IRQF_SHARED,
|
|
|
|
dev->name, dev);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2017-06-06 01:31:16 +00:00
|
|
|
napi_enable(&priv->napi);
|
|
|
|
|
2010-07-08 01:23:19 +00:00
|
|
|
ethoc_init_ring(priv, dev->mem_start);
|
2009-03-27 07:12:24 +00:00
|
|
|
ethoc_reset(priv);
|
|
|
|
|
|
|
|
if (netif_queue_stopped(dev)) {
|
|
|
|
dev_dbg(&dev->dev, " resuming queue\n");
|
|
|
|
netif_wake_queue(dev);
|
|
|
|
} else {
|
|
|
|
dev_dbg(&dev->dev, " starting queue\n");
|
|
|
|
netif_start_queue(dev);
|
|
|
|
}
|
|
|
|
|
2016-12-04 20:40:28 +00:00
|
|
|
priv->old_link = -1;
|
|
|
|
priv->old_duplex = -1;
|
|
|
|
|
2016-07-15 07:59:11 +00:00
|
|
|
phy_start(dev->phydev);
|
2009-03-27 07:12:24 +00:00
|
|
|
|
|
|
|
if (netif_msg_ifup(priv)) {
|
|
|
|
dev_info(&dev->dev, "I/O: %08lx Memory: %08lx-%08lx\n",
|
|
|
|
dev->base_addr, dev->mem_start, dev->mem_end);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ethoc_stop(struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct ethoc *priv = netdev_priv(dev);
|
|
|
|
|
|
|
|
napi_disable(&priv->napi);
|
|
|
|
|
2016-07-15 07:59:11 +00:00
|
|
|
if (dev->phydev)
|
|
|
|
phy_stop(dev->phydev);
|
2009-03-27 07:12:24 +00:00
|
|
|
|
|
|
|
ethoc_disable_rx_and_tx(priv);
|
|
|
|
free_irq(dev->irq, dev);
|
|
|
|
|
|
|
|
if (!netif_queue_stopped(dev))
|
|
|
|
netif_stop_queue(dev);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ethoc_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
|
|
|
|
{
|
|
|
|
struct ethoc *priv = netdev_priv(dev);
|
|
|
|
struct mii_ioctl_data *mdio = if_mii(ifr);
|
|
|
|
struct phy_device *phy = NULL;
|
|
|
|
|
|
|
|
if (!netif_running(dev))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (cmd != SIOCGMIIPHY) {
|
|
|
|
if (mdio->phy_id >= PHY_MAX_ADDR)
|
|
|
|
return -ERANGE;
|
|
|
|
|
2016-01-06 19:11:18 +00:00
|
|
|
phy = mdiobus_get_phy(priv->mdio, mdio->phy_id);
|
2009-03-27 07:12:24 +00:00
|
|
|
if (!phy)
|
|
|
|
return -ENODEV;
|
|
|
|
} else {
|
2016-07-15 07:59:11 +00:00
|
|
|
phy = dev->phydev;
|
2009-03-27 07:12:24 +00:00
|
|
|
}
|
|
|
|
|
2010-07-17 08:48:55 +00:00
|
|
|
return phy_mii_ioctl(phy, ifr, cmd);
|
2009-03-27 07:12:24 +00:00
|
|
|
}
|
|
|
|
|
2013-01-06 03:25:45 +00:00
|
|
|
static void ethoc_do_set_mac_address(struct net_device *dev)
|
2009-03-27 07:12:24 +00:00
|
|
|
{
|
|
|
|
struct ethoc *priv = netdev_priv(dev);
|
2013-01-06 03:25:45 +00:00
|
|
|
unsigned char *mac = dev->dev_addr;
|
2012-02-17 05:43:29 +00:00
|
|
|
|
2009-03-27 07:12:24 +00:00
|
|
|
ethoc_write(priv, MAC_ADDR0, (mac[2] << 24) | (mac[3] << 16) |
|
|
|
|
(mac[4] << 8) | (mac[5] << 0));
|
|
|
|
ethoc_write(priv, MAC_ADDR1, (mac[0] << 8) | (mac[1] << 0));
|
2013-01-06 03:25:45 +00:00
|
|
|
}
|
2009-03-27 07:12:24 +00:00
|
|
|
|
2013-01-06 03:25:45 +00:00
|
|
|
static int ethoc_set_mac_address(struct net_device *dev, void *p)
|
|
|
|
{
|
|
|
|
const struct sockaddr *addr = p;
|
2012-02-17 05:43:29 +00:00
|
|
|
|
2013-01-06 03:25:45 +00:00
|
|
|
if (!is_valid_ether_addr(addr->sa_data))
|
|
|
|
return -EADDRNOTAVAIL;
|
|
|
|
memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN);
|
|
|
|
ethoc_do_set_mac_address(dev);
|
2009-03-27 07:12:24 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ethoc_set_multicast_list(struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct ethoc *priv = netdev_priv(dev);
|
|
|
|
u32 mode = ethoc_read(priv, MODER);
|
2010-04-01 21:22:57 +00:00
|
|
|
struct netdev_hw_addr *ha;
|
2009-03-27 07:12:24 +00:00
|
|
|
u32 hash[2] = { 0, 0 };
|
|
|
|
|
|
|
|
/* set loopback mode if requested */
|
|
|
|
if (dev->flags & IFF_LOOPBACK)
|
|
|
|
mode |= MODER_LOOP;
|
|
|
|
else
|
|
|
|
mode &= ~MODER_LOOP;
|
|
|
|
|
|
|
|
/* receive broadcast frames if requested */
|
|
|
|
if (dev->flags & IFF_BROADCAST)
|
|
|
|
mode &= ~MODER_BRO;
|
|
|
|
else
|
|
|
|
mode |= MODER_BRO;
|
|
|
|
|
|
|
|
/* enable promiscuous mode if requested */
|
|
|
|
if (dev->flags & IFF_PROMISC)
|
|
|
|
mode |= MODER_PRO;
|
|
|
|
else
|
|
|
|
mode &= ~MODER_PRO;
|
|
|
|
|
|
|
|
ethoc_write(priv, MODER, mode);
|
|
|
|
|
|
|
|
/* receive multicast frames */
|
|
|
|
if (dev->flags & IFF_ALLMULTI) {
|
|
|
|
hash[0] = 0xffffffff;
|
|
|
|
hash[1] = 0xffffffff;
|
|
|
|
} else {
|
2010-04-01 21:22:57 +00:00
|
|
|
netdev_for_each_mc_addr(ha, dev) {
|
|
|
|
u32 crc = ether_crc(ETH_ALEN, ha->addr);
|
2009-03-27 07:12:24 +00:00
|
|
|
int bit = (crc >> 26) & 0x3f;
|
|
|
|
hash[bit >> 5] |= 1 << (bit & 0x1f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ethoc_write(priv, ETH_HASH0, hash[0]);
|
|
|
|
ethoc_write(priv, ETH_HASH1, hash[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ethoc_change_mtu(struct net_device *dev, int new_mtu)
|
|
|
|
{
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
|
netdev: pass the stuck queue to the timeout handler
This allows incrementing the correct timeout statistic without any mess.
Down the road, devices can learn to reset just the specific queue.
The patch was generated with the following script:
use strict;
use warnings;
our $^I = '.bak';
my @work = (
["arch/m68k/emu/nfeth.c", "nfeth_tx_timeout"],
["arch/um/drivers/net_kern.c", "uml_net_tx_timeout"],
["arch/um/drivers/vector_kern.c", "vector_net_tx_timeout"],
["arch/xtensa/platforms/iss/network.c", "iss_net_tx_timeout"],
["drivers/char/pcmcia/synclink_cs.c", "hdlcdev_tx_timeout"],
["drivers/infiniband/ulp/ipoib/ipoib_main.c", "ipoib_timeout"],
["drivers/infiniband/ulp/ipoib/ipoib_main.c", "ipoib_timeout"],
["drivers/message/fusion/mptlan.c", "mpt_lan_tx_timeout"],
["drivers/misc/sgi-xp/xpnet.c", "xpnet_dev_tx_timeout"],
["drivers/net/appletalk/cops.c", "cops_timeout"],
["drivers/net/arcnet/arcdevice.h", "arcnet_timeout"],
["drivers/net/arcnet/arcnet.c", "arcnet_timeout"],
["drivers/net/arcnet/com20020.c", "arcnet_timeout"],
["drivers/net/ethernet/3com/3c509.c", "el3_tx_timeout"],
["drivers/net/ethernet/3com/3c515.c", "corkscrew_timeout"],
["drivers/net/ethernet/3com/3c574_cs.c", "el3_tx_timeout"],
["drivers/net/ethernet/3com/3c589_cs.c", "el3_tx_timeout"],
["drivers/net/ethernet/3com/3c59x.c", "vortex_tx_timeout"],
["drivers/net/ethernet/3com/3c59x.c", "vortex_tx_timeout"],
["drivers/net/ethernet/3com/typhoon.c", "typhoon_tx_timeout"],
["drivers/net/ethernet/8390/8390.h", "ei_tx_timeout"],
["drivers/net/ethernet/8390/8390.h", "eip_tx_timeout"],
["drivers/net/ethernet/8390/8390.c", "ei_tx_timeout"],
["drivers/net/ethernet/8390/8390p.c", "eip_tx_timeout"],
["drivers/net/ethernet/8390/ax88796.c", "ax_ei_tx_timeout"],
["drivers/net/ethernet/8390/axnet_cs.c", "axnet_tx_timeout"],
["drivers/net/ethernet/8390/etherh.c", "__ei_tx_timeout"],
["drivers/net/ethernet/8390/hydra.c", "__ei_tx_timeout"],
["drivers/net/ethernet/8390/mac8390.c", "__ei_tx_timeout"],
["drivers/net/ethernet/8390/mcf8390.c", "__ei_tx_timeout"],
["drivers/net/ethernet/8390/lib8390.c", "__ei_tx_timeout"],
["drivers/net/ethernet/8390/ne2k-pci.c", "ei_tx_timeout"],
["drivers/net/ethernet/8390/pcnet_cs.c", "ei_tx_timeout"],
["drivers/net/ethernet/8390/smc-ultra.c", "ei_tx_timeout"],
["drivers/net/ethernet/8390/wd.c", "ei_tx_timeout"],
["drivers/net/ethernet/8390/zorro8390.c", "__ei_tx_timeout"],
["drivers/net/ethernet/adaptec/starfire.c", "tx_timeout"],
["drivers/net/ethernet/agere/et131x.c", "et131x_tx_timeout"],
["drivers/net/ethernet/allwinner/sun4i-emac.c", "emac_timeout"],
["drivers/net/ethernet/alteon/acenic.c", "ace_watchdog"],
["drivers/net/ethernet/amazon/ena/ena_netdev.c", "ena_tx_timeout"],
["drivers/net/ethernet/amd/7990.h", "lance_tx_timeout"],
["drivers/net/ethernet/amd/7990.c", "lance_tx_timeout"],
["drivers/net/ethernet/amd/a2065.c", "lance_tx_timeout"],
["drivers/net/ethernet/amd/am79c961a.c", "am79c961_timeout"],
["drivers/net/ethernet/amd/amd8111e.c", "amd8111e_tx_timeout"],
["drivers/net/ethernet/amd/ariadne.c", "ariadne_tx_timeout"],
["drivers/net/ethernet/amd/atarilance.c", "lance_tx_timeout"],
["drivers/net/ethernet/amd/au1000_eth.c", "au1000_tx_timeout"],
["drivers/net/ethernet/amd/declance.c", "lance_tx_timeout"],
["drivers/net/ethernet/amd/lance.c", "lance_tx_timeout"],
["drivers/net/ethernet/amd/mvme147.c", "lance_tx_timeout"],
["drivers/net/ethernet/amd/ni65.c", "ni65_timeout"],
["drivers/net/ethernet/amd/nmclan_cs.c", "mace_tx_timeout"],
["drivers/net/ethernet/amd/pcnet32.c", "pcnet32_tx_timeout"],
["drivers/net/ethernet/amd/sunlance.c", "lance_tx_timeout"],
["drivers/net/ethernet/amd/xgbe/xgbe-drv.c", "xgbe_tx_timeout"],
["drivers/net/ethernet/apm/xgene-v2/main.c", "xge_timeout"],
["drivers/net/ethernet/apm/xgene/xgene_enet_main.c", "xgene_enet_timeout"],
["drivers/net/ethernet/apple/macmace.c", "mace_tx_timeout"],
["drivers/net/ethernet/atheros/ag71xx.c", "ag71xx_tx_timeout"],
["drivers/net/ethernet/atheros/alx/main.c", "alx_tx_timeout"],
["drivers/net/ethernet/atheros/atl1c/atl1c_main.c", "atl1c_tx_timeout"],
["drivers/net/ethernet/atheros/atl1e/atl1e_main.c", "atl1e_tx_timeout"],
["drivers/net/ethernet/atheros/atlx/atl.c", "atlx_tx_timeout"],
["drivers/net/ethernet/atheros/atlx/atl1.c", "atlx_tx_timeout"],
["drivers/net/ethernet/atheros/atlx/atl2.c", "atl2_tx_timeout"],
["drivers/net/ethernet/broadcom/b44.c", "b44_tx_timeout"],
["drivers/net/ethernet/broadcom/bcmsysport.c", "bcm_sysport_tx_timeout"],
["drivers/net/ethernet/broadcom/bnx2.c", "bnx2_tx_timeout"],
["drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h", "bnx2x_tx_timeout"],
["drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c", "bnx2x_tx_timeout"],
["drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c", "bnx2x_tx_timeout"],
["drivers/net/ethernet/broadcom/bnxt/bnxt.c", "bnxt_tx_timeout"],
["drivers/net/ethernet/broadcom/genet/bcmgenet.c", "bcmgenet_timeout"],
["drivers/net/ethernet/broadcom/sb1250-mac.c", "sbmac_tx_timeout"],
["drivers/net/ethernet/broadcom/tg3.c", "tg3_tx_timeout"],
["drivers/net/ethernet/calxeda/xgmac.c", "xgmac_tx_timeout"],
["drivers/net/ethernet/cavium/liquidio/lio_main.c", "liquidio_tx_timeout"],
["drivers/net/ethernet/cavium/liquidio/lio_vf_main.c", "liquidio_tx_timeout"],
["drivers/net/ethernet/cavium/liquidio/lio_vf_rep.c", "lio_vf_rep_tx_timeout"],
["drivers/net/ethernet/cavium/thunder/nicvf_main.c", "nicvf_tx_timeout"],
["drivers/net/ethernet/cirrus/cs89x0.c", "net_timeout"],
["drivers/net/ethernet/cisco/enic/enic_main.c", "enic_tx_timeout"],
["drivers/net/ethernet/cisco/enic/enic_main.c", "enic_tx_timeout"],
["drivers/net/ethernet/cortina/gemini.c", "gmac_tx_timeout"],
["drivers/net/ethernet/davicom/dm9000.c", "dm9000_timeout"],
["drivers/net/ethernet/dec/tulip/de2104x.c", "de_tx_timeout"],
["drivers/net/ethernet/dec/tulip/tulip_core.c", "tulip_tx_timeout"],
["drivers/net/ethernet/dec/tulip/winbond-840.c", "tx_timeout"],
["drivers/net/ethernet/dlink/dl2k.c", "rio_tx_timeout"],
["drivers/net/ethernet/dlink/sundance.c", "tx_timeout"],
["drivers/net/ethernet/emulex/benet/be_main.c", "be_tx_timeout"],
["drivers/net/ethernet/ethoc.c", "ethoc_tx_timeout"],
["drivers/net/ethernet/faraday/ftgmac100.c", "ftgmac100_tx_timeout"],
["drivers/net/ethernet/fealnx.c", "fealnx_tx_timeout"],
["drivers/net/ethernet/freescale/dpaa/dpaa_eth.c", "dpaa_tx_timeout"],
["drivers/net/ethernet/freescale/fec_main.c", "fec_timeout"],
["drivers/net/ethernet/freescale/fec_mpc52xx.c", "mpc52xx_fec_tx_timeout"],
["drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c", "fs_timeout"],
["drivers/net/ethernet/freescale/gianfar.c", "gfar_timeout"],
["drivers/net/ethernet/freescale/ucc_geth.c", "ucc_geth_timeout"],
["drivers/net/ethernet/fujitsu/fmvj18x_cs.c", "fjn_tx_timeout"],
["drivers/net/ethernet/google/gve/gve_main.c", "gve_tx_timeout"],
["drivers/net/ethernet/hisilicon/hip04_eth.c", "hip04_timeout"],
["drivers/net/ethernet/hisilicon/hix5hd2_gmac.c", "hix5hd2_net_timeout"],
["drivers/net/ethernet/hisilicon/hns/hns_enet.c", "hns_nic_net_timeout"],
["drivers/net/ethernet/hisilicon/hns3/hns3_enet.c", "hns3_nic_net_timeout"],
["drivers/net/ethernet/huawei/hinic/hinic_main.c", "hinic_tx_timeout"],
["drivers/net/ethernet/i825xx/82596.c", "i596_tx_timeout"],
["drivers/net/ethernet/i825xx/ether1.c", "ether1_timeout"],
["drivers/net/ethernet/i825xx/lib82596.c", "i596_tx_timeout"],
["drivers/net/ethernet/i825xx/sun3_82586.c", "sun3_82586_timeout"],
["drivers/net/ethernet/ibm/ehea/ehea_main.c", "ehea_tx_watchdog"],
["drivers/net/ethernet/ibm/emac/core.c", "emac_tx_timeout"],
["drivers/net/ethernet/ibm/emac/core.c", "emac_tx_timeout"],
["drivers/net/ethernet/ibm/ibmvnic.c", "ibmvnic_tx_timeout"],
["drivers/net/ethernet/intel/e100.c", "e100_tx_timeout"],
["drivers/net/ethernet/intel/e1000/e1000_main.c", "e1000_tx_timeout"],
["drivers/net/ethernet/intel/e1000e/netdev.c", "e1000_tx_timeout"],
["drivers/net/ethernet/intel/fm10k/fm10k_netdev.c", "fm10k_tx_timeout"],
["drivers/net/ethernet/intel/i40e/i40e_main.c", "i40e_tx_timeout"],
["drivers/net/ethernet/intel/iavf/iavf_main.c", "iavf_tx_timeout"],
["drivers/net/ethernet/intel/ice/ice_main.c", "ice_tx_timeout"],
["drivers/net/ethernet/intel/ice/ice_main.c", "ice_tx_timeout"],
["drivers/net/ethernet/intel/igb/igb_main.c", "igb_tx_timeout"],
["drivers/net/ethernet/intel/igbvf/netdev.c", "igbvf_tx_timeout"],
["drivers/net/ethernet/intel/ixgb/ixgb_main.c", "ixgb_tx_timeout"],
["drivers/net/ethernet/intel/ixgbe/ixgbe_debugfs.c", "adapter->netdev->netdev_ops->ndo_tx_timeout(adapter->netdev);"],
["drivers/net/ethernet/intel/ixgbe/ixgbe_main.c", "ixgbe_tx_timeout"],
["drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c", "ixgbevf_tx_timeout"],
["drivers/net/ethernet/jme.c", "jme_tx_timeout"],
["drivers/net/ethernet/korina.c", "korina_tx_timeout"],
["drivers/net/ethernet/lantiq_etop.c", "ltq_etop_tx_timeout"],
["drivers/net/ethernet/marvell/mv643xx_eth.c", "mv643xx_eth_tx_timeout"],
["drivers/net/ethernet/marvell/pxa168_eth.c", "pxa168_eth_tx_timeout"],
["drivers/net/ethernet/marvell/skge.c", "skge_tx_timeout"],
["drivers/net/ethernet/marvell/sky2.c", "sky2_tx_timeout"],
["drivers/net/ethernet/marvell/sky2.c", "sky2_tx_timeout"],
["drivers/net/ethernet/mediatek/mtk_eth_soc.c", "mtk_tx_timeout"],
["drivers/net/ethernet/mellanox/mlx4/en_netdev.c", "mlx4_en_tx_timeout"],
["drivers/net/ethernet/mellanox/mlx4/en_netdev.c", "mlx4_en_tx_timeout"],
["drivers/net/ethernet/mellanox/mlx5/core/en_main.c", "mlx5e_tx_timeout"],
["drivers/net/ethernet/micrel/ks8842.c", "ks8842_tx_timeout"],
["drivers/net/ethernet/micrel/ksz884x.c", "netdev_tx_timeout"],
["drivers/net/ethernet/microchip/enc28j60.c", "enc28j60_tx_timeout"],
["drivers/net/ethernet/microchip/encx24j600.c", "encx24j600_tx_timeout"],
["drivers/net/ethernet/natsemi/sonic.h", "sonic_tx_timeout"],
["drivers/net/ethernet/natsemi/sonic.c", "sonic_tx_timeout"],
["drivers/net/ethernet/natsemi/jazzsonic.c", "sonic_tx_timeout"],
["drivers/net/ethernet/natsemi/macsonic.c", "sonic_tx_timeout"],
["drivers/net/ethernet/natsemi/natsemi.c", "ns_tx_timeout"],
["drivers/net/ethernet/natsemi/ns83820.c", "ns83820_tx_timeout"],
["drivers/net/ethernet/natsemi/xtsonic.c", "sonic_tx_timeout"],
["drivers/net/ethernet/neterion/s2io.h", "s2io_tx_watchdog"],
["drivers/net/ethernet/neterion/s2io.c", "s2io_tx_watchdog"],
["drivers/net/ethernet/neterion/vxge/vxge-main.c", "vxge_tx_watchdog"],
["drivers/net/ethernet/netronome/nfp/nfp_net_common.c", "nfp_net_tx_timeout"],
["drivers/net/ethernet/nvidia/forcedeth.c", "nv_tx_timeout"],
["drivers/net/ethernet/nvidia/forcedeth.c", "nv_tx_timeout"],
["drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c", "pch_gbe_tx_timeout"],
["drivers/net/ethernet/packetengines/hamachi.c", "hamachi_tx_timeout"],
["drivers/net/ethernet/packetengines/yellowfin.c", "yellowfin_tx_timeout"],
["drivers/net/ethernet/pensando/ionic/ionic_lif.c", "ionic_tx_timeout"],
["drivers/net/ethernet/qlogic/netxen/netxen_nic_main.c", "netxen_tx_timeout"],
["drivers/net/ethernet/qlogic/qla3xxx.c", "ql3xxx_tx_timeout"],
["drivers/net/ethernet/qlogic/qlcnic/qlcnic_main.c", "qlcnic_tx_timeout"],
["drivers/net/ethernet/qualcomm/emac/emac.c", "emac_tx_timeout"],
["drivers/net/ethernet/qualcomm/qca_spi.c", "qcaspi_netdev_tx_timeout"],
["drivers/net/ethernet/qualcomm/qca_uart.c", "qcauart_netdev_tx_timeout"],
["drivers/net/ethernet/rdc/r6040.c", "r6040_tx_timeout"],
["drivers/net/ethernet/realtek/8139cp.c", "cp_tx_timeout"],
["drivers/net/ethernet/realtek/8139too.c", "rtl8139_tx_timeout"],
["drivers/net/ethernet/realtek/atp.c", "tx_timeout"],
["drivers/net/ethernet/realtek/r8169_main.c", "rtl8169_tx_timeout"],
["drivers/net/ethernet/renesas/ravb_main.c", "ravb_tx_timeout"],
["drivers/net/ethernet/renesas/sh_eth.c", "sh_eth_tx_timeout"],
["drivers/net/ethernet/renesas/sh_eth.c", "sh_eth_tx_timeout"],
["drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c", "sxgbe_tx_timeout"],
["drivers/net/ethernet/seeq/ether3.c", "ether3_timeout"],
["drivers/net/ethernet/seeq/sgiseeq.c", "timeout"],
["drivers/net/ethernet/sfc/efx.c", "efx_watchdog"],
["drivers/net/ethernet/sfc/falcon/efx.c", "ef4_watchdog"],
["drivers/net/ethernet/sgi/ioc3-eth.c", "ioc3_timeout"],
["drivers/net/ethernet/sgi/meth.c", "meth_tx_timeout"],
["drivers/net/ethernet/silan/sc92031.c", "sc92031_tx_timeout"],
["drivers/net/ethernet/sis/sis190.c", "sis190_tx_timeout"],
["drivers/net/ethernet/sis/sis900.c", "sis900_tx_timeout"],
["drivers/net/ethernet/smsc/epic100.c", "epic_tx_timeout"],
["drivers/net/ethernet/smsc/smc911x.c", "smc911x_timeout"],
["drivers/net/ethernet/smsc/smc9194.c", "smc_timeout"],
["drivers/net/ethernet/smsc/smc91c92_cs.c", "smc_tx_timeout"],
["drivers/net/ethernet/smsc/smc91x.c", "smc_timeout"],
["drivers/net/ethernet/stmicro/stmmac/stmmac_main.c", "stmmac_tx_timeout"],
["drivers/net/ethernet/sun/cassini.c", "cas_tx_timeout"],
["drivers/net/ethernet/sun/ldmvsw.c", "sunvnet_tx_timeout_common"],
["drivers/net/ethernet/sun/niu.c", "niu_tx_timeout"],
["drivers/net/ethernet/sun/sunbmac.c", "bigmac_tx_timeout"],
["drivers/net/ethernet/sun/sungem.c", "gem_tx_timeout"],
["drivers/net/ethernet/sun/sunhme.c", "happy_meal_tx_timeout"],
["drivers/net/ethernet/sun/sunqe.c", "qe_tx_timeout"],
["drivers/net/ethernet/sun/sunvnet.c", "sunvnet_tx_timeout_common"],
["drivers/net/ethernet/sun/sunvnet_common.c", "sunvnet_tx_timeout_common"],
["drivers/net/ethernet/sun/sunvnet_common.h", "sunvnet_tx_timeout_common"],
["drivers/net/ethernet/synopsys/dwc-xlgmac-net.c", "xlgmac_tx_timeout"],
["drivers/net/ethernet/ti/cpmac.c", "cpmac_tx_timeout"],
["drivers/net/ethernet/ti/cpsw.c", "cpsw_ndo_tx_timeout"],
["drivers/net/ethernet/ti/cpsw_priv.c", "cpsw_ndo_tx_timeout"],
["drivers/net/ethernet/ti/cpsw_priv.h", "cpsw_ndo_tx_timeout"],
["drivers/net/ethernet/ti/davinci_emac.c", "emac_dev_tx_timeout"],
["drivers/net/ethernet/ti/netcp_core.c", "netcp_ndo_tx_timeout"],
["drivers/net/ethernet/ti/tlan.c", "tlan_tx_timeout"],
["drivers/net/ethernet/toshiba/ps3_gelic_net.h", "gelic_net_tx_timeout"],
["drivers/net/ethernet/toshiba/ps3_gelic_net.c", "gelic_net_tx_timeout"],
["drivers/net/ethernet/toshiba/ps3_gelic_wireless.c", "gelic_net_tx_timeout"],
["drivers/net/ethernet/toshiba/spider_net.c", "spider_net_tx_timeout"],
["drivers/net/ethernet/toshiba/tc35815.c", "tc35815_tx_timeout"],
["drivers/net/ethernet/via/via-rhine.c", "rhine_tx_timeout"],
["drivers/net/ethernet/wiznet/w5100.c", "w5100_tx_timeout"],
["drivers/net/ethernet/wiznet/w5300.c", "w5300_tx_timeout"],
["drivers/net/ethernet/xilinx/xilinx_emaclite.c", "xemaclite_tx_timeout"],
["drivers/net/ethernet/xircom/xirc2ps_cs.c", "xirc_tx_timeout"],
["drivers/net/fjes/fjes_main.c", "fjes_tx_retry"],
["drivers/net/slip/slip.c", "sl_tx_timeout"],
["include/linux/usb/usbnet.h", "usbnet_tx_timeout"],
["drivers/net/usb/aqc111.c", "usbnet_tx_timeout"],
["drivers/net/usb/asix_devices.c", "usbnet_tx_timeout"],
["drivers/net/usb/asix_devices.c", "usbnet_tx_timeout"],
["drivers/net/usb/asix_devices.c", "usbnet_tx_timeout"],
["drivers/net/usb/ax88172a.c", "usbnet_tx_timeout"],
["drivers/net/usb/ax88179_178a.c", "usbnet_tx_timeout"],
["drivers/net/usb/catc.c", "catc_tx_timeout"],
["drivers/net/usb/cdc_mbim.c", "usbnet_tx_timeout"],
["drivers/net/usb/cdc_ncm.c", "usbnet_tx_timeout"],
["drivers/net/usb/dm9601.c", "usbnet_tx_timeout"],
["drivers/net/usb/hso.c", "hso_net_tx_timeout"],
["drivers/net/usb/int51x1.c", "usbnet_tx_timeout"],
["drivers/net/usb/ipheth.c", "ipheth_tx_timeout"],
["drivers/net/usb/kaweth.c", "kaweth_tx_timeout"],
["drivers/net/usb/lan78xx.c", "lan78xx_tx_timeout"],
["drivers/net/usb/mcs7830.c", "usbnet_tx_timeout"],
["drivers/net/usb/pegasus.c", "pegasus_tx_timeout"],
["drivers/net/usb/qmi_wwan.c", "usbnet_tx_timeout"],
["drivers/net/usb/r8152.c", "rtl8152_tx_timeout"],
["drivers/net/usb/rndis_host.c", "usbnet_tx_timeout"],
["drivers/net/usb/rtl8150.c", "rtl8150_tx_timeout"],
["drivers/net/usb/sierra_net.c", "usbnet_tx_timeout"],
["drivers/net/usb/smsc75xx.c", "usbnet_tx_timeout"],
["drivers/net/usb/smsc95xx.c", "usbnet_tx_timeout"],
["drivers/net/usb/sr9700.c", "usbnet_tx_timeout"],
["drivers/net/usb/sr9800.c", "usbnet_tx_timeout"],
["drivers/net/usb/usbnet.c", "usbnet_tx_timeout"],
["drivers/net/vmxnet3/vmxnet3_drv.c", "vmxnet3_tx_timeout"],
["drivers/net/wan/cosa.c", "cosa_net_timeout"],
["drivers/net/wan/farsync.c", "fst_tx_timeout"],
["drivers/net/wan/fsl_ucc_hdlc.c", "uhdlc_tx_timeout"],
["drivers/net/wan/lmc/lmc_main.c", "lmc_driver_timeout"],
["drivers/net/wan/x25_asy.c", "x25_asy_timeout"],
["drivers/net/wimax/i2400m/netdev.c", "i2400m_tx_timeout"],
["drivers/net/wireless/intel/ipw2x00/ipw2100.c", "ipw2100_tx_timeout"],
["drivers/net/wireless/intersil/hostap/hostap_main.c", "prism2_tx_timeout"],
["drivers/net/wireless/intersil/hostap/hostap_main.c", "prism2_tx_timeout"],
["drivers/net/wireless/intersil/hostap/hostap_main.c", "prism2_tx_timeout"],
["drivers/net/wireless/intersil/orinoco/main.c", "orinoco_tx_timeout"],
["drivers/net/wireless/intersil/orinoco/orinoco_usb.c", "orinoco_tx_timeout"],
["drivers/net/wireless/intersil/orinoco/orinoco.h", "orinoco_tx_timeout"],
["drivers/net/wireless/intersil/prism54/islpci_dev.c", "islpci_eth_tx_timeout"],
["drivers/net/wireless/intersil/prism54/islpci_eth.c", "islpci_eth_tx_timeout"],
["drivers/net/wireless/intersil/prism54/islpci_eth.h", "islpci_eth_tx_timeout"],
["drivers/net/wireless/marvell/mwifiex/main.c", "mwifiex_tx_timeout"],
["drivers/net/wireless/quantenna/qtnfmac/core.c", "qtnf_netdev_tx_timeout"],
["drivers/net/wireless/quantenna/qtnfmac/core.h", "qtnf_netdev_tx_timeout"],
["drivers/net/wireless/rndis_wlan.c", "usbnet_tx_timeout"],
["drivers/net/wireless/wl3501_cs.c", "wl3501_tx_timeout"],
["drivers/net/wireless/zydas/zd1201.c", "zd1201_tx_timeout"],
["drivers/s390/net/qeth_core.h", "qeth_tx_timeout"],
["drivers/s390/net/qeth_core_main.c", "qeth_tx_timeout"],
["drivers/s390/net/qeth_l2_main.c", "qeth_tx_timeout"],
["drivers/s390/net/qeth_l2_main.c", "qeth_tx_timeout"],
["drivers/s390/net/qeth_l3_main.c", "qeth_tx_timeout"],
["drivers/s390/net/qeth_l3_main.c", "qeth_tx_timeout"],
["drivers/staging/ks7010/ks_wlan_net.c", "ks_wlan_tx_timeout"],
["drivers/staging/qlge/qlge_main.c", "qlge_tx_timeout"],
["drivers/staging/rtl8192e/rtl8192e/rtl_core.c", "_rtl92e_tx_timeout"],
["drivers/staging/rtl8192u/r8192U_core.c", "tx_timeout"],
["drivers/staging/unisys/visornic/visornic_main.c", "visornic_xmit_timeout"],
["drivers/staging/wlan-ng/p80211netdev.c", "p80211knetdev_tx_timeout"],
["drivers/tty/n_gsm.c", "gsm_mux_net_tx_timeout"],
["drivers/tty/synclink.c", "hdlcdev_tx_timeout"],
["drivers/tty/synclink_gt.c", "hdlcdev_tx_timeout"],
["drivers/tty/synclinkmp.c", "hdlcdev_tx_timeout"],
["net/atm/lec.c", "lec_tx_timeout"],
["net/bluetooth/bnep/netdev.c", "bnep_net_timeout"]
);
for my $p (@work) {
my @pair = @$p;
my $file = $pair[0];
my $func = $pair[1];
print STDERR $file , ": ", $func,"\n";
our @ARGV = ($file);
while (<ARGV>) {
if (m/($func\s*\(struct\s+net_device\s+\*[A-Za-z_]?[A-Za-z-0-9_]*)(\))/) {
print STDERR "found $1+$2 in $file\n";
}
if (s/($func\s*\(struct\s+net_device\s+\*[A-Za-z_]?[A-Za-z-0-9_]*)(\))/$1, unsigned int txqueue$2/) {
print STDERR "$func found in $file\n";
}
print;
}
}
where the list of files and functions is simply from:
git grep ndo_tx_timeout, with manual addition of headers
in the rare cases where the function is from a header,
then manually changing the few places which actually
call ndo_tx_timeout.
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Acked-by: Heiner Kallweit <hkallweit1@gmail.com>
Acked-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Acked-by: Shannon Nelson <snelson@pensando.io>
Reviewed-by: Martin Habets <mhabets@solarflare.com>
changes from v9:
fixup a forward declaration
changes from v9:
more leftovers from v3 change
changes from v8:
fix up a missing direct call to timeout
rebased on net-next
changes from v7:
fixup leftovers from v3 change
changes from v6:
fix typo in rtl driver
changes from v5:
add missing files (allow any net device argument name)
changes from v4:
add a missing driver header
changes from v3:
change queue # to unsigned
Changes from v2:
added headers
Changes from v1:
Fix errors found by kbuild:
generalize the pattern a bit, to pick up
a couple of instances missed by the previous
version.
Signed-off-by: David S. Miller <davem@davemloft.net>
2019-12-10 14:23:51 +00:00
|
|
|
static void ethoc_tx_timeout(struct net_device *dev, unsigned int txqueue)
|
2009-03-27 07:12:24 +00:00
|
|
|
{
|
|
|
|
struct ethoc *priv = netdev_priv(dev);
|
|
|
|
u32 pending = ethoc_read(priv, INT_SOURCE);
|
|
|
|
if (likely(pending))
|
|
|
|
ethoc_interrupt(dev->irq, dev);
|
|
|
|
}
|
|
|
|
|
2009-08-31 19:50:58 +00:00
|
|
|
static netdev_tx_t ethoc_start_xmit(struct sk_buff *skb, struct net_device *dev)
|
2009-03-27 07:12:24 +00:00
|
|
|
{
|
|
|
|
struct ethoc *priv = netdev_priv(dev);
|
|
|
|
struct ethoc_bd bd;
|
|
|
|
unsigned int entry;
|
|
|
|
void *dest;
|
|
|
|
|
2016-07-12 23:04:36 +00:00
|
|
|
if (skb_put_padto(skb, ETHOC_ZLEN)) {
|
|
|
|
dev->stats.tx_errors++;
|
|
|
|
goto out_no_free;
|
|
|
|
}
|
|
|
|
|
2009-03-27 07:12:24 +00:00
|
|
|
if (unlikely(skb->len > ETHOC_BUFSIZ)) {
|
2010-07-05 02:13:31 +00:00
|
|
|
dev->stats.tx_errors++;
|
2009-06-12 03:00:35 +00:00
|
|
|
goto out;
|
2009-03-27 07:12:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
entry = priv->cur_tx % priv->num_tx;
|
|
|
|
spin_lock_irq(&priv->lock);
|
|
|
|
priv->cur_tx++;
|
|
|
|
|
|
|
|
ethoc_read_bd(priv, entry, &bd);
|
|
|
|
if (unlikely(skb->len < ETHOC_ZLEN))
|
|
|
|
bd.stat |= TX_BD_PAD;
|
|
|
|
else
|
|
|
|
bd.stat &= ~TX_BD_PAD;
|
|
|
|
|
2010-06-11 02:47:35 +00:00
|
|
|
dest = priv->vma[entry];
|
2009-03-27 07:12:24 +00:00
|
|
|
memcpy_toio(dest, skb->data, skb->len);
|
|
|
|
|
|
|
|
bd.stat &= ~(TX_BD_STATS | TX_BD_LEN_MASK);
|
|
|
|
bd.stat |= TX_BD_LEN(skb->len);
|
|
|
|
ethoc_write_bd(priv, entry, &bd);
|
|
|
|
|
|
|
|
bd.stat |= TX_BD_READY;
|
|
|
|
ethoc_write_bd(priv, entry, &bd);
|
|
|
|
|
|
|
|
if (priv->cur_tx == (priv->dty_tx + priv->num_tx)) {
|
|
|
|
dev_dbg(&dev->dev, "stopping queue\n");
|
|
|
|
netif_stop_queue(dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
spin_unlock_irq(&priv->lock);
|
2011-06-12 02:19:04 +00:00
|
|
|
skb_tx_timestamp(skb);
|
2009-06-12 03:00:35 +00:00
|
|
|
out:
|
|
|
|
dev_kfree_skb(skb);
|
2016-07-12 23:04:36 +00:00
|
|
|
out_no_free:
|
2009-03-27 07:12:24 +00:00
|
|
|
return NETDEV_TX_OK;
|
|
|
|
}
|
|
|
|
|
2014-01-31 05:41:06 +00:00
|
|
|
static int ethoc_get_regs_len(struct net_device *netdev)
|
|
|
|
{
|
|
|
|
return ETH_END;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ethoc_get_regs(struct net_device *dev, struct ethtool_regs *regs,
|
|
|
|
void *p)
|
|
|
|
{
|
|
|
|
struct ethoc *priv = netdev_priv(dev);
|
|
|
|
u32 *regs_buff = p;
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
regs->version = 0;
|
|
|
|
for (i = 0; i < ETH_END / sizeof(u32); ++i)
|
|
|
|
regs_buff[i] = ethoc_read(priv, i * sizeof(u32));
|
|
|
|
}
|
|
|
|
|
2014-01-31 05:41:07 +00:00
|
|
|
static void ethoc_get_ringparam(struct net_device *dev,
|
|
|
|
struct ethtool_ringparam *ring)
|
|
|
|
{
|
|
|
|
struct ethoc *priv = netdev_priv(dev);
|
|
|
|
|
|
|
|
ring->rx_max_pending = priv->num_bd - 1;
|
|
|
|
ring->rx_mini_max_pending = 0;
|
|
|
|
ring->rx_jumbo_max_pending = 0;
|
|
|
|
ring->tx_max_pending = priv->num_bd - 1;
|
|
|
|
|
|
|
|
ring->rx_pending = priv->num_rx;
|
|
|
|
ring->rx_mini_pending = 0;
|
|
|
|
ring->rx_jumbo_pending = 0;
|
|
|
|
ring->tx_pending = priv->num_tx;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ethoc_set_ringparam(struct net_device *dev,
|
|
|
|
struct ethtool_ringparam *ring)
|
|
|
|
{
|
|
|
|
struct ethoc *priv = netdev_priv(dev);
|
|
|
|
|
|
|
|
if (ring->tx_pending < 1 || ring->rx_pending < 1 ||
|
|
|
|
ring->tx_pending + ring->rx_pending > priv->num_bd)
|
|
|
|
return -EINVAL;
|
|
|
|
if (ring->rx_mini_pending || ring->rx_jumbo_pending)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (netif_running(dev)) {
|
|
|
|
netif_tx_disable(dev);
|
|
|
|
ethoc_disable_rx_and_tx(priv);
|
|
|
|
ethoc_disable_irq(priv, INT_MASK_TX | INT_MASK_RX);
|
|
|
|
synchronize_irq(dev->irq);
|
|
|
|
}
|
|
|
|
|
|
|
|
priv->num_tx = rounddown_pow_of_two(ring->tx_pending);
|
|
|
|
priv->num_rx = ring->rx_pending;
|
|
|
|
ethoc_init_ring(priv, dev->mem_start);
|
|
|
|
|
|
|
|
if (netif_running(dev)) {
|
|
|
|
ethoc_enable_irq(priv, INT_MASK_TX | INT_MASK_RX);
|
|
|
|
ethoc_enable_rx_and_tx(priv);
|
|
|
|
netif_wake_queue(dev);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-01-17 14:01:08 +00:00
|
|
|
static const struct ethtool_ops ethoc_ethtool_ops = {
|
2014-01-31 05:41:06 +00:00
|
|
|
.get_regs_len = ethoc_get_regs_len,
|
|
|
|
.get_regs = ethoc_get_regs,
|
2016-11-15 19:19:46 +00:00
|
|
|
.nway_reset = phy_ethtool_nway_reset,
|
2014-01-31 05:41:04 +00:00
|
|
|
.get_link = ethtool_op_get_link,
|
2014-01-31 05:41:07 +00:00
|
|
|
.get_ringparam = ethoc_get_ringparam,
|
|
|
|
.set_ringparam = ethoc_set_ringparam,
|
2014-01-31 05:41:04 +00:00
|
|
|
.get_ts_info = ethtool_op_get_ts_info,
|
2016-07-15 07:59:12 +00:00
|
|
|
.get_link_ksettings = phy_ethtool_get_link_ksettings,
|
|
|
|
.set_link_ksettings = phy_ethtool_set_link_ksettings,
|
2014-01-31 05:41:04 +00:00
|
|
|
};
|
|
|
|
|
2009-03-27 07:12:24 +00:00
|
|
|
static const struct net_device_ops ethoc_netdev_ops = {
|
|
|
|
.ndo_open = ethoc_open,
|
|
|
|
.ndo_stop = ethoc_stop,
|
|
|
|
.ndo_do_ioctl = ethoc_ioctl,
|
|
|
|
.ndo_set_mac_address = ethoc_set_mac_address,
|
2011-08-16 06:29:01 +00:00
|
|
|
.ndo_set_rx_mode = ethoc_set_multicast_list,
|
2009-03-27 07:12:24 +00:00
|
|
|
.ndo_change_mtu = ethoc_change_mtu,
|
|
|
|
.ndo_tx_timeout = ethoc_tx_timeout,
|
|
|
|
.ndo_start_xmit = ethoc_start_xmit,
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2012-07-10 10:56:00 +00:00
|
|
|
* ethoc_probe - initialize OpenCores ethernet MAC
|
drivers/net/ethernet: clean up mis-targeted comments
As part of the W=1 cleanups for ethernet, a million [*] driver
comments had to be cleaned up to get the W=1 compilation to
succeed. This change finally makes the drivers/net/ethernet tree
compile with W=1 set on the command line. NOTE: The kernel uses
kdoc style (see Documentation/process/kernel-doc.rst) when
documenting code, not doxygen or other styles.
After this patch the x86_64 build has no warnings from W=1, however
scripts/kernel-doc says there are 1545 more warnings in source files, that
I need to develop a script to fix in a followup patch.
The errors fixed here are all kdoc of a few classes, with a few outliers:
In file included from drivers/net/ethernet/qlogic/netxen/netxen_nic_hw.c:10:
drivers/net/ethernet/qlogic/netxen/netxen_nic.h:1193:18: warning: ‘FW_DUMP_LEVELS’ defined but not used [-Wunused-const-variable=]
1193 | static const u32 FW_DUMP_LEVELS[] = { 0x3, 0x7, 0xf, 0x1f, 0x3f, 0x7f, 0xff };
| ^~~~~~~~~~~~~~
... repeats 4 times...
drivers/net/ethernet/sun/cassini.c:2084:24: warning: suggest braces around empty body in an ‘else’ statement [-Wempty-body]
2084 | RX_USED_ADD(page, i);
drivers/net/ethernet/natsemi/ns83820.c: In function ‘phy_intr’:
drivers/net/ethernet/natsemi/ns83820.c:603:6: warning: variable ‘tbisr’ set but not used [-Wunused-but-set-variable]
603 | u32 tbisr, tanar, tanlpar;
| ^~~~~
drivers/net/ethernet/natsemi/ns83820.c: In function ‘ns83820_get_link_ksettings’:
drivers/net/ethernet/natsemi/ns83820.c:1207:11: warning: variable ‘tanar’ set but not used [-Wunused-but-set-variable]
1207 | u32 cfg, tanar, tbicr;
| ^~~~~
drivers/net/ethernet/packetengines/yellowfin.c:1063:18: warning: variable ‘yf_size’ set but not used [-Wunused-but-set-variable]
1063 | int data_size, yf_size;
| ^~~~~~~
Normal kdoc fixes:
warning: Function parameter or member 'x' not described in 'y'
warning: Excess function parameter 'x' description in 'y'
warning: Cannot understand <string> on line <NNN> - I thought it was a doc line
[*] - ok it wasn't quite a million, but it felt like it.
Signed-off-by: Jesse Brandeburg <jesse.brandeburg@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2020-09-25 22:24:45 +00:00
|
|
|
* @pdev: platform device
|
2009-03-27 07:12:24 +00:00
|
|
|
*/
|
2012-12-03 14:24:09 +00:00
|
|
|
static int ethoc_probe(struct platform_device *pdev)
|
2009-03-27 07:12:24 +00:00
|
|
|
{
|
|
|
|
struct net_device *netdev = NULL;
|
|
|
|
struct resource *res = NULL;
|
|
|
|
struct resource *mmio = NULL;
|
|
|
|
struct resource *mem = NULL;
|
|
|
|
struct ethoc *priv = NULL;
|
2010-06-11 02:47:34 +00:00
|
|
|
int num_bd;
|
2009-03-27 07:12:24 +00:00
|
|
|
int ret = 0;
|
2014-02-03 23:33:10 +00:00
|
|
|
struct ethoc_platform_data *pdata = dev_get_platdata(&pdev->dev);
|
|
|
|
u32 eth_clkfreq = pdata ? pdata->eth_clkfreq : 0;
|
2009-03-27 07:12:24 +00:00
|
|
|
|
|
|
|
/* allocate networking device */
|
|
|
|
netdev = alloc_etherdev(sizeof(struct ethoc));
|
|
|
|
if (!netdev) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
SET_NETDEV_DEV(netdev, &pdev->dev);
|
|
|
|
platform_set_drvdata(pdev, netdev);
|
|
|
|
|
|
|
|
/* obtain I/O memory space */
|
|
|
|
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
|
|
|
if (!res) {
|
|
|
|
dev_err(&pdev->dev, "cannot obtain I/O memory space\n");
|
|
|
|
ret = -ENXIO;
|
|
|
|
goto free;
|
|
|
|
}
|
|
|
|
|
|
|
|
mmio = devm_request_mem_region(&pdev->dev, res->start,
|
2010-01-15 09:48:22 +00:00
|
|
|
resource_size(res), res->name);
|
2009-07-27 06:13:30 +00:00
|
|
|
if (!mmio) {
|
2009-03-27 07:12:24 +00:00
|
|
|
dev_err(&pdev->dev, "cannot request I/O memory space\n");
|
|
|
|
ret = -ENXIO;
|
|
|
|
goto free;
|
|
|
|
}
|
|
|
|
|
|
|
|
netdev->base_addr = mmio->start;
|
|
|
|
|
|
|
|
/* obtain buffer memory space */
|
|
|
|
res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
|
2009-10-04 23:33:20 +00:00
|
|
|
if (res) {
|
|
|
|
mem = devm_request_mem_region(&pdev->dev, res->start,
|
2010-01-15 09:48:22 +00:00
|
|
|
resource_size(res), res->name);
|
2009-10-04 23:33:20 +00:00
|
|
|
if (!mem) {
|
|
|
|
dev_err(&pdev->dev, "cannot request memory space\n");
|
|
|
|
ret = -ENXIO;
|
|
|
|
goto free;
|
|
|
|
}
|
|
|
|
|
|
|
|
netdev->mem_start = mem->start;
|
|
|
|
netdev->mem_end = mem->end;
|
2009-03-27 07:12:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* obtain device IRQ number */
|
|
|
|
res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
|
|
|
|
if (!res) {
|
|
|
|
dev_err(&pdev->dev, "cannot obtain IRQ\n");
|
|
|
|
ret = -ENXIO;
|
|
|
|
goto free;
|
|
|
|
}
|
|
|
|
|
|
|
|
netdev->irq = res->start;
|
|
|
|
|
|
|
|
/* setup driver-private data */
|
|
|
|
priv = netdev_priv(netdev);
|
|
|
|
priv->netdev = netdev;
|
|
|
|
|
2020-01-06 08:43:50 +00:00
|
|
|
priv->iobase = devm_ioremap(&pdev->dev, netdev->base_addr,
|
2010-01-15 09:48:22 +00:00
|
|
|
resource_size(mmio));
|
2009-03-27 07:12:24 +00:00
|
|
|
if (!priv->iobase) {
|
|
|
|
dev_err(&pdev->dev, "cannot remap I/O memory space\n");
|
|
|
|
ret = -ENXIO;
|
2016-07-12 23:04:35 +00:00
|
|
|
goto free;
|
2009-03-27 07:12:24 +00:00
|
|
|
}
|
|
|
|
|
2009-10-04 23:33:20 +00:00
|
|
|
if (netdev->mem_end) {
|
2020-01-06 08:43:50 +00:00
|
|
|
priv->membase = devm_ioremap(&pdev->dev,
|
2010-01-15 09:48:22 +00:00
|
|
|
netdev->mem_start, resource_size(mem));
|
2009-10-04 23:33:20 +00:00
|
|
|
if (!priv->membase) {
|
|
|
|
dev_err(&pdev->dev, "cannot remap memory space\n");
|
|
|
|
ret = -ENXIO;
|
2016-07-12 23:04:35 +00:00
|
|
|
goto free;
|
2009-10-04 23:33:20 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Allocate buffer memory */
|
2010-06-11 02:47:40 +00:00
|
|
|
priv->membase = dmam_alloc_coherent(&pdev->dev,
|
2009-10-04 23:33:20 +00:00
|
|
|
buffer_size, (void *)&netdev->mem_start,
|
|
|
|
GFP_KERNEL);
|
|
|
|
if (!priv->membase) {
|
|
|
|
dev_err(&pdev->dev, "cannot allocate %dB buffer\n",
|
|
|
|
buffer_size);
|
|
|
|
ret = -ENOMEM;
|
2016-07-12 23:04:35 +00:00
|
|
|
goto free;
|
2009-10-04 23:33:20 +00:00
|
|
|
}
|
|
|
|
netdev->mem_end = netdev->mem_start + buffer_size;
|
2009-03-27 07:12:24 +00:00
|
|
|
}
|
|
|
|
|
2015-09-22 11:27:16 +00:00
|
|
|
priv->big_endian = pdata ? pdata->big_endian :
|
|
|
|
of_device_is_big_endian(pdev->dev.of_node);
|
|
|
|
|
2010-06-11 02:47:34 +00:00
|
|
|
/* calculate the number of TX/RX buffers, maximum 128 supported */
|
|
|
|
num_bd = min_t(unsigned int,
|
|
|
|
128, (netdev->mem_end - netdev->mem_start + 1) / ETHOC_BUFSIZ);
|
2010-11-25 02:30:32 +00:00
|
|
|
if (num_bd < 4) {
|
|
|
|
ret = -ENODEV;
|
2016-07-12 23:04:35 +00:00
|
|
|
goto free;
|
2010-11-25 02:30:32 +00:00
|
|
|
}
|
2014-01-31 05:41:07 +00:00
|
|
|
priv->num_bd = num_bd;
|
2010-11-25 02:30:32 +00:00
|
|
|
/* num_tx must be a power of two */
|
|
|
|
priv->num_tx = rounddown_pow_of_two(num_bd >> 1);
|
2010-06-11 02:47:34 +00:00
|
|
|
priv->num_rx = num_bd - priv->num_tx;
|
|
|
|
|
2010-11-25 02:30:32 +00:00
|
|
|
dev_dbg(&pdev->dev, "ethoc: num_tx: %d num_rx: %d\n",
|
|
|
|
priv->num_tx, priv->num_rx);
|
|
|
|
|
treewide: devm_kzalloc() -> devm_kcalloc()
The devm_kzalloc() function has a 2-factor argument form, devm_kcalloc().
This patch replaces cases of:
devm_kzalloc(handle, a * b, gfp)
with:
devm_kcalloc(handle, a * b, gfp)
as well as handling cases of:
devm_kzalloc(handle, a * b * c, gfp)
with:
devm_kzalloc(handle, array3_size(a, b, c), gfp)
as it's slightly less ugly than:
devm_kcalloc(handle, array_size(a, b), c, gfp)
This does, however, attempt to ignore constant size factors like:
devm_kzalloc(handle, 4 * 1024, gfp)
though any constants defined via macros get caught up in the conversion.
Any factors with a sizeof() of "unsigned char", "char", and "u8" were
dropped, since they're redundant.
Some manual whitespace fixes were needed in this patch, as Coccinelle
really liked to write "=devm_kcalloc..." instead of "= devm_kcalloc...".
The Coccinelle script used for this was:
// Fix redundant parens around sizeof().
@@
expression HANDLE;
type TYPE;
expression THING, E;
@@
(
devm_kzalloc(HANDLE,
- (sizeof(TYPE)) * E
+ sizeof(TYPE) * E
, ...)
|
devm_kzalloc(HANDLE,
- (sizeof(THING)) * E
+ sizeof(THING) * E
, ...)
)
// Drop single-byte sizes and redundant parens.
@@
expression HANDLE;
expression COUNT;
typedef u8;
typedef __u8;
@@
(
devm_kzalloc(HANDLE,
- sizeof(u8) * (COUNT)
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(__u8) * (COUNT)
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(char) * (COUNT)
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(unsigned char) * (COUNT)
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(u8) * COUNT
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(__u8) * COUNT
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(char) * COUNT
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(unsigned char) * COUNT
+ COUNT
, ...)
)
// 2-factor product with sizeof(type/expression) and identifier or constant.
@@
expression HANDLE;
type TYPE;
expression THING;
identifier COUNT_ID;
constant COUNT_CONST;
@@
(
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * (COUNT_ID)
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * COUNT_ID
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * (COUNT_CONST)
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * COUNT_CONST
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * (COUNT_ID)
+ COUNT_ID, sizeof(THING)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * COUNT_ID
+ COUNT_ID, sizeof(THING)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * (COUNT_CONST)
+ COUNT_CONST, sizeof(THING)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * COUNT_CONST
+ COUNT_CONST, sizeof(THING)
, ...)
)
// 2-factor product, only identifiers.
@@
expression HANDLE;
identifier SIZE, COUNT;
@@
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- SIZE * COUNT
+ COUNT, SIZE
, ...)
// 3-factor product with 1 sizeof(type) or sizeof(expression), with
// redundant parens removed.
@@
expression HANDLE;
expression THING;
identifier STRIDE, COUNT;
type TYPE;
@@
(
devm_kzalloc(HANDLE,
- sizeof(TYPE) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
)
// 3-factor product with 2 sizeof(variable), with redundant parens removed.
@@
expression HANDLE;
expression THING1, THING2;
identifier COUNT;
type TYPE1, TYPE2;
@@
(
devm_kzalloc(HANDLE,
- sizeof(TYPE1) * sizeof(TYPE2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
)
// 3-factor product, only identifiers, with redundant parens removed.
@@
expression HANDLE;
identifier STRIDE, SIZE, COUNT;
@@
(
devm_kzalloc(HANDLE,
- (COUNT) * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- COUNT * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- COUNT * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- (COUNT) * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- COUNT * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- (COUNT) * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- (COUNT) * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- COUNT * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
)
// Any remaining multi-factor products, first at least 3-factor products,
// when they're not all constants...
@@
expression HANDLE;
expression E1, E2, E3;
constant C1, C2, C3;
@@
(
devm_kzalloc(HANDLE, C1 * C2 * C3, ...)
|
devm_kzalloc(HANDLE,
- (E1) * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
|
devm_kzalloc(HANDLE,
- (E1) * (E2) * E3
+ array3_size(E1, E2, E3)
, ...)
|
devm_kzalloc(HANDLE,
- (E1) * (E2) * (E3)
+ array3_size(E1, E2, E3)
, ...)
|
devm_kzalloc(HANDLE,
- E1 * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
)
// And then all remaining 2 factors products when they're not all constants,
// keeping sizeof() as the second factor argument.
@@
expression HANDLE;
expression THING, E1, E2;
type TYPE;
constant C1, C2, C3;
@@
(
devm_kzalloc(HANDLE, sizeof(THING) * C2, ...)
|
devm_kzalloc(HANDLE, sizeof(TYPE) * C2, ...)
|
devm_kzalloc(HANDLE, C1 * C2 * C3, ...)
|
devm_kzalloc(HANDLE, C1 * C2, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * (E2)
+ E2, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * E2
+ E2, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * (E2)
+ E2, sizeof(THING)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * E2
+ E2, sizeof(THING)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- (E1) * E2
+ E1, E2
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- (E1) * (E2)
+ E1, E2
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- E1 * E2
+ E1, E2
, ...)
)
Signed-off-by: Kees Cook <keescook@chromium.org>
2018-06-12 21:07:58 +00:00
|
|
|
priv->vma = devm_kcalloc(&pdev->dev, num_bd, sizeof(void *),
|
|
|
|
GFP_KERNEL);
|
2010-06-11 02:47:35 +00:00
|
|
|
if (!priv->vma) {
|
|
|
|
ret = -ENOMEM;
|
2016-07-12 23:04:35 +00:00
|
|
|
goto free;
|
2010-06-11 02:47:35 +00:00
|
|
|
}
|
|
|
|
|
2009-03-27 07:12:24 +00:00
|
|
|
/* Allow the platform setup code to pass in a MAC address. */
|
2014-02-03 23:33:10 +00:00
|
|
|
if (pdata) {
|
2017-03-17 10:52:15 +00:00
|
|
|
ether_addr_copy(netdev->dev_addr, pdata->hwaddr);
|
2009-03-27 07:12:24 +00:00
|
|
|
priv->phy_id = pdata->phy_id;
|
2010-11-25 02:30:25 +00:00
|
|
|
} else {
|
of: net: pass the dst buffer to of_get_mac_address()
of_get_mac_address() returns a "const void*" pointer to a MAC address.
Lately, support to fetch the MAC address by an NVMEM provider was added.
But this will only work with platform devices. It will not work with
PCI devices (e.g. of an integrated root complex) and esp. not with DSA
ports.
There is an of_* variant of the nvmem binding which works without
devices. The returned data of a nvmem_cell_read() has to be freed after
use. On the other hand the return of_get_mac_address() points to some
static data without a lifetime. The trick for now, was to allocate a
device resource managed buffer which is then returned. This will only
work if we have an actual device.
Change it, so that the caller of of_get_mac_address() has to supply a
buffer where the MAC address is written to. Unfortunately, this will
touch all drivers which use the of_get_mac_address().
Usually the code looks like:
const char *addr;
addr = of_get_mac_address(np);
if (!IS_ERR(addr))
ether_addr_copy(ndev->dev_addr, addr);
This can then be simply rewritten as:
of_get_mac_address(np, ndev->dev_addr);
Sometimes is_valid_ether_addr() is used to test the MAC address.
of_get_mac_address() already makes sure, it just returns a valid MAC
address. Thus we can just test its return code. But we have to be
careful if there are still other sources for the MAC address before the
of_get_mac_address(). In this case we have to keep the
is_valid_ether_addr() call.
The following coccinelle patch was used to convert common cases to the
new style. Afterwards, I've manually gone over the drivers and fixed the
return code variable: either used a new one or if one was already
available use that. Mansour Moufid, thanks for that coccinelle patch!
<spml>
@a@
identifier x;
expression y, z;
@@
- x = of_get_mac_address(y);
+ x = of_get_mac_address(y, z);
<...
- ether_addr_copy(z, x);
...>
@@
identifier a.x;
@@
- if (<+... x ...+>) {}
@@
identifier a.x;
@@
if (<+... x ...+>) {
...
}
- else {}
@@
identifier a.x;
expression e;
@@
- if (<+... x ...+>@e)
- {}
- else
+ if (!(e))
{...}
@@
expression x, y, z;
@@
- x = of_get_mac_address(y, z);
+ of_get_mac_address(y, z);
... when != x
</spml>
All drivers, except drivers/net/ethernet/aeroflex/greth.c, were
compile-time tested.
Suggested-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: Michael Walle <michael@walle.cc>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: David S. Miller <davem@davemloft.net>
2021-04-12 17:47:17 +00:00
|
|
|
of_get_mac_address(pdev->dev.of_node, netdev->dev_addr);
|
2015-09-09 09:24:29 +00:00
|
|
|
priv->phy_id = -1;
|
2009-03-27 07:12:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Check that the given MAC address is valid. If it isn't, read the
|
2013-01-27 18:44:36 +00:00
|
|
|
* current MAC from the controller.
|
|
|
|
*/
|
2009-03-27 07:12:24 +00:00
|
|
|
if (!is_valid_ether_addr(netdev->dev_addr))
|
|
|
|
ethoc_get_mac_address(netdev, netdev->dev_addr);
|
|
|
|
|
|
|
|
/* Check the MAC again for validity, if it still isn't choose and
|
2013-01-27 18:44:36 +00:00
|
|
|
* program a random one.
|
|
|
|
*/
|
2017-02-16 12:54:32 +00:00
|
|
|
if (!is_valid_ether_addr(netdev->dev_addr))
|
|
|
|
eth_hw_addr_random(netdev);
|
2012-02-17 05:43:29 +00:00
|
|
|
|
2013-01-06 03:25:45 +00:00
|
|
|
ethoc_do_set_mac_address(netdev);
|
2009-03-27 07:12:24 +00:00
|
|
|
|
2014-02-03 23:33:10 +00:00
|
|
|
/* Allow the platform setup code to adjust MII management bus clock. */
|
|
|
|
if (!eth_clkfreq) {
|
|
|
|
struct clk *clk = devm_clk_get(&pdev->dev, NULL);
|
|
|
|
|
|
|
|
if (!IS_ERR(clk)) {
|
|
|
|
priv->clk = clk;
|
|
|
|
clk_prepare_enable(clk);
|
|
|
|
eth_clkfreq = clk_get_rate(clk);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (eth_clkfreq) {
|
|
|
|
u32 clkdiv = MIIMODER_CLKDIV(eth_clkfreq / 2500000 + 1);
|
|
|
|
|
|
|
|
if (!clkdiv)
|
|
|
|
clkdiv = 2;
|
|
|
|
dev_dbg(&pdev->dev, "setting MII clkdiv to %u\n", clkdiv);
|
|
|
|
ethoc_write(priv, MIIMODER,
|
|
|
|
(ethoc_read(priv, MIIMODER) & MIIMODER_NOPRE) |
|
|
|
|
clkdiv);
|
|
|
|
}
|
|
|
|
|
2009-03-27 07:12:24 +00:00
|
|
|
/* register MII bus */
|
|
|
|
priv->mdio = mdiobus_alloc();
|
|
|
|
if (!priv->mdio) {
|
|
|
|
ret = -ENOMEM;
|
2016-06-01 13:16:50 +00:00
|
|
|
goto free2;
|
2009-03-27 07:12:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
priv->mdio->name = "ethoc-mdio";
|
|
|
|
snprintf(priv->mdio->id, MII_BUS_ID_SIZE, "%s-%d",
|
|
|
|
priv->mdio->name, pdev->id);
|
|
|
|
priv->mdio->read = ethoc_mdio_read;
|
|
|
|
priv->mdio->write = ethoc_mdio_write;
|
|
|
|
priv->mdio->priv = priv;
|
|
|
|
|
|
|
|
ret = mdiobus_register(priv->mdio);
|
|
|
|
if (ret) {
|
|
|
|
dev_err(&netdev->dev, "failed to register MDIO bus\n");
|
2020-12-23 11:06:12 +00:00
|
|
|
goto free3;
|
2009-03-27 07:12:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = ethoc_mdio_probe(netdev);
|
|
|
|
if (ret) {
|
|
|
|
dev_err(&netdev->dev, "failed to probe MDIO bus\n");
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* setup the net_device structure */
|
|
|
|
netdev->netdev_ops = ðoc_netdev_ops;
|
|
|
|
netdev->watchdog_timeo = ETHOC_TIMEOUT;
|
|
|
|
netdev->features |= 0;
|
2014-01-31 05:41:04 +00:00
|
|
|
netdev->ethtool_ops = ðoc_ethtool_ops;
|
2009-03-27 07:12:24 +00:00
|
|
|
|
|
|
|
/* setup NAPI */
|
|
|
|
netif_napi_add(netdev, &priv->napi, ethoc_poll, 64);
|
|
|
|
|
|
|
|
spin_lock_init(&priv->lock);
|
|
|
|
|
|
|
|
ret = register_netdev(netdev);
|
|
|
|
if (ret < 0) {
|
|
|
|
dev_err(&netdev->dev, "failed to register interface\n");
|
2010-05-23 16:44:02 +00:00
|
|
|
goto error2;
|
2009-03-27 07:12:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
goto out;
|
|
|
|
|
2010-05-23 16:44:02 +00:00
|
|
|
error2:
|
|
|
|
netif_napi_del(&priv->napi);
|
2009-03-27 07:12:24 +00:00
|
|
|
error:
|
|
|
|
mdiobus_unregister(priv->mdio);
|
2020-12-23 11:06:12 +00:00
|
|
|
free3:
|
2009-03-27 07:12:24 +00:00
|
|
|
mdiobus_free(priv->mdio);
|
2016-06-01 13:16:50 +00:00
|
|
|
free2:
|
2018-05-16 11:18:22 +00:00
|
|
|
clk_disable_unprepare(priv->clk);
|
2016-06-01 13:16:50 +00:00
|
|
|
free:
|
2009-03-27 07:12:24 +00:00
|
|
|
free_netdev(netdev);
|
|
|
|
out:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-07-10 10:56:00 +00:00
|
|
|
* ethoc_remove - shutdown OpenCores ethernet MAC
|
2009-03-27 07:12:24 +00:00
|
|
|
* @pdev: platform device
|
|
|
|
*/
|
2012-12-03 14:24:09 +00:00
|
|
|
static int ethoc_remove(struct platform_device *pdev)
|
2009-03-27 07:12:24 +00:00
|
|
|
{
|
|
|
|
struct net_device *netdev = platform_get_drvdata(pdev);
|
|
|
|
struct ethoc *priv = netdev_priv(netdev);
|
|
|
|
|
|
|
|
if (netdev) {
|
2010-05-23 16:44:02 +00:00
|
|
|
netif_napi_del(&priv->napi);
|
2016-07-15 07:59:11 +00:00
|
|
|
phy_disconnect(netdev->phydev);
|
2009-03-27 07:12:24 +00:00
|
|
|
|
|
|
|
if (priv->mdio) {
|
|
|
|
mdiobus_unregister(priv->mdio);
|
|
|
|
mdiobus_free(priv->mdio);
|
|
|
|
}
|
2018-05-16 11:18:22 +00:00
|
|
|
clk_disable_unprepare(priv->clk);
|
2009-03-27 07:12:24 +00:00
|
|
|
unregister_netdev(netdev);
|
|
|
|
free_netdev(netdev);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_PM
|
|
|
|
static int ethoc_suspend(struct platform_device *pdev, pm_message_t state)
|
|
|
|
{
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ethoc_resume(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
# define ethoc_suspend NULL
|
|
|
|
# define ethoc_resume NULL
|
|
|
|
#endif
|
|
|
|
|
2015-03-17 18:37:35 +00:00
|
|
|
static const struct of_device_id ethoc_match[] = {
|
2011-01-21 16:24:48 +00:00
|
|
|
{ .compatible = "opencores,ethoc", },
|
2010-11-25 02:30:25 +00:00
|
|
|
{},
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(of, ethoc_match);
|
|
|
|
|
2009-03-27 07:12:24 +00:00
|
|
|
static struct platform_driver ethoc_driver = {
|
|
|
|
.probe = ethoc_probe,
|
2012-12-03 14:24:09 +00:00
|
|
|
.remove = ethoc_remove,
|
2009-03-27 07:12:24 +00:00
|
|
|
.suspend = ethoc_suspend,
|
|
|
|
.resume = ethoc_resume,
|
|
|
|
.driver = {
|
|
|
|
.name = "ethoc",
|
2010-11-25 02:30:25 +00:00
|
|
|
.of_match_table = ethoc_match,
|
2009-03-27 07:12:24 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2011-11-27 16:44:17 +00:00
|
|
|
module_platform_driver(ethoc_driver);
|
2009-03-27 07:12:24 +00:00
|
|
|
|
|
|
|
MODULE_AUTHOR("Thierry Reding <thierry.reding@avionic-design.de>");
|
|
|
|
MODULE_DESCRIPTION("OpenCores Ethernet MAC driver");
|
|
|
|
MODULE_LICENSE("GPL v2");
|
|
|
|
|