smc911x.c 58 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216
  1. /*
  2. * smc911x.c
  3. * This is a driver for SMSC's LAN911{5,6,7,8} single-chip Ethernet devices.
  4. *
  5. * Copyright (C) 2005 Sensoria Corp
  6. * Derived from the unified SMC91x driver by Nicolas Pitre
  7. * and the smsc911x.c reference driver by SMSC
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  22. *
  23. * Arguments:
  24. * watchdog = TX watchdog timeout
  25. * tx_fifo_kb = Size of TX FIFO in KB
  26. *
  27. * History:
  28. * 04/16/05 Dustin McIntire Initial version
  29. */
  30. static const char version[] =
  31. "smc911x.c: v1.0 04-16-2005 by Dustin McIntire <dustin@sensoria.com>\n";
  32. /* Debugging options */
  33. #define ENABLE_SMC_DEBUG_RX 0
  34. #define ENABLE_SMC_DEBUG_TX 0
  35. #define ENABLE_SMC_DEBUG_DMA 0
  36. #define ENABLE_SMC_DEBUG_PKTS 0
  37. #define ENABLE_SMC_DEBUG_MISC 0
  38. #define ENABLE_SMC_DEBUG_FUNC 0
  39. #define SMC_DEBUG_RX ((ENABLE_SMC_DEBUG_RX ? 1 : 0) << 0)
  40. #define SMC_DEBUG_TX ((ENABLE_SMC_DEBUG_TX ? 1 : 0) << 1)
  41. #define SMC_DEBUG_DMA ((ENABLE_SMC_DEBUG_DMA ? 1 : 0) << 2)
  42. #define SMC_DEBUG_PKTS ((ENABLE_SMC_DEBUG_PKTS ? 1 : 0) << 3)
  43. #define SMC_DEBUG_MISC ((ENABLE_SMC_DEBUG_MISC ? 1 : 0) << 4)
  44. #define SMC_DEBUG_FUNC ((ENABLE_SMC_DEBUG_FUNC ? 1 : 0) << 5)
  45. #ifndef SMC_DEBUG
  46. #define SMC_DEBUG ( SMC_DEBUG_RX | \
  47. SMC_DEBUG_TX | \
  48. SMC_DEBUG_DMA | \
  49. SMC_DEBUG_PKTS | \
  50. SMC_DEBUG_MISC | \
  51. SMC_DEBUG_FUNC \
  52. )
  53. #endif
  54. #include <linux/init.h>
  55. #include <linux/module.h>
  56. #include <linux/kernel.h>
  57. #include <linux/sched.h>
  58. #include <linux/slab.h>
  59. #include <linux/delay.h>
  60. #include <linux/interrupt.h>
  61. #include <linux/errno.h>
  62. #include <linux/ioport.h>
  63. #include <linux/crc32.h>
  64. #include <linux/device.h>
  65. #include <linux/platform_device.h>
  66. #include <linux/spinlock.h>
  67. #include <linux/ethtool.h>
  68. #include <linux/mii.h>
  69. #include <linux/workqueue.h>
  70. #include <linux/netdevice.h>
  71. #include <linux/etherdevice.h>
  72. #include <linux/skbuff.h>
  73. #include <asm/io.h>
  74. #include "smc911x.h"
  75. /*
  76. * Transmit timeout, default 5 seconds.
  77. */
  78. static int watchdog = 5000;
  79. module_param(watchdog, int, 0400);
  80. MODULE_PARM_DESC(watchdog, "transmit timeout in milliseconds");
  81. static int tx_fifo_kb=8;
  82. module_param(tx_fifo_kb, int, 0400);
  83. MODULE_PARM_DESC(tx_fifo_kb,"transmit FIFO size in KB (1<x<15)(default=8)");
  84. MODULE_LICENSE("GPL");
  85. MODULE_ALIAS("platform:smc911x");
  86. /*
  87. * The internal workings of the driver. If you are changing anything
  88. * here with the SMC stuff, you should have the datasheet and know
  89. * what you are doing.
  90. */
  91. #define CARDNAME "smc911x"
  92. /*
  93. * Use power-down feature of the chip
  94. */
  95. #define POWER_DOWN 1
  96. #if SMC_DEBUG > 0
  97. #define DBG(n, args...) \
  98. do { \
  99. if (SMC_DEBUG & (n)) \
  100. printk(args); \
  101. } while (0)
  102. #define PRINTK(args...) printk(args)
  103. #else
  104. #define DBG(n, args...) do { } while (0)
  105. #define PRINTK(args...) printk(KERN_DEBUG args)
  106. #endif
  107. #if SMC_DEBUG_PKTS > 0
  108. static void PRINT_PKT(u_char *buf, int length)
  109. {
  110. int i;
  111. int remainder;
  112. int lines;
  113. lines = length / 16;
  114. remainder = length % 16;
  115. for (i = 0; i < lines ; i ++) {
  116. int cur;
  117. for (cur = 0; cur < 8; cur++) {
  118. u_char a, b;
  119. a = *buf++;
  120. b = *buf++;
  121. printk("%02x%02x ", a, b);
  122. }
  123. printk("\n");
  124. }
  125. for (i = 0; i < remainder/2 ; i++) {
  126. u_char a, b;
  127. a = *buf++;
  128. b = *buf++;
  129. printk("%02x%02x ", a, b);
  130. }
  131. printk("\n");
  132. }
  133. #else
  134. #define PRINT_PKT(x...) do { } while (0)
  135. #endif
  136. /* this enables an interrupt in the interrupt mask register */
  137. #define SMC_ENABLE_INT(lp, x) do { \
  138. unsigned int __mask; \
  139. __mask = SMC_GET_INT_EN((lp)); \
  140. __mask |= (x); \
  141. SMC_SET_INT_EN((lp), __mask); \
  142. } while (0)
  143. /* this disables an interrupt from the interrupt mask register */
  144. #define SMC_DISABLE_INT(lp, x) do { \
  145. unsigned int __mask; \
  146. __mask = SMC_GET_INT_EN((lp)); \
  147. __mask &= ~(x); \
  148. SMC_SET_INT_EN((lp), __mask); \
  149. } while (0)
  150. /*
  151. * this does a soft reset on the device
  152. */
  153. static void smc911x_reset(struct net_device *dev)
  154. {
  155. struct smc911x_local *lp = netdev_priv(dev);
  156. unsigned int reg, timeout=0, resets=1, irq_cfg;
  157. unsigned long flags;
  158. DBG(SMC_DEBUG_FUNC, "%s: --> %s\n", dev->name, __func__);
  159. /* Take out of PM setting first */
  160. if ((SMC_GET_PMT_CTRL(lp) & PMT_CTRL_READY_) == 0) {
  161. /* Write to the bytetest will take out of powerdown */
  162. SMC_SET_BYTE_TEST(lp, 0);
  163. timeout=10;
  164. do {
  165. udelay(10);
  166. reg = SMC_GET_PMT_CTRL(lp) & PMT_CTRL_READY_;
  167. } while (--timeout && !reg);
  168. if (timeout == 0) {
  169. PRINTK("%s: smc911x_reset timeout waiting for PM restore\n", dev->name);
  170. return;
  171. }
  172. }
  173. /* Disable all interrupts */
  174. spin_lock_irqsave(&lp->lock, flags);
  175. SMC_SET_INT_EN(lp, 0);
  176. spin_unlock_irqrestore(&lp->lock, flags);
  177. while (resets--) {
  178. SMC_SET_HW_CFG(lp, HW_CFG_SRST_);
  179. timeout=10;
  180. do {
  181. udelay(10);
  182. reg = SMC_GET_HW_CFG(lp);
  183. /* If chip indicates reset timeout then try again */
  184. if (reg & HW_CFG_SRST_TO_) {
  185. PRINTK("%s: chip reset timeout, retrying...\n", dev->name);
  186. resets++;
  187. break;
  188. }
  189. } while (--timeout && (reg & HW_CFG_SRST_));
  190. }
  191. if (timeout == 0) {
  192. PRINTK("%s: smc911x_reset timeout waiting for reset\n", dev->name);
  193. return;
  194. }
  195. /* make sure EEPROM has finished loading before setting GPIO_CFG */
  196. timeout=1000;
  197. while ( timeout-- && (SMC_GET_E2P_CMD(lp) & E2P_CMD_EPC_BUSY_)) {
  198. udelay(10);
  199. }
  200. if (timeout == 0){
  201. PRINTK("%s: smc911x_reset timeout waiting for EEPROM busy\n", dev->name);
  202. return;
  203. }
  204. /* Initialize interrupts */
  205. SMC_SET_INT_EN(lp, 0);
  206. SMC_ACK_INT(lp, -1);
  207. /* Reset the FIFO level and flow control settings */
  208. SMC_SET_HW_CFG(lp, (lp->tx_fifo_kb & 0xF) << 16);
  209. //TODO: Figure out what appropriate pause time is
  210. SMC_SET_FLOW(lp, FLOW_FCPT_ | FLOW_FCEN_);
  211. SMC_SET_AFC_CFG(lp, lp->afc_cfg);
  212. /* Set to LED outputs */
  213. SMC_SET_GPIO_CFG(lp, 0x70070000);
  214. /*
  215. * Deassert IRQ for 1*10us for edge type interrupts
  216. * and drive IRQ pin push-pull
  217. */
  218. irq_cfg = (1 << 24) | INT_CFG_IRQ_EN_ | INT_CFG_IRQ_TYPE_;
  219. #ifdef SMC_DYNAMIC_BUS_CONFIG
  220. if (lp->cfg.irq_polarity)
  221. irq_cfg |= INT_CFG_IRQ_POL_;
  222. #endif
  223. SMC_SET_IRQ_CFG(lp, irq_cfg);
  224. /* clear anything saved */
  225. if (lp->pending_tx_skb != NULL) {
  226. dev_kfree_skb (lp->pending_tx_skb);
  227. lp->pending_tx_skb = NULL;
  228. dev->stats.tx_errors++;
  229. dev->stats.tx_aborted_errors++;
  230. }
  231. }
  232. /*
  233. * Enable Interrupts, Receive, and Transmit
  234. */
  235. static void smc911x_enable(struct net_device *dev)
  236. {
  237. struct smc911x_local *lp = netdev_priv(dev);
  238. unsigned mask, cfg, cr;
  239. unsigned long flags;
  240. DBG(SMC_DEBUG_FUNC, "%s: --> %s\n", dev->name, __func__);
  241. spin_lock_irqsave(&lp->lock, flags);
  242. SMC_SET_MAC_ADDR(lp, dev->dev_addr);
  243. /* Enable TX */
  244. cfg = SMC_GET_HW_CFG(lp);
  245. cfg &= HW_CFG_TX_FIF_SZ_ | 0xFFF;
  246. cfg |= HW_CFG_SF_;
  247. SMC_SET_HW_CFG(lp, cfg);
  248. SMC_SET_FIFO_TDA(lp, 0xFF);
  249. /* Update TX stats on every 64 packets received or every 1 sec */
  250. SMC_SET_FIFO_TSL(lp, 64);
  251. SMC_SET_GPT_CFG(lp, GPT_CFG_TIMER_EN_ | 10000);
  252. SMC_GET_MAC_CR(lp, cr);
  253. cr |= MAC_CR_TXEN_ | MAC_CR_HBDIS_;
  254. SMC_SET_MAC_CR(lp, cr);
  255. SMC_SET_TX_CFG(lp, TX_CFG_TX_ON_);
  256. /* Add 2 byte padding to start of packets */
  257. SMC_SET_RX_CFG(lp, (2<<8) & RX_CFG_RXDOFF_);
  258. /* Turn on receiver and enable RX */
  259. if (cr & MAC_CR_RXEN_)
  260. DBG(SMC_DEBUG_RX, "%s: Receiver already enabled\n", dev->name);
  261. SMC_SET_MAC_CR(lp, cr | MAC_CR_RXEN_);
  262. /* Interrupt on every received packet */
  263. SMC_SET_FIFO_RSA(lp, 0x01);
  264. SMC_SET_FIFO_RSL(lp, 0x00);
  265. /* now, enable interrupts */
  266. mask = INT_EN_TDFA_EN_ | INT_EN_TSFL_EN_ | INT_EN_RSFL_EN_ |
  267. INT_EN_GPT_INT_EN_ | INT_EN_RXDFH_INT_EN_ | INT_EN_RXE_EN_ |
  268. INT_EN_PHY_INT_EN_;
  269. if (IS_REV_A(lp->revision))
  270. mask|=INT_EN_RDFL_EN_;
  271. else {
  272. mask|=INT_EN_RDFO_EN_;
  273. }
  274. SMC_ENABLE_INT(lp, mask);
  275. spin_unlock_irqrestore(&lp->lock, flags);
  276. }
  277. /*
  278. * this puts the device in an inactive state
  279. */
  280. static void smc911x_shutdown(struct net_device *dev)
  281. {
  282. struct smc911x_local *lp = netdev_priv(dev);
  283. unsigned cr;
  284. unsigned long flags;
  285. DBG(SMC_DEBUG_FUNC, "%s: --> %s\n", CARDNAME, __func__);
  286. /* Disable IRQ's */
  287. SMC_SET_INT_EN(lp, 0);
  288. /* Turn of Rx and TX */
  289. spin_lock_irqsave(&lp->lock, flags);
  290. SMC_GET_MAC_CR(lp, cr);
  291. cr &= ~(MAC_CR_TXEN_ | MAC_CR_RXEN_ | MAC_CR_HBDIS_);
  292. SMC_SET_MAC_CR(lp, cr);
  293. SMC_SET_TX_CFG(lp, TX_CFG_STOP_TX_);
  294. spin_unlock_irqrestore(&lp->lock, flags);
  295. }
  296. static inline void smc911x_drop_pkt(struct net_device *dev)
  297. {
  298. struct smc911x_local *lp = netdev_priv(dev);
  299. unsigned int fifo_count, timeout, reg;
  300. DBG(SMC_DEBUG_FUNC | SMC_DEBUG_RX, "%s: --> %s\n", CARDNAME, __func__);
  301. fifo_count = SMC_GET_RX_FIFO_INF(lp) & 0xFFFF;
  302. if (fifo_count <= 4) {
  303. /* Manually dump the packet data */
  304. while (fifo_count--)
  305. SMC_GET_RX_FIFO(lp);
  306. } else {
  307. /* Fast forward through the bad packet */
  308. SMC_SET_RX_DP_CTRL(lp, RX_DP_CTRL_FFWD_BUSY_);
  309. timeout=50;
  310. do {
  311. udelay(10);
  312. reg = SMC_GET_RX_DP_CTRL(lp) & RX_DP_CTRL_FFWD_BUSY_;
  313. } while (--timeout && reg);
  314. if (timeout == 0) {
  315. PRINTK("%s: timeout waiting for RX fast forward\n", dev->name);
  316. }
  317. }
  318. }
  319. /*
  320. * This is the procedure to handle the receipt of a packet.
  321. * It should be called after checking for packet presence in
  322. * the RX status FIFO. It must be called with the spin lock
  323. * already held.
  324. */
  325. static inline void smc911x_rcv(struct net_device *dev)
  326. {
  327. struct smc911x_local *lp = netdev_priv(dev);
  328. unsigned int pkt_len, status;
  329. struct sk_buff *skb;
  330. unsigned char *data;
  331. DBG(SMC_DEBUG_FUNC | SMC_DEBUG_RX, "%s: --> %s\n",
  332. dev->name, __func__);
  333. status = SMC_GET_RX_STS_FIFO(lp);
  334. DBG(SMC_DEBUG_RX, "%s: Rx pkt len %d status 0x%08x \n",
  335. dev->name, (status & 0x3fff0000) >> 16, status & 0xc000ffff);
  336. pkt_len = (status & RX_STS_PKT_LEN_) >> 16;
  337. if (status & RX_STS_ES_) {
  338. /* Deal with a bad packet */
  339. dev->stats.rx_errors++;
  340. if (status & RX_STS_CRC_ERR_)
  341. dev->stats.rx_crc_errors++;
  342. else {
  343. if (status & RX_STS_LEN_ERR_)
  344. dev->stats.rx_length_errors++;
  345. if (status & RX_STS_MCAST_)
  346. dev->stats.multicast++;
  347. }
  348. /* Remove the bad packet data from the RX FIFO */
  349. smc911x_drop_pkt(dev);
  350. } else {
  351. /* Receive a valid packet */
  352. /* Alloc a buffer with extra room for DMA alignment */
  353. skb=dev_alloc_skb(pkt_len+32);
  354. if (unlikely(skb == NULL)) {
  355. PRINTK( "%s: Low memory, rcvd packet dropped.\n",
  356. dev->name);
  357. dev->stats.rx_dropped++;
  358. smc911x_drop_pkt(dev);
  359. return;
  360. }
  361. /* Align IP header to 32 bits
  362. * Note that the device is configured to add a 2
  363. * byte padding to the packet start, so we really
  364. * want to write to the orignal data pointer */
  365. data = skb->data;
  366. skb_reserve(skb, 2);
  367. skb_put(skb,pkt_len-4);
  368. #ifdef SMC_USE_DMA
  369. {
  370. unsigned int fifo;
  371. /* Lower the FIFO threshold if possible */
  372. fifo = SMC_GET_FIFO_INT(lp);
  373. if (fifo & 0xFF) fifo--;
  374. DBG(SMC_DEBUG_RX, "%s: Setting RX stat FIFO threshold to %d\n",
  375. dev->name, fifo & 0xff);
  376. SMC_SET_FIFO_INT(lp, fifo);
  377. /* Setup RX DMA */
  378. SMC_SET_RX_CFG(lp, RX_CFG_RX_END_ALGN16_ | ((2<<8) & RX_CFG_RXDOFF_));
  379. lp->rxdma_active = 1;
  380. lp->current_rx_skb = skb;
  381. SMC_PULL_DATA(lp, data, (pkt_len+2+15) & ~15);
  382. /* Packet processing deferred to DMA RX interrupt */
  383. }
  384. #else
  385. SMC_SET_RX_CFG(lp, RX_CFG_RX_END_ALGN4_ | ((2<<8) & RX_CFG_RXDOFF_));
  386. SMC_PULL_DATA(lp, data, pkt_len+2+3);
  387. DBG(SMC_DEBUG_PKTS, "%s: Received packet\n", dev->name);
  388. PRINT_PKT(data, ((pkt_len - 4) <= 64) ? pkt_len - 4 : 64);
  389. skb->protocol = eth_type_trans(skb, dev);
  390. netif_rx(skb);
  391. dev->stats.rx_packets++;
  392. dev->stats.rx_bytes += pkt_len-4;
  393. #endif
  394. }
  395. }
  396. /*
  397. * This is called to actually send a packet to the chip.
  398. */
  399. static void smc911x_hardware_send_pkt(struct net_device *dev)
  400. {
  401. struct smc911x_local *lp = netdev_priv(dev);
  402. struct sk_buff *skb;
  403. unsigned int cmdA, cmdB, len;
  404. unsigned char *buf;
  405. DBG(SMC_DEBUG_FUNC | SMC_DEBUG_TX, "%s: --> %s\n", dev->name, __func__);
  406. BUG_ON(lp->pending_tx_skb == NULL);
  407. skb = lp->pending_tx_skb;
  408. lp->pending_tx_skb = NULL;
  409. /* cmdA {25:24] data alignment [20:16] start offset [10:0] buffer length */
  410. /* cmdB {31:16] pkt tag [10:0] length */
  411. #ifdef SMC_USE_DMA
  412. /* 16 byte buffer alignment mode */
  413. buf = (char*)((u32)(skb->data) & ~0xF);
  414. len = (skb->len + 0xF + ((u32)skb->data & 0xF)) & ~0xF;
  415. cmdA = (1<<24) | (((u32)skb->data & 0xF)<<16) |
  416. TX_CMD_A_INT_FIRST_SEG_ | TX_CMD_A_INT_LAST_SEG_ |
  417. skb->len;
  418. #else
  419. buf = (char*)((u32)skb->data & ~0x3);
  420. len = (skb->len + 3 + ((u32)skb->data & 3)) & ~0x3;
  421. cmdA = (((u32)skb->data & 0x3) << 16) |
  422. TX_CMD_A_INT_FIRST_SEG_ | TX_CMD_A_INT_LAST_SEG_ |
  423. skb->len;
  424. #endif
  425. /* tag is packet length so we can use this in stats update later */
  426. cmdB = (skb->len << 16) | (skb->len & 0x7FF);
  427. DBG(SMC_DEBUG_TX, "%s: TX PKT LENGTH 0x%04x (%d) BUF 0x%p CMDA 0x%08x CMDB 0x%08x\n",
  428. dev->name, len, len, buf, cmdA, cmdB);
  429. SMC_SET_TX_FIFO(lp, cmdA);
  430. SMC_SET_TX_FIFO(lp, cmdB);
  431. DBG(SMC_DEBUG_PKTS, "%s: Transmitted packet\n", dev->name);
  432. PRINT_PKT(buf, len <= 64 ? len : 64);
  433. /* Send pkt via PIO or DMA */
  434. #ifdef SMC_USE_DMA
  435. lp->current_tx_skb = skb;
  436. SMC_PUSH_DATA(lp, buf, len);
  437. /* DMA complete IRQ will free buffer and set jiffies */
  438. #else
  439. SMC_PUSH_DATA(lp, buf, len);
  440. dev->trans_start = jiffies;
  441. dev_kfree_skb_irq(skb);
  442. #endif
  443. if (!lp->tx_throttle) {
  444. netif_wake_queue(dev);
  445. }
  446. SMC_ENABLE_INT(lp, INT_EN_TDFA_EN_ | INT_EN_TSFL_EN_);
  447. }
  448. /*
  449. * Since I am not sure if I will have enough room in the chip's ram
  450. * to store the packet, I call this routine which either sends it
  451. * now, or set the card to generates an interrupt when ready
  452. * for the packet.
  453. */
  454. static int smc911x_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
  455. {
  456. struct smc911x_local *lp = netdev_priv(dev);
  457. unsigned int free;
  458. unsigned long flags;
  459. DBG(SMC_DEBUG_FUNC | SMC_DEBUG_TX, "%s: --> %s\n",
  460. dev->name, __func__);
  461. spin_lock_irqsave(&lp->lock, flags);
  462. BUG_ON(lp->pending_tx_skb != NULL);
  463. free = SMC_GET_TX_FIFO_INF(lp) & TX_FIFO_INF_TDFREE_;
  464. DBG(SMC_DEBUG_TX, "%s: TX free space %d\n", dev->name, free);
  465. /* Turn off the flow when running out of space in FIFO */
  466. if (free <= SMC911X_TX_FIFO_LOW_THRESHOLD) {
  467. DBG(SMC_DEBUG_TX, "%s: Disabling data flow due to low FIFO space (%d)\n",
  468. dev->name, free);
  469. /* Reenable when at least 1 packet of size MTU present */
  470. SMC_SET_FIFO_TDA(lp, (SMC911X_TX_FIFO_LOW_THRESHOLD)/64);
  471. lp->tx_throttle = 1;
  472. netif_stop_queue(dev);
  473. }
  474. /* Drop packets when we run out of space in TX FIFO
  475. * Account for overhead required for:
  476. *
  477. * Tx command words 8 bytes
  478. * Start offset 15 bytes
  479. * End padding 15 bytes
  480. */
  481. if (unlikely(free < (skb->len + 8 + 15 + 15))) {
  482. printk("%s: No Tx free space %d < %d\n",
  483. dev->name, free, skb->len);
  484. lp->pending_tx_skb = NULL;
  485. dev->stats.tx_errors++;
  486. dev->stats.tx_dropped++;
  487. spin_unlock_irqrestore(&lp->lock, flags);
  488. dev_kfree_skb(skb);
  489. return 0;
  490. }
  491. #ifdef SMC_USE_DMA
  492. {
  493. /* If the DMA is already running then defer this packet Tx until
  494. * the DMA IRQ starts it
  495. */
  496. if (lp->txdma_active) {
  497. DBG(SMC_DEBUG_TX | SMC_DEBUG_DMA, "%s: Tx DMA running, deferring packet\n", dev->name);
  498. lp->pending_tx_skb = skb;
  499. netif_stop_queue(dev);
  500. spin_unlock_irqrestore(&lp->lock, flags);
  501. return 0;
  502. } else {
  503. DBG(SMC_DEBUG_TX | SMC_DEBUG_DMA, "%s: Activating Tx DMA\n", dev->name);
  504. lp->txdma_active = 1;
  505. }
  506. }
  507. #endif
  508. lp->pending_tx_skb = skb;
  509. smc911x_hardware_send_pkt(dev);
  510. spin_unlock_irqrestore(&lp->lock, flags);
  511. return 0;
  512. }
  513. /*
  514. * This handles a TX status interrupt, which is only called when:
  515. * - a TX error occurred, or
  516. * - TX of a packet completed.
  517. */
  518. static void smc911x_tx(struct net_device *dev)
  519. {
  520. struct smc911x_local *lp = netdev_priv(dev);
  521. unsigned int tx_status;
  522. DBG(SMC_DEBUG_FUNC | SMC_DEBUG_TX, "%s: --> %s\n",
  523. dev->name, __func__);
  524. /* Collect the TX status */
  525. while (((SMC_GET_TX_FIFO_INF(lp) & TX_FIFO_INF_TSUSED_) >> 16) != 0) {
  526. DBG(SMC_DEBUG_TX, "%s: Tx stat FIFO used 0x%04x\n",
  527. dev->name,
  528. (SMC_GET_TX_FIFO_INF(lp) & TX_FIFO_INF_TSUSED_) >> 16);
  529. tx_status = SMC_GET_TX_STS_FIFO(lp);
  530. dev->stats.tx_packets++;
  531. dev->stats.tx_bytes+=tx_status>>16;
  532. DBG(SMC_DEBUG_TX, "%s: Tx FIFO tag 0x%04x status 0x%04x\n",
  533. dev->name, (tx_status & 0xffff0000) >> 16,
  534. tx_status & 0x0000ffff);
  535. /* count Tx errors, but ignore lost carrier errors when in
  536. * full-duplex mode */
  537. if ((tx_status & TX_STS_ES_) && !(lp->ctl_rfduplx &&
  538. !(tx_status & 0x00000306))) {
  539. dev->stats.tx_errors++;
  540. }
  541. if (tx_status & TX_STS_MANY_COLL_) {
  542. dev->stats.collisions+=16;
  543. dev->stats.tx_aborted_errors++;
  544. } else {
  545. dev->stats.collisions+=(tx_status & TX_STS_COLL_CNT_) >> 3;
  546. }
  547. /* carrier error only has meaning for half-duplex communication */
  548. if ((tx_status & (TX_STS_LOC_ | TX_STS_NO_CARR_)) &&
  549. !lp->ctl_rfduplx) {
  550. dev->stats.tx_carrier_errors++;
  551. }
  552. if (tx_status & TX_STS_LATE_COLL_) {
  553. dev->stats.collisions++;
  554. dev->stats.tx_aborted_errors++;
  555. }
  556. }
  557. }
  558. /*---PHY CONTROL AND CONFIGURATION-----------------------------------------*/
  559. /*
  560. * Reads a register from the MII Management serial interface
  561. */
  562. static int smc911x_phy_read(struct net_device *dev, int phyaddr, int phyreg)
  563. {
  564. struct smc911x_local *lp = netdev_priv(dev);
  565. unsigned int phydata;
  566. SMC_GET_MII(lp, phyreg, phyaddr, phydata);
  567. DBG(SMC_DEBUG_MISC, "%s: phyaddr=0x%x, phyreg=0x%02x, phydata=0x%04x\n",
  568. __func__, phyaddr, phyreg, phydata);
  569. return phydata;
  570. }
  571. /*
  572. * Writes a register to the MII Management serial interface
  573. */
  574. static void smc911x_phy_write(struct net_device *dev, int phyaddr, int phyreg,
  575. int phydata)
  576. {
  577. struct smc911x_local *lp = netdev_priv(dev);
  578. DBG(SMC_DEBUG_MISC, "%s: phyaddr=0x%x, phyreg=0x%x, phydata=0x%x\n",
  579. __func__, phyaddr, phyreg, phydata);
  580. SMC_SET_MII(lp, phyreg, phyaddr, phydata);
  581. }
  582. /*
  583. * Finds and reports the PHY address (115 and 117 have external
  584. * PHY interface 118 has internal only
  585. */
  586. static void smc911x_phy_detect(struct net_device *dev)
  587. {
  588. struct smc911x_local *lp = netdev_priv(dev);
  589. int phyaddr;
  590. unsigned int cfg, id1, id2;
  591. DBG(SMC_DEBUG_FUNC, "%s: --> %s\n", dev->name, __func__);
  592. lp->phy_type = 0;
  593. /*
  594. * Scan all 32 PHY addresses if necessary, starting at
  595. * PHY#1 to PHY#31, and then PHY#0 last.
  596. */
  597. switch(lp->version) {
  598. case CHIP_9115:
  599. case CHIP_9117:
  600. case CHIP_9215:
  601. case CHIP_9217:
  602. cfg = SMC_GET_HW_CFG(lp);
  603. if (cfg & HW_CFG_EXT_PHY_DET_) {
  604. cfg &= ~HW_CFG_PHY_CLK_SEL_;
  605. cfg |= HW_CFG_PHY_CLK_SEL_CLK_DIS_;
  606. SMC_SET_HW_CFG(lp, cfg);
  607. udelay(10); /* Wait for clocks to stop */
  608. cfg |= HW_CFG_EXT_PHY_EN_;
  609. SMC_SET_HW_CFG(lp, cfg);
  610. udelay(10); /* Wait for clocks to stop */
  611. cfg &= ~HW_CFG_PHY_CLK_SEL_;
  612. cfg |= HW_CFG_PHY_CLK_SEL_EXT_PHY_;
  613. SMC_SET_HW_CFG(lp, cfg);
  614. udelay(10); /* Wait for clocks to stop */
  615. cfg |= HW_CFG_SMI_SEL_;
  616. SMC_SET_HW_CFG(lp, cfg);
  617. for (phyaddr = 1; phyaddr < 32; ++phyaddr) {
  618. /* Read the PHY identifiers */
  619. SMC_GET_PHY_ID1(lp, phyaddr & 31, id1);
  620. SMC_GET_PHY_ID2(lp, phyaddr & 31, id2);
  621. /* Make sure it is a valid identifier */
  622. if (id1 != 0x0000 && id1 != 0xffff &&
  623. id1 != 0x8000 && id2 != 0x0000 &&
  624. id2 != 0xffff && id2 != 0x8000) {
  625. /* Save the PHY's address */
  626. lp->mii.phy_id = phyaddr & 31;
  627. lp->phy_type = id1 << 16 | id2;
  628. break;
  629. }
  630. }
  631. if (phyaddr < 32)
  632. /* Found an external PHY */
  633. break;
  634. }
  635. default:
  636. /* Internal media only */
  637. SMC_GET_PHY_ID1(lp, 1, id1);
  638. SMC_GET_PHY_ID2(lp, 1, id2);
  639. /* Save the PHY's address */
  640. lp->mii.phy_id = 1;
  641. lp->phy_type = id1 << 16 | id2;
  642. }
  643. DBG(SMC_DEBUG_MISC, "%s: phy_id1=0x%x, phy_id2=0x%x phyaddr=0x%d\n",
  644. dev->name, id1, id2, lp->mii.phy_id);
  645. }
  646. /*
  647. * Sets the PHY to a configuration as determined by the user.
  648. * Called with spin_lock held.
  649. */
  650. static int smc911x_phy_fixed(struct net_device *dev)
  651. {
  652. struct smc911x_local *lp = netdev_priv(dev);
  653. int phyaddr = lp->mii.phy_id;
  654. int bmcr;
  655. DBG(SMC_DEBUG_FUNC, "%s: --> %s\n", dev->name, __func__);
  656. /* Enter Link Disable state */
  657. SMC_GET_PHY_BMCR(lp, phyaddr, bmcr);
  658. bmcr |= BMCR_PDOWN;
  659. SMC_SET_PHY_BMCR(lp, phyaddr, bmcr);
  660. /*
  661. * Set our fixed capabilities
  662. * Disable auto-negotiation
  663. */
  664. bmcr &= ~BMCR_ANENABLE;
  665. if (lp->ctl_rfduplx)
  666. bmcr |= BMCR_FULLDPLX;
  667. if (lp->ctl_rspeed == 100)
  668. bmcr |= BMCR_SPEED100;
  669. /* Write our capabilities to the phy control register */
  670. SMC_SET_PHY_BMCR(lp, phyaddr, bmcr);
  671. /* Re-Configure the Receive/Phy Control register */
  672. bmcr &= ~BMCR_PDOWN;
  673. SMC_SET_PHY_BMCR(lp, phyaddr, bmcr);
  674. return 1;
  675. }
  676. /*
  677. * smc911x_phy_reset - reset the phy
  678. * @dev: net device
  679. * @phy: phy address
  680. *
  681. * Issue a software reset for the specified PHY and
  682. * wait up to 100ms for the reset to complete. We should
  683. * not access the PHY for 50ms after issuing the reset.
  684. *
  685. * The time to wait appears to be dependent on the PHY.
  686. *
  687. */
  688. static int smc911x_phy_reset(struct net_device *dev, int phy)
  689. {
  690. struct smc911x_local *lp = netdev_priv(dev);
  691. int timeout;
  692. unsigned long flags;
  693. unsigned int reg;
  694. DBG(SMC_DEBUG_FUNC, "%s: --> %s()\n", dev->name, __func__);
  695. spin_lock_irqsave(&lp->lock, flags);
  696. reg = SMC_GET_PMT_CTRL(lp);
  697. reg &= ~0xfffff030;
  698. reg |= PMT_CTRL_PHY_RST_;
  699. SMC_SET_PMT_CTRL(lp, reg);
  700. spin_unlock_irqrestore(&lp->lock, flags);
  701. for (timeout = 2; timeout; timeout--) {
  702. msleep(50);
  703. spin_lock_irqsave(&lp->lock, flags);
  704. reg = SMC_GET_PMT_CTRL(lp);
  705. spin_unlock_irqrestore(&lp->lock, flags);
  706. if (!(reg & PMT_CTRL_PHY_RST_)) {
  707. /* extra delay required because the phy may
  708. * not be completed with its reset
  709. * when PHY_BCR_RESET_ is cleared. 256us
  710. * should suffice, but use 500us to be safe
  711. */
  712. udelay(500);
  713. break;
  714. }
  715. }
  716. return reg & PMT_CTRL_PHY_RST_;
  717. }
  718. /*
  719. * smc911x_phy_powerdown - powerdown phy
  720. * @dev: net device
  721. * @phy: phy address
  722. *
  723. * Power down the specified PHY
  724. */
  725. static void smc911x_phy_powerdown(struct net_device *dev, int phy)
  726. {
  727. struct smc911x_local *lp = netdev_priv(dev);
  728. unsigned int bmcr;
  729. /* Enter Link Disable state */
  730. SMC_GET_PHY_BMCR(lp, phy, bmcr);
  731. bmcr |= BMCR_PDOWN;
  732. SMC_SET_PHY_BMCR(lp, phy, bmcr);
  733. }
  734. /*
  735. * smc911x_phy_check_media - check the media status and adjust BMCR
  736. * @dev: net device
  737. * @init: set true for initialisation
  738. *
  739. * Select duplex mode depending on negotiation state. This
  740. * also updates our carrier state.
  741. */
  742. static void smc911x_phy_check_media(struct net_device *dev, int init)
  743. {
  744. struct smc911x_local *lp = netdev_priv(dev);
  745. int phyaddr = lp->mii.phy_id;
  746. unsigned int bmcr, cr;
  747. DBG(SMC_DEBUG_FUNC, "%s: --> %s\n", dev->name, __func__);
  748. if (mii_check_media(&lp->mii, netif_msg_link(lp), init)) {
  749. /* duplex state has changed */
  750. SMC_GET_PHY_BMCR(lp, phyaddr, bmcr);
  751. SMC_GET_MAC_CR(lp, cr);
  752. if (lp->mii.full_duplex) {
  753. DBG(SMC_DEBUG_MISC, "%s: Configuring for full-duplex mode\n", dev->name);
  754. bmcr |= BMCR_FULLDPLX;
  755. cr |= MAC_CR_RCVOWN_;
  756. } else {
  757. DBG(SMC_DEBUG_MISC, "%s: Configuring for half-duplex mode\n", dev->name);
  758. bmcr &= ~BMCR_FULLDPLX;
  759. cr &= ~MAC_CR_RCVOWN_;
  760. }
  761. SMC_SET_PHY_BMCR(lp, phyaddr, bmcr);
  762. SMC_SET_MAC_CR(lp, cr);
  763. }
  764. }
  765. /*
  766. * Configures the specified PHY through the MII management interface
  767. * using Autonegotiation.
  768. * Calls smc911x_phy_fixed() if the user has requested a certain config.
  769. * If RPC ANEG bit is set, the media selection is dependent purely on
  770. * the selection by the MII (either in the MII BMCR reg or the result
  771. * of autonegotiation.) If the RPC ANEG bit is cleared, the selection
  772. * is controlled by the RPC SPEED and RPC DPLX bits.
  773. */
  774. static void smc911x_phy_configure(struct work_struct *work)
  775. {
  776. struct smc911x_local *lp = container_of(work, struct smc911x_local,
  777. phy_configure);
  778. struct net_device *dev = lp->netdev;
  779. int phyaddr = lp->mii.phy_id;
  780. int my_phy_caps; /* My PHY capabilities */
  781. int my_ad_caps; /* My Advertised capabilities */
  782. int status;
  783. unsigned long flags;
  784. DBG(SMC_DEBUG_FUNC, "%s: --> %s()\n", dev->name, __func__);
  785. /*
  786. * We should not be called if phy_type is zero.
  787. */
  788. if (lp->phy_type == 0)
  789. return;
  790. if (smc911x_phy_reset(dev, phyaddr)) {
  791. printk("%s: PHY reset timed out\n", dev->name);
  792. return;
  793. }
  794. spin_lock_irqsave(&lp->lock, flags);
  795. /*
  796. * Enable PHY Interrupts (for register 18)
  797. * Interrupts listed here are enabled
  798. */
  799. SMC_SET_PHY_INT_MASK(lp, phyaddr, PHY_INT_MASK_ENERGY_ON_ |
  800. PHY_INT_MASK_ANEG_COMP_ | PHY_INT_MASK_REMOTE_FAULT_ |
  801. PHY_INT_MASK_LINK_DOWN_);
  802. /* If the user requested no auto neg, then go set his request */
  803. if (lp->mii.force_media) {
  804. smc911x_phy_fixed(dev);
  805. goto smc911x_phy_configure_exit;
  806. }
  807. /* Copy our capabilities from MII_BMSR to MII_ADVERTISE */
  808. SMC_GET_PHY_BMSR(lp, phyaddr, my_phy_caps);
  809. if (!(my_phy_caps & BMSR_ANEGCAPABLE)) {
  810. printk(KERN_INFO "Auto negotiation NOT supported\n");
  811. smc911x_phy_fixed(dev);
  812. goto smc911x_phy_configure_exit;
  813. }
  814. /* CSMA capable w/ both pauses */
  815. my_ad_caps = ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM;
  816. if (my_phy_caps & BMSR_100BASE4)
  817. my_ad_caps |= ADVERTISE_100BASE4;
  818. if (my_phy_caps & BMSR_100FULL)
  819. my_ad_caps |= ADVERTISE_100FULL;
  820. if (my_phy_caps & BMSR_100HALF)
  821. my_ad_caps |= ADVERTISE_100HALF;
  822. if (my_phy_caps & BMSR_10FULL)
  823. my_ad_caps |= ADVERTISE_10FULL;
  824. if (my_phy_caps & BMSR_10HALF)
  825. my_ad_caps |= ADVERTISE_10HALF;
  826. /* Disable capabilities not selected by our user */
  827. if (lp->ctl_rspeed != 100)
  828. my_ad_caps &= ~(ADVERTISE_100BASE4|ADVERTISE_100FULL|ADVERTISE_100HALF);
  829. if (!lp->ctl_rfduplx)
  830. my_ad_caps &= ~(ADVERTISE_100FULL|ADVERTISE_10FULL);
  831. /* Update our Auto-Neg Advertisement Register */
  832. SMC_SET_PHY_MII_ADV(lp, phyaddr, my_ad_caps);
  833. lp->mii.advertising = my_ad_caps;
  834. /*
  835. * Read the register back. Without this, it appears that when
  836. * auto-negotiation is restarted, sometimes it isn't ready and
  837. * the link does not come up.
  838. */
  839. udelay(10);
  840. SMC_GET_PHY_MII_ADV(lp, phyaddr, status);
  841. DBG(SMC_DEBUG_MISC, "%s: phy caps=0x%04x\n", dev->name, my_phy_caps);
  842. DBG(SMC_DEBUG_MISC, "%s: phy advertised caps=0x%04x\n", dev->name, my_ad_caps);
  843. /* Restart auto-negotiation process in order to advertise my caps */
  844. SMC_SET_PHY_BMCR(lp, phyaddr, BMCR_ANENABLE | BMCR_ANRESTART);
  845. smc911x_phy_check_media(dev, 1);
  846. smc911x_phy_configure_exit:
  847. spin_unlock_irqrestore(&lp->lock, flags);
  848. }
  849. /*
  850. * smc911x_phy_interrupt
  851. *
  852. * Purpose: Handle interrupts relating to PHY register 18. This is
  853. * called from the "hard" interrupt handler under our private spinlock.
  854. */
  855. static void smc911x_phy_interrupt(struct net_device *dev)
  856. {
  857. struct smc911x_local *lp = netdev_priv(dev);
  858. int phyaddr = lp->mii.phy_id;
  859. int status;
  860. DBG(SMC_DEBUG_FUNC, "%s: --> %s\n", dev->name, __func__);
  861. if (lp->phy_type == 0)
  862. return;
  863. smc911x_phy_check_media(dev, 0);
  864. /* read to clear status bits */
  865. SMC_GET_PHY_INT_SRC(lp, phyaddr,status);
  866. DBG(SMC_DEBUG_MISC, "%s: PHY interrupt status 0x%04x\n",
  867. dev->name, status & 0xffff);
  868. DBG(SMC_DEBUG_MISC, "%s: AFC_CFG 0x%08x\n",
  869. dev->name, SMC_GET_AFC_CFG(lp));
  870. }
  871. /*--- END PHY CONTROL AND CONFIGURATION-------------------------------------*/
  872. /*
  873. * This is the main routine of the driver, to handle the device when
  874. * it needs some attention.
  875. */
  876. static irqreturn_t smc911x_interrupt(int irq, void *dev_id)
  877. {
  878. struct net_device *dev = dev_id;
  879. struct smc911x_local *lp = netdev_priv(dev);
  880. unsigned int status, mask, timeout;
  881. unsigned int rx_overrun=0, cr, pkts;
  882. unsigned long flags;
  883. DBG(SMC_DEBUG_FUNC, "%s: --> %s\n", dev->name, __func__);
  884. spin_lock_irqsave(&lp->lock, flags);
  885. /* Spurious interrupt check */
  886. if ((SMC_GET_IRQ_CFG(lp) & (INT_CFG_IRQ_INT_ | INT_CFG_IRQ_EN_)) !=
  887. (INT_CFG_IRQ_INT_ | INT_CFG_IRQ_EN_)) {
  888. spin_unlock_irqrestore(&lp->lock, flags);
  889. return IRQ_NONE;
  890. }
  891. mask = SMC_GET_INT_EN(lp);
  892. SMC_SET_INT_EN(lp, 0);
  893. /* set a timeout value, so I don't stay here forever */
  894. timeout = 8;
  895. do {
  896. status = SMC_GET_INT(lp);
  897. DBG(SMC_DEBUG_MISC, "%s: INT 0x%08x MASK 0x%08x OUTSIDE MASK 0x%08x\n",
  898. dev->name, status, mask, status & ~mask);
  899. status &= mask;
  900. if (!status)
  901. break;
  902. /* Handle SW interrupt condition */
  903. if (status & INT_STS_SW_INT_) {
  904. SMC_ACK_INT(lp, INT_STS_SW_INT_);
  905. mask &= ~INT_EN_SW_INT_EN_;
  906. }
  907. /* Handle various error conditions */
  908. if (status & INT_STS_RXE_) {
  909. SMC_ACK_INT(lp, INT_STS_RXE_);
  910. dev->stats.rx_errors++;
  911. }
  912. if (status & INT_STS_RXDFH_INT_) {
  913. SMC_ACK_INT(lp, INT_STS_RXDFH_INT_);
  914. dev->stats.rx_dropped+=SMC_GET_RX_DROP(lp);
  915. }
  916. /* Undocumented interrupt-what is the right thing to do here? */
  917. if (status & INT_STS_RXDF_INT_) {
  918. SMC_ACK_INT(lp, INT_STS_RXDF_INT_);
  919. }
  920. /* Rx Data FIFO exceeds set level */
  921. if (status & INT_STS_RDFL_) {
  922. if (IS_REV_A(lp->revision)) {
  923. rx_overrun=1;
  924. SMC_GET_MAC_CR(lp, cr);
  925. cr &= ~MAC_CR_RXEN_;
  926. SMC_SET_MAC_CR(lp, cr);
  927. DBG(SMC_DEBUG_RX, "%s: RX overrun\n", dev->name);
  928. dev->stats.rx_errors++;
  929. dev->stats.rx_fifo_errors++;
  930. }
  931. SMC_ACK_INT(lp, INT_STS_RDFL_);
  932. }
  933. if (status & INT_STS_RDFO_) {
  934. if (!IS_REV_A(lp->revision)) {
  935. SMC_GET_MAC_CR(lp, cr);
  936. cr &= ~MAC_CR_RXEN_;
  937. SMC_SET_MAC_CR(lp, cr);
  938. rx_overrun=1;
  939. DBG(SMC_DEBUG_RX, "%s: RX overrun\n", dev->name);
  940. dev->stats.rx_errors++;
  941. dev->stats.rx_fifo_errors++;
  942. }
  943. SMC_ACK_INT(lp, INT_STS_RDFO_);
  944. }
  945. /* Handle receive condition */
  946. if ((status & INT_STS_RSFL_) || rx_overrun) {
  947. unsigned int fifo;
  948. DBG(SMC_DEBUG_RX, "%s: RX irq\n", dev->name);
  949. fifo = SMC_GET_RX_FIFO_INF(lp);
  950. pkts = (fifo & RX_FIFO_INF_RXSUSED_) >> 16;
  951. DBG(SMC_DEBUG_RX, "%s: Rx FIFO pkts %d, bytes %d\n",
  952. dev->name, pkts, fifo & 0xFFFF );
  953. if (pkts != 0) {
  954. #ifdef SMC_USE_DMA
  955. unsigned int fifo;
  956. if (lp->rxdma_active){
  957. DBG(SMC_DEBUG_RX | SMC_DEBUG_DMA,
  958. "%s: RX DMA active\n", dev->name);
  959. /* The DMA is already running so up the IRQ threshold */
  960. fifo = SMC_GET_FIFO_INT(lp) & ~0xFF;
  961. fifo |= pkts & 0xFF;
  962. DBG(SMC_DEBUG_RX,
  963. "%s: Setting RX stat FIFO threshold to %d\n",
  964. dev->name, fifo & 0xff);
  965. SMC_SET_FIFO_INT(lp, fifo);
  966. } else
  967. #endif
  968. smc911x_rcv(dev);
  969. }
  970. SMC_ACK_INT(lp, INT_STS_RSFL_);
  971. }
  972. /* Handle transmit FIFO available */
  973. if (status & INT_STS_TDFA_) {
  974. DBG(SMC_DEBUG_TX, "%s: TX data FIFO space available irq\n", dev->name);
  975. SMC_SET_FIFO_TDA(lp, 0xFF);
  976. lp->tx_throttle = 0;
  977. #ifdef SMC_USE_DMA
  978. if (!lp->txdma_active)
  979. #endif
  980. netif_wake_queue(dev);
  981. SMC_ACK_INT(lp, INT_STS_TDFA_);
  982. }
  983. /* Handle transmit done condition */
  984. #if 1
  985. if (status & (INT_STS_TSFL_ | INT_STS_GPT_INT_)) {
  986. DBG(SMC_DEBUG_TX | SMC_DEBUG_MISC,
  987. "%s: Tx stat FIFO limit (%d) /GPT irq\n",
  988. dev->name, (SMC_GET_FIFO_INT(lp) & 0x00ff0000) >> 16);
  989. smc911x_tx(dev);
  990. SMC_SET_GPT_CFG(lp, GPT_CFG_TIMER_EN_ | 10000);
  991. SMC_ACK_INT(lp, INT_STS_TSFL_);
  992. SMC_ACK_INT(lp, INT_STS_TSFL_ | INT_STS_GPT_INT_);
  993. }
  994. #else
  995. if (status & INT_STS_TSFL_) {
  996. DBG(SMC_DEBUG_TX, "%s: TX status FIFO limit (%d) irq \n", dev->name, );
  997. smc911x_tx(dev);
  998. SMC_ACK_INT(lp, INT_STS_TSFL_);
  999. }
  1000. if (status & INT_STS_GPT_INT_) {
  1001. DBG(SMC_DEBUG_RX, "%s: IRQ_CFG 0x%08x FIFO_INT 0x%08x RX_CFG 0x%08x\n",
  1002. dev->name,
  1003. SMC_GET_IRQ_CFG(lp),
  1004. SMC_GET_FIFO_INT(lp),
  1005. SMC_GET_RX_CFG(lp));
  1006. DBG(SMC_DEBUG_RX, "%s: Rx Stat FIFO Used 0x%02x "
  1007. "Data FIFO Used 0x%04x Stat FIFO 0x%08x\n",
  1008. dev->name,
  1009. (SMC_GET_RX_FIFO_INF(lp) & 0x00ff0000) >> 16,
  1010. SMC_GET_RX_FIFO_INF(lp) & 0xffff,
  1011. SMC_GET_RX_STS_FIFO_PEEK(lp));
  1012. SMC_SET_GPT_CFG(lp, GPT_CFG_TIMER_EN_ | 10000);
  1013. SMC_ACK_INT(lp, INT_STS_GPT_INT_);
  1014. }
  1015. #endif
  1016. /* Handle PHY interrupt condition */
  1017. if (status & INT_STS_PHY_INT_) {
  1018. DBG(SMC_DEBUG_MISC, "%s: PHY irq\n", dev->name);
  1019. smc911x_phy_interrupt(dev);
  1020. SMC_ACK_INT(lp, INT_STS_PHY_INT_);
  1021. }
  1022. } while (--timeout);
  1023. /* restore mask state */
  1024. SMC_SET_INT_EN(lp, mask);
  1025. DBG(SMC_DEBUG_MISC, "%s: Interrupt done (%d loops)\n",
  1026. dev->name, 8-timeout);
  1027. spin_unlock_irqrestore(&lp->lock, flags);
  1028. return IRQ_HANDLED;
  1029. }
  1030. #ifdef SMC_USE_DMA
  1031. static void
  1032. smc911x_tx_dma_irq(int dma, void *data)
  1033. {
  1034. struct net_device *dev = (struct net_device *)data;
  1035. struct smc911x_local *lp = netdev_priv(dev);
  1036. struct sk_buff *skb = lp->current_tx_skb;
  1037. unsigned long flags;
  1038. DBG(SMC_DEBUG_FUNC, "%s: --> %s\n", dev->name, __func__);
  1039. DBG(SMC_DEBUG_TX | SMC_DEBUG_DMA, "%s: TX DMA irq handler\n", dev->name);
  1040. /* Clear the DMA interrupt sources */
  1041. SMC_DMA_ACK_IRQ(dev, dma);
  1042. BUG_ON(skb == NULL);
  1043. dma_unmap_single(NULL, tx_dmabuf, tx_dmalen, DMA_TO_DEVICE);
  1044. dev->trans_start = jiffies;
  1045. dev_kfree_skb_irq(skb);
  1046. lp->current_tx_skb = NULL;
  1047. if (lp->pending_tx_skb != NULL)
  1048. smc911x_hardware_send_pkt(dev);
  1049. else {
  1050. DBG(SMC_DEBUG_TX | SMC_DEBUG_DMA,
  1051. "%s: No pending Tx packets. DMA disabled\n", dev->name);
  1052. spin_lock_irqsave(&lp->lock, flags);
  1053. lp->txdma_active = 0;
  1054. if (!lp->tx_throttle) {
  1055. netif_wake_queue(dev);
  1056. }
  1057. spin_unlock_irqrestore(&lp->lock, flags);
  1058. }
  1059. DBG(SMC_DEBUG_TX | SMC_DEBUG_DMA,
  1060. "%s: TX DMA irq completed\n", dev->name);
  1061. }
  1062. static void
  1063. smc911x_rx_dma_irq(int dma, void *data)
  1064. {
  1065. struct net_device *dev = (struct net_device *)data;
  1066. unsigned long ioaddr = dev->base_addr;
  1067. struct smc911x_local *lp = netdev_priv(dev);
  1068. struct sk_buff *skb = lp->current_rx_skb;
  1069. unsigned long flags;
  1070. unsigned int pkts;
  1071. DBG(SMC_DEBUG_FUNC, "%s: --> %s\n", dev->name, __func__);
  1072. DBG(SMC_DEBUG_RX | SMC_DEBUG_DMA, "%s: RX DMA irq handler\n", dev->name);
  1073. /* Clear the DMA interrupt sources */
  1074. SMC_DMA_ACK_IRQ(dev, dma);
  1075. dma_unmap_single(NULL, rx_dmabuf, rx_dmalen, DMA_FROM_DEVICE);
  1076. BUG_ON(skb == NULL);
  1077. lp->current_rx_skb = NULL;
  1078. PRINT_PKT(skb->data, skb->len);
  1079. skb->protocol = eth_type_trans(skb, dev);
  1080. dev->stats.rx_packets++;
  1081. dev->stats.rx_bytes += skb->len;
  1082. netif_rx(skb);
  1083. spin_lock_irqsave(&lp->lock, flags);
  1084. pkts = (SMC_GET_RX_FIFO_INF(lp) & RX_FIFO_INF_RXSUSED_) >> 16;
  1085. if (pkts != 0) {
  1086. smc911x_rcv(dev);
  1087. }else {
  1088. lp->rxdma_active = 0;
  1089. }
  1090. spin_unlock_irqrestore(&lp->lock, flags);
  1091. DBG(SMC_DEBUG_RX | SMC_DEBUG_DMA,
  1092. "%s: RX DMA irq completed. DMA RX FIFO PKTS %d\n",
  1093. dev->name, pkts);
  1094. }
  1095. #endif /* SMC_USE_DMA */
  1096. #ifdef CONFIG_NET_POLL_CONTROLLER
  1097. /*
  1098. * Polling receive - used by netconsole and other diagnostic tools
  1099. * to allow network i/o with interrupts disabled.
  1100. */
  1101. static void smc911x_poll_controller(struct net_device *dev)
  1102. {
  1103. disable_irq(dev->irq);
  1104. smc911x_interrupt(dev->irq, dev);
  1105. enable_irq(dev->irq);
  1106. }
  1107. #endif
  1108. /* Our watchdog timed out. Called by the networking layer */
  1109. static void smc911x_timeout(struct net_device *dev)
  1110. {
  1111. struct smc911x_local *lp = netdev_priv(dev);
  1112. int status, mask;
  1113. unsigned long flags;
  1114. DBG(SMC_DEBUG_FUNC, "%s: --> %s\n", dev->name, __func__);
  1115. spin_lock_irqsave(&lp->lock, flags);
  1116. status = SMC_GET_INT(lp);
  1117. mask = SMC_GET_INT_EN(lp);
  1118. spin_unlock_irqrestore(&lp->lock, flags);
  1119. DBG(SMC_DEBUG_MISC, "%s: INT 0x%02x MASK 0x%02x \n",
  1120. dev->name, status, mask);
  1121. /* Dump the current TX FIFO contents and restart */
  1122. mask = SMC_GET_TX_CFG(lp);
  1123. SMC_SET_TX_CFG(lp, mask | TX_CFG_TXS_DUMP_ | TX_CFG_TXD_DUMP_);
  1124. /*
  1125. * Reconfiguring the PHY doesn't seem like a bad idea here, but
  1126. * smc911x_phy_configure() calls msleep() which calls schedule_timeout()
  1127. * which calls schedule(). Hence we use a work queue.
  1128. */
  1129. if (lp->phy_type != 0)
  1130. schedule_work(&lp->phy_configure);
  1131. /* We can accept TX packets again */
  1132. dev->trans_start = jiffies;
  1133. netif_wake_queue(dev);
  1134. }
  1135. /*
  1136. * This routine will, depending on the values passed to it,
  1137. * either make it accept multicast packets, go into
  1138. * promiscuous mode (for TCPDUMP and cousins) or accept
  1139. * a select set of multicast packets
  1140. */
  1141. static void smc911x_set_multicast_list(struct net_device *dev)
  1142. {
  1143. struct smc911x_local *lp = netdev_priv(dev);
  1144. unsigned int multicast_table[2];
  1145. unsigned int mcr, update_multicast = 0;
  1146. unsigned long flags;
  1147. DBG(SMC_DEBUG_FUNC, "%s: --> %s\n", dev->name, __func__);
  1148. spin_lock_irqsave(&lp->lock, flags);
  1149. SMC_GET_MAC_CR(lp, mcr);
  1150. spin_unlock_irqrestore(&lp->lock, flags);
  1151. if (dev->flags & IFF_PROMISC) {
  1152. DBG(SMC_DEBUG_MISC, "%s: RCR_PRMS\n", dev->name);
  1153. mcr |= MAC_CR_PRMS_;
  1154. }
  1155. /*
  1156. * Here, I am setting this to accept all multicast packets.
  1157. * I don't need to zero the multicast table, because the flag is
  1158. * checked before the table is
  1159. */
  1160. else if (dev->flags & IFF_ALLMULTI || dev->mc_count > 16) {
  1161. DBG(SMC_DEBUG_MISC, "%s: RCR_ALMUL\n", dev->name);
  1162. mcr |= MAC_CR_MCPAS_;
  1163. }
  1164. /*
  1165. * This sets the internal hardware table to filter out unwanted
  1166. * multicast packets before they take up memory.
  1167. *
  1168. * The SMC chip uses a hash table where the high 6 bits of the CRC of
  1169. * address are the offset into the table. If that bit is 1, then the
  1170. * multicast packet is accepted. Otherwise, it's dropped silently.
  1171. *
  1172. * To use the 6 bits as an offset into the table, the high 1 bit is
  1173. * the number of the 32 bit register, while the low 5 bits are the bit
  1174. * within that register.
  1175. */
  1176. else if (dev->mc_count) {
  1177. int i;
  1178. struct dev_mc_list *cur_addr;
  1179. /* Set the Hash perfec mode */
  1180. mcr |= MAC_CR_HPFILT_;
  1181. /* start with a table of all zeros: reject all */
  1182. memset(multicast_table, 0, sizeof(multicast_table));
  1183. cur_addr = dev->mc_list;
  1184. for (i = 0; i < dev->mc_count; i++, cur_addr = cur_addr->next) {
  1185. u32 position;
  1186. /* do we have a pointer here? */
  1187. if (!cur_addr)
  1188. break;
  1189. /* make sure this is a multicast address -
  1190. shouldn't this be a given if we have it here ? */
  1191. if (!(*cur_addr->dmi_addr & 1))
  1192. continue;
  1193. /* upper 6 bits are used as hash index */
  1194. position = ether_crc(ETH_ALEN, cur_addr->dmi_addr)>>26;
  1195. multicast_table[position>>5] |= 1 << (position&0x1f);
  1196. }
  1197. /* be sure I get rid of flags I might have set */
  1198. mcr &= ~(MAC_CR_PRMS_ | MAC_CR_MCPAS_);
  1199. /* now, the table can be loaded into the chipset */
  1200. update_multicast = 1;
  1201. } else {
  1202. DBG(SMC_DEBUG_MISC, "%s: ~(MAC_CR_PRMS_|MAC_CR_MCPAS_)\n",
  1203. dev->name);
  1204. mcr &= ~(MAC_CR_PRMS_ | MAC_CR_MCPAS_);
  1205. /*
  1206. * since I'm disabling all multicast entirely, I need to
  1207. * clear the multicast list
  1208. */
  1209. memset(multicast_table, 0, sizeof(multicast_table));
  1210. update_multicast = 1;
  1211. }
  1212. spin_lock_irqsave(&lp->lock, flags);
  1213. SMC_SET_MAC_CR(lp, mcr);
  1214. if (update_multicast) {
  1215. DBG(SMC_DEBUG_MISC,
  1216. "%s: update mcast hash table 0x%08x 0x%08x\n",
  1217. dev->name, multicast_table[0], multicast_table[1]);
  1218. SMC_SET_HASHL(lp, multicast_table[0]);
  1219. SMC_SET_HASHH(lp, multicast_table[1]);
  1220. }
  1221. spin_unlock_irqrestore(&lp->lock, flags);
  1222. }
  1223. /*
  1224. * Open and Initialize the board
  1225. *
  1226. * Set up everything, reset the card, etc..
  1227. */
  1228. static int
  1229. smc911x_open(struct net_device *dev)
  1230. {
  1231. struct smc911x_local *lp = netdev_priv(dev);
  1232. DBG(SMC_DEBUG_FUNC, "%s: --> %s\n", dev->name, __func__);
  1233. /*
  1234. * Check that the address is valid. If its not, refuse
  1235. * to bring the device up. The user must specify an
  1236. * address using ifconfig eth0 hw ether xx:xx:xx:xx:xx:xx
  1237. */
  1238. if (!is_valid_ether_addr(dev->dev_addr)) {
  1239. PRINTK("%s: no valid ethernet hw addr\n", __func__);
  1240. return -EINVAL;
  1241. }
  1242. /* reset the hardware */
  1243. smc911x_reset(dev);
  1244. /* Configure the PHY, initialize the link state */
  1245. smc911x_phy_configure(&lp->phy_configure);
  1246. /* Turn on Tx + Rx */
  1247. smc911x_enable(dev);
  1248. netif_start_queue(dev);
  1249. return 0;
  1250. }
  1251. /*
  1252. * smc911x_close
  1253. *
  1254. * this makes the board clean up everything that it can
  1255. * and not talk to the outside world. Caused by
  1256. * an 'ifconfig ethX down'
  1257. */
  1258. static int smc911x_close(struct net_device *dev)
  1259. {
  1260. struct smc911x_local *lp = netdev_priv(dev);
  1261. DBG(SMC_DEBUG_FUNC, "%s: --> %s\n", dev->name, __func__);
  1262. netif_stop_queue(dev);
  1263. netif_carrier_off(dev);
  1264. /* clear everything */
  1265. smc911x_shutdown(dev);
  1266. if (lp->phy_type != 0) {
  1267. /* We need to ensure that no calls to
  1268. * smc911x_phy_configure are pending.
  1269. */
  1270. cancel_work_sync(&lp->phy_configure);
  1271. smc911x_phy_powerdown(dev, lp->mii.phy_id);
  1272. }
  1273. if (lp->pending_tx_skb) {
  1274. dev_kfree_skb(lp->pending_tx_skb);
  1275. lp->pending_tx_skb = NULL;
  1276. }
  1277. return 0;
  1278. }
  1279. /*
  1280. * Ethtool support
  1281. */
  1282. static int
  1283. smc911x_ethtool_getsettings(struct net_device *dev, struct ethtool_cmd *cmd)
  1284. {
  1285. struct smc911x_local *lp = netdev_priv(dev);
  1286. int ret, status;
  1287. unsigned long flags;
  1288. DBG(SMC_DEBUG_FUNC, "%s: --> %s\n", dev->name, __func__);
  1289. cmd->maxtxpkt = 1;
  1290. cmd->maxrxpkt = 1;
  1291. if (lp->phy_type != 0) {
  1292. spin_lock_irqsave(&lp->lock, flags);
  1293. ret = mii_ethtool_gset(&lp->mii, cmd);
  1294. spin_unlock_irqrestore(&lp->lock, flags);
  1295. } else {
  1296. cmd->supported = SUPPORTED_10baseT_Half |
  1297. SUPPORTED_10baseT_Full |
  1298. SUPPORTED_TP | SUPPORTED_AUI;
  1299. if (lp->ctl_rspeed == 10)
  1300. cmd->speed = SPEED_10;
  1301. else if (lp->ctl_rspeed == 100)
  1302. cmd->speed = SPEED_100;
  1303. cmd->autoneg = AUTONEG_DISABLE;
  1304. if (lp->mii.phy_id==1)
  1305. cmd->transceiver = XCVR_INTERNAL;
  1306. else
  1307. cmd->transceiver = XCVR_EXTERNAL;
  1308. cmd->port = 0;
  1309. SMC_GET_PHY_SPECIAL(lp, lp->mii.phy_id, status);
  1310. cmd->duplex =
  1311. (status & (PHY_SPECIAL_SPD_10FULL_ | PHY_SPECIAL_SPD_100FULL_)) ?
  1312. DUPLEX_FULL : DUPLEX_HALF;
  1313. ret = 0;
  1314. }
  1315. return ret;
  1316. }
  1317. static int
  1318. smc911x_ethtool_setsettings(struct net_device *dev, struct ethtool_cmd *cmd)
  1319. {
  1320. struct smc911x_local *lp = netdev_priv(dev);
  1321. int ret;
  1322. unsigned long flags;
  1323. if (lp->phy_type != 0) {
  1324. spin_lock_irqsave(&lp->lock, flags);
  1325. ret = mii_ethtool_sset(&lp->mii, cmd);
  1326. spin_unlock_irqrestore(&lp->lock, flags);
  1327. } else {
  1328. if (cmd->autoneg != AUTONEG_DISABLE ||
  1329. cmd->speed != SPEED_10 ||
  1330. (cmd->duplex != DUPLEX_HALF && cmd->duplex != DUPLEX_FULL) ||
  1331. (cmd->port != PORT_TP && cmd->port != PORT_AUI))
  1332. return -EINVAL;
  1333. lp->ctl_rfduplx = cmd->duplex == DUPLEX_FULL;
  1334. ret = 0;
  1335. }
  1336. return ret;
  1337. }
  1338. static void
  1339. smc911x_ethtool_getdrvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
  1340. {
  1341. strncpy(info->driver, CARDNAME, sizeof(info->driver));
  1342. strncpy(info->version, version, sizeof(info->version));
  1343. strncpy(info->bus_info, dev->dev.parent->bus_id, sizeof(info->bus_info));
  1344. }
  1345. static int smc911x_ethtool_nwayreset(struct net_device *dev)
  1346. {
  1347. struct smc911x_local *lp = netdev_priv(dev);
  1348. int ret = -EINVAL;
  1349. unsigned long flags;
  1350. if (lp->phy_type != 0) {
  1351. spin_lock_irqsave(&lp->lock, flags);
  1352. ret = mii_nway_restart(&lp->mii);
  1353. spin_unlock_irqrestore(&lp->lock, flags);
  1354. }
  1355. return ret;
  1356. }
  1357. static u32 smc911x_ethtool_getmsglevel(struct net_device *dev)
  1358. {
  1359. struct smc911x_local *lp = netdev_priv(dev);
  1360. return lp->msg_enable;
  1361. }
  1362. static void smc911x_ethtool_setmsglevel(struct net_device *dev, u32 level)
  1363. {
  1364. struct smc911x_local *lp = netdev_priv(dev);
  1365. lp->msg_enable = level;
  1366. }
  1367. static int smc911x_ethtool_getregslen(struct net_device *dev)
  1368. {
  1369. /* System regs + MAC regs + PHY regs */
  1370. return (((E2P_CMD - ID_REV)/4 + 1) +
  1371. (WUCSR - MAC_CR)+1 + 32) * sizeof(u32);
  1372. }
  1373. static void smc911x_ethtool_getregs(struct net_device *dev,
  1374. struct ethtool_regs* regs, void *buf)
  1375. {
  1376. struct smc911x_local *lp = netdev_priv(dev);
  1377. unsigned long flags;
  1378. u32 reg,i,j=0;
  1379. u32 *data = (u32*)buf;
  1380. regs->version = lp->version;
  1381. for(i=ID_REV;i<=E2P_CMD;i+=4) {
  1382. data[j++] = SMC_inl(lp, i);
  1383. }
  1384. for(i=MAC_CR;i<=WUCSR;i++) {
  1385. spin_lock_irqsave(&lp->lock, flags);
  1386. SMC_GET_MAC_CSR(lp, i, reg);
  1387. spin_unlock_irqrestore(&lp->lock, flags);
  1388. data[j++] = reg;
  1389. }
  1390. for(i=0;i<=31;i++) {
  1391. spin_lock_irqsave(&lp->lock, flags);
  1392. SMC_GET_MII(lp, i, lp->mii.phy_id, reg);
  1393. spin_unlock_irqrestore(&lp->lock, flags);
  1394. data[j++] = reg & 0xFFFF;
  1395. }
  1396. }
  1397. static int smc911x_ethtool_wait_eeprom_ready(struct net_device *dev)
  1398. {
  1399. struct smc911x_local *lp = netdev_priv(dev);
  1400. unsigned int timeout;
  1401. int e2p_cmd;
  1402. e2p_cmd = SMC_GET_E2P_CMD(lp);
  1403. for(timeout=10;(e2p_cmd & E2P_CMD_EPC_BUSY_) && timeout; timeout--) {
  1404. if (e2p_cmd & E2P_CMD_EPC_TIMEOUT_) {
  1405. PRINTK("%s: %s timeout waiting for EEPROM to respond\n",
  1406. dev->name, __func__);
  1407. return -EFAULT;
  1408. }
  1409. mdelay(1);
  1410. e2p_cmd = SMC_GET_E2P_CMD(lp);
  1411. }
  1412. if (timeout == 0) {
  1413. PRINTK("%s: %s timeout waiting for EEPROM CMD not busy\n",
  1414. dev->name, __func__);
  1415. return -ETIMEDOUT;
  1416. }
  1417. return 0;
  1418. }
  1419. static inline int smc911x_ethtool_write_eeprom_cmd(struct net_device *dev,
  1420. int cmd, int addr)
  1421. {
  1422. struct smc911x_local *lp = netdev_priv(dev);
  1423. int ret;
  1424. if ((ret = smc911x_ethtool_wait_eeprom_ready(dev))!=0)
  1425. return ret;
  1426. SMC_SET_E2P_CMD(lp, E2P_CMD_EPC_BUSY_ |
  1427. ((cmd) & (0x7<<28)) |
  1428. ((addr) & 0xFF));
  1429. return 0;
  1430. }
  1431. static inline int smc911x_ethtool_read_eeprom_byte(struct net_device *dev,
  1432. u8 *data)
  1433. {
  1434. struct smc911x_local *lp = netdev_priv(dev);
  1435. int ret;
  1436. if ((ret = smc911x_ethtool_wait_eeprom_ready(dev))!=0)
  1437. return ret;
  1438. *data = SMC_GET_E2P_DATA(lp);
  1439. return 0;
  1440. }
  1441. static inline int smc911x_ethtool_write_eeprom_byte(struct net_device *dev,
  1442. u8 data)
  1443. {
  1444. struct smc911x_local *lp = netdev_priv(dev);
  1445. int ret;
  1446. if ((ret = smc911x_ethtool_wait_eeprom_ready(dev))!=0)
  1447. return ret;
  1448. SMC_SET_E2P_DATA(lp, data);
  1449. return 0;
  1450. }
  1451. static int smc911x_ethtool_geteeprom(struct net_device *dev,
  1452. struct ethtool_eeprom *eeprom, u8 *data)
  1453. {
  1454. u8 eebuf[SMC911X_EEPROM_LEN];
  1455. int i, ret;
  1456. for(i=0;i<SMC911X_EEPROM_LEN;i++) {
  1457. if ((ret=smc911x_ethtool_write_eeprom_cmd(dev, E2P_CMD_EPC_CMD_READ_, i ))!=0)
  1458. return ret;
  1459. if ((ret=smc911x_ethtool_read_eeprom_byte(dev, &eebuf[i]))!=0)
  1460. return ret;
  1461. }
  1462. memcpy(data, eebuf+eeprom->offset, eeprom->len);
  1463. return 0;
  1464. }
  1465. static int smc911x_ethtool_seteeprom(struct net_device *dev,
  1466. struct ethtool_eeprom *eeprom, u8 *data)
  1467. {
  1468. int i, ret;
  1469. /* Enable erase */
  1470. if ((ret=smc911x_ethtool_write_eeprom_cmd(dev, E2P_CMD_EPC_CMD_EWEN_, 0 ))!=0)
  1471. return ret;
  1472. for(i=eeprom->offset;i<(eeprom->offset+eeprom->len);i++) {
  1473. /* erase byte */
  1474. if ((ret=smc911x_ethtool_write_eeprom_cmd(dev, E2P_CMD_EPC_CMD_ERASE_, i ))!=0)
  1475. return ret;
  1476. /* write byte */
  1477. if ((ret=smc911x_ethtool_write_eeprom_byte(dev, *data))!=0)
  1478. return ret;
  1479. if ((ret=smc911x_ethtool_write_eeprom_cmd(dev, E2P_CMD_EPC_CMD_WRITE_, i ))!=0)
  1480. return ret;
  1481. }
  1482. return 0;
  1483. }
  1484. static int smc911x_ethtool_geteeprom_len(struct net_device *dev)
  1485. {
  1486. return SMC911X_EEPROM_LEN;
  1487. }
  1488. static const struct ethtool_ops smc911x_ethtool_ops = {
  1489. .get_settings = smc911x_ethtool_getsettings,
  1490. .set_settings = smc911x_ethtool_setsettings,
  1491. .get_drvinfo = smc911x_ethtool_getdrvinfo,
  1492. .get_msglevel = smc911x_ethtool_getmsglevel,
  1493. .set_msglevel = smc911x_ethtool_setmsglevel,
  1494. .nway_reset = smc911x_ethtool_nwayreset,
  1495. .get_link = ethtool_op_get_link,
  1496. .get_regs_len = smc911x_ethtool_getregslen,
  1497. .get_regs = smc911x_ethtool_getregs,
  1498. .get_eeprom_len = smc911x_ethtool_geteeprom_len,
  1499. .get_eeprom = smc911x_ethtool_geteeprom,
  1500. .set_eeprom = smc911x_ethtool_seteeprom,
  1501. };
  1502. /*
  1503. * smc911x_findirq
  1504. *
  1505. * This routine has a simple purpose -- make the SMC chip generate an
  1506. * interrupt, so an auto-detect routine can detect it, and find the IRQ,
  1507. */
  1508. static int __devinit smc911x_findirq(struct net_device *dev)
  1509. {
  1510. struct smc911x_local *lp = netdev_priv(dev);
  1511. int timeout = 20;
  1512. unsigned long cookie;
  1513. DBG(SMC_DEBUG_FUNC, "--> %s\n", __func__);
  1514. cookie = probe_irq_on();
  1515. /*
  1516. * Force a SW interrupt
  1517. */
  1518. SMC_SET_INT_EN(lp, INT_EN_SW_INT_EN_);
  1519. /*
  1520. * Wait until positive that the interrupt has been generated
  1521. */
  1522. do {
  1523. int int_status;
  1524. udelay(10);
  1525. int_status = SMC_GET_INT_EN(lp);
  1526. if (int_status & INT_EN_SW_INT_EN_)
  1527. break; /* got the interrupt */
  1528. } while (--timeout);
  1529. /*
  1530. * there is really nothing that I can do here if timeout fails,
  1531. * as autoirq_report will return a 0 anyway, which is what I
  1532. * want in this case. Plus, the clean up is needed in both
  1533. * cases.
  1534. */
  1535. /* and disable all interrupts again */
  1536. SMC_SET_INT_EN(lp, 0);
  1537. /* and return what I found */
  1538. return probe_irq_off(cookie);
  1539. }
  1540. /*
  1541. * Function: smc911x_probe(unsigned long ioaddr)
  1542. *
  1543. * Purpose:
  1544. * Tests to see if a given ioaddr points to an SMC911x chip.
  1545. * Returns a 0 on success
  1546. *
  1547. * Algorithm:
  1548. * (1) see if the endian word is OK
  1549. * (1) see if I recognize the chip ID in the appropriate register
  1550. *
  1551. * Here I do typical initialization tasks.
  1552. *
  1553. * o Initialize the structure if needed
  1554. * o print out my vanity message if not done so already
  1555. * o print out what type of hardware is detected
  1556. * o print out the ethernet address
  1557. * o find the IRQ
  1558. * o set up my private data
  1559. * o configure the dev structure with my subroutines
  1560. * o actually GRAB the irq.
  1561. * o GRAB the region
  1562. */
  1563. static int __devinit smc911x_probe(struct net_device *dev)
  1564. {
  1565. struct smc911x_local *lp = netdev_priv(dev);
  1566. int i, retval;
  1567. unsigned int val, chip_id, revision;
  1568. const char *version_string;
  1569. unsigned long irq_flags;
  1570. DBG(SMC_DEBUG_FUNC, "%s: --> %s\n", dev->name, __func__);
  1571. /* First, see if the endian word is recognized */
  1572. val = SMC_GET_BYTE_TEST(lp);
  1573. DBG(SMC_DEBUG_MISC, "%s: endian probe returned 0x%04x\n", CARDNAME, val);
  1574. if (val != 0x87654321) {
  1575. printk(KERN_ERR "Invalid chip endian 0x%08x\n",val);
  1576. retval = -ENODEV;
  1577. goto err_out;
  1578. }
  1579. /*
  1580. * check if the revision register is something that I
  1581. * recognize. These might need to be added to later,
  1582. * as future revisions could be added.
  1583. */
  1584. chip_id = SMC_GET_PN(lp);
  1585. DBG(SMC_DEBUG_MISC, "%s: id probe returned 0x%04x\n", CARDNAME, chip_id);
  1586. for(i=0;chip_ids[i].id != 0; i++) {
  1587. if (chip_ids[i].id == chip_id) break;
  1588. }
  1589. if (!chip_ids[i].id) {
  1590. printk(KERN_ERR "Unknown chip ID %04x\n", chip_id);
  1591. retval = -ENODEV;
  1592. goto err_out;
  1593. }
  1594. version_string = chip_ids[i].name;
  1595. revision = SMC_GET_REV(lp);
  1596. DBG(SMC_DEBUG_MISC, "%s: revision = 0x%04x\n", CARDNAME, revision);
  1597. /* At this point I'll assume that the chip is an SMC911x. */
  1598. DBG(SMC_DEBUG_MISC, "%s: Found a %s\n", CARDNAME, chip_ids[i].name);
  1599. /* Validate the TX FIFO size requested */
  1600. if ((tx_fifo_kb < 2) || (tx_fifo_kb > 14)) {
  1601. printk(KERN_ERR "Invalid TX FIFO size requested %d\n", tx_fifo_kb);
  1602. retval = -EINVAL;
  1603. goto err_out;
  1604. }
  1605. /* fill in some of the fields */
  1606. lp->version = chip_ids[i].id;
  1607. lp->revision = revision;
  1608. lp->tx_fifo_kb = tx_fifo_kb;
  1609. /* Reverse calculate the RX FIFO size from the TX */
  1610. lp->tx_fifo_size=(lp->tx_fifo_kb<<10) - 512;
  1611. lp->rx_fifo_size= ((0x4000 - 512 - lp->tx_fifo_size) / 16) * 15;
  1612. /* Set the automatic flow control values */
  1613. switch(lp->tx_fifo_kb) {
  1614. /*
  1615. * AFC_HI is about ((Rx Data Fifo Size)*2/3)/64
  1616. * AFC_LO is AFC_HI/2
  1617. * BACK_DUR is about 5uS*(AFC_LO) rounded down
  1618. */
  1619. case 2:/* 13440 Rx Data Fifo Size */
  1620. lp->afc_cfg=0x008C46AF;break;
  1621. case 3:/* 12480 Rx Data Fifo Size */
  1622. lp->afc_cfg=0x0082419F;break;
  1623. case 4:/* 11520 Rx Data Fifo Size */
  1624. lp->afc_cfg=0x00783C9F;break;
  1625. case 5:/* 10560 Rx Data Fifo Size */
  1626. lp->afc_cfg=0x006E374F;break;
  1627. case 6:/* 9600 Rx Data Fifo Size */
  1628. lp->afc_cfg=0x0064328F;break;
  1629. case 7:/* 8640 Rx Data Fifo Size */
  1630. lp->afc_cfg=0x005A2D7F;break;
  1631. case 8:/* 7680 Rx Data Fifo Size */
  1632. lp->afc_cfg=0x0050287F;break;
  1633. case 9:/* 6720 Rx Data Fifo Size */
  1634. lp->afc_cfg=0x0046236F;break;
  1635. case 10:/* 5760 Rx Data Fifo Size */
  1636. lp->afc_cfg=0x003C1E6F;break;
  1637. case 11:/* 4800 Rx Data Fifo Size */
  1638. lp->afc_cfg=0x0032195F;break;
  1639. /*
  1640. * AFC_HI is ~1520 bytes less than RX Data Fifo Size
  1641. * AFC_LO is AFC_HI/2
  1642. * BACK_DUR is about 5uS*(AFC_LO) rounded down
  1643. */
  1644. case 12:/* 3840 Rx Data Fifo Size */
  1645. lp->afc_cfg=0x0024124F;break;
  1646. case 13:/* 2880 Rx Data Fifo Size */
  1647. lp->afc_cfg=0x0015073F;break;
  1648. case 14:/* 1920 Rx Data Fifo Size */
  1649. lp->afc_cfg=0x0006032F;break;
  1650. default:
  1651. PRINTK("%s: ERROR -- no AFC_CFG setting found",
  1652. dev->name);
  1653. break;
  1654. }
  1655. DBG(SMC_DEBUG_MISC | SMC_DEBUG_TX | SMC_DEBUG_RX,
  1656. "%s: tx_fifo %d rx_fifo %d afc_cfg 0x%08x\n", CARDNAME,
  1657. lp->tx_fifo_size, lp->rx_fifo_size, lp->afc_cfg);
  1658. spin_lock_init(&lp->lock);
  1659. /* Get the MAC address */
  1660. SMC_GET_MAC_ADDR(lp, dev->dev_addr);
  1661. /* now, reset the chip, and put it into a known state */
  1662. smc911x_reset(dev);
  1663. /*
  1664. * If dev->irq is 0, then the device has to be banged on to see
  1665. * what the IRQ is.
  1666. *
  1667. * Specifying an IRQ is done with the assumption that the user knows
  1668. * what (s)he is doing. No checking is done!!!!
  1669. */
  1670. if (dev->irq < 1) {
  1671. int trials;
  1672. trials = 3;
  1673. while (trials--) {
  1674. dev->irq = smc911x_findirq(dev);
  1675. if (dev->irq)
  1676. break;
  1677. /* kick the card and try again */
  1678. smc911x_reset(dev);
  1679. }
  1680. }
  1681. if (dev->irq == 0) {
  1682. printk("%s: Couldn't autodetect your IRQ. Use irq=xx.\n",
  1683. dev->name);
  1684. retval = -ENODEV;
  1685. goto err_out;
  1686. }
  1687. dev->irq = irq_canonicalize(dev->irq);
  1688. /* Fill in the fields of the device structure with ethernet values. */
  1689. ether_setup(dev);
  1690. dev->open = smc911x_open;
  1691. dev->stop = smc911x_close;
  1692. dev->hard_start_xmit = smc911x_hard_start_xmit;
  1693. dev->tx_timeout = smc911x_timeout;
  1694. dev->watchdog_timeo = msecs_to_jiffies(watchdog);
  1695. dev->set_multicast_list = smc911x_set_multicast_list;
  1696. dev->ethtool_ops = &smc911x_ethtool_ops;
  1697. #ifdef CONFIG_NET_POLL_CONTROLLER
  1698. dev->poll_controller = smc911x_poll_controller;
  1699. #endif
  1700. INIT_WORK(&lp->phy_configure, smc911x_phy_configure);
  1701. lp->mii.phy_id_mask = 0x1f;
  1702. lp->mii.reg_num_mask = 0x1f;
  1703. lp->mii.force_media = 0;
  1704. lp->mii.full_duplex = 0;
  1705. lp->mii.dev = dev;
  1706. lp->mii.mdio_read = smc911x_phy_read;
  1707. lp->mii.mdio_write = smc911x_phy_write;
  1708. /*
  1709. * Locate the phy, if any.
  1710. */
  1711. smc911x_phy_detect(dev);
  1712. /* Set default parameters */
  1713. lp->msg_enable = NETIF_MSG_LINK;
  1714. lp->ctl_rfduplx = 1;
  1715. lp->ctl_rspeed = 100;
  1716. #ifdef SMC_DYNAMIC_BUS_CONFIG
  1717. irq_flags = lp->cfg.irq_flags;
  1718. #else
  1719. irq_flags = IRQF_SHARED | SMC_IRQ_SENSE;
  1720. #endif
  1721. /* Grab the IRQ */
  1722. retval = request_irq(dev->irq, &smc911x_interrupt,
  1723. irq_flags, dev->name, dev);
  1724. if (retval)
  1725. goto err_out;
  1726. #ifdef SMC_USE_DMA
  1727. lp->rxdma = SMC_DMA_REQUEST(dev, smc911x_rx_dma_irq);
  1728. lp->txdma = SMC_DMA_REQUEST(dev, smc911x_tx_dma_irq);
  1729. lp->rxdma_active = 0;
  1730. lp->txdma_active = 0;
  1731. dev->dma = lp->rxdma;
  1732. #endif
  1733. retval = register_netdev(dev);
  1734. if (retval == 0) {
  1735. /* now, print out the card info, in a short format.. */
  1736. printk("%s: %s (rev %d) at %#lx IRQ %d",
  1737. dev->name, version_string, lp->revision,
  1738. dev->base_addr, dev->irq);
  1739. #ifdef SMC_USE_DMA
  1740. if (lp->rxdma != -1)
  1741. printk(" RXDMA %d ", lp->rxdma);
  1742. if (lp->txdma != -1)
  1743. printk("TXDMA %d", lp->txdma);
  1744. #endif
  1745. printk("\n");
  1746. if (!is_valid_ether_addr(dev->dev_addr)) {
  1747. printk("%s: Invalid ethernet MAC address. Please "
  1748. "set using ifconfig\n", dev->name);
  1749. } else {
  1750. /* Print the Ethernet address */
  1751. printk("%s: Ethernet addr: ", dev->name);
  1752. for (i = 0; i < 5; i++)
  1753. printk("%2.2x:", dev->dev_addr[i]);
  1754. printk("%2.2x\n", dev->dev_addr[5]);
  1755. }
  1756. if (lp->phy_type == 0) {
  1757. PRINTK("%s: No PHY found\n", dev->name);
  1758. } else if ((lp->phy_type & ~0xff) == LAN911X_INTERNAL_PHY_ID) {
  1759. PRINTK("%s: LAN911x Internal PHY\n", dev->name);
  1760. } else {
  1761. PRINTK("%s: External PHY 0x%08x\n", dev->name, lp->phy_type);
  1762. }
  1763. }
  1764. err_out:
  1765. #ifdef SMC_USE_DMA
  1766. if (retval) {
  1767. if (lp->rxdma != -1) {
  1768. SMC_DMA_FREE(dev, lp->rxdma);
  1769. }
  1770. if (lp->txdma != -1) {
  1771. SMC_DMA_FREE(dev, lp->txdma);
  1772. }
  1773. }
  1774. #endif
  1775. return retval;
  1776. }
  1777. /*
  1778. * smc911x_init(void)
  1779. *
  1780. * Output:
  1781. * 0 --> there is a device
  1782. * anything else, error
  1783. */
  1784. static int __devinit smc911x_drv_probe(struct platform_device *pdev)
  1785. {
  1786. struct net_device *ndev;
  1787. struct resource *res;
  1788. struct smc911x_local *lp;
  1789. unsigned int *addr;
  1790. int ret;
  1791. DBG(SMC_DEBUG_FUNC, "--> %s\n", __func__);
  1792. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1793. if (!res) {
  1794. ret = -ENODEV;
  1795. goto out;
  1796. }
  1797. /*
  1798. * Request the regions.
  1799. */
  1800. if (!request_mem_region(res->start, SMC911X_IO_EXTENT, CARDNAME)) {
  1801. ret = -EBUSY;
  1802. goto out;
  1803. }
  1804. ndev = alloc_etherdev(sizeof(struct smc911x_local));
  1805. if (!ndev) {
  1806. printk("%s: could not allocate device.\n", CARDNAME);
  1807. ret = -ENOMEM;
  1808. goto release_1;
  1809. }
  1810. SET_NETDEV_DEV(ndev, &pdev->dev);
  1811. ndev->dma = (unsigned char)-1;
  1812. ndev->irq = platform_get_irq(pdev, 0);
  1813. lp = netdev_priv(ndev);
  1814. lp->netdev = ndev;
  1815. #ifdef SMC_DYNAMIC_BUS_CONFIG
  1816. {
  1817. struct smc911x_platdata *pd = pdev->dev.platform_data;
  1818. if (!pd) {
  1819. ret = -EINVAL;
  1820. goto release_both;
  1821. }
  1822. memcpy(&lp->cfg, pd, sizeof(lp->cfg));
  1823. }
  1824. #endif
  1825. addr = ioremap(res->start, SMC911X_IO_EXTENT);
  1826. if (!addr) {
  1827. ret = -ENOMEM;
  1828. goto release_both;
  1829. }
  1830. platform_set_drvdata(pdev, ndev);
  1831. lp->base = addr;
  1832. ndev->base_addr = res->start;
  1833. ret = smc911x_probe(ndev);
  1834. if (ret != 0) {
  1835. platform_set_drvdata(pdev, NULL);
  1836. iounmap(addr);
  1837. release_both:
  1838. free_netdev(ndev);
  1839. release_1:
  1840. release_mem_region(res->start, SMC911X_IO_EXTENT);
  1841. out:
  1842. printk("%s: not found (%d).\n", CARDNAME, ret);
  1843. }
  1844. #ifdef SMC_USE_DMA
  1845. else {
  1846. lp->physaddr = res->start;
  1847. lp->dev = &pdev->dev;
  1848. }
  1849. #endif
  1850. return ret;
  1851. }
  1852. static int __devexit smc911x_drv_remove(struct platform_device *pdev)
  1853. {
  1854. struct net_device *ndev = platform_get_drvdata(pdev);
  1855. struct smc911x_local *lp = netdev_priv(ndev);
  1856. struct resource *res;
  1857. DBG(SMC_DEBUG_FUNC, "--> %s\n", __func__);
  1858. platform_set_drvdata(pdev, NULL);
  1859. unregister_netdev(ndev);
  1860. free_irq(ndev->irq, ndev);
  1861. #ifdef SMC_USE_DMA
  1862. {
  1863. if (lp->rxdma != -1) {
  1864. SMC_DMA_FREE(dev, lp->rxdma);
  1865. }
  1866. if (lp->txdma != -1) {
  1867. SMC_DMA_FREE(dev, lp->txdma);
  1868. }
  1869. }
  1870. #endif
  1871. iounmap(lp->base);
  1872. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1873. release_mem_region(res->start, SMC911X_IO_EXTENT);
  1874. free_netdev(ndev);
  1875. return 0;
  1876. }
  1877. static int smc911x_drv_suspend(struct platform_device *dev, pm_message_t state)
  1878. {
  1879. struct net_device *ndev = platform_get_drvdata(dev);
  1880. struct smc911x_local *lp = netdev_priv(ndev);
  1881. DBG(SMC_DEBUG_FUNC, "--> %s\n", __func__);
  1882. if (ndev) {
  1883. if (netif_running(ndev)) {
  1884. netif_device_detach(ndev);
  1885. smc911x_shutdown(ndev);
  1886. #if POWER_DOWN
  1887. /* Set D2 - Energy detect only setting */
  1888. SMC_SET_PMT_CTRL(lp, 2<<12);
  1889. #endif
  1890. }
  1891. }
  1892. return 0;
  1893. }
  1894. static int smc911x_drv_resume(struct platform_device *dev)
  1895. {
  1896. struct net_device *ndev = platform_get_drvdata(dev);
  1897. DBG(SMC_DEBUG_FUNC, "--> %s\n", __func__);
  1898. if (ndev) {
  1899. struct smc911x_local *lp = netdev_priv(ndev);
  1900. if (netif_running(ndev)) {
  1901. smc911x_reset(ndev);
  1902. if (lp->phy_type != 0)
  1903. smc911x_phy_configure(&lp->phy_configure);
  1904. smc911x_enable(ndev);
  1905. netif_device_attach(ndev);
  1906. }
  1907. }
  1908. return 0;
  1909. }
  1910. static struct platform_driver smc911x_driver = {
  1911. .probe = smc911x_drv_probe,
  1912. .remove = __devexit_p(smc911x_drv_remove),
  1913. .suspend = smc911x_drv_suspend,
  1914. .resume = smc911x_drv_resume,
  1915. .driver = {
  1916. .name = CARDNAME,
  1917. .owner = THIS_MODULE,
  1918. },
  1919. };
  1920. static int __init smc911x_init(void)
  1921. {
  1922. return platform_driver_register(&smc911x_driver);
  1923. }
  1924. static void __exit smc911x_cleanup(void)
  1925. {
  1926. platform_driver_unregister(&smc911x_driver);
  1927. }
  1928. module_init(smc911x_init);
  1929. module_exit(smc911x_cleanup);