blob: 452863d5d498a5aa9f9d08c0e9f4b817d13a3584 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* lasi_82596.c -- driver for the intel 82596 ethernet controller, as
2 munged into HPPA boxen .
3
4 This driver is based upon 82596.c, original credits are below...
5 but there were too many hoops which HP wants jumped through to
6 keep this code in there in a sane manner.
7
Jeff Garzik6aa20a22006-09-13 13:24:59 -04008 3 primary sources of the mess --
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 1) hppa needs *lots* of cacheline flushing to keep this kind of
10 MMIO running.
11
12 2) The 82596 needs to see all of its pointers as their physical
13 address. Thus virt_to_bus/bus_to_virt are *everywhere*.
14
Jeff Garzik6aa20a22006-09-13 13:24:59 -040015 3) The implementation HP is using seems to be significantly pickier
Linus Torvalds1da177e2005-04-16 15:20:36 -070016 about when and how the command and RX units are started. some
17 command ordering was changed.
18
19 Examination of the mach driver leads one to believe that there
20 might be a saner way to pull this off... anyone who feels like a
21 full rewrite can be my guest.
22
23 Split 02/13/2000 Sam Creasey (sammy@oh.verio.com)
Jeff Garzik6aa20a22006-09-13 13:24:59 -040024
Linus Torvalds1da177e2005-04-16 15:20:36 -070025 02/01/2000 Initial modifications for parisc by Helge Deller (deller@gmx.de)
26 03/02/2000 changes for better/correct(?) cache-flushing (deller)
27*/
28
29/* 82596.c: A generic 82596 ethernet driver for linux. */
30/*
31 Based on Apricot.c
32 Written 1994 by Mark Evans.
33 This driver is for the Apricot 82596 bus-master interface
34
35 Modularised 12/94 Mark Evans
36
37
38 Modified to support the 82596 ethernet chips on 680x0 VME boards.
39 by Richard Hirst <richard@sleepie.demon.co.uk>
40 Renamed to be 82596.c
41
42 980825: Changed to receive directly in to sk_buffs which are
43 allocated at open() time. Eliminates copy on incoming frames
44 (small ones are still copied). Shared data now held in a
45 non-cached page, so we can run on 68060 in copyback mode.
46
47 TBD:
48 * look at deferring rx frames rather than discarding (as per tulip)
49 * handle tx ring full as per tulip
50 * performace test to tune rx_copybreak
51
52 Most of my modifications relate to the braindead big-endian
53 implementation by Intel. When the i596 is operating in
54 'big-endian' mode, it thinks a 32 bit value of 0x12345678
55 should be stored as 0x56781234. This is a real pain, when
56 you have linked lists which are shared by the 680x0 and the
57 i596.
58
59 Driver skeleton
60 Written 1993 by Donald Becker.
61 Copyright 1993 United States Government as represented by the Director,
62 National Security Agency. This software may only be used and distributed
63 according to the terms of the GNU General Public License as modified by SRC,
64 incorporated herein by reference.
65
66 The author may be reached as becker@scyld.com, or C/O
67 Scyld Computing Corporation, 410 Severn Ave., Suite 210, Annapolis MD 21403
68
69 */
70
71#include <linux/module.h>
72#include <linux/kernel.h>
73#include <linux/string.h>
74#include <linux/ptrace.h>
75#include <linux/errno.h>
76#include <linux/ioport.h>
77#include <linux/slab.h>
78#include <linux/interrupt.h>
79#include <linux/delay.h>
80#include <linux/netdevice.h>
81#include <linux/etherdevice.h>
82#include <linux/skbuff.h>
83#include <linux/init.h>
84#include <linux/pci.h>
85#include <linux/types.h>
86#include <linux/bitops.h>
87
88#include <asm/io.h>
89#include <asm/pgtable.h>
90#include <asm/irq.h>
91#include <asm/pdc.h>
92#include <asm/cache.h>
93#include <asm/parisc-device.h>
94
95#define LASI_82596_DRIVER_VERSION "LASI 82596 driver - Revision: 1.30"
96
97/* DEBUG flags
98 */
99
100#define DEB_INIT 0x0001
101#define DEB_PROBE 0x0002
102#define DEB_SERIOUS 0x0004
103#define DEB_ERRORS 0x0008
104#define DEB_MULTI 0x0010
105#define DEB_TDR 0x0020
106#define DEB_OPEN 0x0040
107#define DEB_RESET 0x0080
108#define DEB_ADDCMD 0x0100
109#define DEB_STATUS 0x0200
110#define DEB_STARTTX 0x0400
111#define DEB_RXADDR 0x0800
112#define DEB_TXADDR 0x1000
113#define DEB_RXFRAME 0x2000
114#define DEB_INTS 0x4000
115#define DEB_STRUCT 0x8000
116#define DEB_ANY 0xffff
117
118
119#define DEB(x,y) if (i596_debug & (x)) { y; }
120
121
Ralf Baechled3fa72e2006-12-06 20:38:56 -0800122#define CHECK_WBACK(priv, addr,len) \
123 do { dma_cache_sync((priv)->dev, (void *)addr, len, DMA_TO_DEVICE); } while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124
Ralf Baechled3fa72e2006-12-06 20:38:56 -0800125#define CHECK_INV(priv, addr,len) \
126 do { dma_cache_sync((priv)->dev, (void *)addr, len, DMA_FROM_DEVICE); } while(0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127
Ralf Baechled3fa72e2006-12-06 20:38:56 -0800128#define CHECK_WBACK_INV(priv, addr,len) \
129 do { dma_cache_sync((priv)->dev, (void *)addr, len, DMA_BIDIRECTIONAL); } while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130
131
132#define PA_I82596_RESET 0 /* Offsets relative to LASI-LAN-Addr.*/
133#define PA_CPU_PORT_L_ACCESS 4
134#define PA_CHANNEL_ATTENTION 8
135
136
137/*
138 * Define various macros for Channel Attention, word swapping etc., dependent
139 * on architecture. MVME and BVME are 680x0 based, otherwise it is Intel.
140 */
141
142#ifdef __BIG_ENDIAN
143#define WSWAPrfd(x) (((u32)(x)<<16) | ((((u32)(x)))>>16))
144#define WSWAPrbd(x) (((u32)(x)<<16) | ((((u32)(x)))>>16))
145#define WSWAPiscp(x) (((u32)(x)<<16) | ((((u32)(x)))>>16))
146#define WSWAPscb(x) (((u32)(x)<<16) | ((((u32)(x)))>>16))
147#define WSWAPcmd(x) (((u32)(x)<<16) | ((((u32)(x)))>>16))
148#define WSWAPtbd(x) (((u32)(x)<<16) | ((((u32)(x)))>>16))
149#define WSWAPchar(x) (((u32)(x)<<16) | ((((u32)(x)))>>16))
150#define ISCP_BUSY 0x00010000
151#define MACH_IS_APRICOT 0
152#else
153#define WSWAPrfd(x) ((struct i596_rfd *)(x))
154#define WSWAPrbd(x) ((struct i596_rbd *)(x))
155#define WSWAPiscp(x) ((struct i596_iscp *)(x))
156#define WSWAPscb(x) ((struct i596_scb *)(x))
157#define WSWAPcmd(x) ((struct i596_cmd *)(x))
158#define WSWAPtbd(x) ((struct i596_tbd *)(x))
159#define WSWAPchar(x) ((char *)(x))
160#define ISCP_BUSY 0x0001
161#define MACH_IS_APRICOT 1
162#endif
163
164/*
165 * The MPU_PORT command allows direct access to the 82596. With PORT access
166 * the following commands are available (p5-18). The 32-bit port command
167 * must be word-swapped with the most significant word written first.
168 * This only applies to VME boards.
169 */
170#define PORT_RESET 0x00 /* reset 82596 */
171#define PORT_SELFTEST 0x01 /* selftest */
172#define PORT_ALTSCP 0x02 /* alternate SCB address */
173#define PORT_ALTDUMP 0x03 /* Alternate DUMP address */
174
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400175static int i596_debug = (DEB_SERIOUS|DEB_PROBE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176
177MODULE_AUTHOR("Richard Hirst");
178MODULE_DESCRIPTION("i82596 driver");
179MODULE_LICENSE("GPL");
Rusty Russell8d3b33f2006-03-25 03:07:05 -0800180module_param(i596_debug, int, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181MODULE_PARM_DESC(i596_debug, "lasi_82596 debug mask");
182
183/* Copy frames shorter than rx_copybreak, otherwise pass on up in
184 * a full sized sk_buff. Value of 100 stolen from tulip.c (!alpha).
185 */
186static int rx_copybreak = 100;
187
188#define MAX_DRIVERS 4 /* max count of drivers */
189
190#define PKT_BUF_SZ 1536
191#define MAX_MC_CNT 64
192
193#define I596_NULL ((u32)0xffffffff)
194
195#define CMD_EOL 0x8000 /* The last command of the list, stop. */
196#define CMD_SUSP 0x4000 /* Suspend after doing cmd. */
197#define CMD_INTR 0x2000 /* Interrupt after doing cmd. */
198
199#define CMD_FLEX 0x0008 /* Enable flexible memory model */
200
201enum commands {
202 CmdNOp = 0, CmdSASetup = 1, CmdConfigure = 2, CmdMulticastList = 3,
203 CmdTx = 4, CmdTDR = 5, CmdDump = 6, CmdDiagnose = 7
204};
205
206#define STAT_C 0x8000 /* Set to 0 after execution */
207#define STAT_B 0x4000 /* Command being executed */
208#define STAT_OK 0x2000 /* Command executed ok */
209#define STAT_A 0x1000 /* Command aborted */
210
211#define CUC_START 0x0100
212#define CUC_RESUME 0x0200
213#define CUC_SUSPEND 0x0300
214#define CUC_ABORT 0x0400
215#define RX_START 0x0010
216#define RX_RESUME 0x0020
217#define RX_SUSPEND 0x0030
218#define RX_ABORT 0x0040
219
220#define TX_TIMEOUT 5
221
222#define OPT_SWAP_PORT 0x0001 /* Need to wordswp on the MPU port */
223
224
225struct i596_reg {
226 unsigned short porthi;
227 unsigned short portlo;
228 u32 ca;
229};
230
231#define EOF 0x8000
232#define SIZE_MASK 0x3fff
233
234struct i596_tbd {
235 unsigned short size;
236 unsigned short pad;
237 dma_addr_t next;
238 dma_addr_t data;
239 u32 cache_pad[5]; /* Total 32 bytes... */
240};
241
242/* The command structure has two 'next' pointers; v_next is the address of
243 * the next command as seen by the CPU, b_next is the address of the next
244 * command as seen by the 82596. The b_next pointer, as used by the 82596
245 * always references the status field of the next command, rather than the
246 * v_next field, because the 82596 is unaware of v_next. It may seem more
247 * logical to put v_next at the end of the structure, but we cannot do that
248 * because the 82596 expects other fields to be there, depending on command
249 * type.
250 */
251
252struct i596_cmd {
253 struct i596_cmd *v_next; /* Address from CPUs viewpoint */
254 unsigned short status;
255 unsigned short command;
256 dma_addr_t b_next; /* Address from i596 viewpoint */
257};
258
259struct tx_cmd {
260 struct i596_cmd cmd;
261 dma_addr_t tbd;
262 unsigned short size;
263 unsigned short pad;
264 struct sk_buff *skb; /* So we can free it after tx */
265 dma_addr_t dma_addr;
266#ifdef __LP64__
267 u32 cache_pad[6]; /* Total 64 bytes... */
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400268#else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 u32 cache_pad[1]; /* Total 32 bytes... */
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400270#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271};
272
273struct tdr_cmd {
274 struct i596_cmd cmd;
275 unsigned short status;
276 unsigned short pad;
277};
278
279struct mc_cmd {
280 struct i596_cmd cmd;
281 short mc_cnt;
282 char mc_addrs[MAX_MC_CNT*6];
283};
284
285struct sa_cmd {
286 struct i596_cmd cmd;
287 char eth_addr[8];
288};
289
290struct cf_cmd {
291 struct i596_cmd cmd;
292 char i596_config[16];
293};
294
295struct i596_rfd {
296 unsigned short stat;
297 unsigned short cmd;
298 dma_addr_t b_next; /* Address from i596 viewpoint */
299 dma_addr_t rbd;
300 unsigned short count;
301 unsigned short size;
302 struct i596_rfd *v_next; /* Address from CPUs viewpoint */
303 struct i596_rfd *v_prev;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400304#ifndef __LP64__
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 u32 cache_pad[2]; /* Total 32 bytes... */
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400306#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307};
308
309struct i596_rbd {
310 /* hardware data */
311 unsigned short count;
312 unsigned short zero1;
313 dma_addr_t b_next;
314 dma_addr_t b_data; /* Address from i596 viewpoint */
315 unsigned short size;
316 unsigned short zero2;
317 /* driver data */
318 struct sk_buff *skb;
319 struct i596_rbd *v_next;
320 dma_addr_t b_addr; /* This rbd addr from i596 view */
321 unsigned char *v_data; /* Address from CPUs viewpoint */
322 /* Total 32 bytes... */
323#ifdef __LP64__
324 u32 cache_pad[4];
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400325#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326};
327
328/* These values as chosen so struct i596_private fits in one page... */
329
330#define TX_RING_SIZE 32
331#define RX_RING_SIZE 16
332
333struct i596_scb {
334 unsigned short status;
335 unsigned short command;
336 dma_addr_t cmd;
337 dma_addr_t rfd;
338 u32 crc_err;
339 u32 align_err;
340 u32 resource_err;
341 u32 over_err;
342 u32 rcvdt_err;
343 u32 short_err;
344 unsigned short t_on;
345 unsigned short t_off;
346};
347
348struct i596_iscp {
349 u32 stat;
350 dma_addr_t scb;
351};
352
353struct i596_scp {
354 u32 sysbus;
355 u32 pad;
356 dma_addr_t iscp;
357};
358
359struct i596_private {
360 volatile struct i596_scp scp __attribute__((aligned(32)));
361 volatile struct i596_iscp iscp __attribute__((aligned(32)));
362 volatile struct i596_scb scb __attribute__((aligned(32)));
363 struct sa_cmd sa_cmd __attribute__((aligned(32)));
364 struct cf_cmd cf_cmd __attribute__((aligned(32)));
365 struct tdr_cmd tdr_cmd __attribute__((aligned(32)));
366 struct mc_cmd mc_cmd __attribute__((aligned(32)));
367 struct i596_rfd rfds[RX_RING_SIZE] __attribute__((aligned(32)));
368 struct i596_rbd rbds[RX_RING_SIZE] __attribute__((aligned(32)));
369 struct tx_cmd tx_cmds[TX_RING_SIZE] __attribute__((aligned(32)));
370 struct i596_tbd tbds[TX_RING_SIZE] __attribute__((aligned(32)));
371 u32 stat;
372 int last_restart;
373 struct i596_rfd *rfd_head;
374 struct i596_rbd *rbd_head;
375 struct i596_cmd *cmd_tail;
376 struct i596_cmd *cmd_head;
377 int cmd_backlog;
378 u32 last_cmd;
379 struct net_device_stats stats;
380 int next_tx_cmd;
381 int options;
382 spinlock_t lock;
383 dma_addr_t dma_addr;
384 struct device *dev;
385};
386
Helge Deller93ea7742006-10-14 22:11:32 +0200387static const char init_setup[] =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388{
389 0x8E, /* length, prefetch on */
390 0xC8, /* fifo to 8, monitor off */
391 0x80, /* don't save bad frames */
392 0x2E, /* No source address insertion, 8 byte preamble */
393 0x00, /* priority and backoff defaults */
394 0x60, /* interframe spacing */
395 0x00, /* slot time LSB */
396 0xf2, /* slot time and retries */
397 0x00, /* promiscuous mode */
398 0x00, /* collision detect */
399 0x40, /* minimum frame length */
400 0xff,
401 0x00,
402 0x7f /* *multi IA */ };
403
404static int i596_open(struct net_device *dev);
405static int i596_start_xmit(struct sk_buff *skb, struct net_device *dev);
David Howells7d12e782006-10-05 14:55:46 +0100406static irqreturn_t i596_interrupt(int irq, void *dev_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407static int i596_close(struct net_device *dev);
408static struct net_device_stats *i596_get_stats(struct net_device *dev);
409static void i596_add_cmd(struct net_device *dev, struct i596_cmd *cmd);
410static void i596_tx_timeout (struct net_device *dev);
411static void print_eth(unsigned char *buf, char *str);
412static void set_multicast_list(struct net_device *dev);
413
414static int rx_ring_size = RX_RING_SIZE;
415static int ticks_limit = 100;
416static int max_cmd_backlog = TX_RING_SIZE-1;
417
Sven Schnellec27090202005-10-21 22:55:15 -0400418#ifdef CONFIG_NET_POLL_CONTROLLER
419static void i596_poll_controller(struct net_device *dev);
420#endif
421
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422
423static inline void CA(struct net_device *dev)
424{
425 gsc_writel(0, dev->base_addr + PA_CHANNEL_ATTENTION);
426}
427
428
429static inline void MPU_PORT(struct net_device *dev, int c, dma_addr_t x)
430{
431 struct i596_private *lp = dev->priv;
432
433 u32 v = (u32) (c) | (u32) (x);
434 u16 a, b;
435
436 if (lp->options & OPT_SWAP_PORT) {
437 a = v >> 16;
438 b = v & 0xffff;
439 } else {
440 a = v & 0xffff;
441 b = v >> 16;
442 }
443
444 gsc_writel(a, dev->base_addr + PA_CPU_PORT_L_ACCESS);
445 udelay(1);
446 gsc_writel(b, dev->base_addr + PA_CPU_PORT_L_ACCESS);
447}
448
449
450static inline int wait_istat(struct net_device *dev, struct i596_private *lp, int delcnt, char *str)
451{
Ralf Baechled3fa72e2006-12-06 20:38:56 -0800452 CHECK_INV(lp, &(lp->iscp), sizeof(struct i596_iscp));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 while (--delcnt && lp->iscp.stat) {
454 udelay(10);
Ralf Baechled3fa72e2006-12-06 20:38:56 -0800455 CHECK_INV(lp, &(lp->iscp), sizeof(struct i596_iscp));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 }
457 if (!delcnt) {
458 printk("%s: %s, iscp.stat %04x, didn't clear\n",
459 dev->name, str, lp->iscp.stat);
460 return -1;
461 }
462 else
463 return 0;
464}
465
466
467static inline int wait_cmd(struct net_device *dev, struct i596_private *lp, int delcnt, char *str)
468{
Ralf Baechled3fa72e2006-12-06 20:38:56 -0800469 CHECK_INV(lp, &(lp->scb), sizeof(struct i596_scb));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 while (--delcnt && lp->scb.command) {
471 udelay(10);
Ralf Baechled3fa72e2006-12-06 20:38:56 -0800472 CHECK_INV(lp, &(lp->scb), sizeof(struct i596_scb));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 }
474 if (!delcnt) {
475 printk("%s: %s, status %4.4x, cmd %4.4x.\n",
476 dev->name, str, lp->scb.status, lp->scb.command);
477 return -1;
478 }
479 else
480 return 0;
481}
482
483
484static void i596_display_data(struct net_device *dev)
485{
486 struct i596_private *lp = dev->priv;
487 struct i596_cmd *cmd;
488 struct i596_rfd *rfd;
489 struct i596_rbd *rbd;
490
491 printk("lp and scp at %p, .sysbus = %08x, .iscp = %08x\n",
492 &lp->scp, lp->scp.sysbus, lp->scp.iscp);
493 printk("iscp at %p, iscp.stat = %08x, .scb = %08x\n",
494 &lp->iscp, lp->iscp.stat, lp->iscp.scb);
495 printk("scb at %p, scb.status = %04x, .command = %04x,"
496 " .cmd = %08x, .rfd = %08x\n",
497 &lp->scb, lp->scb.status, lp->scb.command,
498 lp->scb.cmd, lp->scb.rfd);
499 printk(" errors: crc %x, align %x, resource %x,"
500 " over %x, rcvdt %x, short %x\n",
501 lp->scb.crc_err, lp->scb.align_err, lp->scb.resource_err,
502 lp->scb.over_err, lp->scb.rcvdt_err, lp->scb.short_err);
503 cmd = lp->cmd_head;
504 while (cmd != NULL) {
505 printk("cmd at %p, .status = %04x, .command = %04x, .b_next = %08x\n",
506 cmd, cmd->status, cmd->command, cmd->b_next);
507 cmd = cmd->v_next;
508 }
509 rfd = lp->rfd_head;
510 printk("rfd_head = %p\n", rfd);
511 do {
512 printk(" %p .stat %04x, .cmd %04x, b_next %08x, rbd %08x,"
513 " count %04x\n",
514 rfd, rfd->stat, rfd->cmd, rfd->b_next, rfd->rbd,
515 rfd->count);
516 rfd = rfd->v_next;
517 } while (rfd != lp->rfd_head);
518 rbd = lp->rbd_head;
519 printk("rbd_head = %p\n", rbd);
520 do {
521 printk(" %p .count %04x, b_next %08x, b_data %08x, size %04x\n",
522 rbd, rbd->count, rbd->b_next, rbd->b_data, rbd->size);
523 rbd = rbd->v_next;
524 } while (rbd != lp->rbd_head);
Ralf Baechled3fa72e2006-12-06 20:38:56 -0800525 CHECK_INV(lp, lp, sizeof(struct i596_private));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526}
527
528
529#if defined(ENABLE_MVME16x_NET) || defined(ENABLE_BVME6000_NET)
David Howells7d12e782006-10-05 14:55:46 +0100530static void i596_error(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531{
532 struct net_device *dev = dev_id;
533 volatile unsigned char *pcc2 = (unsigned char *) 0xfff42000;
534
535 pcc2[0x28] = 1;
536 pcc2[0x2b] = 0x1d;
537 printk("%s: Error interrupt\n", dev->name);
538 i596_display_data(dev);
539}
540#endif
541
542#define virt_to_dma(lp,v) ((lp)->dma_addr + (dma_addr_t)((unsigned long)(v)-(unsigned long)(lp)))
543
544static inline void init_rx_bufs(struct net_device *dev)
545{
546 struct i596_private *lp = dev->priv;
547 int i;
548 struct i596_rfd *rfd;
549 struct i596_rbd *rbd;
550
551 /* First build the Receive Buffer Descriptor List */
552
553 for (i = 0, rbd = lp->rbds; i < rx_ring_size; i++, rbd++) {
554 dma_addr_t dma_addr;
555 struct sk_buff *skb = dev_alloc_skb(PKT_BUF_SZ + 4);
556
557 if (skb == NULL)
558 panic("%s: alloc_skb() failed", __FILE__);
559 skb_reserve(skb, 2);
David S. Miller689be432005-06-28 15:25:31 -0700560 dma_addr = dma_map_single(lp->dev, skb->data,PKT_BUF_SZ,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 DMA_FROM_DEVICE);
562 skb->dev = dev;
563 rbd->v_next = rbd+1;
564 rbd->b_next = WSWAPrbd(virt_to_dma(lp,rbd+1));
565 rbd->b_addr = WSWAPrbd(virt_to_dma(lp,rbd));
566 rbd->skb = skb;
David S. Miller689be432005-06-28 15:25:31 -0700567 rbd->v_data = skb->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 rbd->b_data = WSWAPchar(dma_addr);
569 rbd->size = PKT_BUF_SZ;
570 }
571 lp->rbd_head = lp->rbds;
572 rbd = lp->rbds + rx_ring_size - 1;
573 rbd->v_next = lp->rbds;
574 rbd->b_next = WSWAPrbd(virt_to_dma(lp,lp->rbds));
575
576 /* Now build the Receive Frame Descriptor List */
577
578 for (i = 0, rfd = lp->rfds; i < rx_ring_size; i++, rfd++) {
579 rfd->rbd = I596_NULL;
580 rfd->v_next = rfd+1;
581 rfd->v_prev = rfd-1;
582 rfd->b_next = WSWAPrfd(virt_to_dma(lp,rfd+1));
583 rfd->cmd = CMD_FLEX;
584 }
585 lp->rfd_head = lp->rfds;
586 lp->scb.rfd = WSWAPrfd(virt_to_dma(lp,lp->rfds));
587 rfd = lp->rfds;
588 rfd->rbd = WSWAPrbd(virt_to_dma(lp,lp->rbd_head));
589 rfd->v_prev = lp->rfds + rx_ring_size - 1;
590 rfd = lp->rfds + rx_ring_size - 1;
591 rfd->v_next = lp->rfds;
592 rfd->b_next = WSWAPrfd(virt_to_dma(lp,lp->rfds));
593 rfd->cmd = CMD_EOL|CMD_FLEX;
594
Ralf Baechled3fa72e2006-12-06 20:38:56 -0800595 CHECK_WBACK_INV(lp, lp, sizeof(struct i596_private));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596}
597
598static inline void remove_rx_bufs(struct net_device *dev)
599{
600 struct i596_private *lp = dev->priv;
601 struct i596_rbd *rbd;
602 int i;
603
604 for (i = 0, rbd = lp->rbds; i < rx_ring_size; i++, rbd++) {
605 if (rbd->skb == NULL)
606 break;
607 dma_unmap_single(lp->dev,
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400608 (dma_addr_t)WSWAPchar(rbd->b_data),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 PKT_BUF_SZ, DMA_FROM_DEVICE);
610 dev_kfree_skb(rbd->skb);
611 }
612}
613
614
615static void rebuild_rx_bufs(struct net_device *dev)
616{
617 struct i596_private *lp = dev->priv;
618 int i;
619
620 /* Ensure rx frame/buffer descriptors are tidy */
621
622 for (i = 0; i < rx_ring_size; i++) {
623 lp->rfds[i].rbd = I596_NULL;
624 lp->rfds[i].cmd = CMD_FLEX;
625 }
626 lp->rfds[rx_ring_size-1].cmd = CMD_EOL|CMD_FLEX;
627 lp->rfd_head = lp->rfds;
628 lp->scb.rfd = WSWAPrfd(virt_to_dma(lp,lp->rfds));
629 lp->rbd_head = lp->rbds;
630 lp->rfds[0].rbd = WSWAPrbd(virt_to_dma(lp,lp->rbds));
631
Ralf Baechled3fa72e2006-12-06 20:38:56 -0800632 CHECK_WBACK_INV(lp, lp, sizeof(struct i596_private));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633}
634
635
636static int init_i596_mem(struct net_device *dev)
637{
638 struct i596_private *lp = dev->priv;
639 unsigned long flags;
640
641 disable_irq(dev->irq); /* disable IRQs from LAN */
642 DEB(DEB_INIT,
Sven Schnellec27090202005-10-21 22:55:15 -0400643 printk("RESET 82596 port: %lx (with IRQ %d disabled)\n",
644 (dev->base_addr + PA_I82596_RESET),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 dev->irq));
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400646
Sven Schnellec27090202005-10-21 22:55:15 -0400647 gsc_writel(0, (dev->base_addr + PA_I82596_RESET)); /* Hard Reset */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 udelay(100); /* Wait 100us - seems to help */
649
650 /* change the scp address */
651
652 lp->last_cmd = jiffies;
653
654
655 lp->scp.sysbus = 0x0000006c;
656 lp->scp.iscp = WSWAPiscp(virt_to_dma(lp,&(lp->iscp)));
657 lp->iscp.scb = WSWAPscb(virt_to_dma(lp,&(lp->scb)));
658 lp->iscp.stat = ISCP_BUSY;
659 lp->cmd_backlog = 0;
660
661 lp->cmd_head = NULL;
662 lp->scb.cmd = I596_NULL;
663
664 DEB(DEB_INIT, printk("%s: starting i82596.\n", dev->name));
665
Ralf Baechled3fa72e2006-12-06 20:38:56 -0800666 CHECK_WBACK(lp, &(lp->scp), sizeof(struct i596_scp));
667 CHECK_WBACK(lp, &(lp->iscp), sizeof(struct i596_iscp));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400669 MPU_PORT(dev, PORT_ALTSCP, virt_to_dma(lp,&lp->scp));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670
671 CA(dev);
672
673 if (wait_istat(dev, lp, 1000, "initialization timed out"))
674 goto failed;
675 DEB(DEB_INIT, printk("%s: i82596 initialization successful\n", dev->name));
676
677 /* Ensure rx frame/buffer descriptors are tidy */
678 rebuild_rx_bufs(dev);
679
680 lp->scb.command = 0;
Ralf Baechled3fa72e2006-12-06 20:38:56 -0800681 CHECK_WBACK(lp, &(lp->scb), sizeof(struct i596_scb));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682
683 enable_irq(dev->irq); /* enable IRQs from LAN */
684
685 DEB(DEB_INIT, printk("%s: queuing CmdConfigure\n", dev->name));
Helge Deller93ea7742006-10-14 22:11:32 +0200686 memcpy(lp->cf_cmd.i596_config, init_setup, sizeof(init_setup));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 lp->cf_cmd.cmd.command = CmdConfigure;
Ralf Baechled3fa72e2006-12-06 20:38:56 -0800688 CHECK_WBACK(lp, &(lp->cf_cmd), sizeof(struct cf_cmd));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 i596_add_cmd(dev, &lp->cf_cmd.cmd);
690
691 DEB(DEB_INIT, printk("%s: queuing CmdSASetup\n", dev->name));
692 memcpy(lp->sa_cmd.eth_addr, dev->dev_addr, 6);
693 lp->sa_cmd.cmd.command = CmdSASetup;
Ralf Baechled3fa72e2006-12-06 20:38:56 -0800694 CHECK_WBACK(lp, &(lp->sa_cmd), sizeof(struct sa_cmd));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 i596_add_cmd(dev, &lp->sa_cmd.cmd);
696
697 DEB(DEB_INIT, printk("%s: queuing CmdTDR\n", dev->name));
698 lp->tdr_cmd.cmd.command = CmdTDR;
Ralf Baechled3fa72e2006-12-06 20:38:56 -0800699 CHECK_WBACK(lp, &(lp->tdr_cmd), sizeof(struct tdr_cmd));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 i596_add_cmd(dev, &lp->tdr_cmd.cmd);
701
702 spin_lock_irqsave (&lp->lock, flags);
703
704 if (wait_cmd(dev, lp, 1000, "timed out waiting to issue RX_START")) {
705 spin_unlock_irqrestore (&lp->lock, flags);
706 goto failed;
707 }
708 DEB(DEB_INIT, printk("%s: Issuing RX_START\n", dev->name));
709 lp->scb.command = RX_START;
710 lp->scb.rfd = WSWAPrfd(virt_to_dma(lp,lp->rfds));
Ralf Baechled3fa72e2006-12-06 20:38:56 -0800711 CHECK_WBACK(lp, &(lp->scb), sizeof(struct i596_scb));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712
713 CA(dev);
714
715 spin_unlock_irqrestore (&lp->lock, flags);
716
717 if (wait_cmd(dev, lp, 1000, "RX_START not processed"))
718 goto failed;
719 DEB(DEB_INIT, printk("%s: Receive unit started OK\n", dev->name));
720
721 return 0;
722
723failed:
724 printk("%s: Failed to initialise 82596\n", dev->name);
725 MPU_PORT(dev, PORT_RESET, 0);
726 return -1;
727}
728
729
730static inline int i596_rx(struct net_device *dev)
731{
732 struct i596_private *lp = dev->priv;
733 struct i596_rfd *rfd;
734 struct i596_rbd *rbd;
735 int frames = 0;
736
737 DEB(DEB_RXFRAME, printk("i596_rx(), rfd_head %p, rbd_head %p\n",
738 lp->rfd_head, lp->rbd_head));
739
740
741 rfd = lp->rfd_head; /* Ref next frame to check */
742
Ralf Baechled3fa72e2006-12-06 20:38:56 -0800743 CHECK_INV(lp, rfd, sizeof(struct i596_rfd));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744 while ((rfd->stat) & STAT_C) { /* Loop while complete frames */
745 if (rfd->rbd == I596_NULL)
746 rbd = NULL;
747 else if (rfd->rbd == lp->rbd_head->b_addr) {
748 rbd = lp->rbd_head;
Ralf Baechled3fa72e2006-12-06 20:38:56 -0800749 CHECK_INV(lp, rbd, sizeof(struct i596_rbd));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750 }
751 else {
752 printk("%s: rbd chain broken!\n", dev->name);
753 /* XXX Now what? */
754 rbd = NULL;
755 }
756 DEB(DEB_RXFRAME, printk(" rfd %p, rfd.rbd %08x, rfd.stat %04x\n",
757 rfd, rfd->rbd, rfd->stat));
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400758
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759 if (rbd != NULL && ((rfd->stat) & STAT_OK)) {
760 /* a good frame */
761 int pkt_len = rbd->count & 0x3fff;
762 struct sk_buff *skb = rbd->skb;
763 int rx_in_place = 0;
764
765 DEB(DEB_RXADDR,print_eth(rbd->v_data, "received"));
766 frames++;
767
768 /* Check if the packet is long enough to just accept
769 * without copying to a properly sized skbuff.
770 */
771
772 if (pkt_len > rx_copybreak) {
773 struct sk_buff *newskb;
774 dma_addr_t dma_addr;
775
776 dma_unmap_single(lp->dev,(dma_addr_t)WSWAPchar(rbd->b_data), PKT_BUF_SZ, DMA_FROM_DEVICE);
777 /* Get fresh skbuff to replace filled one. */
778 newskb = dev_alloc_skb(PKT_BUF_SZ + 4);
779 if (newskb == NULL) {
780 skb = NULL; /* drop pkt */
781 goto memory_squeeze;
782 }
783 skb_reserve(newskb, 2);
784
785 /* Pass up the skb already on the Rx ring. */
786 skb_put(skb, pkt_len);
787 rx_in_place = 1;
788 rbd->skb = newskb;
789 newskb->dev = dev;
David S. Miller689be432005-06-28 15:25:31 -0700790 dma_addr = dma_map_single(lp->dev, newskb->data, PKT_BUF_SZ, DMA_FROM_DEVICE);
791 rbd->v_data = newskb->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792 rbd->b_data = WSWAPchar(dma_addr);
Ralf Baechled3fa72e2006-12-06 20:38:56 -0800793 CHECK_WBACK_INV(lp, rbd, sizeof(struct i596_rbd));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794 }
795 else
796 skb = dev_alloc_skb(pkt_len + 2);
797memory_squeeze:
798 if (skb == NULL) {
799 /* XXX tulip.c can defer packets here!! */
800 printk("%s: i596_rx Memory squeeze, dropping packet.\n", dev->name);
801 lp->stats.rx_dropped++;
802 }
803 else {
804 skb->dev = dev;
805 if (!rx_in_place) {
806 /* 16 byte align the data fields */
807 dma_sync_single_for_cpu(lp->dev, (dma_addr_t)WSWAPchar(rbd->b_data), PKT_BUF_SZ, DMA_FROM_DEVICE);
808 skb_reserve(skb, 2);
809 memcpy(skb_put(skb,pkt_len), rbd->v_data, pkt_len);
810 dma_sync_single_for_device(lp->dev, (dma_addr_t)WSWAPchar(rbd->b_data), PKT_BUF_SZ, DMA_FROM_DEVICE);
811 }
812 skb->len = pkt_len;
813 skb->protocol=eth_type_trans(skb,dev);
814 netif_rx(skb);
815 dev->last_rx = jiffies;
816 lp->stats.rx_packets++;
817 lp->stats.rx_bytes+=pkt_len;
818 }
819 }
820 else {
821 DEB(DEB_ERRORS, printk("%s: Error, rfd.stat = 0x%04x\n",
822 dev->name, rfd->stat));
823 lp->stats.rx_errors++;
824 if ((rfd->stat) & 0x0001)
825 lp->stats.collisions++;
826 if ((rfd->stat) & 0x0080)
827 lp->stats.rx_length_errors++;
828 if ((rfd->stat) & 0x0100)
829 lp->stats.rx_over_errors++;
830 if ((rfd->stat) & 0x0200)
831 lp->stats.rx_fifo_errors++;
832 if ((rfd->stat) & 0x0400)
833 lp->stats.rx_frame_errors++;
834 if ((rfd->stat) & 0x0800)
835 lp->stats.rx_crc_errors++;
836 if ((rfd->stat) & 0x1000)
837 lp->stats.rx_length_errors++;
838 }
839
840 /* Clear the buffer descriptor count and EOF + F flags */
841
842 if (rbd != NULL && (rbd->count & 0x4000)) {
843 rbd->count = 0;
844 lp->rbd_head = rbd->v_next;
Ralf Baechled3fa72e2006-12-06 20:38:56 -0800845 CHECK_WBACK_INV(lp, rbd, sizeof(struct i596_rbd));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846 }
847
848 /* Tidy the frame descriptor, marking it as end of list */
849
850 rfd->rbd = I596_NULL;
851 rfd->stat = 0;
852 rfd->cmd = CMD_EOL|CMD_FLEX;
853 rfd->count = 0;
854
855 /* Remove end-of-list from old end descriptor */
856
857 rfd->v_prev->cmd = CMD_FLEX;
858
859 /* Update record of next frame descriptor to process */
860
861 lp->scb.rfd = rfd->b_next;
862 lp->rfd_head = rfd->v_next;
Ralf Baechled3fa72e2006-12-06 20:38:56 -0800863 CHECK_WBACK_INV(lp, rfd->v_prev, sizeof(struct i596_rfd));
864 CHECK_WBACK_INV(lp, rfd, sizeof(struct i596_rfd));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865 rfd = lp->rfd_head;
Ralf Baechled3fa72e2006-12-06 20:38:56 -0800866 CHECK_INV(lp, rfd, sizeof(struct i596_rfd));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867 }
868
869 DEB(DEB_RXFRAME, printk("frames %d\n", frames));
870
871 return 0;
872}
873
874
875static inline void i596_cleanup_cmd(struct net_device *dev, struct i596_private *lp)
876{
877 struct i596_cmd *ptr;
878
879 while (lp->cmd_head != NULL) {
880 ptr = lp->cmd_head;
881 lp->cmd_head = ptr->v_next;
882 lp->cmd_backlog--;
883
884 switch ((ptr->command) & 0x7) {
885 case CmdTx:
886 {
887 struct tx_cmd *tx_cmd = (struct tx_cmd *) ptr;
888 struct sk_buff *skb = tx_cmd->skb;
889 dma_unmap_single(lp->dev, tx_cmd->dma_addr, skb->len, DMA_TO_DEVICE);
890
891 dev_kfree_skb(skb);
892
893 lp->stats.tx_errors++;
894 lp->stats.tx_aborted_errors++;
895
896 ptr->v_next = NULL;
897 ptr->b_next = I596_NULL;
898 tx_cmd->cmd.command = 0; /* Mark as free */
899 break;
900 }
901 default:
902 ptr->v_next = NULL;
903 ptr->b_next = I596_NULL;
904 }
Ralf Baechled3fa72e2006-12-06 20:38:56 -0800905 CHECK_WBACK_INV(lp, ptr, sizeof(struct i596_cmd));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906 }
907
908 wait_cmd(dev, lp, 100, "i596_cleanup_cmd timed out");
909 lp->scb.cmd = I596_NULL;
Ralf Baechled3fa72e2006-12-06 20:38:56 -0800910 CHECK_WBACK(lp, &(lp->scb), sizeof(struct i596_scb));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911}
912
913
914static inline void i596_reset(struct net_device *dev, struct i596_private *lp)
915{
916 unsigned long flags;
917
918 DEB(DEB_RESET, printk("i596_reset\n"));
919
920 spin_lock_irqsave (&lp->lock, flags);
921
922 wait_cmd(dev, lp, 100, "i596_reset timed out");
923
924 netif_stop_queue(dev);
925
926 /* FIXME: this command might cause an lpmc */
927 lp->scb.command = CUC_ABORT | RX_ABORT;
Ralf Baechled3fa72e2006-12-06 20:38:56 -0800928 CHECK_WBACK(lp, &(lp->scb), sizeof(struct i596_scb));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929 CA(dev);
930
931 /* wait for shutdown */
932 wait_cmd(dev, lp, 1000, "i596_reset 2 timed out");
933 spin_unlock_irqrestore (&lp->lock, flags);
934
935 i596_cleanup_cmd(dev,lp);
936 i596_rx(dev);
937
938 netif_start_queue(dev);
939 init_i596_mem(dev);
940}
941
942
943static void i596_add_cmd(struct net_device *dev, struct i596_cmd *cmd)
944{
945 struct i596_private *lp = dev->priv;
946 unsigned long flags;
947
948 DEB(DEB_ADDCMD, printk("i596_add_cmd cmd_head %p\n", lp->cmd_head));
949
950 cmd->status = 0;
951 cmd->command |= (CMD_EOL | CMD_INTR);
952 cmd->v_next = NULL;
953 cmd->b_next = I596_NULL;
Ralf Baechled3fa72e2006-12-06 20:38:56 -0800954 CHECK_WBACK(lp, cmd, sizeof(struct i596_cmd));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955
956 spin_lock_irqsave (&lp->lock, flags);
957
958 if (lp->cmd_head != NULL) {
959 lp->cmd_tail->v_next = cmd;
960 lp->cmd_tail->b_next = WSWAPcmd(virt_to_dma(lp,&cmd->status));
Ralf Baechled3fa72e2006-12-06 20:38:56 -0800961 CHECK_WBACK(lp, lp->cmd_tail, sizeof(struct i596_cmd));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962 } else {
963 lp->cmd_head = cmd;
964 wait_cmd(dev, lp, 100, "i596_add_cmd timed out");
965 lp->scb.cmd = WSWAPcmd(virt_to_dma(lp,&cmd->status));
966 lp->scb.command = CUC_START;
Ralf Baechled3fa72e2006-12-06 20:38:56 -0800967 CHECK_WBACK(lp, &(lp->scb), sizeof(struct i596_scb));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968 CA(dev);
969 }
970 lp->cmd_tail = cmd;
971 lp->cmd_backlog++;
972
973 spin_unlock_irqrestore (&lp->lock, flags);
974
975 if (lp->cmd_backlog > max_cmd_backlog) {
976 unsigned long tickssofar = jiffies - lp->last_cmd;
977
978 if (tickssofar < ticks_limit)
979 return;
980
981 printk("%s: command unit timed out, status resetting.\n", dev->name);
982#if 1
983 i596_reset(dev, lp);
984#endif
985 }
986}
987
988#if 0
989/* this function makes a perfectly adequate probe... but we have a
990 device list */
991static int i596_test(struct net_device *dev)
992{
993 struct i596_private *lp = dev->priv;
994 volatile int *tint;
995 u32 data;
996
997 tint = (volatile int *)(&(lp->scp));
998 data = virt_to_dma(lp,tint);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400999
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000 tint[1] = -1;
Ralf Baechled3fa72e2006-12-06 20:38:56 -08001001 CHECK_WBACK(lp, tint, PAGE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002
1003 MPU_PORT(dev, 1, data);
1004
1005 for(data = 1000000; data; data--) {
Ralf Baechled3fa72e2006-12-06 20:38:56 -08001006 CHECK_INV(lp, tint, PAGE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007 if(tint[1] != -1)
1008 break;
1009
1010 }
1011
1012 printk("i596_test result %d\n", tint[1]);
1013
1014}
1015#endif
1016
1017
1018static int i596_open(struct net_device *dev)
1019{
1020 DEB(DEB_OPEN, printk("%s: i596_open() irq %d.\n", dev->name, dev->irq));
1021
1022 if (request_irq(dev->irq, &i596_interrupt, 0, "i82596", dev)) {
1023 printk("%s: IRQ %d not free\n", dev->name, dev->irq);
1024 goto out;
1025 }
1026
1027 init_rx_bufs(dev);
1028
1029 if (init_i596_mem(dev)) {
1030 printk("%s: Failed to init memory\n", dev->name);
1031 goto out_remove_rx_bufs;
1032 }
1033
1034 netif_start_queue(dev);
1035
1036 return 0;
1037
1038out_remove_rx_bufs:
1039 remove_rx_bufs(dev);
1040 free_irq(dev->irq, dev);
1041out:
1042 return -EAGAIN;
1043}
1044
1045static void i596_tx_timeout (struct net_device *dev)
1046{
1047 struct i596_private *lp = dev->priv;
1048
1049 /* Transmitter timeout, serious problems. */
1050 DEB(DEB_ERRORS, printk("%s: transmit timed out, status resetting.\n",
1051 dev->name));
1052
1053 lp->stats.tx_errors++;
1054
1055 /* Try to restart the adaptor */
1056 if (lp->last_restart == lp->stats.tx_packets) {
1057 DEB(DEB_ERRORS, printk("Resetting board.\n"));
1058 /* Shutdown and restart */
1059 i596_reset (dev, lp);
1060 } else {
1061 /* Issue a channel attention signal */
1062 DEB(DEB_ERRORS, printk("Kicking board.\n"));
1063 lp->scb.command = CUC_START | RX_START;
Ralf Baechled3fa72e2006-12-06 20:38:56 -08001064 CHECK_WBACK_INV(lp, &(lp->scb), sizeof(struct i596_scb));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065 CA (dev);
1066 lp->last_restart = lp->stats.tx_packets;
1067 }
1068
1069 dev->trans_start = jiffies;
1070 netif_wake_queue (dev);
1071}
1072
1073
1074static int i596_start_xmit(struct sk_buff *skb, struct net_device *dev)
1075{
1076 struct i596_private *lp = dev->priv;
1077 struct tx_cmd *tx_cmd;
1078 struct i596_tbd *tbd;
1079 short length = skb->len;
1080 dev->trans_start = jiffies;
1081
1082 DEB(DEB_STARTTX, printk("%s: i596_start_xmit(%x,%p) called\n", dev->name,
1083 skb->len, skb->data));
1084
1085 if (length < ETH_ZLEN) {
Herbert Xu5b057c62006-06-23 02:06:41 -07001086 if (skb_padto(skb, ETH_ZLEN))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087 return 0;
1088 length = ETH_ZLEN;
1089 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001090
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091 netif_stop_queue(dev);
1092
1093 tx_cmd = lp->tx_cmds + lp->next_tx_cmd;
1094 tbd = lp->tbds + lp->next_tx_cmd;
1095
1096 if (tx_cmd->cmd.command) {
1097 DEB(DEB_ERRORS, printk("%s: xmit ring full, dropping packet.\n",
1098 dev->name));
1099 lp->stats.tx_dropped++;
1100
1101 dev_kfree_skb(skb);
1102 } else {
1103 if (++lp->next_tx_cmd == TX_RING_SIZE)
1104 lp->next_tx_cmd = 0;
1105 tx_cmd->tbd = WSWAPtbd(virt_to_dma(lp,tbd));
1106 tbd->next = I596_NULL;
1107
1108 tx_cmd->cmd.command = CMD_FLEX | CmdTx;
1109 tx_cmd->skb = skb;
1110
1111 tx_cmd->pad = 0;
1112 tx_cmd->size = 0;
1113 tbd->pad = 0;
1114 tbd->size = EOF | length;
1115
1116 tx_cmd->dma_addr = dma_map_single(lp->dev, skb->data, skb->len,
1117 DMA_TO_DEVICE);
1118 tbd->data = WSWAPchar(tx_cmd->dma_addr);
1119
1120 DEB(DEB_TXADDR,print_eth(skb->data, "tx-queued"));
Ralf Baechled3fa72e2006-12-06 20:38:56 -08001121 CHECK_WBACK_INV(lp, tx_cmd, sizeof(struct tx_cmd));
1122 CHECK_WBACK_INV(lp, tbd, sizeof(struct i596_tbd));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123 i596_add_cmd(dev, &tx_cmd->cmd);
1124
1125 lp->stats.tx_packets++;
1126 lp->stats.tx_bytes += length;
1127 }
1128
1129 netif_start_queue(dev);
1130
1131 return 0;
1132}
1133
1134static void print_eth(unsigned char *add, char *str)
1135{
1136 int i;
1137
1138 printk("i596 0x%p, ", add);
1139 for (i = 0; i < 6; i++)
1140 printk(" %02X", add[i + 6]);
1141 printk(" -->");
1142 for (i = 0; i < 6; i++)
1143 printk(" %02X", add[i]);
1144 printk(" %02X%02X, %s\n", add[12], add[13], str);
1145}
1146
1147
1148#define LAN_PROM_ADDR 0xF0810000
1149
1150static int __devinit i82596_probe(struct net_device *dev,
1151 struct device *gen_dev)
1152{
1153 int i;
1154 struct i596_private *lp;
1155 char eth_addr[6];
1156 dma_addr_t dma_addr;
1157
1158 /* This lot is ensure things have been cache line aligned. */
Helge Deller93ea7742006-10-14 22:11:32 +02001159 BUILD_BUG_ON(sizeof(struct i596_rfd) != 32);
1160 BUILD_BUG_ON(sizeof(struct i596_rbd) & 31);
1161 BUILD_BUG_ON(sizeof(struct tx_cmd) & 31);
1162 BUILD_BUG_ON(sizeof(struct i596_tbd) != 32);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163#ifndef __LP64__
Helge Deller93ea7742006-10-14 22:11:32 +02001164 BUILD_BUG_ON(sizeof(struct i596_private) > 4096);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165#endif
1166
1167 if (!dev->base_addr || !dev->irq)
1168 return -ENODEV;
1169
1170 if (pdc_lan_station_id(eth_addr, dev->base_addr)) {
1171 for (i=0; i < 6; i++) {
1172 eth_addr[i] = gsc_readb(LAN_PROM_ADDR + i);
1173 }
1174 printk(KERN_INFO "%s: MAC of HP700 LAN read from EEPROM\n", __FILE__);
1175 }
1176
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001177 dev->mem_start = (unsigned long) dma_alloc_noncoherent(gen_dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001178 sizeof(struct i596_private), &dma_addr, GFP_KERNEL);
1179 if (!dev->mem_start) {
1180 printk(KERN_ERR "%s: Couldn't get shared memory\n", __FILE__);
1181 return -ENOMEM;
1182 }
1183
1184 for (i = 0; i < 6; i++)
1185 dev->dev_addr[i] = eth_addr[i];
1186
1187 /* The 82596-specific entries in the device structure. */
1188 dev->open = i596_open;
1189 dev->stop = i596_close;
1190 dev->hard_start_xmit = i596_start_xmit;
1191 dev->get_stats = i596_get_stats;
1192 dev->set_multicast_list = set_multicast_list;
1193 dev->tx_timeout = i596_tx_timeout;
1194 dev->watchdog_timeo = TX_TIMEOUT;
Sven Schnellec27090202005-10-21 22:55:15 -04001195#ifdef CONFIG_NET_POLL_CONTROLLER
1196 dev->poll_controller = i596_poll_controller;
1197#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198
1199 dev->priv = (void *)(dev->mem_start);
1200
1201 lp = dev->priv;
1202 memset(lp, 0, sizeof(struct i596_private));
1203
1204 lp->scb.command = 0;
1205 lp->scb.cmd = I596_NULL;
1206 lp->scb.rfd = I596_NULL;
1207 spin_lock_init(&lp->lock);
1208 lp->dma_addr = dma_addr;
1209 lp->dev = gen_dev;
1210
Ralf Baechled3fa72e2006-12-06 20:38:56 -08001211 CHECK_WBACK_INV(lp, dev->mem_start, sizeof(struct i596_private));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212
1213 i = register_netdev(dev);
1214 if (i) {
1215 lp = dev->priv;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001216 dma_free_noncoherent(lp->dev, sizeof(struct i596_private),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217 (void *)dev->mem_start, lp->dma_addr);
1218 return i;
1219 };
1220
1221 DEB(DEB_PROBE, printk(KERN_INFO "%s: 82596 at %#3lx,", dev->name, dev->base_addr));
1222 for (i = 0; i < 6; i++)
1223 DEB(DEB_PROBE, printk(" %2.2X", dev->dev_addr[i]));
1224 DEB(DEB_PROBE, printk(" IRQ %d.\n", dev->irq));
1225 DEB(DEB_INIT, printk(KERN_INFO "%s: lp at 0x%p (%d bytes), lp->scb at 0x%p\n",
1226 dev->name, lp, (int)sizeof(struct i596_private), &lp->scb));
1227
1228 return 0;
1229}
1230
Sven Schnellec27090202005-10-21 22:55:15 -04001231#ifdef CONFIG_NET_POLL_CONTROLLER
1232static void i596_poll_controller(struct net_device *dev)
1233{
1234 disable_irq(dev->irq);
Matthew Wilcoxbe577a52006-10-06 20:47:23 -06001235 i596_interrupt(dev->irq, dev);
Sven Schnellec27090202005-10-21 22:55:15 -04001236 enable_irq(dev->irq);
1237}
1238#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001239
David Howells7d12e782006-10-05 14:55:46 +01001240static irqreturn_t i596_interrupt(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241{
1242 struct net_device *dev = dev_id;
1243 struct i596_private *lp;
1244 unsigned short status, ack_cmd = 0;
1245
1246 if (dev == NULL) {
1247 printk("%s: irq %d for unknown device.\n", __FUNCTION__, irq);
1248 return IRQ_NONE;
1249 }
1250
1251 lp = dev->priv;
1252
1253 spin_lock (&lp->lock);
1254
1255 wait_cmd(dev, lp, 100, "i596 interrupt, timeout");
1256 status = lp->scb.status;
1257
1258 DEB(DEB_INTS, printk("%s: i596 interrupt, IRQ %d, status %4.4x.\n",
1259 dev->name, irq, status));
1260
1261 ack_cmd = status & 0xf000;
1262
1263 if (!ack_cmd) {
1264 DEB(DEB_ERRORS, printk("%s: interrupt with no events\n", dev->name));
1265 spin_unlock (&lp->lock);
1266 return IRQ_NONE;
1267 }
1268
1269 if ((status & 0x8000) || (status & 0x2000)) {
1270 struct i596_cmd *ptr;
1271
1272 if ((status & 0x8000))
1273 DEB(DEB_INTS, printk("%s: i596 interrupt completed command.\n", dev->name));
1274 if ((status & 0x2000))
1275 DEB(DEB_INTS, printk("%s: i596 interrupt command unit inactive %x.\n", dev->name, status & 0x0700));
1276
1277 while (lp->cmd_head != NULL) {
Ralf Baechled3fa72e2006-12-06 20:38:56 -08001278 CHECK_INV(lp, lp->cmd_head, sizeof(struct i596_cmd));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279 if (!(lp->cmd_head->status & STAT_C))
1280 break;
1281
1282 ptr = lp->cmd_head;
1283
1284 DEB(DEB_STATUS, printk("cmd_head->status = %04x, ->command = %04x\n",
1285 lp->cmd_head->status, lp->cmd_head->command));
1286 lp->cmd_head = ptr->v_next;
1287 lp->cmd_backlog--;
1288
1289 switch ((ptr->command) & 0x7) {
1290 case CmdTx:
1291 {
1292 struct tx_cmd *tx_cmd = (struct tx_cmd *) ptr;
1293 struct sk_buff *skb = tx_cmd->skb;
1294
1295 if ((ptr->status) & STAT_OK) {
1296 DEB(DEB_TXADDR, print_eth(skb->data, "tx-done"));
1297 } else {
1298 lp->stats.tx_errors++;
1299 if ((ptr->status) & 0x0020)
1300 lp->stats.collisions++;
1301 if (!((ptr->status) & 0x0040))
1302 lp->stats.tx_heartbeat_errors++;
1303 if ((ptr->status) & 0x0400)
1304 lp->stats.tx_carrier_errors++;
1305 if ((ptr->status) & 0x0800)
1306 lp->stats.collisions++;
1307 if ((ptr->status) & 0x1000)
1308 lp->stats.tx_aborted_errors++;
1309 }
1310 dma_unmap_single(lp->dev, tx_cmd->dma_addr, skb->len, DMA_TO_DEVICE);
1311 dev_kfree_skb_irq(skb);
1312
1313 tx_cmd->cmd.command = 0; /* Mark free */
1314 break;
1315 }
1316 case CmdTDR:
1317 {
1318 unsigned short status = ((struct tdr_cmd *)ptr)->status;
1319
1320 if (status & 0x8000) {
1321 DEB(DEB_ANY, printk("%s: link ok.\n", dev->name));
1322 } else {
1323 if (status & 0x4000)
1324 printk("%s: Transceiver problem.\n", dev->name);
1325 if (status & 0x2000)
1326 printk("%s: Termination problem.\n", dev->name);
1327 if (status & 0x1000)
1328 printk("%s: Short circuit.\n", dev->name);
1329
1330 DEB(DEB_TDR, printk("%s: Time %d.\n", dev->name, status & 0x07ff));
1331 }
1332 break;
1333 }
1334 case CmdConfigure:
1335 /* Zap command so set_multicast_list() knows it is free */
1336 ptr->command = 0;
1337 break;
1338 }
1339 ptr->v_next = NULL;
1340 ptr->b_next = I596_NULL;
Ralf Baechled3fa72e2006-12-06 20:38:56 -08001341 CHECK_WBACK(lp, ptr, sizeof(struct i596_cmd));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342 lp->last_cmd = jiffies;
1343 }
1344
1345 /* This mess is arranging that only the last of any outstanding
1346 * commands has the interrupt bit set. Should probably really
1347 * only add to the cmd queue when the CU is stopped.
1348 */
1349 ptr = lp->cmd_head;
1350 while ((ptr != NULL) && (ptr != lp->cmd_tail)) {
1351 struct i596_cmd *prev = ptr;
1352
1353 ptr->command &= 0x1fff;
1354 ptr = ptr->v_next;
Ralf Baechled3fa72e2006-12-06 20:38:56 -08001355 CHECK_WBACK_INV(lp, prev, sizeof(struct i596_cmd));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356 }
1357
1358 if ((lp->cmd_head != NULL))
1359 ack_cmd |= CUC_START;
1360 lp->scb.cmd = WSWAPcmd(virt_to_dma(lp,&lp->cmd_head->status));
Ralf Baechled3fa72e2006-12-06 20:38:56 -08001361 CHECK_WBACK_INV(lp, &lp->scb, sizeof(struct i596_scb));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001362 }
1363 if ((status & 0x1000) || (status & 0x4000)) {
1364 if ((status & 0x4000))
1365 DEB(DEB_INTS, printk("%s: i596 interrupt received a frame.\n", dev->name));
1366 i596_rx(dev);
1367 /* Only RX_START if stopped - RGH 07-07-96 */
1368 if (status & 0x1000) {
1369 if (netif_running(dev)) {
1370 DEB(DEB_ERRORS, printk("%s: i596 interrupt receive unit inactive, status 0x%x\n", dev->name, status));
1371 ack_cmd |= RX_START;
1372 lp->stats.rx_errors++;
1373 lp->stats.rx_fifo_errors++;
1374 rebuild_rx_bufs(dev);
1375 }
1376 }
1377 }
1378 wait_cmd(dev, lp, 100, "i596 interrupt, timeout");
1379 lp->scb.command = ack_cmd;
Ralf Baechled3fa72e2006-12-06 20:38:56 -08001380 CHECK_WBACK(lp, &lp->scb, sizeof(struct i596_scb));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381
1382 /* DANGER: I suspect that some kind of interrupt
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001383 acknowledgement aside from acking the 82596 might be needed
Linus Torvalds1da177e2005-04-16 15:20:36 -07001384 here... but it's running acceptably without */
1385
1386 CA(dev);
1387
1388 wait_cmd(dev, lp, 100, "i596 interrupt, exit timeout");
1389 DEB(DEB_INTS, printk("%s: exiting interrupt.\n", dev->name));
1390
1391 spin_unlock (&lp->lock);
1392 return IRQ_HANDLED;
1393}
1394
1395static int i596_close(struct net_device *dev)
1396{
1397 struct i596_private *lp = dev->priv;
1398 unsigned long flags;
1399
1400 netif_stop_queue(dev);
1401
1402 DEB(DEB_INIT, printk("%s: Shutting down ethercard, status was %4.4x.\n",
1403 dev->name, lp->scb.status));
1404
1405 spin_lock_irqsave(&lp->lock, flags);
1406
1407 wait_cmd(dev, lp, 100, "close1 timed out");
1408 lp->scb.command = CUC_ABORT | RX_ABORT;
Ralf Baechled3fa72e2006-12-06 20:38:56 -08001409 CHECK_WBACK(lp, &lp->scb, sizeof(struct i596_scb));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410
1411 CA(dev);
1412
1413 wait_cmd(dev, lp, 100, "close2 timed out");
1414 spin_unlock_irqrestore(&lp->lock, flags);
1415 DEB(DEB_STRUCT,i596_display_data(dev));
1416 i596_cleanup_cmd(dev,lp);
1417
1418 disable_irq(dev->irq);
1419
1420 free_irq(dev->irq, dev);
1421 remove_rx_bufs(dev);
1422
1423 return 0;
1424}
1425
1426static struct net_device_stats *
1427 i596_get_stats(struct net_device *dev)
1428{
1429 struct i596_private *lp = dev->priv;
1430
1431 return &lp->stats;
1432}
1433
1434/*
1435 * Set or clear the multicast filter for this adaptor.
1436 */
1437
1438static void set_multicast_list(struct net_device *dev)
1439{
1440 struct i596_private *lp = dev->priv;
1441 int config = 0, cnt;
1442
1443 DEB(DEB_MULTI, printk("%s: set multicast list, %d entries, promisc %s, allmulti %s\n",
1444 dev->name, dev->mc_count, dev->flags & IFF_PROMISC ? "ON" : "OFF",
1445 dev->flags & IFF_ALLMULTI ? "ON" : "OFF"));
1446
1447 if ((dev->flags & IFF_PROMISC) && !(lp->cf_cmd.i596_config[8] & 0x01)) {
1448 lp->cf_cmd.i596_config[8] |= 0x01;
1449 config = 1;
1450 }
1451 if (!(dev->flags & IFF_PROMISC) && (lp->cf_cmd.i596_config[8] & 0x01)) {
1452 lp->cf_cmd.i596_config[8] &= ~0x01;
1453 config = 1;
1454 }
1455 if ((dev->flags & IFF_ALLMULTI) && (lp->cf_cmd.i596_config[11] & 0x20)) {
1456 lp->cf_cmd.i596_config[11] &= ~0x20;
1457 config = 1;
1458 }
1459 if (!(dev->flags & IFF_ALLMULTI) && !(lp->cf_cmd.i596_config[11] & 0x20)) {
1460 lp->cf_cmd.i596_config[11] |= 0x20;
1461 config = 1;
1462 }
1463 if (config) {
1464 if (lp->cf_cmd.cmd.command)
1465 printk("%s: config change request already queued\n",
1466 dev->name);
1467 else {
1468 lp->cf_cmd.cmd.command = CmdConfigure;
Ralf Baechled3fa72e2006-12-06 20:38:56 -08001469 CHECK_WBACK_INV(lp, &lp->cf_cmd, sizeof(struct cf_cmd));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001470 i596_add_cmd(dev, &lp->cf_cmd.cmd);
1471 }
1472 }
1473
1474 cnt = dev->mc_count;
1475 if (cnt > MAX_MC_CNT)
1476 {
1477 cnt = MAX_MC_CNT;
1478 printk("%s: Only %d multicast addresses supported",
1479 dev->name, cnt);
1480 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001481
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482 if (dev->mc_count > 0) {
1483 struct dev_mc_list *dmi;
1484 unsigned char *cp;
1485 struct mc_cmd *cmd;
1486
1487 cmd = &lp->mc_cmd;
1488 cmd->cmd.command = CmdMulticastList;
1489 cmd->mc_cnt = dev->mc_count * 6;
1490 cp = cmd->mc_addrs;
1491 for (dmi = dev->mc_list; cnt && dmi != NULL; dmi = dmi->next, cnt--, cp += 6) {
1492 memcpy(cp, dmi->dmi_addr, 6);
1493 if (i596_debug > 1)
1494 DEB(DEB_MULTI, printk("%s: Adding address %02x:%02x:%02x:%02x:%02x:%02x\n",
1495 dev->name, cp[0],cp[1],cp[2],cp[3],cp[4],cp[5]));
1496 }
Ralf Baechled3fa72e2006-12-06 20:38:56 -08001497 CHECK_WBACK_INV(lp, &lp->mc_cmd, sizeof(struct mc_cmd));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498 i596_add_cmd(dev, &cmd->cmd);
1499 }
1500}
1501
Linus Torvalds1da177e2005-04-16 15:20:36 -07001502static int debug = -1;
Rusty Russell8d3b33f2006-03-25 03:07:05 -08001503module_param(debug, int, 0);
1504MODULE_PARM_DESC(debug, "lasi_82596 debug mask");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505
1506static int num_drivers;
1507static struct net_device *netdevs[MAX_DRIVERS];
1508
1509static int __devinit
1510lan_init_chip(struct parisc_device *dev)
1511{
1512 struct net_device *netdevice;
1513 int retval;
1514
1515 if (num_drivers >= MAX_DRIVERS) {
1516 /* max count of possible i82596 drivers reached */
1517 return -ENOMEM;
1518 }
1519
1520 if (num_drivers == 0)
1521 printk(KERN_INFO LASI_82596_DRIVER_VERSION "\n");
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001522
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523 if (!dev->irq) {
1524 printk(KERN_ERR "%s: IRQ not found for i82596 at 0x%lx\n",
Matthew Wilcox53f01bb2005-10-21 22:36:40 -04001525 __FILE__, dev->hpa.start);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526 return -ENODEV;
1527 }
1528
Matthew Wilcox53f01bb2005-10-21 22:36:40 -04001529 printk(KERN_INFO "Found i82596 at 0x%lx, IRQ %d\n", dev->hpa.start,
1530 dev->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531
1532 netdevice = alloc_etherdev(0);
1533 if (!netdevice)
1534 return -ENOMEM;
1535
Matthew Wilcox53f01bb2005-10-21 22:36:40 -04001536 netdevice->base_addr = dev->hpa.start;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537 netdevice->irq = dev->irq;
1538
1539 retval = i82596_probe(netdevice, &dev->dev);
1540 if (retval) {
1541 free_netdev(netdevice);
1542 return -ENODEV;
1543 }
1544
1545 if (dev->id.sversion == 0x72) {
1546 ((struct i596_private *)netdevice->priv)->options = OPT_SWAP_PORT;
1547 }
1548
1549 netdevs[num_drivers++] = netdevice;
1550
1551 return retval;
1552}
1553
1554
1555static struct parisc_device_id lan_tbl[] = {
1556 { HPHW_FIO, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x0008a },
1557 { HPHW_FIO, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x00072 },
1558 { 0, }
1559};
1560
1561MODULE_DEVICE_TABLE(parisc, lan_tbl);
1562
1563static struct parisc_driver lan_driver = {
Matthew Wilcoxbdad1f82005-10-21 22:36:23 -04001564 .name = "lasi_82596",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001565 .id_table = lan_tbl,
1566 .probe = lan_init_chip,
1567};
1568
1569static int __devinit lasi_82596_init(void)
1570{
1571 if (debug >= 0)
1572 i596_debug = debug;
1573 return register_parisc_driver(&lan_driver);
1574}
1575
1576module_init(lasi_82596_init);
1577
1578static void __exit lasi_82596_exit(void)
1579{
1580 int i;
1581
1582 for (i=0; i<MAX_DRIVERS; i++) {
1583 struct i596_private *lp;
1584 struct net_device *netdevice;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001585
Linus Torvalds1da177e2005-04-16 15:20:36 -07001586 netdevice = netdevs[i];
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001587 if (!netdevice)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001588 continue;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001589
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590 unregister_netdev(netdevice);
1591
1592 lp = netdevice->priv;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001593 dma_free_noncoherent(lp->dev, sizeof(struct i596_private),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001594 (void *)netdevice->mem_start, lp->dma_addr);
1595 free_netdev(netdevice);
1596 }
1597 num_drivers = 0;
1598
1599 unregister_parisc_driver(&lan_driver);
1600}
1601
1602module_exit(lasi_82596_exit);