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