22 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
24 #define DRV_NAME "3c589_cs"
25 #define DRV_VERSION "1.162-ac"
27 #include <linux/module.h>
29 #include <linux/kernel.h>
30 #include <linux/ptrace.h>
31 #include <linux/slab.h>
32 #include <linux/string.h>
37 #include <linux/ethtool.h>
38 #include <linux/netdevice.h>
41 #include <linux/if_arp.h>
43 #include <linux/bitops.h>
51 #include <asm/uaccess.h>
59 #define EL3_TIMER 0x0a
61 #define EL3_STATUS 0x0e
63 #define EEPROM_READ 0x0080
64 #define EEPROM_BUSY 0x8000
66 #define EL3WINDOW(win_num) outw(SelectWindow + (win_num), ioaddr + EL3_CMD)
117 #define RX_STATUS 0x08
118 #define TX_STATUS 0x0B
122 #define WN4_MEDIA 0x0A
123 #define MEDIA_TP 0x00C0
124 #define MEDIA_LED 0x0001
127 #define TX_TIMEOUT ((400*HZ)/1000)
130 struct pcmcia_device *
p_dev;
139 static const char *if_names[] = {
"auto",
"10baseT",
"10base2",
"AUI" };
149 #define INT_MODULE_PARM(n, v) static int n = v; module_param(n, int, 0)
157 static int tc589_config(
struct pcmcia_device *
link);
158 static void tc589_release(
struct pcmcia_device *
link);
162 static void media_check(
unsigned long arg);
175 static const struct ethtool_ops netdev_ethtool_ops;
177 static void tc589_detach(
struct pcmcia_device *p_dev);
180 .ndo_open = el3_open,
181 .ndo_stop = el3_close,
182 .ndo_start_xmit = el3_start_xmit,
183 .ndo_tx_timeout = el3_tx_timeout,
184 .ndo_set_config = el3_config,
185 .ndo_get_stats = el3_get_stats,
186 .ndo_set_rx_mode = set_multicast_list,
192 static int tc589_probe(
struct pcmcia_device *
link)
197 dev_dbg(&link->dev,
"3c589_attach()\n");
203 lp = netdev_priv(dev);
208 link->resource[0]->end = 16;
209 link->resource[0]->flags |= IO_DATA_PATH_WIDTH_16;
211 link->config_flags |= CONF_ENABLE_IRQ;
212 link->config_index = 1;
219 return tc589_config(link);
222 static void tc589_detach(
struct pcmcia_device *link)
226 dev_dbg(&link->dev,
"3c589_detach\n");
235 static int tc589_config(
struct pcmcia_device *link)
241 static const char *
const ram_split[] = {
"5:3",
"3:1",
"1:1",
"3:5"};
245 dev_dbg(&link->dev,
"3c589_config\n");
250 dev_info(&link->dev,
"hmmm, is this really a 3Com card??\n");
256 for (i = j = 0; j < 0x400; j += 0x10) {
257 if (multi && (j & 0x80))
continue;
258 link->resource[0]->start = j ^ 0x300;
274 dev->
irq = link->irq;
275 dev->
base_addr = link->resource[0]->start;
281 len = pcmcia_get_tuple(link, 0x88, &buf);
282 if (buf && len >= 6) {
283 for (i = 0; i < 3; i++)
288 for (i = 0; i < 3; i++)
290 if (phys_addr[0] ==
htons(0x6060)) {
291 dev_err(&link->dev,
"IO port conflict at 0x%03lx-0x%03lx\n",
299 outw(0x3f00, ioaddr + 8);
306 dev_err(&link->dev,
"invalid if_port requested\n");
311 dev_err(&link->dev,
"register_netdev() failed\n");
315 netdev_info(dev,
"3Com 3c%s, io %#3lx, irq %d, hw_addr %pM\n",
318 netdev_info(dev,
" %dK FIFO split %s Rx:Tx, %s xcvr\n",
319 (
fifo & 7) ? 32 : 8, ram_split[(
fifo >> 16) & 3],
328 static void tc589_release(
struct pcmcia_device *link)
333 static int tc589_suspend(
struct pcmcia_device *link)
343 static int tc589_resume(
struct pcmcia_device *link)
360 static void tc589_wait_for_completion(
struct net_device *dev,
int cmd)
367 netdev_warn(dev,
"command 0x%04x did not complete!\n", cmd);
379 for (i = 1620; i >= 0; i--)
382 return inw(ioaddr + 12);
396 case 0:
case 1:
outw(0, ioaddr + 6);
break;
397 case 2:
outw(3<<14, ioaddr + 6);
break;
398 case 3:
outw(1<<14, ioaddr + 6);
break;
412 static void dump_status(
struct net_device *dev)
416 netdev_info(dev,
" irq status %04x, rx status %04x, tx status %02x tx free %04x\n",
420 netdev_info(dev,
" diagnostics: fifo %04x net %04x ethernet %04x media %04x\n",
421 inw(ioaddr+0x04),
inw(ioaddr+0x06),
inw(ioaddr+0x08),
427 static void tc589_reset(
struct net_device *dev)
433 outw(0x0001, ioaddr + 4);
434 outw(0x3f00, ioaddr + 8);
438 for (i = 0; i < 6; i++)
441 tc589_set_xcvr(dev, dev->
if_port);
446 for (i = 0; i < 9; i++)
467 static void netdev_get_drvinfo(
struct net_device *dev,
476 static const struct ethtool_ops netdev_ethtool_ops = {
477 .get_drvinfo = netdev_get_drvinfo,
483 if (map->
port <= 3) {
485 netdev_info(dev,
"switched to %s port\n", if_names[dev->
if_port]);
486 tc589_set_xcvr(dev, dev->
if_port);
496 struct pcmcia_device *link = lp->
p_dev;
502 netif_start_queue(dev);
506 lp->
media.function = media_check;
511 dev_dbg(&link->dev,
"%s: opened, status %4.4x.\n",
517 static void el3_tx_timeout(
struct net_device *dev)
521 netdev_warn(dev,
"Transmit timed out!\n");
523 dev->
stats.tx_errors++;
526 tc589_wait_for_completion(dev,
TxReset);
528 netif_wake_queue(dev);
531 static void pop_tx_status(
struct net_device *dev)
537 for (i = 32; i > 0; i--) {
539 if (!(tx_status & 0x84))
break;
541 if (tx_status & 0x30)
542 tc589_wait_for_completion(dev,
TxReset);
543 if (tx_status & 0x38) {
544 netdev_dbg(dev,
"transmit error: status 0x%02x\n", tx_status);
546 dev->
stats.tx_aborted_errors++;
559 netdev_dbg(dev,
"el3_start_xmit(length = %ld) called, status %4.4x.\n",
573 netif_stop_queue(dev);
579 spin_unlock_irqrestore(&priv->
lock, flags);
592 int i = 0, handled = 1;
594 if (!netif_device_present(dev))
601 spin_lock(&lp->
lock);
604 if ((status & 0xe000) != 0x2000) {
605 netdev_dbg(dev,
"interrupt from dead card\n");
612 netdev_dbg(dev,
" TX room bit was handled.\n");
615 netif_wake_queue(dev);
630 fifo_diag =
inw(ioaddr + 4);
632 netdev_warn(dev,
"adapter failure, FIFO diagnostic register %04x.\n",
634 if (fifo_diag & 0x0400) {
636 tc589_wait_for_completion(dev,
TxReset);
639 if (fifo_diag & 0x2000) {
641 tc589_wait_for_completion(dev,
RxReset);
649 netdev_err(dev,
"infinite loop in interrupt, status %4.4x.\n",
659 spin_unlock(&lp->
lock);
660 netdev_dbg(dev,
"exiting interrupt, status %4.4x.\n",
665 static void media_check(
unsigned long arg)
673 if (!netif_device_present(dev))
goto reschedule;
680 netdev_warn(dev,
"interrupt(s) dropped!\n");
683 el3_interrupt(dev->
irq, dev);
708 errs =
inb(ioaddr + 0);
710 dev->
stats.tx_carrier_errors += errs;
711 if (errs || (lp->
media_status & 0x0010)) media |= 0x0010;
717 netdev_info(dev,
"%s link beat\n",
721 netdev_info(dev,
"coax cable %s\n",
724 if (media & 0x8000) {
726 netdev_info(dev,
"flipped to 10baseT\n");
728 tc589_set_xcvr(dev, 2);
729 }
else if (media & 0x4000) {
731 tc589_set_xcvr(dev, 1);
733 netdev_info(dev,
"flipped to 10base2\n");
740 spin_unlock_irqrestore(&lp->
lock, flags);
751 struct pcmcia_device *link = lp->
p_dev;
756 spin_unlock_irqrestore(&lp->
lock, flags);
769 static void update_stats(
struct net_device *dev)
773 netdev_dbg(dev,
"updating the statistics.\n");
778 dev->
stats.tx_carrier_errors +=
inb(ioaddr + 0);
779 dev->
stats.tx_heartbeat_errors +=
inb(ioaddr + 1);
781 dev->
stats.collisions +=
inb(ioaddr + 3);
782 dev->
stats.tx_window_errors +=
inb(ioaddr + 4);
783 dev->
stats.rx_fifo_errors +=
inb(ioaddr + 5);
784 dev->
stats.tx_packets +=
inb(ioaddr + 6);
801 netdev_dbg(dev,
"in rx_packet(), status %4.4x, rx_status %4.4x.\n",
803 while (!((rx_status =
inw(ioaddr +
RX_STATUS)) & 0x8000) &&
806 if (rx_status & 0x4000) {
807 short error = rx_status & 0x3800;
808 dev->
stats.rx_errors++;
810 case 0x0000: dev->
stats.rx_over_errors++;
break;
811 case 0x0800: dev->
stats.rx_length_errors++;
break;
812 case 0x1000: dev->
stats.rx_frame_errors++;
break;
813 case 0x1800: dev->
stats.rx_length_errors++;
break;
814 case 0x2000: dev->
stats.rx_frame_errors++;
break;
815 case 0x2800: dev->
stats.rx_crc_errors++;
break;
818 short pkt_len = rx_status & 0x7ff;
821 skb = netdev_alloc_skb(dev, pkt_len + 5);
823 netdev_dbg(dev,
" Receiving packet size %d status %4.4x.\n",
831 dev->
stats.rx_packets++;
834 netdev_dbg(dev,
"couldn't allocate a sk_buff of size %d.\n",
836 dev->
stats.rx_dropped++;
840 tc589_wait_for_completion(dev,
RxDiscard);
843 netdev_warn(dev,
"too much work in el3_rx!\n");
847 static void set_rx_mode(
struct net_device *dev)
859 static void set_multicast_list(
struct net_device *dev)
866 spin_unlock_irqrestore(&priv->
lock, flags);
872 struct pcmcia_device *link = lp->
p_dev;
875 dev_dbg(&link->dev,
"%s: shutting down ethercard.\n", dev->
name);
905 netif_stop_queue(dev);
912 PCMCIA_MFC_DEVICE_MANF_CARD(0, 0x0101, 0x0562),
913 PCMCIA_MFC_DEVICE_PROD_ID1(0,
"Motorola MARQUIS", 0xf03e4e77),
914 PCMCIA_DEVICE_MANF_CARD(0x0101, 0x0589),
915 PCMCIA_DEVICE_PROD_ID12(
"Farallon",
"ENet", 0x58d93fc4, 0x992c2202),
916 PCMCIA_MFC_DEVICE_CIS_MANF_CARD(0, 0x0101, 0x0035,
"cis/3CXEM556.cis"),
917 PCMCIA_MFC_DEVICE_CIS_MANF_CARD(0, 0x0101, 0x003d,
"cis/3CXEM556.cis"),
922 static struct pcmcia_driver tc589_driver = {
925 .probe = tc589_probe,
926 .remove = tc589_detach,
927 .id_table = tc589_ids,
928 .suspend = tc589_suspend,
929 .resume = tc589_resume,
932 static int __init init_tc589(
void)
937 static void __exit exit_tc589(
void)