146 #include <linux/module.h>
147 #include <linux/kernel.h>
148 #include <linux/sched.h>
149 #include <linux/string.h>
150 #include <linux/errno.h>
152 #include <linux/slab.h>
157 #include <linux/netdevice.h>
160 #include <linux/ethtool.h>
161 #include <linux/time.h>
162 #include <linux/types.h>
164 #include <linux/ctype.h>
165 #include <linux/bitops.h>
169 #include <asm/uaccess.h>
173 #define DRV_NAME "ewrk3"
174 #define DRV_VERSION "0.48"
180 static int ewrk3_debug = EWRK3_DEBUG;
182 static int ewrk3_debug = 1;
185 #define EWRK3_NDA 0xffe0
187 #define PROBE_LENGTH 32
188 #define ETH_PROM_SIG 0xAA5500FFUL
190 #ifndef EWRK3_SIGNATURE
191 #define EWRK3_SIGNATURE {"DE203","DE204","DE205",""}
192 #define EWRK3_STRLEN 8
195 #ifndef EWRK3_RAM_BASE_ADDRESSES
196 #define EWRK3_RAM_BASE_ADDRESSES {0xc0000,0xd0000,0x00000}
202 #define EWRK3_IO_BASE 0x100
203 #define EWRK3_IOP_INC 0x20
204 #define EWRK3_TOTAL_SIZE 0x20
206 #ifndef MAX_NUM_EWRK3S
207 #define MAX_NUM_EWRK3S 21
210 #ifndef EWRK3_EISA_IO_PORTS
211 #define EWRK3_EISA_IO_PORTS 0x0c00
214 #ifndef MAX_EISA_SLOTS
215 #define MAX_EISA_SLOTS 16
216 #define EISA_SLOT_INC 0x1000
219 #define QUEUE_PKT_TIMEOUT (1*HZ)
225 #define SHMEM_2K 0x800
226 #define SHMEM_32K 0x8000
227 #define SHMEM_64K 0x10000
232 #define ENABLE_IRQs { \
233 icr |= lp->irq_mask;\
234 outb(icr, EWRK3_ICR); \
237 #define DISABLE_IRQs { \
238 icr = inb(EWRK3_ICR);\
239 icr &= ~lp->irq_mask;\
240 outb(icr, EWRK3_ICR); \
246 #define START_EWRK3 { \
247 csr = inb(EWRK3_CSR);\
248 csr &= ~(CSR_TXD|CSR_RXD);\
249 outb(csr, EWRK3_CSR); \
252 #define STOP_EWRK3 { \
253 csr = (CSR_TXD|CSR_RXD);\
254 outb(csr, EWRK3_CSR); \
260 #define EWRK3_PKT_STAT_SZ 16
261 #define EWRK3_PKT_BIN_SZ 128
293 #define FORCE_2K_MODE { \
294 shmem_length = SHMEM_2K;\
295 outb(((mem_start - 0x80000) >> 11), EWRK3_MBR);\
319 static void EthwrkSignature(
char *
name,
char *eeprom_image);
322 static int EISA_signature(
char *
name,
s32 eisa_id);
335 static int num_ewrks3s;
340 #define INIT_EWRK3 {\
341 outb(EEPROM_INIT, EWRK3_IOPR);\
378 err = isa_probe(dev, iobase);
380 err = eisa_probe(dev, iobase);
393 .ndo_open = ewrk3_open,
394 .ndo_start_xmit = ewrk3_queue_pkt,
395 .ndo_stop = ewrk3_close,
396 .ndo_set_rx_mode = set_multicast_list,
398 .ndo_tx_timeout = ewrk3_timeout,
431 for (chksum = 0, i = 0; i <
EEPROM_MAX; i += 2) {
437 tmp.val = (
short) Read_EEPROM(iobase, (i >> 1));
438 eeprom_image[
i] =
tmp.c[0];
439 eeprom_image[i + 1] =
tmp.c[1];
440 chksum += eeprom_image[
i] + eeprom_image[i + 1];
444 printk(
"%s: Device has a bad on-board EEPROM.\n", dev->
name);
448 EthwrkSignature(
name, eeprom_image);
454 if (iobase > 0x400) {
466 printk(
"%s: %s at %#4lx (EISA slot %ld)",
467 dev->
name,
name, iobase, ((iobase >> 12) & 0x0f));
474 DevicePresent(iobase);
475 status = get_hw_addr(dev, eeprom_image, lemac);
479 printk(
" which has an EEPROM CRC error.\n");
514 if (mem_start != 0) {
515 if ((mem_start >= 0x0a) && (mem_start <= 0x0f)) {
518 }
else if ((mem_start >= 0x14) && (mem_start <= 0x1f)) {
521 }
else if ((mem_start >= 0x40) && (mem_start <= 0xff)) {
522 mem_start = mem_start *
SHMEM_2K + 0x80000;
535 printk(
" is hard strapped.\n");
536 }
else if (mem_start) {
537 printk(
" has a %dk RAM window", (
int) (shmem_length >> 10));
538 printk(
" at 0x%.5lx", mem_start);
540 printk(
" is in I/O only mode");
543 lp = netdev_priv(dev);
562 if (!hard_strapped) {
577 unsigned long irq_mask;
589 irqnum = irq[((icr &
IRQ_SEL) >> 4)];
593 if ((dev->
irq) && (irqnum == dev->
irq)) {
597 printk(
" and failed to detect IRQ line.\n");
598 }
else if ((irqnum == 1) && (lemac ==
LeMAC2)) {
599 printk(
" and an illegal IRQ line detected.\n");
601 printk(
", but incorrect IRQ line detected.\n");
611 printk(
" and requires IRQ%d.\n", dev->
irq);
615 if (ewrk3_debug > 1) {
645 if (
request_irq(dev->
irq, (
void *) ewrk3_interrupt, 0,
"ewrk3", dev)) {
646 printk(
"ewrk3_open(): Requested IRQ%d is busy\n", dev->
irq);
655 if (ewrk3_debug > 1) {
659 printk(
" no shared memory, I/O only mode\n");
671 netif_start_queue(dev);
681 printk(
KERN_ERR " Run the 'ewrk3setup' utility or remove the hard straps.\n");
691 static void ewrk3_init(
struct net_device *dev)
701 set_multicast_list(dev);
721 for (page = 1; page < lp->
mPage; page++) {
732 static void ewrk3_timeout(
struct net_device *dev)
761 netif_wake_queue(dev);
793 printk (
"ewrk3_queue_pkt(): Invalid free memory page (%d).\n",
808 buf = (((
short) page << 11) & 0x7800) + lp->
shmem;
811 buf = (((
short) page << 11) & 0xf800) + lp->
shmem;
830 for (i = 0; i < skb->
len; i++) {
862 spin_unlock_irq (&lp->
hw_lock);
869 netif_stop_queue (dev);
875 spin_unlock_irq (&lp->
hw_lock);
889 lp = netdev_priv(dev);
921 netif_wake_queue(dev);
954 buf = (((
short) page << 11) & 0x7800) + lp->
shmem;
957 buf = (((
short) page << 11) & 0xf800) + lp->
shmem;
961 printk(
"%s: Oops - your private data area is hosed!\n", dev->
name);
973 rx_status =
readb(buf);
975 pkt_len =
readw(buf);
979 if (!(rx_status &
R_ROK)) {
980 dev->
stats.rx_errors++;
981 if (rx_status &
R_DBE)
982 dev->
stats.rx_frame_errors++;
983 if (rx_status &
R_CRC)
984 dev->
stats.rx_crc_errors++;
985 if (rx_status &
R_PLL)
986 dev->
stats.rx_fifo_errors++;
989 skb = netdev_alloc_skb(dev,
999 for (i = 0; i <
pkt_len; i++) {
1013 if (is_multicast_ether_addr(p)) {
1014 if (is_broadcast_ether_addr(p)) {
1019 }
else if (ether_addr_equal(p,
1037 dev->
stats.rx_packets++;
1040 printk(
"%s: Insufficient memory; nuking packet.\n", dev->
name);
1041 dev->
stats.rx_dropped++;
1051 printk(
"ewrk3_rx(): Illegal page number, page %d\n", page);
1069 if (tx_status &
T_VSTS) {
1070 if (tx_status &
T_TXE) {
1071 dev->
stats.tx_errors++;
1072 if (tx_status &
T_NCL)
1073 dev->
stats.tx_carrier_errors++;
1074 if (tx_status &
T_LCL)
1075 dev->
stats.tx_window_errors++;
1076 if (tx_status &
T_CTU) {
1080 lp->
pktStats.excessive_underruns++;
1082 }
else if (tx_status &
T_COLL) {
1083 if ((tx_status & T_COLL) ^
T_XCOLL) {
1084 dev->
stats.collisions++;
1086 lp->
pktStats.excessive_collisions++;
1090 dev->
stats.tx_packets++;
1098 static int ewrk3_close(
struct net_device *dev)
1104 netif_stop_queue(dev);
1106 if (ewrk3_debug > 1) {
1107 printk(
"%s: Shutting down ethercard, status was %2.2x.\n",
1136 static void set_multicast_list(
struct net_device *dev)
1155 SetMulticastFilter(dev);
1169 static void SetMulticastFilter(
struct net_device *dev)
1190 for (i = 0; i < (HASH_TABLE_LEN >> 3); i++) {
1202 for (i = 0; i < (HASH_TABLE_LEN >> 4) - 1; i++) {
1207 for (; i < (HASH_TABLE_LEN >> 3); i++) {
1218 hashcode = crc & ((1 << 9) - 1);
1220 byte = hashcode >> 3;
1221 bit = 1 << (hashcode & 0x07);
1237 spin_unlock_irq(&lp->
hw_lock);
1245 int i = num_ewrks3s, maxSlots;
1250 if (ioaddr >= 0x400)
1261 for (; (i < maxSlots) && (dev !=
NULL);
1265 if (DevicePresent(iobase) == 0) {
1267 ret = ewrk3_hw_init(dev, iobase);
1290 if (ioaddr < 0x1000)
1300 DevicePresent(iobase) == 0) {
1302 ret = ewrk3_hw_init(dev, iobase);
1325 for (i = 0; i < 5000; i++)
1339 for (i = 0; i < 5000; i++)
1344 for (i = 0; i < 75000; i++)
1347 for (i = 0; i < 5000; i++)
1356 static void __init EthwrkSignature(
char *
name,
char *eeprom_image)
1361 for (i=0; *signatures[
i] !=
'\0'; i++)
1365 if (*signatures[i] !=
'\0') {
1391 char Sig[
sizeof(
u32) << 1];
1396 int i,
j, status = 0;
1400 sigLength =
sizeof(
u32) << 1;
1402 for (i = 0, j = 0; j < sigLength && i <
PROBE_LENGTH + sigLength - 1; i++) {
1404 if (dev.Sig[j] == data) {
1407 if (data == dev.Sig[0]) {
1415 if (j != sigLength) {
1429 if (chipType ==
LeMAC2) {
1430 for (crc = 0x6a, j = 0; j <
ETH_ALEN; j++) {
1433 for (k = 0; k < 8; k++, sd >>= 1) {
1434 lfsr = ((((crc & 0x02) >> 1) ^ (crc & 0x01)) ^ (sd & 0x01)) << 7;
1435 crc = (crc >> 1) + lfsr;
1441 for (i = 0, k = 0; i <
ETH_ALEN;) {
1472 static int __init EISA_signature(
char *name,
s32 eisa_id)
1484 for (i = 0; i < 4; i++) {
1485 Eisa.Id[
i] =
inb(eisa_id + i);
1488 ManCode[0] = (((Eisa.Id[0] >> 2) & 0x1f) + 0x40);
1489 ManCode[1] = (((Eisa.Id[1] & 0xe0) >> 5) + ((Eisa.Id[0] & 0x03) << 3) + 0x40);
1490 ManCode[2] = (((Eisa.Id[2] >> 4) & 0x0f) + 0x30);
1491 ManCode[3] = ((Eisa.Id[2] & 0x0f) + 0x30);
1492 ManCode[4] = (((Eisa.Id[3] >> 4) & 0x0f) + 0x30);
1495 for (i = 0; (*signatures[
i] !=
'\0') && (*name ==
'\0'); i++) {
1496 if (
strstr(ManCode, signatures[i]) !=
NULL) {
1546 ethtool_cmd_speed_set(ecmd,
SPEED_10);
1555 unsigned long flags;
1591 spin_unlock_irqrestore(&lp->
hw_lock, flags);
1605 static int ewrk3_set_phys_id(
struct net_device *dev,
1618 spin_unlock_irq(&lp->
hw_lock);
1636 spin_unlock_irq(&lp->
hw_lock);
1641 static const struct ethtool_ops ethtool_ops_203 = {
1642 .get_drvinfo = ewrk3_get_drvinfo,
1643 .get_settings = ewrk3_get_settings,
1644 .set_settings = ewrk3_set_settings,
1645 .set_phys_id = ewrk3_set_phys_id,
1650 .get_settings = ewrk3_get_settings,
1651 .set_settings = ewrk3_set_settings,
1652 .get_link = ewrk3_get_link,
1653 .set_phys_id = ewrk3_set_phys_id,
1665 int i, j, status = 0;
1667 unsigned long flags;
1673 union ewrk3_addr *
tmp;
1699 spin_unlock_irqrestore(&lp->
hw_lock, flags);
1714 spin_unlock_irqrestore(&lp->
hw_lock, flags);
1727 spin_unlock_irqrestore(&lp->
hw_lock, flags);
1739 spin_unlock_irqrestore(&lp->
hw_lock, flags);
1750 for (i = 0; i < (HASH_TABLE_LEN >> 3); i++) {
1757 spin_unlock_irqrestore(&lp->
hw_lock, flags);
1774 set_multicast_list(dev);
1782 set_multicast_list(dev);
1795 spin_unlock_irqrestore(&lp->
hw_lock, flags);
1811 spin_unlock_irqrestore(&lp->
hw_lock, flags);
1823 spin_unlock_irqrestore(&lp->
hw_lock,flags);
1849 for (i = 0; i < (EEPROM_MAX >> 1); i++) {
1850 tmp->val[
i] = (
short) Read_EEPROM(iobase, i);
1871 for (i = 0; i < (EEPROM_MAX >> 1); i++) {
1872 Write_EEPROM(tmp->val[i], iobase, i);
1919 static __exit void ewrk3_exit_module(
void)
1923 for( i=0; i<ndevs; i++ ) {
1926 ewrk3_devs[
i] =
NULL;
1934 static __init int ewrk3_init_module(
void)
1938 while( io[i] && irq[i] ) {
1945 if (ewrk3_probe1(dev, io[i], irq[i]) != 0) {
1950 ewrk3_devs[ndevs++] =
dev;
1954 return ndevs ? 0 : -
EIO;