smc91x.c 62 KB

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