1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 1997-2000 LAN Media Corporation (LMC)
4 * All rights reserved. www.lanmedia.com
5 * Generic HDLC port Copyright (C) 2008 Krzysztof Halasa <khc@pm.waw.pl>
7 * This code is written by:
8 * Andrew Stanley-Jones (asj@cban.com)
9 * Rob Braun (bbraun@vix.com),
10 * Michael Graff (explorer@vix.com) and
11 * Matt Thomas (matt@3am-software.com).
18 * Driver for the LanMedia LMC5200, LMC5245, LMC1000, LMC1200 cards.
20 * To control link specific options lmcctl is required.
21 * It can be obtained from ftp.lanmedia.com.
24 * Linux uses the device struct lmc_private to pass private information
27 * The initialization portion of this driver (the lmc_reset() and the
28 * lmc_dec_reset() functions, as well as the led controls and the
29 * lmc_initcsrs() functions.
31 * The watchdog function runs every second and checks to see if
32 * we still have link, and that the timing source is what we expected
33 * it to be. If link is lost, the interface is marked down, and
34 * we no longer can transmit.
37 #include <linux/kernel.h>
38 #include <linux/module.h>
39 #include <linux/string.h>
40 #include <linux/timer.h>
41 #include <linux/ptrace.h>
42 #include <linux/errno.h>
43 #include <linux/ioport.h>
44 #include <linux/slab.h>
45 #include <linux/interrupt.h>
46 #include <linux/pci.h>
47 #include <linux/delay.h>
48 #include <linux/hdlc.h>
50 #include <linux/if_arp.h>
51 #include <linux/netdevice.h>
52 #include <linux/etherdevice.h>
53 #include <linux/skbuff.h>
54 #include <linux/inet.h>
55 #include <linux/bitops.h>
56 #include <asm/processor.h> /* Processor type for cache alignment. */
59 #include <linux/uaccess.h>
60 //#include <asm/spinlock.h>
62 #define DRIVER_MAJOR_VERSION 1
63 #define DRIVER_MINOR_VERSION 34
64 #define DRIVER_SUB_VERSION 0
66 #define DRIVER_VERSION ((DRIVER_MAJOR_VERSION << 8) + DRIVER_MINOR_VERSION)
70 #include "lmc_ioctl.h"
71 #include "lmc_debug.h"
72 #include "lmc_proto.h"
74 static int LMC_PKT_BUF_SZ
= 1542;
76 static const struct pci_device_id lmc_pci_tbl
[] = {
77 { PCI_VENDOR_ID_DEC
, PCI_DEVICE_ID_DEC_TULIP_FAST
,
78 PCI_VENDOR_ID_LMC
, PCI_ANY_ID
},
79 { PCI_VENDOR_ID_DEC
, PCI_DEVICE_ID_DEC_TULIP_FAST
,
80 PCI_ANY_ID
, PCI_VENDOR_ID_LMC
},
84 MODULE_DEVICE_TABLE(pci
, lmc_pci_tbl
);
85 MODULE_LICENSE("GPL v2");
88 static netdev_tx_t
lmc_start_xmit(struct sk_buff
*skb
,
89 struct net_device
*dev
);
90 static int lmc_rx (struct net_device
*dev
);
91 static int lmc_open(struct net_device
*dev
);
92 static int lmc_close(struct net_device
*dev
);
93 static struct net_device_stats
*lmc_get_stats(struct net_device
*dev
);
94 static irqreturn_t
lmc_interrupt(int irq
, void *dev_instance
);
95 static void lmc_initcsrs(lmc_softc_t
* const sc
, lmc_csrptr_t csr_base
, size_t csr_size
);
96 static void lmc_softreset(lmc_softc_t
* const);
97 static void lmc_running_reset(struct net_device
*dev
);
98 static int lmc_ifdown(struct net_device
* const);
99 static void lmc_watchdog(struct timer_list
*t
);
100 static void lmc_reset(lmc_softc_t
* const sc
);
101 static void lmc_dec_reset(lmc_softc_t
* const sc
);
102 static void lmc_driver_timeout(struct net_device
*dev
, unsigned int txqueue
);
105 * linux reserves 16 device specific IOCTLs. We call them
106 * LMCIOC* to control various bits of our world.
108 int lmc_ioctl(struct net_device
*dev
, struct ifreq
*ifr
, int cmd
) /*fold00*/
110 lmc_softc_t
*sc
= dev_to_sc(dev
);
112 int ret
= -EOPNOTSUPP
;
117 * Most functions mess with the structure
118 * Disable interrupts while we do the polling
123 * Return current driver state. Since we keep this up
124 * To date internally, just copy this out to the user.
126 case LMCIOCGINFO
: /*fold01*/
127 if (copy_to_user(ifr
->ifr_data
, &sc
->ictl
, sizeof(lmc_ctl_t
)))
133 case LMCIOCSINFO
: /*fold01*/
134 if (!capable(CAP_NET_ADMIN
)) {
139 if(dev
->flags
& IFF_UP
){
144 if (copy_from_user(&ctl
, ifr
->ifr_data
, sizeof(lmc_ctl_t
))) {
149 spin_lock_irqsave(&sc
->lmc_lock
, flags
);
150 sc
->lmc_media
->set_status (sc
, &ctl
);
152 if(ctl
.crc_length
!= sc
->ictl
.crc_length
) {
153 sc
->lmc_media
->set_crc_length(sc
, ctl
.crc_length
);
154 if (sc
->ictl
.crc_length
== LMC_CTL_CRC_LENGTH_16
)
155 sc
->TxDescriptControlInit
|= LMC_TDES_ADD_CRC_DISABLE
;
157 sc
->TxDescriptControlInit
&= ~LMC_TDES_ADD_CRC_DISABLE
;
159 spin_unlock_irqrestore(&sc
->lmc_lock
, flags
);
164 case LMCIOCIFTYPE
: /*fold01*/
166 u16 old_type
= sc
->if_type
;
169 if (!capable(CAP_NET_ADMIN
)) {
174 if (copy_from_user(&new_type
, ifr
->ifr_data
, sizeof(u16
))) {
180 if (new_type
== old_type
)
183 break; /* no change */
186 spin_lock_irqsave(&sc
->lmc_lock
, flags
);
189 sc
->if_type
= new_type
;
190 lmc_proto_attach(sc
);
191 ret
= lmc_proto_open(sc
);
192 spin_unlock_irqrestore(&sc
->lmc_lock
, flags
);
196 case LMCIOCGETXINFO
: /*fold01*/
197 spin_lock_irqsave(&sc
->lmc_lock
, flags
);
198 sc
->lmc_xinfo
.Magic0
= 0xBEEFCAFE;
200 sc
->lmc_xinfo
.PciCardType
= sc
->lmc_cardtype
;
201 sc
->lmc_xinfo
.PciSlotNumber
= 0;
202 sc
->lmc_xinfo
.DriverMajorVersion
= DRIVER_MAJOR_VERSION
;
203 sc
->lmc_xinfo
.DriverMinorVersion
= DRIVER_MINOR_VERSION
;
204 sc
->lmc_xinfo
.DriverSubVersion
= DRIVER_SUB_VERSION
;
205 sc
->lmc_xinfo
.XilinxRevisionNumber
=
206 lmc_mii_readreg (sc
, 0, 3) & 0xf;
207 sc
->lmc_xinfo
.MaxFrameSize
= LMC_PKT_BUF_SZ
;
208 sc
->lmc_xinfo
.link_status
= sc
->lmc_media
->get_link_status (sc
);
209 sc
->lmc_xinfo
.mii_reg16
= lmc_mii_readreg (sc
, 0, 16);
210 spin_unlock_irqrestore(&sc
->lmc_lock
, flags
);
212 sc
->lmc_xinfo
.Magic1
= 0xDEADBEEF;
214 if (copy_to_user(ifr
->ifr_data
, &sc
->lmc_xinfo
,
215 sizeof(struct lmc_xinfo
)))
222 case LMCIOCGETLMCSTATS
:
223 spin_lock_irqsave(&sc
->lmc_lock
, flags
);
224 if (sc
->lmc_cardtype
== LMC_CARDTYPE_T1
) {
225 lmc_mii_writereg(sc
, 0, 17, T1FRAMER_FERR_LSB
);
226 sc
->extra_stats
.framingBitErrorCount
+=
227 lmc_mii_readreg(sc
, 0, 18) & 0xff;
228 lmc_mii_writereg(sc
, 0, 17, T1FRAMER_FERR_MSB
);
229 sc
->extra_stats
.framingBitErrorCount
+=
230 (lmc_mii_readreg(sc
, 0, 18) & 0xff) << 8;
231 lmc_mii_writereg(sc
, 0, 17, T1FRAMER_LCV_LSB
);
232 sc
->extra_stats
.lineCodeViolationCount
+=
233 lmc_mii_readreg(sc
, 0, 18) & 0xff;
234 lmc_mii_writereg(sc
, 0, 17, T1FRAMER_LCV_MSB
);
235 sc
->extra_stats
.lineCodeViolationCount
+=
236 (lmc_mii_readreg(sc
, 0, 18) & 0xff) << 8;
237 lmc_mii_writereg(sc
, 0, 17, T1FRAMER_AERR
);
238 regVal
= lmc_mii_readreg(sc
, 0, 18) & 0xff;
240 sc
->extra_stats
.lossOfFrameCount
+=
241 (regVal
& T1FRAMER_LOF_MASK
) >> 4;
242 sc
->extra_stats
.changeOfFrameAlignmentCount
+=
243 (regVal
& T1FRAMER_COFA_MASK
) >> 2;
244 sc
->extra_stats
.severelyErroredFrameCount
+=
245 regVal
& T1FRAMER_SEF_MASK
;
247 spin_unlock_irqrestore(&sc
->lmc_lock
, flags
);
248 if (copy_to_user(ifr
->ifr_data
, &sc
->lmc_device
->stats
,
249 sizeof(sc
->lmc_device
->stats
)) ||
250 copy_to_user(ifr
->ifr_data
+ sizeof(sc
->lmc_device
->stats
),
251 &sc
->extra_stats
, sizeof(sc
->extra_stats
)))
257 case LMCIOCCLEARLMCSTATS
:
258 if (!capable(CAP_NET_ADMIN
)) {
263 spin_lock_irqsave(&sc
->lmc_lock
, flags
);
264 memset(&sc
->lmc_device
->stats
, 0, sizeof(sc
->lmc_device
->stats
));
265 memset(&sc
->extra_stats
, 0, sizeof(sc
->extra_stats
));
266 sc
->extra_stats
.check
= STATCHECK
;
267 sc
->extra_stats
.version_size
= (DRIVER_VERSION
<< 16) +
268 sizeof(sc
->lmc_device
->stats
) + sizeof(sc
->extra_stats
);
269 sc
->extra_stats
.lmc_cardtype
= sc
->lmc_cardtype
;
270 spin_unlock_irqrestore(&sc
->lmc_lock
, flags
);
274 case LMCIOCSETCIRCUIT
: /*fold01*/
275 if (!capable(CAP_NET_ADMIN
)){
280 if(dev
->flags
& IFF_UP
){
285 if (copy_from_user(&ctl
, ifr
->ifr_data
, sizeof(lmc_ctl_t
))) {
289 spin_lock_irqsave(&sc
->lmc_lock
, flags
);
290 sc
->lmc_media
->set_circuit_type(sc
, ctl
.circuit_type
);
291 sc
->ictl
.circuit_type
= ctl
.circuit_type
;
292 spin_unlock_irqrestore(&sc
->lmc_lock
, flags
);
297 case LMCIOCRESET
: /*fold01*/
298 if (!capable(CAP_NET_ADMIN
)){
303 spin_lock_irqsave(&sc
->lmc_lock
, flags
);
304 /* Reset driver and bring back to current state */
305 printk (" REG16 before reset +%04x\n", lmc_mii_readreg (sc
, 0, 16));
306 lmc_running_reset (dev
);
307 printk (" REG16 after reset +%04x\n", lmc_mii_readreg (sc
, 0, 16));
309 LMC_EVENT_LOG(LMC_EVENT_FORCEDRESET
, LMC_CSR_READ (sc
, csr_status
), lmc_mii_readreg (sc
, 0, 16));
310 spin_unlock_irqrestore(&sc
->lmc_lock
, flags
);
316 case LMCIOCDUMPEVENTLOG
:
317 if (copy_to_user(ifr
->ifr_data
, &lmcEventLogIndex
, sizeof(u32
))) {
321 if (copy_to_user(ifr
->ifr_data
+ sizeof(u32
), lmcEventLogBuf
,
322 sizeof(lmcEventLogBuf
)))
328 #endif /* end ifdef _DBG_EVENTLOG */
329 case LMCIOCT1CONTROL
: /*fold01*/
330 if (sc
->lmc_cardtype
!= LMC_CARDTYPE_T1
){
335 case LMCIOCXILINX
: /*fold01*/
337 struct lmc_xilinx_control xc
; /*fold02*/
339 if (!capable(CAP_NET_ADMIN
)){
345 * Stop the xwitter whlie we restart the hardware
347 netif_stop_queue(dev
);
349 if (copy_from_user(&xc
, ifr
->ifr_data
, sizeof(struct lmc_xilinx_control
))) {
354 case lmc_xilinx_reset
: /*fold02*/
356 spin_lock_irqsave(&sc
->lmc_lock
, flags
);
357 lmc_mii_readreg (sc
, 0, 16);
360 * Make all of them 0 and make input
362 lmc_gpio_mkinput(sc
, 0xff);
365 * make the reset output
367 lmc_gpio_mkoutput(sc
, LMC_GEP_RESET
);
370 * RESET low to force configuration. This also forces
371 * the transmitter clock to be internal, but we expect to reset
375 sc
->lmc_gpio
&= ~LMC_GEP_RESET
;
376 LMC_CSR_WRITE(sc
, csr_gp
, sc
->lmc_gpio
);
380 * hold for more than 10 microseconds
384 sc
->lmc_gpio
|= LMC_GEP_RESET
;
385 LMC_CSR_WRITE(sc
, csr_gp
, sc
->lmc_gpio
);
389 * stop driving Xilinx-related signals
391 lmc_gpio_mkinput(sc
, 0xff);
393 /* Reset the frammer hardware */
394 sc
->lmc_media
->set_link_status (sc
, 1);
395 sc
->lmc_media
->set_status (sc
, NULL
);
396 // lmc_softreset(sc);
400 for(i
= 0; i
< 5; i
++){
401 lmc_led_on(sc
, LMC_DS3_LED0
);
403 lmc_led_off(sc
, LMC_DS3_LED0
);
404 lmc_led_on(sc
, LMC_DS3_LED1
);
406 lmc_led_off(sc
, LMC_DS3_LED1
);
407 lmc_led_on(sc
, LMC_DS3_LED3
);
409 lmc_led_off(sc
, LMC_DS3_LED3
);
410 lmc_led_on(sc
, LMC_DS3_LED2
);
412 lmc_led_off(sc
, LMC_DS3_LED2
);
415 spin_unlock_irqrestore(&sc
->lmc_lock
, flags
);
424 case lmc_xilinx_load_prom
: /*fold02*/
426 int timeout
= 500000;
427 spin_lock_irqsave(&sc
->lmc_lock
, flags
);
428 lmc_mii_readreg (sc
, 0, 16);
431 * Make all of them 0 and make input
433 lmc_gpio_mkinput(sc
, 0xff);
436 * make the reset output
438 lmc_gpio_mkoutput(sc
, LMC_GEP_DP
| LMC_GEP_RESET
);
441 * RESET low to force configuration. This also forces
442 * the transmitter clock to be internal, but we expect to reset
446 sc
->lmc_gpio
&= ~(LMC_GEP_RESET
| LMC_GEP_DP
);
447 LMC_CSR_WRITE(sc
, csr_gp
, sc
->lmc_gpio
);
451 * hold for more than 10 microseconds
455 sc
->lmc_gpio
|= LMC_GEP_DP
| LMC_GEP_RESET
;
456 LMC_CSR_WRITE(sc
, csr_gp
, sc
->lmc_gpio
);
459 * busy wait for the chip to reset
461 while( (LMC_CSR_READ(sc
, csr_gp
) & LMC_GEP_INIT
) == 0 &&
467 * stop driving Xilinx-related signals
469 lmc_gpio_mkinput(sc
, 0xff);
470 spin_unlock_irqrestore(&sc
->lmc_lock
, flags
);
479 case lmc_xilinx_load
: /*fold02*/
483 int timeout
= 500000;
490 data
= memdup_user(xc
.data
, xc
.len
);
496 printk("%s: Starting load of data Len: %d at 0x%p == 0x%p\n", dev
->name
, xc
.len
, xc
.data
, data
);
498 spin_lock_irqsave(&sc
->lmc_lock
, flags
);
499 lmc_gpio_mkinput(sc
, 0xff);
502 * Clear the Xilinx and start prgramming from the DEC
513 sc
->lmc_gpio
&= ~LMC_GEP_DP
;
514 sc
->lmc_gpio
&= ~LMC_GEP_RESET
;
515 sc
->lmc_gpio
|= LMC_GEP_MODE
;
516 LMC_CSR_WRITE(sc
, csr_gp
, sc
->lmc_gpio
);
518 lmc_gpio_mkoutput(sc
, LMC_GEP_MODE
| LMC_GEP_DP
| LMC_GEP_RESET
);
521 * Wait at least 10 us 20 to be safe
526 * Clear reset and activate programming lines
533 lmc_gpio_mkinput(sc
, LMC_GEP_DP
| LMC_GEP_RESET
);
536 * Set LOAD, DATA, Clock to 1
539 sc
->lmc_gpio
|= LMC_GEP_MODE
;
540 sc
->lmc_gpio
|= LMC_GEP_DATA
;
541 sc
->lmc_gpio
|= LMC_GEP_CLK
;
542 LMC_CSR_WRITE(sc
, csr_gp
, sc
->lmc_gpio
);
544 lmc_gpio_mkoutput(sc
, LMC_GEP_DATA
| LMC_GEP_CLK
| LMC_GEP_MODE
);
547 * busy wait for the chip to reset
549 while( (LMC_CSR_READ(sc
, csr_gp
) & LMC_GEP_INIT
) == 0 &&
553 printk(KERN_DEBUG
"%s: Waited %d for the Xilinx to clear it's memory\n", dev
->name
, 500000-timeout
);
555 for(pos
= 0; pos
< xc
.len
; pos
++){
558 sc
->lmc_gpio
&= ~LMC_GEP_DATA
; /* Data is 0 */
561 sc
->lmc_gpio
|= LMC_GEP_DATA
; /* Data is 1 */
564 printk(KERN_WARNING
"%s Bad data in xilinx programming data at %d, got %d wanted 0 or 1\n", dev
->name
, pos
, data
[pos
]);
565 sc
->lmc_gpio
|= LMC_GEP_DATA
; /* Assume it's 1 */
567 sc
->lmc_gpio
&= ~LMC_GEP_CLK
; /* Clock to zero */
568 sc
->lmc_gpio
|= LMC_GEP_MODE
;
569 LMC_CSR_WRITE(sc
, csr_gp
, sc
->lmc_gpio
);
572 sc
->lmc_gpio
|= LMC_GEP_CLK
; /* Put the clack back to one */
573 sc
->lmc_gpio
|= LMC_GEP_MODE
;
574 LMC_CSR_WRITE(sc
, csr_gp
, sc
->lmc_gpio
);
577 if((LMC_CSR_READ(sc
, csr_gp
) & LMC_GEP_INIT
) == 0){
578 printk(KERN_WARNING
"%s: Reprogramming FAILED. Needs to be reprogrammed. (corrupted data)\n", dev
->name
);
580 else if((LMC_CSR_READ(sc
, csr_gp
) & LMC_GEP_DP
) == 0){
581 printk(KERN_WARNING
"%s: Reprogramming FAILED. Needs to be reprogrammed. (done)\n", dev
->name
);
584 printk(KERN_DEBUG
"%s: Done reprogramming Xilinx, %d bits, good luck!\n", dev
->name
, pos
);
587 lmc_gpio_mkinput(sc
, 0xff);
589 sc
->lmc_miireg16
|= LMC_MII16_FIFO_RESET
;
590 lmc_mii_writereg(sc
, 0, 16, sc
->lmc_miireg16
);
592 sc
->lmc_miireg16
&= ~LMC_MII16_FIFO_RESET
;
593 lmc_mii_writereg(sc
, 0, 16, sc
->lmc_miireg16
);
594 spin_unlock_irqrestore(&sc
->lmc_lock
, flags
);
607 netif_wake_queue(dev
);
613 /* If we don't know what to do, give the protocol a shot. */
614 ret
= lmc_proto_ioctl (sc
, ifr
, cmd
);
622 /* the watchdog process that cruises around */
623 static void lmc_watchdog(struct timer_list
*t
) /*fold00*/
625 lmc_softc_t
*sc
= from_timer(sc
, t
, timer
);
626 struct net_device
*dev
= sc
->lmc_device
;
631 spin_lock_irqsave(&sc
->lmc_lock
, flags
);
633 if(sc
->check
!= 0xBEAFCAFE){
634 printk("LMC: Corrupt net_device struct, breaking out\n");
635 spin_unlock_irqrestore(&sc
->lmc_lock
, flags
);
640 /* Make sure the tx jabber and rx watchdog are off,
641 * and the transmit and receive processes are running.
644 LMC_CSR_WRITE (sc
, csr_15
, 0x00000011);
645 sc
->lmc_cmdmode
|= TULIP_CMD_TXRUN
| TULIP_CMD_RXRUN
;
646 LMC_CSR_WRITE (sc
, csr_command
, sc
->lmc_cmdmode
);
651 LMC_EVENT_LOG(LMC_EVENT_WATCHDOG
, LMC_CSR_READ (sc
, csr_status
), lmc_mii_readreg (sc
, 0, 16));
653 /* --- begin time out check -----------------------------------
654 * check for a transmit interrupt timeout
655 * Has the packet xmt vs xmt serviced threshold been exceeded */
656 if (sc
->lmc_taint_tx
== sc
->lastlmc_taint_tx
&&
657 sc
->lmc_device
->stats
.tx_packets
> sc
->lasttx_packets
&&
658 sc
->tx_TimeoutInd
== 0)
661 /* wait for the watchdog to come around again */
662 sc
->tx_TimeoutInd
= 1;
664 else if (sc
->lmc_taint_tx
== sc
->lastlmc_taint_tx
&&
665 sc
->lmc_device
->stats
.tx_packets
> sc
->lasttx_packets
&&
669 LMC_EVENT_LOG(LMC_EVENT_XMTINTTMO
, LMC_CSR_READ (sc
, csr_status
), 0);
671 sc
->tx_TimeoutDisplay
= 1;
672 sc
->extra_stats
.tx_TimeoutCnt
++;
674 /* DEC chip is stuck, hit it with a RESET!!!! */
675 lmc_running_reset (dev
);
678 /* look at receive & transmit process state to make sure they are running */
679 LMC_EVENT_LOG(LMC_EVENT_RESET1
, LMC_CSR_READ (sc
, csr_status
), 0);
681 /* look at: DSR - 02 for Reg 16
687 LMC_EVENT_LOG(LMC_EVENT_RESET2
, lmc_mii_readreg (sc
, 0, 16), lmc_mii_readreg (sc
, 0, 17));
689 /* reset the transmit timeout detection flag */
690 sc
->tx_TimeoutInd
= 0;
691 sc
->lastlmc_taint_tx
= sc
->lmc_taint_tx
;
692 sc
->lasttx_packets
= sc
->lmc_device
->stats
.tx_packets
;
694 sc
->tx_TimeoutInd
= 0;
695 sc
->lastlmc_taint_tx
= sc
->lmc_taint_tx
;
696 sc
->lasttx_packets
= sc
->lmc_device
->stats
.tx_packets
;
699 /* --- end time out check ----------------------------------- */
702 link_status
= sc
->lmc_media
->get_link_status (sc
);
705 * hardware level link lost, but the interface is marked as up.
708 if ((link_status
== 0) && (sc
->last_link_status
!= 0)) {
709 printk(KERN_WARNING
"%s: hardware/physical link down\n", dev
->name
);
710 sc
->last_link_status
= 0;
711 /* lmc_reset (sc); Why reset??? The link can go down ok */
713 /* Inform the world that link has been lost */
714 netif_carrier_off(dev
);
718 * hardware link is up, but the interface is marked as down.
719 * Bring it back up again.
721 if (link_status
!= 0 && sc
->last_link_status
== 0) {
722 printk(KERN_WARNING
"%s: hardware/physical link up\n", dev
->name
);
723 sc
->last_link_status
= 1;
724 /* lmc_reset (sc); Again why reset??? */
726 netif_carrier_on(dev
);
729 /* Call media specific watchdog functions */
730 sc
->lmc_media
->watchdog(sc
);
733 * Poke the transmitter to make sure it
734 * never stops, even if we run out of mem
736 LMC_CSR_WRITE(sc
, csr_rxpoll
, 0);
739 * Check for code that failed
740 * and try and fix it as appropriate
742 if(sc
->failed_ring
== 1){
744 * Failed to setup the recv/xmit rin
750 if(sc
->failed_recv_alloc
== 1){
752 * We failed to alloc mem in the
753 * interrupt handler, go through the rings
756 sc
->failed_recv_alloc
= 0;
762 * remember the timer value
766 ticks
= LMC_CSR_READ (sc
, csr_gp_timer
);
767 LMC_CSR_WRITE (sc
, csr_gp_timer
, 0xffffffffUL
);
768 sc
->ictl
.ticks
= 0x0000ffff - (ticks
& 0x0000ffff);
771 * restart this timer.
773 sc
->timer
.expires
= jiffies
+ (HZ
);
774 add_timer (&sc
->timer
);
776 spin_unlock_irqrestore(&sc
->lmc_lock
, flags
);
779 static int lmc_attach(struct net_device
*dev
, unsigned short encoding
,
780 unsigned short parity
)
782 if (encoding
== ENCODING_NRZ
&& parity
== PARITY_CRC16_PR1_CCITT
)
787 static const struct net_device_ops lmc_ops
= {
788 .ndo_open
= lmc_open
,
789 .ndo_stop
= lmc_close
,
790 .ndo_start_xmit
= hdlc_start_xmit
,
791 .ndo_do_ioctl
= lmc_ioctl
,
792 .ndo_tx_timeout
= lmc_driver_timeout
,
793 .ndo_get_stats
= lmc_get_stats
,
796 static int lmc_init_one(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
799 struct net_device
*dev
;
803 static int cards_found
;
805 err
= pcim_enable_device(pdev
);
807 printk(KERN_ERR
"lmc: pci enable failed: %d\n", err
);
811 err
= pci_request_regions(pdev
, "lmc");
813 printk(KERN_ERR
"lmc: pci_request_region failed\n");
818 * Allocate our own device structure
820 sc
= devm_kzalloc(&pdev
->dev
, sizeof(lmc_softc_t
), GFP_KERNEL
);
824 dev
= alloc_hdlcdev(sc
);
826 printk(KERN_ERR
"lmc:alloc_netdev for device failed\n");
831 dev
->type
= ARPHRD_HDLC
;
832 dev_to_hdlc(dev
)->xmit
= lmc_start_xmit
;
833 dev_to_hdlc(dev
)->attach
= lmc_attach
;
834 dev
->netdev_ops
= &lmc_ops
;
835 dev
->watchdog_timeo
= HZ
; /* 1 second */
836 dev
->tx_queue_len
= 100;
837 sc
->lmc_device
= dev
;
838 sc
->name
= dev
->name
;
839 sc
->if_type
= LMC_PPP
;
840 sc
->check
= 0xBEAFCAFE;
841 dev
->base_addr
= pci_resource_start(pdev
, 0);
842 dev
->irq
= pdev
->irq
;
843 pci_set_drvdata(pdev
, dev
);
844 SET_NETDEV_DEV(dev
, &pdev
->dev
);
847 * This will get the protocol layer ready and do any 1 time init's
848 * Must have a valid sc and dev structure
850 lmc_proto_attach(sc
);
852 /* Init the spin lock so can call it latter */
854 spin_lock_init(&sc
->lmc_lock
);
855 pci_set_master(pdev
);
857 printk(KERN_INFO
"%s: detected at %lx, irq %d\n", dev
->name
,
858 dev
->base_addr
, dev
->irq
);
860 err
= register_hdlc_device(dev
);
862 printk(KERN_ERR
"%s: register_netdev failed.\n", dev
->name
);
867 sc
->lmc_cardtype
= LMC_CARDTYPE_UNKNOWN
;
868 sc
->lmc_timing
= LMC_CTL_CLOCK_SOURCE_EXT
;
872 * Check either the subvendor or the subdevice, some systems reverse
873 * the setting in the bois, seems to be version and arch dependent?
874 * Fix the error, exchange the two values
876 if ((subdevice
= pdev
->subsystem_device
) == PCI_VENDOR_ID_LMC
)
877 subdevice
= pdev
->subsystem_vendor
;
880 case PCI_DEVICE_ID_LMC_HSSI
:
881 printk(KERN_INFO
"%s: LMC HSSI\n", dev
->name
);
882 sc
->lmc_cardtype
= LMC_CARDTYPE_HSSI
;
883 sc
->lmc_media
= &lmc_hssi_media
;
885 case PCI_DEVICE_ID_LMC_DS3
:
886 printk(KERN_INFO
"%s: LMC DS3\n", dev
->name
);
887 sc
->lmc_cardtype
= LMC_CARDTYPE_DS3
;
888 sc
->lmc_media
= &lmc_ds3_media
;
890 case PCI_DEVICE_ID_LMC_SSI
:
891 printk(KERN_INFO
"%s: LMC SSI\n", dev
->name
);
892 sc
->lmc_cardtype
= LMC_CARDTYPE_SSI
;
893 sc
->lmc_media
= &lmc_ssi_media
;
895 case PCI_DEVICE_ID_LMC_T1
:
896 printk(KERN_INFO
"%s: LMC T1\n", dev
->name
);
897 sc
->lmc_cardtype
= LMC_CARDTYPE_T1
;
898 sc
->lmc_media
= &lmc_t1_media
;
901 printk(KERN_WARNING
"%s: LMC UNKNOWN CARD!\n", dev
->name
);
905 lmc_initcsrs (sc
, dev
->base_addr
, 8);
907 lmc_gpio_mkinput (sc
, 0xff);
908 sc
->lmc_gpio
= 0; /* drive no signals yet */
910 sc
->lmc_media
->defaults (sc
);
912 sc
->lmc_media
->set_link_status (sc
, LMC_LINK_UP
);
914 /* verify that the PCI Sub System ID matches the Adapter Model number
915 * from the MII register
917 AdapModelNum
= (lmc_mii_readreg (sc
, 0, 3) & 0x3f0) >> 4;
919 if ((AdapModelNum
!= LMC_ADAP_T1
|| /* detect LMC1200 */
920 subdevice
!= PCI_DEVICE_ID_LMC_T1
) &&
921 (AdapModelNum
!= LMC_ADAP_SSI
|| /* detect LMC1000 */
922 subdevice
!= PCI_DEVICE_ID_LMC_SSI
) &&
923 (AdapModelNum
!= LMC_ADAP_DS3
|| /* detect LMC5245 */
924 subdevice
!= PCI_DEVICE_ID_LMC_DS3
) &&
925 (AdapModelNum
!= LMC_ADAP_HSSI
|| /* detect LMC5200 */
926 subdevice
!= PCI_DEVICE_ID_LMC_HSSI
))
927 printk(KERN_WARNING
"%s: Model number (%d) miscompare for PCI"
928 " Subsystem ID = 0x%04x\n",
929 dev
->name
, AdapModelNum
, subdevice
);
934 LMC_CSR_WRITE (sc
, csr_gp_timer
, 0xFFFFFFFFUL
);
936 sc
->board_idx
= cards_found
++;
937 sc
->extra_stats
.check
= STATCHECK
;
938 sc
->extra_stats
.version_size
= (DRIVER_VERSION
<< 16) +
939 sizeof(sc
->lmc_device
->stats
) + sizeof(sc
->extra_stats
);
940 sc
->extra_stats
.lmc_cardtype
= sc
->lmc_cardtype
;
943 sc
->last_link_status
= 0;
949 * Called from pci when removing module.
951 static void lmc_remove_one(struct pci_dev
*pdev
)
953 struct net_device
*dev
= pci_get_drvdata(pdev
);
956 printk(KERN_DEBUG
"%s: removing...\n", dev
->name
);
957 unregister_hdlc_device(dev
);
962 /* After this is called, packets can be sent.
963 * Does not initialize the addresses
965 static int lmc_open(struct net_device
*dev
)
967 lmc_softc_t
*sc
= dev_to_sc(dev
);
970 lmc_led_on(sc
, LMC_DS3_LED0
);
975 LMC_EVENT_LOG(LMC_EVENT_RESET1
, LMC_CSR_READ(sc
, csr_status
), 0);
976 LMC_EVENT_LOG(LMC_EVENT_RESET2
, lmc_mii_readreg(sc
, 0, 16),
977 lmc_mii_readreg(sc
, 0, 17));
984 /* Since we have to use PCI bus, this should work on x86,alpha,ppc */
985 if (request_irq (dev
->irq
, lmc_interrupt
, IRQF_SHARED
, dev
->name
, dev
)){
986 printk(KERN_WARNING
"%s: could not get irq: %d\n", dev
->name
, dev
->irq
);
991 /* Assert Terminal Active */
992 sc
->lmc_miireg16
|= LMC_MII16_LED_ALL
;
993 sc
->lmc_media
->set_link_status (sc
, LMC_LINK_UP
);
996 * reset to last state.
998 sc
->lmc_media
->set_status (sc
, NULL
);
1000 /* setup default bits to be used in tulip_desc_t transmit descriptor
1002 sc
->TxDescriptControlInit
= (
1003 LMC_TDES_INTERRUPT_ON_COMPLETION
1004 | LMC_TDES_FIRST_SEGMENT
1005 | LMC_TDES_LAST_SEGMENT
1006 | LMC_TDES_SECOND_ADDR_CHAINED
1007 | LMC_TDES_DISABLE_PADDING
1010 if (sc
->ictl
.crc_length
== LMC_CTL_CRC_LENGTH_16
) {
1011 /* disable 32 bit CRC generated by ASIC */
1012 sc
->TxDescriptControlInit
|= LMC_TDES_ADD_CRC_DISABLE
;
1014 sc
->lmc_media
->set_crc_length(sc
, sc
->ictl
.crc_length
);
1015 /* Acknoledge the Terminal Active and light LEDs */
1017 /* dev->flags |= IFF_UP; */
1019 if ((err
= lmc_proto_open(sc
)) != 0)
1022 netif_start_queue(dev
);
1023 sc
->extra_stats
.tx_tbusy0
++;
1026 * select what interrupts we want to get
1028 sc
->lmc_intrmask
= 0;
1029 /* Should be using the default interrupt mask defined in the .h file. */
1030 sc
->lmc_intrmask
|= (TULIP_STS_NORMALINTR
1033 | TULIP_STS_ABNRMLINTR
1034 | TULIP_STS_SYSERROR
1035 | TULIP_STS_TXSTOPPED
1036 | TULIP_STS_TXUNDERFLOW
1037 | TULIP_STS_RXSTOPPED
1040 LMC_CSR_WRITE (sc
, csr_intr
, sc
->lmc_intrmask
);
1042 sc
->lmc_cmdmode
|= TULIP_CMD_TXRUN
;
1043 sc
->lmc_cmdmode
|= TULIP_CMD_RXRUN
;
1044 LMC_CSR_WRITE (sc
, csr_command
, sc
->lmc_cmdmode
);
1046 sc
->lmc_ok
= 1; /* Run watchdog */
1049 * Set the if up now - pfb
1052 sc
->last_link_status
= 1;
1055 * Setup a timer for the watchdog on probe, and start it running.
1056 * Since lmc_ok == 0, it will be a NOP for now.
1058 timer_setup(&sc
->timer
, lmc_watchdog
, 0);
1059 sc
->timer
.expires
= jiffies
+ HZ
;
1060 add_timer (&sc
->timer
);
1065 /* Total reset to compensate for the AdTran DSU doing bad things
1069 static void lmc_running_reset (struct net_device
*dev
) /*fold00*/
1071 lmc_softc_t
*sc
= dev_to_sc(dev
);
1073 /* stop interrupts */
1074 /* Clear the interrupt mask */
1075 LMC_CSR_WRITE (sc
, csr_intr
, 0x00000000);
1080 /* sc->lmc_miireg16 |= LMC_MII16_LED_ALL; */
1081 sc
->lmc_media
->set_link_status (sc
, 1);
1082 sc
->lmc_media
->set_status (sc
, NULL
);
1084 netif_wake_queue(dev
);
1087 sc
->extra_stats
.tx_tbusy0
++;
1089 sc
->lmc_intrmask
= TULIP_DEFAULT_INTR_MASK
;
1090 LMC_CSR_WRITE (sc
, csr_intr
, sc
->lmc_intrmask
);
1092 sc
->lmc_cmdmode
|= (TULIP_CMD_TXRUN
| TULIP_CMD_RXRUN
);
1093 LMC_CSR_WRITE (sc
, csr_command
, sc
->lmc_cmdmode
);
1097 /* This is what is called when you ifconfig down a device.
1098 * This disables the timer for the watchdog and keepalives,
1099 * and disables the irq for dev.
1101 static int lmc_close(struct net_device
*dev
)
1103 /* not calling release_region() as we should */
1104 lmc_softc_t
*sc
= dev_to_sc(dev
);
1107 sc
->lmc_media
->set_link_status (sc
, 0);
1108 del_timer (&sc
->timer
);
1109 lmc_proto_close(sc
);
1115 /* Ends the transfer of packets */
1116 /* When the interface goes down, this is called */
1117 static int lmc_ifdown (struct net_device
*dev
) /*fold00*/
1119 lmc_softc_t
*sc
= dev_to_sc(dev
);
1123 /* Don't let anything else go on right now */
1125 netif_stop_queue(dev
);
1126 sc
->extra_stats
.tx_tbusy1
++;
1128 /* stop interrupts */
1129 /* Clear the interrupt mask */
1130 LMC_CSR_WRITE (sc
, csr_intr
, 0x00000000);
1132 /* Stop Tx and Rx on the chip */
1133 csr6
= LMC_CSR_READ (sc
, csr_command
);
1134 csr6
&= ~LMC_DEC_ST
; /* Turn off the Transmission bit */
1135 csr6
&= ~LMC_DEC_SR
; /* Turn off the Receive bit */
1136 LMC_CSR_WRITE (sc
, csr_command
, csr6
);
1138 sc
->lmc_device
->stats
.rx_missed_errors
+=
1139 LMC_CSR_READ(sc
, csr_missed_frames
) & 0xffff;
1141 /* release the interrupt */
1142 if(sc
->got_irq
== 1){
1143 free_irq (dev
->irq
, dev
);
1147 /* free skbuffs in the Rx queue */
1148 for (i
= 0; i
< LMC_RXDESCS
; i
++)
1150 struct sk_buff
*skb
= sc
->lmc_rxq
[i
];
1151 sc
->lmc_rxq
[i
] = NULL
;
1152 sc
->lmc_rxring
[i
].status
= 0;
1153 sc
->lmc_rxring
[i
].length
= 0;
1154 sc
->lmc_rxring
[i
].buffer1
= 0xDEADBEEF;
1157 sc
->lmc_rxq
[i
] = NULL
;
1160 for (i
= 0; i
< LMC_TXDESCS
; i
++)
1162 if (sc
->lmc_txq
[i
] != NULL
)
1163 dev_kfree_skb(sc
->lmc_txq
[i
]);
1164 sc
->lmc_txq
[i
] = NULL
;
1167 lmc_led_off (sc
, LMC_MII16_LED_ALL
);
1169 netif_wake_queue(dev
);
1170 sc
->extra_stats
.tx_tbusy0
++;
1175 /* Interrupt handling routine. This will take an incoming packet, or clean
1176 * up after a trasmit.
1178 static irqreturn_t
lmc_interrupt (int irq
, void *dev_instance
) /*fold00*/
1180 struct net_device
*dev
= (struct net_device
*) dev_instance
;
1181 lmc_softc_t
*sc
= dev_to_sc(dev
);
1186 int max_work
= LMC_RXDESCS
;
1189 spin_lock(&sc
->lmc_lock
);
1192 * Read the csr to find what interrupts we have (if any)
1194 csr
= LMC_CSR_READ (sc
, csr_status
);
1197 * Make sure this is our interrupt
1199 if ( ! (csr
& sc
->lmc_intrmask
)) {
1200 goto lmc_int_fail_out
;
1203 /* always go through this loop at least once */
1204 while (csr
& sc
->lmc_intrmask
) {
1208 * Clear interrupt bits, we handle all case below
1210 LMC_CSR_WRITE (sc
, csr_status
, csr
);
1214 * - Transmit process timed out CSR5<1>
1215 * - Transmit jabber timeout CSR5<3>
1216 * - Transmit underflow CSR5<5>
1217 * - Transmit Receiver buffer unavailable CSR5<7>
1218 * - Receive process stopped CSR5<8>
1219 * - Receive watchdog timeout CSR5<9>
1220 * - Early transmit interrupt CSR5<10>
1222 * Is this really right? Should we do a running reset for jabber?
1223 * (being a WAN card and all)
1225 if (csr
& TULIP_STS_ABNRMLINTR
){
1226 lmc_running_reset (dev
);
1230 if (csr
& TULIP_STS_RXINTR
)
1233 if (csr
& (TULIP_STS_TXINTR
| TULIP_STS_TXNOBUF
| TULIP_STS_TXSTOPPED
)) {
1236 /* reset the transmit timeout detection flag -baz */
1237 sc
->extra_stats
.tx_NoCompleteCnt
= 0;
1239 badtx
= sc
->lmc_taint_tx
;
1240 i
= badtx
% LMC_TXDESCS
;
1242 while ((badtx
< sc
->lmc_next_tx
)) {
1243 stat
= sc
->lmc_txring
[i
].status
;
1245 LMC_EVENT_LOG (LMC_EVENT_XMTINT
, stat
,
1246 sc
->lmc_txring
[i
].length
);
1248 * If bit 31 is 1 the tulip owns it break out of the loop
1250 if (stat
& 0x80000000)
1253 n_compl
++ ; /* i.e., have an empty slot in ring */
1255 * If we have no skbuff or have cleared it
1256 * Already continue to the next buffer
1258 if (sc
->lmc_txq
[i
] == NULL
)
1262 * Check the total error summary to look for any errors
1264 if (stat
& 0x8000) {
1265 sc
->lmc_device
->stats
.tx_errors
++;
1267 sc
->lmc_device
->stats
.tx_aborted_errors
++;
1269 sc
->lmc_device
->stats
.tx_carrier_errors
++;
1271 sc
->lmc_device
->stats
.tx_window_errors
++;
1273 sc
->lmc_device
->stats
.tx_fifo_errors
++;
1275 sc
->lmc_device
->stats
.tx_bytes
+= sc
->lmc_txring
[i
].length
& 0x7ff;
1277 sc
->lmc_device
->stats
.tx_packets
++;
1280 dev_consume_skb_irq(sc
->lmc_txq
[i
]);
1281 sc
->lmc_txq
[i
] = NULL
;
1284 i
= badtx
% LMC_TXDESCS
;
1287 if (sc
->lmc_next_tx
- badtx
> LMC_TXDESCS
)
1289 printk ("%s: out of sync pointer\n", dev
->name
);
1290 badtx
+= LMC_TXDESCS
;
1292 LMC_EVENT_LOG(LMC_EVENT_TBUSY0
, n_compl
, 0);
1294 netif_wake_queue(dev
);
1295 sc
->extra_stats
.tx_tbusy0
++;
1299 sc
->extra_stats
.dirtyTx
= badtx
;
1300 sc
->extra_stats
.lmc_next_tx
= sc
->lmc_next_tx
;
1301 sc
->extra_stats
.lmc_txfull
= sc
->lmc_txfull
;
1303 sc
->lmc_taint_tx
= badtx
;
1306 * Why was there a break here???
1308 } /* end handle transmit interrupt */
1310 if (csr
& TULIP_STS_SYSERROR
) {
1312 printk (KERN_WARNING
"%s: system bus error csr: %#8.8x\n", dev
->name
, csr
);
1313 error
= csr
>>23 & 0x7;
1316 printk(KERN_WARNING
"%s: Parity Fault (bad)\n", dev
->name
);
1319 printk(KERN_WARNING
"%s: Master Abort (naughty)\n", dev
->name
);
1322 printk(KERN_WARNING
"%s: Target Abort (not so naughty)\n", dev
->name
);
1325 printk(KERN_WARNING
"%s: This bus error code was supposed to be reserved!\n", dev
->name
);
1329 LMC_EVENT_LOG(LMC_EVENT_RESET1
, LMC_CSR_READ (sc
, csr_status
), 0);
1330 LMC_EVENT_LOG(LMC_EVENT_RESET2
,
1331 lmc_mii_readreg (sc
, 0, 16),
1332 lmc_mii_readreg (sc
, 0, 17));
1341 * Get current csr status to make sure
1342 * we've cleared all interrupts
1344 csr
= LMC_CSR_READ (sc
, csr_status
);
1345 } /* end interrupt loop */
1346 LMC_EVENT_LOG(LMC_EVENT_INT
, firstcsr
, csr
);
1350 spin_unlock(&sc
->lmc_lock
);
1352 return IRQ_RETVAL(handled
);
1355 static netdev_tx_t
lmc_start_xmit(struct sk_buff
*skb
,
1356 struct net_device
*dev
)
1358 lmc_softc_t
*sc
= dev_to_sc(dev
);
1361 unsigned long flags
;
1363 spin_lock_irqsave(&sc
->lmc_lock
, flags
);
1365 /* normal path, tbusy known to be zero */
1367 entry
= sc
->lmc_next_tx
% LMC_TXDESCS
;
1369 sc
->lmc_txq
[entry
] = skb
;
1370 sc
->lmc_txring
[entry
].buffer1
= virt_to_bus (skb
->data
);
1372 LMC_CONSOLE_LOG("xmit", skb
->data
, skb
->len
);
1375 /* If the queue is less than half full, don't interrupt */
1376 if (sc
->lmc_next_tx
- sc
->lmc_taint_tx
< LMC_TXDESCS
/ 2)
1378 /* Do not interrupt on completion of this packet */
1380 netif_wake_queue(dev
);
1382 else if (sc
->lmc_next_tx
- sc
->lmc_taint_tx
== LMC_TXDESCS
/ 2)
1384 /* This generates an interrupt on completion of this packet */
1386 netif_wake_queue(dev
);
1388 else if (sc
->lmc_next_tx
- sc
->lmc_taint_tx
< LMC_TXDESCS
- 1)
1390 /* Do not interrupt on completion of this packet */
1392 netif_wake_queue(dev
);
1396 /* This generates an interrupt on completion of this packet */
1399 netif_stop_queue(dev
);
1402 flag
= LMC_TDES_INTERRUPT_ON_COMPLETION
;
1404 if (sc
->lmc_next_tx
- sc
->lmc_taint_tx
>= LMC_TXDESCS
- 1)
1405 { /* ring full, go busy */
1407 netif_stop_queue(dev
);
1408 sc
->extra_stats
.tx_tbusy1
++;
1409 LMC_EVENT_LOG(LMC_EVENT_TBUSY1
, entry
, 0);
1414 if (entry
== LMC_TXDESCS
- 1) /* last descriptor in ring */
1415 flag
|= LMC_TDES_END_OF_RING
; /* flag as such for Tulip */
1417 /* don't pad small packets either */
1418 flag
= sc
->lmc_txring
[entry
].length
= (skb
->len
) | flag
|
1419 sc
->TxDescriptControlInit
;
1421 /* set the transmit timeout flag to be checked in
1422 * the watchdog timer handler. -baz
1425 sc
->extra_stats
.tx_NoCompleteCnt
++;
1428 /* give ownership to the chip */
1429 LMC_EVENT_LOG(LMC_EVENT_XMT
, flag
, entry
);
1430 sc
->lmc_txring
[entry
].status
= 0x80000000;
1433 LMC_CSR_WRITE (sc
, csr_txpoll
, 0);
1435 spin_unlock_irqrestore(&sc
->lmc_lock
, flags
);
1437 return NETDEV_TX_OK
;
1441 static int lmc_rx(struct net_device
*dev
)
1443 lmc_softc_t
*sc
= dev_to_sc(dev
);
1445 int rx_work_limit
= LMC_RXDESCS
;
1446 int rxIntLoopCnt
; /* debug -baz */
1447 int localLengthErrCnt
= 0;
1449 struct sk_buff
*skb
, *nsb
;
1452 lmc_led_on(sc
, LMC_DS3_LED3
);
1454 rxIntLoopCnt
= 0; /* debug -baz */
1456 i
= sc
->lmc_next_rx
% LMC_RXDESCS
;
1458 while (((stat
= sc
->lmc_rxring
[i
].status
) & LMC_RDES_OWN_BIT
) != DESC_OWNED_BY_DC21X4
)
1460 rxIntLoopCnt
++; /* debug -baz */
1461 len
= ((stat
& LMC_RDES_FRAME_LENGTH
) >> RDES_FRAME_LENGTH_BIT_NUMBER
);
1462 if ((stat
& 0x0300) != 0x0300) { /* Check first segment and last segment */
1463 if ((stat
& 0x0000ffff) != 0x7fff) {
1464 /* Oversized frame */
1465 sc
->lmc_device
->stats
.rx_length_errors
++;
1470 if (stat
& 0x00000008) { /* Catch a dribbling bit error */
1471 sc
->lmc_device
->stats
.rx_errors
++;
1472 sc
->lmc_device
->stats
.rx_frame_errors
++;
1477 if (stat
& 0x00000004) { /* Catch a CRC error by the Xilinx */
1478 sc
->lmc_device
->stats
.rx_errors
++;
1479 sc
->lmc_device
->stats
.rx_crc_errors
++;
1483 if (len
> LMC_PKT_BUF_SZ
) {
1484 sc
->lmc_device
->stats
.rx_length_errors
++;
1485 localLengthErrCnt
++;
1489 if (len
< sc
->lmc_crcSize
+ 2) {
1490 sc
->lmc_device
->stats
.rx_length_errors
++;
1491 sc
->extra_stats
.rx_SmallPktCnt
++;
1492 localLengthErrCnt
++;
1496 if(stat
& 0x00004000){
1497 printk(KERN_WARNING
"%s: Receiver descriptor error, receiver out of sync?\n", dev
->name
);
1500 len
-= sc
->lmc_crcSize
;
1502 skb
= sc
->lmc_rxq
[i
];
1505 * We ran out of memory at some point
1506 * just allocate an skb buff and continue.
1510 nsb
= dev_alloc_skb (LMC_PKT_BUF_SZ
+ 2);
1512 sc
->lmc_rxq
[i
] = nsb
;
1514 sc
->lmc_rxring
[i
].buffer1
= virt_to_bus(skb_tail_pointer(nsb
));
1516 sc
->failed_recv_alloc
= 1;
1520 sc
->lmc_device
->stats
.rx_packets
++;
1521 sc
->lmc_device
->stats
.rx_bytes
+= len
;
1523 LMC_CONSOLE_LOG("recv", skb
->data
, len
);
1526 * I'm not sure of the sanity of this
1527 * Packets could be arriving at a constant
1528 * 44.210mbits/sec and we're going to copy
1529 * them into a new buffer??
1532 if(len
> (LMC_MTU
- (LMC_MTU
>>2))){ /* len > LMC_MTU * 0.75 */
1534 * If it's a large packet don't copy it just hand it up
1538 sc
->lmc_rxq
[i
] = NULL
;
1539 sc
->lmc_rxring
[i
].buffer1
= 0x0;
1542 skb
->protocol
= lmc_proto_type(sc
, skb
);
1543 skb_reset_mac_header(skb
);
1544 /* skb_reset_network_header(skb); */
1546 lmc_proto_netif(sc
, skb
);
1549 * This skb will be destroyed by the upper layers, make a new one
1551 nsb
= dev_alloc_skb (LMC_PKT_BUF_SZ
+ 2);
1553 sc
->lmc_rxq
[i
] = nsb
;
1555 sc
->lmc_rxring
[i
].buffer1
= virt_to_bus(skb_tail_pointer(nsb
));
1556 /* Transferred to 21140 below */
1560 * We've run out of memory, stop trying to allocate
1561 * memory and exit the interrupt handler
1563 * The chip may run out of receivers and stop
1564 * in which care we'll try to allocate the buffer
1565 * again. (once a second)
1567 sc
->extra_stats
.rx_BuffAllocErr
++;
1568 LMC_EVENT_LOG(LMC_EVENT_RCVINT
, stat
, len
);
1569 sc
->failed_recv_alloc
= 1;
1570 goto skip_out_of_mem
;
1574 nsb
= dev_alloc_skb(len
);
1576 goto give_it_anyways
;
1578 skb_copy_from_linear_data(skb
, skb_put(nsb
, len
), len
);
1580 nsb
->protocol
= lmc_proto_type(sc
, nsb
);
1581 skb_reset_mac_header(nsb
);
1582 /* skb_reset_network_header(nsb); */
1584 lmc_proto_netif(sc
, nsb
);
1588 LMC_EVENT_LOG(LMC_EVENT_RCVINT
, stat
, len
);
1589 sc
->lmc_rxring
[i
].status
= DESC_OWNED_BY_DC21X4
;
1592 i
= sc
->lmc_next_rx
% LMC_RXDESCS
;
1594 if (rx_work_limit
< 0)
1598 /* detect condition for LMC1000 where DSU cable attaches and fills
1599 * descriptors with bogus packets
1601 if (localLengthErrCnt > LMC_RXDESCS - 3) {
1602 sc->extra_stats.rx_BadPktSurgeCnt++;
1603 LMC_EVENT_LOG(LMC_EVENT_BADPKTSURGE, localLengthErrCnt,
1604 sc->extra_stats.rx_BadPktSurgeCnt);
1607 /* save max count of receive descriptors serviced */
1608 if (rxIntLoopCnt
> sc
->extra_stats
.rxIntLoopCnt
)
1609 sc
->extra_stats
.rxIntLoopCnt
= rxIntLoopCnt
; /* debug -baz */
1612 if (rxIntLoopCnt
== 0)
1614 for (i
= 0; i
< LMC_RXDESCS
; i
++)
1616 if ((sc
->lmc_rxring
[i
].status
& LMC_RDES_OWN_BIT
)
1617 != DESC_OWNED_BY_DC21X4
)
1622 LMC_EVENT_LOG(LMC_EVENT_RCVEND
, rxIntLoopCnt
, 0);
1627 lmc_led_off(sc
, LMC_DS3_LED3
);
1633 static struct net_device_stats
*lmc_get_stats(struct net_device
*dev
)
1635 lmc_softc_t
*sc
= dev_to_sc(dev
);
1636 unsigned long flags
;
1638 spin_lock_irqsave(&sc
->lmc_lock
, flags
);
1640 sc
->lmc_device
->stats
.rx_missed_errors
+= LMC_CSR_READ(sc
, csr_missed_frames
) & 0xffff;
1642 spin_unlock_irqrestore(&sc
->lmc_lock
, flags
);
1644 return &sc
->lmc_device
->stats
;
1647 static struct pci_driver lmc_driver
= {
1649 .id_table
= lmc_pci_tbl
,
1650 .probe
= lmc_init_one
,
1651 .remove
= lmc_remove_one
,
1654 module_pci_driver(lmc_driver
);
1656 unsigned lmc_mii_readreg (lmc_softc_t
* const sc
, unsigned devaddr
, unsigned regno
) /*fold00*/
1659 int command
= (0xf6 << 10) | (devaddr
<< 5) | regno
;
1664 for (i
= 15; i
>= 0; i
--)
1666 int dataval
= (command
& (1 << i
)) ? 0x20000 : 0;
1668 LMC_CSR_WRITE (sc
, csr_9
, dataval
);
1670 /* __SLOW_DOWN_IO; */
1671 LMC_CSR_WRITE (sc
, csr_9
, dataval
| 0x10000);
1673 /* __SLOW_DOWN_IO; */
1676 for (i
= 19; i
> 0; i
--)
1678 LMC_CSR_WRITE (sc
, csr_9
, 0x40000);
1680 /* __SLOW_DOWN_IO; */
1681 retval
= (retval
<< 1) | ((LMC_CSR_READ (sc
, csr_9
) & 0x80000) ? 1 : 0);
1682 LMC_CSR_WRITE (sc
, csr_9
, 0x40000 | 0x10000);
1684 /* __SLOW_DOWN_IO; */
1687 return (retval
>> 1) & 0xffff;
1690 void lmc_mii_writereg (lmc_softc_t
* const sc
, unsigned devaddr
, unsigned regno
, unsigned data
) /*fold00*/
1693 int command
= (0x5002 << 16) | (devaddr
<< 23) | (regno
<< 18) | data
;
1702 if (command
& (1 << i
))
1707 LMC_CSR_WRITE (sc
, csr_9
, datav
);
1709 /* __SLOW_DOWN_IO; */
1710 LMC_CSR_WRITE (sc
, csr_9
, (datav
| 0x10000));
1712 /* __SLOW_DOWN_IO; */
1719 LMC_CSR_WRITE (sc
, csr_9
, 0x40000);
1721 /* __SLOW_DOWN_IO; */
1722 LMC_CSR_WRITE (sc
, csr_9
, 0x50000);
1724 /* __SLOW_DOWN_IO; */
1729 static void lmc_softreset (lmc_softc_t
* const sc
) /*fold00*/
1733 /* Initialize the receive rings and buffers. */
1735 sc
->lmc_next_rx
= 0;
1736 sc
->lmc_next_tx
= 0;
1737 sc
->lmc_taint_rx
= 0;
1738 sc
->lmc_taint_tx
= 0;
1741 * Setup each one of the receiver buffers
1742 * allocate an skbuff for each one, setup the descriptor table
1743 * and point each buffer at the next one
1746 for (i
= 0; i
< LMC_RXDESCS
; i
++)
1748 struct sk_buff
*skb
;
1750 if (sc
->lmc_rxq
[i
] == NULL
)
1752 skb
= dev_alloc_skb (LMC_PKT_BUF_SZ
+ 2);
1754 printk(KERN_WARNING
"%s: Failed to allocate receiver ring, will try again\n", sc
->name
);
1755 sc
->failed_ring
= 1;
1759 sc
->lmc_rxq
[i
] = skb
;
1764 skb
= sc
->lmc_rxq
[i
];
1767 skb
->dev
= sc
->lmc_device
;
1769 /* owned by 21140 */
1770 sc
->lmc_rxring
[i
].status
= 0x80000000;
1772 /* used to be PKT_BUF_SZ now uses skb since we lose some to head room */
1773 sc
->lmc_rxring
[i
].length
= skb_tailroom(skb
);
1775 /* use to be tail which is dumb since you're thinking why write
1776 * to the end of the packj,et but since there's nothing there tail == data
1778 sc
->lmc_rxring
[i
].buffer1
= virt_to_bus (skb
->data
);
1780 /* This is fair since the structure is static and we have the next address */
1781 sc
->lmc_rxring
[i
].buffer2
= virt_to_bus (&sc
->lmc_rxring
[i
+ 1]);
1789 sc
->lmc_rxring
[i
- 1].length
|= 0x02000000; /* Set end of buffers flag */
1790 sc
->lmc_rxring
[i
- 1].buffer2
= virt_to_bus(&sc
->lmc_rxring
[0]); /* Point back to the start */
1792 LMC_CSR_WRITE (sc
, csr_rxlist
, virt_to_bus (sc
->lmc_rxring
)); /* write base address */
1794 /* Initialize the transmit rings and buffers */
1795 for (i
= 0; i
< LMC_TXDESCS
; i
++)
1797 if (sc
->lmc_txq
[i
] != NULL
){ /* have buffer */
1798 dev_kfree_skb(sc
->lmc_txq
[i
]); /* free it */
1799 sc
->lmc_device
->stats
.tx_dropped
++; /* We just dropped a packet */
1801 sc
->lmc_txq
[i
] = NULL
;
1802 sc
->lmc_txring
[i
].status
= 0x00000000;
1803 sc
->lmc_txring
[i
].buffer2
= virt_to_bus (&sc
->lmc_txring
[i
+ 1]);
1805 sc
->lmc_txring
[i
- 1].buffer2
= virt_to_bus (&sc
->lmc_txring
[0]);
1806 LMC_CSR_WRITE (sc
, csr_txlist
, virt_to_bus (sc
->lmc_txring
));
1809 void lmc_gpio_mkinput(lmc_softc_t
* const sc
, u32 bits
) /*fold00*/
1811 sc
->lmc_gpio_io
&= ~bits
;
1812 LMC_CSR_WRITE(sc
, csr_gp
, TULIP_GP_PINSET
| (sc
->lmc_gpio_io
));
1815 void lmc_gpio_mkoutput(lmc_softc_t
* const sc
, u32 bits
) /*fold00*/
1817 sc
->lmc_gpio_io
|= bits
;
1818 LMC_CSR_WRITE(sc
, csr_gp
, TULIP_GP_PINSET
| (sc
->lmc_gpio_io
));
1821 void lmc_led_on(lmc_softc_t
* const sc
, u32 led
) /*fold00*/
1823 if ((~sc
->lmc_miireg16
) & led
) /* Already on! */
1826 sc
->lmc_miireg16
&= ~led
;
1827 lmc_mii_writereg(sc
, 0, 16, sc
->lmc_miireg16
);
1830 void lmc_led_off(lmc_softc_t
* const sc
, u32 led
) /*fold00*/
1832 if (sc
->lmc_miireg16
& led
) /* Already set don't do anything */
1835 sc
->lmc_miireg16
|= led
;
1836 lmc_mii_writereg(sc
, 0, 16, sc
->lmc_miireg16
);
1839 static void lmc_reset(lmc_softc_t
* const sc
) /*fold00*/
1841 sc
->lmc_miireg16
|= LMC_MII16_FIFO_RESET
;
1842 lmc_mii_writereg(sc
, 0, 16, sc
->lmc_miireg16
);
1844 sc
->lmc_miireg16
&= ~LMC_MII16_FIFO_RESET
;
1845 lmc_mii_writereg(sc
, 0, 16, sc
->lmc_miireg16
);
1848 * make some of the GPIO pins be outputs
1850 lmc_gpio_mkoutput(sc
, LMC_GEP_RESET
);
1853 * RESET low to force state reset. This also forces
1854 * the transmitter clock to be internal, but we expect to reset
1855 * that later anyway.
1857 sc
->lmc_gpio
&= ~(LMC_GEP_RESET
);
1858 LMC_CSR_WRITE(sc
, csr_gp
, sc
->lmc_gpio
);
1861 * hold for more than 10 microseconds
1866 * stop driving Xilinx-related signals
1868 lmc_gpio_mkinput(sc
, LMC_GEP_RESET
);
1871 * Call media specific init routine
1873 sc
->lmc_media
->init(sc
);
1875 sc
->extra_stats
.resetCount
++;
1878 static void lmc_dec_reset(lmc_softc_t
* const sc
) /*fold00*/
1883 * disable all interrupts
1885 sc
->lmc_intrmask
= 0;
1886 LMC_CSR_WRITE(sc
, csr_intr
, sc
->lmc_intrmask
);
1889 * Reset the chip with a software reset command.
1890 * Wait 10 microseconds (actually 50 PCI cycles but at
1891 * 33MHz that comes to two microseconds but wait a
1892 * bit longer anyways)
1894 LMC_CSR_WRITE(sc
, csr_busmode
, TULIP_BUSMODE_SWRESET
);
1897 sc
->lmc_busmode
= LMC_CSR_READ(sc
, csr_busmode
);
1898 sc
->lmc_busmode
= 0x00100000;
1899 sc
->lmc_busmode
&= ~TULIP_BUSMODE_SWRESET
;
1900 LMC_CSR_WRITE(sc
, csr_busmode
, sc
->lmc_busmode
);
1902 sc
->lmc_cmdmode
= LMC_CSR_READ(sc
, csr_command
);
1906 * no ethernet address in frames we write
1907 * disable padding (txdesc, padding disable)
1908 * ignore runt frames (rdes0 bit 15)
1909 * no receiver watchdog or transmitter jabber timer
1910 * (csr15 bit 0,14 == 1)
1911 * if using 16-bit CRC, turn off CRC (trans desc, crc disable)
1914 sc
->lmc_cmdmode
|= ( TULIP_CMD_PROMISCUOUS
1915 | TULIP_CMD_FULLDUPLEX
1916 | TULIP_CMD_PASSBADPKT
1917 | TULIP_CMD_NOHEARTBEAT
1918 | TULIP_CMD_PORTSELECT
1919 | TULIP_CMD_RECEIVEALL
1920 | TULIP_CMD_MUSTBEONE
1922 sc
->lmc_cmdmode
&= ~( TULIP_CMD_OPERMODE
1923 | TULIP_CMD_THRESHOLDCTL
1924 | TULIP_CMD_STOREFWD
1925 | TULIP_CMD_TXTHRSHLDCTL
1928 LMC_CSR_WRITE(sc
, csr_command
, sc
->lmc_cmdmode
);
1931 * disable receiver watchdog and transmit jabber
1933 val
= LMC_CSR_READ(sc
, csr_sia_general
);
1934 val
|= (TULIP_WATCHDOG_TXDISABLE
| TULIP_WATCHDOG_RXDISABLE
);
1935 LMC_CSR_WRITE(sc
, csr_sia_general
, val
);
1938 static void lmc_initcsrs(lmc_softc_t
* const sc
, lmc_csrptr_t csr_base
, /*fold00*/
1941 sc
->lmc_csrs
.csr_busmode
= csr_base
+ 0 * csr_size
;
1942 sc
->lmc_csrs
.csr_txpoll
= csr_base
+ 1 * csr_size
;
1943 sc
->lmc_csrs
.csr_rxpoll
= csr_base
+ 2 * csr_size
;
1944 sc
->lmc_csrs
.csr_rxlist
= csr_base
+ 3 * csr_size
;
1945 sc
->lmc_csrs
.csr_txlist
= csr_base
+ 4 * csr_size
;
1946 sc
->lmc_csrs
.csr_status
= csr_base
+ 5 * csr_size
;
1947 sc
->lmc_csrs
.csr_command
= csr_base
+ 6 * csr_size
;
1948 sc
->lmc_csrs
.csr_intr
= csr_base
+ 7 * csr_size
;
1949 sc
->lmc_csrs
.csr_missed_frames
= csr_base
+ 8 * csr_size
;
1950 sc
->lmc_csrs
.csr_9
= csr_base
+ 9 * csr_size
;
1951 sc
->lmc_csrs
.csr_10
= csr_base
+ 10 * csr_size
;
1952 sc
->lmc_csrs
.csr_11
= csr_base
+ 11 * csr_size
;
1953 sc
->lmc_csrs
.csr_12
= csr_base
+ 12 * csr_size
;
1954 sc
->lmc_csrs
.csr_13
= csr_base
+ 13 * csr_size
;
1955 sc
->lmc_csrs
.csr_14
= csr_base
+ 14 * csr_size
;
1956 sc
->lmc_csrs
.csr_15
= csr_base
+ 15 * csr_size
;
1959 static void lmc_driver_timeout(struct net_device
*dev
, unsigned int txqueue
)
1961 lmc_softc_t
*sc
= dev_to_sc(dev
);
1963 unsigned long flags
;
1965 spin_lock_irqsave(&sc
->lmc_lock
, flags
);
1967 printk("%s: Xmitter busy|\n", dev
->name
);
1969 sc
->extra_stats
.tx_tbusy_calls
++;
1970 if (jiffies
- dev_trans_start(dev
) < TX_TIMEOUT
)
1974 * Chip seems to have locked up
1976 * This whips out all our descriptor
1977 * table and starts from scartch
1980 LMC_EVENT_LOG(LMC_EVENT_XMTPRCTMO
,
1981 LMC_CSR_READ (sc
, csr_status
),
1982 sc
->extra_stats
.tx_ProcTimeout
);
1984 lmc_running_reset (dev
);
1986 LMC_EVENT_LOG(LMC_EVENT_RESET1
, LMC_CSR_READ (sc
, csr_status
), 0);
1987 LMC_EVENT_LOG(LMC_EVENT_RESET2
,
1988 lmc_mii_readreg (sc
, 0, 16),
1989 lmc_mii_readreg (sc
, 0, 17));
1991 /* restart the tx processes */
1992 csr6
= LMC_CSR_READ (sc
, csr_command
);
1993 LMC_CSR_WRITE (sc
, csr_command
, csr6
| 0x0002);
1994 LMC_CSR_WRITE (sc
, csr_command
, csr6
| 0x2002);
1996 /* immediate transmit */
1997 LMC_CSR_WRITE (sc
, csr_txpoll
, 0);
1999 sc
->lmc_device
->stats
.tx_errors
++;
2000 sc
->extra_stats
.tx_ProcTimeout
++; /* -baz */
2002 netif_trans_update(dev
); /* prevent tx timeout */
2006 spin_unlock_irqrestore(&sc
->lmc_lock
, flags
);