enc28j60.c 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667
  1. /*
  2. * Microchip ENC28J60 ethernet driver (MAC + PHY)
  3. *
  4. * Copyright (C) 2007 Eurek srl
  5. * Author: Claudio Lanconelli <lanconelli.claudio@eptar.com>
  6. * based on enc28j60.c written by David Anders for 2.4 kernel version
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * $Id: enc28j60.c,v 1.22 2007/12/20 10:47:01 claudio Exp $
  14. */
  15. #include <linux/module.h>
  16. #include <linux/kernel.h>
  17. #include <linux/types.h>
  18. #include <linux/fcntl.h>
  19. #include <linux/interrupt.h>
  20. #include <linux/slab.h>
  21. #include <linux/string.h>
  22. #include <linux/errno.h>
  23. #include <linux/init.h>
  24. #include <linux/netdevice.h>
  25. #include <linux/etherdevice.h>
  26. #include <linux/ethtool.h>
  27. #include <linux/tcp.h>
  28. #include <linux/skbuff.h>
  29. #include <linux/delay.h>
  30. #include <linux/spi/spi.h>
  31. #include "enc28j60_hw.h"
  32. #define DRV_NAME "enc28j60"
  33. #define DRV_VERSION "1.01"
  34. #define SPI_OPLEN 1
  35. #define ENC28J60_MSG_DEFAULT \
  36. (NETIF_MSG_PROBE | NETIF_MSG_IFUP | NETIF_MSG_IFDOWN | NETIF_MSG_LINK)
  37. /* Buffer size required for the largest SPI transfer (i.e., reading a
  38. * frame). */
  39. #define SPI_TRANSFER_BUF_LEN (4 + MAX_FRAMELEN)
  40. #define TX_TIMEOUT (4 * HZ)
  41. /* Max TX retries in case of collision as suggested by errata datasheet */
  42. #define MAX_TX_RETRYCOUNT 16
  43. enum {
  44. RXFILTER_NORMAL,
  45. RXFILTER_MULTI,
  46. RXFILTER_PROMISC
  47. };
  48. /* Driver local data */
  49. struct enc28j60_net {
  50. struct net_device *netdev;
  51. struct spi_device *spi;
  52. struct mutex lock;
  53. struct sk_buff *tx_skb;
  54. struct work_struct tx_work;
  55. struct work_struct irq_work;
  56. struct work_struct setrx_work;
  57. struct work_struct restart_work;
  58. u8 bank; /* current register bank selected */
  59. u16 next_pk_ptr; /* next packet pointer within FIFO */
  60. u16 max_pk_counter; /* statistics: max packet counter */
  61. u16 tx_retry_count;
  62. bool hw_enable;
  63. bool full_duplex;
  64. int rxfilter;
  65. u32 msg_enable;
  66. u8 spi_transfer_buf[SPI_TRANSFER_BUF_LEN];
  67. };
  68. /* use ethtool to change the level for any given device */
  69. static struct {
  70. u32 msg_enable;
  71. } debug = { -1 };
  72. /*
  73. * SPI read buffer
  74. * wait for the SPI transfer and copy received data to destination
  75. */
  76. static int
  77. spi_read_buf(struct enc28j60_net *priv, int len, u8 *data)
  78. {
  79. u8 *rx_buf = priv->spi_transfer_buf + 4;
  80. u8 *tx_buf = priv->spi_transfer_buf;
  81. struct spi_transfer t = {
  82. .tx_buf = tx_buf,
  83. .rx_buf = rx_buf,
  84. .len = SPI_OPLEN + len,
  85. };
  86. struct spi_message msg;
  87. int ret;
  88. tx_buf[0] = ENC28J60_READ_BUF_MEM;
  89. tx_buf[1] = tx_buf[2] = tx_buf[3] = 0; /* don't care */
  90. spi_message_init(&msg);
  91. spi_message_add_tail(&t, &msg);
  92. ret = spi_sync(priv->spi, &msg);
  93. if (ret == 0) {
  94. memcpy(data, &rx_buf[SPI_OPLEN], len);
  95. ret = msg.status;
  96. }
  97. if (ret && netif_msg_drv(priv))
  98. printk(KERN_DEBUG DRV_NAME ": %s() failed: ret = %d\n",
  99. __func__, ret);
  100. return ret;
  101. }
  102. /*
  103. * SPI write buffer
  104. */
  105. static int spi_write_buf(struct enc28j60_net *priv, int len,
  106. const u8 *data)
  107. {
  108. int ret;
  109. if (len > SPI_TRANSFER_BUF_LEN - 1 || len <= 0)
  110. ret = -EINVAL;
  111. else {
  112. priv->spi_transfer_buf[0] = ENC28J60_WRITE_BUF_MEM;
  113. memcpy(&priv->spi_transfer_buf[1], data, len);
  114. ret = spi_write(priv->spi, priv->spi_transfer_buf, len + 1);
  115. if (ret && netif_msg_drv(priv))
  116. printk(KERN_DEBUG DRV_NAME ": %s() failed: ret = %d\n",
  117. __func__, ret);
  118. }
  119. return ret;
  120. }
  121. /*
  122. * basic SPI read operation
  123. */
  124. static u8 spi_read_op(struct enc28j60_net *priv, u8 op,
  125. u8 addr)
  126. {
  127. u8 tx_buf[2];
  128. u8 rx_buf[4];
  129. u8 val = 0;
  130. int ret;
  131. int slen = SPI_OPLEN;
  132. /* do dummy read if needed */
  133. if (addr & SPRD_MASK)
  134. slen++;
  135. tx_buf[0] = op | (addr & ADDR_MASK);
  136. ret = spi_write_then_read(priv->spi, tx_buf, 1, rx_buf, slen);
  137. if (ret)
  138. printk(KERN_DEBUG DRV_NAME ": %s() failed: ret = %d\n",
  139. __func__, ret);
  140. else
  141. val = rx_buf[slen - 1];
  142. return val;
  143. }
  144. /*
  145. * basic SPI write operation
  146. */
  147. static int spi_write_op(struct enc28j60_net *priv, u8 op,
  148. u8 addr, u8 val)
  149. {
  150. int ret;
  151. priv->spi_transfer_buf[0] = op | (addr & ADDR_MASK);
  152. priv->spi_transfer_buf[1] = val;
  153. ret = spi_write(priv->spi, priv->spi_transfer_buf, 2);
  154. if (ret && netif_msg_drv(priv))
  155. printk(KERN_DEBUG DRV_NAME ": %s() failed: ret = %d\n",
  156. __func__, ret);
  157. return ret;
  158. }
  159. static void enc28j60_soft_reset(struct enc28j60_net *priv)
  160. {
  161. if (netif_msg_hw(priv))
  162. printk(KERN_DEBUG DRV_NAME ": %s() enter\n", __func__);
  163. spi_write_op(priv, ENC28J60_SOFT_RESET, 0, ENC28J60_SOFT_RESET);
  164. /* Errata workaround #1, CLKRDY check is unreliable,
  165. * delay at least 1 mS instead */
  166. udelay(2000);
  167. }
  168. /*
  169. * select the current register bank if necessary
  170. */
  171. static void enc28j60_set_bank(struct enc28j60_net *priv, u8 addr)
  172. {
  173. u8 b = (addr & BANK_MASK) >> 5;
  174. /* These registers (EIE, EIR, ESTAT, ECON2, ECON1)
  175. * are present in all banks, no need to switch bank
  176. */
  177. if (addr >= EIE && addr <= ECON1)
  178. return;
  179. /* Clear or set each bank selection bit as needed */
  180. if ((b & ECON1_BSEL0) != (priv->bank & ECON1_BSEL0)) {
  181. if (b & ECON1_BSEL0)
  182. spi_write_op(priv, ENC28J60_BIT_FIELD_SET, ECON1,
  183. ECON1_BSEL0);
  184. else
  185. spi_write_op(priv, ENC28J60_BIT_FIELD_CLR, ECON1,
  186. ECON1_BSEL0);
  187. }
  188. if ((b & ECON1_BSEL1) != (priv->bank & ECON1_BSEL1)) {
  189. if (b & ECON1_BSEL1)
  190. spi_write_op(priv, ENC28J60_BIT_FIELD_SET, ECON1,
  191. ECON1_BSEL1);
  192. else
  193. spi_write_op(priv, ENC28J60_BIT_FIELD_CLR, ECON1,
  194. ECON1_BSEL1);
  195. }
  196. priv->bank = b;
  197. }
  198. /*
  199. * Register access routines through the SPI bus.
  200. * Every register access comes in two flavours:
  201. * - nolock_xxx: caller needs to invoke mutex_lock, usually to access
  202. * atomically more than one register
  203. * - locked_xxx: caller doesn't need to invoke mutex_lock, single access
  204. *
  205. * Some registers can be accessed through the bit field clear and
  206. * bit field set to avoid a read modify write cycle.
  207. */
  208. /*
  209. * Register bit field Set
  210. */
  211. static void nolock_reg_bfset(struct enc28j60_net *priv,
  212. u8 addr, u8 mask)
  213. {
  214. enc28j60_set_bank(priv, addr);
  215. spi_write_op(priv, ENC28J60_BIT_FIELD_SET, addr, mask);
  216. }
  217. static void locked_reg_bfset(struct enc28j60_net *priv,
  218. u8 addr, u8 mask)
  219. {
  220. mutex_lock(&priv->lock);
  221. nolock_reg_bfset(priv, addr, mask);
  222. mutex_unlock(&priv->lock);
  223. }
  224. /*
  225. * Register bit field Clear
  226. */
  227. static void nolock_reg_bfclr(struct enc28j60_net *priv,
  228. u8 addr, u8 mask)
  229. {
  230. enc28j60_set_bank(priv, addr);
  231. spi_write_op(priv, ENC28J60_BIT_FIELD_CLR, addr, mask);
  232. }
  233. static void locked_reg_bfclr(struct enc28j60_net *priv,
  234. u8 addr, u8 mask)
  235. {
  236. mutex_lock(&priv->lock);
  237. nolock_reg_bfclr(priv, addr, mask);
  238. mutex_unlock(&priv->lock);
  239. }
  240. /*
  241. * Register byte read
  242. */
  243. static int nolock_regb_read(struct enc28j60_net *priv,
  244. u8 address)
  245. {
  246. enc28j60_set_bank(priv, address);
  247. return spi_read_op(priv, ENC28J60_READ_CTRL_REG, address);
  248. }
  249. static int locked_regb_read(struct enc28j60_net *priv,
  250. u8 address)
  251. {
  252. int ret;
  253. mutex_lock(&priv->lock);
  254. ret = nolock_regb_read(priv, address);
  255. mutex_unlock(&priv->lock);
  256. return ret;
  257. }
  258. /*
  259. * Register word read
  260. */
  261. static int nolock_regw_read(struct enc28j60_net *priv,
  262. u8 address)
  263. {
  264. int rl, rh;
  265. enc28j60_set_bank(priv, address);
  266. rl = spi_read_op(priv, ENC28J60_READ_CTRL_REG, address);
  267. rh = spi_read_op(priv, ENC28J60_READ_CTRL_REG, address + 1);
  268. return (rh << 8) | rl;
  269. }
  270. static int locked_regw_read(struct enc28j60_net *priv,
  271. u8 address)
  272. {
  273. int ret;
  274. mutex_lock(&priv->lock);
  275. ret = nolock_regw_read(priv, address);
  276. mutex_unlock(&priv->lock);
  277. return ret;
  278. }
  279. /*
  280. * Register byte write
  281. */
  282. static void nolock_regb_write(struct enc28j60_net *priv,
  283. u8 address, u8 data)
  284. {
  285. enc28j60_set_bank(priv, address);
  286. spi_write_op(priv, ENC28J60_WRITE_CTRL_REG, address, data);
  287. }
  288. static void locked_regb_write(struct enc28j60_net *priv,
  289. u8 address, u8 data)
  290. {
  291. mutex_lock(&priv->lock);
  292. nolock_regb_write(priv, address, data);
  293. mutex_unlock(&priv->lock);
  294. }
  295. /*
  296. * Register word write
  297. */
  298. static void nolock_regw_write(struct enc28j60_net *priv,
  299. u8 address, u16 data)
  300. {
  301. enc28j60_set_bank(priv, address);
  302. spi_write_op(priv, ENC28J60_WRITE_CTRL_REG, address, (u8) data);
  303. spi_write_op(priv, ENC28J60_WRITE_CTRL_REG, address + 1,
  304. (u8) (data >> 8));
  305. }
  306. static void locked_regw_write(struct enc28j60_net *priv,
  307. u8 address, u16 data)
  308. {
  309. mutex_lock(&priv->lock);
  310. nolock_regw_write(priv, address, data);
  311. mutex_unlock(&priv->lock);
  312. }
  313. /*
  314. * Buffer memory read
  315. * Select the starting address and execute a SPI buffer read
  316. */
  317. static void enc28j60_mem_read(struct enc28j60_net *priv,
  318. u16 addr, int len, u8 *data)
  319. {
  320. mutex_lock(&priv->lock);
  321. nolock_regw_write(priv, ERDPTL, addr);
  322. #ifdef CONFIG_ENC28J60_WRITEVERIFY
  323. if (netif_msg_drv(priv)) {
  324. u16 reg;
  325. reg = nolock_regw_read(priv, ERDPTL);
  326. if (reg != addr)
  327. printk(KERN_DEBUG DRV_NAME ": %s() error writing ERDPT "
  328. "(0x%04x - 0x%04x)\n", __func__, reg, addr);
  329. }
  330. #endif
  331. spi_read_buf(priv, len, data);
  332. mutex_unlock(&priv->lock);
  333. }
  334. /*
  335. * Write packet to enc28j60 TX buffer memory
  336. */
  337. static void
  338. enc28j60_packet_write(struct enc28j60_net *priv, int len, const u8 *data)
  339. {
  340. mutex_lock(&priv->lock);
  341. /* Set the write pointer to start of transmit buffer area */
  342. nolock_regw_write(priv, EWRPTL, TXSTART_INIT);
  343. #ifdef CONFIG_ENC28J60_WRITEVERIFY
  344. if (netif_msg_drv(priv)) {
  345. u16 reg;
  346. reg = nolock_regw_read(priv, EWRPTL);
  347. if (reg != TXSTART_INIT)
  348. printk(KERN_DEBUG DRV_NAME
  349. ": %s() ERWPT:0x%04x != 0x%04x\n",
  350. __func__, reg, TXSTART_INIT);
  351. }
  352. #endif
  353. /* Set the TXND pointer to correspond to the packet size given */
  354. nolock_regw_write(priv, ETXNDL, TXSTART_INIT + len);
  355. /* write per-packet control byte */
  356. spi_write_op(priv, ENC28J60_WRITE_BUF_MEM, 0, 0x00);
  357. if (netif_msg_hw(priv))
  358. printk(KERN_DEBUG DRV_NAME
  359. ": %s() after control byte ERWPT:0x%04x\n",
  360. __func__, nolock_regw_read(priv, EWRPTL));
  361. /* copy the packet into the transmit buffer */
  362. spi_write_buf(priv, len, data);
  363. if (netif_msg_hw(priv))
  364. printk(KERN_DEBUG DRV_NAME
  365. ": %s() after write packet ERWPT:0x%04x, len=%d\n",
  366. __func__, nolock_regw_read(priv, EWRPTL), len);
  367. mutex_unlock(&priv->lock);
  368. }
  369. static unsigned long msec20_to_jiffies;
  370. static int poll_ready(struct enc28j60_net *priv, u8 reg, u8 mask, u8 val)
  371. {
  372. unsigned long timeout = jiffies + msec20_to_jiffies;
  373. /* 20 msec timeout read */
  374. while ((nolock_regb_read(priv, reg) & mask) != val) {
  375. if (time_after(jiffies, timeout)) {
  376. if (netif_msg_drv(priv))
  377. dev_dbg(&priv->spi->dev,
  378. "reg %02x ready timeout!\n", reg);
  379. return -ETIMEDOUT;
  380. }
  381. cpu_relax();
  382. }
  383. return 0;
  384. }
  385. /*
  386. * Wait until the PHY operation is complete.
  387. */
  388. static int wait_phy_ready(struct enc28j60_net *priv)
  389. {
  390. return poll_ready(priv, MISTAT, MISTAT_BUSY, 0) ? 0 : 1;
  391. }
  392. /*
  393. * PHY register read
  394. * PHY registers are not accessed directly, but through the MII
  395. */
  396. static u16 enc28j60_phy_read(struct enc28j60_net *priv, u8 address)
  397. {
  398. u16 ret;
  399. mutex_lock(&priv->lock);
  400. /* set the PHY register address */
  401. nolock_regb_write(priv, MIREGADR, address);
  402. /* start the register read operation */
  403. nolock_regb_write(priv, MICMD, MICMD_MIIRD);
  404. /* wait until the PHY read completes */
  405. wait_phy_ready(priv);
  406. /* quit reading */
  407. nolock_regb_write(priv, MICMD, 0x00);
  408. /* return the data */
  409. ret = nolock_regw_read(priv, MIRDL);
  410. mutex_unlock(&priv->lock);
  411. return ret;
  412. }
  413. static int enc28j60_phy_write(struct enc28j60_net *priv, u8 address, u16 data)
  414. {
  415. int ret;
  416. mutex_lock(&priv->lock);
  417. /* set the PHY register address */
  418. nolock_regb_write(priv, MIREGADR, address);
  419. /* write the PHY data */
  420. nolock_regw_write(priv, MIWRL, data);
  421. /* wait until the PHY write completes and return */
  422. ret = wait_phy_ready(priv);
  423. mutex_unlock(&priv->lock);
  424. return ret;
  425. }
  426. /*
  427. * Program the hardware MAC address from dev->dev_addr.
  428. */
  429. static int enc28j60_set_hw_macaddr(struct net_device *ndev)
  430. {
  431. int ret;
  432. struct enc28j60_net *priv = netdev_priv(ndev);
  433. mutex_lock(&priv->lock);
  434. if (!priv->hw_enable) {
  435. if (netif_msg_drv(priv))
  436. printk(KERN_INFO DRV_NAME
  437. ": %s: Setting MAC address to %pM\n",
  438. ndev->name, ndev->dev_addr);
  439. /* NOTE: MAC address in ENC28J60 is byte-backward */
  440. nolock_regb_write(priv, MAADR5, ndev->dev_addr[0]);
  441. nolock_regb_write(priv, MAADR4, ndev->dev_addr[1]);
  442. nolock_regb_write(priv, MAADR3, ndev->dev_addr[2]);
  443. nolock_regb_write(priv, MAADR2, ndev->dev_addr[3]);
  444. nolock_regb_write(priv, MAADR1, ndev->dev_addr[4]);
  445. nolock_regb_write(priv, MAADR0, ndev->dev_addr[5]);
  446. ret = 0;
  447. } else {
  448. if (netif_msg_drv(priv))
  449. printk(KERN_DEBUG DRV_NAME
  450. ": %s() Hardware must be disabled to set "
  451. "Mac address\n", __func__);
  452. ret = -EBUSY;
  453. }
  454. mutex_unlock(&priv->lock);
  455. return ret;
  456. }
  457. /*
  458. * Store the new hardware address in dev->dev_addr, and update the MAC.
  459. */
  460. static int enc28j60_set_mac_address(struct net_device *dev, void *addr)
  461. {
  462. struct sockaddr *address = addr;
  463. if (netif_running(dev))
  464. return -EBUSY;
  465. if (!is_valid_ether_addr(address->sa_data))
  466. return -EADDRNOTAVAIL;
  467. memcpy(dev->dev_addr, address->sa_data, dev->addr_len);
  468. return enc28j60_set_hw_macaddr(dev);
  469. }
  470. /*
  471. * Debug routine to dump useful register contents
  472. */
  473. static void enc28j60_dump_regs(struct enc28j60_net *priv, const char *msg)
  474. {
  475. mutex_lock(&priv->lock);
  476. printk(KERN_DEBUG DRV_NAME " %s\n"
  477. "HwRevID: 0x%02x\n"
  478. "Cntrl: ECON1 ECON2 ESTAT EIR EIE\n"
  479. " 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n"
  480. "MAC : MACON1 MACON3 MACON4\n"
  481. " 0x%02x 0x%02x 0x%02x\n"
  482. "Rx : ERXST ERXND ERXWRPT ERXRDPT ERXFCON EPKTCNT MAMXFL\n"
  483. " 0x%04x 0x%04x 0x%04x 0x%04x "
  484. "0x%02x 0x%02x 0x%04x\n"
  485. "Tx : ETXST ETXND MACLCON1 MACLCON2 MAPHSUP\n"
  486. " 0x%04x 0x%04x 0x%02x 0x%02x 0x%02x\n",
  487. msg, nolock_regb_read(priv, EREVID),
  488. nolock_regb_read(priv, ECON1), nolock_regb_read(priv, ECON2),
  489. nolock_regb_read(priv, ESTAT), nolock_regb_read(priv, EIR),
  490. nolock_regb_read(priv, EIE), nolock_regb_read(priv, MACON1),
  491. nolock_regb_read(priv, MACON3), nolock_regb_read(priv, MACON4),
  492. nolock_regw_read(priv, ERXSTL), nolock_regw_read(priv, ERXNDL),
  493. nolock_regw_read(priv, ERXWRPTL),
  494. nolock_regw_read(priv, ERXRDPTL),
  495. nolock_regb_read(priv, ERXFCON),
  496. nolock_regb_read(priv, EPKTCNT),
  497. nolock_regw_read(priv, MAMXFLL), nolock_regw_read(priv, ETXSTL),
  498. nolock_regw_read(priv, ETXNDL),
  499. nolock_regb_read(priv, MACLCON1),
  500. nolock_regb_read(priv, MACLCON2),
  501. nolock_regb_read(priv, MAPHSUP));
  502. mutex_unlock(&priv->lock);
  503. }
  504. /*
  505. * ERXRDPT need to be set always at odd addresses, refer to errata datasheet
  506. */
  507. static u16 erxrdpt_workaround(u16 next_packet_ptr, u16 start, u16 end)
  508. {
  509. u16 erxrdpt;
  510. if ((next_packet_ptr - 1 < start) || (next_packet_ptr - 1 > end))
  511. erxrdpt = end;
  512. else
  513. erxrdpt = next_packet_ptr - 1;
  514. return erxrdpt;
  515. }
  516. /*
  517. * Calculate wrap around when reading beyond the end of the RX buffer
  518. */
  519. static u16 rx_packet_start(u16 ptr)
  520. {
  521. if (ptr + RSV_SIZE > RXEND_INIT)
  522. return (ptr + RSV_SIZE) - (RXEND_INIT - RXSTART_INIT + 1);
  523. else
  524. return ptr + RSV_SIZE;
  525. }
  526. static void nolock_rxfifo_init(struct enc28j60_net *priv, u16 start, u16 end)
  527. {
  528. u16 erxrdpt;
  529. if (start > 0x1FFF || end > 0x1FFF || start > end) {
  530. if (netif_msg_drv(priv))
  531. printk(KERN_ERR DRV_NAME ": %s(%d, %d) RXFIFO "
  532. "bad parameters!\n", __func__, start, end);
  533. return;
  534. }
  535. /* set receive buffer start + end */
  536. priv->next_pk_ptr = start;
  537. nolock_regw_write(priv, ERXSTL, start);
  538. erxrdpt = erxrdpt_workaround(priv->next_pk_ptr, start, end);
  539. nolock_regw_write(priv, ERXRDPTL, erxrdpt);
  540. nolock_regw_write(priv, ERXNDL, end);
  541. }
  542. static void nolock_txfifo_init(struct enc28j60_net *priv, u16 start, u16 end)
  543. {
  544. if (start > 0x1FFF || end > 0x1FFF || start > end) {
  545. if (netif_msg_drv(priv))
  546. printk(KERN_ERR DRV_NAME ": %s(%d, %d) TXFIFO "
  547. "bad parameters!\n", __func__, start, end);
  548. return;
  549. }
  550. /* set transmit buffer start + end */
  551. nolock_regw_write(priv, ETXSTL, start);
  552. nolock_regw_write(priv, ETXNDL, end);
  553. }
  554. /*
  555. * Low power mode shrinks power consumption about 100x, so we'd like
  556. * the chip to be in that mode whenever it's inactive. (However, we
  557. * can't stay in lowpower mode during suspend with WOL active.)
  558. */
  559. static void enc28j60_lowpower(struct enc28j60_net *priv, bool is_low)
  560. {
  561. if (netif_msg_drv(priv))
  562. dev_dbg(&priv->spi->dev, "%s power...\n",
  563. is_low ? "low" : "high");
  564. mutex_lock(&priv->lock);
  565. if (is_low) {
  566. nolock_reg_bfclr(priv, ECON1, ECON1_RXEN);
  567. poll_ready(priv, ESTAT, ESTAT_RXBUSY, 0);
  568. poll_ready(priv, ECON1, ECON1_TXRTS, 0);
  569. /* ECON2_VRPS was set during initialization */
  570. nolock_reg_bfset(priv, ECON2, ECON2_PWRSV);
  571. } else {
  572. nolock_reg_bfclr(priv, ECON2, ECON2_PWRSV);
  573. poll_ready(priv, ESTAT, ESTAT_CLKRDY, ESTAT_CLKRDY);
  574. /* caller sets ECON1_RXEN */
  575. }
  576. mutex_unlock(&priv->lock);
  577. }
  578. static int enc28j60_hw_init(struct enc28j60_net *priv)
  579. {
  580. u8 reg;
  581. if (netif_msg_drv(priv))
  582. printk(KERN_DEBUG DRV_NAME ": %s() - %s\n", __func__,
  583. priv->full_duplex ? "FullDuplex" : "HalfDuplex");
  584. mutex_lock(&priv->lock);
  585. /* first reset the chip */
  586. enc28j60_soft_reset(priv);
  587. /* Clear ECON1 */
  588. spi_write_op(priv, ENC28J60_WRITE_CTRL_REG, ECON1, 0x00);
  589. priv->bank = 0;
  590. priv->hw_enable = false;
  591. priv->tx_retry_count = 0;
  592. priv->max_pk_counter = 0;
  593. priv->rxfilter = RXFILTER_NORMAL;
  594. /* enable address auto increment and voltage regulator powersave */
  595. nolock_regb_write(priv, ECON2, ECON2_AUTOINC | ECON2_VRPS);
  596. nolock_rxfifo_init(priv, RXSTART_INIT, RXEND_INIT);
  597. nolock_txfifo_init(priv, TXSTART_INIT, TXEND_INIT);
  598. mutex_unlock(&priv->lock);
  599. /*
  600. * Check the RevID.
  601. * If it's 0x00 or 0xFF probably the enc28j60 is not mounted or
  602. * damaged
  603. */
  604. reg = locked_regb_read(priv, EREVID);
  605. if (netif_msg_drv(priv))
  606. printk(KERN_INFO DRV_NAME ": chip RevID: 0x%02x\n", reg);
  607. if (reg == 0x00 || reg == 0xff) {
  608. if (netif_msg_drv(priv))
  609. printk(KERN_DEBUG DRV_NAME ": %s() Invalid RevId %d\n",
  610. __func__, reg);
  611. return 0;
  612. }
  613. /* default filter mode: (unicast OR broadcast) AND crc valid */
  614. locked_regb_write(priv, ERXFCON,
  615. ERXFCON_UCEN | ERXFCON_CRCEN | ERXFCON_BCEN);
  616. /* enable MAC receive */
  617. locked_regb_write(priv, MACON1,
  618. MACON1_MARXEN | MACON1_TXPAUS | MACON1_RXPAUS);
  619. /* enable automatic padding and CRC operations */
  620. if (priv->full_duplex) {
  621. locked_regb_write(priv, MACON3,
  622. MACON3_PADCFG0 | MACON3_TXCRCEN |
  623. MACON3_FRMLNEN | MACON3_FULDPX);
  624. /* set inter-frame gap (non-back-to-back) */
  625. locked_regb_write(priv, MAIPGL, 0x12);
  626. /* set inter-frame gap (back-to-back) */
  627. locked_regb_write(priv, MABBIPG, 0x15);
  628. } else {
  629. locked_regb_write(priv, MACON3,
  630. MACON3_PADCFG0 | MACON3_TXCRCEN |
  631. MACON3_FRMLNEN);
  632. locked_regb_write(priv, MACON4, 1 << 6); /* DEFER bit */
  633. /* set inter-frame gap (non-back-to-back) */
  634. locked_regw_write(priv, MAIPGL, 0x0C12);
  635. /* set inter-frame gap (back-to-back) */
  636. locked_regb_write(priv, MABBIPG, 0x12);
  637. }
  638. /*
  639. * MACLCON1 (default)
  640. * MACLCON2 (default)
  641. * Set the maximum packet size which the controller will accept
  642. */
  643. locked_regw_write(priv, MAMXFLL, MAX_FRAMELEN);
  644. /* Configure LEDs */
  645. if (!enc28j60_phy_write(priv, PHLCON, ENC28J60_LAMPS_MODE))
  646. return 0;
  647. if (priv->full_duplex) {
  648. if (!enc28j60_phy_write(priv, PHCON1, PHCON1_PDPXMD))
  649. return 0;
  650. if (!enc28j60_phy_write(priv, PHCON2, 0x00))
  651. return 0;
  652. } else {
  653. if (!enc28j60_phy_write(priv, PHCON1, 0x00))
  654. return 0;
  655. if (!enc28j60_phy_write(priv, PHCON2, PHCON2_HDLDIS))
  656. return 0;
  657. }
  658. if (netif_msg_hw(priv))
  659. enc28j60_dump_regs(priv, "Hw initialized.");
  660. return 1;
  661. }
  662. static void enc28j60_hw_enable(struct enc28j60_net *priv)
  663. {
  664. /* enable interrupts */
  665. if (netif_msg_hw(priv))
  666. printk(KERN_DEBUG DRV_NAME ": %s() enabling interrupts.\n",
  667. __func__);
  668. enc28j60_phy_write(priv, PHIE, PHIE_PGEIE | PHIE_PLNKIE);
  669. mutex_lock(&priv->lock);
  670. nolock_reg_bfclr(priv, EIR, EIR_DMAIF | EIR_LINKIF |
  671. EIR_TXIF | EIR_TXERIF | EIR_RXERIF | EIR_PKTIF);
  672. nolock_regb_write(priv, EIE, EIE_INTIE | EIE_PKTIE | EIE_LINKIE |
  673. EIE_TXIE | EIE_TXERIE | EIE_RXERIE);
  674. /* enable receive logic */
  675. nolock_reg_bfset(priv, ECON1, ECON1_RXEN);
  676. priv->hw_enable = true;
  677. mutex_unlock(&priv->lock);
  678. }
  679. static void enc28j60_hw_disable(struct enc28j60_net *priv)
  680. {
  681. mutex_lock(&priv->lock);
  682. /* disable interrutps and packet reception */
  683. nolock_regb_write(priv, EIE, 0x00);
  684. nolock_reg_bfclr(priv, ECON1, ECON1_RXEN);
  685. priv->hw_enable = false;
  686. mutex_unlock(&priv->lock);
  687. }
  688. static int
  689. enc28j60_setlink(struct net_device *ndev, u8 autoneg, u16 speed, u8 duplex)
  690. {
  691. struct enc28j60_net *priv = netdev_priv(ndev);
  692. int ret = 0;
  693. if (!priv->hw_enable) {
  694. /* link is in low power mode now; duplex setting
  695. * will take effect on next enc28j60_hw_init().
  696. */
  697. if (autoneg == AUTONEG_DISABLE && speed == SPEED_10)
  698. priv->full_duplex = (duplex == DUPLEX_FULL);
  699. else {
  700. if (netif_msg_link(priv))
  701. dev_warn(&ndev->dev,
  702. "unsupported link setting\n");
  703. ret = -EOPNOTSUPP;
  704. }
  705. } else {
  706. if (netif_msg_link(priv))
  707. dev_warn(&ndev->dev, "Warning: hw must be disabled "
  708. "to set link mode\n");
  709. ret = -EBUSY;
  710. }
  711. return ret;
  712. }
  713. /*
  714. * Read the Transmit Status Vector
  715. */
  716. static void enc28j60_read_tsv(struct enc28j60_net *priv, u8 tsv[TSV_SIZE])
  717. {
  718. int endptr;
  719. endptr = locked_regw_read(priv, ETXNDL);
  720. if (netif_msg_hw(priv))
  721. printk(KERN_DEBUG DRV_NAME ": reading TSV at addr:0x%04x\n",
  722. endptr + 1);
  723. enc28j60_mem_read(priv, endptr + 1, sizeof(tsv), tsv);
  724. }
  725. static void enc28j60_dump_tsv(struct enc28j60_net *priv, const char *msg,
  726. u8 tsv[TSV_SIZE])
  727. {
  728. u16 tmp1, tmp2;
  729. printk(KERN_DEBUG DRV_NAME ": %s - TSV:\n", msg);
  730. tmp1 = tsv[1];
  731. tmp1 <<= 8;
  732. tmp1 |= tsv[0];
  733. tmp2 = tsv[5];
  734. tmp2 <<= 8;
  735. tmp2 |= tsv[4];
  736. printk(KERN_DEBUG DRV_NAME ": ByteCount: %d, CollisionCount: %d,"
  737. " TotByteOnWire: %d\n", tmp1, tsv[2] & 0x0f, tmp2);
  738. printk(KERN_DEBUG DRV_NAME ": TxDone: %d, CRCErr:%d, LenChkErr: %d,"
  739. " LenOutOfRange: %d\n", TSV_GETBIT(tsv, TSV_TXDONE),
  740. TSV_GETBIT(tsv, TSV_TXCRCERROR),
  741. TSV_GETBIT(tsv, TSV_TXLENCHKERROR),
  742. TSV_GETBIT(tsv, TSV_TXLENOUTOFRANGE));
  743. printk(KERN_DEBUG DRV_NAME ": Multicast: %d, Broadcast: %d, "
  744. "PacketDefer: %d, ExDefer: %d\n",
  745. TSV_GETBIT(tsv, TSV_TXMULTICAST),
  746. TSV_GETBIT(tsv, TSV_TXBROADCAST),
  747. TSV_GETBIT(tsv, TSV_TXPACKETDEFER),
  748. TSV_GETBIT(tsv, TSV_TXEXDEFER));
  749. printk(KERN_DEBUG DRV_NAME ": ExCollision: %d, LateCollision: %d, "
  750. "Giant: %d, Underrun: %d\n",
  751. TSV_GETBIT(tsv, TSV_TXEXCOLLISION),
  752. TSV_GETBIT(tsv, TSV_TXLATECOLLISION),
  753. TSV_GETBIT(tsv, TSV_TXGIANT), TSV_GETBIT(tsv, TSV_TXUNDERRUN));
  754. printk(KERN_DEBUG DRV_NAME ": ControlFrame: %d, PauseFrame: %d, "
  755. "BackPressApp: %d, VLanTagFrame: %d\n",
  756. TSV_GETBIT(tsv, TSV_TXCONTROLFRAME),
  757. TSV_GETBIT(tsv, TSV_TXPAUSEFRAME),
  758. TSV_GETBIT(tsv, TSV_BACKPRESSUREAPP),
  759. TSV_GETBIT(tsv, TSV_TXVLANTAGFRAME));
  760. }
  761. /*
  762. * Receive Status vector
  763. */
  764. static void enc28j60_dump_rsv(struct enc28j60_net *priv, const char *msg,
  765. u16 pk_ptr, int len, u16 sts)
  766. {
  767. printk(KERN_DEBUG DRV_NAME ": %s - NextPk: 0x%04x - RSV:\n",
  768. msg, pk_ptr);
  769. printk(KERN_DEBUG DRV_NAME ": ByteCount: %d, DribbleNibble: %d\n", len,
  770. RSV_GETBIT(sts, RSV_DRIBBLENIBBLE));
  771. printk(KERN_DEBUG DRV_NAME ": RxOK: %d, CRCErr:%d, LenChkErr: %d,"
  772. " LenOutOfRange: %d\n", RSV_GETBIT(sts, RSV_RXOK),
  773. RSV_GETBIT(sts, RSV_CRCERROR),
  774. RSV_GETBIT(sts, RSV_LENCHECKERR),
  775. RSV_GETBIT(sts, RSV_LENOUTOFRANGE));
  776. printk(KERN_DEBUG DRV_NAME ": Multicast: %d, Broadcast: %d, "
  777. "LongDropEvent: %d, CarrierEvent: %d\n",
  778. RSV_GETBIT(sts, RSV_RXMULTICAST),
  779. RSV_GETBIT(sts, RSV_RXBROADCAST),
  780. RSV_GETBIT(sts, RSV_RXLONGEVDROPEV),
  781. RSV_GETBIT(sts, RSV_CARRIEREV));
  782. printk(KERN_DEBUG DRV_NAME ": ControlFrame: %d, PauseFrame: %d,"
  783. " UnknownOp: %d, VLanTagFrame: %d\n",
  784. RSV_GETBIT(sts, RSV_RXCONTROLFRAME),
  785. RSV_GETBIT(sts, RSV_RXPAUSEFRAME),
  786. RSV_GETBIT(sts, RSV_RXUNKNOWNOPCODE),
  787. RSV_GETBIT(sts, RSV_RXTYPEVLAN));
  788. }
  789. static void dump_packet(const char *msg, int len, const char *data)
  790. {
  791. printk(KERN_DEBUG DRV_NAME ": %s - packet len:%d\n", msg, len);
  792. print_hex_dump(KERN_DEBUG, "pk data: ", DUMP_PREFIX_OFFSET, 16, 1,
  793. data, len, true);
  794. }
  795. /*
  796. * Hardware receive function.
  797. * Read the buffer memory, update the FIFO pointer to free the buffer,
  798. * check the status vector and decrement the packet counter.
  799. */
  800. static void enc28j60_hw_rx(struct net_device *ndev)
  801. {
  802. struct enc28j60_net *priv = netdev_priv(ndev);
  803. struct sk_buff *skb = NULL;
  804. u16 erxrdpt, next_packet, rxstat;
  805. u8 rsv[RSV_SIZE];
  806. int len;
  807. if (netif_msg_rx_status(priv))
  808. printk(KERN_DEBUG DRV_NAME ": RX pk_addr:0x%04x\n",
  809. priv->next_pk_ptr);
  810. if (unlikely(priv->next_pk_ptr > RXEND_INIT)) {
  811. if (netif_msg_rx_err(priv))
  812. dev_err(&ndev->dev,
  813. "%s() Invalid packet address!! 0x%04x\n",
  814. __func__, priv->next_pk_ptr);
  815. /* packet address corrupted: reset RX logic */
  816. mutex_lock(&priv->lock);
  817. nolock_reg_bfclr(priv, ECON1, ECON1_RXEN);
  818. nolock_reg_bfset(priv, ECON1, ECON1_RXRST);
  819. nolock_reg_bfclr(priv, ECON1, ECON1_RXRST);
  820. nolock_rxfifo_init(priv, RXSTART_INIT, RXEND_INIT);
  821. nolock_reg_bfclr(priv, EIR, EIR_RXERIF);
  822. nolock_reg_bfset(priv, ECON1, ECON1_RXEN);
  823. mutex_unlock(&priv->lock);
  824. ndev->stats.rx_errors++;
  825. return;
  826. }
  827. /* Read next packet pointer and rx status vector */
  828. enc28j60_mem_read(priv, priv->next_pk_ptr, sizeof(rsv), rsv);
  829. next_packet = rsv[1];
  830. next_packet <<= 8;
  831. next_packet |= rsv[0];
  832. len = rsv[3];
  833. len <<= 8;
  834. len |= rsv[2];
  835. rxstat = rsv[5];
  836. rxstat <<= 8;
  837. rxstat |= rsv[4];
  838. if (netif_msg_rx_status(priv))
  839. enc28j60_dump_rsv(priv, __func__, next_packet, len, rxstat);
  840. if (!RSV_GETBIT(rxstat, RSV_RXOK) || len > MAX_FRAMELEN) {
  841. if (netif_msg_rx_err(priv))
  842. dev_err(&ndev->dev, "Rx Error (%04x)\n", rxstat);
  843. ndev->stats.rx_errors++;
  844. if (RSV_GETBIT(rxstat, RSV_CRCERROR))
  845. ndev->stats.rx_crc_errors++;
  846. if (RSV_GETBIT(rxstat, RSV_LENCHECKERR))
  847. ndev->stats.rx_frame_errors++;
  848. if (len > MAX_FRAMELEN)
  849. ndev->stats.rx_over_errors++;
  850. } else {
  851. skb = dev_alloc_skb(len + NET_IP_ALIGN);
  852. if (!skb) {
  853. if (netif_msg_rx_err(priv))
  854. dev_err(&ndev->dev,
  855. "out of memory for Rx'd frame\n");
  856. ndev->stats.rx_dropped++;
  857. } else {
  858. skb->dev = ndev;
  859. skb_reserve(skb, NET_IP_ALIGN);
  860. /* copy the packet from the receive buffer */
  861. enc28j60_mem_read(priv,
  862. rx_packet_start(priv->next_pk_ptr),
  863. len, skb_put(skb, len));
  864. if (netif_msg_pktdata(priv))
  865. dump_packet(__func__, skb->len, skb->data);
  866. skb->protocol = eth_type_trans(skb, ndev);
  867. /* update statistics */
  868. ndev->stats.rx_packets++;
  869. ndev->stats.rx_bytes += len;
  870. netif_rx_ni(skb);
  871. }
  872. }
  873. /*
  874. * Move the RX read pointer to the start of the next
  875. * received packet.
  876. * This frees the memory we just read out
  877. */
  878. erxrdpt = erxrdpt_workaround(next_packet, RXSTART_INIT, RXEND_INIT);
  879. if (netif_msg_hw(priv))
  880. printk(KERN_DEBUG DRV_NAME ": %s() ERXRDPT:0x%04x\n",
  881. __func__, erxrdpt);
  882. mutex_lock(&priv->lock);
  883. nolock_regw_write(priv, ERXRDPTL, erxrdpt);
  884. #ifdef CONFIG_ENC28J60_WRITEVERIFY
  885. if (netif_msg_drv(priv)) {
  886. u16 reg;
  887. reg = nolock_regw_read(priv, ERXRDPTL);
  888. if (reg != erxrdpt)
  889. printk(KERN_DEBUG DRV_NAME ": %s() ERXRDPT verify "
  890. "error (0x%04x - 0x%04x)\n", __func__,
  891. reg, erxrdpt);
  892. }
  893. #endif
  894. priv->next_pk_ptr = next_packet;
  895. /* we are done with this packet, decrement the packet counter */
  896. nolock_reg_bfset(priv, ECON2, ECON2_PKTDEC);
  897. mutex_unlock(&priv->lock);
  898. }
  899. /*
  900. * Calculate free space in RxFIFO
  901. */
  902. static int enc28j60_get_free_rxfifo(struct enc28j60_net *priv)
  903. {
  904. int epkcnt, erxst, erxnd, erxwr, erxrd;
  905. int free_space;
  906. mutex_lock(&priv->lock);
  907. epkcnt = nolock_regb_read(priv, EPKTCNT);
  908. if (epkcnt >= 255)
  909. free_space = -1;
  910. else {
  911. erxst = nolock_regw_read(priv, ERXSTL);
  912. erxnd = nolock_regw_read(priv, ERXNDL);
  913. erxwr = nolock_regw_read(priv, ERXWRPTL);
  914. erxrd = nolock_regw_read(priv, ERXRDPTL);
  915. if (erxwr > erxrd)
  916. free_space = (erxnd - erxst) - (erxwr - erxrd);
  917. else if (erxwr == erxrd)
  918. free_space = (erxnd - erxst);
  919. else
  920. free_space = erxrd - erxwr - 1;
  921. }
  922. mutex_unlock(&priv->lock);
  923. if (netif_msg_rx_status(priv))
  924. printk(KERN_DEBUG DRV_NAME ": %s() free_space = %d\n",
  925. __func__, free_space);
  926. return free_space;
  927. }
  928. /*
  929. * Access the PHY to determine link status
  930. */
  931. static void enc28j60_check_link_status(struct net_device *ndev)
  932. {
  933. struct enc28j60_net *priv = netdev_priv(ndev);
  934. u16 reg;
  935. int duplex;
  936. reg = enc28j60_phy_read(priv, PHSTAT2);
  937. if (netif_msg_hw(priv))
  938. printk(KERN_DEBUG DRV_NAME ": %s() PHSTAT1: %04x, "
  939. "PHSTAT2: %04x\n", __func__,
  940. enc28j60_phy_read(priv, PHSTAT1), reg);
  941. duplex = reg & PHSTAT2_DPXSTAT;
  942. if (reg & PHSTAT2_LSTAT) {
  943. netif_carrier_on(ndev);
  944. if (netif_msg_ifup(priv))
  945. dev_info(&ndev->dev, "link up - %s\n",
  946. duplex ? "Full duplex" : "Half duplex");
  947. } else {
  948. if (netif_msg_ifdown(priv))
  949. dev_info(&ndev->dev, "link down\n");
  950. netif_carrier_off(ndev);
  951. }
  952. }
  953. static void enc28j60_tx_clear(struct net_device *ndev, bool err)
  954. {
  955. struct enc28j60_net *priv = netdev_priv(ndev);
  956. if (err)
  957. ndev->stats.tx_errors++;
  958. else
  959. ndev->stats.tx_packets++;
  960. if (priv->tx_skb) {
  961. if (!err)
  962. ndev->stats.tx_bytes += priv->tx_skb->len;
  963. dev_kfree_skb(priv->tx_skb);
  964. priv->tx_skb = NULL;
  965. }
  966. locked_reg_bfclr(priv, ECON1, ECON1_TXRTS);
  967. netif_wake_queue(ndev);
  968. }
  969. /*
  970. * RX handler
  971. * ignore PKTIF because is unreliable! (look at the errata datasheet)
  972. * check EPKTCNT is the suggested workaround.
  973. * We don't need to clear interrupt flag, automatically done when
  974. * enc28j60_hw_rx() decrements the packet counter.
  975. * Returns how many packet processed.
  976. */
  977. static int enc28j60_rx_interrupt(struct net_device *ndev)
  978. {
  979. struct enc28j60_net *priv = netdev_priv(ndev);
  980. int pk_counter, ret;
  981. pk_counter = locked_regb_read(priv, EPKTCNT);
  982. if (pk_counter && netif_msg_intr(priv))
  983. printk(KERN_DEBUG DRV_NAME ": intRX, pk_cnt: %d\n", pk_counter);
  984. if (pk_counter > priv->max_pk_counter) {
  985. /* update statistics */
  986. priv->max_pk_counter = pk_counter;
  987. if (netif_msg_rx_status(priv) && priv->max_pk_counter > 1)
  988. printk(KERN_DEBUG DRV_NAME ": RX max_pk_cnt: %d\n",
  989. priv->max_pk_counter);
  990. }
  991. ret = pk_counter;
  992. while (pk_counter-- > 0)
  993. enc28j60_hw_rx(ndev);
  994. return ret;
  995. }
  996. static void enc28j60_irq_work_handler(struct work_struct *work)
  997. {
  998. struct enc28j60_net *priv =
  999. container_of(work, struct enc28j60_net, irq_work);
  1000. struct net_device *ndev = priv->netdev;
  1001. int intflags, loop;
  1002. if (netif_msg_intr(priv))
  1003. printk(KERN_DEBUG DRV_NAME ": %s() enter\n", __func__);
  1004. /* disable further interrupts */
  1005. locked_reg_bfclr(priv, EIE, EIE_INTIE);
  1006. do {
  1007. loop = 0;
  1008. intflags = locked_regb_read(priv, EIR);
  1009. /* DMA interrupt handler (not currently used) */
  1010. if ((intflags & EIR_DMAIF) != 0) {
  1011. loop++;
  1012. if (netif_msg_intr(priv))
  1013. printk(KERN_DEBUG DRV_NAME
  1014. ": intDMA(%d)\n", loop);
  1015. locked_reg_bfclr(priv, EIR, EIR_DMAIF);
  1016. }
  1017. /* LINK changed handler */
  1018. if ((intflags & EIR_LINKIF) != 0) {
  1019. loop++;
  1020. if (netif_msg_intr(priv))
  1021. printk(KERN_DEBUG DRV_NAME
  1022. ": intLINK(%d)\n", loop);
  1023. enc28j60_check_link_status(ndev);
  1024. /* read PHIR to clear the flag */
  1025. enc28j60_phy_read(priv, PHIR);
  1026. }
  1027. /* TX complete handler */
  1028. if ((intflags & EIR_TXIF) != 0) {
  1029. bool err = false;
  1030. loop++;
  1031. if (netif_msg_intr(priv))
  1032. printk(KERN_DEBUG DRV_NAME
  1033. ": intTX(%d)\n", loop);
  1034. priv->tx_retry_count = 0;
  1035. if (locked_regb_read(priv, ESTAT) & ESTAT_TXABRT) {
  1036. if (netif_msg_tx_err(priv))
  1037. dev_err(&ndev->dev,
  1038. "Tx Error (aborted)\n");
  1039. err = true;
  1040. }
  1041. if (netif_msg_tx_done(priv)) {
  1042. u8 tsv[TSV_SIZE];
  1043. enc28j60_read_tsv(priv, tsv);
  1044. enc28j60_dump_tsv(priv, "Tx Done", tsv);
  1045. }
  1046. enc28j60_tx_clear(ndev, err);
  1047. locked_reg_bfclr(priv, EIR, EIR_TXIF);
  1048. }
  1049. /* TX Error handler */
  1050. if ((intflags & EIR_TXERIF) != 0) {
  1051. u8 tsv[TSV_SIZE];
  1052. loop++;
  1053. if (netif_msg_intr(priv))
  1054. printk(KERN_DEBUG DRV_NAME
  1055. ": intTXErr(%d)\n", loop);
  1056. locked_reg_bfclr(priv, ECON1, ECON1_TXRTS);
  1057. enc28j60_read_tsv(priv, tsv);
  1058. if (netif_msg_tx_err(priv))
  1059. enc28j60_dump_tsv(priv, "Tx Error", tsv);
  1060. /* Reset TX logic */
  1061. mutex_lock(&priv->lock);
  1062. nolock_reg_bfset(priv, ECON1, ECON1_TXRST);
  1063. nolock_reg_bfclr(priv, ECON1, ECON1_TXRST);
  1064. nolock_txfifo_init(priv, TXSTART_INIT, TXEND_INIT);
  1065. mutex_unlock(&priv->lock);
  1066. /* Transmit Late collision check for retransmit */
  1067. if (TSV_GETBIT(tsv, TSV_TXLATECOLLISION)) {
  1068. if (netif_msg_tx_err(priv))
  1069. printk(KERN_DEBUG DRV_NAME
  1070. ": LateCollision TXErr (%d)\n",
  1071. priv->tx_retry_count);
  1072. if (priv->tx_retry_count++ < MAX_TX_RETRYCOUNT)
  1073. locked_reg_bfset(priv, ECON1,
  1074. ECON1_TXRTS);
  1075. else
  1076. enc28j60_tx_clear(ndev, true);
  1077. } else
  1078. enc28j60_tx_clear(ndev, true);
  1079. locked_reg_bfclr(priv, EIR, EIR_TXERIF);
  1080. }
  1081. /* RX Error handler */
  1082. if ((intflags & EIR_RXERIF) != 0) {
  1083. loop++;
  1084. if (netif_msg_intr(priv))
  1085. printk(KERN_DEBUG DRV_NAME
  1086. ": intRXErr(%d)\n", loop);
  1087. /* Check free FIFO space to flag RX overrun */
  1088. if (enc28j60_get_free_rxfifo(priv) <= 0) {
  1089. if (netif_msg_rx_err(priv))
  1090. printk(KERN_DEBUG DRV_NAME
  1091. ": RX Overrun\n");
  1092. ndev->stats.rx_dropped++;
  1093. }
  1094. locked_reg_bfclr(priv, EIR, EIR_RXERIF);
  1095. }
  1096. /* RX handler */
  1097. if (enc28j60_rx_interrupt(ndev))
  1098. loop++;
  1099. } while (loop);
  1100. /* re-enable interrupts */
  1101. locked_reg_bfset(priv, EIE, EIE_INTIE);
  1102. if (netif_msg_intr(priv))
  1103. printk(KERN_DEBUG DRV_NAME ": %s() exit\n", __func__);
  1104. }
  1105. /*
  1106. * Hardware transmit function.
  1107. * Fill the buffer memory and send the contents of the transmit buffer
  1108. * onto the network
  1109. */
  1110. static void enc28j60_hw_tx(struct enc28j60_net *priv)
  1111. {
  1112. if (netif_msg_tx_queued(priv))
  1113. printk(KERN_DEBUG DRV_NAME
  1114. ": Tx Packet Len:%d\n", priv->tx_skb->len);
  1115. if (netif_msg_pktdata(priv))
  1116. dump_packet(__func__,
  1117. priv->tx_skb->len, priv->tx_skb->data);
  1118. enc28j60_packet_write(priv, priv->tx_skb->len, priv->tx_skb->data);
  1119. #ifdef CONFIG_ENC28J60_WRITEVERIFY
  1120. /* readback and verify written data */
  1121. if (netif_msg_drv(priv)) {
  1122. int test_len, k;
  1123. u8 test_buf[64]; /* limit the test to the first 64 bytes */
  1124. int okflag;
  1125. test_len = priv->tx_skb->len;
  1126. if (test_len > sizeof(test_buf))
  1127. test_len = sizeof(test_buf);
  1128. /* + 1 to skip control byte */
  1129. enc28j60_mem_read(priv, TXSTART_INIT + 1, test_len, test_buf);
  1130. okflag = 1;
  1131. for (k = 0; k < test_len; k++) {
  1132. if (priv->tx_skb->data[k] != test_buf[k]) {
  1133. printk(KERN_DEBUG DRV_NAME
  1134. ": Error, %d location differ: "
  1135. "0x%02x-0x%02x\n", k,
  1136. priv->tx_skb->data[k], test_buf[k]);
  1137. okflag = 0;
  1138. }
  1139. }
  1140. if (!okflag)
  1141. printk(KERN_DEBUG DRV_NAME ": Tx write buffer, "
  1142. "verify ERROR!\n");
  1143. }
  1144. #endif
  1145. /* set TX request flag */
  1146. locked_reg_bfset(priv, ECON1, ECON1_TXRTS);
  1147. }
  1148. static int enc28j60_send_packet(struct sk_buff *skb, struct net_device *dev)
  1149. {
  1150. struct enc28j60_net *priv = netdev_priv(dev);
  1151. if (netif_msg_tx_queued(priv))
  1152. printk(KERN_DEBUG DRV_NAME ": %s() enter\n", __func__);
  1153. /* If some error occurs while trying to transmit this
  1154. * packet, you should return '1' from this function.
  1155. * In such a case you _may not_ do anything to the
  1156. * SKB, it is still owned by the network queueing
  1157. * layer when an error is returned. This means you
  1158. * may not modify any SKB fields, you may not free
  1159. * the SKB, etc.
  1160. */
  1161. netif_stop_queue(dev);
  1162. /* save the timestamp */
  1163. priv->netdev->trans_start = jiffies;
  1164. /* Remember the skb for deferred processing */
  1165. priv->tx_skb = skb;
  1166. schedule_work(&priv->tx_work);
  1167. return 0;
  1168. }
  1169. static void enc28j60_tx_work_handler(struct work_struct *work)
  1170. {
  1171. struct enc28j60_net *priv =
  1172. container_of(work, struct enc28j60_net, tx_work);
  1173. /* actual delivery of data */
  1174. enc28j60_hw_tx(priv);
  1175. }
  1176. static irqreturn_t enc28j60_irq(int irq, void *dev_id)
  1177. {
  1178. struct enc28j60_net *priv = dev_id;
  1179. /*
  1180. * Can't do anything in interrupt context because we need to
  1181. * block (spi_sync() is blocking) so fire of the interrupt
  1182. * handling workqueue.
  1183. * Remember that we access enc28j60 registers through SPI bus
  1184. * via spi_sync() call.
  1185. */
  1186. schedule_work(&priv->irq_work);
  1187. return IRQ_HANDLED;
  1188. }
  1189. static void enc28j60_tx_timeout(struct net_device *ndev)
  1190. {
  1191. struct enc28j60_net *priv = netdev_priv(ndev);
  1192. if (netif_msg_timer(priv))
  1193. dev_err(&ndev->dev, DRV_NAME " tx timeout\n");
  1194. ndev->stats.tx_errors++;
  1195. /* can't restart safely under softirq */
  1196. schedule_work(&priv->restart_work);
  1197. }
  1198. /*
  1199. * Open/initialize the board. This is called (in the current kernel)
  1200. * sometime after booting when the 'ifconfig' program is run.
  1201. *
  1202. * This routine should set everything up anew at each open, even
  1203. * registers that "should" only need to be set once at boot, so that
  1204. * there is non-reboot way to recover if something goes wrong.
  1205. */
  1206. static int enc28j60_net_open(struct net_device *dev)
  1207. {
  1208. struct enc28j60_net *priv = netdev_priv(dev);
  1209. if (netif_msg_drv(priv))
  1210. printk(KERN_DEBUG DRV_NAME ": %s() enter\n", __func__);
  1211. if (!is_valid_ether_addr(dev->dev_addr)) {
  1212. if (netif_msg_ifup(priv))
  1213. dev_err(&dev->dev, "invalid MAC address %pM\n",
  1214. dev->dev_addr);
  1215. return -EADDRNOTAVAIL;
  1216. }
  1217. /* Reset the hardware here (and take it out of low power mode) */
  1218. enc28j60_lowpower(priv, false);
  1219. enc28j60_hw_disable(priv);
  1220. if (!enc28j60_hw_init(priv)) {
  1221. if (netif_msg_ifup(priv))
  1222. dev_err(&dev->dev, "hw_reset() failed\n");
  1223. return -EINVAL;
  1224. }
  1225. /* Update the MAC address (in case user has changed it) */
  1226. enc28j60_set_hw_macaddr(dev);
  1227. /* Enable interrupts */
  1228. enc28j60_hw_enable(priv);
  1229. /* check link status */
  1230. enc28j60_check_link_status(dev);
  1231. /* We are now ready to accept transmit requests from
  1232. * the queueing layer of the networking.
  1233. */
  1234. netif_start_queue(dev);
  1235. return 0;
  1236. }
  1237. /* The inverse routine to net_open(). */
  1238. static int enc28j60_net_close(struct net_device *dev)
  1239. {
  1240. struct enc28j60_net *priv = netdev_priv(dev);
  1241. if (netif_msg_drv(priv))
  1242. printk(KERN_DEBUG DRV_NAME ": %s() enter\n", __func__);
  1243. enc28j60_hw_disable(priv);
  1244. enc28j60_lowpower(priv, true);
  1245. netif_stop_queue(dev);
  1246. return 0;
  1247. }
  1248. /*
  1249. * Set or clear the multicast filter for this adapter
  1250. * num_addrs == -1 Promiscuous mode, receive all packets
  1251. * num_addrs == 0 Normal mode, filter out multicast packets
  1252. * num_addrs > 0 Multicast mode, receive normal and MC packets
  1253. */
  1254. static void enc28j60_set_multicast_list(struct net_device *dev)
  1255. {
  1256. struct enc28j60_net *priv = netdev_priv(dev);
  1257. int oldfilter = priv->rxfilter;
  1258. if (dev->flags & IFF_PROMISC) {
  1259. if (netif_msg_link(priv))
  1260. dev_info(&dev->dev, "promiscuous mode\n");
  1261. priv->rxfilter = RXFILTER_PROMISC;
  1262. } else if ((dev->flags & IFF_ALLMULTI) || dev->mc_count) {
  1263. if (netif_msg_link(priv))
  1264. dev_info(&dev->dev, "%smulticast mode\n",
  1265. (dev->flags & IFF_ALLMULTI) ? "all-" : "");
  1266. priv->rxfilter = RXFILTER_MULTI;
  1267. } else {
  1268. if (netif_msg_link(priv))
  1269. dev_info(&dev->dev, "normal mode\n");
  1270. priv->rxfilter = RXFILTER_NORMAL;
  1271. }
  1272. if (oldfilter != priv->rxfilter)
  1273. schedule_work(&priv->setrx_work);
  1274. }
  1275. static void enc28j60_setrx_work_handler(struct work_struct *work)
  1276. {
  1277. struct enc28j60_net *priv =
  1278. container_of(work, struct enc28j60_net, setrx_work);
  1279. if (priv->rxfilter == RXFILTER_PROMISC) {
  1280. if (netif_msg_drv(priv))
  1281. printk(KERN_DEBUG DRV_NAME ": promiscuous mode\n");
  1282. locked_regb_write(priv, ERXFCON, 0x00);
  1283. } else if (priv->rxfilter == RXFILTER_MULTI) {
  1284. if (netif_msg_drv(priv))
  1285. printk(KERN_DEBUG DRV_NAME ": multicast mode\n");
  1286. locked_regb_write(priv, ERXFCON,
  1287. ERXFCON_UCEN | ERXFCON_CRCEN |
  1288. ERXFCON_BCEN | ERXFCON_MCEN);
  1289. } else {
  1290. if (netif_msg_drv(priv))
  1291. printk(KERN_DEBUG DRV_NAME ": normal mode\n");
  1292. locked_regb_write(priv, ERXFCON,
  1293. ERXFCON_UCEN | ERXFCON_CRCEN |
  1294. ERXFCON_BCEN);
  1295. }
  1296. }
  1297. static void enc28j60_restart_work_handler(struct work_struct *work)
  1298. {
  1299. struct enc28j60_net *priv =
  1300. container_of(work, struct enc28j60_net, restart_work);
  1301. struct net_device *ndev = priv->netdev;
  1302. int ret;
  1303. rtnl_lock();
  1304. if (netif_running(ndev)) {
  1305. enc28j60_net_close(ndev);
  1306. ret = enc28j60_net_open(ndev);
  1307. if (unlikely(ret)) {
  1308. dev_info(&ndev->dev, " could not restart %d\n", ret);
  1309. dev_close(ndev);
  1310. }
  1311. }
  1312. rtnl_unlock();
  1313. }
  1314. /* ......................... ETHTOOL SUPPORT ........................... */
  1315. static void
  1316. enc28j60_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
  1317. {
  1318. strlcpy(info->driver, DRV_NAME, sizeof(info->driver));
  1319. strlcpy(info->version, DRV_VERSION, sizeof(info->version));
  1320. strlcpy(info->bus_info,
  1321. dev_name(dev->dev.parent), sizeof(info->bus_info));
  1322. }
  1323. static int
  1324. enc28j60_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  1325. {
  1326. struct enc28j60_net *priv = netdev_priv(dev);
  1327. cmd->transceiver = XCVR_INTERNAL;
  1328. cmd->supported = SUPPORTED_10baseT_Half
  1329. | SUPPORTED_10baseT_Full
  1330. | SUPPORTED_TP;
  1331. cmd->speed = SPEED_10;
  1332. cmd->duplex = priv->full_duplex ? DUPLEX_FULL : DUPLEX_HALF;
  1333. cmd->port = PORT_TP;
  1334. cmd->autoneg = AUTONEG_DISABLE;
  1335. return 0;
  1336. }
  1337. static int
  1338. enc28j60_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  1339. {
  1340. return enc28j60_setlink(dev, cmd->autoneg, cmd->speed, cmd->duplex);
  1341. }
  1342. static u32 enc28j60_get_msglevel(struct net_device *dev)
  1343. {
  1344. struct enc28j60_net *priv = netdev_priv(dev);
  1345. return priv->msg_enable;
  1346. }
  1347. static void enc28j60_set_msglevel(struct net_device *dev, u32 val)
  1348. {
  1349. struct enc28j60_net *priv = netdev_priv(dev);
  1350. priv->msg_enable = val;
  1351. }
  1352. static const struct ethtool_ops enc28j60_ethtool_ops = {
  1353. .get_settings = enc28j60_get_settings,
  1354. .set_settings = enc28j60_set_settings,
  1355. .get_drvinfo = enc28j60_get_drvinfo,
  1356. .get_msglevel = enc28j60_get_msglevel,
  1357. .set_msglevel = enc28j60_set_msglevel,
  1358. };
  1359. static int enc28j60_chipset_init(struct net_device *dev)
  1360. {
  1361. struct enc28j60_net *priv = netdev_priv(dev);
  1362. return enc28j60_hw_init(priv);
  1363. }
  1364. static const struct net_device_ops enc28j60_netdev_ops = {
  1365. .ndo_open = enc28j60_net_open,
  1366. .ndo_stop = enc28j60_net_close,
  1367. .ndo_start_xmit = enc28j60_send_packet,
  1368. .ndo_set_multicast_list = enc28j60_set_multicast_list,
  1369. .ndo_set_mac_address = enc28j60_set_mac_address,
  1370. .ndo_tx_timeout = enc28j60_tx_timeout,
  1371. .ndo_change_mtu = eth_change_mtu,
  1372. .ndo_validate_addr = eth_validate_addr,
  1373. };
  1374. static int __devinit enc28j60_probe(struct spi_device *spi)
  1375. {
  1376. struct net_device *dev;
  1377. struct enc28j60_net *priv;
  1378. int ret = 0;
  1379. if (netif_msg_drv(&debug))
  1380. dev_info(&spi->dev, DRV_NAME " Ethernet driver %s loaded\n",
  1381. DRV_VERSION);
  1382. dev = alloc_etherdev(sizeof(struct enc28j60_net));
  1383. if (!dev) {
  1384. if (netif_msg_drv(&debug))
  1385. dev_err(&spi->dev, DRV_NAME
  1386. ": unable to alloc new ethernet\n");
  1387. ret = -ENOMEM;
  1388. goto error_alloc;
  1389. }
  1390. priv = netdev_priv(dev);
  1391. priv->netdev = dev; /* priv to netdev reference */
  1392. priv->spi = spi; /* priv to spi reference */
  1393. priv->msg_enable = netif_msg_init(debug.msg_enable,
  1394. ENC28J60_MSG_DEFAULT);
  1395. mutex_init(&priv->lock);
  1396. INIT_WORK(&priv->tx_work, enc28j60_tx_work_handler);
  1397. INIT_WORK(&priv->setrx_work, enc28j60_setrx_work_handler);
  1398. INIT_WORK(&priv->irq_work, enc28j60_irq_work_handler);
  1399. INIT_WORK(&priv->restart_work, enc28j60_restart_work_handler);
  1400. dev_set_drvdata(&spi->dev, priv); /* spi to priv reference */
  1401. SET_NETDEV_DEV(dev, &spi->dev);
  1402. if (!enc28j60_chipset_init(dev)) {
  1403. if (netif_msg_probe(priv))
  1404. dev_info(&spi->dev, DRV_NAME " chip not found\n");
  1405. ret = -EIO;
  1406. goto error_irq;
  1407. }
  1408. random_ether_addr(dev->dev_addr);
  1409. enc28j60_set_hw_macaddr(dev);
  1410. /* Board setup must set the relevant edge trigger type;
  1411. * level triggers won't currently work.
  1412. */
  1413. ret = request_irq(spi->irq, enc28j60_irq, 0, DRV_NAME, priv);
  1414. if (ret < 0) {
  1415. if (netif_msg_probe(priv))
  1416. dev_err(&spi->dev, DRV_NAME ": request irq %d failed "
  1417. "(ret = %d)\n", spi->irq, ret);
  1418. goto error_irq;
  1419. }
  1420. dev->if_port = IF_PORT_10BASET;
  1421. dev->irq = spi->irq;
  1422. dev->netdev_ops = &enc28j60_netdev_ops;
  1423. dev->watchdog_timeo = TX_TIMEOUT;
  1424. SET_ETHTOOL_OPS(dev, &enc28j60_ethtool_ops);
  1425. enc28j60_lowpower(priv, true);
  1426. ret = register_netdev(dev);
  1427. if (ret) {
  1428. if (netif_msg_probe(priv))
  1429. dev_err(&spi->dev, "register netdev " DRV_NAME
  1430. " failed (ret = %d)\n", ret);
  1431. goto error_register;
  1432. }
  1433. dev_info(&dev->dev, DRV_NAME " driver registered\n");
  1434. return 0;
  1435. error_register:
  1436. free_irq(spi->irq, priv);
  1437. error_irq:
  1438. free_netdev(dev);
  1439. error_alloc:
  1440. return ret;
  1441. }
  1442. static int __devexit enc28j60_remove(struct spi_device *spi)
  1443. {
  1444. struct enc28j60_net *priv = dev_get_drvdata(&spi->dev);
  1445. if (netif_msg_drv(priv))
  1446. printk(KERN_DEBUG DRV_NAME ": remove\n");
  1447. unregister_netdev(priv->netdev);
  1448. free_irq(spi->irq, priv);
  1449. free_netdev(priv->netdev);
  1450. return 0;
  1451. }
  1452. static struct spi_driver enc28j60_driver = {
  1453. .driver = {
  1454. .name = DRV_NAME,
  1455. .owner = THIS_MODULE,
  1456. },
  1457. .probe = enc28j60_probe,
  1458. .remove = __devexit_p(enc28j60_remove),
  1459. };
  1460. static int __init enc28j60_init(void)
  1461. {
  1462. msec20_to_jiffies = msecs_to_jiffies(20);
  1463. return spi_register_driver(&enc28j60_driver);
  1464. }
  1465. module_init(enc28j60_init);
  1466. static void __exit enc28j60_exit(void)
  1467. {
  1468. spi_unregister_driver(&enc28j60_driver);
  1469. }
  1470. module_exit(enc28j60_exit);
  1471. MODULE_DESCRIPTION(DRV_NAME " ethernet driver");
  1472. MODULE_AUTHOR("Claudio Lanconelli <lanconelli.claudio@eptar.com>");
  1473. MODULE_LICENSE("GPL");
  1474. module_param_named(debug, debug.msg_enable, int, 0);
  1475. MODULE_PARM_DESC(debug, "Debug verbosity level (0=none, ..., ffff=all)");