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 int arlan_entry_debug; 51 extern int arlan_exit_debug; 52 extern int testMemory; 53 extern const char* arlan_version; 54 extern int arlan_command(struct net_device * dev, int command); 55 56 #define SIDUNKNOWN -1 57 #define radioNodeIdUNKNOWN -1 58 #define encryptionKeyUNKNOWN '\0'; 59 #define irqUNKNOWN 0 60 #define memUNKNOWN 0 61 #define debugUNKNOWN 0 62 #define probeUNKNOWN 1 63 #define numDevicesUNKNOWN 1 64 #define testMemoryUNKNOWN 1 65 #define spreadingCodeUNKNOWN 0 66 #define channelNumberUNKNOWN 0 67 #define channelSetUNKNOWN 0 68 #define systemIdUNKNOWN -1 69 #define registrationModeUNKNOWN -1 70 #define siteNameUNKNOWN "LinuxSite" 71 72 73 74 #define IFDEBUG( L ) if ( (L) & arlan_debug ) 75 #define ARLAN_FAKE_HDR_LEN 12 76 77 #ifdef ARLAN_DEBUGGING 78 #define DEBUG 1 79 #define ARLAN_ENTRY_EXIT_DEBUGGING 1 80 #define ARLAN_DEBUG(a,b) printk(KERN_DEBUG a, b) 81 #else 82 #define ARLAN_DEBUG(a,b) 83 #endif 84 85 struct arlan_shmem 86 { 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]; 101 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]; 109 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]; 120 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]; 137 138 /* System Parameter Block */ 139 140 /* - Driver Parameters (Novell Specific) */ 141 142 volatile u_short txTimeout; 143 volatile u_short transportTime; 144 volatile u_char _8[4]; 145 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]; 176 177 /* Scrambled Area */ 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; 186 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]; 201 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]; 209 210 /* Statistics Block - 0x0300 */ 211 volatile u_char hostcpuLock; 212 volatile u_char lancpuLock; 213 volatile u_char resetTime[18]; 214 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]; 221 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 */ 226 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]; 245 246 volatile u_char _19[0x86]; 247 248 volatile u_char txBuffer[0x800]; 249 volatile u_char rxBuffer[0x800]; 250 251 volatile u_char _20[0x800]; 252 volatile u_char _21[0x3fb]; 253 volatile u_char configStatus; 254 volatile u_char _22; 255 volatile u_char progIOCtrl; 256 volatile u_char shareMBase; 257 volatile u_char controlRegister; 258 }; 259 260 struct arlan_conf_stru { 261 int spreadingCode; 262 int channelSet; 263 int channelNumber; 264 int scramblingDisable; 265 int txAttenuation; 266 int systemId; 267 int maxDatagramSize; 268 int maxFrameSize; 269 int maxRetries; 270 int receiveMode; 271 int priority; 272 int rootOrRepeater; 273 int SID; 274 int radioNodeId; 275 int registrationMode; 276 int registrationFill; 277 int localTalkAddress; 278 int codeFormat; 279 int numChannels; 280 int channel1; 281 int channel2; 282 int channel3; 283 int channel4; 284 int txClear; 285 int txRetries; 286 int txRouting; 287 int txScrambled; 288 int rxParameter; 289 int txTimeoutMs; 290 int txAckTimeoutMs; 291 int waitCardTimeout; 292 int waitTime; 293 int lParameter; 294 int _15; 295 int headerSize; 296 int async; 297 int retries; 298 int tx_delay_ms; 299 int waitReTransmitPacketMaxSize; 300 int ReTransmitPacketMaxSize; 301 int fastReTransCount; 302 int driverRetransmissions; 303 int registrationInterrupts; 304 int hardwareType; 305 int radioType; 306 int writeRadioType; 307 int writeEEPROM; 308 char siteName[17]; 309 int measure_rate; 310 int in_speed; 311 int out_speed; 312 int in_speed10; 313 int out_speed10; 314 int in_speed_max; 315 int out_speed_max; 316 int pre_Command_Wait; 317 int rx_tweak1; 318 int rx_tweak2; 319 int tx_queue_len; 320 }; 321 322 extern struct arlan_conf_stru arlan_conf[MAX_ARLANS]; 323 324 struct TxParam 325 { 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; 333 }; 334 335 struct TxRingPoint { 336 struct TxParam txParam; 337 338 339 }; 340 341 #define TX_RING_SIZE 2 342 /* Information that need to be kept for each board. */ 343 struct arlan_private { 344 struct net_device_stats stats; 345 long open_time; /* Useless example local info. */ 346 struct arlan_shmem * card; 347 struct arlan_shmem * conf; 348 struct TxParam txParam; 349 int multicastLength; 350 char multicastList[ARLAN_MAX_MULTICAST_ADDRS][6]; 351 int promiscModeEnabled; 352 struct arlan_conf_stru * Conf; 353 int bad; 354 int reset; 355 long long lastReset; 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; 361 atomic_t card_users; 362 atomic_t delay_on; 363 atomic_t retr_on; 364 int registrationLostCount; 365 int reRegisterExp; 366 int nof_tx; 367 int nof_tx_ack; 368 int last_nof_tx; 369 int last_nof_tx_ack; 370 int irq_test_done; 371 int last_command_was_rx; 372 struct TxParam txRing[TX_RING_SIZE]; 373 char reTransmitBuff[0x800]; 374 volatile int txLast; 375 volatile int txNew; 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 long 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 long tx_command_given; 400 volatile long 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; 404 int in_bytes; 405 int out_bytes; 406 int in_time; 407 int out_time; 408 int in_time10; 409 int out_time10; 410 int in_bytes10; 411 int out_bytes10; 412 }; 413 414 415 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 423 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 434 435 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]) 439 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) 444 445 #define READSHM(to,from,atype) {\ 446 atype tmp;\ 447 memcpy_fromio(&(tmp),&(from),sizeof(atype));\ 448 to = tmp;\ 449 } 450 451 #define READSHMEM(from,atype)\ 452 atype from; \ 453 READSHM(from, arlan->from, atype); 454 455 #define WRITESHM(to,from,atype) \ 456 { atype tmpSHM = from;\ 457 memcpy_toio(&(to),&tmpSHM,sizeof(atype));\ 458 } 459 460 #define DEBUGSHM(levelSHM,stringSHM,stuff,atype) \ 461 { atype tmpSHM; \ 462 memcpy_fromio(&tmpSHM,&(stuff),sizeof(atype));\ 463 IFDEBUG(levelSHM) printk(stringSHM,tmpSHM);\ 464 } 465 466 #define WRITESHMB(to, val) \ 467 writeb(val,&(to)) 468 #define READSHMB(to) \ 469 readb(&(to)) 470 #define WRITESHMS(to, val) \ 471 writew(val,&(to)) 472 #define READSHMS(to) \ 473 readw(&(to)) 474 #define WRITESHMI(to, val) \ 475 writel(val,&(to)) 476 #define READSHMI(to) \ 477 readl(&(to)) 478 479 480 481 482 483 #define registrationBad(dev)\ 484 ( ( READSHMB(((struct arlan_private *)dev->priv)->card->registrationMode) > 0) && \ 485 ( READSHMB(((struct arlan_private *)dev->priv)->card->registrationStatus) == 0) ) 486 487 488 #define readControlRegister(dev)\ 489 READSHMB(((struct arlan_private *)dev->priv)->card->cntrlRegImage) 490 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) );} 494 495 496 #define arlan_interrupt_lancpu(dev) {\ 497 int cr; \ 498 \ 499 priv->under_toggle++; \ 500 cr = readControlRegister(dev);\ 501 if (cr & ARLAN_CHANNEL_ATTENTION){ \ 502 writeControlRegister(dev, (cr & ~ARLAN_CHANNEL_ATTENTION));\ 503 }else \ 504 writeControlRegister(dev, (cr | ARLAN_CHANNEL_ATTENTION));\ 505 priv->under_toggle=0; \ 506 } 507 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 ); } 531 532 533 534 535 #define ARLAN_COMMAND_RX 0x000001 536 #define ARLAN_COMMAND_NOOP 0x000002 537 #define ARLAN_COMMAND_NOOPINT 0x000004 538 #define ARLAN_COMMAND_TX 0x000008 539 #define ARLAN_COMMAND_CONF 0x000010 540 #define ARLAN_COMMAND_RESET 0x000020 541 #define ARLAN_COMMAND_TX_ABORT 0x000040 542 #define ARLAN_COMMAND_RX_ABORT 0x000080 543 #define ARLAN_COMMAND_POWERDOWN 0x000100 544 #define ARLAN_COMMAND_POWERUP 0x000200 545 #define ARLAN_COMMAND_SLOW_POLL 0x000400 546 #define ARLAN_COMMAND_ACTIVATE 0x000800 547 #define ARLAN_COMMAND_INT_ACK 0x001000 548 #define ARLAN_COMMAND_INT_ENABLE 0x002000 549 #define ARLAN_COMMAND_WAIT_NOW 0x004000 550 #define ARLAN_COMMAND_LONG_WAIT_NOW 0x008000 551 #define ARLAN_COMMAND_STANDBY 0x010000 552 #define ARLAN_COMMAND_INT_RACK 0x020000 553 #define ARLAN_COMMAND_INT_RENABLE 0x040000 554 #define ARLAN_COMMAND_CONF_WAIT 0x080000 555 #define ARLAN_COMMAND_TBUSY_CLEAR 0x100000 556 #define ARLAN_COMMAND_CLEAN_AND_CONF (ARLAN_COMMAND_TX_ABORT\ 557 | ARLAN_COMMAND_RX_ABORT\ 558 | ARLAN_COMMAND_CONF) 559 #define ARLAN_COMMAND_CLEAN_AND_RESET (ARLAN_COMMAND_TX_ABORT\ 560 | ARLAN_COMMAND_RX_ABORT\ 561 | ARLAN_COMMAND_RESET) 562 563 564 565 #define ARLAN_DEBUG_CHAIN_LOCKS 0x00001 566 #define ARLAN_DEBUG_RESET 0x00002 567 #define ARLAN_DEBUG_TIMING 0x00004 568 #define ARLAN_DEBUG_CARD_STATE 0x00008 569 #define ARLAN_DEBUG_TX_CHAIN 0x00010 570 #define ARLAN_DEBUG_MULTICAST 0x00020 571 #define ARLAN_DEBUG_HEADER_DUMP 0x00040 572 #define ARLAN_DEBUG_INTERRUPT 0x00080 573 #define ARLAN_DEBUG_STARTUP 0x00100 574 #define ARLAN_DEBUG_SHUTDOWN 0x00200 575 576