enc28j60.c 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665
  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/string.h>
  21. #include <linux/errno.h>
  22. #include <linux/init.h>
  23. #include <linux/netdevice.h>
  24. #include <linux/etherdevice.h>
  25. #include <linux/ethtool.h>
  26. #include <linux/tcp.h>
  27. #include <linux/skbuff.h>
  28. #include <linux/delay.h>
  29. #include <linux/spi/spi.h>
  30. #include "enc28j60_hw.h"
  31. #define DRV_NAME "enc28j60"
  32. #define DRV_VERSION "1.01"
  33. #define SPI_OPLEN 1
  34. #define ENC28J60_MSG_DEFAULT \
  35. (NETIF_MSG_PROBE | NETIF_MSG_IFUP | NETIF_MSG_IFDOWN | NETIF_MSG_LINK)
  36. /* Buffer size required for the largest SPI transfer (i.e., reading a
  37. * frame). */
  38. #define SPI_TRANSFER_BUF_LEN (4 + MAX_FRAMELEN)
  39. #define TX_TIMEOUT (4 * HZ)
  40. /* Max TX retries in case of collision as suggested by errata datasheet */
  41. #define MAX_TX_RETRYCOUNT 16
  42. enum {
  43. RXFILTER_NORMAL,
  44. RXFILTER_MULTI,
  45. RXFILTER_PROMISC
  46. };
  47. /* Driver local data */
  48. struct enc28j60_net {
  49. struct net_device *netdev;
  50. struct spi_device *spi;
  51. struct mutex lock;
  52. struct sk_buff *tx_skb;
  53. struct work_struct tx_work;
  54. struct work_struct irq_work;
  55. struct work_struct setrx_work;
  56. struct work_struct restart_work;
  57. u8 bank; /* current register bank selected */
  58. u16 next_pk_ptr; /* next packet pointer within FIFO */
  59. u16 max_pk_counter; /* statistics: max packet counter */
  60. u16 tx_retry_count;
  61. bool hw_enable;
  62. bool full_duplex;
  63. int rxfilter;
  64. u32 msg_enable;
  65. u8 spi_transfer_buf[SPI_TRANSFER_BUF_LEN];
  66. };
  67. /* use ethtool to change the level for any given device */
  68. static struct {
  69. u32 msg_enable;
  70. } debug = { -1 };
  71. /*
  72. * SPI read buffer
  73. * wait for the SPI transfer and copy received data to destination
  74. */
  75. static int
  76. spi_read_buf(struct enc28j60_net *priv, int len, u8 *data)
  77. {
  78. u8 *rx_buf = priv->spi_transfer_buf + 4;
  79. u8 *tx_buf = priv->spi_transfer_buf;
  80. struct spi_transfer t = {
  81. .tx_buf = tx_buf,
  82. .rx_buf = rx_buf,
  83. .len = SPI_OPLEN + len,
  84. };
  85. struct spi_message msg;
  86. int ret;
  87. tx_buf[0] = ENC28J60_READ_BUF_MEM;
  88. tx_buf[1] = tx_buf[2] = tx_buf[3] = 0; /* don't care */
  89. spi_message_init(&msg);
  90. spi_message_add_tail(&t, &msg);
  91. ret = spi_sync(priv->spi, &msg);
  92. if (ret == 0) {
  93. memcpy(data, &rx_buf[SPI_OPLEN], len);
  94. ret = msg.status;
  95. }
  96. if (ret && netif_msg_drv(priv))
  97. printk(KERN_DEBUG DRV_NAME ": %s() failed: ret = %d\n",
  98. __func__, ret);
  99. return ret;
  100. }
  101. /*
  102. * SPI write buffer
  103. */
  104. static int spi_write_buf(struct enc28j60_net *priv, int len,
  105. const u8 *data)
  106. {
  107. int ret;
  108. if (len > SPI_TRANSFER_BUF_LEN - 1 || len <= 0)
  109. ret = -EINVAL;
  110. else {
  111. priv->spi_transfer_buf[0] = ENC28J60_WRITE_BUF_MEM;
  112. memcpy(&priv->spi_transfer_buf[1], data, len);
  113. ret = spi_write(priv->spi, priv->spi_transfer_buf, len + 1);
  114. if (ret && netif_msg_drv(priv))
  115. printk(KERN_DEBUG DRV_NAME ": %s() failed: ret = %d\n",
  116. __func__, ret);
  117. }
  118. return ret;
  119. }
  120. /*
  121. * basic SPI read operation
  122. */
  123. static u8 spi_read_op(struct enc28j60_net *priv, u8 op,
  124. u8 addr)
  125. {
  126. u8 tx_buf[2];
  127. u8 rx_buf[4];
  128. u8 val = 0;
  129. int ret;
  130. int slen = SPI_OPLEN;
  131. /* do dummy read if needed */
  132. if (addr & SPRD_MASK)
  133. slen++;
  134. tx_buf[0] = op | (addr & ADDR_MASK);
  135. ret = spi_write_then_read(priv->spi, tx_buf, 1, rx_buf, slen);
  136. if (ret)
  137. printk(KERN_DEBUG DRV_NAME ": %s() failed: ret = %d\n",
  138. __func__, ret);
  139. else
  140. val = rx_buf[slen - 1];
  141. return val;
  142. }
  143. /*
  144. * basic SPI write operation
  145. */
  146. static int spi_write_op(struct enc28j60_net *priv, u8 op,
  147. u8 addr, u8 val)
  148. {
  149. int ret;
  150. priv->spi_transfer_buf[0] = op | (addr & ADDR_MASK);
  151. priv->spi_transfer_buf[1] = val;
  152. ret = spi_write(priv->spi, priv->spi_transfer_buf, 2);
  153. if (ret && netif_msg_drv(priv))
  154. printk(KERN_DEBUG DRV_NAME ": %s() failed: ret = %d\n",
  155. __func__, ret);
  156. return ret;
  157. }
  158. static void enc28j60_soft_reset(struct enc28j60_net *priv)
  159. {
  160. if (netif_msg_hw(priv))
  161. printk(KERN_DEBUG DRV_NAME ": %s() enter\n", __func__);
  162. spi_write_op(priv, ENC28J60_SOFT_RESET, 0, ENC28J60_SOFT_RESET);
  163. /* Errata workaround #1, CLKRDY check is unreliable,
  164. * delay at least 1 mS instead */
  165. udelay(2000);
  166. }
  167. /*
  168. * select the current register bank if necessary
  169. */
  170. static void enc28j60_set_bank(struct enc28j60_net *priv, u8 addr)
  171. {
  172. u8 b = (addr & BANK_MASK) >> 5;
  173. /* These registers (EIE, EIR, ESTAT, ECON2, ECON1)
  174. * are present in all banks, no need to switch bank
  175. */
  176. if (addr >= EIE && addr <= ECON1)
  177. return;
  178. /* Clear or set each bank selection bit as needed */
  179. if ((b & ECON1_BSEL0) != (priv->bank & ECON1_BSEL0)) {
  180. if (b & ECON1_BSEL0)
  181. spi_write_op(priv, ENC28J60_BIT_FIELD_SET, ECON1,
  182. ECON1_BSEL0);
  183. else
  184. spi_write_op(priv, ENC28J60_BIT_FIELD_CLR, ECON1,
  185. ECON1_BSEL0);
  186. }
  187. if ((b & ECON1_BSEL1) != (priv->bank & ECON1_BSEL1)) {
  188. if (b & ECON1_BSEL1)
  189. spi_write_op(priv, ENC28J60_BIT_FIELD_SET, ECON1,
  190. ECON1_BSEL1);
  191. else
  192. spi_write_op(priv, ENC28J60_BIT_FIELD_CLR, ECON1,
  193. ECON1_BSEL1);
  194. }
  195. priv->bank = b;
  196. }
  197. /*
  198. * Register access routines through the SPI bus.
  199. * Every register access comes in two flavours:
  200. * - nolock_xxx: caller needs to invoke mutex_lock, usually to access
  201. * atomically more than one register
  202. * - locked_xxx: caller doesn't need to invoke mutex_lock, single access
  203. *
  204. * Some registers can be accessed through the bit field clear and
  205. * bit field set to avoid a read modify write cycle.
  206. */
  207. /*
  208. * Register bit field Set
  209. */
  210. static void nolock_reg_bfset(struct enc28j60_net *priv,
  211. u8 addr, u8 mask)
  212. {
  213. enc28j60_set_bank(priv, addr);
  214. spi_write_op(priv, ENC28J60_BIT_FIELD_SET, addr, mask);
  215. }
  216. static void locked_reg_bfset(struct enc28j60_net *priv,
  217. u8 addr, u8 mask)
  218. {
  219. mutex_lock(&priv->lock);
  220. nolock_reg_bfset(priv, addr, mask);
  221. mutex_unlock(&priv->lock);
  222. }
  223. /*
  224. * Register bit field Clear
  225. */
  226. static void nolock_reg_bfclr(struct enc28j60_net *priv,
  227. u8 addr, u8 mask)
  228. {
  229. enc28j60_set_bank(priv, addr);
  230. spi_write_op(priv, ENC28J60_BIT_FIELD_CLR, addr, mask);
  231. }
  232. static void locked_reg_bfclr(struct enc28j60_net *priv,
  233. u8 addr, u8 mask)
  234. {
  235. mutex_lock(&priv->lock);
  236. nolock_reg_bfclr(priv, addr, mask);
  237. mutex_unlock(&priv->lock);
  238. }
  239. /*
  240. * Register byte read
  241. */
  242. static int nolock_regb_read(struct enc28j60_net *priv,
  243. u8 address)
  244. {
  245. enc28j60_set_bank(priv, address);
  246. return spi_read_op(priv, ENC28J60_READ_CTRL_REG, address);
  247. }
  248. static int locked_regb_read(struct enc28j60_net *priv,
  249. u8 address)
  250. {
  251. int ret;
  252. mutex_lock(&priv->lock);
  253. ret = nolock_regb_read(priv, address);
  254. mutex_unlock(&priv->lock);
  255. return ret;
  256. }
  257. /*
  258. * Register word read
  259. */
  260. static int nolock_regw_read(struct enc28j60_net *priv,
  261. u8 address)
  262. {
  263. int rl, rh;
  264. enc28j60_set_bank(priv, address);
  265. rl = spi_read_op(priv, ENC28J60_READ_CTRL_REG, address);
  266. rh = spi_read_op(priv, ENC28J60_READ_CTRL_REG, address + 1);
  267. return (rh << 8) | rl;
  268. }
  269. static int locked_regw_read(struct enc28j60_net *priv,
  270. u8 address)
  271. {
  272. int ret;
  273. mutex_lock(&priv->lock);
  274. ret = nolock_regw_read(priv, address);
  275. mutex_unlock(&priv->lock);
  276. return ret;
  277. }
  278. /*
  279. * Register byte write
  280. */
  281. static void nolock_regb_write(struct enc28j60_net *priv,
  282. u8 address, u8 data)
  283. {
  284. enc28j60_set_bank(priv, address);
  285. spi_write_op(priv, ENC28J60_WRITE_CTRL_REG, address, data);
  286. }
  287. static void locked_regb_write(struct enc28j60_net *priv,
  288. u8 address, u8 data)
  289. {
  290. mutex_lock(&priv->lock);
  291. nolock_regb_write(priv, address, data);
  292. mutex_unlock(&priv->lock);
  293. }
  294. /*
  295. * Register word write
  296. */
  297. static void nolock_regw_write(struct enc28j60_net *priv,
  298. u8 address, u16 data)
  299. {
  300. enc28j60_set_bank(priv, address);
  301. spi_write_op(priv, ENC28J60_WRITE_CTRL_REG, address, (u8) data);
  302. spi_write_op(priv, ENC28J60_WRITE_CTRL_REG, address + 1,
  303. (u8) (data >> 8));
  304. }
  305. static void locked_regw_write(struct enc28j60_net *priv,
  306. u8 address, u16 data)
  307. {
  308. mutex_lock(&priv->lock);
  309. nolock_regw_write(priv, address, data);
  310. mutex_unlock(&priv->lock);
  311. }
  312. /*
  313. * Buffer memory read
  314. * Select the starting address and execute a SPI buffer read
  315. */
  316. static void enc28j60_mem_read(struct enc28j60_net *priv,
  317. u16 addr, int len, u8 *data)
  318. {
  319. mutex_lock(&priv->lock);
  320. nolock_regw_write(priv, ERDPTL, addr);
  321. #ifdef CONFIG_ENC28J60_WRITEVERIFY
  322. if (netif_msg_drv(priv)) {
  323. u16 reg;
  324. reg = nolock_regw_read(priv, ERDPTL);
  325. if (reg != addr)
  326. printk(KERN_DEBUG DRV_NAME ": %s() error writing ERDPT "
  327. "(0x%04x - 0x%04x)\n", __func__, reg, addr);
  328. }
  329. #endif
  330. spi_read_buf(priv, len, data);
  331. mutex_unlock(&priv->lock);
  332. }
  333. /*
  334. * Write packet to enc28j60 TX buffer memory
  335. */
  336. static void
  337. enc28j60_packet_write(struct enc28j60_net *priv, int len, const u8 *data)
  338. {
  339. mutex_lock(&priv->lock);
  340. /* Set the write pointer to start of transmit buffer area */
  341. nolock_regw_write(priv, EWRPTL, TXSTART_INIT);
  342. #ifdef CONFIG_ENC28J60_WRITEVERIFY
  343. if (netif_msg_drv(priv)) {
  344. u16 reg;
  345. reg = nolock_regw_read(priv, EWRPTL);
  346. if (reg != TXSTART_INIT)
  347. printk(KERN_DEBUG DRV_NAME
  348. ": %s() ERWPT:0x%04x != 0x%04x\n",
  349. __func__, reg, TXSTART_INIT);
  350. }
  351. #endif
  352. /* Set the TXND pointer to correspond to the packet size given */
  353. nolock_regw_write(priv, ETXNDL, TXSTART_INIT + len);
  354. /* write per-packet control byte */
  355. spi_write_op(priv, ENC28J60_WRITE_BUF_MEM, 0, 0x00);
  356. if (netif_msg_hw(priv))
  357. printk(KERN_DEBUG DRV_NAME
  358. ": %s() after control byte ERWPT:0x%04x\n",
  359. __func__, nolock_regw_read(priv, EWRPTL));
  360. /* copy the packet into the transmit buffer */
  361. spi_write_buf(priv, len, data);
  362. if (netif_msg_hw(priv))
  363. printk(KERN_DEBUG DRV_NAME
  364. ": %s() after write packet ERWPT:0x%04x, len=%d\n",
  365. __func__, nolock_regw_read(priv, EWRPTL), len);
  366. mutex_unlock(&priv->lock);
  367. }
  368. static unsigned long msec20_to_jiffies;
  369. static int poll_ready(struct enc28j60_net *priv, u8 reg, u8 mask, u8 val)
  370. {
  371. unsigned long timeout = jiffies + msec20_to_jiffies;
  372. /* 20 msec timeout read */
  373. while ((nolock_regb_read(priv, reg) & mask) != val) {
  374. if (time_after(jiffies, timeout)) {
  375. if (netif_msg_drv(priv))
  376. dev_dbg(&priv->spi->dev,
  377. "reg %02x ready timeout!\n", reg);
  378. return -ETIMEDOUT;
  379. }
  380. cpu_relax();
  381. }
  382. return 0;
  383. }
  384. /*
  385. * Wait until the PHY operation is complete.
  386. */
  387. static int wait_phy_ready(struct enc28j60_net *priv)
  388. {
  389. return poll_ready(priv, MISTAT, MISTAT_BUSY, 0) ? 0 : 1;
  390. }
  391. /*
  392. * PHY register read
  393. * PHY registers are not accessed directly, but through the MII
  394. */
  395. static u16 enc28j60_phy_read(struct enc28j60_net *priv, u8 address)
  396. {
  397. u16 ret;
  398. mutex_lock(&priv->lock);
  399. /* set the PHY register address */
  400. nolock_regb_write(priv, MIREGADR, address);
  401. /* start the register read operation */
  402. nolock_regb_write(priv, MICMD, MICMD_MIIRD);
  403. /* wait until the PHY read completes */
  404. wait_phy_ready(priv);
  405. /* quit reading */
  406. nolock_regb_write(priv, MICMD, 0x00);
  407. /* return the data */
  408. ret = nolock_regw_read(priv, MIRDL);
  409. mutex_unlock(&priv->lock);
  410. return ret;
  411. }
  412. static int enc28j60_phy_write(struct enc28j60_net *priv, u8 address, u16 data)
  413. {
  414. int ret;
  415. mutex_lock(&priv->lock);
  416. /* set the PHY register address */
  417. nolock_regb_write(priv, MIREGADR, address);
  418. /* write the PHY data */
  419. nolock_regw_write(priv, MIWRL, data);
  420. /* wait until the PHY write completes and return */
  421. ret = wait_phy_ready(priv);
  422. mutex_unlock(&priv->lock);
  423. return ret;
  424. }
  425. /*
  426. * Program the hardware MAC address from dev->dev_addr.
  427. */
  428. static int enc28j60_set_hw_macaddr(struct net_device *ndev)
  429. {
  430. int ret;
  431. struct enc28j60_net *priv = netdev_priv(ndev);
  432. mutex_lock(&priv->lock);
  433. if (!priv->hw_enable) {
  434. if (netif_msg_drv(priv))
  435. printk(KERN_INFO DRV_NAME
  436. ": %s: Setting MAC address to %pM\n",
  437. ndev->name, ndev->dev_addr);
  438. /* NOTE: MAC address in ENC28J60 is byte-backward */
  439. nolock_regb_write(priv, MAADR5, ndev->dev_addr[0]);
  440. nolock_regb_write(priv, MAADR4, ndev->dev_addr[1]);
  441. nolock_regb_write(priv, MAADR3, ndev->dev_addr[2]);
  442. nolock_regb_write(priv, MAADR2, ndev->dev_addr[3]);
  443. nolock_regb_write(priv, MAADR1, ndev->dev_addr[4]);
  444. nolock_regb_write(priv, MAADR0, ndev->dev_addr[5]);
  445. ret = 0;
  446. } else {
  447. if (netif_msg_drv(priv))
  448. printk(KERN_DEBUG DRV_NAME
  449. ": %s() Hardware must be disabled to set "
  450. "Mac address\n", __func__);
  451. ret = -EBUSY;
  452. }
  453. mutex_unlock(&priv->lock);
  454. return ret;
  455. }
  456. /*
  457. * Store the new hardware address in dev->dev_addr, and update the MAC.
  458. */
  459. static int enc28j60_set_mac_address(struct net_device *dev, void *addr)
  460. {
  461. struct sockaddr *address = addr;
  462. if (netif_running(dev))
  463. return -EBUSY;
  464. if (!is_valid_ether_addr(address->sa_data))
  465. return -EADDRNOTAVAIL;
  466. dev->addr_assign_type &= ~NET_ADDR_RANDOM;
  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, TSV_SIZE, 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 = netdev_alloc_skb(ndev, 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_reserve(skb, NET_IP_ALIGN);
  859. /* copy the packet from the receive buffer */
  860. enc28j60_mem_read(priv,
  861. rx_packet_start(priv->next_pk_ptr),
  862. len, skb_put(skb, len));
  863. if (netif_msg_pktdata(priv))
  864. dump_packet(__func__, skb->len, skb->data);
  865. skb->protocol = eth_type_trans(skb, ndev);
  866. /* update statistics */
  867. ndev->stats.rx_packets++;
  868. ndev->stats.rx_bytes += len;
  869. netif_rx_ni(skb);
  870. }
  871. }
  872. /*
  873. * Move the RX read pointer to the start of the next
  874. * received packet.
  875. * This frees the memory we just read out
  876. */
  877. erxrdpt = erxrdpt_workaround(next_packet, RXSTART_INIT, RXEND_INIT);
  878. if (netif_msg_hw(priv))
  879. printk(KERN_DEBUG DRV_NAME ": %s() ERXRDPT:0x%04x\n",
  880. __func__, erxrdpt);
  881. mutex_lock(&priv->lock);
  882. nolock_regw_write(priv, ERXRDPTL, erxrdpt);
  883. #ifdef CONFIG_ENC28J60_WRITEVERIFY
  884. if (netif_msg_drv(priv)) {
  885. u16 reg;
  886. reg = nolock_regw_read(priv, ERXRDPTL);
  887. if (reg != erxrdpt)
  888. printk(KERN_DEBUG DRV_NAME ": %s() ERXRDPT verify "
  889. "error (0x%04x - 0x%04x)\n", __func__,
  890. reg, erxrdpt);
  891. }
  892. #endif
  893. priv->next_pk_ptr = next_packet;
  894. /* we are done with this packet, decrement the packet counter */
  895. nolock_reg_bfset(priv, ECON2, ECON2_PKTDEC);
  896. mutex_unlock(&priv->lock);
  897. }
  898. /*
  899. * Calculate free space in RxFIFO
  900. */
  901. static int enc28j60_get_free_rxfifo(struct enc28j60_net *priv)
  902. {
  903. int epkcnt, erxst, erxnd, erxwr, erxrd;
  904. int free_space;
  905. mutex_lock(&priv->lock);
  906. epkcnt = nolock_regb_read(priv, EPKTCNT);
  907. if (epkcnt >= 255)
  908. free_space = -1;
  909. else {
  910. erxst = nolock_regw_read(priv, ERXSTL);
  911. erxnd = nolock_regw_read(priv, ERXNDL);
  912. erxwr = nolock_regw_read(priv, ERXWRPTL);
  913. erxrd = nolock_regw_read(priv, ERXRDPTL);
  914. if (erxwr > erxrd)
  915. free_space = (erxnd - erxst) - (erxwr - erxrd);
  916. else if (erxwr == erxrd)
  917. free_space = (erxnd - erxst);
  918. else
  919. free_space = erxrd - erxwr - 1;
  920. }
  921. mutex_unlock(&priv->lock);
  922. if (netif_msg_rx_status(priv))
  923. printk(KERN_DEBUG DRV_NAME ": %s() free_space = %d\n",
  924. __func__, free_space);
  925. return free_space;
  926. }
  927. /*
  928. * Access the PHY to determine link status
  929. */
  930. static void enc28j60_check_link_status(struct net_device *ndev)
  931. {
  932. struct enc28j60_net *priv = netdev_priv(ndev);
  933. u16 reg;
  934. int duplex;
  935. reg = enc28j60_phy_read(priv, PHSTAT2);
  936. if (netif_msg_hw(priv))
  937. printk(KERN_DEBUG DRV_NAME ": %s() PHSTAT1: %04x, "
  938. "PHSTAT2: %04x\n", __func__,
  939. enc28j60_phy_read(priv, PHSTAT1), reg);
  940. duplex = reg & PHSTAT2_DPXSTAT;
  941. if (reg & PHSTAT2_LSTAT) {
  942. netif_carrier_on(ndev);
  943. if (netif_msg_ifup(priv))
  944. dev_info(&ndev->dev, "link up - %s\n",
  945. duplex ? "Full duplex" : "Half duplex");
  946. } else {
  947. if (netif_msg_ifdown(priv))
  948. dev_info(&ndev->dev, "link down\n");
  949. netif_carrier_off(ndev);
  950. }
  951. }
  952. static void enc28j60_tx_clear(struct net_device *ndev, bool err)
  953. {
  954. struct enc28j60_net *priv = netdev_priv(ndev);
  955. if (err)
  956. ndev->stats.tx_errors++;
  957. else
  958. ndev->stats.tx_packets++;
  959. if (priv->tx_skb) {
  960. if (!err)
  961. ndev->stats.tx_bytes += priv->tx_skb->len;
  962. dev_kfree_skb(priv->tx_skb);
  963. priv->tx_skb = NULL;
  964. }
  965. locked_reg_bfclr(priv, ECON1, ECON1_TXRTS);
  966. netif_wake_queue(ndev);
  967. }
  968. /*
  969. * RX handler
  970. * ignore PKTIF because is unreliable! (look at the errata datasheet)
  971. * check EPKTCNT is the suggested workaround.
  972. * We don't need to clear interrupt flag, automatically done when
  973. * enc28j60_hw_rx() decrements the packet counter.
  974. * Returns how many packet processed.
  975. */
  976. static int enc28j60_rx_interrupt(struct net_device *ndev)
  977. {
  978. struct enc28j60_net *priv = netdev_priv(ndev);
  979. int pk_counter, ret;
  980. pk_counter = locked_regb_read(priv, EPKTCNT);
  981. if (pk_counter && netif_msg_intr(priv))
  982. printk(KERN_DEBUG DRV_NAME ": intRX, pk_cnt: %d\n", pk_counter);
  983. if (pk_counter > priv->max_pk_counter) {
  984. /* update statistics */
  985. priv->max_pk_counter = pk_counter;
  986. if (netif_msg_rx_status(priv) && priv->max_pk_counter > 1)
  987. printk(KERN_DEBUG DRV_NAME ": RX max_pk_cnt: %d\n",
  988. priv->max_pk_counter);
  989. }
  990. ret = pk_counter;
  991. while (pk_counter-- > 0)
  992. enc28j60_hw_rx(ndev);
  993. return ret;
  994. }
  995. static void enc28j60_irq_work_handler(struct work_struct *work)
  996. {
  997. struct enc28j60_net *priv =
  998. container_of(work, struct enc28j60_net, irq_work);
  999. struct net_device *ndev = priv->netdev;
  1000. int intflags, loop;
  1001. if (netif_msg_intr(priv))
  1002. printk(KERN_DEBUG DRV_NAME ": %s() enter\n", __func__);
  1003. /* disable further interrupts */
  1004. locked_reg_bfclr(priv, EIE, EIE_INTIE);
  1005. do {
  1006. loop = 0;
  1007. intflags = locked_regb_read(priv, EIR);
  1008. /* DMA interrupt handler (not currently used) */
  1009. if ((intflags & EIR_DMAIF) != 0) {
  1010. loop++;
  1011. if (netif_msg_intr(priv))
  1012. printk(KERN_DEBUG DRV_NAME
  1013. ": intDMA(%d)\n", loop);
  1014. locked_reg_bfclr(priv, EIR, EIR_DMAIF);
  1015. }
  1016. /* LINK changed handler */
  1017. if ((intflags & EIR_LINKIF) != 0) {
  1018. loop++;
  1019. if (netif_msg_intr(priv))
  1020. printk(KERN_DEBUG DRV_NAME
  1021. ": intLINK(%d)\n", loop);
  1022. enc28j60_check_link_status(ndev);
  1023. /* read PHIR to clear the flag */
  1024. enc28j60_phy_read(priv, PHIR);
  1025. }
  1026. /* TX complete handler */
  1027. if ((intflags & EIR_TXIF) != 0) {
  1028. bool err = false;
  1029. loop++;
  1030. if (netif_msg_intr(priv))
  1031. printk(KERN_DEBUG DRV_NAME
  1032. ": intTX(%d)\n", loop);
  1033. priv->tx_retry_count = 0;
  1034. if (locked_regb_read(priv, ESTAT) & ESTAT_TXABRT) {
  1035. if (netif_msg_tx_err(priv))
  1036. dev_err(&ndev->dev,
  1037. "Tx Error (aborted)\n");
  1038. err = true;
  1039. }
  1040. if (netif_msg_tx_done(priv)) {
  1041. u8 tsv[TSV_SIZE];
  1042. enc28j60_read_tsv(priv, tsv);
  1043. enc28j60_dump_tsv(priv, "Tx Done", tsv);
  1044. }
  1045. enc28j60_tx_clear(ndev, err);
  1046. locked_reg_bfclr(priv, EIR, EIR_TXIF);
  1047. }
  1048. /* TX Error handler */
  1049. if ((intflags & EIR_TXERIF) != 0) {
  1050. u8 tsv[TSV_SIZE];
  1051. loop++;
  1052. if (netif_msg_intr(priv))
  1053. printk(KERN_DEBUG DRV_NAME
  1054. ": intTXErr(%d)\n", loop);
  1055. locked_reg_bfclr(priv, ECON1, ECON1_TXRTS);
  1056. enc28j60_read_tsv(priv, tsv);
  1057. if (netif_msg_tx_err(priv))
  1058. enc28j60_dump_tsv(priv, "Tx Error", tsv);
  1059. /* Reset TX logic */
  1060. mutex_lock(&priv->lock);
  1061. nolock_reg_bfset(priv, ECON1, ECON1_TXRST);
  1062. nolock_reg_bfclr(priv, ECON1, ECON1_TXRST);
  1063. nolock_txfifo_init(priv, TXSTART_INIT, TXEND_INIT);
  1064. mutex_unlock(&priv->lock);
  1065. /* Transmit Late collision check for retransmit */
  1066. if (TSV_GETBIT(tsv, TSV_TXLATECOLLISION)) {
  1067. if (netif_msg_tx_err(priv))
  1068. printk(KERN_DEBUG DRV_NAME
  1069. ": LateCollision TXErr (%d)\n",
  1070. priv->tx_retry_count);
  1071. if (priv->tx_retry_count++ < MAX_TX_RETRYCOUNT)
  1072. locked_reg_bfset(priv, ECON1,
  1073. ECON1_TXRTS);
  1074. else
  1075. enc28j60_tx_clear(ndev, true);
  1076. } else
  1077. enc28j60_tx_clear(ndev, true);
  1078. locked_reg_bfclr(priv, EIR, EIR_TXERIF);
  1079. }
  1080. /* RX Error handler */
  1081. if ((intflags & EIR_RXERIF) != 0) {
  1082. loop++;
  1083. if (netif_msg_intr(priv))
  1084. printk(KERN_DEBUG DRV_NAME
  1085. ": intRXErr(%d)\n", loop);
  1086. /* Check free FIFO space to flag RX overrun */
  1087. if (enc28j60_get_free_rxfifo(priv) <= 0) {
  1088. if (netif_msg_rx_err(priv))
  1089. printk(KERN_DEBUG DRV_NAME
  1090. ": RX Overrun\n");
  1091. ndev->stats.rx_dropped++;
  1092. }
  1093. locked_reg_bfclr(priv, EIR, EIR_RXERIF);
  1094. }
  1095. /* RX handler */
  1096. if (enc28j60_rx_interrupt(ndev))
  1097. loop++;
  1098. } while (loop);
  1099. /* re-enable interrupts */
  1100. locked_reg_bfset(priv, EIE, EIE_INTIE);
  1101. if (netif_msg_intr(priv))
  1102. printk(KERN_DEBUG DRV_NAME ": %s() exit\n", __func__);
  1103. }
  1104. /*
  1105. * Hardware transmit function.
  1106. * Fill the buffer memory and send the contents of the transmit buffer
  1107. * onto the network
  1108. */
  1109. static void enc28j60_hw_tx(struct enc28j60_net *priv)
  1110. {
  1111. if (netif_msg_tx_queued(priv))
  1112. printk(KERN_DEBUG DRV_NAME
  1113. ": Tx Packet Len:%d\n", priv->tx_skb->len);
  1114. if (netif_msg_pktdata(priv))
  1115. dump_packet(__func__,
  1116. priv->tx_skb->len, priv->tx_skb->data);
  1117. enc28j60_packet_write(priv, priv->tx_skb->len, priv->tx_skb->data);
  1118. #ifdef CONFIG_ENC28J60_WRITEVERIFY
  1119. /* readback and verify written data */
  1120. if (netif_msg_drv(priv)) {
  1121. int test_len, k;
  1122. u8 test_buf[64]; /* limit the test to the first 64 bytes */
  1123. int okflag;
  1124. test_len = priv->tx_skb->len;
  1125. if (test_len > sizeof(test_buf))
  1126. test_len = sizeof(test_buf);
  1127. /* + 1 to skip control byte */
  1128. enc28j60_mem_read(priv, TXSTART_INIT + 1, test_len, test_buf);
  1129. okflag = 1;
  1130. for (k = 0; k < test_len; k++) {
  1131. if (priv->tx_skb->data[k] != test_buf[k]) {
  1132. printk(KERN_DEBUG DRV_NAME
  1133. ": Error, %d location differ: "
  1134. "0x%02x-0x%02x\n", k,
  1135. priv->tx_skb->data[k], test_buf[k]);
  1136. okflag = 0;
  1137. }
  1138. }
  1139. if (!okflag)
  1140. printk(KERN_DEBUG DRV_NAME ": Tx write buffer, "
  1141. "verify ERROR!\n");
  1142. }
  1143. #endif
  1144. /* set TX request flag */
  1145. locked_reg_bfset(priv, ECON1, ECON1_TXRTS);
  1146. }
  1147. static netdev_tx_t enc28j60_send_packet(struct sk_buff *skb,
  1148. 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. /* Remember the skb for deferred processing */
  1163. priv->tx_skb = skb;
  1164. schedule_work(&priv->tx_work);
  1165. return NETDEV_TX_OK;
  1166. }
  1167. static void enc28j60_tx_work_handler(struct work_struct *work)
  1168. {
  1169. struct enc28j60_net *priv =
  1170. container_of(work, struct enc28j60_net, tx_work);
  1171. /* actual delivery of data */
  1172. enc28j60_hw_tx(priv);
  1173. }
  1174. static irqreturn_t enc28j60_irq(int irq, void *dev_id)
  1175. {
  1176. struct enc28j60_net *priv = dev_id;
  1177. /*
  1178. * Can't do anything in interrupt context because we need to
  1179. * block (spi_sync() is blocking) so fire of the interrupt
  1180. * handling workqueue.
  1181. * Remember that we access enc28j60 registers through SPI bus
  1182. * via spi_sync() call.
  1183. */
  1184. schedule_work(&priv->irq_work);
  1185. return IRQ_HANDLED;
  1186. }
  1187. static void enc28j60_tx_timeout(struct net_device *ndev)
  1188. {
  1189. struct enc28j60_net *priv = netdev_priv(ndev);
  1190. if (netif_msg_timer(priv))
  1191. dev_err(&ndev->dev, DRV_NAME " tx timeout\n");
  1192. ndev->stats.tx_errors++;
  1193. /* can't restart safely under softirq */
  1194. schedule_work(&priv->restart_work);
  1195. }
  1196. /*
  1197. * Open/initialize the board. This is called (in the current kernel)
  1198. * sometime after booting when the 'ifconfig' program is run.
  1199. *
  1200. * This routine should set everything up anew at each open, even
  1201. * registers that "should" only need to be set once at boot, so that
  1202. * there is non-reboot way to recover if something goes wrong.
  1203. */
  1204. static int enc28j60_net_open(struct net_device *dev)
  1205. {
  1206. struct enc28j60_net *priv = netdev_priv(dev);
  1207. if (netif_msg_drv(priv))
  1208. printk(KERN_DEBUG DRV_NAME ": %s() enter\n", __func__);
  1209. if (!is_valid_ether_addr(dev->dev_addr)) {
  1210. if (netif_msg_ifup(priv))
  1211. dev_err(&dev->dev, "invalid MAC address %pM\n",
  1212. dev->dev_addr);
  1213. return -EADDRNOTAVAIL;
  1214. }
  1215. /* Reset the hardware here (and take it out of low power mode) */
  1216. enc28j60_lowpower(priv, false);
  1217. enc28j60_hw_disable(priv);
  1218. if (!enc28j60_hw_init(priv)) {
  1219. if (netif_msg_ifup(priv))
  1220. dev_err(&dev->dev, "hw_reset() failed\n");
  1221. return -EINVAL;
  1222. }
  1223. /* Update the MAC address (in case user has changed it) */
  1224. enc28j60_set_hw_macaddr(dev);
  1225. /* Enable interrupts */
  1226. enc28j60_hw_enable(priv);
  1227. /* check link status */
  1228. enc28j60_check_link_status(dev);
  1229. /* We are now ready to accept transmit requests from
  1230. * the queueing layer of the networking.
  1231. */
  1232. netif_start_queue(dev);
  1233. return 0;
  1234. }
  1235. /* The inverse routine to net_open(). */
  1236. static int enc28j60_net_close(struct net_device *dev)
  1237. {
  1238. struct enc28j60_net *priv = netdev_priv(dev);
  1239. if (netif_msg_drv(priv))
  1240. printk(KERN_DEBUG DRV_NAME ": %s() enter\n", __func__);
  1241. enc28j60_hw_disable(priv);
  1242. enc28j60_lowpower(priv, true);
  1243. netif_stop_queue(dev);
  1244. return 0;
  1245. }
  1246. /*
  1247. * Set or clear the multicast filter for this adapter
  1248. * num_addrs == -1 Promiscuous mode, receive all packets
  1249. * num_addrs == 0 Normal mode, filter out multicast packets
  1250. * num_addrs > 0 Multicast mode, receive normal and MC packets
  1251. */
  1252. static void enc28j60_set_multicast_list(struct net_device *dev)
  1253. {
  1254. struct enc28j60_net *priv = netdev_priv(dev);
  1255. int oldfilter = priv->rxfilter;
  1256. if (dev->flags & IFF_PROMISC) {
  1257. if (netif_msg_link(priv))
  1258. dev_info(&dev->dev, "promiscuous mode\n");
  1259. priv->rxfilter = RXFILTER_PROMISC;
  1260. } else if ((dev->flags & IFF_ALLMULTI) || !netdev_mc_empty(dev)) {
  1261. if (netif_msg_link(priv))
  1262. dev_info(&dev->dev, "%smulticast mode\n",
  1263. (dev->flags & IFF_ALLMULTI) ? "all-" : "");
  1264. priv->rxfilter = RXFILTER_MULTI;
  1265. } else {
  1266. if (netif_msg_link(priv))
  1267. dev_info(&dev->dev, "normal mode\n");
  1268. priv->rxfilter = RXFILTER_NORMAL;
  1269. }
  1270. if (oldfilter != priv->rxfilter)
  1271. schedule_work(&priv->setrx_work);
  1272. }
  1273. static void enc28j60_setrx_work_handler(struct work_struct *work)
  1274. {
  1275. struct enc28j60_net *priv =
  1276. container_of(work, struct enc28j60_net, setrx_work);
  1277. if (priv->rxfilter == RXFILTER_PROMISC) {
  1278. if (netif_msg_drv(priv))
  1279. printk(KERN_DEBUG DRV_NAME ": promiscuous mode\n");
  1280. locked_regb_write(priv, ERXFCON, 0x00);
  1281. } else if (priv->rxfilter == RXFILTER_MULTI) {
  1282. if (netif_msg_drv(priv))
  1283. printk(KERN_DEBUG DRV_NAME ": multicast mode\n");
  1284. locked_regb_write(priv, ERXFCON,
  1285. ERXFCON_UCEN | ERXFCON_CRCEN |
  1286. ERXFCON_BCEN | ERXFCON_MCEN);
  1287. } else {
  1288. if (netif_msg_drv(priv))
  1289. printk(KERN_DEBUG DRV_NAME ": normal mode\n");
  1290. locked_regb_write(priv, ERXFCON,
  1291. ERXFCON_UCEN | ERXFCON_CRCEN |
  1292. ERXFCON_BCEN);
  1293. }
  1294. }
  1295. static void enc28j60_restart_work_handler(struct work_struct *work)
  1296. {
  1297. struct enc28j60_net *priv =
  1298. container_of(work, struct enc28j60_net, restart_work);
  1299. struct net_device *ndev = priv->netdev;
  1300. int ret;
  1301. rtnl_lock();
  1302. if (netif_running(ndev)) {
  1303. enc28j60_net_close(ndev);
  1304. ret = enc28j60_net_open(ndev);
  1305. if (unlikely(ret)) {
  1306. dev_info(&ndev->dev, " could not restart %d\n", ret);
  1307. dev_close(ndev);
  1308. }
  1309. }
  1310. rtnl_unlock();
  1311. }
  1312. /* ......................... ETHTOOL SUPPORT ........................... */
  1313. static void
  1314. enc28j60_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
  1315. {
  1316. strlcpy(info->driver, DRV_NAME, sizeof(info->driver));
  1317. strlcpy(info->version, DRV_VERSION, sizeof(info->version));
  1318. strlcpy(info->bus_info,
  1319. dev_name(dev->dev.parent), sizeof(info->bus_info));
  1320. }
  1321. static int
  1322. enc28j60_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  1323. {
  1324. struct enc28j60_net *priv = netdev_priv(dev);
  1325. cmd->transceiver = XCVR_INTERNAL;
  1326. cmd->supported = SUPPORTED_10baseT_Half
  1327. | SUPPORTED_10baseT_Full
  1328. | SUPPORTED_TP;
  1329. ethtool_cmd_speed_set(cmd, SPEED_10);
  1330. cmd->duplex = priv->full_duplex ? DUPLEX_FULL : DUPLEX_HALF;
  1331. cmd->port = PORT_TP;
  1332. cmd->autoneg = AUTONEG_DISABLE;
  1333. return 0;
  1334. }
  1335. static int
  1336. enc28j60_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  1337. {
  1338. return enc28j60_setlink(dev, cmd->autoneg,
  1339. ethtool_cmd_speed(cmd), cmd->duplex);
  1340. }
  1341. static u32 enc28j60_get_msglevel(struct net_device *dev)
  1342. {
  1343. struct enc28j60_net *priv = netdev_priv(dev);
  1344. return priv->msg_enable;
  1345. }
  1346. static void enc28j60_set_msglevel(struct net_device *dev, u32 val)
  1347. {
  1348. struct enc28j60_net *priv = netdev_priv(dev);
  1349. priv->msg_enable = val;
  1350. }
  1351. static const struct ethtool_ops enc28j60_ethtool_ops = {
  1352. .get_settings = enc28j60_get_settings,
  1353. .set_settings = enc28j60_set_settings,
  1354. .get_drvinfo = enc28j60_get_drvinfo,
  1355. .get_msglevel = enc28j60_get_msglevel,
  1356. .set_msglevel = enc28j60_set_msglevel,
  1357. };
  1358. static int enc28j60_chipset_init(struct net_device *dev)
  1359. {
  1360. struct enc28j60_net *priv = netdev_priv(dev);
  1361. return enc28j60_hw_init(priv);
  1362. }
  1363. static const struct net_device_ops enc28j60_netdev_ops = {
  1364. .ndo_open = enc28j60_net_open,
  1365. .ndo_stop = enc28j60_net_close,
  1366. .ndo_start_xmit = enc28j60_send_packet,
  1367. .ndo_set_rx_mode = enc28j60_set_multicast_list,
  1368. .ndo_set_mac_address = enc28j60_set_mac_address,
  1369. .ndo_tx_timeout = enc28j60_tx_timeout,
  1370. .ndo_change_mtu = eth_change_mtu,
  1371. .ndo_validate_addr = eth_validate_addr,
  1372. };
  1373. static int __devinit enc28j60_probe(struct spi_device *spi)
  1374. {
  1375. struct net_device *dev;
  1376. struct enc28j60_net *priv;
  1377. int ret = 0;
  1378. if (netif_msg_drv(&debug))
  1379. dev_info(&spi->dev, DRV_NAME " Ethernet driver %s loaded\n",
  1380. DRV_VERSION);
  1381. dev = alloc_etherdev(sizeof(struct enc28j60_net));
  1382. if (!dev) {
  1383. ret = -ENOMEM;
  1384. goto error_alloc;
  1385. }
  1386. priv = netdev_priv(dev);
  1387. priv->netdev = dev; /* priv to netdev reference */
  1388. priv->spi = spi; /* priv to spi reference */
  1389. priv->msg_enable = netif_msg_init(debug.msg_enable,
  1390. ENC28J60_MSG_DEFAULT);
  1391. mutex_init(&priv->lock);
  1392. INIT_WORK(&priv->tx_work, enc28j60_tx_work_handler);
  1393. INIT_WORK(&priv->setrx_work, enc28j60_setrx_work_handler);
  1394. INIT_WORK(&priv->irq_work, enc28j60_irq_work_handler);
  1395. INIT_WORK(&priv->restart_work, enc28j60_restart_work_handler);
  1396. dev_set_drvdata(&spi->dev, priv); /* spi to priv reference */
  1397. SET_NETDEV_DEV(dev, &spi->dev);
  1398. if (!enc28j60_chipset_init(dev)) {
  1399. if (netif_msg_probe(priv))
  1400. dev_info(&spi->dev, DRV_NAME " chip not found\n");
  1401. ret = -EIO;
  1402. goto error_irq;
  1403. }
  1404. eth_hw_addr_random(dev);
  1405. enc28j60_set_hw_macaddr(dev);
  1406. /* Board setup must set the relevant edge trigger type;
  1407. * level triggers won't currently work.
  1408. */
  1409. ret = request_irq(spi->irq, enc28j60_irq, 0, DRV_NAME, priv);
  1410. if (ret < 0) {
  1411. if (netif_msg_probe(priv))
  1412. dev_err(&spi->dev, DRV_NAME ": request irq %d failed "
  1413. "(ret = %d)\n", spi->irq, ret);
  1414. goto error_irq;
  1415. }
  1416. dev->if_port = IF_PORT_10BASET;
  1417. dev->irq = spi->irq;
  1418. dev->netdev_ops = &enc28j60_netdev_ops;
  1419. dev->watchdog_timeo = TX_TIMEOUT;
  1420. SET_ETHTOOL_OPS(dev, &enc28j60_ethtool_ops);
  1421. enc28j60_lowpower(priv, true);
  1422. ret = register_netdev(dev);
  1423. if (ret) {
  1424. if (netif_msg_probe(priv))
  1425. dev_err(&spi->dev, "register netdev " DRV_NAME
  1426. " failed (ret = %d)\n", ret);
  1427. goto error_register;
  1428. }
  1429. dev_info(&dev->dev, DRV_NAME " driver registered\n");
  1430. return 0;
  1431. error_register:
  1432. free_irq(spi->irq, priv);
  1433. error_irq:
  1434. free_netdev(dev);
  1435. error_alloc:
  1436. return ret;
  1437. }
  1438. static int __devexit enc28j60_remove(struct spi_device *spi)
  1439. {
  1440. struct enc28j60_net *priv = dev_get_drvdata(&spi->dev);
  1441. if (netif_msg_drv(priv))
  1442. printk(KERN_DEBUG DRV_NAME ": remove\n");
  1443. unregister_netdev(priv->netdev);
  1444. free_irq(spi->irq, priv);
  1445. free_netdev(priv->netdev);
  1446. return 0;
  1447. }
  1448. static struct spi_driver enc28j60_driver = {
  1449. .driver = {
  1450. .name = DRV_NAME,
  1451. .owner = THIS_MODULE,
  1452. },
  1453. .probe = enc28j60_probe,
  1454. .remove = __devexit_p(enc28j60_remove),
  1455. };
  1456. static int __init enc28j60_init(void)
  1457. {
  1458. msec20_to_jiffies = msecs_to_jiffies(20);
  1459. return spi_register_driver(&enc28j60_driver);
  1460. }
  1461. module_init(enc28j60_init);
  1462. static void __exit enc28j60_exit(void)
  1463. {
  1464. spi_unregister_driver(&enc28j60_driver);
  1465. }
  1466. module_exit(enc28j60_exit);
  1467. MODULE_DESCRIPTION(DRV_NAME " ethernet driver");
  1468. MODULE_AUTHOR("Claudio Lanconelli <lanconelli.claudio@eptar.com>");
  1469. MODULE_LICENSE("GPL");
  1470. module_param_named(debug, debug.msg_enable, int, 0);
  1471. MODULE_PARM_DESC(debug, "Debug verbosity level (0=none, ..., ffff=all)");
  1472. MODULE_ALIAS("spi:" DRV_NAME);