smc91x.c 62 KB

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