drivers/net: request_irq - Remove unnecessary leading & from second arg
[deliverable/linux.git] / drivers / net / seeq8005.c
CommitLineData
1da177e4
LT
1/* seeq8005.c: A network driver for linux. */
2/*
3 Based on skeleton.c,
4 Written 1993-94 by Donald Becker.
5 See the skeleton.c file for further copyright information.
6
7 This software may be used and distributed according to the terms
8 of the GNU General Public License, incorporated herein by reference.
9
10 The author may be reached as hamish@zot.apana.org.au
11
12 This file is a network device driver for the SEEQ 8005 chipset and
13 the Linux operating system.
14
15*/
16
17static const char version[] =
18 "seeq8005.c:v1.00 8/07/95 Hamish Coleman (hamish@zot.apana.org.au)\n";
19
20/*
21 Sources:
22 SEEQ 8005 databook
6aa20a22 23
1da177e4
LT
24 Version history:
25 1.00 Public release. cosmetic changes (no warnings now)
26 0.68 Turning per- packet,interrupt debug messages off - testing for release.
27 0.67 timing problems/bad buffer reads seem to be fixed now
28 0.63 *!@$ protocol=eth_type_trans -- now packets flow
29 0.56 Send working
30 0.48 Receive working
31*/
32
33#include <linux/module.h>
34#include <linux/kernel.h>
35#include <linux/types.h>
36#include <linux/fcntl.h>
37#include <linux/interrupt.h>
38#include <linux/ioport.h>
39#include <linux/in.h>
40#include <linux/slab.h>
41#include <linux/string.h>
42#include <linux/init.h>
43#include <linux/delay.h>
44#include <linux/errno.h>
45#include <linux/netdevice.h>
46#include <linux/etherdevice.h>
47#include <linux/skbuff.h>
48#include <linux/bitops.h>
ff5688ae 49#include <linux/jiffies.h>
1da177e4
LT
50
51#include <asm/system.h>
52#include <asm/io.h>
53#include <asm/dma.h>
54
55#include "seeq8005.h"
56
57/* First, a few definitions that the brave might change. */
58/* A zero-terminated list of I/O addresses to be probed. */
59static unsigned int seeq8005_portlist[] __initdata =
60 { 0x300, 0x320, 0x340, 0x360, 0};
61
62/* use 0 for production, 1 for verification, >2 for debug */
63#ifndef NET_DEBUG
64#define NET_DEBUG 1
65#endif
66static unsigned int net_debug = NET_DEBUG;
67
68/* Information that need to be kept for each board. */
69struct net_local {
1da177e4
LT
70 unsigned short receive_ptr; /* What address in packet memory do we expect a recv_pkt_header? */
71 long open_time; /* Useless example local info. */
72};
73
74/* The station (ethernet) address prefix, used for IDing the board. */
75#define SA_ADDR0 0x00
76#define SA_ADDR1 0x80
77#define SA_ADDR2 0x4b
78
79/* Index to functions, as function prototypes. */
80
81static int seeq8005_probe1(struct net_device *dev, int ioaddr);
82static int seeq8005_open(struct net_device *dev);
83static void seeq8005_timeout(struct net_device *dev);
61357325
SH
84static netdev_tx_t seeq8005_send_packet(struct sk_buff *skb,
85 struct net_device *dev);
7d12e780 86static irqreturn_t seeq8005_interrupt(int irq, void *dev_id);
1da177e4
LT
87static void seeq8005_rx(struct net_device *dev);
88static int seeq8005_close(struct net_device *dev);
1da177e4
LT
89static void set_multicast_list(struct net_device *dev);
90
91/* Example routines you must write ;->. */
92#define tx_done(dev) (inw(SEEQ_STATUS) & SEEQSTAT_TX_ON)
93static void hardware_send_packet(struct net_device *dev, char *buf, int length);
94extern void seeq8005_init(struct net_device *dev, int startp);
95static inline void wait_for_buffer(struct net_device *dev);
96
6aa20a22 97
1da177e4
LT
98/* Check for a network adaptor of this type, and return '0' iff one exists.
99 If dev->base_addr == 0, probe all likely locations.
100 If dev->base_addr == 1, always return failure.
101 */
102
103static int io = 0x320;
104static int irq = 10;
105
106struct net_device * __init seeq8005_probe(int unit)
107{
108 struct net_device *dev = alloc_etherdev(sizeof(struct net_local));
109 unsigned *port;
110 int err = 0;
111
112 if (!dev)
113 return ERR_PTR(-ENODEV);
114
115 if (unit >= 0) {
116 sprintf(dev->name, "eth%d", unit);
117 netdev_boot_setup_check(dev);
118 io = dev->base_addr;
119 irq = dev->irq;
120 }
121
122 if (io > 0x1ff) { /* Check a single specified location. */
123 err = seeq8005_probe1(dev, io);
124 } else if (io != 0) { /* Don't probe at all. */
125 err = -ENXIO;
126 } else {
127 for (port = seeq8005_portlist; *port; port++) {
128 if (seeq8005_probe1(dev, *port) == 0)
129 break;
130 }
131 if (!*port)
132 err = -ENODEV;
133 }
134 if (err)
135 goto out;
136 err = register_netdev(dev);
137 if (err)
138 goto out1;
139 return dev;
140out1:
141 release_region(dev->base_addr, SEEQ8005_IO_EXTENT);
142out:
143 free_netdev(dev);
144 return ERR_PTR(err);
145}
146
b20417db
SH
147static const struct net_device_ops seeq8005_netdev_ops = {
148 .ndo_open = seeq8005_open,
149 .ndo_stop = seeq8005_close,
150 .ndo_start_xmit = seeq8005_send_packet,
151 .ndo_tx_timeout = seeq8005_timeout,
152 .ndo_set_multicast_list = set_multicast_list,
153 .ndo_change_mtu = eth_change_mtu,
154 .ndo_set_mac_address = eth_mac_addr,
155 .ndo_validate_addr = eth_validate_addr,
156};
157
1da177e4
LT
158/* This is the real probe routine. Linux has a history of friendly device
159 probes on the ISA bus. A good device probes avoids doing writes, and
160 verifies that the correct device exists and functions. */
161
162static int __init seeq8005_probe1(struct net_device *dev, int ioaddr)
163{
164 static unsigned version_printed;
165 int i,j;
166 unsigned char SA_prom[32];
167 int old_cfg1;
168 int old_cfg2;
169 int old_stat;
170 int old_dmaar;
171 int old_rear;
172 int retval;
173
174 if (!request_region(ioaddr, SEEQ8005_IO_EXTENT, "seeq8005"))
175 return -ENODEV;
176
177 if (net_debug>1)
178 printk("seeq8005: probing at 0x%x\n",ioaddr);
179
180 old_stat = inw(SEEQ_STATUS); /* read status register */
181 if (old_stat == 0xffff) {
182 retval = -ENODEV;
183 goto out; /* assume that 0xffff == no device */
184 }
185 if ( (old_stat & 0x1800) != 0x1800 ) { /* assume that unused bits are 1, as my manual says */
186 if (net_debug>1) {
187 printk("seeq8005: reserved stat bits != 0x1800\n");
188 printk(" == 0x%04x\n",old_stat);
189 }
190 retval = -ENODEV;
191 goto out;
192 }
193
194 old_rear = inw(SEEQ_REA);
195 if (old_rear == 0xffff) {
196 outw(0,SEEQ_REA);
197 if (inw(SEEQ_REA) == 0xffff) { /* assume that 0xffff == no device */
198 retval = -ENODEV;
199 goto out;
200 }
201 } else if ((old_rear & 0xff00) != 0xff00) { /* assume that unused bits are 1 */
202 if (net_debug>1) {
203 printk("seeq8005: unused rear bits != 0xff00\n");
204 printk(" == 0x%04x\n",old_rear);
205 }
206 retval = -ENODEV;
207 goto out;
208 }
6aa20a22 209
1da177e4
LT
210 old_cfg2 = inw(SEEQ_CFG2); /* read CFG2 register */
211 old_cfg1 = inw(SEEQ_CFG1);
212 old_dmaar = inw(SEEQ_DMAAR);
6aa20a22 213
1da177e4
LT
214 if (net_debug>4) {
215 printk("seeq8005: stat = 0x%04x\n",old_stat);
216 printk("seeq8005: cfg1 = 0x%04x\n",old_cfg1);
217 printk("seeq8005: cfg2 = 0x%04x\n",old_cfg2);
218 printk("seeq8005: raer = 0x%04x\n",old_rear);
219 printk("seeq8005: dmaar= 0x%04x\n",old_dmaar);
220 }
6aa20a22 221
1da177e4
LT
222 outw( SEEQCMD_FIFO_WRITE | SEEQCMD_SET_ALL_OFF, SEEQ_CMD); /* setup for reading PROM */
223 outw( 0, SEEQ_DMAAR); /* set starting PROM address */
224 outw( SEEQCFG1_BUFFER_PROM, SEEQ_CFG1); /* set buffer to look at PROM */
225
226
227 j=0;
228 for(i=0; i <32; i++) {
229 j+= SA_prom[i] = inw(SEEQ_BUFFER) & 0xff;
230 }
231
232#if 0
233 /* untested because I only have the one card */
234 if ( (j&0xff) != 0 ) { /* checksum appears to be 8bit = 0 */
235 if (net_debug>1) { /* check this before deciding that we have a card */
236 printk("seeq8005: prom sum error\n");
237 }
238 outw( old_stat, SEEQ_STATUS);
239 outw( old_dmaar, SEEQ_DMAAR);
240 outw( old_cfg1, SEEQ_CFG1);
241 retval = -ENODEV;
242 goto out;
243 }
244#endif
245
246 outw( SEEQCFG2_RESET, SEEQ_CFG2); /* reset the card */
247 udelay(5);
248 outw( SEEQCMD_SET_ALL_OFF, SEEQ_CMD);
6aa20a22 249
1da177e4
LT
250 if (net_debug) {
251 printk("seeq8005: prom sum = 0x%08x\n",j);
252 for(j=0; j<32; j+=16) {
253 printk("seeq8005: prom %02x: ",j);
254 for(i=0;i<16;i++) {
255 printk("%02x ",SA_prom[j|i]);
256 }
257 printk(" ");
258 for(i=0;i<16;i++) {
259 if ((SA_prom[j|i]>31)&&(SA_prom[j|i]<127)) {
260 printk("%c", SA_prom[j|i]);
261 } else {
262 printk(" ");
263 }
264 }
265 printk("\n");
266 }
267 }
268
6aa20a22
JG
269#if 0
270 /*
1da177e4 271 * testing the packet buffer memory doesn't work yet
6aa20a22 272 * but all other buffer accesses do
1da177e4
LT
273 * - fixing is not a priority
274 */
275 if (net_debug>1) { /* test packet buffer memory */
276 printk("seeq8005: testing packet buffer ... ");
277 outw( SEEQCFG1_BUFFER_BUFFER, SEEQ_CFG1);
278 outw( SEEQCMD_FIFO_WRITE | SEEQCMD_SET_ALL_OFF, SEEQ_CMD);
279 outw( 0 , SEEQ_DMAAR);
280 for(i=0;i<32768;i++) {
281 outw(0x5a5a, SEEQ_BUFFER);
282 }
283 j=jiffies+HZ;
284 while ( ((inw(SEEQ_STATUS) & SEEQSTAT_FIFO_EMPTY) != SEEQSTAT_FIFO_EMPTY) && time_before(jiffies, j) )
285 mb();
286 outw( 0 , SEEQ_DMAAR);
287 while ( ((inw(SEEQ_STATUS) & SEEQSTAT_WINDOW_INT) != SEEQSTAT_WINDOW_INT) && time_before(jiffies, j+HZ))
288 mb();
289 if ( (inw(SEEQ_STATUS) & SEEQSTAT_WINDOW_INT) == SEEQSTAT_WINDOW_INT)
290 outw( SEEQCMD_WINDOW_INT_ACK | (inw(SEEQ_STATUS)& SEEQCMD_INT_MASK), SEEQ_CMD);
291 outw( SEEQCMD_FIFO_READ | SEEQCMD_SET_ALL_OFF, SEEQ_CMD);
292 j=0;
293 for(i=0;i<32768;i++) {
294 if (inw(SEEQ_BUFFER) != 0x5a5a)
295 j++;
296 }
297 if (j) {
298 printk("%i\n",j);
299 } else {
300 printk("ok.\n");
301 }
302 }
303#endif
304
305 if (net_debug && version_printed++ == 0)
306 printk(version);
307
308 printk("%s: %s found at %#3x, ", dev->name, "seeq8005", ioaddr);
309
310 /* Fill in the 'dev' fields. */
311 dev->base_addr = ioaddr;
312 dev->irq = irq;
313
314 /* Retrieve and print the ethernet address. */
315 for (i = 0; i < 6; i++)
0795af57 316 dev->dev_addr[i] = SA_prom[i+6];
e174961c 317 printk("%pM", dev->dev_addr);
1da177e4
LT
318
319 if (dev->irq == 0xff)
320 ; /* Do nothing: a user-level program will set it. */
321 else if (dev->irq < 2) { /* "Auto-IRQ" */
322 unsigned long cookie = probe_irq_on();
6aa20a22 323
1da177e4
LT
324 outw( SEEQCMD_RX_INT_EN | SEEQCMD_SET_RX_ON | SEEQCMD_SET_RX_OFF, SEEQ_CMD );
325
326 dev->irq = probe_irq_off(cookie);
6aa20a22 327
1da177e4
LT
328 if (net_debug >= 2)
329 printk(" autoirq is %d\n", dev->irq);
330 } else if (dev->irq == 2)
331 /* Fixup for users that don't know that IRQ 2 is really IRQ 9,
6aa20a22 332 * or don't know which one to set.
1da177e4
LT
333 */
334 dev->irq = 9;
335
336#if 0
337 {
a0607fd3 338 int irqval = request_irq(dev->irq, seeq8005_interrupt, 0, "seeq8005", dev);
1da177e4
LT
339 if (irqval) {
340 printk ("%s: unable to get IRQ %d (irqval=%d).\n", dev->name,
341 dev->irq, irqval);
342 retval = -EAGAIN;
343 goto out;
344 }
345 }
346#endif
b20417db 347 dev->netdev_ops = &seeq8005_netdev_ops;
1da177e4 348 dev->watchdog_timeo = HZ/20;
1da177e4
LT
349 dev->flags &= ~IFF_MULTICAST;
350
351 return 0;
352out:
353 release_region(ioaddr, SEEQ8005_IO_EXTENT);
354 return retval;
355}
356
6aa20a22 357
1da177e4
LT
358/* Open/initialize the board. This is called (in the current kernel)
359 sometime after booting when the 'ifconfig' program is run.
360
361 This routine should set everything up anew at each open, even
362 registers that "should" only need to be set once at boot, so that
363 there is non-reboot way to recover if something goes wrong.
364 */
365static int seeq8005_open(struct net_device *dev)
366{
367 struct net_local *lp = netdev_priv(dev);
368
369 {
a0607fd3 370 int irqval = request_irq(dev->irq, seeq8005_interrupt, 0, "seeq8005", dev);
1da177e4
LT
371 if (irqval) {
372 printk ("%s: unable to get IRQ %d (irqval=%d).\n", dev->name,
373 dev->irq, irqval);
374 return -EAGAIN;
375 }
376 }
377
378 /* Reset the hardware here. Don't forget to set the station address. */
379 seeq8005_init(dev, 1);
380
381 lp->open_time = jiffies;
382
383 netif_start_queue(dev);
384 return 0;
385}
386
387static void seeq8005_timeout(struct net_device *dev)
388{
389 int ioaddr = dev->base_addr;
390 printk(KERN_WARNING "%s: transmit timed out, %s?\n", dev->name,
391 tx_done(dev) ? "IRQ conflict" : "network cable problem");
392 /* Try to restart the adaptor. */
393 seeq8005_init(dev, 1);
394 dev->trans_start = jiffies;
395 netif_wake_queue(dev);
396}
397
61357325
SH
398static netdev_tx_t seeq8005_send_packet(struct sk_buff *skb,
399 struct net_device *dev)
1da177e4 400{
1da177e4
LT
401 short length = skb->len;
402 unsigned char *buf;
403
404 if (length < ETH_ZLEN) {
5b057c6b 405 if (skb_padto(skb, ETH_ZLEN))
6ed10654 406 return NETDEV_TX_OK;
1da177e4
LT
407 length = ETH_ZLEN;
408 }
409 buf = skb->data;
410
411 /* Block a timer-based transmit from overlapping */
412 netif_stop_queue(dev);
6aa20a22
JG
413
414 hardware_send_packet(dev, buf, length);
1da177e4 415 dev->trans_start = jiffies;
09f75cd7 416 dev->stats.tx_bytes += length;
1da177e4
LT
417 dev_kfree_skb (skb);
418 /* You might need to clean up and record Tx statistics here. */
419
6ed10654 420 return NETDEV_TX_OK;
1da177e4 421}
6aa20a22 422
1da177e4
LT
423/*
424 * wait_for_buffer
425 *
426 * This routine waits for the SEEQ chip to assert that the FIFO is ready
427 * by checking for a window interrupt, and then clearing it. This has to
428 * occur in the interrupt handler!
429 */
430inline void wait_for_buffer(struct net_device * dev)
431{
432 int ioaddr = dev->base_addr;
433 unsigned long tmp;
434 int status;
6aa20a22 435
1da177e4
LT
436 tmp = jiffies + HZ;
437 while ( ( ((status=inw(SEEQ_STATUS)) & SEEQSTAT_WINDOW_INT) != SEEQSTAT_WINDOW_INT) && time_before(jiffies, tmp))
438 cpu_relax();
6aa20a22 439
1da177e4
LT
440 if ( (status & SEEQSTAT_WINDOW_INT) == SEEQSTAT_WINDOW_INT)
441 outw( SEEQCMD_WINDOW_INT_ACK | (status & SEEQCMD_INT_MASK), SEEQ_CMD);
442}
6aa20a22 443
1da177e4
LT
444/* The typical workload of the driver:
445 Handle the network interface interrupts. */
7d12e780 446static irqreturn_t seeq8005_interrupt(int irq, void *dev_id)
1da177e4
LT
447{
448 struct net_device *dev = dev_id;
449 struct net_local *lp;
450 int ioaddr, status, boguscount = 0;
451 int handled = 0;
452
453 ioaddr = dev->base_addr;
454 lp = netdev_priv(dev);
455
456 status = inw(SEEQ_STATUS);
457 do {
458 if (net_debug >2) {
459 printk("%s: int, status=0x%04x\n",dev->name,status);
460 }
6aa20a22 461
1da177e4
LT
462 if (status & SEEQSTAT_WINDOW_INT) {
463 handled = 1;
464 outw( SEEQCMD_WINDOW_INT_ACK | (status & SEEQCMD_INT_MASK), SEEQ_CMD);
465 if (net_debug) {
466 printk("%s: window int!\n",dev->name);
467 }
468 }
469 if (status & SEEQSTAT_TX_INT) {
470 handled = 1;
471 outw( SEEQCMD_TX_INT_ACK | (status & SEEQCMD_INT_MASK), SEEQ_CMD);
09f75cd7 472 dev->stats.tx_packets++;
1da177e4
LT
473 netif_wake_queue(dev); /* Inform upper layers. */
474 }
475 if (status & SEEQSTAT_RX_INT) {
476 handled = 1;
477 /* Got a packet(s). */
478 seeq8005_rx(dev);
479 }
480 status = inw(SEEQ_STATUS);
481 } while ( (++boguscount < 10) && (status & SEEQSTAT_ANY_INT)) ;
482
483 if(net_debug>2) {
484 printk("%s: eoi\n",dev->name);
485 }
486 return IRQ_RETVAL(handled);
487}
488
489/* We have a good packet(s), get it/them out of the buffers. */
490static void seeq8005_rx(struct net_device *dev)
491{
492 struct net_local *lp = netdev_priv(dev);
493 int boguscount = 10;
494 int pkt_hdr;
495 int ioaddr = dev->base_addr;
496
497 do {
498 int next_packet;
499 int pkt_len;
500 int i;
501 int status;
502
503 status = inw(SEEQ_STATUS);
504 outw( lp->receive_ptr, SEEQ_DMAAR);
505 outw(SEEQCMD_FIFO_READ | SEEQCMD_RX_INT_ACK | (status & SEEQCMD_INT_MASK), SEEQ_CMD);
506 wait_for_buffer(dev);
507 next_packet = ntohs(inw(SEEQ_BUFFER));
508 pkt_hdr = inw(SEEQ_BUFFER);
6aa20a22 509
1da177e4
LT
510 if (net_debug>2) {
511 printk("%s: 0x%04x recv next=0x%04x, hdr=0x%04x\n",dev->name,lp->receive_ptr,next_packet,pkt_hdr);
512 }
6aa20a22 513
1da177e4
LT
514 if ((next_packet == 0) || ((pkt_hdr & SEEQPKTH_CHAIN)==0)) { /* Read all the frames? */
515 return; /* Done for now */
516 }
6aa20a22 517
1da177e4
LT
518 if ((pkt_hdr & SEEQPKTS_DONE)==0)
519 break;
6aa20a22 520
1da177e4
LT
521 if (next_packet < lp->receive_ptr) {
522 pkt_len = (next_packet + 0x10000 - ((DEFAULT_TEA+1)<<8)) - lp->receive_ptr - 4;
523 } else {
524 pkt_len = next_packet - lp->receive_ptr - 4;
525 }
6aa20a22 526
1da177e4
LT
527 if (next_packet < ((DEFAULT_TEA+1)<<8)) { /* is the next_packet address sane? */
528 printk("%s: recv packet ring corrupt, resetting board\n",dev->name);
529 seeq8005_init(dev,1);
530 return;
531 }
6aa20a22 532
1da177e4 533 lp->receive_ptr = next_packet;
6aa20a22 534
1da177e4
LT
535 if (net_debug>2) {
536 printk("%s: recv len=0x%04x\n",dev->name,pkt_len);
537 }
538
539 if (pkt_hdr & SEEQPKTS_ANY_ERROR) { /* There was an error. */
09f75cd7
JG
540 dev->stats.rx_errors++;
541 if (pkt_hdr & SEEQPKTS_SHORT) dev->stats.rx_frame_errors++;
542 if (pkt_hdr & SEEQPKTS_DRIB) dev->stats.rx_frame_errors++;
543 if (pkt_hdr & SEEQPKTS_OVERSIZE) dev->stats.rx_over_errors++;
544 if (pkt_hdr & SEEQPKTS_CRC_ERR) dev->stats.rx_crc_errors++;
1da177e4
LT
545 /* skip over this packet */
546 outw( SEEQCMD_FIFO_WRITE | SEEQCMD_DMA_INT_ACK | (status & SEEQCMD_INT_MASK), SEEQ_CMD);
547 outw( (lp->receive_ptr & 0xff00)>>8, SEEQ_REA);
548 } else {
549 /* Malloc up new buffer. */
550 struct sk_buff *skb;
551 unsigned char *buf;
552
553 skb = dev_alloc_skb(pkt_len);
554 if (skb == NULL) {
555 printk("%s: Memory squeeze, dropping packet.\n", dev->name);
09f75cd7 556 dev->stats.rx_dropped++;
1da177e4
LT
557 break;
558 }
1da177e4
LT
559 skb_reserve(skb, 2); /* align data on 16 byte */
560 buf = skb_put(skb,pkt_len);
6aa20a22 561
1da177e4 562 insw(SEEQ_BUFFER, buf, (pkt_len + 1) >> 1);
6aa20a22 563
1da177e4
LT
564 if (net_debug>2) {
565 char * p = buf;
566 printk("%s: recv ",dev->name);
567 for(i=0;i<14;i++) {
568 printk("%02x ",*(p++)&0xff);
569 }
570 printk("\n");
571 }
572
573 skb->protocol=eth_type_trans(skb,dev);
574 netif_rx(skb);
09f75cd7
JG
575 dev->stats.rx_packets++;
576 dev->stats.rx_bytes += pkt_len;
1da177e4
LT
577 }
578 } while ((--boguscount) && (pkt_hdr & SEEQPKTH_CHAIN));
579
580 /* If any worth-while packets have been received, netif_rx()
581 has done a mark_bh(NET_BH) for us and will work on them
582 when we get to the bottom-half routine. */
583 return;
584}
585
586/* The inverse routine to net_open(). */
587static int seeq8005_close(struct net_device *dev)
588{
589 struct net_local *lp = netdev_priv(dev);
590 int ioaddr = dev->base_addr;
591
592 lp->open_time = 0;
593
594 netif_stop_queue(dev);
6aa20a22 595
1da177e4
LT
596 /* Flush the Tx and disable Rx here. */
597 outw( SEEQCMD_SET_ALL_OFF, SEEQ_CMD);
598
599 free_irq(dev->irq, dev);
600
601 /* Update the statistics here. */
602
603 return 0;
604
605}
606
1da177e4
LT
607/* Set or clear the multicast filter for this adaptor.
608 num_addrs == -1 Promiscuous mode, receive all packets
609 num_addrs == 0 Normal mode, clear multicast list
610 num_addrs > 0 Multicast mode, receive normal and MC packets, and do
611 best-effort filtering.
612 */
613static void set_multicast_list(struct net_device *dev)
614{
615/*
616 * I _could_ do up to 6 addresses here, but won't (yet?)
617 */
618
619#if 0
620 int ioaddr = dev->base_addr;
621/*
622 * hmm, not even sure if my matching works _anyway_ - seem to be receiving
623 * _everything_ . . .
624 */
6aa20a22 625
1da177e4
LT
626 if (num_addrs) { /* Enable promiscuous mode */
627 outw( (inw(SEEQ_CFG1) & ~SEEQCFG1_MATCH_MASK)| SEEQCFG1_MATCH_ALL, SEEQ_CFG1);
628 dev->flags|=IFF_PROMISC;
629 } else { /* Disable promiscuous mode, use normal mode */
630 outw( (inw(SEEQ_CFG1) & ~SEEQCFG1_MATCH_MASK)| SEEQCFG1_MATCH_BROAD, SEEQ_CFG1);
631 }
632#endif
633}
634
635void seeq8005_init(struct net_device *dev, int startp)
636{
637 struct net_local *lp = netdev_priv(dev);
638 int ioaddr = dev->base_addr;
639 int i;
6aa20a22 640
1da177e4
LT
641 outw(SEEQCFG2_RESET, SEEQ_CFG2); /* reset device */
642 udelay(5);
6aa20a22 643
1da177e4
LT
644 outw( SEEQCMD_FIFO_WRITE | SEEQCMD_SET_ALL_OFF, SEEQ_CMD);
645 outw( 0, SEEQ_DMAAR); /* load start address into both low and high byte */
646/* wait_for_buffer(dev); */ /* I think that you only need a wait for memory buffer */
647 outw( SEEQCFG1_BUFFER_MAC0, SEEQ_CFG1);
6aa20a22 648
1da177e4
LT
649 for(i=0;i<6;i++) { /* set Station address */
650 outb(dev->dev_addr[i], SEEQ_BUFFER);
651 udelay(2);
652 }
6aa20a22 653
1da177e4
LT
654 outw( SEEQCFG1_BUFFER_TEA, SEEQ_CFG1); /* set xmit end area pointer to 16K */
655 outb( DEFAULT_TEA, SEEQ_BUFFER); /* this gives us 16K of send buffer and 48K of recv buffer */
6aa20a22 656
1da177e4
LT
657 lp->receive_ptr = (DEFAULT_TEA+1)<<8; /* so we can find our packet_header */
658 outw( lp->receive_ptr, SEEQ_RPR); /* Receive Pointer Register is set to recv buffer memory */
6aa20a22 659
1da177e4
LT
660 outw( 0x00ff, SEEQ_REA); /* Receive Area End */
661
662 if (net_debug>4) {
663 printk("%s: SA0 = ",dev->name);
664
665 outw( SEEQCMD_FIFO_READ | SEEQCMD_SET_ALL_OFF, SEEQ_CMD);
666 outw( 0, SEEQ_DMAAR);
667 outw( SEEQCFG1_BUFFER_MAC0, SEEQ_CFG1);
6aa20a22 668
1da177e4
LT
669 for(i=0;i<6;i++) {
670 printk("%02x ",inb(SEEQ_BUFFER));
671 }
672 printk("\n");
673 }
6aa20a22 674
1da177e4
LT
675 outw( SEEQCFG1_MAC0_EN | SEEQCFG1_MATCH_BROAD | SEEQCFG1_BUFFER_BUFFER, SEEQ_CFG1);
676 outw( SEEQCFG2_AUTO_REA | SEEQCFG2_CTRLO, SEEQ_CFG2);
677 outw( SEEQCMD_SET_RX_ON | SEEQCMD_TX_INT_EN | SEEQCMD_RX_INT_EN, SEEQ_CMD);
678
679 if (net_debug>4) {
680 int old_cfg1;
681 old_cfg1 = inw(SEEQ_CFG1);
682 printk("%s: stat = 0x%04x\n",dev->name,inw(SEEQ_STATUS));
683 printk("%s: cfg1 = 0x%04x\n",dev->name,old_cfg1);
684 printk("%s: cfg2 = 0x%04x\n",dev->name,inw(SEEQ_CFG2));
685 printk("%s: raer = 0x%04x\n",dev->name,inw(SEEQ_REA));
686 printk("%s: dmaar= 0x%04x\n",dev->name,inw(SEEQ_DMAAR));
6aa20a22 687
1da177e4 688 }
6aa20a22 689}
1da177e4
LT
690
691
692static void hardware_send_packet(struct net_device * dev, char *buf, int length)
693{
694 int ioaddr = dev->base_addr;
695 int status = inw(SEEQ_STATUS);
696 int transmit_ptr = 0;
ff5688ae 697 unsigned long tmp;
1da177e4
LT
698
699 if (net_debug>4) {
700 printk("%s: send 0x%04x\n",dev->name,length);
701 }
6aa20a22 702
1da177e4
LT
703 /* Set FIFO to writemode and set packet-buffer address */
704 outw( SEEQCMD_FIFO_WRITE | (status & SEEQCMD_INT_MASK), SEEQ_CMD);
705 outw( transmit_ptr, SEEQ_DMAAR);
6aa20a22 706
1da177e4
LT
707 /* output SEEQ Packet header barfage */
708 outw( htons(length + 4), SEEQ_BUFFER);
709 outw( SEEQPKTH_XMIT | SEEQPKTH_DATA_FOLLOWS | SEEQPKTH_XMIT_INT_EN, SEEQ_BUFFER );
6aa20a22 710
1da177e4
LT
711 /* blat the buffer */
712 outsw( SEEQ_BUFFER, buf, (length +1) >> 1);
713 /* paranoia !! */
714 outw( 0, SEEQ_BUFFER);
715 outw( 0, SEEQ_BUFFER);
6aa20a22 716
1da177e4
LT
717 /* set address of start of transmit chain */
718 outw( transmit_ptr, SEEQ_TPR);
6aa20a22 719
1da177e4
LT
720 /* drain FIFO */
721 tmp = jiffies;
ff5688ae 722 while ( (((status=inw(SEEQ_STATUS)) & SEEQSTAT_FIFO_EMPTY) == 0) && time_before(jiffies, tmp + HZ))
1da177e4 723 mb();
6aa20a22 724
1da177e4
LT
725 /* doit ! */
726 outw( SEEQCMD_WINDOW_INT_ACK | SEEQCMD_SET_TX_ON | (status & SEEQCMD_INT_MASK), SEEQ_CMD);
6aa20a22 727
1da177e4
LT
728}
729
730
731#ifdef MODULE
732
733static struct net_device *dev_seeq;
734MODULE_LICENSE("GPL");
735module_param(io, int, 0);
736module_param(irq, int, 0);
737MODULE_PARM_DESC(io, "SEEQ 8005 I/O base address");
738MODULE_PARM_DESC(irq, "SEEQ 8005 IRQ number");
739
c971ef46 740int __init init_module(void)
1da177e4
LT
741{
742 dev_seeq = seeq8005_probe(-1);
743 if (IS_ERR(dev_seeq))
744 return PTR_ERR(dev_seeq);
745 return 0;
746}
747
afc8eb46 748void __exit cleanup_module(void)
1da177e4
LT
749{
750 unregister_netdev(dev_seeq);
751 release_region(dev_seeq->base_addr, SEEQ8005_IO_EXTENT);
752 free_netdev(dev_seeq);
753}
754
755#endif /* MODULE */
This page took 0.578452 seconds and 5 git commands to generate.