Import 2.3.10pre5
[davej-history.git] / drivers / net / arlan.c
blobd8f9ee74fe92b31295715e3c573f06d0d17cbfd6
1 /*
2 * Copyright (C) 1997 Cullen Jennings
3 * Copyright (C) 1998 Elmer.Joandi@ut.ee, +37-255-13500
4 * Gnu Public License applies
5 * This module provides support for the Arlan 655 card made by Aironet
6 */
8 #include <linux/config.h>
9 #include "arlan.h"
11 static const char *arlan_version = "C.Jennigs 97 & Elmer.Joandi@ut.ee Oct'98, http://www.ylenurme.ee/~elmer/655/";
13 struct device *arlan_device[MAX_ARLANS];
14 int last_arlan = 0;
16 static int SID = SIDUNKNOWN;
17 static int radioNodeId = radioNodeIdUNKNOWN;
18 static char encryptionKey[12] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'};
19 static char *siteName = siteNameUNKNOWN;
20 static int irq = irqUNKNOWN;
21 static int mem = memUNKNOWN;
22 static int arlan_debug = debugUNKNOWN;
23 static int probe = probeUNKNOWN;
24 static int numDevices = numDevicesUNKNOWN;
25 static int testMemory = testMemoryUNKNOWN;
26 static int spreadingCode = spreadingCodeUNKNOWN;
27 static int channelNumber = channelNumberUNKNOWN;
28 static int channelSet = channelSetUNKNOWN;
29 static int systemId = systemIdUNKNOWN;
30 static int registrationMode = registrationModeUNKNOWN;
31 static int txScrambled = 1;
32 static int keyStart = 0;
33 static int mdebug = 0;
34 static int tx_delay_ms = 0;
35 static int retries = 5;
36 static int async = 1;
37 static int tx_queue_len = 1;
38 static int arlan_entry_debug = 0;
39 static int arlan_exit_debug = 0;
40 static int arlan_entry_and_exit_debug = 0;
41 static int arlan_EEPROM_bad = 0;
43 #if LINUX_VERSION_CODE > 0x20100
44 MODULE_PARM(irq, "i");
45 MODULE_PARM(mem, "i");
46 MODULE_PARM(probe, "i");
47 MODULE_PARM(arlan_debug, "i");
48 MODULE_PARM(numDevices, "i");
49 MODULE_PARM(testMemory, "i");
50 MODULE_PARM(spreadingCode, "i");
51 MODULE_PARM(channelNumber, "i");
52 MODULE_PARM(channelSet, "i");
53 MODULE_PARM(systemId, "i");
54 MODULE_PARM(registrationMode, "i");
55 MODULE_PARM(radioNodeId, "i");
56 MODULE_PARM(SID, "i");
57 MODULE_PARM(txScrambled, "i");
58 MODULE_PARM(keyStart, "i");
59 MODULE_PARM(mdebug, "i");
60 MODULE_PARM(tx_delay_ms, "i");
61 MODULE_PARM(retries, "i");
62 MODULE_PARM(async, "i");
63 MODULE_PARM(tx_queue_len, "i");
64 MODULE_PARM(arlan_entry_debug, "i");
65 MODULE_PARM(arlan_exit_debug, "i");
66 MODULE_PARM(arlan_entry_and_exit_debug, "i");
67 MODULE_PARM(arlan_EEPROM_bad, "i");
69 EXPORT_SYMBOL(arlan_device);
70 EXPORT_SYMBOL(last_arlan);
73 // #warning kernel 2.1.110 tested
74 #define myATOMIC_INIT(a,b) atomic_set(&(a),b)
75 #define __initfunctio(a) __initfunc(a)
77 #else
78 #define test_and_set_bit set_bit
79 #define __initfunctio(a) a
80 #if LINUX_VERSION_CODE != 0x20024
81 // #warning kernel 2.0.36 tested
82 #endif
83 #define myATOMIC_INIT(a,b) a = b;
85 #endif
87 struct arlan_conf_stru arlan_conf[MAX_ARLANS];
88 int arlans_found = 0;
90 static int arlan_probe_here(struct device *dev, int ioaddr);
91 static int arlan_open(struct device *dev);
92 static int arlan_tx(struct sk_buff *skb, struct device *dev);
93 static void arlan_interrupt(int irq, void *dev_id, struct pt_regs *regs);
94 static int arlan_close(struct device *dev);
95 static struct enet_statistics *
96 arlan_statistics (struct device *dev);
97 static void arlan_set_multicast (struct device *dev);
98 static int arlan_hw_tx (struct device* dev, char *buf, int length );
99 static int arlan_hw_config (struct device * dev);
100 static void arlan_tx_done_interrupt (struct device * dev, int status);
101 static void arlan_rx_interrupt (struct device * dev, u_char rxStatus, u_short, u_short);
102 static void arlan_process_interrupt (struct device * dev);
103 static int arlan_command(struct device * dev, int command);
105 EXPORT_SYMBOL(arlan_command);
107 extern inline long long arlan_time(void)
109 struct timeval timev;
110 do_gettimeofday(&timev);
111 return ((long long) timev.tv_sec * 1000000 + timev.tv_usec);
114 #ifdef ARLAN_ENTRY_EXIT_DEBUGING
115 #define ARLAN_DEBUG_ENTRY(name) \
117 struct timeval timev;\
118 do_gettimeofday(&timev);\
119 if (arlan_entry_debug || arlan_entry_and_exit_debug)\
120 printk("--->>>" name " %ld " "\n",((long int) timev.tv_sec * 1000000 + timev.tv_usec));\
122 #define ARLAN_DEBUG_EXIT(name) \
124 struct timeval timev;\
125 do_gettimeofday(&timev);\
126 if (arlan_exit_debug || arlan_entry_and_exit_debug)\
127 printk("<<<---" name " %ld " "\n",((long int) timev.tv_sec * 1000000 + timev.tv_usec) );\
129 #else
130 #define ARLAN_DEBUG_ENTRY(name)
131 #define ARLAN_DEBUG_EXIT(name)
132 #endif
135 #define arlan_interrupt_ack(dev)\
136 clearClearInterrupt(dev);\
137 setClearInterrupt(dev);
140 #define ARLAN_COMMAND_LOCK(dev) \
141 if (atomic_dec_and_test(&((struct arlan_private * )dev->priv)->card_users))\
142 arlan_wait_command_complete_short(dev,__LINE__);
143 #define ARLAN_COMMAND_UNLOCK(dev) \
144 atomic_inc(&((struct arlan_private * )dev->priv)->card_users);
147 #define ARLAN_COMMAND_INC(dev) \
148 {((struct arlan_private *) dev->priv)->under_command++;}
149 #define ARLAN_COMMAND_ZERO(dev) \
150 {((struct arlan_private *) dev->priv)->under_command =0;}
151 #define ARLAN_UNDER_COMMAND(dev)\
152 (((struct arlan_private *) dev->priv)->under_command)
154 #define ARLAN_COMMAND_START(dev) ARLAN_COMMAND_INC(dev)
155 #define ARLAN_COMMAND_END(dev) ARLAN_COMMAND_ZERO(dev)
156 #define ARLAN_TOGGLE_START(dev)\
157 {((struct arlan_private *) dev->priv)->under_toggle++;}
158 #define ARLAN_TOGGLE_END(dev)\
159 {((struct arlan_private *) dev->priv)->under_toggle=0;}
160 #define ARLAN_UNDER_TOGGLE(dev)\
161 (((struct arlan_private *) dev->priv)->under_toggle)
165 extern inline int arlan_drop_tx(struct device *dev)
167 struct arlan_private *priv = ((struct arlan_private *) dev->priv);
169 priv->stats.tx_errors++;
170 if (priv->Conf->tx_delay_ms)
172 priv->tx_done_delayed = jiffies + priv->Conf->tx_delay_ms * HZ / 1000 + 1;
174 else
176 priv->waiting_command_mask &= ~ARLAN_COMMAND_TX;
177 TXHEAD(dev).offset = 0;
178 TXTAIL(dev).offset = 0;
179 priv->txLast = 0;
180 priv->txOffset = 0;
181 priv->bad = 0;
182 if (!priv->under_reset && !priv->under_config)
184 dev->tbusy = 0;
185 mark_bh(NET_BH);
188 return 1;
192 static int arlan_command(struct device *dev, int command_p)
195 volatile struct arlan_shmem *arlan = ((struct arlan_private *) dev->priv)->card;
196 struct arlan_conf_stru *conf = ((struct arlan_private *) dev->priv)->Conf;
197 struct arlan_private *priv = (struct arlan_private *) dev->priv;
198 int udelayed = 0;
199 int i = 0;
200 long long time_mks = arlan_time();
202 ARLAN_DEBUG_ENTRY("arlan_command");
204 if (priv->card_polling_interval)
205 priv->card_polling_interval = 1;
207 if (arlan_debug & ARLAN_DEBUG_CHAIN_LOCKS)
208 printk(KERN_DEBUG "arlan_command, %lx lock %x commandByte %x waiting %x incoming %x \n",
209 jiffies, priv->command_lock, READSHMB(arlan->commandByte),
210 priv->waiting_command_mask, command_p);
212 priv->waiting_command_mask |= command_p;
214 if (priv->waiting_command_mask & ARLAN_COMMAND_RESET)
215 if (jiffies - priv->lastReset < 5 * HZ)
216 priv->waiting_command_mask &= ~ARLAN_COMMAND_RESET;
218 if (priv->waiting_command_mask & ARLAN_COMMAND_INT_ACK)
220 arlan_interrupt_ack(dev);
221 priv->waiting_command_mask &= ~ARLAN_COMMAND_INT_ACK;
223 if (priv->waiting_command_mask & ARLAN_COMMAND_INT_ENABLE)
225 setInterruptEnable(dev);
226 priv->waiting_command_mask &= ~ARLAN_COMMAND_INT_ENABLE;
229 /* Card access serializing lock */
231 if (test_and_set_bit(0, (void *) &priv->command_lock))
233 if (arlan_debug & ARLAN_DEBUG_CHAIN_LOCKS)
234 printk(KERN_DEBUG "arlan_command: entered when command locked \n");
235 goto command_busy_end;
237 /* Check cards status and waiting */
239 if (priv->waiting_command_mask & (ARLAN_COMMAND_LONG_WAIT_NOW | ARLAN_COMMAND_WAIT_NOW))
241 while (priv->waiting_command_mask & (ARLAN_COMMAND_LONG_WAIT_NOW | ARLAN_COMMAND_WAIT_NOW))
243 if (READSHMB(arlan->resetFlag) ||
244 READSHMB(arlan->commandByte)) /* ||
245 (readControlRegister(dev) & ARLAN_ACCESS))
247 udelay(40);
248 else
249 priv->waiting_command_mask &= ~(ARLAN_COMMAND_LONG_WAIT_NOW | ARLAN_COMMAND_WAIT_NOW);
251 udelayed++;
253 if (priv->waiting_command_mask & ARLAN_COMMAND_LONG_WAIT_NOW)
255 if (udelayed * 40 > 1000000)
257 printk(KERN_ERR "%s long wait too long \n", dev->name);
258 priv->waiting_command_mask |= ARLAN_COMMAND_RESET;
259 break;
262 else if (priv->waiting_command_mask & ARLAN_COMMAND_WAIT_NOW)
264 if (udelayed * 40 > 1000)
266 printk(KERN_ERR "%s short wait too long \n", dev->name);
267 goto bad_end;
272 else
274 i = 0;
275 while ((READSHMB(arlan->resetFlag) ||
276 READSHMB(arlan->commandByte)) &&
277 conf->pre_Command_Wait > (i++) * 10)
278 udelay(10);
281 if ((READSHMB(arlan->resetFlag) ||
282 READSHMB(arlan->commandByte)) &&
283 !(priv->waiting_command_mask & ARLAN_COMMAND_RESET))
285 goto card_busy_end;
288 if (priv->waiting_command_mask & ARLAN_COMMAND_RESET)
290 priv->under_reset = 1;
291 dev->start = 0;
293 if (priv->waiting_command_mask & ARLAN_COMMAND_CONF)
295 priv->under_config = 1;
296 dev->start = 0;
299 /* Issuing command */
300 arlan_lock_card_access(dev);
301 if (priv->waiting_command_mask & ARLAN_COMMAND_POWERUP)
303 // if (readControlRegister(dev) & (ARLAN_ACCESS && ARLAN_POWER))
304 setPowerOn(dev);
305 arlan_interrupt_lancpu(dev);
306 priv->waiting_command_mask &= ~ARLAN_COMMAND_POWERUP;
307 priv->waiting_command_mask |= ARLAN_COMMAND_RESET;
308 priv->card_polling_interval = HZ / 10;
310 else if (priv->waiting_command_mask & ARLAN_COMMAND_ACTIVATE)
312 WRITESHMB(arlan->commandByte, ARLAN_COM_ACTIVATE);
313 arlan_interrupt_lancpu(dev);
314 priv->waiting_command_mask &= ~ARLAN_COMMAND_ACTIVATE;
315 priv->card_polling_interval = HZ / 10;
317 else if (priv->waiting_command_mask & ARLAN_COMMAND_RX_ABORT)
319 if (priv->rx_command_given)
321 WRITESHMB(arlan->commandByte, ARLAN_COM_RX_ABORT);
322 arlan_interrupt_lancpu(dev);
323 priv->rx_command_given = 0;
325 priv->waiting_command_mask &= ~ARLAN_COMMAND_RX_ABORT;
326 priv->card_polling_interval = 1;
328 else if (priv->waiting_command_mask & ARLAN_COMMAND_TX_ABORT)
330 if (priv->tx_command_given)
332 WRITESHMB(arlan->commandByte, ARLAN_COM_TX_ABORT);
333 arlan_interrupt_lancpu(dev);
334 priv->tx_command_given = 0;
336 priv->waiting_command_mask &= ~ARLAN_COMMAND_TX_ABORT;
337 priv->card_polling_interval = 1;
339 else if (priv->waiting_command_mask & ARLAN_COMMAND_RESET)
341 arlan_drop_tx(dev);
342 if (priv->tx_command_given || priv->rx_command_given)
344 printk(KERN_ERR "%s: Reset under tx or rx command \n", dev->name);
346 if (arlan_debug & ARLAN_DEBUG_RESET)
347 printk(KERN_ERR "%s: Doing chip reset\n", dev->name);
348 priv->lastReset = jiffies;
349 WRITESHM(arlan->commandByte, 0, u_char);
350 /* hold card in reset state */
351 setHardwareReset(dev);
352 /* set reset flag and then release reset */
353 WRITESHM(arlan->resetFlag, 0xff, u_char);
354 clearChannelAttention(dev);
355 clearHardwareReset(dev);
356 priv->numResets++;
357 priv->card_polling_interval = HZ / 4;
358 priv->waiting_command_mask &= ~ARLAN_COMMAND_RESET;
359 priv->waiting_command_mask |= ARLAN_COMMAND_INT_RACK;
360 // priv->waiting_command_mask |= ARLAN_COMMAND_INT_RENABLE;
361 // priv->waiting_command_mask |= ARLAN_COMMAND_RX;
363 else if (priv->waiting_command_mask & ARLAN_COMMAND_INT_RACK)
365 clearHardwareReset(dev);
366 clearClearInterrupt(dev);
367 setClearInterrupt(dev);
368 setInterruptEnable(dev);
369 priv->waiting_command_mask &= ~ARLAN_COMMAND_INT_RACK;
370 priv->waiting_command_mask |= ARLAN_COMMAND_CONF;
371 priv->under_config = 1;
372 priv->under_reset = 0;
374 else if (priv->waiting_command_mask & ARLAN_COMMAND_INT_RENABLE)
376 setInterruptEnable(dev);
377 priv->waiting_command_mask &= ~ARLAN_COMMAND_INT_RENABLE;
379 else if (priv->waiting_command_mask & ARLAN_COMMAND_CONF)
381 if (priv->tx_command_given || priv->rx_command_given)
383 printk(KERN_ERR "%s: Reset under tx or rx command \n", dev->name);
385 dev->start = 0;
386 arlan_drop_tx(dev);
387 setInterruptEnable(dev);
388 arlan_hw_config(dev);
389 arlan_interrupt_lancpu(dev);
390 priv->waiting_command_mask &= ~ARLAN_COMMAND_CONF;
391 priv->card_polling_interval = HZ / 10;
392 // priv->waiting_command_mask |= ARLAN_COMMAND_INT_RACK;
393 // priv->waiting_command_mask |= ARLAN_COMMAND_INT_ENABLE;
394 priv->waiting_command_mask |= ARLAN_COMMAND_CONF_WAIT;
396 else if (priv->waiting_command_mask & ARLAN_COMMAND_CONF_WAIT)
398 if (READSHMB(arlan->configuredStatusFlag) != 0 &&
399 READSHMB(arlan->diagnosticInfo) == 0xff)
401 priv->waiting_command_mask &= ~ARLAN_COMMAND_CONF_WAIT;
402 priv->waiting_command_mask |= ARLAN_COMMAND_RX;
403 priv->card_polling_interval = HZ / 10;
404 priv->tx_command_given = 0;
405 priv->under_config = 0;
406 if (dev->tbusy || !dev->start)
408 dev->tbusy = 0;
409 dev->start = 1;
410 mark_bh(NET_BH);
413 else
415 priv->card_polling_interval = 1;
416 if (arlan_debug & ARLAN_DEBUG_TIMING)
417 printk(KERN_ERR "configure delayed \n");
420 else if (priv->waiting_command_mask & ARLAN_COMMAND_RX)
422 if (!registrationBad(dev))
424 setInterruptEnable(dev);
425 memset_io((void *) arlan->commandParameter, 0, 0xf);
426 WRITESHMB(arlan->commandByte, ARLAN_COM_INT | ARLAN_COM_RX_ENABLE);
427 WRITESHMB(arlan->commandParameter[0], conf->rxParameter);
428 arlan_interrupt_lancpu(dev);
429 priv->rx_command_given;
430 priv->last_rx_time = arlan_time();
431 priv->waiting_command_mask &= ~ARLAN_COMMAND_RX;
432 priv->card_polling_interval = 1;
434 else
435 priv->card_polling_interval = 2;
437 else if (priv->waiting_command_mask & ARLAN_COMMAND_TX)
439 if (!test_and_set_bit(0, (void *) &priv->tx_command_given))
441 if ((time_mks - priv->last_tx_time > conf->rx_tweak1) ||
442 (time_mks - priv->last_rx_int_ack_time < conf->rx_tweak2))
444 setInterruptEnable(dev);
445 memset_io((void *) arlan->commandParameter, 0, 0xf);
446 WRITESHMB(arlan->commandByte, ARLAN_COM_TX_ENABLE | ARLAN_COM_INT);
447 memcpy_toio((void *) arlan->commandParameter, &TXLAST(dev), 14);
448 // for ( i=1 ; i < 15 ; i++) printk("%02x:",READSHMB(arlan->commandParameter[i]));
449 priv->last_command_was_rx = 0;
450 priv->tx_last_sent = jiffies;
451 arlan_interrupt_lancpu(dev);
452 priv->last_tx_time = arlan_time();
453 priv->tx_command_given = 1;
454 priv->waiting_command_mask &= ~ARLAN_COMMAND_TX;
455 priv->card_polling_interval = 1;
457 else
459 priv->tx_command_given = 0;
460 priv->card_polling_interval = 1;
463 else if (arlan_debug & ARLAN_DEBUG_CHAIN_LOCKS)
464 printk(KERN_ERR "tx command when tx chain locked \n");
466 else if (priv->waiting_command_mask & ARLAN_COMMAND_NOOPINT)
469 WRITESHMB(arlan->commandByte, ARLAN_COM_NOP | ARLAN_COM_INT);
471 arlan_interrupt_lancpu(dev);
472 priv->waiting_command_mask &= ~ARLAN_COMMAND_NOOPINT;
473 priv->card_polling_interval = HZ / 3;
475 else if (priv->waiting_command_mask & ARLAN_COMMAND_NOOP)
477 WRITESHMB(arlan->commandByte, ARLAN_COM_NOP);
478 arlan_interrupt_lancpu(dev);
479 priv->waiting_command_mask &= ~ARLAN_COMMAND_NOOP;
480 priv->card_polling_interval = HZ / 3;
482 else if (priv->waiting_command_mask & ARLAN_COMMAND_SLOW_POLL)
484 WRITESHMB(arlan->commandByte, ARLAN_COM_GOTO_SLOW_POLL);
485 arlan_interrupt_lancpu(dev);
486 priv->waiting_command_mask &= ~ARLAN_COMMAND_SLOW_POLL;
487 priv->card_polling_interval = HZ / 3;
489 else if (priv->waiting_command_mask & ARLAN_COMMAND_POWERDOWN)
491 setPowerOff(dev);
492 if (arlan_debug & ARLAN_DEBUG_CARD_STATE)
493 printk(KERN_WARNING "%s: Arlan Going Standby\n", dev->name);
494 priv->waiting_command_mask &= ~ARLAN_COMMAND_POWERDOWN;
495 priv->card_polling_interval = 3 * HZ;
497 arlan_unlock_card_access(dev);
498 for (i = 0; READSHMB(arlan->commandByte) && i < 20; i++)
499 udelay(10);
500 if (READSHMB(arlan->commandByte))
501 if (arlan_debug & ARLAN_DEBUG_CARD_STATE)
502 printk(KERN_ERR "card busy leaving command %x \n", priv->waiting_command_mask);
504 priv->command_lock = 0;
505 ARLAN_DEBUG_EXIT("arlan_command");
506 priv->last_command_buff_free_time = jiffies;
507 return 0;
509 card_busy_end:
510 if (jiffies - priv->last_command_buff_free_time > HZ)
511 priv->waiting_command_mask |= ARLAN_COMMAND_CLEAN_AND_RESET;
513 if (arlan_debug & ARLAN_DEBUG_CARD_STATE)
514 printk(KERN_ERR "%s arlan_command card busy end \n", dev->name);
515 priv->command_lock = 0;
516 ARLAN_DEBUG_EXIT("arlan_command");
517 return 1;
519 bad_end:
520 printk(KERN_ERR "%s arlan_command bad end \n", dev->name);
522 priv->command_lock = 0;
523 ARLAN_DEBUG_EXIT("arlan_command");
525 return -1;
527 command_busy_end:
528 if (arlan_debug & ARLAN_DEBUG_CARD_STATE)
529 printk(KERN_ERR "%s arlan_command command busy end \n", dev->name);
530 ARLAN_DEBUG_EXIT("arlan_command");
531 return 2;
535 extern inline void arlan_command_process(struct device *dev)
537 struct arlan_private *priv = ((struct arlan_private *) dev->priv);
539 int times = 0;
540 while (priv->waiting_command_mask && times < 8)
542 if (priv->waiting_command_mask)
544 if (arlan_command(dev, 0))
545 break;
546 times++;
548 /* if long command, we wont repeat trying */ ;
549 if (priv->card_polling_interval > 1)
550 break;
551 times++;
556 extern inline void arlan_retransmit_now(struct device *dev)
558 struct arlan_private *priv = ((struct arlan_private *) dev->priv);
561 ARLAN_DEBUG_ENTRY("arlan_retransmit_now");
562 if (TXLAST(dev).offset == 0)
564 if (TXHEAD(dev).offset)
566 priv->txLast = 0;
567 IFDEBUG(ARLAN_DEBUG_TX_CHAIN) printk(KERN_DEBUG "TX buff switch to head \n");
570 else if (TXTAIL(dev).offset)
572 IFDEBUG(ARLAN_DEBUG_TX_CHAIN) printk(KERN_DEBUG "TX buff switch to tail \n");
573 priv->txLast = 1;
575 else
576 IFDEBUG(ARLAN_DEBUG_TX_CHAIN) printk(KERN_ERR "ReTransmit buff empty");
577 priv->txOffset = 0;
578 dev->tbusy = 0;
579 mark_bh(NET_BH);
580 return;
583 arlan_command(dev, ARLAN_COMMAND_TX);
585 priv->nof_tx++;
587 priv->Conf->driverRetransmissions++;
588 priv->retransmissions++;
590 IFDEBUG(ARLAN_DEBUG_TX_CHAIN) printk("Retransmit %d bytes \n", TXLAST(dev).length);
592 ARLAN_DEBUG_EXIT("arlan_retransmit_now");
597 static void arlan_registration_timer(unsigned long data)
599 struct device *dev = (struct device *) data;
600 struct arlan_private *priv = (struct arlan_private *) dev->priv;
602 int lostTime = ((int) (jiffies - priv->registrationLastSeen)) * 1000 / HZ;
603 int bh_mark_needed = 0;
604 int next_tick = 1;
607 priv->timer_chain_active = 1;
610 if (registrationBad(dev))
612 //debug=100;
613 priv->registrationLostCount++;
614 if (lostTime > 7000 && lostTime < 7200)
616 printk(KERN_NOTICE "%s registration Lost \n", dev->name);
618 if (lostTime / priv->reRegisterExp > 2000)
619 arlan_command(dev, ARLAN_COMMAND_CLEAN_AND_CONF);
620 if (lostTime / (priv->reRegisterExp) > 3500)
621 arlan_command(dev, ARLAN_COMMAND_CLEAN_AND_RESET);
622 if (priv->reRegisterExp < 400)
623 priv->reRegisterExp += 2;
624 if (lostTime > 7200)
626 next_tick = HZ;
627 arlan_command(dev, ARLAN_COMMAND_CLEAN_AND_RESET);
630 else
632 if (priv->Conf->registrationMode && lostTime > 10000 &&
633 priv->registrationLostCount)
635 printk(KERN_NOTICE "%s registration is back after %d milliseconds\n", dev->name,
636 ((int) (jiffies - priv->registrationLastSeen) * 1000) / HZ);
638 priv->registrationLastSeen = jiffies;
639 priv->registrationLostCount = 0;
640 priv->reRegisterExp = 1;
641 if (dev->start == 0)
643 dev->start = 1;
644 mark_bh(NET_BH);
649 if (!registrationBad(dev) && priv->ReTransmitRequested)
651 IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
652 printk(KERN_ERR "Retranmit from timer \n");
653 priv->ReTransmitRequested = 0;
654 arlan_retransmit_now(dev);
656 if (!registrationBad(dev) &&
657 priv->tx_done_delayed < jiffies &&
658 priv->tx_done_delayed != 0)
660 TXLAST(dev).offset = 0;
661 if (priv->txLast)
662 priv->txLast = 0;
663 else if (TXTAIL(dev).offset)
664 priv->txLast = 1;
665 if (TXLAST(dev).offset)
667 arlan_retransmit_now(dev);
668 dev->trans_start = jiffies;
670 if (!(TXHEAD(dev).offset && TXTAIL(dev).offset))
672 priv->txOffset = 0;
673 dev->tbusy = 0;
674 mark_bh(NET_BH);
676 priv->tx_done_delayed = 0;
677 bh_mark_needed = 1;
679 if (bh_mark_needed)
681 priv->txOffset = 0;
682 dev->tbusy = 0;
683 mark_bh(NET_BH);
685 arlan_process_interrupt(dev);
687 if (next_tick < priv->card_polling_interval)
688 next_tick = priv->card_polling_interval;
690 priv->timer_chain_active = 0;
691 priv->timer.expires = jiffies + next_tick;
693 add_timer(&priv->timer);
699 static void arlan_print_registers(struct device *dev, int line)
701 volatile struct arlan_shmem *arlan = ((struct arlan_private *) dev->priv)->card;
703 u_char hostcpuLock, lancpuLock, controlRegister, cntrlRegImage,
704 txStatus, rxStatus, interruptInProgress, commandByte;
707 ARLAN_DEBUG_ENTRY("arlan_print_registers");
708 READSHM(interruptInProgress, arlan->interruptInProgress, u_char);
709 READSHM(hostcpuLock, arlan->hostcpuLock, u_char);
710 READSHM(lancpuLock, arlan->lancpuLock, u_char);
711 READSHM(controlRegister, arlan->controlRegister, u_char);
712 READSHM(cntrlRegImage, arlan->cntrlRegImage, u_char);
713 READSHM(txStatus, arlan->txStatus, u_char);
714 READSHM(rxStatus, arlan->rxStatus, u_char);
715 READSHM(commandByte, arlan->commandByte, u_char);
717 printk(KERN_WARNING "line %04d IP %02x HL %02x LL %02x CB %02x CR %02x CRI %02x TX %02x RX %02x\n",
718 line, interruptInProgress, hostcpuLock, lancpuLock, commandByte,
719 controlRegister, cntrlRegImage, txStatus, rxStatus);
721 ARLAN_DEBUG_EXIT("arlan_print_registers");
725 static int arlan_hw_tx(struct device *dev, char *buf, int length)
727 int i;
729 struct arlan_private *priv = (struct arlan_private *) dev->priv;
730 volatile struct arlan_shmem *arlan = priv->card;
731 struct arlan_conf_stru *conf = priv->Conf;
733 int tailStarts = 0x800;
734 int headEnds = 0x0;
737 ARLAN_DEBUG_ENTRY("arlan_hw_tx");
738 if (TXHEAD(dev).offset)
739 headEnds = (((TXHEAD(dev).offset + TXHEAD(dev).length - (((int) arlan->txBuffer) - ((int) arlan))) / 64) + 1) * 64;
740 if (TXTAIL(dev).offset)
741 tailStarts = 0x800 - (((TXTAIL(dev).offset - (((int) arlan->txBuffer) - ((int) arlan))) / 64) + 2) * 64;
744 if (!TXHEAD(dev).offset && length < tailStarts)
746 IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
747 printk(KERN_ERR "TXHEAD insert, tailStart %d\n", tailStarts);
749 TXHEAD(dev).offset =
750 (((int) arlan->txBuffer) - ((int) arlan));
751 TXHEAD(dev).length = length - ARLAN_FAKE_HDR_LEN;
752 for (i = 0; i < 6; i++)
753 TXHEAD(dev).dest[i] = buf[i];
754 TXHEAD(dev).clear = conf->txClear;
755 TXHEAD(dev).retries = conf->txRetries; /* 0 is use default */
756 TXHEAD(dev).routing = conf->txRouting;
757 TXHEAD(dev).scrambled = conf->txScrambled;
758 memcpy_toio(((char *) arlan + TXHEAD(dev).offset), buf + ARLAN_FAKE_HDR_LEN, TXHEAD(dev).length);
760 else if (!TXTAIL(dev).offset && length < (0x800 - headEnds))
762 IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
763 printk(KERN_ERR "TXTAIL insert, headEnd %d\n", headEnds);
765 TXTAIL(dev).offset =
766 (((int) arlan->txBuffer) - ((int) arlan)) + 0x800 - (length / 64 + 2) * 64;
767 TXTAIL(dev).length = length - ARLAN_FAKE_HDR_LEN;
768 for (i = 0; i < 6; i++)
769 TXTAIL(dev).dest[i] = buf[i];
770 TXTAIL(dev).clear = conf->txClear;
771 TXTAIL(dev).retries = conf->txRetries;
772 TXTAIL(dev).routing = conf->txRouting;
773 TXTAIL(dev).scrambled = conf->txScrambled;
774 memcpy_toio(((char *) arlan + TXTAIL(dev).offset), buf + ARLAN_FAKE_HDR_LEN, TXTAIL(dev).length);
776 else
778 dev->tbusy = 1;
779 return -1;
780 IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
781 printk(KERN_ERR "TX TAIL & HEAD full, return, tailStart %d headEnd %d\n", tailStarts, headEnds);
783 priv->out_bytes += length;
784 priv->out_bytes10 += length;
785 if (conf->measure_rate < 1)
786 conf->measure_rate = 1;
787 if (jiffies - priv->out_time > conf->measure_rate * HZ)
789 conf->out_speed = priv->out_bytes / conf->measure_rate;
790 priv->out_bytes = 0;
791 priv->out_time = jiffies;
793 if (jiffies - priv->out_time10 > conf->measure_rate * HZ * 10)
795 conf->out_speed10 = priv->out_bytes10 / (10 * conf->measure_rate);
796 priv->out_bytes10 = 0;
797 priv->out_time10 = jiffies;
799 if (TXHEAD(dev).offset && TXTAIL(dev).offset)
801 dev->tbusy = 1;
802 return 0;
804 else
805 dev->tbusy = 0;
808 IFDEBUG(ARLAN_DEBUG_HEADER_DUMP)
809 printk(KERN_WARNING "%s Transmit t %2x:%2x:%2x:%2x:%2x:%2x f %2x:%2x:%2x:%2x:%2x:%2x \n", dev->name,
810 (unsigned char) buf[0], (unsigned char) buf[1], (unsigned char) buf[2], (unsigned char) buf[3],
811 (unsigned char) buf[4], (unsigned char) buf[5], (unsigned char) buf[6], (unsigned char) buf[7],
812 (unsigned char) buf[8], (unsigned char) buf[9], (unsigned char) buf[10], (unsigned char) buf[11]);
814 IFDEBUG(ARLAN_DEBUG_TX_CHAIN) printk(KERN_ERR "TX command prepare for buffer %d\n", priv->txLast);
816 arlan_command(dev, ARLAN_COMMAND_TX);
818 priv->last_command_was_rx = 0;
819 priv->tx_last_sent = jiffies;
820 priv->nof_tx++;
822 IFDEBUG(ARLAN_DEBUG_TX_CHAIN) printk("%s TX Qued %d bytes \n", dev->name, length);
824 ARLAN_DEBUG_EXIT("arlan_hw_tx");
826 return 0;
830 static int arlan_hw_config(struct device *dev)
832 volatile struct arlan_shmem *arlan = ((struct arlan_private *) dev->priv)->card;
833 struct arlan_conf_stru *conf = ((struct arlan_private *) dev->priv)->Conf;
834 struct arlan_private *priv = (struct arlan_private *) dev->priv;
836 ARLAN_DEBUG_ENTRY("arlan_hw_config");
838 printk(KERN_NOTICE "%s arlan configure called \n", dev->name);
839 if (arlan_EEPROM_bad)
840 printk(KERN_NOTICE "arlan configure with eeprom bad option \n");
843 WRITESHM(arlan->spreadingCode, conf->spreadingCode, u_char);
844 WRITESHM(arlan->channelSet, conf->channelSet, u_char);
846 if (arlan_EEPROM_bad)
847 WRITESHM(arlan->defaultChannelSet, conf->channelSet, u_char);
849 WRITESHM(arlan->channelNumber, conf->channelNumber, u_char);
851 WRITESHM(arlan->scramblingDisable, conf->scramblingDisable, u_char);
852 WRITESHM(arlan->txAttenuation, conf->txAttenuation, u_char);
854 WRITESHM(arlan->systemId, conf->systemId, u_int);
856 WRITESHM(arlan->maxRetries, conf->maxRetries, u_char);
857 WRITESHM(arlan->receiveMode, conf->receiveMode, u_char);
858 WRITESHM(arlan->priority, conf->priority, u_char);
859 WRITESHM(arlan->rootOrRepeater, conf->rootOrRepeater, u_char);
860 WRITESHM(arlan->SID, conf->SID, u_int);
862 WRITESHM(arlan->registrationMode, conf->registrationMode, u_char);
864 WRITESHM(arlan->registrationFill, conf->registrationFill, u_char);
865 WRITESHM(arlan->localTalkAddress, conf->localTalkAddress, u_char);
866 WRITESHM(arlan->codeFormat, conf->codeFormat, u_char);
867 WRITESHM(arlan->numChannels, conf->numChannels, u_char);
868 WRITESHM(arlan->channel1, conf->channel1, u_char);
869 WRITESHM(arlan->channel2, conf->channel2, u_char);
870 WRITESHM(arlan->channel3, conf->channel3, u_char);
871 WRITESHM(arlan->channel4, conf->channel4, u_char);
872 WRITESHM(arlan->radioNodeId, conf->radioNodeId, u_short);
873 WRITESHM(arlan->SID, conf->SID, u_int);
874 WRITESHM(arlan->waitTime, conf->waitTime, u_short);
875 WRITESHM(arlan->lParameter, conf->lParameter, u_short);
876 memcpy_toio(&(arlan->_15), &(conf->_15), 3);
877 WRITESHM(arlan->_15, conf->_15, u_short);
878 WRITESHM(arlan->headerSize, conf->headerSize, u_short);
879 if (arlan_EEPROM_bad)
880 WRITESHM(arlan->hardwareType, conf->hardwareType, u_char);
881 WRITESHM(arlan->radioType, conf->radioType, u_char);
882 if (arlan_EEPROM_bad)
883 WRITESHM(arlan->radioModule, conf->radioType, u_char);
885 memcpy_toio(arlan->encryptionKey + keyStart, encryptionKey, 8);
886 memcpy_toio(arlan->name, conf->siteName, 16);
888 WRITESHMB(arlan->commandByte, ARLAN_COM_INT | ARLAN_COM_CONF); /* do configure */
889 memset_io(arlan->commandParameter, 0, 0xf); /* 0xf */
890 memset_io(arlan->commandParameter + 1, 0, 2);
891 if (conf->writeEEPROM)
893 memset_io(arlan->commandParameter, conf->writeEEPROM, 1);
894 // conf->writeEEPROM=0;
896 if (conf->registrationMode && conf->registrationInterrupts)
897 memset_io(arlan->commandParameter + 3, 1, 1);
898 else
899 memset_io(arlan->commandParameter + 3, 0, 1);
901 priv->irq_test_done = 0;
903 if (conf->tx_queue_len)
904 dev->tx_queue_len = conf->tx_queue_len;
905 udelay(100);
907 ARLAN_DEBUG_EXIT("arlan_hw_config");
908 return 0;
912 static int arlan_read_card_configuration(struct device *dev)
914 u_char tlx415;
915 volatile struct arlan_shmem *arlan = ((struct arlan_private *) dev->priv)->card;
916 struct arlan_conf_stru *conf = ((struct arlan_private *) dev->priv)->Conf;
918 ARLAN_DEBUG_ENTRY("arlan_read_card_configuration");
920 if (radioNodeId == radioNodeIdUNKNOWN)
922 READSHM(conf->radioNodeId, arlan->radioNodeId, u_short);
924 else
925 conf->radioNodeId = radioNodeId;
927 if (SID == SIDUNKNOWN)
929 READSHM(conf->SID, arlan->SID, u_int);
931 else conf->SID = SID;
933 if (spreadingCode == spreadingCodeUNKNOWN)
935 READSHM(conf->spreadingCode, arlan->spreadingCode, u_char);
937 else
938 conf->spreadingCode = spreadingCode;
940 if (channelSet == channelSetUNKNOWN)
942 READSHM(conf->channelSet, arlan->channelSet, u_char);
944 else conf->channelSet = channelSet;
946 if (channelNumber == channelNumberUNKNOWN)
948 READSHM(conf->channelNumber, arlan->channelNumber, u_char);
950 else conf->channelNumber = channelNumber;
952 READSHM(conf->scramblingDisable, arlan->scramblingDisable, u_char);
953 READSHM(conf->txAttenuation, arlan->txAttenuation, u_char);
955 if (systemId == systemIdUNKNOWN)
957 READSHM(conf->systemId, arlan->systemId, u_int);
959 else conf->systemId = systemId;
961 READSHM(conf->maxDatagramSize, arlan->maxDatagramSize, u_short);
962 READSHM(conf->maxFrameSize, arlan->maxFrameSize, u_short);
963 READSHM(conf->maxRetries, arlan->maxRetries, u_char);
964 READSHM(conf->receiveMode, arlan->receiveMode, u_char);
965 READSHM(conf->priority, arlan->priority, u_char);
966 READSHM(conf->rootOrRepeater, arlan->rootOrRepeater, u_char);
968 if (SID == SIDUNKNOWN)
970 READSHM(conf->SID, arlan->SID, u_int);
972 else conf->SID = SID;
974 if (registrationMode == registrationModeUNKNOWN)
976 READSHM(conf->registrationMode, arlan->registrationMode, u_char);
978 else conf->registrationMode = registrationMode;
980 READSHM(conf->registrationFill, arlan->registrationFill, u_char);
981 READSHM(conf->localTalkAddress, arlan->localTalkAddress, u_char);
982 READSHM(conf->codeFormat, arlan->codeFormat, u_char);
983 READSHM(conf->numChannels, arlan->numChannels, u_char);
984 READSHM(conf->channel1, arlan->channel1, u_char);
985 READSHM(conf->channel2, arlan->channel2, u_char);
986 READSHM(conf->channel3, arlan->channel3, u_char);
987 READSHM(conf->channel4, arlan->channel4, u_char);
988 READSHM(conf->waitTime, arlan->waitTime, u_short);
989 READSHM(conf->lParameter, arlan->lParameter, u_short);
990 READSHM(conf->_15, arlan->_15, u_short);
991 READSHM(conf->headerSize, arlan->headerSize, u_short);
992 READSHM(conf->hardwareType, arlan->hardwareType, u_char);
993 READSHM(conf->radioType, arlan->radioModule, u_char);
995 if (conf->radioType == 0)
996 conf->radioType = 0xc;
998 WRITESHM(arlan->configStatus, 0xA5, u_char);
999 READSHM(tlx415, arlan->configStatus, u_char);
1001 if (tlx415 != 0xA5)
1002 printk(KERN_INFO "%s tlx415 chip \n", dev->name);
1004 conf->txClear = 0;
1005 conf->txRetries = 1;
1006 conf->txRouting = 1;
1007 conf->txScrambled = 0;
1008 conf->rxParameter = 1;
1009 conf->txTimeoutMs = 4000;
1010 conf->waitCardTimeout = 100000;
1011 conf->receiveMode = ARLAN_RCV_CLEAN;
1012 memcpy_fromio(conf->siteName, arlan->name, 16);
1013 conf->siteName[16] = '\0';
1014 conf->retries = retries;
1015 conf->tx_delay_ms = tx_delay_ms;
1016 conf->async = async;
1017 conf->ReTransmitPacketMaxSize = 200;
1018 conf->waitReTransmitPacketMaxSize = 200;
1019 conf->txAckTimeoutMs = 900;
1020 conf->fastReTransCount = 3;
1022 ARLAN_DEBUG_EXIT("arlan_read_card_configuration");
1024 return 0;
1028 static int lastFoundAt = 0xbe000;
1032 * This is the real probe routine. Linux has a history of friendly device
1033 * probes on the ISA bus. A good device probes avoids doing writes, and
1034 * verifies that the correct device exists and functions.
1037 __initfunctio(static int arlan_check_fingerprint(int memaddr))
1039 static char probeText[] = "TELESYSTEM SLW INC. ARLAN \0";
1040 char tempBuf[49];
1041 volatile struct arlan_shmem *arlan = (struct arlan_shmem *) memaddr;
1043 ARLAN_DEBUG_ENTRY("arlan_check_fingerprint");
1044 memcpy_fromio(tempBuf, arlan->textRegion, 29);
1045 tempBuf[30] = 0;
1047 /* check for card at this address */
1048 if (0 != strncmp(tempBuf, probeText, 29))
1049 return -ENODEV;
1051 // printk(KERN_INFO "arlan found at 0x%x \n",memaddr);
1052 ARLAN_DEBUG_EXIT("arlan_check_fingerprint");
1054 return 0;
1059 __initfunctio(int arlan_probe_everywhere(struct device *dev))
1061 int m;
1062 int probed = 0;
1063 int found = 0;
1065 ARLAN_DEBUG_ENTRY("arlan_probe_everywhere");
1066 if (mem != 0 && numDevices == 1) /* Check a single specified location. */
1068 if (arlan_probe_here(dev, mem) == 0)
1069 return 0;
1070 else
1071 return -ENODEV;
1073 for (m = lastFoundAt + 0x2000; m <= 0xDE000; m += 0x2000)
1075 if (arlan_probe_here(dev, m) == 0)
1077 found++;
1078 lastFoundAt = m;
1079 break;
1081 probed++;
1083 if (found == 0 && probed != 0)
1085 if (lastFoundAt == 0xbe000)
1086 printk(KERN_ERR "arlan: No Arlan devices found \n");
1087 return ENODEV;
1089 else
1090 return 0;
1092 ARLAN_DEBUG_EXIT("arlan_probe_everywhere");
1094 return ENODEV;
1097 __initfunctio(int arlan_find_devices(void))
1099 int m;
1100 int found = 0;
1102 ARLAN_DEBUG_ENTRY("arlan_find_devices");
1103 if (mem != 0 && numDevices == 1) /* Check a single specified location. */
1104 return 1;
1105 for (m = 0xc000; m <= 0xDE000; m += 0x2000)
1107 if (arlan_check_fingerprint(m) == 0)
1108 found++;
1110 ARLAN_DEBUG_EXIT("arlan_find_devices");
1112 return found;
1116 static int arlan_change_mtu(struct device *dev, int new_mtu)
1118 struct arlan_conf_stru *conf = ((struct arlan_private *) dev->priv)->Conf;
1120 ARLAN_DEBUG_ENTRY("arlan_change_mtu");
1121 if ((new_mtu < 68) || (new_mtu > 2032))
1122 return -EINVAL;
1123 dev->mtu = new_mtu;
1124 if (new_mtu < 256)
1125 new_mtu = 256; /* cards book suggests 1600 */
1126 conf->maxDatagramSize = new_mtu;
1127 conf->maxFrameSize = new_mtu + 48;
1129 arlan_command(dev, ARLAN_COMMAND_CLEAN_AND_CONF);
1130 printk(KERN_NOTICE "%s mtu changed to %d \n", dev->name, new_mtu);
1132 ARLAN_DEBUG_EXIT("arlan_change_mtu");
1134 return 0;
1137 static int arlan_mac_addr(struct device *dev, void *p)
1139 struct sockaddr *addr = p;
1142 ARLAN_DEBUG_ENTRY("arlan_mac_addr");
1143 return -EINVAL;
1145 if (dev->start)
1146 return -EBUSY;
1147 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
1149 ARLAN_DEBUG_EXIT("arlan_mac_addr");
1150 return 0;
1156 __initfunctio(static int
1157 arlan_allocate_device(int num, struct device *devs))
1160 struct device *dev;
1162 ARLAN_DEBUG_ENTRY("arlan_allocate_device");
1164 if (!devs)
1165 dev = init_etherdev(0, sizeof(struct arlan_private));
1166 else
1168 dev = devs;
1169 dev->priv = kmalloc(sizeof(struct arlan_private), GFP_KERNEL);
1172 if (dev == NULL || dev->priv == NULL)
1174 printk(KERN_CRIT "init_etherdev failed ");
1175 return 0;
1177 ((struct arlan_private *) dev->priv)->conf =
1178 kmalloc(sizeof(struct arlan_shmem), GFP_KERNEL);
1180 if (dev == NULL || dev->priv == NULL ||
1181 ((struct arlan_private *) dev->priv)->conf == NULL)
1183 return 0;
1184 printk(KERN_CRIT " No memory at arlan_allocate_device \n");
1186 /* Fill in the 'dev' fields. */
1187 dev->base_addr = 0;
1188 dev->mem_start = 0;
1189 dev->mem_end = 0;
1190 dev->mtu = 1500;
1191 dev->flags = 0; /* IFF_BROADCAST & IFF_MULTICAST & IFF_PROMISC; */
1192 dev->irq = 0;
1193 dev->dma = 0;
1194 dev->tx_queue_len = tx_queue_len;
1195 ether_setup(dev);
1196 dev->tx_queue_len = tx_queue_len;
1197 dev->open = arlan_open;
1198 dev->stop = arlan_close;
1199 dev->hard_start_xmit = arlan_tx;
1200 dev->get_stats = arlan_statistics;
1201 dev->set_multicast_list = arlan_set_multicast;
1202 dev->change_mtu = arlan_change_mtu;
1203 dev->set_mac_address = arlan_mac_addr;
1204 ((struct arlan_private *) dev->priv)->irq_test_done = 0;
1205 arlan_device[num] = dev;
1206 ((struct arlan_private *) arlan_device[num]->priv)->Conf = &(arlan_conf[num]);
1208 ((struct arlan_private *) dev->priv)->Conf->pre_Command_Wait = 40;
1209 ((struct arlan_private *) dev->priv)->Conf->rx_tweak1 = 30;
1210 ((struct arlan_private *) dev->priv)->Conf->rx_tweak2 = 0;
1212 ARLAN_DEBUG_EXIT("arlan_allocate_device");
1213 return (int) dev;
1217 __initfunctio(int arlan_probe_here(struct device *dev, int memaddr))
1219 volatile struct arlan_shmem *arlan;
1221 ARLAN_DEBUG_ENTRY("arlan_probe_here");
1223 if (arlan_check_fingerprint(memaddr))
1224 return -ENODEV;
1226 printk(KERN_NOTICE "%s: Arlan found at %#5x, \n ", dev->name, memaddr);
1228 if (!arlan_allocate_device(arlans_found, dev))
1229 return -1;
1231 ((struct arlan_private *) dev->priv)->card = (struct arlan_shmem *) memaddr;
1232 arlan = (void *) memaddr;
1234 dev->mem_start = memaddr;
1235 dev->mem_end = memaddr + 0x1FFF;
1237 if (dev->irq < 2)
1239 READSHM(dev->irq, arlan->irqLevel, u_char);
1240 } else if (dev->irq == 2)
1241 dev->irq = 9;
1243 arlan_read_card_configuration(dev);
1245 ARLAN_DEBUG_EXIT("arlan_probe_here");
1246 return 0;
1252 static int arlan_open(struct device *dev)
1254 struct arlan_private *priv = (struct arlan_private *) dev->priv;
1255 volatile struct arlan_shmem *arlan = priv->card;
1256 int ret = 0;
1258 ARLAN_DEBUG_ENTRY("arlan_open");
1260 if (dev->mem_start == 0)
1261 ret = arlan_probe_everywhere(dev);
1262 if (ret != 0)
1263 return ret;
1265 arlan = ((struct arlan_private *) dev->priv)->card;
1267 if (request_irq(dev->irq, &arlan_interrupt, 0, dev->name, dev))
1269 printk(KERN_ERR "%s: unable to get IRQ %d .\n",
1270 dev->name, dev->irq);
1271 return -EAGAIN;
1273 arlan_command(dev, ARLAN_COMMAND_POWERUP | ARLAN_COMMAND_LONG_WAIT_NOW);
1275 priv->bad = 0;
1276 priv->lastReset = 0;
1277 priv->reset = 0;
1278 priv->open_time = jiffies;
1279 memcpy_fromio(dev->dev_addr, arlan->lanCardNodeId, 6);
1280 memset(dev->broadcast, 0xff, 6);
1281 dev->tbusy = 1;
1282 priv->txOffset = 0;
1283 dev->interrupt = 0;
1284 dev->start = 1;
1285 dev->tx_queue_len = tx_queue_len;
1286 init_timer(&priv->timer);
1287 priv->timer.expires = jiffies + HZ / 10;
1288 priv->timer.data = (unsigned long) dev;
1289 priv->timer.function = &arlan_registration_timer; /* timer handler */
1290 priv->interrupt_processing_active = 0;
1291 priv->command_lock = 0;
1292 add_timer(&priv->timer);
1294 init_mutex(&priv->card_lock);
1295 myATOMIC_INIT(priv->card_users, 1); /* damn 2.0.33 */
1296 priv->registrationLostCount = 0;
1297 priv->registrationLastSeen = jiffies;
1298 priv->txLast = 0;
1299 priv->tx_command_given = 0;
1301 priv->reRegisterExp = 1;
1302 priv->nof_tx = 0;
1303 priv->nof_tx_ack = 0;
1304 priv->last_command_was_rx = 0;
1305 priv->tx_last_sent = jiffies - 1;
1306 priv->tx_last_cleared = jiffies;
1307 priv->Conf->writeEEPROM = 0;
1308 priv->Conf->registrationInterrupts = 1;
1310 dev->tbusy = 0;
1312 MOD_INC_USE_COUNT;
1313 #ifdef CONFIG_PROC_FS
1314 #ifndef MODULE
1315 if (arlan_device[0])
1316 init_arlan_proc();
1317 #endif
1318 #endif
1319 ARLAN_DEBUG_EXIT("arlan_open");
1320 return 0;
1326 static int arlan_tx(struct sk_buff *skb, struct device *dev)
1328 struct arlan_private *priv = ((struct arlan_private *) dev->priv);
1329 struct arlan_conf_stru *conf = ((struct arlan_private *) dev->priv)->Conf;
1331 ARLAN_DEBUG_ENTRY("arlan_tx");
1333 if (dev->tbusy)
1336 * If we get here, some higher level has decided we are broken.
1337 * There should really be a "kick me" function call instead.
1339 int tickssofar = jiffies - dev->trans_start;
1341 if (((tickssofar * 1000) / HZ) * 2 > conf->txTimeoutMs)
1342 arlan_command(dev, ARLAN_COMMAND_TX_ABORT);
1344 if (((tickssofar * 1000) / HZ) < conf->txTimeoutMs)
1346 // up(&priv->card_lock);
1347 goto bad_end;
1349 printk(KERN_ERR "%s: arlan transmit timed out, kernel decided\n", dev->name);
1350 /* Try to restart the adaptor. */
1351 arlan_command(dev, ARLAN_COMMAND_CLEAN_AND_RESET);
1352 dev->trans_start = jiffies;
1353 goto bad_end;
1357 * Block a timer-based transmit from overlapping. This could better be
1358 * done with atomic_swap(1, dev->tbusy), but set_bit() works as well.
1360 if (test_and_set_bit(0, (void *) &dev->tbusy) != 0)
1362 printk(KERN_ERR "%s: Transmitter access conflict.\n",
1363 dev->name);
1365 else
1367 short length;
1368 unsigned char *buf;
1371 * If some higher layer thinks we've missed an tx-done interrupt
1372 * we are passed NULL. Caution: dev_tint() handles the cli()/sti()
1373 * itself.
1376 length = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
1377 buf = skb->data;
1379 if (priv->txOffset + length + 0x12 > 0x800)
1380 printk(KERN_ERR "TX RING overflow \n");
1382 if (arlan_hw_tx(dev, buf, length) == -1)
1383 goto bad_end;
1385 dev->trans_start = jiffies;
1387 dev_kfree_skb(skb);
1389 arlan_process_interrupt(dev);
1390 priv->tx_chain_active = 0;
1391 ARLAN_DEBUG_EXIT("arlan_tx");
1392 return 0;
1394 bad_end:
1395 arlan_process_interrupt(dev);
1396 priv->tx_chain_active = 0;
1397 ARLAN_DEBUG_EXIT("arlan_tx");
1398 return 1;
1402 extern inline int DoNotReTransmitCrap(struct device *dev)
1404 struct arlan_private *priv = ((struct arlan_private *) dev->priv);
1406 if (TXLAST(dev).length < priv->Conf->ReTransmitPacketMaxSize)
1407 return 1;
1408 return 0;
1412 extern inline int DoNotWaitReTransmitCrap(struct device *dev)
1414 struct arlan_private *priv = ((struct arlan_private *) dev->priv);
1416 if (TXLAST(dev).length < priv->Conf->waitReTransmitPacketMaxSize)
1417 return 1;
1418 return 0;
1421 extern inline void arlan_queue_retransmit(struct device *dev)
1423 struct arlan_private *priv = ((struct arlan_private *) dev->priv);
1425 ARLAN_DEBUG_ENTRY("arlan_queue_retransmit");
1427 if (DoNotWaitReTransmitCrap(dev))
1429 arlan_drop_tx(dev);
1430 } else
1431 priv->ReTransmitRequested++;
1433 ARLAN_DEBUG_EXIT("arlan_queue_retransmit");
1436 extern inline void RetryOrFail(struct device *dev)
1438 struct arlan_private *priv = ((struct arlan_private *) dev->priv);
1440 ARLAN_DEBUG_ENTRY("RetryOrFail");
1442 if (priv->retransmissions > priv->Conf->retries ||
1443 DoNotReTransmitCrap(dev))
1445 arlan_drop_tx(dev);
1447 else if (priv->bad <= priv->Conf->fastReTransCount)
1449 arlan_retransmit_now(dev);
1451 else arlan_queue_retransmit(dev);
1453 ARLAN_DEBUG_EXIT("RetryOrFail");
1457 static void arlan_tx_done_interrupt(struct device *dev, int status)
1459 struct arlan_private *priv = ((struct arlan_private *) dev->priv);
1461 ARLAN_DEBUG_ENTRY("arlan_tx_done_interrupt");
1463 priv->tx_last_cleared = jiffies;
1464 priv->tx_command_given = 0;
1465 priv->nof_tx_ack++;
1466 switch (status)
1468 case 1:
1470 IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
1471 printk("arlan intr: transmit OK\n");
1472 priv->stats.tx_packets++;
1473 priv->bad = 0;
1474 priv->reset = 0;
1475 priv->retransmissions = 0;
1476 if (priv->Conf->tx_delay_ms)
1478 priv->tx_done_delayed = jiffies + (priv->Conf->tx_delay_ms * HZ) / 1000 + 1;;
1480 else
1482 TXLAST(dev).offset = 0;
1483 if (priv->txLast)
1484 priv->txLast = 0;
1485 else if (TXTAIL(dev).offset)
1486 priv->txLast = 1;
1487 if (TXLAST(dev).offset)
1489 arlan_retransmit_now(dev);
1490 dev->trans_start = jiffies;
1492 if (!TXHEAD(dev).offset || !TXTAIL(dev).offset)
1494 priv->txOffset = 0;
1495 dev->tbusy = 0;
1496 mark_bh(NET_BH);
1500 break;
1502 case 2:
1504 IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
1505 printk("arlan intr: transmit timed out\n");
1506 priv->bad += 1;
1507 //arlan_queue_retransmit(dev);
1508 RetryOrFail(dev);
1510 break;
1512 case 3:
1514 IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
1515 printk("arlan intr: transmit max retries\n");
1516 priv->bad += 1;
1517 priv->reset = 0;
1518 //arlan_queue_retransmit(dev);
1519 RetryOrFail(dev);
1521 break;
1523 case 4:
1525 IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
1526 printk("arlan intr: transmit aborted\n");
1527 priv->bad += 1;
1528 arlan_queue_retransmit(dev);
1529 //RetryOrFail(dev);
1531 break;
1533 case 5:
1535 IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
1536 printk("arlan intr: transmit not registered\n");
1537 priv->bad += 1;
1538 //debug=101;
1539 arlan_queue_retransmit(dev);
1541 break;
1543 case 6:
1545 IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
1546 printk("arlan intr: transmit destination full\n");
1547 priv->bad += 1;
1548 priv->reset = 0;
1549 //arlan_drop_tx(dev);
1550 arlan_queue_retransmit(dev);
1552 break;
1554 case 7:
1556 IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
1557 printk("arlan intr: transmit unknown ack\n");
1558 priv->bad += 1;
1559 priv->reset = 0;
1560 arlan_queue_retransmit(dev);
1562 break;
1564 case 8:
1566 IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
1567 printk("arlan intr: transmit dest mail box full\n");
1568 priv->bad += 1;
1569 priv->reset = 0;
1570 //arlan_drop_tx(dev);
1571 arlan_queue_retransmit(dev);
1573 break;
1575 case 9:
1577 IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
1578 printk("arlan intr: transmit root dest not reg.\n");
1579 priv->bad += 1;
1580 priv->reset = 1;
1581 //arlan_drop_tx(dev);
1582 arlan_queue_retransmit(dev);
1584 break;
1586 default:
1588 printk(KERN_ERR "arlan intr: transmit status unknown\n");
1589 priv->bad += 1;
1590 priv->reset = 1;
1591 arlan_drop_tx(dev);
1595 ARLAN_DEBUG_EXIT("arlan_tx_done_interrupt");
1599 static void arlan_rx_interrupt(struct device *dev, u_char rxStatus, u_short rxOffset, u_short pkt_len)
1601 char *skbtmp;
1602 int i = 0;
1604 struct arlan_private *priv = (struct arlan_private *) dev->priv;
1605 volatile struct arlan_shmem *arlan = priv->card;
1606 struct arlan_conf_stru *conf = priv->Conf;
1609 ARLAN_DEBUG_ENTRY("arlan_rx_interrupt");
1610 // by spec, not WRITESHMB(arlan->rxStatus,0x00);
1611 // prohibited here arlan_command(dev, ARLAN_COMMAND_RX);
1613 if (pkt_len < 10 || pkt_len > 2048)
1615 printk(KERN_WARNING "%s: got too short or long packet, len %d \n", dev->name, pkt_len);
1616 return;
1618 if (rxOffset + pkt_len > 0x2000)
1620 printk("%s: got too long packet, len %d offset %x\n", dev->name, pkt_len, rxOffset);
1621 return;
1623 priv->in_bytes += pkt_len;
1624 priv->in_bytes10 += pkt_len;
1625 if (conf->measure_rate < 1)
1626 conf->measure_rate = 1;
1627 if (jiffies - priv->in_time > conf->measure_rate * HZ)
1629 conf->in_speed = priv->in_bytes / conf->measure_rate;
1630 priv->in_bytes = 0;
1631 priv->in_time = jiffies;
1633 if (jiffies - priv->in_time10 > conf->measure_rate * HZ * 10)
1635 conf->in_speed10 = priv->in_bytes10 / (10 * conf->measure_rate);
1636 priv->in_bytes10 = 0;
1637 priv->in_time10 = jiffies;
1639 DEBUGSHM(1, "arlan rcv pkt rxStatus= %d ", arlan->rxStatus, u_char);
1640 switch (rxStatus)
1642 case 1:
1643 case 2:
1644 case 3:
1646 /* Malloc up new buffer. */
1647 struct sk_buff *skb;
1649 DEBUGSHM(50, "arlan recv pkt offs=%d\n", arlan->rxOffset, u_short);
1650 DEBUGSHM(1, "arlan rxFrmType = %d \n", arlan->rxFrmType, u_char);
1651 DEBUGSHM(1, KERN_INFO "arlan rx scrambled = %d \n", arlan->scrambled, u_char);
1653 /* here we do multicast filtering to avoid slow 8-bit memcopy */
1654 #ifdef ARLAN_MULTICAST
1655 if (!(dev->flags & IFF_ALLMULTI) &&
1656 !(dev->flags & IFF_PROMISC) &&
1657 dev->mc_list)
1659 char hw_dst_addr[6];
1660 struct dev_mc_list *dmi = dev->mc_list;
1661 int i;
1663 memcpy_fromio(hw_dst_addr, arlan->ultimateDestAddress, 6);
1664 if (hw_dst_addr[0] == 0x01)
1666 if (mdebug)
1667 if (hw_dst_addr[1] == 0x00)
1668 printk(KERN_ERR "%s mcast 0x0100 \n", dev->name);
1669 else if (hw_dst_addr[1] == 0x40)
1670 printk(KERN_ERR "%s m/bcast 0x0140 \n", dev->name);
1671 while (dmi)
1672 { if (dmi->dmi_addrlen == 6)
1674 if (arlan_debug & ARLAN_DEBUG_HEADER_DUMP)
1675 printk(KERN_ERR "%s mcl %2x:%2x:%2x:%2x:%2x:%2x \n", dev->name,
1676 dmi->dmi_addr[0], dmi->dmi_addr[1], dmi->dmi_addr[2],
1677 dmi->dmi_addr[3], dmi->dmi_addr[4], dmi->dmi_addr[5]);
1678 for (i = 0; i < 6; i++)
1679 if (dmi->dmi_addr[i] != hw_dst_addr[i])
1680 break;
1681 if (i == 6)
1682 break;
1684 else
1685 printk(KERN_ERR "%s: invalid multicast address length given.\n", dev->name);
1686 dmi = dmi->next;
1688 /* we reach here if multicast filtering is on and packet
1689 * is multicast and not for receive */
1690 goto end_of_interupt;
1693 #endif // ARLAN_MULTICAST
1694 /* multicast filtering ends here */
1695 pkt_len += ARLAN_FAKE_HDR_LEN;
1697 skb = dev_alloc_skb(pkt_len + 4);
1698 if (skb == NULL)
1700 printk(KERN_ERR "%s: Memory squeeze, dropping packet.\n", dev->name);
1701 priv->stats.rx_dropped++;
1702 break;
1704 skb_reserve(skb, 2);
1705 skb->dev = dev;
1706 skbtmp = skb_put(skb, pkt_len);
1708 memcpy_fromio(skbtmp + ARLAN_FAKE_HDR_LEN, ((char *) arlan) + rxOffset, pkt_len - ARLAN_FAKE_HDR_LEN);
1709 memcpy_fromio(skbtmp, arlan->ultimateDestAddress, 6);
1710 memcpy_fromio(skbtmp + 6, arlan->rxSrc, 6);
1711 WRITESHMB(arlan->rxStatus, 0x00);
1712 arlan_command(dev, ARLAN_COMMAND_RX);
1714 IFDEBUG(ARLAN_DEBUG_HEADER_DUMP)
1716 char immedDestAddress[6];
1717 char immedSrcAddress[6];
1718 memcpy_fromio(immedDestAddress, arlan->immedDestAddress, 6);
1719 memcpy_fromio(immedSrcAddress, arlan->immedSrcAddress, 6);
1721 printk(KERN_WARNING "%s t %2x:%2x:%2x:%2x:%2x:%2x f %2x:%2x:%2x:%2x:%2x:%2x imd %2x:%2x:%2x:%2x:%2x:%2x ims %2x:%2x:%2x:%2x:%2x:%2x\n", dev->name,
1722 (unsigned char) skbtmp[0], (unsigned char) skbtmp[1], (unsigned char) skbtmp[2], (unsigned char) skbtmp[3],
1723 (unsigned char) skbtmp[4], (unsigned char) skbtmp[5], (unsigned char) skbtmp[6], (unsigned char) skbtmp[7],
1724 (unsigned char) skbtmp[8], (unsigned char) skbtmp[9], (unsigned char) skbtmp[10], (unsigned char) skbtmp[11],
1725 immedDestAddress[0], immedDestAddress[1], immedDestAddress[2],
1726 immedDestAddress[3], immedDestAddress[4], immedDestAddress[5],
1727 immedSrcAddress[0], immedSrcAddress[1], immedSrcAddress[2],
1728 immedSrcAddress[3], immedSrcAddress[4], immedSrcAddress[5]);
1730 skb->protocol = eth_type_trans(skb, dev);
1731 IFDEBUG(ARLAN_DEBUG_HEADER_DUMP)
1732 if (skb->protocol != 0x608 && skb->protocol != 0x8)
1734 for (i = 0; i <= 22; i++)
1735 printk("%02x:", (u_char) skbtmp[i + 12]);
1736 printk(KERN_ERR "\n");
1737 printk(KERN_WARNING "arlan kernel pkt type trans %x \n", skb->protocol);
1739 netif_rx(skb);
1740 priv->stats.rx_packets++;
1742 break;
1744 default:
1745 printk(KERN_ERR "arlan intr: recieved unknown status\n");
1746 priv->stats.rx_crc_errors++;
1747 break;
1749 ARLAN_DEBUG_EXIT("arlan_rx_interrupt");
1752 static void arlan_process_interrupt(struct device *dev)
1754 struct arlan_private *priv = (struct arlan_private *) dev->priv;
1755 volatile struct arlan_shmem *arlan = priv->card;
1756 u_char rxStatus = READSHMB(arlan->rxStatus);
1757 u_char txStatus = READSHMB(arlan->txStatus);
1758 u_short rxOffset = READSHMS(arlan->rxOffset);
1759 u_short pkt_len = READSHMS(arlan->rxLength);
1760 int interrupt_count = 0;
1762 ARLAN_DEBUG_ENTRY("arlan_process_interrupt");
1764 if (test_and_set_bit(0, (void *) &priv->interrupt_processing_active))
1766 if (arlan_debug & ARLAN_DEBUG_CHAIN_LOCKS)
1767 printk(KERN_ERR "interrupt chain reentering \n");
1768 goto end_int_process;
1770 while ((rxStatus || txStatus || priv->interrupt_ack_requested)
1771 && (interrupt_count < 5))
1773 if (rxStatus)
1774 priv->last_rx_int_ack_time = arlan_time();
1776 arlan_command(dev, ARLAN_COMMAND_INT_ACK);
1777 arlan_command(dev, ARLAN_COMMAND_INT_ENABLE);
1779 IFDEBUG(ARLAN_DEBUG_INTERRUPT)
1780 printk(KERN_ERR "%s: got IRQ rx %x tx %x comm %x rxOff %x rxLen %x \n",
1781 dev->name, rxStatus, txStatus, READSHMB(arlan->commandByte),
1782 rxOffset, pkt_len);
1784 if (rxStatus == 0 && txStatus == 0)
1786 priv->last_command_was_rx = 0;
1787 if (priv->irq_test_done)
1789 if (!registrationBad(dev))
1790 IFDEBUG(ARLAN_DEBUG_INTERRUPT) printk(KERN_ERR "%s unknown interrupt(nop? regLost ?) reason tx %d rx %d ",
1791 dev->name, txStatus, rxStatus);
1792 } else {
1793 IFDEBUG(ARLAN_DEBUG_INTERRUPT)
1794 printk(KERN_INFO "%s irq $%d test OK \n", dev->name, dev->irq);
1797 priv->interrupt_ack_requested = 0;
1798 goto ends;
1800 if (txStatus != 0)
1802 WRITESHMB(arlan->txStatus, 0x00);
1803 arlan_tx_done_interrupt(dev, txStatus);
1804 goto ends;
1806 if (rxStatus == 1 || rxStatus == 2)
1807 { /* a packet waiting */
1808 arlan_rx_interrupt(dev, rxStatus, rxOffset, pkt_len);
1809 goto ends;
1811 if (rxStatus > 2 && rxStatus < 0xff)
1813 priv->last_command_was_rx = 0;
1814 WRITESHMB(arlan->rxStatus, 0x00);
1815 printk(KERN_ERR "%s unknown rxStatus reason tx %d rx %d ",
1816 dev->name, txStatus, rxStatus);
1817 goto ends;
1819 if (rxStatus == 0xff)
1821 priv->last_command_was_rx = 0;
1822 WRITESHMB(arlan->rxStatus, 0x00);
1823 arlan_command(dev, ARLAN_COMMAND_RX);
1824 if (registrationBad(dev))
1825 dev->start = 0;
1826 if (!registrationBad(dev))
1828 priv->registrationLastSeen = jiffies;
1829 if (!dev->tbusy && !priv->under_reset && !priv->under_config)
1831 mark_bh(NET_BH);
1832 dev->start = 1;
1835 goto ends;
1837 ends:
1839 arlan_command_process(dev);
1841 rxStatus = READSHMB(arlan->rxStatus);
1842 txStatus = READSHMB(arlan->txStatus);
1843 rxOffset = READSHMS(arlan->rxOffset);
1844 pkt_len = READSHMS(arlan->rxLength);
1847 priv->irq_test_done = 1;
1849 interrupt_count++;
1851 priv->interrupt_processing_active = 0;
1853 end_int_process:
1854 arlan_command_process(dev);
1856 ARLAN_DEBUG_EXIT("arlan_process_interrupt");
1857 return;
1860 static void arlan_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1862 struct device *dev = dev_id;
1863 struct arlan_private *priv = (struct arlan_private *) dev->priv;
1864 volatile struct arlan_shmem *arlan = priv->card;
1865 u_char rxStatus = READSHMB(arlan->rxStatus);
1866 u_char txStatus = READSHMB(arlan->txStatus);
1868 ARLAN_DEBUG_ENTRY("arlan_interrupt");
1871 if (!rxStatus && !txStatus)
1872 priv->interrupt_ack_requested++;
1873 dev->interrupt++;
1875 arlan_process_interrupt(dev);
1877 priv->irq_test_done = 1;
1878 dev->interrupt--;
1880 ARLAN_DEBUG_EXIT("arlan_interrupt");
1881 return;
1886 static int arlan_close(struct device *dev)
1888 struct arlan_private *priv = (struct arlan_private *) dev->priv;
1890 if (!dev)
1892 printk(KERN_CRIT "arlan: No Device\n");
1893 return 0;
1895 priv = (struct arlan_private *) dev->priv;
1896 if (!priv)
1898 printk(KERN_CRIT "arlan: No Device priv \n");
1899 return 0;
1901 ARLAN_DEBUG_ENTRY("arlan_close");
1903 IFDEBUG(ARLAN_DEBUG_STARTUP)
1904 printk(KERN_NOTICE "%s: Closing device\n", dev->name);
1906 priv->open_time = 0;
1907 dev->tbusy = 1;
1908 dev->start = 0;
1909 del_timer(&priv->timer);
1910 free_irq(dev->irq, dev);
1912 MOD_DEC_USE_COUNT;
1914 ARLAN_DEBUG_EXIT("arlan_close");
1915 return 0;
1919 static long alignLong(volatile u_char * ptr)
1921 long ret;
1922 memcpy_fromio(&ret, (void *) ptr, 4);
1923 return ret;
1928 * Get the current statistics.
1929 * This may be called with the card open or closed.
1932 static struct enet_statistics *arlan_statistics(struct device *dev)
1934 struct arlan_private *priv = (struct arlan_private *) dev->priv;
1935 volatile struct arlan_shmem *arlan = ((struct arlan_private *) dev->priv)->card;
1938 ARLAN_DEBUG_ENTRY("arlan_statistics");
1940 /* Update the statistics from the device registers. */
1942 READSHM(priv->stats.collisions, arlan->numReTransmissions, u_int);
1943 READSHM(priv->stats.rx_crc_errors, arlan->numCRCErrors, u_int);
1944 READSHM(priv->stats.rx_dropped, arlan->numFramesDiscarded, u_int);
1945 READSHM(priv->stats.rx_fifo_errors, arlan->numRXBufferOverflows, u_int);
1946 READSHM(priv->stats.rx_frame_errors, arlan->numReceiveFramesLost, u_int);
1947 READSHM(priv->stats.rx_over_errors, arlan->numRXOverruns, u_int);
1948 READSHM(priv->stats.rx_packets, arlan->numDatagramsReceived, u_int);
1949 READSHM(priv->stats.tx_aborted_errors, arlan->numAbortErrors, u_int);
1950 READSHM(priv->stats.tx_carrier_errors, arlan->numStatusTimeouts, u_int);
1951 READSHM(priv->stats.tx_dropped, arlan->numDatagramsDiscarded, u_int);
1952 READSHM(priv->stats.tx_fifo_errors, arlan->numTXUnderruns, u_int);
1953 READSHM(priv->stats.tx_packets, arlan->numDatagramsTransmitted, u_int);
1954 READSHM(priv->stats.tx_window_errors, arlan->numHoldOffs, u_int);
1956 ARLAN_DEBUG_EXIT("arlan_statistics");
1958 return &priv->stats;
1962 static void arlan_set_multicast(struct device *dev)
1964 volatile struct arlan_shmem *arlan = ((struct arlan_private *) dev->priv)->card;
1965 struct arlan_conf_stru *conf = ((struct arlan_private *) dev->priv)->Conf;
1966 int board_conf_needed = 0;
1969 ARLAN_DEBUG_ENTRY("arlan_set_multicast");
1971 if (dev->flags & IFF_PROMISC)
1973 unsigned char recMode;
1974 READSHM(recMode, arlan->receiveMode, u_char);
1975 conf->receiveMode = (ARLAN_RCV_PROMISC | ARLAN_RCV_CONTROL);
1976 if (conf->receiveMode != recMode)
1977 board_conf_needed = 1;
1979 else
1981 /* turn off promiscuous mode */
1982 unsigned char recMode;
1983 READSHM(recMode, arlan->receiveMode, u_char);
1984 conf->receiveMode = ARLAN_RCV_CLEAN | ARLAN_RCV_CONTROL;
1985 if (conf->receiveMode != recMode)
1986 board_conf_needed = 1;
1988 if (board_conf_needed)
1989 arlan_command(dev, ARLAN_COMMAND_CONF);
1991 ARLAN_DEBUG_EXIT("arlan_set_multicast");
1995 __initfunctio(int arlan_probe(struct device *dev))
1997 printk("Arlan driver %s\n", arlan_version);
1999 if (arlan_probe_everywhere(dev))
2000 return ENODEV;
2002 arlans_found++;
2004 if (arlans_found == 1)
2005 siteName = kmalloc(100, GFP_KERNEL);
2006 return 0;
2009 #ifdef MODULE
2011 int init_module(void)
2013 int i = 0;
2015 ARLAN_DEBUG_ENTRY("init_module");
2017 if (channelSet != channelSetUNKNOWN || channelNumber != channelNumberUNKNOWN || systemId != systemIdUNKNOWN)
2019 printk(KERN_WARNING "arlan: wrong module params for multiple devices\n ");
2020 return -1;
2022 numDevices = arlan_find_devices();
2023 if (numDevices == 0)
2025 printk(KERN_ERR "arlan: no devices found \n");
2026 return -1;
2029 siteName = kmalloc(100, GFP_KERNEL);
2030 if(siteName==NULL)
2032 printk(KERN_ERR "arlan: No memory for site name.\n");
2033 return -1;
2035 for (i = 0; i < numDevices && i < MAX_ARLANS; i++)
2037 if (!arlan_allocate_device(i, NULL))
2038 return -1;
2039 if (arlan_device[i] == NULL)
2041 printk(KERN_CRIT "arlan: Not Enough memory \n");
2042 return -1;
2044 if (probe)
2045 arlan_probe_everywhere(arlan_device[i]);
2047 printk(KERN_INFO "Arlan driver %s\n", arlan_version);
2048 ARLAN_DEBUG_EXIT("init_module");
2049 return 0;
2053 void cleanup_module(void)
2055 int i = 0;
2057 ARLAN_DEBUG_ENTRY("cleanup_module");
2059 IFDEBUG(ARLAN_DEBUG_SHUTDOWN)
2060 printk(KERN_INFO "arlan: unloading module\n");
2061 for (i = 0; i < MAX_ARLANS; i++)
2063 if (arlan_device[i])
2065 unregister_netdev(arlan_device[i]);
2066 if (arlan_device[i]->priv)
2068 if (((struct arlan_private *) arlan_device[i]->priv)->conf)
2069 kfree(((struct arlan_private *) arlan_device[i]->priv)->conf);
2070 kfree(arlan_device[i]);
2072 arlan_device[i] = NULL;
2075 ARLAN_DEBUG_EXIT("cleanup_module");
2079 #endif