12 #define pr_fmt(fmt) "tulip: " fmt
14 #define DRV_NAME "tulip"
15 #ifdef CONFIG_TULIP_NAPI
16 #define DRV_VERSION "1.1.15-NAPI"
18 #define DRV_VERSION "1.1.15"
20 #define DRV_RELDATE "Feb 27, 2007"
23 #include <linux/module.h>
24 #include <linux/pci.h>
25 #include <linux/slab.h>
31 #include <linux/mii.h>
33 #include <asm/unaligned.h>
34 #include <asm/uaccess.h>
46 static unsigned int max_interrupt_work = 25;
56 "10baseT",
"10base2",
"AUI",
"100baseTx",
57 "10baseT-FDX",
"100baseTx-FDX",
"100baseT4",
"100baseFx",
58 "100baseFx-FDX",
"MII 10baseT",
"MII 10baseT-FDX",
"MII",
59 "10baseT(forced)",
"MII 100baseTx",
"MII 100baseTx-FDX",
"MII 100baseT4",
60 "MII 100baseFx-HDX",
"MII 100baseFx-FDX",
"Home-PNA 1Mbps",
"Invalid-19",
61 "",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"Transceiver reset",
65 #if defined(__alpha__) || defined(__arm__) || defined(__hppa__) || \
66 defined(CONFIG_SPARC) || defined(__ia64__) || \
67 defined(__sh__) || defined(__mips__)
68 static int rx_copybreak = 1518;
70 static int rx_copybreak = 100;
86 #if defined(__alpha__) || defined(__ia64__)
87 static int csr0 = 0x01A00000 | 0xE000;
88 #elif defined(__i386__) || defined(__powerpc__) || defined(__x86_64__)
89 static int csr0 = 0x01A00000 | 0x8000;
90 #elif defined(CONFIG_SPARC) || defined(__hppa__)
95 static int csr0 = 0x01A00000 | 0x9000;
96 #elif defined(__arm__) || defined(__sh__)
97 static int csr0 = 0x01A00000 | 0x4800;
98 #elif defined(__mips__)
99 static int csr0 = 0x00200000 | 0x4000;
101 #warning Processor architecture undefined!
102 static int csr0 = 0x00A00000 | 0x4800;
107 #define TX_TIMEOUT (4*HZ)
127 static void tulip_timer(
unsigned long data)
132 if (netif_running(dev))
147 {
"Digital DS21140 Tulip", 128, 0x0001ebef,
152 {
"Digital DS21142/43 Tulip", 128, 0x0801fbff,
157 {
"Lite-On 82c168 PNIC", 256, 0x0001fbef,
161 {
"Macronix 98713 PMAC", 128, 0x0001ebef,
165 {
"Macronix 98715 PMAC", 256, 0x0001ebef,
169 {
"Macronix 98725 PMAC", 256, 0x0001ebef,
173 {
"ASIX AX88140", 128, 0x0001fbff,
178 {
"Lite-On PNIC-II", 256, 0x0801fbff,
182 {
"ADMtek Comet", 256, 0x0001abef,
186 {
"Compex 9881 PMAC", 128, 0x0001ebef,
190 {
"Intel DS21145 Tulip", 128, 0x0801fbff,
195 #ifdef CONFIG_TULIP_DM910X
196 {
"Davicom DM9102/DM9102A", 128, 0x0001ebef,
204 {
"Conexant LANfinity", 256, 0x0001ebef,
231 #ifdef CONFIG_TULIP_DM910X
257 {0,0,0,16, 3,19,16,24, 27,4,7,5, 0,20,23,20, 28,31,0,0, };
271 static void tulip_set_wolopts(
struct pci_dev *pdev,
u32 wolopts);
272 #ifdef CONFIG_NET_POLL_CONTROLLER
277 int sleep,
int snooze)
281 pci_read_config_dword (tp->
pdev,
CFDD, &tmp);
288 pci_write_config_dword (tp->
pdev,
CFDD, newtmp);
298 int next_tick = 3*
HZ;
302 #ifdef CONFIG_TULIP_NAPI
303 napi_enable(&tp->
napi);
307 tulip_set_power_state (tp, 0, 0);
312 tulip_set_wolopts(tp->
pdev, 0);
361 *setup_frm++ = eaddrs[0]; *setup_frm++ = eaddrs[0];
362 *setup_frm++ = eaddrs[1]; *setup_frm++ = eaddrs[1];
363 *setup_frm++ = eaddrs[2]; *setup_frm++ = eaddrs[2];
390 for (i = 0; i < tp->
mtable->leafcount; i++)
391 if (tp->
mtable->mleaf[i].media == looking_for) {
393 "Using user-specified media %s\n",
398 if ((tp->
mtable->defaultmedia & 0x0800) == 0) {
400 for (i = 0; i < tp->
mtable->leafcount; i++)
401 if (tp->
mtable->mleaf[i].media == looking_for) {
403 "Using EEPROM-set media %s\n",
409 for (i = tp->
mtable->leafcount - 1;
432 "Using MII transceiver %d, status %04x\n",
459 tp->
csr6 = 0x00420000;
472 tp->
csr6 = 0x01a80200;
479 tp->
csr6 = 0x00040000;
494 tulip_start_rxtx(tp);
498 netdev_dbg(dev,
"Done tulip_up(), CSR0 %08x, CSR5 %08x CSR6 %08x\n",
508 #ifdef CONFIG_TULIP_NAPI
521 tulip_init_ring (dev);
530 netif_start_queue (dev);
535 tulip_free_ring (dev);
540 static void tulip_tx_timeout(
struct net_device *dev)
552 "Transmit timeout using MII device\n");
557 "21140 transmit timed out, status %08x, SIA %08x %08x %08x %08x, resetting...\n",
566 "PNIC2 transmit timed out, status %08x, CSR6/7 %08x / %08x CSR12 %08x, resetting...\n",
573 "Transmit timed out, status %08x, CSR12 %08x, resetting...\n",
578 #if defined(way_too_many_messages)
585 "%2d: %08x %08x %08x %08x %02x %02x %02x\n",
587 (
unsigned int)tp->
rx_ring[i].status,
588 (
unsigned int)tp->
rx_ring[i].length,
589 (
unsigned int)tp->
rx_ring[i].buffer1,
590 (
unsigned int)tp->
rx_ring[i].buffer2,
591 buf[0], buf[1], buf[2]);
592 for (j = 0; buf[
j] != 0xee && j < 1600; j++)
607 tulip_tx_timeout_complete(tp, ioaddr);
610 spin_unlock_irqrestore (&tp->
lock, flags);
612 netif_wake_queue (dev);
617 static void tulip_init_ring(
struct net_device *dev)
647 mapping = pci_map_single(tp->
pdev, skb->
data,
681 mapping = pci_map_single(tp->
pdev, skb->
data,
694 netif_stop_queue(dev);
696 if (entry == TX_RING_SIZE-1)
710 spin_unlock_irqrestore(&tp->
lock, flags);
725 tp->
dev->stats.tx_errors++;
733 pci_unmap_single(tp->
pdev,
751 static void tulip_down (
struct net_device *dev)
759 #ifdef CONFIG_TULIP_NAPI
760 napi_disable(&tp->
napi);
764 #ifdef CONFIG_TULIP_NAPI
779 tulip_clean_tx_ring(tp);
784 spin_unlock_irqrestore (&tp->
lock, flags);
793 tulip_set_power_state (tp, 0, 1);
796 static void tulip_free_ring (
struct net_device *dev)
833 static int tulip_close (
struct net_device *dev)
838 netif_stop_queue (dev);
843 netdev_dbg(dev,
"Shutting down ethercard, status was %02x\n",
848 tulip_free_ring (dev);
858 if (netif_running(dev)) {
865 spin_unlock_irqrestore(&tp->
lock, flags);
881 static int tulip_ethtool_set_wol(
struct net_device *dev,
894 static void tulip_ethtool_get_wol(
struct net_device *dev,
906 .get_drvinfo = tulip_get_drvinfo,
907 .set_wol = tulip_ethtool_set_wol,
908 .get_wol = tulip_ethtool_get_wol,
917 const unsigned int phy_idx = 0;
918 int phy = tp->
phys[phy_idx] & 0x1f;
919 unsigned int regnum = data->
reg_num;
938 if (((csr14<<5) & 0x1000) ||
948 ((csr12&0x7000) == 0x5000 ? 0x20 : 0) +
949 ((csr12&0x06) == 6 ? 0 : 4);
956 ((csr14 >> 1) & 0x20) + 1;
957 data->
val_out |= ((csr14 >> 9) & 0x03C0);
960 default: data->
val_out = 0;
break;
970 if (data->
phy_id == phy) {
987 if ((value & 0x1200) == 0x1200) {
994 }
else if (regnum == 4)
1013 static void build_setup_frame_hash(
u16 *setup_frm,
struct net_device *dev)
1021 memset(hash_table, 0,
sizeof(hash_table));
1022 __set_bit_le(255, hash_table);
1027 __set_bit_le(index, hash_table);
1029 for (i = 0; i < 32; i++) {
1030 *setup_frm++ = hash_table[
i];
1031 *setup_frm++ = hash_table[
i];
1037 *setup_frm++ = eaddrs[0]; *setup_frm++ = eaddrs[0];
1038 *setup_frm++ = eaddrs[1]; *setup_frm++ = eaddrs[1];
1039 *setup_frm++ = eaddrs[2]; *setup_frm++ = eaddrs[2];
1042 static void build_setup_frame_perfect(
u16 *setup_frm,
struct net_device *dev)
1052 *setup_frm++ = *eaddrs; *setup_frm++ = *eaddrs++;
1053 *setup_frm++ = *eaddrs; *setup_frm++ = *eaddrs++;
1054 *setup_frm++ = *eaddrs; *setup_frm++ = *eaddrs++;
1062 *setup_frm++ = eaddrs[0]; *setup_frm++ = eaddrs[0];
1063 *setup_frm++ = eaddrs[1]; *setup_frm++ = eaddrs[1];
1064 *setup_frm++ = eaddrs[2]; *setup_frm++ = eaddrs[2];
1068 static void set_rx_mode(
struct net_device *dev)
1076 tp->
csr6 &= ~0x00D5;
1094 u32 mc_filter[2] = {0, 0};
1104 mc_filter[filterbit >> 5] |= 1 << (filterbit & 31);
1107 "Added filter for %pM %08x bit %d\n",
1128 unsigned long flags;
1129 u32 tx_flags = 0x08000000 | 192;
1136 tx_flags = 0x08400000 | 192;
1172 if (entry == TX_RING_SIZE-1)
1181 netif_stop_queue(dev);
1187 spin_unlock_irqrestore(&tp->
lock, flags);
1193 #ifdef CONFIG_TULIP_MWI
1205 tp->
csr0 = csr0 = 0;
1216 pci_read_config_word(pdev,
PCI_COMMAND, &pci_command);
1222 if ((csr0 & MWI) && (cache == 0)) {
1265 netdev_dbg(dev,
"MWI config cacheline=%d, csr0=%08x\n",
1275 static int tulip_uli_dm_quirk(
struct pci_dev *pdev)
1283 .ndo_open = tulip_open,
1284 .ndo_start_xmit = tulip_start_xmit,
1285 .ndo_tx_timeout = tulip_tx_timeout,
1286 .ndo_stop = tulip_close,
1287 .ndo_get_stats = tulip_get_stats,
1288 .ndo_do_ioctl = private_ioctl,
1289 .ndo_set_rx_mode = set_rx_mode,
1293 #ifdef CONFIG_NET_POLL_CONTROLLER
1294 .ndo_poll_controller = poll_tulip,
1309 static unsigned char last_phys_addr[6] = {0x00,
'L',
'i',
'n',
'u',
'x'};
1310 static int last_irq;
1311 static int multiport_cnt;
1314 unsigned char *ee_data;
1317 static int board_idx = -1;
1319 const char *chip_name = tulip_tbl[chip_idx].
chip_name;
1320 unsigned int eeprom_missing = 0;
1321 unsigned int force_csr0 = 0;
1336 pr_err(
"skipping LMC card\n");
1342 pr_err(
"skipping SBE T3E3 port\n");
1352 #ifdef CONFIG_TULIP_DM910X
1353 if (chip_idx ==
DM910X) {
1356 if (pdev->
vendor == 0x1282 && pdev->
device == 0x9100 &&
1358 pr_info(
"skipping early DM9100 with Crc bug (use dmfe)\n");
1362 dp = pci_device_to_OF_node(pdev);
1364 pr_info(
"skipping DM910x expansion card (use dmfe)\n");
1390 if ((csr0 & 0x3f00) == 0)
1396 csr0 &= ~0xfff10000;
1399 if (tulip_uli_dm_quirk(pdev)) {
1400 csr0 &= ~0x01f100ff;
1401 #if defined(CONFIG_SPARC)
1402 csr0 = (csr0 & ~0xff00) | 0xe000;
1411 pr_err(
"Cannot enable tulip board #%d, aborting\n", board_idx);
1418 pr_notice(
"Failed to set power state to D0\n");
1424 dev = alloc_etherdev (
sizeof (*tp));
1430 pr_err(
"%s: I/O region (0x%llx@0x%llx) too small, aborting\n",
1434 goto err_out_free_netdev;
1440 goto err_out_free_netdev;
1442 ioaddr = pci_iomap(pdev,
TULIP_BAR, tulip_tbl[chip_idx].io_size);
1445 goto err_out_free_res;
1451 tp = netdev_priv(dev);
1459 goto err_out_mtable;
1469 if (chip_idx ==
COMET ) {
1471 pci_read_config_dword (pdev, 0x80, &sig);
1472 if (sig == 0x09811317) {
1475 pr_info(
"%s: Enabled WOL support for AN983B\n",
1491 #ifdef CONFIG_TULIP_MWI
1493 tulip_mwi_config (pdev, dev);
1497 tulip_stop_rxtx(tp);
1513 chip_name =
"GSC DS21140 Tulip";
1529 for (i = 0; i < 3; i++) {
1530 int value, boguscnt = 100000;
1534 }
while (value < 0 && --boguscnt > 0);
1536 sum += value & 0xffff;
1538 }
else if (chip_idx ==
COMET) {
1542 for (i = 0; i < 6; i ++)
1548 int ee_max_addr = ((1 << ee_addr_size) - 1) *
sizeof(
u16);
1550 if (ee_max_addr >
sizeof(tp->
eeprom))
1551 ee_max_addr =
sizeof(tp->
eeprom);
1553 for (i = 0; i < ee_max_addr ; i +=
sizeof(
u16)) {
1555 ee_data[
i] = data & 0xff;
1556 ee_data[i + 1] = data >> 8;
1562 for (i = 0; i < 8; i ++)
1563 if (ee_data[i] != ee_data[16+i])
1567 if (ee_data[0x198] == 0x04 && ee_data[0x199] == 6)
1569 }
else if (ee_data[0] == 0xff && ee_data[1] == 0xff &&
1574 #ifdef CONFIG_MIPS_COBALT
1575 if ((pdev->
bus->number == 0) &&
1581 memcpy(ee_data + 16, ee_data, 8);
1586 if (ee_data[0] == 0x61 && ee_data[1] == 0x10) {
1588 ee_data[0] = ee_data[2];
1589 ee_data[1] = ee_data[3];
1597 for (i = 4; i >= 0; i -= 2) {
1598 ee_data[17 + i + 3] = ee_data[17 +
i];
1599 ee_data[16 + i + 5] = ee_data[16 +
i];
1604 for (i = 0; i < 6; i ++) {
1605 dev->
dev_addr[
i] = ee_data[i + sa_offset];
1606 sum += ee_data[i + sa_offset];
1614 for (i = 0; i < 6; i+=2) {
1626 if (sum == 0 || sum == 6*0xff) {
1627 #if defined(CONFIG_SPARC)
1628 struct device_node *dp = pci_device_to_OF_node(pdev);
1629 const unsigned char *
addr;
1633 for (i = 0; i < 5; i++)
1634 dev->
dev_addr[i] = last_phys_addr[i];
1635 dev->
dev_addr[i] = last_phys_addr[i] + 1;
1636 #
if defined(CONFIG_SPARC)
1638 if (addr && len == 6)
1641 #if defined(__i386__) || defined(__x86_64__)
1647 for (i = 0; i < 6; i++)
1648 last_phys_addr[i] = dev->
dev_addr[i];
1657 if (mtu[board_idx] > 0)
1658 dev->
mtu = mtu[board_idx];
1673 static const u16 media2advert[] = {
1674 0x20, 0x40, 0x03e0, 0x60, 0x80, 0x100, 0x200
1690 for (i = 0; i < tp->
mtable->leafcount; i++)
1691 if (tp->
mtable->mleaf[i].media == 11) {
1709 #ifdef CONFIG_TULIP_NAPI
1715 goto err_out_free_ring;
1717 pci_set_drvdata(pdev, dev);
1720 #ifdef CONFIG_TULIP_MMIO
1721 "%s rev %d at MMIO %#llx,%s %pM, IRQ %d\n",
1723 "%s rev %d at Port %#llx,%s %pM, IRQ %d\n",
1727 eeprom_missing ?
" EEPROM not present," :
"",
1787 tulip_set_power_state (tp, 0, 1);
1804 err_out_free_netdev:
1811 static void tulip_set_wolopts (
struct pci_dev *pdev,
u32 wolopts)
1813 struct net_device *dev = pci_get_drvdata(pdev);
1845 struct net_device *dev = pci_get_drvdata(pdev);
1851 if (!netif_running(dev))
1867 tulip_set_wolopts(pdev, tp->
wolinfo.wolopts);
1868 rc = pci_enable_wake(pdev, pstate, tp->
wolinfo.wolopts);
1870 pr_err(
"pci_enable_wake failed (%d)\n", rc);
1878 static int tulip_resume(
struct pci_dev *pdev)
1880 struct net_device *dev = pci_get_drvdata(pdev);
1892 if (!netif_running(dev))
1896 pr_err(
"pci_enable_device failed in resume\n");
1903 pr_err(
"request_irq failed in resume\n");
1917 tulip_set_wolopts(pdev, 0);
1921 if (netif_running(dev))
1932 struct net_device *dev = pci_get_drvdata (pdev);
1938 tp = netdev_priv(dev);
1948 pci_set_drvdata (pdev,
NULL);
1953 #ifdef CONFIG_NET_POLL_CONTROLLER
1960 static void poll_tulip (
struct net_device *dev)
1963 const int irq = tp->
pdev->irq;
1975 .id_table = tulip_pci_tbl,
1976 .probe = tulip_init_one,
1979 .suspend = tulip_suspend,
1980 .resume = tulip_resume,
1985 static int __init tulip_init (
void)
1996 return pci_register_driver(&tulip_driver);
2000 static void __exit tulip_cleanup (
void)