smc911x.c 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202
  1. /*
  2. * smc911x.c
  3. * This is a driver for SMSC's LAN911{5,6,7,8} single-chip Ethernet devices.
  4. *
  5. * Copyright (C) 2005 Sensoria Corp
  6. * Derived from the unified SMC91x driver by Nicolas Pitre
  7. * and the smsc911x.c reference driver by SMSC
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, see <http://www.gnu.org/licenses/>.
  21. *
  22. * Arguments:
  23. * watchdog = TX watchdog timeout
  24. * tx_fifo_kb = Size of TX FIFO in KB
  25. *
  26. * History:
  27. * 04/16/05 Dustin McIntire Initial version
  28. */
  29. static const char version[] =
  30. "smc911x.c: v1.0 04-16-2005 by Dustin McIntire <dustin@sensoria.com>\n";
  31. /* Debugging options */
  32. #define ENABLE_SMC_DEBUG_RX 0
  33. #define ENABLE_SMC_DEBUG_TX 0
  34. #define ENABLE_SMC_DEBUG_DMA 0
  35. #define ENABLE_SMC_DEBUG_PKTS 0
  36. #define ENABLE_SMC_DEBUG_MISC 0
  37. #define ENABLE_SMC_DEBUG_FUNC 0
  38. #define SMC_DEBUG_RX ((ENABLE_SMC_DEBUG_RX ? 1 : 0) << 0)
  39. #define SMC_DEBUG_TX ((ENABLE_SMC_DEBUG_TX ? 1 : 0) << 1)
  40. #define SMC_DEBUG_DMA ((ENABLE_SMC_DEBUG_DMA ? 1 : 0) << 2)
  41. #define SMC_DEBUG_PKTS ((ENABLE_SMC_DEBUG_PKTS ? 1 : 0) << 3)
  42. #define SMC_DEBUG_MISC ((ENABLE_SMC_DEBUG_MISC ? 1 : 0) << 4)
  43. #define SMC_DEBUG_FUNC ((ENABLE_SMC_DEBUG_FUNC ? 1 : 0) << 5)
  44. #ifndef SMC_DEBUG
  45. #define SMC_DEBUG ( SMC_DEBUG_RX | \
  46. SMC_DEBUG_TX | \
  47. SMC_DEBUG_DMA | \
  48. SMC_DEBUG_PKTS | \
  49. SMC_DEBUG_MISC | \
  50. SMC_DEBUG_FUNC \
  51. )
  52. #endif
  53. #include <linux/module.h>
  54. #include <linux/kernel.h>
  55. #include <linux/sched.h>
  56. #include <linux/delay.h>
  57. #include <linux/interrupt.h>
  58. #include <linux/errno.h>
  59. #include <linux/ioport.h>
  60. #include <linux/crc32.h>
  61. #include <linux/device.h>
  62. #include <linux/platform_device.h>
  63. #include <linux/spinlock.h>
  64. #include <linux/ethtool.h>
  65. #include <linux/mii.h>
  66. #include <linux/workqueue.h>
  67. #include <linux/netdevice.h>
  68. #include <linux/etherdevice.h>
  69. #include <linux/skbuff.h>
  70. #include <linux/dmaengine.h>
  71. #include <asm/io.h>
  72. #include "smc911x.h"
  73. /*
  74. * Transmit timeout, default 5 seconds.
  75. */
  76. static int watchdog = 5000;
  77. module_param(watchdog, int, 0400);
  78. MODULE_PARM_DESC(watchdog, "transmit timeout in milliseconds");
  79. static int tx_fifo_kb=8;
  80. module_param(tx_fifo_kb, int, 0400);
  81. MODULE_PARM_DESC(tx_fifo_kb,"transmit FIFO size in KB (1<x<15)(default=8)");
  82. MODULE_LICENSE("GPL");
  83. MODULE_ALIAS("platform:smc911x");
  84. /*
  85. * The internal workings of the driver. If you are changing anything
  86. * here with the SMC stuff, you should have the datasheet and know
  87. * what you are doing.
  88. */
  89. #define CARDNAME "smc911x"
  90. /*
  91. * Use power-down feature of the chip
  92. */
  93. #define POWER_DOWN 1
  94. #if SMC_DEBUG > 0
  95. #define DBG(n, dev, args...) \
  96. do { \
  97. if (SMC_DEBUG & (n)) \
  98. netdev_dbg(dev, args); \
  99. } while (0)
  100. #define PRINTK(dev, args...) netdev_info(dev, args)
  101. #else
  102. #define DBG(n, dev, args...) do { } while (0)
  103. #define PRINTK(dev, args...) netdev_dbg(dev, args)
  104. #endif
  105. #if SMC_DEBUG_PKTS > 0
  106. static void PRINT_PKT(u_char *buf, int length)
  107. {
  108. int i;
  109. int remainder;
  110. int lines;
  111. lines = length / 16;
  112. remainder = length % 16;
  113. for (i = 0; i < lines ; i ++) {
  114. int cur;
  115. printk(KERN_DEBUG);
  116. for (cur = 0; cur < 8; cur++) {
  117. u_char a, b;
  118. a = *buf++;
  119. b = *buf++;
  120. pr_cont("%02x%02x ", a, b);
  121. }
  122. pr_cont("\n");
  123. }
  124. printk(KERN_DEBUG);
  125. for (i = 0; i < remainder/2 ; i++) {
  126. u_char a, b;
  127. a = *buf++;
  128. b = *buf++;
  129. pr_cont("%02x%02x ", a, b);
  130. }
  131. pr_cont("\n");
  132. }
  133. #else
  134. #define PRINT_PKT(x...) do { } while (0)
  135. #endif
  136. /* this enables an interrupt in the interrupt mask register */
  137. #define SMC_ENABLE_INT(lp, x) do { \
  138. unsigned int __mask; \
  139. __mask = SMC_GET_INT_EN((lp)); \
  140. __mask |= (x); \
  141. SMC_SET_INT_EN((lp), __mask); \
  142. } while (0)
  143. /* this disables an interrupt from the interrupt mask register */
  144. #define SMC_DISABLE_INT(lp, x) do { \
  145. unsigned int __mask; \
  146. __mask = SMC_GET_INT_EN((lp)); \
  147. __mask &= ~(x); \
  148. SMC_SET_INT_EN((lp), __mask); \
  149. } while (0)
  150. /*
  151. * this does a soft reset on the device
  152. */
  153. static void smc911x_reset(struct net_device *dev)
  154. {
  155. struct smc911x_local *lp = netdev_priv(dev);
  156. unsigned int reg, timeout=0, resets=1, irq_cfg;
  157. unsigned long flags;
  158. DBG(SMC_DEBUG_FUNC, dev, "--> %s\n", __func__);
  159. /* Take out of PM setting first */
  160. if ((SMC_GET_PMT_CTRL(lp) & PMT_CTRL_READY_) == 0) {
  161. /* Write to the bytetest will take out of powerdown */
  162. SMC_SET_BYTE_TEST(lp, 0);
  163. timeout=10;
  164. do {
  165. udelay(10);
  166. reg = SMC_GET_PMT_CTRL(lp) & PMT_CTRL_READY_;
  167. } while (--timeout && !reg);
  168. if (timeout == 0) {
  169. PRINTK(dev, "smc911x_reset timeout waiting for PM restore\n");
  170. return;
  171. }
  172. }
  173. /* Disable all interrupts */
  174. spin_lock_irqsave(&lp->lock, flags);
  175. SMC_SET_INT_EN(lp, 0);
  176. spin_unlock_irqrestore(&lp->lock, flags);
  177. while (resets--) {
  178. SMC_SET_HW_CFG(lp, HW_CFG_SRST_);
  179. timeout=10;
  180. do {
  181. udelay(10);
  182. reg = SMC_GET_HW_CFG(lp);
  183. /* If chip indicates reset timeout then try again */
  184. if (reg & HW_CFG_SRST_TO_) {
  185. PRINTK(dev, "chip reset timeout, retrying...\n");
  186. resets++;
  187. break;
  188. }
  189. } while (--timeout && (reg & HW_CFG_SRST_));
  190. }
  191. if (timeout == 0) {
  192. PRINTK(dev, "smc911x_reset timeout waiting for reset\n");
  193. return;
  194. }
  195. /* make sure EEPROM has finished loading before setting GPIO_CFG */
  196. timeout=1000;
  197. while (--timeout && (SMC_GET_E2P_CMD(lp) & E2P_CMD_EPC_BUSY_))
  198. udelay(10);
  199. if (timeout == 0){
  200. PRINTK(dev, "smc911x_reset timeout waiting for EEPROM busy\n");
  201. return;
  202. }
  203. /* Initialize interrupts */
  204. SMC_SET_INT_EN(lp, 0);
  205. SMC_ACK_INT(lp, -1);
  206. /* Reset the FIFO level and flow control settings */
  207. SMC_SET_HW_CFG(lp, (lp->tx_fifo_kb & 0xF) << 16);
  208. //TODO: Figure out what appropriate pause time is
  209. SMC_SET_FLOW(lp, FLOW_FCPT_ | FLOW_FCEN_);
  210. SMC_SET_AFC_CFG(lp, lp->afc_cfg);
  211. /* Set to LED outputs */
  212. SMC_SET_GPIO_CFG(lp, 0x70070000);
  213. /*
  214. * Deassert IRQ for 1*10us for edge type interrupts
  215. * and drive IRQ pin push-pull
  216. */
  217. irq_cfg = (1 << 24) | INT_CFG_IRQ_EN_ | INT_CFG_IRQ_TYPE_;
  218. #ifdef SMC_DYNAMIC_BUS_CONFIG
  219. if (lp->cfg.irq_polarity)
  220. irq_cfg |= INT_CFG_IRQ_POL_;
  221. #endif
  222. SMC_SET_IRQ_CFG(lp, irq_cfg);
  223. /* clear anything saved */
  224. if (lp->pending_tx_skb != NULL) {
  225. dev_kfree_skb (lp->pending_tx_skb);
  226. lp->pending_tx_skb = NULL;
  227. dev->stats.tx_errors++;
  228. dev->stats.tx_aborted_errors++;
  229. }
  230. }
  231. /*
  232. * Enable Interrupts, Receive, and Transmit
  233. */
  234. static void smc911x_enable(struct net_device *dev)
  235. {
  236. struct smc911x_local *lp = netdev_priv(dev);
  237. unsigned mask, cfg, cr;
  238. unsigned long flags;
  239. DBG(SMC_DEBUG_FUNC, dev, "--> %s\n", __func__);
  240. spin_lock_irqsave(&lp->lock, flags);
  241. SMC_SET_MAC_ADDR(lp, dev->dev_addr);
  242. /* Enable TX */
  243. cfg = SMC_GET_HW_CFG(lp);
  244. cfg &= HW_CFG_TX_FIF_SZ_ | 0xFFF;
  245. cfg |= HW_CFG_SF_;
  246. SMC_SET_HW_CFG(lp, cfg);
  247. SMC_SET_FIFO_TDA(lp, 0xFF);
  248. /* Update TX stats on every 64 packets received or every 1 sec */
  249. SMC_SET_FIFO_TSL(lp, 64);
  250. SMC_SET_GPT_CFG(lp, GPT_CFG_TIMER_EN_ | 10000);
  251. SMC_GET_MAC_CR(lp, cr);
  252. cr |= MAC_CR_TXEN_ | MAC_CR_HBDIS_;
  253. SMC_SET_MAC_CR(lp, cr);
  254. SMC_SET_TX_CFG(lp, TX_CFG_TX_ON_);
  255. /* Add 2 byte padding to start of packets */
  256. SMC_SET_RX_CFG(lp, (2<<8) & RX_CFG_RXDOFF_);
  257. /* Turn on receiver and enable RX */
  258. if (cr & MAC_CR_RXEN_)
  259. DBG(SMC_DEBUG_RX, dev, "Receiver already enabled\n");
  260. SMC_SET_MAC_CR(lp, cr | MAC_CR_RXEN_);
  261. /* Interrupt on every received packet */
  262. SMC_SET_FIFO_RSA(lp, 0x01);
  263. SMC_SET_FIFO_RSL(lp, 0x00);
  264. /* now, enable interrupts */
  265. mask = INT_EN_TDFA_EN_ | INT_EN_TSFL_EN_ | INT_EN_RSFL_EN_ |
  266. INT_EN_GPT_INT_EN_ | INT_EN_RXDFH_INT_EN_ | INT_EN_RXE_EN_ |
  267. INT_EN_PHY_INT_EN_;
  268. if (IS_REV_A(lp->revision))
  269. mask|=INT_EN_RDFL_EN_;
  270. else {
  271. mask|=INT_EN_RDFO_EN_;
  272. }
  273. SMC_ENABLE_INT(lp, mask);
  274. spin_unlock_irqrestore(&lp->lock, flags);
  275. }
  276. /*
  277. * this puts the device in an inactive state
  278. */
  279. static void smc911x_shutdown(struct net_device *dev)
  280. {
  281. struct smc911x_local *lp = netdev_priv(dev);
  282. unsigned cr;
  283. unsigned long flags;
  284. DBG(SMC_DEBUG_FUNC, dev, "%s: --> %s\n", CARDNAME, __func__);
  285. /* Disable IRQ's */
  286. SMC_SET_INT_EN(lp, 0);
  287. /* Turn of Rx and TX */
  288. spin_lock_irqsave(&lp->lock, flags);
  289. SMC_GET_MAC_CR(lp, cr);
  290. cr &= ~(MAC_CR_TXEN_ | MAC_CR_RXEN_ | MAC_CR_HBDIS_);
  291. SMC_SET_MAC_CR(lp, cr);
  292. SMC_SET_TX_CFG(lp, TX_CFG_STOP_TX_);
  293. spin_unlock_irqrestore(&lp->lock, flags);
  294. }
  295. static inline void smc911x_drop_pkt(struct net_device *dev)
  296. {
  297. struct smc911x_local *lp = netdev_priv(dev);
  298. unsigned int fifo_count, timeout, reg;
  299. DBG(SMC_DEBUG_FUNC | SMC_DEBUG_RX, dev, "%s: --> %s\n",
  300. CARDNAME, __func__);
  301. fifo_count = SMC_GET_RX_FIFO_INF(lp) & 0xFFFF;
  302. if (fifo_count <= 4) {
  303. /* Manually dump the packet data */
  304. while (fifo_count--)
  305. SMC_GET_RX_FIFO(lp);
  306. } else {
  307. /* Fast forward through the bad packet */
  308. SMC_SET_RX_DP_CTRL(lp, RX_DP_CTRL_FFWD_BUSY_);
  309. timeout=50;
  310. do {
  311. udelay(10);
  312. reg = SMC_GET_RX_DP_CTRL(lp) & RX_DP_CTRL_FFWD_BUSY_;
  313. } while (--timeout && reg);
  314. if (timeout == 0) {
  315. PRINTK(dev, "timeout waiting for RX fast forward\n");
  316. }
  317. }
  318. }
  319. /*
  320. * This is the procedure to handle the receipt of a packet.
  321. * It should be called after checking for packet presence in
  322. * the RX status FIFO. It must be called with the spin lock
  323. * already held.
  324. */
  325. static inline void smc911x_rcv(struct net_device *dev)
  326. {
  327. struct smc911x_local *lp = netdev_priv(dev);
  328. unsigned int pkt_len, status;
  329. struct sk_buff *skb;
  330. unsigned char *data;
  331. DBG(SMC_DEBUG_FUNC | SMC_DEBUG_RX, dev, "--> %s\n",
  332. __func__);
  333. status = SMC_GET_RX_STS_FIFO(lp);
  334. DBG(SMC_DEBUG_RX, dev, "Rx pkt len %d status 0x%08x\n",
  335. (status & 0x3fff0000) >> 16, status & 0xc000ffff);
  336. pkt_len = (status & RX_STS_PKT_LEN_) >> 16;
  337. if (status & RX_STS_ES_) {
  338. /* Deal with a bad packet */
  339. dev->stats.rx_errors++;
  340. if (status & RX_STS_CRC_ERR_)
  341. dev->stats.rx_crc_errors++;
  342. else {
  343. if (status & RX_STS_LEN_ERR_)
  344. dev->stats.rx_length_errors++;
  345. if (status & RX_STS_MCAST_)
  346. dev->stats.multicast++;
  347. }
  348. /* Remove the bad packet data from the RX FIFO */
  349. smc911x_drop_pkt(dev);
  350. } else {
  351. /* Receive a valid packet */
  352. /* Alloc a buffer with extra room for DMA alignment */
  353. skb = netdev_alloc_skb(dev, pkt_len+32);
  354. if (unlikely(skb == NULL)) {
  355. PRINTK(dev, "Low memory, rcvd packet dropped.\n");
  356. dev->stats.rx_dropped++;
  357. smc911x_drop_pkt(dev);
  358. return;
  359. }
  360. /* Align IP header to 32 bits
  361. * Note that the device is configured to add a 2
  362. * byte padding to the packet start, so we really
  363. * want to write to the orignal data pointer */
  364. data = skb->data;
  365. skb_reserve(skb, 2);
  366. skb_put(skb,pkt_len-4);
  367. #ifdef SMC_USE_DMA
  368. {
  369. unsigned int fifo;
  370. /* Lower the FIFO threshold if possible */
  371. fifo = SMC_GET_FIFO_INT(lp);
  372. if (fifo & 0xFF) fifo--;
  373. DBG(SMC_DEBUG_RX, dev, "Setting RX stat FIFO threshold to %d\n",
  374. fifo & 0xff);
  375. SMC_SET_FIFO_INT(lp, fifo);
  376. /* Setup RX DMA */
  377. SMC_SET_RX_CFG(lp, RX_CFG_RX_END_ALGN16_ | ((2<<8) & RX_CFG_RXDOFF_));
  378. lp->rxdma_active = 1;
  379. lp->current_rx_skb = skb;
  380. SMC_PULL_DATA(lp, data, (pkt_len+2+15) & ~15);
  381. /* Packet processing deferred to DMA RX interrupt */
  382. }
  383. #else
  384. SMC_SET_RX_CFG(lp, RX_CFG_RX_END_ALGN4_ | ((2<<8) & RX_CFG_RXDOFF_));
  385. SMC_PULL_DATA(lp, data, pkt_len+2+3);
  386. DBG(SMC_DEBUG_PKTS, dev, "Received packet\n");
  387. PRINT_PKT(data, ((pkt_len - 4) <= 64) ? pkt_len - 4 : 64);
  388. skb->protocol = eth_type_trans(skb, dev);
  389. netif_rx(skb);
  390. dev->stats.rx_packets++;
  391. dev->stats.rx_bytes += pkt_len-4;
  392. #endif
  393. }
  394. }
  395. /*
  396. * This is called to actually send a packet to the chip.
  397. */
  398. static void smc911x_hardware_send_pkt(struct net_device *dev)
  399. {
  400. struct smc911x_local *lp = netdev_priv(dev);
  401. struct sk_buff *skb;
  402. unsigned int cmdA, cmdB, len;
  403. unsigned char *buf;
  404. DBG(SMC_DEBUG_FUNC | SMC_DEBUG_TX, dev, "--> %s\n", __func__);
  405. BUG_ON(lp->pending_tx_skb == NULL);
  406. skb = lp->pending_tx_skb;
  407. lp->pending_tx_skb = NULL;
  408. /* cmdA {25:24] data alignment [20:16] start offset [10:0] buffer length */
  409. /* cmdB {31:16] pkt tag [10:0] length */
  410. #ifdef SMC_USE_DMA
  411. /* 16 byte buffer alignment mode */
  412. buf = (char*)((u32)(skb->data) & ~0xF);
  413. len = (skb->len + 0xF + ((u32)skb->data & 0xF)) & ~0xF;
  414. cmdA = (1<<24) | (((u32)skb->data & 0xF)<<16) |
  415. TX_CMD_A_INT_FIRST_SEG_ | TX_CMD_A_INT_LAST_SEG_ |
  416. skb->len;
  417. #else
  418. buf = (char*)((u32)skb->data & ~0x3);
  419. len = (skb->len + 3 + ((u32)skb->data & 3)) & ~0x3;
  420. cmdA = (((u32)skb->data & 0x3) << 16) |
  421. TX_CMD_A_INT_FIRST_SEG_ | TX_CMD_A_INT_LAST_SEG_ |
  422. skb->len;
  423. #endif
  424. /* tag is packet length so we can use this in stats update later */
  425. cmdB = (skb->len << 16) | (skb->len & 0x7FF);
  426. DBG(SMC_DEBUG_TX, dev, "TX PKT LENGTH 0x%04x (%d) BUF 0x%p CMDA 0x%08x CMDB 0x%08x\n",
  427. len, len, buf, cmdA, cmdB);
  428. SMC_SET_TX_FIFO(lp, cmdA);
  429. SMC_SET_TX_FIFO(lp, cmdB);
  430. DBG(SMC_DEBUG_PKTS, dev, "Transmitted packet\n");
  431. PRINT_PKT(buf, len <= 64 ? len : 64);
  432. /* Send pkt via PIO or DMA */
  433. #ifdef SMC_USE_DMA
  434. lp->current_tx_skb = skb;
  435. SMC_PUSH_DATA(lp, buf, len);
  436. /* DMA complete IRQ will free buffer and set jiffies */
  437. #else
  438. SMC_PUSH_DATA(lp, buf, len);
  439. netif_trans_update(dev);
  440. dev_kfree_skb_irq(skb);
  441. #endif
  442. if (!lp->tx_throttle) {
  443. netif_wake_queue(dev);
  444. }
  445. SMC_ENABLE_INT(lp, INT_EN_TDFA_EN_ | INT_EN_TSFL_EN_);
  446. }
  447. /*
  448. * Since I am not sure if I will have enough room in the chip's ram
  449. * to store the packet, I call this routine which either sends it
  450. * now, or set the card to generates an interrupt when ready
  451. * for the packet.
  452. */
  453. static netdev_tx_t
  454. smc911x_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
  455. {
  456. struct smc911x_local *lp = netdev_priv(dev);
  457. unsigned int free;
  458. unsigned long flags;
  459. DBG(SMC_DEBUG_FUNC | SMC_DEBUG_TX, dev, "--> %s\n",
  460. __func__);
  461. spin_lock_irqsave(&lp->lock, flags);
  462. BUG_ON(lp->pending_tx_skb != NULL);
  463. free = SMC_GET_TX_FIFO_INF(lp) & TX_FIFO_INF_TDFREE_;
  464. DBG(SMC_DEBUG_TX, dev, "TX free space %d\n", free);
  465. /* Turn off the flow when running out of space in FIFO */
  466. if (free <= SMC911X_TX_FIFO_LOW_THRESHOLD) {
  467. DBG(SMC_DEBUG_TX, dev, "Disabling data flow due to low FIFO space (%d)\n",
  468. free);
  469. /* Reenable when at least 1 packet of size MTU present */
  470. SMC_SET_FIFO_TDA(lp, (SMC911X_TX_FIFO_LOW_THRESHOLD)/64);
  471. lp->tx_throttle = 1;
  472. netif_stop_queue(dev);
  473. }
  474. /* Drop packets when we run out of space in TX FIFO
  475. * Account for overhead required for:
  476. *
  477. * Tx command words 8 bytes
  478. * Start offset 15 bytes
  479. * End padding 15 bytes
  480. */
  481. if (unlikely(free < (skb->len + 8 + 15 + 15))) {
  482. netdev_warn(dev, "No Tx free space %d < %d\n",
  483. free, skb->len);
  484. lp->pending_tx_skb = NULL;
  485. dev->stats.tx_errors++;
  486. dev->stats.tx_dropped++;
  487. spin_unlock_irqrestore(&lp->lock, flags);
  488. dev_kfree_skb_any(skb);
  489. return NETDEV_TX_OK;
  490. }
  491. #ifdef SMC_USE_DMA
  492. {
  493. /* If the DMA is already running then defer this packet Tx until
  494. * the DMA IRQ starts it
  495. */
  496. if (lp->txdma_active) {
  497. DBG(SMC_DEBUG_TX | SMC_DEBUG_DMA, dev, "Tx DMA running, deferring packet\n");
  498. lp->pending_tx_skb = skb;
  499. netif_stop_queue(dev);
  500. spin_unlock_irqrestore(&lp->lock, flags);
  501. return NETDEV_TX_OK;
  502. } else {
  503. DBG(SMC_DEBUG_TX | SMC_DEBUG_DMA, dev, "Activating Tx DMA\n");
  504. lp->txdma_active = 1;
  505. }
  506. }
  507. #endif
  508. lp->pending_tx_skb = skb;
  509. smc911x_hardware_send_pkt(dev);
  510. spin_unlock_irqrestore(&lp->lock, flags);
  511. return NETDEV_TX_OK;
  512. }
  513. /*
  514. * This handles a TX status interrupt, which is only called when:
  515. * - a TX error occurred, or
  516. * - TX of a packet completed.
  517. */
  518. static void smc911x_tx(struct net_device *dev)
  519. {
  520. struct smc911x_local *lp = netdev_priv(dev);
  521. unsigned int tx_status;
  522. DBG(SMC_DEBUG_FUNC | SMC_DEBUG_TX, dev, "--> %s\n",
  523. __func__);
  524. /* Collect the TX status */
  525. while (((SMC_GET_TX_FIFO_INF(lp) & TX_FIFO_INF_TSUSED_) >> 16) != 0) {
  526. DBG(SMC_DEBUG_TX, dev, "Tx stat FIFO used 0x%04x\n",
  527. (SMC_GET_TX_FIFO_INF(lp) & TX_FIFO_INF_TSUSED_) >> 16);
  528. tx_status = SMC_GET_TX_STS_FIFO(lp);
  529. dev->stats.tx_packets++;
  530. dev->stats.tx_bytes+=tx_status>>16;
  531. DBG(SMC_DEBUG_TX, dev, "Tx FIFO tag 0x%04x status 0x%04x\n",
  532. (tx_status & 0xffff0000) >> 16,
  533. tx_status & 0x0000ffff);
  534. /* count Tx errors, but ignore lost carrier errors when in
  535. * full-duplex mode */
  536. if ((tx_status & TX_STS_ES_) && !(lp->ctl_rfduplx &&
  537. !(tx_status & 0x00000306))) {
  538. dev->stats.tx_errors++;
  539. }
  540. if (tx_status & TX_STS_MANY_COLL_) {
  541. dev->stats.collisions+=16;
  542. dev->stats.tx_aborted_errors++;
  543. } else {
  544. dev->stats.collisions+=(tx_status & TX_STS_COLL_CNT_) >> 3;
  545. }
  546. /* carrier error only has meaning for half-duplex communication */
  547. if ((tx_status & (TX_STS_LOC_ | TX_STS_NO_CARR_)) &&
  548. !lp->ctl_rfduplx) {
  549. dev->stats.tx_carrier_errors++;
  550. }
  551. if (tx_status & TX_STS_LATE_COLL_) {
  552. dev->stats.collisions++;
  553. dev->stats.tx_aborted_errors++;
  554. }
  555. }
  556. }
  557. /*---PHY CONTROL AND CONFIGURATION-----------------------------------------*/
  558. /*
  559. * Reads a register from the MII Management serial interface
  560. */
  561. static int smc911x_phy_read(struct net_device *dev, int phyaddr, int phyreg)
  562. {
  563. struct smc911x_local *lp = netdev_priv(dev);
  564. unsigned int phydata;
  565. SMC_GET_MII(lp, phyreg, phyaddr, phydata);
  566. DBG(SMC_DEBUG_MISC, dev, "%s: phyaddr=0x%x, phyreg=0x%02x, phydata=0x%04x\n",
  567. __func__, phyaddr, phyreg, phydata);
  568. return phydata;
  569. }
  570. /*
  571. * Writes a register to the MII Management serial interface
  572. */
  573. static void smc911x_phy_write(struct net_device *dev, int phyaddr, int phyreg,
  574. int phydata)
  575. {
  576. struct smc911x_local *lp = netdev_priv(dev);
  577. DBG(SMC_DEBUG_MISC, dev, "%s: phyaddr=0x%x, phyreg=0x%x, phydata=0x%x\n",
  578. __func__, phyaddr, phyreg, phydata);
  579. SMC_SET_MII(lp, phyreg, phyaddr, phydata);
  580. }
  581. /*
  582. * Finds and reports the PHY address (115 and 117 have external
  583. * PHY interface 118 has internal only
  584. */
  585. static void smc911x_phy_detect(struct net_device *dev)
  586. {
  587. struct smc911x_local *lp = netdev_priv(dev);
  588. int phyaddr;
  589. unsigned int cfg, id1, id2;
  590. DBG(SMC_DEBUG_FUNC, dev, "--> %s\n", __func__);
  591. lp->phy_type = 0;
  592. /*
  593. * Scan all 32 PHY addresses if necessary, starting at
  594. * PHY#1 to PHY#31, and then PHY#0 last.
  595. */
  596. switch(lp->version) {
  597. case CHIP_9115:
  598. case CHIP_9117:
  599. case CHIP_9215:
  600. case CHIP_9217:
  601. cfg = SMC_GET_HW_CFG(lp);
  602. if (cfg & HW_CFG_EXT_PHY_DET_) {
  603. cfg &= ~HW_CFG_PHY_CLK_SEL_;
  604. cfg |= HW_CFG_PHY_CLK_SEL_CLK_DIS_;
  605. SMC_SET_HW_CFG(lp, cfg);
  606. udelay(10); /* Wait for clocks to stop */
  607. cfg |= HW_CFG_EXT_PHY_EN_;
  608. SMC_SET_HW_CFG(lp, cfg);
  609. udelay(10); /* Wait for clocks to stop */
  610. cfg &= ~HW_CFG_PHY_CLK_SEL_;
  611. cfg |= HW_CFG_PHY_CLK_SEL_EXT_PHY_;
  612. SMC_SET_HW_CFG(lp, cfg);
  613. udelay(10); /* Wait for clocks to stop */
  614. cfg |= HW_CFG_SMI_SEL_;
  615. SMC_SET_HW_CFG(lp, cfg);
  616. for (phyaddr = 1; phyaddr < 32; ++phyaddr) {
  617. /* Read the PHY identifiers */
  618. SMC_GET_PHY_ID1(lp, phyaddr & 31, id1);
  619. SMC_GET_PHY_ID2(lp, phyaddr & 31, id2);
  620. /* Make sure it is a valid identifier */
  621. if (id1 != 0x0000 && id1 != 0xffff &&
  622. id1 != 0x8000 && id2 != 0x0000 &&
  623. id2 != 0xffff && id2 != 0x8000) {
  624. /* Save the PHY's address */
  625. lp->mii.phy_id = phyaddr & 31;
  626. lp->phy_type = id1 << 16 | id2;
  627. break;
  628. }
  629. }
  630. if (phyaddr < 32)
  631. /* Found an external PHY */
  632. break;
  633. }
  634. default:
  635. /* Internal media only */
  636. SMC_GET_PHY_ID1(lp, 1, id1);
  637. SMC_GET_PHY_ID2(lp, 1, id2);
  638. /* Save the PHY's address */
  639. lp->mii.phy_id = 1;
  640. lp->phy_type = id1 << 16 | id2;
  641. }
  642. DBG(SMC_DEBUG_MISC, dev, "phy_id1=0x%x, phy_id2=0x%x phyaddr=0x%x\n",
  643. id1, id2, lp->mii.phy_id);
  644. }
  645. /*
  646. * Sets the PHY to a configuration as determined by the user.
  647. * Called with spin_lock held.
  648. */
  649. static int smc911x_phy_fixed(struct net_device *dev)
  650. {
  651. struct smc911x_local *lp = netdev_priv(dev);
  652. int phyaddr = lp->mii.phy_id;
  653. int bmcr;
  654. DBG(SMC_DEBUG_FUNC, dev, "--> %s\n", __func__);
  655. /* Enter Link Disable state */
  656. SMC_GET_PHY_BMCR(lp, phyaddr, bmcr);
  657. bmcr |= BMCR_PDOWN;
  658. SMC_SET_PHY_BMCR(lp, phyaddr, bmcr);
  659. /*
  660. * Set our fixed capabilities
  661. * Disable auto-negotiation
  662. */
  663. bmcr &= ~BMCR_ANENABLE;
  664. if (lp->ctl_rfduplx)
  665. bmcr |= BMCR_FULLDPLX;
  666. if (lp->ctl_rspeed == 100)
  667. bmcr |= BMCR_SPEED100;
  668. /* Write our capabilities to the phy control register */
  669. SMC_SET_PHY_BMCR(lp, phyaddr, bmcr);
  670. /* Re-Configure the Receive/Phy Control register */
  671. bmcr &= ~BMCR_PDOWN;
  672. SMC_SET_PHY_BMCR(lp, phyaddr, bmcr);
  673. return 1;
  674. }
  675. /**
  676. * smc911x_phy_reset - reset the phy
  677. * @dev: net device
  678. * @phy: phy address
  679. *
  680. * Issue a software reset for the specified PHY and
  681. * wait up to 100ms for the reset to complete. We should
  682. * not access the PHY for 50ms after issuing the reset.
  683. *
  684. * The time to wait appears to be dependent on the PHY.
  685. *
  686. */
  687. static int smc911x_phy_reset(struct net_device *dev, int phy)
  688. {
  689. struct smc911x_local *lp = netdev_priv(dev);
  690. int timeout;
  691. unsigned long flags;
  692. unsigned int reg;
  693. DBG(SMC_DEBUG_FUNC, dev, "--> %s()\n", __func__);
  694. spin_lock_irqsave(&lp->lock, flags);
  695. reg = SMC_GET_PMT_CTRL(lp);
  696. reg &= ~0xfffff030;
  697. reg |= PMT_CTRL_PHY_RST_;
  698. SMC_SET_PMT_CTRL(lp, reg);
  699. spin_unlock_irqrestore(&lp->lock, flags);
  700. for (timeout = 2; timeout; timeout--) {
  701. msleep(50);
  702. spin_lock_irqsave(&lp->lock, flags);
  703. reg = SMC_GET_PMT_CTRL(lp);
  704. spin_unlock_irqrestore(&lp->lock, flags);
  705. if (!(reg & PMT_CTRL_PHY_RST_)) {
  706. /* extra delay required because the phy may
  707. * not be completed with its reset
  708. * when PHY_BCR_RESET_ is cleared. 256us
  709. * should suffice, but use 500us to be safe
  710. */
  711. udelay(500);
  712. break;
  713. }
  714. }
  715. return reg & PMT_CTRL_PHY_RST_;
  716. }
  717. /**
  718. * smc911x_phy_powerdown - powerdown phy
  719. * @dev: net device
  720. * @phy: phy address
  721. *
  722. * Power down the specified PHY
  723. */
  724. static void smc911x_phy_powerdown(struct net_device *dev, int phy)
  725. {
  726. struct smc911x_local *lp = netdev_priv(dev);
  727. unsigned int bmcr;
  728. /* Enter Link Disable state */
  729. SMC_GET_PHY_BMCR(lp, phy, bmcr);
  730. bmcr |= BMCR_PDOWN;
  731. SMC_SET_PHY_BMCR(lp, phy, bmcr);
  732. }
  733. /**
  734. * smc911x_phy_check_media - check the media status and adjust BMCR
  735. * @dev: net device
  736. * @init: set true for initialisation
  737. *
  738. * Select duplex mode depending on negotiation state. This
  739. * also updates our carrier state.
  740. */
  741. static void smc911x_phy_check_media(struct net_device *dev, int init)
  742. {
  743. struct smc911x_local *lp = netdev_priv(dev);
  744. int phyaddr = lp->mii.phy_id;
  745. unsigned int bmcr, cr;
  746. DBG(SMC_DEBUG_FUNC, dev, "--> %s\n", __func__);
  747. if (mii_check_media(&lp->mii, netif_msg_link(lp), init)) {
  748. /* duplex state has changed */
  749. SMC_GET_PHY_BMCR(lp, phyaddr, bmcr);
  750. SMC_GET_MAC_CR(lp, cr);
  751. if (lp->mii.full_duplex) {
  752. DBG(SMC_DEBUG_MISC, dev, "Configuring for full-duplex mode\n");
  753. bmcr |= BMCR_FULLDPLX;
  754. cr |= MAC_CR_RCVOWN_;
  755. } else {
  756. DBG(SMC_DEBUG_MISC, dev, "Configuring for half-duplex mode\n");
  757. bmcr &= ~BMCR_FULLDPLX;
  758. cr &= ~MAC_CR_RCVOWN_;
  759. }
  760. SMC_SET_PHY_BMCR(lp, phyaddr, bmcr);
  761. SMC_SET_MAC_CR(lp, cr);
  762. }
  763. }
  764. /*
  765. * Configures the specified PHY through the MII management interface
  766. * using Autonegotiation.
  767. * Calls smc911x_phy_fixed() if the user has requested a certain config.
  768. * If RPC ANEG bit is set, the media selection is dependent purely on
  769. * the selection by the MII (either in the MII BMCR reg or the result
  770. * of autonegotiation.) If the RPC ANEG bit is cleared, the selection
  771. * is controlled by the RPC SPEED and RPC DPLX bits.
  772. */
  773. static void smc911x_phy_configure(struct work_struct *work)
  774. {
  775. struct smc911x_local *lp = container_of(work, struct smc911x_local,
  776. phy_configure);
  777. struct net_device *dev = lp->netdev;
  778. int phyaddr = lp->mii.phy_id;
  779. int my_phy_caps; /* My PHY capabilities */
  780. int my_ad_caps; /* My Advertised capabilities */
  781. int status;
  782. unsigned long flags;
  783. DBG(SMC_DEBUG_FUNC, dev, "--> %s()\n", __func__);
  784. /*
  785. * We should not be called if phy_type is zero.
  786. */
  787. if (lp->phy_type == 0)
  788. return;
  789. if (smc911x_phy_reset(dev, phyaddr)) {
  790. netdev_info(dev, "PHY reset timed out\n");
  791. return;
  792. }
  793. spin_lock_irqsave(&lp->lock, flags);
  794. /*
  795. * Enable PHY Interrupts (for register 18)
  796. * Interrupts listed here are enabled
  797. */
  798. SMC_SET_PHY_INT_MASK(lp, phyaddr, PHY_INT_MASK_ENERGY_ON_ |
  799. PHY_INT_MASK_ANEG_COMP_ | PHY_INT_MASK_REMOTE_FAULT_ |
  800. PHY_INT_MASK_LINK_DOWN_);
  801. /* If the user requested no auto neg, then go set his request */
  802. if (lp->mii.force_media) {
  803. smc911x_phy_fixed(dev);
  804. goto smc911x_phy_configure_exit;
  805. }
  806. /* Copy our capabilities from MII_BMSR to MII_ADVERTISE */
  807. SMC_GET_PHY_BMSR(lp, phyaddr, my_phy_caps);
  808. if (!(my_phy_caps & BMSR_ANEGCAPABLE)) {
  809. netdev_info(dev, "Auto negotiation NOT supported\n");
  810. smc911x_phy_fixed(dev);
  811. goto smc911x_phy_configure_exit;
  812. }
  813. /* CSMA capable w/ both pauses */
  814. my_ad_caps = ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM;
  815. if (my_phy_caps & BMSR_100BASE4)
  816. my_ad_caps |= ADVERTISE_100BASE4;
  817. if (my_phy_caps & BMSR_100FULL)
  818. my_ad_caps |= ADVERTISE_100FULL;
  819. if (my_phy_caps & BMSR_100HALF)
  820. my_ad_caps |= ADVERTISE_100HALF;
  821. if (my_phy_caps & BMSR_10FULL)
  822. my_ad_caps |= ADVERTISE_10FULL;
  823. if (my_phy_caps & BMSR_10HALF)
  824. my_ad_caps |= ADVERTISE_10HALF;
  825. /* Disable capabilities not selected by our user */
  826. if (lp->ctl_rspeed != 100)
  827. my_ad_caps &= ~(ADVERTISE_100BASE4|ADVERTISE_100FULL|ADVERTISE_100HALF);
  828. if (!lp->ctl_rfduplx)
  829. my_ad_caps &= ~(ADVERTISE_100FULL|ADVERTISE_10FULL);
  830. /* Update our Auto-Neg Advertisement Register */
  831. SMC_SET_PHY_MII_ADV(lp, phyaddr, my_ad_caps);
  832. lp->mii.advertising = my_ad_caps;
  833. /*
  834. * Read the register back. Without this, it appears that when
  835. * auto-negotiation is restarted, sometimes it isn't ready and
  836. * the link does not come up.
  837. */
  838. udelay(10);
  839. SMC_GET_PHY_MII_ADV(lp, phyaddr, status);
  840. DBG(SMC_DEBUG_MISC, dev, "phy caps=0x%04x\n", my_phy_caps);
  841. DBG(SMC_DEBUG_MISC, dev, "phy advertised caps=0x%04x\n", my_ad_caps);
  842. /* Restart auto-negotiation process in order to advertise my caps */
  843. SMC_SET_PHY_BMCR(lp, phyaddr, BMCR_ANENABLE | BMCR_ANRESTART);
  844. smc911x_phy_check_media(dev, 1);
  845. smc911x_phy_configure_exit:
  846. spin_unlock_irqrestore(&lp->lock, flags);
  847. }
  848. /*
  849. * smc911x_phy_interrupt
  850. *
  851. * Purpose: Handle interrupts relating to PHY register 18. This is
  852. * called from the "hard" interrupt handler under our private spinlock.
  853. */
  854. static void smc911x_phy_interrupt(struct net_device *dev)
  855. {
  856. struct smc911x_local *lp = netdev_priv(dev);
  857. int phyaddr = lp->mii.phy_id;
  858. int status;
  859. DBG(SMC_DEBUG_FUNC, dev, "--> %s\n", __func__);
  860. if (lp->phy_type == 0)
  861. return;
  862. smc911x_phy_check_media(dev, 0);
  863. /* read to clear status bits */
  864. SMC_GET_PHY_INT_SRC(lp, phyaddr,status);
  865. DBG(SMC_DEBUG_MISC, dev, "PHY interrupt status 0x%04x\n",
  866. status & 0xffff);
  867. DBG(SMC_DEBUG_MISC, dev, "AFC_CFG 0x%08x\n",
  868. SMC_GET_AFC_CFG(lp));
  869. }
  870. /*--- END PHY CONTROL AND CONFIGURATION-------------------------------------*/
  871. /*
  872. * This is the main routine of the driver, to handle the device when
  873. * it needs some attention.
  874. */
  875. static irqreturn_t smc911x_interrupt(int irq, void *dev_id)
  876. {
  877. struct net_device *dev = dev_id;
  878. struct smc911x_local *lp = netdev_priv(dev);
  879. unsigned int status, mask, timeout;
  880. unsigned int rx_overrun=0, cr, pkts;
  881. unsigned long flags;
  882. DBG(SMC_DEBUG_FUNC, dev, "--> %s\n", __func__);
  883. spin_lock_irqsave(&lp->lock, flags);
  884. /* Spurious interrupt check */
  885. if ((SMC_GET_IRQ_CFG(lp) & (INT_CFG_IRQ_INT_ | INT_CFG_IRQ_EN_)) !=
  886. (INT_CFG_IRQ_INT_ | INT_CFG_IRQ_EN_)) {
  887. spin_unlock_irqrestore(&lp->lock, flags);
  888. return IRQ_NONE;
  889. }
  890. mask = SMC_GET_INT_EN(lp);
  891. SMC_SET_INT_EN(lp, 0);
  892. /* set a timeout value, so I don't stay here forever */
  893. timeout = 8;
  894. do {
  895. status = SMC_GET_INT(lp);
  896. DBG(SMC_DEBUG_MISC, dev, "INT 0x%08x MASK 0x%08x OUTSIDE MASK 0x%08x\n",
  897. status, mask, status & ~mask);
  898. status &= mask;
  899. if (!status)
  900. break;
  901. /* Handle SW interrupt condition */
  902. if (status & INT_STS_SW_INT_) {
  903. SMC_ACK_INT(lp, INT_STS_SW_INT_);
  904. mask &= ~INT_EN_SW_INT_EN_;
  905. }
  906. /* Handle various error conditions */
  907. if (status & INT_STS_RXE_) {
  908. SMC_ACK_INT(lp, INT_STS_RXE_);
  909. dev->stats.rx_errors++;
  910. }
  911. if (status & INT_STS_RXDFH_INT_) {
  912. SMC_ACK_INT(lp, INT_STS_RXDFH_INT_);
  913. dev->stats.rx_dropped+=SMC_GET_RX_DROP(lp);
  914. }
  915. /* Undocumented interrupt-what is the right thing to do here? */
  916. if (status & INT_STS_RXDF_INT_) {
  917. SMC_ACK_INT(lp, INT_STS_RXDF_INT_);
  918. }
  919. /* Rx Data FIFO exceeds set level */
  920. if (status & INT_STS_RDFL_) {
  921. if (IS_REV_A(lp->revision)) {
  922. rx_overrun=1;
  923. SMC_GET_MAC_CR(lp, cr);
  924. cr &= ~MAC_CR_RXEN_;
  925. SMC_SET_MAC_CR(lp, cr);
  926. DBG(SMC_DEBUG_RX, dev, "RX overrun\n");
  927. dev->stats.rx_errors++;
  928. dev->stats.rx_fifo_errors++;
  929. }
  930. SMC_ACK_INT(lp, INT_STS_RDFL_);
  931. }
  932. if (status & INT_STS_RDFO_) {
  933. if (!IS_REV_A(lp->revision)) {
  934. SMC_GET_MAC_CR(lp, cr);
  935. cr &= ~MAC_CR_RXEN_;
  936. SMC_SET_MAC_CR(lp, cr);
  937. rx_overrun=1;
  938. DBG(SMC_DEBUG_RX, dev, "RX overrun\n");
  939. dev->stats.rx_errors++;
  940. dev->stats.rx_fifo_errors++;
  941. }
  942. SMC_ACK_INT(lp, INT_STS_RDFO_);
  943. }
  944. /* Handle receive condition */
  945. if ((status & INT_STS_RSFL_) || rx_overrun) {
  946. unsigned int fifo;
  947. DBG(SMC_DEBUG_RX, dev, "RX irq\n");
  948. fifo = SMC_GET_RX_FIFO_INF(lp);
  949. pkts = (fifo & RX_FIFO_INF_RXSUSED_) >> 16;
  950. DBG(SMC_DEBUG_RX, dev, "Rx FIFO pkts %d, bytes %d\n",
  951. pkts, fifo & 0xFFFF);
  952. if (pkts != 0) {
  953. #ifdef SMC_USE_DMA
  954. unsigned int fifo;
  955. if (lp->rxdma_active){
  956. DBG(SMC_DEBUG_RX | SMC_DEBUG_DMA, dev,
  957. "RX DMA active\n");
  958. /* The DMA is already running so up the IRQ threshold */
  959. fifo = SMC_GET_FIFO_INT(lp) & ~0xFF;
  960. fifo |= pkts & 0xFF;
  961. DBG(SMC_DEBUG_RX, dev,
  962. "Setting RX stat FIFO threshold to %d\n",
  963. fifo & 0xff);
  964. SMC_SET_FIFO_INT(lp, fifo);
  965. } else
  966. #endif
  967. smc911x_rcv(dev);
  968. }
  969. SMC_ACK_INT(lp, INT_STS_RSFL_);
  970. }
  971. /* Handle transmit FIFO available */
  972. if (status & INT_STS_TDFA_) {
  973. DBG(SMC_DEBUG_TX, dev, "TX data FIFO space available irq\n");
  974. SMC_SET_FIFO_TDA(lp, 0xFF);
  975. lp->tx_throttle = 0;
  976. #ifdef SMC_USE_DMA
  977. if (!lp->txdma_active)
  978. #endif
  979. netif_wake_queue(dev);
  980. SMC_ACK_INT(lp, INT_STS_TDFA_);
  981. }
  982. /* Handle transmit done condition */
  983. #if 1
  984. if (status & (INT_STS_TSFL_ | INT_STS_GPT_INT_)) {
  985. DBG(SMC_DEBUG_TX | SMC_DEBUG_MISC, dev,
  986. "Tx stat FIFO limit (%d) /GPT irq\n",
  987. (SMC_GET_FIFO_INT(lp) & 0x00ff0000) >> 16);
  988. smc911x_tx(dev);
  989. SMC_SET_GPT_CFG(lp, GPT_CFG_TIMER_EN_ | 10000);
  990. SMC_ACK_INT(lp, INT_STS_TSFL_);
  991. SMC_ACK_INT(lp, INT_STS_TSFL_ | INT_STS_GPT_INT_);
  992. }
  993. #else
  994. if (status & INT_STS_TSFL_) {
  995. DBG(SMC_DEBUG_TX, dev, "TX status FIFO limit (%d) irq\n", ?);
  996. smc911x_tx(dev);
  997. SMC_ACK_INT(lp, INT_STS_TSFL_);
  998. }
  999. if (status & INT_STS_GPT_INT_) {
  1000. DBG(SMC_DEBUG_RX, dev, "IRQ_CFG 0x%08x FIFO_INT 0x%08x RX_CFG 0x%08x\n",
  1001. SMC_GET_IRQ_CFG(lp),
  1002. SMC_GET_FIFO_INT(lp),
  1003. SMC_GET_RX_CFG(lp));
  1004. DBG(SMC_DEBUG_RX, dev, "Rx Stat FIFO Used 0x%02x Data FIFO Used 0x%04x Stat FIFO 0x%08x\n",
  1005. (SMC_GET_RX_FIFO_INF(lp) & 0x00ff0000) >> 16,
  1006. SMC_GET_RX_FIFO_INF(lp) & 0xffff,
  1007. SMC_GET_RX_STS_FIFO_PEEK(lp));
  1008. SMC_SET_GPT_CFG(lp, GPT_CFG_TIMER_EN_ | 10000);
  1009. SMC_ACK_INT(lp, INT_STS_GPT_INT_);
  1010. }
  1011. #endif
  1012. /* Handle PHY interrupt condition */
  1013. if (status & INT_STS_PHY_INT_) {
  1014. DBG(SMC_DEBUG_MISC, dev, "PHY irq\n");
  1015. smc911x_phy_interrupt(dev);
  1016. SMC_ACK_INT(lp, INT_STS_PHY_INT_);
  1017. }
  1018. } while (--timeout);
  1019. /* restore mask state */
  1020. SMC_SET_INT_EN(lp, mask);
  1021. DBG(SMC_DEBUG_MISC, dev, "Interrupt done (%d loops)\n",
  1022. 8-timeout);
  1023. spin_unlock_irqrestore(&lp->lock, flags);
  1024. return IRQ_HANDLED;
  1025. }
  1026. #ifdef SMC_USE_DMA
  1027. static void
  1028. smc911x_tx_dma_irq(void *data)
  1029. {
  1030. struct smc911x_local *lp = data;
  1031. struct net_device *dev = lp->netdev;
  1032. struct sk_buff *skb = lp->current_tx_skb;
  1033. unsigned long flags;
  1034. DBG(SMC_DEBUG_FUNC, dev, "--> %s\n", __func__);
  1035. DBG(SMC_DEBUG_TX | SMC_DEBUG_DMA, dev, "TX DMA irq handler\n");
  1036. BUG_ON(skb == NULL);
  1037. dma_unmap_single(NULL, tx_dmabuf, tx_dmalen, DMA_TO_DEVICE);
  1038. netif_trans_update(dev);
  1039. dev_kfree_skb_irq(skb);
  1040. lp->current_tx_skb = NULL;
  1041. if (lp->pending_tx_skb != NULL)
  1042. smc911x_hardware_send_pkt(dev);
  1043. else {
  1044. DBG(SMC_DEBUG_TX | SMC_DEBUG_DMA, dev,
  1045. "No pending Tx packets. DMA disabled\n");
  1046. spin_lock_irqsave(&lp->lock, flags);
  1047. lp->txdma_active = 0;
  1048. if (!lp->tx_throttle) {
  1049. netif_wake_queue(dev);
  1050. }
  1051. spin_unlock_irqrestore(&lp->lock, flags);
  1052. }
  1053. DBG(SMC_DEBUG_TX | SMC_DEBUG_DMA, dev,
  1054. "TX DMA irq completed\n");
  1055. }
  1056. static void
  1057. smc911x_rx_dma_irq(void *data)
  1058. {
  1059. struct smc911x_local *lp = data;
  1060. struct net_device *dev = lp->netdev;
  1061. struct sk_buff *skb = lp->current_rx_skb;
  1062. unsigned long flags;
  1063. unsigned int pkts;
  1064. DBG(SMC_DEBUG_FUNC, dev, "--> %s\n", __func__);
  1065. DBG(SMC_DEBUG_RX | SMC_DEBUG_DMA, dev, "RX DMA irq handler\n");
  1066. dma_unmap_single(NULL, rx_dmabuf, rx_dmalen, DMA_FROM_DEVICE);
  1067. BUG_ON(skb == NULL);
  1068. lp->current_rx_skb = NULL;
  1069. PRINT_PKT(skb->data, skb->len);
  1070. skb->protocol = eth_type_trans(skb, dev);
  1071. dev->stats.rx_packets++;
  1072. dev->stats.rx_bytes += skb->len;
  1073. netif_rx(skb);
  1074. spin_lock_irqsave(&lp->lock, flags);
  1075. pkts = (SMC_GET_RX_FIFO_INF(lp) & RX_FIFO_INF_RXSUSED_) >> 16;
  1076. if (pkts != 0) {
  1077. smc911x_rcv(dev);
  1078. }else {
  1079. lp->rxdma_active = 0;
  1080. }
  1081. spin_unlock_irqrestore(&lp->lock, flags);
  1082. DBG(SMC_DEBUG_RX | SMC_DEBUG_DMA, dev,
  1083. "RX DMA irq completed. DMA RX FIFO PKTS %d\n",
  1084. pkts);
  1085. }
  1086. #endif /* SMC_USE_DMA */
  1087. #ifdef CONFIG_NET_POLL_CONTROLLER
  1088. /*
  1089. * Polling receive - used by netconsole and other diagnostic tools
  1090. * to allow network i/o with interrupts disabled.
  1091. */
  1092. static void smc911x_poll_controller(struct net_device *dev)
  1093. {
  1094. disable_irq(dev->irq);
  1095. smc911x_interrupt(dev->irq, dev);
  1096. enable_irq(dev->irq);
  1097. }
  1098. #endif
  1099. /* Our watchdog timed out. Called by the networking layer */
  1100. static void smc911x_timeout(struct net_device *dev)
  1101. {
  1102. struct smc911x_local *lp = netdev_priv(dev);
  1103. int status, mask;
  1104. unsigned long flags;
  1105. DBG(SMC_DEBUG_FUNC, dev, "--> %s\n", __func__);
  1106. spin_lock_irqsave(&lp->lock, flags);
  1107. status = SMC_GET_INT(lp);
  1108. mask = SMC_GET_INT_EN(lp);
  1109. spin_unlock_irqrestore(&lp->lock, flags);
  1110. DBG(SMC_DEBUG_MISC, dev, "INT 0x%02x MASK 0x%02x\n",
  1111. status, mask);
  1112. /* Dump the current TX FIFO contents and restart */
  1113. mask = SMC_GET_TX_CFG(lp);
  1114. SMC_SET_TX_CFG(lp, mask | TX_CFG_TXS_DUMP_ | TX_CFG_TXD_DUMP_);
  1115. /*
  1116. * Reconfiguring the PHY doesn't seem like a bad idea here, but
  1117. * smc911x_phy_configure() calls msleep() which calls schedule_timeout()
  1118. * which calls schedule(). Hence we use a work queue.
  1119. */
  1120. if (lp->phy_type != 0)
  1121. schedule_work(&lp->phy_configure);
  1122. /* We can accept TX packets again */
  1123. netif_trans_update(dev); /* prevent tx timeout */
  1124. netif_wake_queue(dev);
  1125. }
  1126. /*
  1127. * This routine will, depending on the values passed to it,
  1128. * either make it accept multicast packets, go into
  1129. * promiscuous mode (for TCPDUMP and cousins) or accept
  1130. * a select set of multicast packets
  1131. */
  1132. static void smc911x_set_multicast_list(struct net_device *dev)
  1133. {
  1134. struct smc911x_local *lp = netdev_priv(dev);
  1135. unsigned int multicast_table[2];
  1136. unsigned int mcr, update_multicast = 0;
  1137. unsigned long flags;
  1138. DBG(SMC_DEBUG_FUNC, dev, "--> %s\n", __func__);
  1139. spin_lock_irqsave(&lp->lock, flags);
  1140. SMC_GET_MAC_CR(lp, mcr);
  1141. spin_unlock_irqrestore(&lp->lock, flags);
  1142. if (dev->flags & IFF_PROMISC) {
  1143. DBG(SMC_DEBUG_MISC, dev, "RCR_PRMS\n");
  1144. mcr |= MAC_CR_PRMS_;
  1145. }
  1146. /*
  1147. * Here, I am setting this to accept all multicast packets.
  1148. * I don't need to zero the multicast table, because the flag is
  1149. * checked before the table is
  1150. */
  1151. else if (dev->flags & IFF_ALLMULTI || netdev_mc_count(dev) > 16) {
  1152. DBG(SMC_DEBUG_MISC, dev, "RCR_ALMUL\n");
  1153. mcr |= MAC_CR_MCPAS_;
  1154. }
  1155. /*
  1156. * This sets the internal hardware table to filter out unwanted
  1157. * multicast packets before they take up memory.
  1158. *
  1159. * The SMC chip uses a hash table where the high 6 bits of the CRC of
  1160. * address are the offset into the table. If that bit is 1, then the
  1161. * multicast packet is accepted. Otherwise, it's dropped silently.
  1162. *
  1163. * To use the 6 bits as an offset into the table, the high 1 bit is
  1164. * the number of the 32 bit register, while the low 5 bits are the bit
  1165. * within that register.
  1166. */
  1167. else if (!netdev_mc_empty(dev)) {
  1168. struct netdev_hw_addr *ha;
  1169. /* Set the Hash perfec mode */
  1170. mcr |= MAC_CR_HPFILT_;
  1171. /* start with a table of all zeros: reject all */
  1172. memset(multicast_table, 0, sizeof(multicast_table));
  1173. netdev_for_each_mc_addr(ha, dev) {
  1174. u32 position;
  1175. /* upper 6 bits are used as hash index */
  1176. position = ether_crc(ETH_ALEN, ha->addr)>>26;
  1177. multicast_table[position>>5] |= 1 << (position&0x1f);
  1178. }
  1179. /* be sure I get rid of flags I might have set */
  1180. mcr &= ~(MAC_CR_PRMS_ | MAC_CR_MCPAS_);
  1181. /* now, the table can be loaded into the chipset */
  1182. update_multicast = 1;
  1183. } else {
  1184. DBG(SMC_DEBUG_MISC, dev, "~(MAC_CR_PRMS_|MAC_CR_MCPAS_)\n");
  1185. mcr &= ~(MAC_CR_PRMS_ | MAC_CR_MCPAS_);
  1186. /*
  1187. * since I'm disabling all multicast entirely, I need to
  1188. * clear the multicast list
  1189. */
  1190. memset(multicast_table, 0, sizeof(multicast_table));
  1191. update_multicast = 1;
  1192. }
  1193. spin_lock_irqsave(&lp->lock, flags);
  1194. SMC_SET_MAC_CR(lp, mcr);
  1195. if (update_multicast) {
  1196. DBG(SMC_DEBUG_MISC, dev,
  1197. "update mcast hash table 0x%08x 0x%08x\n",
  1198. multicast_table[0], multicast_table[1]);
  1199. SMC_SET_HASHL(lp, multicast_table[0]);
  1200. SMC_SET_HASHH(lp, multicast_table[1]);
  1201. }
  1202. spin_unlock_irqrestore(&lp->lock, flags);
  1203. }
  1204. /*
  1205. * Open and Initialize the board
  1206. *
  1207. * Set up everything, reset the card, etc..
  1208. */
  1209. static int
  1210. smc911x_open(struct net_device *dev)
  1211. {
  1212. struct smc911x_local *lp = netdev_priv(dev);
  1213. DBG(SMC_DEBUG_FUNC, dev, "--> %s\n", __func__);
  1214. /* reset the hardware */
  1215. smc911x_reset(dev);
  1216. /* Configure the PHY, initialize the link state */
  1217. smc911x_phy_configure(&lp->phy_configure);
  1218. /* Turn on Tx + Rx */
  1219. smc911x_enable(dev);
  1220. netif_start_queue(dev);
  1221. return 0;
  1222. }
  1223. /*
  1224. * smc911x_close
  1225. *
  1226. * this makes the board clean up everything that it can
  1227. * and not talk to the outside world. Caused by
  1228. * an 'ifconfig ethX down'
  1229. */
  1230. static int smc911x_close(struct net_device *dev)
  1231. {
  1232. struct smc911x_local *lp = netdev_priv(dev);
  1233. DBG(SMC_DEBUG_FUNC, dev, "--> %s\n", __func__);
  1234. netif_stop_queue(dev);
  1235. netif_carrier_off(dev);
  1236. /* clear everything */
  1237. smc911x_shutdown(dev);
  1238. if (lp->phy_type != 0) {
  1239. /* We need to ensure that no calls to
  1240. * smc911x_phy_configure are pending.
  1241. */
  1242. cancel_work_sync(&lp->phy_configure);
  1243. smc911x_phy_powerdown(dev, lp->mii.phy_id);
  1244. }
  1245. if (lp->pending_tx_skb) {
  1246. dev_kfree_skb(lp->pending_tx_skb);
  1247. lp->pending_tx_skb = NULL;
  1248. }
  1249. return 0;
  1250. }
  1251. /*
  1252. * Ethtool support
  1253. */
  1254. static int
  1255. smc911x_ethtool_get_link_ksettings(struct net_device *dev,
  1256. struct ethtool_link_ksettings *cmd)
  1257. {
  1258. struct smc911x_local *lp = netdev_priv(dev);
  1259. int status;
  1260. unsigned long flags;
  1261. u32 supported;
  1262. DBG(SMC_DEBUG_FUNC, dev, "--> %s\n", __func__);
  1263. if (lp->phy_type != 0) {
  1264. spin_lock_irqsave(&lp->lock, flags);
  1265. mii_ethtool_get_link_ksettings(&lp->mii, cmd);
  1266. spin_unlock_irqrestore(&lp->lock, flags);
  1267. } else {
  1268. supported = SUPPORTED_10baseT_Half |
  1269. SUPPORTED_10baseT_Full |
  1270. SUPPORTED_TP | SUPPORTED_AUI;
  1271. if (lp->ctl_rspeed == 10)
  1272. cmd->base.speed = SPEED_10;
  1273. else if (lp->ctl_rspeed == 100)
  1274. cmd->base.speed = SPEED_100;
  1275. cmd->base.autoneg = AUTONEG_DISABLE;
  1276. cmd->base.port = 0;
  1277. SMC_GET_PHY_SPECIAL(lp, lp->mii.phy_id, status);
  1278. cmd->base.duplex =
  1279. (status & (PHY_SPECIAL_SPD_10FULL_ | PHY_SPECIAL_SPD_100FULL_)) ?
  1280. DUPLEX_FULL : DUPLEX_HALF;
  1281. ethtool_convert_legacy_u32_to_link_mode(
  1282. cmd->link_modes.supported, supported);
  1283. }
  1284. return 0;
  1285. }
  1286. static int
  1287. smc911x_ethtool_set_link_ksettings(struct net_device *dev,
  1288. const struct ethtool_link_ksettings *cmd)
  1289. {
  1290. struct smc911x_local *lp = netdev_priv(dev);
  1291. int ret;
  1292. unsigned long flags;
  1293. if (lp->phy_type != 0) {
  1294. spin_lock_irqsave(&lp->lock, flags);
  1295. ret = mii_ethtool_set_link_ksettings(&lp->mii, cmd);
  1296. spin_unlock_irqrestore(&lp->lock, flags);
  1297. } else {
  1298. if (cmd->base.autoneg != AUTONEG_DISABLE ||
  1299. cmd->base.speed != SPEED_10 ||
  1300. (cmd->base.duplex != DUPLEX_HALF &&
  1301. cmd->base.duplex != DUPLEX_FULL) ||
  1302. (cmd->base.port != PORT_TP &&
  1303. cmd->base.port != PORT_AUI))
  1304. return -EINVAL;
  1305. lp->ctl_rfduplx = cmd->base.duplex == DUPLEX_FULL;
  1306. ret = 0;
  1307. }
  1308. return ret;
  1309. }
  1310. static void
  1311. smc911x_ethtool_getdrvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
  1312. {
  1313. strlcpy(info->driver, CARDNAME, sizeof(info->driver));
  1314. strlcpy(info->version, version, sizeof(info->version));
  1315. strlcpy(info->bus_info, dev_name(dev->dev.parent),
  1316. sizeof(info->bus_info));
  1317. }
  1318. static int smc911x_ethtool_nwayreset(struct net_device *dev)
  1319. {
  1320. struct smc911x_local *lp = netdev_priv(dev);
  1321. int ret = -EINVAL;
  1322. unsigned long flags;
  1323. if (lp->phy_type != 0) {
  1324. spin_lock_irqsave(&lp->lock, flags);
  1325. ret = mii_nway_restart(&lp->mii);
  1326. spin_unlock_irqrestore(&lp->lock, flags);
  1327. }
  1328. return ret;
  1329. }
  1330. static u32 smc911x_ethtool_getmsglevel(struct net_device *dev)
  1331. {
  1332. struct smc911x_local *lp = netdev_priv(dev);
  1333. return lp->msg_enable;
  1334. }
  1335. static void smc911x_ethtool_setmsglevel(struct net_device *dev, u32 level)
  1336. {
  1337. struct smc911x_local *lp = netdev_priv(dev);
  1338. lp->msg_enable = level;
  1339. }
  1340. static int smc911x_ethtool_getregslen(struct net_device *dev)
  1341. {
  1342. /* System regs + MAC regs + PHY regs */
  1343. return (((E2P_CMD - ID_REV)/4 + 1) +
  1344. (WUCSR - MAC_CR)+1 + 32) * sizeof(u32);
  1345. }
  1346. static void smc911x_ethtool_getregs(struct net_device *dev,
  1347. struct ethtool_regs* regs, void *buf)
  1348. {
  1349. struct smc911x_local *lp = netdev_priv(dev);
  1350. unsigned long flags;
  1351. u32 reg,i,j=0;
  1352. u32 *data = (u32*)buf;
  1353. regs->version = lp->version;
  1354. for(i=ID_REV;i<=E2P_CMD;i+=4) {
  1355. data[j++] = SMC_inl(lp, i);
  1356. }
  1357. for(i=MAC_CR;i<=WUCSR;i++) {
  1358. spin_lock_irqsave(&lp->lock, flags);
  1359. SMC_GET_MAC_CSR(lp, i, reg);
  1360. spin_unlock_irqrestore(&lp->lock, flags);
  1361. data[j++] = reg;
  1362. }
  1363. for(i=0;i<=31;i++) {
  1364. spin_lock_irqsave(&lp->lock, flags);
  1365. SMC_GET_MII(lp, i, lp->mii.phy_id, reg);
  1366. spin_unlock_irqrestore(&lp->lock, flags);
  1367. data[j++] = reg & 0xFFFF;
  1368. }
  1369. }
  1370. static int smc911x_ethtool_wait_eeprom_ready(struct net_device *dev)
  1371. {
  1372. struct smc911x_local *lp = netdev_priv(dev);
  1373. unsigned int timeout;
  1374. int e2p_cmd;
  1375. e2p_cmd = SMC_GET_E2P_CMD(lp);
  1376. for(timeout=10;(e2p_cmd & E2P_CMD_EPC_BUSY_) && timeout; timeout--) {
  1377. if (e2p_cmd & E2P_CMD_EPC_TIMEOUT_) {
  1378. PRINTK(dev, "%s timeout waiting for EEPROM to respond\n",
  1379. __func__);
  1380. return -EFAULT;
  1381. }
  1382. mdelay(1);
  1383. e2p_cmd = SMC_GET_E2P_CMD(lp);
  1384. }
  1385. if (timeout == 0) {
  1386. PRINTK(dev, "%s timeout waiting for EEPROM CMD not busy\n",
  1387. __func__);
  1388. return -ETIMEDOUT;
  1389. }
  1390. return 0;
  1391. }
  1392. static inline int smc911x_ethtool_write_eeprom_cmd(struct net_device *dev,
  1393. int cmd, int addr)
  1394. {
  1395. struct smc911x_local *lp = netdev_priv(dev);
  1396. int ret;
  1397. if ((ret = smc911x_ethtool_wait_eeprom_ready(dev))!=0)
  1398. return ret;
  1399. SMC_SET_E2P_CMD(lp, E2P_CMD_EPC_BUSY_ |
  1400. ((cmd) & (0x7<<28)) |
  1401. ((addr) & 0xFF));
  1402. return 0;
  1403. }
  1404. static inline int smc911x_ethtool_read_eeprom_byte(struct net_device *dev,
  1405. u8 *data)
  1406. {
  1407. struct smc911x_local *lp = netdev_priv(dev);
  1408. int ret;
  1409. if ((ret = smc911x_ethtool_wait_eeprom_ready(dev))!=0)
  1410. return ret;
  1411. *data = SMC_GET_E2P_DATA(lp);
  1412. return 0;
  1413. }
  1414. static inline int smc911x_ethtool_write_eeprom_byte(struct net_device *dev,
  1415. u8 data)
  1416. {
  1417. struct smc911x_local *lp = netdev_priv(dev);
  1418. int ret;
  1419. if ((ret = smc911x_ethtool_wait_eeprom_ready(dev))!=0)
  1420. return ret;
  1421. SMC_SET_E2P_DATA(lp, data);
  1422. return 0;
  1423. }
  1424. static int smc911x_ethtool_geteeprom(struct net_device *dev,
  1425. struct ethtool_eeprom *eeprom, u8 *data)
  1426. {
  1427. u8 eebuf[SMC911X_EEPROM_LEN];
  1428. int i, ret;
  1429. for(i=0;i<SMC911X_EEPROM_LEN;i++) {
  1430. if ((ret=smc911x_ethtool_write_eeprom_cmd(dev, E2P_CMD_EPC_CMD_READ_, i ))!=0)
  1431. return ret;
  1432. if ((ret=smc911x_ethtool_read_eeprom_byte(dev, &eebuf[i]))!=0)
  1433. return ret;
  1434. }
  1435. memcpy(data, eebuf+eeprom->offset, eeprom->len);
  1436. return 0;
  1437. }
  1438. static int smc911x_ethtool_seteeprom(struct net_device *dev,
  1439. struct ethtool_eeprom *eeprom, u8 *data)
  1440. {
  1441. int i, ret;
  1442. /* Enable erase */
  1443. if ((ret=smc911x_ethtool_write_eeprom_cmd(dev, E2P_CMD_EPC_CMD_EWEN_, 0 ))!=0)
  1444. return ret;
  1445. for(i=eeprom->offset;i<(eeprom->offset+eeprom->len);i++) {
  1446. /* erase byte */
  1447. if ((ret=smc911x_ethtool_write_eeprom_cmd(dev, E2P_CMD_EPC_CMD_ERASE_, i ))!=0)
  1448. return ret;
  1449. /* write byte */
  1450. if ((ret=smc911x_ethtool_write_eeprom_byte(dev, *data))!=0)
  1451. return ret;
  1452. if ((ret=smc911x_ethtool_write_eeprom_cmd(dev, E2P_CMD_EPC_CMD_WRITE_, i ))!=0)
  1453. return ret;
  1454. }
  1455. return 0;
  1456. }
  1457. static int smc911x_ethtool_geteeprom_len(struct net_device *dev)
  1458. {
  1459. return SMC911X_EEPROM_LEN;
  1460. }
  1461. static const struct ethtool_ops smc911x_ethtool_ops = {
  1462. .get_drvinfo = smc911x_ethtool_getdrvinfo,
  1463. .get_msglevel = smc911x_ethtool_getmsglevel,
  1464. .set_msglevel = smc911x_ethtool_setmsglevel,
  1465. .nway_reset = smc911x_ethtool_nwayreset,
  1466. .get_link = ethtool_op_get_link,
  1467. .get_regs_len = smc911x_ethtool_getregslen,
  1468. .get_regs = smc911x_ethtool_getregs,
  1469. .get_eeprom_len = smc911x_ethtool_geteeprom_len,
  1470. .get_eeprom = smc911x_ethtool_geteeprom,
  1471. .set_eeprom = smc911x_ethtool_seteeprom,
  1472. .get_link_ksettings = smc911x_ethtool_get_link_ksettings,
  1473. .set_link_ksettings = smc911x_ethtool_set_link_ksettings,
  1474. };
  1475. /*
  1476. * smc911x_findirq
  1477. *
  1478. * This routine has a simple purpose -- make the SMC chip generate an
  1479. * interrupt, so an auto-detect routine can detect it, and find the IRQ,
  1480. */
  1481. static int smc911x_findirq(struct net_device *dev)
  1482. {
  1483. struct smc911x_local *lp = netdev_priv(dev);
  1484. int timeout = 20;
  1485. unsigned long cookie;
  1486. DBG(SMC_DEBUG_FUNC, dev, "--> %s\n", __func__);
  1487. cookie = probe_irq_on();
  1488. /*
  1489. * Force a SW interrupt
  1490. */
  1491. SMC_SET_INT_EN(lp, INT_EN_SW_INT_EN_);
  1492. /*
  1493. * Wait until positive that the interrupt has been generated
  1494. */
  1495. do {
  1496. int int_status;
  1497. udelay(10);
  1498. int_status = SMC_GET_INT_EN(lp);
  1499. if (int_status & INT_EN_SW_INT_EN_)
  1500. break; /* got the interrupt */
  1501. } while (--timeout);
  1502. /*
  1503. * there is really nothing that I can do here if timeout fails,
  1504. * as autoirq_report will return a 0 anyway, which is what I
  1505. * want in this case. Plus, the clean up is needed in both
  1506. * cases.
  1507. */
  1508. /* and disable all interrupts again */
  1509. SMC_SET_INT_EN(lp, 0);
  1510. /* and return what I found */
  1511. return probe_irq_off(cookie);
  1512. }
  1513. static const struct net_device_ops smc911x_netdev_ops = {
  1514. .ndo_open = smc911x_open,
  1515. .ndo_stop = smc911x_close,
  1516. .ndo_start_xmit = smc911x_hard_start_xmit,
  1517. .ndo_tx_timeout = smc911x_timeout,
  1518. .ndo_set_rx_mode = smc911x_set_multicast_list,
  1519. .ndo_validate_addr = eth_validate_addr,
  1520. .ndo_set_mac_address = eth_mac_addr,
  1521. #ifdef CONFIG_NET_POLL_CONTROLLER
  1522. .ndo_poll_controller = smc911x_poll_controller,
  1523. #endif
  1524. };
  1525. /*
  1526. * Function: smc911x_probe(unsigned long ioaddr)
  1527. *
  1528. * Purpose:
  1529. * Tests to see if a given ioaddr points to an SMC911x chip.
  1530. * Returns a 0 on success
  1531. *
  1532. * Algorithm:
  1533. * (1) see if the endian word is OK
  1534. * (1) see if I recognize the chip ID in the appropriate register
  1535. *
  1536. * Here I do typical initialization tasks.
  1537. *
  1538. * o Initialize the structure if needed
  1539. * o print out my vanity message if not done so already
  1540. * o print out what type of hardware is detected
  1541. * o print out the ethernet address
  1542. * o find the IRQ
  1543. * o set up my private data
  1544. * o configure the dev structure with my subroutines
  1545. * o actually GRAB the irq.
  1546. * o GRAB the region
  1547. */
  1548. static int smc911x_probe(struct net_device *dev)
  1549. {
  1550. struct smc911x_local *lp = netdev_priv(dev);
  1551. int i, retval;
  1552. unsigned int val, chip_id, revision;
  1553. const char *version_string;
  1554. unsigned long irq_flags;
  1555. #ifdef SMC_USE_DMA
  1556. struct dma_slave_config config;
  1557. dma_cap_mask_t mask;
  1558. #endif
  1559. DBG(SMC_DEBUG_FUNC, dev, "--> %s\n", __func__);
  1560. /* First, see if the endian word is recognized */
  1561. val = SMC_GET_BYTE_TEST(lp);
  1562. DBG(SMC_DEBUG_MISC, dev, "%s: endian probe returned 0x%04x\n",
  1563. CARDNAME, val);
  1564. if (val != 0x87654321) {
  1565. netdev_err(dev, "Invalid chip endian 0x%08x\n", val);
  1566. retval = -ENODEV;
  1567. goto err_out;
  1568. }
  1569. /*
  1570. * check if the revision register is something that I
  1571. * recognize. These might need to be added to later,
  1572. * as future revisions could be added.
  1573. */
  1574. chip_id = SMC_GET_PN(lp);
  1575. DBG(SMC_DEBUG_MISC, dev, "%s: id probe returned 0x%04x\n",
  1576. CARDNAME, chip_id);
  1577. for(i=0;chip_ids[i].id != 0; i++) {
  1578. if (chip_ids[i].id == chip_id) break;
  1579. }
  1580. if (!chip_ids[i].id) {
  1581. netdev_err(dev, "Unknown chip ID %04x\n", chip_id);
  1582. retval = -ENODEV;
  1583. goto err_out;
  1584. }
  1585. version_string = chip_ids[i].name;
  1586. revision = SMC_GET_REV(lp);
  1587. DBG(SMC_DEBUG_MISC, dev, "%s: revision = 0x%04x\n", CARDNAME, revision);
  1588. /* At this point I'll assume that the chip is an SMC911x. */
  1589. DBG(SMC_DEBUG_MISC, dev, "%s: Found a %s\n",
  1590. CARDNAME, chip_ids[i].name);
  1591. /* Validate the TX FIFO size requested */
  1592. if ((tx_fifo_kb < 2) || (tx_fifo_kb > 14)) {
  1593. netdev_err(dev, "Invalid TX FIFO size requested %d\n",
  1594. tx_fifo_kb);
  1595. retval = -EINVAL;
  1596. goto err_out;
  1597. }
  1598. /* fill in some of the fields */
  1599. lp->version = chip_ids[i].id;
  1600. lp->revision = revision;
  1601. lp->tx_fifo_kb = tx_fifo_kb;
  1602. /* Reverse calculate the RX FIFO size from the TX */
  1603. lp->tx_fifo_size=(lp->tx_fifo_kb<<10) - 512;
  1604. lp->rx_fifo_size= ((0x4000 - 512 - lp->tx_fifo_size) / 16) * 15;
  1605. /* Set the automatic flow control values */
  1606. switch(lp->tx_fifo_kb) {
  1607. /*
  1608. * AFC_HI is about ((Rx Data Fifo Size)*2/3)/64
  1609. * AFC_LO is AFC_HI/2
  1610. * BACK_DUR is about 5uS*(AFC_LO) rounded down
  1611. */
  1612. case 2:/* 13440 Rx Data Fifo Size */
  1613. lp->afc_cfg=0x008C46AF;break;
  1614. case 3:/* 12480 Rx Data Fifo Size */
  1615. lp->afc_cfg=0x0082419F;break;
  1616. case 4:/* 11520 Rx Data Fifo Size */
  1617. lp->afc_cfg=0x00783C9F;break;
  1618. case 5:/* 10560 Rx Data Fifo Size */
  1619. lp->afc_cfg=0x006E374F;break;
  1620. case 6:/* 9600 Rx Data Fifo Size */
  1621. lp->afc_cfg=0x0064328F;break;
  1622. case 7:/* 8640 Rx Data Fifo Size */
  1623. lp->afc_cfg=0x005A2D7F;break;
  1624. case 8:/* 7680 Rx Data Fifo Size */
  1625. lp->afc_cfg=0x0050287F;break;
  1626. case 9:/* 6720 Rx Data Fifo Size */
  1627. lp->afc_cfg=0x0046236F;break;
  1628. case 10:/* 5760 Rx Data Fifo Size */
  1629. lp->afc_cfg=0x003C1E6F;break;
  1630. case 11:/* 4800 Rx Data Fifo Size */
  1631. lp->afc_cfg=0x0032195F;break;
  1632. /*
  1633. * AFC_HI is ~1520 bytes less than RX Data Fifo Size
  1634. * AFC_LO is AFC_HI/2
  1635. * BACK_DUR is about 5uS*(AFC_LO) rounded down
  1636. */
  1637. case 12:/* 3840 Rx Data Fifo Size */
  1638. lp->afc_cfg=0x0024124F;break;
  1639. case 13:/* 2880 Rx Data Fifo Size */
  1640. lp->afc_cfg=0x0015073F;break;
  1641. case 14:/* 1920 Rx Data Fifo Size */
  1642. lp->afc_cfg=0x0006032F;break;
  1643. default:
  1644. PRINTK(dev, "ERROR -- no AFC_CFG setting found");
  1645. break;
  1646. }
  1647. DBG(SMC_DEBUG_MISC | SMC_DEBUG_TX | SMC_DEBUG_RX, dev,
  1648. "%s: tx_fifo %d rx_fifo %d afc_cfg 0x%08x\n", CARDNAME,
  1649. lp->tx_fifo_size, lp->rx_fifo_size, lp->afc_cfg);
  1650. spin_lock_init(&lp->lock);
  1651. /* Get the MAC address */
  1652. SMC_GET_MAC_ADDR(lp, dev->dev_addr);
  1653. /* now, reset the chip, and put it into a known state */
  1654. smc911x_reset(dev);
  1655. /*
  1656. * If dev->irq is 0, then the device has to be banged on to see
  1657. * what the IRQ is.
  1658. *
  1659. * Specifying an IRQ is done with the assumption that the user knows
  1660. * what (s)he is doing. No checking is done!!!!
  1661. */
  1662. if (dev->irq < 1) {
  1663. int trials;
  1664. trials = 3;
  1665. while (trials--) {
  1666. dev->irq = smc911x_findirq(dev);
  1667. if (dev->irq)
  1668. break;
  1669. /* kick the card and try again */
  1670. smc911x_reset(dev);
  1671. }
  1672. }
  1673. if (dev->irq == 0) {
  1674. netdev_warn(dev, "Couldn't autodetect your IRQ. Use irq=xx.\n");
  1675. retval = -ENODEV;
  1676. goto err_out;
  1677. }
  1678. dev->irq = irq_canonicalize(dev->irq);
  1679. dev->netdev_ops = &smc911x_netdev_ops;
  1680. dev->watchdog_timeo = msecs_to_jiffies(watchdog);
  1681. dev->ethtool_ops = &smc911x_ethtool_ops;
  1682. INIT_WORK(&lp->phy_configure, smc911x_phy_configure);
  1683. lp->mii.phy_id_mask = 0x1f;
  1684. lp->mii.reg_num_mask = 0x1f;
  1685. lp->mii.force_media = 0;
  1686. lp->mii.full_duplex = 0;
  1687. lp->mii.dev = dev;
  1688. lp->mii.mdio_read = smc911x_phy_read;
  1689. lp->mii.mdio_write = smc911x_phy_write;
  1690. /*
  1691. * Locate the phy, if any.
  1692. */
  1693. smc911x_phy_detect(dev);
  1694. /* Set default parameters */
  1695. lp->msg_enable = NETIF_MSG_LINK;
  1696. lp->ctl_rfduplx = 1;
  1697. lp->ctl_rspeed = 100;
  1698. #ifdef SMC_DYNAMIC_BUS_CONFIG
  1699. irq_flags = lp->cfg.irq_flags;
  1700. #else
  1701. irq_flags = IRQF_SHARED | SMC_IRQ_SENSE;
  1702. #endif
  1703. /* Grab the IRQ */
  1704. retval = request_irq(dev->irq, smc911x_interrupt,
  1705. irq_flags, dev->name, dev);
  1706. if (retval)
  1707. goto err_out;
  1708. #ifdef SMC_USE_DMA
  1709. dma_cap_zero(mask);
  1710. dma_cap_set(DMA_SLAVE, mask);
  1711. lp->rxdma = dma_request_channel(mask, NULL, NULL);
  1712. lp->txdma = dma_request_channel(mask, NULL, NULL);
  1713. lp->rxdma_active = 0;
  1714. lp->txdma_active = 0;
  1715. memset(&config, 0, sizeof(config));
  1716. config.src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
  1717. config.dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
  1718. config.src_addr = lp->physaddr + RX_DATA_FIFO;
  1719. config.dst_addr = lp->physaddr + TX_DATA_FIFO;
  1720. config.src_maxburst = 32;
  1721. config.dst_maxburst = 32;
  1722. retval = dmaengine_slave_config(lp->rxdma, &config);
  1723. if (retval) {
  1724. dev_err(lp->dev, "dma rx channel configuration failed: %d\n",
  1725. retval);
  1726. goto err_out;
  1727. }
  1728. retval = dmaengine_slave_config(lp->txdma, &config);
  1729. if (retval) {
  1730. dev_err(lp->dev, "dma tx channel configuration failed: %d\n",
  1731. retval);
  1732. goto err_out;
  1733. }
  1734. #endif
  1735. retval = register_netdev(dev);
  1736. if (retval == 0) {
  1737. /* now, print out the card info, in a short format.. */
  1738. netdev_info(dev, "%s (rev %d) at %#lx IRQ %d",
  1739. version_string, lp->revision,
  1740. dev->base_addr, dev->irq);
  1741. #ifdef SMC_USE_DMA
  1742. if (lp->rxdma)
  1743. pr_cont(" RXDMA %p", lp->rxdma);
  1744. if (lp->txdma)
  1745. pr_cont(" TXDMA %p", lp->txdma);
  1746. #endif
  1747. pr_cont("\n");
  1748. if (!is_valid_ether_addr(dev->dev_addr)) {
  1749. netdev_warn(dev, "Invalid ethernet MAC address. Please set using ifconfig\n");
  1750. } else {
  1751. /* Print the Ethernet address */
  1752. netdev_info(dev, "Ethernet addr: %pM\n",
  1753. dev->dev_addr);
  1754. }
  1755. if (lp->phy_type == 0) {
  1756. PRINTK(dev, "No PHY found\n");
  1757. } else if ((lp->phy_type & ~0xff) == LAN911X_INTERNAL_PHY_ID) {
  1758. PRINTK(dev, "LAN911x Internal PHY\n");
  1759. } else {
  1760. PRINTK(dev, "External PHY 0x%08x\n", lp->phy_type);
  1761. }
  1762. }
  1763. err_out:
  1764. #ifdef SMC_USE_DMA
  1765. if (retval) {
  1766. if (lp->rxdma)
  1767. dma_release_channel(lp->rxdma);
  1768. if (lp->txdma)
  1769. dma_release_channel(lp->txdma);
  1770. }
  1771. #endif
  1772. return retval;
  1773. }
  1774. /*
  1775. * smc911x_drv_probe(void)
  1776. *
  1777. * Output:
  1778. * 0 --> there is a device
  1779. * anything else, error
  1780. */
  1781. static int smc911x_drv_probe(struct platform_device *pdev)
  1782. {
  1783. struct net_device *ndev;
  1784. struct resource *res;
  1785. struct smc911x_local *lp;
  1786. void __iomem *addr;
  1787. int ret;
  1788. /* ndev is not valid yet, so avoid passing it in. */
  1789. DBG(SMC_DEBUG_FUNC, "--> %s\n", __func__);
  1790. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1791. if (!res) {
  1792. ret = -ENODEV;
  1793. goto out;
  1794. }
  1795. /*
  1796. * Request the regions.
  1797. */
  1798. if (!request_mem_region(res->start, SMC911X_IO_EXTENT, CARDNAME)) {
  1799. ret = -EBUSY;
  1800. goto out;
  1801. }
  1802. ndev = alloc_etherdev(sizeof(struct smc911x_local));
  1803. if (!ndev) {
  1804. ret = -ENOMEM;
  1805. goto release_1;
  1806. }
  1807. SET_NETDEV_DEV(ndev, &pdev->dev);
  1808. ndev->dma = (unsigned char)-1;
  1809. ndev->irq = platform_get_irq(pdev, 0);
  1810. lp = netdev_priv(ndev);
  1811. lp->netdev = ndev;
  1812. #ifdef SMC_DYNAMIC_BUS_CONFIG
  1813. {
  1814. struct smc911x_platdata *pd = dev_get_platdata(&pdev->dev);
  1815. if (!pd) {
  1816. ret = -EINVAL;
  1817. goto release_both;
  1818. }
  1819. memcpy(&lp->cfg, pd, sizeof(lp->cfg));
  1820. }
  1821. #endif
  1822. addr = ioremap(res->start, SMC911X_IO_EXTENT);
  1823. if (!addr) {
  1824. ret = -ENOMEM;
  1825. goto release_both;
  1826. }
  1827. platform_set_drvdata(pdev, ndev);
  1828. lp->base = addr;
  1829. ndev->base_addr = res->start;
  1830. ret = smc911x_probe(ndev);
  1831. if (ret != 0) {
  1832. iounmap(addr);
  1833. release_both:
  1834. free_netdev(ndev);
  1835. release_1:
  1836. release_mem_region(res->start, SMC911X_IO_EXTENT);
  1837. out:
  1838. pr_info("%s: not found (%d).\n", CARDNAME, ret);
  1839. }
  1840. #ifdef SMC_USE_DMA
  1841. else {
  1842. lp->physaddr = res->start;
  1843. lp->dev = &pdev->dev;
  1844. }
  1845. #endif
  1846. return ret;
  1847. }
  1848. static int smc911x_drv_remove(struct platform_device *pdev)
  1849. {
  1850. struct net_device *ndev = platform_get_drvdata(pdev);
  1851. struct smc911x_local *lp = netdev_priv(ndev);
  1852. struct resource *res;
  1853. DBG(SMC_DEBUG_FUNC, ndev, "--> %s\n", __func__);
  1854. unregister_netdev(ndev);
  1855. free_irq(ndev->irq, ndev);
  1856. #ifdef SMC_USE_DMA
  1857. {
  1858. if (lp->rxdma)
  1859. dma_release_channel(lp->rxdma);
  1860. if (lp->txdma)
  1861. dma_release_channel(lp->txdma);
  1862. }
  1863. #endif
  1864. iounmap(lp->base);
  1865. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1866. release_mem_region(res->start, SMC911X_IO_EXTENT);
  1867. free_netdev(ndev);
  1868. return 0;
  1869. }
  1870. static int smc911x_drv_suspend(struct platform_device *dev, pm_message_t state)
  1871. {
  1872. struct net_device *ndev = platform_get_drvdata(dev);
  1873. struct smc911x_local *lp = netdev_priv(ndev);
  1874. DBG(SMC_DEBUG_FUNC, ndev, "--> %s\n", __func__);
  1875. if (ndev) {
  1876. if (netif_running(ndev)) {
  1877. netif_device_detach(ndev);
  1878. smc911x_shutdown(ndev);
  1879. #if POWER_DOWN
  1880. /* Set D2 - Energy detect only setting */
  1881. SMC_SET_PMT_CTRL(lp, 2<<12);
  1882. #endif
  1883. }
  1884. }
  1885. return 0;
  1886. }
  1887. static int smc911x_drv_resume(struct platform_device *dev)
  1888. {
  1889. struct net_device *ndev = platform_get_drvdata(dev);
  1890. DBG(SMC_DEBUG_FUNC, ndev, "--> %s\n", __func__);
  1891. if (ndev) {
  1892. struct smc911x_local *lp = netdev_priv(ndev);
  1893. if (netif_running(ndev)) {
  1894. smc911x_reset(ndev);
  1895. if (lp->phy_type != 0)
  1896. smc911x_phy_configure(&lp->phy_configure);
  1897. smc911x_enable(ndev);
  1898. netif_device_attach(ndev);
  1899. }
  1900. }
  1901. return 0;
  1902. }
  1903. static struct platform_driver smc911x_driver = {
  1904. .probe = smc911x_drv_probe,
  1905. .remove = smc911x_drv_remove,
  1906. .suspend = smc911x_drv_suspend,
  1907. .resume = smc911x_drv_resume,
  1908. .driver = {
  1909. .name = CARDNAME,
  1910. },
  1911. };
  1912. module_platform_driver(smc911x_driver);