2 * Copyright (c) 1997-2000 LAN Media Corporation (LMC)
3 * All rights reserved. www.lanmedia.com
5 * This code is written by:
6 * Andrew Stanley-Jones (asj@cban.com)
7 * Rob Braun (bbraun@vix.com),
8 * Michael Graff (explorer@vix.com) and
9 * Matt Thomas (matt@3am-software.com).
16 * This software may be used and distributed according to the terms
17 * of the GNU General Public License version 2, incorporated herein by reference.
19 * Driver for the LanMedia LMC5200, LMC5245, LMC1000, LMC1200 cards.
21 * To control link specific options lmcctl is required.
22 * It can be obtained from ftp.lanmedia.com.
25 * Linux uses the device struct lmc_private to pass private information
28 * The initialization portion of this driver (the lmc_reset() and the
29 * lmc_dec_reset() functions, as well as the led controls and the
30 * lmc_initcsrs() functions.
32 * The watchdog function runs every second and checks to see if
33 * we still have link, and that the timing source is what we expected
34 * it to be. If link is lost, the interface is marked down, and
35 * we no longer can transmit.
39 /* $Id: lmc_main.c,v 1.36 2000/04/11 05:25:25 asj Exp $ */
41 #include <linux/kernel.h>
42 #include <linux/module.h>
43 #include <linux/string.h>
44 #include <linux/timer.h>
45 #include <linux/ptrace.h>
46 #include <linux/errno.h>
47 #include <linux/ioport.h>
48 #include <linux/slab.h>
49 #include <linux/interrupt.h>
50 #include <linux/pci.h>
51 #include <linux/delay.h>
52 #include <linux/init.h>
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>
60 #include <net/syncppp.h>
62 #include <asm/processor.h> /* Processor type for cache alignment. */
63 #include <asm/bitops.h>
66 #include <asm/uaccess.h>
67 //#include <asm/spinlock.h>
69 #define DRIVER_MAJOR_VERSION 1
70 #define DRIVER_MINOR_VERSION 34
71 #define DRIVER_SUB_VERSION 0
73 #define DRIVER_VERSION ((DRIVER_MAJOR_VERSION << 8) + DRIVER_MINOR_VERSION)
77 #include "lmc_ioctl.h"
78 #include "lmc_debug.h"
79 #include "lmc_proto.h"
81 static int lmc_first_load = 0;
83 static int LMC_PKT_BUF_SZ = 1542;
85 static struct pci_device_id lmc_pci_tbl[] = {
86 { PCI_VENDOR_ID_DEC, PCI_DEVICE_ID_DEC_TULIP_FAST,
87 PCI_VENDOR_ID_LMC, PCI_ANY_ID },
88 { PCI_VENDOR_ID_DEC, PCI_DEVICE_ID_DEC_TULIP_FAST,
89 PCI_ANY_ID, PCI_VENDOR_ID_LMC },
93 MODULE_DEVICE_TABLE(pci, lmc_pci_tbl);
94 MODULE_LICENSE("GPL");
97 static int lmc_start_xmit(struct sk_buff *skb, struct net_device *dev);
98 static int lmc_start_xmit(struct sk_buff *skb, struct net_device *dev);
99 static int lmc_rx (struct net_device *dev);
100 static int lmc_open(struct net_device *dev);
101 static int lmc_close(struct net_device *dev);
102 static struct net_device_stats *lmc_get_stats(struct net_device *dev);
103 static irqreturn_t lmc_interrupt(int irq, void *dev_instance, struct pt_regs *regs);
104 static int lmc_set_config(struct net_device *dev, struct ifmap *map);
105 static void lmc_initcsrs(lmc_softc_t * const sc, lmc_csrptr_t csr_base, size_t csr_size);
106 static void lmc_softreset(lmc_softc_t * const);
107 static void lmc_running_reset(struct net_device *dev);
108 static int lmc_ifdown(struct net_device * const);
109 static void lmc_watchdog(unsigned long data);
110 static void lmc_reset(lmc_softc_t * const sc);
111 static void lmc_dec_reset(lmc_softc_t * const sc);
112 static void lmc_driver_timeout(struct net_device *dev);
115 * linux reserves 16 device specific IOCTLs. We call them
116 * LMCIOC* to control various bits of our world.
118 int lmc_ioctl (struct net_device *dev, struct ifreq *ifr, int cmd) /*fold00*/
132 lmc_trace(dev, "lmc_ioctl in");
135 * Most functions mess with the structure
136 * Disable interrupts while we do the polling
138 spin_lock_irqsave(&sc->lmc_lock, flags);
142 * Return current driver state. Since we keep this up
143 * To date internally, just copy this out to the user.
145 case LMCIOCGINFO: /*fold01*/
146 if (copy_to_user(ifr->ifr_data, &sc->ictl, sizeof (lmc_ctl_t)))
151 case LMCIOCSINFO: /*fold01*/
152 sp = &((struct ppp_device *) dev)->sppp;
153 if (!capable(CAP_NET_ADMIN)) {
158 if(dev->flags & IFF_UP){
163 if (copy_from_user(&ctl, ifr->ifr_data, sizeof (lmc_ctl_t)))
166 sc->lmc_media->set_status (sc, &ctl);
168 if(ctl.crc_length != sc->ictl.crc_length) {
169 sc->lmc_media->set_crc_length(sc, ctl.crc_length);
170 if (sc->ictl.crc_length == LMC_CTL_CRC_LENGTH_16)
171 sc->TxDescriptControlInit |= LMC_TDES_ADD_CRC_DISABLE;
173 sc->TxDescriptControlInit &= ~LMC_TDES_ADD_CRC_DISABLE;
176 if (ctl.keepalive_onoff == LMC_CTL_OFF)
177 sp->pp_flags &= ~PP_KEEPALIVE; /* Turn off */
179 sp->pp_flags |= PP_KEEPALIVE; /* Turn on */
184 case LMCIOCIFTYPE: /*fold01*/
186 u_int16_t old_type = sc->if_type;
189 if (!capable(CAP_NET_ADMIN)) {
194 if (copy_from_user(&new_type, ifr->ifr_data, sizeof(u_int16_t)))
198 if (new_type == old_type)
201 break; /* no change */
205 lmc_proto_detach(sc);
207 sc->if_type = new_type;
208 // lmc_proto_init(sc);
209 lmc_proto_attach(sc);
216 case LMCIOCGETXINFO: /*fold01*/
217 sc->lmc_xinfo.Magic0 = 0xBEEFCAFE;
219 sc->lmc_xinfo.PciCardType = sc->lmc_cardtype;
220 sc->lmc_xinfo.PciSlotNumber = 0;
221 sc->lmc_xinfo.DriverMajorVersion = DRIVER_MAJOR_VERSION;
222 sc->lmc_xinfo.DriverMinorVersion = DRIVER_MINOR_VERSION;
223 sc->lmc_xinfo.DriverSubVersion = DRIVER_SUB_VERSION;
224 sc->lmc_xinfo.XilinxRevisionNumber =
225 lmc_mii_readreg (sc, 0, 3) & 0xf;
226 sc->lmc_xinfo.MaxFrameSize = LMC_PKT_BUF_SZ;
227 sc->lmc_xinfo.link_status = sc->lmc_media->get_link_status (sc);
228 sc->lmc_xinfo.mii_reg16 = lmc_mii_readreg (sc, 0, 16);
230 sc->lmc_xinfo.Magic1 = 0xDEADBEEF;
232 if (copy_to_user(ifr->ifr_data, &sc->lmc_xinfo,
233 sizeof (struct lmc_xinfo)))
239 case LMCIOCGETLMCSTATS: /*fold01*/
240 if (sc->lmc_cardtype == LMC_CARDTYPE_T1){
241 lmc_mii_writereg (sc, 0, 17, T1FRAMER_FERR_LSB);
242 sc->stats.framingBitErrorCount +=
243 lmc_mii_readreg (sc, 0, 18) & 0xff;
244 lmc_mii_writereg (sc, 0, 17, T1FRAMER_FERR_MSB);
245 sc->stats.framingBitErrorCount +=
246 (lmc_mii_readreg (sc, 0, 18) & 0xff) << 8;
247 lmc_mii_writereg (sc, 0, 17, T1FRAMER_LCV_LSB);
248 sc->stats.lineCodeViolationCount +=
249 lmc_mii_readreg (sc, 0, 18) & 0xff;
250 lmc_mii_writereg (sc, 0, 17, T1FRAMER_LCV_MSB);
251 sc->stats.lineCodeViolationCount +=
252 (lmc_mii_readreg (sc, 0, 18) & 0xff) << 8;
253 lmc_mii_writereg (sc, 0, 17, T1FRAMER_AERR);
254 regVal = lmc_mii_readreg (sc, 0, 18) & 0xff;
256 sc->stats.lossOfFrameCount +=
257 (regVal & T1FRAMER_LOF_MASK) >> 4;
258 sc->stats.changeOfFrameAlignmentCount +=
259 (regVal & T1FRAMER_COFA_MASK) >> 2;
260 sc->stats.severelyErroredFrameCount +=
261 regVal & T1FRAMER_SEF_MASK;
264 if (copy_to_user(ifr->ifr_data, &sc->stats,
265 sizeof (struct lmc_statistics)))
271 case LMCIOCCLEARLMCSTATS: /*fold01*/
272 if (!capable(CAP_NET_ADMIN)){
277 memset (&sc->stats, 0, sizeof (struct lmc_statistics));
278 sc->stats.check = STATCHECK;
279 sc->stats.version_size = (DRIVER_VERSION << 16) +
280 sizeof (struct lmc_statistics);
281 sc->stats.lmc_cardtype = sc->lmc_cardtype;
285 case LMCIOCSETCIRCUIT: /*fold01*/
286 if (!capable(CAP_NET_ADMIN)){
291 if(dev->flags & IFF_UP){
296 if (copy_from_user(&ctl, ifr->ifr_data, sizeof (lmc_ctl_t)))
298 sc->lmc_media->set_circuit_type(sc, ctl.circuit_type);
299 sc->ictl.circuit_type = ctl.circuit_type;
304 case LMCIOCRESET: /*fold01*/
305 if (!capable(CAP_NET_ADMIN)){
310 /* Reset driver and bring back to current state */
311 printk (" REG16 before reset +%04x\n", lmc_mii_readreg (sc, 0, 16));
312 lmc_running_reset (dev);
313 printk (" REG16 after reset +%04x\n", lmc_mii_readreg (sc, 0, 16));
315 LMC_EVENT_LOG(LMC_EVENT_FORCEDRESET, LMC_CSR_READ (sc, csr_status), lmc_mii_readreg (sc, 0, 16));
321 case LMCIOCDUMPEVENTLOG:
322 if (copy_to_user(ifr->ifr_data, &lmcEventLogIndex, sizeof (u32)))
324 if (copy_to_user(ifr->ifr_data + sizeof (u32), lmcEventLogBuf, sizeof (lmcEventLogBuf)))
329 #endif /* end ifdef _DBG_EVENTLOG */
330 case LMCIOCT1CONTROL: /*fold01*/
331 if (sc->lmc_cardtype != LMC_CARDTYPE_T1){
336 case LMCIOCXILINX: /*fold01*/
338 struct lmc_xilinx_control xc; /*fold02*/
340 if (!capable(CAP_NET_ADMIN)){
346 * Stop the xwitter whlie we restart the hardware
348 netif_stop_queue(dev);
350 if (copy_from_user(&xc, ifr->ifr_data, sizeof (struct lmc_xilinx_control)))
353 case lmc_xilinx_reset: /*fold02*/
356 mii = lmc_mii_readreg (sc, 0, 16);
359 * Make all of them 0 and make input
361 lmc_gpio_mkinput(sc, 0xff);
364 * make the reset output
366 lmc_gpio_mkoutput(sc, LMC_GEP_RESET);
369 * RESET low to force configuration. This also forces
370 * the transmitter clock to be internal, but we expect to reset
374 sc->lmc_gpio &= ~LMC_GEP_RESET;
375 LMC_CSR_WRITE(sc, csr_gp, sc->lmc_gpio);
379 * hold for more than 10 microseconds
383 sc->lmc_gpio |= LMC_GEP_RESET;
384 LMC_CSR_WRITE(sc, csr_gp, sc->lmc_gpio);
388 * stop driving Xilinx-related signals
390 lmc_gpio_mkinput(sc, 0xff);
392 /* Reset the frammer hardware */
393 sc->lmc_media->set_link_status (sc, 1);
394 sc->lmc_media->set_status (sc, NULL);
395 // lmc_softreset(sc);
399 for(i = 0; i < 5; i++){
400 lmc_led_on(sc, LMC_DS3_LED0);
402 lmc_led_off(sc, LMC_DS3_LED0);
403 lmc_led_on(sc, LMC_DS3_LED1);
405 lmc_led_off(sc, LMC_DS3_LED1);
406 lmc_led_on(sc, LMC_DS3_LED3);
408 lmc_led_off(sc, LMC_DS3_LED3);
409 lmc_led_on(sc, LMC_DS3_LED2);
411 lmc_led_off(sc, LMC_DS3_LED2);
422 case lmc_xilinx_load_prom: /*fold02*/
425 int timeout = 500000;
426 mii = lmc_mii_readreg (sc, 0, 16);
429 * Make all of them 0 and make input
431 lmc_gpio_mkinput(sc, 0xff);
434 * make the reset output
436 lmc_gpio_mkoutput(sc, LMC_GEP_DP | LMC_GEP_RESET);
439 * RESET low to force configuration. This also forces
440 * the transmitter clock to be internal, but we expect to reset
444 sc->lmc_gpio &= ~(LMC_GEP_RESET | LMC_GEP_DP);
445 LMC_CSR_WRITE(sc, csr_gp, sc->lmc_gpio);
449 * hold for more than 10 microseconds
453 sc->lmc_gpio |= LMC_GEP_DP | LMC_GEP_RESET;
454 LMC_CSR_WRITE(sc, csr_gp, sc->lmc_gpio);
457 * busy wait for the chip to reset
459 while( (LMC_CSR_READ(sc, csr_gp) & LMC_GEP_INIT) == 0 &&
465 * stop driving Xilinx-related signals
467 lmc_gpio_mkinput(sc, 0xff);
476 case lmc_xilinx_load: /*fold02*/
480 int timeout = 500000;
487 data = kmalloc(xc.len, GFP_KERNEL);
489 printk(KERN_WARNING "%s: Failed to allocate memory for copy\n", dev->name);
494 if(copy_from_user(data, xc.data, xc.len))
501 printk("%s: Starting load of data Len: %d at 0x%p == 0x%p\n", dev->name, xc.len, xc.data, data);
503 lmc_gpio_mkinput(sc, 0xff);
506 * Clear the Xilinx and start prgramming from the DEC
517 sc->lmc_gpio &= ~LMC_GEP_DP;
518 sc->lmc_gpio &= ~LMC_GEP_RESET;
519 sc->lmc_gpio |= LMC_GEP_MODE;
520 LMC_CSR_WRITE(sc, csr_gp, sc->lmc_gpio);
522 lmc_gpio_mkoutput(sc, LMC_GEP_MODE | LMC_GEP_DP | LMC_GEP_RESET);
525 * Wait at least 10 us 20 to be safe
530 * Clear reset and activate programming lines
537 lmc_gpio_mkinput(sc, LMC_GEP_DP | LMC_GEP_RESET);
540 * Set LOAD, DATA, Clock to 1
543 sc->lmc_gpio |= LMC_GEP_MODE;
544 sc->lmc_gpio |= LMC_GEP_DATA;
545 sc->lmc_gpio |= LMC_GEP_CLK;
546 LMC_CSR_WRITE(sc, csr_gp, sc->lmc_gpio);
548 lmc_gpio_mkoutput(sc, LMC_GEP_DATA | LMC_GEP_CLK | LMC_GEP_MODE );
551 * busy wait for the chip to reset
553 while( (LMC_CSR_READ(sc, csr_gp) & LMC_GEP_INIT) == 0 &&
557 printk(KERN_DEBUG "%s: Waited %d for the Xilinx to clear it's memory\n", dev->name, 500000-timeout);
559 for(pos = 0; pos < xc.len; pos++){
562 sc->lmc_gpio &= ~LMC_GEP_DATA; /* Data is 0 */
565 sc->lmc_gpio |= LMC_GEP_DATA; /* Data is 1 */
568 printk(KERN_WARNING "%s Bad data in xilinx programming data at %d, got %d wanted 0 or 1\n", dev->name, pos, data[pos]);
569 sc->lmc_gpio |= LMC_GEP_DATA; /* Assume it's 1 */
571 sc->lmc_gpio &= ~LMC_GEP_CLK; /* Clock to zero */
572 sc->lmc_gpio |= LMC_GEP_MODE;
573 LMC_CSR_WRITE(sc, csr_gp, sc->lmc_gpio);
576 sc->lmc_gpio |= LMC_GEP_CLK; /* Put the clack back to one */
577 sc->lmc_gpio |= LMC_GEP_MODE;
578 LMC_CSR_WRITE(sc, csr_gp, sc->lmc_gpio);
581 if((LMC_CSR_READ(sc, csr_gp) & LMC_GEP_INIT) == 0){
582 printk(KERN_WARNING "%s: Reprogramming FAILED. Needs to be reprogrammed. (corrupted data)\n", dev->name);
584 else if((LMC_CSR_READ(sc, csr_gp) & LMC_GEP_DP) == 0){
585 printk(KERN_WARNING "%s: Reprogramming FAILED. Needs to be reprogrammed. (done)\n", dev->name);
588 printk(KERN_DEBUG "%s: Done reprogramming Xilinx, %d bits, good luck!\n", dev->name, pos);
591 lmc_gpio_mkinput(sc, 0xff);
593 sc->lmc_miireg16 |= LMC_MII16_FIFO_RESET;
594 lmc_mii_writereg(sc, 0, 16, sc->lmc_miireg16);
596 sc->lmc_miireg16 &= ~LMC_MII16_FIFO_RESET;
597 lmc_mii_writereg(sc, 0, 16, sc->lmc_miireg16);
610 netif_wake_queue(dev);
616 /* If we don't know what to do, give the protocol a shot. */
617 ret = lmc_proto_ioctl (sc, ifr, cmd);
621 spin_unlock_irqrestore(&sc->lmc_lock, flags); /*fold01*/
623 lmc_trace(dev, "lmc_ioctl out");
629 /* the watchdog process that cruises around */
630 static void lmc_watchdog (unsigned long data) /*fold00*/
632 struct net_device *dev = (struct net_device *) data;
640 lmc_trace(dev, "lmc_watchdog in");
642 spin_lock_irqsave(&sc->lmc_lock, flags);
644 if(sc->check != 0xBEAFCAFE){
645 printk("LMC: Corrupt net_device stuct, breaking out\n");
646 spin_unlock_irqrestore(&sc->lmc_lock, flags);
651 /* Make sure the tx jabber and rx watchdog are off,
652 * and the transmit and receive processes are running.
655 LMC_CSR_WRITE (sc, csr_15, 0x00000011);
656 sc->lmc_cmdmode |= TULIP_CMD_TXRUN | TULIP_CMD_RXRUN;
657 LMC_CSR_WRITE (sc, csr_command, sc->lmc_cmdmode);
662 LMC_EVENT_LOG(LMC_EVENT_WATCHDOG, LMC_CSR_READ (sc, csr_status), lmc_mii_readreg (sc, 0, 16));
664 /* --- begin time out check -----------------------------------
665 * check for a transmit interrupt timeout
666 * Has the packet xmt vs xmt serviced threshold been exceeded */
667 if (sc->lmc_taint_tx == sc->lastlmc_taint_tx &&
668 sc->stats.tx_packets > sc->lasttx_packets &&
669 sc->tx_TimeoutInd == 0)
672 /* wait for the watchdog to come around again */
673 sc->tx_TimeoutInd = 1;
675 else if (sc->lmc_taint_tx == sc->lastlmc_taint_tx &&
676 sc->stats.tx_packets > sc->lasttx_packets &&
680 LMC_EVENT_LOG(LMC_EVENT_XMTINTTMO, LMC_CSR_READ (sc, csr_status), 0);
682 sc->tx_TimeoutDisplay = 1;
683 sc->stats.tx_TimeoutCnt++;
685 /* DEC chip is stuck, hit it with a RESET!!!! */
686 lmc_running_reset (dev);
689 /* look at receive & transmit process state to make sure they are running */
690 LMC_EVENT_LOG(LMC_EVENT_RESET1, LMC_CSR_READ (sc, csr_status), 0);
692 /* look at: DSR - 02 for Reg 16
698 LMC_EVENT_LOG(LMC_EVENT_RESET2, lmc_mii_readreg (sc, 0, 16), lmc_mii_readreg (sc, 0, 17));
700 /* reset the transmit timeout detection flag */
701 sc->tx_TimeoutInd = 0;
702 sc->lastlmc_taint_tx = sc->lmc_taint_tx;
703 sc->lasttx_packets = sc->stats.tx_packets;
707 sc->tx_TimeoutInd = 0;
708 sc->lastlmc_taint_tx = sc->lmc_taint_tx;
709 sc->lasttx_packets = sc->stats.tx_packets;
712 /* --- end time out check ----------------------------------- */
715 link_status = sc->lmc_media->get_link_status (sc);
718 * hardware level link lost, but the interface is marked as up.
721 if ((link_status == 0) && (sc->last_link_status != 0)) {
722 printk(KERN_WARNING "%s: hardware/physical link down\n", dev->name);
723 sc->last_link_status = 0;
724 /* lmc_reset (sc); Why reset??? The link can go down ok */
726 /* Inform the world that link has been lost */
727 dev->flags &= ~IFF_RUNNING;
731 * hardware link is up, but the interface is marked as down.
732 * Bring it back up again.
734 if (link_status != 0 && sc->last_link_status == 0) {
735 printk(KERN_WARNING "%s: hardware/physical link up\n", dev->name);
736 sc->last_link_status = 1;
737 /* lmc_reset (sc); Again why reset??? */
739 /* Inform the world that link protocol is back up. */
740 dev->flags |= IFF_RUNNING;
742 /* Now we have to tell the syncppp that we had an outage
743 * and that it should deal. Calling sppp_reopen here
744 * should do the trick, but we may have to call sppp_close
745 * when the link goes down, and call sppp_open here.
746 * Subject to more testing.
750 lmc_proto_reopen(sc);
754 /* Call media specific watchdog functions */
755 sc->lmc_media->watchdog(sc);
758 * Poke the transmitter to make sure it
759 * never stops, even if we run out of mem
761 LMC_CSR_WRITE(sc, csr_rxpoll, 0);
764 * Check for code that failed
765 * and try and fix it as appropriate
767 if(sc->failed_ring == 1){
769 * Failed to setup the recv/xmit rin
775 if(sc->failed_recv_alloc == 1){
777 * We failed to alloc mem in the
778 * interrupt handler, go through the rings
781 sc->failed_recv_alloc = 0;
787 * remember the timer value
791 ticks = LMC_CSR_READ (sc, csr_gp_timer);
792 LMC_CSR_WRITE (sc, csr_gp_timer, 0xffffffffUL);
793 sc->ictl.ticks = 0x0000ffff - (ticks & 0x0000ffff);
796 * restart this timer.
798 sc->timer.expires = jiffies + (HZ);
799 add_timer (&sc->timer);
801 spin_unlock_irqrestore(&sc->lmc_lock, flags);
803 lmc_trace(dev, "lmc_watchdog out");
807 static void lmc_setup(struct net_device * const dev) /*fold00*/
809 lmc_trace(dev, "lmc_setup in");
811 dev->type = ARPHRD_HDLC;
812 dev->hard_start_xmit = lmc_start_xmit;
813 dev->open = lmc_open;
814 dev->stop = lmc_close;
815 dev->get_stats = lmc_get_stats;
816 dev->do_ioctl = lmc_ioctl;
817 dev->set_config = lmc_set_config;
818 dev->tx_timeout = lmc_driver_timeout;
819 dev->watchdog_timeo = (HZ); /* 1 second */
821 lmc_trace(dev, "lmc_setup out");
825 static int __devinit lmc_init_one(struct pci_dev *pdev,
826 const struct pci_device_id *ent)
828 struct net_device *dev;
831 u_int16_t AdapModelNum;
833 static int cards_found;
835 /* We name by type not by vendor */
836 static const char lmcname[] = "hdlc%d";
839 * GCOM uses LMC vendor name so that clients can know which card
842 static const char lmcname[] = "lmc%d";
847 * Allocate our own device structure
849 dev = alloc_netdev(sizeof(lmc_softc_t), lmcname, lmc_setup);
851 printk (KERN_ERR "lmc:alloc_netdev for device failed\n");
855 lmc_trace(dev, "lmc_init_one in");
857 err = pci_enable_device(pdev);
859 printk(KERN_ERR "lmc: pci enable failed:%d\n", err);
863 if (pci_request_regions(pdev, "lmc")) {
864 printk(KERN_ERR "lmc: pci_request_region failed\n");
869 pci_set_drvdata(pdev, dev);
871 if(lmc_first_load == 0){
872 printk(KERN_INFO "Lan Media Corporation WAN Driver Version %d.%d.%d\n",
873 DRIVER_MAJOR_VERSION, DRIVER_MINOR_VERSION,DRIVER_SUB_VERSION);
878 sc->lmc_device = dev;
879 sc->name = dev->name;
881 /* Initialize the sppp layer */
882 /* An ioctl can cause a subsequent detach for raw frame interface */
883 sc->if_type = LMC_PPP;
884 sc->check = 0xBEAFCAFE;
885 dev->base_addr = pci_resource_start(pdev, 0);
886 dev->irq = pdev->irq;
888 SET_MODULE_OWNER(dev);
889 SET_NETDEV_DEV(dev, &pdev->dev);
892 * This will get the protocol layer ready and do any 1 time init's
893 * Must have a valid sc and dev structure
897 lmc_proto_attach(sc);
900 * Why were we changing this???
901 dev->tx_queue_len = 100;
904 /* Init the spin lock so can call it latter */
906 spin_lock_init(&sc->lmc_lock);
907 pci_set_master(pdev);
909 printk ("%s: detected at %lx, irq %d\n", dev->name,
910 dev->base_addr, dev->irq);
912 if (register_netdev (dev) != 0) {
913 printk (KERN_ERR "%s: register_netdev failed.\n", dev->name);
917 sc->lmc_cardtype = LMC_CARDTYPE_UNKNOWN;
918 sc->lmc_timing = LMC_CTL_CLOCK_SOURCE_EXT;
922 * Check either the subvendor or the subdevice, some systems reverse
923 * the setting in the bois, seems to be version and arch dependent?
924 * Fix the error, exchange the two values
926 if ((subdevice = pdev->subsystem_device) == PCI_VENDOR_ID_LMC)
927 subdevice = pdev->subsystem_vendor;
930 case PCI_DEVICE_ID_LMC_HSSI:
931 printk ("%s: LMC HSSI\n", dev->name);
932 sc->lmc_cardtype = LMC_CARDTYPE_HSSI;
933 sc->lmc_media = &lmc_hssi_media;
935 case PCI_DEVICE_ID_LMC_DS3:
936 printk ("%s: LMC DS3\n", dev->name);
937 sc->lmc_cardtype = LMC_CARDTYPE_DS3;
938 sc->lmc_media = &lmc_ds3_media;
940 case PCI_DEVICE_ID_LMC_SSI:
941 printk ("%s: LMC SSI\n", dev->name);
942 sc->lmc_cardtype = LMC_CARDTYPE_SSI;
943 sc->lmc_media = &lmc_ssi_media;
945 case PCI_DEVICE_ID_LMC_T1:
946 printk ("%s: LMC T1\n", dev->name);
947 sc->lmc_cardtype = LMC_CARDTYPE_T1;
948 sc->lmc_media = &lmc_t1_media;
951 printk (KERN_WARNING "%s: LMC UNKOWN CARD!\n", dev->name);
955 lmc_initcsrs (sc, dev->base_addr, 8);
957 lmc_gpio_mkinput (sc, 0xff);
958 sc->lmc_gpio = 0; /* drive no signals yet */
960 sc->lmc_media->defaults (sc);
962 sc->lmc_media->set_link_status (sc, LMC_LINK_UP);
964 /* verify that the PCI Sub System ID matches the Adapter Model number
965 * from the MII register
967 AdapModelNum = (lmc_mii_readreg (sc, 0, 3) & 0x3f0) >> 4;
969 if ((AdapModelNum == LMC_ADAP_T1
970 && subdevice == PCI_DEVICE_ID_LMC_T1) || /* detect LMC1200 */
971 (AdapModelNum == LMC_ADAP_SSI
972 && subdevice == PCI_DEVICE_ID_LMC_SSI) || /* detect LMC1000 */
973 (AdapModelNum == LMC_ADAP_DS3
974 && subdevice == PCI_DEVICE_ID_LMC_DS3) || /* detect LMC5245 */
975 (AdapModelNum == LMC_ADAP_HSSI
976 && subdevice == PCI_DEVICE_ID_LMC_HSSI))
977 { /* detect LMC5200 */
981 printk ("%s: Model number (%d) miscompare for PCI Subsystem ID = 0x%04x\n",
982 dev->name, AdapModelNum, subdevice);
988 LMC_CSR_WRITE (sc, csr_gp_timer, 0xFFFFFFFFUL);
990 sc->board_idx = cards_found++;
991 sc->stats.check = STATCHECK;
992 sc->stats.version_size = (DRIVER_VERSION << 16) +
993 sizeof (struct lmc_statistics);
994 sc->stats.lmc_cardtype = sc->lmc_cardtype;
997 sc->last_link_status = 0;
999 lmc_trace(dev, "lmc_init_one out");
1003 lmc_proto_detach(sc);
1006 pci_release_regions(pdev);
1007 pci_set_drvdata(pdev, NULL);
1016 * Called from pci when removing module.
1018 static void __devexit lmc_remove_one (struct pci_dev *pdev)
1020 struct net_device *dev = pci_get_drvdata(pdev);
1023 lmc_softc_t *sc = dev->priv;
1025 printk("%s: removing...\n", dev->name);
1026 lmc_proto_detach(sc);
1027 unregister_netdev(dev);
1029 pci_release_regions(pdev);
1030 pci_disable_device(pdev);
1031 pci_set_drvdata(pdev, NULL);
1035 /* After this is called, packets can be sent.
1036 * Does not initialize the addresses
1038 static int lmc_open (struct net_device *dev) /*fold00*/
1040 lmc_softc_t *sc = dev->priv;
1042 lmc_trace(dev, "lmc_open in");
1044 lmc_led_on(sc, LMC_DS3_LED0);
1049 LMC_EVENT_LOG(LMC_EVENT_RESET1, LMC_CSR_READ (sc, csr_status), 0);
1050 LMC_EVENT_LOG(LMC_EVENT_RESET2,
1051 lmc_mii_readreg (sc, 0, 16),
1052 lmc_mii_readreg (sc, 0, 17));
1056 lmc_trace(dev, "lmc_open lmc_ok out");
1062 /* Since we have to use PCI bus, this should work on x86,alpha,ppc */
1063 if (request_irq (dev->irq, &lmc_interrupt, SA_SHIRQ, dev->name, dev)){
1064 printk(KERN_WARNING "%s: could not get irq: %d\n", dev->name, dev->irq);
1065 lmc_trace(dev, "lmc_open irq failed out");
1070 /* Assert Terminal Active */
1071 sc->lmc_miireg16 |= LMC_MII16_LED_ALL;
1072 sc->lmc_media->set_link_status (sc, LMC_LINK_UP);
1075 * reset to last state.
1077 sc->lmc_media->set_status (sc, NULL);
1079 /* setup default bits to be used in tulip_desc_t transmit descriptor
1081 sc->TxDescriptControlInit = (
1082 LMC_TDES_INTERRUPT_ON_COMPLETION
1083 | LMC_TDES_FIRST_SEGMENT
1084 | LMC_TDES_LAST_SEGMENT
1085 | LMC_TDES_SECOND_ADDR_CHAINED
1086 | LMC_TDES_DISABLE_PADDING
1089 if (sc->ictl.crc_length == LMC_CTL_CRC_LENGTH_16) {
1090 /* disable 32 bit CRC generated by ASIC */
1091 sc->TxDescriptControlInit |= LMC_TDES_ADD_CRC_DISABLE;
1093 sc->lmc_media->set_crc_length(sc, sc->ictl.crc_length);
1094 /* Acknoledge the Terminal Active and light LEDs */
1096 /* dev->flags |= IFF_UP; */
1100 dev->do_ioctl = lmc_ioctl;
1103 netif_start_queue(dev);
1105 sc->stats.tx_tbusy0++ ;
1108 * select what interrupts we want to get
1110 sc->lmc_intrmask = 0;
1111 /* Should be using the default interrupt mask defined in the .h file. */
1112 sc->lmc_intrmask |= (TULIP_STS_NORMALINTR
1115 | TULIP_STS_ABNRMLINTR
1116 | TULIP_STS_SYSERROR
1117 | TULIP_STS_TXSTOPPED
1118 | TULIP_STS_TXUNDERFLOW
1119 | TULIP_STS_RXSTOPPED
1122 LMC_CSR_WRITE (sc, csr_intr, sc->lmc_intrmask);
1124 sc->lmc_cmdmode |= TULIP_CMD_TXRUN;
1125 sc->lmc_cmdmode |= TULIP_CMD_RXRUN;
1126 LMC_CSR_WRITE (sc, csr_command, sc->lmc_cmdmode);
1128 sc->lmc_ok = 1; /* Run watchdog */
1131 * Set the if up now - pfb
1134 sc->last_link_status = 1;
1137 * Setup a timer for the watchdog on probe, and start it running.
1138 * Since lmc_ok == 0, it will be a NOP for now.
1140 init_timer (&sc->timer);
1141 sc->timer.expires = jiffies + HZ;
1142 sc->timer.data = (unsigned long) dev;
1143 sc->timer.function = &lmc_watchdog;
1144 add_timer (&sc->timer);
1146 lmc_trace(dev, "lmc_open out");
1151 /* Total reset to compensate for the AdTran DSU doing bad things
1155 static void lmc_running_reset (struct net_device *dev) /*fold00*/
1158 lmc_softc_t *sc = (lmc_softc_t *) dev->priv;
1160 lmc_trace(dev, "lmc_runnig_reset in");
1162 /* stop interrupts */
1163 /* Clear the interrupt mask */
1164 LMC_CSR_WRITE (sc, csr_intr, 0x00000000);
1169 /* sc->lmc_miireg16 |= LMC_MII16_LED_ALL; */
1170 sc->lmc_media->set_link_status (sc, 1);
1171 sc->lmc_media->set_status (sc, NULL);
1173 //dev->flags |= IFF_RUNNING;
1175 netif_wake_queue(dev);
1178 sc->stats.tx_tbusy0++ ;
1180 sc->lmc_intrmask = TULIP_DEFAULT_INTR_MASK;
1181 LMC_CSR_WRITE (sc, csr_intr, sc->lmc_intrmask);
1183 sc->lmc_cmdmode |= (TULIP_CMD_TXRUN | TULIP_CMD_RXRUN);
1184 LMC_CSR_WRITE (sc, csr_command, sc->lmc_cmdmode);
1186 lmc_trace(dev, "lmc_runnin_reset_out");
1190 /* This is what is called when you ifconfig down a device.
1191 * This disables the timer for the watchdog and keepalives,
1192 * and disables the irq for dev.
1194 static int lmc_close (struct net_device *dev) /*fold00*/
1196 /* not calling release_region() as we should */
1199 lmc_trace(dev, "lmc_close in");
1203 sc->lmc_media->set_link_status (sc, 0);
1204 del_timer (&sc->timer);
1205 lmc_proto_close(sc);
1208 lmc_trace(dev, "lmc_close out");
1213 /* Ends the transfer of packets */
1214 /* When the interface goes down, this is called */
1215 static int lmc_ifdown (struct net_device *dev) /*fold00*/
1217 lmc_softc_t *sc = dev->priv;
1221 lmc_trace(dev, "lmc_ifdown in");
1223 /* Don't let anything else go on right now */
1225 netif_stop_queue(dev);
1226 sc->stats.tx_tbusy1++ ;
1228 /* stop interrupts */
1229 /* Clear the interrupt mask */
1230 LMC_CSR_WRITE (sc, csr_intr, 0x00000000);
1232 /* Stop Tx and Rx on the chip */
1233 csr6 = LMC_CSR_READ (sc, csr_command);
1234 csr6 &= ~LMC_DEC_ST; /* Turn off the Transmission bit */
1235 csr6 &= ~LMC_DEC_SR; /* Turn off the Receive bit */
1236 LMC_CSR_WRITE (sc, csr_command, csr6);
1238 dev->flags &= ~IFF_RUNNING;
1240 sc->stats.rx_missed_errors +=
1241 LMC_CSR_READ (sc, csr_missed_frames) & 0xffff;
1243 /* release the interrupt */
1244 if(sc->got_irq == 1){
1245 free_irq (dev->irq, dev);
1249 /* free skbuffs in the Rx queue */
1250 for (i = 0; i < LMC_RXDESCS; i++)
1252 struct sk_buff *skb = sc->lmc_rxq[i];
1253 sc->lmc_rxq[i] = NULL;
1254 sc->lmc_rxring[i].status = 0;
1255 sc->lmc_rxring[i].length = 0;
1256 sc->lmc_rxring[i].buffer1 = 0xDEADBEEF;
1259 sc->lmc_rxq[i] = NULL;
1262 for (i = 0; i < LMC_TXDESCS; i++)
1264 if (sc->lmc_txq[i] != NULL)
1265 dev_kfree_skb(sc->lmc_txq[i]);
1266 sc->lmc_txq[i] = NULL;
1269 lmc_led_off (sc, LMC_MII16_LED_ALL);
1271 netif_wake_queue(dev);
1272 sc->stats.tx_tbusy0++ ;
1274 lmc_trace(dev, "lmc_ifdown out");
1279 /* Interrupt handling routine. This will take an incoming packet, or clean
1280 * up after a trasmit.
1282 static irqreturn_t lmc_interrupt (int irq, void *dev_instance, struct pt_regs *regs) /*fold00*/
1284 struct net_device *dev = (struct net_device *) dev_instance;
1291 int max_work = LMC_RXDESCS;
1294 lmc_trace(dev, "lmc_interrupt in");
1298 spin_lock(&sc->lmc_lock);
1301 * Read the csr to find what interrupts we have (if any)
1303 csr = LMC_CSR_READ (sc, csr_status);
1306 * Make sure this is our interrupt
1308 if ( ! (csr & sc->lmc_intrmask)) {
1309 goto lmc_int_fail_out;
1314 /* always go through this loop at least once */
1315 while (csr & sc->lmc_intrmask) {
1319 * Clear interrupt bits, we handle all case below
1321 LMC_CSR_WRITE (sc, csr_status, csr);
1325 * - Transmit process timed out CSR5<1>
1326 * - Transmit jabber timeout CSR5<3>
1327 * - Transmit underflow CSR5<5>
1328 * - Transmit Receiver buffer unavailable CSR5<7>
1329 * - Receive process stopped CSR5<8>
1330 * - Receive watchdog timeout CSR5<9>
1331 * - Early transmit interrupt CSR5<10>
1333 * Is this really right? Should we do a running reset for jabber?
1334 * (being a WAN card and all)
1336 if (csr & TULIP_STS_ABNRMLINTR){
1337 lmc_running_reset (dev);
1341 if (csr & TULIP_STS_RXINTR){
1342 lmc_trace(dev, "rx interrupt");
1346 if (csr & (TULIP_STS_TXINTR | TULIP_STS_TXNOBUF | TULIP_STS_TXSTOPPED)) {
1349 /* reset the transmit timeout detection flag -baz */
1350 sc->stats.tx_NoCompleteCnt = 0;
1352 badtx = sc->lmc_taint_tx;
1353 i = badtx % LMC_TXDESCS;
1355 while ((badtx < sc->lmc_next_tx)) {
1356 stat = sc->lmc_txring[i].status;
1358 LMC_EVENT_LOG (LMC_EVENT_XMTINT, stat,
1359 sc->lmc_txring[i].length);
1361 * If bit 31 is 1 the tulip owns it break out of the loop
1363 if (stat & 0x80000000)
1366 n_compl++ ; /* i.e., have an empty slot in ring */
1368 * If we have no skbuff or have cleared it
1369 * Already continue to the next buffer
1371 if (sc->lmc_txq[i] == NULL)
1375 * Check the total error summary to look for any errors
1377 if (stat & 0x8000) {
1378 sc->stats.tx_errors++;
1380 sc->stats.tx_aborted_errors++;
1382 sc->stats.tx_carrier_errors++;
1384 sc->stats.tx_window_errors++;
1386 sc->stats.tx_fifo_errors++;
1390 sc->stats.tx_bytes += sc->lmc_txring[i].length & 0x7ff;
1392 sc->stats.tx_packets++;
1395 // dev_kfree_skb(sc->lmc_txq[i]);
1396 dev_kfree_skb_irq(sc->lmc_txq[i]);
1397 sc->lmc_txq[i] = NULL;
1400 i = badtx % LMC_TXDESCS;
1403 if (sc->lmc_next_tx - badtx > LMC_TXDESCS)
1405 printk ("%s: out of sync pointer\n", dev->name);
1406 badtx += LMC_TXDESCS;
1408 LMC_EVENT_LOG(LMC_EVENT_TBUSY0, n_compl, 0);
1410 netif_wake_queue(dev);
1411 sc->stats.tx_tbusy0++ ;
1415 sc->stats.dirtyTx = badtx;
1416 sc->stats.lmc_next_tx = sc->lmc_next_tx;
1417 sc->stats.lmc_txfull = sc->lmc_txfull;
1419 sc->lmc_taint_tx = badtx;
1422 * Why was there a break here???
1424 } /* end handle transmit interrupt */
1426 if (csr & TULIP_STS_SYSERROR) {
1428 printk (KERN_WARNING "%s: system bus error csr: %#8.8x\n", dev->name, csr);
1429 error = csr>>23 & 0x7;
1432 printk(KERN_WARNING "%s: Parity Fault (bad)\n", dev->name);
1435 printk(KERN_WARNING "%s: Master Abort (naughty)\n", dev->name);
1438 printk(KERN_WARNING "%s: Target Abort (not so naughty)\n", dev->name);
1441 printk(KERN_WARNING "%s: This bus error code was supposed to be reserved!\n", dev->name);
1445 LMC_EVENT_LOG(LMC_EVENT_RESET1, LMC_CSR_READ (sc, csr_status), 0);
1446 LMC_EVENT_LOG(LMC_EVENT_RESET2,
1447 lmc_mii_readreg (sc, 0, 16),
1448 lmc_mii_readreg (sc, 0, 17));
1457 * Get current csr status to make sure
1458 * we've cleared all interrupts
1460 csr = LMC_CSR_READ (sc, csr_status);
1461 } /* end interrupt loop */
1462 LMC_EVENT_LOG(LMC_EVENT_INT, firstcsr, csr);
1466 spin_unlock(&sc->lmc_lock);
1468 lmc_trace(dev, "lmc_interrupt out");
1469 return IRQ_RETVAL(handled);
1472 static int lmc_start_xmit (struct sk_buff *skb, struct net_device *dev) /*fold00*/
1478 unsigned long flags;
1480 lmc_trace(dev, "lmc_start_xmit in");
1484 spin_lock_irqsave(&sc->lmc_lock, flags);
1486 /* normal path, tbusy known to be zero */
1488 entry = sc->lmc_next_tx % LMC_TXDESCS;
1490 sc->lmc_txq[entry] = skb;
1491 sc->lmc_txring[entry].buffer1 = virt_to_bus (skb->data);
1493 LMC_CONSOLE_LOG("xmit", skb->data, skb->len);
1496 /* If the queue is less than half full, don't interrupt */
1497 if (sc->lmc_next_tx - sc->lmc_taint_tx < LMC_TXDESCS / 2)
1499 /* Do not interrupt on completion of this packet */
1501 netif_wake_queue(dev);
1503 else if (sc->lmc_next_tx - sc->lmc_taint_tx == LMC_TXDESCS / 2)
1505 /* This generates an interrupt on completion of this packet */
1507 netif_wake_queue(dev);
1509 else if (sc->lmc_next_tx - sc->lmc_taint_tx < LMC_TXDESCS - 1)
1511 /* Do not interrupt on completion of this packet */
1513 netif_wake_queue(dev);
1517 /* This generates an interrupt on completion of this packet */
1520 netif_stop_queue(dev);
1523 flag = LMC_TDES_INTERRUPT_ON_COMPLETION;
1525 if (sc->lmc_next_tx - sc->lmc_taint_tx >= LMC_TXDESCS - 1)
1526 { /* ring full, go busy */
1528 netif_stop_queue(dev);
1529 sc->stats.tx_tbusy1++ ;
1530 LMC_EVENT_LOG(LMC_EVENT_TBUSY1, entry, 0);
1535 if (entry == LMC_TXDESCS - 1) /* last descriptor in ring */
1536 flag |= LMC_TDES_END_OF_RING; /* flag as such for Tulip */
1538 /* don't pad small packets either */
1539 flag = sc->lmc_txring[entry].length = (skb->len) | flag |
1540 sc->TxDescriptControlInit;
1542 /* set the transmit timeout flag to be checked in
1543 * the watchdog timer handler. -baz
1546 sc->stats.tx_NoCompleteCnt++;
1549 /* give ownership to the chip */
1550 LMC_EVENT_LOG(LMC_EVENT_XMT, flag, entry);
1551 sc->lmc_txring[entry].status = 0x80000000;
1554 LMC_CSR_WRITE (sc, csr_txpoll, 0);
1556 dev->trans_start = jiffies;
1558 spin_unlock_irqrestore(&sc->lmc_lock, flags);
1560 lmc_trace(dev, "lmc_start_xmit_out");
1565 static int lmc_rx (struct net_device *dev) /*fold00*/
1569 int rx_work_limit = LMC_RXDESCS;
1570 unsigned int next_rx;
1571 int rxIntLoopCnt; /* debug -baz */
1572 int localLengthErrCnt = 0;
1574 struct sk_buff *skb, *nsb;
1577 lmc_trace(dev, "lmc_rx in");
1581 lmc_led_on(sc, LMC_DS3_LED3);
1583 rxIntLoopCnt = 0; /* debug -baz */
1585 i = sc->lmc_next_rx % LMC_RXDESCS;
1586 next_rx = sc->lmc_next_rx;
1588 while (((stat = sc->lmc_rxring[i].status) & LMC_RDES_OWN_BIT) != DESC_OWNED_BY_DC21X4)
1590 rxIntLoopCnt++; /* debug -baz */
1591 len = ((stat & LMC_RDES_FRAME_LENGTH) >> RDES_FRAME_LENGTH_BIT_NUMBER);
1592 if ((stat & 0x0300) != 0x0300) { /* Check first segment and last segment */
1593 if ((stat & 0x0000ffff) != 0x7fff) {
1594 /* Oversized frame */
1595 sc->stats.rx_length_errors++;
1600 if(stat & 0x00000008){ /* Catch a dribbling bit error */
1601 sc->stats.rx_errors++;
1602 sc->stats.rx_frame_errors++;
1607 if(stat & 0x00000004){ /* Catch a CRC error by the Xilinx */
1608 sc->stats.rx_errors++;
1609 sc->stats.rx_crc_errors++;
1614 if (len > LMC_PKT_BUF_SZ){
1615 sc->stats.rx_length_errors++;
1616 localLengthErrCnt++;
1620 if (len < sc->lmc_crcSize + 2) {
1621 sc->stats.rx_length_errors++;
1622 sc->stats.rx_SmallPktCnt++;
1623 localLengthErrCnt++;
1627 if(stat & 0x00004000){
1628 printk(KERN_WARNING "%s: Receiver descriptor error, receiver out of sync?\n", dev->name);
1631 len -= sc->lmc_crcSize;
1633 skb = sc->lmc_rxq[i];
1636 * We ran out of memory at some point
1637 * just allocate an skb buff and continue.
1641 nsb = dev_alloc_skb (LMC_PKT_BUF_SZ + 2);
1643 sc->lmc_rxq[i] = nsb;
1645 sc->lmc_rxring[i].buffer1 = virt_to_bus (nsb->tail);
1647 sc->failed_recv_alloc = 1;
1651 dev->last_rx = jiffies;
1652 sc->stats.rx_packets++;
1653 sc->stats.rx_bytes += len;
1655 LMC_CONSOLE_LOG("recv", skb->data, len);
1658 * I'm not sure of the sanity of this
1659 * Packets could be arriving at a constant
1660 * 44.210mbits/sec and we're going to copy
1661 * them into a new buffer??
1664 if(len > (LMC_MTU - (LMC_MTU>>2))){ /* len > LMC_MTU * 0.75 */
1666 * If it's a large packet don't copy it just hand it up
1670 sc->lmc_rxq[i] = NULL;
1671 sc->lmc_rxring[i].buffer1 = 0x0;
1674 skb->protocol = lmc_proto_type(sc, skb);
1675 skb->protocol = htons(ETH_P_WAN_PPP);
1676 skb->mac.raw = skb->data;
1677 // skb->nh.raw = skb->data;
1679 lmc_proto_netif(sc, skb);
1682 * This skb will be destroyed by the upper layers, make a new one
1684 nsb = dev_alloc_skb (LMC_PKT_BUF_SZ + 2);
1686 sc->lmc_rxq[i] = nsb;
1688 sc->lmc_rxring[i].buffer1 = virt_to_bus (nsb->tail);
1689 /* Transferred to 21140 below */
1693 * We've run out of memory, stop trying to allocate
1694 * memory and exit the interrupt handler
1696 * The chip may run out of receivers and stop
1697 * in which care we'll try to allocate the buffer
1698 * again. (once a second)
1700 sc->stats.rx_BuffAllocErr++;
1701 LMC_EVENT_LOG(LMC_EVENT_RCVINT, stat, len);
1702 sc->failed_recv_alloc = 1;
1703 goto skip_out_of_mem;
1707 nsb = dev_alloc_skb(len);
1709 goto give_it_anyways;
1711 memcpy(skb_put(nsb, len), skb->data, len);
1713 nsb->protocol = lmc_proto_type(sc, skb);
1714 nsb->mac.raw = nsb->data;
1715 // nsb->nh.raw = nsb->data;
1717 lmc_proto_netif(sc, nsb);
1721 LMC_EVENT_LOG(LMC_EVENT_RCVINT, stat, len);
1722 sc->lmc_rxring[i].status = DESC_OWNED_BY_DC21X4;
1725 i = sc->lmc_next_rx % LMC_RXDESCS;
1727 if (rx_work_limit < 0)
1731 /* detect condition for LMC1000 where DSU cable attaches and fills
1732 * descriptors with bogus packets
1734 if (localLengthErrCnt > LMC_RXDESCS - 3) {
1735 sc->stats.rx_BadPktSurgeCnt++;
1736 LMC_EVENT_LOG(LMC_EVENT_BADPKTSURGE,
1738 sc->stats.rx_BadPktSurgeCnt);
1741 /* save max count of receive descriptors serviced */
1742 if (rxIntLoopCnt > sc->stats.rxIntLoopCnt) {
1743 sc->stats.rxIntLoopCnt = rxIntLoopCnt; /* debug -baz */
1747 if (rxIntLoopCnt == 0)
1749 for (i = 0; i < LMC_RXDESCS; i++)
1751 if ((sc->lmc_rxring[i].status & LMC_RDES_OWN_BIT)
1752 != DESC_OWNED_BY_DC21X4)
1757 LMC_EVENT_LOG(LMC_EVENT_RCVEND, rxIntLoopCnt, 0);
1762 lmc_led_off(sc, LMC_DS3_LED3);
1766 lmc_trace(dev, "lmc_rx out");
1771 static struct net_device_stats *lmc_get_stats (struct net_device *dev) /*fold00*/
1773 lmc_softc_t *sc = dev->priv;
1774 unsigned long flags;
1776 lmc_trace(dev, "lmc_get_stats in");
1779 spin_lock_irqsave(&sc->lmc_lock, flags);
1781 sc->stats.rx_missed_errors += LMC_CSR_READ (sc, csr_missed_frames) & 0xffff;
1783 spin_unlock_irqrestore(&sc->lmc_lock, flags);
1785 lmc_trace(dev, "lmc_get_stats out");
1787 return (struct net_device_stats *) &sc->stats;
1790 static struct pci_driver lmc_driver = {
1792 .id_table = lmc_pci_tbl,
1793 .probe = lmc_init_one,
1794 .remove = __devexit_p(lmc_remove_one),
1797 static int __init init_lmc(void)
1799 return pci_module_init(&lmc_driver);
1802 static void __exit exit_lmc(void)
1804 pci_unregister_driver(&lmc_driver);
1807 module_init(init_lmc);
1808 module_exit(exit_lmc);
1810 unsigned lmc_mii_readreg (lmc_softc_t * const sc, unsigned devaddr, unsigned regno) /*fold00*/
1813 int command = (0xf6 << 10) | (devaddr << 5) | regno;
1816 lmc_trace(sc->lmc_device, "lmc_mii_readreg in");
1820 lmc_trace(sc->lmc_device, "lmc_mii_readreg: done sync");
1822 for (i = 15; i >= 0; i--)
1824 int dataval = (command & (1 << i)) ? 0x20000 : 0;
1826 LMC_CSR_WRITE (sc, csr_9, dataval);
1828 /* __SLOW_DOWN_IO; */
1829 LMC_CSR_WRITE (sc, csr_9, dataval | 0x10000);
1831 /* __SLOW_DOWN_IO; */
1834 lmc_trace(sc->lmc_device, "lmc_mii_readreg: done1");
1836 for (i = 19; i > 0; i--)
1838 LMC_CSR_WRITE (sc, csr_9, 0x40000);
1840 /* __SLOW_DOWN_IO; */
1841 retval = (retval << 1) | ((LMC_CSR_READ (sc, csr_9) & 0x80000) ? 1 : 0);
1842 LMC_CSR_WRITE (sc, csr_9, 0x40000 | 0x10000);
1844 /* __SLOW_DOWN_IO; */
1847 lmc_trace(sc->lmc_device, "lmc_mii_readreg out");
1849 return (retval >> 1) & 0xffff;
1852 void lmc_mii_writereg (lmc_softc_t * const sc, unsigned devaddr, unsigned regno, unsigned data) /*fold00*/
1855 int command = (0x5002 << 16) | (devaddr << 23) | (regno << 18) | data;
1857 lmc_trace(sc->lmc_device, "lmc_mii_writereg in");
1866 if (command & (1 << i))
1871 LMC_CSR_WRITE (sc, csr_9, datav);
1873 /* __SLOW_DOWN_IO; */
1874 LMC_CSR_WRITE (sc, csr_9, (datav | 0x10000));
1876 /* __SLOW_DOWN_IO; */
1883 LMC_CSR_WRITE (sc, csr_9, 0x40000);
1885 /* __SLOW_DOWN_IO; */
1886 LMC_CSR_WRITE (sc, csr_9, 0x50000);
1888 /* __SLOW_DOWN_IO; */
1892 lmc_trace(sc->lmc_device, "lmc_mii_writereg out");
1895 static void lmc_softreset (lmc_softc_t * const sc) /*fold00*/
1899 lmc_trace(sc->lmc_device, "lmc_softreset in");
1901 /* Initialize the receive rings and buffers. */
1903 sc->lmc_next_rx = 0;
1904 sc->lmc_next_tx = 0;
1905 sc->lmc_taint_rx = 0;
1906 sc->lmc_taint_tx = 0;
1909 * Setup each one of the receiver buffers
1910 * allocate an skbuff for each one, setup the descriptor table
1911 * and point each buffer at the next one
1914 for (i = 0; i < LMC_RXDESCS; i++)
1916 struct sk_buff *skb;
1918 if (sc->lmc_rxq[i] == NULL)
1920 skb = dev_alloc_skb (LMC_PKT_BUF_SZ + 2);
1922 printk(KERN_WARNING "%s: Failed to allocate receiver ring, will try again\n", sc->name);
1923 sc->failed_ring = 1;
1927 sc->lmc_rxq[i] = skb;
1932 skb = sc->lmc_rxq[i];
1935 skb->dev = sc->lmc_device;
1937 /* owned by 21140 */
1938 sc->lmc_rxring[i].status = 0x80000000;
1940 /* used to be PKT_BUF_SZ now uses skb since we lose some to head room */
1941 sc->lmc_rxring[i].length = skb->end - skb->data;
1943 /* use to be tail which is dumb since you're thinking why write
1944 * to the end of the packj,et but since there's nothing there tail == data
1946 sc->lmc_rxring[i].buffer1 = virt_to_bus (skb->data);
1948 /* This is fair since the structure is static and we have the next address */
1949 sc->lmc_rxring[i].buffer2 = virt_to_bus (&sc->lmc_rxring[i + 1]);
1956 sc->lmc_rxring[i - 1].length |= 0x02000000; /* Set end of buffers flag */
1957 sc->lmc_rxring[i - 1].buffer2 = virt_to_bus (&sc->lmc_rxring[0]); /* Point back to the start */
1958 LMC_CSR_WRITE (sc, csr_rxlist, virt_to_bus (sc->lmc_rxring)); /* write base address */
1961 /* Initialize the transmit rings and buffers */
1962 for (i = 0; i < LMC_TXDESCS; i++)
1964 if (sc->lmc_txq[i] != NULL){ /* have buffer */
1965 dev_kfree_skb(sc->lmc_txq[i]); /* free it */
1966 sc->stats.tx_dropped++; /* We just dropped a packet */
1968 sc->lmc_txq[i] = NULL;
1969 sc->lmc_txring[i].status = 0x00000000;
1970 sc->lmc_txring[i].buffer2 = virt_to_bus (&sc->lmc_txring[i + 1]);
1972 sc->lmc_txring[i - 1].buffer2 = virt_to_bus (&sc->lmc_txring[0]);
1973 LMC_CSR_WRITE (sc, csr_txlist, virt_to_bus (sc->lmc_txring));
1975 lmc_trace(sc->lmc_device, "lmc_softreset out");
1978 static int lmc_set_config(struct net_device *dev, struct ifmap *map) /*fold00*/
1980 lmc_trace(dev, "lmc_set_config in");
1981 lmc_trace(dev, "lmc_set_config out");
1985 void lmc_gpio_mkinput(lmc_softc_t * const sc, u_int32_t bits) /*fold00*/
1987 lmc_trace(sc->lmc_device, "lmc_gpio_mkinput in");
1988 sc->lmc_gpio_io &= ~bits;
1989 LMC_CSR_WRITE(sc, csr_gp, TULIP_GP_PINSET | (sc->lmc_gpio_io));
1990 lmc_trace(sc->lmc_device, "lmc_gpio_mkinput out");
1993 void lmc_gpio_mkoutput(lmc_softc_t * const sc, u_int32_t bits) /*fold00*/
1995 lmc_trace(sc->lmc_device, "lmc_gpio_mkoutput in");
1996 sc->lmc_gpio_io |= bits;
1997 LMC_CSR_WRITE(sc, csr_gp, TULIP_GP_PINSET | (sc->lmc_gpio_io));
1998 lmc_trace(sc->lmc_device, "lmc_gpio_mkoutput out");
2001 void lmc_led_on(lmc_softc_t * const sc, u_int32_t led) /*fold00*/
2003 lmc_trace(sc->lmc_device, "lmc_led_on in");
2004 if((~sc->lmc_miireg16) & led){ /* Already on! */
2005 lmc_trace(sc->lmc_device, "lmc_led_on aon out");
2009 sc->lmc_miireg16 &= ~led;
2010 lmc_mii_writereg(sc, 0, 16, sc->lmc_miireg16);
2011 lmc_trace(sc->lmc_device, "lmc_led_on out");
2014 void lmc_led_off(lmc_softc_t * const sc, u_int32_t led) /*fold00*/
2016 lmc_trace(sc->lmc_device, "lmc_led_off in");
2017 if(sc->lmc_miireg16 & led){ /* Already set don't do anything */
2018 lmc_trace(sc->lmc_device, "lmc_led_off aoff out");
2022 sc->lmc_miireg16 |= led;
2023 lmc_mii_writereg(sc, 0, 16, sc->lmc_miireg16);
2024 lmc_trace(sc->lmc_device, "lmc_led_off out");
2027 static void lmc_reset(lmc_softc_t * const sc) /*fold00*/
2029 lmc_trace(sc->lmc_device, "lmc_reset in");
2030 sc->lmc_miireg16 |= LMC_MII16_FIFO_RESET;
2031 lmc_mii_writereg(sc, 0, 16, sc->lmc_miireg16);
2033 sc->lmc_miireg16 &= ~LMC_MII16_FIFO_RESET;
2034 lmc_mii_writereg(sc, 0, 16, sc->lmc_miireg16);
2037 * make some of the GPIO pins be outputs
2039 lmc_gpio_mkoutput(sc, LMC_GEP_RESET);
2042 * RESET low to force state reset. This also forces
2043 * the transmitter clock to be internal, but we expect to reset
2044 * that later anyway.
2046 sc->lmc_gpio &= ~(LMC_GEP_RESET);
2047 LMC_CSR_WRITE(sc, csr_gp, sc->lmc_gpio);
2050 * hold for more than 10 microseconds
2055 * stop driving Xilinx-related signals
2057 lmc_gpio_mkinput(sc, LMC_GEP_RESET);
2060 * Call media specific init routine
2062 sc->lmc_media->init(sc);
2064 sc->stats.resetCount++;
2065 lmc_trace(sc->lmc_device, "lmc_reset out");
2068 static void lmc_dec_reset(lmc_softc_t * const sc) /*fold00*/
2071 lmc_trace(sc->lmc_device, "lmc_dec_reset in");
2074 * disable all interrupts
2076 sc->lmc_intrmask = 0;
2077 LMC_CSR_WRITE(sc, csr_intr, sc->lmc_intrmask);
2080 * Reset the chip with a software reset command.
2081 * Wait 10 microseconds (actually 50 PCI cycles but at
2082 * 33MHz that comes to two microseconds but wait a
2083 * bit longer anyways)
2085 LMC_CSR_WRITE(sc, csr_busmode, TULIP_BUSMODE_SWRESET);
2088 sc->lmc_busmode = LMC_CSR_READ(sc, csr_busmode);
2089 sc->lmc_busmode = 0x00100000;
2090 sc->lmc_busmode &= ~TULIP_BUSMODE_SWRESET;
2091 LMC_CSR_WRITE(sc, csr_busmode, sc->lmc_busmode);
2093 sc->lmc_cmdmode = LMC_CSR_READ(sc, csr_command);
2097 * no ethernet address in frames we write
2098 * disable padding (txdesc, padding disable)
2099 * ignore runt frames (rdes0 bit 15)
2100 * no receiver watchdog or transmitter jabber timer
2101 * (csr15 bit 0,14 == 1)
2102 * if using 16-bit CRC, turn off CRC (trans desc, crc disable)
2105 sc->lmc_cmdmode |= ( TULIP_CMD_PROMISCUOUS
2106 | TULIP_CMD_FULLDUPLEX
2107 | TULIP_CMD_PASSBADPKT
2108 | TULIP_CMD_NOHEARTBEAT
2109 | TULIP_CMD_PORTSELECT
2110 | TULIP_CMD_RECEIVEALL
2111 | TULIP_CMD_MUSTBEONE
2113 sc->lmc_cmdmode &= ~( TULIP_CMD_OPERMODE
2114 | TULIP_CMD_THRESHOLDCTL
2115 | TULIP_CMD_STOREFWD
2116 | TULIP_CMD_TXTHRSHLDCTL
2119 LMC_CSR_WRITE(sc, csr_command, sc->lmc_cmdmode);
2122 * disable receiver watchdog and transmit jabber
2124 val = LMC_CSR_READ(sc, csr_sia_general);
2125 val |= (TULIP_WATCHDOG_TXDISABLE | TULIP_WATCHDOG_RXDISABLE);
2126 LMC_CSR_WRITE(sc, csr_sia_general, val);
2128 lmc_trace(sc->lmc_device, "lmc_dec_reset out");
2131 static void lmc_initcsrs(lmc_softc_t * const sc, lmc_csrptr_t csr_base, /*fold00*/
2134 lmc_trace(sc->lmc_device, "lmc_initcsrs in");
2135 sc->lmc_csrs.csr_busmode = csr_base + 0 * csr_size;
2136 sc->lmc_csrs.csr_txpoll = csr_base + 1 * csr_size;
2137 sc->lmc_csrs.csr_rxpoll = csr_base + 2 * csr_size;
2138 sc->lmc_csrs.csr_rxlist = csr_base + 3 * csr_size;
2139 sc->lmc_csrs.csr_txlist = csr_base + 4 * csr_size;
2140 sc->lmc_csrs.csr_status = csr_base + 5 * csr_size;
2141 sc->lmc_csrs.csr_command = csr_base + 6 * csr_size;
2142 sc->lmc_csrs.csr_intr = csr_base + 7 * csr_size;
2143 sc->lmc_csrs.csr_missed_frames = csr_base + 8 * csr_size;
2144 sc->lmc_csrs.csr_9 = csr_base + 9 * csr_size;
2145 sc->lmc_csrs.csr_10 = csr_base + 10 * csr_size;
2146 sc->lmc_csrs.csr_11 = csr_base + 11 * csr_size;
2147 sc->lmc_csrs.csr_12 = csr_base + 12 * csr_size;
2148 sc->lmc_csrs.csr_13 = csr_base + 13 * csr_size;
2149 sc->lmc_csrs.csr_14 = csr_base + 14 * csr_size;
2150 sc->lmc_csrs.csr_15 = csr_base + 15 * csr_size;
2151 lmc_trace(sc->lmc_device, "lmc_initcsrs out");
2154 static void lmc_driver_timeout(struct net_device *dev) { /*fold00*/
2157 unsigned long flags;
2159 lmc_trace(dev, "lmc_driver_timeout in");
2163 spin_lock_irqsave(&sc->lmc_lock, flags);
2165 printk("%s: Xmitter busy|\n", dev->name);
2167 sc->stats.tx_tbusy_calls++ ;
2168 if (jiffies - dev->trans_start < TX_TIMEOUT) {
2173 * Chip seems to have locked up
2175 * This whips out all our decriptor
2176 * table and starts from scartch
2179 LMC_EVENT_LOG(LMC_EVENT_XMTPRCTMO,
2180 LMC_CSR_READ (sc, csr_status),
2181 sc->stats.tx_ProcTimeout);
2183 lmc_running_reset (dev);
2185 LMC_EVENT_LOG(LMC_EVENT_RESET1, LMC_CSR_READ (sc, csr_status), 0);
2186 LMC_EVENT_LOG(LMC_EVENT_RESET2,
2187 lmc_mii_readreg (sc, 0, 16),
2188 lmc_mii_readreg (sc, 0, 17));
2190 /* restart the tx processes */
2191 csr6 = LMC_CSR_READ (sc, csr_command);
2192 LMC_CSR_WRITE (sc, csr_command, csr6 | 0x0002);
2193 LMC_CSR_WRITE (sc, csr_command, csr6 | 0x2002);
2195 /* immediate transmit */
2196 LMC_CSR_WRITE (sc, csr_txpoll, 0);
2198 sc->stats.tx_errors++;
2199 sc->stats.tx_ProcTimeout++; /* -baz */
2201 dev->trans_start = jiffies;
2205 spin_unlock_irqrestore(&sc->lmc_lock, flags);
2207 lmc_trace(dev, "lmc_driver_timout out");