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