hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/drivers/net/ethernet/microchip/enc28j60.c
....@@ -1,14 +1,10 @@
1
+// SPDX-License-Identifier: GPL-2.0+
12 /*
23 * Microchip ENC28J60 ethernet driver (MAC + PHY)
34 *
45 * Copyright (C) 2007 Eurek srl
56 * Author: Claudio Lanconelli <lanconelli.claudio@eptar.com>
67 * 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.
128 *
139 * $Id: enc28j60.c,v 1.22 2007/12/20 10:47:01 claudio Exp $
1410 */
....@@ -18,9 +14,9 @@
1814 #include <linux/types.h>
1915 #include <linux/fcntl.h>
2016 #include <linux/interrupt.h>
17
+#include <linux/property.h>
2118 #include <linux/string.h>
2219 #include <linux/errno.h>
23
-#include <linux/init.h>
2420 #include <linux/netdevice.h>
2521 #include <linux/etherdevice.h>
2622 #include <linux/ethtool.h>
....@@ -28,7 +24,6 @@
2824 #include <linux/skbuff.h>
2925 #include <linux/delay.h>
3026 #include <linux/spi/spi.h>
31
-#include <linux/of_net.h>
3227
3328 #include "enc28j60_hw.h"
3429
....@@ -41,10 +36,11 @@
4136 (NETIF_MSG_PROBE | NETIF_MSG_IFUP | NETIF_MSG_IFDOWN | NETIF_MSG_LINK)
4237
4338 /* Buffer size required for the largest SPI transfer (i.e., reading a
44
- * frame). */
39
+ * frame).
40
+ */
4541 #define SPI_TRANSFER_BUF_LEN (4 + MAX_FRAMELEN)
4642
47
-#define TX_TIMEOUT (4 * HZ)
43
+#define TX_TIMEOUT (4 * HZ)
4844
4945 /* Max TX retries in case of collision as suggested by errata datasheet */
5046 #define MAX_TX_RETRYCOUNT 16
....@@ -83,11 +79,12 @@
8379
8480 /*
8581 * SPI read buffer
86
- * wait for the SPI transfer and copy received data to destination
82
+ * Wait for the SPI transfer and copy received data to destination.
8783 */
8884 static int
8985 spi_read_buf(struct enc28j60_net *priv, int len, u8 *data)
9086 {
87
+ struct device *dev = &priv->spi->dev;
9188 u8 *rx_buf = priv->spi_transfer_buf + 4;
9289 u8 *tx_buf = priv->spi_transfer_buf;
9390 struct spi_transfer tx = {
....@@ -113,8 +110,8 @@
113110 ret = msg.status;
114111 }
115112 if (ret && netif_msg_drv(priv))
116
- printk(KERN_DEBUG DRV_NAME ": %s() failed: ret = %d\n",
117
- __func__, ret);
113
+ dev_printk(KERN_DEBUG, dev, "%s() failed: ret = %d\n",
114
+ __func__, ret);
118115
119116 return ret;
120117 }
....@@ -122,9 +119,9 @@
122119 /*
123120 * SPI write buffer
124121 */
125
-static int spi_write_buf(struct enc28j60_net *priv, int len,
126
- const u8 *data)
122
+static int spi_write_buf(struct enc28j60_net *priv, int len, const u8 *data)
127123 {
124
+ struct device *dev = &priv->spi->dev;
128125 int ret;
129126
130127 if (len > SPI_TRANSFER_BUF_LEN - 1 || len <= 0)
....@@ -134,8 +131,8 @@
134131 memcpy(&priv->spi_transfer_buf[1], data, len);
135132 ret = spi_write(priv->spi, priv->spi_transfer_buf, len + 1);
136133 if (ret && netif_msg_drv(priv))
137
- printk(KERN_DEBUG DRV_NAME ": %s() failed: ret = %d\n",
138
- __func__, ret);
134
+ dev_printk(KERN_DEBUG, dev, "%s() failed: ret = %d\n",
135
+ __func__, ret);
139136 }
140137 return ret;
141138 }
....@@ -143,9 +140,9 @@
143140 /*
144141 * basic SPI read operation
145142 */
146
-static u8 spi_read_op(struct enc28j60_net *priv, u8 op,
147
- u8 addr)
143
+static u8 spi_read_op(struct enc28j60_net *priv, u8 op, u8 addr)
148144 {
145
+ struct device *dev = &priv->spi->dev;
149146 u8 tx_buf[2];
150147 u8 rx_buf[4];
151148 u8 val = 0;
....@@ -159,8 +156,8 @@
159156 tx_buf[0] = op | (addr & ADDR_MASK);
160157 ret = spi_write_then_read(priv->spi, tx_buf, 1, rx_buf, slen);
161158 if (ret)
162
- printk(KERN_DEBUG DRV_NAME ": %s() failed: ret = %d\n",
163
- __func__, ret);
159
+ dev_printk(KERN_DEBUG, dev, "%s() failed: ret = %d\n",
160
+ __func__, ret);
164161 else
165162 val = rx_buf[slen - 1];
166163
....@@ -170,28 +167,25 @@
170167 /*
171168 * basic SPI write operation
172169 */
173
-static int spi_write_op(struct enc28j60_net *priv, u8 op,
174
- u8 addr, u8 val)
170
+static int spi_write_op(struct enc28j60_net *priv, u8 op, u8 addr, u8 val)
175171 {
172
+ struct device *dev = &priv->spi->dev;
176173 int ret;
177174
178175 priv->spi_transfer_buf[0] = op | (addr & ADDR_MASK);
179176 priv->spi_transfer_buf[1] = val;
180177 ret = spi_write(priv->spi, priv->spi_transfer_buf, 2);
181178 if (ret && netif_msg_drv(priv))
182
- printk(KERN_DEBUG DRV_NAME ": %s() failed: ret = %d\n",
183
- __func__, ret);
179
+ dev_printk(KERN_DEBUG, dev, "%s() failed: ret = %d\n",
180
+ __func__, ret);
184181 return ret;
185182 }
186183
187184 static void enc28j60_soft_reset(struct enc28j60_net *priv)
188185 {
189
- if (netif_msg_hw(priv))
190
- printk(KERN_DEBUG DRV_NAME ": %s() enter\n", __func__);
191
-
192186 spi_write_op(priv, ENC28J60_SOFT_RESET, 0, ENC28J60_SOFT_RESET);
193187 /* Errata workaround #1, CLKRDY check is unreliable,
194
- * delay at least 1 mS instead */
188
+ * delay at least 1 ms instead */
195189 udelay(2000);
196190 }
197191
....@@ -203,7 +197,7 @@
203197 u8 b = (addr & BANK_MASK) >> 5;
204198
205199 /* These registers (EIE, EIR, ESTAT, ECON2, ECON1)
206
- * are present in all banks, no need to switch bank
200
+ * are present in all banks, no need to switch bank.
207201 */
208202 if (addr >= EIE && addr <= ECON1)
209203 return;
....@@ -242,15 +236,13 @@
242236 /*
243237 * Register bit field Set
244238 */
245
-static void nolock_reg_bfset(struct enc28j60_net *priv,
246
- u8 addr, u8 mask)
239
+static void nolock_reg_bfset(struct enc28j60_net *priv, u8 addr, u8 mask)
247240 {
248241 enc28j60_set_bank(priv, addr);
249242 spi_write_op(priv, ENC28J60_BIT_FIELD_SET, addr, mask);
250243 }
251244
252
-static void locked_reg_bfset(struct enc28j60_net *priv,
253
- u8 addr, u8 mask)
245
+static void locked_reg_bfset(struct enc28j60_net *priv, u8 addr, u8 mask)
254246 {
255247 mutex_lock(&priv->lock);
256248 nolock_reg_bfset(priv, addr, mask);
....@@ -260,15 +252,13 @@
260252 /*
261253 * Register bit field Clear
262254 */
263
-static void nolock_reg_bfclr(struct enc28j60_net *priv,
264
- u8 addr, u8 mask)
255
+static void nolock_reg_bfclr(struct enc28j60_net *priv, u8 addr, u8 mask)
265256 {
266257 enc28j60_set_bank(priv, addr);
267258 spi_write_op(priv, ENC28J60_BIT_FIELD_CLR, addr, mask);
268259 }
269260
270
-static void locked_reg_bfclr(struct enc28j60_net *priv,
271
- u8 addr, u8 mask)
261
+static void locked_reg_bfclr(struct enc28j60_net *priv, u8 addr, u8 mask)
272262 {
273263 mutex_lock(&priv->lock);
274264 nolock_reg_bfclr(priv, addr, mask);
....@@ -278,15 +268,13 @@
278268 /*
279269 * Register byte read
280270 */
281
-static int nolock_regb_read(struct enc28j60_net *priv,
282
- u8 address)
271
+static int nolock_regb_read(struct enc28j60_net *priv, u8 address)
283272 {
284273 enc28j60_set_bank(priv, address);
285274 return spi_read_op(priv, ENC28J60_READ_CTRL_REG, address);
286275 }
287276
288
-static int locked_regb_read(struct enc28j60_net *priv,
289
- u8 address)
277
+static int locked_regb_read(struct enc28j60_net *priv, u8 address)
290278 {
291279 int ret;
292280
....@@ -300,8 +288,7 @@
300288 /*
301289 * Register word read
302290 */
303
-static int nolock_regw_read(struct enc28j60_net *priv,
304
- u8 address)
291
+static int nolock_regw_read(struct enc28j60_net *priv, u8 address)
305292 {
306293 int rl, rh;
307294
....@@ -312,8 +299,7 @@
312299 return (rh << 8) | rl;
313300 }
314301
315
-static int locked_regw_read(struct enc28j60_net *priv,
316
- u8 address)
302
+static int locked_regw_read(struct enc28j60_net *priv, u8 address)
317303 {
318304 int ret;
319305
....@@ -327,15 +313,13 @@
327313 /*
328314 * Register byte write
329315 */
330
-static void nolock_regb_write(struct enc28j60_net *priv,
331
- u8 address, u8 data)
316
+static void nolock_regb_write(struct enc28j60_net *priv, u8 address, u8 data)
332317 {
333318 enc28j60_set_bank(priv, address);
334319 spi_write_op(priv, ENC28J60_WRITE_CTRL_REG, address, data);
335320 }
336321
337
-static void locked_regb_write(struct enc28j60_net *priv,
338
- u8 address, u8 data)
322
+static void locked_regb_write(struct enc28j60_net *priv, u8 address, u8 data)
339323 {
340324 mutex_lock(&priv->lock);
341325 nolock_regb_write(priv, address, data);
....@@ -345,8 +329,7 @@
345329 /*
346330 * Register word write
347331 */
348
-static void nolock_regw_write(struct enc28j60_net *priv,
349
- u8 address, u16 data)
332
+static void nolock_regw_write(struct enc28j60_net *priv, u8 address, u16 data)
350333 {
351334 enc28j60_set_bank(priv, address);
352335 spi_write_op(priv, ENC28J60_WRITE_CTRL_REG, address, (u8) data);
....@@ -354,8 +337,7 @@
354337 (u8) (data >> 8));
355338 }
356339
357
-static void locked_regw_write(struct enc28j60_net *priv,
358
- u8 address, u16 data)
340
+static void locked_regw_write(struct enc28j60_net *priv, u8 address, u16 data)
359341 {
360342 mutex_lock(&priv->lock);
361343 nolock_regw_write(priv, address, data);
....@@ -364,20 +346,23 @@
364346
365347 /*
366348 * Buffer memory read
367
- * Select the starting address and execute a SPI buffer read
349
+ * Select the starting address and execute a SPI buffer read.
368350 */
369
-static void enc28j60_mem_read(struct enc28j60_net *priv,
370
- u16 addr, int len, u8 *data)
351
+static void enc28j60_mem_read(struct enc28j60_net *priv, u16 addr, int len,
352
+ u8 *data)
371353 {
372354 mutex_lock(&priv->lock);
373355 nolock_regw_write(priv, ERDPTL, addr);
374356 #ifdef CONFIG_ENC28J60_WRITEVERIFY
375357 if (netif_msg_drv(priv)) {
358
+ struct device *dev = &priv->spi->dev;
376359 u16 reg;
360
+
377361 reg = nolock_regw_read(priv, ERDPTL);
378362 if (reg != addr)
379
- printk(KERN_DEBUG DRV_NAME ": %s() error writing ERDPT "
380
- "(0x%04x - 0x%04x)\n", __func__, reg, addr);
363
+ dev_printk(KERN_DEBUG, dev,
364
+ "%s() error writing ERDPT (0x%04x - 0x%04x)\n",
365
+ __func__, reg, addr);
381366 }
382367 #endif
383368 spi_read_buf(priv, len, data);
....@@ -390,6 +375,8 @@
390375 static void
391376 enc28j60_packet_write(struct enc28j60_net *priv, int len, const u8 *data)
392377 {
378
+ struct device *dev = &priv->spi->dev;
379
+
393380 mutex_lock(&priv->lock);
394381 /* Set the write pointer to start of transmit buffer area */
395382 nolock_regw_write(priv, EWRPTL, TXSTART_INIT);
....@@ -398,9 +385,9 @@
398385 u16 reg;
399386 reg = nolock_regw_read(priv, EWRPTL);
400387 if (reg != TXSTART_INIT)
401
- printk(KERN_DEBUG DRV_NAME
402
- ": %s() ERWPT:0x%04x != 0x%04x\n",
403
- __func__, reg, TXSTART_INIT);
388
+ dev_printk(KERN_DEBUG, dev,
389
+ "%s() ERWPT:0x%04x != 0x%04x\n",
390
+ __func__, reg, TXSTART_INIT);
404391 }
405392 #endif
406393 /* Set the TXND pointer to correspond to the packet size given */
....@@ -408,30 +395,28 @@
408395 /* write per-packet control byte */
409396 spi_write_op(priv, ENC28J60_WRITE_BUF_MEM, 0, 0x00);
410397 if (netif_msg_hw(priv))
411
- printk(KERN_DEBUG DRV_NAME
412
- ": %s() after control byte ERWPT:0x%04x\n",
413
- __func__, nolock_regw_read(priv, EWRPTL));
398
+ dev_printk(KERN_DEBUG, dev,
399
+ "%s() after control byte ERWPT:0x%04x\n",
400
+ __func__, nolock_regw_read(priv, EWRPTL));
414401 /* copy the packet into the transmit buffer */
415402 spi_write_buf(priv, len, data);
416403 if (netif_msg_hw(priv))
417
- printk(KERN_DEBUG DRV_NAME
418
- ": %s() after write packet ERWPT:0x%04x, len=%d\n",
419
- __func__, nolock_regw_read(priv, EWRPTL), len);
404
+ dev_printk(KERN_DEBUG, dev,
405
+ "%s() after write packet ERWPT:0x%04x, len=%d\n",
406
+ __func__, nolock_regw_read(priv, EWRPTL), len);
420407 mutex_unlock(&priv->lock);
421408 }
422409
423
-static unsigned long msec20_to_jiffies;
424
-
425410 static int poll_ready(struct enc28j60_net *priv, u8 reg, u8 mask, u8 val)
426411 {
427
- unsigned long timeout = jiffies + msec20_to_jiffies;
412
+ struct device *dev = &priv->spi->dev;
413
+ unsigned long timeout = jiffies + msecs_to_jiffies(20);
428414
429415 /* 20 msec timeout read */
430416 while ((nolock_regb_read(priv, reg) & mask) != val) {
431417 if (time_after(jiffies, timeout)) {
432418 if (netif_msg_drv(priv))
433
- dev_dbg(&priv->spi->dev,
434
- "reg %02x ready timeout!\n", reg);
419
+ dev_dbg(dev, "reg %02x ready timeout!\n", reg);
435420 return -ETIMEDOUT;
436421 }
437422 cpu_relax();
....@@ -449,7 +434,7 @@
449434
450435 /*
451436 * PHY register read
452
- * PHY registers are not accessed directly, but through the MII
437
+ * PHY registers are not accessed directly, but through the MII.
453438 */
454439 static u16 enc28j60_phy_read(struct enc28j60_net *priv, u8 address)
455440 {
....@@ -465,7 +450,7 @@
465450 /* quit reading */
466451 nolock_regb_write(priv, MICMD, 0x00);
467452 /* return the data */
468
- ret = nolock_regw_read(priv, MIRDL);
453
+ ret = nolock_regw_read(priv, MIRDL);
469454 mutex_unlock(&priv->lock);
470455
471456 return ret;
....@@ -494,13 +479,13 @@
494479 {
495480 int ret;
496481 struct enc28j60_net *priv = netdev_priv(ndev);
482
+ struct device *dev = &priv->spi->dev;
497483
498484 mutex_lock(&priv->lock);
499485 if (!priv->hw_enable) {
500486 if (netif_msg_drv(priv))
501
- printk(KERN_INFO DRV_NAME
502
- ": %s: Setting MAC address to %pM\n",
503
- ndev->name, ndev->dev_addr);
487
+ dev_info(dev, "%s: Setting MAC address to %pM\n",
488
+ ndev->name, ndev->dev_addr);
504489 /* NOTE: MAC address in ENC28J60 is byte-backward */
505490 nolock_regb_write(priv, MAADR5, ndev->dev_addr[0]);
506491 nolock_regb_write(priv, MAADR4, ndev->dev_addr[1]);
....@@ -511,9 +496,9 @@
511496 ret = 0;
512497 } else {
513498 if (netif_msg_drv(priv))
514
- printk(KERN_DEBUG DRV_NAME
515
- ": %s() Hardware must be disabled to set "
516
- "Mac address\n", __func__);
499
+ dev_printk(KERN_DEBUG, dev,
500
+ "%s() Hardware must be disabled to set Mac address\n",
501
+ __func__);
517502 ret = -EBUSY;
518503 }
519504 mutex_unlock(&priv->lock);
....@@ -532,7 +517,7 @@
532517 if (!is_valid_ether_addr(address->sa_data))
533518 return -EADDRNOTAVAIL;
534519
535
- memcpy(dev->dev_addr, address->sa_data, dev->addr_len);
520
+ ether_addr_copy(dev->dev_addr, address->sa_data);
536521 return enc28j60_set_hw_macaddr(dev);
537522 }
538523
....@@ -541,33 +526,36 @@
541526 */
542527 static void enc28j60_dump_regs(struct enc28j60_net *priv, const char *msg)
543528 {
529
+ struct device *dev = &priv->spi->dev;
530
+
544531 mutex_lock(&priv->lock);
545
- printk(KERN_DEBUG DRV_NAME " %s\n"
546
- "HwRevID: 0x%02x\n"
547
- "Cntrl: ECON1 ECON2 ESTAT EIR EIE\n"
548
- " 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n"
549
- "MAC : MACON1 MACON3 MACON4\n"
550
- " 0x%02x 0x%02x 0x%02x\n"
551
- "Rx : ERXST ERXND ERXWRPT ERXRDPT ERXFCON EPKTCNT MAMXFL\n"
552
- " 0x%04x 0x%04x 0x%04x 0x%04x "
553
- "0x%02x 0x%02x 0x%04x\n"
554
- "Tx : ETXST ETXND MACLCON1 MACLCON2 MAPHSUP\n"
555
- " 0x%04x 0x%04x 0x%02x 0x%02x 0x%02x\n",
556
- msg, nolock_regb_read(priv, EREVID),
557
- nolock_regb_read(priv, ECON1), nolock_regb_read(priv, ECON2),
558
- nolock_regb_read(priv, ESTAT), nolock_regb_read(priv, EIR),
559
- nolock_regb_read(priv, EIE), nolock_regb_read(priv, MACON1),
560
- nolock_regb_read(priv, MACON3), nolock_regb_read(priv, MACON4),
561
- nolock_regw_read(priv, ERXSTL), nolock_regw_read(priv, ERXNDL),
562
- nolock_regw_read(priv, ERXWRPTL),
563
- nolock_regw_read(priv, ERXRDPTL),
564
- nolock_regb_read(priv, ERXFCON),
565
- nolock_regb_read(priv, EPKTCNT),
566
- nolock_regw_read(priv, MAMXFLL), nolock_regw_read(priv, ETXSTL),
567
- nolock_regw_read(priv, ETXNDL),
568
- nolock_regb_read(priv, MACLCON1),
569
- nolock_regb_read(priv, MACLCON2),
570
- nolock_regb_read(priv, MAPHSUP));
532
+ dev_printk(KERN_DEBUG, dev,
533
+ " %s\n"
534
+ "HwRevID: 0x%02x\n"
535
+ "Cntrl: ECON1 ECON2 ESTAT EIR EIE\n"
536
+ " 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n"
537
+ "MAC : MACON1 MACON3 MACON4\n"
538
+ " 0x%02x 0x%02x 0x%02x\n"
539
+ "Rx : ERXST ERXND ERXWRPT ERXRDPT ERXFCON EPKTCNT MAMXFL\n"
540
+ " 0x%04x 0x%04x 0x%04x 0x%04x "
541
+ "0x%02x 0x%02x 0x%04x\n"
542
+ "Tx : ETXST ETXND MACLCON1 MACLCON2 MAPHSUP\n"
543
+ " 0x%04x 0x%04x 0x%02x 0x%02x 0x%02x\n",
544
+ msg, nolock_regb_read(priv, EREVID),
545
+ nolock_regb_read(priv, ECON1), nolock_regb_read(priv, ECON2),
546
+ nolock_regb_read(priv, ESTAT), nolock_regb_read(priv, EIR),
547
+ nolock_regb_read(priv, EIE), nolock_regb_read(priv, MACON1),
548
+ nolock_regb_read(priv, MACON3), nolock_regb_read(priv, MACON4),
549
+ nolock_regw_read(priv, ERXSTL), nolock_regw_read(priv, ERXNDL),
550
+ nolock_regw_read(priv, ERXWRPTL),
551
+ nolock_regw_read(priv, ERXRDPTL),
552
+ nolock_regb_read(priv, ERXFCON),
553
+ nolock_regb_read(priv, EPKTCNT),
554
+ nolock_regw_read(priv, MAMXFLL), nolock_regw_read(priv, ETXSTL),
555
+ nolock_regw_read(priv, ETXNDL),
556
+ nolock_regb_read(priv, MACLCON1),
557
+ nolock_regb_read(priv, MACLCON2),
558
+ nolock_regb_read(priv, MAPHSUP));
571559 mutex_unlock(&priv->lock);
572560 }
573561
....@@ -599,12 +587,13 @@
599587
600588 static void nolock_rxfifo_init(struct enc28j60_net *priv, u16 start, u16 end)
601589 {
590
+ struct device *dev = &priv->spi->dev;
602591 u16 erxrdpt;
603592
604593 if (start > 0x1FFF || end > 0x1FFF || start > end) {
605594 if (netif_msg_drv(priv))
606
- printk(KERN_ERR DRV_NAME ": %s(%d, %d) RXFIFO "
607
- "bad parameters!\n", __func__, start, end);
595
+ dev_err(dev, "%s(%d, %d) RXFIFO bad parameters!\n",
596
+ __func__, start, end);
608597 return;
609598 }
610599 /* set receive buffer start + end */
....@@ -617,10 +606,12 @@
617606
618607 static void nolock_txfifo_init(struct enc28j60_net *priv, u16 start, u16 end)
619608 {
609
+ struct device *dev = &priv->spi->dev;
610
+
620611 if (start > 0x1FFF || end > 0x1FFF || start > end) {
621612 if (netif_msg_drv(priv))
622
- printk(KERN_ERR DRV_NAME ": %s(%d, %d) TXFIFO "
623
- "bad parameters!\n", __func__, start, end);
613
+ dev_err(dev, "%s(%d, %d) TXFIFO bad parameters!\n",
614
+ __func__, start, end);
624615 return;
625616 }
626617 /* set transmit buffer start + end */
....@@ -630,14 +621,15 @@
630621
631622 /*
632623 * Low power mode shrinks power consumption about 100x, so we'd like
633
- * the chip to be in that mode whenever it's inactive. (However, we
634
- * can't stay in lowpower mode during suspend with WOL active.)
624
+ * the chip to be in that mode whenever it's inactive. (However, we
625
+ * can't stay in low power mode during suspend with WOL active.)
635626 */
636627 static void enc28j60_lowpower(struct enc28j60_net *priv, bool is_low)
637628 {
629
+ struct device *dev = &priv->spi->dev;
630
+
638631 if (netif_msg_drv(priv))
639
- dev_dbg(&priv->spi->dev, "%s power...\n",
640
- is_low ? "low" : "high");
632
+ dev_dbg(dev, "%s power...\n", is_low ? "low" : "high");
641633
642634 mutex_lock(&priv->lock);
643635 if (is_low) {
....@@ -656,11 +648,12 @@
656648
657649 static int enc28j60_hw_init(struct enc28j60_net *priv)
658650 {
651
+ struct device *dev = &priv->spi->dev;
659652 u8 reg;
660653
661654 if (netif_msg_drv(priv))
662
- printk(KERN_DEBUG DRV_NAME ": %s() - %s\n", __func__,
663
- priv->full_duplex ? "FullDuplex" : "HalfDuplex");
655
+ dev_printk(KERN_DEBUG, dev, "%s() - %s\n", __func__,
656
+ priv->full_duplex ? "FullDuplex" : "HalfDuplex");
664657
665658 mutex_lock(&priv->lock);
666659 /* first reset the chip */
....@@ -682,15 +675,15 @@
682675 /*
683676 * Check the RevID.
684677 * If it's 0x00 or 0xFF probably the enc28j60 is not mounted or
685
- * damaged
678
+ * damaged.
686679 */
687680 reg = locked_regb_read(priv, EREVID);
688681 if (netif_msg_drv(priv))
689
- printk(KERN_INFO DRV_NAME ": chip RevID: 0x%02x\n", reg);
682
+ dev_info(dev, "chip RevID: 0x%02x\n", reg);
690683 if (reg == 0x00 || reg == 0xff) {
691684 if (netif_msg_drv(priv))
692
- printk(KERN_DEBUG DRV_NAME ": %s() Invalid RevId %d\n",
693
- __func__, reg);
685
+ dev_printk(KERN_DEBUG, dev, "%s() Invalid RevId %d\n",
686
+ __func__, reg);
694687 return 0;
695688 }
696689
....@@ -723,7 +716,7 @@
723716 /*
724717 * MACLCON1 (default)
725718 * MACLCON2 (default)
726
- * Set the maximum packet size which the controller will accept
719
+ * Set the maximum packet size which the controller will accept.
727720 */
728721 locked_regw_write(priv, MAMXFLL, MAX_FRAMELEN);
729722
....@@ -750,10 +743,12 @@
750743
751744 static void enc28j60_hw_enable(struct enc28j60_net *priv)
752745 {
746
+ struct device *dev = &priv->spi->dev;
747
+
753748 /* enable interrupts */
754749 if (netif_msg_hw(priv))
755
- printk(KERN_DEBUG DRV_NAME ": %s() enabling interrupts.\n",
756
- __func__);
750
+ dev_printk(KERN_DEBUG, dev, "%s() enabling interrupts.\n",
751
+ __func__);
757752
758753 enc28j60_phy_write(priv, PHIE, PHIE_PGEIE | PHIE_PLNKIE);
759754
....@@ -772,7 +767,7 @@
772767 static void enc28j60_hw_disable(struct enc28j60_net *priv)
773768 {
774769 mutex_lock(&priv->lock);
775
- /* disable interrutps and packet reception */
770
+ /* disable interrupts and packet reception */
776771 nolock_regb_write(priv, EIE, 0x00);
777772 nolock_reg_bfclr(priv, ECON1, ECON1_RXEN);
778773 priv->hw_enable = false;
....@@ -793,14 +788,12 @@
793788 priv->full_duplex = (duplex == DUPLEX_FULL);
794789 else {
795790 if (netif_msg_link(priv))
796
- dev_warn(&ndev->dev,
797
- "unsupported link setting\n");
791
+ netdev_warn(ndev, "unsupported link setting\n");
798792 ret = -EOPNOTSUPP;
799793 }
800794 } else {
801795 if (netif_msg_link(priv))
802
- dev_warn(&ndev->dev, "Warning: hw must be disabled "
803
- "to set link mode\n");
796
+ netdev_warn(ndev, "Warning: hw must be disabled to set link mode\n");
804797 ret = -EBUSY;
805798 }
806799 return ret;
....@@ -811,21 +804,23 @@
811804 */
812805 static void enc28j60_read_tsv(struct enc28j60_net *priv, u8 tsv[TSV_SIZE])
813806 {
807
+ struct device *dev = &priv->spi->dev;
814808 int endptr;
815809
816810 endptr = locked_regw_read(priv, ETXNDL);
817811 if (netif_msg_hw(priv))
818
- printk(KERN_DEBUG DRV_NAME ": reading TSV at addr:0x%04x\n",
819
- endptr + 1);
812
+ dev_printk(KERN_DEBUG, dev, "reading TSV at addr:0x%04x\n",
813
+ endptr + 1);
820814 enc28j60_mem_read(priv, endptr + 1, TSV_SIZE, tsv);
821815 }
822816
823817 static void enc28j60_dump_tsv(struct enc28j60_net *priv, const char *msg,
824
- u8 tsv[TSV_SIZE])
818
+ u8 tsv[TSV_SIZE])
825819 {
820
+ struct device *dev = &priv->spi->dev;
826821 u16 tmp1, tmp2;
827822
828
- printk(KERN_DEBUG DRV_NAME ": %s - TSV:\n", msg);
823
+ dev_printk(KERN_DEBUG, dev, "%s - TSV:\n", msg);
829824 tmp1 = tsv[1];
830825 tmp1 <<= 8;
831826 tmp1 |= tsv[0];
....@@ -834,30 +829,32 @@
834829 tmp2 <<= 8;
835830 tmp2 |= tsv[4];
836831
837
- printk(KERN_DEBUG DRV_NAME ": ByteCount: %d, CollisionCount: %d,"
838
- " TotByteOnWire: %d\n", tmp1, tsv[2] & 0x0f, tmp2);
839
- printk(KERN_DEBUG DRV_NAME ": TxDone: %d, CRCErr:%d, LenChkErr: %d,"
840
- " LenOutOfRange: %d\n", TSV_GETBIT(tsv, TSV_TXDONE),
841
- TSV_GETBIT(tsv, TSV_TXCRCERROR),
842
- TSV_GETBIT(tsv, TSV_TXLENCHKERROR),
843
- TSV_GETBIT(tsv, TSV_TXLENOUTOFRANGE));
844
- printk(KERN_DEBUG DRV_NAME ": Multicast: %d, Broadcast: %d, "
845
- "PacketDefer: %d, ExDefer: %d\n",
846
- TSV_GETBIT(tsv, TSV_TXMULTICAST),
847
- TSV_GETBIT(tsv, TSV_TXBROADCAST),
848
- TSV_GETBIT(tsv, TSV_TXPACKETDEFER),
849
- TSV_GETBIT(tsv, TSV_TXEXDEFER));
850
- printk(KERN_DEBUG DRV_NAME ": ExCollision: %d, LateCollision: %d, "
851
- "Giant: %d, Underrun: %d\n",
852
- TSV_GETBIT(tsv, TSV_TXEXCOLLISION),
853
- TSV_GETBIT(tsv, TSV_TXLATECOLLISION),
854
- TSV_GETBIT(tsv, TSV_TXGIANT), TSV_GETBIT(tsv, TSV_TXUNDERRUN));
855
- printk(KERN_DEBUG DRV_NAME ": ControlFrame: %d, PauseFrame: %d, "
856
- "BackPressApp: %d, VLanTagFrame: %d\n",
857
- TSV_GETBIT(tsv, TSV_TXCONTROLFRAME),
858
- TSV_GETBIT(tsv, TSV_TXPAUSEFRAME),
859
- TSV_GETBIT(tsv, TSV_BACKPRESSUREAPP),
860
- TSV_GETBIT(tsv, TSV_TXVLANTAGFRAME));
832
+ dev_printk(KERN_DEBUG, dev,
833
+ "ByteCount: %d, CollisionCount: %d, TotByteOnWire: %d\n",
834
+ tmp1, tsv[2] & 0x0f, tmp2);
835
+ dev_printk(KERN_DEBUG, dev,
836
+ "TxDone: %d, CRCErr:%d, LenChkErr: %d, LenOutOfRange: %d\n",
837
+ TSV_GETBIT(tsv, TSV_TXDONE),
838
+ TSV_GETBIT(tsv, TSV_TXCRCERROR),
839
+ TSV_GETBIT(tsv, TSV_TXLENCHKERROR),
840
+ TSV_GETBIT(tsv, TSV_TXLENOUTOFRANGE));
841
+ dev_printk(KERN_DEBUG, dev,
842
+ "Multicast: %d, Broadcast: %d, PacketDefer: %d, ExDefer: %d\n",
843
+ TSV_GETBIT(tsv, TSV_TXMULTICAST),
844
+ TSV_GETBIT(tsv, TSV_TXBROADCAST),
845
+ TSV_GETBIT(tsv, TSV_TXPACKETDEFER),
846
+ TSV_GETBIT(tsv, TSV_TXEXDEFER));
847
+ dev_printk(KERN_DEBUG, dev,
848
+ "ExCollision: %d, LateCollision: %d, Giant: %d, Underrun: %d\n",
849
+ TSV_GETBIT(tsv, TSV_TXEXCOLLISION),
850
+ TSV_GETBIT(tsv, TSV_TXLATECOLLISION),
851
+ TSV_GETBIT(tsv, TSV_TXGIANT), TSV_GETBIT(tsv, TSV_TXUNDERRUN));
852
+ dev_printk(KERN_DEBUG, dev,
853
+ "ControlFrame: %d, PauseFrame: %d, BackPressApp: %d, VLanTagFrame: %d\n",
854
+ TSV_GETBIT(tsv, TSV_TXCONTROLFRAME),
855
+ TSV_GETBIT(tsv, TSV_TXPAUSEFRAME),
856
+ TSV_GETBIT(tsv, TSV_BACKPRESSUREAPP),
857
+ TSV_GETBIT(tsv, TSV_TXVLANTAGFRAME));
861858 }
862859
863860 /*
....@@ -866,27 +863,29 @@
866863 static void enc28j60_dump_rsv(struct enc28j60_net *priv, const char *msg,
867864 u16 pk_ptr, int len, u16 sts)
868865 {
869
- printk(KERN_DEBUG DRV_NAME ": %s - NextPk: 0x%04x - RSV:\n",
870
- msg, pk_ptr);
871
- printk(KERN_DEBUG DRV_NAME ": ByteCount: %d, DribbleNibble: %d\n", len,
872
- RSV_GETBIT(sts, RSV_DRIBBLENIBBLE));
873
- printk(KERN_DEBUG DRV_NAME ": RxOK: %d, CRCErr:%d, LenChkErr: %d,"
874
- " LenOutOfRange: %d\n", RSV_GETBIT(sts, RSV_RXOK),
875
- RSV_GETBIT(sts, RSV_CRCERROR),
876
- RSV_GETBIT(sts, RSV_LENCHECKERR),
877
- RSV_GETBIT(sts, RSV_LENOUTOFRANGE));
878
- printk(KERN_DEBUG DRV_NAME ": Multicast: %d, Broadcast: %d, "
879
- "LongDropEvent: %d, CarrierEvent: %d\n",
880
- RSV_GETBIT(sts, RSV_RXMULTICAST),
881
- RSV_GETBIT(sts, RSV_RXBROADCAST),
882
- RSV_GETBIT(sts, RSV_RXLONGEVDROPEV),
883
- RSV_GETBIT(sts, RSV_CARRIEREV));
884
- printk(KERN_DEBUG DRV_NAME ": ControlFrame: %d, PauseFrame: %d,"
885
- " UnknownOp: %d, VLanTagFrame: %d\n",
886
- RSV_GETBIT(sts, RSV_RXCONTROLFRAME),
887
- RSV_GETBIT(sts, RSV_RXPAUSEFRAME),
888
- RSV_GETBIT(sts, RSV_RXUNKNOWNOPCODE),
889
- RSV_GETBIT(sts, RSV_RXTYPEVLAN));
866
+ struct device *dev = &priv->spi->dev;
867
+
868
+ dev_printk(KERN_DEBUG, dev, "%s - NextPk: 0x%04x - RSV:\n", msg, pk_ptr);
869
+ dev_printk(KERN_DEBUG, dev, "ByteCount: %d, DribbleNibble: %d\n",
870
+ len, RSV_GETBIT(sts, RSV_DRIBBLENIBBLE));
871
+ dev_printk(KERN_DEBUG, dev,
872
+ "RxOK: %d, CRCErr:%d, LenChkErr: %d, LenOutOfRange: %d\n",
873
+ RSV_GETBIT(sts, RSV_RXOK),
874
+ RSV_GETBIT(sts, RSV_CRCERROR),
875
+ RSV_GETBIT(sts, RSV_LENCHECKERR),
876
+ RSV_GETBIT(sts, RSV_LENOUTOFRANGE));
877
+ dev_printk(KERN_DEBUG, dev,
878
+ "Multicast: %d, Broadcast: %d, LongDropEvent: %d, CarrierEvent: %d\n",
879
+ RSV_GETBIT(sts, RSV_RXMULTICAST),
880
+ RSV_GETBIT(sts, RSV_RXBROADCAST),
881
+ RSV_GETBIT(sts, RSV_RXLONGEVDROPEV),
882
+ RSV_GETBIT(sts, RSV_CARRIEREV));
883
+ dev_printk(KERN_DEBUG, dev,
884
+ "ControlFrame: %d, PauseFrame: %d, UnknownOp: %d, VLanTagFrame: %d\n",
885
+ RSV_GETBIT(sts, RSV_RXCONTROLFRAME),
886
+ RSV_GETBIT(sts, RSV_RXPAUSEFRAME),
887
+ RSV_GETBIT(sts, RSV_RXUNKNOWNOPCODE),
888
+ RSV_GETBIT(sts, RSV_RXTYPEVLAN));
890889 }
891890
892891 static void dump_packet(const char *msg, int len, const char *data)
....@@ -904,20 +903,20 @@
904903 static void enc28j60_hw_rx(struct net_device *ndev)
905904 {
906905 struct enc28j60_net *priv = netdev_priv(ndev);
906
+ struct device *dev = &priv->spi->dev;
907907 struct sk_buff *skb = NULL;
908908 u16 erxrdpt, next_packet, rxstat;
909909 u8 rsv[RSV_SIZE];
910910 int len;
911911
912912 if (netif_msg_rx_status(priv))
913
- printk(KERN_DEBUG DRV_NAME ": RX pk_addr:0x%04x\n",
914
- priv->next_pk_ptr);
913
+ netdev_printk(KERN_DEBUG, ndev, "RX pk_addr:0x%04x\n",
914
+ priv->next_pk_ptr);
915915
916916 if (unlikely(priv->next_pk_ptr > RXEND_INIT)) {
917917 if (netif_msg_rx_err(priv))
918
- dev_err(&ndev->dev,
919
- "%s() Invalid packet address!! 0x%04x\n",
920
- __func__, priv->next_pk_ptr);
918
+ netdev_err(ndev, "%s() Invalid packet address!! 0x%04x\n",
919
+ __func__, priv->next_pk_ptr);
921920 /* packet address corrupted: reset RX logic */
922921 mutex_lock(&priv->lock);
923922 nolock_reg_bfclr(priv, ECON1, ECON1_RXEN);
....@@ -950,7 +949,7 @@
950949
951950 if (!RSV_GETBIT(rxstat, RSV_RXOK) || len > MAX_FRAMELEN) {
952951 if (netif_msg_rx_err(priv))
953
- dev_err(&ndev->dev, "Rx Error (%04x)\n", rxstat);
952
+ netdev_err(ndev, "Rx Error (%04x)\n", rxstat);
954953 ndev->stats.rx_errors++;
955954 if (RSV_GETBIT(rxstat, RSV_CRCERROR))
956955 ndev->stats.rx_crc_errors++;
....@@ -962,8 +961,7 @@
962961 skb = netdev_alloc_skb(ndev, len + NET_IP_ALIGN);
963962 if (!skb) {
964963 if (netif_msg_rx_err(priv))
965
- dev_err(&ndev->dev,
966
- "out of memory for Rx'd frame\n");
964
+ netdev_err(ndev, "out of memory for Rx'd frame\n");
967965 ndev->stats.rx_dropped++;
968966 } else {
969967 skb_reserve(skb, NET_IP_ALIGN);
....@@ -983,12 +981,12 @@
983981 /*
984982 * Move the RX read pointer to the start of the next
985983 * received packet.
986
- * This frees the memory we just read out
984
+ * This frees the memory we just read out.
987985 */
988986 erxrdpt = erxrdpt_workaround(next_packet, RXSTART_INIT, RXEND_INIT);
989987 if (netif_msg_hw(priv))
990
- printk(KERN_DEBUG DRV_NAME ": %s() ERXRDPT:0x%04x\n",
991
- __func__, erxrdpt);
988
+ dev_printk(KERN_DEBUG, dev, "%s() ERXRDPT:0x%04x\n",
989
+ __func__, erxrdpt);
992990
993991 mutex_lock(&priv->lock);
994992 nolock_regw_write(priv, ERXRDPTL, erxrdpt);
....@@ -997,9 +995,9 @@
997995 u16 reg;
998996 reg = nolock_regw_read(priv, ERXRDPTL);
999997 if (reg != erxrdpt)
1000
- printk(KERN_DEBUG DRV_NAME ": %s() ERXRDPT verify "
1001
- "error (0x%04x - 0x%04x)\n", __func__,
1002
- reg, erxrdpt);
998
+ dev_printk(KERN_DEBUG, dev,
999
+ "%s() ERXRDPT verify error (0x%04x - 0x%04x)\n",
1000
+ __func__, reg, erxrdpt);
10031001 }
10041002 #endif
10051003 priv->next_pk_ptr = next_packet;
....@@ -1013,6 +1011,7 @@
10131011 */
10141012 static int enc28j60_get_free_rxfifo(struct enc28j60_net *priv)
10151013 {
1014
+ struct net_device *ndev = priv->netdev;
10161015 int epkcnt, erxst, erxnd, erxwr, erxrd;
10171016 int free_space;
10181017
....@@ -1035,8 +1034,8 @@
10351034 }
10361035 mutex_unlock(&priv->lock);
10371036 if (netif_msg_rx_status(priv))
1038
- printk(KERN_DEBUG DRV_NAME ": %s() free_space = %d\n",
1039
- __func__, free_space);
1037
+ netdev_printk(KERN_DEBUG, ndev, "%s() free_space = %d\n",
1038
+ __func__, free_space);
10401039 return free_space;
10411040 }
10421041
....@@ -1046,24 +1045,25 @@
10461045 static void enc28j60_check_link_status(struct net_device *ndev)
10471046 {
10481047 struct enc28j60_net *priv = netdev_priv(ndev);
1048
+ struct device *dev = &priv->spi->dev;
10491049 u16 reg;
10501050 int duplex;
10511051
10521052 reg = enc28j60_phy_read(priv, PHSTAT2);
10531053 if (netif_msg_hw(priv))
1054
- printk(KERN_DEBUG DRV_NAME ": %s() PHSTAT1: %04x, "
1055
- "PHSTAT2: %04x\n", __func__,
1056
- enc28j60_phy_read(priv, PHSTAT1), reg);
1054
+ dev_printk(KERN_DEBUG, dev,
1055
+ "%s() PHSTAT1: %04x, PHSTAT2: %04x\n", __func__,
1056
+ enc28j60_phy_read(priv, PHSTAT1), reg);
10571057 duplex = reg & PHSTAT2_DPXSTAT;
10581058
10591059 if (reg & PHSTAT2_LSTAT) {
10601060 netif_carrier_on(ndev);
10611061 if (netif_msg_ifup(priv))
1062
- dev_info(&ndev->dev, "link up - %s\n",
1063
- duplex ? "Full duplex" : "Half duplex");
1062
+ netdev_info(ndev, "link up - %s\n",
1063
+ duplex ? "Full duplex" : "Half duplex");
10641064 } else {
10651065 if (netif_msg_ifdown(priv))
1066
- dev_info(&ndev->dev, "link down\n");
1066
+ netdev_info(ndev, "link down\n");
10671067 netif_carrier_off(ndev);
10681068 }
10691069 }
....@@ -1089,8 +1089,8 @@
10891089
10901090 /*
10911091 * RX handler
1092
- * ignore PKTIF because is unreliable! (look at the errata datasheet)
1093
- * check EPKTCNT is the suggested workaround.
1092
+ * Ignore PKTIF because is unreliable! (Look at the errata datasheet)
1093
+ * Check EPKTCNT is the suggested workaround.
10941094 * We don't need to clear interrupt flag, automatically done when
10951095 * enc28j60_hw_rx() decrements the packet counter.
10961096 * Returns how many packet processed.
....@@ -1102,13 +1102,14 @@
11021102
11031103 pk_counter = locked_regb_read(priv, EPKTCNT);
11041104 if (pk_counter && netif_msg_intr(priv))
1105
- printk(KERN_DEBUG DRV_NAME ": intRX, pk_cnt: %d\n", pk_counter);
1105
+ netdev_printk(KERN_DEBUG, ndev, "intRX, pk_cnt: %d\n",
1106
+ pk_counter);
11061107 if (pk_counter > priv->max_pk_counter) {
11071108 /* update statistics */
11081109 priv->max_pk_counter = pk_counter;
11091110 if (netif_msg_rx_status(priv) && priv->max_pk_counter > 1)
1110
- printk(KERN_DEBUG DRV_NAME ": RX max_pk_cnt: %d\n",
1111
- priv->max_pk_counter);
1111
+ netdev_printk(KERN_DEBUG, ndev, "RX max_pk_cnt: %d\n",
1112
+ priv->max_pk_counter);
11121113 }
11131114 ret = pk_counter;
11141115 while (pk_counter-- > 0)
....@@ -1124,8 +1125,6 @@
11241125 struct net_device *ndev = priv->netdev;
11251126 int intflags, loop;
11261127
1127
- if (netif_msg_intr(priv))
1128
- printk(KERN_DEBUG DRV_NAME ": %s() enter\n", __func__);
11291128 /* disable further interrupts */
11301129 locked_reg_bfclr(priv, EIE, EIE_INTIE);
11311130
....@@ -1136,16 +1135,16 @@
11361135 if ((intflags & EIR_DMAIF) != 0) {
11371136 loop++;
11381137 if (netif_msg_intr(priv))
1139
- printk(KERN_DEBUG DRV_NAME
1140
- ": intDMA(%d)\n", loop);
1138
+ netdev_printk(KERN_DEBUG, ndev, "intDMA(%d)\n",
1139
+ loop);
11411140 locked_reg_bfclr(priv, EIR, EIR_DMAIF);
11421141 }
11431142 /* LINK changed handler */
11441143 if ((intflags & EIR_LINKIF) != 0) {
11451144 loop++;
11461145 if (netif_msg_intr(priv))
1147
- printk(KERN_DEBUG DRV_NAME
1148
- ": intLINK(%d)\n", loop);
1146
+ netdev_printk(KERN_DEBUG, ndev, "intLINK(%d)\n",
1147
+ loop);
11491148 enc28j60_check_link_status(ndev);
11501149 /* read PHIR to clear the flag */
11511150 enc28j60_phy_read(priv, PHIR);
....@@ -1156,13 +1155,12 @@
11561155 bool err = false;
11571156 loop++;
11581157 if (netif_msg_intr(priv))
1159
- printk(KERN_DEBUG DRV_NAME
1160
- ": intTX(%d)\n", loop);
1158
+ netdev_printk(KERN_DEBUG, ndev, "intTX(%d)\n",
1159
+ loop);
11611160 priv->tx_retry_count = 0;
11621161 if (locked_regb_read(priv, ESTAT) & ESTAT_TXABRT) {
11631162 if (netif_msg_tx_err(priv))
1164
- dev_err(&ndev->dev,
1165
- "Tx Error (aborted)\n");
1163
+ netdev_err(ndev, "Tx Error (aborted)\n");
11661164 err = true;
11671165 }
11681166 if (netif_msg_tx_done(priv)) {
....@@ -1179,8 +1177,8 @@
11791177
11801178 loop++;
11811179 if (netif_msg_intr(priv))
1182
- printk(KERN_DEBUG DRV_NAME
1183
- ": intTXErr(%d)\n", loop);
1180
+ netdev_printk(KERN_DEBUG, ndev, "intTXErr(%d)\n",
1181
+ loop);
11841182 locked_reg_bfclr(priv, ECON1, ECON1_TXRTS);
11851183 enc28j60_read_tsv(priv, tsv);
11861184 if (netif_msg_tx_err(priv))
....@@ -1194,9 +1192,9 @@
11941192 /* Transmit Late collision check for retransmit */
11951193 if (TSV_GETBIT(tsv, TSV_TXLATECOLLISION)) {
11961194 if (netif_msg_tx_err(priv))
1197
- printk(KERN_DEBUG DRV_NAME
1198
- ": LateCollision TXErr (%d)\n",
1199
- priv->tx_retry_count);
1195
+ netdev_printk(KERN_DEBUG, ndev,
1196
+ "LateCollision TXErr (%d)\n",
1197
+ priv->tx_retry_count);
12001198 if (priv->tx_retry_count++ < MAX_TX_RETRYCOUNT)
12011199 locked_reg_bfset(priv, ECON1,
12021200 ECON1_TXRTS);
....@@ -1210,13 +1208,12 @@
12101208 if ((intflags & EIR_RXERIF) != 0) {
12111209 loop++;
12121210 if (netif_msg_intr(priv))
1213
- printk(KERN_DEBUG DRV_NAME
1214
- ": intRXErr(%d)\n", loop);
1211
+ netdev_printk(KERN_DEBUG, ndev, "intRXErr(%d)\n",
1212
+ loop);
12151213 /* Check free FIFO space to flag RX overrun */
12161214 if (enc28j60_get_free_rxfifo(priv) <= 0) {
12171215 if (netif_msg_rx_err(priv))
1218
- printk(KERN_DEBUG DRV_NAME
1219
- ": RX Overrun\n");
1216
+ netdev_printk(KERN_DEBUG, ndev, "RX Overrun\n");
12201217 ndev->stats.rx_dropped++;
12211218 }
12221219 locked_reg_bfclr(priv, EIR, EIR_RXERIF);
....@@ -1228,8 +1225,6 @@
12281225
12291226 /* re-enable interrupts */
12301227 locked_reg_bfset(priv, EIE, EIE_INTIE);
1231
- if (netif_msg_intr(priv))
1232
- printk(KERN_DEBUG DRV_NAME ": %s() exit\n", __func__);
12331228 }
12341229
12351230 /*
....@@ -1239,11 +1234,13 @@
12391234 */
12401235 static void enc28j60_hw_tx(struct enc28j60_net *priv)
12411236 {
1237
+ struct net_device *ndev = priv->netdev;
1238
+
12421239 BUG_ON(!priv->tx_skb);
12431240
12441241 if (netif_msg_tx_queued(priv))
1245
- printk(KERN_DEBUG DRV_NAME
1246
- ": Tx Packet Len:%d\n", priv->tx_skb->len);
1242
+ netdev_printk(KERN_DEBUG, ndev, "Tx Packet Len:%d\n",
1243
+ priv->tx_skb->len);
12471244
12481245 if (netif_msg_pktdata(priv))
12491246 dump_packet(__func__,
....@@ -1253,6 +1250,7 @@
12531250 #ifdef CONFIG_ENC28J60_WRITEVERIFY
12541251 /* readback and verify written data */
12551252 if (netif_msg_drv(priv)) {
1253
+ struct device *dev = &priv->spi->dev;
12561254 int test_len, k;
12571255 u8 test_buf[64]; /* limit the test to the first 64 bytes */
12581256 int okflag;
....@@ -1266,16 +1264,14 @@
12661264 okflag = 1;
12671265 for (k = 0; k < test_len; k++) {
12681266 if (priv->tx_skb->data[k] != test_buf[k]) {
1269
- printk(KERN_DEBUG DRV_NAME
1270
- ": Error, %d location differ: "
1271
- "0x%02x-0x%02x\n", k,
1272
- priv->tx_skb->data[k], test_buf[k]);
1267
+ dev_printk(KERN_DEBUG, dev,
1268
+ "Error, %d location differ: 0x%02x-0x%02x\n",
1269
+ k, priv->tx_skb->data[k], test_buf[k]);
12731270 okflag = 0;
12741271 }
12751272 }
12761273 if (!okflag)
1277
- printk(KERN_DEBUG DRV_NAME ": Tx write buffer, "
1278
- "verify ERROR!\n");
1274
+ dev_printk(KERN_DEBUG, dev, "Tx write buffer, verify ERROR!\n");
12791275 }
12801276 #endif
12811277 /* set TX request flag */
....@@ -1287,14 +1283,11 @@
12871283 {
12881284 struct enc28j60_net *priv = netdev_priv(dev);
12891285
1290
- if (netif_msg_tx_queued(priv))
1291
- printk(KERN_DEBUG DRV_NAME ": %s() enter\n", __func__);
1292
-
12931286 /* If some error occurs while trying to transmit this
12941287 * packet, you should return '1' from this function.
12951288 * In such a case you _may not_ do anything to the
12961289 * SKB, it is still owned by the network queueing
1297
- * layer when an error is returned. This means you
1290
+ * layer when an error is returned. This means you
12981291 * may not modify any SKB fields, you may not free
12991292 * the SKB, etc.
13001293 */
....@@ -1332,12 +1325,12 @@
13321325 return IRQ_HANDLED;
13331326 }
13341327
1335
-static void enc28j60_tx_timeout(struct net_device *ndev)
1328
+static void enc28j60_tx_timeout(struct net_device *ndev, unsigned int txqueue)
13361329 {
13371330 struct enc28j60_net *priv = netdev_priv(ndev);
13381331
13391332 if (netif_msg_timer(priv))
1340
- dev_err(&ndev->dev, DRV_NAME " tx timeout\n");
1333
+ netdev_err(ndev, "tx timeout\n");
13411334
13421335 ndev->stats.tx_errors++;
13431336 /* can't restart safely under softirq */
....@@ -1356,13 +1349,9 @@
13561349 {
13571350 struct enc28j60_net *priv = netdev_priv(dev);
13581351
1359
- if (netif_msg_drv(priv))
1360
- printk(KERN_DEBUG DRV_NAME ": %s() enter\n", __func__);
1361
-
13621352 if (!is_valid_ether_addr(dev->dev_addr)) {
13631353 if (netif_msg_ifup(priv))
1364
- dev_err(&dev->dev, "invalid MAC address %pM\n",
1365
- dev->dev_addr);
1354
+ netdev_err(dev, "invalid MAC address %pM\n", dev->dev_addr);
13661355 return -EADDRNOTAVAIL;
13671356 }
13681357 /* Reset the hardware here (and take it out of low power mode) */
....@@ -1370,7 +1359,7 @@
13701359 enc28j60_hw_disable(priv);
13711360 if (!enc28j60_hw_init(priv)) {
13721361 if (netif_msg_ifup(priv))
1373
- dev_err(&dev->dev, "hw_reset() failed\n");
1362
+ netdev_err(dev, "hw_reset() failed\n");
13741363 return -EINVAL;
13751364 }
13761365 /* Update the MAC address (in case user has changed it) */
....@@ -1392,9 +1381,6 @@
13921381 {
13931382 struct enc28j60_net *priv = netdev_priv(dev);
13941383
1395
- if (netif_msg_drv(priv))
1396
- printk(KERN_DEBUG DRV_NAME ": %s() enter\n", __func__);
1397
-
13981384 enc28j60_hw_disable(priv);
13991385 enc28j60_lowpower(priv, true);
14001386 netif_stop_queue(dev);
....@@ -1415,16 +1401,16 @@
14151401
14161402 if (dev->flags & IFF_PROMISC) {
14171403 if (netif_msg_link(priv))
1418
- dev_info(&dev->dev, "promiscuous mode\n");
1404
+ netdev_info(dev, "promiscuous mode\n");
14191405 priv->rxfilter = RXFILTER_PROMISC;
14201406 } else if ((dev->flags & IFF_ALLMULTI) || !netdev_mc_empty(dev)) {
14211407 if (netif_msg_link(priv))
1422
- dev_info(&dev->dev, "%smulticast mode\n",
1423
- (dev->flags & IFF_ALLMULTI) ? "all-" : "");
1408
+ netdev_info(dev, "%smulticast mode\n",
1409
+ (dev->flags & IFF_ALLMULTI) ? "all-" : "");
14241410 priv->rxfilter = RXFILTER_MULTI;
14251411 } else {
14261412 if (netif_msg_link(priv))
1427
- dev_info(&dev->dev, "normal mode\n");
1413
+ netdev_info(dev, "normal mode\n");
14281414 priv->rxfilter = RXFILTER_NORMAL;
14291415 }
14301416
....@@ -1436,20 +1422,21 @@
14361422 {
14371423 struct enc28j60_net *priv =
14381424 container_of(work, struct enc28j60_net, setrx_work);
1425
+ struct device *dev = &priv->spi->dev;
14391426
14401427 if (priv->rxfilter == RXFILTER_PROMISC) {
14411428 if (netif_msg_drv(priv))
1442
- printk(KERN_DEBUG DRV_NAME ": promiscuous mode\n");
1429
+ dev_printk(KERN_DEBUG, dev, "promiscuous mode\n");
14431430 locked_regb_write(priv, ERXFCON, 0x00);
14441431 } else if (priv->rxfilter == RXFILTER_MULTI) {
14451432 if (netif_msg_drv(priv))
1446
- printk(KERN_DEBUG DRV_NAME ": multicast mode\n");
1433
+ dev_printk(KERN_DEBUG, dev, "multicast mode\n");
14471434 locked_regb_write(priv, ERXFCON,
14481435 ERXFCON_UCEN | ERXFCON_CRCEN |
14491436 ERXFCON_BCEN | ERXFCON_MCEN);
14501437 } else {
14511438 if (netif_msg_drv(priv))
1452
- printk(KERN_DEBUG DRV_NAME ": normal mode\n");
1439
+ dev_printk(KERN_DEBUG, dev, "normal mode\n");
14531440 locked_regb_write(priv, ERXFCON,
14541441 ERXFCON_UCEN | ERXFCON_CRCEN |
14551442 ERXFCON_BCEN);
....@@ -1468,7 +1455,7 @@
14681455 enc28j60_net_close(ndev);
14691456 ret = enc28j60_net_open(ndev);
14701457 if (unlikely(ret)) {
1471
- dev_info(&ndev->dev, " could not restart %d\n", ret);
1458
+ netdev_info(ndev, "could not restart %d\n", ret);
14721459 dev_close(ndev);
14731460 }
14741461 }
....@@ -1552,14 +1539,13 @@
15521539
15531540 static int enc28j60_probe(struct spi_device *spi)
15541541 {
1542
+ unsigned char macaddr[ETH_ALEN];
15551543 struct net_device *dev;
15561544 struct enc28j60_net *priv;
1557
- const void *macaddr;
15581545 int ret = 0;
15591546
15601547 if (netif_msg_drv(&debug))
1561
- dev_info(&spi->dev, DRV_NAME " Ethernet driver %s loaded\n",
1562
- DRV_VERSION);
1548
+ dev_info(&spi->dev, "Ethernet driver %s loaded\n", DRV_VERSION);
15631549
15641550 dev = alloc_etherdev(sizeof(struct enc28j60_net));
15651551 if (!dev) {
....@@ -1570,8 +1556,7 @@
15701556
15711557 priv->netdev = dev; /* priv to netdev reference */
15721558 priv->spi = spi; /* priv to spi reference */
1573
- priv->msg_enable = netif_msg_init(debug.msg_enable,
1574
- ENC28J60_MSG_DEFAULT);
1559
+ priv->msg_enable = netif_msg_init(debug.msg_enable, ENC28J60_MSG_DEFAULT);
15751560 mutex_init(&priv->lock);
15761561 INIT_WORK(&priv->tx_work, enc28j60_tx_work_handler);
15771562 INIT_WORK(&priv->setrx_work, enc28j60_setrx_work_handler);
....@@ -1582,13 +1567,12 @@
15821567
15831568 if (!enc28j60_chipset_init(dev)) {
15841569 if (netif_msg_probe(priv))
1585
- dev_info(&spi->dev, DRV_NAME " chip not found\n");
1570
+ dev_info(&spi->dev, "chip not found\n");
15861571 ret = -EIO;
15871572 goto error_irq;
15881573 }
15891574
1590
- macaddr = of_get_mac_address(spi->dev.of_node);
1591
- if (macaddr)
1575
+ if (device_get_mac_address(&spi->dev, macaddr, sizeof(macaddr)))
15921576 ether_addr_copy(dev->dev_addr, macaddr);
15931577 else
15941578 eth_hw_addr_random(dev);
....@@ -1600,8 +1584,8 @@
16001584 ret = request_irq(spi->irq, enc28j60_irq, 0, DRV_NAME, priv);
16011585 if (ret < 0) {
16021586 if (netif_msg_probe(priv))
1603
- dev_err(&spi->dev, DRV_NAME ": request irq %d failed "
1604
- "(ret = %d)\n", spi->irq, ret);
1587
+ dev_err(&spi->dev, "request irq %d failed (ret = %d)\n",
1588
+ spi->irq, ret);
16051589 goto error_irq;
16061590 }
16071591
....@@ -1616,11 +1600,10 @@
16161600 ret = register_netdev(dev);
16171601 if (ret) {
16181602 if (netif_msg_probe(priv))
1619
- dev_err(&spi->dev, "register netdev " DRV_NAME
1620
- " failed (ret = %d)\n", ret);
1603
+ dev_err(&spi->dev, "register netdev failed (ret = %d)\n",
1604
+ ret);
16211605 goto error_register;
16221606 }
1623
- dev_info(&dev->dev, DRV_NAME " driver registered\n");
16241607
16251608 return 0;
16261609
....@@ -1635,9 +1618,6 @@
16351618 static int enc28j60_remove(struct spi_device *spi)
16361619 {
16371620 struct enc28j60_net *priv = spi_get_drvdata(spi);
1638
-
1639
- if (netif_msg_drv(priv))
1640
- printk(KERN_DEBUG DRV_NAME ": remove\n");
16411621
16421622 unregister_netdev(priv->netdev);
16431623 free_irq(spi->irq, priv);
....@@ -1660,26 +1640,11 @@
16601640 .probe = enc28j60_probe,
16611641 .remove = enc28j60_remove,
16621642 };
1663
-
1664
-static int __init enc28j60_init(void)
1665
-{
1666
- msec20_to_jiffies = msecs_to_jiffies(20);
1667
-
1668
- return spi_register_driver(&enc28j60_driver);
1669
-}
1670
-
1671
-module_init(enc28j60_init);
1672
-
1673
-static void __exit enc28j60_exit(void)
1674
-{
1675
- spi_unregister_driver(&enc28j60_driver);
1676
-}
1677
-
1678
-module_exit(enc28j60_exit);
1643
+module_spi_driver(enc28j60_driver);
16791644
16801645 MODULE_DESCRIPTION(DRV_NAME " ethernet driver");
16811646 MODULE_AUTHOR("Claudio Lanconelli <lanconelli.claudio@eptar.com>");
16821647 MODULE_LICENSE("GPL");
16831648 module_param_named(debug, debug.msg_enable, int, 0);
1684
-MODULE_PARM_DESC(debug, "Debug verbosity level (0=none, ..., ffff=all)");
1649
+MODULE_PARM_DESC(debug, "Debug verbosity level in amount of bits set (0=none, ..., 31=all)");
16851650 MODULE_ALIAS("spi:" DRV_NAME);