aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/arlan-main.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /drivers/net/wireless/arlan-main.c
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'drivers/net/wireless/arlan-main.c')
-rw-r--r--drivers/net/wireless/arlan-main.c1896
1 files changed, 1896 insertions, 0 deletions
diff --git a/drivers/net/wireless/arlan-main.c b/drivers/net/wireless/arlan-main.c
new file mode 100644
index 000000000000..4f304c6e693a
--- /dev/null
+++ b/drivers/net/wireless/arlan-main.c
@@ -0,0 +1,1896 @@
1/*
2 * Copyright (C) 1997 Cullen Jennings
3 * Copyright (C) 1998 Elmer Joandiu, elmer@ylenurme.ee
4 * GNU General Public License applies
5 * This module provides support for the Arlan 655 card made by Aironet
6 */
7
8#include <linux/config.h>
9#include "arlan.h"
10
11#if BITS_PER_LONG != 32
12# error FIXME: this driver requires a 32-bit platform
13#endif
14
15static const char *arlan_version = "C.Jennigs 97 & Elmer.Joandi@ut.ee Oct'98, http://www.ylenurme.ee/~elmer/655/";
16
17struct net_device *arlan_device[MAX_ARLANS];
18
19static int SID = SIDUNKNOWN;
20static int radioNodeId = radioNodeIdUNKNOWN;
21static char encryptionKey[12] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'};
22int arlan_debug = debugUNKNOWN;
23static int spreadingCode = spreadingCodeUNKNOWN;
24static int channelNumber = channelNumberUNKNOWN;
25static int channelSet = channelSetUNKNOWN;
26static int systemId = systemIdUNKNOWN;
27static int registrationMode = registrationModeUNKNOWN;
28static int keyStart;
29static int tx_delay_ms;
30static int retries = 5;
31static int tx_queue_len = 1;
32static int arlan_EEPROM_bad;
33
34#ifdef ARLAN_DEBUGGING
35
36static int arlan_entry_debug;
37static int arlan_exit_debug;
38static int testMemory = testMemoryUNKNOWN;
39static int irq = irqUNKNOWN;
40static int txScrambled = 1;
41static int mdebug;
42
43module_param(irq, int, 0);
44module_param(mdebug, int, 0);
45module_param(testMemory, int, 0);
46module_param(arlan_entry_debug, int, 0);
47module_param(arlan_exit_debug, int, 0);
48module_param(txScrambled, int, 0);
49MODULE_PARM_DESC(irq, "(unused)");
50MODULE_PARM_DESC(testMemory, "(unused)");
51MODULE_PARM_DESC(mdebug, "Arlan multicast debugging (0-1)");
52#endif
53
54module_param(arlan_debug, int, 0);
55module_param(spreadingCode, int, 0);
56module_param(channelNumber, int, 0);
57module_param(channelSet, int, 0);
58module_param(systemId, int, 0);
59module_param(registrationMode, int, 0);
60module_param(radioNodeId, int, 0);
61module_param(SID, int, 0);
62module_param(keyStart, int, 0);
63module_param(tx_delay_ms, int, 0);
64module_param(retries, int, 0);
65module_param(tx_queue_len, int, 0);
66module_param(arlan_EEPROM_bad, int, 0);
67MODULE_PARM_DESC(arlan_debug, "Arlan debug enable (0-1)");
68MODULE_PARM_DESC(retries, "Arlan maximum packet retransmisions");
69#ifdef ARLAN_ENTRY_EXIT_DEBUGGING
70MODULE_PARM_DESC(arlan_entry_debug, "Arlan driver function entry debugging");
71MODULE_PARM_DESC(arlan_exit_debug, "Arlan driver function exit debugging");
72MODULE_PARM_DESC(arlan_entry_and_exit_debug, "Arlan driver function entry and exit debugging");
73#else
74MODULE_PARM_DESC(arlan_entry_debug, "(ignored)");
75MODULE_PARM_DESC(arlan_exit_debug, "(ignored)");
76MODULE_PARM_DESC(arlan_entry_and_exit_debug, "(ignored)");
77#endif
78
79struct arlan_conf_stru arlan_conf[MAX_ARLANS];
80static int arlans_found;
81
82static int arlan_open(struct net_device *dev);
83static int arlan_tx(struct sk_buff *skb, struct net_device *dev);
84static irqreturn_t arlan_interrupt(int irq, void *dev_id, struct pt_regs *regs);
85static int arlan_close(struct net_device *dev);
86static struct net_device_stats *
87 arlan_statistics (struct net_device *dev);
88static void arlan_set_multicast (struct net_device *dev);
89static int arlan_hw_tx (struct net_device* dev, char *buf, int length );
90static int arlan_hw_config (struct net_device * dev);
91static void arlan_tx_done_interrupt (struct net_device * dev, int status);
92static void arlan_rx_interrupt (struct net_device * dev, u_char rxStatus, u_short, u_short);
93static void arlan_process_interrupt (struct net_device * dev);
94static void arlan_tx_timeout (struct net_device *dev);
95
96static inline long us2ticks(int us)
97{
98 return us * (1000000 / HZ);
99}
100
101
102#ifdef ARLAN_ENTRY_EXIT_DEBUGGING
103#define ARLAN_DEBUG_ENTRY(name) \
104 {\
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));\
109 }
110#define ARLAN_DEBUG_EXIT(name) \
111 {\
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) );\
116 }
117#else
118#define ARLAN_DEBUG_ENTRY(name)
119#define ARLAN_DEBUG_EXIT(name)
120#endif
121
122
123#define arlan_interrupt_ack(dev)\
124 clearClearInterrupt(dev);\
125 setClearInterrupt(dev);
126
127static inline int arlan_drop_tx(struct net_device *dev)
128{
129 struct arlan_private *priv = netdev_priv(dev);
130
131 priv->stats.tx_errors++;
132 if (priv->Conf->tx_delay_ms)
133 {
134 priv->tx_done_delayed = jiffies + priv->Conf->tx_delay_ms * HZ / 1000 + 1;
135 }
136 else
137 {
138 priv->waiting_command_mask &= ~ARLAN_COMMAND_TX;
139 TXHEAD(dev).offset = 0;
140 TXTAIL(dev).offset = 0;
141 priv->txLast = 0;
142 priv->bad = 0;
143 if (!priv->under_reset && !priv->under_config)
144 netif_wake_queue (dev);
145 }
146 return 1;
147}
148
149
150int arlan_command(struct net_device *dev, int command_p)
151{
152 struct arlan_private *priv = netdev_priv(dev);
153 volatile struct arlan_shmem __iomem *arlan = priv->card;
154 struct arlan_conf_stru *conf = priv->Conf;
155 int udelayed = 0;
156 int i = 0;
157 unsigned long flags;
158
159 ARLAN_DEBUG_ENTRY("arlan_command");
160
161 if (priv->card_polling_interval)
162 priv->card_polling_interval = 1;
163
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);
168
169 priv->waiting_command_mask |= command_p;
170
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;
174
175 if (priv->waiting_command_mask & ARLAN_COMMAND_INT_ACK)
176 {
177 arlan_interrupt_ack(dev);
178 priv->waiting_command_mask &= ~ARLAN_COMMAND_INT_ACK;
179 }
180 if (priv->waiting_command_mask & ARLAN_COMMAND_INT_ENABLE)
181 {
182 setInterruptEnable(dev);
183 priv->waiting_command_mask &= ~ARLAN_COMMAND_INT_ENABLE;
184 }
185
186 /* Card access serializing lock */
187 spin_lock_irqsave(&priv->lock, flags);
188
189 /* Check cards status and waiting */
190
191 if (priv->waiting_command_mask & (ARLAN_COMMAND_LONG_WAIT_NOW | ARLAN_COMMAND_WAIT_NOW))
192 {
193 while (priv->waiting_command_mask & (ARLAN_COMMAND_LONG_WAIT_NOW | ARLAN_COMMAND_WAIT_NOW))
194 {
195 if (READSHMB(arlan->resetFlag) ||
196 READSHMB(arlan->commandByte)) /* ||
197 (readControlRegister(dev) & ARLAN_ACCESS))
198 */
199 udelay(40);
200 else
201 priv->waiting_command_mask &= ~(ARLAN_COMMAND_LONG_WAIT_NOW | ARLAN_COMMAND_WAIT_NOW);
202
203 udelayed++;
204
205 if (priv->waiting_command_mask & ARLAN_COMMAND_LONG_WAIT_NOW)
206 {
207 if (udelayed * 40 > 1000000)
208 {
209 printk(KERN_ERR "%s long wait too long \n", dev->name);
210 priv->waiting_command_mask |= ARLAN_COMMAND_RESET;
211 break;
212 }
213 }
214 else if (priv->waiting_command_mask & ARLAN_COMMAND_WAIT_NOW)
215 {
216 if (udelayed * 40 > 1000)
217 {
218 printk(KERN_ERR "%s short wait too long \n", dev->name);
219 goto bad_end;
220 }
221 }
222 }
223 }
224 else
225 {
226 i = 0;
227 while ((READSHMB(arlan->resetFlag) ||
228 READSHMB(arlan->commandByte)) &&
229 conf->pre_Command_Wait > (i++) * 10)
230 udelay(10);
231
232
233 if ((READSHMB(arlan->resetFlag) ||
234 READSHMB(arlan->commandByte)) &&
235 !(priv->waiting_command_mask & ARLAN_COMMAND_RESET))
236 {
237 goto card_busy_end;
238 }
239 }
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;
244
245 /* Issuing command */
246 arlan_lock_card_access(dev);
247 if (priv->waiting_command_mask & ARLAN_COMMAND_POWERUP)
248 {
249 // if (readControlRegister(dev) & (ARLAN_ACCESS && ARLAN_POWER))
250 setPowerOn(dev);
251 arlan_interrupt_lancpu(dev);
252 priv->waiting_command_mask &= ~ARLAN_COMMAND_POWERUP;
253 priv->waiting_command_mask |= ARLAN_COMMAND_RESET;
254 priv->card_polling_interval = HZ / 10;
255 }
256 else if (priv->waiting_command_mask & ARLAN_COMMAND_ACTIVATE)
257 {
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;
262 }
263 else if (priv->waiting_command_mask & ARLAN_COMMAND_RX_ABORT)
264 {
265 if (priv->rx_command_given)
266 {
267 WRITESHMB(arlan->commandByte, ARLAN_COM_RX_ABORT);
268 arlan_interrupt_lancpu(dev);
269 priv->rx_command_given = 0;
270 }
271 priv->waiting_command_mask &= ~ARLAN_COMMAND_RX_ABORT;
272 priv->card_polling_interval = 1;
273 }
274 else if (priv->waiting_command_mask & ARLAN_COMMAND_TX_ABORT)
275 {
276 if (priv->tx_command_given)
277 {
278 WRITESHMB(arlan->commandByte, ARLAN_COM_TX_ABORT);
279 arlan_interrupt_lancpu(dev);
280 priv->tx_command_given = 0;
281 }
282 priv->waiting_command_mask &= ~ARLAN_COMMAND_TX_ABORT;
283 priv->card_polling_interval = 1;
284 }
285 else if (priv->waiting_command_mask & ARLAN_COMMAND_RESET)
286 {
287 priv->under_reset=1;
288 netif_stop_queue (dev);
289
290 arlan_drop_tx(dev);
291 if (priv->tx_command_given || priv->rx_command_given)
292 {
293 printk(KERN_ERR "%s: Reset under tx or rx command \n", dev->name);
294 }
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;
311 }
312 else if (priv->waiting_command_mask & ARLAN_COMMAND_INT_RACK)
313 {
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;
322 }
323 else if (priv->waiting_command_mask & ARLAN_COMMAND_INT_RENABLE)
324 {
325 setInterruptEnable(dev);
326 priv->waiting_command_mask &= ~ARLAN_COMMAND_INT_RENABLE;
327 }
328 else if (priv->waiting_command_mask & ARLAN_COMMAND_CONF)
329 {
330 if (priv->tx_command_given || priv->rx_command_given)
331 {
332 printk(KERN_ERR "%s: Reset under tx or rx command \n", dev->name);
333 }
334 arlan_drop_tx(dev);
335 setInterruptEnable(dev);
336 arlan_hw_config(dev);
337 arlan_interrupt_lancpu(dev);
338 priv->waiting_command_mask &= ~ARLAN_COMMAND_CONF;
339 priv->card_polling_interval = HZ / 10;
340// priv->waiting_command_mask |= ARLAN_COMMAND_INT_RACK;
341// priv->waiting_command_mask |= ARLAN_COMMAND_INT_ENABLE;
342 priv->waiting_command_mask |= ARLAN_COMMAND_CONF_WAIT;
343 }
344 else if (priv->waiting_command_mask & ARLAN_COMMAND_CONF_WAIT)
345 {
346 if (READSHMB(arlan->configuredStatusFlag) != 0 &&
347 READSHMB(arlan->diagnosticInfo) == 0xff)
348 {
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;
355 }
356 else
357 {
358 priv->card_polling_interval = 1;
359 if (arlan_debug & ARLAN_DEBUG_TIMING)
360 printk(KERN_ERR "configure delayed \n");
361 }
362 }
363 else if (priv->waiting_command_mask & ARLAN_COMMAND_RX)
364 {
365 if (!registrationBad(dev))
366 {
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;
375 }
376 else
377 priv->card_polling_interval = 2;
378 }
379 else if (priv->waiting_command_mask & ARLAN_COMMAND_TBUSY_CLEAR)
380 {
381 if ( !registrationBad(dev) &&
382 (netif_queue_stopped(dev) || !netif_running(dev)) )
383 {
384 priv->waiting_command_mask &= ~ARLAN_COMMAND_TBUSY_CLEAR;
385 netif_wake_queue (dev);
386 }
387 }
388 else if (priv->waiting_command_mask & ARLAN_COMMAND_TX)
389 {
390 if (!test_and_set_bit(0, (void *) &priv->tx_command_given))
391 {
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)))
396 {
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;
407 }
408 else
409 {
410 priv->tx_command_given = 0;
411 priv->card_polling_interval = 1;
412 }
413 }
414 else if (arlan_debug & ARLAN_DEBUG_CHAIN_LOCKS)
415 printk(KERN_ERR "tx command when tx chain locked \n");
416 }
417 else if (priv->waiting_command_mask & ARLAN_COMMAND_NOOPINT)
418 {
419 {
420 WRITESHMB(arlan->commandByte, ARLAN_COM_NOP | ARLAN_COM_INT);
421 }
422 arlan_interrupt_lancpu(dev);
423 priv->waiting_command_mask &= ~ARLAN_COMMAND_NOOPINT;
424 priv->card_polling_interval = HZ / 3;
425 }
426 else if (priv->waiting_command_mask & ARLAN_COMMAND_NOOP)
427 {
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;
432 }
433 else if (priv->waiting_command_mask & ARLAN_COMMAND_SLOW_POLL)
434 {
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;
439 }
440 else if (priv->waiting_command_mask & ARLAN_COMMAND_POWERDOWN)
441 {
442 setPowerOff(dev);
443 if (arlan_debug & ARLAN_DEBUG_CARD_STATE)
444 printk(KERN_WARNING "%s: Arlan Going Standby\n", dev->name);
445 priv->waiting_command_mask &= ~ARLAN_COMMAND_POWERDOWN;
446 priv->card_polling_interval = 3 * HZ;
447 }
448 arlan_unlock_card_access(dev);
449 for (i = 0; READSHMB(arlan->commandByte) && i < 20; i++)
450 udelay(10);
451 if (READSHMB(arlan->commandByte))
452 if (arlan_debug & ARLAN_DEBUG_CARD_STATE)
453 printk(KERN_ERR "card busy leaving command %lx\n", priv->waiting_command_mask);
454
455 spin_unlock_irqrestore(&priv->lock, flags);
456 ARLAN_DEBUG_EXIT("arlan_command");
457 priv->last_command_buff_free_time = jiffies;
458 return 0;
459
460card_busy_end:
461 if (time_after(jiffies, priv->last_command_buff_free_time + HZ))
462 priv->waiting_command_mask |= ARLAN_COMMAND_CLEAN_AND_RESET;
463
464 if (arlan_debug & ARLAN_DEBUG_CARD_STATE)
465 printk(KERN_ERR "%s arlan_command card busy end \n", dev->name);
466 spin_unlock_irqrestore(&priv->lock, flags);
467 ARLAN_DEBUG_EXIT("arlan_command");
468 return 1;
469
470bad_end:
471 printk(KERN_ERR "%s arlan_command bad end \n", dev->name);
472
473 spin_unlock_irqrestore(&priv->lock, flags);
474 ARLAN_DEBUG_EXIT("arlan_command");
475
476 return -1;
477}
478
479static inline void arlan_command_process(struct net_device *dev)
480{
481 struct arlan_private *priv = netdev_priv(dev);
482
483 int times = 0;
484 while (priv->waiting_command_mask && times < 8)
485 {
486 if (priv->waiting_command_mask)
487 {
488 if (arlan_command(dev, 0))
489 break;
490 times++;
491 }
492 /* if long command, we won't repeat trying */ ;
493 if (priv->card_polling_interval > 1)
494 break;
495 times++;
496 }
497}
498
499
500static inline void arlan_retransmit_now(struct net_device *dev)
501{
502 struct arlan_private *priv = netdev_priv(dev);
503
504
505 ARLAN_DEBUG_ENTRY("arlan_retransmit_now");
506 if (TXLAST(dev).offset == 0)
507 {
508 if (TXHEAD(dev).offset)
509 {
510 priv->txLast = 0;
511 IFDEBUG(ARLAN_DEBUG_TX_CHAIN) printk(KERN_DEBUG "TX buff switch to head \n");
512
513 }
514 else if (TXTAIL(dev).offset)
515 {
516 IFDEBUG(ARLAN_DEBUG_TX_CHAIN) printk(KERN_DEBUG "TX buff switch to tail \n");
517 priv->txLast = 1;
518 }
519 else
520 IFDEBUG(ARLAN_DEBUG_TX_CHAIN) printk(KERN_ERR "ReTransmit buff empty");
521 netif_wake_queue (dev);
522 return;
523
524 }
525 arlan_command(dev, ARLAN_COMMAND_TX);
526
527 priv->Conf->driverRetransmissions++;
528 priv->retransmissions++;
529
530 IFDEBUG(ARLAN_DEBUG_TX_CHAIN) printk("Retransmit %d bytes \n", TXLAST(dev).length);
531
532 ARLAN_DEBUG_EXIT("arlan_retransmit_now");
533}
534
535
536
537static void arlan_registration_timer(unsigned long data)
538{
539 struct net_device *dev = (struct net_device *) data;
540 struct arlan_private *priv = netdev_priv(dev);
541 int bh_mark_needed = 0;
542 int next_tick = 1;
543 long lostTime = ((long)jiffies - (long)priv->registrationLastSeen)
544 * (1000/HZ);
545
546 if (registrationBad(dev))
547 {
548 priv->registrationLostCount++;
549 if (lostTime > 7000 && lostTime < 7200)
550 {
551 printk(KERN_NOTICE "%s registration Lost \n", dev->name);
552 }
553 if (lostTime / priv->reRegisterExp > 2000)
554 arlan_command(dev, ARLAN_COMMAND_CLEAN_AND_CONF);
555 if (lostTime / (priv->reRegisterExp) > 3500)
556 arlan_command(dev, ARLAN_COMMAND_CLEAN_AND_RESET);
557 if (priv->reRegisterExp < 400)
558 priv->reRegisterExp += 2;
559 if (lostTime > 7200)
560 {
561 next_tick = HZ;
562 arlan_command(dev, ARLAN_COMMAND_CLEAN_AND_RESET);
563 }
564 }
565 else
566 {
567 if (priv->Conf->registrationMode && lostTime > 10000 &&
568 priv->registrationLostCount)
569 {
570 printk(KERN_NOTICE "%s registration is back after %ld milliseconds\n",
571 dev->name, lostTime);
572 }
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;
582 }
583 }
584
585
586 if (!registrationBad(dev) && priv->ReTransmitRequested)
587 {
588 IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
589 printk(KERN_ERR "Retransmit from timer \n");
590 priv->ReTransmitRequested = 0;
591 arlan_retransmit_now(dev);
592 }
593 if (!registrationBad(dev) &&
594 time_after(jiffies, priv->tx_done_delayed) &&
595 priv->tx_done_delayed != 0)
596 {
597 TXLAST(dev).offset = 0;
598 if (priv->txLast)
599 priv->txLast = 0;
600 else if (TXTAIL(dev).offset)
601 priv->txLast = 1;
602 if (TXLAST(dev).offset)
603 {
604 arlan_retransmit_now(dev);
605 dev->trans_start = jiffies;
606 }
607 if (!(TXHEAD(dev).offset && TXTAIL(dev).offset))
608 {
609 netif_wake_queue (dev);
610 }
611 priv->tx_done_delayed = 0;
612 bh_mark_needed = 1;
613 }
614 if (bh_mark_needed)
615 {
616 netif_wake_queue (dev);
617 }
618 arlan_process_interrupt(dev);
619
620 if (next_tick < priv->card_polling_interval)
621 next_tick = priv->card_polling_interval;
622
623 priv->timer.expires = jiffies + next_tick;
624
625 add_timer(&priv->timer);
626}
627
628
629#ifdef ARLAN_DEBUGGING
630
631static void arlan_print_registers(struct net_device *dev, int line)
632{
633 struct arlan_private *priv = netdev_priv(dev);
634 volatile struct arlan_shmem *arlan = priv->card;
635
636 u_char hostcpuLock, lancpuLock, controlRegister, cntrlRegImage,
637 txStatus, rxStatus, interruptInProgress, commandByte;
638
639
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);
649
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);
653
654 ARLAN_DEBUG_EXIT("arlan_print_registers");
655}
656#endif
657
658
659static int arlan_hw_tx(struct net_device *dev, char *buf, int length)
660{
661 int i;
662
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;
666
667 int tailStarts = 0x800;
668 int headEnds = 0x0;
669
670
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;
676
677
678 if (!TXHEAD(dev).offset && length < tailStarts)
679 {
680 IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
681 printk(KERN_ERR "TXHEAD insert, tailStart %d\n", tailStarts);
682
683 TXHEAD(dev).offset =
684 offsetof(struct arlan_shmem, txBuffer);
685 TXHEAD(dev).length = length - ARLAN_FAKE_HDR_LEN;
686 for (i = 0; i < 6; i++)
687 TXHEAD(dev).dest[i] = buf[i];
688 TXHEAD(dev).clear = conf->txClear;
689 TXHEAD(dev).retries = conf->txRetries; /* 0 is use default */
690 TXHEAD(dev).routing = conf->txRouting;
691 TXHEAD(dev).scrambled = conf->txScrambled;
692 memcpy_toio((char __iomem *)arlan + TXHEAD(dev).offset, buf + ARLAN_FAKE_HDR_LEN, TXHEAD(dev).length);
693 }
694 else if (!TXTAIL(dev).offset && length < (0x800 - headEnds))
695 {
696 IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
697 printk(KERN_ERR "TXTAIL insert, headEnd %d\n", headEnds);
698
699 TXTAIL(dev).offset =
700 offsetof(struct arlan_shmem, txBuffer) + 0x800 - (length / 64 + 2) * 64;
701 TXTAIL(dev).length = length - ARLAN_FAKE_HDR_LEN;
702 for (i = 0; i < 6; i++)
703 TXTAIL(dev).dest[i] = buf[i];
704 TXTAIL(dev).clear = conf->txClear;
705 TXTAIL(dev).retries = conf->txRetries;
706 TXTAIL(dev).routing = conf->txRouting;
707 TXTAIL(dev).scrambled = conf->txScrambled;
708 memcpy_toio(((char __iomem *)arlan + TXTAIL(dev).offset), buf + ARLAN_FAKE_HDR_LEN, TXTAIL(dev).length);
709 }
710 else
711 {
712 netif_stop_queue (dev);
713 IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
714 printk(KERN_ERR "TX TAIL & HEAD full, return, tailStart %d headEnd %d\n", tailStarts, headEnds);
715 return -1;
716 }
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))
722 {
723 conf->out_speed = priv->out_bytes / conf->measure_rate;
724 priv->out_bytes = 0;
725 priv->out_time = jiffies;
726 }
727 if (time_after(jiffies, priv->out_time10 + conf->measure_rate * 10*HZ))
728 {
729 conf->out_speed10 = priv->out_bytes10 / (10 * conf->measure_rate);
730 priv->out_bytes10 = 0;
731 priv->out_time10 = jiffies;
732 }
733 if (TXHEAD(dev).offset && TXTAIL(dev).offset)
734 {
735 netif_stop_queue (dev);
736 return 0;
737 }
738 else
739 netif_start_queue (dev);
740
741
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]);
747
748 IFDEBUG(ARLAN_DEBUG_TX_CHAIN) printk(KERN_ERR "TX command prepare for buffer %d\n", priv->txLast);
749
750 arlan_command(dev, ARLAN_COMMAND_TX);
751
752 priv->tx_last_sent = jiffies;
753
754 IFDEBUG(ARLAN_DEBUG_TX_CHAIN) printk("%s TX Qued %d bytes \n", dev->name, length);
755
756 ARLAN_DEBUG_EXIT("arlan_hw_tx");
757
758 return 0;
759}
760
761
762static int arlan_hw_config(struct net_device *dev)
763{
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;
767
768 ARLAN_DEBUG_ENTRY("arlan_hw_config");
769
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");
773
774
775 WRITESHM(arlan->spreadingCode, conf->spreadingCode, u_char);
776 WRITESHM(arlan->channelSet, conf->channelSet, u_char);
777
778 if (arlan_EEPROM_bad)
779 WRITESHM(arlan->defaultChannelSet, conf->channelSet, u_char);
780
781 WRITESHM(arlan->channelNumber, conf->channelNumber, u_char);
782
783 WRITESHM(arlan->scramblingDisable, conf->scramblingDisable, u_char);
784 WRITESHM(arlan->txAttenuation, conf->txAttenuation, u_char);
785
786 WRITESHM(arlan->systemId, conf->systemId, u_int);
787
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);
793
794 WRITESHM(arlan->registrationMode, conf->registrationMode, u_char);
795
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);
816
817 memcpy_toio(arlan->encryptionKey + keyStart, encryptionKey, 8);
818 memcpy_toio(arlan->name, conf->siteName, 16);
819
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)
824 {
825 memset_io(arlan->commandParameter, conf->writeEEPROM, 1);
826// conf->writeEEPROM=0;
827 }
828 if (conf->registrationMode && conf->registrationInterrupts)
829 memset_io(arlan->commandParameter + 3, 1, 1);
830 else
831 memset_io(arlan->commandParameter + 3, 0, 1);
832
833 priv->irq_test_done = 0;
834
835 if (conf->tx_queue_len)
836 dev->tx_queue_len = conf->tx_queue_len;
837 udelay(100);
838
839 ARLAN_DEBUG_EXIT("arlan_hw_config");
840 return 0;
841}
842
843
844static int arlan_read_card_configuration(struct net_device *dev)
845{
846 u_char tlx415;
847 struct arlan_private *priv = netdev_priv(dev);
848 volatile struct arlan_shmem __iomem *arlan = priv->card;
849 struct arlan_conf_stru *conf = priv->Conf;
850
851 ARLAN_DEBUG_ENTRY("arlan_read_card_configuration");
852
853 if (radioNodeId == radioNodeIdUNKNOWN)
854 {
855 READSHM(conf->radioNodeId, arlan->radioNodeId, u_short);
856 }
857 else
858 conf->radioNodeId = radioNodeId;
859
860 if (SID == SIDUNKNOWN)
861 {
862 READSHM(conf->SID, arlan->SID, u_int);
863 }
864 else conf->SID = SID;
865
866 if (spreadingCode == spreadingCodeUNKNOWN)
867 {
868 READSHM(conf->spreadingCode, arlan->spreadingCode, u_char);
869 }
870 else
871 conf->spreadingCode = spreadingCode;
872
873 if (channelSet == channelSetUNKNOWN)
874 {
875 READSHM(conf->channelSet, arlan->channelSet, u_char);
876 }
877 else conf->channelSet = channelSet;
878
879 if (channelNumber == channelNumberUNKNOWN)
880 {
881 READSHM(conf->channelNumber, arlan->channelNumber, u_char);
882 }
883 else conf->channelNumber = channelNumber;
884
885 READSHM(conf->scramblingDisable, arlan->scramblingDisable, u_char);
886 READSHM(conf->txAttenuation, arlan->txAttenuation, u_char);
887
888 if (systemId == systemIdUNKNOWN)
889 {
890 READSHM(conf->systemId, arlan->systemId, u_int);
891 }
892 else conf->systemId = systemId;
893
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);
900
901 if (SID == SIDUNKNOWN)
902 {
903 READSHM(conf->SID, arlan->SID, u_int);
904 }
905 else conf->SID = SID;
906
907 if (registrationMode == registrationModeUNKNOWN)
908 {
909 READSHM(conf->registrationMode, arlan->registrationMode, u_char);
910 }
911 else conf->registrationMode = registrationMode;
912
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);
927
928 if (conf->radioType == 0)
929 conf->radioType = 0xc;
930
931 WRITESHM(arlan->configStatus, 0xA5, u_char);
932 READSHM(tlx415, arlan->configStatus, u_char);
933
934 if (tlx415 != 0xA5)
935 printk(KERN_INFO "%s tlx415 chip \n", dev->name);
936
937 conf->txClear = 0;
938 conf->txRetries = 1;
939 conf->txRouting = 1;
940 conf->txScrambled = 0;
941 conf->rxParameter = 1;
942 conf->txTimeoutMs = 4000;
943 conf->waitCardTimeout = 100000;
944 conf->receiveMode = ARLAN_RCV_CLEAN;
945 memcpy_fromio(conf->siteName, arlan->name, 16);
946 conf->siteName[16] = '\0';
947 conf->retries = retries;
948 conf->tx_delay_ms = tx_delay_ms;
949 conf->ReTransmitPacketMaxSize = 200;
950 conf->waitReTransmitPacketMaxSize = 200;
951 conf->txAckTimeoutMs = 900;
952 conf->fastReTransCount = 3;
953
954 ARLAN_DEBUG_EXIT("arlan_read_card_configuration");
955
956 return 0;
957}
958
959
960static int lastFoundAt = 0xbe000;
961
962
963/*
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.
967 */
968#define ARLAN_SHMEM_SIZE 0x2000
969static int __init arlan_check_fingerprint(unsigned long memaddr)
970{
971 static const char probeText[] = "TELESYSTEM SLW INC. ARLAN \0";
972 volatile struct arlan_shmem __iomem *arlan = (struct arlan_shmem *) memaddr;
973 unsigned long paddr = virt_to_phys((void *) memaddr);
974 char tempBuf[49];
975
976 ARLAN_DEBUG_ENTRY("arlan_check_fingerprint");
977
978 if (!request_mem_region(paddr, ARLAN_SHMEM_SIZE, "arlan")) {
979 // printk(KERN_WARNING "arlan: memory region %lx excluded from probing \n",paddr);
980 return -ENODEV;
981 }
982
983 memcpy_fromio(tempBuf, arlan->textRegion, 29);
984 tempBuf[30] = 0;
985
986 /* check for card at this address */
987 if (0 != strncmp(tempBuf, probeText, 29)){
988 release_mem_region(paddr, ARLAN_SHMEM_SIZE);
989 return -ENODEV;
990 }
991
992// printk(KERN_INFO "arlan found at 0x%x \n",memaddr);
993 ARLAN_DEBUG_EXIT("arlan_check_fingerprint");
994
995 return 0;
996}
997
998static int arlan_change_mtu(struct net_device *dev, int new_mtu)
999{
1000 struct arlan_private *priv = netdev_priv(dev);
1001 struct arlan_conf_stru *conf = priv->Conf;
1002
1003 ARLAN_DEBUG_ENTRY("arlan_change_mtu");
1004 if (new_mtu > 2032)
1005 return -EINVAL;
1006 dev->mtu = new_mtu;
1007 if (new_mtu < 256)
1008 new_mtu = 256; /* cards book suggests 1600 */
1009 conf->maxDatagramSize = new_mtu;
1010 conf->maxFrameSize = new_mtu + 48;
1011
1012 arlan_command(dev, ARLAN_COMMAND_CLEAN_AND_CONF);
1013 printk(KERN_NOTICE "%s mtu changed to %d \n", dev->name, new_mtu);
1014
1015 ARLAN_DEBUG_EXIT("arlan_change_mtu");
1016
1017 return 0;
1018}
1019
1020static int arlan_mac_addr(struct net_device *dev, void *p)
1021{
1022 struct sockaddr *addr = p;
1023
1024
1025 ARLAN_DEBUG_ENTRY("arlan_mac_addr");
1026 return -EINVAL;
1027
1028 if (!netif_running(dev))
1029 return -EBUSY;
1030 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
1031
1032 ARLAN_DEBUG_EXIT("arlan_mac_addr");
1033 return 0;
1034}
1035
1036
1037
1038static int __init arlan_setup_device(struct net_device *dev, int num)
1039{
1040 struct arlan_private *ap = netdev_priv(dev);
1041 int err;
1042
1043 ARLAN_DEBUG_ENTRY("arlan_setup_device");
1044
1045 ap->conf = (struct arlan_shmem *)(ap+1);
1046
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;
1057
1058 ap->irq_test_done = 0;
1059 ap->Conf = &arlan_conf[num];
1060
1061 ap->Conf->pre_Command_Wait = 40;
1062 ap->Conf->rx_tweak1 = 30;
1063 ap->Conf->rx_tweak2 = 0;
1064
1065
1066 err = register_netdev(dev);
1067 if (err) {
1068 release_mem_region(virt_to_phys((void *) dev->mem_start),
1069 ARLAN_SHMEM_SIZE);
1070 free_netdev(dev);
1071 return err;
1072 }
1073 arlan_device[num] = dev;
1074 ARLAN_DEBUG_EXIT("arlan_setup_device");
1075 return 0;
1076}
1077
1078static int __init arlan_probe_here(struct net_device *dev,
1079 unsigned long memaddr)
1080{
1081 struct arlan_private *ap = netdev_priv(dev);
1082
1083 ARLAN_DEBUG_ENTRY("arlan_probe_here");
1084
1085 if (arlan_check_fingerprint(memaddr))
1086 return -ENODEV;
1087
1088 printk(KERN_NOTICE "%s: Arlan found at %x, \n ", dev->name,
1089 (int) virt_to_phys((void*)memaddr));
1090
1091 ap->card = (void *) memaddr;
1092 dev->mem_start = memaddr;
1093 dev->mem_end = memaddr + ARLAN_SHMEM_SIZE-1;
1094
1095 if (dev->irq < 2)
1096 {
1097 READSHM(dev->irq, ap->card->irqLevel, u_char);
1098 } else if (dev->irq == 2)
1099 dev->irq = 9;
1100
1101 arlan_read_card_configuration(dev);
1102
1103 ARLAN_DEBUG_EXIT("arlan_probe_here");
1104 return 0;
1105}
1106
1107
1108static int arlan_open(struct net_device *dev)
1109{
1110 struct arlan_private *priv = netdev_priv(dev);
1111 volatile struct arlan_shmem __iomem *arlan = priv->card;
1112 int ret = 0;
1113
1114 ARLAN_DEBUG_ENTRY("arlan_open");
1115
1116 ret = request_irq(dev->irq, &arlan_interrupt, 0, dev->name, dev);
1117 if (ret)
1118 {
1119 printk(KERN_ERR "%s: unable to get IRQ %d .\n",
1120 dev->name, dev->irq);
1121 return ret;
1122 }
1123
1124
1125 priv->bad = 0;
1126 priv->lastReset = 0;
1127 priv->reset = 0;
1128 memcpy_fromio(dev->dev_addr, arlan->lanCardNodeId, 6);
1129 memset(dev->broadcast, 0xff, 6);
1130 dev->tx_queue_len = tx_queue_len;
1131 priv->interrupt_processing_active = 0;
1132 spin_lock_init(&priv->lock);
1133
1134 netif_start_queue (dev);
1135
1136 priv->registrationLostCount = 0;
1137 priv->registrationLastSeen = jiffies;
1138 priv->txLast = 0;
1139 priv->tx_command_given = 0;
1140 priv->rx_command_given = 0;
1141
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;
1147
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 */
1152
1153 arlan_command(dev, ARLAN_COMMAND_POWERUP | ARLAN_COMMAND_LONG_WAIT_NOW);
1154 mdelay(200);
1155 add_timer(&priv->timer);
1156
1157 ARLAN_DEBUG_EXIT("arlan_open");
1158 return 0;
1159}
1160
1161
1162static void arlan_tx_timeout (struct net_device *dev)
1163{
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);
1169}
1170
1171
1172static int arlan_tx(struct sk_buff *skb, struct net_device *dev)
1173{
1174 short length;
1175 unsigned char *buf;
1176
1177 ARLAN_DEBUG_ENTRY("arlan_tx");
1178
1179 length = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
1180 buf = skb->data;
1181
1182 if (length + 0x12 > 0x800) {
1183 printk(KERN_ERR "TX RING overflow \n");
1184 netif_stop_queue (dev);
1185 }
1186
1187 if (arlan_hw_tx(dev, buf, length) == -1)
1188 goto bad_end;
1189
1190 dev->trans_start = jiffies;
1191
1192 dev_kfree_skb(skb);
1193
1194 arlan_process_interrupt(dev);
1195 ARLAN_DEBUG_EXIT("arlan_tx");
1196 return 0;
1197
1198bad_end:
1199 arlan_process_interrupt(dev);
1200 netif_stop_queue (dev);
1201 ARLAN_DEBUG_EXIT("arlan_tx");
1202 return 1;
1203}
1204
1205
1206static inline int DoNotReTransmitCrap(struct net_device *dev)
1207{
1208 struct arlan_private *priv = netdev_priv(dev);
1209
1210 if (TXLAST(dev).length < priv->Conf->ReTransmitPacketMaxSize)
1211 return 1;
1212 return 0;
1213
1214}
1215
1216static inline int DoNotWaitReTransmitCrap(struct net_device *dev)
1217{
1218 struct arlan_private *priv = netdev_priv(dev);
1219
1220 if (TXLAST(dev).length < priv->Conf->waitReTransmitPacketMaxSize)
1221 return 1;
1222 return 0;
1223}
1224
1225static inline void arlan_queue_retransmit(struct net_device *dev)
1226{
1227 struct arlan_private *priv = netdev_priv(dev);
1228
1229 ARLAN_DEBUG_ENTRY("arlan_queue_retransmit");
1230
1231 if (DoNotWaitReTransmitCrap(dev))
1232 {
1233 arlan_drop_tx(dev);
1234 } else
1235 priv->ReTransmitRequested++;
1236
1237 ARLAN_DEBUG_EXIT("arlan_queue_retransmit");
1238}
1239
1240static inline void RetryOrFail(struct net_device *dev)
1241{
1242 struct arlan_private *priv = netdev_priv(dev);
1243
1244 ARLAN_DEBUG_ENTRY("RetryOrFail");
1245
1246 if (priv->retransmissions > priv->Conf->retries ||
1247 DoNotReTransmitCrap(dev))
1248 {
1249 arlan_drop_tx(dev);
1250 }
1251 else if (priv->bad <= priv->Conf->fastReTransCount)
1252 {
1253 arlan_retransmit_now(dev);
1254 }
1255 else arlan_queue_retransmit(dev);
1256
1257 ARLAN_DEBUG_EXIT("RetryOrFail");
1258}
1259
1260
1261static void arlan_tx_done_interrupt(struct net_device *dev, int status)
1262{
1263 struct arlan_private *priv = netdev_priv(dev);
1264
1265 ARLAN_DEBUG_ENTRY("arlan_tx_done_interrupt");
1266
1267 priv->tx_last_cleared = jiffies;
1268 priv->tx_command_given = 0;
1269 switch (status)
1270 {
1271 case 1:
1272 {
1273 IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
1274 printk("arlan intr: transmit OK\n");
1275 priv->stats.tx_packets++;
1276 priv->bad = 0;
1277 priv->reset = 0;
1278 priv->retransmissions = 0;
1279 if (priv->Conf->tx_delay_ms)
1280 {
1281 priv->tx_done_delayed = jiffies + (priv->Conf->tx_delay_ms * HZ) / 1000 + 1;
1282 }
1283 else
1284 {
1285 TXLAST(dev).offset = 0;
1286 if (priv->txLast)
1287 priv->txLast = 0;
1288 else if (TXTAIL(dev).offset)
1289 priv->txLast = 1;
1290 if (TXLAST(dev).offset)
1291 {
1292 arlan_retransmit_now(dev);
1293 dev->trans_start = jiffies;
1294 }
1295 if (!TXHEAD(dev).offset || !TXTAIL(dev).offset)
1296 {
1297 netif_wake_queue (dev);
1298 }
1299 }
1300 }
1301 break;
1302
1303 case 2:
1304 {
1305 IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
1306 printk("arlan intr: transmit timed out\n");
1307 priv->bad += 1;
1308 //arlan_queue_retransmit(dev);
1309 RetryOrFail(dev);
1310 }
1311 break;
1312
1313 case 3:
1314 {
1315 IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
1316 printk("arlan intr: transmit max retries\n");
1317 priv->bad += 1;
1318 priv->reset = 0;
1319 //arlan_queue_retransmit(dev);
1320 RetryOrFail(dev);
1321 }
1322 break;
1323
1324 case 4:
1325 {
1326 IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
1327 printk("arlan intr: transmit aborted\n");
1328 priv->bad += 1;
1329 arlan_queue_retransmit(dev);
1330 //RetryOrFail(dev);
1331 }
1332 break;
1333
1334 case 5:
1335 {
1336 IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
1337 printk("arlan intr: transmit not registered\n");
1338 priv->bad += 1;
1339 //debug=101;
1340 arlan_queue_retransmit(dev);
1341 }
1342 break;
1343
1344 case 6:
1345 {
1346 IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
1347 printk("arlan intr: transmit destination full\n");
1348 priv->bad += 1;
1349 priv->reset = 0;
1350 //arlan_drop_tx(dev);
1351 arlan_queue_retransmit(dev);
1352 }
1353 break;
1354
1355 case 7:
1356 {
1357 IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
1358 printk("arlan intr: transmit unknown ack\n");
1359 priv->bad += 1;
1360 priv->reset = 0;
1361 arlan_queue_retransmit(dev);
1362 }
1363 break;
1364
1365 case 8:
1366 {
1367 IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
1368 printk("arlan intr: transmit dest mail box full\n");
1369 priv->bad += 1;
1370 priv->reset = 0;
1371 //arlan_drop_tx(dev);
1372 arlan_queue_retransmit(dev);
1373 }
1374 break;
1375
1376 case 9:
1377 {
1378 IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
1379 printk("arlan intr: transmit root dest not reg.\n");
1380 priv->bad += 1;
1381 priv->reset = 1;
1382 //arlan_drop_tx(dev);
1383 arlan_queue_retransmit(dev);
1384 }
1385 break;
1386
1387 default:
1388 {
1389 printk(KERN_ERR "arlan intr: transmit status unknown\n");
1390 priv->bad += 1;
1391 priv->reset = 1;
1392 arlan_drop_tx(dev);
1393 }
1394 }
1395
1396 ARLAN_DEBUG_EXIT("arlan_tx_done_interrupt");
1397}
1398
1399
1400static void arlan_rx_interrupt(struct net_device *dev, u_char rxStatus, u_short rxOffset, u_short pkt_len)
1401{
1402 char *skbtmp;
1403 int i = 0;
1404
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;
1408
1409
1410 ARLAN_DEBUG_ENTRY("arlan_rx_interrupt");
1411 // by spec, not WRITESHMB(arlan->rxStatus,0x00);
1412 // prohibited here arlan_command(dev, ARLAN_COMMAND_RX);
1413
1414 if (pkt_len < 10 || pkt_len > 2048)
1415 {
1416 printk(KERN_WARNING "%s: got too short or long packet, len %d \n", dev->name, pkt_len);
1417 return;
1418 }
1419 if (rxOffset + pkt_len > 0x2000)
1420 {
1421 printk("%s: got too long packet, len %d offset %x\n", dev->name, pkt_len, rxOffset);
1422 return;
1423 }
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))
1429 {
1430 conf->in_speed = priv->in_bytes / conf->measure_rate;
1431 priv->in_bytes = 0;
1432 priv->in_time = jiffies;
1433 }
1434 if (time_after(jiffies, priv->in_time10 + conf->measure_rate * 10*HZ))
1435 {
1436 conf->in_speed10 = priv->in_bytes10 / (10 * conf->measure_rate);
1437 priv->in_bytes10 = 0;
1438 priv->in_time10 = jiffies;
1439 }
1440 DEBUGSHM(1, "arlan rcv pkt rxStatus= %d ", arlan->rxStatus, u_char);
1441 switch (rxStatus)
1442 {
1443 case 1:
1444 case 2:
1445 case 3:
1446 {
1447 /* Malloc up new buffer. */
1448 struct sk_buff *skb;
1449
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);
1453
1454 /* here we do multicast filtering to avoid slow 8-bit memcopy */
1455#ifdef ARLAN_MULTICAST
1456 if (!(dev->flags & IFF_ALLMULTI) &&
1457 !(dev->flags & IFF_PROMISC) &&
1458 dev->mc_list)
1459 {
1460 char hw_dst_addr[6];
1461 struct dev_mc_list *dmi = dev->mc_list;
1462 int i;
1463
1464 memcpy_fromio(hw_dst_addr, arlan->ultimateDestAddress, 6);
1465 if (hw_dst_addr[0] == 0x01)
1466 {
1467 if (mdebug)
1468 if (hw_dst_addr[1] == 0x00)
1469 printk(KERN_ERR "%s mcast 0x0100 \n", dev->name);
1470 else if (hw_dst_addr[1] == 0x40)
1471 printk(KERN_ERR "%s m/bcast 0x0140 \n", dev->name);
1472 while (dmi)
1473 { if (dmi->dmi_addrlen == 6)
1474 {
1475 if (arlan_debug & ARLAN_DEBUG_HEADER_DUMP)
1476 printk(KERN_ERR "%s mcl %2x:%2x:%2x:%2x:%2x:%2x \n", dev->name,
1477 dmi->dmi_addr[0], dmi->dmi_addr[1], dmi->dmi_addr[2],
1478 dmi->dmi_addr[3], dmi->dmi_addr[4], dmi->dmi_addr[5]);
1479 for (i = 0; i < 6; i++)
1480 if (dmi->dmi_addr[i] != hw_dst_addr[i])
1481 break;
1482 if (i == 6)
1483 break;
1484 }
1485 else
1486 printk(KERN_ERR "%s: invalid multicast address length given.\n", dev->name);
1487 dmi = dmi->next;
1488 }
1489 /* we reach here if multicast filtering is on and packet
1490 * is multicast and not for receive */
1491 goto end_of_interrupt;
1492 }
1493 }
1494#endif // ARLAN_MULTICAST
1495 /* multicast filtering ends here */
1496 pkt_len += ARLAN_FAKE_HDR_LEN;
1497
1498 skb = dev_alloc_skb(pkt_len + 4);
1499 if (skb == NULL)
1500 {
1501 printk(KERN_ERR "%s: Memory squeeze, dropping packet.\n", dev->name);
1502 priv->stats.rx_dropped++;
1503 break;
1504 }
1505 skb_reserve(skb, 2);
1506 skb->dev = dev;
1507 skbtmp = skb_put(skb, pkt_len);
1508
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);
1514
1515 IFDEBUG(ARLAN_DEBUG_HEADER_DUMP)
1516 {
1517 char immedDestAddress[6];
1518 char immedSrcAddress[6];
1519 memcpy_fromio(immedDestAddress, arlan->immedDestAddress, 6);
1520 memcpy_fromio(immedSrcAddress, arlan->immedSrcAddress, 6);
1521
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]);
1530 }
1531 skb->protocol = eth_type_trans(skb, dev);
1532 IFDEBUG(ARLAN_DEBUG_HEADER_DUMP)
1533 if (skb->protocol != 0x608 && skb->protocol != 0x8)
1534 {
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);
1539 }
1540 netif_rx(skb);
1541 dev->last_rx = jiffies;
1542 priv->stats.rx_packets++;
1543 priv->stats.rx_bytes += pkt_len;
1544 }
1545 break;
1546
1547 default:
1548 printk(KERN_ERR "arlan intr: received unknown status\n");
1549 priv->stats.rx_crc_errors++;
1550 break;
1551 }
1552 ARLAN_DEBUG_EXIT("arlan_rx_interrupt");
1553}
1554
1555static void arlan_process_interrupt(struct net_device *dev)
1556{
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;
1564
1565 ARLAN_DEBUG_ENTRY("arlan_process_interrupt");
1566
1567 if (test_and_set_bit(0, (void *) &priv->interrupt_processing_active))
1568 {
1569 if (arlan_debug & ARLAN_DEBUG_CHAIN_LOCKS)
1570 printk(KERN_ERR "interrupt chain reentering \n");
1571 goto end_int_process;
1572 }
1573 while ((rxStatus || txStatus || priv->interrupt_ack_requested)
1574 && (interrupt_count < 5))
1575 {
1576 if (rxStatus)
1577 priv->last_rx_int_ack_time = jiffies;
1578
1579 arlan_command(dev, ARLAN_COMMAND_INT_ACK);
1580 arlan_command(dev, ARLAN_COMMAND_INT_ENABLE);
1581
1582 IFDEBUG(ARLAN_DEBUG_INTERRUPT)
1583 printk(KERN_ERR "%s: got IRQ rx %x tx %x comm %x rxOff %x rxLen %x \n",
1584 dev->name, rxStatus, txStatus, READSHMB(arlan->commandByte),
1585 rxOffset, pkt_len);
1586
1587 if (rxStatus == 0 && txStatus == 0)
1588 {
1589 if (priv->irq_test_done)
1590 {
1591 if (!registrationBad(dev))
1592 IFDEBUG(ARLAN_DEBUG_INTERRUPT) printk(KERN_ERR "%s unknown interrupt(nop? regLost ?) reason tx %d rx %d ",
1593 dev->name, txStatus, rxStatus);
1594 } else {
1595 IFDEBUG(ARLAN_DEBUG_INTERRUPT)
1596 printk(KERN_INFO "%s irq $%d test OK \n", dev->name, dev->irq);
1597
1598 }
1599 priv->interrupt_ack_requested = 0;
1600 goto ends;
1601 }
1602 if (txStatus != 0)
1603 {
1604 WRITESHMB(arlan->txStatus, 0x00);
1605 arlan_tx_done_interrupt(dev, txStatus);
1606 goto ends;
1607 }
1608 if (rxStatus == 1 || rxStatus == 2)
1609 { /* a packet waiting */
1610 arlan_rx_interrupt(dev, rxStatus, rxOffset, pkt_len);
1611 goto ends;
1612 }
1613 if (rxStatus > 2 && rxStatus < 0xff)
1614 {
1615 WRITESHMB(arlan->rxStatus, 0x00);
1616 printk(KERN_ERR "%s unknown rxStatus reason tx %d rx %d ",
1617 dev->name, txStatus, rxStatus);
1618 goto ends;
1619 }
1620 if (rxStatus == 0xff)
1621 {
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))
1627 {
1628 priv->registrationLastSeen = jiffies;
1629 if (!netif_queue_stopped(dev) && !priv->under_reset && !priv->under_config)
1630 netif_wake_queue (dev);
1631 }
1632 goto ends;
1633 }
1634ends:
1635
1636 arlan_command_process(dev);
1637
1638 rxStatus = READSHMB(arlan->rxStatus);
1639 txStatus = READSHMB(arlan->txStatus);
1640 rxOffset = READSHMS(arlan->rxOffset);
1641 pkt_len = READSHMS(arlan->rxLength);
1642
1643
1644 priv->irq_test_done = 1;
1645
1646 interrupt_count++;
1647 }
1648 priv->interrupt_processing_active = 0;
1649
1650end_int_process:
1651 arlan_command_process(dev);
1652
1653 ARLAN_DEBUG_EXIT("arlan_process_interrupt");
1654 return;
1655}
1656
1657static irqreturn_t arlan_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1658{
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);
1664
1665 ARLAN_DEBUG_ENTRY("arlan_interrupt");
1666
1667
1668 if (!rxStatus && !txStatus)
1669 priv->interrupt_ack_requested++;
1670
1671 arlan_process_interrupt(dev);
1672
1673 priv->irq_test_done = 1;
1674
1675 ARLAN_DEBUG_EXIT("arlan_interrupt");
1676 return IRQ_HANDLED;
1677
1678}
1679
1680
1681static int arlan_close(struct net_device *dev)
1682{
1683 struct arlan_private *priv = netdev_priv(dev);
1684
1685 ARLAN_DEBUG_ENTRY("arlan_close");
1686
1687 del_timer_sync(&priv->timer);
1688
1689 arlan_command(dev, ARLAN_COMMAND_POWERDOWN);
1690
1691 IFDEBUG(ARLAN_DEBUG_STARTUP)
1692 printk(KERN_NOTICE "%s: Closing device\n", dev->name);
1693
1694 netif_stop_queue(dev);
1695 free_irq(dev->irq, dev);
1696
1697 ARLAN_DEBUG_EXIT("arlan_close");
1698 return 0;
1699}
1700
1701#ifdef ARLAN_DEBUGGING
1702static long alignLong(volatile u_char * ptr)
1703{
1704 long ret;
1705 memcpy_fromio(&ret, (void *) ptr, 4);
1706 return ret;
1707}
1708#endif
1709
1710/*
1711 * Get the current statistics.
1712 * This may be called with the card open or closed.
1713 */
1714
1715static struct net_device_stats *arlan_statistics(struct net_device *dev)
1716{
1717 struct arlan_private *priv = netdev_priv(dev);
1718 volatile struct arlan_shmem __iomem *arlan = priv->card;
1719
1720
1721 ARLAN_DEBUG_ENTRY("arlan_statistics");
1722
1723 /* Update the statistics from the device registers. */
1724
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);
1738
1739 ARLAN_DEBUG_EXIT("arlan_statistics");
1740
1741 return &priv->stats;
1742}
1743
1744
1745static void arlan_set_multicast(struct net_device *dev)
1746{
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;
1751
1752
1753 ARLAN_DEBUG_ENTRY("arlan_set_multicast");
1754
1755 if (dev->flags & IFF_PROMISC)
1756 {
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;
1762 }
1763 else
1764 {
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;
1771 }
1772 if (board_conf_needed)
1773 arlan_command(dev, ARLAN_COMMAND_CONF);
1774
1775 ARLAN_DEBUG_EXIT("arlan_set_multicast");
1776}
1777
1778
1779struct net_device * __init arlan_probe(int unit)
1780{
1781 struct net_device *dev;
1782 int err;
1783 int m;
1784
1785 ARLAN_DEBUG_ENTRY("arlan_probe");
1786
1787 if (arlans_found == MAX_ARLANS)
1788 return ERR_PTR(-ENODEV);
1789
1790 /*
1791 * Reserve space for local data and a copy of the shared memory
1792 * that is used by the /proc interface.
1793 */
1794 dev = alloc_etherdev(sizeof(struct arlan_private)
1795 + sizeof(struct arlan_shmem));
1796 if (!dev)
1797 return ERR_PTR(-ENOMEM);
1798
1799 SET_MODULE_OWNER(dev);
1800
1801 if (unit >= 0) {
1802 sprintf(dev->name, "eth%d", unit);
1803 netdev_boot_setup_check(dev);
1804
1805 if (dev->mem_start) {
1806 if (arlan_probe_here(dev, dev->mem_start) == 0)
1807 goto found;
1808 goto not_found;
1809 }
1810
1811 }
1812
1813
1814 for (m = (int)phys_to_virt(lastFoundAt) + ARLAN_SHMEM_SIZE;
1815 m <= (int)phys_to_virt(0xDE000);
1816 m += ARLAN_SHMEM_SIZE)
1817 {
1818 if (arlan_probe_here(dev, m) == 0)
1819 {
1820 lastFoundAt = (int)virt_to_phys((void*)m);
1821 goto found;
1822 }
1823 }
1824
1825 if (lastFoundAt == 0xbe000)
1826 printk(KERN_ERR "arlan: No Arlan devices found \n");
1827
1828 not_found:
1829 free_netdev(dev);
1830 return ERR_PTR(-ENODEV);
1831
1832 found:
1833 err = arlan_setup_device(dev, arlans_found);
1834 if (err)
1835 dev = ERR_PTR(err);
1836 else if (!arlans_found++)
1837 printk(KERN_INFO "Arlan driver %s\n", arlan_version);
1838
1839 return dev;
1840}
1841
1842#ifdef MODULE
1843int init_module(void)
1844{
1845 int i = 0;
1846
1847 ARLAN_DEBUG_ENTRY("init_module");
1848
1849 if (channelSet != channelSetUNKNOWN || channelNumber != channelNumberUNKNOWN || systemId != systemIdUNKNOWN)
1850 return -EINVAL;
1851
1852 for (i = 0; i < MAX_ARLANS; i++) {
1853 struct net_device *dev = arlan_probe(i);
1854
1855 if (IS_ERR(dev))
1856 return PTR_ERR(dev);
1857 }
1858 init_arlan_proc();
1859 printk(KERN_INFO "Arlan driver %s\n", arlan_version);
1860 ARLAN_DEBUG_EXIT("init_module");
1861 return 0;
1862}
1863
1864
1865void cleanup_module(void)
1866{
1867 int i = 0;
1868 struct net_device *dev;
1869
1870 ARLAN_DEBUG_ENTRY("cleanup_module");
1871
1872 IFDEBUG(ARLAN_DEBUG_SHUTDOWN)
1873 printk(KERN_INFO "arlan: unloading module\n");
1874
1875 cleanup_arlan_proc();
1876
1877 for (i = 0; i < MAX_ARLANS; i++)
1878 {
1879 dev = arlan_device[i];
1880 if (dev) {
1881 arlan_command(dev, ARLAN_COMMAND_POWERDOWN );
1882
1883 unregister_netdev(dev);
1884 release_mem_region(virt_to_phys((void *) dev->mem_start),
1885 ARLAN_SHMEM_SIZE);
1886 free_netdev(dev);
1887 arlan_device[i] = NULL;
1888 }
1889 }
1890
1891 ARLAN_DEBUG_EXIT("cleanup_module");
1892}
1893
1894
1895#endif
1896MODULE_LICENSE("GPL");