~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Linux/drivers/net/natsemi.c

Version: ~ [ 2.4.0 ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /* natsemi.c: A Linux PCI Ethernet driver for the NatSemi DP83810 series. */
  2 /*
  3         Written/copyright 1999-2000 by Donald Becker.
  4 
  5         This software may be used and distributed according to the terms of
  6         the GNU General Public License (GPL), incorporated herein by reference.
  7         Drivers based on or derived from this code fall under the GPL and must
  8         retain the authorship, copyright and license notice.  This file is not
  9         a complete program and may only be used when the entire operating
 10         system is licensed under the GPL.  License for under other terms may be
 11         available.  Contact the original author for details.
 12 
 13         The original author may be reached as becker@scyld.com, or at
 14         Scyld Computing Corporation
 15         410 Severn Ave., Suite 210
 16         Annapolis MD 21403
 17 
 18         Support information and updates available at
 19         http://www.scyld.com/network/netsemi.html
 20 
 21 
 22         Linux kernel modifications:
 23 
 24         Version 1.0.1:
 25                 - Spinlock fixes
 26                 - Bug fixes and better intr performance (Tjeerd)
 27         Version 1.0.2:
 28                 - Now reads correct MAC address from eeprom
 29 
 30 */
 31 
 32 /* These identify the driver base version and may not be removed. */
 33 static const char version1[] =
 34 "natsemi.c:v1.05 8/7/2000  Written by Donald Becker <becker@scyld.com>\n";
 35 static const char version2[] =
 36 "  http://www.scyld.com/network/natsemi.html\n";
 37 static const char version3[] =
 38 "  (unofficial 2.4.x kernel port, version 1.0.2, October 6, 2000 Jeff Garzik, Tjeerd Mulder)\n";
 39 /* Updated to recommendations in pci-skeleton v2.03. */
 40 
 41 /* Automatically extracted configuration info:
 42 probe-func: natsemi_probe
 43 config-in: tristate 'National Semiconductor DP83810 series PCI Ethernet support' CONFIG_NATSEMI
 44 
 45 c-help-name: National Semiconductor DP83810 series PCI Ethernet support
 46 c-help-symbol: CONFIG_NATSEMI
 47 c-help: This driver is for the National Semiconductor DP83810 series,
 48 c-help: including the 83815 chip.
 49 c-help: More specific information and updates are available from 
 50 c-help: http://www.scyld.com/network/natsemi.html
 51 */
 52 
 53 /* The user-configurable values.
 54    These may be modified when a driver module is loaded.*/
 55 
 56 static int debug = 1;                   /* 1 normal messages, 0 quiet .. 7 verbose. */
 57 /* Maximum events (Rx packets, etc.) to handle at each interrupt. */
 58 static int max_interrupt_work = 20;
 59 static int mtu = 0;
 60 /* Maximum number of multicast addresses to filter (vs. rx-all-multicast).
 61    This chip uses a 512 element hash table based on the Ethernet CRC.  */
 62 static int multicast_filter_limit = 100;
 63 
 64 /* Set the copy breakpoint for the copy-only-tiny-frames scheme.
 65    Setting to > 1518 effectively disables this feature. */
 66 static int rx_copybreak = 0;
 67 
 68 /* Used to pass the media type, etc.
 69    Both 'options[]' and 'full_duplex[]' should exist for driver
 70    interoperability.
 71    The media type is usually passed in 'options[]'.
 72 */
 73 #define MAX_UNITS 8             /* More are supported, limit only on options */
 74 static int options[MAX_UNITS] = {-1, -1, -1, -1, -1, -1, -1, -1};
 75 static int full_duplex[MAX_UNITS] = {-1, -1, -1, -1, -1, -1, -1, -1};
 76 
 77 /* Operational parameters that are set at compile time. */
 78 
 79 /* Keep the ring sizes a power of two for compile efficiency.
 80    The compiler will convert <unsigned>'%'<2^N> into a bit mask.
 81    Making the Tx ring too large decreases the effectiveness of channel
 82    bonding and packet priority.
 83    There are no ill effects from too-large receive rings. */
 84 #define TX_RING_SIZE    16
 85 #define TX_QUEUE_LEN    10              /* Limit ring entries actually used.  */
 86 #define RX_RING_SIZE    32
 87 
 88 /* Operational parameters that usually are not changed. */
 89 /* Time in jiffies before concluding the transmitter is hung. */
 90 #define TX_TIMEOUT  (2*HZ)
 91 
 92 #define PKT_BUF_SZ              1536                    /* Size of each temporary Rx buffer.*/
 93 
 94 #if !defined(__OPTIMIZE__)
 95 #warning  You must compile this file with the correct options!
 96 #warning  See the last lines of the source file.
 97 #error You must compile this driver with "-O".
 98 #endif
 99 
100 /* Include files, designed to support most kernel versions 2.0.0 and later. */
101 #include <linux/version.h>
102 #include <linux/module.h>
103 #include <linux/kernel.h>
104 #include <linux/string.h>
105 #include <linux/timer.h>
106 #include <linux/errno.h>
107 #include <linux/ioport.h>
108 #include <linux/malloc.h>
109 #include <linux/interrupt.h>
110 #include <linux/pci.h>
111 #include <linux/netdevice.h>
112 #include <linux/etherdevice.h>
113 #include <linux/skbuff.h>
114 #include <linux/init.h>
115 #include <linux/spinlock.h>
116 #include <asm/processor.h>              /* Processor type for cache alignment. */
117 #include <asm/bitops.h>
118 #include <asm/io.h>
119 
120 /* Condensed operations for readability. */
121 #define virt_to_le32desc(addr)  cpu_to_le32(virt_to_bus(addr))
122 #define le32desc_to_virt(addr)  bus_to_virt(le32_to_cpu(addr))
123 
124 MODULE_AUTHOR("Donald Becker <becker@scyld.com>");
125 MODULE_DESCRIPTION("National Semiconductor DP83810 series PCI Ethernet driver");
126 MODULE_PARM(max_interrupt_work, "i");
127 MODULE_PARM(mtu, "i");
128 MODULE_PARM(debug, "i");
129 MODULE_PARM(rx_copybreak, "i");
130 MODULE_PARM(options, "1-" __MODULE_STRING(MAX_UNITS) "i");
131 MODULE_PARM(full_duplex, "1-" __MODULE_STRING(MAX_UNITS) "i");
132 
133 /*
134                                 Theory of Operation
135 
136 I. Board Compatibility
137 
138 This driver is designed for National Semiconductor DP83815 PCI Ethernet NIC.
139 It also works with other chips in in the DP83810 series.
140 
141 II. Board-specific settings
142 
143 This driver requires the PCI interrupt line to be valid.
144 It honors the EEPROM-set values. 
145 
146 III. Driver operation
147 
148 IIIa. Ring buffers
149 
150 This driver uses two statically allocated fixed-size descriptor lists
151 formed into rings by a branch from the final descriptor to the beginning of
152 the list.  The ring sizes are set at compile time by RX/TX_RING_SIZE.
153 The NatSemi design uses a 'next descriptor' pointer that the driver forms
154 into a list. 
155 
156 IIIb/c. Transmit/Receive Structure
157 
158 This driver uses a zero-copy receive and transmit scheme.
159 The driver allocates full frame size skbuffs for the Rx ring buffers at
160 open() time and passes the skb->data field to the chip as receive data
161 buffers.  When an incoming frame is less than RX_COPYBREAK bytes long,
162 a fresh skbuff is allocated and the frame is copied to the new skbuff.
163 When the incoming frame is larger, the skbuff is passed directly up the
164 protocol stack.  Buffers consumed this way are replaced by newly allocated
165 skbuffs in a later phase of receives.
166 
167 The RX_COPYBREAK value is chosen to trade-off the memory wasted by
168 using a full-sized skbuff for small frames vs. the copying costs of larger
169 frames.  New boards are typically used in generously configured machines
170 and the underfilled buffers have negligible impact compared to the benefit of
171 a single allocation size, so the default value of zero results in never
172 copying packets.  When copying is done, the cost is usually mitigated by using
173 a combined copy/checksum routine.  Copying also preloads the cache, which is
174 most useful with small frames.
175 
176 A subtle aspect of the operation is that unaligned buffers are not permitted
177 by the hardware.  Thus the IP header at offset 14 in an ethernet frame isn't
178 longword aligned for further processing.  On copies frames are put into the
179 skbuff at an offset of "+2", 16-byte aligning the IP header.
180 
181 IIId. Synchronization
182 
183 The driver runs as two independent, single-threaded flows of control.  One
184 is the send-packet routine, which enforces single-threaded use by the
185 dev->tbusy flag.  The other thread is the interrupt handler, which is single
186 threaded by the hardware and interrupt handling software.
187 
188 The send packet thread has partial control over the Tx ring and 'dev->tbusy'
189 flag.  It sets the tbusy flag whenever it's queuing a Tx packet. If the next
190 queue slot is empty, it clears the tbusy flag when finished otherwise it sets
191 the 'lp->tx_full' flag.
192 
193 The interrupt handler has exclusive control over the Rx ring and records stats
194 from the Tx ring.  After reaping the stats, it marks the Tx queue entry as
195 empty by incrementing the dirty_tx mark. Iff the 'lp->tx_full' flag is set, it
196 clears both the tx_full and tbusy flags.
197 
198 IV. Notes
199 
200 NatSemi PCI network controllers are very uncommon.
201 
202 IVb. References
203 
204 http://www.scyld.com/expert/100mbps.html
205 http://www.scyld.com/expert/NWay.html
206 Datasheet is available from:
207 http://www.national.com/pf/DP/DP83815.html
208 
209 IVc. Errata
210 
211 None characterised.
212 */
213 
214 
215 
216 enum pcistuff {
217         PCI_USES_IO = 0x01,
218         PCI_USES_MEM = 0x02,
219         PCI_USES_MASTER = 0x04,
220         PCI_ADDR0 = 0x08,
221         PCI_ADDR1 = 0x10,
222 };
223 
224 /* MMIO operations required */
225 #define PCI_IOTYPE (PCI_USES_MASTER | PCI_USES_MEM | PCI_ADDR1)
226 
227 
228 /* array of board data directly indexed by pci_tbl[x].driver_data */
229 static struct {
230         const char *name;
231         unsigned long flags;
232 } natsemi_pci_info[] __devinitdata = {
233         { "NatSemi DP83815", PCI_IOTYPE },
234 };
235 
236 static struct pci_device_id natsemi_pci_tbl[] __devinitdata = {
237         { 0x100B, 0x0020, PCI_ANY_ID, PCI_ANY_ID, },
238         { 0, },
239 };
240 MODULE_DEVICE_TABLE(pci, natsemi_pci_tbl);
241 
242 /* Offsets to the device registers.
243    Unlike software-only systems, device drivers interact with complex hardware.
244    It's not useful to define symbolic names for every register bit in the
245    device.
246 */
247 enum register_offsets {
248         ChipCmd=0x00, ChipConfig=0x04, EECtrl=0x08, PCIBusCfg=0x0C,
249         IntrStatus=0x10, IntrMask=0x14, IntrEnable=0x18,
250         TxRingPtr=0x20, TxConfig=0x24,
251         RxRingPtr=0x30, RxConfig=0x34, ClkRun=0x3C,
252         WOLCmd=0x40, PauseCmd=0x44, RxFilterAddr=0x48, RxFilterData=0x4C,
253         BootRomAddr=0x50, BootRomData=0x54, StatsCtrl=0x5C, StatsData=0x60,
254         RxPktErrs=0x60, RxMissed=0x68, RxCRCErrs=0x64,
255 };
256 
257 /* Bit in ChipCmd. */
258 enum ChipCmdBits {
259         ChipReset=0x100, RxReset=0x20, TxReset=0x10, RxOff=0x08, RxOn=0x04,
260         TxOff=0x02, TxOn=0x01,
261 };
262 
263 /* Bits in the interrupt status/mask registers. */
264 enum intr_status_bits {
265         IntrRxDone=0x0001, IntrRxIntr=0x0002, IntrRxErr=0x0004, IntrRxEarly=0x0008,
266         IntrRxIdle=0x0010, IntrRxOverrun=0x0020,
267         IntrTxDone=0x0040, IntrTxIntr=0x0080, IntrTxErr=0x0100,
268         IntrTxIdle=0x0200, IntrTxOverrun=0x0400,
269         StatsMax=0x0800, LinkChange=0x4000,
270         WOLPkt=0x2000,
271         RxResetDone=0x1000000, TxResetDone=0x2000000,
272         IntrPCIErr=0x00f00000,
273         IntrAbnormalSummary=0xCD20,
274 };
275 
276 /* Bits in the RxMode register. */
277 enum rx_mode_bits {
278         EnableFilter            = 0x80000000,
279         AcceptBroadcast         = 0x40000000,
280         AcceptAllMulticast      = 0x20000000,
281         AcceptAllPhys           = 0x10000000,
282         AcceptMyPhys            = 0x08000000,
283         AcceptMulticast         = 0x00200000,
284         AcceptErr=0x20, /* these 2 are in another register */
285         AcceptRunt=0x10,/* and are not used in this driver */
286 };
287 
288 /* The Rx and Tx buffer descriptors. */
289 /* Note that using only 32 bit fields simplifies conversion to big-endian
290    architectures. */
291 struct netdev_desc {
292         u32 next_desc;
293         s32 cmd_status;
294         u32 addr;
295         u32 software_use;
296 };
297 
298 /* Bits in network_desc.status */
299 enum desc_status_bits {
300         DescOwn=0x80000000, DescMore=0x40000000, DescIntr=0x20000000,
301         DescNoCRC=0x10000000,
302         DescPktOK=0x08000000, RxTooLong=0x00400000,
303 };
304 
305 #define PRIV_ALIGN      15      /* Required alignment mask */
306 struct netdev_private {
307         /* Descriptor rings first for alignment. */
308         struct netdev_desc rx_ring[RX_RING_SIZE];
309         struct netdev_desc tx_ring[TX_RING_SIZE];
310         /* The addresses of receive-in-place skbuffs. */
311         struct sk_buff* rx_skbuff[RX_RING_SIZE];
312         /* The saved address of a sent-in-place packet/buffer, for later free(). */
313         struct sk_buff* tx_skbuff[TX_RING_SIZE];
314         struct net_device_stats stats;
315         struct timer_list timer;        /* Media monitoring timer. */
316         /* Frequently used values: keep some adjacent for cache effect. */
317         struct pci_dev *pci_dev;
318         struct netdev_desc *rx_head_desc;
319         unsigned int cur_rx, dirty_rx;          /* Producer/consumer ring indices */
320         unsigned int cur_tx, dirty_tx;
321         unsigned int rx_buf_sz;                         /* Based on MTU+slack. */
322         unsigned int tx_full:1;                         /* The Tx queue is full. */
323         /* These values are keep track of the transceiver/media in use. */
324         unsigned int full_duplex:1;                     /* Full-duplex operation requested. */
325         unsigned int duplex_lock:1;
326         unsigned int medialock:1;                       /* Do not sense media. */
327         unsigned int default_port:4;            /* Last dev->if_port value. */
328         /* Rx filter. */
329         u32 cur_rx_mode;
330         u32 rx_filter[16];
331         /* FIFO and PCI burst thresholds. */
332         int tx_config, rx_config;
333         /* original contents of ClkRun register */
334         int SavedClkRun;
335         /* MII transceiver section. */
336         u16 advertising;                                        /* NWay media advertisement */
337         
338         unsigned int iosize;
339         spinlock_t lock;
340 };
341 
342 static int  eeprom_read(long ioaddr, int location);
343 static int  mdio_read(struct net_device *dev, int phy_id, int location);
344 static void mdio_write(struct net_device *dev, int phy_id, int location, int value);
345 static int  netdev_open(struct net_device *dev);
346 static void check_duplex(struct net_device *dev);
347 static void netdev_timer(unsigned long data);
348 static void tx_timeout(struct net_device *dev);
349 static void init_ring(struct net_device *dev);
350 static int  start_tx(struct sk_buff *skb, struct net_device *dev);
351 static void intr_handler(int irq, void *dev_instance, struct pt_regs *regs);
352 static void netdev_error(struct net_device *dev, int intr_status);
353 static int  netdev_rx(struct net_device *dev);
354 static void netdev_error(struct net_device *dev, int intr_status);
355 static void set_rx_mode(struct net_device *dev);
356 static struct net_device_stats *get_stats(struct net_device *dev);
357 static int mii_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
358 static int  netdev_close(struct net_device *dev);
359 
360 
361 static int __devinit natsemi_probe1 (struct pci_dev *pdev,
362                                      const struct pci_device_id *ent)
363 {
364         struct net_device *dev;
365         struct netdev_private *np;
366         int i, option, irq = pdev->irq, chip_idx = ent->driver_data;
367         static int find_cnt = -1;
368         static int printed_version;
369         unsigned long ioaddr, iosize;
370         const int pcibar = 1; /* PCI base address register */
371 
372         if ((debug <= 1) && !printed_version++)
373                 printk(KERN_INFO "%s" KERN_INFO "%s" KERN_INFO "%s",
374                         version1, version2, version3);
375 
376         find_cnt++;
377         option = find_cnt < MAX_UNITS ? options[find_cnt] : 0;
378         ioaddr = pci_resource_start(pdev, pcibar);
379         iosize = pci_resource_len(pdev, pcibar);
380         
381         if (pci_enable_device(pdev))
382                 return -EIO;
383         if (natsemi_pci_info[chip_idx].flags & PCI_USES_MASTER)
384                 pci_set_master(pdev);
385 
386         dev = init_etherdev(NULL, sizeof (struct netdev_private));
387         if (!dev)
388                 return -ENOMEM;
389         SET_MODULE_OWNER(dev);
390 
391         {
392                 void *mmio;
393                 if (request_mem_region(ioaddr, iosize, dev->name) == NULL) {
394                         unregister_netdev(dev);
395                         kfree(dev);
396                         return -EBUSY;
397                 }
398                 mmio = ioremap (ioaddr, iosize);
399                 if (!mmio) {
400                         release_mem_region(ioaddr, iosize);
401                         unregister_netdev(dev);
402                         kfree(dev);
403                         return -ENOMEM;
404                 }
405                 ioaddr = (unsigned long) mmio;
406         }
407 
408         printk(KERN_INFO "%s: %s at 0x%lx, ",
409                    dev->name, natsemi_pci_info[chip_idx].name, ioaddr);
410 
411         for (i = 0; i < ETH_ALEN/2; i++) {
412                 /* weird organization */
413                 unsigned short a;
414                 a = (le16_to_cpu(eeprom_read(ioaddr, i + 6)) >> 15) + 
415                     (le16_to_cpu(eeprom_read(ioaddr, i + 7)) << 1);
416                 ((u16 *)dev->dev_addr)[i] = a;
417         }
418         for (i = 0; i < ETH_ALEN-1; i++)
419                         printk("%2.2x:", dev->dev_addr[i]);
420         printk("%2.2x, IRQ %d.\n", dev->dev_addr[i], irq);
421 
422 #if ! defined(final_version) /* Dump the EEPROM contents during development. */
423         if (debug > 4)
424                 for (i = 0; i < 64; i++)
425                         printk("%4.4x%s",
426                                    eeprom_read(ioaddr, i), i % 16 != 15 ? " " : "\n");
427 #endif
428 
429         /* Reset the chip to erase previous misconfiguration. */
430         writel(ChipReset, ioaddr + ChipCmd);
431 
432         dev->base_addr = ioaddr;
433         dev->irq = irq;
434 
435         np = dev->priv;
436 
437         np->pci_dev = pdev;
438         pdev->driver_data = dev;
439         np->iosize = iosize;
440         spin_lock_init(&np->lock);
441 
442         if (dev->mem_start)
443                 option = dev->mem_start;
444 
445         /* The lower four bits are the media type. */
446         if (option > 0) {
447                 if (option & 0x200)
448                         np->full_duplex = 1;
449                 np->default_port = option & 15;
450                 if (np->default_port)
451                         np->medialock = 1;
452         }
453         if (find_cnt < MAX_UNITS  &&  full_duplex[find_cnt] > 0)
454                 np->full_duplex = 1;
455 
456         if (np->full_duplex)
457                 np->duplex_lock = 1;
458 
459         /* The chip-specific entries in the device structure. */
460         dev->open = &netdev_open;
461         dev->hard_start_xmit = &start_tx;
462         dev->stop = &netdev_close;
463         dev->get_stats = &get_stats;
464         dev->set_multicast_list = &set_rx_mode;
465         dev->do_ioctl = &mii_ioctl;
466         dev->tx_timeout = &tx_timeout;
467         dev->watchdog_timeo = TX_TIMEOUT;
468 
469         if (mtu)
470                 dev->mtu = mtu;
471 
472         np->advertising = readl(ioaddr + 0x90);
473         printk(KERN_INFO "%s: Transceiver status 0x%4.4x advertising %4.4x.\n",
474                    dev->name, (int)readl(ioaddr + 0x84), np->advertising);
475 
476         return 0;
477 }
478 
479 
480 /* Read the EEPROM and MII Management Data I/O (MDIO) interfaces.
481    The EEPROM code is for the common 93c06/46 EEPROMs with 6 bit addresses. */
482 
483 /* Delay between EEPROM clock transitions.
484    No extra delay is needed with 33Mhz PCI, but future 66Mhz access may need
485    a delay.  Note that pre-2.0.34 kernels had a cache-alignment bug that
486    made udelay() unreliable.
487    The old method of using an ISA access as a delay, __SLOW_DOWN_IO__, is
488    depricated.
489 */
490 #define eeprom_delay(ee_addr)   readl(ee_addr)
491 
492 enum EEPROM_Ctrl_Bits {
493         EE_ShiftClk=0x04, EE_DataIn=0x01, EE_ChipSelect=0x08, EE_DataOut=0x02,
494 };
495 #define EE_Write0 (EE_ChipSelect)
496 #define EE_Write1 (EE_ChipSelect | EE_DataIn)
497 
498 /* The EEPROM commands include the alway-set leading bit. */
499 enum EEPROM_Cmds {
500         EE_WriteCmd=(5 << 6), EE_ReadCmd=(6 << 6), EE_EraseCmd=(7 << 6),
501 };
502 
503 static int eeprom_read(long addr, int location)
504 {
505         int i;
506         int retval = 0;
507         int ee_addr = addr + EECtrl;
508         int read_cmd = location | EE_ReadCmd;
509         writel(EE_Write0, ee_addr);
510 
511         /* Shift the read command bits out. */
512         for (i = 10; i >= 0; i--) {
513                 short dataval = (read_cmd & (1 << i)) ? EE_Write1 : EE_Write0;
514                 writel(dataval, ee_addr);
515                 eeprom_delay(ee_addr);
516                 writel(dataval | EE_ShiftClk, ee_addr);
517                 eeprom_delay(ee_addr);
518         }
519         writel(EE_ChipSelect, ee_addr);
520 
521         for (i = 16; i > 0; i--) {
522                 writel(EE_ChipSelect | EE_ShiftClk, ee_addr);
523                 eeprom_delay(ee_addr);
524                 /* data bits are LSB first */
525                 retval = (retval >> 1) | ((readl(ee_addr) & EE_DataOut) ? 0x8000 : 0);
526                 writel(EE_ChipSelect, ee_addr);
527                 eeprom_delay(ee_addr);
528         }
529 
530         /* Terminate the EEPROM access. */
531         writel(EE_Write0, ee_addr);
532         writel(0, ee_addr);
533         return retval;
534 }
535 
536 /*  MII transceiver control section.
537         The 83815 series has an internal transceiver, and we present the
538         management registers as if they were MII connected. */
539 
540 static int mdio_read(struct net_device *dev, int phy_id, int location)
541 {
542         if (phy_id == 1 && location < 32)
543                 return readl(dev->base_addr + 0x80 + (location<<2)) & 0xffff;
544         else
545                 return 0xffff;
546 }
547 
548 static void mdio_write(struct net_device *dev, int phy_id, int location, int value)
549 {
550         if (phy_id == 1 && location < 32)
551                 writew(value, dev->base_addr + 0x80 + (location<<2));
552 }
553 
554 
555 static int netdev_open(struct net_device *dev)
556 {
557         struct netdev_private *np = (struct netdev_private *)dev->priv;
558         long ioaddr = dev->base_addr;
559         int i;
560 
561         /* Do we need to reset the chip??? */
562 
563         i = request_irq(dev->irq, &intr_handler, SA_SHIRQ, dev->name, dev);
564         if (i) return i;
565 
566         if (debug > 1)
567                 printk(KERN_DEBUG "%s: netdev_open() irq %d.\n",
568                            dev->name, dev->irq);
569 
570         init_ring(dev);
571 
572         writel(virt_to_bus(np->rx_ring), ioaddr + RxRingPtr);
573         writel(virt_to_bus(np->tx_ring), ioaddr + TxRingPtr);
574 
575         for (i = 0; i < ETH_ALEN; i += 2) {
576                 writel(i, ioaddr + RxFilterAddr);
577                 writew(dev->dev_addr[i] + (dev->dev_addr[i+1] << 8),
578                            ioaddr + RxFilterData);
579         }
580 
581         /* Initialize other registers. */
582         /* Configure the PCI bus bursts and FIFO thresholds. */
583         /* Configure for standard, in-spec Ethernet. */
584         np->tx_config = (1<<28) +       /* Automatic transmit padding */
585                         (1<<23) +       /* Excessive collision retry */
586                         (0x0<<20) +     /* Max DMA burst = 512 byte */
587                         (8<<8) +        /* fill threshold = 256 byte */
588                         2;              /* drain threshold = 64 byte */
589         writel(np->tx_config, ioaddr + TxConfig);
590         np->rx_config = (0x0<<20)       /* Max DMA burst = 512 byte */ +
591                         (0x8<<1);       /* Drain Threshold = 64 byte */
592         writel(np->rx_config, ioaddr + RxConfig);
593 
594         if (dev->if_port == 0)
595                 dev->if_port = np->default_port;
596 
597         /* Disable PME */
598         np->SavedClkRun = readl(ioaddr + ClkRun);
599         writel(np->SavedClkRun & ~0x100, ioaddr + ClkRun);
600 
601         netif_start_queue(dev);
602 
603         check_duplex(dev);
604         set_rx_mode(dev);
605 
606         /* Enable interrupts by setting the interrupt mask.
607          * We don't listen for TxDone interrupts and rely on TxIdle. */
608         writel(IntrAbnormalSummary | IntrTxIdle | IntrRxIdle | IntrRxDone,
609                 ioaddr + IntrMask);
610         writel(1, ioaddr + IntrEnable);
611 
612         writel(RxOn | TxOn, ioaddr + ChipCmd);
613         writel(4, ioaddr + StatsCtrl);                                  /* Clear Stats */
614 
615         if (debug > 2)
616                 printk(KERN_DEBUG "%s: Done netdev_open(), status: %x.\n",
617                            dev->name, (int)readl(ioaddr + ChipCmd));
618 
619         /* Set the timer to check for link beat. */
620         init_timer(&np->timer);
621         np->timer.expires = jiffies + 3*HZ;
622         np->timer.data = (unsigned long)dev;
623         np->timer.function = &netdev_timer;                             /* timer handler */
624         add_timer(&np->timer);
625 
626         return 0;
627 }
628 
629 static void check_duplex(struct net_device *dev)
630 {
631         struct netdev_private *np = (struct netdev_private *)dev->priv;
632         long ioaddr = dev->base_addr;
633         int duplex;
634 
635         if (np->duplex_lock)
636                 return;
637         duplex = readl(ioaddr + ChipConfig) & 0x20000000 ? 1 : 0;
638         if (np->full_duplex != duplex) {
639                 np->full_duplex = duplex;
640                 if (debug)
641                         printk(KERN_INFO "%s: Setting %s-duplex based on negotiated link"
642                                    " capability.\n", dev->name,
643                                    duplex ? "full" : "half");
644                 if (duplex) {
645                         np->rx_config |= 0x10000000;
646                         np->tx_config |= 0xC0000000;
647                 } else {
648                         np->rx_config &= ~0x10000000;
649                         np->tx_config &= ~0xC0000000;
650                 }
651                 writel(np->tx_config, ioaddr + TxConfig);
652                 writel(np->rx_config, ioaddr + RxConfig);
653         }
654 }
655 
656 static void netdev_timer(unsigned long data)
657 {
658         struct net_device *dev = (struct net_device *)data;
659         struct netdev_private *np = (struct netdev_private *)dev->priv;
660         long ioaddr = dev->base_addr;
661         int next_tick = 60*HZ;
662 
663         if (debug > 3)
664                 printk(KERN_DEBUG "%s: Media selection timer tick, status %8.8x.\n",
665                            dev->name, (int)readl(ioaddr + IntrStatus));
666         check_duplex(dev);
667         np->timer.expires = jiffies + next_tick;
668         add_timer(&np->timer);
669 }
670 
671 static void tx_timeout(struct net_device *dev)
672 {
673         struct netdev_private *np = (struct netdev_private *)dev->priv;
674         long ioaddr = dev->base_addr;
675 
676         printk(KERN_WARNING "%s: Transmit timed out, status %8.8x,"
677                    " resetting...\n", dev->name, (int)readl(ioaddr + TxRingPtr));
678 
679 #ifndef __alpha__
680         {
681                 int i;
682                 printk(KERN_DEBUG "  Rx ring %8.8x: ", (int)np->rx_ring);
683                 for (i = 0; i < RX_RING_SIZE; i++)
684                         printk(" %8.8x", (unsigned int)np->rx_ring[i].cmd_status);
685                 printk("\n"KERN_DEBUG"  Tx ring %8.8x: ", (int)np->tx_ring);
686                 for (i = 0; i < TX_RING_SIZE; i++)
687                         printk(" %4.4x", np->tx_ring[i].cmd_status);
688                 printk("\n");
689         }
690 #endif
691 
692         /* Perhaps we should reinitialize the hardware here. */
693         dev->if_port = 0;
694         /* Stop and restart the chip's Tx processes . */
695 
696         /* Trigger an immediate transmit demand. */
697 
698         dev->trans_start = jiffies;
699         np->stats.tx_errors++;
700         return;
701 }
702 
703 
704 /* Initialize the Rx and Tx rings, along with various 'dev' bits. */
705 static void init_ring(struct net_device *dev)
706 {
707         struct netdev_private *np = (struct netdev_private *)dev->priv;
708         int i;
709 
710         np->tx_full = 0;
711         np->cur_rx = np->cur_tx = 0;
712         np->dirty_rx = np->dirty_tx = 0;
713 
714         np->rx_buf_sz = (dev->mtu <= 1500 ? PKT_BUF_SZ : dev->mtu + 32);
715         np->rx_head_desc = &np->rx_ring[0];
716 
717         /* Initialize all Rx descriptors. */
718         for (i = 0; i < RX_RING_SIZE; i++) {
719                 np->rx_ring[i].next_desc = virt_to_le32desc(&np->rx_ring[i+1]);
720                 np->rx_ring[i].cmd_status = DescOwn;
721                 np->rx_skbuff[i] = 0;
722         }
723         /* Mark the last entry as wrapping the ring. */
724         np->rx_ring[i-1].next_desc = virt_to_le32desc(&np->rx_ring[0]);
725 
726         /* Fill in the Rx buffers.  Handle allocation failure gracefully. */
727         for (i = 0; i < RX_RING_SIZE; i++) {
728                 struct sk_buff *skb = dev_alloc_skb(np->rx_buf_sz);
729                 np->rx_skbuff[i] = skb;
730                 if (skb == NULL)
731                         break;
732                 skb->dev = dev;                 /* Mark as being used by this device. */
733                 np->rx_ring[i].addr = virt_to_le32desc(skb->tail);
734                 np->rx_ring[i].cmd_status =
735                         cpu_to_le32(np->rx_buf_sz);
736         }
737         np->dirty_rx = (unsigned int)(i - RX_RING_SIZE);
738 
739         for (i = 0; i < TX_RING_SIZE; i++) {
740                 np->tx_skbuff[i] = 0;
741                 np->tx_ring[i].next_desc = virt_to_le32desc(&np->tx_ring[i+1]);
742                 np->tx_ring[i].cmd_status = 0;
743         }
744         np->tx_ring[i-1].next_desc = virt_to_le32desc(&np->tx_ring[0]);
745         return;
746 }
747 
748 static int start_tx(struct sk_buff *skb, struct net_device *dev)
749 {
750         struct netdev_private *np = (struct netdev_private *)dev->priv;
751         unsigned entry;
752 
753         /* Note: Ordering is important here, set the field with the
754            "ownership" bit last, and only then increment cur_tx. */
755 
756         /* Calculate the next Tx descriptor entry. */
757         entry = np->cur_tx % TX_RING_SIZE;
758 
759         np->tx_skbuff[entry] = skb;
760 
761         np->tx_ring[entry].addr = virt_to_le32desc(skb->data);
762         np->tx_ring[entry].cmd_status = cpu_to_le32(DescOwn | skb->len);
763         np->cur_tx++;
764 
765         /* StrongARM: Explicitly cache flush np->tx_ring and skb->data,skb->len. */
766 
767         if (np->cur_tx - np->dirty_tx >= TX_QUEUE_LEN - 1) {
768                 np->tx_full = 1;
769                 netif_stop_queue(dev);
770         }
771         /* Wake the potentially-idle transmit channel. */
772         writel(TxOn, dev->base_addr + ChipCmd);
773 
774         dev->trans_start = jiffies;
775 
776         if (debug > 4) {
777                 printk(KERN_DEBUG "%s: Transmit frame #%d queued in slot %d.\n",
778                            dev->name, np->cur_tx, entry);
779         }
780         return 0;
781 }
782 
783 /* The interrupt handler does all of the Rx thread work and cleans up
784    after the Tx thread. */
785 static void intr_handler(int irq, void *dev_instance, struct pt_regs *rgs)
786 {
787         struct net_device *dev = (struct net_device *)dev_instance;
788         struct netdev_private *np;
789         long ioaddr;
790         int boguscnt = max_interrupt_work;
791 
792 #ifndef final_version                   /* Can never occur. */
793         if (dev == NULL) {
794                 printk (KERN_ERR "Netdev interrupt handler(): IRQ %d for unknown "
795                                 "device.\n", irq);
796                 return;
797         }
798 #endif
799 
800         ioaddr = dev->base_addr;
801         np = (struct netdev_private *)dev->priv;
802 
803         spin_lock(&np->lock);
804 
805         do {
806                 u32 intr_status = readl(ioaddr + IntrStatus);
807 
808                 /* Acknowledge all of the current interrupt sources ASAP. */
809                 writel(intr_status & 0x000ffff, ioaddr + IntrStatus);
810 
811                 if (debug > 4)
812                         printk(KERN_DEBUG "%s: Interrupt, status %4.4x.\n",
813                                    dev->name, intr_status);
814 
815                 if (intr_status == 0)
816                         break;
817 
818                 if (intr_status & (IntrRxDone | IntrRxErr | IntrRxIdle | IntrRxOverrun))
819                         netdev_rx(dev);
820 
821                 for (; np->cur_tx - np->dirty_tx > 0; np->dirty_tx++) {
822                         int entry = np->dirty_tx % TX_RING_SIZE;
823                         if (np->tx_ring[entry].cmd_status & cpu_to_le32(DescOwn))
824                                 break;
825                         if (np->tx_ring[entry].cmd_status & cpu_to_le32(0x08000000)) {
826                                 np->stats.tx_packets++;
827 #if LINUX_VERSION_CODE > 0x20127
828                                 np->stats.tx_bytes += np->tx_skbuff[entry]->len;
829 #endif
830                         } else {                        /* Various Tx errors */
831                                 int tx_status = le32_to_cpu(np->tx_ring[entry].cmd_status);
832                                 if (tx_status & 0x04010000) np->stats.tx_aborted_errors++;
833                                 if (tx_status & 0x02000000) np->stats.tx_fifo_errors++;
834                                 if (tx_status & 0x01000000) np->stats.tx_carrier_errors++;
835                                 if (tx_status & 0x00200000) np->stats.tx_window_errors++;
836                                 np->stats.tx_errors++;
837                         }
838                         /* Free the original skb. */
839                         dev_kfree_skb_irq(np->tx_skbuff[entry]);
840                         np->tx_skbuff[entry] = 0;
841                 }
842                 if (np->tx_full
843                         && np->cur_tx - np->dirty_tx < TX_QUEUE_LEN - 4) {
844                         /* The ring is no longer full, wake queue. */
845                         np->tx_full = 0;
846                         netif_wake_queue(dev);
847                 }
848 
849                 /* Abnormal error summary/uncommon events handlers. */
850                 if (intr_status & IntrAbnormalSummary)
851                         netdev_error(dev, intr_status);
852 
853                 if (--boguscnt < 0) {
854                         printk(KERN_WARNING "%s: Too much work at interrupt, "
855                                    "status=0x%4.4x.\n",
856                                    dev->name, intr_status);
857                         break;
858                 }
859         } while (1);
860 
861         if (debug > 3)
862                 printk(KERN_DEBUG "%s: exiting interrupt, status=%#4.4x.\n",
863                            dev->name, (int)readl(ioaddr + IntrStatus));
864 
865 #ifndef final_version
866         /* Code that should never be run!  Perhaps remove after testing.. */
867         {
868                 static int stopit = 10;
869                 if (!netif_running(dev)  &&  --stopit < 0) {
870                         printk(KERN_ERR "%s: Emergency stop, looping startup interrupt.\n",
871                                    dev->name);
872                         free_irq(irq, dev);
873                 }
874         }
875 #endif
876 
877         spin_unlock(&np->lock);
878 }
879 
880 /* This routine is logically part of the interrupt handler, but separated
881    for clarity and better register allocation. */
882 static int netdev_rx(struct net_device *dev)
883 {
884         struct netdev_private *np = (struct netdev_private *)dev->priv;
885         int entry = np->cur_rx % RX_RING_SIZE;
886         int boguscnt = np->dirty_rx + RX_RING_SIZE - np->cur_rx;
887         s32 desc_status = le32_to_cpu(np->rx_head_desc->cmd_status);
888 
889         /* If the driver owns the next entry it's a new packet. Send it up. */
890         while (desc_status < 0) {        /* e.g. & DescOwn */
891                 if (debug > 4)
892                         printk(KERN_DEBUG "  In netdev_rx() entry %d status was %8.8x.\n",
893                                    entry, desc_status);
894                 if (--boguscnt < 0)
895                         break;
896 
897                 if ((desc_status & (DescMore|DescPktOK|RxTooLong)) != DescPktOK) {
898                         if (desc_status & DescMore) {
899                                 printk(KERN_WARNING "%s: Oversized(?) Ethernet frame spanned "
900                                            "multiple buffers, entry %#x status %x.\n",
901                                            dev->name, np->cur_rx, desc_status);
902                                 np->stats.rx_length_errors++;
903                         } else {
904                                 /* There was a error. */
905                                 if (debug > 2)
906                                         printk(KERN_DEBUG "  netdev_rx() Rx error was %8.8x.\n",
907                                                    desc_status);
908                                 np->stats.rx_errors++;
909                                 if (desc_status & 0x06000000) np->stats.rx_over_errors++;
910                                 if (desc_status & 0x00600000) np->stats.rx_length_errors++;
911                                 if (desc_status & 0x00140000) np->stats.rx_frame_errors++;
912                                 if (desc_status & 0x00080000) np->stats.rx_crc_errors++;
913                         }
914                 } else {
915                         struct sk_buff *skb;
916                         int pkt_len = (desc_status & 0x0fff) - 4;       /* Omit CRC size. */
917                         /* Check if the packet is long enough to accept without copying
918                            to a minimally-sized skbuff. */
919                         if (pkt_len < rx_copybreak
920                                 && (skb = dev_alloc_skb(pkt_len + 2)) != NULL) {
921                                 skb->dev = dev;
922                                 skb_reserve(skb, 2);    /* 16 byte align the IP header */
923 #if HAS_IP_COPYSUM
924                                 eth_copy_and_sum(skb, np->rx_skbuff[entry]->tail, pkt_len, 0);
925                                 skb_put(skb, pkt_len);
926 #else
927                                 memcpy(skb_put(skb, pkt_len), np->rx_skbuff[entry]->tail,
928                                            pkt_len);
929 #endif
930                         } else {
931                                 char *temp = skb_put(skb = np->rx_skbuff[entry], pkt_len);
932                                 np->rx_skbuff[entry] = NULL;
933 #ifndef final_version                           /* Remove after testing. */
934                                 if (le32desc_to_virt(np->rx_ring[entry].addr) != temp)
935                                         printk(KERN_ERR "%s: Internal fault: The skbuff addresses "
936                                                    "do not match in netdev_rx: %p vs. %p / %p.\n",
937                                                    dev->name,
938                                                    le32desc_to_virt(np->rx_ring[entry].addr),
939                                                    skb->head, temp);
940 #endif
941                         }
942 #ifndef final_version                           /* Remove after testing. */
943                         /* You will want this info for the initial debug. */
944                         if (debug > 5)
945                                 printk(KERN_DEBUG "  Rx data %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:"
946                                            "%2.2x %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x %2.2x%2.2x "
947                                            "%d.%d.%d.%d.\n",
948                                            skb->data[0], skb->data[1], skb->data[2], skb->data[3],
949                                            skb->data[4], skb->data[5], skb->data[6], skb->data[7],
950                                            skb->data[8], skb->data[9], skb->data[10],
951                                            skb->data[11], skb->data[12], skb->data[13],
952                                            skb->data[14], skb->data[15], skb->data[16],
953                                            skb->data[17]);
954 #endif
955                         skb->protocol = eth_type_trans(skb, dev);
956                         /* W/ hardware checksum: skb->ip_summed = CHECKSUM_UNNECESSARY; */
957                         netif_rx(skb);
958                         dev->last_rx = jiffies;
959                         np->stats.rx_packets++;
960 #if LINUX_VERSION_CODE > 0x20127
961                         np->stats.rx_bytes += pkt_len;
962 #endif
963                 }
964                 entry = (++np->cur_rx) % RX_RING_SIZE;
965                 np->rx_head_desc = &np->rx_ring[entry];
966                 desc_status = le32_to_cpu(np->rx_head_desc->cmd_status);
967         }
968 
969         /* Refill the Rx ring buffers. */
970         for (; np->cur_rx - np->dirty_rx > 0; np->dirty_rx++) {
971                 struct sk_buff *skb;
972                 entry = np->dirty_rx % RX_RING_SIZE;
973                 if (np->rx_skbuff[entry] == NULL) {
974                         skb = dev_alloc_skb(np->rx_buf_sz);
975                         np->rx_skbuff[entry] = skb;
976                         if (skb == NULL)
977                                 break;                          /* Better luck next round. */
978                         skb->dev = dev;                 /* Mark as being used by this device. */
979                         np->rx_ring[entry].addr = virt_to_le32desc(skb->tail);
980                 }
981                 np->rx_ring[entry].cmd_status =
982                         cpu_to_le32(np->rx_buf_sz);
983         }
984 
985         /* Restart Rx engine if stopped. */
986         writel(RxOn, dev->base_addr + ChipCmd);
987         return 0;
988 }
989 
990 static void netdev_error(struct net_device *dev, int intr_status)
991 {
992         struct netdev_private *np = (struct netdev_private *)dev->priv;
993         long ioaddr = dev->base_addr;
994 
995         if (intr_status & LinkChange) {
996                 printk(KERN_NOTICE "%s: Link changed: Autonegotiation advertising"
997                            " %4.4x  partner %4.4x.\n", dev->name,
998                            (int)readl(ioaddr + 0x90), (int)readl(ioaddr + 0x94));
999                 check_duplex(dev);
1000         }
1001         if (intr_status & StatsMax) {
1002                 get_stats(dev);
1003         }
1004         if ((intr_status & ~(LinkChange|StatsMax|RxResetDone|TxResetDone|0x83ff))
1005                 && debug)
1006                 printk(KERN_ERR "%s: Something Wicked happened! %4.4x.\n",
1007                            dev->name, intr_status);
1008         /* Hmmmmm, it's not clear how to recover from PCI faults. */
1009         if (intr_status & IntrPCIErr) {
1010                 np->stats.tx_fifo_errors++;
1011                 np->stats.rx_fifo_errors++;
1012         }
1013 }
1014 
1015 static struct net_device_stats *get_stats(struct net_device *dev)
1016 {
1017         long ioaddr = dev->base_addr;
1018         struct netdev_private *np = (struct netdev_private *)dev->priv;
1019 
1020         /* We should lock this segment of code for SMP eventually, although
1021            the vulnerability window is very small and statistics are
1022            non-critical. */
1023         /* The chip only need report frame silently dropped. */
1024         np->stats.rx_crc_errors += readl(ioaddr + RxCRCErrs);
1025         np->stats.rx_missed_errors      += readl(ioaddr + RxMissed);
1026 
1027         return &np->stats;
1028 }
1029 
1030 /* The little-endian AUTODIN II ethernet CRC calculations.
1031    A big-endian version is also available.
1032    This is slow but compact code.  Do not use this routine for bulk data,
1033    use a table-based routine instead.
1034    This is common code and should be moved to net/core/crc.c.
1035    Chips may use the upper or lower CRC bits, and may reverse and/or invert
1036    them.  Select the endian-ness that results in minimal calculations.
1037 */
1038 static unsigned const ethernet_polynomial_le = 0xedb88320U;
1039 static inline unsigned ether_crc_le(int length, unsigned char *data)
1040 {
1041         unsigned int crc = 0xffffffff;  /* Initial value. */
1042         while(--length >= 0) {
1043                 unsigned char current_octet = *data++;
1044                 int bit;
1045                 for (bit = 8; --bit >= 0; current_octet >>= 1) {
1046                         if ((crc ^ current_octet) & 1) {
1047                                 crc >>= 1;
1048                                 crc ^= ethernet_polynomial_le;
1049                         } else
1050                                 crc >>= 1;
1051                 }
1052         }
1053         return crc;
1054 }
1055 
1056 static void set_rx_mode(struct net_device *dev)
1057 {
1058         long ioaddr = dev->base_addr;
1059         struct netdev_private *np = (struct netdev_private *)dev->priv;
1060         u16 mc_filter[32];                      /* Multicast hash filter */
1061         u32 rx_mode;
1062 
1063         if (dev->flags & IFF_PROMISC) {                 /* Set promiscuous. */
1064                 /* Unconditionally log net taps. */
1065                 printk(KERN_NOTICE "%s: Promiscuous mode enabled.\n", dev->name);
1066                 rx_mode = AcceptBroadcast | AcceptAllMulticast | AcceptAllPhys
1067                         | AcceptMyPhys;
1068         } else if ((dev->mc_count > multicast_filter_limit)
1069                            ||  (dev->flags & IFF_ALLMULTI)) {
1070                 rx_mode = AcceptBroadcast | AcceptAllMulticast | AcceptMyPhys;
1071         } else {
1072                 struct dev_mc_list *mclist;
1073                 int i;
1074                 memset(mc_filter, 0, sizeof(mc_filter));
1075                 for (i = 0, mclist = dev->mc_list; mclist && i < dev->mc_count;
1076                          i++, mclist = mclist->next) {
1077                         set_bit(ether_crc_le(ETH_ALEN, mclist->dmi_addr) & 0x1ff,
1078                                         mc_filter);
1079                 }
1080                 for (i = 0; i < 32; i++) {
1081                         writew(0x200 + (i<<1), ioaddr + RxFilterAddr);
1082                         writew(cpu_to_be16(mc_filter[i]), ioaddr + RxFilterData);
1083                 }
1084                 rx_mode = AcceptBroadcast | AcceptMulticast | AcceptMyPhys;
1085         }
1086         writel(rx_mode | EnableFilter, ioaddr + RxFilterAddr);
1087         np->cur_rx_mode = rx_mode;
1088 }
1089 
1090 static int mii_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
1091 {
1092         u16 *data = (u16 *)&rq->ifr_data;
1093 
1094         switch(cmd) {
1095         case SIOCDEVPRIVATE:            /* Get the address of the PHY in use. */
1096                 data[0] = 1;
1097                 /* Fall Through */
1098         case SIOCDEVPRIVATE+1:          /* Read the specified MII register. */
1099                 data[3] = mdio_read(dev, data[0] & 0x1f, data[1] & 0x1f);
1100                 return 0;
1101         case SIOCDEVPRIVATE+2:          /* Write the specified MII register */
1102                 if (!capable(CAP_NET_ADMIN))
1103                         return -EPERM;
1104                 mdio_write(dev, data[0] & 0x1f, data[1] & 0x1f, data[2]);
1105                 return 0;
1106         default:
1107                 return -EOPNOTSUPP;
1108         }
1109 }
1110 
1111 static int netdev_close(struct net_device *dev)
1112 {
1113         long ioaddr = dev->base_addr;
1114         struct netdev_private *np = (struct netdev_private *)dev->priv;
1115         int i;
1116 
1117         netif_stop_queue(dev);
1118 
1119         if (debug > 1) {
1120                 printk(KERN_DEBUG "%s: Shutting down ethercard, status was %4.4x "
1121                            "Int %2.2x.\n",
1122                            dev->name, (int)readl(ioaddr + ChipCmd),
1123                            (int)readl(ioaddr + IntrStatus));
1124                 printk(KERN_DEBUG "%s: Queue pointers were Tx %d / %d,  Rx %d / %d.\n",
1125                            dev->name, np->cur_tx, np->dirty_tx, np->cur_rx, np->dirty_rx);
1126         }
1127 
1128         /* Disable interrupts using the mask. */
1129         writel(0, ioaddr + IntrMask);
1130         writel(0, ioaddr + IntrEnable);
1131         writel(2, ioaddr + StatsCtrl);                                  /* Freeze Stats */
1132 
1133         /* Stop the chip's Tx and Rx processes. */
1134         writel(RxOff | TxOff, ioaddr + ChipCmd);
1135 
1136         del_timer_sync(&np->timer);
1137 
1138 #ifdef __i386__
1139         if (debug > 2) {
1140                 printk("\n"KERN_DEBUG"  Tx ring at %8.8x:\n",
1141                            (int)virt_to_bus(np->tx_ring));
1142                 for (i = 0; i < TX_RING_SIZE; i++)
1143                         printk(" #%d desc. %8.8x %8.8x.\n",
1144                                    i, np->tx_ring[i].cmd_status, np->tx_ring[i].addr);
1145                 printk("\n"KERN_DEBUG "  Rx ring %8.8x:\n",
1146                            (int)virt_to_bus(np->rx_ring));
1147                 for (i = 0; i < RX_RING_SIZE; i++) {
1148                         printk(KERN_DEBUG " #%d desc. %8.8x %8.8x\n",
1149                                    i, np->rx_ring[i].cmd_status, np->rx_ring[i].addr);
1150                 }
1151         }
1152 #endif /* __i386__ debugging only */
1153 
1154         free_irq(dev->irq, dev);
1155 
1156         /* Free all the skbuffs in the Rx queue. */
1157         for (i = 0; i < RX_RING_SIZE; i++) {
1158                 np->rx_ring[i].cmd_status = 0;
1159                 np->rx_ring[i].addr = 0xBADF00D0; /* An invalid address. */
1160                 if (np->rx_skbuff[i]) {
1161 #if LINUX_VERSION_CODE < 0x20100
1162                         np->rx_skbuff[i]->free = 1;
1163 #endif
1164                         dev_kfree_skb(np->rx_skbuff[i]);
1165                 }
1166                 np->rx_skbuff[i] = 0;
1167         }
1168         for (i = 0; i < TX_RING_SIZE; i++) {
1169                 if (np->tx_skbuff[i])
1170                         dev_kfree_skb(np->tx_skbuff[i]);
1171                 np->tx_skbuff[i] = 0;
1172         }
1173         /* Restore PME enable bit */
1174         writel(np->SavedClkRun, ioaddr + ClkRun);
1175 #if 0
1176         writel(0x0200, ioaddr + ChipConfig); /* Power down Xcvr. */
1177 #endif
1178 
1179         return 0;
1180 }
1181 
1182 
1183 static void __devexit natsemi_remove1 (struct pci_dev *pdev)
1184 {
1185         struct net_device *dev = pdev->driver_data;
1186         struct netdev_private *np = (struct netdev_private *)dev->priv;
1187         const int pcibar = 1; /* PCI base address register */
1188 
1189         unregister_netdev (dev);
1190         release_mem_region(pci_resource_start(pdev, pcibar), np->iosize);
1191         iounmap ((char *) dev->base_addr);
1192         kfree (dev);
1193 }
1194 
1195 static struct pci_driver natsemi_driver = {
1196         name:           "natsemi",
1197         id_table:       natsemi_pci_tbl,
1198         probe:          natsemi_probe1,
1199         remove:         natsemi_remove1,
1200 };
1201 
1202 static int __init natsemi_init_mod (void)
1203 {
1204         if (debug > 1)
1205                 printk(KERN_INFO "%s" KERN_INFO "%s" KERN_INFO "%s",
1206                         version1, version2, version3);
1207 
1208         return pci_module_init (&natsemi_driver);
1209 }
1210 
1211 static void __exit natsemi_exit_mod (void)
1212 {
1213         pci_unregister_driver (&natsemi_driver);
1214 }
1215 
1216 module_init(natsemi_init_mod);
1217 module_exit(natsemi_exit_mod);
1218 
1219 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.