15 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
17 #define DRV_NAME "uli526x"
18 #define DRV_VERSION "0.9.3"
19 #define DRV_RELDATE "2005-7-29"
21 #include <linux/module.h>
23 #include <linux/kernel.h>
24 #include <linux/string.h>
26 #include <linux/errno.h>
29 #include <linux/pci.h>
31 #include <linux/netdevice.h>
33 #include <linux/ethtool.h>
38 #include <linux/bitops.h>
40 #include <asm/processor.h>
43 #include <asm/uaccess.h>
45 #define uw32(reg, val) iowrite32(val, ioaddr + (reg))
46 #define ur32(reg) ioread32(ioaddr + (reg))
49 #define PCI_ULI5261_ID 0x526110B9
50 #define PCI_ULI5263_ID 0x526310B9
52 #define ULI526X_IO_SIZE 0x100
53 #define TX_DESC_CNT 0x20
54 #define RX_DESC_CNT 0x30
55 #define TX_FREE_DESC_CNT (TX_DESC_CNT - 2)
56 #define TX_WAKE_DESC_CNT (TX_DESC_CNT - 3)
57 #define DESC_ALL_CNT (TX_DESC_CNT + RX_DESC_CNT)
58 #define TX_BUF_ALLOC 0x600
59 #define RX_ALLOC_SIZE 0x620
60 #define ULI526X_RESET 1
62 #define CR6_DEFAULT 0x22200000
63 #define CR7_DEFAULT 0x180c1
64 #define CR15_DEFAULT 0x06
65 #define TDES0_ERR_MASK 0x4302
66 #define MAX_PACKET_SIZE 1514
67 #define ULI5261_MAX_MULTICAST 14
68 #define RX_COPY_SIZE 100
69 #define MAX_CHECK_PACKET 0x8000
71 #define ULI526X_10MHF 0
72 #define ULI526X_100MHF 1
73 #define ULI526X_10MFD 4
74 #define ULI526X_100MFD 5
75 #define ULI526X_AUTO 8
77 #define ULI526X_TXTH_72 0x400000
78 #define ULI526X_TXTH_96 0x404000
79 #define ULI526X_TXTH_128 0x0000
80 #define ULI526X_TXTH_256 0x4000
81 #define ULI526X_TXTH_512 0x8000
82 #define ULI526X_TXTH_1K 0xC000
84 #define ULI526X_TIMER_WUT (jiffies + HZ * 1)
85 #define ULI526X_TX_TIMEOUT ((16*HZ)/2)
86 #define ULI526X_TX_KICK (4*HZ/2)
88 #define ULI526X_DBUG(dbug_now, msg, value) \
90 if (uli526x_debug || (dbug_now)) \
91 pr_err("%s %lx\n", (msg), (long) (value)); \
94 #define SHOW_MEDIA_TYPE(mode) \
95 pr_err("Change Speed to %sMhz %s duplex\n", \
96 mode & 1 ? "100" : "10", \
97 mode & 4 ? "full" : "half");
101 #define CR9_SROM_READ 0x4800
103 #define CR9_SRCLK 0x2
104 #define CR9_CRDOUT 0x8
105 #define SROM_DATA_0 0x0
106 #define SROM_DATA_1 0x4
107 #define PHY_DATA_1 0x20000
108 #define PHY_DATA_0 0x00000
109 #define MDCLKH 0x10000
111 #define PHY_POWER_DOWN 0x800
113 #define SROM_V41_CODE 0x14
211 static int uli526x_debug;
213 static u32 uli526x_cr6_user_set;
225 static void uli526x_set_filter_mode(
struct net_device *);
226 static const struct ethtool_ops netdev_ethtool_ops;
229 #ifdef CONFIG_NET_POLL_CONTROLLER
233 static void allocate_rx_buffer(
struct net_device *);
235 static void send_filter_frame(
struct net_device *,
int);
244 static void uli526x_timer(
unsigned long);
248 static void uli526x_dynamic_reset(
struct net_device *);
250 static void uli526x_init(
struct net_device *);
268 .ndo_open = uli526x_open,
269 .ndo_stop = uli526x_stop,
270 .ndo_start_xmit = uli526x_start_xmit,
271 .ndo_set_rx_mode = uli526x_set_filter_mode,
275 #ifdef CONFIG_NET_POLL_CONTROLLER
276 .ndo_poll_controller = uli526x_poll,
294 if (!printed_version++)
298 dev = alloc_etherdev(
sizeof(*db));
304 pr_warn(
"32-bit PCI DMA not available\n");
315 pr_err(
"I/O base is zero\n");
317 goto err_out_disable;
321 pr_err(
"Allocated I/O size too small\n");
323 goto err_out_disable;
328 pr_err(
"Failed to request PCI regions\n");
329 goto err_out_disable;
333 db = netdev_priv(dev);
340 goto err_out_release;
344 goto err_out_free_tx_desc;
353 db->
phy.write = phy_writeby_cr10;
354 db->
phy.read = phy_readby_cr10;
357 db->
phy.write = phy_writeby_cr9;
358 db->
phy.read = phy_readby_cr9;
363 ioaddr = pci_iomap(pdev, 0, 0);
365 goto err_out_free_tx_buf;
371 pci_set_drvdata(pdev, dev);
381 for (i = 0; i < 64; i++)
395 for (i = 0; i < 6; i++)
404 for (i = 0; i < 6; i++)
411 netdev_info(dev,
"ULi M%04lx at pci%s, %pM, irq %d\n",
424 err_out_free_tx_desc:
432 pci_set_drvdata(pdev,
NULL);
441 struct net_device *dev = pci_get_drvdata(pdev);
453 pci_set_drvdata(pdev,
NULL);
463 static int uli526x_open(
struct net_device *dev)
494 netif_wake_queue(dev);
500 db->
timer.function = uli526x_timer;
514 static void uli526x_init(
struct net_device *dev)
517 struct uli_phy_ops *
phy = &db->
phy;
534 for (phy_tmp = 0; phy_tmp < 32; phy_tmp++) {
537 phy_value = phy->read(db, phy_tmp, 3);
538 if (phy_value != 0xffff && phy_value != 0) {
545 pr_warn(
"Can not find the phy address!!!\n");
550 phy_reg_reset = phy->read(db, db->
phy_addr, 0);
551 phy_reg_reset = (phy_reg_reset | 0x8000);
552 phy->write(db, db->
phy_addr, 0, phy_reg_reset);
559 while (timeout-- && phy->read(db, db->
phy_addr, 0) & 0x8000)
563 uli526x_set_phyxcer(db);
570 uli526x_descriptor_init(dev, ioaddr);
607 netif_stop_queue(dev);
611 netdev_err(dev,
"big packet = %d\n", (
u16)skb->
len);
620 spin_unlock_irqrestore(&db->
lock, flags);
646 netif_wake_queue(dev);
649 spin_unlock_irqrestore(&db->
lock, flags);
664 static int uli526x_stop(
struct net_device *dev)
670 netif_stop_queue(dev);
684 uli526x_free_rxbuffer(db);
711 spin_unlock_irqrestore(&db->
lock, flags);
721 spin_unlock_irqrestore(&db->
lock, flags);
727 uli526x_rx_packet(dev, db);
731 allocate_rx_buffer(dev);
735 uli526x_free_tx_pkt(dev, db);
740 spin_unlock_irqrestore(&db->
lock, flags);
744 #ifdef CONFIG_NET_POLL_CONTROLLER
745 static void uli526x_poll(
struct net_device *dev)
750 uli526x_interrupt(db->
pdev->irq, dev);
758 static void uli526x_free_tx_pkt(
struct net_device *dev,
767 if (tdes0 & 0x80000000)
772 dev->
stats.tx_packets++;
775 if ( tdes0 != 0x7fffffff ) {
776 dev->
stats.collisions += (tdes0 >> 3) & 0xf;
779 dev->
stats.tx_errors++;
780 if (tdes0 & 0x0002) {
808 netif_wake_queue(dev);
827 if (rdes0 & 0x80000000)
836 if ( (rdes0 & 0x300) != 0x300) {
843 rxlen = ( (rdes0 >> 16) & 0x3fff) - 4;
846 if (rdes0 & 0x8000) {
848 dev->
stats.rx_errors++;
850 dev->
stats.rx_fifo_errors++;
852 dev->
stats.rx_crc_errors++;
854 dev->
stats.rx_length_errors++;
857 if ( !(rdes0 & 0x8000) ||
866 (((new_skb = netdev_alloc_skb(dev, rxlen + 2)) !=
NULL))) {
879 dev->
stats.rx_packets++;
900 static void uli526x_set_filter_mode(
struct net_device * dev)
912 spin_unlock_irqrestore(&db->
lock, flags);
922 spin_unlock_irqrestore(&db->
lock, flags);
928 spin_unlock_irqrestore(&db->
lock, flags);
954 ethtool_cmd_speed_set(ecmd,
SPEED_10);
967 ethtool_cmd_speed_set(ecmd, -1);
977 static void netdev_get_drvinfo(
struct net_device *dev,
990 ULi_ethtool_gset(np, cmd);
1010 static const struct ethtool_ops netdev_ethtool_ops = {
1011 .get_drvinfo = netdev_get_drvinfo,
1012 .get_settings = netdev_get_settings,
1013 .get_link = netdev_get_link,
1014 .get_wol = uli526x_get_wol,
1022 static void uli526x_timer(
unsigned long data)
1026 struct uli_phy_ops *phy = &db->
phy;
1028 unsigned long flags;
1053 netdev_err(dev,
" Tx timeout - resetting\n");
1060 uli526x_dynamic_reset(dev);
1063 spin_unlock_irqrestore(&db->
lock, flags);
1068 if ((phy->read(db, db->
phy_addr, 5) & 0x01e0)!=0)
1075 netdev_info(dev,
"NIC Link is Down\n");
1081 phy->write(db, db->
phy_addr, 0, 0x1000);
1095 uli526x_sense_speed(db) )
1097 uli526x_process_mode(db);
1101 netdev_info(dev,
"NIC Link is Up %d Mbps %s duplex\n",
1116 netdev_info(dev,
"NIC Link is Down\n");
1125 spin_unlock_irqrestore(&db->
lock, flags);
1135 static void uli526x_reset_prepare(
struct net_device *dev)
1147 netif_stop_queue(dev);
1150 uli526x_free_rxbuffer(db);
1169 static void uli526x_dynamic_reset(
struct net_device *dev)
1173 uli526x_reset_prepare(dev);
1179 netif_wake_queue(dev);
1191 struct net_device *dev = pci_get_drvdata(pdev);
1197 if (!netdev_priv(dev))
1202 if (!netif_running(dev))
1206 uli526x_reset_prepare(dev);
1209 pci_enable_wake(pdev, power_state, 0);
1216 netif_wake_queue(dev);
1228 struct net_device *dev = pci_get_drvdata(pdev);
1233 if (!netdev_priv(dev))
1238 if (!netif_running(dev))
1243 netdev_warn(dev,
"Could not put device into D0\n");
1251 netif_wake_queue(dev);
1258 #define uli526x_suspend NULL
1259 #define uli526x_resume NULL
1292 skb_tail_pointer(skb),
1309 static void uli526x_descriptor_init(
struct net_device *dev,
void __iomem *ioaddr)
1314 unsigned char *tmp_buf;
1337 for (tmp_tx = db->
first_tx_desc, i = 0; i < TX_DESC_CNT; i++, tmp_tx++) {
1342 tmp_tx_dma +=
sizeof(
struct tx_desc);
1356 tmp_rx_dma +=
sizeof(
struct rx_desc);
1364 allocate_rx_buffer(dev);
1372 static void update_cr6(
u32 cr6_data,
void __iomem *ioaddr)
1385 #define FLT_SHIFT 16
1390 static void send_filter_frame(
struct net_device *dev,
int mc_cnt)
1419 *suptr++ = addrptr[0] << FLT_SHIFT;
1420 *suptr++ = addrptr[1] << FLT_SHIFT;
1421 *suptr++ = addrptr[2] << FLT_SHIFT;
1439 update_cr6(db->
cr6_data | 0x2000, ioaddr);
1444 netdev_err(dev,
"No Tx resource - Send_filter_frame!\n");
1453 static void allocate_rx_buffer(
struct net_device *dev)
1467 skb_tail_pointer(skb),
1499 for (i = 5; i >= 0; i--) {
1501 srom_clk_write(db, srom_data);
1506 for (i = 16; i > 0; i--) {
1509 srom_data = (srom_data << 1) |
1526 struct uli_phy_ops *phy = &db->
phy;
1530 phy_mode = phy->read(db, db->
phy_addr, 1);
1531 phy_mode = phy->read(db, db->
phy_addr, 1);
1533 if ( (phy_mode & 0x24) == 0x24 ) {
1535 phy_mode = ((phy->read(db, db->
phy_addr, 5) & 0x01e0)<<7);
1538 else if(phy_mode&0x4000)
1540 else if(phy_mode&0x2000)
1570 struct uli_phy_ops *phy = &db->
phy;
1574 phy_reg = phy->read(db, db->
phy_addr, 4) & ~0x01e0;
1591 if ( !(phy_reg & 0x01e0)) {
1595 phy->write(db, db->
phy_addr, 4, phy_reg);
1598 phy->write(db, db->
phy_addr, 0, 0x1200);
1612 struct uli_phy_ops *phy = &db->
phy;
1626 phy_reg = phy->read(db, db->
phy_addr, 6);
1627 if (!(phy_reg & 0x1)) {
1636 phy->write(db, db->
phy_addr, 0, phy_reg);
1644 u8 offset,
u16 phy_data)
1649 for (i = 0; i < 35; i++)
1661 for (i = 0x10; i > 0; i = i >> 1)
1665 for (i = 0x10; i > 0; i = i >> 1)
1666 phy_write_1bit(db, offset & i ?
PHY_DATA_1 : PHY_DATA_0);
1670 phy_write_1bit(db, PHY_DATA_0);
1673 for (i = 0x8000; i > 0; i >>= 1)
1674 phy_write_1bit(db, phy_data & i ?
PHY_DATA_1 : PHY_DATA_0);
1683 for (i = 0; i < 35; i++)
1687 phy_write_1bit(db, PHY_DATA_0);
1692 phy_write_1bit(db, PHY_DATA_0);
1695 for (i = 0x10; i > 0; i = i >> 1)
1696 phy_write_1bit(db, phy_addr & i ?
PHY_DATA_1 : PHY_DATA_0);
1699 for (i = 0x10; i > 0; i = i >> 1)
1700 phy_write_1bit(db, offset & i ?
PHY_DATA_1 : PHY_DATA_0);
1706 for (phy_data = 0, i = 0; i < 16; i++) {
1708 phy_data |= phy_read_1bit(db);
1718 u32 cr10_value = phy_addr;
1720 cr10_value = (cr10_value << 5) + offset;
1721 cr10_value = (cr10_value << 16) + 0x08000000;
1726 if (cr10_value & 0x10000000)
1729 return cr10_value & 0x0ffff;
1733 u8 offset,
u16 phy_data)
1736 u32 cr10_value = phy_addr;
1738 cr10_value = (cr10_value << 5) + offset;
1739 cr10_value = (cr10_value << 16) + 0x04000000 + phy_data;
1771 phy_data = (
ur32(
DCR9) >> 19) & 0x1;
1789 .id_table = uli526x_pci_tbl,
1790 .probe = uli526x_init_one,
1804 MODULE_PARM_DESC(mode,
"ULi M5261/M5263: Bit 0: 10/100Mbps, bit 2: duplex, bit 8: HomePNA");
1811 static int __init uli526x_init_module(
void)
1815 printed_version = 1;
1820 uli526x_debug =
debug;
1822 uli526x_cr6_user_set = cr6set;
1829 uli526x_media_mode =
mode;
1836 return pci_register_driver(&uli526x_driver);
1846 static void __exit uli526x_cleanup_module(
void)