Commit 53c0ec4f authored by Armin Wolf's avatar Armin Wolf Committed by David S. Miller

ne2k-pci: Fix various coding-style issues and improve printk() usage

Fixed a ton of minor checkpatch errors/warnings and remove version
printing at module init/when device is found and use MODULE_VERSION
instead. Also modifying the RTL8029 PCI string to include the compatible
RTL8029AS nic.
The only mayor issue remaining is the missing SPDX tag, but since the
exact version of the GPL is not stated anywhere inside the file, its
impossible to add such a tag at the moment.
But maybe it is possible, since 8390.h states Donald Becker's 8390
drivers are licensed under GPL 2.2 only (= GPL-2.0-only ?).
The kernel module containing this patch compiles and runs without
problems on a RTL8029AS-based NE2000 clone card with kernel 5.7.0-rc6.
Signed-off-by: default avatarArmin Wolf <W_Armin@gmx.de>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 81f3dc93
/* ne2k-pci.c: A NE2000 clone on PCI bus driver for Linux. */ /* A Linux device driver for PCI NE2000 clones.
/* *
A Linux device driver for PCI NE2000 clones. * Authors and other copyright holders:
* 1992-2000 by Donald Becker, NE2000 core and various modifications.
Authors and other copyright holders: * 1995-1998 by Paul Gortmaker, core modifications and PCI support.
1992-2000 by Donald Becker, NE2000 core and various modifications. * Copyright 1993 assigned to the United States Government as represented
1995-1998 by Paul Gortmaker, core modifications and PCI support. * by the Director, National Security Agency.
Copyright 1993 assigned to the United States Government as represented *
by the Director, National Security Agency. * This software may be used and distributed according to the terms of
* the GNU General Public License (GPL), incorporated herein by reference.
This software may be used and distributed according to the terms of * Drivers based on or derived from this code fall under the GPL and must
the GNU General Public License (GPL), incorporated herein by reference. * retain the authorship, copyright and license notice. This file is not
Drivers based on or derived from this code fall under the GPL and must * a complete program and may only be used when the entire operating
retain the authorship, copyright and license notice. This file is not * system is licensed under the GPL.
a complete program and may only be used when the entire operating *
system is licensed under the GPL. * The author may be reached as becker@scyld.com, or C/O
* Scyld Computing Corporation
The author may be reached as becker@scyld.com, or C/O * 410 Severn Ave., Suite 210
Scyld Computing Corporation * Annapolis MD 21403
410 Severn Ave., Suite 210 *
Annapolis MD 21403 * Issues remaining:
* People are making PCI NE2000 clones! Oh the horror, the horror...
Issues remaining: * Limited full-duplex support.
People are making PCI ne2000 clones! Oh the horror, the horror... */
Limited full-duplex support.
*/
#define DRV_NAME "ne2k-pci" #define DRV_NAME "ne2k-pci"
#define DRV_DESCRIPTION "PCI NE2000 clone driver"
#define DRV_AUTHOR "Donald Becker / Paul Gortmaker"
#define DRV_VERSION "1.03" #define DRV_VERSION "1.03"
#define DRV_RELDATE "9/22/2003" #define DRV_RELDATE "9/22/2003"
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
/* The user-configurable values. /* The user-configurable values.
These may be modified when a driver module is loaded.*/ * These may be modified when a driver module is loaded.
*/
/* More are supported, limit only on options */
#define MAX_UNITS 8
#define MAX_UNITS 8 /* More are supported, limit only on options */
/* Used to pass the full-duplex flag, etc. */ /* Used to pass the full-duplex flag, etc. */
static int full_duplex[MAX_UNITS]; static int full_duplex[MAX_UNITS];
static int options[MAX_UNITS]; static int options[MAX_UNITS];
...@@ -52,7 +56,7 @@ static int options[MAX_UNITS]; ...@@ -52,7 +56,7 @@ static int options[MAX_UNITS];
#include <linux/netdevice.h> #include <linux/netdevice.h>
#include <linux/etherdevice.h> #include <linux/etherdevice.h>
#include <asm/io.h> #include <linux/io.h>
#include <asm/irq.h> #include <asm/irq.h>
#include <linux/uaccess.h> #include <linux/uaccess.h>
...@@ -60,20 +64,14 @@ static int options[MAX_UNITS]; ...@@ -60,20 +64,14 @@ static int options[MAX_UNITS];
static u32 ne2k_msg_enable; static u32 ne2k_msg_enable;
/* These identify the driver base version and may not be removed. */
static const char version[] =
KERN_INFO DRV_NAME ".c:v" DRV_VERSION " " DRV_RELDATE
" D. Becker/P. Gortmaker\n";
#if defined(__powerpc__) #if defined(__powerpc__)
#define inl_le(addr) le32_to_cpu(inl(addr)) #define inl_le(addr) le32_to_cpu(inl(addr))
#define inw_le(addr) le16_to_cpu(inw(addr)) #define inw_le(addr) le16_to_cpu(inw(addr))
#endif #endif
#define PFX DRV_NAME ": " MODULE_AUTHOR(DRV_AUTHOR);
MODULE_DESCRIPTION(DRV_DESCRIPTION);
MODULE_AUTHOR("Donald Becker / Paul Gortmaker"); MODULE_VERSION(DRV_VERSION);
MODULE_DESCRIPTION("PCI NE2000 clone driver");
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
module_param_named(msg_enable, ne2k_msg_enable, uint, 0444); module_param_named(msg_enable, ne2k_msg_enable, uint, 0444);
...@@ -83,7 +81,8 @@ MODULE_PARM_DESC(msg_enable, "Debug message level (see linux/netdevice.h for bit ...@@ -83,7 +81,8 @@ MODULE_PARM_DESC(msg_enable, "Debug message level (see linux/netdevice.h for bit
MODULE_PARM_DESC(options, "Bit 5: full duplex"); MODULE_PARM_DESC(options, "Bit 5: full duplex");
MODULE_PARM_DESC(full_duplex, "full duplex setting(s) (1)"); MODULE_PARM_DESC(full_duplex, "full duplex setting(s) (1)");
/* Some defines that people can play with if so inclined. */ /* Some defines that people can play with if so inclined.
*/
/* Use 32 bit data-movement operations instead of 16 bit. */ /* Use 32 bit data-movement operations instead of 16 bit. */
#define USE_LONGIO #define USE_LONGIO
...@@ -91,14 +90,18 @@ MODULE_PARM_DESC(full_duplex, "full duplex setting(s) (1)"); ...@@ -91,14 +90,18 @@ MODULE_PARM_DESC(full_duplex, "full duplex setting(s) (1)");
/* Do we implement the read before write bugfix ? */ /* Do we implement the read before write bugfix ? */
/* #define NE_RW_BUGFIX */ /* #define NE_RW_BUGFIX */
/* Flags. We rename an existing ei_status field to store flags! */ /* Flags. We rename an existing ei_status field to store flags!
/* Thus only the low 8 bits are usable for non-init-time flags. */ * Thus only the low 8 bits are usable for non-init-time flags.
*/
#define ne2k_flags reg0 #define ne2k_flags reg0
enum { enum {
ONLY_16BIT_IO=8, ONLY_32BIT_IO=4, /* Chip can do only 16/32-bit xfers. */ /* Chip can do only 16/32-bit xfers. */
FORCE_FDX=0x20, /* User override. */ ONLY_16BIT_IO = 8, ONLY_32BIT_IO = 4,
REALTEK_FDX=0x40, HOLTEK_FDX=0x80, /* User override. */
STOP_PG_0x60=0x100, FORCE_FDX = 0x20,
REALTEK_FDX = 0x40, HOLTEK_FDX = 0x80,
STOP_PG_0x60 = 0x100,
}; };
enum ne2k_pci_chipsets { enum ne2k_pci_chipsets {
...@@ -120,7 +123,7 @@ static struct { ...@@ -120,7 +123,7 @@ static struct {
char *name; char *name;
int flags; int flags;
} pci_clone_list[] = { } pci_clone_list[] = {
{"RealTek RTL-8029", REALTEK_FDX}, {"RealTek RTL-8029(AS)", REALTEK_FDX},
{"Winbond 89C940", 0}, {"Winbond 89C940", 0},
{"Compex RL2000", 0}, {"Compex RL2000", 0},
{"KTI ET32P2", 0}, {"KTI ET32P2", 0},
...@@ -149,6 +152,7 @@ static const struct pci_device_id ne2k_pci_tbl[] = { ...@@ -149,6 +152,7 @@ static const struct pci_device_id ne2k_pci_tbl[] = {
{ 0x8c4a, 0x1980, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_Winbond_89C940_8c4a }, { 0x8c4a, 0x1980, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_Winbond_89C940_8c4a },
{ 0, } { 0, }
}; };
MODULE_DEVICE_TABLE(pci, ne2k_pci_tbl); MODULE_DEVICE_TABLE(pci, ne2k_pci_tbl);
...@@ -168,18 +172,20 @@ static int ne2k_pci_open(struct net_device *dev); ...@@ -168,18 +172,20 @@ static int ne2k_pci_open(struct net_device *dev);
static int ne2k_pci_close(struct net_device *dev); static int ne2k_pci_close(struct net_device *dev);
static void ne2k_pci_reset_8390(struct net_device *dev); static void ne2k_pci_reset_8390(struct net_device *dev);
static void ne2k_pci_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr, static void ne2k_pci_get_8390_hdr(struct net_device *dev,
int ring_page); struct e8390_pkt_hdr *hdr, int ring_page);
static void ne2k_pci_block_input(struct net_device *dev, int count, static void ne2k_pci_block_input(struct net_device *dev, int count,
struct sk_buff *skb, int ring_offset); struct sk_buff *skb, int ring_offset);
static void ne2k_pci_block_output(struct net_device *dev, const int count, static void ne2k_pci_block_output(struct net_device *dev, const int count,
const unsigned char *buf, const int start_page); const unsigned char *buf,
const int start_page);
static const struct ethtool_ops ne2k_pci_ethtool_ops; static const struct ethtool_ops ne2k_pci_ethtool_ops;
/* There is no room in the standard 8390 structure for extra info we need, /* There is no room in the standard 8390 structure for extra info we need,
so we build a meta/outer-wrapper structure.. */ * so we build a meta/outer-wrapper structure..
*/
struct ne2k_pci_card { struct ne2k_pci_card {
struct net_device *dev; struct net_device *dev;
struct pci_dev *pci_dev; struct pci_dev *pci_dev;
...@@ -187,18 +193,17 @@ struct ne2k_pci_card { ...@@ -187,18 +193,17 @@ struct ne2k_pci_card {
/* /* NEx000-clone boards have a Station Address (SA) PROM (SAPROM) in the packet
NEx000-clone boards have a Station Address (SA) PROM (SAPROM) in the packet * buffer memory space. By-the-spec NE2000 clones have 0x57,0x57 in bytes
buffer memory space. By-the-spec NE2000 clones have 0x57,0x57 in bytes * 0x0e,0x0f of the SAPROM, while other supposed NE2000 clones must be
0x0e,0x0f of the SAPROM, while other supposed NE2000 clones must be * detected by their SA prefix.
detected by their SA prefix. *
* Reading the SAPROM from a word-wide card with the 8390 set in byte-wide
Reading the SAPROM from a word-wide card with the 8390 set in byte-wide * mode results in doubled values, which can be detected and compensated for.
mode results in doubled values, which can be detected and compensated for. *
* The probe is also responsible for initializing the card and filling
The probe is also responsible for initializing the card and filling * in the 'dev' and 'ei_status' structures.
in the 'dev' and 'ei_status' structures. */
*/
static const struct net_device_ops ne2k_netdev_ops = { static const struct net_device_ops ne2k_netdev_ops = {
.ndo_open = ne2k_pci_open, .ndo_open = ne2k_pci_open,
...@@ -227,28 +232,21 @@ static int ne2k_pci_init_one(struct pci_dev *pdev, ...@@ -227,28 +232,21 @@ static int ne2k_pci_init_one(struct pci_dev *pdev,
int flags = pci_clone_list[chip_idx].flags; int flags = pci_clone_list[chip_idx].flags;
struct ei_device *ei_local; struct ei_device *ei_local;
/* when built into the kernel, we only print version if device is found */
#ifndef MODULE
static int printed_version;
if (!printed_version++)
printk(version);
#endif
fnd_cnt++; fnd_cnt++;
i = pci_enable_device (pdev); i = pci_enable_device(pdev);
if (i) if (i)
return i; return i;
ioaddr = pci_resource_start (pdev, 0); ioaddr = pci_resource_start(pdev, 0);
irq = pdev->irq; irq = pdev->irq;
if (!ioaddr || ((pci_resource_flags (pdev, 0) & IORESOURCE_IO) == 0)) { if (!ioaddr || ((pci_resource_flags(pdev, 0) & IORESOURCE_IO) == 0)) {
dev_err(&pdev->dev, "no I/O resource at PCI BAR #0\n"); dev_err(&pdev->dev, "no I/O resource at PCI BAR #0\n");
goto err_out; goto err_out;
} }
if (request_region (ioaddr, NE_IO_EXTENT, DRV_NAME) == NULL) { if (!request_region(ioaddr, NE_IO_EXTENT, DRV_NAME)) {
dev_err(&pdev->dev, "I/O resource 0x%x @ 0x%lx busy\n", dev_err(&pdev->dev, "I/O resource 0x%x @ 0x%lx busy\n",
NE_IO_EXTENT, ioaddr); NE_IO_EXTENT, ioaddr);
goto err_out; goto err_out;
...@@ -261,14 +259,17 @@ static int ne2k_pci_init_one(struct pci_dev *pdev, ...@@ -261,14 +259,17 @@ static int ne2k_pci_init_one(struct pci_dev *pdev,
/* Do a preliminary verification that we have a 8390. */ /* Do a preliminary verification that we have a 8390. */
{ {
int regd; int regd;
outb(E8390_NODMA+E8390_PAGE1+E8390_STOP, ioaddr + E8390_CMD);
outb(E8390_NODMA + E8390_PAGE1 + E8390_STOP, ioaddr + E8390_CMD);
regd = inb(ioaddr + 0x0d); regd = inb(ioaddr + 0x0d);
outb(0xff, ioaddr + 0x0d); outb(0xff, ioaddr + 0x0d);
outb(E8390_NODMA+E8390_PAGE0, ioaddr + E8390_CMD); outb(E8390_NODMA + E8390_PAGE0, ioaddr + E8390_CMD);
inb(ioaddr + EN0_COUNTER0); /* Clear the counter by reading. */ /* Clear the counter by reading. */
inb(ioaddr + EN0_COUNTER0);
if (inb(ioaddr + EN0_COUNTER0) != 0) { if (inb(ioaddr + EN0_COUNTER0) != 0) {
outb(reg0, ioaddr); outb(reg0, ioaddr);
outb(regd, ioaddr + 0x0d); /* Restore the old values. */ /* Restore the old values. */
outb(regd, ioaddr + 0x0d);
goto err_out_free_res; goto err_out_free_res;
} }
} }
...@@ -291,8 +292,8 @@ static int ne2k_pci_init_one(struct pci_dev *pdev, ...@@ -291,8 +292,8 @@ static int ne2k_pci_init_one(struct pci_dev *pdev,
outb(inb(ioaddr + NE_RESET), ioaddr + NE_RESET); outb(inb(ioaddr + NE_RESET), ioaddr + NE_RESET);
/* This looks like a horrible timing loop, but it should never take /* This looks like a horrible timing loop, but it should never
more than a few cycles. * take more than a few cycles.
*/ */
while ((inb(ioaddr + EN0_ISR) & ENISR_RESET) == 0) while ((inb(ioaddr + EN0_ISR) & ENISR_RESET) == 0)
/* Limit wait: '2' avoids jiffy roll-over. */ /* Limit wait: '2' avoids jiffy roll-over. */
...@@ -301,42 +302,53 @@ static int ne2k_pci_init_one(struct pci_dev *pdev, ...@@ -301,42 +302,53 @@ static int ne2k_pci_init_one(struct pci_dev *pdev,
"Card failure (no reset ack).\n"); "Card failure (no reset ack).\n");
goto err_out_free_netdev; goto err_out_free_netdev;
} }
/* Ack all intr. */
outb(0xff, ioaddr + EN0_ISR); /* Ack all intr. */ outb(0xff, ioaddr + EN0_ISR);
} }
/* Read the 16 bytes of station address PROM. /* Read the 16 bytes of station address PROM.
We must first initialize registers, similar to NS8390_init(eifdev, 0). * We must first initialize registers, similar
We can't reliably read the SAPROM address without this. * to NS8390_init(eifdev, 0).
(I learned the hard way!). */ * We can't reliably read the SAPROM address without this.
* (I learned the hard way!).
*/
{ {
struct {unsigned char value, offset; } program_seq[] = { struct {unsigned char value, offset; } program_seq[] = {
{E8390_NODMA+E8390_PAGE0+E8390_STOP, E8390_CMD}, /* Select page 0*/ /* Select page 0 */
{0x49, EN0_DCFG}, /* Set word-wide access. */ {E8390_NODMA + E8390_PAGE0 + E8390_STOP, E8390_CMD},
{0x00, EN0_RCNTLO}, /* Clear the count regs. */ /* Set word-wide access */
{0x49, EN0_DCFG},
/* Clear the count regs. */
{0x00, EN0_RCNTLO},
/* Mask completion IRQ */
{0x00, EN0_RCNTHI}, {0x00, EN0_RCNTHI},
{0x00, EN0_IMR}, /* Mask completion irq. */ {0x00, EN0_IMR},
{0xFF, EN0_ISR}, {0xFF, EN0_ISR},
{E8390_RXOFF, EN0_RXCR}, /* 0x20 Set to monitor */ /* 0x20 Set to monitor */
{E8390_TXOFF, EN0_TXCR}, /* 0x02 and loopback mode. */ {E8390_RXOFF, EN0_RXCR},
/* 0x02 and loopback mode */
{E8390_TXOFF, EN0_TXCR},
{32, EN0_RCNTLO}, {32, EN0_RCNTLO},
{0x00, EN0_RCNTHI}, {0x00, EN0_RCNTHI},
{0x00, EN0_RSARLO}, /* DMA starting at 0x0000. */ /* DMA starting at 0x0000 */
{0x00, EN0_RSARLO},
{0x00, EN0_RSARHI}, {0x00, EN0_RSARHI},
{E8390_RREAD+E8390_START, E8390_CMD}, {E8390_RREAD+E8390_START, E8390_CMD},
}; };
for (i = 0; i < ARRAY_SIZE(program_seq); i++) for (i = 0; i < ARRAY_SIZE(program_seq); i++)
outb(program_seq[i].value, ioaddr + program_seq[i].offset); outb(program_seq[i].value,
ioaddr + program_seq[i].offset);
} }
/* Note: all PCI cards have at least 16 bit access, so we don't have /* Note: all PCI cards have at least 16 bit access, so we don't have
to check for 8 bit cards. Most cards permit 32 bit access. */ * to check for 8 bit cards. Most cards permit 32 bit access.
*/
if (flags & ONLY_32BIT_IO) { if (flags & ONLY_32BIT_IO) {
for (i = 0; i < 4 ; i++) for (i = 0; i < 4 ; i++)
((u32 *)SA_prom)[i] = le32_to_cpu(inl(ioaddr + NE_DATAPORT)); ((u32 *)SA_prom)[i] = le32_to_cpu(inl(ioaddr + NE_DATAPORT));
} else } else
for(i = 0; i < 32 /*sizeof(SA_prom)*/; i++) for (i = 0; i < 32 /* sizeof(SA_prom )*/; i++)
SA_prom[i] = inb(ioaddr + NE_DATAPORT); SA_prom[i] = inb(ioaddr + NE_DATAPORT);
/* We always set the 8390 registers for word mode. */ /* We always set the 8390 registers for word mode. */
...@@ -388,16 +400,15 @@ static int ne2k_pci_init_one(struct pci_dev *pdev, ...@@ -388,16 +400,15 @@ static int ne2k_pci_init_one(struct pci_dev *pdev,
return 0; return 0;
err_out_free_netdev: err_out_free_netdev:
free_netdev (dev); free_netdev(dev);
err_out_free_res: err_out_free_res:
release_region (ioaddr, NE_IO_EXTENT); release_region(ioaddr, NE_IO_EXTENT);
err_out: err_out:
pci_disable_device(pdev); pci_disable_device(pdev);
return -ENODEV; return -ENODEV;
} }
/* /* Magic incantation sequence for full duplex on the supported cards.
* Magic incantation sequence for full duplex on the supported cards.
*/ */
static inline int set_realtek_fdx(struct net_device *dev) static inline int set_realtek_fdx(struct net_device *dev)
{ {
...@@ -431,7 +442,9 @@ static int ne2k_pci_set_fdx(struct net_device *dev) ...@@ -431,7 +442,9 @@ static int ne2k_pci_set_fdx(struct net_device *dev)
static int ne2k_pci_open(struct net_device *dev) static int ne2k_pci_open(struct net_device *dev)
{ {
int ret = request_irq(dev->irq, ei_interrupt, IRQF_SHARED, dev->name, dev); int ret = request_irq(dev->irq, ei_interrupt, IRQF_SHARED,
dev->name, dev);
if (ret) if (ret)
return ret; return ret;
...@@ -450,7 +463,8 @@ static int ne2k_pci_close(struct net_device *dev) ...@@ -450,7 +463,8 @@ static int ne2k_pci_close(struct net_device *dev)
} }
/* Hard reset the card. This used to pause for the same period that a /* Hard reset the card. This used to pause for the same period that a
8390 reset command required, but that shouldn't be necessary. */ * 8390 reset command required, but that shouldn't be necessary.
*/
static void ne2k_pci_reset_8390(struct net_device *dev) static void ne2k_pci_reset_8390(struct net_device *dev)
{ {
unsigned long reset_start_time = jiffies; unsigned long reset_start_time = jiffies;
...@@ -467,31 +481,34 @@ static void ne2k_pci_reset_8390(struct net_device *dev) ...@@ -467,31 +481,34 @@ static void ne2k_pci_reset_8390(struct net_device *dev)
/* This check _should_not_ be necessary, omit eventually. */ /* This check _should_not_ be necessary, omit eventually. */
while ((inb(NE_BASE+EN0_ISR) & ENISR_RESET) == 0) while ((inb(NE_BASE+EN0_ISR) & ENISR_RESET) == 0)
if (jiffies - reset_start_time > 2) { if (jiffies - reset_start_time > 2) {
netdev_err(dev, "ne2k_pci_reset_8390() did not complete.\n"); netdev_err(dev, "%s did not complete.\n", __func__);
break; break;
} }
outb(ENISR_RESET, NE_BASE + EN0_ISR); /* Ack intr. */ /* Ack intr. */
outb(ENISR_RESET, NE_BASE + EN0_ISR);
} }
/* Grab the 8390 specific header. Similar to the block_input routine, but /* Grab the 8390 specific header. Similar to the block_input routine, but
we don't need to be concerned with ring wrap as the header will be at * we don't need to be concerned with ring wrap as the header will be at
the start of a page, so we optimize accordingly. */ * the start of a page, so we optimize accordingly.
*/
static void ne2k_pci_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr, int ring_page) static void ne2k_pci_get_8390_hdr(struct net_device *dev,
struct e8390_pkt_hdr *hdr, int ring_page)
{ {
long nic_base = dev->base_addr; long nic_base = dev->base_addr;
/* This *shouldn't* happen. If it does, it's the last thing you'll see */ /* This *shouldn't* happen. If it does, it's the last thing you'll see
*/
if (ei_status.dmaing) { if (ei_status.dmaing) {
netdev_err(dev, "DMAing conflict in ne2k_pci_get_8390_hdr " netdev_err(dev, "DMAing conflict in %s [DMAstat:%d][irqlock:%d].\n",
"[DMAstat:%d][irqlock:%d].\n", __func__, ei_status.dmaing, ei_status.irqlock);
ei_status.dmaing, ei_status.irqlock);
return; return;
} }
ei_status.dmaing |= 0x01; ei_status.dmaing |= 0x01;
outb(E8390_NODMA+E8390_PAGE0+E8390_START, nic_base+ NE_CMD); outb(E8390_NODMA + E8390_PAGE0 + E8390_START, nic_base + NE_CMD);
outb(sizeof(struct e8390_pkt_hdr), nic_base + EN0_RCNTLO); outb(sizeof(struct e8390_pkt_hdr), nic_base + EN0_RCNTLO);
outb(0, nic_base + EN0_RCNTHI); outb(0, nic_base + EN0_RCNTHI);
outb(0, nic_base + EN0_RSARLO); /* On page boundary */ outb(0, nic_base + EN0_RSARLO); /* On page boundary */
...@@ -499,20 +516,22 @@ static void ne2k_pci_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr * ...@@ -499,20 +516,22 @@ static void ne2k_pci_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *
outb(E8390_RREAD+E8390_START, nic_base + NE_CMD); outb(E8390_RREAD+E8390_START, nic_base + NE_CMD);
if (ei_status.ne2k_flags & ONLY_16BIT_IO) { if (ei_status.ne2k_flags & ONLY_16BIT_IO) {
insw(NE_BASE + NE_DATAPORT, hdr, sizeof(struct e8390_pkt_hdr)>>1); insw(NE_BASE + NE_DATAPORT, hdr,
sizeof(struct e8390_pkt_hdr) >> 1);
} else { } else {
*(u32*)hdr = le32_to_cpu(inl(NE_BASE + NE_DATAPORT)); *(u32 *)hdr = le32_to_cpu(inl(NE_BASE + NE_DATAPORT));
le16_to_cpus(&hdr->count); le16_to_cpus(&hdr->count);
} }
/* Ack intr. */
outb(ENISR_RDC, nic_base + EN0_ISR); /* Ack intr. */ outb(ENISR_RDC, nic_base + EN0_ISR);
ei_status.dmaing &= ~0x01; ei_status.dmaing &= ~0x01;
} }
/* Block input and output, similar to the Crynwr packet driver. If you /* Block input and output, similar to the Crynwr packet driver. If you
are porting to a new ethercard, look at the packet driver source for hints. *are porting to a new ethercard, look at the packet driver source for hints.
The NEx000 doesn't share the on-board packet memory -- you have to put *The NEx000 doesn't share the on-board packet memory -- you have to put
the packet out through the "remote DMA" dataport using outb. */ *the packet out through the "remote DMA" dataport using outb.
*/
static void ne2k_pci_block_input(struct net_device *dev, int count, static void ne2k_pci_block_input(struct net_device *dev, int count,
struct sk_buff *skb, int ring_offset) struct sk_buff *skb, int ring_offset)
...@@ -520,30 +539,30 @@ static void ne2k_pci_block_input(struct net_device *dev, int count, ...@@ -520,30 +539,30 @@ static void ne2k_pci_block_input(struct net_device *dev, int count,
long nic_base = dev->base_addr; long nic_base = dev->base_addr;
char *buf = skb->data; char *buf = skb->data;
/* This *shouldn't* happen. If it does, it's the last thing you'll see */ /* This *shouldn't* happen.
* If it does, it's the last thing you'll see.
*/
if (ei_status.dmaing) { if (ei_status.dmaing) {
netdev_err(dev, "DMAing conflict in ne2k_pci_block_input " netdev_err(dev, "DMAing conflict in %s [DMAstat:%d][irqlock:%d]\n",
"[DMAstat:%d][irqlock:%d].\n", __func__, ei_status.dmaing, ei_status.irqlock);
ei_status.dmaing, ei_status.irqlock);
return; return;
} }
ei_status.dmaing |= 0x01; ei_status.dmaing |= 0x01;
if (ei_status.ne2k_flags & ONLY_32BIT_IO) if (ei_status.ne2k_flags & ONLY_32BIT_IO)
count = (count + 3) & 0xFFFC; count = (count + 3) & 0xFFFC;
outb(E8390_NODMA+E8390_PAGE0+E8390_START, nic_base+ NE_CMD); outb(E8390_NODMA + E8390_PAGE0 + E8390_START, nic_base + NE_CMD);
outb(count & 0xff, nic_base + EN0_RCNTLO); outb(count & 0xff, nic_base + EN0_RCNTLO);
outb(count >> 8, nic_base + EN0_RCNTHI); outb(count >> 8, nic_base + EN0_RCNTHI);
outb(ring_offset & 0xff, nic_base + EN0_RSARLO); outb(ring_offset & 0xff, nic_base + EN0_RSARLO);
outb(ring_offset >> 8, nic_base + EN0_RSARHI); outb(ring_offset >> 8, nic_base + EN0_RSARHI);
outb(E8390_RREAD+E8390_START, nic_base + NE_CMD); outb(E8390_RREAD + E8390_START, nic_base + NE_CMD);
if (ei_status.ne2k_flags & ONLY_16BIT_IO) { if (ei_status.ne2k_flags & ONLY_16BIT_IO) {
insw(NE_BASE + NE_DATAPORT,buf,count>>1); insw(NE_BASE + NE_DATAPORT, buf, count >> 1);
if (count & 0x01) { if (count & 0x01)
buf[count-1] = inb(NE_BASE + NE_DATAPORT); buf[count-1] = inb(NE_BASE + NE_DATAPORT);
}
} else { } else {
insl(NE_BASE + NE_DATAPORT, buf, count>>2); insl(NE_BASE + NE_DATAPORT, buf, count >> 2);
if (count & 3) { if (count & 3) {
buf += count & ~3; buf += count & ~3;
if (count & 2) { if (count & 2) {
...@@ -556,8 +575,8 @@ static void ne2k_pci_block_input(struct net_device *dev, int count, ...@@ -556,8 +575,8 @@ static void ne2k_pci_block_input(struct net_device *dev, int count,
*buf = inb(NE_BASE + NE_DATAPORT); *buf = inb(NE_BASE + NE_DATAPORT);
} }
} }
/* Ack intr. */
outb(ENISR_RDC, nic_base + EN0_ISR); /* Ack intr. */ outb(ENISR_RDC, nic_base + EN0_ISR);
ei_status.dmaing &= ~0x01; ei_status.dmaing &= ~0x01;
} }
...@@ -568,18 +587,20 @@ static void ne2k_pci_block_output(struct net_device *dev, int count, ...@@ -568,18 +587,20 @@ static void ne2k_pci_block_output(struct net_device *dev, int count,
unsigned long dma_start; unsigned long dma_start;
/* On little-endian it's always safe to round the count up for /* On little-endian it's always safe to round the count up for
word writes. */ * word writes.
*/
if (ei_status.ne2k_flags & ONLY_32BIT_IO) if (ei_status.ne2k_flags & ONLY_32BIT_IO)
count = (count + 3) & 0xFFFC; count = (count + 3) & 0xFFFC;
else else
if (count & 0x01) if (count & 0x01)
count++; count++;
/* This *shouldn't* happen. If it does, it's the last thing you'll see */ /* This *shouldn't* happen.
* If it does, it's the last thing you'll see.
*/
if (ei_status.dmaing) { if (ei_status.dmaing) {
netdev_err(dev, "DMAing conflict in ne2k_pci_block_output." netdev_err(dev, "DMAing conflict in %s [DMAstat:%d][irqlock:%d]\n",
"[DMAstat:%d][irqlock:%d]\n", __func__, ei_status.dmaing, ei_status.irqlock);
ei_status.dmaing, ei_status.irqlock);
return; return;
} }
ei_status.dmaing |= 0x01; ei_status.dmaing |= 0x01;
...@@ -588,9 +609,10 @@ static void ne2k_pci_block_output(struct net_device *dev, int count, ...@@ -588,9 +609,10 @@ static void ne2k_pci_block_output(struct net_device *dev, int count,
#ifdef NE8390_RW_BUGFIX #ifdef NE8390_RW_BUGFIX
/* Handle the read-before-write bug the same way as the /* Handle the read-before-write bug the same way as the
Crynwr packet driver -- the NatSemi method doesn't work. * Crynwr packet driver -- the NatSemi method doesn't work.
Actually this doesn't always work either, but if you have * Actually this doesn't always work either, but if you have
problems with your NEx000 this is better than nothing! */ * problems with your NEx000 this is better than nothing!
*/
outb(0x42, nic_base + EN0_RCNTLO); outb(0x42, nic_base + EN0_RCNTLO);
outb(0x00, nic_base + EN0_RCNTHI); outb(0x00, nic_base + EN0_RCNTHI);
outb(0x42, nic_base + EN0_RSARLO); outb(0x42, nic_base + EN0_RSARLO);
...@@ -606,9 +628,9 @@ static void ne2k_pci_block_output(struct net_device *dev, int count, ...@@ -606,9 +628,9 @@ static void ne2k_pci_block_output(struct net_device *dev, int count,
outb(start_page, nic_base + EN0_RSARHI); outb(start_page, nic_base + EN0_RSARHI);
outb(E8390_RWRITE+E8390_START, nic_base + NE_CMD); outb(E8390_RWRITE+E8390_START, nic_base + NE_CMD);
if (ei_status.ne2k_flags & ONLY_16BIT_IO) { if (ei_status.ne2k_flags & ONLY_16BIT_IO) {
outsw(NE_BASE + NE_DATAPORT, buf, count>>1); outsw(NE_BASE + NE_DATAPORT, buf, count >> 1);
} else { } else {
outsl(NE_BASE + NE_DATAPORT, buf, count>>2); outsl(NE_BASE + NE_DATAPORT, buf, count >> 2);
if (count & 3) { if (count & 3) {
buf += count & ~3; buf += count & ~3;
if (count & 2) { if (count & 2) {
...@@ -623,14 +645,15 @@ static void ne2k_pci_block_output(struct net_device *dev, int count, ...@@ -623,14 +645,15 @@ static void ne2k_pci_block_output(struct net_device *dev, int count,
dma_start = jiffies; dma_start = jiffies;
while ((inb(nic_base + EN0_ISR) & ENISR_RDC) == 0) while ((inb(nic_base + EN0_ISR) & ENISR_RDC) == 0)
if (jiffies - dma_start > 2) { /* Avoid clock roll-over. */ /* Avoid clock roll-over. */
if (jiffies - dma_start > 2) {
netdev_warn(dev, "timeout waiting for Tx RDC.\n"); netdev_warn(dev, "timeout waiting for Tx RDC.\n");
ne2k_pci_reset_8390(dev); ne2k_pci_reset_8390(dev);
NS8390_init(dev,1); NS8390_init(dev, 1);
break; break;
} }
/* Ack intr. */
outb(ENISR_RDC, nic_base + EN0_ISR); /* Ack intr. */ outb(ENISR_RDC, nic_base + EN0_ISR);
ei_status.dmaing &= ~0x01; ei_status.dmaing &= ~0x01;
} }
...@@ -640,9 +663,9 @@ static void ne2k_pci_get_drvinfo(struct net_device *dev, ...@@ -640,9 +663,9 @@ static void ne2k_pci_get_drvinfo(struct net_device *dev,
struct ei_device *ei = netdev_priv(dev); struct ei_device *ei = netdev_priv(dev);
struct pci_dev *pci_dev = (struct pci_dev *) ei->priv; struct pci_dev *pci_dev = (struct pci_dev *) ei->priv;
strlcpy(info->driver, DRV_NAME, sizeof(info->driver)); strscpy(info->driver, DRV_NAME, sizeof(info->driver));
strlcpy(info->version, DRV_VERSION, sizeof(info->version)); strscpy(info->version, DRV_VERSION, sizeof(info->version));
strlcpy(info->bus_info, pci_name(pci_dev), sizeof(info->bus_info)); strscpy(info->bus_info, pci_name(pci_dev), sizeof(info->bus_info));
} }
static u32 ne2k_pci_get_msglevel(struct net_device *dev) static u32 ne2k_pci_get_msglevel(struct net_device *dev)
...@@ -677,9 +700,9 @@ static void ne2k_pci_remove_one(struct pci_dev *pdev) ...@@ -677,9 +700,9 @@ static void ne2k_pci_remove_one(struct pci_dev *pdev)
} }
#ifdef CONFIG_PM #ifdef CONFIG_PM
static int ne2k_pci_suspend (struct pci_dev *pdev, pm_message_t state) static int ne2k_pci_suspend(struct pci_dev *pdev, pm_message_t state)
{ {
struct net_device *dev = pci_get_drvdata (pdev); struct net_device *dev = pci_get_drvdata(pdev);
netif_device_detach(dev); netif_device_detach(dev);
pci_save_state(pdev); pci_save_state(pdev);
...@@ -689,9 +712,9 @@ static int ne2k_pci_suspend (struct pci_dev *pdev, pm_message_t state) ...@@ -689,9 +712,9 @@ static int ne2k_pci_suspend (struct pci_dev *pdev, pm_message_t state)
return 0; return 0;
} }
static int ne2k_pci_resume (struct pci_dev *pdev) static int ne2k_pci_resume(struct pci_dev *pdev)
{ {
struct net_device *dev = pci_get_drvdata (pdev); struct net_device *dev = pci_get_drvdata(pdev);
int rc; int rc;
pci_set_power_state(pdev, PCI_D0); pci_set_power_state(pdev, PCI_D0);
...@@ -718,24 +741,20 @@ static struct pci_driver ne2k_driver = { ...@@ -718,24 +741,20 @@ static struct pci_driver ne2k_driver = {
#ifdef CONFIG_PM #ifdef CONFIG_PM
.suspend = ne2k_pci_suspend, .suspend = ne2k_pci_suspend,
.resume = ne2k_pci_resume, .resume = ne2k_pci_resume,
#endif /* CONFIG_PM */ #endif
}; };
static int __init ne2k_pci_init(void) static int __init ne2k_pci_init(void)
{ {
/* when a module, this is printed whether or not devices are found in probe */
#ifdef MODULE
printk(version);
#endif
return pci_register_driver(&ne2k_driver); return pci_register_driver(&ne2k_driver);
} }
static void __exit ne2k_pci_cleanup(void) static void __exit ne2k_pci_cleanup(void)
{ {
pci_unregister_driver (&ne2k_driver); pci_unregister_driver(&ne2k_driver);
} }
module_init(ne2k_pci_init); module_init(ne2k_pci_init);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment