From dc6851123df9ff41883ab2bf5db1dc4cf4c57eb8 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Fri, 23 Nov 2007 15:31:33 -0500 Subject: [PATCH] Import 2.3.46pre3 --- arch/i386/defconfig | 5 + arch/m68k/mac/baboon.c | 1 - arch/m68k/mac/misc.c | 2 +- arch/ppc/kernel/mk_defs.c | 1 + arch/ppc/kernel/process.c | 1 + drivers/char/lp.c | 6 - drivers/isdn/avmb1/b1dma.c | 1 + drivers/isdn/hisax/hfc_sx.c | 1 - drivers/isdn/hysdn/boardergo.c | 1 - drivers/isdn/hysdn/hysdn_boot.c | 1 - drivers/isdn/hysdn/hysdn_net.c | 1 - drivers/isdn/hysdn/hysdn_procconf.c | 1 - drivers/isdn/hysdn/hysdn_procfs.c | 1 - drivers/isdn/hysdn/hysdn_proclog.c | 1 - drivers/isdn/hysdn/hysdn_sched.c | 1 - drivers/macintosh/adb-iop.c | 1 - drivers/macintosh/via-pmu68k.c | 1 - drivers/net/8139too.c | 190 ++- drivers/net/ewrk3.c | 1 + drivers/net/hamradio/6pack.c | 141 +- drivers/net/hamradio/bpqether.c | 33 +- drivers/net/hamradio/scc.c | 129 +- drivers/net/pcmcia/3c589_cs.c | 2 - drivers/net/rtl8129.c | 2 +- drivers/net/setup.c | 8 - drivers/net/tulip.c | 3126 +++++++++++++++++++---------------- drivers/net/yellowfin.c | 831 +++++----- drivers/usb/hid.c | 2 +- drivers/usb/plusb.c | 1 - include/asm-ppc/hardirq.h | 1 + include/linux/ax25.h | 18 +- net/ax25/af_ax25.c | 28 +- 32 files changed, 2469 insertions(+), 2071 deletions(-) diff --git a/arch/i386/defconfig b/arch/i386/defconfig index 6047f6de2..66f9b5ff1 100644 --- a/arch/i386/defconfig +++ b/arch/i386/defconfig @@ -238,6 +238,11 @@ CONFIG_SCSI_NCR53C8XX_SYNC=20 # CONFIG_SCSI_ULTRASTOR is not set # +# PCMCIA SCSI adapter support +# +# CONFIG_SCSI_PCMCIA is not set + +# # I2O device support # # CONFIG_I2O is not set diff --git a/arch/m68k/mac/baboon.c b/arch/m68k/mac/baboon.c index a940053d9..445a99780 100644 --- a/arch/m68k/mac/baboon.c +++ b/arch/m68k/mac/baboon.c @@ -6,7 +6,6 @@ * Nubus slot $C interrupt. */ -#include #include #include #include diff --git a/arch/m68k/mac/misc.c b/arch/m68k/mac/misc.c index 15803f9a7..a14f25c56 100644 --- a/arch/m68k/mac/misc.c +++ b/arch/m68k/mac/misc.c @@ -3,6 +3,7 @@ */ #include +#include #include #include #include @@ -27,7 +28,6 @@ #include #define BOOTINFO_COMPAT_1_0 -#include #include #include diff --git a/arch/ppc/kernel/mk_defs.c b/arch/ppc/kernel/mk_defs.c index 3efc7bbf9..4f3c6834d 100644 --- a/arch/ppc/kernel/mk_defs.c +++ b/arch/ppc/kernel/mk_defs.c @@ -9,6 +9,7 @@ */ #include +#include #include #include #include diff --git a/arch/ppc/kernel/process.c b/arch/ppc/kernel/process.c index 3b30f50ef..41382b2d7 100644 --- a/arch/ppc/kernel/process.c +++ b/arch/ppc/kernel/process.c @@ -19,6 +19,7 @@ * */ +#include #include #include #include diff --git a/drivers/char/lp.c b/drivers/char/lp.c index a68742c18..72377382f 100644 --- a/drivers/char/lp.c +++ b/drivers/char/lp.c @@ -166,12 +166,6 @@ static int lp_preempt(void *handle) return 0; } - if (!(lps->flags & LP_PORT_BUSY)) { - /* Let the port go. */ - clear_bit (LP_HAVE_PORT_BIT, &lps->flags); - return 0; - } - /* Don't actually release the port now */ return 1; } diff --git a/drivers/isdn/avmb1/b1dma.c b/drivers/isdn/avmb1/b1dma.c index 04eb29aba..8bf595282 100644 --- a/drivers/isdn/avmb1/b1dma.c +++ b/drivers/isdn/avmb1/b1dma.c @@ -15,6 +15,7 @@ * */ +#include #include #include #include diff --git a/drivers/isdn/hisax/hfc_sx.c b/drivers/isdn/hisax/hfc_sx.c index ee14af806..462de9d91 100644 --- a/drivers/isdn/hisax/hfc_sx.c +++ b/drivers/isdn/hisax/hfc_sx.c @@ -38,7 +38,6 @@ * */ -#include #define __NO_VERSION__ #include "hisax.h" #include "hfc_sx.h" diff --git a/drivers/isdn/hysdn/boardergo.c b/drivers/isdn/hysdn/boardergo.c index 31f91531b..578e4a14d 100644 --- a/drivers/isdn/hysdn/boardergo.c +++ b/drivers/isdn/hysdn/boardergo.c @@ -32,7 +32,6 @@ * */ -#include #define __NO_VERSION__ #include #include diff --git a/drivers/isdn/hysdn/hysdn_boot.c b/drivers/isdn/hysdn/hysdn_boot.c index e62418089..030c40de6 100644 --- a/drivers/isdn/hysdn/hysdn_boot.c +++ b/drivers/isdn/hysdn/hysdn_boot.c @@ -28,7 +28,6 @@ * */ -#include #define __NO_VERSION__ #include #include diff --git a/drivers/isdn/hysdn/hysdn_net.c b/drivers/isdn/hysdn/hysdn_net.c index 3546ea818..1a3d21012 100644 --- a/drivers/isdn/hysdn/hysdn_net.c +++ b/drivers/isdn/hysdn/hysdn_net.c @@ -39,7 +39,6 @@ * */ -#include #define __NO_VERSION__ #include #include diff --git a/drivers/isdn/hysdn/hysdn_procconf.c b/drivers/isdn/hysdn/hysdn_procconf.c index c26ef7fed..81e1b84f0 100644 --- a/drivers/isdn/hysdn/hysdn_procconf.c +++ b/drivers/isdn/hysdn/hysdn_procconf.c @@ -31,7 +31,6 @@ * */ -#include #define __NO_VERSION__ #include #include diff --git a/drivers/isdn/hysdn/hysdn_procfs.c b/drivers/isdn/hysdn/hysdn_procfs.c index 3400067ff..d70d350e9 100644 --- a/drivers/isdn/hysdn/hysdn_procfs.c +++ b/drivers/isdn/hysdn/hysdn_procfs.c @@ -27,7 +27,6 @@ * */ -#include #define __NO_VERSION__ #include #include diff --git a/drivers/isdn/hysdn/hysdn_proclog.c b/drivers/isdn/hysdn/hysdn_proclog.c index 88a001af8..aea6a96ad 100644 --- a/drivers/isdn/hysdn/hysdn_proclog.c +++ b/drivers/isdn/hysdn/hysdn_proclog.c @@ -31,7 +31,6 @@ * */ -#include #define __NO_VERSION__ #include #include diff --git a/drivers/isdn/hysdn/hysdn_sched.c b/drivers/isdn/hysdn/hysdn_sched.c index 991272152..0e5f9e7ba 100644 --- a/drivers/isdn/hysdn/hysdn_sched.c +++ b/drivers/isdn/hysdn/hysdn_sched.c @@ -28,7 +28,6 @@ * */ -#include #define __NO_VERSION__ #include #include diff --git a/drivers/macintosh/adb-iop.c b/drivers/macintosh/adb-iop.c index 3c3db0a71..cf0504e0e 100644 --- a/drivers/macintosh/adb-iop.c +++ b/drivers/macintosh/adb-iop.c @@ -12,7 +12,6 @@ * o Implement SRQ handling. */ -#include #include #include #include diff --git a/drivers/macintosh/via-pmu68k.c b/drivers/macintosh/via-pmu68k.c index bdb9fae0e..0c14baed5 100644 --- a/drivers/macintosh/via-pmu68k.c +++ b/drivers/macintosh/via-pmu68k.c @@ -18,7 +18,6 @@ */ #include -#include #include #include #include diff --git a/drivers/net/8139too.c b/drivers/net/8139too.c index d6a7f66df..9abb0a4ae 100644 --- a/drivers/net/8139too.c +++ b/drivers/net/8139too.c @@ -19,6 +19,11 @@ David S. Miller - PCI DMA and softnet updates + Ernst Gill - fixes ported from BSD driver + + Daniel Kobras - identified specific locations of + posted MMIO write bugginess + ----------------------------------------------------------------------------- Theory of Operation @@ -82,7 +87,7 @@ an MMIO register read. #include -#define RTL8139_VERSION "0.9.0" +#define RTL8139_VERSION "0.9.2" #define RTL8139_MODULE_NAME "8139too" #define RTL8139_DRIVER_NAME RTL8139_MODULE_NAME " Fast Ethernet driver " RTL8139_VERSION #define PFX RTL8139_MODULE_NAME ": " @@ -154,15 +159,17 @@ enum { #define RTL8139_CAPS HAS_CHIP_XCVR|HAS_LNK_CHNG typedef enum { - UNKNOWN = 0, RTL8139, RTL8139_CB, SMC1211TX, - MPX5030, + /*MPX5030,*/ SIS900, SIS7016, + DELTA8139, + ADDTRON8139, } chip_t; + static struct { chip_t chip; const char *name; @@ -170,19 +177,24 @@ static struct { { RTL8139, "RealTek RTL8139 Fast Ethernet"}, { RTL8139_CB, "RealTek RTL8139B PCI/CardBus"}, { SMC1211TX, "SMC1211TX EZCard 10/100 (RealTek RTL8139)"}, - { MPX5030, "Accton MPX5030 (RealTek RTL8139)"}, +/* { MPX5030, "Accton MPX5030 (RealTek RTL8139)"},*/ { SIS900, "SiS 900 (RealTek RTL8139) Fast Ethernet"}, { SIS7016, "SiS 7016 (RealTek RTL8139) Fast Ethernet"}, + { DELTA8139, "Delta Electronics 8139 10/100BaseTX"}, + { ADDTRON8139, "Addtron Technolgy 8139 10/100BaseTX"}, {0,}, }; + static struct pci_device_id rtl8139_pci_tbl[] __devinitdata = { {0x10ec, 0x8139, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RTL8139 }, {0x10ec, 0x8138, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RTL8139_CB }, {0x1113, 0x1211, PCI_ANY_ID, PCI_ANY_ID, 0, 0, SMC1211TX }, - {0x1113, 0x1211, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MPX5030 }, +/* {0x1113, 0x1211, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MPX5030 },*/ {0x1039, 0x0900, PCI_ANY_ID, PCI_ANY_ID, 0, 0, SIS900 }, {0x1039, 0x7016, PCI_ANY_ID, PCI_ANY_ID, 0, 0, SIS7016 }, + {0x1500, 0x1360, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DELTA8139 }, + {0x4033, 0x1360, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ADDTRON8139 }, {0,}, }; MODULE_DEVICE_TABLE (pci, rtl8139_pci_tbl); @@ -304,7 +316,7 @@ enum CSCRBits { #define PARA78_default 0x78fa8388 #define PARA7c_default 0xcb38de43 /* param[0][3] */ #define PARA7c_xxx 0xcb38de43 -unsigned long param[4][4] = { +static const unsigned long param[4][4] = { {0xcb39de43, 0xcb39ce43, 0xfb38de03, 0xcb38de43}, {0xcb39de43, 0xcb39ce43, 0xcb39ce83, 0xcb39ce83}, {0xcb39de43, 0xcb39ce43, 0xcb39ce83, 0xcb39ce83}, @@ -328,7 +340,6 @@ struct rtl8139_private { struct timer_list timer; /* Media selection timer. */ unsigned char *rx_ring; unsigned int cur_rx; /* Index into the Rx buffer of next Rx pkt. */ - unsigned int rx_config; unsigned int cur_tx, dirty_tx, tx_flag; /* The saved address of a sent-in-place packet/buffer, for skfree(). */ struct ring_info tx_info[NUM_TX_DESC]; @@ -370,13 +381,43 @@ static struct net_device_stats *rtl8139_get_stats (struct net_device *dev); static inline u32 ether_crc (int length, unsigned char *data); static void rtl8139_set_rx_mode (struct net_device *dev); -/* read after write, to avoid rtl8139 bug w/ posted MMIO writes */ -#define RTL_W8(reg, val8) do { writeb (val8, ioaddr + reg); readb (ioaddr + reg); } while (0) -#define RTL_W16(reg, val16) do { writew (val16, ioaddr + reg); readw (ioaddr + reg); } while (0) -#define RTL_W32(reg, val32) do { writel (val32, ioaddr + reg); readl (ioaddr + reg); } while (0) -#define RTL_R8(reg) readb (ioaddr + reg) -#define RTL_R16(reg) readw (ioaddr + reg) -#define RTL_R32(reg) readl (ioaddr + reg) +/* write MMIO register, with flush */ +/* Flush avoids rtl8139 bug w/ posted MMIO writes */ +#define RTL_W8_F(reg, val8) do { writeb ((val8), ioaddr + (reg)); readb (ioaddr + (reg)); } while (0) +#define RTL_W16_F(reg, val16) do { writew ((val16), ioaddr + (reg)); readw (ioaddr + (reg)); } while (0) +#define RTL_W32_F(reg, val32) do { writel ((val32), ioaddr + (reg)); readl (ioaddr + (reg)); } while (0) + + +#if MMIO_FLUSH_AUDIT_COMPLETE + +/* write MMIO register */ +#define RTL_W8(reg, val8) writeb ((val8), ioaddr + (reg)) +#define RTL_W16(reg, val16) writew ((val16), ioaddr + (reg)) +#define RTL_W32(reg, val32) writel ((val32), ioaddr + (reg)) + +#else + +/* write MMIO register, then flush */ +#define RTL_W8 RTL_W8_F +#define RTL_W16 RTL_W16_F +#define RTL_W32 RTL_W32_F + +#endif /* MMIO_FLUSH_AUDIT_COMPLETE */ + +/* read MMIO register */ +#define RTL_R8(reg) readb (ioaddr + (reg)) +#define RTL_R16(reg) readw (ioaddr + (reg)) +#define RTL_R32(reg) readl (ioaddr + (reg)) + + +static const u16 rtl8139_intr_mask = + PCIErr | PCSTimeout | RxUnderrun | RxOverflow | RxFIFOOver | + TxErr | TxOK | RxErr | RxOK; + +static const unsigned int rtl8139_rx_config = + (RX_FIFO_THRESH << 13) | + (RX_BUF_LEN_IDX << 11) | + (RX_DMA_BURST << 8); static const char * __devinit rtl8139_name_from_chip (chip_t chip) @@ -855,22 +896,18 @@ static int rtl8139_open (struct net_device *dev) rtl8139_init_ring (dev); tp->full_duplex = tp->duplex_lock; tp->tx_flag = (TX_FIFO_THRESH << 11) & 0x003f0000; - tp->rx_config = - (RX_FIFO_THRESH << 13) | - (RX_BUF_LEN_IDX << 11) | - (RX_DMA_BURST << 8); /* Check that the chip has finished the reset. */ for (i = 1000; i > 0; i--) if ((RTL_R8 (ChipCmd) & CmdReset) == 0) break; - RTL_W32 (MAC0 + 0, cpu_to_le32 (*(u32 *) (dev->dev_addr + 0))); - RTL_W32 (MAC0 + 4, cpu_to_le32 (*(u32 *) (dev->dev_addr + 4))); + RTL_W32_F (MAC0 + 0, cpu_to_le32 (*(u32 *) (dev->dev_addr + 0))); + RTL_W32_F (MAC0 + 4, cpu_to_le32 (*(u32 *) (dev->dev_addr + 4))); /* Must enable Tx/Rx before setting transfer thresholds! */ RTL_W8 (ChipCmd, CmdRxEnb | CmdTxEnb); - RTL_W32 (RxConfig, tp->rx_config); + RTL_W32 (RxConfig, rtl8139_rx_config); RTL_W32 (TxConfig, (TX_DMA_BURST << 8) | 0x00000000); /* Reset N-Way to chipset defaults */ @@ -897,9 +934,7 @@ static int rtl8139_open (struct net_device *dev) RTL_W8 (ChipCmd, CmdRxEnb | CmdTxEnb); /* Enable all known interrupts by setting the interrupt mask. */ - RTL_W16 (IntrMask, - PCIErr | PCSTimeout | RxUnderrun | RxOverflow | RxFIFOOver - | TxErr | TxOK | RxErr | RxOK); + RTL_W16 (IntrMask, rtl8139_intr_mask); DPRINTK ("%s: rtl8139_open() ioaddr %#lx IRQ %d" " GP Pins %2.2x %s-duplex.\n", @@ -938,8 +973,8 @@ static void rtl8139_hw_start (struct net_device *dev) break; /* Restore our idea of the MAC address. */ - RTL_W32 (MAC0 + 0, cpu_to_le32 (*(u32 *) (dev->dev_addr + 0))); - RTL_W32 (MAC0 + 4, cpu_to_le32 (*(u32 *) (dev->dev_addr + 4))); + RTL_W32_F (MAC0 + 0, cpu_to_le32 (*(u32 *) (dev->dev_addr + 0))); + RTL_W32_F (MAC0 + 4, cpu_to_le32 (*(u32 *) (dev->dev_addr + 4))); /* Hmmm, do these belong here? */ RTL_W8 (Cfg9346, 0x00); @@ -947,7 +982,7 @@ static void rtl8139_hw_start (struct net_device *dev) /* Must enable Tx/Rx before setting transfer thresholds! */ RTL_W8 (ChipCmd, CmdRxEnb | CmdTxEnb); - RTL_W32 (RxConfig, tp->rx_config); + RTL_W32 (RxConfig, rtl8139_rx_config); /* Check this value: the documentation contradicts ifself. Is the IFG correct with bit 28:27 zero, or with |0x03000000 ? */ RTL_W32 (TxConfig, (TX_DMA_BURST << 8) | 0x00000000); @@ -974,9 +1009,7 @@ static void rtl8139_hw_start (struct net_device *dev) rtl8139_set_rx_mode (dev); RTL_W8 (ChipCmd, CmdRxEnb | CmdTxEnb); /* Enable all known interrupts by setting the interrupt mask. */ - RTL_W16 (IntrMask, - PCIErr | PCSTimeout | RxUnderrun | RxOverflow | RxFIFOOver - | TxErr | TxOK | RxErr | RxOK); + RTL_W16 (IntrMask, rtl8139_intr_mask); netif_start_queue (dev); @@ -1136,9 +1169,9 @@ static void rtl8139_tx_timeout (struct net_device *dev) DPRINTK ("%s: Transmit timeout, status %2.2x %4.4x " "media %2.2x.\n", dev->name, - readb (ioaddr + ChipCmd), - readw (ioaddr + IntrStatus), - readb (ioaddr + GPPinData)); + RTL_R8 (ChipCmd), + RTL_R16 (IntrStatus), + RTL_R8 (GPPinData)); /* Disable interrupts by clearing the interrupt mask. */ RTL_W16 (IntrMask, 0x0000); @@ -1148,7 +1181,7 @@ static void rtl8139_tx_timeout (struct net_device *dev) dev->name, tp->cur_tx, tp->dirty_tx); for (i = 0; i < NUM_TX_DESC; i++) printk (KERN_DEBUG "%s: Tx descriptor %d is %8.8x.%s\n", - dev->name, i, readl (ioaddr + TxStatus0 + i * 4), + dev->name, i, RTL_R32 (TxStatus0 + (i * 4)), i == tp->dirty_tx % NUM_TX_DESC ? " (queue head)" : ""); printk (KERN_DEBUG "%s: MII #%d registers are:", dev->name, @@ -1263,7 +1296,7 @@ static inline void rtl8139_tx_interrupt (struct net_device *dev, while (tp->cur_tx - dirty_tx > 0) { int entry = dirty_tx % NUM_TX_DESC; - int txstatus = readl (ioaddr + TxStatus0 + entry * 4); + int txstatus = RTL_R32 (TxStatus0 + (entry * 4)); if (!(txstatus & (TxStatOK | TxUnderrun | TxAborted))) break; /* It still hasn't been Txed */ @@ -1338,11 +1371,11 @@ static inline void rtl8139_rx_interrupt (struct net_device *dev, DPRINTK ("%s: In rtl8139_rx(), current %4.4x BufAddr %4.4x," " free to %4.4x, Cmd %2.2x.\n", dev->name, cur_rx, - readw (ioaddr + RxBufAddr), - readw (ioaddr + RxBufPtr), - readb (ioaddr + ChipCmd)); + RTL_R16 (RxBufAddr), + RTL_R16 (RxBufPtr), + RTL_R8 (ChipCmd)); - while ((readb (ioaddr + ChipCmd) & RxBufEmpty) == 0) { + while ((RTL_R8 (ChipCmd) & RxBufEmpty) == 0) { int ring_offset = cur_rx % RX_BUF_LEN; u32 rx_status = le32_to_cpu (*(u32 *) (rx_ring + ring_offset)); @@ -1359,6 +1392,18 @@ static inline void rtl8139_rx_interrupt (struct net_device *dev, printk (".\n"); #endif + /* E. Gill */ + /* Note from BSD driver: + * Here's a totally undocumented fact for you. When the + * RealTek chip is in the process of copying a packet into + * RAM for you, the length will be 0xfff0. If you spot a + * packet header with this value, you need to stop. The + * datasheet makes absolutely no mention of this and + * RealTek should be shot for this. + */ + if (rx_size == 0xfff0) + break; + if (rx_status & (RxBadSymbol | RxRunt | RxTooLong | RxCRCErr | RxBadAlign)) { @@ -1437,13 +1482,13 @@ static inline void rtl8139_rx_interrupt (struct net_device *dev, } cur_rx = (cur_rx + rx_size + 4 + 3) & ~3; - RTL_W16 (RxBufPtr, cur_rx - 16); + RTL_W16_F (RxBufPtr, cur_rx - 16); } DPRINTK ("%s: Done rtl8139_rx(), current %4.4x BufAddr %4.4x," " free to %4.4x, Cmd %2.2x.\n", dev->name, cur_rx, - readw (ioaddr + RxBufAddr), - readw (ioaddr + RxBufPtr), - readb (ioaddr + ChipCmd)); + RTL_R16 (RxBufAddr), + RTL_R16 (RxBufPtr), + RTL_R8 (ChipCmd)); tp->cur_rx = cur_rx; } @@ -1468,14 +1513,13 @@ static inline int rtl8139_weird_interrupt (struct net_device *dev, } /* Update the error count. */ - tp->stats.rx_missed_errors += - readl (ioaddr + RxMissed); + tp->stats.rx_missed_errors += RTL_R32 (RxMissed); RTL_W32 (RxMissed, 0); if ((status & RxUnderrun) && link_changed && (tp->drv_flags & HAS_LNK_CHNG)) { /* Really link-change on new chips. */ - int lpar = readw (ioaddr + NWayLPAR); + int lpar = RTL_R16 (NWayLPAR); int duplex = (lpar & 0x0100) || (lpar & 0x01C0) == 0x0040 || tp->duplex_lock; if (tp->full_duplex != duplex) { @@ -1496,8 +1540,8 @@ static inline int rtl8139_weird_interrupt (struct net_device *dev, tp->stats.rx_fifo_errors++; if (status & RxOverflow) { tp->stats.rx_over_errors++; - tp->cur_rx = readw (ioaddr + RxBufAddr) % RX_BUF_LEN; - RTL_W16 (RxBufPtr, tp->cur_rx - 16); + tp->cur_rx = RTL_R16 (RxBufAddr) % RX_BUF_LEN; + RTL_W16_F (RxBufPtr, tp->cur_rx - 16); } if (status & PCIErr) { u16 pci_cmd_status; @@ -1524,17 +1568,40 @@ static void rtl8139_interrupt (int irq, void *dev_instance, spin_lock_irq (&tp->lock); + /* disable interrupt generation while handling this interrupt */ + RTL_W16 (IntrMask, 0x0000); + do { - int status = readw (ioaddr + IntrStatus); + int status = RTL_R16 (IntrStatus); /* Acknowledge all of the current interrupt sources ASAP, but an first get an additional status bit from CSCR. */ if (status & RxUnderrun) - link_changed = readw (ioaddr + CSCR) & CSCR_LinkChangeBit; - RTL_W16 (IntrStatus, status); + link_changed = RTL_R16 (CSCR) & CSCR_LinkChangeBit; + + /* E. Gill */ + /* In case of an RxFIFOOver we must also clear the RxOverflow + bit to avoid dropping frames for ever. Believe me, I got a + lot of troubles copying huge data (approximately 2 RxFIFOOver + errors per 1GB data transfer). + The following is written in the 'p-guide.pdf' file (RTL8139(A/B) + Programming guide V0.1, from 1999/1/15) on page 9 from REALTEC. + ----------------------------------------------------------- + 2. RxFIFOOvw handling: + When RxFIFOOvw occurs, all incoming packets are discarded. + Clear ISR(RxFIFOOvw) doesn't dismiss RxFIFOOvw event. To + dismiss RxFIFOOvw event, the ISR(RxBufOvw) must be written + with a '1'. + ----------------------------------------------------------- + Unfortunately I was not able to find any reason for the + RxFIFOOver error (I got the feeling this depends on the + CPU speed, lower CPU speed --> more errors). + After clearing the RxOverflow bit the transfer of the + packet was repeated and all data are error free transfered */ + RTL_W16 (IntrStatus, (status & RxFIFOOver) ? (status | RxOverflow) : status); DPRINTK ("%s: interrupt status=%#4.4x new intstat=%#4.4x.\n", dev->name, status, - readw (ioaddr + IntrStatus)); + RTL_R16 (IntrStatus)); if ((status & (PCIErr | PCSTimeout | RxUnderrun | RxOverflow | @@ -1565,11 +1632,14 @@ static void rtl8139_interrupt (int irq, void *dev_instance, } } while (1); - DPRINTK ("%s: exiting interrupt, intr_status=%#4.4x.\n", - dev->name, readw (ioaddr + IntrStatus)); + /* Enable all known interrupts by setting the interrupt mask. */ + RTL_W16 (IntrMask, rtl8139_intr_mask); spin_unlock_irq (&tp->lock); - return; + + DPRINTK ("%s: exiting interrupt, intr_status=%#4.4x.\n", + dev->name, RTL_R16 (IntrStatus)); + } static int rtl8139_close (struct net_device *dev) @@ -1583,7 +1653,7 @@ static int rtl8139_close (struct net_device *dev) netif_stop_queue (dev); DPRINTK ("%s: Shutting down ethercard, status was 0x%4.4x.\n", - dev->name, readw (ioaddr + IntrStatus)); + dev->name, RTL_R16 (IntrStatus)); /* Disable interrupts by clearing the interrupt mask. */ RTL_W16 (IntrMask, 0x0000); @@ -1710,7 +1780,7 @@ static void rtl8139_set_rx_mode (struct net_device *dev) DPRINTK ("ENTER\n"); DPRINTK ("%s: rtl8139_set_rx_mode(%4.4x) done -- Rx config %8.8x.\n", - dev->name, dev->flags, readl (ioaddr + RxConfig)); + dev->name, dev->flags, RTL_R32 (RxConfig)); /* Note: do not reorder, GCC is clever about common statements. */ if (dev->flags & IFF_PROMISC) { @@ -1739,9 +1809,9 @@ static void rtl8139_set_rx_mode (struct net_device *dev) mc_filter); } /* We can safely update without stopping the chip. */ - RTL_W32 (RxConfig, tp->rx_config | rx_mode); - RTL_W32 (MAR0 + 0, mc_filter[0]); - RTL_W32 (MAR0 + 4, mc_filter[1]); + RTL_W32 (RxConfig, rtl8139_rx_config | rx_mode); + RTL_W32_F (MAR0 + 0, mc_filter[0]); + RTL_W32_F (MAR0 + 4, mc_filter[1]); DPRINTK ("EXIT\n"); } diff --git a/drivers/net/ewrk3.c b/drivers/net/ewrk3.c index efed9b817..90c82b341 100644 --- a/drivers/net/ewrk3.c +++ b/drivers/net/ewrk3.c @@ -138,6 +138,7 @@ static const char *version = "ewrk3.c:v0.43 96/8/16 davies@maniac.ultranet.com\n"; +#include #include #include diff --git a/drivers/net/hamradio/6pack.c b/drivers/net/hamradio/6pack.c index 16dc8a976..e8708a28f 100644 --- a/drivers/net/hamradio/6pack.c +++ b/drivers/net/hamradio/6pack.c @@ -158,24 +158,6 @@ sp_free(struct sixpack *sp) } -/* Set the "sending" flag. */ -static inline void -sp_lock(struct sixpack *sp) -{ - if (test_and_set_bit(0, (void *) &sp->dev->tbusy)) - printk(KERN_WARNING "%s: trying to lock already locked device!\n", sp->dev->name); -} - - -/* Clear the "sending" flag. */ -static inline void -sp_unlock(struct sixpack *sp) -{ - if (!test_and_clear_bit(0, (void *)&sp->dev->tbusy)) - printk(KERN_WARNING "%s: trying to unlock already unlocked device!\n", sp->dev->name); -} - - /* Send one completely decapsulated IP datagram to the IP layer. */ /* This is the routine that sends the received data to the kernel AX.25. @@ -226,7 +208,7 @@ sp_encaps(struct sixpack *sp, unsigned char *icp, int len) len = sp->mtu; printk(KERN_DEBUG "%s: truncating oversized transmit packet!\n", sp->dev->name); sp->tx_dropped++; - sp_unlock(sp); + netif_start_queue(sp->dev); return; } @@ -235,21 +217,21 @@ sp_encaps(struct sixpack *sp, unsigned char *icp, int len) if (p[0] > 5) { printk(KERN_DEBUG "%s: invalid KISS command -- dropped\n", sp->dev->name); - sp_unlock(sp); + netif_start_queue(sp->dev); return; } if ((p[0] != 0) && (len > 2)) { printk(KERN_DEBUG "%s: KISS control packet too long -- dropped\n", sp->dev->name); - sp_unlock(sp); + netif_start_queue(sp->dev); return; } if ((p[0] == 0) && (len < 15)) { printk(KERN_DEBUG "%s: bad AX.25 packet to transmit -- dropped\n", sp->dev->name); - sp_unlock(sp); + netif_start_queue(sp->dev); sp->tx_dropped++; return; } @@ -301,17 +283,17 @@ static void sixpack_write_wakeup(struct tty_struct *tty) struct sixpack *sp = (struct sixpack *) tty->disc_data; /* First make sure we're connected. */ - if (!sp || sp->magic != SIXPACK_MAGIC || !sp->dev->start) { + if (!sp || sp->magic != SIXPACK_MAGIC || !test_bit(LINK_STATE_START, &sp->dev->state)) { return; } + if (sp->xleft <= 0) { /* Now serial buffer is almost free & we can start * transmission of another packet */ sp->tx_packets++; tty->flags &= ~(1 << TTY_DO_WRITE_WAKEUP); - sp_unlock(sp); sp->tx_enable = 0; - mark_bh(NET_BH); + netif_wake_queue(sp->dev); return; } @@ -331,18 +313,9 @@ sp_xmit(struct sk_buff *skb, struct net_device *dev) { struct sixpack *sp = (struct sixpack*)(dev->priv); - if (!dev->start) - { - printk(KERN_WARNING "%s: xmit call when iface is down\n", dev->name); - return 1; - } - - if (dev->tbusy) - return 1; - /* We were not busy, so we are now... :-) */ if (skb != NULL) { - sp_lock(sp); + netif_stop_queue(dev); sp->tx_bytes+=skb->len; /*---2.1.x---*/ sp_encaps(sp, skb->data, skb->len); dev_kfree_skb(skb); @@ -458,8 +431,7 @@ sp_open(struct net_device *dev) sp->tnc_ok = 0; sp->tx_enable = 0; - dev->tbusy = 0; - dev->start = 1; + netif_start_queue(dev); init_timer(&sp->tx_t); init_timer(&sp->resync_t); @@ -477,9 +449,8 @@ sp_close(struct net_device *dev) return -EBUSY; } sp->tty->flags &= ~(1 << TTY_DO_WRITE_WAKEUP); - dev->tbusy = 1; - dev->start = 0; + netif_stop_queue(dev); return 0; } @@ -506,7 +477,7 @@ sixpack_receive_buf(struct tty_struct *tty, const unsigned char *cp, char *fp, i struct sixpack *sp = (struct sixpack *) tty->disc_data; - if (!sp || sp->magic != SIXPACK_MAGIC || !sp->dev->start || !count) + if (!sp || sp->magic != SIXPACK_MAGIC || !test_bit(LINK_STATE_START, &sp->dev->state) || !count) return; save_flags(flags); @@ -723,17 +694,13 @@ static int sp_open_dev(struct net_device *dev) /* Initialize 6pack control device -- register 6pack line discipline */ -#ifdef MODULE -static int sixpack_init_ctrl_dev(void) -#else /* !MODULE */ -int __init sixpack_init_ctrl_dev(struct net_device *dummy) -#endif /* !MODULE */ +static int __init sixpack_init_ctrl_dev(void) { int status; if (sixpack_maxdev < 4) sixpack_maxdev = 4; /* Sanity */ - printk(KERN_INFO "6pack: %s (dynamic channels, max=%d)\n", + printk(KERN_INFO "AX.25: 6pack driver, %s (dynamic channels, max=%d)\n", SIXPACK_VERSION, sixpack_maxdev); sixpack_ctrls = (sixpack_ctrl_t **) kmalloc(sizeof(void*)*sixpack_maxdev, GFP_KERNEL); @@ -766,16 +733,40 @@ int __init sixpack_init_ctrl_dev(struct net_device *dummy) printk(KERN_WARNING "6pack: can't register line discipline (err = %d)\n", status); } -#ifdef MODULE return status; -#else - /* Return "not found", so that dev_init() will unlink - * the placeholder device entry for us. - */ - return ENODEV; -#endif } +static void __exit sixpack_cleanup_driver(void) +{ + int i; + + if (sixpack_ctrls != NULL) + { + for (i = 0; i < sixpack_maxdev; i++) + { + if (sixpack_ctrls[i]) + { + /* + * VSV = if dev->start==0, then device + * unregistered while close proc. + */ + if (test_bit(LINK_STATE_START, &sixpack_ctrls[i]->dev.state)) + unregister_netdev(&(sixpack_ctrls[i]->dev)); + + kfree(sixpack_ctrls[i]); + sixpack_ctrls[i] = NULL; + } + } + kfree(sixpack_ctrls); + sixpack_ctrls = NULL; + } + if ((i = tty_register_ldisc(N_6PACK, NULL))) + { + printk(KERN_WARNING "6pack: can't unregister line discipline (err = %d)\n", i); + } +} + + /* Initialize the 6pack driver. Called by DDI. */ int sixpack_init(struct net_device *dev) @@ -809,6 +800,7 @@ sixpack_init(struct net_device *dev) dev->type = ARPHRD_AX25; dev->tx_queue_len = 10; dev->rebuild_header = sp_rebuild_header; + dev->tx_timeout = NULL; memcpy(dev->broadcast, ax25_bcast, AX25_ADDR_LEN); /* Only activated in AX.25 mode */ memcpy(dev->dev_addr, ax25_test, AX25_ADDR_LEN); /* "" "" "" "" */ @@ -821,45 +813,8 @@ sixpack_init(struct net_device *dev) return 0; } -#ifdef MODULE - -int -init_module(void) -{ - return sixpack_init_ctrl_dev(); -} - -void -cleanup_module(void) -{ - int i; - if (sixpack_ctrls != NULL) - { - for (i = 0; i < sixpack_maxdev; i++) - { - if (sixpack_ctrls[i]) - { - /* - * VSV = if dev->start==0, then device - * unregistered while close proc. - */ - if (sixpack_ctrls[i]->dev.start) - unregister_netdev(&(sixpack_ctrls[i]->dev)); - kfree(sixpack_ctrls[i]); - sixpack_ctrls[i] = NULL; - } - } - kfree(sixpack_ctrls); - sixpack_ctrls = NULL; - } - if ((i = tty_register_ldisc(N_6PACK, NULL))) - { - printk(KERN_WARNING "6pack: can't unregister line discipline (err = %d)\n", i); - } -} -#endif /* MODULE */ /* ----> 6pack timer interrupt handler and friends. <---- */ static void @@ -1127,3 +1082,9 @@ void decode_data(byte inbyte, struct sixpack *sp) sp->rx_count = 0; } } + + +MODULE_AUTHOR("Andreas Könsgen "); +MODULE_DESCRIPTION("6pack driver for AX.25"); +module_init(sixpack_init_ctrl_dev); +module_exit(sixpack_cleanup_driver); diff --git a/drivers/net/hamradio/bpqether.c b/drivers/net/hamradio/bpqether.c index 689dcdb36..cc5c35bf3 100644 --- a/drivers/net/hamradio/bpqether.c +++ b/drivers/net/hamradio/bpqether.c @@ -222,7 +222,7 @@ static int bpq_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_ty dev = bpq_get_ax25_dev(dev); - if (dev == NULL || test_bit(LINK_STATE_START, &dev->state) == 0) { + if (dev == NULL || !test_bit(LINK_STATE_START, &dev->state)) { kfree_skb(skb); return 0; } @@ -275,7 +275,8 @@ static int bpq_xmit(struct sk_buff *skb, struct net_device *dev) * Just to be *really* sure not to send anything if the interface * is down, the ethernet device may have gone. */ - if (!test_bit(LINK_STATE_START, &dev->state)) { + if (!test_bit(LINK_STATE_START, &dev->state)) + { bpq_check_devices(dev); kfree_skb(skb); return -ENODEV; @@ -324,7 +325,7 @@ static int bpq_xmit(struct sk_buff *skb, struct net_device *dev) bpq->stats.tx_bytes+=skb->len; dev_queue_xmit(skb); - + netif_wake_queue(dev); return 0; } @@ -407,7 +408,9 @@ static int bpq_open(struct net_device *dev) { if (bpq_check_devices(dev)) return -ENODEV; /* oops, it's gone */ + MOD_INC_USE_COUNT; + netif_start_queue(dev); return 0; } @@ -614,7 +617,7 @@ static int bpq_device_event(struct notifier_block *this,unsigned long event, voi * Initialize driver. To be called from af_ax25 if not compiled as a * module */ -int __init bpq_init(void) +static int __init bpq_init_driver(void) { struct net_device *dev; @@ -623,7 +626,7 @@ int __init bpq_init(void) register_netdevice_notifier(&bpq_dev_notifier); - printk(KERN_INFO "AX.25 ethernet driver version 0.01\n"); + printk(KERN_INFO "AX.25: bpqether driver version 0.01\n"); proc_net_create ("bpqether", 0, bpq_get_info); @@ -636,22 +639,10 @@ int __init bpq_init(void) } } read_unlock_bh(&dev_base_lock); -out: return 0; } -#ifdef MODULE -EXPORT_NO_SYMBOLS; - -MODULE_AUTHOR("Joerg Reuter DL1BKE "); -MODULE_DESCRIPTION("Transmit and receive AX.25 packets over Ethernet"); - -int init_module(void) -{ - return bpq_init(); -} - -void cleanup_module(void) +static void __exit bpq_cleanup_driver(void) { struct bpqdev *bpq; @@ -664,4 +655,8 @@ void cleanup_module(void) for (bpq = bpq_devices; bpq != NULL; bpq = bpq->next) unregister_netdev(&bpq->axdev); } -#endif + +MODULE_AUTHOR("Joerg Reuter DL1BKE "); +MODULE_DESCRIPTION("Transmit and receive AX.25 packets over Ethernet"); +module_init(bpq_init_driver); +module_exit(bpq_cleanup_driver); diff --git a/drivers/net/hamradio/scc.c b/drivers/net/hamradio/scc.c index 08d079b1d..09bb422f1 100644 --- a/drivers/net/hamradio/scc.c +++ b/drivers/net/hamradio/scc.c @@ -1,7 +1,7 @@ #define RCS_ID "$Id: scc.c,v 1.75 1998/11/04 15:15:01 jreuter Exp jreuter $" #define VERSION "3.0" -#define BANNER "Z8530 SCC driver version "VERSION".dl1bke (experimental) by DL1BKE\n" +#define BANNER "AX.25: Z8530 SCC driver version "VERSION".dl1bke\n" /* * Please use z8530drv-utils-3.0 with this version. @@ -19,7 +19,7 @@ ******************************************************************** - Copyright (c) 1993, 1998 Joerg Reuter DL1BKE + Copyright (c) 1993, 2000 Joerg Reuter DL1BKE portions (c) 1993 Guido ten Dolle PE1NNZ @@ -104,6 +104,9 @@ flags that aren't... Restarting the DPLL does not help either, it resynchronizes too slow and the first received frame gets lost. + 2000-02-13 Fixed for new network driver interface changes, still + does TX timeouts itself since it uses its own queue + scheme. Thanks to all who contributed to this driver with ideas and bug reports! @@ -236,9 +239,6 @@ static unsigned char Driver_Initialized = 0; static int Nchips = 0; static io_port Vector_Latch = 0; -MODULE_AUTHOR("Joerg Reuter "); -MODULE_DESCRIPTION("Network Device Driver for Z8530 based HDLC cards for Amateur Packet Radio"); -MODULE_SUPPORTED_DEVICE("scc"); /* ******************************************************************** */ /* * Port Access Functions * */ @@ -314,17 +314,6 @@ static inline void scc_sti(int irq) /* * Some useful macros * */ /* ******************************************************************** */ - -static inline void scc_lock_dev(struct scc_channel *scc) -{ - netif_stop_queue(scc->dev); -} - -static inline void scc_unlock_dev(struct scc_channel *scc) -{ - netif_wake_queue(scc->dev); -} - static inline void scc_discard_buffers(struct scc_channel *scc) { unsigned long flags; @@ -382,7 +371,7 @@ static inline void flush_rx_FIFO(struct scc_channel *scc) if(scc->rx_buff != NULL) /* did we receive something? */ { scc->stat.rxerrs++; /* then count it as an error */ - kfree_skb(scc->rx_buff); + dev_kfree_skb_irq(scc->rx_buff); scc->rx_buff = NULL; } } @@ -411,7 +400,7 @@ static inline void scc_txint(struct scc_channel *scc) { skb = skb_dequeue(&scc->tx_queue); scc->tx_buff = skb; - scc_unlock_dev(scc); + netif_wake_queue(scc->dev); if (skb == NULL) { @@ -422,7 +411,7 @@ static inline void scc_txint(struct scc_channel *scc) if (skb->len == 0) /* Paranoia... */ { - dev_kfree_skb(skb); + dev_kfree_skb_irq(skb); scc->tx_buff = NULL; scc_tx_done(scc); Outb(scc->ctrl, RES_Tx_P); @@ -448,7 +437,7 @@ static inline void scc_txint(struct scc_channel *scc) { Outb(scc->ctrl, RES_Tx_P); /* reset pending int */ cl(scc, R10, ABUNDER); /* send CRC */ - dev_kfree_skb(skb); + dev_kfree_skb_irq(skb); scc->tx_buff = NULL; scc->stat.tx_state = TXS_NEWFRAME; /* next frame... */ return; @@ -533,7 +522,7 @@ static inline void scc_exint(struct scc_channel *scc) if (scc->tx_buff != NULL) { - dev_kfree_skb(scc->tx_buff); + dev_kfree_skb_irq(scc->tx_buff); scc->tx_buff = NULL; } @@ -583,7 +572,7 @@ static inline void scc_rxint(struct scc_channel *scc) #ifdef notdef printk(KERN_DEBUG "z8530drv: oops, scc_rxint() received huge frame...\n"); #endif - kfree_skb(skb); + dev_kfree_skb_irq(skb); scc->rx_buff = NULL; Inb(scc->data); or(scc, R3, ENT_HM); @@ -613,7 +602,7 @@ static inline void scc_spint(struct scc_channel *scc) or(scc,R3,ENT_HM); /* enter hunt mode for next flag */ if (skb != NULL) - kfree_skb(skb); + dev_kfree_skb_irq(skb); scc->rx_buff = NULL; } @@ -629,7 +618,7 @@ static inline void scc_spint(struct scc_channel *scc) scc->rx_buff = NULL; scc->stat.rxframes++; } else { /* a bad frame */ - kfree_skb(skb); + dev_kfree_skb_irq(skb); scc->rx_buff = NULL; scc->stat.rxerrs++; } @@ -1112,7 +1101,7 @@ static void scc_tx_done(struct scc_channel *scc) scc_start_tx_timer(scc, t_tail, scc->kiss.tailtime); } - scc_unlock_dev(scc); + netif_wake_queue(scc->dev); } @@ -1163,7 +1152,7 @@ static void t_dwait(unsigned long channel) if (skb_queue_len(&scc->tx_queue) == 0) /* nothing to send */ { scc->stat.tx_state = TXS_IDLE; - scc_unlock_dev(scc); /* t_maxkeyup locked it. */ + netif_wake_queue(scc->dev); /* t_maxkeyup locked it. */ return; } @@ -1243,7 +1232,7 @@ static void t_tail(unsigned long channel) } scc->stat.tx_state = TXS_IDLE; - scc_unlock_dev(scc); + netif_wake_queue(scc->dev); } @@ -1257,14 +1246,13 @@ static void t_busy(unsigned long channel) struct scc_channel *scc = (struct scc_channel *) channel; del_timer(&scc->tx_t); - scc_lock_dev(scc); + netif_stop_queue(scc->dev); /* don't pile on the wabbit! */ scc_discard_buffers(scc); - scc->stat.txerrs++; scc->stat.tx_state = TXS_IDLE; - - scc_unlock_dev(scc); + + netif_wake_queue(scc->dev); } /* MAXKEYUP timeout @@ -1285,7 +1273,7 @@ static void t_maxkeyup(unsigned long channel) * accept new data. */ - scc_lock_dev(scc); + netif_stop_queue(scc->dev); scc_discard_buffers(scc); del_timer(&scc->tx_t); @@ -1460,8 +1448,7 @@ static void scc_stop_calibrate(unsigned long channel) Outb(scc->ctrl,RES_EXT_INT); /* reset ext/status interrupts */ Outb(scc->ctrl,RES_EXT_INT); - scc_unlock_dev(scc); - + netif_wake_queue(scc->dev); restore_flags(flags); } @@ -1474,7 +1461,7 @@ scc_start_calibrate(struct scc_channel *scc, int duration, unsigned char pattern save_flags(flags); cli(); - scc_lock_dev(scc); + netif_stop_queue(scc->dev); scc_discard_buffers(scc); del_timer(&scc->tx_wdog); @@ -1497,7 +1484,6 @@ scc_start_calibrate(struct scc_channel *scc, int duration, unsigned char pattern Outb(scc->ctrl,RES_EXT_INT); scc_key_trx(scc, TX_ON); - restore_flags(flags); } @@ -1583,7 +1569,9 @@ static int scc_net_setup(struct scc_channel *scc, unsigned char *name, int addev dev = scc->dev; memset(dev, 0, sizeof(struct net_device)); - buf = (unsigned char *) kmalloc(10, GFP_KERNEL); + if ((buf = (unsigned char *) kmalloc(10, GFP_KERNEL)) == NULL) + return -ENOMEM; + strcpy(buf, name); dev->priv = (void *) scc; @@ -1627,6 +1615,7 @@ static int scc_net_init(struct net_device *dev) dev->set_mac_address = scc_net_set_mac_address; dev->get_stats = scc_net_get_stats; dev->do_ioctl = scc_net_ioctl; + dev->tx_timeout = NULL; memcpy(dev->broadcast, ax25_bcast, AX25_ADDR_LEN); memcpy(dev->dev_addr, ax25_nocall, AX25_ADDR_LEN); @@ -1647,14 +1636,11 @@ static int scc_net_open(struct net_device *dev) { struct scc_channel *scc = (struct scc_channel *) dev->priv; - if (scc == NULL || scc->magic != SCC_MAGIC) - return -ENODEV; - if (!scc->init) return -EINVAL; MOD_INC_USE_COUNT; - + scc->tx_buff = NULL; skb_queue_head_init(&scc->tx_queue); @@ -1671,10 +1657,7 @@ static int scc_net_close(struct net_device *dev) struct scc_channel *scc = (struct scc_channel *) dev->priv; unsigned long flags; - if (scc == NULL || scc->magic != SCC_MAGIC) - return -ENODEV; - - MOD_DEC_USE_COUNT; + netif_stop_queue(dev); save_flags(flags); cli(); @@ -1690,7 +1673,7 @@ static int scc_net_close(struct net_device *dev) scc_discard_buffers(scc); - netif_stop_queue(dev); + MOD_DEC_USE_COUNT; return 0; } @@ -1700,7 +1683,7 @@ static void scc_net_rx(struct scc_channel *scc, struct sk_buff *skb) { if (skb->len == 0) { - kfree_skb(skb); + dev_kfree_skb_irq(skb); return; } @@ -1722,12 +1705,6 @@ static int scc_net_tx(struct sk_buff *skb, struct net_device *dev) struct scc_channel *scc = (struct scc_channel *) dev->priv; unsigned long flags; char kisscmd; - - if (scc == NULL || scc->magic != SCC_MAGIC) - { - dev_kfree_skb(skb); - return 0; - } if (skb->len > scc->stat.bufsize || skb->len < 2) { @@ -1749,18 +1726,18 @@ static int scc_net_tx(struct sk_buff *skb, struct net_device *dev) return 0; } - save_flags(flags); + save_flags(flags); cli(); if (skb_queue_len(&scc->tx_queue) > scc->dev->tx_queue_len) { struct sk_buff *skb_del; - skb_del = __skb_dequeue(&scc->tx_queue); + skb_del = skb_dequeue(&scc->tx_queue); dev_kfree_skb(skb_del); } - __skb_queue_tail(&scc->tx_queue, skb); - + skb_queue_tail(&scc->tx_queue, skb); dev->trans_start = jiffies; + /* * Start transmission if the trx state is idle or @@ -1777,8 +1754,7 @@ static int scc_net_tx(struct sk_buff *skb, struct net_device *dev) scc_start_tx_timer(scc, t_dwait, 0); } - restore_flags(flags); - + restore_flags(flags); return 0; } @@ -1807,9 +1783,6 @@ static int scc_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) struct scc_channel *scc; scc = (struct scc_channel *) dev->priv; - if (scc == NULL || scc->magic != SCC_MAGIC) - return -EINVAL; - arg = (void *) ifr->ifr_data; if (!Driver_Initialized) @@ -2048,9 +2021,6 @@ static struct net_device_stats *scc_net_get_stats(struct net_device *dev) { struct scc_channel *scc = (struct scc_channel *) dev->priv; - if (scc == NULL || scc->magic != SCC_MAGIC) - return NULL; - scc->dev_stat.rx_errors = scc->stat.rxerrs + scc->stat.rx_over; scc->dev_stat.tx_errors = scc->stat.txerrs + scc->stat.tx_under; scc->dev_stat.rx_fifo_errors = scc->stat.rx_over; @@ -2182,7 +2152,7 @@ done: /* * Init SCC driver * */ /* ******************************************************************** */ -int __init scc_init (void) +static int __init scc_init_driver (void) { int chip, chan, k, result; char devname[10]; @@ -2218,25 +2188,7 @@ int __init scc_init (void) return 0; } -/* ******************************************************************** */ -/* * Module support * */ -/* ******************************************************************** */ - - -#ifdef MODULE -int init_module(void) -{ - int result = 0; - - result = scc_init(); - - if (result == 0) - printk(KERN_INFO "Copyright 1993,1998 Joerg Reuter DL1BKE (jreuter@poboxes.com)\n"); - - return result; -} - -void cleanup_module(void) +static void __exit scc_cleanup_driver(void) { long flags; io_port ctrl; @@ -2279,4 +2231,9 @@ void cleanup_module(void) scc_net_procfs_remove(); } -#endif + +MODULE_AUTHOR("Joerg Reuter "); +MODULE_DESCRIPTION("AX.25 Device Driver for Z8530 based HDLC cards"); +MODULE_SUPPORTED_DEVICE("scc"); +module_init(scc_init_driver); +module_exit(scc_cleanup_driver); diff --git a/drivers/net/pcmcia/3c589_cs.c b/drivers/net/pcmcia/3c589_cs.c index 60ec6ebe7..d593c6fac 100644 --- a/drivers/net/pcmcia/3c589_cs.c +++ b/drivers/net/pcmcia/3c589_cs.c @@ -805,8 +805,6 @@ static void el3_interrupt(int irq, void *dev_id, struct pt_regs *regs) /* There's room in the FIFO for a full-sized packet. */ outw(AckIntr | TxAvailable, ioaddr + EL3_CMD); netif_wake_queue (dev); - } else { - netif_stop_queue (dev); } if (status & TxComplete) diff --git a/drivers/net/rtl8129.c b/drivers/net/rtl8129.c index d284df6f6..c0efbf4c0 100644 --- a/drivers/net/rtl8129.c +++ b/drivers/net/rtl8129.c @@ -240,7 +240,7 @@ enum CSCRBits { CSCR_LinkStatusBits=0x0f000, CSCR_LinkDownOffCmd=0x003c0, CSCR_LinkDownCmd=0x0f3c0, }; -unsigned long param[4][4]={ +static const unsigned long param[4][4]={ {0x0cb39de43,0x0cb39ce43,0x0fb38de03,0x0cb38de43}, {0x0cb39de43,0x0cb39ce43,0x0cb39ce83,0x0cb39ce83}, {0x0cb39de43,0x0cb39ce43,0x0cb39ce83,0x0cb39ce83}, diff --git a/drivers/net/setup.c b/drivers/net/setup.c index 29a63e1aa..472b23a8c 100644 --- a/drivers/net/setup.c +++ b/drivers/net/setup.c @@ -15,9 +15,7 @@ extern int strip_init_ctrl_dev(void); extern int x25_asy_init_ctrl_dev(void); extern int slhc_install(void); -extern int bpq_init(void); extern int dmascc_init(void); -extern int scc_init(void); extern int yam_init(void); extern int awc4500_pci_probe(void); @@ -59,15 +57,9 @@ struct net_probe pci_probes[] __initdata = { * Early setup devices */ -#if defined(CONFIG_SCC) - {scc_init, 0}, -#endif #if defined(CONFIG_DMASCC) {dmascc_init, 0}, #endif -#if defined(CONFIG_BPQETHER) - {bpq_init, 0}, -#endif #if defined(CONFIG_DLCI) {dlci_setup, 0}, #endif diff --git a/drivers/net/tulip.c b/drivers/net/tulip.c index cf9b4e47d..eca5ce247 100644 --- a/drivers/net/tulip.c +++ b/drivers/net/tulip.c @@ -1,140 +1,53 @@ /* tulip.c: A DEC 21040-family ethernet driver for Linux. */ /* - Written 1994-1998 by Donald Becker. + Copyright 2000 The Linux Kernel Team + Written/copyright 1994-1999 by Donald Becker. This software may be used and distributed according to the terms of the GNU Public License, incorporated herein by reference. - This driver is for the Digital "Tulip" ethernet adapter interface. + This driver is for the Digital "Tulip" Ethernet adapter interface. It should work with most DEC 21*4*-based chips/ethercards, as well as - PNIC and MXIC chips. + with work-alike chips from Lite-On (PNIC) and Macronix (MXIC) and ASIX. The author may be reached as becker@CESDIS.gsfc.nasa.gov, or C/O Center of Excellence in Space Data and Information Sciences Code 930.5, Goddard Space Flight Center, Greenbelt MD 20771 - Support and updates available at + Additional information available at http://cesdis.gsfc.nasa.gov/linux/drivers/tulip.html -*/ - -#define SMP_CHECK -static const char version[] = "tulip.c:v0.89H 5/23/98 becker@cesdis.gsfc.nasa.gov\n"; - -/* A few user-configurable values. */ - -/* Maximum events (Rx packets, etc.) to handle at each interrupt. */ -static int max_interrupt_work = 25; - -#define MAX_UNITS 8 -/* Used to pass the full-duplex flag, etc. */ -static int full_duplex[MAX_UNITS] = {0, }; -static int options[MAX_UNITS] = {0, }; -static int mtu[MAX_UNITS] = {0, }; /* Jumbo MTU for interfaces. */ - -/* The possible media types that can be set in options[] are: */ -static const char * const medianame[] = { - "10baseT", "10base2", "AUI", "100baseTx", - "10baseT-FD", "100baseTx-FD", "100baseT4", "100baseFx", - "100baseFx-FD", "MII 10baseT", "MII 10baseT-FD", "MII", - "10baseT(forced)", "MII 100baseTx", "MII 100baseTx-FD", "MII 100baseT4", -}; - -/* Set if the PCI BIOS detects the chips on a multiport board backwards. */ -#ifdef REVERSE_PROBE_ORDER -static int reverse_probe = 1; -#else -static int reverse_probe = 0; -#endif - -/* Keep the ring sizes a power of two for efficiency. - Making the Tx ring too large decreases the effectiveness of channel - bonding and packet priority. - There are no ill effects from too-large receive rings. */ -#define TX_RING_SIZE 16 -#define RX_RING_SIZE 32 - -/* Set the copy breakpoint for the copy-only-tiny-buffer Rx structure. */ -#ifdef __alpha__ -static int rx_copybreak = 1518; -#else -static int rx_copybreak = 100; -#endif - -/* Operational parameters that usually are not changed. */ -/* Time in jiffies before concluding the transmitter is hung. */ -#define TX_TIMEOUT (4*HZ) - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include /* Processor type for cache alignment. */ -#include -#include -#include - -#include -#include -#include - -/* Kernel compatibility defines, common to David Hind's PCMCIA package. - This is only in the support-all-kernels source code. */ -#include /* Evil, but neccessary */ - -#define RUN_AT(x) (jiffies + (x)) -#define DEV_ALLOC_SKB(len) dev_alloc_skb(len + 2) - -#define NEW_MULTICAST -#include - -#ifdef SA_SHIRQ -#define IRQ(irq, dev_id, pt_regs) (irq, dev_id, pt_regs) -#else -#define IRQ(irq, dev_id, pt_regs) (irq, pt_regs) -#endif - -/* The total size is unusually large: The 21040 aligns each of its 16 - longword-wide registers on a quadword boundary. */ -#define TULIP_TOTAL_SIZE 0x80 - -#ifdef HAVE_DEVLIST -struct netdev_entry tulip_drv = -{"Tulip", tulip_pci_probe, TULIP_TOTAL_SIZE, NULL}; -#endif + + For this specific driver variant please use linux-kernel for + bug reports. -#ifdef TULIP_DEBUG -int tulip_debug = TULIP_DEBUG; -#else -int tulip_debug = 1; -#endif -/* Theory of Operation I. Board Compatibility This device driver is designed for the DECchip "Tulip", Digital's single-chip ethernet controllers for PCI. Supported members of the family -are the 21040, 21041, 21140, 21140A, 21142, and 21143. These chips are used on -many PCI boards including the SMC EtherPower series. +are the 21040, 21041, 21140, 21140A, 21142, and 21143. Similar work-alike +chips from Lite-On, Macronics, ASIX, Compex and other listed below are also +supported. +These chips are used on at least 140 unique PCI board designs. The great +number of chips and board designs supported is the reason for the +driver size and complexity. Almost of the increasing complexity is in the +board configuration and media selection code. There is very little +increasing in the operational critical path length. II. Board-specific settings PCI bus devices are configured by the system at boot time, so no jumpers need to be set on the board. The system BIOS preferably should assign the PCI INTA signal to an otherwise unused system IRQ line. -Note: Kernel versions earlier than 1.3.73 do not support shared PCI -interrupt lines. + +Some boards have EEPROMs tables with default media entry. The factory default +is usually "autoselect". This should only be overridden when using +transceiver connections without link beat e.g. 10base2 or AUI, or (rarely!) +for forcing full-duplex when used with old link partners that do not do +autonegotiation. III. Driver operation @@ -182,111 +95,261 @@ tx_full and tbusy flags. IV. Notes -Thanks to Duke Kamstra of SMC for providing an EtherPower board. +Thanks to Duke Kamstra of SMC for long ago providing an EtherPower board. +Greg LaPolla at Linksys provided PNIC and other Linksys boards. +Znyx provided a four-port card for testing. IVb. References http://cesdis.gsfc.nasa.gov/linux/misc/NWay.html http://www.digital.com (search for current 21*4* datasheets and "21X4 SROM") -http://www.national.com/pf/DP/DP83840.html +http://www.national.com/pf/DP/DP83840A.html +http://www.asix.com.tw/pmac.htm +http://www.admtek.com.tw/ IVc. Errata -The DEC databook doesn't document which Rx filter settings accept broadcast -packets. Nor does it document how to configure the part to configure the -serial subsystem for normal (vs. loopback) operation or how to have it -autoswitch between internal 10baseT, SIA and AUI transceivers. - +The old DEC databooks were light on details. The 21040 databook claims that CSR13, CSR14, and CSR15 should each be the last -register of the set CSR12-15 written. Hmmm, now how is that possible? */ +register of the set CSR12-15 written. Hmmm, now how is that possible? +The DEC SROM format is very badly designed not precisely defined, leading to +part of the media selection junkheap below. Some boards do not have EEPROM +media tables and need to be patched up. Worse, other boards use the DEC +design kit media table when it isn't correct for their board. -/* A few values that may be tweaked. */ -#define PKT_BUF_SZ 1536 /* Size of each temporary Rx buffer.*/ +We cannot use MII interrupts because there is no defined GPIO pin to attach +them. The MII transceiver status is polled using an kernel timer. + +*/ + +static const char version[] = "Linux Tulip driver version 0.9.2 (Feb 15, 2000)\n"; + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include /* Processor type for cache alignment. */ +#include +#include +#include + + + +/* A few user-configurable values. */ + +/* Maximum events (Rx packets, etc.) to handle at each interrupt. */ +static int max_interrupt_work = 25; + +#define MAX_UNITS 8 +/* Used to pass the full-duplex flag, etc. */ +static int full_duplex[MAX_UNITS] = {0, }; +static int options[MAX_UNITS] = {0, }; +static int mtu[MAX_UNITS] = {0, }; /* Jumbo MTU for interfaces. */ + +/* The possible media types that can be set in options[] are: */ +static const char * const medianame[] = { + "10baseT", "10base2", "AUI", "100baseTx", + "10baseT-FD", "100baseTx-FD", "100baseT4", "100baseFx", + "100baseFx-FD", "MII 10baseT", "MII 10baseT-FD", "MII", + "10baseT(forced)", "MII 100baseTx", "MII 100baseTx-FD", "MII 100baseT4", +}; + +/* Set if the PCI BIOS detects the chips on a multiport board backwards. */ +#ifdef REVERSE_PROBE_ORDER +static int reverse_probe = 1; +#else +static int reverse_probe = 0; +#endif + +/* Keep the ring sizes a power of two for efficiency. + Making the Tx ring too large decreases the effectiveness of channel + bonding and packet priority. + There are no ill effects from too-large receive rings. */ +#define TX_RING_SIZE 16 +#define RX_RING_SIZE 32 + +/* Set the copy breakpoint for the copy-only-tiny-buffer Rx structure. */ +#ifdef __alpha__ +static int rx_copybreak = 1518; +#else +static int rx_copybreak = 100; +#endif + +/* + Set the bus performance register. + Typical: Set 16 longword cache alignment, no burst limit. + Cache alignment bits 15:14 Burst length 13:8 + 0000 No alignment 0x00000000 unlimited 0800 8 longwords + 4000 8 longwords 0100 1 longword 1000 16 longwords + 8000 16 longwords 0200 2 longwords 2000 32 longwords + C000 32 longwords 0400 4 longwords + Warning: many older 486 systems are broken and require setting 0x00A04800 + 8 longword cache alignment, 8 longword burst. + ToDo: Non-Intel setting could be better. +*/ + +#if defined(__alpha__) +static int csr0 = 0x01A00000 | 0xE000; +#elif defined(__i386__) || defined(__powerpc__) || defined(__sparc__) +static int csr0 = 0x01A00000 | 0x8000; +#else +#warning Processor architecture undefined! +static int csr0 = 0x00A00000 | 0x4800; +#endif +/* Operational parameters that usually are not changed. */ +/* Time in jiffies before concluding the transmitter is hung. */ +#define TX_TIMEOUT (4*HZ) +#define PKT_BUF_SZ 1536 /* Size of each temporary Rx buffer.*/ /* This is a mysterious value that can be written to CSR11 in the 21040 (only) to support a pre-NWay full-duplex signaling mechanism using short frames. No one knows what it should be, but if left at its default value some 10base2(!) packets trigger a full-duplex-request interrupt. */ #define FULL_DUPLEX_MAGIC 0x6969 -#ifndef PCI_VENDOR_ID_DEC /* Now defined in linux/pci.h */ -#define PCI_VENDOR_ID_DEC 0x1011 -#define PCI_DEVICE_ID_TULIP 0x0002 /* 21040. */ -#define PCI_DEVICE_ID_TULIP_FAST 0x0009 /* 21140. */ -#endif -#ifndef PCI_DEVICE_ID_DEC_TULIP_PLUS -#define PCI_DEVICE_ID_DEC_TULIP_PLUS 0x0014 /* 21041. */ -#endif -#ifndef PCI_DEVICE_ID_DEC_TULIP_21142 -#define PCI_DEVICE_ID_DEC_TULIP_21142 0x0019 -#endif +/* Kernel compatibility defines, some common to David Hind's PCMCIA package. + This is only in the support-all-kernels source code. */ -#ifndef PCI_VENDOR_ID_LITEON -#define PCI_VENDOR_ID_LITEON 0x11AD -#endif +MODULE_AUTHOR("Donald Becker "); +MODULE_DESCRIPTION("Digital 21*4* Tulip ethernet driver"); +MODULE_PARM(debug, "i"); +MODULE_PARM(max_interrupt_work, "i"); +MODULE_PARM(reverse_probe, "i"); +MODULE_PARM(rx_copybreak, "i"); +MODULE_PARM(csr0, "i"); +MODULE_PARM(options, "1-" __MODULE_STRING(MAX_UNITS) "i"); +MODULE_PARM(full_duplex, "1-" __MODULE_STRING(MAX_UNITS) "i"); + +#define TULIP_MODULE_NAME "tulip" +#define PFX TULIP_MODULE_NAME ": " -#ifndef PCI_VENDOR_ID_MXIC -#define PCI_VENDOR_ID_MXIC 0x10d9 -#define PCI_DEVICE_ID_MX98713 0x0512 -#define PCI_DEVICE_ID_MX98715 0x0531 -#define PCI_DEVICE_ID_MX98725 0x0531 +#define RUN_AT(x) (jiffies + (x)) + +/* Condensed operations for readability. */ +#define virt_to_le32desc(addr) cpu_to_le32(virt_to_bus(addr)) +#define le32desc_to_virt(addr) bus_to_virt(le32_to_cpu(addr)) + +#define tulip_debug debug +#ifdef TULIP_DEBUG +static int tulip_debug = TULIP_DEBUG; +#else +static int tulip_debug = 1; #endif -/* The rest of these values should never change. */ + + +/* This table use during operation for capabilities and media timer. */ static void tulip_timer(unsigned long data); static void t21142_timer(unsigned long data); static void mxic_timer(unsigned long data); static void pnic_timer(unsigned long data); +static void comet_timer(unsigned long data); -/* A table describing the chip types. */ -enum tbl_flag { HAS_MII=1, HAS_MEDIA_TABLE = 2, CSR12_IN_SROM = 4,}; +enum tbl_flag { + HAS_MII=1, HAS_MEDIA_TABLE=2, CSR12_IN_SROM=4, ALWAYS_CHECK_MII=8, + HAS_PWRDWN=0x10, MC_HASH_ONLY=0x20, /* Hash-only multicast filter. */ + HAS_PNICNWAY=0x80, HAS_NWAY143=0x40, /* Uses internal NWay xcvr. */ + HAS_8023X=0x100, +}; static struct tulip_chip_table { - int vendor_id, device_id; char *chip_name; int io_size; int valid_intrs; /* CSR7 interrupt enable settings */ int flags; void (*media_timer)(unsigned long data); } tulip_tbl[] = { - { PCI_VENDOR_ID_DEC, PCI_DEVICE_ID_DEC_TULIP, - "Digital DC21040 Tulip", 128, 0x0001ebef, 0, tulip_timer }, - { PCI_VENDOR_ID_DEC, PCI_DEVICE_ID_DEC_TULIP_PLUS, - "Digital DC21041 Tulip", 128, 0x0001ebef, HAS_MEDIA_TABLE, tulip_timer }, - { PCI_VENDOR_ID_DEC, PCI_DEVICE_ID_DEC_TULIP_FAST, - "Digital DS21140 Tulip", 128, 0x0001ebef, - HAS_MII | HAS_MEDIA_TABLE | CSR12_IN_SROM, - tulip_timer }, - { PCI_VENDOR_ID_DEC, PCI_DEVICE_ID_DEC_TULIP_21142, - "Digital DS21142/3 Tulip", 128, 0x0801fbff, - HAS_MII | HAS_MEDIA_TABLE, t21142_timer }, - { PCI_VENDOR_ID_LITEON, 0x0002, - "Lite-On 82c168 PNIC", 256, 0x0001ebef, HAS_MII, pnic_timer }, - { PCI_VENDOR_ID_MXIC, PCI_DEVICE_ID_MX98713, - "Macronix 98713 PMAC", 128, 0x0001ebef, - HAS_MII | HAS_MEDIA_TABLE | CSR12_IN_SROM, tulip_timer /* Tulip-like! */ }, - { PCI_VENDOR_ID_MXIC, PCI_DEVICE_ID_MX98715, - "Macronix 98715 PMAC", 256, 0x0001ebef, HAS_MEDIA_TABLE, mxic_timer }, - { PCI_VENDOR_ID_MXIC, PCI_DEVICE_ID_MX98725, - "Macronix 98725 PMAC", 256, 0x0001ebef, HAS_MEDIA_TABLE, mxic_timer }, - { 0x125B, 0x1400, "ASIX AX88140", 128, 0x0001fbff, + { "Digital DC21040 Tulip", 128, 0x0001ebef, 0, tulip_timer }, + { "Digital DC21041 Tulip", 128, 0x0001ebff, HAS_MEDIA_TABLE, tulip_timer }, + { "Digital DS21140 Tulip", 128, 0x0001ebef, HAS_MII | HAS_MEDIA_TABLE | CSR12_IN_SROM, tulip_timer }, - {0, 0, 0, 0}, + { "Digital DS21143 Tulip", 128, 0x0801fbff, + HAS_MII | HAS_MEDIA_TABLE | ALWAYS_CHECK_MII | HAS_PWRDWN | HAS_NWAY143, + t21142_timer }, + { "Lite-On 82c168 PNIC", 256, 0x0001ebef, + HAS_MII | HAS_PNICNWAY, pnic_timer }, + { "Macronix 98713 PMAC", 128, 0x0001ebef, + HAS_MII | HAS_MEDIA_TABLE | CSR12_IN_SROM, mxic_timer }, + { "Macronix 98715 PMAC", 256, 0x0001ebef, + HAS_MEDIA_TABLE, mxic_timer }, + { "Macronix 98725 PMAC", 256, 0x0001ebef, + HAS_MEDIA_TABLE, mxic_timer }, + { "ASIX AX88140", 128, 0x0001fbff, + HAS_MII | HAS_MEDIA_TABLE | CSR12_IN_SROM | MC_HASH_ONLY, tulip_timer }, + { "Lite-On PNIC-II", 256, 0x0801fbff, + HAS_MII | HAS_NWAY143 | HAS_8023X, t21142_timer }, + { "ADMtek Comet", 256, 0x0001abef, + MC_HASH_ONLY, comet_timer }, + { "Compex 9881 PMAC", 128, 0x0001ebef, + HAS_MII | HAS_MEDIA_TABLE | CSR12_IN_SROM, mxic_timer }, + { "Intel DS21145 Tulip", 128, 0x0801fbff, + HAS_MII | HAS_MEDIA_TABLE | ALWAYS_CHECK_MII | HAS_PWRDWN | HAS_NWAY143, + t21142_timer }, + { "Xircom tulip work-alike", 128, 0x0801fbff, + HAS_MII | HAS_MEDIA_TABLE | ALWAYS_CHECK_MII | HAS_PWRDWN | HAS_NWAY143, + t21142_timer }, + {0}, }; -/* This matches the table above. */ -enum chips { DC21040=0, DC21041=1, DC21140=2, DC21142=3, DC21143=3, - LC82C168, MX98713, MX98715, MX98725}; +/* This matches the table above. Note 21142 == 21143. */ +enum chips { + DC21040=0, + DC21041=1, + DC21140=2, + DC21142=3, DC21143=3, + LC82C168, + MX98713, + MX98715, + MX98725, + AX88140, + PNIC2, + COMET, + COMPEX9881, + I21145, + XIRCLONE, +}; + + +static struct pci_device_id tulip_pci_tbl[] __devinitdata = { + { 0x1011, 0x0002, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DC21040 }, + { 0x1011, 0x0014, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DC21041 }, + { 0x1011, 0x0009, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DC21140 }, + { 0x1011, 0x0019, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DC21143 }, + { 0x11AD, 0x0002, PCI_ANY_ID, PCI_ANY_ID, 0, 0, LC82C168 }, + { 0x10d9, 0x0512, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MX98713 }, + { 0x10d9, 0x0531, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MX98715 }, + { 0x10d9, 0x0531, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MX98725 }, + { 0x125B, 0x1400, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AX88140 }, + { 0x11AD, 0xc115, PCI_ANY_ID, PCI_ANY_ID, 0, 0, PNIC2 }, + { 0x1317, 0x0981, PCI_ANY_ID, PCI_ANY_ID, 0, 0, COMET }, + { 0x11F6, 0x9881, PCI_ANY_ID, PCI_ANY_ID, 0, 0, COMPEX9881 }, + { 0x8086, 0x0039, PCI_ANY_ID, PCI_ANY_ID, 0, 0, I21145 }, + { 0x115d, 0x0003, PCI_ANY_ID, PCI_ANY_ID, 0, 0, XIRCLONE }, + {0}, +}; +MODULE_DEVICE_TABLE(pci,tulip_pci_tbl); + /* A full-duplex map for media types. */ -enum MediaIs {MediaIsFD = 1, MediaAlwaysFD=2, MediaIsMII=4, MediaIsFx=8, - MediaIs100=16}; +enum MediaIs { + MediaIsFD = 1, MediaAlwaysFD=2, MediaIsMII=4, MediaIsFx=8, + MediaIs100=16}; static const char media_cap[] = {0,0,0,16, 3,19,16,24, 27,4,7,5, 0,20,23,20 }; +static u8 t21040_csr13[] = {2,0x0C,8,4, 4,0,0,0, 0,0,0,0, 4,0,0,0}; /* 21041 transceiver register settings: 10-T, 10-2, AUI, 10-T, 10T-FD*/ -static u16 t21041_csr13[] = { 0xEF05, 0xEF09, 0xEF09, 0xEF01, 0xEF09, }; -static u16 t21041_csr14[] = { 0x7F3F, 0xF7FD, 0xF7FD, 0x7F3F, 0x7F3D, }; +static u16 t21041_csr13[] = { 0xEF01, 0xEF09, 0xEF09, 0xEF01, 0xEF09, }; +static u16 t21041_csr14[] = { 0xFFFF, 0xF7FD, 0xF7FD, 0x7F3F, 0x7F3D, }; static u16 t21041_csr15[] = { 0x0008, 0x0006, 0x000E, 0x0008, 0x0008, }; static u16 t21142_csr13[] = { 0x0001, 0x0009, 0x0009, 0x0000, 0x0001, }; @@ -302,16 +365,12 @@ enum tulip_offsets { /* The bits in the CSR5 status registers, mostly interrupt sources. */ enum status_bits { - TimerInt=0x800, TPLnkFail=0x1000, TPLnkPass=0x10, + TimerInt=0x800, SytemError=0x2000, TPLnkFail=0x1000, TPLnkPass=0x10, NormalIntr=0x10000, AbnormalIntr=0x8000, RxJabber=0x200, RxDied=0x100, RxNoBuf=0x80, RxIntr=0x40, TxFIFOUnderflow=0x20, TxJabber=0x08, TxNoBuf=0x04, TxDied=0x02, TxIntr=0x01, }; -enum desc_status_bits { - DescOwned=0x80000000, RxDescFatalErr=0x8000, RxWholePkt=0x0300, -}; - /* The Tulip Rx and Tx buffer descriptors. */ struct tulip_rx_desc { s32 status; @@ -325,6 +384,22 @@ struct tulip_tx_desc { u32 buffer1, buffer2; /* We use only buffer 1. */ }; +enum desc_status_bits { + DescOwned=0x80000000, RxDescFatalErr=0x8000, RxWholePkt=0x0300, +}; + +/* Ring-wrap flag in length field, use for last ring entry. + 0x01000000 means chain on buffer2 address, + 0x02000000 means use the ring start address in CSR2/3. + Note: Some work-alike chips do not function correctly in chained mode. + The ASIX chip works only in chained mode. + Thus we indicates ring mode, but always write the 'next' field for + chained mode as well. +*/ +#define DESC_RING_WRAP 0x02000000 + +#define EEPROM_SIZE 128 /* 2 << EEPROM_ADDRLEN */ + struct medialeaf { u8 type; u8 media; @@ -334,7 +409,8 @@ struct medialeaf { struct mediatable { u16 defaultmedia; u8 leafcount, csr12dir; /* General purpose pin directions. */ - unsigned has_mii:1, has_nonmii:1; + unsigned has_mii:1, has_nonmii:1, has_reset:6; + u32 csr15dir, csr15val; /* 21143 NWay setting. */ struct medialeaf mleaf[0]; }; @@ -356,12 +432,13 @@ struct tulip_private { /* The addresses of receive-in-place skbuffs. */ struct sk_buff* rx_skbuff[RX_RING_SIZE]; char *rx_buffs; /* Address of temporary Rx buffers. */ - u32 setup_frame[48]; /* Pseudo-Tx frame to init address table. */ + u16 setup_frame[96]; /* Pseudo-Tx frame to init address table. */ int chip_id; int revision; + int flags; struct net_device_stats stats; struct timer_list timer; /* Media selection timer. */ - spinlock_t tx_lock; + spinlock_t tx_lock; unsigned int cur_rx, cur_tx; /* The next free ring entry */ unsigned int dirty_rx, dirty_tx; /* The ring entries to be free()ed. */ unsigned int tx_full:1; /* The Tx queue is full. */ @@ -372,469 +449,111 @@ struct tulip_private { unsigned int media2:4; /* Secondary monitored media port. */ unsigned int medialock:1; /* Don't sense media type. */ unsigned int mediasense:1; /* Media sensing in progress. */ + unsigned int nway:1, nwayset:1; /* 21143 internal NWay. */ + unsigned int csr0; /* CSR0 setting. */ unsigned int csr6; /* Current CSR6 control settings. */ - unsigned char eeprom[128]; /* Serial EEPROM contents. */ + unsigned char eeprom[EEPROM_SIZE]; /* Serial EEPROM contents. */ + void (*link_change)(struct net_device *dev, int csr5); u16 to_advertise; /* NWay capabilities advertised. */ + u16 lpar; /* 21143 Link partner ability. */ u16 advertising[4]; signed char phys[4], mii_cnt; /* MII device addresses. */ struct mediatable *mtable; int cur_index; /* Current media index. */ - unsigned char pci_bus, pci_dev_fn; + int saved_if_port; + struct pci_dev *pdev; + int ttimer; + int susp_rx; + unsigned long nir; int pad0, pad1; /* Used for 8-byte alignment */ }; -static struct net_device *tulip_probe1(int pci_bus, int pci_devfn, - int chip_id, int options); static void parse_eeprom(struct net_device *dev); -static int read_eeprom(long ioaddr, int location); +static int read_eeprom(long ioaddr, int location, int addr_len); static int mdio_read(struct net_device *dev, int phy_id, int location); static void mdio_write(struct net_device *dev, int phy_id, int location, int value); static void select_media(struct net_device *dev, int startup); static int tulip_open(struct net_device *dev); -static void tulip_timer(unsigned long data); +/* Chip-specific media selection (timer functions prototyped above). */ +static void t21142_lnk_change(struct net_device *dev, int csr5); +static void t21142_start_nway(struct net_device *dev); +static void pnic_lnk_change(struct net_device *dev, int csr5); +static void pnic_do_nway(struct net_device *dev); + static void tulip_tx_timeout(struct net_device *dev); static void tulip_init_ring(struct net_device *dev); static int tulip_start_xmit(struct sk_buff *skb, struct net_device *dev); +static int tulip_refill_rx(struct net_device *dev); static int tulip_rx(struct net_device *dev); -static void tulip_interrupt IRQ(int irq, void *dev_instance, struct pt_regs *regs); +static void tulip_interrupt(int irq, void *dev_instance, struct pt_regs *regs); static int tulip_close(struct net_device *dev); -static struct enet_statistics *tulip_get_stats(struct net_device *dev); -#ifdef HAVE_PRIVATE_IOCTL +static struct net_device_stats *tulip_get_stats(struct net_device *dev); static int private_ioctl(struct net_device *dev, struct ifreq *rq, int cmd); -#endif -#ifdef NEW_MULTICAST static void set_rx_mode(struct net_device *dev); -#else -static void set_rx_mode(struct net_device *dev, int num_addrs, void *addrs); -#endif - - -/* A list of all installed Tulip devices, for removing the driver module. */ -static struct net_device *root_tulip_dev = NULL; -/* This 21040 probe no longer uses a large fixed contiguous Rx buffer region, - but now receives directly into full-sized skbuffs that are allocated - at open() time. - This allows the probe routine to use the old driver initialization - interface. */ - -static int __init tulip_probe(void) -{ - int cards_found = 0; - static int pci_index = 0; /* Static, for multiple probe calls. */ - unsigned char pci_bus, pci_device_fn; - - /* Ideally we would detect all network cards in slot order. That would - be best done a central PCI probe dispatch, which wouldn't work - well with the current structure. So instead we detect just the - Tulip cards in slot order. */ - - if (! pci_present()) - return -ENODEV; - for (;pci_index < 0xff; pci_index++) { - u16 vendor, device, pci_command, new_command; - unsigned long pci_ioaddr = 0; - int chip_idx = 0; - struct pci_dev *pdev; - - if (pcibios_find_class - (PCI_CLASS_NETWORK_ETHERNET << 8, - reverse_probe ? 0xfe - pci_index : pci_index, - &pci_bus, &pci_device_fn) != PCIBIOS_SUCCESSFUL) - { - if (reverse_probe) - continue; - else - break; - } - - pdev = pci_find_slot (pci_bus, pci_device_fn); - vendor = pdev->vendor; - device = pdev->device; - - for (chip_idx = 0; tulip_tbl[chip_idx].chip_name; chip_idx++) - if (vendor == tulip_tbl[chip_idx].vendor_id && - device == tulip_tbl[chip_idx].device_id) - break; - if (tulip_tbl[chip_idx].chip_name == 0) { - if (vendor == PCI_VENDOR_ID_DEC || - vendor == PCI_VENDOR_ID_LITEON) - printk(KERN_INFO "Unknown Tulip-style PCI ethernet chip type" - " %4.4x %4.4x"" detected: not configured.\n", - vendor, device); - continue; - } - pci_ioaddr = pci_find_slot(pci_bus, pci_device_fn)->resource[0].start; - /* Remove I/O space marker in bit 0. */ - pci_ioaddr &= ~3; +/* Serial EEPROM section. */ +/* The main routine to parse the very complicated SROM structure. + Search www.digital.com for "21X4 SROM" to get details. + This code is very complex, and will require changes to support + additional cards, so I'll be verbose about what is going on. + */ - if (tulip_debug > 2) - printk(KERN_DEBUG "Found %s at I/O %#lx.\n", - tulip_tbl[chip_idx].chip_name, pci_ioaddr); - - if (check_region(pci_ioaddr, tulip_tbl[chip_idx].io_size)) - continue; - - pci_read_config_word(pdev, PCI_COMMAND, &pci_command); - new_command = pci_command | PCI_COMMAND_MASTER|PCI_COMMAND_IO; - if (pci_command != new_command) { - printk(KERN_INFO " The PCI BIOS has not enabled this" - " device! Updating PCI command %4.4x->%4.4x.\n", - pci_command, new_command); - pci_write_config_word(pdev, PCI_COMMAND, new_command); - } +/* Known cards that have old-style EEPROMs. */ +static struct fixups { + char *name; + unsigned char addr0, addr1, addr2; + u16 newtable[32]; /* Max length below. */ +} eeprom_fixups[] = { + {"Asante", 0, 0, 0x94, {0x1e00, 0x0000, 0x0800, 0x0100, 0x018c, + 0x0000, 0x0000, 0xe078, 0x0001, 0x0050, 0x0018 }}, + {"SMC9332DST", 0, 0, 0xC0, { 0x1e00, 0x0000, 0x0800, 0x041f, + 0x0000, 0x009E, /* 10baseT */ + 0x0004, 0x009E, /* 10baseT-FD */ + 0x0903, 0x006D, /* 100baseTx */ + 0x0905, 0x006D, /* 100baseTx-FD */ }}, + {"Cogent EM100", 0, 0, 0x92, { 0x1e00, 0x0000, 0x0800, 0x063f, + 0x0107, 0x8021, /* 100baseFx */ + 0x0108, 0x8021, /* 100baseFx-FD */ + 0x0100, 0x009E, /* 10baseT */ + 0x0104, 0x009E, /* 10baseT-FD */ + 0x0103, 0x006D, /* 100baseTx */ + 0x0105, 0x006D, /* 100baseTx-FD */ }}, + {"Maxtech NX-110", 0, 0, 0xE8, { 0x1e00, 0x0000, 0x0800, 0x0513, + 0x1001, 0x009E, /* 10base2, CSR12 0x10*/ + 0x0000, 0x009E, /* 10baseT */ + 0x0004, 0x009E, /* 10baseT-FD */ + 0x0303, 0x006D, /* 100baseTx, CSR12 0x03 */ + 0x0305, 0x006D, /* 100baseTx-FD CSR12 0x03 */}}, + {"Accton EN1207", 0, 0, 0xE8, { 0x1e00, 0x0000, 0x0800, 0x051F, + 0x1B01, 0x0000, /* 10base2, CSR12 0x1B */ + 0x0B00, 0x009E, /* 10baseT, CSR12 0x0B */ + 0x0B04, 0x009E, /* 10baseT-FD,CSR12 0x0B */ + 0x1B03, 0x006D, /* 100baseTx, CSR12 0x1B */ + 0x1B05, 0x006D, /* 100baseTx-FD CSR12 0x1B */ + }}, + {0, 0, 0, 0, {}}}; - if(tulip_probe1(pci_bus, pci_device_fn, chip_idx, cards_found)) - { - /* Get and check the bus-master and latency values. */ - unsigned char pci_latency; - pci_read_config_byte(pdev, PCI_LATENCY_TIMER, &pci_latency); - if (pci_latency < 10) { - printk(KERN_INFO " PCI latency timer (CFLT) is " - "unreasonably low at %d. Setting to 64 clocks.\n", - pci_latency); - pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 64); - } else if (tulip_debug > 1) - printk(KERN_INFO " PCI latency timer (CFLT) is %#x, " - " PCI command is %4.4x.\n", - pci_latency, new_command); - /* Bring the 21143 out power-down mode. */ - if (device == PCI_DEVICE_ID_DEC_TULIP_21142) - pci_write_config_dword(pdev, 0x40, 0x40000000); - cards_found++; - } - } +static const char * block_name[] = {"21140 non-MII", "21140 MII PHY", + "21142 Serial PHY", "21142 MII PHY", "21143 SYM PHY", "21143 reset method"}; - return cards_found ? 0 : -ENODEV; -} +#if defined(__i386__) /* AKA get_unaligned() */ +#define get_u16(ptr) (*(u16 *)(ptr)) +#else +#define get_u16(ptr) (((u8*)(ptr))[0] + (((u8*)(ptr))[1]<<8)) +#endif -static struct net_device *tulip_probe1(int pci_bus, int pci_device_fn, - int chip_id, int board_idx) -{ - struct net_device *dev; - static int did_version = 0; /* Already printed version info. */ - struct tulip_private *tp; - long ioaddr; - int irq; - /* See note below on the multiport cards. */ - static unsigned char last_phys_addr[6] = {0x00, 'L', 'i', 'n', 'u', 'x'}; - static int last_irq = 0; - static int multiport_cnt = 0; /* For four-port boards w/one EEPROM */ - int i; - unsigned short sum; - - if (tulip_debug > 0 && did_version++ == 0) - printk(KERN_INFO "%s", version); - - dev = init_etherdev(NULL, 0); - - irq = pci_find_slot(pci_bus, pci_device_fn)->irq; - ioaddr = pci_find_slot(pci_bus, pci_device_fn)->resource[0].start; - - printk(KERN_INFO "%s: %s at %#3lx,", - dev->name, tulip_tbl[chip_id].chip_name, ioaddr); - - /* Stop the chip's Tx and Rx processes. */ - outl(inl(ioaddr + CSR6) & ~0x2002, ioaddr + CSR6); - /* Clear the missed-packet counter. */ - (volatile int)inl(ioaddr + CSR8); - - if (chip_id == DC21041) { - if (inl(ioaddr + CSR9) & 0x8000) { - printk(" 21040 compatible mode,"); - chip_id = DC21040; - } else { - printk(" 21041 mode,"); - } - } - - /* The station address ROM is read byte serially. The register must - be polled, waiting for the value to be read bit serially from the - EEPROM. - */ - sum = 0; - if (chip_id == DC21040) { - outl(0, ioaddr + CSR9); /* Reset the pointer with a dummy write. */ - for (i = 0; i < 6; i++) { - int value, boguscnt = 100000; - do - value = inl(ioaddr + CSR9); - while (value < 0 && --boguscnt > 0); - dev->dev_addr[i] = value; - sum += value & 0xff; - } - } else if (chip_id == LC82C168) { - for (i = 0; i < 3; i++) { - int value, boguscnt = 100000; - outl(0x600 | i, ioaddr + 0x98); - do - value = inl(ioaddr + CSR9); - while (value < 0 && --boguscnt > 0); - ((u16*)dev->dev_addr)[i] = value; - sum += value & 0xffff; - } - } else { /* Must be a new chip, with a serial EEPROM interface. */ - /* We read the whole EEPROM, and sort it out later. DEC has a - specification _Digital Semiconductor 21X4 Serial ROM Format_ - but early vendor boards just put the address in the first six - EEPROM locations. */ - unsigned char ee_data[128]; - int sa_offset = 0; - - for (i = 0; i < sizeof(ee_data)/2; i++) - ((u16 *)ee_data)[i] = read_eeprom(ioaddr, i); - - /* Detect the simple EEPROM format by the duplicated station addr. */ - for (i = 0; i < 8; i ++) - if (ee_data[i] != ee_data[16+i]) - sa_offset = 20; - if (ee_data[0] == 0xff && ee_data[1] == 0xff && ee_data[2] == 0) { - sa_offset = 2; /* Grrr, damn Matrox boards. */ - multiport_cnt = 4; - } - for (i = 0; i < 6; i ++) { - dev->dev_addr[i] = ee_data[i + sa_offset]; - sum += ee_data[i + sa_offset]; - } - } - /* Lite-On boards have the address byte-swapped. */ - if (dev->dev_addr[0] == 0xA0 && dev->dev_addr[1] == 0x00) - for (i = 0; i < 6; i+=2) { - char tmp = dev->dev_addr[i]; - dev->dev_addr[i] = dev->dev_addr[i+1]; - dev->dev_addr[i+1] = tmp; - } - /* On the Zynx 315 Etherarray and other multiport boards only the - first Tulip has an EEPROM. - The addresses of the subsequent ports are derived from the first. - Many PCI BIOSes also incorrectly report the IRQ line, so we correct - that here as well. */ - if (sum == 0 || sum == 6*0xff) { - printk(" EEPROM not present,"); - for (i = 0; i < 5; i++) - dev->dev_addr[i] = last_phys_addr[i]; - dev->dev_addr[i] = last_phys_addr[i] + 1; -#if defined(__i386__) /* This BIOS bug doesn't exist on Alphas. */ - irq = last_irq; -#endif - } - - for (i = 0; i < 6; i++) - printk(" %2.2x", last_phys_addr[i] = dev->dev_addr[i]); - printk(", IRQ %d.\n", irq); - last_irq = irq; - - /* We do a request_region() only to register /proc/ioports info. */ - /* Note that proper size is tulip_tbl[chip_id].chip_name, but... */ - request_region(ioaddr, TULIP_TOTAL_SIZE, dev->name); - - dev->base_addr = ioaddr; - dev->irq = irq; - - /* Make certain the data structures are quadword aligned. */ - tp = (void *)(((long)kmalloc(sizeof(*tp), GFP_KERNEL | GFP_DMA) + 7) & ~7); - memset(tp, 0, sizeof(*tp)); - dev->priv = tp; - - tp->next_module = root_tulip_dev; - root_tulip_dev = dev; - - tp->pci_bus = pci_bus; - tp->pci_dev_fn = pci_device_fn; - tp->chip_id = chip_id; - -#ifdef TULIP_FULL_DUPLEX - tp->full_duplex = 1; - tp->full_duplex_lock = 1; -#endif -#ifdef TULIP_DEFAULT_MEDIA - tp->default_port = TULIP_DEFAULT_MEDIA; -#endif -#ifdef TULIP_NO_MEDIA_SWITCH - tp->medialock = 1; -#endif - - /* The lower four bits are the media type. */ - if (board_idx >= 0 && board_idx < MAX_UNITS) { - tp->default_port = options[board_idx] & 15; - if ((options[board_idx] & 0x90) || full_duplex[board_idx] > 0) - tp->full_duplex = 1; - if (mtu[board_idx] > 0) - dev->mtu = mtu[board_idx]; - } - if (dev->mem_start) - tp->default_port = dev->mem_start; - if (tp->default_port) { - tp->medialock = 1; - if (media_cap[tp->default_port] & MediaAlwaysFD) - tp->full_duplex = 1; - } - if (tp->full_duplex) - tp->full_duplex_lock = 1; - - /* This is logically part of probe1(), but too complex to write inline. */ - if (tulip_tbl[chip_id].flags & HAS_MEDIA_TABLE) - parse_eeprom(dev); - - if (media_cap[tp->default_port] & MediaIsMII) { - u16 media2advert[] = { 0x20, 0x40, 0x03e0, 0x60, 0x80, 0x100, 0x200 }; - tp->to_advertise = media2advert[tp->default_port - 9]; - } else - tp->to_advertise = 0x03e1; - - if ((tp->mtable && tp->mtable->has_mii) || - ( ! tp->mtable && (tulip_tbl[tp->chip_id].flags & HAS_MII))) { - int phy, phy_idx; - /* Find the connected MII xcvrs. - Doing this in open() would allow detecting external xcvrs later, - but takes much time. */ - for (phy = 0, phy_idx = 0; phy < 32 && phy_idx < sizeof(tp->phys); - phy++) { - int mii_status = mdio_read(dev, phy, 1); - if (mii_status != 0xffff && mii_status != 0x0000) { - int mii_reg0 = mdio_read(dev, phy, 0); - int reg4 = ((mii_status>>6) & tp->to_advertise) | 1; - tp->phys[phy_idx] = phy; - tp->advertising[phy_idx++] = reg4; - printk(KERN_INFO "%s: MII transceiver found at MDIO address " - "%d, config %4.4x status %4.4x.\n", - dev->name, phy, mii_reg0, mii_status); - if (1 || (media_cap[tp->default_port] & MediaIsMII)) { - printk(KERN_DEBUG "%s: Advertising %4.4x on PHY %d," - " previously advertising %4.4x.\n", - dev->name, reg4, phy, mdio_read(dev, phy, 4)); - mdio_write(dev, phy, 4, reg4); - } - /* Enable autonegotiation: some boards default to off. */ - mdio_write(dev, phy, 0, mii_reg0 | - (tp->full_duplex ? 0x1100 : 0x1000) | - (media_cap[tp->default_port]&MediaIs100 ? 0x2000:0)); - } - } - tp->mii_cnt = phy_idx; - if (tp->mtable && tp->mtable->has_mii && phy_idx == 0) { - printk(KERN_INFO "%s: ***WARNING***: No MII transceiver found!\n", - dev->name); - tp->phys[0] = 1; - } - } - - /* The Tulip-specific entries in the device structure. */ - dev->open = &tulip_open; - dev->hard_start_xmit = &tulip_start_xmit; - dev->tx_timeout = &tulip_tx_timeout; - dev->watchdog_timeo = TX_TIMEOUT; - dev->stop = &tulip_close; - dev->get_stats = &tulip_get_stats; -#ifdef HAVE_PRIVATE_IOCTL - dev->do_ioctl = &private_ioctl; -#endif -#ifdef HAVE_MULTICAST - dev->set_multicast_list = &set_rx_mode; -#endif - - /* Reset the xcvr interface and turn on heartbeat. */ - switch (chip_id) { - case DC21041: - outl(0x00000000, ioaddr + CSR13); - outl(0xFFFFFFFF, ioaddr + CSR14); - outl(0x00000008, ioaddr + CSR15); /* Listen on AUI also. */ - outl(inl(ioaddr + CSR6) | 0x0200, ioaddr + CSR6); - outl(0x0000EF05, ioaddr + CSR13); - break; - case DC21040: - outl(0x00000000, ioaddr + CSR13); - outl(0x00000004, ioaddr + CSR13); - break; - case DC21140: default: - if (tp->mtable) - outl(tp->mtable->csr12dir | 0x100, ioaddr + CSR12); - break; - case DC21142: - outl(0x82420200, ioaddr + CSR6); - outl(0x0001, ioaddr + CSR13); - outl(0x0003FFFF, ioaddr + CSR14); - outl(0x0008, ioaddr + CSR15); - outl(0x0001, ioaddr + CSR13); - outl(0x1301, ioaddr + CSR12); /* Start NWay. */ - break; - case LC82C168: - if ( ! tp->mii_cnt) { - outl(0x00420000, ioaddr + CSR6); - outl(0x30, ioaddr + CSR12); - outl(0x0001F078, ioaddr + 0xB8); - outl(0x0201F078, ioaddr + 0xB8); /* Turn on autonegotiation. */ - } - break; - case MX98713: case MX98715: case MX98725: - outl(0x00000000, ioaddr + CSR6); - outl(0x000711C0, ioaddr + CSR14); /* Turn on NWay. */ - outl(0x00000001, ioaddr + CSR13); - break; - } - - return dev; -} - -/* Serial EEPROM section. */ -/* The main routine to parse the very complicated SROM structure. - Search www.digital.com for "21X4 SROM" to get details. - This code is very complex, and will require changes to support - additional cards, so I'll be verbose about what is going on. - */ - -/* Known cards that have old-style EEPROMs. */ -static struct fixups { - char *name; - unsigned char addr0, addr1, addr2; - u16 newtable[32]; /* Max length below. */ -} eeprom_fixups[] = { - {"Asante", 0, 0, 0x94, {0x1e00, 0x0000, 0x0800, 0x0100, 0x018c, - 0x0000, 0x0000, 0xe078, 0x0001, 0x0050, 0x0018 }}, - {"SMC9332DST", 0, 0, 0xC0, { 0x1e00, 0x0000, 0x0800, 0x021f, - 0x0000, 0x009E, /* 10baseT */ - 0x0903, 0x006D, /* 100baseTx */ }}, - {"Cogent EM100", 0, 0, 0x92, { 0x1e00, 0x0000, 0x0800, 0x033f, - 0x0107, 0x8021, /* 100baseFx */ - 0x0108, 0x8021, /* 100baseFx-FD */ - 0x0103, 0x006D, /* 100baseTx */ }}, - {"Maxtech NX-110", 0, 0, 0xE8, { 0x1e00, 0x0000, 0x0800, 0x0313, - 0x1001, 0x009E, /* 10base2, CSR12 0x10*/ - 0x0000, 0x009E, /* 10baseT */ - 0x0303, 0x006D, /* 100baseTx, CSR12 0x03 */ }}, - {"Accton EN1207", 0, 0, 0xE8, { 0x1e00, 0x0000, 0x0800, 0x031F, - 0x1B01, 0x0000, /* 10base2, CSR12 0x1B */ - 0x1B03, 0x006D, /* 100baseTx, CSR12 0x1B */ - 0x0B00, 0x009E, /* 10baseT, CSR12 0x0B */ - }}, - {0, 0, 0, 0, {}}}; - -static const char * block_name[] = {"21140 non-MII", "21140 MII PHY", - "21142 Serial PHY", "21142 MII PHY", "21143 SYM PHY", "21143 reset method"}; - -#define EEPROM_SIZE 128 -#if defined(__i386__) -#define get_u16(ptr) (*(u16 *)(ptr)) -#else -#define get_u16(ptr) (((u8*)(ptr))[0] + (((u8*)(ptr))[1]<<8)) -#endif - -static void parse_eeprom(struct net_device *dev) +static void parse_eeprom(struct net_device *dev) { /* The last media info list parsed, for multiport boards. */ static struct mediatable *last_mediatable = NULL; static unsigned char *last_ee_data = NULL; static int controller_index = 0; struct tulip_private *tp = (struct tulip_private *)dev->priv; - long ioaddr = dev->base_addr; unsigned char *ee_data = tp->eeprom; int i; tp->mtable = 0; - for (i = 0; i < EEPROM_SIZE/2; i++) - ((u16 *)ee_data)[i] = read_eeprom(ioaddr, i); - /* Detect an old-style (SA only) EEPROM layout: memcmp(eedata, eedata+16, 8). */ for (i = 0; i < 8; i ++) @@ -871,20 +590,13 @@ static void parse_eeprom(struct net_device *dev) } } if (eeprom_fixups[i].name == NULL) { /* No fixup found. */ - printk(KERN_INFO "%s: Old style EEPROM -- no media selection information.\n", + printk(KERN_INFO "%s: Old style EEPROM with no media selection " + "information.\n", dev->name); return; } } - if (tulip_debug > 1) { - printk(KERN_DEBUG "read_eeprom:"); - for (i = 0; i < 64; i++) { - printk("%s%4.4x", (i & 7) == 0 ? "\n" KERN_DEBUG : " ", - read_eeprom(ioaddr, i)); - } - printk("\n"); - } - + controller_index = 0; if (ee_data[19] > 1) { /* Multiport board. */ last_ee_data = ee_data; @@ -894,42 +606,29 @@ subsequent_board: if (ee_data[27] == 0) { /* No valid media table. */ } else if (tp->chip_id == DC21041) { unsigned char *p = (void *)ee_data + ee_data[27 + controller_index*3]; - short media; - int count; - - media = get_u16(p); - p += 2; - count = *p++; + int media = get_u16(p); + int count = p[2]; + p += 3; - printk(KERN_INFO "%s:21041 Media information at %d, default media " - "%4.4x (%s).\n", dev->name, ee_data[27], media, + printk(KERN_INFO "%s: 21041 Media table, default media %4.4x (%s).\n", + dev->name, media, media & 0x0800 ? "Autosense" : medianame[media & 15]); for (i = 0; i < count; i++) { unsigned char media_code = *p++; - u16 csrvals[3]; - int idx; - for (idx = 0; idx < 3; idx++) { - csrvals[idx] = get_u16(p); - p += 2; - } - if (media_code & 0x40) { - printk(KERN_INFO "%s: 21041 media %2.2x (%s)," - " csr13 %4.4x csr14 %4.4x csr15 %4.4x.\n", - dev->name, media_code & 15, medianame[media_code & 15], - csrvals[0], csrvals[1], csrvals[2]); - } else - printk(KERN_INFO "%s: 21041 media #%d, %s.\n", - dev->name, media_code & 15, medianame[media_code & 15]); + if (media_code & 0x40) + p += 6; + printk(KERN_INFO "%s: 21041 media #%d, %s.\n", + dev->name, media_code & 15, medianame[media_code & 15]); } } else { unsigned char *p = (void *)ee_data + ee_data[27]; unsigned char csr12dir = 0; - int count; + int count, new_advertise = 0; struct mediatable *mtable; u16 media = get_u16(p); p += 2; - if (tulip_tbl[tp->chip_id].flags & CSR12_IN_SROM) + if (tp->flags & CSR12_IN_SROM) csr12dir = *p++; count = *p++; mtable = (struct mediatable *) @@ -941,13 +640,14 @@ subsequent_board: mtable->defaultmedia = media; mtable->leafcount = count; mtable->csr12dir = csr12dir; - mtable->has_nonmii = mtable->has_mii = 0; + mtable->has_nonmii = mtable->has_mii = mtable->has_reset = 0; + mtable->csr15dir = mtable->csr15val = 0; printk(KERN_INFO "%s: EEPROM default media type %s.\n", dev->name, media & 0x0800 ? "Autosense" : medianame[media & 15]); for (i = 0; i < count; i++) { struct medialeaf *leaf = &mtable->mleaf[i]; - + if ((p[0] & 0x80) == 0) { /* 21140 Compact block. */ leaf->type = 0; leaf->media = p[0] & 0x3f; @@ -957,12 +657,34 @@ subsequent_board: p += 4; } else { leaf->type = p[1]; - if (p[1] & 1) { + if (p[1] == 0x05) { + mtable->has_reset = i; + leaf->media = p[2] & 0x0f; + } else if (p[1] & 1) { mtable->has_mii = 1; leaf->media = 11; } else { mtable->has_nonmii = 1; leaf->media = p[2] & 0x0f; + switch (leaf->media) { + case 0: new_advertise |= 0x0020; break; + case 4: new_advertise |= 0x0040; break; + case 3: new_advertise |= 0x0080; break; + case 5: new_advertise |= 0x0100; break; + case 6: new_advertise |= 0x0200; break; + } + if (p[1] == 2 && leaf->media == 0) { + if (p[2] & 0x40) { + u32 base15 = get_unaligned((u16*)&p[7]); + mtable->csr15dir = + (get_unaligned((u16*)&p[9])<<16) + base15; + mtable->csr15val = + (get_unaligned((u16*)&p[11])<<16) + base15; + } else { + mtable->csr15dir = get_unaligned((u16*)&p[3])<<16; + mtable->csr15val = get_unaligned((u16*)&p[5])<<16; + } + } } leaf->leafdata = p + 2; p += (p[0] & 0x3f) + 1; @@ -971,7 +693,7 @@ subsequent_board: unsigned char *bp = leaf->leafdata; printk(KERN_INFO "%s: MII interface PHY %d, setup/reset " "sequences %d/%d long, capabilities %2.2x %2.2x.\n", - dev->name, bp[0], bp[1], bp[1 + bp[1]*2], + dev->name, bp[0], bp[1], bp[2 + bp[1]*2], bp[5 + bp[2 + bp[1]*2]*2], bp[4 + bp[2 + bp[1]*2]*2]); } printk(KERN_INFO "%s: Index #%d - Media %s (#%d) described " @@ -979,6 +701,8 @@ subsequent_board: dev->name, i, medianame[leaf->media], leaf->media, block_name[leaf->type], leaf->type); } + if (new_advertise) + tp->to_advertise = new_advertise; } } /* Reading a serial EEPROM is a "bit" grungy, but we work our way through:->.*/ @@ -986,54 +710,48 @@ subsequent_board: /* EEPROM_Ctrl bits. */ #define EE_SHIFT_CLK 0x02 /* EEPROM shift clock. */ #define EE_CS 0x01 /* EEPROM chip select. */ -#define EE_DATA_WRITE 0x04 /* EEPROM chip data in. */ +#define EE_DATA_WRITE 0x04 /* Data from the Tulip to EEPROM. */ #define EE_WRITE_0 0x01 #define EE_WRITE_1 0x05 -#define EE_DATA_READ 0x08 /* EEPROM chip data out. */ +#define EE_DATA_READ 0x08 /* Data from the EEPROM chip. */ #define EE_ENB (0x4800 | EE_CS) /* Delay between EEPROM clock transitions. - The 1.2 code is a "nasty" timing loop, but PC compatible machines are - *supposed* to delay an ISA-compatible period for the SLOW_DOWN_IO macro. */ -#ifdef _LINUX_DELAY_H -#define eeprom_delay(nanosec) udelay((nanosec + 999)/1000) -#else -#define eeprom_delay(nanosec) do { int _i = 3; while (--_i > 0) { __SLOW_DOWN_IO; }} while (0) -#endif + Even at 33Mhz current PCI implementations don't overrun the EEPROM clock. + We add a bus turn-around to insure that this remains true. */ +#define eeprom_delay() inl(ee_addr) /* The EEPROM commands include the alway-set leading bit. */ -#define EE_WRITE_CMD (5 << 6) -#define EE_READ_CMD (6 << 6) -#define EE_ERASE_CMD (7 << 6) +#define EE_READ_CMD (6) -static int read_eeprom(long ioaddr, int location) +/* Note: this routine returns extra data bits for size detection. */ +static int read_eeprom(long ioaddr, int location, int addr_len) { int i; - unsigned short retval = 0; + unsigned retval = 0; long ee_addr = ioaddr + CSR9; - int read_cmd = location | EE_READ_CMD; - + int read_cmd = location | (EE_READ_CMD << addr_len); + outl(EE_ENB & ~EE_CS, ee_addr); outl(EE_ENB, ee_addr); - + /* Shift the read command bits out. */ - for (i = 10; i >= 0; i--) { + for (i = 4 + addr_len; i >= 0; i--) { short dataval = (read_cmd & (1 << i)) ? EE_DATA_WRITE : 0; outl(EE_ENB | dataval, ee_addr); - eeprom_delay(100); + eeprom_delay(); outl(EE_ENB | dataval | EE_SHIFT_CLK, ee_addr); - eeprom_delay(150); - outl(EE_ENB | dataval, ee_addr); /* Finish EEPROM a clock tick. */ - eeprom_delay(250); + eeprom_delay(); + retval = (retval << 1) | ((inl(ee_addr) & EE_DATA_READ) ? 1 : 0); } outl(EE_ENB, ee_addr); - + for (i = 16; i > 0; i--) { outl(EE_ENB | EE_SHIFT_CLK, ee_addr); - eeprom_delay(100); + eeprom_delay(); retval = (retval << 1) | ((inl(ee_addr) & EE_DATA_READ) ? 1 : 0); outl(EE_ENB, ee_addr); - eeprom_delay(100); + eeprom_delay(); } /* Terminate the EEPROM access. */ @@ -1067,20 +785,34 @@ static int mdio_read(struct net_device *dev, int phy_id, int location) int i; int read_cmd = (0xf6 << 10) | (phy_id << 5) | location; int retval = 0; - long mdio_addr = dev->base_addr + CSR9; + long ioaddr = dev->base_addr; + long mdio_addr = ioaddr + CSR9; if (tp->chip_id == LC82C168) { - long ioaddr = dev->base_addr; int i = 1000; outl(0x60020000 + (phy_id<<23) + (location<<18), ioaddr + 0xA0); + inl(ioaddr + 0xA0); + inl(ioaddr + 0xA0); while (--i > 0) if ( ! ((retval = inl(ioaddr + 0xA0)) & 0x80000000)) return retval & 0xffff; return 0xffff; } - /* Establish sync by sending at least 32 logic ones. */ - for (i = 32; i >= 0; i--) { + if (tp->chip_id == COMET) { + if (phy_id == 1) { + if (location < 7) + return inl(ioaddr + 0xB4 + (location<<2)); + else if (location == 17) + return inl(ioaddr + 0xD0); + else if (location >= 29 && location <= 31) + return inl(ioaddr + 0xD4 + ((location-29)<<2)); + } + return 0xffff; + } + + /* Establish sync by sending at least 32 logic ones. */ + for (i = 32; i >= 0; i--) { outl(MDIO_ENB | MDIO_DATA_WRITE1, mdio_addr); mdio_delay(); outl(MDIO_ENB | MDIO_DATA_WRITE1 | MDIO_SHIFT_CLK, mdio_addr); @@ -1111,10 +843,10 @@ static void mdio_write(struct net_device *dev, int phy_id, int location, int val struct tulip_private *tp = (struct tulip_private *)dev->priv; int i; int cmd = (0x5002 << 16) | (phy_id << 23) | (location<<18) | value; - long mdio_addr = dev->base_addr + CSR9; + long ioaddr = dev->base_addr; + long mdio_addr = ioaddr + CSR9; if (tp->chip_id == LC82C168) { - long ioaddr = dev->base_addr; int i = 1000; outl(cmd, ioaddr + 0xA0); do @@ -1124,7 +856,19 @@ static void mdio_write(struct net_device *dev, int phy_id, int location, int val return; } - /* Establish sync by sending 32 logic ones. */ + if (tp->chip_id == COMET) { + if (phy_id != 1) + return; + if (location < 7) + outl(value, ioaddr + 0xB4 + (location<<2)); + else if (location == 17) + outl(value, ioaddr + 0xD0); + else if (location >= 29 && location <= 31) + outl(value, ioaddr + 0xD4 + ((location-29)<<2)); + return; + } + + /* Establish sync by sending 32 logic ones. */ for (i = 32; i >= 0; i--) { outl(MDIO_ENB | MDIO_DATA_WRITE1, mdio_addr); mdio_delay(); @@ -1155,7 +899,12 @@ tulip_open(struct net_device *dev) { struct tulip_private *tp = (struct tulip_private *)dev->priv; long ioaddr = dev->base_addr; - int i = 0; + int next_tick = 3*HZ; + int i; + + /* Wake the chip from sleep/snooze mode. */ + if (tp->flags & HAS_PWRDWN) + pci_write_config_dword(tp->pdev, 0x40, 0); /* On some chip revs we must set the MII/SYM port before the reset!? */ if (tp->mii_cnt || (tp->mtable && tp->mtable->has_mii)) @@ -1163,85 +912,63 @@ tulip_open(struct net_device *dev) /* Reset the chip, holding bit 0 set at least 50 PCI cycles. */ outl(0x00000001, ioaddr + CSR0); -#ifdef _LINUX_DELAY_H - udelay(2); -#else - SLOW_DOWN_IO; -#endif + + if (request_irq(dev->irq, &tulip_interrupt, SA_SHIRQ, dev->name, dev)) + return -EAGAIN; + /* Deassert reset. - 486: Set 8 longword cache alignment, 8 longword burst. - 586: Set 16 longword cache alignment, no burst limit. - Cache alignment bits 15:14 Burst length 13:8 - 0000 No alignment 0x00000000 unlimited 0800 8 longwords - 4000 8 longwords 0100 1 longword 1000 16 longwords - 8000 16 longwords 0200 2 longwords 2000 32 longwords - C000 32 longwords 0400 4 longwords Wait the specified 50 PCI cycles after a reset by initializing Tx and Rx queues and the address filter list. */ -#if defined(__alpha__) - /* ToDo: Alpha setting could be better. */ - outl(0x01A00000 | 0xE000, ioaddr + CSR0); -#elif defined(__powerpc__) - outl(0x01A00080 | 0x8000, ioaddr + CSR0); -#elif defined(__i386__) -#if defined(MODULE) - /* When a module we don't have 'x86' to check. */ - outl(0x01A00000 | 0x4800, ioaddr + CSR0); -#else -#define x86 boot_cpu_data.x86 - outl(0x01A00000 | (x86 <= 4 ? 0x4800 : 0x8000), ioaddr + CSR0); - if (x86 <= 4) - printk(KERN_INFO "%s: This is a 386/486 PCI system, setting cache " - "alignment to %x.\n", dev->name, - 0x01A00000 | (x86 <= 4 ? 0x4800 : 0x8000)); -#endif -#else - outl(0x01A00000 | 0x4800, ioaddr + CSR0); -#warning Processor architecture undefined! -#endif - -#ifdef SA_SHIRQ - if (request_irq(dev->irq, &tulip_interrupt, SA_SHIRQ, dev->name, dev)) { - return -EAGAIN; - } -#else - if (irq2dev_map[dev->irq] != NULL - || (irq2dev_map[dev->irq] = dev) == NULL - || dev->irq == 0 - || request_irq(dev->irq, &tulip_interrupt, 0, - tulip_tbl[tp->chip_id].chip_name)) { - return -EAGAIN; - } -#endif + outl(tp->csr0, ioaddr + CSR0); if (tulip_debug > 1) printk(KERN_DEBUG "%s: tulip_open() irq %d.\n", dev->name, dev->irq); MOD_INC_USE_COUNT; - spin_lock_init(&tp->tx_lock); + spin_lock_init(&tp->tx_lock); tulip_init_ring(dev); - /* This is set_rx_mode(), but without starting the transmitter. */ - /* Fill the whole address filter table with our physical address. */ - { - u16 *eaddrs = (u16 *)dev->dev_addr; - u32 *setup_frm = tp->setup_frame, i; - - /* You must add the broadcast address when doing perfect filtering! */ - *setup_frm++ = 0xffff; - *setup_frm++ = 0xffff; - *setup_frm++ = 0xffff; - /* Fill the rest of the accept table with our physical address. */ - for (i = 1; i < 16; i++) { - *setup_frm++ = eaddrs[0]; - *setup_frm++ = eaddrs[1]; - *setup_frm++ = eaddrs[2]; +#if 0 + if (tp->chip_id == PNIC2) { + u32 addr_low = cpu_to_le32(get_unaligned((u32 *)dev->dev_addr)); + u32 addr_high = cpu_to_le16(get_unaligned((u16 *)(dev->dev_addr+4))); + addr_high = (dev->dev_addr[4]<<8) + (dev->dev_addr[5]<<0); + outl((dev->dev_addr[0]<<8) + dev->dev_addr[1] + + (dev->dev_addr[2]<<24) + (dev->dev_addr[3]<<16), + ioaddr + 0xB0); + outl(addr_high + (addr_high<<16), ioaddr + 0xB8); + } +#endif + if (tp->flags & MC_HASH_ONLY) { + u32 addr_low = cpu_to_le32(get_unaligned((u32 *)dev->dev_addr)); + u32 addr_high = cpu_to_le32(get_unaligned((u16 *)(dev->dev_addr+4))); + if (tp->chip_id == AX88140) { + outl(0, ioaddr + CSR13); + outl(addr_low, ioaddr + CSR14); + outl(1, ioaddr + CSR13); + outl(addr_high, ioaddr + CSR14); + } else if (tp->chip_id == COMET) { + outl(addr_low, ioaddr + 0xA4); + outl(addr_high, ioaddr + 0xA8); + outl(0, ioaddr + 0xAC); + outl(0, ioaddr + 0xB0); } + } else { + /* This is set_rx_mode(), but without starting the transmitter. */ + u16 *eaddrs = (u16 *)dev->dev_addr; + u16 *setup_frm = &tp->setup_frame[15*6]; + + /* 21140 bug: you must add the broadcast address. */ + memset(tp->setup_frame, 0xff, sizeof(tp->setup_frame)); + /* Fill the final entry of the table with our physical address. */ + *setup_frm++ = eaddrs[0]; *setup_frm++ = eaddrs[0]; + *setup_frm++ = eaddrs[1]; *setup_frm++ = eaddrs[1]; + *setup_frm++ = eaddrs[2]; *setup_frm++ = eaddrs[2]; /* Put the setup frame on the Tx list. */ - tp->tx_ring[0].length = 0x08000000 | 192; - tp->tx_ring[0].buffer1 = virt_to_bus(tp->setup_frame); - tp->tx_ring[0].status = 0x80000000; + tp->tx_ring[0].length = cpu_to_le32(0x08000000 | 192); + tp->tx_ring[0].buffer1 = virt_to_le32desc(tp->setup_frame); + tp->tx_ring[0].status = cpu_to_le32(DescOwned); tp->cur_tx++; } @@ -1249,13 +976,12 @@ tulip_open(struct net_device *dev) outl(virt_to_bus(tp->rx_ring), ioaddr + CSR3); outl(virt_to_bus(tp->tx_ring), ioaddr + CSR4); + tp->saved_if_port = dev->if_port; if (dev->if_port == 0) dev->if_port = tp->default_port; - if (tp->chip_id == DC21041 && dev->if_port > 4) - /* Invalid: Select initial TP, autosense, autonegotiate. */ - dev->if_port = 4; /* Allow selecting a default media. */ + i = 0; if (tp->mtable == NULL) goto media_picked; if (dev->if_port) { @@ -1268,31 +994,80 @@ tulip_open(struct net_device *dev) goto media_picked; } } - if ((tp->mtable->defaultmedia & 0x0800) == 0) + if ((tp->mtable->defaultmedia & 0x0800) == 0) { + int looking_for = tp->mtable->defaultmedia & 15; for (i = 0; i < tp->mtable->leafcount; i++) - if (tp->mtable->mleaf[i].media == (tp->mtable->defaultmedia & 15)) { - printk(KERN_INFO "%s: Using EEPROM-set media %s.\n", - dev->name, medianame[tp->mtable->mleaf[i].media]); - goto media_picked; - } + if (tp->mtable->mleaf[i].media == looking_for) { + printk(KERN_INFO "%s: Using EEPROM-set media %s.\n", + dev->name, medianame[looking_for]); + goto media_picked; + } + } /* Start sensing first non-full-duplex media. */ for (i = tp->mtable->leafcount - 1; (media_cap[tp->mtable->mleaf[i].media] & MediaAlwaysFD) && i > 0; i--) - ; + ; media_picked: tp->csr6 = 0; tp->cur_index = i; + tp->nwayset = 0; + if (dev->if_port == 0 && tp->chip_id == DC21041) { + tp->nway = 1; + } if (dev->if_port == 0 && tp->chip_id == DC21142) { - tp->csr6 = 0x82420200; - outl(0x0003FFFF, ioaddr + CSR14); + if (tp->mii_cnt) { + select_media(dev, 1); + if (tulip_debug > 1) + printk(KERN_INFO "%s: Using MII transceiver %d, status " + "%4.4x.\n", + dev->name, tp->phys[0], mdio_read(dev, tp->phys[0], 1)); + outl(0x82020000, ioaddr + CSR6); + tp->csr6 = 0x820E0000; + dev->if_port = 11; + outl(0x0000, ioaddr + CSR13); + outl(0x0000, ioaddr + CSR14); + } else + t21142_start_nway(dev); + } else if (tp->chip_id == PNIC2) { + t21142_start_nway(dev); + } else if (tp->chip_id == LC82C168 && ! tp->medialock) { + if (tp->mii_cnt) { + dev->if_port = 11; + tp->csr6 = 0x814C0000 | (tp->full_duplex ? 0x0200 : 0); + outl(0x0001, ioaddr + CSR15); + } else if (inl(ioaddr + CSR5) & TPLnkPass) + pnic_do_nway(dev); + else { + /* Start with 10mbps to do autonegotiation. */ + outl(0x32, ioaddr + CSR12); + tp->csr6 = 0x00420000; + outl(0x0001B078, ioaddr + 0xB8); + outl(0x0201B078, ioaddr + 0xB8); + next_tick = 1*HZ; + } + } else if ((tp->chip_id == MX98713 || tp->chip_id == COMPEX9881) + && ! tp->medialock) { + dev->if_port = 0; + tp->csr6 = 0x01880000 | (tp->full_duplex ? 0x0200 : 0); + outl(0x0f370000 | inw(ioaddr + 0x80), ioaddr + 0x80); + } else if (tp->chip_id == MX98715 || tp->chip_id == MX98725) { + /* Provided by BOLO, Macronix - 12/10/1998. */ + dev->if_port = 0; + tp->csr6 = 0x01a80200; + outl(0x0f370000 | inw(ioaddr + 0x80), ioaddr + 0x80); + outl(0x11000 | inw(ioaddr + 0xa0), ioaddr + 0xa0); + } else if (tp->chip_id == DC21143 && + media_cap[dev->if_port] & MediaIsMII) { + /* We must reset the media CSRs when we force-select MII mode. */ + outl(0x0000, ioaddr + CSR13); + outl(0x0000, ioaddr + CSR14); outl(0x0008, ioaddr + CSR15); - outl(0x0001, ioaddr + CSR13); - outl(0x1301, ioaddr + CSR12); - } else if (tp->chip_id == LC82C168 && tp->mii_cnt && ! tp->medialock) { - dev->if_port = 11; - tp->csr6 = 0x816C0000 | (tp->full_duplex ? 0x0200 : 0); - outl(0x0001, ioaddr + CSR15); + } else if (tp->chip_id == COMET) { + dev->if_port = 0; + tp->csr6 = 0x00040000; + } else if (tp->chip_id == AX88140) { + tp->csr6 = tp->mii_cnt ? 0x00040100 : 0x00000100; } else select_media(dev, 1); @@ -1314,7 +1089,7 @@ media_picked: /* Set the timer to switch to check for link beat and perhaps switch to an alternate media type. */ init_timer(&tp->timer); - tp->timer.expires = RUN_AT(5*HZ); + tp->timer.expires = RUN_AT(next_tick); tp->timer.data = (unsigned long)dev; tp->timer.function = tulip_tbl[tp->chip_id].media_timer; add_timer(&tp->timer); @@ -1331,7 +1106,7 @@ static void select_media(struct net_device *dev, int startup) struct tulip_private *tp = (struct tulip_private *)dev->priv; struct mediatable *mtable = tp->mtable; u32 new_csr6; - int check_mii =0, i; + int i; if (mtable) { struct medialeaf *mleaf = &mtable->mleaf[tp->cur_index]; @@ -1349,33 +1124,56 @@ static void select_media(struct net_device *dev, int startup) new_csr6 = 0x02000000 | ((p[2] & 0x71) << 18); break; case 2: case 4: { - u16 setup[3]; - for (i = 0; i < 3; i++) + u16 setup[5]; + u32 csr13val, csr14val, csr15dir, csr15val; + for (i = 0; i < 5; i++) setup[i] = get_u16(&p[i*2 + 1]); dev->if_port = p[0] & 15; + if (media_cap[dev->if_port] & MediaAlwaysFD) + tp->full_duplex = 1; + + if (startup && mtable->has_reset) { + struct medialeaf *rleaf = &mtable->mleaf[mtable->has_reset]; + unsigned char *rst = rleaf->leafdata; + if (tulip_debug > 1) + printk(KERN_DEBUG "%s: Resetting the transceiver.\n", + dev->name); + for (i = 0; i < rst[0]; i++) + outl(get_u16(rst + 1 + (i<<1)) << 16, ioaddr + CSR15); + } if (tulip_debug > 1) - printk(KERN_DEBUG "%s: 21142 non-MII %s transceiver control %4.4x/%4.4x.\n", + printk(KERN_DEBUG "%s: 21143 non-MII %s transceiver control " + "%4.4x/%4.4x.\n", dev->name, medianame[dev->if_port], setup[0], setup[1]); if (p[0] & 0x40) { /* SIA (CSR13-15) setup values are provided. */ + csr13val = setup[0]; + csr14val = setup[1]; + csr15dir = (setup[3]<<16) | setup[2]; + csr15val = (setup[4]<<16) | setup[2]; outl(0, ioaddr + CSR13); - outl(setup[1], ioaddr + CSR14); - outl(setup[2], ioaddr + CSR15); - outl(setup[0], ioaddr + CSR13); - for (i = 0; i < 3; i++) /* Re-fill setup[] */ - setup[i] = get_u16(&p[i*2 + 7]); - } else if (dev->if_port <= 4) { - outl(0, ioaddr + CSR13); - outl(t21142_csr14[dev->if_port], ioaddr + CSR14); - outl(t21142_csr15[dev->if_port], ioaddr + CSR15); - outl(t21142_csr13[dev->if_port], ioaddr + CSR13); + outl(csr14val, ioaddr + CSR14); + outl(csr15dir, ioaddr + CSR15); /* Direction */ + outl(csr15val, ioaddr + CSR15); /* Data */ + outl(csr13val, ioaddr + CSR13); } else { - outl(0, ioaddr + CSR14); - outl(8, ioaddr + CSR15); - outl(0, ioaddr + CSR13); + csr13val = 1; + csr14val = 0x0003FF7F; + csr15dir = (setup[0]<<16) | 0x0008; + csr15val = (setup[1]<<16) | 0x0008; + if (dev->if_port <= 4) + csr14val = t21142_csr14[dev->if_port]; + if (startup) { + outl(0, ioaddr + CSR13); + outl(csr14val, ioaddr + CSR14); + } + outl(csr15dir, ioaddr + CSR15); /* Direction */ + outl(csr15val, ioaddr + CSR15); /* Data */ + if (startup) outl(csr13val, ioaddr + CSR13); } - outl(setup[0]<<16, ioaddr + CSR15); /* Direction */ - outl(setup[1]<<16, ioaddr + CSR15); /* Data */ + if (tulip_debug > 1) + printk(KERN_DEBUG "%s: Setting CSR15 to %8.8x/%8.8x.\n", + dev->name, csr15dir, csr15val); if (mleaf->type == 4) new_csr6 = 0x82020000 | ((setup[2] & 0x71) << 18); else @@ -1389,7 +1187,6 @@ static void select_media(struct net_device *dev, int startup) u16 to_advertise; dev->if_port = 11; - check_mii = 1; new_csr6 = 0x020E0000; if (mleaf->type == 3) { /* 21142 */ u16 *init_sequence = (u16*)(p+2); @@ -1416,7 +1213,7 @@ static void select_media(struct net_device *dev, int startup) } to_advertise = (get_u16(&misc_info[1]) & tp->to_advertise) | 1; tp->advertising[phy_num] = to_advertise; - if (tulip_debug > 1 || 1) + if (tulip_debug > 1) printk(KERN_DEBUG "%s: Advertising %4.4x on PHY %d (%d).\n", dev->name, to_advertise, phy_num, tp->phys[phy_num]); /* Bogus: put in by a committee? */ @@ -1424,32 +1221,33 @@ static void select_media(struct net_device *dev, int startup) break; } default: - new_csr6 = 0x020E0000; + printk(KERN_DEBUG "%s: Invalid media table selection %d.\n", + dev->name, mleaf->type); + new_csr6 = 0x020E0000; } if (tulip_debug > 1) printk(KERN_DEBUG "%s: Using media type %s, CSR12 is %2.2x.\n", dev->name, medianame[dev->if_port], inl(ioaddr + CSR12) & 0xff); } else if (tp->chip_id == DC21041) { + int port = dev->if_port <= 4 ? dev->if_port : 0; if (tulip_debug > 1) printk(KERN_DEBUG "%s: 21041 using media %s, CSR12 is %4.4x.\n", - dev->name, medianame[dev->if_port & 15], - inl(ioaddr + CSR12) & 0xffff); + dev->name, medianame[port == 3 ? 12: port], + inl(ioaddr + CSR12)); outl(0x00000000, ioaddr + CSR13); /* Reset the serial interface */ - outl(t21041_csr14[dev->if_port], ioaddr + CSR14); - outl(t21041_csr15[dev->if_port], ioaddr + CSR15); - outl(t21041_csr13[dev->if_port], ioaddr + CSR13); + outl(t21041_csr14[port], ioaddr + CSR14); + outl(t21041_csr15[port], ioaddr + CSR15); + outl(t21041_csr13[port], ioaddr + CSR13); new_csr6 = 0x80020000; } else if (tp->chip_id == LC82C168) { if (startup && ! tp->medialock) dev->if_port = tp->mii_cnt ? 11 : 0; if (tulip_debug > 1) - printk(KERN_DEBUG "%s: PNIC PHY status is %3.3x, CSR12 %4.4x," - " media %s.\n", - dev->name, inl(ioaddr + 0xB8), inl(ioaddr + CSR12), - medianame[dev->if_port]); + printk(KERN_DEBUG "%s: PNIC PHY status is %3.3x, media %s.\n", + dev->name, inl(ioaddr + 0xB8), medianame[dev->if_port]); if (tp->mii_cnt) { - new_csr6 = 0x812C0000; + new_csr6 = 0x810C0000; outl(0x0001, ioaddr + CSR15); outl(0x0201B07A, ioaddr + 0xB8); } else if (startup) { @@ -1461,10 +1259,8 @@ static void select_media(struct net_device *dev, int startup) } else if (dev->if_port == 3 || dev->if_port == 5) { outl(0x33, ioaddr + CSR12); new_csr6 = 0x01860000; - if (startup) - outl(0x0201F868, ioaddr + 0xB8); /* Trigger autonegotiation. */ - else - outl(0x1F868, ioaddr + 0xB8); + /* Trigger autonegotiation. */ + outl(startup ? 0x0201F868 : 0x0001F868, ioaddr + 0xB8); } else { outl(0x32, ioaddr + CSR12); new_csr6 = 0x00420000; @@ -1475,20 +1271,24 @@ static void select_media(struct net_device *dev, int startup) int csr12 = inl(ioaddr + CSR12); if (tulip_debug > 1) printk(KERN_DEBUG "%s: 21040 media type is %s, CSR12 is %2.2x.\n", - dev->name, dev->if_port ? "AUI" : "10baseT", csr12); - new_csr6 = (dev->if_port ? 0x01860000 : 0x00420000); + dev->name, medianame[dev->if_port], csr12); + if (media_cap[dev->if_port] & MediaAlwaysFD) + tp->full_duplex = 1; + new_csr6 = 0x20000; /* Set the full duplux match frame. */ outl(FULL_DUPLEX_MAGIC, ioaddr + CSR11); outl(0x00000000, ioaddr + CSR13); /* Reset the serial interface */ - outl(dev->if_port ? 0x0000000C : 0x00000004, ioaddr + CSR13); + if (t21040_csr13[dev->if_port] & 8) { + outl(0x0705, ioaddr + CSR14); + outl(0x0006, ioaddr + CSR15); + } else { + outl(0xffff, ioaddr + CSR14); + outl(0x0000, ioaddr + CSR15); + } + outl(0x8f01 | t21040_csr13[dev->if_port], ioaddr + CSR13); } else { /* Unknown chip type with no media table. */ if (tp->default_port == 0) - { - if (tp->mii_cnt) - dev->if_port = 11; - else - dev->if_port = 3; - } + dev->if_port = tp->mii_cnt ? 11 : 3; if (media_cap[dev->if_port] & MediaIsMII) { new_csr6 = 0x020E0000; } else if (media_cap[dev->if_port] & MediaIsFx) { @@ -1506,28 +1306,80 @@ static void select_media(struct net_device *dev, int startup) return; } +/* + Check the MII negotiated duplex, and change the CSR6 setting if + required. + Return 0 if everything is OK. + Return < 0 if the transceiver is missing or has no link beat. + */ +static int check_duplex(struct net_device *dev) +{ + long ioaddr = dev->base_addr; + struct tulip_private *tp = (struct tulip_private *)dev->priv; + int mii_reg1, mii_reg5, negotiated, duplex; + + if (tp->full_duplex_lock) + return 0; + mii_reg1 = mdio_read(dev, tp->phys[0], 1); + mii_reg5 = mdio_read(dev, tp->phys[0], 5); + if (tulip_debug > 1) + printk(KERN_INFO "%s: MII status %4.4x, Link partner report " + "%4.4x.\n", dev->name, mii_reg1, mii_reg5); + if (mii_reg1 == 0xffff) + return -2; + if ((mii_reg1 & 0x0004) == 0) { + int new_reg1 = mdio_read(dev, tp->phys[0], 1); + if ((new_reg1 & 0x0004) == 0) { + if (tulip_debug > 1) + printk(KERN_INFO "%s: No link beat on the MII interface," + " status %4.4x.\n", dev->name, new_reg1); + return -1; + } + } + negotiated = mii_reg5 & tp->advertising[0]; + duplex = ((negotiated & 0x0300) == 0x0100 + || (negotiated & 0x00C0) == 0x0040); + /* 100baseTx-FD or 10T-FD, but not 100-HD */ + if (tp->full_duplex != duplex) { + tp->full_duplex = duplex; + if (negotiated & 0x038) /* 100mbps. */ + tp->csr6 &= ~0x00400000; + if (tp->full_duplex) tp->csr6 |= 0x0200; + else tp->csr6 &= ~0x0200; + outl(tp->csr6 | 0x0002, ioaddr + CSR6); + outl(tp->csr6 | 0x2002, ioaddr + CSR6); + if (tulip_debug > 0) + printk(KERN_INFO "%s: Setting %s-duplex based on MII" + "#%d link partner capability of %4.4x.\n", + dev->name, tp->full_duplex ? "full" : "half", + tp->phys[0], mii_reg5); + return 1; + } + return 0; +} + static void tulip_timer(unsigned long data) { struct net_device *dev = (struct net_device *)data; struct tulip_private *tp = (struct tulip_private *)dev->priv; long ioaddr = dev->base_addr; u32 csr12 = inl(ioaddr + CSR12); - int next_tick = 0; + int next_tick = 2*HZ; - if (tulip_debug > 3) { - printk(KERN_DEBUG "%s: Media selection tick, status %8.8x mode %8.8x " - "SIA %8.8x %8.8x %8.8x %8.8x.\n", - dev->name, inl(ioaddr + CSR5), inl(ioaddr + CSR6), - csr12, inl(ioaddr + CSR13), + if (tulip_debug > 2) { + printk(KERN_DEBUG "%s: Media selection tick, %s, status %8.8x mode" + " %8.8x SIA %8.8x %8.8x %8.8x %8.8x.\n", + dev->name, medianame[dev->if_port], inl(ioaddr + CSR5), + inl(ioaddr + CSR6), csr12, inl(ioaddr + CSR13), inl(ioaddr + CSR14), inl(ioaddr + CSR15)); } switch (tp->chip_id) { case DC21040: - if (csr12 & 0x0002) { /* Network error */ - printk(KERN_INFO "%s: No 10baseT link beat found, switching to %s media.\n", - dev->name, dev->if_port ? "10baseT" : "AUI"); - dev->if_port ^= 1; - outl(dev->if_port ? 0x0000000C : 0x00000004, ioaddr + CSR13); + if (!tp->medialock && csr12 & 0x0002) { /* Network error */ + printk(KERN_INFO "%s: No link beat found.\n", + dev->name); + dev->if_port = (dev->if_port == 2 ? 0 : 2); + select_media(dev, 0); dev->trans_start = jiffies; } break; @@ -1535,6 +1387,7 @@ static void tulip_timer(unsigned long data) if (tulip_debug > 2) printk(KERN_DEBUG "%s: 21041 media tick CSR12 %8.8x.\n", dev->name, csr12); + if (tp->medialock) break; switch (dev->if_port) { case 0: case 3: case 4: if (csr12 & 0x0004) { /*LnkFail */ @@ -1556,25 +1409,26 @@ static void tulip_timer(unsigned long data) break; case 1: /* 10base2 */ case 2: /* AUI */ - if (csr12 & 0x0100) { - next_tick = (30*HZ); /* 30 sec. */ - tp->mediasense = 0; - } else if ((csr12 & 0x0004) == 0) { - printk(KERN_INFO "%s: 21041 media switched to 10baseT.\n", dev->name); - dev->if_port = 0; - select_media(dev, 0); - next_tick = (24*HZ)/10; /* 2.4 sec. */ - } else if (tp->mediasense || (csr12 & 0x0002)) { - dev->if_port = 3 - dev->if_port; /* Swap ports. */ - select_media(dev, 0); - next_tick = 20*HZ; - } else { - next_tick = 20*HZ; - } - break; + if (csr12 & 0x0100) { + next_tick = (30*HZ); /* 30 sec. */ + tp->mediasense = 0; + } else if ((csr12 & 0x0004) == 0) { + printk(KERN_INFO "%s: 21041 media switched to 10baseT.\n", + dev->name); + dev->if_port = 0; + select_media(dev, 0); + next_tick = (24*HZ)/10; /* 2.4 sec. */ + } else if (tp->mediasense || (csr12 & 0x0002)) { + dev->if_port = 3 - dev->if_port; /* Swap ports. */ + select_media(dev, 0); + next_tick = 20*HZ; + } else { + next_tick = 20*HZ; + } + break; } break; - case DC21140: case DC21142: case MX98713: default: { + case DC21140: case DC21142: case MX98713: case COMPEX9881: default: { struct medialeaf *mleaf; unsigned char *p; if (tp->mtable == NULL) { /* No EEPROM info, use generic code. */ @@ -1643,53 +1497,11 @@ static void tulip_timer(unsigned long data) next_tick = (24*HZ)/10; break; } - case 1: case 3: { /* 21140, 21142 MII */ - int mii_reg1, mii_reg5; + case 1: case 3: /* 21140, 21142 MII */ actually_mii: - mii_reg1 = mdio_read(dev, tp->phys[0], 1); - mii_reg5 = mdio_read(dev, tp->phys[0], 5); - if (tulip_debug > 1) - printk(KERN_INFO "%s: MII status %4.4x, Link partner report " - "%4.4x, CSR12 %2.2x, %cD.\n", - dev->name, mii_reg1, mii_reg5, csr12, - tp->full_duplex ? 'F' : 'H'); - if (mii_reg1 != 0xffff && (mii_reg1 & 0x0004) == 0) { - int new_reg1 = mdio_read(dev, tp->phys[0], 1); - if ((new_reg1 & 0x0004) == 0) { - printk(KERN_INFO "%s: No link beat on the MII interface," - " status then %4.4x now %4.4x.\n", - dev->name, mii_reg1, new_reg1); - if (tp->mtable && tp->mtable->has_nonmii) - goto select_next_media; - } - } - if (mii_reg5 == 0xffff || mii_reg5 == 0x0000) - ; /* No MII device or no link partner report */ - else if (tp->full_duplex_lock) - ; - else { - int negotiated = mii_reg5 & tp->advertising[0]; - int duplex = ((negotiated & 0x0100) != 0 - || (negotiated & 0x00C0) == 0x0040); - /* 100baseTx-FD or 10T-FD, but not 100-HD */ - if (tp->full_duplex != duplex) { - tp->full_duplex = duplex; - if (tp->full_duplex) - tp->csr6 |= 0x0200; - else - tp->csr6 &= ~0x0200; - outl(tp->csr6 | 0x0002, ioaddr + CSR6); - outl(tp->csr6 | 0x2002, ioaddr + CSR6); - if (tulip_debug > 0) /* Gurppp, should be >1 */ - printk(KERN_INFO "%s: Setting %s-duplex based on MII" - " Xcvr #%d parter capability of %4.4x.\n", - dev->name, tp->full_duplex ? "full" : "half", - tp->phys[0], mii_reg5); - } - } + check_duplex(dev); next_tick = 60*HZ; break; - } case 2: /* 21142 serial block has no link beat. */ default: break; @@ -1697,10 +1509,8 @@ static void tulip_timer(unsigned long data) } break; } - if (next_tick) { - tp->timer.expires = RUN_AT(next_tick); - add_timer(&tp->timer); - } + tp->timer.expires = RUN_AT(next_tick); + add_timer(&tp->timer); } /* Handle the 21143 uniquely: do autoselect with NWay, not the EEPROM list @@ -1714,49 +1524,50 @@ static void t21142_timer(unsigned long data) int next_tick = 60*HZ; int new_csr6 = 0; - if (tulip_debug > 1) - printk(KERN_INFO"%s: 21142 negotiation status %8.8x, %s.\n", + if (tulip_debug > 2) + printk(KERN_INFO"%s: 21143 negotiation status %8.8x, %s.\n", dev->name, csr12, medianame[dev->if_port]); - if (dev->if_port == 3) { - if (csr12 & 2) { /* No 100mbps link beat, revert to 10mbps. */ - new_csr6 = 0x82420200; - outl(new_csr6, ioaddr + CSR6); - outl(0x0000, ioaddr + CSR13); - outl(0x0003FFFF, ioaddr + CSR14); - outl(0x0008, ioaddr + CSR15); - outl(0x0001, ioaddr + CSR13); - outl(0x1301, ioaddr + CSR12); /* Start NWay. */ + if (media_cap[dev->if_port] & MediaIsMII) { + check_duplex(dev); + next_tick = 60*HZ; + } else if (tp->nwayset) { + /* Don't screw up a negotiated session! */ + if (tulip_debug > 1) + printk(KERN_INFO"%s: Using NWay-set %s media, csr12 %8.8x.\n", + dev->name, medianame[dev->if_port], csr12); + } else if (tp->medialock) { + ; + } else if (dev->if_port == 3) { + if (csr12 & 2) { /* No 100mbps link beat, revert to 10mbps. */ + if (tulip_debug > 1) + printk(KERN_INFO"%s: No 21143 100baseTx link beat, %8.8x, " + "trying NWay.\n", dev->name, csr12); + t21142_start_nway(dev); + next_tick = 3*HZ; } } else if ((csr12 & 0x7000) != 0x5000) { /* Negotiation failed. Search media types. */ if (tulip_debug > 1) - printk(KERN_INFO"%s: 21142 negotiation failed, status %8.8x.\n", + printk(KERN_INFO"%s: 21143 negotiation failed, status %8.8x.\n", dev->name, csr12); if (!(csr12 & 4)) { /* 10mbps link beat good. */ new_csr6 = 0x82420000; dev->if_port = 0; outl(0, ioaddr + CSR13); outl(0x0003FFFF, ioaddr + CSR14); - outl(t21142_csr15[dev->if_port], ioaddr + CSR15); + outw(t21142_csr15[dev->if_port], ioaddr + CSR15); outl(t21142_csr13[dev->if_port], ioaddr + CSR13); - } else if (csr12 & 0x100) { - new_csr6 = 0x82420200; - dev->if_port = 2; - outl(0, ioaddr + CSR13); - outl(0x0003FFFF, ioaddr + CSR14); - outl(0x0008, ioaddr + CSR15); - outl(0x0001, ioaddr + CSR13); } else { /* Select 100mbps port to check for link beat. */ new_csr6 = 0x83860000; dev->if_port = 3; outl(0, ioaddr + CSR13); outl(0x0003FF7F, ioaddr + CSR14); - outl(8, ioaddr + CSR15); + outw(8, ioaddr + CSR15); outl(1, ioaddr + CSR13); } if (tulip_debug > 1) - printk(KERN_INFO"%s: Testing new 21142 media %s.\n", + printk(KERN_INFO"%s: Testing new 21143 media %s.\n", dev->name, medianame[dev->if_port]); if (new_csr6 != (tp->csr6 & ~0x00D5)) { tp->csr6 &= 0x00D5; @@ -1765,51 +1576,141 @@ static void t21142_timer(unsigned long data) outl(tp->csr6 | 0x0002, ioaddr + CSR6); outl(tp->csr6 | 0x2002, ioaddr + CSR6); } + next_tick = 3*HZ; } + tp->timer.expires = RUN_AT(next_tick); add_timer(&tp->timer); } -static void t21142_lnk_change( struct net_device *dev) +static void t21142_start_nway(struct net_device *dev) +{ + struct tulip_private *tp = (struct tulip_private *)dev->priv; + long ioaddr = dev->base_addr; + int csr14 = ((tp->to_advertise & 0x0780) << 9) | + ((tp->to_advertise&0x0020)<<1) | 0xffbf; + + dev->if_port = 0; + tp->nway = tp->mediasense = 1; + tp->nwayset = tp->lpar = 0; + if (debug > 1) + printk(KERN_DEBUG "%s: Restarting 21143 autonegotiation, %8.8x.\n", + dev->name, csr14); + outl(0x0001, ioaddr + CSR13); + outl(csr14, ioaddr + CSR14); + tp->csr6 = 0x82420000 | (tp->to_advertise & 0x0040 ? 0x0200 : 0); + outl(tp->csr6, ioaddr + CSR6); + if (tp->mtable && tp->mtable->csr15dir) { + outl(tp->mtable->csr15dir, ioaddr + CSR15); + outl(tp->mtable->csr15val, ioaddr + CSR15); + } else + outw(0x0008, ioaddr + CSR15); + outl(0x1301, ioaddr + CSR12); /* Trigger NWAY. */ +} + +static void t21142_lnk_change(struct net_device *dev, int csr5) { struct tulip_private *tp = (struct tulip_private *)dev->priv; long ioaddr = dev->base_addr; int csr12 = inl(ioaddr + CSR12); if (tulip_debug > 1) - printk(KERN_INFO"%s: 21142 link status interrupt %8.8x, CSR5 %x.\n", - dev->name, csr12, inl(ioaddr + CSR5)); - - if ((csr12 & 0x7000) == 0x5000) { - if (csr12 & 0x01800000) { - /* Switch to 100mbps mode. */ - outl(tp->csr6 | 0x0002, ioaddr + CSR6); - if (csr12 & 0x01000000) { - dev->if_port = 5; - tp->csr6 = 0x83860200; - } else { + printk(KERN_INFO"%s: 21143 link status interrupt %8.8x, CSR5 %x, " + "%8.8x.\n", dev->name, csr12, csr5, inl(ioaddr + CSR14)); + + /* If NWay finished and we have a negotiated partner capability. */ + if (tp->nway && !tp->nwayset && (csr12 & 0x7000) == 0x5000) { + int setup_done = 0; + int negotiated = tp->to_advertise & (csr12 >> 16); + tp->lpar = csr12 >> 16; + tp->nwayset = 1; + if (negotiated & 0x0100) dev->if_port = 5; + else if (negotiated & 0x0080) dev->if_port = 3; + else if (negotiated & 0x0040) dev->if_port = 4; + else if (negotiated & 0x0020) dev->if_port = 0; + else { + tp->nwayset = 0; + if ((csr12 & 2) == 0 && (tp->to_advertise & 0x0180)) dev->if_port = 3; - tp->csr6 = 0x83860000; - } - outl(tp->csr6 | 0x2002, ioaddr + CSR6); - } /* Else 10baseT-FD is handled automatically. */ - } else if (dev->if_port == 3) { - if (!(csr12 & 2)) - printk(KERN_INFO"%s: 21142 100baseTx link beat good.\n", - dev->name); - else - dev->if_port = 0; - } else if (dev->if_port == 0) { - if (!(csr12 & 4)) - printk(KERN_INFO"%s: 21142 10baseT link beat good.\n", + } + tp->full_duplex = (media_cap[dev->if_port] & MediaAlwaysFD) ? 1:0; + + if (tulip_debug > 1) { + if (tp->nwayset) + printk(KERN_INFO "%s: Switching to %s based on link " + "negotiation %4.4x & %4.4x = %4.4x.\n", + dev->name, medianame[dev->if_port], tp->to_advertise, + tp->lpar, negotiated); + else + printk(KERN_INFO "%s: Autonegotiation failed, using %s," + " link beat status %4.4x.\n", + dev->name, medianame[dev->if_port], csr12); + } + + if (tp->mtable) { + int i; + for (i = 0; i < tp->mtable->leafcount; i++) + if (tp->mtable->mleaf[i].media == dev->if_port) { + tp->cur_index = i; + select_media(dev, 0); + setup_done = 1; + break; + } + } + if ( ! setup_done) { + tp->csr6 = dev->if_port & 1 ? 0x83860000 : 0x82420000; + if (tp->full_duplex) + tp->csr6 |= 0x0200; + outl(1, ioaddr + CSR13); + } +#if 0 /* Restart shouldn't be needed. */ + outl(tp->csr6 | 0x0000, ioaddr + CSR6); + if (debug > 2) + printk(KERN_DEBUG "%s: Restarting Tx and Rx, CSR5 is %8.8x.\n", + dev->name, inl(ioaddr + CSR5)); +#endif + outl(tp->csr6 | 0x2002, ioaddr + CSR6); + if (debug > 2) + printk(KERN_DEBUG "%s: Setting CSR6 %8.8x/%x CSR12 %8.8x.\n", + dev->name, tp->csr6, inl(ioaddr + CSR6), + inl(ioaddr + CSR12)); + } else if ((tp->nwayset && (csr5 & 0x08000000) + && (dev->if_port == 3 || dev->if_port == 5) + && (csr12 & 2) == 2) || + (tp->nway && (csr5 & (TPLnkFail)))) { + /* Link blew? Maybe restart NWay. */ + del_timer(&tp->timer); + t21142_start_nway(dev); + tp->timer.expires = RUN_AT(3*HZ); + add_timer(&tp->timer); + } else if (dev->if_port == 3 || dev->if_port == 5) { + if (tulip_debug > 1) + printk(KERN_INFO"%s: 21143 %s link beat %s.\n", + dev->name, medianame[dev->if_port], + (csr12 & 2) ? "failed" : "good"); + if ((csr12 & 2) && ! tp->medialock) { + del_timer(&tp->timer); + t21142_start_nway(dev); + tp->timer.expires = RUN_AT(3*HZ); + add_timer(&tp->timer); + } + } else if (dev->if_port == 0 || dev->if_port == 4) { + if ((csr12 & 4) == 0) + printk(KERN_INFO"%s: 21143 10baseT link beat good.\n", dev->name); } else if (!(csr12 & 4)) { /* 10mbps link beat good. */ - printk(KERN_INFO"%s: 21142 10mpbs sensed media.\n", + if (tulip_debug) + printk(KERN_INFO"%s: 21143 10mbps sensed media.\n", + dev->name); + dev->if_port = 0; + } else if (tp->nwayset) { + if (tulip_debug) + printk(KERN_INFO"%s: 21143 using NWay-set %s, csr6 %8.8x.\n", + dev->name, medianame[dev->if_port], tp->csr6); + } else { /* 100mbps link beat good. */ + if (tulip_debug) + printk(KERN_INFO"%s: 21143 100baseTx sensed media.\n", dev->name); - dev->if_port = 0; - } else { /* 100mbps link beat good. */ - printk(KERN_INFO"%s: 21142 100baseTx sensed media.\n", - dev->name); dev->if_port = 3; tp->csr6 = 0x83860000; outl(0x0003FF7F, ioaddr + CSR14); @@ -1818,7 +1719,6 @@ static void t21142_lnk_change( struct net_device *dev) outl(tp->csr6 | 0x2002, ioaddr + CSR6); } } - static void mxic_timer(unsigned long data) { @@ -1837,57 +1737,98 @@ static void mxic_timer(unsigned long data) } } +static void pnic_do_nway(struct net_device *dev) +{ + struct tulip_private *tp = (struct tulip_private *)dev->priv; + long ioaddr = dev->base_addr; + u32 phy_reg = inl(ioaddr + 0xB8); + u32 new_csr6 = tp->csr6 & ~0x40C40200; + + if (phy_reg & 0x78000000) { /* Ignore baseT4 */ + if (phy_reg & 0x20000000) dev->if_port = 5; + else if (phy_reg & 0x40000000) dev->if_port = 3; + else if (phy_reg & 0x10000000) dev->if_port = 4; + else if (phy_reg & 0x08000000) dev->if_port = 0; + tp->nwayset = 1; + new_csr6 = (dev->if_port & 1) ? 0x01860000 : 0x00420000; + outl(0x32 | (dev->if_port & 1), ioaddr + CSR12); + if (dev->if_port & 1) + outl(0x1F868, ioaddr + 0xB8); + if (phy_reg & 0x30000000) { + tp->full_duplex = 1; + new_csr6 |= 0x00000200; + } + if (tulip_debug > 1) + printk(KERN_DEBUG "%s: PNIC autonegotiated status %8.8x, %s.\n", + dev->name, phy_reg, medianame[dev->if_port]); + if (tp->csr6 != new_csr6) { + tp->csr6 = new_csr6; + outl(tp->csr6 | 0x0002, ioaddr + CSR6); /* Restart Tx */ + outl(tp->csr6 | 0x2002, ioaddr + CSR6); + dev->trans_start = jiffies; + } + } +} +static void pnic_lnk_change(struct net_device *dev, int csr5) +{ + struct tulip_private *tp = (struct tulip_private *)dev->priv; + long ioaddr = dev->base_addr; + int phy_reg = inl(ioaddr + 0xB8); + + if (tulip_debug > 1) + printk(KERN_DEBUG "%s: PNIC link changed state %8.8x, CSR5 %8.8x.\n", + dev->name, phy_reg, csr5); + if (inl(ioaddr + CSR5) & TPLnkFail) { + outl((inl(ioaddr + CSR7) & ~TPLnkFail) | TPLnkPass, ioaddr + CSR7); + if (! tp->nwayset || jiffies - dev->trans_start > 1*HZ) { + tp->csr6 = 0x00420000 | (tp->csr6 & 0x0000fdff); + outl(tp->csr6, ioaddr + CSR6); + outl(0x30, ioaddr + CSR12); + outl(0x0201F078, ioaddr + 0xB8); /* Turn on autonegotiation. */ + dev->trans_start = jiffies; + } + } else if (inl(ioaddr + CSR5) & TPLnkPass) { + pnic_do_nway(dev); + outl((inl(ioaddr + CSR7) & ~TPLnkPass) | TPLnkFail, ioaddr + CSR7); + } +} static void pnic_timer(unsigned long data) { struct net_device *dev = (struct net_device *)data; struct tulip_private *tp = (struct tulip_private *)dev->priv; long ioaddr = dev->base_addr; - int csr12 = inl(ioaddr + CSR12); int next_tick = 60*HZ; - int new_csr6 = tp->csr6 & ~0x40C40200; if (media_cap[dev->if_port] & MediaIsMII) { - int negotiated = mdio_read(dev, tp->phys[0], 5) & tp->advertising[0]; - - if (tulip_debug > 1) - printk(KERN_DEBUG "%s: LC82C168 negotiated capability %8.8x, " - "CSR5 %8.8x.\n", - dev->name, negotiated, inl(ioaddr + CSR5)); - - if (negotiated & 0x0380) /* 10 vs 100mbps */ - new_csr6 |= 0x812E0000; - else - new_csr6 |= 0x816E0000; - if (((negotiated & 0x0300) == 0x0100) /* Duplex */ - || (negotiated & 0x00C0) == 0x0040 - || tp->full_duplex_lock) { - tp->full_duplex = 1; - new_csr6 |= 0x0200; - } - if (tulip_debug > 1) - printk(KERN_DEBUG "%s: LC82C168 MII PHY status %4.4x, Link " - "partner report %4.4x, csr6 %8.8x/%8.8x.\n", - dev->name, mdio_read(dev, tp->phys[0], 1), negotiated, - tp->csr6, inl(ioaddr + CSR6)); + if (check_duplex(dev) > 0) + next_tick = 3*HZ; } else { + int csr12 = inl(ioaddr + CSR12); + int new_csr6 = tp->csr6 & ~0x40C40200; int phy_reg = inl(ioaddr + 0xB8); int csr5 = inl(ioaddr + CSR5); if (tulip_debug > 1) - printk(KERN_DEBUG "%s: LC82C168 phy status %8.8x, CSR5 %8.8x.\n", - dev->name, phy_reg, csr5); - + printk(KERN_DEBUG "%s: PNIC timer PHY status %8.8x, %s " + "CSR5 %8.8x.\n", + dev->name, phy_reg, medianame[dev->if_port], csr5); if (phy_reg & 0x04000000) { /* Remote link fault */ - /*outl(0x0201F078, ioaddr + 0xB8);*/ - next_tick = 3*HZ; - } - if (inl(ioaddr + CSR5) & TPLnkFail) { /* 100baseTx link beat */ + outl(0x0201F078, ioaddr + 0xB8); + next_tick = 1*HZ; + tp->nwayset = 0; + } else if (phy_reg & 0x78000000) { /* Ignore baseT4 */ + pnic_do_nway(dev); + next_tick = 60*HZ; + } else if (csr5 & TPLnkFail) { /* 100baseTx link beat */ if (tulip_debug > 1) printk(KERN_DEBUG "%s: %s link beat failed, CSR12 %4.4x, " "CSR5 %8.8x, PHY %3.3x.\n", dev->name, medianame[dev->if_port], csr12, inl(ioaddr + CSR5), inl(ioaddr + 0xB8)); + next_tick = 3*HZ; if (tp->medialock) { + } else if (tp->nwayset && (dev->if_port & 1)) { + next_tick = 1*HZ; } else if (dev->if_port == 0) { dev->if_port = 3; outl(0x33, ioaddr + CSR12); @@ -1899,162 +1840,187 @@ static void pnic_timer(unsigned long data) new_csr6 = 0x00420000; outl(0x1F078, ioaddr + 0xB8); } - new_csr6 |= (tp->csr6 & 0xfdff); - next_tick = 3*HZ; - } else - new_csr6 = tp->csr6; - if (tp->full_duplex_lock || (phy_reg & 0x30000000) != 0) { - tp->full_duplex = 1; - new_csr6 |= 0x00000200; + if (tp->csr6 != new_csr6) { + tp->csr6 = new_csr6; + outl(tp->csr6 | 0x0002, ioaddr + CSR6); /* Restart Tx */ + outl(tp->csr6 | 0x2002, ioaddr + CSR6); + dev->trans_start = jiffies; + if (tulip_debug > 1) + printk(KERN_INFO "%s: Changing PNIC configuration to %s " + "%s-duplex, CSR6 %8.8x.\n", + dev->name, medianame[dev->if_port], + tp->full_duplex ? "full" : "half", new_csr6); + } } } - if (tp->csr6 != new_csr6) { - tp->csr6 = new_csr6; - outl(tp->csr6 | 0x0002, ioaddr + CSR6); /* Restart Tx */ - outl(tp->csr6 | 0x2002, ioaddr + CSR6); - dev->trans_start = jiffies; - if (tulip_debug > 0) /* Gurppp, should be >1 */ - printk(KERN_INFO "%s: Changing PNIC configuration to %s-duplex, " - "CSR6 %8.8x.\n", - dev->name, tp->full_duplex ? "full" : "half", new_csr6); - } tp->timer.expires = RUN_AT(next_tick); add_timer(&tp->timer); } -static void tulip_tx_timeout(struct net_device *dev) +static void comet_timer(unsigned long data) { - struct tulip_private *tp = (struct tulip_private *)dev->priv; - long ioaddr = dev->base_addr; - - printk("%s: transmit timed out\n", dev->name); - - if (media_cap[dev->if_port] & MediaIsMII) { - /* Do nothing -- the media monitor should handle this. */ -#if 0 - if (tulip_debug > 1) -#endif - printk(KERN_WARNING "%s: Transmit timeout using MII device.\n", - dev->name); - dev->trans_start = jiffies; - return; - } else if (tp->chip_id == DC21040) { - if (inl(ioaddr + CSR12) & 0x0002) { - printk(KERN_INFO "%s: transmit timed out, switching to %s media.\n", - dev->name, dev->if_port ? "10baseT" : "AUI"); - dev->if_port ^= 1; - outl(dev->if_port ? 0x0000000C : 0x00000004, ioaddr + CSR13); - } - dev->trans_start = jiffies; - return; - } else if (tp->chip_id == DC21041) { - u32 csr12 = inl(ioaddr + CSR12); - - printk(KERN_WARNING "%s: 21041 transmit timed out, status %8.8x, CSR12 %8.8x," - " CSR13 %8.8x, CSR14 %8.8x, resetting...\n", - dev->name, inl(ioaddr + CSR5), csr12, - inl(ioaddr + CSR13), inl(ioaddr + CSR14)); - tp->mediasense = 1; - if (dev->if_port == 1 || dev->if_port == 2) - if (csr12 & 0x0004) { - dev->if_port = 2 - dev->if_port; - } else - dev->if_port = 0; - else - dev->if_port = 1; - select_media(dev, 0); - tp->stats.tx_errors++; - dev->trans_start = jiffies; - return; - } else if (tp->chip_id == DC21140 || tp->chip_id == DC21142 - || tp->chip_id == MX98713) { - /* Stop the transmit process. */ - outl(tp->csr6 | 0x0002, ioaddr + CSR6); - printk(KERN_WARNING "%s: 21140 transmit timed out, status %8.8x, " - "SIA %8.8x %8.8x %8.8x %8.8x, resetting...\n", - dev->name, inl(ioaddr + CSR5), inl(ioaddr + CSR12), - inl(ioaddr + CSR13), inl(ioaddr + CSR14), inl(ioaddr + CSR15)); - if (tp->mtable) { - if (--tp->cur_index < 0) { - /* We start again, but should instead look for default. */ - tp->cur_index = tp->mtable->leafcount - 1; - } - select_media(dev, 0); - printk(KERN_WARNING "%s: transmit timed out, switching to %s media.\n", - dev->name, dev->if_port ? "100baseTx" : "10baseT"); - } - outl(tp->csr6 | 0x2002, ioaddr + CSR6); - tp->stats.tx_errors++; - dev->trans_start = jiffies; - return; - } else - printk(KERN_WARNING "%s: transmit timed out, status %8.8x, CSR12 %8.8x," - " resetting...\n", - dev->name, inl(ioaddr + CSR5), inl(ioaddr + CSR12)); -#ifdef way_too_many_messages - printk(" Rx ring %8.8x: ", (int)tp->rx_ring); - for (i = 0; i < RX_RING_SIZE; i++) - printk(" %8.8x", (unsigned int)tp->rx_ring[i].status); - printk("\n Tx ring %8.8x: ", (int)tp->tx_ring); - for (i = 0; i < TX_RING_SIZE; i++) - printk(" %8.8x", (unsigned int)tp->tx_ring[i].status); - printk("\n"); -#endif + struct net_device *dev = (struct net_device *)data; + struct tulip_private *tp = (struct tulip_private *)dev->priv; + long ioaddr = dev->base_addr; + int next_tick = 60*HZ; - /* Perhaps we should reinitialize the hardware here. */ - dev->if_port = 0; - /* Stop and restart the chip's Tx processes . */ - outl(tp->csr6 | 0x0002, ioaddr + CSR6); - outl(tp->csr6 | 0x2002, ioaddr + CSR6); - /* Trigger an immediate transmit demand. */ - outl(0, ioaddr + CSR1); - - dev->trans_start = jiffies; - tp->stats.tx_errors++; - return; + if (tulip_debug > 1) + printk(KERN_DEBUG "%s: Comet link status %4.4x partner capability " + "%4.4x.\n", + dev->name, inl(ioaddr + 0xB8), inl(ioaddr + 0xC8)); + tp->timer.expires = RUN_AT(next_tick); + add_timer(&tp->timer); } - -/* Initialize the Rx and Tx rings, along with various 'dev' bits. */ -static void -tulip_init_ring(struct net_device *dev) +static void tulip_tx_timeout(struct net_device *dev) { struct tulip_private *tp = (struct tulip_private *)dev->priv; - int i; - - tp->tx_full = 0; - tp->cur_rx = tp->cur_tx = 0; - tp->dirty_rx = tp->dirty_tx = 0; + long ioaddr = dev->base_addr; - for (i = 0; i < RX_RING_SIZE; i++) { - tp->rx_ring[i].status = 0x80000000; /* Owned by Tulip chip */ - tp->rx_ring[i].length = PKT_BUF_SZ; - { - /* Note the receive buffer must be longword aligned. - dev_alloc_skb() provides 16 byte alignment. But do *not* - use skb_reserve() to align the IP header! */ - struct sk_buff *skb; - skb = DEV_ALLOC_SKB(PKT_BUF_SZ); - tp->rx_skbuff[i] = skb; - if (skb == NULL) - break; /* Bad news! */ - skb->dev = dev; /* Mark as being used by this device. */ - tp->rx_ring[i].buffer1 = virt_to_bus(skb->tail); - } - tp->rx_ring[i].buffer2 = virt_to_bus(&tp->rx_ring[i+1]); - } + if (media_cap[dev->if_port] & MediaIsMII) { + /* Do nothing -- the media monitor should handle this. */ + if (tulip_debug > 1) + printk(KERN_WARNING "%s: Transmit timeout using MII device.\n", + dev->name); + } else if (tp->chip_id == DC21040) { + if ( !tp->medialock && inl(ioaddr + CSR12) & 0x0002) { + dev->if_port = (dev->if_port == 2 ? 0 : 2); + printk(KERN_INFO "%s: transmit timed out, switching to " + "%s.\n", + dev->name, medianame[dev->if_port]); + select_media(dev, 0); + } + dev->trans_start = jiffies; + return; + } else if (tp->chip_id == DC21041) { + int csr12 = inl(ioaddr + CSR12); + + printk(KERN_WARNING "%s: 21041 transmit timed out, status %8.8x, " + "CSR12 %8.8x, CSR13 %8.8x, CSR14 %8.8x, resetting...\n", + dev->name, inl(ioaddr + CSR5), csr12, + inl(ioaddr + CSR13), inl(ioaddr + CSR14)); + tp->mediasense = 1; + if ( ! tp->medialock) { + if (dev->if_port == 1 || dev->if_port == 2) + if (csr12 & 0x0004) { + dev->if_port = 2 - dev->if_port; + } else + dev->if_port = 0; + else + dev->if_port = 1; + select_media(dev, 0); + } + } else if (tp->chip_id == DC21140 || tp->chip_id == DC21142 + || tp->chip_id == MX98713 || tp->chip_id == COMPEX9881) { + printk(KERN_WARNING "%s: 21140 transmit timed out, status %8.8x, " + "SIA %8.8x %8.8x %8.8x %8.8x, resetting...\n", + dev->name, inl(ioaddr + CSR5), inl(ioaddr + CSR12), + inl(ioaddr + CSR13), inl(ioaddr + CSR14), inl(ioaddr + CSR15)); + if ( ! tp->medialock && tp->mtable) { + do + --tp->cur_index; + while (tp->cur_index >= 0 + && (media_cap[tp->mtable->mleaf[tp->cur_index].media] + & MediaIsFD)); + if (--tp->cur_index < 0) { + /* We start again, but should instead look for default. */ + tp->cur_index = tp->mtable->leafcount - 1; + } + select_media(dev, 0); + printk(KERN_WARNING "%s: transmit timed out, switching to %s " + "media.\n", dev->name, medianame[dev->if_port]); + } + } else { + printk(KERN_WARNING "%s: Transmit timed out, status %8.8x, CSR12 " + "%8.8x, resetting...\n", + dev->name, inl(ioaddr + CSR5), inl(ioaddr + CSR12)); + dev->if_port = 0; + } + +#if defined(way_too_many_messages) + if (tulip_debug > 3) { + int i; + for (i = 0; i < RX_RING_SIZE; i++) { + u8 *buf = (u8 *)(tp->rx_ring[i].buffer1); + int j; + printk(KERN_DEBUG "%2d: %8.8x %8.8x %8.8x %8.8x " + "%2.2x %2.2x %2.2x.\n", + i, (unsigned int)tp->rx_ring[i].status, + (unsigned int)tp->rx_ring[i].length, + (unsigned int)tp->rx_ring[i].buffer1, + (unsigned int)tp->rx_ring[i].buffer2, + buf[0], buf[1], buf[2]); + for (j = 0; buf[j] != 0xee && j < 1600; j++) + if (j < 100) printk(" %2.2x", buf[j]); + printk(" j=%d.\n", j); + } + printk(KERN_DEBUG " Rx ring %8.8x: ", (int)tp->rx_ring); + for (i = 0; i < RX_RING_SIZE; i++) + printk(" %8.8x", (unsigned int)tp->rx_ring[i].status); + printk("\n" KERN_DEBUG " Tx ring %8.8x: ", (int)tp->tx_ring); + for (i = 0; i < TX_RING_SIZE; i++) + printk(" %8.8x", (unsigned int)tp->tx_ring[i].status); + printk("\n"); + } +#endif + + /* Stop and restart the chip's Tx processes . */ + outl(tp->csr6 | 0x0002, ioaddr + CSR6); + outl(tp->csr6 | 0x2002, ioaddr + CSR6); + /* Trigger an immediate transmit demand. */ + outl(0, ioaddr + CSR1); + + dev->trans_start = jiffies; + tp->stats.tx_errors++; + return; +} + + +/* Initialize the Rx and Tx rings, along with various 'dev' bits. */ +static void tulip_init_ring(struct net_device *dev) +{ + struct tulip_private *tp = (struct tulip_private *)dev->priv; + int i; + + tp->tx_full = 0; + tp->cur_rx = tp->cur_tx = 0; + tp->dirty_rx = tp->dirty_tx = 0; + tp->susp_rx = 0; + tp->ttimer = 0; + tp->nir = 0; + + for (i = 0; i < RX_RING_SIZE; i++) { + tp->rx_ring[i].status = 0x00000000; + tp->rx_ring[i].length = cpu_to_le32(PKT_BUF_SZ); + tp->rx_ring[i].buffer2 = virt_to_le32desc(&tp->rx_ring[i+1]); + tp->rx_skbuff[i] = NULL; + } /* Mark the last entry as wrapping the ring. */ - tp->rx_ring[i-1].length = PKT_BUF_SZ | 0x02000000; - tp->rx_ring[i-1].buffer2 = virt_to_bus(&tp->rx_ring[0]); + tp->rx_ring[i-1].length = cpu_to_le32(PKT_BUF_SZ | DESC_RING_WRAP); + tp->rx_ring[i-1].buffer2 = virt_to_le32desc(&tp->rx_ring[0]); + + for (i = 0; i < RX_RING_SIZE; i++) { + /* Note the receive buffer must be longword aligned. + dev_alloc_skb() provides 16 byte alignment. But do *not* + use skb_reserve() to align the IP header! */ + struct sk_buff *skb = dev_alloc_skb(PKT_BUF_SZ); + tp->rx_skbuff[i] = skb; + if (skb == NULL) + break; + skb->dev = dev; /* Mark as being used by this device. */ + tp->rx_ring[i].status = cpu_to_le32(DescOwned); /* Owned by Tulip chip */ + tp->rx_ring[i].buffer1 = virt_to_le32desc(skb->tail); + } + tp->dirty_rx = (unsigned int)(i - RX_RING_SIZE); /* The Tx buffer descriptor is filled in as needed, but we do need to clear the ownership bit. */ for (i = 0; i < TX_RING_SIZE; i++) { tp->tx_skbuff[i] = 0; tp->tx_ring[i].status = 0x00000000; - tp->tx_ring[i].buffer2 = virt_to_bus(&tp->tx_ring[i+1]); + tp->tx_ring[i].buffer2 = virt_to_le32desc(&tp->tx_ring[i+1]); } - tp->tx_ring[i-1].buffer2 = virt_to_bus(&tp->tx_ring[0]); + tp->tx_ring[i-1].buffer2 = virt_to_le32desc(&tp->tx_ring[0]); } static int @@ -2065,8 +2031,8 @@ tulip_start_xmit(struct sk_buff *skb, struct net_device *dev) u32 flag; unsigned long cpuflags; - /* Caution: the write order is important here, set the base address - with the "ownership" bits last. */ + /* Caution: the write order is important here, set the field + with the ownership bits last. */ spin_lock_irqsave(&tp->tx_lock, cpuflags); @@ -2074,25 +2040,24 @@ tulip_start_xmit(struct sk_buff *skb, struct net_device *dev) entry = tp->cur_tx % TX_RING_SIZE; tp->tx_skbuff[entry] = skb; - tp->tx_ring[entry].buffer1 = virt_to_bus(skb->data); + tp->tx_ring[entry].buffer1 = virt_to_le32desc(skb->data); if (tp->cur_tx - tp->dirty_tx < TX_RING_SIZE/2) {/* Typical path */ - flag = 0x60000000; /* No interrupt */ + flag = 0x60000000; /* No interrupt */ } else if (tp->cur_tx - tp->dirty_tx == TX_RING_SIZE/2) { - flag = 0xe0000000; /* Tx-done intr. */ + flag = 0xe0000000; /* Tx-done intr. */ } else if (tp->cur_tx - tp->dirty_tx < TX_RING_SIZE - 2) { - flag = 0x60000000; /* No Tx-done intr. */ - } else { - /* Leave room for set_rx_mode() to fill entries. */ - flag = 0xe0000000; /* Tx-done intr. */ - tp->tx_full = 1; - netif_stop_queue(dev); + flag = 0x60000000; /* No Tx-done intr. */ + } else { /* Leave room for set_rx_mode() to fill entries. */ + tp->tx_full = 1; + flag = 0xe0000000; /* Tx-done intr. */ + netif_stop_queue(dev); } if (entry == TX_RING_SIZE-1) - flag |= 0xe2000000; + flag = 0xe0000000 | DESC_RING_WRAP; - tp->tx_ring[entry].length = skb->len | flag; - tp->tx_ring[entry].status = 0x80000000; /* Pass ownership to the chip. */ + tp->tx_ring[entry].length = cpu_to_le32(skb->len | flag); + tp->tx_ring[entry].status = cpu_to_le32(DescOwned); tp->cur_tx++; spin_unlock_irqrestore(&tp->tx_lock, cpuflags); @@ -2106,26 +2071,22 @@ tulip_start_xmit(struct sk_buff *skb, struct net_device *dev) /* The interrupt handler does all of the Rx thread work and cleans up after the Tx thread. */ -static void tulip_interrupt IRQ(int irq, void *dev_instance, struct pt_regs *regs) +static void tulip_interrupt(int irq, void *dev_instance, struct pt_regs *regs) { -#ifdef SA_SHIRQ /* Use the now-standard shared IRQ implementation. */ struct net_device *dev = (struct net_device *)dev_instance; -#else - struct net_device *dev = (struct net_device *)(irq2dev_map[irq]); -#endif - - struct tulip_private *tp; - long ioaddr; - int csr5, work_budget = max_interrupt_work; - - if (dev == NULL) { - printk (KERN_ERR" tulip_interrupt(): irq %d for unknown device.\n", - irq); - return; - } + struct tulip_private *tp = (struct tulip_private *)dev->priv; + long ioaddr = dev->base_addr; + int csr5; + int entry; + int missed; + int rx = 0; + int tx = 0; + int oi = 0; + int maxrx = RX_RING_SIZE; + int maxtx = TX_RING_SIZE; + int maxoi = TX_RING_SIZE; - ioaddr = dev->base_addr; - tp = (struct tulip_private *)dev->priv; + tp->nir++; do { csr5 = inl(ioaddr + CSR5); @@ -2139,10 +2100,12 @@ static void tulip_interrupt IRQ(int irq, void *dev_instance, struct pt_regs *reg if ((csr5 & (NormalIntr|AbnormalIntr)) == 0) break; - if (csr5 & (RxIntr | RxNoBuf)) - work_budget -= tulip_rx(dev); + if (csr5 & (RxIntr | RxNoBuf)) { + rx += tulip_rx(dev); + tulip_refill_rx(dev); + } - if (csr5 & (TxNoBuf | TxDied | TxIntr)) { + if (csr5 & (TxNoBuf | TxDied | TxIntr | TimerInt)) { unsigned int dirty_tx; spin_lock(&tp->tx_lock); @@ -2150,14 +2113,14 @@ static void tulip_interrupt IRQ(int irq, void *dev_instance, struct pt_regs *reg for (dirty_tx = tp->dirty_tx; tp->cur_tx - dirty_tx > 0; dirty_tx++) { int entry = dirty_tx % TX_RING_SIZE; - int status = tp->tx_ring[entry].status; + int status = le32_to_cpu(tp->tx_ring[entry].status); if (status < 0) - break; /* It still hasn't been Txed */ + break; /* It still has not been Txed */ /* Check for Rx filter setup frames. */ if (tp->tx_skbuff[entry] == NULL) continue; - + if (status & 0x8000) { /* There was an major error, log it. */ #ifndef final_version @@ -2179,7 +2142,7 @@ static void tulip_interrupt IRQ(int irq, void *dev_instance, struct pt_regs *reg #ifdef ETHER_STATS if (status & 0x0001) tp->stats.tx_deferred++; #endif - tp->stats.tx_bytes += tp->tx_ring[entry].length & 0x7ff; + tp->stats.tx_bytes += tp->tx_skbuff[entry]->len; tp->stats.collisions += (status >> 3) & 15; tp->stats.tx_packets++; } @@ -2187,6 +2150,7 @@ static void tulip_interrupt IRQ(int irq, void *dev_instance, struct pt_regs *reg /* Free the original skb. */ dev_kfree_skb_irq(tp->tx_skbuff[entry]); tp->tx_skbuff[entry] = 0; + tx++; } #ifndef final_version @@ -2204,12 +2168,11 @@ static void tulip_interrupt IRQ(int irq, void *dev_instance, struct pt_regs *reg } tp->dirty_tx = dirty_tx; - if (csr5 & TxDied) { - if (tulip_debug > 1) - printk(KERN_WARNING "%s: The transmitter stopped!" - " CSR5 is %x, CSR6 %x.\n", - dev->name, csr5, inl(ioaddr + CSR6)); + if (tulip_debug > 2) + printk(KERN_WARNING "%s: The transmitter stopped." + " CSR5 is %x, CSR6 %x, new CSR6 %x.\n", + dev->name, csr5, inl(ioaddr + CSR6), tp->csr6); outl(tp->csr6 | 0x0002, ioaddr + CSR6); outl(tp->csr6 | 0x2002, ioaddr + CSR6); } @@ -2218,6 +2181,8 @@ static void tulip_interrupt IRQ(int irq, void *dev_instance, struct pt_regs *reg /* Log errors. */ if (csr5 & AbnormalIntr) { /* Abnormal error summary bit. */ + if (csr5 == 0xffffffff) + break; if (csr5 & TxJabber) tp->stats.tx_errors++; if (csr5 & TxFIFOUnderflow) { if ((tp->csr6 & 0xC000) != 0xC000) @@ -2227,117 +2192,177 @@ static void tulip_interrupt IRQ(int irq, void *dev_instance, struct pt_regs *reg /* Restart the transmit process. */ outl(tp->csr6 | 0x0002, ioaddr + CSR6); outl(tp->csr6 | 0x2002, ioaddr + CSR6); + outl(0, ioaddr + CSR1); } if (csr5 & RxDied) { /* Missed a Rx frame. */ tp->stats.rx_errors++; tp->stats.rx_missed_errors += inl(ioaddr + CSR8) & 0xffff; + outl(tp->csr6 | 0x2002, ioaddr + CSR6); } - if (csr5 & TimerInt) { - printk(KERN_ERR "%s: Something Wicked happened! %8.8x.\n", - dev->name, csr5); - /* Hmmmmm, it's not clear what to do here. */ + if (csr5 & (TPLnkPass | TPLnkFail | 0x08000000)) { + if (tp->link_change) + (tp->link_change)(dev, csr5); } - if (csr5 & (TPLnkPass | TPLnkFail | 0x08000000) - && tp->chip_id == DC21142) { - if (tulip_debug > 1) - printk(KERN_INFO"%s: 21142 link change, CSR5 = %8.8x.\n", - dev->name, csr5); - t21142_lnk_change(dev); + if (csr5 & SytemError) { + printk(KERN_ERR "%s: (%lu) System Error occured\n", dev->name, tp->nir); } /* Clear all error sources, included undocumented ones! */ outl(0x0800f7ba, ioaddr + CSR5); + oi++; + } + if (csr5 & TimerInt) { +#if 0 + if (tulip_debug > 2) + printk(KERN_ERR "%s: Re-enabling interrupts, %8.8x.\n", + dev->name, csr5); + outl(tulip_tbl[tp->chip_id].valid_intrs, ioaddr + CSR7); +#endif + tp->ttimer = 0; + oi++; } - if (--work_budget < 0) { + if (tx > maxtx || rx > maxrx || oi > maxoi) { if (tulip_debug > 1) - printk(KERN_WARNING "%s: Too much work at interrupt, " - "csr5=0x%8.8x.\n", dev->name, csr5); + printk(KERN_WARNING "%s: Too much work during an interrupt, " + "csr5=0x%8.8x. (%lu) (%d,%d,%d)\n", dev->name, csr5, tp->nir, tx, rx, oi); /* Acknowledge all interrupt sources. */ - outl(0x8001ffff, ioaddr + CSR5); -#ifdef notdef - /* Clear all but standard interrupt sources. */ - outl((~csr5) & 0x0001ebef, ioaddr + CSR7); +#if 0 + /* Clear all interrupting sources, set timer to re-enable. */ + outl(((~csr5) & 0x0001ebef) | NormalIntr | AbnormalIntr | TimerInt, + ioaddr + CSR7); + outl(12, ioaddr + CSR11); + tp->ttimer = 1; #endif break; } } while (1); - if (tulip_debug > 3) + tulip_refill_rx(dev); + + /* check if we card is in suspend mode */ + entry = tp->dirty_rx % RX_RING_SIZE; + if (tp->rx_skbuff[entry] == NULL) { + if (tulip_debug > 1) + printk(KERN_WARNING "%s: in rx suspend mode: (%lu) (tp->cur_rx = %u, ttimer = %d, rx = %d) go/stay in suspend mode\n", dev->name, tp->nir, tp->cur_rx, tp->ttimer, rx); + if (tp->ttimer == 0 || (inl(ioaddr + CSR11) & 0xffff) == 0) { + if (tulip_debug > 1) + printk(KERN_WARNING "%s: in rx suspend mode: (%lu) set timer\n", dev->name, tp->nir); + outl(tulip_tbl[tp->chip_id].valid_intrs | TimerInt, + ioaddr + CSR7); + outl(TimerInt, ioaddr + CSR5); + outl(12, ioaddr + CSR11); + tp->ttimer = 1; + } + } + + if ((missed = inl(ioaddr + CSR8) & 0x1ffff)) { + tp->stats.rx_dropped += missed & 0x10000 ? 0x10000 : missed; + } + + if (tulip_debug > 4) printk(KERN_DEBUG "%s: exiting interrupt, csr5=%#4.4x.\n", dev->name, inl(ioaddr + CSR5)); - return; } -static int -tulip_rx(struct net_device *dev) +static int tulip_refill_rx(struct net_device *dev) +{ + struct tulip_private *tp = (struct tulip_private *)dev->priv; + int entry; + int refilled = 0; + + /* Refill the Rx ring buffers. */ + for (; tp->cur_rx - tp->dirty_rx > 0; tp->dirty_rx++) { + entry = tp->dirty_rx % RX_RING_SIZE; + if (tp->rx_skbuff[entry] == NULL) { + struct sk_buff *skb; + skb = tp->rx_skbuff[entry] = dev_alloc_skb(PKT_BUF_SZ); + if (skb == NULL) + break; + skb->dev = dev; /* Mark as being used by this device. */ + tp->rx_ring[entry].buffer1 = virt_to_le32desc(skb->tail); + refilled++; + } + tp->rx_ring[entry].status = cpu_to_le32(DescOwned); + } + return refilled; +} + +static int tulip_rx(struct net_device *dev) { struct tulip_private *tp = (struct tulip_private *)dev->priv; int entry = tp->cur_rx % RX_RING_SIZE; int rx_work_limit = tp->dirty_rx + RX_RING_SIZE - tp->cur_rx; - int work_done = 0; + int received = 0; if (tulip_debug > 4) printk(KERN_DEBUG " In tulip_rx(), entry %d %8.8x.\n", entry, tp->rx_ring[entry].status); - /* If we own the next entry, it's a new packet. Send it up. */ - while (tp->rx_ring[entry].status >= 0) { - s32 status = tp->rx_ring[entry].status; + /* If we own the next entry, it is a new packet. Send it up. */ + while ( ! (tp->rx_ring[entry].status & cpu_to_le32(DescOwned))) { + s32 status = le32_to_cpu(tp->rx_ring[entry].status); + if (tulip_debug > 5) + printk(KERN_DEBUG "%s: In tulip_rx(), entry %d %8.8x.\n", + dev->name, entry, status); if (--rx_work_limit < 0) break; - if ((status & 0x0300) != 0x0300) { - if ((status & 0xffff) != 0x7fff) { /* Ingore earlier buffers. */ - if (tulip_debug > 1) - printk(KERN_WARNING "%s: Oversized Ethernet frame spanned " - "multiple buffers, status %8.8x!\n", + if ((status & 0x38008300) != 0x0300) { + if ((status & 0x38000300) != 0x0300) { + /* Ingore earlier buffers. */ + if ((status & 0xffff) != 0x7fff) { + if (tulip_debug > 1) + printk(KERN_WARNING "%s: Oversized Ethernet frame " + "spanned multiple buffers, status %8.8x!\n", + dev->name, status); + tp->stats.rx_length_errors++; + } + } else if (status & RxDescFatalErr) { + /* There was a fatal error. */ + if (tulip_debug > 2) + printk(KERN_DEBUG "%s: Receive error, Rx status %8.8x.\n", dev->name, status); - tp->stats.rx_length_errors++; + tp->stats.rx_errors++; /* end of a packet.*/ + if (status & 0x0890) tp->stats.rx_length_errors++; + if (status & 0x0004) tp->stats.rx_frame_errors++; + if (status & 0x0002) tp->stats.rx_crc_errors++; + if (status & 0x0001) tp->stats.rx_fifo_errors++; } - } else if (status & 0x8000) { - /* There was a fatal error. */ - if (tulip_debug > 2) - printk(KERN_DEBUG "%s: Receive error, Rx status %8.8x.\n", - dev->name, status); - tp->stats.rx_errors++; /* end of a packet.*/ - if (status & 0x0890) tp->stats.rx_length_errors++; - if (status & 0x0004) tp->stats.rx_frame_errors++; - if (status & 0x0002) tp->stats.rx_crc_errors++; - if (status & 0x0001) tp->stats.rx_fifo_errors++; } else { /* Omit the four octet CRC from the length. */ - short pkt_len = (status >> 16) - 4; + short pkt_len = ((status >> 16) & 0x7ff) - 4; struct sk_buff *skb; - /* Check if the packet is long enough to just accept without - copying to a properly sized skbuff. */ +#ifndef final_version + if (pkt_len > 1518) { + printk(KERN_WARNING "%s: Bogus packet size of %d (%#x).\n", + dev->name, pkt_len, pkt_len); + pkt_len = 1518; + tp->stats.rx_length_errors++; + } +#endif + /* Check if the packet is long enough to accept without copying + to a minimally-sized skbuff. */ if (pkt_len < rx_copybreak - && (skb = DEV_ALLOC_SKB(pkt_len+2)) != NULL) { + && (skb = dev_alloc_skb(pkt_len + 2)) != NULL) { skb->dev = dev; skb_reserve(skb, 2); /* 16 byte align the IP header */ -#if LINUX_VERSION_CODE < 0x20200 || defined(__alpha__) - memcpy(skb_put(skb, pkt_len), - bus_to_virt(tp->rx_ring[entry].buffer1), pkt_len); -#else - eth_copy_and_sum(skb, bus_to_virt(tp->rx_ring[entry].buffer1), - pkt_len, 0); +#if ! defined(__alpha__) + eth_copy_and_sum(skb, tp->rx_skbuff[entry]->tail, pkt_len, 0); skb_put(skb, pkt_len); +#else + memcpy(skb_put(skb, pkt_len), tp->rx_skbuff[entry]->tail, + pkt_len); #endif - work_done++; } else { /* Pass up the skb already on the Rx ring. */ - skb = tp->rx_skbuff[entry]; + char *temp = skb_put(skb = tp->rx_skbuff[entry], pkt_len); tp->rx_skbuff[entry] = NULL; #ifndef final_version - { - void *temp = skb_put(skb, pkt_len); - if (bus_to_virt(tp->rx_ring[entry].buffer1) != temp) - printk(KERN_ERR "%s: Internal consistency error! The " - "skbuff addresses do not match in tulip_rx:" - " %p vs. %p / %p.\n", dev->name, - bus_to_virt(tp->rx_ring[entry].buffer1), - skb->head, temp); - } -#else - skb_put(skb, pkt_len); + if (le32desc_to_virt(tp->rx_ring[entry].buffer1) != temp) + printk(KERN_ERR "%s: Internal fault: The skbuff addresses " + "do not match in tulip_rx: %p vs. %p / %p.\n", + dev->name, + le32desc_to_virt(tp->rx_ring[entry].buffer1), + skb->head, temp); #endif } skb->protocol = eth_type_trans(skb, dev); @@ -2346,25 +2371,11 @@ tulip_rx(struct net_device *dev) tp->stats.rx_packets++; tp->stats.rx_bytes += pkt_len; } + received++; entry = (++tp->cur_rx) % RX_RING_SIZE; } - /* Refill the Rx ring buffers. */ - for (; tp->cur_rx - tp->dirty_rx > 0; tp->dirty_rx++) { - entry = tp->dirty_rx % RX_RING_SIZE; - if (tp->rx_skbuff[entry] == NULL) { - struct sk_buff *skb; - skb = tp->rx_skbuff[entry] = DEV_ALLOC_SKB(PKT_BUF_SZ); - if (skb == NULL) - break; - skb->dev = dev; /* Mark as being used by this device. */ - tp->rx_ring[entry].buffer1 = virt_to_bus(skb->tail); - work_done++; - } - tp->rx_ring[entry].status = 0x80000000; - } - - return work_done; + return received; } static int @@ -2382,22 +2393,20 @@ tulip_close(struct net_device *dev) /* Disable interrupts by clearing the interrupt mask. */ outl(0x00000000, ioaddr + CSR7); - /* Stop the chip's Tx and Rx processes. */ + /* Stop the Tx and Rx processes. */ outl(inl(ioaddr + CSR6) & ~0x2002, ioaddr + CSR6); /* 21040 -- Leave the card in 10baseT state. */ if (tp->chip_id == DC21040) outl(0x00000004, ioaddr + CSR13); - tp->stats.rx_missed_errors += inl(ioaddr + CSR8) & 0xffff; + if (inl(ioaddr + CSR6) != 0xffffffff) + tp->stats.rx_missed_errors += inl(ioaddr + CSR8) & 0xffff; del_timer(&tp->timer); -#ifdef SA_SHIRQ free_irq(dev->irq, dev); -#else - free_irq(dev->irq); - irq2dev_map[dev->irq] = 0; -#endif + + dev->if_port = tp->saved_if_port; /* Free all the skbuffs in the Rx queue. */ for (i = 0; i < RX_RING_SIZE; i++) { @@ -2416,6 +2425,9 @@ tulip_close(struct net_device *dev) tp->tx_skbuff[i] = 0; } + /* Leave the driver in snooze, not sleep, mode. */ + if (tp->flags & HAS_PWRDWN) + pci_write_config_dword(tp->pdev, 0x40, 0x40000000); MOD_DEC_USE_COUNT; @@ -2434,7 +2446,7 @@ tulip_get_stats(struct net_device *dev) return &tp->stats; } -#ifdef HAVE_PRIVATE_IOCTL + /* Provide ioctl() calls to examine the MII xcvr state. */ static int private_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) { @@ -2446,31 +2458,32 @@ static int private_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) switch(cmd) { case SIOCDEVPRIVATE: /* Get the address of the PHY in use. */ - if (tp->mtable && tp->mtable->has_mii) + if (tp->mii_cnt) data[0] = phy; - else if (tp->chip_id == DC21142) + else if (tp->flags & HAS_NWAY143) data[0] = 32; + else if (tp->chip_id == COMET) + data[0] = 1; else return -ENODEV; - return 0; case SIOCDEVPRIVATE+1: /* Read the specified MII register. */ - if (data[0] == 32) { /* 21142 pseudo-MII */ + if (data[0] == 32 && (tp->flags & HAS_NWAY143)) { int csr12 = inl(ioaddr + CSR12); int csr14 = inl(ioaddr + CSR14); switch (data[1]) { case 0: { - data[3] = ((csr14<<13)&0x4000) + ((csr14<<5)&0x1000); + data[3] = (csr14<<5) & 0x1000; break; } case 1: data[3] = 0x7848 + ((csr12&0x7000) == 0x5000 ? 0x20 : 0) + (csr12&0x06 ? 0x04 : 0); break; case 4: { - int csr14 = inl(ioaddr + CSR14); - data[3] = ((csr14>>9)&0x0380) + ((csr14>>1)&0x20) + 1; + data[3] = ((csr14>>9)&0x07C0) + + ((inl(ioaddr + CSR6)>>3)&0x0040) + ((csr14>>1)&0x20) + 1; break; } - case 5: data[3] = inl(ioaddr + CSR12) >> 16; break; + case 5: data[3] = csr12 >> 16; break; default: data[3] = 0; break; } } else { @@ -2481,9 +2494,11 @@ static int private_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) } return 0; case SIOCDEVPRIVATE+2: /* Write the specified MII register */ - if (!suser()) + if (!capable(CAP_NET_ADMIN)) return -EPERM; - if (data[0] == 32) { /* 21142 pseudo-MII */ + if (data[0] == 32 && (tp->flags & HAS_NWAY143)) { + if (data[1] == 5) + tp->to_advertise = data[2]; } else { save_flags(flags); cli(); @@ -2497,7 +2512,7 @@ static int private_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) return -EOPNOTSUPP; } -#endif /* HAVE_PRIVATE_IOCTL */ + /* Set or clear the multicast filter for this adaptor. Note that we only use exclusion around actually queueing the @@ -2508,9 +2523,9 @@ static int private_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) N.B. Do not use for bulk data, use a table-based routine instead. This is common code and should be moved to net/core/crc.c */ static unsigned const ethernet_polynomial_le = 0xedb88320U; -static inline unsigned ether_crc_le(int length, unsigned char *data) +static inline u32 ether_crc_le(int length, unsigned char *data) { - unsigned int crc = 0xffffffff; /* Initial value. */ + u32 crc = 0xffffffff; /* Initial value. */ while(--length >= 0) { unsigned char current_octet = *data++; int bit; @@ -2524,223 +2539,554 @@ static inline unsigned ether_crc_le(int length, unsigned char *data) } return crc; } +static unsigned const ethernet_polynomial = 0x04c11db7U; +static inline u32 ether_crc(int length, unsigned char *data) +{ + int crc = -1; + + while(--length >= 0) { + unsigned char current_octet = *data++; + int bit; + for (bit = 0; bit < 8; bit++, current_octet >>= 1) + crc = (crc << 1) ^ + ((crc < 0) ^ (current_octet & 1) ? ethernet_polynomial : 0); + } + return crc; +} -#ifdef NEW_MULTICAST static void set_rx_mode(struct net_device *dev) -#else -static void set_rx_mode(struct net_device *dev, int num_addrs, void *addrs) -#endif { + struct tulip_private *tp = (struct tulip_private *)dev->priv; long ioaddr = dev->base_addr; int csr6 = inl(ioaddr + CSR6) & ~0x00D5; - struct tulip_private *tp = (struct tulip_private *)dev->priv; unsigned long cpuflags; tp->csr6 &= ~0x00D5; if (dev->flags & IFF_PROMISC) { /* Set promiscuous. */ - outl(csr6 | 0x00C0, ioaddr + CSR6); + tp->csr6 |= 0x00C0; + csr6 |= 0x00C0; /* Unconditionally log net taps. */ printk(KERN_INFO "%s: Promiscuous mode enabled.\n", dev->name); - tp->csr6 |= 0xC0; } else if ((dev->mc_count > 1000) || (dev->flags & IFF_ALLMULTI)) { - /* Too many to filter perfectly -- accept all multicasts. */ - outl(csr6 | 0x0080, ioaddr + CSR6); - tp->csr6 |= 0x80; + /* Too many to filter well -- accept all multicasts. */ + tp->csr6 |= 0x0080; + csr6 |= 0x0080; + } else if (tp->flags & MC_HASH_ONLY) { + /* Some work-alikes have only a 64-entry hash filter table. */ + /* Should verify correctness on big-endian/__powerpc__ */ + struct dev_mc_list *mclist; + int i; + u32 mc_filter[2]; /* Multicast hash filter */ + if (dev->mc_count > 64) { /* Arbitrary non-effective limit. */ + tp->csr6 |= 0x0080; + csr6 |= 0x0080; + } else { + mc_filter[1] = mc_filter[0] = 0; + for (i = 0, mclist = dev->mc_list; mclist && i < dev->mc_count; + i++, mclist = mclist->next) + set_bit(ether_crc(ETH_ALEN, mclist->dmi_addr)>>26, mc_filter); + if (tp->chip_id == AX88140) { + outl(2, ioaddr + CSR13); + outl(mc_filter[0], ioaddr + CSR14); + outl(3, ioaddr + CSR13); + outl(mc_filter[1], ioaddr + CSR14); + } else if (tp->chip_id == COMET) { /* Has a simple hash filter. */ + outl(mc_filter[0], ioaddr + 0xAC); + outl(mc_filter[1], ioaddr + 0xB0); + } + } } else { - u32 *setup_frm = tp->setup_frame; + u16 *eaddrs, *setup_frm = tp->setup_frame; struct dev_mc_list *mclist; - u16 *eaddrs; - u32 tx_flags; + u32 tx_flags = 0x08000000 | 192; int i; + /* Note that only the low-address shortword of setup_frame is valid! + The values are doubled for big-endian architectures. */ if (dev->mc_count > 14) { /* Must use a multicast hash table. */ - u16 hash_table[32]; - memset(hash_table, 0, sizeof(hash_table)); - /* This should work on big-endian machines as well. */ - for (i = 0, mclist = dev->mc_list; mclist && i < dev->mc_count; - i++, mclist = mclist->next) - set_bit(ether_crc_le(ETH_ALEN, mclist->dmi_addr) & 0x1ff, - hash_table); - /* Copy the hash table to the setup frame. - NOTE that only the LOW SHORTWORD of setup_frame[] is valid! */ - for (i = 0; i < 32; i++) - *setup_frm++ = hash_table[i]; - setup_frm += 7; - tx_flags = 0x08400000 | 192; - /* Too clever: i > 15 for fall-though. */ + u16 hash_table[32]; + tx_flags = 0x08400000 | 192; /* Use hash filter. */ + memset(hash_table, 0, sizeof(hash_table)); + set_bit(255, hash_table); /* Broadcast entry */ + /* This should work on big-endian machines as well. */ + for (i = 0, mclist = dev->mc_list; mclist && i < dev->mc_count; + i++, mclist = mclist->next) + set_bit(ether_crc_le(ETH_ALEN, mclist->dmi_addr) & 0x1ff, + hash_table); + for (i = 0; i < 32; i++) + *setup_frm++ = *setup_frm++ = hash_table[i]; + setup_frm = &tp->setup_frame[13*6]; } else { - /* We have <= 15 addresses so we can use the wonderful - 16 address perfect filtering of the Tulip. */ - for (i = 0, mclist = dev->mc_list; i < dev->mc_count; - i++, mclist = mclist->next) { - /* Note that only the low shortword of setup_frame[] is valid! - This code may require tweaking for non-x86 architectures! */ - eaddrs = (u16 *)mclist->dmi_addr; - *setup_frm++ = *eaddrs++; - *setup_frm++ = *eaddrs++; - *setup_frm++ = *eaddrs++; - } - /* Fill the rest of the table with our physical address. - Once again, only the low shortword or setup_frame[] is valid! */ - *setup_frm++ = 0xffff; - *setup_frm++ = 0xffff; - *setup_frm++ = 0xffff; - tx_flags = 0x08000000 | 192; + /* We have <= 14 addresses so we can use the wonderful + 16 address perfect filtering of the Tulip. */ + for (i = 0, mclist = dev->mc_list; i < dev->mc_count; + i++, mclist = mclist->next) { + eaddrs = (u16 *)mclist->dmi_addr; + *setup_frm++ = *setup_frm++ = *eaddrs++; + *setup_frm++ = *setup_frm++ = *eaddrs++; + *setup_frm++ = *setup_frm++ = *eaddrs++; + } + /* Fill the unused entries with the broadcast address. */ + memset(setup_frm, 0xff, (15-i)*12); + setup_frm = &tp->setup_frame[15*6]; } + /* Fill the final entry with our physical address. */ eaddrs = (u16 *)dev->dev_addr; - do { - *setup_frm++ = eaddrs[0]; - *setup_frm++ = eaddrs[1]; - *setup_frm++ = eaddrs[2]; - } while (++i < 15); + *setup_frm++ = *setup_frm++ = eaddrs[0]; + *setup_frm++ = *setup_frm++ = eaddrs[1]; + *setup_frm++ = *setup_frm++ = eaddrs[2]; /* Now add this frame to the Tx list. */ spin_lock_irqsave(&tp->tx_lock, cpuflags); if (tp->cur_tx - tp->dirty_tx > TX_RING_SIZE - 2) { /* Same setup recently queued, we need not add it. */ } else { - unsigned int entry, dummy = 0; + unsigned long flags; + unsigned int entry; + save_flags(flags); cli(); entry = tp->cur_tx++ % TX_RING_SIZE; if (entry != 0) { /* Avoid a chip errata by prefixing a dummy entry. */ tp->tx_skbuff[entry] = 0; tp->tx_ring[entry].length = - (entry == TX_RING_SIZE-1) ? 0x02000000 : 0; + (entry == TX_RING_SIZE-1) ? cpu_to_le32(DESC_RING_WRAP) : 0; tp->tx_ring[entry].buffer1 = 0; - /* race with chip, set DescOwned later */ - dummy = entry; + tp->tx_ring[entry].status = cpu_to_le32(DescOwned); entry = tp->cur_tx++ % TX_RING_SIZE; } tp->tx_skbuff[entry] = 0; /* Put the setup frame on the Tx list. */ if (entry == TX_RING_SIZE-1) - tx_flags |= 0x02000000; /* Wrap ring. */ - tp->tx_ring[entry].length = tx_flags; - tp->tx_ring[entry].buffer1 = virt_to_bus(tp->setup_frame); - tp->tx_ring[entry].status = 0x80000000; + tx_flags |= DESC_RING_WRAP; /* Wrap ring. */ + tp->tx_ring[entry].length = cpu_to_le32(tx_flags); + tp->tx_ring[entry].buffer1 = virt_to_le32desc(tp->setup_frame); + tp->tx_ring[entry].status = cpu_to_le32(DescOwned); if (tp->cur_tx - tp->dirty_tx >= TX_RING_SIZE - 2) { netif_stop_queue(dev); tp->tx_full = 1; } - if (dummy >= 0) - tp->tx_ring[dummy].status = DescOwned; spin_unlock_irqrestore(&tp->tx_lock, cpuflags); /* Trigger an immediate transmit demand. */ outl(0, ioaddr + CSR1); } - outl(csr6 | 0x0000, ioaddr + CSR6); } + outl(csr6 | 0x0000, ioaddr + CSR6); } - -#ifdef CARDBUS -#include -static dev_node_t *tulip_attach(dev_locator_t *loc) +static int __devinit tulip_init_one (struct pci_dev *pdev, + const struct pci_device_id *ent) { - u16 dev_id; - u32 io; - u8 bus, devfn; + static int did_version = 0; /* Already printed version info. */ + struct tulip_private *tp; + /* See note below on the multiport cards. */ + static unsigned char last_phys_addr[6] = {0x00, 'L', 'i', 'n', 'u', 'x'}; + static int last_irq = 0; + static int multiport_cnt = 0; /* For four-port boards w/one EEPROM */ + u8 chip_rev; + int i, irq; + unsigned short sum; + u8 ee_data[EEPROM_SIZE]; struct net_device *dev; - struct pci_dev *pdev; + long ioaddr; + static int board_idx = -1; + int chip_idx = ent->driver_data; + + board_idx++; - if (loc->bus != LOC_PCI) return NULL; - pdev = pci_find_slot (loc->b.pci.bus, loc->b.pci.devfn); - if (!pdev) return NULL; - printk(KERN_INFO "tulip_attach(bus %d, function %d)\n", bus, devfn); - io = pdev->resource[0].start; - dev_id = pdev->device; - io &= ~3; - dev = tulip_probe1(bus, devfn, DC21142, -1); - if (dev) { - dev_node_t *node = kmalloc(sizeof(dev_node_t), GFP_KERNEL); - strcpy(node->dev_name, dev->name); - node->major = node->minor = 0; - node->next = NULL; - MOD_INC_USE_COUNT; - return node; + if (tulip_debug > 0 && did_version++ == 0) + printk(KERN_INFO "%s", version); + + if( pdev->subsystem_vendor == 0x1376 ){ + printk(KERN_ERR "tulip: skipping LMC card.\n"); + return -ENODEV; } - return NULL; -} + + ioaddr = pci_resource_start (pdev, 0); + irq = pdev->irq; -static void tulip_detach(dev_node_t *node) -{ - struct net_device **devp, **next; - printk(KERN_INFO "tulip_detach(%s)\n", node->dev_name); - for (devp = &root_tulip_dev; *devp; devp = next) { - next = &((struct tulip_private *)(*devp)->priv)->next_module; - if (strcmp((*devp)->name, node->dev_name) == 0) break; + /* Make certain the data structures are quadword aligned. */ + dev = init_etherdev (NULL, sizeof (*tp)); + if (!dev) + return -ENOMEM; + + /* We do a request_region() only to register /proc/ioports info. */ + /* Note that proper size is tulip_tbl[chip_idx].chip_name, but... */ + if (!request_region (ioaddr, tulip_tbl[chip_idx].io_size, dev->name)) + goto err_out_free_netdev; + + pci_enable_device (pdev); + + tp = dev->priv; + memset(tp, 0, sizeof(*tp)); + + pci_read_config_byte (pdev, PCI_REVISION_ID, &chip_rev); + + /* Bring the 21041/21143 out of sleep mode. + Caution: Snooze mode does not work with some boards! */ + if (tulip_tbl[chip_idx].flags & HAS_PWRDWN) + pci_write_config_dword(pdev, 0x40, 0x00000000); + + printk(KERN_INFO "%s: %s rev %d at %#3lx,", + dev->name, tulip_tbl[chip_idx].chip_name, chip_rev, ioaddr); + + /* Stop the chip's Tx and Rx processes. */ + outl(inl(ioaddr + CSR6) & ~0x2002, ioaddr + CSR6); + /* Clear the missed-packet counter. */ + (volatile int)inl(ioaddr + CSR8); + + if (chip_idx == DC21041 && inl(ioaddr + CSR9) & 0x8000) { + printk(" 21040 compatible mode,"); + chip_idx = DC21040; } - if (*devp) { - unregister_netdev(*devp); - kfree(*devp); - *devp = *next; - kfree(node); - MOD_DEC_USE_COUNT; + + /* The station address ROM is read byte serially. The register must + be polled, waiting for the value to be read bit serially from the + EEPROM. + */ + sum = 0; + if (chip_idx == DC21040) { + outl(0, ioaddr + CSR9); /* Reset the pointer with a dummy write. */ + for (i = 0; i < 6; i++) { + int value, boguscnt = 100000; + do + value = inl(ioaddr + CSR9); + while (value < 0 && --boguscnt > 0); + dev->dev_addr[i] = value; + sum += value & 0xff; + } + } else if (chip_idx == LC82C168) { + for (i = 0; i < 3; i++) { + int value, boguscnt = 100000; + outl(0x600 | i, ioaddr + 0x98); + do + value = inl(ioaddr + CSR9); + while (value < 0 && --boguscnt > 0); + put_unaligned(le16_to_cpu(value), ((u16*)dev->dev_addr) + i); + sum += value & 0xffff; + } + } else if (chip_idx == COMET) { + /* No need to read the EEPROM. */ + put_unaligned(inl(ioaddr + 0xA4), (u32 *)dev->dev_addr); + put_unaligned(inl(ioaddr + 0xA8), (u16 *)(dev->dev_addr + 4)); + for (i = 0; i < 6; i ++) + sum += dev->dev_addr[i]; + } else { + /* A serial EEPROM interface, we read now and sort it out later. */ + int sa_offset = 0; + int ee_addr_size = read_eeprom(ioaddr, 0xff, 8) & 0x40000 ? 8 : 6; + + for (i = 0; i < sizeof(ee_data)/2; i++) + ((u16 *)ee_data)[i] = + le16_to_cpu(read_eeprom(ioaddr, i, ee_addr_size)); + + /* DEC now has a specification (see Notes) but early board makers + just put the address in the first EEPROM locations. */ + /* This does memcmp(eedata, eedata+16, 8) */ + for (i = 0; i < 8; i ++) + if (ee_data[i] != ee_data[16+i]) + sa_offset = 20; + if (ee_data[0] == 0xff && ee_data[1] == 0xff && ee_data[2] == 0) { + sa_offset = 2; /* Grrr, damn Matrox boards. */ + multiport_cnt = 4; + } + for (i = 0; i < 6; i ++) { + dev->dev_addr[i] = ee_data[i + sa_offset]; + sum += ee_data[i + sa_offset]; + } + } + /* Lite-On boards have the address byte-swapped. */ + if ((dev->dev_addr[0] == 0xA0 || dev->dev_addr[0] == 0xC0) + && dev->dev_addr[1] == 0x00) + for (i = 0; i < 6; i+=2) { + char tmp = dev->dev_addr[i]; + dev->dev_addr[i] = dev->dev_addr[i+1]; + dev->dev_addr[i+1] = tmp; + } + /* On the Zynx 315 Etherarray and other multiport boards only the + first Tulip has an EEPROM. + The addresses of the subsequent ports are derived from the first. + Many PCI BIOSes also incorrectly report the IRQ line, so we correct + that here as well. */ + if (sum == 0 || sum == 6*0xff) { + printk(" EEPROM not present,"); + for (i = 0; i < 5; i++) + dev->dev_addr[i] = last_phys_addr[i]; + dev->dev_addr[i] = last_phys_addr[i] + 1; +#if defined(__i386__) /* Patch up x86 BIOS bug. */ + if (last_irq) + irq = last_irq; +#endif } -} -struct driver_operations tulip_ops = { - "tulip_cb", tulip_attach, NULL, NULL, tulip_detach -}; + for (i = 0; i < 6; i++) + printk("%c%2.2X", i ? ':' : ' ', last_phys_addr[i] = dev->dev_addr[i]); + printk(", IRQ %d.\n", irq); + last_irq = irq; -#endif /* Cardbus support */ + pdev->driver_data = dev; + dev->base_addr = ioaddr; + dev->irq = irq; -MODULE_AUTHOR("Donald Becker "); -MODULE_DESCRIPTION("Digital 21*4* Tulip ethernet driver"); -MODULE_PARM(debug, "i"); -MODULE_PARM(max_interrupt_work, "i"); -MODULE_PARM(reverse_probe, "i"); -MODULE_PARM(rx_copybreak, "i"); -MODULE_PARM(options, "1-" __MODULE_STRING(MAX_UNITS) "i"); -MODULE_PARM(full_duplex, "1-" __MODULE_STRING(MAX_UNITS) "i"); + tp->chip_id = chip_idx; + tp->revision = chip_rev; + tp->flags = tulip_tbl[chip_idx].flags; + tp->csr0 = csr0; + tp->pdev = pdev; -/* An additional parameter that may be passed in... */ -static int debug = -1; + /* BugFixes: The 21143-TD hangs with PCI Write-and-Invalidate cycles. + And the ASIX must have a burst limit or horrible things happen. */ + if (chip_idx == DC21143 && chip_rev == 65) + tp->csr0 &= ~0x01000000; + else if (chip_idx == AX88140) + tp->csr0 |= 0x2000; -static int __init tulip_init_module (void) -{ - if (debug >= 0) - tulip_debug = debug; +#ifdef TULIP_FULL_DUPLEX + tp->full_duplex = 1; + tp->full_duplex_lock = 1; +#endif +#ifdef TULIP_DEFAULT_MEDIA + tp->default_port = TULIP_DEFAULT_MEDIA; +#endif +#ifdef TULIP_NO_MEDIA_SWITCH + tp->medialock = 1; +#endif + + /* The lower four bits are the media type. */ + if (board_idx >= 0 && board_idx < MAX_UNITS) { + tp->default_port = options[board_idx] & 15; + if ((options[board_idx] & 0x90) || full_duplex[board_idx] > 0) + tp->full_duplex = 1; + if (mtu[board_idx] > 0) + dev->mtu = mtu[board_idx]; + } + if (dev->mem_start) + tp->default_port = dev->mem_start; + if (tp->default_port) { + tp->medialock = 1; + if (media_cap[tp->default_port] & MediaAlwaysFD) + tp->full_duplex = 1; + } + if (tp->full_duplex) + tp->full_duplex_lock = 1; + + if (media_cap[tp->default_port] & MediaIsMII) { + u16 media2advert[] = { 0x20, 0x40, 0x03e0, 0x60, 0x80, 0x100, 0x200 }; + tp->to_advertise = media2advert[tp->default_port - 9]; + } else if (tp->flags & HAS_8023X) + tp->to_advertise = 0x05e1; + else + tp->to_advertise = 0x01e1; + + /* This is logically part of probe1(), but too complex to write inline. */ + if (tp->flags & HAS_MEDIA_TABLE) { + memcpy(tp->eeprom, ee_data, sizeof(tp->eeprom)); + parse_eeprom(dev); + } + + if ((tp->flags & ALWAYS_CHECK_MII) || + (tp->mtable && tp->mtable->has_mii) || + ( ! tp->mtable && (tp->flags & HAS_MII))) { + int phy, phy_idx; + if (tp->mtable && tp->mtable->has_mii) { + for (i = 0; i < tp->mtable->leafcount; i++) + if (tp->mtable->mleaf[i].media == 11) { + tp->cur_index = i; + tp->saved_if_port = dev->if_port; + select_media(dev, 1); + dev->if_port = tp->saved_if_port; + break; + } + } + /* Find the connected MII xcvrs. + Doing this in open() would allow detecting external xcvrs later, + but takes much time. */ + for (phy = 0, phy_idx = 0; phy < 32 && phy_idx < sizeof(tp->phys); + phy++) { + int mii_status = mdio_read(dev, phy, 1); + if ((mii_status & 0x8301) == 0x8001 || + ((mii_status & 0x8000) == 0 && (mii_status & 0x7800) != 0)) { + int mii_reg0 = mdio_read(dev, phy, 0); + int mii_advert = mdio_read(dev, phy, 4); + int reg4 = ((mii_status>>6) & tp->to_advertise) | 1; + tp->phys[phy_idx] = phy; + tp->advertising[phy_idx++] = reg4; + printk(KERN_INFO "%s: MII transceiver #%d " + "config %4.4x status %4.4x advertising %4.4x.\n", + dev->name, phy, mii_reg0, mii_status, mii_advert); + /* Fixup for DLink with miswired PHY. */ + if (mii_advert != reg4) { + printk(KERN_DEBUG "%s: Advertising %4.4x on PHY %d," + " previously advertising %4.4x.\n", + dev->name, reg4, phy, mii_advert); + printk(KERN_DEBUG "%s: Advertising %4.4x (to advertise" + " is %4.4x).\n", + dev->name, reg4, tp->to_advertise); + mdio_write(dev, phy, 4, reg4); + } + /* Enable autonegotiation: some boards default to off. */ + mdio_write(dev, phy, 0, mii_reg0 | + (tp->full_duplex ? 0x1100 : 0x1000) | + (media_cap[tp->default_port]&MediaIs100 ? 0x2000:0)); + } + } + tp->mii_cnt = phy_idx; + if (tp->mtable && tp->mtable->has_mii && phy_idx == 0) { + printk(KERN_INFO "%s: ***WARNING***: No MII transceiver found!\n", + dev->name); + tp->phys[0] = 1; + } + } + + /* The Tulip-specific entries in the device structure. */ + dev->open = tulip_open; + dev->hard_start_xmit = tulip_start_xmit; + dev->tx_timeout = tulip_tx_timeout; + dev->watchdog_timeo = TX_TIMEOUT; + dev->stop = tulip_close; + dev->get_stats = tulip_get_stats; + dev->do_ioctl = private_ioctl; + dev->set_multicast_list = set_rx_mode; + + if ((tp->flags & HAS_NWAY143) || tp->chip_id == DC21041) + tp->link_change = t21142_lnk_change; + else if (tp->flags & HAS_PNICNWAY) + tp->link_change = pnic_lnk_change; + + /* Reset the xcvr interface and turn on heartbeat. */ + switch (chip_idx) { + case DC21041: + tp->to_advertise = 0x0061; + outl(0x00000000, ioaddr + CSR13); + outl(0xFFFFFFFF, ioaddr + CSR14); + outl(0x00000008, ioaddr + CSR15); /* Listen on AUI also. */ + outl(inl(ioaddr + CSR6) | 0x0200, ioaddr + CSR6); + outl(0x0000EF05, ioaddr + CSR13); + break; + case DC21040: + outl(0x00000000, ioaddr + CSR13); + outl(0x00000004, ioaddr + CSR13); + break; + case DC21140: default: + if (tp->mtable) + outl(tp->mtable->csr12dir | 0x100, ioaddr + CSR12); + break; + case DC21142: + case PNIC2: + if (tp->mii_cnt || media_cap[dev->if_port] & MediaIsMII) { + outl(0x82020000, ioaddr + CSR6); + outl(0x0000, ioaddr + CSR13); + outl(0x0000, ioaddr + CSR14); + outl(0x820E0000, ioaddr + CSR6); + } else + t21142_start_nway(dev); + break; + case LC82C168: + if ( ! tp->mii_cnt) { + tp->nway = 1; + tp->nwayset = 0; + outl(0x00420000, ioaddr + CSR6); + outl(0x30, ioaddr + CSR12); + outl(0x0001F078, ioaddr + 0xB8); + outl(0x0201F078, ioaddr + 0xB8); /* Turn on autonegotiation. */ + } + break; + case MX98713: case COMPEX9881: + outl(0x00000000, ioaddr + CSR6); + outl(0x000711C0, ioaddr + CSR14); /* Turn on NWay. */ + outl(0x00000001, ioaddr + CSR13); + break; + case MX98715: case MX98725: + outl(0x01a80000, ioaddr + CSR6); + outl(0xFFFFFFFF, ioaddr + CSR14); + outl(0x00001000, ioaddr + CSR12); + break; + case COMET: + /* No initialization necessary. */ + break; + } + + if (tulip_tbl[chip_idx].flags & HAS_PWRDWN) + pci_write_config_dword(pdev, 0x40, 0x40000000); -#ifdef CARDBUS - register_driver(&tulip_ops); return 0; -#else - return tulip_probe(); -#endif + +err_out_free_netdev: + unregister_netdev (dev); + kfree (dev); + return -ENODEV; } -static void __exit tulip_cleanup_module (void) + +static void tulip_suspend (struct pci_dev *pdev) { - struct net_device *next_dev; + struct net_device *dev = pdev->driver_data; + + if (dev) { + long ioaddr = dev->base_addr; + struct tulip_private *tp = (struct tulip_private *)dev->priv; + int csr6 = inl(ioaddr + CSR6); + /* Disable interrupts, stop the chip, gather stats. */ + if (csr6 != 0xffffffff) { + outl(0x00000000, ioaddr + CSR7); + outl(csr6 & ~0x2002, ioaddr + CSR6); + tp->stats.rx_missed_errors += inl(ioaddr + CSR8) & 0xffff; + } + tulip_close(dev); + /* Put the 21143 into sleep mode. */ + pci_write_config_dword(pdev, 0x40,0x80000000); + } +} -#ifdef CARDBUS - unregister_driver(&tulip_ops); -#endif - /* No need to check MOD_IN_USE, as sys_delete_module() checks. */ - while (root_tulip_dev) { - next_dev = ((struct tulip_private *)root_tulip_dev->priv)->next_module; - unregister_netdev(root_tulip_dev); - release_region(root_tulip_dev->base_addr, TULIP_TOTAL_SIZE); - kfree(root_tulip_dev); - root_tulip_dev = next_dev; +static void tulip_resume (struct pci_dev *pdev) +{ + struct net_device *dev = pdev->driver_data; + + if (dev) { + pci_write_config_dword(pdev, 0x40, 0x0000); + tulip_open(dev); } } -module_init(tulip_init_module); -module_exit(tulip_cleanup_module); +static void __devexit tulip_remove_one (struct pci_dev *pdev) +{ + struct net_device *dev = pdev->driver_data; -/* - * Local variables: - * SMP-compile-command: "gcc -D__SMP__ -DMODULE -D__KERNEL__ -I/usr/src/linux/net/inet -Wall -Wstrict-prototypes -O6 -c tulip.c `[ -f /usr/include/linux/modversions.h ] && echo -DMODVERSIONS`" - * compile-command: "gcc -DMODULE -D__KERNEL__ -I/usr/src/linux/net/inet -Wall -Wstrict-prototypes -O6 -c tulip.c `[ -f /usr/include/linux/modversions.h ] && echo -DMODVERSIONS`" - * c-indent-level: 4 - * c-basic-offset: 4 - * tab-width: 4 - * End: - */ + if (dev) { + struct tulip_private *tp = (struct tulip_private *)dev->priv; + unregister_netdev(dev); + release_region(dev->base_addr, + tulip_tbl[tp->chip_id].io_size); + kfree(dev); + } +} + + +static struct pci_driver tulip_driver = { + name: TULIP_MODULE_NAME, + id_table: tulip_pci_tbl, + probe: tulip_init_one, + remove: tulip_remove_one, + suspend: tulip_suspend, + resume: tulip_resume, +}; + + +static int __init tulip_init (void) +{ + return pci_register_driver (&tulip_driver) > 0 ? 0 : -ENODEV; +} + + +static void __exit tulip_cleanup (void) +{ + pci_unregister_driver (&tulip_driver); +} + + +module_init(tulip_init); +module_exit(tulip_cleanup); diff --git a/drivers/net/yellowfin.c b/drivers/net/yellowfin.c index e6eb9492c..b9265b46c 100644 --- a/drivers/net/yellowfin.c +++ b/drivers/net/yellowfin.c @@ -1,6 +1,6 @@ /* yellowfin.c: A Packet Engines G-NIC ethernet driver for linux. */ /* - Written 1997-1998 by Donald Becker. + Written 1997-1999 by Donald Becker. This software may be used and distributed according to the terms of the GNU Public License, incorporated herein by reference. @@ -17,13 +17,13 @@ */ static const char *version = -"yellowfin.c:v1.02 7/26/98 Written by Donald Becker, becker@cesdis.edu\n" +"yellowfin.c:v1.03a 7/30/99 Written by Donald Becker, becker@cesdis.edu\n" " http://cesdis.gsfc.nasa.gov/linux/drivers/yellowfin.html\n"; /* A few user-configurable values. */ +static int debug = 1; static int max_interrupt_work = 20; -static int min_pci_latency = 64; static int mtu = 0; #ifdef YF_PROTOTYPE /* Support for prototype hardware errata. */ /* System-wide count of bogus-rx frames. */ @@ -50,25 +50,38 @@ static int rx_copybreak = 0; static int options[MAX_UNITS] = {-1, -1, -1, -1, -1, -1, -1, -1}; static int full_duplex[MAX_UNITS] = {-1, -1, -1, -1, -1, -1, -1, -1}; +/* Do ugly workaround for GX server chipset errata. */ +static int gx_fix = 0; + /* Operational parameters that are set at compile time. */ /* Keep the ring sizes a power of two for efficiency. - Making the Tx ring too large decreases the effectiveness of channel + Making the Tx queue too long decreases the effectiveness of channel bonding and packet priority. There are no ill effects from too-large receive rings. */ #define TX_RING_SIZE 16 -#define RX_RING_SIZE 32 +#define TX_QUEUE_SIZE 12 /* Must be > 4 && <= TX_RING_SIZE */ +#define RX_RING_SIZE 64 /* Operational parameters that usually are not changed. */ /* Time in jiffies before concluding the transmitter is hung. */ -#define TX_TIMEOUT ((2000*HZ)/1000) +#define TX_TIMEOUT (2*HZ) + +#define yellowfin_debug debug +#if !defined(__OPTIMIZE__) || !defined(__KERNEL__) +#warning You must compile this file with the correct options! +#warning See the last lines of the source file. +#error You must compile this driver with "-O". +#endif + +#include +#include #include +#include #include -#include #include #include -#include #include #include #include @@ -76,20 +89,20 @@ static int full_duplex[MAX_UNITS] = {-1, -1, -1, -1, -1, -1, -1, -1}; #include #include #include /* Processor type for cache alignment. */ -#include #include +#include #include #include #include #include -#define RUN_AT(x) (jiffies + (x)) +/* Condensed operations for readability. + Compatibility defines are now in drv_compat.h */ -/* The PCI I/O space extent. */ -#define YELLOWFIN_TOTAL_SIZE 0x100 +#define virt_to_le32desc(addr) cpu_to_le32(virt_to_bus(addr)) +#define le32desc_to_virt(addr) bus_to_virt(le32_to_cpu(addr)) -int yellowfin_debug = 1; /* Theory of Operation @@ -172,31 +185,49 @@ See Packet Engines confidential appendix (prototype chips only). /* A few values that may be tweaked. */ #define PKT_BUF_SZ 1536 /* Size of each temporary Rx buffer.*/ -#ifndef PCI_VENDOR_ID_PKT_ENG /* To be defined in linux/pci.h */ -#define PCI_VENDOR_ID_PKT_ENG 0x1000 /* Hmm, likely number.. */ -#define PCI_DEVICE_ID_SYM58C885 0x0701 -#define PCI_DEVICE_ID_YELLOWFIN 0x0702 -#endif - /* The rest of these values should never change. */ -static void yellowfin_timer(unsigned long data); +enum capability_flags { + HasMII=1, FullTxStatus=2, IsGigabit=4, HasMulticastBug=8, FullRxStatus=16, + HasMACAddrBug=32, /* Really only on early revs. */ +}; + + +/* The PCI I/O space extent. */ +#define YELLOWFIN_SIZE 0x100 + +#define YELLOWFIN_MODULE_NAME "yellowfin" +#define PFX YELLOWFIN_MODULE_NAME ": " + + +typedef enum { + YELLOWFIN_GNIC, + SYM83C885, +} chip_t; -enum capability_flags {HasMII=1, FullTxStatus=2}; -static struct chip_info { - u16 vendor_id, device_id, device_id_mask, pci_flags; + +struct chip_info { const char *name; - void (*media_timer)(unsigned long data); - u32 chip_rev; /* As read from ChipRev, not PCI dev ID. */ int flags; -} chip_tbl[] = { - {0x1000, 0x0702, 0xffff, 0, "Yellowfin G-NIC Gbit Ethernet", - yellowfin_timer, 0x0702, FullTxStatus}, - {0x1000, 0x0701, 0xffff, 0, "Symbios SYM83C885", - yellowfin_timer, 0x0701, HasMII}, - {0,}, }; + +/* index by chip_t */ +static struct chip_info chip_info[] = { + {"Yellowfin G-NIC Gigabit Ethernet", + FullTxStatus | IsGigabit | HasMulticastBug | HasMACAddrBug}, + {"Symbios SYM83C885", HasMII }, +}; + + +static struct pci_device_id yellowfin_pci_tbl[] __devinitdata = { + { 0x1000, 0x0702, PCI_ANY_ID, PCI_ANY_ID, 0, 0, YELLOWFIN_GNIC }, + { 0x1000, 0x0701, PCI_ANY_ID, PCI_ANY_ID, 0, 0, SYM83C885 }, + { 0, }, +}; +MODULE_DEVICE_TABLE (pci, yellowfin_pci_tbl); + + /* Offsets to the Yellowfin registers. Various sizes and alignments. */ enum yellowfin_offsets { TxCtrl=0x00, TxStatus=0x04, TxPtr=0x0C, @@ -204,7 +235,8 @@ enum yellowfin_offsets { RxCtrl=0x40, RxStatus=0x44, RxPtr=0x4C, RxIntrSel=0x50, RxBranchSel=0x54, RxWaitSel=0x58, EventStatus=0x80, IntrEnb=0x82, IntrClear=0x84, IntrStatus=0x86, - ChipRev=0x8C, DMACtrl=0x90, Cnfg=0xA0, FrameGap0=0xA2, FrameGap1=0xA4, + ChipRev=0x8C, DMACtrl=0x90, TxThreshold=0x94, + Cnfg=0xA0, FrameGap0=0xA2, FrameGap1=0xA4, MII_Cmd=0xA6, MII_Addr=0xA8, MII_Wr_Data=0xAA, MII_Rd_Data=0xAC, MII_Status=0xAE, RxDepth=0xB8, FlowCtrl=0xBC, @@ -213,29 +245,35 @@ enum yellowfin_offsets { EEFeature=0xF5, }; -/* The Yellowfin Rx and Tx buffer descriptors. */ +/* The Yellowfin Rx and Tx buffer descriptors. + Elements are written as 32 bit for endian portability. */ struct yellowfin_desc { - u16 request_cnt; - u16 cmd; + u32 dbdma_cmd; u32 addr; u32 branch_addr; - u16 result_cnt; - u16 status; + u32 result_status; }; struct tx_status_words { +#if defined(__powerpc__) + u16 tx_errs; + u16 tx_cnt; + u16 paused; + u16 total_tx_cnt; +#else /* Little endian chips. */ u16 tx_cnt; u16 tx_errs; u16 total_tx_cnt; u16 paused; +#endif }; /* Bits in yellowfin_desc.cmd */ enum desc_cmd_bits { - CMD_TX_PKT=0x1000, CMD_RX_BUF=0x2000, CMD_TXSTATUS=0x3000, - CMD_NOP=0x6000, CMD_STOP=0x7000, - BRANCH_ALWAYS=0x0C, INTR_ALWAYS=0x30, WAIT_ALWAYS=0x03, - BRANCH_IFTRUE=0x04, + CMD_TX_PKT=0x10000000, CMD_RX_BUF=0x20000000, CMD_TXSTATUS=0x30000000, + CMD_NOP=0x60000000, CMD_STOP=0x70000000, + BRANCH_ALWAYS=0x0C0000, INTR_ALWAYS=0x300000, WAIT_ALWAYS=0x030000, + BRANCH_IFTRUE=0x040000, }; /* Bits in yellowfin_desc.status */ @@ -247,6 +285,7 @@ enum intr_status_bits { IntrTxDone=0x10, IntrTxInvalid=0x20, IntrTxPCIFault=0x40,IntrTxPCIErr=0x80, IntrEarlyRx=0x100, IntrWakeup=0x200, }; +#define PRIV_ALIGN 31 /* Required alignment mask */ struct yellowfin_private { /* Descriptor rings first for alignment. Tx requires a second descriptor for status. */ @@ -254,21 +293,23 @@ struct yellowfin_private { struct yellowfin_desc tx_ring[TX_RING_SIZE*2]; const char *product_name; struct net_device *next_module; + void *priv_addr; /* Unaligned address for kfree */ /* The addresses of receive-in-place skbuffs. */ struct sk_buff* rx_skbuff[RX_RING_SIZE]; /* The saved address of a sent-in-place packet/buffer, for skfree(). */ struct sk_buff* tx_skbuff[TX_RING_SIZE]; struct tx_status_words tx_status[TX_RING_SIZE]; struct timer_list timer; /* Media selection timer. */ - struct enet_statistics stats; - spinlock_t lock; + struct net_device_stats stats; /* Frequently used and paired value: keep adjacent for cache effect. */ - int chip_id; + struct pci_dev *pci_dev; + int chip_id, flags; struct yellowfin_desc *rx_head_desc; - struct tx_status_words *tx_tail_desc; unsigned int cur_rx, dirty_rx; /* Producer/consumer ring indices */ - unsigned int cur_tx, dirty_tx; unsigned int rx_buf_sz; /* Based on MTU+slack. */ + struct tx_status_words *tx_tail_desc; + unsigned int cur_tx, dirty_tx; + int tx_threshold; unsigned int tx_full:1; /* The Tx queue is full. */ unsigned int full_duplex:1; /* Full-duplex operation requested. */ unsigned int duplex_lock:1; @@ -279,19 +320,21 @@ struct yellowfin_private { u16 advertising; /* NWay media advertisement */ unsigned char phys[2]; /* MII device addresses. */ u32 pad[4]; /* Used for 32-byte alignment */ + spinlock_t lock; }; + MODULE_AUTHOR("Donald Becker "); MODULE_DESCRIPTION("Packet Engines Yellowfin G-NIC Gigabit Ethernet driver"); MODULE_PARM(max_interrupt_work, "i"); -MODULE_PARM(min_pci_latency, "i"); MODULE_PARM(mtu, "i"); MODULE_PARM(debug, "i"); MODULE_PARM(rx_copybreak, "i"); +MODULE_PARM(gx_fix, "i"); MODULE_PARM(options, "1-" __MODULE_STRING(MAX_UNITS) "i"); MODULE_PARM(full_duplex, "1-" __MODULE_STRING(MAX_UNITS) "i"); -static struct net_device *yellowfin_probe1(long ioaddr, int irq, int chip_id, int options); + static int read_eeprom(long ioaddr, int location); static int mdio_read(long ioaddr, int phy_id, int location); static void mdio_write(long ioaddr, int phy_id, int location, int value); @@ -307,197 +350,17 @@ static void yellowfin_interrupt(int irq, void *dev_instance, struct pt_regs *reg static int yellowfin_rx(struct net_device *dev); static void yellowfin_error(struct net_device *dev, int intr_status); static int yellowfin_close(struct net_device *dev); -static struct enet_statistics *yellowfin_get_stats(struct net_device *dev); +static struct net_device_stats *yellowfin_get_stats(struct net_device *dev); static void set_rx_mode(struct net_device *dev); - - -/* A list of all installed Yellowfin devices, for removing the driver module. */ -static struct net_device *root_yellowfin_dev = NULL; - -static int __init yellowfin_probe(void) -{ - int cards_found = 0; - int pci_index = 0; - unsigned char pci_bus, pci_device_fn; - - if ( ! pci_present()) - return -ENODEV; - - for (;pci_index < 0xff; pci_index++) { - u8 pci_latency; - u16 pci_command, new_command, vendor, device; - int chip_idx; - int irq; - long ioaddr; - struct pci_dev *pdev; - - if (pcibios_find_class (PCI_CLASS_NETWORK_ETHERNET << 8, - pci_index, - &pci_bus, &pci_device_fn) - != PCIBIOS_SUCCESSFUL) - break; - - pdev = pci_find_slot (pci_bus, pci_device_fn); - if (!pdev) break; - vendor = pdev->vendor; - device = pdev->device; - - for (chip_idx = 0; chip_tbl[chip_idx].vendor_id; chip_idx++) - if (vendor == chip_tbl[chip_idx].vendor_id - && (device & chip_tbl[chip_idx].device_id_mask) == - chip_tbl[chip_idx].device_id) - break; - if (chip_tbl[chip_idx].vendor_id == 0) /* Compiled out! */ - continue; - - { - struct pci_dev *pdev = pci_find_slot(pci_bus, pci_device_fn); - ioaddr = pdev->resource[0].start; - irq = pdev->irq; - } - - if (yellowfin_debug > 2) - printk(KERN_INFO "Found %s at I/O %#lx, IRQ %d.\n", - chip_tbl[chip_idx].name, ioaddr, irq); - - if (check_region(ioaddr, YELLOWFIN_TOTAL_SIZE)) - continue; - - pci_read_config_word(pdev, PCI_COMMAND, &pci_command); - new_command = pci_command | PCI_COMMAND_MASTER|PCI_COMMAND_IO; - if (pci_command != new_command) { - printk(KERN_INFO " The PCI BIOS has not enabled the" - " device at %d/%d! Updating PCI command %4.4x->%4.4x.\n", - pci_bus, pci_device_fn, pci_command, new_command); - pci_write_config_word(pdev, PCI_COMMAND, new_command); - } - if(yellowfin_probe1(ioaddr, irq, chip_idx, cards_found)) - { - /* Get and check the bus-master and latency values. */ - pci_read_config_byte(pdev, PCI_LATENCY_TIMER, &pci_latency); - if (pci_latency < min_pci_latency) { - printk(KERN_INFO " PCI latency timer (CFLT) is " - "unreasonably low at %d. Setting to %d clocks.\n", - pci_latency, min_pci_latency); - pci_write_config_byte(pdev, PCI_LATENCY_TIMER, min_pci_latency); - } else if (yellowfin_debug > 1) - printk(KERN_INFO " PCI latency timer (CFLT) is %#x.\n", - pci_latency); - cards_found++; - } - } - - return cards_found ? 0 : -ENODEV; -} - -static struct net_device *yellowfin_probe1(long ioaddr, int irq, int chip_id, int card_idx) +static int __devinit read_eeprom(long ioaddr, int location) { - static int did_version = 0; /* Already printed version info. */ - struct yellowfin_private *yp; - int option, i; - struct net_device *dev; - - if (yellowfin_debug > 0 && did_version++ == 0) - printk(version); - - dev = init_etherdev(NULL, sizeof(struct yellowfin_private)); - - printk(KERN_INFO "%s: %s type %8x at 0x%lx, ", - dev->name, chip_tbl[chip_id].name, inl(ioaddr + ChipRev), ioaddr); - - if (inw(ioaddr + ChipRev) == 0x0702) - for (i = 0; i < 6; i++) - dev->dev_addr[i] = inb(ioaddr + StnAddr + i); - else { - int ee_offset = (read_eeprom(ioaddr, 6) == 0xff ? 0x100 : 0); - for (i = 0; i < 6; i++) - dev->dev_addr[i] = read_eeprom(ioaddr, ee_offset + i); - } - for (i = 0; i < 5; i++) - printk("%2.2x:", dev->dev_addr[i]); - printk("%2.2x, IRQ %d.\n", dev->dev_addr[i], irq); - - /* Reset the chip. */ - outl(0x80000000, ioaddr + DMACtrl); - - /* We do a request_region() only to register /proc/ioports info. */ - request_region(ioaddr, YELLOWFIN_TOTAL_SIZE, dev->name); - - dev->base_addr = ioaddr; - dev->irq = irq; - - /* Make certain the descriptor lists are aligned. */ - yp = (void *)(((long)kmalloc(sizeof(*yp), GFP_KERNEL) + 31) & ~31); - memset(yp, 0, sizeof(*yp)); - dev->priv = yp; - - yp->next_module = root_yellowfin_dev; - root_yellowfin_dev = dev; - - yp->chip_id = chip_id; - yp->lock = SPIN_LOCK_UNLOCKED; - - option = card_idx < MAX_UNITS ? options[card_idx] : 0; - if (dev->mem_start) - option = dev->mem_start; - - /* The lower four bits are the media type. */ - if (option > 0) { - if (option & 0x200) - yp->full_duplex = 1; - yp->default_port = option & 15; - if (yp->default_port) - yp->medialock = 1; - } - if (card_idx < MAX_UNITS && full_duplex[card_idx] > 0) - yp->full_duplex = 1; - - if (yp->full_duplex) - yp->duplex_lock = 1; - - /* The Yellowfin-specific entries in the device structure. */ - dev->open = &yellowfin_open; - dev->hard_start_xmit = &yellowfin_start_xmit; - dev->stop = &yellowfin_close; - dev->get_stats = &yellowfin_get_stats; - dev->set_multicast_list = &set_rx_mode; -#ifdef HAVE_PRIVATE_IOCTL - dev->do_ioctl = &mii_ioctl; -#endif - dev->tx_timeout = yellowfin_tx_timeout; - dev->watchdog_timeo = TX_TIMEOUT; - - if (mtu) - dev->mtu = mtu; - - if (chip_tbl[yp->chip_id].flags & HasMII) { - int phy, phy_idx = 0; - for (phy = 0; phy < 32 && phy_idx < 4; phy++) { - int mii_status = mdio_read(ioaddr, phy, 1); - if (mii_status != 0xffff && - mii_status != 0x0000) { - yp->phys[phy_idx++] = phy; - yp->advertising = mdio_read(ioaddr, phy, 4); - printk(KERN_INFO "%s: MII PHY found at address %d, status " - "0x%4.4x advertising %4.4x.\n", - dev->name, phy, mii_status, yp->advertising); - } - } - yp->mii_cnt = phy_idx; - } - - return dev; -} - -static int read_eeprom(long ioaddr, int location) -{ - int bogus_cnt = 1000; + int bogus_cnt = 10000; /* Typical 33Mhz: 1050 ticks */ outb(location, ioaddr + EEAddr); outb(0x30 | ((location >> 8) & 7), ioaddr + EECtrl); - while ((inb(ioaddr + EEStatus) & 0x80) && --bogus_cnt > 0) + while ((inb(ioaddr + EEStatus) & 0x80) && --bogus_cnt > 0) ; return inb(ioaddr + EERead); } @@ -575,13 +438,16 @@ static int yellowfin_open(struct net_device *dev) /* Enable automatic generation of flow control frames, period 0xffff. */ outl(0x0030FFFF, ioaddr + FlowCtrl); + yp->tx_threshold = 32; + outl(yp->tx_threshold, ioaddr + TxThreshold); + if (dev->if_port == 0) dev->if_port = yp->default_port; - netif_start_queue(dev); + netif_start_queue (dev); /* Setting the Rx mode will start the Rx process. */ - if (yp->chip_id == 0) { + if (yp->flags & IsGigabit) { /* We are always in full-duplex mode with gigabit! */ yp->full_duplex = 1; outw(0x01CF, ioaddr + Cnfg); @@ -604,7 +470,7 @@ static int yellowfin_open(struct net_device *dev) } /* Set the timer to check for link beat. */ init_timer(&yp->timer); - yp->timer.expires = RUN_AT((24*HZ)/10); /* 2.4 sec. */ + yp->timer.expires = jiffies + 3*HZ; yp->timer.data = (unsigned long)dev; yp->timer.function = &yellowfin_timer; /* timer handler */ add_timer(&yp->timer); @@ -617,7 +483,7 @@ static void yellowfin_timer(unsigned long data) struct net_device *dev = (struct net_device *)data; struct yellowfin_private *yp = (struct yellowfin_private *)dev->priv; long ioaddr = dev->base_addr; - int next_tick = 0; + int next_tick = 60*HZ; if (yellowfin_debug > 3) { printk(KERN_DEBUG "%s: Yellowfin timer tick, status %8.8x.\n", @@ -646,10 +512,8 @@ static void yellowfin_timer(unsigned long data) next_tick = 3*HZ; } - if (next_tick) { - yp->timer.expires = RUN_AT(next_tick); - add_timer(&yp->timer); - } + yp->timer.expires = jiffies + next_tick; + add_timer(&yp->timer); } static void yellowfin_tx_timeout(struct net_device *dev) @@ -657,34 +521,38 @@ static void yellowfin_tx_timeout(struct net_device *dev) struct yellowfin_private *yp = (struct yellowfin_private *)dev->priv; long ioaddr = dev->base_addr; - printk(KERN_WARNING "%s: Yellowfin transmit timed out, status %8.8x, resetting...\n", - dev->name, inl(ioaddr)); + printk(KERN_WARNING "%s: Yellowfin transmit timed out at %d/%d Tx " + "status %4.4x, Rx status %4.4x, resetting...\n", + dev->name, yp->cur_tx, yp->dirty_tx, + inl(ioaddr + TxStatus), inl(ioaddr + RxStatus)); -#ifndef __alpha__ - { + /* Note: these should be KERN_DEBUG. */ + if (yellowfin_debug) { int i; - printk(KERN_DEBUG " Rx ring %8.8x: ", (int)yp->rx_ring); + printk(KERN_WARNING " Rx ring %p: ", yp->rx_ring); for (i = 0; i < RX_RING_SIZE; i++) - printk(" %8.8x", (unsigned int)yp->rx_ring[i].status); - printk("\n"KERN_DEBUG" Tx ring %8.8x: ", (int)yp->tx_ring); + printk(" %8.8x", yp->rx_ring[i].result_status); + printk("\n"KERN_WARNING" Tx ring %p: ", yp->tx_ring); for (i = 0; i < TX_RING_SIZE; i++) - printk(" %4.4x /%4.4x", yp->tx_status[i].tx_errs, yp->tx_ring[i].status); + printk(" %4.4x /%8.8x", yp->tx_status[i].tx_errs, + yp->tx_ring[i].result_status); printk("\n"); } -#endif - /* Perhaps we should reinitialize the hardware here. */ - dev->if_port = 0; - /* Stop and restart the chip's Tx processes . */ + /* If the hardware is found to hang regularly, we will update the code + to reinitialize the chip here. */ + dev->if_port = 0; - /* Trigger an immediate transmit demand. */ + /* Wake the potentially-idle transmit channel. */ + outl(0x10001000, dev->base_addr + TxCtrl); + if (yp->cur_tx - yp->dirty_tx < TX_QUEUE_SIZE) + netif_wake_queue (dev); /* Typical path */ - dev->trans_start = jiffies; - yp->stats.tx_errors++; - return; + dev->trans_start = jiffies; + yp->stats.tx_errors++; + return; } - /* Initialize the Rx and Tx rings, along with various 'dev' bits. */ static void yellowfin_init_ring(struct net_device *dev) { @@ -693,62 +561,66 @@ static void yellowfin_init_ring(struct net_device *dev) yp->tx_full = 0; yp->cur_rx = yp->cur_tx = 0; - yp->dirty_rx = yp->dirty_tx = 0; + yp->dirty_tx = 0; yp->rx_buf_sz = (dev->mtu <= 1500 ? PKT_BUF_SZ : dev->mtu + 32); yp->rx_head_desc = &yp->rx_ring[0]; for (i = 0; i < RX_RING_SIZE; i++) { - struct sk_buff *skb; - - yp->rx_ring[i].request_cnt = yp->rx_buf_sz; - yp->rx_ring[i].cmd = CMD_RX_BUF | INTR_ALWAYS; + yp->rx_ring[i].dbdma_cmd = + cpu_to_le32(CMD_RX_BUF | INTR_ALWAYS | yp->rx_buf_sz); + yp->rx_ring[i].branch_addr = virt_to_le32desc(&yp->rx_ring[i+1]); + } + /* Mark the last entry as wrapping the ring. */ + yp->rx_ring[i-1].branch_addr = virt_to_le32desc(&yp->rx_ring[0]); - skb = dev_alloc_skb(yp->rx_buf_sz); + for (i = 0; i < RX_RING_SIZE; i++) { + struct sk_buff *skb = dev_alloc_skb(yp->rx_buf_sz); yp->rx_skbuff[i] = skb; - if (skb) { - skb->dev = dev; /* Mark as being used by this device. */ - skb_reserve(skb, 2); /* 16 byte align the IP header. */ - yp->rx_ring[i].addr = virt_to_bus(skb->tail); - } else if (yp->dirty_rx == 0) - yp->dirty_rx = (unsigned int)(0 - RX_RING_SIZE); - yp->rx_ring[i].branch_addr = virt_to_bus(&yp->rx_ring[i+1]); + if (skb == NULL) + break; + skb->dev = dev; /* Mark as being used by this device. */ + skb_reserve(skb, 2); /* 16 byte align the IP header. */ + yp->rx_ring[i].addr = virt_to_le32desc(skb->tail); } - /* Mark the last entry as wrapping the ring. */ - yp->rx_ring[i-1].cmd = CMD_RX_BUF | INTR_ALWAYS | BRANCH_ALWAYS; - yp->rx_ring[i-1].branch_addr = virt_to_bus(&yp->rx_ring[0]); + yp->rx_ring[i-1].dbdma_cmd = cpu_to_le32(CMD_STOP); + yp->dirty_rx = (unsigned int)(i - RX_RING_SIZE); -/*#define NO_TXSTATS*/ +#define NO_TXSTATS #ifdef NO_TXSTATS /* In this mode the Tx ring needs only a single descriptor. */ for (i = 0; i < TX_RING_SIZE; i++) { yp->tx_skbuff[i] = 0; - yp->tx_ring[i].cmd = CMD_STOP; - yp->tx_ring[i].branch_addr = virt_to_bus(&yp->tx_ring[i+1]); + yp->tx_ring[i].dbdma_cmd = cpu_to_le32(CMD_STOP); + yp->tx_ring[i].branch_addr = virt_to_le32desc(&yp->tx_ring[i+1]); } - yp->tx_ring[--i].cmd = CMD_STOP | BRANCH_ALWAYS; /* Wrap ring */ - yp->tx_ring[i].branch_addr = virt_to_bus(&yp->tx_ring[0]); + /* Wrap ring */ + yp->tx_ring[--i].dbdma_cmd = cpu_to_le32(CMD_STOP | BRANCH_ALWAYS); + yp->tx_ring[i].branch_addr = virt_to_le32desc(&yp->tx_ring[0]); #else /* Tx ring needs a pair of descriptors, the second for the status. */ for (i = 0; i < TX_RING_SIZE*2; i++) { yp->tx_skbuff[i/2] = 0; - yp->tx_ring[i].cmd = CMD_STOP; /* Branch on Tx error. */ - yp->tx_ring[i].branch_addr = virt_to_bus(&yp->tx_ring[i+1]); + /* Branch on Tx error. */ + yp->tx_ring[i].dbdma_cmd = cpu_to_le32(CMD_STOP); + yp->tx_ring[i].branch_addr = virt_to_le32desc(&yp->tx_ring[i+1]); i++; - if (chip_tbl[yp->chip_id].flags & FullTxStatus) { - yp->tx_ring[i].cmd = CMD_TXSTATUS; + if (yp->flags & FullTxStatus) { + yp->tx_ring[i].dbdma_cmd = + cpu_to_le32(CMD_TXSTATUS | sizeof(yp->tx_status[i])); yp->tx_ring[i].request_cnt = sizeof(yp->tx_status[i]); - yp->tx_ring[i].addr = virt_to_bus(&yp->tx_status[i/2]); + yp->tx_ring[i].addr = virt_to_le32desc(&yp->tx_status[i/2]); } else { /* Symbios chips write only tx_errs word. */ - yp->tx_ring[i].cmd = CMD_TXSTATUS | INTR_ALWAYS; + yp->tx_ring[i].dbdma_cmd = + cpu_to_le32(CMD_TXSTATUS | INTR_ALWAYS | 2); yp->tx_ring[i].request_cnt = 2; - yp->tx_ring[i].addr = virt_to_bus(&yp->tx_status[i/2].tx_errs); + yp->tx_ring[i].addr = virt_to_le32desc(&yp->tx_status[i/2].tx_errs); } - yp->tx_ring[i].branch_addr = virt_to_bus(&yp->tx_ring[i+1]); + yp->tx_ring[i].branch_addr = virt_to_le32desc(&yp->tx_ring[i+1]); } /* Wrap ring */ - yp->tx_ring[--i].cmd = CMD_TXSTATUS | BRANCH_ALWAYS | INTR_ALWAYS; - yp->tx_ring[i].branch_addr = virt_to_bus(&yp->tx_ring[0]); + yp->tx_ring[--i].dbdma_cmd |= cpu_to_le32(BRANCH_ALWAYS | INTR_ALWAYS); + yp->tx_ring[i].branch_addr = virt_to_le32desc(&yp->tx_ring[0]); #endif yp->tx_tail_desc = &yp->tx_status[0]; return; @@ -759,6 +631,8 @@ static int yellowfin_start_xmit(struct sk_buff *skb, struct net_device *dev) struct yellowfin_private *yp = (struct yellowfin_private *)dev->priv; unsigned entry; + netif_stop_queue (dev); + /* Caution: the write order is important here, set the base address with the "ownership" bits last. */ @@ -767,34 +641,42 @@ static int yellowfin_start_xmit(struct sk_buff *skb, struct net_device *dev) yp->tx_skbuff[entry] = skb; + if (gx_fix) { /* Note: only works for paddable protocols e.g. IP. */ + int cacheline_end = (virt_to_bus(skb->data) + skb->len) % 32; + /* Fix GX chipset errata. */ + if (cacheline_end > 24 || cacheline_end == 0) + skb->len += 32 - cacheline_end + 1; + } #ifdef NO_TXSTATS - yp->tx_ring[entry].request_cnt = skb->len; - yp->tx_ring[entry].addr = virt_to_bus(skb->data); - yp->tx_ring[entry].status = 0; + yp->tx_ring[entry].addr = virt_to_le32desc(skb->data); + yp->tx_ring[entry].result_status = 0; if (entry >= TX_RING_SIZE-1) { - yp->tx_ring[0].cmd = CMD_STOP; /* New stop command. */ - yp->tx_ring[TX_RING_SIZE-1].cmd = CMD_TX_PKT | BRANCH_ALWAYS; + /* New stop command. */ + yp->tx_ring[0].dbdma_cmd = cpu_to_le32(CMD_STOP); + yp->tx_ring[TX_RING_SIZE-1].dbdma_cmd = + cpu_to_le32(CMD_TX_PKT|BRANCH_ALWAYS | skb->len); } else { - yp->tx_ring[entry+1].cmd = CMD_STOP; /* New stop command. */ - yp->tx_ring[entry].cmd = CMD_TX_PKT | BRANCH_IFTRUE; + yp->tx_ring[entry+1].dbdma_cmd = cpu_to_le32(CMD_STOP); + yp->tx_ring[entry].dbdma_cmd = + cpu_to_le32(CMD_TX_PKT | BRANCH_IFTRUE | skb->len); } yp->cur_tx++; #else yp->tx_ring[entry<<1].request_cnt = skb->len; - yp->tx_ring[entry<<1].addr = virt_to_bus(skb->data); + yp->tx_ring[entry<<1].addr = virt_to_le32desc(skb->data); /* The input_last (status-write) command is constant, but we must rewrite the subsequent 'stop' command. */ yp->cur_tx++; { unsigned next_entry = yp->cur_tx % TX_RING_SIZE; - yp->tx_ring[next_entry<<1].cmd = CMD_STOP; + yp->tx_ring[next_entry<<1].dbdma_cmd = cpu_to_le32(CMD_STOP); } /* Final step -- overwrite the old 'stop' command. */ - yp->tx_ring[entry<<1].cmd = - (entry % 6) == 0 ? CMD_TX_PKT | INTR_ALWAYS | BRANCH_IFTRUE : - CMD_TX_PKT | BRANCH_IFTRUE; + yp->tx_ring[entry<<1].dbdma_cmd = + cpu_to_le32( ((entry % 6) == 0 ? CMD_TX_PKT|INTR_ALWAYS|BRANCH_IFTRUE : + CMD_TX_PKT | BRANCH_IFTRUE) | skb->len); #endif /* Non-x86 Todo: explicitly flush cache lines here. */ @@ -802,8 +684,8 @@ static int yellowfin_start_xmit(struct sk_buff *skb, struct net_device *dev) /* Wake the potentially-idle transmit channel. */ outl(0x10001000, dev->base_addr + TxCtrl); - if (yp->cur_tx - yp->dirty_tx < TX_RING_SIZE - 1) - netif_start_queue(dev); /* Typical path */ + if (yp->cur_tx - yp->dirty_tx < TX_QUEUE_SIZE) + netif_start_queue (dev); /* Typical path */ else yp->tx_full = 1; dev->trans_start = jiffies; @@ -853,20 +735,23 @@ static void yellowfin_interrupt(int irq, void *dev_instance, struct pt_regs *reg #ifdef NO_TXSTATS for (; yp->cur_tx - yp->dirty_tx > 0; yp->dirty_tx++) { int entry = yp->dirty_tx % TX_RING_SIZE; - if (yp->tx_ring[entry].status == 0) + if (yp->tx_ring[entry].result_status == 0) break; + yp->stats.tx_bytes += yp->tx_skbuff[entry]->len; + yp->stats.tx_packets++; /* Free the original skb. */ dev_kfree_skb_irq(yp->tx_skbuff[entry]); yp->tx_skbuff[entry] = 0; - yp->stats.tx_packets++; } - if (yp->tx_full && - test_bit(LINK_STATE_XOFF, &dev->flags) && - yp->cur_tx - yp->dirty_tx < TX_RING_SIZE - 4) { + if (yp->tx_full + && yp->cur_tx - yp->dirty_tx < TX_QUEUE_SIZE - 4) { /* The ring is no longer full, clear tbusy. */ yp->tx_full = 0; - netif_wake_queue (dev); } + if (yp->tx_full) + netif_stop_queue(dev); + else + netif_wake_queue(dev); #else if (intr_status & IntrTxDone || yp->tx_tail_desc->tx_errs) { @@ -890,7 +775,7 @@ static void yellowfin_interrupt(int irq, void *dev_instance, struct pt_regs *reg #endif if (tx_errs == 0) break; /* It still hasn't been Txed */ - if (tx_errs & 0xF8100000) { + if (tx_errs & 0xF810) { /* There was an major error, log it. */ #ifndef final_version if (yellowfin_debug > 1) @@ -914,10 +799,10 @@ static void yellowfin_interrupt(int irq, void *dev_instance, struct pt_regs *reg #ifdef ETHER_STATS if (tx_errs & 0x0400) yp->stats.tx_deferred++; #endif + yp->stats.tx_bytes += yp->tx_skbuff[entry]->len; yp->stats.collisions += tx_errs & 15; yp->stats.tx_packets++; } - /* Free the original skb. */ dev_kfree_skb_irq(yp->tx_skbuff[entry]); yp->tx_skbuff[entry] = 0; @@ -933,13 +818,15 @@ static void yellowfin_interrupt(int irq, void *dev_instance, struct pt_regs *reg } #endif - if (yp->tx_full && - test_bit(LINK_STATE_XOFF, &dev->flags) && - yp->cur_tx - dirty_tx < TX_RING_SIZE - 2) { + if (yp->tx_full + && yp->cur_tx - dirty_tx < TX_QUEUE_SIZE - 2) { /* The ring is no longer full, clear tbusy. */ yp->tx_full = 0; - netif_wake_queue (dev); } + if (yp->tx_full) + netif_stop_queue(dev); + else + netif_wake_queue(dev); yp->dirty_tx = dirty_tx; yp->tx_tail_desc = &yp->tx_status[dirty_tx % TX_RING_SIZE]; @@ -964,15 +851,14 @@ static void yellowfin_interrupt(int irq, void *dev_instance, struct pt_regs *reg /* Code that should never be run! Perhaps remove after testing.. */ { static int stopit = 10; - if ((!test_bit(LINK_STATE_START, &dev->state)) && --stopit < 0) { + if ((!(test_bit(LINK_STATE_START, &dev->state))) && --stopit < 0) { printk(KERN_ERR "%s: Emergency stop, looping startup interrupt.\n", dev->name); free_irq(irq, dev); } } - spin_lock (&yp->lock); - return; + spin_unlock (&yp->lock); } /* This routine is logically part of the interrupt handler, but separated @@ -984,21 +870,22 @@ static int yellowfin_rx(struct net_device *dev) int boguscnt = 20; if (yellowfin_debug > 4) { - printk(KERN_DEBUG " In yellowfin_rx(), entry %d status %4.4x.\n", - entry, yp->rx_ring[entry].status); - printk(KERN_DEBUG " #%d desc. %4.4x %4.4x %8.8x %4.4x %4.4x.\n", - entry, yp->rx_ring[entry].cmd, - yp->rx_ring[entry].request_cnt, yp->rx_ring[entry].addr, - yp->rx_ring[entry].result_cnt, yp->rx_ring[entry].status); + printk(KERN_DEBUG " In yellowfin_rx(), entry %d status %8.8x.\n", + entry, yp->rx_ring[entry].result_status); + printk(KERN_DEBUG " #%d desc. %8.8x %8.8x %8.8x.\n", + entry, yp->rx_ring[entry].dbdma_cmd, yp->rx_ring[entry].addr, + yp->rx_ring[entry].result_status); } /* If EOP is set on the next entry, it's a new packet. Send it up. */ - while (yp->rx_head_desc->status) { + while (yp->rx_head_desc->result_status) { struct yellowfin_desc *desc = yp->rx_head_desc; - u16 desc_status = desc->status; - int data_size = desc->request_cnt - desc->result_cnt; - u8 *buf_addr = bus_to_virt(desc->addr); - s16 frame_status = get_unaligned((s16*)(buf_addr+data_size-2)); + u16 desc_status = le32_to_cpu(desc->result_status) >> 16; + int data_size = + (le32_to_cpu(desc->dbdma_cmd) - le32_to_cpu(desc->result_status)) + & 0xffff; + u8 *buf_addr = le32desc_to_virt(desc->addr); + s16 frame_status = get_unaligned((s16*)&(buf_addr[data_size - 2])); if (yellowfin_debug > 4) printk(KERN_DEBUG " yellowfin_rx() status was %4.4x.\n", @@ -1009,7 +896,7 @@ static int yellowfin_rx(struct net_device *dev) printk(KERN_WARNING "%s: Oversized Ethernet frame spanned multiple buffers," " status %4.4x!\n", dev->name, desc_status); yp->stats.rx_length_errors++; - } else if (yp->chip_id == 0 && (frame_status & 0x0038)) { + } else if ((yp->flags & IsGigabit) && (frame_status & 0x0038)) { /* There was a error. */ if (yellowfin_debug > 3) printk(KERN_DEBUG " yellowfin_rx() Rx error was %4.4x.\n", @@ -1019,7 +906,7 @@ static int yellowfin_rx(struct net_device *dev) if (frame_status & 0x0008) yp->stats.rx_frame_errors++; if (frame_status & 0x0010) yp->stats.rx_crc_errors++; if (frame_status < 0) yp->stats.rx_dropped++; - } else if (yp->chip_id != 0 && + } else if ( !(yp->flags & IsGigabit) && ((buf_addr[data_size-1] & 0x85) || buf_addr[data_size-2] & 0xC0)) { u8 status1 = buf_addr[data_size-2]; u8 status2 = buf_addr[data_size-1]; @@ -1029,14 +916,16 @@ static int yellowfin_rx(struct net_device *dev) if (status2 & 0x04) yp->stats.rx_crc_errors++; if (status2 & 0x80) yp->stats.rx_dropped++; #ifdef YF_PROTOTYPE /* Support for prototype hardware errata. */ - } else if (memcmp(bus_to_virt(yp->rx_ring[entry].addr), + } else if ((yp->flags & HasMACAddrBug) && + memcmp(le32desc_to_virt(yp->rx_ring[entry].addr), dev->dev_addr, 6) != 0 - && memcmp(bus_to_virt(yp->rx_ring[entry].addr), + && memcmp(le32desc_to_virt(yp->rx_ring[entry].addr), "\377\377\377\377\377\377", 6) != 0) { - printk(KERN_WARNING "%s: Bad frame to %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x.\n", - dev->name, buf_addr[0], buf_addr[1], buf_addr[2], - buf_addr[3], buf_addr[4], buf_addr[5]); - bogus_rx++; + if (bogus_rx++ == 0) + printk(KERN_WARNING "%s: Bad frame to %2.2x:%2.2x:%2.2x:%2.2x:" + "%2.2x:%2.2x.\n", + dev->name, buf_addr[0], buf_addr[1], buf_addr[2], + buf_addr[3], buf_addr[4], buf_addr[5]); #endif } else { struct sk_buff *skb; @@ -1055,10 +944,10 @@ static int yellowfin_rx(struct net_device *dev) if (pkt_len > rx_copybreak) { char *temp = skb_put(skb = yp->rx_skbuff[entry], pkt_len); #ifndef final_verison /* Remove after testing. */ - if (bus_to_virt(yp->rx_ring[entry].addr) != temp) + if (le32desc_to_virt(yp->rx_ring[entry].addr) != temp) printk(KERN_WARNING "%s: Warning -- the skbuff addresses " "do not match in yellowfin_rx: %p vs. %p / %p.\n", - dev->name, bus_to_virt(yp->rx_ring[entry].addr), + dev->name, le32desc_to_virt(yp->rx_ring[entry].addr), skb->head, temp); #endif yp->rx_skbuff[entry] = NULL; @@ -1068,19 +957,19 @@ static int yellowfin_rx(struct net_device *dev) break; skb->dev = dev; skb_reserve(skb, 2); /* 16 byte align the data fields */ -#if 1 - eth_copy_and_sum(skb, bus_to_virt(yp->rx_ring[entry].addr), - pkt_len, 0); +#if 1 || USE_IP_CSUM + eth_copy_and_sum(skb, yp->rx_skbuff[entry]->tail, pkt_len, 0); skb_put(skb, pkt_len); #else - memcpy(skb_put(skb, pkt_len), - bus_to_virt(yp->rx_ring[entry].addr), pkt_len); + memcpy(skb_put(skb, pkt_len), yp->rx_skbuff[entry]->tail, + pkt_len); #endif } skb->protocol = eth_type_trans(skb, dev); netif_rx(skb); dev->last_rx = jiffies; yp->stats.rx_packets++; + yp->stats.rx_bytes += pkt_len; } entry = (++yp->cur_rx) % RX_RING_SIZE; yp->rx_head_desc = &yp->rx_ring[entry]; @@ -1088,24 +977,25 @@ static int yellowfin_rx(struct net_device *dev) /* Refill the Rx ring buffers. */ for (; yp->cur_rx - yp->dirty_rx > 0; yp->dirty_rx++) { - struct sk_buff *skb; entry = yp->dirty_rx % RX_RING_SIZE; if (yp->rx_skbuff[entry] == NULL) { - skb = dev_alloc_skb(yp->rx_buf_sz); + struct sk_buff *skb = dev_alloc_skb(yp->rx_buf_sz); if (skb == NULL) break; /* Better luck next round. */ + yp->rx_skbuff[entry] = skb; skb->dev = dev; /* Mark as being used by this device. */ skb_reserve(skb, 2); /* Align IP on 16 byte boundaries */ - yp->rx_ring[entry].addr = virt_to_bus(skb->tail); - yp->rx_skbuff[entry] = skb; + yp->rx_ring[entry].addr = virt_to_le32desc(skb->tail); } - yp->rx_ring[entry].cmd = CMD_STOP; - yp->rx_ring[entry].status = 0; /* Clear complete bit. */ + yp->rx_ring[entry].dbdma_cmd = cpu_to_le32(CMD_STOP); + yp->rx_ring[entry].result_status = 0; /* Clear complete bit. */ if (entry != 0) - yp->rx_ring[entry - 1].cmd = CMD_RX_BUF | INTR_ALWAYS; + yp->rx_ring[entry - 1].dbdma_cmd = + cpu_to_le32(CMD_RX_BUF | INTR_ALWAYS | yp->rx_buf_sz); else - yp->rx_ring[RX_RING_SIZE - 1].cmd = - CMD_RX_BUF | INTR_ALWAYS | BRANCH_ALWAYS; + yp->rx_ring[RX_RING_SIZE - 1].dbdma_cmd = + cpu_to_le32(CMD_RX_BUF | INTR_ALWAYS | BRANCH_ALWAYS + | yp->rx_buf_sz); } return 0; @@ -1130,7 +1020,7 @@ static int yellowfin_close(struct net_device *dev) struct yellowfin_private *yp = (struct yellowfin_private *)dev->priv; int i; - netif_stop_queue(dev); + netif_stop_queue (dev); if (yellowfin_debug > 1) { printk(KERN_DEBUG "%s: Shutting down ethercard, status was Tx %4.4x Rx %4.4x Int %2.2x.\n", @@ -1149,16 +1039,14 @@ static int yellowfin_close(struct net_device *dev) del_timer(&yp->timer); -#ifdef __i386__ +#if !defined(final_version) && defined(__i386__) if (yellowfin_debug > 2) { printk("\n"KERN_DEBUG" Tx ring at %8.8x:\n", (int)virt_to_bus(yp->tx_ring)); for (i = 0; i < TX_RING_SIZE*2; i++) - printk(" %c #%d desc. %4.4x %4.4x %8.8x %8.8x %4.4x %4.4x.\n", + printk(" %c #%d desc. %8.8x %8.8x %8.8x %8.8x.\n", inl(ioaddr + TxPtr) == (long)&yp->tx_ring[i] ? '>' : ' ', - i, yp->tx_ring[i].cmd, - yp->tx_ring[i].request_cnt, yp->tx_ring[i].addr, - yp->tx_ring[i].branch_addr, - yp->tx_ring[i].result_cnt, yp->tx_ring[i].status); + i, yp->tx_ring[i].dbdma_cmd, yp->tx_ring[i].addr, + yp->tx_ring[i].branch_addr, yp->tx_ring[i].result_status); printk(KERN_DEBUG " Tx status %p:\n", yp->tx_status); for (i = 0; i < TX_RING_SIZE; i++) printk(" #%d status %4.4x %4.4x %4.4x %4.4x.\n", @@ -1167,16 +1055,16 @@ static int yellowfin_close(struct net_device *dev) printk("\n"KERN_DEBUG " Rx ring %8.8x:\n", (int)virt_to_bus(yp->rx_ring)); for (i = 0; i < RX_RING_SIZE; i++) { - printk(KERN_DEBUG " %c #%d desc. %4.4x %4.4x %8.8x %4.4x %4.4x\n", + printk(KERN_DEBUG " %c #%d desc. %8.8x %8.8x %8.8x\n", inl(ioaddr + RxPtr) == (long)&yp->rx_ring[i] ? '>' : ' ', - i, yp->rx_ring[i].cmd, - yp->rx_ring[i].request_cnt, yp->rx_ring[i].addr, - yp->rx_ring[i].result_cnt, yp->rx_ring[i].status); + i, yp->rx_ring[i].dbdma_cmd, yp->rx_ring[i].addr, + yp->rx_ring[i].result_status); if (yellowfin_debug > 6) { - if (*(u8*)yp->rx_ring[i].addr != 0x69) { + if (get_unaligned((u8*)yp->rx_ring[i].addr) != 0x69) { int j; for (j = 0; j < 0x50; j++) - printk(" %4.4x", ((u16*)yp->rx_ring[i].addr)[j]); + printk(" %4.4x", + get_unaligned(((u16*)yp->rx_ring[i].addr) + j)); printk("\n"); } } @@ -1188,7 +1076,7 @@ static int yellowfin_close(struct net_device *dev) /* Free all the skbuffs in the Rx queue. */ for (i = 0; i < RX_RING_SIZE; i++) { - yp->rx_ring[i].cmd = CMD_STOP; + yp->rx_ring[i].dbdma_cmd = cpu_to_le32(CMD_STOP); yp->rx_ring[i].addr = 0xBADF00D0; /* An invalid address. */ if (yp->rx_skbuff[i]) { dev_kfree_skb(yp->rx_skbuff[i]); @@ -1212,7 +1100,7 @@ static int yellowfin_close(struct net_device *dev) return 0; } -static struct enet_statistics *yellowfin_get_stats(struct net_device *dev) +static struct net_device_stats *yellowfin_get_stats(struct net_device *dev) { struct yellowfin_private *yp = (struct yellowfin_private *)dev->priv; return &yp->stats; @@ -1267,7 +1155,7 @@ static void set_rx_mode(struct net_device *dev) i++, mclist = mclist->next) { /* Due to a bug in the early chip versions, multiple filter slots must be set for each address. */ - if (yp->chip_id == 0) { + if (yp->flags & HasMulticastBug) { set_bit((ether_crc_le(3, mclist->dmi_addr) >> 3) & 0x3f, hash_table); set_bit((ether_crc_le(4, mclist->dmi_addr) >> 3) & 0x3f, @@ -1303,7 +1191,7 @@ static int mii_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) data[3] = mdio_read(ioaddr, data[0] & 0x1f, data[1] & 0x1f); return 0; case SIOCDEVPRIVATE+2: /* Write the specified MII register */ - if (!suser()) + if (!capable(CAP_NET_ADMIN)) return -EPERM; mdio_write(ioaddr, data[0] & 0x1f, data[1] & 0x1f, data[2]); return 0; @@ -1314,40 +1202,201 @@ static int mii_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) #endif /* HAVE_PRIVATE_IOCTL */ -/* An additional parameter that may be passed in... */ -static int debug = -1; - -static int __init yellowfin_init_module(void) +static int __devinit yellowfin_init_one(struct pci_dev *pdev, + const struct pci_device_id *ent) { - if (debug >= 0) - yellowfin_debug = debug; + struct net_device *dev; + struct yellowfin_private *yp; + int option, i, irq; + int flags, chip_idx; + static int find_cnt = 0; + long ioaddr; + + chip_idx = ent->driver_data; + flags = chip_info[chip_idx].flags; + + dev = init_etherdev(NULL, 0); + if (!dev) { + printk (KERN_ERR PFX "cannot allocate ethernet device\n"); + return -ENOMEM; + } + + dev->priv = kmalloc(sizeof(*yp) + PRIV_ALIGN, GFP_KERNEL); + if (!dev->priv) + goto err_out_free_netdev; + yp = (void *)(((long)dev->priv + PRIV_ALIGN) & ~PRIV_ALIGN); + memset(yp, 0, sizeof(*yp)); + yp->priv_addr = dev->priv; /* store real addr for kfree */ + dev->priv = yp; /* use aligned addr */ + + if (!request_region (pci_resource_start (pdev, 0), + YELLOWFIN_SIZE, YELLOWFIN_MODULE_NAME)) { + printk (KERN_ERR PFX "cannot obtain I/O port region\n"); + goto err_out_free_priv; + } + if (!request_mem_region (pci_resource_start (pdev, 1), + YELLOWFIN_SIZE, YELLOWFIN_MODULE_NAME)) { + printk (KERN_ERR PFX "cannot obtain MMIO region\n"); + goto err_out_free_pio_region; + } + + pci_enable_device (pdev); + pci_set_master (pdev); + +#ifdef USE_IO_OPS + ioaddr = pci_resource_start (pdev, 0); +#else + ioaddr = pci_resource_start (pdev, 1); +#endif + irq = pdev->irq; + + printk(KERN_INFO "%s: %s type %8x at 0x%lx, ", + dev->name, chip_info[chip_idx].name, inl(ioaddr + ChipRev), ioaddr); + + if (flags & IsGigabit) + for (i = 0; i < 6; i++) + dev->dev_addr[i] = inb(ioaddr + StnAddr + i); + else { + int ee_offset = (read_eeprom(ioaddr, 6) == 0xff ? 0x100 : 0); + for (i = 0; i < 6; i++) + dev->dev_addr[i] = read_eeprom(ioaddr, ee_offset + i); + } + for (i = 0; i < 5; i++) + printk("%2.2x:", dev->dev_addr[i]); + printk("%2.2x, IRQ %d.\n", dev->dev_addr[i], irq); + + /* Reset the chip. */ + outl(0x80000000, ioaddr + DMACtrl); + + dev->base_addr = ioaddr; + dev->irq = irq; + + pdev->driver_data = dev; + yp->chip_id = chip_idx; + yp->flags = flags; + yp->lock = SPIN_LOCK_UNLOCKED; + + option = find_cnt < MAX_UNITS ? options[find_cnt] : 0; + if (dev->mem_start) + option = dev->mem_start; + + /* The lower four bits are the media type. */ + if (option > 0) { + if (option & 0x200) + yp->full_duplex = 1; + yp->default_port = option & 15; + if (yp->default_port) + yp->medialock = 1; + } + if (find_cnt < MAX_UNITS && full_duplex[find_cnt] > 0) + yp->full_duplex = 1; + + if (yp->full_duplex) + yp->duplex_lock = 1; + + /* The Yellowfin-specific entries in the device structure. */ + dev->open = &yellowfin_open; + dev->hard_start_xmit = &yellowfin_start_xmit; + dev->stop = &yellowfin_close; + dev->get_stats = &yellowfin_get_stats; + dev->set_multicast_list = &set_rx_mode; +#ifdef HAVE_PRIVATE_IOCTL + dev->do_ioctl = &mii_ioctl; +#endif + dev->tx_timeout = yellowfin_tx_timeout; + dev->watchdog_timeo = TX_TIMEOUT; - return yellowfin_probe(); + if (mtu) + dev->mtu = mtu; + + if (yp->flags & HasMII) { + int phy, phy_idx = 0; + for (phy = 0; phy < 32 && phy_idx < 4; phy++) { + int mii_status = mdio_read(ioaddr, phy, 1); + if (mii_status != 0xffff && + mii_status != 0x0000) { + yp->phys[phy_idx++] = phy; + yp->advertising = mdio_read(ioaddr, phy, 4); + printk(KERN_INFO "%s: MII PHY found at address %d, status " + "0x%4.4x advertising %4.4x.\n", + dev->name, phy, mii_status, yp->advertising); + } + } + yp->mii_cnt = phy_idx; + } + + find_cnt++; + + return 0; + +err_out_free_pio_region: + release_region (pci_resource_start (pdev, 0), YELLOWFIN_SIZE); +err_out_free_priv: + kfree (dev->priv); +err_out_free_netdev: + unregister_netdev (dev); + kfree (dev); + return -ENODEV; } -static void __exit yellowfin_cleanup_module (void) +static void __devexit yellowfin_remove_one (struct pci_dev *pdev) { - struct net_device *next_dev; - - /* No need to check MOD_IN_USE, as sys_delete_module() checks. */ - while (root_yellowfin_dev) { - next_dev = ((struct yellowfin_private *)root_yellowfin_dev->priv)->next_module; - unregister_netdev(root_yellowfin_dev); - release_region(root_yellowfin_dev->base_addr, YELLOWFIN_TOTAL_SIZE); - kfree(root_yellowfin_dev); - root_yellowfin_dev = next_dev; + struct net_device *dev = pdev->driver_data; + struct yellowfin_private *np; + + if (!dev) { + printk (KERN_ERR "remove non-existent device\n"); + return; } + np = (struct yellowfin_private *) dev->priv; + + unregister_netdev (dev); + +#ifdef USE_IO_OPS + release_region (dev->base_addr, YELLOWFIN_SIZE); +#else + iounmap ((void *) dev->base_addr); + release_mem_region (dev->base_addr, YELLOWFIN_SIZE); +#endif + + if (np->priv_addr) + kfree (np->priv_addr); + + kfree (dev); +} + + +static struct pci_driver yellowfin_driver = { + name: YELLOWFIN_MODULE_NAME, + id_table: yellowfin_pci_tbl, + probe: yellowfin_init_one, + remove: yellowfin_remove_one, +}; + + +static int __init yellowfin_init (void) +{ + if (debug) /* Emit version even if no cards detected. */ + printk(KERN_INFO "%s", version); + return pci_register_driver (&yellowfin_driver) > 0 ? 0 : -ENODEV; +} + + +static void __exit yellowfin_cleanup (void) +{ + pci_unregister_driver (&yellowfin_driver); } -module_init(yellowfin_init_module); -module_exit(yellowfin_cleanup_module); + +module_init(yellowfin_init); +module_exit(yellowfin_exit); /* * Local variables: - * compile-command: "gcc -DMODULE -D__KERNEL__ -I/usr/src/linux/net/inet -Wall -Wstrict-prototypes -O6 -c yellowfin.c `[ -f /usr/include/linux/modversions.h ] && echo -DMODVERSIONS`" - * compile-command-alphaLX: "gcc -DMODULE -D__KERNEL__ -I/usr/src/linux/net/inet -Wall -Wstrict-prototypes -O2 -c yellowfin.c `[ -f /usr/include/linux/modversions.h ] && echo -DMODVERSIONS` -fomit-frame-pointer -fno-strength-reduce -mno-fp-regs -Wa,-m21164a -DBWX_USABLE -DBWIO_ENABLED" - * SMP-compile-command: "gcc -D__SMP__ -DMODULE -D__KERNEL__ -I/usr/src/linux/net/inet -Wall -Wstrict-prototypes -O6 -c yellowfin.c `[ -f /usr/include/linux/modversions.h ] && echo -DMODVERSIONS`" + * compile-command: "gcc -DMODULE -D__KERNEL__ -Wall -Wstrict-prototypes -O6 -c yellowfin.c `[ -f /usr/include/linux/modversions.h ] && echo -DMODVERSIONS`" + * compile-command-alphaLX: "gcc -DMODULE -D__KERNEL__ -Wall -Wstrict-prototypes -O2 -c yellowfin.c `[ -f /usr/include/linux/modversions.h ] && echo -DMODVERSIONS` -fomit-frame-pointer -fno-strength-reduce -mno-fp-regs -Wa,-m21164a -DBWX_USABLE -DBWIO_ENABLED" + * SMP-compile-command: "gcc -D__SMP__ -DMODULE -D__KERNEL__ -Wall -Wstrict-prototypes -O6 -c yellowfin.c `[ -f /usr/include/linux/modversions.h ] && echo -DMODVERSIONS`" * c-indent-level: 4 * c-basic-offset: 4 * tab-width: 4 diff --git a/drivers/usb/hid.c b/drivers/usb/hid.c index ce7bc7e34..e9bd801d5 100644 --- a/drivers/usb/hid.c +++ b/drivers/usb/hid.c @@ -1363,7 +1363,7 @@ static void* hid_probe(struct usb_device *dev, unsigned int ifnum) hid_init_input(hid); input_register_device(&hid->input); - printk(KERN_INFO "input%d: USB HID v%d.%d %s\n", + printk(KERN_INFO "input%d: USB HID v%x.%02x %s\n", hid->input.number, hid->version >> 8, hid->version & 0xff, (hid->application & 0xffff) <= 8 ? hid_name[hid->application & 0xffff] : "device"); diff --git a/drivers/usb/plusb.c b/drivers/usb/plusb.c index 671ed942c..0cac10898 100644 --- a/drivers/usb/plusb.c +++ b/drivers/usb/plusb.c @@ -27,7 +27,6 @@ /*****************************************************************************/ -#include #include #include #include diff --git a/include/asm-ppc/hardirq.h b/include/asm-ppc/hardirq.h index 80c3e1de6..c2c58315e 100644 --- a/include/asm-ppc/hardirq.h +++ b/include/asm-ppc/hardirq.h @@ -1,6 +1,7 @@ #ifndef __ASM_HARDIRQ_H #define __ASM_HARDIRQ_H +#include #include extern unsigned int local_irq_count[NR_CPUS]; diff --git a/include/linux/ax25.h b/include/linux/ax25.h index 1e492c8ff..9191445bb 100644 --- a/include/linux/ax25.h +++ b/include/linux/ax25.h @@ -29,9 +29,11 @@ #define SIOCAX25NOUID (SIOCPROTOPRIVATE+3) #define SIOCAX25OPTRT (SIOCPROTOPRIVATE+7) #define SIOCAX25CTLCON (SIOCPROTOPRIVATE+8) -#define SIOCAX25GETINFO (SIOCPROTOPRIVATE+9) +#define SIOCAX25GETINFOOLD (SIOCPROTOPRIVATE+9) #define SIOCAX25ADDFWD (SIOCPROTOPRIVATE+10) #define SIOCAX25DELFWD (SIOCPROTOPRIVATE+11) +#define SIOCAX25DEVCTL (SIOCPROTOPRIVATE+12) +#define SIOCAX25GETINFO (SIOCPROTOPRIVATE+13) #define AX25_SET_RT_IPMODE 2 @@ -80,6 +82,17 @@ struct ax25_ctl_struct { ax25_address digi_addr[AX25_MAX_DIGIS]; }; +/* this will go away. Please do not export to user land */ +struct ax25_info_struct_depreciated { + unsigned int n2, n2count; + unsigned int t1, t1timer; + unsigned int t2, t2timer; + unsigned int t3, t3timer; + unsigned int idle, idletimer; + unsigned int state; + unsigned int rcv_q, snd_q; +}; + struct ax25_info_struct { unsigned int n2, n2count; unsigned int t1, t1timer; @@ -88,6 +101,9 @@ struct ax25_info_struct { unsigned int idle, idletimer; unsigned int state; unsigned int rcv_q, snd_q; + unsigned int vs, vr, va, vs_max; + unsigned int paclen; + unsigned int window; }; struct ax25_fwd_struct { diff --git a/net/ax25/af_ax25.c b/net/ax25/af_ax25.c index f39e19d41..a676660dc 100644 --- a/net/ax25/af_ax25.c +++ b/net/ax25/af_ax25.c @@ -1574,8 +1574,10 @@ static int ax25_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) return -EPERM; return ax25_ctl_ioctl(cmd, (void *)arg); - case SIOCAX25GETINFO: { + case SIOCAX25GETINFO: + case SIOCAX25GETINFOOLD: { struct ax25_info_struct ax25_info; + ax25_info.t1 = sk->protinfo.ax25->t1 / HZ; ax25_info.t2 = sk->protinfo.ax25->t2 / HZ; ax25_info.t3 = sk->protinfo.ax25->t3 / HZ; @@ -1589,8 +1591,28 @@ static int ax25_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) ax25_info.state = sk->protinfo.ax25->state; ax25_info.rcv_q = atomic_read(&sk->rmem_alloc); ax25_info.snd_q = atomic_read(&sk->wmem_alloc); - if (copy_to_user((void *)arg, &ax25_info, sizeof(ax25_info))) - return -EFAULT; + ax25_info.vs = sk->protinfo.ax25->vs; + ax25_info.vr = sk->protinfo.ax25->vr; + ax25_info.va = sk->protinfo.ax25->va; + ax25_info.vs_max = sk->protinfo.ax25->vs; /* reserved */ + ax25_info.paclen = sk->protinfo.ax25->paclen; + ax25_info.window = sk->protinfo.ax25->window; + + /* old structure? */ + if (cmd == SIOCAX25GETINFOOLD) { + static int warned = 0; + if (!warned) { + printk(KERN_INFO "%s uses old SIOCAX25GETINFO\n", + current->comm); + warned=1; + } + + if (copy_to_user((void *)arg, &ax25_info, sizeof(struct ax25_info_struct_depreciated))) + return -EFAULT; + } else { + if (copy_to_user((void *)arg, &ax25_info, sizeof(struct ax25_info_struct))) + return -EINVAL; + } return 0; } -- 2.11.4.GIT