smsc9420.c 43 KB

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