2 * Copyright (C) 1997 Cullen Jennings
3 * Copyright (C) 1998 Elmer.Joandi@ut.ee, +37-255-13500
4 * GNU General Public License applies
6 #include <linux/version.h>
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>
18 #include <linux/slab.h>
19 #include <linux/string.h>
20 #include <linux/timer.h>
22 #include <linux/init.h>
23 #include <asm/system.h>
24 #include <asm/bitops.h>
26 #include <linux/errno.h>
27 #include <linux/delay.h>
28 #include <linux/netdevice.h>
29 #include <linux/etherdevice.h>
32 //#define ARLAN_DEBUGGING 1
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 */
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
45 extern int init_arlan_proc(void);
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);
58 #define radioNodeIdUNKNOWN -1
59 #define encryptionKeyUNKNOWN '\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"
75 #define IFDEBUG( L ) if ( (L) & arlan_debug )
76 #define ARLAN_FAKE_HDR_LEN 12
78 #ifdef ARLAN_DEBUGGING
80 #define ARLAN_ENTRY_EXIT_DEBUGGING 1
81 #define ARLAN_DEBUG(a,b) printk(KERN_DEBUG a, b)
83 #define ARLAN_DEBUG(a,b)
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];
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];
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];
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];
139 /* System Parameter Block */
141 /* - Driver Parameters (Novell Specific) */
143 volatile u_short txTimeout;
144 volatile u_short transportTime;
145 volatile u_char _8[4];
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];
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;
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];
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];
211 /* Statistics Block - 0x0300 */
212 volatile u_char hostcpuLock;
213 volatile u_char lancpuLock;
214 volatile u_char resetTime[18];
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];
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 */
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];
247 volatile u_char _19[0x86];
249 volatile u_char txBuffer[0x800];
250 volatile u_char rxBuffer[0x800];
252 volatile u_char _20[0x800];
253 volatile u_char _21[0x3fb];
254 volatile u_char configStatus;
256 volatile u_char progIOCtrl;
257 volatile u_char shareMBase;
258 volatile u_char controlRegister;
261 struct arlan_conf_stru {
265 int scramblingDisable;
276 int registrationMode;
277 int registrationFill;
278 int localTalkAddress;
300 int waitReTransmitPacketMaxSize;
301 int ReTransmitPacketMaxSize;
302 int fastReTransCount;
303 int driverRetransmissions;
304 int registrationInterrupts;
317 int pre_Command_Wait;
323 extern struct arlan_conf_stru arlan_conf[MAX_ARLANS];
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;
337 struct TxParam txParam;
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;
351 char multicastList[ARLAN_MAX_MULTICAST_ADDRS][6];
352 int promiscModeEnabled;
353 struct arlan_conf_stru * Conf;
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;
365 int registrationLostCount;
372 int last_command_was_rx;
373 struct TxParam txRing[TX_RING_SIZE];
374 char reTransmitBuff[0x800];
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;
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
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
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])
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)
446 #define READSHM(to,from,atype) {\
448 memcpy_fromio(&(tmp),&(from),sizeof(atype));\
452 #define READSHMEM(from,atype)\
454 READSHM(from, arlan->from, atype);
456 #define WRITESHM(to,from,atype) \
457 { atype tmpSHM = from;\
458 memcpy_toio(&(to),&tmpSHM,sizeof(atype));\
461 #define DEBUGSHM(levelSHM,stringSHM,stuff,atype) \
463 memcpy_fromio(&tmpSHM,&(stuff),sizeof(atype));\
464 IFDEBUG(levelSHM) printk(stringSHM,tmpSHM);\
467 #define WRITESHMB(to, val) \
469 #define READSHMB(to) \
471 #define WRITESHMS(to, val) \
473 #define READSHMS(to) \
475 #define WRITESHMI(to, val) \
477 #define READSHMI(to) \
484 #define registrationBad(dev)\
485 ( ( READSHMB(((struct arlan_private *)dev->priv)->card->registrationMode) > 0) && \
486 ( READSHMB(((struct arlan_private *)dev->priv)->card->registrationStatus) == 0) )
489 #define readControlRegister(dev)\
490 READSHMB(((struct arlan_private *)dev->priv)->card->cntrlRegImage)
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) );}
497 #define arlan_interrupt_lancpu(dev) {\
500 priv->under_toggle++; \
501 cr = readControlRegister(dev);\
502 if (cr & ARLAN_CHANNEL_ATTENTION){ \
503 writeControlRegister(dev, (cr & ~ARLAN_CHANNEL_ATTENTION));\
505 writeControlRegister(dev, (cr | ARLAN_CHANNEL_ATTENTION));\
506 priv->under_toggle=0; \
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 ); }
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)
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