2 * Copyright (C) 1997 Cullen Jennings
3 * Copyright (C) 1998 Elmer.Joandi@ut.ee, +37-255-13500
4 * Gnu 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/malloc.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>
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 static int arlan_debug
;
50 static char * siteName
;
51 static int arlan_entry_debug
;
52 static int arlan_exit_debug
;
53 static int arlan_entry_and_exit_debug
;
54 static int testMemory
;
55 static const char* arlan_version
;
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
79 #define ARLAN_ENTRY_EXIT_DEBUGING 1
80 #define ARLAN_DEBUG(a,b) printk(KERN_DEBUG a, b)
82 #define ARLAN_DEBUG(a,b)
87 /* Header Signature */
88 volatile char textRegion
[48];
89 volatile u_char resetFlag
;
90 volatile u_char diagnosticInfo
;
91 volatile u_short diagnosticOffset
;
92 volatile u_char _1
[12];
93 volatile u_char lanCardNodeId
[6];
94 volatile u_char broadcastAddress
[6];
95 volatile u_char hardwareType
;
96 volatile u_char majorHardwareVersion
;
97 volatile u_char minorHardwareVersion
;
98 volatile u_char radioModule
;// shows EEPROM, can be overridden at 0x111
99 volatile u_char defaultChannelSet
; // shows EEProm, can be overriiden at 0x10A
100 volatile u_char _2
[47];
102 /* Control/Status Block - 0x0080 */
103 volatile u_char interruptInProgress
; /* not used by lancpu */
104 volatile u_char cntrlRegImage
; /* not used by lancpu */
105 volatile u_char _3
[13];
106 volatile u_char dumpByte
;
107 volatile u_char commandByte
; /* non-zero = active */
108 volatile u_char commandParameter
[15];
110 /* Receive Status - 0x00a0 */
111 volatile u_char rxStatus
; /* 1- data, 2-control, 0xff - registr change */
112 volatile u_char rxFrmType
;
113 volatile u_short rxOffset
;
114 volatile u_short rxLength
;
115 volatile u_char rxSrc
[6];
116 volatile u_char rxBroadcastFlag
;
117 volatile u_char rxQuality
;
118 volatile u_char scrambled
;
119 volatile u_char _4
[1];
121 /* Transmit Status - 0x00b0 */
122 volatile u_char txStatus
;
123 volatile u_char txAckQuality
;
124 volatile u_char numRetries
;
125 volatile u_char _5
[14];
126 volatile u_char registeredRouter
[6];
127 volatile u_char backboneRouter
[6];
128 volatile u_char registrationStatus
;
129 volatile u_char configuredStatusFlag
;
130 volatile u_char _6
[1];
131 volatile u_char ultimateDestAddress
[6];
132 volatile u_char immedDestAddress
[6];
133 volatile u_char immedSrcAddress
[6];
134 volatile u_short rxSequenceNumber
;
135 volatile u_char assignedLocaltalkAddress
;
136 volatile u_char _7
[27];
138 /* System Parameter Block */
140 /* - Driver Parameters (Novell Specific) */
142 volatile u_short txTimeout
;
143 volatile u_short transportTime
;
144 volatile u_char _8
[4];
146 /* - Configuration Parameters */
147 volatile u_char irqLevel
;
148 volatile u_char spreadingCode
;
149 volatile u_char channelSet
;
150 volatile u_char channelNumber
;
151 volatile u_short radioNodeId
;
152 volatile u_char _9
[2];
153 volatile u_char scramblingDisable
;
154 volatile u_char radioType
;
155 volatile u_short routerId
;
156 volatile u_char _10
[9];
157 volatile u_char txAttenuation
;
158 volatile u_char systemId
[4];
159 volatile u_short globalChecksum
;
160 volatile u_char _11
[4];
161 volatile u_short maxDatagramSize
;
162 volatile u_short maxFrameSize
;
163 volatile u_char maxRetries
;
164 volatile u_char receiveMode
;
165 volatile u_char priority
;
166 volatile u_char rootOrRepeater
;
167 volatile u_char specifiedRouter
[6];
168 volatile u_short fastPollPeriod
;
169 volatile u_char pollDecay
;
170 volatile u_char fastPollDelay
[2];
171 volatile u_char arlThreshold
;
172 volatile u_char arlDecay
;
173 volatile u_char _12
[1];
174 volatile u_short specRouterTimeout
;
175 volatile u_char _13
[5];
178 volatile u_char SID
[4];
179 volatile u_char encryptionKey
[12];
180 volatile u_char _14
[2];
181 volatile u_char waitTime
[2];
182 volatile u_char lParameter
[2];
183 volatile u_char _15
[3];
184 volatile u_short headerSize
;
185 volatile u_short sectionChecksum
;
187 volatile u_char registrationMode
;
188 volatile u_char registrationFill
;
189 volatile u_short pollPeriod
;
190 volatile u_short refreshPeriod
;
191 volatile u_char name
[16];
192 volatile u_char NID
[6];
193 volatile u_char localTalkAddress
;
194 volatile u_char codeFormat
;
195 volatile u_char numChannels
;
196 volatile u_char channel1
;
197 volatile u_char channel2
;
198 volatile u_char channel3
;
199 volatile u_char channel4
;
200 volatile u_char SSCode
[59];
202 volatile u_char _16
[0xC0];
203 volatile u_short auxCmd
;
204 volatile u_char dumpPtr
[4];
205 volatile u_char dumpVal
;
206 volatile u_char _17
[0x6A];
207 volatile u_char wireTest
;
208 volatile u_char _18
[14];
210 /* Statistics Block - 0x0300 */
211 volatile u_char hostcpuLock
;
212 volatile u_char lancpuLock
;
213 volatile u_char resetTime
[18];
215 volatile u_char numDatagramsTransmitted
[4];
216 volatile u_char numReTransmissions
[4];
217 volatile u_char numFramesDiscarded
[4];
218 volatile u_char numDatagramsReceived
[4];
219 volatile u_char numDuplicateReceivedFrames
[4];
220 volatile u_char numDatagramsDiscarded
[4];
222 volatile u_short maxNumReTransmitDatagram
;
223 volatile u_short maxNumReTransmitFrames
;
224 volatile u_short maxNumConsecutiveDuplicateFrames
;
225 /* misaligned here so we have to go to characters */
227 volatile u_char numBytesTransmitted
[4];
228 volatile u_char numBytesReceived
[4];
229 volatile u_char numCRCErrors
[4];
230 volatile u_char numLengthErrors
[4];
231 volatile u_char numAbortErrors
[4];
232 volatile u_char numTXUnderruns
[4];
233 volatile u_char numRXOverruns
[4];
234 volatile u_char numHoldOffs
[4];
235 volatile u_char numFramesTransmitted
[4];
236 volatile u_char numFramesReceived
[4];
237 volatile u_char numReceiveFramesLost
[4];
238 volatile u_char numRXBufferOverflows
[4];
239 volatile u_char numFramesDiscardedAddrMismatch
[4];
240 volatile u_char numFramesDiscardedSIDMismatch
[4];
241 volatile u_char numPollsTransmistted
[4];
242 volatile u_char numPollAcknowledges
[4];
243 volatile u_char numStatusTimeouts
[4];
244 volatile u_char numNACKReceived
[4];
246 volatile u_char _19
[0x86];
248 volatile u_char txBuffer
[0x800];
249 volatile u_char rxBuffer
[0x800];
251 volatile u_char _20
[0x800];
252 volatile u_char _21
[0x3fb];
253 volatile u_char configStatus
;
255 volatile u_char progIOCtrl
;
256 volatile u_char shareMBase
;
257 volatile u_char controlRegister
;
260 struct arlan_conf_stru
{
264 int scramblingDisable
;
275 int registrationMode
;
276 int registrationFill
;
277 int localTalkAddress
;
299 int waitReTransmitPacketMaxSize
;
300 int ReTransmitPacketMaxSize
;
301 int fastReTransCount
;
302 int driverRetransmissions
;
303 int registrationInterrupts
;
316 int pre_Command_Wait
;
322 struct arlan_conf_stru arlan_conf
[MAX_ARLANS
];
326 volatile short offset
;
327 volatile short length
;
328 volatile u_char dest
[6];
329 volatile unsigned char clear
;
330 volatile unsigned char retries
;
331 volatile unsigned char routing
;
332 volatile unsigned char scrambled
;
336 struct TxParam txParam
;
341 #define TX_RING_SIZE 2
342 /* Information that need to be kept for each board. */
343 struct arlan_private
{
344 struct enet_statistics stats
;
345 long open_time
; /* Useless example local info. */
346 struct arlan_shmem
* card
;
347 struct arlan_shmem
* conf
;
348 struct TxParam txParam
;
350 char multicastList
[ARLAN_MAX_MULTICAST_ADDRS
][6];
351 int promiscModeEnabled
;
352 struct arlan_conf_stru
* Conf
;
356 struct timer_list timer
;
357 struct timer_list tx_delay_timer
;
358 struct timer_list tx_retry_timer
;
359 struct timer_list rx_check_timer
;
360 struct semaphore card_lock
;
364 int registrationLostCount
;
371 int last_command_was_rx
;
372 struct TxParam txRing
[TX_RING_SIZE
];
373 char reTransmitBuff
[0x800];
376 volatile int txOffset
;
377 volatile char ReTransmitRequested
;
378 volatile long long tx_done_delayed
;
379 volatile long long registrationLastSeen
;
380 volatile char under_command
;
381 volatile char under_toggle
;
382 volatile long long tx_last_sent
;
383 volatile long long tx_last_cleared
;
384 volatile u_char under_tx
;
385 volatile int retransmissions
;
386 volatile int tx_chain_active
;
387 volatile int timer_chain_active
;
388 volatile int interrupt_ack_requested
;
389 volatile int command_lock
;
390 volatile int rx_command_needed
;
391 volatile int tx_command_needed
;
392 volatile int waiting_command_mask
;
393 volatile int card_polling_interval
;
394 volatile int last_command_buff_free_time
;
395 volatile int numResets
;
396 volatile int under_reset
;
397 volatile int under_config
;
398 volatile int rx_command_given
;
399 volatile int tx_command_given
;
400 volatile int interrupt_processing_active
;
401 volatile long long last_tx_time
;
402 volatile long long last_rx_time
;
403 volatile long long last_rx_int_ack_time
;
416 #define ARLAN_CLEAR 0x00
417 #define ARLAN_RESET 0x01
418 #define ARLAN_CHANNEL_ATTENTION 0x02
419 #define ARLAN_INTERRUPT_ENABLE 0x04
420 #define ARLAN_CLEAR_INTERRUPT 0x08
421 #define ARLAN_POWER 0x40
422 #define ARLAN_ACCESS 0x80
424 #define ARLAN_COM_CONF 0x01
425 #define ARLAN_COM_RX_ENABLE 0x03
426 #define ARLAN_COM_RX_ABORT 0x04
427 #define ARLAN_COM_TX_ENABLE 0x05
428 #define ARLAN_COM_TX_ABORT 0x06
429 #define ARLAN_COM_NOP 0x07
430 #define ARLAN_COM_STANDBY 0x08
431 #define ARLAN_COM_ACTIVATE 0x09
432 #define ARLAN_COM_GOTO_SLOW_POLL 0x0a
433 #define ARLAN_COM_INT 0x80
436 #define TXLAST(dev) (((struct arlan_private *)dev->priv)->txRing[((struct arlan_private *)dev->priv)->txLast])
437 #define TXHEAD(dev) (((struct arlan_private *)dev->priv)->txRing[0])
438 #define TXTAIL(dev) (((struct arlan_private *)dev->priv)->txRing[1])
440 #define TXBuffStart(dev) \
441 ((int)(((struct arlan_private *)dev->priv)->card)->txBuffer) - ((int)(((struct arlan_private *)dev->priv)->card) )
442 #define TXBuffEnd(dev) \
443 ((int)(((struct arlan_private *)dev->priv)->card)->rxBuffer) - ((int)(((struct arlan_private *)dev->priv)->card)
445 #define READSHM(to,from,atype) {\
447 memcpy_fromio(&(tmp),&(from),sizeof(atype));\
451 #define READSHMEM(from,atype)\
453 READSHM(from, arlan->from, atype);
455 #define WRITESHM(to,from,atype) \
456 { atype tmpSHM = from;\
457 memcpy_toio(&(to),&tmpSHM,sizeof(atype));\
460 #define DEBUGSHM(levelSHM,stringSHM,stuff,atype) \
462 memcpy_fromio(&tmpSHM,&(stuff),sizeof(atype));\
463 IFDEBUG(levelSHM) printk(stringSHM,tmpSHM);\
466 #define WRITESHMB(to, val) \
468 #define READSHMB(to) \
470 #define WRITESHMS(to, val) \
472 #define READSHMS(to) \
474 #define WRITESHMI(to, val) \
476 #define READSHMI(to) \
483 #define registrationBad(dev)\
484 ( ( READSHMB(((struct arlan_private *)dev->priv)->card->registrationMode) > 0) && \
485 ( READSHMB(((struct arlan_private *)dev->priv)->card->registrationStatus) == 0) )
488 #define readControlRegister(dev)\
489 READSHMB(((struct arlan_private *)dev->priv)->card->cntrlRegImage)
491 #define writeControlRegister(dev, v){\
492 WRITESHMB(((struct arlan_private *)dev->priv)->card->cntrlRegImage ,((v) &0xF) );\
493 WRITESHMB(((struct arlan_private *)dev->priv)->card->controlRegister ,(v) );}
496 #define arlan_interrupt_lancpu(dev) {\
499 priv->under_toggle++; \
500 cr = readControlRegister(dev);\
501 if (cr & ARLAN_CHANNEL_ATTENTION){ \
502 writeControlRegister(dev, (cr & ~ARLAN_CHANNEL_ATTENTION));\
504 writeControlRegister(dev, (cr | ARLAN_CHANNEL_ATTENTION));\
505 priv->under_toggle=0; \
508 #define clearChannelAttention(dev){ \
509 writeControlRegister(dev,readControlRegister(dev) & ~ARLAN_CHANNEL_ATTENTION);}
510 #define setHardwareReset(dev) {\
511 writeControlRegister(dev,readControlRegister(dev) | ARLAN_RESET);}
512 #define clearHardwareReset(dev) {\
513 writeControlRegister(dev,readControlRegister(dev) & ~ARLAN_RESET);}
514 #define setInterruptEnable(dev){\
515 writeControlRegister(dev,readControlRegister(dev) | ARLAN_INTERRUPT_ENABLE) ;}
516 #define clearInterruptEnable(dev){\
517 writeControlRegister(dev,readControlRegister(dev) & ~ARLAN_INTERRUPT_ENABLE) ;}
518 #define setClearInterrupt(dev){\
519 writeControlRegister(dev,readControlRegister(dev) | ARLAN_CLEAR_INTERRUPT) ;}
520 #define clearClearInterrupt(dev){\
521 writeControlRegister(dev,readControlRegister(dev) & ~ARLAN_CLEAR_INTERRUPT);}
522 #define setPowerOff(dev){\
523 writeControlRegister(dev,readControlRegister(dev) | (ARLAN_POWER && ARLAN_ACCESS));\
524 writeControlRegister(dev,readControlRegister(dev) & ~ARLAN_ACCESS);}
525 #define setPowerOn(dev){\
526 writeControlRegister(dev,readControlRegister(dev) & ~(ARLAN_POWER)); }
527 #define arlan_lock_card_access(dev){\
528 writeControlRegister(dev,readControlRegister(dev) & ~ARLAN_ACCESS);}
529 #define arlan_unlock_card_access(dev){\
530 writeControlRegister(dev,readControlRegister(dev) | ARLAN_ACCESS ); }
535 #define ARLAN_COMMAND_RX 0x00001
536 #define ARLAN_COMMAND_NOOP 0x00002
537 #define ARLAN_COMMAND_NOOPINT 0x00004
538 #define ARLAN_COMMAND_TX 0x00008
539 #define ARLAN_COMMAND_CONF 0x00010
540 #define ARLAN_COMMAND_RESET 0x00020
541 #define ARLAN_COMMAND_TX_ABORT 0x00040
542 #define ARLAN_COMMAND_RX_ABORT 0x00080
543 #define ARLAN_COMMAND_POWERDOWN 0x00100
544 #define ARLAN_COMMAND_POWERUP 0x00200
545 #define ARLAN_COMMAND_SLOW_POLL 0x00400
546 #define ARLAN_COMMAND_ACTIVATE 0x00800
547 #define ARLAN_COMMAND_INT_ACK 0x01000
548 #define ARLAN_COMMAND_INT_ENABLE 0x02000
549 #define ARLAN_COMMAND_WAIT_NOW 0x04000
550 #define ARLAN_COMMAND_LONG_WAIT_NOW 0x08000
551 #define ARLAN_COMMAND_STANDBY 0x10000
552 #define ARLAN_COMMAND_INT_RACK 0x20000
553 #define ARLAN_COMMAND_INT_RENABLE 0x40000
554 #define ARLAN_COMMAND_CONF_WAIT 0x80000
555 #define ARLAN_COMMAND_CLEAN_AND_CONF (ARLAN_COMMAND_TX_ABORT\
556 | ARLAN_COMMAND_RX_ABORT\
557 | ARLAN_COMMAND_CONF)
558 #define ARLAN_COMMAND_CLEAN_AND_RESET (ARLAN_COMMAND_TX_ABORT\
559 | ARLAN_COMMAND_RX_ABORT\
560 | ARLAN_COMMAND_RESET)
564 #define ARLAN_DEBUG_CHAIN_LOCKS 0x00001
565 #define ARLAN_DEBUG_RESET 0x00002
566 #define ARLAN_DEBUG_TIMING 0x00004
567 #define ARLAN_DEBUG_CARD_STATE 0x00008
568 #define ARLAN_DEBUG_TX_CHAIN 0x00010
569 #define ARLAN_DEBUG_MULTICAST 0x00020
570 #define ARLAN_DEBUG_HEADER_DUMP 0x00040
571 #define ARLAN_DEBUG_INTERRUPT 0x00080
572 #define ARLAN_DEBUG_STARTUP 0x00100
573 #define ARLAN_DEBUG_SHUTDOWN 0x00200