blob: f80640f5a744f382ff14355caa60011199c74f93 [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
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02004 * Generic HDLC port Copyright (C) 2008 Krzysztof Halasa <khc@pm.waw.pl>
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 *
6 * This code is written by:
7 * Andrew Stanley-Jones (asj@cban.com)
8 * Rob Braun (bbraun@vix.com),
9 * Michael Graff (explorer@vix.com) and
10 * Matt Thomas (matt@3am-software.com).
11 *
12 * With Help By:
13 * David Boggs
14 * Ron Crane
15 * Alan Cox
16 *
17 * This software may be used and distributed according to the terms
18 * of the GNU General Public License version 2, incorporated herein by reference.
19 *
20 * Driver for the LanMedia LMC5200, LMC5245, LMC1000, LMC1200 cards.
21 *
22 * To control link specific options lmcctl is required.
23 * It can be obtained from ftp.lanmedia.com.
24 *
25 * Linux driver notes:
26 * Linux uses the device struct lmc_private to pass private information
27 * arround.
28 *
29 * The initialization portion of this driver (the lmc_reset() and the
30 * lmc_dec_reset() functions, as well as the led controls and the
31 * lmc_initcsrs() functions.
32 *
33 * The watchdog function runs every second and checks to see if
34 * we still have link, and that the timing source is what we expected
35 * it to be. If link is lost, the interface is marked down, and
36 * we no longer can transmit.
37 *
38 */
39
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#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>
Krzysztof Hałasa64bef762008-07-02 20:46:21 +020051#include <linux/hdlc.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070052#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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070060#include <asm/processor.h> /* Processor type for cache alignment. */
61#include <asm/io.h>
62#include <asm/dma.h>
63#include <asm/uaccess.h>
64//#include <asm/spinlock.h>
65
66#define DRIVER_MAJOR_VERSION 1
67#define DRIVER_MINOR_VERSION 34
68#define DRIVER_SUB_VERSION 0
69
70#define DRIVER_VERSION ((DRIVER_MAJOR_VERSION << 8) + DRIVER_MINOR_VERSION)
71
72#include "lmc.h"
73#include "lmc_var.h"
74#include "lmc_ioctl.h"
75#include "lmc_debug.h"
76#include "lmc_proto.h"
77
Linus Torvalds1da177e2005-04-16 15:20:36 -070078static int LMC_PKT_BUF_SZ = 1542;
79
80static struct pci_device_id lmc_pci_tbl[] = {
81 { PCI_VENDOR_ID_DEC, PCI_DEVICE_ID_DEC_TULIP_FAST,
82 PCI_VENDOR_ID_LMC, PCI_ANY_ID },
83 { PCI_VENDOR_ID_DEC, PCI_DEVICE_ID_DEC_TULIP_FAST,
84 PCI_ANY_ID, PCI_VENDOR_ID_LMC },
85 { 0 }
86};
87
88MODULE_DEVICE_TABLE(pci, lmc_pci_tbl);
Krzysztof Hałasa64bef762008-07-02 20:46:21 +020089MODULE_LICENSE("GPL v2");
Linus Torvalds1da177e2005-04-16 15:20:36 -070090
91
92static int lmc_start_xmit(struct sk_buff *skb, struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070093static 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);
David Howells7d12e782006-10-05 14:55:46 +010097static irqreturn_t lmc_interrupt(int irq, void *dev_instance);
Linus Torvalds1da177e2005-04-16 15:20:36 -070098static 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(unsigned long data);
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 * linux reserves 16 device specific IOCTLs. We call them
109 * LMCIOC* to control various bits of our world.
110 */
Krzysztof Hałasa64bef762008-07-02 20:46:21 +0200111int lmc_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) /*fold00*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112{
Krzysztof Hałasa64bef762008-07-02 20:46:21 +0200113 lmc_softc_t *sc = dev_to_sc(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 lmc_ctl_t ctl;
Krzysztof Hałasa64bef762008-07-02 20:46:21 +0200115 int ret = -EOPNOTSUPP;
116 u16 regVal;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 unsigned long flags;
118
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 lmc_trace(dev, "lmc_ioctl in");
120
121 /*
122 * Most functions mess with the structure
123 * Disable interrupts while we do the polling
124 */
125 spin_lock_irqsave(&sc->lmc_lock, flags);
126
127 switch (cmd) {
128 /*
129 * Return current driver state. Since we keep this up
130 * To date internally, just copy this out to the user.
131 */
132 case LMCIOCGINFO: /*fold01*/
Roel Kluine3376dc2007-10-30 01:11:46 -0700133 if (copy_to_user(ifr->ifr_data, &sc->ictl, sizeof(lmc_ctl_t)))
134 ret = -EFAULT;
135 else
136 ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 break;
138
139 case LMCIOCSINFO: /*fold01*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 if (!capable(CAP_NET_ADMIN)) {
141 ret = -EPERM;
142 break;
143 }
144
145 if(dev->flags & IFF_UP){
146 ret = -EBUSY;
147 break;
148 }
149
Roel Kluine3376dc2007-10-30 01:11:46 -0700150 if (copy_from_user(&ctl, ifr->ifr_data, sizeof(lmc_ctl_t))) {
151 ret = -EFAULT;
152 break;
153 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154
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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 ret = 0;
166 break;
167
168 case LMCIOCIFTYPE: /*fold01*/
169 {
Krzysztof Hałasa64bef762008-07-02 20:46:21 +0200170 u16 old_type = sc->if_type;
171 u16 new_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172
173 if (!capable(CAP_NET_ADMIN)) {
174 ret = -EPERM;
175 break;
176 }
177
Krzysztof Hałasa64bef762008-07-02 20:46:21 +0200178 if (copy_from_user(&new_type, ifr->ifr_data, sizeof(u16))) {
Roel Kluine3376dc2007-10-30 01:11:46 -0700179 ret = -EFAULT;
180 break;
181 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182
183
184 if (new_type == old_type)
185 {
186 ret = 0 ;
187 break; /* no change */
188 }
189
190 lmc_proto_close(sc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191
192 sc->if_type = new_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 lmc_proto_attach(sc);
Krzysztof Hałasa64bef762008-07-02 20:46:21 +0200194 ret = lmc_proto_open(sc);
195 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 }
197
198 case LMCIOCGETXINFO: /*fold01*/
199 sc->lmc_xinfo.Magic0 = 0xBEEFCAFE;
200
201 sc->lmc_xinfo.PciCardType = sc->lmc_cardtype;
202 sc->lmc_xinfo.PciSlotNumber = 0;
203 sc->lmc_xinfo.DriverMajorVersion = DRIVER_MAJOR_VERSION;
204 sc->lmc_xinfo.DriverMinorVersion = DRIVER_MINOR_VERSION;
205 sc->lmc_xinfo.DriverSubVersion = DRIVER_SUB_VERSION;
206 sc->lmc_xinfo.XilinxRevisionNumber =
207 lmc_mii_readreg (sc, 0, 3) & 0xf;
208 sc->lmc_xinfo.MaxFrameSize = LMC_PKT_BUF_SZ;
209 sc->lmc_xinfo.link_status = sc->lmc_media->get_link_status (sc);
210 sc->lmc_xinfo.mii_reg16 = lmc_mii_readreg (sc, 0, 16);
211
212 sc->lmc_xinfo.Magic1 = 0xDEADBEEF;
213
214 if (copy_to_user(ifr->ifr_data, &sc->lmc_xinfo,
Adrian Bunk5c415422007-10-30 15:34:34 -0700215 sizeof(struct lmc_xinfo)))
Roel Kluine3376dc2007-10-30 01:11:46 -0700216 ret = -EFAULT;
217 else
218 ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219
220 break;
221
Krzysztof Hałasa64bef762008-07-02 20:46:21 +0200222 case LMCIOCGETLMCSTATS:
223 if (sc->lmc_cardtype == LMC_CARDTYPE_T1) {
224 lmc_mii_writereg(sc, 0, 17, T1FRAMER_FERR_LSB);
225 sc->extra_stats.framingBitErrorCount +=
226 lmc_mii_readreg(sc, 0, 18) & 0xff;
227 lmc_mii_writereg(sc, 0, 17, T1FRAMER_FERR_MSB);
228 sc->extra_stats.framingBitErrorCount +=
229 (lmc_mii_readreg(sc, 0, 18) & 0xff) << 8;
230 lmc_mii_writereg(sc, 0, 17, T1FRAMER_LCV_LSB);
231 sc->extra_stats.lineCodeViolationCount +=
232 lmc_mii_readreg(sc, 0, 18) & 0xff;
233 lmc_mii_writereg(sc, 0, 17, T1FRAMER_LCV_MSB);
234 sc->extra_stats.lineCodeViolationCount +=
235 (lmc_mii_readreg(sc, 0, 18) & 0xff) << 8;
236 lmc_mii_writereg(sc, 0, 17, T1FRAMER_AERR);
237 regVal = lmc_mii_readreg(sc, 0, 18) & 0xff;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238
Krzysztof Hałasa64bef762008-07-02 20:46:21 +0200239 sc->extra_stats.lossOfFrameCount +=
240 (regVal & T1FRAMER_LOF_MASK) >> 4;
241 sc->extra_stats.changeOfFrameAlignmentCount +=
242 (regVal & T1FRAMER_COFA_MASK) >> 2;
243 sc->extra_stats.severelyErroredFrameCount +=
244 regVal & T1FRAMER_SEF_MASK;
245 }
246 if (copy_to_user(ifr->ifr_data, &sc->lmc_device->stats,
247 sizeof(sc->lmc_device->stats)) ||
248 copy_to_user(ifr->ifr_data + sizeof(sc->lmc_device->stats),
249 &sc->extra_stats, sizeof(sc->extra_stats)))
250 ret = -EFAULT;
251 else
252 ret = 0;
253 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254
Krzysztof Hałasa64bef762008-07-02 20:46:21 +0200255 case LMCIOCCLEARLMCSTATS:
256 if (!capable(CAP_NET_ADMIN)) {
257 ret = -EPERM;
258 break;
259 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260
Krzysztof Hałasa64bef762008-07-02 20:46:21 +0200261 memset(&sc->lmc_device->stats, 0, sizeof(sc->lmc_device->stats));
262 memset(&sc->extra_stats, 0, sizeof(sc->extra_stats));
263 sc->extra_stats.check = STATCHECK;
264 sc->extra_stats.version_size = (DRIVER_VERSION << 16) +
265 sizeof(sc->lmc_device->stats) + sizeof(sc->extra_stats);
266 sc->extra_stats.lmc_cardtype = sc->lmc_cardtype;
267 ret = 0;
268 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269
270 case LMCIOCSETCIRCUIT: /*fold01*/
271 if (!capable(CAP_NET_ADMIN)){
272 ret = -EPERM;
273 break;
274 }
275
276 if(dev->flags & IFF_UP){
277 ret = -EBUSY;
278 break;
279 }
280
Roel Kluine3376dc2007-10-30 01:11:46 -0700281 if (copy_from_user(&ctl, ifr->ifr_data, sizeof(lmc_ctl_t))) {
282 ret = -EFAULT;
283 break;
284 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 sc->lmc_media->set_circuit_type(sc, ctl.circuit_type);
286 sc->ictl.circuit_type = ctl.circuit_type;
287 ret = 0;
288
289 break;
290
291 case LMCIOCRESET: /*fold01*/
292 if (!capable(CAP_NET_ADMIN)){
293 ret = -EPERM;
294 break;
295 }
296
297 /* Reset driver and bring back to current state */
298 printk (" REG16 before reset +%04x\n", lmc_mii_readreg (sc, 0, 16));
299 lmc_running_reset (dev);
300 printk (" REG16 after reset +%04x\n", lmc_mii_readreg (sc, 0, 16));
301
302 LMC_EVENT_LOG(LMC_EVENT_FORCEDRESET, LMC_CSR_READ (sc, csr_status), lmc_mii_readreg (sc, 0, 16));
303
304 ret = 0;
305 break;
306
307#ifdef DEBUG
308 case LMCIOCDUMPEVENTLOG:
Roel Kluine3376dc2007-10-30 01:11:46 -0700309 if (copy_to_user(ifr->ifr_data, &lmcEventLogIndex, sizeof(u32))) {
310 ret = -EFAULT;
311 break;
312 }
Krzysztof Hałasa867240f2008-07-03 00:39:46 +0200313 if (copy_to_user(ifr->ifr_data + sizeof(u32), lmcEventLogBuf,
314 sizeof(lmcEventLogBuf)))
Roel Kluine3376dc2007-10-30 01:11:46 -0700315 ret = -EFAULT;
316 else
317 ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 break;
320#endif /* end ifdef _DBG_EVENTLOG */
321 case LMCIOCT1CONTROL: /*fold01*/
322 if (sc->lmc_cardtype != LMC_CARDTYPE_T1){
323 ret = -EOPNOTSUPP;
324 break;
325 }
326 break;
327 case LMCIOCXILINX: /*fold01*/
328 {
329 struct lmc_xilinx_control xc; /*fold02*/
330
331 if (!capable(CAP_NET_ADMIN)){
332 ret = -EPERM;
333 break;
334 }
335
336 /*
337 * Stop the xwitter whlie we restart the hardware
338 */
339 netif_stop_queue(dev);
340
Roel Kluine3376dc2007-10-30 01:11:46 -0700341 if (copy_from_user(&xc, ifr->ifr_data, sizeof(struct lmc_xilinx_control))) {
342 ret = -EFAULT;
343 break;
344 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 switch(xc.command){
346 case lmc_xilinx_reset: /*fold02*/
347 {
348 u16 mii;
349 mii = lmc_mii_readreg (sc, 0, 16);
350
351 /*
352 * Make all of them 0 and make input
353 */
354 lmc_gpio_mkinput(sc, 0xff);
355
356 /*
357 * make the reset output
358 */
359 lmc_gpio_mkoutput(sc, LMC_GEP_RESET);
360
361 /*
362 * RESET low to force configuration. This also forces
363 * the transmitter clock to be internal, but we expect to reset
364 * that later anyway.
365 */
366
367 sc->lmc_gpio &= ~LMC_GEP_RESET;
368 LMC_CSR_WRITE(sc, csr_gp, sc->lmc_gpio);
369
370
371 /*
372 * hold for more than 10 microseconds
373 */
374 udelay(50);
375
376 sc->lmc_gpio |= LMC_GEP_RESET;
377 LMC_CSR_WRITE(sc, csr_gp, sc->lmc_gpio);
378
379
380 /*
381 * stop driving Xilinx-related signals
382 */
383 lmc_gpio_mkinput(sc, 0xff);
384
385 /* Reset the frammer hardware */
386 sc->lmc_media->set_link_status (sc, 1);
387 sc->lmc_media->set_status (sc, NULL);
388// lmc_softreset(sc);
389
390 {
391 int i;
392 for(i = 0; i < 5; i++){
393 lmc_led_on(sc, LMC_DS3_LED0);
394 mdelay(100);
395 lmc_led_off(sc, LMC_DS3_LED0);
396 lmc_led_on(sc, LMC_DS3_LED1);
397 mdelay(100);
398 lmc_led_off(sc, LMC_DS3_LED1);
399 lmc_led_on(sc, LMC_DS3_LED3);
400 mdelay(100);
401 lmc_led_off(sc, LMC_DS3_LED3);
402 lmc_led_on(sc, LMC_DS3_LED2);
403 mdelay(100);
404 lmc_led_off(sc, LMC_DS3_LED2);
405 }
406 }
407
408
409
410 ret = 0x0;
411
412 }
413
414 break;
415 case lmc_xilinx_load_prom: /*fold02*/
416 {
417 u16 mii;
418 int timeout = 500000;
419 mii = lmc_mii_readreg (sc, 0, 16);
420
421 /*
422 * Make all of them 0 and make input
423 */
424 lmc_gpio_mkinput(sc, 0xff);
425
426 /*
427 * make the reset output
428 */
429 lmc_gpio_mkoutput(sc, LMC_GEP_DP | LMC_GEP_RESET);
430
431 /*
432 * RESET low to force configuration. This also forces
433 * the transmitter clock to be internal, but we expect to reset
434 * that later anyway.
435 */
436
437 sc->lmc_gpio &= ~(LMC_GEP_RESET | LMC_GEP_DP);
438 LMC_CSR_WRITE(sc, csr_gp, sc->lmc_gpio);
439
440
441 /*
442 * hold for more than 10 microseconds
443 */
444 udelay(50);
445
446 sc->lmc_gpio |= LMC_GEP_DP | LMC_GEP_RESET;
447 LMC_CSR_WRITE(sc, csr_gp, sc->lmc_gpio);
448
449 /*
450 * busy wait for the chip to reset
451 */
452 while( (LMC_CSR_READ(sc, csr_gp) & LMC_GEP_INIT) == 0 &&
453 (timeout-- > 0))
454 ;
455
456
457 /*
458 * stop driving Xilinx-related signals
459 */
460 lmc_gpio_mkinput(sc, 0xff);
461
462 ret = 0x0;
463
464
465 break;
466
467 }
468
469 case lmc_xilinx_load: /*fold02*/
470 {
471 char *data;
472 int pos;
473 int timeout = 500000;
474
Al Viro79ea13c2008-01-24 02:06:46 -0800475 if (!xc.data) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 ret = -EINVAL;
477 break;
478 }
479
480 data = kmalloc(xc.len, GFP_KERNEL);
Al Viro79ea13c2008-01-24 02:06:46 -0800481 if (!data) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 printk(KERN_WARNING "%s: Failed to allocate memory for copy\n", dev->name);
483 ret = -ENOMEM;
484 break;
485 }
486
487 if(copy_from_user(data, xc.data, xc.len))
488 {
489 kfree(data);
490 ret = -ENOMEM;
491 break;
492 }
493
494 printk("%s: Starting load of data Len: %d at 0x%p == 0x%p\n", dev->name, xc.len, xc.data, data);
495
496 lmc_gpio_mkinput(sc, 0xff);
497
498 /*
499 * Clear the Xilinx and start prgramming from the DEC
500 */
501
502 /*
503 * Set ouput as:
504 * Reset: 0 (active)
505 * DP: 0 (active)
506 * Mode: 1
507 *
508 */
509 sc->lmc_gpio = 0x00;
510 sc->lmc_gpio &= ~LMC_GEP_DP;
511 sc->lmc_gpio &= ~LMC_GEP_RESET;
512 sc->lmc_gpio |= LMC_GEP_MODE;
513 LMC_CSR_WRITE(sc, csr_gp, sc->lmc_gpio);
514
515 lmc_gpio_mkoutput(sc, LMC_GEP_MODE | LMC_GEP_DP | LMC_GEP_RESET);
516
517 /*
518 * Wait at least 10 us 20 to be safe
519 */
520 udelay(50);
521
522 /*
523 * Clear reset and activate programming lines
524 * Reset: Input
525 * DP: Input
526 * Clock: Output
527 * Data: Output
528 * Mode: Output
529 */
530 lmc_gpio_mkinput(sc, LMC_GEP_DP | LMC_GEP_RESET);
531
532 /*
533 * Set LOAD, DATA, Clock to 1
534 */
535 sc->lmc_gpio = 0x00;
536 sc->lmc_gpio |= LMC_GEP_MODE;
537 sc->lmc_gpio |= LMC_GEP_DATA;
538 sc->lmc_gpio |= LMC_GEP_CLK;
539 LMC_CSR_WRITE(sc, csr_gp, sc->lmc_gpio);
540
541 lmc_gpio_mkoutput(sc, LMC_GEP_DATA | LMC_GEP_CLK | LMC_GEP_MODE );
542
543 /*
544 * busy wait for the chip to reset
545 */
546 while( (LMC_CSR_READ(sc, csr_gp) & LMC_GEP_INIT) == 0 &&
547 (timeout-- > 0))
548 ;
549
550 printk(KERN_DEBUG "%s: Waited %d for the Xilinx to clear it's memory\n", dev->name, 500000-timeout);
551
552 for(pos = 0; pos < xc.len; pos++){
553 switch(data[pos]){
554 case 0:
555 sc->lmc_gpio &= ~LMC_GEP_DATA; /* Data is 0 */
556 break;
557 case 1:
558 sc->lmc_gpio |= LMC_GEP_DATA; /* Data is 1 */
559 break;
560 default:
561 printk(KERN_WARNING "%s Bad data in xilinx programming data at %d, got %d wanted 0 or 1\n", dev->name, pos, data[pos]);
562 sc->lmc_gpio |= LMC_GEP_DATA; /* Assume it's 1 */
563 }
564 sc->lmc_gpio &= ~LMC_GEP_CLK; /* Clock to zero */
565 sc->lmc_gpio |= LMC_GEP_MODE;
566 LMC_CSR_WRITE(sc, csr_gp, sc->lmc_gpio);
567 udelay(1);
568
569 sc->lmc_gpio |= LMC_GEP_CLK; /* Put the clack back to one */
570 sc->lmc_gpio |= LMC_GEP_MODE;
571 LMC_CSR_WRITE(sc, csr_gp, sc->lmc_gpio);
572 udelay(1);
573 }
574 if((LMC_CSR_READ(sc, csr_gp) & LMC_GEP_INIT) == 0){
575 printk(KERN_WARNING "%s: Reprogramming FAILED. Needs to be reprogrammed. (corrupted data)\n", dev->name);
576 }
577 else if((LMC_CSR_READ(sc, csr_gp) & LMC_GEP_DP) == 0){
578 printk(KERN_WARNING "%s: Reprogramming FAILED. Needs to be reprogrammed. (done)\n", dev->name);
579 }
580 else {
581 printk(KERN_DEBUG "%s: Done reprogramming Xilinx, %d bits, good luck!\n", dev->name, pos);
582 }
583
584 lmc_gpio_mkinput(sc, 0xff);
585
586 sc->lmc_miireg16 |= LMC_MII16_FIFO_RESET;
587 lmc_mii_writereg(sc, 0, 16, sc->lmc_miireg16);
588
589 sc->lmc_miireg16 &= ~LMC_MII16_FIFO_RESET;
590 lmc_mii_writereg(sc, 0, 16, sc->lmc_miireg16);
591
592 kfree(data);
593
594 ret = 0;
595
596 break;
597 }
598 default: /*fold02*/
599 ret = -EBADE;
600 break;
601 }
602
603 netif_wake_queue(dev);
604 sc->lmc_txfull = 0;
605
606 }
607 break;
608 default: /*fold01*/
609 /* If we don't know what to do, give the protocol a shot. */
610 ret = lmc_proto_ioctl (sc, ifr, cmd);
611 break;
612 }
613
614 spin_unlock_irqrestore(&sc->lmc_lock, flags); /*fold01*/
615
616 lmc_trace(dev, "lmc_ioctl out");
617
618 return ret;
619}
620
621
622/* the watchdog process that cruises around */
623static void lmc_watchdog (unsigned long data) /*fold00*/
624{
Krzysztof Hałasa64bef762008-07-02 20:46:21 +0200625 struct net_device *dev = (struct net_device *)data;
626 lmc_softc_t *sc = dev_to_sc(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 int link_status;
Krzysztof Hałasa867240f2008-07-03 00:39:46 +0200628 u32 ticks;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 unsigned long flags;
630
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 lmc_trace(dev, "lmc_watchdog in");
632
633 spin_lock_irqsave(&sc->lmc_lock, flags);
634
635 if(sc->check != 0xBEAFCAFE){
Alexey Dobriyan323579882006-01-15 02:12:54 +0100636 printk("LMC: Corrupt net_device struct, breaking out\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 spin_unlock_irqrestore(&sc->lmc_lock, flags);
638 return;
639 }
640
641
642 /* Make sure the tx jabber and rx watchdog are off,
643 * and the transmit and receive processes are running.
644 */
645
646 LMC_CSR_WRITE (sc, csr_15, 0x00000011);
647 sc->lmc_cmdmode |= TULIP_CMD_TXRUN | TULIP_CMD_RXRUN;
648 LMC_CSR_WRITE (sc, csr_command, sc->lmc_cmdmode);
649
650 if (sc->lmc_ok == 0)
651 goto kick_timer;
652
653 LMC_EVENT_LOG(LMC_EVENT_WATCHDOG, LMC_CSR_READ (sc, csr_status), lmc_mii_readreg (sc, 0, 16));
654
655 /* --- begin time out check -----------------------------------
656 * check for a transmit interrupt timeout
657 * Has the packet xmt vs xmt serviced threshold been exceeded */
658 if (sc->lmc_taint_tx == sc->lastlmc_taint_tx &&
Krzysztof Hałasa64bef762008-07-02 20:46:21 +0200659 sc->lmc_device->stats.tx_packets > sc->lasttx_packets &&
660 sc->tx_TimeoutInd == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 {
662
663 /* wait for the watchdog to come around again */
664 sc->tx_TimeoutInd = 1;
665 }
666 else if (sc->lmc_taint_tx == sc->lastlmc_taint_tx &&
Krzysztof Hałasa64bef762008-07-02 20:46:21 +0200667 sc->lmc_device->stats.tx_packets > sc->lasttx_packets &&
668 sc->tx_TimeoutInd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 {
670
671 LMC_EVENT_LOG(LMC_EVENT_XMTINTTMO, LMC_CSR_READ (sc, csr_status), 0);
672
673 sc->tx_TimeoutDisplay = 1;
Krzysztof Hałasa64bef762008-07-02 20:46:21 +0200674 sc->extra_stats.tx_TimeoutCnt++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675
676 /* DEC chip is stuck, hit it with a RESET!!!! */
677 lmc_running_reset (dev);
678
679
680 /* look at receive & transmit process state to make sure they are running */
681 LMC_EVENT_LOG(LMC_EVENT_RESET1, LMC_CSR_READ (sc, csr_status), 0);
682
683 /* look at: DSR - 02 for Reg 16
684 * CTS - 08
685 * DCD - 10
686 * RI - 20
687 * for Reg 17
688 */
689 LMC_EVENT_LOG(LMC_EVENT_RESET2, lmc_mii_readreg (sc, 0, 16), lmc_mii_readreg (sc, 0, 17));
690
691 /* reset the transmit timeout detection flag */
692 sc->tx_TimeoutInd = 0;
693 sc->lastlmc_taint_tx = sc->lmc_taint_tx;
Krzysztof Hałasa64bef762008-07-02 20:46:21 +0200694 sc->lasttx_packets = sc->lmc_device->stats.tx_packets;
695 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 sc->tx_TimeoutInd = 0;
697 sc->lastlmc_taint_tx = sc->lmc_taint_tx;
Krzysztof Hałasa64bef762008-07-02 20:46:21 +0200698 sc->lasttx_packets = sc->lmc_device->stats.tx_packets;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699 }
700
701 /* --- end time out check ----------------------------------- */
702
703
704 link_status = sc->lmc_media->get_link_status (sc);
705
706 /*
707 * hardware level link lost, but the interface is marked as up.
708 * Mark it as down.
709 */
710 if ((link_status == 0) && (sc->last_link_status != 0)) {
711 printk(KERN_WARNING "%s: hardware/physical link down\n", dev->name);
712 sc->last_link_status = 0;
713 /* lmc_reset (sc); Why reset??? The link can go down ok */
714
715 /* Inform the world that link has been lost */
7d17c1d2005-05-12 19:45:25 -0400716 netif_carrier_off(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717 }
718
719 /*
720 * hardware link is up, but the interface is marked as down.
721 * Bring it back up again.
722 */
723 if (link_status != 0 && sc->last_link_status == 0) {
724 printk(KERN_WARNING "%s: hardware/physical link up\n", dev->name);
725 sc->last_link_status = 1;
726 /* lmc_reset (sc); Again why reset??? */
727
7d17c1d2005-05-12 19:45:25 -0400728 netif_carrier_on(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729 }
730
731 /* Call media specific watchdog functions */
732 sc->lmc_media->watchdog(sc);
733
734 /*
735 * Poke the transmitter to make sure it
736 * never stops, even if we run out of mem
737 */
738 LMC_CSR_WRITE(sc, csr_rxpoll, 0);
739
740 /*
741 * Check for code that failed
742 * and try and fix it as appropriate
743 */
744 if(sc->failed_ring == 1){
745 /*
746 * Failed to setup the recv/xmit rin
747 * Try again
748 */
749 sc->failed_ring = 0;
750 lmc_softreset(sc);
751 }
752 if(sc->failed_recv_alloc == 1){
753 /*
754 * We failed to alloc mem in the
755 * interrupt handler, go through the rings
756 * and rebuild them
757 */
758 sc->failed_recv_alloc = 0;
759 lmc_softreset(sc);
760 }
761
762
763 /*
764 * remember the timer value
765 */
766kick_timer:
767
768 ticks = LMC_CSR_READ (sc, csr_gp_timer);
769 LMC_CSR_WRITE (sc, csr_gp_timer, 0xffffffffUL);
770 sc->ictl.ticks = 0x0000ffff - (ticks & 0x0000ffff);
771
772 /*
773 * restart this timer.
774 */
775 sc->timer.expires = jiffies + (HZ);
776 add_timer (&sc->timer);
777
778 spin_unlock_irqrestore(&sc->lmc_lock, flags);
779
780 lmc_trace(dev, "lmc_watchdog out");
781
782}
783
Krzysztof Hałasa64bef762008-07-02 20:46:21 +0200784static int lmc_attach(struct net_device *dev, unsigned short encoding,
785 unsigned short parity)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786{
Krzysztof Hałasa64bef762008-07-02 20:46:21 +0200787 if (encoding == ENCODING_NRZ && parity == PARITY_CRC16_PR1_CCITT)
788 return 0;
789 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790}
791
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792static int __devinit lmc_init_one(struct pci_dev *pdev,
793 const struct pci_device_id *ent)
794{
Krzysztof Hałasa64bef762008-07-02 20:46:21 +0200795 lmc_softc_t *sc;
796 struct net_device *dev;
797 u16 subdevice;
798 u16 AdapModelNum;
799 int err;
800 static int cards_found;
801
802 /* lmc_trace(dev, "lmc_init_one in"); */
803
804 err = pci_enable_device(pdev);
805 if (err) {
806 printk(KERN_ERR "lmc: pci enable failed: %d\n", err);
807 return err;
808 }
809
810 err = pci_request_regions(pdev, "lmc");
811 if (err) {
812 printk(KERN_ERR "lmc: pci_request_region failed\n");
813 goto err_req_io;
814 }
815
816 /*
817 * Allocate our own device structure
818 */
819 sc = kzalloc(sizeof(lmc_softc_t), GFP_KERNEL);
820 if (!sc) {
821 err = -ENOMEM;
822 goto err_kzalloc;
823 }
824
825 dev = alloc_hdlcdev(sc);
826 if (!dev) {
827 printk(KERN_ERR "lmc:alloc_netdev for device failed\n");
828 goto err_hdlcdev;
829 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830
831
Krzysztof Hałasa64bef762008-07-02 20:46:21 +0200832 dev->type = ARPHRD_HDLC;
833 dev_to_hdlc(dev)->xmit = lmc_start_xmit;
834 dev_to_hdlc(dev)->attach = lmc_attach;
835 dev->open = lmc_open;
836 dev->stop = lmc_close;
837 dev->get_stats = lmc_get_stats;
838 dev->do_ioctl = lmc_ioctl;
839 dev->tx_timeout = lmc_driver_timeout;
840 dev->watchdog_timeo = HZ; /* 1 second */
841 dev->tx_queue_len = 100;
842 sc->lmc_device = dev;
843 sc->name = dev->name;
844 sc->if_type = LMC_PPP;
845 sc->check = 0xBEAFCAFE;
846 dev->base_addr = pci_resource_start(pdev, 0);
847 dev->irq = pdev->irq;
848 pci_set_drvdata(pdev, dev);
849 SET_NETDEV_DEV(dev, &pdev->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850
Krzysztof Hałasa64bef762008-07-02 20:46:21 +0200851 /*
852 * This will get the protocol layer ready and do any 1 time init's
853 * Must have a valid sc and dev structure
854 */
855 lmc_proto_attach(sc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856
Krzysztof Hałasa64bef762008-07-02 20:46:21 +0200857 /* Init the spin lock so can call it latter */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858
Krzysztof Hałasa64bef762008-07-02 20:46:21 +0200859 spin_lock_init(&sc->lmc_lock);
860 pci_set_master(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861
Krzysztof Hałasa64bef762008-07-02 20:46:21 +0200862 printk(KERN_INFO "%s: detected at %lx, irq %d\n", dev->name,
863 dev->base_addr, dev->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864
Krzysztof Hałasa64bef762008-07-02 20:46:21 +0200865 err = register_hdlc_device(dev);
866 if (err) {
867 printk(KERN_ERR "%s: register_netdev failed.\n", dev->name);
868 free_netdev(dev);
869 goto err_hdlcdev;
870 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871
872 sc->lmc_cardtype = LMC_CARDTYPE_UNKNOWN;
873 sc->lmc_timing = LMC_CTL_CLOCK_SOURCE_EXT;
874
875 /*
876 *
877 * Check either the subvendor or the subdevice, some systems reverse
878 * the setting in the bois, seems to be version and arch dependent?
879 * Fix the error, exchange the two values
880 */
881 if ((subdevice = pdev->subsystem_device) == PCI_VENDOR_ID_LMC)
882 subdevice = pdev->subsystem_vendor;
883
884 switch (subdevice) {
885 case PCI_DEVICE_ID_LMC_HSSI:
Krzysztof Hałasa64bef762008-07-02 20:46:21 +0200886 printk(KERN_INFO "%s: LMC HSSI\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887 sc->lmc_cardtype = LMC_CARDTYPE_HSSI;
888 sc->lmc_media = &lmc_hssi_media;
889 break;
890 case PCI_DEVICE_ID_LMC_DS3:
Krzysztof Hałasa64bef762008-07-02 20:46:21 +0200891 printk(KERN_INFO "%s: LMC DS3\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892 sc->lmc_cardtype = LMC_CARDTYPE_DS3;
893 sc->lmc_media = &lmc_ds3_media;
894 break;
895 case PCI_DEVICE_ID_LMC_SSI:
Krzysztof Hałasa64bef762008-07-02 20:46:21 +0200896 printk(KERN_INFO "%s: LMC SSI\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897 sc->lmc_cardtype = LMC_CARDTYPE_SSI;
898 sc->lmc_media = &lmc_ssi_media;
899 break;
900 case PCI_DEVICE_ID_LMC_T1:
Krzysztof Hałasa64bef762008-07-02 20:46:21 +0200901 printk(KERN_INFO "%s: LMC T1\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902 sc->lmc_cardtype = LMC_CARDTYPE_T1;
903 sc->lmc_media = &lmc_t1_media;
904 break;
905 default:
Krzysztof Hałasa64bef762008-07-02 20:46:21 +0200906 printk(KERN_WARNING "%s: LMC UNKOWN CARD!\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907 break;
908 }
909
910 lmc_initcsrs (sc, dev->base_addr, 8);
911
912 lmc_gpio_mkinput (sc, 0xff);
913 sc->lmc_gpio = 0; /* drive no signals yet */
914
915 sc->lmc_media->defaults (sc);
916
917 sc->lmc_media->set_link_status (sc, LMC_LINK_UP);
918
919 /* verify that the PCI Sub System ID matches the Adapter Model number
920 * from the MII register
921 */
922 AdapModelNum = (lmc_mii_readreg (sc, 0, 3) & 0x3f0) >> 4;
923
Krzysztof Hałasa64bef762008-07-02 20:46:21 +0200924 if ((AdapModelNum != LMC_ADAP_T1 || /* detect LMC1200 */
925 subdevice != PCI_DEVICE_ID_LMC_T1) &&
926 (AdapModelNum != LMC_ADAP_SSI || /* detect LMC1000 */
927 subdevice != PCI_DEVICE_ID_LMC_SSI) &&
928 (AdapModelNum != LMC_ADAP_DS3 || /* detect LMC5245 */
929 subdevice != PCI_DEVICE_ID_LMC_DS3) &&
930 (AdapModelNum != LMC_ADAP_HSSI || /* detect LMC5200 */
931 subdevice != PCI_DEVICE_ID_LMC_HSSI))
932 printk(KERN_WARNING "%s: Model number (%d) miscompare for PCI"
933 " Subsystem ID = 0x%04x\n",
934 dev->name, AdapModelNum, subdevice);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936 /*
937 * reset clock
938 */
939 LMC_CSR_WRITE (sc, csr_gp_timer, 0xFFFFFFFFUL);
940
941 sc->board_idx = cards_found++;
Krzysztof Hałasa64bef762008-07-02 20:46:21 +0200942 sc->extra_stats.check = STATCHECK;
943 sc->extra_stats.version_size = (DRIVER_VERSION << 16) +
944 sizeof(sc->lmc_device->stats) + sizeof(sc->extra_stats);
945 sc->extra_stats.lmc_cardtype = sc->lmc_cardtype;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946
947 sc->lmc_ok = 0;
948 sc->last_link_status = 0;
949
950 lmc_trace(dev, "lmc_init_one out");
951 return 0;
952
Krzysztof Hałasa64bef762008-07-02 20:46:21 +0200953err_hdlcdev:
954 pci_set_drvdata(pdev, NULL);
955 kfree(sc);
956err_kzalloc:
957 pci_release_regions(pdev);
958err_req_io:
959 pci_disable_device(pdev);
960 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961}
962
963/*
964 * Called from pci when removing module.
965 */
Krzysztof Hałasa64bef762008-07-02 20:46:21 +0200966static void __devexit lmc_remove_one(struct pci_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967{
Krzysztof Hałasa64bef762008-07-02 20:46:21 +0200968 struct net_device *dev = pci_get_drvdata(pdev);
969
970 if (dev) {
971 printk(KERN_DEBUG "%s: removing...\n", dev->name);
972 unregister_hdlc_device(dev);
973 free_netdev(dev);
974 pci_release_regions(pdev);
975 pci_disable_device(pdev);
976 pci_set_drvdata(pdev, NULL);
977 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978}
979
980/* After this is called, packets can be sent.
981 * Does not initialize the addresses
982 */
Krzysztof Hałasa64bef762008-07-02 20:46:21 +0200983static int lmc_open(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984{
Krzysztof Hałasa64bef762008-07-02 20:46:21 +0200985 lmc_softc_t *sc = dev_to_sc(dev);
986 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987
988 lmc_trace(dev, "lmc_open in");
989
990 lmc_led_on(sc, LMC_DS3_LED0);
991
Krzysztof Hałasa64bef762008-07-02 20:46:21 +0200992 lmc_dec_reset(sc);
993 lmc_reset(sc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994
Krzysztof Hałasa64bef762008-07-02 20:46:21 +0200995 LMC_EVENT_LOG(LMC_EVENT_RESET1, LMC_CSR_READ(sc, csr_status), 0);
996 LMC_EVENT_LOG(LMC_EVENT_RESET2, lmc_mii_readreg(sc, 0, 16),
997 lmc_mii_readreg(sc, 0, 17));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998
999 if (sc->lmc_ok){
1000 lmc_trace(dev, "lmc_open lmc_ok out");
1001 return (0);
1002 }
1003
1004 lmc_softreset (sc);
1005
1006 /* Since we have to use PCI bus, this should work on x86,alpha,ppc */
Thomas Gleixner1fb9df52006-07-01 19:29:39 -07001007 if (request_irq (dev->irq, &lmc_interrupt, IRQF_SHARED, dev->name, dev)){
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008 printk(KERN_WARNING "%s: could not get irq: %d\n", dev->name, dev->irq);
1009 lmc_trace(dev, "lmc_open irq failed out");
1010 return -EAGAIN;
1011 }
1012 sc->got_irq = 1;
1013
1014 /* Assert Terminal Active */
1015 sc->lmc_miireg16 |= LMC_MII16_LED_ALL;
1016 sc->lmc_media->set_link_status (sc, LMC_LINK_UP);
1017
1018 /*
1019 * reset to last state.
1020 */
1021 sc->lmc_media->set_status (sc, NULL);
1022
1023 /* setup default bits to be used in tulip_desc_t transmit descriptor
1024 * -baz */
1025 sc->TxDescriptControlInit = (
1026 LMC_TDES_INTERRUPT_ON_COMPLETION
1027 | LMC_TDES_FIRST_SEGMENT
1028 | LMC_TDES_LAST_SEGMENT
1029 | LMC_TDES_SECOND_ADDR_CHAINED
1030 | LMC_TDES_DISABLE_PADDING
1031 );
1032
1033 if (sc->ictl.crc_length == LMC_CTL_CRC_LENGTH_16) {
1034 /* disable 32 bit CRC generated by ASIC */
1035 sc->TxDescriptControlInit |= LMC_TDES_ADD_CRC_DISABLE;
1036 }
1037 sc->lmc_media->set_crc_length(sc, sc->ictl.crc_length);
1038 /* Acknoledge the Terminal Active and light LEDs */
1039
1040 /* dev->flags |= IFF_UP; */
1041
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02001042 if ((err = lmc_proto_open(sc)) != 0)
1043 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044
1045 dev->do_ioctl = lmc_ioctl;
1046
1047
1048 netif_start_queue(dev);
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02001049 sc->extra_stats.tx_tbusy0++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050
1051 /*
1052 * select what interrupts we want to get
1053 */
1054 sc->lmc_intrmask = 0;
1055 /* Should be using the default interrupt mask defined in the .h file. */
1056 sc->lmc_intrmask |= (TULIP_STS_NORMALINTR
1057 | TULIP_STS_RXINTR
1058 | TULIP_STS_TXINTR
1059 | TULIP_STS_ABNRMLINTR
1060 | TULIP_STS_SYSERROR
1061 | TULIP_STS_TXSTOPPED
1062 | TULIP_STS_TXUNDERFLOW
1063 | TULIP_STS_RXSTOPPED
1064 | TULIP_STS_RXNOBUF
1065 );
1066 LMC_CSR_WRITE (sc, csr_intr, sc->lmc_intrmask);
1067
1068 sc->lmc_cmdmode |= TULIP_CMD_TXRUN;
1069 sc->lmc_cmdmode |= TULIP_CMD_RXRUN;
1070 LMC_CSR_WRITE (sc, csr_command, sc->lmc_cmdmode);
1071
1072 sc->lmc_ok = 1; /* Run watchdog */
1073
1074 /*
1075 * Set the if up now - pfb
1076 */
1077
1078 sc->last_link_status = 1;
1079
1080 /*
1081 * Setup a timer for the watchdog on probe, and start it running.
1082 * Since lmc_ok == 0, it will be a NOP for now.
1083 */
1084 init_timer (&sc->timer);
1085 sc->timer.expires = jiffies + HZ;
1086 sc->timer.data = (unsigned long) dev;
1087 sc->timer.function = &lmc_watchdog;
1088 add_timer (&sc->timer);
1089
1090 lmc_trace(dev, "lmc_open out");
1091
1092 return (0);
1093}
1094
1095/* Total reset to compensate for the AdTran DSU doing bad things
1096 * under heavy load
1097 */
1098
1099static void lmc_running_reset (struct net_device *dev) /*fold00*/
1100{
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02001101 lmc_softc_t *sc = dev_to_sc(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102
1103 lmc_trace(dev, "lmc_runnig_reset in");
1104
1105 /* stop interrupts */
1106 /* Clear the interrupt mask */
1107 LMC_CSR_WRITE (sc, csr_intr, 0x00000000);
1108
1109 lmc_dec_reset (sc);
1110 lmc_reset (sc);
1111 lmc_softreset (sc);
1112 /* sc->lmc_miireg16 |= LMC_MII16_LED_ALL; */
1113 sc->lmc_media->set_link_status (sc, 1);
1114 sc->lmc_media->set_status (sc, NULL);
1115
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116 netif_wake_queue(dev);
1117
1118 sc->lmc_txfull = 0;
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02001119 sc->extra_stats.tx_tbusy0++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120
1121 sc->lmc_intrmask = TULIP_DEFAULT_INTR_MASK;
1122 LMC_CSR_WRITE (sc, csr_intr, sc->lmc_intrmask);
1123
1124 sc->lmc_cmdmode |= (TULIP_CMD_TXRUN | TULIP_CMD_RXRUN);
1125 LMC_CSR_WRITE (sc, csr_command, sc->lmc_cmdmode);
1126
1127 lmc_trace(dev, "lmc_runnin_reset_out");
1128}
1129
1130
1131/* This is what is called when you ifconfig down a device.
1132 * This disables the timer for the watchdog and keepalives,
1133 * and disables the irq for dev.
1134 */
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02001135static int lmc_close(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136{
1137 /* not calling release_region() as we should */
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02001138 lmc_softc_t *sc = dev_to_sc(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139
1140 lmc_trace(dev, "lmc_close in");
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02001141
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142 sc->lmc_ok = 0;
1143 sc->lmc_media->set_link_status (sc, 0);
1144 del_timer (&sc->timer);
1145 lmc_proto_close(sc);
1146 lmc_ifdown (dev);
1147
1148 lmc_trace(dev, "lmc_close out");
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02001149
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150 return 0;
1151}
1152
1153/* Ends the transfer of packets */
1154/* When the interface goes down, this is called */
1155static int lmc_ifdown (struct net_device *dev) /*fold00*/
1156{
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02001157 lmc_softc_t *sc = dev_to_sc(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158 u32 csr6;
1159 int i;
1160
1161 lmc_trace(dev, "lmc_ifdown in");
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02001162
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163 /* Don't let anything else go on right now */
1164 // dev->start = 0;
1165 netif_stop_queue(dev);
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02001166 sc->extra_stats.tx_tbusy1++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167
1168 /* stop interrupts */
1169 /* Clear the interrupt mask */
1170 LMC_CSR_WRITE (sc, csr_intr, 0x00000000);
1171
1172 /* Stop Tx and Rx on the chip */
1173 csr6 = LMC_CSR_READ (sc, csr_command);
1174 csr6 &= ~LMC_DEC_ST; /* Turn off the Transmission bit */
1175 csr6 &= ~LMC_DEC_SR; /* Turn off the Receive bit */
1176 LMC_CSR_WRITE (sc, csr_command, csr6);
1177
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02001178 sc->lmc_device->stats.rx_missed_errors +=
1179 LMC_CSR_READ(sc, csr_missed_frames) & 0xffff;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180
1181 /* release the interrupt */
1182 if(sc->got_irq == 1){
1183 free_irq (dev->irq, dev);
1184 sc->got_irq = 0;
1185 }
1186
1187 /* free skbuffs in the Rx queue */
1188 for (i = 0; i < LMC_RXDESCS; i++)
1189 {
1190 struct sk_buff *skb = sc->lmc_rxq[i];
1191 sc->lmc_rxq[i] = NULL;
1192 sc->lmc_rxring[i].status = 0;
1193 sc->lmc_rxring[i].length = 0;
1194 sc->lmc_rxring[i].buffer1 = 0xDEADBEEF;
1195 if (skb != NULL)
1196 dev_kfree_skb(skb);
1197 sc->lmc_rxq[i] = NULL;
1198 }
1199
1200 for (i = 0; i < LMC_TXDESCS; i++)
1201 {
1202 if (sc->lmc_txq[i] != NULL)
1203 dev_kfree_skb(sc->lmc_txq[i]);
1204 sc->lmc_txq[i] = NULL;
1205 }
1206
1207 lmc_led_off (sc, LMC_MII16_LED_ALL);
1208
1209 netif_wake_queue(dev);
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02001210 sc->extra_stats.tx_tbusy0++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211
1212 lmc_trace(dev, "lmc_ifdown out");
1213
1214 return 0;
1215}
1216
1217/* Interrupt handling routine. This will take an incoming packet, or clean
1218 * up after a trasmit.
1219 */
David Howells7d12e782006-10-05 14:55:46 +01001220static irqreturn_t lmc_interrupt (int irq, void *dev_instance) /*fold00*/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221{
1222 struct net_device *dev = (struct net_device *) dev_instance;
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02001223 lmc_softc_t *sc = dev_to_sc(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224 u32 csr;
1225 int i;
1226 s32 stat;
1227 unsigned int badtx;
1228 u32 firstcsr;
1229 int max_work = LMC_RXDESCS;
1230 int handled = 0;
1231
1232 lmc_trace(dev, "lmc_interrupt in");
1233
Linus Torvalds1da177e2005-04-16 15:20:36 -07001234 spin_lock(&sc->lmc_lock);
1235
1236 /*
1237 * Read the csr to find what interrupts we have (if any)
1238 */
1239 csr = LMC_CSR_READ (sc, csr_status);
1240
1241 /*
1242 * Make sure this is our interrupt
1243 */
1244 if ( ! (csr & sc->lmc_intrmask)) {
1245 goto lmc_int_fail_out;
1246 }
1247
1248 firstcsr = csr;
1249
1250 /* always go through this loop at least once */
1251 while (csr & sc->lmc_intrmask) {
1252 handled = 1;
1253
1254 /*
1255 * Clear interrupt bits, we handle all case below
1256 */
1257 LMC_CSR_WRITE (sc, csr_status, csr);
1258
1259 /*
1260 * One of
1261 * - Transmit process timed out CSR5<1>
1262 * - Transmit jabber timeout CSR5<3>
1263 * - Transmit underflow CSR5<5>
1264 * - Transmit Receiver buffer unavailable CSR5<7>
1265 * - Receive process stopped CSR5<8>
1266 * - Receive watchdog timeout CSR5<9>
1267 * - Early transmit interrupt CSR5<10>
1268 *
1269 * Is this really right? Should we do a running reset for jabber?
1270 * (being a WAN card and all)
1271 */
1272 if (csr & TULIP_STS_ABNRMLINTR){
1273 lmc_running_reset (dev);
1274 break;
1275 }
1276
1277 if (csr & TULIP_STS_RXINTR){
1278 lmc_trace(dev, "rx interrupt");
1279 lmc_rx (dev);
1280
1281 }
1282 if (csr & (TULIP_STS_TXINTR | TULIP_STS_TXNOBUF | TULIP_STS_TXSTOPPED)) {
1283
1284 int n_compl = 0 ;
1285 /* reset the transmit timeout detection flag -baz */
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02001286 sc->extra_stats.tx_NoCompleteCnt = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287
1288 badtx = sc->lmc_taint_tx;
1289 i = badtx % LMC_TXDESCS;
1290
1291 while ((badtx < sc->lmc_next_tx)) {
1292 stat = sc->lmc_txring[i].status;
1293
1294 LMC_EVENT_LOG (LMC_EVENT_XMTINT, stat,
1295 sc->lmc_txring[i].length);
1296 /*
1297 * If bit 31 is 1 the tulip owns it break out of the loop
1298 */
1299 if (stat & 0x80000000)
1300 break;
1301
1302 n_compl++ ; /* i.e., have an empty slot in ring */
1303 /*
1304 * If we have no skbuff or have cleared it
1305 * Already continue to the next buffer
1306 */
1307 if (sc->lmc_txq[i] == NULL)
1308 continue;
1309
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02001310 /*
1311 * Check the total error summary to look for any errors
1312 */
1313 if (stat & 0x8000) {
1314 sc->lmc_device->stats.tx_errors++;
1315 if (stat & 0x4104)
1316 sc->lmc_device->stats.tx_aborted_errors++;
1317 if (stat & 0x0C00)
1318 sc->lmc_device->stats.tx_carrier_errors++;
1319 if (stat & 0x0200)
1320 sc->lmc_device->stats.tx_window_errors++;
1321 if (stat & 0x0002)
1322 sc->lmc_device->stats.tx_fifo_errors++;
1323 } else {
1324 sc->lmc_device->stats.tx_bytes += sc->lmc_txring[i].length & 0x7ff;
1325
1326 sc->lmc_device->stats.tx_packets++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327 }
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02001328
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329 // dev_kfree_skb(sc->lmc_txq[i]);
1330 dev_kfree_skb_irq(sc->lmc_txq[i]);
1331 sc->lmc_txq[i] = NULL;
1332
1333 badtx++;
1334 i = badtx % LMC_TXDESCS;
1335 }
1336
1337 if (sc->lmc_next_tx - badtx > LMC_TXDESCS)
1338 {
1339 printk ("%s: out of sync pointer\n", dev->name);
1340 badtx += LMC_TXDESCS;
1341 }
1342 LMC_EVENT_LOG(LMC_EVENT_TBUSY0, n_compl, 0);
1343 sc->lmc_txfull = 0;
1344 netif_wake_queue(dev);
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02001345 sc->extra_stats.tx_tbusy0++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346
1347
1348#ifdef DEBUG
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02001349 sc->extra_stats.dirtyTx = badtx;
1350 sc->extra_stats.lmc_next_tx = sc->lmc_next_tx;
1351 sc->extra_stats.lmc_txfull = sc->lmc_txfull;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352#endif
1353 sc->lmc_taint_tx = badtx;
1354
1355 /*
1356 * Why was there a break here???
1357 */
1358 } /* end handle transmit interrupt */
1359
1360 if (csr & TULIP_STS_SYSERROR) {
1361 u32 error;
1362 printk (KERN_WARNING "%s: system bus error csr: %#8.8x\n", dev->name, csr);
1363 error = csr>>23 & 0x7;
1364 switch(error){
1365 case 0x000:
1366 printk(KERN_WARNING "%s: Parity Fault (bad)\n", dev->name);
1367 break;
1368 case 0x001:
1369 printk(KERN_WARNING "%s: Master Abort (naughty)\n", dev->name);
1370 break;
1371 case 0x010:
1372 printk(KERN_WARNING "%s: Target Abort (not so naughty)\n", dev->name);
1373 break;
1374 default:
1375 printk(KERN_WARNING "%s: This bus error code was supposed to be reserved!\n", dev->name);
1376 }
1377 lmc_dec_reset (sc);
1378 lmc_reset (sc);
1379 LMC_EVENT_LOG(LMC_EVENT_RESET1, LMC_CSR_READ (sc, csr_status), 0);
1380 LMC_EVENT_LOG(LMC_EVENT_RESET2,
1381 lmc_mii_readreg (sc, 0, 16),
1382 lmc_mii_readreg (sc, 0, 17));
1383
1384 }
1385
1386
1387 if(max_work-- <= 0)
1388 break;
1389
1390 /*
1391 * Get current csr status to make sure
1392 * we've cleared all interrupts
1393 */
1394 csr = LMC_CSR_READ (sc, csr_status);
1395 } /* end interrupt loop */
1396 LMC_EVENT_LOG(LMC_EVENT_INT, firstcsr, csr);
1397
1398lmc_int_fail_out:
1399
1400 spin_unlock(&sc->lmc_lock);
1401
1402 lmc_trace(dev, "lmc_interrupt out");
1403 return IRQ_RETVAL(handled);
1404}
1405
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02001406static int lmc_start_xmit(struct sk_buff *skb, struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001407{
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02001408 lmc_softc_t *sc = dev_to_sc(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409 u32 flag;
1410 int entry;
1411 int ret = 0;
1412 unsigned long flags;
1413
1414 lmc_trace(dev, "lmc_start_xmit in");
1415
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416 spin_lock_irqsave(&sc->lmc_lock, flags);
1417
1418 /* normal path, tbusy known to be zero */
1419
1420 entry = sc->lmc_next_tx % LMC_TXDESCS;
1421
1422 sc->lmc_txq[entry] = skb;
1423 sc->lmc_txring[entry].buffer1 = virt_to_bus (skb->data);
1424
1425 LMC_CONSOLE_LOG("xmit", skb->data, skb->len);
1426
1427#ifndef GCOM
1428 /* If the queue is less than half full, don't interrupt */
1429 if (sc->lmc_next_tx - sc->lmc_taint_tx < LMC_TXDESCS / 2)
1430 {
1431 /* Do not interrupt on completion of this packet */
1432 flag = 0x60000000;
1433 netif_wake_queue(dev);
1434 }
1435 else if (sc->lmc_next_tx - sc->lmc_taint_tx == LMC_TXDESCS / 2)
1436 {
1437 /* This generates an interrupt on completion of this packet */
1438 flag = 0xe0000000;
1439 netif_wake_queue(dev);
1440 }
1441 else if (sc->lmc_next_tx - sc->lmc_taint_tx < LMC_TXDESCS - 1)
1442 {
1443 /* Do not interrupt on completion of this packet */
1444 flag = 0x60000000;
1445 netif_wake_queue(dev);
1446 }
1447 else
1448 {
1449 /* This generates an interrupt on completion of this packet */
1450 flag = 0xe0000000;
1451 sc->lmc_txfull = 1;
1452 netif_stop_queue(dev);
1453 }
1454#else
1455 flag = LMC_TDES_INTERRUPT_ON_COMPLETION;
1456
1457 if (sc->lmc_next_tx - sc->lmc_taint_tx >= LMC_TXDESCS - 1)
1458 { /* ring full, go busy */
1459 sc->lmc_txfull = 1;
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02001460 netif_stop_queue(dev);
1461 sc->extra_stats.tx_tbusy1++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462 LMC_EVENT_LOG(LMC_EVENT_TBUSY1, entry, 0);
1463 }
1464#endif
1465
1466
1467 if (entry == LMC_TXDESCS - 1) /* last descriptor in ring */
1468 flag |= LMC_TDES_END_OF_RING; /* flag as such for Tulip */
1469
1470 /* don't pad small packets either */
1471 flag = sc->lmc_txring[entry].length = (skb->len) | flag |
1472 sc->TxDescriptControlInit;
1473
1474 /* set the transmit timeout flag to be checked in
1475 * the watchdog timer handler. -baz
1476 */
1477
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02001478 sc->extra_stats.tx_NoCompleteCnt++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479 sc->lmc_next_tx++;
1480
1481 /* give ownership to the chip */
1482 LMC_EVENT_LOG(LMC_EVENT_XMT, flag, entry);
1483 sc->lmc_txring[entry].status = 0x80000000;
1484
1485 /* send now! */
1486 LMC_CSR_WRITE (sc, csr_txpoll, 0);
1487
1488 dev->trans_start = jiffies;
1489
1490 spin_unlock_irqrestore(&sc->lmc_lock, flags);
1491
1492 lmc_trace(dev, "lmc_start_xmit_out");
1493 return ret;
1494}
1495
1496
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02001497static int lmc_rx(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498{
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02001499 lmc_softc_t *sc = dev_to_sc(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001500 int i;
1501 int rx_work_limit = LMC_RXDESCS;
1502 unsigned int next_rx;
1503 int rxIntLoopCnt; /* debug -baz */
1504 int localLengthErrCnt = 0;
1505 long stat;
1506 struct sk_buff *skb, *nsb;
1507 u16 len;
1508
1509 lmc_trace(dev, "lmc_rx in");
1510
Linus Torvalds1da177e2005-04-16 15:20:36 -07001511 lmc_led_on(sc, LMC_DS3_LED3);
1512
1513 rxIntLoopCnt = 0; /* debug -baz */
1514
1515 i = sc->lmc_next_rx % LMC_RXDESCS;
1516 next_rx = sc->lmc_next_rx;
1517
1518 while (((stat = sc->lmc_rxring[i].status) & LMC_RDES_OWN_BIT) != DESC_OWNED_BY_DC21X4)
1519 {
1520 rxIntLoopCnt++; /* debug -baz */
1521 len = ((stat & LMC_RDES_FRAME_LENGTH) >> RDES_FRAME_LENGTH_BIT_NUMBER);
1522 if ((stat & 0x0300) != 0x0300) { /* Check first segment and last segment */
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02001523 if ((stat & 0x0000ffff) != 0x7fff) {
1524 /* Oversized frame */
1525 sc->lmc_device->stats.rx_length_errors++;
1526 goto skip_packet;
1527 }
1528 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001529
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02001530 if (stat & 0x00000008) { /* Catch a dribbling bit error */
1531 sc->lmc_device->stats.rx_errors++;
1532 sc->lmc_device->stats.rx_frame_errors++;
1533 goto skip_packet;
1534 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535
1536
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02001537 if (stat & 0x00000004) { /* Catch a CRC error by the Xilinx */
1538 sc->lmc_device->stats.rx_errors++;
1539 sc->lmc_device->stats.rx_crc_errors++;
1540 goto skip_packet;
1541 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02001543 if (len > LMC_PKT_BUF_SZ) {
1544 sc->lmc_device->stats.rx_length_errors++;
1545 localLengthErrCnt++;
1546 goto skip_packet;
1547 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02001549 if (len < sc->lmc_crcSize + 2) {
1550 sc->lmc_device->stats.rx_length_errors++;
1551 sc->extra_stats.rx_SmallPktCnt++;
1552 localLengthErrCnt++;
1553 goto skip_packet;
1554 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001555
1556 if(stat & 0x00004000){
1557 printk(KERN_WARNING "%s: Receiver descriptor error, receiver out of sync?\n", dev->name);
1558 }
1559
1560 len -= sc->lmc_crcSize;
1561
1562 skb = sc->lmc_rxq[i];
1563
1564 /*
1565 * We ran out of memory at some point
1566 * just allocate an skb buff and continue.
1567 */
1568
Al Viro79ea13c2008-01-24 02:06:46 -08001569 if (!skb) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001570 nsb = dev_alloc_skb (LMC_PKT_BUF_SZ + 2);
1571 if (nsb) {
1572 sc->lmc_rxq[i] = nsb;
1573 nsb->dev = dev;
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -07001574 sc->lmc_rxring[i].buffer1 = virt_to_bus(skb_tail_pointer(nsb));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001575 }
1576 sc->failed_recv_alloc = 1;
1577 goto skip_packet;
1578 }
1579
1580 dev->last_rx = jiffies;
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02001581 sc->lmc_device->stats.rx_packets++;
1582 sc->lmc_device->stats.rx_bytes += len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001583
1584 LMC_CONSOLE_LOG("recv", skb->data, len);
1585
1586 /*
1587 * I'm not sure of the sanity of this
1588 * Packets could be arriving at a constant
1589 * 44.210mbits/sec and we're going to copy
1590 * them into a new buffer??
1591 */
1592
1593 if(len > (LMC_MTU - (LMC_MTU>>2))){ /* len > LMC_MTU * 0.75 */
1594 /*
1595 * If it's a large packet don't copy it just hand it up
1596 */
1597 give_it_anyways:
1598
1599 sc->lmc_rxq[i] = NULL;
1600 sc->lmc_rxring[i].buffer1 = 0x0;
1601
1602 skb_put (skb, len);
1603 skb->protocol = lmc_proto_type(sc, skb);
Arnaldo Carvalho de Melo459a98e2007-03-19 15:30:44 -07001604 skb_reset_mac_header(skb);
Arnaldo Carvalho de Meloc1d2bbe2007-04-10 20:45:18 -07001605 /* skb_reset_network_header(skb); */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001606 skb->dev = dev;
1607 lmc_proto_netif(sc, skb);
1608
1609 /*
1610 * This skb will be destroyed by the upper layers, make a new one
1611 */
1612 nsb = dev_alloc_skb (LMC_PKT_BUF_SZ + 2);
1613 if (nsb) {
1614 sc->lmc_rxq[i] = nsb;
1615 nsb->dev = dev;
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -07001616 sc->lmc_rxring[i].buffer1 = virt_to_bus(skb_tail_pointer(nsb));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001617 /* Transferred to 21140 below */
1618 }
1619 else {
1620 /*
1621 * We've run out of memory, stop trying to allocate
1622 * memory and exit the interrupt handler
1623 *
1624 * The chip may run out of receivers and stop
1625 * in which care we'll try to allocate the buffer
1626 * again. (once a second)
1627 */
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02001628 sc->extra_stats.rx_BuffAllocErr++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001629 LMC_EVENT_LOG(LMC_EVENT_RCVINT, stat, len);
1630 sc->failed_recv_alloc = 1;
1631 goto skip_out_of_mem;
1632 }
1633 }
1634 else {
1635 nsb = dev_alloc_skb(len);
1636 if(!nsb) {
1637 goto give_it_anyways;
1638 }
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001639 skb_copy_from_linear_data(skb, skb_put(nsb, len), len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001640
1641 nsb->protocol = lmc_proto_type(sc, skb);
Arnaldo Carvalho de Melo459a98e2007-03-19 15:30:44 -07001642 skb_reset_mac_header(nsb);
Arnaldo Carvalho de Meloc1d2bbe2007-04-10 20:45:18 -07001643 /* skb_reset_network_header(nsb); */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001644 nsb->dev = dev;
1645 lmc_proto_netif(sc, nsb);
1646 }
1647
1648 skip_packet:
1649 LMC_EVENT_LOG(LMC_EVENT_RCVINT, stat, len);
1650 sc->lmc_rxring[i].status = DESC_OWNED_BY_DC21X4;
1651
1652 sc->lmc_next_rx++;
1653 i = sc->lmc_next_rx % LMC_RXDESCS;
1654 rx_work_limit--;
1655 if (rx_work_limit < 0)
1656 break;
1657 }
1658
1659 /* detect condition for LMC1000 where DSU cable attaches and fills
1660 * descriptors with bogus packets
1661 *
1662 if (localLengthErrCnt > LMC_RXDESCS - 3) {
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02001663 sc->extra_stats.rx_BadPktSurgeCnt++;
1664 LMC_EVENT_LOG(LMC_EVENT_BADPKTSURGE, localLengthErrCnt,
1665 sc->extra_stats.rx_BadPktSurgeCnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001666 } */
1667
1668 /* save max count of receive descriptors serviced */
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02001669 if (rxIntLoopCnt > sc->extra_stats.rxIntLoopCnt)
1670 sc->extra_stats.rxIntLoopCnt = rxIntLoopCnt; /* debug -baz */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001671
1672#ifdef DEBUG
1673 if (rxIntLoopCnt == 0)
1674 {
1675 for (i = 0; i < LMC_RXDESCS; i++)
1676 {
1677 if ((sc->lmc_rxring[i].status & LMC_RDES_OWN_BIT)
1678 != DESC_OWNED_BY_DC21X4)
1679 {
1680 rxIntLoopCnt++;
1681 }
1682 }
1683 LMC_EVENT_LOG(LMC_EVENT_RCVEND, rxIntLoopCnt, 0);
1684 }
1685#endif
1686
1687
1688 lmc_led_off(sc, LMC_DS3_LED3);
1689
1690skip_out_of_mem:
1691
1692 lmc_trace(dev, "lmc_rx out");
1693
1694 return 0;
1695}
1696
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02001697static struct net_device_stats *lmc_get_stats(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001698{
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02001699 lmc_softc_t *sc = dev_to_sc(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001700 unsigned long flags;
1701
1702 lmc_trace(dev, "lmc_get_stats in");
1703
Linus Torvalds1da177e2005-04-16 15:20:36 -07001704 spin_lock_irqsave(&sc->lmc_lock, flags);
1705
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02001706 sc->lmc_device->stats.rx_missed_errors += LMC_CSR_READ(sc, csr_missed_frames) & 0xffff;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001707
1708 spin_unlock_irqrestore(&sc->lmc_lock, flags);
1709
1710 lmc_trace(dev, "lmc_get_stats out");
1711
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02001712 return &sc->lmc_device->stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001713}
1714
1715static struct pci_driver lmc_driver = {
1716 .name = "lmc",
1717 .id_table = lmc_pci_tbl,
1718 .probe = lmc_init_one,
1719 .remove = __devexit_p(lmc_remove_one),
1720};
1721
1722static int __init init_lmc(void)
1723{
Jeff Garzik29917622006-08-19 17:48:59 -04001724 return pci_register_driver(&lmc_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001725}
1726
1727static void __exit exit_lmc(void)
1728{
1729 pci_unregister_driver(&lmc_driver);
1730}
1731
1732module_init(init_lmc);
1733module_exit(exit_lmc);
1734
1735unsigned lmc_mii_readreg (lmc_softc_t * const sc, unsigned devaddr, unsigned regno) /*fold00*/
1736{
1737 int i;
1738 int command = (0xf6 << 10) | (devaddr << 5) | regno;
1739 int retval = 0;
1740
1741 lmc_trace(sc->lmc_device, "lmc_mii_readreg in");
1742
1743 LMC_MII_SYNC (sc);
1744
1745 lmc_trace(sc->lmc_device, "lmc_mii_readreg: done sync");
1746
1747 for (i = 15; i >= 0; i--)
1748 {
1749 int dataval = (command & (1 << i)) ? 0x20000 : 0;
1750
1751 LMC_CSR_WRITE (sc, csr_9, dataval);
1752 lmc_delay ();
1753 /* __SLOW_DOWN_IO; */
1754 LMC_CSR_WRITE (sc, csr_9, dataval | 0x10000);
1755 lmc_delay ();
1756 /* __SLOW_DOWN_IO; */
1757 }
1758
1759 lmc_trace(sc->lmc_device, "lmc_mii_readreg: done1");
1760
1761 for (i = 19; i > 0; i--)
1762 {
1763 LMC_CSR_WRITE (sc, csr_9, 0x40000);
1764 lmc_delay ();
1765 /* __SLOW_DOWN_IO; */
1766 retval = (retval << 1) | ((LMC_CSR_READ (sc, csr_9) & 0x80000) ? 1 : 0);
1767 LMC_CSR_WRITE (sc, csr_9, 0x40000 | 0x10000);
1768 lmc_delay ();
1769 /* __SLOW_DOWN_IO; */
1770 }
1771
1772 lmc_trace(sc->lmc_device, "lmc_mii_readreg out");
1773
1774 return (retval >> 1) & 0xffff;
1775}
1776
1777void lmc_mii_writereg (lmc_softc_t * const sc, unsigned devaddr, unsigned regno, unsigned data) /*fold00*/
1778{
1779 int i = 32;
1780 int command = (0x5002 << 16) | (devaddr << 23) | (regno << 18) | data;
1781
1782 lmc_trace(sc->lmc_device, "lmc_mii_writereg in");
1783
1784 LMC_MII_SYNC (sc);
1785
1786 i = 31;
1787 while (i >= 0)
1788 {
1789 int datav;
1790
1791 if (command & (1 << i))
1792 datav = 0x20000;
1793 else
1794 datav = 0x00000;
1795
1796 LMC_CSR_WRITE (sc, csr_9, datav);
1797 lmc_delay ();
1798 /* __SLOW_DOWN_IO; */
1799 LMC_CSR_WRITE (sc, csr_9, (datav | 0x10000));
1800 lmc_delay ();
1801 /* __SLOW_DOWN_IO; */
1802 i--;
1803 }
1804
1805 i = 2;
1806 while (i > 0)
1807 {
1808 LMC_CSR_WRITE (sc, csr_9, 0x40000);
1809 lmc_delay ();
1810 /* __SLOW_DOWN_IO; */
1811 LMC_CSR_WRITE (sc, csr_9, 0x50000);
1812 lmc_delay ();
1813 /* __SLOW_DOWN_IO; */
1814 i--;
1815 }
1816
1817 lmc_trace(sc->lmc_device, "lmc_mii_writereg out");
1818}
1819
1820static void lmc_softreset (lmc_softc_t * const sc) /*fold00*/
1821{
1822 int i;
1823
1824 lmc_trace(sc->lmc_device, "lmc_softreset in");
1825
1826 /* Initialize the receive rings and buffers. */
1827 sc->lmc_txfull = 0;
1828 sc->lmc_next_rx = 0;
1829 sc->lmc_next_tx = 0;
1830 sc->lmc_taint_rx = 0;
1831 sc->lmc_taint_tx = 0;
1832
1833 /*
1834 * Setup each one of the receiver buffers
1835 * allocate an skbuff for each one, setup the descriptor table
1836 * and point each buffer at the next one
1837 */
1838
1839 for (i = 0; i < LMC_RXDESCS; i++)
1840 {
1841 struct sk_buff *skb;
1842
1843 if (sc->lmc_rxq[i] == NULL)
1844 {
1845 skb = dev_alloc_skb (LMC_PKT_BUF_SZ + 2);
1846 if(skb == NULL){
1847 printk(KERN_WARNING "%s: Failed to allocate receiver ring, will try again\n", sc->name);
1848 sc->failed_ring = 1;
1849 break;
1850 }
1851 else{
1852 sc->lmc_rxq[i] = skb;
1853 }
1854 }
1855 else
1856 {
1857 skb = sc->lmc_rxq[i];
1858 }
1859
1860 skb->dev = sc->lmc_device;
1861
1862 /* owned by 21140 */
1863 sc->lmc_rxring[i].status = 0x80000000;
1864
1865 /* 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 -03001866 sc->lmc_rxring[i].length = skb_tailroom(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001867
1868 /* use to be tail which is dumb since you're thinking why write
1869 * to the end of the packj,et but since there's nothing there tail == data
1870 */
1871 sc->lmc_rxring[i].buffer1 = virt_to_bus (skb->data);
1872
1873 /* This is fair since the structure is static and we have the next address */
1874 sc->lmc_rxring[i].buffer2 = virt_to_bus (&sc->lmc_rxring[i + 1]);
1875
1876 }
1877
1878 /*
1879 * Sets end of ring
1880 */
1881 sc->lmc_rxring[i - 1].length |= 0x02000000; /* Set end of buffers flag */
1882 sc->lmc_rxring[i - 1].buffer2 = virt_to_bus (&sc->lmc_rxring[0]); /* Point back to the start */
1883 LMC_CSR_WRITE (sc, csr_rxlist, virt_to_bus (sc->lmc_rxring)); /* write base address */
1884
1885
1886 /* Initialize the transmit rings and buffers */
1887 for (i = 0; i < LMC_TXDESCS; i++)
1888 {
1889 if (sc->lmc_txq[i] != NULL){ /* have buffer */
1890 dev_kfree_skb(sc->lmc_txq[i]); /* free it */
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02001891 sc->lmc_device->stats.tx_dropped++; /* We just dropped a packet */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001892 }
1893 sc->lmc_txq[i] = NULL;
1894 sc->lmc_txring[i].status = 0x00000000;
1895 sc->lmc_txring[i].buffer2 = virt_to_bus (&sc->lmc_txring[i + 1]);
1896 }
1897 sc->lmc_txring[i - 1].buffer2 = virt_to_bus (&sc->lmc_txring[0]);
1898 LMC_CSR_WRITE (sc, csr_txlist, virt_to_bus (sc->lmc_txring));
1899
1900 lmc_trace(sc->lmc_device, "lmc_softreset out");
1901}
1902
Krzysztof Hałasa867240f2008-07-03 00:39:46 +02001903void lmc_gpio_mkinput(lmc_softc_t * const sc, u32 bits) /*fold00*/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001904{
1905 lmc_trace(sc->lmc_device, "lmc_gpio_mkinput in");
1906 sc->lmc_gpio_io &= ~bits;
1907 LMC_CSR_WRITE(sc, csr_gp, TULIP_GP_PINSET | (sc->lmc_gpio_io));
1908 lmc_trace(sc->lmc_device, "lmc_gpio_mkinput out");
1909}
1910
Krzysztof Hałasa867240f2008-07-03 00:39:46 +02001911void lmc_gpio_mkoutput(lmc_softc_t * const sc, u32 bits) /*fold00*/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001912{
1913 lmc_trace(sc->lmc_device, "lmc_gpio_mkoutput in");
1914 sc->lmc_gpio_io |= bits;
1915 LMC_CSR_WRITE(sc, csr_gp, TULIP_GP_PINSET | (sc->lmc_gpio_io));
1916 lmc_trace(sc->lmc_device, "lmc_gpio_mkoutput out");
1917}
1918
Krzysztof Hałasa867240f2008-07-03 00:39:46 +02001919void lmc_led_on(lmc_softc_t * const sc, u32 led) /*fold00*/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001920{
1921 lmc_trace(sc->lmc_device, "lmc_led_on in");
1922 if((~sc->lmc_miireg16) & led){ /* Already on! */
1923 lmc_trace(sc->lmc_device, "lmc_led_on aon out");
1924 return;
1925 }
1926
1927 sc->lmc_miireg16 &= ~led;
1928 lmc_mii_writereg(sc, 0, 16, sc->lmc_miireg16);
1929 lmc_trace(sc->lmc_device, "lmc_led_on out");
1930}
1931
Krzysztof Hałasa867240f2008-07-03 00:39:46 +02001932void lmc_led_off(lmc_softc_t * const sc, u32 led) /*fold00*/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001933{
1934 lmc_trace(sc->lmc_device, "lmc_led_off in");
1935 if(sc->lmc_miireg16 & led){ /* Already set don't do anything */
1936 lmc_trace(sc->lmc_device, "lmc_led_off aoff out");
1937 return;
1938 }
1939
1940 sc->lmc_miireg16 |= led;
1941 lmc_mii_writereg(sc, 0, 16, sc->lmc_miireg16);
1942 lmc_trace(sc->lmc_device, "lmc_led_off out");
1943}
1944
1945static void lmc_reset(lmc_softc_t * const sc) /*fold00*/
1946{
1947 lmc_trace(sc->lmc_device, "lmc_reset in");
1948 sc->lmc_miireg16 |= LMC_MII16_FIFO_RESET;
1949 lmc_mii_writereg(sc, 0, 16, sc->lmc_miireg16);
1950
1951 sc->lmc_miireg16 &= ~LMC_MII16_FIFO_RESET;
1952 lmc_mii_writereg(sc, 0, 16, sc->lmc_miireg16);
1953
1954 /*
1955 * make some of the GPIO pins be outputs
1956 */
1957 lmc_gpio_mkoutput(sc, LMC_GEP_RESET);
1958
1959 /*
1960 * RESET low to force state reset. This also forces
1961 * the transmitter clock to be internal, but we expect to reset
1962 * that later anyway.
1963 */
1964 sc->lmc_gpio &= ~(LMC_GEP_RESET);
1965 LMC_CSR_WRITE(sc, csr_gp, sc->lmc_gpio);
1966
1967 /*
1968 * hold for more than 10 microseconds
1969 */
1970 udelay(50);
1971
1972 /*
1973 * stop driving Xilinx-related signals
1974 */
1975 lmc_gpio_mkinput(sc, LMC_GEP_RESET);
1976
1977 /*
1978 * Call media specific init routine
1979 */
1980 sc->lmc_media->init(sc);
1981
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02001982 sc->extra_stats.resetCount++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001983 lmc_trace(sc->lmc_device, "lmc_reset out");
1984}
1985
1986static void lmc_dec_reset(lmc_softc_t * const sc) /*fold00*/
1987{
Krzysztof Hałasa867240f2008-07-03 00:39:46 +02001988 u32 val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001989 lmc_trace(sc->lmc_device, "lmc_dec_reset in");
1990
1991 /*
1992 * disable all interrupts
1993 */
1994 sc->lmc_intrmask = 0;
1995 LMC_CSR_WRITE(sc, csr_intr, sc->lmc_intrmask);
1996
1997 /*
1998 * Reset the chip with a software reset command.
1999 * Wait 10 microseconds (actually 50 PCI cycles but at
2000 * 33MHz that comes to two microseconds but wait a
2001 * bit longer anyways)
2002 */
2003 LMC_CSR_WRITE(sc, csr_busmode, TULIP_BUSMODE_SWRESET);
2004 udelay(25);
2005#ifdef __sparc__
2006 sc->lmc_busmode = LMC_CSR_READ(sc, csr_busmode);
2007 sc->lmc_busmode = 0x00100000;
2008 sc->lmc_busmode &= ~TULIP_BUSMODE_SWRESET;
2009 LMC_CSR_WRITE(sc, csr_busmode, sc->lmc_busmode);
2010#endif
2011 sc->lmc_cmdmode = LMC_CSR_READ(sc, csr_command);
2012
2013 /*
2014 * We want:
2015 * no ethernet address in frames we write
2016 * disable padding (txdesc, padding disable)
2017 * ignore runt frames (rdes0 bit 15)
2018 * no receiver watchdog or transmitter jabber timer
2019 * (csr15 bit 0,14 == 1)
2020 * if using 16-bit CRC, turn off CRC (trans desc, crc disable)
2021 */
2022
2023 sc->lmc_cmdmode |= ( TULIP_CMD_PROMISCUOUS
2024 | TULIP_CMD_FULLDUPLEX
2025 | TULIP_CMD_PASSBADPKT
2026 | TULIP_CMD_NOHEARTBEAT
2027 | TULIP_CMD_PORTSELECT
2028 | TULIP_CMD_RECEIVEALL
2029 | TULIP_CMD_MUSTBEONE
2030 );
2031 sc->lmc_cmdmode &= ~( TULIP_CMD_OPERMODE
2032 | TULIP_CMD_THRESHOLDCTL
2033 | TULIP_CMD_STOREFWD
2034 | TULIP_CMD_TXTHRSHLDCTL
2035 );
2036
2037 LMC_CSR_WRITE(sc, csr_command, sc->lmc_cmdmode);
2038
2039 /*
2040 * disable receiver watchdog and transmit jabber
2041 */
2042 val = LMC_CSR_READ(sc, csr_sia_general);
2043 val |= (TULIP_WATCHDOG_TXDISABLE | TULIP_WATCHDOG_RXDISABLE);
2044 LMC_CSR_WRITE(sc, csr_sia_general, val);
2045
2046 lmc_trace(sc->lmc_device, "lmc_dec_reset out");
2047}
2048
2049static void lmc_initcsrs(lmc_softc_t * const sc, lmc_csrptr_t csr_base, /*fold00*/
2050 size_t csr_size)
2051{
2052 lmc_trace(sc->lmc_device, "lmc_initcsrs in");
2053 sc->lmc_csrs.csr_busmode = csr_base + 0 * csr_size;
2054 sc->lmc_csrs.csr_txpoll = csr_base + 1 * csr_size;
2055 sc->lmc_csrs.csr_rxpoll = csr_base + 2 * csr_size;
2056 sc->lmc_csrs.csr_rxlist = csr_base + 3 * csr_size;
2057 sc->lmc_csrs.csr_txlist = csr_base + 4 * csr_size;
2058 sc->lmc_csrs.csr_status = csr_base + 5 * csr_size;
2059 sc->lmc_csrs.csr_command = csr_base + 6 * csr_size;
2060 sc->lmc_csrs.csr_intr = csr_base + 7 * csr_size;
2061 sc->lmc_csrs.csr_missed_frames = csr_base + 8 * csr_size;
2062 sc->lmc_csrs.csr_9 = csr_base + 9 * csr_size;
2063 sc->lmc_csrs.csr_10 = csr_base + 10 * csr_size;
2064 sc->lmc_csrs.csr_11 = csr_base + 11 * csr_size;
2065 sc->lmc_csrs.csr_12 = csr_base + 12 * csr_size;
2066 sc->lmc_csrs.csr_13 = csr_base + 13 * csr_size;
2067 sc->lmc_csrs.csr_14 = csr_base + 14 * csr_size;
2068 sc->lmc_csrs.csr_15 = csr_base + 15 * csr_size;
2069 lmc_trace(sc->lmc_device, "lmc_initcsrs out");
2070}
2071
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02002072static void lmc_driver_timeout(struct net_device *dev)
2073{
2074 lmc_softc_t *sc = dev_to_sc(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002075 u32 csr6;
2076 unsigned long flags;
2077
2078 lmc_trace(dev, "lmc_driver_timeout in");
2079
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080 spin_lock_irqsave(&sc->lmc_lock, flags);
2081
2082 printk("%s: Xmitter busy|\n", dev->name);
2083
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02002084 sc->extra_stats.tx_tbusy_calls++;
2085 if (jiffies - dev->trans_start < TX_TIMEOUT)
2086 goto bug_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002087
2088 /*
2089 * Chip seems to have locked up
2090 * Reset it
2091 * This whips out all our decriptor
2092 * table and starts from scartch
2093 */
2094
2095 LMC_EVENT_LOG(LMC_EVENT_XMTPRCTMO,
2096 LMC_CSR_READ (sc, csr_status),
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02002097 sc->extra_stats.tx_ProcTimeout);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002098
2099 lmc_running_reset (dev);
2100
2101 LMC_EVENT_LOG(LMC_EVENT_RESET1, LMC_CSR_READ (sc, csr_status), 0);
2102 LMC_EVENT_LOG(LMC_EVENT_RESET2,
2103 lmc_mii_readreg (sc, 0, 16),
2104 lmc_mii_readreg (sc, 0, 17));
2105
2106 /* restart the tx processes */
2107 csr6 = LMC_CSR_READ (sc, csr_command);
2108 LMC_CSR_WRITE (sc, csr_command, csr6 | 0x0002);
2109 LMC_CSR_WRITE (sc, csr_command, csr6 | 0x2002);
2110
2111 /* immediate transmit */
2112 LMC_CSR_WRITE (sc, csr_txpoll, 0);
2113
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02002114 sc->lmc_device->stats.tx_errors++;
2115 sc->extra_stats.tx_ProcTimeout++; /* -baz */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002116
2117 dev->trans_start = jiffies;
2118
2119bug_out:
2120
2121 spin_unlock_irqrestore(&sc->lmc_lock, flags);
2122
2123 lmc_trace(dev, "lmc_driver_timout out");
2124
2125
2126}