[TG3]: Set minimal hw interrupt mitigation.
[linux-2.6/verdex.git] / drivers / net / wireless / arlan-main.c
blob4f304c6e693a79b0ab4c6de51c77da89d6620a04
1 /*
2 * Copyright (C) 1997 Cullen Jennings
3 * Copyright (C) 1998 Elmer Joandiu, elmer@ylenurme.ee
4 * GNU General 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 #if BITS_PER_LONG != 32
12 # error FIXME: this driver requires a 32-bit platform
13 #endif
15 static const char *arlan_version = "C.Jennigs 97 & Elmer.Joandi@ut.ee Oct'98, http://www.ylenurme.ee/~elmer/655/";
17 struct net_device *arlan_device[MAX_ARLANS];
19 static int SID = SIDUNKNOWN;
20 static int radioNodeId = radioNodeIdUNKNOWN;
21 static char encryptionKey[12] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'};
22 int arlan_debug = debugUNKNOWN;
23 static int spreadingCode = spreadingCodeUNKNOWN;
24 static int channelNumber = channelNumberUNKNOWN;
25 static int channelSet = channelSetUNKNOWN;
26 static int systemId = systemIdUNKNOWN;
27 static int registrationMode = registrationModeUNKNOWN;
28 static int keyStart;
29 static int tx_delay_ms;
30 static int retries = 5;
31 static int tx_queue_len = 1;
32 static int arlan_EEPROM_bad;
34 #ifdef ARLAN_DEBUGGING
36 static int arlan_entry_debug;
37 static int arlan_exit_debug;
38 static int testMemory = testMemoryUNKNOWN;
39 static int irq = irqUNKNOWN;
40 static int txScrambled = 1;
41 static int mdebug;
43 module_param(irq, int, 0);
44 module_param(mdebug, int, 0);
45 module_param(testMemory, int, 0);
46 module_param(arlan_entry_debug, int, 0);
47 module_param(arlan_exit_debug, int, 0);
48 module_param(txScrambled, int, 0);
49 MODULE_PARM_DESC(irq, "(unused)");
50 MODULE_PARM_DESC(testMemory, "(unused)");
51 MODULE_PARM_DESC(mdebug, "Arlan multicast debugging (0-1)");
52 #endif
54 module_param(arlan_debug, int, 0);
55 module_param(spreadingCode, int, 0);
56 module_param(channelNumber, int, 0);
57 module_param(channelSet, int, 0);
58 module_param(systemId, int, 0);
59 module_param(registrationMode, int, 0);
60 module_param(radioNodeId, int, 0);
61 module_param(SID, int, 0);
62 module_param(keyStart, int, 0);
63 module_param(tx_delay_ms, int, 0);
64 module_param(retries, int, 0);
65 module_param(tx_queue_len, int, 0);
66 module_param(arlan_EEPROM_bad, int, 0);
67 MODULE_PARM_DESC(arlan_debug, "Arlan debug enable (0-1)");
68 MODULE_PARM_DESC(retries, "Arlan maximum packet retransmisions");
69 #ifdef ARLAN_ENTRY_EXIT_DEBUGGING
70 MODULE_PARM_DESC(arlan_entry_debug, "Arlan driver function entry debugging");
71 MODULE_PARM_DESC(arlan_exit_debug, "Arlan driver function exit debugging");
72 MODULE_PARM_DESC(arlan_entry_and_exit_debug, "Arlan driver function entry and exit debugging");
73 #else
74 MODULE_PARM_DESC(arlan_entry_debug, "(ignored)");
75 MODULE_PARM_DESC(arlan_exit_debug, "(ignored)");
76 MODULE_PARM_DESC(arlan_entry_and_exit_debug, "(ignored)");
77 #endif
79 struct arlan_conf_stru arlan_conf[MAX_ARLANS];
80 static int arlans_found;
82 static int arlan_open(struct net_device *dev);
83 static int arlan_tx(struct sk_buff *skb, struct net_device *dev);
84 static irqreturn_t arlan_interrupt(int irq, void *dev_id, struct pt_regs *regs);
85 static int arlan_close(struct net_device *dev);
86 static struct net_device_stats *
87 arlan_statistics (struct net_device *dev);
88 static void arlan_set_multicast (struct net_device *dev);
89 static int arlan_hw_tx (struct net_device* dev, char *buf, int length );
90 static int arlan_hw_config (struct net_device * dev);
91 static void arlan_tx_done_interrupt (struct net_device * dev, int status);
92 static void arlan_rx_interrupt (struct net_device * dev, u_char rxStatus, u_short, u_short);
93 static void arlan_process_interrupt (struct net_device * dev);
94 static void arlan_tx_timeout (struct net_device *dev);
96 static inline long us2ticks(int us)
98 return us * (1000000 / HZ);
102 #ifdef ARLAN_ENTRY_EXIT_DEBUGGING
103 #define ARLAN_DEBUG_ENTRY(name) \
105 struct timeval timev;\
106 do_gettimeofday(&timev);\
107 if (arlan_entry_debug || arlan_entry_and_exit_debug)\
108 printk("--->>>" name " %ld " "\n",((long int) timev.tv_sec * 1000000 + timev.tv_usec));\
110 #define ARLAN_DEBUG_EXIT(name) \
112 struct timeval timev;\
113 do_gettimeofday(&timev);\
114 if (arlan_exit_debug || arlan_entry_and_exit_debug)\
115 printk("<<<---" name " %ld " "\n",((long int) timev.tv_sec * 1000000 + timev.tv_usec) );\
117 #else
118 #define ARLAN_DEBUG_ENTRY(name)
119 #define ARLAN_DEBUG_EXIT(name)
120 #endif
123 #define arlan_interrupt_ack(dev)\
124 clearClearInterrupt(dev);\
125 setClearInterrupt(dev);
127 static inline int arlan_drop_tx(struct net_device *dev)
129 struct arlan_private *priv = netdev_priv(dev);
131 priv->stats.tx_errors++;
132 if (priv->Conf->tx_delay_ms)
134 priv->tx_done_delayed = jiffies + priv->Conf->tx_delay_ms * HZ / 1000 + 1;
136 else
138 priv->waiting_command_mask &= ~ARLAN_COMMAND_TX;
139 TXHEAD(dev).offset = 0;
140 TXTAIL(dev).offset = 0;
141 priv->txLast = 0;
142 priv->bad = 0;
143 if (!priv->under_reset && !priv->under_config)
144 netif_wake_queue (dev);
146 return 1;
150 int arlan_command(struct net_device *dev, int command_p)
152 struct arlan_private *priv = netdev_priv(dev);
153 volatile struct arlan_shmem __iomem *arlan = priv->card;
154 struct arlan_conf_stru *conf = priv->Conf;
155 int udelayed = 0;
156 int i = 0;
157 unsigned long flags;
159 ARLAN_DEBUG_ENTRY("arlan_command");
161 if (priv->card_polling_interval)
162 priv->card_polling_interval = 1;
164 if (arlan_debug & ARLAN_DEBUG_CHAIN_LOCKS)
165 printk(KERN_DEBUG "arlan_command, %lx commandByte %x waiting %lx incoming %x \n",
166 jiffies, READSHMB(arlan->commandByte),
167 priv->waiting_command_mask, command_p);
169 priv->waiting_command_mask |= command_p;
171 if (priv->waiting_command_mask & ARLAN_COMMAND_RESET)
172 if (time_after(jiffies, priv->lastReset + 5 * HZ))
173 priv->waiting_command_mask &= ~ARLAN_COMMAND_RESET;
175 if (priv->waiting_command_mask & ARLAN_COMMAND_INT_ACK)
177 arlan_interrupt_ack(dev);
178 priv->waiting_command_mask &= ~ARLAN_COMMAND_INT_ACK;
180 if (priv->waiting_command_mask & ARLAN_COMMAND_INT_ENABLE)
182 setInterruptEnable(dev);
183 priv->waiting_command_mask &= ~ARLAN_COMMAND_INT_ENABLE;
186 /* Card access serializing lock */
187 spin_lock_irqsave(&priv->lock, flags);
189 /* Check cards status and waiting */
191 if (priv->waiting_command_mask & (ARLAN_COMMAND_LONG_WAIT_NOW | ARLAN_COMMAND_WAIT_NOW))
193 while (priv->waiting_command_mask & (ARLAN_COMMAND_LONG_WAIT_NOW | ARLAN_COMMAND_WAIT_NOW))
195 if (READSHMB(arlan->resetFlag) ||
196 READSHMB(arlan->commandByte)) /* ||
197 (readControlRegister(dev) & ARLAN_ACCESS))
199 udelay(40);
200 else
201 priv->waiting_command_mask &= ~(ARLAN_COMMAND_LONG_WAIT_NOW | ARLAN_COMMAND_WAIT_NOW);
203 udelayed++;
205 if (priv->waiting_command_mask & ARLAN_COMMAND_LONG_WAIT_NOW)
207 if (udelayed * 40 > 1000000)
209 printk(KERN_ERR "%s long wait too long \n", dev->name);
210 priv->waiting_command_mask |= ARLAN_COMMAND_RESET;
211 break;
214 else if (priv->waiting_command_mask & ARLAN_COMMAND_WAIT_NOW)
216 if (udelayed * 40 > 1000)
218 printk(KERN_ERR "%s short wait too long \n", dev->name);
219 goto bad_end;
224 else
226 i = 0;
227 while ((READSHMB(arlan->resetFlag) ||
228 READSHMB(arlan->commandByte)) &&
229 conf->pre_Command_Wait > (i++) * 10)
230 udelay(10);
233 if ((READSHMB(arlan->resetFlag) ||
234 READSHMB(arlan->commandByte)) &&
235 !(priv->waiting_command_mask & ARLAN_COMMAND_RESET))
237 goto card_busy_end;
240 if (priv->waiting_command_mask & ARLAN_COMMAND_RESET)
241 priv->under_reset = 1;
242 if (priv->waiting_command_mask & ARLAN_COMMAND_CONF)
243 priv->under_config = 1;
245 /* Issuing command */
246 arlan_lock_card_access(dev);
247 if (priv->waiting_command_mask & ARLAN_COMMAND_POWERUP)
249 // if (readControlRegister(dev) & (ARLAN_ACCESS && ARLAN_POWER))
250 setPowerOn(dev);
251 arlan_interrupt_lancpu(dev);
252 priv->waiting_command_mask &= ~ARLAN_COMMAND_POWERUP;
253 priv->waiting_command_mask |= ARLAN_COMMAND_RESET;
254 priv->card_polling_interval = HZ / 10;
256 else if (priv->waiting_command_mask & ARLAN_COMMAND_ACTIVATE)
258 WRITESHMB(arlan->commandByte, ARLAN_COM_ACTIVATE);
259 arlan_interrupt_lancpu(dev);
260 priv->waiting_command_mask &= ~ARLAN_COMMAND_ACTIVATE;
261 priv->card_polling_interval = HZ / 10;
263 else if (priv->waiting_command_mask & ARLAN_COMMAND_RX_ABORT)
265 if (priv->rx_command_given)
267 WRITESHMB(arlan->commandByte, ARLAN_COM_RX_ABORT);
268 arlan_interrupt_lancpu(dev);
269 priv->rx_command_given = 0;
271 priv->waiting_command_mask &= ~ARLAN_COMMAND_RX_ABORT;
272 priv->card_polling_interval = 1;
274 else if (priv->waiting_command_mask & ARLAN_COMMAND_TX_ABORT)
276 if (priv->tx_command_given)
278 WRITESHMB(arlan->commandByte, ARLAN_COM_TX_ABORT);
279 arlan_interrupt_lancpu(dev);
280 priv->tx_command_given = 0;
282 priv->waiting_command_mask &= ~ARLAN_COMMAND_TX_ABORT;
283 priv->card_polling_interval = 1;
285 else if (priv->waiting_command_mask & ARLAN_COMMAND_RESET)
287 priv->under_reset=1;
288 netif_stop_queue (dev);
290 arlan_drop_tx(dev);
291 if (priv->tx_command_given || priv->rx_command_given)
293 printk(KERN_ERR "%s: Reset under tx or rx command \n", dev->name);
295 netif_stop_queue (dev);
296 if (arlan_debug & ARLAN_DEBUG_RESET)
297 printk(KERN_ERR "%s: Doing chip reset\n", dev->name);
298 priv->lastReset = jiffies;
299 WRITESHM(arlan->commandByte, 0, u_char);
300 /* hold card in reset state */
301 setHardwareReset(dev);
302 /* set reset flag and then release reset */
303 WRITESHM(arlan->resetFlag, 0xff, u_char);
304 clearChannelAttention(dev);
305 clearHardwareReset(dev);
306 priv->card_polling_interval = HZ / 4;
307 priv->waiting_command_mask &= ~ARLAN_COMMAND_RESET;
308 priv->waiting_command_mask |= ARLAN_COMMAND_INT_RACK;
309 // priv->waiting_command_mask |= ARLAN_COMMAND_INT_RENABLE;
310 // priv->waiting_command_mask |= ARLAN_COMMAND_RX;
312 else if (priv->waiting_command_mask & ARLAN_COMMAND_INT_RACK)
314 clearHardwareReset(dev);
315 clearClearInterrupt(dev);
316 setClearInterrupt(dev);
317 setInterruptEnable(dev);
318 priv->waiting_command_mask &= ~ARLAN_COMMAND_INT_RACK;
319 priv->waiting_command_mask |= ARLAN_COMMAND_CONF;
320 priv->under_config = 1;
321 priv->under_reset = 0;
323 else if (priv->waiting_command_mask & ARLAN_COMMAND_INT_RENABLE)
325 setInterruptEnable(dev);
326 priv->waiting_command_mask &= ~ARLAN_COMMAND_INT_RENABLE;
328 else if (priv->waiting_command_mask & ARLAN_COMMAND_CONF)
330 if (priv->tx_command_given || priv->rx_command_given)
332 printk(KERN_ERR "%s: Reset under tx or rx command \n", dev->name);
334 arlan_drop_tx(dev);
335 setInterruptEnable(dev);
336 arlan_hw_config(dev);
337 arlan_interrupt_lancpu(dev);
338 priv->waiting_command_mask &= ~ARLAN_COMMAND_CONF;
339 priv->card_polling_interval = HZ / 10;
340 // priv->waiting_command_mask |= ARLAN_COMMAND_INT_RACK;
341 // priv->waiting_command_mask |= ARLAN_COMMAND_INT_ENABLE;
342 priv->waiting_command_mask |= ARLAN_COMMAND_CONF_WAIT;
344 else if (priv->waiting_command_mask & ARLAN_COMMAND_CONF_WAIT)
346 if (READSHMB(arlan->configuredStatusFlag) != 0 &&
347 READSHMB(arlan->diagnosticInfo) == 0xff)
349 priv->waiting_command_mask &= ~ARLAN_COMMAND_CONF_WAIT;
350 priv->waiting_command_mask |= ARLAN_COMMAND_RX;
351 priv->waiting_command_mask |= ARLAN_COMMAND_TBUSY_CLEAR;
352 priv->card_polling_interval = HZ / 10;
353 priv->tx_command_given = 0;
354 priv->under_config = 0;
356 else
358 priv->card_polling_interval = 1;
359 if (arlan_debug & ARLAN_DEBUG_TIMING)
360 printk(KERN_ERR "configure delayed \n");
363 else if (priv->waiting_command_mask & ARLAN_COMMAND_RX)
365 if (!registrationBad(dev))
367 setInterruptEnable(dev);
368 memset_io(arlan->commandParameter, 0, 0xf);
369 WRITESHMB(arlan->commandByte, ARLAN_COM_INT | ARLAN_COM_RX_ENABLE);
370 WRITESHMB(arlan->commandParameter[0], conf->rxParameter);
371 arlan_interrupt_lancpu(dev);
372 priv->rx_command_given = 0; // mnjah, bad
373 priv->waiting_command_mask &= ~ARLAN_COMMAND_RX;
374 priv->card_polling_interval = 1;
376 else
377 priv->card_polling_interval = 2;
379 else if (priv->waiting_command_mask & ARLAN_COMMAND_TBUSY_CLEAR)
381 if ( !registrationBad(dev) &&
382 (netif_queue_stopped(dev) || !netif_running(dev)) )
384 priv->waiting_command_mask &= ~ARLAN_COMMAND_TBUSY_CLEAR;
385 netif_wake_queue (dev);
388 else if (priv->waiting_command_mask & ARLAN_COMMAND_TX)
390 if (!test_and_set_bit(0, (void *) &priv->tx_command_given))
392 if (time_after(jiffies,
393 priv->tx_last_sent + us2ticks(conf->rx_tweak1))
394 || time_before(jiffies,
395 priv->last_rx_int_ack_time + us2ticks(conf->rx_tweak2)))
397 setInterruptEnable(dev);
398 memset_io(arlan->commandParameter, 0, 0xf);
399 WRITESHMB(arlan->commandByte, ARLAN_COM_TX_ENABLE | ARLAN_COM_INT);
400 memcpy_toio(arlan->commandParameter, &TXLAST(dev), 14);
401 // for ( i=1 ; i < 15 ; i++) printk("%02x:",READSHMB(arlan->commandParameter[i]));
402 priv->tx_last_sent = jiffies;
403 arlan_interrupt_lancpu(dev);
404 priv->tx_command_given = 1;
405 priv->waiting_command_mask &= ~ARLAN_COMMAND_TX;
406 priv->card_polling_interval = 1;
408 else
410 priv->tx_command_given = 0;
411 priv->card_polling_interval = 1;
414 else if (arlan_debug & ARLAN_DEBUG_CHAIN_LOCKS)
415 printk(KERN_ERR "tx command when tx chain locked \n");
417 else if (priv->waiting_command_mask & ARLAN_COMMAND_NOOPINT)
420 WRITESHMB(arlan->commandByte, ARLAN_COM_NOP | ARLAN_COM_INT);
422 arlan_interrupt_lancpu(dev);
423 priv->waiting_command_mask &= ~ARLAN_COMMAND_NOOPINT;
424 priv->card_polling_interval = HZ / 3;
426 else if (priv->waiting_command_mask & ARLAN_COMMAND_NOOP)
428 WRITESHMB(arlan->commandByte, ARLAN_COM_NOP);
429 arlan_interrupt_lancpu(dev);
430 priv->waiting_command_mask &= ~ARLAN_COMMAND_NOOP;
431 priv->card_polling_interval = HZ / 3;
433 else if (priv->waiting_command_mask & ARLAN_COMMAND_SLOW_POLL)
435 WRITESHMB(arlan->commandByte, ARLAN_COM_GOTO_SLOW_POLL);
436 arlan_interrupt_lancpu(dev);
437 priv->waiting_command_mask &= ~ARLAN_COMMAND_SLOW_POLL;
438 priv->card_polling_interval = HZ / 3;
440 else if (priv->waiting_command_mask & ARLAN_COMMAND_POWERDOWN)
442 setPowerOff(dev);
443 if (arlan_debug & ARLAN_DEBUG_CARD_STATE)
444 printk(KERN_WARNING "%s: Arlan Going Standby\n", dev->name);
445 priv->waiting_command_mask &= ~ARLAN_COMMAND_POWERDOWN;
446 priv->card_polling_interval = 3 * HZ;
448 arlan_unlock_card_access(dev);
449 for (i = 0; READSHMB(arlan->commandByte) && i < 20; i++)
450 udelay(10);
451 if (READSHMB(arlan->commandByte))
452 if (arlan_debug & ARLAN_DEBUG_CARD_STATE)
453 printk(KERN_ERR "card busy leaving command %lx\n", priv->waiting_command_mask);
455 spin_unlock_irqrestore(&priv->lock, flags);
456 ARLAN_DEBUG_EXIT("arlan_command");
457 priv->last_command_buff_free_time = jiffies;
458 return 0;
460 card_busy_end:
461 if (time_after(jiffies, priv->last_command_buff_free_time + HZ))
462 priv->waiting_command_mask |= ARLAN_COMMAND_CLEAN_AND_RESET;
464 if (arlan_debug & ARLAN_DEBUG_CARD_STATE)
465 printk(KERN_ERR "%s arlan_command card busy end \n", dev->name);
466 spin_unlock_irqrestore(&priv->lock, flags);
467 ARLAN_DEBUG_EXIT("arlan_command");
468 return 1;
470 bad_end:
471 printk(KERN_ERR "%s arlan_command bad end \n", dev->name);
473 spin_unlock_irqrestore(&priv->lock, flags);
474 ARLAN_DEBUG_EXIT("arlan_command");
476 return -1;
479 static inline void arlan_command_process(struct net_device *dev)
481 struct arlan_private *priv = netdev_priv(dev);
483 int times = 0;
484 while (priv->waiting_command_mask && times < 8)
486 if (priv->waiting_command_mask)
488 if (arlan_command(dev, 0))
489 break;
490 times++;
492 /* if long command, we won't repeat trying */ ;
493 if (priv->card_polling_interval > 1)
494 break;
495 times++;
500 static inline void arlan_retransmit_now(struct net_device *dev)
502 struct arlan_private *priv = netdev_priv(dev);
505 ARLAN_DEBUG_ENTRY("arlan_retransmit_now");
506 if (TXLAST(dev).offset == 0)
508 if (TXHEAD(dev).offset)
510 priv->txLast = 0;
511 IFDEBUG(ARLAN_DEBUG_TX_CHAIN) printk(KERN_DEBUG "TX buff switch to head \n");
514 else if (TXTAIL(dev).offset)
516 IFDEBUG(ARLAN_DEBUG_TX_CHAIN) printk(KERN_DEBUG "TX buff switch to tail \n");
517 priv->txLast = 1;
519 else
520 IFDEBUG(ARLAN_DEBUG_TX_CHAIN) printk(KERN_ERR "ReTransmit buff empty");
521 netif_wake_queue (dev);
522 return;
525 arlan_command(dev, ARLAN_COMMAND_TX);
527 priv->Conf->driverRetransmissions++;
528 priv->retransmissions++;
530 IFDEBUG(ARLAN_DEBUG_TX_CHAIN) printk("Retransmit %d bytes \n", TXLAST(dev).length);
532 ARLAN_DEBUG_EXIT("arlan_retransmit_now");
537 static void arlan_registration_timer(unsigned long data)
539 struct net_device *dev = (struct net_device *) data;
540 struct arlan_private *priv = netdev_priv(dev);
541 int bh_mark_needed = 0;
542 int next_tick = 1;
543 long lostTime = ((long)jiffies - (long)priv->registrationLastSeen)
544 * (1000/HZ);
546 if (registrationBad(dev))
548 priv->registrationLostCount++;
549 if (lostTime > 7000 && lostTime < 7200)
551 printk(KERN_NOTICE "%s registration Lost \n", dev->name);
553 if (lostTime / priv->reRegisterExp > 2000)
554 arlan_command(dev, ARLAN_COMMAND_CLEAN_AND_CONF);
555 if (lostTime / (priv->reRegisterExp) > 3500)
556 arlan_command(dev, ARLAN_COMMAND_CLEAN_AND_RESET);
557 if (priv->reRegisterExp < 400)
558 priv->reRegisterExp += 2;
559 if (lostTime > 7200)
561 next_tick = HZ;
562 arlan_command(dev, ARLAN_COMMAND_CLEAN_AND_RESET);
565 else
567 if (priv->Conf->registrationMode && lostTime > 10000 &&
568 priv->registrationLostCount)
570 printk(KERN_NOTICE "%s registration is back after %ld milliseconds\n",
571 dev->name, lostTime);
573 priv->registrationLastSeen = jiffies;
574 priv->registrationLostCount = 0;
575 priv->reRegisterExp = 1;
576 if (!netif_running(dev) )
577 netif_wake_queue(dev);
578 if (time_after(priv->tx_last_sent,priv->tx_last_cleared) &&
579 time_after(jiffies, priv->tx_last_sent * 5*HZ) ){
580 arlan_command(dev, ARLAN_COMMAND_CLEAN_AND_RESET);
581 priv->tx_last_cleared = jiffies;
586 if (!registrationBad(dev) && priv->ReTransmitRequested)
588 IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
589 printk(KERN_ERR "Retransmit from timer \n");
590 priv->ReTransmitRequested = 0;
591 arlan_retransmit_now(dev);
593 if (!registrationBad(dev) &&
594 time_after(jiffies, priv->tx_done_delayed) &&
595 priv->tx_done_delayed != 0)
597 TXLAST(dev).offset = 0;
598 if (priv->txLast)
599 priv->txLast = 0;
600 else if (TXTAIL(dev).offset)
601 priv->txLast = 1;
602 if (TXLAST(dev).offset)
604 arlan_retransmit_now(dev);
605 dev->trans_start = jiffies;
607 if (!(TXHEAD(dev).offset && TXTAIL(dev).offset))
609 netif_wake_queue (dev);
611 priv->tx_done_delayed = 0;
612 bh_mark_needed = 1;
614 if (bh_mark_needed)
616 netif_wake_queue (dev);
618 arlan_process_interrupt(dev);
620 if (next_tick < priv->card_polling_interval)
621 next_tick = priv->card_polling_interval;
623 priv->timer.expires = jiffies + next_tick;
625 add_timer(&priv->timer);
629 #ifdef ARLAN_DEBUGGING
631 static void arlan_print_registers(struct net_device *dev, int line)
633 struct arlan_private *priv = netdev_priv(dev);
634 volatile struct arlan_shmem *arlan = priv->card;
636 u_char hostcpuLock, lancpuLock, controlRegister, cntrlRegImage,
637 txStatus, rxStatus, interruptInProgress, commandByte;
640 ARLAN_DEBUG_ENTRY("arlan_print_registers");
641 READSHM(interruptInProgress, arlan->interruptInProgress, u_char);
642 READSHM(hostcpuLock, arlan->hostcpuLock, u_char);
643 READSHM(lancpuLock, arlan->lancpuLock, u_char);
644 READSHM(controlRegister, arlan->controlRegister, u_char);
645 READSHM(cntrlRegImage, arlan->cntrlRegImage, u_char);
646 READSHM(txStatus, arlan->txStatus, u_char);
647 READSHM(rxStatus, arlan->rxStatus, u_char);
648 READSHM(commandByte, arlan->commandByte, u_char);
650 printk(KERN_WARNING "line %04d IP %02x HL %02x LL %02x CB %02x CR %02x CRI %02x TX %02x RX %02x\n",
651 line, interruptInProgress, hostcpuLock, lancpuLock, commandByte,
652 controlRegister, cntrlRegImage, txStatus, rxStatus);
654 ARLAN_DEBUG_EXIT("arlan_print_registers");
656 #endif
659 static int arlan_hw_tx(struct net_device *dev, char *buf, int length)
661 int i;
663 struct arlan_private *priv = netdev_priv(dev);
664 volatile struct arlan_shmem __iomem *arlan = priv->card;
665 struct arlan_conf_stru *conf = priv->Conf;
667 int tailStarts = 0x800;
668 int headEnds = 0x0;
671 ARLAN_DEBUG_ENTRY("arlan_hw_tx");
672 if (TXHEAD(dev).offset)
673 headEnds = (((TXHEAD(dev).offset + TXHEAD(dev).length - offsetof(struct arlan_shmem, txBuffer)) / 64) + 1) * 64;
674 if (TXTAIL(dev).offset)
675 tailStarts = 0x800 - (((TXTAIL(dev).offset - offsetof(struct arlan_shmem, txBuffer)) / 64) + 2) * 64;
678 if (!TXHEAD(dev).offset && length < tailStarts)
680 IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
681 printk(KERN_ERR "TXHEAD insert, tailStart %d\n", tailStarts);
683 TXHEAD(dev).offset =
684 offsetof(struct arlan_shmem, txBuffer);
685 TXHEAD(dev).length = length - ARLAN_FAKE_HDR_LEN;
686 for (i = 0; i < 6; i++)
687 TXHEAD(dev).dest[i] = buf[i];
688 TXHEAD(dev).clear = conf->txClear;
689 TXHEAD(dev).retries = conf->txRetries; /* 0 is use default */
690 TXHEAD(dev).routing = conf->txRouting;
691 TXHEAD(dev).scrambled = conf->txScrambled;
692 memcpy_toio((char __iomem *)arlan + TXHEAD(dev).offset, buf + ARLAN_FAKE_HDR_LEN, TXHEAD(dev).length);
694 else if (!TXTAIL(dev).offset && length < (0x800 - headEnds))
696 IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
697 printk(KERN_ERR "TXTAIL insert, headEnd %d\n", headEnds);
699 TXTAIL(dev).offset =
700 offsetof(struct arlan_shmem, txBuffer) + 0x800 - (length / 64 + 2) * 64;
701 TXTAIL(dev).length = length - ARLAN_FAKE_HDR_LEN;
702 for (i = 0; i < 6; i++)
703 TXTAIL(dev).dest[i] = buf[i];
704 TXTAIL(dev).clear = conf->txClear;
705 TXTAIL(dev).retries = conf->txRetries;
706 TXTAIL(dev).routing = conf->txRouting;
707 TXTAIL(dev).scrambled = conf->txScrambled;
708 memcpy_toio(((char __iomem *)arlan + TXTAIL(dev).offset), buf + ARLAN_FAKE_HDR_LEN, TXTAIL(dev).length);
710 else
712 netif_stop_queue (dev);
713 IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
714 printk(KERN_ERR "TX TAIL & HEAD full, return, tailStart %d headEnd %d\n", tailStarts, headEnds);
715 return -1;
717 priv->out_bytes += length;
718 priv->out_bytes10 += length;
719 if (conf->measure_rate < 1)
720 conf->measure_rate = 1;
721 if (time_after(jiffies, priv->out_time + conf->measure_rate * HZ))
723 conf->out_speed = priv->out_bytes / conf->measure_rate;
724 priv->out_bytes = 0;
725 priv->out_time = jiffies;
727 if (time_after(jiffies, priv->out_time10 + conf->measure_rate * 10*HZ))
729 conf->out_speed10 = priv->out_bytes10 / (10 * conf->measure_rate);
730 priv->out_bytes10 = 0;
731 priv->out_time10 = jiffies;
733 if (TXHEAD(dev).offset && TXTAIL(dev).offset)
735 netif_stop_queue (dev);
736 return 0;
738 else
739 netif_start_queue (dev);
742 IFDEBUG(ARLAN_DEBUG_HEADER_DUMP)
743 printk(KERN_WARNING "%s Transmit t %2x:%2x:%2x:%2x:%2x:%2x f %2x:%2x:%2x:%2x:%2x:%2x \n", dev->name,
744 (unsigned char) buf[0], (unsigned char) buf[1], (unsigned char) buf[2], (unsigned char) buf[3],
745 (unsigned char) buf[4], (unsigned char) buf[5], (unsigned char) buf[6], (unsigned char) buf[7],
746 (unsigned char) buf[8], (unsigned char) buf[9], (unsigned char) buf[10], (unsigned char) buf[11]);
748 IFDEBUG(ARLAN_DEBUG_TX_CHAIN) printk(KERN_ERR "TX command prepare for buffer %d\n", priv->txLast);
750 arlan_command(dev, ARLAN_COMMAND_TX);
752 priv->tx_last_sent = jiffies;
754 IFDEBUG(ARLAN_DEBUG_TX_CHAIN) printk("%s TX Qued %d bytes \n", dev->name, length);
756 ARLAN_DEBUG_EXIT("arlan_hw_tx");
758 return 0;
762 static int arlan_hw_config(struct net_device *dev)
764 struct arlan_private *priv = netdev_priv(dev);
765 volatile struct arlan_shmem __iomem *arlan = priv->card;
766 struct arlan_conf_stru *conf = priv->Conf;
768 ARLAN_DEBUG_ENTRY("arlan_hw_config");
770 printk(KERN_NOTICE "%s arlan configure called \n", dev->name);
771 if (arlan_EEPROM_bad)
772 printk(KERN_NOTICE "arlan configure with eeprom bad option \n");
775 WRITESHM(arlan->spreadingCode, conf->spreadingCode, u_char);
776 WRITESHM(arlan->channelSet, conf->channelSet, u_char);
778 if (arlan_EEPROM_bad)
779 WRITESHM(arlan->defaultChannelSet, conf->channelSet, u_char);
781 WRITESHM(arlan->channelNumber, conf->channelNumber, u_char);
783 WRITESHM(arlan->scramblingDisable, conf->scramblingDisable, u_char);
784 WRITESHM(arlan->txAttenuation, conf->txAttenuation, u_char);
786 WRITESHM(arlan->systemId, conf->systemId, u_int);
788 WRITESHM(arlan->maxRetries, conf->maxRetries, u_char);
789 WRITESHM(arlan->receiveMode, conf->receiveMode, u_char);
790 WRITESHM(arlan->priority, conf->priority, u_char);
791 WRITESHM(arlan->rootOrRepeater, conf->rootOrRepeater, u_char);
792 WRITESHM(arlan->SID, conf->SID, u_int);
794 WRITESHM(arlan->registrationMode, conf->registrationMode, u_char);
796 WRITESHM(arlan->registrationFill, conf->registrationFill, u_char);
797 WRITESHM(arlan->localTalkAddress, conf->localTalkAddress, u_char);
798 WRITESHM(arlan->codeFormat, conf->codeFormat, u_char);
799 WRITESHM(arlan->numChannels, conf->numChannels, u_char);
800 WRITESHM(arlan->channel1, conf->channel1, u_char);
801 WRITESHM(arlan->channel2, conf->channel2, u_char);
802 WRITESHM(arlan->channel3, conf->channel3, u_char);
803 WRITESHM(arlan->channel4, conf->channel4, u_char);
804 WRITESHM(arlan->radioNodeId, conf->radioNodeId, u_short);
805 WRITESHM(arlan->SID, conf->SID, u_int);
806 WRITESHM(arlan->waitTime, conf->waitTime, u_short);
807 WRITESHM(arlan->lParameter, conf->lParameter, u_short);
808 memcpy_toio(&(arlan->_15), &(conf->_15), 3);
809 WRITESHM(arlan->_15, conf->_15, u_short);
810 WRITESHM(arlan->headerSize, conf->headerSize, u_short);
811 if (arlan_EEPROM_bad)
812 WRITESHM(arlan->hardwareType, conf->hardwareType, u_char);
813 WRITESHM(arlan->radioType, conf->radioType, u_char);
814 if (arlan_EEPROM_bad)
815 WRITESHM(arlan->radioModule, conf->radioType, u_char);
817 memcpy_toio(arlan->encryptionKey + keyStart, encryptionKey, 8);
818 memcpy_toio(arlan->name, conf->siteName, 16);
820 WRITESHMB(arlan->commandByte, ARLAN_COM_INT | ARLAN_COM_CONF); /* do configure */
821 memset_io(arlan->commandParameter, 0, 0xf); /* 0xf */
822 memset_io(arlan->commandParameter + 1, 0, 2);
823 if (conf->writeEEPROM)
825 memset_io(arlan->commandParameter, conf->writeEEPROM, 1);
826 // conf->writeEEPROM=0;
828 if (conf->registrationMode && conf->registrationInterrupts)
829 memset_io(arlan->commandParameter + 3, 1, 1);
830 else
831 memset_io(arlan->commandParameter + 3, 0, 1);
833 priv->irq_test_done = 0;
835 if (conf->tx_queue_len)
836 dev->tx_queue_len = conf->tx_queue_len;
837 udelay(100);
839 ARLAN_DEBUG_EXIT("arlan_hw_config");
840 return 0;
844 static int arlan_read_card_configuration(struct net_device *dev)
846 u_char tlx415;
847 struct arlan_private *priv = netdev_priv(dev);
848 volatile struct arlan_shmem __iomem *arlan = priv->card;
849 struct arlan_conf_stru *conf = priv->Conf;
851 ARLAN_DEBUG_ENTRY("arlan_read_card_configuration");
853 if (radioNodeId == radioNodeIdUNKNOWN)
855 READSHM(conf->radioNodeId, arlan->radioNodeId, u_short);
857 else
858 conf->radioNodeId = radioNodeId;
860 if (SID == SIDUNKNOWN)
862 READSHM(conf->SID, arlan->SID, u_int);
864 else conf->SID = SID;
866 if (spreadingCode == spreadingCodeUNKNOWN)
868 READSHM(conf->spreadingCode, arlan->spreadingCode, u_char);
870 else
871 conf->spreadingCode = spreadingCode;
873 if (channelSet == channelSetUNKNOWN)
875 READSHM(conf->channelSet, arlan->channelSet, u_char);
877 else conf->channelSet = channelSet;
879 if (channelNumber == channelNumberUNKNOWN)
881 READSHM(conf->channelNumber, arlan->channelNumber, u_char);
883 else conf->channelNumber = channelNumber;
885 READSHM(conf->scramblingDisable, arlan->scramblingDisable, u_char);
886 READSHM(conf->txAttenuation, arlan->txAttenuation, u_char);
888 if (systemId == systemIdUNKNOWN)
890 READSHM(conf->systemId, arlan->systemId, u_int);
892 else conf->systemId = systemId;
894 READSHM(conf->maxDatagramSize, arlan->maxDatagramSize, u_short);
895 READSHM(conf->maxFrameSize, arlan->maxFrameSize, u_short);
896 READSHM(conf->maxRetries, arlan->maxRetries, u_char);
897 READSHM(conf->receiveMode, arlan->receiveMode, u_char);
898 READSHM(conf->priority, arlan->priority, u_char);
899 READSHM(conf->rootOrRepeater, arlan->rootOrRepeater, u_char);
901 if (SID == SIDUNKNOWN)
903 READSHM(conf->SID, arlan->SID, u_int);
905 else conf->SID = SID;
907 if (registrationMode == registrationModeUNKNOWN)
909 READSHM(conf->registrationMode, arlan->registrationMode, u_char);
911 else conf->registrationMode = registrationMode;
913 READSHM(conf->registrationFill, arlan->registrationFill, u_char);
914 READSHM(conf->localTalkAddress, arlan->localTalkAddress, u_char);
915 READSHM(conf->codeFormat, arlan->codeFormat, u_char);
916 READSHM(conf->numChannels, arlan->numChannels, u_char);
917 READSHM(conf->channel1, arlan->channel1, u_char);
918 READSHM(conf->channel2, arlan->channel2, u_char);
919 READSHM(conf->channel3, arlan->channel3, u_char);
920 READSHM(conf->channel4, arlan->channel4, u_char);
921 READSHM(conf->waitTime, arlan->waitTime, u_short);
922 READSHM(conf->lParameter, arlan->lParameter, u_short);
923 READSHM(conf->_15, arlan->_15, u_short);
924 READSHM(conf->headerSize, arlan->headerSize, u_short);
925 READSHM(conf->hardwareType, arlan->hardwareType, u_char);
926 READSHM(conf->radioType, arlan->radioModule, u_char);
928 if (conf->radioType == 0)
929 conf->radioType = 0xc;
931 WRITESHM(arlan->configStatus, 0xA5, u_char);
932 READSHM(tlx415, arlan->configStatus, u_char);
934 if (tlx415 != 0xA5)
935 printk(KERN_INFO "%s tlx415 chip \n", dev->name);
937 conf->txClear = 0;
938 conf->txRetries = 1;
939 conf->txRouting = 1;
940 conf->txScrambled = 0;
941 conf->rxParameter = 1;
942 conf->txTimeoutMs = 4000;
943 conf->waitCardTimeout = 100000;
944 conf->receiveMode = ARLAN_RCV_CLEAN;
945 memcpy_fromio(conf->siteName, arlan->name, 16);
946 conf->siteName[16] = '\0';
947 conf->retries = retries;
948 conf->tx_delay_ms = tx_delay_ms;
949 conf->ReTransmitPacketMaxSize = 200;
950 conf->waitReTransmitPacketMaxSize = 200;
951 conf->txAckTimeoutMs = 900;
952 conf->fastReTransCount = 3;
954 ARLAN_DEBUG_EXIT("arlan_read_card_configuration");
956 return 0;
960 static int lastFoundAt = 0xbe000;
964 * This is the real probe routine. Linux has a history of friendly device
965 * probes on the ISA bus. A good device probes avoids doing writes, and
966 * verifies that the correct device exists and functions.
968 #define ARLAN_SHMEM_SIZE 0x2000
969 static int __init arlan_check_fingerprint(unsigned long memaddr)
971 static const char probeText[] = "TELESYSTEM SLW INC. ARLAN \0";
972 volatile struct arlan_shmem __iomem *arlan = (struct arlan_shmem *) memaddr;
973 unsigned long paddr = virt_to_phys((void *) memaddr);
974 char tempBuf[49];
976 ARLAN_DEBUG_ENTRY("arlan_check_fingerprint");
978 if (!request_mem_region(paddr, ARLAN_SHMEM_SIZE, "arlan")) {
979 // printk(KERN_WARNING "arlan: memory region %lx excluded from probing \n",paddr);
980 return -ENODEV;
983 memcpy_fromio(tempBuf, arlan->textRegion, 29);
984 tempBuf[30] = 0;
986 /* check for card at this address */
987 if (0 != strncmp(tempBuf, probeText, 29)){
988 release_mem_region(paddr, ARLAN_SHMEM_SIZE);
989 return -ENODEV;
992 // printk(KERN_INFO "arlan found at 0x%x \n",memaddr);
993 ARLAN_DEBUG_EXIT("arlan_check_fingerprint");
995 return 0;
998 static int arlan_change_mtu(struct net_device *dev, int new_mtu)
1000 struct arlan_private *priv = netdev_priv(dev);
1001 struct arlan_conf_stru *conf = priv->Conf;
1003 ARLAN_DEBUG_ENTRY("arlan_change_mtu");
1004 if (new_mtu > 2032)
1005 return -EINVAL;
1006 dev->mtu = new_mtu;
1007 if (new_mtu < 256)
1008 new_mtu = 256; /* cards book suggests 1600 */
1009 conf->maxDatagramSize = new_mtu;
1010 conf->maxFrameSize = new_mtu + 48;
1012 arlan_command(dev, ARLAN_COMMAND_CLEAN_AND_CONF);
1013 printk(KERN_NOTICE "%s mtu changed to %d \n", dev->name, new_mtu);
1015 ARLAN_DEBUG_EXIT("arlan_change_mtu");
1017 return 0;
1020 static int arlan_mac_addr(struct net_device *dev, void *p)
1022 struct sockaddr *addr = p;
1025 ARLAN_DEBUG_ENTRY("arlan_mac_addr");
1026 return -EINVAL;
1028 if (!netif_running(dev))
1029 return -EBUSY;
1030 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
1032 ARLAN_DEBUG_EXIT("arlan_mac_addr");
1033 return 0;
1038 static int __init arlan_setup_device(struct net_device *dev, int num)
1040 struct arlan_private *ap = netdev_priv(dev);
1041 int err;
1043 ARLAN_DEBUG_ENTRY("arlan_setup_device");
1045 ap->conf = (struct arlan_shmem *)(ap+1);
1047 dev->tx_queue_len = tx_queue_len;
1048 dev->open = arlan_open;
1049 dev->stop = arlan_close;
1050 dev->hard_start_xmit = arlan_tx;
1051 dev->get_stats = arlan_statistics;
1052 dev->set_multicast_list = arlan_set_multicast;
1053 dev->change_mtu = arlan_change_mtu;
1054 dev->set_mac_address = arlan_mac_addr;
1055 dev->tx_timeout = arlan_tx_timeout;
1056 dev->watchdog_timeo = 3*HZ;
1058 ap->irq_test_done = 0;
1059 ap->Conf = &arlan_conf[num];
1061 ap->Conf->pre_Command_Wait = 40;
1062 ap->Conf->rx_tweak1 = 30;
1063 ap->Conf->rx_tweak2 = 0;
1066 err = register_netdev(dev);
1067 if (err) {
1068 release_mem_region(virt_to_phys((void *) dev->mem_start),
1069 ARLAN_SHMEM_SIZE);
1070 free_netdev(dev);
1071 return err;
1073 arlan_device[num] = dev;
1074 ARLAN_DEBUG_EXIT("arlan_setup_device");
1075 return 0;
1078 static int __init arlan_probe_here(struct net_device *dev,
1079 unsigned long memaddr)
1081 struct arlan_private *ap = netdev_priv(dev);
1083 ARLAN_DEBUG_ENTRY("arlan_probe_here");
1085 if (arlan_check_fingerprint(memaddr))
1086 return -ENODEV;
1088 printk(KERN_NOTICE "%s: Arlan found at %x, \n ", dev->name,
1089 (int) virt_to_phys((void*)memaddr));
1091 ap->card = (void *) memaddr;
1092 dev->mem_start = memaddr;
1093 dev->mem_end = memaddr + ARLAN_SHMEM_SIZE-1;
1095 if (dev->irq < 2)
1097 READSHM(dev->irq, ap->card->irqLevel, u_char);
1098 } else if (dev->irq == 2)
1099 dev->irq = 9;
1101 arlan_read_card_configuration(dev);
1103 ARLAN_DEBUG_EXIT("arlan_probe_here");
1104 return 0;
1108 static int arlan_open(struct net_device *dev)
1110 struct arlan_private *priv = netdev_priv(dev);
1111 volatile struct arlan_shmem __iomem *arlan = priv->card;
1112 int ret = 0;
1114 ARLAN_DEBUG_ENTRY("arlan_open");
1116 ret = request_irq(dev->irq, &arlan_interrupt, 0, dev->name, dev);
1117 if (ret)
1119 printk(KERN_ERR "%s: unable to get IRQ %d .\n",
1120 dev->name, dev->irq);
1121 return ret;
1125 priv->bad = 0;
1126 priv->lastReset = 0;
1127 priv->reset = 0;
1128 memcpy_fromio(dev->dev_addr, arlan->lanCardNodeId, 6);
1129 memset(dev->broadcast, 0xff, 6);
1130 dev->tx_queue_len = tx_queue_len;
1131 priv->interrupt_processing_active = 0;
1132 spin_lock_init(&priv->lock);
1134 netif_start_queue (dev);
1136 priv->registrationLostCount = 0;
1137 priv->registrationLastSeen = jiffies;
1138 priv->txLast = 0;
1139 priv->tx_command_given = 0;
1140 priv->rx_command_given = 0;
1142 priv->reRegisterExp = 1;
1143 priv->tx_last_sent = jiffies - 1;
1144 priv->tx_last_cleared = jiffies;
1145 priv->Conf->writeEEPROM = 0;
1146 priv->Conf->registrationInterrupts = 1;
1148 init_timer(&priv->timer);
1149 priv->timer.expires = jiffies + HZ / 10;
1150 priv->timer.data = (unsigned long) dev;
1151 priv->timer.function = &arlan_registration_timer; /* timer handler */
1153 arlan_command(dev, ARLAN_COMMAND_POWERUP | ARLAN_COMMAND_LONG_WAIT_NOW);
1154 mdelay(200);
1155 add_timer(&priv->timer);
1157 ARLAN_DEBUG_EXIT("arlan_open");
1158 return 0;
1162 static void arlan_tx_timeout (struct net_device *dev)
1164 printk(KERN_ERR "%s: arlan transmit timed out, kernel decided\n", dev->name);
1165 /* Try to restart the adaptor. */
1166 arlan_command(dev, ARLAN_COMMAND_CLEAN_AND_RESET);
1167 // dev->trans_start = jiffies;
1168 // netif_start_queue (dev);
1172 static int arlan_tx(struct sk_buff *skb, struct net_device *dev)
1174 short length;
1175 unsigned char *buf;
1177 ARLAN_DEBUG_ENTRY("arlan_tx");
1179 length = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
1180 buf = skb->data;
1182 if (length + 0x12 > 0x800) {
1183 printk(KERN_ERR "TX RING overflow \n");
1184 netif_stop_queue (dev);
1187 if (arlan_hw_tx(dev, buf, length) == -1)
1188 goto bad_end;
1190 dev->trans_start = jiffies;
1192 dev_kfree_skb(skb);
1194 arlan_process_interrupt(dev);
1195 ARLAN_DEBUG_EXIT("arlan_tx");
1196 return 0;
1198 bad_end:
1199 arlan_process_interrupt(dev);
1200 netif_stop_queue (dev);
1201 ARLAN_DEBUG_EXIT("arlan_tx");
1202 return 1;
1206 static inline int DoNotReTransmitCrap(struct net_device *dev)
1208 struct arlan_private *priv = netdev_priv(dev);
1210 if (TXLAST(dev).length < priv->Conf->ReTransmitPacketMaxSize)
1211 return 1;
1212 return 0;
1216 static inline int DoNotWaitReTransmitCrap(struct net_device *dev)
1218 struct arlan_private *priv = netdev_priv(dev);
1220 if (TXLAST(dev).length < priv->Conf->waitReTransmitPacketMaxSize)
1221 return 1;
1222 return 0;
1225 static inline void arlan_queue_retransmit(struct net_device *dev)
1227 struct arlan_private *priv = netdev_priv(dev);
1229 ARLAN_DEBUG_ENTRY("arlan_queue_retransmit");
1231 if (DoNotWaitReTransmitCrap(dev))
1233 arlan_drop_tx(dev);
1234 } else
1235 priv->ReTransmitRequested++;
1237 ARLAN_DEBUG_EXIT("arlan_queue_retransmit");
1240 static inline void RetryOrFail(struct net_device *dev)
1242 struct arlan_private *priv = netdev_priv(dev);
1244 ARLAN_DEBUG_ENTRY("RetryOrFail");
1246 if (priv->retransmissions > priv->Conf->retries ||
1247 DoNotReTransmitCrap(dev))
1249 arlan_drop_tx(dev);
1251 else if (priv->bad <= priv->Conf->fastReTransCount)
1253 arlan_retransmit_now(dev);
1255 else arlan_queue_retransmit(dev);
1257 ARLAN_DEBUG_EXIT("RetryOrFail");
1261 static void arlan_tx_done_interrupt(struct net_device *dev, int status)
1263 struct arlan_private *priv = netdev_priv(dev);
1265 ARLAN_DEBUG_ENTRY("arlan_tx_done_interrupt");
1267 priv->tx_last_cleared = jiffies;
1268 priv->tx_command_given = 0;
1269 switch (status)
1271 case 1:
1273 IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
1274 printk("arlan intr: transmit OK\n");
1275 priv->stats.tx_packets++;
1276 priv->bad = 0;
1277 priv->reset = 0;
1278 priv->retransmissions = 0;
1279 if (priv->Conf->tx_delay_ms)
1281 priv->tx_done_delayed = jiffies + (priv->Conf->tx_delay_ms * HZ) / 1000 + 1;
1283 else
1285 TXLAST(dev).offset = 0;
1286 if (priv->txLast)
1287 priv->txLast = 0;
1288 else if (TXTAIL(dev).offset)
1289 priv->txLast = 1;
1290 if (TXLAST(dev).offset)
1292 arlan_retransmit_now(dev);
1293 dev->trans_start = jiffies;
1295 if (!TXHEAD(dev).offset || !TXTAIL(dev).offset)
1297 netif_wake_queue (dev);
1301 break;
1303 case 2:
1305 IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
1306 printk("arlan intr: transmit timed out\n");
1307 priv->bad += 1;
1308 //arlan_queue_retransmit(dev);
1309 RetryOrFail(dev);
1311 break;
1313 case 3:
1315 IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
1316 printk("arlan intr: transmit max retries\n");
1317 priv->bad += 1;
1318 priv->reset = 0;
1319 //arlan_queue_retransmit(dev);
1320 RetryOrFail(dev);
1322 break;
1324 case 4:
1326 IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
1327 printk("arlan intr: transmit aborted\n");
1328 priv->bad += 1;
1329 arlan_queue_retransmit(dev);
1330 //RetryOrFail(dev);
1332 break;
1334 case 5:
1336 IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
1337 printk("arlan intr: transmit not registered\n");
1338 priv->bad += 1;
1339 //debug=101;
1340 arlan_queue_retransmit(dev);
1342 break;
1344 case 6:
1346 IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
1347 printk("arlan intr: transmit destination full\n");
1348 priv->bad += 1;
1349 priv->reset = 0;
1350 //arlan_drop_tx(dev);
1351 arlan_queue_retransmit(dev);
1353 break;
1355 case 7:
1357 IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
1358 printk("arlan intr: transmit unknown ack\n");
1359 priv->bad += 1;
1360 priv->reset = 0;
1361 arlan_queue_retransmit(dev);
1363 break;
1365 case 8:
1367 IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
1368 printk("arlan intr: transmit dest mail box full\n");
1369 priv->bad += 1;
1370 priv->reset = 0;
1371 //arlan_drop_tx(dev);
1372 arlan_queue_retransmit(dev);
1374 break;
1376 case 9:
1378 IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
1379 printk("arlan intr: transmit root dest not reg.\n");
1380 priv->bad += 1;
1381 priv->reset = 1;
1382 //arlan_drop_tx(dev);
1383 arlan_queue_retransmit(dev);
1385 break;
1387 default:
1389 printk(KERN_ERR "arlan intr: transmit status unknown\n");
1390 priv->bad += 1;
1391 priv->reset = 1;
1392 arlan_drop_tx(dev);
1396 ARLAN_DEBUG_EXIT("arlan_tx_done_interrupt");
1400 static void arlan_rx_interrupt(struct net_device *dev, u_char rxStatus, u_short rxOffset, u_short pkt_len)
1402 char *skbtmp;
1403 int i = 0;
1405 struct arlan_private *priv = netdev_priv(dev);
1406 volatile struct arlan_shmem __iomem *arlan = priv->card;
1407 struct arlan_conf_stru *conf = priv->Conf;
1410 ARLAN_DEBUG_ENTRY("arlan_rx_interrupt");
1411 // by spec, not WRITESHMB(arlan->rxStatus,0x00);
1412 // prohibited here arlan_command(dev, ARLAN_COMMAND_RX);
1414 if (pkt_len < 10 || pkt_len > 2048)
1416 printk(KERN_WARNING "%s: got too short or long packet, len %d \n", dev->name, pkt_len);
1417 return;
1419 if (rxOffset + pkt_len > 0x2000)
1421 printk("%s: got too long packet, len %d offset %x\n", dev->name, pkt_len, rxOffset);
1422 return;
1424 priv->in_bytes += pkt_len;
1425 priv->in_bytes10 += pkt_len;
1426 if (conf->measure_rate < 1)
1427 conf->measure_rate = 1;
1428 if (time_after(jiffies, priv->in_time + conf->measure_rate * HZ))
1430 conf->in_speed = priv->in_bytes / conf->measure_rate;
1431 priv->in_bytes = 0;
1432 priv->in_time = jiffies;
1434 if (time_after(jiffies, priv->in_time10 + conf->measure_rate * 10*HZ))
1436 conf->in_speed10 = priv->in_bytes10 / (10 * conf->measure_rate);
1437 priv->in_bytes10 = 0;
1438 priv->in_time10 = jiffies;
1440 DEBUGSHM(1, "arlan rcv pkt rxStatus= %d ", arlan->rxStatus, u_char);
1441 switch (rxStatus)
1443 case 1:
1444 case 2:
1445 case 3:
1447 /* Malloc up new buffer. */
1448 struct sk_buff *skb;
1450 DEBUGSHM(50, "arlan recv pkt offs=%d\n", arlan->rxOffset, u_short);
1451 DEBUGSHM(1, "arlan rxFrmType = %d \n", arlan->rxFrmType, u_char);
1452 DEBUGSHM(1, KERN_INFO "arlan rx scrambled = %d \n", arlan->scrambled, u_char);
1454 /* here we do multicast filtering to avoid slow 8-bit memcopy */
1455 #ifdef ARLAN_MULTICAST
1456 if (!(dev->flags & IFF_ALLMULTI) &&
1457 !(dev->flags & IFF_PROMISC) &&
1458 dev->mc_list)
1460 char hw_dst_addr[6];
1461 struct dev_mc_list *dmi = dev->mc_list;
1462 int i;
1464 memcpy_fromio(hw_dst_addr, arlan->ultimateDestAddress, 6);
1465 if (hw_dst_addr[0] == 0x01)
1467 if (mdebug)
1468 if (hw_dst_addr[1] == 0x00)
1469 printk(KERN_ERR "%s mcast 0x0100 \n", dev->name);
1470 else if (hw_dst_addr[1] == 0x40)
1471 printk(KERN_ERR "%s m/bcast 0x0140 \n", dev->name);
1472 while (dmi)
1473 { if (dmi->dmi_addrlen == 6)
1475 if (arlan_debug & ARLAN_DEBUG_HEADER_DUMP)
1476 printk(KERN_ERR "%s mcl %2x:%2x:%2x:%2x:%2x:%2x \n", dev->name,
1477 dmi->dmi_addr[0], dmi->dmi_addr[1], dmi->dmi_addr[2],
1478 dmi->dmi_addr[3], dmi->dmi_addr[4], dmi->dmi_addr[5]);
1479 for (i = 0; i < 6; i++)
1480 if (dmi->dmi_addr[i] != hw_dst_addr[i])
1481 break;
1482 if (i == 6)
1483 break;
1485 else
1486 printk(KERN_ERR "%s: invalid multicast address length given.\n", dev->name);
1487 dmi = dmi->next;
1489 /* we reach here if multicast filtering is on and packet
1490 * is multicast and not for receive */
1491 goto end_of_interrupt;
1494 #endif // ARLAN_MULTICAST
1495 /* multicast filtering ends here */
1496 pkt_len += ARLAN_FAKE_HDR_LEN;
1498 skb = dev_alloc_skb(pkt_len + 4);
1499 if (skb == NULL)
1501 printk(KERN_ERR "%s: Memory squeeze, dropping packet.\n", dev->name);
1502 priv->stats.rx_dropped++;
1503 break;
1505 skb_reserve(skb, 2);
1506 skb->dev = dev;
1507 skbtmp = skb_put(skb, pkt_len);
1509 memcpy_fromio(skbtmp + ARLAN_FAKE_HDR_LEN, ((char __iomem *) arlan) + rxOffset, pkt_len - ARLAN_FAKE_HDR_LEN);
1510 memcpy_fromio(skbtmp, arlan->ultimateDestAddress, 6);
1511 memcpy_fromio(skbtmp + 6, arlan->rxSrc, 6);
1512 WRITESHMB(arlan->rxStatus, 0x00);
1513 arlan_command(dev, ARLAN_COMMAND_RX);
1515 IFDEBUG(ARLAN_DEBUG_HEADER_DUMP)
1517 char immedDestAddress[6];
1518 char immedSrcAddress[6];
1519 memcpy_fromio(immedDestAddress, arlan->immedDestAddress, 6);
1520 memcpy_fromio(immedSrcAddress, arlan->immedSrcAddress, 6);
1522 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,
1523 (unsigned char) skbtmp[0], (unsigned char) skbtmp[1], (unsigned char) skbtmp[2], (unsigned char) skbtmp[3],
1524 (unsigned char) skbtmp[4], (unsigned char) skbtmp[5], (unsigned char) skbtmp[6], (unsigned char) skbtmp[7],
1525 (unsigned char) skbtmp[8], (unsigned char) skbtmp[9], (unsigned char) skbtmp[10], (unsigned char) skbtmp[11],
1526 immedDestAddress[0], immedDestAddress[1], immedDestAddress[2],
1527 immedDestAddress[3], immedDestAddress[4], immedDestAddress[5],
1528 immedSrcAddress[0], immedSrcAddress[1], immedSrcAddress[2],
1529 immedSrcAddress[3], immedSrcAddress[4], immedSrcAddress[5]);
1531 skb->protocol = eth_type_trans(skb, dev);
1532 IFDEBUG(ARLAN_DEBUG_HEADER_DUMP)
1533 if (skb->protocol != 0x608 && skb->protocol != 0x8)
1535 for (i = 0; i <= 22; i++)
1536 printk("%02x:", (u_char) skbtmp[i + 12]);
1537 printk(KERN_ERR "\n");
1538 printk(KERN_WARNING "arlan kernel pkt type trans %x \n", skb->protocol);
1540 netif_rx(skb);
1541 dev->last_rx = jiffies;
1542 priv->stats.rx_packets++;
1543 priv->stats.rx_bytes += pkt_len;
1545 break;
1547 default:
1548 printk(KERN_ERR "arlan intr: received unknown status\n");
1549 priv->stats.rx_crc_errors++;
1550 break;
1552 ARLAN_DEBUG_EXIT("arlan_rx_interrupt");
1555 static void arlan_process_interrupt(struct net_device *dev)
1557 struct arlan_private *priv = netdev_priv(dev);
1558 volatile struct arlan_shmem __iomem *arlan = priv->card;
1559 u_char rxStatus = READSHMB(arlan->rxStatus);
1560 u_char txStatus = READSHMB(arlan->txStatus);
1561 u_short rxOffset = READSHMS(arlan->rxOffset);
1562 u_short pkt_len = READSHMS(arlan->rxLength);
1563 int interrupt_count = 0;
1565 ARLAN_DEBUG_ENTRY("arlan_process_interrupt");
1567 if (test_and_set_bit(0, (void *) &priv->interrupt_processing_active))
1569 if (arlan_debug & ARLAN_DEBUG_CHAIN_LOCKS)
1570 printk(KERN_ERR "interrupt chain reentering \n");
1571 goto end_int_process;
1573 while ((rxStatus || txStatus || priv->interrupt_ack_requested)
1574 && (interrupt_count < 5))
1576 if (rxStatus)
1577 priv->last_rx_int_ack_time = jiffies;
1579 arlan_command(dev, ARLAN_COMMAND_INT_ACK);
1580 arlan_command(dev, ARLAN_COMMAND_INT_ENABLE);
1582 IFDEBUG(ARLAN_DEBUG_INTERRUPT)
1583 printk(KERN_ERR "%s: got IRQ rx %x tx %x comm %x rxOff %x rxLen %x \n",
1584 dev->name, rxStatus, txStatus, READSHMB(arlan->commandByte),
1585 rxOffset, pkt_len);
1587 if (rxStatus == 0 && txStatus == 0)
1589 if (priv->irq_test_done)
1591 if (!registrationBad(dev))
1592 IFDEBUG(ARLAN_DEBUG_INTERRUPT) printk(KERN_ERR "%s unknown interrupt(nop? regLost ?) reason tx %d rx %d ",
1593 dev->name, txStatus, rxStatus);
1594 } else {
1595 IFDEBUG(ARLAN_DEBUG_INTERRUPT)
1596 printk(KERN_INFO "%s irq $%d test OK \n", dev->name, dev->irq);
1599 priv->interrupt_ack_requested = 0;
1600 goto ends;
1602 if (txStatus != 0)
1604 WRITESHMB(arlan->txStatus, 0x00);
1605 arlan_tx_done_interrupt(dev, txStatus);
1606 goto ends;
1608 if (rxStatus == 1 || rxStatus == 2)
1609 { /* a packet waiting */
1610 arlan_rx_interrupt(dev, rxStatus, rxOffset, pkt_len);
1611 goto ends;
1613 if (rxStatus > 2 && rxStatus < 0xff)
1615 WRITESHMB(arlan->rxStatus, 0x00);
1616 printk(KERN_ERR "%s unknown rxStatus reason tx %d rx %d ",
1617 dev->name, txStatus, rxStatus);
1618 goto ends;
1620 if (rxStatus == 0xff)
1622 WRITESHMB(arlan->rxStatus, 0x00);
1623 arlan_command(dev, ARLAN_COMMAND_RX);
1624 if (registrationBad(dev))
1625 netif_device_detach(dev);
1626 if (!registrationBad(dev))
1628 priv->registrationLastSeen = jiffies;
1629 if (!netif_queue_stopped(dev) && !priv->under_reset && !priv->under_config)
1630 netif_wake_queue (dev);
1632 goto ends;
1634 ends:
1636 arlan_command_process(dev);
1638 rxStatus = READSHMB(arlan->rxStatus);
1639 txStatus = READSHMB(arlan->txStatus);
1640 rxOffset = READSHMS(arlan->rxOffset);
1641 pkt_len = READSHMS(arlan->rxLength);
1644 priv->irq_test_done = 1;
1646 interrupt_count++;
1648 priv->interrupt_processing_active = 0;
1650 end_int_process:
1651 arlan_command_process(dev);
1653 ARLAN_DEBUG_EXIT("arlan_process_interrupt");
1654 return;
1657 static irqreturn_t arlan_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1659 struct net_device *dev = dev_id;
1660 struct arlan_private *priv = netdev_priv(dev);
1661 volatile struct arlan_shmem __iomem *arlan = priv->card;
1662 u_char rxStatus = READSHMB(arlan->rxStatus);
1663 u_char txStatus = READSHMB(arlan->txStatus);
1665 ARLAN_DEBUG_ENTRY("arlan_interrupt");
1668 if (!rxStatus && !txStatus)
1669 priv->interrupt_ack_requested++;
1671 arlan_process_interrupt(dev);
1673 priv->irq_test_done = 1;
1675 ARLAN_DEBUG_EXIT("arlan_interrupt");
1676 return IRQ_HANDLED;
1681 static int arlan_close(struct net_device *dev)
1683 struct arlan_private *priv = netdev_priv(dev);
1685 ARLAN_DEBUG_ENTRY("arlan_close");
1687 del_timer_sync(&priv->timer);
1689 arlan_command(dev, ARLAN_COMMAND_POWERDOWN);
1691 IFDEBUG(ARLAN_DEBUG_STARTUP)
1692 printk(KERN_NOTICE "%s: Closing device\n", dev->name);
1694 netif_stop_queue(dev);
1695 free_irq(dev->irq, dev);
1697 ARLAN_DEBUG_EXIT("arlan_close");
1698 return 0;
1701 #ifdef ARLAN_DEBUGGING
1702 static long alignLong(volatile u_char * ptr)
1704 long ret;
1705 memcpy_fromio(&ret, (void *) ptr, 4);
1706 return ret;
1708 #endif
1711 * Get the current statistics.
1712 * This may be called with the card open or closed.
1715 static struct net_device_stats *arlan_statistics(struct net_device *dev)
1717 struct arlan_private *priv = netdev_priv(dev);
1718 volatile struct arlan_shmem __iomem *arlan = priv->card;
1721 ARLAN_DEBUG_ENTRY("arlan_statistics");
1723 /* Update the statistics from the device registers. */
1725 READSHM(priv->stats.collisions, arlan->numReTransmissions, u_int);
1726 READSHM(priv->stats.rx_crc_errors, arlan->numCRCErrors, u_int);
1727 READSHM(priv->stats.rx_dropped, arlan->numFramesDiscarded, u_int);
1728 READSHM(priv->stats.rx_fifo_errors, arlan->numRXBufferOverflows, u_int);
1729 READSHM(priv->stats.rx_frame_errors, arlan->numReceiveFramesLost, u_int);
1730 READSHM(priv->stats.rx_over_errors, arlan->numRXOverruns, u_int);
1731 READSHM(priv->stats.rx_packets, arlan->numDatagramsReceived, u_int);
1732 READSHM(priv->stats.tx_aborted_errors, arlan->numAbortErrors, u_int);
1733 READSHM(priv->stats.tx_carrier_errors, arlan->numStatusTimeouts, u_int);
1734 READSHM(priv->stats.tx_dropped, arlan->numDatagramsDiscarded, u_int);
1735 READSHM(priv->stats.tx_fifo_errors, arlan->numTXUnderruns, u_int);
1736 READSHM(priv->stats.tx_packets, arlan->numDatagramsTransmitted, u_int);
1737 READSHM(priv->stats.tx_window_errors, arlan->numHoldOffs, u_int);
1739 ARLAN_DEBUG_EXIT("arlan_statistics");
1741 return &priv->stats;
1745 static void arlan_set_multicast(struct net_device *dev)
1747 struct arlan_private *priv = netdev_priv(dev);
1748 volatile struct arlan_shmem __iomem *arlan = priv->card;
1749 struct arlan_conf_stru *conf = priv->Conf;
1750 int board_conf_needed = 0;
1753 ARLAN_DEBUG_ENTRY("arlan_set_multicast");
1755 if (dev->flags & IFF_PROMISC)
1757 unsigned char recMode;
1758 READSHM(recMode, arlan->receiveMode, u_char);
1759 conf->receiveMode = (ARLAN_RCV_PROMISC | ARLAN_RCV_CONTROL);
1760 if (conf->receiveMode != recMode)
1761 board_conf_needed = 1;
1763 else
1765 /* turn off promiscuous mode */
1766 unsigned char recMode;
1767 READSHM(recMode, arlan->receiveMode, u_char);
1768 conf->receiveMode = ARLAN_RCV_CLEAN | ARLAN_RCV_CONTROL;
1769 if (conf->receiveMode != recMode)
1770 board_conf_needed = 1;
1772 if (board_conf_needed)
1773 arlan_command(dev, ARLAN_COMMAND_CONF);
1775 ARLAN_DEBUG_EXIT("arlan_set_multicast");
1779 struct net_device * __init arlan_probe(int unit)
1781 struct net_device *dev;
1782 int err;
1783 int m;
1785 ARLAN_DEBUG_ENTRY("arlan_probe");
1787 if (arlans_found == MAX_ARLANS)
1788 return ERR_PTR(-ENODEV);
1791 * Reserve space for local data and a copy of the shared memory
1792 * that is used by the /proc interface.
1794 dev = alloc_etherdev(sizeof(struct arlan_private)
1795 + sizeof(struct arlan_shmem));
1796 if (!dev)
1797 return ERR_PTR(-ENOMEM);
1799 SET_MODULE_OWNER(dev);
1801 if (unit >= 0) {
1802 sprintf(dev->name, "eth%d", unit);
1803 netdev_boot_setup_check(dev);
1805 if (dev->mem_start) {
1806 if (arlan_probe_here(dev, dev->mem_start) == 0)
1807 goto found;
1808 goto not_found;
1814 for (m = (int)phys_to_virt(lastFoundAt) + ARLAN_SHMEM_SIZE;
1815 m <= (int)phys_to_virt(0xDE000);
1816 m += ARLAN_SHMEM_SIZE)
1818 if (arlan_probe_here(dev, m) == 0)
1820 lastFoundAt = (int)virt_to_phys((void*)m);
1821 goto found;
1825 if (lastFoundAt == 0xbe000)
1826 printk(KERN_ERR "arlan: No Arlan devices found \n");
1828 not_found:
1829 free_netdev(dev);
1830 return ERR_PTR(-ENODEV);
1832 found:
1833 err = arlan_setup_device(dev, arlans_found);
1834 if (err)
1835 dev = ERR_PTR(err);
1836 else if (!arlans_found++)
1837 printk(KERN_INFO "Arlan driver %s\n", arlan_version);
1839 return dev;
1842 #ifdef MODULE
1843 int init_module(void)
1845 int i = 0;
1847 ARLAN_DEBUG_ENTRY("init_module");
1849 if (channelSet != channelSetUNKNOWN || channelNumber != channelNumberUNKNOWN || systemId != systemIdUNKNOWN)
1850 return -EINVAL;
1852 for (i = 0; i < MAX_ARLANS; i++) {
1853 struct net_device *dev = arlan_probe(i);
1855 if (IS_ERR(dev))
1856 return PTR_ERR(dev);
1858 init_arlan_proc();
1859 printk(KERN_INFO "Arlan driver %s\n", arlan_version);
1860 ARLAN_DEBUG_EXIT("init_module");
1861 return 0;
1865 void cleanup_module(void)
1867 int i = 0;
1868 struct net_device *dev;
1870 ARLAN_DEBUG_ENTRY("cleanup_module");
1872 IFDEBUG(ARLAN_DEBUG_SHUTDOWN)
1873 printk(KERN_INFO "arlan: unloading module\n");
1875 cleanup_arlan_proc();
1877 for (i = 0; i < MAX_ARLANS; i++)
1879 dev = arlan_device[i];
1880 if (dev) {
1881 arlan_command(dev, ARLAN_COMMAND_POWERDOWN );
1883 unregister_netdev(dev);
1884 release_mem_region(virt_to_phys((void *) dev->mem_start),
1885 ARLAN_SHMEM_SIZE);
1886 free_netdev(dev);
1887 arlan_device[i] = NULL;
1891 ARLAN_DEBUG_EXIT("cleanup_module");
1895 #endif
1896 MODULE_LICENSE("GPL");