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>
59 #include <linux/bitops.h>
61 #include <net/syncppp.h>
63 #include <asm/processor.h> /* Processor type for cache alignment. */
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);
104 static void lmc_initcsrs(lmc_softc_t * const sc, lmc_csrptr_t csr_base, size_t csr_size);
105 static void lmc_softreset(lmc_softc_t * const);
106 static void lmc_running_reset(struct net_device *dev);
107 static int lmc_ifdown(struct net_device * const);
108 static void lmc_watchdog(unsigned long data);
109 static void lmc_reset(lmc_softc_t * const sc);
110 static void lmc_dec_reset(lmc_softc_t * const sc);
111 static void lmc_driver_timeout(struct net_device *dev);
114 * linux reserves 16 device specific IOCTLs. We call them
115 * LMCIOC* to control various bits of our world.
117 int lmc_ioctl (struct net_device *dev, struct ifreq *ifr, int cmd) /*fold00*/
131 lmc_trace(dev, "lmc_ioctl in");
134 * Most functions mess with the structure
135 * Disable interrupts while we do the polling
137 spin_lock_irqsave(&sc->lmc_lock, flags);
141 * Return current driver state. Since we keep this up
142 * To date internally, just copy this out to the user.
144 case LMCIOCGINFO: /*fold01*/
145 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))) {
168 sc->lmc_media->set_status (sc, &ctl);
170 if(ctl.crc_length != sc->ictl.crc_length) {
171 sc->lmc_media->set_crc_length(sc, ctl.crc_length);
172 if (sc->ictl.crc_length == LMC_CTL_CRC_LENGTH_16)
173 sc->TxDescriptControlInit |= LMC_TDES_ADD_CRC_DISABLE;
175 sc->TxDescriptControlInit &= ~LMC_TDES_ADD_CRC_DISABLE;
178 if (ctl.keepalive_onoff == LMC_CTL_OFF)
179 sp->pp_flags &= ~PP_KEEPALIVE; /* Turn off */
181 sp->pp_flags |= PP_KEEPALIVE; /* Turn on */
186 case LMCIOCIFTYPE: /*fold01*/
188 u_int16_t old_type = sc->if_type;
191 if (!capable(CAP_NET_ADMIN)) {
196 if (copy_from_user(&new_type, ifr->ifr_data, sizeof(u_int16_t))) {
202 if (new_type == old_type)
205 break; /* no change */
209 lmc_proto_detach(sc);
211 sc->if_type = new_type;
212 // lmc_proto_init(sc);
213 lmc_proto_attach(sc);
220 case LMCIOCGETXINFO: /*fold01*/
221 sc->lmc_xinfo.Magic0 = 0xBEEFCAFE;
223 sc->lmc_xinfo.PciCardType = sc->lmc_cardtype;
224 sc->lmc_xinfo.PciSlotNumber = 0;
225 sc->lmc_xinfo.DriverMajorVersion = DRIVER_MAJOR_VERSION;
226 sc->lmc_xinfo.DriverMinorVersion = DRIVER_MINOR_VERSION;
227 sc->lmc_xinfo.DriverSubVersion = DRIVER_SUB_VERSION;
228 sc->lmc_xinfo.XilinxRevisionNumber =
229 lmc_mii_readreg (sc, 0, 3) & 0xf;
230 sc->lmc_xinfo.MaxFrameSize = LMC_PKT_BUF_SZ;
231 sc->lmc_xinfo.link_status = sc->lmc_media->get_link_status (sc);
232 sc->lmc_xinfo.mii_reg16 = lmc_mii_readreg (sc, 0, 16);
234 sc->lmc_xinfo.Magic1 = 0xDEADBEEF;
236 if (copy_to_user(ifr->ifr_data, &sc->lmc_xinfo,
237 sizeof(struct lmc_xinfo)))
244 case LMCIOCGETLMCSTATS: /*fold01*/
245 if (sc->lmc_cardtype == LMC_CARDTYPE_T1){
246 lmc_mii_writereg (sc, 0, 17, T1FRAMER_FERR_LSB);
247 sc->stats.framingBitErrorCount +=
248 lmc_mii_readreg (sc, 0, 18) & 0xff;
249 lmc_mii_writereg (sc, 0, 17, T1FRAMER_FERR_MSB);
250 sc->stats.framingBitErrorCount +=
251 (lmc_mii_readreg (sc, 0, 18) & 0xff) << 8;
252 lmc_mii_writereg (sc, 0, 17, T1FRAMER_LCV_LSB);
253 sc->stats.lineCodeViolationCount +=
254 lmc_mii_readreg (sc, 0, 18) & 0xff;
255 lmc_mii_writereg (sc, 0, 17, T1FRAMER_LCV_MSB);
256 sc->stats.lineCodeViolationCount +=
257 (lmc_mii_readreg (sc, 0, 18) & 0xff) << 8;
258 lmc_mii_writereg (sc, 0, 17, T1FRAMER_AERR);
259 regVal = lmc_mii_readreg (sc, 0, 18) & 0xff;
261 sc->stats.lossOfFrameCount +=
262 (regVal & T1FRAMER_LOF_MASK) >> 4;
263 sc->stats.changeOfFrameAlignmentCount +=
264 (regVal & T1FRAMER_COFA_MASK) >> 2;
265 sc->stats.severelyErroredFrameCount +=
266 regVal & T1FRAMER_SEF_MASK;
269 if (copy_to_user(ifr->ifr_data, &sc->stats,
270 sizeof (struct lmc_statistics)))
276 case LMCIOCCLEARLMCSTATS: /*fold01*/
277 if (!capable(CAP_NET_ADMIN)){
282 memset (&sc->stats, 0, sizeof (struct lmc_statistics));
283 sc->stats.check = STATCHECK;
284 sc->stats.version_size = (DRIVER_VERSION << 16) +
285 sizeof (struct lmc_statistics);
286 sc->stats.lmc_cardtype = sc->lmc_cardtype;
290 case LMCIOCSETCIRCUIT: /*fold01*/
291 if (!capable(CAP_NET_ADMIN)){
296 if(dev->flags & IFF_UP){
301 if (copy_from_user(&ctl, ifr->ifr_data, sizeof(lmc_ctl_t))) {
305 sc->lmc_media->set_circuit_type(sc, ctl.circuit_type);
306 sc->ictl.circuit_type = ctl.circuit_type;
311 case LMCIOCRESET: /*fold01*/
312 if (!capable(CAP_NET_ADMIN)){
317 /* Reset driver and bring back to current state */
318 printk (" REG16 before reset +%04x\n", lmc_mii_readreg (sc, 0, 16));
319 lmc_running_reset (dev);
320 printk (" REG16 after reset +%04x\n", lmc_mii_readreg (sc, 0, 16));
322 LMC_EVENT_LOG(LMC_EVENT_FORCEDRESET, LMC_CSR_READ (sc, csr_status), lmc_mii_readreg (sc, 0, 16));
328 case LMCIOCDUMPEVENTLOG:
329 if (copy_to_user(ifr->ifr_data, &lmcEventLogIndex, sizeof(u32))) {
333 if (copy_to_user(ifr->ifr_data + sizeof (u32), lmcEventLogBuf, sizeof (lmcEventLogBuf)))
339 #endif /* end ifdef _DBG_EVENTLOG */
340 case LMCIOCT1CONTROL: /*fold01*/
341 if (sc->lmc_cardtype != LMC_CARDTYPE_T1){
346 case LMCIOCXILINX: /*fold01*/
348 struct lmc_xilinx_control xc; /*fold02*/
350 if (!capable(CAP_NET_ADMIN)){
356 * Stop the xwitter whlie we restart the hardware
358 netif_stop_queue(dev);
360 if (copy_from_user(&xc, ifr->ifr_data, sizeof(struct lmc_xilinx_control))) {
365 case lmc_xilinx_reset: /*fold02*/
368 mii = lmc_mii_readreg (sc, 0, 16);
371 * Make all of them 0 and make input
373 lmc_gpio_mkinput(sc, 0xff);
376 * make the reset output
378 lmc_gpio_mkoutput(sc, LMC_GEP_RESET);
381 * RESET low to force configuration. This also forces
382 * the transmitter clock to be internal, but we expect to reset
386 sc->lmc_gpio &= ~LMC_GEP_RESET;
387 LMC_CSR_WRITE(sc, csr_gp, sc->lmc_gpio);
391 * hold for more than 10 microseconds
395 sc->lmc_gpio |= LMC_GEP_RESET;
396 LMC_CSR_WRITE(sc, csr_gp, sc->lmc_gpio);
400 * stop driving Xilinx-related signals
402 lmc_gpio_mkinput(sc, 0xff);
404 /* Reset the frammer hardware */
405 sc->lmc_media->set_link_status (sc, 1);
406 sc->lmc_media->set_status (sc, NULL);
407 // lmc_softreset(sc);
411 for(i = 0; i < 5; i++){
412 lmc_led_on(sc, LMC_DS3_LED0);
414 lmc_led_off(sc, LMC_DS3_LED0);
415 lmc_led_on(sc, LMC_DS3_LED1);
417 lmc_led_off(sc, LMC_DS3_LED1);
418 lmc_led_on(sc, LMC_DS3_LED3);
420 lmc_led_off(sc, LMC_DS3_LED3);
421 lmc_led_on(sc, LMC_DS3_LED2);
423 lmc_led_off(sc, LMC_DS3_LED2);
434 case lmc_xilinx_load_prom: /*fold02*/
437 int timeout = 500000;
438 mii = lmc_mii_readreg (sc, 0, 16);
441 * Make all of them 0 and make input
443 lmc_gpio_mkinput(sc, 0xff);
446 * make the reset output
448 lmc_gpio_mkoutput(sc, LMC_GEP_DP | LMC_GEP_RESET);
451 * RESET low to force configuration. This also forces
452 * the transmitter clock to be internal, but we expect to reset
456 sc->lmc_gpio &= ~(LMC_GEP_RESET | LMC_GEP_DP);
457 LMC_CSR_WRITE(sc, csr_gp, sc->lmc_gpio);
461 * hold for more than 10 microseconds
465 sc->lmc_gpio |= LMC_GEP_DP | LMC_GEP_RESET;
466 LMC_CSR_WRITE(sc, csr_gp, sc->lmc_gpio);
469 * busy wait for the chip to reset
471 while( (LMC_CSR_READ(sc, csr_gp) & LMC_GEP_INIT) == 0 &&
477 * stop driving Xilinx-related signals
479 lmc_gpio_mkinput(sc, 0xff);
488 case lmc_xilinx_load: /*fold02*/
492 int timeout = 500000;
499 data = kmalloc(xc.len, GFP_KERNEL);
501 printk(KERN_WARNING "%s: Failed to allocate memory for copy\n", dev->name);
506 if(copy_from_user(data, xc.data, xc.len))
513 printk("%s: Starting load of data Len: %d at 0x%p == 0x%p\n", dev->name, xc.len, xc.data, data);
515 lmc_gpio_mkinput(sc, 0xff);
518 * Clear the Xilinx and start prgramming from the DEC
529 sc->lmc_gpio &= ~LMC_GEP_DP;
530 sc->lmc_gpio &= ~LMC_GEP_RESET;
531 sc->lmc_gpio |= LMC_GEP_MODE;
532 LMC_CSR_WRITE(sc, csr_gp, sc->lmc_gpio);
534 lmc_gpio_mkoutput(sc, LMC_GEP_MODE | LMC_GEP_DP | LMC_GEP_RESET);
537 * Wait at least 10 us 20 to be safe
542 * Clear reset and activate programming lines
549 lmc_gpio_mkinput(sc, LMC_GEP_DP | LMC_GEP_RESET);
552 * Set LOAD, DATA, Clock to 1
555 sc->lmc_gpio |= LMC_GEP_MODE;
556 sc->lmc_gpio |= LMC_GEP_DATA;
557 sc->lmc_gpio |= LMC_GEP_CLK;
558 LMC_CSR_WRITE(sc, csr_gp, sc->lmc_gpio);
560 lmc_gpio_mkoutput(sc, LMC_GEP_DATA | LMC_GEP_CLK | LMC_GEP_MODE );
563 * busy wait for the chip to reset
565 while( (LMC_CSR_READ(sc, csr_gp) & LMC_GEP_INIT) == 0 &&
569 printk(KERN_DEBUG "%s: Waited %d for the Xilinx to clear it's memory\n", dev->name, 500000-timeout);
571 for(pos = 0; pos < xc.len; pos++){
574 sc->lmc_gpio &= ~LMC_GEP_DATA; /* Data is 0 */
577 sc->lmc_gpio |= LMC_GEP_DATA; /* Data is 1 */
580 printk(KERN_WARNING "%s Bad data in xilinx programming data at %d, got %d wanted 0 or 1\n", dev->name, pos, data[pos]);
581 sc->lmc_gpio |= LMC_GEP_DATA; /* Assume it's 1 */
583 sc->lmc_gpio &= ~LMC_GEP_CLK; /* Clock to zero */
584 sc->lmc_gpio |= LMC_GEP_MODE;
585 LMC_CSR_WRITE(sc, csr_gp, sc->lmc_gpio);
588 sc->lmc_gpio |= LMC_GEP_CLK; /* Put the clack back to one */
589 sc->lmc_gpio |= LMC_GEP_MODE;
590 LMC_CSR_WRITE(sc, csr_gp, sc->lmc_gpio);
593 if((LMC_CSR_READ(sc, csr_gp) & LMC_GEP_INIT) == 0){
594 printk(KERN_WARNING "%s: Reprogramming FAILED. Needs to be reprogrammed. (corrupted data)\n", dev->name);
596 else if((LMC_CSR_READ(sc, csr_gp) & LMC_GEP_DP) == 0){
597 printk(KERN_WARNING "%s: Reprogramming FAILED. Needs to be reprogrammed. (done)\n", dev->name);
600 printk(KERN_DEBUG "%s: Done reprogramming Xilinx, %d bits, good luck!\n", dev->name, pos);
603 lmc_gpio_mkinput(sc, 0xff);
605 sc->lmc_miireg16 |= LMC_MII16_FIFO_RESET;
606 lmc_mii_writereg(sc, 0, 16, sc->lmc_miireg16);
608 sc->lmc_miireg16 &= ~LMC_MII16_FIFO_RESET;
609 lmc_mii_writereg(sc, 0, 16, sc->lmc_miireg16);
622 netif_wake_queue(dev);
628 /* If we don't know what to do, give the protocol a shot. */
629 ret = lmc_proto_ioctl (sc, ifr, cmd);
633 spin_unlock_irqrestore(&sc->lmc_lock, flags); /*fold01*/
635 lmc_trace(dev, "lmc_ioctl out");
641 /* the watchdog process that cruises around */
642 static void lmc_watchdog (unsigned long data) /*fold00*/
644 struct net_device *dev = (struct net_device *) data;
652 lmc_trace(dev, "lmc_watchdog in");
654 spin_lock_irqsave(&sc->lmc_lock, flags);
656 if(sc->check != 0xBEAFCAFE){
657 printk("LMC: Corrupt net_device struct, breaking out\n");
658 spin_unlock_irqrestore(&sc->lmc_lock, flags);
663 /* Make sure the tx jabber and rx watchdog are off,
664 * and the transmit and receive processes are running.
667 LMC_CSR_WRITE (sc, csr_15, 0x00000011);
668 sc->lmc_cmdmode |= TULIP_CMD_TXRUN | TULIP_CMD_RXRUN;
669 LMC_CSR_WRITE (sc, csr_command, sc->lmc_cmdmode);
674 LMC_EVENT_LOG(LMC_EVENT_WATCHDOG, LMC_CSR_READ (sc, csr_status), lmc_mii_readreg (sc, 0, 16));
676 /* --- begin time out check -----------------------------------
677 * check for a transmit interrupt timeout
678 * Has the packet xmt vs xmt serviced threshold been exceeded */
679 if (sc->lmc_taint_tx == sc->lastlmc_taint_tx &&
680 sc->stats.tx_packets > sc->lasttx_packets &&
681 sc->tx_TimeoutInd == 0)
684 /* wait for the watchdog to come around again */
685 sc->tx_TimeoutInd = 1;
687 else if (sc->lmc_taint_tx == sc->lastlmc_taint_tx &&
688 sc->stats.tx_packets > sc->lasttx_packets &&
692 LMC_EVENT_LOG(LMC_EVENT_XMTINTTMO, LMC_CSR_READ (sc, csr_status), 0);
694 sc->tx_TimeoutDisplay = 1;
695 sc->stats.tx_TimeoutCnt++;
697 /* DEC chip is stuck, hit it with a RESET!!!! */
698 lmc_running_reset (dev);
701 /* look at receive & transmit process state to make sure they are running */
702 LMC_EVENT_LOG(LMC_EVENT_RESET1, LMC_CSR_READ (sc, csr_status), 0);
704 /* look at: DSR - 02 for Reg 16
710 LMC_EVENT_LOG(LMC_EVENT_RESET2, lmc_mii_readreg (sc, 0, 16), lmc_mii_readreg (sc, 0, 17));
712 /* reset the transmit timeout detection flag */
713 sc->tx_TimeoutInd = 0;
714 sc->lastlmc_taint_tx = sc->lmc_taint_tx;
715 sc->lasttx_packets = sc->stats.tx_packets;
719 sc->tx_TimeoutInd = 0;
720 sc->lastlmc_taint_tx = sc->lmc_taint_tx;
721 sc->lasttx_packets = sc->stats.tx_packets;
724 /* --- end time out check ----------------------------------- */
727 link_status = sc->lmc_media->get_link_status (sc);
730 * hardware level link lost, but the interface is marked as up.
733 if ((link_status == 0) && (sc->last_link_status != 0)) {
734 printk(KERN_WARNING "%s: hardware/physical link down\n", dev->name);
735 sc->last_link_status = 0;
736 /* lmc_reset (sc); Why reset??? The link can go down ok */
738 /* Inform the world that link has been lost */
739 netif_carrier_off(dev);
743 * hardware link is up, but the interface is marked as down.
744 * Bring it back up again.
746 if (link_status != 0 && sc->last_link_status == 0) {
747 printk(KERN_WARNING "%s: hardware/physical link up\n", dev->name);
748 sc->last_link_status = 1;
749 /* lmc_reset (sc); Again why reset??? */
751 /* Inform the world that link protocol is back up. */
752 netif_carrier_on(dev);
754 /* Now we have to tell the syncppp that we had an outage
755 * and that it should deal. Calling sppp_reopen here
756 * should do the trick, but we may have to call sppp_close
757 * when the link goes down, and call sppp_open here.
758 * Subject to more testing.
762 lmc_proto_reopen(sc);
766 /* Call media specific watchdog functions */
767 sc->lmc_media->watchdog(sc);
770 * Poke the transmitter to make sure it
771 * never stops, even if we run out of mem
773 LMC_CSR_WRITE(sc, csr_rxpoll, 0);
776 * Check for code that failed
777 * and try and fix it as appropriate
779 if(sc->failed_ring == 1){
781 * Failed to setup the recv/xmit rin
787 if(sc->failed_recv_alloc == 1){
789 * We failed to alloc mem in the
790 * interrupt handler, go through the rings
793 sc->failed_recv_alloc = 0;
799 * remember the timer value
803 ticks = LMC_CSR_READ (sc, csr_gp_timer);
804 LMC_CSR_WRITE (sc, csr_gp_timer, 0xffffffffUL);
805 sc->ictl.ticks = 0x0000ffff - (ticks & 0x0000ffff);
808 * restart this timer.
810 sc->timer.expires = jiffies + (HZ);
811 add_timer (&sc->timer);
813 spin_unlock_irqrestore(&sc->lmc_lock, flags);
815 lmc_trace(dev, "lmc_watchdog out");
819 static void lmc_setup(struct net_device * const dev) /*fold00*/
821 lmc_trace(dev, "lmc_setup in");
823 dev->type = ARPHRD_HDLC;
824 dev->hard_start_xmit = lmc_start_xmit;
825 dev->open = lmc_open;
826 dev->stop = lmc_close;
827 dev->get_stats = lmc_get_stats;
828 dev->do_ioctl = lmc_ioctl;
829 dev->tx_timeout = lmc_driver_timeout;
830 dev->watchdog_timeo = (HZ); /* 1 second */
832 lmc_trace(dev, "lmc_setup out");
836 static int __devinit lmc_init_one(struct pci_dev *pdev,
837 const struct pci_device_id *ent)
839 struct net_device *dev;
842 u_int16_t AdapModelNum;
844 static int cards_found;
846 /* We name by type not by vendor */
847 static const char lmcname[] = "hdlc%d";
850 * GCOM uses LMC vendor name so that clients can know which card
853 static const char lmcname[] = "lmc%d";
858 * Allocate our own device structure
860 dev = alloc_netdev(sizeof(lmc_softc_t), lmcname, lmc_setup);
862 printk (KERN_ERR "lmc:alloc_netdev for device failed\n");
866 lmc_trace(dev, "lmc_init_one in");
868 err = pci_enable_device(pdev);
870 printk(KERN_ERR "lmc: pci enable failed:%d\n", err);
874 if (pci_request_regions(pdev, "lmc")) {
875 printk(KERN_ERR "lmc: pci_request_region failed\n");
880 pci_set_drvdata(pdev, dev);
882 if(lmc_first_load == 0){
883 printk(KERN_INFO "Lan Media Corporation WAN Driver Version %d.%d.%d\n",
884 DRIVER_MAJOR_VERSION, DRIVER_MINOR_VERSION,DRIVER_SUB_VERSION);
889 sc->lmc_device = dev;
890 sc->name = dev->name;
892 /* Initialize the sppp layer */
893 /* An ioctl can cause a subsequent detach for raw frame interface */
895 sc->if_type = LMC_PPP;
896 sc->check = 0xBEAFCAFE;
897 dev->base_addr = pci_resource_start(pdev, 0);
898 dev->irq = pdev->irq;
900 SET_NETDEV_DEV(dev, &pdev->dev);
903 * This will get the protocol layer ready and do any 1 time init's
904 * Must have a valid sc and dev structure
908 lmc_proto_attach(sc);
911 * Why were we changing this???
912 dev->tx_queue_len = 100;
915 /* Init the spin lock so can call it latter */
917 spin_lock_init(&sc->lmc_lock);
918 pci_set_master(pdev);
920 printk ("%s: detected at %lx, irq %d\n", dev->name,
921 dev->base_addr, dev->irq);
923 if (register_netdev (dev) != 0) {
924 printk (KERN_ERR "%s: register_netdev failed.\n", dev->name);
928 sc->lmc_cardtype = LMC_CARDTYPE_UNKNOWN;
929 sc->lmc_timing = LMC_CTL_CLOCK_SOURCE_EXT;
933 * Check either the subvendor or the subdevice, some systems reverse
934 * the setting in the bois, seems to be version and arch dependent?
935 * Fix the error, exchange the two values
937 if ((subdevice = pdev->subsystem_device) == PCI_VENDOR_ID_LMC)
938 subdevice = pdev->subsystem_vendor;
941 case PCI_DEVICE_ID_LMC_HSSI:
942 printk ("%s: LMC HSSI\n", dev->name);
943 sc->lmc_cardtype = LMC_CARDTYPE_HSSI;
944 sc->lmc_media = &lmc_hssi_media;
946 case PCI_DEVICE_ID_LMC_DS3:
947 printk ("%s: LMC DS3\n", dev->name);
948 sc->lmc_cardtype = LMC_CARDTYPE_DS3;
949 sc->lmc_media = &lmc_ds3_media;
951 case PCI_DEVICE_ID_LMC_SSI:
952 printk ("%s: LMC SSI\n", dev->name);
953 sc->lmc_cardtype = LMC_CARDTYPE_SSI;
954 sc->lmc_media = &lmc_ssi_media;
956 case PCI_DEVICE_ID_LMC_T1:
957 printk ("%s: LMC T1\n", dev->name);
958 sc->lmc_cardtype = LMC_CARDTYPE_T1;
959 sc->lmc_media = &lmc_t1_media;
962 printk (KERN_WARNING "%s: LMC UNKOWN CARD!\n", dev->name);
966 lmc_initcsrs (sc, dev->base_addr, 8);
968 lmc_gpio_mkinput (sc, 0xff);
969 sc->lmc_gpio = 0; /* drive no signals yet */
971 sc->lmc_media->defaults (sc);
973 sc->lmc_media->set_link_status (sc, LMC_LINK_UP);
975 /* verify that the PCI Sub System ID matches the Adapter Model number
976 * from the MII register
978 AdapModelNum = (lmc_mii_readreg (sc, 0, 3) & 0x3f0) >> 4;
980 if ((AdapModelNum == LMC_ADAP_T1
981 && subdevice == PCI_DEVICE_ID_LMC_T1) || /* detect LMC1200 */
982 (AdapModelNum == LMC_ADAP_SSI
983 && subdevice == PCI_DEVICE_ID_LMC_SSI) || /* detect LMC1000 */
984 (AdapModelNum == LMC_ADAP_DS3
985 && subdevice == PCI_DEVICE_ID_LMC_DS3) || /* detect LMC5245 */
986 (AdapModelNum == LMC_ADAP_HSSI
987 && subdevice == PCI_DEVICE_ID_LMC_HSSI))
988 { /* detect LMC5200 */
992 printk ("%s: Model number (%d) miscompare for PCI Subsystem ID = 0x%04x\n",
993 dev->name, AdapModelNum, subdevice);
999 LMC_CSR_WRITE (sc, csr_gp_timer, 0xFFFFFFFFUL);
1001 sc->board_idx = cards_found++;
1002 sc->stats.check = STATCHECK;
1003 sc->stats.version_size = (DRIVER_VERSION << 16) +
1004 sizeof (struct lmc_statistics);
1005 sc->stats.lmc_cardtype = sc->lmc_cardtype;
1008 sc->last_link_status = 0;
1010 lmc_trace(dev, "lmc_init_one out");
1014 lmc_proto_detach(sc);
1017 pci_release_regions(pdev);
1018 pci_set_drvdata(pdev, NULL);
1027 * Called from pci when removing module.
1029 static void __devexit lmc_remove_one (struct pci_dev *pdev)
1031 struct net_device *dev = pci_get_drvdata(pdev);
1034 lmc_softc_t *sc = dev->priv;
1036 printk("%s: removing...\n", dev->name);
1037 lmc_proto_detach(sc);
1038 unregister_netdev(dev);
1040 pci_release_regions(pdev);
1041 pci_disable_device(pdev);
1042 pci_set_drvdata(pdev, NULL);
1046 /* After this is called, packets can be sent.
1047 * Does not initialize the addresses
1049 static int lmc_open (struct net_device *dev) /*fold00*/
1051 lmc_softc_t *sc = dev->priv;
1053 lmc_trace(dev, "lmc_open in");
1055 lmc_led_on(sc, LMC_DS3_LED0);
1060 LMC_EVENT_LOG(LMC_EVENT_RESET1, LMC_CSR_READ (sc, csr_status), 0);
1061 LMC_EVENT_LOG(LMC_EVENT_RESET2,
1062 lmc_mii_readreg (sc, 0, 16),
1063 lmc_mii_readreg (sc, 0, 17));
1067 lmc_trace(dev, "lmc_open lmc_ok out");
1073 /* Since we have to use PCI bus, this should work on x86,alpha,ppc */
1074 if (request_irq (dev->irq, &lmc_interrupt, IRQF_SHARED, dev->name, dev)){
1075 printk(KERN_WARNING "%s: could not get irq: %d\n", dev->name, dev->irq);
1076 lmc_trace(dev, "lmc_open irq failed out");
1081 /* Assert Terminal Active */
1082 sc->lmc_miireg16 |= LMC_MII16_LED_ALL;
1083 sc->lmc_media->set_link_status (sc, LMC_LINK_UP);
1086 * reset to last state.
1088 sc->lmc_media->set_status (sc, NULL);
1090 /* setup default bits to be used in tulip_desc_t transmit descriptor
1092 sc->TxDescriptControlInit = (
1093 LMC_TDES_INTERRUPT_ON_COMPLETION
1094 | LMC_TDES_FIRST_SEGMENT
1095 | LMC_TDES_LAST_SEGMENT
1096 | LMC_TDES_SECOND_ADDR_CHAINED
1097 | LMC_TDES_DISABLE_PADDING
1100 if (sc->ictl.crc_length == LMC_CTL_CRC_LENGTH_16) {
1101 /* disable 32 bit CRC generated by ASIC */
1102 sc->TxDescriptControlInit |= LMC_TDES_ADD_CRC_DISABLE;
1104 sc->lmc_media->set_crc_length(sc, sc->ictl.crc_length);
1105 /* Acknoledge the Terminal Active and light LEDs */
1107 /* dev->flags |= IFF_UP; */
1111 dev->do_ioctl = lmc_ioctl;
1114 netif_start_queue(dev);
1116 sc->stats.tx_tbusy0++ ;
1119 * select what interrupts we want to get
1121 sc->lmc_intrmask = 0;
1122 /* Should be using the default interrupt mask defined in the .h file. */
1123 sc->lmc_intrmask |= (TULIP_STS_NORMALINTR
1126 | TULIP_STS_ABNRMLINTR
1127 | TULIP_STS_SYSERROR
1128 | TULIP_STS_TXSTOPPED
1129 | TULIP_STS_TXUNDERFLOW
1130 | TULIP_STS_RXSTOPPED
1133 LMC_CSR_WRITE (sc, csr_intr, sc->lmc_intrmask);
1135 sc->lmc_cmdmode |= TULIP_CMD_TXRUN;
1136 sc->lmc_cmdmode |= TULIP_CMD_RXRUN;
1137 LMC_CSR_WRITE (sc, csr_command, sc->lmc_cmdmode);
1139 sc->lmc_ok = 1; /* Run watchdog */
1142 * Set the if up now - pfb
1145 sc->last_link_status = 1;
1148 * Setup a timer for the watchdog on probe, and start it running.
1149 * Since lmc_ok == 0, it will be a NOP for now.
1151 init_timer (&sc->timer);
1152 sc->timer.expires = jiffies + HZ;
1153 sc->timer.data = (unsigned long) dev;
1154 sc->timer.function = &lmc_watchdog;
1155 add_timer (&sc->timer);
1157 lmc_trace(dev, "lmc_open out");
1162 /* Total reset to compensate for the AdTran DSU doing bad things
1166 static void lmc_running_reset (struct net_device *dev) /*fold00*/
1169 lmc_softc_t *sc = (lmc_softc_t *) dev->priv;
1171 lmc_trace(dev, "lmc_runnig_reset in");
1173 /* stop interrupts */
1174 /* Clear the interrupt mask */
1175 LMC_CSR_WRITE (sc, csr_intr, 0x00000000);
1180 /* sc->lmc_miireg16 |= LMC_MII16_LED_ALL; */
1181 sc->lmc_media->set_link_status (sc, 1);
1182 sc->lmc_media->set_status (sc, NULL);
1184 netif_wake_queue(dev);
1187 sc->stats.tx_tbusy0++ ;
1189 sc->lmc_intrmask = TULIP_DEFAULT_INTR_MASK;
1190 LMC_CSR_WRITE (sc, csr_intr, sc->lmc_intrmask);
1192 sc->lmc_cmdmode |= (TULIP_CMD_TXRUN | TULIP_CMD_RXRUN);
1193 LMC_CSR_WRITE (sc, csr_command, sc->lmc_cmdmode);
1195 lmc_trace(dev, "lmc_runnin_reset_out");
1199 /* This is what is called when you ifconfig down a device.
1200 * This disables the timer for the watchdog and keepalives,
1201 * and disables the irq for dev.
1203 static int lmc_close (struct net_device *dev) /*fold00*/
1205 /* not calling release_region() as we should */
1208 lmc_trace(dev, "lmc_close in");
1212 sc->lmc_media->set_link_status (sc, 0);
1213 del_timer (&sc->timer);
1214 lmc_proto_close(sc);
1217 lmc_trace(dev, "lmc_close out");
1222 /* Ends the transfer of packets */
1223 /* When the interface goes down, this is called */
1224 static int lmc_ifdown (struct net_device *dev) /*fold00*/
1226 lmc_softc_t *sc = dev->priv;
1230 lmc_trace(dev, "lmc_ifdown in");
1232 /* Don't let anything else go on right now */
1234 netif_stop_queue(dev);
1235 sc->stats.tx_tbusy1++ ;
1237 /* stop interrupts */
1238 /* Clear the interrupt mask */
1239 LMC_CSR_WRITE (sc, csr_intr, 0x00000000);
1241 /* Stop Tx and Rx on the chip */
1242 csr6 = LMC_CSR_READ (sc, csr_command);
1243 csr6 &= ~LMC_DEC_ST; /* Turn off the Transmission bit */
1244 csr6 &= ~LMC_DEC_SR; /* Turn off the Receive bit */
1245 LMC_CSR_WRITE (sc, csr_command, csr6);
1247 sc->stats.rx_missed_errors +=
1248 LMC_CSR_READ (sc, csr_missed_frames) & 0xffff;
1250 /* release the interrupt */
1251 if(sc->got_irq == 1){
1252 free_irq (dev->irq, dev);
1256 /* free skbuffs in the Rx queue */
1257 for (i = 0; i < LMC_RXDESCS; i++)
1259 struct sk_buff *skb = sc->lmc_rxq[i];
1260 sc->lmc_rxq[i] = NULL;
1261 sc->lmc_rxring[i].status = 0;
1262 sc->lmc_rxring[i].length = 0;
1263 sc->lmc_rxring[i].buffer1 = 0xDEADBEEF;
1266 sc->lmc_rxq[i] = NULL;
1269 for (i = 0; i < LMC_TXDESCS; i++)
1271 if (sc->lmc_txq[i] != NULL)
1272 dev_kfree_skb(sc->lmc_txq[i]);
1273 sc->lmc_txq[i] = NULL;
1276 lmc_led_off (sc, LMC_MII16_LED_ALL);
1278 netif_wake_queue(dev);
1279 sc->stats.tx_tbusy0++ ;
1281 lmc_trace(dev, "lmc_ifdown out");
1286 /* Interrupt handling routine. This will take an incoming packet, or clean
1287 * up after a trasmit.
1289 static irqreturn_t lmc_interrupt (int irq, void *dev_instance) /*fold00*/
1291 struct net_device *dev = (struct net_device *) dev_instance;
1298 int max_work = LMC_RXDESCS;
1301 lmc_trace(dev, "lmc_interrupt in");
1305 spin_lock(&sc->lmc_lock);
1308 * Read the csr to find what interrupts we have (if any)
1310 csr = LMC_CSR_READ (sc, csr_status);
1313 * Make sure this is our interrupt
1315 if ( ! (csr & sc->lmc_intrmask)) {
1316 goto lmc_int_fail_out;
1321 /* always go through this loop at least once */
1322 while (csr & sc->lmc_intrmask) {
1326 * Clear interrupt bits, we handle all case below
1328 LMC_CSR_WRITE (sc, csr_status, csr);
1332 * - Transmit process timed out CSR5<1>
1333 * - Transmit jabber timeout CSR5<3>
1334 * - Transmit underflow CSR5<5>
1335 * - Transmit Receiver buffer unavailable CSR5<7>
1336 * - Receive process stopped CSR5<8>
1337 * - Receive watchdog timeout CSR5<9>
1338 * - Early transmit interrupt CSR5<10>
1340 * Is this really right? Should we do a running reset for jabber?
1341 * (being a WAN card and all)
1343 if (csr & TULIP_STS_ABNRMLINTR){
1344 lmc_running_reset (dev);
1348 if (csr & TULIP_STS_RXINTR){
1349 lmc_trace(dev, "rx interrupt");
1353 if (csr & (TULIP_STS_TXINTR | TULIP_STS_TXNOBUF | TULIP_STS_TXSTOPPED)) {
1356 /* reset the transmit timeout detection flag -baz */
1357 sc->stats.tx_NoCompleteCnt = 0;
1359 badtx = sc->lmc_taint_tx;
1360 i = badtx % LMC_TXDESCS;
1362 while ((badtx < sc->lmc_next_tx)) {
1363 stat = sc->lmc_txring[i].status;
1365 LMC_EVENT_LOG (LMC_EVENT_XMTINT, stat,
1366 sc->lmc_txring[i].length);
1368 * If bit 31 is 1 the tulip owns it break out of the loop
1370 if (stat & 0x80000000)
1373 n_compl++ ; /* i.e., have an empty slot in ring */
1375 * If we have no skbuff or have cleared it
1376 * Already continue to the next buffer
1378 if (sc->lmc_txq[i] == NULL)
1382 * Check the total error summary to look for any errors
1384 if (stat & 0x8000) {
1385 sc->stats.tx_errors++;
1387 sc->stats.tx_aborted_errors++;
1389 sc->stats.tx_carrier_errors++;
1391 sc->stats.tx_window_errors++;
1393 sc->stats.tx_fifo_errors++;
1397 sc->stats.tx_bytes += sc->lmc_txring[i].length & 0x7ff;
1399 sc->stats.tx_packets++;
1402 // dev_kfree_skb(sc->lmc_txq[i]);
1403 dev_kfree_skb_irq(sc->lmc_txq[i]);
1404 sc->lmc_txq[i] = NULL;
1407 i = badtx % LMC_TXDESCS;
1410 if (sc->lmc_next_tx - badtx > LMC_TXDESCS)
1412 printk ("%s: out of sync pointer\n", dev->name);
1413 badtx += LMC_TXDESCS;
1415 LMC_EVENT_LOG(LMC_EVENT_TBUSY0, n_compl, 0);
1417 netif_wake_queue(dev);
1418 sc->stats.tx_tbusy0++ ;
1422 sc->stats.dirtyTx = badtx;
1423 sc->stats.lmc_next_tx = sc->lmc_next_tx;
1424 sc->stats.lmc_txfull = sc->lmc_txfull;
1426 sc->lmc_taint_tx = badtx;
1429 * Why was there a break here???
1431 } /* end handle transmit interrupt */
1433 if (csr & TULIP_STS_SYSERROR) {
1435 printk (KERN_WARNING "%s: system bus error csr: %#8.8x\n", dev->name, csr);
1436 error = csr>>23 & 0x7;
1439 printk(KERN_WARNING "%s: Parity Fault (bad)\n", dev->name);
1442 printk(KERN_WARNING "%s: Master Abort (naughty)\n", dev->name);
1445 printk(KERN_WARNING "%s: Target Abort (not so naughty)\n", dev->name);
1448 printk(KERN_WARNING "%s: This bus error code was supposed to be reserved!\n", dev->name);
1452 LMC_EVENT_LOG(LMC_EVENT_RESET1, LMC_CSR_READ (sc, csr_status), 0);
1453 LMC_EVENT_LOG(LMC_EVENT_RESET2,
1454 lmc_mii_readreg (sc, 0, 16),
1455 lmc_mii_readreg (sc, 0, 17));
1464 * Get current csr status to make sure
1465 * we've cleared all interrupts
1467 csr = LMC_CSR_READ (sc, csr_status);
1468 } /* end interrupt loop */
1469 LMC_EVENT_LOG(LMC_EVENT_INT, firstcsr, csr);
1473 spin_unlock(&sc->lmc_lock);
1475 lmc_trace(dev, "lmc_interrupt out");
1476 return IRQ_RETVAL(handled);
1479 static int lmc_start_xmit (struct sk_buff *skb, struct net_device *dev) /*fold00*/
1485 unsigned long flags;
1487 lmc_trace(dev, "lmc_start_xmit in");
1491 spin_lock_irqsave(&sc->lmc_lock, flags);
1493 /* normal path, tbusy known to be zero */
1495 entry = sc->lmc_next_tx % LMC_TXDESCS;
1497 sc->lmc_txq[entry] = skb;
1498 sc->lmc_txring[entry].buffer1 = virt_to_bus (skb->data);
1500 LMC_CONSOLE_LOG("xmit", skb->data, skb->len);
1503 /* If the queue is less than half full, don't interrupt */
1504 if (sc->lmc_next_tx - sc->lmc_taint_tx < LMC_TXDESCS / 2)
1506 /* Do not interrupt on completion of this packet */
1508 netif_wake_queue(dev);
1510 else if (sc->lmc_next_tx - sc->lmc_taint_tx == LMC_TXDESCS / 2)
1512 /* This generates an interrupt on completion of this packet */
1514 netif_wake_queue(dev);
1516 else if (sc->lmc_next_tx - sc->lmc_taint_tx < LMC_TXDESCS - 1)
1518 /* Do not interrupt on completion of this packet */
1520 netif_wake_queue(dev);
1524 /* This generates an interrupt on completion of this packet */
1527 netif_stop_queue(dev);
1530 flag = LMC_TDES_INTERRUPT_ON_COMPLETION;
1532 if (sc->lmc_next_tx - sc->lmc_taint_tx >= LMC_TXDESCS - 1)
1533 { /* ring full, go busy */
1535 netif_stop_queue(dev);
1536 sc->stats.tx_tbusy1++ ;
1537 LMC_EVENT_LOG(LMC_EVENT_TBUSY1, entry, 0);
1542 if (entry == LMC_TXDESCS - 1) /* last descriptor in ring */
1543 flag |= LMC_TDES_END_OF_RING; /* flag as such for Tulip */
1545 /* don't pad small packets either */
1546 flag = sc->lmc_txring[entry].length = (skb->len) | flag |
1547 sc->TxDescriptControlInit;
1549 /* set the transmit timeout flag to be checked in
1550 * the watchdog timer handler. -baz
1553 sc->stats.tx_NoCompleteCnt++;
1556 /* give ownership to the chip */
1557 LMC_EVENT_LOG(LMC_EVENT_XMT, flag, entry);
1558 sc->lmc_txring[entry].status = 0x80000000;
1561 LMC_CSR_WRITE (sc, csr_txpoll, 0);
1563 dev->trans_start = jiffies;
1565 spin_unlock_irqrestore(&sc->lmc_lock, flags);
1567 lmc_trace(dev, "lmc_start_xmit_out");
1572 static int lmc_rx (struct net_device *dev) /*fold00*/
1576 int rx_work_limit = LMC_RXDESCS;
1577 unsigned int next_rx;
1578 int rxIntLoopCnt; /* debug -baz */
1579 int localLengthErrCnt = 0;
1581 struct sk_buff *skb, *nsb;
1584 lmc_trace(dev, "lmc_rx in");
1588 lmc_led_on(sc, LMC_DS3_LED3);
1590 rxIntLoopCnt = 0; /* debug -baz */
1592 i = sc->lmc_next_rx % LMC_RXDESCS;
1593 next_rx = sc->lmc_next_rx;
1595 while (((stat = sc->lmc_rxring[i].status) & LMC_RDES_OWN_BIT) != DESC_OWNED_BY_DC21X4)
1597 rxIntLoopCnt++; /* debug -baz */
1598 len = ((stat & LMC_RDES_FRAME_LENGTH) >> RDES_FRAME_LENGTH_BIT_NUMBER);
1599 if ((stat & 0x0300) != 0x0300) { /* Check first segment and last segment */
1600 if ((stat & 0x0000ffff) != 0x7fff) {
1601 /* Oversized frame */
1602 sc->stats.rx_length_errors++;
1607 if(stat & 0x00000008){ /* Catch a dribbling bit error */
1608 sc->stats.rx_errors++;
1609 sc->stats.rx_frame_errors++;
1614 if(stat & 0x00000004){ /* Catch a CRC error by the Xilinx */
1615 sc->stats.rx_errors++;
1616 sc->stats.rx_crc_errors++;
1621 if (len > LMC_PKT_BUF_SZ){
1622 sc->stats.rx_length_errors++;
1623 localLengthErrCnt++;
1627 if (len < sc->lmc_crcSize + 2) {
1628 sc->stats.rx_length_errors++;
1629 sc->stats.rx_SmallPktCnt++;
1630 localLengthErrCnt++;
1634 if(stat & 0x00004000){
1635 printk(KERN_WARNING "%s: Receiver descriptor error, receiver out of sync?\n", dev->name);
1638 len -= sc->lmc_crcSize;
1640 skb = sc->lmc_rxq[i];
1643 * We ran out of memory at some point
1644 * just allocate an skb buff and continue.
1648 nsb = dev_alloc_skb (LMC_PKT_BUF_SZ + 2);
1650 sc->lmc_rxq[i] = nsb;
1652 sc->lmc_rxring[i].buffer1 = virt_to_bus(skb_tail_pointer(nsb));
1654 sc->failed_recv_alloc = 1;
1658 dev->last_rx = jiffies;
1659 sc->stats.rx_packets++;
1660 sc->stats.rx_bytes += len;
1662 LMC_CONSOLE_LOG("recv", skb->data, len);
1665 * I'm not sure of the sanity of this
1666 * Packets could be arriving at a constant
1667 * 44.210mbits/sec and we're going to copy
1668 * them into a new buffer??
1671 if(len > (LMC_MTU - (LMC_MTU>>2))){ /* len > LMC_MTU * 0.75 */
1673 * If it's a large packet don't copy it just hand it up
1677 sc->lmc_rxq[i] = NULL;
1678 sc->lmc_rxring[i].buffer1 = 0x0;
1681 skb->protocol = lmc_proto_type(sc, skb);
1682 skb->protocol = htons(ETH_P_WAN_PPP);
1683 skb_reset_mac_header(skb);
1684 /* skb_reset_network_header(skb); */
1686 lmc_proto_netif(sc, skb);
1689 * This skb will be destroyed by the upper layers, make a new one
1691 nsb = dev_alloc_skb (LMC_PKT_BUF_SZ + 2);
1693 sc->lmc_rxq[i] = nsb;
1695 sc->lmc_rxring[i].buffer1 = virt_to_bus(skb_tail_pointer(nsb));
1696 /* Transferred to 21140 below */
1700 * We've run out of memory, stop trying to allocate
1701 * memory and exit the interrupt handler
1703 * The chip may run out of receivers and stop
1704 * in which care we'll try to allocate the buffer
1705 * again. (once a second)
1707 sc->stats.rx_BuffAllocErr++;
1708 LMC_EVENT_LOG(LMC_EVENT_RCVINT, stat, len);
1709 sc->failed_recv_alloc = 1;
1710 goto skip_out_of_mem;
1714 nsb = dev_alloc_skb(len);
1716 goto give_it_anyways;
1718 skb_copy_from_linear_data(skb, skb_put(nsb, len), len);
1720 nsb->protocol = lmc_proto_type(sc, skb);
1721 skb_reset_mac_header(nsb);
1722 /* skb_reset_network_header(nsb); */
1724 lmc_proto_netif(sc, nsb);
1728 LMC_EVENT_LOG(LMC_EVENT_RCVINT, stat, len);
1729 sc->lmc_rxring[i].status = DESC_OWNED_BY_DC21X4;
1732 i = sc->lmc_next_rx % LMC_RXDESCS;
1734 if (rx_work_limit < 0)
1738 /* detect condition for LMC1000 where DSU cable attaches and fills
1739 * descriptors with bogus packets
1741 if (localLengthErrCnt > LMC_RXDESCS - 3) {
1742 sc->stats.rx_BadPktSurgeCnt++;
1743 LMC_EVENT_LOG(LMC_EVENT_BADPKTSURGE,
1745 sc->stats.rx_BadPktSurgeCnt);
1748 /* save max count of receive descriptors serviced */
1749 if (rxIntLoopCnt > sc->stats.rxIntLoopCnt) {
1750 sc->stats.rxIntLoopCnt = rxIntLoopCnt; /* debug -baz */
1754 if (rxIntLoopCnt == 0)
1756 for (i = 0; i < LMC_RXDESCS; i++)
1758 if ((sc->lmc_rxring[i].status & LMC_RDES_OWN_BIT)
1759 != DESC_OWNED_BY_DC21X4)
1764 LMC_EVENT_LOG(LMC_EVENT_RCVEND, rxIntLoopCnt, 0);
1769 lmc_led_off(sc, LMC_DS3_LED3);
1773 lmc_trace(dev, "lmc_rx out");
1778 static struct net_device_stats *lmc_get_stats (struct net_device *dev) /*fold00*/
1780 lmc_softc_t *sc = dev->priv;
1781 unsigned long flags;
1783 lmc_trace(dev, "lmc_get_stats in");
1786 spin_lock_irqsave(&sc->lmc_lock, flags);
1788 sc->stats.rx_missed_errors += LMC_CSR_READ (sc, csr_missed_frames) & 0xffff;
1790 spin_unlock_irqrestore(&sc->lmc_lock, flags);
1792 lmc_trace(dev, "lmc_get_stats out");
1794 return (struct net_device_stats *) &sc->stats;
1797 static struct pci_driver lmc_driver = {
1799 .id_table = lmc_pci_tbl,
1800 .probe = lmc_init_one,
1801 .remove = __devexit_p(lmc_remove_one),
1804 static int __init init_lmc(void)
1806 return pci_register_driver(&lmc_driver);
1809 static void __exit exit_lmc(void)
1811 pci_unregister_driver(&lmc_driver);
1814 module_init(init_lmc);
1815 module_exit(exit_lmc);
1817 unsigned lmc_mii_readreg (lmc_softc_t * const sc, unsigned devaddr, unsigned regno) /*fold00*/
1820 int command = (0xf6 << 10) | (devaddr << 5) | regno;
1823 lmc_trace(sc->lmc_device, "lmc_mii_readreg in");
1827 lmc_trace(sc->lmc_device, "lmc_mii_readreg: done sync");
1829 for (i = 15; i >= 0; i--)
1831 int dataval = (command & (1 << i)) ? 0x20000 : 0;
1833 LMC_CSR_WRITE (sc, csr_9, dataval);
1835 /* __SLOW_DOWN_IO; */
1836 LMC_CSR_WRITE (sc, csr_9, dataval | 0x10000);
1838 /* __SLOW_DOWN_IO; */
1841 lmc_trace(sc->lmc_device, "lmc_mii_readreg: done1");
1843 for (i = 19; i > 0; i--)
1845 LMC_CSR_WRITE (sc, csr_9, 0x40000);
1847 /* __SLOW_DOWN_IO; */
1848 retval = (retval << 1) | ((LMC_CSR_READ (sc, csr_9) & 0x80000) ? 1 : 0);
1849 LMC_CSR_WRITE (sc, csr_9, 0x40000 | 0x10000);
1851 /* __SLOW_DOWN_IO; */
1854 lmc_trace(sc->lmc_device, "lmc_mii_readreg out");
1856 return (retval >> 1) & 0xffff;
1859 void lmc_mii_writereg (lmc_softc_t * const sc, unsigned devaddr, unsigned regno, unsigned data) /*fold00*/
1862 int command = (0x5002 << 16) | (devaddr << 23) | (regno << 18) | data;
1864 lmc_trace(sc->lmc_device, "lmc_mii_writereg in");
1873 if (command & (1 << i))
1878 LMC_CSR_WRITE (sc, csr_9, datav);
1880 /* __SLOW_DOWN_IO; */
1881 LMC_CSR_WRITE (sc, csr_9, (datav | 0x10000));
1883 /* __SLOW_DOWN_IO; */
1890 LMC_CSR_WRITE (sc, csr_9, 0x40000);
1892 /* __SLOW_DOWN_IO; */
1893 LMC_CSR_WRITE (sc, csr_9, 0x50000);
1895 /* __SLOW_DOWN_IO; */
1899 lmc_trace(sc->lmc_device, "lmc_mii_writereg out");
1902 static void lmc_softreset (lmc_softc_t * const sc) /*fold00*/
1906 lmc_trace(sc->lmc_device, "lmc_softreset in");
1908 /* Initialize the receive rings and buffers. */
1910 sc->lmc_next_rx = 0;
1911 sc->lmc_next_tx = 0;
1912 sc->lmc_taint_rx = 0;
1913 sc->lmc_taint_tx = 0;
1916 * Setup each one of the receiver buffers
1917 * allocate an skbuff for each one, setup the descriptor table
1918 * and point each buffer at the next one
1921 for (i = 0; i < LMC_RXDESCS; i++)
1923 struct sk_buff *skb;
1925 if (sc->lmc_rxq[i] == NULL)
1927 skb = dev_alloc_skb (LMC_PKT_BUF_SZ + 2);
1929 printk(KERN_WARNING "%s: Failed to allocate receiver ring, will try again\n", sc->name);
1930 sc->failed_ring = 1;
1934 sc->lmc_rxq[i] = skb;
1939 skb = sc->lmc_rxq[i];
1942 skb->dev = sc->lmc_device;
1944 /* owned by 21140 */
1945 sc->lmc_rxring[i].status = 0x80000000;
1947 /* used to be PKT_BUF_SZ now uses skb since we lose some to head room */
1948 sc->lmc_rxring[i].length = skb_tailroom(skb);
1950 /* use to be tail which is dumb since you're thinking why write
1951 * to the end of the packj,et but since there's nothing there tail == data
1953 sc->lmc_rxring[i].buffer1 = virt_to_bus (skb->data);
1955 /* This is fair since the structure is static and we have the next address */
1956 sc->lmc_rxring[i].buffer2 = virt_to_bus (&sc->lmc_rxring[i + 1]);
1963 sc->lmc_rxring[i - 1].length |= 0x02000000; /* Set end of buffers flag */
1964 sc->lmc_rxring[i - 1].buffer2 = virt_to_bus (&sc->lmc_rxring[0]); /* Point back to the start */
1965 LMC_CSR_WRITE (sc, csr_rxlist, virt_to_bus (sc->lmc_rxring)); /* write base address */
1968 /* Initialize the transmit rings and buffers */
1969 for (i = 0; i < LMC_TXDESCS; i++)
1971 if (sc->lmc_txq[i] != NULL){ /* have buffer */
1972 dev_kfree_skb(sc->lmc_txq[i]); /* free it */
1973 sc->stats.tx_dropped++; /* We just dropped a packet */
1975 sc->lmc_txq[i] = NULL;
1976 sc->lmc_txring[i].status = 0x00000000;
1977 sc->lmc_txring[i].buffer2 = virt_to_bus (&sc->lmc_txring[i + 1]);
1979 sc->lmc_txring[i - 1].buffer2 = virt_to_bus (&sc->lmc_txring[0]);
1980 LMC_CSR_WRITE (sc, csr_txlist, virt_to_bus (sc->lmc_txring));
1982 lmc_trace(sc->lmc_device, "lmc_softreset 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");