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