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