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 testMemory
= testMemoryUNKNOWN
;
37 static int irq
= irqUNKNOWN
;
38 static int txScrambled
= 1;
41 module_param(irq
, int, 0);
42 module_param(mdebug
, int, 0);
43 module_param(testMemory
, int, 0);
44 module_param(txScrambled
, int, 0);
45 MODULE_PARM_DESC(irq
, "(unused)");
46 MODULE_PARM_DESC(testMemory
, "(unused)");
47 MODULE_PARM_DESC(mdebug
, "Arlan multicast debugging (0-1)");
50 module_param_named(debug
, arlan_debug
, int, 0);
51 module_param(spreadingCode
, int, 0);
52 module_param(channelNumber
, int, 0);
53 module_param(channelSet
, int, 0);
54 module_param(systemId
, int, 0);
55 module_param(registrationMode
, int, 0);
56 module_param(radioNodeId
, int, 0);
57 module_param(SID
, int, 0);
58 module_param(keyStart
, int, 0);
59 module_param(tx_delay_ms
, int, 0);
60 module_param(retries
, int, 0);
61 module_param(tx_queue_len
, int, 0);
62 module_param_named(EEPROM_bad
, arlan_EEPROM_bad
, int, 0);
63 MODULE_PARM_DESC(debug
, "Arlan debug enable (0-1)");
64 MODULE_PARM_DESC(retries
, "Arlan maximum packet retransmisions");
65 #ifdef ARLAN_ENTRY_EXIT_DEBUGGING
66 static int arlan_entry_debug
;
67 static int arlan_exit_debug
;
68 static int arlan_entry_and_exit_debug
;
69 module_param_named(entry_debug
, arlan_entry_debug
, int, 0);
70 module_param_named(exit_debug
, arlan_exit_debug
, int, 0);
71 module_param_named(entry_and_exit_debug
, arlan_entry_and_exit_debug
, int, 0);
72 MODULE_PARM_DESC(entry_debug
, "Arlan driver function entry debugging");
73 MODULE_PARM_DESC(exit_debug
, "Arlan driver function exit debugging");
74 MODULE_PARM_DESC(entry_and_exit_debug
, "Arlan driver function entry and exit debugging");
77 struct arlan_conf_stru arlan_conf
[MAX_ARLANS
];
78 static int arlans_found
;
80 static int arlan_open(struct net_device
*dev
);
81 static int arlan_tx(struct sk_buff
*skb
, struct net_device
*dev
);
82 static irqreturn_t
arlan_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
);
83 static int arlan_close(struct net_device
*dev
);
84 static struct net_device_stats
*
85 arlan_statistics (struct net_device
*dev
);
86 static void arlan_set_multicast (struct net_device
*dev
);
87 static int arlan_hw_tx (struct net_device
* dev
, char *buf
, int length
);
88 static int arlan_hw_config (struct net_device
* dev
);
89 static void arlan_tx_done_interrupt (struct net_device
* dev
, int status
);
90 static void arlan_rx_interrupt (struct net_device
* dev
, u_char rxStatus
, u_short
, u_short
);
91 static void arlan_process_interrupt (struct net_device
* dev
);
92 static void arlan_tx_timeout (struct net_device
*dev
);
94 static inline long us2ticks(int us
)
96 return us
* (1000000 / HZ
);
100 #ifdef ARLAN_ENTRY_EXIT_DEBUGGING
101 #define ARLAN_DEBUG_ENTRY(name) \
103 struct timeval timev;\
104 do_gettimeofday(&timev);\
105 if (arlan_entry_debug || arlan_entry_and_exit_debug)\
106 printk("--->>>" name " %ld " "\n",((long int) timev.tv_sec * 1000000 + timev.tv_usec));\
108 #define ARLAN_DEBUG_EXIT(name) \
110 struct timeval timev;\
111 do_gettimeofday(&timev);\
112 if (arlan_exit_debug || arlan_entry_and_exit_debug)\
113 printk("<<<---" name " %ld " "\n",((long int) timev.tv_sec * 1000000 + timev.tv_usec) );\
116 #define ARLAN_DEBUG_ENTRY(name)
117 #define ARLAN_DEBUG_EXIT(name)
121 #define arlan_interrupt_ack(dev)\
122 clearClearInterrupt(dev);\
123 setClearInterrupt(dev);
125 static inline int arlan_drop_tx(struct net_device
*dev
)
127 struct arlan_private
*priv
= netdev_priv(dev
);
129 priv
->stats
.tx_errors
++;
130 if (priv
->Conf
->tx_delay_ms
)
132 priv
->tx_done_delayed
= jiffies
+ priv
->Conf
->tx_delay_ms
* HZ
/ 1000 + 1;
136 priv
->waiting_command_mask
&= ~ARLAN_COMMAND_TX
;
137 TXHEAD(dev
).offset
= 0;
138 TXTAIL(dev
).offset
= 0;
141 if (!priv
->under_reset
&& !priv
->under_config
)
142 netif_wake_queue (dev
);
148 int arlan_command(struct net_device
*dev
, int command_p
)
150 struct arlan_private
*priv
= netdev_priv(dev
);
151 volatile struct arlan_shmem __iomem
*arlan
= priv
->card
;
152 struct arlan_conf_stru
*conf
= priv
->Conf
;
157 ARLAN_DEBUG_ENTRY("arlan_command");
159 if (priv
->card_polling_interval
)
160 priv
->card_polling_interval
= 1;
162 if (arlan_debug
& ARLAN_DEBUG_CHAIN_LOCKS
)
163 printk(KERN_DEBUG
"arlan_command, %lx commandByte %x waiting %lx incoming %x \n",
164 jiffies
, READSHMB(arlan
->commandByte
),
165 priv
->waiting_command_mask
, command_p
);
167 priv
->waiting_command_mask
|= command_p
;
169 if (priv
->waiting_command_mask
& ARLAN_COMMAND_RESET
)
170 if (time_after(jiffies
, priv
->lastReset
+ 5 * HZ
))
171 priv
->waiting_command_mask
&= ~ARLAN_COMMAND_RESET
;
173 if (priv
->waiting_command_mask
& ARLAN_COMMAND_INT_ACK
)
175 arlan_interrupt_ack(dev
);
176 priv
->waiting_command_mask
&= ~ARLAN_COMMAND_INT_ACK
;
178 if (priv
->waiting_command_mask
& ARLAN_COMMAND_INT_ENABLE
)
180 setInterruptEnable(dev
);
181 priv
->waiting_command_mask
&= ~ARLAN_COMMAND_INT_ENABLE
;
184 /* Card access serializing lock */
185 spin_lock_irqsave(&priv
->lock
, flags
);
187 /* Check cards status and waiting */
189 if (priv
->waiting_command_mask
& (ARLAN_COMMAND_LONG_WAIT_NOW
| ARLAN_COMMAND_WAIT_NOW
))
191 while (priv
->waiting_command_mask
& (ARLAN_COMMAND_LONG_WAIT_NOW
| ARLAN_COMMAND_WAIT_NOW
))
193 if (READSHMB(arlan
->resetFlag
) ||
194 READSHMB(arlan
->commandByte
)) /* ||
195 (readControlRegister(dev) & ARLAN_ACCESS))
199 priv
->waiting_command_mask
&= ~(ARLAN_COMMAND_LONG_WAIT_NOW
| ARLAN_COMMAND_WAIT_NOW
);
203 if (priv
->waiting_command_mask
& ARLAN_COMMAND_LONG_WAIT_NOW
)
205 if (udelayed
* 40 > 1000000)
207 printk(KERN_ERR
"%s long wait too long \n", dev
->name
);
208 priv
->waiting_command_mask
|= ARLAN_COMMAND_RESET
;
212 else if (priv
->waiting_command_mask
& ARLAN_COMMAND_WAIT_NOW
)
214 if (udelayed
* 40 > 1000)
216 printk(KERN_ERR
"%s short wait too long \n", dev
->name
);
225 while ((READSHMB(arlan
->resetFlag
) ||
226 READSHMB(arlan
->commandByte
)) &&
227 conf
->pre_Command_Wait
> (i
++) * 10)
231 if ((READSHMB(arlan
->resetFlag
) ||
232 READSHMB(arlan
->commandByte
)) &&
233 !(priv
->waiting_command_mask
& ARLAN_COMMAND_RESET
))
238 if (priv
->waiting_command_mask
& ARLAN_COMMAND_RESET
)
239 priv
->under_reset
= 1;
240 if (priv
->waiting_command_mask
& ARLAN_COMMAND_CONF
)
241 priv
->under_config
= 1;
243 /* Issuing command */
244 arlan_lock_card_access(dev
);
245 if (priv
->waiting_command_mask
& ARLAN_COMMAND_POWERUP
)
247 // if (readControlRegister(dev) & (ARLAN_ACCESS && ARLAN_POWER))
249 arlan_interrupt_lancpu(dev
);
250 priv
->waiting_command_mask
&= ~ARLAN_COMMAND_POWERUP
;
251 priv
->waiting_command_mask
|= ARLAN_COMMAND_RESET
;
252 priv
->card_polling_interval
= HZ
/ 10;
254 else if (priv
->waiting_command_mask
& ARLAN_COMMAND_ACTIVATE
)
256 WRITESHMB(arlan
->commandByte
, ARLAN_COM_ACTIVATE
);
257 arlan_interrupt_lancpu(dev
);
258 priv
->waiting_command_mask
&= ~ARLAN_COMMAND_ACTIVATE
;
259 priv
->card_polling_interval
= HZ
/ 10;
261 else if (priv
->waiting_command_mask
& ARLAN_COMMAND_RX_ABORT
)
263 if (priv
->rx_command_given
)
265 WRITESHMB(arlan
->commandByte
, ARLAN_COM_RX_ABORT
);
266 arlan_interrupt_lancpu(dev
);
267 priv
->rx_command_given
= 0;
269 priv
->waiting_command_mask
&= ~ARLAN_COMMAND_RX_ABORT
;
270 priv
->card_polling_interval
= 1;
272 else if (priv
->waiting_command_mask
& ARLAN_COMMAND_TX_ABORT
)
274 if (priv
->tx_command_given
)
276 WRITESHMB(arlan
->commandByte
, ARLAN_COM_TX_ABORT
);
277 arlan_interrupt_lancpu(dev
);
278 priv
->tx_command_given
= 0;
280 priv
->waiting_command_mask
&= ~ARLAN_COMMAND_TX_ABORT
;
281 priv
->card_polling_interval
= 1;
283 else if (priv
->waiting_command_mask
& ARLAN_COMMAND_RESET
)
286 netif_stop_queue (dev
);
289 if (priv
->tx_command_given
|| priv
->rx_command_given
)
291 printk(KERN_ERR
"%s: Reset under tx or rx command \n", dev
->name
);
293 netif_stop_queue (dev
);
294 if (arlan_debug
& ARLAN_DEBUG_RESET
)
295 printk(KERN_ERR
"%s: Doing chip reset\n", dev
->name
);
296 priv
->lastReset
= jiffies
;
297 WRITESHM(arlan
->commandByte
, 0, u_char
);
298 /* hold card in reset state */
299 setHardwareReset(dev
);
300 /* set reset flag and then release reset */
301 WRITESHM(arlan
->resetFlag
, 0xff, u_char
);
302 clearChannelAttention(dev
);
303 clearHardwareReset(dev
);
304 priv
->card_polling_interval
= HZ
/ 4;
305 priv
->waiting_command_mask
&= ~ARLAN_COMMAND_RESET
;
306 priv
->waiting_command_mask
|= ARLAN_COMMAND_INT_RACK
;
307 // priv->waiting_command_mask |= ARLAN_COMMAND_INT_RENABLE;
308 // priv->waiting_command_mask |= ARLAN_COMMAND_RX;
310 else if (priv
->waiting_command_mask
& ARLAN_COMMAND_INT_RACK
)
312 clearHardwareReset(dev
);
313 clearClearInterrupt(dev
);
314 setClearInterrupt(dev
);
315 setInterruptEnable(dev
);
316 priv
->waiting_command_mask
&= ~ARLAN_COMMAND_INT_RACK
;
317 priv
->waiting_command_mask
|= ARLAN_COMMAND_CONF
;
318 priv
->under_config
= 1;
319 priv
->under_reset
= 0;
321 else if (priv
->waiting_command_mask
& ARLAN_COMMAND_INT_RENABLE
)
323 setInterruptEnable(dev
);
324 priv
->waiting_command_mask
&= ~ARLAN_COMMAND_INT_RENABLE
;
326 else if (priv
->waiting_command_mask
& ARLAN_COMMAND_CONF
)
328 if (priv
->tx_command_given
|| priv
->rx_command_given
)
330 printk(KERN_ERR
"%s: Reset under tx or rx command \n", dev
->name
);
333 setInterruptEnable(dev
);
334 arlan_hw_config(dev
);
335 arlan_interrupt_lancpu(dev
);
336 priv
->waiting_command_mask
&= ~ARLAN_COMMAND_CONF
;
337 priv
->card_polling_interval
= HZ
/ 10;
338 // priv->waiting_command_mask |= ARLAN_COMMAND_INT_RACK;
339 // priv->waiting_command_mask |= ARLAN_COMMAND_INT_ENABLE;
340 priv
->waiting_command_mask
|= ARLAN_COMMAND_CONF_WAIT
;
342 else if (priv
->waiting_command_mask
& ARLAN_COMMAND_CONF_WAIT
)
344 if (READSHMB(arlan
->configuredStatusFlag
) != 0 &&
345 READSHMB(arlan
->diagnosticInfo
) == 0xff)
347 priv
->waiting_command_mask
&= ~ARLAN_COMMAND_CONF_WAIT
;
348 priv
->waiting_command_mask
|= ARLAN_COMMAND_RX
;
349 priv
->waiting_command_mask
|= ARLAN_COMMAND_TBUSY_CLEAR
;
350 priv
->card_polling_interval
= HZ
/ 10;
351 priv
->tx_command_given
= 0;
352 priv
->under_config
= 0;
356 priv
->card_polling_interval
= 1;
357 if (arlan_debug
& ARLAN_DEBUG_TIMING
)
358 printk(KERN_ERR
"configure delayed \n");
361 else if (priv
->waiting_command_mask
& ARLAN_COMMAND_RX
)
363 if (!registrationBad(dev
))
365 setInterruptEnable(dev
);
366 memset_io(arlan
->commandParameter
, 0, 0xf);
367 WRITESHMB(arlan
->commandByte
, ARLAN_COM_INT
| ARLAN_COM_RX_ENABLE
);
368 WRITESHMB(arlan
->commandParameter
[0], conf
->rxParameter
);
369 arlan_interrupt_lancpu(dev
);
370 priv
->rx_command_given
= 0; // mnjah, bad
371 priv
->waiting_command_mask
&= ~ARLAN_COMMAND_RX
;
372 priv
->card_polling_interval
= 1;
375 priv
->card_polling_interval
= 2;
377 else if (priv
->waiting_command_mask
& ARLAN_COMMAND_TBUSY_CLEAR
)
379 if ( !registrationBad(dev
) &&
380 (netif_queue_stopped(dev
) || !netif_running(dev
)) )
382 priv
->waiting_command_mask
&= ~ARLAN_COMMAND_TBUSY_CLEAR
;
383 netif_wake_queue (dev
);
386 else if (priv
->waiting_command_mask
& ARLAN_COMMAND_TX
)
388 if (!test_and_set_bit(0, (void *) &priv
->tx_command_given
))
390 if (time_after(jiffies
,
391 priv
->tx_last_sent
+ us2ticks(conf
->rx_tweak1
))
392 || time_before(jiffies
,
393 priv
->last_rx_int_ack_time
+ us2ticks(conf
->rx_tweak2
)))
395 setInterruptEnable(dev
);
396 memset_io(arlan
->commandParameter
, 0, 0xf);
397 WRITESHMB(arlan
->commandByte
, ARLAN_COM_TX_ENABLE
| ARLAN_COM_INT
);
398 memcpy_toio(arlan
->commandParameter
, &TXLAST(dev
), 14);
399 // for ( i=1 ; i < 15 ; i++) printk("%02x:",READSHMB(arlan->commandParameter[i]));
400 priv
->tx_last_sent
= jiffies
;
401 arlan_interrupt_lancpu(dev
);
402 priv
->tx_command_given
= 1;
403 priv
->waiting_command_mask
&= ~ARLAN_COMMAND_TX
;
404 priv
->card_polling_interval
= 1;
408 priv
->tx_command_given
= 0;
409 priv
->card_polling_interval
= 1;
412 else if (arlan_debug
& ARLAN_DEBUG_CHAIN_LOCKS
)
413 printk(KERN_ERR
"tx command when tx chain locked \n");
415 else if (priv
->waiting_command_mask
& ARLAN_COMMAND_NOOPINT
)
418 WRITESHMB(arlan
->commandByte
, ARLAN_COM_NOP
| ARLAN_COM_INT
);
420 arlan_interrupt_lancpu(dev
);
421 priv
->waiting_command_mask
&= ~ARLAN_COMMAND_NOOPINT
;
422 priv
->card_polling_interval
= HZ
/ 3;
424 else if (priv
->waiting_command_mask
& ARLAN_COMMAND_NOOP
)
426 WRITESHMB(arlan
->commandByte
, ARLAN_COM_NOP
);
427 arlan_interrupt_lancpu(dev
);
428 priv
->waiting_command_mask
&= ~ARLAN_COMMAND_NOOP
;
429 priv
->card_polling_interval
= HZ
/ 3;
431 else if (priv
->waiting_command_mask
& ARLAN_COMMAND_SLOW_POLL
)
433 WRITESHMB(arlan
->commandByte
, ARLAN_COM_GOTO_SLOW_POLL
);
434 arlan_interrupt_lancpu(dev
);
435 priv
->waiting_command_mask
&= ~ARLAN_COMMAND_SLOW_POLL
;
436 priv
->card_polling_interval
= HZ
/ 3;
438 else if (priv
->waiting_command_mask
& ARLAN_COMMAND_POWERDOWN
)
441 if (arlan_debug
& ARLAN_DEBUG_CARD_STATE
)
442 printk(KERN_WARNING
"%s: Arlan Going Standby\n", dev
->name
);
443 priv
->waiting_command_mask
&= ~ARLAN_COMMAND_POWERDOWN
;
444 priv
->card_polling_interval
= 3 * HZ
;
446 arlan_unlock_card_access(dev
);
447 for (i
= 0; READSHMB(arlan
->commandByte
) && i
< 20; i
++)
449 if (READSHMB(arlan
->commandByte
))
450 if (arlan_debug
& ARLAN_DEBUG_CARD_STATE
)
451 printk(KERN_ERR
"card busy leaving command %lx\n", priv
->waiting_command_mask
);
453 spin_unlock_irqrestore(&priv
->lock
, flags
);
454 ARLAN_DEBUG_EXIT("arlan_command");
455 priv
->last_command_buff_free_time
= jiffies
;
459 if (time_after(jiffies
, priv
->last_command_buff_free_time
+ HZ
))
460 priv
->waiting_command_mask
|= ARLAN_COMMAND_CLEAN_AND_RESET
;
462 if (arlan_debug
& ARLAN_DEBUG_CARD_STATE
)
463 printk(KERN_ERR
"%s arlan_command card busy end \n", dev
->name
);
464 spin_unlock_irqrestore(&priv
->lock
, flags
);
465 ARLAN_DEBUG_EXIT("arlan_command");
469 printk(KERN_ERR
"%s arlan_command bad end \n", dev
->name
);
471 spin_unlock_irqrestore(&priv
->lock
, flags
);
472 ARLAN_DEBUG_EXIT("arlan_command");
477 static inline void arlan_command_process(struct net_device
*dev
)
479 struct arlan_private
*priv
= netdev_priv(dev
);
482 while (priv
->waiting_command_mask
&& times
< 8)
484 if (priv
->waiting_command_mask
)
486 if (arlan_command(dev
, 0))
490 /* if long command, we won't repeat trying */ ;
491 if (priv
->card_polling_interval
> 1)
498 static inline void arlan_retransmit_now(struct net_device
*dev
)
500 struct arlan_private
*priv
= netdev_priv(dev
);
503 ARLAN_DEBUG_ENTRY("arlan_retransmit_now");
504 if (TXLAST(dev
).offset
== 0)
506 if (TXHEAD(dev
).offset
)
509 IFDEBUG(ARLAN_DEBUG_TX_CHAIN
) printk(KERN_DEBUG
"TX buff switch to head \n");
512 else if (TXTAIL(dev
).offset
)
514 IFDEBUG(ARLAN_DEBUG_TX_CHAIN
) printk(KERN_DEBUG
"TX buff switch to tail \n");
518 IFDEBUG(ARLAN_DEBUG_TX_CHAIN
) printk(KERN_ERR
"ReTransmit buff empty");
519 netif_wake_queue (dev
);
523 arlan_command(dev
, ARLAN_COMMAND_TX
);
525 priv
->Conf
->driverRetransmissions
++;
526 priv
->retransmissions
++;
528 IFDEBUG(ARLAN_DEBUG_TX_CHAIN
) printk("Retransmit %d bytes \n", TXLAST(dev
).length
);
530 ARLAN_DEBUG_EXIT("arlan_retransmit_now");
535 static void arlan_registration_timer(unsigned long data
)
537 struct net_device
*dev
= (struct net_device
*) data
;
538 struct arlan_private
*priv
= netdev_priv(dev
);
539 int bh_mark_needed
= 0;
541 long lostTime
= ((long)jiffies
- (long)priv
->registrationLastSeen
)
544 if (registrationBad(dev
))
546 priv
->registrationLostCount
++;
547 if (lostTime
> 7000 && lostTime
< 7200)
549 printk(KERN_NOTICE
"%s registration Lost \n", dev
->name
);
551 if (lostTime
/ priv
->reRegisterExp
> 2000)
552 arlan_command(dev
, ARLAN_COMMAND_CLEAN_AND_CONF
);
553 if (lostTime
/ (priv
->reRegisterExp
) > 3500)
554 arlan_command(dev
, ARLAN_COMMAND_CLEAN_AND_RESET
);
555 if (priv
->reRegisterExp
< 400)
556 priv
->reRegisterExp
+= 2;
560 arlan_command(dev
, ARLAN_COMMAND_CLEAN_AND_RESET
);
565 if (priv
->Conf
->registrationMode
&& lostTime
> 10000 &&
566 priv
->registrationLostCount
)
568 printk(KERN_NOTICE
"%s registration is back after %ld milliseconds\n",
569 dev
->name
, lostTime
);
571 priv
->registrationLastSeen
= jiffies
;
572 priv
->registrationLostCount
= 0;
573 priv
->reRegisterExp
= 1;
574 if (!netif_running(dev
) )
575 netif_wake_queue(dev
);
576 if (time_after(priv
->tx_last_sent
,priv
->tx_last_cleared
) &&
577 time_after(jiffies
, priv
->tx_last_sent
* 5*HZ
) ){
578 arlan_command(dev
, ARLAN_COMMAND_CLEAN_AND_RESET
);
579 priv
->tx_last_cleared
= jiffies
;
584 if (!registrationBad(dev
) && priv
->ReTransmitRequested
)
586 IFDEBUG(ARLAN_DEBUG_TX_CHAIN
)
587 printk(KERN_ERR
"Retransmit from timer \n");
588 priv
->ReTransmitRequested
= 0;
589 arlan_retransmit_now(dev
);
591 if (!registrationBad(dev
) &&
592 time_after(jiffies
, priv
->tx_done_delayed
) &&
593 priv
->tx_done_delayed
!= 0)
595 TXLAST(dev
).offset
= 0;
598 else if (TXTAIL(dev
).offset
)
600 if (TXLAST(dev
).offset
)
602 arlan_retransmit_now(dev
);
603 dev
->trans_start
= jiffies
;
605 if (!(TXHEAD(dev
).offset
&& TXTAIL(dev
).offset
))
607 netif_wake_queue (dev
);
609 priv
->tx_done_delayed
= 0;
614 netif_wake_queue (dev
);
616 arlan_process_interrupt(dev
);
618 if (next_tick
< priv
->card_polling_interval
)
619 next_tick
= priv
->card_polling_interval
;
621 priv
->timer
.expires
= jiffies
+ next_tick
;
623 add_timer(&priv
->timer
);
627 #ifdef ARLAN_DEBUGGING
629 static void arlan_print_registers(struct net_device
*dev
, int line
)
631 struct arlan_private
*priv
= netdev_priv(dev
);
632 volatile struct arlan_shmem
*arlan
= priv
->card
;
634 u_char hostcpuLock
, lancpuLock
, controlRegister
, cntrlRegImage
,
635 txStatus
, rxStatus
, interruptInProgress
, commandByte
;
638 ARLAN_DEBUG_ENTRY("arlan_print_registers");
639 READSHM(interruptInProgress
, arlan
->interruptInProgress
, u_char
);
640 READSHM(hostcpuLock
, arlan
->hostcpuLock
, u_char
);
641 READSHM(lancpuLock
, arlan
->lancpuLock
, u_char
);
642 READSHM(controlRegister
, arlan
->controlRegister
, u_char
);
643 READSHM(cntrlRegImage
, arlan
->cntrlRegImage
, u_char
);
644 READSHM(txStatus
, arlan
->txStatus
, u_char
);
645 READSHM(rxStatus
, arlan
->rxStatus
, u_char
);
646 READSHM(commandByte
, arlan
->commandByte
, u_char
);
648 printk(KERN_WARNING
"line %04d IP %02x HL %02x LL %02x CB %02x CR %02x CRI %02x TX %02x RX %02x\n",
649 line
, interruptInProgress
, hostcpuLock
, lancpuLock
, commandByte
,
650 controlRegister
, cntrlRegImage
, txStatus
, rxStatus
);
652 ARLAN_DEBUG_EXIT("arlan_print_registers");
657 static int arlan_hw_tx(struct net_device
*dev
, char *buf
, int length
)
661 struct arlan_private
*priv
= netdev_priv(dev
);
662 volatile struct arlan_shmem __iomem
*arlan
= priv
->card
;
663 struct arlan_conf_stru
*conf
= priv
->Conf
;
665 int tailStarts
= 0x800;
669 ARLAN_DEBUG_ENTRY("arlan_hw_tx");
670 if (TXHEAD(dev
).offset
)
671 headEnds
= (((TXHEAD(dev
).offset
+ TXHEAD(dev
).length
- offsetof(struct arlan_shmem
, txBuffer
)) / 64) + 1) * 64;
672 if (TXTAIL(dev
).offset
)
673 tailStarts
= 0x800 - (((TXTAIL(dev
).offset
- offsetof(struct arlan_shmem
, txBuffer
)) / 64) + 2) * 64;
676 if (!TXHEAD(dev
).offset
&& length
< tailStarts
)
678 IFDEBUG(ARLAN_DEBUG_TX_CHAIN
)
679 printk(KERN_ERR
"TXHEAD insert, tailStart %d\n", tailStarts
);
682 offsetof(struct arlan_shmem
, txBuffer
);
683 TXHEAD(dev
).length
= length
- ARLAN_FAKE_HDR_LEN
;
684 for (i
= 0; i
< 6; i
++)
685 TXHEAD(dev
).dest
[i
] = buf
[i
];
686 TXHEAD(dev
).clear
= conf
->txClear
;
687 TXHEAD(dev
).retries
= conf
->txRetries
; /* 0 is use default */
688 TXHEAD(dev
).routing
= conf
->txRouting
;
689 TXHEAD(dev
).scrambled
= conf
->txScrambled
;
690 memcpy_toio((char __iomem
*)arlan
+ TXHEAD(dev
).offset
, buf
+ ARLAN_FAKE_HDR_LEN
, TXHEAD(dev
).length
);
692 else if (!TXTAIL(dev
).offset
&& length
< (0x800 - headEnds
))
694 IFDEBUG(ARLAN_DEBUG_TX_CHAIN
)
695 printk(KERN_ERR
"TXTAIL insert, headEnd %d\n", headEnds
);
698 offsetof(struct arlan_shmem
, txBuffer
) + 0x800 - (length
/ 64 + 2) * 64;
699 TXTAIL(dev
).length
= length
- ARLAN_FAKE_HDR_LEN
;
700 for (i
= 0; i
< 6; i
++)
701 TXTAIL(dev
).dest
[i
] = buf
[i
];
702 TXTAIL(dev
).clear
= conf
->txClear
;
703 TXTAIL(dev
).retries
= conf
->txRetries
;
704 TXTAIL(dev
).routing
= conf
->txRouting
;
705 TXTAIL(dev
).scrambled
= conf
->txScrambled
;
706 memcpy_toio(((char __iomem
*)arlan
+ TXTAIL(dev
).offset
), buf
+ ARLAN_FAKE_HDR_LEN
, TXTAIL(dev
).length
);
710 netif_stop_queue (dev
);
711 IFDEBUG(ARLAN_DEBUG_TX_CHAIN
)
712 printk(KERN_ERR
"TX TAIL & HEAD full, return, tailStart %d headEnd %d\n", tailStarts
, headEnds
);
715 priv
->out_bytes
+= length
;
716 priv
->out_bytes10
+= length
;
717 if (conf
->measure_rate
< 1)
718 conf
->measure_rate
= 1;
719 if (time_after(jiffies
, priv
->out_time
+ conf
->measure_rate
* HZ
))
721 conf
->out_speed
= priv
->out_bytes
/ conf
->measure_rate
;
723 priv
->out_time
= jiffies
;
725 if (time_after(jiffies
, priv
->out_time10
+ conf
->measure_rate
* 10*HZ
))
727 conf
->out_speed10
= priv
->out_bytes10
/ (10 * conf
->measure_rate
);
728 priv
->out_bytes10
= 0;
729 priv
->out_time10
= jiffies
;
731 if (TXHEAD(dev
).offset
&& TXTAIL(dev
).offset
)
733 netif_stop_queue (dev
);
737 netif_start_queue (dev
);
740 IFDEBUG(ARLAN_DEBUG_HEADER_DUMP
)
741 printk(KERN_WARNING
"%s Transmit t %2x:%2x:%2x:%2x:%2x:%2x f %2x:%2x:%2x:%2x:%2x:%2x \n", dev
->name
,
742 (unsigned char) buf
[0], (unsigned char) buf
[1], (unsigned char) buf
[2], (unsigned char) buf
[3],
743 (unsigned char) buf
[4], (unsigned char) buf
[5], (unsigned char) buf
[6], (unsigned char) buf
[7],
744 (unsigned char) buf
[8], (unsigned char) buf
[9], (unsigned char) buf
[10], (unsigned char) buf
[11]);
746 IFDEBUG(ARLAN_DEBUG_TX_CHAIN
) printk(KERN_ERR
"TX command prepare for buffer %d\n", priv
->txLast
);
748 arlan_command(dev
, ARLAN_COMMAND_TX
);
750 priv
->tx_last_sent
= jiffies
;
752 IFDEBUG(ARLAN_DEBUG_TX_CHAIN
) printk("%s TX Qued %d bytes \n", dev
->name
, length
);
754 ARLAN_DEBUG_EXIT("arlan_hw_tx");
760 static int arlan_hw_config(struct net_device
*dev
)
762 struct arlan_private
*priv
= netdev_priv(dev
);
763 volatile struct arlan_shmem __iomem
*arlan
= priv
->card
;
764 struct arlan_conf_stru
*conf
= priv
->Conf
;
766 ARLAN_DEBUG_ENTRY("arlan_hw_config");
768 printk(KERN_NOTICE
"%s arlan configure called \n", dev
->name
);
769 if (arlan_EEPROM_bad
)
770 printk(KERN_NOTICE
"arlan configure with eeprom bad option \n");
773 WRITESHM(arlan
->spreadingCode
, conf
->spreadingCode
, u_char
);
774 WRITESHM(arlan
->channelSet
, conf
->channelSet
, u_char
);
776 if (arlan_EEPROM_bad
)
777 WRITESHM(arlan
->defaultChannelSet
, conf
->channelSet
, u_char
);
779 WRITESHM(arlan
->channelNumber
, conf
->channelNumber
, u_char
);
781 WRITESHM(arlan
->scramblingDisable
, conf
->scramblingDisable
, u_char
);
782 WRITESHM(arlan
->txAttenuation
, conf
->txAttenuation
, u_char
);
784 WRITESHM(arlan
->systemId
, conf
->systemId
, u_int
);
786 WRITESHM(arlan
->maxRetries
, conf
->maxRetries
, u_char
);
787 WRITESHM(arlan
->receiveMode
, conf
->receiveMode
, u_char
);
788 WRITESHM(arlan
->priority
, conf
->priority
, u_char
);
789 WRITESHM(arlan
->rootOrRepeater
, conf
->rootOrRepeater
, u_char
);
790 WRITESHM(arlan
->SID
, conf
->SID
, u_int
);
792 WRITESHM(arlan
->registrationMode
, conf
->registrationMode
, u_char
);
794 WRITESHM(arlan
->registrationFill
, conf
->registrationFill
, u_char
);
795 WRITESHM(arlan
->localTalkAddress
, conf
->localTalkAddress
, u_char
);
796 WRITESHM(arlan
->codeFormat
, conf
->codeFormat
, u_char
);
797 WRITESHM(arlan
->numChannels
, conf
->numChannels
, u_char
);
798 WRITESHM(arlan
->channel1
, conf
->channel1
, u_char
);
799 WRITESHM(arlan
->channel2
, conf
->channel2
, u_char
);
800 WRITESHM(arlan
->channel3
, conf
->channel3
, u_char
);
801 WRITESHM(arlan
->channel4
, conf
->channel4
, u_char
);
802 WRITESHM(arlan
->radioNodeId
, conf
->radioNodeId
, u_short
);
803 WRITESHM(arlan
->SID
, conf
->SID
, u_int
);
804 WRITESHM(arlan
->waitTime
, conf
->waitTime
, u_short
);
805 WRITESHM(arlan
->lParameter
, conf
->lParameter
, u_short
);
806 memcpy_toio(&(arlan
->_15
), &(conf
->_15
), 3);
807 WRITESHM(arlan
->_15
, conf
->_15
, u_short
);
808 WRITESHM(arlan
->headerSize
, conf
->headerSize
, u_short
);
809 if (arlan_EEPROM_bad
)
810 WRITESHM(arlan
->hardwareType
, conf
->hardwareType
, u_char
);
811 WRITESHM(arlan
->radioType
, conf
->radioType
, u_char
);
812 if (arlan_EEPROM_bad
)
813 WRITESHM(arlan
->radioModule
, conf
->radioType
, u_char
);
815 memcpy_toio(arlan
->encryptionKey
+ keyStart
, encryptionKey
, 8);
816 memcpy_toio(arlan
->name
, conf
->siteName
, 16);
818 WRITESHMB(arlan
->commandByte
, ARLAN_COM_INT
| ARLAN_COM_CONF
); /* do configure */
819 memset_io(arlan
->commandParameter
, 0, 0xf); /* 0xf */
820 memset_io(arlan
->commandParameter
+ 1, 0, 2);
821 if (conf
->writeEEPROM
)
823 memset_io(arlan
->commandParameter
, conf
->writeEEPROM
, 1);
824 // conf->writeEEPROM=0;
826 if (conf
->registrationMode
&& conf
->registrationInterrupts
)
827 memset_io(arlan
->commandParameter
+ 3, 1, 1);
829 memset_io(arlan
->commandParameter
+ 3, 0, 1);
831 priv
->irq_test_done
= 0;
833 if (conf
->tx_queue_len
)
834 dev
->tx_queue_len
= conf
->tx_queue_len
;
837 ARLAN_DEBUG_EXIT("arlan_hw_config");
842 static int arlan_read_card_configuration(struct net_device
*dev
)
845 struct arlan_private
*priv
= netdev_priv(dev
);
846 volatile struct arlan_shmem __iomem
*arlan
= priv
->card
;
847 struct arlan_conf_stru
*conf
= priv
->Conf
;
849 ARLAN_DEBUG_ENTRY("arlan_read_card_configuration");
851 if (radioNodeId
== radioNodeIdUNKNOWN
)
853 READSHM(conf
->radioNodeId
, arlan
->radioNodeId
, u_short
);
856 conf
->radioNodeId
= radioNodeId
;
858 if (SID
== SIDUNKNOWN
)
860 READSHM(conf
->SID
, arlan
->SID
, u_int
);
862 else conf
->SID
= SID
;
864 if (spreadingCode
== spreadingCodeUNKNOWN
)
866 READSHM(conf
->spreadingCode
, arlan
->spreadingCode
, u_char
);
869 conf
->spreadingCode
= spreadingCode
;
871 if (channelSet
== channelSetUNKNOWN
)
873 READSHM(conf
->channelSet
, arlan
->channelSet
, u_char
);
875 else conf
->channelSet
= channelSet
;
877 if (channelNumber
== channelNumberUNKNOWN
)
879 READSHM(conf
->channelNumber
, arlan
->channelNumber
, u_char
);
881 else conf
->channelNumber
= channelNumber
;
883 READSHM(conf
->scramblingDisable
, arlan
->scramblingDisable
, u_char
);
884 READSHM(conf
->txAttenuation
, arlan
->txAttenuation
, u_char
);
886 if (systemId
== systemIdUNKNOWN
)
888 READSHM(conf
->systemId
, arlan
->systemId
, u_int
);
890 else conf
->systemId
= systemId
;
892 READSHM(conf
->maxDatagramSize
, arlan
->maxDatagramSize
, u_short
);
893 READSHM(conf
->maxFrameSize
, arlan
->maxFrameSize
, u_short
);
894 READSHM(conf
->maxRetries
, arlan
->maxRetries
, u_char
);
895 READSHM(conf
->receiveMode
, arlan
->receiveMode
, u_char
);
896 READSHM(conf
->priority
, arlan
->priority
, u_char
);
897 READSHM(conf
->rootOrRepeater
, arlan
->rootOrRepeater
, u_char
);
899 if (SID
== SIDUNKNOWN
)
901 READSHM(conf
->SID
, arlan
->SID
, u_int
);
903 else conf
->SID
= SID
;
905 if (registrationMode
== registrationModeUNKNOWN
)
907 READSHM(conf
->registrationMode
, arlan
->registrationMode
, u_char
);
909 else conf
->registrationMode
= registrationMode
;
911 READSHM(conf
->registrationFill
, arlan
->registrationFill
, u_char
);
912 READSHM(conf
->localTalkAddress
, arlan
->localTalkAddress
, u_char
);
913 READSHM(conf
->codeFormat
, arlan
->codeFormat
, u_char
);
914 READSHM(conf
->numChannels
, arlan
->numChannels
, u_char
);
915 READSHM(conf
->channel1
, arlan
->channel1
, u_char
);
916 READSHM(conf
->channel2
, arlan
->channel2
, u_char
);
917 READSHM(conf
->channel3
, arlan
->channel3
, u_char
);
918 READSHM(conf
->channel4
, arlan
->channel4
, u_char
);
919 READSHM(conf
->waitTime
, arlan
->waitTime
, u_short
);
920 READSHM(conf
->lParameter
, arlan
->lParameter
, u_short
);
921 READSHM(conf
->_15
, arlan
->_15
, u_short
);
922 READSHM(conf
->headerSize
, arlan
->headerSize
, u_short
);
923 READSHM(conf
->hardwareType
, arlan
->hardwareType
, u_char
);
924 READSHM(conf
->radioType
, arlan
->radioModule
, u_char
);
926 if (conf
->radioType
== 0)
927 conf
->radioType
= 0xc;
929 WRITESHM(arlan
->configStatus
, 0xA5, u_char
);
930 READSHM(tlx415
, arlan
->configStatus
, u_char
);
933 printk(KERN_INFO
"%s tlx415 chip \n", dev
->name
);
938 conf
->txScrambled
= 0;
939 conf
->rxParameter
= 1;
940 conf
->txTimeoutMs
= 4000;
941 conf
->waitCardTimeout
= 100000;
942 conf
->receiveMode
= ARLAN_RCV_CLEAN
;
943 memcpy_fromio(conf
->siteName
, arlan
->name
, 16);
944 conf
->siteName
[16] = '\0';
945 conf
->retries
= retries
;
946 conf
->tx_delay_ms
= tx_delay_ms
;
947 conf
->ReTransmitPacketMaxSize
= 200;
948 conf
->waitReTransmitPacketMaxSize
= 200;
949 conf
->txAckTimeoutMs
= 900;
950 conf
->fastReTransCount
= 3;
952 ARLAN_DEBUG_EXIT("arlan_read_card_configuration");
958 static int lastFoundAt
= 0xbe000;
962 * This is the real probe routine. Linux has a history of friendly device
963 * probes on the ISA bus. A good device probes avoids doing writes, and
964 * verifies that the correct device exists and functions.
966 #define ARLAN_SHMEM_SIZE 0x2000
967 static int __init
arlan_check_fingerprint(unsigned long memaddr
)
969 static const char probeText
[] = "TELESYSTEM SLW INC. ARLAN \0";
970 volatile struct arlan_shmem __iomem
*arlan
= (struct arlan_shmem
*) memaddr
;
971 unsigned long paddr
= virt_to_phys((void *) memaddr
);
974 ARLAN_DEBUG_ENTRY("arlan_check_fingerprint");
976 if (!request_mem_region(paddr
, ARLAN_SHMEM_SIZE
, "arlan")) {
977 // printk(KERN_WARNING "arlan: memory region %lx excluded from probing \n",paddr);
981 memcpy_fromio(tempBuf
, arlan
->textRegion
, 29);
984 /* check for card at this address */
985 if (0 != strncmp(tempBuf
, probeText
, 29)){
986 release_mem_region(paddr
, ARLAN_SHMEM_SIZE
);
990 // printk(KERN_INFO "arlan found at 0x%x \n",memaddr);
991 ARLAN_DEBUG_EXIT("arlan_check_fingerprint");
996 static int arlan_change_mtu(struct net_device
*dev
, int new_mtu
)
998 struct arlan_private
*priv
= netdev_priv(dev
);
999 struct arlan_conf_stru
*conf
= priv
->Conf
;
1001 ARLAN_DEBUG_ENTRY("arlan_change_mtu");
1006 new_mtu
= 256; /* cards book suggests 1600 */
1007 conf
->maxDatagramSize
= new_mtu
;
1008 conf
->maxFrameSize
= new_mtu
+ 48;
1010 arlan_command(dev
, ARLAN_COMMAND_CLEAN_AND_CONF
);
1011 printk(KERN_NOTICE
"%s mtu changed to %d \n", dev
->name
, new_mtu
);
1013 ARLAN_DEBUG_EXIT("arlan_change_mtu");
1018 static int arlan_mac_addr(struct net_device
*dev
, void *p
)
1020 struct sockaddr
*addr
= p
;
1023 ARLAN_DEBUG_ENTRY("arlan_mac_addr");
1026 if (!netif_running(dev
))
1028 memcpy(dev
->dev_addr
, addr
->sa_data
, dev
->addr_len
);
1030 ARLAN_DEBUG_EXIT("arlan_mac_addr");
1036 static int __init
arlan_setup_device(struct net_device
*dev
, int num
)
1038 struct arlan_private
*ap
= netdev_priv(dev
);
1041 ARLAN_DEBUG_ENTRY("arlan_setup_device");
1043 ap
->conf
= (struct arlan_shmem
*)(ap
+1);
1045 dev
->tx_queue_len
= tx_queue_len
;
1046 dev
->open
= arlan_open
;
1047 dev
->stop
= arlan_close
;
1048 dev
->hard_start_xmit
= arlan_tx
;
1049 dev
->get_stats
= arlan_statistics
;
1050 dev
->set_multicast_list
= arlan_set_multicast
;
1051 dev
->change_mtu
= arlan_change_mtu
;
1052 dev
->set_mac_address
= arlan_mac_addr
;
1053 dev
->tx_timeout
= arlan_tx_timeout
;
1054 dev
->watchdog_timeo
= 3*HZ
;
1056 ap
->irq_test_done
= 0;
1057 ap
->Conf
= &arlan_conf
[num
];
1059 ap
->Conf
->pre_Command_Wait
= 40;
1060 ap
->Conf
->rx_tweak1
= 30;
1061 ap
->Conf
->rx_tweak2
= 0;
1064 err
= register_netdev(dev
);
1066 release_mem_region(virt_to_phys((void *) dev
->mem_start
),
1071 arlan_device
[num
] = dev
;
1072 ARLAN_DEBUG_EXIT("arlan_setup_device");
1076 static int __init
arlan_probe_here(struct net_device
*dev
,
1077 unsigned long memaddr
)
1079 struct arlan_private
*ap
= netdev_priv(dev
);
1081 ARLAN_DEBUG_ENTRY("arlan_probe_here");
1083 if (arlan_check_fingerprint(memaddr
))
1086 printk(KERN_NOTICE
"%s: Arlan found at %x, \n ", dev
->name
,
1087 (int) virt_to_phys((void*)memaddr
));
1089 ap
->card
= (void *) memaddr
;
1090 dev
->mem_start
= memaddr
;
1091 dev
->mem_end
= memaddr
+ ARLAN_SHMEM_SIZE
-1;
1095 READSHM(dev
->irq
, ap
->card
->irqLevel
, u_char
);
1096 } else if (dev
->irq
== 2)
1099 arlan_read_card_configuration(dev
);
1101 ARLAN_DEBUG_EXIT("arlan_probe_here");
1106 static int arlan_open(struct net_device
*dev
)
1108 struct arlan_private
*priv
= netdev_priv(dev
);
1109 volatile struct arlan_shmem __iomem
*arlan
= priv
->card
;
1112 ARLAN_DEBUG_ENTRY("arlan_open");
1114 ret
= request_irq(dev
->irq
, &arlan_interrupt
, 0, dev
->name
, dev
);
1117 printk(KERN_ERR
"%s: unable to get IRQ %d .\n",
1118 dev
->name
, dev
->irq
);
1124 priv
->lastReset
= 0;
1126 memcpy_fromio(dev
->dev_addr
, arlan
->lanCardNodeId
, 6);
1127 memset(dev
->broadcast
, 0xff, 6);
1128 dev
->tx_queue_len
= tx_queue_len
;
1129 priv
->interrupt_processing_active
= 0;
1130 spin_lock_init(&priv
->lock
);
1132 netif_start_queue (dev
);
1134 priv
->registrationLostCount
= 0;
1135 priv
->registrationLastSeen
= jiffies
;
1137 priv
->tx_command_given
= 0;
1138 priv
->rx_command_given
= 0;
1140 priv
->reRegisterExp
= 1;
1141 priv
->tx_last_sent
= jiffies
- 1;
1142 priv
->tx_last_cleared
= jiffies
;
1143 priv
->Conf
->writeEEPROM
= 0;
1144 priv
->Conf
->registrationInterrupts
= 1;
1146 init_timer(&priv
->timer
);
1147 priv
->timer
.expires
= jiffies
+ HZ
/ 10;
1148 priv
->timer
.data
= (unsigned long) dev
;
1149 priv
->timer
.function
= &arlan_registration_timer
; /* timer handler */
1151 arlan_command(dev
, ARLAN_COMMAND_POWERUP
| ARLAN_COMMAND_LONG_WAIT_NOW
);
1153 add_timer(&priv
->timer
);
1155 ARLAN_DEBUG_EXIT("arlan_open");
1160 static void arlan_tx_timeout (struct net_device
*dev
)
1162 printk(KERN_ERR
"%s: arlan transmit timed out, kernel decided\n", dev
->name
);
1163 /* Try to restart the adaptor. */
1164 arlan_command(dev
, ARLAN_COMMAND_CLEAN_AND_RESET
);
1165 // dev->trans_start = jiffies;
1166 // netif_start_queue (dev);
1170 static int arlan_tx(struct sk_buff
*skb
, struct net_device
*dev
)
1175 ARLAN_DEBUG_ENTRY("arlan_tx");
1177 length
= ETH_ZLEN
< skb
->len
? skb
->len
: ETH_ZLEN
;
1180 if (length
+ 0x12 > 0x800) {
1181 printk(KERN_ERR
"TX RING overflow \n");
1182 netif_stop_queue (dev
);
1185 if (arlan_hw_tx(dev
, buf
, length
) == -1)
1188 dev
->trans_start
= jiffies
;
1192 arlan_process_interrupt(dev
);
1193 ARLAN_DEBUG_EXIT("arlan_tx");
1197 arlan_process_interrupt(dev
);
1198 netif_stop_queue (dev
);
1199 ARLAN_DEBUG_EXIT("arlan_tx");
1204 static inline int DoNotReTransmitCrap(struct net_device
*dev
)
1206 struct arlan_private
*priv
= netdev_priv(dev
);
1208 if (TXLAST(dev
).length
< priv
->Conf
->ReTransmitPacketMaxSize
)
1214 static inline int DoNotWaitReTransmitCrap(struct net_device
*dev
)
1216 struct arlan_private
*priv
= netdev_priv(dev
);
1218 if (TXLAST(dev
).length
< priv
->Conf
->waitReTransmitPacketMaxSize
)
1223 static inline void arlan_queue_retransmit(struct net_device
*dev
)
1225 struct arlan_private
*priv
= netdev_priv(dev
);
1227 ARLAN_DEBUG_ENTRY("arlan_queue_retransmit");
1229 if (DoNotWaitReTransmitCrap(dev
))
1233 priv
->ReTransmitRequested
++;
1235 ARLAN_DEBUG_EXIT("arlan_queue_retransmit");
1238 static inline void RetryOrFail(struct net_device
*dev
)
1240 struct arlan_private
*priv
= netdev_priv(dev
);
1242 ARLAN_DEBUG_ENTRY("RetryOrFail");
1244 if (priv
->retransmissions
> priv
->Conf
->retries
||
1245 DoNotReTransmitCrap(dev
))
1249 else if (priv
->bad
<= priv
->Conf
->fastReTransCount
)
1251 arlan_retransmit_now(dev
);
1253 else arlan_queue_retransmit(dev
);
1255 ARLAN_DEBUG_EXIT("RetryOrFail");
1259 static void arlan_tx_done_interrupt(struct net_device
*dev
, int status
)
1261 struct arlan_private
*priv
= netdev_priv(dev
);
1263 ARLAN_DEBUG_ENTRY("arlan_tx_done_interrupt");
1265 priv
->tx_last_cleared
= jiffies
;
1266 priv
->tx_command_given
= 0;
1271 IFDEBUG(ARLAN_DEBUG_TX_CHAIN
)
1272 printk("arlan intr: transmit OK\n");
1273 priv
->stats
.tx_packets
++;
1276 priv
->retransmissions
= 0;
1277 if (priv
->Conf
->tx_delay_ms
)
1279 priv
->tx_done_delayed
= jiffies
+ (priv
->Conf
->tx_delay_ms
* HZ
) / 1000 + 1;
1283 TXLAST(dev
).offset
= 0;
1286 else if (TXTAIL(dev
).offset
)
1288 if (TXLAST(dev
).offset
)
1290 arlan_retransmit_now(dev
);
1291 dev
->trans_start
= jiffies
;
1293 if (!TXHEAD(dev
).offset
|| !TXTAIL(dev
).offset
)
1295 netif_wake_queue (dev
);
1303 IFDEBUG(ARLAN_DEBUG_TX_CHAIN
)
1304 printk("arlan intr: transmit timed out\n");
1306 //arlan_queue_retransmit(dev);
1313 IFDEBUG(ARLAN_DEBUG_TX_CHAIN
)
1314 printk("arlan intr: transmit max retries\n");
1317 //arlan_queue_retransmit(dev);
1324 IFDEBUG(ARLAN_DEBUG_TX_CHAIN
)
1325 printk("arlan intr: transmit aborted\n");
1327 arlan_queue_retransmit(dev
);
1334 IFDEBUG(ARLAN_DEBUG_TX_CHAIN
)
1335 printk("arlan intr: transmit not registered\n");
1338 arlan_queue_retransmit(dev
);
1344 IFDEBUG(ARLAN_DEBUG_TX_CHAIN
)
1345 printk("arlan intr: transmit destination full\n");
1348 //arlan_drop_tx(dev);
1349 arlan_queue_retransmit(dev
);
1355 IFDEBUG(ARLAN_DEBUG_TX_CHAIN
)
1356 printk("arlan intr: transmit unknown ack\n");
1359 arlan_queue_retransmit(dev
);
1365 IFDEBUG(ARLAN_DEBUG_TX_CHAIN
)
1366 printk("arlan intr: transmit dest mail box full\n");
1369 //arlan_drop_tx(dev);
1370 arlan_queue_retransmit(dev
);
1376 IFDEBUG(ARLAN_DEBUG_TX_CHAIN
)
1377 printk("arlan intr: transmit root dest not reg.\n");
1380 //arlan_drop_tx(dev);
1381 arlan_queue_retransmit(dev
);
1387 printk(KERN_ERR
"arlan intr: transmit status unknown\n");
1394 ARLAN_DEBUG_EXIT("arlan_tx_done_interrupt");
1398 static void arlan_rx_interrupt(struct net_device
*dev
, u_char rxStatus
, u_short rxOffset
, u_short pkt_len
)
1403 struct arlan_private
*priv
= netdev_priv(dev
);
1404 volatile struct arlan_shmem __iomem
*arlan
= priv
->card
;
1405 struct arlan_conf_stru
*conf
= priv
->Conf
;
1408 ARLAN_DEBUG_ENTRY("arlan_rx_interrupt");
1409 // by spec, not WRITESHMB(arlan->rxStatus,0x00);
1410 // prohibited here arlan_command(dev, ARLAN_COMMAND_RX);
1412 if (pkt_len
< 10 || pkt_len
> 2048)
1414 printk(KERN_WARNING
"%s: got too short or long packet, len %d \n", dev
->name
, pkt_len
);
1417 if (rxOffset
+ pkt_len
> 0x2000)
1419 printk("%s: got too long packet, len %d offset %x\n", dev
->name
, pkt_len
, rxOffset
);
1422 priv
->in_bytes
+= pkt_len
;
1423 priv
->in_bytes10
+= pkt_len
;
1424 if (conf
->measure_rate
< 1)
1425 conf
->measure_rate
= 1;
1426 if (time_after(jiffies
, priv
->in_time
+ conf
->measure_rate
* HZ
))
1428 conf
->in_speed
= priv
->in_bytes
/ conf
->measure_rate
;
1430 priv
->in_time
= jiffies
;
1432 if (time_after(jiffies
, priv
->in_time10
+ conf
->measure_rate
* 10*HZ
))
1434 conf
->in_speed10
= priv
->in_bytes10
/ (10 * conf
->measure_rate
);
1435 priv
->in_bytes10
= 0;
1436 priv
->in_time10
= jiffies
;
1438 DEBUGSHM(1, "arlan rcv pkt rxStatus= %d ", arlan
->rxStatus
, u_char
);
1445 /* Malloc up new buffer. */
1446 struct sk_buff
*skb
;
1448 DEBUGSHM(50, "arlan recv pkt offs=%d\n", arlan
->rxOffset
, u_short
);
1449 DEBUGSHM(1, "arlan rxFrmType = %d \n", arlan
->rxFrmType
, u_char
);
1450 DEBUGSHM(1, KERN_INFO
"arlan rx scrambled = %d \n", arlan
->scrambled
, u_char
);
1452 /* here we do multicast filtering to avoid slow 8-bit memcopy */
1453 #ifdef ARLAN_MULTICAST
1454 if (!(dev
->flags
& IFF_ALLMULTI
) &&
1455 !(dev
->flags
& IFF_PROMISC
) &&
1458 char hw_dst_addr
[6];
1459 struct dev_mc_list
*dmi
= dev
->mc_list
;
1462 memcpy_fromio(hw_dst_addr
, arlan
->ultimateDestAddress
, 6);
1463 if (hw_dst_addr
[0] == 0x01)
1466 if (hw_dst_addr
[1] == 0x00)
1467 printk(KERN_ERR
"%s mcast 0x0100 \n", dev
->name
);
1468 else if (hw_dst_addr
[1] == 0x40)
1469 printk(KERN_ERR
"%s m/bcast 0x0140 \n", dev
->name
);
1471 { if (dmi
->dmi_addrlen
== 6)
1473 if (arlan_debug
& ARLAN_DEBUG_HEADER_DUMP
)
1474 printk(KERN_ERR
"%s mcl %2x:%2x:%2x:%2x:%2x:%2x \n", dev
->name
,
1475 dmi
->dmi_addr
[0], dmi
->dmi_addr
[1], dmi
->dmi_addr
[2],
1476 dmi
->dmi_addr
[3], dmi
->dmi_addr
[4], dmi
->dmi_addr
[5]);
1477 for (i
= 0; i
< 6; i
++)
1478 if (dmi
->dmi_addr
[i
] != hw_dst_addr
[i
])
1484 printk(KERN_ERR
"%s: invalid multicast address length given.\n", dev
->name
);
1487 /* we reach here if multicast filtering is on and packet
1488 * is multicast and not for receive */
1489 goto end_of_interrupt
;
1492 #endif // ARLAN_MULTICAST
1493 /* multicast filtering ends here */
1494 pkt_len
+= ARLAN_FAKE_HDR_LEN
;
1496 skb
= dev_alloc_skb(pkt_len
+ 4);
1499 printk(KERN_ERR
"%s: Memory squeeze, dropping packet.\n", dev
->name
);
1500 priv
->stats
.rx_dropped
++;
1503 skb_reserve(skb
, 2);
1505 skbtmp
= skb_put(skb
, pkt_len
);
1507 memcpy_fromio(skbtmp
+ ARLAN_FAKE_HDR_LEN
, ((char __iomem
*) arlan
) + rxOffset
, pkt_len
- ARLAN_FAKE_HDR_LEN
);
1508 memcpy_fromio(skbtmp
, arlan
->ultimateDestAddress
, 6);
1509 memcpy_fromio(skbtmp
+ 6, arlan
->rxSrc
, 6);
1510 WRITESHMB(arlan
->rxStatus
, 0x00);
1511 arlan_command(dev
, ARLAN_COMMAND_RX
);
1513 IFDEBUG(ARLAN_DEBUG_HEADER_DUMP
)
1515 char immedDestAddress
[6];
1516 char immedSrcAddress
[6];
1517 memcpy_fromio(immedDestAddress
, arlan
->immedDestAddress
, 6);
1518 memcpy_fromio(immedSrcAddress
, arlan
->immedSrcAddress
, 6);
1520 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
,
1521 (unsigned char) skbtmp
[0], (unsigned char) skbtmp
[1], (unsigned char) skbtmp
[2], (unsigned char) skbtmp
[3],
1522 (unsigned char) skbtmp
[4], (unsigned char) skbtmp
[5], (unsigned char) skbtmp
[6], (unsigned char) skbtmp
[7],
1523 (unsigned char) skbtmp
[8], (unsigned char) skbtmp
[9], (unsigned char) skbtmp
[10], (unsigned char) skbtmp
[11],
1524 immedDestAddress
[0], immedDestAddress
[1], immedDestAddress
[2],
1525 immedDestAddress
[3], immedDestAddress
[4], immedDestAddress
[5],
1526 immedSrcAddress
[0], immedSrcAddress
[1], immedSrcAddress
[2],
1527 immedSrcAddress
[3], immedSrcAddress
[4], immedSrcAddress
[5]);
1529 skb
->protocol
= eth_type_trans(skb
, dev
);
1530 IFDEBUG(ARLAN_DEBUG_HEADER_DUMP
)
1531 if (skb
->protocol
!= 0x608 && skb
->protocol
!= 0x8)
1533 for (i
= 0; i
<= 22; i
++)
1534 printk("%02x:", (u_char
) skbtmp
[i
+ 12]);
1535 printk(KERN_ERR
"\n");
1536 printk(KERN_WARNING
"arlan kernel pkt type trans %x \n", skb
->protocol
);
1539 dev
->last_rx
= jiffies
;
1540 priv
->stats
.rx_packets
++;
1541 priv
->stats
.rx_bytes
+= pkt_len
;
1546 printk(KERN_ERR
"arlan intr: received unknown status\n");
1547 priv
->stats
.rx_crc_errors
++;
1550 ARLAN_DEBUG_EXIT("arlan_rx_interrupt");
1553 static void arlan_process_interrupt(struct net_device
*dev
)
1555 struct arlan_private
*priv
= netdev_priv(dev
);
1556 volatile struct arlan_shmem __iomem
*arlan
= priv
->card
;
1557 u_char rxStatus
= READSHMB(arlan
->rxStatus
);
1558 u_char txStatus
= READSHMB(arlan
->txStatus
);
1559 u_short rxOffset
= READSHMS(arlan
->rxOffset
);
1560 u_short pkt_len
= READSHMS(arlan
->rxLength
);
1561 int interrupt_count
= 0;
1563 ARLAN_DEBUG_ENTRY("arlan_process_interrupt");
1565 if (test_and_set_bit(0, (void *) &priv
->interrupt_processing_active
))
1567 if (arlan_debug
& ARLAN_DEBUG_CHAIN_LOCKS
)
1568 printk(KERN_ERR
"interrupt chain reentering \n");
1569 goto end_int_process
;
1571 while ((rxStatus
|| txStatus
|| priv
->interrupt_ack_requested
)
1572 && (interrupt_count
< 5))
1575 priv
->last_rx_int_ack_time
= jiffies
;
1577 arlan_command(dev
, ARLAN_COMMAND_INT_ACK
);
1578 arlan_command(dev
, ARLAN_COMMAND_INT_ENABLE
);
1580 IFDEBUG(ARLAN_DEBUG_INTERRUPT
)
1581 printk(KERN_ERR
"%s: got IRQ rx %x tx %x comm %x rxOff %x rxLen %x \n",
1582 dev
->name
, rxStatus
, txStatus
, READSHMB(arlan
->commandByte
),
1585 if (rxStatus
== 0 && txStatus
== 0)
1587 if (priv
->irq_test_done
)
1589 if (!registrationBad(dev
))
1590 IFDEBUG(ARLAN_DEBUG_INTERRUPT
) printk(KERN_ERR
"%s unknown interrupt(nop? regLost ?) reason tx %d rx %d ",
1591 dev
->name
, txStatus
, rxStatus
);
1593 IFDEBUG(ARLAN_DEBUG_INTERRUPT
)
1594 printk(KERN_INFO
"%s irq $%d test OK \n", dev
->name
, dev
->irq
);
1597 priv
->interrupt_ack_requested
= 0;
1602 WRITESHMB(arlan
->txStatus
, 0x00);
1603 arlan_tx_done_interrupt(dev
, txStatus
);
1606 if (rxStatus
== 1 || rxStatus
== 2)
1607 { /* a packet waiting */
1608 arlan_rx_interrupt(dev
, rxStatus
, rxOffset
, pkt_len
);
1611 if (rxStatus
> 2 && rxStatus
< 0xff)
1613 WRITESHMB(arlan
->rxStatus
, 0x00);
1614 printk(KERN_ERR
"%s unknown rxStatus reason tx %d rx %d ",
1615 dev
->name
, txStatus
, rxStatus
);
1618 if (rxStatus
== 0xff)
1620 WRITESHMB(arlan
->rxStatus
, 0x00);
1621 arlan_command(dev
, ARLAN_COMMAND_RX
);
1622 if (registrationBad(dev
))
1623 netif_device_detach(dev
);
1624 if (!registrationBad(dev
))
1626 priv
->registrationLastSeen
= jiffies
;
1627 if (!netif_queue_stopped(dev
) && !priv
->under_reset
&& !priv
->under_config
)
1628 netif_wake_queue (dev
);
1634 arlan_command_process(dev
);
1636 rxStatus
= READSHMB(arlan
->rxStatus
);
1637 txStatus
= READSHMB(arlan
->txStatus
);
1638 rxOffset
= READSHMS(arlan
->rxOffset
);
1639 pkt_len
= READSHMS(arlan
->rxLength
);
1642 priv
->irq_test_done
= 1;
1646 priv
->interrupt_processing_active
= 0;
1649 arlan_command_process(dev
);
1651 ARLAN_DEBUG_EXIT("arlan_process_interrupt");
1655 static irqreturn_t
arlan_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
1657 struct net_device
*dev
= dev_id
;
1658 struct arlan_private
*priv
= netdev_priv(dev
);
1659 volatile struct arlan_shmem __iomem
*arlan
= priv
->card
;
1660 u_char rxStatus
= READSHMB(arlan
->rxStatus
);
1661 u_char txStatus
= READSHMB(arlan
->txStatus
);
1663 ARLAN_DEBUG_ENTRY("arlan_interrupt");
1666 if (!rxStatus
&& !txStatus
)
1667 priv
->interrupt_ack_requested
++;
1669 arlan_process_interrupt(dev
);
1671 priv
->irq_test_done
= 1;
1673 ARLAN_DEBUG_EXIT("arlan_interrupt");
1679 static int arlan_close(struct net_device
*dev
)
1681 struct arlan_private
*priv
= netdev_priv(dev
);
1683 ARLAN_DEBUG_ENTRY("arlan_close");
1685 del_timer_sync(&priv
->timer
);
1687 arlan_command(dev
, ARLAN_COMMAND_POWERDOWN
);
1689 IFDEBUG(ARLAN_DEBUG_STARTUP
)
1690 printk(KERN_NOTICE
"%s: Closing device\n", dev
->name
);
1692 netif_stop_queue(dev
);
1693 free_irq(dev
->irq
, dev
);
1695 ARLAN_DEBUG_EXIT("arlan_close");
1699 #ifdef ARLAN_DEBUGGING
1700 static long alignLong(volatile u_char
* ptr
)
1703 memcpy_fromio(&ret
, (void *) ptr
, 4);
1709 * Get the current statistics.
1710 * This may be called with the card open or closed.
1713 static struct net_device_stats
*arlan_statistics(struct net_device
*dev
)
1715 struct arlan_private
*priv
= netdev_priv(dev
);
1716 volatile struct arlan_shmem __iomem
*arlan
= priv
->card
;
1719 ARLAN_DEBUG_ENTRY("arlan_statistics");
1721 /* Update the statistics from the device registers. */
1723 READSHM(priv
->stats
.collisions
, arlan
->numReTransmissions
, u_int
);
1724 READSHM(priv
->stats
.rx_crc_errors
, arlan
->numCRCErrors
, u_int
);
1725 READSHM(priv
->stats
.rx_dropped
, arlan
->numFramesDiscarded
, u_int
);
1726 READSHM(priv
->stats
.rx_fifo_errors
, arlan
->numRXBufferOverflows
, u_int
);
1727 READSHM(priv
->stats
.rx_frame_errors
, arlan
->numReceiveFramesLost
, u_int
);
1728 READSHM(priv
->stats
.rx_over_errors
, arlan
->numRXOverruns
, u_int
);
1729 READSHM(priv
->stats
.rx_packets
, arlan
->numDatagramsReceived
, u_int
);
1730 READSHM(priv
->stats
.tx_aborted_errors
, arlan
->numAbortErrors
, u_int
);
1731 READSHM(priv
->stats
.tx_carrier_errors
, arlan
->numStatusTimeouts
, u_int
);
1732 READSHM(priv
->stats
.tx_dropped
, arlan
->numDatagramsDiscarded
, u_int
);
1733 READSHM(priv
->stats
.tx_fifo_errors
, arlan
->numTXUnderruns
, u_int
);
1734 READSHM(priv
->stats
.tx_packets
, arlan
->numDatagramsTransmitted
, u_int
);
1735 READSHM(priv
->stats
.tx_window_errors
, arlan
->numHoldOffs
, u_int
);
1737 ARLAN_DEBUG_EXIT("arlan_statistics");
1739 return &priv
->stats
;
1743 static void arlan_set_multicast(struct net_device
*dev
)
1745 struct arlan_private
*priv
= netdev_priv(dev
);
1746 volatile struct arlan_shmem __iomem
*arlan
= priv
->card
;
1747 struct arlan_conf_stru
*conf
= priv
->Conf
;
1748 int board_conf_needed
= 0;
1751 ARLAN_DEBUG_ENTRY("arlan_set_multicast");
1753 if (dev
->flags
& IFF_PROMISC
)
1755 unsigned char recMode
;
1756 READSHM(recMode
, arlan
->receiveMode
, u_char
);
1757 conf
->receiveMode
= (ARLAN_RCV_PROMISC
| ARLAN_RCV_CONTROL
);
1758 if (conf
->receiveMode
!= recMode
)
1759 board_conf_needed
= 1;
1763 /* turn off promiscuous mode */
1764 unsigned char recMode
;
1765 READSHM(recMode
, arlan
->receiveMode
, u_char
);
1766 conf
->receiveMode
= ARLAN_RCV_CLEAN
| ARLAN_RCV_CONTROL
;
1767 if (conf
->receiveMode
!= recMode
)
1768 board_conf_needed
= 1;
1770 if (board_conf_needed
)
1771 arlan_command(dev
, ARLAN_COMMAND_CONF
);
1773 ARLAN_DEBUG_EXIT("arlan_set_multicast");
1777 struct net_device
* __init
arlan_probe(int unit
)
1779 struct net_device
*dev
;
1783 ARLAN_DEBUG_ENTRY("arlan_probe");
1785 if (arlans_found
== MAX_ARLANS
)
1786 return ERR_PTR(-ENODEV
);
1789 * Reserve space for local data and a copy of the shared memory
1790 * that is used by the /proc interface.
1792 dev
= alloc_etherdev(sizeof(struct arlan_private
)
1793 + sizeof(struct arlan_shmem
));
1795 return ERR_PTR(-ENOMEM
);
1797 SET_MODULE_OWNER(dev
);
1800 sprintf(dev
->name
, "eth%d", unit
);
1801 netdev_boot_setup_check(dev
);
1803 if (dev
->mem_start
) {
1804 if (arlan_probe_here(dev
, dev
->mem_start
) == 0)
1812 for (m
= (int)phys_to_virt(lastFoundAt
) + ARLAN_SHMEM_SIZE
;
1813 m
<= (int)phys_to_virt(0xDE000);
1814 m
+= ARLAN_SHMEM_SIZE
)
1816 if (arlan_probe_here(dev
, m
) == 0)
1818 lastFoundAt
= (int)virt_to_phys((void*)m
);
1823 if (lastFoundAt
== 0xbe000)
1824 printk(KERN_ERR
"arlan: No Arlan devices found \n");
1828 return ERR_PTR(-ENODEV
);
1831 err
= arlan_setup_device(dev
, arlans_found
);
1834 else if (!arlans_found
++)
1835 printk(KERN_INFO
"Arlan driver %s\n", arlan_version
);
1841 int init_module(void)
1845 ARLAN_DEBUG_ENTRY("init_module");
1847 if (channelSet
!= channelSetUNKNOWN
|| channelNumber
!= channelNumberUNKNOWN
|| systemId
!= systemIdUNKNOWN
)
1850 for (i
= 0; i
< MAX_ARLANS
; i
++) {
1851 struct net_device
*dev
= arlan_probe(i
);
1854 return PTR_ERR(dev
);
1857 printk(KERN_INFO
"Arlan driver %s\n", arlan_version
);
1858 ARLAN_DEBUG_EXIT("init_module");
1863 void cleanup_module(void)
1866 struct net_device
*dev
;
1868 ARLAN_DEBUG_ENTRY("cleanup_module");
1870 IFDEBUG(ARLAN_DEBUG_SHUTDOWN
)
1871 printk(KERN_INFO
"arlan: unloading module\n");
1873 cleanup_arlan_proc();
1875 for (i
= 0; i
< MAX_ARLANS
; i
++)
1877 dev
= arlan_device
[i
];
1879 arlan_command(dev
, ARLAN_COMMAND_POWERDOWN
);
1881 unregister_netdev(dev
);
1882 release_mem_region(virt_to_phys((void *) dev
->mem_start
),
1885 arlan_device
[i
] = NULL
;
1889 ARLAN_DEBUG_EXIT("cleanup_module");
1894 MODULE_LICENSE("GPL");