27 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
29 #include <linux/kernel.h>
30 #include <linux/module.h>
32 #include <linux/ptrace.h>
33 #include <linux/string.h>
37 #include <linux/netdevice.h>
40 #include <linux/mii.h>
49 #include <asm/byteorder.h>
50 #include <asm/uaccess.h>
52 #define AXNET_CMD 0x00
53 #define AXNET_DATAPORT 0x10
54 #define AXNET_RESET 0x1f
55 #define AXNET_MII_EEP 0x14
56 #define AXNET_TEST 0x15
57 #define AXNET_GPIO 0x17
59 #define AXNET_START_PG 0x40
60 #define AXNET_STOP_PG 0x80
62 #define AXNET_RDC_TIMEOUT 0x02
64 #define IS_AX88190 0x0001
65 #define IS_AX88790 0x0002
78 static int axnet_config(
struct pcmcia_device *
link);
79 static void axnet_release(
struct pcmcia_device *
link);
100 const u_char *
buf,
const int start_page);
102 static void axnet_detach(
struct pcmcia_device *p_dev);
104 static void AX88190_init(
struct net_device *
dev,
int startp);
125 void *
p = (
char *)netdev_priv(dev) +
sizeof(
struct ei_device);
130 .ndo_open = axnet_open,
131 .ndo_stop = axnet_close,
132 .ndo_do_ioctl = axnet_ioctl,
133 .ndo_start_xmit = axnet_start_xmit,
134 .ndo_tx_timeout = axnet_tx_timeout,
136 .ndo_set_rx_mode = set_multicast_list,
142 static int axnet_probe(
struct pcmcia_device *
link)
148 dev_dbg(&link->dev,
"axnet_attach()\n");
154 ei_local = netdev_priv(dev);
160 link->config_flags |= CONF_ENABLE_IRQ;
166 return axnet_config(link);
169 static void axnet_detach(
struct pcmcia_device *link)
173 dev_dbg(&link->dev,
"axnet_detach(0x%p)\n", link);
188 static int get_prom(
struct pcmcia_device *link)
214 if (link->config_base != 0x03c0)
217 axnet_reset_8390(dev);
223 for (i = 0; i < 6; i += 2) {
231 static int try_io_port(
struct pcmcia_device *link)
234 link->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
235 link->resource[1]->flags &= ~IO_DATA_PATH_WIDTH;
236 if (link->resource[0]->end == 32) {
237 link->resource[0]->flags |= IO_DATA_PATH_WIDTH_AUTO;
239 if (link->resource[1]->end > 0)
240 link->resource[1]->flags |= IO_DATA_PATH_WIDTH_8;
243 link->resource[0]->flags |= IO_DATA_PATH_WIDTH_8;
244 link->resource[1]->flags |= IO_DATA_PATH_WIDTH_16;
246 if (link->resource[0]->start == 0) {
247 for (j = 0; j < 0x400; j += 0x20) {
248 link->resource[0]->start = j ^ 0x300;
249 link->resource[1]->start = (j ^ 0x300) + 0x10;
261 static int axnet_configcheck(
struct pcmcia_device *p_dev,
void *priv_data)
263 if (p_dev->config_index == 0)
266 p_dev->config_index = 0x05;
267 if (p_dev->resource[0]->end + p_dev->resource[1]->end < 32)
270 return try_io_port(p_dev);
273 static int axnet_config(
struct pcmcia_device *link)
279 dev_dbg(&link->dev,
"axnet_config(0x%p)\n", link);
282 link->config_regs = 0x63;
283 link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO;
284 ret = pcmcia_loop_config(link, axnet_configcheck,
NULL);
291 if (resource_size(link->resource[1]) == 8)
292 link->config_flags |= CONF_ENABLE_SPKR;
298 dev->
irq = link->irq;
299 dev->
base_addr = link->resource[0]->start;
301 if (!get_prom(link)) {
302 pr_notice(
"this is not an AX88190 card!\n");
327 for (i = 0; i < 32; i++) {
330 if (j == j2)
continue;
331 if ((j != 0) && (j != 0xffff))
break;
338 for (i = 0; i < 32; i++) {
341 if (j == j2)
continue;
342 if ((j != 0) && (j != 0xffff)) {
349 info->
phy_id = (i < 32) ? i : -1;
357 netdev_info(dev,
"Asix AX88%d90: io %#3lx, irq %d, hw_addr %pM\n",
361 netdev_dbg(dev,
" MII transceiver at index %d, status %x\n",
364 netdev_notice(dev,
" No MII transceivers found!\n");
373 static void axnet_release(
struct pcmcia_device *link)
378 static int axnet_suspend(
struct pcmcia_device *link)
388 static int axnet_resume(
struct pcmcia_device *link)
397 axnet_reset_8390(dev);
398 AX88190_init(dev, 1);
412 #define MDIO_SHIFT_CLK 0x01
413 #define MDIO_DATA_WRITE0 0x00
414 #define MDIO_DATA_WRITE1 0x08
415 #define MDIO_DATA_READ 0x04
416 #define MDIO_MASK 0x0f
417 #define MDIO_ENB_IN 0x02
419 static void mdio_sync(
unsigned int addr)
422 for (bits = 0; bits < 32; bits++) {
434 for (i = 14; i >= 0; i--) {
439 for (i = 19; i > 0; i--) {
444 return (retval>>1) & 0xffff;
447 static void mdio_write(
unsigned int addr,
int phy_id,
int loc,
int value)
449 u_int cmd = (0x05<<28)|(phy_id<<23)|(loc<<18)|(1<<17)|
value;
453 for (i = 31; i >= 0; i--) {
458 for (i = 1; i >= 0; i--) {
470 struct pcmcia_device *link = info->
p_dev;
473 dev_dbg(&link->dev,
"axnet_open('%s')\n", dev->
name);
487 info->
watchdog.function = ei_watchdog;
497 static int axnet_close(
struct net_device *dev)
500 struct pcmcia_device *link = info->
p_dev;
502 dev_dbg(&link->dev,
"axnet_close('%s')\n", dev->
name);
508 netif_stop_queue(dev);
521 static void axnet_reset_8390(
struct net_device *dev)
532 for (i = 0; i < 100; i++) {
540 netdev_err(dev,
"axnet_reset_8390() did not complete\n");
549 PRIV(dev)->stale = 0;
550 return ax_interrupt(irq, dev_id);
561 if (!netif_device_present(dev))
goto reschedule;
567 netdev_info(dev,
"interrupt(s) dropped!\n");
568 ei_irq_wrapper(dev->
irq, dev);
580 link = mdio_read(mii_addr, info->
phy_id, 1);
581 if (!link || (link == 0xffff)) {
582 netdev_info(dev,
"MII is missing!\n");
590 netdev_info(dev,
"%s link beat\n", link ?
"found" :
"lost");
594 netdev_info(dev,
"autonegotiation complete: %dbaseT-%cD selected\n",
595 (p & 0x0180) ? 100 : 10, (p & 0x0140) ?
'F' :
'H');
597 netdev_info(dev,
"link partner did not autonegotiate\n");
598 AX88190_init(dev, 1);
630 static void get_8390_hdr(
struct net_device *dev,
653 int xfer_count =
count;
670 static void block_output(
struct net_device *dev,
int count,
671 const u_char *buf,
const int start_page)
690 PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x016c, 0x0081),
691 PCMCIA_DEVICE_MANF_CARD(0x018a, 0x0301),
692 PCMCIA_DEVICE_MANF_CARD(0x01bf, 0x2328),
693 PCMCIA_DEVICE_MANF_CARD(0x026f, 0x0301),
694 PCMCIA_DEVICE_MANF_CARD(0x026f, 0x0303),
695 PCMCIA_DEVICE_MANF_CARD(0x026f, 0x0309),
696 PCMCIA_DEVICE_MANF_CARD(0x0274, 0x1106),
697 PCMCIA_DEVICE_MANF_CARD(0x8a01, 0xc1ab),
698 PCMCIA_DEVICE_MANF_CARD(0x021b, 0x0202),
699 PCMCIA_DEVICE_MANF_CARD(0xffff, 0x1090),
700 PCMCIA_DEVICE_PROD_ID12(
"AmbiCom,Inc.",
"Fast Ethernet PC Card(AMB8110)", 0x49b020a7, 0x119cc9fc),
701 PCMCIA_DEVICE_PROD_ID124(
"Fast Ethernet",
"16-bit PC Card",
"AX88190", 0xb4be14e3, 0x9a12eb6a, 0xab9be5ef),
702 PCMCIA_DEVICE_PROD_ID12(
"ASIX",
"AX88190", 0x0959823b, 0xab9be5ef),
703 PCMCIA_DEVICE_PROD_ID12(
"Billionton",
"LNA-100B", 0x552ab682, 0xbc3b87e1),
704 PCMCIA_DEVICE_PROD_ID12(
"CHEETAH ETHERCARD",
"EN2228", 0x00fa7bc8, 0x00e990cc),
705 PCMCIA_DEVICE_PROD_ID12(
"CNet",
"CNF301", 0xbc477dde, 0x78c5f40b),
706 PCMCIA_DEVICE_PROD_ID12(
"corega K.K.",
"corega FEther PCC-TXD", 0x5261440f, 0x436768c5),
707 PCMCIA_DEVICE_PROD_ID12(
"corega K.K.",
"corega FEtherII PCC-TXD", 0x5261440f, 0x730df72e),
708 PCMCIA_DEVICE_PROD_ID12(
"corega K.K.",
"corega FEther PCC-TXM", 0x5261440f, 0x3abbd061),
709 PCMCIA_DEVICE_PROD_ID12(
"Dynalink",
"L100C16", 0x55632fd5, 0x66bc2a90),
710 PCMCIA_DEVICE_PROD_ID12(
"IO DATA",
"ETXPCM", 0x547e66dc, 0x233adac2),
711 PCMCIA_DEVICE_PROD_ID12(
"Linksys",
"EtherFast 10/100 PC Card (PCMPC100 V3)", 0x0733cc81, 0x232019a8),
712 PCMCIA_DEVICE_PROD_ID12(
"MELCO",
"LPC3-TX", 0x481e0094, 0xf91af609),
713 PCMCIA_DEVICE_PROD_ID12(
"NETGEAR",
"FA411", 0x9aa79dc3, 0x40fad875),
714 PCMCIA_DEVICE_PROD_ID12(
"PCMCIA",
"100BASE", 0x281f1c5d, 0x7c2add04),
715 PCMCIA_DEVICE_PROD_ID12(
"PCMCIA",
"FastEtherCard", 0x281f1c5d, 0x7ef26116),
716 PCMCIA_DEVICE_PROD_ID12(
"PCMCIA",
"FEP501", 0x281f1c5d, 0x2e272058),
717 PCMCIA_DEVICE_PROD_ID14(
"Network Everywhere",
"AX88190", 0x820a67b6, 0xab9be5ef),
722 static struct pcmcia_driver axnet_cs_driver = {
725 .probe = axnet_probe,
726 .remove = axnet_detach,
727 .id_table = axnet_ids,
728 .suspend = axnet_suspend,
729 .resume = axnet_resume,
732 static int __init init_axnet_cs(
void)
737 static void __exit exit_axnet_cs(
void)
794 #include <linux/bitops.h>
796 #include <linux/fcntl.h>
797 #include <linux/in.h>
820 #define ei_reset_8390 (ei_local->reset_8390)
821 #define ei_block_output (ei_local->block_output)
822 #define ei_block_input (ei_local->block_input)
823 #define ei_get_8390_hdr (ei_local->get_8390_hdr)
831 static void ei_tx_intr(
struct net_device *dev);
832 static void ei_tx_err(
struct net_device *dev);
833 static void ei_receive(
struct net_device *dev);
834 static void ei_rx_overrun(
struct net_device *dev);
837 static void NS8390_trigger_send(
struct net_device *dev,
unsigned int length,
839 static void do_set_multicast_list(
struct net_device *dev);
878 struct ei_device *ei_local = netdev_priv(dev);
886 AX88190_init(dev, 1);
889 netif_start_queue(dev);
890 spin_unlock_irqrestore(&ei_local->
page_lock, flags);
895 #define dev_lock(dev) (((struct ei_device *)netdev_priv(dev))->page_lock)
912 AX88190_init(dev, 0);
913 spin_unlock_irqrestore(&
dev_lock(dev), flags);
914 netif_stop_queue(dev);
926 static void axnet_tx_timeout(
struct net_device *dev)
929 struct ei_device *ei_local = netdev_priv(dev);
933 dev->
stats.tx_errors++;
938 spin_unlock_irqrestore(&ei_local->
page_lock, flags);
941 "Tx timed out, %s TSR=%#2x, ISR=%#2x, t=%d.\n",
942 (txsr &
ENTSR_ABT) ?
"excess collisions." :
943 (isr) ?
"lost interrupt?" :
"cable problem?",
944 txsr, isr, tickssofar);
946 if (!isr && !dev->
stats.tx_packets)
958 AX88190_init(dev, 1);
960 spin_unlock_irqrestore(&ei_local->
page_lock, flags);
961 netif_wake_queue(dev);
976 struct ei_device *ei_local = netdev_priv(dev);
977 int length, send_length, output_page;
981 netif_stop_queue(dev);
1009 if (ei_local->
tx1 == 0)
1012 ei_local->
tx1 = send_length;
1013 if (ei_debug && ei_local->
tx2 > 0)
1015 "idle transmitter tx2=%d, lasttx=%d, txing=%d\n",
1019 else if (ei_local->
tx2 == 0)
1022 ei_local->
tx2 = send_length;
1023 if (ei_debug && ei_local->
tx1 > 0)
1025 "idle transmitter, tx1=%d, lasttx=%d, txing=%d\n",
1033 "No Tx buffers free! tx1=%d tx2=%d last=%d\n",
1034 ei_local->
tx1, ei_local->
tx2,
1037 netif_stop_queue(dev);
1039 spin_unlock_irqrestore(&ei_local->
page_lock, flags);
1040 dev->
stats.tx_errors++;
1050 if (length == skb->
len)
1054 skb_copy_from_linear_data(skb, packet, skb->
len);
1058 if (! ei_local->
txing)
1060 ei_local->
txing = 1;
1061 NS8390_trigger_send(dev, send_length, output_page);
1076 if (ei_local->
tx1 && ei_local->
tx2)
1077 netif_stop_queue(dev);
1079 netif_start_queue(dev);
1085 spin_unlock_irqrestore(&ei_local->
page_lock, flags);
1087 dev_kfree_skb (skb);
1088 dev->
stats.tx_bytes += send_length;
1109 int interrupts, nr_serviced = 0,
i;
1112 unsigned long flags;
1115 ei_local = netdev_priv(dev);
1128 msg =
"Interrupted while interrupts are masked!";
1130 msg =
"Reentering the interrupt handler!";
1131 netdev_info(dev,
"%s, isr=%#2x imr=%#2x\n",
1136 spin_unlock_irqrestore(&ei_local->
page_lock, flags);
1148 while ((interrupts =
inb_p(e8390_base +
EN0_ISR)) != 0 &&
1151 if (!netif_running(dev) || (interrupts == 0xff)) {
1154 "interrupt from stopped card\n");
1163 for (i = 0; i < 10; i++) {
1164 if (!(
inb(e8390_base +
EN0_ISR) & interrupts))
1190 if (interrupts && ei_debug > 3)
1196 if(interrupts!=0xFF)
1197 netdev_warn(dev,
"Too much work at interrupt, status %#2.2x\n",
1201 netdev_warn(dev,
"unknown interrupt %#2x\n",
1211 spin_unlock_irqrestore(&ei_local->
page_lock, flags);
1229 static void ei_tx_err(
struct net_device *dev)
1233 unsigned char tx_was_aborted = txsr & (ENTSR_ABT+
ENTSR_FU);
1235 #ifdef VERBOSE_ERROR_DUMP
1237 "transmitter error (%#2x):", txsr);
1238 if (txsr & ENTSR_ABT)
1239 pr_cont(
" excess-collisions");
1255 dev->
stats.tx_errors++;
1256 if (txsr & ENTSR_CRS) dev->
stats.tx_carrier_errors++;
1257 if (txsr & ENTSR_CDH) dev->
stats.tx_heartbeat_errors++;
1270 static void ei_tx_intr(
struct net_device *dev)
1273 struct ei_device *ei_local = netdev_priv(dev);
1282 if (ei_local->
tx1 < 0)
1285 netdev_err(dev,
"%s: bogus last_tx_buffer %d, tx1=%d\n",
1289 if (ei_local->
tx2 > 0)
1291 ei_local->
txing = 1;
1299 else if (ei_local->
tx2 < 0)
1302 netdev_info(dev,
"%s: bogus last_tx_buffer %d, tx2=%d\n",
1306 if (ei_local->
tx1 > 0)
1308 ei_local->
txing = 1;
1323 dev->
stats.collisions++;
1325 dev->
stats.tx_packets++;
1328 dev->
stats.tx_errors++;
1329 if (status & ENTSR_ABT)
1331 dev->
stats.tx_aborted_errors++;
1332 dev->
stats.collisions += 16;
1334 if (status & ENTSR_CRS)
1335 dev->
stats.tx_carrier_errors++;
1336 if (status & ENTSR_FU)
1337 dev->
stats.tx_fifo_errors++;
1338 if (status & ENTSR_CDH)
1339 dev->
stats.tx_heartbeat_errors++;
1341 dev->
stats.tx_window_errors++;
1343 netif_wake_queue(dev);
1354 static void ei_receive(
struct net_device *dev)
1357 struct ei_device *ei_local = netdev_priv(dev);
1358 unsigned char rxing_page, this_frame,
next_frame;
1359 unsigned short current_offset;
1360 int rx_pkt_count = 0;
1363 while (++rx_pkt_count < 10)
1381 if (ei_debug > 0 && this_frame != ei_local->
current_page && (this_frame!=0x0 || rxing_page!=0xFF))
1382 netdev_err(dev,
"mismatched read page pointers %2x vs %2x\n",
1385 if (this_frame == rxing_page)
1388 current_offset = this_frame << 8;
1392 pkt_stat = rx_frame.status;
1394 next_frame = this_frame + 1 + ((pkt_len+4)>>8);
1396 if (pkt_len < 60 || pkt_len > 1518)
1400 "bogus packet size: %d, status=%#2x nxpg=%#2x\n",
1401 rx_frame.count, rx_frame.status,
1403 dev->
stats.rx_errors++;
1404 dev->
stats.rx_length_errors++;
1410 skb = netdev_alloc_skb(dev, pkt_len + 2);
1415 "Couldn't allocate a sk_buff of size %d\n",
1417 dev->
stats.rx_dropped++;
1424 ei_block_input(dev, pkt_len, skb, current_offset +
sizeof(rx_frame));
1427 dev->
stats.rx_packets++;
1430 dev->
stats.multicast++;
1437 "bogus packet: status=%#2x nxpg=%#2x size=%d\n",
1438 rx_frame.status, rx_frame.next,
1440 dev->
stats.rx_errors++;
1443 dev->
stats.rx_fifo_errors++;
1445 next_frame = rx_frame.next;
1448 if (next_frame >= ei_local->
stop_page) {
1449 netdev_info(dev,
"next frame inconsistency, %#2x\n",
1471 static void ei_rx_overrun(
struct net_device *dev)
1475 unsigned char was_txing, must_resend = 0;
1486 dev->
stats.rx_over_errors++;
1540 struct ei_device *ei_local = netdev_priv(dev);
1541 unsigned long flags;
1544 if (!netif_running(dev))
1552 spin_unlock_irqrestore(&ei_local->
page_lock, flags);
1573 bits[crc>>29] |= (1<<((crc>>26)&7));
1585 static void do_set_multicast_list(
struct net_device *dev)
1589 struct ei_device *ei_local = netdev_priv(dev);
1594 make_mc_bits(ei_local->
mcfilter, dev);
1601 for(i = 0; i < 8; i++)
1623 static void set_multicast_list(
struct net_device *dev)
1625 unsigned long flags;
1628 do_set_multicast_list(dev);
1629 spin_unlock_irqrestore(&
dev_lock(dev), flags);
1643 static void AX88190_init(
struct net_device *dev,
int startp)
1647 struct ei_device *ei_local = netdev_priv(dev);
1652 panic(
"8390.c: header struct mispacked\n");
1664 ei_local->
tx1 = ei_local->
tx2 = 0;
1676 for(i = 0; i < 6; i++)
1680 netdev_err(dev,
"Hw. address read/write mismap %d\n", i);
1686 netif_start_queue(dev);
1687 ei_local->
tx1 = ei_local->
tx2 = 0;
1688 ei_local->
txing = 0;
1702 do_set_multicast_list(dev);
1709 static void NS8390_trigger_send(
struct net_device *dev,
unsigned int length,
1717 netdev_warn(dev,
"trigger_send() called with the transmitter busy\n");