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
8 #include <linux/config.h>
11 #if BITS_PER_LONG != 32
12 # error FIXME: this driver requires a 32-bit platform
15 static const char *arlan_version = "C.Jennigs 97 & Elmer.Joandi@ut.ee Oct'98, http://www.ylenurme.ee/~elmer/655/";
17 struct net_device *arlan_device[MAX_ARLANS];
19 static int SID = SIDUNKNOWN;
20 static int radioNodeId = radioNodeIdUNKNOWN;
21 static char encryptionKey[12] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'};
22 int arlan_debug = debugUNKNOWN;
23 static int spreadingCode = spreadingCodeUNKNOWN;
24 static int channelNumber = channelNumberUNKNOWN;
25 static int channelSet = channelSetUNKNOWN;
26 static int systemId = systemIdUNKNOWN;
27 static int registrationMode = registrationModeUNKNOWN;
29 static int tx_delay_ms;
30 static int retries = 5;
31 static int tx_queue_len = 1;
32 static int arlan_EEPROM_bad;
34 #ifdef ARLAN_DEBUGGING
36 static int arlan_entry_debug;
37 static int arlan_exit_debug;
38 static int testMemory = testMemoryUNKNOWN;
39 static int irq = irqUNKNOWN;
40 static int txScrambled = 1;
43 module_param(irq, int, 0);
44 module_param(mdebug, int, 0);
45 module_param(testMemory, int, 0);
46 module_param(arlan_entry_debug, int, 0);
47 module_param(arlan_exit_debug, int, 0);
48 module_param(txScrambled, int, 0);
49 MODULE_PARM_DESC(irq, "(unused)");
50 MODULE_PARM_DESC(testMemory, "(unused)");
51 MODULE_PARM_DESC(mdebug, "Arlan multicast debugging (0-1)");
54 module_param(arlan_debug, int, 0);
55 module_param(spreadingCode, int, 0);
56 module_param(channelNumber, int, 0);
57 module_param(channelSet, int, 0);
58 module_param(systemId, int, 0);
59 module_param(registrationMode, int, 0);
60 module_param(radioNodeId, int, 0);
61 module_param(SID, int, 0);
62 module_param(keyStart, int, 0);
63 module_param(tx_delay_ms, int, 0);
64 module_param(retries, int, 0);
65 module_param(tx_queue_len, int, 0);
66 module_param(arlan_EEPROM_bad, int, 0);
67 MODULE_PARM_DESC(arlan_debug, "Arlan debug enable (0-1)");
68 MODULE_PARM_DESC(retries, "Arlan maximum packet retransmisions");
69 #ifdef ARLAN_ENTRY_EXIT_DEBUGGING
70 MODULE_PARM_DESC(arlan_entry_debug, "Arlan driver function entry debugging");
71 MODULE_PARM_DESC(arlan_exit_debug, "Arlan driver function exit debugging");
72 MODULE_PARM_DESC(arlan_entry_and_exit_debug, "Arlan driver function entry and exit debugging");
74 MODULE_PARM_DESC(arlan_entry_debug, "(ignored)");
75 MODULE_PARM_DESC(arlan_exit_debug, "(ignored)");
76 MODULE_PARM_DESC(arlan_entry_and_exit_debug, "(ignored)");
79 struct arlan_conf_stru arlan_conf[MAX_ARLANS];
80 static int arlans_found;
82 static int arlan_open(struct net_device *dev);
83 static int arlan_tx(struct sk_buff *skb, struct net_device *dev);
84 static irqreturn_t arlan_interrupt(int irq, void *dev_id, struct pt_regs *regs);
85 static int arlan_close(struct net_device *dev);
86 static struct net_device_stats *
87 arlan_statistics (struct net_device *dev);
88 static void arlan_set_multicast (struct net_device *dev);
89 static int arlan_hw_tx (struct net_device* dev, char *buf, int length );
90 static int arlan_hw_config (struct net_device * dev);
91 static void arlan_tx_done_interrupt (struct net_device * dev, int status);
92 static void arlan_rx_interrupt (struct net_device * dev, u_char rxStatus, u_short, u_short);
93 static void arlan_process_interrupt (struct net_device * dev);
94 static void arlan_tx_timeout (struct net_device *dev);
96 static inline long us2ticks(int us)
98 return us * (1000000 / HZ);
102 #ifdef ARLAN_ENTRY_EXIT_DEBUGGING
103 #define ARLAN_DEBUG_ENTRY(name) \
105 struct timeval timev;\
106 do_gettimeofday(&timev);\
107 if (arlan_entry_debug || arlan_entry_and_exit_debug)\
108 printk("--->>>" name " %ld " "\n",((long int) timev.tv_sec * 1000000 + timev.tv_usec));\
110 #define ARLAN_DEBUG_EXIT(name) \
112 struct timeval timev;\
113 do_gettimeofday(&timev);\
114 if (arlan_exit_debug || arlan_entry_and_exit_debug)\
115 printk("<<<---" name " %ld " "\n",((long int) timev.tv_sec * 1000000 + timev.tv_usec) );\
118 #define ARLAN_DEBUG_ENTRY(name)
119 #define ARLAN_DEBUG_EXIT(name)
123 #define arlan_interrupt_ack(dev)\
124 clearClearInterrupt(dev);\
125 setClearInterrupt(dev);
127 static inline int arlan_drop_tx(struct net_device *dev)
129 struct arlan_private *priv = netdev_priv(dev);
131 priv->stats.tx_errors++;
132 if (priv->Conf->tx_delay_ms)
134 priv->tx_done_delayed = jiffies + priv->Conf->tx_delay_ms * HZ / 1000 + 1;
138 priv->waiting_command_mask &= ~ARLAN_COMMAND_TX;
139 TXHEAD(dev).offset = 0;
140 TXTAIL(dev).offset = 0;
143 if (!priv->under_reset && !priv->under_config)
144 netif_wake_queue (dev);
150 int arlan_command(struct net_device *dev, int command_p)
152 struct arlan_private *priv = netdev_priv(dev);
153 volatile struct arlan_shmem __iomem *arlan = priv->card;
154 struct arlan_conf_stru *conf = priv->Conf;
159 ARLAN_DEBUG_ENTRY("arlan_command");
161 if (priv->card_polling_interval)
162 priv->card_polling_interval = 1;
164 if (arlan_debug & ARLAN_DEBUG_CHAIN_LOCKS)
165 printk(KERN_DEBUG "arlan_command, %lx commandByte %x waiting %lx incoming %x \n",
166 jiffies, READSHMB(arlan->commandByte),
167 priv->waiting_command_mask, command_p);
169 priv->waiting_command_mask |= command_p;
171 if (priv->waiting_command_mask & ARLAN_COMMAND_RESET)
172 if (time_after(jiffies, priv->lastReset + 5 * HZ))
173 priv->waiting_command_mask &= ~ARLAN_COMMAND_RESET;
175 if (priv->waiting_command_mask & ARLAN_COMMAND_INT_ACK)
177 arlan_interrupt_ack(dev);
178 priv->waiting_command_mask &= ~ARLAN_COMMAND_INT_ACK;
180 if (priv->waiting_command_mask & ARLAN_COMMAND_INT_ENABLE)
182 setInterruptEnable(dev);
183 priv->waiting_command_mask &= ~ARLAN_COMMAND_INT_ENABLE;
186 /* Card access serializing lock */
187 spin_lock_irqsave(&priv->lock, flags);
189 /* Check cards status and waiting */
191 if (priv->waiting_command_mask & (ARLAN_COMMAND_LONG_WAIT_NOW | ARLAN_COMMAND_WAIT_NOW))
193 while (priv->waiting_command_mask & (ARLAN_COMMAND_LONG_WAIT_NOW | ARLAN_COMMAND_WAIT_NOW))
195 if (READSHMB(arlan->resetFlag) ||
196 READSHMB(arlan->commandByte)) /* ||
197 (readControlRegister(dev) & ARLAN_ACCESS))
201 priv->waiting_command_mask &= ~(ARLAN_COMMAND_LONG_WAIT_NOW | ARLAN_COMMAND_WAIT_NOW);
205 if (priv->waiting_command_mask & ARLAN_COMMAND_LONG_WAIT_NOW)
207 if (udelayed * 40 > 1000000)
209 printk(KERN_ERR "%s long wait too long \n", dev->name);
210 priv->waiting_command_mask |= ARLAN_COMMAND_RESET;
214 else if (priv->waiting_command_mask & ARLAN_COMMAND_WAIT_NOW)
216 if (udelayed * 40 > 1000)
218 printk(KERN_ERR "%s short wait too long \n", dev->name);
227 while ((READSHMB(arlan->resetFlag) ||
228 READSHMB(arlan->commandByte)) &&
229 conf->pre_Command_Wait > (i++) * 10)
233 if ((READSHMB(arlan->resetFlag) ||
234 READSHMB(arlan->commandByte)) &&
235 !(priv->waiting_command_mask & ARLAN_COMMAND_RESET))
240 if (priv->waiting_command_mask & ARLAN_COMMAND_RESET)
241 priv->under_reset = 1;
242 if (priv->waiting_command_mask & ARLAN_COMMAND_CONF)
243 priv->under_config = 1;
245 /* Issuing command */
246 arlan_lock_card_access(dev);
247 if (priv->waiting_command_mask & ARLAN_COMMAND_POWERUP)
249 // if (readControlRegister(dev) & (ARLAN_ACCESS && ARLAN_POWER))
251 arlan_interrupt_lancpu(dev);
252 priv->waiting_command_mask &= ~ARLAN_COMMAND_POWERUP;
253 priv->waiting_command_mask |= ARLAN_COMMAND_RESET;
254 priv->card_polling_interval = HZ / 10;
256 else if (priv->waiting_command_mask & ARLAN_COMMAND_ACTIVATE)
258 WRITESHMB(arlan->commandByte, ARLAN_COM_ACTIVATE);
259 arlan_interrupt_lancpu(dev);
260 priv->waiting_command_mask &= ~ARLAN_COMMAND_ACTIVATE;
261 priv->card_polling_interval = HZ / 10;
263 else if (priv->waiting_command_mask & ARLAN_COMMAND_RX_ABORT)
265 if (priv->rx_command_given)
267 WRITESHMB(arlan->commandByte, ARLAN_COM_RX_ABORT);
268 arlan_interrupt_lancpu(dev);
269 priv->rx_command_given = 0;
271 priv->waiting_command_mask &= ~ARLAN_COMMAND_RX_ABORT;
272 priv->card_polling_interval = 1;
274 else if (priv->waiting_command_mask & ARLAN_COMMAND_TX_ABORT)
276 if (priv->tx_command_given)
278 WRITESHMB(arlan->commandByte, ARLAN_COM_TX_ABORT);
279 arlan_interrupt_lancpu(dev);
280 priv->tx_command_given = 0;
282 priv->waiting_command_mask &= ~ARLAN_COMMAND_TX_ABORT;
283 priv->card_polling_interval = 1;
285 else if (priv->waiting_command_mask & ARLAN_COMMAND_RESET)
288 netif_stop_queue (dev);
291 if (priv->tx_command_given || priv->rx_command_given)
293 printk(KERN_ERR "%s: Reset under tx or rx command \n", dev->name);
295 netif_stop_queue (dev);
296 if (arlan_debug & ARLAN_DEBUG_RESET)
297 printk(KERN_ERR "%s: Doing chip reset\n", dev->name);
298 priv->lastReset = jiffies;
299 WRITESHM(arlan->commandByte, 0, u_char);
300 /* hold card in reset state */
301 setHardwareReset(dev);
302 /* set reset flag and then release reset */
303 WRITESHM(arlan->resetFlag, 0xff, u_char);
304 clearChannelAttention(dev);
305 clearHardwareReset(dev);
306 priv->card_polling_interval = HZ / 4;
307 priv->waiting_command_mask &= ~ARLAN_COMMAND_RESET;
308 priv->waiting_command_mask |= ARLAN_COMMAND_INT_RACK;
309 // priv->waiting_command_mask |= ARLAN_COMMAND_INT_RENABLE;
310 // priv->waiting_command_mask |= ARLAN_COMMAND_RX;
312 else if (priv->waiting_command_mask & ARLAN_COMMAND_INT_RACK)
314 clearHardwareReset(dev);
315 clearClearInterrupt(dev);
316 setClearInterrupt(dev);
317 setInterruptEnable(dev);
318 priv->waiting_command_mask &= ~ARLAN_COMMAND_INT_RACK;
319 priv->waiting_command_mask |= ARLAN_COMMAND_CONF;
320 priv->under_config = 1;
321 priv->under_reset = 0;
323 else if (priv->waiting_command_mask & ARLAN_COMMAND_INT_RENABLE)
325 setInterruptEnable(dev);
326 priv->waiting_command_mask &= ~ARLAN_COMMAND_INT_RENABLE;
328 else if (priv->waiting_command_mask & ARLAN_COMMAND_CONF)
330 if (priv->tx_command_given || priv->rx_command_given)
332 printk(KERN_ERR "%s: Reset under tx or rx command \n", dev->name);
335 setInterruptEnable(dev);
336 arlan_hw_config(dev);
337 arlan_interrupt_lancpu(dev);
338 priv->waiting_command_mask &= ~ARLAN_COMMAND_CONF;
339 priv->card_polling_interval = HZ / 10;
340 // priv->waiting_command_mask |= ARLAN_COMMAND_INT_RACK;
341 // priv->waiting_command_mask |= ARLAN_COMMAND_INT_ENABLE;
342 priv->waiting_command_mask |= ARLAN_COMMAND_CONF_WAIT;
344 else if (priv->waiting_command_mask & ARLAN_COMMAND_CONF_WAIT)
346 if (READSHMB(arlan->configuredStatusFlag) != 0 &&
347 READSHMB(arlan->diagnosticInfo) == 0xff)
349 priv->waiting_command_mask &= ~ARLAN_COMMAND_CONF_WAIT;
350 priv->waiting_command_mask |= ARLAN_COMMAND_RX;
351 priv->waiting_command_mask |= ARLAN_COMMAND_TBUSY_CLEAR;
352 priv->card_polling_interval = HZ / 10;
353 priv->tx_command_given = 0;
354 priv->under_config = 0;
358 priv->card_polling_interval = 1;
359 if (arlan_debug & ARLAN_DEBUG_TIMING)
360 printk(KERN_ERR "configure delayed \n");
363 else if (priv->waiting_command_mask & ARLAN_COMMAND_RX)
365 if (!registrationBad(dev))
367 setInterruptEnable(dev);
368 memset_io(arlan->commandParameter, 0, 0xf);
369 WRITESHMB(arlan->commandByte, ARLAN_COM_INT | ARLAN_COM_RX_ENABLE);
370 WRITESHMB(arlan->commandParameter[0], conf->rxParameter);
371 arlan_interrupt_lancpu(dev);
372 priv->rx_command_given = 0; // mnjah, bad
373 priv->waiting_command_mask &= ~ARLAN_COMMAND_RX;
374 priv->card_polling_interval = 1;
377 priv->card_polling_interval = 2;
379 else if (priv->waiting_command_mask & ARLAN_COMMAND_TBUSY_CLEAR)
381 if ( !registrationBad(dev) &&
382 (netif_queue_stopped(dev) || !netif_running(dev)) )
384 priv->waiting_command_mask &= ~ARLAN_COMMAND_TBUSY_CLEAR;
385 netif_wake_queue (dev);
388 else if (priv->waiting_command_mask & ARLAN_COMMAND_TX)
390 if (!test_and_set_bit(0, (void *) &priv->tx_command_given))
392 if (time_after(jiffies,
393 priv->tx_last_sent + us2ticks(conf->rx_tweak1))
394 || time_before(jiffies,
395 priv->last_rx_int_ack_time + us2ticks(conf->rx_tweak2)))
397 setInterruptEnable(dev);
398 memset_io(arlan->commandParameter, 0, 0xf);
399 WRITESHMB(arlan->commandByte, ARLAN_COM_TX_ENABLE | ARLAN_COM_INT);
400 memcpy_toio(arlan->commandParameter, &TXLAST(dev), 14);
401 // for ( i=1 ; i < 15 ; i++) printk("%02x:",READSHMB(arlan->commandParameter[i]));
402 priv->tx_last_sent = jiffies;
403 arlan_interrupt_lancpu(dev);
404 priv->tx_command_given = 1;
405 priv->waiting_command_mask &= ~ARLAN_COMMAND_TX;
406 priv->card_polling_interval = 1;
410 priv->tx_command_given = 0;
411 priv->card_polling_interval = 1;
414 else if (arlan_debug & ARLAN_DEBUG_CHAIN_LOCKS)
415 printk(KERN_ERR "tx command when tx chain locked \n");
417 else if (priv->waiting_command_mask & ARLAN_COMMAND_NOOPINT)
420 WRITESHMB(arlan->commandByte, ARLAN_COM_NOP | ARLAN_COM_INT);
422 arlan_interrupt_lancpu(dev);
423 priv->waiting_command_mask &= ~ARLAN_COMMAND_NOOPINT;
424 priv->card_polling_interval = HZ / 3;
426 else if (priv->waiting_command_mask & ARLAN_COMMAND_NOOP)
428 WRITESHMB(arlan->commandByte, ARLAN_COM_NOP);
429 arlan_interrupt_lancpu(dev);
430 priv->waiting_command_mask &= ~ARLAN_COMMAND_NOOP;
431 priv->card_polling_interval = HZ / 3;
433 else if (priv->waiting_command_mask & ARLAN_COMMAND_SLOW_POLL)
435 WRITESHMB(arlan->commandByte, ARLAN_COM_GOTO_SLOW_POLL);
436 arlan_interrupt_lancpu(dev);
437 priv->waiting_command_mask &= ~ARLAN_COMMAND_SLOW_POLL;
438 priv->card_polling_interval = HZ / 3;
440 else if (priv->waiting_command_mask & ARLAN_COMMAND_POWERDOWN)
443 if (arlan_debug & ARLAN_DEBUG_CARD_STATE)
444 printk(KERN_WARNING "%s: Arlan Going Standby\n", dev->name);
445 priv->waiting_command_mask &= ~ARLAN_COMMAND_POWERDOWN;
446 priv->card_polling_interval = 3 * HZ;
448 arlan_unlock_card_access(dev);
449 for (i = 0; READSHMB(arlan->commandByte) && i < 20; i++)
451 if (READSHMB(arlan->commandByte))
452 if (arlan_debug & ARLAN_DEBUG_CARD_STATE)
453 printk(KERN_ERR "card busy leaving command %lx\n", priv->waiting_command_mask);
455 spin_unlock_irqrestore(&priv->lock, flags);
456 ARLAN_DEBUG_EXIT("arlan_command");
457 priv->last_command_buff_free_time = jiffies;
461 if (time_after(jiffies, priv->last_command_buff_free_time + HZ))
462 priv->waiting_command_mask |= ARLAN_COMMAND_CLEAN_AND_RESET;
464 if (arlan_debug & ARLAN_DEBUG_CARD_STATE)
465 printk(KERN_ERR "%s arlan_command card busy end \n", dev->name);
466 spin_unlock_irqrestore(&priv->lock, flags);
467 ARLAN_DEBUG_EXIT("arlan_command");
471 printk(KERN_ERR "%s arlan_command bad end \n", dev->name);
473 spin_unlock_irqrestore(&priv->lock, flags);
474 ARLAN_DEBUG_EXIT("arlan_command");
479 static inline void arlan_command_process(struct net_device *dev)
481 struct arlan_private *priv = netdev_priv(dev);
484 while (priv->waiting_command_mask && times < 8)
486 if (priv->waiting_command_mask)
488 if (arlan_command(dev, 0))
492 /* if long command, we won't repeat trying */ ;
493 if (priv->card_polling_interval > 1)
500 static inline void arlan_retransmit_now(struct net_device *dev)
502 struct arlan_private *priv = netdev_priv(dev);
505 ARLAN_DEBUG_ENTRY("arlan_retransmit_now");
506 if (TXLAST(dev).offset == 0)
508 if (TXHEAD(dev).offset)
511 IFDEBUG(ARLAN_DEBUG_TX_CHAIN) printk(KERN_DEBUG "TX buff switch to head \n");
514 else if (TXTAIL(dev).offset)
516 IFDEBUG(ARLAN_DEBUG_TX_CHAIN) printk(KERN_DEBUG "TX buff switch to tail \n");
520 IFDEBUG(ARLAN_DEBUG_TX_CHAIN) printk(KERN_ERR "ReTransmit buff empty");
521 netif_wake_queue (dev);
525 arlan_command(dev, ARLAN_COMMAND_TX);
527 priv->Conf->driverRetransmissions++;
528 priv->retransmissions++;
530 IFDEBUG(ARLAN_DEBUG_TX_CHAIN) printk("Retransmit %d bytes \n", TXLAST(dev).length);
532 ARLAN_DEBUG_EXIT("arlan_retransmit_now");
537 static void arlan_registration_timer(unsigned long data)
539 struct net_device *dev = (struct net_device *) data;
540 struct arlan_private *priv = netdev_priv(dev);
541 int bh_mark_needed = 0;
543 long lostTime = ((long)jiffies - (long)priv->registrationLastSeen)
546 if (registrationBad(dev))
548 priv->registrationLostCount++;
549 if (lostTime > 7000 && lostTime < 7200)
551 printk(KERN_NOTICE "%s registration Lost \n", dev->name);
553 if (lostTime / priv->reRegisterExp > 2000)
554 arlan_command(dev, ARLAN_COMMAND_CLEAN_AND_CONF);
555 if (lostTime / (priv->reRegisterExp) > 3500)
556 arlan_command(dev, ARLAN_COMMAND_CLEAN_AND_RESET);
557 if (priv->reRegisterExp < 400)
558 priv->reRegisterExp += 2;
562 arlan_command(dev, ARLAN_COMMAND_CLEAN_AND_RESET);
567 if (priv->Conf->registrationMode && lostTime > 10000 &&
568 priv->registrationLostCount)
570 printk(KERN_NOTICE "%s registration is back after %ld milliseconds\n",
571 dev->name, lostTime);
573 priv->registrationLastSeen = jiffies;
574 priv->registrationLostCount = 0;
575 priv->reRegisterExp = 1;
576 if (!netif_running(dev) )
577 netif_wake_queue(dev);
578 if (time_after(priv->tx_last_sent,priv->tx_last_cleared) &&
579 time_after(jiffies, priv->tx_last_sent * 5*HZ) ){
580 arlan_command(dev, ARLAN_COMMAND_CLEAN_AND_RESET);
581 priv->tx_last_cleared = jiffies;
586 if (!registrationBad(dev) && priv->ReTransmitRequested)
588 IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
589 printk(KERN_ERR "Retransmit from timer \n");
590 priv->ReTransmitRequested = 0;
591 arlan_retransmit_now(dev);
593 if (!registrationBad(dev) &&
594 time_after(jiffies, priv->tx_done_delayed) &&
595 priv->tx_done_delayed != 0)
597 TXLAST(dev).offset = 0;
600 else if (TXTAIL(dev).offset)
602 if (TXLAST(dev).offset)
604 arlan_retransmit_now(dev);
605 dev->trans_start = jiffies;
607 if (!(TXHEAD(dev).offset && TXTAIL(dev).offset))
609 netif_wake_queue (dev);
611 priv->tx_done_delayed = 0;
616 netif_wake_queue (dev);
618 arlan_process_interrupt(dev);
620 if (next_tick < priv->card_polling_interval)
621 next_tick = priv->card_polling_interval;
623 priv->timer.expires = jiffies + next_tick;
625 add_timer(&priv->timer);
629 #ifdef ARLAN_DEBUGGING
631 static void arlan_print_registers(struct net_device *dev, int line)
633 struct arlan_private *priv = netdev_priv(dev);
634 volatile struct arlan_shmem *arlan = priv->card;
636 u_char hostcpuLock, lancpuLock, controlRegister, cntrlRegImage,
637 txStatus, rxStatus, interruptInProgress, commandByte;
640 ARLAN_DEBUG_ENTRY("arlan_print_registers");
641 READSHM(interruptInProgress, arlan->interruptInProgress, u_char);
642 READSHM(hostcpuLock, arlan->hostcpuLock, u_char);
643 READSHM(lancpuLock, arlan->lancpuLock, u_char);
644 READSHM(controlRegister, arlan->controlRegister, u_char);
645 READSHM(cntrlRegImage, arlan->cntrlRegImage, u_char);
646 READSHM(txStatus, arlan->txStatus, u_char);
647 READSHM(rxStatus, arlan->rxStatus, u_char);
648 READSHM(commandByte, arlan->commandByte, u_char);
650 printk(KERN_WARNING "line %04d IP %02x HL %02x LL %02x CB %02x CR %02x CRI %02x TX %02x RX %02x\n",
651 line, interruptInProgress, hostcpuLock, lancpuLock, commandByte,
652 controlRegister, cntrlRegImage, txStatus, rxStatus);
654 ARLAN_DEBUG_EXIT("arlan_print_registers");
659 static int arlan_hw_tx(struct net_device *dev, char *buf, int length)
663 struct arlan_private *priv = netdev_priv(dev);
664 volatile struct arlan_shmem __iomem *arlan = priv->card;
665 struct arlan_conf_stru *conf = priv->Conf;
667 int tailStarts = 0x800;
671 ARLAN_DEBUG_ENTRY("arlan_hw_tx");
672 if (TXHEAD(dev).offset)
673 headEnds = (((TXHEAD(dev).offset + TXHEAD(dev).length - offsetof(struct arlan_shmem, txBuffer)) / 64) + 1) * 64;
674 if (TXTAIL(dev).offset)
675 tailStarts = 0x800 - (((TXTAIL(dev).offset - offsetof(struct arlan_shmem, txBuffer)) / 64) + 2) * 64;
678 if (!TXHEAD(dev).offset && length < tailStarts)
680 IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
681 printk(KERN_ERR "TXHEAD insert, tailStart %d\n", tailStarts);
684 offsetof(struct arlan_shmem, txBuffer);
685 TXHEAD(dev).length = length - ARLAN_FAKE_HDR_LEN;
686 for (i = 0; i < 6; i++)
687 TXHEAD(dev).dest[i] = buf[i];
688 TXHEAD(dev).clear = conf->txClear;
689 TXHEAD(dev).retries = conf->txRetries; /* 0 is use default */
690 TXHEAD(dev).routing = conf->txRouting;
691 TXHEAD(dev).scrambled = conf->txScrambled;
692 memcpy_toio((char __iomem *)arlan + TXHEAD(dev).offset, buf + ARLAN_FAKE_HDR_LEN, TXHEAD(dev).length);
694 else if (!TXTAIL(dev).offset && length < (0x800 - headEnds))
696 IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
697 printk(KERN_ERR "TXTAIL insert, headEnd %d\n", headEnds);
700 offsetof(struct arlan_shmem, txBuffer) + 0x800 - (length / 64 + 2) * 64;
701 TXTAIL(dev).length = length - ARLAN_FAKE_HDR_LEN;
702 for (i = 0; i < 6; i++)
703 TXTAIL(dev).dest[i] = buf[i];
704 TXTAIL(dev).clear = conf->txClear;
705 TXTAIL(dev).retries = conf->txRetries;
706 TXTAIL(dev).routing = conf->txRouting;
707 TXTAIL(dev).scrambled = conf->txScrambled;
708 memcpy_toio(((char __iomem *)arlan + TXTAIL(dev).offset), buf + ARLAN_FAKE_HDR_LEN, TXTAIL(dev).length);
712 netif_stop_queue (dev);
713 IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
714 printk(KERN_ERR "TX TAIL & HEAD full, return, tailStart %d headEnd %d\n", tailStarts, headEnds);
717 priv->out_bytes += length;
718 priv->out_bytes10 += length;
719 if (conf->measure_rate < 1)
720 conf->measure_rate = 1;
721 if (time_after(jiffies, priv->out_time + conf->measure_rate * HZ))
723 conf->out_speed = priv->out_bytes / conf->measure_rate;
725 priv->out_time = jiffies;
727 if (time_after(jiffies, priv->out_time10 + conf->measure_rate * 10*HZ))
729 conf->out_speed10 = priv->out_bytes10 / (10 * conf->measure_rate);
730 priv->out_bytes10 = 0;
731 priv->out_time10 = jiffies;
733 if (TXHEAD(dev).offset && TXTAIL(dev).offset)
735 netif_stop_queue (dev);
739 netif_start_queue (dev);
742 IFDEBUG(ARLAN_DEBUG_HEADER_DUMP)
743 printk(KERN_WARNING "%s Transmit t %2x:%2x:%2x:%2x:%2x:%2x f %2x:%2x:%2x:%2x:%2x:%2x \n", dev->name,
744 (unsigned char) buf[0], (unsigned char) buf[1], (unsigned char) buf[2], (unsigned char) buf[3],
745 (unsigned char) buf[4], (unsigned char) buf[5], (unsigned char) buf[6], (unsigned char) buf[7],
746 (unsigned char) buf[8], (unsigned char) buf[9], (unsigned char) buf[10], (unsigned char) buf[11]);
748 IFDEBUG(ARLAN_DEBUG_TX_CHAIN) printk(KERN_ERR "TX command prepare for buffer %d\n", priv->txLast);
750 arlan_command(dev, ARLAN_COMMAND_TX);
752 priv->tx_last_sent = jiffies;
754 IFDEBUG(ARLAN_DEBUG_TX_CHAIN) printk("%s TX Qued %d bytes \n", dev->name, length);
756 ARLAN_DEBUG_EXIT("arlan_hw_tx");
762 static int arlan_hw_config(struct net_device *dev)
764 struct arlan_private *priv = netdev_priv(dev);
765 volatile struct arlan_shmem __iomem *arlan = priv->card;
766 struct arlan_conf_stru *conf = priv->Conf;
768 ARLAN_DEBUG_ENTRY("arlan_hw_config");
770 printk(KERN_NOTICE "%s arlan configure called \n", dev->name);
771 if (arlan_EEPROM_bad)
772 printk(KERN_NOTICE "arlan configure with eeprom bad option \n");
775 WRITESHM(arlan->spreadingCode, conf->spreadingCode, u_char);
776 WRITESHM(arlan->channelSet, conf->channelSet, u_char);
778 if (arlan_EEPROM_bad)
779 WRITESHM(arlan->defaultChannelSet, conf->channelSet, u_char);
781 WRITESHM(arlan->channelNumber, conf->channelNumber, u_char);
783 WRITESHM(arlan->scramblingDisable, conf->scramblingDisable, u_char);
784 WRITESHM(arlan->txAttenuation, conf->txAttenuation, u_char);
786 WRITESHM(arlan->systemId, conf->systemId, u_int);
788 WRITESHM(arlan->maxRetries, conf->maxRetries, u_char);
789 WRITESHM(arlan->receiveMode, conf->receiveMode, u_char);
790 WRITESHM(arlan->priority, conf->priority, u_char);
791 WRITESHM(arlan->rootOrRepeater, conf->rootOrRepeater, u_char);
792 WRITESHM(arlan->SID, conf->SID, u_int);
794 WRITESHM(arlan->registrationMode, conf->registrationMode, u_char);
796 WRITESHM(arlan->registrationFill, conf->registrationFill, u_char);
797 WRITESHM(arlan->localTalkAddress, conf->localTalkAddress, u_char);
798 WRITESHM(arlan->codeFormat, conf->codeFormat, u_char);
799 WRITESHM(arlan->numChannels, conf->numChannels, u_char);
800 WRITESHM(arlan->channel1, conf->channel1, u_char);
801 WRITESHM(arlan->channel2, conf->channel2, u_char);
802 WRITESHM(arlan->channel3, conf->channel3, u_char);
803 WRITESHM(arlan->channel4, conf->channel4, u_char);
804 WRITESHM(arlan->radioNodeId, conf->radioNodeId, u_short);
805 WRITESHM(arlan->SID, conf->SID, u_int);
806 WRITESHM(arlan->waitTime, conf->waitTime, u_short);
807 WRITESHM(arlan->lParameter, conf->lParameter, u_short);
808 memcpy_toio(&(arlan->_15), &(conf->_15), 3);
809 WRITESHM(arlan->_15, conf->_15, u_short);
810 WRITESHM(arlan->headerSize, conf->headerSize, u_short);
811 if (arlan_EEPROM_bad)
812 WRITESHM(arlan->hardwareType, conf->hardwareType, u_char);
813 WRITESHM(arlan->radioType, conf->radioType, u_char);
814 if (arlan_EEPROM_bad)
815 WRITESHM(arlan->radioModule, conf->radioType, u_char);
817 memcpy_toio(arlan->encryptionKey + keyStart, encryptionKey, 8);
818 memcpy_toio(arlan->name, conf->siteName, 16);
820 WRITESHMB(arlan->commandByte, ARLAN_COM_INT | ARLAN_COM_CONF); /* do configure */
821 memset_io(arlan->commandParameter, 0, 0xf); /* 0xf */
822 memset_io(arlan->commandParameter + 1, 0, 2);
823 if (conf->writeEEPROM)
825 memset_io(arlan->commandParameter, conf->writeEEPROM, 1);
826 // conf->writeEEPROM=0;
828 if (conf->registrationMode && conf->registrationInterrupts)
829 memset_io(arlan->commandParameter + 3, 1, 1);
831 memset_io(arlan->commandParameter + 3, 0, 1);
833 priv->irq_test_done = 0;
835 if (conf->tx_queue_len)
836 dev->tx_queue_len = conf->tx_queue_len;
839 ARLAN_DEBUG_EXIT("arlan_hw_config");
844 static int arlan_read_card_configuration(struct net_device *dev)
847 struct arlan_private *priv = netdev_priv(dev);
848 volatile struct arlan_shmem __iomem *arlan = priv->card;
849 struct arlan_conf_stru *conf = priv->Conf;
851 ARLAN_DEBUG_ENTRY("arlan_read_card_configuration");
853 if (radioNodeId == radioNodeIdUNKNOWN)
855 READSHM(conf->radioNodeId, arlan->radioNodeId, u_short);
858 conf->radioNodeId = radioNodeId;
860 if (SID == SIDUNKNOWN)
862 READSHM(conf->SID, arlan->SID, u_int);
864 else conf->SID = SID;
866 if (spreadingCode == spreadingCodeUNKNOWN)
868 READSHM(conf->spreadingCode, arlan->spreadingCode, u_char);
871 conf->spreadingCode = spreadingCode;
873 if (channelSet == channelSetUNKNOWN)
875 READSHM(conf->channelSet, arlan->channelSet, u_char);
877 else conf->channelSet = channelSet;
879 if (channelNumber == channelNumberUNKNOWN)
881 READSHM(conf->channelNumber, arlan->channelNumber, u_char);
883 else conf->channelNumber = channelNumber;
885 READSHM(conf->scramblingDisable, arlan->scramblingDisable, u_char);
886 READSHM(conf->txAttenuation, arlan->txAttenuation, u_char);
888 if (systemId == systemIdUNKNOWN)
890 READSHM(conf->systemId, arlan->systemId, u_int);
892 else conf->systemId = systemId;
894 READSHM(conf->maxDatagramSize, arlan->maxDatagramSize, u_short);
895 READSHM(conf->maxFrameSize, arlan->maxFrameSize, u_short);
896 READSHM(conf->maxRetries, arlan->maxRetries, u_char);
897 READSHM(conf->receiveMode, arlan->receiveMode, u_char);
898 READSHM(conf->priority, arlan->priority, u_char);
899 READSHM(conf->rootOrRepeater, arlan->rootOrRepeater, u_char);
901 if (SID == SIDUNKNOWN)
903 READSHM(conf->SID, arlan->SID, u_int);
905 else conf->SID = SID;
907 if (registrationMode == registrationModeUNKNOWN)
909 READSHM(conf->registrationMode, arlan->registrationMode, u_char);
911 else conf->registrationMode = registrationMode;
913 READSHM(conf->registrationFill, arlan->registrationFill, u_char);
914 READSHM(conf->localTalkAddress, arlan->localTalkAddress, u_char);
915 READSHM(conf->codeFormat, arlan->codeFormat, u_char);
916 READSHM(conf->numChannels, arlan->numChannels, u_char);
917 READSHM(conf->channel1, arlan->channel1, u_char);
918 READSHM(conf->channel2, arlan->channel2, u_char);
919 READSHM(conf->channel3, arlan->channel3, u_char);
920 READSHM(conf->channel4, arlan->channel4, u_char);
921 READSHM(conf->waitTime, arlan->waitTime, u_short);
922 READSHM(conf->lParameter, arlan->lParameter, u_short);
923 READSHM(conf->_15, arlan->_15, u_short);
924 READSHM(conf->headerSize, arlan->headerSize, u_short);
925 READSHM(conf->hardwareType, arlan->hardwareType, u_char);
926 READSHM(conf->radioType, arlan->radioModule, u_char);
928 if (conf->radioType == 0)
929 conf->radioType = 0xc;
931 WRITESHM(arlan->configStatus, 0xA5, u_char);
932 READSHM(tlx415, arlan->configStatus, u_char);
935 printk(KERN_INFO "%s tlx415 chip \n", dev->name);
940 conf->txScrambled = 0;
941 conf->rxParameter = 1;
942 conf->txTimeoutMs = 4000;
943 conf->waitCardTimeout = 100000;
944 conf->receiveMode = ARLAN_RCV_CLEAN;
945 memcpy_fromio(conf->siteName, arlan->name, 16);
946 conf->siteName[16] = '\0';
947 conf->retries = retries;
948 conf->tx_delay_ms = tx_delay_ms;
949 conf->ReTransmitPacketMaxSize = 200;
950 conf->waitReTransmitPacketMaxSize = 200;
951 conf->txAckTimeoutMs = 900;
952 conf->fastReTransCount = 3;
954 ARLAN_DEBUG_EXIT("arlan_read_card_configuration");
960 static int lastFoundAt = 0xbe000;
964 * This is the real probe routine. Linux has a history of friendly device
965 * probes on the ISA bus. A good device probes avoids doing writes, and
966 * verifies that the correct device exists and functions.
968 #define ARLAN_SHMEM_SIZE 0x2000
969 static int __init arlan_check_fingerprint(unsigned long memaddr)
971 static const char probeText[] = "TELESYSTEM SLW INC. ARLAN \0";
972 volatile struct arlan_shmem __iomem *arlan = (struct arlan_shmem *) memaddr;
973 unsigned long paddr = virt_to_phys((void *) memaddr);
976 ARLAN_DEBUG_ENTRY("arlan_check_fingerprint");
978 if (!request_mem_region(paddr, ARLAN_SHMEM_SIZE, "arlan")) {
979 // printk(KERN_WARNING "arlan: memory region %lx excluded from probing \n",paddr);
983 memcpy_fromio(tempBuf, arlan->textRegion, 29);
986 /* check for card at this address */
987 if (0 != strncmp(tempBuf, probeText, 29)){
988 release_mem_region(paddr, ARLAN_SHMEM_SIZE);
992 // printk(KERN_INFO "arlan found at 0x%x \n",memaddr);
993 ARLAN_DEBUG_EXIT("arlan_check_fingerprint");
998 static int arlan_change_mtu(struct net_device *dev, int new_mtu)
1000 struct arlan_private *priv = netdev_priv(dev);
1001 struct arlan_conf_stru *conf = priv->Conf;
1003 ARLAN_DEBUG_ENTRY("arlan_change_mtu");
1008 new_mtu = 256; /* cards book suggests 1600 */
1009 conf->maxDatagramSize = new_mtu;
1010 conf->maxFrameSize = new_mtu + 48;
1012 arlan_command(dev, ARLAN_COMMAND_CLEAN_AND_CONF);
1013 printk(KERN_NOTICE "%s mtu changed to %d \n", dev->name, new_mtu);
1015 ARLAN_DEBUG_EXIT("arlan_change_mtu");
1020 static int arlan_mac_addr(struct net_device *dev, void *p)
1022 struct sockaddr *addr = p;
1025 ARLAN_DEBUG_ENTRY("arlan_mac_addr");
1028 if (!netif_running(dev))
1030 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
1032 ARLAN_DEBUG_EXIT("arlan_mac_addr");
1038 static int __init arlan_setup_device(struct net_device *dev, int num)
1040 struct arlan_private *ap = netdev_priv(dev);
1043 ARLAN_DEBUG_ENTRY("arlan_setup_device");
1045 ap->conf = (struct arlan_shmem *)(ap+1);
1047 dev->tx_queue_len = tx_queue_len;
1048 dev->open = arlan_open;
1049 dev->stop = arlan_close;
1050 dev->hard_start_xmit = arlan_tx;
1051 dev->get_stats = arlan_statistics;
1052 dev->set_multicast_list = arlan_set_multicast;
1053 dev->change_mtu = arlan_change_mtu;
1054 dev->set_mac_address = arlan_mac_addr;
1055 dev->tx_timeout = arlan_tx_timeout;
1056 dev->watchdog_timeo = 3*HZ;
1058 ap->irq_test_done = 0;
1059 ap->Conf = &arlan_conf[num];
1061 ap->Conf->pre_Command_Wait = 40;
1062 ap->Conf->rx_tweak1 = 30;
1063 ap->Conf->rx_tweak2 = 0;
1066 err = register_netdev(dev);
1068 release_mem_region(virt_to_phys((void *) dev->mem_start),
1073 arlan_device[num] = dev;
1074 ARLAN_DEBUG_EXIT("arlan_setup_device");
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))
1088 printk(KERN_NOTICE "%s: Arlan found at %x, \n ", dev->name,
1089 (int) virt_to_phys((void*)memaddr));
1091 ap->card = (void *) memaddr;
1092 dev->mem_start = memaddr;
1093 dev->mem_end = memaddr + ARLAN_SHMEM_SIZE-1;
1097 READSHM(dev->irq, ap->card->irqLevel, u_char);
1098 } else if (dev->irq == 2)
1101 arlan_read_card_configuration(dev);
1103 ARLAN_DEBUG_EXIT("arlan_probe_here");
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;
1114 ARLAN_DEBUG_ENTRY("arlan_open");
1116 ret = request_irq(dev->irq, &arlan_interrupt, 0, dev->name, dev);
1119 printk(KERN_ERR "%s: unable to get IRQ %d .\n",
1120 dev->name, dev->irq);
1126 priv->lastReset = 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;
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);
1155 add_timer(&priv->timer);
1157 ARLAN_DEBUG_EXIT("arlan_open");
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)
1177 ARLAN_DEBUG_ENTRY("arlan_tx");
1179 length = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
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)
1190 dev->trans_start = jiffies;
1194 arlan_process_interrupt(dev);
1195 ARLAN_DEBUG_EXIT("arlan_tx");
1199 arlan_process_interrupt(dev);
1200 netif_stop_queue (dev);
1201 ARLAN_DEBUG_EXIT("arlan_tx");
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)
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)
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))
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))
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;
1273 IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
1274 printk("arlan intr: transmit OK\n");
1275 priv->stats.tx_packets++;
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;
1285 TXLAST(dev).offset = 0;
1288 else if (TXTAIL(dev).offset)
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);
1305 IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
1306 printk("arlan intr: transmit timed out\n");
1308 //arlan_queue_retransmit(dev);
1315 IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
1316 printk("arlan intr: transmit max retries\n");
1319 //arlan_queue_retransmit(dev);
1326 IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
1327 printk("arlan intr: transmit aborted\n");
1329 arlan_queue_retransmit(dev);
1336 IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
1337 printk("arlan intr: transmit not registered\n");
1340 arlan_queue_retransmit(dev);
1346 IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
1347 printk("arlan intr: transmit destination full\n");
1350 //arlan_drop_tx(dev);
1351 arlan_queue_retransmit(dev);
1357 IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
1358 printk("arlan intr: transmit unknown ack\n");
1361 arlan_queue_retransmit(dev);
1367 IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
1368 printk("arlan intr: transmit dest mail box full\n");
1371 //arlan_drop_tx(dev);
1372 arlan_queue_retransmit(dev);
1378 IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
1379 printk("arlan intr: transmit root dest not reg.\n");
1382 //arlan_drop_tx(dev);
1383 arlan_queue_retransmit(dev);
1389 printk(KERN_ERR "arlan intr: transmit status unknown\n");
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)
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);
1419 if (rxOffset + pkt_len > 0x2000)
1421 printk("%s: got too long packet, len %d offset %x\n", dev->name, pkt_len, rxOffset);
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;
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);
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) &&
1460 char hw_dst_addr[6];
1461 struct dev_mc_list *dmi = dev->mc_list;
1464 memcpy_fromio(hw_dst_addr, arlan->ultimateDestAddress, 6);
1465 if (hw_dst_addr[0] == 0x01)
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);
1473 { if (dmi->dmi_addrlen == 6)
1475 if (arlan_debug & ARLAN_DEBUG_HEADER_DUMP)
1476 printk(KERN_ERR "%s mcl %2x:%2x:%2x:%2x:%2x:%2x \n", dev->name,
1477 dmi->dmi_addr[0], dmi->dmi_addr[1], dmi->dmi_addr[2],
1478 dmi->dmi_addr[3], dmi->dmi_addr[4], dmi->dmi_addr[5]);
1479 for (i = 0; i < 6; i++)
1480 if (dmi->dmi_addr[i] != hw_dst_addr[i])
1486 printk(KERN_ERR "%s: invalid multicast address length given.\n", dev->name);
1489 /* we reach here if multicast filtering is on and packet
1490 * is multicast and not for receive */
1491 goto end_of_interrupt;
1494 #endif // ARLAN_MULTICAST
1495 /* multicast filtering ends here */
1496 pkt_len += ARLAN_FAKE_HDR_LEN;
1498 skb = dev_alloc_skb(pkt_len + 4);
1501 printk(KERN_ERR "%s: Memory squeeze, dropping packet.\n", dev->name);
1502 priv->stats.rx_dropped++;
1505 skb_reserve(skb, 2);
1507 skbtmp = skb_put(skb, pkt_len);
1509 memcpy_fromio(skbtmp + ARLAN_FAKE_HDR_LEN, ((char __iomem *) arlan) + rxOffset, pkt_len - ARLAN_FAKE_HDR_LEN);
1510 memcpy_fromio(skbtmp, arlan->ultimateDestAddress, 6);
1511 memcpy_fromio(skbtmp + 6, arlan->rxSrc, 6);
1512 WRITESHMB(arlan->rxStatus, 0x00);
1513 arlan_command(dev, ARLAN_COMMAND_RX);
1515 IFDEBUG(ARLAN_DEBUG_HEADER_DUMP)
1517 char immedDestAddress[6];
1518 char immedSrcAddress[6];
1519 memcpy_fromio(immedDestAddress, arlan->immedDestAddress, 6);
1520 memcpy_fromio(immedSrcAddress, arlan->immedSrcAddress, 6);
1522 printk(KERN_WARNING "%s t %2x:%2x:%2x:%2x:%2x:%2x f %2x:%2x:%2x:%2x:%2x:%2x imd %2x:%2x:%2x:%2x:%2x:%2x ims %2x:%2x:%2x:%2x:%2x:%2x\n", dev->name,
1523 (unsigned char) skbtmp[0], (unsigned char) skbtmp[1], (unsigned char) skbtmp[2], (unsigned char) skbtmp[3],
1524 (unsigned char) skbtmp[4], (unsigned char) skbtmp[5], (unsigned char) skbtmp[6], (unsigned char) skbtmp[7],
1525 (unsigned char) skbtmp[8], (unsigned char) skbtmp[9], (unsigned char) skbtmp[10], (unsigned char) skbtmp[11],
1526 immedDestAddress[0], immedDestAddress[1], immedDestAddress[2],
1527 immedDestAddress[3], immedDestAddress[4], immedDestAddress[5],
1528 immedSrcAddress[0], immedSrcAddress[1], immedSrcAddress[2],
1529 immedSrcAddress[3], immedSrcAddress[4], immedSrcAddress[5]);
1531 skb->protocol = eth_type_trans(skb, dev);
1532 IFDEBUG(ARLAN_DEBUG_HEADER_DUMP)
1533 if (skb->protocol != 0x608 && skb->protocol != 0x8)
1535 for (i = 0; i <= 22; i++)
1536 printk("%02x:", (u_char) skbtmp[i + 12]);
1537 printk(KERN_ERR "\n");
1538 printk(KERN_WARNING "arlan kernel pkt type trans %x \n", skb->protocol);
1541 dev->last_rx = jiffies;
1542 priv->stats.rx_packets++;
1543 priv->stats.rx_bytes += pkt_len;
1548 printk(KERN_ERR "arlan intr: received unknown status\n");
1549 priv->stats.rx_crc_errors++;
1552 ARLAN_DEBUG_EXIT("arlan_rx_interrupt");
1555 static void arlan_process_interrupt(struct net_device *dev)
1557 struct arlan_private *priv = netdev_priv(dev);
1558 volatile struct arlan_shmem __iomem *arlan = priv->card;
1559 u_char rxStatus = READSHMB(arlan->rxStatus);
1560 u_char txStatus = READSHMB(arlan->txStatus);
1561 u_short rxOffset = READSHMS(arlan->rxOffset);
1562 u_short pkt_len = READSHMS(arlan->rxLength);
1563 int interrupt_count = 0;
1565 ARLAN_DEBUG_ENTRY("arlan_process_interrupt");
1567 if (test_and_set_bit(0, (void *) &priv->interrupt_processing_active))
1569 if (arlan_debug & ARLAN_DEBUG_CHAIN_LOCKS)
1570 printk(KERN_ERR "interrupt chain reentering \n");
1571 goto end_int_process;
1573 while ((rxStatus || txStatus || priv->interrupt_ack_requested)
1574 && (interrupt_count < 5))
1577 priv->last_rx_int_ack_time = jiffies;
1579 arlan_command(dev, ARLAN_COMMAND_INT_ACK);
1580 arlan_command(dev, ARLAN_COMMAND_INT_ENABLE);
1582 IFDEBUG(ARLAN_DEBUG_INTERRUPT)
1583 printk(KERN_ERR "%s: got IRQ rx %x tx %x comm %x rxOff %x rxLen %x \n",
1584 dev->name, rxStatus, txStatus, READSHMB(arlan->commandByte),
1587 if (rxStatus == 0 && txStatus == 0)
1589 if (priv->irq_test_done)
1591 if (!registrationBad(dev))
1592 IFDEBUG(ARLAN_DEBUG_INTERRUPT) printk(KERN_ERR "%s unknown interrupt(nop? regLost ?) reason tx %d rx %d ",
1593 dev->name, txStatus, rxStatus);
1595 IFDEBUG(ARLAN_DEBUG_INTERRUPT)
1596 printk(KERN_INFO "%s irq $%d test OK \n", dev->name, dev->irq);
1599 priv->interrupt_ack_requested = 0;
1604 WRITESHMB(arlan->txStatus, 0x00);
1605 arlan_tx_done_interrupt(dev, txStatus);
1608 if (rxStatus == 1 || rxStatus == 2)
1609 { /* a packet waiting */
1610 arlan_rx_interrupt(dev, rxStatus, rxOffset, pkt_len);
1613 if (rxStatus > 2 && rxStatus < 0xff)
1615 WRITESHMB(arlan->rxStatus, 0x00);
1616 printk(KERN_ERR "%s unknown rxStatus reason tx %d rx %d ",
1617 dev->name, txStatus, rxStatus);
1620 if (rxStatus == 0xff)
1622 WRITESHMB(arlan->rxStatus, 0x00);
1623 arlan_command(dev, ARLAN_COMMAND_RX);
1624 if (registrationBad(dev))
1625 netif_device_detach(dev);
1626 if (!registrationBad(dev))
1628 priv->registrationLastSeen = jiffies;
1629 if (!netif_queue_stopped(dev) && !priv->under_reset && !priv->under_config)
1630 netif_wake_queue (dev);
1636 arlan_command_process(dev);
1638 rxStatus = READSHMB(arlan->rxStatus);
1639 txStatus = READSHMB(arlan->txStatus);
1640 rxOffset = READSHMS(arlan->rxOffset);
1641 pkt_len = READSHMS(arlan->rxLength);
1644 priv->irq_test_done = 1;
1648 priv->interrupt_processing_active = 0;
1651 arlan_command_process(dev);
1653 ARLAN_DEBUG_EXIT("arlan_process_interrupt");
1657 static irqreturn_t arlan_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1659 struct net_device *dev = dev_id;
1660 struct arlan_private *priv = netdev_priv(dev);
1661 volatile struct arlan_shmem __iomem *arlan = priv->card;
1662 u_char rxStatus = READSHMB(arlan->rxStatus);
1663 u_char txStatus = READSHMB(arlan->txStatus);
1665 ARLAN_DEBUG_ENTRY("arlan_interrupt");
1668 if (!rxStatus && !txStatus)
1669 priv->interrupt_ack_requested++;
1671 arlan_process_interrupt(dev);
1673 priv->irq_test_done = 1;
1675 ARLAN_DEBUG_EXIT("arlan_interrupt");
1681 static int arlan_close(struct net_device *dev)
1683 struct arlan_private *priv = netdev_priv(dev);
1685 ARLAN_DEBUG_ENTRY("arlan_close");
1687 del_timer_sync(&priv->timer);
1689 arlan_command(dev, ARLAN_COMMAND_POWERDOWN);
1691 IFDEBUG(ARLAN_DEBUG_STARTUP)
1692 printk(KERN_NOTICE "%s: Closing device\n", dev->name);
1694 netif_stop_queue(dev);
1695 free_irq(dev->irq, dev);
1697 ARLAN_DEBUG_EXIT("arlan_close");
1701 #ifdef ARLAN_DEBUGGING
1702 static long alignLong(volatile u_char * ptr)
1705 memcpy_fromio(&ret, (void *) ptr, 4);
1711 * Get the current statistics.
1712 * This may be called with the card open or closed.
1715 static struct net_device_stats *arlan_statistics(struct net_device *dev)
1717 struct arlan_private *priv = netdev_priv(dev);
1718 volatile struct arlan_shmem __iomem *arlan = priv->card;
1721 ARLAN_DEBUG_ENTRY("arlan_statistics");
1723 /* Update the statistics from the device registers. */
1725 READSHM(priv->stats.collisions, arlan->numReTransmissions, u_int);
1726 READSHM(priv->stats.rx_crc_errors, arlan->numCRCErrors, u_int);
1727 READSHM(priv->stats.rx_dropped, arlan->numFramesDiscarded, u_int);
1728 READSHM(priv->stats.rx_fifo_errors, arlan->numRXBufferOverflows, u_int);
1729 READSHM(priv->stats.rx_frame_errors, arlan->numReceiveFramesLost, u_int);
1730 READSHM(priv->stats.rx_over_errors, arlan->numRXOverruns, u_int);
1731 READSHM(priv->stats.rx_packets, arlan->numDatagramsReceived, u_int);
1732 READSHM(priv->stats.tx_aborted_errors, arlan->numAbortErrors, u_int);
1733 READSHM(priv->stats.tx_carrier_errors, arlan->numStatusTimeouts, u_int);
1734 READSHM(priv->stats.tx_dropped, arlan->numDatagramsDiscarded, u_int);
1735 READSHM(priv->stats.tx_fifo_errors, arlan->numTXUnderruns, u_int);
1736 READSHM(priv->stats.tx_packets, arlan->numDatagramsTransmitted, u_int);
1737 READSHM(priv->stats.tx_window_errors, arlan->numHoldOffs, u_int);
1739 ARLAN_DEBUG_EXIT("arlan_statistics");
1741 return &priv->stats;
1745 static void arlan_set_multicast(struct net_device *dev)
1747 struct arlan_private *priv = netdev_priv(dev);
1748 volatile struct arlan_shmem __iomem *arlan = priv->card;
1749 struct arlan_conf_stru *conf = priv->Conf;
1750 int board_conf_needed = 0;
1753 ARLAN_DEBUG_ENTRY("arlan_set_multicast");
1755 if (dev->flags & IFF_PROMISC)
1757 unsigned char recMode;
1758 READSHM(recMode, arlan->receiveMode, u_char);
1759 conf->receiveMode = (ARLAN_RCV_PROMISC | ARLAN_RCV_CONTROL);
1760 if (conf->receiveMode != recMode)
1761 board_conf_needed = 1;
1765 /* turn off promiscuous mode */
1766 unsigned char recMode;
1767 READSHM(recMode, arlan->receiveMode, u_char);
1768 conf->receiveMode = ARLAN_RCV_CLEAN | ARLAN_RCV_CONTROL;
1769 if (conf->receiveMode != recMode)
1770 board_conf_needed = 1;
1772 if (board_conf_needed)
1773 arlan_command(dev, ARLAN_COMMAND_CONF);
1775 ARLAN_DEBUG_EXIT("arlan_set_multicast");
1779 struct net_device * __init arlan_probe(int unit)
1781 struct net_device *dev;
1785 ARLAN_DEBUG_ENTRY("arlan_probe");
1787 if (arlans_found == MAX_ARLANS)
1788 return ERR_PTR(-ENODEV);
1791 * Reserve space for local data and a copy of the shared memory
1792 * that is used by the /proc interface.
1794 dev = alloc_etherdev(sizeof(struct arlan_private)
1795 + sizeof(struct arlan_shmem));
1797 return ERR_PTR(-ENOMEM);
1799 SET_MODULE_OWNER(dev);
1802 sprintf(dev->name, "eth%d", unit);
1803 netdev_boot_setup_check(dev);
1805 if (dev->mem_start) {
1806 if (arlan_probe_here(dev, dev->mem_start) == 0)
1814 for (m = (int)phys_to_virt(lastFoundAt) + ARLAN_SHMEM_SIZE;
1815 m <= (int)phys_to_virt(0xDE000);
1816 m += ARLAN_SHMEM_SIZE)
1818 if (arlan_probe_here(dev, m) == 0)
1820 lastFoundAt = (int)virt_to_phys((void*)m);
1825 if (lastFoundAt == 0xbe000)
1826 printk(KERN_ERR "arlan: No Arlan devices found \n");
1830 return ERR_PTR(-ENODEV);
1833 err = arlan_setup_device(dev, arlans_found);
1836 else if (!arlans_found++)
1837 printk(KERN_INFO "Arlan driver %s\n", arlan_version);
1843 int init_module(void)
1847 ARLAN_DEBUG_ENTRY("init_module");
1849 if (channelSet != channelSetUNKNOWN || channelNumber != channelNumberUNKNOWN || systemId != systemIdUNKNOWN)
1852 for (i = 0; i < MAX_ARLANS; i++) {
1853 struct net_device *dev = arlan_probe(i);
1856 return PTR_ERR(dev);
1859 printk(KERN_INFO "Arlan driver %s\n", arlan_version);
1860 ARLAN_DEBUG_EXIT("init_module");
1865 void cleanup_module(void)
1868 struct net_device *dev;
1870 ARLAN_DEBUG_ENTRY("cleanup_module");
1872 IFDEBUG(ARLAN_DEBUG_SHUTDOWN)
1873 printk(KERN_INFO "arlan: unloading module\n");
1875 cleanup_arlan_proc();
1877 for (i = 0; i < MAX_ARLANS; i++)
1879 dev = arlan_device[i];
1881 arlan_command(dev, ARLAN_COMMAND_POWERDOWN );
1883 unregister_netdev(dev);
1884 release_mem_region(virt_to_phys((void *) dev->mem_start),
1887 arlan_device[i] = NULL;
1891 ARLAN_DEBUG_EXIT("cleanup_module");
1896 MODULE_LICENSE("GPL");