* better
[mascara-docs.git] / i386 / linux-2.3.21 / drivers / net / wan / sbni.c
blob9d5fba082016e1a61c5512949ff4d55f50687f7f
1 /*
2 * Driver for Granch SBNI-12 leased line network adapters.
3 *
4 * Copyright 1997 - 1999, Granch ltd.
5 * Written 1999 by Yaroslav Polyakov (xenon@granch.ru).
7 * This software may be used and distributed according to the terms
8 * of the GNU Public License, incorporated herein by reference.
9 *
10 * // Whole developers team:
11 * // Yaroslav Polyakov (xenon@granch.ru)
12 * // - main developer of this version
13 * // Alexey Zverev (zverev@granch.ru)
14 * // - previous SBNI driver for linux
15 * // Alexey Chirkov (chirkov@granch.ru)
16 * // - all the hardware work and consulting
17 * // Max Khon (max@iclub.nsu.ru)
18 * // - first SBNI driver for linux
19 * // --------------------------------------------
20 * // also I thank:
21 * // Max Krasnyansky (max@uznet.net)
22 * // - for bug hunting and many ideas
23 * // Alan Cox (Alan.Cox@linux.org)
24 * // - for consulting in some hardcore questions
25 * // Donald Becker (becker@cesdis.gsfc.nasa.gov)
26 * // - for pretty nice skeleton
28 * More info and useful utilities to work w/ SBNI you can find at
29 * http://www.granch.ru.
31 * 3.0.0 = Initial Revision, Yaroslav Polyakov (24 Feb 1999)
32 * - added pre-calculation for CRC, fixed bug with "len-2" frames,
33 * - removed outbound fragmentation (MTU=1000), written CRC-calculation
34 * - on asm, added work with hard_headers and now we have our own cache
35 * - for them, optionally supported word-interchange on some chipsets,
36 * - something else I cant remember ;)
38 * 3.0.1 = just fixed some bugs (14 apr 1999).
39 * - fixed statistical tx bug
40 * - fixed wrong creation dates (1998 -> 1999) in driver source code ;)
41 * - fixed source address bug.
42 * - fixed permanent nirvana bug
44 * 3.1.0 = (Katyusha) (26 apr 1999)
45 * - Added balancing feature
47 * 3.1.1 = (Medea) (5 aug 1999)
48 * - Fixed mac.raw bug
49 * - Thanks to tolix@olviko.ru and
50 * - to Barnaul Brewery, producers of my favorite beer "Medea".
56 #undef GOODBUS16
57 #define CRCASM
58 #define KATYUSHA
60 #include <linux/version.h>
62 #if LINUX_VERSION_CODE >=0x020200
63 #define v22
64 #endif
67 #include <linux/module.h>
68 #include <linux/kernel.h>
69 #include <linux/sched.h>
70 #include <linux/ptrace.h>
71 #include <linux/fcntl.h>
72 #include <linux/ioport.h>
73 #include <linux/interrupt.h>
74 #include <linux/malloc.h>
75 #include <linux/string.h>
76 #include <linux/errno.h>
78 #include <asm/io.h>
79 #include <asm/types.h>
80 #include <asm/byteorder.h>
83 #include <linux/netdevice.h>
84 #include <linux/etherdevice.h>
85 #include <linux/skbuff.h>
86 #include <linux/timer.h>
87 #include <linux/config.h> /* for CONFIG_INET. do we need this?*/
89 #include <net/arp.h>
93 #ifdef v22
94 #include <asm/uaccess.h>
95 #include <linux/init.h>
96 #endif
98 #include "sbni.h"
101 static const char *version =
102 "sbni.c: ver. 3.1.1 Medea 5 Aug 1999 Yaroslav Polyakov (xenon@granch.ru)\n";
104 int sbni_probe(struct net_device *dev);
105 static int sbni_probe1(struct net_device *dev, int ioaddr);
106 static int sbni_open(struct net_device *dev);
107 static int sbni_start_xmit(struct sk_buff *skb, struct net_device *dev);
108 static void sbni_interrupt(int irq, void *dev_id, struct pt_regs *regs);
109 static int sbni_close(struct net_device *dev);
110 static void sbni_drop_tx_queue(struct net_device *dev);
111 static struct enet_statistics *sbni_get_stats(struct net_device *dev);
112 void card_start(struct net_device *dev);
113 static inline unsigned short sbni_recv(struct net_device *dev);
114 void change_level(struct net_device *dev);
115 static inline void sbni_xmit(struct net_device *dev);
116 static inline void sbni_get_packet(struct net_device* dev);
117 static void sbni_watchdog(unsigned long arg);
118 static void set_multicast_list(struct net_device *dev);
119 static int sbni_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd);
120 static int sbni_set_mac_address(struct net_device *dev, void *addr);
121 unsigned long calc_crc(char *mem, int len, unsigned initial);
122 void sbni_nirvana(struct net_device *dev);
123 static int sbni_header(struct sk_buff *skb, struct net_device *dev, unsigned short type,
124 void *daddr, void *saddr, unsigned len);
126 static int sbni_rebuild_header(struct sk_buff *skb);
127 static int sbni_header_cache(struct neighbour *neigh, struct hh_cache *hh);
129 static inline void sbni_outs(int port, void *data, int len);
130 static inline void sbni_ins(int port, void *data, int len);
134 #define SIZE_OF_TIMEOUT_RXL_TAB 4
135 static u_char timeout_rxl_tab[] = {
136 0x03, 0x05, 0x08, 0x0b
139 static u_char rxl_tab[] = {
140 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x08,
141 0x0a, 0x0c, 0x0f, 0x16, 0x18, 0x1a, 0x1c, 0x1f
144 /* A zero-terminated list of I/O addresses to be probed */
145 static unsigned int netcard_portlist[] = {
146 0x210, 0x2c0, 0x2d0, 0x2f0, 0x220, 0x230, 0x240, 0x250,
147 0x260, 0x290, 0x2a0, 0x2b0, 0x224, 0x234, 0x244, 0x254,
148 0x264, 0x294, 0x2a4, 0x2b4, 0};
150 static unsigned char magic_reply[] = {
151 0x5a,0x06,0x30,0x00,0x00,0x50,0x65,0x44,0x20
154 static int def_baud = DEF_RATE;
155 static int def_rxl = DEF_RXL_DELTA;
156 static long def_mac = 0;
160 * CRC-32 stuff
163 #define CRC32(c,crc) (crc32tab[((size_t)(crc) ^ (c)) & 0xff] ^ (((crc) >> 8) & 0x00FFFFFF))
164 /* CRC generator 0xEDB88320 */
165 /* CRC remainder 0x2144DF1C */
166 /* CRC initial value 0x00000000 */
167 #define CRC32_REMAINDER 0x2144DF1C
168 #define CRC32_INITIAL 0x00000000
170 static unsigned long crc32tab[] = {
171 0xD202EF8D, 0xA505DF1B, 0x3C0C8EA1, 0x4B0BBE37,
172 0xD56F2B94, 0xA2681B02, 0x3B614AB8, 0x4C667A2E,
173 0xDCD967BF, 0xABDE5729, 0x32D70693, 0x45D03605,
174 0xDBB4A3A6, 0xACB39330, 0x35BAC28A, 0x42BDF21C,
175 0xCFB5FFE9, 0xB8B2CF7F, 0x21BB9EC5, 0x56BCAE53,
176 0xC8D83BF0, 0xBFDF0B66, 0x26D65ADC, 0x51D16A4A,
177 0xC16E77DB, 0xB669474D, 0x2F6016F7, 0x58672661,
178 0xC603B3C2, 0xB1048354, 0x280DD2EE, 0x5F0AE278,
179 0xE96CCF45, 0x9E6BFFD3, 0x0762AE69, 0x70659EFF,
180 0xEE010B5C, 0x99063BCA, 0x000F6A70, 0x77085AE6,
181 0xE7B74777, 0x90B077E1, 0x09B9265B, 0x7EBE16CD,
182 0xE0DA836E, 0x97DDB3F8, 0x0ED4E242, 0x79D3D2D4,
183 0xF4DBDF21, 0x83DCEFB7, 0x1AD5BE0D, 0x6DD28E9B,
184 0xF3B61B38, 0x84B12BAE, 0x1DB87A14, 0x6ABF4A82,
185 0xFA005713, 0x8D076785, 0x140E363F, 0x630906A9,
186 0xFD6D930A, 0x8A6AA39C, 0x1363F226, 0x6464C2B0,
187 0xA4DEAE1D, 0xD3D99E8B, 0x4AD0CF31, 0x3DD7FFA7,
188 0xA3B36A04, 0xD4B45A92, 0x4DBD0B28, 0x3ABA3BBE,
189 0xAA05262F, 0xDD0216B9, 0x440B4703, 0x330C7795,
190 0xAD68E236, 0xDA6FD2A0, 0x4366831A, 0x3461B38C,
191 0xB969BE79, 0xCE6E8EEF, 0x5767DF55, 0x2060EFC3,
192 0xBE047A60, 0xC9034AF6, 0x500A1B4C, 0x270D2BDA,
193 0xB7B2364B, 0xC0B506DD, 0x59BC5767, 0x2EBB67F1,
194 0xB0DFF252, 0xC7D8C2C4, 0x5ED1937E, 0x29D6A3E8,
195 0x9FB08ED5, 0xE8B7BE43, 0x71BEEFF9, 0x06B9DF6F,
196 0x98DD4ACC, 0xEFDA7A5A, 0x76D32BE0, 0x01D41B76,
197 0x916B06E7, 0xE66C3671, 0x7F6567CB, 0x0862575D,
198 0x9606C2FE, 0xE101F268, 0x7808A3D2, 0x0F0F9344,
199 0x82079EB1, 0xF500AE27, 0x6C09FF9D, 0x1B0ECF0B,
200 0x856A5AA8, 0xF26D6A3E, 0x6B643B84, 0x1C630B12,
201 0x8CDC1683, 0xFBDB2615, 0x62D277AF, 0x15D54739,
202 0x8BB1D29A, 0xFCB6E20C, 0x65BFB3B6, 0x12B88320,
203 0x3FBA6CAD, 0x48BD5C3B, 0xD1B40D81, 0xA6B33D17,
204 0x38D7A8B4, 0x4FD09822, 0xD6D9C998, 0xA1DEF90E,
205 0x3161E49F, 0x4666D409, 0xDF6F85B3, 0xA868B525,
206 0x360C2086, 0x410B1010, 0xD80241AA, 0xAF05713C,
207 0x220D7CC9, 0x550A4C5F, 0xCC031DE5, 0xBB042D73,
208 0x2560B8D0, 0x52678846, 0xCB6ED9FC, 0xBC69E96A,
209 0x2CD6F4FB, 0x5BD1C46D, 0xC2D895D7, 0xB5DFA541,
210 0x2BBB30E2, 0x5CBC0074, 0xC5B551CE, 0xB2B26158,
211 0x04D44C65, 0x73D37CF3, 0xEADA2D49, 0x9DDD1DDF,
212 0x03B9887C, 0x74BEB8EA, 0xEDB7E950, 0x9AB0D9C6,
213 0x0A0FC457, 0x7D08F4C1, 0xE401A57B, 0x930695ED,
214 0x0D62004E, 0x7A6530D8, 0xE36C6162, 0x946B51F4,
215 0x19635C01, 0x6E646C97, 0xF76D3D2D, 0x806A0DBB,
216 0x1E0E9818, 0x6909A88E, 0xF000F934, 0x8707C9A2,
217 0x17B8D433, 0x60BFE4A5, 0xF9B6B51F, 0x8EB18589,
218 0x10D5102A, 0x67D220BC, 0xFEDB7106, 0x89DC4190,
219 0x49662D3D, 0x3E611DAB, 0xA7684C11, 0xD06F7C87,
220 0x4E0BE924, 0x390CD9B2, 0xA0058808, 0xD702B89E,
221 0x47BDA50F, 0x30BA9599, 0xA9B3C423, 0xDEB4F4B5,
222 0x40D06116, 0x37D75180, 0xAEDE003A, 0xD9D930AC,
223 0x54D13D59, 0x23D60DCF, 0xBADF5C75, 0xCDD86CE3,
224 0x53BCF940, 0x24BBC9D6, 0xBDB2986C, 0xCAB5A8FA,
225 0x5A0AB56B, 0x2D0D85FD, 0xB404D447, 0xC303E4D1,
226 0x5D677172, 0x2A6041E4, 0xB369105E, 0xC46E20C8,
227 0x72080DF5, 0x050F3D63, 0x9C066CD9, 0xEB015C4F,
228 0x7565C9EC, 0x0262F97A, 0x9B6BA8C0, 0xEC6C9856,
229 0x7CD385C7, 0x0BD4B551, 0x92DDE4EB, 0xE5DAD47D,
230 0x7BBE41DE, 0x0CB97148, 0x95B020F2, 0xE2B71064,
231 0x6FBF1D91, 0x18B82D07, 0x81B17CBD, 0xF6B64C2B,
232 0x68D2D988, 0x1FD5E91E, 0x86DCB8A4, 0xF1DB8832,
233 0x616495A3, 0x1663A535, 0x8F6AF48F, 0xF86DC419,
234 0x660951BA, 0x110E612C, 0x88073096, 0xFF000000
237 static inline void sbni_outs(int port, void *data, int len)
239 #ifdef GOODBUS16
240 outsw(port,data,len/2);
241 if(len & 1)
242 outb(((char*)data)[len - 1],port);
243 #else
244 outsb(port,data,len);
245 #endif
248 static inline void sbni_ins(int port, void *data, int len)
250 #ifdef GOODBUS16
251 insw(port,data,len/2);
252 if(len & 1)
253 ((char*)data)[len - 1] = inb(port);
254 #else
255 insb(port,data,len);
256 #endif
260 static int sbni_header(struct sk_buff *skb, struct net_device *dev, unsigned short type,
261 void *daddr, void *saddr, unsigned len)
263 struct sbni_hard_header *hh = (struct sbni_hard_header *)
264 skb_push(skb, sizeof(struct sbni_hard_header));
267 if(type!=ETH_P_802_3)
268 hh->h_proto = htons(type);
269 else
270 hh->h_proto = htons(len);
272 if(saddr)
273 memcpy(hh->h_source,saddr,dev->addr_len);
274 else
275 memcpy(hh->h_source,dev->dev_addr,dev->addr_len);
277 if(daddr)
279 memcpy(hh->h_dest,daddr,dev->addr_len);
280 return dev->hard_header_len;
282 return -dev->hard_header_len;
286 int sbni_header_cache(struct neighbour *neigh, struct hh_cache *hh)
288 unsigned short type = hh->hh_type;
289 struct sbni_hard_header *sbni = (struct sbni_hard_header*)
290 (((u8*)hh->hh_data) - 8);
291 struct net_device *dev = neigh->dev;
294 if (type == __constant_htons(ETH_P_802_3))
295 return -1;
297 sbni->h_proto = type;
298 memcpy(sbni->h_source, dev->dev_addr, dev->addr_len);
299 memcpy(sbni->h_dest, neigh->ha, dev->addr_len);
300 return 0;
303 static int sbni_rebuild_header(struct sk_buff *skb)
305 struct sbni_hard_header *hh = (struct sbni_hard_header *)skb;
307 * Only ARP/IP is currently supported
311 * Try to get ARP to resolve the header.
314 #ifdef CONFIG_INET
315 return arp_find((unsigned char*)hh->h_dest, skb)? 1 : 0;
316 #else
317 return 0;
318 #endif
321 static void sbni_header_cache_update(struct hh_cache *hh, struct net_device *dev, unsigned char * haddr)
323 memcpy(((u8*)hh->hh_data) + 2, haddr, dev->addr_len);
328 #ifdef HAVE_DEVLIST
329 struct netdev_entry sbni_drv = {
330 "sbni", sbni_probe1, SBNI_IO_EXTENT, netcard_portlist
333 #else
335 int __init sbni_probe(struct net_device *dev)
337 int i;
338 int base_addr = dev ? dev->base_addr : 0;
340 DP( printk("%s: sbni_probe\n", dev->name); )
342 if(base_addr > 0x1ff) /* Check a single specified location. */
343 return sbni_probe1(dev, base_addr);
344 else if(base_addr != 0) /* Don't probe at all. */
345 return ENXIO;
346 for(i = 0; (base_addr = netcard_portlist[i]); i++)
348 if(!check_region(base_addr, SBNI_IO_EXTENT) && base_addr != 1)
350 /* Lock this address, or later we'll try it again */
351 netcard_portlist[i] = 1;
352 if(sbni_probe1(dev, base_addr) == 0)
353 return 0;
356 return ENODEV;
359 #endif /* have devlist*/
362 * The actual probe.
366 Valid combinations in CSR0 (for probing):
368 VALID_DECODER 0000,0011,1011,1010
370 ; 0 ; -
371 TR_REQ ; 1 ; +
372 TR_RDY ; 2 ; -
373 TR_RDY TR_REQ ; 3 ; +
374 BU_EMP ; 4 ; +
375 BU_EMP TR_REQ ; 5 ; +
376 BU_EMP TR_RDY ; 6 ; -
377 BU_EMP TR_RDY TR_REQ ; 7 ; +
378 RC_RDY ; 8 ; +
379 RC_RDY TR_REQ ; 9 ; +
380 RC_RDY TR_RDY ; 10 ; -
381 RC_RDY TR_RDY TR_REQ ; 11 ; -
382 RC_RDY BU_EMP ; 12 ; -
383 RC_RDY BU_EMP TR_REQ ; 13 ; -
384 RC_RDY BU_EMP TR_RDY ; 14 ; -
385 RC_RDY BU_EMP TR_RDY TR_REQ ; 15 ; -
387 #define VALID_DECODER (2 + 8 + 0x10 + 0x20 + 0x80 + 0x100 + 0x200)
389 static int __init sbni_probe1(struct net_device *dev, int ioaddr)
392 int autoirq = 0;
393 int bad_card = 0;
394 unsigned char csr0;
395 struct net_local* lp;
396 static int version_printed = 0;
398 DP( printk("%s: sbni_probe1 ioaddr=%d\n", dev->name, ioaddr); )
400 if(check_region(ioaddr, SBNI_IO_EXTENT) < 0)
401 return -ENODEV;
402 if(version_printed++ == 0)
403 printk(version);
405 /* check for valid combination in CSR0 */
406 csr0 = inb(ioaddr + CSR0);
407 if(csr0 == 0xff || csr0 == 0)
408 bad_card = 1;
409 else
411 csr0 &= ~EN_INT;
412 if(csr0 & BU_EMP)
413 csr0 |= EN_INT;
414 if((VALID_DECODER & (1 << (csr0 >> 4))) == 0)
415 bad_card = 1;
418 if(bad_card)
419 return ENODEV;
420 else
421 outb(0, ioaddr + CSR0);
422 if(dev->irq < 2)
424 DP( printk("%s: autoprobing\n", dev->name); );
425 autoirq_setup(5);
426 outb(EN_INT | TR_REQ, ioaddr + CSR0);
427 outb(PR_RES, ioaddr + CSR1);
428 autoirq = autoirq_report(5);
430 if(autoirq == 0)
432 printk("sbni probe at %#x failed to detect IRQ line\n", ioaddr);
433 return EAGAIN;
436 /* clear FIFO buffer */
437 outb(0, ioaddr + CSR0);
439 if(autoirq)
440 dev->irq = autoirq;
443 int irqval=request_irq(dev->irq, sbni_interrupt, 0, dev->name, dev);
444 if (irqval)
446 printk (" unable to get IRQ %d (irqval=%d).\n", dev->irq, irqval);
447 return EAGAIN;
452 * Initialize the device structure.
455 dev->priv = kmalloc(sizeof(struct net_local), GFP_KERNEL);
456 if(dev->priv == NULL)
458 DP( printk("%s: cannot allocate memory\n", dev->name); )
459 return -ENOMEM;
462 memset(dev->priv, 0, sizeof(struct net_local));
463 dev->base_addr = ioaddr;
464 request_region(ioaddr, SBNI_IO_EXTENT, "sbni");
467 * generate Ethernet address (0x00ff01xxxxxx)
470 *(u16*)dev->dev_addr = htons(0x00ff);
471 *(u32*)(dev->dev_addr+2) = htonl(((def_mac ? def_mac : (u32) dev->priv) & 0x00ffffff) | 0x01000000);
473 lp = dev->priv;
474 if(def_rxl < 0)
476 /* autodetect receive level */
477 lp->rxl_curr = 0xf;
478 lp->rxl_delta = -1;
479 } else {
480 /* fixed receive level */
481 lp->rxl_curr = def_rxl & 0xf;
482 lp->rxl_delta = 0;
484 lp->csr1.rxl = rxl_tab[lp->rxl_curr];
485 lp->csr1.rate = def_baud & 3;
486 lp->frame_len = DEF_FRAME_LEN;
487 printk("%s: sbni adapter at %#lx, using %sIRQ %d, MAC: 00:ff:01:%x:%x:%x\n",
488 dev->name, dev->base_addr, autoirq ? "auto":"assigned ", dev->irq,
489 *(unsigned char*)(dev->dev_addr+3),
490 *(unsigned char*)(dev->dev_addr+4),
491 *(unsigned char*)(dev->dev_addr+5)
494 printk("%s: receive level: ", dev->name);
495 if(lp->rxl_delta == 0)
496 printk ("%#1x (fixed)", lp->rxl_curr);
497 else
498 printk ("autodetect");
499 printk(", baud rate: %u\n", (unsigned)lp->csr1.rate);
502 * The SBNI-specific entries in the device structure.
504 dev->open = &sbni_open;
505 dev->hard_start_xmit = &sbni_start_xmit;
506 dev->stop = &sbni_close;
507 dev->get_stats = &sbni_get_stats;
508 dev->set_multicast_list = &set_multicast_list;
509 dev->set_mac_address = &sbni_set_mac_address;
510 dev->do_ioctl = &sbni_ioctl;
513 * Setup the generic properties
516 ether_setup(dev);
518 dev->hard_header = sbni_header;
519 dev->hard_header_len = sizeof(struct sbni_hard_header);
520 dev->rebuild_header=sbni_rebuild_header;
521 dev->mtu = DEF_FRAME_LEN;
523 dev->hard_header_cache = sbni_header_cache;
524 dev->header_cache_update = sbni_header_cache_update;
526 lp->m=dev;
527 lp->me=dev;
528 lp->next_lp=NULL;
530 return 0;
534 * Open/initialize the board.
537 static int sbni_open(struct net_device *dev)
539 struct net_local* lp = (struct net_local*)dev->priv;
540 struct timer_list* watchdog = &lp->watchdog;
543 DP( printk("%s: sbni_open\n", dev->name); )
545 cli();
546 lp->currframe = NULL;
548 card_start(dev);
549 dev->start = 1;
550 /* set timer watchdog */
551 init_timer(watchdog);
552 watchdog->expires = jiffies + SBNI_TIMEOUT;
553 watchdog->data = (unsigned long)dev;
554 watchdog->function = sbni_watchdog;
555 add_timer(watchdog);
556 DP( printk("%s: sbni timer watchdog initialized\n", dev->name); );
558 sti();
560 MOD_INC_USE_COUNT;
561 return 0;
564 static int sbni_close(struct net_device *dev)
566 int ioaddr = dev->base_addr;
567 struct net_local* lp = (struct net_local*) dev->priv;
568 struct timer_list* watchdog = &lp->watchdog;
571 DP( printk("%s: sbni_close\n", dev->name); )
573 cli();
575 sbni_drop_tx_queue(dev);
577 dev->tbusy = 1;
578 dev->start = 0;
580 del_timer(watchdog);
582 outb(0, ioaddr + CSR0);
583 sti();
585 MOD_DEC_USE_COUNT;
586 return 0;
589 static int sbni_start_xmit(struct sk_buff *skb, struct net_device *dev)
591 struct net_local *lp = (struct net_local*)dev->priv;
592 struct sbni_hard_header *hh=(struct sbni_hard_header *)skb->data;
594 #ifdef KATYUSHA
595 struct net_local *nl;
596 int stop;
597 #endif
599 DP( printk("%s: sbni_start_xmit In \n", dev->name); );
602 if(lp->me != dev)
603 panic("sbni: lp->me != dev !!!\nMail to developer (xenon@granch.ru) if you noticed this error\n");
605 if(dev->interrupt)
607 DP( printk("sbni_xmit_start: interrupt\n"); )
608 /* May be unloading, don't stamp on */
609 return 1; /* the packet buffer this time */
612 hh->number = 1;
613 hh->reserv = 0;
615 hh->packetlen = (skb->len - sizeof (unsigned short) -
616 (sizeof(struct sbni_hard_header) - SBNI_HH_SZ))
617 | PACKET_SEND_OK | PACKET_FIRST_FRAME;
619 /* we should use hairy method to calculate crc because of extra bytes are
620 livin between hard header and data*/
621 hh->crc = calc_crc((void*)&hh->packetlen, SBNI_HH_SZ - sizeof(unsigned), CRC32_INITIAL);
622 hh->crc = calc_crc(skb->data + sizeof(struct sbni_hard_header),
623 skb->len - sizeof(struct sbni_hard_header),
624 hh->crc);
626 #ifdef KATYUSHA
627 /* looking for first idle device */
628 for (stop=0,nl=lp; nl && !stop; nl=nl->next_lp)
630 if((!nl->currframe) && (nl->carrier)) /* if idle */
632 skb->dev = lp->me;
633 nl->currframe = skb;
634 /* set request for transmit */
635 outb(inb(nl->me->base_addr + CSR0) | TR_REQ,
636 nl->me->base_addr + CSR0);
637 stop=1;
641 if(!stop) /* we havent found any idle.*/
643 skb_queue_tail(&lp->queue,skb);
644 outb(inb(dev->base_addr + CSR0) | TR_REQ, dev->base_addr + CSR0);
647 #else
648 if (lp->currframe || 1)
650 skb_queue_tail(&lp->queue,skb);
653 else
655 lp->currframe = skb;
657 /* set request for transmit */
658 outb(inb(dev->base_addr + CSR0) | TR_REQ, dev->base_addr + CSR0);
659 #endif
660 return 0;
663 void card_start(struct net_device *dev)
665 struct net_local *lp = (struct net_local*)dev->priv;
667 DP( printk("%s: card_start\n",dev->name); )
668 lp->wait_frame_number = 0;
669 lp->inppos = lp->outpos = 0;
670 lp->eth_trans_buffer_len = 0;
671 lp->tr_err = TR_ERROR_COUNT;
672 lp->last_receive_OK = FALSE;
673 lp->tr_resend = FALSE;
674 lp->timer_ticks = CHANGE_LEVEL_START_TICKS;
675 lp->timeout_rxl = 0;
677 lp->waitack=0;
678 skb_queue_head_init(&lp->queue);
679 sbni_drop_tx_queue(dev);
680 dev->tbusy = 0;
682 dev->interrupt = 0;
683 /* Reset the card and set start parameters */
684 outb(PR_RES | *(char*)&lp->csr1, dev->base_addr + CSR1);
685 outb(EN_INT, dev->base_addr + CSR0);
688 void sbni_nirvana(struct net_device *dev)
690 sbni_outs(dev->base_addr+DAT,magic_reply,9);
693 static inline unsigned short sbni_recv(struct net_device *dev)
695 struct net_local *lp = (struct net_local*)dev->priv;
696 unsigned long crc;
697 unsigned short packetlen = 0;
698 unsigned short packetinf, packetfirst, receiveframeresend;
699 unsigned char current_frame;
700 unsigned int i, j;
701 unsigned char delme,rcv_res=RCV_WR;
703 lp->in_stats.all_rx_number++;
705 if((delme=inb(dev->base_addr + DAT)) == SBNI_SIG)
707 crc = CRC32_INITIAL;
708 *(((unsigned char *)&packetlen) + 0) = inb(dev->base_addr + DAT);
709 crc = CRC32(*(((unsigned char *)&packetlen) + 0), crc);
710 *(((unsigned char *)&packetlen) + 1) = inb(dev->base_addr + DAT);
711 crc = CRC32(*(((unsigned char *)&packetlen) + 1), crc);
712 packetinf = packetlen & PACKET_INF_MASK;
713 packetfirst = packetlen & PACKET_FIRST_FRAME;
714 receiveframeresend = packetlen & RECEIVE_FRAME_RESEND;
715 packetlen = packetlen & PACKET_LEN_MASK;
718 if((packetlen <= SB_MAX_BUFFER_ARRAY - 3) && (packetlen >= 6))
720 /* read frame number */
721 current_frame = inb(dev->base_addr + DAT);
722 crc = CRC32(current_frame, crc);
723 /* read HandShake counter */
724 lp->HSCounter = inb(dev->base_addr + DAT);
725 crc = CRC32(lp->HSCounter, crc);
726 packetlen -= 2;
728 sbni_ins(dev->base_addr + DAT, lp->eth_rcv_buffer + lp->inppos, packetlen);
730 for(i = lp->inppos; i < (packetlen + lp->inppos); i++)
732 crc = CRC32(lp->eth_rcv_buffer[i], crc);
735 if(crc == CRC32_REMAINDER)
737 if(packetlen > 4)
738 rcv_res=RCV_OK;
739 else if(packetlen == 4)
740 rcv_res=RCV_NO;
742 if(lp->waitack && packetinf == PACKET_RESEND)
743 lp->in_stats.resend_tx_number++;
746 switch(packetinf)
748 case PACKET_SEND_OK:
750 lp->tr_err = TR_ERROR_COUNT;
751 lp->tr_resend = FALSE;
752 /* if(lp->trans_frame_number){ */
753 lp->outpos += lp->realframelen;
755 /* SendComplete
756 * not supported
758 DP( printk("%s: sbni_recv SendComplete\n",dev->name); );
760 * We sucessfully sent current packet
763 if(lp->waitack)
765 dev_kfree_skb(lp->currframe);
766 lp->stats.tx_packets++;
767 #ifdef KATYUSHA
768 lp->currframe=skb_dequeue(&(((struct net_local*) (lp->m->priv))->queue));
769 #else
770 lp->currframe=skb_dequeue(&lp->queue);
771 #endif
772 lp->in_stats.all_tx_number++;
773 lp->waitack=0;
777 * reset output active flags
779 dev->tbusy = 0;
780 mark_bh(NET_BH);
781 /*} if */
783 case PACKET_RESEND:
785 if(lp->tr_err) /**/
786 lp->tr_err--;
787 if(lp->ok_curr < 0xffffffff)
788 lp->ok_curr++;
789 if(packetlen > 4 && !(lp->last_receive_OK && receiveframeresend))
791 if(packetfirst)
793 if(lp->wait_frame_number)
795 for(i = lp->inppos, j = 0;
796 i < (lp->inppos + packetlen - 4);
797 i++, j++)
798 lp->eth_rcv_buffer[j] = lp->eth_rcv_buffer[i];
800 lp->wait_frame_number = current_frame;
801 lp->inppos = 0;
803 if(current_frame == lp->wait_frame_number)
805 lp->inppos += (packetlen - 4);
806 if(lp->wait_frame_number == 1)
808 sbni_get_packet(dev);
809 lp->inppos = 0;
811 lp->wait_frame_number--;
814 lp->last_receive_OK = TRUE;
815 break;
817 default:
818 break;
821 else
823 DP(printk("%s: bad CRC32\n",dev->name));
824 change_level(dev);
827 else
829 DP(printk("%s: bad len\n ",dev->name));
830 change_level(dev);
831 lp->stats.rx_over_errors++;
834 else
836 DP(printk("%s: bad sig\n",dev->name));
837 change_level(dev);
839 outb(inb(dev->base_addr + CSR0) ^ CT_ZER, dev->base_addr + CSR0);
840 return (rcv_res);
843 void change_level(struct net_device *dev)
845 struct net_local *lp = (struct net_local*)dev->priv;
847 lp->in_stats.bad_rx_number++;
848 lp->stats.tx_errors++;
849 if(lp->rxl_delta == 0)
850 return;
852 * set new rxl_delta value
854 if(lp->rxl_curr == 0)
855 lp->rxl_delta = 1;
856 else if(lp->rxl_curr == 0xf)
857 lp->rxl_delta = -1;
858 else if(lp->ok_curr < lp->ok_prev)
859 lp->rxl_delta = -lp->rxl_delta;
861 * set new rxl_curr value
863 lp->csr1.rxl = rxl_tab[lp->rxl_curr += lp->rxl_delta];
864 outb(*(char*)&lp->csr1, dev->base_addr + CSR1);
868 * update ok_prev/ok_curr counters
870 lp->ok_prev = lp->ok_curr;
871 lp->ok_curr = 0;
873 DP( printk("%s: receive error, rxl_curr = %d, rxl_delta = %d\n",\
874 dev->name,lp->rxl_curr, lp->rxl_delta); )
878 static inline void sbni_xmit(struct net_device *dev)
880 struct net_local* lp = (struct net_local *)dev->priv;
881 struct sk_buff *skb;
883 skb=lp->currframe;
885 DP( printk("%s: sbni_xmit CSR0=%02x\n",dev->name, (unsigned char)inb(dev->base_addr + CSR0)); );
887 /* push signature*/
888 outb(SBNI_SIG, dev->base_addr + DAT);
890 /* push frame w/o crc [HAiRY]*/
891 sbni_outs(dev->base_addr + DAT,
892 &((struct sbni_hard_header *)(skb->data))->packetlen,
893 SBNI_HH_SZ - sizeof(unsigned));
895 sbni_outs(dev->base_addr + DAT,
896 skb->data + sizeof(struct sbni_hard_header),
897 skb->len - sizeof(struct sbni_hard_header)); /* ÕÓÐÅÅÍ ÅÝÅ */
899 /* push crc */
900 sbni_outs(dev->base_addr + DAT, skb->data, sizeof(unsigned));
902 lp->waitack=1;
906 * The typical workload of the driver:
907 * Handle the ether interface interrupts.
909 static void sbni_interrupt(int irq, void *dev_id, struct pt_regs *regs)
911 struct net_device *dev = dev_id;
912 struct net_local* lp;
913 u_char csr0;
914 unsigned short rcv_res = RCV_NO;
917 if(dev == NULL || dev->irq != irq)
919 printk("sbni: irq %d for unknown device\n", irq);
920 return;
923 if(dev->interrupt)
925 printk("%s: Reentering the interrupt driver!\n", dev->name);
926 return;
928 dev->interrupt = 1;
930 csr0 = inb(dev->base_addr + CSR0);
931 DP( printk("%s: entering interrupt handler, CSR0 = %02x\n", dev->name, csr0); )
933 lp=dev->priv;
935 if(!lp->carrier)
936 lp->carrier=1;
939 * Disable adapter interrupts
941 outb((csr0 & ~EN_INT) | TR_REQ, dev->base_addr + CSR0);
942 lp->timer_ticks = CHANGE_LEVEL_START_TICKS;
943 csr0 = inb(dev->base_addr + CSR0);
945 if(csr0 & (TR_RDY | RC_RDY))
947 if(csr0 & RC_RDY)
948 rcv_res = sbni_recv(dev);
950 if((lp->currframe) && (rcv_res != RCV_WR))
951 sbni_xmit(dev);
952 else if (rcv_res == RCV_OK)
953 sbni_nirvana(dev);
955 csr0 = inb(dev->base_addr + CSR0);
956 DP( printk("%s: CSR0 = %02x\n",dev->name, (u_int)csr0); );
960 DP( printk("%s: leaving interrupt handler, CSR0 = %02x\n",dev->name, csr0 | EN_INT); );
962 /* here we should send pong */
963 outb(inb(dev->base_addr+CSR0) & ~TR_REQ, dev->base_addr + CSR0);
964 if(lp->currframe)
965 outb(inb(dev->base_addr+CSR0) | TR_REQ, dev->base_addr + CSR0);
966 else
967 csr0 = inb(dev->base_addr + CSR0);
970 * Enable adapter interrupts
973 outb(csr0 | EN_INT, dev->base_addr + CSR0);
974 dev->interrupt = 0;
977 static struct enet_statistics *sbni_get_stats(struct net_device *dev)
979 struct net_local *lp = (struct net_local *)dev->priv;
980 return &lp->stats;
983 static inline void sbni_get_packet(struct net_device* dev)
985 struct net_local* lp = (struct net_local*)dev->priv;
986 struct sk_buff* skb;
987 unsigned char *rawp;
991 skb = dev_alloc_skb(lp->inppos - ETH_HLEN + sizeof(struct sbni_hard_header));
993 if(skb == NULL)
995 DP( printk("%s: Memory squeeze, dropping packet.\n", dev->name); )
996 lp->stats.rx_dropped++;
997 return;
998 } else {
999 #ifdef KATYUSHA
1000 skb->dev = lp->m;
1001 #else
1002 skb->dev = dev;
1003 #endif
1004 memcpy((unsigned char*)skb_put(skb, lp->inppos + 8)+8,
1005 lp->eth_rcv_buffer,
1006 lp->inppos);
1009 skb->mac.raw = skb->data + 8;
1011 if((*(char*)lp->eth_rcv_buffer) & 1)
1013 if(memcmp(lp->eth_rcv_buffer,dev->broadcast, ETH_ALEN)==0)
1014 skb->pkt_type=PACKET_BROADCAST;
1015 else
1016 skb->pkt_type=PACKET_MULTICAST;
1018 else if(dev->flags&(IFF_PROMISC|IFF_ALLMULTI))
1020 if(memcmp(lp->eth_rcv_buffer,dev->dev_addr, ETH_ALEN))
1021 skb->pkt_type=PACKET_OTHERHOST;
1024 if( htons(*((unsigned short*)(&lp->eth_rcv_buffer[2*ETH_ALEN]))) >= 1536)
1025 skb->protocol = *((unsigned short*)(&lp->eth_rcv_buffer[2*ETH_ALEN]));
1026 else
1028 rawp = (unsigned char*)(&lp->eth_rcv_buffer[2*ETH_ALEN]);
1029 if (*(unsigned short *)rawp == 0xFFFF)
1030 skb->protocol=htons(ETH_P_802_3);
1031 else
1032 skb->protocol=htons(ETH_P_802_2);
1036 skb_pull(skb,SBNI_HH_SZ);
1038 netif_rx(skb);
1039 lp->stats.rx_packets++;
1041 return;
1044 static void sbni_watchdog(unsigned long arg)
1046 struct net_device* dev = (struct net_device*)arg;
1047 struct net_local* lp = (struct net_local *)dev->priv;
1048 u_char csr0;
1052 DP( printk("%s: watchdog start\n",dev->name); )
1054 * if no pong received and transmission is not in progress
1055 * then assume error
1057 cli();
1058 csr0 = inb(dev->base_addr + CSR0);
1059 if(csr0 & (RC_CHK | TR_REQ))
1061 if(lp->timer_ticks)
1063 if(csr0 & (RC_RDY | BU_EMP))
1065 lp->timer_ticks--;
1068 else
1070 if(lp->rxl_delta)
1072 lp->ok_prev = lp->ok_curr;
1073 lp->ok_curr = 0;
1074 lp->rxl_curr = timeout_rxl_tab[lp->timeout_rxl];
1075 lp->timeout_rxl++;
1076 if(lp->timeout_rxl > SIZE_OF_TIMEOUT_RXL_TAB - 1)
1077 lp->timeout_rxl = 0;
1078 lp->csr1.rxl = rxl_tab[lp->rxl_curr];
1080 * update ok_prev/ok_curr counters
1082 lp->ok_prev = lp->ok_curr;
1083 lp->ok_curr = 0;
1085 if(lp->tr_err)
1086 lp->tr_err--;
1087 else
1089 /* Drop the queue of tx packets */
1090 sbni_drop_tx_queue(dev);
1091 lp->carrier=0;
1095 * send pong
1098 csr0 = inb(dev->base_addr + CSR0);
1099 outb(csr0 & ~TR_REQ, dev->base_addr + CSR0);
1100 outb(*(char*)(&lp->csr1) | PR_RES, dev->base_addr + CSR1);
1101 lp->in_stats.timeout_number++;
1104 sti();
1105 outb(csr0 | RC_CHK, dev->base_addr + CSR0);
1106 if(dev->start)
1108 struct timer_list* watchdog = &lp->watchdog;
1109 init_timer(watchdog);
1110 watchdog->expires = jiffies + SBNI_TIMEOUT;
1111 watchdog->data = arg;
1112 watchdog->function = sbni_watchdog;
1113 add_timer(watchdog);
1117 static void sbni_drop_tx_queue(struct net_device *dev)
1119 struct net_local* lp = (struct net_local *)dev->priv,*nl;
1120 struct sk_buff *tmp;
1122 /* first of all, we should try to gift our packets to another interface */
1124 nl=(struct net_local *)lp->m->priv;
1125 if(nl==lp)
1126 nl=lp->next_lp;
1128 if(nl)
1130 /* we found device*/
1131 if(lp->currframe)
1133 if(!nl->currframe)
1135 nl->currframe=lp->currframe;
1137 else
1139 skb_queue_head(&((struct net_local*)(lp->m->priv))->queue,lp->currframe);
1142 lp->currframe=NULL;
1144 if(!nl->currframe)
1145 nl->currframe=skb_dequeue(&(((struct net_local*)(lp->m->priv))->queue));
1147 /* set request for transmit */
1148 outb(inb(nl->me->base_addr + CSR0) | TR_REQ, nl->me->base_addr + CSR0);
1151 else
1153 /* *sigh*, we should forget this packets */
1154 nl=lp->m->priv;
1156 while((tmp = skb_dequeue(&nl->queue)) != NULL)
1158 dev_kfree_skb(tmp);
1159 lp->stats.tx_packets++;
1162 if (lp->currframe)
1164 dev_kfree_skb(lp->currframe);
1165 lp->currframe = NULL;
1166 lp->stats.tx_packets++;
1169 lp->waitack=0;
1170 dev->tbusy = 0;
1172 mark_bh(NET_BH);
1173 DP( printk("%s: queue dropping stoped\n",dev->name); );
1177 * Set or clear the multicast filter for this adaptor.
1178 * num_addrs == -1 Promiscuous mode, receive all packets
1179 * num_addrs == 0 Normal mode, clear multicast list
1180 * num_addrs > 0 Multicast mode, receive normal and MC packets,
1181 * and do best-effort filtering.
1184 static void set_multicast_list(struct net_device *dev)
1187 * always enabled promiscuous mode.
1189 return;
1192 static int sbni_set_mac_address(struct net_device *dev, void *addr)
1194 /* struct net_local *lp = (struct net_local *)dev->priv; */
1195 struct sockaddr *saddr = addr;
1197 if(dev->start)
1199 /* Only possible while card isn't started */
1200 return -EBUSY;
1202 memcpy(dev->dev_addr, saddr->sa_data, dev->addr_len);
1203 return (0);
1206 static int sbni_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
1208 struct net_local* lp = (struct net_local *)dev->priv,*tlp;
1209 struct net_device *slave;
1210 int error = 0;
1211 char tmpstr[6];
1214 switch(cmd)
1216 case SIOCDEVGETINSTATS:
1218 struct sbni_in_stats *in_stats = (struct sbni_in_stats *)ifr->ifr_data;
1219 DP( printk("%s: SIOCDEVGETINSTATS %08x\n",dev->name,(unsigned)in_stats);)
1220 if(copy_to_user((void *)in_stats, (void *)(&(lp->in_stats)), sizeof(struct sbni_in_stats)))
1221 return -EFAULT;
1222 break;
1224 case SIOCDEVRESINSTATS:
1226 DP( printk("%s: SIOCDEVRESINSTATS\n",dev->name); )
1227 lp->in_stats.all_rx_number = 0;
1228 lp->in_stats.bad_rx_number = 0;
1229 lp->in_stats.timeout_number = 0;
1230 lp->in_stats.all_tx_number = 0;
1231 lp->in_stats.resend_tx_number = 0;
1232 break;
1234 case SIOCDEVGHWSTATE:
1236 struct sbni_flags flags;
1237 flags.rxl = lp->rxl_curr;
1238 flags.rate = lp->csr1.rate;
1239 flags.fixed_rxl = (lp->rxl_delta == 0);
1240 flags.fixed_rate = 1;
1241 ifr->ifr_data = *(caddr_t*)&flags;
1242 DP( printk("%s: get flags (0x%02x)\n",dev->name, (unsigned char)ifr->ifr_data); )
1243 break;
1245 case SIOCDEVSHWSTATE:
1247 struct sbni_flags flags;
1248 DP( printk("%s: SIOCDEVSHWSTATE flags=0x%02x\n",dev->name, (unsigned char)ifr->ifr_data); )
1249 /* root only */
1250 if(!capable(CAP_NET_ADMIN))
1251 return -EPERM;
1252 flags = *(struct sbni_flags*)&ifr->ifr_data;
1253 if(flags.fixed_rxl)
1255 lp->rxl_delta = 0;
1256 lp->rxl_curr = flags.rxl;
1258 else
1260 lp->rxl_delta = DEF_RXL_DELTA;
1261 lp->rxl_curr = DEF_RXL;
1263 lp->csr1.rxl = rxl_tab[lp->rxl_curr];
1264 if(flags.fixed_rate)
1265 lp->csr1.rate = flags.rate;
1266 else
1267 lp->csr1.rate = DEF_RATE;
1269 * Don't be afraid...
1271 outb(*(char*)(&lp->csr1) | PR_RES, dev->base_addr + CSR1);
1273 DP( printk("%s: set flags (0x%02x)\n receive level: %u, baud rate: %u\n",\
1274 dev->name, (unsigned char)ifr->ifr_data, (unsigned)lp->rxl_curr, (unsigned)lp->csr1.rate); )
1275 break;
1278 case SIOCDEVENSLAVE:
1279 if(!capable(CAP_NET_ADMIN))
1280 return -EPERM;
1281 if(copy_from_user( tmpstr, ifr->ifr_data, 6))
1282 return -EFAULT;
1283 slave=dev_get(tmpstr);
1284 if(!(slave && slave->flags & IFF_UP && dev->flags & IFF_UP))
1286 printk("%s: Both devices should be UP to enslave!\n",dev->name);
1287 return -EINVAL;
1290 if(slave)
1292 if(!((dev->flags & IFF_SLAVE) || (slave->flags & IFF_SLAVE)))
1294 /* drop queue*/
1295 sbni_drop_tx_queue(slave);
1296 slave->flags |= IFF_SLAVE;
1297 ((struct net_local *)(slave->priv))->m=dev;
1298 while(lp->next_lp) //tail it after last slave
1299 lp=lp->next_lp;
1300 lp->next_lp=slave->priv;
1301 lp=(struct net_local *)dev->priv;
1302 dev->flags |= IFF_MASTER;
1304 else
1306 printk("%s: one of devices is already slave!\n",dev->name);
1307 return -EBUSY;
1310 else
1312 printk("%s: can't find device %s to enslave\n",dev->name,ifr->ifr_data);
1313 return -ENOENT;
1315 break;
1317 case SIOCDEVEMANSIPATE:
1318 if(!capable(CAP_NET_ADMIN))
1319 return -EPERM;
1321 if(dev->flags & IFF_SLAVE)
1323 dev->flags &= ~IFF_SLAVE;
1324 /* exclude us from masters slavelist*/
1325 for(tlp=lp->m->priv;tlp->next_lp!=lp && tlp->next_lp;tlp=tlp->next_lp);
1326 if(tlp->next_lp)
1328 tlp->next_lp = lp->next_lp;
1329 if(!((struct net_local *)lp->m->priv)->next_lp)
1331 lp->m->flags &= ~IFF_MASTER;
1333 lp->next_lp=NULL;
1334 lp->m=dev;
1336 else
1338 printk("%s: Ooops. drivers structure is mangled!\n",dev->name);
1339 return -EIO;
1342 else
1344 printk("%s: isn't slave device!\n",dev->name);
1345 return -EINVAL;
1347 break;
1349 default:
1350 DP( printk("%s: invalid ioctl: 0x%x\n",dev->name, cmd); )
1351 error = -EINVAL;
1353 return (error);
1358 #ifdef CRCASM
1360 unsigned long calc_crc(char *mem, int len, unsigned initial)
1363 __asm__ (
1364 "xorl %%eax,%%eax\n\t"
1365 "1:\n\t"
1366 "lodsb\n\t"
1367 "xorb %%dl,%%al\n\t"
1368 "shrl $8,%%edx\n\t"
1369 "xorl (%%edi,%%eax,4),%%edx\n\t"
1370 "loop 1b\n\t"
1371 "movl %%edx,%%eax"
1373 : "S" (mem), "D" (&crc32tab[0]), "c" (len), "d" (initial)
1374 : "eax", "edx", "ecx"
1376 /* return crc; */
1379 #else
1381 unsigned long calc_crc(char *mem, int len, unsigned initial)
1383 unsigned crc;
1384 crc = initial;
1386 for(;len;mem++,len--)
1388 crc = CRC32(*mem, crc);
1390 return(crc);
1392 #endif /* CRCASM */
1393 #ifdef MODULE
1395 static int io[SBNI_MAX_NUM_CARDS] = { 0 };
1396 static int irq[SBNI_MAX_NUM_CARDS] = { 0 };
1397 static int rxl[SBNI_MAX_NUM_CARDS] = { -1, -1, -1, -1, -1, -1, -1, -1 };
1398 static int baud[SBNI_MAX_NUM_CARDS] = { 0 };
1399 static long mac[SBNI_MAX_NUM_CARDS] = { 0 };
1401 #ifdef v22
1402 MODULE_PARM(io, "1-" __MODULE_STRING(SBNI_MAX_NUM_CARDS) "i");
1403 MODULE_PARM(irq, "1-" __MODULE_STRING(SBNI_MAX_NUM_CARDS) "i");
1404 MODULE_PARM(rxl, "1-" __MODULE_STRING(SBNI_MAX_NUM_CARDS) "i");
1405 MODULE_PARM(baud, "1-" __MODULE_STRING(SBNI_MAX_NUM_CARDS) "i");
1406 MODULE_PARM(mac, "1-" __MODULE_STRING(SBNI_MAX_NUM_CARDS) "i");
1407 #endif
1410 static int sbniautodetect = -1;
1412 static struct net_device dev_sbni[SBNI_MAX_NUM_CARDS] = {
1414 "sbni0",
1415 0, 0, 0, 0, /* memory */
1416 0, 0, /* base, irq */
1417 0, 0, 0, NULL, sbni_probe
1420 "sbni1",
1421 0, 0, 0, 0, /* memory */
1422 0, 0, /* base, irq */
1423 0, 0, 0, NULL, sbni_probe
1426 "sbni2",
1427 0, 0, 0, 0, /* memory */
1428 0, 0, /* base, irq */
1429 0, 0, 0, NULL, sbni_probe
1432 "sbni3",
1433 0, 0, 0, 0, /* memory */
1434 0, 0, /* base, irq */
1435 0, 0, 0, NULL, sbni_probe
1438 "sbni4",
1439 0, 0, 0, 0, /* memory */
1440 0, 0, /* base, irq */
1441 0, 0, 0, NULL, sbni_probe
1444 "sbni5",
1445 0, 0, 0, 0, /* memory */
1446 0, 0, /* base, irq */
1447 0, 0, 0, NULL, sbni_probe
1450 "sbni6",
1451 0, 0, 0, 0, /* memory */
1452 0, 0, /* base, irq */
1453 0, 0, 0, NULL, sbni_probe
1456 "sbni7",
1457 0, 0, 0, 0, /* memory */
1458 0, 0, /* base, irq */
1459 0, 0, 0, NULL, sbni_probe
1463 int init_module(void)
1465 int devices = 0;
1466 int installed = 0;
1467 int i;
1469 /* My simple plug for this huge init_module. "XenON */
1471 if(sbniautodetect != -1)
1473 /* Autodetect mode */
1474 printk("sbni: Autodetect mode (not recommended!) ...\n");
1475 if(!sbniautodetect)
1476 sbniautodetect=SBNI_MAX_NUM_CARDS;
1477 printk("Trying to find %d SBNI cards...\n", sbniautodetect);
1478 if(sbniautodetect > SBNI_MAX_NUM_CARDS)
1480 sbniautodetect = SBNI_MAX_NUM_CARDS;
1481 printk("sbni: You want to detect too many cards. Truncated to %d\n", SBNI_MAX_NUM_CARDS);
1483 for(i = 0; i < sbniautodetect; i++)
1485 if(!register_netdev(&dev_sbni[i]))
1486 installed++;
1488 if(installed)
1489 return 0;
1490 else
1491 return -EIO;
1494 /* Manual mode */
1495 for(i = 0; i < SBNI_MAX_NUM_CARDS; i++)
1497 if((io[i] != 0) || (irq[i] != 0))
1498 devices++;
1500 for(i = 0; i < devices; i++)
1502 dev_sbni[i].irq = irq[i];
1503 dev_sbni[i].base_addr = io[i];
1504 def_rxl = rxl[i];
1505 def_baud = baud[i];
1506 def_mac = mac[i];
1507 if(register_netdev(&dev_sbni[i]))
1508 printk("sbni: card not found!\n");
1509 else
1510 installed++;
1512 if(installed)
1513 return 0;
1514 else
1515 return -EIO;
1518 void cleanup_module(void)
1520 int i;
1521 for(i = 0; i < 4; i++)
1523 if(dev_sbni[i].priv)
1525 free_irq(dev_sbni[i].irq, &dev_sbni[i]);
1526 release_region(dev_sbni[i].base_addr, SBNI_IO_EXTENT);
1527 unregister_netdev(&dev_sbni[i]);
1528 kfree(dev_sbni[i].priv);
1529 dev_sbni[i].priv = NULL;
1533 #endif /* MODULE */