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#include <linux/kernel.h>
38#include <linux/module.h>
39#include <linux/string.h>
40#include <linux/timer.h>
41#include <linux/ptrace.h>
42#include <linux/errno.h>
43#include <linux/ioport.h>
44#include <linux/slab.h>
45#include <linux/interrupt.h>
46#include <linux/pci.h>
47#include <linux/delay.h>
48#include <linux/hdlc.h>
49#include <linux/in.h>
50#include <linux/if_arp.h>
51#include <linux/netdevice.h>
52#include <linux/etherdevice.h>
53#include <linux/skbuff.h>
54#include <linux/inet.h>
55#include <linux/bitops.h>
56#include <asm/processor.h>
57#include <asm/io.h>
58#include <asm/dma.h>
59#include <linux/uaccess.h>
60#include <linux/jiffies.h>
61
62
63#define DRIVER_MAJOR_VERSION 1
64#define DRIVER_MINOR_VERSION 34
65#define DRIVER_SUB_VERSION 0
66
67#define DRIVER_VERSION ((DRIVER_MAJOR_VERSION << 8) + DRIVER_MINOR_VERSION)
68
69#include "lmc.h"
70#include "lmc_var.h"
71#include "lmc_ioctl.h"
72#include "lmc_debug.h"
73#include "lmc_proto.h"
74
75static int LMC_PKT_BUF_SZ = 1542;
76
77static const struct pci_device_id lmc_pci_tbl[] = {
78 { PCI_VENDOR_ID_DEC, PCI_DEVICE_ID_DEC_TULIP_FAST,
79 PCI_VENDOR_ID_LMC, PCI_ANY_ID },
80 { PCI_VENDOR_ID_DEC, PCI_DEVICE_ID_DEC_TULIP_FAST,
81 PCI_ANY_ID, PCI_VENDOR_ID_LMC },
82 { 0 }
83};
84
85MODULE_DEVICE_TABLE(pci, lmc_pci_tbl);
86MODULE_LICENSE("GPL v2");
87
88
89static netdev_tx_t lmc_start_xmit(struct sk_buff *skb,
90 struct net_device *dev);
91static int lmc_rx (struct net_device *dev);
92static int lmc_open(struct net_device *dev);
93static int lmc_close(struct net_device *dev);
94static struct net_device_stats *lmc_get_stats(struct net_device *dev);
95static irqreturn_t lmc_interrupt(int irq, void *dev_instance);
96static void lmc_initcsrs(lmc_softc_t * const sc, lmc_csrptr_t csr_base, size_t csr_size);
97static void lmc_softreset(lmc_softc_t * const);
98static void lmc_running_reset(struct net_device *dev);
99static int lmc_ifdown(struct net_device * const);
100static void lmc_watchdog(struct timer_list *t);
101static void lmc_reset(lmc_softc_t * const sc);
102static void lmc_dec_reset(lmc_softc_t * const sc);
103static void lmc_driver_timeout(struct net_device *dev, unsigned int txqueue);
104
105
106
107
108
109static int lmc_siocdevprivate(struct net_device *dev, struct ifreq *ifr,
110 void __user *data, int cmd)
111{
112 lmc_softc_t *sc = dev_to_sc(dev);
113 lmc_ctl_t ctl;
114 int ret = -EOPNOTSUPP;
115 u16 regVal;
116 unsigned long flags;
117
118
119
120
121
122
123 switch (cmd) {
124
125
126
127
128 case LMCIOCGINFO:
129 if (copy_to_user(data, &sc->ictl, sizeof(lmc_ctl_t)))
130 ret = -EFAULT;
131 else
132 ret = 0;
133 break;
134
135 case LMCIOCSINFO:
136 if (!capable(CAP_NET_ADMIN)) {
137 ret = -EPERM;
138 break;
139 }
140
141 if(dev->flags & IFF_UP){
142 ret = -EBUSY;
143 break;
144 }
145
146 if (copy_from_user(&ctl, data, sizeof(lmc_ctl_t))) {
147 ret = -EFAULT;
148 break;
149 }
150
151 spin_lock_irqsave(&sc->lmc_lock, flags);
152 sc->lmc_media->set_status (sc, &ctl);
153
154 if(ctl.crc_length != sc->ictl.crc_length) {
155 sc->lmc_media->set_crc_length(sc, ctl.crc_length);
156 if (sc->ictl.crc_length == LMC_CTL_CRC_LENGTH_16)
157 sc->TxDescriptControlInit |= LMC_TDES_ADD_CRC_DISABLE;
158 else
159 sc->TxDescriptControlInit &= ~LMC_TDES_ADD_CRC_DISABLE;
160 }
161 spin_unlock_irqrestore(&sc->lmc_lock, flags);
162
163 ret = 0;
164 break;
165
166 case LMCIOCIFTYPE:
167 {
168 u16 old_type = sc->if_type;
169 u16 new_type;
170
171 if (!capable(CAP_NET_ADMIN)) {
172 ret = -EPERM;
173 break;
174 }
175
176 if (copy_from_user(&new_type, data, sizeof(u16))) {
177 ret = -EFAULT;
178 break;
179 }
180
181
182 if (new_type == old_type)
183 {
184 ret = 0 ;
185 break;
186 }
187
188 spin_lock_irqsave(&sc->lmc_lock, flags);
189 lmc_proto_close(sc);
190
191 sc->if_type = new_type;
192 lmc_proto_attach(sc);
193 ret = lmc_proto_open(sc);
194 spin_unlock_irqrestore(&sc->lmc_lock, flags);
195 break;
196 }
197
198 case LMCIOCGETXINFO:
199 spin_lock_irqsave(&sc->lmc_lock, flags);
200 sc->lmc_xinfo.Magic0 = 0xBEEFCAFE;
201
202 sc->lmc_xinfo.PciCardType = sc->lmc_cardtype;
203 sc->lmc_xinfo.PciSlotNumber = 0;
204 sc->lmc_xinfo.DriverMajorVersion = DRIVER_MAJOR_VERSION;
205 sc->lmc_xinfo.DriverMinorVersion = DRIVER_MINOR_VERSION;
206 sc->lmc_xinfo.DriverSubVersion = DRIVER_SUB_VERSION;
207 sc->lmc_xinfo.XilinxRevisionNumber =
208 lmc_mii_readreg (sc, 0, 3) & 0xf;
209 sc->lmc_xinfo.MaxFrameSize = LMC_PKT_BUF_SZ;
210 sc->lmc_xinfo.link_status = sc->lmc_media->get_link_status (sc);
211 sc->lmc_xinfo.mii_reg16 = lmc_mii_readreg (sc, 0, 16);
212 spin_unlock_irqrestore(&sc->lmc_lock, flags);
213
214 sc->lmc_xinfo.Magic1 = 0xDEADBEEF;
215
216 if (copy_to_user(data, &sc->lmc_xinfo, sizeof(struct lmc_xinfo)))
217 ret = -EFAULT;
218 else
219 ret = 0;
220
221 break;
222
223 case LMCIOCGETLMCSTATS:
224 spin_lock_irqsave(&sc->lmc_lock, flags);
225 if (sc->lmc_cardtype == LMC_CARDTYPE_T1) {
226 lmc_mii_writereg(sc, 0, 17, T1FRAMER_FERR_LSB);
227 sc->extra_stats.framingBitErrorCount +=
228 lmc_mii_readreg(sc, 0, 18) & 0xff;
229 lmc_mii_writereg(sc, 0, 17, T1FRAMER_FERR_MSB);
230 sc->extra_stats.framingBitErrorCount +=
231 (lmc_mii_readreg(sc, 0, 18) & 0xff) << 8;
232 lmc_mii_writereg(sc, 0, 17, T1FRAMER_LCV_LSB);
233 sc->extra_stats.lineCodeViolationCount +=
234 lmc_mii_readreg(sc, 0, 18) & 0xff;
235 lmc_mii_writereg(sc, 0, 17, T1FRAMER_LCV_MSB);
236 sc->extra_stats.lineCodeViolationCount +=
237 (lmc_mii_readreg(sc, 0, 18) & 0xff) << 8;
238 lmc_mii_writereg(sc, 0, 17, T1FRAMER_AERR);
239 regVal = lmc_mii_readreg(sc, 0, 18) & 0xff;
240
241 sc->extra_stats.lossOfFrameCount +=
242 (regVal & T1FRAMER_LOF_MASK) >> 4;
243 sc->extra_stats.changeOfFrameAlignmentCount +=
244 (regVal & T1FRAMER_COFA_MASK) >> 2;
245 sc->extra_stats.severelyErroredFrameCount +=
246 regVal & T1FRAMER_SEF_MASK;
247 }
248 spin_unlock_irqrestore(&sc->lmc_lock, flags);
249 if (copy_to_user(data, &sc->lmc_device->stats,
250 sizeof(sc->lmc_device->stats)) ||
251 copy_to_user(data + sizeof(sc->lmc_device->stats),
252 &sc->extra_stats, sizeof(sc->extra_stats)))
253 ret = -EFAULT;
254 else
255 ret = 0;
256 break;
257
258 case LMCIOCCLEARLMCSTATS:
259 if (!capable(CAP_NET_ADMIN)) {
260 ret = -EPERM;
261 break;
262 }
263
264 spin_lock_irqsave(&sc->lmc_lock, flags);
265 memset(&sc->lmc_device->stats, 0, sizeof(sc->lmc_device->stats));
266 memset(&sc->extra_stats, 0, sizeof(sc->extra_stats));
267 sc->extra_stats.check = STATCHECK;
268 sc->extra_stats.version_size = (DRIVER_VERSION << 16) +
269 sizeof(sc->lmc_device->stats) + sizeof(sc->extra_stats);
270 sc->extra_stats.lmc_cardtype = sc->lmc_cardtype;
271 spin_unlock_irqrestore(&sc->lmc_lock, flags);
272 ret = 0;
273 break;
274
275 case LMCIOCSETCIRCUIT:
276 if (!capable(CAP_NET_ADMIN)){
277 ret = -EPERM;
278 break;
279 }
280
281 if(dev->flags & IFF_UP){
282 ret = -EBUSY;
283 break;
284 }
285
286 if (copy_from_user(&ctl, data, sizeof(lmc_ctl_t))) {
287 ret = -EFAULT;
288 break;
289 }
290 spin_lock_irqsave(&sc->lmc_lock, flags);
291 sc->lmc_media->set_circuit_type(sc, ctl.circuit_type);
292 sc->ictl.circuit_type = ctl.circuit_type;
293 spin_unlock_irqrestore(&sc->lmc_lock, flags);
294 ret = 0;
295
296 break;
297
298 case LMCIOCRESET:
299 if (!capable(CAP_NET_ADMIN)){
300 ret = -EPERM;
301 break;
302 }
303
304 spin_lock_irqsave(&sc->lmc_lock, flags);
305
306 printk (" REG16 before reset +%04x\n", lmc_mii_readreg (sc, 0, 16));
307 lmc_running_reset (dev);
308 printk (" REG16 after reset +%04x\n", lmc_mii_readreg (sc, 0, 16));
309
310 LMC_EVENT_LOG(LMC_EVENT_FORCEDRESET, LMC_CSR_READ (sc, csr_status), lmc_mii_readreg (sc, 0, 16));
311 spin_unlock_irqrestore(&sc->lmc_lock, flags);
312
313 ret = 0;
314 break;
315
316#ifdef DEBUG
317 case LMCIOCDUMPEVENTLOG:
318 if (copy_to_user(data, &lmcEventLogIndex, sizeof(u32))) {
319 ret = -EFAULT;
320 break;
321 }
322 if (copy_to_user(data + sizeof(u32), lmcEventLogBuf,
323 sizeof(lmcEventLogBuf)))
324 ret = -EFAULT;
325 else
326 ret = 0;
327
328 break;
329#endif
330 case LMCIOCT1CONTROL:
331 if (sc->lmc_cardtype != LMC_CARDTYPE_T1){
332 ret = -EOPNOTSUPP;
333 break;
334 }
335 break;
336 case LMCIOCXILINX:
337 {
338 struct lmc_xilinx_control xc;
339
340 if (!capable(CAP_NET_ADMIN)){
341 ret = -EPERM;
342 break;
343 }
344
345
346
347
348 netif_stop_queue(dev);
349
350 if (copy_from_user(&xc, data, sizeof(struct lmc_xilinx_control))) {
351 ret = -EFAULT;
352 break;
353 }
354 switch(xc.command){
355 case lmc_xilinx_reset:
356 {
357 spin_lock_irqsave(&sc->lmc_lock, flags);
358 lmc_mii_readreg (sc, 0, 16);
359
360
361
362
363 lmc_gpio_mkinput(sc, 0xff);
364
365
366
367
368 lmc_gpio_mkoutput(sc, LMC_GEP_RESET);
369
370
371
372
373
374
375
376 sc->lmc_gpio &= ~LMC_GEP_RESET;
377 LMC_CSR_WRITE(sc, csr_gp, sc->lmc_gpio);
378
379
380
381
382
383 udelay(50);
384
385 sc->lmc_gpio |= LMC_GEP_RESET;
386 LMC_CSR_WRITE(sc, csr_gp, sc->lmc_gpio);
387
388
389
390
391
392 lmc_gpio_mkinput(sc, 0xff);
393
394
395 sc->lmc_media->set_link_status (sc, 1);
396 sc->lmc_media->set_status (sc, NULL);
397
398
399 {
400 int i;
401 for(i = 0; i < 5; i++){
402 lmc_led_on(sc, LMC_DS3_LED0);
403 mdelay(100);
404 lmc_led_off(sc, LMC_DS3_LED0);
405 lmc_led_on(sc, LMC_DS3_LED1);
406 mdelay(100);
407 lmc_led_off(sc, LMC_DS3_LED1);
408 lmc_led_on(sc, LMC_DS3_LED3);
409 mdelay(100);
410 lmc_led_off(sc, LMC_DS3_LED3);
411 lmc_led_on(sc, LMC_DS3_LED2);
412 mdelay(100);
413 lmc_led_off(sc, LMC_DS3_LED2);
414 }
415 }
416 spin_unlock_irqrestore(&sc->lmc_lock, flags);
417
418
419
420 ret = 0x0;
421
422 }
423
424 break;
425 case lmc_xilinx_load_prom:
426 {
427 int timeout = 500000;
428 spin_lock_irqsave(&sc->lmc_lock, flags);
429 lmc_mii_readreg (sc, 0, 16);
430
431
432
433
434 lmc_gpio_mkinput(sc, 0xff);
435
436
437
438
439 lmc_gpio_mkoutput(sc, LMC_GEP_DP | LMC_GEP_RESET);
440
441
442
443
444
445
446
447 sc->lmc_gpio &= ~(LMC_GEP_RESET | LMC_GEP_DP);
448 LMC_CSR_WRITE(sc, csr_gp, sc->lmc_gpio);
449
450
451
452
453
454 udelay(50);
455
456 sc->lmc_gpio |= LMC_GEP_DP | LMC_GEP_RESET;
457 LMC_CSR_WRITE(sc, csr_gp, sc->lmc_gpio);
458
459
460
461
462 while( (LMC_CSR_READ(sc, csr_gp) & LMC_GEP_INIT) == 0 &&
463 (timeout-- > 0))
464 cpu_relax();
465
466
467
468
469
470 lmc_gpio_mkinput(sc, 0xff);
471 spin_unlock_irqrestore(&sc->lmc_lock, flags);
472
473 ret = 0x0;
474
475
476 break;
477
478 }
479
480 case lmc_xilinx_load:
481 {
482 char *data;
483 int pos;
484 int timeout = 500000;
485
486 if (!xc.data) {
487 ret = -EINVAL;
488 break;
489 }
490
491 data = memdup_user(xc.data, xc.len);
492 if (IS_ERR(data)) {
493 ret = PTR_ERR(data);
494 break;
495 }
496
497 printk("%s: Starting load of data Len: %d at 0x%p == 0x%p\n", dev->name, xc.len, xc.data, data);
498
499 spin_lock_irqsave(&sc->lmc_lock, flags);
500 lmc_gpio_mkinput(sc, 0xff);
501
502
503
504
505
506
507
508
509
510
511
512
513 sc->lmc_gpio = 0x00;
514 sc->lmc_gpio &= ~LMC_GEP_DP;
515 sc->lmc_gpio &= ~LMC_GEP_RESET;
516 sc->lmc_gpio |= LMC_GEP_MODE;
517 LMC_CSR_WRITE(sc, csr_gp, sc->lmc_gpio);
518
519 lmc_gpio_mkoutput(sc, LMC_GEP_MODE | LMC_GEP_DP | LMC_GEP_RESET);
520
521
522
523
524 udelay(50);
525
526
527
528
529
530
531
532
533
534 lmc_gpio_mkinput(sc, LMC_GEP_DP | LMC_GEP_RESET);
535
536
537
538
539 sc->lmc_gpio = 0x00;
540 sc->lmc_gpio |= LMC_GEP_MODE;
541 sc->lmc_gpio |= LMC_GEP_DATA;
542 sc->lmc_gpio |= LMC_GEP_CLK;
543 LMC_CSR_WRITE(sc, csr_gp, sc->lmc_gpio);
544
545 lmc_gpio_mkoutput(sc, LMC_GEP_DATA | LMC_GEP_CLK | LMC_GEP_MODE );
546
547
548
549
550 while( (LMC_CSR_READ(sc, csr_gp) & LMC_GEP_INIT) == 0 &&
551 (timeout-- > 0))
552 cpu_relax();
553
554 printk(KERN_DEBUG "%s: Waited %d for the Xilinx to clear its memory\n", dev->name, 500000-timeout);
555
556 for(pos = 0; pos < xc.len; pos++){
557 switch(data[pos]){
558 case 0:
559 sc->lmc_gpio &= ~LMC_GEP_DATA;
560 break;
561 case 1:
562 sc->lmc_gpio |= LMC_GEP_DATA;
563 break;
564 default:
565 printk(KERN_WARNING "%s Bad data in xilinx programming data at %d, got %d wanted 0 or 1\n", dev->name, pos, data[pos]);
566 sc->lmc_gpio |= LMC_GEP_DATA;
567 }
568 sc->lmc_gpio &= ~LMC_GEP_CLK;
569 sc->lmc_gpio |= LMC_GEP_MODE;
570 LMC_CSR_WRITE(sc, csr_gp, sc->lmc_gpio);
571 udelay(1);
572
573 sc->lmc_gpio |= LMC_GEP_CLK;
574 sc->lmc_gpio |= LMC_GEP_MODE;
575 LMC_CSR_WRITE(sc, csr_gp, sc->lmc_gpio);
576 udelay(1);
577 }
578 if((LMC_CSR_READ(sc, csr_gp) & LMC_GEP_INIT) == 0){
579 printk(KERN_WARNING "%s: Reprogramming FAILED. Needs to be reprogrammed. (corrupted data)\n", dev->name);
580 }
581 else if((LMC_CSR_READ(sc, csr_gp) & LMC_GEP_DP) == 0){
582 printk(KERN_WARNING "%s: Reprogramming FAILED. Needs to be reprogrammed. (done)\n", dev->name);
583 }
584 else {
585 printk(KERN_DEBUG "%s: Done reprogramming Xilinx, %d bits, good luck!\n", dev->name, pos);
586 }
587
588 lmc_gpio_mkinput(sc, 0xff);
589
590 sc->lmc_miireg16 |= LMC_MII16_FIFO_RESET;
591 lmc_mii_writereg(sc, 0, 16, sc->lmc_miireg16);
592
593 sc->lmc_miireg16 &= ~LMC_MII16_FIFO_RESET;
594 lmc_mii_writereg(sc, 0, 16, sc->lmc_miireg16);
595 spin_unlock_irqrestore(&sc->lmc_lock, flags);
596
597 kfree(data);
598
599 ret = 0;
600
601 break;
602 }
603 default:
604 ret = -EBADE;
605 break;
606 }
607
608 netif_wake_queue(dev);
609 sc->lmc_txfull = 0;
610
611 }
612 break;
613 default:
614 break;
615 }
616
617 return ret;
618}
619
620
621
622static void lmc_watchdog(struct timer_list *t)
623{
624 lmc_softc_t *sc = from_timer(sc, t, timer);
625 struct net_device *dev = sc->lmc_device;
626 int link_status;
627 u32 ticks;
628 unsigned long flags;
629
630 spin_lock_irqsave(&sc->lmc_lock, flags);
631
632 if(sc->check != 0xBEAFCAFE){
633 printk("LMC: Corrupt net_device struct, breaking out\n");
634 spin_unlock_irqrestore(&sc->lmc_lock, flags);
635 return;
636 }
637
638
639
640
641
642
643 LMC_CSR_WRITE (sc, csr_15, 0x00000011);
644 sc->lmc_cmdmode |= TULIP_CMD_TXRUN | TULIP_CMD_RXRUN;
645 LMC_CSR_WRITE (sc, csr_command, sc->lmc_cmdmode);
646
647 if (sc->lmc_ok == 0)
648 goto kick_timer;
649
650 LMC_EVENT_LOG(LMC_EVENT_WATCHDOG, LMC_CSR_READ (sc, csr_status), lmc_mii_readreg (sc, 0, 16));
651
652
653
654
655 if (sc->lmc_taint_tx == sc->lastlmc_taint_tx &&
656 sc->lmc_device->stats.tx_packets > sc->lasttx_packets &&
657 sc->tx_TimeoutInd == 0)
658 {
659
660
661 sc->tx_TimeoutInd = 1;
662 }
663 else if (sc->lmc_taint_tx == sc->lastlmc_taint_tx &&
664 sc->lmc_device->stats.tx_packets > sc->lasttx_packets &&
665 sc->tx_TimeoutInd)
666 {
667
668 LMC_EVENT_LOG(LMC_EVENT_XMTINTTMO, LMC_CSR_READ (sc, csr_status), 0);
669
670 sc->tx_TimeoutDisplay = 1;
671 sc->extra_stats.tx_TimeoutCnt++;
672
673
674 lmc_running_reset (dev);
675
676
677
678 LMC_EVENT_LOG(LMC_EVENT_RESET1, LMC_CSR_READ (sc, csr_status), 0);
679
680
681
682
683
684
685
686 LMC_EVENT_LOG(LMC_EVENT_RESET2, lmc_mii_readreg (sc, 0, 16), lmc_mii_readreg (sc, 0, 17));
687
688
689 sc->tx_TimeoutInd = 0;
690 sc->lastlmc_taint_tx = sc->lmc_taint_tx;
691 sc->lasttx_packets = sc->lmc_device->stats.tx_packets;
692 } else {
693 sc->tx_TimeoutInd = 0;
694 sc->lastlmc_taint_tx = sc->lmc_taint_tx;
695 sc->lasttx_packets = sc->lmc_device->stats.tx_packets;
696 }
697
698
699
700
701 link_status = sc->lmc_media->get_link_status (sc);
702
703
704
705
706
707 if ((link_status == 0) && (sc->last_link_status != 0)) {
708 printk(KERN_WARNING "%s: hardware/physical link down\n", dev->name);
709 sc->last_link_status = 0;
710
711
712
713 netif_carrier_off(dev);
714 }
715
716
717
718
719
720 if (link_status != 0 && sc->last_link_status == 0) {
721 printk(KERN_WARNING "%s: hardware/physical link up\n", dev->name);
722 sc->last_link_status = 1;
723
724
725 netif_carrier_on(dev);
726 }
727
728
729 sc->lmc_media->watchdog(sc);
730
731
732
733
734
735 LMC_CSR_WRITE(sc, csr_rxpoll, 0);
736
737
738
739
740
741 if(sc->failed_ring == 1){
742
743
744
745
746 sc->failed_ring = 0;
747 lmc_softreset(sc);
748 }
749 if(sc->failed_recv_alloc == 1){
750
751
752
753
754
755 sc->failed_recv_alloc = 0;
756 lmc_softreset(sc);
757 }
758
759
760
761
762
763kick_timer:
764
765 ticks = LMC_CSR_READ (sc, csr_gp_timer);
766 LMC_CSR_WRITE (sc, csr_gp_timer, 0xffffffffUL);
767 sc->ictl.ticks = 0x0000ffff - (ticks & 0x0000ffff);
768
769
770
771
772 sc->timer.expires = jiffies + (HZ);
773 add_timer (&sc->timer);
774
775 spin_unlock_irqrestore(&sc->lmc_lock, flags);
776}
777
778static int lmc_attach(struct net_device *dev, unsigned short encoding,
779 unsigned short parity)
780{
781 if (encoding == ENCODING_NRZ && parity == PARITY_CRC16_PR1_CCITT)
782 return 0;
783 return -EINVAL;
784}
785
786static const struct net_device_ops lmc_ops = {
787 .ndo_open = lmc_open,
788 .ndo_stop = lmc_close,
789 .ndo_start_xmit = hdlc_start_xmit,
790 .ndo_siocwandev = hdlc_ioctl,
791 .ndo_siocdevprivate = lmc_siocdevprivate,
792 .ndo_tx_timeout = lmc_driver_timeout,
793 .ndo_get_stats = lmc_get_stats,
794};
795
796static int lmc_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
797{
798 lmc_softc_t *sc;
799 struct net_device *dev;
800 u16 subdevice;
801 u16 AdapModelNum;
802 int err;
803 static int cards_found;
804
805 err = pcim_enable_device(pdev);
806 if (err) {
807 printk(KERN_ERR "lmc: pci enable failed: %d\n", err);
808 return err;
809 }
810
811 err = pci_request_regions(pdev, "lmc");
812 if (err) {
813 printk(KERN_ERR "lmc: pci_request_region failed\n");
814 return err;
815 }
816
817
818
819
820 sc = devm_kzalloc(&pdev->dev, sizeof(lmc_softc_t), GFP_KERNEL);
821 if (!sc)
822 return -ENOMEM;
823
824 dev = alloc_hdlcdev(sc);
825 if (!dev) {
826 printk(KERN_ERR "lmc:alloc_netdev for device failed\n");
827 return -ENOMEM;
828 }
829
830
831 dev->type = ARPHRD_HDLC;
832 dev_to_hdlc(dev)->xmit = lmc_start_xmit;
833 dev_to_hdlc(dev)->attach = lmc_attach;
834 dev->netdev_ops = &lmc_ops;
835 dev->watchdog_timeo = HZ;
836 dev->tx_queue_len = 100;
837 sc->lmc_device = dev;
838 sc->name = dev->name;
839 sc->if_type = LMC_PPP;
840 sc->check = 0xBEAFCAFE;
841 dev->base_addr = pci_resource_start(pdev, 0);
842 dev->irq = pdev->irq;
843 pci_set_drvdata(pdev, dev);
844 SET_NETDEV_DEV(dev, &pdev->dev);
845
846
847
848
849
850 lmc_proto_attach(sc);
851
852
853
854 spin_lock_init(&sc->lmc_lock);
855 pci_set_master(pdev);
856
857 printk(KERN_INFO "hdlc: detected at %lx, irq %d\n",
858 dev->base_addr, dev->irq);
859
860 err = register_hdlc_device(dev);
861 if (err) {
862 printk(KERN_ERR "%s: register_netdev failed.\n", dev->name);
863 free_netdev(dev);
864 return err;
865 }
866
867 sc->lmc_cardtype = LMC_CARDTYPE_UNKNOWN;
868 sc->lmc_timing = LMC_CTL_CLOCK_SOURCE_EXT;
869
870
871
872
873
874
875
876 if ((subdevice = pdev->subsystem_device) == PCI_VENDOR_ID_LMC)
877 subdevice = pdev->subsystem_vendor;
878
879 switch (subdevice) {
880 case PCI_DEVICE_ID_LMC_HSSI:
881 printk(KERN_INFO "%s: LMC HSSI\n", dev->name);
882 sc->lmc_cardtype = LMC_CARDTYPE_HSSI;
883 sc->lmc_media = &lmc_hssi_media;
884 break;
885 case PCI_DEVICE_ID_LMC_DS3:
886 printk(KERN_INFO "%s: LMC DS3\n", dev->name);
887 sc->lmc_cardtype = LMC_CARDTYPE_DS3;
888 sc->lmc_media = &lmc_ds3_media;
889 break;
890 case PCI_DEVICE_ID_LMC_SSI:
891 printk(KERN_INFO "%s: LMC SSI\n", dev->name);
892 sc->lmc_cardtype = LMC_CARDTYPE_SSI;
893 sc->lmc_media = &lmc_ssi_media;
894 break;
895 case PCI_DEVICE_ID_LMC_T1:
896 printk(KERN_INFO "%s: LMC T1\n", dev->name);
897 sc->lmc_cardtype = LMC_CARDTYPE_T1;
898 sc->lmc_media = &lmc_t1_media;
899 break;
900 default:
901 printk(KERN_WARNING "%s: LMC UNKNOWN CARD!\n", dev->name);
902 unregister_hdlc_device(dev);
903 return -EIO;
904 break;
905 }
906
907 lmc_initcsrs (sc, dev->base_addr, 8);
908
909 lmc_gpio_mkinput (sc, 0xff);
910 sc->lmc_gpio = 0;
911
912 sc->lmc_media->defaults (sc);
913
914 sc->lmc_media->set_link_status (sc, LMC_LINK_UP);
915
916
917
918
919 AdapModelNum = (lmc_mii_readreg (sc, 0, 3) & 0x3f0) >> 4;
920
921 if ((AdapModelNum != LMC_ADAP_T1 ||
922 subdevice != PCI_DEVICE_ID_LMC_T1) &&
923 (AdapModelNum != LMC_ADAP_SSI ||
924 subdevice != PCI_DEVICE_ID_LMC_SSI) &&
925 (AdapModelNum != LMC_ADAP_DS3 ||
926 subdevice != PCI_DEVICE_ID_LMC_DS3) &&
927 (AdapModelNum != LMC_ADAP_HSSI ||
928 subdevice != PCI_DEVICE_ID_LMC_HSSI))
929 printk(KERN_WARNING "%s: Model number (%d) miscompare for PCI"
930 " Subsystem ID = 0x%04x\n",
931 dev->name, AdapModelNum, subdevice);
932
933
934
935
936 LMC_CSR_WRITE (sc, csr_gp_timer, 0xFFFFFFFFUL);
937
938 sc->board_idx = cards_found++;
939 sc->extra_stats.check = STATCHECK;
940 sc->extra_stats.version_size = (DRIVER_VERSION << 16) +
941 sizeof(sc->lmc_device->stats) + sizeof(sc->extra_stats);
942 sc->extra_stats.lmc_cardtype = sc->lmc_cardtype;
943
944 sc->lmc_ok = 0;
945 sc->last_link_status = 0;
946
947 return 0;
948}
949
950
951
952
953static void lmc_remove_one(struct pci_dev *pdev)
954{
955 struct net_device *dev = pci_get_drvdata(pdev);
956
957 if (dev) {
958 printk(KERN_DEBUG "%s: removing...\n", dev->name);
959 unregister_hdlc_device(dev);
960 free_netdev(dev);
961 }
962}
963
964
965
966
967static int lmc_open(struct net_device *dev)
968{
969 lmc_softc_t *sc = dev_to_sc(dev);
970 int err;
971
972 lmc_led_on(sc, LMC_DS3_LED0);
973
974 lmc_dec_reset(sc);
975 lmc_reset(sc);
976
977 LMC_EVENT_LOG(LMC_EVENT_RESET1, LMC_CSR_READ(sc, csr_status), 0);
978 LMC_EVENT_LOG(LMC_EVENT_RESET2, lmc_mii_readreg(sc, 0, 16),
979 lmc_mii_readreg(sc, 0, 17));
980
981 if (sc->lmc_ok)
982 return 0;
983
984 lmc_softreset (sc);
985
986
987 if (request_irq (dev->irq, lmc_interrupt, IRQF_SHARED, dev->name, dev)){
988 printk(KERN_WARNING "%s: could not get irq: %d\n", dev->name, dev->irq);
989 return -EAGAIN;
990 }
991 sc->got_irq = 1;
992
993
994 sc->lmc_miireg16 |= LMC_MII16_LED_ALL;
995 sc->lmc_media->set_link_status (sc, LMC_LINK_UP);
996
997
998
999
1000 sc->lmc_media->set_status (sc, NULL);
1001
1002
1003
1004 sc->TxDescriptControlInit = (
1005 LMC_TDES_INTERRUPT_ON_COMPLETION
1006 | LMC_TDES_FIRST_SEGMENT
1007 | LMC_TDES_LAST_SEGMENT
1008 | LMC_TDES_SECOND_ADDR_CHAINED
1009 | LMC_TDES_DISABLE_PADDING
1010 );
1011
1012 if (sc->ictl.crc_length == LMC_CTL_CRC_LENGTH_16) {
1013
1014 sc->TxDescriptControlInit |= LMC_TDES_ADD_CRC_DISABLE;
1015 }
1016 sc->lmc_media->set_crc_length(sc, sc->ictl.crc_length);
1017
1018
1019
1020
1021 if ((err = lmc_proto_open(sc)) != 0)
1022 return err;
1023
1024 netif_start_queue(dev);
1025 sc->extra_stats.tx_tbusy0++;
1026
1027
1028
1029
1030 sc->lmc_intrmask = 0;
1031
1032 sc->lmc_intrmask |= (TULIP_STS_NORMALINTR
1033 | TULIP_STS_RXINTR
1034 | TULIP_STS_TXINTR
1035 | TULIP_STS_ABNRMLINTR
1036 | TULIP_STS_SYSERROR
1037 | TULIP_STS_TXSTOPPED
1038 | TULIP_STS_TXUNDERFLOW
1039 | TULIP_STS_RXSTOPPED
1040 | TULIP_STS_RXNOBUF
1041 );
1042 LMC_CSR_WRITE (sc, csr_intr, sc->lmc_intrmask);
1043
1044 sc->lmc_cmdmode |= TULIP_CMD_TXRUN;
1045 sc->lmc_cmdmode |= TULIP_CMD_RXRUN;
1046 LMC_CSR_WRITE (sc, csr_command, sc->lmc_cmdmode);
1047
1048 sc->lmc_ok = 1;
1049
1050
1051
1052
1053
1054 sc->last_link_status = 1;
1055
1056
1057
1058
1059
1060 timer_setup(&sc->timer, lmc_watchdog, 0);
1061 sc->timer.expires = jiffies + HZ;
1062 add_timer (&sc->timer);
1063
1064 return 0;
1065}
1066
1067
1068
1069
1070
1071static void lmc_running_reset (struct net_device *dev)
1072{
1073 lmc_softc_t *sc = dev_to_sc(dev);
1074
1075
1076
1077 LMC_CSR_WRITE (sc, csr_intr, 0x00000000);
1078
1079 lmc_dec_reset (sc);
1080 lmc_reset (sc);
1081 lmc_softreset (sc);
1082
1083 sc->lmc_media->set_link_status (sc, 1);
1084 sc->lmc_media->set_status (sc, NULL);
1085
1086 netif_wake_queue(dev);
1087
1088 sc->lmc_txfull = 0;
1089 sc->extra_stats.tx_tbusy0++;
1090
1091 sc->lmc_intrmask = TULIP_DEFAULT_INTR_MASK;
1092 LMC_CSR_WRITE (sc, csr_intr, sc->lmc_intrmask);
1093
1094 sc->lmc_cmdmode |= (TULIP_CMD_TXRUN | TULIP_CMD_RXRUN);
1095 LMC_CSR_WRITE (sc, csr_command, sc->lmc_cmdmode);
1096}
1097
1098
1099
1100
1101
1102
1103static int lmc_close(struct net_device *dev)
1104{
1105
1106 lmc_softc_t *sc = dev_to_sc(dev);
1107
1108 sc->lmc_ok = 0;
1109 sc->lmc_media->set_link_status (sc, 0);
1110 del_timer (&sc->timer);
1111 lmc_proto_close(sc);
1112 lmc_ifdown (dev);
1113
1114 return 0;
1115}
1116
1117
1118
1119static int lmc_ifdown (struct net_device *dev)
1120{
1121 lmc_softc_t *sc = dev_to_sc(dev);
1122 u32 csr6;
1123 int i;
1124
1125
1126
1127 netif_stop_queue(dev);
1128 sc->extra_stats.tx_tbusy1++;
1129
1130
1131
1132 LMC_CSR_WRITE (sc, csr_intr, 0x00000000);
1133
1134
1135 csr6 = LMC_CSR_READ (sc, csr_command);
1136 csr6 &= ~LMC_DEC_ST;
1137 csr6 &= ~LMC_DEC_SR;
1138 LMC_CSR_WRITE (sc, csr_command, csr6);
1139
1140 sc->lmc_device->stats.rx_missed_errors +=
1141 LMC_CSR_READ(sc, csr_missed_frames) & 0xffff;
1142
1143
1144 if(sc->got_irq == 1){
1145 free_irq (dev->irq, dev);
1146 sc->got_irq = 0;
1147 }
1148
1149
1150 for (i = 0; i < LMC_RXDESCS; i++)
1151 {
1152 struct sk_buff *skb = sc->lmc_rxq[i];
1153 sc->lmc_rxq[i] = NULL;
1154 sc->lmc_rxring[i].status = 0;
1155 sc->lmc_rxring[i].length = 0;
1156 sc->lmc_rxring[i].buffer1 = 0xDEADBEEF;
1157 if (skb != NULL)
1158 dev_kfree_skb(skb);
1159 sc->lmc_rxq[i] = NULL;
1160 }
1161
1162 for (i = 0; i < LMC_TXDESCS; i++)
1163 {
1164 if (sc->lmc_txq[i] != NULL)
1165 dev_kfree_skb(sc->lmc_txq[i]);
1166 sc->lmc_txq[i] = NULL;
1167 }
1168
1169 lmc_led_off (sc, LMC_MII16_LED_ALL);
1170
1171 netif_wake_queue(dev);
1172 sc->extra_stats.tx_tbusy0++;
1173
1174 return 0;
1175}
1176
1177
1178
1179
1180static irqreturn_t lmc_interrupt (int irq, void *dev_instance)
1181{
1182 struct net_device *dev = (struct net_device *) dev_instance;
1183 lmc_softc_t *sc = dev_to_sc(dev);
1184 u32 csr;
1185 int i;
1186 s32 stat;
1187 unsigned int badtx;
1188 int max_work = LMC_RXDESCS;
1189 int handled = 0;
1190
1191 spin_lock(&sc->lmc_lock);
1192
1193
1194
1195
1196 csr = LMC_CSR_READ (sc, csr_status);
1197
1198
1199
1200
1201 if ( ! (csr & sc->lmc_intrmask)) {
1202 goto lmc_int_fail_out;
1203 }
1204
1205
1206 while (csr & sc->lmc_intrmask) {
1207 handled = 1;
1208
1209
1210
1211
1212 LMC_CSR_WRITE (sc, csr_status, csr);
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227 if (csr & TULIP_STS_ABNRMLINTR){
1228 lmc_running_reset (dev);
1229 break;
1230 }
1231
1232 if (csr & TULIP_STS_RXINTR)
1233 lmc_rx (dev);
1234
1235 if (csr & (TULIP_STS_TXINTR | TULIP_STS_TXNOBUF | TULIP_STS_TXSTOPPED)) {
1236
1237 int n_compl = 0 ;
1238
1239 sc->extra_stats.tx_NoCompleteCnt = 0;
1240
1241 badtx = sc->lmc_taint_tx;
1242 i = badtx % LMC_TXDESCS;
1243
1244 while ((badtx < sc->lmc_next_tx)) {
1245 stat = sc->lmc_txring[i].status;
1246
1247 LMC_EVENT_LOG (LMC_EVENT_XMTINT, stat,
1248 sc->lmc_txring[i].length);
1249
1250
1251
1252 if (stat & 0x80000000)
1253 break;
1254
1255 n_compl++ ;
1256
1257
1258
1259
1260 if (sc->lmc_txq[i] == NULL)
1261 continue;
1262
1263
1264
1265
1266 if (stat & 0x8000) {
1267 sc->lmc_device->stats.tx_errors++;
1268 if (stat & 0x4104)
1269 sc->lmc_device->stats.tx_aborted_errors++;
1270 if (stat & 0x0C00)
1271 sc->lmc_device->stats.tx_carrier_errors++;
1272 if (stat & 0x0200)
1273 sc->lmc_device->stats.tx_window_errors++;
1274 if (stat & 0x0002)
1275 sc->lmc_device->stats.tx_fifo_errors++;
1276 } else {
1277 sc->lmc_device->stats.tx_bytes += sc->lmc_txring[i].length & 0x7ff;
1278
1279 sc->lmc_device->stats.tx_packets++;
1280 }
1281
1282 dev_consume_skb_irq(sc->lmc_txq[i]);
1283 sc->lmc_txq[i] = NULL;
1284
1285 badtx++;
1286 i = badtx % LMC_TXDESCS;
1287 }
1288
1289 if (sc->lmc_next_tx - badtx > LMC_TXDESCS)
1290 {
1291 printk ("%s: out of sync pointer\n", dev->name);
1292 badtx += LMC_TXDESCS;
1293 }
1294 LMC_EVENT_LOG(LMC_EVENT_TBUSY0, n_compl, 0);
1295 sc->lmc_txfull = 0;
1296 netif_wake_queue(dev);
1297 sc->extra_stats.tx_tbusy0++;
1298
1299
1300#ifdef DEBUG
1301 sc->extra_stats.dirtyTx = badtx;
1302 sc->extra_stats.lmc_next_tx = sc->lmc_next_tx;
1303 sc->extra_stats.lmc_txfull = sc->lmc_txfull;
1304#endif
1305 sc->lmc_taint_tx = badtx;
1306
1307
1308
1309
1310 }
1311
1312 if (csr & TULIP_STS_SYSERROR) {
1313 u32 error;
1314 printk (KERN_WARNING "%s: system bus error csr: %#8.8x\n", dev->name, csr);
1315 error = csr>>23 & 0x7;
1316 switch(error){
1317 case 0x000:
1318 printk(KERN_WARNING "%s: Parity Fault (bad)\n", dev->name);
1319 break;
1320 case 0x001:
1321 printk(KERN_WARNING "%s: Master Abort (naughty)\n", dev->name);
1322 break;
1323 case 0x002:
1324 printk(KERN_WARNING "%s: Target Abort (not so naughty)\n", dev->name);
1325 break;
1326 default:
1327 printk(KERN_WARNING "%s: This bus error code was supposed to be reserved!\n", dev->name);
1328 }
1329 lmc_dec_reset (sc);
1330 lmc_reset (sc);
1331 LMC_EVENT_LOG(LMC_EVENT_RESET1, LMC_CSR_READ (sc, csr_status), 0);
1332 LMC_EVENT_LOG(LMC_EVENT_RESET2,
1333 lmc_mii_readreg (sc, 0, 16),
1334 lmc_mii_readreg (sc, 0, 17));
1335
1336 }
1337
1338
1339 if(max_work-- <= 0)
1340 break;
1341
1342
1343
1344
1345
1346 csr = LMC_CSR_READ (sc, csr_status);
1347 }
1348 LMC_EVENT_LOG(LMC_EVENT_INT, firstcsr, csr);
1349
1350lmc_int_fail_out:
1351
1352 spin_unlock(&sc->lmc_lock);
1353
1354 return IRQ_RETVAL(handled);
1355}
1356
1357static netdev_tx_t lmc_start_xmit(struct sk_buff *skb,
1358 struct net_device *dev)
1359{
1360 lmc_softc_t *sc = dev_to_sc(dev);
1361 u32 flag;
1362 int entry;
1363 unsigned long flags;
1364
1365 spin_lock_irqsave(&sc->lmc_lock, flags);
1366
1367
1368
1369 entry = sc->lmc_next_tx % LMC_TXDESCS;
1370
1371 sc->lmc_txq[entry] = skb;
1372 sc->lmc_txring[entry].buffer1 = virt_to_bus (skb->data);
1373
1374 LMC_CONSOLE_LOG("xmit", skb->data, skb->len);
1375
1376#ifndef GCOM
1377
1378 if (sc->lmc_next_tx - sc->lmc_taint_tx < LMC_TXDESCS / 2)
1379 {
1380
1381 flag = 0x60000000;
1382 netif_wake_queue(dev);
1383 }
1384 else if (sc->lmc_next_tx - sc->lmc_taint_tx == LMC_TXDESCS / 2)
1385 {
1386
1387 flag = 0xe0000000;
1388 netif_wake_queue(dev);
1389 }
1390 else if (sc->lmc_next_tx - sc->lmc_taint_tx < LMC_TXDESCS - 1)
1391 {
1392
1393 flag = 0x60000000;
1394 netif_wake_queue(dev);
1395 }
1396 else
1397 {
1398
1399 flag = 0xe0000000;
1400 sc->lmc_txfull = 1;
1401 netif_stop_queue(dev);
1402 }
1403#else
1404 flag = LMC_TDES_INTERRUPT_ON_COMPLETION;
1405
1406 if (sc->lmc_next_tx - sc->lmc_taint_tx >= LMC_TXDESCS - 1)
1407 {
1408 sc->lmc_txfull = 1;
1409 netif_stop_queue(dev);
1410 sc->extra_stats.tx_tbusy1++;
1411 LMC_EVENT_LOG(LMC_EVENT_TBUSY1, entry, 0);
1412 }
1413#endif
1414
1415
1416 if (entry == LMC_TXDESCS - 1)
1417 flag |= LMC_TDES_END_OF_RING;
1418
1419
1420 flag = sc->lmc_txring[entry].length = (skb->len) | flag |
1421 sc->TxDescriptControlInit;
1422
1423
1424
1425
1426
1427 sc->extra_stats.tx_NoCompleteCnt++;
1428 sc->lmc_next_tx++;
1429
1430
1431 LMC_EVENT_LOG(LMC_EVENT_XMT, flag, entry);
1432 sc->lmc_txring[entry].status = 0x80000000;
1433
1434
1435 LMC_CSR_WRITE (sc, csr_txpoll, 0);
1436
1437 spin_unlock_irqrestore(&sc->lmc_lock, flags);
1438
1439 return NETDEV_TX_OK;
1440}
1441
1442
1443static int lmc_rx(struct net_device *dev)
1444{
1445 lmc_softc_t *sc = dev_to_sc(dev);
1446 int i;
1447 int rx_work_limit = LMC_RXDESCS;
1448 int rxIntLoopCnt;
1449 int localLengthErrCnt = 0;
1450 long stat;
1451 struct sk_buff *skb, *nsb;
1452 u16 len;
1453
1454 lmc_led_on(sc, LMC_DS3_LED3);
1455
1456 rxIntLoopCnt = 0;
1457
1458 i = sc->lmc_next_rx % LMC_RXDESCS;
1459
1460 while (((stat = sc->lmc_rxring[i].status) & LMC_RDES_OWN_BIT) != DESC_OWNED_BY_DC21X4)
1461 {
1462 rxIntLoopCnt++;
1463 len = ((stat & LMC_RDES_FRAME_LENGTH) >> RDES_FRAME_LENGTH_BIT_NUMBER);
1464 if ((stat & 0x0300) != 0x0300) {
1465 if ((stat & 0x0000ffff) != 0x7fff) {
1466
1467 sc->lmc_device->stats.rx_length_errors++;
1468 goto skip_packet;
1469 }
1470 }
1471
1472 if (stat & 0x00000008) {
1473 sc->lmc_device->stats.rx_errors++;
1474 sc->lmc_device->stats.rx_frame_errors++;
1475 goto skip_packet;
1476 }
1477
1478
1479 if (stat & 0x00000004) {
1480 sc->lmc_device->stats.rx_errors++;
1481 sc->lmc_device->stats.rx_crc_errors++;
1482 goto skip_packet;
1483 }
1484
1485 if (len > LMC_PKT_BUF_SZ) {
1486 sc->lmc_device->stats.rx_length_errors++;
1487 localLengthErrCnt++;
1488 goto skip_packet;
1489 }
1490
1491 if (len < sc->lmc_crcSize + 2) {
1492 sc->lmc_device->stats.rx_length_errors++;
1493 sc->extra_stats.rx_SmallPktCnt++;
1494 localLengthErrCnt++;
1495 goto skip_packet;
1496 }
1497
1498 if(stat & 0x00004000){
1499 printk(KERN_WARNING "%s: Receiver descriptor error, receiver out of sync?\n", dev->name);
1500 }
1501
1502 len -= sc->lmc_crcSize;
1503
1504 skb = sc->lmc_rxq[i];
1505
1506
1507
1508
1509
1510
1511 if (!skb) {
1512 nsb = dev_alloc_skb (LMC_PKT_BUF_SZ + 2);
1513 if (nsb) {
1514 sc->lmc_rxq[i] = nsb;
1515 nsb->dev = dev;
1516 sc->lmc_rxring[i].buffer1 = virt_to_bus(skb_tail_pointer(nsb));
1517 }
1518 sc->failed_recv_alloc = 1;
1519 goto skip_packet;
1520 }
1521
1522 sc->lmc_device->stats.rx_packets++;
1523 sc->lmc_device->stats.rx_bytes += len;
1524
1525 LMC_CONSOLE_LOG("recv", skb->data, len);
1526
1527
1528
1529
1530
1531
1532
1533
1534 if(len > (LMC_MTU - (LMC_MTU>>2))){
1535
1536
1537
1538 give_it_anyways:
1539
1540 sc->lmc_rxq[i] = NULL;
1541 sc->lmc_rxring[i].buffer1 = 0x0;
1542
1543 skb_put (skb, len);
1544 skb->protocol = lmc_proto_type(sc, skb);
1545 skb_reset_mac_header(skb);
1546
1547 skb->dev = dev;
1548 lmc_proto_netif(sc, skb);
1549
1550
1551
1552
1553 nsb = dev_alloc_skb (LMC_PKT_BUF_SZ + 2);
1554 if (nsb) {
1555 sc->lmc_rxq[i] = nsb;
1556 nsb->dev = dev;
1557 sc->lmc_rxring[i].buffer1 = virt_to_bus(skb_tail_pointer(nsb));
1558
1559 }
1560 else {
1561
1562
1563
1564
1565
1566
1567
1568
1569 sc->extra_stats.rx_BuffAllocErr++;
1570 LMC_EVENT_LOG(LMC_EVENT_RCVINT, stat, len);
1571 sc->failed_recv_alloc = 1;
1572 goto skip_out_of_mem;
1573 }
1574 }
1575 else {
1576 nsb = dev_alloc_skb(len);
1577 if(!nsb) {
1578 goto give_it_anyways;
1579 }
1580 skb_copy_from_linear_data(skb, skb_put(nsb, len), len);
1581
1582 nsb->protocol = lmc_proto_type(sc, nsb);
1583 skb_reset_mac_header(nsb);
1584
1585 nsb->dev = dev;
1586 lmc_proto_netif(sc, nsb);
1587 }
1588
1589 skip_packet:
1590 LMC_EVENT_LOG(LMC_EVENT_RCVINT, stat, len);
1591 sc->lmc_rxring[i].status = DESC_OWNED_BY_DC21X4;
1592
1593 sc->lmc_next_rx++;
1594 i = sc->lmc_next_rx % LMC_RXDESCS;
1595 rx_work_limit--;
1596 if (rx_work_limit < 0)
1597 break;
1598 }
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610 if (rxIntLoopCnt > sc->extra_stats.rxIntLoopCnt)
1611 sc->extra_stats.rxIntLoopCnt = rxIntLoopCnt;
1612
1613#ifdef DEBUG
1614 if (rxIntLoopCnt == 0)
1615 {
1616 for (i = 0; i < LMC_RXDESCS; i++)
1617 {
1618 if ((sc->lmc_rxring[i].status & LMC_RDES_OWN_BIT)
1619 != DESC_OWNED_BY_DC21X4)
1620 {
1621 rxIntLoopCnt++;
1622 }
1623 }
1624 LMC_EVENT_LOG(LMC_EVENT_RCVEND, rxIntLoopCnt, 0);
1625 }
1626#endif
1627
1628
1629 lmc_led_off(sc, LMC_DS3_LED3);
1630
1631skip_out_of_mem:
1632 return 0;
1633}
1634
1635static struct net_device_stats *lmc_get_stats(struct net_device *dev)
1636{
1637 lmc_softc_t *sc = dev_to_sc(dev);
1638 unsigned long flags;
1639
1640 spin_lock_irqsave(&sc->lmc_lock, flags);
1641
1642 sc->lmc_device->stats.rx_missed_errors += LMC_CSR_READ(sc, csr_missed_frames) & 0xffff;
1643
1644 spin_unlock_irqrestore(&sc->lmc_lock, flags);
1645
1646 return &sc->lmc_device->stats;
1647}
1648
1649static struct pci_driver lmc_driver = {
1650 .name = "lmc",
1651 .id_table = lmc_pci_tbl,
1652 .probe = lmc_init_one,
1653 .remove = lmc_remove_one,
1654};
1655
1656module_pci_driver(lmc_driver);
1657
1658unsigned lmc_mii_readreg (lmc_softc_t * const sc, unsigned devaddr, unsigned regno)
1659{
1660 int i;
1661 int command = (0xf6 << 10) | (devaddr << 5) | regno;
1662 int retval = 0;
1663
1664 LMC_MII_SYNC (sc);
1665
1666 for (i = 15; i >= 0; i--)
1667 {
1668 int dataval = (command & (1 << i)) ? 0x20000 : 0;
1669
1670 LMC_CSR_WRITE (sc, csr_9, dataval);
1671 lmc_delay ();
1672
1673 LMC_CSR_WRITE (sc, csr_9, dataval | 0x10000);
1674 lmc_delay ();
1675
1676 }
1677
1678 for (i = 19; i > 0; i--)
1679 {
1680 LMC_CSR_WRITE (sc, csr_9, 0x40000);
1681 lmc_delay ();
1682
1683 retval = (retval << 1) | ((LMC_CSR_READ (sc, csr_9) & 0x80000) ? 1 : 0);
1684 LMC_CSR_WRITE (sc, csr_9, 0x40000 | 0x10000);
1685 lmc_delay ();
1686
1687 }
1688
1689 return (retval >> 1) & 0xffff;
1690}
1691
1692void lmc_mii_writereg (lmc_softc_t * const sc, unsigned devaddr, unsigned regno, unsigned data)
1693{
1694 int i = 32;
1695 int command = (0x5002 << 16) | (devaddr << 23) | (regno << 18) | data;
1696
1697 LMC_MII_SYNC (sc);
1698
1699 i = 31;
1700 while (i >= 0)
1701 {
1702 int datav;
1703
1704 if (command & (1 << i))
1705 datav = 0x20000;
1706 else
1707 datav = 0x00000;
1708
1709 LMC_CSR_WRITE (sc, csr_9, datav);
1710 lmc_delay ();
1711
1712 LMC_CSR_WRITE (sc, csr_9, (datav | 0x10000));
1713 lmc_delay ();
1714
1715 i--;
1716 }
1717
1718 i = 2;
1719 while (i > 0)
1720 {
1721 LMC_CSR_WRITE (sc, csr_9, 0x40000);
1722 lmc_delay ();
1723
1724 LMC_CSR_WRITE (sc, csr_9, 0x50000);
1725 lmc_delay ();
1726
1727 i--;
1728 }
1729}
1730
1731static void lmc_softreset (lmc_softc_t * const sc)
1732{
1733 int i;
1734
1735
1736 sc->lmc_txfull = 0;
1737 sc->lmc_next_rx = 0;
1738 sc->lmc_next_tx = 0;
1739 sc->lmc_taint_rx = 0;
1740 sc->lmc_taint_tx = 0;
1741
1742
1743
1744
1745
1746
1747
1748 for (i = 0; i < LMC_RXDESCS; i++)
1749 {
1750 struct sk_buff *skb;
1751
1752 if (sc->lmc_rxq[i] == NULL)
1753 {
1754 skb = dev_alloc_skb (LMC_PKT_BUF_SZ + 2);
1755 if(skb == NULL){
1756 printk(KERN_WARNING "%s: Failed to allocate receiver ring, will try again\n", sc->name);
1757 sc->failed_ring = 1;
1758 break;
1759 }
1760 else{
1761 sc->lmc_rxq[i] = skb;
1762 }
1763 }
1764 else
1765 {
1766 skb = sc->lmc_rxq[i];
1767 }
1768
1769 skb->dev = sc->lmc_device;
1770
1771
1772 sc->lmc_rxring[i].status = 0x80000000;
1773
1774
1775 sc->lmc_rxring[i].length = skb_tailroom(skb);
1776
1777
1778
1779
1780 sc->lmc_rxring[i].buffer1 = virt_to_bus (skb->data);
1781
1782
1783 sc->lmc_rxring[i].buffer2 = virt_to_bus (&sc->lmc_rxring[i + 1]);
1784
1785 }
1786
1787
1788
1789
1790 if (i != 0) {
1791 sc->lmc_rxring[i - 1].length |= 0x02000000;
1792 sc->lmc_rxring[i - 1].buffer2 = virt_to_bus(&sc->lmc_rxring[0]);
1793 }
1794 LMC_CSR_WRITE (sc, csr_rxlist, virt_to_bus (sc->lmc_rxring));
1795
1796
1797 for (i = 0; i < LMC_TXDESCS; i++)
1798 {
1799 if (sc->lmc_txq[i] != NULL){
1800 dev_kfree_skb(sc->lmc_txq[i]);
1801 sc->lmc_device->stats.tx_dropped++;
1802 }
1803 sc->lmc_txq[i] = NULL;
1804 sc->lmc_txring[i].status = 0x00000000;
1805 sc->lmc_txring[i].buffer2 = virt_to_bus (&sc->lmc_txring[i + 1]);
1806 }
1807 sc->lmc_txring[i - 1].buffer2 = virt_to_bus (&sc->lmc_txring[0]);
1808 LMC_CSR_WRITE (sc, csr_txlist, virt_to_bus (sc->lmc_txring));
1809}
1810
1811void lmc_gpio_mkinput(lmc_softc_t * const sc, u32 bits)
1812{
1813 sc->lmc_gpio_io &= ~bits;
1814 LMC_CSR_WRITE(sc, csr_gp, TULIP_GP_PINSET | (sc->lmc_gpio_io));
1815}
1816
1817void lmc_gpio_mkoutput(lmc_softc_t * const sc, u32 bits)
1818{
1819 sc->lmc_gpio_io |= bits;
1820 LMC_CSR_WRITE(sc, csr_gp, TULIP_GP_PINSET | (sc->lmc_gpio_io));
1821}
1822
1823void lmc_led_on(lmc_softc_t * const sc, u32 led)
1824{
1825 if ((~sc->lmc_miireg16) & led)
1826 return;
1827
1828 sc->lmc_miireg16 &= ~led;
1829 lmc_mii_writereg(sc, 0, 16, sc->lmc_miireg16);
1830}
1831
1832void lmc_led_off(lmc_softc_t * const sc, u32 led)
1833{
1834 if (sc->lmc_miireg16 & led)
1835 return;
1836
1837 sc->lmc_miireg16 |= led;
1838 lmc_mii_writereg(sc, 0, 16, sc->lmc_miireg16);
1839}
1840
1841static void lmc_reset(lmc_softc_t * const sc)
1842{
1843 sc->lmc_miireg16 |= LMC_MII16_FIFO_RESET;
1844 lmc_mii_writereg(sc, 0, 16, sc->lmc_miireg16);
1845
1846 sc->lmc_miireg16 &= ~LMC_MII16_FIFO_RESET;
1847 lmc_mii_writereg(sc, 0, 16, sc->lmc_miireg16);
1848
1849
1850
1851
1852 lmc_gpio_mkoutput(sc, LMC_GEP_RESET);
1853
1854
1855
1856
1857
1858
1859 sc->lmc_gpio &= ~(LMC_GEP_RESET);
1860 LMC_CSR_WRITE(sc, csr_gp, sc->lmc_gpio);
1861
1862
1863
1864
1865 udelay(50);
1866
1867
1868
1869
1870 lmc_gpio_mkinput(sc, LMC_GEP_RESET);
1871
1872
1873
1874
1875 sc->lmc_media->init(sc);
1876
1877 sc->extra_stats.resetCount++;
1878}
1879
1880static void lmc_dec_reset(lmc_softc_t * const sc)
1881{
1882 u32 val;
1883
1884
1885
1886
1887 sc->lmc_intrmask = 0;
1888 LMC_CSR_WRITE(sc, csr_intr, sc->lmc_intrmask);
1889
1890
1891
1892
1893
1894
1895
1896 LMC_CSR_WRITE(sc, csr_busmode, TULIP_BUSMODE_SWRESET);
1897 udelay(25);
1898#ifdef __sparc__
1899 sc->lmc_busmode = LMC_CSR_READ(sc, csr_busmode);
1900 sc->lmc_busmode = 0x00100000;
1901 sc->lmc_busmode &= ~TULIP_BUSMODE_SWRESET;
1902 LMC_CSR_WRITE(sc, csr_busmode, sc->lmc_busmode);
1903#endif
1904 sc->lmc_cmdmode = LMC_CSR_READ(sc, csr_command);
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916 sc->lmc_cmdmode |= ( TULIP_CMD_PROMISCUOUS
1917 | TULIP_CMD_FULLDUPLEX
1918 | TULIP_CMD_PASSBADPKT
1919 | TULIP_CMD_NOHEARTBEAT
1920 | TULIP_CMD_PORTSELECT
1921 | TULIP_CMD_RECEIVEALL
1922 | TULIP_CMD_MUSTBEONE
1923 );
1924 sc->lmc_cmdmode &= ~( TULIP_CMD_OPERMODE
1925 | TULIP_CMD_THRESHOLDCTL
1926 | TULIP_CMD_STOREFWD
1927 | TULIP_CMD_TXTHRSHLDCTL
1928 );
1929
1930 LMC_CSR_WRITE(sc, csr_command, sc->lmc_cmdmode);
1931
1932
1933
1934
1935 val = LMC_CSR_READ(sc, csr_sia_general);
1936 val |= (TULIP_WATCHDOG_TXDISABLE | TULIP_WATCHDOG_RXDISABLE);
1937 LMC_CSR_WRITE(sc, csr_sia_general, val);
1938}
1939
1940static void lmc_initcsrs(lmc_softc_t * const sc, lmc_csrptr_t csr_base,
1941 size_t csr_size)
1942{
1943 sc->lmc_csrs.csr_busmode = csr_base + 0 * csr_size;
1944 sc->lmc_csrs.csr_txpoll = csr_base + 1 * csr_size;
1945 sc->lmc_csrs.csr_rxpoll = csr_base + 2 * csr_size;
1946 sc->lmc_csrs.csr_rxlist = csr_base + 3 * csr_size;
1947 sc->lmc_csrs.csr_txlist = csr_base + 4 * csr_size;
1948 sc->lmc_csrs.csr_status = csr_base + 5 * csr_size;
1949 sc->lmc_csrs.csr_command = csr_base + 6 * csr_size;
1950 sc->lmc_csrs.csr_intr = csr_base + 7 * csr_size;
1951 sc->lmc_csrs.csr_missed_frames = csr_base + 8 * csr_size;
1952 sc->lmc_csrs.csr_9 = csr_base + 9 * csr_size;
1953 sc->lmc_csrs.csr_10 = csr_base + 10 * csr_size;
1954 sc->lmc_csrs.csr_11 = csr_base + 11 * csr_size;
1955 sc->lmc_csrs.csr_12 = csr_base + 12 * csr_size;
1956 sc->lmc_csrs.csr_13 = csr_base + 13 * csr_size;
1957 sc->lmc_csrs.csr_14 = csr_base + 14 * csr_size;
1958 sc->lmc_csrs.csr_15 = csr_base + 15 * csr_size;
1959}
1960
1961static void lmc_driver_timeout(struct net_device *dev, unsigned int txqueue)
1962{
1963 lmc_softc_t *sc = dev_to_sc(dev);
1964 u32 csr6;
1965 unsigned long flags;
1966
1967 spin_lock_irqsave(&sc->lmc_lock, flags);
1968
1969 printk("%s: Xmitter busy|\n", dev->name);
1970
1971 sc->extra_stats.tx_tbusy_calls++;
1972 if (time_is_before_jiffies(dev_trans_start(dev) + TX_TIMEOUT))
1973 goto bug_out;
1974
1975
1976
1977
1978
1979
1980
1981
1982 LMC_EVENT_LOG(LMC_EVENT_XMTPRCTMO,
1983 LMC_CSR_READ (sc, csr_status),
1984 sc->extra_stats.tx_ProcTimeout);
1985
1986 lmc_running_reset (dev);
1987
1988 LMC_EVENT_LOG(LMC_EVENT_RESET1, LMC_CSR_READ (sc, csr_status), 0);
1989 LMC_EVENT_LOG(LMC_EVENT_RESET2,
1990 lmc_mii_readreg (sc, 0, 16),
1991 lmc_mii_readreg (sc, 0, 17));
1992
1993
1994 csr6 = LMC_CSR_READ (sc, csr_command);
1995 LMC_CSR_WRITE (sc, csr_command, csr6 | 0x0002);
1996 LMC_CSR_WRITE (sc, csr_command, csr6 | 0x2002);
1997
1998
1999 LMC_CSR_WRITE (sc, csr_txpoll, 0);
2000
2001 sc->lmc_device->stats.tx_errors++;
2002 sc->extra_stats.tx_ProcTimeout++;
2003
2004 netif_trans_update(dev);
2005
2006bug_out:
2007
2008 spin_unlock_irqrestore(&sc->lmc_lock, flags);
2009}
2010