33 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
37 #include <linux/errno.h>
39 #include <linux/ethtool.h>
43 #include <linux/kernel.h>
44 #include <linux/module.h>
45 #include <linux/netdevice.h>
48 #include <linux/sched.h>
51 #include <linux/bitops.h>
54 #include <linux/swab.h>
57 #include <linux/device.h>
64 #define SMSC_CHIPNAME "smsc911x"
65 #define SMSC_MDIONAME "smsc911x-mdio"
66 #define SMSC_DRV_VERSION "2008-10-21"
73 static int debug = 16;
87 unsigned int *
buf,
unsigned int wordcount);
89 unsigned int *
buf,
unsigned int wordcount);
92 #define SMSC911X_NUM_SUPPLIES 2
128 #ifdef USE_PHY_WORK_AROUND
129 #define MIN_PACKET_SIZE (64)
150 #define __smsc_shift(pdata, reg) ((reg) << ((pdata)->config.shift))
159 ((
readw(pdata->
ioaddr + reg + 2) & 0xFFFF) << 16));
187 data = pdata->
ops->reg_read(pdata, reg);
188 spin_unlock_irqrestore(&pdata->
dev_lock, flags);
193 static inline void __smsc911x_reg_write(
struct smsc911x_data *pdata,
u32 reg,
221 writew((val >> 16) & 0xFFFF,
235 pdata->
ops->reg_write(pdata, reg, val);
236 spin_unlock_irqrestore(&pdata->
dev_lock, flags);
242 unsigned int wordcount)
268 spin_unlock_irqrestore(&pdata->
dev_lock, flags);
273 smsc911x_tx_writefifo_shift(
struct smsc911x_data *pdata,
unsigned int *buf,
274 unsigned int wordcount)
295 __smsc911x_reg_write_shift(pdata,
302 spin_unlock_irqrestore(&pdata->
dev_lock, flags);
307 smsc911x_rx_readfifo(
struct smsc911x_data *pdata,
unsigned int *buf,
308 unsigned int wordcount)
316 *buf++ =
swab32(__smsc911x_reg_read(pdata,
334 spin_unlock_irqrestore(&pdata->
dev_lock, flags);
339 smsc911x_rx_readfifo_shift(
struct smsc911x_data *pdata,
unsigned int *buf,
340 unsigned int wordcount)
348 *buf++ =
swab32(__smsc911x_reg_read_shift(pdata,
361 *buf++ = __smsc911x_reg_read_shift(pdata,
368 spin_unlock_irqrestore(&pdata->
dev_lock, flags);
383 netdev_err(ndev,
"failed to enable regulators %d\n",
393 struct net_device *ndev = platform_get_drvdata(pdev);
411 struct net_device *ndev = platform_get_drvdata(pdev);
416 pdata->
supplies[0].supply =
"vdd33a";
417 pdata->
supplies[1].supply =
"vddvario";
422 netdev_err(ndev,
"couldn't get regulators %d\n",
433 struct net_device *ndev = platform_get_drvdata(pdev);
443 static int smsc911x_mac_complete(
struct smsc911x_data *pdata)
450 for (i = 0; i < 40; i++) {
455 SMSC_WARN(pdata,
hw,
"Timed out waiting for MAC not BUSY. "
456 "MAC_CSR_CMD: 0x%08X", val);
474 smsc911x_reg_write(pdata,
MAC_CSR_CMD, ((offset & 0xFF) |
478 temp = smsc911x_reg_read(pdata,
BYTE_TEST);
481 if (
likely(smsc911x_mac_complete(pdata) == 0))
490 unsigned int offset,
u32 val)
497 if (
unlikely(temp & MAC_CSR_CMD_CSR_BUSY_)) {
499 "smsc911x_mac_write failed, MAC busy at entry");
507 smsc911x_reg_write(pdata,
MAC_CSR_CMD, ((offset & 0xFF) |
508 MAC_CSR_CMD_CSR_BUSY_));
511 temp = smsc911x_reg_read(pdata,
BYTE_TEST);
514 if (
likely(smsc911x_mac_complete(pdata) == 0))
517 SMSC_WARN(pdata,
hw,
"smsc911x_mac_write failed, MAC busy after write");
532 SMSC_WARN(pdata,
hw,
"MII is busy in smsc911x_mii_read???");
538 addr = ((phyaddr & 0x1F) << 11) | ((regidx & 0x1F) << 6);
542 for (i = 0; i < 100; i++)
543 if (!(smsc911x_mac_read(pdata,
MII_ACC) & MII_ACC_MII_BUSY_)) {
544 reg = smsc911x_mac_read(pdata,
MII_DATA);
548 SMSC_WARN(pdata,
hw,
"Timed out waiting for MII read to finish");
552 spin_unlock_irqrestore(&pdata->
mac_lock, flags);
557 static int smsc911x_mii_write(
struct mii_bus *bus,
int phyaddr,
int regidx,
569 SMSC_WARN(pdata,
hw,
"MII is busy in smsc911x_mii_write???");
575 smsc911x_mac_write(pdata,
MII_DATA, val);
578 addr = ((phyaddr & 0x1F) << 11) | ((regidx & 0x1F) << 6) |
583 for (i = 0; i < 100; i++)
584 if (!(smsc911x_mac_read(pdata,
MII_ACC) & MII_ACC_MII_BUSY_)) {
589 SMSC_WARN(pdata,
hw,
"Timed out waiting for MII write to finish");
593 spin_unlock_irqrestore(&pdata->
mac_lock, flags);
598 static void smsc911x_phy_enable_external(
struct smsc911x_data *pdata)
600 unsigned int hwcfg = smsc911x_reg_read(pdata,
HW_CFG);
605 smsc911x_reg_write(pdata,
HW_CFG, hwcfg);
610 smsc911x_reg_write(pdata,
HW_CFG, hwcfg);
615 smsc911x_reg_write(pdata,
HW_CFG, hwcfg);
619 smsc911x_reg_write(pdata,
HW_CFG, hwcfg);
625 static void smsc911x_phy_initialise_external(
struct smsc911x_data *pdata)
627 unsigned int hwcfg = smsc911x_reg_read(pdata,
HW_CFG);
634 smsc911x_phy_enable_external(pdata);
638 "HW_CFG EXT_PHY_DET set, using external PHY");
639 smsc911x_phy_enable_external(pdata);
643 "HW_CFG EXT_PHY_DET clear, using internal PHY");
649 static unsigned int smsc911x_tx_get_txstatus(
struct smsc911x_data *pdata)
661 static unsigned int smsc911x_rx_get_rxstatus(
struct smsc911x_data *pdata)
663 unsigned int result =
672 #ifdef USE_PHY_WORK_AROUND
673 static int smsc911x_phy_check_loopbackpkt(
struct smsc911x_data *pdata)
680 for (tries = 0; tries < 10; tries++) {
681 unsigned int txcmd_a;
682 unsigned int txcmd_b;
684 unsigned int pktlength;
705 pdata->
ops->tx_writefifo(pdata, (
unsigned int *)bufp, wrsz);
711 status = smsc911x_tx_get_txstatus(pdata);
712 }
while ((i--) && (!status));
716 "Failed to transmit during loopback test");
721 "Transmit encountered errors during loopback test");
729 status = smsc911x_rx_get_rxstatus(pdata);
730 }
while ((i--) && (!status));
734 "Failed to receive during loopback test");
739 "Receive encountered errors during loopback test");
743 pktlength = ((status & 0x3FFF0000
UL) >> 16);
745 rdsz = pktlength + 3;
749 pdata->
ops->rx_readfifo(pdata, (
unsigned int *)bufp, rdsz);
753 "during loop back test, size=%d, will retry",
771 "during loop back test, will retry");
783 unsigned int i = 100000;
792 temp = smsc911x_mii_read(phy_dev->
bus, phy_dev->
addr,
796 if (temp & BMCR_RESET) {
797 SMSC_WARN(pdata,
hw,
"PHY reset failed to complete");
820 for (i = 6; i < 12; i++)
830 val = smsc911x_reg_read(pdata,
HW_CFG);
833 smsc911x_reg_write(pdata,
HW_CFG, val);
836 smsc911x_reg_write(pdata,
RX_CFG,
839 for (i = 0; i < 10; i++) {
848 spin_unlock_irqrestore(&pdata->
mac_lock, flags);
850 if (smsc911x_phy_check_loopbackpkt(pdata) == 0) {
858 smsc911x_mac_write(pdata,
MAC_CR, 0);
859 spin_unlock_irqrestore(&pdata->
mac_lock, flags);
861 smsc911x_phy_reset(pdata);
866 smsc911x_mac_write(pdata,
MAC_CR, 0);
867 spin_unlock_irqrestore(&pdata->
mac_lock, flags);
872 smsc911x_reg_write(pdata,
TX_CFG, 0);
873 smsc911x_reg_write(pdata,
RX_CFG, 0);
879 static void smsc911x_phy_update_flowcontrol(
struct smsc911x_data *pdata)
889 u8 cap = mii_resolve_flowctrl_fdx(lcladv, rmtadv);
902 (cap & FLOW_CTRL_RX ?
"enabled" :
"disabled"),
903 (cap & FLOW_CTRL_TX ?
"enabled" :
"disabled"));
911 smsc911x_mac_write(pdata,
FLOW, flow);
912 spin_unlock_irqrestore(&pdata->
mac_lock, flags);
914 smsc911x_reg_write(pdata,
AFC_CFG, afc);
919 static void smsc911x_phy_adjust_link(
struct net_device *dev)
931 mac_cr = smsc911x_mac_read(pdata,
MAC_CR);
934 "configuring for full duplex mode");
938 "configuring for half duplex mode");
941 smsc911x_mac_write(pdata,
MAC_CR, mac_cr);
942 spin_unlock_irqrestore(&pdata->
mac_lock, flags);
944 smsc911x_phy_update_flowcontrol(pdata);
948 carrier = netif_carrier_ok(dev);
984 static int smsc911x_mii_probe(
struct net_device *dev)
993 netdev_err(dev,
"no PHY found\n");
997 SMSC_TRACE(pdata, probe,
"PHY: addr %d, phy_id 0x%08X",
1001 &smsc911x_phy_adjust_link, 0,
1002 pdata->
config.phy_interface);
1005 netdev_err(dev,
"Could not attach to PHY\n");
1010 "attached PHY driver [%s] (mii_bus:phy_addr=%s, irq=%d)\n",
1011 phydev->
drv->name, dev_name(&phydev->
dev), phydev->
irq);
1022 #ifdef USE_PHY_WORK_AROUND
1023 if (smsc911x_phy_loopbacktest(dev) < 0) {
1040 pdata->
mii_bus = mdiobus_alloc();
1050 pdata->
mii_bus->read = smsc911x_mii_read;
1051 pdata->
mii_bus->write = smsc911x_mii_write;
1058 switch (pdata->
idrev & 0xFFFF0000) {
1064 smsc911x_phy_initialise_external(pdata);
1067 SMSC_TRACE(pdata,
hw,
"External PHY is not supported, "
1068 "using internal PHY");
1075 pdata->
mii_bus->phy_mask = ~(1 << 1);
1079 SMSC_WARN(pdata, probe,
"Error registering mii bus");
1080 goto err_out_free_bus_2;
1083 if (smsc911x_mii_probe(dev) < 0) {
1084 SMSC_WARN(pdata, probe,
"Error registering mii bus");
1085 goto err_out_unregister_bus_3;
1090 err_out_unregister_bus_3:
1099 static unsigned int smsc911x_tx_get_txstatcount(
struct smsc911x_data *pdata)
1106 static void smsc911x_tx_update_txcounters(
struct net_device *dev)
1111 while ((tx_stat = smsc911x_tx_get_txstatus(pdata)) != 0) {
1112 if (
unlikely(tx_stat & 0x80000000)) {
1120 SMSC_WARN(pdata,
hw,
"Packet tag reserved bit is high");
1122 if (
unlikely(tx_stat & TX_STS_ES_)) {
1123 dev->
stats.tx_errors++;
1125 dev->
stats.tx_packets++;
1126 dev->
stats.tx_bytes += (tx_stat >> 16);
1129 dev->
stats.collisions += 16;
1130 dev->
stats.tx_aborted_errors += 1;
1132 dev->
stats.collisions +=
1133 ((tx_stat >> 3) & 0xF);
1136 dev->
stats.tx_carrier_errors += 1;
1138 dev->
stats.collisions++;
1139 dev->
stats.tx_aborted_errors++;
1147 smsc911x_rx_counterrors(
struct net_device *dev,
unsigned int rxstat)
1151 if (
unlikely(rxstat & RX_STS_ES_)) {
1152 dev->
stats.rx_errors++;
1154 dev->
stats.rx_crc_errors++;
1161 dev->
stats.rx_length_errors++;
1163 dev->
stats.multicast++;
1169 smsc911x_rx_fastforward(
struct smsc911x_data *pdata,
unsigned int pktwords)
1171 if (
likely(pktwords >= 4)) {
1182 "RX FFWD to finish, RX_DP_CTRL: 0x%08X", val);
1198 while (npackets < budget) {
1199 unsigned int pktlength;
1200 unsigned int pktwords;
1202 unsigned int rxstat = smsc911x_rx_get_rxstatus(pdata);
1210 temp = smsc911x_reg_read(pdata,
INT_EN);
1212 smsc911x_reg_write(pdata,
INT_EN, temp);
1220 pktlength = ((rxstat & 0x3FFF0000) >> 16);
1222 smsc911x_rx_counterrors(dev, rxstat);
1224 if (
unlikely(rxstat & RX_STS_ES_)) {
1226 "Discarding packet with error bit set");
1229 smsc911x_rx_fastforward(pdata, pktwords);
1230 dev->
stats.rx_dropped++;
1234 skb = netdev_alloc_skb(dev, pktwords << 2);
1237 "Unable to allocate skb for rx packet");
1239 smsc911x_rx_fastforward(pdata, pktwords);
1240 dev->
stats.rx_dropped++;
1244 pdata->
ops->rx_readfifo(pdata,
1245 (
unsigned int *)skb->
data, pktwords);
1251 skb_checksum_none_assert(skb);
1255 dev->
stats.rx_packets++;
1256 dev->
stats.rx_bytes += (pktlength - 4);
1271 static void smsc911x_rx_multicast_update(
struct smsc911x_data *pdata)
1275 unsigned int mac_cr;
1279 mac_cr = smsc911x_mac_read(pdata,
MAC_CR);
1282 smsc911x_mac_write(pdata,
MAC_CR, mac_cr);
1285 SMSC_TRACE(pdata,
hw,
"maccr 0x%08X, HASHH 0x%08X, HASHL 0x%08X",
1289 static void smsc911x_rx_multicast_update_workaround(
struct smsc911x_data *pdata)
1291 unsigned int mac_cr;
1304 SMSC_WARN(pdata, drv,
"Rx not stopped");
1307 smsc911x_rx_multicast_update(pdata);
1310 mac_cr = smsc911x_mac_read(pdata,
MAC_CR);
1312 smsc911x_mac_write(pdata,
MAC_CR, mac_cr);
1319 static int smsc911x_phy_disable_energy_detect(
struct smsc911x_data *pdata)
1329 SMSC_WARN(pdata, drv,
"Failed reading PHY control reg");
1341 rc & (~MII_LAN83C185_EDPWRDOWN));
1344 SMSC_WARN(pdata, drv,
"Failed writing PHY control reg");
1354 static int smsc911x_phy_enable_energy_detect(
struct smsc911x_data *pdata)
1364 SMSC_WARN(pdata, drv,
"Failed reading PHY control reg");
1369 if (!(rc & MII_LAN83C185_EDPWRDOWN)) {
1373 rc | MII_LAN83C185_EDPWRDOWN);
1376 SMSC_WARN(pdata, drv,
"Failed writing PHY control reg");
1387 unsigned int timeout;
1398 ret = smsc911x_phy_disable_energy_detect(pdata);
1401 SMSC_WARN(pdata, drv,
"Failed to wakeup the PHY chip");
1411 temp = smsc911x_reg_read(pdata,
HW_CFG);
1414 if (
unlikely(temp & HW_CFG_SRST_)) {
1415 SMSC_WARN(pdata, drv,
"Failed to complete reset");
1420 ret = smsc911x_phy_enable_energy_detect(pdata);
1423 SMSC_WARN(pdata, drv,
"Failed to wakeup the PHY chip");
1433 smsc911x_set_hw_mac_address(
struct smsc911x_data *pdata,
u8 dev_addr[6])
1435 u32 mac_high16 = (dev_addr[5] << 8) | dev_addr[4];
1436 u32 mac_low32 = (dev_addr[3] << 24) | (dev_addr[2] << 16) |
1437 (dev_addr[1] << 8) | dev_addr[0];
1441 smsc911x_mac_write(pdata,
ADDRH, mac_high16);
1442 smsc911x_mac_write(pdata,
ADDRL, mac_low32);
1445 static void smsc911x_disable_irq_chip(
struct net_device *dev)
1449 smsc911x_reg_write(pdata,
INT_EN, 0);
1450 smsc911x_reg_write(pdata,
INT_STS, 0xFFFFFFFF);
1453 static int smsc911x_open(
struct net_device *dev)
1456 unsigned int timeout;
1458 unsigned int intcfg;
1466 if (!is_valid_ether_addr(dev->
dev_addr)) {
1467 SMSC_WARN(pdata,
hw,
"dev_addr is not a valid MAC address");
1472 if (smsc911x_soft_reset(pdata)) {
1477 smsc911x_reg_write(pdata,
HW_CFG, 0x00050000);
1478 smsc911x_reg_write(pdata,
AFC_CFG, 0x006E3740);
1494 "Timed out waiting for EEPROM busy bit to clear");
1496 smsc911x_reg_write(pdata,
GPIO_CFG, 0x70070000);
1501 smsc911x_set_hw_mac_address(pdata, dev->
dev_addr);
1505 smsc911x_disable_irq_chip(dev);
1510 if (pdata->
config.irq_polarity) {
1511 SMSC_TRACE(pdata, ifup,
"irq polarity: active high");
1514 SMSC_TRACE(pdata, ifup,
"irq polarity: active low");
1517 if (pdata->
config.irq_type) {
1518 SMSC_TRACE(pdata, ifup,
"irq type: push-pull");
1521 SMSC_TRACE(pdata, ifup,
"irq type: open drain");
1524 smsc911x_reg_write(pdata,
INT_CFG, intcfg);
1526 SMSC_TRACE(pdata, ifup,
"Testing irq handler using IRQ %d", dev->
irq);
1530 temp = smsc911x_reg_read(pdata,
INT_EN);
1532 smsc911x_reg_write(pdata,
INT_EN, temp);
1542 netdev_warn(dev,
"ISR failed signaling test (IRQ %d)\n",
1546 SMSC_TRACE(pdata, ifup,
"IRQ handler passed test using IRQ %d",
1549 netdev_info(dev,
"SMSC911x/921x identified at %#08lx, IRQ: %d\n",
1550 (
unsigned long)pdata->
ioaddr, dev->
irq);
1559 temp = smsc911x_reg_read(pdata,
HW_CFG);
1563 smsc911x_reg_write(pdata,
HW_CFG, temp);
1565 temp = smsc911x_reg_read(pdata,
FIFO_INT);
1568 smsc911x_reg_write(pdata,
FIFO_INT, temp);
1574 napi_enable(&pdata->
napi);
1576 temp = smsc911x_reg_read(pdata,
INT_EN);
1578 smsc911x_reg_write(pdata,
INT_EN, temp);
1581 temp = smsc911x_mac_read(pdata,
MAC_CR);
1583 smsc911x_mac_write(pdata,
MAC_CR, temp);
1588 netif_start_queue(dev);
1593 static int smsc911x_stop(
struct net_device *dev)
1599 temp = smsc911x_reg_read(pdata,
INT_CFG);
1601 smsc911x_reg_write(pdata,
INT_CFG, temp);
1604 netif_stop_queue(dev);
1605 napi_disable(&pdata->
napi);
1608 dev->
stats.rx_dropped += smsc911x_reg_read(pdata,
RX_DROP);
1609 smsc911x_tx_update_txcounters(dev);
1615 SMSC_TRACE(pdata, ifdown,
"Interface stopped");
1620 static int smsc911x_hard_start_xmit(
struct sk_buff *skb,
struct net_device *dev)
1623 unsigned int freespace;
1624 unsigned int tx_cmd_a;
1625 unsigned int tx_cmd_b;
1634 "Tx data fifo low, space available: %d", freespace);
1639 tx_cmd_a |= (
unsigned int)skb->
len;
1641 tx_cmd_b = ((
unsigned int)skb->
len) << 16;
1642 tx_cmd_b |= (
unsigned int)skb->
len;
1648 wrsz = (
u32)skb->
len + 3;
1652 pdata->
ops->tx_writefifo(pdata, (
unsigned int *)bufp, wrsz);
1653 freespace -= (skb->
len + 32);
1654 skb_tx_timestamp(skb);
1657 if (
unlikely(smsc911x_tx_get_txstatcount(pdata) >= 30))
1658 smsc911x_tx_update_txcounters(dev);
1661 netif_stop_queue(dev);
1662 temp = smsc911x_reg_read(pdata,
FIFO_INT);
1665 smsc911x_reg_write(pdata,
FIFO_INT, temp);
1675 smsc911x_tx_update_txcounters(dev);
1676 dev->
stats.rx_dropped += smsc911x_reg_read(pdata,
RX_DROP);
1681 static void smsc911x_set_multicast_list(
struct net_device *dev)
1684 unsigned long flags;
1700 unsigned int hash_high = 0;
1701 unsigned int hash_low = 0;
1708 unsigned int bitnum = smsc911x_hash(ha->
addr);
1709 unsigned int mask = 0x01 << (bitnum & 0x1F);
1717 pdata->
hashhi = hash_high;
1718 pdata->
hashlo = hash_low;
1740 temp = smsc911x_mac_read(pdata,
MAC_CR);
1742 smsc911x_mac_write(pdata,
MAC_CR, temp);
1749 smsc911x_rx_multicast_update(pdata);
1752 spin_unlock_irqrestore(&pdata->
mac_lock, flags);
1759 u32 intsts = smsc911x_reg_read(pdata,
INT_STS);
1760 u32 inten = smsc911x_reg_read(pdata,
INT_EN);
1765 temp = smsc911x_reg_read(pdata,
INT_EN);
1767 smsc911x_reg_write(pdata,
INT_EN, temp);
1768 smsc911x_reg_write(pdata,
INT_STS, INT_STS_SW_INT_);
1778 smsc911x_reg_write(pdata,
INT_STS, INT_STS_RXSTOP_INT_);
1780 smsc911x_rx_multicast_update_workaround(pdata);
1785 temp = smsc911x_reg_read(pdata,
FIFO_INT);
1787 smsc911x_reg_write(pdata,
FIFO_INT, temp);
1788 smsc911x_reg_write(pdata,
INT_STS, INT_STS_TDFA_);
1789 netif_wake_queue(dev);
1795 smsc911x_reg_write(pdata,
INT_STS, INT_STS_RXE_);
1800 if (
likely(napi_schedule_prep(&pdata->
napi))) {
1802 temp = smsc911x_reg_read(pdata,
INT_EN);
1804 smsc911x_reg_write(pdata,
INT_EN, temp);
1808 SMSC_WARN(pdata, rx_err,
"napi_schedule_prep failed");
1816 #ifdef CONFIG_NET_POLL_CONTROLLER
1817 static void smsc911x_poll_controller(
struct net_device *dev)
1820 smsc911x_irqhandler(0, dev);
1825 static int smsc911x_set_mac_address(
struct net_device *dev,
void *
p)
1833 if (pdata->
generation <= 1 && netif_running(dev))
1836 if (!is_valid_ether_addr(addr->
sa_data))
1843 smsc911x_set_hw_mac_address(pdata, dev->
dev_addr);
1846 netdev_info(dev,
"MAC Address: %pM\n", dev->
dev_addr);
1856 if (!netif_running(dev) || !pdata->
phy_dev)
1880 static void smsc911x_ethtool_getdrvinfo(
struct net_device *dev,
1889 static int smsc911x_ethtool_nwayreset(
struct net_device *dev)
1896 static u32 smsc911x_ethtool_getmsglevel(
struct net_device *dev)
1908 static int smsc911x_ethtool_getregslen(
struct net_device *dev)
1920 unsigned long flags;
1927 data[j++] = smsc911x_reg_read(pdata, i);
1931 data[j++] = smsc911x_mac_read(pdata, i);
1932 spin_unlock_irqrestore(&pdata->
mac_lock, flags);
1935 for (i = 0; i <= 31; i++)
1936 data[j++] = smsc911x_mii_read(phy_dev->
bus, phy_dev->
addr, i);
1939 static void smsc911x_eeprom_enable_access(
struct smsc911x_data *pdata)
1941 unsigned int temp = smsc911x_reg_read(pdata,
GPIO_CFG);
1943 smsc911x_reg_write(pdata,
GPIO_CFG, temp);
1953 if (smsc911x_reg_read(pdata,
E2P_CMD) & E2P_CMD_EPC_BUSY_) {
1959 smsc911x_reg_write(pdata,
E2P_CMD, e2cmd);
1963 e2cmd = smsc911x_reg_read(pdata,
E2P_CMD);
1964 }
while ((e2cmd & E2P_CMD_EPC_BUSY_) && (--timeout));
1972 SMSC_TRACE(pdata,
drv,
"Error occurred during eeprom operation");
1979 static int smsc911x_eeprom_read_location(
struct smsc911x_data *pdata,
1986 ret = smsc911x_eeprom_send_cmd(pdata, op);
1994 static int smsc911x_eeprom_write_location(
struct smsc911x_data *pdata,
1995 u8 address,
u8 data)
2001 SMSC_TRACE(pdata,
drv,
"address 0x%x, data 0x%x", address, data);
2002 ret = smsc911x_eeprom_send_cmd(pdata, op);
2009 temp = smsc911x_reg_read(pdata,
BYTE_TEST);
2011 ret = smsc911x_eeprom_send_cmd(pdata, op);
2017 static int smsc911x_ethtool_get_eeprom_len(
struct net_device *dev)
2022 static int smsc911x_ethtool_get_eeprom(
struct net_device *dev,
2030 smsc911x_eeprom_enable_access(pdata);
2033 for (i = 0; i < len; i++) {
2034 int ret = smsc911x_eeprom_read_location(pdata, i, eeprom_data);
2046 static int smsc911x_ethtool_set_eeprom(
struct net_device *dev,
2052 smsc911x_eeprom_enable_access(pdata);
2054 ret = smsc911x_eeprom_write_location(pdata, eeprom->
offset, *data);
2063 static const struct ethtool_ops smsc911x_ethtool_ops = {
2064 .get_settings = smsc911x_ethtool_getsettings,
2065 .set_settings = smsc911x_ethtool_setsettings,
2067 .get_drvinfo = smsc911x_ethtool_getdrvinfo,
2068 .nway_reset = smsc911x_ethtool_nwayreset,
2069 .get_msglevel = smsc911x_ethtool_getmsglevel,
2070 .set_msglevel = smsc911x_ethtool_setmsglevel,
2071 .get_regs_len = smsc911x_ethtool_getregslen,
2072 .get_regs = smsc911x_ethtool_getregs,
2073 .get_eeprom_len = smsc911x_ethtool_get_eeprom_len,
2074 .get_eeprom = smsc911x_ethtool_get_eeprom,
2075 .set_eeprom = smsc911x_ethtool_set_eeprom,
2080 .ndo_open = smsc911x_open,
2081 .ndo_stop = smsc911x_stop,
2082 .ndo_start_xmit = smsc911x_hard_start_xmit,
2083 .ndo_get_stats = smsc911x_get_stats,
2084 .ndo_set_rx_mode = smsc911x_set_multicast_list,
2085 .ndo_do_ioctl = smsc911x_do_ioctl,
2088 .ndo_set_mac_address = smsc911x_set_mac_address,
2089 #ifdef CONFIG_NET_POLL_CONTROLLER
2090 .ndo_poll_controller = smsc911x_poll_controller,
2098 u32 mac_high16 = smsc911x_mac_read(pdata,
ADDRH);
2099 u32 mac_low32 = smsc911x_mac_read(pdata,
ADDRL);
2113 unsigned int byte_test,
mask;
2114 unsigned int to = 100;
2116 SMSC_TRACE(pdata, probe,
"Driver Parameters:");
2117 SMSC_TRACE(pdata, probe,
"LAN base: 0x%08lX",
2118 (
unsigned long)pdata->
ioaddr);
2120 SMSC_TRACE(pdata, probe,
"PHY will be autodetected.");
2125 if (pdata->
ioaddr == 0) {
2126 SMSC_WARN(pdata, probe,
"pdata->ioaddr: 0x00000000");
2146 while (!(smsc911x_reg_read(pdata,
PMT_CTRL) & mask) && --to)
2150 pr_err(
"Device not READY in 100ms aborting\n");
2155 byte_test = smsc911x_reg_read(pdata,
BYTE_TEST);
2156 SMSC_TRACE(pdata, probe,
"BYTE_TEST: 0x%08X", byte_test);
2157 if (byte_test == 0x43218765) {
2158 SMSC_TRACE(pdata, probe,
"BYTE_TEST looks swapped, "
2159 "applying WORD_SWAP");
2160 smsc911x_reg_write(pdata,
WORD_SWAP, 0xffffffff);
2164 byte_test = smsc911x_reg_read(pdata,
BYTE_TEST);
2166 byte_test = smsc911x_reg_read(pdata,
BYTE_TEST);
2169 if (byte_test != 0x87654321) {
2170 SMSC_WARN(pdata, drv,
"BYTE_TEST: 0x%08X", byte_test);
2171 if (((byte_test >> 16) & 0xFFFF) == (byte_test & 0xFFFF)) {
2173 "top 16 bits equal to bottom 16 bits");
2175 "This may mean the chip is set "
2176 "for 32 bit while the bus is reading 16 bit");
2185 switch (pdata->
idrev & 0xFFFF0000) {
2212 SMSC_WARN(pdata, probe,
"LAN911x not identified, idrev: 0x%08X",
2218 "LAN911x identified, idrev: 0x%08X, generation: %d",
2223 "This driver is not intended for this chip revision");
2230 smsc911x_read_mac_address(dev);
2235 if (smsc911x_soft_reset(pdata))
2253 dev = platform_get_drvdata(pdev);
2255 pdata = netdev_priv(dev);
2260 SMSC_TRACE(pdata, ifdown,
"Stopping driver");
2267 platform_set_drvdata(pdev,
NULL);
2279 (
void)smsc911x_disable_resources(pdev);
2280 smsc911x_free_resources(pdev);
2288 static const struct smsc911x_ops standard_smsc911x_ops = {
2289 .reg_read = __smsc911x_reg_read,
2290 .reg_write = __smsc911x_reg_write,
2291 .rx_readfifo = smsc911x_rx_readfifo,
2292 .tx_writefifo = smsc911x_tx_writefifo,
2296 static const struct smsc911x_ops shifted_smsc911x_ops = {
2297 .reg_read = __smsc911x_reg_read_shift,
2298 .reg_write = __smsc911x_reg_write_shift,
2299 .rx_readfifo = smsc911x_rx_readfifo_shift,
2300 .tx_writefifo = smsc911x_tx_writefifo_shift,
2304 static int __devinit smsc911x_probe_config_dt(
2320 of_property_read_u32(np,
"reg-shift", &config->
shift);
2322 of_property_read_u32(np,
"reg-io-width", &width);
2346 static inline int smsc911x_probe_config_dt(
2361 unsigned int intcfg = 0;
2372 pr_warn(
"Could not allocate resource\n");
2376 res_size = resource_size(res);
2380 pr_warn(
"Could not allocate irq resource\n");
2393 goto out_release_io_1;
2398 pdata = netdev_priv(dev);
2406 platform_set_drvdata(pdev, dev);
2408 retval = smsc911x_request_resources(pdev);
2410 goto out_request_resources_fail;
2412 retval = smsc911x_enable_resources(pdev);
2414 goto out_enable_resources_fail;
2417 SMSC_WARN(pdata, probe,
"Error smsc911x base address invalid");
2419 goto out_disable_resources;
2422 retval = smsc911x_probe_config_dt(&pdata->
config, np);
2423 if (retval && config) {
2430 SMSC_WARN(pdata, probe,
"Error smsc911x config not found");
2431 goto out_disable_resources;
2435 pdata->
ops = &standard_smsc911x_ops;
2438 pdata->
ops = &shifted_smsc911x_ops;
2440 retval = smsc911x_init(dev);
2442 goto out_disable_resources;
2451 smsc911x_reg_write(pdata,
INT_CFG, intcfg);
2454 smsc911x_disable_irq_chip(dev);
2460 "Unable to claim requested irq: %d", dev->
irq);
2461 goto out_disable_resources;
2466 SMSC_WARN(pdata, probe,
"Error %i registering device", retval);
2470 "Network interface: \"%s\"", dev->
name);
2473 retval = smsc911x_mii_init(pdev, dev);
2475 SMSC_WARN(pdata, probe,
"Error %i initialising mii", retval);
2476 goto out_unregister_netdev_5;
2482 if (is_valid_ether_addr(dev->
dev_addr)) {
2483 smsc911x_set_hw_mac_address(pdata, dev->
dev_addr);
2485 "MAC Address is specified by configuration");
2486 }
else if (is_valid_ether_addr(pdata->
config.mac)) {
2489 "MAC Address specified by platform data");
2495 if (is_valid_ether_addr(dev->
dev_addr)) {
2498 "Mac Address is read from LAN911x EEPROM");
2501 eth_hw_addr_random(dev);
2502 smsc911x_set_hw_mac_address(pdata, dev->
dev_addr);
2504 "MAC Address is set to eth_random_addr");
2510 netdev_info(dev,
"MAC Address: %pM\n", dev->
dev_addr);
2514 out_unregister_netdev_5:
2518 out_disable_resources:
2519 (
void)smsc911x_disable_resources(pdev);
2520 out_enable_resources_fail:
2521 smsc911x_free_resources(pdev);
2522 out_request_resources_fail:
2523 platform_set_drvdata(pdev,
NULL);
2538 static int smsc911x_suspend(
struct device *dev)
2545 smsc911x_reg_write(pdata,
PMT_CTRL,
2552 static int smsc911x_resume(
struct device *dev)
2556 unsigned int to = 100;
2562 smsc911x_reg_write(pdata,
BYTE_TEST, 0);
2570 return (to == 0) ? -
EIO : 0;
2573 static const struct dev_pm_ops smsc911x_pm_ops = {
2575 .resume = smsc911x_resume,
2578 #define SMSC911X_PM_OPS (&smsc911x_pm_ops)
2581 #define SMSC911X_PM_OPS NULL
2585 { .compatible =
"smsc,lan9115", },
2591 .probe = smsc911x_drv_probe,
2597 .of_match_table = smsc911x_dt_ids,
2602 static int __init smsc911x_init_module(
void)
2609 static void __exit smsc911x_cleanup_module(
void)