blob: d7bb63e616b5e41f9ca72f2c52fa583dddcff113 [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 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125
126 switch (cmd) {
127 /*
128 * Return current driver state. Since we keep this up
129 * To date internally, just copy this out to the user.
130 */
131 case LMCIOCGINFO: /*fold01*/
Roel Kluine3376dc2007-10-30 01:11:46 -0700132 if (copy_to_user(ifr->ifr_data, &sc->ictl, sizeof(lmc_ctl_t)))
133 ret = -EFAULT;
134 else
135 ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 break;
137
138 case LMCIOCSINFO: /*fold01*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 if (!capable(CAP_NET_ADMIN)) {
140 ret = -EPERM;
141 break;
142 }
143
144 if(dev->flags & IFF_UP){
145 ret = -EBUSY;
146 break;
147 }
148
Roel Kluine3376dc2007-10-30 01:11:46 -0700149 if (copy_from_user(&ctl, ifr->ifr_data, sizeof(lmc_ctl_t))) {
150 ret = -EFAULT;
151 break;
152 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153
Alan Cox8ab7b662008-10-15 11:50:42 +0100154 spin_lock_irqsave(&sc->lmc_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 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 }
Alan Cox8ab7b662008-10-15 11:50:42 +0100164 spin_unlock_irqrestore(&sc->lmc_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 ret = 0;
167 break;
168
169 case LMCIOCIFTYPE: /*fold01*/
170 {
Krzysztof Hałasa64bef762008-07-02 20:46:21 +0200171 u16 old_type = sc->if_type;
172 u16 new_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173
174 if (!capable(CAP_NET_ADMIN)) {
175 ret = -EPERM;
176 break;
177 }
178
Krzysztof Hałasa64bef762008-07-02 20:46:21 +0200179 if (copy_from_user(&new_type, ifr->ifr_data, sizeof(u16))) {
Roel Kluine3376dc2007-10-30 01:11:46 -0700180 ret = -EFAULT;
181 break;
182 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183
184
185 if (new_type == old_type)
186 {
187 ret = 0 ;
188 break; /* no change */
189 }
190
Alan Cox8ab7b662008-10-15 11:50:42 +0100191 spin_lock_irqsave(&sc->lmc_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 lmc_proto_close(sc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193
194 sc->if_type = new_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 lmc_proto_attach(sc);
Krzysztof Hałasa64bef762008-07-02 20:46:21 +0200196 ret = lmc_proto_open(sc);
Alan Cox8ab7b662008-10-15 11:50:42 +0100197 spin_unlock_irqrestore(&sc->lmc_lock, flags);
Krzysztof Hałasa64bef762008-07-02 20:46:21 +0200198 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 }
200
201 case LMCIOCGETXINFO: /*fold01*/
Alan Cox8ab7b662008-10-15 11:50:42 +0100202 spin_lock_irqsave(&sc->lmc_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 sc->lmc_xinfo.Magic0 = 0xBEEFCAFE;
204
205 sc->lmc_xinfo.PciCardType = sc->lmc_cardtype;
206 sc->lmc_xinfo.PciSlotNumber = 0;
207 sc->lmc_xinfo.DriverMajorVersion = DRIVER_MAJOR_VERSION;
208 sc->lmc_xinfo.DriverMinorVersion = DRIVER_MINOR_VERSION;
209 sc->lmc_xinfo.DriverSubVersion = DRIVER_SUB_VERSION;
210 sc->lmc_xinfo.XilinxRevisionNumber =
211 lmc_mii_readreg (sc, 0, 3) & 0xf;
212 sc->lmc_xinfo.MaxFrameSize = LMC_PKT_BUF_SZ;
213 sc->lmc_xinfo.link_status = sc->lmc_media->get_link_status (sc);
214 sc->lmc_xinfo.mii_reg16 = lmc_mii_readreg (sc, 0, 16);
Alan Cox8ab7b662008-10-15 11:50:42 +0100215 spin_unlock_irqrestore(&sc->lmc_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216
217 sc->lmc_xinfo.Magic1 = 0xDEADBEEF;
218
219 if (copy_to_user(ifr->ifr_data, &sc->lmc_xinfo,
Adrian Bunk5c415422007-10-30 15:34:34 -0700220 sizeof(struct lmc_xinfo)))
Roel Kluine3376dc2007-10-30 01:11:46 -0700221 ret = -EFAULT;
222 else
223 ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224
225 break;
226
Krzysztof Hałasa64bef762008-07-02 20:46:21 +0200227 case LMCIOCGETLMCSTATS:
Alan Cox8ab7b662008-10-15 11:50:42 +0100228 spin_lock_irqsave(&sc->lmc_lock, flags);
Krzysztof Hałasa64bef762008-07-02 20:46:21 +0200229 if (sc->lmc_cardtype == LMC_CARDTYPE_T1) {
230 lmc_mii_writereg(sc, 0, 17, T1FRAMER_FERR_LSB);
231 sc->extra_stats.framingBitErrorCount +=
232 lmc_mii_readreg(sc, 0, 18) & 0xff;
233 lmc_mii_writereg(sc, 0, 17, T1FRAMER_FERR_MSB);
234 sc->extra_stats.framingBitErrorCount +=
235 (lmc_mii_readreg(sc, 0, 18) & 0xff) << 8;
236 lmc_mii_writereg(sc, 0, 17, T1FRAMER_LCV_LSB);
237 sc->extra_stats.lineCodeViolationCount +=
238 lmc_mii_readreg(sc, 0, 18) & 0xff;
239 lmc_mii_writereg(sc, 0, 17, T1FRAMER_LCV_MSB);
240 sc->extra_stats.lineCodeViolationCount +=
241 (lmc_mii_readreg(sc, 0, 18) & 0xff) << 8;
242 lmc_mii_writereg(sc, 0, 17, T1FRAMER_AERR);
243 regVal = lmc_mii_readreg(sc, 0, 18) & 0xff;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244
Krzysztof Hałasa64bef762008-07-02 20:46:21 +0200245 sc->extra_stats.lossOfFrameCount +=
246 (regVal & T1FRAMER_LOF_MASK) >> 4;
247 sc->extra_stats.changeOfFrameAlignmentCount +=
248 (regVal & T1FRAMER_COFA_MASK) >> 2;
249 sc->extra_stats.severelyErroredFrameCount +=
250 regVal & T1FRAMER_SEF_MASK;
251 }
Alan Cox8ab7b662008-10-15 11:50:42 +0100252 spin_unlock_irqrestore(&sc->lmc_lock, flags);
Krzysztof Hałasa64bef762008-07-02 20:46:21 +0200253 if (copy_to_user(ifr->ifr_data, &sc->lmc_device->stats,
254 sizeof(sc->lmc_device->stats)) ||
255 copy_to_user(ifr->ifr_data + sizeof(sc->lmc_device->stats),
256 &sc->extra_stats, sizeof(sc->extra_stats)))
257 ret = -EFAULT;
258 else
259 ret = 0;
260 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261
Krzysztof Hałasa64bef762008-07-02 20:46:21 +0200262 case LMCIOCCLEARLMCSTATS:
263 if (!capable(CAP_NET_ADMIN)) {
264 ret = -EPERM;
265 break;
266 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267
Alan Cox8ab7b662008-10-15 11:50:42 +0100268 spin_lock_irqsave(&sc->lmc_lock, flags);
Krzysztof Hałasa64bef762008-07-02 20:46:21 +0200269 memset(&sc->lmc_device->stats, 0, sizeof(sc->lmc_device->stats));
270 memset(&sc->extra_stats, 0, sizeof(sc->extra_stats));
271 sc->extra_stats.check = STATCHECK;
272 sc->extra_stats.version_size = (DRIVER_VERSION << 16) +
273 sizeof(sc->lmc_device->stats) + sizeof(sc->extra_stats);
274 sc->extra_stats.lmc_cardtype = sc->lmc_cardtype;
Alan Cox8ab7b662008-10-15 11:50:42 +0100275 spin_unlock_irqrestore(&sc->lmc_lock, flags);
Krzysztof Hałasa64bef762008-07-02 20:46:21 +0200276 ret = 0;
277 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278
279 case LMCIOCSETCIRCUIT: /*fold01*/
280 if (!capable(CAP_NET_ADMIN)){
281 ret = -EPERM;
282 break;
283 }
284
285 if(dev->flags & IFF_UP){
286 ret = -EBUSY;
287 break;
288 }
289
Roel Kluine3376dc2007-10-30 01:11:46 -0700290 if (copy_from_user(&ctl, ifr->ifr_data, sizeof(lmc_ctl_t))) {
291 ret = -EFAULT;
292 break;
293 }
Alan Cox8ab7b662008-10-15 11:50:42 +0100294 spin_lock_irqsave(&sc->lmc_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 sc->lmc_media->set_circuit_type(sc, ctl.circuit_type);
296 sc->ictl.circuit_type = ctl.circuit_type;
Alan Cox8ab7b662008-10-15 11:50:42 +0100297 spin_unlock_irqrestore(&sc->lmc_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 ret = 0;
299
300 break;
301
302 case LMCIOCRESET: /*fold01*/
303 if (!capable(CAP_NET_ADMIN)){
304 ret = -EPERM;
305 break;
306 }
307
Alan Cox8ab7b662008-10-15 11:50:42 +0100308 spin_lock_irqsave(&sc->lmc_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 /* 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));
Alan Cox8ab7b662008-10-15 11:50:42 +0100315 spin_unlock_irqrestore(&sc->lmc_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316
317 ret = 0;
318 break;
319
320#ifdef DEBUG
321 case LMCIOCDUMPEVENTLOG:
Roel Kluine3376dc2007-10-30 01:11:46 -0700322 if (copy_to_user(ifr->ifr_data, &lmcEventLogIndex, sizeof(u32))) {
323 ret = -EFAULT;
324 break;
325 }
Krzysztof Hałasa867240f2008-07-03 00:39:46 +0200326 if (copy_to_user(ifr->ifr_data + sizeof(u32), lmcEventLogBuf,
327 sizeof(lmcEventLogBuf)))
Roel Kluine3376dc2007-10-30 01:11:46 -0700328 ret = -EFAULT;
329 else
330 ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 break;
333#endif /* end ifdef _DBG_EVENTLOG */
334 case LMCIOCT1CONTROL: /*fold01*/
335 if (sc->lmc_cardtype != LMC_CARDTYPE_T1){
336 ret = -EOPNOTSUPP;
337 break;
338 }
339 break;
340 case LMCIOCXILINX: /*fold01*/
341 {
342 struct lmc_xilinx_control xc; /*fold02*/
343
344 if (!capable(CAP_NET_ADMIN)){
345 ret = -EPERM;
346 break;
347 }
348
349 /*
350 * Stop the xwitter whlie we restart the hardware
351 */
352 netif_stop_queue(dev);
353
Alan Cox8ab7b662008-10-15 11:50:42 +0100354 if (copy_from_user(&xc, ifr->ifr_data, sizeof(struct lmc_xilinx_control))) {
Roel Kluine3376dc2007-10-30 01:11:46 -0700355 ret = -EFAULT;
356 break;
Alan Cox8ab7b662008-10-15 11:50:42 +0100357 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358 switch(xc.command){
359 case lmc_xilinx_reset: /*fold02*/
360 {
361 u16 mii;
Alan Cox8ab7b662008-10-15 11:50:42 +0100362 spin_lock_irqsave(&sc->lmc_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 mii = lmc_mii_readreg (sc, 0, 16);
364
365 /*
366 * Make all of them 0 and make input
367 */
368 lmc_gpio_mkinput(sc, 0xff);
369
370 /*
371 * make the reset output
372 */
373 lmc_gpio_mkoutput(sc, LMC_GEP_RESET);
374
375 /*
376 * RESET low to force configuration. This also forces
377 * the transmitter clock to be internal, but we expect to reset
378 * that later anyway.
379 */
380
381 sc->lmc_gpio &= ~LMC_GEP_RESET;
382 LMC_CSR_WRITE(sc, csr_gp, sc->lmc_gpio);
383
384
385 /*
386 * hold for more than 10 microseconds
387 */
388 udelay(50);
389
390 sc->lmc_gpio |= LMC_GEP_RESET;
391 LMC_CSR_WRITE(sc, csr_gp, sc->lmc_gpio);
392
393
394 /*
395 * stop driving Xilinx-related signals
396 */
397 lmc_gpio_mkinput(sc, 0xff);
398
399 /* Reset the frammer hardware */
400 sc->lmc_media->set_link_status (sc, 1);
401 sc->lmc_media->set_status (sc, NULL);
402// lmc_softreset(sc);
403
404 {
405 int i;
406 for(i = 0; i < 5; i++){
407 lmc_led_on(sc, LMC_DS3_LED0);
408 mdelay(100);
409 lmc_led_off(sc, LMC_DS3_LED0);
410 lmc_led_on(sc, LMC_DS3_LED1);
411 mdelay(100);
412 lmc_led_off(sc, LMC_DS3_LED1);
413 lmc_led_on(sc, LMC_DS3_LED3);
414 mdelay(100);
415 lmc_led_off(sc, LMC_DS3_LED3);
416 lmc_led_on(sc, LMC_DS3_LED2);
417 mdelay(100);
418 lmc_led_off(sc, LMC_DS3_LED2);
419 }
420 }
Alan Cox8ab7b662008-10-15 11:50:42 +0100421 spin_unlock_irqrestore(&sc->lmc_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422
423
424
425 ret = 0x0;
426
427 }
428
429 break;
430 case lmc_xilinx_load_prom: /*fold02*/
431 {
432 u16 mii;
433 int timeout = 500000;
Alan Cox8ab7b662008-10-15 11:50:42 +0100434 spin_lock_irqsave(&sc->lmc_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 mii = lmc_mii_readreg (sc, 0, 16);
436
437 /*
438 * Make all of them 0 and make input
439 */
440 lmc_gpio_mkinput(sc, 0xff);
441
442 /*
443 * make the reset output
444 */
445 lmc_gpio_mkoutput(sc, LMC_GEP_DP | LMC_GEP_RESET);
446
447 /*
448 * RESET low to force configuration. This also forces
449 * the transmitter clock to be internal, but we expect to reset
450 * that later anyway.
451 */
452
453 sc->lmc_gpio &= ~(LMC_GEP_RESET | LMC_GEP_DP);
454 LMC_CSR_WRITE(sc, csr_gp, sc->lmc_gpio);
455
456
457 /*
458 * hold for more than 10 microseconds
459 */
460 udelay(50);
461
462 sc->lmc_gpio |= LMC_GEP_DP | LMC_GEP_RESET;
463 LMC_CSR_WRITE(sc, csr_gp, sc->lmc_gpio);
464
465 /*
466 * busy wait for the chip to reset
467 */
468 while( (LMC_CSR_READ(sc, csr_gp) & LMC_GEP_INIT) == 0 &&
469 (timeout-- > 0))
Alan Cox8ab7b662008-10-15 11:50:42 +0100470 cpu_relax();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471
472
473 /*
474 * stop driving Xilinx-related signals
475 */
476 lmc_gpio_mkinput(sc, 0xff);
Alan Cox8ab7b662008-10-15 11:50:42 +0100477 spin_unlock_irqrestore(&sc->lmc_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478
479 ret = 0x0;
480
481
482 break;
483
484 }
485
486 case lmc_xilinx_load: /*fold02*/
487 {
488 char *data;
489 int pos;
490 int timeout = 500000;
491
Al Viro79ea13c2008-01-24 02:06:46 -0800492 if (!xc.data) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 ret = -EINVAL;
494 break;
495 }
496
497 data = kmalloc(xc.len, GFP_KERNEL);
Al Viro79ea13c2008-01-24 02:06:46 -0800498 if (!data) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 printk(KERN_WARNING "%s: Failed to allocate memory for copy\n", dev->name);
500 ret = -ENOMEM;
501 break;
502 }
503
504 if(copy_from_user(data, xc.data, xc.len))
505 {
506 kfree(data);
507 ret = -ENOMEM;
508 break;
509 }
510
511 printk("%s: Starting load of data Len: %d at 0x%p == 0x%p\n", dev->name, xc.len, xc.data, data);
512
Alan Cox8ab7b662008-10-15 11:50:42 +0100513 spin_lock_irqsave(&sc->lmc_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 lmc_gpio_mkinput(sc, 0xff);
515
516 /*
517 * Clear the Xilinx and start prgramming from the DEC
518 */
519
520 /*
521 * Set ouput as:
522 * Reset: 0 (active)
523 * DP: 0 (active)
524 * Mode: 1
525 *
526 */
527 sc->lmc_gpio = 0x00;
528 sc->lmc_gpio &= ~LMC_GEP_DP;
529 sc->lmc_gpio &= ~LMC_GEP_RESET;
530 sc->lmc_gpio |= LMC_GEP_MODE;
531 LMC_CSR_WRITE(sc, csr_gp, sc->lmc_gpio);
532
533 lmc_gpio_mkoutput(sc, LMC_GEP_MODE | LMC_GEP_DP | LMC_GEP_RESET);
534
535 /*
536 * Wait at least 10 us 20 to be safe
537 */
538 udelay(50);
539
540 /*
541 * Clear reset and activate programming lines
542 * Reset: Input
543 * DP: Input
544 * Clock: Output
545 * Data: Output
546 * Mode: Output
547 */
548 lmc_gpio_mkinput(sc, LMC_GEP_DP | LMC_GEP_RESET);
549
550 /*
551 * Set LOAD, DATA, Clock to 1
552 */
553 sc->lmc_gpio = 0x00;
554 sc->lmc_gpio |= LMC_GEP_MODE;
555 sc->lmc_gpio |= LMC_GEP_DATA;
556 sc->lmc_gpio |= LMC_GEP_CLK;
557 LMC_CSR_WRITE(sc, csr_gp, sc->lmc_gpio);
558
559 lmc_gpio_mkoutput(sc, LMC_GEP_DATA | LMC_GEP_CLK | LMC_GEP_MODE );
560
561 /*
562 * busy wait for the chip to reset
563 */
564 while( (LMC_CSR_READ(sc, csr_gp) & LMC_GEP_INIT) == 0 &&
565 (timeout-- > 0))
Alan Cox8ab7b662008-10-15 11:50:42 +0100566 cpu_relax();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567
568 printk(KERN_DEBUG "%s: Waited %d for the Xilinx to clear it's memory\n", dev->name, 500000-timeout);
569
570 for(pos = 0; pos < xc.len; pos++){
571 switch(data[pos]){
572 case 0:
573 sc->lmc_gpio &= ~LMC_GEP_DATA; /* Data is 0 */
574 break;
575 case 1:
576 sc->lmc_gpio |= LMC_GEP_DATA; /* Data is 1 */
577 break;
578 default:
579 printk(KERN_WARNING "%s Bad data in xilinx programming data at %d, got %d wanted 0 or 1\n", dev->name, pos, data[pos]);
580 sc->lmc_gpio |= LMC_GEP_DATA; /* Assume it's 1 */
581 }
582 sc->lmc_gpio &= ~LMC_GEP_CLK; /* Clock to zero */
583 sc->lmc_gpio |= LMC_GEP_MODE;
584 LMC_CSR_WRITE(sc, csr_gp, sc->lmc_gpio);
585 udelay(1);
586
587 sc->lmc_gpio |= LMC_GEP_CLK; /* Put the clack back to one */
588 sc->lmc_gpio |= LMC_GEP_MODE;
589 LMC_CSR_WRITE(sc, csr_gp, sc->lmc_gpio);
590 udelay(1);
591 }
592 if((LMC_CSR_READ(sc, csr_gp) & LMC_GEP_INIT) == 0){
593 printk(KERN_WARNING "%s: Reprogramming FAILED. Needs to be reprogrammed. (corrupted data)\n", dev->name);
594 }
595 else if((LMC_CSR_READ(sc, csr_gp) & LMC_GEP_DP) == 0){
596 printk(KERN_WARNING "%s: Reprogramming FAILED. Needs to be reprogrammed. (done)\n", dev->name);
597 }
598 else {
599 printk(KERN_DEBUG "%s: Done reprogramming Xilinx, %d bits, good luck!\n", dev->name, pos);
600 }
601
602 lmc_gpio_mkinput(sc, 0xff);
603
604 sc->lmc_miireg16 |= LMC_MII16_FIFO_RESET;
605 lmc_mii_writereg(sc, 0, 16, sc->lmc_miireg16);
606
607 sc->lmc_miireg16 &= ~LMC_MII16_FIFO_RESET;
608 lmc_mii_writereg(sc, 0, 16, sc->lmc_miireg16);
Alan Cox8ab7b662008-10-15 11:50:42 +0100609 spin_unlock_irqrestore(&sc->lmc_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610
611 kfree(data);
612
613 ret = 0;
614
615 break;
616 }
617 default: /*fold02*/
618 ret = -EBADE;
619 break;
620 }
621
622 netif_wake_queue(dev);
623 sc->lmc_txfull = 0;
624
625 }
626 break;
627 default: /*fold01*/
628 /* If we don't know what to do, give the protocol a shot. */
629 ret = lmc_proto_ioctl (sc, ifr, cmd);
630 break;
631 }
632
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 lmc_trace(dev, "lmc_ioctl out");
634
635 return ret;
636}
637
638
639/* the watchdog process that cruises around */
640static void lmc_watchdog (unsigned long data) /*fold00*/
641{
Krzysztof Hałasa64bef762008-07-02 20:46:21 +0200642 struct net_device *dev = (struct net_device *)data;
643 lmc_softc_t *sc = dev_to_sc(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 int link_status;
Krzysztof Hałasa867240f2008-07-03 00:39:46 +0200645 u32 ticks;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 unsigned long flags;
647
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 lmc_trace(dev, "lmc_watchdog in");
649
650 spin_lock_irqsave(&sc->lmc_lock, flags);
651
652 if(sc->check != 0xBEAFCAFE){
Alexey Dobriyan323579882006-01-15 02:12:54 +0100653 printk("LMC: Corrupt net_device struct, breaking out\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 spin_unlock_irqrestore(&sc->lmc_lock, flags);
655 return;
656 }
657
658
659 /* Make sure the tx jabber and rx watchdog are off,
660 * and the transmit and receive processes are running.
661 */
662
663 LMC_CSR_WRITE (sc, csr_15, 0x00000011);
664 sc->lmc_cmdmode |= TULIP_CMD_TXRUN | TULIP_CMD_RXRUN;
665 LMC_CSR_WRITE (sc, csr_command, sc->lmc_cmdmode);
666
667 if (sc->lmc_ok == 0)
668 goto kick_timer;
669
670 LMC_EVENT_LOG(LMC_EVENT_WATCHDOG, LMC_CSR_READ (sc, csr_status), lmc_mii_readreg (sc, 0, 16));
671
672 /* --- begin time out check -----------------------------------
673 * check for a transmit interrupt timeout
674 * Has the packet xmt vs xmt serviced threshold been exceeded */
675 if (sc->lmc_taint_tx == sc->lastlmc_taint_tx &&
Krzysztof Hałasa64bef762008-07-02 20:46:21 +0200676 sc->lmc_device->stats.tx_packets > sc->lasttx_packets &&
677 sc->tx_TimeoutInd == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678 {
679
680 /* wait for the watchdog to come around again */
681 sc->tx_TimeoutInd = 1;
682 }
683 else if (sc->lmc_taint_tx == sc->lastlmc_taint_tx &&
Krzysztof Hałasa64bef762008-07-02 20:46:21 +0200684 sc->lmc_device->stats.tx_packets > sc->lasttx_packets &&
685 sc->tx_TimeoutInd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 {
687
688 LMC_EVENT_LOG(LMC_EVENT_XMTINTTMO, LMC_CSR_READ (sc, csr_status), 0);
689
690 sc->tx_TimeoutDisplay = 1;
Krzysztof Hałasa64bef762008-07-02 20:46:21 +0200691 sc->extra_stats.tx_TimeoutCnt++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692
693 /* DEC chip is stuck, hit it with a RESET!!!! */
694 lmc_running_reset (dev);
695
696
697 /* look at receive & transmit process state to make sure they are running */
698 LMC_EVENT_LOG(LMC_EVENT_RESET1, LMC_CSR_READ (sc, csr_status), 0);
699
700 /* look at: DSR - 02 for Reg 16
701 * CTS - 08
702 * DCD - 10
703 * RI - 20
704 * for Reg 17
705 */
706 LMC_EVENT_LOG(LMC_EVENT_RESET2, lmc_mii_readreg (sc, 0, 16), lmc_mii_readreg (sc, 0, 17));
707
708 /* reset the transmit timeout detection flag */
709 sc->tx_TimeoutInd = 0;
710 sc->lastlmc_taint_tx = sc->lmc_taint_tx;
Krzysztof Hałasa64bef762008-07-02 20:46:21 +0200711 sc->lasttx_packets = sc->lmc_device->stats.tx_packets;
712 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713 sc->tx_TimeoutInd = 0;
714 sc->lastlmc_taint_tx = sc->lmc_taint_tx;
Krzysztof Hałasa64bef762008-07-02 20:46:21 +0200715 sc->lasttx_packets = sc->lmc_device->stats.tx_packets;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716 }
717
718 /* --- end time out check ----------------------------------- */
719
720
721 link_status = sc->lmc_media->get_link_status (sc);
722
723 /*
724 * hardware level link lost, but the interface is marked as up.
725 * Mark it as down.
726 */
727 if ((link_status == 0) && (sc->last_link_status != 0)) {
728 printk(KERN_WARNING "%s: hardware/physical link down\n", dev->name);
729 sc->last_link_status = 0;
730 /* lmc_reset (sc); Why reset??? The link can go down ok */
731
732 /* Inform the world that link has been lost */
7d17c1d2005-05-12 19:45:25 -0400733 netif_carrier_off(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734 }
735
736 /*
737 * hardware link is up, but the interface is marked as down.
738 * Bring it back up again.
739 */
740 if (link_status != 0 && sc->last_link_status == 0) {
741 printk(KERN_WARNING "%s: hardware/physical link up\n", dev->name);
742 sc->last_link_status = 1;
743 /* lmc_reset (sc); Again why reset??? */
744
7d17c1d2005-05-12 19:45:25 -0400745 netif_carrier_on(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746 }
747
748 /* Call media specific watchdog functions */
749 sc->lmc_media->watchdog(sc);
750
751 /*
752 * Poke the transmitter to make sure it
753 * never stops, even if we run out of mem
754 */
755 LMC_CSR_WRITE(sc, csr_rxpoll, 0);
756
757 /*
758 * Check for code that failed
759 * and try and fix it as appropriate
760 */
761 if(sc->failed_ring == 1){
762 /*
763 * Failed to setup the recv/xmit rin
764 * Try again
765 */
766 sc->failed_ring = 0;
767 lmc_softreset(sc);
768 }
769 if(sc->failed_recv_alloc == 1){
770 /*
771 * We failed to alloc mem in the
772 * interrupt handler, go through the rings
773 * and rebuild them
774 */
775 sc->failed_recv_alloc = 0;
776 lmc_softreset(sc);
777 }
778
779
780 /*
781 * remember the timer value
782 */
783kick_timer:
784
785 ticks = LMC_CSR_READ (sc, csr_gp_timer);
786 LMC_CSR_WRITE (sc, csr_gp_timer, 0xffffffffUL);
787 sc->ictl.ticks = 0x0000ffff - (ticks & 0x0000ffff);
788
789 /*
790 * restart this timer.
791 */
792 sc->timer.expires = jiffies + (HZ);
793 add_timer (&sc->timer);
794
795 spin_unlock_irqrestore(&sc->lmc_lock, flags);
796
797 lmc_trace(dev, "lmc_watchdog out");
798
799}
800
Krzysztof Hałasa64bef762008-07-02 20:46:21 +0200801static int lmc_attach(struct net_device *dev, unsigned short encoding,
802 unsigned short parity)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803{
Krzysztof Hałasa64bef762008-07-02 20:46:21 +0200804 if (encoding == ENCODING_NRZ && parity == PARITY_CRC16_PR1_CCITT)
805 return 0;
806 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807}
808
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809static int __devinit lmc_init_one(struct pci_dev *pdev,
810 const struct pci_device_id *ent)
811{
Krzysztof Hałasa64bef762008-07-02 20:46:21 +0200812 lmc_softc_t *sc;
813 struct net_device *dev;
814 u16 subdevice;
815 u16 AdapModelNum;
816 int err;
817 static int cards_found;
818
819 /* lmc_trace(dev, "lmc_init_one in"); */
820
821 err = pci_enable_device(pdev);
822 if (err) {
823 printk(KERN_ERR "lmc: pci enable failed: %d\n", err);
824 return err;
825 }
826
827 err = pci_request_regions(pdev, "lmc");
828 if (err) {
829 printk(KERN_ERR "lmc: pci_request_region failed\n");
830 goto err_req_io;
831 }
832
833 /*
834 * Allocate our own device structure
835 */
836 sc = kzalloc(sizeof(lmc_softc_t), GFP_KERNEL);
837 if (!sc) {
838 err = -ENOMEM;
839 goto err_kzalloc;
840 }
841
842 dev = alloc_hdlcdev(sc);
843 if (!dev) {
844 printk(KERN_ERR "lmc:alloc_netdev for device failed\n");
845 goto err_hdlcdev;
846 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847
848
Krzysztof Hałasa64bef762008-07-02 20:46:21 +0200849 dev->type = ARPHRD_HDLC;
850 dev_to_hdlc(dev)->xmit = lmc_start_xmit;
851 dev_to_hdlc(dev)->attach = lmc_attach;
852 dev->open = lmc_open;
853 dev->stop = lmc_close;
854 dev->get_stats = lmc_get_stats;
855 dev->do_ioctl = lmc_ioctl;
856 dev->tx_timeout = lmc_driver_timeout;
857 dev->watchdog_timeo = HZ; /* 1 second */
858 dev->tx_queue_len = 100;
859 sc->lmc_device = dev;
860 sc->name = dev->name;
861 sc->if_type = LMC_PPP;
862 sc->check = 0xBEAFCAFE;
863 dev->base_addr = pci_resource_start(pdev, 0);
864 dev->irq = pdev->irq;
865 pci_set_drvdata(pdev, dev);
866 SET_NETDEV_DEV(dev, &pdev->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867
Krzysztof Hałasa64bef762008-07-02 20:46:21 +0200868 /*
869 * This will get the protocol layer ready and do any 1 time init's
870 * Must have a valid sc and dev structure
871 */
872 lmc_proto_attach(sc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873
Krzysztof Hałasa64bef762008-07-02 20:46:21 +0200874 /* Init the spin lock so can call it latter */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875
Krzysztof Hałasa64bef762008-07-02 20:46:21 +0200876 spin_lock_init(&sc->lmc_lock);
877 pci_set_master(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878
Krzysztof Hałasa64bef762008-07-02 20:46:21 +0200879 printk(KERN_INFO "%s: detected at %lx, irq %d\n", dev->name,
880 dev->base_addr, dev->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881
Krzysztof Hałasa64bef762008-07-02 20:46:21 +0200882 err = register_hdlc_device(dev);
883 if (err) {
884 printk(KERN_ERR "%s: register_netdev failed.\n", dev->name);
885 free_netdev(dev);
886 goto err_hdlcdev;
887 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888
889 sc->lmc_cardtype = LMC_CARDTYPE_UNKNOWN;
890 sc->lmc_timing = LMC_CTL_CLOCK_SOURCE_EXT;
891
892 /*
893 *
894 * Check either the subvendor or the subdevice, some systems reverse
895 * the setting in the bois, seems to be version and arch dependent?
896 * Fix the error, exchange the two values
897 */
898 if ((subdevice = pdev->subsystem_device) == PCI_VENDOR_ID_LMC)
899 subdevice = pdev->subsystem_vendor;
900
901 switch (subdevice) {
902 case PCI_DEVICE_ID_LMC_HSSI:
Krzysztof Hałasa64bef762008-07-02 20:46:21 +0200903 printk(KERN_INFO "%s: LMC HSSI\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904 sc->lmc_cardtype = LMC_CARDTYPE_HSSI;
905 sc->lmc_media = &lmc_hssi_media;
906 break;
907 case PCI_DEVICE_ID_LMC_DS3:
Krzysztof Hałasa64bef762008-07-02 20:46:21 +0200908 printk(KERN_INFO "%s: LMC DS3\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909 sc->lmc_cardtype = LMC_CARDTYPE_DS3;
910 sc->lmc_media = &lmc_ds3_media;
911 break;
912 case PCI_DEVICE_ID_LMC_SSI:
Krzysztof Hałasa64bef762008-07-02 20:46:21 +0200913 printk(KERN_INFO "%s: LMC SSI\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914 sc->lmc_cardtype = LMC_CARDTYPE_SSI;
915 sc->lmc_media = &lmc_ssi_media;
916 break;
917 case PCI_DEVICE_ID_LMC_T1:
Krzysztof Hałasa64bef762008-07-02 20:46:21 +0200918 printk(KERN_INFO "%s: LMC T1\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919 sc->lmc_cardtype = LMC_CARDTYPE_T1;
920 sc->lmc_media = &lmc_t1_media;
921 break;
922 default:
Krzysztof Hałasa64bef762008-07-02 20:46:21 +0200923 printk(KERN_WARNING "%s: LMC UNKOWN CARD!\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924 break;
925 }
926
927 lmc_initcsrs (sc, dev->base_addr, 8);
928
929 lmc_gpio_mkinput (sc, 0xff);
930 sc->lmc_gpio = 0; /* drive no signals yet */
931
932 sc->lmc_media->defaults (sc);
933
934 sc->lmc_media->set_link_status (sc, LMC_LINK_UP);
935
936 /* verify that the PCI Sub System ID matches the Adapter Model number
937 * from the MII register
938 */
939 AdapModelNum = (lmc_mii_readreg (sc, 0, 3) & 0x3f0) >> 4;
940
Krzysztof Hałasa64bef762008-07-02 20:46:21 +0200941 if ((AdapModelNum != LMC_ADAP_T1 || /* detect LMC1200 */
942 subdevice != PCI_DEVICE_ID_LMC_T1) &&
943 (AdapModelNum != LMC_ADAP_SSI || /* detect LMC1000 */
944 subdevice != PCI_DEVICE_ID_LMC_SSI) &&
945 (AdapModelNum != LMC_ADAP_DS3 || /* detect LMC5245 */
946 subdevice != PCI_DEVICE_ID_LMC_DS3) &&
947 (AdapModelNum != LMC_ADAP_HSSI || /* detect LMC5200 */
948 subdevice != PCI_DEVICE_ID_LMC_HSSI))
949 printk(KERN_WARNING "%s: Model number (%d) miscompare for PCI"
950 " Subsystem ID = 0x%04x\n",
951 dev->name, AdapModelNum, subdevice);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953 /*
954 * reset clock
955 */
956 LMC_CSR_WRITE (sc, csr_gp_timer, 0xFFFFFFFFUL);
957
958 sc->board_idx = cards_found++;
Krzysztof Hałasa64bef762008-07-02 20:46:21 +0200959 sc->extra_stats.check = STATCHECK;
960 sc->extra_stats.version_size = (DRIVER_VERSION << 16) +
961 sizeof(sc->lmc_device->stats) + sizeof(sc->extra_stats);
962 sc->extra_stats.lmc_cardtype = sc->lmc_cardtype;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963
964 sc->lmc_ok = 0;
965 sc->last_link_status = 0;
966
967 lmc_trace(dev, "lmc_init_one out");
968 return 0;
969
Krzysztof Hałasa64bef762008-07-02 20:46:21 +0200970err_hdlcdev:
971 pci_set_drvdata(pdev, NULL);
972 kfree(sc);
973err_kzalloc:
974 pci_release_regions(pdev);
975err_req_io:
976 pci_disable_device(pdev);
977 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978}
979
980/*
981 * Called from pci when removing module.
982 */
Krzysztof Hałasa64bef762008-07-02 20:46:21 +0200983static void __devexit lmc_remove_one(struct pci_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984{
Krzysztof Hałasa64bef762008-07-02 20:46:21 +0200985 struct net_device *dev = pci_get_drvdata(pdev);
986
987 if (dev) {
988 printk(KERN_DEBUG "%s: removing...\n", dev->name);
989 unregister_hdlc_device(dev);
990 free_netdev(dev);
991 pci_release_regions(pdev);
992 pci_disable_device(pdev);
993 pci_set_drvdata(pdev, NULL);
994 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995}
996
997/* After this is called, packets can be sent.
998 * Does not initialize the addresses
999 */
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02001000static int lmc_open(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001{
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02001002 lmc_softc_t *sc = dev_to_sc(dev);
1003 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004
1005 lmc_trace(dev, "lmc_open in");
1006
1007 lmc_led_on(sc, LMC_DS3_LED0);
1008
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02001009 lmc_dec_reset(sc);
1010 lmc_reset(sc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02001012 LMC_EVENT_LOG(LMC_EVENT_RESET1, LMC_CSR_READ(sc, csr_status), 0);
1013 LMC_EVENT_LOG(LMC_EVENT_RESET2, lmc_mii_readreg(sc, 0, 16),
1014 lmc_mii_readreg(sc, 0, 17));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015
1016 if (sc->lmc_ok){
1017 lmc_trace(dev, "lmc_open lmc_ok out");
1018 return (0);
1019 }
1020
1021 lmc_softreset (sc);
1022
1023 /* Since we have to use PCI bus, this should work on x86,alpha,ppc */
Thomas Gleixner1fb9df52006-07-01 19:29:39 -07001024 if (request_irq (dev->irq, &lmc_interrupt, IRQF_SHARED, dev->name, dev)){
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025 printk(KERN_WARNING "%s: could not get irq: %d\n", dev->name, dev->irq);
1026 lmc_trace(dev, "lmc_open irq failed out");
1027 return -EAGAIN;
1028 }
1029 sc->got_irq = 1;
1030
1031 /* Assert Terminal Active */
1032 sc->lmc_miireg16 |= LMC_MII16_LED_ALL;
1033 sc->lmc_media->set_link_status (sc, LMC_LINK_UP);
1034
1035 /*
1036 * reset to last state.
1037 */
1038 sc->lmc_media->set_status (sc, NULL);
1039
1040 /* setup default bits to be used in tulip_desc_t transmit descriptor
1041 * -baz */
1042 sc->TxDescriptControlInit = (
1043 LMC_TDES_INTERRUPT_ON_COMPLETION
1044 | LMC_TDES_FIRST_SEGMENT
1045 | LMC_TDES_LAST_SEGMENT
1046 | LMC_TDES_SECOND_ADDR_CHAINED
1047 | LMC_TDES_DISABLE_PADDING
1048 );
1049
1050 if (sc->ictl.crc_length == LMC_CTL_CRC_LENGTH_16) {
1051 /* disable 32 bit CRC generated by ASIC */
1052 sc->TxDescriptControlInit |= LMC_TDES_ADD_CRC_DISABLE;
1053 }
1054 sc->lmc_media->set_crc_length(sc, sc->ictl.crc_length);
1055 /* Acknoledge the Terminal Active and light LEDs */
1056
1057 /* dev->flags |= IFF_UP; */
1058
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02001059 if ((err = lmc_proto_open(sc)) != 0)
1060 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061
1062 dev->do_ioctl = lmc_ioctl;
1063
1064
1065 netif_start_queue(dev);
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02001066 sc->extra_stats.tx_tbusy0++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067
1068 /*
1069 * select what interrupts we want to get
1070 */
1071 sc->lmc_intrmask = 0;
1072 /* Should be using the default interrupt mask defined in the .h file. */
1073 sc->lmc_intrmask |= (TULIP_STS_NORMALINTR
1074 | TULIP_STS_RXINTR
1075 | TULIP_STS_TXINTR
1076 | TULIP_STS_ABNRMLINTR
1077 | TULIP_STS_SYSERROR
1078 | TULIP_STS_TXSTOPPED
1079 | TULIP_STS_TXUNDERFLOW
1080 | TULIP_STS_RXSTOPPED
1081 | TULIP_STS_RXNOBUF
1082 );
1083 LMC_CSR_WRITE (sc, csr_intr, sc->lmc_intrmask);
1084
1085 sc->lmc_cmdmode |= TULIP_CMD_TXRUN;
1086 sc->lmc_cmdmode |= TULIP_CMD_RXRUN;
1087 LMC_CSR_WRITE (sc, csr_command, sc->lmc_cmdmode);
1088
1089 sc->lmc_ok = 1; /* Run watchdog */
1090
1091 /*
1092 * Set the if up now - pfb
1093 */
1094
1095 sc->last_link_status = 1;
1096
1097 /*
1098 * Setup a timer for the watchdog on probe, and start it running.
1099 * Since lmc_ok == 0, it will be a NOP for now.
1100 */
1101 init_timer (&sc->timer);
1102 sc->timer.expires = jiffies + HZ;
1103 sc->timer.data = (unsigned long) dev;
1104 sc->timer.function = &lmc_watchdog;
1105 add_timer (&sc->timer);
1106
1107 lmc_trace(dev, "lmc_open out");
1108
1109 return (0);
1110}
1111
1112/* Total reset to compensate for the AdTran DSU doing bad things
1113 * under heavy load
1114 */
1115
1116static void lmc_running_reset (struct net_device *dev) /*fold00*/
1117{
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02001118 lmc_softc_t *sc = dev_to_sc(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119
1120 lmc_trace(dev, "lmc_runnig_reset in");
1121
1122 /* stop interrupts */
1123 /* Clear the interrupt mask */
1124 LMC_CSR_WRITE (sc, csr_intr, 0x00000000);
1125
1126 lmc_dec_reset (sc);
1127 lmc_reset (sc);
1128 lmc_softreset (sc);
1129 /* sc->lmc_miireg16 |= LMC_MII16_LED_ALL; */
1130 sc->lmc_media->set_link_status (sc, 1);
1131 sc->lmc_media->set_status (sc, NULL);
1132
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133 netif_wake_queue(dev);
1134
1135 sc->lmc_txfull = 0;
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02001136 sc->extra_stats.tx_tbusy0++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137
1138 sc->lmc_intrmask = TULIP_DEFAULT_INTR_MASK;
1139 LMC_CSR_WRITE (sc, csr_intr, sc->lmc_intrmask);
1140
1141 sc->lmc_cmdmode |= (TULIP_CMD_TXRUN | TULIP_CMD_RXRUN);
1142 LMC_CSR_WRITE (sc, csr_command, sc->lmc_cmdmode);
1143
1144 lmc_trace(dev, "lmc_runnin_reset_out");
1145}
1146
1147
1148/* This is what is called when you ifconfig down a device.
1149 * This disables the timer for the watchdog and keepalives,
1150 * and disables the irq for dev.
1151 */
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02001152static int lmc_close(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153{
1154 /* not calling release_region() as we should */
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02001155 lmc_softc_t *sc = dev_to_sc(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156
1157 lmc_trace(dev, "lmc_close in");
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02001158
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159 sc->lmc_ok = 0;
1160 sc->lmc_media->set_link_status (sc, 0);
1161 del_timer (&sc->timer);
1162 lmc_proto_close(sc);
1163 lmc_ifdown (dev);
1164
1165 lmc_trace(dev, "lmc_close out");
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02001166
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167 return 0;
1168}
1169
1170/* Ends the transfer of packets */
1171/* When the interface goes down, this is called */
1172static int lmc_ifdown (struct net_device *dev) /*fold00*/
1173{
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02001174 lmc_softc_t *sc = dev_to_sc(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175 u32 csr6;
1176 int i;
1177
1178 lmc_trace(dev, "lmc_ifdown in");
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02001179
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180 /* Don't let anything else go on right now */
1181 // dev->start = 0;
1182 netif_stop_queue(dev);
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02001183 sc->extra_stats.tx_tbusy1++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184
1185 /* stop interrupts */
1186 /* Clear the interrupt mask */
1187 LMC_CSR_WRITE (sc, csr_intr, 0x00000000);
1188
1189 /* Stop Tx and Rx on the chip */
1190 csr6 = LMC_CSR_READ (sc, csr_command);
1191 csr6 &= ~LMC_DEC_ST; /* Turn off the Transmission bit */
1192 csr6 &= ~LMC_DEC_SR; /* Turn off the Receive bit */
1193 LMC_CSR_WRITE (sc, csr_command, csr6);
1194
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02001195 sc->lmc_device->stats.rx_missed_errors +=
1196 LMC_CSR_READ(sc, csr_missed_frames) & 0xffff;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197
1198 /* release the interrupt */
1199 if(sc->got_irq == 1){
1200 free_irq (dev->irq, dev);
1201 sc->got_irq = 0;
1202 }
1203
1204 /* free skbuffs in the Rx queue */
1205 for (i = 0; i < LMC_RXDESCS; i++)
1206 {
1207 struct sk_buff *skb = sc->lmc_rxq[i];
1208 sc->lmc_rxq[i] = NULL;
1209 sc->lmc_rxring[i].status = 0;
1210 sc->lmc_rxring[i].length = 0;
1211 sc->lmc_rxring[i].buffer1 = 0xDEADBEEF;
1212 if (skb != NULL)
1213 dev_kfree_skb(skb);
1214 sc->lmc_rxq[i] = NULL;
1215 }
1216
1217 for (i = 0; i < LMC_TXDESCS; i++)
1218 {
1219 if (sc->lmc_txq[i] != NULL)
1220 dev_kfree_skb(sc->lmc_txq[i]);
1221 sc->lmc_txq[i] = NULL;
1222 }
1223
1224 lmc_led_off (sc, LMC_MII16_LED_ALL);
1225
1226 netif_wake_queue(dev);
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02001227 sc->extra_stats.tx_tbusy0++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001228
1229 lmc_trace(dev, "lmc_ifdown out");
1230
1231 return 0;
1232}
1233
1234/* Interrupt handling routine. This will take an incoming packet, or clean
1235 * up after a trasmit.
1236 */
David Howells7d12e782006-10-05 14:55:46 +01001237static irqreturn_t lmc_interrupt (int irq, void *dev_instance) /*fold00*/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001238{
1239 struct net_device *dev = (struct net_device *) dev_instance;
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02001240 lmc_softc_t *sc = dev_to_sc(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241 u32 csr;
1242 int i;
1243 s32 stat;
1244 unsigned int badtx;
1245 u32 firstcsr;
1246 int max_work = LMC_RXDESCS;
1247 int handled = 0;
1248
1249 lmc_trace(dev, "lmc_interrupt in");
1250
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251 spin_lock(&sc->lmc_lock);
1252
1253 /*
1254 * Read the csr to find what interrupts we have (if any)
1255 */
1256 csr = LMC_CSR_READ (sc, csr_status);
1257
1258 /*
1259 * Make sure this is our interrupt
1260 */
1261 if ( ! (csr & sc->lmc_intrmask)) {
1262 goto lmc_int_fail_out;
1263 }
1264
1265 firstcsr = csr;
1266
1267 /* always go through this loop at least once */
1268 while (csr & sc->lmc_intrmask) {
1269 handled = 1;
1270
1271 /*
1272 * Clear interrupt bits, we handle all case below
1273 */
1274 LMC_CSR_WRITE (sc, csr_status, csr);
1275
1276 /*
1277 * One of
1278 * - Transmit process timed out CSR5<1>
1279 * - Transmit jabber timeout CSR5<3>
1280 * - Transmit underflow CSR5<5>
1281 * - Transmit Receiver buffer unavailable CSR5<7>
1282 * - Receive process stopped CSR5<8>
1283 * - Receive watchdog timeout CSR5<9>
1284 * - Early transmit interrupt CSR5<10>
1285 *
1286 * Is this really right? Should we do a running reset for jabber?
1287 * (being a WAN card and all)
1288 */
1289 if (csr & TULIP_STS_ABNRMLINTR){
1290 lmc_running_reset (dev);
1291 break;
1292 }
1293
1294 if (csr & TULIP_STS_RXINTR){
1295 lmc_trace(dev, "rx interrupt");
1296 lmc_rx (dev);
1297
1298 }
1299 if (csr & (TULIP_STS_TXINTR | TULIP_STS_TXNOBUF | TULIP_STS_TXSTOPPED)) {
1300
1301 int n_compl = 0 ;
1302 /* reset the transmit timeout detection flag -baz */
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02001303 sc->extra_stats.tx_NoCompleteCnt = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304
1305 badtx = sc->lmc_taint_tx;
1306 i = badtx % LMC_TXDESCS;
1307
1308 while ((badtx < sc->lmc_next_tx)) {
1309 stat = sc->lmc_txring[i].status;
1310
1311 LMC_EVENT_LOG (LMC_EVENT_XMTINT, stat,
1312 sc->lmc_txring[i].length);
1313 /*
1314 * If bit 31 is 1 the tulip owns it break out of the loop
1315 */
1316 if (stat & 0x80000000)
1317 break;
1318
1319 n_compl++ ; /* i.e., have an empty slot in ring */
1320 /*
1321 * If we have no skbuff or have cleared it
1322 * Already continue to the next buffer
1323 */
1324 if (sc->lmc_txq[i] == NULL)
1325 continue;
1326
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02001327 /*
1328 * Check the total error summary to look for any errors
1329 */
1330 if (stat & 0x8000) {
1331 sc->lmc_device->stats.tx_errors++;
1332 if (stat & 0x4104)
1333 sc->lmc_device->stats.tx_aborted_errors++;
1334 if (stat & 0x0C00)
1335 sc->lmc_device->stats.tx_carrier_errors++;
1336 if (stat & 0x0200)
1337 sc->lmc_device->stats.tx_window_errors++;
1338 if (stat & 0x0002)
1339 sc->lmc_device->stats.tx_fifo_errors++;
1340 } else {
1341 sc->lmc_device->stats.tx_bytes += sc->lmc_txring[i].length & 0x7ff;
1342
1343 sc->lmc_device->stats.tx_packets++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344 }
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02001345
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346 // dev_kfree_skb(sc->lmc_txq[i]);
1347 dev_kfree_skb_irq(sc->lmc_txq[i]);
1348 sc->lmc_txq[i] = NULL;
1349
1350 badtx++;
1351 i = badtx % LMC_TXDESCS;
1352 }
1353
1354 if (sc->lmc_next_tx - badtx > LMC_TXDESCS)
1355 {
1356 printk ("%s: out of sync pointer\n", dev->name);
1357 badtx += LMC_TXDESCS;
1358 }
1359 LMC_EVENT_LOG(LMC_EVENT_TBUSY0, n_compl, 0);
1360 sc->lmc_txfull = 0;
1361 netif_wake_queue(dev);
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02001362 sc->extra_stats.tx_tbusy0++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001363
1364
1365#ifdef DEBUG
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02001366 sc->extra_stats.dirtyTx = badtx;
1367 sc->extra_stats.lmc_next_tx = sc->lmc_next_tx;
1368 sc->extra_stats.lmc_txfull = sc->lmc_txfull;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369#endif
1370 sc->lmc_taint_tx = badtx;
1371
1372 /*
1373 * Why was there a break here???
1374 */
1375 } /* end handle transmit interrupt */
1376
1377 if (csr & TULIP_STS_SYSERROR) {
1378 u32 error;
1379 printk (KERN_WARNING "%s: system bus error csr: %#8.8x\n", dev->name, csr);
1380 error = csr>>23 & 0x7;
1381 switch(error){
1382 case 0x000:
1383 printk(KERN_WARNING "%s: Parity Fault (bad)\n", dev->name);
1384 break;
1385 case 0x001:
1386 printk(KERN_WARNING "%s: Master Abort (naughty)\n", dev->name);
1387 break;
1388 case 0x010:
1389 printk(KERN_WARNING "%s: Target Abort (not so naughty)\n", dev->name);
1390 break;
1391 default:
1392 printk(KERN_WARNING "%s: This bus error code was supposed to be reserved!\n", dev->name);
1393 }
1394 lmc_dec_reset (sc);
1395 lmc_reset (sc);
1396 LMC_EVENT_LOG(LMC_EVENT_RESET1, LMC_CSR_READ (sc, csr_status), 0);
1397 LMC_EVENT_LOG(LMC_EVENT_RESET2,
1398 lmc_mii_readreg (sc, 0, 16),
1399 lmc_mii_readreg (sc, 0, 17));
1400
1401 }
1402
1403
1404 if(max_work-- <= 0)
1405 break;
1406
1407 /*
1408 * Get current csr status to make sure
1409 * we've cleared all interrupts
1410 */
1411 csr = LMC_CSR_READ (sc, csr_status);
1412 } /* end interrupt loop */
1413 LMC_EVENT_LOG(LMC_EVENT_INT, firstcsr, csr);
1414
1415lmc_int_fail_out:
1416
1417 spin_unlock(&sc->lmc_lock);
1418
1419 lmc_trace(dev, "lmc_interrupt out");
1420 return IRQ_RETVAL(handled);
1421}
1422
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02001423static int lmc_start_xmit(struct sk_buff *skb, struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424{
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02001425 lmc_softc_t *sc = dev_to_sc(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426 u32 flag;
1427 int entry;
1428 int ret = 0;
1429 unsigned long flags;
1430
1431 lmc_trace(dev, "lmc_start_xmit in");
1432
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433 spin_lock_irqsave(&sc->lmc_lock, flags);
1434
1435 /* normal path, tbusy known to be zero */
1436
1437 entry = sc->lmc_next_tx % LMC_TXDESCS;
1438
1439 sc->lmc_txq[entry] = skb;
1440 sc->lmc_txring[entry].buffer1 = virt_to_bus (skb->data);
1441
1442 LMC_CONSOLE_LOG("xmit", skb->data, skb->len);
1443
1444#ifndef GCOM
1445 /* If the queue is less than half full, don't interrupt */
1446 if (sc->lmc_next_tx - sc->lmc_taint_tx < LMC_TXDESCS / 2)
1447 {
1448 /* Do not interrupt on completion of this packet */
1449 flag = 0x60000000;
1450 netif_wake_queue(dev);
1451 }
1452 else if (sc->lmc_next_tx - sc->lmc_taint_tx == LMC_TXDESCS / 2)
1453 {
1454 /* This generates an interrupt on completion of this packet */
1455 flag = 0xe0000000;
1456 netif_wake_queue(dev);
1457 }
1458 else if (sc->lmc_next_tx - sc->lmc_taint_tx < LMC_TXDESCS - 1)
1459 {
1460 /* Do not interrupt on completion of this packet */
1461 flag = 0x60000000;
1462 netif_wake_queue(dev);
1463 }
1464 else
1465 {
1466 /* This generates an interrupt on completion of this packet */
1467 flag = 0xe0000000;
1468 sc->lmc_txfull = 1;
1469 netif_stop_queue(dev);
1470 }
1471#else
1472 flag = LMC_TDES_INTERRUPT_ON_COMPLETION;
1473
1474 if (sc->lmc_next_tx - sc->lmc_taint_tx >= LMC_TXDESCS - 1)
1475 { /* ring full, go busy */
1476 sc->lmc_txfull = 1;
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02001477 netif_stop_queue(dev);
1478 sc->extra_stats.tx_tbusy1++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479 LMC_EVENT_LOG(LMC_EVENT_TBUSY1, entry, 0);
1480 }
1481#endif
1482
1483
1484 if (entry == LMC_TXDESCS - 1) /* last descriptor in ring */
1485 flag |= LMC_TDES_END_OF_RING; /* flag as such for Tulip */
1486
1487 /* don't pad small packets either */
1488 flag = sc->lmc_txring[entry].length = (skb->len) | flag |
1489 sc->TxDescriptControlInit;
1490
1491 /* set the transmit timeout flag to be checked in
1492 * the watchdog timer handler. -baz
1493 */
1494
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02001495 sc->extra_stats.tx_NoCompleteCnt++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496 sc->lmc_next_tx++;
1497
1498 /* give ownership to the chip */
1499 LMC_EVENT_LOG(LMC_EVENT_XMT, flag, entry);
1500 sc->lmc_txring[entry].status = 0x80000000;
1501
1502 /* send now! */
1503 LMC_CSR_WRITE (sc, csr_txpoll, 0);
1504
1505 dev->trans_start = jiffies;
1506
1507 spin_unlock_irqrestore(&sc->lmc_lock, flags);
1508
1509 lmc_trace(dev, "lmc_start_xmit_out");
1510 return ret;
1511}
1512
1513
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02001514static int lmc_rx(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515{
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02001516 lmc_softc_t *sc = dev_to_sc(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517 int i;
1518 int rx_work_limit = LMC_RXDESCS;
1519 unsigned int next_rx;
1520 int rxIntLoopCnt; /* debug -baz */
1521 int localLengthErrCnt = 0;
1522 long stat;
1523 struct sk_buff *skb, *nsb;
1524 u16 len;
1525
1526 lmc_trace(dev, "lmc_rx in");
1527
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528 lmc_led_on(sc, LMC_DS3_LED3);
1529
1530 rxIntLoopCnt = 0; /* debug -baz */
1531
1532 i = sc->lmc_next_rx % LMC_RXDESCS;
1533 next_rx = sc->lmc_next_rx;
1534
1535 while (((stat = sc->lmc_rxring[i].status) & LMC_RDES_OWN_BIT) != DESC_OWNED_BY_DC21X4)
1536 {
1537 rxIntLoopCnt++; /* debug -baz */
1538 len = ((stat & LMC_RDES_FRAME_LENGTH) >> RDES_FRAME_LENGTH_BIT_NUMBER);
1539 if ((stat & 0x0300) != 0x0300) { /* Check first segment and last segment */
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02001540 if ((stat & 0x0000ffff) != 0x7fff) {
1541 /* Oversized frame */
1542 sc->lmc_device->stats.rx_length_errors++;
1543 goto skip_packet;
1544 }
1545 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02001547 if (stat & 0x00000008) { /* Catch a dribbling bit error */
1548 sc->lmc_device->stats.rx_errors++;
1549 sc->lmc_device->stats.rx_frame_errors++;
1550 goto skip_packet;
1551 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552
1553
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02001554 if (stat & 0x00000004) { /* Catch a CRC error by the Xilinx */
1555 sc->lmc_device->stats.rx_errors++;
1556 sc->lmc_device->stats.rx_crc_errors++;
1557 goto skip_packet;
1558 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001559
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02001560 if (len > LMC_PKT_BUF_SZ) {
1561 sc->lmc_device->stats.rx_length_errors++;
1562 localLengthErrCnt++;
1563 goto skip_packet;
1564 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001565
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02001566 if (len < sc->lmc_crcSize + 2) {
1567 sc->lmc_device->stats.rx_length_errors++;
1568 sc->extra_stats.rx_SmallPktCnt++;
1569 localLengthErrCnt++;
1570 goto skip_packet;
1571 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001572
1573 if(stat & 0x00004000){
1574 printk(KERN_WARNING "%s: Receiver descriptor error, receiver out of sync?\n", dev->name);
1575 }
1576
1577 len -= sc->lmc_crcSize;
1578
1579 skb = sc->lmc_rxq[i];
1580
1581 /*
1582 * We ran out of memory at some point
1583 * just allocate an skb buff and continue.
1584 */
1585
Al Viro79ea13c2008-01-24 02:06:46 -08001586 if (!skb) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001587 nsb = dev_alloc_skb (LMC_PKT_BUF_SZ + 2);
1588 if (nsb) {
1589 sc->lmc_rxq[i] = nsb;
1590 nsb->dev = dev;
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -07001591 sc->lmc_rxring[i].buffer1 = virt_to_bus(skb_tail_pointer(nsb));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001592 }
1593 sc->failed_recv_alloc = 1;
1594 goto skip_packet;
1595 }
1596
1597 dev->last_rx = jiffies;
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02001598 sc->lmc_device->stats.rx_packets++;
1599 sc->lmc_device->stats.rx_bytes += len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001600
1601 LMC_CONSOLE_LOG("recv", skb->data, len);
1602
1603 /*
1604 * I'm not sure of the sanity of this
1605 * Packets could be arriving at a constant
1606 * 44.210mbits/sec and we're going to copy
1607 * them into a new buffer??
1608 */
1609
1610 if(len > (LMC_MTU - (LMC_MTU>>2))){ /* len > LMC_MTU * 0.75 */
1611 /*
1612 * If it's a large packet don't copy it just hand it up
1613 */
1614 give_it_anyways:
1615
1616 sc->lmc_rxq[i] = NULL;
1617 sc->lmc_rxring[i].buffer1 = 0x0;
1618
1619 skb_put (skb, len);
1620 skb->protocol = lmc_proto_type(sc, skb);
Arnaldo Carvalho de Melo459a98e2007-03-19 15:30:44 -07001621 skb_reset_mac_header(skb);
Arnaldo Carvalho de Meloc1d2bbe2007-04-10 20:45:18 -07001622 /* skb_reset_network_header(skb); */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001623 skb->dev = dev;
1624 lmc_proto_netif(sc, skb);
1625
1626 /*
1627 * This skb will be destroyed by the upper layers, make a new one
1628 */
1629 nsb = dev_alloc_skb (LMC_PKT_BUF_SZ + 2);
1630 if (nsb) {
1631 sc->lmc_rxq[i] = nsb;
1632 nsb->dev = dev;
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -07001633 sc->lmc_rxring[i].buffer1 = virt_to_bus(skb_tail_pointer(nsb));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001634 /* Transferred to 21140 below */
1635 }
1636 else {
1637 /*
1638 * We've run out of memory, stop trying to allocate
1639 * memory and exit the interrupt handler
1640 *
1641 * The chip may run out of receivers and stop
1642 * in which care we'll try to allocate the buffer
1643 * again. (once a second)
1644 */
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02001645 sc->extra_stats.rx_BuffAllocErr++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001646 LMC_EVENT_LOG(LMC_EVENT_RCVINT, stat, len);
1647 sc->failed_recv_alloc = 1;
1648 goto skip_out_of_mem;
1649 }
1650 }
1651 else {
1652 nsb = dev_alloc_skb(len);
1653 if(!nsb) {
1654 goto give_it_anyways;
1655 }
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001656 skb_copy_from_linear_data(skb, skb_put(nsb, len), len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001657
1658 nsb->protocol = lmc_proto_type(sc, skb);
Arnaldo Carvalho de Melo459a98e2007-03-19 15:30:44 -07001659 skb_reset_mac_header(nsb);
Arnaldo Carvalho de Meloc1d2bbe2007-04-10 20:45:18 -07001660 /* skb_reset_network_header(nsb); */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001661 nsb->dev = dev;
1662 lmc_proto_netif(sc, nsb);
1663 }
1664
1665 skip_packet:
1666 LMC_EVENT_LOG(LMC_EVENT_RCVINT, stat, len);
1667 sc->lmc_rxring[i].status = DESC_OWNED_BY_DC21X4;
1668
1669 sc->lmc_next_rx++;
1670 i = sc->lmc_next_rx % LMC_RXDESCS;
1671 rx_work_limit--;
1672 if (rx_work_limit < 0)
1673 break;
1674 }
1675
1676 /* detect condition for LMC1000 where DSU cable attaches and fills
1677 * descriptors with bogus packets
1678 *
1679 if (localLengthErrCnt > LMC_RXDESCS - 3) {
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02001680 sc->extra_stats.rx_BadPktSurgeCnt++;
1681 LMC_EVENT_LOG(LMC_EVENT_BADPKTSURGE, localLengthErrCnt,
1682 sc->extra_stats.rx_BadPktSurgeCnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001683 } */
1684
1685 /* save max count of receive descriptors serviced */
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02001686 if (rxIntLoopCnt > sc->extra_stats.rxIntLoopCnt)
1687 sc->extra_stats.rxIntLoopCnt = rxIntLoopCnt; /* debug -baz */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001688
1689#ifdef DEBUG
1690 if (rxIntLoopCnt == 0)
1691 {
1692 for (i = 0; i < LMC_RXDESCS; i++)
1693 {
1694 if ((sc->lmc_rxring[i].status & LMC_RDES_OWN_BIT)
1695 != DESC_OWNED_BY_DC21X4)
1696 {
1697 rxIntLoopCnt++;
1698 }
1699 }
1700 LMC_EVENT_LOG(LMC_EVENT_RCVEND, rxIntLoopCnt, 0);
1701 }
1702#endif
1703
1704
1705 lmc_led_off(sc, LMC_DS3_LED3);
1706
1707skip_out_of_mem:
1708
1709 lmc_trace(dev, "lmc_rx out");
1710
1711 return 0;
1712}
1713
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02001714static struct net_device_stats *lmc_get_stats(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001715{
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02001716 lmc_softc_t *sc = dev_to_sc(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001717 unsigned long flags;
1718
1719 lmc_trace(dev, "lmc_get_stats in");
1720
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721 spin_lock_irqsave(&sc->lmc_lock, flags);
1722
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02001723 sc->lmc_device->stats.rx_missed_errors += LMC_CSR_READ(sc, csr_missed_frames) & 0xffff;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001724
1725 spin_unlock_irqrestore(&sc->lmc_lock, flags);
1726
1727 lmc_trace(dev, "lmc_get_stats out");
1728
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02001729 return &sc->lmc_device->stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001730}
1731
1732static struct pci_driver lmc_driver = {
1733 .name = "lmc",
1734 .id_table = lmc_pci_tbl,
1735 .probe = lmc_init_one,
1736 .remove = __devexit_p(lmc_remove_one),
1737};
1738
1739static int __init init_lmc(void)
1740{
Jeff Garzik29917622006-08-19 17:48:59 -04001741 return pci_register_driver(&lmc_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001742}
1743
1744static void __exit exit_lmc(void)
1745{
1746 pci_unregister_driver(&lmc_driver);
1747}
1748
1749module_init(init_lmc);
1750module_exit(exit_lmc);
1751
1752unsigned lmc_mii_readreg (lmc_softc_t * const sc, unsigned devaddr, unsigned regno) /*fold00*/
1753{
1754 int i;
1755 int command = (0xf6 << 10) | (devaddr << 5) | regno;
1756 int retval = 0;
1757
1758 lmc_trace(sc->lmc_device, "lmc_mii_readreg in");
1759
1760 LMC_MII_SYNC (sc);
1761
1762 lmc_trace(sc->lmc_device, "lmc_mii_readreg: done sync");
1763
1764 for (i = 15; i >= 0; i--)
1765 {
1766 int dataval = (command & (1 << i)) ? 0x20000 : 0;
1767
1768 LMC_CSR_WRITE (sc, csr_9, dataval);
1769 lmc_delay ();
1770 /* __SLOW_DOWN_IO; */
1771 LMC_CSR_WRITE (sc, csr_9, dataval | 0x10000);
1772 lmc_delay ();
1773 /* __SLOW_DOWN_IO; */
1774 }
1775
1776 lmc_trace(sc->lmc_device, "lmc_mii_readreg: done1");
1777
1778 for (i = 19; i > 0; i--)
1779 {
1780 LMC_CSR_WRITE (sc, csr_9, 0x40000);
1781 lmc_delay ();
1782 /* __SLOW_DOWN_IO; */
1783 retval = (retval << 1) | ((LMC_CSR_READ (sc, csr_9) & 0x80000) ? 1 : 0);
1784 LMC_CSR_WRITE (sc, csr_9, 0x40000 | 0x10000);
1785 lmc_delay ();
1786 /* __SLOW_DOWN_IO; */
1787 }
1788
1789 lmc_trace(sc->lmc_device, "lmc_mii_readreg out");
1790
1791 return (retval >> 1) & 0xffff;
1792}
1793
1794void lmc_mii_writereg (lmc_softc_t * const sc, unsigned devaddr, unsigned regno, unsigned data) /*fold00*/
1795{
1796 int i = 32;
1797 int command = (0x5002 << 16) | (devaddr << 23) | (regno << 18) | data;
1798
1799 lmc_trace(sc->lmc_device, "lmc_mii_writereg in");
1800
1801 LMC_MII_SYNC (sc);
1802
1803 i = 31;
1804 while (i >= 0)
1805 {
1806 int datav;
1807
1808 if (command & (1 << i))
1809 datav = 0x20000;
1810 else
1811 datav = 0x00000;
1812
1813 LMC_CSR_WRITE (sc, csr_9, datav);
1814 lmc_delay ();
1815 /* __SLOW_DOWN_IO; */
1816 LMC_CSR_WRITE (sc, csr_9, (datav | 0x10000));
1817 lmc_delay ();
1818 /* __SLOW_DOWN_IO; */
1819 i--;
1820 }
1821
1822 i = 2;
1823 while (i > 0)
1824 {
1825 LMC_CSR_WRITE (sc, csr_9, 0x40000);
1826 lmc_delay ();
1827 /* __SLOW_DOWN_IO; */
1828 LMC_CSR_WRITE (sc, csr_9, 0x50000);
1829 lmc_delay ();
1830 /* __SLOW_DOWN_IO; */
1831 i--;
1832 }
1833
1834 lmc_trace(sc->lmc_device, "lmc_mii_writereg out");
1835}
1836
1837static void lmc_softreset (lmc_softc_t * const sc) /*fold00*/
1838{
1839 int i;
1840
1841 lmc_trace(sc->lmc_device, "lmc_softreset in");
1842
1843 /* Initialize the receive rings and buffers. */
1844 sc->lmc_txfull = 0;
1845 sc->lmc_next_rx = 0;
1846 sc->lmc_next_tx = 0;
1847 sc->lmc_taint_rx = 0;
1848 sc->lmc_taint_tx = 0;
1849
1850 /*
1851 * Setup each one of the receiver buffers
1852 * allocate an skbuff for each one, setup the descriptor table
1853 * and point each buffer at the next one
1854 */
1855
1856 for (i = 0; i < LMC_RXDESCS; i++)
1857 {
1858 struct sk_buff *skb;
1859
1860 if (sc->lmc_rxq[i] == NULL)
1861 {
1862 skb = dev_alloc_skb (LMC_PKT_BUF_SZ + 2);
1863 if(skb == NULL){
1864 printk(KERN_WARNING "%s: Failed to allocate receiver ring, will try again\n", sc->name);
1865 sc->failed_ring = 1;
1866 break;
1867 }
1868 else{
1869 sc->lmc_rxq[i] = skb;
1870 }
1871 }
1872 else
1873 {
1874 skb = sc->lmc_rxq[i];
1875 }
1876
1877 skb->dev = sc->lmc_device;
1878
1879 /* owned by 21140 */
1880 sc->lmc_rxring[i].status = 0x80000000;
1881
1882 /* 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 -03001883 sc->lmc_rxring[i].length = skb_tailroom(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001884
1885 /* use to be tail which is dumb since you're thinking why write
1886 * to the end of the packj,et but since there's nothing there tail == data
1887 */
1888 sc->lmc_rxring[i].buffer1 = virt_to_bus (skb->data);
1889
1890 /* This is fair since the structure is static and we have the next address */
1891 sc->lmc_rxring[i].buffer2 = virt_to_bus (&sc->lmc_rxring[i + 1]);
1892
1893 }
1894
1895 /*
1896 * Sets end of ring
1897 */
1898 sc->lmc_rxring[i - 1].length |= 0x02000000; /* Set end of buffers flag */
1899 sc->lmc_rxring[i - 1].buffer2 = virt_to_bus (&sc->lmc_rxring[0]); /* Point back to the start */
1900 LMC_CSR_WRITE (sc, csr_rxlist, virt_to_bus (sc->lmc_rxring)); /* write base address */
1901
1902
1903 /* Initialize the transmit rings and buffers */
1904 for (i = 0; i < LMC_TXDESCS; i++)
1905 {
1906 if (sc->lmc_txq[i] != NULL){ /* have buffer */
1907 dev_kfree_skb(sc->lmc_txq[i]); /* free it */
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02001908 sc->lmc_device->stats.tx_dropped++; /* We just dropped a packet */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001909 }
1910 sc->lmc_txq[i] = NULL;
1911 sc->lmc_txring[i].status = 0x00000000;
1912 sc->lmc_txring[i].buffer2 = virt_to_bus (&sc->lmc_txring[i + 1]);
1913 }
1914 sc->lmc_txring[i - 1].buffer2 = virt_to_bus (&sc->lmc_txring[0]);
1915 LMC_CSR_WRITE (sc, csr_txlist, virt_to_bus (sc->lmc_txring));
1916
1917 lmc_trace(sc->lmc_device, "lmc_softreset out");
1918}
1919
Krzysztof Hałasa867240f2008-07-03 00:39:46 +02001920void lmc_gpio_mkinput(lmc_softc_t * const sc, u32 bits) /*fold00*/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001921{
1922 lmc_trace(sc->lmc_device, "lmc_gpio_mkinput in");
1923 sc->lmc_gpio_io &= ~bits;
1924 LMC_CSR_WRITE(sc, csr_gp, TULIP_GP_PINSET | (sc->lmc_gpio_io));
1925 lmc_trace(sc->lmc_device, "lmc_gpio_mkinput out");
1926}
1927
Krzysztof Hałasa867240f2008-07-03 00:39:46 +02001928void lmc_gpio_mkoutput(lmc_softc_t * const sc, u32 bits) /*fold00*/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001929{
1930 lmc_trace(sc->lmc_device, "lmc_gpio_mkoutput in");
1931 sc->lmc_gpio_io |= bits;
1932 LMC_CSR_WRITE(sc, csr_gp, TULIP_GP_PINSET | (sc->lmc_gpio_io));
1933 lmc_trace(sc->lmc_device, "lmc_gpio_mkoutput out");
1934}
1935
Krzysztof Hałasa867240f2008-07-03 00:39:46 +02001936void lmc_led_on(lmc_softc_t * const sc, u32 led) /*fold00*/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001937{
1938 lmc_trace(sc->lmc_device, "lmc_led_on in");
1939 if((~sc->lmc_miireg16) & led){ /* Already on! */
1940 lmc_trace(sc->lmc_device, "lmc_led_on aon out");
1941 return;
1942 }
1943
1944 sc->lmc_miireg16 &= ~led;
1945 lmc_mii_writereg(sc, 0, 16, sc->lmc_miireg16);
1946 lmc_trace(sc->lmc_device, "lmc_led_on out");
1947}
1948
Krzysztof Hałasa867240f2008-07-03 00:39:46 +02001949void lmc_led_off(lmc_softc_t * const sc, u32 led) /*fold00*/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001950{
1951 lmc_trace(sc->lmc_device, "lmc_led_off in");
1952 if(sc->lmc_miireg16 & led){ /* Already set don't do anything */
1953 lmc_trace(sc->lmc_device, "lmc_led_off aoff out");
1954 return;
1955 }
1956
1957 sc->lmc_miireg16 |= led;
1958 lmc_mii_writereg(sc, 0, 16, sc->lmc_miireg16);
1959 lmc_trace(sc->lmc_device, "lmc_led_off out");
1960}
1961
1962static void lmc_reset(lmc_softc_t * const sc) /*fold00*/
1963{
1964 lmc_trace(sc->lmc_device, "lmc_reset in");
1965 sc->lmc_miireg16 |= LMC_MII16_FIFO_RESET;
1966 lmc_mii_writereg(sc, 0, 16, sc->lmc_miireg16);
1967
1968 sc->lmc_miireg16 &= ~LMC_MII16_FIFO_RESET;
1969 lmc_mii_writereg(sc, 0, 16, sc->lmc_miireg16);
1970
1971 /*
1972 * make some of the GPIO pins be outputs
1973 */
1974 lmc_gpio_mkoutput(sc, LMC_GEP_RESET);
1975
1976 /*
1977 * RESET low to force state reset. This also forces
1978 * the transmitter clock to be internal, but we expect to reset
1979 * that later anyway.
1980 */
1981 sc->lmc_gpio &= ~(LMC_GEP_RESET);
1982 LMC_CSR_WRITE(sc, csr_gp, sc->lmc_gpio);
1983
1984 /*
1985 * hold for more than 10 microseconds
1986 */
1987 udelay(50);
1988
1989 /*
1990 * stop driving Xilinx-related signals
1991 */
1992 lmc_gpio_mkinput(sc, LMC_GEP_RESET);
1993
1994 /*
1995 * Call media specific init routine
1996 */
1997 sc->lmc_media->init(sc);
1998
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02001999 sc->extra_stats.resetCount++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002000 lmc_trace(sc->lmc_device, "lmc_reset out");
2001}
2002
2003static void lmc_dec_reset(lmc_softc_t * const sc) /*fold00*/
2004{
Krzysztof Hałasa867240f2008-07-03 00:39:46 +02002005 u32 val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002006 lmc_trace(sc->lmc_device, "lmc_dec_reset in");
2007
2008 /*
2009 * disable all interrupts
2010 */
2011 sc->lmc_intrmask = 0;
2012 LMC_CSR_WRITE(sc, csr_intr, sc->lmc_intrmask);
2013
2014 /*
2015 * Reset the chip with a software reset command.
2016 * Wait 10 microseconds (actually 50 PCI cycles but at
2017 * 33MHz that comes to two microseconds but wait a
2018 * bit longer anyways)
2019 */
2020 LMC_CSR_WRITE(sc, csr_busmode, TULIP_BUSMODE_SWRESET);
2021 udelay(25);
2022#ifdef __sparc__
2023 sc->lmc_busmode = LMC_CSR_READ(sc, csr_busmode);
2024 sc->lmc_busmode = 0x00100000;
2025 sc->lmc_busmode &= ~TULIP_BUSMODE_SWRESET;
2026 LMC_CSR_WRITE(sc, csr_busmode, sc->lmc_busmode);
2027#endif
2028 sc->lmc_cmdmode = LMC_CSR_READ(sc, csr_command);
2029
2030 /*
2031 * We want:
2032 * no ethernet address in frames we write
2033 * disable padding (txdesc, padding disable)
2034 * ignore runt frames (rdes0 bit 15)
2035 * no receiver watchdog or transmitter jabber timer
2036 * (csr15 bit 0,14 == 1)
2037 * if using 16-bit CRC, turn off CRC (trans desc, crc disable)
2038 */
2039
2040 sc->lmc_cmdmode |= ( TULIP_CMD_PROMISCUOUS
2041 | TULIP_CMD_FULLDUPLEX
2042 | TULIP_CMD_PASSBADPKT
2043 | TULIP_CMD_NOHEARTBEAT
2044 | TULIP_CMD_PORTSELECT
2045 | TULIP_CMD_RECEIVEALL
2046 | TULIP_CMD_MUSTBEONE
2047 );
2048 sc->lmc_cmdmode &= ~( TULIP_CMD_OPERMODE
2049 | TULIP_CMD_THRESHOLDCTL
2050 | TULIP_CMD_STOREFWD
2051 | TULIP_CMD_TXTHRSHLDCTL
2052 );
2053
2054 LMC_CSR_WRITE(sc, csr_command, sc->lmc_cmdmode);
2055
2056 /*
2057 * disable receiver watchdog and transmit jabber
2058 */
2059 val = LMC_CSR_READ(sc, csr_sia_general);
2060 val |= (TULIP_WATCHDOG_TXDISABLE | TULIP_WATCHDOG_RXDISABLE);
2061 LMC_CSR_WRITE(sc, csr_sia_general, val);
2062
2063 lmc_trace(sc->lmc_device, "lmc_dec_reset out");
2064}
2065
2066static void lmc_initcsrs(lmc_softc_t * const sc, lmc_csrptr_t csr_base, /*fold00*/
2067 size_t csr_size)
2068{
2069 lmc_trace(sc->lmc_device, "lmc_initcsrs in");
2070 sc->lmc_csrs.csr_busmode = csr_base + 0 * csr_size;
2071 sc->lmc_csrs.csr_txpoll = csr_base + 1 * csr_size;
2072 sc->lmc_csrs.csr_rxpoll = csr_base + 2 * csr_size;
2073 sc->lmc_csrs.csr_rxlist = csr_base + 3 * csr_size;
2074 sc->lmc_csrs.csr_txlist = csr_base + 4 * csr_size;
2075 sc->lmc_csrs.csr_status = csr_base + 5 * csr_size;
2076 sc->lmc_csrs.csr_command = csr_base + 6 * csr_size;
2077 sc->lmc_csrs.csr_intr = csr_base + 7 * csr_size;
2078 sc->lmc_csrs.csr_missed_frames = csr_base + 8 * csr_size;
2079 sc->lmc_csrs.csr_9 = csr_base + 9 * csr_size;
2080 sc->lmc_csrs.csr_10 = csr_base + 10 * csr_size;
2081 sc->lmc_csrs.csr_11 = csr_base + 11 * csr_size;
2082 sc->lmc_csrs.csr_12 = csr_base + 12 * csr_size;
2083 sc->lmc_csrs.csr_13 = csr_base + 13 * csr_size;
2084 sc->lmc_csrs.csr_14 = csr_base + 14 * csr_size;
2085 sc->lmc_csrs.csr_15 = csr_base + 15 * csr_size;
2086 lmc_trace(sc->lmc_device, "lmc_initcsrs out");
2087}
2088
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02002089static void lmc_driver_timeout(struct net_device *dev)
2090{
2091 lmc_softc_t *sc = dev_to_sc(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002092 u32 csr6;
2093 unsigned long flags;
2094
2095 lmc_trace(dev, "lmc_driver_timeout in");
2096
Linus Torvalds1da177e2005-04-16 15:20:36 -07002097 spin_lock_irqsave(&sc->lmc_lock, flags);
2098
2099 printk("%s: Xmitter busy|\n", dev->name);
2100
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02002101 sc->extra_stats.tx_tbusy_calls++;
2102 if (jiffies - dev->trans_start < TX_TIMEOUT)
2103 goto bug_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002104
2105 /*
2106 * Chip seems to have locked up
2107 * Reset it
2108 * This whips out all our decriptor
2109 * table and starts from scartch
2110 */
2111
2112 LMC_EVENT_LOG(LMC_EVENT_XMTPRCTMO,
2113 LMC_CSR_READ (sc, csr_status),
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02002114 sc->extra_stats.tx_ProcTimeout);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002115
2116 lmc_running_reset (dev);
2117
2118 LMC_EVENT_LOG(LMC_EVENT_RESET1, LMC_CSR_READ (sc, csr_status), 0);
2119 LMC_EVENT_LOG(LMC_EVENT_RESET2,
2120 lmc_mii_readreg (sc, 0, 16),
2121 lmc_mii_readreg (sc, 0, 17));
2122
2123 /* restart the tx processes */
2124 csr6 = LMC_CSR_READ (sc, csr_command);
2125 LMC_CSR_WRITE (sc, csr_command, csr6 | 0x0002);
2126 LMC_CSR_WRITE (sc, csr_command, csr6 | 0x2002);
2127
2128 /* immediate transmit */
2129 LMC_CSR_WRITE (sc, csr_txpoll, 0);
2130
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02002131 sc->lmc_device->stats.tx_errors++;
2132 sc->extra_stats.tx_ProcTimeout++; /* -baz */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002133
2134 dev->trans_start = jiffies;
2135
2136bug_out:
2137
2138 spin_unlock_irqrestore(&sc->lmc_lock, flags);
2139
2140 lmc_trace(dev, "lmc_driver_timout out");
2141
2142
2143}