enc28j60.c 45 KB

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