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