Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* pcnet32.c: An AMD PCnet32 ethernet driver for linux. */ |
| 2 | /* |
| 3 | * Copyright 1996-1999 Thomas Bogendoerfer |
| 4 | * |
| 5 | * Derived from the lance driver written 1993,1994,1995 by Donald Becker. |
| 6 | * |
| 7 | * Copyright 1993 United States Government as represented by the |
| 8 | * Director, National Security Agency. |
| 9 | * |
| 10 | * This software may be used and distributed according to the terms |
| 11 | * of the GNU General Public License, incorporated herein by reference. |
| 12 | * |
| 13 | * This driver is for PCnet32 and PCnetPCI based ethercards |
| 14 | */ |
| 15 | /************************************************************************** |
| 16 | * 23 Oct, 2000. |
| 17 | * Fixed a few bugs, related to running the controller in 32bit mode. |
| 18 | * |
| 19 | * Carsten Langgaard, carstenl@mips.com |
| 20 | * Copyright (C) 2000 MIPS Technologies, Inc. All rights reserved. |
| 21 | * |
| 22 | *************************************************************************/ |
| 23 | |
| 24 | #define DRV_NAME "pcnet32" |
Don Fry | 2964bbd | 2005-11-01 12:50:57 -0800 | [diff] [blame] | 25 | #define DRV_VERSION "1.31c" |
| 26 | #define DRV_RELDATE "01.Nov.2005" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | #define PFX DRV_NAME ": " |
| 28 | |
| 29 | static const char *version = |
| 30 | DRV_NAME ".c:v" DRV_VERSION " " DRV_RELDATE " tsbogend@alpha.franken.de\n"; |
| 31 | |
| 32 | #include <linux/module.h> |
| 33 | #include <linux/kernel.h> |
| 34 | #include <linux/string.h> |
| 35 | #include <linux/errno.h> |
| 36 | #include <linux/ioport.h> |
| 37 | #include <linux/slab.h> |
| 38 | #include <linux/interrupt.h> |
| 39 | #include <linux/pci.h> |
| 40 | #include <linux/delay.h> |
| 41 | #include <linux/init.h> |
| 42 | #include <linux/ethtool.h> |
| 43 | #include <linux/mii.h> |
| 44 | #include <linux/crc32.h> |
| 45 | #include <linux/netdevice.h> |
| 46 | #include <linux/etherdevice.h> |
| 47 | #include <linux/skbuff.h> |
| 48 | #include <linux/spinlock.h> |
| 49 | #include <linux/moduleparam.h> |
| 50 | #include <linux/bitops.h> |
| 51 | |
| 52 | #include <asm/dma.h> |
| 53 | #include <asm/io.h> |
| 54 | #include <asm/uaccess.h> |
| 55 | #include <asm/irq.h> |
| 56 | |
| 57 | /* |
| 58 | * PCI device identifiers for "new style" Linux PCI Device Drivers |
| 59 | */ |
| 60 | static struct pci_device_id pcnet32_pci_tbl[] = { |
| 61 | { PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_LANCE_HOME, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, |
| 62 | { PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_LANCE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, |
| 63 | /* |
| 64 | * Adapters that were sold with IBM's RS/6000 or pSeries hardware have |
| 65 | * the incorrect vendor id. |
| 66 | */ |
| 67 | { PCI_VENDOR_ID_TRIDENT, PCI_DEVICE_ID_AMD_LANCE, PCI_ANY_ID, PCI_ANY_ID, |
| 68 | PCI_CLASS_NETWORK_ETHERNET << 8, 0xffff00, 0 }, |
| 69 | { 0, } |
| 70 | }; |
| 71 | |
| 72 | MODULE_DEVICE_TABLE (pci, pcnet32_pci_tbl); |
| 73 | |
| 74 | static int cards_found; |
| 75 | |
| 76 | /* |
| 77 | * VLB I/O addresses |
| 78 | */ |
| 79 | static unsigned int pcnet32_portlist[] __initdata = |
| 80 | { 0x300, 0x320, 0x340, 0x360, 0 }; |
| 81 | |
| 82 | |
| 83 | |
| 84 | static int pcnet32_debug = 0; |
| 85 | static int tx_start = 1; /* Mapping -- 0:20, 1:64, 2:128, 3:~220 (depends on chip vers) */ |
| 86 | static int pcnet32vlb; /* check for VLB cards ? */ |
| 87 | |
| 88 | static struct net_device *pcnet32_dev; |
| 89 | |
| 90 | static int max_interrupt_work = 2; |
| 91 | static int rx_copybreak = 200; |
| 92 | |
| 93 | #define PCNET32_PORT_AUI 0x00 |
| 94 | #define PCNET32_PORT_10BT 0x01 |
| 95 | #define PCNET32_PORT_GPSI 0x02 |
| 96 | #define PCNET32_PORT_MII 0x03 |
| 97 | |
| 98 | #define PCNET32_PORT_PORTSEL 0x03 |
| 99 | #define PCNET32_PORT_ASEL 0x04 |
| 100 | #define PCNET32_PORT_100 0x40 |
| 101 | #define PCNET32_PORT_FD 0x80 |
| 102 | |
| 103 | #define PCNET32_DMA_MASK 0xffffffff |
| 104 | |
| 105 | #define PCNET32_WATCHDOG_TIMEOUT (jiffies + (2 * HZ)) |
| 106 | #define PCNET32_BLINK_TIMEOUT (jiffies + (HZ/4)) |
| 107 | |
| 108 | /* |
| 109 | * table to translate option values from tulip |
| 110 | * to internal options |
| 111 | */ |
| 112 | static unsigned char options_mapping[] = { |
| 113 | PCNET32_PORT_ASEL, /* 0 Auto-select */ |
| 114 | PCNET32_PORT_AUI, /* 1 BNC/AUI */ |
| 115 | PCNET32_PORT_AUI, /* 2 AUI/BNC */ |
| 116 | PCNET32_PORT_ASEL, /* 3 not supported */ |
| 117 | PCNET32_PORT_10BT | PCNET32_PORT_FD, /* 4 10baseT-FD */ |
| 118 | PCNET32_PORT_ASEL, /* 5 not supported */ |
| 119 | PCNET32_PORT_ASEL, /* 6 not supported */ |
| 120 | PCNET32_PORT_ASEL, /* 7 not supported */ |
| 121 | PCNET32_PORT_ASEL, /* 8 not supported */ |
| 122 | PCNET32_PORT_MII, /* 9 MII 10baseT */ |
| 123 | PCNET32_PORT_MII | PCNET32_PORT_FD, /* 10 MII 10baseT-FD */ |
| 124 | PCNET32_PORT_MII, /* 11 MII (autosel) */ |
| 125 | PCNET32_PORT_10BT, /* 12 10BaseT */ |
| 126 | PCNET32_PORT_MII | PCNET32_PORT_100, /* 13 MII 100BaseTx */ |
| 127 | PCNET32_PORT_MII | PCNET32_PORT_100 | PCNET32_PORT_FD, /* 14 MII 100BaseTx-FD */ |
| 128 | PCNET32_PORT_ASEL /* 15 not supported */ |
| 129 | }; |
| 130 | |
| 131 | static const char pcnet32_gstrings_test[][ETH_GSTRING_LEN] = { |
| 132 | "Loopback test (offline)" |
| 133 | }; |
| 134 | #define PCNET32_TEST_LEN (sizeof(pcnet32_gstrings_test) / ETH_GSTRING_LEN) |
| 135 | |
| 136 | #define PCNET32_NUM_REGS 168 |
| 137 | |
| 138 | #define MAX_UNITS 8 /* More are supported, limit only on options */ |
| 139 | static int options[MAX_UNITS]; |
| 140 | static int full_duplex[MAX_UNITS]; |
| 141 | static int homepna[MAX_UNITS]; |
| 142 | |
| 143 | /* |
| 144 | * Theory of Operation |
| 145 | * |
| 146 | * This driver uses the same software structure as the normal lance |
| 147 | * driver. So look for a verbose description in lance.c. The differences |
| 148 | * to the normal lance driver is the use of the 32bit mode of PCnet32 |
| 149 | * and PCnetPCI chips. Because these chips are 32bit chips, there is no |
| 150 | * 16MB limitation and we don't need bounce buffers. |
| 151 | */ |
| 152 | |
| 153 | /* |
| 154 | * History: |
| 155 | * v0.01: Initial version |
| 156 | * only tested on Alpha Noname Board |
| 157 | * v0.02: changed IRQ handling for new interrupt scheme (dev_id) |
| 158 | * tested on a ASUS SP3G |
| 159 | * v0.10: fixed an odd problem with the 79C974 in a Compaq Deskpro XL |
| 160 | * looks like the 974 doesn't like stopping and restarting in a |
| 161 | * short period of time; now we do a reinit of the lance; the |
| 162 | * bug was triggered by doing ifconfig eth0 <ip> broadcast <addr> |
| 163 | * and hangs the machine (thanks to Klaus Liedl for debugging) |
| 164 | * v0.12: by suggestion from Donald Becker: Renamed driver to pcnet32, |
| 165 | * made it standalone (no need for lance.c) |
| 166 | * v0.13: added additional PCI detecting for special PCI devices (Compaq) |
| 167 | * v0.14: stripped down additional PCI probe (thanks to David C Niemi |
| 168 | * and sveneric@xs4all.nl for testing this on their Compaq boxes) |
| 169 | * v0.15: added 79C965 (VLB) probe |
| 170 | * added interrupt sharing for PCI chips |
| 171 | * v0.16: fixed set_multicast_list on Alpha machines |
| 172 | * v0.17: removed hack from dev.c; now pcnet32 uses ethif_probe in Space.c |
| 173 | * v0.19: changed setting of autoselect bit |
| 174 | * v0.20: removed additional Compaq PCI probe; there is now a working one |
| 175 | * in arch/i386/bios32.c |
| 176 | * v0.21: added endian conversion for ppc, from work by cort@cs.nmt.edu |
| 177 | * v0.22: added printing of status to ring dump |
| 178 | * v0.23: changed enet_statistics to net_devive_stats |
| 179 | * v0.90: added multicast filter |
| 180 | * added module support |
| 181 | * changed irq probe to new style |
| 182 | * added PCnetFast chip id |
| 183 | * added fix for receive stalls with Intel saturn chipsets |
| 184 | * added in-place rx skbs like in the tulip driver |
| 185 | * minor cleanups |
| 186 | * v0.91: added PCnetFast+ chip id |
| 187 | * back port to 2.0.x |
| 188 | * v1.00: added some stuff from Donald Becker's 2.0.34 version |
| 189 | * added support for byte counters in net_dev_stats |
| 190 | * v1.01: do ring dumps, only when debugging the driver |
| 191 | * increased the transmit timeout |
| 192 | * v1.02: fixed memory leak in pcnet32_init_ring() |
| 193 | * v1.10: workaround for stopped transmitter |
| 194 | * added port selection for modules |
| 195 | * detect special T1/E1 WAN card and setup port selection |
| 196 | * v1.11: fixed wrong checking of Tx errors |
| 197 | * v1.20: added check of return value kmalloc (cpeterso@cs.washington.edu) |
| 198 | * added save original kmalloc addr for freeing (mcr@solidum.com) |
| 199 | * added support for PCnetHome chip (joe@MIT.EDU) |
| 200 | * rewritten PCI card detection |
| 201 | * added dwio mode to get driver working on some PPC machines |
| 202 | * v1.21: added mii selection and mii ioctl |
| 203 | * v1.22: changed pci scanning code to make PPC people happy |
| 204 | * fixed switching to 32bit mode in pcnet32_open() (thanks |
| 205 | * to Michael Richard <mcr@solidum.com> for noticing this one) |
| 206 | * added sub vendor/device id matching (thanks again to |
| 207 | * Michael Richard <mcr@solidum.com>) |
| 208 | * added chip id for 79c973/975 (thanks to Zach Brown <zab@zabbo.net>) |
| 209 | * v1.23 fixed small bug, when manual selecting MII speed/duplex |
| 210 | * v1.24 Applied Thomas' patch to use TxStartPoint and thus decrease TxFIFO |
| 211 | * underflows. Added tx_start_pt module parameter. Increased |
| 212 | * TX_RING_SIZE from 16 to 32. Added #ifdef'd code to use DXSUFLO |
| 213 | * for FAST[+] chipsets. <kaf@fc.hp.com> |
| 214 | * v1.24ac Added SMP spinlocking - Alan Cox <alan@redhat.com> |
| 215 | * v1.25kf Added No Interrupt on successful Tx for some Tx's <kaf@fc.hp.com> |
| 216 | * v1.26 Converted to pci_alloc_consistent, Jamey Hicks / George France |
| 217 | * <jamey@crl.dec.com> |
| 218 | * - Fixed a few bugs, related to running the controller in 32bit mode. |
| 219 | * 23 Oct, 2000. Carsten Langgaard, carstenl@mips.com |
| 220 | * Copyright (C) 2000 MIPS Technologies, Inc. All rights reserved. |
| 221 | * v1.26p Fix oops on rmmod+insmod; plug i/o resource leak - Paul Gortmaker |
| 222 | * v1.27 improved CSR/PROM address detection, lots of cleanups, |
| 223 | * new pcnet32vlb module option, HP-PARISC support, |
| 224 | * added module parameter descriptions, |
| 225 | * initial ethtool support - Helge Deller <deller@gmx.de> |
| 226 | * v1.27a Sun Feb 10 2002 Go Taniguchi <go@turbolinux.co.jp> |
| 227 | * use alloc_etherdev and register_netdev |
| 228 | * fix pci probe not increment cards_found |
| 229 | * FD auto negotiate error workaround for xSeries250 |
| 230 | * clean up and using new mii module |
| 231 | * v1.27b Sep 30 2002 Kent Yoder <yoder1@us.ibm.com> |
| 232 | * Added timer for cable connection state changes. |
| 233 | * v1.28 20 Feb 2004 Don Fry <brazilnut@us.ibm.com> |
| 234 | * Jon Mason <jonmason@us.ibm.com>, Chinmay Albal <albal@in.ibm.com> |
| 235 | * Now uses ethtool_ops, netif_msg_* and generic_mii_ioctl. |
| 236 | * Fixes bogus 'Bus master arbitration failure', pci_[un]map_single |
| 237 | * length errors, and transmit hangs. Cleans up after errors in open. |
| 238 | * Jim Lewis <jklewis@us.ibm.com> added ethernet loopback test. |
| 239 | * Thomas Munck Steenholdt <tmus@tmus.dk> non-mii ioctl corrections. |
| 240 | * v1.29 6 Apr 2004 Jim Lewis <jklewis@us.ibm.com> added physical |
| 241 | * identification code (blink led's) and register dump. |
| 242 | * Don Fry added timer for 971/972 so skbufs don't remain on tx ring |
| 243 | * forever. |
| 244 | * v1.30 18 May 2004 Don Fry removed timer and Last Transmit Interrupt |
| 245 | * (ltint) as they added complexity and didn't give good throughput. |
| 246 | * v1.30a 22 May 2004 Don Fry limit frames received during interrupt. |
| 247 | * v1.30b 24 May 2004 Don Fry fix bogus tx carrier errors with 79c973, |
| 248 | * assisted by Bruce Penrod <bmpenrod@endruntechnologies.com>. |
| 249 | * v1.30c 25 May 2004 Don Fry added netif_wake_queue after pcnet32_restart. |
| 250 | * v1.30d 01 Jun 2004 Don Fry discard oversize rx packets. |
| 251 | * v1.30e 11 Jun 2004 Don Fry recover after fifo error and rx hang. |
| 252 | * v1.30f 16 Jun 2004 Don Fry cleanup IRQ to allow 0 and 1 for PCI, |
| 253 | * expanding on suggestions from Ralf Baechle <ralf@linux-mips.org>, |
| 254 | * and Brian Murphy <brian@murphy.dk>. |
| 255 | * v1.30g 22 Jun 2004 Patrick Simmons <psimmons@flash.net> added option |
| 256 | * homepna for selecting HomePNA mode for PCNet/Home 79C978. |
| 257 | * v1.30h 24 Jun 2004 Don Fry correctly select auto, speed, duplex in bcr32. |
| 258 | * v1.30i 28 Jun 2004 Don Fry change to use module_param. |
Don Fry | 1bcd315 | 2005-04-29 14:51:17 -0700 | [diff] [blame] | 259 | * v1.30j 29 Apr 2005 Don Fry fix skb/map leak with loopback test. |
Hubert WS Lin | eabf041 | 2005-09-14 11:39:25 -0700 | [diff] [blame] | 260 | * v1.31 02 Sep 2005 Hubert WS Lin <wslin@tw.ibm.c0m> added set_ringparam(). |
Hubert WS Lin | 7620992 | 2005-09-14 11:39:27 -0700 | [diff] [blame] | 261 | * v1.31a 12 Sep 2005 Hubert WS Lin <wslin@tw.ibm.c0m> set min ring size to 4 |
| 262 | * to allow loopback test to work unchanged. |
Don Fry | a88c844 | 2005-11-01 12:04:33 -0800 | [diff] [blame] | 263 | * v1.31b 06 Oct 2005 Don Fry changed alloc_ring to show name of device |
| 264 | * if allocation fails |
Don Fry | 2964bbd | 2005-11-01 12:50:57 -0800 | [diff] [blame] | 265 | * v1.31c 01 Nov 2005 Don Fry Allied Telesyn 2700/2701 FX are 100Mbit only. |
| 266 | * Force 100Mbit FD if Auto (ASEL) is selected. |
| 267 | * See Bugzilla 2669 and 4551. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | */ |
| 269 | |
| 270 | |
| 271 | /* |
| 272 | * Set the number of Tx and Rx buffers, using Log_2(# buffers). |
| 273 | * Reasonable default values are 4 Tx buffers, and 16 Rx buffers. |
| 274 | * That translates to 2 (4 == 2^^2) and 4 (16 == 2^^4). |
| 275 | */ |
| 276 | #ifndef PCNET32_LOG_TX_BUFFERS |
Hubert WS Lin | eabf041 | 2005-09-14 11:39:25 -0700 | [diff] [blame] | 277 | #define PCNET32_LOG_TX_BUFFERS 4 |
| 278 | #define PCNET32_LOG_RX_BUFFERS 5 |
| 279 | #define PCNET32_LOG_MAX_TX_BUFFERS 9 /* 2^9 == 512 */ |
| 280 | #define PCNET32_LOG_MAX_RX_BUFFERS 9 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | #endif |
| 282 | |
| 283 | #define TX_RING_SIZE (1 << (PCNET32_LOG_TX_BUFFERS)) |
Hubert WS Lin | eabf041 | 2005-09-14 11:39:25 -0700 | [diff] [blame] | 284 | #define TX_MAX_RING_SIZE (1 << (PCNET32_LOG_MAX_TX_BUFFERS)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | |
| 286 | #define RX_RING_SIZE (1 << (PCNET32_LOG_RX_BUFFERS)) |
Hubert WS Lin | eabf041 | 2005-09-14 11:39:25 -0700 | [diff] [blame] | 287 | #define RX_MAX_RING_SIZE (1 << (PCNET32_LOG_MAX_RX_BUFFERS)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | |
| 289 | #define PKT_BUF_SZ 1544 |
| 290 | |
| 291 | /* Offsets from base I/O address. */ |
| 292 | #define PCNET32_WIO_RDP 0x10 |
| 293 | #define PCNET32_WIO_RAP 0x12 |
| 294 | #define PCNET32_WIO_RESET 0x14 |
| 295 | #define PCNET32_WIO_BDP 0x16 |
| 296 | |
| 297 | #define PCNET32_DWIO_RDP 0x10 |
| 298 | #define PCNET32_DWIO_RAP 0x14 |
| 299 | #define PCNET32_DWIO_RESET 0x18 |
| 300 | #define PCNET32_DWIO_BDP 0x1C |
| 301 | |
| 302 | #define PCNET32_TOTAL_SIZE 0x20 |
| 303 | |
| 304 | /* The PCNET32 Rx and Tx ring descriptors. */ |
| 305 | struct pcnet32_rx_head { |
| 306 | u32 base; |
| 307 | s16 buf_length; |
| 308 | s16 status; |
| 309 | u32 msg_length; |
| 310 | u32 reserved; |
| 311 | }; |
| 312 | |
| 313 | struct pcnet32_tx_head { |
| 314 | u32 base; |
| 315 | s16 length; |
| 316 | s16 status; |
| 317 | u32 misc; |
| 318 | u32 reserved; |
| 319 | }; |
| 320 | |
| 321 | /* The PCNET32 32-Bit initialization block, described in databook. */ |
| 322 | struct pcnet32_init_block { |
| 323 | u16 mode; |
| 324 | u16 tlen_rlen; |
| 325 | u8 phys_addr[6]; |
| 326 | u16 reserved; |
| 327 | u32 filter[2]; |
| 328 | /* Receive and transmit ring base, along with extra bits. */ |
| 329 | u32 rx_ring; |
| 330 | u32 tx_ring; |
| 331 | }; |
| 332 | |
| 333 | /* PCnet32 access functions */ |
| 334 | struct pcnet32_access { |
| 335 | u16 (*read_csr)(unsigned long, int); |
| 336 | void (*write_csr)(unsigned long, int, u16); |
| 337 | u16 (*read_bcr)(unsigned long, int); |
| 338 | void (*write_bcr)(unsigned long, int, u16); |
| 339 | u16 (*read_rap)(unsigned long); |
| 340 | void (*write_rap)(unsigned long, u16); |
| 341 | void (*reset)(unsigned long); |
| 342 | }; |
| 343 | |
| 344 | /* |
Hubert WS Lin | 7620992 | 2005-09-14 11:39:27 -0700 | [diff] [blame] | 345 | * The first field of pcnet32_private is read by the ethernet device |
| 346 | * so the structure should be allocated using pci_alloc_consistent(). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | */ |
| 348 | struct pcnet32_private { |
Hubert WS Lin | 7620992 | 2005-09-14 11:39:27 -0700 | [diff] [blame] | 349 | struct pcnet32_init_block init_block; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | /* The Tx and Rx ring entries must be aligned on 16-byte boundaries in 32bit mode. */ |
Hubert WS Lin | eabf041 | 2005-09-14 11:39:25 -0700 | [diff] [blame] | 351 | struct pcnet32_rx_head *rx_ring; |
| 352 | struct pcnet32_tx_head *tx_ring; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | dma_addr_t dma_addr; /* DMA address of beginning of this |
| 354 | object, returned by |
| 355 | pci_alloc_consistent */ |
| 356 | struct pci_dev *pci_dev; /* Pointer to the associated pci device |
| 357 | structure */ |
| 358 | const char *name; |
| 359 | /* The saved address of a sent-in-place packet/buffer, for skfree(). */ |
Hubert WS Lin | eabf041 | 2005-09-14 11:39:25 -0700 | [diff] [blame] | 360 | struct sk_buff **tx_skbuff; |
| 361 | struct sk_buff **rx_skbuff; |
| 362 | dma_addr_t *tx_dma_addr; |
| 363 | dma_addr_t *rx_dma_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | struct pcnet32_access a; |
| 365 | spinlock_t lock; /* Guard lock */ |
| 366 | unsigned int cur_rx, cur_tx; /* The next free ring entry */ |
Hubert WS Lin | eabf041 | 2005-09-14 11:39:25 -0700 | [diff] [blame] | 367 | unsigned int rx_ring_size; /* current rx ring size */ |
| 368 | unsigned int tx_ring_size; /* current tx ring size */ |
| 369 | unsigned int rx_mod_mask; /* rx ring modular mask */ |
| 370 | unsigned int tx_mod_mask; /* tx ring modular mask */ |
| 371 | unsigned short rx_len_bits; |
| 372 | unsigned short tx_len_bits; |
| 373 | dma_addr_t rx_ring_dma_addr; |
| 374 | dma_addr_t tx_ring_dma_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | unsigned int dirty_rx, dirty_tx; /* The ring entries to be free()ed. */ |
| 376 | struct net_device_stats stats; |
| 377 | char tx_full; |
| 378 | int options; |
| 379 | unsigned int shared_irq:1, /* shared irq possible */ |
| 380 | dxsuflo:1, /* disable transmit stop on uflo */ |
| 381 | mii:1; /* mii port available */ |
| 382 | struct net_device *next; |
| 383 | struct mii_if_info mii_if; |
| 384 | struct timer_list watchdog_timer; |
| 385 | struct timer_list blink_timer; |
| 386 | u32 msg_enable; /* debug message level */ |
| 387 | }; |
| 388 | |
| 389 | static void pcnet32_probe_vlbus(void); |
| 390 | static int pcnet32_probe_pci(struct pci_dev *, const struct pci_device_id *); |
| 391 | static int pcnet32_probe1(unsigned long, int, struct pci_dev *); |
| 392 | static int pcnet32_open(struct net_device *); |
| 393 | static int pcnet32_init_ring(struct net_device *); |
| 394 | static int pcnet32_start_xmit(struct sk_buff *, struct net_device *); |
| 395 | static int pcnet32_rx(struct net_device *); |
| 396 | static void pcnet32_tx_timeout (struct net_device *dev); |
| 397 | static irqreturn_t pcnet32_interrupt(int, void *, struct pt_regs *); |
| 398 | static int pcnet32_close(struct net_device *); |
| 399 | static struct net_device_stats *pcnet32_get_stats(struct net_device *); |
| 400 | static void pcnet32_load_multicast(struct net_device *dev); |
| 401 | static void pcnet32_set_multicast_list(struct net_device *); |
| 402 | static int pcnet32_ioctl(struct net_device *, struct ifreq *, int); |
| 403 | static void pcnet32_watchdog(struct net_device *); |
| 404 | static int mdio_read(struct net_device *dev, int phy_id, int reg_num); |
| 405 | static void mdio_write(struct net_device *dev, int phy_id, int reg_num, int val); |
| 406 | static void pcnet32_restart(struct net_device *dev, unsigned int csr0_bits); |
| 407 | static void pcnet32_ethtool_test(struct net_device *dev, |
| 408 | struct ethtool_test *eth_test, u64 *data); |
| 409 | static int pcnet32_loopback_test(struct net_device *dev, uint64_t *data1); |
| 410 | static int pcnet32_phys_id(struct net_device *dev, u32 data); |
| 411 | static void pcnet32_led_blink_callback(struct net_device *dev); |
| 412 | static int pcnet32_get_regs_len(struct net_device *dev); |
| 413 | static void pcnet32_get_regs(struct net_device *dev, struct ethtool_regs *regs, |
| 414 | void *ptr); |
Don Fry | 1bcd315 | 2005-04-29 14:51:17 -0700 | [diff] [blame] | 415 | static void pcnet32_purge_tx_ring(struct net_device *dev); |
Don Fry | a88c844 | 2005-11-01 12:04:33 -0800 | [diff] [blame] | 416 | static int pcnet32_alloc_ring(struct net_device *dev, char *name); |
Hubert WS Lin | eabf041 | 2005-09-14 11:39:25 -0700 | [diff] [blame] | 417 | static void pcnet32_free_ring(struct net_device *dev); |
| 418 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | |
| 420 | enum pci_flags_bit { |
| 421 | PCI_USES_IO=1, PCI_USES_MEM=2, PCI_USES_MASTER=4, |
| 422 | PCI_ADDR0=0x10<<0, PCI_ADDR1=0x10<<1, PCI_ADDR2=0x10<<2, PCI_ADDR3=0x10<<3, |
| 423 | }; |
| 424 | |
| 425 | |
| 426 | static u16 pcnet32_wio_read_csr (unsigned long addr, int index) |
| 427 | { |
| 428 | outw (index, addr+PCNET32_WIO_RAP); |
| 429 | return inw (addr+PCNET32_WIO_RDP); |
| 430 | } |
| 431 | |
| 432 | static void pcnet32_wio_write_csr (unsigned long addr, int index, u16 val) |
| 433 | { |
| 434 | outw (index, addr+PCNET32_WIO_RAP); |
| 435 | outw (val, addr+PCNET32_WIO_RDP); |
| 436 | } |
| 437 | |
| 438 | static u16 pcnet32_wio_read_bcr (unsigned long addr, int index) |
| 439 | { |
| 440 | outw (index, addr+PCNET32_WIO_RAP); |
| 441 | return inw (addr+PCNET32_WIO_BDP); |
| 442 | } |
| 443 | |
| 444 | static void pcnet32_wio_write_bcr (unsigned long addr, int index, u16 val) |
| 445 | { |
| 446 | outw (index, addr+PCNET32_WIO_RAP); |
| 447 | outw (val, addr+PCNET32_WIO_BDP); |
| 448 | } |
| 449 | |
| 450 | static u16 pcnet32_wio_read_rap (unsigned long addr) |
| 451 | { |
| 452 | return inw (addr+PCNET32_WIO_RAP); |
| 453 | } |
| 454 | |
| 455 | static void pcnet32_wio_write_rap (unsigned long addr, u16 val) |
| 456 | { |
| 457 | outw (val, addr+PCNET32_WIO_RAP); |
| 458 | } |
| 459 | |
| 460 | static void pcnet32_wio_reset (unsigned long addr) |
| 461 | { |
| 462 | inw (addr+PCNET32_WIO_RESET); |
| 463 | } |
| 464 | |
| 465 | static int pcnet32_wio_check (unsigned long addr) |
| 466 | { |
| 467 | outw (88, addr+PCNET32_WIO_RAP); |
| 468 | return (inw (addr+PCNET32_WIO_RAP) == 88); |
| 469 | } |
| 470 | |
| 471 | static struct pcnet32_access pcnet32_wio = { |
| 472 | .read_csr = pcnet32_wio_read_csr, |
| 473 | .write_csr = pcnet32_wio_write_csr, |
| 474 | .read_bcr = pcnet32_wio_read_bcr, |
| 475 | .write_bcr = pcnet32_wio_write_bcr, |
| 476 | .read_rap = pcnet32_wio_read_rap, |
| 477 | .write_rap = pcnet32_wio_write_rap, |
| 478 | .reset = pcnet32_wio_reset |
| 479 | }; |
| 480 | |
| 481 | static u16 pcnet32_dwio_read_csr (unsigned long addr, int index) |
| 482 | { |
| 483 | outl (index, addr+PCNET32_DWIO_RAP); |
| 484 | return (inl (addr+PCNET32_DWIO_RDP) & 0xffff); |
| 485 | } |
| 486 | |
| 487 | static void pcnet32_dwio_write_csr (unsigned long addr, int index, u16 val) |
| 488 | { |
| 489 | outl (index, addr+PCNET32_DWIO_RAP); |
| 490 | outl (val, addr+PCNET32_DWIO_RDP); |
| 491 | } |
| 492 | |
| 493 | static u16 pcnet32_dwio_read_bcr (unsigned long addr, int index) |
| 494 | { |
| 495 | outl (index, addr+PCNET32_DWIO_RAP); |
| 496 | return (inl (addr+PCNET32_DWIO_BDP) & 0xffff); |
| 497 | } |
| 498 | |
| 499 | static void pcnet32_dwio_write_bcr (unsigned long addr, int index, u16 val) |
| 500 | { |
| 501 | outl (index, addr+PCNET32_DWIO_RAP); |
| 502 | outl (val, addr+PCNET32_DWIO_BDP); |
| 503 | } |
| 504 | |
| 505 | static u16 pcnet32_dwio_read_rap (unsigned long addr) |
| 506 | { |
| 507 | return (inl (addr+PCNET32_DWIO_RAP) & 0xffff); |
| 508 | } |
| 509 | |
| 510 | static void pcnet32_dwio_write_rap (unsigned long addr, u16 val) |
| 511 | { |
| 512 | outl (val, addr+PCNET32_DWIO_RAP); |
| 513 | } |
| 514 | |
| 515 | static void pcnet32_dwio_reset (unsigned long addr) |
| 516 | { |
| 517 | inl (addr+PCNET32_DWIO_RESET); |
| 518 | } |
| 519 | |
| 520 | static int pcnet32_dwio_check (unsigned long addr) |
| 521 | { |
| 522 | outl (88, addr+PCNET32_DWIO_RAP); |
| 523 | return ((inl (addr+PCNET32_DWIO_RAP) & 0xffff) == 88); |
| 524 | } |
| 525 | |
| 526 | static struct pcnet32_access pcnet32_dwio = { |
| 527 | .read_csr = pcnet32_dwio_read_csr, |
| 528 | .write_csr = pcnet32_dwio_write_csr, |
| 529 | .read_bcr = pcnet32_dwio_read_bcr, |
| 530 | .write_bcr = pcnet32_dwio_write_bcr, |
| 531 | .read_rap = pcnet32_dwio_read_rap, |
| 532 | .write_rap = pcnet32_dwio_write_rap, |
| 533 | .reset = pcnet32_dwio_reset |
| 534 | }; |
| 535 | |
| 536 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 537 | static void pcnet32_poll_controller(struct net_device *dev) |
| 538 | { |
| 539 | disable_irq(dev->irq); |
| 540 | pcnet32_interrupt(0, dev, NULL); |
| 541 | enable_irq(dev->irq); |
| 542 | } |
| 543 | #endif |
| 544 | |
| 545 | |
| 546 | static int pcnet32_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) |
| 547 | { |
| 548 | struct pcnet32_private *lp = dev->priv; |
| 549 | unsigned long flags; |
| 550 | int r = -EOPNOTSUPP; |
| 551 | |
| 552 | if (lp->mii) { |
| 553 | spin_lock_irqsave(&lp->lock, flags); |
| 554 | mii_ethtool_gset(&lp->mii_if, cmd); |
| 555 | spin_unlock_irqrestore(&lp->lock, flags); |
| 556 | r = 0; |
| 557 | } |
| 558 | return r; |
| 559 | } |
| 560 | |
| 561 | static int pcnet32_set_settings(struct net_device *dev, struct ethtool_cmd *cmd) |
| 562 | { |
| 563 | struct pcnet32_private *lp = dev->priv; |
| 564 | unsigned long flags; |
| 565 | int r = -EOPNOTSUPP; |
| 566 | |
| 567 | if (lp->mii) { |
| 568 | spin_lock_irqsave(&lp->lock, flags); |
| 569 | r = mii_ethtool_sset(&lp->mii_if, cmd); |
| 570 | spin_unlock_irqrestore(&lp->lock, flags); |
| 571 | } |
| 572 | return r; |
| 573 | } |
| 574 | |
| 575 | static void pcnet32_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info) |
| 576 | { |
| 577 | struct pcnet32_private *lp = dev->priv; |
| 578 | |
| 579 | strcpy (info->driver, DRV_NAME); |
| 580 | strcpy (info->version, DRV_VERSION); |
| 581 | if (lp->pci_dev) |
| 582 | strcpy (info->bus_info, pci_name(lp->pci_dev)); |
| 583 | else |
| 584 | sprintf(info->bus_info, "VLB 0x%lx", dev->base_addr); |
| 585 | } |
| 586 | |
| 587 | static u32 pcnet32_get_link(struct net_device *dev) |
| 588 | { |
| 589 | struct pcnet32_private *lp = dev->priv; |
| 590 | unsigned long flags; |
| 591 | int r; |
| 592 | |
| 593 | spin_lock_irqsave(&lp->lock, flags); |
| 594 | if (lp->mii) { |
| 595 | r = mii_link_ok(&lp->mii_if); |
| 596 | } else { |
| 597 | ulong ioaddr = dev->base_addr; /* card base I/O address */ |
| 598 | r = (lp->a.read_bcr(ioaddr, 4) != 0xc0); |
| 599 | } |
| 600 | spin_unlock_irqrestore(&lp->lock, flags); |
| 601 | |
| 602 | return r; |
| 603 | } |
| 604 | |
| 605 | static u32 pcnet32_get_msglevel(struct net_device *dev) |
| 606 | { |
| 607 | struct pcnet32_private *lp = dev->priv; |
| 608 | return lp->msg_enable; |
| 609 | } |
| 610 | |
| 611 | static void pcnet32_set_msglevel(struct net_device *dev, u32 value) |
| 612 | { |
| 613 | struct pcnet32_private *lp = dev->priv; |
| 614 | lp->msg_enable = value; |
| 615 | } |
| 616 | |
| 617 | static int pcnet32_nway_reset(struct net_device *dev) |
| 618 | { |
| 619 | struct pcnet32_private *lp = dev->priv; |
| 620 | unsigned long flags; |
| 621 | int r = -EOPNOTSUPP; |
| 622 | |
| 623 | if (lp->mii) { |
| 624 | spin_lock_irqsave(&lp->lock, flags); |
| 625 | r = mii_nway_restart(&lp->mii_if); |
| 626 | spin_unlock_irqrestore(&lp->lock, flags); |
| 627 | } |
| 628 | return r; |
| 629 | } |
| 630 | |
| 631 | static void pcnet32_get_ringparam(struct net_device *dev, struct ethtool_ringparam *ering) |
| 632 | { |
| 633 | struct pcnet32_private *lp = dev->priv; |
| 634 | |
Hubert WS Lin | eabf041 | 2005-09-14 11:39:25 -0700 | [diff] [blame] | 635 | ering->tx_max_pending = TX_MAX_RING_SIZE - 1; |
| 636 | ering->tx_pending = lp->tx_ring_size - 1; |
| 637 | ering->rx_max_pending = RX_MAX_RING_SIZE - 1; |
| 638 | ering->rx_pending = lp->rx_ring_size - 1; |
| 639 | } |
| 640 | |
| 641 | static int pcnet32_set_ringparam(struct net_device *dev, struct ethtool_ringparam *ering) |
| 642 | { |
| 643 | struct pcnet32_private *lp = dev->priv; |
| 644 | unsigned long flags; |
| 645 | int i; |
| 646 | |
| 647 | if (ering->rx_mini_pending || ering->rx_jumbo_pending) |
| 648 | return -EINVAL; |
| 649 | |
| 650 | if (netif_running(dev)) |
| 651 | pcnet32_close(dev); |
| 652 | |
| 653 | spin_lock_irqsave(&lp->lock, flags); |
| 654 | pcnet32_free_ring(dev); |
| 655 | lp->tx_ring_size = min(ering->tx_pending, (unsigned int) TX_MAX_RING_SIZE); |
| 656 | lp->rx_ring_size = min(ering->rx_pending, (unsigned int) RX_MAX_RING_SIZE); |
| 657 | |
Hubert WS Lin | 7620992 | 2005-09-14 11:39:27 -0700 | [diff] [blame] | 658 | /* set the minimum ring size to 4, to allow the loopback test to work |
| 659 | * unchanged. |
| 660 | */ |
| 661 | for (i = 2; i <= PCNET32_LOG_MAX_TX_BUFFERS; i++) { |
Hubert WS Lin | eabf041 | 2005-09-14 11:39:25 -0700 | [diff] [blame] | 662 | if (lp->tx_ring_size <= (1 << i)) |
| 663 | break; |
| 664 | } |
| 665 | lp->tx_ring_size = (1 << i); |
| 666 | lp->tx_mod_mask = lp->tx_ring_size - 1; |
| 667 | lp->tx_len_bits = (i << 12); |
| 668 | |
Hubert WS Lin | 7620992 | 2005-09-14 11:39:27 -0700 | [diff] [blame] | 669 | for (i = 2; i <= PCNET32_LOG_MAX_RX_BUFFERS; i++) { |
Hubert WS Lin | eabf041 | 2005-09-14 11:39:25 -0700 | [diff] [blame] | 670 | if (lp->rx_ring_size <= (1 << i)) |
| 671 | break; |
| 672 | } |
| 673 | lp->rx_ring_size = (1 << i); |
| 674 | lp->rx_mod_mask = lp->rx_ring_size - 1; |
| 675 | lp->rx_len_bits = (i << 4); |
| 676 | |
Don Fry | a88c844 | 2005-11-01 12:04:33 -0800 | [diff] [blame] | 677 | if (pcnet32_alloc_ring(dev, dev->name)) { |
Hubert WS Lin | eabf041 | 2005-09-14 11:39:25 -0700 | [diff] [blame] | 678 | pcnet32_free_ring(dev); |
Don Fry | a88c844 | 2005-11-01 12:04:33 -0800 | [diff] [blame] | 679 | spin_unlock_irqrestore(&lp->lock, flags); |
Hubert WS Lin | eabf041 | 2005-09-14 11:39:25 -0700 | [diff] [blame] | 680 | return -ENOMEM; |
| 681 | } |
| 682 | |
| 683 | spin_unlock_irqrestore(&lp->lock, flags); |
| 684 | |
| 685 | if (pcnet32_debug & NETIF_MSG_DRV) |
Don Fry | a88c844 | 2005-11-01 12:04:33 -0800 | [diff] [blame] | 686 | printk(KERN_INFO PFX "%s: Ring Param Settings: RX: %d, TX: %d\n", |
| 687 | dev->name, lp->rx_ring_size, lp->tx_ring_size); |
Hubert WS Lin | eabf041 | 2005-09-14 11:39:25 -0700 | [diff] [blame] | 688 | |
| 689 | if (netif_running(dev)) |
| 690 | pcnet32_open(dev); |
| 691 | |
| 692 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 693 | } |
| 694 | |
| 695 | static void pcnet32_get_strings(struct net_device *dev, u32 stringset, u8 *data) |
| 696 | { |
| 697 | memcpy(data, pcnet32_gstrings_test, sizeof(pcnet32_gstrings_test)); |
| 698 | } |
| 699 | |
| 700 | static int pcnet32_self_test_count(struct net_device *dev) |
| 701 | { |
| 702 | return PCNET32_TEST_LEN; |
| 703 | } |
| 704 | |
| 705 | static void pcnet32_ethtool_test(struct net_device *dev, |
| 706 | struct ethtool_test *test, u64 *data) |
| 707 | { |
| 708 | struct pcnet32_private *lp = dev->priv; |
| 709 | int rc; |
| 710 | |
| 711 | if (test->flags == ETH_TEST_FL_OFFLINE) { |
| 712 | rc = pcnet32_loopback_test(dev, data); |
| 713 | if (rc) { |
| 714 | if (netif_msg_hw(lp)) |
| 715 | printk(KERN_DEBUG "%s: Loopback test failed.\n", dev->name); |
| 716 | test->flags |= ETH_TEST_FL_FAILED; |
| 717 | } else if (netif_msg_hw(lp)) |
| 718 | printk(KERN_DEBUG "%s: Loopback test passed.\n", dev->name); |
| 719 | } else if (netif_msg_hw(lp)) |
| 720 | printk(KERN_DEBUG "%s: No tests to run (specify 'Offline' on ethtool).", dev->name); |
| 721 | } /* end pcnet32_ethtool_test */ |
| 722 | |
| 723 | static int pcnet32_loopback_test(struct net_device *dev, uint64_t *data1) |
| 724 | { |
| 725 | struct pcnet32_private *lp = dev->priv; |
| 726 | struct pcnet32_access *a = &lp->a; /* access to registers */ |
| 727 | ulong ioaddr = dev->base_addr; /* card base I/O address */ |
| 728 | struct sk_buff *skb; /* sk buff */ |
| 729 | int x, i; /* counters */ |
| 730 | int numbuffs = 4; /* number of TX/RX buffers and descs */ |
| 731 | u16 status = 0x8300; /* TX ring status */ |
| 732 | u16 teststatus; /* test of ring status */ |
| 733 | int rc; /* return code */ |
| 734 | int size; /* size of packets */ |
| 735 | unsigned char *packet; /* source packet data */ |
| 736 | static int data_len = 60; /* length of source packets */ |
| 737 | unsigned long flags; |
| 738 | unsigned long ticks; |
| 739 | |
| 740 | *data1 = 1; /* status of test, default to fail */ |
| 741 | rc = 1; /* default to fail */ |
| 742 | |
| 743 | if (netif_running(dev)) |
| 744 | pcnet32_close(dev); |
| 745 | |
| 746 | spin_lock_irqsave(&lp->lock, flags); |
| 747 | |
| 748 | /* Reset the PCNET32 */ |
| 749 | lp->a.reset (ioaddr); |
| 750 | |
| 751 | /* switch pcnet32 to 32bit mode */ |
| 752 | lp->a.write_bcr (ioaddr, 20, 2); |
| 753 | |
| 754 | lp->init_block.mode = le16_to_cpu((lp->options & PCNET32_PORT_PORTSEL) << 7); |
| 755 | lp->init_block.filter[0] = 0; |
| 756 | lp->init_block.filter[1] = 0; |
| 757 | |
| 758 | /* purge & init rings but don't actually restart */ |
| 759 | pcnet32_restart(dev, 0x0000); |
| 760 | |
| 761 | lp->a.write_csr(ioaddr, 0, 0x0004); /* Set STOP bit */ |
| 762 | |
| 763 | /* Initialize Transmit buffers. */ |
| 764 | size = data_len + 15; |
| 765 | for (x=0; x<numbuffs; x++) { |
| 766 | if (!(skb = dev_alloc_skb(size))) { |
| 767 | if (netif_msg_hw(lp)) |
| 768 | printk(KERN_DEBUG "%s: Cannot allocate skb at line: %d!\n", |
| 769 | dev->name, __LINE__); |
| 770 | goto clean_up; |
| 771 | } else { |
| 772 | packet = skb->data; |
| 773 | skb_put(skb, size); /* create space for data */ |
| 774 | lp->tx_skbuff[x] = skb; |
| 775 | lp->tx_ring[x].length = le16_to_cpu(-skb->len); |
| 776 | lp->tx_ring[x].misc = 0; |
| 777 | |
| 778 | /* put DA and SA into the skb */ |
| 779 | for (i=0; i<6; i++) |
| 780 | *packet++ = dev->dev_addr[i]; |
| 781 | for (i=0; i<6; i++) |
| 782 | *packet++ = dev->dev_addr[i]; |
| 783 | /* type */ |
| 784 | *packet++ = 0x08; |
| 785 | *packet++ = 0x06; |
| 786 | /* packet number */ |
| 787 | *packet++ = x; |
| 788 | /* fill packet with data */ |
| 789 | for (i=0; i<data_len; i++) |
| 790 | *packet++ = i; |
| 791 | |
| 792 | lp->tx_dma_addr[x] = pci_map_single(lp->pci_dev, skb->data, |
| 793 | skb->len, PCI_DMA_TODEVICE); |
| 794 | lp->tx_ring[x].base = (u32)le32_to_cpu(lp->tx_dma_addr[x]); |
| 795 | wmb(); /* Make sure owner changes after all others are visible */ |
| 796 | lp->tx_ring[x].status = le16_to_cpu(status); |
| 797 | } |
| 798 | } |
| 799 | |
| 800 | x = a->read_bcr(ioaddr, 32); /* set internal loopback in BSR32 */ |
| 801 | x = x | 0x0002; |
| 802 | a->write_bcr(ioaddr, 32, x); |
| 803 | |
| 804 | lp->a.write_csr (ioaddr, 15, 0x0044); /* set int loopback in CSR15 */ |
| 805 | |
| 806 | teststatus = le16_to_cpu(0x8000); |
| 807 | lp->a.write_csr(ioaddr, 0, 0x0002); /* Set STRT bit */ |
| 808 | |
| 809 | /* Check status of descriptors */ |
| 810 | for (x=0; x<numbuffs; x++) { |
| 811 | ticks = 0; |
| 812 | rmb(); |
| 813 | while ((lp->rx_ring[x].status & teststatus) && (ticks < 200)) { |
| 814 | spin_unlock_irqrestore(&lp->lock, flags); |
| 815 | mdelay(1); |
| 816 | spin_lock_irqsave(&lp->lock, flags); |
| 817 | rmb(); |
| 818 | ticks++; |
| 819 | } |
| 820 | if (ticks == 200) { |
| 821 | if (netif_msg_hw(lp)) |
| 822 | printk("%s: Desc %d failed to reset!\n",dev->name,x); |
| 823 | break; |
| 824 | } |
| 825 | } |
| 826 | |
| 827 | lp->a.write_csr(ioaddr, 0, 0x0004); /* Set STOP bit */ |
| 828 | wmb(); |
| 829 | if (netif_msg_hw(lp) && netif_msg_pktdata(lp)) { |
| 830 | printk(KERN_DEBUG "%s: RX loopback packets:\n", dev->name); |
| 831 | |
| 832 | for (x=0; x<numbuffs; x++) { |
| 833 | printk(KERN_DEBUG "%s: Packet %d:\n", dev->name, x); |
| 834 | skb = lp->rx_skbuff[x]; |
| 835 | for (i=0; i<size; i++) { |
| 836 | printk("%02x ", *(skb->data+i)); |
| 837 | } |
| 838 | printk("\n"); |
| 839 | } |
| 840 | } |
| 841 | |
| 842 | x = 0; |
| 843 | rc = 0; |
| 844 | while (x<numbuffs && !rc) { |
| 845 | skb = lp->rx_skbuff[x]; |
| 846 | packet = lp->tx_skbuff[x]->data; |
| 847 | for (i=0; i<size; i++) { |
| 848 | if (*(skb->data+i) != packet[i]) { |
| 849 | if (netif_msg_hw(lp)) |
| 850 | printk(KERN_DEBUG "%s: Error in compare! %2x - %02x %02x\n", |
| 851 | dev->name, i, *(skb->data+i), packet[i]); |
| 852 | rc = 1; |
| 853 | break; |
| 854 | } |
| 855 | } |
| 856 | x++; |
| 857 | } |
| 858 | if (!rc) { |
| 859 | *data1 = 0; |
| 860 | } |
| 861 | |
| 862 | clean_up: |
Don Fry | 1bcd315 | 2005-04-29 14:51:17 -0700 | [diff] [blame] | 863 | pcnet32_purge_tx_ring(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 864 | x = a->read_csr(ioaddr, 15) & 0xFFFF; |
| 865 | a->write_csr(ioaddr, 15, (x & ~0x0044)); /* reset bits 6 and 2 */ |
| 866 | |
| 867 | x = a->read_bcr(ioaddr, 32); /* reset internal loopback */ |
| 868 | x = x & ~0x0002; |
| 869 | a->write_bcr(ioaddr, 32, x); |
| 870 | |
| 871 | spin_unlock_irqrestore(&lp->lock, flags); |
| 872 | |
| 873 | if (netif_running(dev)) { |
| 874 | pcnet32_open(dev); |
| 875 | } else { |
| 876 | lp->a.write_bcr (ioaddr, 20, 4); /* return to 16bit mode */ |
| 877 | } |
| 878 | |
| 879 | return(rc); |
| 880 | } /* end pcnet32_loopback_test */ |
| 881 | |
| 882 | static void pcnet32_led_blink_callback(struct net_device *dev) |
| 883 | { |
| 884 | struct pcnet32_private *lp = dev->priv; |
| 885 | struct pcnet32_access *a = &lp->a; |
| 886 | ulong ioaddr = dev->base_addr; |
| 887 | unsigned long flags; |
| 888 | int i; |
| 889 | |
| 890 | spin_lock_irqsave(&lp->lock, flags); |
| 891 | for (i=4; i<8; i++) { |
| 892 | a->write_bcr(ioaddr, i, a->read_bcr(ioaddr, i) ^ 0x4000); |
| 893 | } |
| 894 | spin_unlock_irqrestore(&lp->lock, flags); |
| 895 | |
| 896 | mod_timer(&lp->blink_timer, PCNET32_BLINK_TIMEOUT); |
| 897 | } |
| 898 | |
| 899 | static int pcnet32_phys_id(struct net_device *dev, u32 data) |
| 900 | { |
| 901 | struct pcnet32_private *lp = dev->priv; |
| 902 | struct pcnet32_access *a = &lp->a; |
| 903 | ulong ioaddr = dev->base_addr; |
| 904 | unsigned long flags; |
| 905 | int i, regs[4]; |
| 906 | |
| 907 | if (!lp->blink_timer.function) { |
| 908 | init_timer(&lp->blink_timer); |
| 909 | lp->blink_timer.function = (void *) pcnet32_led_blink_callback; |
| 910 | lp->blink_timer.data = (unsigned long) dev; |
| 911 | } |
| 912 | |
| 913 | /* Save the current value of the bcrs */ |
| 914 | spin_lock_irqsave(&lp->lock, flags); |
| 915 | for (i=4; i<8; i++) { |
| 916 | regs[i-4] = a->read_bcr(ioaddr, i); |
| 917 | } |
| 918 | spin_unlock_irqrestore(&lp->lock, flags); |
| 919 | |
| 920 | mod_timer(&lp->blink_timer, jiffies); |
| 921 | set_current_state(TASK_INTERRUPTIBLE); |
| 922 | |
| 923 | if ((!data) || (data > (u32)(MAX_SCHEDULE_TIMEOUT / HZ))) |
| 924 | data = (u32)(MAX_SCHEDULE_TIMEOUT / HZ); |
| 925 | |
Nishanth Aravamudan | f17697a | 2005-06-20 23:54:12 +0200 | [diff] [blame] | 926 | msleep_interruptible(data * 1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 927 | del_timer_sync(&lp->blink_timer); |
| 928 | |
| 929 | /* Restore the original value of the bcrs */ |
| 930 | spin_lock_irqsave(&lp->lock, flags); |
| 931 | for (i=4; i<8; i++) { |
| 932 | a->write_bcr(ioaddr, i, regs[i-4]); |
| 933 | } |
| 934 | spin_unlock_irqrestore(&lp->lock, flags); |
| 935 | |
| 936 | return 0; |
| 937 | } |
| 938 | |
| 939 | static int pcnet32_get_regs_len(struct net_device *dev) |
| 940 | { |
| 941 | return(PCNET32_NUM_REGS * sizeof(u16)); |
| 942 | } |
| 943 | |
| 944 | static void pcnet32_get_regs(struct net_device *dev, struct ethtool_regs *regs, |
| 945 | void *ptr) |
| 946 | { |
| 947 | int i, csr0; |
| 948 | u16 *buff = ptr; |
| 949 | struct pcnet32_private *lp = dev->priv; |
| 950 | struct pcnet32_access *a = &lp->a; |
| 951 | ulong ioaddr = dev->base_addr; |
| 952 | int ticks; |
| 953 | unsigned long flags; |
| 954 | |
| 955 | spin_lock_irqsave(&lp->lock, flags); |
| 956 | |
| 957 | csr0 = a->read_csr(ioaddr, 0); |
| 958 | if (!(csr0 & 0x0004)) { /* If not stopped */ |
| 959 | /* set SUSPEND (SPND) - CSR5 bit 0 */ |
| 960 | a->write_csr(ioaddr, 5, 0x0001); |
| 961 | |
| 962 | /* poll waiting for bit to be set */ |
| 963 | ticks = 0; |
| 964 | while (!(a->read_csr(ioaddr, 5) & 0x0001)) { |
| 965 | spin_unlock_irqrestore(&lp->lock, flags); |
| 966 | mdelay(1); |
| 967 | spin_lock_irqsave(&lp->lock, flags); |
| 968 | ticks++; |
| 969 | if (ticks > 200) { |
| 970 | if (netif_msg_hw(lp)) |
| 971 | printk(KERN_DEBUG "%s: Error getting into suspend!\n", |
| 972 | dev->name); |
| 973 | break; |
| 974 | } |
| 975 | } |
| 976 | } |
| 977 | |
| 978 | /* read address PROM */ |
| 979 | for (i=0; i<16; i += 2) |
| 980 | *buff++ = inw(ioaddr + i); |
| 981 | |
| 982 | /* read control and status registers */ |
| 983 | for (i=0; i<90; i++) { |
| 984 | *buff++ = a->read_csr(ioaddr, i); |
| 985 | } |
| 986 | |
| 987 | *buff++ = a->read_csr(ioaddr, 112); |
| 988 | *buff++ = a->read_csr(ioaddr, 114); |
| 989 | |
| 990 | /* read bus configuration registers */ |
Don Fry | 4371dc6 | 2005-11-01 13:13:35 -0800 | [diff] [blame] | 991 | for (i=0; i<30; i++) { |
| 992 | *buff++ = a->read_bcr(ioaddr, i); |
| 993 | } |
| 994 | *buff++ = 0; /* skip bcr30 so as not to hang 79C976 */ |
| 995 | for (i=31; i<36; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 996 | *buff++ = a->read_bcr(ioaddr, i); |
| 997 | } |
| 998 | |
| 999 | /* read mii phy registers */ |
| 1000 | if (lp->mii) { |
| 1001 | for (i=0; i<32; i++) { |
| 1002 | lp->a.write_bcr(ioaddr, 33, ((lp->mii_if.phy_id) << 5) | i); |
| 1003 | *buff++ = lp->a.read_bcr(ioaddr, 34); |
| 1004 | } |
| 1005 | } |
| 1006 | |
| 1007 | if (!(csr0 & 0x0004)) { /* If not stopped */ |
| 1008 | /* clear SUSPEND (SPND) - CSR5 bit 0 */ |
| 1009 | a->write_csr(ioaddr, 5, 0x0000); |
| 1010 | } |
| 1011 | |
| 1012 | i = buff - (u16 *)ptr; |
| 1013 | for (; i < PCNET32_NUM_REGS; i++) |
| 1014 | *buff++ = 0; |
| 1015 | |
| 1016 | spin_unlock_irqrestore(&lp->lock, flags); |
| 1017 | } |
| 1018 | |
| 1019 | static struct ethtool_ops pcnet32_ethtool_ops = { |
| 1020 | .get_settings = pcnet32_get_settings, |
| 1021 | .set_settings = pcnet32_set_settings, |
| 1022 | .get_drvinfo = pcnet32_get_drvinfo, |
| 1023 | .get_msglevel = pcnet32_get_msglevel, |
| 1024 | .set_msglevel = pcnet32_set_msglevel, |
| 1025 | .nway_reset = pcnet32_nway_reset, |
| 1026 | .get_link = pcnet32_get_link, |
| 1027 | .get_ringparam = pcnet32_get_ringparam, |
Hubert WS Lin | eabf041 | 2005-09-14 11:39:25 -0700 | [diff] [blame] | 1028 | .set_ringparam = pcnet32_set_ringparam, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1029 | .get_tx_csum = ethtool_op_get_tx_csum, |
| 1030 | .get_sg = ethtool_op_get_sg, |
| 1031 | .get_tso = ethtool_op_get_tso, |
| 1032 | .get_strings = pcnet32_get_strings, |
| 1033 | .self_test_count = pcnet32_self_test_count, |
| 1034 | .self_test = pcnet32_ethtool_test, |
| 1035 | .phys_id = pcnet32_phys_id, |
| 1036 | .get_regs_len = pcnet32_get_regs_len, |
| 1037 | .get_regs = pcnet32_get_regs, |
John W. Linville | db0276b | 2005-09-12 10:48:57 -0400 | [diff] [blame] | 1038 | .get_perm_addr = ethtool_op_get_perm_addr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1039 | }; |
| 1040 | |
| 1041 | /* only probes for non-PCI devices, the rest are handled by |
| 1042 | * pci_register_driver via pcnet32_probe_pci */ |
| 1043 | |
| 1044 | static void __devinit |
| 1045 | pcnet32_probe_vlbus(void) |
| 1046 | { |
| 1047 | unsigned int *port, ioaddr; |
| 1048 | |
| 1049 | /* search for PCnet32 VLB cards at known addresses */ |
| 1050 | for (port = pcnet32_portlist; (ioaddr = *port); port++) { |
| 1051 | if (request_region(ioaddr, PCNET32_TOTAL_SIZE, "pcnet32_probe_vlbus")) { |
| 1052 | /* check if there is really a pcnet chip on that ioaddr */ |
| 1053 | if ((inb(ioaddr + 14) == 0x57) && (inb(ioaddr + 15) == 0x57)) { |
| 1054 | pcnet32_probe1(ioaddr, 0, NULL); |
| 1055 | } else { |
| 1056 | release_region(ioaddr, PCNET32_TOTAL_SIZE); |
| 1057 | } |
| 1058 | } |
| 1059 | } |
| 1060 | } |
| 1061 | |
| 1062 | |
| 1063 | static int __devinit |
| 1064 | pcnet32_probe_pci(struct pci_dev *pdev, const struct pci_device_id *ent) |
| 1065 | { |
| 1066 | unsigned long ioaddr; |
| 1067 | int err; |
| 1068 | |
| 1069 | err = pci_enable_device(pdev); |
| 1070 | if (err < 0) { |
| 1071 | if (pcnet32_debug & NETIF_MSG_PROBE) |
| 1072 | printk(KERN_ERR PFX "failed to enable device -- err=%d\n", err); |
| 1073 | return err; |
| 1074 | } |
| 1075 | pci_set_master(pdev); |
| 1076 | |
| 1077 | ioaddr = pci_resource_start (pdev, 0); |
| 1078 | if (!ioaddr) { |
| 1079 | if (pcnet32_debug & NETIF_MSG_PROBE) |
| 1080 | printk (KERN_ERR PFX "card has no PCI IO resources, aborting\n"); |
| 1081 | return -ENODEV; |
| 1082 | } |
| 1083 | |
| 1084 | if (!pci_dma_supported(pdev, PCNET32_DMA_MASK)) { |
| 1085 | if (pcnet32_debug & NETIF_MSG_PROBE) |
| 1086 | printk(KERN_ERR PFX "architecture does not support 32bit PCI busmaster DMA\n"); |
| 1087 | return -ENODEV; |
| 1088 | } |
| 1089 | if (request_region(ioaddr, PCNET32_TOTAL_SIZE, "pcnet32_probe_pci") == NULL) { |
| 1090 | if (pcnet32_debug & NETIF_MSG_PROBE) |
| 1091 | printk(KERN_ERR PFX "io address range already allocated\n"); |
| 1092 | return -EBUSY; |
| 1093 | } |
| 1094 | |
| 1095 | err = pcnet32_probe1(ioaddr, 1, pdev); |
| 1096 | if (err < 0) { |
| 1097 | pci_disable_device(pdev); |
| 1098 | } |
| 1099 | return err; |
| 1100 | } |
| 1101 | |
| 1102 | |
| 1103 | /* pcnet32_probe1 |
| 1104 | * Called from both pcnet32_probe_vlbus and pcnet_probe_pci. |
| 1105 | * pdev will be NULL when called from pcnet32_probe_vlbus. |
| 1106 | */ |
| 1107 | static int __devinit |
| 1108 | pcnet32_probe1(unsigned long ioaddr, int shared, struct pci_dev *pdev) |
| 1109 | { |
| 1110 | struct pcnet32_private *lp; |
| 1111 | dma_addr_t lp_dma_addr; |
| 1112 | int i, media; |
| 1113 | int fdx, mii, fset, dxsuflo; |
| 1114 | int chip_version; |
| 1115 | char *chipname; |
| 1116 | struct net_device *dev; |
| 1117 | struct pcnet32_access *a = NULL; |
| 1118 | u8 promaddr[6]; |
| 1119 | int ret = -ENODEV; |
| 1120 | |
| 1121 | /* reset the chip */ |
| 1122 | pcnet32_wio_reset(ioaddr); |
| 1123 | |
| 1124 | /* NOTE: 16-bit check is first, otherwise some older PCnet chips fail */ |
| 1125 | if (pcnet32_wio_read_csr(ioaddr, 0) == 4 && pcnet32_wio_check(ioaddr)) { |
| 1126 | a = &pcnet32_wio; |
| 1127 | } else { |
| 1128 | pcnet32_dwio_reset(ioaddr); |
| 1129 | if (pcnet32_dwio_read_csr(ioaddr, 0) == 4 && pcnet32_dwio_check(ioaddr)) { |
| 1130 | a = &pcnet32_dwio; |
| 1131 | } else |
| 1132 | goto err_release_region; |
| 1133 | } |
| 1134 | |
| 1135 | chip_version = a->read_csr(ioaddr, 88) | (a->read_csr(ioaddr,89) << 16); |
| 1136 | if ((pcnet32_debug & NETIF_MSG_PROBE) && (pcnet32_debug & NETIF_MSG_HW)) |
| 1137 | printk(KERN_INFO " PCnet chip version is %#x.\n", chip_version); |
| 1138 | if ((chip_version & 0xfff) != 0x003) { |
| 1139 | if (pcnet32_debug & NETIF_MSG_PROBE) |
| 1140 | printk(KERN_INFO PFX "Unsupported chip version.\n"); |
| 1141 | goto err_release_region; |
| 1142 | } |
| 1143 | |
| 1144 | /* initialize variables */ |
| 1145 | fdx = mii = fset = dxsuflo = 0; |
| 1146 | chip_version = (chip_version >> 12) & 0xffff; |
| 1147 | |
| 1148 | switch (chip_version) { |
| 1149 | case 0x2420: |
| 1150 | chipname = "PCnet/PCI 79C970"; /* PCI */ |
| 1151 | break; |
| 1152 | case 0x2430: |
| 1153 | if (shared) |
| 1154 | chipname = "PCnet/PCI 79C970"; /* 970 gives the wrong chip id back */ |
| 1155 | else |
| 1156 | chipname = "PCnet/32 79C965"; /* 486/VL bus */ |
| 1157 | break; |
| 1158 | case 0x2621: |
| 1159 | chipname = "PCnet/PCI II 79C970A"; /* PCI */ |
| 1160 | fdx = 1; |
| 1161 | break; |
| 1162 | case 0x2623: |
| 1163 | chipname = "PCnet/FAST 79C971"; /* PCI */ |
| 1164 | fdx = 1; mii = 1; fset = 1; |
| 1165 | break; |
| 1166 | case 0x2624: |
| 1167 | chipname = "PCnet/FAST+ 79C972"; /* PCI */ |
| 1168 | fdx = 1; mii = 1; fset = 1; |
| 1169 | break; |
| 1170 | case 0x2625: |
| 1171 | chipname = "PCnet/FAST III 79C973"; /* PCI */ |
| 1172 | fdx = 1; mii = 1; |
| 1173 | break; |
| 1174 | case 0x2626: |
| 1175 | chipname = "PCnet/Home 79C978"; /* PCI */ |
| 1176 | fdx = 1; |
| 1177 | /* |
| 1178 | * This is based on specs published at www.amd.com. This section |
| 1179 | * assumes that a card with a 79C978 wants to go into standard |
| 1180 | * ethernet mode. The 79C978 can also go into 1Mb HomePNA mode, |
| 1181 | * and the module option homepna=1 can select this instead. |
| 1182 | */ |
| 1183 | media = a->read_bcr(ioaddr, 49); |
| 1184 | media &= ~3; /* default to 10Mb ethernet */ |
| 1185 | if (cards_found < MAX_UNITS && homepna[cards_found]) |
| 1186 | media |= 1; /* switch to home wiring mode */ |
| 1187 | if (pcnet32_debug & NETIF_MSG_PROBE) |
| 1188 | printk(KERN_DEBUG PFX "media set to %sMbit mode.\n", |
| 1189 | (media & 1) ? "1" : "10"); |
| 1190 | a->write_bcr(ioaddr, 49, media); |
| 1191 | break; |
| 1192 | case 0x2627: |
| 1193 | chipname = "PCnet/FAST III 79C975"; /* PCI */ |
| 1194 | fdx = 1; mii = 1; |
| 1195 | break; |
| 1196 | case 0x2628: |
| 1197 | chipname = "PCnet/PRO 79C976"; |
| 1198 | fdx = 1; mii = 1; |
| 1199 | break; |
| 1200 | default: |
| 1201 | if (pcnet32_debug & NETIF_MSG_PROBE) |
| 1202 | printk(KERN_INFO PFX "PCnet version %#x, no PCnet32 chip.\n", |
| 1203 | chip_version); |
| 1204 | goto err_release_region; |
| 1205 | } |
| 1206 | |
| 1207 | /* |
| 1208 | * On selected chips turn on the BCR18:NOUFLO bit. This stops transmit |
| 1209 | * starting until the packet is loaded. Strike one for reliability, lose |
| 1210 | * one for latency - although on PCI this isnt a big loss. Older chips |
| 1211 | * have FIFO's smaller than a packet, so you can't do this. |
| 1212 | * Turn on BCR18:BurstRdEn and BCR18:BurstWrEn. |
| 1213 | */ |
| 1214 | |
| 1215 | if (fset) { |
| 1216 | a->write_bcr(ioaddr, 18, (a->read_bcr(ioaddr, 18) | 0x0860)); |
| 1217 | a->write_csr(ioaddr, 80, (a->read_csr(ioaddr, 80) & 0x0C00) | 0x0c00); |
| 1218 | dxsuflo = 1; |
| 1219 | } |
| 1220 | |
| 1221 | dev = alloc_etherdev(0); |
| 1222 | if (!dev) { |
| 1223 | if (pcnet32_debug & NETIF_MSG_PROBE) |
| 1224 | printk(KERN_ERR PFX "Memory allocation failed.\n"); |
| 1225 | ret = -ENOMEM; |
| 1226 | goto err_release_region; |
| 1227 | } |
| 1228 | SET_NETDEV_DEV(dev, &pdev->dev); |
| 1229 | |
| 1230 | if (pcnet32_debug & NETIF_MSG_PROBE) |
| 1231 | printk(KERN_INFO PFX "%s at %#3lx,", chipname, ioaddr); |
| 1232 | |
| 1233 | /* In most chips, after a chip reset, the ethernet address is read from the |
| 1234 | * station address PROM at the base address and programmed into the |
| 1235 | * "Physical Address Registers" CSR12-14. |
| 1236 | * As a precautionary measure, we read the PROM values and complain if |
| 1237 | * they disagree with the CSRs. Either way, we use the CSR values, and |
| 1238 | * double check that they are valid. |
| 1239 | */ |
| 1240 | for (i = 0; i < 3; i++) { |
| 1241 | unsigned int val; |
| 1242 | val = a->read_csr(ioaddr, i+12) & 0x0ffff; |
| 1243 | /* There may be endianness issues here. */ |
| 1244 | dev->dev_addr[2*i] = val & 0x0ff; |
| 1245 | dev->dev_addr[2*i+1] = (val >> 8) & 0x0ff; |
| 1246 | } |
| 1247 | |
| 1248 | /* read PROM address and compare with CSR address */ |
| 1249 | for (i = 0; i < 6; i++) |
| 1250 | promaddr[i] = inb(ioaddr + i); |
| 1251 | |
| 1252 | if (memcmp(promaddr, dev->dev_addr, 6) |
| 1253 | || !is_valid_ether_addr(dev->dev_addr)) { |
| 1254 | #ifndef __powerpc__ |
| 1255 | if (is_valid_ether_addr(promaddr)) { |
| 1256 | #else |
| 1257 | if (!is_valid_ether_addr(dev->dev_addr) |
| 1258 | && is_valid_ether_addr(promaddr)) { |
| 1259 | #endif |
| 1260 | if (pcnet32_debug & NETIF_MSG_PROBE) { |
| 1261 | printk(" warning: CSR address invalid,\n"); |
| 1262 | printk(KERN_INFO " using instead PROM address of"); |
| 1263 | } |
| 1264 | memcpy(dev->dev_addr, promaddr, 6); |
| 1265 | } |
| 1266 | } |
John W. Linville | db0276b | 2005-09-12 10:48:57 -0400 | [diff] [blame] | 1267 | memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1268 | |
| 1269 | /* if the ethernet address is not valid, force to 00:00:00:00:00:00 */ |
John W. Linville | db0276b | 2005-09-12 10:48:57 -0400 | [diff] [blame] | 1270 | if (!is_valid_ether_addr(dev->perm_addr)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1271 | memset(dev->dev_addr, 0, sizeof(dev->dev_addr)); |
| 1272 | |
| 1273 | if (pcnet32_debug & NETIF_MSG_PROBE) { |
| 1274 | for (i = 0; i < 6; i++) |
| 1275 | printk(" %2.2x", dev->dev_addr[i]); |
| 1276 | |
| 1277 | /* Version 0x2623 and 0x2624 */ |
| 1278 | if (((chip_version + 1) & 0xfffe) == 0x2624) { |
| 1279 | i = a->read_csr(ioaddr, 80) & 0x0C00; /* Check tx_start_pt */ |
| 1280 | printk("\n" KERN_INFO " tx_start_pt(0x%04x):",i); |
| 1281 | switch(i>>10) { |
| 1282 | case 0: printk(" 20 bytes,"); break; |
| 1283 | case 1: printk(" 64 bytes,"); break; |
| 1284 | case 2: printk(" 128 bytes,"); break; |
| 1285 | case 3: printk("~220 bytes,"); break; |
| 1286 | } |
| 1287 | i = a->read_bcr(ioaddr, 18); /* Check Burst/Bus control */ |
| 1288 | printk(" BCR18(%x):",i&0xffff); |
| 1289 | if (i & (1<<5)) printk("BurstWrEn "); |
| 1290 | if (i & (1<<6)) printk("BurstRdEn "); |
| 1291 | if (i & (1<<7)) printk("DWordIO "); |
| 1292 | if (i & (1<<11)) printk("NoUFlow "); |
| 1293 | i = a->read_bcr(ioaddr, 25); |
| 1294 | printk("\n" KERN_INFO " SRAMSIZE=0x%04x,",i<<8); |
| 1295 | i = a->read_bcr(ioaddr, 26); |
| 1296 | printk(" SRAM_BND=0x%04x,",i<<8); |
| 1297 | i = a->read_bcr(ioaddr, 27); |
| 1298 | if (i & (1<<14)) printk("LowLatRx"); |
| 1299 | } |
| 1300 | } |
| 1301 | |
| 1302 | dev->base_addr = ioaddr; |
| 1303 | /* pci_alloc_consistent returns page-aligned memory, so we do not have to check the alignment */ |
| 1304 | if ((lp = pci_alloc_consistent(pdev, sizeof(*lp), &lp_dma_addr)) == NULL) { |
| 1305 | if (pcnet32_debug & NETIF_MSG_PROBE) |
| 1306 | printk(KERN_ERR PFX "Consistent memory allocation failed.\n"); |
| 1307 | ret = -ENOMEM; |
| 1308 | goto err_free_netdev; |
| 1309 | } |
| 1310 | |
| 1311 | memset(lp, 0, sizeof(*lp)); |
| 1312 | lp->dma_addr = lp_dma_addr; |
| 1313 | lp->pci_dev = pdev; |
| 1314 | |
| 1315 | spin_lock_init(&lp->lock); |
| 1316 | |
| 1317 | SET_MODULE_OWNER(dev); |
| 1318 | SET_NETDEV_DEV(dev, &pdev->dev); |
| 1319 | dev->priv = lp; |
| 1320 | lp->name = chipname; |
| 1321 | lp->shared_irq = shared; |
Hubert WS Lin | eabf041 | 2005-09-14 11:39:25 -0700 | [diff] [blame] | 1322 | lp->tx_ring_size = TX_RING_SIZE; /* default tx ring size */ |
| 1323 | lp->rx_ring_size = RX_RING_SIZE; /* default rx ring size */ |
| 1324 | lp->tx_mod_mask = lp->tx_ring_size - 1; |
| 1325 | lp->rx_mod_mask = lp->rx_ring_size - 1; |
| 1326 | lp->tx_len_bits = (PCNET32_LOG_TX_BUFFERS << 12); |
| 1327 | lp->rx_len_bits = (PCNET32_LOG_RX_BUFFERS << 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1328 | lp->mii_if.full_duplex = fdx; |
| 1329 | lp->mii_if.phy_id_mask = 0x1f; |
| 1330 | lp->mii_if.reg_num_mask = 0x1f; |
| 1331 | lp->dxsuflo = dxsuflo; |
| 1332 | lp->mii = mii; |
| 1333 | lp->msg_enable = pcnet32_debug; |
| 1334 | if ((cards_found >= MAX_UNITS) || (options[cards_found] > sizeof(options_mapping))) |
| 1335 | lp->options = PCNET32_PORT_ASEL; |
| 1336 | else |
| 1337 | lp->options = options_mapping[options[cards_found]]; |
| 1338 | lp->mii_if.dev = dev; |
| 1339 | lp->mii_if.mdio_read = mdio_read; |
| 1340 | lp->mii_if.mdio_write = mdio_write; |
| 1341 | |
| 1342 | if (fdx && !(lp->options & PCNET32_PORT_ASEL) && |
| 1343 | ((cards_found>=MAX_UNITS) || full_duplex[cards_found])) |
| 1344 | lp->options |= PCNET32_PORT_FD; |
| 1345 | |
| 1346 | if (!a) { |
| 1347 | if (pcnet32_debug & NETIF_MSG_PROBE) |
| 1348 | printk(KERN_ERR PFX "No access methods\n"); |
| 1349 | ret = -ENODEV; |
| 1350 | goto err_free_consistent; |
| 1351 | } |
| 1352 | lp->a = *a; |
| 1353 | |
Don Fry | a88c844 | 2005-11-01 12:04:33 -0800 | [diff] [blame] | 1354 | /* prior to register_netdev, dev->name is not yet correct */ |
| 1355 | if (pcnet32_alloc_ring(dev, pci_name(lp->pci_dev))) { |
Hubert WS Lin | eabf041 | 2005-09-14 11:39:25 -0700 | [diff] [blame] | 1356 | ret = -ENOMEM; |
| 1357 | goto err_free_ring; |
| 1358 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1359 | /* detect special T1/E1 WAN card by checking for MAC address */ |
| 1360 | if (dev->dev_addr[0] == 0x00 && dev->dev_addr[1] == 0xe0 |
| 1361 | && dev->dev_addr[2] == 0x75) |
| 1362 | lp->options = PCNET32_PORT_FD | PCNET32_PORT_GPSI; |
| 1363 | |
| 1364 | lp->init_block.mode = le16_to_cpu(0x0003); /* Disable Rx and Tx. */ |
Hubert WS Lin | eabf041 | 2005-09-14 11:39:25 -0700 | [diff] [blame] | 1365 | lp->init_block.tlen_rlen = le16_to_cpu(lp->tx_len_bits | lp->rx_len_bits); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1366 | for (i = 0; i < 6; i++) |
| 1367 | lp->init_block.phys_addr[i] = dev->dev_addr[i]; |
| 1368 | lp->init_block.filter[0] = 0x00000000; |
| 1369 | lp->init_block.filter[1] = 0x00000000; |
Hubert WS Lin | eabf041 | 2005-09-14 11:39:25 -0700 | [diff] [blame] | 1370 | lp->init_block.rx_ring = (u32)le32_to_cpu(lp->rx_ring_dma_addr); |
| 1371 | lp->init_block.tx_ring = (u32)le32_to_cpu(lp->tx_ring_dma_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1372 | |
| 1373 | /* switch pcnet32 to 32bit mode */ |
| 1374 | a->write_bcr(ioaddr, 20, 2); |
| 1375 | |
| 1376 | a->write_csr(ioaddr, 1, (lp->dma_addr + offsetof(struct pcnet32_private, |
| 1377 | init_block)) & 0xffff); |
| 1378 | a->write_csr(ioaddr, 2, (lp->dma_addr + offsetof(struct pcnet32_private, |
| 1379 | init_block)) >> 16); |
| 1380 | |
| 1381 | if (pdev) { /* use the IRQ provided by PCI */ |
| 1382 | dev->irq = pdev->irq; |
| 1383 | if (pcnet32_debug & NETIF_MSG_PROBE) |
| 1384 | printk(" assigned IRQ %d.\n", dev->irq); |
| 1385 | } else { |
| 1386 | unsigned long irq_mask = probe_irq_on(); |
| 1387 | |
| 1388 | /* |
| 1389 | * To auto-IRQ we enable the initialization-done and DMA error |
| 1390 | * interrupts. For ISA boards we get a DMA error, but VLB and PCI |
| 1391 | * boards will work. |
| 1392 | */ |
| 1393 | /* Trigger an initialization just for the interrupt. */ |
| 1394 | a->write_csr (ioaddr, 0, 0x41); |
| 1395 | mdelay (1); |
| 1396 | |
| 1397 | dev->irq = probe_irq_off (irq_mask); |
| 1398 | if (!dev->irq) { |
| 1399 | if (pcnet32_debug & NETIF_MSG_PROBE) |
| 1400 | printk(", failed to detect IRQ line.\n"); |
| 1401 | ret = -ENODEV; |
Hubert WS Lin | eabf041 | 2005-09-14 11:39:25 -0700 | [diff] [blame] | 1402 | goto err_free_ring; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1403 | } |
| 1404 | if (pcnet32_debug & NETIF_MSG_PROBE) |
| 1405 | printk(", probed IRQ %d.\n", dev->irq); |
| 1406 | } |
| 1407 | |
| 1408 | /* Set the mii phy_id so that we can query the link state */ |
| 1409 | if (lp->mii) |
| 1410 | lp->mii_if.phy_id = ((lp->a.read_bcr (ioaddr, 33)) >> 5) & 0x1f; |
| 1411 | |
| 1412 | init_timer (&lp->watchdog_timer); |
| 1413 | lp->watchdog_timer.data = (unsigned long) dev; |
| 1414 | lp->watchdog_timer.function = (void *) &pcnet32_watchdog; |
| 1415 | |
| 1416 | /* The PCNET32-specific entries in the device structure. */ |
| 1417 | dev->open = &pcnet32_open; |
| 1418 | dev->hard_start_xmit = &pcnet32_start_xmit; |
| 1419 | dev->stop = &pcnet32_close; |
| 1420 | dev->get_stats = &pcnet32_get_stats; |
| 1421 | dev->set_multicast_list = &pcnet32_set_multicast_list; |
| 1422 | dev->do_ioctl = &pcnet32_ioctl; |
| 1423 | dev->ethtool_ops = &pcnet32_ethtool_ops; |
| 1424 | dev->tx_timeout = pcnet32_tx_timeout; |
| 1425 | dev->watchdog_timeo = (5*HZ); |
| 1426 | |
| 1427 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 1428 | dev->poll_controller = pcnet32_poll_controller; |
| 1429 | #endif |
| 1430 | |
| 1431 | /* Fill in the generic fields of the device structure. */ |
| 1432 | if (register_netdev(dev)) |
Hubert WS Lin | eabf041 | 2005-09-14 11:39:25 -0700 | [diff] [blame] | 1433 | goto err_free_ring; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1434 | |
| 1435 | if (pdev) { |
| 1436 | pci_set_drvdata(pdev, dev); |
| 1437 | } else { |
| 1438 | lp->next = pcnet32_dev; |
| 1439 | pcnet32_dev = dev; |
| 1440 | } |
| 1441 | |
| 1442 | if (pcnet32_debug & NETIF_MSG_PROBE) |
| 1443 | printk(KERN_INFO "%s: registered as %s\n", dev->name, lp->name); |
| 1444 | cards_found++; |
| 1445 | |
| 1446 | /* enable LED writes */ |
| 1447 | a->write_bcr(ioaddr, 2, a->read_bcr(ioaddr, 2) | 0x1000); |
| 1448 | |
| 1449 | return 0; |
| 1450 | |
Hubert WS Lin | eabf041 | 2005-09-14 11:39:25 -0700 | [diff] [blame] | 1451 | err_free_ring: |
| 1452 | pcnet32_free_ring(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1453 | err_free_consistent: |
| 1454 | pci_free_consistent(lp->pci_dev, sizeof(*lp), lp, lp->dma_addr); |
| 1455 | err_free_netdev: |
| 1456 | free_netdev(dev); |
| 1457 | err_release_region: |
| 1458 | release_region(ioaddr, PCNET32_TOTAL_SIZE); |
| 1459 | return ret; |
| 1460 | } |
| 1461 | |
| 1462 | |
Don Fry | a88c844 | 2005-11-01 12:04:33 -0800 | [diff] [blame] | 1463 | /* if any allocation fails, caller must also call pcnet32_free_ring */ |
| 1464 | static int pcnet32_alloc_ring(struct net_device *dev, char *name) |
Hubert WS Lin | eabf041 | 2005-09-14 11:39:25 -0700 | [diff] [blame] | 1465 | { |
| 1466 | struct pcnet32_private *lp = dev->priv; |
| 1467 | |
Don Fry | a88c844 | 2005-11-01 12:04:33 -0800 | [diff] [blame] | 1468 | lp->tx_ring = pci_alloc_consistent(lp->pci_dev, |
| 1469 | sizeof(struct pcnet32_tx_head) * lp->tx_ring_size, |
| 1470 | &lp->tx_ring_dma_addr); |
| 1471 | if (lp->tx_ring == NULL) { |
Hubert WS Lin | eabf041 | 2005-09-14 11:39:25 -0700 | [diff] [blame] | 1472 | if (pcnet32_debug & NETIF_MSG_DRV) |
Don Fry | a88c844 | 2005-11-01 12:04:33 -0800 | [diff] [blame] | 1473 | printk("\n" KERN_ERR PFX "%s: Consistent memory allocation failed.\n", |
| 1474 | name); |
Hubert WS Lin | eabf041 | 2005-09-14 11:39:25 -0700 | [diff] [blame] | 1475 | return -ENOMEM; |
| 1476 | } |
| 1477 | |
Don Fry | a88c844 | 2005-11-01 12:04:33 -0800 | [diff] [blame] | 1478 | lp->rx_ring = pci_alloc_consistent(lp->pci_dev, |
| 1479 | sizeof(struct pcnet32_rx_head) * lp->rx_ring_size, |
| 1480 | &lp->rx_ring_dma_addr); |
| 1481 | if (lp->rx_ring == NULL) { |
Hubert WS Lin | eabf041 | 2005-09-14 11:39:25 -0700 | [diff] [blame] | 1482 | if (pcnet32_debug & NETIF_MSG_DRV) |
Don Fry | a88c844 | 2005-11-01 12:04:33 -0800 | [diff] [blame] | 1483 | printk("\n" KERN_ERR PFX "%s: Consistent memory allocation failed.\n", |
| 1484 | name); |
Hubert WS Lin | eabf041 | 2005-09-14 11:39:25 -0700 | [diff] [blame] | 1485 | return -ENOMEM; |
| 1486 | } |
| 1487 | |
Don Fry | a88c844 | 2005-11-01 12:04:33 -0800 | [diff] [blame] | 1488 | lp->tx_dma_addr = kmalloc(sizeof(dma_addr_t) * lp->tx_ring_size, |
| 1489 | GFP_ATOMIC); |
| 1490 | if (!lp->tx_dma_addr) { |
Hubert WS Lin | eabf041 | 2005-09-14 11:39:25 -0700 | [diff] [blame] | 1491 | if (pcnet32_debug & NETIF_MSG_DRV) |
Don Fry | a88c844 | 2005-11-01 12:04:33 -0800 | [diff] [blame] | 1492 | printk("\n" KERN_ERR PFX "%s: Memory allocation failed.\n", name); |
Hubert WS Lin | eabf041 | 2005-09-14 11:39:25 -0700 | [diff] [blame] | 1493 | return -ENOMEM; |
| 1494 | } |
| 1495 | memset(lp->tx_dma_addr, 0, sizeof(dma_addr_t) * lp->tx_ring_size); |
| 1496 | |
Don Fry | a88c844 | 2005-11-01 12:04:33 -0800 | [diff] [blame] | 1497 | lp->rx_dma_addr = kmalloc(sizeof(dma_addr_t) * lp->rx_ring_size, |
| 1498 | GFP_ATOMIC); |
| 1499 | if (!lp->rx_dma_addr) { |
Hubert WS Lin | eabf041 | 2005-09-14 11:39:25 -0700 | [diff] [blame] | 1500 | if (pcnet32_debug & NETIF_MSG_DRV) |
Don Fry | a88c844 | 2005-11-01 12:04:33 -0800 | [diff] [blame] | 1501 | printk("\n" KERN_ERR PFX "%s: Memory allocation failed.\n", name); |
Hubert WS Lin | eabf041 | 2005-09-14 11:39:25 -0700 | [diff] [blame] | 1502 | return -ENOMEM; |
| 1503 | } |
| 1504 | memset(lp->rx_dma_addr, 0, sizeof(dma_addr_t) * lp->rx_ring_size); |
| 1505 | |
Don Fry | a88c844 | 2005-11-01 12:04:33 -0800 | [diff] [blame] | 1506 | lp->tx_skbuff = kmalloc(sizeof(struct sk_buff *) * lp->tx_ring_size, |
| 1507 | GFP_ATOMIC); |
| 1508 | if (!lp->tx_skbuff) { |
Hubert WS Lin | eabf041 | 2005-09-14 11:39:25 -0700 | [diff] [blame] | 1509 | if (pcnet32_debug & NETIF_MSG_DRV) |
Don Fry | a88c844 | 2005-11-01 12:04:33 -0800 | [diff] [blame] | 1510 | printk("\n" KERN_ERR PFX "%s: Memory allocation failed.\n", name); |
Hubert WS Lin | eabf041 | 2005-09-14 11:39:25 -0700 | [diff] [blame] | 1511 | return -ENOMEM; |
| 1512 | } |
| 1513 | memset(lp->tx_skbuff, 0, sizeof(struct sk_buff *) * lp->tx_ring_size); |
| 1514 | |
Don Fry | a88c844 | 2005-11-01 12:04:33 -0800 | [diff] [blame] | 1515 | lp->rx_skbuff = kmalloc(sizeof(struct sk_buff *) * lp->rx_ring_size, |
| 1516 | GFP_ATOMIC); |
| 1517 | if (!lp->rx_skbuff) { |
Hubert WS Lin | eabf041 | 2005-09-14 11:39:25 -0700 | [diff] [blame] | 1518 | if (pcnet32_debug & NETIF_MSG_DRV) |
Don Fry | a88c844 | 2005-11-01 12:04:33 -0800 | [diff] [blame] | 1519 | printk("\n" KERN_ERR PFX "%s: Memory allocation failed.\n", name); |
Hubert WS Lin | eabf041 | 2005-09-14 11:39:25 -0700 | [diff] [blame] | 1520 | return -ENOMEM; |
| 1521 | } |
| 1522 | memset(lp->rx_skbuff, 0, sizeof(struct sk_buff *) * lp->rx_ring_size); |
| 1523 | |
| 1524 | return 0; |
| 1525 | } |
| 1526 | |
| 1527 | |
| 1528 | static void pcnet32_free_ring(struct net_device *dev) |
| 1529 | { |
| 1530 | struct pcnet32_private *lp = dev->priv; |
| 1531 | |
| 1532 | kfree(lp->tx_skbuff); |
| 1533 | lp->tx_skbuff = NULL; |
| 1534 | |
| 1535 | kfree(lp->rx_skbuff); |
| 1536 | lp->rx_skbuff = NULL; |
| 1537 | |
| 1538 | kfree(lp->tx_dma_addr); |
| 1539 | lp->tx_dma_addr = NULL; |
| 1540 | |
| 1541 | kfree(lp->rx_dma_addr); |
| 1542 | lp->rx_dma_addr = NULL; |
| 1543 | |
| 1544 | if (lp->tx_ring) { |
| 1545 | pci_free_consistent(lp->pci_dev, sizeof(struct pcnet32_tx_head) * lp->tx_ring_size, |
| 1546 | lp->tx_ring, lp->tx_ring_dma_addr); |
| 1547 | lp->tx_ring = NULL; |
| 1548 | } |
| 1549 | |
| 1550 | if (lp->rx_ring) { |
| 1551 | pci_free_consistent(lp->pci_dev, sizeof(struct pcnet32_rx_head) * lp->rx_ring_size, |
| 1552 | lp->rx_ring, lp->rx_ring_dma_addr); |
| 1553 | lp->rx_ring = NULL; |
| 1554 | } |
| 1555 | } |
| 1556 | |
| 1557 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1558 | static int |
| 1559 | pcnet32_open(struct net_device *dev) |
| 1560 | { |
| 1561 | struct pcnet32_private *lp = dev->priv; |
| 1562 | unsigned long ioaddr = dev->base_addr; |
| 1563 | u16 val; |
| 1564 | int i; |
| 1565 | int rc; |
| 1566 | unsigned long flags; |
| 1567 | |
| 1568 | if (request_irq(dev->irq, &pcnet32_interrupt, |
| 1569 | lp->shared_irq ? SA_SHIRQ : 0, dev->name, (void *)dev)) { |
| 1570 | return -EAGAIN; |
| 1571 | } |
| 1572 | |
| 1573 | spin_lock_irqsave(&lp->lock, flags); |
| 1574 | /* Check for a valid station address */ |
| 1575 | if (!is_valid_ether_addr(dev->dev_addr)) { |
| 1576 | rc = -EINVAL; |
| 1577 | goto err_free_irq; |
| 1578 | } |
| 1579 | |
| 1580 | /* Reset the PCNET32 */ |
| 1581 | lp->a.reset (ioaddr); |
| 1582 | |
| 1583 | /* switch pcnet32 to 32bit mode */ |
| 1584 | lp->a.write_bcr (ioaddr, 20, 2); |
| 1585 | |
| 1586 | if (netif_msg_ifup(lp)) |
| 1587 | printk(KERN_DEBUG "%s: pcnet32_open() irq %d tx/rx rings %#x/%#x init %#x.\n", |
| 1588 | dev->name, dev->irq, |
Hubert WS Lin | eabf041 | 2005-09-14 11:39:25 -0700 | [diff] [blame] | 1589 | (u32) (lp->tx_ring_dma_addr), |
| 1590 | (u32) (lp->rx_ring_dma_addr), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1591 | (u32) (lp->dma_addr + offsetof(struct pcnet32_private, init_block))); |
| 1592 | |
| 1593 | /* set/reset autoselect bit */ |
| 1594 | val = lp->a.read_bcr (ioaddr, 2) & ~2; |
| 1595 | if (lp->options & PCNET32_PORT_ASEL) |
| 1596 | val |= 2; |
| 1597 | lp->a.write_bcr (ioaddr, 2, val); |
| 1598 | |
| 1599 | /* handle full duplex setting */ |
| 1600 | if (lp->mii_if.full_duplex) { |
| 1601 | val = lp->a.read_bcr (ioaddr, 9) & ~3; |
| 1602 | if (lp->options & PCNET32_PORT_FD) { |
| 1603 | val |= 1; |
| 1604 | if (lp->options == (PCNET32_PORT_FD | PCNET32_PORT_AUI)) |
| 1605 | val |= 2; |
| 1606 | } else if (lp->options & PCNET32_PORT_ASEL) { |
| 1607 | /* workaround of xSeries250, turn on for 79C975 only */ |
| 1608 | i = ((lp->a.read_csr(ioaddr, 88) | |
| 1609 | (lp->a.read_csr(ioaddr,89) << 16)) >> 12) & 0xffff; |
| 1610 | if (i == 0x2627) |
| 1611 | val |= 3; |
| 1612 | } |
| 1613 | lp->a.write_bcr (ioaddr, 9, val); |
| 1614 | } |
| 1615 | |
| 1616 | /* set/reset GPSI bit in test register */ |
| 1617 | val = lp->a.read_csr (ioaddr, 124) & ~0x10; |
| 1618 | if ((lp->options & PCNET32_PORT_PORTSEL) == PCNET32_PORT_GPSI) |
| 1619 | val |= 0x10; |
| 1620 | lp->a.write_csr (ioaddr, 124, val); |
| 1621 | |
Don Fry | 2964bbd | 2005-11-01 12:50:57 -0800 | [diff] [blame] | 1622 | /* Allied Telesyn AT 2700/2701 FX are 100Mbit only and do not negotiate */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1623 | if (lp->pci_dev->subsystem_vendor == PCI_VENDOR_ID_AT && |
Don Fry | 2964bbd | 2005-11-01 12:50:57 -0800 | [diff] [blame] | 1624 | (lp->pci_dev->subsystem_device == PCI_SUBDEVICE_ID_AT_2700FX || |
| 1625 | lp->pci_dev->subsystem_device == PCI_SUBDEVICE_ID_AT_2701FX)) { |
| 1626 | if (lp->options & PCNET32_PORT_ASEL) { |
| 1627 | lp->options = PCNET32_PORT_FD | PCNET32_PORT_100; |
| 1628 | if (netif_msg_link(lp)) |
| 1629 | printk(KERN_DEBUG "%s: Setting 100Mb-Full Duplex.\n", |
| 1630 | dev->name); |
| 1631 | } |
| 1632 | } |
| 1633 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1634 | /* |
| 1635 | * 24 Jun 2004 according AMD, in order to change the PHY, |
| 1636 | * DANAS (or DISPM for 79C976) must be set; then select the speed, |
| 1637 | * duplex, and/or enable auto negotiation, and clear DANAS |
| 1638 | */ |
| 1639 | if (lp->mii && !(lp->options & PCNET32_PORT_ASEL)) { |
| 1640 | lp->a.write_bcr(ioaddr, 32, |
| 1641 | lp->a.read_bcr(ioaddr, 32) | 0x0080); |
| 1642 | /* disable Auto Negotiation, set 10Mpbs, HD */ |
| 1643 | val = lp->a.read_bcr(ioaddr, 32) & ~0xb8; |
| 1644 | if (lp->options & PCNET32_PORT_FD) |
| 1645 | val |= 0x10; |
| 1646 | if (lp->options & PCNET32_PORT_100) |
| 1647 | val |= 0x08; |
| 1648 | lp->a.write_bcr (ioaddr, 32, val); |
| 1649 | } else { |
| 1650 | if (lp->options & PCNET32_PORT_ASEL) { |
| 1651 | lp->a.write_bcr(ioaddr, 32, |
| 1652 | lp->a.read_bcr(ioaddr, 32) | 0x0080); |
| 1653 | /* enable auto negotiate, setup, disable fd */ |
| 1654 | val = lp->a.read_bcr(ioaddr, 32) & ~0x98; |
| 1655 | val |= 0x20; |
| 1656 | lp->a.write_bcr(ioaddr, 32, val); |
| 1657 | } |
| 1658 | } |
| 1659 | } |
| 1660 | |
| 1661 | #ifdef DO_DXSUFLO |
| 1662 | if (lp->dxsuflo) { /* Disable transmit stop on underflow */ |
| 1663 | val = lp->a.read_csr (ioaddr, 3); |
| 1664 | val |= 0x40; |
| 1665 | lp->a.write_csr (ioaddr, 3, val); |
| 1666 | } |
| 1667 | #endif |
| 1668 | |
| 1669 | lp->init_block.mode = le16_to_cpu((lp->options & PCNET32_PORT_PORTSEL) << 7); |
| 1670 | pcnet32_load_multicast(dev); |
| 1671 | |
| 1672 | if (pcnet32_init_ring(dev)) { |
| 1673 | rc = -ENOMEM; |
| 1674 | goto err_free_ring; |
| 1675 | } |
| 1676 | |
| 1677 | /* Re-initialize the PCNET32, and start it when done. */ |
| 1678 | lp->a.write_csr (ioaddr, 1, (lp->dma_addr + |
| 1679 | offsetof(struct pcnet32_private, init_block)) & 0xffff); |
| 1680 | lp->a.write_csr (ioaddr, 2, (lp->dma_addr + |
| 1681 | offsetof(struct pcnet32_private, init_block)) >> 16); |
| 1682 | |
| 1683 | lp->a.write_csr (ioaddr, 4, 0x0915); |
| 1684 | lp->a.write_csr (ioaddr, 0, 0x0001); |
| 1685 | |
| 1686 | netif_start_queue(dev); |
| 1687 | |
| 1688 | /* If we have mii, print the link status and start the watchdog */ |
| 1689 | if (lp->mii) { |
| 1690 | mii_check_media (&lp->mii_if, netif_msg_link(lp), 1); |
| 1691 | mod_timer (&(lp->watchdog_timer), PCNET32_WATCHDOG_TIMEOUT); |
| 1692 | } |
| 1693 | |
| 1694 | i = 0; |
| 1695 | while (i++ < 100) |
| 1696 | if (lp->a.read_csr (ioaddr, 0) & 0x0100) |
| 1697 | break; |
| 1698 | /* |
| 1699 | * We used to clear the InitDone bit, 0x0100, here but Mark Stockton |
| 1700 | * reports that doing so triggers a bug in the '974. |
| 1701 | */ |
| 1702 | lp->a.write_csr (ioaddr, 0, 0x0042); |
| 1703 | |
| 1704 | if (netif_msg_ifup(lp)) |
| 1705 | printk(KERN_DEBUG "%s: pcnet32 open after %d ticks, init block %#x csr0 %4.4x.\n", |
| 1706 | dev->name, i, (u32) (lp->dma_addr + |
| 1707 | offsetof(struct pcnet32_private, init_block)), |
| 1708 | lp->a.read_csr(ioaddr, 0)); |
| 1709 | |
| 1710 | spin_unlock_irqrestore(&lp->lock, flags); |
| 1711 | |
| 1712 | return 0; /* Always succeed */ |
| 1713 | |
| 1714 | err_free_ring: |
| 1715 | /* free any allocated skbuffs */ |
Hubert WS Lin | eabf041 | 2005-09-14 11:39:25 -0700 | [diff] [blame] | 1716 | for (i = 0; i < lp->rx_ring_size; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1717 | lp->rx_ring[i].status = 0; |
| 1718 | if (lp->rx_skbuff[i]) { |
| 1719 | pci_unmap_single(lp->pci_dev, lp->rx_dma_addr[i], PKT_BUF_SZ-2, |
| 1720 | PCI_DMA_FROMDEVICE); |
| 1721 | dev_kfree_skb(lp->rx_skbuff[i]); |
| 1722 | } |
| 1723 | lp->rx_skbuff[i] = NULL; |
| 1724 | lp->rx_dma_addr[i] = 0; |
| 1725 | } |
Hubert WS Lin | eabf041 | 2005-09-14 11:39:25 -0700 | [diff] [blame] | 1726 | |
| 1727 | pcnet32_free_ring(dev); |
| 1728 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1729 | /* |
| 1730 | * Switch back to 16bit mode to avoid problems with dumb |
| 1731 | * DOS packet driver after a warm reboot |
| 1732 | */ |
| 1733 | lp->a.write_bcr (ioaddr, 20, 4); |
| 1734 | |
| 1735 | err_free_irq: |
| 1736 | spin_unlock_irqrestore(&lp->lock, flags); |
| 1737 | free_irq(dev->irq, dev); |
| 1738 | return rc; |
| 1739 | } |
| 1740 | |
| 1741 | /* |
| 1742 | * The LANCE has been halted for one reason or another (busmaster memory |
| 1743 | * arbitration error, Tx FIFO underflow, driver stopped it to reconfigure, |
| 1744 | * etc.). Modern LANCE variants always reload their ring-buffer |
| 1745 | * configuration when restarted, so we must reinitialize our ring |
| 1746 | * context before restarting. As part of this reinitialization, |
| 1747 | * find all packets still on the Tx ring and pretend that they had been |
| 1748 | * sent (in effect, drop the packets on the floor) - the higher-level |
| 1749 | * protocols will time out and retransmit. It'd be better to shuffle |
| 1750 | * these skbs to a temp list and then actually re-Tx them after |
| 1751 | * restarting the chip, but I'm too lazy to do so right now. dplatt@3do.com |
| 1752 | */ |
| 1753 | |
| 1754 | static void |
| 1755 | pcnet32_purge_tx_ring(struct net_device *dev) |
| 1756 | { |
| 1757 | struct pcnet32_private *lp = dev->priv; |
| 1758 | int i; |
| 1759 | |
Hubert WS Lin | eabf041 | 2005-09-14 11:39:25 -0700 | [diff] [blame] | 1760 | for (i = 0; i < lp->tx_ring_size; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1761 | lp->tx_ring[i].status = 0; /* CPU owns buffer */ |
| 1762 | wmb(); /* Make sure adapter sees owner change */ |
| 1763 | if (lp->tx_skbuff[i]) { |
| 1764 | pci_unmap_single(lp->pci_dev, lp->tx_dma_addr[i], |
| 1765 | lp->tx_skbuff[i]->len, PCI_DMA_TODEVICE); |
| 1766 | dev_kfree_skb_any(lp->tx_skbuff[i]); |
| 1767 | } |
| 1768 | lp->tx_skbuff[i] = NULL; |
| 1769 | lp->tx_dma_addr[i] = 0; |
| 1770 | } |
| 1771 | } |
| 1772 | |
| 1773 | |
| 1774 | /* Initialize the PCNET32 Rx and Tx rings. */ |
| 1775 | static int |
| 1776 | pcnet32_init_ring(struct net_device *dev) |
| 1777 | { |
| 1778 | struct pcnet32_private *lp = dev->priv; |
| 1779 | int i; |
| 1780 | |
| 1781 | lp->tx_full = 0; |
| 1782 | lp->cur_rx = lp->cur_tx = 0; |
| 1783 | lp->dirty_rx = lp->dirty_tx = 0; |
| 1784 | |
Hubert WS Lin | eabf041 | 2005-09-14 11:39:25 -0700 | [diff] [blame] | 1785 | for (i = 0; i < lp->rx_ring_size; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1786 | struct sk_buff *rx_skbuff = lp->rx_skbuff[i]; |
| 1787 | if (rx_skbuff == NULL) { |
| 1788 | if (!(rx_skbuff = lp->rx_skbuff[i] = dev_alloc_skb (PKT_BUF_SZ))) { |
| 1789 | /* there is not much, we can do at this point */ |
| 1790 | if (pcnet32_debug & NETIF_MSG_DRV) |
| 1791 | printk(KERN_ERR "%s: pcnet32_init_ring dev_alloc_skb failed.\n", |
| 1792 | dev->name); |
| 1793 | return -1; |
| 1794 | } |
| 1795 | skb_reserve (rx_skbuff, 2); |
| 1796 | } |
| 1797 | |
| 1798 | rmb(); |
| 1799 | if (lp->rx_dma_addr[i] == 0) |
David S. Miller | 689be43 | 2005-06-28 15:25:31 -0700 | [diff] [blame] | 1800 | lp->rx_dma_addr[i] = pci_map_single(lp->pci_dev, rx_skbuff->data, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1801 | PKT_BUF_SZ-2, PCI_DMA_FROMDEVICE); |
| 1802 | lp->rx_ring[i].base = (u32)le32_to_cpu(lp->rx_dma_addr[i]); |
| 1803 | lp->rx_ring[i].buf_length = le16_to_cpu(2-PKT_BUF_SZ); |
| 1804 | wmb(); /* Make sure owner changes after all others are visible */ |
| 1805 | lp->rx_ring[i].status = le16_to_cpu(0x8000); |
| 1806 | } |
| 1807 | /* The Tx buffer address is filled in as needed, but we do need to clear |
| 1808 | * the upper ownership bit. */ |
Hubert WS Lin | eabf041 | 2005-09-14 11:39:25 -0700 | [diff] [blame] | 1809 | for (i = 0; i < lp->tx_ring_size; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1810 | lp->tx_ring[i].status = 0; /* CPU owns buffer */ |
| 1811 | wmb(); /* Make sure adapter sees owner change */ |
| 1812 | lp->tx_ring[i].base = 0; |
| 1813 | lp->tx_dma_addr[i] = 0; |
| 1814 | } |
| 1815 | |
Hubert WS Lin | eabf041 | 2005-09-14 11:39:25 -0700 | [diff] [blame] | 1816 | lp->init_block.tlen_rlen = le16_to_cpu(lp->tx_len_bits | lp->rx_len_bits); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1817 | for (i = 0; i < 6; i++) |
| 1818 | lp->init_block.phys_addr[i] = dev->dev_addr[i]; |
Hubert WS Lin | eabf041 | 2005-09-14 11:39:25 -0700 | [diff] [blame] | 1819 | lp->init_block.rx_ring = (u32)le32_to_cpu(lp->rx_ring_dma_addr); |
| 1820 | lp->init_block.tx_ring = (u32)le32_to_cpu(lp->tx_ring_dma_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1821 | wmb(); /* Make sure all changes are visible */ |
| 1822 | return 0; |
| 1823 | } |
| 1824 | |
| 1825 | /* the pcnet32 has been issued a stop or reset. Wait for the stop bit |
| 1826 | * then flush the pending transmit operations, re-initialize the ring, |
| 1827 | * and tell the chip to initialize. |
| 1828 | */ |
| 1829 | static void |
| 1830 | pcnet32_restart(struct net_device *dev, unsigned int csr0_bits) |
| 1831 | { |
| 1832 | struct pcnet32_private *lp = dev->priv; |
| 1833 | unsigned long ioaddr = dev->base_addr; |
| 1834 | int i; |
| 1835 | |
| 1836 | /* wait for stop */ |
| 1837 | for (i=0; i<100; i++) |
| 1838 | if (lp->a.read_csr(ioaddr, 0) & 0x0004) |
| 1839 | break; |
| 1840 | |
| 1841 | if (i >= 100 && netif_msg_drv(lp)) |
| 1842 | printk(KERN_ERR "%s: pcnet32_restart timed out waiting for stop.\n", |
| 1843 | dev->name); |
| 1844 | |
| 1845 | pcnet32_purge_tx_ring(dev); |
| 1846 | if (pcnet32_init_ring(dev)) |
| 1847 | return; |
| 1848 | |
| 1849 | /* ReInit Ring */ |
| 1850 | lp->a.write_csr (ioaddr, 0, 1); |
| 1851 | i = 0; |
| 1852 | while (i++ < 1000) |
| 1853 | if (lp->a.read_csr (ioaddr, 0) & 0x0100) |
| 1854 | break; |
| 1855 | |
| 1856 | lp->a.write_csr (ioaddr, 0, csr0_bits); |
| 1857 | } |
| 1858 | |
| 1859 | |
| 1860 | static void |
| 1861 | pcnet32_tx_timeout (struct net_device *dev) |
| 1862 | { |
| 1863 | struct pcnet32_private *lp = dev->priv; |
| 1864 | unsigned long ioaddr = dev->base_addr, flags; |
| 1865 | |
| 1866 | spin_lock_irqsave(&lp->lock, flags); |
| 1867 | /* Transmitter timeout, serious problems. */ |
| 1868 | if (pcnet32_debug & NETIF_MSG_DRV) |
| 1869 | printk(KERN_ERR "%s: transmit timed out, status %4.4x, resetting.\n", |
| 1870 | dev->name, lp->a.read_csr(ioaddr, 0)); |
| 1871 | lp->a.write_csr (ioaddr, 0, 0x0004); |
| 1872 | lp->stats.tx_errors++; |
| 1873 | if (netif_msg_tx_err(lp)) { |
| 1874 | int i; |
| 1875 | printk(KERN_DEBUG " Ring data dump: dirty_tx %d cur_tx %d%s cur_rx %d.", |
| 1876 | lp->dirty_tx, lp->cur_tx, lp->tx_full ? " (full)" : "", |
| 1877 | lp->cur_rx); |
Hubert WS Lin | eabf041 | 2005-09-14 11:39:25 -0700 | [diff] [blame] | 1878 | for (i = 0 ; i < lp->rx_ring_size; i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1879 | printk("%s %08x %04x %08x %04x", i & 1 ? "" : "\n ", |
| 1880 | le32_to_cpu(lp->rx_ring[i].base), |
| 1881 | (-le16_to_cpu(lp->rx_ring[i].buf_length)) & 0xffff, |
| 1882 | le32_to_cpu(lp->rx_ring[i].msg_length), |
| 1883 | le16_to_cpu(lp->rx_ring[i].status)); |
Hubert WS Lin | eabf041 | 2005-09-14 11:39:25 -0700 | [diff] [blame] | 1884 | for (i = 0 ; i < lp->tx_ring_size; i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1885 | printk("%s %08x %04x %08x %04x", i & 1 ? "" : "\n ", |
| 1886 | le32_to_cpu(lp->tx_ring[i].base), |
| 1887 | (-le16_to_cpu(lp->tx_ring[i].length)) & 0xffff, |
| 1888 | le32_to_cpu(lp->tx_ring[i].misc), |
| 1889 | le16_to_cpu(lp->tx_ring[i].status)); |
| 1890 | printk("\n"); |
| 1891 | } |
| 1892 | pcnet32_restart(dev, 0x0042); |
| 1893 | |
| 1894 | dev->trans_start = jiffies; |
| 1895 | netif_wake_queue(dev); |
| 1896 | |
| 1897 | spin_unlock_irqrestore(&lp->lock, flags); |
| 1898 | } |
| 1899 | |
| 1900 | |
| 1901 | static int |
| 1902 | pcnet32_start_xmit(struct sk_buff *skb, struct net_device *dev) |
| 1903 | { |
| 1904 | struct pcnet32_private *lp = dev->priv; |
| 1905 | unsigned long ioaddr = dev->base_addr; |
| 1906 | u16 status; |
| 1907 | int entry; |
| 1908 | unsigned long flags; |
| 1909 | |
| 1910 | spin_lock_irqsave(&lp->lock, flags); |
| 1911 | |
| 1912 | if (netif_msg_tx_queued(lp)) { |
| 1913 | printk(KERN_DEBUG "%s: pcnet32_start_xmit() called, csr0 %4.4x.\n", |
| 1914 | dev->name, lp->a.read_csr(ioaddr, 0)); |
| 1915 | } |
| 1916 | |
| 1917 | /* Default status -- will not enable Successful-TxDone |
| 1918 | * interrupt when that option is available to us. |
| 1919 | */ |
| 1920 | status = 0x8300; |
| 1921 | |
| 1922 | /* Fill in a Tx ring entry */ |
| 1923 | |
| 1924 | /* Mask to ring buffer boundary. */ |
Hubert WS Lin | eabf041 | 2005-09-14 11:39:25 -0700 | [diff] [blame] | 1925 | entry = lp->cur_tx & lp->tx_mod_mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1926 | |
| 1927 | /* Caution: the write order is important here, set the status |
| 1928 | * with the "ownership" bits last. */ |
| 1929 | |
| 1930 | lp->tx_ring[entry].length = le16_to_cpu(-skb->len); |
| 1931 | |
| 1932 | lp->tx_ring[entry].misc = 0x00000000; |
| 1933 | |
| 1934 | lp->tx_skbuff[entry] = skb; |
| 1935 | lp->tx_dma_addr[entry] = pci_map_single(lp->pci_dev, skb->data, skb->len, |
| 1936 | PCI_DMA_TODEVICE); |
| 1937 | lp->tx_ring[entry].base = (u32)le32_to_cpu(lp->tx_dma_addr[entry]); |
| 1938 | wmb(); /* Make sure owner changes after all others are visible */ |
| 1939 | lp->tx_ring[entry].status = le16_to_cpu(status); |
| 1940 | |
| 1941 | lp->cur_tx++; |
| 1942 | lp->stats.tx_bytes += skb->len; |
| 1943 | |
| 1944 | /* Trigger an immediate send poll. */ |
| 1945 | lp->a.write_csr (ioaddr, 0, 0x0048); |
| 1946 | |
| 1947 | dev->trans_start = jiffies; |
| 1948 | |
Hubert WS Lin | eabf041 | 2005-09-14 11:39:25 -0700 | [diff] [blame] | 1949 | if (lp->tx_ring[(entry+1) & lp->tx_mod_mask].base != 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1950 | lp->tx_full = 1; |
| 1951 | netif_stop_queue(dev); |
| 1952 | } |
| 1953 | spin_unlock_irqrestore(&lp->lock, flags); |
| 1954 | return 0; |
| 1955 | } |
| 1956 | |
| 1957 | /* The PCNET32 interrupt handler. */ |
| 1958 | static irqreturn_t |
| 1959 | pcnet32_interrupt(int irq, void *dev_id, struct pt_regs * regs) |
| 1960 | { |
| 1961 | struct net_device *dev = dev_id; |
| 1962 | struct pcnet32_private *lp; |
| 1963 | unsigned long ioaddr; |
| 1964 | u16 csr0,rap; |
| 1965 | int boguscnt = max_interrupt_work; |
| 1966 | int must_restart; |
| 1967 | |
| 1968 | if (!dev) { |
| 1969 | if (pcnet32_debug & NETIF_MSG_INTR) |
| 1970 | printk (KERN_DEBUG "%s(): irq %d for unknown device\n", |
| 1971 | __FUNCTION__, irq); |
| 1972 | return IRQ_NONE; |
| 1973 | } |
| 1974 | |
| 1975 | ioaddr = dev->base_addr; |
| 1976 | lp = dev->priv; |
| 1977 | |
| 1978 | spin_lock(&lp->lock); |
| 1979 | |
| 1980 | rap = lp->a.read_rap(ioaddr); |
| 1981 | while ((csr0 = lp->a.read_csr (ioaddr, 0)) & 0x8f00 && --boguscnt >= 0) { |
| 1982 | if (csr0 == 0xffff) { |
| 1983 | break; /* PCMCIA remove happened */ |
| 1984 | } |
| 1985 | /* Acknowledge all of the current interrupt sources ASAP. */ |
| 1986 | lp->a.write_csr (ioaddr, 0, csr0 & ~0x004f); |
| 1987 | |
| 1988 | must_restart = 0; |
| 1989 | |
| 1990 | if (netif_msg_intr(lp)) |
| 1991 | printk(KERN_DEBUG "%s: interrupt csr0=%#2.2x new csr=%#2.2x.\n", |
| 1992 | dev->name, csr0, lp->a.read_csr (ioaddr, 0)); |
| 1993 | |
| 1994 | if (csr0 & 0x0400) /* Rx interrupt */ |
| 1995 | pcnet32_rx(dev); |
| 1996 | |
| 1997 | if (csr0 & 0x0200) { /* Tx-done interrupt */ |
| 1998 | unsigned int dirty_tx = lp->dirty_tx; |
| 1999 | int delta; |
| 2000 | |
| 2001 | while (dirty_tx != lp->cur_tx) { |
Hubert WS Lin | eabf041 | 2005-09-14 11:39:25 -0700 | [diff] [blame] | 2002 | int entry = dirty_tx & lp->tx_mod_mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2003 | int status = (short)le16_to_cpu(lp->tx_ring[entry].status); |
| 2004 | |
| 2005 | if (status < 0) |
| 2006 | break; /* It still hasn't been Txed */ |
| 2007 | |
| 2008 | lp->tx_ring[entry].base = 0; |
| 2009 | |
| 2010 | if (status & 0x4000) { |
| 2011 | /* There was an major error, log it. */ |
| 2012 | int err_status = le32_to_cpu(lp->tx_ring[entry].misc); |
| 2013 | lp->stats.tx_errors++; |
| 2014 | if (netif_msg_tx_err(lp)) |
| 2015 | printk(KERN_ERR "%s: Tx error status=%04x err_status=%08x\n", |
| 2016 | dev->name, status, err_status); |
| 2017 | if (err_status & 0x04000000) lp->stats.tx_aborted_errors++; |
| 2018 | if (err_status & 0x08000000) lp->stats.tx_carrier_errors++; |
| 2019 | if (err_status & 0x10000000) lp->stats.tx_window_errors++; |
| 2020 | #ifndef DO_DXSUFLO |
| 2021 | if (err_status & 0x40000000) { |
| 2022 | lp->stats.tx_fifo_errors++; |
| 2023 | /* Ackk! On FIFO errors the Tx unit is turned off! */ |
| 2024 | /* Remove this verbosity later! */ |
| 2025 | if (netif_msg_tx_err(lp)) |
| 2026 | printk(KERN_ERR "%s: Tx FIFO error! CSR0=%4.4x\n", |
| 2027 | dev->name, csr0); |
| 2028 | must_restart = 1; |
| 2029 | } |
| 2030 | #else |
| 2031 | if (err_status & 0x40000000) { |
| 2032 | lp->stats.tx_fifo_errors++; |
| 2033 | if (! lp->dxsuflo) { /* If controller doesn't recover ... */ |
| 2034 | /* Ackk! On FIFO errors the Tx unit is turned off! */ |
| 2035 | /* Remove this verbosity later! */ |
| 2036 | if (netif_msg_tx_err(lp)) |
| 2037 | printk(KERN_ERR "%s: Tx FIFO error! CSR0=%4.4x\n", |
| 2038 | dev->name, csr0); |
| 2039 | must_restart = 1; |
| 2040 | } |
| 2041 | } |
| 2042 | #endif |
| 2043 | } else { |
| 2044 | if (status & 0x1800) |
| 2045 | lp->stats.collisions++; |
| 2046 | lp->stats.tx_packets++; |
| 2047 | } |
| 2048 | |
| 2049 | /* We must free the original skb */ |
| 2050 | if (lp->tx_skbuff[entry]) { |
| 2051 | pci_unmap_single(lp->pci_dev, lp->tx_dma_addr[entry], |
| 2052 | lp->tx_skbuff[entry]->len, PCI_DMA_TODEVICE); |
| 2053 | dev_kfree_skb_irq(lp->tx_skbuff[entry]); |
| 2054 | lp->tx_skbuff[entry] = NULL; |
| 2055 | lp->tx_dma_addr[entry] = 0; |
| 2056 | } |
| 2057 | dirty_tx++; |
| 2058 | } |
| 2059 | |
Hubert WS Lin | eabf041 | 2005-09-14 11:39:25 -0700 | [diff] [blame] | 2060 | delta = (lp->cur_tx - dirty_tx) & (lp->tx_mod_mask + lp->tx_ring_size); |
| 2061 | if (delta > lp->tx_ring_size) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2062 | if (netif_msg_drv(lp)) |
| 2063 | printk(KERN_ERR "%s: out-of-sync dirty pointer, %d vs. %d, full=%d.\n", |
| 2064 | dev->name, dirty_tx, lp->cur_tx, lp->tx_full); |
Hubert WS Lin | eabf041 | 2005-09-14 11:39:25 -0700 | [diff] [blame] | 2065 | dirty_tx += lp->tx_ring_size; |
| 2066 | delta -= lp->tx_ring_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2067 | } |
| 2068 | |
| 2069 | if (lp->tx_full && |
| 2070 | netif_queue_stopped(dev) && |
Hubert WS Lin | eabf041 | 2005-09-14 11:39:25 -0700 | [diff] [blame] | 2071 | delta < lp->tx_ring_size - 2) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2072 | /* The ring is no longer full, clear tbusy. */ |
| 2073 | lp->tx_full = 0; |
| 2074 | netif_wake_queue (dev); |
| 2075 | } |
| 2076 | lp->dirty_tx = dirty_tx; |
| 2077 | } |
| 2078 | |
| 2079 | /* Log misc errors. */ |
| 2080 | if (csr0 & 0x4000) lp->stats.tx_errors++; /* Tx babble. */ |
| 2081 | if (csr0 & 0x1000) { |
| 2082 | /* |
| 2083 | * this happens when our receive ring is full. This shouldn't |
| 2084 | * be a problem as we will see normal rx interrupts for the frames |
| 2085 | * in the receive ring. But there are some PCI chipsets (I can |
| 2086 | * reproduce this on SP3G with Intel saturn chipset) which have |
| 2087 | * sometimes problems and will fill up the receive ring with |
| 2088 | * error descriptors. In this situation we don't get a rx |
| 2089 | * interrupt, but a missed frame interrupt sooner or later. |
| 2090 | * So we try to clean up our receive ring here. |
| 2091 | */ |
| 2092 | pcnet32_rx(dev); |
| 2093 | lp->stats.rx_errors++; /* Missed a Rx frame. */ |
| 2094 | } |
| 2095 | if (csr0 & 0x0800) { |
| 2096 | if (netif_msg_drv(lp)) |
| 2097 | printk(KERN_ERR "%s: Bus master arbitration failure, status %4.4x.\n", |
| 2098 | dev->name, csr0); |
| 2099 | /* unlike for the lance, there is no restart needed */ |
| 2100 | } |
| 2101 | |
| 2102 | if (must_restart) { |
| 2103 | /* reset the chip to clear the error condition, then restart */ |
| 2104 | lp->a.reset(ioaddr); |
| 2105 | lp->a.write_csr(ioaddr, 4, 0x0915); |
| 2106 | pcnet32_restart(dev, 0x0002); |
| 2107 | netif_wake_queue(dev); |
| 2108 | } |
| 2109 | } |
| 2110 | |
| 2111 | /* Set interrupt enable. */ |
| 2112 | lp->a.write_csr (ioaddr, 0, 0x0040); |
| 2113 | lp->a.write_rap (ioaddr,rap); |
| 2114 | |
| 2115 | if (netif_msg_intr(lp)) |
| 2116 | printk(KERN_DEBUG "%s: exiting interrupt, csr0=%#4.4x.\n", |
| 2117 | dev->name, lp->a.read_csr (ioaddr, 0)); |
| 2118 | |
| 2119 | spin_unlock(&lp->lock); |
| 2120 | |
| 2121 | return IRQ_HANDLED; |
| 2122 | } |
| 2123 | |
| 2124 | static int |
| 2125 | pcnet32_rx(struct net_device *dev) |
| 2126 | { |
| 2127 | struct pcnet32_private *lp = dev->priv; |
Hubert WS Lin | eabf041 | 2005-09-14 11:39:25 -0700 | [diff] [blame] | 2128 | int entry = lp->cur_rx & lp->rx_mod_mask; |
| 2129 | int boguscnt = lp->rx_ring_size / 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2130 | |
| 2131 | /* If we own the next entry, it's a new packet. Send it up. */ |
| 2132 | while ((short)le16_to_cpu(lp->rx_ring[entry].status) >= 0) { |
| 2133 | int status = (short)le16_to_cpu(lp->rx_ring[entry].status) >> 8; |
| 2134 | |
| 2135 | if (status != 0x03) { /* There was an error. */ |
| 2136 | /* |
| 2137 | * There is a tricky error noted by John Murphy, |
| 2138 | * <murf@perftech.com> to Russ Nelson: Even with full-sized |
| 2139 | * buffers it's possible for a jabber packet to use two |
| 2140 | * buffers, with only the last correctly noting the error. |
| 2141 | */ |
| 2142 | if (status & 0x01) /* Only count a general error at the */ |
| 2143 | lp->stats.rx_errors++; /* end of a packet.*/ |
| 2144 | if (status & 0x20) lp->stats.rx_frame_errors++; |
| 2145 | if (status & 0x10) lp->stats.rx_over_errors++; |
| 2146 | if (status & 0x08) lp->stats.rx_crc_errors++; |
| 2147 | if (status & 0x04) lp->stats.rx_fifo_errors++; |
| 2148 | lp->rx_ring[entry].status &= le16_to_cpu(0x03ff); |
| 2149 | } else { |
| 2150 | /* Malloc up new buffer, compatible with net-2e. */ |
| 2151 | short pkt_len = (le32_to_cpu(lp->rx_ring[entry].msg_length) & 0xfff)-4; |
| 2152 | struct sk_buff *skb; |
| 2153 | |
| 2154 | /* Discard oversize frames. */ |
| 2155 | if (unlikely(pkt_len > PKT_BUF_SZ - 2)) { |
| 2156 | if (netif_msg_drv(lp)) |
| 2157 | printk(KERN_ERR "%s: Impossible packet size %d!\n", |
| 2158 | dev->name, pkt_len); |
| 2159 | lp->stats.rx_errors++; |
| 2160 | } else if (pkt_len < 60) { |
| 2161 | if (netif_msg_rx_err(lp)) |
| 2162 | printk(KERN_ERR "%s: Runt packet!\n", dev->name); |
| 2163 | lp->stats.rx_errors++; |
| 2164 | } else { |
| 2165 | int rx_in_place = 0; |
| 2166 | |
| 2167 | if (pkt_len > rx_copybreak) { |
| 2168 | struct sk_buff *newskb; |
| 2169 | |
| 2170 | if ((newskb = dev_alloc_skb(PKT_BUF_SZ))) { |
| 2171 | skb_reserve (newskb, 2); |
| 2172 | skb = lp->rx_skbuff[entry]; |
| 2173 | pci_unmap_single(lp->pci_dev, lp->rx_dma_addr[entry], |
| 2174 | PKT_BUF_SZ-2, PCI_DMA_FROMDEVICE); |
| 2175 | skb_put (skb, pkt_len); |
| 2176 | lp->rx_skbuff[entry] = newskb; |
| 2177 | newskb->dev = dev; |
| 2178 | lp->rx_dma_addr[entry] = |
David S. Miller | 689be43 | 2005-06-28 15:25:31 -0700 | [diff] [blame] | 2179 | pci_map_single(lp->pci_dev, newskb->data, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2180 | PKT_BUF_SZ-2, PCI_DMA_FROMDEVICE); |
| 2181 | lp->rx_ring[entry].base = le32_to_cpu(lp->rx_dma_addr[entry]); |
| 2182 | rx_in_place = 1; |
| 2183 | } else |
| 2184 | skb = NULL; |
| 2185 | } else { |
| 2186 | skb = dev_alloc_skb(pkt_len+2); |
| 2187 | } |
| 2188 | |
| 2189 | if (skb == NULL) { |
| 2190 | int i; |
| 2191 | if (netif_msg_drv(lp)) |
| 2192 | printk(KERN_ERR "%s: Memory squeeze, deferring packet.\n", |
| 2193 | dev->name); |
Hubert WS Lin | eabf041 | 2005-09-14 11:39:25 -0700 | [diff] [blame] | 2194 | for (i = 0; i < lp->rx_ring_size; i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2195 | if ((short)le16_to_cpu(lp->rx_ring[(entry+i) |
Hubert WS Lin | eabf041 | 2005-09-14 11:39:25 -0700 | [diff] [blame] | 2196 | & lp->rx_mod_mask].status) < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2197 | break; |
| 2198 | |
Hubert WS Lin | eabf041 | 2005-09-14 11:39:25 -0700 | [diff] [blame] | 2199 | if (i > lp->rx_ring_size -2) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2200 | lp->stats.rx_dropped++; |
| 2201 | lp->rx_ring[entry].status |= le16_to_cpu(0x8000); |
| 2202 | wmb(); /* Make sure adapter sees owner change */ |
| 2203 | lp->cur_rx++; |
| 2204 | } |
| 2205 | break; |
| 2206 | } |
| 2207 | skb->dev = dev; |
| 2208 | if (!rx_in_place) { |
| 2209 | skb_reserve(skb,2); /* 16 byte align */ |
| 2210 | skb_put(skb,pkt_len); /* Make room */ |
| 2211 | pci_dma_sync_single_for_cpu(lp->pci_dev, |
| 2212 | lp->rx_dma_addr[entry], |
| 2213 | PKT_BUF_SZ-2, |
| 2214 | PCI_DMA_FROMDEVICE); |
| 2215 | eth_copy_and_sum(skb, |
David S. Miller | 689be43 | 2005-06-28 15:25:31 -0700 | [diff] [blame] | 2216 | (unsigned char *)(lp->rx_skbuff[entry]->data), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2217 | pkt_len,0); |
| 2218 | pci_dma_sync_single_for_device(lp->pci_dev, |
| 2219 | lp->rx_dma_addr[entry], |
| 2220 | PKT_BUF_SZ-2, |
| 2221 | PCI_DMA_FROMDEVICE); |
| 2222 | } |
| 2223 | lp->stats.rx_bytes += skb->len; |
| 2224 | skb->protocol=eth_type_trans(skb,dev); |
| 2225 | netif_rx(skb); |
| 2226 | dev->last_rx = jiffies; |
| 2227 | lp->stats.rx_packets++; |
| 2228 | } |
| 2229 | } |
| 2230 | /* |
| 2231 | * The docs say that the buffer length isn't touched, but Andrew Boyd |
| 2232 | * of QNX reports that some revs of the 79C965 clear it. |
| 2233 | */ |
| 2234 | lp->rx_ring[entry].buf_length = le16_to_cpu(2-PKT_BUF_SZ); |
| 2235 | wmb(); /* Make sure owner changes after all others are visible */ |
| 2236 | lp->rx_ring[entry].status |= le16_to_cpu(0x8000); |
Hubert WS Lin | eabf041 | 2005-09-14 11:39:25 -0700 | [diff] [blame] | 2237 | entry = (++lp->cur_rx) & lp->rx_mod_mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2238 | if (--boguscnt <= 0) break; /* don't stay in loop forever */ |
| 2239 | } |
| 2240 | |
| 2241 | return 0; |
| 2242 | } |
| 2243 | |
| 2244 | static int |
| 2245 | pcnet32_close(struct net_device *dev) |
| 2246 | { |
| 2247 | unsigned long ioaddr = dev->base_addr; |
| 2248 | struct pcnet32_private *lp = dev->priv; |
| 2249 | int i; |
| 2250 | unsigned long flags; |
| 2251 | |
| 2252 | del_timer_sync(&lp->watchdog_timer); |
| 2253 | |
| 2254 | netif_stop_queue(dev); |
| 2255 | |
| 2256 | spin_lock_irqsave(&lp->lock, flags); |
| 2257 | |
| 2258 | lp->stats.rx_missed_errors = lp->a.read_csr (ioaddr, 112); |
| 2259 | |
| 2260 | if (netif_msg_ifdown(lp)) |
| 2261 | printk(KERN_DEBUG "%s: Shutting down ethercard, status was %2.2x.\n", |
| 2262 | dev->name, lp->a.read_csr (ioaddr, 0)); |
| 2263 | |
| 2264 | /* We stop the PCNET32 here -- it occasionally polls memory if we don't. */ |
| 2265 | lp->a.write_csr (ioaddr, 0, 0x0004); |
| 2266 | |
| 2267 | /* |
| 2268 | * Switch back to 16bit mode to avoid problems with dumb |
| 2269 | * DOS packet driver after a warm reboot |
| 2270 | */ |
| 2271 | lp->a.write_bcr (ioaddr, 20, 4); |
| 2272 | |
| 2273 | spin_unlock_irqrestore(&lp->lock, flags); |
| 2274 | |
| 2275 | free_irq(dev->irq, dev); |
| 2276 | |
| 2277 | spin_lock_irqsave(&lp->lock, flags); |
| 2278 | |
| 2279 | /* free all allocated skbuffs */ |
Hubert WS Lin | eabf041 | 2005-09-14 11:39:25 -0700 | [diff] [blame] | 2280 | for (i = 0; i < lp->rx_ring_size; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2281 | lp->rx_ring[i].status = 0; |
| 2282 | wmb(); /* Make sure adapter sees owner change */ |
| 2283 | if (lp->rx_skbuff[i]) { |
| 2284 | pci_unmap_single(lp->pci_dev, lp->rx_dma_addr[i], PKT_BUF_SZ-2, |
| 2285 | PCI_DMA_FROMDEVICE); |
| 2286 | dev_kfree_skb(lp->rx_skbuff[i]); |
| 2287 | } |
| 2288 | lp->rx_skbuff[i] = NULL; |
| 2289 | lp->rx_dma_addr[i] = 0; |
| 2290 | } |
| 2291 | |
Hubert WS Lin | eabf041 | 2005-09-14 11:39:25 -0700 | [diff] [blame] | 2292 | for (i = 0; i < lp->tx_ring_size; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2293 | lp->tx_ring[i].status = 0; /* CPU owns buffer */ |
| 2294 | wmb(); /* Make sure adapter sees owner change */ |
| 2295 | if (lp->tx_skbuff[i]) { |
| 2296 | pci_unmap_single(lp->pci_dev, lp->tx_dma_addr[i], |
| 2297 | lp->tx_skbuff[i]->len, PCI_DMA_TODEVICE); |
| 2298 | dev_kfree_skb(lp->tx_skbuff[i]); |
| 2299 | } |
| 2300 | lp->tx_skbuff[i] = NULL; |
| 2301 | lp->tx_dma_addr[i] = 0; |
| 2302 | } |
| 2303 | |
| 2304 | spin_unlock_irqrestore(&lp->lock, flags); |
| 2305 | |
| 2306 | return 0; |
| 2307 | } |
| 2308 | |
| 2309 | static struct net_device_stats * |
| 2310 | pcnet32_get_stats(struct net_device *dev) |
| 2311 | { |
| 2312 | struct pcnet32_private *lp = dev->priv; |
| 2313 | unsigned long ioaddr = dev->base_addr; |
| 2314 | u16 saved_addr; |
| 2315 | unsigned long flags; |
| 2316 | |
| 2317 | spin_lock_irqsave(&lp->lock, flags); |
| 2318 | saved_addr = lp->a.read_rap(ioaddr); |
| 2319 | lp->stats.rx_missed_errors = lp->a.read_csr (ioaddr, 112); |
| 2320 | lp->a.write_rap(ioaddr, saved_addr); |
| 2321 | spin_unlock_irqrestore(&lp->lock, flags); |
| 2322 | |
| 2323 | return &lp->stats; |
| 2324 | } |
| 2325 | |
| 2326 | /* taken from the sunlance driver, which it took from the depca driver */ |
| 2327 | static void pcnet32_load_multicast (struct net_device *dev) |
| 2328 | { |
| 2329 | struct pcnet32_private *lp = dev->priv; |
| 2330 | volatile struct pcnet32_init_block *ib = &lp->init_block; |
| 2331 | volatile u16 *mcast_table = (u16 *)&ib->filter; |
| 2332 | struct dev_mc_list *dmi=dev->mc_list; |
| 2333 | char *addrs; |
| 2334 | int i; |
| 2335 | u32 crc; |
| 2336 | |
| 2337 | /* set all multicast bits */ |
| 2338 | if (dev->flags & IFF_ALLMULTI) { |
| 2339 | ib->filter[0] = 0xffffffff; |
| 2340 | ib->filter[1] = 0xffffffff; |
| 2341 | return; |
| 2342 | } |
| 2343 | /* clear the multicast filter */ |
| 2344 | ib->filter[0] = 0; |
| 2345 | ib->filter[1] = 0; |
| 2346 | |
| 2347 | /* Add addresses */ |
| 2348 | for (i = 0; i < dev->mc_count; i++) { |
| 2349 | addrs = dmi->dmi_addr; |
| 2350 | dmi = dmi->next; |
| 2351 | |
| 2352 | /* multicast address? */ |
| 2353 | if (!(*addrs & 1)) |
| 2354 | continue; |
| 2355 | |
| 2356 | crc = ether_crc_le(6, addrs); |
| 2357 | crc = crc >> 26; |
| 2358 | mcast_table [crc >> 4] = le16_to_cpu( |
| 2359 | le16_to_cpu(mcast_table [crc >> 4]) | (1 << (crc & 0xf))); |
| 2360 | } |
| 2361 | return; |
| 2362 | } |
| 2363 | |
| 2364 | |
| 2365 | /* |
| 2366 | * Set or clear the multicast filter for this adaptor. |
| 2367 | */ |
| 2368 | static void pcnet32_set_multicast_list(struct net_device *dev) |
| 2369 | { |
| 2370 | unsigned long ioaddr = dev->base_addr, flags; |
| 2371 | struct pcnet32_private *lp = dev->priv; |
| 2372 | |
| 2373 | spin_lock_irqsave(&lp->lock, flags); |
| 2374 | if (dev->flags&IFF_PROMISC) { |
| 2375 | /* Log any net taps. */ |
| 2376 | if (netif_msg_hw(lp)) |
| 2377 | printk(KERN_INFO "%s: Promiscuous mode enabled.\n", dev->name); |
| 2378 | lp->init_block.mode = le16_to_cpu(0x8000 | (lp->options & PCNET32_PORT_PORTSEL) << 7); |
| 2379 | } else { |
| 2380 | lp->init_block.mode = le16_to_cpu((lp->options & PCNET32_PORT_PORTSEL) << 7); |
| 2381 | pcnet32_load_multicast (dev); |
| 2382 | } |
| 2383 | |
| 2384 | lp->a.write_csr (ioaddr, 0, 0x0004); /* Temporarily stop the lance. */ |
| 2385 | pcnet32_restart(dev, 0x0042); /* Resume normal operation */ |
| 2386 | netif_wake_queue(dev); |
| 2387 | |
| 2388 | spin_unlock_irqrestore(&lp->lock, flags); |
| 2389 | } |
| 2390 | |
| 2391 | /* This routine assumes that the lp->lock is held */ |
| 2392 | static int mdio_read(struct net_device *dev, int phy_id, int reg_num) |
| 2393 | { |
| 2394 | struct pcnet32_private *lp = dev->priv; |
| 2395 | unsigned long ioaddr = dev->base_addr; |
| 2396 | u16 val_out; |
| 2397 | |
| 2398 | if (!lp->mii) |
| 2399 | return 0; |
| 2400 | |
| 2401 | lp->a.write_bcr(ioaddr, 33, ((phy_id & 0x1f) << 5) | (reg_num & 0x1f)); |
| 2402 | val_out = lp->a.read_bcr(ioaddr, 34); |
| 2403 | |
| 2404 | return val_out; |
| 2405 | } |
| 2406 | |
| 2407 | /* This routine assumes that the lp->lock is held */ |
| 2408 | static void mdio_write(struct net_device *dev, int phy_id, int reg_num, int val) |
| 2409 | { |
| 2410 | struct pcnet32_private *lp = dev->priv; |
| 2411 | unsigned long ioaddr = dev->base_addr; |
| 2412 | |
| 2413 | if (!lp->mii) |
| 2414 | return; |
| 2415 | |
| 2416 | lp->a.write_bcr(ioaddr, 33, ((phy_id & 0x1f) << 5) | (reg_num & 0x1f)); |
| 2417 | lp->a.write_bcr(ioaddr, 34, val); |
| 2418 | } |
| 2419 | |
| 2420 | static int pcnet32_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) |
| 2421 | { |
| 2422 | struct pcnet32_private *lp = dev->priv; |
| 2423 | int rc; |
| 2424 | unsigned long flags; |
| 2425 | |
| 2426 | /* SIOC[GS]MIIxxx ioctls */ |
| 2427 | if (lp->mii) { |
| 2428 | spin_lock_irqsave(&lp->lock, flags); |
| 2429 | rc = generic_mii_ioctl(&lp->mii_if, if_mii(rq), cmd, NULL); |
| 2430 | spin_unlock_irqrestore(&lp->lock, flags); |
| 2431 | } else { |
| 2432 | rc = -EOPNOTSUPP; |
| 2433 | } |
| 2434 | |
| 2435 | return rc; |
| 2436 | } |
| 2437 | |
| 2438 | static void pcnet32_watchdog(struct net_device *dev) |
| 2439 | { |
| 2440 | struct pcnet32_private *lp = dev->priv; |
| 2441 | unsigned long flags; |
| 2442 | |
| 2443 | /* Print the link status if it has changed */ |
| 2444 | if (lp->mii) { |
| 2445 | spin_lock_irqsave(&lp->lock, flags); |
| 2446 | mii_check_media (&lp->mii_if, netif_msg_link(lp), 0); |
| 2447 | spin_unlock_irqrestore(&lp->lock, flags); |
| 2448 | } |
| 2449 | |
| 2450 | mod_timer (&(lp->watchdog_timer), PCNET32_WATCHDOG_TIMEOUT); |
| 2451 | } |
| 2452 | |
| 2453 | static void __devexit pcnet32_remove_one(struct pci_dev *pdev) |
| 2454 | { |
| 2455 | struct net_device *dev = pci_get_drvdata(pdev); |
| 2456 | |
| 2457 | if (dev) { |
| 2458 | struct pcnet32_private *lp = dev->priv; |
| 2459 | |
| 2460 | unregister_netdev(dev); |
Hubert WS Lin | eabf041 | 2005-09-14 11:39:25 -0700 | [diff] [blame] | 2461 | pcnet32_free_ring(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2462 | release_region(dev->base_addr, PCNET32_TOTAL_SIZE); |
| 2463 | pci_free_consistent(lp->pci_dev, sizeof(*lp), lp, lp->dma_addr); |
| 2464 | free_netdev(dev); |
| 2465 | pci_disable_device(pdev); |
| 2466 | pci_set_drvdata(pdev, NULL); |
| 2467 | } |
| 2468 | } |
| 2469 | |
| 2470 | static struct pci_driver pcnet32_driver = { |
| 2471 | .name = DRV_NAME, |
| 2472 | .probe = pcnet32_probe_pci, |
| 2473 | .remove = __devexit_p(pcnet32_remove_one), |
| 2474 | .id_table = pcnet32_pci_tbl, |
| 2475 | }; |
| 2476 | |
| 2477 | /* An additional parameter that may be passed in... */ |
| 2478 | static int debug = -1; |
| 2479 | static int tx_start_pt = -1; |
| 2480 | static int pcnet32_have_pci; |
| 2481 | |
| 2482 | module_param(debug, int, 0); |
| 2483 | MODULE_PARM_DESC(debug, DRV_NAME " debug level"); |
| 2484 | module_param(max_interrupt_work, int, 0); |
| 2485 | MODULE_PARM_DESC(max_interrupt_work, DRV_NAME " maximum events handled per interrupt"); |
| 2486 | module_param(rx_copybreak, int, 0); |
| 2487 | MODULE_PARM_DESC(rx_copybreak, DRV_NAME " copy breakpoint for copy-only-tiny-frames"); |
| 2488 | module_param(tx_start_pt, int, 0); |
| 2489 | MODULE_PARM_DESC(tx_start_pt, DRV_NAME " transmit start point (0-3)"); |
| 2490 | module_param(pcnet32vlb, int, 0); |
| 2491 | MODULE_PARM_DESC(pcnet32vlb, DRV_NAME " Vesa local bus (VLB) support (0/1)"); |
| 2492 | module_param_array(options, int, NULL, 0); |
| 2493 | MODULE_PARM_DESC(options, DRV_NAME " initial option setting(s) (0-15)"); |
| 2494 | module_param_array(full_duplex, int, NULL, 0); |
| 2495 | MODULE_PARM_DESC(full_duplex, DRV_NAME " full duplex setting(s) (1)"); |
| 2496 | /* Module Parameter for HomePNA cards added by Patrick Simmons, 2004 */ |
| 2497 | module_param_array(homepna, int, NULL, 0); |
| 2498 | MODULE_PARM_DESC(homepna, DRV_NAME " mode for 79C978 cards (1 for HomePNA, 0 for Ethernet, default Ethernet"); |
| 2499 | |
| 2500 | MODULE_AUTHOR("Thomas Bogendoerfer"); |
| 2501 | MODULE_DESCRIPTION("Driver for PCnet32 and PCnetPCI based ethercards"); |
| 2502 | MODULE_LICENSE("GPL"); |
| 2503 | |
| 2504 | #define PCNET32_MSG_DEFAULT (NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_LINK) |
| 2505 | |
| 2506 | static int __init pcnet32_init_module(void) |
| 2507 | { |
| 2508 | printk(KERN_INFO "%s", version); |
| 2509 | |
| 2510 | pcnet32_debug = netif_msg_init(debug, PCNET32_MSG_DEFAULT); |
| 2511 | |
| 2512 | if ((tx_start_pt >= 0) && (tx_start_pt <= 3)) |
| 2513 | tx_start = tx_start_pt; |
| 2514 | |
| 2515 | /* find the PCI devices */ |
| 2516 | if (!pci_module_init(&pcnet32_driver)) |
| 2517 | pcnet32_have_pci = 1; |
| 2518 | |
| 2519 | /* should we find any remaining VLbus devices ? */ |
| 2520 | if (pcnet32vlb) |
| 2521 | pcnet32_probe_vlbus(); |
| 2522 | |
| 2523 | if (cards_found && (pcnet32_debug & NETIF_MSG_PROBE)) |
| 2524 | printk(KERN_INFO PFX "%d cards_found.\n", cards_found); |
| 2525 | |
| 2526 | return (pcnet32_have_pci + cards_found) ? 0 : -ENODEV; |
| 2527 | } |
| 2528 | |
| 2529 | static void __exit pcnet32_cleanup_module(void) |
| 2530 | { |
| 2531 | struct net_device *next_dev; |
| 2532 | |
| 2533 | while (pcnet32_dev) { |
| 2534 | struct pcnet32_private *lp = pcnet32_dev->priv; |
| 2535 | next_dev = lp->next; |
| 2536 | unregister_netdev(pcnet32_dev); |
Hubert WS Lin | eabf041 | 2005-09-14 11:39:25 -0700 | [diff] [blame] | 2537 | pcnet32_free_ring(pcnet32_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2538 | release_region(pcnet32_dev->base_addr, PCNET32_TOTAL_SIZE); |
| 2539 | pci_free_consistent(lp->pci_dev, sizeof(*lp), lp, lp->dma_addr); |
| 2540 | free_netdev(pcnet32_dev); |
| 2541 | pcnet32_dev = next_dev; |
| 2542 | } |
| 2543 | |
| 2544 | if (pcnet32_have_pci) |
| 2545 | pci_unregister_driver(&pcnet32_driver); |
| 2546 | } |
| 2547 | |
| 2548 | module_init(pcnet32_init_module); |
| 2549 | module_exit(pcnet32_cleanup_module); |
| 2550 | |
| 2551 | /* |
| 2552 | * Local variables: |
| 2553 | * c-indent-level: 4 |
| 2554 | * tab-width: 8 |
| 2555 | * End: |
| 2556 | */ |