1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59#include <linux/module.h>
60#include <linux/init.h>
61#include <linux/delay.h>
62#include <linux/kernel.h>
63#include <linux/string.h>
64#include <linux/errno.h>
65#include <linux/ioport.h>
66#include <linux/slab.h>
67#include <linux/interrupt.h>
68#include <linux/netdevice.h>
69#include <linux/etherdevice.h>
70#include <linux/skbuff.h>
71#include <linux/bitops.h>
72
73#include <asm/io.h>
74#include <asm/dma.h>
75
76#define DRV_NAME "lp486e"
77
78
79#define LOG_SRCDST 0x80000000
80#define LOG_STATINT 0x40000000
81#define LOG_STARTINT 0x20000000
82
83#define i596_debug debug
84
85static int i596_debug = 0;
86
87static const char * const medianame[] = {
88 "10baseT", "AUI",
89 "10baseT-FD", "AUI-FD",
90};
91
92#define LP486E_TOTAL_SIZE 16
93
94#define I596_NULL (0xffffffff)
95
96#define CMD_EOL 0x8000
97#define CMD_SUSP 0x4000
98#define CMD_INTR 0x2000
99
100#define CMD_FLEX 0x0008
101
102enum commands {
103 CmdNOP = 0,
104 CmdIASetup = 1,
105 CmdConfigure = 2,
106 CmdMulticastList = 3,
107 CmdTx = 4,
108 CmdTDR = 5,
109 CmdDump = 6,
110 CmdDiagnose = 7
111};
112
113#if 0
114static const char *CUcmdnames[8] = { "NOP", "IASetup", "Configure", "MulticastList",
115 "Tx", "TDR", "Dump", "Diagnose" };
116#endif
117
118
119#define STAT_CX 0x8000
120
121#define STAT_FR 0x4000
122#define STAT_CNA 0x2000
123#define STAT_RNR 0x1000
124#define STAT_ACK (STAT_CX | STAT_FR | STAT_CNA | STAT_RNR)
125#define STAT_CUS 0x0700
126
127#define STAT_RUS 0x00f0
128
129
130
131#define STAT_T 0x0008
132#define STAT_ZERO 0x0807
133
134#if 0
135static char *CUstates[8] = {
136 "idle", "suspended", "active", 0, 0, 0, 0, 0
137};
138static char *RUstates[16] = {
139 "idle", "suspended", "no resources", 0, "ready", 0, 0, 0,
140 0, 0, "no RBDs", 0, "out of RBDs", 0, 0, 0
141};
142
143static void
144i596_out_status(int status) {
145 int bad = 0;
146 char *s;
147
148 printk("status %4.4x:", status);
149 if (status == 0xffff)
150 printk(" strange..\n");
151 else {
152 if (status & STAT_CX)
153 printk(" CU done");
154 if (status & STAT_CNA)
155 printk(" CU stopped");
156 if (status & STAT_FR)
157 printk(" got a frame");
158 if (status & STAT_RNR)
159 printk(" RU stopped");
160 if (status & STAT_T)
161 printk(" throttled");
162 if (status & STAT_ZERO)
163 bad = 1;
164 s = CUstates[(status & STAT_CUS) >> 8];
165 if (!s)
166 bad = 1;
167 else
168 printk(" CU(%s)", s);
169 s = RUstates[(status & STAT_RUS) >> 4];
170 if (!s)
171 bad = 1;
172 else
173 printk(" RU(%s)", s);
174 if (bad)
175 printk(" bad status");
176 printk("\n");
177 }
178}
179#endif
180
181
182#define ACK_CX 0x8000
183#define ACK_FR 0x4000
184#define ACK_CNA 0x2000
185#define ACK_RNR 0x1000
186
187#define CUC_START 0x0100
188#define CUC_RESUME 0x0200
189#define CUC_SUSPEND 0x0300
190#define CUC_ABORT 0x0400
191
192#define RX_START 0x0010
193#define RX_RESUME 0x0020
194#define RX_SUSPEND 0x0030
195#define RX_ABORT 0x0040
196
197typedef u32 phys_addr;
198
199static inline phys_addr
200va_to_pa(void *x) {
201 return x ? virt_to_bus(x) : I596_NULL;
202}
203
204static inline void *
205pa_to_va(phys_addr x) {
206 return (x == I596_NULL) ? NULL : bus_to_virt(x);
207}
208
209
210#define CMD_STAT_C 0x8000
211#define CMD_STAT_B 0x4000
212#define CMD_STAT_OK 0x2000
213#define CMD_STAT_A 0x1000
214
215struct i596_cmd {
216 unsigned short status;
217 unsigned short command;
218 phys_addr pa_next;
219};
220
221#define EOF 0x8000
222#define SIZE_MASK 0x3fff
223
224struct i596_tbd {
225 unsigned short size;
226 unsigned short pad;
227 phys_addr pa_next;
228 phys_addr pa_data;
229 struct sk_buff *skb;
230};
231
232struct tx_cmd {
233 struct i596_cmd cmd;
234 phys_addr pa_tbd;
235 unsigned short size;
236 unsigned short pad;
237};
238
239
240#define RFD_STAT_C 0x8000
241#define RFD_STAT_B 0x4000
242#define RFD_STAT_OK 0x2000
243#define RFD_STATUS 0x1fff
244#define RFD_LENGTH_ERR 0x1000
245#define RFD_CRC_ERR 0x0800
246#define RFD_ALIGN_ERR 0x0400
247#define RFD_NOBUFS_ERR 0x0200
248#define RFD_DMA_ERR 0x0100
249#define RFD_SHORT_FRAME_ERR 0x0080
250#define RFD_NOEOP_ERR 0x0040
251#define RFD_TRUNC_ERR 0x0020
252#define RFD_MULTICAST 0x0002
253
254#define RFD_COLLISION 0x0001
255
256
257struct i596_rfd {
258 unsigned short stat;
259 unsigned short cmd;
260 phys_addr pa_next;
261 phys_addr pa_rbd;
262 unsigned short count;
263 unsigned short size;
264 char data[1532];
265};
266
267#define RBD_EL 0x8000
268#define RBD_P 0x4000
269#define RBD_SIZEMASK 0x3fff
270#define RBD_EOF 0x8000
271#define RBD_F 0x4000
272
273
274struct i596_rbd {
275 unsigned short size;
276 unsigned short pad;
277 phys_addr pa_next;
278 phys_addr pa_data;
279 phys_addr pa_prev;
280
281
282 struct sk_buff *skb;
283};
284
285#define RX_RING_SIZE 64
286#define RX_SKBSIZE (ETH_FRAME_LEN+10)
287#define RX_RBD_SIZE 32
288
289
290struct i596_scb {
291 u16 status;
292 u16 command;
293 phys_addr pa_cmd;
294 phys_addr pa_rfd;
295 u32 crc_err;
296 u32 align_err;
297 u32 resource_err;
298 u32 over_err;
299 u32 rcvdt_err;
300 u32 short_err;
301 u16 t_on;
302 u16 t_off;
303};
304
305
306struct i596_iscp {
307 u32 busy;
308 phys_addr pa_scb;
309};
310
311
312struct i596_scp {
313 u32 sysbus;
314 u32 pad;
315 phys_addr pa_iscp;
316};
317
318
319
320
321
322
323
324
325struct i596_dump {
326 u16 dump[153];
327};
328
329struct i596_private {
330 struct i596_scp scp;
331 struct i596_iscp iscp;
332 struct i596_scb scb;
333 u32 dummy;
334 struct i596_dump dump;
335
336 struct i596_cmd set_add;
337 char eth_addr[8];
338
339 struct i596_cmd set_conf;
340 char i596_config[16];
341
342 struct i596_cmd tdr;
343 unsigned long tdr_stat;
344
345 int last_restart;
346 struct i596_rbd *rbd_list;
347 struct i596_rbd *rbd_tail;
348 struct i596_rfd *rx_tail;
349 struct i596_cmd *cmd_tail;
350 struct i596_cmd *cmd_head;
351 int cmd_backlog;
352 unsigned long last_cmd;
353 spinlock_t cmd_lock;
354};
355
356static char init_setup[14] = {
357 0x8E,
358 0xC8,
359 0x40,
360 0x2E,
361
362 0x00,
363 0x60,
364 0x00,
365 0xf2,
366 0x00,
367
368
369
370
371 0x00,
372 0x40,
373 0xff,
374
375 0x00,
376 0x7f
377};
378
379static int i596_open(struct net_device *dev);
380static netdev_tx_t i596_start_xmit(struct sk_buff *skb, struct net_device *dev);
381static irqreturn_t i596_interrupt(int irq, void *dev_id);
382static int i596_close(struct net_device *dev);
383static void i596_add_cmd(struct net_device *dev, struct i596_cmd *cmd);
384static void print_eth(char *);
385static void set_multicast_list(struct net_device *dev);
386static void i596_tx_timeout(struct net_device *dev);
387
388static int
389i596_timeout(struct net_device *dev, char *msg, int ct) {
390 struct i596_private *lp;
391 int boguscnt = ct;
392
393 lp = netdev_priv(dev);
394 while (lp->scb.command) {
395 if (--boguscnt == 0) {
396 printk("%s: %s timed out - stat %4.4x, cmd %4.4x\n",
397 dev->name, msg,
398 lp->scb.status, lp->scb.command);
399 return 1;
400 }
401 udelay(5);
402 barrier();
403 }
404 return 0;
405}
406
407static inline int
408init_rx_bufs(struct net_device *dev, int num) {
409 struct i596_private *lp;
410 struct i596_rfd *rfd;
411 int i;
412
413
414 lp = netdev_priv(dev);
415 lp->scb.pa_rfd = I596_NULL;
416
417 for (i = 0; i < num; i++) {
418 rfd = kmalloc(sizeof(struct i596_rfd), GFP_KERNEL);
419 if (rfd == NULL)
420 break;
421
422 rfd->stat = 0;
423 rfd->pa_rbd = I596_NULL;
424 rfd->count = 0;
425 rfd->size = 1532;
426 if (i == 0) {
427 rfd->cmd = CMD_EOL;
428 lp->rx_tail = rfd;
429 } else {
430 rfd->cmd = 0;
431 }
432 rfd->pa_next = lp->scb.pa_rfd;
433 lp->scb.pa_rfd = va_to_pa(rfd);
434 lp->rx_tail->pa_next = lp->scb.pa_rfd;
435 }
436
437#if 0
438 for (i = 0; i<RX_RBD_SIZE; i++) {
439 rbd = kmalloc(sizeof(struct i596_rbd), GFP_KERNEL);
440 if (rbd) {
441 rbd->pad = 0;
442 rbd->count = 0;
443 rbd->skb = dev_alloc_skb(RX_SKBSIZE);
444 if (!rbd->skb) {
445 printk("dev_alloc_skb failed");
446 }
447 rbd->next = rfd->rbd;
448 if (i) {
449 rfd->rbd->prev = rbd;
450 rbd->size = RX_SKBSIZE;
451 } else {
452 rbd->size = (RX_SKBSIZE | RBD_EL);
453 lp->rbd_tail = rbd;
454 }
455
456 rfd->rbd = rbd;
457 } else {
458 printk("Could not kmalloc rbd\n");
459 }
460 }
461 lp->rbd_tail->next = rfd->rbd;
462#endif
463 return i;
464}
465
466static inline void
467remove_rx_bufs(struct net_device *dev) {
468 struct i596_private *lp;
469 struct i596_rfd *rfd;
470
471 lp = netdev_priv(dev);
472 lp->rx_tail->pa_next = I596_NULL;
473
474 do {
475 rfd = pa_to_va(lp->scb.pa_rfd);
476 lp->scb.pa_rfd = rfd->pa_next;
477 kfree(rfd);
478 } while (rfd != lp->rx_tail);
479
480 lp->rx_tail = NULL;
481
482#if 0
483 for (lp->rbd_list) {
484 }
485#endif
486}
487
488#define PORT_RESET 0x00
489#define PORT_SELFTEST 0x01
490#define PORT_ALTSCP 0x02
491#define PORT_DUMP 0x03
492
493#define IOADDR 0xcb0
494#define IRQ 10
495
496
497static inline void
498PORT(phys_addr a, unsigned int cmd) {
499 if (a & 0xf)
500 printk("lp486e.c: PORT: address not aligned\n");
501 outw(((a & 0xffff) | cmd), IOADDR);
502 outw(((a>>16) & 0xffff), IOADDR+2);
503}
504
505static inline void
506CA(void) {
507 outb(0, IOADDR+4);
508 udelay(8);
509}
510
511static inline void
512CLEAR_INT(void) {
513 outb(0, IOADDR+8);
514}
515
516#if 0
517
518static void
519i596_port_do(struct net_device *dev, int portcmd, char *cmdname) {
520 struct i596_private *lp = netdev_priv(dev);
521 u16 *outp;
522 int i, m;
523
524 memset((void *)&(lp->dump), 0, sizeof(struct i596_dump));
525 outp = &(lp->dump.dump[0]);
526
527 PORT(va_to_pa(outp), portcmd);
528 mdelay(30);
529
530 printk("lp486e i82596 %s result:\n", cmdname);
531 for (m = ARRAY_SIZE(lp->dump.dump); m && lp->dump.dump[m-1] == 0; m--)
532 ;
533 for (i = 0; i < m; i++) {
534 printk(" %04x", lp->dump.dump[i]);
535 if (i%8 == 7)
536 printk("\n");
537 }
538 printk("\n");
539}
540#endif
541
542static int
543i596_scp_setup(struct net_device *dev) {
544 struct i596_private *lp = netdev_priv(dev);
545 int boguscnt;
546
547
548
549
550
551
552
553
554
555
556
557
558
559 lp->scp.sysbus = 0x00440000;
560 lp->scp.pad = 0;
561 lp->scp.pa_iscp = va_to_pa(&(lp->iscp));
562
563
564
565
566 lp->iscp.busy = 0x0001;
567 lp->iscp.pa_scb = va_to_pa(&(lp->scb));
568
569 lp->scb.command = 0;
570 lp->scb.status = 0;
571 lp->scb.pa_cmd = I596_NULL;
572
573
574 lp->last_cmd = jiffies;
575 lp->cmd_backlog = 0;
576 lp->cmd_head = NULL;
577
578
579
580
581
582
583 PORT(0, PORT_RESET);
584 udelay(100);
585
586
587
588
589
590 PORT(va_to_pa(&lp->scp), PORT_ALTSCP);
591
592
593
594
595
596
597 CA();
598
599
600
601
602 boguscnt = 100;
603 while (lp->iscp.busy) {
604 if (--boguscnt == 0) {
605
606 printk("%s: i82596 initialization timed out\n",
607 dev->name);
608 return 1;
609 }
610 udelay(5);
611 barrier();
612 }
613
614
615 return 0;
616}
617
618static int
619init_i596(struct net_device *dev) {
620 struct i596_private *lp;
621
622 if (i596_scp_setup(dev))
623 return 1;
624
625 lp = netdev_priv(dev);
626 lp->scb.command = 0;
627
628 memcpy ((void *)lp->i596_config, init_setup, 14);
629 lp->set_conf.command = CmdConfigure;
630 i596_add_cmd(dev, (void *)&lp->set_conf);
631
632 memcpy ((void *)lp->eth_addr, dev->dev_addr, 6);
633 lp->set_add.command = CmdIASetup;
634 i596_add_cmd(dev, (struct i596_cmd *)&lp->set_add);
635
636 lp->tdr.command = CmdTDR;
637 i596_add_cmd(dev, (struct i596_cmd *)&lp->tdr);
638
639 if (lp->scb.command && i596_timeout(dev, "i82596 init", 200))
640 return 1;
641
642 lp->scb.command = RX_START;
643 CA();
644
645 barrier();
646
647 if (lp->scb.command && i596_timeout(dev, "Receive Unit start", 100))
648 return 1;
649
650 return 0;
651}
652
653
654static inline int
655i596_rx_one(struct net_device *dev, struct i596_private *lp,
656 struct i596_rfd *rfd, int *frames) {
657
658 if (rfd->stat & RFD_STAT_OK) {
659
660 int pkt_len = (rfd->count & 0x3fff);
661 struct sk_buff *skb = dev_alloc_skb(pkt_len);
662
663 (*frames)++;
664
665 if (rfd->cmd & CMD_EOL)
666 printk("Received on EOL\n");
667
668 if (skb == NULL) {
669 printk ("%s: i596_rx Memory squeeze, "
670 "dropping packet.\n", dev->name);
671 dev->stats.rx_dropped++;
672 return 1;
673 }
674
675 memcpy(skb_put(skb,pkt_len), rfd->data, pkt_len);
676
677 skb->protocol = eth_type_trans(skb,dev);
678 netif_rx(skb);
679 dev->stats.rx_packets++;
680 } else {
681#if 0
682 printk("Frame reception error status %04x\n",
683 rfd->stat);
684#endif
685 dev->stats.rx_errors++;
686 if (rfd->stat & RFD_COLLISION)
687 dev->stats.collisions++;
688 if (rfd->stat & RFD_SHORT_FRAME_ERR)
689 dev->stats.rx_length_errors++;
690 if (rfd->stat & RFD_DMA_ERR)
691 dev->stats.rx_over_errors++;
692 if (rfd->stat & RFD_NOBUFS_ERR)
693 dev->stats.rx_fifo_errors++;
694 if (rfd->stat & RFD_ALIGN_ERR)
695 dev->stats.rx_frame_errors++;
696 if (rfd->stat & RFD_CRC_ERR)
697 dev->stats.rx_crc_errors++;
698 if (rfd->stat & RFD_LENGTH_ERR)
699 dev->stats.rx_length_errors++;
700 }
701 rfd->stat = rfd->count = 0;
702 return 0;
703}
704
705static int
706i596_rx(struct net_device *dev) {
707 struct i596_private *lp = netdev_priv(dev);
708 struct i596_rfd *rfd;
709 int frames = 0;
710
711 while (1) {
712 rfd = pa_to_va(lp->scb.pa_rfd);
713 if (!rfd) {
714 printk(KERN_ERR "i596_rx: NULL rfd?\n");
715 return 0;
716 }
717#if 1
718 if (rfd->stat && !(rfd->stat & (RFD_STAT_C | RFD_STAT_B)))
719 printk("SF:%p-%04x\n", rfd, rfd->stat);
720#endif
721 if (!(rfd->stat & RFD_STAT_C))
722 break;
723 if (i596_rx_one(dev, lp, rfd, &frames))
724 break;
725 rfd->cmd = CMD_EOL;
726 lp->rx_tail->cmd = 0;
727 lp->rx_tail = rfd;
728 lp->scb.pa_rfd = rfd->pa_next;
729 barrier();
730 }
731
732 return frames;
733}
734
735static void
736i596_cleanup_cmd(struct net_device *dev) {
737 struct i596_private *lp;
738 struct i596_cmd *cmd;
739
740 lp = netdev_priv(dev);
741 while (lp->cmd_head) {
742 cmd = (struct i596_cmd *)lp->cmd_head;
743
744 lp->cmd_head = pa_to_va(lp->cmd_head->pa_next);
745 lp->cmd_backlog--;
746
747 switch ((cmd->command) & 0x7) {
748 case CmdTx: {
749 struct tx_cmd *tx_cmd = (struct tx_cmd *) cmd;
750 struct i596_tbd * tx_cmd_tbd;
751 tx_cmd_tbd = pa_to_va(tx_cmd->pa_tbd);
752
753 dev_kfree_skb_any(tx_cmd_tbd->skb);
754
755 dev->stats.tx_errors++;
756 dev->stats.tx_aborted_errors++;
757
758 cmd->pa_next = I596_NULL;
759 kfree((unsigned char *)tx_cmd);
760 netif_wake_queue(dev);
761 break;
762 }
763 case CmdMulticastList: {
764
765
766 cmd->pa_next = I596_NULL;
767 kfree((unsigned char *)cmd);
768 break;
769 }
770 default: {
771 cmd->pa_next = I596_NULL;
772 break;
773 }
774 }
775 barrier();
776 }
777
778 if (lp->scb.command && i596_timeout(dev, "i596_cleanup_cmd", 100))
779 ;
780
781 lp->scb.pa_cmd = va_to_pa(lp->cmd_head);
782}
783
784static void i596_reset(struct net_device *dev, struct i596_private *lp, int ioaddr) {
785
786 if (lp->scb.command && i596_timeout(dev, "i596_reset", 100))
787 ;
788
789 netif_stop_queue(dev);
790
791 lp->scb.command = CUC_ABORT | RX_ABORT;
792 CA();
793 barrier();
794
795
796 if (lp->scb.command && i596_timeout(dev, "i596_reset(2)", 400))
797 ;
798
799 i596_cleanup_cmd(dev);
800 i596_rx(dev);
801
802 netif_start_queue(dev);
803
804 init_i596(dev);
805}
806
807static void i596_add_cmd(struct net_device *dev, struct i596_cmd *cmd) {
808 struct i596_private *lp = netdev_priv(dev);
809 int ioaddr = dev->base_addr;
810 unsigned long flags;
811
812 cmd->status = 0;
813 cmd->command |= (CMD_EOL | CMD_INTR);
814 cmd->pa_next = I596_NULL;
815
816 spin_lock_irqsave(&lp->cmd_lock, flags);
817
818 if (lp->cmd_head) {
819 lp->cmd_tail->pa_next = va_to_pa(cmd);
820 } else {
821 lp->cmd_head = cmd;
822 if (lp->scb.command && i596_timeout(dev, "i596_add_cmd", 100))
823 ;
824 lp->scb.pa_cmd = va_to_pa(cmd);
825 lp->scb.command = CUC_START;
826 CA();
827 }
828 lp->cmd_tail = cmd;
829 lp->cmd_backlog++;
830
831 lp->cmd_head = pa_to_va(lp->scb.pa_cmd);
832 spin_unlock_irqrestore(&lp->cmd_lock, flags);
833
834 if (lp->cmd_backlog > 16) {
835 int tickssofar = jiffies - lp->last_cmd;
836 if (tickssofar < HZ/4)
837 return;
838
839 printk(KERN_WARNING "%s: command unit timed out, status resetting.\n", dev->name);
840 i596_reset(dev, lp, ioaddr);
841 }
842}
843
844static int i596_open(struct net_device *dev)
845{
846 int i;
847
848 i = request_irq(dev->irq, i596_interrupt, IRQF_SHARED, dev->name, dev);
849 if (i) {
850 printk(KERN_ERR "%s: IRQ %d not free\n", dev->name, dev->irq);
851 return i;
852 }
853
854 if ((i = init_rx_bufs(dev, RX_RING_SIZE)) < RX_RING_SIZE)
855 printk(KERN_ERR "%s: only able to allocate %d receive buffers\n", dev->name, i);
856
857 if (i < 4) {
858 free_irq(dev->irq, dev);
859 return -EAGAIN;
860 }
861 netif_start_queue(dev);
862 init_i596(dev);
863 return 0;
864}
865
866static netdev_tx_t i596_start_xmit (struct sk_buff *skb, struct net_device *dev) {
867 struct tx_cmd *tx_cmd;
868 short length;
869
870 length = skb->len;
871
872 if (length < ETH_ZLEN) {
873 if (skb_padto(skb, ETH_ZLEN))
874 return NETDEV_TX_OK;
875 length = ETH_ZLEN;
876 }
877
878 tx_cmd = kmalloc((sizeof (struct tx_cmd) + sizeof (struct i596_tbd)), GFP_ATOMIC);
879 if (tx_cmd == NULL) {
880 printk(KERN_WARNING "%s: i596_xmit Memory squeeze, dropping packet.\n", dev->name);
881 dev->stats.tx_dropped++;
882 dev_kfree_skb (skb);
883 } else {
884 struct i596_tbd *tx_cmd_tbd;
885 tx_cmd_tbd = (struct i596_tbd *) (tx_cmd + 1);
886 tx_cmd->pa_tbd = va_to_pa (tx_cmd_tbd);
887 tx_cmd_tbd->pa_next = I596_NULL;
888
889 tx_cmd->cmd.command = (CMD_FLEX | CmdTx);
890
891 tx_cmd->pad = 0;
892 tx_cmd->size = 0;
893 tx_cmd_tbd->pad = 0;
894 tx_cmd_tbd->size = (EOF | length);
895
896 tx_cmd_tbd->pa_data = va_to_pa (skb->data);
897 tx_cmd_tbd->skb = skb;
898
899 if (i596_debug & LOG_SRCDST)
900 print_eth (skb->data);
901
902 i596_add_cmd (dev, (struct i596_cmd *) tx_cmd);
903
904 dev->stats.tx_packets++;
905 }
906
907 return NETDEV_TX_OK;
908}
909
910static void
911i596_tx_timeout (struct net_device *dev) {
912 struct i596_private *lp = netdev_priv(dev);
913 int ioaddr = dev->base_addr;
914
915
916 printk(KERN_WARNING "%s: transmit timed out, status resetting.\n", dev->name);
917 dev->stats.tx_errors++;
918
919
920 if (lp->last_restart == dev->stats.tx_packets) {
921 printk ("Resetting board.\n");
922
923
924 i596_reset (dev, lp, ioaddr);
925 } else {
926
927 printk ("Kicking board.\n");
928 lp->scb.command = (CUC_START | RX_START);
929 CA();
930 lp->last_restart = dev->stats.tx_packets;
931 }
932 netif_wake_queue(dev);
933}
934
935static void print_eth(char *add)
936{
937 int i;
938
939 printk ("Dest ");
940 for (i = 0; i < 6; i++)
941 printk(" %2.2X", (unsigned char) add[i]);
942 printk ("\n");
943
944 printk ("Source");
945 for (i = 0; i < 6; i++)
946 printk(" %2.2X", (unsigned char) add[i+6]);
947 printk ("\n");
948
949 printk ("type %2.2X%2.2X\n",
950 (unsigned char) add[12], (unsigned char) add[13]);
951}
952
953static const struct net_device_ops i596_netdev_ops = {
954 .ndo_open = i596_open,
955 .ndo_stop = i596_close,
956 .ndo_start_xmit = i596_start_xmit,
957 .ndo_set_multicast_list = set_multicast_list,
958 .ndo_tx_timeout = i596_tx_timeout,
959 .ndo_change_mtu = eth_change_mtu,
960 .ndo_set_mac_address = eth_mac_addr,
961 .ndo_validate_addr = eth_validate_addr,
962};
963
964static int __init lp486e_probe(struct net_device *dev) {
965 struct i596_private *lp;
966 unsigned char eth_addr[6] = { 0, 0xaa, 0, 0, 0, 0 };
967 unsigned char *bios;
968 int i, j;
969 int ret = -ENOMEM;
970 static int probed;
971
972 if (probed)
973 return -ENODEV;
974 probed++;
975
976 if (!request_region(IOADDR, LP486E_TOTAL_SIZE, DRV_NAME)) {
977 printk(KERN_ERR "lp486e: IO address 0x%x in use\n", IOADDR);
978 return -EBUSY;
979 }
980
981 lp = netdev_priv(dev);
982 spin_lock_init(&lp->cmd_lock);
983
984
985
986
987 if (i596_scp_setup(dev)) {
988 ret = -ENODEV;
989 goto err_out_kfree;
990 }
991
992 dev->base_addr = IOADDR;
993 dev->irq = IRQ;
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006 bios = bus_to_virt(0xe8000);
1007 for (j = 0; j < 0x2000; j++) {
1008 if (bios[j] == 0 && bios[j+1] == 0xaa && bios[j+2] == 0) {
1009 printk("%s: maybe address at BIOS 0x%x:",
1010 dev->name, 0xe8000+j);
1011 for (i = 0; i < 6; i++) {
1012 eth_addr[i] = bios[i+j];
1013 printk(" %2.2X", eth_addr[i]);
1014 }
1015 printk("\n");
1016 }
1017 }
1018
1019 printk("%s: lp486e 82596 at %#3lx, IRQ %d,",
1020 dev->name, dev->base_addr, dev->irq);
1021 for (i = 0; i < 6; i++)
1022 printk(" %2.2X", dev->dev_addr[i] = eth_addr[i]);
1023 printk("\n");
1024
1025
1026 dev->netdev_ops = &i596_netdev_ops;
1027 dev->watchdog_timeo = 5*HZ;
1028
1029#if 0
1030
1031 i596_port_do(dev, PORT_SELFTEST, "selftest");
1032 i596_port_do(dev, PORT_DUMP, "dump");
1033#endif
1034 return 0;
1035
1036err_out_kfree:
1037 release_region(IOADDR, LP486E_TOTAL_SIZE);
1038 return ret;
1039}
1040
1041static inline void
1042i596_handle_CU_completion(struct net_device *dev,
1043 struct i596_private *lp,
1044 unsigned short status,
1045 unsigned short *ack_cmdp) {
1046 struct i596_cmd *cmd;
1047 int frames_out = 0;
1048 int commands_done = 0;
1049 int cmd_val;
1050 unsigned long flags;
1051
1052 spin_lock_irqsave(&lp->cmd_lock, flags);
1053 cmd = lp->cmd_head;
1054
1055 while (lp->cmd_head && (lp->cmd_head->status & CMD_STAT_C)) {
1056 cmd = lp->cmd_head;
1057
1058 lp->cmd_head = pa_to_va(lp->cmd_head->pa_next);
1059 lp->cmd_backlog--;
1060
1061 commands_done++;
1062 cmd_val = cmd->command & 0x7;
1063#if 0
1064 printk("finished CU %s command (%d)\n",
1065 CUcmdnames[cmd_val], cmd_val);
1066#endif
1067 switch (cmd_val) {
1068 case CmdTx:
1069 {
1070 struct tx_cmd *tx_cmd;
1071 struct i596_tbd *tx_cmd_tbd;
1072
1073 tx_cmd = (struct tx_cmd *) cmd;
1074 tx_cmd_tbd = pa_to_va(tx_cmd->pa_tbd);
1075
1076 frames_out++;
1077 if (cmd->status & CMD_STAT_OK) {
1078 if (i596_debug)
1079 print_eth(pa_to_va(tx_cmd_tbd->pa_data));
1080 } else {
1081 dev->stats.tx_errors++;
1082 if (i596_debug)
1083 printk("transmission failure:%04x\n",
1084 cmd->status);
1085 if (cmd->status & 0x0020)
1086 dev->stats.collisions++;
1087 if (!(cmd->status & 0x0040))
1088 dev->stats.tx_heartbeat_errors++;
1089 if (cmd->status & 0x0400)
1090 dev->stats.tx_carrier_errors++;
1091 if (cmd->status & 0x0800)
1092 dev->stats.collisions++;
1093 if (cmd->status & 0x1000)
1094 dev->stats.tx_aborted_errors++;
1095 }
1096 dev_kfree_skb_irq(tx_cmd_tbd->skb);
1097
1098 cmd->pa_next = I596_NULL;
1099 kfree((unsigned char *)tx_cmd);
1100 netif_wake_queue(dev);
1101 break;
1102 }
1103
1104 case CmdMulticastList:
1105 cmd->pa_next = I596_NULL;
1106 kfree((unsigned char *)cmd);
1107 break;
1108
1109 case CmdTDR:
1110 {
1111 unsigned long status = *((unsigned long *) (cmd + 1));
1112 if (status & 0x8000) {
1113 if (i596_debug)
1114 printk("%s: link ok.\n", dev->name);
1115 } else {
1116 if (status & 0x4000)
1117 printk("%s: Transceiver problem.\n",
1118 dev->name);
1119 if (status & 0x2000)
1120 printk("%s: Termination problem.\n",
1121 dev->name);
1122 if (status & 0x1000)
1123 printk("%s: Short circuit.\n",
1124 dev->name);
1125 printk("%s: Time %ld.\n",
1126 dev->name, status & 0x07ff);
1127 }
1128 }
1129 default:
1130 cmd->pa_next = I596_NULL;
1131 lp->last_cmd = jiffies;
1132
1133 }
1134 barrier();
1135 }
1136
1137 cmd = lp->cmd_head;
1138 while (cmd && (cmd != lp->cmd_tail)) {
1139 cmd->command &= 0x1fff;
1140 cmd = pa_to_va(cmd->pa_next);
1141 barrier();
1142 }
1143
1144 if (lp->cmd_head)
1145 *ack_cmdp |= CUC_START;
1146 lp->scb.pa_cmd = va_to_pa(lp->cmd_head);
1147 spin_unlock_irqrestore(&lp->cmd_lock, flags);
1148}
1149
1150static irqreturn_t
1151i596_interrupt(int irq, void *dev_instance)
1152{
1153 struct net_device *dev = dev_instance;
1154 struct i596_private *lp = netdev_priv(dev);
1155 unsigned short status, ack_cmd = 0;
1156 int frames_in = 0;
1157
1158
1159
1160
1161
1162 if (lp->scb.command && i596_timeout(dev, "interrupt", 40))
1163 ;
1164
1165
1166
1167
1168
1169
1170
1171
1172 status = lp->scb.status;
1173#if 0
1174 if (i596_debug) {
1175 printk("%s: i596 interrupt, ", dev->name);
1176 i596_out_status(status);
1177 }
1178#endif
1179
1180
1181 if (status == 0xffff) {
1182 printk("%s: i596_interrupt: got status 0xffff\n", dev->name);
1183 goto out;
1184 }
1185
1186 ack_cmd = (status & STAT_ACK);
1187
1188 if (status & (STAT_CX | STAT_CNA))
1189 i596_handle_CU_completion(dev, lp, status, &ack_cmd);
1190
1191 if (status & (STAT_FR | STAT_RNR)) {
1192
1193 if ((status & STAT_RNR) && netif_running(dev))
1194 ack_cmd |= RX_START;
1195
1196 if (status & STAT_FR) {
1197 frames_in = i596_rx(dev);
1198 if (!frames_in)
1199 printk("receive frame reported, but no frames\n");
1200 }
1201 }
1202
1203
1204
1205
1206
1207
1208
1209 if (lp->scb.command && i596_timeout(dev, "i596 interrupt", 100))
1210 ;
1211
1212 lp->scb.command = ack_cmd;
1213
1214 CLEAR_INT();
1215 CA();
1216
1217 out:
1218 return IRQ_HANDLED;
1219}
1220
1221static int i596_close(struct net_device *dev) {
1222 struct i596_private *lp = netdev_priv(dev);
1223
1224 netif_stop_queue(dev);
1225
1226 if (i596_debug)
1227 printk("%s: Shutting down ethercard, status was %4.4x.\n",
1228 dev->name, lp->scb.status);
1229
1230 lp->scb.command = (CUC_ABORT | RX_ABORT);
1231 CA();
1232
1233 i596_cleanup_cmd(dev);
1234
1235 if (lp->scb.command && i596_timeout(dev, "i596_close", 200))
1236 ;
1237
1238 free_irq(dev->irq, dev);
1239 remove_rx_bufs(dev);
1240
1241 return 0;
1242}
1243
1244
1245
1246
1247
1248static void set_multicast_list(struct net_device *dev) {
1249 struct i596_private *lp = netdev_priv(dev);
1250 struct i596_cmd *cmd;
1251
1252 if (i596_debug > 1)
1253 printk ("%s: set multicast list %d\n",
1254 dev->name, netdev_mc_count(dev));
1255
1256 if (!netdev_mc_empty(dev)) {
1257 struct netdev_hw_addr *ha;
1258 char *cp;
1259 cmd = kmalloc(sizeof(struct i596_cmd) + 2 +
1260 netdev_mc_count(dev) * 6, GFP_ATOMIC);
1261 if (cmd == NULL) {
1262 printk (KERN_ERR "%s: set_multicast Memory squeeze.\n", dev->name);
1263 return;
1264 }
1265 cmd->command = CmdMulticastList;
1266 *((unsigned short *) (cmd + 1)) = netdev_mc_count(dev) * 6;
1267 cp = ((char *)(cmd + 1))+2;
1268 netdev_for_each_mc_addr(ha, dev) {
1269 memcpy(cp, ha->addr, 6);
1270 cp += 6;
1271 }
1272 if (i596_debug & LOG_SRCDST)
1273 print_eth (((char *)(cmd + 1)) + 2);
1274 i596_add_cmd(dev, cmd);
1275 } else {
1276 if (lp->set_conf.pa_next != I596_NULL) {
1277 return;
1278 }
1279 if (netdev_mc_empty(dev) &&
1280 !(dev->flags & (IFF_PROMISC | IFF_ALLMULTI))) {
1281 lp->i596_config[8] &= ~0x01;
1282 } else {
1283 lp->i596_config[8] |= 0x01;
1284 }
1285
1286 i596_add_cmd(dev, (struct i596_cmd *) &lp->set_conf);
1287 }
1288}
1289
1290MODULE_AUTHOR("Ard van Breemen <ard@cstmel.nl.eu.org>");
1291MODULE_DESCRIPTION("Intel Panther onboard i82596 driver");
1292MODULE_LICENSE("GPL");
1293
1294static struct net_device *dev_lp486e;
1295static int full_duplex;
1296static int options;
1297static int io = IOADDR;
1298static int irq = IRQ;
1299
1300module_param(debug, int, 0);
1301
1302
1303
1304module_param(options, int, 0);
1305module_param(full_duplex, int, 0);
1306
1307static int __init lp486e_init_module(void) {
1308 int err;
1309 struct net_device *dev = alloc_etherdev(sizeof(struct i596_private));
1310 if (!dev)
1311 return -ENOMEM;
1312
1313 dev->irq = irq;
1314 dev->base_addr = io;
1315 err = lp486e_probe(dev);
1316 if (err) {
1317 free_netdev(dev);
1318 return err;
1319 }
1320 err = register_netdev(dev);
1321 if (err) {
1322 release_region(dev->base_addr, LP486E_TOTAL_SIZE);
1323 free_netdev(dev);
1324 return err;
1325 }
1326 dev_lp486e = dev;
1327 full_duplex = 0;
1328 options = 0;
1329 return 0;
1330}
1331
1332static void __exit lp486e_cleanup_module(void) {
1333 unregister_netdev(dev_lp486e);
1334 release_region(dev_lp486e->base_addr, LP486E_TOTAL_SIZE);
1335 free_netdev(dev_lp486e);
1336}
1337
1338module_init(lp486e_init_module);
1339module_exit(lp486e_cleanup_module);
1340