ASoC: Fix handling of bias levels for non-DAPM codecs
[linux/fpc-iii.git] / drivers / net / wireless / arlan-main.c
blobd84caf198a23ed0f2d4057f6bab603915fbed586
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 "arlan.h"
10 #if BITS_PER_LONG != 32
11 # error FIXME: this driver requires a 32-bit platform
12 #endif
14 static const char *arlan_version = "C.Jennigs 97 & Elmer.Joandi@ut.ee Oct'98, http://www.ylenurme.ee/~elmer/655/";
16 struct net_device *arlan_device[MAX_ARLANS];
18 static int SID = SIDUNKNOWN;
19 static int radioNodeId = radioNodeIdUNKNOWN;
20 static char encryptionKey[12] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'};
21 int arlan_debug = debugUNKNOWN;
22 static int spreadingCode = spreadingCodeUNKNOWN;
23 static int channelNumber = channelNumberUNKNOWN;
24 static int channelSet = channelSetUNKNOWN;
25 static int systemId = systemIdUNKNOWN;
26 static int registrationMode = registrationModeUNKNOWN;
27 static int keyStart;
28 static int tx_delay_ms;
29 static int retries = 5;
30 static int tx_queue_len = 1;
31 static int arlan_EEPROM_bad;
33 #ifdef ARLAN_DEBUGGING
35 static int testMemory = testMemoryUNKNOWN;
36 static int irq = irqUNKNOWN;
37 static int txScrambled = 1;
38 static int mdebug;
40 module_param(irq, int, 0);
41 module_param(mdebug, int, 0);
42 module_param(testMemory, int, 0);
43 module_param(txScrambled, int, 0);
44 MODULE_PARM_DESC(irq, "(unused)");
45 MODULE_PARM_DESC(testMemory, "(unused)");
46 MODULE_PARM_DESC(mdebug, "Arlan multicast debugging (0-1)");
47 #endif
49 module_param_named(debug, arlan_debug, int, 0);
50 module_param(spreadingCode, int, 0);
51 module_param(channelNumber, int, 0);
52 module_param(channelSet, int, 0);
53 module_param(systemId, int, 0);
54 module_param(registrationMode, int, 0);
55 module_param(radioNodeId, int, 0);
56 module_param(SID, int, 0);
57 module_param(keyStart, int, 0);
58 module_param(tx_delay_ms, int, 0);
59 module_param(retries, int, 0);
60 module_param(tx_queue_len, int, 0);
61 module_param_named(EEPROM_bad, arlan_EEPROM_bad, int, 0);
62 MODULE_PARM_DESC(debug, "Arlan debug enable (0-1)");
63 MODULE_PARM_DESC(retries, "Arlan maximum packet retransmisions");
64 #ifdef ARLAN_ENTRY_EXIT_DEBUGGING
65 static int arlan_entry_debug;
66 static int arlan_exit_debug;
67 static int arlan_entry_and_exit_debug;
68 module_param_named(entry_debug, arlan_entry_debug, int, 0);
69 module_param_named(exit_debug, arlan_exit_debug, int, 0);
70 module_param_named(entry_and_exit_debug, arlan_entry_and_exit_debug, int, 0);
71 MODULE_PARM_DESC(entry_debug, "Arlan driver function entry debugging");
72 MODULE_PARM_DESC(exit_debug, "Arlan driver function exit debugging");
73 MODULE_PARM_DESC(entry_and_exit_debug, "Arlan driver function entry and exit debugging");
74 #endif
76 struct arlan_conf_stru arlan_conf[MAX_ARLANS];
77 static int arlans_found;
79 static int arlan_open(struct net_device *dev);
80 static int arlan_tx(struct sk_buff *skb, struct net_device *dev);
81 static irqreturn_t arlan_interrupt(int irq, void *dev_id);
82 static int arlan_close(struct net_device *dev);
83 static struct net_device_stats *
84 arlan_statistics (struct net_device *dev);
85 static void arlan_set_multicast (struct net_device *dev);
86 static int arlan_hw_tx (struct net_device* dev, char *buf, int length );
87 static int arlan_hw_config (struct net_device * dev);
88 static void arlan_tx_done_interrupt (struct net_device * dev, int status);
89 static void arlan_rx_interrupt (struct net_device * dev, u_char rxStatus, u_short, u_short);
90 static void arlan_process_interrupt (struct net_device * dev);
91 static void arlan_tx_timeout (struct net_device *dev);
93 static inline long us2ticks(int us)
95 return us * (1000000 / HZ);
99 #ifdef ARLAN_ENTRY_EXIT_DEBUGGING
100 #define ARLAN_DEBUG_ENTRY(name) \
102 struct timeval timev;\
103 do_gettimeofday(&timev);\
104 if (arlan_entry_debug || arlan_entry_and_exit_debug)\
105 printk("--->>>" name " %ld " "\n",((long int) timev.tv_sec * 1000000 + timev.tv_usec));\
107 #define ARLAN_DEBUG_EXIT(name) \
109 struct timeval timev;\
110 do_gettimeofday(&timev);\
111 if (arlan_exit_debug || arlan_entry_and_exit_debug)\
112 printk("<<<---" name " %ld " "\n",((long int) timev.tv_sec * 1000000 + timev.tv_usec) );\
114 #else
115 #define ARLAN_DEBUG_ENTRY(name)
116 #define ARLAN_DEBUG_EXIT(name)
117 #endif
120 #define arlan_interrupt_ack(dev)\
121 clearClearInterrupt(dev);\
122 setClearInterrupt(dev);
124 static inline int arlan_drop_tx(struct net_device *dev)
126 struct arlan_private *priv = netdev_priv(dev);
128 dev->stats.tx_errors++;
129 if (priv->Conf->tx_delay_ms)
131 priv->tx_done_delayed = jiffies + priv->Conf->tx_delay_ms * HZ / 1000 + 1;
133 else
135 priv->waiting_command_mask &= ~ARLAN_COMMAND_TX;
136 TXHEAD(dev).offset = 0;
137 TXTAIL(dev).offset = 0;
138 priv->txLast = 0;
139 priv->bad = 0;
140 if (!priv->under_reset && !priv->under_config)
141 netif_wake_queue (dev);
143 return 1;
147 int arlan_command(struct net_device *dev, int command_p)
149 struct arlan_private *priv = netdev_priv(dev);
150 volatile struct arlan_shmem __iomem *arlan = priv->card;
151 struct arlan_conf_stru *conf = priv->Conf;
152 int udelayed = 0;
153 int i = 0;
154 unsigned long flags;
156 ARLAN_DEBUG_ENTRY("arlan_command");
158 if (priv->card_polling_interval)
159 priv->card_polling_interval = 1;
161 if (arlan_debug & ARLAN_DEBUG_CHAIN_LOCKS)
162 printk(KERN_DEBUG "arlan_command, %lx commandByte %x waiting %lx incoming %x \n",
163 jiffies, READSHMB(arlan->commandByte),
164 priv->waiting_command_mask, command_p);
166 priv->waiting_command_mask |= command_p;
168 if (priv->waiting_command_mask & ARLAN_COMMAND_RESET)
169 if (time_after(jiffies, priv->lastReset + 5 * HZ))
170 priv->waiting_command_mask &= ~ARLAN_COMMAND_RESET;
172 if (priv->waiting_command_mask & ARLAN_COMMAND_INT_ACK)
174 arlan_interrupt_ack(dev);
175 priv->waiting_command_mask &= ~ARLAN_COMMAND_INT_ACK;
177 if (priv->waiting_command_mask & ARLAN_COMMAND_INT_ENABLE)
179 setInterruptEnable(dev);
180 priv->waiting_command_mask &= ~ARLAN_COMMAND_INT_ENABLE;
183 /* Card access serializing lock */
184 spin_lock_irqsave(&priv->lock, flags);
186 /* Check cards status and waiting */
188 if (priv->waiting_command_mask & (ARLAN_COMMAND_LONG_WAIT_NOW | ARLAN_COMMAND_WAIT_NOW))
190 while (priv->waiting_command_mask & (ARLAN_COMMAND_LONG_WAIT_NOW | ARLAN_COMMAND_WAIT_NOW))
192 if (READSHMB(arlan->resetFlag) ||
193 READSHMB(arlan->commandByte)) /* ||
194 (readControlRegister(dev) & ARLAN_ACCESS))
196 udelay(40);
197 else
198 priv->waiting_command_mask &= ~(ARLAN_COMMAND_LONG_WAIT_NOW | ARLAN_COMMAND_WAIT_NOW);
200 udelayed++;
202 if (priv->waiting_command_mask & ARLAN_COMMAND_LONG_WAIT_NOW)
204 if (udelayed * 40 > 1000000)
206 printk(KERN_ERR "%s long wait too long \n", dev->name);
207 priv->waiting_command_mask |= ARLAN_COMMAND_RESET;
208 break;
211 else if (priv->waiting_command_mask & ARLAN_COMMAND_WAIT_NOW)
213 if (udelayed * 40 > 1000)
215 printk(KERN_ERR "%s short wait too long \n", dev->name);
216 goto bad_end;
221 else
223 i = 0;
224 while ((READSHMB(arlan->resetFlag) ||
225 READSHMB(arlan->commandByte)) &&
226 conf->pre_Command_Wait > (i++) * 10)
227 udelay(10);
230 if ((READSHMB(arlan->resetFlag) ||
231 READSHMB(arlan->commandByte)) &&
232 !(priv->waiting_command_mask & ARLAN_COMMAND_RESET))
234 goto card_busy_end;
237 if (priv->waiting_command_mask & ARLAN_COMMAND_RESET)
238 priv->under_reset = 1;
239 if (priv->waiting_command_mask & ARLAN_COMMAND_CONF)
240 priv->under_config = 1;
242 /* Issuing command */
243 arlan_lock_card_access(dev);
244 if (priv->waiting_command_mask & ARLAN_COMMAND_POWERUP)
246 // if (readControlRegister(dev) & (ARLAN_ACCESS && ARLAN_POWER))
247 setPowerOn(dev);
248 arlan_interrupt_lancpu(dev);
249 priv->waiting_command_mask &= ~ARLAN_COMMAND_POWERUP;
250 priv->waiting_command_mask |= ARLAN_COMMAND_RESET;
251 priv->card_polling_interval = HZ / 10;
253 else if (priv->waiting_command_mask & ARLAN_COMMAND_ACTIVATE)
255 WRITESHMB(arlan->commandByte, ARLAN_COM_ACTIVATE);
256 arlan_interrupt_lancpu(dev);
257 priv->waiting_command_mask &= ~ARLAN_COMMAND_ACTIVATE;
258 priv->card_polling_interval = HZ / 10;
260 else if (priv->waiting_command_mask & ARLAN_COMMAND_RX_ABORT)
262 if (priv->rx_command_given)
264 WRITESHMB(arlan->commandByte, ARLAN_COM_RX_ABORT);
265 arlan_interrupt_lancpu(dev);
266 priv->rx_command_given = 0;
268 priv->waiting_command_mask &= ~ARLAN_COMMAND_RX_ABORT;
269 priv->card_polling_interval = 1;
271 else if (priv->waiting_command_mask & ARLAN_COMMAND_TX_ABORT)
273 if (priv->tx_command_given)
275 WRITESHMB(arlan->commandByte, ARLAN_COM_TX_ABORT);
276 arlan_interrupt_lancpu(dev);
277 priv->tx_command_given = 0;
279 priv->waiting_command_mask &= ~ARLAN_COMMAND_TX_ABORT;
280 priv->card_polling_interval = 1;
282 else if (priv->waiting_command_mask & ARLAN_COMMAND_RESET)
284 priv->under_reset=1;
285 netif_stop_queue (dev);
287 arlan_drop_tx(dev);
288 if (priv->tx_command_given || priv->rx_command_given)
290 printk(KERN_ERR "%s: Reset under tx or rx command \n", dev->name);
292 netif_stop_queue (dev);
293 if (arlan_debug & ARLAN_DEBUG_RESET)
294 printk(KERN_ERR "%s: Doing chip reset\n", dev->name);
295 priv->lastReset = jiffies;
296 WRITESHM(arlan->commandByte, 0, u_char);
297 /* hold card in reset state */
298 setHardwareReset(dev);
299 /* set reset flag and then release reset */
300 WRITESHM(arlan->resetFlag, 0xff, u_char);
301 clearChannelAttention(dev);
302 clearHardwareReset(dev);
303 priv->card_polling_interval = HZ / 4;
304 priv->waiting_command_mask &= ~ARLAN_COMMAND_RESET;
305 priv->waiting_command_mask |= ARLAN_COMMAND_INT_RACK;
306 // priv->waiting_command_mask |= ARLAN_COMMAND_INT_RENABLE;
307 // priv->waiting_command_mask |= ARLAN_COMMAND_RX;
309 else if (priv->waiting_command_mask & ARLAN_COMMAND_INT_RACK)
311 clearHardwareReset(dev);
312 clearClearInterrupt(dev);
313 setClearInterrupt(dev);
314 setInterruptEnable(dev);
315 priv->waiting_command_mask &= ~ARLAN_COMMAND_INT_RACK;
316 priv->waiting_command_mask |= ARLAN_COMMAND_CONF;
317 priv->under_config = 1;
318 priv->under_reset = 0;
320 else if (priv->waiting_command_mask & ARLAN_COMMAND_INT_RENABLE)
322 setInterruptEnable(dev);
323 priv->waiting_command_mask &= ~ARLAN_COMMAND_INT_RENABLE;
325 else if (priv->waiting_command_mask & ARLAN_COMMAND_CONF)
327 if (priv->tx_command_given || priv->rx_command_given)
329 printk(KERN_ERR "%s: Reset under tx or rx command \n", dev->name);
331 arlan_drop_tx(dev);
332 setInterruptEnable(dev);
333 arlan_hw_config(dev);
334 arlan_interrupt_lancpu(dev);
335 priv->waiting_command_mask &= ~ARLAN_COMMAND_CONF;
336 priv->card_polling_interval = HZ / 10;
337 // priv->waiting_command_mask |= ARLAN_COMMAND_INT_RACK;
338 // priv->waiting_command_mask |= ARLAN_COMMAND_INT_ENABLE;
339 priv->waiting_command_mask |= ARLAN_COMMAND_CONF_WAIT;
341 else if (priv->waiting_command_mask & ARLAN_COMMAND_CONF_WAIT)
343 if (READSHMB(arlan->configuredStatusFlag) != 0 &&
344 READSHMB(arlan->diagnosticInfo) == 0xff)
346 priv->waiting_command_mask &= ~ARLAN_COMMAND_CONF_WAIT;
347 priv->waiting_command_mask |= ARLAN_COMMAND_RX;
348 priv->waiting_command_mask |= ARLAN_COMMAND_TBUSY_CLEAR;
349 priv->card_polling_interval = HZ / 10;
350 priv->tx_command_given = 0;
351 priv->under_config = 0;
353 else
355 priv->card_polling_interval = 1;
356 if (arlan_debug & ARLAN_DEBUG_TIMING)
357 printk(KERN_ERR "configure delayed \n");
360 else if (priv->waiting_command_mask & ARLAN_COMMAND_RX)
362 if (!registrationBad(dev))
364 setInterruptEnable(dev);
365 memset_io(arlan->commandParameter, 0, 0xf);
366 WRITESHMB(arlan->commandByte, ARLAN_COM_INT | ARLAN_COM_RX_ENABLE);
367 WRITESHMB(arlan->commandParameter[0], conf->rxParameter);
368 arlan_interrupt_lancpu(dev);
369 priv->rx_command_given = 0; // mnjah, bad
370 priv->waiting_command_mask &= ~ARLAN_COMMAND_RX;
371 priv->card_polling_interval = 1;
373 else
374 priv->card_polling_interval = 2;
376 else if (priv->waiting_command_mask & ARLAN_COMMAND_TBUSY_CLEAR)
378 if ( !registrationBad(dev) &&
379 (netif_queue_stopped(dev) || !netif_running(dev)) )
381 priv->waiting_command_mask &= ~ARLAN_COMMAND_TBUSY_CLEAR;
382 netif_wake_queue (dev);
385 else if (priv->waiting_command_mask & ARLAN_COMMAND_TX)
387 if (!test_and_set_bit(0, (void *) &priv->tx_command_given))
389 if (time_after(jiffies,
390 priv->tx_last_sent + us2ticks(conf->rx_tweak1))
391 || time_before(jiffies,
392 priv->last_rx_int_ack_time + us2ticks(conf->rx_tweak2)))
394 setInterruptEnable(dev);
395 memset_io(arlan->commandParameter, 0, 0xf);
396 WRITESHMB(arlan->commandByte, ARLAN_COM_TX_ENABLE | ARLAN_COM_INT);
397 memcpy_toio(arlan->commandParameter, &TXLAST(dev), 14);
398 // for ( i=1 ; i < 15 ; i++) printk("%02x:",READSHMB(arlan->commandParameter[i]));
399 priv->tx_last_sent = jiffies;
400 arlan_interrupt_lancpu(dev);
401 priv->tx_command_given = 1;
402 priv->waiting_command_mask &= ~ARLAN_COMMAND_TX;
403 priv->card_polling_interval = 1;
405 else
407 priv->tx_command_given = 0;
408 priv->card_polling_interval = 1;
411 else if (arlan_debug & ARLAN_DEBUG_CHAIN_LOCKS)
412 printk(KERN_ERR "tx command when tx chain locked \n");
414 else if (priv->waiting_command_mask & ARLAN_COMMAND_NOOPINT)
417 WRITESHMB(arlan->commandByte, ARLAN_COM_NOP | ARLAN_COM_INT);
419 arlan_interrupt_lancpu(dev);
420 priv->waiting_command_mask &= ~ARLAN_COMMAND_NOOPINT;
421 priv->card_polling_interval = HZ / 3;
423 else if (priv->waiting_command_mask & ARLAN_COMMAND_NOOP)
425 WRITESHMB(arlan->commandByte, ARLAN_COM_NOP);
426 arlan_interrupt_lancpu(dev);
427 priv->waiting_command_mask &= ~ARLAN_COMMAND_NOOP;
428 priv->card_polling_interval = HZ / 3;
430 else if (priv->waiting_command_mask & ARLAN_COMMAND_SLOW_POLL)
432 WRITESHMB(arlan->commandByte, ARLAN_COM_GOTO_SLOW_POLL);
433 arlan_interrupt_lancpu(dev);
434 priv->waiting_command_mask &= ~ARLAN_COMMAND_SLOW_POLL;
435 priv->card_polling_interval = HZ / 3;
437 else if (priv->waiting_command_mask & ARLAN_COMMAND_POWERDOWN)
439 setPowerOff(dev);
440 if (arlan_debug & ARLAN_DEBUG_CARD_STATE)
441 printk(KERN_WARNING "%s: Arlan Going Standby\n", dev->name);
442 priv->waiting_command_mask &= ~ARLAN_COMMAND_POWERDOWN;
443 priv->card_polling_interval = 3 * HZ;
445 arlan_unlock_card_access(dev);
446 for (i = 0; READSHMB(arlan->commandByte) && i < 20; i++)
447 udelay(10);
448 if (READSHMB(arlan->commandByte))
449 if (arlan_debug & ARLAN_DEBUG_CARD_STATE)
450 printk(KERN_ERR "card busy leaving command %lx\n", priv->waiting_command_mask);
452 spin_unlock_irqrestore(&priv->lock, flags);
453 ARLAN_DEBUG_EXIT("arlan_command");
454 priv->last_command_buff_free_time = jiffies;
455 return 0;
457 card_busy_end:
458 if (time_after(jiffies, priv->last_command_buff_free_time + HZ))
459 priv->waiting_command_mask |= ARLAN_COMMAND_CLEAN_AND_RESET;
461 if (arlan_debug & ARLAN_DEBUG_CARD_STATE)
462 printk(KERN_ERR "%s arlan_command card busy end \n", dev->name);
463 spin_unlock_irqrestore(&priv->lock, flags);
464 ARLAN_DEBUG_EXIT("arlan_command");
465 return 1;
467 bad_end:
468 printk(KERN_ERR "%s arlan_command bad end \n", dev->name);
470 spin_unlock_irqrestore(&priv->lock, flags);
471 ARLAN_DEBUG_EXIT("arlan_command");
473 return -1;
476 static inline void arlan_command_process(struct net_device *dev)
478 struct arlan_private *priv = netdev_priv(dev);
480 int times = 0;
481 while (priv->waiting_command_mask && times < 8)
483 if (priv->waiting_command_mask)
485 if (arlan_command(dev, 0))
486 break;
487 times++;
489 /* if long command, we won't repeat trying */ ;
490 if (priv->card_polling_interval > 1)
491 break;
492 times++;
497 static inline void arlan_retransmit_now(struct net_device *dev)
499 struct arlan_private *priv = netdev_priv(dev);
502 ARLAN_DEBUG_ENTRY("arlan_retransmit_now");
503 if (TXLAST(dev).offset == 0)
505 if (TXHEAD(dev).offset)
507 priv->txLast = 0;
508 IFDEBUG(ARLAN_DEBUG_TX_CHAIN) printk(KERN_DEBUG "TX buff switch to head \n");
511 else if (TXTAIL(dev).offset)
513 IFDEBUG(ARLAN_DEBUG_TX_CHAIN) printk(KERN_DEBUG "TX buff switch to tail \n");
514 priv->txLast = 1;
516 else
517 IFDEBUG(ARLAN_DEBUG_TX_CHAIN) printk(KERN_ERR "ReTransmit buff empty");
518 netif_wake_queue (dev);
519 return;
522 arlan_command(dev, ARLAN_COMMAND_TX);
524 priv->Conf->driverRetransmissions++;
525 priv->retransmissions++;
527 IFDEBUG(ARLAN_DEBUG_TX_CHAIN) printk("Retransmit %d bytes \n", TXLAST(dev).length);
529 ARLAN_DEBUG_EXIT("arlan_retransmit_now");
534 static void arlan_registration_timer(unsigned long data)
536 struct net_device *dev = (struct net_device *) data;
537 struct arlan_private *priv = netdev_priv(dev);
538 int bh_mark_needed = 0;
539 int next_tick = 1;
540 long lostTime = ((long)jiffies - (long)priv->registrationLastSeen)
541 * (1000/HZ);
543 if (registrationBad(dev))
545 priv->registrationLostCount++;
546 if (lostTime > 7000 && lostTime < 7200)
548 printk(KERN_NOTICE "%s registration Lost \n", dev->name);
550 if (lostTime / priv->reRegisterExp > 2000)
551 arlan_command(dev, ARLAN_COMMAND_CLEAN_AND_CONF);
552 if (lostTime / (priv->reRegisterExp) > 3500)
553 arlan_command(dev, ARLAN_COMMAND_CLEAN_AND_RESET);
554 if (priv->reRegisterExp < 400)
555 priv->reRegisterExp += 2;
556 if (lostTime > 7200)
558 next_tick = HZ;
559 arlan_command(dev, ARLAN_COMMAND_CLEAN_AND_RESET);
562 else
564 if (priv->Conf->registrationMode && lostTime > 10000 &&
565 priv->registrationLostCount)
567 printk(KERN_NOTICE "%s registration is back after %ld milliseconds\n",
568 dev->name, lostTime);
570 priv->registrationLastSeen = jiffies;
571 priv->registrationLostCount = 0;
572 priv->reRegisterExp = 1;
573 if (!netif_running(dev) )
574 netif_wake_queue(dev);
575 if (time_after(priv->tx_last_sent,priv->tx_last_cleared) &&
576 time_after(jiffies, priv->tx_last_sent * 5*HZ) ){
577 arlan_command(dev, ARLAN_COMMAND_CLEAN_AND_RESET);
578 priv->tx_last_cleared = jiffies;
583 if (!registrationBad(dev) && priv->ReTransmitRequested)
585 IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
586 printk(KERN_ERR "Retransmit from timer \n");
587 priv->ReTransmitRequested = 0;
588 arlan_retransmit_now(dev);
590 if (!registrationBad(dev) &&
591 time_after(jiffies, priv->tx_done_delayed) &&
592 priv->tx_done_delayed != 0)
594 TXLAST(dev).offset = 0;
595 if (priv->txLast)
596 priv->txLast = 0;
597 else if (TXTAIL(dev).offset)
598 priv->txLast = 1;
599 if (TXLAST(dev).offset)
601 arlan_retransmit_now(dev);
602 dev->trans_start = jiffies;
604 if (!(TXHEAD(dev).offset && TXTAIL(dev).offset))
606 netif_wake_queue (dev);
608 priv->tx_done_delayed = 0;
609 bh_mark_needed = 1;
611 if (bh_mark_needed)
613 netif_wake_queue (dev);
615 arlan_process_interrupt(dev);
617 if (next_tick < priv->card_polling_interval)
618 next_tick = priv->card_polling_interval;
620 priv->timer.expires = jiffies + next_tick;
622 add_timer(&priv->timer);
626 #ifdef ARLAN_DEBUGGING
628 static void arlan_print_registers(struct net_device *dev, int line)
630 struct arlan_private *priv = netdev_priv(dev);
631 volatile struct arlan_shmem *arlan = priv->card;
633 u_char hostcpuLock, lancpuLock, controlRegister, cntrlRegImage,
634 txStatus, rxStatus, interruptInProgress, commandByte;
637 ARLAN_DEBUG_ENTRY("arlan_print_registers");
638 READSHM(interruptInProgress, arlan->interruptInProgress, u_char);
639 READSHM(hostcpuLock, arlan->hostcpuLock, u_char);
640 READSHM(lancpuLock, arlan->lancpuLock, u_char);
641 READSHM(controlRegister, arlan->controlRegister, u_char);
642 READSHM(cntrlRegImage, arlan->cntrlRegImage, u_char);
643 READSHM(txStatus, arlan->txStatus, u_char);
644 READSHM(rxStatus, arlan->rxStatus, u_char);
645 READSHM(commandByte, arlan->commandByte, u_char);
647 printk(KERN_WARNING "line %04d IP %02x HL %02x LL %02x CB %02x CR %02x CRI %02x TX %02x RX %02x\n",
648 line, interruptInProgress, hostcpuLock, lancpuLock, commandByte,
649 controlRegister, cntrlRegImage, txStatus, rxStatus);
651 ARLAN_DEBUG_EXIT("arlan_print_registers");
653 #endif
656 static int arlan_hw_tx(struct net_device *dev, char *buf, int length)
658 int i;
660 struct arlan_private *priv = netdev_priv(dev);
661 volatile struct arlan_shmem __iomem *arlan = priv->card;
662 struct arlan_conf_stru *conf = priv->Conf;
664 int tailStarts = 0x800;
665 int headEnds = 0x0;
668 ARLAN_DEBUG_ENTRY("arlan_hw_tx");
669 if (TXHEAD(dev).offset)
670 headEnds = (((TXHEAD(dev).offset + TXHEAD(dev).length - offsetof(struct arlan_shmem, txBuffer)) / 64) + 1) * 64;
671 if (TXTAIL(dev).offset)
672 tailStarts = 0x800 - (((TXTAIL(dev).offset - offsetof(struct arlan_shmem, txBuffer)) / 64) + 2) * 64;
675 if (!TXHEAD(dev).offset && length < tailStarts)
677 IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
678 printk(KERN_ERR "TXHEAD insert, tailStart %d\n", tailStarts);
680 TXHEAD(dev).offset =
681 offsetof(struct arlan_shmem, txBuffer);
682 TXHEAD(dev).length = length - ARLAN_FAKE_HDR_LEN;
683 for (i = 0; i < 6; i++)
684 TXHEAD(dev).dest[i] = buf[i];
685 TXHEAD(dev).clear = conf->txClear;
686 TXHEAD(dev).retries = conf->txRetries; /* 0 is use default */
687 TXHEAD(dev).routing = conf->txRouting;
688 TXHEAD(dev).scrambled = conf->txScrambled;
689 memcpy_toio((char __iomem *)arlan + TXHEAD(dev).offset, buf + ARLAN_FAKE_HDR_LEN, TXHEAD(dev).length);
691 else if (!TXTAIL(dev).offset && length < (0x800 - headEnds))
693 IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
694 printk(KERN_ERR "TXTAIL insert, headEnd %d\n", headEnds);
696 TXTAIL(dev).offset =
697 offsetof(struct arlan_shmem, txBuffer) + 0x800 - (length / 64 + 2) * 64;
698 TXTAIL(dev).length = length - ARLAN_FAKE_HDR_LEN;
699 for (i = 0; i < 6; i++)
700 TXTAIL(dev).dest[i] = buf[i];
701 TXTAIL(dev).clear = conf->txClear;
702 TXTAIL(dev).retries = conf->txRetries;
703 TXTAIL(dev).routing = conf->txRouting;
704 TXTAIL(dev).scrambled = conf->txScrambled;
705 memcpy_toio(((char __iomem *)arlan + TXTAIL(dev).offset), buf + ARLAN_FAKE_HDR_LEN, TXTAIL(dev).length);
707 else
709 netif_stop_queue (dev);
710 IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
711 printk(KERN_ERR "TX TAIL & HEAD full, return, tailStart %d headEnd %d\n", tailStarts, headEnds);
712 return -1;
714 priv->out_bytes += length;
715 priv->out_bytes10 += length;
716 if (conf->measure_rate < 1)
717 conf->measure_rate = 1;
718 if (time_after(jiffies, priv->out_time + conf->measure_rate * HZ))
720 conf->out_speed = priv->out_bytes / conf->measure_rate;
721 priv->out_bytes = 0;
722 priv->out_time = jiffies;
724 if (time_after(jiffies, priv->out_time10 + conf->measure_rate * 10*HZ))
726 conf->out_speed10 = priv->out_bytes10 / (10 * conf->measure_rate);
727 priv->out_bytes10 = 0;
728 priv->out_time10 = jiffies;
730 if (TXHEAD(dev).offset && TXTAIL(dev).offset)
732 netif_stop_queue (dev);
733 return 0;
735 else
736 netif_start_queue (dev);
739 IFDEBUG(ARLAN_DEBUG_HEADER_DUMP)
740 printk(KERN_WARNING "%s Transmit t %2x:%2x:%2x:%2x:%2x:%2x f %2x:%2x:%2x:%2x:%2x:%2x \n", dev->name,
741 (unsigned char) buf[0], (unsigned char) buf[1], (unsigned char) buf[2], (unsigned char) buf[3],
742 (unsigned char) buf[4], (unsigned char) buf[5], (unsigned char) buf[6], (unsigned char) buf[7],
743 (unsigned char) buf[8], (unsigned char) buf[9], (unsigned char) buf[10], (unsigned char) buf[11]);
745 IFDEBUG(ARLAN_DEBUG_TX_CHAIN) printk(KERN_ERR "TX command prepare for buffer %d\n", priv->txLast);
747 arlan_command(dev, ARLAN_COMMAND_TX);
749 priv->tx_last_sent = jiffies;
751 IFDEBUG(ARLAN_DEBUG_TX_CHAIN) printk("%s TX Qued %d bytes \n", dev->name, length);
753 ARLAN_DEBUG_EXIT("arlan_hw_tx");
755 return 0;
759 static int arlan_hw_config(struct net_device *dev)
761 struct arlan_private *priv = netdev_priv(dev);
762 volatile struct arlan_shmem __iomem *arlan = priv->card;
763 struct arlan_conf_stru *conf = priv->Conf;
765 ARLAN_DEBUG_ENTRY("arlan_hw_config");
767 printk(KERN_NOTICE "%s arlan configure called \n", dev->name);
768 if (arlan_EEPROM_bad)
769 printk(KERN_NOTICE "arlan configure with eeprom bad option \n");
772 WRITESHM(arlan->spreadingCode, conf->spreadingCode, u_char);
773 WRITESHM(arlan->channelSet, conf->channelSet, u_char);
775 if (arlan_EEPROM_bad)
776 WRITESHM(arlan->defaultChannelSet, conf->channelSet, u_char);
778 WRITESHM(arlan->channelNumber, conf->channelNumber, u_char);
780 WRITESHM(arlan->scramblingDisable, conf->scramblingDisable, u_char);
781 WRITESHM(arlan->txAttenuation, conf->txAttenuation, u_char);
783 WRITESHM(arlan->systemId, conf->systemId, u_int);
785 WRITESHM(arlan->maxRetries, conf->maxRetries, u_char);
786 WRITESHM(arlan->receiveMode, conf->receiveMode, u_char);
787 WRITESHM(arlan->priority, conf->priority, u_char);
788 WRITESHM(arlan->rootOrRepeater, conf->rootOrRepeater, u_char);
789 WRITESHM(arlan->SID, conf->SID, u_int);
791 WRITESHM(arlan->registrationMode, conf->registrationMode, u_char);
793 WRITESHM(arlan->registrationFill, conf->registrationFill, u_char);
794 WRITESHM(arlan->localTalkAddress, conf->localTalkAddress, u_char);
795 WRITESHM(arlan->codeFormat, conf->codeFormat, u_char);
796 WRITESHM(arlan->numChannels, conf->numChannels, u_char);
797 WRITESHM(arlan->channel1, conf->channel1, u_char);
798 WRITESHM(arlan->channel2, conf->channel2, u_char);
799 WRITESHM(arlan->channel3, conf->channel3, u_char);
800 WRITESHM(arlan->channel4, conf->channel4, u_char);
801 WRITESHM(arlan->radioNodeId, conf->radioNodeId, u_short);
802 WRITESHM(arlan->SID, conf->SID, u_int);
803 WRITESHM(arlan->waitTime, conf->waitTime, u_short);
804 WRITESHM(arlan->lParameter, conf->lParameter, u_short);
805 memcpy_toio(&(arlan->_15), &(conf->_15), 3);
806 WRITESHM(arlan->_15, conf->_15, u_short);
807 WRITESHM(arlan->headerSize, conf->headerSize, u_short);
808 if (arlan_EEPROM_bad)
809 WRITESHM(arlan->hardwareType, conf->hardwareType, u_char);
810 WRITESHM(arlan->radioType, conf->radioType, u_char);
811 if (arlan_EEPROM_bad)
812 WRITESHM(arlan->radioModule, conf->radioType, u_char);
814 memcpy_toio(arlan->encryptionKey + keyStart, encryptionKey, 8);
815 memcpy_toio(arlan->name, conf->siteName, 16);
817 WRITESHMB(arlan->commandByte, ARLAN_COM_INT | ARLAN_COM_CONF); /* do configure */
818 memset_io(arlan->commandParameter, 0, 0xf); /* 0xf */
819 memset_io(arlan->commandParameter + 1, 0, 2);
820 if (conf->writeEEPROM)
822 memset_io(arlan->commandParameter, conf->writeEEPROM, 1);
823 // conf->writeEEPROM=0;
825 if (conf->registrationMode && conf->registrationInterrupts)
826 memset_io(arlan->commandParameter + 3, 1, 1);
827 else
828 memset_io(arlan->commandParameter + 3, 0, 1);
830 priv->irq_test_done = 0;
832 if (conf->tx_queue_len)
833 dev->tx_queue_len = conf->tx_queue_len;
834 udelay(100);
836 ARLAN_DEBUG_EXIT("arlan_hw_config");
837 return 0;
841 static int arlan_read_card_configuration(struct net_device *dev)
843 u_char tlx415;
844 struct arlan_private *priv = netdev_priv(dev);
845 volatile struct arlan_shmem __iomem *arlan = priv->card;
846 struct arlan_conf_stru *conf = priv->Conf;
848 ARLAN_DEBUG_ENTRY("arlan_read_card_configuration");
850 if (radioNodeId == radioNodeIdUNKNOWN)
852 READSHM(conf->radioNodeId, arlan->radioNodeId, u_short);
854 else
855 conf->radioNodeId = radioNodeId;
857 if (SID == SIDUNKNOWN)
859 READSHM(conf->SID, arlan->SID, u_int);
861 else conf->SID = SID;
863 if (spreadingCode == spreadingCodeUNKNOWN)
865 READSHM(conf->spreadingCode, arlan->spreadingCode, u_char);
867 else
868 conf->spreadingCode = spreadingCode;
870 if (channelSet == channelSetUNKNOWN)
872 READSHM(conf->channelSet, arlan->channelSet, u_char);
874 else conf->channelSet = channelSet;
876 if (channelNumber == channelNumberUNKNOWN)
878 READSHM(conf->channelNumber, arlan->channelNumber, u_char);
880 else conf->channelNumber = channelNumber;
882 READSHM(conf->scramblingDisable, arlan->scramblingDisable, u_char);
883 READSHM(conf->txAttenuation, arlan->txAttenuation, u_char);
885 if (systemId == systemIdUNKNOWN)
887 READSHM(conf->systemId, arlan->systemId, u_int);
889 else conf->systemId = systemId;
891 READSHM(conf->maxDatagramSize, arlan->maxDatagramSize, u_short);
892 READSHM(conf->maxFrameSize, arlan->maxFrameSize, u_short);
893 READSHM(conf->maxRetries, arlan->maxRetries, u_char);
894 READSHM(conf->receiveMode, arlan->receiveMode, u_char);
895 READSHM(conf->priority, arlan->priority, u_char);
896 READSHM(conf->rootOrRepeater, arlan->rootOrRepeater, u_char);
898 if (SID == SIDUNKNOWN)
900 READSHM(conf->SID, arlan->SID, u_int);
902 else conf->SID = SID;
904 if (registrationMode == registrationModeUNKNOWN)
906 READSHM(conf->registrationMode, arlan->registrationMode, u_char);
908 else conf->registrationMode = registrationMode;
910 READSHM(conf->registrationFill, arlan->registrationFill, u_char);
911 READSHM(conf->localTalkAddress, arlan->localTalkAddress, u_char);
912 READSHM(conf->codeFormat, arlan->codeFormat, u_char);
913 READSHM(conf->numChannels, arlan->numChannels, u_char);
914 READSHM(conf->channel1, arlan->channel1, u_char);
915 READSHM(conf->channel2, arlan->channel2, u_char);
916 READSHM(conf->channel3, arlan->channel3, u_char);
917 READSHM(conf->channel4, arlan->channel4, u_char);
918 READSHM(conf->waitTime, arlan->waitTime, u_short);
919 READSHM(conf->lParameter, arlan->lParameter, u_short);
920 READSHM(conf->_15, arlan->_15, u_short);
921 READSHM(conf->headerSize, arlan->headerSize, u_short);
922 READSHM(conf->hardwareType, arlan->hardwareType, u_char);
923 READSHM(conf->radioType, arlan->radioModule, u_char);
925 if (conf->radioType == 0)
926 conf->radioType = 0xc;
928 WRITESHM(arlan->configStatus, 0xA5, u_char);
929 READSHM(tlx415, arlan->configStatus, u_char);
931 if (tlx415 != 0xA5)
932 printk(KERN_INFO "%s tlx415 chip \n", dev->name);
934 conf->txClear = 0;
935 conf->txRetries = 1;
936 conf->txRouting = 1;
937 conf->txScrambled = 0;
938 conf->rxParameter = 1;
939 conf->txTimeoutMs = 4000;
940 conf->waitCardTimeout = 100000;
941 conf->receiveMode = ARLAN_RCV_CLEAN;
942 memcpy_fromio(conf->siteName, arlan->name, 16);
943 conf->siteName[16] = '\0';
944 conf->retries = retries;
945 conf->tx_delay_ms = tx_delay_ms;
946 conf->ReTransmitPacketMaxSize = 200;
947 conf->waitReTransmitPacketMaxSize = 200;
948 conf->txAckTimeoutMs = 900;
949 conf->fastReTransCount = 3;
951 ARLAN_DEBUG_EXIT("arlan_read_card_configuration");
953 return 0;
957 static int lastFoundAt = 0xbe000;
961 * This is the real probe routine. Linux has a history of friendly device
962 * probes on the ISA bus. A good device probes avoids doing writes, and
963 * verifies that the correct device exists and functions.
965 #define ARLAN_SHMEM_SIZE 0x2000
966 static int __init arlan_check_fingerprint(unsigned long memaddr)
968 static const char probeText[] = "TELESYSTEM SLW INC. ARLAN \0";
969 volatile struct arlan_shmem __iomem *arlan = (struct arlan_shmem *) memaddr;
970 unsigned long paddr = virt_to_phys((void *) memaddr);
971 char tempBuf[49];
973 ARLAN_DEBUG_ENTRY("arlan_check_fingerprint");
975 if (!request_mem_region(paddr, ARLAN_SHMEM_SIZE, "arlan")) {
976 // printk(KERN_WARNING "arlan: memory region %lx excluded from probing \n",paddr);
977 return -ENODEV;
980 memcpy_fromio(tempBuf, arlan->textRegion, 29);
981 tempBuf[30] = 0;
983 /* check for card at this address */
984 if (0 != strncmp(tempBuf, probeText, 29)){
985 release_mem_region(paddr, ARLAN_SHMEM_SIZE);
986 return -ENODEV;
989 // printk(KERN_INFO "arlan found at 0x%x \n",memaddr);
990 ARLAN_DEBUG_EXIT("arlan_check_fingerprint");
992 return 0;
995 static int arlan_change_mtu(struct net_device *dev, int new_mtu)
997 struct arlan_private *priv = netdev_priv(dev);
998 struct arlan_conf_stru *conf = priv->Conf;
1000 ARLAN_DEBUG_ENTRY("arlan_change_mtu");
1001 if (new_mtu > 2032)
1002 return -EINVAL;
1003 dev->mtu = new_mtu;
1004 if (new_mtu < 256)
1005 new_mtu = 256; /* cards book suggests 1600 */
1006 conf->maxDatagramSize = new_mtu;
1007 conf->maxFrameSize = new_mtu + 48;
1009 arlan_command(dev, ARLAN_COMMAND_CLEAN_AND_CONF);
1010 printk(KERN_NOTICE "%s mtu changed to %d \n", dev->name, new_mtu);
1012 ARLAN_DEBUG_EXIT("arlan_change_mtu");
1014 return 0;
1017 static int arlan_mac_addr(struct net_device *dev, void *p)
1019 struct sockaddr *addr = p;
1022 ARLAN_DEBUG_ENTRY("arlan_mac_addr");
1023 return -EINVAL;
1025 if (!netif_running(dev))
1026 return -EBUSY;
1027 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
1029 ARLAN_DEBUG_EXIT("arlan_mac_addr");
1030 return 0;
1033 static const struct net_device_ops arlan_netdev_ops = {
1034 .ndo_open = arlan_open,
1035 .ndo_stop = arlan_close,
1036 .ndo_start_xmit = arlan_tx,
1037 .ndo_get_stats = arlan_statistics,
1038 .ndo_set_multicast_list = arlan_set_multicast,
1039 .ndo_change_mtu = arlan_change_mtu,
1040 .ndo_set_mac_address = arlan_mac_addr,
1041 .ndo_tx_timeout = arlan_tx_timeout,
1042 .ndo_validate_addr = eth_validate_addr,
1045 static int __init arlan_setup_device(struct net_device *dev, int num)
1047 struct arlan_private *ap = netdev_priv(dev);
1048 int err;
1050 ARLAN_DEBUG_ENTRY("arlan_setup_device");
1052 ap->conf = (struct arlan_shmem *)(ap+1);
1054 dev->tx_queue_len = tx_queue_len;
1055 dev->netdev_ops = &arlan_netdev_ops;
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 %llx, \n ", dev->name,
1089 (u64) 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 NETDEV_TX_BUSY;
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 dev->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)
1474 if (dmi->dmi_addrlen == 6) {
1475 if (arlan_debug & ARLAN_DEBUG_HEADER_DUMP)
1476 printk(KERN_ERR "%s mcl %pM\n",
1477 dev->name, dmi->dmi_addr);
1478 for (i = 0; i < 6; i++)
1479 if (dmi->dmi_addr[i] != hw_dst_addr[i])
1480 break;
1481 if (i == 6)
1482 break;
1483 } else
1484 printk(KERN_ERR "%s: invalid multicast address length given.\n", dev->name);
1485 dmi = dmi->next;
1487 /* we reach here if multicast filtering is on and packet
1488 * is multicast and not for receive */
1489 goto end_of_interrupt;
1492 #endif // ARLAN_MULTICAST
1493 /* multicast filtering ends here */
1494 pkt_len += ARLAN_FAKE_HDR_LEN;
1496 skb = dev_alloc_skb(pkt_len + 4);
1497 if (skb == NULL)
1499 printk(KERN_ERR "%s: Memory squeeze, dropping packet.\n", dev->name);
1500 dev->stats.rx_dropped++;
1501 break;
1503 skb_reserve(skb, 2);
1504 skbtmp = skb_put(skb, pkt_len);
1506 memcpy_fromio(skbtmp + ARLAN_FAKE_HDR_LEN, ((char __iomem *) arlan) + rxOffset, pkt_len - ARLAN_FAKE_HDR_LEN);
1507 memcpy_fromio(skbtmp, arlan->ultimateDestAddress, 6);
1508 memcpy_fromio(skbtmp + 6, arlan->rxSrc, 6);
1509 WRITESHMB(arlan->rxStatus, 0x00);
1510 arlan_command(dev, ARLAN_COMMAND_RX);
1512 IFDEBUG(ARLAN_DEBUG_HEADER_DUMP)
1514 char immedDestAddress[6];
1515 char immedSrcAddress[6];
1516 memcpy_fromio(immedDestAddress, arlan->immedDestAddress, 6);
1517 memcpy_fromio(immedSrcAddress, arlan->immedSrcAddress, 6);
1519 printk(KERN_WARNING "%s t %pM f %pM imd %pM ims %pM\n",
1520 dev->name, skbtmp,
1521 &skbtmp[6],
1522 immedDestAddress,
1523 immedSrcAddress);
1525 skb->protocol = eth_type_trans(skb, dev);
1526 IFDEBUG(ARLAN_DEBUG_HEADER_DUMP)
1527 if (skb->protocol != 0x608 && skb->protocol != 0x8)
1529 for (i = 0; i <= 22; i++)
1530 printk("%02x:", (u_char) skbtmp[i + 12]);
1531 printk(KERN_ERR "\n");
1532 printk(KERN_WARNING "arlan kernel pkt type trans %x \n", skb->protocol);
1534 netif_rx(skb);
1535 dev->stats.rx_packets++;
1536 dev->stats.rx_bytes += pkt_len;
1538 break;
1540 default:
1541 printk(KERN_ERR "arlan intr: received unknown status\n");
1542 dev->stats.rx_crc_errors++;
1543 break;
1545 ARLAN_DEBUG_EXIT("arlan_rx_interrupt");
1548 static void arlan_process_interrupt(struct net_device *dev)
1550 struct arlan_private *priv = netdev_priv(dev);
1551 volatile struct arlan_shmem __iomem *arlan = priv->card;
1552 u_char rxStatus = READSHMB(arlan->rxStatus);
1553 u_char txStatus = READSHMB(arlan->txStatus);
1554 u_short rxOffset = READSHMS(arlan->rxOffset);
1555 u_short pkt_len = READSHMS(arlan->rxLength);
1556 int interrupt_count = 0;
1558 ARLAN_DEBUG_ENTRY("arlan_process_interrupt");
1560 if (test_and_set_bit(0, (void *) &priv->interrupt_processing_active))
1562 if (arlan_debug & ARLAN_DEBUG_CHAIN_LOCKS)
1563 printk(KERN_ERR "interrupt chain reentering \n");
1564 goto end_int_process;
1566 while ((rxStatus || txStatus || priv->interrupt_ack_requested)
1567 && (interrupt_count < 5))
1569 if (rxStatus)
1570 priv->last_rx_int_ack_time = jiffies;
1572 arlan_command(dev, ARLAN_COMMAND_INT_ACK);
1573 arlan_command(dev, ARLAN_COMMAND_INT_ENABLE);
1575 IFDEBUG(ARLAN_DEBUG_INTERRUPT)
1576 printk(KERN_ERR "%s: got IRQ rx %x tx %x comm %x rxOff %x rxLen %x \n",
1577 dev->name, rxStatus, txStatus, READSHMB(arlan->commandByte),
1578 rxOffset, pkt_len);
1580 if (rxStatus == 0 && txStatus == 0)
1582 if (priv->irq_test_done)
1584 if (!registrationBad(dev))
1585 IFDEBUG(ARLAN_DEBUG_INTERRUPT) printk(KERN_ERR "%s unknown interrupt(nop? regLost ?) reason tx %d rx %d ",
1586 dev->name, txStatus, rxStatus);
1587 } else {
1588 IFDEBUG(ARLAN_DEBUG_INTERRUPT)
1589 printk(KERN_INFO "%s irq $%d test OK \n", dev->name, dev->irq);
1592 priv->interrupt_ack_requested = 0;
1593 goto ends;
1595 if (txStatus != 0)
1597 WRITESHMB(arlan->txStatus, 0x00);
1598 arlan_tx_done_interrupt(dev, txStatus);
1599 goto ends;
1601 if (rxStatus == 1 || rxStatus == 2)
1602 { /* a packet waiting */
1603 arlan_rx_interrupt(dev, rxStatus, rxOffset, pkt_len);
1604 goto ends;
1606 if (rxStatus > 2 && rxStatus < 0xff)
1608 WRITESHMB(arlan->rxStatus, 0x00);
1609 printk(KERN_ERR "%s unknown rxStatus reason tx %d rx %d ",
1610 dev->name, txStatus, rxStatus);
1611 goto ends;
1613 if (rxStatus == 0xff)
1615 WRITESHMB(arlan->rxStatus, 0x00);
1616 arlan_command(dev, ARLAN_COMMAND_RX);
1617 if (registrationBad(dev))
1618 netif_device_detach(dev);
1619 if (!registrationBad(dev))
1621 priv->registrationLastSeen = jiffies;
1622 if (!netif_queue_stopped(dev) && !priv->under_reset && !priv->under_config)
1623 netif_wake_queue (dev);
1625 goto ends;
1627 ends:
1629 arlan_command_process(dev);
1631 rxStatus = READSHMB(arlan->rxStatus);
1632 txStatus = READSHMB(arlan->txStatus);
1633 rxOffset = READSHMS(arlan->rxOffset);
1634 pkt_len = READSHMS(arlan->rxLength);
1637 priv->irq_test_done = 1;
1639 interrupt_count++;
1641 priv->interrupt_processing_active = 0;
1643 end_int_process:
1644 arlan_command_process(dev);
1646 ARLAN_DEBUG_EXIT("arlan_process_interrupt");
1647 return;
1650 static irqreturn_t arlan_interrupt(int irq, void *dev_id)
1652 struct net_device *dev = dev_id;
1653 struct arlan_private *priv = netdev_priv(dev);
1654 volatile struct arlan_shmem __iomem *arlan = priv->card;
1655 u_char rxStatus = READSHMB(arlan->rxStatus);
1656 u_char txStatus = READSHMB(arlan->txStatus);
1658 ARLAN_DEBUG_ENTRY("arlan_interrupt");
1661 if (!rxStatus && !txStatus)
1662 priv->interrupt_ack_requested++;
1664 arlan_process_interrupt(dev);
1666 priv->irq_test_done = 1;
1668 ARLAN_DEBUG_EXIT("arlan_interrupt");
1669 return IRQ_HANDLED;
1674 static int arlan_close(struct net_device *dev)
1676 struct arlan_private *priv = netdev_priv(dev);
1678 ARLAN_DEBUG_ENTRY("arlan_close");
1680 del_timer_sync(&priv->timer);
1682 arlan_command(dev, ARLAN_COMMAND_POWERDOWN);
1684 IFDEBUG(ARLAN_DEBUG_STARTUP)
1685 printk(KERN_NOTICE "%s: Closing device\n", dev->name);
1687 netif_stop_queue(dev);
1688 free_irq(dev->irq, dev);
1690 ARLAN_DEBUG_EXIT("arlan_close");
1691 return 0;
1694 #ifdef ARLAN_DEBUGGING
1695 static long alignLong(volatile u_char * ptr)
1697 long ret;
1698 memcpy_fromio(&ret, (void *) ptr, 4);
1699 return ret;
1701 #endif
1704 * Get the current statistics.
1705 * This may be called with the card open or closed.
1708 static struct net_device_stats *arlan_statistics(struct net_device *dev)
1710 struct arlan_private *priv = netdev_priv(dev);
1711 volatile struct arlan_shmem __iomem *arlan = priv->card;
1714 ARLAN_DEBUG_ENTRY("arlan_statistics");
1716 /* Update the statistics from the device registers. */
1718 READSHM(dev->stats.collisions, arlan->numReTransmissions, u_int);
1719 READSHM(dev->stats.rx_crc_errors, arlan->numCRCErrors, u_int);
1720 READSHM(dev->stats.rx_dropped, arlan->numFramesDiscarded, u_int);
1721 READSHM(dev->stats.rx_fifo_errors, arlan->numRXBufferOverflows, u_int);
1722 READSHM(dev->stats.rx_frame_errors, arlan->numReceiveFramesLost, u_int);
1723 READSHM(dev->stats.rx_over_errors, arlan->numRXOverruns, u_int);
1724 READSHM(dev->stats.rx_packets, arlan->numDatagramsReceived, u_int);
1725 READSHM(dev->stats.tx_aborted_errors, arlan->numAbortErrors, u_int);
1726 READSHM(dev->stats.tx_carrier_errors, arlan->numStatusTimeouts, u_int);
1727 READSHM(dev->stats.tx_dropped, arlan->numDatagramsDiscarded, u_int);
1728 READSHM(dev->stats.tx_fifo_errors, arlan->numTXUnderruns, u_int);
1729 READSHM(dev->stats.tx_packets, arlan->numDatagramsTransmitted, u_int);
1730 READSHM(dev->stats.tx_window_errors, arlan->numHoldOffs, u_int);
1732 ARLAN_DEBUG_EXIT("arlan_statistics");
1734 return &dev->stats;
1738 static void arlan_set_multicast(struct net_device *dev)
1740 struct arlan_private *priv = netdev_priv(dev);
1741 volatile struct arlan_shmem __iomem *arlan = priv->card;
1742 struct arlan_conf_stru *conf = priv->Conf;
1743 int board_conf_needed = 0;
1746 ARLAN_DEBUG_ENTRY("arlan_set_multicast");
1748 if (dev->flags & IFF_PROMISC)
1750 unsigned char recMode;
1751 READSHM(recMode, arlan->receiveMode, u_char);
1752 conf->receiveMode = (ARLAN_RCV_PROMISC | ARLAN_RCV_CONTROL);
1753 if (conf->receiveMode != recMode)
1754 board_conf_needed = 1;
1756 else
1758 /* turn off promiscuous mode */
1759 unsigned char recMode;
1760 READSHM(recMode, arlan->receiveMode, u_char);
1761 conf->receiveMode = ARLAN_RCV_CLEAN | ARLAN_RCV_CONTROL;
1762 if (conf->receiveMode != recMode)
1763 board_conf_needed = 1;
1765 if (board_conf_needed)
1766 arlan_command(dev, ARLAN_COMMAND_CONF);
1768 ARLAN_DEBUG_EXIT("arlan_set_multicast");
1772 struct net_device * __init arlan_probe(int unit)
1774 struct net_device *dev;
1775 int err;
1776 int m;
1778 ARLAN_DEBUG_ENTRY("arlan_probe");
1780 if (arlans_found == MAX_ARLANS)
1781 return ERR_PTR(-ENODEV);
1784 * Reserve space for local data and a copy of the shared memory
1785 * that is used by the /proc interface.
1787 dev = alloc_etherdev(sizeof(struct arlan_private)
1788 + sizeof(struct arlan_shmem));
1789 if (!dev)
1790 return ERR_PTR(-ENOMEM);
1792 if (unit >= 0) {
1793 sprintf(dev->name, "eth%d", unit);
1794 netdev_boot_setup_check(dev);
1796 if (dev->mem_start) {
1797 if (arlan_probe_here(dev, dev->mem_start) == 0)
1798 goto found;
1799 goto not_found;
1805 for (m = (int)phys_to_virt(lastFoundAt) + ARLAN_SHMEM_SIZE;
1806 m <= (int)phys_to_virt(0xDE000);
1807 m += ARLAN_SHMEM_SIZE)
1809 if (arlan_probe_here(dev, m) == 0)
1811 lastFoundAt = (int)virt_to_phys((void*)m);
1812 goto found;
1816 if (lastFoundAt == 0xbe000)
1817 printk(KERN_ERR "arlan: No Arlan devices found \n");
1819 not_found:
1820 free_netdev(dev);
1821 return ERR_PTR(-ENODEV);
1823 found:
1824 err = arlan_setup_device(dev, arlans_found);
1825 if (err)
1826 dev = ERR_PTR(err);
1827 else if (!arlans_found++)
1828 printk(KERN_INFO "Arlan driver %s\n", arlan_version);
1830 return dev;
1833 #ifdef MODULE
1834 int __init init_module(void)
1836 int i = 0;
1838 ARLAN_DEBUG_ENTRY("init_module");
1840 if (channelSet != channelSetUNKNOWN || channelNumber != channelNumberUNKNOWN || systemId != systemIdUNKNOWN)
1841 return -EINVAL;
1843 for (i = 0; i < MAX_ARLANS; i++) {
1844 struct net_device *dev = arlan_probe(i);
1846 if (IS_ERR(dev))
1847 return PTR_ERR(dev);
1849 init_arlan_proc();
1850 printk(KERN_INFO "Arlan driver %s\n", arlan_version);
1851 ARLAN_DEBUG_EXIT("init_module");
1852 return 0;
1856 void __exit cleanup_module(void)
1858 int i = 0;
1859 struct net_device *dev;
1861 ARLAN_DEBUG_ENTRY("cleanup_module");
1863 IFDEBUG(ARLAN_DEBUG_SHUTDOWN)
1864 printk(KERN_INFO "arlan: unloading module\n");
1866 cleanup_arlan_proc();
1868 for (i = 0; i < MAX_ARLANS; i++)
1870 dev = arlan_device[i];
1871 if (dev) {
1872 arlan_command(dev, ARLAN_COMMAND_POWERDOWN );
1874 unregister_netdev(dev);
1875 release_mem_region(virt_to_phys((void *) dev->mem_start),
1876 ARLAN_SHMEM_SIZE);
1877 free_netdev(dev);
1878 arlan_device[i] = NULL;
1882 ARLAN_DEBUG_EXIT("cleanup_module");
1886 #endif
1887 MODULE_LICENSE("GPL");