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