1 /* 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
8 3 primary sources of the mess --
9 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
15 3) The implementation HP is using seems to be significantly pickier
16 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)
24
25 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 Public License as modified by SRC,
64 incorporated herein by reference.
65
66 The author may be reached as becker@super.org or
67 C/O Supercomputing Research Ctr., 17100 Science Dr., Bowie MD 20715
68
69 */
70
71 static const char *version = "82596.c $Revision: 1.14 $\n";
72
73 #include <linux/module.h>
74
75 #include <linux/kernel.h>
76 #include <linux/sched.h>
77 #include <linux/string.h>
78 #include <linux/ptrace.h>
79 #include <linux/errno.h>
80 #include <linux/ioport.h>
81 #include <linux/malloc.h>
82 #include <linux/interrupt.h>
83 #include <linux/delay.h>
84 #include <linux/netdevice.h>
85 #include <linux/etherdevice.h>
86 #include <linux/skbuff.h>
87 #include <linux/init.h>
88 #include <linux/pci.h>
89
90 #include <asm/bitops.h>
91 #include <asm/io.h>
92 #include <asm/pgtable.h>
93 #include <asm/pgalloc.h>
94 #include <asm/irq.h>
95
96 #include <asm/pdc.h>
97 #include <asm/gsc.h>
98 #include <asm/cache.h>
99
100 /* DEBUG flags
101 */
102
103 #define DEB_INIT 0x0001
104 #define DEB_PROBE 0x0002
105 #define DEB_SERIOUS 0x0004
106 #define DEB_ERRORS 0x0008
107 #define DEB_MULTI 0x0010
108 #define DEB_TDR 0x0020
109 #define DEB_OPEN 0x0040
110 #define DEB_RESET 0x0080
111 #define DEB_ADDCMD 0x0100
112 #define DEB_STATUS 0x0200
113 #define DEB_STARTTX 0x0400
114 #define DEB_RXADDR 0x0800
115 #define DEB_TXADDR 0x1000
116 #define DEB_RXFRAME 0x2000
117 #define DEB_INTS 0x4000
118 #define DEB_STRUCT 0x8000
119 #define DEB_ANY 0xffff
120
121
122 #define DEB(x,y) if (i596_debug & (x)) y
123
124
125 #define CHECK_WBACK(addr,len) \
126 do { if (!dma_consistent) dma_cache_wback((unsigned long)addr,len); } while (0)
127
128 #define CHECK_INV(addr,len) \
129 do { if (!dma_consistent) dma_cache_inv((unsigned long)addr,len); } while(0)
130
131 #define CHECK_WBACK_INV(addr,len) \
132 do { if (!dma_consistent) dma_cache_wback_inv((unsigned long)addr,len); } while (0)
133
134
135 #define PA_I82596_RESET 0 /* Offsets relative to LASI-LAN-Addr.*/
136 #define PA_CPU_PORT_L_ACCESS 4
137 #define PA_CHANNEL_ATTENTION 8
138
139
140 /*
141 * Define various macros for Channel Attention, word swapping etc., dependent
142 * on architecture. MVME and BVME are 680x0 based, otherwise it is Intel.
143 */
144
145 #ifdef __BIG_ENDIAN
146 #define WSWAPrfd(x) ((struct i596_rfd *) (((u32)(x)<<16) | ((((u32)(x)))>>16)))
147 #define WSWAPrbd(x) ((struct i596_rbd *) (((u32)(x)<<16) | ((((u32)(x)))>>16)))
148 #define WSWAPiscp(x) ((struct i596_iscp *)(((u32)(x)<<16) | ((((u32)(x)))>>16)))
149 #define WSWAPscb(x) ((struct i596_scb *) (((u32)(x)<<16) | ((((u32)(x)))>>16)))
150 #define WSWAPcmd(x) ((struct i596_cmd *) (((u32)(x)<<16) | ((((u32)(x)))>>16)))
151 #define WSWAPtbd(x) ((struct i596_tbd *) (((u32)(x)<<16) | ((((u32)(x)))>>16)))
152 #define WSWAPchar(x) ((char *) (((u32)(x)<<16) | ((((u32)(x)))>>16)))
153 #define ISCP_BUSY 0x00010000
154 #define MACH_IS_APRICOT 0
155 #else
156 #define WSWAPrfd(x) ((struct i596_rfd *)(x))
157 #define WSWAPrbd(x) ((struct i596_rbd *)(x))
158 #define WSWAPiscp(x) ((struct i596_iscp *)(x))
159 #define WSWAPscb(x) ((struct i596_scb *)(x))
160 #define WSWAPcmd(x) ((struct i596_cmd *)(x))
161 #define WSWAPtbd(x) ((struct i596_tbd *)(x))
162 #define WSWAPchar(x) ((char *)(x))
163 #define ISCP_BUSY 0x0001
164 #define MACH_IS_APRICOT 1
165 #endif
166
167 /*
168 * The MPU_PORT command allows direct access to the 82596. With PORT access
169 * the following commands are available (p5-18). The 32-bit port command
170 * must be word-swapped with the most significant word written first.
171 * This only applies to VME boards.
172 */
173 #define PORT_RESET 0x00 /* reset 82596 */
174 #define PORT_SELFTEST 0x01 /* selftest */
175 #define PORT_ALTSCP 0x02 /* alternate SCB address */
176 #define PORT_ALTDUMP 0x03 /* Alternate DUMP address */
177
178 static int i596_debug = (DEB_SERIOUS|DEB_PROBE);
179
180 MODULE_AUTHOR("Richard Hirst");
181 MODULE_DESCRIPTION("i82596 driver");
182 MODULE_PARM(i596_debug, "i");
183
184
185 /* Copy frames shorter than rx_copybreak, otherwise pass on up in
186 * a full sized sk_buff. Value of 100 stolen from tulip.c (!alpha).
187 */
188 static int rx_copybreak = 100;
189
190 #define PKT_BUF_SZ 1536
191 #define MAX_MC_CNT 64
192
193 #define I596_TOTAL_SIZE 17
194
195 #define I596_NULL ((void *)0xffffffff)
196
197 #define CMD_EOL 0x8000 /* The last command of the list, stop. */
198 #define CMD_SUSP 0x4000 /* Suspend after doing cmd. */
199 #define CMD_INTR 0x2000 /* Interrupt after doing cmd. */
200
201 #define CMD_FLEX 0x0008 /* Enable flexible memory model */
202
203 enum commands {
204 CmdNOp = 0, CmdSASetup = 1, CmdConfigure = 2, CmdMulticastList = 3,
205 CmdTx = 4, CmdTDR = 5, CmdDump = 6, CmdDiagnose = 7
206 };
207
208 #define STAT_C 0x8000 /* Set to 0 after execution */
209 #define STAT_B 0x4000 /* Command being executed */
210 #define STAT_OK 0x2000 /* Command executed ok */
211 #define STAT_A 0x1000 /* Command aborted */
212
213 #define CUC_START 0x0100
214 #define CUC_RESUME 0x0200
215 #define CUC_SUSPEND 0x0300
216 #define CUC_ABORT 0x0400
217 #define RX_START 0x0010
218 #define RX_RESUME 0x0020
219 #define RX_SUSPEND 0x0030
220 #define RX_ABORT 0x0040
221
222 #define TX_TIMEOUT 5
223
224 #define OPT_SWAP_PORT 0x0001 /* Need to wordswp on the MPU port */
225
226
227 struct i596_reg {
228 unsigned short porthi;
229 unsigned short portlo;
230 unsigned long ca;
231 };
232
233 #define EOF 0x8000
234 #define SIZE_MASK 0x3fff
235
236 struct i596_tbd {
237 unsigned short size;
238 unsigned short pad;
239 struct i596_tbd *next;
240 char *data;
241 long cache_pad[5]; /* Total 32 bytes... */
242 };
243
244 /* The command structure has two 'next' pointers; v_next is the address of
245 * the next command as seen by the CPU, b_next is the address of the next
246 * command as seen by the 82596. The b_next pointer, as used by the 82596
247 * always references the status field of the next command, rather than the
248 * v_next field, because the 82596 is unaware of v_next. It may seem more
249 * logical to put v_next at the end of the structure, but we cannot do that
250 * because the 82596 expects other fields to be there, depending on command
251 * type.
252 */
253
254 struct i596_cmd {
255 struct i596_cmd *v_next; /* Address from CPUs viewpoint */
256 unsigned short status;
257 unsigned short command;
258 struct i596_cmd *b_next; /* Address from i596 viewpoint */
259 };
260
261 struct tx_cmd {
262 struct i596_cmd cmd;
263 struct i596_tbd *tbd;
264 unsigned short size;
265 unsigned short pad;
266 struct sk_buff *skb; /* So we can free it after tx */
267 dma_addr_t dma_addr;
268 long cache_pad[1]; /* Total 32 bytes... */
269 };
270
271 struct tdr_cmd {
272 struct i596_cmd cmd;
273 unsigned short status;
274 unsigned short pad;
275 };
276
277 struct mc_cmd {
278 struct i596_cmd cmd;
279 short mc_cnt;
280 char mc_addrs[MAX_MC_CNT*6];
281 };
282
283 struct sa_cmd {
284 struct i596_cmd cmd;
285 char eth_addr[8];
286 };
287
288 struct cf_cmd {
289 struct i596_cmd cmd;
290 char i596_config[16];
291 };
292
293 struct i596_rfd {
294 unsigned short stat;
295 unsigned short cmd;
296 struct i596_rfd *b_next; /* Address from i596 viewpoint */
297 struct i596_rbd *rbd;
298 unsigned short count;
299 unsigned short size;
300 struct i596_rfd *v_next; /* Address from CPUs viewpoint */
301 struct i596_rfd *v_prev;
302 long cache_pad[2]; /* Total 32 bytes... */
303 };
304
305 struct i596_rbd {
306 unsigned short count;
307 unsigned short zero1;
308 struct i596_rbd *b_next;
309 unsigned char *b_data; /* Address from i596 viewpoint */
310 unsigned short size;
311 unsigned short zero2;
312 struct sk_buff *skb;
313 struct i596_rbd *v_next;
314 struct i596_rbd *b_addr; /* This rbd addr from i596 view */
315 unsigned char *v_data; /* Address from CPUs viewpoint */
316 /* Total 32 bytes... */
317 };
318
319 /* These values as chosen so struct i596_private fits in one page... */
320
321 #define TX_RING_SIZE 32
322 #define RX_RING_SIZE 16
323
324 struct i596_scb {
325 unsigned short status;
326 unsigned short command;
327 struct i596_cmd *cmd;
328 struct i596_rfd *rfd;
329 unsigned long crc_err;
330 unsigned long align_err;
331 unsigned long resource_err;
332 unsigned long over_err;
333 unsigned long rcvdt_err;
334 unsigned long short_err;
335 unsigned short t_on;
336 unsigned short t_off;
337 };
338
339 struct i596_iscp {
340 unsigned long stat;
341 struct i596_scb *scb;
342 };
343
344 struct i596_scp {
345 unsigned long sysbus;
346 unsigned long pad;
347 struct i596_iscp *iscp;
348 };
349
350 struct i596_private {
351 volatile struct i596_scp scp __attribute__((aligned(32)));
352 volatile struct i596_iscp iscp __attribute__((aligned(32)));
353 volatile struct i596_scb scb __attribute__((aligned(32)));
354 struct sa_cmd sa_cmd __attribute__((aligned(32)));
355 struct cf_cmd cf_cmd __attribute__((aligned(32)));
356 struct tdr_cmd tdr_cmd __attribute__((aligned(32)));
357 struct mc_cmd mc_cmd __attribute__((aligned(32)));
358 struct i596_rfd rfds[RX_RING_SIZE] __attribute__((aligned(32)));
359 struct i596_rbd rbds[RX_RING_SIZE] __attribute__((aligned(32)));
360 struct tx_cmd tx_cmds[TX_RING_SIZE] __attribute__((aligned(32)));
361 struct i596_tbd tbds[TX_RING_SIZE] __attribute__((aligned(32)));
362 unsigned long stat;
363 int last_restart;
364 struct i596_rfd *rfd_head;
365 struct i596_rbd *rbd_head;
366 struct i596_cmd *cmd_tail;
367 struct i596_cmd *cmd_head;
368 int cmd_backlog;
369 unsigned long last_cmd;
370 struct net_device_stats stats;
371 int next_tx_cmd;
372 int options;
373 spinlock_t lock;
374 dma_addr_t dma_addr;
375 };
376
377 char init_setup[] =
378 {
379 0x8E, /* length, prefetch on */
380 0xC8, /* fifo to 8, monitor off */
381 0x80, /* don't save bad frames */
382 0x2E, /* No source address insertion, 8 byte preamble */
383 0x00, /* priority and backoff defaults */
384 0x60, /* interframe spacing */
385 0x00, /* slot time LSB */
386 0xf2, /* slot time and retries */
387 0x00, /* promiscuous mode */
388 0x00, /* collision detect */
389 0x40, /* minimum frame length */
390 0xff,
391 0x00,
392 0x7f /* *multi IA */ };
393
394 static int dma_consistent = 1; /* Zero if pci_alloc_consistent() fails */
395
396 static int i596_open(struct net_device *dev);
397 static int i596_start_xmit(struct sk_buff *skb, struct net_device *dev);
398 static void i596_interrupt(int irq, void *dev_id, struct pt_regs *regs);
399 static int i596_close(struct net_device *dev);
400 static struct net_device_stats *i596_get_stats(struct net_device *dev);
401 static void i596_add_cmd(struct net_device *dev, struct i596_cmd *cmd);
402 static void i596_tx_timeout (struct net_device *dev);
403 static void print_eth(unsigned char *buf, char *str);
404 static void set_multicast_list(struct net_device *dev);
405
406 static int rx_ring_size = RX_RING_SIZE;
407 static int ticks_limit = 100;
408 static int max_cmd_backlog = TX_RING_SIZE-1;
409
410
411 static inline void CA(struct net_device *dev)
412 {
413 gsc_writel(0, (void*)(dev->base_addr + PA_CHANNEL_ATTENTION));
414 }
415
416
417 static inline void MPU_PORT(struct net_device *dev, int c, volatile void *x)
418 {
419 struct i596_private *lp = (struct i596_private *) dev->priv;
420
421 u32 v = (u32) (c) | (u32) (x);
422
423 if (lp->options & OPT_SWAP_PORT)
424 v = ((u32) (v) << 16) | ((u32) (v) >> 16);
425
426 gsc_writel(v & 0xffff, (void*)(dev->base_addr + PA_CPU_PORT_L_ACCESS));
427 udelay(1);
428 gsc_writel(v >> 16, (void*)(dev->base_addr + PA_CPU_PORT_L_ACCESS));
429 }
430
431
432 static inline int wait_istat(struct net_device *dev, struct i596_private *lp, int delcnt, char *str)
433 {
434 CHECK_INV(&(lp->iscp), sizeof(struct i596_iscp));
435 while (--delcnt && lp->iscp.stat) {
436 udelay(10);
437 CHECK_INV(&(lp->iscp), sizeof(struct i596_iscp));
438 }
439 if (!delcnt) {
440 printk("%s: %s, iscp.stat %04lx, didn't clear\n",
441 dev->name, str, lp->iscp.stat);
442 return -1;
443 }
444 else
445 return 0;
446 }
447
448
449 static inline int wait_cmd(struct net_device *dev, struct i596_private *lp, int delcnt, char *str)
450 {
451 CHECK_INV(&(lp->scb), sizeof(struct i596_scb));
452 while (--delcnt && lp->scb.command) {
453 udelay(10);
454 CHECK_INV(&(lp->scb), sizeof(struct i596_scb));
455 }
456 if (!delcnt) {
457 printk("%s: %s, status %4.4x, cmd %4.4x.\n",
458 dev->name, str, lp->scb.status, lp->scb.command);
459 return -1;
460 }
461 else
462 return 0;
463 }
464
465
466 static void i596_display_data(struct net_device *dev)
467 {
468 struct i596_private *lp = (struct i596_private *) dev->priv;
469 struct i596_cmd *cmd;
470 struct i596_rfd *rfd;
471 struct i596_rbd *rbd;
472
473 printk("lp and scp at %p, .sysbus = %08lx, .iscp = %p\n",
474 &lp->scp, lp->scp.sysbus, lp->scp.iscp);
475 printk("iscp at %p, iscp.stat = %08lx, .scb = %p\n",
476 &lp->iscp, lp->iscp.stat, lp->iscp.scb);
477 printk("scb at %p, scb.status = %04x, .command = %04x,"
478 " .cmd = %p, .rfd = %p\n",
479 &lp->scb, lp->scb.status, lp->scb.command,
480 lp->scb.cmd, lp->scb.rfd);
481 printk(" errors: crc %lx, align %lx, resource %lx,"
482 " over %lx, rcvdt %lx, short %lx\n",
483 lp->scb.crc_err, lp->scb.align_err, lp->scb.resource_err,
484 lp->scb.over_err, lp->scb.rcvdt_err, lp->scb.short_err);
485 cmd = lp->cmd_head;
486 while (cmd != I596_NULL) {
487 printk("cmd at %p, .status = %04x, .command = %04x, .b_next = %p\n",
488 cmd, cmd->status, cmd->command, cmd->b_next);
489 cmd = cmd->v_next;
490 }
491 rfd = lp->rfd_head;
492 printk("rfd_head = %p\n", rfd);
493 do {
494 printk (" %p .stat %04x, .cmd %04x, b_next %p, rbd %p,"
495 " count %04x\n",
496 rfd, rfd->stat, rfd->cmd, rfd->b_next, rfd->rbd,
497 rfd->count);
498 rfd = rfd->v_next;
499 } while (rfd != lp->rfd_head);
500 rbd = lp->rbd_head;
501 printk("rbd_head = %p\n", rbd);
502 do {
503 printk(" %p .count %04x, b_next %p, b_data %p, size %04x\n",
504 rbd, rbd->count, rbd->b_next, rbd->b_data, rbd->size);
505 rbd = rbd->v_next;
506 } while (rbd != lp->rbd_head);
507 CHECK_INV(lp, sizeof(struct i596_private));
508 }
509
510
511 #if defined(ENABLE_MVME16x_NET) || defined(ENABLE_BVME6000_NET)
512 static void i596_error(int irq, void *dev_id, struct pt_regs *regs)
513 {
514 struct net_device *dev = dev_id;
515 volatile unsigned char *pcc2 = (unsigned char *) 0xfff42000;
516
517 pcc2[0x28] = 1;
518 pcc2[0x2b] = 0x1d;
519 printk("%s: Error interrupt\n", dev->name);
520 i596_display_data(dev);
521 }
522 #endif
523
524 #define virt_to_dma(lp,v) ((char *)(v)-(char *)(lp)+(char *)((lp)->dma_addr))
525
526 static inline void init_rx_bufs(struct net_device *dev)
527 {
528 struct i596_private *lp = (struct i596_private *)dev->priv;
529 int i;
530 struct i596_rfd *rfd;
531 struct i596_rbd *rbd;
532
533 /* First build the Receive Buffer Descriptor List */
534
535 for (i = 0, rbd = lp->rbds; i < rx_ring_size; i++, rbd++) {
536 dma_addr_t dma_addr;
537 struct sk_buff *skb = dev_alloc_skb(PKT_BUF_SZ + 4);
538
539 if (skb == NULL)
540 panic("82596: alloc_skb() failed");
541 skb_reserve(skb, 2);
542 dma_addr = pci_map_single(NULL, skb->tail,PKT_BUF_SZ,
543 PCI_DMA_FROMDEVICE);
544 skb->dev = dev;
545 rbd->v_next = rbd+1;
546 rbd->b_next = WSWAPrbd(virt_to_dma(lp,rbd+1));
547 rbd->b_addr = WSWAPrbd(virt_to_dma(lp,rbd));
548 rbd->skb = skb;
549 rbd->v_data = skb->tail;
550 rbd->b_data = WSWAPchar(dma_addr);
551 rbd->size = PKT_BUF_SZ;
552 }
553 lp->rbd_head = lp->rbds;
554 rbd = lp->rbds + rx_ring_size - 1;
555 rbd->v_next = lp->rbds;
556 rbd->b_next = WSWAPrbd(virt_to_dma(lp,lp->rbds));
557
558 /* Now build the Receive Frame Descriptor List */
559
560 for (i = 0, rfd = lp->rfds; i < rx_ring_size; i++, rfd++) {
561 rfd->rbd = I596_NULL;
562 rfd->v_next = rfd+1;
563 rfd->v_prev = rfd-1;
564 rfd->b_next = WSWAPrfd(virt_to_dma(lp,rfd+1));
565 rfd->cmd = CMD_FLEX;
566 }
567 lp->rfd_head = lp->rfds;
568 lp->scb.rfd = WSWAPrfd(virt_to_dma(lp,lp->rfds));
569 rfd = lp->rfds;
570 rfd->rbd = lp->rbd_head;
571 rfd->v_prev = lp->rfds + rx_ring_size - 1;
572 rfd = lp->rfds + rx_ring_size - 1;
573 rfd->v_next = lp->rfds;
574 rfd->b_next = WSWAPrfd(virt_to_dma(lp,lp->rfds));
575 rfd->cmd = CMD_EOL|CMD_FLEX;
576
577 CHECK_WBACK_INV(lp, sizeof(struct i596_private));
578 }
579
580 static inline void remove_rx_bufs(struct net_device *dev)
581 {
582 struct i596_private *lp = (struct i596_private *)dev->priv;
583 struct i596_rbd *rbd;
584 int i;
585
586 for (i = 0, rbd = lp->rbds; i < rx_ring_size; i++, rbd++) {
587 if (rbd->skb == NULL)
588 break;
589 pci_unmap_single(NULL,(dma_addr_t)WSWAPchar(rbd->b_data), PKT_BUF_SZ, PCI_DMA_FROMDEVICE);
590 dev_kfree_skb(rbd->skb);
591 }
592 }
593
594
595 static void rebuild_rx_bufs(struct net_device *dev)
596 {
597 struct i596_private *lp = (struct i596_private *) dev->priv;
598 int i;
599
600 /* Ensure rx frame/buffer descriptors are tidy */
601
602 for (i = 0; i < rx_ring_size; i++) {
603 lp->rfds[i].rbd = I596_NULL;
604 lp->rfds[i].cmd = CMD_FLEX;
605 }
606 lp->rfds[rx_ring_size-1].cmd = CMD_EOL|CMD_FLEX;
607 lp->rfd_head = lp->rfds;
608 lp->scb.rfd = WSWAPrfd(virt_to_dma(lp,lp->rfds));
609 lp->rbd_head = lp->rbds;
610 lp->rfds[0].rbd = WSWAPrbd(virt_to_dma(lp,lp->rbds));
611
612 CHECK_WBACK_INV(lp, sizeof(struct i596_private));
613 }
614
615
616 static int init_i596_mem(struct net_device *dev)
617 {
618 struct i596_private *lp = (struct i596_private *) dev->priv;
619 unsigned long flags;
620
621 disable_irq(dev->irq); /* disable IRQs from LAN */
622 DEB(DEB_INIT,
623 printk("RESET 82596 port: %08lX (with IRQ%d disabled)\n",
624 dev->base_addr + PA_I82596_RESET,
625 dev->irq));
626
627 gsc_writel(0, (void*)(dev->base_addr + PA_I82596_RESET)); /* Hard Reset */
628 udelay(100); /* Wait 100us - seems to help */
629
630 /* change the scp address */
631
632 lp->last_cmd = jiffies;
633
634
635 lp->scp.sysbus = 0x0000006c;
636 lp->scp.iscp = WSWAPiscp(virt_to_dma(lp,&(lp->iscp)));
637 lp->iscp.scb = WSWAPscb(virt_to_dma(lp,&(lp->scb)));
638 lp->iscp.stat = ISCP_BUSY;
639 lp->cmd_backlog = 0;
640
641 lp->cmd_head = lp->scb.cmd = I596_NULL;
642
643 DEB(DEB_INIT,printk("%s: starting i82596.\n", dev->name));
644
645 CHECK_WBACK(&(lp->scp), sizeof(struct i596_scp));
646 CHECK_WBACK(&(lp->iscp), sizeof(struct i596_iscp));
647
648 MPU_PORT(dev, PORT_ALTSCP, (void *)virt_to_dma(lp,&lp->scp));
649
650 CA(dev);
651
652 if (wait_istat(dev,lp,1000,"initialization timed out"))
653 goto failed;
654 DEB(DEB_INIT,printk("%s: i82596 initialization successful\n", dev->name));
655
656 /* Ensure rx frame/buffer descriptors are tidy */
657 rebuild_rx_bufs(dev);
658
659 lp->scb.command = 0;
660 CHECK_WBACK(&(lp->scb), sizeof(struct i596_scb));
661
662 enable_irq(dev->irq); /* enable IRQs from LAN */
663
664 DEB(DEB_INIT,printk("%s: queuing CmdConfigure\n", dev->name));
665 memcpy(lp->cf_cmd.i596_config, init_setup, 14);
666 lp->cf_cmd.cmd.command = CmdConfigure;
667 CHECK_WBACK(&(lp->cf_cmd), sizeof(struct cf_cmd));
668 i596_add_cmd(dev, &lp->cf_cmd.cmd);
669
670 DEB(DEB_INIT,printk("%s: queuing CmdSASetup\n", dev->name));
671 memcpy(lp->sa_cmd.eth_addr, dev->dev_addr, 6);
672 lp->sa_cmd.cmd.command = CmdSASetup;
673 CHECK_WBACK(&(lp->sa_cmd), sizeof(struct sa_cmd));
674 i596_add_cmd(dev, &lp->sa_cmd.cmd);
675
676 DEB(DEB_INIT,printk("%s: queuing CmdTDR\n", dev->name));
677 lp->tdr_cmd.cmd.command = CmdTDR;
678 CHECK_WBACK(&(lp->tdr_cmd), sizeof(struct tdr_cmd));
679 i596_add_cmd(dev, &lp->tdr_cmd.cmd);
680
681 spin_lock_irqsave (&lp->lock, flags);
682
683 if (wait_cmd(dev,lp,1000,"timed out waiting to issue RX_START")) {
684 spin_unlock_irqrestore (&lp->lock, flags);
685 goto failed;
686 }
687 DEB(DEB_INIT,printk("%s: Issuing RX_START\n", dev->name));
688 lp->scb.command = RX_START;
689 lp->scb.rfd = WSWAPrfd(virt_to_dma(lp,lp->rfds));
690 CHECK_WBACK(&(lp->scb), sizeof(struct i596_scb));
691
692 CA(dev);
693
694 spin_unlock_irqrestore (&lp->lock, flags);
695
696 if (wait_cmd(dev,lp,1000,"RX_START not processed"))
697 goto failed;
698 DEB(DEB_INIT,printk("%s: Receive unit started OK\n", dev->name));
699
700 return 0;
701
702 failed:
703 printk("%s: Failed to initialise 82596\n", dev->name);
704 MPU_PORT(dev, PORT_RESET, 0);
705 return -1;
706 }
707
708
709 static inline int i596_rx(struct net_device *dev)
710 {
711 struct i596_private *lp = (struct i596_private *)dev->priv;
712 struct i596_rfd *rfd;
713 struct i596_rbd *rbd;
714 int frames = 0;
715
716 DEB(DEB_RXFRAME,printk ("i596_rx(), rfd_head %p, rbd_head %p\n",
717 lp->rfd_head, lp->rbd_head));
718
719
720 rfd = lp->rfd_head; /* Ref next frame to check */
721
722 CHECK_INV(rfd, sizeof(struct i596_rfd));
723 while ((rfd->stat) & STAT_C) { /* Loop while complete frames */
724 if (rfd->rbd == I596_NULL)
725 rbd = I596_NULL;
726 else if (rfd->rbd == lp->rbd_head->b_addr) {
727 rbd = lp->rbd_head;
728 CHECK_INV(rbd, sizeof(struct i596_rbd));
729 }
730 else {
731 printk("%s: rbd chain broken!\n", dev->name);
732 /* XXX Now what? */
733 rbd = I596_NULL;
734 }
735 DEB(DEB_RXFRAME, printk(" rfd %p, rfd.rbd %p, rfd.stat %04x\n",
736 rfd, rfd->rbd, rfd->stat));
737
738 if (rbd != I596_NULL && ((rfd->stat) & STAT_OK)) {
739 /* a good frame */
740 int pkt_len = rbd->count & 0x3fff;
741 struct sk_buff *skb = rbd->skb;
742 int rx_in_place = 0;
743
744 DEB(DEB_RXADDR,print_eth(rbd->v_data, "received"));
745 frames++;
746
747 /* Check if the packet is long enough to just accept
748 * without copying to a properly sized skbuff.
749 */
750
751 if (pkt_len > rx_copybreak) {
752 struct sk_buff *newskb;
753 dma_addr_t dma_addr;
754
755 pci_unmap_single(NULL,(dma_addr_t)WSWAPchar(rbd->b_data), PKT_BUF_SZ, PCI_DMA_FROMDEVICE);
756 /* Get fresh skbuff to replace filled one. */
757 newskb = dev_alloc_skb(PKT_BUF_SZ + 4);
758 if (newskb == NULL) {
759 skb = NULL; /* drop pkt */
760 goto memory_squeeze;
761 }
762 skb_reserve(newskb, 2);
763
764 /* Pass up the skb already on the Rx ring. */
765 skb_put(skb, pkt_len);
766 rx_in_place = 1;
767 rbd->skb = newskb;
768 newskb->dev = dev;
769 dma_addr = pci_map_single(NULL, newskb->tail, PKT_BUF_SZ, PCI_DMA_FROMDEVICE);
770 rbd->v_data = newskb->tail;
771 rbd->b_data = WSWAPchar(dma_addr);
772 CHECK_WBACK_INV(rbd, sizeof(struct i596_rbd));
773 }
774 else
775 skb = dev_alloc_skb(pkt_len + 2);
776 memory_squeeze:
777 if (skb == NULL) {
778 /* XXX tulip.c can defer packets here!! */
779 printk ("%s: i596_rx Memory squeeze, dropping packet.\n", dev->name);
780 lp->stats.rx_dropped++;
781 }
782 else {
783 skb->dev = dev;
784 if (!rx_in_place) {
785 /* 16 byte align the data fields */
786 pci_dma_sync_single(NULL, (dma_addr_t)WSWAPchar(rbd->b_data), PKT_BUF_SZ, PCI_DMA_FROMDEVICE);
787 skb_reserve(skb, 2);
788 memcpy(skb_put(skb,pkt_len), rbd->v_data, pkt_len);
789 }
790 skb->len = pkt_len;
791 skb->protocol=eth_type_trans(skb,dev);
792 netif_rx(skb);
793 lp->stats.rx_packets++;
794 lp->stats.rx_bytes+=pkt_len;
795 }
796 }
797 else {
798 DEB(DEB_ERRORS, printk("%s: Error, rfd.stat = 0x%04x\n",
799 dev->name, rfd->stat));
800 lp->stats.rx_errors++;
801 if ((rfd->stat) & 0x0001)
802 lp->stats.collisions++;
803 if ((rfd->stat) & 0x0080)
804 lp->stats.rx_length_errors++;
805 if ((rfd->stat) & 0x0100)
806 lp->stats.rx_over_errors++;
807 if ((rfd->stat) & 0x0200)
808 lp->stats.rx_fifo_errors++;
809 if ((rfd->stat) & 0x0400)
810 lp->stats.rx_frame_errors++;
811 if ((rfd->stat) & 0x0800)
812 lp->stats.rx_crc_errors++;
813 if ((rfd->stat) & 0x1000)
814 lp->stats.rx_length_errors++;
815 }
816
817 /* Clear the buffer descriptor count and EOF + F flags */
818
819 if (rbd != I596_NULL && (rbd->count & 0x4000)) {
820 rbd->count = 0;
821 lp->rbd_head = rbd->v_next;
822 CHECK_WBACK_INV(rbd, sizeof(struct i596_rbd));
823 }
824
825 /* Tidy the frame descriptor, marking it as end of list */
826
827 rfd->rbd = I596_NULL;
828 rfd->stat = 0;
829 rfd->cmd = CMD_EOL|CMD_FLEX;
830 rfd->count = 0;
831
832 /* Remove end-of-list from old end descriptor */
833
834 rfd->v_prev->cmd = CMD_FLEX;
835
836 /* Update record of next frame descriptor to process */
837
838 lp->scb.rfd = rfd->b_next;
839 lp->rfd_head = rfd->v_next;
840 CHECK_WBACK_INV(rfd->v_prev, sizeof(struct i596_rfd));
841 CHECK_WBACK_INV(rfd, sizeof(struct i596_rfd));
842 rfd = lp->rfd_head;
843 CHECK_INV(rfd, sizeof(struct i596_rfd));
844 }
845
846 DEB(DEB_RXFRAME,printk ("frames %d\n", frames));
847
848 return 0;
849 }
850
851
852 static inline void i596_cleanup_cmd(struct net_device *dev, struct i596_private *lp)
853 {
854 struct i596_cmd *ptr;
855
856 while (lp->cmd_head != I596_NULL) {
857 ptr = lp->cmd_head;
858 lp->cmd_head = ptr->v_next;
859 lp->cmd_backlog--;
860
861 switch ((ptr->command) & 0x7) {
862 case CmdTx:
863 {
864 struct tx_cmd *tx_cmd = (struct tx_cmd *) ptr;
865 struct sk_buff *skb = tx_cmd->skb;
866 pci_unmap_single(NULL, tx_cmd->dma_addr, skb->len, PCI_DMA_TODEVICE);
867
868 dev_kfree_skb(skb);
869
870 lp->stats.tx_errors++;
871 lp->stats.tx_aborted_errors++;
872
873 ptr->v_next = ptr->b_next = I596_NULL;
874 tx_cmd->cmd.command = 0; /* Mark as free */
875 break;
876 }
877 default:
878 ptr->v_next = ptr->b_next = I596_NULL;
879 }
880 CHECK_WBACK_INV(ptr, sizeof(struct i596_cmd));
881 }
882
883 wait_cmd(dev,lp,100,"i596_cleanup_cmd timed out");
884 lp->scb.cmd = I596_NULL;
885 CHECK_WBACK(&(lp->scb), sizeof(struct i596_scb));
886 }
887
888
889 static inline void i596_reset(struct net_device *dev, struct i596_private *lp, int ioaddr)
890 {
891 unsigned long flags;
892
893 DEB(DEB_RESET,printk("i596_reset\n"));
894
895 spin_lock_irqsave (&lp->lock, flags);
896
897 wait_cmd(dev,lp,100,"i596_reset timed out");
898
899 netif_stop_queue(dev);
900
901 /* FIXME: this command might cause an lpmc */
902 lp->scb.command = CUC_ABORT | RX_ABORT;
903 CHECK_WBACK(&(lp->scb), sizeof(struct i596_scb));
904 CA(dev);
905
906 /* wait for shutdown */
907 wait_cmd(dev,lp,1000,"i596_reset 2 timed out");
908 spin_unlock_irqrestore (&lp->lock, flags);
909
910 i596_cleanup_cmd(dev,lp);
911 i596_rx(dev);
912
913 netif_start_queue(dev);
914 init_i596_mem(dev);
915 }
916
917
918 static void i596_add_cmd(struct net_device *dev, struct i596_cmd *cmd)
919 {
920 struct i596_private *lp = (struct i596_private *) dev->priv;
921 int ioaddr = dev->base_addr;
922 unsigned long flags;
923
924 DEB(DEB_ADDCMD,printk("i596_add_cmd cmd_head %p\n", lp->cmd_head));
925
926 cmd->status = 0;
927 cmd->command |= (CMD_EOL | CMD_INTR);
928 cmd->v_next = cmd->b_next = I596_NULL;
929 CHECK_WBACK(cmd, sizeof(struct i596_cmd));
930
931 spin_lock_irqsave (&lp->lock, flags);
932
933 if (lp->cmd_head != I596_NULL) {
934 lp->cmd_tail->v_next = cmd;
935 lp->cmd_tail->b_next = WSWAPcmd(virt_to_dma(lp,&cmd->status));
936 CHECK_WBACK(lp->cmd_tail, sizeof(struct i596_cmd));
937 } else {
938 lp->cmd_head = cmd;
939 wait_cmd(dev,lp,100,"i596_add_cmd timed out");
940 lp->scb.cmd = WSWAPcmd(virt_to_dma(lp,&cmd->status));
941 lp->scb.command = CUC_START;
942 CHECK_WBACK(&(lp->scb), sizeof(struct i596_scb));
943 CA(dev);
944 }
945 lp->cmd_tail = cmd;
946 lp->cmd_backlog++;
947
948 spin_unlock_irqrestore (&lp->lock, flags);
949
950 if (lp->cmd_backlog > max_cmd_backlog) {
951 unsigned long tickssofar = jiffies - lp->last_cmd;
952
953 if (tickssofar < ticks_limit)
954 return;
955
956 printk("%s: command unit timed out, status resetting.\n", dev->name);
957 #if 1
958 i596_reset(dev, lp, ioaddr);
959 #endif
960 }
961 }
962
963 #if 0
964 /* this function makes a perfectly adequate probe... but we have a
965 device list */
966 static int i596_test(struct net_device *dev)
967 {
968 struct i596_private *lp = (struct i596_private *) dev->priv;
969 volatile int *tint;
970 u32 data;
971
972 tint = (volatile int *)(&(lp->scp));
973 data = virt_to_dma(lp,tint);
974
975 tint[1] = -1;
976 CHECK_WBACK(tint,PAGE_SIZE);
977
978 MPU_PORT(dev, 1, data);
979
980 for(data = 1000000; data; data--) {
981 CHECK_INV(tint,PAGE_SIZE);
982 if(tint[1] != -1)
983 break;
984
985 }
986
987 printk("i596_test result %d\n", tint[1]);
988
989 }
990 #endif
991
992
993 static int i596_open(struct net_device *dev)
994 {
995 int res = 0;
996
997 DEB(DEB_OPEN,printk("%s: i596_open() irq %d.\n", dev->name, dev->irq));
998
999 if (request_irq(dev->irq, &i596_interrupt, 0, "i82596", dev)) {
1000 printk("%s: IRQ %d not free\n", dev->name, dev->irq);
1001 return -EAGAIN;
1002 }
1003
1004 request_region(dev->base_addr, 12, dev->name);
1005
1006 init_rx_bufs(dev);
1007
1008 netif_start_queue(dev);
1009
1010 MOD_INC_USE_COUNT;
1011
1012 /* Initialize the 82596 memory */
1013 if (init_i596_mem(dev)) {
1014 res = -EAGAIN;
1015 free_irq(dev->irq, dev);
1016 }
1017
1018 return res;
1019 }
1020
1021 static void i596_tx_timeout (struct net_device *dev)
1022 {
1023 struct i596_private *lp = (struct i596_private *) dev->priv;
1024 int ioaddr = dev->base_addr;
1025
1026 /* Transmitter timeout, serious problems. */
1027 DEB(DEB_ERRORS,printk("%s: transmit timed out, status resetting.\n",
1028 dev->name));
1029
1030 lp->stats.tx_errors++;
1031
1032 /* Try to restart the adaptor */
1033 if (lp->last_restart == lp->stats.tx_packets) {
1034 DEB(DEB_ERRORS,printk ("Resetting board.\n"));
1035 /* Shutdown and restart */
1036 i596_reset (dev, lp, ioaddr);
1037 } else {
1038 /* Issue a channel attention signal */
1039 DEB(DEB_ERRORS,printk ("Kicking board.\n"));
1040 lp->scb.command = CUC_START | RX_START;
1041 CHECK_WBACK_INV(&(lp->scb), sizeof(struct i596_scb));
1042 CA (dev);
1043 lp->last_restart = lp->stats.tx_packets;
1044 }
1045
1046 dev->trans_start = jiffies;
1047 netif_wake_queue (dev);
1048 }
1049
1050
1051 static int i596_start_xmit(struct sk_buff *skb, struct net_device *dev)
1052 {
1053 struct i596_private *lp = (struct i596_private *) dev->priv;
1054 struct tx_cmd *tx_cmd;
1055 struct i596_tbd *tbd;
1056 short length = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
1057 dev->trans_start = jiffies;
1058
1059 DEB(DEB_STARTTX,printk("%s: i596_start_xmit(%x,%x) called\n", dev->name,
1060 skb->len, (unsigned int)skb->data));
1061
1062 netif_stop_queue(dev);
1063
1064 tx_cmd = lp->tx_cmds + lp->next_tx_cmd;
1065 tbd = lp->tbds + lp->next_tx_cmd;
1066
1067 if (tx_cmd->cmd.command) {
1068 DEB(DEB_ERRORS,printk ("%s: xmit ring full, dropping packet.\n",
1069 dev->name));
1070 lp->stats.tx_dropped++;
1071
1072 dev_kfree_skb(skb);
1073 } else {
1074 if (++lp->next_tx_cmd == TX_RING_SIZE)
1075 lp->next_tx_cmd = 0;
1076 tx_cmd->tbd = WSWAPtbd(virt_to_dma(lp,tbd));
1077 tbd->next = I596_NULL;
1078
1079 tx_cmd->cmd.command = CMD_FLEX | CmdTx;
1080 tx_cmd->skb = skb;
1081
1082 tx_cmd->pad = 0;
1083 tx_cmd->size = 0;
1084 tbd->pad = 0;
1085 tbd->size = EOF | length;
1086
1087 tx_cmd->dma_addr = pci_map_single(NULL, skb->data, skb->len,
1088 PCI_DMA_TODEVICE);
1089 tbd->data = WSWAPchar(tx_cmd->dma_addr);
1090
1091 DEB(DEB_TXADDR,print_eth(skb->data, "tx-queued"));
1092 CHECK_WBACK_INV(tx_cmd, sizeof(struct tx_cmd));
1093 CHECK_WBACK_INV(tbd, sizeof(struct i596_tbd));
1094 i596_add_cmd(dev, &tx_cmd->cmd);
1095
1096 lp->stats.tx_packets++;
1097 lp->stats.tx_bytes += length;
1098 }
1099
1100 netif_start_queue(dev);
1101
1102 return 0;
1103 }
1104
1105 static void print_eth(unsigned char *add, char *str)
1106 {
1107 int i;
1108
1109 printk("i596 0x%p, ", add);
1110 for (i = 0; i < 6; i++)
1111 printk(" %02X", add[i + 6]);
1112 printk(" -->");
1113 for (i = 0; i < 6; i++)
1114 printk(" %02X", add[i]);
1115 printk(" %02X%02X, %s\n", add[12], add[13], str);
1116 }
1117
1118
1119 #define LAN_PROM_ADDR 0xF0810000
1120
1121 static int __init i82596_probe(struct net_device *dev, int options)
1122 {
1123 int i;
1124 struct i596_private *lp;
1125 char eth_addr[6];
1126 dma_addr_t dma_addr;
1127
1128 /* This lot is ensure things have been cache line aligned. */
1129 if (sizeof(struct i596_rfd) != 32) {
1130 printk("82596: sizeof(struct i596_rfd) = %d\n",
1131 sizeof(struct i596_rfd));
1132 return -ENODEV;
1133 }
1134 if (sizeof(struct i596_rbd) != 32) {
1135 printk("82596: sizeof(struct i596_rbd) = %d\n",
1136 sizeof(struct i596_rbd));
1137 return -ENODEV;
1138 }
1139 if (sizeof(struct tx_cmd) != 32) {
1140 printk("82596: sizeof(struct tx_cmd) = %d\n",
1141 sizeof(struct tx_cmd));
1142 return -ENODEV;
1143 }
1144 if (sizeof(struct i596_tbd) != 32) {
1145 printk("82596: sizeof(struct i596_tbd) = %d\n",
1146 sizeof(struct i596_tbd));
1147 return -ENODEV;
1148 }
1149 if (sizeof(struct i596_private) > 4096) {
1150 printk("82596: sizeof(struct i596_private) = %d\n",
1151 sizeof(struct i596_private));
1152 return -ENODEV;
1153 }
1154
1155 /* FIXME:
1156 Currently this works only, if set-up from lasi.c.
1157 This should be changed to use probing too !
1158 */
1159
1160 if (!dev->base_addr || !dev->irq)
1161 return -ENODEV;
1162
1163 if (!pdc_lan_station_id( (char*)ð_addr, (void*)dev->base_addr)) {
1164 for(i=0;i<6;i++)
1165 eth_addr[i] = gsc_readb(LAN_PROM_ADDR+i);
1166 printk("82596.c: MAC of HP700 LAN blindely read from the prom!\n");
1167 }
1168
1169 dev->mem_start = (int)pci_alloc_consistent( NULL,
1170 sizeof(struct i596_private), &dma_addr);
1171 if (!dev->mem_start) {
1172 printk("%s: Couldn't get consistent shared memory\n", dev->name);
1173 dma_consistent = 0;
1174 dev->mem_start = (int)__get_free_pages(GFP_ATOMIC, 0);
1175 if (!dev->mem_start) {
1176 printk("%s: Couldn't get shared memory\n", dev->name);
1177 #ifdef ENABLE_APRICOT
1178 release_region(dev->base_addr, I596_TOTAL_SIZE);
1179 #endif
1180 return -ENOMEM;
1181 }
1182 dma_addr = virt_to_bus(dev->mem_start);
1183 }
1184
1185 ether_setup(dev);
1186 DEB(DEB_PROBE,printk("%s: 82596 at %#3lx,", dev->name, dev->base_addr));
1187
1188 for (i = 0; i < 6; i++)
1189 DEB(DEB_PROBE,printk(" %2.2X", dev->dev_addr[i] = eth_addr[i]));
1190
1191 DEB(DEB_PROBE,printk(" IRQ %d.\n", dev->irq));
1192
1193 DEB(DEB_PROBE,printk(version));
1194
1195 /* The 82596-specific entries in the device structure. */
1196 dev->open = i596_open;
1197 dev->stop = i596_close;
1198 dev->hard_start_xmit = i596_start_xmit;
1199 dev->get_stats = i596_get_stats;
1200 dev->set_multicast_list = set_multicast_list;
1201 dev->tx_timeout = i596_tx_timeout;
1202 dev->watchdog_timeo = TX_TIMEOUT;
1203
1204 dev->priv = (void *)(dev->mem_start);
1205
1206 lp = (struct i596_private *) dev->priv;
1207 DEB(DEB_INIT,printk ("%s: lp at 0x%08lx (%d bytes), lp->scb at 0x%08lx\n",
1208 dev->name, (unsigned long)lp,
1209 sizeof(struct i596_private), (unsigned long)&lp->scb));
1210 memset((void *) lp, 0, sizeof(struct i596_private));
1211
1212 #if 0
1213 kernel_set_cachemode((void *)(dev->mem_start), 4096, IOMAP_NOCACHE_SER);
1214 #endif
1215 lp->options = options;
1216 lp->scb.command = 0;
1217 lp->scb.cmd = I596_NULL;
1218 lp->scb.rfd = I596_NULL;
1219 lp->lock = SPIN_LOCK_UNLOCKED;
1220 lp->dma_addr = dma_addr;
1221
1222 CHECK_WBACK_INV(dev->mem_start, sizeof(struct i596_private));
1223
1224 return 0;
1225 }
1226
1227
1228 int __init lasi_i82596_probe(struct net_device *dev)
1229 {
1230 return i82596_probe(dev, 0);
1231 }
1232
1233
1234 int __init asp_i82596_probe(struct net_device *dev)
1235 {
1236 return i82596_probe(dev, OPT_SWAP_PORT);
1237 }
1238
1239
1240 static void i596_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1241 {
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("i596_interrupt(): irq %d for unknown device.\n", irq);
1248 return;
1249 }
1250
1251 lp = (struct i596_private *) 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;
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 != I596_NULL) {
1278 CHECK_INV(lp->cmd_head, sizeof(struct i596_cmd));
1279 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 pci_unmap_single(NULL, tx_cmd->dma_addr, skb->len, PCI_DMA_TODEVICE);
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 = ptr->b_next = I596_NULL;
1340 CHECK_WBACK(ptr, sizeof(struct i596_cmd));
1341 lp->last_cmd = jiffies;
1342 }
1343
1344 /* This mess is arranging that only the last of any outstanding
1345 * commands has the interrupt bit set. Should probably really
1346 * only add to the cmd queue when the CU is stopped.
1347 */
1348 ptr = lp->cmd_head;
1349 while ((ptr != I596_NULL) && (ptr != lp->cmd_tail)) {
1350 struct i596_cmd *prev = ptr;
1351
1352 ptr->command &= 0x1fff;
1353 ptr = ptr->v_next;
1354 CHECK_WBACK_INV(prev, sizeof(struct i596_cmd));
1355 }
1356
1357 if ((lp->cmd_head != I596_NULL))
1358 ack_cmd |= CUC_START;
1359 lp->scb.cmd = WSWAPcmd(virt_to_dma(lp,&lp->cmd_head->status));
1360 CHECK_WBACK_INV(&lp->scb, sizeof(struct i596_scb));
1361 }
1362 if ((status & 0x1000) || (status & 0x4000)) {
1363 if ((status & 0x4000))
1364 DEB(DEB_INTS,printk("%s: i596 interrupt received a frame.\n", dev->name));
1365 i596_rx(dev);
1366 /* Only RX_START if stopped - RGH 07-07-96 */
1367 if (status & 0x1000) {
1368 if (netif_running(dev)) {
1369 DEB(DEB_ERRORS,printk("%s: i596 interrupt receive unit inactive, status 0x%x\n", dev->name, status));
1370 ack_cmd |= RX_START;
1371 lp->stats.rx_errors++;
1372 lp->stats.rx_fifo_errors++;
1373 rebuild_rx_bufs(dev);
1374 }
1375 }
1376 }
1377 wait_cmd(dev,lp,100,"i596 interrupt, timeout");
1378 lp->scb.command = ack_cmd;
1379 CHECK_WBACK(&lp->scb, sizeof(struct i596_scb));
1380
1381 /* DANGER: I suspect that some kind of interrupt
1382 acknowledgement aside from acking the 82596 might be needed
1383 here... but it's running acceptably without */
1384
1385 CA(dev);
1386
1387 wait_cmd(dev,lp,100,"i596 interrupt, exit timeout");
1388 DEB(DEB_INTS,printk("%s: exiting interrupt.\n", dev->name));
1389
1390 spin_unlock (&lp->lock);
1391 return;
1392 }
1393
1394 static int i596_close(struct net_device *dev)
1395 {
1396 struct i596_private *lp = (struct i596_private *) dev->priv;
1397 unsigned long flags;
1398
1399 netif_stop_queue(dev);
1400
1401 DEB(DEB_INIT,printk("%s: Shutting down ethercard, status was %4.4x.\n",
1402 dev->name, lp->scb.status));
1403
1404 save_flags(flags);
1405 cli();
1406
1407 wait_cmd(dev,lp,100,"close1 timed out");
1408 lp->scb.command = CUC_ABORT | RX_ABORT;
1409 CHECK_WBACK(&lp->scb, sizeof(struct i596_scb));
1410
1411 CA(dev);
1412
1413 wait_cmd(dev,lp,100,"close2 timed out");
1414 restore_flags(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 release_region(dev->base_addr, 12);
1424
1425 MOD_DEC_USE_COUNT;
1426
1427 return 0;
1428 }
1429
1430 static struct net_device_stats *
1431 i596_get_stats(struct net_device *dev)
1432 {
1433 struct i596_private *lp = (struct i596_private *) dev->priv;
1434
1435 return &lp->stats;
1436 }
1437
1438 /*
1439 * Set or clear the multicast filter for this adaptor.
1440 */
1441
1442 static void set_multicast_list(struct net_device *dev)
1443 {
1444 struct i596_private *lp = (struct i596_private *) dev->priv;
1445 int config = 0, cnt;
1446
1447 DEB(DEB_MULTI,printk("%s: set multicast list, %d entries, promisc %s, allmulti %s\n", dev->name, dev->mc_count, dev->flags & IFF_PROMISC ? "ON" : "OFF", dev->flags & IFF_ALLMULTI ? "ON" : "OFF"));
1448
1449 if ((dev->flags & IFF_PROMISC) && !(lp->cf_cmd.i596_config[8] & 0x01)) {
1450 lp->cf_cmd.i596_config[8] |= 0x01;
1451 config = 1;
1452 }
1453 if (!(dev->flags & IFF_PROMISC) && (lp->cf_cmd.i596_config[8] & 0x01)) {
1454 lp->cf_cmd.i596_config[8] &= ~0x01;
1455 config = 1;
1456 }
1457 if ((dev->flags & IFF_ALLMULTI) && (lp->cf_cmd.i596_config[11] & 0x20)) {
1458 lp->cf_cmd.i596_config[11] &= ~0x20;
1459 config = 1;
1460 }
1461 if (!(dev->flags & IFF_ALLMULTI) && !(lp->cf_cmd.i596_config[11] & 0x20)) {
1462 lp->cf_cmd.i596_config[11] |= 0x20;
1463 config = 1;
1464 }
1465 if (config) {
1466 if (lp->cf_cmd.cmd.command)
1467 printk("%s: config change request already queued\n",
1468 dev->name);
1469 else {
1470 lp->cf_cmd.cmd.command = CmdConfigure;
1471 CHECK_WBACK_INV(&lp->cf_cmd, sizeof(struct cf_cmd));
1472 i596_add_cmd(dev, &lp->cf_cmd.cmd);
1473 }
1474 }
1475
1476 cnt = dev->mc_count;
1477 if (cnt > MAX_MC_CNT)
1478 {
1479 cnt = MAX_MC_CNT;
1480 printk("%s: Only %d multicast addresses supported",
1481 dev->name, cnt);
1482 }
1483
1484 if (dev->mc_count > 0) {
1485 struct dev_mc_list *dmi;
1486 unsigned char *cp;
1487 struct mc_cmd *cmd;
1488
1489 cmd = &lp->mc_cmd;
1490 cmd->cmd.command = CmdMulticastList;
1491 cmd->mc_cnt = dev->mc_count * 6;
1492 cp = cmd->mc_addrs;
1493 for (dmi = dev->mc_list; cnt && dmi != NULL; dmi = dmi->next, cnt--, cp += 6) {
1494 memcpy(cp, dmi->dmi_addr, 6);
1495 if (i596_debug > 1)
1496 DEB(DEB_MULTI,printk("%s: Adding address %02x:%02x:%02x:%02x:%02x:%02x\n",
1497 dev->name, cp[0],cp[1],cp[2],cp[3],cp[4],cp[5]));
1498 }
1499 CHECK_WBACK_INV(&lp->mc_cmd, sizeof(struct mc_cmd));
1500 i596_add_cmd(dev, &cmd->cmd);
1501 }
1502 }
1503
1504 #ifdef HAVE_DEVLIST
1505 static unsigned int i596_portlist[] __initdata =
1506 {0x300, 0};
1507 struct netdev_entry i596_drv =
1508 {"lasi_i82596", lasi_i82596_probe, I596_TOTAL_SIZE, i596_portlist};
1509 #endif
1510
1511 #ifdef MODULE
1512 static char devicename[9] =
1513 {0,};
1514 static struct net_device dev_82596 =
1515 {
1516 devicename, /* device name inserted by drivers/net/net_init.c */
1517 0, 0, 0, 0,
1518 0, 0, /* base, irq */
1519 0, 0, 0, NULL, lasi_i82596_probe};
1520
1521
1522 MODULE_PARM(debug, "i");
1523 static int debug = -1;
1524
1525 int init_module(void)
1526 {
1527 if (debug >= 0)
1528 i596_debug = debug;
1529 if (register_netdev(&dev_82596) != 0)
1530 return -EIO;
1531 return 0;
1532 }
1533
1534 void cleanup_module(void)
1535 {
1536 unregister_netdev(&dev_82596);
1537 lp = (struct i596_private *) dev_82596.priv;
1538
1539 if (dma_consistent)
1540 pci_free_consistent( NULL, sizeof( struct i596_private),
1541 dev_82596.mem_start, lp->dma_addr);
1542 else
1543 free_page ((u32)(dev_82596.mem_start));
1544
1545 dev_82596.priv = NULL;
1546 }
1547
1548 #endif /* MODULE */
1549
1550
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.