72 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
74 #include <linux/module.h>
75 #include <linux/kernel.h>
77 #include <linux/slab.h>
78 #include <linux/string.h>
83 #include <linux/netdevice.h>
86 #include <linux/if_arp.h>
88 #include <linux/bitops.h>
89 #include <linux/mii.h>
96 #include <asm/uaccess.h>
107 #define INT_MODULE_PARM(n, v) static int n = v; module_param(n, int, 0)
122 #define TX_TIMEOUT ((800*HZ)/1000)
128 #define EL3_DATA 0x00
130 #define EL3_STATUS 0x0e
132 #define EL3WINDOW(win_num) outw(SelectWindow + (win_num), ioaddr + EL3_CMD)
196 #define MEDIA_TP 0x00C0
214 static char mii_preamble_required = 0;
218 static int tc574_config(
struct pcmcia_device *
link);
219 static void tc574_release(
struct pcmcia_device *
link);
221 static void mdio_sync(
unsigned int ioaddr,
int bits);
222 static int mdio_read(
unsigned int ioaddr,
int phy_id,
int location);
223 static void mdio_write(
unsigned int ioaddr,
int phy_id,
int location,
229 static void media_check(
unsigned long arg);
243 static void tc574_detach(
struct pcmcia_device *p_dev);
251 .ndo_open = el3_open,
252 .ndo_stop = el3_close,
253 .ndo_start_xmit = el3_start_xmit,
254 .ndo_tx_timeout = el3_tx_timeout,
255 .ndo_get_stats = el3_get_stats,
256 .ndo_do_ioctl = el3_ioctl,
257 .ndo_set_rx_mode = set_multicast_list,
263 static int tc574_probe(
struct pcmcia_device *
link)
268 dev_dbg(&link->dev,
"3c574_attach()\n");
274 lp = netdev_priv(dev);
279 link->resource[0]->end = 32;
280 link->resource[0]->flags |= IO_DATA_PATH_WIDTH_16;
281 link->config_flags |= CONF_ENABLE_IRQ;
282 link->config_index = 1;
287 return tc574_config(link);
290 static void tc574_detach(
struct pcmcia_device *link)
294 dev_dbg(&link->dev,
"3c574_detach()\n");
303 static const char *ram_split[] = {
"5:3",
"3:1",
"1:1",
"3:5"};
305 static int tc574_config(
struct pcmcia_device *link)
319 dev_dbg(&link->dev,
"3c574_config()\n");
323 for (i = j = 0; j < 0x400; j += 0x20) {
324 link->resource[0]->start = j ^ 0x300;
340 dev->
irq = link->irq;
341 dev->
base_addr = link->resource[0]->start;
349 len = pcmcia_get_tuple(link, 0x88, &buf);
350 if (buf && len >= 6) {
351 for (i = 0; i < 3; i++)
357 for (i = 0; i < 3; i++)
359 if (phys_addr[0] ==
htons(0x6060)) {
360 pr_notice(
"IO port conflict at 0x%03lx-0x%03lx\n",
365 if (link->prod_id[1])
366 cardname = link->prod_id[1];
368 cardname =
"3Com 3c574";
373 mcr =
inb(ioaddr + 2);
375 pr_info(
" ASIC rev %d,", mcr>>3);
391 tc574_wait_for_completion(dev,
TxReset);
392 tc574_wait_for_completion(dev,
RxReset);
397 for (phy = 1; phy <= 32; phy++) {
399 mdio_sync(ioaddr, 32);
400 mii_status = mdio_read(ioaddr, phy & 0x1f, 1);
401 if (mii_status != 0xffff) {
402 lp->
phys = phy & 0x1f;
403 dev_dbg(&link->dev,
" MII transceiver at "
404 "index %d, status %x.\n",
406 if ((mii_status & 0x0040) == 0)
407 mii_preamble_required = 1;
412 pr_notice(
" No MII transceivers found!\n");
415 i = mdio_read(ioaddr, lp->
phys, 16) | 0x40;
416 mdio_write(ioaddr, lp->
phys, 16, i);
432 netdev_info(dev,
"%s at io %#3lx, irq %d, hw_addr %pM\n",
434 netdev_info(dev,
" %dK FIFO split %s Rx:Tx, %sMII interface.\n",
447 static void tc574_release(
struct pcmcia_device *link)
452 static int tc574_suspend(
struct pcmcia_device *link)
462 static int tc574_resume(
struct pcmcia_device *link)
474 static void dump_status(
struct net_device *dev)
478 netdev_info(dev,
" irq status %04x, rx status %04x, tx status %02x, tx free %04x\n",
483 netdev_info(dev,
" diagnostics: fifo %04x net %04x ethernet %04x media %04x\n",
484 inw(ioaddr+0x04),
inw(ioaddr+0x06),
485 inw(ioaddr+0x08),
inw(ioaddr+0x0a));
492 static void tc574_wait_for_completion(
struct net_device *dev,
int cmd)
499 netdev_notice(dev,
"command 0x%04x did not complete!\n", cmd);
510 for (timer = 1620; timer >= 0; timer--) {
524 #define MDIO_SHIFT_CLK 0x01
525 #define MDIO_DIR_WRITE 0x04
526 #define MDIO_DATA_WRITE0 (0x00 | MDIO_DIR_WRITE)
527 #define MDIO_DATA_WRITE1 (0x02 | MDIO_DIR_WRITE)
528 #define MDIO_DATA_READ 0x02
529 #define MDIO_ENB_IN 0x00
533 static void mdio_sync(
unsigned int ioaddr,
int bits)
538 while (-- bits >= 0) {
544 static int mdio_read(
unsigned int ioaddr,
int phy_id,
int location)
547 int read_cmd = (0xf6 << 10) | (phy_id << 5) |
location;
551 if (mii_preamble_required)
552 mdio_sync(ioaddr, 32);
555 for (i = 14; i >= 0; i--) {
557 outw(dataval, mdio_addr);
561 for (i = 19; i > 0; i--) {
566 return (retval>>1) & 0xffff;
569 static void mdio_write(
unsigned int ioaddr,
int phy_id,
int location,
int value)
571 int write_cmd = 0x50020000 | (phy_id << 23) | (location << 18) |
value;
575 if (mii_preamble_required)
576 mdio_sync(ioaddr, 32);
579 for (i = 31; i >= 0; i--) {
581 outw(dataval, mdio_addr);
585 for (i = 1; i >= 0; i--) {
592 static void tc574_reset(
struct net_device *dev)
599 tc574_wait_for_completion(dev,
TotalReset|0x10);
608 for (i = 0; i < 6; i++)
625 tc574_wait_for_completion(dev,
TxReset);
626 tc574_wait_for_completion(dev,
RxReset);
635 for (i = 0; i < 10; i++)
650 mdio_sync(ioaddr, 32);
652 if (!auto_polarity) {
654 i = mdio_read(ioaddr, lp->
phys, 16) | 0x20;
655 mdio_write(ioaddr, lp->
phys, 16, i);
677 struct pcmcia_device *link = lp->
p_dev;
683 netif_start_queue(dev);
686 lp->
media.function = media_check;
691 dev_dbg(&link->dev,
"%s: opened, status %4.4x.\n",
697 static void el3_tx_timeout(
struct net_device *dev)
701 netdev_notice(dev,
"Transmit timed out!\n");
703 dev->
stats.tx_errors++;
706 tc574_wait_for_completion(dev,
TxReset);
708 netif_wake_queue(dev);
711 static void pop_tx_status(
struct net_device *dev)
717 for (i = 32; i > 0; i--) {
719 if (!(tx_status & 0x84))
722 if (tx_status & 0x30)
723 tc574_wait_for_completion(dev,
TxReset);
724 if (tx_status & 0x38) {
725 pr_debug(
"%s: transmit error: status 0x%02x\n",
726 dev->
name, tx_status);
728 dev->
stats.tx_aborted_errors++;
741 pr_debug(
"%s: el3_start_xmit(length = %ld) called, "
742 "status %4.4x.\n", dev->
name, (
long)skb->
len,
757 netif_stop_queue(dev);
776 int work_budget = max_interrupt_work;
779 if (!netif_device_present(dev))
783 pr_debug(
"%s: interrupt, status %4.4x.\n",
790 if (!netif_device_present(dev) ||
791 ((status & 0xe000) != 0x2000)) {
799 work_budget = el3_rx(dev, work_budget);
802 pr_debug(
" TX room bit was handled.\n");
805 netif_wake_queue(dev);
816 work_budget = el3_rx(dev, work_budget);
824 netdev_notice(dev,
"adapter failure, FIFO diagnostic register %04x\n",
826 if (fifo_diag & 0x0400) {
828 tc574_wait_for_completion(dev,
TxReset);
831 if (fifo_diag & 0x2000) {
833 tc574_wait_for_completion(dev,
RxReset);
841 if (--work_budget < 0) {
842 pr_debug(
"%s: Too much work in interrupt, "
843 "status %4.4x.\n", dev->
name, status);
852 pr_debug(
"%s: exiting interrupt, status %4.4x.\n",
864 static void media_check(
unsigned long arg)
872 if (!netif_device_present(dev))
879 netdev_info(dev,
"interrupt(s) dropped!\n");
882 el3_interrupt(dev->
irq, dev);
896 media = mdio_read(ioaddr, lp->
phys, 1);
897 partner = mdio_read(ioaddr, lp->
phys, 5);
902 netdev_info(dev,
"%s link beat\n",
907 netdev_info(dev,
"autonegotiation restarted\n");
908 }
else if (partner) {
911 netdev_info(dev,
"autonegotiation complete: "
912 "%dbaseT-%cD selected\n",
913 (partner & 0x0180) ? 100 : 10,
914 (partner & 0x0140) ?
'F' :
'H');
916 netdev_info(dev,
"link partner did not autonegotiate\n");
920 outb((partner & 0x0140 ? 0x20 : 0) |
926 netdev_info(dev,
"remote fault detected\n");
928 netdev_info(dev,
"jabber detected\n");
942 if (netif_device_present(dev)) {
955 static void update_stats(
struct net_device *dev)
968 dev->
stats.tx_carrier_errors +=
inb(ioaddr + 0);
969 dev->
stats.tx_heartbeat_errors +=
inb(ioaddr + 1);
971 dev->
stats.collisions +=
inb(ioaddr + 3);
972 dev->
stats.tx_window_errors +=
inb(ioaddr + 4);
973 dev->
stats.rx_fifo_errors +=
inb(ioaddr + 5);
974 dev->
stats.tx_packets +=
inb(ioaddr + 6);
975 up =
inb(ioaddr + 9);
976 dev->
stats.tx_packets += (up&0x30) << 4;
979 rx =
inw(ioaddr + 10);
980 tx =
inw(ioaddr + 12);
984 up =
inb(ioaddr + 13);
989 static int el3_rx(
struct net_device *dev,
int worklimit)
994 pr_debug(
"%s: in rx_packet(), status %4.4x, rx_status %4.4x.\n",
996 while (!((rx_status =
inw(ioaddr +
RxStatus)) & 0x8000) &&
999 if (rx_status & 0x4000) {
1000 short error = rx_status & 0x3800;
1001 dev->
stats.rx_errors++;
1003 case 0x0000: dev->
stats.rx_over_errors++;
break;
1004 case 0x0800: dev->
stats.rx_length_errors++;
break;
1005 case 0x1000: dev->
stats.rx_frame_errors++;
break;
1006 case 0x1800: dev->
stats.rx_length_errors++;
break;
1007 case 0x2000: dev->
stats.rx_frame_errors++;
break;
1008 case 0x2800: dev->
stats.rx_crc_errors++;
break;
1011 short pkt_len = rx_status & 0x7ff;
1014 skb = netdev_alloc_skb(dev, pkt_len + 5);
1016 pr_debug(
" Receiving packet size %d status %4.4x.\n",
1017 pkt_len, rx_status);
1019 skb_reserve(skb, 2);
1024 dev->
stats.rx_packets++;
1027 pr_debug(
"%s: couldn't allocate a sk_buff of"
1028 " size %d.\n", dev->
name, pkt_len);
1029 dev->
stats.rx_dropped++;
1032 tc574_wait_for_completion(dev,
RxDiscard);
1044 int phy = lp->
phys & 0x1f;
1046 pr_debug(
"%s: In ioct(%-.6s, %#4.4x) %4.4x %4.4x %4.4x %4.4x.\n",
1056 unsigned long flags;
1070 unsigned long flags;
1075 mdio_write(ioaddr, data->
phy_id & 0x1f,
1094 static void set_rx_mode(
struct net_device *dev)
1107 static void set_multicast_list(
struct net_device *dev)
1110 unsigned long flags;
1121 struct pcmcia_device *link = lp->
p_dev;
1123 dev_dbg(&link->dev,
"%s: shutting down ethercard.\n", dev->
name);
1126 unsigned long flags;
1146 netif_stop_queue(dev);
1153 PCMCIA_DEVICE_MANF_CARD(0x0101, 0x0574),
1154 PCMCIA_MFC_DEVICE_CIS_MANF_CARD(0, 0x0101, 0x0556,
"cis/3CCFEM556.cis"),
1159 static struct pcmcia_driver tc574_driver = {
1162 .probe = tc574_probe,
1163 .remove = tc574_detach,
1164 .id_table = tc574_ids,
1165 .suspend = tc574_suspend,
1166 .resume = tc574_resume,
1169 static int __init init_tc574(
void)
1174 static void __exit exit_tc574(
void)