30 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
33 #include <linux/module.h>
38 #include <linux/pci.h>
40 #include <linux/netdevice.h>
45 #include <linux/mii.h>
53 static int tlan_devices_installed;
59 static int boards_found;
65 "ThunderLAN duplex setting(s) (0-default, 1-half, 2-full)");
81 static const char tlan_signature[] =
"TLAN";
82 static const char tlan_banner[] =
"ThunderLAN driver v1.17\n";
83 static int tlan_have_pci;
84 static int tlan_have_eisa;
86 static const char *
const media[] = {
87 "10BaseT-HD",
"10BaseT-FD",
"100baseTx-HD",
88 "100BaseTx-FD",
"100BaseT4",
NULL
97 {
"Compaq Netelligent 10/100 TX PCI UTP",
100 {
"Compaq NetFlex-3/P",
103 {
"Compaq Netelligent Integrated 10/100 TX UTP",
105 {
"Compaq Netelligent Dual 10/100 TX PCI UTP",
107 {
"Compaq Netelligent 10/100 TX Embedded UTP",
114 {
"Compaq NetFlex-3/E",
117 {
"Compaq NetFlex-3/E",
152 static void tlan_eisa_probe(
void);
153 static void tlan_eisa_cleanup(
void);
157 static irqreturn_t tlan_handle_interrupt(
int,
void *);
160 static void tlan_set_multicast_list(
struct net_device *);
162 static int tlan_probe1(
struct pci_dev *pdev,
long ioaddr,
166 static int tlan_init_one(
struct pci_dev *pdev,
177 static void tlan_timer(
unsigned long);
179 static void tlan_reset_lists(
struct net_device *);
180 static void tlan_free_lists(
struct net_device *);
181 static void tlan_print_dio(
u16);
182 static void tlan_print_list(
struct tlan_list *,
char *,
int);
183 static void tlan_read_and_clear_stats(
struct net_device *,
int);
184 static void tlan_reset_adapter(
struct net_device *);
185 static void tlan_finish_reset(
struct net_device *);
186 static void tlan_set_mac(
struct net_device *,
int areg,
char *
mac);
188 static void tlan_phy_print(
struct net_device *);
189 static void tlan_phy_detect(
struct net_device *);
190 static void tlan_phy_power_down(
struct net_device *);
191 static void tlan_phy_power_up(
struct net_device *);
192 static void tlan_phy_reset(
struct net_device *);
193 static void tlan_phy_start_link(
struct net_device *);
194 static void tlan_phy_finish_auto_neg(
struct net_device *);
196 static void tlan_phy_monitor(
struct net_device *);
207 static void tlan_mii_send_data(
u16,
u32,
unsigned);
208 static void tlan_mii_sync(
u16);
211 static void tlan_ee_send_start(
u16);
212 static int tlan_ee_send_byte(
u16,
u8,
int);
213 static void tlan_ee_receive_byte(
u16,
u8 *,
int);
220 unsigned long addr = (
unsigned long)skb;
230 addr = tag->
buffer[9].address;
231 addr |= ((
unsigned long) tag->
buffer[8].address << 16) << 16;
239 tlan_handle_stat_overflow,
243 tlan_handle_status_check,
251 unsigned long flags = 0;
258 spin_unlock_irqrestore(&priv->
lock, flags);
261 priv->
timer.function = tlan_timer;
263 spin_unlock_irqrestore(&priv->
lock, flags);
305 struct net_device *dev = pci_get_drvdata(pdev);
306 struct tlan_priv *priv = netdev_priv(dev);
322 pci_set_drvdata(pdev,
NULL);
325 static void tlan_start(
struct net_device *dev)
327 tlan_reset_lists(dev);
332 tlan_reset_adapter(dev);
333 netif_wake_queue(dev);
338 struct tlan_priv *priv = netdev_priv(dev);
343 tlan_reset_adapter(dev);
354 struct net_device *dev = pci_get_drvdata(pdev);
356 if (netif_running(dev))
370 struct net_device *dev = pci_get_drvdata(pdev);
374 pci_enable_wake(pdev, 0, 0);
377 if (netif_running(dev))
385 #define tlan_suspend NULL
386 #define tlan_resume NULL
393 .id_table = tlan_pci_tbl,
394 .probe = tlan_init_one,
400 static int __init tlan_probe(
void)
410 rc = pci_register_driver(&tlan_driver);
413 pr_err(
"Could not register pci driver\n");
414 goto err_out_pci_free;
420 pr_info(
"%d device%s installed, PCI: %d EISA: %d\n",
421 tlan_devices_installed, tlan_devices_installed == 1 ?
"" :
"s",
422 tlan_have_pci, tlan_have_eisa);
424 if (tlan_devices_installed == 0) {
426 goto err_out_pci_unreg;
440 return tlan_probe1(pdev, -1, -1, 0, ent);
464 long ioaddr,
int irq,
int rev,
481 pr_err(
"Could not reserve IO regions\n");
487 dev = alloc_etherdev(
sizeof(
struct tlan_priv));
490 goto err_out_regions;
494 priv = netdev_priv(dev);
507 pr_err(
"No suitable PCI mapping available\n");
508 goto err_out_free_dev;
511 for (reg = 0; reg <= 5; reg++) {
515 "IO mapping is available at %x.\n",
521 pr_err(
"No IO mappings available\n");
523 goto err_out_free_dev;
530 pci_set_drvdata(pdev, dev);
537 if (device_id == 0x20F1) {
556 if (priv->
speed == 0x1)
558 else if (priv->
speed == 0x2)
563 priv->
aui =
aui[boards_found];
577 pr_err(
"Could not set up device\n");
578 goto err_out_free_dev;
583 pr_err(
"Could not register device\n");
588 tlan_devices_installed++;
596 tlan_eisa_devices =
dev;
600 netdev_info(dev,
"irq=%2d, io=%04x, %s, Rev. %d\n",
624 static void tlan_eisa_cleanup(
void)
629 while (tlan_have_eisa) {
630 dev = tlan_eisa_devices;
631 priv = netdev_priv(dev);
646 static void __exit tlan_exit(
void)
675 static void __init tlan_eisa_probe(
void)
688 for (ioaddr = 0x1000; ioaddr < 0x9000; ioaddr += 0x1000) {
697 "Probing for EISA adapter at IO: 0x%4x : ",
708 if (device_id != 0x20F1 && device_id != 0x40F1) {
724 switch (
inb(ioaddr + 0xcc0)) {
743 rc = tlan_probe1(
NULL, ioaddr, irq,
754 pr_info(
"Card found but it is not enabled, skipping\n");
761 #ifdef CONFIG_NET_POLL_CONTROLLER
765 tlan_handle_interrupt(dev->
irq, dev);
771 .ndo_open = tlan_open,
772 .ndo_stop = tlan_close,
773 .ndo_start_xmit = tlan_start_tx,
774 .ndo_tx_timeout = tlan_tx_timeout,
775 .ndo_get_stats = tlan_get_stats,
776 .ndo_set_rx_mode = tlan_set_multicast_list,
777 .ndo_do_ioctl = tlan_ioctl,
781 #ifdef CONFIG_NET_POLL_CONTROLLER
782 .ndo_poll_controller = tlan_poll,
812 priv = netdev_priv(dev);
822 pr_err(
"Could not allocate lists and buffers for %s\n",
835 for (i = 0; i < 6 ; i++)
836 err |= tlan_ee_read_byte(dev,
840 pr_err(
"%s: Error reading MAC from eeprom: %d\n",
877 struct tlan_priv *priv = netdev_priv(dev);
885 netdev_err(dev,
"Cannot open because IRQ %d is already in use\n",
920 struct tlan_priv *priv = netdev_priv(dev);
933 tlan_mii_read_reg(dev, data->
phy_id & 0x1f,
939 tlan_mii_write_reg(dev, data->
phy_id & 0x1f,
959 static void tlan_tx_timeout(
struct net_device *dev)
965 tlan_free_lists(dev);
966 tlan_reset_lists(dev);
968 tlan_reset_adapter(dev);
970 netif_wake_queue(dev);
990 tlan_tx_timeout(priv->
dev);
1018 struct tlan_priv *priv = netdev_priv(dev);
1021 unsigned long flags;
1041 "TRANSMIT: %s is busy (Head=%d Tail=%d)\n",
1043 netif_stop_queue(dev);
1050 tail_list->
buffer[0].address = pci_map_single(priv->
pci_dev,
1053 tlan_store_skb(tail_list, skb);
1057 tail_list->
buffer[1].count = 0;
1058 tail_list->
buffer[1].address = 0;
1065 "TRANSMIT: Starting TX on buffer %d\n",
1071 "TRANSMIT: Adding buffer %d to TX channel\n",
1081 spin_unlock_irqrestore(&priv->
lock, flags);
1115 struct tlan_priv *priv = netdev_priv(dev);
1119 spin_lock(&priv->
lock);
1128 ack = tlan_int_vector[
type](
dev, host_int);
1136 spin_unlock(&priv->
lock);
1159 static int tlan_close(
struct net_device *dev)
1161 struct tlan_priv *priv = netdev_priv(dev);
1167 tlan_free_lists(dev);
1194 struct tlan_priv *priv = netdev_priv(dev);
1206 tlan_phy_print(dev);
1210 tlan_print_list(priv->
rx_list + i,
"RX", i);
1212 tlan_print_list(priv->
tx_list + i,
"TX", i);
1242 static void tlan_set_multicast_list(
struct net_device *dev)
1260 for (i = 0; i < 3; i++)
1261 tlan_set_mac(dev, i + 1,
NULL);
1270 tlan_set_mac(dev, i + 1,
1271 (
char *) &ha->
addr);
1274 tlan_hash_func((
u8 *)&ha->
addr);
1278 hash2 |= (1 << (offset - 32));
1283 tlan_set_mac(dev, i + 1,
NULL);
1332 struct tlan_priv *priv = netdev_priv(dev);
1340 "TRANSMIT: Handling TX EOF (Head=%d Tail=%d)\n",
1346 struct sk_buff *skb = tlan_get_skb(head_list);
1349 pci_unmap_single(priv->
pci_dev, head_list->
buffer[0].address,
1354 head_list->
buffer[8].address = 0;
1355 head_list->
buffer[9].address = 0;
1363 netif_start_queue(dev);
1370 "Received interrupt for uncompleted TX frame\n");
1374 "TRANSMIT: handling TX EOC (Head=%d Tail=%d)\n",
1392 priv->
timer.function = tlan_timer;
1465 struct tlan_priv *priv = netdev_priv(dev);
1490 new_skb = netdev_alloc_skb_ip_align(dev,
1493 goto drop_and_reuse;
1495 skb = tlan_get_skb(head_list);
1496 pci_unmap_single(priv->
pci_dev, frame_dma,
1500 dev->
stats.rx_bytes += frame_size;
1505 head_list->
buffer[0].address =
1509 tlan_store_skb(head_list, new_skb);
1514 tail_list->
forward = head_list_phys;
1525 "Received interrupt for uncompleted RX frame\n");
1530 "RECEIVE: handling RX EOC (Head=%d Tail=%d)\n",
1544 priv->
timer.function = tlan_timer;
1581 netdev_info(dev,
"Test interrupt\n");
1611 struct tlan_priv *priv = netdev_priv(dev);
1619 "TRANSMIT: handling TX EOC (Head=%d Tail=%d) -- IRQ\n",
1626 netif_stop_queue(dev);
1663 struct tlan_priv *priv = netdev_priv(dev);
1673 netif_stop_queue(dev);
1675 netdev_info(dev,
"Adaptor Error = 0x%x\n", error);
1681 netif_wake_queue(dev);
1684 TLAN_DBG(TLAN_DEBUG_GNRL,
"%s: Status Check\n", dev->
name);
1690 TLAN_DBG(TLAN_DEBUG_GNRL,
"%s: Net_Sts = %x\n",
1691 dev->
name, (
unsigned) net_sts);
1701 }
else if ((tlphy_sts & TLAN_TS_POLOK) &&
1702 (tlphy_ctl & TLAN_TC_SWAPOL)) {
1703 tlphy_ctl &= ~TLAN_TC_SWAPOL;
1709 tlan_phy_print(dev);
1742 struct tlan_priv *priv = netdev_priv(dev);
1748 "RECEIVE: Handling RX EOC (head=%d tail=%d) -- IRQ\n",
1803 static void tlan_timer(
unsigned long data)
1806 struct tlan_priv *priv = netdev_priv(dev);
1808 unsigned long flags = 0;
1815 tlan_phy_monitor(dev);
1819 tlan_phy_power_down(dev);
1822 tlan_phy_power_up(dev);
1825 tlan_phy_reset(dev);
1828 tlan_phy_start_link(dev);
1831 tlan_phy_finish_auto_neg(dev);
1834 tlan_finish_reset(dev);
1844 priv->
timer.function = tlan_timer;
1847 spin_unlock_irqrestore(&priv->
lock, flags);
1852 spin_unlock_irqrestore(&priv->
lock, flags);
1886 static void tlan_reset_lists(
struct net_device *dev)
1888 struct tlan_priv *priv = netdev_priv(dev);
1899 list->
buffer[0].address = 0;
1900 list->
buffer[2].count = 0;
1901 list->
buffer[2].address = 0;
1902 list->
buffer[8].address = 0;
1903 list->
buffer[9].address = 0;
1907 priv->
rx_tail = TLAN_NUM_RX_LISTS - 1;
1916 netdev_err(dev,
"Out of memory for received data\n");
1924 tlan_store_skb(list, skb);
1925 list->
buffer[1].count = 0;
1926 list->
buffer[1].address = 0;
1931 while (i < TLAN_NUM_RX_LISTS) {
1940 static void tlan_free_lists(
struct net_device *dev)
1942 struct tlan_priv *priv = netdev_priv(dev);
1949 skb = tlan_get_skb(list);
1958 list->
buffer[8].address = 0;
1959 list->
buffer[9].address = 0;
1965 skb = tlan_get_skb(list);
1967 pci_unmap_single(priv->
pci_dev,
1972 list->
buffer[8].address = 0;
1973 list->
buffer[9].address = 0;
2000 pr_info(
"Contents of internal registers for io base 0x%04hx\n",
2003 for (i = 0; i < 0x4C; i += 8) {
2004 data0 = tlan_dio_read32(io_base, i);
2005 data1 = tlan_dio_read32(io_base, i + 0x4);
2006 pr_info(
"0x%02x 0x%08x 0x%08x\n", i, data0, data1);
2031 static void tlan_print_list(
struct tlan_list *list,
char *type,
int num)
2035 pr_info(
"%s List %d at %p\n", type, num, list);
2040 for (i = 0; i < 2; i++) {
2041 pr_info(
" Buffer[%d].count, addr = 0x%08x, 0x%08x\n",
2070 u32 tx_good, tx_under;
2071 u32 rx_good, rx_over;
2073 u32 multi_col, single_col;
2074 u32 excess_col, late_col, loss;
2106 dev->
stats.rx_packets += rx_good;
2107 dev->
stats.rx_errors += rx_over + crc +
code;
2108 dev->
stats.tx_packets += tx_good;
2109 dev->
stats.tx_errors += tx_under + loss;
2110 dev->
stats.collisions += multi_col
2111 + single_col + excess_col + late_col;
2113 dev->
stats.rx_over_errors += rx_over;
2117 dev->
stats.tx_aborted_errors += tx_under;
2118 dev->
stats.tx_carrier_errors += loss;
2146 struct tlan_priv *priv = netdev_priv(dev);
2197 tlan_phy_detect(dev);
2202 if (priv->
aui == 1) {
2217 tlan_finish_reset(dev);
2219 tlan_phy_power_down(dev);
2229 struct tlan_priv *priv = netdev_priv(dev);
2237 u16 tlphy_id1, tlphy_id2;
2257 netdev_info(dev,
"Link forced\n");
2259 tlan_mii_read_reg(dev, phy,
MII_GEN_STS, &status);
2261 tlan_mii_read_reg(dev, phy,
MII_GEN_STS, &status);
2266 tlan_mii_read_reg(dev, phy,
MII_AN_LPA, &partner);
2270 "Link active with %s %uMbps %s-Duplex\n",
2272 ?
"forced" :
"Autonegotiation enabled,",
2279 netdev_info(dev,
"Partner capability:");
2280 for (i = 5; i < 10; i++)
2281 if (partner & (1 << i))
2294 }
else if (status & MII_GS_LINK) {
2295 netdev_info(dev,
"Link active\n");
2305 sio = tlan_dio_read8(dev->
base_addr, TLAN_NET_SIO);
2307 tlan_dio_write8(dev->
base_addr, TLAN_NET_SIO, sio);
2310 if (status & MII_GS_LINK) {
2311 tlan_set_mac(dev, 0, dev->
dev_addr);
2321 netdev_info(dev,
"Link inactive, will retry in 10 secs...\n");
2325 tlan_set_multicast_list(dev);
2353 static void tlan_set_mac(
struct net_device *dev,
int areg,
char *
mac)
2360 for (i = 0; i < 6; i++)
2364 for (i = 0; i < 6; i++)
2397 static void tlan_phy_print(
struct net_device *dev)
2399 struct tlan_priv *priv = netdev_priv(dev);
2405 netdev_info(dev,
"Unmanaged PHY\n");
2407 netdev_info(dev,
"PHY 0x%02x\n", phy);
2408 pr_info(
" Off. +0 +1 +2 +3\n");
2409 for (i = 0; i < 0x20; i += 4) {
2410 tlan_mii_read_reg(dev, phy, i, &data0);
2411 tlan_mii_read_reg(dev, phy, i + 1, &data1);
2412 tlan_mii_read_reg(dev, phy, i + 2, &data2);
2413 tlan_mii_read_reg(dev, phy, i + 3, &data3);
2414 pr_info(
" 0x%02x 0x%04hx 0x%04hx 0x%04hx 0x%04hx\n",
2415 i, data0, data1, data2, data3);
2418 netdev_info(dev,
"Invalid PHY\n");
2443 static void tlan_phy_detect(
struct net_device *dev)
2445 struct tlan_priv *priv = netdev_priv(dev);
2465 tlan_mii_read_reg(dev, phy,
MII_GEN_CTL, &control);
2468 if ((control != 0xffff) ||
2469 (hi != 0xffff) || (lo != 0xffff)) {
2471 "PHY found at %02x %04x %04x %04x\n",
2472 phy, control, hi, lo);
2485 netdev_info(dev,
"Cannot initialize device, no PHY was found!\n");
2492 static void tlan_phy_power_down(
struct net_device *dev)
2494 struct tlan_priv *priv = netdev_priv(dev);
2497 TLAN_DBG(TLAN_DEBUG_GNRL,
"%s: Powering down PHY(s).\n", dev->
name);
2519 static void tlan_phy_power_up(
struct net_device *dev)
2521 struct tlan_priv *priv = netdev_priv(dev);
2524 TLAN_DBG(TLAN_DEBUG_GNRL,
"%s: Powering up PHY.\n", dev->
name);
2540 static void tlan_phy_reset(
struct net_device *dev)
2542 struct tlan_priv *priv = netdev_priv(dev);
2548 TLAN_DBG(TLAN_DEBUG_GNRL,
"%s: Resetting PHY.\n", dev->
name);
2567 static void tlan_phy_start_link(
struct net_device *dev)
2569 struct tlan_priv *priv = netdev_priv(dev);
2578 TLAN_DBG(TLAN_DEBUG_GNRL,
"%s: Trying to activate link.\n", dev->
name);
2579 tlan_mii_read_reg(dev, phy,
MII_GEN_STS, &status);
2580 tlan_mii_read_reg(dev, phy,
MII_GEN_STS, &ability);
2584 ability = status >> 11;
2587 tlan_mii_write_reg(dev, phy,
MII_GEN_CTL, 0x0000);
2591 tlan_mii_write_reg(dev, phy,
MII_GEN_CTL, 0x0100);
2594 tlan_mii_write_reg(dev, phy,
MII_GEN_CTL, 0x2000);
2598 tlan_mii_write_reg(dev, phy,
MII_GEN_CTL, 0x2100);
2603 (ability << 5) | 1);
2605 tlan_mii_write_reg(dev, phy,
MII_GEN_CTL, 0x1000);
2607 tlan_mii_write_reg(dev, phy,
MII_GEN_CTL, 0x1200);
2613 netdev_info(dev,
"Starting autonegotiation\n");
2627 }
else if (priv->
phy_num == 0) {
2641 tlan_mii_write_reg(dev, phy,
MII_GEN_CTL, control);
2655 static void tlan_phy_finish_auto_neg(
struct net_device *dev)
2657 struct tlan_priv *priv = netdev_priv(dev);
2667 tlan_mii_read_reg(dev, phy,
MII_GEN_STS, &status);
2669 tlan_mii_read_reg(dev, phy,
MII_GEN_STS, &status);
2676 pr_info(
"Giving autonegotiation more time.\n");
2677 pr_info(
"Please check that your adapter has\n");
2678 pr_info(
"been properly connected to a HUB or Switch.\n");
2679 pr_info(
"Trying to establish link in the background...\n");
2685 netdev_info(dev,
"Autonegotiation complete\n");
2686 tlan_mii_read_reg(dev, phy,
MII_AN_ADV, &an_adv);
2687 tlan_mii_read_reg(dev, phy,
MII_AN_LPA, &an_lpa);
2688 mode = an_adv & an_lpa & 0x03E0;
2691 else if (!(mode & 0x0080) && (mode & 0x0040))
2694 if ((!(mode & 0x0180)) &&
2707 (an_adv & an_lpa & 0x0040)) {
2710 netdev_info(dev,
"Starting internal PHY with FULL-DUPLEX\n");
2714 netdev_info(dev,
"Starting internal PHY with HALF-DUPLEX\n");
2744 void tlan_phy_monitor(
struct net_device *dev)
2746 struct tlan_priv *priv = netdev_priv(dev);
2753 tlan_mii_read_reg(dev, phy,
MII_GEN_STS, &phy_status);
2756 if (!(phy_status & MII_GS_LINK)) {
2768 if ((phy_status & MII_GS_LINK) && !priv->
link) {
2826 struct tlan_priv *priv = netdev_priv(dev);
2827 unsigned long flags = 0;
2842 tlan_mii_send_data(dev->
base_addr, 0x1, 2);
2843 tlan_mii_send_data(dev->
base_addr, 0x2, 2);
2844 tlan_mii_send_data(dev->
base_addr, phy, 5);
2845 tlan_mii_send_data(dev->
base_addr, reg, 5);
2857 for (i = 0; i < 16; i++) {
2864 for (tmp = 0, i = 0x8000;
i; i >>= 1) {
2882 spin_unlock_irqrestore(&priv->
lock, flags);
2909 static void tlan_mii_send_data(
u16 base_port,
u32 data,
unsigned num_bits)
2921 for (i = (0x1 << (num_bits - 1));
i; i >>= 1) {
2951 static void tlan_mii_sync(
u16 base_port)
2960 for (i = 0; i < 32; i++) {
2995 unsigned long flags = 0;
2996 struct tlan_priv *priv = netdev_priv(dev);
3010 tlan_mii_send_data(dev->
base_addr, 0x1, 2);
3011 tlan_mii_send_data(dev->
base_addr, 0x1, 2);
3012 tlan_mii_send_data(dev->
base_addr, phy, 5);
3013 tlan_mii_send_data(dev->
base_addr, reg, 5);
3015 tlan_mii_send_data(dev->
base_addr, 0x2, 2);
3016 tlan_mii_send_data(dev->
base_addr, val, 16);
3025 spin_unlock_irqrestore(&priv->
lock, flags);
3061 static void tlan_ee_send_start(
u16 io_base)
3101 static int tlan_ee_send_byte(
u16 io_base,
u8 data,
int stop)
3111 for (place = 0x80; place != 0; place >>= 1) {
3125 if ((!err) && stop) {
3163 static void tlan_ee_receive_byte(
u16 io_base,
u8 *data,
int stop)
3174 for (place = 0x80; place; place >>= 1) {
3222 static int tlan_ee_read_byte(
struct net_device *dev,
u8 ee_addr,
u8 *data)
3225 struct tlan_priv *priv = netdev_priv(dev);
3226 unsigned long flags = 0;
3250 spin_unlock_irqrestore(&priv->
lock, flags);