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