64 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
66 #define DRV_NAME "dmfe"
67 #define DRV_VERSION "1.36.4"
68 #define DRV_RELDATE "2002-01-17"
70 #include <linux/module.h>
71 #include <linux/kernel.h>
72 #include <linux/string.h>
74 #include <linux/ptrace.h>
75 #include <linux/errno.h>
78 #include <linux/pci.h>
81 #include <linux/netdevice.h>
83 #include <linux/ethtool.h>
88 #include <linux/bitops.h>
90 #include <asm/processor.h>
93 #include <asm/uaccess.h>
96 #ifdef CONFIG_TULIP_DM910X
102 #define PCI_DM9132_ID 0x91321282
103 #define PCI_DM9102_ID 0x91021282
104 #define PCI_DM9100_ID 0x91001282
105 #define PCI_DM9009_ID 0x90091282
107 #define DM9102_IO_SIZE 0x80
108 #define DM9102A_IO_SIZE 0x100
109 #define TX_MAX_SEND_CNT 0x1
110 #define TX_DESC_CNT 0x10
111 #define RX_DESC_CNT 0x20
112 #define TX_FREE_DESC_CNT (TX_DESC_CNT - 2)
113 #define TX_WAKE_DESC_CNT (TX_DESC_CNT - 3)
114 #define DESC_ALL_CNT (TX_DESC_CNT + RX_DESC_CNT)
115 #define TX_BUF_ALLOC 0x600
116 #define RX_ALLOC_SIZE 0x620
117 #define DM910X_RESET 1
118 #define CR0_DEFAULT 0x00E00000
119 #define CR6_DEFAULT 0x00080000
120 #define CR7_DEFAULT 0x180c1
121 #define CR15_DEFAULT 0x06
122 #define TDES0_ERR_MASK 0x4302
123 #define MAX_PACKET_SIZE 1514
124 #define DMFE_MAX_MULTICAST 14
125 #define RX_COPY_SIZE 100
126 #define MAX_CHECK_PACKET 0x8000
127 #define DM9801_NOISE_FLOOR 8
128 #define DM9802_NOISE_FLOOR 5
130 #define DMFE_WOL_LINKCHANGE 0x20000000
131 #define DMFE_WOL_SAMPLEPACKET 0x10000000
132 #define DMFE_WOL_MAGICPACKET 0x08000000
136 #define DMFE_100MHF 1
138 #define DMFE_100MFD 5
140 #define DMFE_1M_HPNA 0x10
142 #define DMFE_TXTH_72 0x400000
143 #define DMFE_TXTH_96 0x404000
144 #define DMFE_TXTH_128 0x0000
145 #define DMFE_TXTH_256 0x4000
146 #define DMFE_TXTH_512 0x8000
147 #define DMFE_TXTH_1K 0xC000
149 #define DMFE_TIMER_WUT (jiffies + HZ * 1)
150 #define DMFE_TX_TIMEOUT ((3*HZ)/2)
151 #define DMFE_TX_KICK (HZ/2)
153 #define dw32(reg, val) iowrite32(val, ioaddr + (reg))
154 #define dw16(reg, val) iowrite16(val, ioaddr + (reg))
155 #define dr32(reg) ioread32(ioaddr + (reg))
156 #define dr16(reg) ioread16(ioaddr + (reg))
157 #define dr8(reg) ioread8(ioaddr + (reg))
159 #define DMFE_DBUG(dbug_now, msg, value) \
161 if (dmfe_debug || (dbug_now)) \
163 (msg), (long) (value)); \
166 #define SHOW_MEDIA_TYPE(mode) \
167 pr_info("Change Speed to %sMhz %s duplex\n" , \
168 (mode & 1) ? "100":"10", \
169 (mode & 4) ? "full":"half");
173 #define CR9_SROM_READ 0x4800
175 #define CR9_SRCLK 0x2
176 #define CR9_CRDOUT 0x8
177 #define SROM_DATA_0 0x0
178 #define SROM_DATA_1 0x4
179 #define PHY_DATA_1 0x20000
180 #define PHY_DATA_0 0x00000
181 #define MDCLKH 0x10000
183 #define PHY_POWER_DOWN 0x800
185 #define SROM_V41_CODE 0x14
187 #define __CHK_IO_SIZE(pci_id, dev_rev) \
188 (( ((pci_id)==PCI_DM9132_ID) || ((dev_rev) >= 0x30) ) ? \
189 DM9102A_IO_SIZE: DM9102_IO_SIZE)
191 #define CHK_IO_SIZE(pci_dev) \
192 (__CHK_IO_SIZE(((pci_dev)->device << 16) | (pci_dev)->vendor, \
193 (pci_dev)->revision))
196 #define DEVICE net_device
298 static int dmfe_debug;
299 static unsigned char dmfe_media_mode =
DMFE_AUTO;
300 static u32 dmfe_cr6_user_set;
305 static unsigned char mode = 8;
306 static u8 chkmode = 1;
308 static u8 HPNA_rx_cmd;
309 static u8 HPNA_tx_cmd;
310 static u8 HPNA_NoiseFloor;
316 static int dmfe_open(
struct DEVICE *);
318 static int dmfe_stop(
struct DEVICE *);
319 static void dmfe_set_filter_mode(
struct DEVICE *);
320 static const struct ethtool_ops netdev_ethtool_ops;
321 static u16 read_srom_word(
void __iomem *,
int);
323 #ifdef CONFIG_NET_POLL_CONTROLLER
326 static void dmfe_descriptor_init(
struct net_device *);
327 static void allocate_rx_buffer(
struct net_device *);
329 static void send_filter_frame(
struct DEVICE *);
330 static void dm9132_id_table(
struct DEVICE *);
333 static void phy_write_1bit(
void __iomem *,
u32);
337 static void dmfe_timer(
unsigned long);
338 static inline u32 cal_CRC(
unsigned char *,
unsigned int,
u8);
342 static void dmfe_dynamic_reset(
struct DEVICE *);
344 static void dmfe_init_dm910x(
struct DEVICE *);
354 .ndo_open = dmfe_open,
355 .ndo_stop = dmfe_stop,
356 .ndo_start_xmit = dmfe_start_xmit,
357 .ndo_set_rx_mode = dmfe_set_filter_mode,
361 #ifdef CONFIG_NET_POLL_CONTROLLER
362 .ndo_poll_controller = poll_dmfe,
380 if (!printed_version++)
387 #ifdef CONFIG_TULIP_DM910X
393 pr_info(
"skipping on-board DM910x (use tulip)\n");
400 dev = alloc_etherdev(
sizeof(*db));
406 pr_warn(
"32-bit PCI DMA not available\n");
417 pr_err(
"I/O base is zero\n");
419 goto err_out_disable;
423 pr_err(
"Allocated I/O size too small\n");
425 goto err_out_disable;
438 pr_err(
"Failed to request PCI regions\n");
440 goto err_out_disable;
444 db = netdev_priv(dev);
458 goto err_out_free_desc;
468 db->
ioaddr = pci_iomap(pdev, 0, 0);
471 goto err_out_free_buf;
479 pci_set_drvdata(pdev, dev);
485 pci_read_config_dword(pdev, 0x50, &pci_pmr);
493 for (i = 0; i < 64; i++) {
499 for (i = 0; i < 6; i++)
506 dev_info(&dev->
dev,
"Davicom DM%04lx at pci%s, %pM, irq %d\n",
527 pci_set_drvdata(pdev,
NULL);
536 struct net_device *dev = pci_get_drvdata(pdev);
553 pci_set_drvdata(pdev,
NULL);
556 DMFE_DBUG(0,
"dmfe_remove_one() exit", 0);
565 static int dmfe_open(
struct DEVICE *dev)
601 dmfe_init_dm910x(dev);
604 netif_wake_queue(dev);
610 db->
timer.function = dmfe_timer;
624 static void dmfe_init_dm910x(
struct DEVICE *dev)
654 dmfe_set_phyxcer(db);
661 dmfe_descriptor_init(dev);
668 dm9132_id_table(dev);
670 send_filter_frame(dev);
708 netif_stop_queue(dev);
714 spin_unlock_irqrestore(&db->
lock, flags);
743 netif_wake_queue(dev);
746 spin_unlock_irqrestore(&db->
lock, flags);
761 static int dmfe_stop(
struct DEVICE *dev)
769 netif_stop_queue(dev);
783 dmfe_free_rxbuffer(db);
787 printk(
"FU:%lx EC:%lx LC:%lx NC:%lx LOC:%lx TXJT:%lx RESET:%lx RCR8:%lx FAL:%lx TT:%lx\n",
818 spin_unlock_irqrestore(&db->
lock, flags);
831 spin_unlock_irqrestore(&db->
lock, flags);
837 dmfe_rx_packet(dev, db);
841 allocate_rx_buffer(dev);
845 dmfe_free_tx_pkt(dev, db);
857 spin_unlock_irqrestore(&db->
lock, flags);
862 #ifdef CONFIG_NET_POLL_CONTROLLER
869 static void poll_dmfe (
struct net_device *dev)
872 const int irq = db->
pdev->irq;
877 dmfe_interrupt (irq, dev);
895 if (tdes0 & 0x80000000)
900 dev->stats.tx_packets++;
903 if ( tdes0 != 0x7fffffff ) {
904 dev->stats.collisions += (tdes0 >> 3) & 0xf;
907 dev->stats.tx_errors++;
909 if (tdes0 & 0x0002) {
946 netif_wake_queue(dev);
959 if (flag) crc = ~crc;
979 if (rdes0 & 0x80000000)
988 if ( (rdes0 & 0x300) != 0x300) {
991 DMFE_DBUG(0,
"Reuse SK buffer, rdes0", rdes0);
995 rxlen = ( (rdes0 >> 16) & 0x3fff) - 4;
998 if (rdes0 & 0x8000) {
1000 dev->stats.rx_errors++;
1002 dev->stats.rx_fifo_errors++;
1004 dev->stats.rx_crc_errors++;
1006 dev->stats.rx_length_errors++;
1009 if ( !(rdes0 & 0x8000) ||
1015 (cal_CRC(skb->
data, rxlen, 1) !=
1016 (*(
u32 *) (skb->
data+rxlen) ))) {
1024 ((newskb = netdev_alloc_skb(dev, rxlen + 2))
1029 skb_reserve(skb, 2);
1039 dev->stats.rx_packets++;
1040 dev->stats.rx_bytes +=
rxlen;
1044 DMFE_DBUG(0,
"Reuse SK buffer, rdes0", rdes0);
1059 static void dmfe_set_filter_mode(
struct DEVICE * dev)
1062 unsigned long flags;
1065 DMFE_DBUG(0,
"dmfe_set_filter_mode()", 0);
1072 spin_unlock_irqrestore(&db->
lock, flags);
1077 DMFE_DBUG(0,
"Pass all multicast address", mc_count);
1080 spin_unlock_irqrestore(&db->
lock, flags);
1084 DMFE_DBUG(0,
"Set multicast address", mc_count);
1086 dm9132_id_table(dev);
1088 send_filter_frame(dev);
1089 spin_unlock_irqrestore(&db->
lock, flags);
1096 static void dmfe_ethtool_get_drvinfo(
struct net_device *dev,
1106 static int dmfe_ethtool_set_wol(
struct net_device *dev,
1119 static void dmfe_ethtool_get_wol(
struct net_device *dev,
1129 static const struct ethtool_ops netdev_ethtool_ops = {
1130 .get_drvinfo = dmfe_ethtool_get_drvinfo,
1132 .set_wol = dmfe_ethtool_set_wol,
1133 .get_wol = dmfe_ethtool_get_wol,
1141 static void dmfe_timer(
unsigned long data)
1147 unsigned char tmp_cr12;
1148 unsigned long flags;
1150 int link_ok, link_ok_phy;
1166 spin_unlock_irqrestore(&db->
lock, flags);
1201 dmfe_dynamic_reset(dev);
1205 spin_unlock_irqrestore(&db->
lock, flags);
1228 link_ok = (tmp_cr12 & 0x43) ? 1 : 0;
1241 if (link_ok_phy != link_ok) {
1242 DMFE_DBUG (0,
"PHY and chip report different link status", 0);
1243 link_ok = link_ok | link_ok_phy;
1246 if ( !link_ok && netif_carrier_ok(dev)) {
1264 }
else if (!netif_carrier_ok(dev)) {
1274 dmfe_process_mode(db);
1281 dmfe_HPNA_remote_cmd_chk(db);
1287 spin_unlock_irqrestore(&db->
lock, flags);
1299 static void dmfe_dynamic_reset(
struct net_device *dev)
1304 DMFE_DBUG(0,
"dmfe_dynamic_reset()", 0);
1313 netif_stop_queue(dev);
1316 dmfe_free_rxbuffer(db);
1326 dmfe_init_dm910x(dev);
1329 netif_wake_queue(dev);
1339 DMFE_DBUG(0,
"dmfe_free_rxbuffer()", 0);
1376 static void dmfe_descriptor_init(
struct net_device *dev)
1382 unsigned char *tmp_buf;
1387 DMFE_DBUG(0,
"dmfe_descriptor_init()", 0);
1408 for (tmp_tx = db->
first_tx_desc, i = 0; i < TX_DESC_CNT; i++, tmp_tx++) {
1413 tmp_tx_dma +=
sizeof(
struct tx_desc);
1427 tmp_rx_dma +=
sizeof(
struct rx_desc);
1435 allocate_rx_buffer(dev);
1444 static void update_cr6(
u32 cr6_data,
void __iomem *ioaddr)
1448 cr6_tmp = cr6_data & ~0x2002;
1461 static void dm9132_id_table(
struct net_device *dev)
1467 u16 i, hash_table[4];
1470 for (i = 0; i < 3; i++) {
1471 dw16(0, addrptr[i]);
1476 memset(hash_table, 0,
sizeof(hash_table));
1479 hash_table[3] = 0x8000;
1483 u32 hash_val = cal_CRC((
char *)ha->addr, 6, 0) & 0x3f;
1485 hash_table[hash_val / 16] |= (
u16) 1 << (hash_val % 16);
1489 for (i = 0; i < 4; i++, ioaddr += 4)
1490 dw16(0, hash_table[i]);
1499 static void send_filter_frame(
struct net_device *dev)
1515 *suptr++ = addrptr[0];
1516 *suptr++ = addrptr[1];
1517 *suptr++ = addrptr[2];
1527 *suptr++ = addrptr[0];
1528 *suptr++ = addrptr[1];
1529 *suptr++ = addrptr[2];
1549 update_cr6(db->
cr6_data | 0x2000, ioaddr);
1563 static void allocate_rx_buffer(
struct net_device *dev)
1586 static void srom_clk_write(
void __iomem *ioaddr,
u32 data)
1588 static const u32 cmd[] = {
1620 for (i = 5; i >= 0; i--) {
1622 srom_clk_write(ioaddr, srom_data);
1628 for (i = 16; i > 0; i--) {
1631 srom_data = (srom_data << 1) |
1654 update_cr6(db->
cr6_data & ~0x40000, ioaddr);
1659 if ( (phy_mode & 0x24) == 0x24 ) {
1677 DMFE_DBUG(0,
"Link Failed :", phy_mode);
1727 if ( !(phy_reg & 0x01e0)) {
1770 if ( !(phy_reg & 0x1) ) {
1800 dw16(0x80 + offset * 4, phy_data);
1805 for (i = 0; i < 35; i++)
1817 for (i = 0x10; i > 0; i = i >> 1)
1818 phy_write_1bit(ioaddr,
1822 for (i = 0x10; i > 0; i = i >> 1)
1823 phy_write_1bit(ioaddr,
1828 phy_write_1bit(ioaddr, PHY_DATA_0);
1831 for ( i = 0x8000; i > 0; i >>= 1)
1832 phy_write_1bit(ioaddr,
1849 phy_data =
dr16(0x80 + offset * 4);
1854 for (i = 0; i < 35; i++)
1858 phy_write_1bit(ioaddr, PHY_DATA_0);
1863 phy_write_1bit(ioaddr, PHY_DATA_0);
1866 for (i = 0x10; i > 0; i = i >> 1)
1867 phy_write_1bit(ioaddr,
1871 for (i = 0x10; i > 0; i = i >> 1)
1872 phy_write_1bit(ioaddr,
1876 phy_read_1bit(ioaddr);
1879 for (phy_data = 0, i = 0; i < 16; i++) {
1881 phy_data |= phy_read_1bit(ioaddr);
1893 static void phy_write_1bit(
void __iomem *ioaddr,
u32 phy_data)
1908 static u16 phy_read_1bit(
void __iomem *ioaddr)
1914 phy_data = (
dr32(
DCR9) >> 19) & 0x1;
1928 char * srom = db->
srom;
1929 int dmfe_mode, tmp_reg;
1942 for (tmp_reg = 1; tmp_reg < 0x10; tmp_reg <<= 1) {
1944 case 0x1: db->
PHY_reg4 |= 0x0020;
break;
1945 case 0x2: db->
PHY_reg4 |= 0x0040;
break;
1946 case 0x4: db->
PHY_reg4 |= 0x0080;
break;
1947 case 0x8: db->
PHY_reg4 |= 0x0100;
break;
1956 case 0x2: dmfe_media_mode =
DMFE_10MFD;
break;
1964 if ( (SF_mode & 0x1) || (srom[43] & 0x80) )
1968 if ( (SF_mode & 0x2) || (srom[40] & 0x1) )
1972 if ( (SF_mode & 0x4) || (srom[40] & 0xe) )
1980 if (HPNA_rx_cmd == 0)
1984 if (HPNA_tx_cmd == 1)
2003 if ( ( tmp_reg & 0xfff0 ) == 0xb900 ) {
2009 dmfe_program_DM9801(db, tmp_reg);
2013 dmfe_program_DM9802(db);
2024 static void dmfe_program_DM9801(
struct dmfe_board_info * db,
int HPNA_rev)
2033 reg25 = ( (reg25 + HPNA_NoiseFloor) & 0xff) | 0xf000;
2038 reg25 = (reg25 & 0xff00) + HPNA_NoiseFloor;
2040 reg17 = (reg17 & 0xfff0) + HPNA_NoiseFloor + 3;
2047 reg25 = (reg25 & 0xff00) + HPNA_NoiseFloor - 5;
2049 reg17 = (reg17 & 0xfff0) + HPNA_NoiseFloor;
2069 phy_reg = ( phy_reg & 0xff00) + HPNA_NoiseFloor;
2086 case 0x00: phy_reg = 0x0a00;
break;
2087 case 0x20: phy_reg = 0x0900;
break;
2088 case 0x40: phy_reg = 0x0600;
break;
2089 case 0x60: phy_reg = 0x0500;
break;
2116 struct net_device *dev = pci_get_drvdata(pci_dev);
2133 dmfe_free_rxbuffer(db);
2136 pci_read_config_dword(pci_dev, 0x40, &tmp);
2144 pci_write_config_dword(pci_dev, 0x40, tmp);
2158 struct net_device *dev = pci_get_drvdata(pci_dev);
2165 dmfe_init_dm910x(dev);
2168 pci_read_config_dword(pci_dev, 0x40, &tmp);
2171 pci_write_config_dword(pci_dev, 0x40, tmp);
2182 #define dmfe_suspend NULL
2183 #define dmfe_resume NULL
2188 .id_table = dmfe_pci_tbl,
2189 .probe = dmfe_init_one,
2211 "Bit 0: 10/100Mbps, bit 2: duplex, bit 8: HomePNA");
2214 "(bit 0: VLAN, bit 1 Flow Control, bit 2: TX pause packet)");
2221 static int __init dmfe_init_module(
void)
2226 printed_version = 1;
2233 dmfe_cr6_user_set = cr6set;
2241 dmfe_media_mode =
mode;
2249 if (HPNA_rx_cmd > 1)
2251 if (HPNA_tx_cmd > 1)
2253 if (HPNA_NoiseFloor > 15)
2254 HPNA_NoiseFloor = 0;
2256 rc = pci_register_driver(&dmfe_driver);
2270 static void __exit dmfe_cleanup_module(
void)
2272 DMFE_DBUG(0,
"dmfe_clean_module() ", debug);