smsc9420.c 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707
  1. /***************************************************************************
  2. *
  3. * Copyright (C) 2007,2008 SMSC
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License
  7. * as published by the Free Software Foundation; either version 2
  8. * of the License, or (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, see <http://www.gnu.org/licenses/>.
  17. *
  18. ***************************************************************************
  19. */
  20. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  21. #include <linux/interrupt.h>
  22. #include <linux/kernel.h>
  23. #include <linux/netdevice.h>
  24. #include <linux/phy.h>
  25. #include <linux/pci.h>
  26. #include <linux/if_vlan.h>
  27. #include <linux/dma-mapping.h>
  28. #include <linux/crc32.h>
  29. #include <linux/slab.h>
  30. #include <linux/module.h>
  31. #include <asm/unaligned.h>
  32. #include "smsc9420.h"
  33. #define DRV_NAME "smsc9420"
  34. #define DRV_MDIONAME "smsc9420-mdio"
  35. #define DRV_DESCRIPTION "SMSC LAN9420 driver"
  36. #define DRV_VERSION "1.01"
  37. MODULE_LICENSE("GPL");
  38. MODULE_VERSION(DRV_VERSION);
  39. struct smsc9420_dma_desc {
  40. u32 status;
  41. u32 length;
  42. u32 buffer1;
  43. u32 buffer2;
  44. };
  45. struct smsc9420_ring_info {
  46. struct sk_buff *skb;
  47. dma_addr_t mapping;
  48. };
  49. struct smsc9420_pdata {
  50. void __iomem *ioaddr;
  51. struct pci_dev *pdev;
  52. struct net_device *dev;
  53. struct smsc9420_dma_desc *rx_ring;
  54. struct smsc9420_dma_desc *tx_ring;
  55. struct smsc9420_ring_info *tx_buffers;
  56. struct smsc9420_ring_info *rx_buffers;
  57. dma_addr_t rx_dma_addr;
  58. dma_addr_t tx_dma_addr;
  59. int tx_ring_head, tx_ring_tail;
  60. int rx_ring_head, rx_ring_tail;
  61. spinlock_t int_lock;
  62. spinlock_t phy_lock;
  63. struct napi_struct napi;
  64. bool software_irq_signal;
  65. bool rx_csum;
  66. u32 msg_enable;
  67. struct mii_bus *mii_bus;
  68. int last_duplex;
  69. int last_carrier;
  70. };
  71. static const struct pci_device_id smsc9420_id_table[] = {
  72. { PCI_VENDOR_ID_9420, PCI_DEVICE_ID_9420, PCI_ANY_ID, PCI_ANY_ID, },
  73. { 0, }
  74. };
  75. MODULE_DEVICE_TABLE(pci, smsc9420_id_table);
  76. #define SMSC_MSG_DEFAULT (NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_LINK)
  77. static uint smsc_debug;
  78. static uint debug = -1;
  79. module_param(debug, uint, 0);
  80. MODULE_PARM_DESC(debug, "debug level");
  81. static inline u32 smsc9420_reg_read(struct smsc9420_pdata *pd, u32 offset)
  82. {
  83. return ioread32(pd->ioaddr + offset);
  84. }
  85. static inline void
  86. smsc9420_reg_write(struct smsc9420_pdata *pd, u32 offset, u32 value)
  87. {
  88. iowrite32(value, pd->ioaddr + offset);
  89. }
  90. static inline void smsc9420_pci_flush_write(struct smsc9420_pdata *pd)
  91. {
  92. /* to ensure PCI write completion, we must perform a PCI read */
  93. smsc9420_reg_read(pd, ID_REV);
  94. }
  95. static int smsc9420_mii_read(struct mii_bus *bus, int phyaddr, int regidx)
  96. {
  97. struct smsc9420_pdata *pd = (struct smsc9420_pdata *)bus->priv;
  98. unsigned long flags;
  99. u32 addr;
  100. int i, reg = -EIO;
  101. spin_lock_irqsave(&pd->phy_lock, flags);
  102. /* confirm MII not busy */
  103. if ((smsc9420_reg_read(pd, MII_ACCESS) & MII_ACCESS_MII_BUSY_)) {
  104. netif_warn(pd, drv, pd->dev, "MII is busy???\n");
  105. goto out;
  106. }
  107. /* set the address, index & direction (read from PHY) */
  108. addr = ((phyaddr & 0x1F) << 11) | ((regidx & 0x1F) << 6) |
  109. MII_ACCESS_MII_READ_;
  110. smsc9420_reg_write(pd, MII_ACCESS, addr);
  111. /* wait for read to complete with 50us timeout */
  112. for (i = 0; i < 5; i++) {
  113. if (!(smsc9420_reg_read(pd, MII_ACCESS) &
  114. MII_ACCESS_MII_BUSY_)) {
  115. reg = (u16)smsc9420_reg_read(pd, MII_DATA);
  116. goto out;
  117. }
  118. udelay(10);
  119. }
  120. netif_warn(pd, drv, pd->dev, "MII busy timeout!\n");
  121. out:
  122. spin_unlock_irqrestore(&pd->phy_lock, flags);
  123. return reg;
  124. }
  125. static int smsc9420_mii_write(struct mii_bus *bus, int phyaddr, int regidx,
  126. u16 val)
  127. {
  128. struct smsc9420_pdata *pd = (struct smsc9420_pdata *)bus->priv;
  129. unsigned long flags;
  130. u32 addr;
  131. int i, reg = -EIO;
  132. spin_lock_irqsave(&pd->phy_lock, flags);
  133. /* confirm MII not busy */
  134. if ((smsc9420_reg_read(pd, MII_ACCESS) & MII_ACCESS_MII_BUSY_)) {
  135. netif_warn(pd, drv, pd->dev, "MII is busy???\n");
  136. goto out;
  137. }
  138. /* put the data to write in the MAC */
  139. smsc9420_reg_write(pd, MII_DATA, (u32)val);
  140. /* set the address, index & direction (write to PHY) */
  141. addr = ((phyaddr & 0x1F) << 11) | ((regidx & 0x1F) << 6) |
  142. MII_ACCESS_MII_WRITE_;
  143. smsc9420_reg_write(pd, MII_ACCESS, addr);
  144. /* wait for write to complete with 50us timeout */
  145. for (i = 0; i < 5; i++) {
  146. if (!(smsc9420_reg_read(pd, MII_ACCESS) &
  147. MII_ACCESS_MII_BUSY_)) {
  148. reg = 0;
  149. goto out;
  150. }
  151. udelay(10);
  152. }
  153. netif_warn(pd, drv, pd->dev, "MII busy timeout!\n");
  154. out:
  155. spin_unlock_irqrestore(&pd->phy_lock, flags);
  156. return reg;
  157. }
  158. /* Returns hash bit number for given MAC address
  159. * Example:
  160. * 01 00 5E 00 00 01 -> returns bit number 31 */
  161. static u32 smsc9420_hash(u8 addr[ETH_ALEN])
  162. {
  163. return (ether_crc(ETH_ALEN, addr) >> 26) & 0x3f;
  164. }
  165. static int smsc9420_eeprom_reload(struct smsc9420_pdata *pd)
  166. {
  167. int timeout = 100000;
  168. BUG_ON(!pd);
  169. if (smsc9420_reg_read(pd, E2P_CMD) & E2P_CMD_EPC_BUSY_) {
  170. netif_dbg(pd, drv, pd->dev, "%s: Eeprom busy\n", __func__);
  171. return -EIO;
  172. }
  173. smsc9420_reg_write(pd, E2P_CMD,
  174. (E2P_CMD_EPC_BUSY_ | E2P_CMD_EPC_CMD_RELOAD_));
  175. do {
  176. udelay(10);
  177. if (!(smsc9420_reg_read(pd, E2P_CMD) & E2P_CMD_EPC_BUSY_))
  178. return 0;
  179. } while (timeout--);
  180. netif_warn(pd, drv, pd->dev, "%s: Eeprom timed out\n", __func__);
  181. return -EIO;
  182. }
  183. /* Standard ioctls for mii-tool */
  184. static int smsc9420_do_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  185. {
  186. if (!netif_running(dev) || !dev->phydev)
  187. return -EINVAL;
  188. return phy_mii_ioctl(dev->phydev, ifr, cmd);
  189. }
  190. static void smsc9420_ethtool_get_drvinfo(struct net_device *netdev,
  191. struct ethtool_drvinfo *drvinfo)
  192. {
  193. struct smsc9420_pdata *pd = netdev_priv(netdev);
  194. strlcpy(drvinfo->driver, DRV_NAME, sizeof(drvinfo->driver));
  195. strlcpy(drvinfo->bus_info, pci_name(pd->pdev),
  196. sizeof(drvinfo->bus_info));
  197. strlcpy(drvinfo->version, DRV_VERSION, sizeof(drvinfo->version));
  198. }
  199. static u32 smsc9420_ethtool_get_msglevel(struct net_device *netdev)
  200. {
  201. struct smsc9420_pdata *pd = netdev_priv(netdev);
  202. return pd->msg_enable;
  203. }
  204. static void smsc9420_ethtool_set_msglevel(struct net_device *netdev, u32 data)
  205. {
  206. struct smsc9420_pdata *pd = netdev_priv(netdev);
  207. pd->msg_enable = data;
  208. }
  209. static int smsc9420_ethtool_getregslen(struct net_device *dev)
  210. {
  211. /* all smsc9420 registers plus all phy registers */
  212. return 0x100 + (32 * sizeof(u32));
  213. }
  214. static void
  215. smsc9420_ethtool_getregs(struct net_device *dev, struct ethtool_regs *regs,
  216. void *buf)
  217. {
  218. struct smsc9420_pdata *pd = netdev_priv(dev);
  219. struct phy_device *phy_dev = dev->phydev;
  220. unsigned int i, j = 0;
  221. u32 *data = buf;
  222. regs->version = smsc9420_reg_read(pd, ID_REV);
  223. for (i = 0; i < 0x100; i += (sizeof(u32)))
  224. data[j++] = smsc9420_reg_read(pd, i);
  225. // cannot read phy registers if the net device is down
  226. if (!phy_dev)
  227. return;
  228. for (i = 0; i <= 31; i++)
  229. data[j++] = smsc9420_mii_read(phy_dev->mdio.bus,
  230. phy_dev->mdio.addr, i);
  231. }
  232. static void smsc9420_eeprom_enable_access(struct smsc9420_pdata *pd)
  233. {
  234. unsigned int temp = smsc9420_reg_read(pd, GPIO_CFG);
  235. temp &= ~GPIO_CFG_EEPR_EN_;
  236. smsc9420_reg_write(pd, GPIO_CFG, temp);
  237. msleep(1);
  238. }
  239. static int smsc9420_eeprom_send_cmd(struct smsc9420_pdata *pd, u32 op)
  240. {
  241. int timeout = 100;
  242. u32 e2cmd;
  243. netif_dbg(pd, hw, pd->dev, "op 0x%08x\n", op);
  244. if (smsc9420_reg_read(pd, E2P_CMD) & E2P_CMD_EPC_BUSY_) {
  245. netif_warn(pd, hw, pd->dev, "Busy at start\n");
  246. return -EBUSY;
  247. }
  248. e2cmd = op | E2P_CMD_EPC_BUSY_;
  249. smsc9420_reg_write(pd, E2P_CMD, e2cmd);
  250. do {
  251. msleep(1);
  252. e2cmd = smsc9420_reg_read(pd, E2P_CMD);
  253. } while ((e2cmd & E2P_CMD_EPC_BUSY_) && (--timeout));
  254. if (!timeout) {
  255. netif_info(pd, hw, pd->dev, "TIMED OUT\n");
  256. return -EAGAIN;
  257. }
  258. if (e2cmd & E2P_CMD_EPC_TIMEOUT_) {
  259. netif_info(pd, hw, pd->dev,
  260. "Error occurred during eeprom operation\n");
  261. return -EINVAL;
  262. }
  263. return 0;
  264. }
  265. static int smsc9420_eeprom_read_location(struct smsc9420_pdata *pd,
  266. u8 address, u8 *data)
  267. {
  268. u32 op = E2P_CMD_EPC_CMD_READ_ | address;
  269. int ret;
  270. netif_dbg(pd, hw, pd->dev, "address 0x%x\n", address);
  271. ret = smsc9420_eeprom_send_cmd(pd, op);
  272. if (!ret)
  273. data[address] = smsc9420_reg_read(pd, E2P_DATA);
  274. return ret;
  275. }
  276. static int smsc9420_eeprom_write_location(struct smsc9420_pdata *pd,
  277. u8 address, u8 data)
  278. {
  279. u32 op = E2P_CMD_EPC_CMD_ERASE_ | address;
  280. int ret;
  281. netif_dbg(pd, hw, pd->dev, "address 0x%x, data 0x%x\n", address, data);
  282. ret = smsc9420_eeprom_send_cmd(pd, op);
  283. if (!ret) {
  284. op = E2P_CMD_EPC_CMD_WRITE_ | address;
  285. smsc9420_reg_write(pd, E2P_DATA, (u32)data);
  286. ret = smsc9420_eeprom_send_cmd(pd, op);
  287. }
  288. return ret;
  289. }
  290. static int smsc9420_ethtool_get_eeprom_len(struct net_device *dev)
  291. {
  292. return SMSC9420_EEPROM_SIZE;
  293. }
  294. static int smsc9420_ethtool_get_eeprom(struct net_device *dev,
  295. struct ethtool_eeprom *eeprom, u8 *data)
  296. {
  297. struct smsc9420_pdata *pd = netdev_priv(dev);
  298. u8 eeprom_data[SMSC9420_EEPROM_SIZE];
  299. int len, i;
  300. smsc9420_eeprom_enable_access(pd);
  301. len = min(eeprom->len, SMSC9420_EEPROM_SIZE);
  302. for (i = 0; i < len; i++) {
  303. int ret = smsc9420_eeprom_read_location(pd, i, eeprom_data);
  304. if (ret < 0) {
  305. eeprom->len = 0;
  306. return ret;
  307. }
  308. }
  309. memcpy(data, &eeprom_data[eeprom->offset], len);
  310. eeprom->magic = SMSC9420_EEPROM_MAGIC;
  311. eeprom->len = len;
  312. return 0;
  313. }
  314. static int smsc9420_ethtool_set_eeprom(struct net_device *dev,
  315. struct ethtool_eeprom *eeprom, u8 *data)
  316. {
  317. struct smsc9420_pdata *pd = netdev_priv(dev);
  318. int ret;
  319. if (eeprom->magic != SMSC9420_EEPROM_MAGIC)
  320. return -EINVAL;
  321. smsc9420_eeprom_enable_access(pd);
  322. smsc9420_eeprom_send_cmd(pd, E2P_CMD_EPC_CMD_EWEN_);
  323. ret = smsc9420_eeprom_write_location(pd, eeprom->offset, *data);
  324. smsc9420_eeprom_send_cmd(pd, E2P_CMD_EPC_CMD_EWDS_);
  325. /* Single byte write, according to man page */
  326. eeprom->len = 1;
  327. return ret;
  328. }
  329. static const struct ethtool_ops smsc9420_ethtool_ops = {
  330. .get_drvinfo = smsc9420_ethtool_get_drvinfo,
  331. .get_msglevel = smsc9420_ethtool_get_msglevel,
  332. .set_msglevel = smsc9420_ethtool_set_msglevel,
  333. .nway_reset = phy_ethtool_nway_reset,
  334. .get_link = ethtool_op_get_link,
  335. .get_eeprom_len = smsc9420_ethtool_get_eeprom_len,
  336. .get_eeprom = smsc9420_ethtool_get_eeprom,
  337. .set_eeprom = smsc9420_ethtool_set_eeprom,
  338. .get_regs_len = smsc9420_ethtool_getregslen,
  339. .get_regs = smsc9420_ethtool_getregs,
  340. .get_ts_info = ethtool_op_get_ts_info,
  341. .get_link_ksettings = phy_ethtool_get_link_ksettings,
  342. .set_link_ksettings = phy_ethtool_set_link_ksettings,
  343. };
  344. /* Sets the device MAC address to dev_addr */
  345. static void smsc9420_set_mac_address(struct net_device *dev)
  346. {
  347. struct smsc9420_pdata *pd = netdev_priv(dev);
  348. u8 *dev_addr = dev->dev_addr;
  349. u32 mac_high16 = (dev_addr[5] << 8) | dev_addr[4];
  350. u32 mac_low32 = (dev_addr[3] << 24) | (dev_addr[2] << 16) |
  351. (dev_addr[1] << 8) | dev_addr[0];
  352. smsc9420_reg_write(pd, ADDRH, mac_high16);
  353. smsc9420_reg_write(pd, ADDRL, mac_low32);
  354. }
  355. static void smsc9420_check_mac_address(struct net_device *dev)
  356. {
  357. struct smsc9420_pdata *pd = netdev_priv(dev);
  358. /* Check if mac address has been specified when bringing interface up */
  359. if (is_valid_ether_addr(dev->dev_addr)) {
  360. smsc9420_set_mac_address(dev);
  361. netif_dbg(pd, probe, pd->dev,
  362. "MAC Address is specified by configuration\n");
  363. } else {
  364. /* Try reading mac address from device. if EEPROM is present
  365. * it will already have been set */
  366. u32 mac_high16 = smsc9420_reg_read(pd, ADDRH);
  367. u32 mac_low32 = smsc9420_reg_read(pd, ADDRL);
  368. dev->dev_addr[0] = (u8)(mac_low32);
  369. dev->dev_addr[1] = (u8)(mac_low32 >> 8);
  370. dev->dev_addr[2] = (u8)(mac_low32 >> 16);
  371. dev->dev_addr[3] = (u8)(mac_low32 >> 24);
  372. dev->dev_addr[4] = (u8)(mac_high16);
  373. dev->dev_addr[5] = (u8)(mac_high16 >> 8);
  374. if (is_valid_ether_addr(dev->dev_addr)) {
  375. /* eeprom values are valid so use them */
  376. netif_dbg(pd, probe, pd->dev,
  377. "Mac Address is read from EEPROM\n");
  378. } else {
  379. /* eeprom values are invalid, generate random MAC */
  380. eth_hw_addr_random(dev);
  381. smsc9420_set_mac_address(dev);
  382. netif_dbg(pd, probe, pd->dev,
  383. "MAC Address is set to random\n");
  384. }
  385. }
  386. }
  387. static void smsc9420_stop_tx(struct smsc9420_pdata *pd)
  388. {
  389. u32 dmac_control, mac_cr, dma_intr_ena;
  390. int timeout = 1000;
  391. /* disable TX DMAC */
  392. dmac_control = smsc9420_reg_read(pd, DMAC_CONTROL);
  393. dmac_control &= (~DMAC_CONTROL_ST_);
  394. smsc9420_reg_write(pd, DMAC_CONTROL, dmac_control);
  395. /* Wait max 10ms for transmit process to stop */
  396. while (--timeout) {
  397. if (smsc9420_reg_read(pd, DMAC_STATUS) & DMAC_STS_TS_)
  398. break;
  399. udelay(10);
  400. }
  401. if (!timeout)
  402. netif_warn(pd, ifdown, pd->dev, "TX DMAC failed to stop\n");
  403. /* ACK Tx DMAC stop bit */
  404. smsc9420_reg_write(pd, DMAC_STATUS, DMAC_STS_TXPS_);
  405. /* mask TX DMAC interrupts */
  406. dma_intr_ena = smsc9420_reg_read(pd, DMAC_INTR_ENA);
  407. dma_intr_ena &= ~(DMAC_INTR_ENA_TX_);
  408. smsc9420_reg_write(pd, DMAC_INTR_ENA, dma_intr_ena);
  409. smsc9420_pci_flush_write(pd);
  410. /* stop MAC TX */
  411. mac_cr = smsc9420_reg_read(pd, MAC_CR) & (~MAC_CR_TXEN_);
  412. smsc9420_reg_write(pd, MAC_CR, mac_cr);
  413. smsc9420_pci_flush_write(pd);
  414. }
  415. static void smsc9420_free_tx_ring(struct smsc9420_pdata *pd)
  416. {
  417. int i;
  418. BUG_ON(!pd->tx_ring);
  419. if (!pd->tx_buffers)
  420. return;
  421. for (i = 0; i < TX_RING_SIZE; i++) {
  422. struct sk_buff *skb = pd->tx_buffers[i].skb;
  423. if (skb) {
  424. BUG_ON(!pd->tx_buffers[i].mapping);
  425. pci_unmap_single(pd->pdev, pd->tx_buffers[i].mapping,
  426. skb->len, PCI_DMA_TODEVICE);
  427. dev_kfree_skb_any(skb);
  428. }
  429. pd->tx_ring[i].status = 0;
  430. pd->tx_ring[i].length = 0;
  431. pd->tx_ring[i].buffer1 = 0;
  432. pd->tx_ring[i].buffer2 = 0;
  433. }
  434. wmb();
  435. kfree(pd->tx_buffers);
  436. pd->tx_buffers = NULL;
  437. pd->tx_ring_head = 0;
  438. pd->tx_ring_tail = 0;
  439. }
  440. static void smsc9420_free_rx_ring(struct smsc9420_pdata *pd)
  441. {
  442. int i;
  443. BUG_ON(!pd->rx_ring);
  444. if (!pd->rx_buffers)
  445. return;
  446. for (i = 0; i < RX_RING_SIZE; i++) {
  447. if (pd->rx_buffers[i].skb)
  448. dev_kfree_skb_any(pd->rx_buffers[i].skb);
  449. if (pd->rx_buffers[i].mapping)
  450. pci_unmap_single(pd->pdev, pd->rx_buffers[i].mapping,
  451. PKT_BUF_SZ, PCI_DMA_FROMDEVICE);
  452. pd->rx_ring[i].status = 0;
  453. pd->rx_ring[i].length = 0;
  454. pd->rx_ring[i].buffer1 = 0;
  455. pd->rx_ring[i].buffer2 = 0;
  456. }
  457. wmb();
  458. kfree(pd->rx_buffers);
  459. pd->rx_buffers = NULL;
  460. pd->rx_ring_head = 0;
  461. pd->rx_ring_tail = 0;
  462. }
  463. static void smsc9420_stop_rx(struct smsc9420_pdata *pd)
  464. {
  465. int timeout = 1000;
  466. u32 mac_cr, dmac_control, dma_intr_ena;
  467. /* mask RX DMAC interrupts */
  468. dma_intr_ena = smsc9420_reg_read(pd, DMAC_INTR_ENA);
  469. dma_intr_ena &= (~DMAC_INTR_ENA_RX_);
  470. smsc9420_reg_write(pd, DMAC_INTR_ENA, dma_intr_ena);
  471. smsc9420_pci_flush_write(pd);
  472. /* stop RX MAC prior to stoping DMA */
  473. mac_cr = smsc9420_reg_read(pd, MAC_CR) & (~MAC_CR_RXEN_);
  474. smsc9420_reg_write(pd, MAC_CR, mac_cr);
  475. smsc9420_pci_flush_write(pd);
  476. /* stop RX DMAC */
  477. dmac_control = smsc9420_reg_read(pd, DMAC_CONTROL);
  478. dmac_control &= (~DMAC_CONTROL_SR_);
  479. smsc9420_reg_write(pd, DMAC_CONTROL, dmac_control);
  480. smsc9420_pci_flush_write(pd);
  481. /* wait up to 10ms for receive to stop */
  482. while (--timeout) {
  483. if (smsc9420_reg_read(pd, DMAC_STATUS) & DMAC_STS_RS_)
  484. break;
  485. udelay(10);
  486. }
  487. if (!timeout)
  488. netif_warn(pd, ifdown, pd->dev,
  489. "RX DMAC did not stop! timeout\n");
  490. /* ACK the Rx DMAC stop bit */
  491. smsc9420_reg_write(pd, DMAC_STATUS, DMAC_STS_RXPS_);
  492. }
  493. static irqreturn_t smsc9420_isr(int irq, void *dev_id)
  494. {
  495. struct smsc9420_pdata *pd = dev_id;
  496. u32 int_cfg, int_sts, int_ctl;
  497. irqreturn_t ret = IRQ_NONE;
  498. ulong flags;
  499. BUG_ON(!pd);
  500. BUG_ON(!pd->ioaddr);
  501. int_cfg = smsc9420_reg_read(pd, INT_CFG);
  502. /* check if it's our interrupt */
  503. if ((int_cfg & (INT_CFG_IRQ_EN_ | INT_CFG_IRQ_INT_)) !=
  504. (INT_CFG_IRQ_EN_ | INT_CFG_IRQ_INT_))
  505. return IRQ_NONE;
  506. int_sts = smsc9420_reg_read(pd, INT_STAT);
  507. if (likely(INT_STAT_DMAC_INT_ & int_sts)) {
  508. u32 status = smsc9420_reg_read(pd, DMAC_STATUS);
  509. u32 ints_to_clear = 0;
  510. if (status & DMAC_STS_TX_) {
  511. ints_to_clear |= (DMAC_STS_TX_ | DMAC_STS_NIS_);
  512. netif_wake_queue(pd->dev);
  513. }
  514. if (status & DMAC_STS_RX_) {
  515. /* mask RX DMAC interrupts */
  516. u32 dma_intr_ena = smsc9420_reg_read(pd, DMAC_INTR_ENA);
  517. dma_intr_ena &= (~DMAC_INTR_ENA_RX_);
  518. smsc9420_reg_write(pd, DMAC_INTR_ENA, dma_intr_ena);
  519. smsc9420_pci_flush_write(pd);
  520. ints_to_clear |= (DMAC_STS_RX_ | DMAC_STS_NIS_);
  521. napi_schedule(&pd->napi);
  522. }
  523. if (ints_to_clear)
  524. smsc9420_reg_write(pd, DMAC_STATUS, ints_to_clear);
  525. ret = IRQ_HANDLED;
  526. }
  527. if (unlikely(INT_STAT_SW_INT_ & int_sts)) {
  528. /* mask software interrupt */
  529. spin_lock_irqsave(&pd->int_lock, flags);
  530. int_ctl = smsc9420_reg_read(pd, INT_CTL);
  531. int_ctl &= (~INT_CTL_SW_INT_EN_);
  532. smsc9420_reg_write(pd, INT_CTL, int_ctl);
  533. spin_unlock_irqrestore(&pd->int_lock, flags);
  534. smsc9420_reg_write(pd, INT_STAT, INT_STAT_SW_INT_);
  535. pd->software_irq_signal = true;
  536. smp_wmb();
  537. ret = IRQ_HANDLED;
  538. }
  539. /* to ensure PCI write completion, we must perform a PCI read */
  540. smsc9420_pci_flush_write(pd);
  541. return ret;
  542. }
  543. #ifdef CONFIG_NET_POLL_CONTROLLER
  544. static void smsc9420_poll_controller(struct net_device *dev)
  545. {
  546. struct smsc9420_pdata *pd = netdev_priv(dev);
  547. const int irq = pd->pdev->irq;
  548. disable_irq(irq);
  549. smsc9420_isr(0, dev);
  550. enable_irq(irq);
  551. }
  552. #endif /* CONFIG_NET_POLL_CONTROLLER */
  553. static void smsc9420_dmac_soft_reset(struct smsc9420_pdata *pd)
  554. {
  555. smsc9420_reg_write(pd, BUS_MODE, BUS_MODE_SWR_);
  556. smsc9420_reg_read(pd, BUS_MODE);
  557. udelay(2);
  558. if (smsc9420_reg_read(pd, BUS_MODE) & BUS_MODE_SWR_)
  559. netif_warn(pd, drv, pd->dev, "Software reset not cleared\n");
  560. }
  561. static int smsc9420_stop(struct net_device *dev)
  562. {
  563. struct smsc9420_pdata *pd = netdev_priv(dev);
  564. u32 int_cfg;
  565. ulong flags;
  566. BUG_ON(!pd);
  567. BUG_ON(!dev->phydev);
  568. /* disable master interrupt */
  569. spin_lock_irqsave(&pd->int_lock, flags);
  570. int_cfg = smsc9420_reg_read(pd, INT_CFG) & (~INT_CFG_IRQ_EN_);
  571. smsc9420_reg_write(pd, INT_CFG, int_cfg);
  572. spin_unlock_irqrestore(&pd->int_lock, flags);
  573. netif_tx_disable(dev);
  574. napi_disable(&pd->napi);
  575. smsc9420_stop_tx(pd);
  576. smsc9420_free_tx_ring(pd);
  577. smsc9420_stop_rx(pd);
  578. smsc9420_free_rx_ring(pd);
  579. free_irq(pd->pdev->irq, pd);
  580. smsc9420_dmac_soft_reset(pd);
  581. phy_stop(dev->phydev);
  582. phy_disconnect(dev->phydev);
  583. mdiobus_unregister(pd->mii_bus);
  584. mdiobus_free(pd->mii_bus);
  585. return 0;
  586. }
  587. static void smsc9420_rx_count_stats(struct net_device *dev, u32 desc_status)
  588. {
  589. if (unlikely(desc_status & RDES0_ERROR_SUMMARY_)) {
  590. dev->stats.rx_errors++;
  591. if (desc_status & RDES0_DESCRIPTOR_ERROR_)
  592. dev->stats.rx_over_errors++;
  593. else if (desc_status & (RDES0_FRAME_TOO_LONG_ |
  594. RDES0_RUNT_FRAME_ | RDES0_COLLISION_SEEN_))
  595. dev->stats.rx_frame_errors++;
  596. else if (desc_status & RDES0_CRC_ERROR_)
  597. dev->stats.rx_crc_errors++;
  598. }
  599. if (unlikely(desc_status & RDES0_LENGTH_ERROR_))
  600. dev->stats.rx_length_errors++;
  601. if (unlikely(!((desc_status & RDES0_LAST_DESCRIPTOR_) &&
  602. (desc_status & RDES0_FIRST_DESCRIPTOR_))))
  603. dev->stats.rx_length_errors++;
  604. if (desc_status & RDES0_MULTICAST_FRAME_)
  605. dev->stats.multicast++;
  606. }
  607. static void smsc9420_rx_handoff(struct smsc9420_pdata *pd, const int index,
  608. const u32 status)
  609. {
  610. struct net_device *dev = pd->dev;
  611. struct sk_buff *skb;
  612. u16 packet_length = (status & RDES0_FRAME_LENGTH_MASK_)
  613. >> RDES0_FRAME_LENGTH_SHFT_;
  614. /* remove crc from packet lendth */
  615. packet_length -= 4;
  616. if (pd->rx_csum)
  617. packet_length -= 2;
  618. dev->stats.rx_packets++;
  619. dev->stats.rx_bytes += packet_length;
  620. pci_unmap_single(pd->pdev, pd->rx_buffers[index].mapping,
  621. PKT_BUF_SZ, PCI_DMA_FROMDEVICE);
  622. pd->rx_buffers[index].mapping = 0;
  623. skb = pd->rx_buffers[index].skb;
  624. pd->rx_buffers[index].skb = NULL;
  625. if (pd->rx_csum) {
  626. u16 hw_csum = get_unaligned_le16(skb_tail_pointer(skb) +
  627. NET_IP_ALIGN + packet_length + 4);
  628. put_unaligned_le16(hw_csum, &skb->csum);
  629. skb->ip_summed = CHECKSUM_COMPLETE;
  630. }
  631. skb_reserve(skb, NET_IP_ALIGN);
  632. skb_put(skb, packet_length);
  633. skb->protocol = eth_type_trans(skb, dev);
  634. netif_receive_skb(skb);
  635. }
  636. static int smsc9420_alloc_rx_buffer(struct smsc9420_pdata *pd, int index)
  637. {
  638. struct sk_buff *skb = netdev_alloc_skb(pd->dev, PKT_BUF_SZ);
  639. dma_addr_t mapping;
  640. BUG_ON(pd->rx_buffers[index].skb);
  641. BUG_ON(pd->rx_buffers[index].mapping);
  642. if (unlikely(!skb))
  643. return -ENOMEM;
  644. mapping = pci_map_single(pd->pdev, skb_tail_pointer(skb),
  645. PKT_BUF_SZ, PCI_DMA_FROMDEVICE);
  646. if (pci_dma_mapping_error(pd->pdev, mapping)) {
  647. dev_kfree_skb_any(skb);
  648. netif_warn(pd, rx_err, pd->dev, "pci_map_single failed!\n");
  649. return -ENOMEM;
  650. }
  651. pd->rx_buffers[index].skb = skb;
  652. pd->rx_buffers[index].mapping = mapping;
  653. pd->rx_ring[index].buffer1 = mapping + NET_IP_ALIGN;
  654. pd->rx_ring[index].status = RDES0_OWN_;
  655. wmb();
  656. return 0;
  657. }
  658. static void smsc9420_alloc_new_rx_buffers(struct smsc9420_pdata *pd)
  659. {
  660. while (pd->rx_ring_tail != pd->rx_ring_head) {
  661. if (smsc9420_alloc_rx_buffer(pd, pd->rx_ring_tail))
  662. break;
  663. pd->rx_ring_tail = (pd->rx_ring_tail + 1) % RX_RING_SIZE;
  664. }
  665. }
  666. static int smsc9420_rx_poll(struct napi_struct *napi, int budget)
  667. {
  668. struct smsc9420_pdata *pd =
  669. container_of(napi, struct smsc9420_pdata, napi);
  670. struct net_device *dev = pd->dev;
  671. u32 drop_frame_cnt, dma_intr_ena, status;
  672. int work_done;
  673. for (work_done = 0; work_done < budget; work_done++) {
  674. rmb();
  675. status = pd->rx_ring[pd->rx_ring_head].status;
  676. /* stop if DMAC owns this dma descriptor */
  677. if (status & RDES0_OWN_)
  678. break;
  679. smsc9420_rx_count_stats(dev, status);
  680. smsc9420_rx_handoff(pd, pd->rx_ring_head, status);
  681. pd->rx_ring_head = (pd->rx_ring_head + 1) % RX_RING_SIZE;
  682. smsc9420_alloc_new_rx_buffers(pd);
  683. }
  684. drop_frame_cnt = smsc9420_reg_read(pd, MISS_FRAME_CNTR);
  685. dev->stats.rx_dropped +=
  686. (drop_frame_cnt & 0xFFFF) + ((drop_frame_cnt >> 17) & 0x3FF);
  687. /* Kick RXDMA */
  688. smsc9420_reg_write(pd, RX_POLL_DEMAND, 1);
  689. smsc9420_pci_flush_write(pd);
  690. if (work_done < budget) {
  691. napi_complete_done(&pd->napi, work_done);
  692. /* re-enable RX DMA interrupts */
  693. dma_intr_ena = smsc9420_reg_read(pd, DMAC_INTR_ENA);
  694. dma_intr_ena |= (DMAC_INTR_ENA_RX_ | DMAC_INTR_ENA_NIS_);
  695. smsc9420_reg_write(pd, DMAC_INTR_ENA, dma_intr_ena);
  696. smsc9420_pci_flush_write(pd);
  697. }
  698. return work_done;
  699. }
  700. static void
  701. smsc9420_tx_update_stats(struct net_device *dev, u32 status, u32 length)
  702. {
  703. if (unlikely(status & TDES0_ERROR_SUMMARY_)) {
  704. dev->stats.tx_errors++;
  705. if (status & (TDES0_EXCESSIVE_DEFERRAL_ |
  706. TDES0_EXCESSIVE_COLLISIONS_))
  707. dev->stats.tx_aborted_errors++;
  708. if (status & (TDES0_LOSS_OF_CARRIER_ | TDES0_NO_CARRIER_))
  709. dev->stats.tx_carrier_errors++;
  710. } else {
  711. dev->stats.tx_packets++;
  712. dev->stats.tx_bytes += (length & 0x7FF);
  713. }
  714. if (unlikely(status & TDES0_EXCESSIVE_COLLISIONS_)) {
  715. dev->stats.collisions += 16;
  716. } else {
  717. dev->stats.collisions +=
  718. (status & TDES0_COLLISION_COUNT_MASK_) >>
  719. TDES0_COLLISION_COUNT_SHFT_;
  720. }
  721. if (unlikely(status & TDES0_HEARTBEAT_FAIL_))
  722. dev->stats.tx_heartbeat_errors++;
  723. }
  724. /* Check for completed dma transfers, update stats and free skbs */
  725. static void smsc9420_complete_tx(struct net_device *dev)
  726. {
  727. struct smsc9420_pdata *pd = netdev_priv(dev);
  728. while (pd->tx_ring_tail != pd->tx_ring_head) {
  729. int index = pd->tx_ring_tail;
  730. u32 status, length;
  731. rmb();
  732. status = pd->tx_ring[index].status;
  733. length = pd->tx_ring[index].length;
  734. /* Check if DMA still owns this descriptor */
  735. if (unlikely(TDES0_OWN_ & status))
  736. break;
  737. smsc9420_tx_update_stats(dev, status, length);
  738. BUG_ON(!pd->tx_buffers[index].skb);
  739. BUG_ON(!pd->tx_buffers[index].mapping);
  740. pci_unmap_single(pd->pdev, pd->tx_buffers[index].mapping,
  741. pd->tx_buffers[index].skb->len, PCI_DMA_TODEVICE);
  742. pd->tx_buffers[index].mapping = 0;
  743. dev_kfree_skb_any(pd->tx_buffers[index].skb);
  744. pd->tx_buffers[index].skb = NULL;
  745. pd->tx_ring[index].buffer1 = 0;
  746. wmb();
  747. pd->tx_ring_tail = (pd->tx_ring_tail + 1) % TX_RING_SIZE;
  748. }
  749. }
  750. static netdev_tx_t smsc9420_hard_start_xmit(struct sk_buff *skb,
  751. struct net_device *dev)
  752. {
  753. struct smsc9420_pdata *pd = netdev_priv(dev);
  754. dma_addr_t mapping;
  755. int index = pd->tx_ring_head;
  756. u32 tmp_desc1;
  757. bool about_to_take_last_desc =
  758. (((pd->tx_ring_head + 2) % TX_RING_SIZE) == pd->tx_ring_tail);
  759. smsc9420_complete_tx(dev);
  760. rmb();
  761. BUG_ON(pd->tx_ring[index].status & TDES0_OWN_);
  762. BUG_ON(pd->tx_buffers[index].skb);
  763. BUG_ON(pd->tx_buffers[index].mapping);
  764. mapping = pci_map_single(pd->pdev, skb->data,
  765. skb->len, PCI_DMA_TODEVICE);
  766. if (pci_dma_mapping_error(pd->pdev, mapping)) {
  767. netif_warn(pd, tx_err, pd->dev,
  768. "pci_map_single failed, dropping packet\n");
  769. return NETDEV_TX_BUSY;
  770. }
  771. pd->tx_buffers[index].skb = skb;
  772. pd->tx_buffers[index].mapping = mapping;
  773. tmp_desc1 = (TDES1_LS_ | ((u32)skb->len & 0x7FF));
  774. if (unlikely(about_to_take_last_desc)) {
  775. tmp_desc1 |= TDES1_IC_;
  776. netif_stop_queue(pd->dev);
  777. }
  778. /* check if we are at the last descriptor and need to set EOR */
  779. if (unlikely(index == (TX_RING_SIZE - 1)))
  780. tmp_desc1 |= TDES1_TER_;
  781. pd->tx_ring[index].buffer1 = mapping;
  782. pd->tx_ring[index].length = tmp_desc1;
  783. wmb();
  784. /* increment head */
  785. pd->tx_ring_head = (pd->tx_ring_head + 1) % TX_RING_SIZE;
  786. /* assign ownership to DMAC */
  787. pd->tx_ring[index].status = TDES0_OWN_;
  788. wmb();
  789. skb_tx_timestamp(skb);
  790. /* kick the DMA */
  791. smsc9420_reg_write(pd, TX_POLL_DEMAND, 1);
  792. smsc9420_pci_flush_write(pd);
  793. return NETDEV_TX_OK;
  794. }
  795. static struct net_device_stats *smsc9420_get_stats(struct net_device *dev)
  796. {
  797. struct smsc9420_pdata *pd = netdev_priv(dev);
  798. u32 counter = smsc9420_reg_read(pd, MISS_FRAME_CNTR);
  799. dev->stats.rx_dropped +=
  800. (counter & 0x0000FFFF) + ((counter >> 17) & 0x000003FF);
  801. return &dev->stats;
  802. }
  803. static void smsc9420_set_multicast_list(struct net_device *dev)
  804. {
  805. struct smsc9420_pdata *pd = netdev_priv(dev);
  806. u32 mac_cr = smsc9420_reg_read(pd, MAC_CR);
  807. if (dev->flags & IFF_PROMISC) {
  808. netif_dbg(pd, hw, pd->dev, "Promiscuous Mode Enabled\n");
  809. mac_cr |= MAC_CR_PRMS_;
  810. mac_cr &= (~MAC_CR_MCPAS_);
  811. mac_cr &= (~MAC_CR_HPFILT_);
  812. } else if (dev->flags & IFF_ALLMULTI) {
  813. netif_dbg(pd, hw, pd->dev, "Receive all Multicast Enabled\n");
  814. mac_cr &= (~MAC_CR_PRMS_);
  815. mac_cr |= MAC_CR_MCPAS_;
  816. mac_cr &= (~MAC_CR_HPFILT_);
  817. } else if (!netdev_mc_empty(dev)) {
  818. struct netdev_hw_addr *ha;
  819. u32 hash_lo = 0, hash_hi = 0;
  820. netif_dbg(pd, hw, pd->dev, "Multicast filter enabled\n");
  821. netdev_for_each_mc_addr(ha, dev) {
  822. u32 bit_num = smsc9420_hash(ha->addr);
  823. u32 mask = 1 << (bit_num & 0x1F);
  824. if (bit_num & 0x20)
  825. hash_hi |= mask;
  826. else
  827. hash_lo |= mask;
  828. }
  829. smsc9420_reg_write(pd, HASHH, hash_hi);
  830. smsc9420_reg_write(pd, HASHL, hash_lo);
  831. mac_cr &= (~MAC_CR_PRMS_);
  832. mac_cr &= (~MAC_CR_MCPAS_);
  833. mac_cr |= MAC_CR_HPFILT_;
  834. } else {
  835. netif_dbg(pd, hw, pd->dev, "Receive own packets only\n");
  836. smsc9420_reg_write(pd, HASHH, 0);
  837. smsc9420_reg_write(pd, HASHL, 0);
  838. mac_cr &= (~MAC_CR_PRMS_);
  839. mac_cr &= (~MAC_CR_MCPAS_);
  840. mac_cr &= (~MAC_CR_HPFILT_);
  841. }
  842. smsc9420_reg_write(pd, MAC_CR, mac_cr);
  843. smsc9420_pci_flush_write(pd);
  844. }
  845. static void smsc9420_phy_update_flowcontrol(struct smsc9420_pdata *pd)
  846. {
  847. struct net_device *dev = pd->dev;
  848. struct phy_device *phy_dev = dev->phydev;
  849. u32 flow;
  850. if (phy_dev->duplex == DUPLEX_FULL) {
  851. u16 lcladv = phy_read(phy_dev, MII_ADVERTISE);
  852. u16 rmtadv = phy_read(phy_dev, MII_LPA);
  853. u8 cap = mii_resolve_flowctrl_fdx(lcladv, rmtadv);
  854. if (cap & FLOW_CTRL_RX)
  855. flow = 0xFFFF0002;
  856. else
  857. flow = 0;
  858. netif_info(pd, link, pd->dev, "rx pause %s, tx pause %s\n",
  859. cap & FLOW_CTRL_RX ? "enabled" : "disabled",
  860. cap & FLOW_CTRL_TX ? "enabled" : "disabled");
  861. } else {
  862. netif_info(pd, link, pd->dev, "half duplex\n");
  863. flow = 0;
  864. }
  865. smsc9420_reg_write(pd, FLOW, flow);
  866. }
  867. /* Update link mode if anything has changed. Called periodically when the
  868. * PHY is in polling mode, even if nothing has changed. */
  869. static void smsc9420_phy_adjust_link(struct net_device *dev)
  870. {
  871. struct smsc9420_pdata *pd = netdev_priv(dev);
  872. struct phy_device *phy_dev = dev->phydev;
  873. int carrier;
  874. if (phy_dev->duplex != pd->last_duplex) {
  875. u32 mac_cr = smsc9420_reg_read(pd, MAC_CR);
  876. if (phy_dev->duplex) {
  877. netif_dbg(pd, link, pd->dev, "full duplex mode\n");
  878. mac_cr |= MAC_CR_FDPX_;
  879. } else {
  880. netif_dbg(pd, link, pd->dev, "half duplex mode\n");
  881. mac_cr &= ~MAC_CR_FDPX_;
  882. }
  883. smsc9420_reg_write(pd, MAC_CR, mac_cr);
  884. smsc9420_phy_update_flowcontrol(pd);
  885. pd->last_duplex = phy_dev->duplex;
  886. }
  887. carrier = netif_carrier_ok(dev);
  888. if (carrier != pd->last_carrier) {
  889. if (carrier)
  890. netif_dbg(pd, link, pd->dev, "carrier OK\n");
  891. else
  892. netif_dbg(pd, link, pd->dev, "no carrier\n");
  893. pd->last_carrier = carrier;
  894. }
  895. }
  896. static int smsc9420_mii_probe(struct net_device *dev)
  897. {
  898. struct smsc9420_pdata *pd = netdev_priv(dev);
  899. struct phy_device *phydev = NULL;
  900. BUG_ON(dev->phydev);
  901. /* Device only supports internal PHY at address 1 */
  902. phydev = mdiobus_get_phy(pd->mii_bus, 1);
  903. if (!phydev) {
  904. netdev_err(dev, "no PHY found at address 1\n");
  905. return -ENODEV;
  906. }
  907. phydev = phy_connect(dev, phydev_name(phydev),
  908. smsc9420_phy_adjust_link, PHY_INTERFACE_MODE_MII);
  909. if (IS_ERR(phydev)) {
  910. netdev_err(dev, "Could not attach to PHY\n");
  911. return PTR_ERR(phydev);
  912. }
  913. /* mask with MAC supported features */
  914. phydev->supported &= (PHY_BASIC_FEATURES | SUPPORTED_Pause |
  915. SUPPORTED_Asym_Pause);
  916. phydev->advertising = phydev->supported;
  917. phy_attached_info(phydev);
  918. pd->last_duplex = -1;
  919. pd->last_carrier = -1;
  920. return 0;
  921. }
  922. static int smsc9420_mii_init(struct net_device *dev)
  923. {
  924. struct smsc9420_pdata *pd = netdev_priv(dev);
  925. int err = -ENXIO;
  926. pd->mii_bus = mdiobus_alloc();
  927. if (!pd->mii_bus) {
  928. err = -ENOMEM;
  929. goto err_out_1;
  930. }
  931. pd->mii_bus->name = DRV_MDIONAME;
  932. snprintf(pd->mii_bus->id, MII_BUS_ID_SIZE, "%x",
  933. (pd->pdev->bus->number << 8) | pd->pdev->devfn);
  934. pd->mii_bus->priv = pd;
  935. pd->mii_bus->read = smsc9420_mii_read;
  936. pd->mii_bus->write = smsc9420_mii_write;
  937. /* Mask all PHYs except ID 1 (internal) */
  938. pd->mii_bus->phy_mask = ~(1 << 1);
  939. if (mdiobus_register(pd->mii_bus)) {
  940. netif_warn(pd, probe, pd->dev, "Error registering mii bus\n");
  941. goto err_out_free_bus_2;
  942. }
  943. if (smsc9420_mii_probe(dev) < 0) {
  944. netif_warn(pd, probe, pd->dev, "Error probing mii bus\n");
  945. goto err_out_unregister_bus_3;
  946. }
  947. return 0;
  948. err_out_unregister_bus_3:
  949. mdiobus_unregister(pd->mii_bus);
  950. err_out_free_bus_2:
  951. mdiobus_free(pd->mii_bus);
  952. err_out_1:
  953. return err;
  954. }
  955. static int smsc9420_alloc_tx_ring(struct smsc9420_pdata *pd)
  956. {
  957. int i;
  958. BUG_ON(!pd->tx_ring);
  959. pd->tx_buffers = kmalloc_array(TX_RING_SIZE,
  960. sizeof(struct smsc9420_ring_info),
  961. GFP_KERNEL);
  962. if (!pd->tx_buffers)
  963. return -ENOMEM;
  964. /* Initialize the TX Ring */
  965. for (i = 0; i < TX_RING_SIZE; i++) {
  966. pd->tx_buffers[i].skb = NULL;
  967. pd->tx_buffers[i].mapping = 0;
  968. pd->tx_ring[i].status = 0;
  969. pd->tx_ring[i].length = 0;
  970. pd->tx_ring[i].buffer1 = 0;
  971. pd->tx_ring[i].buffer2 = 0;
  972. }
  973. pd->tx_ring[TX_RING_SIZE - 1].length = TDES1_TER_;
  974. wmb();
  975. pd->tx_ring_head = 0;
  976. pd->tx_ring_tail = 0;
  977. smsc9420_reg_write(pd, TX_BASE_ADDR, pd->tx_dma_addr);
  978. smsc9420_pci_flush_write(pd);
  979. return 0;
  980. }
  981. static int smsc9420_alloc_rx_ring(struct smsc9420_pdata *pd)
  982. {
  983. int i;
  984. BUG_ON(!pd->rx_ring);
  985. pd->rx_buffers = kmalloc_array(RX_RING_SIZE,
  986. sizeof(struct smsc9420_ring_info),
  987. GFP_KERNEL);
  988. if (pd->rx_buffers == NULL)
  989. goto out;
  990. /* initialize the rx ring */
  991. for (i = 0; i < RX_RING_SIZE; i++) {
  992. pd->rx_ring[i].status = 0;
  993. pd->rx_ring[i].length = PKT_BUF_SZ;
  994. pd->rx_ring[i].buffer2 = 0;
  995. pd->rx_buffers[i].skb = NULL;
  996. pd->rx_buffers[i].mapping = 0;
  997. }
  998. pd->rx_ring[RX_RING_SIZE - 1].length = (PKT_BUF_SZ | RDES1_RER_);
  999. /* now allocate the entire ring of skbs */
  1000. for (i = 0; i < RX_RING_SIZE; i++) {
  1001. if (smsc9420_alloc_rx_buffer(pd, i)) {
  1002. netif_warn(pd, ifup, pd->dev,
  1003. "failed to allocate rx skb %d\n", i);
  1004. goto out_free_rx_skbs;
  1005. }
  1006. }
  1007. pd->rx_ring_head = 0;
  1008. pd->rx_ring_tail = 0;
  1009. smsc9420_reg_write(pd, VLAN1, ETH_P_8021Q);
  1010. netif_dbg(pd, ifup, pd->dev, "VLAN1 = 0x%08x\n",
  1011. smsc9420_reg_read(pd, VLAN1));
  1012. if (pd->rx_csum) {
  1013. /* Enable RX COE */
  1014. u32 coe = smsc9420_reg_read(pd, COE_CR) | RX_COE_EN;
  1015. smsc9420_reg_write(pd, COE_CR, coe);
  1016. netif_dbg(pd, ifup, pd->dev, "COE_CR = 0x%08x\n", coe);
  1017. }
  1018. smsc9420_reg_write(pd, RX_BASE_ADDR, pd->rx_dma_addr);
  1019. smsc9420_pci_flush_write(pd);
  1020. return 0;
  1021. out_free_rx_skbs:
  1022. smsc9420_free_rx_ring(pd);
  1023. out:
  1024. return -ENOMEM;
  1025. }
  1026. static int smsc9420_open(struct net_device *dev)
  1027. {
  1028. struct smsc9420_pdata *pd = netdev_priv(dev);
  1029. u32 bus_mode, mac_cr, dmac_control, int_cfg, dma_intr_ena, int_ctl;
  1030. const int irq = pd->pdev->irq;
  1031. unsigned long flags;
  1032. int result = 0, timeout;
  1033. if (!is_valid_ether_addr(dev->dev_addr)) {
  1034. netif_warn(pd, ifup, pd->dev,
  1035. "dev_addr is not a valid MAC address\n");
  1036. result = -EADDRNOTAVAIL;
  1037. goto out_0;
  1038. }
  1039. netif_carrier_off(dev);
  1040. /* disable, mask and acknowledge all interrupts */
  1041. spin_lock_irqsave(&pd->int_lock, flags);
  1042. int_cfg = smsc9420_reg_read(pd, INT_CFG) & (~INT_CFG_IRQ_EN_);
  1043. smsc9420_reg_write(pd, INT_CFG, int_cfg);
  1044. smsc9420_reg_write(pd, INT_CTL, 0);
  1045. spin_unlock_irqrestore(&pd->int_lock, flags);
  1046. smsc9420_reg_write(pd, DMAC_INTR_ENA, 0);
  1047. smsc9420_reg_write(pd, INT_STAT, 0xFFFFFFFF);
  1048. smsc9420_pci_flush_write(pd);
  1049. result = request_irq(irq, smsc9420_isr, IRQF_SHARED, DRV_NAME, pd);
  1050. if (result) {
  1051. netif_warn(pd, ifup, pd->dev, "Unable to use IRQ = %d\n", irq);
  1052. result = -ENODEV;
  1053. goto out_0;
  1054. }
  1055. smsc9420_dmac_soft_reset(pd);
  1056. /* make sure MAC_CR is sane */
  1057. smsc9420_reg_write(pd, MAC_CR, 0);
  1058. smsc9420_set_mac_address(dev);
  1059. /* Configure GPIO pins to drive LEDs */
  1060. smsc9420_reg_write(pd, GPIO_CFG,
  1061. (GPIO_CFG_LED_3_ | GPIO_CFG_LED_2_ | GPIO_CFG_LED_1_));
  1062. bus_mode = BUS_MODE_DMA_BURST_LENGTH_16;
  1063. #ifdef __BIG_ENDIAN
  1064. bus_mode |= BUS_MODE_DBO_;
  1065. #endif
  1066. smsc9420_reg_write(pd, BUS_MODE, bus_mode);
  1067. smsc9420_pci_flush_write(pd);
  1068. /* set bus master bridge arbitration priority for Rx and TX DMA */
  1069. smsc9420_reg_write(pd, BUS_CFG, BUS_CFG_RXTXWEIGHT_4_1);
  1070. smsc9420_reg_write(pd, DMAC_CONTROL,
  1071. (DMAC_CONTROL_SF_ | DMAC_CONTROL_OSF_));
  1072. smsc9420_pci_flush_write(pd);
  1073. /* test the IRQ connection to the ISR */
  1074. netif_dbg(pd, ifup, pd->dev, "Testing ISR using IRQ %d\n", irq);
  1075. pd->software_irq_signal = false;
  1076. spin_lock_irqsave(&pd->int_lock, flags);
  1077. /* configure interrupt deassertion timer and enable interrupts */
  1078. int_cfg = smsc9420_reg_read(pd, INT_CFG) | INT_CFG_IRQ_EN_;
  1079. int_cfg &= ~(INT_CFG_INT_DEAS_MASK);
  1080. int_cfg |= (INT_DEAS_TIME & INT_CFG_INT_DEAS_MASK);
  1081. smsc9420_reg_write(pd, INT_CFG, int_cfg);
  1082. /* unmask software interrupt */
  1083. int_ctl = smsc9420_reg_read(pd, INT_CTL) | INT_CTL_SW_INT_EN_;
  1084. smsc9420_reg_write(pd, INT_CTL, int_ctl);
  1085. spin_unlock_irqrestore(&pd->int_lock, flags);
  1086. smsc9420_pci_flush_write(pd);
  1087. timeout = 1000;
  1088. while (timeout--) {
  1089. if (pd->software_irq_signal)
  1090. break;
  1091. msleep(1);
  1092. }
  1093. /* disable interrupts */
  1094. spin_lock_irqsave(&pd->int_lock, flags);
  1095. int_cfg = smsc9420_reg_read(pd, INT_CFG) & (~INT_CFG_IRQ_EN_);
  1096. smsc9420_reg_write(pd, INT_CFG, int_cfg);
  1097. spin_unlock_irqrestore(&pd->int_lock, flags);
  1098. if (!pd->software_irq_signal) {
  1099. netif_warn(pd, ifup, pd->dev, "ISR failed signaling test\n");
  1100. result = -ENODEV;
  1101. goto out_free_irq_1;
  1102. }
  1103. netif_dbg(pd, ifup, pd->dev, "ISR passed test using IRQ %d\n", irq);
  1104. result = smsc9420_alloc_tx_ring(pd);
  1105. if (result) {
  1106. netif_warn(pd, ifup, pd->dev,
  1107. "Failed to Initialize tx dma ring\n");
  1108. result = -ENOMEM;
  1109. goto out_free_irq_1;
  1110. }
  1111. result = smsc9420_alloc_rx_ring(pd);
  1112. if (result) {
  1113. netif_warn(pd, ifup, pd->dev,
  1114. "Failed to Initialize rx dma ring\n");
  1115. result = -ENOMEM;
  1116. goto out_free_tx_ring_2;
  1117. }
  1118. result = smsc9420_mii_init(dev);
  1119. if (result) {
  1120. netif_warn(pd, ifup, pd->dev, "Failed to initialize Phy\n");
  1121. result = -ENODEV;
  1122. goto out_free_rx_ring_3;
  1123. }
  1124. /* Bring the PHY up */
  1125. phy_start(dev->phydev);
  1126. napi_enable(&pd->napi);
  1127. /* start tx and rx */
  1128. mac_cr = smsc9420_reg_read(pd, MAC_CR) | MAC_CR_TXEN_ | MAC_CR_RXEN_;
  1129. smsc9420_reg_write(pd, MAC_CR, mac_cr);
  1130. dmac_control = smsc9420_reg_read(pd, DMAC_CONTROL);
  1131. dmac_control |= DMAC_CONTROL_ST_ | DMAC_CONTROL_SR_;
  1132. smsc9420_reg_write(pd, DMAC_CONTROL, dmac_control);
  1133. smsc9420_pci_flush_write(pd);
  1134. dma_intr_ena = smsc9420_reg_read(pd, DMAC_INTR_ENA);
  1135. dma_intr_ena |=
  1136. (DMAC_INTR_ENA_TX_ | DMAC_INTR_ENA_RX_ | DMAC_INTR_ENA_NIS_);
  1137. smsc9420_reg_write(pd, DMAC_INTR_ENA, dma_intr_ena);
  1138. smsc9420_pci_flush_write(pd);
  1139. netif_wake_queue(dev);
  1140. smsc9420_reg_write(pd, RX_POLL_DEMAND, 1);
  1141. /* enable interrupts */
  1142. spin_lock_irqsave(&pd->int_lock, flags);
  1143. int_cfg = smsc9420_reg_read(pd, INT_CFG) | INT_CFG_IRQ_EN_;
  1144. smsc9420_reg_write(pd, INT_CFG, int_cfg);
  1145. spin_unlock_irqrestore(&pd->int_lock, flags);
  1146. return 0;
  1147. out_free_rx_ring_3:
  1148. smsc9420_free_rx_ring(pd);
  1149. out_free_tx_ring_2:
  1150. smsc9420_free_tx_ring(pd);
  1151. out_free_irq_1:
  1152. free_irq(irq, pd);
  1153. out_0:
  1154. return result;
  1155. }
  1156. #ifdef CONFIG_PM
  1157. static int smsc9420_suspend(struct pci_dev *pdev, pm_message_t state)
  1158. {
  1159. struct net_device *dev = pci_get_drvdata(pdev);
  1160. struct smsc9420_pdata *pd = netdev_priv(dev);
  1161. u32 int_cfg;
  1162. ulong flags;
  1163. /* disable interrupts */
  1164. spin_lock_irqsave(&pd->int_lock, flags);
  1165. int_cfg = smsc9420_reg_read(pd, INT_CFG) & (~INT_CFG_IRQ_EN_);
  1166. smsc9420_reg_write(pd, INT_CFG, int_cfg);
  1167. spin_unlock_irqrestore(&pd->int_lock, flags);
  1168. if (netif_running(dev)) {
  1169. netif_tx_disable(dev);
  1170. smsc9420_stop_tx(pd);
  1171. smsc9420_free_tx_ring(pd);
  1172. napi_disable(&pd->napi);
  1173. smsc9420_stop_rx(pd);
  1174. smsc9420_free_rx_ring(pd);
  1175. free_irq(pd->pdev->irq, pd);
  1176. netif_device_detach(dev);
  1177. }
  1178. pci_save_state(pdev);
  1179. pci_enable_wake(pdev, pci_choose_state(pdev, state), 0);
  1180. pci_disable_device(pdev);
  1181. pci_set_power_state(pdev, pci_choose_state(pdev, state));
  1182. return 0;
  1183. }
  1184. static int smsc9420_resume(struct pci_dev *pdev)
  1185. {
  1186. struct net_device *dev = pci_get_drvdata(pdev);
  1187. struct smsc9420_pdata *pd = netdev_priv(dev);
  1188. int err;
  1189. pci_set_power_state(pdev, PCI_D0);
  1190. pci_restore_state(pdev);
  1191. err = pci_enable_device(pdev);
  1192. if (err)
  1193. return err;
  1194. pci_set_master(pdev);
  1195. err = pci_enable_wake(pdev, PCI_D0, 0);
  1196. if (err)
  1197. netif_warn(pd, ifup, pd->dev, "pci_enable_wake failed: %d\n",
  1198. err);
  1199. if (netif_running(dev)) {
  1200. /* FIXME: gross. It looks like ancient PM relic.*/
  1201. err = smsc9420_open(dev);
  1202. netif_device_attach(dev);
  1203. }
  1204. return err;
  1205. }
  1206. #endif /* CONFIG_PM */
  1207. static const struct net_device_ops smsc9420_netdev_ops = {
  1208. .ndo_open = smsc9420_open,
  1209. .ndo_stop = smsc9420_stop,
  1210. .ndo_start_xmit = smsc9420_hard_start_xmit,
  1211. .ndo_get_stats = smsc9420_get_stats,
  1212. .ndo_set_rx_mode = smsc9420_set_multicast_list,
  1213. .ndo_do_ioctl = smsc9420_do_ioctl,
  1214. .ndo_validate_addr = eth_validate_addr,
  1215. .ndo_set_mac_address = eth_mac_addr,
  1216. #ifdef CONFIG_NET_POLL_CONTROLLER
  1217. .ndo_poll_controller = smsc9420_poll_controller,
  1218. #endif /* CONFIG_NET_POLL_CONTROLLER */
  1219. };
  1220. static int
  1221. smsc9420_probe(struct pci_dev *pdev, const struct pci_device_id *id)
  1222. {
  1223. struct net_device *dev;
  1224. struct smsc9420_pdata *pd;
  1225. void __iomem *virt_addr;
  1226. int result = 0;
  1227. u32 id_rev;
  1228. pr_info("%s version %s\n", DRV_DESCRIPTION, DRV_VERSION);
  1229. /* First do the PCI initialisation */
  1230. result = pci_enable_device(pdev);
  1231. if (unlikely(result)) {
  1232. pr_err("Cannot enable smsc9420\n");
  1233. goto out_0;
  1234. }
  1235. pci_set_master(pdev);
  1236. dev = alloc_etherdev(sizeof(*pd));
  1237. if (!dev)
  1238. goto out_disable_pci_device_1;
  1239. SET_NETDEV_DEV(dev, &pdev->dev);
  1240. if (!(pci_resource_flags(pdev, SMSC_BAR) & IORESOURCE_MEM)) {
  1241. netdev_err(dev, "Cannot find PCI device base address\n");
  1242. goto out_free_netdev_2;
  1243. }
  1244. if ((pci_request_regions(pdev, DRV_NAME))) {
  1245. netdev_err(dev, "Cannot obtain PCI resources, aborting\n");
  1246. goto out_free_netdev_2;
  1247. }
  1248. if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) {
  1249. netdev_err(dev, "No usable DMA configuration, aborting\n");
  1250. goto out_free_regions_3;
  1251. }
  1252. virt_addr = ioremap(pci_resource_start(pdev, SMSC_BAR),
  1253. pci_resource_len(pdev, SMSC_BAR));
  1254. if (!virt_addr) {
  1255. netdev_err(dev, "Cannot map device registers, aborting\n");
  1256. goto out_free_regions_3;
  1257. }
  1258. /* registers are double mapped with 0 offset for LE and 0x200 for BE */
  1259. virt_addr += LAN9420_CPSR_ENDIAN_OFFSET;
  1260. pd = netdev_priv(dev);
  1261. /* pci descriptors are created in the PCI consistent area */
  1262. pd->rx_ring = pci_alloc_consistent(pdev,
  1263. sizeof(struct smsc9420_dma_desc) * RX_RING_SIZE +
  1264. sizeof(struct smsc9420_dma_desc) * TX_RING_SIZE,
  1265. &pd->rx_dma_addr);
  1266. if (!pd->rx_ring)
  1267. goto out_free_io_4;
  1268. /* descriptors are aligned due to the nature of pci_alloc_consistent */
  1269. pd->tx_ring = (pd->rx_ring + RX_RING_SIZE);
  1270. pd->tx_dma_addr = pd->rx_dma_addr +
  1271. sizeof(struct smsc9420_dma_desc) * RX_RING_SIZE;
  1272. pd->pdev = pdev;
  1273. pd->dev = dev;
  1274. pd->ioaddr = virt_addr;
  1275. pd->msg_enable = smsc_debug;
  1276. pd->rx_csum = true;
  1277. netif_dbg(pd, probe, pd->dev, "lan_base=0x%08lx\n", (ulong)virt_addr);
  1278. id_rev = smsc9420_reg_read(pd, ID_REV);
  1279. switch (id_rev & 0xFFFF0000) {
  1280. case 0x94200000:
  1281. netif_info(pd, probe, pd->dev,
  1282. "LAN9420 identified, ID_REV=0x%08X\n", id_rev);
  1283. break;
  1284. default:
  1285. netif_warn(pd, probe, pd->dev, "LAN9420 NOT identified\n");
  1286. netif_warn(pd, probe, pd->dev, "ID_REV=0x%08X\n", id_rev);
  1287. goto out_free_dmadesc_5;
  1288. }
  1289. smsc9420_dmac_soft_reset(pd);
  1290. smsc9420_eeprom_reload(pd);
  1291. smsc9420_check_mac_address(dev);
  1292. dev->netdev_ops = &smsc9420_netdev_ops;
  1293. dev->ethtool_ops = &smsc9420_ethtool_ops;
  1294. netif_napi_add(dev, &pd->napi, smsc9420_rx_poll, NAPI_WEIGHT);
  1295. result = register_netdev(dev);
  1296. if (result) {
  1297. netif_warn(pd, probe, pd->dev, "error %i registering device\n",
  1298. result);
  1299. goto out_free_dmadesc_5;
  1300. }
  1301. pci_set_drvdata(pdev, dev);
  1302. spin_lock_init(&pd->int_lock);
  1303. spin_lock_init(&pd->phy_lock);
  1304. dev_info(&dev->dev, "MAC Address: %pM\n", dev->dev_addr);
  1305. return 0;
  1306. out_free_dmadesc_5:
  1307. pci_free_consistent(pdev, sizeof(struct smsc9420_dma_desc) *
  1308. (RX_RING_SIZE + TX_RING_SIZE), pd->rx_ring, pd->rx_dma_addr);
  1309. out_free_io_4:
  1310. iounmap(virt_addr - LAN9420_CPSR_ENDIAN_OFFSET);
  1311. out_free_regions_3:
  1312. pci_release_regions(pdev);
  1313. out_free_netdev_2:
  1314. free_netdev(dev);
  1315. out_disable_pci_device_1:
  1316. pci_disable_device(pdev);
  1317. out_0:
  1318. return -ENODEV;
  1319. }
  1320. static void smsc9420_remove(struct pci_dev *pdev)
  1321. {
  1322. struct net_device *dev;
  1323. struct smsc9420_pdata *pd;
  1324. dev = pci_get_drvdata(pdev);
  1325. if (!dev)
  1326. return;
  1327. pd = netdev_priv(dev);
  1328. unregister_netdev(dev);
  1329. /* tx_buffers and rx_buffers are freed in stop */
  1330. BUG_ON(pd->tx_buffers);
  1331. BUG_ON(pd->rx_buffers);
  1332. BUG_ON(!pd->tx_ring);
  1333. BUG_ON(!pd->rx_ring);
  1334. pci_free_consistent(pdev, sizeof(struct smsc9420_dma_desc) *
  1335. (RX_RING_SIZE + TX_RING_SIZE), pd->rx_ring, pd->rx_dma_addr);
  1336. iounmap(pd->ioaddr - LAN9420_CPSR_ENDIAN_OFFSET);
  1337. pci_release_regions(pdev);
  1338. free_netdev(dev);
  1339. pci_disable_device(pdev);
  1340. }
  1341. static struct pci_driver smsc9420_driver = {
  1342. .name = DRV_NAME,
  1343. .id_table = smsc9420_id_table,
  1344. .probe = smsc9420_probe,
  1345. .remove = smsc9420_remove,
  1346. #ifdef CONFIG_PM
  1347. .suspend = smsc9420_suspend,
  1348. .resume = smsc9420_resume,
  1349. #endif /* CONFIG_PM */
  1350. };
  1351. static int __init smsc9420_init_module(void)
  1352. {
  1353. smsc_debug = netif_msg_init(debug, SMSC_MSG_DEFAULT);
  1354. return pci_register_driver(&smsc9420_driver);
  1355. }
  1356. static void __exit smsc9420_exit_module(void)
  1357. {
  1358. pci_unregister_driver(&smsc9420_driver);
  1359. }
  1360. module_init(smsc9420_init_module);
  1361. module_exit(smsc9420_exit_module);