70 #include <linux/module.h>
71 #include <linux/kernel.h>
72 #include <linux/sched.h>
76 #include <linux/errno.h>
81 #include <linux/ethtool.h>
82 #include <linux/mii.h>
86 #include <linux/netdevice.h>
116 #define CARDNAME "smc91x"
128 #define MEMORY_WAIT_TIME 16
134 #define MAX_IRQ_LOOPS 8
143 #define THROTTLE_TX_PKTS 0
152 #define DBG(n, args...) \
154 if (SMC_DEBUG >= (n)) \
158 #define PRINTK(args...) printk(args)
160 #define DBG(n, args...) do { } while(0)
161 #define PRINTK(args...) printk(KERN_DEBUG args)
172 remainder = length % 16;
174 for (i = 0; i < lines ; i ++) {
176 for (cur = 0; cur < 8; cur++) {
180 printk(
"%02x%02x ", a, b);
184 for (i = 0; i < remainder/2 ; i++) {
188 printk(
"%02x%02x ", a, b);
193 #define PRINT_PKT(x...) do { } while(0)
198 #define SMC_ENABLE_INT(lp, x) do { \
199 unsigned char mask; \
200 unsigned long smc_enable_flags; \
201 spin_lock_irqsave(&lp->lock, smc_enable_flags); \
202 mask = SMC_GET_INT_MASK(lp); \
204 SMC_SET_INT_MASK(lp, mask); \
205 spin_unlock_irqrestore(&lp->lock, smc_enable_flags); \
209 #define SMC_DISABLE_INT(lp, x) do { \
210 unsigned char mask; \
211 unsigned long smc_disable_flags; \
212 spin_lock_irqsave(&lp->lock, smc_disable_flags); \
213 mask = SMC_GET_INT_MASK(lp); \
215 SMC_SET_INT_MASK(lp, mask); \
216 spin_unlock_irqrestore(&lp->lock, smc_disable_flags); \
224 #define SMC_WAIT_MMU_BUSY(lp) do { \
225 if (unlikely(SMC_GET_MMU_CMD(lp) & MC_BUSY)) { \
226 unsigned long timeout = jiffies + 2; \
227 while (SMC_GET_MMU_CMD(lp) & MC_BUSY) { \
228 if (time_after(jiffies, timeout)) { \
229 printk("%s: timeout %s line %d\n", \
230 dev->name, __FILE__, __LINE__); \
249 DBG(2,
"%s: %s\n", dev->
name, __func__);
252 spin_lock_irq(&lp->
lock);
257 spin_unlock_irq(&lp->
lock);
261 dev_kfree_skb(pending_skb);
262 dev->
stats.tx_errors++;
263 dev->
stats.tx_aborted_errors++;
342 DBG(2,
"%s: %s\n", dev->
name, __func__);
370 static void smc_shutdown(
struct net_device *dev)
379 spin_lock_irq(&lp->
lock);
384 spin_unlock_irq(&lp->
lock);
386 dev_kfree_skb(pending_skb);
403 static inline void smc_rcv(
struct net_device *dev)
407 unsigned int packet_number,
status, packet_len;
409 DBG(3,
"%s: %s\n", dev->
name, __func__);
413 PRINTK(
"%s: smc_rcv with nothing on FIFO.\n", dev->
name);
422 packet_len &= 0x07ff;
423 DBG(2,
"%s: RX PNR 0x%x STATUS 0x%04x LENGTH 0x%04x (%d)\n",
424 dev->
name, packet_number, status,
425 packet_len, packet_len);
429 if (status &
RS_TOOLONG && packet_len <= (1514 + 4 + 6)) {
434 if (packet_len < 6) {
437 dev->
name, packet_len, status);
442 dev->
stats.rx_errors++;
444 dev->
stats.rx_frame_errors++;
446 dev->
stats.rx_length_errors++;
448 dev->
stats.rx_crc_errors++;
456 dev->
stats.multicast++;
466 skb = netdev_alloc_skb(dev, packet_len);
472 dev->
stats.rx_dropped++;
488 data_len = packet_len - ((status &
RS_ODDFRAME) ? 5 : 6);
499 dev->
stats.rx_packets++;
526 #define smc_special_trylock(lock, flags) \
529 local_irq_save(flags); \
530 __ret = spin_trylock(lock); \
532 local_irq_restore(flags); \
535 #define smc_special_lock(lock, flags) spin_lock_irqsave(lock, flags)
536 #define smc_special_unlock(lock, flags) spin_unlock_irqrestore(lock, flags)
538 #define smc_special_trylock(lock, flags) (flags == flags)
539 #define smc_special_lock(lock, flags) do { flags = 0; } while (0)
540 #define smc_special_unlock(lock, flags) do { flags = 0; } while (0)
546 static void smc_hardware_send_pkt(
unsigned long data)
552 unsigned int packet_no,
len;
556 DBG(3,
"%s: %s\n", dev->
name, __func__);
559 netif_stop_queue(dev);
560 tasklet_schedule(&lp->
tx_task);
573 printk(
"%s: Memory allocation failed.\n", dev->
name);
574 dev->
stats.tx_errors++;
575 dev->
stats.tx_fifo_errors++;
586 DBG(2,
"%s: TX PNR 0x%x LENGTH 0x%04x (%d) BUF 0x%p\n",
587 dev->
name, packet_no, len, len, buf);
611 netif_stop_queue(dev);
618 dev->
stats.tx_packets++;
624 netif_wake_queue(dev);
639 unsigned int numPages, poll_count,
status;
642 DBG(3,
"%s: %s\n", dev->
name, __func__);
657 numPages = ((skb->
len & ~1) + (6 - 1)) >> 8;
659 printk(
"%s: Far too big packet error.\n", dev->
name);
660 dev->
stats.tx_errors++;
661 dev->
stats.tx_dropped++;
682 }
while (--poll_count);
689 netif_stop_queue(dev);
690 DBG(2,
"%s: TX memory allocation deferred.\n", dev->
name);
697 smc_hardware_send_pkt((
unsigned long)dev);
714 DBG(3,
"%s: %s\n", dev->
name, __func__);
719 PRINTK(
"%s: smc_tx with nothing on FIFO.\n", dev->
name);
730 DBG(2,
"%s: TX STATUS 0x%04x PNR 0x%02x\n",
731 dev->
name, tx_status, packet_no);
734 dev->
stats.tx_errors++;
737 dev->
stats.tx_carrier_errors++;
740 PRINTK(
"%s: %s occurred on last xmit\n", dev->
name,
742 "late collision" :
"too many collisions");
743 dev->
stats.tx_window_errors++;
746 "bad collisions. Please check duplex "
747 "setting.\n", dev->
name);
772 unsigned int mii_reg,
mask;
777 for (mask = 1 << (bits - 1);
mask; mask >>= 1) {
790 static unsigned int smc_mii_in(
struct net_device *dev,
int bits)
794 unsigned int mii_reg,
mask,
val;
799 for (mask = 1 << (bits - 1), val = 0;
mask; mask >>= 1) {
819 unsigned int phydata;
824 smc_mii_out(dev, 0xffffffff, 32);
827 smc_mii_out(dev, 6 << 10 | phyaddr << 5 | phyreg, 14);
830 phydata = smc_mii_in(dev, 18);
835 DBG(3,
"%s: phyaddr=0x%x, phyreg=0x%x, phydata=0x%x\n",
836 __func__, phyaddr, phyreg, phydata);
845 static void smc_phy_write(
struct net_device *dev,
int phyaddr,
int phyreg,
854 smc_mii_out(dev, 0xffffffff, 32);
857 smc_mii_out(dev, 5 << 28 | phyaddr << 23 | phyreg << 18 | 2 << 16 | phydata, 32);
862 DBG(3,
"%s: phyaddr=0x%x, phyreg=0x%x, phydata=0x%x\n",
863 __func__, phyaddr, phyreg, phydata);
871 static void smc_phy_detect(
struct net_device *dev)
876 DBG(2,
"%s: %s\n", dev->
name, __func__);
884 for (phyaddr = 1; phyaddr < 33; ++
phyaddr) {
888 id1 = smc_phy_read(dev, phyaddr & 31,
MII_PHYSID1);
889 id2 = smc_phy_read(dev, phyaddr & 31,
MII_PHYSID2);
891 DBG(3,
"%s: phy_id1=0x%x, phy_id2=0x%x\n",
892 dev->
name, id1, id2);
895 if (id1 != 0x0000 && id1 != 0xffff && id1 != 0x8000 &&
896 id2 != 0x0000 && id2 != 0xffff && id2 != 0x8000) {
898 lp->
mii.phy_id = phyaddr & 31;
908 static int smc_phy_fixed(
struct net_device *dev)
912 int phyaddr = lp->
mii.phy_id;
915 DBG(3,
"%s: %s\n", dev->
name, __func__);
935 smc_phy_write(dev, phyaddr,
MII_BMCR, bmcr);
966 for (timeout = 2; timeout; timeout--) {
967 spin_unlock_irq(&lp->
lock);
969 spin_lock_irq(&lp->
lock);
971 bmcr = smc_phy_read(dev, phy,
MII_BMCR);
985 static void smc_phy_powerdown(
struct net_device *dev)
989 int phy = lp->
mii.phy_id;
999 bmcr = smc_phy_read(dev, phy,
MII_BMCR);
1011 static void smc_phy_check_media(
struct net_device *dev,
int init)
1013 struct smc_local *lp = netdev_priv(dev);
1018 if (lp->
mii.full_duplex) {
1044 int phyaddr = lp->
mii.phy_id;
1049 DBG(3,
"%s:smc_program_phy()\n", dev->
name);
1051 spin_lock_irq(&lp->
lock);
1057 goto smc_phy_configure_exit;
1059 if (smc_phy_reset(dev, phyaddr)) {
1060 printk(
"%s: PHY reset timed out\n", dev->
name);
1061 goto smc_phy_configure_exit;
1078 if (lp->
mii.force_media) {
1080 goto smc_phy_configure_exit;
1084 my_phy_caps = smc_phy_read(dev, phyaddr,
MII_BMSR);
1089 goto smc_phy_configure_exit;
1114 lp->
mii.advertising = my_ad_caps;
1123 DBG(2,
"%s: phy caps=%x\n", dev->
name, my_phy_caps);
1124 DBG(2,
"%s: phy advertised caps=%x\n", dev->
name, my_ad_caps);
1129 smc_phy_check_media(dev, 1);
1131 smc_phy_configure_exit:
1133 spin_unlock_irq(&lp->
lock);
1142 static void smc_phy_interrupt(
struct net_device *dev)
1144 struct smc_local *lp = netdev_priv(dev);
1145 int phyaddr = lp->
mii.phy_id;
1148 DBG(2,
"%s: %s\n", dev->
name, __func__);
1154 smc_phy_check_media(dev, 0);
1165 static void smc_10bt_check_media(
struct net_device *dev,
int init)
1167 struct smc_local *lp = netdev_priv(dev);
1169 unsigned int old_carrier, new_carrier;
1171 old_carrier = netif_carrier_ok(dev) ? 1 : 0;
1177 if (init || (old_carrier != new_carrier)) {
1185 new_carrier ?
"up" :
"down");
1189 static void smc_eph_interrupt(
struct net_device *dev)
1191 struct smc_local *lp = netdev_priv(dev);
1195 smc_10bt_check_media(dev, 0);
1211 struct smc_local *lp = netdev_priv(dev);
1216 DBG(3,
"%s: %s\n", dev->
name, __func__);
1218 spin_lock(&lp->
lock);
1235 DBG(2,
"%s: INT 0x%02x MASK 0x%02x MEM 0x%04x FIFO 0x%04x\n",
1236 dev->
name, status, mask,
1248 DBG(3,
"%s: TX int\n", dev->
name);
1252 netif_wake_queue(dev);
1254 DBG(3,
"%s: RX irq\n", dev->
name);
1257 DBG(3,
"%s: Allocation irq\n", dev->
name);
1258 tasklet_hi_schedule(&lp->
tx_task);
1259 mask &= ~IM_ALLOC_INT;
1261 DBG(3,
"%s: TX empty\n", dev->
name);
1262 mask &= ~IM_TX_EMPTY_INT;
1270 dev->
stats.collisions += card_stats & 0xF;
1274 dev->
stats.collisions += card_stats & 0xF;
1276 DBG(1,
"%s: RX overrun (EPH_ST 0x%04x)\n", dev->
name,
1281 dev->
stats.rx_errors++;
1282 dev->
stats.rx_fifo_errors++;
1284 smc_eph_interrupt(dev);
1287 smc_phy_interrupt(dev);
1290 PRINTK(
"%s: UNSUPPORTED: ERCV INTERRUPT\n", dev->
name);
1292 }
while (--timeout);
1297 spin_unlock(&lp->
lock);
1299 #ifndef CONFIG_NET_POLL_CONTROLLER
1301 PRINTK(
"%s: spurious interrupt (mask = 0x%02x)\n",
1304 DBG(3,
"%s: Interrupt done (%d loops)\n",
1318 #ifdef CONFIG_NET_POLL_CONTROLLER
1323 static void smc_poll_controller(
struct net_device *dev)
1326 smc_interrupt(dev->
irq, dev);
1332 static void smc_timeout(
struct net_device *dev)
1334 struct smc_local *lp = netdev_priv(dev);
1338 DBG(2,
"%s: %s\n", dev->
name, __func__);
1340 spin_lock_irq(&lp->
lock);
1348 spin_unlock_irq(&lp->
lock);
1349 PRINTK(
"%s: TX timeout (INT 0x%02x INTMASK 0x%02x "
1350 "MEM 0x%04x FIFO 0x%04x EPH_ST 0x%04x)\n",
1351 dev->
name, status, mask, meminfo, fifo, eph_st );
1366 netif_wake_queue(dev);
1375 static void smc_set_multicast_list(
struct net_device *dev)
1377 struct smc_local *lp = netdev_priv(dev);
1379 unsigned char multicast_table[8];
1380 int update_multicast = 0;
1382 DBG(2,
"%s: %s\n", dev->
name, __func__);
1385 DBG(2,
"%s: RCR_PRMS\n", dev->
name);
1400 DBG(2,
"%s: RCR_ALMUL\n", dev->
name);
1420 static const unsigned char invert3[] = {0, 4, 2, 6, 1, 5, 3, 7};
1423 memset(multicast_table, 0,
sizeof(multicast_table));
1432 multicast_table[invert3[position&7]] |=
1433 (1<<invert3[(position>>3)&7]);
1440 update_multicast = 1;
1442 DBG(2,
"%s: ~(RCR_PRMS|RCR_ALMUL)\n", dev->
name);
1449 memset(multicast_table, 0,
sizeof(multicast_table));
1450 update_multicast = 1;
1453 spin_lock_irq(&lp->
lock);
1456 if (update_multicast) {
1461 spin_unlock_irq(&lp->
lock);
1473 struct smc_local *lp = netdev_priv(dev);
1475 DBG(2,
"%s: %s\n", dev->
name, __func__);
1482 if (!is_valid_ether_addr(dev->
dev_addr)) {
1483 PRINTK(
"%s: no valid ethernet hw addr\n", __func__);
1509 spin_lock_irq(&lp->
lock);
1510 smc_10bt_check_media(dev, 1);
1511 spin_unlock_irq(&lp->
lock);
1514 netif_start_queue(dev);
1527 struct smc_local *lp = netdev_priv(dev);
1529 DBG(2,
"%s: %s\n", dev->
name, __func__);
1531 netif_stop_queue(dev);
1537 smc_phy_powerdown(dev);
1547 struct smc_local *lp = netdev_priv(dev);
1554 spin_lock_irq(&lp->
lock);
1556 spin_unlock_irq(&lp->
lock);
1563 ethtool_cmd_speed_set(cmd,
SPEED_10);
1581 struct smc_local *lp = netdev_priv(dev);
1585 spin_lock_irq(&lp->
lock);
1587 spin_unlock_irq(&lp->
lock);
1615 static int smc_ethtool_nwayreset(
struct net_device *dev)
1617 struct smc_local *lp = netdev_priv(dev);
1621 spin_lock_irq(&lp->
lock);
1623 spin_unlock_irq(&lp->
lock);
1631 struct smc_local *lp = netdev_priv(dev);
1637 struct smc_local *lp = netdev_priv(dev);
1644 struct smc_local *lp = netdev_priv(dev);
1647 spin_lock_irq(&lp->
lock);
1665 spin_unlock_irq(&lp->
lock);
1669 static int smc_read_eeprom_word(
struct net_device *dev,
u16 addr,
u16 *word)
1672 struct smc_local *lp = netdev_priv(dev);
1675 spin_lock_irq(&lp->
lock);
1693 spin_unlock_irq(&lp->
lock);
1697 static int smc_ethtool_geteeprom_len(
struct net_device *dev)
1702 static int smc_ethtool_geteeprom(
struct net_device *dev,
1708 DBG(1,
"Reading %d bytes at %d(0x%x)\n",
1710 imax = smc_ethtool_geteeprom_len(dev);
1711 for (i = 0; i < eeprom->
len; i += 2) {
1717 ret = smc_read_eeprom_word(dev, offset >> 1, &wbuf);
1720 DBG(2,
"Read 0x%x from 0x%x\n", wbuf, offset >> 1);
1721 data[
i] = (wbuf >> 8) & 0xff;
1722 data[i+1] = wbuf & 0xff;
1727 static int smc_ethtool_seteeprom(
struct net_device *dev,
1733 DBG(1,
"Writing %d bytes to %d(0x%x)\n",
1735 imax = smc_ethtool_geteeprom_len(dev);
1736 for (i = 0; i < eeprom->
len; i += 2) {
1739 int offset = i + eeprom->
offset;
1742 wbuf = (data[
i] << 8) | data[i + 1];
1743 DBG(2,
"Writing 0x%x to 0x%x\n", wbuf, offset >> 1);
1744 ret = smc_write_eeprom_word(dev, offset >> 1, wbuf);
1752 static const struct ethtool_ops smc_ethtool_ops = {
1753 .get_settings = smc_ethtool_getsettings,
1754 .set_settings = smc_ethtool_setsettings,
1755 .get_drvinfo = smc_ethtool_getdrvinfo,
1757 .get_msglevel = smc_ethtool_getmsglevel,
1758 .set_msglevel = smc_ethtool_setmsglevel,
1759 .nway_reset = smc_ethtool_nwayreset,
1761 .get_eeprom_len = smc_ethtool_geteeprom_len,
1762 .get_eeprom = smc_ethtool_geteeprom,
1763 .set_eeprom = smc_ethtool_seteeprom,
1767 .ndo_open = smc_open,
1768 .ndo_stop = smc_close,
1769 .ndo_start_xmit = smc_hard_start_xmit,
1770 .ndo_tx_timeout = smc_timeout,
1771 .ndo_set_rx_mode = smc_set_multicast_list,
1775 #ifdef CONFIG_NET_POLL_CONTROLLER
1776 .ndo_poll_controller = smc_poll_controller,
1824 if (int_status & IM_ALLOC_INT)
1826 }
while (--timeout);
1867 unsigned long irq_flags)
1869 struct smc_local *lp = netdev_priv(dev);
1870 static int version_printed = 0;
1872 unsigned int val, revision_register;
1879 DBG(2,
"%s: bank signature probe returned 0x%04x\n",
CARDNAME, val);
1880 if ((val & 0xFF00) != 0x3300) {
1881 if ((val & 0xFF) == 0x33) {
1883 "%s: Detected possible byte-swapped interface"
1884 " at IOADDR %p\n",
CARDNAME, ioaddr);
1896 if ((val & 0xFF00) != 0x3300) {
1911 printk(
"%s: IOADDR %p doesn't match configuration (%x).\n",
1922 DBG(2,
"%s: revision = 0x%04x\n",
CARDNAME, revision_register);
1923 version_string = chip_ids[ (revision_register >> 4) & 0xF];
1924 if (!version_string || (revision_register & 0xff00) != 0x3300) {
1926 printk(
"%s: IO %p: Unrecognized revision register 0x%04x"
1928 ioaddr, revision_register);
1935 if (version_printed++ == 0)
1941 lp->
version = revision_register & 0xff;
1971 dev->
irq = smc_findirq(lp);
1978 if (dev->
irq == 0) {
1979 printk(
"%s: Couldn't autodetect your IRQ. Use irq=xx.\n",
1996 lp->
mii.phy_id_mask = 0x1f;
1997 lp->
mii.reg_num_mask = 0x1f;
1998 lp->
mii.force_media = 0;
1999 lp->
mii.full_duplex = 0;
2001 lp->
mii.mdio_read = smc_phy_read;
2002 lp->
mii.mdio_write = smc_phy_write;
2008 smc_phy_detect(dev);
2012 smc_phy_powerdown(dev);
2029 #ifdef CONFIG_ARCH_PXA
2030 # ifdef SMC_USE_PXA_DMA
2035 smc_pxa_dma_irq,
NULL);
2044 printk(
"%s: %s (rev %d) at %p IRQ %d",
2045 dev->
name, version_string, revision_register & 0x0f,
2048 if (dev->
dma != (
unsigned char)-1)
2055 if (!is_valid_ether_addr(dev->
dev_addr)) {
2056 printk(
"%s: Invalid ethernet MAC address. Please "
2057 "set using ifconfig\n", dev->
name);
2060 printk(
"%s: Ethernet addr: %pM\n",
2066 }
else if ((lp->
phy_type & 0xfffffff0) == 0x0016f840) {
2067 PRINTK(
"%s: PHY LAN83C183 (LAN91C111 Internal)\n", dev->
name);
2068 }
else if ((lp->
phy_type & 0xfffffff0) == 0x02821c50) {
2074 #ifdef CONFIG_ARCH_PXA
2075 if (retval && dev->
dma != (
unsigned char)-1)
2084 struct smc_local *lp = netdev_priv(ndev);
2085 unsigned long flags;
2086 unsigned char ecor, ecsr;
2163 struct smc_local *lp __maybe_unused = netdev_priv(ndev);
2173 struct smc_local *lp = netdev_priv(ndev);
2190 struct smc_local *lp = netdev_priv(ndev);
2224 ndev = alloc_etherdev(
sizeof(
struct smc_local));
2235 lp = netdev_priv(ndev);
2247 if (!lp->
cfg.leda && !lp->
cfg.ledb) {
2252 ndev->
dma = (
unsigned char)-1;
2259 goto out_free_netdev;
2265 goto out_free_netdev;
2271 goto out_release_io;
2279 ret = smc_request_attrib(pdev, ndev);
2281 goto out_release_io;
2282 #if defined(CONFIG_SA1100_ASSABET)
2285 platform_set_drvdata(pdev, ndev);
2286 ret = smc_enable_device(pdev);
2288 goto out_release_attrib;
2293 goto out_release_attrib;
2296 #ifdef CONFIG_ARCH_PXA
2298 struct smc_local *lp = netdev_priv(ndev);
2299 lp->device = &pdev->
dev;
2300 lp->physaddr = res->
start;
2304 ret = smc_probe(ndev, addr, irq_flags);
2308 smc_request_datacs(pdev, ndev);
2313 platform_set_drvdata(pdev,
NULL);
2316 smc_release_attrib(pdev, ndev);
2329 struct net_device *ndev = platform_get_drvdata(pdev);
2330 struct smc_local *lp = netdev_priv(ndev);
2333 platform_set_drvdata(pdev,
NULL);
2339 #ifdef CONFIG_ARCH_PXA
2340 if (ndev->
dma != (
unsigned char)-1)
2345 smc_release_datacs(pdev,ndev);
2346 smc_release_attrib(pdev,ndev);
2358 static int smc_drv_suspend(
struct device *dev)
2361 struct net_device *ndev = platform_get_drvdata(pdev);
2364 if (netif_running(ndev)) {
2367 smc_phy_powerdown(ndev);
2373 static int smc_drv_resume(
struct device *dev)
2376 struct net_device *ndev = platform_get_drvdata(pdev);
2379 struct smc_local *lp = netdev_priv(ndev);
2380 smc_enable_device(pdev);
2381 if (netif_running(ndev)) {
2394 { .compatible =
"smsc,lan91c94", },
2395 { .compatible =
"smsc,lan91c111", },
2400 #define smc91x_match NULL
2404 .suspend = smc_drv_suspend,
2405 .resume = smc_drv_resume,
2409 .probe = smc_drv_probe,
2414 .pm = &smc_drv_pm_ops,