34 #define ENABLE_SMC_DEBUG_RX 0
35 #define ENABLE_SMC_DEBUG_TX 0
36 #define ENABLE_SMC_DEBUG_DMA 0
37 #define ENABLE_SMC_DEBUG_PKTS 0
38 #define ENABLE_SMC_DEBUG_MISC 0
39 #define ENABLE_SMC_DEBUG_FUNC 0
41 #define SMC_DEBUG_RX ((ENABLE_SMC_DEBUG_RX ? 1 : 0) << 0)
42 #define SMC_DEBUG_TX ((ENABLE_SMC_DEBUG_TX ? 1 : 0) << 1)
43 #define SMC_DEBUG_DMA ((ENABLE_SMC_DEBUG_DMA ? 1 : 0) << 2)
44 #define SMC_DEBUG_PKTS ((ENABLE_SMC_DEBUG_PKTS ? 1 : 0) << 3)
45 #define SMC_DEBUG_MISC ((ENABLE_SMC_DEBUG_MISC ? 1 : 0) << 4)
46 #define SMC_DEBUG_FUNC ((ENABLE_SMC_DEBUG_FUNC ? 1 : 0) << 5)
49 #define SMC_DEBUG ( SMC_DEBUG_RX | \
59 #include <linux/module.h>
60 #include <linux/kernel.h>
61 #include <linux/sched.h>
64 #include <linux/errno.h>
67 #include <linux/device.h>
70 #include <linux/ethtool.h>
71 #include <linux/mii.h>
74 #include <linux/netdevice.h>
89 static int tx_fifo_kb=8;
101 #define CARDNAME "smc911x"
109 #define DBG(n, args...) \
111 if (SMC_DEBUG & (n)) \
115 #define PRINTK(args...) printk(args)
117 #define DBG(n, args...) do { } while (0)
118 #define PRINTK(args...) printk(KERN_DEBUG args)
121 #if SMC_DEBUG_PKTS > 0
129 remainder = length % 16;
131 for (i = 0; i < lines ; i ++) {
133 for (cur = 0; cur < 8; cur++) {
137 printk(
"%02x%02x ", a, b);
141 for (i = 0; i < remainder/2 ; i++) {
145 printk(
"%02x%02x ", a, b);
150 #define PRINT_PKT(x...) do { } while (0)
155 #define SMC_ENABLE_INT(lp, x) do { \
156 unsigned int __mask; \
157 __mask = SMC_GET_INT_EN((lp)); \
159 SMC_SET_INT_EN((lp), __mask); \
163 #define SMC_DISABLE_INT(lp, x) do { \
164 unsigned int __mask; \
165 __mask = SMC_GET_INT_EN((lp)); \
167 SMC_SET_INT_EN((lp), __mask); \
189 }
while (--timeout && !reg);
191 PRINTK(
"%s: smc911x_reset timeout waiting for PM restore\n", dev->
name);
199 spin_unlock_irqrestore(&lp->
lock, flags);
209 PRINTK(
"%s: chip reset timeout, retrying...\n", dev->
name);
216 PRINTK(
"%s: smc911x_reset timeout waiting for reset\n", dev->
name);
226 PRINTK(
"%s: smc911x_reset timeout waiting for EEPROM busy\n", dev->
name);
249 #ifdef SMC_DYNAMIC_BUS_CONFIG
250 if (lp->
cfg.irq_polarity)
259 dev->
stats.tx_errors++;
260 dev->
stats.tx_aborted_errors++;
318 spin_unlock_irqrestore(&lp->
lock, flags);
324 static void smc911x_shutdown(
struct net_device *dev)
341 spin_unlock_irqrestore(&lp->
lock, flags);
344 static inline void smc911x_drop_pkt(
struct net_device *dev)
351 if (fifo_count <= 4) {
362 }
while (--timeout && reg);
364 PRINTK(
"%s: timeout waiting for RX fast forward\n", dev->
name);
375 static inline void smc911x_rcv(
struct net_device *dev)
383 dev->
name, __func__);
386 dev->
name, (status & 0x3fff0000) >> 16, status & 0xc000ffff);
390 dev->
stats.rx_errors++;
392 dev->
stats.rx_crc_errors++;
395 dev->
stats.rx_length_errors++;
397 dev->
stats.multicast++;
400 smc911x_drop_pkt(dev);
404 skb = netdev_alloc_skb(dev, pkt_len+32);
406 PRINTK(
"%s: Low memory, rcvd packet dropped.\n",
408 dev->
stats.rx_dropped++;
409 smc911x_drop_pkt(dev);
424 if (fifo & 0xFF) fifo--;
426 dev->
name, fifo & 0xff);
430 lp->rxdma_active = 1;
431 lp->current_rx_skb =
skb;
440 PRINT_PKT(data, ((pkt_len - 4) <= 64) ? pkt_len - 4 : 64);
443 dev->
stats.rx_packets++;
444 dev->
stats.rx_bytes += pkt_len-4;
452 static void smc911x_hardware_send_pkt(
struct net_device *dev)
456 unsigned int cmdA, cmdB,
len;
469 buf = (
char*)((
u32)(skb->
data) & ~0xF);
470 len = (skb->
len + 0xF + ((
u32)skb->
data & 0xF)) & ~0xF;
471 cmdA = (1<<24) | (((
u32)skb->
data & 0xF)<<16) |
475 buf = (
char*)((
u32)skb->
data & ~0x3);
476 len = (skb->
len + 3 + ((
u32)skb->
data & 3)) & ~0x3;
477 cmdA = (((
u32)skb->
data & 0x3) << 16) |
482 cmdB = (skb->
len << 16) | (skb->
len & 0x7FF);
484 DBG(
SMC_DEBUG_TX,
"%s: TX PKT LENGTH 0x%04x (%d) BUF 0x%p CMDA 0x%08x CMDB 0x%08x\n",
485 dev->
name, len, len, buf, cmdA, cmdB);
494 lp->current_tx_skb =
skb;
503 netif_wake_queue(dev);
521 dev->
name, __func__);
532 DBG(
SMC_DEBUG_TX,
"%s: Disabling data flow due to low FIFO space (%d)\n",
537 netif_stop_queue(dev);
548 printk(
"%s: No Tx free space %d < %d\n",
551 dev->
stats.tx_errors++;
552 dev->
stats.tx_dropped++;
553 spin_unlock_irqrestore(&lp->
lock, flags);
563 if (lp->txdma_active) {
566 netif_stop_queue(dev);
567 spin_unlock_irqrestore(&lp->
lock, flags);
571 lp->txdma_active = 1;
576 smc911x_hardware_send_pkt(dev);
577 spin_unlock_irqrestore(&lp->
lock, flags);
587 static void smc911x_tx(
struct net_device *dev)
593 dev->
name, __func__);
601 dev->
stats.tx_packets++;
602 dev->
stats.tx_bytes+=tx_status>>16;
604 dev->
name, (tx_status & 0xffff0000) >> 16,
605 tx_status & 0x0000ffff);
609 !(tx_status & 0x00000306))) {
610 dev->
stats.tx_errors++;
613 dev->
stats.collisions+=16;
614 dev->
stats.tx_aborted_errors++;
621 dev->
stats.tx_carrier_errors++;
624 dev->
stats.collisions++;
625 dev->
stats.tx_aborted_errors++;
639 unsigned int phydata;
644 __func__, phyaddr, phyreg, phydata);
658 __func__, phyaddr, phyreg, phydata);
667 static void smc911x_phy_detect(
struct net_device *dev)
705 for (phyaddr = 1; phyaddr < 32; ++
phyaddr) {
712 if (id1 != 0x0000 && id1 != 0xffff &&
713 id1 != 0x8000 && id2 != 0x0000 &&
714 id2 != 0xffff && id2 != 0x8000) {
716 lp->
mii.phy_id = phyaddr & 31;
735 dev->
name, id1, id2, lp->
mii.phy_id);
742 static int smc911x_phy_fixed(
struct net_device *dev)
745 int phyaddr = lp->
mii.phy_id;
788 static int smc911x_phy_reset(
struct net_device *dev,
int phy)
802 spin_unlock_irqrestore(&lp->
lock, flags);
803 for (timeout = 2; timeout; timeout--) {
807 spin_unlock_irqrestore(&lp->
lock, flags);
829 static void smc911x_phy_powerdown(
struct net_device *dev,
int phy)
848 static void smc911x_phy_check_media(
struct net_device *dev,
int init)
851 int phyaddr = lp->
mii.phy_id;
852 unsigned int bmcr,
cr;
860 if (lp->
mii.full_duplex) {
888 int phyaddr = lp->
mii.phy_id;
902 if (smc911x_phy_reset(dev, phyaddr)) {
903 printk(
"%s: PHY reset timed out\n", dev->
name);
917 if (lp->
mii.force_media) {
918 smc911x_phy_fixed(dev);
919 goto smc911x_phy_configure_exit;
926 smc911x_phy_fixed(dev);
927 goto smc911x_phy_configure_exit;
953 lp->
mii.advertising = my_ad_caps;
969 smc911x_phy_check_media(dev, 1);
971 smc911x_phy_configure_exit:
972 spin_unlock_irqrestore(&lp->
lock, flags);
981 static void smc911x_phy_interrupt(
struct net_device *dev)
984 int phyaddr = lp->
mii.phy_id;
992 smc911x_phy_check_media(dev, 0);
996 dev->
name, status & 0xffff);
1012 unsigned int rx_overrun=0,
cr, pkts;
1013 unsigned long flags;
1022 spin_unlock_irqrestore(&lp->
lock, flags);
1037 dev->
name, status, mask, status & ~mask);
1051 dev->
stats.rx_errors++;
1067 cr &= ~MAC_CR_RXEN_;
1070 dev->
stats.rx_errors++;
1071 dev->
stats.rx_fifo_errors++;
1078 cr &= ~MAC_CR_RXEN_;
1082 dev->
stats.rx_errors++;
1083 dev->
stats.rx_fifo_errors++;
1094 dev->
name, pkts, fifo & 0xFFFF );
1098 if (lp->rxdma_active){
1100 "%s: RX DMA active\n", dev->
name);
1103 fifo |= pkts & 0xFF;
1105 "%s: Setting RX stat FIFO threshold to %d\n",
1106 dev->
name, fifo & 0xff);
1120 if (!lp->txdma_active)
1122 netif_wake_queue(dev);
1129 "%s: Tx stat FIFO limit (%d) /GPT irq\n",
1144 DBG(
SMC_DEBUG_RX,
"%s: IRQ_CFG 0x%08x FIFO_INT 0x%08x RX_CFG 0x%08x\n",
1150 "Data FIFO Used 0x%04x Stat FIFO 0x%08x\n",
1163 smc911x_phy_interrupt(dev);
1166 }
while (--timeout);
1172 dev->
name, 8-timeout);
1174 spin_unlock_irqrestore(&lp->
lock, flags);
1181 smc911x_tx_dma_irq(
int dma,
void *data)
1185 struct sk_buff *skb = lp->current_tx_skb;
1186 unsigned long flags;
1192 SMC_DMA_ACK_IRQ(dev, dma);
1197 lp->current_tx_skb =
NULL;
1199 smc911x_hardware_send_pkt(dev);
1202 "%s: No pending Tx packets. DMA disabled\n", dev->
name);
1204 lp->txdma_active = 0;
1206 netif_wake_queue(dev);
1208 spin_unlock_irqrestore(&lp->
lock, flags);
1212 "%s: TX DMA irq completed\n", dev->
name);
1215 smc911x_rx_dma_irq(
int dma,
void *data)
1220 struct sk_buff *skb = lp->current_rx_skb;
1221 unsigned long flags;
1227 SMC_DMA_ACK_IRQ(dev, dma);
1230 lp->current_rx_skb =
NULL;
1233 dev->
stats.rx_packets++;
1242 lp->rxdma_active = 0;
1244 spin_unlock_irqrestore(&lp->
lock, flags);
1246 "%s: RX DMA irq completed. DMA RX FIFO PKTS %d\n",
1251 #ifdef CONFIG_NET_POLL_CONTROLLER
1256 static void smc911x_poll_controller(
struct net_device *dev)
1259 smc911x_interrupt(dev->
irq, dev);
1265 static void smc911x_timeout(
struct net_device *dev)
1269 unsigned long flags;
1276 spin_unlock_irqrestore(&lp->
lock, flags);
1278 dev->
name, status, mask);
1293 netif_wake_queue(dev);
1302 static void smc911x_set_multicast_list(
struct net_device *dev)
1305 unsigned int multicast_table[2];
1306 unsigned int mcr, update_multicast = 0;
1307 unsigned long flags;
1313 spin_unlock_irqrestore(&lp->
lock, flags);
1349 memset(multicast_table, 0,
sizeof(multicast_table));
1357 multicast_table[position>>5] |= 1 << (position&0x1f);
1364 update_multicast = 1;
1374 memset(multicast_table, 0,
sizeof(multicast_table));
1375 update_multicast = 1;
1380 if (update_multicast) {
1382 "%s: update mcast hash table 0x%08x 0x%08x\n",
1383 dev->
name, multicast_table[0], multicast_table[1]);
1387 spin_unlock_irqrestore(&lp->
lock, flags);
1408 if (!is_valid_ether_addr(dev->
dev_addr)) {
1409 PRINTK(
"%s: no valid ethernet hw addr\n", __func__);
1420 smc911x_enable(dev);
1422 netif_start_queue(dev);
1434 static int smc911x_close(
struct net_device *dev)
1440 netif_stop_queue(dev);
1444 smc911x_shutdown(dev);
1451 smc911x_phy_powerdown(dev, lp->
mii.phy_id);
1470 unsigned long flags;
1479 spin_unlock_irqrestore(&lp->
lock, flags);
1486 ethtool_cmd_speed_set(cmd,
SPEED_10);
1491 if (lp->
mii.phy_id==1)
1511 unsigned long flags;
1516 spin_unlock_irqrestore(&lp->
lock, flags);
1540 static int smc911x_ethtool_nwayreset(
struct net_device *dev)
1544 unsigned long flags;
1549 spin_unlock_irqrestore(&lp->
lock, flags);
1555 static u32 smc911x_ethtool_getmsglevel(
struct net_device *dev)
1567 static int smc911x_ethtool_getregslen(
struct net_device *dev)
1574 static void smc911x_ethtool_getregs(
struct net_device *dev,
1578 unsigned long flags;
1589 spin_unlock_irqrestore(&lp->
lock, flags);
1592 for(i=0;i<=31;i++) {
1595 spin_unlock_irqrestore(&lp->
lock, flags);
1596 data[j++] = reg & 0xFFFF;
1600 static int smc911x_ethtool_wait_eeprom_ready(
struct net_device *dev)
1603 unsigned int timeout;
1609 PRINTK(
"%s: %s timeout waiting for EEPROM to respond\n",
1610 dev->
name, __func__);
1617 PRINTK(
"%s: %s timeout waiting for EEPROM CMD not busy\n",
1618 dev->
name, __func__);
1624 static inline int smc911x_ethtool_write_eeprom_cmd(
struct net_device *dev,
1630 if ((ret = smc911x_ethtool_wait_eeprom_ready(dev))!=0)
1633 ((cmd) & (0x7<<28)) |
1638 static inline int smc911x_ethtool_read_eeprom_byte(
struct net_device *dev,
1644 if ((ret = smc911x_ethtool_wait_eeprom_ready(dev))!=0)
1650 static inline int smc911x_ethtool_write_eeprom_byte(
struct net_device *dev,
1656 if ((ret = smc911x_ethtool_wait_eeprom_ready(dev))!=0)
1662 static int smc911x_ethtool_geteeprom(
struct net_device *dev,
1671 if ((ret=smc911x_ethtool_read_eeprom_byte(dev, &eebuf[i]))!=0)
1678 static int smc911x_ethtool_seteeprom(
struct net_device *dev,
1691 if ((ret=smc911x_ethtool_write_eeprom_byte(dev, *data))!=0)
1699 static int smc911x_ethtool_geteeprom_len(
struct net_device *dev)
1704 static const struct ethtool_ops smc911x_ethtool_ops = {
1705 .get_settings = smc911x_ethtool_getsettings,
1706 .set_settings = smc911x_ethtool_setsettings,
1707 .get_drvinfo = smc911x_ethtool_getdrvinfo,
1708 .get_msglevel = smc911x_ethtool_getmsglevel,
1709 .set_msglevel = smc911x_ethtool_setmsglevel,
1710 .nway_reset = smc911x_ethtool_nwayreset,
1712 .get_regs_len = smc911x_ethtool_getregslen,
1713 .get_regs = smc911x_ethtool_getregs,
1714 .get_eeprom_len = smc911x_ethtool_geteeprom_len,
1715 .get_eeprom = smc911x_ethtool_geteeprom,
1716 .set_eeprom = smc911x_ethtool_seteeprom,
1750 }
while (--timeout);
1767 .ndo_open = smc911x_open,
1768 .ndo_stop = smc911x_close,
1769 .ndo_start_xmit = smc911x_hard_start_xmit,
1770 .ndo_tx_timeout = smc911x_timeout,
1771 .ndo_set_rx_mode = smc911x_set_multicast_list,
1775 #ifdef CONFIG_NET_POLL_CONTROLLER
1776 .ndo_poll_controller = smc911x_poll_controller,
1809 unsigned long irq_flags;
1816 if (val != 0x87654321) {
1829 for(i=0;chip_ids[
i].id != 0; i++) {
1830 if (chip_ids[i].
id == chip_id)
break;
1832 if (!chip_ids[i].
id) {
1837 version_string = chip_ids[
i].name;
1899 PRINTK(
"%s: ERROR -- no AFC_CFG setting found",
1905 "%s: tx_fifo %d rx_fifo %d afc_cfg 0x%08x\n",
CARDNAME,
1928 dev->
irq = smc911x_findirq(dev);
1935 if (dev->
irq == 0) {
1936 printk(
"%s: Couldn't autodetect your IRQ. Use irq=xx.\n",
1951 lp->
mii.phy_id_mask = 0x1f;
1952 lp->
mii.reg_num_mask = 0x1f;
1953 lp->
mii.force_media = 0;
1954 lp->
mii.full_duplex = 0;
1956 lp->
mii.mdio_read = smc911x_phy_read;
1957 lp->
mii.mdio_write = smc911x_phy_write;
1962 smc911x_phy_detect(dev);
1969 #ifdef SMC_DYNAMIC_BUS_CONFIG
1970 irq_flags = lp->
cfg.irq_flags;
1977 irq_flags, dev->
name, dev);
1982 lp->rxdma = SMC_DMA_REQUEST(dev, smc911x_rx_dma_irq);
1983 lp->txdma = SMC_DMA_REQUEST(dev, smc911x_tx_dma_irq);
1984 lp->rxdma_active = 0;
1985 lp->txdma_active = 0;
1986 dev->
dma = lp->rxdma;
1992 printk(
"%s: %s (rev %d) at %#lx IRQ %d",
1997 if (lp->rxdma != -1)
1998 printk(
" RXDMA %d ", lp->rxdma);
2000 if (lp->txdma != -1)
2001 printk(
"TXDMA %d", lp->txdma);
2004 if (!is_valid_ether_addr(dev->
dev_addr)) {
2005 printk(
"%s: Invalid ethernet MAC address. Please "
2006 "set using ifconfig\n", dev->
name);
2009 printk(
"%s: Ethernet addr: %pM\n",
2016 PRINTK(
"%s: LAN911x Internal PHY\n", dev->
name);
2025 if (lp->rxdma != -1) {
2026 SMC_DMA_FREE(dev, lp->rxdma);
2028 if (lp->txdma != -1) {
2029 SMC_DMA_FREE(dev, lp->txdma);
2073 ndev->
dma = (
unsigned char)-1;
2075 lp = netdev_priv(ndev);
2077 #ifdef SMC_DYNAMIC_BUS_CONFIG
2094 platform_set_drvdata(pdev, ndev);
2097 ret = smc911x_probe(ndev);
2099 platform_set_drvdata(pdev,
NULL);
2110 lp->physaddr = res->
start;
2111 lp->dev = &pdev->
dev;
2120 struct net_device *ndev = platform_get_drvdata(pdev);
2125 platform_set_drvdata(pdev,
NULL);
2133 if (lp->rxdma != -1) {
2134 SMC_DMA_FREE(dev, lp->rxdma);
2136 if (lp->txdma != -1) {
2137 SMC_DMA_FREE(dev, lp->txdma);
2151 struct net_device *ndev = platform_get_drvdata(dev);
2156 if (netif_running(ndev)) {
2158 smc911x_shutdown(ndev);
2170 struct net_device *ndev = platform_get_drvdata(dev);
2176 if (netif_running(ndev)) {
2177 smc911x_reset(ndev);
2180 smc911x_enable(ndev);
2188 .probe = smc911x_drv_probe,
2190 .suspend = smc911x_drv_suspend,
2191 .resume = smc911x_drv_resume,