225 #include <linux/module.h>
226 #include <linux/kernel.h>
227 #include <linux/sched.h>
228 #include <linux/string.h>
229 #include <linux/errno.h>
231 #include <linux/slab.h>
236 #include <linux/netdevice.h>
239 #include <linux/time.h>
240 #include <linux/types.h>
242 #include <linux/ctype.h>
245 #include <linux/bitops.h>
247 #include <asm/uaccess.h>
260 static int depca_debug = DEPCA_DEBUG;
262 static int depca_debug = 1;
265 #define DEPCA_NDA 0xffe0
267 #define TX_TIMEOUT (1*HZ)
272 #define PROBE_LENGTH 32
273 #define ETH_PROM_SIG 0xAA5500FFUL
282 #define NUM_RX_DESC 8
283 #define NUM_TX_DESC 8
284 #define RX_BUFF_SZ 1536
285 #define TX_BUFF_SZ 1536
290 #define DEPCA_EISA_IO_PORTS 0x0c00
295 #define DEPCA_RAM_BASE_ADDRESSES {0xc0000,0xd0000,0xe0000,0x00000}
296 #define DEPCA_TOTAL_SIZE 0x10
301 } depca_io_ports[] = {
310 #define DEPCA_SIGNATURE {"DEPCA",\
312 "DE200","DE201","DE202",\
323 static char depca_string[] =
"depca";
329 {
"DEC4220",
de422 },
339 .name = depca_string,
340 .probe = depca_eisa_probe,
350 return depca_device_remove(&pdev->
dev);
354 .probe = depca_isa_probe,
357 .name = depca_string,
364 #define DEPCA_STRLEN 16
372 #define DEPCA_ALIGN4 ((u_long)4 - 1)
373 #define DEPCA_ALIGN8 ((u_long)8 - 1)
374 #define DEPCA_ALIGN DEPCA_ALIGN8
391 #define LA_MASK 0x0000ffff
405 #define DEPCA_PKT_STAT_SZ 16
406 #define DEPCA_PKT_BIN_SZ 128
456 #define TX_BUFFS_AVAIL ((lp->tx_old<=lp->tx_new)?\
457 lp->tx_old+lp->txRingMask-lp->tx_new:\
458 lp->tx_old -lp->tx_new-1)
482 static int DevicePresent(
u_long ioaddr);
495 static char *adapter_name;
512 outw(CSR0, DEPCA_ADDR);\
513 outw(STOP, DEPCA_DATA)
516 .ndo_open = depca_open,
517 .ndo_start_xmit = depca_start_xmit,
518 .ndo_stop = depca_close,
519 .ndo_set_rx_mode = set_multicast_list,
521 .ndo_tx_timeout = depca_tx_timeout,
561 lp = netdev_priv(dev);
567 printk(
"%s: %s at 0x%04lx",
568 dev_name(device), depca_signature[lp->
adapter], ioaddr);
586 status = get_hw_addr(dev);
589 printk(
" which has an Ethernet PROM CRC error.\n");
607 printk(
",\n requests %dkB RAM: only %dkB is available!\n", (mem_len >> 10), netRAM);
611 printk(
",\n has %dkB RAM at 0x%.5lx", netRAM, mem_start);
621 depca_signature[lp->
adapter], dev_name(device));
672 depca_init_ring(dev);
678 nicsr = ((nicsr & ~
IM) |
IEN);
684 unsigned char irqnum;
685 unsigned long irq_mask,
delay;
694 depca_irq = de1xx_irq;
701 depca_irq = de2xx_irq;
704 depca_irq = de422_irq;
722 printk(
" and failed to detect IRQ line.\n");
725 for (dev->
irq = 0, i = 0; (depca_irq[i]) && (!dev->
irq); i++)
726 if (irqnum == depca_irq[i]) {
732 printk(
" but incorrect IRQ line detected.\n");
737 printk(
" and assigned IRQ%d.\n", dev->
irq);
740 if (depca_debug > 1) {
782 depca_init_ring(dev);
788 printk(
"depca_open(): Requested IRQ%d is busy\n", dev->
irq);
793 nicsr = ((nicsr & ~
IM & ~
LED) |
IEN);
797 netif_start_queue(dev);
799 status = InitRestartDepca(dev);
801 if (depca_debug > 1) {
810 static void depca_init_ring(
struct net_device *dev)
817 netif_stop_queue(dev);
840 SetMulticastFilter(dev);
850 static void depca_tx_timeout(
struct net_device *dev)
857 depca_init_ring(dev);
860 netif_wake_queue(dev);
861 InitRestartDepca(dev);
882 netif_stop_queue(dev);
885 status = load_packet(dev, skb);
895 netif_start_queue(dev);
914 printk(
"depca_interrupt(): irq %d for unknown device.\n", irq);
918 lp = netdev_priv(dev);
921 spin_lock(&lp->
lock);
942 netif_wake_queue(dev);
946 nicsr = (nicsr & ~
IM & ~
LED);
949 spin_unlock(&lp->
lock);
962 if (status &
R_STP) {
965 if (status &
R_ENP) {
966 if (status &
R_ERR) {
967 dev->
stats.rx_errors++;
969 dev->
stats.rx_frame_errors++;
971 dev->
stats.rx_over_errors++;
973 dev->
stats.rx_crc_errors++;
975 dev->
stats.rx_fifo_errors++;
980 skb = netdev_alloc_skb(dev, pkt_len + 2);
1003 dev->
stats.rx_packets++;
1011 if (is_multicast_ether_addr(buf)) {
1012 if (is_broadcast_ether_addr(buf)) {
1017 }
else if (ether_addr_equal(buf,
1027 printk(
"%s: Memory squeeze, deferring packet.\n", dev->
name);
1028 dev->
stats.rx_dropped++;
1064 }
else if (status &
T_ERR) {
1066 dev->
stats.tx_errors++;
1068 dev->
stats.tx_aborted_errors++;
1070 dev->
stats.tx_carrier_errors++;
1072 dev->
stats.tx_window_errors++;
1074 dev->
stats.tx_fifo_errors++;
1081 dev->
stats.collisions++;
1083 dev->
stats.tx_packets++;
1093 static int depca_close(
struct net_device *dev)
1099 netif_stop_queue(dev);
1103 if (depca_debug > 1) {
1144 static int InitRestartDepca(
struct net_device *dev)
1162 if (depca_debug > 2) {
1176 static void set_multicast_list(
struct net_device *dev)
1181 netif_stop_queue(dev);
1185 depca_init_ring(dev);
1190 SetMulticastFilter(dev);
1195 InitRestartDepca(dev);
1196 netif_start_queue(dev);
1205 static void SetMulticastFilter(
struct net_device *dev)
1214 for (i = 0; i < (HASH_TABLE_LEN >> 3); i++) {
1218 for (i = 0; i < (HASH_TABLE_LEN >> 3); i++) {
1224 hashcode = (crc & 1);
1225 for (j = 0; j < 5; j++) {
1226 hashcode = (hashcode << 1) | ((crc >>= 1) & 1);
1229 byte = hashcode >> 3;
1230 bit = 1 << (hashcode & 0x07);
1245 if (DevicePresent(ioaddr)) {
1250 if (!(*devp = alloc_etherdev (
sizeof (
struct depca_private)))) {
1267 static void __init depca_platform_probe (
void)
1272 for (i = 0; depca_io_ports[
i].iobase; i++) {
1273 depca_io_ports[
i].device =
NULL;
1284 pldev->
dev.platform_data = (
void *) depca_io_ports[i].iobase;
1285 depca_io_ports[
i].device = pldev;
1288 depca_io_ports[
i].device =
NULL;
1289 pldev->
dev.platform_data =
NULL;
1294 if (!pldev->
dev.driver) {
1300 depca_io_ports[
i].device =
NULL;
1301 pldev->
dev.platform_data =
NULL;
1313 for (i = 0; mem_base[
i]; i++) {
1314 *mem_start =
mem ?
mem : mem_base[
i];
1315 adapter = DepcaSignature (adapter_name, *mem_start);
1327 u_long ioaddr, mem_start = 0;
1331 ioaddr = (
u_long) device->
dev.platform_data;
1333 if ((status = depca_common_init (ioaddr, &dev)))
1336 adapter = depca_shmem_probe (&mem_start);
1346 lp = netdev_priv(dev);
1351 if ((status = depca_hw_init(dev, &device->
dev)))
1368 static int __init depca_eisa_probe (
struct device *device)
1380 if ((status = depca_common_init (ioaddr, &dev)))
1389 adapter = depca_shmem_probe (&mem_start);
1397 lp = netdev_priv(dev);
1402 if ((status = depca_hw_init(dev, device)))
1415 static int __devexit depca_device_remove (
struct device *device)
1422 lp = netdev_priv(dev);
1444 u_long prom_addr = base_addr + 0xc000;
1445 u_long mem_addr = base_addr + 0x8000;
1462 for (i = 0; i < 16; i++) {
1463 tmpstr[
i] =
readb(ptr + i);
1470 for (i = 0; *depca_signature[
i] !=
'\0'; i++) {
1471 for (j = 0, k = 0; j < 16 && k <
strlen(depca_signature[i]); j++) {
1472 if (depca_signature[i][k] == tmpstr[j]) {
1478 if (k ==
strlen(depca_signature[i]))
1483 if (name && *name && (i ==
unknown)) {
1484 for (i = 0; *depca_signature[
i] !=
'\0'; i++) {
1485 if (
strcmp(name, depca_signature[i]) == 0)
1515 char Sig[
sizeof(
u32) << 1];
1518 short sigLength = 0;
1521 int i,
j, status = 0;
1534 sigLength =
sizeof(
u32) << 1;
1536 for (i = 0, j = 0; j < sigLength && i <
PROBE_LENGTH + sigLength - 1; i++) {
1538 if (dev.Sig[j] == data) {
1541 if (data == dev.Sig[0]) {
1549 if (j != sigLength) {
1565 int i,
k,
tmp, status = 0;
1570 for (i = 0, k = 0, j = 0; j < 3; j++) {
1636 for (i = end; i !=
entry; --
i) {
1652 static void depca_dbg_open(
struct net_device *dev)
1659 if (depca_debug > 1) {
1663 printk(
"%s: depca open with irq %d\n", dev->
name, dev->
irq);
1664 printk(
"Descriptor head addresses (CPU):\n");
1666 printk(
"Descriptor addresses (CPU):\nRX: ");
1680 printk(
"\nDescriptor buffers (Device):\nRX: ");
1697 printk(
" multicast hash table: ");
1698 for (i = 0; i < (HASH_TABLE_LEN >> 3) - 1; i++) {
1732 unsigned long flags;
1753 netif_stop_queue(dev);
1758 depca_init_ring(dev);
1760 InitRestartDepca(dev);
1761 netif_start_queue(dev);
1767 netif_stop_queue(dev);
1772 depca_init_ring(dev);
1776 InitRestartDepca(dev);
1777 netif_start_queue(dev);
1783 netif_stop_queue(dev);
1788 depca_init_ring(dev);
1792 InitRestartDepca(dev);
1793 netif_start_queue(dev);
1815 set_multicast_list(dev);
1821 set_multicast_list(dev);
1827 set_multicast_list(dev);
1837 spin_unlock_irqrestore(&lp->
lock, flags);
1848 spin_unlock_irqrestore(&lp->
lock, flags);
1869 static int __init depca_module_init (
void)
1882 depca_platform_probe();
1892 static void __exit depca_module_exit (
void)
1900 for (i = 0; depca_io_ports[
i].iobase; i++) {
1901 if (depca_io_ports[i].device) {
1902 depca_io_ports[
i].device->dev.platform_data =
NULL;
1904 depca_io_ports[
i].device =
NULL;