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
10 #if BITS_PER_LONG != 32
11 # error FIXME: this driver requires a 32-bit platform
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;
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;
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)");
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");
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) );\
115 #define ARLAN_DEBUG_ENTRY(name)
116 #define ARLAN_DEBUG_EXIT(name)
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 priv->stats.tx_errors++;
129 if (priv->Conf->tx_delay_ms)
131 priv->tx_done_delayed = jiffies + priv->Conf->tx_delay_ms * HZ / 1000 + 1;
135 priv->waiting_command_mask &= ~ARLAN_COMMAND_TX;
136 TXHEAD(dev).offset = 0;
137 TXTAIL(dev).offset = 0;
140 if (!priv->under_reset && !priv->under_config)
141 netif_wake_queue (dev);
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;
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))
198 priv->waiting_command_mask &= ~(ARLAN_COMMAND_LONG_WAIT_NOW | ARLAN_COMMAND_WAIT_NOW);
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;
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);
224 while ((READSHMB(arlan->resetFlag) ||
225 READSHMB(arlan->commandByte)) &&
226 conf->pre_Command_Wait > (i++) * 10)
230 if ((READSHMB(arlan->resetFlag) ||
231 READSHMB(arlan->commandByte)) &&
232 !(priv->waiting_command_mask & ARLAN_COMMAND_RESET))
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))
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)
285 netif_stop_queue (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);
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;
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;
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;
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)
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++)
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;
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");
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");
476 static inline void arlan_command_process(struct net_device *dev)
478 struct arlan_private *priv = netdev_priv(dev);
481 while (priv->waiting_command_mask && times < 8)
483 if (priv->waiting_command_mask)
485 if (arlan_command(dev, 0))
489 /* if long command, we won't repeat trying */ ;
490 if (priv->card_polling_interval > 1)
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)
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");
517 IFDEBUG(ARLAN_DEBUG_TX_CHAIN) printk(KERN_ERR "ReTransmit buff empty");
518 netif_wake_queue (dev);
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;
540 long lostTime = ((long)jiffies - (long)priv->registrationLastSeen)
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;
559 arlan_command(dev, ARLAN_COMMAND_CLEAN_AND_RESET);
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;
597 else if (TXTAIL(dev).offset)
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;
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");
656 static int arlan_hw_tx(struct net_device *dev, char *buf, int length)
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;
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);
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);
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);
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);
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;
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);
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");
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);
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;
836 ARLAN_DEBUG_EXIT("arlan_hw_config");
841 static int arlan_read_card_configuration(struct net_device *dev)
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);
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);
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);
932 printk(KERN_INFO "%s tlx415 chip \n", dev->name);
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");
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);
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);
980 memcpy_fromio(tempBuf, arlan->textRegion, 29);
983 /* check for card at this address */
984 if (0 != strncmp(tempBuf, probeText, 29)){
985 release_mem_region(paddr, ARLAN_SHMEM_SIZE);
989 // printk(KERN_INFO "arlan found at 0x%x \n",memaddr);
990 ARLAN_DEBUG_EXIT("arlan_check_fingerprint");
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");
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");
1017 static int arlan_mac_addr(struct net_device *dev, void *p)
1019 struct sockaddr *addr = p;
1022 ARLAN_DEBUG_ENTRY("arlan_mac_addr");
1025 if (!netif_running(dev))
1027 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
1029 ARLAN_DEBUG_EXIT("arlan_mac_addr");
1035 static int __init arlan_setup_device(struct net_device *dev, int num)
1037 struct arlan_private *ap = netdev_priv(dev);
1040 ARLAN_DEBUG_ENTRY("arlan_setup_device");
1042 ap->conf = (struct arlan_shmem *)(ap+1);
1044 dev->tx_queue_len = tx_queue_len;
1045 dev->open = arlan_open;
1046 dev->stop = arlan_close;
1047 dev->hard_start_xmit = arlan_tx;
1048 dev->get_stats = arlan_statistics;
1049 dev->set_multicast_list = arlan_set_multicast;
1050 dev->change_mtu = arlan_change_mtu;
1051 dev->set_mac_address = arlan_mac_addr;
1052 dev->tx_timeout = arlan_tx_timeout;
1053 dev->watchdog_timeo = 3*HZ;
1055 ap->irq_test_done = 0;
1056 ap->Conf = &arlan_conf[num];
1058 ap->Conf->pre_Command_Wait = 40;
1059 ap->Conf->rx_tweak1 = 30;
1060 ap->Conf->rx_tweak2 = 0;
1063 err = register_netdev(dev);
1065 release_mem_region(virt_to_phys((void *) dev->mem_start),
1070 arlan_device[num] = dev;
1071 ARLAN_DEBUG_EXIT("arlan_setup_device");
1075 static int __init arlan_probe_here(struct net_device *dev,
1076 unsigned long memaddr)
1078 struct arlan_private *ap = netdev_priv(dev);
1080 ARLAN_DEBUG_ENTRY("arlan_probe_here");
1082 if (arlan_check_fingerprint(memaddr))
1085 printk(KERN_NOTICE "%s: Arlan found at %x, \n ", dev->name,
1086 (int) virt_to_phys((void*)memaddr));
1088 ap->card = (void *) memaddr;
1089 dev->mem_start = memaddr;
1090 dev->mem_end = memaddr + ARLAN_SHMEM_SIZE-1;
1094 READSHM(dev->irq, ap->card->irqLevel, u_char);
1095 } else if (dev->irq == 2)
1098 arlan_read_card_configuration(dev);
1100 ARLAN_DEBUG_EXIT("arlan_probe_here");
1105 static int arlan_open(struct net_device *dev)
1107 struct arlan_private *priv = netdev_priv(dev);
1108 volatile struct arlan_shmem __iomem *arlan = priv->card;
1111 ARLAN_DEBUG_ENTRY("arlan_open");
1113 ret = request_irq(dev->irq, &arlan_interrupt, 0, dev->name, dev);
1116 printk(KERN_ERR "%s: unable to get IRQ %d .\n",
1117 dev->name, dev->irq);
1123 priv->lastReset = 0;
1125 memcpy_fromio(dev->dev_addr, arlan->lanCardNodeId, 6);
1126 memset(dev->broadcast, 0xff, 6);
1127 dev->tx_queue_len = tx_queue_len;
1128 priv->interrupt_processing_active = 0;
1129 spin_lock_init(&priv->lock);
1131 netif_start_queue (dev);
1133 priv->registrationLostCount = 0;
1134 priv->registrationLastSeen = jiffies;
1136 priv->tx_command_given = 0;
1137 priv->rx_command_given = 0;
1139 priv->reRegisterExp = 1;
1140 priv->tx_last_sent = jiffies - 1;
1141 priv->tx_last_cleared = jiffies;
1142 priv->Conf->writeEEPROM = 0;
1143 priv->Conf->registrationInterrupts = 1;
1145 init_timer(&priv->timer);
1146 priv->timer.expires = jiffies + HZ / 10;
1147 priv->timer.data = (unsigned long) dev;
1148 priv->timer.function = &arlan_registration_timer; /* timer handler */
1150 arlan_command(dev, ARLAN_COMMAND_POWERUP | ARLAN_COMMAND_LONG_WAIT_NOW);
1152 add_timer(&priv->timer);
1154 ARLAN_DEBUG_EXIT("arlan_open");
1159 static void arlan_tx_timeout (struct net_device *dev)
1161 printk(KERN_ERR "%s: arlan transmit timed out, kernel decided\n", dev->name);
1162 /* Try to restart the adaptor. */
1163 arlan_command(dev, ARLAN_COMMAND_CLEAN_AND_RESET);
1164 // dev->trans_start = jiffies;
1165 // netif_start_queue (dev);
1169 static int arlan_tx(struct sk_buff *skb, struct net_device *dev)
1174 ARLAN_DEBUG_ENTRY("arlan_tx");
1176 length = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
1179 if (length + 0x12 > 0x800) {
1180 printk(KERN_ERR "TX RING overflow \n");
1181 netif_stop_queue (dev);
1184 if (arlan_hw_tx(dev, buf, length) == -1)
1187 dev->trans_start = jiffies;
1191 arlan_process_interrupt(dev);
1192 ARLAN_DEBUG_EXIT("arlan_tx");
1196 arlan_process_interrupt(dev);
1197 netif_stop_queue (dev);
1198 ARLAN_DEBUG_EXIT("arlan_tx");
1203 static inline int DoNotReTransmitCrap(struct net_device *dev)
1205 struct arlan_private *priv = netdev_priv(dev);
1207 if (TXLAST(dev).length < priv->Conf->ReTransmitPacketMaxSize)
1213 static inline int DoNotWaitReTransmitCrap(struct net_device *dev)
1215 struct arlan_private *priv = netdev_priv(dev);
1217 if (TXLAST(dev).length < priv->Conf->waitReTransmitPacketMaxSize)
1222 static inline void arlan_queue_retransmit(struct net_device *dev)
1224 struct arlan_private *priv = netdev_priv(dev);
1226 ARLAN_DEBUG_ENTRY("arlan_queue_retransmit");
1228 if (DoNotWaitReTransmitCrap(dev))
1232 priv->ReTransmitRequested++;
1234 ARLAN_DEBUG_EXIT("arlan_queue_retransmit");
1237 static inline void RetryOrFail(struct net_device *dev)
1239 struct arlan_private *priv = netdev_priv(dev);
1241 ARLAN_DEBUG_ENTRY("RetryOrFail");
1243 if (priv->retransmissions > priv->Conf->retries ||
1244 DoNotReTransmitCrap(dev))
1248 else if (priv->bad <= priv->Conf->fastReTransCount)
1250 arlan_retransmit_now(dev);
1252 else arlan_queue_retransmit(dev);
1254 ARLAN_DEBUG_EXIT("RetryOrFail");
1258 static void arlan_tx_done_interrupt(struct net_device *dev, int status)
1260 struct arlan_private *priv = netdev_priv(dev);
1262 ARLAN_DEBUG_ENTRY("arlan_tx_done_interrupt");
1264 priv->tx_last_cleared = jiffies;
1265 priv->tx_command_given = 0;
1270 IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
1271 printk("arlan intr: transmit OK\n");
1272 priv->stats.tx_packets++;
1275 priv->retransmissions = 0;
1276 if (priv->Conf->tx_delay_ms)
1278 priv->tx_done_delayed = jiffies + (priv->Conf->tx_delay_ms * HZ) / 1000 + 1;
1282 TXLAST(dev).offset = 0;
1285 else if (TXTAIL(dev).offset)
1287 if (TXLAST(dev).offset)
1289 arlan_retransmit_now(dev);
1290 dev->trans_start = jiffies;
1292 if (!TXHEAD(dev).offset || !TXTAIL(dev).offset)
1294 netif_wake_queue (dev);
1302 IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
1303 printk("arlan intr: transmit timed out\n");
1305 //arlan_queue_retransmit(dev);
1312 IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
1313 printk("arlan intr: transmit max retries\n");
1316 //arlan_queue_retransmit(dev);
1323 IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
1324 printk("arlan intr: transmit aborted\n");
1326 arlan_queue_retransmit(dev);
1333 IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
1334 printk("arlan intr: transmit not registered\n");
1337 arlan_queue_retransmit(dev);
1343 IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
1344 printk("arlan intr: transmit destination full\n");
1347 //arlan_drop_tx(dev);
1348 arlan_queue_retransmit(dev);
1354 IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
1355 printk("arlan intr: transmit unknown ack\n");
1358 arlan_queue_retransmit(dev);
1364 IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
1365 printk("arlan intr: transmit dest mail box full\n");
1368 //arlan_drop_tx(dev);
1369 arlan_queue_retransmit(dev);
1375 IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
1376 printk("arlan intr: transmit root dest not reg.\n");
1379 //arlan_drop_tx(dev);
1380 arlan_queue_retransmit(dev);
1386 printk(KERN_ERR "arlan intr: transmit status unknown\n");
1393 ARLAN_DEBUG_EXIT("arlan_tx_done_interrupt");
1397 static void arlan_rx_interrupt(struct net_device *dev, u_char rxStatus, u_short rxOffset, u_short pkt_len)
1402 struct arlan_private *priv = netdev_priv(dev);
1403 volatile struct arlan_shmem __iomem *arlan = priv->card;
1404 struct arlan_conf_stru *conf = priv->Conf;
1407 ARLAN_DEBUG_ENTRY("arlan_rx_interrupt");
1408 // by spec, not WRITESHMB(arlan->rxStatus,0x00);
1409 // prohibited here arlan_command(dev, ARLAN_COMMAND_RX);
1411 if (pkt_len < 10 || pkt_len > 2048)
1413 printk(KERN_WARNING "%s: got too short or long packet, len %d \n", dev->name, pkt_len);
1416 if (rxOffset + pkt_len > 0x2000)
1418 printk("%s: got too long packet, len %d offset %x\n", dev->name, pkt_len, rxOffset);
1421 priv->in_bytes += pkt_len;
1422 priv->in_bytes10 += pkt_len;
1423 if (conf->measure_rate < 1)
1424 conf->measure_rate = 1;
1425 if (time_after(jiffies, priv->in_time + conf->measure_rate * HZ))
1427 conf->in_speed = priv->in_bytes / conf->measure_rate;
1429 priv->in_time = jiffies;
1431 if (time_after(jiffies, priv->in_time10 + conf->measure_rate * 10*HZ))
1433 conf->in_speed10 = priv->in_bytes10 / (10 * conf->measure_rate);
1434 priv->in_bytes10 = 0;
1435 priv->in_time10 = jiffies;
1437 DEBUGSHM(1, "arlan rcv pkt rxStatus= %d ", arlan->rxStatus, u_char);
1444 /* Malloc up new buffer. */
1445 struct sk_buff *skb;
1447 DEBUGSHM(50, "arlan recv pkt offs=%d\n", arlan->rxOffset, u_short);
1448 DEBUGSHM(1, "arlan rxFrmType = %d \n", arlan->rxFrmType, u_char);
1449 DEBUGSHM(1, KERN_INFO "arlan rx scrambled = %d \n", arlan->scrambled, u_char);
1451 /* here we do multicast filtering to avoid slow 8-bit memcopy */
1452 #ifdef ARLAN_MULTICAST
1453 if (!(dev->flags & IFF_ALLMULTI) &&
1454 !(dev->flags & IFF_PROMISC) &&
1457 char hw_dst_addr[6];
1458 struct dev_mc_list *dmi = dev->mc_list;
1461 memcpy_fromio(hw_dst_addr, arlan->ultimateDestAddress, 6);
1462 if (hw_dst_addr[0] == 0x01)
1465 if (hw_dst_addr[1] == 0x00)
1466 printk(KERN_ERR "%s mcast 0x0100 \n", dev->name);
1467 else if (hw_dst_addr[1] == 0x40)
1468 printk(KERN_ERR "%s m/bcast 0x0140 \n", dev->name);
1470 { if (dmi->dmi_addrlen == 6)
1472 DECLARE_MAC_BUF(mac);
1473 if (arlan_debug & ARLAN_DEBUG_HEADER_DUMP)
1474 printk(KERN_ERR "%s mcl %s\n",
1475 dev->name, print_mac(mac, dmi->dmi_addr));
1476 for (i = 0; i < 6; i++)
1477 if (dmi->dmi_addr[i] != hw_dst_addr[i])
1483 printk(KERN_ERR "%s: invalid multicast address length given.\n", dev->name);
1486 /* we reach here if multicast filtering is on and packet
1487 * is multicast and not for receive */
1488 goto end_of_interrupt;
1491 #endif // ARLAN_MULTICAST
1492 /* multicast filtering ends here */
1493 pkt_len += ARLAN_FAKE_HDR_LEN;
1495 skb = dev_alloc_skb(pkt_len + 4);
1498 printk(KERN_ERR "%s: Memory squeeze, dropping packet.\n", dev->name);
1499 priv->stats.rx_dropped++;
1502 skb_reserve(skb, 2);
1503 skbtmp = skb_put(skb, pkt_len);
1505 memcpy_fromio(skbtmp + ARLAN_FAKE_HDR_LEN, ((char __iomem *) arlan) + rxOffset, pkt_len - ARLAN_FAKE_HDR_LEN);
1506 memcpy_fromio(skbtmp, arlan->ultimateDestAddress, 6);
1507 memcpy_fromio(skbtmp + 6, arlan->rxSrc, 6);
1508 WRITESHMB(arlan->rxStatus, 0x00);
1509 arlan_command(dev, ARLAN_COMMAND_RX);
1511 IFDEBUG(ARLAN_DEBUG_HEADER_DUMP)
1513 char immedDestAddress[6];
1514 char immedSrcAddress[6];
1515 DECLARE_MAC_BUF(mac);
1516 DECLARE_MAC_BUF(mac2);
1517 DECLARE_MAC_BUF(mac3);
1518 DECLARE_MAC_BUF(mac4);
1519 memcpy_fromio(immedDestAddress, arlan->immedDestAddress, 6);
1520 memcpy_fromio(immedSrcAddress, arlan->immedSrcAddress, 6);
1522 printk(KERN_WARNING "%s t %s f %s imd %s ims %s\n",
1523 dev->name, print_mac(mac, skbtmp),
1524 print_mac(mac2, &skbtmp[6]),
1525 print_mac(mac3, immedDestAddress),
1526 print_mac(mac4, immedSrcAddress));
1528 skb->protocol = eth_type_trans(skb, dev);
1529 IFDEBUG(ARLAN_DEBUG_HEADER_DUMP)
1530 if (skb->protocol != 0x608 && skb->protocol != 0x8)
1532 for (i = 0; i <= 22; i++)
1533 printk("%02x:", (u_char) skbtmp[i + 12]);
1534 printk(KERN_ERR "\n");
1535 printk(KERN_WARNING "arlan kernel pkt type trans %x \n", skb->protocol);
1538 dev->last_rx = jiffies;
1539 priv->stats.rx_packets++;
1540 priv->stats.rx_bytes += pkt_len;
1545 printk(KERN_ERR "arlan intr: received unknown status\n");
1546 priv->stats.rx_crc_errors++;
1549 ARLAN_DEBUG_EXIT("arlan_rx_interrupt");
1552 static void arlan_process_interrupt(struct net_device *dev)
1554 struct arlan_private *priv = netdev_priv(dev);
1555 volatile struct arlan_shmem __iomem *arlan = priv->card;
1556 u_char rxStatus = READSHMB(arlan->rxStatus);
1557 u_char txStatus = READSHMB(arlan->txStatus);
1558 u_short rxOffset = READSHMS(arlan->rxOffset);
1559 u_short pkt_len = READSHMS(arlan->rxLength);
1560 int interrupt_count = 0;
1562 ARLAN_DEBUG_ENTRY("arlan_process_interrupt");
1564 if (test_and_set_bit(0, (void *) &priv->interrupt_processing_active))
1566 if (arlan_debug & ARLAN_DEBUG_CHAIN_LOCKS)
1567 printk(KERN_ERR "interrupt chain reentering \n");
1568 goto end_int_process;
1570 while ((rxStatus || txStatus || priv->interrupt_ack_requested)
1571 && (interrupt_count < 5))
1574 priv->last_rx_int_ack_time = jiffies;
1576 arlan_command(dev, ARLAN_COMMAND_INT_ACK);
1577 arlan_command(dev, ARLAN_COMMAND_INT_ENABLE);
1579 IFDEBUG(ARLAN_DEBUG_INTERRUPT)
1580 printk(KERN_ERR "%s: got IRQ rx %x tx %x comm %x rxOff %x rxLen %x \n",
1581 dev->name, rxStatus, txStatus, READSHMB(arlan->commandByte),
1584 if (rxStatus == 0 && txStatus == 0)
1586 if (priv->irq_test_done)
1588 if (!registrationBad(dev))
1589 IFDEBUG(ARLAN_DEBUG_INTERRUPT) printk(KERN_ERR "%s unknown interrupt(nop? regLost ?) reason tx %d rx %d ",
1590 dev->name, txStatus, rxStatus);
1592 IFDEBUG(ARLAN_DEBUG_INTERRUPT)
1593 printk(KERN_INFO "%s irq $%d test OK \n", dev->name, dev->irq);
1596 priv->interrupt_ack_requested = 0;
1601 WRITESHMB(arlan->txStatus, 0x00);
1602 arlan_tx_done_interrupt(dev, txStatus);
1605 if (rxStatus == 1 || rxStatus == 2)
1606 { /* a packet waiting */
1607 arlan_rx_interrupt(dev, rxStatus, rxOffset, pkt_len);
1610 if (rxStatus > 2 && rxStatus < 0xff)
1612 WRITESHMB(arlan->rxStatus, 0x00);
1613 printk(KERN_ERR "%s unknown rxStatus reason tx %d rx %d ",
1614 dev->name, txStatus, rxStatus);
1617 if (rxStatus == 0xff)
1619 WRITESHMB(arlan->rxStatus, 0x00);
1620 arlan_command(dev, ARLAN_COMMAND_RX);
1621 if (registrationBad(dev))
1622 netif_device_detach(dev);
1623 if (!registrationBad(dev))
1625 priv->registrationLastSeen = jiffies;
1626 if (!netif_queue_stopped(dev) && !priv->under_reset && !priv->under_config)
1627 netif_wake_queue (dev);
1633 arlan_command_process(dev);
1635 rxStatus = READSHMB(arlan->rxStatus);
1636 txStatus = READSHMB(arlan->txStatus);
1637 rxOffset = READSHMS(arlan->rxOffset);
1638 pkt_len = READSHMS(arlan->rxLength);
1641 priv->irq_test_done = 1;
1645 priv->interrupt_processing_active = 0;
1648 arlan_command_process(dev);
1650 ARLAN_DEBUG_EXIT("arlan_process_interrupt");
1654 static irqreturn_t arlan_interrupt(int irq, void *dev_id)
1656 struct net_device *dev = dev_id;
1657 struct arlan_private *priv = netdev_priv(dev);
1658 volatile struct arlan_shmem __iomem *arlan = priv->card;
1659 u_char rxStatus = READSHMB(arlan->rxStatus);
1660 u_char txStatus = READSHMB(arlan->txStatus);
1662 ARLAN_DEBUG_ENTRY("arlan_interrupt");
1665 if (!rxStatus && !txStatus)
1666 priv->interrupt_ack_requested++;
1668 arlan_process_interrupt(dev);
1670 priv->irq_test_done = 1;
1672 ARLAN_DEBUG_EXIT("arlan_interrupt");
1678 static int arlan_close(struct net_device *dev)
1680 struct arlan_private *priv = netdev_priv(dev);
1682 ARLAN_DEBUG_ENTRY("arlan_close");
1684 del_timer_sync(&priv->timer);
1686 arlan_command(dev, ARLAN_COMMAND_POWERDOWN);
1688 IFDEBUG(ARLAN_DEBUG_STARTUP)
1689 printk(KERN_NOTICE "%s: Closing device\n", dev->name);
1691 netif_stop_queue(dev);
1692 free_irq(dev->irq, dev);
1694 ARLAN_DEBUG_EXIT("arlan_close");
1698 #ifdef ARLAN_DEBUGGING
1699 static long alignLong(volatile u_char * ptr)
1702 memcpy_fromio(&ret, (void *) ptr, 4);
1708 * Get the current statistics.
1709 * This may be called with the card open or closed.
1712 static struct net_device_stats *arlan_statistics(struct net_device *dev)
1714 struct arlan_private *priv = netdev_priv(dev);
1715 volatile struct arlan_shmem __iomem *arlan = priv->card;
1718 ARLAN_DEBUG_ENTRY("arlan_statistics");
1720 /* Update the statistics from the device registers. */
1722 READSHM(priv->stats.collisions, arlan->numReTransmissions, u_int);
1723 READSHM(priv->stats.rx_crc_errors, arlan->numCRCErrors, u_int);
1724 READSHM(priv->stats.rx_dropped, arlan->numFramesDiscarded, u_int);
1725 READSHM(priv->stats.rx_fifo_errors, arlan->numRXBufferOverflows, u_int);
1726 READSHM(priv->stats.rx_frame_errors, arlan->numReceiveFramesLost, u_int);
1727 READSHM(priv->stats.rx_over_errors, arlan->numRXOverruns, u_int);
1728 READSHM(priv->stats.rx_packets, arlan->numDatagramsReceived, u_int);
1729 READSHM(priv->stats.tx_aborted_errors, arlan->numAbortErrors, u_int);
1730 READSHM(priv->stats.tx_carrier_errors, arlan->numStatusTimeouts, u_int);
1731 READSHM(priv->stats.tx_dropped, arlan->numDatagramsDiscarded, u_int);
1732 READSHM(priv->stats.tx_fifo_errors, arlan->numTXUnderruns, u_int);
1733 READSHM(priv->stats.tx_packets, arlan->numDatagramsTransmitted, u_int);
1734 READSHM(priv->stats.tx_window_errors, arlan->numHoldOffs, u_int);
1736 ARLAN_DEBUG_EXIT("arlan_statistics");
1738 return &priv->stats;
1742 static void arlan_set_multicast(struct net_device *dev)
1744 struct arlan_private *priv = netdev_priv(dev);
1745 volatile struct arlan_shmem __iomem *arlan = priv->card;
1746 struct arlan_conf_stru *conf = priv->Conf;
1747 int board_conf_needed = 0;
1750 ARLAN_DEBUG_ENTRY("arlan_set_multicast");
1752 if (dev->flags & IFF_PROMISC)
1754 unsigned char recMode;
1755 READSHM(recMode, arlan->receiveMode, u_char);
1756 conf->receiveMode = (ARLAN_RCV_PROMISC | ARLAN_RCV_CONTROL);
1757 if (conf->receiveMode != recMode)
1758 board_conf_needed = 1;
1762 /* turn off promiscuous mode */
1763 unsigned char recMode;
1764 READSHM(recMode, arlan->receiveMode, u_char);
1765 conf->receiveMode = ARLAN_RCV_CLEAN | ARLAN_RCV_CONTROL;
1766 if (conf->receiveMode != recMode)
1767 board_conf_needed = 1;
1769 if (board_conf_needed)
1770 arlan_command(dev, ARLAN_COMMAND_CONF);
1772 ARLAN_DEBUG_EXIT("arlan_set_multicast");
1776 struct net_device * __init arlan_probe(int unit)
1778 struct net_device *dev;
1782 ARLAN_DEBUG_ENTRY("arlan_probe");
1784 if (arlans_found == MAX_ARLANS)
1785 return ERR_PTR(-ENODEV);
1788 * Reserve space for local data and a copy of the shared memory
1789 * that is used by the /proc interface.
1791 dev = alloc_etherdev(sizeof(struct arlan_private)
1792 + sizeof(struct arlan_shmem));
1794 return ERR_PTR(-ENOMEM);
1797 sprintf(dev->name, "eth%d", unit);
1798 netdev_boot_setup_check(dev);
1800 if (dev->mem_start) {
1801 if (arlan_probe_here(dev, dev->mem_start) == 0)
1809 for (m = (int)phys_to_virt(lastFoundAt) + ARLAN_SHMEM_SIZE;
1810 m <= (int)phys_to_virt(0xDE000);
1811 m += ARLAN_SHMEM_SIZE)
1813 if (arlan_probe_here(dev, m) == 0)
1815 lastFoundAt = (int)virt_to_phys((void*)m);
1820 if (lastFoundAt == 0xbe000)
1821 printk(KERN_ERR "arlan: No Arlan devices found \n");
1825 return ERR_PTR(-ENODEV);
1828 err = arlan_setup_device(dev, arlans_found);
1831 else if (!arlans_found++)
1832 printk(KERN_INFO "Arlan driver %s\n", arlan_version);
1838 int __init init_module(void)
1842 ARLAN_DEBUG_ENTRY("init_module");
1844 if (channelSet != channelSetUNKNOWN || channelNumber != channelNumberUNKNOWN || systemId != systemIdUNKNOWN)
1847 for (i = 0; i < MAX_ARLANS; i++) {
1848 struct net_device *dev = arlan_probe(i);
1851 return PTR_ERR(dev);
1854 printk(KERN_INFO "Arlan driver %s\n", arlan_version);
1855 ARLAN_DEBUG_EXIT("init_module");
1860 void __exit cleanup_module(void)
1863 struct net_device *dev;
1865 ARLAN_DEBUG_ENTRY("cleanup_module");
1867 IFDEBUG(ARLAN_DEBUG_SHUTDOWN)
1868 printk(KERN_INFO "arlan: unloading module\n");
1870 cleanup_arlan_proc();
1872 for (i = 0; i < MAX_ARLANS; i++)
1874 dev = arlan_device[i];
1876 arlan_command(dev, ARLAN_COMMAND_POWERDOWN );
1878 unregister_netdev(dev);
1879 release_mem_region(virt_to_phys((void *) dev->mem_start),
1882 arlan_device[i] = NULL;
1886 ARLAN_DEBUG_EXIT("cleanup_module");
1891 MODULE_LICENSE("GPL");