1 #include <linux/config.h>
2 #include "arlan.h"
3 
4 #include <linux/sysctl.h>
5 
6 #ifdef CONFIG_PROC_FS
7 
8 
9 #include <linux/version.h>
10 
11 /* void enableReceive(struct net_device* dev);
12 */
13 
14 
15 
16 #define ARLAN_STR_SIZE 	0x2ff0
17 #define DEV_ARLAN_INFO 	1
18 #define DEV_ARLAN 	1
19 #define SARLG(type,var) {\
20 	pos += sprintf(arlan_drive_info+pos, "%s\t=\t0x%x\n", #var, READSHMB(priva->card->var));	\
21 	}
22 
23 #define SARLBN(type,var,nn) {\
24 	pos += sprintf(arlan_drive_info+pos, "%s\t=\t0x",#var);\
25 	for (i=0; i < nn; i++ ) pos += sprintf(arlan_drive_info+pos, "%02x",READSHMB(priva->card->var[i]));\
26 	pos += sprintf(arlan_drive_info+pos, "\n");	\
27 	}
28 
29 #define SARLBNpln(type,var,nn) {\
30 	for (i=0; i < nn; i++ ) pos += sprintf(arlan_drive_info+pos, "%02x",READSHMB(priva->card->var[i]));\
31 	}
32 
33 #define SARLSTR(var,nn) {\
34 	char tmpStr[400];\
35 	int  tmpLn = nn;\
36 	if (nn > 399 ) tmpLn = 399; \
37 	memcpy(tmpStr,(char *) priva->conf->var,tmpLn);\
38 	tmpStr[tmpLn] = 0; \
39 	pos += sprintf(arlan_drive_info+pos, "%s\t=\t%s \n",#var,priva->conf->var);\
40 	}
41 
42 #define SARLUC(var)  	SARLG(u_char, var)
43 #define SARLUCN(var,nn) SARLBN(u_char,var, nn)
44 #define SARLUS(var)	SARLG(u_short, var)
45 #define SARLUSN(var,nn)	SARLBN(u_short,var, nn)
46 #define SARLUI(var)	SARLG(u_int, var)
47 
48 #define SARLUSA(var) {\
49 	u_short tmpVar;\
50 	memcpy(&tmpVar, (short *) priva->conf->var,2); \
51 	pos += sprintf(arlan_drive_info+pos, "%s\t=\t0x%x\n",#var, tmpVar);\
52 }
53 
54 #define SARLUIA(var) {\
55 	u_int tmpVar;\
56 	memcpy(&tmpVar, (int* )priva->conf->var,4); \
57 	pos += sprintf(arlan_drive_info+pos, "%s\t=\t0x%x\n",#var, tmpVar);\
58 }
59 
60 
arlan_diagnostic_info_string(struct net_device * dev)61 static const char *arlan_diagnostic_info_string(struct net_device *dev)
62 {
63 
64 	volatile struct arlan_shmem *arlan = ((struct arlan_private *) dev->priv)->card;
65 	u_char diagnosticInfo;
66 
67 	READSHM(diagnosticInfo, arlan->diagnosticInfo, u_char);
68 
69 	switch (diagnosticInfo)
70 	{
71 		case 0xFF:
72 			return "Diagnostic info is OK";
73 		case 0xFE:
74 			return "ERROR EPROM Checksum error ";
75 		case 0xFD:
76 			return "ERROR Local Ram Test Failed ";
77 		case 0xFC:
78 			return "ERROR SCC failure ";
79 		case 0xFB:
80 			return "ERROR BackBone failure ";
81 		case 0xFA:
82 			return "ERROR tranceiver not found ";
83 		case 0xF9:
84 			return "ERROR no more address space ";
85 		case 0xF8:
86 			return "ERROR Checksum error  ";
87 		case 0xF7:
88 			return "ERROR Missing SS Code";
89 		case 0xF6:
90 			return "ERROR Invalid config format";
91 		case 0xF5:
92 			return "ERROR Reserved errorcode F5";
93 		case 0xF4:
94 			return "ERROR Invalid spreading code/channel number";
95 		case 0xF3:
96 			return "ERROR Load Code Error";
97 		case 0xF2:
98 			return "ERROR Reserver errorcode F2 ";
99 		case 0xF1:
100 			return "ERROR Invalid command receivec by LAN card ";
101 		case 0xF0:
102 			return "ERROR Invalid parameter found in command ";
103 		case 0xEF:
104 			return "ERROR On-chip timer failure ";
105 		case 0xEE:
106 			return "ERROR T410 timer failure ";
107 		case 0xED:
108 			return "ERROR Too Many TxEnable commands ";
109 		case 0xEC:
110 			return "ERROR EEPROM error on radio module ";
111 		default:
112 			return "ERROR unknown Diagnostic info reply code ";
113 	  }
114 };
115 
arlan_hardware_type_string(struct net_device * dev)116 static const char *arlan_hardware_type_string(struct net_device *dev)
117 {
118 	u_char hardwareType;
119 	volatile struct arlan_shmem *arlan = ((struct arlan_private *) dev->priv)->card;
120 
121 	READSHM(hardwareType, arlan->hardwareType, u_char);
122 	switch (hardwareType)
123 	{
124 		case 0x00:
125 			return "type A450";
126 		case 0x01:
127 			return "type A650 ";
128 		case 0x04:
129 			return "type TMA coproc";
130 		case 0x0D:
131 			return "type A650E ";
132 		case 0x18:
133 			return "type TMA coproc Australian";
134 		case 0x19:
135 			return "type A650A ";
136 		case 0x26:
137 			return "type TMA coproc European";
138 		case 0x2E:
139 			return "type A655 ";
140 		case 0x2F:
141 			return "type A655A ";
142 		case 0x30:
143 			return "type A655E ";
144 		case 0x0B:
145 			return "type A670 ";
146 		case 0x0C:
147 			return "type A670E ";
148 		case 0x2D:
149 			return "type A670A ";
150 		case 0x0F:
151 			return "type A411T";
152 		case 0x16:
153 			return "type A411TA";
154 		case 0x1B:
155 			return "type A440T";
156 		case 0x1C:
157 			return "type A412T";
158 		case 0x1E:
159 			return "type A412TA";
160 		case 0x22:
161 			return "type A411TE";
162 		case 0x24:
163 			return "type A412TE";
164 		case 0x27:
165 			return "type A671T ";
166 		case 0x29:
167 			return "type A671TA ";
168 		case 0x2B:
169 			return "type A671TE ";
170 		case 0x31:
171 			return "type A415T ";
172 		case 0x33:
173 			return "type A415TA ";
174 		case 0x35:
175 			return "type A415TE ";
176 		case 0x37:
177 			return "type A672";
178 		case 0x39:
179 			return "type A672A ";
180 		case 0x3B:
181 			return "type A672T";
182 		case 0x6B:
183 			return "type IC2200";
184 		default:
185 			return "type A672T";
186 	}
187 }
188 #ifdef ARLAN_DEBUGGING
arlan_print_diagnostic_info(struct net_device * dev)189 static void arlan_print_diagnostic_info(struct net_device *dev)
190 {
191 	int i;
192 	u_char diagnosticInfo;
193 	u_short diagnosticOffset;
194 	u_char hardwareType;
195 	volatile struct arlan_shmem *arlan = ((struct arlan_private *) dev->priv)->card;
196 
197 	//  ARLAN_DEBUG_ENTRY("arlan_print_diagnostic_info");
198 
199 	if (READSHMB(arlan->configuredStatusFlag) == 0)
200 		printk("Arlan: Card NOT configured\n");
201 	else
202 		printk("Arlan: Card is configured\n");
203 
204 	READSHM(diagnosticInfo, arlan->diagnosticInfo, u_char);
205 	READSHM(diagnosticOffset, arlan->diagnosticOffset, u_short);
206 
207 	printk(KERN_INFO "%s\n", arlan_diagnostic_info_string(dev));
208 
209 	if (diagnosticInfo != 0xff)
210 		printk("%s arlan: Diagnostic Offset %d \n", dev->name, diagnosticOffset);
211 
212 	printk("arlan: LAN CODE ID = ");
213 	for (i = 0; i < 6; i++)
214 		DEBUGSHM(1, "%03d:", arlan->lanCardNodeId[i], u_char);
215 	printk("\n");
216 
217 	printk("arlan: Arlan BroadCast address  = ");
218 	for (i = 0; i < 6; i++)
219 		DEBUGSHM(1, "%03d:", arlan->broadcastAddress[i], u_char);
220 	printk("\n");
221 
222 	READSHM(hardwareType, arlan->hardwareType, u_char);
223 	printk(KERN_INFO "%s\n", arlan_hardware_type_string(dev));
224 
225 
226 	DEBUGSHM(1, "arlan: channelNumber=%d\n", arlan->channelNumber, u_char);
227 	DEBUGSHM(1, "arlan: channelSet=%d\n", arlan->channelSet, u_char);
228 	DEBUGSHM(1, "arlan: spreadingCode=%d\n", arlan->spreadingCode, u_char);
229 	DEBUGSHM(1, "arlan: radioNodeId=%d\n", arlan->radioNodeId, u_short);
230 	DEBUGSHM(1, "arlan: SID	=%d\n", arlan->SID, u_short);
231 	DEBUGSHM(1, "arlan: rxOffset=%d\n", arlan->rxOffset, u_short);
232 
233 	DEBUGSHM(1, "arlan: registration mode is %d\n", arlan->registrationMode, u_char);
234 
235 	printk("arlan: name= ");
236 	IFDEBUG(1)
237 
238 	for (i = 0; i < 16; i++)
239 	{
240 		char c;
241 		READSHM(c, arlan->name[i], char);
242 		if (c)
243 			printk("%c", c);
244 	}
245 	printk("\n");
246 
247 //   ARLAN_DEBUG_EXIT("arlan_print_diagnostic_info");
248 
249 }
250 
251 
252 /******************************		TEST 	MEMORY	**************/
253 
arlan_hw_test_memory(struct net_device * dev)254 static int arlan_hw_test_memory(struct net_device *dev)
255 {
256 	u_char *ptr;
257 	int i;
258 	int memlen = sizeof(struct arlan_shmem) - 0xF;	/* avoid control register */
259 	volatile char *arlan_mem = (char *) (dev->mem_start);
260 	volatile struct arlan_shmem *arlan = ((struct arlan_private *) dev->priv)->card;
261 	char pattern;
262 
263 	ptr = NULL;
264 
265 	/* hold card in reset state */
266 	setHardwareReset(dev);
267 
268 	/* test memory */
269 	pattern = 0;
270 	for (i = 0; i < memlen; i++)
271 		WRITESHM(arlan_mem[i], ((u_char) pattern++), u_char);
272 
273 	pattern = 0;
274 	for (i = 0; i < memlen; i++)
275 	{
276 		char res;
277 		READSHM(res, arlan_mem[i], char);
278 		if (res != pattern++)
279 		{
280 			printk(KERN_ERR "Arlan driver memory test 1 failed \n");
281 			return -1;
282 		}
283 	}
284 
285 	pattern = 0;
286 	for (i = 0; i < memlen; i++)
287 		WRITESHM(arlan_mem[i], ~(pattern++), char);
288 
289 	pattern = 0;
290 	for (i = 0; i < memlen; i++)
291 	{
292 		char res;
293 		READSHM(res, arlan_mem[i], char);
294 		if (res != ~(pattern++))
295 		{
296 			printk(KERN_ERR "Arlan driver memory test 2 failed \n");
297 			return -1;
298 		}
299 	}
300 
301 	/* zero memory */
302 	for (i = 0; i < memlen; i++)
303 		WRITESHM(arlan_mem[i], 0x00, char);
304 
305 	IFDEBUG(1) printk(KERN_INFO "Arlan: memory tests ok\n");
306 
307 	/* set reset flag and then release reset */
308 	WRITESHM(arlan->resetFlag, 0xff, u_char);
309 
310 	clearChannelAttention(dev);
311 	clearHardwareReset(dev);
312 
313 	/* wait for reset flag to become zero, we'll wait for two seconds */
314 	if (arlan_command(dev, ARLAN_COMMAND_LONG_WAIT_NOW))
315 	{
316 		printk(KERN_ERR "%s arlan: failed to come back from memory test\n", dev->name);
317 		return -1;
318 	}
319 	return 0;
320 }
321 
arlan_setup_card_by_book(struct net_device * dev)322 static int arlan_setup_card_by_book(struct net_device *dev)
323 {
324 	u_char irqLevel, configuredStatusFlag;
325 	volatile struct arlan_shmem *arlan = ((struct arlan_private *) dev->priv)->card;
326 
327 //	ARLAN_DEBUG_ENTRY("arlan_setup_card");
328 
329 	READSHM(configuredStatusFlag, arlan->configuredStatusFlag, u_char);
330 
331 	IFDEBUG(10)
332 	if (configuredStatusFlag != 0)
333 		IFDEBUG(10) printk("arlan: CARD IS CONFIGURED\n");
334 	else
335 		IFDEBUG(10) printk("arlan: card is NOT configured\n");
336 
337 	if (testMemory || (READSHMB(arlan->diagnosticInfo) != 0xff))
338 		if (arlan_hw_test_memory(dev))
339 			return -1;
340 
341 	DEBUGSHM(4, "arlan configuredStatus = %d \n", arlan->configuredStatusFlag, u_char);
342 	DEBUGSHM(4, "arlan driver diagnostic: 0x%2x\n", arlan->diagnosticInfo, u_char);
343 
344 	/* issue nop command - no interrupt */
345 	arlan_command(dev, ARLAN_COMMAND_NOOP);
346 	if (arlan_command(dev, ARLAN_COMMAND_WAIT_NOW) != 0)
347 		return -1;
348 
349 	IFDEBUG(50) printk("1st Noop successfully executed !!\n");
350 
351 	/* try to turn on the arlan interrupts */
352 	clearClearInterrupt(dev);
353 	setClearInterrupt(dev);
354 	setInterruptEnable(dev);
355 
356 	/* issue nop command - with interrupt */
357 
358 	arlan_command(dev, ARLAN_COMMAND_NOOPINT);
359 	if (arlan_command(dev, ARLAN_COMMAND_WAIT_NOW) != 0)
360 		return -1;
361 
362 
363 	IFDEBUG(50) printk("2nd Noop successfully executed !!\n");
364 
365 	READSHM(irqLevel, arlan->irqLevel, u_char)
366 
367 	if (irqLevel != dev->irq)
368 	{
369 		IFDEBUG(1) printk(KERN_WARNING "arlan dip switches set irq to %d\n", irqLevel);
370 		printk(KERN_WARNING "device driver irq set to %d - does not match\n", dev->irq);
371 		dev->irq = irqLevel;
372 	}
373 	else
374 		IFDEBUG(2) printk("irq level is OK\n");
375 
376 
377 	IFDEBUG(3) arlan_print_diagnostic_info(dev);
378 
379 	arlan_command(dev, ARLAN_COMMAND_CONF);
380 
381 	READSHM(configuredStatusFlag, arlan->configuredStatusFlag, u_char);
382 	if (configuredStatusFlag == 0)
383 	{
384 		printk(KERN_WARNING "arlan configure failed\n");
385 		return -1;
386 	}
387 	arlan_command(dev, ARLAN_COMMAND_LONG_WAIT_NOW);
388 	arlan_command(dev, ARLAN_COMMAND_RX);
389 	arlan_command(dev, ARLAN_COMMAND_LONG_WAIT_NOW);
390 	printk(KERN_NOTICE "%s: arlan driver version %s loaded\n",
391 	       dev->name, arlan_version);
392 
393 //	ARLAN_DEBUG_EXIT("arlan_setup_card");
394 
395 	return 0;		/* no errors */
396 }
397 #endif
398 
399 #ifdef ARLAN_PROC_INTERFACE
400 #ifdef ARLAN_PROC_SHM_DUMP
401 
402 static char arlan_drive_info[ARLAN_STR_SIZE] = "A655\n\0";
403 
arlan_sysctl_info(ctl_table * ctl,int write,struct file * filp,void * buffer,size_t * lenp)404 static int arlan_sysctl_info(ctl_table * ctl, int write, struct file *filp,
405 		      void *buffer, size_t * lenp)
406 {
407 	int i;
408 	int retv, pos, devnum;
409 	struct arlan_private *priva = NULL;
410 	struct net_device *dev;
411 	pos = 0;
412 	if (write)
413 	{
414 		printk("wrirte: ");
415 		for (i = 0; i < 100; i++)
416 			printk("adi %x \n", arlan_drive_info[i]);
417 	}
418 	if (ctl->procname == NULL || arlan_drive_info == NULL)
419 	{
420 		printk(KERN_WARNING " procname is NULL in sysctl_table or arlan_drive_info is NULL \n at arlan module\n ");
421 		return -1;
422 	}
423 	devnum = ctl->procname[5] - '0';
424 	if (devnum < 0 || devnum > MAX_ARLANS - 1)
425 	{
426 		printk(KERN_WARNING "too strange devnum in procfs parse\n ");
427 		return -1;
428 	}
429 	else if (arlan_device[devnum] == NULL)
430 	{
431 		if (ctl->procname)
432 			pos += sprintf(arlan_drive_info + pos, "\t%s\n\n", ctl->procname);
433 		pos += sprintf(arlan_drive_info + pos, "No device found here \n");
434 		goto final;
435 	}
436 	else
437 		priva = arlan_device[devnum]->priv;
438 
439 	if (priva == NULL)
440 	{
441 		printk(KERN_WARNING " Could not find the device private in arlan procsys, bad\n ");
442 		return -1;
443 	}
444 	dev = arlan_device[devnum];
445 
446 	memcpy_fromio(priva->conf, priva->card, sizeof(struct arlan_shmem));
447 
448 	pos = sprintf(arlan_drive_info, "Arlan  info \n");
449 	/* Header Signature */
450 	SARLSTR(textRegion, 48);
451 	SARLUC(resetFlag);
452 	pos += sprintf(arlan_drive_info + pos, "diagnosticInfo\t=\t%s \n", arlan_diagnostic_info_string(dev));
453 	SARLUC(diagnosticInfo);
454 	SARLUS(diagnosticOffset);
455 	SARLUCN(_1, 12);
456 	SARLUCN(lanCardNodeId, 6);
457 	SARLUCN(broadcastAddress, 6);
458 	pos += sprintf(arlan_drive_info + pos, "hardwareType =\t  %s \n", arlan_hardware_type_string(dev));
459 	SARLUC(hardwareType);
460 	SARLUC(majorHardwareVersion);
461 	SARLUC(minorHardwareVersion);
462 	SARLUC(radioModule);
463 	SARLUC(defaultChannelSet);
464 	SARLUCN(_2, 47);
465 
466 	/* Control/Status Block - 0x0080 */
467 	SARLUC(interruptInProgress);
468 	SARLUC(cntrlRegImage);
469 
470 	SARLUCN(_3, 14);
471 	SARLUC(commandByte);
472 	SARLUCN(commandParameter, 15);
473 
474 	/* Receive Status - 0x00a0 */
475 	SARLUC(rxStatus);
476 	SARLUC(rxFrmType);
477 	SARLUS(rxOffset);
478 	SARLUS(rxLength);
479 	SARLUCN(rxSrc, 6);
480 	SARLUC(rxBroadcastFlag);
481 	SARLUC(rxQuality);
482 	SARLUC(scrambled);
483 	SARLUCN(_4, 1);
484 
485 	/* Transmit Status - 0x00b0 */
486 	SARLUC(txStatus);
487 	SARLUC(txAckQuality);
488 	SARLUC(numRetries);
489 	SARLUCN(_5, 14);
490 	SARLUCN(registeredRouter, 6);
491 	SARLUCN(backboneRouter, 6);
492 	SARLUC(registrationStatus);
493 	SARLUC(configuredStatusFlag);
494 	SARLUCN(_6, 1);
495 	SARLUCN(ultimateDestAddress, 6);
496 	SARLUCN(immedDestAddress, 6);
497 	SARLUCN(immedSrcAddress, 6);
498 	SARLUS(rxSequenceNumber);
499 	SARLUC(assignedLocaltalkAddress);
500 	SARLUCN(_7, 27);
501 
502 	/* System Parameter Block */
503 
504 	/* - Driver Parameters (Novell Specific) */
505 
506 	SARLUS(txTimeout);
507 	SARLUS(transportTime);
508 	SARLUCN(_8, 4);
509 
510 	/* - Configuration Parameters */
511 	SARLUC(irqLevel);
512 	SARLUC(spreadingCode);
513 	SARLUC(channelSet);
514 	SARLUC(channelNumber);
515 	SARLUS(radioNodeId);
516 	SARLUCN(_9, 2);
517 	SARLUC(scramblingDisable);
518 	SARLUC(radioType);
519 	SARLUS(routerId);
520 	SARLUCN(_10, 9);
521 	SARLUC(txAttenuation);
522 	SARLUIA(systemId);
523 	SARLUS(globalChecksum);
524 	SARLUCN(_11, 4);
525 	SARLUS(maxDatagramSize);
526 	SARLUS(maxFrameSize);
527 	SARLUC(maxRetries);
528 	SARLUC(receiveMode);
529 	SARLUC(priority);
530 	SARLUC(rootOrRepeater);
531 	SARLUCN(specifiedRouter, 6);
532 	SARLUS(fastPollPeriod);
533 	SARLUC(pollDecay);
534 	SARLUSA(fastPollDelay);
535 	SARLUC(arlThreshold);
536 	SARLUC(arlDecay);
537 	SARLUCN(_12, 1);
538 	SARLUS(specRouterTimeout);
539 	SARLUCN(_13, 5);
540 
541 	/* Scrambled Area */
542 	SARLUIA(SID);
543 	SARLUCN(encryptionKey, 12);
544 	SARLUIA(_14);
545 	SARLUSA(waitTime);
546 	SARLUSA(lParameter);
547 	SARLUCN(_15, 3);
548 	SARLUS(headerSize);
549 	SARLUS(sectionChecksum);
550 
551 	SARLUC(registrationMode);
552 	SARLUC(registrationFill);
553 	SARLUS(pollPeriod);
554 	SARLUS(refreshPeriod);
555 	SARLSTR(name, 16);
556 	SARLUCN(NID, 6);
557 	SARLUC(localTalkAddress);
558 	SARLUC(codeFormat);
559 	SARLUC(numChannels);
560 	SARLUC(channel1);
561 	SARLUC(channel2);
562 	SARLUC(channel3);
563 	SARLUC(channel4);
564 	SARLUCN(SSCode, 59);
565 
566 /*      SARLUCN( _16, 0x140);
567  */
568 	/* Statistics Block - 0x0300 */
569 	SARLUC(hostcpuLock);
570 	SARLUC(lancpuLock);
571 	SARLUCN(resetTime, 18);
572 	SARLUIA(numDatagramsTransmitted);
573 	SARLUIA(numReTransmissions);
574 	SARLUIA(numFramesDiscarded);
575 	SARLUIA(numDatagramsReceived);
576 	SARLUIA(numDuplicateReceivedFrames);
577 	SARLUIA(numDatagramsDiscarded);
578 	SARLUS(maxNumReTransmitDatagram);
579 	SARLUS(maxNumReTransmitFrames);
580 	SARLUS(maxNumConsecutiveDuplicateFrames);
581 	/* misaligned here so we have to go to characters */
582 	SARLUIA(numBytesTransmitted);
583 	SARLUIA(numBytesReceived);
584 	SARLUIA(numCRCErrors);
585 	SARLUIA(numLengthErrors);
586 	SARLUIA(numAbortErrors);
587 	SARLUIA(numTXUnderruns);
588 	SARLUIA(numRXOverruns);
589 	SARLUIA(numHoldOffs);
590 	SARLUIA(numFramesTransmitted);
591 	SARLUIA(numFramesReceived);
592 	SARLUIA(numReceiveFramesLost);
593 	SARLUIA(numRXBufferOverflows);
594 	SARLUIA(numFramesDiscardedAddrMismatch);
595 	SARLUIA(numFramesDiscardedSIDMismatch);
596 	SARLUIA(numPollsTransmistted);
597 	SARLUIA(numPollAcknowledges);
598 	SARLUIA(numStatusTimeouts);
599 	SARLUIA(numNACKReceived);
600 	SARLUS(auxCmd);
601 	SARLUCN(dumpPtr, 4);
602 	SARLUC(dumpVal);
603 	SARLUC(wireTest);
604 
605 	/* next 4 seems too long for procfs, over single page ?
606 	SARLUCN( _17, 0x86);
607 	SARLUCN( txBuffer, 0x800);
608 	SARLUCN( rxBuffer,  0x800);
609 	SARLUCN( _18, 0x0bff);
610 	 */
611 
612 	pos += sprintf(arlan_drive_info + pos, "rxRing\t=\t0x");
613 	for (i = 0; i < 0x50; i++)
614 		pos += sprintf(arlan_drive_info + pos, "%02x", ((char *) priva->conf)[priva->conf->rxOffset + i]);
615 	pos += sprintf(arlan_drive_info + pos, "\n");
616 
617 	SARLUC(configStatus);
618 	SARLUC(_22);
619 	SARLUC(progIOCtrl);
620 	SARLUC(shareMBase);
621 	SARLUC(controlRegister);
622 
623 	pos += sprintf(arlan_drive_info + pos, " total %d chars\n", pos);
624 	if (ctl)
625 		if (ctl->procname)
626 			pos += sprintf(arlan_drive_info + pos, " driver name : %s\n", ctl->procname);
627 final:
628 	*lenp = pos;
629 
630 	if (!write)
631 		retv = proc_dostring(ctl, write, filp, buffer, lenp);
632 	else
633 	{
634 		*lenp = 0;
635 		return -1;
636 	}
637 	return retv;
638 }
639 
640 
arlan_sysctl_info161719(ctl_table * ctl,int write,struct file * filp,void * buffer,size_t * lenp)641 static int arlan_sysctl_info161719(ctl_table * ctl, int write, struct file *filp,
642 			    void *buffer, size_t * lenp)
643 {
644 	int i;
645 	int retv, pos, devnum;
646 	struct arlan_private *priva = NULL;
647 
648 	pos = 0;
649 	devnum = ctl->procname[5] - '0';
650 	if (arlan_device[devnum] == NULL)
651 	{
652 		pos += sprintf(arlan_drive_info + pos, "No device found here \n");
653 		goto final;
654 	}
655 	else
656 		priva = arlan_device[devnum]->priv;
657 	if (priva == NULL)
658 	{
659 		printk(KERN_WARNING " Could not find the device private in arlan procsys, bad\n ");
660 		return -1;
661 	}
662 	memcpy_fromio(priva->conf, priva->card, sizeof(struct arlan_shmem));
663 	SARLUCN(_16, 0xC0);
664 	SARLUCN(_17, 0x6A);
665 	SARLUCN(_18, 14);
666 	SARLUCN(_19, 0x86);
667 	SARLUCN(_21, 0x3fd);
668 
669 final:
670 	*lenp = pos;
671 	retv = proc_dostring(ctl, write, filp, buffer, lenp);
672 	return retv;
673 }
674 
arlan_sysctl_infotxRing(ctl_table * ctl,int write,struct file * filp,void * buffer,size_t * lenp)675 static int arlan_sysctl_infotxRing(ctl_table * ctl, int write, struct file *filp,
676 			    void *buffer, size_t * lenp)
677 {
678 	int i;
679 	int retv, pos, devnum;
680 	struct arlan_private *priva = NULL;
681 
682 	pos = 0;
683 	devnum = ctl->procname[5] - '0';
684 	if (arlan_device[devnum] == NULL)
685 	{
686 		  pos += sprintf(arlan_drive_info + pos, "No device found here \n");
687 		  goto final;
688 	}
689 	else
690 		priva = arlan_device[devnum]->priv;
691 	if (priva == NULL)
692 	{
693 		printk(KERN_WARNING " Could not find the device private in arlan procsys, bad\n ");
694 		return -1;
695 	}
696 	memcpy_fromio(priva->conf, priva->card, sizeof(struct arlan_shmem));
697 	SARLBNpln(u_char, txBuffer, 0x800);
698 final:
699 	*lenp = pos;
700 	retv = proc_dostring(ctl, write, filp, buffer, lenp);
701 	return retv;
702 }
703 
arlan_sysctl_inforxRing(ctl_table * ctl,int write,struct file * filp,void * buffer,size_t * lenp)704 static int arlan_sysctl_inforxRing(ctl_table * ctl, int write, struct file *filp,
705 			    void *buffer, size_t * lenp)
706 {
707 	int i;
708 	int retv, pos, devnum;
709 	struct arlan_private *priva = NULL;
710 
711 	pos = 0;
712 	devnum = ctl->procname[5] - '0';
713 	if (arlan_device[devnum] == NULL)
714 	{
715 		  pos += sprintf(arlan_drive_info + pos, "No device found here \n");
716 		  goto final;
717 	} else
718 		priva = arlan_device[devnum]->priv;
719 	if (priva == NULL)
720 	{
721 		printk(KERN_WARNING " Could not find the device private in arlan procsys, bad\n ");
722 		return -1;
723 	}
724 	memcpy_fromio(priva->conf, priva->card, sizeof(struct arlan_shmem));
725 	SARLBNpln(u_char, rxBuffer, 0x800);
726 final:
727 	*lenp = pos;
728 	retv = proc_dostring(ctl, write, filp, buffer, lenp);
729 	return retv;
730 }
731 
arlan_sysctl_info18(ctl_table * ctl,int write,struct file * filp,void * buffer,size_t * lenp)732 static int arlan_sysctl_info18(ctl_table * ctl, int write, struct file *filp,
733 			void *buffer, size_t * lenp)
734 {
735 	int i;
736 	int retv, pos, devnum;
737 	struct arlan_private *priva = NULL;
738 
739 	pos = 0;
740 	devnum = ctl->procname[5] - '0';
741 	if (arlan_device[devnum] == NULL)
742 	{
743 		pos += sprintf(arlan_drive_info + pos, "No device found here \n");
744 		goto final;
745 	}
746 	else
747 		priva = arlan_device[devnum]->priv;
748 	if (priva == NULL)
749 	{
750 		printk(KERN_WARNING " Could not find the device private in arlan procsys, bad\n ");
751 		return -1;
752 	}
753 	memcpy_fromio(priva->conf, priva->card, sizeof(struct arlan_shmem));
754 	SARLBNpln(u_char, _18, 0x800);
755 
756 final:
757 	*lenp = pos;
758 	retv = proc_dostring(ctl, write, filp, buffer, lenp);
759 	return retv;
760 }
761 
762 
763 #endif				/* #ifdef ARLAN_PROC_SHM_DUMP */
764 
765 
766 static char conf_reset_result[200];
767 
arlan_configure(ctl_table * ctl,int write,struct file * filp,void * buffer,size_t * lenp)768 static int arlan_configure(ctl_table * ctl, int write, struct file *filp,
769 		    void *buffer, size_t * lenp)
770 {
771 	int pos = 0;
772 	int devnum = ctl->procname[6] - '0';
773 	struct arlan_private *priv;
774 
775 	if (devnum < 0 || devnum > MAX_ARLANS - 1)
776 	{
777 		  printk(KERN_WARNING "too strange devnum in procfs parse\n ");
778 		  return -1;
779 	}
780 	else if (arlan_device[devnum] != NULL)
781 	{
782 		  priv = arlan_device[devnum]->priv;
783 
784 		  arlan_command(arlan_device[devnum], ARLAN_COMMAND_CLEAN_AND_CONF);
785 	}
786 	else
787 		return -1;
788 
789 	*lenp = pos;
790 	return proc_dostring(ctl, write, filp, buffer, lenp);
791 }
792 
arlan_sysctl_reset(ctl_table * ctl,int write,struct file * filp,void * buffer,size_t * lenp)793 static int arlan_sysctl_reset(ctl_table * ctl, int write, struct file *filp,
794 		       void *buffer, size_t * lenp)
795 {
796 	int pos = 0;
797 	int devnum = ctl->procname[5] - '0';
798 	struct arlan_private *priv;
799 
800 	if (devnum < 0 || devnum > MAX_ARLANS - 1)
801 	{
802 		  printk(KERN_WARNING "too strange devnum in procfs parse\n ");
803 		  return -1;
804 	}
805 	else if (arlan_device[devnum] != NULL)
806 	{
807 		priv = arlan_device[devnum]->priv;
808 		arlan_command(arlan_device[devnum], ARLAN_COMMAND_CLEAN_AND_RESET);
809 
810 	} else
811 		return -1;
812 	*lenp = pos + 3;
813 	return proc_dostring(ctl, write, filp, buffer, lenp);
814 }
815 
816 
817 /* Place files in /proc/sys/dev/arlan */
818 #define CTBLN(num,card,nam) \
819         {num , #nam, &(arlan_conf[card].nam), \
820          sizeof(int), 0600, NULL, &proc_dointvec}
821 #ifdef ARLAN_DEBUGGING
822 
823 #define ARLAN_PROC_DEBUG_ENTRIES	{48, "entry_exit_debug", &arlan_entry_and_exit_debug, \
824                 sizeof(int), 0600, NULL, &proc_dointvec},\
825 	{49, "debug", &arlan_debug, \
826                 sizeof(int), 0600, NULL, &proc_dointvec},
827 #else
828 #define ARLAN_PROC_DEBUG_ENTRIES
829 #endif
830 
831 #define ARLAN_SYSCTL_TABLE_TOTAL(cardNo)\
832 	CTBLN(1,cardNo,spreadingCode),\
833 	CTBLN(2,cardNo, channelNumber),\
834 	CTBLN(3,cardNo, scramblingDisable),\
835 	CTBLN(4,cardNo, txAttenuation),\
836 	CTBLN(5,cardNo, systemId), \
837 	CTBLN(6,cardNo, maxDatagramSize),\
838 	CTBLN(7,cardNo, maxFrameSize),\
839 	CTBLN(8,cardNo, maxRetries),\
840 	CTBLN(9,cardNo, receiveMode),\
841 	CTBLN(10,cardNo, priority),\
842 	CTBLN(11,cardNo, rootOrRepeater),\
843 	CTBLN(12,cardNo, SID),\
844 	CTBLN(13,cardNo, registrationMode),\
845 	CTBLN(14,cardNo, registrationFill),\
846 	CTBLN(15,cardNo, localTalkAddress),\
847 	CTBLN(16,cardNo, codeFormat),\
848 	CTBLN(17,cardNo, numChannels),\
849 	CTBLN(18,cardNo, channel1),\
850 	CTBLN(19,cardNo, channel2),\
851 	CTBLN(20,cardNo, channel3),\
852 	CTBLN(21,cardNo, channel4),\
853 	CTBLN(22,cardNo, txClear),\
854 	CTBLN(23,cardNo, txRetries),\
855 	CTBLN(24,cardNo, txRouting),\
856 	CTBLN(25,cardNo, txScrambled),\
857 	CTBLN(26,cardNo, rxParameter),\
858 	CTBLN(27,cardNo, txTimeoutMs),\
859 	CTBLN(28,cardNo, waitCardTimeout),\
860 	CTBLN(29,cardNo, channelSet), \
861 	{30, "name", arlan_conf[cardNo].siteName, \
862                 16, 0600, NULL, &proc_dostring},\
863 	CTBLN(31,cardNo,waitTime),\
864 	CTBLN(32,cardNo,lParameter),\
865 	CTBLN(33,cardNo,_15),\
866 	CTBLN(34,cardNo,headerSize),\
867 	CTBLN(35,cardNo,async),\
868 	CTBLN(36,cardNo,tx_delay_ms),\
869 	CTBLN(37,cardNo,retries),\
870 	CTBLN(38,cardNo,ReTransmitPacketMaxSize),\
871 	CTBLN(39,cardNo,waitReTransmitPacketMaxSize),\
872 	CTBLN(40,cardNo,fastReTransCount),\
873 	CTBLN(41,cardNo,driverRetransmissions),\
874 	CTBLN(42,cardNo,txAckTimeoutMs),\
875 	CTBLN(43,cardNo,registrationInterrupts),\
876 	CTBLN(44,cardNo,hardwareType),\
877 	CTBLN(45,cardNo,radioType),\
878 	CTBLN(46,cardNo,writeEEPROM),\
879 	CTBLN(47,cardNo,writeRadioType),\
880 	ARLAN_PROC_DEBUG_ENTRIES\
881 	CTBLN(50,cardNo,in_speed),\
882 	CTBLN(51,cardNo,out_speed),\
883 	CTBLN(52,cardNo,in_speed10),\
884 	CTBLN(53,cardNo,out_speed10),\
885 	CTBLN(54,cardNo,in_speed_max),\
886 	CTBLN(55,cardNo,out_speed_max),\
887 	CTBLN(56,cardNo,measure_rate),\
888 	CTBLN(57,cardNo,pre_Command_Wait),\
889 	CTBLN(58,cardNo,rx_tweak1),\
890 	CTBLN(59,cardNo,rx_tweak2),\
891 	CTBLN(60,cardNo,tx_queue_len),\
892 
893 
894 
895 static ctl_table arlan_conf_table0[] =
896 {
897 	ARLAN_SYSCTL_TABLE_TOTAL(0)
898 
899 #ifdef ARLAN_PROC_SHM_DUMP
900 	{150, "arlan0-txRing", &arlan_drive_info,
901 	 ARLAN_STR_SIZE, 0400, NULL, &arlan_sysctl_infotxRing},
902 	{151, "arlan0-rxRing", &arlan_drive_info,
903 	 ARLAN_STR_SIZE, 0400, NULL, &arlan_sysctl_inforxRing},
904 	{152, "arlan0-18", &arlan_drive_info,
905 	 ARLAN_STR_SIZE, 0400, NULL, &arlan_sysctl_info18},
906 	{153, "arlan0-ring", &arlan_drive_info,
907 	 ARLAN_STR_SIZE, 0400, NULL, &arlan_sysctl_info161719},
908 	{154, "arlan0-shm-cpy", &arlan_drive_info,
909 	 ARLAN_STR_SIZE, 0400, NULL, &arlan_sysctl_info},
910 #endif
911 	{155, "config0", &conf_reset_result, \
912 	 100, 0400, NULL, &arlan_configure}, \
913 	{156, "reset0", &conf_reset_result, \
914 	 100, 0400, NULL, &arlan_sysctl_reset}, \
915 	{0}
916 };
917 
918 static ctl_table arlan_conf_table1[] =
919 {
920 
921 	ARLAN_SYSCTL_TABLE_TOTAL(1)
922 
923 #ifdef ARLAN_PROC_SHM_DUMP
924 	{150, "arlan1-txRing", &arlan_drive_info,
925 	 ARLAN_STR_SIZE, 0400, NULL, &arlan_sysctl_infotxRing},
926 	{151, "arlan1-rxRing", &arlan_drive_info,
927 	 ARLAN_STR_SIZE, 0400, NULL, &arlan_sysctl_inforxRing},
928 	{152, "arlan1-18", &arlan_drive_info,
929 	 ARLAN_STR_SIZE, 0400, NULL, &arlan_sysctl_info18},
930 	{153, "arlan1-ring", &arlan_drive_info,
931 	 ARLAN_STR_SIZE, 0400, NULL, &arlan_sysctl_info161719},
932 	{154, "arlan1-shm-cpy", &arlan_drive_info,
933 	 ARLAN_STR_SIZE, 0400, NULL, &arlan_sysctl_info},
934 #endif
935 	{155, "config1", &conf_reset_result,
936 	 100, 0400, NULL, &arlan_configure},
937 	{156, "reset1", &conf_reset_result,
938 	 100, 0400, NULL, &arlan_sysctl_reset},
939 	{0}
940 };
941 
942 static ctl_table arlan_conf_table2[] =
943 {
944 
945 	ARLAN_SYSCTL_TABLE_TOTAL(2)
946 
947 #ifdef ARLAN_PROC_SHM_DUMP
948 	{150, "arlan2-txRing", &arlan_drive_info,
949 	 ARLAN_STR_SIZE, 0400, NULL, &arlan_sysctl_infotxRing},
950 	{151, "arlan2-rxRing", &arlan_drive_info,
951 	 ARLAN_STR_SIZE, 0400, NULL, &arlan_sysctl_inforxRing},
952 	{152, "arlan2-18", &arlan_drive_info,
953 	 ARLAN_STR_SIZE, 0400, NULL, &arlan_sysctl_info18},
954 	{153, "arlan2-ring", &arlan_drive_info,
955 	 ARLAN_STR_SIZE, 0400, NULL, &arlan_sysctl_info161719},
956 	{154, "arlan2-shm-cpy", &arlan_drive_info,
957 	 ARLAN_STR_SIZE, 0400, NULL, &arlan_sysctl_info},
958 #endif
959 	{155, "config2", &conf_reset_result,
960 	 100, 0400, NULL, &arlan_configure},
961 	{156, "reset2", &conf_reset_result,
962 	 100, 0400, NULL, &arlan_sysctl_reset},
963 	{0}
964 };
965 
966 static ctl_table arlan_conf_table3[] =
967 {
968 
969 	ARLAN_SYSCTL_TABLE_TOTAL(3)
970 
971 #ifdef ARLAN_PROC_SHM_DUMP
972 	{150, "arlan3-txRing", &arlan_drive_info,
973 	 ARLAN_STR_SIZE, 0400, NULL, &arlan_sysctl_infotxRing},
974 	{151, "arlan3-rxRing", &arlan_drive_info,
975 	 ARLAN_STR_SIZE, 0400, NULL, &arlan_sysctl_inforxRing},
976 	{152, "arlan3-18", &arlan_drive_info,
977 	 ARLAN_STR_SIZE, 0400, NULL, &arlan_sysctl_info18},
978 	{153, "arlan3-ring", &arlan_drive_info,
979 	 ARLAN_STR_SIZE, 0400, NULL, &arlan_sysctl_info161719},
980 	{154, "arlan3-shm-cpy", &arlan_drive_info,
981 	 ARLAN_STR_SIZE, 0400, NULL, &arlan_sysctl_info},
982 #endif
983 	{155, "config3", &conf_reset_result,
984 	 100, 0400, NULL, &arlan_configure},
985 	{156, "reset3", &conf_reset_result,
986 	 100, 0400, NULL, &arlan_sysctl_reset},
987 	{0}
988 };
989 
990 
991 
992 static ctl_table arlan_table[] =
993 {
994 	{0, "arlan0", NULL, 0, 0600, arlan_conf_table0},
995 	{0, "arlan1", NULL, 0, 0600, arlan_conf_table1},
996 	{0, "arlan2", NULL, 0, 0600, arlan_conf_table2},
997 	{0, "arlan3", NULL, 0, 0600, arlan_conf_table3},
998 	{0}
999 };
1000 
1001 #else
1002 
1003 static ctl_table arlan_table[MAX_ARLANS + 1] =
1004 {
1005 	{0}
1006 };
1007 #endif
1008 #else
1009 
1010 static ctl_table arlan_table[MAX_ARLANS + 1] =
1011 {
1012 	{0}
1013 };
1014 #endif
1015 
1016 
1017 // static int mmtu = 1234;
1018 
1019 static ctl_table arlan_root_table[] =
1020 {
1021 	{254, "arlan", NULL, 0, 0555, arlan_table},
1022 	{0}
1023 };
1024 
1025 /* Make sure that /proc/sys/dev is there */
1026 //static ctl_table arlan_device_root_table[] =
1027 //{
1028 //	{CTL_DEV, "dev", NULL, 0, 0555, arlan_root_table},
1029 //	{0}
1030 //};
1031 
1032 
1033 
1034 static struct ctl_table_header *arlan_device_sysctl_header;
1035 
init_arlan_proc(void)1036 int init_arlan_proc(void)
1037 {
1038 
1039 	int i = 0;
1040 	if (arlan_device_sysctl_header)
1041 		return 0;
1042 	for (i = 0; i < MAX_ARLANS && arlan_device[i]; i++)
1043 		arlan_table[i].ctl_name = i + 1;
1044 	arlan_device_sysctl_header = register_sysctl_table(arlan_root_table, 0);
1045 	if (!arlan_device_sysctl_header)
1046 		return -1;
1047 
1048 	return 0;
1049 
1050 };
1051 
1052 
1053 
1054 #ifdef MODULE
1055 
init_module(void)1056 int init_module(void)
1057 {
1058 
1059 	return init_arlan_proc();
1060 };
1061 
cleanup_module(void)1062 void cleanup_module(void)
1063 {
1064 	unregister_sysctl_table(arlan_device_sysctl_header);
1065 	arlan_device_sysctl_header = NULL;
1066 
1067 	return;
1068 };
1069 
1070 #endif				// MODULE
1071 MODULE_LICENSE("GPL");
1072