ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / drivers / net / wireless / arlan.h
1 /*
2  *  Copyright (C) 1997 Cullen Jennings
3  *  Copyright (C) 1998 Elmer.Joandi@ut.ee, +37-255-13500        
4  *  GNU General Public License applies
5  */
6
7 #include <linux/module.h>
8 #include <linux/config.h>
9 #include <linux/kernel.h>
10 #include <linux/types.h>
11 #include <linux/skbuff.h>
12 #include <linux/if_ether.h>     /* For the statistics structure. */
13 #include <linux/if_arp.h>       /* For ARPHRD_ETHER */
14 #include <linux/ptrace.h>
15 #include <linux/ioport.h>
16 #include <linux/in.h>
17 #include <linux/slab.h>
18 #include <linux/string.h>
19 #include <linux/timer.h>
20
21 #include <linux/init.h>
22 #include <asm/system.h>
23 #include <asm/bitops.h>
24 #include <asm/io.h>
25 #include <linux/errno.h>
26 #include <linux/delay.h>
27 #include <linux/netdevice.h>
28 #include <linux/etherdevice.h>
29
30
31 //#define ARLAN_DEBUGGING 1
32
33 #define ARLAN_PROC_INTERFACE
34 #define MAX_ARLANS 4 /* not more than 4 ! */
35 #define ARLAN_PROC_SHM_DUMP /* shows all card registers, makes driver way larger */
36
37 #define ARLAN_MAX_MULTICAST_ADDRS 16
38 #define ARLAN_RCV_CLEAN         0
39 #define ARLAN_RCV_PROMISC 1
40 #define ARLAN_RCV_CONTROL 2
41
42 #ifdef CONFIG_PROC_FS
43 extern int init_arlan_proc(void);
44 extern void cleanup_arlan_proc(void);
45 #else
46 #define init_arlan_proc()       (0)
47 #define cleanup_arlan_proc()    do { } while (0);
48 #endif
49
50 extern struct net_device *arlan_device[MAX_ARLANS];
51 extern int      arlan_debug;
52 extern int      arlan_entry_debug;
53 extern int      arlan_exit_debug;
54 extern int      testMemory;
55 extern const char* arlan_version;
56 extern int     arlan_command(struct net_device * dev, int command);
57  
58 #define SIDUNKNOWN -1
59 #define radioNodeIdUNKNOWN -1
60 #define irqUNKNOWN 0
61 #define debugUNKNOWN 0
62 #define testMemoryUNKNOWN 1
63 #define spreadingCodeUNKNOWN 0
64 #define channelNumberUNKNOWN 0
65 #define channelSetUNKNOWN 0
66 #define systemIdUNKNOWN -1
67 #define registrationModeUNKNOWN -1
68
69
70 #define IFDEBUG( L ) if ( (L) & arlan_debug ) 
71 #define ARLAN_FAKE_HDR_LEN 12 
72
73 #ifdef ARLAN_DEBUGGING
74         #define DEBUG 1
75         #define ARLAN_ENTRY_EXIT_DEBUGGING 1
76         #define ARLAN_DEBUG(a,b) printk(KERN_DEBUG a, b)
77 #else
78         #define ARLAN_DEBUG(a,b) 
79 #endif
80
81 #define ARLAN_SHMEM_SIZE        0x2000
82
83 struct arlan_shmem
84 {
85       /* Header Signature */ 
86       volatile  char textRegion[48];
87       volatile  u_char resetFlag;
88       volatile  u_char  diagnosticInfo;
89       volatile  u_short diagnosticOffset;
90       volatile  u_char _1[12];
91       volatile  u_char lanCardNodeId[6];
92       volatile  u_char broadcastAddress[6];
93       volatile  u_char hardwareType;
94       volatile  u_char majorHardwareVersion;
95       volatile  u_char minorHardwareVersion;
96       volatile  u_char radioModule;// shows EEPROM, can be overridden at 0x111
97       volatile  u_char defaultChannelSet; // shows EEProm, can be overriiden at 0x10A
98       volatile  u_char _2[47];
99       
100       /* Control/Status Block - 0x0080 */
101       volatile  u_char interruptInProgress; /* not used by lancpu */
102       volatile  u_char cntrlRegImage; /* not used by lancpu */
103       volatile  u_char _3[13];
104       volatile  u_char dumpByte;
105       volatile  u_char commandByte; /* non-zero = active */
106       volatile  u_char commandParameter[15];
107
108       /* Receive Status - 0x00a0 */
109       volatile  u_char rxStatus; /* 1- data, 2-control, 0xff - registr change */
110       volatile  u_char rxFrmType;
111       volatile  u_short rxOffset;
112       volatile  u_short rxLength;
113       volatile  u_char rxSrc[6];
114       volatile  u_char rxBroadcastFlag;
115       volatile  u_char rxQuality;
116       volatile  u_char scrambled;
117       volatile  u_char _4[1];
118       
119       /* Transmit Status - 0x00b0 */
120       volatile  u_char txStatus;
121       volatile  u_char txAckQuality;
122       volatile  u_char numRetries;
123       volatile  u_char _5[14];
124       volatile  u_char registeredRouter[6];
125       volatile  u_char backboneRouter[6];
126       volatile  u_char registrationStatus;
127       volatile  u_char configuredStatusFlag;
128       volatile  u_char _6[1];
129       volatile  u_char ultimateDestAddress[6];
130       volatile  u_char immedDestAddress[6];
131       volatile  u_char immedSrcAddress[6];
132       volatile  u_short rxSequenceNumber;
133       volatile  u_char assignedLocaltalkAddress;
134       volatile  u_char _7[27];
135
136       /* System Parameter Block */
137
138       /* - Driver Parameters (Novell Specific) */
139
140       volatile  u_short txTimeout;
141       volatile  u_short transportTime;
142       volatile  u_char _8[4];
143
144       /* - Configuration Parameters */
145       volatile  u_char irqLevel;
146       volatile  u_char spreadingCode;
147       volatile  u_char channelSet;
148       volatile  u_char channelNumber;
149       volatile  u_short radioNodeId;
150       volatile  u_char _9[2];
151       volatile  u_char scramblingDisable;
152       volatile  u_char radioType;
153       volatile  u_short routerId;
154       volatile  u_char _10[9];
155       volatile  u_char txAttenuation;
156       volatile  u_char systemId[4]; 
157       volatile  u_short globalChecksum;
158       volatile  u_char _11[4];
159       volatile  u_short maxDatagramSize;
160       volatile  u_short maxFrameSize;
161       volatile  u_char maxRetries;
162       volatile  u_char receiveMode;
163       volatile  u_char priority;
164       volatile  u_char rootOrRepeater;
165       volatile  u_char specifiedRouter[6];
166       volatile  u_short fastPollPeriod;
167       volatile  u_char pollDecay;
168       volatile  u_char fastPollDelay[2];
169       volatile  u_char arlThreshold;
170       volatile  u_char arlDecay;
171       volatile  u_char _12[1];
172       volatile  u_short specRouterTimeout;
173       volatile  u_char _13[5];
174
175       /* Scrambled Area */
176       volatile  u_char SID[4];
177       volatile  u_char encryptionKey[12];
178       volatile  u_char _14[2];
179       volatile  u_char waitTime[2];
180       volatile  u_char lParameter[2];
181       volatile  u_char _15[3];
182       volatile  u_short headerSize;
183       volatile  u_short sectionChecksum;
184
185       volatile  u_char registrationMode;
186       volatile  u_char registrationFill;
187       volatile  u_short pollPeriod;
188       volatile  u_short refreshPeriod;
189       volatile  u_char name[16];
190       volatile  u_char NID[6];
191       volatile  u_char localTalkAddress;
192       volatile  u_char codeFormat;
193       volatile  u_char numChannels;
194       volatile  u_char channel1;
195       volatile  u_char channel2;
196       volatile  u_char channel3;
197       volatile  u_char channel4;
198       volatile  u_char SSCode[59];
199
200       volatile  u_char _16[0xC0];
201       volatile  u_short auxCmd;
202       volatile  u_char  dumpPtr[4];
203       volatile  u_char dumpVal;
204       volatile  u_char _17[0x6A];
205       volatile  u_char wireTest;
206       volatile  u_char _18[14];
207
208       /* Statistics Block - 0x0300 */
209       volatile  u_char hostcpuLock;
210       volatile  u_char lancpuLock;
211       volatile  u_char resetTime[18];
212       
213       volatile  u_char numDatagramsTransmitted[4];
214       volatile  u_char numReTransmissions[4];
215       volatile  u_char numFramesDiscarded[4];
216       volatile  u_char numDatagramsReceived[4];
217       volatile  u_char numDuplicateReceivedFrames[4];
218       volatile  u_char numDatagramsDiscarded[4];
219       
220       volatile  u_short maxNumReTransmitDatagram;
221       volatile  u_short maxNumReTransmitFrames;
222       volatile  u_short maxNumConsecutiveDuplicateFrames;
223       /* misaligned here so we have to go to characters */
224      
225       volatile  u_char numBytesTransmitted[4];
226       volatile  u_char numBytesReceived[4];
227       volatile  u_char numCRCErrors[4];
228       volatile  u_char numLengthErrors[4];
229       volatile  u_char numAbortErrors[4];
230       volatile  u_char numTXUnderruns[4];
231       volatile  u_char numRXOverruns[4];
232       volatile  u_char numHoldOffs[4];
233       volatile  u_char numFramesTransmitted[4];
234       volatile  u_char numFramesReceived[4];
235       volatile  u_char numReceiveFramesLost[4];
236       volatile  u_char numRXBufferOverflows[4];
237       volatile  u_char numFramesDiscardedAddrMismatch[4];
238       volatile  u_char numFramesDiscardedSIDMismatch[4];
239       volatile  u_char numPollsTransmistted[4];
240       volatile  u_char numPollAcknowledges[4];
241       volatile  u_char numStatusTimeouts[4];
242       volatile  u_char numNACKReceived[4];
243
244       volatile  u_char _19[0x86];
245
246       volatile  u_char txBuffer[0x800];
247       volatile  u_char rxBuffer[0x800];
248
249       volatile  u_char _20[0x800];
250       volatile  u_char _21[0x3fb];
251       volatile  u_char configStatus;
252       volatile  u_char _22;
253       volatile  u_char progIOCtrl;
254       volatile  u_char shareMBase;
255       volatile  u_char controlRegister;
256 };
257
258 struct arlan_conf_stru {
259       int spreadingCode;
260       int channelSet;
261       int channelNumber;
262       int scramblingDisable;
263       int txAttenuation;
264       int systemId; 
265       int maxDatagramSize;
266       int maxFrameSize;
267       int maxRetries;
268       int receiveMode;
269       int priority;
270       int rootOrRepeater;
271       int SID;
272       int radioNodeId;
273       int registrationMode;
274       int registrationFill;
275       int localTalkAddress;
276       int codeFormat;
277       int numChannels;
278       int channel1;
279       int channel2;
280       int channel3;
281       int channel4;
282       int txClear;
283       int txRetries;
284       int txRouting;
285       int txScrambled;
286       int rxParameter;
287       int txTimeoutMs;
288       int txAckTimeoutMs;
289       int waitCardTimeout;
290       int       waitTime;
291       int       lParameter;
292       int       _15;
293       int       headerSize;
294       int retries;
295       int tx_delay_ms;
296       int waitReTransmitPacketMaxSize;
297       int ReTransmitPacketMaxSize;
298       int fastReTransCount;
299       int driverRetransmissions;
300       int registrationInterrupts;
301       int hardwareType;
302       int radioType;
303       int writeRadioType;
304       int writeEEPROM;
305       char siteName[17];
306       int measure_rate;
307       int in_speed;
308       int out_speed;
309       int in_speed10;
310       int out_speed10;
311       int in_speed_max;
312       int out_speed_max;
313       int pre_Command_Wait;
314       int rx_tweak1;
315       int rx_tweak2;
316       int tx_queue_len;
317 };
318
319 extern struct arlan_conf_stru arlan_conf[MAX_ARLANS];
320
321 struct TxParam
322 {
323       volatile  short           offset;
324       volatile  short           length;
325       volatile  u_char          dest[6];
326       volatile  unsigned        char clear;
327       volatile  unsigned        char retries;
328       volatile  unsigned        char routing;
329       volatile  unsigned        char scrambled;
330 };
331
332 #define TX_RING_SIZE 2
333 /* Information that need to be kept for each board. */
334 struct arlan_private {
335       struct net_device_stats stats;
336       struct arlan_shmem * card;
337       struct arlan_shmem * conf;
338
339       struct arlan_conf_stru * Conf;         
340       int       bad;
341       int       reset;
342       unsigned long lastReset;
343       struct timer_list timer;
344       struct timer_list tx_delay_timer;
345       struct timer_list tx_retry_timer;
346       struct timer_list rx_check_timer;
347
348       int registrationLostCount;
349       int reRegisterExp;
350       int irq_test_done;
351
352       struct TxParam txRing[TX_RING_SIZE];
353       char reTransmitBuff[0x800];
354       int txLast;
355       unsigned ReTransmitRequested;
356       unsigned long tx_done_delayed;
357       unsigned long registrationLastSeen;
358
359       unsigned long     tx_last_sent;
360       unsigned long     tx_last_cleared;
361       unsigned long     retransmissions;
362       unsigned long     interrupt_ack_requested;
363       spinlock_t        lock;
364       unsigned long     waiting_command_mask;
365       unsigned long     card_polling_interval;
366       unsigned long     last_command_buff_free_time;
367
368       int               under_reset;
369       int               under_config;
370       int               rx_command_given;
371       int               tx_command_given;
372       unsigned  long    interrupt_processing_active;
373       unsigned long     last_rx_int_ack_time;
374       unsigned long     in_bytes;
375       unsigned long     out_bytes;
376       unsigned long     in_time;
377       unsigned long     out_time;
378       unsigned long     in_time10;
379       unsigned long     out_time10;
380       unsigned long     in_bytes10;
381       unsigned long     out_bytes10;
382       int       init_etherdev_alloc;
383 };
384
385
386
387 #define ARLAN_CLEAR             0x00
388 #define ARLAN_RESET             0x01
389 #define ARLAN_CHANNEL_ATTENTION 0x02
390 #define ARLAN_INTERRUPT_ENABLE  0x04
391 #define ARLAN_CLEAR_INTERRUPT   0x08
392 #define ARLAN_POWER             0x40
393 #define ARLAN_ACCESS            0x80
394
395 #define ARLAN_COM_CONF                0x01
396 #define ARLAN_COM_RX_ENABLE           0x03
397 #define ARLAN_COM_RX_ABORT            0x04
398 #define ARLAN_COM_TX_ENABLE           0x05
399 #define ARLAN_COM_TX_ABORT            0x06
400 #define ARLAN_COM_NOP                 0x07
401 #define ARLAN_COM_STANDBY             0x08
402 #define ARLAN_COM_ACTIVATE            0x09
403 #define ARLAN_COM_GOTO_SLOW_POLL      0x0a
404 #define ARLAN_COM_INT                 0x80
405
406
407 #define TXLAST(dev) (((struct arlan_private *)dev->priv)->txRing[((struct arlan_private *)dev->priv)->txLast])
408 #define TXHEAD(dev) (((struct arlan_private *)dev->priv)->txRing[0])
409 #define TXTAIL(dev) (((struct arlan_private *)dev->priv)->txRing[1])
410
411 #define TXBuffStart(dev) \
412  ((int)(((struct arlan_private *)dev->priv)->card)->txBuffer) - ((int)(((struct arlan_private *)dev->priv)->card) )
413 #define TXBuffEnd(dev) \
414  ((int)(((struct arlan_private *)dev->priv)->card)->rxBuffer) - ((int)(((struct arlan_private *)dev->priv)->card)
415  
416 #define READSHM(to,from,atype) {\
417         atype tmp;\
418         memcpy_fromio(&(tmp),&(from),sizeof(atype));\
419         to = tmp;\
420         }
421
422 #define READSHMEM(from,atype)\
423         atype from; \
424         READSHM(from, arlan->from, atype);
425
426 #define WRITESHM(to,from,atype) \
427         { atype tmpSHM = from;\
428         memcpy_toio(&(to),&tmpSHM,sizeof(atype));\
429         }
430
431 #define DEBUGSHM(levelSHM,stringSHM,stuff,atype) \
432         {       atype tmpSHM; \
433                 memcpy_fromio(&tmpSHM,&(stuff),sizeof(atype));\
434                 IFDEBUG(levelSHM) printk(stringSHM,tmpSHM);\
435         }
436
437 #define WRITESHMB(to, val) \
438         writeb(val,&(to))
439 #define READSHMB(to) \
440         readb(&(to))
441 #define WRITESHMS(to, val) \
442         writew(val,&(to))
443 #define READSHMS(to) \
444         readw(&(to))
445 #define WRITESHMI(to, val) \
446         writel(val,&(to))
447 #define READSHMI(to) \
448         readl(&(to))
449
450
451
452
453
454 #define registrationBad(dev)\
455    ( (   READSHMB(((struct arlan_private *)dev->priv)->card->registrationMode)    > 0) && \
456      (   READSHMB(((struct arlan_private *)dev->priv)->card->registrationStatus) == 0)    )
457
458
459 #define readControlRegister(dev)\
460         READSHMB(((struct arlan_private *)dev->priv)->card->cntrlRegImage)
461
462 #define writeControlRegister(dev, v){\
463    WRITESHMB(((struct arlan_private *)dev->priv)->card->cntrlRegImage   ,((v) &0xF) );\
464    WRITESHMB(((struct arlan_private *)dev->priv)->card->controlRegister ,(v)    );}
465
466
467 #define arlan_interrupt_lancpu(dev) {\
468    int cr;   \
469    \
470    cr = readControlRegister(dev);\
471    if (cr & ARLAN_CHANNEL_ATTENTION){ \
472       writeControlRegister(dev, (cr & ~ARLAN_CHANNEL_ATTENTION));\
473    }else  \
474       writeControlRegister(dev, (cr | ARLAN_CHANNEL_ATTENTION));\
475 }
476
477 #define clearChannelAttention(dev){ \
478    writeControlRegister(dev,readControlRegister(dev) & ~ARLAN_CHANNEL_ATTENTION);}
479 #define setHardwareReset(dev) {\
480    writeControlRegister(dev,readControlRegister(dev) | ARLAN_RESET);}
481 #define clearHardwareReset(dev) {\
482    writeControlRegister(dev,readControlRegister(dev) & ~ARLAN_RESET);}
483 #define setInterruptEnable(dev){\
484    writeControlRegister(dev,readControlRegister(dev) | ARLAN_INTERRUPT_ENABLE)  ;}
485 #define clearInterruptEnable(dev){\
486    writeControlRegister(dev,readControlRegister(dev) & ~ARLAN_INTERRUPT_ENABLE)  ;}
487 #define setClearInterrupt(dev){\
488    writeControlRegister(dev,readControlRegister(dev) | ARLAN_CLEAR_INTERRUPT)   ;}
489 #define clearClearInterrupt(dev){\
490    writeControlRegister(dev,readControlRegister(dev) & ~ARLAN_CLEAR_INTERRUPT);}
491 #define setPowerOff(dev){\
492    writeControlRegister(dev,readControlRegister(dev) | (ARLAN_POWER && ARLAN_ACCESS));\
493    writeControlRegister(dev,readControlRegister(dev) & ~ARLAN_ACCESS);}
494 #define setPowerOn(dev){\
495    writeControlRegister(dev,readControlRegister(dev) & ~(ARLAN_POWER));   }
496 #define arlan_lock_card_access(dev){\
497    writeControlRegister(dev,readControlRegister(dev) & ~ARLAN_ACCESS);}
498 #define arlan_unlock_card_access(dev){\
499    writeControlRegister(dev,readControlRegister(dev) | ARLAN_ACCESS ); }  
500
501
502
503
504 #define ARLAN_COMMAND_RX                0x000001
505 #define ARLAN_COMMAND_NOOP              0x000002
506 #define ARLAN_COMMAND_NOOPINT           0x000004
507 #define ARLAN_COMMAND_TX                0x000008
508 #define ARLAN_COMMAND_CONF              0x000010
509 #define ARLAN_COMMAND_RESET             0x000020
510 #define ARLAN_COMMAND_TX_ABORT          0x000040
511 #define ARLAN_COMMAND_RX_ABORT          0x000080
512 #define ARLAN_COMMAND_POWERDOWN         0x000100
513 #define ARLAN_COMMAND_POWERUP           0x000200
514 #define ARLAN_COMMAND_SLOW_POLL         0x000400
515 #define ARLAN_COMMAND_ACTIVATE          0x000800
516 #define ARLAN_COMMAND_INT_ACK           0x001000
517 #define ARLAN_COMMAND_INT_ENABLE        0x002000
518 #define ARLAN_COMMAND_WAIT_NOW          0x004000
519 #define ARLAN_COMMAND_LONG_WAIT_NOW     0x008000
520 #define ARLAN_COMMAND_STANDBY           0x010000
521 #define ARLAN_COMMAND_INT_RACK          0x020000
522 #define ARLAN_COMMAND_INT_RENABLE       0x040000
523 #define ARLAN_COMMAND_CONF_WAIT         0x080000
524 #define ARLAN_COMMAND_TBUSY_CLEAR       0x100000
525 #define ARLAN_COMMAND_CLEAN_AND_CONF    (ARLAN_COMMAND_TX_ABORT\
526                                         | ARLAN_COMMAND_RX_ABORT\
527                                         | ARLAN_COMMAND_CONF)
528 #define ARLAN_COMMAND_CLEAN_AND_RESET   (ARLAN_COMMAND_TX_ABORT\
529                                         | ARLAN_COMMAND_RX_ABORT\
530                                         | ARLAN_COMMAND_RESET)
531
532
533  
534 #define ARLAN_DEBUG_CHAIN_LOCKS         0x00001
535 #define ARLAN_DEBUG_RESET               0x00002
536 #define ARLAN_DEBUG_TIMING              0x00004
537 #define ARLAN_DEBUG_CARD_STATE          0x00008
538 #define ARLAN_DEBUG_TX_CHAIN            0x00010
539 #define ARLAN_DEBUG_MULTICAST           0x00020
540 #define ARLAN_DEBUG_HEADER_DUMP         0x00040
541 #define ARLAN_DEBUG_INTERRUPT           0x00080
542 #define ARLAN_DEBUG_STARTUP             0x00100
543 #define ARLAN_DEBUG_SHUTDOWN            0x00200
544