110 #include <linux/module.h>
134 #include <linux/kernel.h>
135 #include <linux/types.h>
136 #include <linux/fcntl.h>
139 #include <linux/in.h>
140 #include <linux/string.h>
141 #include <linux/errno.h>
142 #include <linux/netdevice.h>
148 #include <linux/bitops.h>
149 #include <linux/ethtool.h>
154 #define DRV_NAME "eepro"
155 #define DRV_VERSION "0.13c"
157 #define compat_dev_kfree_skb( skb, mode ) dev_kfree_skb( (skb) )
159 #define SLOW_DOWN inb(0x80)
161 #define compat_init_data __initdata
167 { 0x300, 0x210, 0x240, 0x280, 0x2C0, 0x200, 0x320, 0x340, 0x360, 0};
183 #define EEPRO_IO_EXTENT 16
189 #define LAN595FX_10ISA 3
221 #define SA_ADDR0 0x00
222 #define SA_ADDR1 0xaa
223 #define SA_ADDR2 0x00
225 #define GetBit(x,y) ((x & (1<<y))>>y)
230 #define ee_BusWidth 2
231 #define ee_FlashAddr 3
232 #define ee_FlashMask 0x7
234 #define ee_reserved0 7
238 #define ee_IO0Mask 0x
243 #define ee_IntMask 0x7
248 #define ee_AutoPort 7
251 #define ee_reserved1 10
252 #define ee_AltReady 13
253 #define ee_reserved2 14
266 #define ee_BootType 1
267 #define ee_BootTypeMask 0x3
269 #define ee_FlashSock 4
273 #define ee_PowerMgt 10
275 #define ee_CPMask 0x7
278 #define ee_Stepping 0
279 #define ee_StepMask 0x0F
281 #define ee_BoardMask 0x0FFF
284 #define ee_INT_TO_IRQ 0
285 #define ee_FX_INT2IRQ 0x1EB8
289 #define ee_Checksum 0xBABA
293 #define ee_addr_vendor 0x10
294 #define ee_addr_id 0x11
295 #define ee_addr_SN 0x12
296 #define ee_addr_CRC_8 0x14
299 #define ee_vendor_intel0 0x25
300 #define ee_vendor_intel1 0xD4
301 #define ee_id_eepro10p0 0x10
302 #define ee_id_eepro10p1 0x31
304 #define TX_TIMEOUT ((4*HZ)/10)
308 static int eepro_probe1(
struct net_device *
dev,
int autoprobe);
314 static void eepro_transmit_interrupt(
struct net_device *
dev);
353 #define RAM_SIZE 0x8000
356 #define RCV_DEFAULT_RAM 0x6000
359 #define XMT_DEFAULT_RAM (RAM_SIZE - RCV_DEFAULT_RAM)
361 #define XMT_START_PRO RCV_DEFAULT_RAM
362 #define XMT_START_10 0x0000
363 #define RCV_START_PRO 0x0000
364 #define RCV_START_10 XMT_DEFAULT_RAM
366 #define RCV_DONE 0x0008
368 #define RX_ERROR 0x0d81
370 #define TX_DONE_BIT 0x0080
372 #define CHAIN_BIT 0x8000
373 #define XMT_STATUS 0x02
374 #define XMT_CHAIN 0x04
375 #define XMT_COUNT 0x06
377 #define BANK0_SELECT 0x00
378 #define BANK1_SELECT 0x40
379 #define BANK2_SELECT 0x80
382 #define COMMAND_REG 0x00
383 #define MC_SETUP 0x03
385 #define DIAGNOSE_CMD 0x07
386 #define RCV_ENABLE_CMD 0x08
387 #define RCV_DISABLE_CMD 0x0a
388 #define STOP_RCV_CMD 0x0b
389 #define RESET_CMD 0x0e
390 #define POWER_DOWN_CMD 0x18
391 #define RESUME_XMT_CMD 0x1c
392 #define SEL_RESET_CMD 0x1e
393 #define STATUS_REG 0x01
396 #define EXEC_STATUS 0x30
398 #define R_ROBIN_BITS 0xc0
399 #define ID_REG_MASK 0x2c
400 #define ID_REG_SIG 0x24
401 #define AUTO_ENABLE 0x10
402 #define INT_MASK_REG 0x03
403 #define RX_STOP_MASK 0x01
406 #define EXEC_MASK 0x08
407 #define ALL_MASK 0x0f
408 #define IO_32_BIT 0x10
410 #define RCV_STOP 0x06
412 #define XMT_BAR_PRO 0x0a
413 #define XMT_BAR_10 0x0b
415 #define HOST_ADDRESS_REG 0x0c
417 #define IO_PORT_32_BIT 0x0c
421 #define WORD_WIDTH 0x02
422 #define INT_ENABLE 0x80
423 #define INT_NO_REG 0x02
424 #define RCV_LOWER_LIMIT_REG 0x08
425 #define RCV_UPPER_LIMIT_REG 0x09
427 #define XMT_LOWER_LIMIT_REG_PRO 0x0a
428 #define XMT_UPPER_LIMIT_REG_PRO 0x0b
429 #define XMT_LOWER_LIMIT_REG_10 0x0b
430 #define XMT_UPPER_LIMIT_REG_10 0x0a
433 #define XMT_Chain_Int 0x20
434 #define XMT_Chain_ErrStop 0x40
435 #define RCV_Discard_BadFrame 0x80
437 #define PRMSC_Mode 0x01
438 #define Multi_IA 0x20
444 #define A_N_ENABLE 0x02
446 #define I_ADD_REG0 0x04
447 #define I_ADD_REG1 0x05
448 #define I_ADD_REG2 0x06
449 #define I_ADD_REG3 0x07
450 #define I_ADD_REG4 0x08
451 #define I_ADD_REG5 0x09
453 #define EEPROM_REG_PRO 0x0a
454 #define EEPROM_REG_10 0x0b
462 #define eepro_reset(ioaddr) outb(RESET_CMD, ioaddr)
465 #define eepro_sel_reset(ioaddr) { \
466 outb(SEL_RESET_CMD, ioaddr); \
472 #define eepro_dis_int(ioaddr) outb(ALL_MASK, ioaddr + INT_MASK_REG)
475 #define eepro_clear_int(ioaddr) outb(ALL_MASK, ioaddr + STATUS_REG)
478 #define eepro_en_int(ioaddr) outb(ALL_MASK & ~(RX_MASK | TX_MASK), \
479 ioaddr + INT_MASK_REG)
482 #define eepro_en_intexec(ioaddr) outb(ALL_MASK & ~(EXEC_MASK), ioaddr + INT_MASK_REG)
485 #define eepro_en_rx(ioaddr) outb(RCV_ENABLE_CMD, ioaddr)
488 #define eepro_dis_rx(ioaddr) outb(RCV_DISABLE_CMD, ioaddr)
491 #define eepro_sw2bank0(ioaddr) outb(BANK0_SELECT, ioaddr)
492 #define eepro_sw2bank1(ioaddr) outb(BANK1_SELECT, ioaddr)
493 #define eepro_sw2bank2(ioaddr) outb(BANK2_SELECT, ioaddr)
496 #define eepro_en_intline(ioaddr) outb(inb(ioaddr + REG1) | INT_ENABLE,\
500 #define eepro_dis_intline(ioaddr) outb(inb(ioaddr + REG1) & 0x7f, \
504 #define eepro_diag(ioaddr) outb(DIAGNOSE_CMD, ioaddr)
507 #define eepro_ack_rx(ioaddr) outb (RX_INT, ioaddr + STATUS_REG)
510 #define eepro_ack_tx(ioaddr) outb (TX_INT, ioaddr + STATUS_REG)
513 #define eepro_complete_selreset(ioaddr) { \
514 dev->stats.tx_errors++;\
515 eepro_sel_reset(ioaddr);\
517 lp->xmt_lower_limit;\
518 lp->tx_start = lp->tx_end;\
520 dev->trans_start = jiffies;\
521 netif_wake_queue(dev);\
522 eepro_en_rx(ioaddr);\
541 #define WakeupPort 0x279
542 #define WakeupSeq {0x6A, 0xB5, 0xDA, 0xED, 0xF6, 0xFB, 0x7D, 0xBE,\
543 0xDF, 0x6F, 0x37, 0x1B, 0x0D, 0x86, 0xC3, 0x61,\
544 0xB0, 0x58, 0x2C, 0x16, 0x8B, 0x45, 0xA2, 0xD1,\
545 0xE8, 0x74, 0x3A, 0x9D, 0xCE, 0xE7, 0x73, 0x43}
548 unsigned short int WS[32]=WakeupSeq;
556 for (i=0; i<32; i++) {
567 if (base_addr > 0x1ff)
568 return eepro_probe1(dev, 0);
570 else if (base_addr != 0)
573 for (i = 0; eepro_portlist[
i]; i++) {
576 if (eepro_probe1(dev, 1) == 0)
595 err = do_eepro_probe(dev);
613 for (i = 0; i < 8; i++)
658 for (i=0, j=0; i<15; i++)
665 static void eepro_recalc (
struct net_device *dev)
669 lp = netdev_priv(dev);
691 const char *
ifmap[] = {
"AUI",
"10Base2",
"10BaseT"};
699 printk(
"%s: Intel EtherExpress 10 ISA\n at %#x,",
703 printk(
"%s: Intel EtherExpress Pro/10+ ISA\n at %#x,",
707 printk(
"%s: Intel EtherExpress Pro/10 ISA at %#x,",
711 printk(
"%s: Intel 82595-based lan card at %#x,",
731 "enabled but not used!\n", dev->
name);
736 printEEPROMInfo(dev);
742 .ndo_open = eepro_open,
743 .ndo_stop = eepro_close,
744 .ndo_start_xmit = eepro_send_packet,
745 .ndo_set_rx_mode = set_multicast_list,
746 .ndo_tx_timeout = eepro_tx_timeout,
786 if ((
inb(ioaddr +
ID_REG) & R_ROBIN_BITS) != (counter + 0x40))
789 lp = netdev_priv(dev);
804 if (station_addr[0] == 0x0000 || station_addr[0] == 0xffff) {
814 for (i = 0; i < 8; i++) {
817 station_addr[1] = lp->
word[3];
818 station_addr[2] = lp->
word[4];
823 else if (station_addr[2] ==
SA_ADDR1)
828 for (i=0; i < 6; i++)
829 dev->
dev_addr[i] = ((
unsigned char *) station_addr)[5-
i];
843 if (dev->
irq < 2 && lp->
eepro != 0) {
846 unsigned irqMask = lp->
word[7];
849 irqMask &= irqMask - 1;
851 count =
ffs(irqMask);
854 dev->
irq = count - 1;
857 printk(
KERN_ERR " Duh! illegal interrupt vector stored in EEPROM.\n");
859 }
else if (dev->
irq == 2) {
869 eepro_print_info(dev);
893 static const char irqrmap[] = {-1,-1,0,1,-1,2,-1,-1,-1,0,3,4,-1,-1,-1,-1};
894 static const char irqrmap2[] = {-1,-1,4,0,1,2,-1,3,-1,4,5,6,7,-1,-1,-1};
895 static int eepro_grab_irq(
struct net_device *dev)
897 static const int irqlist[] = { 3, 4, 5, 7, 9, 10, 11, 12, 0 };
898 const int *irqp = irqlist;
924 unsigned long irq_mask;
957 unsigned short temp_reg, old8, old9;
965 irqMask = lp->
word[7];
987 if (dev->
irq < 2 && eepro_grab_irq(dev) == 0) {
1007 if (temp_reg & 0x10)
1009 for (i=0; i < 6; i++)
1012 temp_reg =
inb(ioaddr +
REG1);
1016 temp_reg =
inb(ioaddr +
REG2);
1017 outb(temp_reg | 0x14, ioaddr +
REG2);
1019 temp_reg =
inb(ioaddr +
REG3);
1020 outb(temp_reg & 0x3f, ioaddr +
REG3);
1070 old8 =
inb(ioaddr + 8);
1071 outb(~old8, ioaddr + 8);
1073 if ((temp_reg =
inb(ioaddr + 8)) == old8) {
1080 outb(old8, ioaddr + 8);
1081 old9 =
inb(ioaddr + 9);
1089 outb(old9, ioaddr + 9);
1109 netif_start_queue(dev);
1120 static void eepro_tx_timeout (
struct net_device *dev)
1127 "network cable problem");
1131 "network cable problem");
1140 unsigned long flags;
1152 netif_stop_queue (dev);
1158 unsigned char *
buf = skb->
data;
1160 if (hardware_send_packet(dev, buf, length))
1162 dev->
stats.tx_dropped++;
1165 netif_wake_queue(dev);
1170 dev_kfree_skb (skb);
1179 spin_unlock_irqrestore(&lp->
lock, flags);
1189 eepro_interrupt(
int irq,
void *
dev_id)
1193 int ioaddr,
status, boguscount = 20;
1196 lp = netdev_priv(dev);
1198 spin_lock(&lp->
lock);
1229 eepro_transmit_interrupt(dev);
1238 spin_unlock(&lp->
lock);
1242 static int eepro_close(
struct net_device *dev)
1248 netif_stop_queue(dev);
1253 temp_reg =
inb(ioaddr +
REG1);
1254 outb(temp_reg & 0x7f, ioaddr +
REG1);
1287 unsigned short mode;
1301 else if (mc_count == 0)
1313 unsigned short status, *eaddrs;
1314 int i, boguscount = 0;
1334 eaddrs = (
unsigned short *) ha->
addr;
1340 eaddrs = (
unsigned short *) dev->
dev_addr;
1378 }
else if ((i & 0x0f) == 0x03) {
1380 dev->
name, mc_count,
1381 mc_count > 1 ?
"es":
"");
1385 }
while (++boguscount < 100);
1401 #define eeprom_delay() { udelay(40); }
1402 #define EE_READ_CMD (6 << 6)
1408 unsigned short retval = 0;
1412 short ctrl_val =
EECS ;
1420 outb(ctrl_val, ee_addr);
1423 for (i = 8; i >= 0; i--) {
1424 short outval = (read_cmd & (1 <<
i)) ? ctrl_val |
EEDI
1426 outb(outval, ee_addr);
1429 outb(outval, ee_addr);
1432 outb(ctrl_val, ee_addr);
1434 for (i = 16; i > 0; i--) {
1436 retval = (retval << 1) | ((
inb(ee_addr) &
EEDO) ? 1 : 0);
1444 outb(ctrl_val, ee_addr);
1451 hardware_send_packet(
struct net_device *dev,
void *buf,
short length)
1465 else tx_available = lp->
xmt_ram;
1467 if (((((length + 3) >> 1) << 1) + 2*
XMT_HEADER) >= tx_available) {
1473 end = last + (((length + 3) >> 1) << 1) +
XMT_HEADER;
1480 end = last + (((length + 3) >> 1) << 1) +
XMT_HEADER;
1513 if (lp->
tx_end != last) {
1540 short boguscount = 20;
1542 unsigned rcv_event, rcv_status, rcv_next_frame, rcv_size;
1563 dev->
stats.rx_bytes+=rcv_size;
1565 skb = netdev_alloc_skb(dev, rcv_size + 5);
1568 dev->
stats.rx_dropped++;
1583 (rcv_size + 3) >> 2);
1589 dev->
stats.rx_packets++;
1594 dev->
stats.rx_errors++;
1596 if (rcv_status & 0x0100)
1597 dev->
stats.rx_over_errors++;
1599 else if (rcv_status & 0x0400)
1600 dev->
stats.rx_frame_errors++;
1602 else if (rcv_status & 0x0800)
1603 dev->
stats.rx_crc_errors++;
1605 printk(
KERN_DEBUG "%s: event = %#x, status = %#x, next = %#x, size = %#x\n",
1606 dev->
name, rcv_event, rcv_status, rcv_next_frame, rcv_size);
1609 if (rcv_status & 0x1000)
1610 dev->
stats.rx_length_errors++;
1615 if (--boguscount == 0)
1632 eepro_transmit_interrupt(
struct net_device *dev)
1636 short boguscount = 25;
1650 netif_wake_queue (dev);
1652 if (xmt_status &
TX_OK)
1653 dev->
stats.tx_packets++;
1655 dev->
stats.tx_errors++;
1656 if (xmt_status & 0x0400) {
1657 dev->
stats.tx_carrier_errors++;
1661 dev->
name, xmt_status);
1665 dev->
name, xmt_status);
1667 dev->
name, xmt_status);
1670 if (xmt_status & 0x000f) {
1671 dev->
stats.collisions += (xmt_status & 0x000f);
1674 if ((xmt_status & 0x0040) == 0x0) {
1675 dev->
stats.tx_heartbeat_errors++;
1680 static int eepro_ethtool_get_settings(
struct net_device *dev,
1705 ethtool_cmd_speed_set(cmd,
SPEED_10);
1725 static void eepro_ethtool_get_drvinfo(
struct net_device *dev,
1734 static const struct ethtool_ops eepro_ethtool_ops = {
1735 .get_settings = eepro_ethtool_get_settings,
1736 .get_drvinfo = eepro_ethtool_get_drvinfo,
1742 static struct net_device *dev_eepro[MAX_EEPRO];
1744 static int io[MAX_EEPRO] = {
1745 [0 ... MAX_EEPRO-1] = -1
1747 static int irq[MAX_EEPRO];
1748 static int mem[MAX_EEPRO] = {
1751 static int autodetect;
1766 MODULE_PARM_DESC(mem,
"EtherExpress Pro/10 Rx buffer size(es) in kB (3-29)");
1767 MODULE_PARM_DESC(autodetect,
"EtherExpress Pro/10 force board(s) detection (0-1)");
1773 if (io[0] == -1 && autodetect == 0) {
1775 printk(
KERN_WARNING "eepro_init_module: Please add \"autodetect=1\" to force probe\n");
1778 else if (autodetect) {
1780 for (i = 0; i < MAX_EEPRO; i++) {
1784 printk(
KERN_INFO "eepro_init_module: Auto-detecting boards (May God protect us...)\n");
1787 for (i = 0; i < MAX_EEPRO && io[
i] != -1; i++) {
1796 if (do_eepro_probe(dev) == 0) {
1797 dev_eepro[n_eepro++] =
dev;
1807 return n_eepro ? 0 : -
ENODEV;
1815 for (i=0; i<n_eepro; i++) {