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
15 const char *arlan_version = "C.Jennigs 97 & Elmer.Joandi@ut.ee Oct'98, http://www.ylenurme.ee/~elmer/655/";
16
17 struct net_device *arlan_device[MAX_ARLANS];
18 int last_arlan;
19
20 static int SID = SIDUNKNOWN;
21 static int radioNodeId = radioNodeIdUNKNOWN;
22 static char encryptionKey[12] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'};
23 static char *siteName = siteNameUNKNOWN;
24 static int mem = memUNKNOWN;
25 int arlan_debug = debugUNKNOWN;
26 static int probe = probeUNKNOWN;
27 static int numDevices = numDevicesUNKNOWN;
28 static int spreadingCode = spreadingCodeUNKNOWN;
29 static int channelNumber = channelNumberUNKNOWN;
30 static int channelSet = channelSetUNKNOWN;
31 static int systemId = systemIdUNKNOWN;
32 static int registrationMode = registrationModeUNKNOWN;
33 static int keyStart;
34 static int tx_delay_ms;
35 static int retries = 5;
36 static int async = 1;
37 static int tx_queue_len = 1;
38 static int arlan_EEPROM_bad;
39
40 #ifdef ARLAN_DEBUGGING
41
42 static int arlan_entry_debug;
43 static int arlan_exit_debug;
44 static int testMemory = testMemoryUNKNOWN;
45 static int irq = irqUNKNOWN;
46 static int txScrambled = 1;
47 static int mdebug;
48 #endif
49
50 #if LINUX_VERSION_CODE > 0x20100
51 MODULE_PARM(irq, "i");
52 MODULE_PARM(mem, "i");
53 MODULE_PARM(probe, "i");
54 MODULE_PARM(arlan_debug, "i");
55 MODULE_PARM(numDevices, "i");
56 MODULE_PARM(testMemory, "i");
57 MODULE_PARM(spreadingCode, "i");
58 MODULE_PARM(channelNumber, "i");
59 MODULE_PARM(channelSet, "i");
60 MODULE_PARM(systemId, "i");
61 MODULE_PARM(registrationMode, "i");
62 MODULE_PARM(radioNodeId, "i");
63 MODULE_PARM(SID, "i");
64 MODULE_PARM(txScrambled, "i");
65 MODULE_PARM(keyStart, "i");
66 MODULE_PARM(mdebug, "i");
67 MODULE_PARM(tx_delay_ms, "i");
68 MODULE_PARM(retries, "i");
69 MODULE_PARM(async, "i");
70 MODULE_PARM(tx_queue_len, "i");
71 MODULE_PARM(arlan_entry_debug, "i");
72 MODULE_PARM(arlan_exit_debug, "i");
73 MODULE_PARM(arlan_entry_and_exit_debug, "i");
74 MODULE_PARM(arlan_EEPROM_bad, "i");
75 MODULE_PARM_DESC(irq, "(unused)");
76 MODULE_PARM_DESC(mem, "Arlan memory address for single device probing");
77 MODULE_PARM_DESC(probe, "Arlan probe at initialization (0-1)");
78 MODULE_PARM_DESC(arlan_debug, "Arlan debug enable (0-1)");
79 MODULE_PARM_DESC(numDevices, "Number of Arlan devices; ignored if >1");
80 MODULE_PARM_DESC(testMemory, "(unused)");
81 MODULE_PARM_DESC(mdebug, "Arlan multicast debugging (0-1)");
82 MODULE_PARM_DESC(retries, "Arlan maximum packet retransmisions");
83 #ifdef ARLAN_ENTRY_EXIT_DEBUGGING
84 MODULE_PARM_DESC(arlan_entry_debug, "Arlan driver function entry debugging");
85 MODULE_PARM_DESC(arlan_exit_debug, "Arlan driver function exit debugging");
86 MODULE_PARM_DESC(arlan_entry_and_exit_debug, "Arlan driver function entry and exit debugging");
87 #else
88 MODULE_PARM_DESC(arlan_entry_debug, "(ignored)");
89 MODULE_PARM_DESC(arlan_exit_debug, "(ignored)");
90 MODULE_PARM_DESC(arlan_entry_and_exit_debug, "(ignored)");
91 #endif
92
93 EXPORT_SYMBOL(arlan_device);
94 EXPORT_SYMBOL(arlan_conf);
95 EXPORT_SYMBOL(last_arlan);
96
97
98 // #warning kernel 2.1.110 tested
99 #define myATOMIC_INIT(a,b) atomic_set(&(a),b)
100
101 #else
102 #define test_and_set_bit set_bit
103 #if LINUX_VERSION_CODE != 0x20024
104 // #warning kernel 2.0.36 tested
105 #endif
106 #define myATOMIC_INIT(a,b) a = b;
107
108 #endif
109
110 struct arlan_conf_stru arlan_conf[MAX_ARLANS];
111 static int arlans_found;
112
113 static int arlan_probe_here(struct net_device *dev, int ioaddr);
114 static int arlan_open(struct net_device *dev);
115 static int arlan_tx(struct sk_buff *skb, struct net_device *dev);
116 static void arlan_interrupt(int irq, void *dev_id, struct pt_regs *regs);
117 static int arlan_close(struct net_device *dev);
118 static struct net_device_stats *
119 arlan_statistics (struct net_device *dev);
120 static void arlan_set_multicast (struct net_device *dev);
121 static int arlan_hw_tx (struct net_device* dev, char *buf, int length );
122 static int arlan_hw_config (struct net_device * dev);
123 static void arlan_tx_done_interrupt (struct net_device * dev, int status);
124 static void arlan_rx_interrupt (struct net_device * dev, u_char rxStatus, u_short, u_short);
125 static void arlan_process_interrupt (struct net_device * dev);
126 static void arlan_tx_timeout (struct net_device *dev);
127 int arlan_command(struct net_device * dev, int command);
128
129 EXPORT_SYMBOL(arlan_command);
130
arlan_time(void)131 static inline long long arlan_time(void)
132 {
133 struct timeval timev;
134 do_gettimeofday(&timev);
135 return ((long long) timev.tv_sec * 1000000 + timev.tv_usec);
136 };
137
138 #ifdef ARLAN_ENTRY_EXIT_DEBUGGING
139 #define ARLAN_DEBUG_ENTRY(name) \
140 {\
141 struct timeval timev;\
142 do_gettimeofday(&timev);\
143 if (arlan_entry_debug || arlan_entry_and_exit_debug)\
144 printk("--->>>" name " %ld " "\n",((long int) timev.tv_sec * 1000000 + timev.tv_usec));\
145 }
146 #define ARLAN_DEBUG_EXIT(name) \
147 {\
148 struct timeval timev;\
149 do_gettimeofday(&timev);\
150 if (arlan_exit_debug || arlan_entry_and_exit_debug)\
151 printk("<<<---" name " %ld " "\n",((long int) timev.tv_sec * 1000000 + timev.tv_usec) );\
152 }
153 #else
154 #define ARLAN_DEBUG_ENTRY(name)
155 #define ARLAN_DEBUG_EXIT(name)
156 #endif
157
158
159 #define arlan_interrupt_ack(dev)\
160 clearClearInterrupt(dev);\
161 setClearInterrupt(dev);
162
163
164 #define ARLAN_COMMAND_LOCK(dev) \
165 if (atomic_dec_and_test(&((struct arlan_private * )dev->priv)->card_users))\
166 arlan_wait_command_complete_short(dev,__LINE__);
167 #define ARLAN_COMMAND_UNLOCK(dev) \
168 atomic_inc(&((struct arlan_private * )dev->priv)->card_users);
169
170
171 #define ARLAN_COMMAND_INC(dev) \
172 {((struct arlan_private *) dev->priv)->under_command++;}
173 #define ARLAN_COMMAND_ZERO(dev) \
174 {((struct arlan_private *) dev->priv)->under_command =0;}
175 #define ARLAN_UNDER_COMMAND(dev)\
176 (((struct arlan_private *) dev->priv)->under_command)
177
178 #define ARLAN_COMMAND_START(dev) ARLAN_COMMAND_INC(dev)
179 #define ARLAN_COMMAND_END(dev) ARLAN_COMMAND_ZERO(dev)
180 #define ARLAN_TOGGLE_START(dev)\
181 {((struct arlan_private *) dev->priv)->under_toggle++;}
182 #define ARLAN_TOGGLE_END(dev)\
183 {((struct arlan_private *) dev->priv)->under_toggle=0;}
184 #define ARLAN_UNDER_TOGGLE(dev)\
185 (((struct arlan_private *) dev->priv)->under_toggle)
186
187
188
arlan_drop_tx(struct net_device * dev)189 static inline int arlan_drop_tx(struct net_device *dev)
190 {
191 struct arlan_private *priv = ((struct arlan_private *) dev->priv);
192
193 priv->stats.tx_errors++;
194 if (priv->Conf->tx_delay_ms)
195 {
196 priv->tx_done_delayed = jiffies + priv->Conf->tx_delay_ms * HZ / 1000 + 1;
197 }
198 else
199 {
200 priv->waiting_command_mask &= ~ARLAN_COMMAND_TX;
201 TXHEAD(dev).offset = 0;
202 TXTAIL(dev).offset = 0;
203 priv->txLast = 0;
204 priv->txOffset = 0;
205 priv->bad = 0;
206 if (!priv->under_reset && !priv->under_config)
207 netif_wake_queue (dev);
208 }
209 return 1;
210 };
211
212
arlan_command(struct net_device * dev,int command_p)213 int arlan_command(struct net_device *dev, int command_p)
214 {
215
216 volatile struct arlan_shmem *arlan = ((struct arlan_private *) dev->priv)->card;
217 struct arlan_conf_stru *conf = ((struct arlan_private *) dev->priv)->Conf;
218 struct arlan_private *priv = (struct arlan_private *) dev->priv;
219 int udelayed = 0;
220 int i = 0;
221 long long time_mks = arlan_time();
222
223 ARLAN_DEBUG_ENTRY("arlan_command");
224
225 if (priv->card_polling_interval)
226 priv->card_polling_interval = 1;
227
228 if (arlan_debug & ARLAN_DEBUG_CHAIN_LOCKS)
229 printk(KERN_DEBUG "arlan_command, %lx lock %lx commandByte %x waiting %x incoming %x \n",
230 jiffies, priv->command_lock, READSHMB(arlan->commandByte),
231 priv->waiting_command_mask, command_p);
232
233 priv->waiting_command_mask |= command_p;
234
235 if (priv->waiting_command_mask & ARLAN_COMMAND_RESET)
236 if (jiffies - priv->lastReset < 5 * HZ)
237 priv->waiting_command_mask &= ~ARLAN_COMMAND_RESET;
238
239 if (priv->waiting_command_mask & ARLAN_COMMAND_INT_ACK)
240 {
241 arlan_interrupt_ack(dev);
242 priv->waiting_command_mask &= ~ARLAN_COMMAND_INT_ACK;
243 }
244 if (priv->waiting_command_mask & ARLAN_COMMAND_INT_ENABLE)
245 {
246 setInterruptEnable(dev);
247 priv->waiting_command_mask &= ~ARLAN_COMMAND_INT_ENABLE;
248 }
249
250 /* Card access serializing lock */
251
252 if (test_and_set_bit(0, (void *) &priv->command_lock))
253 {
254 if (arlan_debug & ARLAN_DEBUG_CHAIN_LOCKS)
255 printk(KERN_DEBUG "arlan_command: entered when command locked \n");
256 goto command_busy_end;
257 }
258 /* Check cards status and waiting */
259
260 if (priv->waiting_command_mask & (ARLAN_COMMAND_LONG_WAIT_NOW | ARLAN_COMMAND_WAIT_NOW))
261 {
262 while (priv->waiting_command_mask & (ARLAN_COMMAND_LONG_WAIT_NOW | ARLAN_COMMAND_WAIT_NOW))
263 {
264 if (READSHMB(arlan->resetFlag) ||
265 READSHMB(arlan->commandByte)) /* ||
266 (readControlRegister(dev) & ARLAN_ACCESS))
267 */
268 udelay(40);
269 else
270 priv->waiting_command_mask &= ~(ARLAN_COMMAND_LONG_WAIT_NOW | ARLAN_COMMAND_WAIT_NOW);
271
272 udelayed++;
273
274 if (priv->waiting_command_mask & ARLAN_COMMAND_LONG_WAIT_NOW)
275 {
276 if (udelayed * 40 > 1000000)
277 {
278 printk(KERN_ERR "%s long wait too long \n", dev->name);
279 priv->waiting_command_mask |= ARLAN_COMMAND_RESET;
280 break;
281 }
282 }
283 else if (priv->waiting_command_mask & ARLAN_COMMAND_WAIT_NOW)
284 {
285 if (udelayed * 40 > 1000)
286 {
287 printk(KERN_ERR "%s short wait too long \n", dev->name);
288 goto bad_end;
289 }
290 }
291 }
292 }
293 else
294 {
295 i = 0;
296 while ((READSHMB(arlan->resetFlag) ||
297 READSHMB(arlan->commandByte)) &&
298 conf->pre_Command_Wait > (i++) * 10)
299 udelay(10);
300
301
302 if ((READSHMB(arlan->resetFlag) ||
303 READSHMB(arlan->commandByte)) &&
304 !(priv->waiting_command_mask & ARLAN_COMMAND_RESET))
305 {
306 goto card_busy_end;
307 }
308 }
309 if (priv->waiting_command_mask & ARLAN_COMMAND_RESET)
310 priv->under_reset = 1;
311 if (priv->waiting_command_mask & ARLAN_COMMAND_CONF)
312 priv->under_config = 1;
313
314 /* Issuing command */
315 arlan_lock_card_access(dev);
316 if (priv->waiting_command_mask & ARLAN_COMMAND_POWERUP)
317 {
318 // if (readControlRegister(dev) & (ARLAN_ACCESS && ARLAN_POWER))
319 setPowerOn(dev);
320 arlan_interrupt_lancpu(dev);
321 priv->waiting_command_mask &= ~ARLAN_COMMAND_POWERUP;
322 priv->waiting_command_mask |= ARLAN_COMMAND_RESET;
323 priv->card_polling_interval = HZ / 10;
324 }
325 else if (priv->waiting_command_mask & ARLAN_COMMAND_ACTIVATE)
326 {
327 WRITESHMB(arlan->commandByte, ARLAN_COM_ACTIVATE);
328 arlan_interrupt_lancpu(dev);
329 priv->waiting_command_mask &= ~ARLAN_COMMAND_ACTIVATE;
330 priv->card_polling_interval = HZ / 10;
331 }
332 else if (priv->waiting_command_mask & ARLAN_COMMAND_RX_ABORT)
333 {
334 if (priv->rx_command_given)
335 {
336 WRITESHMB(arlan->commandByte, ARLAN_COM_RX_ABORT);
337 arlan_interrupt_lancpu(dev);
338 priv->rx_command_given = 0;
339 }
340 priv->waiting_command_mask &= ~ARLAN_COMMAND_RX_ABORT;
341 priv->card_polling_interval = 1;
342 }
343 else if (priv->waiting_command_mask & ARLAN_COMMAND_TX_ABORT)
344 {
345 if (priv->tx_command_given)
346 {
347 WRITESHMB(arlan->commandByte, ARLAN_COM_TX_ABORT);
348 arlan_interrupt_lancpu(dev);
349 priv->tx_command_given = 0;
350 }
351 priv->waiting_command_mask &= ~ARLAN_COMMAND_TX_ABORT;
352 priv->card_polling_interval = 1;
353 }
354 else if (priv->waiting_command_mask & ARLAN_COMMAND_RESET)
355 {
356 priv->under_reset=1;
357 netif_stop_queue (dev);
358
359 arlan_drop_tx(dev);
360 if (priv->tx_command_given || priv->rx_command_given)
361 {
362 printk(KERN_ERR "%s: Reset under tx or rx command \n", dev->name);
363 };
364 netif_stop_queue (dev);
365 if (arlan_debug & ARLAN_DEBUG_RESET)
366 printk(KERN_ERR "%s: Doing chip reset\n", dev->name);
367 priv->lastReset = jiffies;
368 WRITESHM(arlan->commandByte, 0, u_char);
369 /* hold card in reset state */
370 setHardwareReset(dev);
371 /* set reset flag and then release reset */
372 WRITESHM(arlan->resetFlag, 0xff, u_char);
373 clearChannelAttention(dev);
374 clearHardwareReset(dev);
375 priv->numResets++;
376 priv->card_polling_interval = HZ / 4;
377 priv->waiting_command_mask &= ~ARLAN_COMMAND_RESET;
378 priv->waiting_command_mask |= ARLAN_COMMAND_INT_RACK;
379 // priv->waiting_command_mask |= ARLAN_COMMAND_INT_RENABLE;
380 // priv->waiting_command_mask |= ARLAN_COMMAND_RX;
381 }
382 else if (priv->waiting_command_mask & ARLAN_COMMAND_INT_RACK)
383 {
384 clearHardwareReset(dev);
385 clearClearInterrupt(dev);
386 setClearInterrupt(dev);
387 setInterruptEnable(dev);
388 priv->waiting_command_mask &= ~ARLAN_COMMAND_INT_RACK;
389 priv->waiting_command_mask |= ARLAN_COMMAND_CONF;
390 priv->under_config = 1;
391 priv->under_reset = 0;
392 }
393 else if (priv->waiting_command_mask & ARLAN_COMMAND_INT_RENABLE)
394 {
395 setInterruptEnable(dev);
396 priv->waiting_command_mask &= ~ARLAN_COMMAND_INT_RENABLE;
397 }
398 else if (priv->waiting_command_mask & ARLAN_COMMAND_CONF)
399 {
400 if (priv->tx_command_given || priv->rx_command_given)
401 {
402 printk(KERN_ERR "%s: Reset under tx or rx command \n", dev->name);
403 }
404 arlan_drop_tx(dev);
405 setInterruptEnable(dev);
406 arlan_hw_config(dev);
407 arlan_interrupt_lancpu(dev);
408 priv->waiting_command_mask &= ~ARLAN_COMMAND_CONF;
409 priv->card_polling_interval = HZ / 10;
410 // priv->waiting_command_mask |= ARLAN_COMMAND_INT_RACK;
411 // priv->waiting_command_mask |= ARLAN_COMMAND_INT_ENABLE;
412 priv->waiting_command_mask |= ARLAN_COMMAND_CONF_WAIT;
413 }
414 else if (priv->waiting_command_mask & ARLAN_COMMAND_CONF_WAIT)
415 {
416 if (READSHMB(arlan->configuredStatusFlag) != 0 &&
417 READSHMB(arlan->diagnosticInfo) == 0xff)
418 {
419 priv->waiting_command_mask &= ~ARLAN_COMMAND_CONF_WAIT;
420 priv->waiting_command_mask |= ARLAN_COMMAND_RX;
421 priv->waiting_command_mask |= ARLAN_COMMAND_TBUSY_CLEAR;
422 priv->card_polling_interval = HZ / 10;
423 priv->tx_command_given = 0;
424 priv->under_config = 0;
425 }
426 else
427 {
428 priv->card_polling_interval = 1;
429 if (arlan_debug & ARLAN_DEBUG_TIMING)
430 printk(KERN_ERR "configure delayed \n");
431 }
432 }
433 else if (priv->waiting_command_mask & ARLAN_COMMAND_RX)
434 {
435 if (!registrationBad(dev))
436 {
437 setInterruptEnable(dev);
438 memset_io((void *) arlan->commandParameter, 0, 0xf);
439 WRITESHMB(arlan->commandByte, ARLAN_COM_INT | ARLAN_COM_RX_ENABLE);
440 WRITESHMB(arlan->commandParameter[0], conf->rxParameter);
441 arlan_interrupt_lancpu(dev);
442 priv->rx_command_given = 0; // mnjah, bad
443 priv->last_rx_time = arlan_time();
444 priv->waiting_command_mask &= ~ARLAN_COMMAND_RX;
445 priv->card_polling_interval = 1;
446 }
447 else
448 priv->card_polling_interval = 2;
449 }
450 else if (priv->waiting_command_mask & ARLAN_COMMAND_TBUSY_CLEAR)
451 {
452 if ( !registrationBad(dev) &&
453 (netif_queue_stopped(dev) || !netif_running(dev)) )
454 {
455 priv->waiting_command_mask &= ~ARLAN_COMMAND_TBUSY_CLEAR;
456 netif_wake_queue (dev);
457 };
458 }
459 else if (priv->waiting_command_mask & ARLAN_COMMAND_TX)
460 {
461 if (!test_and_set_bit(0, (void *) &priv->tx_command_given))
462 {
463 if ((time_mks - priv->last_tx_time > conf->rx_tweak1) ||
464 (time_mks - priv->last_rx_int_ack_time < conf->rx_tweak2))
465 {
466 setInterruptEnable(dev);
467 memset_io((void *) arlan->commandParameter, 0, 0xf);
468 WRITESHMB(arlan->commandByte, ARLAN_COM_TX_ENABLE | ARLAN_COM_INT);
469 memcpy_toio((void *) arlan->commandParameter, &TXLAST(dev), 14);
470 // for ( i=1 ; i < 15 ; i++) printk("%02x:",READSHMB(arlan->commandParameter[i]));
471 priv->last_command_was_rx = 0;
472 priv->tx_last_sent = jiffies;
473 arlan_interrupt_lancpu(dev);
474 priv->last_tx_time = arlan_time();
475 priv->tx_command_given = 1;
476 priv->waiting_command_mask &= ~ARLAN_COMMAND_TX;
477 priv->card_polling_interval = 1;
478 }
479 else
480 {
481 priv->tx_command_given = 0;
482 priv->card_polling_interval = 1;
483 }
484 }
485 else if (arlan_debug & ARLAN_DEBUG_CHAIN_LOCKS)
486 printk(KERN_ERR "tx command when tx chain locked \n");
487 }
488 else if (priv->waiting_command_mask & ARLAN_COMMAND_NOOPINT)
489 {
490 {
491 WRITESHMB(arlan->commandByte, ARLAN_COM_NOP | ARLAN_COM_INT);
492 }
493 arlan_interrupt_lancpu(dev);
494 priv->waiting_command_mask &= ~ARLAN_COMMAND_NOOPINT;
495 priv->card_polling_interval = HZ / 3;
496 }
497 else if (priv->waiting_command_mask & ARLAN_COMMAND_NOOP)
498 {
499 WRITESHMB(arlan->commandByte, ARLAN_COM_NOP);
500 arlan_interrupt_lancpu(dev);
501 priv->waiting_command_mask &= ~ARLAN_COMMAND_NOOP;
502 priv->card_polling_interval = HZ / 3;
503 }
504 else if (priv->waiting_command_mask & ARLAN_COMMAND_SLOW_POLL)
505 {
506 WRITESHMB(arlan->commandByte, ARLAN_COM_GOTO_SLOW_POLL);
507 arlan_interrupt_lancpu(dev);
508 priv->waiting_command_mask &= ~ARLAN_COMMAND_SLOW_POLL;
509 priv->card_polling_interval = HZ / 3;
510 }
511 else if (priv->waiting_command_mask & ARLAN_COMMAND_POWERDOWN)
512 {
513 setPowerOff(dev);
514 if (arlan_debug & ARLAN_DEBUG_CARD_STATE)
515 printk(KERN_WARNING "%s: Arlan Going Standby\n", dev->name);
516 priv->waiting_command_mask &= ~ARLAN_COMMAND_POWERDOWN;
517 priv->card_polling_interval = 3 * HZ;
518 }
519 arlan_unlock_card_access(dev);
520 for (i = 0; READSHMB(arlan->commandByte) && i < 20; i++)
521 udelay(10);
522 if (READSHMB(arlan->commandByte))
523 if (arlan_debug & ARLAN_DEBUG_CARD_STATE)
524 printk(KERN_ERR "card busy leaving command %x \n", priv->waiting_command_mask);
525
526 priv->command_lock = 0;
527 ARLAN_DEBUG_EXIT("arlan_command");
528 priv->last_command_buff_free_time = jiffies;
529 return 0;
530
531 card_busy_end:
532 if (jiffies - priv->last_command_buff_free_time > HZ)
533 priv->waiting_command_mask |= ARLAN_COMMAND_CLEAN_AND_RESET;
534
535 if (arlan_debug & ARLAN_DEBUG_CARD_STATE)
536 printk(KERN_ERR "%s arlan_command card busy end \n", dev->name);
537 priv->command_lock = 0;
538 ARLAN_DEBUG_EXIT("arlan_command");
539 return 1;
540
541 bad_end:
542 printk(KERN_ERR "%s arlan_command bad end \n", dev->name);
543
544 priv->command_lock = 0;
545 ARLAN_DEBUG_EXIT("arlan_command");
546
547 return -1;
548
549 command_busy_end:
550 if (arlan_debug & ARLAN_DEBUG_CARD_STATE)
551 printk(KERN_ERR "%s arlan_command command busy end \n", dev->name);
552 ARLAN_DEBUG_EXIT("arlan_command");
553 return 2;
554
555 };
556
arlan_command_process(struct net_device * dev)557 static inline void arlan_command_process(struct net_device *dev)
558 {
559 struct arlan_private *priv = ((struct arlan_private *) dev->priv);
560
561 int times = 0;
562 while (priv->waiting_command_mask && times < 8)
563 {
564 if (priv->waiting_command_mask)
565 {
566 if (arlan_command(dev, 0))
567 break;
568 times++;
569 }
570 /* if long command, we wont repeat trying */ ;
571 if (priv->card_polling_interval > 1)
572 break;
573 times++;
574 }
575 }
576
577
arlan_retransmit_now(struct net_device * dev)578 static inline void arlan_retransmit_now(struct net_device *dev)
579 {
580 struct arlan_private *priv = ((struct arlan_private *) dev->priv);
581
582
583 ARLAN_DEBUG_ENTRY("arlan_retransmit_now");
584 if (TXLAST(dev).offset == 0)
585 {
586 if (TXHEAD(dev).offset)
587 {
588 priv->txLast = 0;
589 IFDEBUG(ARLAN_DEBUG_TX_CHAIN) printk(KERN_DEBUG "TX buff switch to head \n");
590
591 }
592 else if (TXTAIL(dev).offset)
593 {
594 IFDEBUG(ARLAN_DEBUG_TX_CHAIN) printk(KERN_DEBUG "TX buff switch to tail \n");
595 priv->txLast = 1;
596 }
597 else
598 IFDEBUG(ARLAN_DEBUG_TX_CHAIN) printk(KERN_ERR "ReTransmit buff empty");
599 priv->txOffset = 0;
600 netif_wake_queue (dev);
601 return;
602
603 }
604 arlan_command(dev, ARLAN_COMMAND_TX);
605
606 priv->nof_tx++;
607
608 priv->Conf->driverRetransmissions++;
609 priv->retransmissions++;
610
611 IFDEBUG(ARLAN_DEBUG_TX_CHAIN) printk("Retransmit %d bytes \n", TXLAST(dev).length);
612
613 ARLAN_DEBUG_EXIT("arlan_retransmit_now");
614 }
615
616
617
arlan_registration_timer(unsigned long data)618 static void arlan_registration_timer(unsigned long data)
619 {
620 struct net_device *dev = (struct net_device *) data;
621 struct arlan_private *priv = (struct arlan_private *) dev->priv;
622
623 int lostTime = ((int) (jiffies - priv->registrationLastSeen)) * 1000 / HZ;
624 int bh_mark_needed = 0;
625 int next_tick = 1;
626
627
628 priv->timer_chain_active = 1;
629
630
631 if (registrationBad(dev))
632 {
633 //debug=100;
634 priv->registrationLostCount++;
635 if (lostTime > 7000 && lostTime < 7200)
636 {
637 printk(KERN_NOTICE "%s registration Lost \n", dev->name);
638 }
639 if (lostTime / priv->reRegisterExp > 2000)
640 arlan_command(dev, ARLAN_COMMAND_CLEAN_AND_CONF);
641 if (lostTime / (priv->reRegisterExp) > 3500)
642 arlan_command(dev, ARLAN_COMMAND_CLEAN_AND_RESET);
643 if (priv->reRegisterExp < 400)
644 priv->reRegisterExp += 2;
645 if (lostTime > 7200)
646 {
647 next_tick = HZ;
648 arlan_command(dev, ARLAN_COMMAND_CLEAN_AND_RESET);
649 }
650 }
651 else
652 {
653 if (priv->Conf->registrationMode && lostTime > 10000 &&
654 priv->registrationLostCount)
655 {
656 printk(KERN_NOTICE "%s registration is back after %d milliseconds\n", dev->name,
657 ((int) (jiffies - priv->registrationLastSeen) * 1000) / HZ);
658 }
659 priv->registrationLastSeen = jiffies;
660 priv->registrationLostCount = 0;
661 priv->reRegisterExp = 1;
662 if (!netif_running(dev) )
663 netif_wake_queue(dev);
664 if (priv->tx_last_sent > priv->tx_last_cleared &&
665 jiffies - priv->tx_last_sent > 5*HZ ){
666 arlan_command(dev, ARLAN_COMMAND_CLEAN_AND_RESET);
667 priv->tx_last_cleared = jiffies;
668 };
669 }
670
671
672 if (!registrationBad(dev) && priv->ReTransmitRequested)
673 {
674 IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
675 printk(KERN_ERR "Retransmit from timer \n");
676 priv->ReTransmitRequested = 0;
677 arlan_retransmit_now(dev);
678 }
679 if (!registrationBad(dev) &&
680 time_after(jiffies, priv->tx_done_delayed) &&
681 priv->tx_done_delayed != 0)
682 {
683 TXLAST(dev).offset = 0;
684 if (priv->txLast)
685 priv->txLast = 0;
686 else if (TXTAIL(dev).offset)
687 priv->txLast = 1;
688 if (TXLAST(dev).offset)
689 {
690 arlan_retransmit_now(dev);
691 dev->trans_start = jiffies;
692 }
693 if (!(TXHEAD(dev).offset && TXTAIL(dev).offset))
694 {
695 priv->txOffset = 0;
696 netif_wake_queue (dev);
697 }
698 priv->tx_done_delayed = 0;
699 bh_mark_needed = 1;
700 }
701 if (bh_mark_needed)
702 {
703 priv->txOffset = 0;
704 netif_wake_queue (dev);
705 }
706 arlan_process_interrupt(dev);
707
708 if (next_tick < priv->card_polling_interval)
709 next_tick = priv->card_polling_interval;
710
711 priv->timer_chain_active = 0;
712 priv->timer.expires = jiffies + next_tick;
713
714 add_timer(&priv->timer);
715 }
716
717
718 #ifdef ARLAN_DEBUGGING
719
arlan_print_registers(struct net_device * dev,int line)720 static void arlan_print_registers(struct net_device *dev, int line)
721 {
722 volatile struct arlan_shmem *arlan = ((struct arlan_private *) dev->priv)->card;
723
724 u_char hostcpuLock, lancpuLock, controlRegister, cntrlRegImage,
725 txStatus, rxStatus, interruptInProgress, commandByte;
726
727
728 ARLAN_DEBUG_ENTRY("arlan_print_registers");
729 READSHM(interruptInProgress, arlan->interruptInProgress, u_char);
730 READSHM(hostcpuLock, arlan->hostcpuLock, u_char);
731 READSHM(lancpuLock, arlan->lancpuLock, u_char);
732 READSHM(controlRegister, arlan->controlRegister, u_char);
733 READSHM(cntrlRegImage, arlan->cntrlRegImage, u_char);
734 READSHM(txStatus, arlan->txStatus, u_char);
735 READSHM(rxStatus, arlan->rxStatus, u_char);
736 READSHM(commandByte, arlan->commandByte, u_char);
737
738 printk(KERN_WARNING "line %04d IP %02x HL %02x LL %02x CB %02x CR %02x CRI %02x TX %02x RX %02x\n",
739 line, interruptInProgress, hostcpuLock, lancpuLock, commandByte,
740 controlRegister, cntrlRegImage, txStatus, rxStatus);
741
742 ARLAN_DEBUG_EXIT("arlan_print_registers");
743 }
744 #endif
745
746
arlan_hw_tx(struct net_device * dev,char * buf,int length)747 static int arlan_hw_tx(struct net_device *dev, char *buf, int length)
748 {
749 int i;
750
751 struct arlan_private *priv = (struct arlan_private *) dev->priv;
752 volatile struct arlan_shmem *arlan = priv->card;
753 struct arlan_conf_stru *conf = priv->Conf;
754
755 int tailStarts = 0x800;
756 int headEnds = 0x0;
757
758
759 ARLAN_DEBUG_ENTRY("arlan_hw_tx");
760 if (TXHEAD(dev).offset)
761 headEnds = (((TXHEAD(dev).offset + TXHEAD(dev).length - (((int) arlan->txBuffer) - ((int) arlan))) / 64) + 1) * 64;
762 if (TXTAIL(dev).offset)
763 tailStarts = 0x800 - (((TXTAIL(dev).offset - (((int) arlan->txBuffer) - ((int) arlan))) / 64) + 2) * 64;
764
765
766 if (!TXHEAD(dev).offset && length < tailStarts)
767 {
768 IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
769 printk(KERN_ERR "TXHEAD insert, tailStart %d\n", tailStarts);
770
771 TXHEAD(dev).offset =
772 (((int) arlan->txBuffer) - ((int) arlan));
773 TXHEAD(dev).length = length - ARLAN_FAKE_HDR_LEN;
774 for (i = 0; i < 6; i++)
775 TXHEAD(dev).dest[i] = buf[i];
776 TXHEAD(dev).clear = conf->txClear;
777 TXHEAD(dev).retries = conf->txRetries; /* 0 is use default */
778 TXHEAD(dev).routing = conf->txRouting;
779 TXHEAD(dev).scrambled = conf->txScrambled;
780 memcpy_toio(((char *) arlan + TXHEAD(dev).offset), buf + ARLAN_FAKE_HDR_LEN, TXHEAD(dev).length);
781 }
782 else if (!TXTAIL(dev).offset && length < (0x800 - headEnds))
783 {
784 IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
785 printk(KERN_ERR "TXTAIL insert, headEnd %d\n", headEnds);
786
787 TXTAIL(dev).offset =
788 (((int) arlan->txBuffer) - ((int) arlan)) + 0x800 - (length / 64 + 2) * 64;
789 TXTAIL(dev).length = length - ARLAN_FAKE_HDR_LEN;
790 for (i = 0; i < 6; i++)
791 TXTAIL(dev).dest[i] = buf[i];
792 TXTAIL(dev).clear = conf->txClear;
793 TXTAIL(dev).retries = conf->txRetries;
794 TXTAIL(dev).routing = conf->txRouting;
795 TXTAIL(dev).scrambled = conf->txScrambled;
796 memcpy_toio(((char *) arlan + TXTAIL(dev).offset), buf + ARLAN_FAKE_HDR_LEN, TXTAIL(dev).length);
797 }
798 else
799 {
800 netif_stop_queue (dev);
801 return -1;
802 IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
803 printk(KERN_ERR "TX TAIL & HEAD full, return, tailStart %d headEnd %d\n", tailStarts, headEnds);
804 }
805 priv->out_bytes += length;
806 priv->out_bytes10 += length;
807 if (conf->measure_rate < 1)
808 conf->measure_rate = 1;
809 if (jiffies - priv->out_time > conf->measure_rate * HZ)
810 {
811 conf->out_speed = priv->out_bytes / conf->measure_rate;
812 priv->out_bytes = 0;
813 priv->out_time = jiffies;
814 }
815 if (jiffies - priv->out_time10 > conf->measure_rate * HZ * 10)
816 {
817 conf->out_speed10 = priv->out_bytes10 / (10 * conf->measure_rate);
818 priv->out_bytes10 = 0;
819 priv->out_time10 = jiffies;
820 }
821 if (TXHEAD(dev).offset && TXTAIL(dev).offset)
822 {
823 netif_stop_queue (dev);
824 return 0;
825 }
826 else
827 netif_start_queue (dev);
828
829
830 IFDEBUG(ARLAN_DEBUG_HEADER_DUMP)
831 printk(KERN_WARNING "%s Transmit t %2x:%2x:%2x:%2x:%2x:%2x f %2x:%2x:%2x:%2x:%2x:%2x \n", dev->name,
832 (unsigned char) buf[0], (unsigned char) buf[1], (unsigned char) buf[2], (unsigned char) buf[3],
833 (unsigned char) buf[4], (unsigned char) buf[5], (unsigned char) buf[6], (unsigned char) buf[7],
834 (unsigned char) buf[8], (unsigned char) buf[9], (unsigned char) buf[10], (unsigned char) buf[11]);
835
836 IFDEBUG(ARLAN_DEBUG_TX_CHAIN) printk(KERN_ERR "TX command prepare for buffer %d\n", priv->txLast);
837
838 arlan_command(dev, ARLAN_COMMAND_TX);
839
840 priv->last_command_was_rx = 0;
841 priv->tx_last_sent = jiffies;
842 priv->nof_tx++;
843
844 IFDEBUG(ARLAN_DEBUG_TX_CHAIN) printk("%s TX Qued %d bytes \n", dev->name, length);
845
846 ARLAN_DEBUG_EXIT("arlan_hw_tx");
847
848 return 0;
849 }
850
851
arlan_hw_config(struct net_device * dev)852 static int arlan_hw_config(struct net_device *dev)
853 {
854 volatile struct arlan_shmem *arlan = ((struct arlan_private *) dev->priv)->card;
855 struct arlan_conf_stru *conf = ((struct arlan_private *) dev->priv)->Conf;
856 struct arlan_private *priv = (struct arlan_private *) dev->priv;
857
858 ARLAN_DEBUG_ENTRY("arlan_hw_config");
859
860 printk(KERN_NOTICE "%s arlan configure called \n", dev->name);
861 if (arlan_EEPROM_bad)
862 printk(KERN_NOTICE "arlan configure with eeprom bad option \n");
863
864
865 WRITESHM(arlan->spreadingCode, conf->spreadingCode, u_char);
866 WRITESHM(arlan->channelSet, conf->channelSet, u_char);
867
868 if (arlan_EEPROM_bad)
869 WRITESHM(arlan->defaultChannelSet, conf->channelSet, u_char);
870
871 WRITESHM(arlan->channelNumber, conf->channelNumber, u_char);
872
873 WRITESHM(arlan->scramblingDisable, conf->scramblingDisable, u_char);
874 WRITESHM(arlan->txAttenuation, conf->txAttenuation, u_char);
875
876 WRITESHM(arlan->systemId, conf->systemId, u_int);
877
878 WRITESHM(arlan->maxRetries, conf->maxRetries, u_char);
879 WRITESHM(arlan->receiveMode, conf->receiveMode, u_char);
880 WRITESHM(arlan->priority, conf->priority, u_char);
881 WRITESHM(arlan->rootOrRepeater, conf->rootOrRepeater, u_char);
882 WRITESHM(arlan->SID, conf->SID, u_int);
883
884 WRITESHM(arlan->registrationMode, conf->registrationMode, u_char);
885
886 WRITESHM(arlan->registrationFill, conf->registrationFill, u_char);
887 WRITESHM(arlan->localTalkAddress, conf->localTalkAddress, u_char);
888 WRITESHM(arlan->codeFormat, conf->codeFormat, u_char);
889 WRITESHM(arlan->numChannels, conf->numChannels, u_char);
890 WRITESHM(arlan->channel1, conf->channel1, u_char);
891 WRITESHM(arlan->channel2, conf->channel2, u_char);
892 WRITESHM(arlan->channel3, conf->channel3, u_char);
893 WRITESHM(arlan->channel4, conf->channel4, u_char);
894 WRITESHM(arlan->radioNodeId, conf->radioNodeId, u_short);
895 WRITESHM(arlan->SID, conf->SID, u_int);
896 WRITESHM(arlan->waitTime, conf->waitTime, u_short);
897 WRITESHM(arlan->lParameter, conf->lParameter, u_short);
898 memcpy_toio(&(arlan->_15), &(conf->_15), 3);
899 WRITESHM(arlan->_15, conf->_15, u_short);
900 WRITESHM(arlan->headerSize, conf->headerSize, u_short);
901 if (arlan_EEPROM_bad)
902 WRITESHM(arlan->hardwareType, conf->hardwareType, u_char);
903 WRITESHM(arlan->radioType, conf->radioType, u_char);
904 if (arlan_EEPROM_bad)
905 WRITESHM(arlan->radioModule, conf->radioType, u_char);
906
907 memcpy_toio(arlan->encryptionKey + keyStart, encryptionKey, 8);
908 memcpy_toio(arlan->name, conf->siteName, 16);
909
910 WRITESHMB(arlan->commandByte, ARLAN_COM_INT | ARLAN_COM_CONF); /* do configure */
911 memset_io(arlan->commandParameter, 0, 0xf); /* 0xf */
912 memset_io(arlan->commandParameter + 1, 0, 2);
913 if (conf->writeEEPROM)
914 {
915 memset_io(arlan->commandParameter, conf->writeEEPROM, 1);
916 // conf->writeEEPROM=0;
917 }
918 if (conf->registrationMode && conf->registrationInterrupts)
919 memset_io(arlan->commandParameter + 3, 1, 1);
920 else
921 memset_io(arlan->commandParameter + 3, 0, 1);
922
923 priv->irq_test_done = 0;
924
925 if (conf->tx_queue_len)
926 dev->tx_queue_len = conf->tx_queue_len;
927 udelay(100);
928
929 ARLAN_DEBUG_EXIT("arlan_hw_config");
930 return 0;
931 }
932
933
arlan_read_card_configuration(struct net_device * dev)934 static int arlan_read_card_configuration(struct net_device *dev)
935 {
936 u_char tlx415;
937 volatile struct arlan_shmem *arlan = ((struct arlan_private *) dev->priv)->card;
938 struct arlan_conf_stru *conf = ((struct arlan_private *) dev->priv)->Conf;
939
940 ARLAN_DEBUG_ENTRY("arlan_read_card_configuration");
941
942 if (radioNodeId == radioNodeIdUNKNOWN)
943 {
944 READSHM(conf->radioNodeId, arlan->radioNodeId, u_short);
945 }
946 else
947 conf->radioNodeId = radioNodeId;
948
949 if (SID == SIDUNKNOWN)
950 {
951 READSHM(conf->SID, arlan->SID, u_int);
952 }
953 else conf->SID = SID;
954
955 if (spreadingCode == spreadingCodeUNKNOWN)
956 {
957 READSHM(conf->spreadingCode, arlan->spreadingCode, u_char);
958 }
959 else
960 conf->spreadingCode = spreadingCode;
961
962 if (channelSet == channelSetUNKNOWN)
963 {
964 READSHM(conf->channelSet, arlan->channelSet, u_char);
965 }
966 else conf->channelSet = channelSet;
967
968 if (channelNumber == channelNumberUNKNOWN)
969 {
970 READSHM(conf->channelNumber, arlan->channelNumber, u_char);
971 }
972 else conf->channelNumber = channelNumber;
973
974 READSHM(conf->scramblingDisable, arlan->scramblingDisable, u_char);
975 READSHM(conf->txAttenuation, arlan->txAttenuation, u_char);
976
977 if (systemId == systemIdUNKNOWN)
978 {
979 READSHM(conf->systemId, arlan->systemId, u_int);
980 }
981 else conf->systemId = systemId;
982
983 READSHM(conf->maxDatagramSize, arlan->maxDatagramSize, u_short);
984 READSHM(conf->maxFrameSize, arlan->maxFrameSize, u_short);
985 READSHM(conf->maxRetries, arlan->maxRetries, u_char);
986 READSHM(conf->receiveMode, arlan->receiveMode, u_char);
987 READSHM(conf->priority, arlan->priority, u_char);
988 READSHM(conf->rootOrRepeater, arlan->rootOrRepeater, u_char);
989
990 if (SID == SIDUNKNOWN)
991 {
992 READSHM(conf->SID, arlan->SID, u_int);
993 }
994 else conf->SID = SID;
995
996 if (registrationMode == registrationModeUNKNOWN)
997 {
998 READSHM(conf->registrationMode, arlan->registrationMode, u_char);
999 }
1000 else conf->registrationMode = registrationMode;
1001
1002 READSHM(conf->registrationFill, arlan->registrationFill, u_char);
1003 READSHM(conf->localTalkAddress, arlan->localTalkAddress, u_char);
1004 READSHM(conf->codeFormat, arlan->codeFormat, u_char);
1005 READSHM(conf->numChannels, arlan->numChannels, u_char);
1006 READSHM(conf->channel1, arlan->channel1, u_char);
1007 READSHM(conf->channel2, arlan->channel2, u_char);
1008 READSHM(conf->channel3, arlan->channel3, u_char);
1009 READSHM(conf->channel4, arlan->channel4, u_char);
1010 READSHM(conf->waitTime, arlan->waitTime, u_short);
1011 READSHM(conf->lParameter, arlan->lParameter, u_short);
1012 READSHM(conf->_15, arlan->_15, u_short);
1013 READSHM(conf->headerSize, arlan->headerSize, u_short);
1014 READSHM(conf->hardwareType, arlan->hardwareType, u_char);
1015 READSHM(conf->radioType, arlan->radioModule, u_char);
1016
1017 if (conf->radioType == 0)
1018 conf->radioType = 0xc;
1019
1020 WRITESHM(arlan->configStatus, 0xA5, u_char);
1021 READSHM(tlx415, arlan->configStatus, u_char);
1022
1023 if (tlx415 != 0xA5)
1024 printk(KERN_INFO "%s tlx415 chip \n", dev->name);
1025
1026 conf->txClear = 0;
1027 conf->txRetries = 1;
1028 conf->txRouting = 1;
1029 conf->txScrambled = 0;
1030 conf->rxParameter = 1;
1031 conf->txTimeoutMs = 4000;
1032 conf->waitCardTimeout = 100000;
1033 conf->receiveMode = ARLAN_RCV_CLEAN;
1034 memcpy_fromio(conf->siteName, arlan->name, 16);
1035 conf->siteName[16] = '\0';
1036 conf->retries = retries;
1037 conf->tx_delay_ms = tx_delay_ms;
1038 conf->async = async;
1039 conf->ReTransmitPacketMaxSize = 200;
1040 conf->waitReTransmitPacketMaxSize = 200;
1041 conf->txAckTimeoutMs = 900;
1042 conf->fastReTransCount = 3;
1043
1044 ARLAN_DEBUG_EXIT("arlan_read_card_configuration");
1045
1046 return 0;
1047 }
1048
1049
1050 static int lastFoundAt = 0xbe000;
1051
1052
1053 /*
1054 * This is the real probe routine. Linux has a history of friendly device
1055 * probes on the ISA bus. A good device probes avoids doing writes, and
1056 * verifies that the correct device exists and functions.
1057 */
1058
arlan_check_fingerprint(int memaddr)1059 static int __init arlan_check_fingerprint(int memaddr)
1060 {
1061 static char probeText[] = "TELESYSTEM SLW INC. ARLAN \0";
1062 char tempBuf[49];
1063 volatile struct arlan_shmem *arlan = (struct arlan_shmem *) memaddr;
1064
1065 ARLAN_DEBUG_ENTRY("arlan_check_fingerprint");
1066 if (check_mem_region(virt_to_phys((void *)memaddr),0x2000 )){
1067 // printk(KERN_WARNING "arlan: memory region %lx excluded from probing \n",virt_to_phys((void*)memaddr));
1068 return -ENODEV;
1069 };
1070 memcpy_fromio(tempBuf, arlan->textRegion, 29);
1071 tempBuf[30] = 0;
1072
1073 /* check for card at this address */
1074 if (0 != strncmp(tempBuf, probeText, 29)){
1075 // not release_mem_region(virt_to_phys((void*)memaddr),0x2000);
1076 return -ENODEV;
1077 }
1078
1079 // printk(KERN_INFO "arlan found at 0x%x \n",memaddr);
1080 ARLAN_DEBUG_EXIT("arlan_check_fingerprint");
1081
1082 return 0;
1083
1084
1085 }
1086
arlan_probe_everywhere(struct net_device * dev)1087 static int __init arlan_probe_everywhere(struct net_device *dev)
1088 {
1089 int m;
1090 int probed = 0;
1091 int found = 0;
1092
1093 SET_MODULE_OWNER(dev);
1094
1095 ARLAN_DEBUG_ENTRY("arlan_probe_everywhere");
1096 if (mem != 0 && numDevices == 1) /* Check a single specified location. */
1097 {
1098 if (arlan_probe_here(dev, (int) phys_to_virt( mem) ) == 0)
1099 return 0;
1100 else
1101 return -ENODEV;
1102 }
1103 for (m = (int)phys_to_virt(lastFoundAt) + 0x2000; m <= (int)phys_to_virt(0xDE000); m += 0x2000)
1104 {
1105 if (arlan_probe_here(dev, m) == 0)
1106 {
1107 found++;
1108 lastFoundAt = (int)virt_to_phys((void*)m);
1109 break;
1110 }
1111 probed++;
1112 }
1113 if (found == 0 && probed != 0)
1114 {
1115 if (lastFoundAt == 0xbe000)
1116 printk(KERN_ERR "arlan: No Arlan devices found \n");
1117 return -ENODEV;
1118 }
1119 else
1120 return 0;
1121
1122 ARLAN_DEBUG_EXIT("arlan_probe_everywhere");
1123
1124 return -ENODEV;
1125 }
1126
arlan_find_devices(void)1127 static int __init arlan_find_devices(void)
1128 {
1129 int m;
1130 int found = 0;
1131
1132 ARLAN_DEBUG_ENTRY("arlan_find_devices");
1133 if (mem != 0 && numDevices == 1) /* Check a single specified location. */
1134 return 1;
1135 for (m =(int) phys_to_virt(0xc0000); m <=(int) phys_to_virt(0xDE000); m += 0x2000)
1136 {
1137 if (arlan_check_fingerprint(m) == 0)
1138 found++;
1139 }
1140 ARLAN_DEBUG_EXIT("arlan_find_devices");
1141
1142 return found;
1143 }
1144
1145
arlan_change_mtu(struct net_device * dev,int new_mtu)1146 static int arlan_change_mtu(struct net_device *dev, int new_mtu)
1147 {
1148 struct arlan_conf_stru *conf = ((struct arlan_private *) dev->priv)->Conf;
1149
1150 ARLAN_DEBUG_ENTRY("arlan_change_mtu");
1151 if (new_mtu > 2032)
1152 return -EINVAL;
1153 dev->mtu = new_mtu;
1154 if (new_mtu < 256)
1155 new_mtu = 256; /* cards book suggests 1600 */
1156 conf->maxDatagramSize = new_mtu;
1157 conf->maxFrameSize = new_mtu + 48;
1158
1159 arlan_command(dev, ARLAN_COMMAND_CLEAN_AND_CONF);
1160 printk(KERN_NOTICE "%s mtu changed to %d \n", dev->name, new_mtu);
1161
1162 ARLAN_DEBUG_EXIT("arlan_change_mtu");
1163
1164 return 0;
1165 }
1166
arlan_mac_addr(struct net_device * dev,void * p)1167 static int arlan_mac_addr(struct net_device *dev, void *p)
1168 {
1169 struct sockaddr *addr = p;
1170
1171
1172 ARLAN_DEBUG_ENTRY("arlan_mac_addr");
1173 return -EINVAL;
1174
1175 if (!netif_running(dev))
1176 return -EBUSY;
1177 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
1178
1179 ARLAN_DEBUG_EXIT("arlan_mac_addr");
1180 return 0;
1181 }
1182
1183
1184
1185
1186 static int __init
arlan_allocate_device(int num,struct net_device * devs)1187 arlan_allocate_device(int num, struct net_device *devs)
1188 {
1189
1190 struct net_device *dev;
1191
1192 ARLAN_DEBUG_ENTRY("arlan_allocate_device");
1193
1194 if (!devs)
1195 dev = init_etherdev(0, sizeof(struct arlan_private));
1196 else
1197 {
1198 dev = devs;
1199 dev->priv = kmalloc(sizeof(struct arlan_private), GFP_KERNEL);
1200 };
1201
1202 if (dev == NULL || dev->priv == NULL)
1203 {
1204 printk(KERN_CRIT "init_etherdev failed ");
1205 return 0;
1206 }
1207
1208 memset(dev->priv,0,sizeof(struct arlan_private));
1209
1210 ((struct arlan_private *) dev->priv)->conf =
1211 kmalloc(sizeof(struct arlan_shmem), GFP_KERNEL);
1212
1213 if (dev == NULL || dev->priv == NULL ||
1214 ((struct arlan_private *) dev->priv)->conf == NULL)
1215 {
1216 return 0;
1217 printk(KERN_CRIT " No memory at arlan_allocate_device \n");
1218 }
1219 /* Fill in the 'dev' fields. */
1220 dev->base_addr = 0;
1221 dev->mem_start = 0;
1222 dev->mem_end = 0;
1223 dev->mtu = 1500;
1224 dev->flags = 0; /* IFF_BROADCAST & IFF_MULTICAST & IFF_PROMISC; */
1225 dev->irq = 0;
1226 dev->dma = 0;
1227 dev->tx_queue_len = tx_queue_len;
1228 ether_setup(dev);
1229 dev->tx_queue_len = tx_queue_len;
1230 dev->open = arlan_open;
1231 dev->stop = arlan_close;
1232 dev->hard_start_xmit = arlan_tx;
1233 dev->get_stats = arlan_statistics;
1234 dev->set_multicast_list = arlan_set_multicast;
1235 dev->change_mtu = arlan_change_mtu;
1236 dev->set_mac_address = arlan_mac_addr;
1237 dev->tx_timeout = arlan_tx_timeout;
1238 dev->watchdog_timeo = 3*HZ;
1239
1240 ((struct arlan_private *) dev->priv)->irq_test_done = 0;
1241 arlan_device[num] = dev;
1242 ((struct arlan_private *) arlan_device[num]->priv)->Conf = &(arlan_conf[num]);
1243
1244 ((struct arlan_private *) dev->priv)->Conf->pre_Command_Wait = 40;
1245 ((struct arlan_private *) dev->priv)->Conf->rx_tweak1 = 30;
1246 ((struct arlan_private *) dev->priv)->Conf->rx_tweak2 = 0;
1247
1248 ARLAN_DEBUG_EXIT("arlan_allocate_device");
1249 return (int) dev;
1250 }
1251
1252
arlan_probe_here(struct net_device * dev,int memaddr)1253 static int __init arlan_probe_here(struct net_device *dev, int memaddr)
1254 {
1255 volatile struct arlan_shmem *arlan;
1256
1257 ARLAN_DEBUG_ENTRY("arlan_probe_here");
1258
1259 if (arlan_check_fingerprint(memaddr))
1260 return -ENODEV;
1261
1262 printk(KERN_NOTICE "%s: Arlan found at %x, \n ", dev->name, (int) virt_to_phys((void*)memaddr));
1263
1264 if (!arlan_allocate_device(arlans_found, dev))
1265 return -1;
1266
1267 ((struct arlan_private *) dev->priv)->card = (struct arlan_shmem *) memaddr;
1268 arlan = (void *) memaddr;
1269
1270 dev->mem_start = memaddr;
1271 dev->mem_end = memaddr + 0x1FFF;
1272
1273 if (dev->irq < 2)
1274 {
1275 READSHM(dev->irq, arlan->irqLevel, u_char);
1276 } else if (dev->irq == 2)
1277 dev->irq = 9;
1278
1279 arlan_read_card_configuration(dev);
1280
1281 ARLAN_DEBUG_EXIT("arlan_probe_here");
1282 return 0;
1283 }
1284
1285
1286
1287
arlan_open(struct net_device * dev)1288 static int arlan_open(struct net_device *dev)
1289 {
1290 struct arlan_private *priv = (struct arlan_private *) dev->priv;
1291 volatile struct arlan_shmem *arlan = priv->card;
1292 int ret = 0;
1293
1294 ARLAN_DEBUG_ENTRY("arlan_open");
1295
1296 if (dev->mem_start == 0)
1297 ret = arlan_probe_everywhere(dev);
1298 if (ret != 0)
1299 return ret;
1300
1301 arlan = ((struct arlan_private *) dev->priv)->card;
1302 ret = request_irq(dev->irq, &arlan_interrupt, 0, dev->name, dev);
1303 if (ret)
1304 {
1305 printk(KERN_ERR "%s: unable to get IRQ %d .\n",
1306 dev->name, dev->irq);
1307 return ret;
1308 }
1309
1310
1311 priv->bad = 0;
1312 priv->lastReset = 0;
1313 priv->reset = 0;
1314 priv->open_time = jiffies;
1315 memcpy_fromio(dev->dev_addr, arlan->lanCardNodeId, 6);
1316 memset(dev->broadcast, 0xff, 6);
1317 priv->txOffset = 0;
1318 dev->tx_queue_len = tx_queue_len;
1319 priv->interrupt_processing_active = 0;
1320 priv->command_lock = 0;
1321
1322 netif_start_queue (dev);
1323
1324 init_MUTEX(&priv->card_lock);
1325 myATOMIC_INIT(priv->card_users, 1); /* damn 2.0.33 */
1326 priv->registrationLostCount = 0;
1327 priv->registrationLastSeen = jiffies;
1328 priv->txLast = 0;
1329 priv->tx_command_given = 0;
1330 priv->rx_command_given = 0;
1331
1332 priv->reRegisterExp = 1;
1333 priv->nof_tx = 0;
1334 priv->nof_tx_ack = 0;
1335 priv->last_command_was_rx = 0;
1336 priv->tx_last_sent = jiffies - 1;
1337 priv->tx_last_cleared = jiffies;
1338 priv->Conf->writeEEPROM = 0;
1339 priv->Conf->registrationInterrupts = 1;
1340
1341 init_timer(&priv->timer);
1342 priv->timer.expires = jiffies + HZ / 10;
1343 priv->timer.data = (unsigned long) dev;
1344 priv->timer.function = &arlan_registration_timer; /* timer handler */
1345
1346 arlan_command(dev, ARLAN_COMMAND_POWERUP | ARLAN_COMMAND_LONG_WAIT_NOW);
1347 mdelay(200);
1348 add_timer(&priv->timer);
1349
1350 #ifdef CONFIG_PROC_FS
1351 #ifndef MODULE
1352 if (arlan_device[0])
1353 init_arlan_proc();
1354 #endif
1355 #endif
1356 ARLAN_DEBUG_EXIT("arlan_open");
1357 return 0;
1358 }
1359
1360
arlan_tx_timeout(struct net_device * dev)1361 static void arlan_tx_timeout (struct net_device *dev)
1362 {
1363 printk(KERN_ERR "%s: arlan transmit timed out, kernel decided\n", dev->name);
1364 /* Try to restart the adaptor. */
1365 arlan_command(dev, ARLAN_COMMAND_CLEAN_AND_RESET);
1366 // dev->trans_start = jiffies;
1367 // netif_start_queue (dev);
1368 }
1369
1370
arlan_tx(struct sk_buff * skb,struct net_device * dev)1371 static int arlan_tx(struct sk_buff *skb, struct net_device *dev)
1372 {
1373 struct arlan_private *priv = ((struct arlan_private *) dev->priv);
1374 short length;
1375 unsigned char *buf;
1376
1377 ARLAN_DEBUG_ENTRY("arlan_tx");
1378
1379 length = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
1380 buf = skb->data;
1381
1382 if (priv->txOffset + length + 0x12 > 0x800) {
1383 printk(KERN_ERR "TX RING overflow \n");
1384 netif_stop_queue (dev);
1385 }
1386
1387 if (arlan_hw_tx(dev, buf, length) == -1)
1388 goto bad_end;
1389
1390 dev->trans_start = jiffies;
1391
1392 dev_kfree_skb(skb);
1393
1394 arlan_process_interrupt(dev);
1395 priv->tx_chain_active = 0;
1396 ARLAN_DEBUG_EXIT("arlan_tx");
1397 return 0;
1398
1399 bad_end:
1400 arlan_process_interrupt(dev);
1401 priv->tx_chain_active = 0;
1402 netif_stop_queue (dev);
1403 ARLAN_DEBUG_EXIT("arlan_tx");
1404 return 1;
1405 }
1406
1407
DoNotReTransmitCrap(struct net_device * dev)1408 static inline int DoNotReTransmitCrap(struct net_device *dev)
1409 {
1410 struct arlan_private *priv = ((struct arlan_private *) dev->priv);
1411
1412 if (TXLAST(dev).length < priv->Conf->ReTransmitPacketMaxSize)
1413 return 1;
1414 return 0;
1415
1416 }
1417
DoNotWaitReTransmitCrap(struct net_device * dev)1418 static inline int DoNotWaitReTransmitCrap(struct net_device *dev)
1419 {
1420 struct arlan_private *priv = ((struct arlan_private *) dev->priv);
1421
1422 if (TXLAST(dev).length < priv->Conf->waitReTransmitPacketMaxSize)
1423 return 1;
1424 return 0;
1425 }
1426
arlan_queue_retransmit(struct net_device * dev)1427 static inline void arlan_queue_retransmit(struct net_device *dev)
1428 {
1429 struct arlan_private *priv = ((struct arlan_private *) dev->priv);
1430
1431 ARLAN_DEBUG_ENTRY("arlan_queue_retransmit");
1432
1433 if (DoNotWaitReTransmitCrap(dev))
1434 {
1435 arlan_drop_tx(dev);
1436 } else
1437 priv->ReTransmitRequested++;
1438
1439 ARLAN_DEBUG_EXIT("arlan_queue_retransmit");
1440 };
1441
RetryOrFail(struct net_device * dev)1442 static inline void RetryOrFail(struct net_device *dev)
1443 {
1444 struct arlan_private *priv = ((struct arlan_private *) dev->priv);
1445
1446 ARLAN_DEBUG_ENTRY("RetryOrFail");
1447
1448 if (priv->retransmissions > priv->Conf->retries ||
1449 DoNotReTransmitCrap(dev))
1450 {
1451 arlan_drop_tx(dev);
1452 }
1453 else if (priv->bad <= priv->Conf->fastReTransCount)
1454 {
1455 arlan_retransmit_now(dev);
1456 }
1457 else arlan_queue_retransmit(dev);
1458
1459 ARLAN_DEBUG_EXIT("RetryOrFail");
1460 }
1461
1462
arlan_tx_done_interrupt(struct net_device * dev,int status)1463 static void arlan_tx_done_interrupt(struct net_device *dev, int status)
1464 {
1465 struct arlan_private *priv = ((struct arlan_private *) dev->priv);
1466
1467 ARLAN_DEBUG_ENTRY("arlan_tx_done_interrupt");
1468
1469 priv->tx_last_cleared = jiffies;
1470 priv->tx_command_given = 0;
1471 priv->nof_tx_ack++;
1472 switch (status)
1473 {
1474 case 1:
1475 {
1476 IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
1477 printk("arlan intr: transmit OK\n");
1478 priv->stats.tx_packets++;
1479 priv->bad = 0;
1480 priv->reset = 0;
1481 priv->retransmissions = 0;
1482 if (priv->Conf->tx_delay_ms)
1483 {
1484 priv->tx_done_delayed = jiffies + (priv->Conf->tx_delay_ms * HZ) / 1000 + 1;;
1485 }
1486 else
1487 {
1488 TXLAST(dev).offset = 0;
1489 if (priv->txLast)
1490 priv->txLast = 0;
1491 else if (TXTAIL(dev).offset)
1492 priv->txLast = 1;
1493 if (TXLAST(dev).offset)
1494 {
1495 arlan_retransmit_now(dev);
1496 dev->trans_start = jiffies;
1497 }
1498 if (!TXHEAD(dev).offset || !TXTAIL(dev).offset)
1499 {
1500 priv->txOffset = 0;
1501 netif_wake_queue (dev);
1502 }
1503 }
1504 }
1505 break;
1506
1507 case 2:
1508 {
1509 IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
1510 printk("arlan intr: transmit timed out\n");
1511 priv->bad += 1;
1512 //arlan_queue_retransmit(dev);
1513 RetryOrFail(dev);
1514 }
1515 break;
1516
1517 case 3:
1518 {
1519 IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
1520 printk("arlan intr: transmit max retries\n");
1521 priv->bad += 1;
1522 priv->reset = 0;
1523 //arlan_queue_retransmit(dev);
1524 RetryOrFail(dev);
1525 }
1526 break;
1527
1528 case 4:
1529 {
1530 IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
1531 printk("arlan intr: transmit aborted\n");
1532 priv->bad += 1;
1533 arlan_queue_retransmit(dev);
1534 //RetryOrFail(dev);
1535 }
1536 break;
1537
1538 case 5:
1539 {
1540 IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
1541 printk("arlan intr: transmit not registered\n");
1542 priv->bad += 1;
1543 //debug=101;
1544 arlan_queue_retransmit(dev);
1545 }
1546 break;
1547
1548 case 6:
1549 {
1550 IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
1551 printk("arlan intr: transmit destination full\n");
1552 priv->bad += 1;
1553 priv->reset = 0;
1554 //arlan_drop_tx(dev);
1555 arlan_queue_retransmit(dev);
1556 }
1557 break;
1558
1559 case 7:
1560 {
1561 IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
1562 printk("arlan intr: transmit unknown ack\n");
1563 priv->bad += 1;
1564 priv->reset = 0;
1565 arlan_queue_retransmit(dev);
1566 }
1567 break;
1568
1569 case 8:
1570 {
1571 IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
1572 printk("arlan intr: transmit dest mail box full\n");
1573 priv->bad += 1;
1574 priv->reset = 0;
1575 //arlan_drop_tx(dev);
1576 arlan_queue_retransmit(dev);
1577 }
1578 break;
1579
1580 case 9:
1581 {
1582 IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
1583 printk("arlan intr: transmit root dest not reg.\n");
1584 priv->bad += 1;
1585 priv->reset = 1;
1586 //arlan_drop_tx(dev);
1587 arlan_queue_retransmit(dev);
1588 }
1589 break;
1590
1591 default:
1592 {
1593 printk(KERN_ERR "arlan intr: transmit status unknown\n");
1594 priv->bad += 1;
1595 priv->reset = 1;
1596 arlan_drop_tx(dev);
1597 }
1598 }
1599
1600 ARLAN_DEBUG_EXIT("arlan_tx_done_interrupt");
1601 }
1602
1603
arlan_rx_interrupt(struct net_device * dev,u_char rxStatus,u_short rxOffset,u_short pkt_len)1604 static void arlan_rx_interrupt(struct net_device *dev, u_char rxStatus, u_short rxOffset, u_short pkt_len)
1605 {
1606 char *skbtmp;
1607 int i = 0;
1608
1609 struct arlan_private *priv = (struct arlan_private *) dev->priv;
1610 volatile struct arlan_shmem *arlan = priv->card;
1611 struct arlan_conf_stru *conf = priv->Conf;
1612
1613
1614 ARLAN_DEBUG_ENTRY("arlan_rx_interrupt");
1615 // by spec, not WRITESHMB(arlan->rxStatus,0x00);
1616 // prohibited here arlan_command(dev, ARLAN_COMMAND_RX);
1617
1618 if (pkt_len < 10 || pkt_len > 2048)
1619 {
1620 printk(KERN_WARNING "%s: got too short or long packet, len %d \n", dev->name, pkt_len);
1621 return;
1622 }
1623 if (rxOffset + pkt_len > 0x2000)
1624 {
1625 printk("%s: got too long packet, len %d offset %x\n", dev->name, pkt_len, rxOffset);
1626 return;
1627 }
1628 priv->in_bytes += pkt_len;
1629 priv->in_bytes10 += pkt_len;
1630 if (conf->measure_rate < 1)
1631 conf->measure_rate = 1;
1632 if (jiffies - priv->in_time > conf->measure_rate * HZ)
1633 {
1634 conf->in_speed = priv->in_bytes / conf->measure_rate;
1635 priv->in_bytes = 0;
1636 priv->in_time = jiffies;
1637 }
1638 if (jiffies - priv->in_time10 > conf->measure_rate * HZ * 10)
1639 {
1640 conf->in_speed10 = priv->in_bytes10 / (10 * conf->measure_rate);
1641 priv->in_bytes10 = 0;
1642 priv->in_time10 = jiffies;
1643 }
1644 DEBUGSHM(1, "arlan rcv pkt rxStatus= %d ", arlan->rxStatus, u_char);
1645 switch (rxStatus)
1646 {
1647 case 1:
1648 case 2:
1649 case 3:
1650 {
1651 /* Malloc up new buffer. */
1652 struct sk_buff *skb;
1653
1654 DEBUGSHM(50, "arlan recv pkt offs=%d\n", arlan->rxOffset, u_short);
1655 DEBUGSHM(1, "arlan rxFrmType = %d \n", arlan->rxFrmType, u_char);
1656 DEBUGSHM(1, KERN_INFO "arlan rx scrambled = %d \n", arlan->scrambled, u_char);
1657
1658 /* here we do multicast filtering to avoid slow 8-bit memcopy */
1659 #ifdef ARLAN_MULTICAST
1660 if (!(dev->flags & IFF_ALLMULTI) &&
1661 !(dev->flags & IFF_PROMISC) &&
1662 dev->mc_list)
1663 {
1664 char hw_dst_addr[6];
1665 struct dev_mc_list *dmi = dev->mc_list;
1666 int i;
1667
1668 memcpy_fromio(hw_dst_addr, arlan->ultimateDestAddress, 6);
1669 if (hw_dst_addr[0] == 0x01)
1670 {
1671 if (mdebug)
1672 if (hw_dst_addr[1] == 0x00)
1673 printk(KERN_ERR "%s mcast 0x0100 \n", dev->name);
1674 else if (hw_dst_addr[1] == 0x40)
1675 printk(KERN_ERR "%s m/bcast 0x0140 \n", dev->name);
1676 while (dmi)
1677 { if (dmi->dmi_addrlen == 6)
1678 {
1679 if (arlan_debug & ARLAN_DEBUG_HEADER_DUMP)
1680 printk(KERN_ERR "%s mcl %2x:%2x:%2x:%2x:%2x:%2x \n", dev->name,
1681 dmi->dmi_addr[0], dmi->dmi_addr[1], dmi->dmi_addr[2],
1682 dmi->dmi_addr[3], dmi->dmi_addr[4], dmi->dmi_addr[5]);
1683 for (i = 0; i < 6; i++)
1684 if (dmi->dmi_addr[i] != hw_dst_addr[i])
1685 break;
1686 if (i == 6)
1687 break;
1688 }
1689 else
1690 printk(KERN_ERR "%s: invalid multicast address length given.\n", dev->name);
1691 dmi = dmi->next;
1692 }
1693 /* we reach here if multicast filtering is on and packet
1694 * is multicast and not for receive */
1695 goto end_of_interrupt;
1696 }
1697 }
1698 #endif // ARLAN_MULTICAST
1699 /* multicast filtering ends here */
1700 pkt_len += ARLAN_FAKE_HDR_LEN;
1701
1702 skb = dev_alloc_skb(pkt_len + 4);
1703 if (skb == NULL)
1704 {
1705 printk(KERN_ERR "%s: Memory squeeze, dropping packet.\n", dev->name);
1706 priv->stats.rx_dropped++;
1707 break;
1708 }
1709 skb_reserve(skb, 2);
1710 skb->dev = dev;
1711 skbtmp = skb_put(skb, pkt_len);
1712
1713 memcpy_fromio(skbtmp + ARLAN_FAKE_HDR_LEN, ((char *) arlan) + rxOffset, pkt_len - ARLAN_FAKE_HDR_LEN);
1714 memcpy_fromio(skbtmp, arlan->ultimateDestAddress, 6);
1715 memcpy_fromio(skbtmp + 6, arlan->rxSrc, 6);
1716 WRITESHMB(arlan->rxStatus, 0x00);
1717 arlan_command(dev, ARLAN_COMMAND_RX);
1718
1719 IFDEBUG(ARLAN_DEBUG_HEADER_DUMP)
1720 {
1721 char immedDestAddress[6];
1722 char immedSrcAddress[6];
1723 memcpy_fromio(immedDestAddress, arlan->immedDestAddress, 6);
1724 memcpy_fromio(immedSrcAddress, arlan->immedSrcAddress, 6);
1725
1726 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,
1727 (unsigned char) skbtmp[0], (unsigned char) skbtmp[1], (unsigned char) skbtmp[2], (unsigned char) skbtmp[3],
1728 (unsigned char) skbtmp[4], (unsigned char) skbtmp[5], (unsigned char) skbtmp[6], (unsigned char) skbtmp[7],
1729 (unsigned char) skbtmp[8], (unsigned char) skbtmp[9], (unsigned char) skbtmp[10], (unsigned char) skbtmp[11],
1730 immedDestAddress[0], immedDestAddress[1], immedDestAddress[2],
1731 immedDestAddress[3], immedDestAddress[4], immedDestAddress[5],
1732 immedSrcAddress[0], immedSrcAddress[1], immedSrcAddress[2],
1733 immedSrcAddress[3], immedSrcAddress[4], immedSrcAddress[5]);
1734 }
1735 skb->protocol = eth_type_trans(skb, dev);
1736 IFDEBUG(ARLAN_DEBUG_HEADER_DUMP)
1737 if (skb->protocol != 0x608 && skb->protocol != 0x8)
1738 {
1739 for (i = 0; i <= 22; i++)
1740 printk("%02x:", (u_char) skbtmp[i + 12]);
1741 printk(KERN_ERR "\n");
1742 printk(KERN_WARNING "arlan kernel pkt type trans %x \n", skb->protocol);
1743 }
1744 netif_rx(skb);
1745 dev->last_rx = jiffies;
1746 priv->stats.rx_packets++;
1747 priv->stats.rx_bytes += pkt_len;
1748 }
1749 break;
1750
1751 default:
1752 printk(KERN_ERR "arlan intr: received unknown status\n");
1753 priv->stats.rx_crc_errors++;
1754 break;
1755 }
1756 ARLAN_DEBUG_EXIT("arlan_rx_interrupt");
1757 }
1758
arlan_process_interrupt(struct net_device * dev)1759 static void arlan_process_interrupt(struct net_device *dev)
1760 {
1761 struct arlan_private *priv = (struct arlan_private *) dev->priv;
1762 volatile struct arlan_shmem *arlan = priv->card;
1763 u_char rxStatus = READSHMB(arlan->rxStatus);
1764 u_char txStatus = READSHMB(arlan->txStatus);
1765 u_short rxOffset = READSHMS(arlan->rxOffset);
1766 u_short pkt_len = READSHMS(arlan->rxLength);
1767 int interrupt_count = 0;
1768
1769 ARLAN_DEBUG_ENTRY("arlan_process_interrupt");
1770
1771 if (test_and_set_bit(0, (void *) &priv->interrupt_processing_active))
1772 {
1773 if (arlan_debug & ARLAN_DEBUG_CHAIN_LOCKS)
1774 printk(KERN_ERR "interrupt chain reentering \n");
1775 goto end_int_process;
1776 }
1777 while ((rxStatus || txStatus || priv->interrupt_ack_requested)
1778 && (interrupt_count < 5))
1779 {
1780 if (rxStatus)
1781 priv->last_rx_int_ack_time = arlan_time();
1782
1783 arlan_command(dev, ARLAN_COMMAND_INT_ACK);
1784 arlan_command(dev, ARLAN_COMMAND_INT_ENABLE);
1785
1786 IFDEBUG(ARLAN_DEBUG_INTERRUPT)
1787 printk(KERN_ERR "%s: got IRQ rx %x tx %x comm %x rxOff %x rxLen %x \n",
1788 dev->name, rxStatus, txStatus, READSHMB(arlan->commandByte),
1789 rxOffset, pkt_len);
1790
1791 if (rxStatus == 0 && txStatus == 0)
1792 {
1793 priv->last_command_was_rx = 0;
1794 if (priv->irq_test_done)
1795 {
1796 if (!registrationBad(dev))
1797 IFDEBUG(ARLAN_DEBUG_INTERRUPT) printk(KERN_ERR "%s unknown interrupt(nop? regLost ?) reason tx %d rx %d ",
1798 dev->name, txStatus, rxStatus);
1799 } else {
1800 IFDEBUG(ARLAN_DEBUG_INTERRUPT)
1801 printk(KERN_INFO "%s irq $%d test OK \n", dev->name, dev->irq);
1802
1803 }
1804 priv->interrupt_ack_requested = 0;
1805 goto ends;
1806 }
1807 if (txStatus != 0)
1808 {
1809 WRITESHMB(arlan->txStatus, 0x00);
1810 arlan_tx_done_interrupt(dev, txStatus);
1811 goto ends;
1812 }
1813 if (rxStatus == 1 || rxStatus == 2)
1814 { /* a packet waiting */
1815 arlan_rx_interrupt(dev, rxStatus, rxOffset, pkt_len);
1816 goto ends;
1817 }
1818 if (rxStatus > 2 && rxStatus < 0xff)
1819 {
1820 priv->last_command_was_rx = 0;
1821 WRITESHMB(arlan->rxStatus, 0x00);
1822 printk(KERN_ERR "%s unknown rxStatus reason tx %d rx %d ",
1823 dev->name, txStatus, rxStatus);
1824 goto ends;
1825 }
1826 if (rxStatus == 0xff)
1827 {
1828 priv->last_command_was_rx = 0;
1829 WRITESHMB(arlan->rxStatus, 0x00);
1830 arlan_command(dev, ARLAN_COMMAND_RX);
1831 if (registrationBad(dev))
1832 netif_device_detach(dev);
1833 if (!registrationBad(dev))
1834 {
1835 priv->registrationLastSeen = jiffies;
1836 if (!netif_queue_stopped(dev) && !priv->under_reset && !priv->under_config)
1837 netif_wake_queue (dev);
1838 }
1839 goto ends;
1840 }
1841 ends:
1842
1843 arlan_command_process(dev);
1844
1845 rxStatus = READSHMB(arlan->rxStatus);
1846 txStatus = READSHMB(arlan->txStatus);
1847 rxOffset = READSHMS(arlan->rxOffset);
1848 pkt_len = READSHMS(arlan->rxLength);
1849
1850
1851 priv->irq_test_done = 1;
1852
1853 interrupt_count++;
1854 }
1855 priv->interrupt_processing_active = 0;
1856
1857 end_int_process:
1858 arlan_command_process(dev);
1859
1860 ARLAN_DEBUG_EXIT("arlan_process_interrupt");
1861 return;
1862 }
1863
arlan_interrupt(int irq,void * dev_id,struct pt_regs * regs)1864 static void arlan_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1865 {
1866 struct net_device *dev = dev_id;
1867 struct arlan_private *priv = (struct arlan_private *) dev->priv;
1868 volatile struct arlan_shmem *arlan = priv->card;
1869 u_char rxStatus = READSHMB(arlan->rxStatus);
1870 u_char txStatus = READSHMB(arlan->txStatus);
1871
1872 ARLAN_DEBUG_ENTRY("arlan_interrupt");
1873
1874
1875 if (!rxStatus && !txStatus)
1876 priv->interrupt_ack_requested++;
1877
1878 arlan_process_interrupt(dev);
1879
1880 priv->irq_test_done = 1;
1881
1882 ARLAN_DEBUG_EXIT("arlan_interrupt");
1883 return;
1884
1885 }
1886
1887
arlan_close(struct net_device * dev)1888 static int arlan_close(struct net_device *dev)
1889 {
1890 struct arlan_private *priv = (struct arlan_private *) dev->priv;
1891
1892 if (!dev)
1893 {
1894 printk(KERN_CRIT "arlan: No Device\n");
1895 return 0;
1896 }
1897 priv = (struct arlan_private *) dev->priv;
1898 if (!priv)
1899 {
1900 printk(KERN_CRIT "arlan: No Device priv \n");
1901 return 0;
1902 }
1903 ARLAN_DEBUG_ENTRY("arlan_close");
1904
1905 del_timer(&priv->timer);
1906
1907 arlan_command(dev, ARLAN_COMMAND_POWERDOWN);
1908
1909 IFDEBUG(ARLAN_DEBUG_STARTUP)
1910 printk(KERN_NOTICE "%s: Closing device\n", dev->name);
1911
1912 priv->open_time = 0;
1913 netif_stop_queue(dev);
1914 free_irq(dev->irq, dev);
1915
1916 ARLAN_DEBUG_EXIT("arlan_close");
1917 return 0;
1918 }
1919
1920 #ifdef ARLAN_DEBUGGING
alignLong(volatile u_char * ptr)1921 static long alignLong(volatile u_char * ptr)
1922 {
1923 long ret;
1924 memcpy_fromio(&ret, (void *) ptr, 4);
1925 return ret;
1926 }
1927 #endif
1928
1929 /*
1930 * Get the current statistics.
1931 * This may be called with the card open or closed.
1932 */
1933
arlan_statistics(struct net_device * dev)1934 static struct net_device_stats *arlan_statistics(struct net_device *dev)
1935 {
1936 struct arlan_private *priv = (struct arlan_private *) dev->priv;
1937 volatile struct arlan_shmem *arlan = ((struct arlan_private *) dev->priv)->card;
1938
1939
1940 ARLAN_DEBUG_ENTRY("arlan_statistics");
1941
1942 /* Update the statistics from the device registers. */
1943
1944 READSHM(priv->stats.collisions, arlan->numReTransmissions, u_int);
1945 READSHM(priv->stats.rx_crc_errors, arlan->numCRCErrors, u_int);
1946 READSHM(priv->stats.rx_dropped, arlan->numFramesDiscarded, u_int);
1947 READSHM(priv->stats.rx_fifo_errors, arlan->numRXBufferOverflows, u_int);
1948 READSHM(priv->stats.rx_frame_errors, arlan->numReceiveFramesLost, u_int);
1949 READSHM(priv->stats.rx_over_errors, arlan->numRXOverruns, u_int);
1950 READSHM(priv->stats.rx_packets, arlan->numDatagramsReceived, u_int);
1951 READSHM(priv->stats.tx_aborted_errors, arlan->numAbortErrors, u_int);
1952 READSHM(priv->stats.tx_carrier_errors, arlan->numStatusTimeouts, u_int);
1953 READSHM(priv->stats.tx_dropped, arlan->numDatagramsDiscarded, u_int);
1954 READSHM(priv->stats.tx_fifo_errors, arlan->numTXUnderruns, u_int);
1955 READSHM(priv->stats.tx_packets, arlan->numDatagramsTransmitted, u_int);
1956 READSHM(priv->stats.tx_window_errors, arlan->numHoldOffs, u_int);
1957
1958 ARLAN_DEBUG_EXIT("arlan_statistics");
1959
1960 return &priv->stats;
1961 }
1962
1963
arlan_set_multicast(struct net_device * dev)1964 static void arlan_set_multicast(struct net_device *dev)
1965 {
1966 volatile struct arlan_shmem *arlan = ((struct arlan_private *) dev->priv)->card;
1967 struct arlan_conf_stru *conf = ((struct arlan_private *) dev->priv)->Conf;
1968 int board_conf_needed = 0;
1969
1970
1971 ARLAN_DEBUG_ENTRY("arlan_set_multicast");
1972
1973 if (dev->flags & IFF_PROMISC)
1974 {
1975 unsigned char recMode;
1976 READSHM(recMode, arlan->receiveMode, u_char);
1977 conf->receiveMode = (ARLAN_RCV_PROMISC | ARLAN_RCV_CONTROL);
1978 if (conf->receiveMode != recMode)
1979 board_conf_needed = 1;
1980 }
1981 else
1982 {
1983 /* turn off promiscuous mode */
1984 unsigned char recMode;
1985 READSHM(recMode, arlan->receiveMode, u_char);
1986 conf->receiveMode = ARLAN_RCV_CLEAN | ARLAN_RCV_CONTROL;
1987 if (conf->receiveMode != recMode)
1988 board_conf_needed = 1;
1989 }
1990 if (board_conf_needed)
1991 arlan_command(dev, ARLAN_COMMAND_CONF);
1992
1993 ARLAN_DEBUG_EXIT("arlan_set_multicast");
1994 }
1995
1996
arlan_probe(struct net_device * dev)1997 int __init arlan_probe(struct net_device *dev)
1998 {
1999 printk("Arlan driver %s\n", arlan_version);
2000
2001 if (arlan_probe_everywhere(dev))
2002 return -ENODEV;
2003
2004 arlans_found++;
2005
2006 if (arlans_found == 1)
2007 siteName = kmalloc(100, GFP_KERNEL);
2008 return 0;
2009 }
2010
2011 #ifdef MODULE
2012
init_module(void)2013 int init_module(void)
2014 {
2015 int i = 0;
2016
2017 ARLAN_DEBUG_ENTRY("init_module");
2018
2019 if (channelSet != channelSetUNKNOWN || channelNumber != channelNumberUNKNOWN || systemId != systemIdUNKNOWN)
2020 {
2021 printk(KERN_WARNING "arlan: wrong module params for multiple devices\n ");
2022 return -1;
2023 }
2024 numDevices = arlan_find_devices();
2025 if (numDevices == 0)
2026 {
2027 printk(KERN_ERR "arlan: no devices found \n");
2028 return -1;
2029 }
2030
2031 siteName = kmalloc(100, GFP_KERNEL);
2032 if(siteName==NULL)
2033 {
2034 printk(KERN_ERR "arlan: No memory for site name.\n");
2035 return -1;
2036 }
2037 for (i = 0; i < numDevices && i < MAX_ARLANS; i++)
2038 {
2039 if (!arlan_allocate_device(i, NULL))
2040 return -1;
2041 if (arlan_device[i] == NULL)
2042 {
2043 printk(KERN_CRIT "arlan: Not Enough memory \n");
2044 return -1;
2045 }
2046 if (probe)
2047 arlan_probe_everywhere(arlan_device[i]);
2048 // arlan_command(arlan_device[i], ARLAN_COMMAND_POWERDOWN );
2049 }
2050 printk(KERN_INFO "Arlan driver %s\n", arlan_version);
2051 ARLAN_DEBUG_EXIT("init_module");
2052 return 0;
2053 }
2054
2055
cleanup_module(void)2056 void cleanup_module(void)
2057 {
2058 int i = 0;
2059
2060 ARLAN_DEBUG_ENTRY("cleanup_module");
2061
2062 IFDEBUG(ARLAN_DEBUG_SHUTDOWN)
2063 printk(KERN_INFO "arlan: unloading module\n");
2064 for (i = 0; i < MAX_ARLANS; i++)
2065 {
2066 if (arlan_device[i])
2067 {
2068 arlan_command(arlan_device[i], ARLAN_COMMAND_POWERDOWN );
2069
2070 // release_mem_region(virt_to_phys(arlan_device[i]->mem_start), 0x2000 );
2071 unregister_netdev(arlan_device[i]);
2072 if (arlan_device[i]->priv)
2073 {
2074 if (((struct arlan_private *) arlan_device[i]->priv)->conf)
2075 kfree(((struct arlan_private *) arlan_device[i]->priv)->conf);
2076 kfree(arlan_device[i]);
2077 }
2078 arlan_device[i] = NULL;
2079 }
2080 }
2081 ARLAN_DEBUG_EXIT("cleanup_module");
2082 }
2083
2084
2085 #endif
2086 MODULE_LICENSE("GPL");
2087