blob: 5ea877221f463c9dbb8c45b386a548a07464b435 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001 /*
2 * Copyright (c) 1997-2000 LAN Media Corporation (LMC)
3 * All rights reserved. www.lanmedia.com
4 *
5 * This code is written by:
6 * Andrew Stanley-Jones (asj@cban.com)
7 * Rob Braun (bbraun@vix.com),
8 * Michael Graff (explorer@vix.com) and
9 * Matt Thomas (matt@3am-software.com).
10 *
11 * With Help By:
12 * David Boggs
13 * Ron Crane
14 * Alan Cox
15 *
16 * This software may be used and distributed according to the terms
17 * of the GNU General Public License version 2, incorporated herein by reference.
18 *
19 * Driver for the LanMedia LMC5200, LMC5245, LMC1000, LMC1200 cards.
20 *
21 * To control link specific options lmcctl is required.
22 * It can be obtained from ftp.lanmedia.com.
23 *
24 * Linux driver notes:
25 * Linux uses the device struct lmc_private to pass private information
26 * arround.
27 *
28 * The initialization portion of this driver (the lmc_reset() and the
29 * lmc_dec_reset() functions, as well as the led controls and the
30 * lmc_initcsrs() functions.
31 *
32 * The watchdog function runs every second and checks to see if
33 * we still have link, and that the timing source is what we expected
34 * it to be. If link is lost, the interface is marked down, and
35 * we no longer can transmit.
36 *
37 */
38
39/* $Id: lmc_main.c,v 1.36 2000/04/11 05:25:25 asj Exp $ */
40
41#include <linux/kernel.h>
42#include <linux/module.h>
43#include <linux/string.h>
44#include <linux/timer.h>
45#include <linux/ptrace.h>
46#include <linux/errno.h>
47#include <linux/ioport.h>
48#include <linux/slab.h>
49#include <linux/interrupt.h>
50#include <linux/pci.h>
51#include <linux/delay.h>
52#include <linux/init.h>
53#include <linux/in.h>
54#include <linux/if_arp.h>
55#include <linux/netdevice.h>
56#include <linux/etherdevice.h>
57#include <linux/skbuff.h>
58#include <linux/inet.h>
59#include <linux/bitops.h>
60
61#include <net/syncppp.h>
62
63#include <asm/processor.h> /* Processor type for cache alignment. */
64#include <asm/io.h>
65#include <asm/dma.h>
66#include <asm/uaccess.h>
67//#include <asm/spinlock.h>
68
69#define DRIVER_MAJOR_VERSION 1
70#define DRIVER_MINOR_VERSION 34
71#define DRIVER_SUB_VERSION 0
72
73#define DRIVER_VERSION ((DRIVER_MAJOR_VERSION << 8) + DRIVER_MINOR_VERSION)
74
75#include "lmc.h"
76#include "lmc_var.h"
77#include "lmc_ioctl.h"
78#include "lmc_debug.h"
79#include "lmc_proto.h"
80
81static int lmc_first_load = 0;
82
83static int LMC_PKT_BUF_SZ = 1542;
84
85static struct pci_device_id lmc_pci_tbl[] = {
86 { PCI_VENDOR_ID_DEC, PCI_DEVICE_ID_DEC_TULIP_FAST,
87 PCI_VENDOR_ID_LMC, PCI_ANY_ID },
88 { PCI_VENDOR_ID_DEC, PCI_DEVICE_ID_DEC_TULIP_FAST,
89 PCI_ANY_ID, PCI_VENDOR_ID_LMC },
90 { 0 }
91};
92
93MODULE_DEVICE_TABLE(pci, lmc_pci_tbl);
94MODULE_LICENSE("GPL");
95
96
97static int lmc_start_xmit(struct sk_buff *skb, struct net_device *dev);
98static int lmc_start_xmit(struct sk_buff *skb, struct net_device *dev);
99static int lmc_rx (struct net_device *dev);
100static int lmc_open(struct net_device *dev);
101static int lmc_close(struct net_device *dev);
102static struct net_device_stats *lmc_get_stats(struct net_device *dev);
David Howells7d12e782006-10-05 14:55:46 +0100103static irqreturn_t lmc_interrupt(int irq, void *dev_instance);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104static void lmc_initcsrs(lmc_softc_t * const sc, lmc_csrptr_t csr_base, size_t csr_size);
105static void lmc_softreset(lmc_softc_t * const);
106static void lmc_running_reset(struct net_device *dev);
107static int lmc_ifdown(struct net_device * const);
108static void lmc_watchdog(unsigned long data);
109static void lmc_reset(lmc_softc_t * const sc);
110static void lmc_dec_reset(lmc_softc_t * const sc);
111static void lmc_driver_timeout(struct net_device *dev);
112
113/*
114 * linux reserves 16 device specific IOCTLs. We call them
115 * LMCIOC* to control various bits of our world.
116 */
117int lmc_ioctl (struct net_device *dev, struct ifreq *ifr, int cmd) /*fold00*/
118{
119 lmc_softc_t *sc;
120 lmc_ctl_t ctl;
121 int ret;
122 u_int16_t regVal;
123 unsigned long flags;
124
125 struct sppp *sp;
126
127 ret = -EOPNOTSUPP;
128
129 sc = dev->priv;
130
131 lmc_trace(dev, "lmc_ioctl in");
132
133 /*
134 * Most functions mess with the structure
135 * Disable interrupts while we do the polling
136 */
137 spin_lock_irqsave(&sc->lmc_lock, flags);
138
139 switch (cmd) {
140 /*
141 * Return current driver state. Since we keep this up
142 * To date internally, just copy this out to the user.
143 */
144 case LMCIOCGINFO: /*fold01*/
145 if (copy_to_user(ifr->ifr_data, &sc->ictl, sizeof (lmc_ctl_t)))
146 return -EFAULT;
147 ret = 0;
148 break;
149
150 case LMCIOCSINFO: /*fold01*/
151 sp = &((struct ppp_device *) dev)->sppp;
152 if (!capable(CAP_NET_ADMIN)) {
153 ret = -EPERM;
154 break;
155 }
156
157 if(dev->flags & IFF_UP){
158 ret = -EBUSY;
159 break;
160 }
161
162 if (copy_from_user(&ctl, ifr->ifr_data, sizeof (lmc_ctl_t)))
163 return -EFAULT;
164
165 sc->lmc_media->set_status (sc, &ctl);
166
167 if(ctl.crc_length != sc->ictl.crc_length) {
168 sc->lmc_media->set_crc_length(sc, ctl.crc_length);
169 if (sc->ictl.crc_length == LMC_CTL_CRC_LENGTH_16)
170 sc->TxDescriptControlInit |= LMC_TDES_ADD_CRC_DISABLE;
171 else
172 sc->TxDescriptControlInit &= ~LMC_TDES_ADD_CRC_DISABLE;
173 }
174
175 if (ctl.keepalive_onoff == LMC_CTL_OFF)
176 sp->pp_flags &= ~PP_KEEPALIVE; /* Turn off */
177 else
178 sp->pp_flags |= PP_KEEPALIVE; /* Turn on */
179
180 ret = 0;
181 break;
182
183 case LMCIOCIFTYPE: /*fold01*/
184 {
185 u_int16_t old_type = sc->if_type;
186 u_int16_t new_type;
187
188 if (!capable(CAP_NET_ADMIN)) {
189 ret = -EPERM;
190 break;
191 }
192
193 if (copy_from_user(&new_type, ifr->ifr_data, sizeof(u_int16_t)))
194 return -EFAULT;
195
196
197 if (new_type == old_type)
198 {
199 ret = 0 ;
200 break; /* no change */
201 }
202
203 lmc_proto_close(sc);
204 lmc_proto_detach(sc);
205
206 sc->if_type = new_type;
207// lmc_proto_init(sc);
208 lmc_proto_attach(sc);
209 lmc_proto_open(sc);
210
211 ret = 0 ;
212 break ;
213 }
214
215 case LMCIOCGETXINFO: /*fold01*/
216 sc->lmc_xinfo.Magic0 = 0xBEEFCAFE;
217
218 sc->lmc_xinfo.PciCardType = sc->lmc_cardtype;
219 sc->lmc_xinfo.PciSlotNumber = 0;
220 sc->lmc_xinfo.DriverMajorVersion = DRIVER_MAJOR_VERSION;
221 sc->lmc_xinfo.DriverMinorVersion = DRIVER_MINOR_VERSION;
222 sc->lmc_xinfo.DriverSubVersion = DRIVER_SUB_VERSION;
223 sc->lmc_xinfo.XilinxRevisionNumber =
224 lmc_mii_readreg (sc, 0, 3) & 0xf;
225 sc->lmc_xinfo.MaxFrameSize = LMC_PKT_BUF_SZ;
226 sc->lmc_xinfo.link_status = sc->lmc_media->get_link_status (sc);
227 sc->lmc_xinfo.mii_reg16 = lmc_mii_readreg (sc, 0, 16);
228
229 sc->lmc_xinfo.Magic1 = 0xDEADBEEF;
230
231 if (copy_to_user(ifr->ifr_data, &sc->lmc_xinfo,
232 sizeof (struct lmc_xinfo)))
233 return -EFAULT;
234 ret = 0;
235
236 break;
237
238 case LMCIOCGETLMCSTATS: /*fold01*/
239 if (sc->lmc_cardtype == LMC_CARDTYPE_T1){
240 lmc_mii_writereg (sc, 0, 17, T1FRAMER_FERR_LSB);
241 sc->stats.framingBitErrorCount +=
242 lmc_mii_readreg (sc, 0, 18) & 0xff;
243 lmc_mii_writereg (sc, 0, 17, T1FRAMER_FERR_MSB);
244 sc->stats.framingBitErrorCount +=
245 (lmc_mii_readreg (sc, 0, 18) & 0xff) << 8;
246 lmc_mii_writereg (sc, 0, 17, T1FRAMER_LCV_LSB);
247 sc->stats.lineCodeViolationCount +=
248 lmc_mii_readreg (sc, 0, 18) & 0xff;
249 lmc_mii_writereg (sc, 0, 17, T1FRAMER_LCV_MSB);
250 sc->stats.lineCodeViolationCount +=
251 (lmc_mii_readreg (sc, 0, 18) & 0xff) << 8;
252 lmc_mii_writereg (sc, 0, 17, T1FRAMER_AERR);
253 regVal = lmc_mii_readreg (sc, 0, 18) & 0xff;
254
255 sc->stats.lossOfFrameCount +=
256 (regVal & T1FRAMER_LOF_MASK) >> 4;
257 sc->stats.changeOfFrameAlignmentCount +=
258 (regVal & T1FRAMER_COFA_MASK) >> 2;
259 sc->stats.severelyErroredFrameCount +=
260 regVal & T1FRAMER_SEF_MASK;
261 }
262
263 if (copy_to_user(ifr->ifr_data, &sc->stats,
264 sizeof (struct lmc_statistics)))
265 return -EFAULT;
266
267 ret = 0;
268 break;
269
270 case LMCIOCCLEARLMCSTATS: /*fold01*/
271 if (!capable(CAP_NET_ADMIN)){
272 ret = -EPERM;
273 break;
274 }
275
276 memset (&sc->stats, 0, sizeof (struct lmc_statistics));
277 sc->stats.check = STATCHECK;
278 sc->stats.version_size = (DRIVER_VERSION << 16) +
279 sizeof (struct lmc_statistics);
280 sc->stats.lmc_cardtype = sc->lmc_cardtype;
281 ret = 0;
282 break;
283
284 case LMCIOCSETCIRCUIT: /*fold01*/
285 if (!capable(CAP_NET_ADMIN)){
286 ret = -EPERM;
287 break;
288 }
289
290 if(dev->flags & IFF_UP){
291 ret = -EBUSY;
292 break;
293 }
294
295 if (copy_from_user(&ctl, ifr->ifr_data, sizeof (lmc_ctl_t)))
296 return -EFAULT;
297 sc->lmc_media->set_circuit_type(sc, ctl.circuit_type);
298 sc->ictl.circuit_type = ctl.circuit_type;
299 ret = 0;
300
301 break;
302
303 case LMCIOCRESET: /*fold01*/
304 if (!capable(CAP_NET_ADMIN)){
305 ret = -EPERM;
306 break;
307 }
308
309 /* Reset driver and bring back to current state */
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
316 ret = 0;
317 break;
318
319#ifdef DEBUG
320 case LMCIOCDUMPEVENTLOG:
321 if (copy_to_user(ifr->ifr_data, &lmcEventLogIndex, sizeof (u32)))
322 return -EFAULT;
323 if (copy_to_user(ifr->ifr_data + sizeof (u32), lmcEventLogBuf, sizeof (lmcEventLogBuf)))
324 return -EFAULT;
325
326 ret = 0;
327 break;
328#endif /* end ifdef _DBG_EVENTLOG */
329 case LMCIOCT1CONTROL: /*fold01*/
330 if (sc->lmc_cardtype != LMC_CARDTYPE_T1){
331 ret = -EOPNOTSUPP;
332 break;
333 }
334 break;
335 case LMCIOCXILINX: /*fold01*/
336 {
337 struct lmc_xilinx_control xc; /*fold02*/
338
339 if (!capable(CAP_NET_ADMIN)){
340 ret = -EPERM;
341 break;
342 }
343
344 /*
345 * Stop the xwitter whlie we restart the hardware
346 */
347 netif_stop_queue(dev);
348
349 if (copy_from_user(&xc, ifr->ifr_data, sizeof (struct lmc_xilinx_control)))
350 return -EFAULT;
351 switch(xc.command){
352 case lmc_xilinx_reset: /*fold02*/
353 {
354 u16 mii;
355 mii = lmc_mii_readreg (sc, 0, 16);
356
357 /*
358 * Make all of them 0 and make input
359 */
360 lmc_gpio_mkinput(sc, 0xff);
361
362 /*
363 * make the reset output
364 */
365 lmc_gpio_mkoutput(sc, LMC_GEP_RESET);
366
367 /*
368 * RESET low to force configuration. This also forces
369 * the transmitter clock to be internal, but we expect to reset
370 * that later anyway.
371 */
372
373 sc->lmc_gpio &= ~LMC_GEP_RESET;
374 LMC_CSR_WRITE(sc, csr_gp, sc->lmc_gpio);
375
376
377 /*
378 * hold for more than 10 microseconds
379 */
380 udelay(50);
381
382 sc->lmc_gpio |= LMC_GEP_RESET;
383 LMC_CSR_WRITE(sc, csr_gp, sc->lmc_gpio);
384
385
386 /*
387 * stop driving Xilinx-related signals
388 */
389 lmc_gpio_mkinput(sc, 0xff);
390
391 /* Reset the frammer hardware */
392 sc->lmc_media->set_link_status (sc, 1);
393 sc->lmc_media->set_status (sc, NULL);
394// lmc_softreset(sc);
395
396 {
397 int i;
398 for(i = 0; i < 5; i++){
399 lmc_led_on(sc, LMC_DS3_LED0);
400 mdelay(100);
401 lmc_led_off(sc, LMC_DS3_LED0);
402 lmc_led_on(sc, LMC_DS3_LED1);
403 mdelay(100);
404 lmc_led_off(sc, LMC_DS3_LED1);
405 lmc_led_on(sc, LMC_DS3_LED3);
406 mdelay(100);
407 lmc_led_off(sc, LMC_DS3_LED3);
408 lmc_led_on(sc, LMC_DS3_LED2);
409 mdelay(100);
410 lmc_led_off(sc, LMC_DS3_LED2);
411 }
412 }
413
414
415
416 ret = 0x0;
417
418 }
419
420 break;
421 case lmc_xilinx_load_prom: /*fold02*/
422 {
423 u16 mii;
424 int timeout = 500000;
425 mii = lmc_mii_readreg (sc, 0, 16);
426
427 /*
428 * Make all of them 0 and make input
429 */
430 lmc_gpio_mkinput(sc, 0xff);
431
432 /*
433 * make the reset output
434 */
435 lmc_gpio_mkoutput(sc, LMC_GEP_DP | LMC_GEP_RESET);
436
437 /*
438 * RESET low to force configuration. This also forces
439 * the transmitter clock to be internal, but we expect to reset
440 * that later anyway.
441 */
442
443 sc->lmc_gpio &= ~(LMC_GEP_RESET | LMC_GEP_DP);
444 LMC_CSR_WRITE(sc, csr_gp, sc->lmc_gpio);
445
446
447 /*
448 * hold for more than 10 microseconds
449 */
450 udelay(50);
451
452 sc->lmc_gpio |= LMC_GEP_DP | LMC_GEP_RESET;
453 LMC_CSR_WRITE(sc, csr_gp, sc->lmc_gpio);
454
455 /*
456 * busy wait for the chip to reset
457 */
458 while( (LMC_CSR_READ(sc, csr_gp) & LMC_GEP_INIT) == 0 &&
459 (timeout-- > 0))
460 ;
461
462
463 /*
464 * stop driving Xilinx-related signals
465 */
466 lmc_gpio_mkinput(sc, 0xff);
467
468 ret = 0x0;
469
470
471 break;
472
473 }
474
475 case lmc_xilinx_load: /*fold02*/
476 {
477 char *data;
478 int pos;
479 int timeout = 500000;
480
481 if(xc.data == 0x0){
482 ret = -EINVAL;
483 break;
484 }
485
486 data = kmalloc(xc.len, GFP_KERNEL);
487 if(data == 0x0){
488 printk(KERN_WARNING "%s: Failed to allocate memory for copy\n", dev->name);
489 ret = -ENOMEM;
490 break;
491 }
492
493 if(copy_from_user(data, xc.data, xc.len))
494 {
495 kfree(data);
496 ret = -ENOMEM;
497 break;
498 }
499
500 printk("%s: Starting load of data Len: %d at 0x%p == 0x%p\n", dev->name, xc.len, xc.data, data);
501
502 lmc_gpio_mkinput(sc, 0xff);
503
504 /*
505 * Clear the Xilinx and start prgramming from the DEC
506 */
507
508 /*
509 * Set ouput as:
510 * Reset: 0 (active)
511 * DP: 0 (active)
512 * Mode: 1
513 *
514 */
515 sc->lmc_gpio = 0x00;
516 sc->lmc_gpio &= ~LMC_GEP_DP;
517 sc->lmc_gpio &= ~LMC_GEP_RESET;
518 sc->lmc_gpio |= LMC_GEP_MODE;
519 LMC_CSR_WRITE(sc, csr_gp, sc->lmc_gpio);
520
521 lmc_gpio_mkoutput(sc, LMC_GEP_MODE | LMC_GEP_DP | LMC_GEP_RESET);
522
523 /*
524 * Wait at least 10 us 20 to be safe
525 */
526 udelay(50);
527
528 /*
529 * Clear reset and activate programming lines
530 * Reset: Input
531 * DP: Input
532 * Clock: Output
533 * Data: Output
534 * Mode: Output
535 */
536 lmc_gpio_mkinput(sc, LMC_GEP_DP | LMC_GEP_RESET);
537
538 /*
539 * Set LOAD, DATA, Clock to 1
540 */
541 sc->lmc_gpio = 0x00;
542 sc->lmc_gpio |= LMC_GEP_MODE;
543 sc->lmc_gpio |= LMC_GEP_DATA;
544 sc->lmc_gpio |= LMC_GEP_CLK;
545 LMC_CSR_WRITE(sc, csr_gp, sc->lmc_gpio);
546
547 lmc_gpio_mkoutput(sc, LMC_GEP_DATA | LMC_GEP_CLK | LMC_GEP_MODE );
548
549 /*
550 * busy wait for the chip to reset
551 */
552 while( (LMC_CSR_READ(sc, csr_gp) & LMC_GEP_INIT) == 0 &&
553 (timeout-- > 0))
554 ;
555
556 printk(KERN_DEBUG "%s: Waited %d for the Xilinx to clear it's memory\n", dev->name, 500000-timeout);
557
558 for(pos = 0; pos < xc.len; pos++){
559 switch(data[pos]){
560 case 0:
561 sc->lmc_gpio &= ~LMC_GEP_DATA; /* Data is 0 */
562 break;
563 case 1:
564 sc->lmc_gpio |= LMC_GEP_DATA; /* Data is 1 */
565 break;
566 default:
567 printk(KERN_WARNING "%s Bad data in xilinx programming data at %d, got %d wanted 0 or 1\n", dev->name, pos, data[pos]);
568 sc->lmc_gpio |= LMC_GEP_DATA; /* Assume it's 1 */
569 }
570 sc->lmc_gpio &= ~LMC_GEP_CLK; /* Clock to zero */
571 sc->lmc_gpio |= LMC_GEP_MODE;
572 LMC_CSR_WRITE(sc, csr_gp, sc->lmc_gpio);
573 udelay(1);
574
575 sc->lmc_gpio |= LMC_GEP_CLK; /* Put the clack back to one */
576 sc->lmc_gpio |= LMC_GEP_MODE;
577 LMC_CSR_WRITE(sc, csr_gp, sc->lmc_gpio);
578 udelay(1);
579 }
580 if((LMC_CSR_READ(sc, csr_gp) & LMC_GEP_INIT) == 0){
581 printk(KERN_WARNING "%s: Reprogramming FAILED. Needs to be reprogrammed. (corrupted data)\n", dev->name);
582 }
583 else if((LMC_CSR_READ(sc, csr_gp) & LMC_GEP_DP) == 0){
584 printk(KERN_WARNING "%s: Reprogramming FAILED. Needs to be reprogrammed. (done)\n", dev->name);
585 }
586 else {
587 printk(KERN_DEBUG "%s: Done reprogramming Xilinx, %d bits, good luck!\n", dev->name, pos);
588 }
589
590 lmc_gpio_mkinput(sc, 0xff);
591
592 sc->lmc_miireg16 |= LMC_MII16_FIFO_RESET;
593 lmc_mii_writereg(sc, 0, 16, sc->lmc_miireg16);
594
595 sc->lmc_miireg16 &= ~LMC_MII16_FIFO_RESET;
596 lmc_mii_writereg(sc, 0, 16, sc->lmc_miireg16);
597
598 kfree(data);
599
600 ret = 0;
601
602 break;
603 }
604 default: /*fold02*/
605 ret = -EBADE;
606 break;
607 }
608
609 netif_wake_queue(dev);
610 sc->lmc_txfull = 0;
611
612 }
613 break;
614 default: /*fold01*/
615 /* If we don't know what to do, give the protocol a shot. */
616 ret = lmc_proto_ioctl (sc, ifr, cmd);
617 break;
618 }
619
620 spin_unlock_irqrestore(&sc->lmc_lock, flags); /*fold01*/
621
622 lmc_trace(dev, "lmc_ioctl out");
623
624 return ret;
625}
626
627
628/* the watchdog process that cruises around */
629static void lmc_watchdog (unsigned long data) /*fold00*/
630{
631 struct net_device *dev = (struct net_device *) data;
632 lmc_softc_t *sc;
633 int link_status;
634 u_int32_t ticks;
635 unsigned long flags;
636
637 sc = dev->priv;
638
639 lmc_trace(dev, "lmc_watchdog in");
640
641 spin_lock_irqsave(&sc->lmc_lock, flags);
642
643 if(sc->check != 0xBEAFCAFE){
Alexey Dobriyan323579882006-01-15 02:12:54 +0100644 printk("LMC: Corrupt net_device struct, breaking out\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 spin_unlock_irqrestore(&sc->lmc_lock, flags);
646 return;
647 }
648
649
650 /* Make sure the tx jabber and rx watchdog are off,
651 * and the transmit and receive processes are running.
652 */
653
654 LMC_CSR_WRITE (sc, csr_15, 0x00000011);
655 sc->lmc_cmdmode |= TULIP_CMD_TXRUN | TULIP_CMD_RXRUN;
656 LMC_CSR_WRITE (sc, csr_command, sc->lmc_cmdmode);
657
658 if (sc->lmc_ok == 0)
659 goto kick_timer;
660
661 LMC_EVENT_LOG(LMC_EVENT_WATCHDOG, LMC_CSR_READ (sc, csr_status), lmc_mii_readreg (sc, 0, 16));
662
663 /* --- begin time out check -----------------------------------
664 * check for a transmit interrupt timeout
665 * Has the packet xmt vs xmt serviced threshold been exceeded */
666 if (sc->lmc_taint_tx == sc->lastlmc_taint_tx &&
667 sc->stats.tx_packets > sc->lasttx_packets &&
668 sc->tx_TimeoutInd == 0)
669 {
670
671 /* wait for the watchdog to come around again */
672 sc->tx_TimeoutInd = 1;
673 }
674 else if (sc->lmc_taint_tx == sc->lastlmc_taint_tx &&
675 sc->stats.tx_packets > sc->lasttx_packets &&
676 sc->tx_TimeoutInd)
677 {
678
679 LMC_EVENT_LOG(LMC_EVENT_XMTINTTMO, LMC_CSR_READ (sc, csr_status), 0);
680
681 sc->tx_TimeoutDisplay = 1;
682 sc->stats.tx_TimeoutCnt++;
683
684 /* DEC chip is stuck, hit it with a RESET!!!! */
685 lmc_running_reset (dev);
686
687
688 /* look at receive & transmit process state to make sure they are running */
689 LMC_EVENT_LOG(LMC_EVENT_RESET1, LMC_CSR_READ (sc, csr_status), 0);
690
691 /* look at: DSR - 02 for Reg 16
692 * CTS - 08
693 * DCD - 10
694 * RI - 20
695 * for Reg 17
696 */
697 LMC_EVENT_LOG(LMC_EVENT_RESET2, lmc_mii_readreg (sc, 0, 16), lmc_mii_readreg (sc, 0, 17));
698
699 /* reset the transmit timeout detection flag */
700 sc->tx_TimeoutInd = 0;
701 sc->lastlmc_taint_tx = sc->lmc_taint_tx;
702 sc->lasttx_packets = sc->stats.tx_packets;
703 }
704 else
705 {
706 sc->tx_TimeoutInd = 0;
707 sc->lastlmc_taint_tx = sc->lmc_taint_tx;
708 sc->lasttx_packets = sc->stats.tx_packets;
709 }
710
711 /* --- end time out check ----------------------------------- */
712
713
714 link_status = sc->lmc_media->get_link_status (sc);
715
716 /*
717 * hardware level link lost, but the interface is marked as up.
718 * Mark it as down.
719 */
720 if ((link_status == 0) && (sc->last_link_status != 0)) {
721 printk(KERN_WARNING "%s: hardware/physical link down\n", dev->name);
722 sc->last_link_status = 0;
723 /* lmc_reset (sc); Why reset??? The link can go down ok */
724
725 /* Inform the world that link has been lost */
7d17c1d2005-05-12 19:45:25 -0400726 netif_carrier_off(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727 }
728
729 /*
730 * hardware link is up, but the interface is marked as down.
731 * Bring it back up again.
732 */
733 if (link_status != 0 && sc->last_link_status == 0) {
734 printk(KERN_WARNING "%s: hardware/physical link up\n", dev->name);
735 sc->last_link_status = 1;
736 /* lmc_reset (sc); Again why reset??? */
737
738 /* Inform the world that link protocol is back up. */
7d17c1d2005-05-12 19:45:25 -0400739 netif_carrier_on(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740
741 /* Now we have to tell the syncppp that we had an outage
742 * and that it should deal. Calling sppp_reopen here
743 * should do the trick, but we may have to call sppp_close
744 * when the link goes down, and call sppp_open here.
745 * Subject to more testing.
746 * --bbraun
747 */
748
749 lmc_proto_reopen(sc);
750
751 }
752
753 /* Call media specific watchdog functions */
754 sc->lmc_media->watchdog(sc);
755
756 /*
757 * Poke the transmitter to make sure it
758 * never stops, even if we run out of mem
759 */
760 LMC_CSR_WRITE(sc, csr_rxpoll, 0);
761
762 /*
763 * Check for code that failed
764 * and try and fix it as appropriate
765 */
766 if(sc->failed_ring == 1){
767 /*
768 * Failed to setup the recv/xmit rin
769 * Try again
770 */
771 sc->failed_ring = 0;
772 lmc_softreset(sc);
773 }
774 if(sc->failed_recv_alloc == 1){
775 /*
776 * We failed to alloc mem in the
777 * interrupt handler, go through the rings
778 * and rebuild them
779 */
780 sc->failed_recv_alloc = 0;
781 lmc_softreset(sc);
782 }
783
784
785 /*
786 * remember the timer value
787 */
788kick_timer:
789
790 ticks = LMC_CSR_READ (sc, csr_gp_timer);
791 LMC_CSR_WRITE (sc, csr_gp_timer, 0xffffffffUL);
792 sc->ictl.ticks = 0x0000ffff - (ticks & 0x0000ffff);
793
794 /*
795 * restart this timer.
796 */
797 sc->timer.expires = jiffies + (HZ);
798 add_timer (&sc->timer);
799
800 spin_unlock_irqrestore(&sc->lmc_lock, flags);
801
802 lmc_trace(dev, "lmc_watchdog out");
803
804}
805
806static void lmc_setup(struct net_device * const dev) /*fold00*/
807{
808 lmc_trace(dev, "lmc_setup in");
809
810 dev->type = ARPHRD_HDLC;
811 dev->hard_start_xmit = lmc_start_xmit;
812 dev->open = lmc_open;
813 dev->stop = lmc_close;
814 dev->get_stats = lmc_get_stats;
815 dev->do_ioctl = lmc_ioctl;
816 dev->tx_timeout = lmc_driver_timeout;
817 dev->watchdog_timeo = (HZ); /* 1 second */
818
819 lmc_trace(dev, "lmc_setup out");
820}
821
822
823static int __devinit lmc_init_one(struct pci_dev *pdev,
824 const struct pci_device_id *ent)
825{
826 struct net_device *dev;
827 lmc_softc_t *sc;
828 u16 subdevice;
829 u_int16_t AdapModelNum;
830 int err = -ENOMEM;
831 static int cards_found;
832#ifndef GCOM
833 /* We name by type not by vendor */
834 static const char lmcname[] = "hdlc%d";
835#else
836 /*
837 * GCOM uses LMC vendor name so that clients can know which card
838 * to attach to.
839 */
840 static const char lmcname[] = "lmc%d";
841#endif
842
843
844 /*
845 * Allocate our own device structure
846 */
847 dev = alloc_netdev(sizeof(lmc_softc_t), lmcname, lmc_setup);
848 if (!dev) {
849 printk (KERN_ERR "lmc:alloc_netdev for device failed\n");
850 goto out1;
851 }
852
853 lmc_trace(dev, "lmc_init_one in");
854
855 err = pci_enable_device(pdev);
856 if (err) {
857 printk(KERN_ERR "lmc: pci enable failed:%d\n", err);
858 goto out2;
859 }
860
861 if (pci_request_regions(pdev, "lmc")) {
862 printk(KERN_ERR "lmc: pci_request_region failed\n");
863 err = -EIO;
864 goto out3;
865 }
866
867 pci_set_drvdata(pdev, dev);
868
869 if(lmc_first_load == 0){
870 printk(KERN_INFO "Lan Media Corporation WAN Driver Version %d.%d.%d\n",
871 DRIVER_MAJOR_VERSION, DRIVER_MINOR_VERSION,DRIVER_SUB_VERSION);
872 lmc_first_load = 1;
873 }
874
875 sc = dev->priv;
876 sc->lmc_device = dev;
877 sc->name = dev->name;
878
879 /* Initialize the sppp layer */
880 /* An ioctl can cause a subsequent detach for raw frame interface */
881 sc->if_type = LMC_PPP;
882 sc->check = 0xBEAFCAFE;
883 dev->base_addr = pci_resource_start(pdev, 0);
884 dev->irq = pdev->irq;
885
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886 SET_NETDEV_DEV(dev, &pdev->dev);
887
888 /*
889 * This will get the protocol layer ready and do any 1 time init's
890 * Must have a valid sc and dev structure
891 */
892 lmc_proto_init(sc);
893
894 lmc_proto_attach(sc);
895
896 /*
897 * Why were we changing this???
898 dev->tx_queue_len = 100;
899 */
900
901 /* Init the spin lock so can call it latter */
902
903 spin_lock_init(&sc->lmc_lock);
904 pci_set_master(pdev);
905
906 printk ("%s: detected at %lx, irq %d\n", dev->name,
907 dev->base_addr, dev->irq);
908
909 if (register_netdev (dev) != 0) {
910 printk (KERN_ERR "%s: register_netdev failed.\n", dev->name);
911 goto out4;
912 }
913
914 sc->lmc_cardtype = LMC_CARDTYPE_UNKNOWN;
915 sc->lmc_timing = LMC_CTL_CLOCK_SOURCE_EXT;
916
917 /*
918 *
919 * Check either the subvendor or the subdevice, some systems reverse
920 * the setting in the bois, seems to be version and arch dependent?
921 * Fix the error, exchange the two values
922 */
923 if ((subdevice = pdev->subsystem_device) == PCI_VENDOR_ID_LMC)
924 subdevice = pdev->subsystem_vendor;
925
926 switch (subdevice) {
927 case PCI_DEVICE_ID_LMC_HSSI:
928 printk ("%s: LMC HSSI\n", dev->name);
929 sc->lmc_cardtype = LMC_CARDTYPE_HSSI;
930 sc->lmc_media = &lmc_hssi_media;
931 break;
932 case PCI_DEVICE_ID_LMC_DS3:
933 printk ("%s: LMC DS3\n", dev->name);
934 sc->lmc_cardtype = LMC_CARDTYPE_DS3;
935 sc->lmc_media = &lmc_ds3_media;
936 break;
937 case PCI_DEVICE_ID_LMC_SSI:
938 printk ("%s: LMC SSI\n", dev->name);
939 sc->lmc_cardtype = LMC_CARDTYPE_SSI;
940 sc->lmc_media = &lmc_ssi_media;
941 break;
942 case PCI_DEVICE_ID_LMC_T1:
943 printk ("%s: LMC T1\n", dev->name);
944 sc->lmc_cardtype = LMC_CARDTYPE_T1;
945 sc->lmc_media = &lmc_t1_media;
946 break;
947 default:
948 printk (KERN_WARNING "%s: LMC UNKOWN CARD!\n", dev->name);
949 break;
950 }
951
952 lmc_initcsrs (sc, dev->base_addr, 8);
953
954 lmc_gpio_mkinput (sc, 0xff);
955 sc->lmc_gpio = 0; /* drive no signals yet */
956
957 sc->lmc_media->defaults (sc);
958
959 sc->lmc_media->set_link_status (sc, LMC_LINK_UP);
960
961 /* verify that the PCI Sub System ID matches the Adapter Model number
962 * from the MII register
963 */
964 AdapModelNum = (lmc_mii_readreg (sc, 0, 3) & 0x3f0) >> 4;
965
966 if ((AdapModelNum == LMC_ADAP_T1
967 && subdevice == PCI_DEVICE_ID_LMC_T1) || /* detect LMC1200 */
968 (AdapModelNum == LMC_ADAP_SSI
969 && subdevice == PCI_DEVICE_ID_LMC_SSI) || /* detect LMC1000 */
970 (AdapModelNum == LMC_ADAP_DS3
971 && subdevice == PCI_DEVICE_ID_LMC_DS3) || /* detect LMC5245 */
972 (AdapModelNum == LMC_ADAP_HSSI
973 && subdevice == PCI_DEVICE_ID_LMC_HSSI))
974 { /* detect LMC5200 */
975
976 }
977 else {
978 printk ("%s: Model number (%d) miscompare for PCI Subsystem ID = 0x%04x\n",
979 dev->name, AdapModelNum, subdevice);
980// return (NULL);
981 }
982 /*
983 * reset clock
984 */
985 LMC_CSR_WRITE (sc, csr_gp_timer, 0xFFFFFFFFUL);
986
987 sc->board_idx = cards_found++;
988 sc->stats.check = STATCHECK;
989 sc->stats.version_size = (DRIVER_VERSION << 16) +
990 sizeof (struct lmc_statistics);
991 sc->stats.lmc_cardtype = sc->lmc_cardtype;
992
993 sc->lmc_ok = 0;
994 sc->last_link_status = 0;
995
996 lmc_trace(dev, "lmc_init_one out");
997 return 0;
998
999 out4:
1000 lmc_proto_detach(sc);
1001 out3:
1002 if (pdev) {
1003 pci_release_regions(pdev);
1004 pci_set_drvdata(pdev, NULL);
1005 }
1006 out2:
1007 free_netdev(dev);
1008 out1:
1009 return err;
1010}
1011
1012/*
1013 * Called from pci when removing module.
1014 */
1015static void __devexit lmc_remove_one (struct pci_dev *pdev)
1016{
1017 struct net_device *dev = pci_get_drvdata(pdev);
1018
1019 if (dev) {
1020 lmc_softc_t *sc = dev->priv;
1021
1022 printk("%s: removing...\n", dev->name);
1023 lmc_proto_detach(sc);
1024 unregister_netdev(dev);
1025 free_netdev(dev);
1026 pci_release_regions(pdev);
1027 pci_disable_device(pdev);
1028 pci_set_drvdata(pdev, NULL);
1029 }
1030}
1031
1032/* After this is called, packets can be sent.
1033 * Does not initialize the addresses
1034 */
1035static int lmc_open (struct net_device *dev) /*fold00*/
1036{
1037 lmc_softc_t *sc = dev->priv;
1038
1039 lmc_trace(dev, "lmc_open in");
1040
1041 lmc_led_on(sc, LMC_DS3_LED0);
1042
1043 lmc_dec_reset (sc);
1044 lmc_reset (sc);
1045
1046 LMC_EVENT_LOG(LMC_EVENT_RESET1, LMC_CSR_READ (sc, csr_status), 0);
1047 LMC_EVENT_LOG(LMC_EVENT_RESET2,
1048 lmc_mii_readreg (sc, 0, 16),
1049 lmc_mii_readreg (sc, 0, 17));
1050
1051
1052 if (sc->lmc_ok){
1053 lmc_trace(dev, "lmc_open lmc_ok out");
1054 return (0);
1055 }
1056
1057 lmc_softreset (sc);
1058
1059 /* Since we have to use PCI bus, this should work on x86,alpha,ppc */
Thomas Gleixner1fb9df52006-07-01 19:29:39 -07001060 if (request_irq (dev->irq, &lmc_interrupt, IRQF_SHARED, dev->name, dev)){
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061 printk(KERN_WARNING "%s: could not get irq: %d\n", dev->name, dev->irq);
1062 lmc_trace(dev, "lmc_open irq failed out");
1063 return -EAGAIN;
1064 }
1065 sc->got_irq = 1;
1066
1067 /* Assert Terminal Active */
1068 sc->lmc_miireg16 |= LMC_MII16_LED_ALL;
1069 sc->lmc_media->set_link_status (sc, LMC_LINK_UP);
1070
1071 /*
1072 * reset to last state.
1073 */
1074 sc->lmc_media->set_status (sc, NULL);
1075
1076 /* setup default bits to be used in tulip_desc_t transmit descriptor
1077 * -baz */
1078 sc->TxDescriptControlInit = (
1079 LMC_TDES_INTERRUPT_ON_COMPLETION
1080 | LMC_TDES_FIRST_SEGMENT
1081 | LMC_TDES_LAST_SEGMENT
1082 | LMC_TDES_SECOND_ADDR_CHAINED
1083 | LMC_TDES_DISABLE_PADDING
1084 );
1085
1086 if (sc->ictl.crc_length == LMC_CTL_CRC_LENGTH_16) {
1087 /* disable 32 bit CRC generated by ASIC */
1088 sc->TxDescriptControlInit |= LMC_TDES_ADD_CRC_DISABLE;
1089 }
1090 sc->lmc_media->set_crc_length(sc, sc->ictl.crc_length);
1091 /* Acknoledge the Terminal Active and light LEDs */
1092
1093 /* dev->flags |= IFF_UP; */
1094
1095 lmc_proto_open(sc);
1096
1097 dev->do_ioctl = lmc_ioctl;
1098
1099
1100 netif_start_queue(dev);
1101
1102 sc->stats.tx_tbusy0++ ;
1103
1104 /*
1105 * select what interrupts we want to get
1106 */
1107 sc->lmc_intrmask = 0;
1108 /* Should be using the default interrupt mask defined in the .h file. */
1109 sc->lmc_intrmask |= (TULIP_STS_NORMALINTR
1110 | TULIP_STS_RXINTR
1111 | TULIP_STS_TXINTR
1112 | TULIP_STS_ABNRMLINTR
1113 | TULIP_STS_SYSERROR
1114 | TULIP_STS_TXSTOPPED
1115 | TULIP_STS_TXUNDERFLOW
1116 | TULIP_STS_RXSTOPPED
1117 | TULIP_STS_RXNOBUF
1118 );
1119 LMC_CSR_WRITE (sc, csr_intr, sc->lmc_intrmask);
1120
1121 sc->lmc_cmdmode |= TULIP_CMD_TXRUN;
1122 sc->lmc_cmdmode |= TULIP_CMD_RXRUN;
1123 LMC_CSR_WRITE (sc, csr_command, sc->lmc_cmdmode);
1124
1125 sc->lmc_ok = 1; /* Run watchdog */
1126
1127 /*
1128 * Set the if up now - pfb
1129 */
1130
1131 sc->last_link_status = 1;
1132
1133 /*
1134 * Setup a timer for the watchdog on probe, and start it running.
1135 * Since lmc_ok == 0, it will be a NOP for now.
1136 */
1137 init_timer (&sc->timer);
1138 sc->timer.expires = jiffies + HZ;
1139 sc->timer.data = (unsigned long) dev;
1140 sc->timer.function = &lmc_watchdog;
1141 add_timer (&sc->timer);
1142
1143 lmc_trace(dev, "lmc_open out");
1144
1145 return (0);
1146}
1147
1148/* Total reset to compensate for the AdTran DSU doing bad things
1149 * under heavy load
1150 */
1151
1152static void lmc_running_reset (struct net_device *dev) /*fold00*/
1153{
1154
1155 lmc_softc_t *sc = (lmc_softc_t *) dev->priv;
1156
1157 lmc_trace(dev, "lmc_runnig_reset in");
1158
1159 /* stop interrupts */
1160 /* Clear the interrupt mask */
1161 LMC_CSR_WRITE (sc, csr_intr, 0x00000000);
1162
1163 lmc_dec_reset (sc);
1164 lmc_reset (sc);
1165 lmc_softreset (sc);
1166 /* sc->lmc_miireg16 |= LMC_MII16_LED_ALL; */
1167 sc->lmc_media->set_link_status (sc, 1);
1168 sc->lmc_media->set_status (sc, NULL);
1169
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170 netif_wake_queue(dev);
1171
1172 sc->lmc_txfull = 0;
1173 sc->stats.tx_tbusy0++ ;
1174
1175 sc->lmc_intrmask = TULIP_DEFAULT_INTR_MASK;
1176 LMC_CSR_WRITE (sc, csr_intr, sc->lmc_intrmask);
1177
1178 sc->lmc_cmdmode |= (TULIP_CMD_TXRUN | TULIP_CMD_RXRUN);
1179 LMC_CSR_WRITE (sc, csr_command, sc->lmc_cmdmode);
1180
1181 lmc_trace(dev, "lmc_runnin_reset_out");
1182}
1183
1184
1185/* This is what is called when you ifconfig down a device.
1186 * This disables the timer for the watchdog and keepalives,
1187 * and disables the irq for dev.
1188 */
1189static int lmc_close (struct net_device *dev) /*fold00*/
1190{
1191 /* not calling release_region() as we should */
1192 lmc_softc_t *sc;
1193
1194 lmc_trace(dev, "lmc_close in");
1195
1196 sc = dev->priv;
1197 sc->lmc_ok = 0;
1198 sc->lmc_media->set_link_status (sc, 0);
1199 del_timer (&sc->timer);
1200 lmc_proto_close(sc);
1201 lmc_ifdown (dev);
1202
1203 lmc_trace(dev, "lmc_close out");
1204
1205 return 0;
1206}
1207
1208/* Ends the transfer of packets */
1209/* When the interface goes down, this is called */
1210static int lmc_ifdown (struct net_device *dev) /*fold00*/
1211{
1212 lmc_softc_t *sc = dev->priv;
1213 u32 csr6;
1214 int i;
1215
1216 lmc_trace(dev, "lmc_ifdown in");
1217
1218 /* Don't let anything else go on right now */
1219 // dev->start = 0;
1220 netif_stop_queue(dev);
1221 sc->stats.tx_tbusy1++ ;
1222
1223 /* stop interrupts */
1224 /* Clear the interrupt mask */
1225 LMC_CSR_WRITE (sc, csr_intr, 0x00000000);
1226
1227 /* Stop Tx and Rx on the chip */
1228 csr6 = LMC_CSR_READ (sc, csr_command);
1229 csr6 &= ~LMC_DEC_ST; /* Turn off the Transmission bit */
1230 csr6 &= ~LMC_DEC_SR; /* Turn off the Receive bit */
1231 LMC_CSR_WRITE (sc, csr_command, csr6);
1232
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233 sc->stats.rx_missed_errors +=
1234 LMC_CSR_READ (sc, csr_missed_frames) & 0xffff;
1235
1236 /* release the interrupt */
1237 if(sc->got_irq == 1){
1238 free_irq (dev->irq, dev);
1239 sc->got_irq = 0;
1240 }
1241
1242 /* free skbuffs in the Rx queue */
1243 for (i = 0; i < LMC_RXDESCS; i++)
1244 {
1245 struct sk_buff *skb = sc->lmc_rxq[i];
1246 sc->lmc_rxq[i] = NULL;
1247 sc->lmc_rxring[i].status = 0;
1248 sc->lmc_rxring[i].length = 0;
1249 sc->lmc_rxring[i].buffer1 = 0xDEADBEEF;
1250 if (skb != NULL)
1251 dev_kfree_skb(skb);
1252 sc->lmc_rxq[i] = NULL;
1253 }
1254
1255 for (i = 0; i < LMC_TXDESCS; i++)
1256 {
1257 if (sc->lmc_txq[i] != NULL)
1258 dev_kfree_skb(sc->lmc_txq[i]);
1259 sc->lmc_txq[i] = NULL;
1260 }
1261
1262 lmc_led_off (sc, LMC_MII16_LED_ALL);
1263
1264 netif_wake_queue(dev);
1265 sc->stats.tx_tbusy0++ ;
1266
1267 lmc_trace(dev, "lmc_ifdown out");
1268
1269 return 0;
1270}
1271
1272/* Interrupt handling routine. This will take an incoming packet, or clean
1273 * up after a trasmit.
1274 */
David Howells7d12e782006-10-05 14:55:46 +01001275static irqreturn_t lmc_interrupt (int irq, void *dev_instance) /*fold00*/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276{
1277 struct net_device *dev = (struct net_device *) dev_instance;
1278 lmc_softc_t *sc;
1279 u32 csr;
1280 int i;
1281 s32 stat;
1282 unsigned int badtx;
1283 u32 firstcsr;
1284 int max_work = LMC_RXDESCS;
1285 int handled = 0;
1286
1287 lmc_trace(dev, "lmc_interrupt in");
1288
1289 sc = dev->priv;
1290
1291 spin_lock(&sc->lmc_lock);
1292
1293 /*
1294 * Read the csr to find what interrupts we have (if any)
1295 */
1296 csr = LMC_CSR_READ (sc, csr_status);
1297
1298 /*
1299 * Make sure this is our interrupt
1300 */
1301 if ( ! (csr & sc->lmc_intrmask)) {
1302 goto lmc_int_fail_out;
1303 }
1304
1305 firstcsr = csr;
1306
1307 /* always go through this loop at least once */
1308 while (csr & sc->lmc_intrmask) {
1309 handled = 1;
1310
1311 /*
1312 * Clear interrupt bits, we handle all case below
1313 */
1314 LMC_CSR_WRITE (sc, csr_status, csr);
1315
1316 /*
1317 * One of
1318 * - Transmit process timed out CSR5<1>
1319 * - Transmit jabber timeout CSR5<3>
1320 * - Transmit underflow CSR5<5>
1321 * - Transmit Receiver buffer unavailable CSR5<7>
1322 * - Receive process stopped CSR5<8>
1323 * - Receive watchdog timeout CSR5<9>
1324 * - Early transmit interrupt CSR5<10>
1325 *
1326 * Is this really right? Should we do a running reset for jabber?
1327 * (being a WAN card and all)
1328 */
1329 if (csr & TULIP_STS_ABNRMLINTR){
1330 lmc_running_reset (dev);
1331 break;
1332 }
1333
1334 if (csr & TULIP_STS_RXINTR){
1335 lmc_trace(dev, "rx interrupt");
1336 lmc_rx (dev);
1337
1338 }
1339 if (csr & (TULIP_STS_TXINTR | TULIP_STS_TXNOBUF | TULIP_STS_TXSTOPPED)) {
1340
1341 int n_compl = 0 ;
1342 /* reset the transmit timeout detection flag -baz */
1343 sc->stats.tx_NoCompleteCnt = 0;
1344
1345 badtx = sc->lmc_taint_tx;
1346 i = badtx % LMC_TXDESCS;
1347
1348 while ((badtx < sc->lmc_next_tx)) {
1349 stat = sc->lmc_txring[i].status;
1350
1351 LMC_EVENT_LOG (LMC_EVENT_XMTINT, stat,
1352 sc->lmc_txring[i].length);
1353 /*
1354 * If bit 31 is 1 the tulip owns it break out of the loop
1355 */
1356 if (stat & 0x80000000)
1357 break;
1358
1359 n_compl++ ; /* i.e., have an empty slot in ring */
1360 /*
1361 * If we have no skbuff or have cleared it
1362 * Already continue to the next buffer
1363 */
1364 if (sc->lmc_txq[i] == NULL)
1365 continue;
1366
1367 /*
1368 * Check the total error summary to look for any errors
1369 */
1370 if (stat & 0x8000) {
1371 sc->stats.tx_errors++;
1372 if (stat & 0x4104)
1373 sc->stats.tx_aborted_errors++;
1374 if (stat & 0x0C00)
1375 sc->stats.tx_carrier_errors++;
1376 if (stat & 0x0200)
1377 sc->stats.tx_window_errors++;
1378 if (stat & 0x0002)
1379 sc->stats.tx_fifo_errors++;
1380 }
1381 else {
1382
1383 sc->stats.tx_bytes += sc->lmc_txring[i].length & 0x7ff;
1384
1385 sc->stats.tx_packets++;
1386 }
1387
1388 // dev_kfree_skb(sc->lmc_txq[i]);
1389 dev_kfree_skb_irq(sc->lmc_txq[i]);
1390 sc->lmc_txq[i] = NULL;
1391
1392 badtx++;
1393 i = badtx % LMC_TXDESCS;
1394 }
1395
1396 if (sc->lmc_next_tx - badtx > LMC_TXDESCS)
1397 {
1398 printk ("%s: out of sync pointer\n", dev->name);
1399 badtx += LMC_TXDESCS;
1400 }
1401 LMC_EVENT_LOG(LMC_EVENT_TBUSY0, n_compl, 0);
1402 sc->lmc_txfull = 0;
1403 netif_wake_queue(dev);
1404 sc->stats.tx_tbusy0++ ;
1405
1406
1407#ifdef DEBUG
1408 sc->stats.dirtyTx = badtx;
1409 sc->stats.lmc_next_tx = sc->lmc_next_tx;
1410 sc->stats.lmc_txfull = sc->lmc_txfull;
1411#endif
1412 sc->lmc_taint_tx = badtx;
1413
1414 /*
1415 * Why was there a break here???
1416 */
1417 } /* end handle transmit interrupt */
1418
1419 if (csr & TULIP_STS_SYSERROR) {
1420 u32 error;
1421 printk (KERN_WARNING "%s: system bus error csr: %#8.8x\n", dev->name, csr);
1422 error = csr>>23 & 0x7;
1423 switch(error){
1424 case 0x000:
1425 printk(KERN_WARNING "%s: Parity Fault (bad)\n", dev->name);
1426 break;
1427 case 0x001:
1428 printk(KERN_WARNING "%s: Master Abort (naughty)\n", dev->name);
1429 break;
1430 case 0x010:
1431 printk(KERN_WARNING "%s: Target Abort (not so naughty)\n", dev->name);
1432 break;
1433 default:
1434 printk(KERN_WARNING "%s: This bus error code was supposed to be reserved!\n", dev->name);
1435 }
1436 lmc_dec_reset (sc);
1437 lmc_reset (sc);
1438 LMC_EVENT_LOG(LMC_EVENT_RESET1, LMC_CSR_READ (sc, csr_status), 0);
1439 LMC_EVENT_LOG(LMC_EVENT_RESET2,
1440 lmc_mii_readreg (sc, 0, 16),
1441 lmc_mii_readreg (sc, 0, 17));
1442
1443 }
1444
1445
1446 if(max_work-- <= 0)
1447 break;
1448
1449 /*
1450 * Get current csr status to make sure
1451 * we've cleared all interrupts
1452 */
1453 csr = LMC_CSR_READ (sc, csr_status);
1454 } /* end interrupt loop */
1455 LMC_EVENT_LOG(LMC_EVENT_INT, firstcsr, csr);
1456
1457lmc_int_fail_out:
1458
1459 spin_unlock(&sc->lmc_lock);
1460
1461 lmc_trace(dev, "lmc_interrupt out");
1462 return IRQ_RETVAL(handled);
1463}
1464
1465static int lmc_start_xmit (struct sk_buff *skb, struct net_device *dev) /*fold00*/
1466{
1467 lmc_softc_t *sc;
1468 u32 flag;
1469 int entry;
1470 int ret = 0;
1471 unsigned long flags;
1472
1473 lmc_trace(dev, "lmc_start_xmit in");
1474
1475 sc = dev->priv;
1476
1477 spin_lock_irqsave(&sc->lmc_lock, flags);
1478
1479 /* normal path, tbusy known to be zero */
1480
1481 entry = sc->lmc_next_tx % LMC_TXDESCS;
1482
1483 sc->lmc_txq[entry] = skb;
1484 sc->lmc_txring[entry].buffer1 = virt_to_bus (skb->data);
1485
1486 LMC_CONSOLE_LOG("xmit", skb->data, skb->len);
1487
1488#ifndef GCOM
1489 /* If the queue is less than half full, don't interrupt */
1490 if (sc->lmc_next_tx - sc->lmc_taint_tx < LMC_TXDESCS / 2)
1491 {
1492 /* Do not interrupt on completion of this packet */
1493 flag = 0x60000000;
1494 netif_wake_queue(dev);
1495 }
1496 else if (sc->lmc_next_tx - sc->lmc_taint_tx == LMC_TXDESCS / 2)
1497 {
1498 /* This generates an interrupt on completion of this packet */
1499 flag = 0xe0000000;
1500 netif_wake_queue(dev);
1501 }
1502 else if (sc->lmc_next_tx - sc->lmc_taint_tx < LMC_TXDESCS - 1)
1503 {
1504 /* Do not interrupt on completion of this packet */
1505 flag = 0x60000000;
1506 netif_wake_queue(dev);
1507 }
1508 else
1509 {
1510 /* This generates an interrupt on completion of this packet */
1511 flag = 0xe0000000;
1512 sc->lmc_txfull = 1;
1513 netif_stop_queue(dev);
1514 }
1515#else
1516 flag = LMC_TDES_INTERRUPT_ON_COMPLETION;
1517
1518 if (sc->lmc_next_tx - sc->lmc_taint_tx >= LMC_TXDESCS - 1)
1519 { /* ring full, go busy */
1520 sc->lmc_txfull = 1;
1521 netif_stop_queue(dev);
1522 sc->stats.tx_tbusy1++ ;
1523 LMC_EVENT_LOG(LMC_EVENT_TBUSY1, entry, 0);
1524 }
1525#endif
1526
1527
1528 if (entry == LMC_TXDESCS - 1) /* last descriptor in ring */
1529 flag |= LMC_TDES_END_OF_RING; /* flag as such for Tulip */
1530
1531 /* don't pad small packets either */
1532 flag = sc->lmc_txring[entry].length = (skb->len) | flag |
1533 sc->TxDescriptControlInit;
1534
1535 /* set the transmit timeout flag to be checked in
1536 * the watchdog timer handler. -baz
1537 */
1538
1539 sc->stats.tx_NoCompleteCnt++;
1540 sc->lmc_next_tx++;
1541
1542 /* give ownership to the chip */
1543 LMC_EVENT_LOG(LMC_EVENT_XMT, flag, entry);
1544 sc->lmc_txring[entry].status = 0x80000000;
1545
1546 /* send now! */
1547 LMC_CSR_WRITE (sc, csr_txpoll, 0);
1548
1549 dev->trans_start = jiffies;
1550
1551 spin_unlock_irqrestore(&sc->lmc_lock, flags);
1552
1553 lmc_trace(dev, "lmc_start_xmit_out");
1554 return ret;
1555}
1556
1557
1558static int lmc_rx (struct net_device *dev) /*fold00*/
1559{
1560 lmc_softc_t *sc;
1561 int i;
1562 int rx_work_limit = LMC_RXDESCS;
1563 unsigned int next_rx;
1564 int rxIntLoopCnt; /* debug -baz */
1565 int localLengthErrCnt = 0;
1566 long stat;
1567 struct sk_buff *skb, *nsb;
1568 u16 len;
1569
1570 lmc_trace(dev, "lmc_rx in");
1571
1572 sc = dev->priv;
1573
1574 lmc_led_on(sc, LMC_DS3_LED3);
1575
1576 rxIntLoopCnt = 0; /* debug -baz */
1577
1578 i = sc->lmc_next_rx % LMC_RXDESCS;
1579 next_rx = sc->lmc_next_rx;
1580
1581 while (((stat = sc->lmc_rxring[i].status) & LMC_RDES_OWN_BIT) != DESC_OWNED_BY_DC21X4)
1582 {
1583 rxIntLoopCnt++; /* debug -baz */
1584 len = ((stat & LMC_RDES_FRAME_LENGTH) >> RDES_FRAME_LENGTH_BIT_NUMBER);
1585 if ((stat & 0x0300) != 0x0300) { /* Check first segment and last segment */
1586 if ((stat & 0x0000ffff) != 0x7fff) {
1587 /* Oversized frame */
1588 sc->stats.rx_length_errors++;
1589 goto skip_packet;
1590 }
1591 }
1592
1593 if(stat & 0x00000008){ /* Catch a dribbling bit error */
1594 sc->stats.rx_errors++;
1595 sc->stats.rx_frame_errors++;
1596 goto skip_packet;
1597 }
1598
1599
1600 if(stat & 0x00000004){ /* Catch a CRC error by the Xilinx */
1601 sc->stats.rx_errors++;
1602 sc->stats.rx_crc_errors++;
1603 goto skip_packet;
1604 }
1605
1606
1607 if (len > LMC_PKT_BUF_SZ){
1608 sc->stats.rx_length_errors++;
1609 localLengthErrCnt++;
1610 goto skip_packet;
1611 }
1612
1613 if (len < sc->lmc_crcSize + 2) {
1614 sc->stats.rx_length_errors++;
1615 sc->stats.rx_SmallPktCnt++;
1616 localLengthErrCnt++;
1617 goto skip_packet;
1618 }
1619
1620 if(stat & 0x00004000){
1621 printk(KERN_WARNING "%s: Receiver descriptor error, receiver out of sync?\n", dev->name);
1622 }
1623
1624 len -= sc->lmc_crcSize;
1625
1626 skb = sc->lmc_rxq[i];
1627
1628 /*
1629 * We ran out of memory at some point
1630 * just allocate an skb buff and continue.
1631 */
1632
1633 if(skb == 0x0){
1634 nsb = dev_alloc_skb (LMC_PKT_BUF_SZ + 2);
1635 if (nsb) {
1636 sc->lmc_rxq[i] = nsb;
1637 nsb->dev = dev;
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -07001638 sc->lmc_rxring[i].buffer1 = virt_to_bus(skb_tail_pointer(nsb));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001639 }
1640 sc->failed_recv_alloc = 1;
1641 goto skip_packet;
1642 }
1643
1644 dev->last_rx = jiffies;
1645 sc->stats.rx_packets++;
1646 sc->stats.rx_bytes += len;
1647
1648 LMC_CONSOLE_LOG("recv", skb->data, len);
1649
1650 /*
1651 * I'm not sure of the sanity of this
1652 * Packets could be arriving at a constant
1653 * 44.210mbits/sec and we're going to copy
1654 * them into a new buffer??
1655 */
1656
1657 if(len > (LMC_MTU - (LMC_MTU>>2))){ /* len > LMC_MTU * 0.75 */
1658 /*
1659 * If it's a large packet don't copy it just hand it up
1660 */
1661 give_it_anyways:
1662
1663 sc->lmc_rxq[i] = NULL;
1664 sc->lmc_rxring[i].buffer1 = 0x0;
1665
1666 skb_put (skb, len);
1667 skb->protocol = lmc_proto_type(sc, skb);
1668 skb->protocol = htons(ETH_P_WAN_PPP);
Arnaldo Carvalho de Melo459a98e2007-03-19 15:30:44 -07001669 skb_reset_mac_header(skb);
Arnaldo Carvalho de Meloc1d2bbe2007-04-10 20:45:18 -07001670 /* skb_reset_network_header(skb); */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001671 skb->dev = dev;
1672 lmc_proto_netif(sc, skb);
1673
1674 /*
1675 * This skb will be destroyed by the upper layers, make a new one
1676 */
1677 nsb = dev_alloc_skb (LMC_PKT_BUF_SZ + 2);
1678 if (nsb) {
1679 sc->lmc_rxq[i] = nsb;
1680 nsb->dev = dev;
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -07001681 sc->lmc_rxring[i].buffer1 = virt_to_bus(skb_tail_pointer(nsb));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001682 /* Transferred to 21140 below */
1683 }
1684 else {
1685 /*
1686 * We've run out of memory, stop trying to allocate
1687 * memory and exit the interrupt handler
1688 *
1689 * The chip may run out of receivers and stop
1690 * in which care we'll try to allocate the buffer
1691 * again. (once a second)
1692 */
1693 sc->stats.rx_BuffAllocErr++;
1694 LMC_EVENT_LOG(LMC_EVENT_RCVINT, stat, len);
1695 sc->failed_recv_alloc = 1;
1696 goto skip_out_of_mem;
1697 }
1698 }
1699 else {
1700 nsb = dev_alloc_skb(len);
1701 if(!nsb) {
1702 goto give_it_anyways;
1703 }
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001704 skb_copy_from_linear_data(skb, skb_put(nsb, len), len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001705
1706 nsb->protocol = lmc_proto_type(sc, skb);
Arnaldo Carvalho de Melo459a98e2007-03-19 15:30:44 -07001707 skb_reset_mac_header(nsb);
Arnaldo Carvalho de Meloc1d2bbe2007-04-10 20:45:18 -07001708 /* skb_reset_network_header(nsb); */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001709 nsb->dev = dev;
1710 lmc_proto_netif(sc, nsb);
1711 }
1712
1713 skip_packet:
1714 LMC_EVENT_LOG(LMC_EVENT_RCVINT, stat, len);
1715 sc->lmc_rxring[i].status = DESC_OWNED_BY_DC21X4;
1716
1717 sc->lmc_next_rx++;
1718 i = sc->lmc_next_rx % LMC_RXDESCS;
1719 rx_work_limit--;
1720 if (rx_work_limit < 0)
1721 break;
1722 }
1723
1724 /* detect condition for LMC1000 where DSU cable attaches and fills
1725 * descriptors with bogus packets
1726 *
1727 if (localLengthErrCnt > LMC_RXDESCS - 3) {
1728 sc->stats.rx_BadPktSurgeCnt++;
1729 LMC_EVENT_LOG(LMC_EVENT_BADPKTSURGE,
1730 localLengthErrCnt,
1731 sc->stats.rx_BadPktSurgeCnt);
1732 } */
1733
1734 /* save max count of receive descriptors serviced */
1735 if (rxIntLoopCnt > sc->stats.rxIntLoopCnt) {
1736 sc->stats.rxIntLoopCnt = rxIntLoopCnt; /* debug -baz */
1737 }
1738
1739#ifdef DEBUG
1740 if (rxIntLoopCnt == 0)
1741 {
1742 for (i = 0; i < LMC_RXDESCS; i++)
1743 {
1744 if ((sc->lmc_rxring[i].status & LMC_RDES_OWN_BIT)
1745 != DESC_OWNED_BY_DC21X4)
1746 {
1747 rxIntLoopCnt++;
1748 }
1749 }
1750 LMC_EVENT_LOG(LMC_EVENT_RCVEND, rxIntLoopCnt, 0);
1751 }
1752#endif
1753
1754
1755 lmc_led_off(sc, LMC_DS3_LED3);
1756
1757skip_out_of_mem:
1758
1759 lmc_trace(dev, "lmc_rx out");
1760
1761 return 0;
1762}
1763
1764static struct net_device_stats *lmc_get_stats (struct net_device *dev) /*fold00*/
1765{
1766 lmc_softc_t *sc = dev->priv;
1767 unsigned long flags;
1768
1769 lmc_trace(dev, "lmc_get_stats in");
1770
1771
1772 spin_lock_irqsave(&sc->lmc_lock, flags);
1773
1774 sc->stats.rx_missed_errors += LMC_CSR_READ (sc, csr_missed_frames) & 0xffff;
1775
1776 spin_unlock_irqrestore(&sc->lmc_lock, flags);
1777
1778 lmc_trace(dev, "lmc_get_stats out");
1779
1780 return (struct net_device_stats *) &sc->stats;
1781}
1782
1783static struct pci_driver lmc_driver = {
1784 .name = "lmc",
1785 .id_table = lmc_pci_tbl,
1786 .probe = lmc_init_one,
1787 .remove = __devexit_p(lmc_remove_one),
1788};
1789
1790static int __init init_lmc(void)
1791{
Jeff Garzik29917622006-08-19 17:48:59 -04001792 return pci_register_driver(&lmc_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001793}
1794
1795static void __exit exit_lmc(void)
1796{
1797 pci_unregister_driver(&lmc_driver);
1798}
1799
1800module_init(init_lmc);
1801module_exit(exit_lmc);
1802
1803unsigned lmc_mii_readreg (lmc_softc_t * const sc, unsigned devaddr, unsigned regno) /*fold00*/
1804{
1805 int i;
1806 int command = (0xf6 << 10) | (devaddr << 5) | regno;
1807 int retval = 0;
1808
1809 lmc_trace(sc->lmc_device, "lmc_mii_readreg in");
1810
1811 LMC_MII_SYNC (sc);
1812
1813 lmc_trace(sc->lmc_device, "lmc_mii_readreg: done sync");
1814
1815 for (i = 15; i >= 0; i--)
1816 {
1817 int dataval = (command & (1 << i)) ? 0x20000 : 0;
1818
1819 LMC_CSR_WRITE (sc, csr_9, dataval);
1820 lmc_delay ();
1821 /* __SLOW_DOWN_IO; */
1822 LMC_CSR_WRITE (sc, csr_9, dataval | 0x10000);
1823 lmc_delay ();
1824 /* __SLOW_DOWN_IO; */
1825 }
1826
1827 lmc_trace(sc->lmc_device, "lmc_mii_readreg: done1");
1828
1829 for (i = 19; i > 0; i--)
1830 {
1831 LMC_CSR_WRITE (sc, csr_9, 0x40000);
1832 lmc_delay ();
1833 /* __SLOW_DOWN_IO; */
1834 retval = (retval << 1) | ((LMC_CSR_READ (sc, csr_9) & 0x80000) ? 1 : 0);
1835 LMC_CSR_WRITE (sc, csr_9, 0x40000 | 0x10000);
1836 lmc_delay ();
1837 /* __SLOW_DOWN_IO; */
1838 }
1839
1840 lmc_trace(sc->lmc_device, "lmc_mii_readreg out");
1841
1842 return (retval >> 1) & 0xffff;
1843}
1844
1845void lmc_mii_writereg (lmc_softc_t * const sc, unsigned devaddr, unsigned regno, unsigned data) /*fold00*/
1846{
1847 int i = 32;
1848 int command = (0x5002 << 16) | (devaddr << 23) | (regno << 18) | data;
1849
1850 lmc_trace(sc->lmc_device, "lmc_mii_writereg in");
1851
1852 LMC_MII_SYNC (sc);
1853
1854 i = 31;
1855 while (i >= 0)
1856 {
1857 int datav;
1858
1859 if (command & (1 << i))
1860 datav = 0x20000;
1861 else
1862 datav = 0x00000;
1863
1864 LMC_CSR_WRITE (sc, csr_9, datav);
1865 lmc_delay ();
1866 /* __SLOW_DOWN_IO; */
1867 LMC_CSR_WRITE (sc, csr_9, (datav | 0x10000));
1868 lmc_delay ();
1869 /* __SLOW_DOWN_IO; */
1870 i--;
1871 }
1872
1873 i = 2;
1874 while (i > 0)
1875 {
1876 LMC_CSR_WRITE (sc, csr_9, 0x40000);
1877 lmc_delay ();
1878 /* __SLOW_DOWN_IO; */
1879 LMC_CSR_WRITE (sc, csr_9, 0x50000);
1880 lmc_delay ();
1881 /* __SLOW_DOWN_IO; */
1882 i--;
1883 }
1884
1885 lmc_trace(sc->lmc_device, "lmc_mii_writereg out");
1886}
1887
1888static void lmc_softreset (lmc_softc_t * const sc) /*fold00*/
1889{
1890 int i;
1891
1892 lmc_trace(sc->lmc_device, "lmc_softreset in");
1893
1894 /* Initialize the receive rings and buffers. */
1895 sc->lmc_txfull = 0;
1896 sc->lmc_next_rx = 0;
1897 sc->lmc_next_tx = 0;
1898 sc->lmc_taint_rx = 0;
1899 sc->lmc_taint_tx = 0;
1900
1901 /*
1902 * Setup each one of the receiver buffers
1903 * allocate an skbuff for each one, setup the descriptor table
1904 * and point each buffer at the next one
1905 */
1906
1907 for (i = 0; i < LMC_RXDESCS; i++)
1908 {
1909 struct sk_buff *skb;
1910
1911 if (sc->lmc_rxq[i] == NULL)
1912 {
1913 skb = dev_alloc_skb (LMC_PKT_BUF_SZ + 2);
1914 if(skb == NULL){
1915 printk(KERN_WARNING "%s: Failed to allocate receiver ring, will try again\n", sc->name);
1916 sc->failed_ring = 1;
1917 break;
1918 }
1919 else{
1920 sc->lmc_rxq[i] = skb;
1921 }
1922 }
1923 else
1924 {
1925 skb = sc->lmc_rxq[i];
1926 }
1927
1928 skb->dev = sc->lmc_device;
1929
1930 /* owned by 21140 */
1931 sc->lmc_rxring[i].status = 0x80000000;
1932
1933 /* used to be PKT_BUF_SZ now uses skb since we lose some to head room */
Arnaldo Carvalho de Melod004b8d2007-03-20 12:00:44 -03001934 sc->lmc_rxring[i].length = skb_tailroom(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001935
1936 /* use to be tail which is dumb since you're thinking why write
1937 * to the end of the packj,et but since there's nothing there tail == data
1938 */
1939 sc->lmc_rxring[i].buffer1 = virt_to_bus (skb->data);
1940
1941 /* This is fair since the structure is static and we have the next address */
1942 sc->lmc_rxring[i].buffer2 = virt_to_bus (&sc->lmc_rxring[i + 1]);
1943
1944 }
1945
1946 /*
1947 * Sets end of ring
1948 */
1949 sc->lmc_rxring[i - 1].length |= 0x02000000; /* Set end of buffers flag */
1950 sc->lmc_rxring[i - 1].buffer2 = virt_to_bus (&sc->lmc_rxring[0]); /* Point back to the start */
1951 LMC_CSR_WRITE (sc, csr_rxlist, virt_to_bus (sc->lmc_rxring)); /* write base address */
1952
1953
1954 /* Initialize the transmit rings and buffers */
1955 for (i = 0; i < LMC_TXDESCS; i++)
1956 {
1957 if (sc->lmc_txq[i] != NULL){ /* have buffer */
1958 dev_kfree_skb(sc->lmc_txq[i]); /* free it */
1959 sc->stats.tx_dropped++; /* We just dropped a packet */
1960 }
1961 sc->lmc_txq[i] = NULL;
1962 sc->lmc_txring[i].status = 0x00000000;
1963 sc->lmc_txring[i].buffer2 = virt_to_bus (&sc->lmc_txring[i + 1]);
1964 }
1965 sc->lmc_txring[i - 1].buffer2 = virt_to_bus (&sc->lmc_txring[0]);
1966 LMC_CSR_WRITE (sc, csr_txlist, virt_to_bus (sc->lmc_txring));
1967
1968 lmc_trace(sc->lmc_device, "lmc_softreset out");
1969}
1970
1971void lmc_gpio_mkinput(lmc_softc_t * const sc, u_int32_t bits) /*fold00*/
1972{
1973 lmc_trace(sc->lmc_device, "lmc_gpio_mkinput in");
1974 sc->lmc_gpio_io &= ~bits;
1975 LMC_CSR_WRITE(sc, csr_gp, TULIP_GP_PINSET | (sc->lmc_gpio_io));
1976 lmc_trace(sc->lmc_device, "lmc_gpio_mkinput out");
1977}
1978
1979void lmc_gpio_mkoutput(lmc_softc_t * const sc, u_int32_t bits) /*fold00*/
1980{
1981 lmc_trace(sc->lmc_device, "lmc_gpio_mkoutput in");
1982 sc->lmc_gpio_io |= bits;
1983 LMC_CSR_WRITE(sc, csr_gp, TULIP_GP_PINSET | (sc->lmc_gpio_io));
1984 lmc_trace(sc->lmc_device, "lmc_gpio_mkoutput out");
1985}
1986
1987void lmc_led_on(lmc_softc_t * const sc, u_int32_t led) /*fold00*/
1988{
1989 lmc_trace(sc->lmc_device, "lmc_led_on in");
1990 if((~sc->lmc_miireg16) & led){ /* Already on! */
1991 lmc_trace(sc->lmc_device, "lmc_led_on aon out");
1992 return;
1993 }
1994
1995 sc->lmc_miireg16 &= ~led;
1996 lmc_mii_writereg(sc, 0, 16, sc->lmc_miireg16);
1997 lmc_trace(sc->lmc_device, "lmc_led_on out");
1998}
1999
2000void lmc_led_off(lmc_softc_t * const sc, u_int32_t led) /*fold00*/
2001{
2002 lmc_trace(sc->lmc_device, "lmc_led_off in");
2003 if(sc->lmc_miireg16 & led){ /* Already set don't do anything */
2004 lmc_trace(sc->lmc_device, "lmc_led_off aoff out");
2005 return;
2006 }
2007
2008 sc->lmc_miireg16 |= led;
2009 lmc_mii_writereg(sc, 0, 16, sc->lmc_miireg16);
2010 lmc_trace(sc->lmc_device, "lmc_led_off out");
2011}
2012
2013static void lmc_reset(lmc_softc_t * const sc) /*fold00*/
2014{
2015 lmc_trace(sc->lmc_device, "lmc_reset in");
2016 sc->lmc_miireg16 |= LMC_MII16_FIFO_RESET;
2017 lmc_mii_writereg(sc, 0, 16, sc->lmc_miireg16);
2018
2019 sc->lmc_miireg16 &= ~LMC_MII16_FIFO_RESET;
2020 lmc_mii_writereg(sc, 0, 16, sc->lmc_miireg16);
2021
2022 /*
2023 * make some of the GPIO pins be outputs
2024 */
2025 lmc_gpio_mkoutput(sc, LMC_GEP_RESET);
2026
2027 /*
2028 * RESET low to force state reset. This also forces
2029 * the transmitter clock to be internal, but we expect to reset
2030 * that later anyway.
2031 */
2032 sc->lmc_gpio &= ~(LMC_GEP_RESET);
2033 LMC_CSR_WRITE(sc, csr_gp, sc->lmc_gpio);
2034
2035 /*
2036 * hold for more than 10 microseconds
2037 */
2038 udelay(50);
2039
2040 /*
2041 * stop driving Xilinx-related signals
2042 */
2043 lmc_gpio_mkinput(sc, LMC_GEP_RESET);
2044
2045 /*
2046 * Call media specific init routine
2047 */
2048 sc->lmc_media->init(sc);
2049
2050 sc->stats.resetCount++;
2051 lmc_trace(sc->lmc_device, "lmc_reset out");
2052}
2053
2054static void lmc_dec_reset(lmc_softc_t * const sc) /*fold00*/
2055{
2056 u_int32_t val;
2057 lmc_trace(sc->lmc_device, "lmc_dec_reset in");
2058
2059 /*
2060 * disable all interrupts
2061 */
2062 sc->lmc_intrmask = 0;
2063 LMC_CSR_WRITE(sc, csr_intr, sc->lmc_intrmask);
2064
2065 /*
2066 * Reset the chip with a software reset command.
2067 * Wait 10 microseconds (actually 50 PCI cycles but at
2068 * 33MHz that comes to two microseconds but wait a
2069 * bit longer anyways)
2070 */
2071 LMC_CSR_WRITE(sc, csr_busmode, TULIP_BUSMODE_SWRESET);
2072 udelay(25);
2073#ifdef __sparc__
2074 sc->lmc_busmode = LMC_CSR_READ(sc, csr_busmode);
2075 sc->lmc_busmode = 0x00100000;
2076 sc->lmc_busmode &= ~TULIP_BUSMODE_SWRESET;
2077 LMC_CSR_WRITE(sc, csr_busmode, sc->lmc_busmode);
2078#endif
2079 sc->lmc_cmdmode = LMC_CSR_READ(sc, csr_command);
2080
2081 /*
2082 * We want:
2083 * no ethernet address in frames we write
2084 * disable padding (txdesc, padding disable)
2085 * ignore runt frames (rdes0 bit 15)
2086 * no receiver watchdog or transmitter jabber timer
2087 * (csr15 bit 0,14 == 1)
2088 * if using 16-bit CRC, turn off CRC (trans desc, crc disable)
2089 */
2090
2091 sc->lmc_cmdmode |= ( TULIP_CMD_PROMISCUOUS
2092 | TULIP_CMD_FULLDUPLEX
2093 | TULIP_CMD_PASSBADPKT
2094 | TULIP_CMD_NOHEARTBEAT
2095 | TULIP_CMD_PORTSELECT
2096 | TULIP_CMD_RECEIVEALL
2097 | TULIP_CMD_MUSTBEONE
2098 );
2099 sc->lmc_cmdmode &= ~( TULIP_CMD_OPERMODE
2100 | TULIP_CMD_THRESHOLDCTL
2101 | TULIP_CMD_STOREFWD
2102 | TULIP_CMD_TXTHRSHLDCTL
2103 );
2104
2105 LMC_CSR_WRITE(sc, csr_command, sc->lmc_cmdmode);
2106
2107 /*
2108 * disable receiver watchdog and transmit jabber
2109 */
2110 val = LMC_CSR_READ(sc, csr_sia_general);
2111 val |= (TULIP_WATCHDOG_TXDISABLE | TULIP_WATCHDOG_RXDISABLE);
2112 LMC_CSR_WRITE(sc, csr_sia_general, val);
2113
2114 lmc_trace(sc->lmc_device, "lmc_dec_reset out");
2115}
2116
2117static void lmc_initcsrs(lmc_softc_t * const sc, lmc_csrptr_t csr_base, /*fold00*/
2118 size_t csr_size)
2119{
2120 lmc_trace(sc->lmc_device, "lmc_initcsrs in");
2121 sc->lmc_csrs.csr_busmode = csr_base + 0 * csr_size;
2122 sc->lmc_csrs.csr_txpoll = csr_base + 1 * csr_size;
2123 sc->lmc_csrs.csr_rxpoll = csr_base + 2 * csr_size;
2124 sc->lmc_csrs.csr_rxlist = csr_base + 3 * csr_size;
2125 sc->lmc_csrs.csr_txlist = csr_base + 4 * csr_size;
2126 sc->lmc_csrs.csr_status = csr_base + 5 * csr_size;
2127 sc->lmc_csrs.csr_command = csr_base + 6 * csr_size;
2128 sc->lmc_csrs.csr_intr = csr_base + 7 * csr_size;
2129 sc->lmc_csrs.csr_missed_frames = csr_base + 8 * csr_size;
2130 sc->lmc_csrs.csr_9 = csr_base + 9 * csr_size;
2131 sc->lmc_csrs.csr_10 = csr_base + 10 * csr_size;
2132 sc->lmc_csrs.csr_11 = csr_base + 11 * csr_size;
2133 sc->lmc_csrs.csr_12 = csr_base + 12 * csr_size;
2134 sc->lmc_csrs.csr_13 = csr_base + 13 * csr_size;
2135 sc->lmc_csrs.csr_14 = csr_base + 14 * csr_size;
2136 sc->lmc_csrs.csr_15 = csr_base + 15 * csr_size;
2137 lmc_trace(sc->lmc_device, "lmc_initcsrs out");
2138}
2139
2140static void lmc_driver_timeout(struct net_device *dev) { /*fold00*/
2141 lmc_softc_t *sc;
2142 u32 csr6;
2143 unsigned long flags;
2144
2145 lmc_trace(dev, "lmc_driver_timeout in");
2146
2147 sc = dev->priv;
2148
2149 spin_lock_irqsave(&sc->lmc_lock, flags);
2150
2151 printk("%s: Xmitter busy|\n", dev->name);
2152
2153 sc->stats.tx_tbusy_calls++ ;
2154 if (jiffies - dev->trans_start < TX_TIMEOUT) {
2155 goto bug_out;
2156 }
2157
2158 /*
2159 * Chip seems to have locked up
2160 * Reset it
2161 * This whips out all our decriptor
2162 * table and starts from scartch
2163 */
2164
2165 LMC_EVENT_LOG(LMC_EVENT_XMTPRCTMO,
2166 LMC_CSR_READ (sc, csr_status),
2167 sc->stats.tx_ProcTimeout);
2168
2169 lmc_running_reset (dev);
2170
2171 LMC_EVENT_LOG(LMC_EVENT_RESET1, LMC_CSR_READ (sc, csr_status), 0);
2172 LMC_EVENT_LOG(LMC_EVENT_RESET2,
2173 lmc_mii_readreg (sc, 0, 16),
2174 lmc_mii_readreg (sc, 0, 17));
2175
2176 /* restart the tx processes */
2177 csr6 = LMC_CSR_READ (sc, csr_command);
2178 LMC_CSR_WRITE (sc, csr_command, csr6 | 0x0002);
2179 LMC_CSR_WRITE (sc, csr_command, csr6 | 0x2002);
2180
2181 /* immediate transmit */
2182 LMC_CSR_WRITE (sc, csr_txpoll, 0);
2183
2184 sc->stats.tx_errors++;
2185 sc->stats.tx_ProcTimeout++; /* -baz */
2186
2187 dev->trans_start = jiffies;
2188
2189bug_out:
2190
2191 spin_unlock_irqrestore(&sc->lmc_lock, flags);
2192
2193 lmc_trace(dev, "lmc_driver_timout out");
2194
2195
2196}