smc91x.c 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418
  1. /*
  2. * smc91x.c
  3. * This is a driver for SMSC's 91C9x/91C1xx single-chip Ethernet devices.
  4. *
  5. * Copyright (C) 1996 by Erik Stahlman
  6. * Copyright (C) 2001 Standard Microsystems Corporation
  7. * Developed by Simple Network Magic Corporation
  8. * Copyright (C) 2003 Monta Vista Software, Inc.
  9. * Unified SMC91x driver by Nicolas Pitre
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  24. *
  25. * Arguments:
  26. * io = for the base address
  27. * irq = for the IRQ
  28. * nowait = 0 for normal wait states, 1 eliminates additional wait states
  29. *
  30. * original author:
  31. * Erik Stahlman <erik@vt.edu>
  32. *
  33. * hardware multicast code:
  34. * Peter Cammaert <pc@denkart.be>
  35. *
  36. * contributors:
  37. * Daris A Nevil <dnevil@snmc.com>
  38. * Nicolas Pitre <nico@cam.org>
  39. * Russell King <rmk@arm.linux.org.uk>
  40. *
  41. * History:
  42. * 08/20/00 Arnaldo Melo fix kfree(skb) in smc_hardware_send_packet
  43. * 12/15/00 Christian Jullien fix "Warning: kfree_skb on hard IRQ"
  44. * 03/16/01 Daris A Nevil modified smc9194.c for use with LAN91C111
  45. * 08/22/01 Scott Anderson merge changes from smc9194 to smc91111
  46. * 08/21/01 Pramod B Bhardwaj added support for RevB of LAN91C111
  47. * 12/20/01 Jeff Sutherland initial port to Xscale PXA with DMA support
  48. * 04/07/03 Nicolas Pitre unified SMC91x driver, killed irq races,
  49. * more bus abstraction, big cleanup, etc.
  50. * 29/09/03 Russell King - add driver model support
  51. * - ethtool support
  52. * - convert to use generic MII interface
  53. * - add link up/down notification
  54. * - don't try to handle full negotiation in
  55. * smc_phy_configure
  56. * - clean up (and fix stack overrun) in PHY
  57. * MII read/write functions
  58. * 22/09/04 Nicolas Pitre big update (see commit log for details)
  59. */
  60. static const char version[] =
  61. "smc91x.c: v1.1, sep 22 2004 by Nicolas Pitre <nico@cam.org>\n";
  62. /* Debugging level */
  63. #ifndef SMC_DEBUG
  64. #define SMC_DEBUG 0
  65. #endif
  66. #include <linux/init.h>
  67. #include <linux/module.h>
  68. #include <linux/kernel.h>
  69. #include <linux/sched.h>
  70. #include <linux/slab.h>
  71. #include <linux/delay.h>
  72. #include <linux/interrupt.h>
  73. #include <linux/errno.h>
  74. #include <linux/ioport.h>
  75. #include <linux/crc32.h>
  76. #include <linux/platform_device.h>
  77. #include <linux/spinlock.h>
  78. #include <linux/ethtool.h>
  79. #include <linux/mii.h>
  80. #include <linux/workqueue.h>
  81. #include <linux/netdevice.h>
  82. #include <linux/etherdevice.h>
  83. #include <linux/skbuff.h>
  84. #include <asm/io.h>
  85. #include "smc91x.h"
  86. #ifndef SMC_NOWAIT
  87. # define SMC_NOWAIT 0
  88. #endif
  89. static int nowait = SMC_NOWAIT;
  90. module_param(nowait, int, 0400);
  91. MODULE_PARM_DESC(nowait, "set to 1 for no wait state");
  92. /*
  93. * Transmit timeout, default 5 seconds.
  94. */
  95. static int watchdog = 1000;
  96. module_param(watchdog, int, 0400);
  97. MODULE_PARM_DESC(watchdog, "transmit timeout in milliseconds");
  98. MODULE_LICENSE("GPL");
  99. MODULE_ALIAS("platform:smc91x");
  100. /*
  101. * The internal workings of the driver. If you are changing anything
  102. * here with the SMC stuff, you should have the datasheet and know
  103. * what you are doing.
  104. */
  105. #define CARDNAME "smc91x"
  106. /*
  107. * Use power-down feature of the chip
  108. */
  109. #define POWER_DOWN 1
  110. /*
  111. * Wait time for memory to be free. This probably shouldn't be
  112. * tuned that much, as waiting for this means nothing else happens
  113. * in the system
  114. */
  115. #define MEMORY_WAIT_TIME 16
  116. /*
  117. * The maximum number of processing loops allowed for each call to the
  118. * IRQ handler.
  119. */
  120. #define MAX_IRQ_LOOPS 8
  121. /*
  122. * This selects whether TX packets are sent one by one to the SMC91x internal
  123. * memory and throttled until transmission completes. This may prevent
  124. * RX overruns a litle by keeping much of the memory free for RX packets
  125. * but to the expense of reduced TX throughput and increased IRQ overhead.
  126. * Note this is not a cure for a too slow data bus or too high IRQ latency.
  127. */
  128. #define THROTTLE_TX_PKTS 0
  129. /*
  130. * The MII clock high/low times. 2x this number gives the MII clock period
  131. * in microseconds. (was 50, but this gives 6.4ms for each MII transaction!)
  132. */
  133. #define MII_DELAY 1
  134. #if SMC_DEBUG > 0
  135. #define DBG(n, args...) \
  136. do { \
  137. if (SMC_DEBUG >= (n)) \
  138. printk(args); \
  139. } while (0)
  140. #define PRINTK(args...) printk(args)
  141. #else
  142. #define DBG(n, args...) do { } while(0)
  143. #define PRINTK(args...) printk(KERN_DEBUG args)
  144. #endif
  145. #if SMC_DEBUG > 3
  146. static void PRINT_PKT(u_char *buf, int length)
  147. {
  148. int i;
  149. int remainder;
  150. int lines;
  151. lines = length / 16;
  152. remainder = length % 16;
  153. for (i = 0; i < lines ; i ++) {
  154. int cur;
  155. for (cur = 0; cur < 8; cur++) {
  156. u_char a, b;
  157. a = *buf++;
  158. b = *buf++;
  159. printk("%02x%02x ", a, b);
  160. }
  161. printk("\n");
  162. }
  163. for (i = 0; i < remainder/2 ; i++) {
  164. u_char a, b;
  165. a = *buf++;
  166. b = *buf++;
  167. printk("%02x%02x ", a, b);
  168. }
  169. printk("\n");
  170. }
  171. #else
  172. #define PRINT_PKT(x...) do { } while(0)
  173. #endif
  174. /* this enables an interrupt in the interrupt mask register */
  175. #define SMC_ENABLE_INT(lp, x) do { \
  176. unsigned char mask; \
  177. spin_lock_irq(&lp->lock); \
  178. mask = SMC_GET_INT_MASK(lp); \
  179. mask |= (x); \
  180. SMC_SET_INT_MASK(lp, mask); \
  181. spin_unlock_irq(&lp->lock); \
  182. } while (0)
  183. /* this disables an interrupt from the interrupt mask register */
  184. #define SMC_DISABLE_INT(lp, x) do { \
  185. unsigned char mask; \
  186. spin_lock_irq(&lp->lock); \
  187. mask = SMC_GET_INT_MASK(lp); \
  188. mask &= ~(x); \
  189. SMC_SET_INT_MASK(lp, mask); \
  190. spin_unlock_irq(&lp->lock); \
  191. } while (0)
  192. /*
  193. * Wait while MMU is busy. This is usually in the order of a few nanosecs
  194. * if at all, but let's avoid deadlocking the system if the hardware
  195. * decides to go south.
  196. */
  197. #define SMC_WAIT_MMU_BUSY(lp) do { \
  198. if (unlikely(SMC_GET_MMU_CMD(lp) & MC_BUSY)) { \
  199. unsigned long timeout = jiffies + 2; \
  200. while (SMC_GET_MMU_CMD(lp) & MC_BUSY) { \
  201. if (time_after(jiffies, timeout)) { \
  202. printk("%s: timeout %s line %d\n", \
  203. dev->name, __FILE__, __LINE__); \
  204. break; \
  205. } \
  206. cpu_relax(); \
  207. } \
  208. } \
  209. } while (0)
  210. /*
  211. * this does a soft reset on the device
  212. */
  213. static void smc_reset(struct net_device *dev)
  214. {
  215. struct smc_local *lp = netdev_priv(dev);
  216. void __iomem *ioaddr = lp->base;
  217. unsigned int ctl, cfg;
  218. struct sk_buff *pending_skb;
  219. DBG(2, "%s: %s\n", dev->name, __func__);
  220. /* Disable all interrupts, block TX tasklet */
  221. spin_lock_irq(&lp->lock);
  222. SMC_SELECT_BANK(lp, 2);
  223. SMC_SET_INT_MASK(lp, 0);
  224. pending_skb = lp->pending_tx_skb;
  225. lp->pending_tx_skb = NULL;
  226. spin_unlock_irq(&lp->lock);
  227. /* free any pending tx skb */
  228. if (pending_skb) {
  229. dev_kfree_skb(pending_skb);
  230. dev->stats.tx_errors++;
  231. dev->stats.tx_aborted_errors++;
  232. }
  233. /*
  234. * This resets the registers mostly to defaults, but doesn't
  235. * affect EEPROM. That seems unnecessary
  236. */
  237. SMC_SELECT_BANK(lp, 0);
  238. SMC_SET_RCR(lp, RCR_SOFTRST);
  239. /*
  240. * Setup the Configuration Register
  241. * This is necessary because the CONFIG_REG is not affected
  242. * by a soft reset
  243. */
  244. SMC_SELECT_BANK(lp, 1);
  245. cfg = CONFIG_DEFAULT;
  246. /*
  247. * Setup for fast accesses if requested. If the card/system
  248. * can't handle it then there will be no recovery except for
  249. * a hard reset or power cycle
  250. */
  251. if (lp->cfg.flags & SMC91X_NOWAIT)
  252. cfg |= CONFIG_NO_WAIT;
  253. /*
  254. * Release from possible power-down state
  255. * Configuration register is not affected by Soft Reset
  256. */
  257. cfg |= CONFIG_EPH_POWER_EN;
  258. SMC_SET_CONFIG(lp, cfg);
  259. /* this should pause enough for the chip to be happy */
  260. /*
  261. * elaborate? What does the chip _need_? --jgarzik
  262. *
  263. * This seems to be undocumented, but something the original
  264. * driver(s) have always done. Suspect undocumented timing
  265. * info/determined empirically. --rmk
  266. */
  267. udelay(1);
  268. /* Disable transmit and receive functionality */
  269. SMC_SELECT_BANK(lp, 0);
  270. SMC_SET_RCR(lp, RCR_CLEAR);
  271. SMC_SET_TCR(lp, TCR_CLEAR);
  272. SMC_SELECT_BANK(lp, 1);
  273. ctl = SMC_GET_CTL(lp) | CTL_LE_ENABLE;
  274. /*
  275. * Set the control register to automatically release successfully
  276. * transmitted packets, to make the best use out of our limited
  277. * memory
  278. */
  279. if(!THROTTLE_TX_PKTS)
  280. ctl |= CTL_AUTO_RELEASE;
  281. else
  282. ctl &= ~CTL_AUTO_RELEASE;
  283. SMC_SET_CTL(lp, ctl);
  284. /* Reset the MMU */
  285. SMC_SELECT_BANK(lp, 2);
  286. SMC_SET_MMU_CMD(lp, MC_RESET);
  287. SMC_WAIT_MMU_BUSY(lp);
  288. }
  289. /*
  290. * Enable Interrupts, Receive, and Transmit
  291. */
  292. static void smc_enable(struct net_device *dev)
  293. {
  294. struct smc_local *lp = netdev_priv(dev);
  295. void __iomem *ioaddr = lp->base;
  296. int mask;
  297. DBG(2, "%s: %s\n", dev->name, __func__);
  298. /* see the header file for options in TCR/RCR DEFAULT */
  299. SMC_SELECT_BANK(lp, 0);
  300. SMC_SET_TCR(lp, lp->tcr_cur_mode);
  301. SMC_SET_RCR(lp, lp->rcr_cur_mode);
  302. SMC_SELECT_BANK(lp, 1);
  303. SMC_SET_MAC_ADDR(lp, dev->dev_addr);
  304. /* now, enable interrupts */
  305. mask = IM_EPH_INT|IM_RX_OVRN_INT|IM_RCV_INT;
  306. if (lp->version >= (CHIP_91100 << 4))
  307. mask |= IM_MDINT;
  308. SMC_SELECT_BANK(lp, 2);
  309. SMC_SET_INT_MASK(lp, mask);
  310. /*
  311. * From this point the register bank must _NOT_ be switched away
  312. * to something else than bank 2 without proper locking against
  313. * races with any tasklet or interrupt handlers until smc_shutdown()
  314. * or smc_reset() is called.
  315. */
  316. }
  317. /*
  318. * this puts the device in an inactive state
  319. */
  320. static void smc_shutdown(struct net_device *dev)
  321. {
  322. struct smc_local *lp = netdev_priv(dev);
  323. void __iomem *ioaddr = lp->base;
  324. struct sk_buff *pending_skb;
  325. DBG(2, "%s: %s\n", CARDNAME, __func__);
  326. /* no more interrupts for me */
  327. spin_lock_irq(&lp->lock);
  328. SMC_SELECT_BANK(lp, 2);
  329. SMC_SET_INT_MASK(lp, 0);
  330. pending_skb = lp->pending_tx_skb;
  331. lp->pending_tx_skb = NULL;
  332. spin_unlock_irq(&lp->lock);
  333. if (pending_skb)
  334. dev_kfree_skb(pending_skb);
  335. /* and tell the card to stay away from that nasty outside world */
  336. SMC_SELECT_BANK(lp, 0);
  337. SMC_SET_RCR(lp, RCR_CLEAR);
  338. SMC_SET_TCR(lp, TCR_CLEAR);
  339. #ifdef POWER_DOWN
  340. /* finally, shut the chip down */
  341. SMC_SELECT_BANK(lp, 1);
  342. SMC_SET_CONFIG(lp, SMC_GET_CONFIG(lp) & ~CONFIG_EPH_POWER_EN);
  343. #endif
  344. }
  345. /*
  346. * This is the procedure to handle the receipt of a packet.
  347. */
  348. static inline void smc_rcv(struct net_device *dev)
  349. {
  350. struct smc_local *lp = netdev_priv(dev);
  351. void __iomem *ioaddr = lp->base;
  352. unsigned int packet_number, status, packet_len;
  353. DBG(3, "%s: %s\n", dev->name, __func__);
  354. packet_number = SMC_GET_RXFIFO(lp);
  355. if (unlikely(packet_number & RXFIFO_REMPTY)) {
  356. PRINTK("%s: smc_rcv with nothing on FIFO.\n", dev->name);
  357. return;
  358. }
  359. /* read from start of packet */
  360. SMC_SET_PTR(lp, PTR_READ | PTR_RCV | PTR_AUTOINC);
  361. /* First two words are status and packet length */
  362. SMC_GET_PKT_HDR(lp, status, packet_len);
  363. packet_len &= 0x07ff; /* mask off top bits */
  364. DBG(2, "%s: RX PNR 0x%x STATUS 0x%04x LENGTH 0x%04x (%d)\n",
  365. dev->name, packet_number, status,
  366. packet_len, packet_len);
  367. back:
  368. if (unlikely(packet_len < 6 || status & RS_ERRORS)) {
  369. if (status & RS_TOOLONG && packet_len <= (1514 + 4 + 6)) {
  370. /* accept VLAN packets */
  371. status &= ~RS_TOOLONG;
  372. goto back;
  373. }
  374. if (packet_len < 6) {
  375. /* bloody hardware */
  376. printk(KERN_ERR "%s: fubar (rxlen %u status %x\n",
  377. dev->name, packet_len, status);
  378. status |= RS_TOOSHORT;
  379. }
  380. SMC_WAIT_MMU_BUSY(lp);
  381. SMC_SET_MMU_CMD(lp, MC_RELEASE);
  382. dev->stats.rx_errors++;
  383. if (status & RS_ALGNERR)
  384. dev->stats.rx_frame_errors++;
  385. if (status & (RS_TOOSHORT | RS_TOOLONG))
  386. dev->stats.rx_length_errors++;
  387. if (status & RS_BADCRC)
  388. dev->stats.rx_crc_errors++;
  389. } else {
  390. struct sk_buff *skb;
  391. unsigned char *data;
  392. unsigned int data_len;
  393. /* set multicast stats */
  394. if (status & RS_MULTICAST)
  395. dev->stats.multicast++;
  396. /*
  397. * Actual payload is packet_len - 6 (or 5 if odd byte).
  398. * We want skb_reserve(2) and the final ctrl word
  399. * (2 bytes, possibly containing the payload odd byte).
  400. * Furthermore, we add 2 bytes to allow rounding up to
  401. * multiple of 4 bytes on 32 bit buses.
  402. * Hence packet_len - 6 + 2 + 2 + 2.
  403. */
  404. skb = dev_alloc_skb(packet_len);
  405. if (unlikely(skb == NULL)) {
  406. printk(KERN_NOTICE "%s: Low memory, packet dropped.\n",
  407. dev->name);
  408. SMC_WAIT_MMU_BUSY(lp);
  409. SMC_SET_MMU_CMD(lp, MC_RELEASE);
  410. dev->stats.rx_dropped++;
  411. return;
  412. }
  413. /* Align IP header to 32 bits */
  414. skb_reserve(skb, 2);
  415. /* BUG: the LAN91C111 rev A never sets this bit. Force it. */
  416. if (lp->version == 0x90)
  417. status |= RS_ODDFRAME;
  418. /*
  419. * If odd length: packet_len - 5,
  420. * otherwise packet_len - 6.
  421. * With the trailing ctrl byte it's packet_len - 4.
  422. */
  423. data_len = packet_len - ((status & RS_ODDFRAME) ? 5 : 6);
  424. data = skb_put(skb, data_len);
  425. SMC_PULL_DATA(lp, data, packet_len - 4);
  426. SMC_WAIT_MMU_BUSY(lp);
  427. SMC_SET_MMU_CMD(lp, MC_RELEASE);
  428. PRINT_PKT(data, packet_len - 4);
  429. skb->protocol = eth_type_trans(skb, dev);
  430. netif_rx(skb);
  431. dev->stats.rx_packets++;
  432. dev->stats.rx_bytes += data_len;
  433. }
  434. }
  435. #ifdef CONFIG_SMP
  436. /*
  437. * On SMP we have the following problem:
  438. *
  439. * A = smc_hardware_send_pkt()
  440. * B = smc_hard_start_xmit()
  441. * C = smc_interrupt()
  442. *
  443. * A and B can never be executed simultaneously. However, at least on UP,
  444. * it is possible (and even desirable) for C to interrupt execution of
  445. * A or B in order to have better RX reliability and avoid overruns.
  446. * C, just like A and B, must have exclusive access to the chip and
  447. * each of them must lock against any other concurrent access.
  448. * Unfortunately this is not possible to have C suspend execution of A or
  449. * B taking place on another CPU. On UP this is no an issue since A and B
  450. * are run from softirq context and C from hard IRQ context, and there is
  451. * no other CPU where concurrent access can happen.
  452. * If ever there is a way to force at least B and C to always be executed
  453. * on the same CPU then we could use read/write locks to protect against
  454. * any other concurrent access and C would always interrupt B. But life
  455. * isn't that easy in a SMP world...
  456. */
  457. #define smc_special_trylock(lock) \
  458. ({ \
  459. int __ret; \
  460. local_irq_disable(); \
  461. __ret = spin_trylock(lock); \
  462. if (!__ret) \
  463. local_irq_enable(); \
  464. __ret; \
  465. })
  466. #define smc_special_lock(lock) spin_lock_irq(lock)
  467. #define smc_special_unlock(lock) spin_unlock_irq(lock)
  468. #else
  469. #define smc_special_trylock(lock) (1)
  470. #define smc_special_lock(lock) do { } while (0)
  471. #define smc_special_unlock(lock) do { } while (0)
  472. #endif
  473. /*
  474. * This is called to actually send a packet to the chip.
  475. */
  476. static void smc_hardware_send_pkt(unsigned long data)
  477. {
  478. struct net_device *dev = (struct net_device *)data;
  479. struct smc_local *lp = netdev_priv(dev);
  480. void __iomem *ioaddr = lp->base;
  481. struct sk_buff *skb;
  482. unsigned int packet_no, len;
  483. unsigned char *buf;
  484. DBG(3, "%s: %s\n", dev->name, __func__);
  485. if (!smc_special_trylock(&lp->lock)) {
  486. netif_stop_queue(dev);
  487. tasklet_schedule(&lp->tx_task);
  488. return;
  489. }
  490. skb = lp->pending_tx_skb;
  491. if (unlikely(!skb)) {
  492. smc_special_unlock(&lp->lock);
  493. return;
  494. }
  495. lp->pending_tx_skb = NULL;
  496. packet_no = SMC_GET_AR(lp);
  497. if (unlikely(packet_no & AR_FAILED)) {
  498. printk("%s: Memory allocation failed.\n", dev->name);
  499. dev->stats.tx_errors++;
  500. dev->stats.tx_fifo_errors++;
  501. smc_special_unlock(&lp->lock);
  502. goto done;
  503. }
  504. /* point to the beginning of the packet */
  505. SMC_SET_PN(lp, packet_no);
  506. SMC_SET_PTR(lp, PTR_AUTOINC);
  507. buf = skb->data;
  508. len = skb->len;
  509. DBG(2, "%s: TX PNR 0x%x LENGTH 0x%04x (%d) BUF 0x%p\n",
  510. dev->name, packet_no, len, len, buf);
  511. PRINT_PKT(buf, len);
  512. /*
  513. * Send the packet length (+6 for status words, length, and ctl.
  514. * The card will pad to 64 bytes with zeroes if packet is too small.
  515. */
  516. SMC_PUT_PKT_HDR(lp, 0, len + 6);
  517. /* send the actual data */
  518. SMC_PUSH_DATA(lp, buf, len & ~1);
  519. /* Send final ctl word with the last byte if there is one */
  520. SMC_outw(((len & 1) ? (0x2000 | buf[len-1]) : 0), ioaddr, DATA_REG(lp));
  521. /*
  522. * If THROTTLE_TX_PKTS is set, we stop the queue here. This will
  523. * have the effect of having at most one packet queued for TX
  524. * in the chip's memory at all time.
  525. *
  526. * If THROTTLE_TX_PKTS is not set then the queue is stopped only
  527. * when memory allocation (MC_ALLOC) does not succeed right away.
  528. */
  529. if (THROTTLE_TX_PKTS)
  530. netif_stop_queue(dev);
  531. /* queue the packet for TX */
  532. SMC_SET_MMU_CMD(lp, MC_ENQUEUE);
  533. smc_special_unlock(&lp->lock);
  534. dev->trans_start = jiffies;
  535. dev->stats.tx_packets++;
  536. dev->stats.tx_bytes += len;
  537. SMC_ENABLE_INT(lp, IM_TX_INT | IM_TX_EMPTY_INT);
  538. done: if (!THROTTLE_TX_PKTS)
  539. netif_wake_queue(dev);
  540. dev_kfree_skb(skb);
  541. }
  542. /*
  543. * Since I am not sure if I will have enough room in the chip's ram
  544. * to store the packet, I call this routine which either sends it
  545. * now, or set the card to generates an interrupt when ready
  546. * for the packet.
  547. */
  548. static int smc_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
  549. {
  550. struct smc_local *lp = netdev_priv(dev);
  551. void __iomem *ioaddr = lp->base;
  552. unsigned int numPages, poll_count, status;
  553. DBG(3, "%s: %s\n", dev->name, __func__);
  554. BUG_ON(lp->pending_tx_skb != NULL);
  555. /*
  556. * The MMU wants the number of pages to be the number of 256 bytes
  557. * 'pages', minus 1 (since a packet can't ever have 0 pages :))
  558. *
  559. * The 91C111 ignores the size bits, but earlier models don't.
  560. *
  561. * Pkt size for allocating is data length +6 (for additional status
  562. * words, length and ctl)
  563. *
  564. * If odd size then last byte is included in ctl word.
  565. */
  566. numPages = ((skb->len & ~1) + (6 - 1)) >> 8;
  567. if (unlikely(numPages > 7)) {
  568. printk("%s: Far too big packet error.\n", dev->name);
  569. dev->stats.tx_errors++;
  570. dev->stats.tx_dropped++;
  571. dev_kfree_skb(skb);
  572. return 0;
  573. }
  574. smc_special_lock(&lp->lock);
  575. /* now, try to allocate the memory */
  576. SMC_SET_MMU_CMD(lp, MC_ALLOC | numPages);
  577. /*
  578. * Poll the chip for a short amount of time in case the
  579. * allocation succeeds quickly.
  580. */
  581. poll_count = MEMORY_WAIT_TIME;
  582. do {
  583. status = SMC_GET_INT(lp);
  584. if (status & IM_ALLOC_INT) {
  585. SMC_ACK_INT(lp, IM_ALLOC_INT);
  586. break;
  587. }
  588. } while (--poll_count);
  589. smc_special_unlock(&lp->lock);
  590. lp->pending_tx_skb = skb;
  591. if (!poll_count) {
  592. /* oh well, wait until the chip finds memory later */
  593. netif_stop_queue(dev);
  594. DBG(2, "%s: TX memory allocation deferred.\n", dev->name);
  595. SMC_ENABLE_INT(lp, IM_ALLOC_INT);
  596. } else {
  597. /*
  598. * Allocation succeeded: push packet to the chip's own memory
  599. * immediately.
  600. */
  601. smc_hardware_send_pkt((unsigned long)dev);
  602. }
  603. return 0;
  604. }
  605. /*
  606. * This handles a TX interrupt, which is only called when:
  607. * - a TX error occurred, or
  608. * - CTL_AUTO_RELEASE is not set and TX of a packet completed.
  609. */
  610. static void smc_tx(struct net_device *dev)
  611. {
  612. struct smc_local *lp = netdev_priv(dev);
  613. void __iomem *ioaddr = lp->base;
  614. unsigned int saved_packet, packet_no, tx_status, pkt_len;
  615. DBG(3, "%s: %s\n", dev->name, __func__);
  616. /* If the TX FIFO is empty then nothing to do */
  617. packet_no = SMC_GET_TXFIFO(lp);
  618. if (unlikely(packet_no & TXFIFO_TEMPTY)) {
  619. PRINTK("%s: smc_tx with nothing on FIFO.\n", dev->name);
  620. return;
  621. }
  622. /* select packet to read from */
  623. saved_packet = SMC_GET_PN(lp);
  624. SMC_SET_PN(lp, packet_no);
  625. /* read the first word (status word) from this packet */
  626. SMC_SET_PTR(lp, PTR_AUTOINC | PTR_READ);
  627. SMC_GET_PKT_HDR(lp, tx_status, pkt_len);
  628. DBG(2, "%s: TX STATUS 0x%04x PNR 0x%02x\n",
  629. dev->name, tx_status, packet_no);
  630. if (!(tx_status & ES_TX_SUC))
  631. dev->stats.tx_errors++;
  632. if (tx_status & ES_LOSTCARR)
  633. dev->stats.tx_carrier_errors++;
  634. if (tx_status & (ES_LATCOL | ES_16COL)) {
  635. PRINTK("%s: %s occurred on last xmit\n", dev->name,
  636. (tx_status & ES_LATCOL) ?
  637. "late collision" : "too many collisions");
  638. dev->stats.tx_window_errors++;
  639. if (!(dev->stats.tx_window_errors & 63) && net_ratelimit()) {
  640. printk(KERN_INFO "%s: unexpectedly large number of "
  641. "bad collisions. Please check duplex "
  642. "setting.\n", dev->name);
  643. }
  644. }
  645. /* kill the packet */
  646. SMC_WAIT_MMU_BUSY(lp);
  647. SMC_SET_MMU_CMD(lp, MC_FREEPKT);
  648. /* Don't restore Packet Number Reg until busy bit is cleared */
  649. SMC_WAIT_MMU_BUSY(lp);
  650. SMC_SET_PN(lp, saved_packet);
  651. /* re-enable transmit */
  652. SMC_SELECT_BANK(lp, 0);
  653. SMC_SET_TCR(lp, lp->tcr_cur_mode);
  654. SMC_SELECT_BANK(lp, 2);
  655. }
  656. /*---PHY CONTROL AND CONFIGURATION-----------------------------------------*/
  657. static void smc_mii_out(struct net_device *dev, unsigned int val, int bits)
  658. {
  659. struct smc_local *lp = netdev_priv(dev);
  660. void __iomem *ioaddr = lp->base;
  661. unsigned int mii_reg, mask;
  662. mii_reg = SMC_GET_MII(lp) & ~(MII_MCLK | MII_MDOE | MII_MDO);
  663. mii_reg |= MII_MDOE;
  664. for (mask = 1 << (bits - 1); mask; mask >>= 1) {
  665. if (val & mask)
  666. mii_reg |= MII_MDO;
  667. else
  668. mii_reg &= ~MII_MDO;
  669. SMC_SET_MII(lp, mii_reg);
  670. udelay(MII_DELAY);
  671. SMC_SET_MII(lp, mii_reg | MII_MCLK);
  672. udelay(MII_DELAY);
  673. }
  674. }
  675. static unsigned int smc_mii_in(struct net_device *dev, int bits)
  676. {
  677. struct smc_local *lp = netdev_priv(dev);
  678. void __iomem *ioaddr = lp->base;
  679. unsigned int mii_reg, mask, val;
  680. mii_reg = SMC_GET_MII(lp) & ~(MII_MCLK | MII_MDOE | MII_MDO);
  681. SMC_SET_MII(lp, mii_reg);
  682. for (mask = 1 << (bits - 1), val = 0; mask; mask >>= 1) {
  683. if (SMC_GET_MII(lp) & MII_MDI)
  684. val |= mask;
  685. SMC_SET_MII(lp, mii_reg);
  686. udelay(MII_DELAY);
  687. SMC_SET_MII(lp, mii_reg | MII_MCLK);
  688. udelay(MII_DELAY);
  689. }
  690. return val;
  691. }
  692. /*
  693. * Reads a register from the MII Management serial interface
  694. */
  695. static int smc_phy_read(struct net_device *dev, int phyaddr, int phyreg)
  696. {
  697. struct smc_local *lp = netdev_priv(dev);
  698. void __iomem *ioaddr = lp->base;
  699. unsigned int phydata;
  700. SMC_SELECT_BANK(lp, 3);
  701. /* Idle - 32 ones */
  702. smc_mii_out(dev, 0xffffffff, 32);
  703. /* Start code (01) + read (10) + phyaddr + phyreg */
  704. smc_mii_out(dev, 6 << 10 | phyaddr << 5 | phyreg, 14);
  705. /* Turnaround (2bits) + phydata */
  706. phydata = smc_mii_in(dev, 18);
  707. /* Return to idle state */
  708. SMC_SET_MII(lp, SMC_GET_MII(lp) & ~(MII_MCLK|MII_MDOE|MII_MDO));
  709. DBG(3, "%s: phyaddr=0x%x, phyreg=0x%x, phydata=0x%x\n",
  710. __func__, phyaddr, phyreg, phydata);
  711. SMC_SELECT_BANK(lp, 2);
  712. return phydata;
  713. }
  714. /*
  715. * Writes a register to the MII Management serial interface
  716. */
  717. static void smc_phy_write(struct net_device *dev, int phyaddr, int phyreg,
  718. int phydata)
  719. {
  720. struct smc_local *lp = netdev_priv(dev);
  721. void __iomem *ioaddr = lp->base;
  722. SMC_SELECT_BANK(lp, 3);
  723. /* Idle - 32 ones */
  724. smc_mii_out(dev, 0xffffffff, 32);
  725. /* Start code (01) + write (01) + phyaddr + phyreg + turnaround + phydata */
  726. smc_mii_out(dev, 5 << 28 | phyaddr << 23 | phyreg << 18 | 2 << 16 | phydata, 32);
  727. /* Return to idle state */
  728. SMC_SET_MII(lp, SMC_GET_MII(lp) & ~(MII_MCLK|MII_MDOE|MII_MDO));
  729. DBG(3, "%s: phyaddr=0x%x, phyreg=0x%x, phydata=0x%x\n",
  730. __func__, phyaddr, phyreg, phydata);
  731. SMC_SELECT_BANK(lp, 2);
  732. }
  733. /*
  734. * Finds and reports the PHY address
  735. */
  736. static void smc_phy_detect(struct net_device *dev)
  737. {
  738. struct smc_local *lp = netdev_priv(dev);
  739. int phyaddr;
  740. DBG(2, "%s: %s\n", dev->name, __func__);
  741. lp->phy_type = 0;
  742. /*
  743. * Scan all 32 PHY addresses if necessary, starting at
  744. * PHY#1 to PHY#31, and then PHY#0 last.
  745. */
  746. for (phyaddr = 1; phyaddr < 33; ++phyaddr) {
  747. unsigned int id1, id2;
  748. /* Read the PHY identifiers */
  749. id1 = smc_phy_read(dev, phyaddr & 31, MII_PHYSID1);
  750. id2 = smc_phy_read(dev, phyaddr & 31, MII_PHYSID2);
  751. DBG(3, "%s: phy_id1=0x%x, phy_id2=0x%x\n",
  752. dev->name, id1, id2);
  753. /* Make sure it is a valid identifier */
  754. if (id1 != 0x0000 && id1 != 0xffff && id1 != 0x8000 &&
  755. id2 != 0x0000 && id2 != 0xffff && id2 != 0x8000) {
  756. /* Save the PHY's address */
  757. lp->mii.phy_id = phyaddr & 31;
  758. lp->phy_type = id1 << 16 | id2;
  759. break;
  760. }
  761. }
  762. }
  763. /*
  764. * Sets the PHY to a configuration as determined by the user
  765. */
  766. static int smc_phy_fixed(struct net_device *dev)
  767. {
  768. struct smc_local *lp = netdev_priv(dev);
  769. void __iomem *ioaddr = lp->base;
  770. int phyaddr = lp->mii.phy_id;
  771. int bmcr, cfg1;
  772. DBG(3, "%s: %s\n", dev->name, __func__);
  773. /* Enter Link Disable state */
  774. cfg1 = smc_phy_read(dev, phyaddr, PHY_CFG1_REG);
  775. cfg1 |= PHY_CFG1_LNKDIS;
  776. smc_phy_write(dev, phyaddr, PHY_CFG1_REG, cfg1);
  777. /*
  778. * Set our fixed capabilities
  779. * Disable auto-negotiation
  780. */
  781. bmcr = 0;
  782. if (lp->ctl_rfduplx)
  783. bmcr |= BMCR_FULLDPLX;
  784. if (lp->ctl_rspeed == 100)
  785. bmcr |= BMCR_SPEED100;
  786. /* Write our capabilities to the phy control register */
  787. smc_phy_write(dev, phyaddr, MII_BMCR, bmcr);
  788. /* Re-Configure the Receive/Phy Control register */
  789. SMC_SELECT_BANK(lp, 0);
  790. SMC_SET_RPC(lp, lp->rpc_cur_mode);
  791. SMC_SELECT_BANK(lp, 2);
  792. return 1;
  793. }
  794. /*
  795. * smc_phy_reset - reset the phy
  796. * @dev: net device
  797. * @phy: phy address
  798. *
  799. * Issue a software reset for the specified PHY and
  800. * wait up to 100ms for the reset to complete. We should
  801. * not access the PHY for 50ms after issuing the reset.
  802. *
  803. * The time to wait appears to be dependent on the PHY.
  804. *
  805. * Must be called with lp->lock locked.
  806. */
  807. static int smc_phy_reset(struct net_device *dev, int phy)
  808. {
  809. struct smc_local *lp = netdev_priv(dev);
  810. unsigned int bmcr;
  811. int timeout;
  812. smc_phy_write(dev, phy, MII_BMCR, BMCR_RESET);
  813. for (timeout = 2; timeout; timeout--) {
  814. spin_unlock_irq(&lp->lock);
  815. msleep(50);
  816. spin_lock_irq(&lp->lock);
  817. bmcr = smc_phy_read(dev, phy, MII_BMCR);
  818. if (!(bmcr & BMCR_RESET))
  819. break;
  820. }
  821. return bmcr & BMCR_RESET;
  822. }
  823. /*
  824. * smc_phy_powerdown - powerdown phy
  825. * @dev: net device
  826. *
  827. * Power down the specified PHY
  828. */
  829. static void smc_phy_powerdown(struct net_device *dev)
  830. {
  831. struct smc_local *lp = netdev_priv(dev);
  832. unsigned int bmcr;
  833. int phy = lp->mii.phy_id;
  834. if (lp->phy_type == 0)
  835. return;
  836. /* We need to ensure that no calls to smc_phy_configure are
  837. pending.
  838. */
  839. cancel_work_sync(&lp->phy_configure);
  840. bmcr = smc_phy_read(dev, phy, MII_BMCR);
  841. smc_phy_write(dev, phy, MII_BMCR, bmcr | BMCR_PDOWN);
  842. }
  843. /*
  844. * smc_phy_check_media - check the media status and adjust TCR
  845. * @dev: net device
  846. * @init: set true for initialisation
  847. *
  848. * Select duplex mode depending on negotiation state. This
  849. * also updates our carrier state.
  850. */
  851. static void smc_phy_check_media(struct net_device *dev, int init)
  852. {
  853. struct smc_local *lp = netdev_priv(dev);
  854. void __iomem *ioaddr = lp->base;
  855. if (mii_check_media(&lp->mii, netif_msg_link(lp), init)) {
  856. /* duplex state has changed */
  857. if (lp->mii.full_duplex) {
  858. lp->tcr_cur_mode |= TCR_SWFDUP;
  859. } else {
  860. lp->tcr_cur_mode &= ~TCR_SWFDUP;
  861. }
  862. SMC_SELECT_BANK(lp, 0);
  863. SMC_SET_TCR(lp, lp->tcr_cur_mode);
  864. }
  865. }
  866. /*
  867. * Configures the specified PHY through the MII management interface
  868. * using Autonegotiation.
  869. * Calls smc_phy_fixed() if the user has requested a certain config.
  870. * If RPC ANEG bit is set, the media selection is dependent purely on
  871. * the selection by the MII (either in the MII BMCR reg or the result
  872. * of autonegotiation.) If the RPC ANEG bit is cleared, the selection
  873. * is controlled by the RPC SPEED and RPC DPLX bits.
  874. */
  875. static void smc_phy_configure(struct work_struct *work)
  876. {
  877. struct smc_local *lp =
  878. container_of(work, struct smc_local, phy_configure);
  879. struct net_device *dev = lp->dev;
  880. void __iomem *ioaddr = lp->base;
  881. int phyaddr = lp->mii.phy_id;
  882. int my_phy_caps; /* My PHY capabilities */
  883. int my_ad_caps; /* My Advertised capabilities */
  884. int status;
  885. DBG(3, "%s:smc_program_phy()\n", dev->name);
  886. spin_lock_irq(&lp->lock);
  887. /*
  888. * We should not be called if phy_type is zero.
  889. */
  890. if (lp->phy_type == 0)
  891. goto smc_phy_configure_exit;
  892. if (smc_phy_reset(dev, phyaddr)) {
  893. printk("%s: PHY reset timed out\n", dev->name);
  894. goto smc_phy_configure_exit;
  895. }
  896. /*
  897. * Enable PHY Interrupts (for register 18)
  898. * Interrupts listed here are disabled
  899. */
  900. smc_phy_write(dev, phyaddr, PHY_MASK_REG,
  901. PHY_INT_LOSSSYNC | PHY_INT_CWRD | PHY_INT_SSD |
  902. PHY_INT_ESD | PHY_INT_RPOL | PHY_INT_JAB |
  903. PHY_INT_SPDDET | PHY_INT_DPLXDET);
  904. /* Configure the Receive/Phy Control register */
  905. SMC_SELECT_BANK(lp, 0);
  906. SMC_SET_RPC(lp, lp->rpc_cur_mode);
  907. /* If the user requested no auto neg, then go set his request */
  908. if (lp->mii.force_media) {
  909. smc_phy_fixed(dev);
  910. goto smc_phy_configure_exit;
  911. }
  912. /* Copy our capabilities from MII_BMSR to MII_ADVERTISE */
  913. my_phy_caps = smc_phy_read(dev, phyaddr, MII_BMSR);
  914. if (!(my_phy_caps & BMSR_ANEGCAPABLE)) {
  915. printk(KERN_INFO "Auto negotiation NOT supported\n");
  916. smc_phy_fixed(dev);
  917. goto smc_phy_configure_exit;
  918. }
  919. my_ad_caps = ADVERTISE_CSMA; /* I am CSMA capable */
  920. if (my_phy_caps & BMSR_100BASE4)
  921. my_ad_caps |= ADVERTISE_100BASE4;
  922. if (my_phy_caps & BMSR_100FULL)
  923. my_ad_caps |= ADVERTISE_100FULL;
  924. if (my_phy_caps & BMSR_100HALF)
  925. my_ad_caps |= ADVERTISE_100HALF;
  926. if (my_phy_caps & BMSR_10FULL)
  927. my_ad_caps |= ADVERTISE_10FULL;
  928. if (my_phy_caps & BMSR_10HALF)
  929. my_ad_caps |= ADVERTISE_10HALF;
  930. /* Disable capabilities not selected by our user */
  931. if (lp->ctl_rspeed != 100)
  932. my_ad_caps &= ~(ADVERTISE_100BASE4|ADVERTISE_100FULL|ADVERTISE_100HALF);
  933. if (!lp->ctl_rfduplx)
  934. my_ad_caps &= ~(ADVERTISE_100FULL|ADVERTISE_10FULL);
  935. /* Update our Auto-Neg Advertisement Register */
  936. smc_phy_write(dev, phyaddr, MII_ADVERTISE, my_ad_caps);
  937. lp->mii.advertising = my_ad_caps;
  938. /*
  939. * Read the register back. Without this, it appears that when
  940. * auto-negotiation is restarted, sometimes it isn't ready and
  941. * the link does not come up.
  942. */
  943. status = smc_phy_read(dev, phyaddr, MII_ADVERTISE);
  944. DBG(2, "%s: phy caps=%x\n", dev->name, my_phy_caps);
  945. DBG(2, "%s: phy advertised caps=%x\n", dev->name, my_ad_caps);
  946. /* Restart auto-negotiation process in order to advertise my caps */
  947. smc_phy_write(dev, phyaddr, MII_BMCR, BMCR_ANENABLE | BMCR_ANRESTART);
  948. smc_phy_check_media(dev, 1);
  949. smc_phy_configure_exit:
  950. SMC_SELECT_BANK(lp, 2);
  951. spin_unlock_irq(&lp->lock);
  952. }
  953. /*
  954. * smc_phy_interrupt
  955. *
  956. * Purpose: Handle interrupts relating to PHY register 18. This is
  957. * called from the "hard" interrupt handler under our private spinlock.
  958. */
  959. static void smc_phy_interrupt(struct net_device *dev)
  960. {
  961. struct smc_local *lp = netdev_priv(dev);
  962. int phyaddr = lp->mii.phy_id;
  963. int phy18;
  964. DBG(2, "%s: %s\n", dev->name, __func__);
  965. if (lp->phy_type == 0)
  966. return;
  967. for(;;) {
  968. smc_phy_check_media(dev, 0);
  969. /* Read PHY Register 18, Status Output */
  970. phy18 = smc_phy_read(dev, phyaddr, PHY_INT_REG);
  971. if ((phy18 & PHY_INT_INT) == 0)
  972. break;
  973. }
  974. }
  975. /*--- END PHY CONTROL AND CONFIGURATION-------------------------------------*/
  976. static void smc_10bt_check_media(struct net_device *dev, int init)
  977. {
  978. struct smc_local *lp = netdev_priv(dev);
  979. void __iomem *ioaddr = lp->base;
  980. unsigned int old_carrier, new_carrier;
  981. old_carrier = netif_carrier_ok(dev) ? 1 : 0;
  982. SMC_SELECT_BANK(lp, 0);
  983. new_carrier = (SMC_GET_EPH_STATUS(lp) & ES_LINK_OK) ? 1 : 0;
  984. SMC_SELECT_BANK(lp, 2);
  985. if (init || (old_carrier != new_carrier)) {
  986. if (!new_carrier) {
  987. netif_carrier_off(dev);
  988. } else {
  989. netif_carrier_on(dev);
  990. }
  991. if (netif_msg_link(lp))
  992. printk(KERN_INFO "%s: link %s\n", dev->name,
  993. new_carrier ? "up" : "down");
  994. }
  995. }
  996. static void smc_eph_interrupt(struct net_device *dev)
  997. {
  998. struct smc_local *lp = netdev_priv(dev);
  999. void __iomem *ioaddr = lp->base;
  1000. unsigned int ctl;
  1001. smc_10bt_check_media(dev, 0);
  1002. SMC_SELECT_BANK(lp, 1);
  1003. ctl = SMC_GET_CTL(lp);
  1004. SMC_SET_CTL(lp, ctl & ~CTL_LE_ENABLE);
  1005. SMC_SET_CTL(lp, ctl);
  1006. SMC_SELECT_BANK(lp, 2);
  1007. }
  1008. /*
  1009. * This is the main routine of the driver, to handle the device when
  1010. * it needs some attention.
  1011. */
  1012. static irqreturn_t smc_interrupt(int irq, void *dev_id)
  1013. {
  1014. struct net_device *dev = dev_id;
  1015. struct smc_local *lp = netdev_priv(dev);
  1016. void __iomem *ioaddr = lp->base;
  1017. int status, mask, timeout, card_stats;
  1018. int saved_pointer;
  1019. DBG(3, "%s: %s\n", dev->name, __func__);
  1020. spin_lock(&lp->lock);
  1021. /* A preamble may be used when there is a potential race
  1022. * between the interruptible transmit functions and this
  1023. * ISR. */
  1024. SMC_INTERRUPT_PREAMBLE;
  1025. saved_pointer = SMC_GET_PTR(lp);
  1026. mask = SMC_GET_INT_MASK(lp);
  1027. SMC_SET_INT_MASK(lp, 0);
  1028. /* set a timeout value, so I don't stay here forever */
  1029. timeout = MAX_IRQ_LOOPS;
  1030. do {
  1031. status = SMC_GET_INT(lp);
  1032. DBG(2, "%s: INT 0x%02x MASK 0x%02x MEM 0x%04x FIFO 0x%04x\n",
  1033. dev->name, status, mask,
  1034. ({ int meminfo; SMC_SELECT_BANK(lp, 0);
  1035. meminfo = SMC_GET_MIR(lp);
  1036. SMC_SELECT_BANK(lp, 2); meminfo; }),
  1037. SMC_GET_FIFO(lp));
  1038. status &= mask;
  1039. if (!status)
  1040. break;
  1041. if (status & IM_TX_INT) {
  1042. /* do this before RX as it will free memory quickly */
  1043. DBG(3, "%s: TX int\n", dev->name);
  1044. smc_tx(dev);
  1045. SMC_ACK_INT(lp, IM_TX_INT);
  1046. if (THROTTLE_TX_PKTS)
  1047. netif_wake_queue(dev);
  1048. } else if (status & IM_RCV_INT) {
  1049. DBG(3, "%s: RX irq\n", dev->name);
  1050. smc_rcv(dev);
  1051. } else if (status & IM_ALLOC_INT) {
  1052. DBG(3, "%s: Allocation irq\n", dev->name);
  1053. tasklet_hi_schedule(&lp->tx_task);
  1054. mask &= ~IM_ALLOC_INT;
  1055. } else if (status & IM_TX_EMPTY_INT) {
  1056. DBG(3, "%s: TX empty\n", dev->name);
  1057. mask &= ~IM_TX_EMPTY_INT;
  1058. /* update stats */
  1059. SMC_SELECT_BANK(lp, 0);
  1060. card_stats = SMC_GET_COUNTER(lp);
  1061. SMC_SELECT_BANK(lp, 2);
  1062. /* single collisions */
  1063. dev->stats.collisions += card_stats & 0xF;
  1064. card_stats >>= 4;
  1065. /* multiple collisions */
  1066. dev->stats.collisions += card_stats & 0xF;
  1067. } else if (status & IM_RX_OVRN_INT) {
  1068. DBG(1, "%s: RX overrun (EPH_ST 0x%04x)\n", dev->name,
  1069. ({ int eph_st; SMC_SELECT_BANK(lp, 0);
  1070. eph_st = SMC_GET_EPH_STATUS(lp);
  1071. SMC_SELECT_BANK(lp, 2); eph_st; }));
  1072. SMC_ACK_INT(lp, IM_RX_OVRN_INT);
  1073. dev->stats.rx_errors++;
  1074. dev->stats.rx_fifo_errors++;
  1075. } else if (status & IM_EPH_INT) {
  1076. smc_eph_interrupt(dev);
  1077. } else if (status & IM_MDINT) {
  1078. SMC_ACK_INT(lp, IM_MDINT);
  1079. smc_phy_interrupt(dev);
  1080. } else if (status & IM_ERCV_INT) {
  1081. SMC_ACK_INT(lp, IM_ERCV_INT);
  1082. PRINTK("%s: UNSUPPORTED: ERCV INTERRUPT \n", dev->name);
  1083. }
  1084. } while (--timeout);
  1085. /* restore register states */
  1086. SMC_SET_PTR(lp, saved_pointer);
  1087. SMC_SET_INT_MASK(lp, mask);
  1088. spin_unlock(&lp->lock);
  1089. #ifndef CONFIG_NET_POLL_CONTROLLER
  1090. if (timeout == MAX_IRQ_LOOPS)
  1091. PRINTK("%s: spurious interrupt (mask = 0x%02x)\n",
  1092. dev->name, mask);
  1093. #endif
  1094. DBG(3, "%s: Interrupt done (%d loops)\n",
  1095. dev->name, MAX_IRQ_LOOPS - timeout);
  1096. /*
  1097. * We return IRQ_HANDLED unconditionally here even if there was
  1098. * nothing to do. There is a possibility that a packet might
  1099. * get enqueued into the chip right after TX_EMPTY_INT is raised
  1100. * but just before the CPU acknowledges the IRQ.
  1101. * Better take an unneeded IRQ in some occasions than complexifying
  1102. * the code for all cases.
  1103. */
  1104. return IRQ_HANDLED;
  1105. }
  1106. #ifdef CONFIG_NET_POLL_CONTROLLER
  1107. /*
  1108. * Polling receive - used by netconsole and other diagnostic tools
  1109. * to allow network i/o with interrupts disabled.
  1110. */
  1111. static void smc_poll_controller(struct net_device *dev)
  1112. {
  1113. disable_irq(dev->irq);
  1114. smc_interrupt(dev->irq, dev);
  1115. enable_irq(dev->irq);
  1116. }
  1117. #endif
  1118. /* Our watchdog timed out. Called by the networking layer */
  1119. static void smc_timeout(struct net_device *dev)
  1120. {
  1121. struct smc_local *lp = netdev_priv(dev);
  1122. void __iomem *ioaddr = lp->base;
  1123. int status, mask, eph_st, meminfo, fifo;
  1124. DBG(2, "%s: %s\n", dev->name, __func__);
  1125. spin_lock_irq(&lp->lock);
  1126. status = SMC_GET_INT(lp);
  1127. mask = SMC_GET_INT_MASK(lp);
  1128. fifo = SMC_GET_FIFO(lp);
  1129. SMC_SELECT_BANK(lp, 0);
  1130. eph_st = SMC_GET_EPH_STATUS(lp);
  1131. meminfo = SMC_GET_MIR(lp);
  1132. SMC_SELECT_BANK(lp, 2);
  1133. spin_unlock_irq(&lp->lock);
  1134. PRINTK( "%s: TX timeout (INT 0x%02x INTMASK 0x%02x "
  1135. "MEM 0x%04x FIFO 0x%04x EPH_ST 0x%04x)\n",
  1136. dev->name, status, mask, meminfo, fifo, eph_st );
  1137. smc_reset(dev);
  1138. smc_enable(dev);
  1139. /*
  1140. * Reconfiguring the PHY doesn't seem like a bad idea here, but
  1141. * smc_phy_configure() calls msleep() which calls schedule_timeout()
  1142. * which calls schedule(). Hence we use a work queue.
  1143. */
  1144. if (lp->phy_type != 0)
  1145. schedule_work(&lp->phy_configure);
  1146. /* We can accept TX packets again */
  1147. dev->trans_start = jiffies;
  1148. netif_wake_queue(dev);
  1149. }
  1150. /*
  1151. * This routine will, depending on the values passed to it,
  1152. * either make it accept multicast packets, go into
  1153. * promiscuous mode (for TCPDUMP and cousins) or accept
  1154. * a select set of multicast packets
  1155. */
  1156. static void smc_set_multicast_list(struct net_device *dev)
  1157. {
  1158. struct smc_local *lp = netdev_priv(dev);
  1159. void __iomem *ioaddr = lp->base;
  1160. unsigned char multicast_table[8];
  1161. int update_multicast = 0;
  1162. DBG(2, "%s: %s\n", dev->name, __func__);
  1163. if (dev->flags & IFF_PROMISC) {
  1164. DBG(2, "%s: RCR_PRMS\n", dev->name);
  1165. lp->rcr_cur_mode |= RCR_PRMS;
  1166. }
  1167. /* BUG? I never disable promiscuous mode if multicasting was turned on.
  1168. Now, I turn off promiscuous mode, but I don't do anything to multicasting
  1169. when promiscuous mode is turned on.
  1170. */
  1171. /*
  1172. * Here, I am setting this to accept all multicast packets.
  1173. * I don't need to zero the multicast table, because the flag is
  1174. * checked before the table is
  1175. */
  1176. else if (dev->flags & IFF_ALLMULTI || dev->mc_count > 16) {
  1177. DBG(2, "%s: RCR_ALMUL\n", dev->name);
  1178. lp->rcr_cur_mode |= RCR_ALMUL;
  1179. }
  1180. /*
  1181. * This sets the internal hardware table to filter out unwanted
  1182. * multicast packets before they take up memory.
  1183. *
  1184. * The SMC chip uses a hash table where the high 6 bits of the CRC of
  1185. * address are the offset into the table. If that bit is 1, then the
  1186. * multicast packet is accepted. Otherwise, it's dropped silently.
  1187. *
  1188. * To use the 6 bits as an offset into the table, the high 3 bits are
  1189. * the number of the 8 bit register, while the low 3 bits are the bit
  1190. * within that register.
  1191. */
  1192. else if (dev->mc_count) {
  1193. int i;
  1194. struct dev_mc_list *cur_addr;
  1195. /* table for flipping the order of 3 bits */
  1196. static const unsigned char invert3[] = {0, 4, 2, 6, 1, 5, 3, 7};
  1197. /* start with a table of all zeros: reject all */
  1198. memset(multicast_table, 0, sizeof(multicast_table));
  1199. cur_addr = dev->mc_list;
  1200. for (i = 0; i < dev->mc_count; i++, cur_addr = cur_addr->next) {
  1201. int position;
  1202. /* do we have a pointer here? */
  1203. if (!cur_addr)
  1204. break;
  1205. /* make sure this is a multicast address -
  1206. shouldn't this be a given if we have it here ? */
  1207. if (!(*cur_addr->dmi_addr & 1))
  1208. continue;
  1209. /* only use the low order bits */
  1210. position = crc32_le(~0, cur_addr->dmi_addr, 6) & 0x3f;
  1211. /* do some messy swapping to put the bit in the right spot */
  1212. multicast_table[invert3[position&7]] |=
  1213. (1<<invert3[(position>>3)&7]);
  1214. }
  1215. /* be sure I get rid of flags I might have set */
  1216. lp->rcr_cur_mode &= ~(RCR_PRMS | RCR_ALMUL);
  1217. /* now, the table can be loaded into the chipset */
  1218. update_multicast = 1;
  1219. } else {
  1220. DBG(2, "%s: ~(RCR_PRMS|RCR_ALMUL)\n", dev->name);
  1221. lp->rcr_cur_mode &= ~(RCR_PRMS | RCR_ALMUL);
  1222. /*
  1223. * since I'm disabling all multicast entirely, I need to
  1224. * clear the multicast list
  1225. */
  1226. memset(multicast_table, 0, sizeof(multicast_table));
  1227. update_multicast = 1;
  1228. }
  1229. spin_lock_irq(&lp->lock);
  1230. SMC_SELECT_BANK(lp, 0);
  1231. SMC_SET_RCR(lp, lp->rcr_cur_mode);
  1232. if (update_multicast) {
  1233. SMC_SELECT_BANK(lp, 3);
  1234. SMC_SET_MCAST(lp, multicast_table);
  1235. }
  1236. SMC_SELECT_BANK(lp, 2);
  1237. spin_unlock_irq(&lp->lock);
  1238. }
  1239. /*
  1240. * Open and Initialize the board
  1241. *
  1242. * Set up everything, reset the card, etc..
  1243. */
  1244. static int
  1245. smc_open(struct net_device *dev)
  1246. {
  1247. struct smc_local *lp = netdev_priv(dev);
  1248. DBG(2, "%s: %s\n", dev->name, __func__);
  1249. /*
  1250. * Check that the address is valid. If its not, refuse
  1251. * to bring the device up. The user must specify an
  1252. * address using ifconfig eth0 hw ether xx:xx:xx:xx:xx:xx
  1253. */
  1254. if (!is_valid_ether_addr(dev->dev_addr)) {
  1255. PRINTK("%s: no valid ethernet hw addr\n", __func__);
  1256. return -EINVAL;
  1257. }
  1258. /* Setup the default Register Modes */
  1259. lp->tcr_cur_mode = TCR_DEFAULT;
  1260. lp->rcr_cur_mode = RCR_DEFAULT;
  1261. lp->rpc_cur_mode = RPC_DEFAULT |
  1262. lp->cfg.leda << RPC_LSXA_SHFT |
  1263. lp->cfg.ledb << RPC_LSXB_SHFT;
  1264. /*
  1265. * If we are not using a MII interface, we need to
  1266. * monitor our own carrier signal to detect faults.
  1267. */
  1268. if (lp->phy_type == 0)
  1269. lp->tcr_cur_mode |= TCR_MON_CSN;
  1270. /* reset the hardware */
  1271. smc_reset(dev);
  1272. smc_enable(dev);
  1273. /* Configure the PHY, initialize the link state */
  1274. if (lp->phy_type != 0)
  1275. smc_phy_configure(&lp->phy_configure);
  1276. else {
  1277. spin_lock_irq(&lp->lock);
  1278. smc_10bt_check_media(dev, 1);
  1279. spin_unlock_irq(&lp->lock);
  1280. }
  1281. netif_start_queue(dev);
  1282. return 0;
  1283. }
  1284. /*
  1285. * smc_close
  1286. *
  1287. * this makes the board clean up everything that it can
  1288. * and not talk to the outside world. Caused by
  1289. * an 'ifconfig ethX down'
  1290. */
  1291. static int smc_close(struct net_device *dev)
  1292. {
  1293. struct smc_local *lp = netdev_priv(dev);
  1294. DBG(2, "%s: %s\n", dev->name, __func__);
  1295. netif_stop_queue(dev);
  1296. netif_carrier_off(dev);
  1297. /* clear everything */
  1298. smc_shutdown(dev);
  1299. tasklet_kill(&lp->tx_task);
  1300. smc_phy_powerdown(dev);
  1301. return 0;
  1302. }
  1303. /*
  1304. * Ethtool support
  1305. */
  1306. static int
  1307. smc_ethtool_getsettings(struct net_device *dev, struct ethtool_cmd *cmd)
  1308. {
  1309. struct smc_local *lp = netdev_priv(dev);
  1310. int ret;
  1311. cmd->maxtxpkt = 1;
  1312. cmd->maxrxpkt = 1;
  1313. if (lp->phy_type != 0) {
  1314. spin_lock_irq(&lp->lock);
  1315. ret = mii_ethtool_gset(&lp->mii, cmd);
  1316. spin_unlock_irq(&lp->lock);
  1317. } else {
  1318. cmd->supported = SUPPORTED_10baseT_Half |
  1319. SUPPORTED_10baseT_Full |
  1320. SUPPORTED_TP | SUPPORTED_AUI;
  1321. if (lp->ctl_rspeed == 10)
  1322. cmd->speed = SPEED_10;
  1323. else if (lp->ctl_rspeed == 100)
  1324. cmd->speed = SPEED_100;
  1325. cmd->autoneg = AUTONEG_DISABLE;
  1326. cmd->transceiver = XCVR_INTERNAL;
  1327. cmd->port = 0;
  1328. cmd->duplex = lp->tcr_cur_mode & TCR_SWFDUP ? DUPLEX_FULL : DUPLEX_HALF;
  1329. ret = 0;
  1330. }
  1331. return ret;
  1332. }
  1333. static int
  1334. smc_ethtool_setsettings(struct net_device *dev, struct ethtool_cmd *cmd)
  1335. {
  1336. struct smc_local *lp = netdev_priv(dev);
  1337. int ret;
  1338. if (lp->phy_type != 0) {
  1339. spin_lock_irq(&lp->lock);
  1340. ret = mii_ethtool_sset(&lp->mii, cmd);
  1341. spin_unlock_irq(&lp->lock);
  1342. } else {
  1343. if (cmd->autoneg != AUTONEG_DISABLE ||
  1344. cmd->speed != SPEED_10 ||
  1345. (cmd->duplex != DUPLEX_HALF && cmd->duplex != DUPLEX_FULL) ||
  1346. (cmd->port != PORT_TP && cmd->port != PORT_AUI))
  1347. return -EINVAL;
  1348. // lp->port = cmd->port;
  1349. lp->ctl_rfduplx = cmd->duplex == DUPLEX_FULL;
  1350. // if (netif_running(dev))
  1351. // smc_set_port(dev);
  1352. ret = 0;
  1353. }
  1354. return ret;
  1355. }
  1356. static void
  1357. smc_ethtool_getdrvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
  1358. {
  1359. strncpy(info->driver, CARDNAME, sizeof(info->driver));
  1360. strncpy(info->version, version, sizeof(info->version));
  1361. strncpy(info->bus_info, dev_name(dev->dev.parent), sizeof(info->bus_info));
  1362. }
  1363. static int smc_ethtool_nwayreset(struct net_device *dev)
  1364. {
  1365. struct smc_local *lp = netdev_priv(dev);
  1366. int ret = -EINVAL;
  1367. if (lp->phy_type != 0) {
  1368. spin_lock_irq(&lp->lock);
  1369. ret = mii_nway_restart(&lp->mii);
  1370. spin_unlock_irq(&lp->lock);
  1371. }
  1372. return ret;
  1373. }
  1374. static u32 smc_ethtool_getmsglevel(struct net_device *dev)
  1375. {
  1376. struct smc_local *lp = netdev_priv(dev);
  1377. return lp->msg_enable;
  1378. }
  1379. static void smc_ethtool_setmsglevel(struct net_device *dev, u32 level)
  1380. {
  1381. struct smc_local *lp = netdev_priv(dev);
  1382. lp->msg_enable = level;
  1383. }
  1384. static int smc_write_eeprom_word(struct net_device *dev, u16 addr, u16 word)
  1385. {
  1386. u16 ctl;
  1387. struct smc_local *lp = netdev_priv(dev);
  1388. void __iomem *ioaddr = lp->base;
  1389. spin_lock_irq(&lp->lock);
  1390. /* load word into GP register */
  1391. SMC_SELECT_BANK(lp, 1);
  1392. SMC_SET_GP(lp, word);
  1393. /* set the address to put the data in EEPROM */
  1394. SMC_SELECT_BANK(lp, 2);
  1395. SMC_SET_PTR(lp, addr);
  1396. /* tell it to write */
  1397. SMC_SELECT_BANK(lp, 1);
  1398. ctl = SMC_GET_CTL(lp);
  1399. SMC_SET_CTL(lp, ctl | (CTL_EEPROM_SELECT | CTL_STORE));
  1400. /* wait for it to finish */
  1401. do {
  1402. udelay(1);
  1403. } while (SMC_GET_CTL(lp) & CTL_STORE);
  1404. /* clean up */
  1405. SMC_SET_CTL(lp, ctl);
  1406. SMC_SELECT_BANK(lp, 2);
  1407. spin_unlock_irq(&lp->lock);
  1408. return 0;
  1409. }
  1410. static int smc_read_eeprom_word(struct net_device *dev, u16 addr, u16 *word)
  1411. {
  1412. u16 ctl;
  1413. struct smc_local *lp = netdev_priv(dev);
  1414. void __iomem *ioaddr = lp->base;
  1415. spin_lock_irq(&lp->lock);
  1416. /* set the EEPROM address to get the data from */
  1417. SMC_SELECT_BANK(lp, 2);
  1418. SMC_SET_PTR(lp, addr | PTR_READ);
  1419. /* tell it to load */
  1420. SMC_SELECT_BANK(lp, 1);
  1421. SMC_SET_GP(lp, 0xffff); /* init to known */
  1422. ctl = SMC_GET_CTL(lp);
  1423. SMC_SET_CTL(lp, ctl | (CTL_EEPROM_SELECT | CTL_RELOAD));
  1424. /* wait for it to finish */
  1425. do {
  1426. udelay(1);
  1427. } while (SMC_GET_CTL(lp) & CTL_RELOAD);
  1428. /* read word from GP register */
  1429. *word = SMC_GET_GP(lp);
  1430. /* clean up */
  1431. SMC_SET_CTL(lp, ctl);
  1432. SMC_SELECT_BANK(lp, 2);
  1433. spin_unlock_irq(&lp->lock);
  1434. return 0;
  1435. }
  1436. static int smc_ethtool_geteeprom_len(struct net_device *dev)
  1437. {
  1438. return 0x23 * 2;
  1439. }
  1440. static int smc_ethtool_geteeprom(struct net_device *dev,
  1441. struct ethtool_eeprom *eeprom, u8 *data)
  1442. {
  1443. int i;
  1444. int imax;
  1445. DBG(1, "Reading %d bytes at %d(0x%x)\n",
  1446. eeprom->len, eeprom->offset, eeprom->offset);
  1447. imax = smc_ethtool_geteeprom_len(dev);
  1448. for (i = 0; i < eeprom->len; i += 2) {
  1449. int ret;
  1450. u16 wbuf;
  1451. int offset = i + eeprom->offset;
  1452. if (offset > imax)
  1453. break;
  1454. ret = smc_read_eeprom_word(dev, offset >> 1, &wbuf);
  1455. if (ret != 0)
  1456. return ret;
  1457. DBG(2, "Read 0x%x from 0x%x\n", wbuf, offset >> 1);
  1458. data[i] = (wbuf >> 8) & 0xff;
  1459. data[i+1] = wbuf & 0xff;
  1460. }
  1461. return 0;
  1462. }
  1463. static int smc_ethtool_seteeprom(struct net_device *dev,
  1464. struct ethtool_eeprom *eeprom, u8 *data)
  1465. {
  1466. int i;
  1467. int imax;
  1468. DBG(1, "Writing %d bytes to %d(0x%x)\n",
  1469. eeprom->len, eeprom->offset, eeprom->offset);
  1470. imax = smc_ethtool_geteeprom_len(dev);
  1471. for (i = 0; i < eeprom->len; i += 2) {
  1472. int ret;
  1473. u16 wbuf;
  1474. int offset = i + eeprom->offset;
  1475. if (offset > imax)
  1476. break;
  1477. wbuf = (data[i] << 8) | data[i + 1];
  1478. DBG(2, "Writing 0x%x to 0x%x\n", wbuf, offset >> 1);
  1479. ret = smc_write_eeprom_word(dev, offset >> 1, wbuf);
  1480. if (ret != 0)
  1481. return ret;
  1482. }
  1483. return 0;
  1484. }
  1485. static const struct ethtool_ops smc_ethtool_ops = {
  1486. .get_settings = smc_ethtool_getsettings,
  1487. .set_settings = smc_ethtool_setsettings,
  1488. .get_drvinfo = smc_ethtool_getdrvinfo,
  1489. .get_msglevel = smc_ethtool_getmsglevel,
  1490. .set_msglevel = smc_ethtool_setmsglevel,
  1491. .nway_reset = smc_ethtool_nwayreset,
  1492. .get_link = ethtool_op_get_link,
  1493. .get_eeprom_len = smc_ethtool_geteeprom_len,
  1494. .get_eeprom = smc_ethtool_geteeprom,
  1495. .set_eeprom = smc_ethtool_seteeprom,
  1496. };
  1497. static const struct net_device_ops smc_netdev_ops = {
  1498. .ndo_open = smc_open,
  1499. .ndo_stop = smc_close,
  1500. .ndo_start_xmit = smc_hard_start_xmit,
  1501. .ndo_tx_timeout = smc_timeout,
  1502. .ndo_set_multicast_list = smc_set_multicast_list,
  1503. .ndo_change_mtu = eth_change_mtu,
  1504. .ndo_validate_addr = eth_validate_addr,
  1505. .ndo_set_mac_address = eth_mac_addr,
  1506. #ifdef CONFIG_NET_POLL_CONTROLLER
  1507. .ndo_poll_controller = smc_poll_controller,
  1508. #endif
  1509. };
  1510. /*
  1511. * smc_findirq
  1512. *
  1513. * This routine has a simple purpose -- make the SMC chip generate an
  1514. * interrupt, so an auto-detect routine can detect it, and find the IRQ,
  1515. */
  1516. /*
  1517. * does this still work?
  1518. *
  1519. * I just deleted auto_irq.c, since it was never built...
  1520. * --jgarzik
  1521. */
  1522. static int __devinit smc_findirq(struct smc_local *lp)
  1523. {
  1524. void __iomem *ioaddr = lp->base;
  1525. int timeout = 20;
  1526. unsigned long cookie;
  1527. DBG(2, "%s: %s\n", CARDNAME, __func__);
  1528. cookie = probe_irq_on();
  1529. /*
  1530. * What I try to do here is trigger an ALLOC_INT. This is done
  1531. * by allocating a small chunk of memory, which will give an interrupt
  1532. * when done.
  1533. */
  1534. /* enable ALLOCation interrupts ONLY */
  1535. SMC_SELECT_BANK(lp, 2);
  1536. SMC_SET_INT_MASK(lp, IM_ALLOC_INT);
  1537. /*
  1538. * Allocate 512 bytes of memory. Note that the chip was just
  1539. * reset so all the memory is available
  1540. */
  1541. SMC_SET_MMU_CMD(lp, MC_ALLOC | 1);
  1542. /*
  1543. * Wait until positive that the interrupt has been generated
  1544. */
  1545. do {
  1546. int int_status;
  1547. udelay(10);
  1548. int_status = SMC_GET_INT(lp);
  1549. if (int_status & IM_ALLOC_INT)
  1550. break; /* got the interrupt */
  1551. } while (--timeout);
  1552. /*
  1553. * there is really nothing that I can do here if timeout fails,
  1554. * as autoirq_report will return a 0 anyway, which is what I
  1555. * want in this case. Plus, the clean up is needed in both
  1556. * cases.
  1557. */
  1558. /* and disable all interrupts again */
  1559. SMC_SET_INT_MASK(lp, 0);
  1560. /* and return what I found */
  1561. return probe_irq_off(cookie);
  1562. }
  1563. /*
  1564. * Function: smc_probe(unsigned long ioaddr)
  1565. *
  1566. * Purpose:
  1567. * Tests to see if a given ioaddr points to an SMC91x chip.
  1568. * Returns a 0 on success
  1569. *
  1570. * Algorithm:
  1571. * (1) see if the high byte of BANK_SELECT is 0x33
  1572. * (2) compare the ioaddr with the base register's address
  1573. * (3) see if I recognize the chip ID in the appropriate register
  1574. *
  1575. * Here I do typical initialization tasks.
  1576. *
  1577. * o Initialize the structure if needed
  1578. * o print out my vanity message if not done so already
  1579. * o print out what type of hardware is detected
  1580. * o print out the ethernet address
  1581. * o find the IRQ
  1582. * o set up my private data
  1583. * o configure the dev structure with my subroutines
  1584. * o actually GRAB the irq.
  1585. * o GRAB the region
  1586. */
  1587. static int __devinit smc_probe(struct net_device *dev, void __iomem *ioaddr,
  1588. unsigned long irq_flags)
  1589. {
  1590. struct smc_local *lp = netdev_priv(dev);
  1591. static int version_printed = 0;
  1592. int retval;
  1593. unsigned int val, revision_register;
  1594. const char *version_string;
  1595. DBG(2, "%s: %s\n", CARDNAME, __func__);
  1596. /* First, see if the high byte is 0x33 */
  1597. val = SMC_CURRENT_BANK(lp);
  1598. DBG(2, "%s: bank signature probe returned 0x%04x\n", CARDNAME, val);
  1599. if ((val & 0xFF00) != 0x3300) {
  1600. if ((val & 0xFF) == 0x33) {
  1601. printk(KERN_WARNING
  1602. "%s: Detected possible byte-swapped interface"
  1603. " at IOADDR %p\n", CARDNAME, ioaddr);
  1604. }
  1605. retval = -ENODEV;
  1606. goto err_out;
  1607. }
  1608. /*
  1609. * The above MIGHT indicate a device, but I need to write to
  1610. * further test this.
  1611. */
  1612. SMC_SELECT_BANK(lp, 0);
  1613. val = SMC_CURRENT_BANK(lp);
  1614. if ((val & 0xFF00) != 0x3300) {
  1615. retval = -ENODEV;
  1616. goto err_out;
  1617. }
  1618. /*
  1619. * well, we've already written once, so hopefully another
  1620. * time won't hurt. This time, I need to switch the bank
  1621. * register to bank 1, so I can access the base address
  1622. * register
  1623. */
  1624. SMC_SELECT_BANK(lp, 1);
  1625. val = SMC_GET_BASE(lp);
  1626. val = ((val & 0x1F00) >> 3) << SMC_IO_SHIFT;
  1627. if (((unsigned int)ioaddr & (0x3e0 << SMC_IO_SHIFT)) != val) {
  1628. printk("%s: IOADDR %p doesn't match configuration (%x).\n",
  1629. CARDNAME, ioaddr, val);
  1630. }
  1631. /*
  1632. * check if the revision register is something that I
  1633. * recognize. These might need to be added to later,
  1634. * as future revisions could be added.
  1635. */
  1636. SMC_SELECT_BANK(lp, 3);
  1637. revision_register = SMC_GET_REV(lp);
  1638. DBG(2, "%s: revision = 0x%04x\n", CARDNAME, revision_register);
  1639. version_string = chip_ids[ (revision_register >> 4) & 0xF];
  1640. if (!version_string || (revision_register & 0xff00) != 0x3300) {
  1641. /* I don't recognize this chip, so... */
  1642. printk("%s: IO %p: Unrecognized revision register 0x%04x"
  1643. ", Contact author.\n", CARDNAME,
  1644. ioaddr, revision_register);
  1645. retval = -ENODEV;
  1646. goto err_out;
  1647. }
  1648. /* At this point I'll assume that the chip is an SMC91x. */
  1649. if (version_printed++ == 0)
  1650. printk("%s", version);
  1651. /* fill in some of the fields */
  1652. dev->base_addr = (unsigned long)ioaddr;
  1653. lp->base = ioaddr;
  1654. lp->version = revision_register & 0xff;
  1655. spin_lock_init(&lp->lock);
  1656. /* Get the MAC address */
  1657. SMC_SELECT_BANK(lp, 1);
  1658. SMC_GET_MAC_ADDR(lp, dev->dev_addr);
  1659. /* now, reset the chip, and put it into a known state */
  1660. smc_reset(dev);
  1661. /*
  1662. * If dev->irq is 0, then the device has to be banged on to see
  1663. * what the IRQ is.
  1664. *
  1665. * This banging doesn't always detect the IRQ, for unknown reasons.
  1666. * a workaround is to reset the chip and try again.
  1667. *
  1668. * Interestingly, the DOS packet driver *SETS* the IRQ on the card to
  1669. * be what is requested on the command line. I don't do that, mostly
  1670. * because the card that I have uses a non-standard method of accessing
  1671. * the IRQs, and because this _should_ work in most configurations.
  1672. *
  1673. * Specifying an IRQ is done with the assumption that the user knows
  1674. * what (s)he is doing. No checking is done!!!!
  1675. */
  1676. if (dev->irq < 1) {
  1677. int trials;
  1678. trials = 3;
  1679. while (trials--) {
  1680. dev->irq = smc_findirq(lp);
  1681. if (dev->irq)
  1682. break;
  1683. /* kick the card and try again */
  1684. smc_reset(dev);
  1685. }
  1686. }
  1687. if (dev->irq == 0) {
  1688. printk("%s: Couldn't autodetect your IRQ. Use irq=xx.\n",
  1689. dev->name);
  1690. retval = -ENODEV;
  1691. goto err_out;
  1692. }
  1693. dev->irq = irq_canonicalize(dev->irq);
  1694. /* Fill in the fields of the device structure with ethernet values. */
  1695. ether_setup(dev);
  1696. dev->watchdog_timeo = msecs_to_jiffies(watchdog);
  1697. dev->netdev_ops = &smc_netdev_ops;
  1698. dev->ethtool_ops = &smc_ethtool_ops;
  1699. tasklet_init(&lp->tx_task, smc_hardware_send_pkt, (unsigned long)dev);
  1700. INIT_WORK(&lp->phy_configure, smc_phy_configure);
  1701. lp->dev = dev;
  1702. lp->mii.phy_id_mask = 0x1f;
  1703. lp->mii.reg_num_mask = 0x1f;
  1704. lp->mii.force_media = 0;
  1705. lp->mii.full_duplex = 0;
  1706. lp->mii.dev = dev;
  1707. lp->mii.mdio_read = smc_phy_read;
  1708. lp->mii.mdio_write = smc_phy_write;
  1709. /*
  1710. * Locate the phy, if any.
  1711. */
  1712. if (lp->version >= (CHIP_91100 << 4))
  1713. smc_phy_detect(dev);
  1714. /* then shut everything down to save power */
  1715. smc_shutdown(dev);
  1716. smc_phy_powerdown(dev);
  1717. /* Set default parameters */
  1718. lp->msg_enable = NETIF_MSG_LINK;
  1719. lp->ctl_rfduplx = 0;
  1720. lp->ctl_rspeed = 10;
  1721. if (lp->version >= (CHIP_91100 << 4)) {
  1722. lp->ctl_rfduplx = 1;
  1723. lp->ctl_rspeed = 100;
  1724. }
  1725. /* Grab the IRQ */
  1726. retval = request_irq(dev->irq, &smc_interrupt, irq_flags, dev->name, dev);
  1727. if (retval)
  1728. goto err_out;
  1729. #ifdef CONFIG_ARCH_PXA
  1730. # ifdef SMC_USE_PXA_DMA
  1731. lp->cfg.flags |= SMC91X_USE_DMA;
  1732. # endif
  1733. if (lp->cfg.flags & SMC91X_USE_DMA) {
  1734. int dma = pxa_request_dma(dev->name, DMA_PRIO_LOW,
  1735. smc_pxa_dma_irq, NULL);
  1736. if (dma >= 0)
  1737. dev->dma = dma;
  1738. }
  1739. #endif
  1740. retval = register_netdev(dev);
  1741. if (retval == 0) {
  1742. /* now, print out the card info, in a short format.. */
  1743. printk("%s: %s (rev %d) at %p IRQ %d",
  1744. dev->name, version_string, revision_register & 0x0f,
  1745. lp->base, dev->irq);
  1746. if (dev->dma != (unsigned char)-1)
  1747. printk(" DMA %d", dev->dma);
  1748. printk("%s%s\n",
  1749. lp->cfg.flags & SMC91X_NOWAIT ? " [nowait]" : "",
  1750. THROTTLE_TX_PKTS ? " [throttle_tx]" : "");
  1751. if (!is_valid_ether_addr(dev->dev_addr)) {
  1752. printk("%s: Invalid ethernet MAC address. Please "
  1753. "set using ifconfig\n", dev->name);
  1754. } else {
  1755. /* Print the Ethernet address */
  1756. printk("%s: Ethernet addr: %pM\n",
  1757. dev->name, dev->dev_addr);
  1758. }
  1759. if (lp->phy_type == 0) {
  1760. PRINTK("%s: No PHY found\n", dev->name);
  1761. } else if ((lp->phy_type & 0xfffffff0) == 0x0016f840) {
  1762. PRINTK("%s: PHY LAN83C183 (LAN91C111 Internal)\n", dev->name);
  1763. } else if ((lp->phy_type & 0xfffffff0) == 0x02821c50) {
  1764. PRINTK("%s: PHY LAN83C180\n", dev->name);
  1765. }
  1766. }
  1767. err_out:
  1768. #ifdef CONFIG_ARCH_PXA
  1769. if (retval && dev->dma != (unsigned char)-1)
  1770. pxa_free_dma(dev->dma);
  1771. #endif
  1772. return retval;
  1773. }
  1774. static int smc_enable_device(struct platform_device *pdev)
  1775. {
  1776. struct net_device *ndev = platform_get_drvdata(pdev);
  1777. struct smc_local *lp = netdev_priv(ndev);
  1778. unsigned long flags;
  1779. unsigned char ecor, ecsr;
  1780. void __iomem *addr;
  1781. struct resource * res;
  1782. res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "smc91x-attrib");
  1783. if (!res)
  1784. return 0;
  1785. /*
  1786. * Map the attribute space. This is overkill, but clean.
  1787. */
  1788. addr = ioremap(res->start, ATTRIB_SIZE);
  1789. if (!addr)
  1790. return -ENOMEM;
  1791. /*
  1792. * Reset the device. We must disable IRQs around this
  1793. * since a reset causes the IRQ line become active.
  1794. */
  1795. local_irq_save(flags);
  1796. ecor = readb(addr + (ECOR << SMC_IO_SHIFT)) & ~ECOR_RESET;
  1797. writeb(ecor | ECOR_RESET, addr + (ECOR << SMC_IO_SHIFT));
  1798. readb(addr + (ECOR << SMC_IO_SHIFT));
  1799. /*
  1800. * Wait 100us for the chip to reset.
  1801. */
  1802. udelay(100);
  1803. /*
  1804. * The device will ignore all writes to the enable bit while
  1805. * reset is asserted, even if the reset bit is cleared in the
  1806. * same write. Must clear reset first, then enable the device.
  1807. */
  1808. writeb(ecor, addr + (ECOR << SMC_IO_SHIFT));
  1809. writeb(ecor | ECOR_ENABLE, addr + (ECOR << SMC_IO_SHIFT));
  1810. /*
  1811. * Set the appropriate byte/word mode.
  1812. */
  1813. ecsr = readb(addr + (ECSR << SMC_IO_SHIFT)) & ~ECSR_IOIS8;
  1814. if (!SMC_16BIT(lp))
  1815. ecsr |= ECSR_IOIS8;
  1816. writeb(ecsr, addr + (ECSR << SMC_IO_SHIFT));
  1817. local_irq_restore(flags);
  1818. iounmap(addr);
  1819. /*
  1820. * Wait for the chip to wake up. We could poll the control
  1821. * register in the main register space, but that isn't mapped
  1822. * yet. We know this is going to take 750us.
  1823. */
  1824. msleep(1);
  1825. return 0;
  1826. }
  1827. static int smc_request_attrib(struct platform_device *pdev,
  1828. struct net_device *ndev)
  1829. {
  1830. struct resource * res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "smc91x-attrib");
  1831. struct smc_local *lp __maybe_unused = netdev_priv(ndev);
  1832. if (!res)
  1833. return 0;
  1834. if (!request_mem_region(res->start, ATTRIB_SIZE, CARDNAME))
  1835. return -EBUSY;
  1836. return 0;
  1837. }
  1838. static void smc_release_attrib(struct platform_device *pdev,
  1839. struct net_device *ndev)
  1840. {
  1841. struct resource * res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "smc91x-attrib");
  1842. struct smc_local *lp __maybe_unused = netdev_priv(ndev);
  1843. if (res)
  1844. release_mem_region(res->start, ATTRIB_SIZE);
  1845. }
  1846. static inline void smc_request_datacs(struct platform_device *pdev, struct net_device *ndev)
  1847. {
  1848. if (SMC_CAN_USE_DATACS) {
  1849. struct resource * res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "smc91x-data32");
  1850. struct smc_local *lp = netdev_priv(ndev);
  1851. if (!res)
  1852. return;
  1853. if(!request_mem_region(res->start, SMC_DATA_EXTENT, CARDNAME)) {
  1854. printk(KERN_INFO "%s: failed to request datacs memory region.\n", CARDNAME);
  1855. return;
  1856. }
  1857. lp->datacs = ioremap(res->start, SMC_DATA_EXTENT);
  1858. }
  1859. }
  1860. static void smc_release_datacs(struct platform_device *pdev, struct net_device *ndev)
  1861. {
  1862. if (SMC_CAN_USE_DATACS) {
  1863. struct smc_local *lp = netdev_priv(ndev);
  1864. struct resource * res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "smc91x-data32");
  1865. if (lp->datacs)
  1866. iounmap(lp->datacs);
  1867. lp->datacs = NULL;
  1868. if (res)
  1869. release_mem_region(res->start, SMC_DATA_EXTENT);
  1870. }
  1871. }
  1872. /*
  1873. * smc_init(void)
  1874. * Input parameters:
  1875. * dev->base_addr == 0, try to find all possible locations
  1876. * dev->base_addr > 0x1ff, this is the address to check
  1877. * dev->base_addr == <anything else>, return failure code
  1878. *
  1879. * Output:
  1880. * 0 --> there is a device
  1881. * anything else, error
  1882. */
  1883. static int __devinit smc_drv_probe(struct platform_device *pdev)
  1884. {
  1885. struct smc91x_platdata *pd = pdev->dev.platform_data;
  1886. struct smc_local *lp;
  1887. struct net_device *ndev;
  1888. struct resource *res, *ires;
  1889. unsigned int __iomem *addr;
  1890. unsigned long irq_flags = SMC_IRQ_FLAGS;
  1891. int ret;
  1892. ndev = alloc_etherdev(sizeof(struct smc_local));
  1893. if (!ndev) {
  1894. printk("%s: could not allocate device.\n", CARDNAME);
  1895. ret = -ENOMEM;
  1896. goto out;
  1897. }
  1898. SET_NETDEV_DEV(ndev, &pdev->dev);
  1899. /* get configuration from platform data, only allow use of
  1900. * bus width if both SMC_CAN_USE_xxx and SMC91X_USE_xxx are set.
  1901. */
  1902. lp = netdev_priv(ndev);
  1903. if (pd) {
  1904. memcpy(&lp->cfg, pd, sizeof(lp->cfg));
  1905. lp->io_shift = SMC91X_IO_SHIFT(lp->cfg.flags);
  1906. } else {
  1907. lp->cfg.flags |= (SMC_CAN_USE_8BIT) ? SMC91X_USE_8BIT : 0;
  1908. lp->cfg.flags |= (SMC_CAN_USE_16BIT) ? SMC91X_USE_16BIT : 0;
  1909. lp->cfg.flags |= (SMC_CAN_USE_32BIT) ? SMC91X_USE_32BIT : 0;
  1910. lp->cfg.flags |= (nowait) ? SMC91X_NOWAIT : 0;
  1911. }
  1912. if (!lp->cfg.leda && !lp->cfg.ledb) {
  1913. lp->cfg.leda = RPC_LSA_DEFAULT;
  1914. lp->cfg.ledb = RPC_LSB_DEFAULT;
  1915. }
  1916. ndev->dma = (unsigned char)-1;
  1917. res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "smc91x-regs");
  1918. if (!res)
  1919. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1920. if (!res) {
  1921. ret = -ENODEV;
  1922. goto out_free_netdev;
  1923. }
  1924. if (!request_mem_region(res->start, SMC_IO_EXTENT, CARDNAME)) {
  1925. ret = -EBUSY;
  1926. goto out_free_netdev;
  1927. }
  1928. ires = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  1929. if (!ires) {
  1930. ret = -ENODEV;
  1931. goto out_release_io;
  1932. }
  1933. ndev->irq = ires->start;
  1934. if (ires->flags & IRQF_TRIGGER_MASK)
  1935. irq_flags = ires->flags & IRQF_TRIGGER_MASK;
  1936. ret = smc_request_attrib(pdev, ndev);
  1937. if (ret)
  1938. goto out_release_io;
  1939. #if defined(CONFIG_SA1100_ASSABET)
  1940. NCR_0 |= NCR_ENET_OSC_EN;
  1941. #endif
  1942. platform_set_drvdata(pdev, ndev);
  1943. ret = smc_enable_device(pdev);
  1944. if (ret)
  1945. goto out_release_attrib;
  1946. addr = ioremap(res->start, SMC_IO_EXTENT);
  1947. if (!addr) {
  1948. ret = -ENOMEM;
  1949. goto out_release_attrib;
  1950. }
  1951. #ifdef CONFIG_ARCH_PXA
  1952. {
  1953. struct smc_local *lp = netdev_priv(ndev);
  1954. lp->device = &pdev->dev;
  1955. lp->physaddr = res->start;
  1956. }
  1957. #endif
  1958. ret = smc_probe(ndev, addr, irq_flags);
  1959. if (ret != 0)
  1960. goto out_iounmap;
  1961. smc_request_datacs(pdev, ndev);
  1962. return 0;
  1963. out_iounmap:
  1964. platform_set_drvdata(pdev, NULL);
  1965. iounmap(addr);
  1966. out_release_attrib:
  1967. smc_release_attrib(pdev, ndev);
  1968. out_release_io:
  1969. release_mem_region(res->start, SMC_IO_EXTENT);
  1970. out_free_netdev:
  1971. free_netdev(ndev);
  1972. out:
  1973. printk("%s: not found (%d).\n", CARDNAME, ret);
  1974. return ret;
  1975. }
  1976. static int __devexit smc_drv_remove(struct platform_device *pdev)
  1977. {
  1978. struct net_device *ndev = platform_get_drvdata(pdev);
  1979. struct smc_local *lp = netdev_priv(ndev);
  1980. struct resource *res;
  1981. platform_set_drvdata(pdev, NULL);
  1982. unregister_netdev(ndev);
  1983. free_irq(ndev->irq, ndev);
  1984. #ifdef CONFIG_ARCH_PXA
  1985. if (ndev->dma != (unsigned char)-1)
  1986. pxa_free_dma(ndev->dma);
  1987. #endif
  1988. iounmap(lp->base);
  1989. smc_release_datacs(pdev,ndev);
  1990. smc_release_attrib(pdev,ndev);
  1991. res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "smc91x-regs");
  1992. if (!res)
  1993. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1994. release_mem_region(res->start, SMC_IO_EXTENT);
  1995. free_netdev(ndev);
  1996. return 0;
  1997. }
  1998. static int smc_drv_suspend(struct platform_device *dev, pm_message_t state)
  1999. {
  2000. struct net_device *ndev = platform_get_drvdata(dev);
  2001. if (ndev) {
  2002. if (netif_running(ndev)) {
  2003. netif_device_detach(ndev);
  2004. smc_shutdown(ndev);
  2005. smc_phy_powerdown(ndev);
  2006. }
  2007. }
  2008. return 0;
  2009. }
  2010. static int smc_drv_resume(struct platform_device *dev)
  2011. {
  2012. struct net_device *ndev = platform_get_drvdata(dev);
  2013. if (ndev) {
  2014. struct smc_local *lp = netdev_priv(ndev);
  2015. smc_enable_device(dev);
  2016. if (netif_running(ndev)) {
  2017. smc_reset(ndev);
  2018. smc_enable(ndev);
  2019. if (lp->phy_type != 0)
  2020. smc_phy_configure(&lp->phy_configure);
  2021. netif_device_attach(ndev);
  2022. }
  2023. }
  2024. return 0;
  2025. }
  2026. static struct platform_driver smc_driver = {
  2027. .probe = smc_drv_probe,
  2028. .remove = __devexit_p(smc_drv_remove),
  2029. .suspend = smc_drv_suspend,
  2030. .resume = smc_drv_resume,
  2031. .driver = {
  2032. .name = CARDNAME,
  2033. .owner = THIS_MODULE,
  2034. },
  2035. };
  2036. static int __init smc_init(void)
  2037. {
  2038. return platform_driver_register(&smc_driver);
  2039. }
  2040. static void __exit smc_cleanup(void)
  2041. {
  2042. platform_driver_unregister(&smc_driver);
  2043. }
  2044. module_init(smc_init);
  2045. module_exit(smc_cleanup);