drivers/net/: all drivers/net/ cleanup with ARRAY_SIZE
[deliverable/linux.git] / drivers / net / ni5010.c
CommitLineData
1da177e4
LT
1/* ni5010.c: A network driver for the MiCom-Interlan NI5010 ethercard.
2 *
5b552b16 3 * Copyright 1996,1997,2006 Jan-Pascal van Best and Andreas Mohr.
1da177e4
LT
4 *
5 * This software may be used and distributed according to the terms
6 * of the GNU General Public License, incorporated herein by reference.
7 *
8 * The authors may be reached as:
5b552b16 9 * janpascal@vanbest.org andi@lisas.de
1da177e4
LT
10 *
11 * Sources:
12 * Donald Becker's "skeleton.c"
13 * Crynwr ni5010 packet driver
14 *
15 * Changes:
16 * v0.0: First test version
17 * v0.1: First working version
18 * v0.2:
19 * v0.3->v0.90: Now demand setting io and irq when loading as module
20 * 970430 v0.91: modified for Linux 2.1.14
21 * v0.92: Implemented Andreas' (better) NI5010 probe
22 * 970503 v0.93: Fixed auto-irq failure on warm reboot (JB)
23 * 970623 v1.00: First kernel version (AM)
24 * 970814 v1.01: Added detection of onboard receive buffer size (AM)
5b552b16 25 * 060611 v1.02: slight cleanup: email addresses, driver modernization.
1da177e4 26 * Bugs:
5b552b16 27 * - not SMP-safe (no locking of I/O accesses)
1da177e4
LT
28 * - Note that you have to patch ifconfig for the new /proc/net/dev
29 * format. It gives incorrect stats otherwise.
30 *
31 * To do:
32 * Fix all bugs :-)
33 * Move some stuff to chipset_init()
34 * Handle xmt errors other than collisions
35 * Complete merge with Andreas' driver
36 * Implement ring buffers (Is this useful? You can't squeeze
37 * too many packet in a 2k buffer!)
5b552b16 38 * Implement DMA (Again, is this useful? Some docs say DMA is
1da177e4
LT
39 * slower than programmed I/O)
40 *
41 * Compile with:
42 * gcc -O2 -fomit-frame-pointer -m486 -D__KERNEL__ \
6aa20a22 43 * -DMODULE -c ni5010.c
1da177e4
LT
44 *
45 * Insert with e.g.:
5b552b16 46 * insmod ni5010.ko io=0x300 irq=5
1da177e4
LT
47 */
48
49#include <linux/module.h>
50#include <linux/kernel.h>
51#include <linux/string.h>
52#include <linux/errno.h>
53#include <linux/ioport.h>
54#include <linux/slab.h>
55#include <linux/interrupt.h>
56#include <linux/delay.h>
57#include <linux/init.h>
58#include <linux/bitops.h>
59#include <asm/io.h>
60#include <asm/dma.h>
61
62#include <linux/netdevice.h>
63#include <linux/etherdevice.h>
64#include <linux/skbuff.h>
65
66#include "ni5010.h"
67
5b552b16
AM
68static const char boardname[] = "NI5010";
69static char version[] __initdata =
70 "ni5010.c: v1.02 20060611 Jan-Pascal van Best and Andreas Mohr\n";
6aa20a22 71
1da177e4
LT
72/* bufsize_rcv == 0 means autoprobing */
73static unsigned int bufsize_rcv;
74
5b552b16
AM
75#define JUMPERED_INTERRUPTS /* IRQ line jumpered on board */
76#undef JUMPERED_DMA /* No DMA used */
1da177e4
LT
77#undef FULL_IODETECT /* Only detect in portlist */
78
79#ifndef FULL_IODETECT
80/* A zero-terminated list of I/O addresses to be probed. */
81static unsigned int ports[] __initdata =
82 { 0x300, 0x320, 0x340, 0x360, 0x380, 0x3a0, 0 };
83#endif
84
85/* Use 0 for production, 1 for verification, >2 for debug */
86#ifndef NI5010_DEBUG
87#define NI5010_DEBUG 0
88#endif
89
90/* Information that needs to be kept for each board. */
91struct ni5010_local {
92 struct net_device_stats stats;
93 int o_pkt_size;
94 spinlock_t lock;
95};
96
97/* Index to functions, as function prototypes. */
98
99static int ni5010_probe1(struct net_device *dev, int ioaddr);
100static int ni5010_open(struct net_device *dev);
101static int ni5010_send_packet(struct sk_buff *skb, struct net_device *dev);
7d12e780 102static irqreturn_t ni5010_interrupt(int irq, void *dev_id);
1da177e4
LT
103static void ni5010_rx(struct net_device *dev);
104static void ni5010_timeout(struct net_device *dev);
105static int ni5010_close(struct net_device *dev);
106static struct net_device_stats *ni5010_get_stats(struct net_device *dev);
107static void ni5010_set_multicast_list(struct net_device *dev);
108static void reset_receiver(struct net_device *dev);
109
110static int process_xmt_interrupt(struct net_device *dev);
111#define tx_done(dev) 1
112static void hardware_send_packet(struct net_device *dev, char *buf, int length, int pad);
113static void chipset_init(struct net_device *dev, int startp);
114static void dump_packet(void *buf, int len);
115static void ni5010_show_registers(struct net_device *dev);
116
117static int io;
118static int irq;
119
120struct net_device * __init ni5010_probe(int unit)
121{
122 struct net_device *dev = alloc_etherdev(sizeof(struct ni5010_local));
123 int *port;
124 int err = 0;
125
126 if (!dev)
127 return ERR_PTR(-ENOMEM);
128
129 if (unit >= 0) {
130 sprintf(dev->name, "eth%d", unit);
131 netdev_boot_setup_check(dev);
132 io = dev->base_addr;
133 irq = dev->irq;
134 }
135
136 PRINTK2((KERN_DEBUG "%s: Entering ni5010_probe\n", dev->name));
137
1da177e4
LT
138 if (io > 0x1ff) { /* Check a single specified location. */
139 err = ni5010_probe1(dev, io);
140 } else if (io != 0) { /* Don't probe at all. */
141 err = -ENXIO;
142 } else {
143#ifdef FULL_IODETECT
144 for (io=0x200; io<0x400 && ni5010_probe1(dev, io) ; io+=0x20)
145 ;
146 if (io == 0x400)
147 err = -ENODEV;
148
149#else
150 for (port = ports; *port && ni5010_probe1(dev, *port); port++)
151 ;
152 if (!*port)
153 err = -ENODEV;
154#endif /* FULL_IODETECT */
155 }
156 if (err)
157 goto out;
158 err = register_netdev(dev);
159 if (err)
160 goto out1;
161 return dev;
162out1:
163 release_region(dev->base_addr, NI5010_IO_EXTENT);
164out:
165 free_netdev(dev);
166 return ERR_PTR(err);
167}
168
169static inline int rd_port(int ioaddr)
170{
171 inb(IE_RBUF);
172 return inb(IE_SAPROM);
173}
174
175static void __init trigger_irq(int ioaddr)
176{
177 outb(0x00, EDLC_RESET); /* Clear EDLC hold RESET state */
178 outb(0x00, IE_RESET); /* Board reset */
179 outb(0x00, EDLC_XMASK); /* Disable all Xmt interrupts */
180 outb(0x00, EDLC_RMASK); /* Disable all Rcv interrupt */
181 outb(0xff, EDLC_XCLR); /* Clear all pending Xmt interrupts */
182 outb(0xff, EDLC_RCLR); /* Clear all pending Rcv interrupts */
183 /*
184 * Transmit packet mode: Ignore parity, Power xcvr,
185 * Enable loopback
186 */
187 outb(XMD_IG_PAR | XMD_T_MODE | XMD_LBC, EDLC_XMODE);
188 outb(RMD_BROADCAST, EDLC_RMODE); /* Receive normal&broadcast */
189 outb(XM_ALL, EDLC_XMASK); /* Enable all Xmt interrupts */
190 udelay(50); /* FIXME: Necessary? */
191 outb(MM_EN_XMT|MM_MUX, IE_MMODE); /* Start transmission */
192}
193
194/*
195 * This is the real probe routine. Linux has a history of friendly device
196 * probes on the ISA bus. A good device probes avoids doing writes, and
197 * verifies that the correct device exists and functions.
198 */
199
200static int __init ni5010_probe1(struct net_device *dev, int ioaddr)
201{
202 static unsigned version_printed;
203 struct ni5010_local *lp;
204 int i;
205 unsigned int data = 0;
206 int boguscount = 40;
207 int err = -ENODEV;
208
209 dev->base_addr = ioaddr;
210 dev->irq = irq;
211
212 if (!request_region(ioaddr, NI5010_IO_EXTENT, boardname))
213 return -EBUSY;
214
215 /*
216 * This is no "official" probe method, I've rather tested which
217 * probe works best with my seven NI5010 cards
218 * (they have very different serial numbers)
219 * Suggestions or failure reports are very, very welcome !
220 * But I think it is a relatively good probe method
221 * since it doesn't use any "outb"
222 * It should be nearly 100% reliable !
223 * well-known WARNING: this probe method (like many others)
224 * will hang the system if a NE2000 card region is probed !
225 *
226 * - Andreas
227 */
228
6aa20a22 229 PRINTK2((KERN_DEBUG "%s: entering ni5010_probe1(%#3x)\n",
1da177e4
LT
230 dev->name, ioaddr));
231
232 if (inb(ioaddr+0) == 0xff)
233 goto out;
234
235 while ( (rd_port(ioaddr) & rd_port(ioaddr) & rd_port(ioaddr) &
236 rd_port(ioaddr) & rd_port(ioaddr) & rd_port(ioaddr)) != 0xff)
237 {
238 if (boguscount-- == 0)
239 goto out;
240 }
241
242 PRINTK2((KERN_DEBUG "%s: I/O #1 passed!\n", dev->name));
243
244 for (i=0; i<32; i++)
245 if ( (data = rd_port(ioaddr)) != 0xff) break;
246 if (data==0xff)
247 goto out;
248
249 PRINTK2((KERN_DEBUG "%s: I/O #2 passed!\n", dev->name));
250
251 if ((data != SA_ADDR0) || (rd_port(ioaddr) != SA_ADDR1) ||
252 (rd_port(ioaddr) != SA_ADDR2))
253 goto out;
254
255 for (i=0; i<4; i++)
256 rd_port(ioaddr);
257
258 if ( (rd_port(ioaddr) != NI5010_MAGICVAL1) ||
259 (rd_port(ioaddr) != NI5010_MAGICVAL2) )
260 goto out;
261
262 PRINTK2((KERN_DEBUG "%s: I/O #3 passed!\n", dev->name));
263
264 if (NI5010_DEBUG && version_printed++ == 0)
265 printk(KERN_INFO "%s", version);
266
267 printk("NI5010 ethercard probe at 0x%x: ", ioaddr);
268
269 dev->base_addr = ioaddr;
270
271 for (i=0; i<6; i++) {
272 outw(i, IE_GP);
273 printk("%2.2x ", dev->dev_addr[i] = inb(IE_SAPROM));
274 }
275
276 PRINTK2((KERN_DEBUG "%s: I/O #4 passed!\n", dev->name));
277
5b552b16 278#ifdef JUMPERED_INTERRUPTS
1da177e4
LT
279 if (dev->irq == 0xff)
280 ;
281 else if (dev->irq < 2) {
282 unsigned long irq_mask;
283
284 PRINTK2((KERN_DEBUG "%s: I/O #5 passed!\n", dev->name));
285
286 irq_mask = probe_irq_on();
287 trigger_irq(ioaddr);
288 mdelay(20);
289 dev->irq = probe_irq_off(irq_mask);
290
291 PRINTK2((KERN_DEBUG "%s: I/O #6 passed!\n", dev->name));
292
293 if (dev->irq == 0) {
294 err = -EAGAIN;
295 printk(KERN_WARNING "%s: no IRQ found!\n", dev->name);
296 goto out;
297 }
298 PRINTK2((KERN_DEBUG "%s: I/O #7 passed!\n", dev->name));
299 } else if (dev->irq == 2) {
300 dev->irq = 9;
301 }
5b552b16 302#endif /* JUMPERED_INTERRUPTS */
1da177e4
LT
303 PRINTK2((KERN_DEBUG "%s: I/O #9 passed!\n", dev->name));
304
305 /* DMA is not supported (yet?), so no use detecting it */
306 lp = netdev_priv(dev);
307
308 spin_lock_init(&lp->lock);
309
310 PRINTK2((KERN_DEBUG "%s: I/O #10 passed!\n", dev->name));
311
312/* get the size of the onboard receive buffer
313 * higher addresses than bufsize are wrapped into real buffer
314 * i.e. data for offs. 0x801 is written to 0x1 with a 2K onboard buffer
315 */
316 if (!bufsize_rcv) {
317 outb(1, IE_MMODE); /* Put Rcv buffer on system bus */
318 outw(0, IE_GP); /* Point GP at start of packet */
319 outb(0, IE_RBUF); /* set buffer byte 0 to 0 */
320 for (i = 1; i < 0xff; i++) {
321 outw(i << 8, IE_GP); /* Point GP at packet size to be tested */
322 outb(i, IE_RBUF);
323 outw(0x0, IE_GP); /* Point GP at start of packet */
324 data = inb(IE_RBUF);
325 if (data == i) break;
326 }
327 bufsize_rcv = i << 8;
328 outw(0, IE_GP); /* Point GP at start of packet */
329 outb(0, IE_RBUF); /* set buffer byte 0 to 0 again */
330 }
5b552b16 331 printk("-> bufsize rcv/xmt=%d/%d\n", bufsize_rcv, NI5010_BUFSIZE);
1da177e4 332 memset(dev->priv, 0, sizeof(struct ni5010_local));
6aa20a22 333
1da177e4
LT
334 dev->open = ni5010_open;
335 dev->stop = ni5010_close;
336 dev->hard_start_xmit = ni5010_send_packet;
337 dev->get_stats = ni5010_get_stats;
338 dev->set_multicast_list = ni5010_set_multicast_list;
339 dev->tx_timeout = ni5010_timeout;
340 dev->watchdog_timeo = HZ/20;
341
342 dev->flags &= ~IFF_MULTICAST; /* Multicast doesn't work */
343
344 /* Shut up the ni5010 */
345 outb(0, EDLC_RMASK); /* Mask all receive interrupts */
346 outb(0, EDLC_XMASK); /* Mask all xmit interrupts */
347 outb(0xff, EDLC_RCLR); /* Kill all pending rcv interrupts */
348 outb(0xff, EDLC_XCLR); /* Kill all pending xmt interrupts */
349
350 printk(KERN_INFO "%s: NI5010 found at 0x%x, using IRQ %d", dev->name, ioaddr, dev->irq);
5b552b16
AM
351 if (dev->dma)
352 printk(" & DMA %d", dev->dma);
1da177e4 353 printk(".\n");
1da177e4
LT
354 return 0;
355out:
356 release_region(dev->base_addr, NI5010_IO_EXTENT);
357 return err;
358}
359
6aa20a22 360/*
1da177e4
LT
361 * Open/initialize the board. This is called (in the current kernel)
362 * sometime after booting when the 'ifconfig' program is run.
363 *
364 * This routine should set everything up anew at each open, even
365 * registers that "should" only need to be set once at boot, so that
5b552b16 366 * there is a non-reboot way to recover if something goes wrong.
1da177e4 367 */
6aa20a22 368
1da177e4
LT
369static int ni5010_open(struct net_device *dev)
370{
371 int ioaddr = dev->base_addr;
372 int i;
373
6aa20a22
JG
374 PRINTK2((KERN_DEBUG "%s: entering ni5010_open()\n", dev->name));
375
1da177e4
LT
376 if (request_irq(dev->irq, &ni5010_interrupt, 0, boardname, dev)) {
377 printk(KERN_WARNING "%s: Cannot get irq %#2x\n", dev->name, dev->irq);
378 return -EAGAIN;
379 }
380 PRINTK3((KERN_DEBUG "%s: passed open() #1\n", dev->name));
381 /*
382 * Always allocate the DMA channel after the IRQ,
383 * and clean up on failure.
384 */
5b552b16 385#ifdef JUMPERED_DMA
1da177e4
LT
386 if (request_dma(dev->dma, cardname)) {
387 printk(KERN_WARNING "%s: Cannot get dma %#2x\n", dev->name, dev->dma);
388 free_irq(dev->irq, NULL);
389 return -EAGAIN;
390 }
5b552b16 391#endif /* JUMPERED_DMA */
1da177e4
LT
392
393 PRINTK3((KERN_DEBUG "%s: passed open() #2\n", dev->name));
394 /* Reset the hardware here. Don't forget to set the station address. */
395
396 outb(RS_RESET, EDLC_RESET); /* Hold up EDLC_RESET while configing board */
397 outb(0, IE_RESET); /* Hardware reset of ni5010 board */
398 outb(XMD_LBC, EDLC_XMODE); /* Only loopback xmits */
399
400 PRINTK3((KERN_DEBUG "%s: passed open() #3\n", dev->name));
401 /* Set the station address */
402 for(i = 0;i < 6; i++) {
403 outb(dev->dev_addr[i], EDLC_ADDR + i);
404 }
6aa20a22
JG
405
406 PRINTK3((KERN_DEBUG "%s: Initialising ni5010\n", dev->name));
1da177e4 407 outb(0, EDLC_XMASK); /* No xmit interrupts for now */
6aa20a22 408 outb(XMD_IG_PAR | XMD_T_MODE | XMD_LBC, EDLC_XMODE);
1da177e4
LT
409 /* Normal packet xmit mode */
410 outb(0xff, EDLC_XCLR); /* Clear all pending xmit interrupts */
411 outb(RMD_BROADCAST, EDLC_RMODE);
412 /* Receive broadcast and normal packets */
413 reset_receiver(dev); /* Ready ni5010 for receiving packets */
6aa20a22 414
1da177e4 415 outb(0, EDLC_RESET); /* Un-reset the ni5010 */
6aa20a22 416
1da177e4 417 netif_start_queue(dev);
6aa20a22
JG
418
419 if (NI5010_DEBUG) ni5010_show_registers(dev);
1da177e4
LT
420
421 PRINTK((KERN_DEBUG "%s: open successful\n", dev->name));
422 return 0;
423}
424
425static void reset_receiver(struct net_device *dev)
426{
427 int ioaddr = dev->base_addr;
6aa20a22 428
1da177e4
LT
429 PRINTK3((KERN_DEBUG "%s: resetting receiver\n", dev->name));
430 outw(0, IE_GP); /* Receive packet at start of buffer */
431 outb(0xff, EDLC_RCLR); /* Clear all pending rcv interrupts */
432 outb(0, IE_MMODE); /* Put EDLC to rcv buffer */
433 outb(MM_EN_RCV, IE_MMODE); /* Enable rcv */
434 outb(0xff, EDLC_RMASK); /* Enable all rcv interrupts */
435}
436
437static void ni5010_timeout(struct net_device *dev)
438{
439 printk(KERN_WARNING "%s: transmit timed out, %s?\n", dev->name,
440 tx_done(dev) ? "IRQ conflict" : "network cable problem");
441 /* Try to restart the adaptor. */
442 /* FIXME: Give it a real kick here */
443 chipset_init(dev, 1);
444 dev->trans_start = jiffies;
445 netif_wake_queue(dev);
446}
447
448static int ni5010_send_packet(struct sk_buff *skb, struct net_device *dev)
449{
450 int length = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
451
452 PRINTK2((KERN_DEBUG "%s: entering ni5010_send_packet\n", dev->name));
453
6aa20a22 454 /*
1da177e4
LT
455 * Block sending
456 */
6aa20a22 457
1da177e4
LT
458 netif_stop_queue(dev);
459 hardware_send_packet(dev, (unsigned char *)skb->data, skb->len, length-skb->len);
460 dev->trans_start = jiffies;
461 dev_kfree_skb (skb);
462 return 0;
463}
464
6aa20a22 465/*
1da177e4 466 * The typical workload of the driver:
6aa20a22 467 * Handle the network interface interrupts.
1da177e4 468 */
7d12e780 469static irqreturn_t ni5010_interrupt(int irq, void *dev_id)
1da177e4
LT
470{
471 struct net_device *dev = dev_id;
472 struct ni5010_local *lp;
473 int ioaddr, status;
474 int xmit_was_error = 0;
475
476 PRINTK2((KERN_DEBUG "%s: entering ni5010_interrupt\n", dev->name));
477
478 ioaddr = dev->base_addr;
479 lp = netdev_priv(dev);
6aa20a22 480
1da177e4 481 spin_lock(&lp->lock);
6aa20a22 482 status = inb(IE_ISTAT);
1da177e4 483 PRINTK3((KERN_DEBUG "%s: IE_ISTAT = %#02x\n", dev->name, status));
6aa20a22 484
1da177e4
LT
485 if ((status & IS_R_INT) == 0) ni5010_rx(dev);
486
487 if ((status & IS_X_INT) == 0) {
488 xmit_was_error = process_xmt_interrupt(dev);
489 }
490
491 if ((status & IS_DMA_INT) == 0) {
492 PRINTK((KERN_DEBUG "%s: DMA complete (?)\n", dev->name));
493 outb(0, IE_DMA_RST); /* Reset DMA int */
494 }
495
6aa20a22
JG
496 if (!xmit_was_error)
497 reset_receiver(dev);
1da177e4
LT
498 spin_unlock(&lp->lock);
499 return IRQ_HANDLED;
500}
501
502
503static void dump_packet(void *buf, int len)
504{
505 int i;
6aa20a22 506
1da177e4
LT
507 printk(KERN_DEBUG "Packet length = %#4x\n", len);
508 for (i = 0; i < len; i++){
509 if (i % 16 == 0) printk(KERN_DEBUG "%#4.4x", i);
510 if (i % 2 == 0) printk(" ");
511 printk("%2.2x", ((unsigned char *)buf)[i]);
512 if (i % 16 == 15) printk("\n");
513 }
514 printk("\n");
6aa20a22 515
1da177e4
LT
516 return;
517}
518
519/* We have a good packet, get it out of the buffer. */
520static void ni5010_rx(struct net_device *dev)
521{
522 struct ni5010_local *lp = netdev_priv(dev);
523 int ioaddr = dev->base_addr;
524 unsigned char rcv_stat;
525 struct sk_buff *skb;
526 int i_pkt_size;
6aa20a22
JG
527
528 PRINTK2((KERN_DEBUG "%s: entering ni5010_rx()\n", dev->name));
529
1da177e4 530 rcv_stat = inb(EDLC_RSTAT);
6aa20a22
JG
531 PRINTK3((KERN_DEBUG "%s: EDLC_RSTAT = %#2x\n", dev->name, rcv_stat));
532
1da177e4
LT
533 if ( (rcv_stat & RS_VALID_BITS) != RS_PKT_OK) {
534 PRINTK((KERN_INFO "%s: receive error.\n", dev->name));
535 lp->stats.rx_errors++;
536 if (rcv_stat & RS_RUNT) lp->stats.rx_length_errors++;
537 if (rcv_stat & RS_ALIGN) lp->stats.rx_frame_errors++;
538 if (rcv_stat & RS_CRC_ERR) lp->stats.rx_crc_errors++;
539 if (rcv_stat & RS_OFLW) lp->stats.rx_fifo_errors++;
540 outb(0xff, EDLC_RCLR); /* Clear the interrupt */
541 return;
542 }
6aa20a22 543
1da177e4
LT
544 outb(0xff, EDLC_RCLR); /* Clear the interrupt */
545
546 i_pkt_size = inw(IE_RCNT);
547 if (i_pkt_size > ETH_FRAME_LEN || i_pkt_size < 10 ) {
6aa20a22 548 PRINTK((KERN_DEBUG "%s: Packet size error, packet size = %#4.4x\n",
1da177e4
LT
549 dev->name, i_pkt_size));
550 lp->stats.rx_errors++;
551 lp->stats.rx_length_errors++;
552 return;
553 }
554
555 /* Malloc up new buffer. */
556 skb = dev_alloc_skb(i_pkt_size + 3);
557 if (skb == NULL) {
558 printk(KERN_WARNING "%s: Memory squeeze, dropping packet.\n", dev->name);
559 lp->stats.rx_dropped++;
560 return;
561 }
6aa20a22 562
1da177e4 563 skb_reserve(skb, 2);
6aa20a22 564
1da177e4
LT
565 /* Read packet into buffer */
566 outb(MM_MUX, IE_MMODE); /* Rcv buffer to system bus */
567 outw(0, IE_GP); /* Seek to beginning of packet */
6aa20a22
JG
568 insb(IE_RBUF, skb_put(skb, i_pkt_size), i_pkt_size);
569
570 if (NI5010_DEBUG >= 4)
571 dump_packet(skb->data, skb->len);
572
1da177e4
LT
573 skb->protocol = eth_type_trans(skb,dev);
574 netif_rx(skb);
575 dev->last_rx = jiffies;
576 lp->stats.rx_packets++;
577 lp->stats.rx_bytes += i_pkt_size;
578
6aa20a22 579 PRINTK2((KERN_DEBUG "%s: Received packet, size=%#4.4x\n",
1da177e4 580 dev->name, i_pkt_size));
6aa20a22 581
1da177e4
LT
582}
583
584static int process_xmt_interrupt(struct net_device *dev)
585{
586 struct ni5010_local *lp = netdev_priv(dev);
587 int ioaddr = dev->base_addr;
588 int xmit_stat;
589
590 PRINTK2((KERN_DEBUG "%s: entering process_xmt_interrupt\n", dev->name));
591
592 xmit_stat = inb(EDLC_XSTAT);
593 PRINTK3((KERN_DEBUG "%s: EDLC_XSTAT = %2.2x\n", dev->name, xmit_stat));
6aa20a22 594
1da177e4
LT
595 outb(0, EDLC_XMASK); /* Disable xmit IRQ's */
596 outb(0xff, EDLC_XCLR); /* Clear all pending xmit IRQ's */
6aa20a22 597
1da177e4 598 if (xmit_stat & XS_COLL){
6aa20a22 599 PRINTK((KERN_DEBUG "%s: collision detected, retransmitting\n",
1da177e4
LT
600 dev->name));
601 outw(NI5010_BUFSIZE - lp->o_pkt_size, IE_GP);
602 /* outb(0, IE_MMODE); */ /* xmt buf on sysbus FIXME: needed ? */
603 outb(MM_EN_XMT | MM_MUX, IE_MMODE);
604 outb(XM_ALL, EDLC_XMASK); /* Enable xmt IRQ's */
605 lp->stats.collisions++;
606 return 1;
607 }
608
609 /* FIXME: handle other xmt error conditions */
610
611 lp->stats.tx_packets++;
612 lp->stats.tx_bytes += lp->o_pkt_size;
613 netif_wake_queue(dev);
6aa20a22
JG
614
615 PRINTK2((KERN_DEBUG "%s: sent packet, size=%#4.4x\n",
1da177e4
LT
616 dev->name, lp->o_pkt_size));
617
618 return 0;
619}
620
621/* The inverse routine to ni5010_open(). */
622static int ni5010_close(struct net_device *dev)
623{
624 int ioaddr = dev->base_addr;
625
626 PRINTK2((KERN_DEBUG "%s: entering ni5010_close\n", dev->name));
5b552b16 627#ifdef JUMPERED_INTERRUPTS
1da177e4
LT
628 free_irq(dev->irq, NULL);
629#endif
630 /* Put card in held-RESET state */
631 outb(0, IE_MMODE);
632 outb(RS_RESET, EDLC_RESET);
633
634 netif_stop_queue(dev);
6aa20a22 635
1da177e4
LT
636 PRINTK((KERN_DEBUG "%s: %s closed down\n", dev->name, boardname));
637 return 0;
638
639}
640
641/* Get the current statistics. This may be called with the card open or
642 closed. */
643static struct net_device_stats *ni5010_get_stats(struct net_device *dev)
644{
645 struct ni5010_local *lp = netdev_priv(dev);
646
647 PRINTK2((KERN_DEBUG "%s: entering ni5010_get_stats\n", dev->name));
6aa20a22 648
1da177e4 649 if (NI5010_DEBUG) ni5010_show_registers(dev);
6aa20a22 650
1da177e4
LT
651 /* cli(); */
652 /* Update the statistics from the device registers. */
653 /* We do this in the interrupt handler */
654 /* sti(); */
655
656 return &lp->stats;
657}
658
659/* Set or clear the multicast filter for this adaptor.
660 num_addrs == -1 Promiscuous mode, receive all packets
661 num_addrs == 0 Normal mode, clear multicast list
662 num_addrs > 0 Multicast mode, receive normal and MC packets, and do
663 best-effort filtering.
664*/
665static void ni5010_set_multicast_list(struct net_device *dev)
666{
6aa20a22 667 short ioaddr = dev->base_addr;
1da177e4
LT
668
669 PRINTK2((KERN_DEBUG "%s: entering set_multicast_list\n", dev->name));
670
b947dd4b 671 if (dev->flags&IFF_PROMISC || dev->flags&IFF_ALLMULTI || dev->mc_list) {
1da177e4
LT
672 dev->flags |= IFF_PROMISC;
673 outb(RMD_PROMISC, EDLC_RMODE); /* Enable promiscuous mode */
674 PRINTK((KERN_DEBUG "%s: Entering promiscuous mode\n", dev->name));
1da177e4
LT
675 } else {
676 PRINTK((KERN_DEBUG "%s: Entering broadcast mode\n", dev->name));
677 outb(RMD_BROADCAST, EDLC_RMODE); /* Disable promiscuous mode, use normal mode */
678 }
679}
680
681static void hardware_send_packet(struct net_device *dev, char *buf, int length, int pad)
682{
683 struct ni5010_local *lp = netdev_priv(dev);
684 int ioaddr = dev->base_addr;
685 unsigned long flags;
686 unsigned int buf_offs;
687
688 PRINTK2((KERN_DEBUG "%s: entering hardware_send_packet\n", dev->name));
6aa20a22 689
1da177e4
LT
690 if (length > ETH_FRAME_LEN) {
691 PRINTK((KERN_WARNING "%s: packet too large, not possible\n",
692 dev->name));
693 return;
694 }
695
696 if (NI5010_DEBUG) ni5010_show_registers(dev);
697
698 if (inb(IE_ISTAT) & IS_EN_XMT) {
6aa20a22 699 PRINTK((KERN_WARNING "%s: sending packet while already transmitting, not possible\n",
1da177e4
LT
700 dev->name));
701 return;
702 }
6aa20a22 703
1da177e4
LT
704 if (NI5010_DEBUG > 3) dump_packet(buf, length);
705
706 buf_offs = NI5010_BUFSIZE - length - pad;
707
708 spin_lock_irqsave(&lp->lock, flags);
709 lp->o_pkt_size = length + pad;
710
711 outb(0, EDLC_RMASK); /* Mask all receive interrupts */
712 outb(0, IE_MMODE); /* Put Xmit buffer on system bus */
713 outb(0xff, EDLC_RCLR); /* Clear out pending rcv interrupts */
714
715 outw(buf_offs, IE_GP); /* Point GP at start of packet */
716 outsb(IE_XBUF, buf, length); /* Put data in buffer */
717 while(pad--)
718 outb(0, IE_XBUF);
6aa20a22 719
1da177e4
LT
720 outw(buf_offs, IE_GP); /* Rewrite where packet starts */
721
722 /* should work without that outb() (Crynwr used it) */
723 /*outb(MM_MUX, IE_MMODE);*/ /* Xmt buffer to EDLC bus */
724 outb(MM_EN_XMT | MM_MUX, IE_MMODE); /* Begin transmission */
725 outb(XM_ALL, EDLC_XMASK); /* Cause interrupt after completion or fail */
726
727 spin_unlock_irqrestore(&lp->lock, flags);
728
729 netif_wake_queue(dev);
6aa20a22
JG
730
731 if (NI5010_DEBUG) ni5010_show_registers(dev);
1da177e4
LT
732}
733
734static void chipset_init(struct net_device *dev, int startp)
735{
736 /* FIXME: Move some stuff here */
737 PRINTK3((KERN_DEBUG "%s: doing NOTHING in chipset_init\n", dev->name));
738}
739
740static void ni5010_show_registers(struct net_device *dev)
741{
742 int ioaddr = dev->base_addr;
6aa20a22 743
1da177e4
LT
744 PRINTK3((KERN_DEBUG "%s: XSTAT %#2.2x\n", dev->name, inb(EDLC_XSTAT)));
745 PRINTK3((KERN_DEBUG "%s: XMASK %#2.2x\n", dev->name, inb(EDLC_XMASK)));
746 PRINTK3((KERN_DEBUG "%s: RSTAT %#2.2x\n", dev->name, inb(EDLC_RSTAT)));
747 PRINTK3((KERN_DEBUG "%s: RMASK %#2.2x\n", dev->name, inb(EDLC_RMASK)));
748 PRINTK3((KERN_DEBUG "%s: RMODE %#2.2x\n", dev->name, inb(EDLC_RMODE)));
749 PRINTK3((KERN_DEBUG "%s: XMODE %#2.2x\n", dev->name, inb(EDLC_XMODE)));
750 PRINTK3((KERN_DEBUG "%s: ISTAT %#2.2x\n", dev->name, inb(IE_ISTAT)));
751}
752
753#ifdef MODULE
754static struct net_device *dev_ni5010;
755
8d3b33f6
RR
756module_param(io, int, 0);
757module_param(irq, int, 0);
1da177e4
LT
758MODULE_PARM_DESC(io, "ni5010 I/O base address");
759MODULE_PARM_DESC(irq, "ni5010 IRQ number");
760
5b552b16 761static int __init ni5010_init_module(void)
1da177e4
LT
762{
763 PRINTK2((KERN_DEBUG "%s: entering init_module\n", boardname));
764 /*
765 if(io <= 0 || irq == 0){
766 printk(KERN_WARNING "%s: Autoprobing not allowed for modules.\n", boardname);
767 printk(KERN_WARNING "%s: Set symbols 'io' and 'irq'\n", boardname);
768 return -EINVAL;
769 }
770 */
771 if (io <= 0){
772 printk(KERN_WARNING "%s: Autoprobing for modules is hazardous, trying anyway..\n", boardname);
773 }
774
775 PRINTK2((KERN_DEBUG "%s: init_module irq=%#2x, io=%#3x\n", boardname, irq, io));
776 dev_ni5010 = ni5010_probe(-1);
777 if (IS_ERR(dev_ni5010))
778 return PTR_ERR(dev_ni5010);
779 return 0;
780}
781
5b552b16 782static void __exit ni5010_cleanup_module(void)
1da177e4
LT
783{
784 PRINTK2((KERN_DEBUG "%s: entering cleanup_module\n", boardname));
785 unregister_netdev(dev_ni5010);
786 release_region(dev_ni5010->base_addr, NI5010_IO_EXTENT);
787 free_netdev(dev_ni5010);
788}
5b552b16
AM
789module_init(ni5010_init_module);
790module_exit(ni5010_cleanup_module);
1da177e4
LT
791#endif /* MODULE */
792MODULE_LICENSE("GPL");
793
794/*
795 * Local variables:
796 * compile-command: "gcc -D__KERNEL__ -I/usr/src/linux/net/inet -Wall -Wstrict-prototypes -O6 -m486 -c ni5010.c"
797 * version-control: t
798 * kept-new-versions: 5
799 * tab-width: 4
800 * End:
801 */
This page took 0.310042 seconds and 5 git commands to generate.