hc
2024-05-10 23fa18eaa71266feff7ba8d83022d9e1cc83c65a
kernel/drivers/net/ethernet/8390/ne2k-pci.c
....@@ -1,39 +1,43 @@
1
-/* ne2k-pci.c: A NE2000 clone on PCI bus driver for Linux. */
2
-/*
3
- A Linux device driver for PCI NE2000 clones.
4
-
5
- Authors and other copyright holders:
6
- 1992-2000 by Donald Becker, NE2000 core and various modifications.
7
- 1995-1998 by Paul Gortmaker, core modifications and PCI support.
8
- Copyright 1993 assigned to the United States Government as represented
9
- by the Director, National Security Agency.
10
-
11
- This software may be used and distributed according to the terms of
12
- the GNU General Public License (GPL), incorporated herein by reference.
13
- Drivers based on or derived from this code fall under the GPL and must
14
- retain the authorship, copyright and license notice. This file is not
15
- a complete program and may only be used when the entire operating
16
- system is licensed under the GPL.
17
-
18
- The author may be reached as becker@scyld.com, or C/O
19
- Scyld Computing Corporation
20
- 410 Severn Ave., Suite 210
21
- Annapolis MD 21403
22
-
23
- Issues remaining:
24
- People are making PCI ne2000 clones! Oh the horror, the horror...
25
- Limited full-duplex support.
26
-*/
1
+/* A Linux device driver for PCI NE2000 clones.
2
+ *
3
+ * Authors and other copyright holders:
4
+ * 1992-2000 by Donald Becker, NE2000 core and various modifications.
5
+ * 1995-1998 by Paul Gortmaker, core modifications and PCI support.
6
+ * Copyright 1993 assigned to the United States Government as represented
7
+ * by the Director, National Security Agency.
8
+ *
9
+ * This software may be used and distributed according to the terms of
10
+ * the GNU General Public License (GPL), incorporated herein by reference.
11
+ * Drivers based on or derived from this code fall under the GPL and must
12
+ * retain the authorship, copyright and license notice. This file is not
13
+ * a complete program and may only be used when the entire operating
14
+ * system is licensed under the GPL.
15
+ *
16
+ * The author may be reached as becker@scyld.com, or C/O
17
+ * Scyld Computing Corporation
18
+ * 410 Severn Ave., Suite 210
19
+ * Annapolis MD 21403
20
+ *
21
+ * Issues remaining:
22
+ * People are making PCI NE2000 clones! Oh the horror, the horror...
23
+ * Limited full-duplex support.
24
+ */
2725
2826 #define DRV_NAME "ne2k-pci"
27
+#define DRV_DESCRIPTION "PCI NE2000 clone driver"
28
+#define DRV_AUTHOR "Donald Becker / Paul Gortmaker"
2929 #define DRV_VERSION "1.03"
3030 #define DRV_RELDATE "9/22/2003"
3131
32
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
3233
3334 /* The user-configurable values.
34
- These may be modified when a driver module is loaded.*/
35
+ * These may be modified when a driver module is loaded.
36
+ */
3537
36
-#define MAX_UNITS 8 /* More are supported, limit only on options */
38
+/* More are supported, limit only on options */
39
+#define MAX_UNITS 8
40
+
3741 /* Used to pass the full-duplex flag, etc. */
3842 static int full_duplex[MAX_UNITS];
3943 static int options[MAX_UNITS];
....@@ -52,38 +56,36 @@
5256 #include <linux/netdevice.h>
5357 #include <linux/etherdevice.h>
5458
55
-#include <asm/io.h>
59
+#include <linux/io.h>
5660 #include <asm/irq.h>
5761 #include <linux/uaccess.h>
5862
5963 #include "8390.h"
6064
61
-static u32 ne2k_msg_enable;
65
+static int ne2k_msg_enable;
6266
63
-/* These identify the driver base version and may not be removed. */
64
-static const char version[] =
65
- KERN_INFO DRV_NAME ".c:v" DRV_VERSION " " DRV_RELDATE
66
- " D. Becker/P. Gortmaker\n";
67
+static const int default_msg_level = (NETIF_MSG_DRV | NETIF_MSG_PROBE |
68
+ NETIF_MSG_RX_ERR | NETIF_MSG_TX_ERR);
6769
6870 #if defined(__powerpc__)
6971 #define inl_le(addr) le32_to_cpu(inl(addr))
7072 #define inw_le(addr) le16_to_cpu(inw(addr))
7173 #endif
7274
73
-#define PFX DRV_NAME ": "
74
-
75
-MODULE_AUTHOR("Donald Becker / Paul Gortmaker");
76
-MODULE_DESCRIPTION("PCI NE2000 clone driver");
75
+MODULE_AUTHOR(DRV_AUTHOR);
76
+MODULE_DESCRIPTION(DRV_DESCRIPTION);
77
+MODULE_VERSION(DRV_VERSION);
7778 MODULE_LICENSE("GPL");
7879
79
-module_param_named(msg_enable, ne2k_msg_enable, uint, 0444);
80
+module_param_named(msg_enable, ne2k_msg_enable, int, 0444);
8081 module_param_array(options, int, NULL, 0);
8182 module_param_array(full_duplex, int, NULL, 0);
8283 MODULE_PARM_DESC(msg_enable, "Debug message level (see linux/netdevice.h for bitmap)");
8384 MODULE_PARM_DESC(options, "Bit 5: full duplex");
8485 MODULE_PARM_DESC(full_duplex, "full duplex setting(s) (1)");
8586
86
-/* Some defines that people can play with if so inclined. */
87
+/* Some defines that people can play with if so inclined.
88
+ */
8789
8890 /* Use 32 bit data-movement operations instead of 16 bit. */
8991 #define USE_LONGIO
....@@ -91,14 +93,18 @@
9193 /* Do we implement the read before write bugfix ? */
9294 /* #define NE_RW_BUGFIX */
9395
94
-/* Flags. We rename an existing ei_status field to store flags! */
95
-/* Thus only the low 8 bits are usable for non-init-time flags. */
96
+/* Flags. We rename an existing ei_status field to store flags!
97
+ * Thus only the low 8 bits are usable for non-init-time flags.
98
+ */
9699 #define ne2k_flags reg0
100
+
97101 enum {
98
- ONLY_16BIT_IO=8, ONLY_32BIT_IO=4, /* Chip can do only 16/32-bit xfers. */
99
- FORCE_FDX=0x20, /* User override. */
100
- REALTEK_FDX=0x40, HOLTEK_FDX=0x80,
101
- STOP_PG_0x60=0x100,
102
+ /* Chip can do only 16/32-bit xfers. */
103
+ ONLY_16BIT_IO = 8, ONLY_32BIT_IO = 4,
104
+ /* User override. */
105
+ FORCE_FDX = 0x20,
106
+ REALTEK_FDX = 0x40, HOLTEK_FDX = 0x80,
107
+ STOP_PG_0x60 = 0x100,
102108 };
103109
104110 enum ne2k_pci_chipsets {
....@@ -120,7 +126,7 @@
120126 char *name;
121127 int flags;
122128 } pci_clone_list[] = {
123
- {"RealTek RTL-8029", REALTEK_FDX},
129
+ {"RealTek RTL-8029(AS)", REALTEK_FDX},
124130 {"Winbond 89C940", 0},
125131 {"Compex RL2000", 0},
126132 {"KTI ET32P2", 0},
....@@ -149,13 +155,14 @@
149155 { 0x8c4a, 0x1980, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_Winbond_89C940_8c4a },
150156 { 0, }
151157 };
158
+
152159 MODULE_DEVICE_TABLE(pci, ne2k_pci_tbl);
153160
154161
155162 /* ---- No user-serviceable parts below ---- */
156163
157164 #define NE_BASE (dev->base_addr)
158
-#define NE_CMD 0x00
165
+#define NE_CMD 0x00
159166 #define NE_DATAPORT 0x10 /* NatSemi-defined port window offset. */
160167 #define NE_RESET 0x1f /* Issue a read to reset, a write to clear. */
161168 #define NE_IO_EXTENT 0x20
....@@ -168,18 +175,20 @@
168175 static int ne2k_pci_close(struct net_device *dev);
169176
170177 static void ne2k_pci_reset_8390(struct net_device *dev);
171
-static void ne2k_pci_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr,
172
- int ring_page);
178
+static void ne2k_pci_get_8390_hdr(struct net_device *dev,
179
+ struct e8390_pkt_hdr *hdr, int ring_page);
173180 static void ne2k_pci_block_input(struct net_device *dev, int count,
174
- struct sk_buff *skb, int ring_offset);
181
+ struct sk_buff *skb, int ring_offset);
175182 static void ne2k_pci_block_output(struct net_device *dev, const int count,
176
- const unsigned char *buf, const int start_page);
183
+ const unsigned char *buf,
184
+ const int start_page);
177185 static const struct ethtool_ops ne2k_pci_ethtool_ops;
178186
179187
180188
181189 /* There is no room in the standard 8390 structure for extra info we need,
182
- so we build a meta/outer-wrapper structure.. */
190
+ * so we build a meta/outer-wrapper structure..
191
+ */
183192 struct ne2k_pci_card {
184193 struct net_device *dev;
185194 struct pci_dev *pci_dev;
....@@ -187,18 +196,17 @@
187196
188197
189198
190
-/*
191
- NEx000-clone boards have a Station Address (SA) PROM (SAPROM) in the packet
192
- buffer memory space. By-the-spec NE2000 clones have 0x57,0x57 in bytes
193
- 0x0e,0x0f of the SAPROM, while other supposed NE2000 clones must be
194
- detected by their SA prefix.
195
-
196
- Reading the SAPROM from a word-wide card with the 8390 set in byte-wide
197
- mode results in doubled values, which can be detected and compensated for.
198
-
199
- The probe is also responsible for initializing the card and filling
200
- in the 'dev' and 'ei_status' structures.
201
-*/
199
+/* NEx000-clone boards have a Station Address (SA) PROM (SAPROM) in the packet
200
+ * buffer memory space. By-the-spec NE2000 clones have 0x57,0x57 in bytes
201
+ * 0x0e,0x0f of the SAPROM, while other supposed NE2000 clones must be
202
+ * detected by their SA prefix.
203
+ *
204
+ * Reading the SAPROM from a word-wide card with the 8390 set in byte-wide
205
+ * mode results in doubled values, which can be detected and compensated for.
206
+ *
207
+ * The probe is also responsible for initializing the card and filling
208
+ * in the 'dev' and 'ei_status' structures.
209
+ */
202210
203211 static const struct net_device_ops ne2k_netdev_ops = {
204212 .ndo_open = ne2k_pci_open,
....@@ -208,7 +216,7 @@
208216 .ndo_get_stats = ei_get_stats,
209217 .ndo_set_rx_mode = ei_set_multicast_list,
210218 .ndo_validate_addr = eth_validate_addr,
211
- .ndo_set_mac_address = eth_mac_addr,
219
+ .ndo_set_mac_address = eth_mac_addr,
212220 #ifdef CONFIG_NET_POLL_CONTROLLER
213221 .ndo_poll_controller = ei_poll,
214222 #endif
....@@ -227,28 +235,21 @@
227235 int flags = pci_clone_list[chip_idx].flags;
228236 struct ei_device *ei_local;
229237
230
-/* when built into the kernel, we only print version if device is found */
231
-#ifndef MODULE
232
- static int printed_version;
233
- if (!printed_version++)
234
- printk(version);
235
-#endif
236
-
237238 fnd_cnt++;
238239
239
- i = pci_enable_device (pdev);
240
+ i = pci_enable_device(pdev);
240241 if (i)
241242 return i;
242243
243
- ioaddr = pci_resource_start (pdev, 0);
244
+ ioaddr = pci_resource_start(pdev, 0);
244245 irq = pdev->irq;
245246
246
- if (!ioaddr || ((pci_resource_flags (pdev, 0) & IORESOURCE_IO) == 0)) {
247
+ if (!ioaddr || ((pci_resource_flags(pdev, 0) & IORESOURCE_IO) == 0)) {
247248 dev_err(&pdev->dev, "no I/O resource at PCI BAR #0\n");
248249 goto err_out;
249250 }
250251
251
- if (request_region (ioaddr, NE_IO_EXTENT, DRV_NAME) == NULL) {
252
+ if (!request_region(ioaddr, NE_IO_EXTENT, DRV_NAME)) {
252253 dev_err(&pdev->dev, "I/O resource 0x%x @ 0x%lx busy\n",
253254 NE_IO_EXTENT, ioaddr);
254255 goto err_out;
....@@ -261,14 +262,17 @@
261262 /* Do a preliminary verification that we have a 8390. */
262263 {
263264 int regd;
264
- outb(E8390_NODMA+E8390_PAGE1+E8390_STOP, ioaddr + E8390_CMD);
265
+
266
+ outb(E8390_NODMA + E8390_PAGE1 + E8390_STOP, ioaddr + E8390_CMD);
265267 regd = inb(ioaddr + 0x0d);
266268 outb(0xff, ioaddr + 0x0d);
267
- outb(E8390_NODMA+E8390_PAGE0, ioaddr + E8390_CMD);
268
- inb(ioaddr + EN0_COUNTER0); /* Clear the counter by reading. */
269
+ outb(E8390_NODMA + E8390_PAGE0, ioaddr + E8390_CMD);
270
+ /* Clear the counter by reading. */
271
+ inb(ioaddr + EN0_COUNTER0);
269272 if (inb(ioaddr + EN0_COUNTER0) != 0) {
270273 outb(reg0, ioaddr);
271
- outb(regd, ioaddr + 0x0d); /* Restore the old values. */
274
+ /* Restore the old values. */
275
+ outb(regd, ioaddr + 0x0d);
272276 goto err_out_free_res;
273277 }
274278 }
....@@ -281,7 +285,7 @@
281285 }
282286 dev->netdev_ops = &ne2k_netdev_ops;
283287 ei_local = netdev_priv(dev);
284
- ei_local->msg_enable = ne2k_msg_enable;
288
+ ei_local->msg_enable = netif_msg_init(ne2k_msg_enable, default_msg_level);
285289
286290 SET_NETDEV_DEV(dev, &pdev->dev);
287291
....@@ -291,9 +295,9 @@
291295
292296 outb(inb(ioaddr + NE_RESET), ioaddr + NE_RESET);
293297
294
- /* This looks like a horrible timing loop, but it should never take
295
- more than a few cycles.
296
- */
298
+ /* This looks like a horrible timing loop, but it should never
299
+ * take more than a few cycles.
300
+ */
297301 while ((inb(ioaddr + EN0_ISR) & ENISR_RESET) == 0)
298302 /* Limit wait: '2' avoids jiffy roll-over. */
299303 if (jiffies - reset_start_time > 2) {
....@@ -301,42 +305,53 @@
301305 "Card failure (no reset ack).\n");
302306 goto err_out_free_netdev;
303307 }
304
-
305
- outb(0xff, ioaddr + EN0_ISR); /* Ack all intr. */
308
+ /* Ack all intr. */
309
+ outb(0xff, ioaddr + EN0_ISR);
306310 }
307311
308312 /* Read the 16 bytes of station address PROM.
309
- We must first initialize registers, similar to NS8390_init(eifdev, 0).
310
- We can't reliably read the SAPROM address without this.
311
- (I learned the hard way!). */
313
+ * We must first initialize registers, similar
314
+ * to NS8390_init(eifdev, 0).
315
+ * We can't reliably read the SAPROM address without this.
316
+ * (I learned the hard way!).
317
+ */
312318 {
313319 struct {unsigned char value, offset; } program_seq[] = {
314
- {E8390_NODMA+E8390_PAGE0+E8390_STOP, E8390_CMD}, /* Select page 0*/
315
- {0x49, EN0_DCFG}, /* Set word-wide access. */
316
- {0x00, EN0_RCNTLO}, /* Clear the count regs. */
320
+ /* Select page 0 */
321
+ {E8390_NODMA + E8390_PAGE0 + E8390_STOP, E8390_CMD},
322
+ /* Set word-wide access */
323
+ {0x49, EN0_DCFG},
324
+ /* Clear the count regs. */
325
+ {0x00, EN0_RCNTLO},
326
+ /* Mask completion IRQ */
317327 {0x00, EN0_RCNTHI},
318
- {0x00, EN0_IMR}, /* Mask completion irq. */
328
+ {0x00, EN0_IMR},
319329 {0xFF, EN0_ISR},
320
- {E8390_RXOFF, EN0_RXCR}, /* 0x20 Set to monitor */
321
- {E8390_TXOFF, EN0_TXCR}, /* 0x02 and loopback mode. */
330
+ /* 0x20 Set to monitor */
331
+ {E8390_RXOFF, EN0_RXCR},
332
+ /* 0x02 and loopback mode */
333
+ {E8390_TXOFF, EN0_TXCR},
322334 {32, EN0_RCNTLO},
323335 {0x00, EN0_RCNTHI},
324
- {0x00, EN0_RSARLO}, /* DMA starting at 0x0000. */
336
+ /* DMA starting at 0x0000 */
337
+ {0x00, EN0_RSARLO},
325338 {0x00, EN0_RSARHI},
326339 {E8390_RREAD+E8390_START, E8390_CMD},
327340 };
328341 for (i = 0; i < ARRAY_SIZE(program_seq); i++)
329
- outb(program_seq[i].value, ioaddr + program_seq[i].offset);
342
+ outb(program_seq[i].value,
343
+ ioaddr + program_seq[i].offset);
330344
331345 }
332346
333347 /* Note: all PCI cards have at least 16 bit access, so we don't have
334
- to check for 8 bit cards. Most cards permit 32 bit access. */
348
+ * to check for 8 bit cards. Most cards permit 32 bit access.
349
+ */
335350 if (flags & ONLY_32BIT_IO) {
336351 for (i = 0; i < 4 ; i++)
337352 ((u32 *)SA_prom)[i] = le32_to_cpu(inl(ioaddr + NE_DATAPORT));
338353 } else
339
- for(i = 0; i < 32 /*sizeof(SA_prom)*/; i++)
354
+ for (i = 0; i < 32 /* sizeof(SA_prom )*/; i++)
340355 SA_prom[i] = inb(ioaddr + NE_DATAPORT);
341356
342357 /* We always set the 8390 registers for word mode. */
....@@ -356,7 +371,7 @@
356371 ei_status.word16 = 1;
357372 ei_status.ne2k_flags = flags;
358373 if (fnd_cnt < MAX_UNITS) {
359
- if (full_duplex[fnd_cnt] > 0 || (options[fnd_cnt] & FORCE_FDX))
374
+ if (full_duplex[fnd_cnt] > 0 || (options[fnd_cnt] & FORCE_FDX))
360375 ei_status.ne2k_flags |= FORCE_FDX;
361376 }
362377
....@@ -388,16 +403,15 @@
388403 return 0;
389404
390405 err_out_free_netdev:
391
- free_netdev (dev);
406
+ free_netdev(dev);
392407 err_out_free_res:
393
- release_region (ioaddr, NE_IO_EXTENT);
408
+ release_region(ioaddr, NE_IO_EXTENT);
394409 err_out:
395410 pci_disable_device(pdev);
396411 return -ENODEV;
397412 }
398413
399
-/*
400
- * Magic incantation sequence for full duplex on the supported cards.
414
+/* Magic incantation sequence for full duplex on the supported cards.
401415 */
402416 static inline int set_realtek_fdx(struct net_device *dev)
403417 {
....@@ -431,7 +445,9 @@
431445
432446 static int ne2k_pci_open(struct net_device *dev)
433447 {
434
- int ret = request_irq(dev->irq, ei_interrupt, IRQF_SHARED, dev->name, dev);
448
+ int ret = request_irq(dev->irq, ei_interrupt, IRQF_SHARED,
449
+ dev->name, dev);
450
+
435451 if (ret)
436452 return ret;
437453
....@@ -450,7 +466,8 @@
450466 }
451467
452468 /* Hard reset the card. This used to pause for the same period that a
453
- 8390 reset command required, but that shouldn't be necessary. */
469
+ * 8390 reset command required, but that shouldn't be necessary.
470
+ */
454471 static void ne2k_pci_reset_8390(struct net_device *dev)
455472 {
456473 unsigned long reset_start_time = jiffies;
....@@ -467,31 +484,34 @@
467484 /* This check _should_not_ be necessary, omit eventually. */
468485 while ((inb(NE_BASE+EN0_ISR) & ENISR_RESET) == 0)
469486 if (jiffies - reset_start_time > 2) {
470
- netdev_err(dev, "ne2k_pci_reset_8390() did not complete.\n");
487
+ netdev_err(dev, "%s did not complete.\n", __func__);
471488 break;
472489 }
473
- outb(ENISR_RESET, NE_BASE + EN0_ISR); /* Ack intr. */
490
+ /* Ack intr. */
491
+ outb(ENISR_RESET, NE_BASE + EN0_ISR);
474492 }
475493
476494 /* Grab the 8390 specific header. Similar to the block_input routine, but
477
- we don't need to be concerned with ring wrap as the header will be at
478
- the start of a page, so we optimize accordingly. */
495
+ * we don't need to be concerned with ring wrap as the header will be at
496
+ * the start of a page, so we optimize accordingly.
497
+ */
479498
480
-static void ne2k_pci_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr, int ring_page)
499
+static void ne2k_pci_get_8390_hdr(struct net_device *dev,
500
+ struct e8390_pkt_hdr *hdr, int ring_page)
481501 {
482502
483503 long nic_base = dev->base_addr;
484504
485
- /* This *shouldn't* happen. If it does, it's the last thing you'll see */
505
+ /* This *shouldn't* happen. If it does, it's the last thing you'll see
506
+ */
486507 if (ei_status.dmaing) {
487
- netdev_err(dev, "DMAing conflict in ne2k_pci_get_8390_hdr "
488
- "[DMAstat:%d][irqlock:%d].\n",
489
- ei_status.dmaing, ei_status.irqlock);
508
+ netdev_err(dev, "DMAing conflict in %s [DMAstat:%d][irqlock:%d].\n",
509
+ __func__, ei_status.dmaing, ei_status.irqlock);
490510 return;
491511 }
492512
493513 ei_status.dmaing |= 0x01;
494
- outb(E8390_NODMA+E8390_PAGE0+E8390_START, nic_base+ NE_CMD);
514
+ outb(E8390_NODMA + E8390_PAGE0 + E8390_START, nic_base + NE_CMD);
495515 outb(sizeof(struct e8390_pkt_hdr), nic_base + EN0_RCNTLO);
496516 outb(0, nic_base + EN0_RCNTHI);
497517 outb(0, nic_base + EN0_RSARLO); /* On page boundary */
....@@ -499,20 +519,22 @@
499519 outb(E8390_RREAD+E8390_START, nic_base + NE_CMD);
500520
501521 if (ei_status.ne2k_flags & ONLY_16BIT_IO) {
502
- insw(NE_BASE + NE_DATAPORT, hdr, sizeof(struct e8390_pkt_hdr)>>1);
522
+ insw(NE_BASE + NE_DATAPORT, hdr,
523
+ sizeof(struct e8390_pkt_hdr) >> 1);
503524 } else {
504
- *(u32*)hdr = le32_to_cpu(inl(NE_BASE + NE_DATAPORT));
525
+ *(u32 *)hdr = le32_to_cpu(inl(NE_BASE + NE_DATAPORT));
505526 le16_to_cpus(&hdr->count);
506527 }
507
-
508
- outb(ENISR_RDC, nic_base + EN0_ISR); /* Ack intr. */
528
+ /* Ack intr. */
529
+ outb(ENISR_RDC, nic_base + EN0_ISR);
509530 ei_status.dmaing &= ~0x01;
510531 }
511532
512533 /* Block input and output, similar to the Crynwr packet driver. If you
513
- are porting to a new ethercard, look at the packet driver source for hints.
514
- The NEx000 doesn't share the on-board packet memory -- you have to put
515
- the packet out through the "remote DMA" dataport using outb. */
534
+ *are porting to a new ethercard, look at the packet driver source for hints.
535
+ *The NEx000 doesn't share the on-board packet memory -- you have to put
536
+ *the packet out through the "remote DMA" dataport using outb.
537
+ */
516538
517539 static void ne2k_pci_block_input(struct net_device *dev, int count,
518540 struct sk_buff *skb, int ring_offset)
....@@ -520,30 +542,30 @@
520542 long nic_base = dev->base_addr;
521543 char *buf = skb->data;
522544
523
- /* This *shouldn't* happen. If it does, it's the last thing you'll see */
545
+ /* This *shouldn't* happen.
546
+ * If it does, it's the last thing you'll see.
547
+ */
524548 if (ei_status.dmaing) {
525
- netdev_err(dev, "DMAing conflict in ne2k_pci_block_input "
526
- "[DMAstat:%d][irqlock:%d].\n",
527
- ei_status.dmaing, ei_status.irqlock);
549
+ netdev_err(dev, "DMAing conflict in %s [DMAstat:%d][irqlock:%d]\n",
550
+ __func__, ei_status.dmaing, ei_status.irqlock);
528551 return;
529552 }
530553 ei_status.dmaing |= 0x01;
531554 if (ei_status.ne2k_flags & ONLY_32BIT_IO)
532555 count = (count + 3) & 0xFFFC;
533
- outb(E8390_NODMA+E8390_PAGE0+E8390_START, nic_base+ NE_CMD);
556
+ outb(E8390_NODMA + E8390_PAGE0 + E8390_START, nic_base + NE_CMD);
534557 outb(count & 0xff, nic_base + EN0_RCNTLO);
535558 outb(count >> 8, nic_base + EN0_RCNTHI);
536559 outb(ring_offset & 0xff, nic_base + EN0_RSARLO);
537560 outb(ring_offset >> 8, nic_base + EN0_RSARHI);
538
- outb(E8390_RREAD+E8390_START, nic_base + NE_CMD);
561
+ outb(E8390_RREAD + E8390_START, nic_base + NE_CMD);
539562
540563 if (ei_status.ne2k_flags & ONLY_16BIT_IO) {
541
- insw(NE_BASE + NE_DATAPORT,buf,count>>1);
542
- if (count & 0x01) {
564
+ insw(NE_BASE + NE_DATAPORT, buf, count >> 1);
565
+ if (count & 0x01)
543566 buf[count-1] = inb(NE_BASE + NE_DATAPORT);
544
- }
545567 } else {
546
- insl(NE_BASE + NE_DATAPORT, buf, count>>2);
568
+ insl(NE_BASE + NE_DATAPORT, buf, count >> 2);
547569 if (count & 3) {
548570 buf += count & ~3;
549571 if (count & 2) {
....@@ -556,30 +578,32 @@
556578 *buf = inb(NE_BASE + NE_DATAPORT);
557579 }
558580 }
559
-
560
- outb(ENISR_RDC, nic_base + EN0_ISR); /* Ack intr. */
581
+ /* Ack intr. */
582
+ outb(ENISR_RDC, nic_base + EN0_ISR);
561583 ei_status.dmaing &= ~0x01;
562584 }
563585
564586 static void ne2k_pci_block_output(struct net_device *dev, int count,
565
- const unsigned char *buf, const int start_page)
587
+ const unsigned char *buf, const int start_page)
566588 {
567589 long nic_base = NE_BASE;
568590 unsigned long dma_start;
569591
570592 /* On little-endian it's always safe to round the count up for
571
- word writes. */
593
+ * word writes.
594
+ */
572595 if (ei_status.ne2k_flags & ONLY_32BIT_IO)
573596 count = (count + 3) & 0xFFFC;
574597 else
575598 if (count & 0x01)
576599 count++;
577600
578
- /* This *shouldn't* happen. If it does, it's the last thing you'll see */
601
+ /* This *shouldn't* happen.
602
+ * If it does, it's the last thing you'll see.
603
+ */
579604 if (ei_status.dmaing) {
580
- netdev_err(dev, "DMAing conflict in ne2k_pci_block_output."
581
- "[DMAstat:%d][irqlock:%d]\n",
582
- ei_status.dmaing, ei_status.irqlock);
605
+ netdev_err(dev, "DMAing conflict in %s [DMAstat:%d][irqlock:%d]\n",
606
+ __func__, ei_status.dmaing, ei_status.irqlock);
583607 return;
584608 }
585609 ei_status.dmaing |= 0x01;
....@@ -588,9 +612,10 @@
588612
589613 #ifdef NE8390_RW_BUGFIX
590614 /* Handle the read-before-write bug the same way as the
591
- Crynwr packet driver -- the NatSemi method doesn't work.
592
- Actually this doesn't always work either, but if you have
593
- problems with your NEx000 this is better than nothing! */
615
+ * Crynwr packet driver -- the NatSemi method doesn't work.
616
+ * Actually this doesn't always work either, but if you have
617
+ * problems with your NEx000 this is better than nothing!
618
+ */
594619 outb(0x42, nic_base + EN0_RCNTLO);
595620 outb(0x00, nic_base + EN0_RCNTHI);
596621 outb(0x42, nic_base + EN0_RSARLO);
....@@ -599,16 +624,16 @@
599624 #endif
600625 outb(ENISR_RDC, nic_base + EN0_ISR);
601626
602
- /* Now the normal output. */
627
+ /* Now the normal output. */
603628 outb(count & 0xff, nic_base + EN0_RCNTLO);
604629 outb(count >> 8, nic_base + EN0_RCNTHI);
605630 outb(0x00, nic_base + EN0_RSARLO);
606631 outb(start_page, nic_base + EN0_RSARHI);
607632 outb(E8390_RWRITE+E8390_START, nic_base + NE_CMD);
608633 if (ei_status.ne2k_flags & ONLY_16BIT_IO) {
609
- outsw(NE_BASE + NE_DATAPORT, buf, count>>1);
634
+ outsw(NE_BASE + NE_DATAPORT, buf, count >> 1);
610635 } else {
611
- outsl(NE_BASE + NE_DATAPORT, buf, count>>2);
636
+ outsl(NE_BASE + NE_DATAPORT, buf, count >> 2);
612637 if (count & 3) {
613638 buf += count & ~3;
614639 if (count & 2) {
....@@ -623,14 +648,15 @@
623648 dma_start = jiffies;
624649
625650 while ((inb(nic_base + EN0_ISR) & ENISR_RDC) == 0)
626
- if (jiffies - dma_start > 2) { /* Avoid clock roll-over. */
651
+ /* Avoid clock roll-over. */
652
+ if (jiffies - dma_start > 2) {
627653 netdev_warn(dev, "timeout waiting for Tx RDC.\n");
628654 ne2k_pci_reset_8390(dev);
629
- NS8390_init(dev,1);
655
+ NS8390_init(dev, 1);
630656 break;
631657 }
632
-
633
- outb(ENISR_RDC, nic_base + EN0_ISR); /* Ack intr. */
658
+ /* Ack intr. */
659
+ outb(ENISR_RDC, nic_base + EN0_ISR);
634660 ei_status.dmaing &= ~0x01;
635661 }
636662
....@@ -640,9 +666,9 @@
640666 struct ei_device *ei = netdev_priv(dev);
641667 struct pci_dev *pci_dev = (struct pci_dev *) ei->priv;
642668
643
- strlcpy(info->driver, DRV_NAME, sizeof(info->driver));
644
- strlcpy(info->version, DRV_VERSION, sizeof(info->version));
645
- strlcpy(info->bus_info, pci_name(pci_dev), sizeof(info->bus_info));
669
+ strscpy(info->driver, DRV_NAME, sizeof(info->driver));
670
+ strscpy(info->version, DRV_VERSION, sizeof(info->version));
671
+ strscpy(info->bus_info, pci_name(pci_dev), sizeof(info->bus_info));
646672 }
647673
648674 static u32 ne2k_pci_get_msglevel(struct net_device *dev)
....@@ -676,30 +702,18 @@
676702 pci_disable_device(pdev);
677703 }
678704
679
-#ifdef CONFIG_PM
680
-static int ne2k_pci_suspend (struct pci_dev *pdev, pm_message_t state)
705
+static int __maybe_unused ne2k_pci_suspend(struct device *dev_d)
681706 {
682
- struct net_device *dev = pci_get_drvdata (pdev);
707
+ struct net_device *dev = dev_get_drvdata(dev_d);
683708
684709 netif_device_detach(dev);
685
- pci_save_state(pdev);
686
- pci_disable_device(pdev);
687
- pci_set_power_state(pdev, pci_choose_state(pdev, state));
688710
689711 return 0;
690712 }
691713
692
-static int ne2k_pci_resume (struct pci_dev *pdev)
714
+static int __maybe_unused ne2k_pci_resume(struct device *dev_d)
693715 {
694
- struct net_device *dev = pci_get_drvdata (pdev);
695
- int rc;
696
-
697
- pci_set_power_state(pdev, PCI_D0);
698
- pci_restore_state(pdev);
699
-
700
- rc = pci_enable_device(pdev);
701
- if (rc)
702
- return rc;
716
+ struct net_device *dev = dev_get_drvdata(dev_d);
703717
704718 NS8390_init(dev, 1);
705719 netif_device_attach(dev);
....@@ -707,35 +721,26 @@
707721 return 0;
708722 }
709723
710
-#endif /* CONFIG_PM */
711
-
724
+static SIMPLE_DEV_PM_OPS(ne2k_pci_pm_ops, ne2k_pci_suspend, ne2k_pci_resume);
712725
713726 static struct pci_driver ne2k_driver = {
714727 .name = DRV_NAME,
715728 .probe = ne2k_pci_init_one,
716729 .remove = ne2k_pci_remove_one,
717730 .id_table = ne2k_pci_tbl,
718
-#ifdef CONFIG_PM
719
- .suspend = ne2k_pci_suspend,
720
- .resume = ne2k_pci_resume,
721
-#endif /* CONFIG_PM */
722
-
731
+ .driver.pm = &ne2k_pci_pm_ops,
723732 };
724733
725734
726735 static int __init ne2k_pci_init(void)
727736 {
728
-/* when a module, this is printed whether or not devices are found in probe */
729
-#ifdef MODULE
730
- printk(version);
731
-#endif
732737 return pci_register_driver(&ne2k_driver);
733738 }
734739
735740
736741 static void __exit ne2k_pci_cleanup(void)
737742 {
738
- pci_unregister_driver (&ne2k_driver);
743
+ pci_unregister_driver(&ne2k_driver);
739744 }
740745
741746 module_init(ne2k_pci_init);