1/* 2 * Copyright (C) 1997 Cullen Jennings 3 * Copyright (C) 1998 Elmer Joandiu, elmer@ylenurme.ee 4 * GNU General Public License applies 5 * This module provides support for the Arlan 655 card made by Aironet 6 */ 7 8#include "arlan.h" 9 10#if BITS_PER_LONG != 32 11# error FIXME: this driver requires a 32-bit platform 12#endif 13 14static const char *arlan_version = "C.Jennigs 97 & Elmer.Joandi@ut.ee Oct'98, http://www.ylenurme.ee/~elmer/655/"; 15 16struct net_device *arlan_device[MAX_ARLANS]; 17 18static int SID = SIDUNKNOWN; 19static int radioNodeId = radioNodeIdUNKNOWN; 20static char encryptionKey[12] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'}; 21int arlan_debug = debugUNKNOWN; 22static int spreadingCode = spreadingCodeUNKNOWN; 23static int channelNumber = channelNumberUNKNOWN; 24static int channelSet = channelSetUNKNOWN; 25static int systemId = systemIdUNKNOWN; 26static int registrationMode = registrationModeUNKNOWN; 27static int keyStart; 28static int tx_delay_ms; 29static int retries = 5; 30static int tx_queue_len = 1; 31static int arlan_EEPROM_bad; 32 33#ifdef ARLAN_DEBUGGING 34 35static int testMemory = testMemoryUNKNOWN; 36static int irq = irqUNKNOWN; 37static int txScrambled = 1; 38static int mdebug; 39 40module_param(irq, int, 0); 41module_param(mdebug, int, 0); 42module_param(testMemory, int, 0); 43module_param(txScrambled, int, 0); 44MODULE_PARM_DESC(irq, "(unused)"); 45MODULE_PARM_DESC(testMemory, "(unused)"); 46MODULE_PARM_DESC(mdebug, "Arlan multicast debugging (0-1)"); 47#endif 48 49module_param_named(debug, arlan_debug, int, 0); 50module_param(spreadingCode, int, 0); 51module_param(channelNumber, int, 0); 52module_param(channelSet, int, 0); 53module_param(systemId, int, 0); 54module_param(registrationMode, int, 0); 55module_param(radioNodeId, int, 0); 56module_param(SID, int, 0); 57module_param(keyStart, int, 0); 58module_param(tx_delay_ms, int, 0); 59module_param(retries, int, 0); 60module_param(tx_queue_len, int, 0); 61module_param_named(EEPROM_bad, arlan_EEPROM_bad, int, 0); 62MODULE_PARM_DESC(debug, "Arlan debug enable (0-1)"); 63MODULE_PARM_DESC(retries, "Arlan maximum packet retransmisions"); 64#ifdef ARLAN_ENTRY_EXIT_DEBUGGING 65static int arlan_entry_debug; 66static int arlan_exit_debug; 67static int arlan_entry_and_exit_debug; 68module_param_named(entry_debug, arlan_entry_debug, int, 0); 69module_param_named(exit_debug, arlan_exit_debug, int, 0); 70module_param_named(entry_and_exit_debug, arlan_entry_and_exit_debug, int, 0); 71MODULE_PARM_DESC(entry_debug, "Arlan driver function entry debugging"); 72MODULE_PARM_DESC(exit_debug, "Arlan driver function exit debugging"); 73MODULE_PARM_DESC(entry_and_exit_debug, "Arlan driver function entry and exit debugging"); 74#endif 75 76struct arlan_conf_stru arlan_conf[MAX_ARLANS]; 77static int arlans_found; 78 79static int arlan_open(struct net_device *dev); 80static int arlan_tx(struct sk_buff *skb, struct net_device *dev); 81static irqreturn_t arlan_interrupt(int irq, void *dev_id); 82static int arlan_close(struct net_device *dev); 83static struct net_device_stats * 84 arlan_statistics (struct net_device *dev); 85static void arlan_set_multicast (struct net_device *dev); 86static int arlan_hw_tx (struct net_device* dev, char *buf, int length ); 87static int arlan_hw_config (struct net_device * dev); 88static void arlan_tx_done_interrupt (struct net_device * dev, int status); 89static void arlan_rx_interrupt (struct net_device * dev, u_char rxStatus, u_short, u_short); 90static void arlan_process_interrupt (struct net_device * dev); 91static void arlan_tx_timeout (struct net_device *dev); 92 93static inline long us2ticks(int us) 94{ 95 return us * (1000000 / HZ); 96} 97 98 99#ifdef ARLAN_ENTRY_EXIT_DEBUGGING 100#define ARLAN_DEBUG_ENTRY(name) \ 101 {\ 102 struct timeval timev;\ 103 do_gettimeofday(&timev);\ 104 if (arlan_entry_debug || arlan_entry_and_exit_debug)\ 105 printk("--->>>" name " %ld " "\n",((long int) timev.tv_sec * 1000000 + timev.tv_usec));\ 106 } 107#define ARLAN_DEBUG_EXIT(name) \ 108 {\ 109 struct timeval timev;\ 110 do_gettimeofday(&timev);\ 111 if (arlan_exit_debug || arlan_entry_and_exit_debug)\ 112 printk("<<<---" name " %ld " "\n",((long int) timev.tv_sec * 1000000 + timev.tv_usec) );\ 113 } 114#else 115#define ARLAN_DEBUG_ENTRY(name) 116#define ARLAN_DEBUG_EXIT(name) 117#endif 118 119 120#define arlan_interrupt_ack(dev)\ 121 clearClearInterrupt(dev);\ 122 setClearInterrupt(dev); 123 124static inline int arlan_drop_tx(struct net_device *dev) 125{ 126 struct arlan_private *priv = netdev_priv(dev); 127 128 priv->stats.tx_errors++; 129 if (priv->Conf->tx_delay_ms) 130 { 131 priv->tx_done_delayed = jiffies + priv->Conf->tx_delay_ms * HZ / 1000 + 1; 132 } 133 else 134 { 135 priv->waiting_command_mask &= ~ARLAN_COMMAND_TX; 136 TXHEAD(dev).offset = 0; 137 TXTAIL(dev).offset = 0; 138 priv->txLast = 0; 139 priv->bad = 0; 140 if (!priv->under_reset && !priv->under_config) 141 netif_wake_queue (dev); 142 } 143 return 1; 144} 145 146 147int arlan_command(struct net_device *dev, int command_p) 148{ 149 struct arlan_private *priv = netdev_priv(dev); 150 volatile struct arlan_shmem __iomem *arlan = priv->card; 151 struct arlan_conf_stru *conf = priv->Conf; 152 int udelayed = 0; 153 int i = 0; 154 unsigned long flags; 155 156 ARLAN_DEBUG_ENTRY("arlan_command"); 157 158 if (priv->card_polling_interval) 159 priv->card_polling_interval = 1; 160 161 if (arlan_debug & ARLAN_DEBUG_CHAIN_LOCKS) 162 printk(KERN_DEBUG "arlan_command, %lx commandByte %x waiting %lx incoming %x \n", 163 jiffies, READSHMB(arlan->commandByte), 164 priv->waiting_command_mask, command_p); 165 166 priv->waiting_command_mask |= command_p; 167 168 if (priv->waiting_command_mask & ARLAN_COMMAND_RESET) 169 if (time_after(jiffies, priv->lastReset + 5 * HZ)) 170 priv->waiting_command_mask &= ~ARLAN_COMMAND_RESET; 171 172 if (priv->waiting_command_mask & ARLAN_COMMAND_INT_ACK) 173 { 174 arlan_interrupt_ack(dev); 175 priv->waiting_command_mask &= ~ARLAN_COMMAND_INT_ACK; 176 } 177 if (priv->waiting_command_mask & ARLAN_COMMAND_INT_ENABLE) 178 { 179 setInterruptEnable(dev); 180 priv->waiting_command_mask &= ~ARLAN_COMMAND_INT_ENABLE; 181 } 182 183 /* Card access serializing lock */ 184 spin_lock_irqsave(&priv->lock, flags); 185 186 /* Check cards status and waiting */ 187 188 if (priv->waiting_command_mask & (ARLAN_COMMAND_LONG_WAIT_NOW | ARLAN_COMMAND_WAIT_NOW)) 189 { 190 while (priv->waiting_command_mask & (ARLAN_COMMAND_LONG_WAIT_NOW | ARLAN_COMMAND_WAIT_NOW)) 191 { 192 if (READSHMB(arlan->resetFlag) || 193 READSHMB(arlan->commandByte)) /* || 194 (readControlRegister(dev) & ARLAN_ACCESS)) 195 */ 196 udelay(40); 197 else 198 priv->waiting_command_mask &= ~(ARLAN_COMMAND_LONG_WAIT_NOW | ARLAN_COMMAND_WAIT_NOW); 199 200 udelayed++; 201 202 if (priv->waiting_command_mask & ARLAN_COMMAND_LONG_WAIT_NOW) 203 { 204 if (udelayed * 40 > 1000000) 205 { 206 printk(KERN_ERR "%s long wait too long \n", dev->name); 207 priv->waiting_command_mask |= ARLAN_COMMAND_RESET; 208 break; 209 } 210 } 211 else if (priv->waiting_command_mask & ARLAN_COMMAND_WAIT_NOW) 212 { 213 if (udelayed * 40 > 1000) 214 { 215 printk(KERN_ERR "%s short wait too long \n", dev->name); 216 goto bad_end; 217 } 218 } 219 } 220 } 221 else 222 { 223 i = 0; 224 while ((READSHMB(arlan->resetFlag) || 225 READSHMB(arlan->commandByte)) && 226 conf->pre_Command_Wait > (i++) * 10) 227 udelay(10); 228 229 230 if ((READSHMB(arlan->resetFlag) || 231 READSHMB(arlan->commandByte)) && 232 !(priv->waiting_command_mask & ARLAN_COMMAND_RESET)) 233 { 234 goto card_busy_end; 235 } 236 } 237 if (priv->waiting_command_mask & ARLAN_COMMAND_RESET) 238 priv->under_reset = 1; 239 if (priv->waiting_command_mask & ARLAN_COMMAND_CONF) 240 priv->under_config = 1; 241 242 /* Issuing command */ 243 arlan_lock_card_access(dev); 244 if (priv->waiting_command_mask & ARLAN_COMMAND_POWERUP) 245 { 246 // if (readControlRegister(dev) & (ARLAN_ACCESS && ARLAN_POWER)) 247 setPowerOn(dev); 248 arlan_interrupt_lancpu(dev); 249 priv->waiting_command_mask &= ~ARLAN_COMMAND_POWERUP; 250 priv->waiting_command_mask |= ARLAN_COMMAND_RESET; 251 priv->card_polling_interval = HZ / 10; 252 } 253 else if (priv->waiting_command_mask & ARLAN_COMMAND_ACTIVATE) 254 { 255 WRITESHMB(arlan->commandByte, ARLAN_COM_ACTIVATE); 256 arlan_interrupt_lancpu(dev); 257 priv->waiting_command_mask &= ~ARLAN_COMMAND_ACTIVATE; 258 priv->card_polling_interval = HZ / 10; 259 } 260 else if (priv->waiting_command_mask & ARLAN_COMMAND_RX_ABORT) 261 { 262 if (priv->rx_command_given) 263 { 264 WRITESHMB(arlan->commandByte, ARLAN_COM_RX_ABORT); 265 arlan_interrupt_lancpu(dev); 266 priv->rx_command_given = 0; 267 } 268 priv->waiting_command_mask &= ~ARLAN_COMMAND_RX_ABORT; 269 priv->card_polling_interval = 1; 270 } 271 else if (priv->waiting_command_mask & ARLAN_COMMAND_TX_ABORT) 272 { 273 if (priv->tx_command_given) 274 { 275 WRITESHMB(arlan->commandByte, ARLAN_COM_TX_ABORT); 276 arlan_interrupt_lancpu(dev); 277 priv->tx_command_given = 0; 278 } 279 priv->waiting_command_mask &= ~ARLAN_COMMAND_TX_ABORT; 280 priv->card_polling_interval = 1; 281 } 282 else if (priv->waiting_command_mask & ARLAN_COMMAND_RESET) 283 { 284 priv->under_reset=1; 285 netif_stop_queue (dev); 286 287 arlan_drop_tx(dev); 288 if (priv->tx_command_given || priv->rx_command_given) 289 { 290 printk(KERN_ERR "%s: Reset under tx or rx command \n", dev->name); 291 } 292 netif_stop_queue (dev); 293 if (arlan_debug & ARLAN_DEBUG_RESET) 294 printk(KERN_ERR "%s: Doing chip reset\n", dev->name); 295 priv->lastReset = jiffies; 296 WRITESHM(arlan->commandByte, 0, u_char); 297 /* hold card in reset state */ 298 setHardwareReset(dev); 299 /* set reset flag and then release reset */ 300 WRITESHM(arlan->resetFlag, 0xff, u_char); 301 clearChannelAttention(dev); 302 clearHardwareReset(dev); 303 priv->card_polling_interval = HZ / 4; 304 priv->waiting_command_mask &= ~ARLAN_COMMAND_RESET; 305 priv->waiting_command_mask |= ARLAN_COMMAND_INT_RACK; 306// priv->waiting_command_mask |= ARLAN_COMMAND_INT_RENABLE; 307// priv->waiting_command_mask |= ARLAN_COMMAND_RX; 308 } 309 else if (priv->waiting_command_mask & ARLAN_COMMAND_INT_RACK) 310 { 311 clearHardwareReset(dev); 312 clearClearInterrupt(dev); 313 setClearInterrupt(dev); 314 setInterruptEnable(dev); 315 priv->waiting_command_mask &= ~ARLAN_COMMAND_INT_RACK; 316 priv->waiting_command_mask |= ARLAN_COMMAND_CONF; 317 priv->under_config = 1; 318 priv->under_reset = 0; 319 } 320 else if (priv->waiting_command_mask & ARLAN_COMMAND_INT_RENABLE) 321 { 322 setInterruptEnable(dev); 323 priv->waiting_command_mask &= ~ARLAN_COMMAND_INT_RENABLE; 324 } 325 else if (priv->waiting_command_mask & ARLAN_COMMAND_CONF) 326 { 327 if (priv->tx_command_given || priv->rx_command_given) 328 { 329 printk(KERN_ERR "%s: Reset under tx or rx command \n", dev->name); 330 } 331 arlan_drop_tx(dev); 332 setInterruptEnable(dev); 333 arlan_hw_config(dev); 334 arlan_interrupt_lancpu(dev); 335 priv->waiting_command_mask &= ~ARLAN_COMMAND_CONF; 336 priv->card_polling_interval = HZ / 10; 337// priv->waiting_command_mask |= ARLAN_COMMAND_INT_RACK; 338// priv->waiting_command_mask |= ARLAN_COMMAND_INT_ENABLE; 339 priv->waiting_command_mask |= ARLAN_COMMAND_CONF_WAIT; 340 } 341 else if (priv->waiting_command_mask & ARLAN_COMMAND_CONF_WAIT) 342 { 343 if (READSHMB(arlan->configuredStatusFlag) != 0 && 344 READSHMB(arlan->diagnosticInfo) == 0xff) 345 { 346 priv->waiting_command_mask &= ~ARLAN_COMMAND_CONF_WAIT; 347 priv->waiting_command_mask |= ARLAN_COMMAND_RX; 348 priv->waiting_command_mask |= ARLAN_COMMAND_TBUSY_CLEAR; 349 priv->card_polling_interval = HZ / 10; 350 priv->tx_command_given = 0; 351 priv->under_config = 0; 352 } 353 else 354 { 355 priv->card_polling_interval = 1; 356 if (arlan_debug & ARLAN_DEBUG_TIMING) 357 printk(KERN_ERR "configure delayed \n"); 358 } 359 } 360 else if (priv->waiting_command_mask & ARLAN_COMMAND_RX) 361 { 362 if (!registrationBad(dev)) 363 { 364 setInterruptEnable(dev); 365 memset_io(arlan->commandParameter, 0, 0xf); 366 WRITESHMB(arlan->commandByte, ARLAN_COM_INT | ARLAN_COM_RX_ENABLE); 367 WRITESHMB(arlan->commandParameter[0], conf->rxParameter); 368 arlan_interrupt_lancpu(dev); 369 priv->rx_command_given = 0; // mnjah, bad 370 priv->waiting_command_mask &= ~ARLAN_COMMAND_RX; 371 priv->card_polling_interval = 1; 372 } 373 else 374 priv->card_polling_interval = 2; 375 } 376 else if (priv->waiting_command_mask & ARLAN_COMMAND_TBUSY_CLEAR) 377 { 378 if ( !registrationBad(dev) && 379 (netif_queue_stopped(dev) || !netif_running(dev)) ) 380 { 381 priv->waiting_command_mask &= ~ARLAN_COMMAND_TBUSY_CLEAR; 382 netif_wake_queue (dev); 383 } 384 } 385 else if (priv->waiting_command_mask & ARLAN_COMMAND_TX) 386 { 387 if (!test_and_set_bit(0, (void *) &priv->tx_command_given)) 388 { 389 if (time_after(jiffies, 390 priv->tx_last_sent + us2ticks(conf->rx_tweak1)) 391 || time_before(jiffies, 392 priv->last_rx_int_ack_time + us2ticks(conf->rx_tweak2))) 393 { 394 setInterruptEnable(dev); 395 memset_io(arlan->commandParameter, 0, 0xf); 396 WRITESHMB(arlan->commandByte, ARLAN_COM_TX_ENABLE | ARLAN_COM_INT); 397 memcpy_toio(arlan->commandParameter, &TXLAST(dev), 14); 398// for ( i=1 ; i < 15 ; i++) printk("%02x:",READSHMB(arlan->commandParameter[i])); 399 priv->tx_last_sent = jiffies; 400 arlan_interrupt_lancpu(dev); 401 priv->tx_command_given = 1; 402 priv->waiting_command_mask &= ~ARLAN_COMMAND_TX; 403 priv->card_polling_interval = 1; 404 } 405 else 406 { 407 priv->tx_command_given = 0; 408 priv->card_polling_interval = 1; 409 } 410 } 411 else if (arlan_debug & ARLAN_DEBUG_CHAIN_LOCKS) 412 printk(KERN_ERR "tx command when tx chain locked \n"); 413 } 414 else if (priv->waiting_command_mask & ARLAN_COMMAND_NOOPINT) 415 { 416 { 417 WRITESHMB(arlan->commandByte, ARLAN_COM_NOP | ARLAN_COM_INT); 418 } 419 arlan_interrupt_lancpu(dev); 420 priv->waiting_command_mask &= ~ARLAN_COMMAND_NOOPINT; 421 priv->card_polling_interval = HZ / 3; 422 } 423 else if (priv->waiting_command_mask & ARLAN_COMMAND_NOOP) 424 { 425 WRITESHMB(arlan->commandByte, ARLAN_COM_NOP); 426 arlan_interrupt_lancpu(dev); 427 priv->waiting_command_mask &= ~ARLAN_COMMAND_NOOP; 428 priv->card_polling_interval = HZ / 3; 429 } 430 else if (priv->waiting_command_mask & ARLAN_COMMAND_SLOW_POLL) 431 { 432 WRITESHMB(arlan->commandByte, ARLAN_COM_GOTO_SLOW_POLL); 433 arlan_interrupt_lancpu(dev); 434 priv->waiting_command_mask &= ~ARLAN_COMMAND_SLOW_POLL; 435 priv->card_polling_interval = HZ / 3; 436 } 437 else if (priv->waiting_command_mask & ARLAN_COMMAND_POWERDOWN) 438 { 439 setPowerOff(dev); 440 if (arlan_debug & ARLAN_DEBUG_CARD_STATE) 441 printk(KERN_WARNING "%s: Arlan Going Standby\n", dev->name); 442 priv->waiting_command_mask &= ~ARLAN_COMMAND_POWERDOWN; 443 priv->card_polling_interval = 3 * HZ; 444 } 445 arlan_unlock_card_access(dev); 446 for (i = 0; READSHMB(arlan->commandByte) && i < 20; i++) 447 udelay(10); 448 if (READSHMB(arlan->commandByte)) 449 if (arlan_debug & ARLAN_DEBUG_CARD_STATE) 450 printk(KERN_ERR "card busy leaving command %lx\n", priv->waiting_command_mask); 451 452 spin_unlock_irqrestore(&priv->lock, flags); 453 ARLAN_DEBUG_EXIT("arlan_command"); 454 priv->last_command_buff_free_time = jiffies; 455 return 0; 456 457card_busy_end: 458 if (time_after(jiffies, priv->last_command_buff_free_time + HZ)) 459 priv->waiting_command_mask |= ARLAN_COMMAND_CLEAN_AND_RESET; 460 461 if (arlan_debug & ARLAN_DEBUG_CARD_STATE) 462 printk(KERN_ERR "%s arlan_command card busy end \n", dev->name); 463 spin_unlock_irqrestore(&priv->lock, flags); 464 ARLAN_DEBUG_EXIT("arlan_command"); 465 return 1; 466 467bad_end: 468 printk(KERN_ERR "%s arlan_command bad end \n", dev->name); 469 470 spin_unlock_irqrestore(&priv->lock, flags); 471 ARLAN_DEBUG_EXIT("arlan_command"); 472 473 return -1; 474} 475 476static inline void arlan_command_process(struct net_device *dev) 477{ 478 struct arlan_private *priv = netdev_priv(dev); 479 480 int times = 0; 481 while (priv->waiting_command_mask && times < 8) 482 { 483 if (priv->waiting_command_mask) 484 { 485 if (arlan_command(dev, 0)) 486 break; 487 times++; 488 } 489 /* if long command, we won't repeat trying */ ; 490 if (priv->card_polling_interval > 1) 491 break; 492 times++; 493 } 494} 495 496 497static inline void arlan_retransmit_now(struct net_device *dev) 498{ 499 struct arlan_private *priv = netdev_priv(dev); 500 501 502 ARLAN_DEBUG_ENTRY("arlan_retransmit_now"); 503 if (TXLAST(dev).offset == 0) 504 { 505 if (TXHEAD(dev).offset) 506 { 507 priv->txLast = 0; 508 IFDEBUG(ARLAN_DEBUG_TX_CHAIN) printk(KERN_DEBUG "TX buff switch to head \n"); 509 510 } 511 else if (TXTAIL(dev).offset) 512 { 513 IFDEBUG(ARLAN_DEBUG_TX_CHAIN) printk(KERN_DEBUG "TX buff switch to tail \n"); 514 priv->txLast = 1; 515 } 516 else 517 IFDEBUG(ARLAN_DEBUG_TX_CHAIN) printk(KERN_ERR "ReTransmit buff empty"); 518 netif_wake_queue (dev); 519 return; 520 521 } 522 arlan_command(dev, ARLAN_COMMAND_TX); 523 524 priv->Conf->driverRetransmissions++; 525 priv->retransmissions++; 526 527 IFDEBUG(ARLAN_DEBUG_TX_CHAIN) printk("Retransmit %d bytes \n", TXLAST(dev).length); 528 529 ARLAN_DEBUG_EXIT("arlan_retransmit_now"); 530} 531 532 533 534static void arlan_registration_timer(unsigned long data) 535{ 536 struct net_device *dev = (struct net_device *) data; 537 struct arlan_private *priv = netdev_priv(dev); 538 int bh_mark_needed = 0; 539 int next_tick = 1; 540 long lostTime = ((long)jiffies - (long)priv->registrationLastSeen) 541 * (1000/HZ); 542 543 if (registrationBad(dev)) 544 { 545 priv->registrationLostCount++; 546 if (lostTime > 7000 && lostTime < 7200) 547 { 548 printk(KERN_NOTICE "%s registration Lost \n", dev->name); 549 } 550 if (lostTime / priv->reRegisterExp > 2000) 551 arlan_command(dev, ARLAN_COMMAND_CLEAN_AND_CONF); 552 if (lostTime / (priv->reRegisterExp) > 3500) 553 arlan_command(dev, ARLAN_COMMAND_CLEAN_AND_RESET); 554 if (priv->reRegisterExp < 400) 555 priv->reRegisterExp += 2; 556 if (lostTime > 7200) 557 { 558 next_tick = HZ; 559 arlan_command(dev, ARLAN_COMMAND_CLEAN_AND_RESET); 560 } 561 } 562 else 563 { 564 if (priv->Conf->registrationMode && lostTime > 10000 && 565 priv->registrationLostCount) 566 { 567 printk(KERN_NOTICE "%s registration is back after %ld milliseconds\n", 568 dev->name, lostTime); 569 } 570 priv->registrationLastSeen = jiffies; 571 priv->registrationLostCount = 0; 572 priv->reRegisterExp = 1; 573 if (!netif_running(dev) ) 574 netif_wake_queue(dev); 575 if (time_after(priv->tx_last_sent,priv->tx_last_cleared) && 576 time_after(jiffies, priv->tx_last_sent * 5*HZ) ){ 577 arlan_command(dev, ARLAN_COMMAND_CLEAN_AND_RESET); 578 priv->tx_last_cleared = jiffies; 579 } 580 } 581 582 583 if (!registrationBad(dev) && priv->ReTransmitRequested) 584 { 585 IFDEBUG(ARLAN_DEBUG_TX_CHAIN) 586 printk(KERN_ERR "Retransmit from timer \n"); 587 priv->ReTransmitRequested = 0; 588 arlan_retransmit_now(dev); 589 } 590 if (!registrationBad(dev) && 591 time_after(jiffies, priv->tx_done_delayed) && 592 priv->tx_done_delayed != 0) 593 { 594 TXLAST(dev).offset = 0; 595 if (priv->txLast) 596 priv->txLast = 0; 597 else if (TXTAIL(dev).offset) 598 priv->txLast = 1; 599 if (TXLAST(dev).offset) 600 { 601 arlan_retransmit_now(dev); 602 dev->trans_start = jiffies; 603 } 604 if (!(TXHEAD(dev).offset && TXTAIL(dev).offset)) 605 { 606 netif_wake_queue (dev); 607 } 608 priv->tx_done_delayed = 0; 609 bh_mark_needed = 1; 610 } 611 if (bh_mark_needed) 612 { 613 netif_wake_queue (dev); 614 } 615 arlan_process_interrupt(dev); 616 617 if (next_tick < priv->card_polling_interval) 618 next_tick = priv->card_polling_interval; 619 620 priv->timer.expires = jiffies + next_tick; 621 622 add_timer(&priv->timer); 623} 624 625 626#ifdef ARLAN_DEBUGGING 627 628static void arlan_print_registers(struct net_device *dev, int line) 629{ 630 struct arlan_private *priv = netdev_priv(dev); 631 volatile struct arlan_shmem *arlan = priv->card; 632 633 u_char hostcpuLock, lancpuLock, controlRegister, cntrlRegImage, 634 txStatus, rxStatus, interruptInProgress, commandByte; 635 636 637 ARLAN_DEBUG_ENTRY("arlan_print_registers"); 638 READSHM(interruptInProgress, arlan->interruptInProgress, u_char); 639 READSHM(hostcpuLock, arlan->hostcpuLock, u_char); 640 READSHM(lancpuLock, arlan->lancpuLock, u_char); 641 READSHM(controlRegister, arlan->controlRegister, u_char); 642 READSHM(cntrlRegImage, arlan->cntrlRegImage, u_char); 643 READSHM(txStatus, arlan->txStatus, u_char); 644 READSHM(rxStatus, arlan->rxStatus, u_char); 645 READSHM(commandByte, arlan->commandByte, u_char); 646 647 printk(KERN_WARNING "line %04d IP %02x HL %02x LL %02x CB %02x CR %02x CRI %02x TX %02x RX %02x\n", 648 line, interruptInProgress, hostcpuLock, lancpuLock, commandByte, 649 controlRegister, cntrlRegImage, txStatus, rxStatus); 650 651 ARLAN_DEBUG_EXIT("arlan_print_registers"); 652} 653#endif 654 655 656static int arlan_hw_tx(struct net_device *dev, char *buf, int length) 657{ 658 int i; 659 660 struct arlan_private *priv = netdev_priv(dev); 661 volatile struct arlan_shmem __iomem *arlan = priv->card; 662 struct arlan_conf_stru *conf = priv->Conf; 663 664 int tailStarts = 0x800; 665 int headEnds = 0x0; 666 667 668 ARLAN_DEBUG_ENTRY("arlan_hw_tx"); 669 if (TXHEAD(dev).offset) 670 headEnds = (((TXHEAD(dev).offset + TXHEAD(dev).length - offsetof(struct arlan_shmem, txBuffer)) / 64) + 1) * 64; 671 if (TXTAIL(dev).offset) 672 tailStarts = 0x800 - (((TXTAIL(dev).offset - offsetof(struct arlan_shmem, txBuffer)) / 64) + 2) * 64; 673 674 675 if (!TXHEAD(dev).offset && length < tailStarts) 676 { 677 IFDEBUG(ARLAN_DEBUG_TX_CHAIN) 678 printk(KERN_ERR "TXHEAD insert, tailStart %d\n", tailStarts); 679 680 TXHEAD(dev).offset = 681 offsetof(struct arlan_shmem, txBuffer); 682 TXHEAD(dev).length = length - ARLAN_FAKE_HDR_LEN; 683 for (i = 0; i < 6; i++) 684 TXHEAD(dev).dest[i] = buf[i]; 685 TXHEAD(dev).clear = conf->txClear; 686 TXHEAD(dev).retries = conf->txRetries; /* 0 is use default */ 687 TXHEAD(dev).routing = conf->txRouting; 688 TXHEAD(dev).scrambled = conf->txScrambled; 689 memcpy_toio((char __iomem *)arlan + TXHEAD(dev).offset, buf + ARLAN_FAKE_HDR_LEN, TXHEAD(dev).length); 690 } 691 else if (!TXTAIL(dev).offset && length < (0x800 - headEnds)) 692 { 693 IFDEBUG(ARLAN_DEBUG_TX_CHAIN) 694 printk(KERN_ERR "TXTAIL insert, headEnd %d\n", headEnds); 695 696 TXTAIL(dev).offset = 697 offsetof(struct arlan_shmem, txBuffer) + 0x800 - (length / 64 + 2) * 64; 698 TXTAIL(dev).length = length - ARLAN_FAKE_HDR_LEN; 699 for (i = 0; i < 6; i++) 700 TXTAIL(dev).dest[i] = buf[i]; 701 TXTAIL(dev).clear = conf->txClear; 702 TXTAIL(dev).retries = conf->txRetries; 703 TXTAIL(dev).routing = conf->txRouting; 704 TXTAIL(dev).scrambled = conf->txScrambled; 705 memcpy_toio(((char __iomem *)arlan + TXTAIL(dev).offset), buf + ARLAN_FAKE_HDR_LEN, TXTAIL(dev).length); 706 } 707 else 708 { 709 netif_stop_queue (dev); 710 IFDEBUG(ARLAN_DEBUG_TX_CHAIN) 711 printk(KERN_ERR "TX TAIL & HEAD full, return, tailStart %d headEnd %d\n", tailStarts, headEnds); 712 return -1; 713 } 714 priv->out_bytes += length; 715 priv->out_bytes10 += length; 716 if (conf->measure_rate < 1) 717 conf->measure_rate = 1; 718 if (time_after(jiffies, priv->out_time + conf->measure_rate * HZ)) 719 { 720 conf->out_speed = priv->out_bytes / conf->measure_rate; 721 priv->out_bytes = 0; 722 priv->out_time = jiffies; 723 } 724 if (time_after(jiffies, priv->out_time10 + conf->measure_rate * 10*HZ)) 725 { 726 conf->out_speed10 = priv->out_bytes10 / (10 * conf->measure_rate); 727 priv->out_bytes10 = 0; 728 priv->out_time10 = jiffies; 729 } 730 if (TXHEAD(dev).offset && TXTAIL(dev).offset) 731 { 732 netif_stop_queue (dev); 733 return 0; 734 } 735 else 736 netif_start_queue (dev); 737 738 739 IFDEBUG(ARLAN_DEBUG_HEADER_DUMP) 740 printk(KERN_WARNING "%s Transmit t %2x:%2x:%2x:%2x:%2x:%2x f %2x:%2x:%2x:%2x:%2x:%2x \n", dev->name, 741 (unsigned char) buf[0], (unsigned char) buf[1], (unsigned char) buf[2], (unsigned char) buf[3], 742 (unsigned char) buf[4], (unsigned char) buf[5], (unsigned char) buf[6], (unsigned char) buf[7], 743 (unsigned char) buf[8], (unsigned char) buf[9], (unsigned char) buf[10], (unsigned char) buf[11]); 744 745 IFDEBUG(ARLAN_DEBUG_TX_CHAIN) printk(KERN_ERR "TX command prepare for buffer %d\n", priv->txLast); 746 747 arlan_command(dev, ARLAN_COMMAND_TX); 748 749 priv->tx_last_sent = jiffies; 750 751 IFDEBUG(ARLAN_DEBUG_TX_CHAIN) printk("%s TX Qued %d bytes \n", dev->name, length); 752 753 ARLAN_DEBUG_EXIT("arlan_hw_tx"); 754 755 return 0; 756} 757 758 759static int arlan_hw_config(struct net_device *dev) 760{ 761 struct arlan_private *priv = netdev_priv(dev); 762 volatile struct arlan_shmem __iomem *arlan = priv->card; 763 struct arlan_conf_stru *conf = priv->Conf; 764 765 ARLAN_DEBUG_ENTRY("arlan_hw_config"); 766 767 printk(KERN_NOTICE "%s arlan configure called \n", dev->name); 768 if (arlan_EEPROM_bad) 769 printk(KERN_NOTICE "arlan configure with eeprom bad option \n"); 770 771 772 WRITESHM(arlan->spreadingCode, conf->spreadingCode, u_char); 773 WRITESHM(arlan->channelSet, conf->channelSet, u_char); 774 775 if (arlan_EEPROM_bad) 776 WRITESHM(arlan->defaultChannelSet, conf->channelSet, u_char); 777 778 WRITESHM(arlan->channelNumber, conf->channelNumber, u_char); 779 780 WRITESHM(arlan->scramblingDisable, conf->scramblingDisable, u_char); 781 WRITESHM(arlan->txAttenuation, conf->txAttenuation, u_char); 782 783 WRITESHM(arlan->systemId, conf->systemId, u_int); 784 785 WRITESHM(arlan->maxRetries, conf->maxRetries, u_char); 786 WRITESHM(arlan->receiveMode, conf->receiveMode, u_char); 787 WRITESHM(arlan->priority, conf->priority, u_char); 788 WRITESHM(arlan->rootOrRepeater, conf->rootOrRepeater, u_char); 789 WRITESHM(arlan->SID, conf->SID, u_int); 790 791 WRITESHM(arlan->registrationMode, conf->registrationMode, u_char); 792 793 WRITESHM(arlan->registrationFill, conf->registrationFill, u_char); 794 WRITESHM(arlan->localTalkAddress, conf->localTalkAddress, u_char); 795 WRITESHM(arlan->codeFormat, conf->codeFormat, u_char); 796 WRITESHM(arlan->numChannels, conf->numChannels, u_char); 797 WRITESHM(arlan->channel1, conf->channel1, u_char); 798 WRITESHM(arlan->channel2, conf->channel2, u_char); 799 WRITESHM(arlan->channel3, conf->channel3, u_char); 800 WRITESHM(arlan->channel4, conf->channel4, u_char); 801 WRITESHM(arlan->radioNodeId, conf->radioNodeId, u_short); 802 WRITESHM(arlan->SID, conf->SID, u_int); 803 WRITESHM(arlan->waitTime, conf->waitTime, u_short); 804 WRITESHM(arlan->lParameter, conf->lParameter, u_short); 805 memcpy_toio(&(arlan->_15), &(conf->_15), 3); 806 WRITESHM(arlan->_15, conf->_15, u_short); 807 WRITESHM(arlan->headerSize, conf->headerSize, u_short); 808 if (arlan_EEPROM_bad) 809 WRITESHM(arlan->hardwareType, conf->hardwareType, u_char); 810 WRITESHM(arlan->radioType, conf->radioType, u_char); 811 if (arlan_EEPROM_bad) 812 WRITESHM(arlan->radioModule, conf->radioType, u_char); 813 814 memcpy_toio(arlan->encryptionKey + keyStart, encryptionKey, 8); 815 memcpy_toio(arlan->name, conf->siteName, 16); 816 817 WRITESHMB(arlan->commandByte, ARLAN_COM_INT | ARLAN_COM_CONF); /* do configure */ 818 memset_io(arlan->commandParameter, 0, 0xf); /* 0xf */ 819 memset_io(arlan->commandParameter + 1, 0, 2); 820 if (conf->writeEEPROM) 821 { 822 memset_io(arlan->commandParameter, conf->writeEEPROM, 1); 823// conf->writeEEPROM=0; 824 } 825 if (conf->registrationMode && conf->registrationInterrupts) 826 memset_io(arlan->commandParameter + 3, 1, 1); 827 else 828 memset_io(arlan->commandParameter + 3, 0, 1); 829 830 priv->irq_test_done = 0; 831 832 if (conf->tx_queue_len) 833 dev->tx_queue_len = conf->tx_queue_len; 834 udelay(100); 835 836 ARLAN_DEBUG_EXIT("arlan_hw_config"); 837 return 0; 838} 839 840 841static int arlan_read_card_configuration(struct net_device *dev) 842{ 843 u_char tlx415; 844 struct arlan_private *priv = netdev_priv(dev); 845 volatile struct arlan_shmem __iomem *arlan = priv->card; 846 struct arlan_conf_stru *conf = priv->Conf; 847 848 ARLAN_DEBUG_ENTRY("arlan_read_card_configuration"); 849 850 if (radioNodeId == radioNodeIdUNKNOWN) 851 { 852 READSHM(conf->radioNodeId, arlan->radioNodeId, u_short); 853 } 854 else 855 conf->radioNodeId = radioNodeId; 856 857 if (SID == SIDUNKNOWN) 858 { 859 READSHM(conf->SID, arlan->SID, u_int); 860 } 861 else conf->SID = SID; 862 863 if (spreadingCode == spreadingCodeUNKNOWN) 864 { 865 READSHM(conf->spreadingCode, arlan->spreadingCode, u_char); 866 } 867 else 868 conf->spreadingCode = spreadingCode; 869 870 if (channelSet == channelSetUNKNOWN) 871 { 872 READSHM(conf->channelSet, arlan->channelSet, u_char); 873 } 874 else conf->channelSet = channelSet; 875 876 if (channelNumber == channelNumberUNKNOWN) 877 { 878 READSHM(conf->channelNumber, arlan->channelNumber, u_char); 879 } 880 else conf->channelNumber = channelNumber; 881 882 READSHM(conf->scramblingDisable, arlan->scramblingDisable, u_char); 883 READSHM(conf->txAttenuation, arlan->txAttenuation, u_char); 884 885 if (systemId == systemIdUNKNOWN) 886 { 887 READSHM(conf->systemId, arlan->systemId, u_int); 888 } 889 else conf->systemId = systemId; 890 891 READSHM(conf->maxDatagramSize, arlan->maxDatagramSize, u_short); 892 READSHM(conf->maxFrameSize, arlan->maxFrameSize, u_short); 893 READSHM(conf->maxRetries, arlan->maxRetries, u_char); 894 READSHM(conf->receiveMode, arlan->receiveMode, u_char); 895 READSHM(conf->priority, arlan->priority, u_char); 896 READSHM(conf->rootOrRepeater, arlan->rootOrRepeater, u_char); 897 898 if (SID == SIDUNKNOWN) 899 { 900 READSHM(conf->SID, arlan->SID, u_int); 901 } 902 else conf->SID = SID; 903 904 if (registrationMode == registrationModeUNKNOWN) 905 { 906 READSHM(conf->registrationMode, arlan->registrationMode, u_char); 907 } 908 else conf->registrationMode = registrationMode; 909 910 READSHM(conf->registrationFill, arlan->registrationFill, u_char); 911 READSHM(conf->localTalkAddress, arlan->localTalkAddress, u_char); 912 READSHM(conf->codeFormat, arlan->codeFormat, u_char); 913 READSHM(conf->numChannels, arlan->numChannels, u_char); 914 READSHM(conf->channel1, arlan->channel1, u_char); 915 READSHM(conf->channel2, arlan->channel2, u_char); 916 READSHM(conf->channel3, arlan->channel3, u_char); 917 READSHM(conf->channel4, arlan->channel4, u_char); 918 READSHM(conf->waitTime, arlan->waitTime, u_short); 919 READSHM(conf->lParameter, arlan->lParameter, u_short); 920 READSHM(conf->_15, arlan->_15, u_short); 921 READSHM(conf->headerSize, arlan->headerSize, u_short); 922 READSHM(conf->hardwareType, arlan->hardwareType, u_char); 923 READSHM(conf->radioType, arlan->radioModule, u_char); 924 925 if (conf->radioType == 0) 926 conf->radioType = 0xc; 927 928 WRITESHM(arlan->configStatus, 0xA5, u_char); 929 READSHM(tlx415, arlan->configStatus, u_char); 930 931 if (tlx415 != 0xA5) 932 printk(KERN_INFO "%s tlx415 chip \n", dev->name); 933 934 conf->txClear = 0; 935 conf->txRetries = 1; 936 conf->txRouting = 1; 937 conf->txScrambled = 0; 938 conf->rxParameter = 1; 939 conf->txTimeoutMs = 4000; 940 conf->waitCardTimeout = 100000; 941 conf->receiveMode = ARLAN_RCV_CLEAN; 942 memcpy_fromio(conf->siteName, arlan->name, 16); 943 conf->siteName[16] = '\0'; 944 conf->retries = retries; 945 conf->tx_delay_ms = tx_delay_ms; 946 conf->ReTransmitPacketMaxSize = 200; 947 conf->waitReTransmitPacketMaxSize = 200; 948 conf->txAckTimeoutMs = 900; 949 conf->fastReTransCount = 3; 950 951 ARLAN_DEBUG_EXIT("arlan_read_card_configuration"); 952 953 return 0; 954} 955 956 957static int lastFoundAt = 0xbe000; 958 959 960/* 961 * This is the real probe routine. Linux has a history of friendly device 962 * probes on the ISA bus. A good device probes avoids doing writes, and 963 * verifies that the correct device exists and functions. 964 */ 965#define ARLAN_SHMEM_SIZE 0x2000 966static int __init arlan_check_fingerprint(unsigned long memaddr) 967{ 968 static const char probeText[] = "TELESYSTEM SLW INC. ARLAN \0"; 969 volatile struct arlan_shmem __iomem *arlan = (struct arlan_shmem *) memaddr; 970 unsigned long paddr = virt_to_phys((void *) memaddr); 971 char tempBuf[49]; 972 973 ARLAN_DEBUG_ENTRY("arlan_check_fingerprint"); 974 975 if (!request_mem_region(paddr, ARLAN_SHMEM_SIZE, "arlan")) { 976 // printk(KERN_WARNING "arlan: memory region %lx excluded from probing \n",paddr); 977 return -ENODEV; 978 } 979 980 memcpy_fromio(tempBuf, arlan->textRegion, 29); 981 tempBuf[30] = 0; 982 983 /* check for card at this address */ 984 if (0 != strncmp(tempBuf, probeText, 29)){ 985 release_mem_region(paddr, ARLAN_SHMEM_SIZE); 986 return -ENODEV; 987 } 988 989// printk(KERN_INFO "arlan found at 0x%x \n",memaddr); 990 ARLAN_DEBUG_EXIT("arlan_check_fingerprint"); 991 992 return 0; 993} 994 995static int arlan_change_mtu(struct net_device *dev, int new_mtu) 996{ 997 struct arlan_private *priv = netdev_priv(dev); 998 struct arlan_conf_stru *conf = priv->Conf; 999 1000 ARLAN_DEBUG_ENTRY("arlan_change_mtu"); 1001 if (new_mtu > 2032) 1002 return -EINVAL; 1003 dev->mtu = new_mtu; 1004 if (new_mtu < 256) 1005 new_mtu = 256; /* cards book suggests 1600 */ 1006 conf->maxDatagramSize = new_mtu; 1007 conf->maxFrameSize = new_mtu + 48; 1008 1009 arlan_command(dev, ARLAN_COMMAND_CLEAN_AND_CONF); 1010 printk(KERN_NOTICE "%s mtu changed to %d \n", dev->name, new_mtu); 1011 1012 ARLAN_DEBUG_EXIT("arlan_change_mtu"); 1013 1014 return 0; 1015} 1016 1017static int arlan_mac_addr(struct net_device *dev, void *p) 1018{ 1019 struct sockaddr *addr = p; 1020 1021 1022 ARLAN_DEBUG_ENTRY("arlan_mac_addr"); 1023 return -EINVAL; 1024 1025 if (!netif_running(dev)) 1026 return -EBUSY; 1027 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len); 1028 1029 ARLAN_DEBUG_EXIT("arlan_mac_addr"); 1030 return 0; 1031} 1032 1033 1034 1035static int __init arlan_setup_device(struct net_device *dev, int num) 1036{ 1037 struct arlan_private *ap = netdev_priv(dev); 1038 int err; 1039 1040 ARLAN_DEBUG_ENTRY("arlan_setup_device"); 1041 1042 ap->conf = (struct arlan_shmem *)(ap+1); 1043 1044 dev->tx_queue_len = tx_queue_len; 1045 dev->open = arlan_open; 1046 dev->stop = arlan_close; 1047 dev->hard_start_xmit = arlan_tx; 1048 dev->get_stats = arlan_statistics; 1049 dev->set_multicast_list = arlan_set_multicast; 1050 dev->change_mtu = arlan_change_mtu; 1051 dev->set_mac_address = arlan_mac_addr; 1052 dev->tx_timeout = arlan_tx_timeout; 1053 dev->watchdog_timeo = 3*HZ; 1054 1055 ap->irq_test_done = 0; 1056 ap->Conf = &arlan_conf[num]; 1057 1058 ap->Conf->pre_Command_Wait = 40; 1059 ap->Conf->rx_tweak1 = 30; 1060 ap->Conf->rx_tweak2 = 0; 1061 1062 1063 err = register_netdev(dev); 1064 if (err) { 1065 release_mem_region(virt_to_phys((void *) dev->mem_start), 1066 ARLAN_SHMEM_SIZE); 1067 free_netdev(dev); 1068 return err; 1069 } 1070 arlan_device[num] = dev; 1071 ARLAN_DEBUG_EXIT("arlan_setup_device"); 1072 return 0; 1073} 1074 1075static int __init arlan_probe_here(struct net_device *dev, 1076 unsigned long memaddr) 1077{ 1078 struct arlan_private *ap = netdev_priv(dev); 1079 1080 ARLAN_DEBUG_ENTRY("arlan_probe_here"); 1081 1082 if (arlan_check_fingerprint(memaddr)) 1083 return -ENODEV; 1084 1085 printk(KERN_NOTICE "%s: Arlan found at %x, \n ", dev->name, 1086 (int) virt_to_phys((void*)memaddr)); 1087 1088 ap->card = (void *) memaddr; 1089 dev->mem_start = memaddr; 1090 dev->mem_end = memaddr + ARLAN_SHMEM_SIZE-1; 1091 1092 if (dev->irq < 2) 1093 { 1094 READSHM(dev->irq, ap->card->irqLevel, u_char); 1095 } else if (dev->irq == 2) 1096 dev->irq = 9; 1097 1098 arlan_read_card_configuration(dev); 1099 1100 ARLAN_DEBUG_EXIT("arlan_probe_here"); 1101 return 0; 1102} 1103 1104 1105static int arlan_open(struct net_device *dev) 1106{ 1107 struct arlan_private *priv = netdev_priv(dev); 1108 volatile struct arlan_shmem __iomem *arlan = priv->card; 1109 int ret = 0; 1110 1111 ARLAN_DEBUG_ENTRY("arlan_open"); 1112 1113 ret = request_irq(dev->irq, &arlan_interrupt, 0, dev->name, dev); 1114 if (ret) 1115 { 1116 printk(KERN_ERR "%s: unable to get IRQ %d .\n", 1117 dev->name, dev->irq); 1118 return ret; 1119 } 1120 1121 1122 priv->bad = 0; 1123 priv->lastReset = 0; 1124 priv->reset = 0; 1125 memcpy_fromio(dev->dev_addr, arlan->lanCardNodeId, 6); 1126 memset(dev->broadcast, 0xff, 6); 1127 dev->tx_queue_len = tx_queue_len; 1128 priv->interrupt_processing_active = 0; 1129 spin_lock_init(&priv->lock); 1130 1131 netif_start_queue (dev); 1132 1133 priv->registrationLostCount = 0; 1134 priv->registrationLastSeen = jiffies; 1135 priv->txLast = 0; 1136 priv->tx_command_given = 0; 1137 priv->rx_command_given = 0; 1138 1139 priv->reRegisterExp = 1; 1140 priv->tx_last_sent = jiffies - 1; 1141 priv->tx_last_cleared = jiffies; 1142 priv->Conf->writeEEPROM = 0; 1143 priv->Conf->registrationInterrupts = 1; 1144 1145 init_timer(&priv->timer); 1146 priv->timer.expires = jiffies + HZ / 10; 1147 priv->timer.data = (unsigned long) dev; 1148 priv->timer.function = &arlan_registration_timer; /* timer handler */ 1149 1150 arlan_command(dev, ARLAN_COMMAND_POWERUP | ARLAN_COMMAND_LONG_WAIT_NOW); 1151 mdelay(200); 1152 add_timer(&priv->timer); 1153 1154 ARLAN_DEBUG_EXIT("arlan_open"); 1155 return 0; 1156} 1157 1158 1159static void arlan_tx_timeout (struct net_device *dev) 1160{ 1161 printk(KERN_ERR "%s: arlan transmit timed out, kernel decided\n", dev->name); 1162 /* Try to restart the adaptor. */ 1163 arlan_command(dev, ARLAN_COMMAND_CLEAN_AND_RESET); 1164 // dev->trans_start = jiffies; 1165 // netif_start_queue (dev); 1166} 1167 1168 1169static int arlan_tx(struct sk_buff *skb, struct net_device *dev) 1170{ 1171 short length; 1172 unsigned char *buf; 1173 1174 ARLAN_DEBUG_ENTRY("arlan_tx"); 1175 1176 length = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN; 1177 buf = skb->data; 1178 1179 if (length + 0x12 > 0x800) { 1180 printk(KERN_ERR "TX RING overflow \n"); 1181 netif_stop_queue (dev); 1182 } 1183 1184 if (arlan_hw_tx(dev, buf, length) == -1) 1185 goto bad_end; 1186 1187 dev->trans_start = jiffies; 1188 1189 dev_kfree_skb(skb); 1190 1191 arlan_process_interrupt(dev); 1192 ARLAN_DEBUG_EXIT("arlan_tx"); 1193 return 0; 1194 1195bad_end: 1196 arlan_process_interrupt(dev); 1197 netif_stop_queue (dev); 1198 ARLAN_DEBUG_EXIT("arlan_tx"); 1199 return 1; 1200} 1201 1202 1203static inline int DoNotReTransmitCrap(struct net_device *dev) 1204{ 1205 struct arlan_private *priv = netdev_priv(dev); 1206 1207 if (TXLAST(dev).length < priv->Conf->ReTransmitPacketMaxSize) 1208 return 1; 1209 return 0; 1210 1211} 1212 1213static inline int DoNotWaitReTransmitCrap(struct net_device *dev) 1214{ 1215 struct arlan_private *priv = netdev_priv(dev); 1216 1217 if (TXLAST(dev).length < priv->Conf->waitReTransmitPacketMaxSize) 1218 return 1; 1219 return 0; 1220} 1221 1222static inline void arlan_queue_retransmit(struct net_device *dev) 1223{ 1224 struct arlan_private *priv = netdev_priv(dev); 1225 1226 ARLAN_DEBUG_ENTRY("arlan_queue_retransmit"); 1227 1228 if (DoNotWaitReTransmitCrap(dev)) 1229 { 1230 arlan_drop_tx(dev); 1231 } else 1232 priv->ReTransmitRequested++; 1233 1234 ARLAN_DEBUG_EXIT("arlan_queue_retransmit"); 1235} 1236 1237static inline void RetryOrFail(struct net_device *dev) 1238{ 1239 struct arlan_private *priv = netdev_priv(dev); 1240 1241 ARLAN_DEBUG_ENTRY("RetryOrFail"); 1242 1243 if (priv->retransmissions > priv->Conf->retries || 1244 DoNotReTransmitCrap(dev)) 1245 { 1246 arlan_drop_tx(dev); 1247 } 1248 else if (priv->bad <= priv->Conf->fastReTransCount) 1249 { 1250 arlan_retransmit_now(dev); 1251 } 1252 else arlan_queue_retransmit(dev); 1253 1254 ARLAN_DEBUG_EXIT("RetryOrFail"); 1255} 1256 1257 1258static void arlan_tx_done_interrupt(struct net_device *dev, int status) 1259{ 1260 struct arlan_private *priv = netdev_priv(dev); 1261 1262 ARLAN_DEBUG_ENTRY("arlan_tx_done_interrupt"); 1263 1264 priv->tx_last_cleared = jiffies; 1265 priv->tx_command_given = 0; 1266 switch (status) 1267 { 1268 case 1: 1269 { 1270 IFDEBUG(ARLAN_DEBUG_TX_CHAIN) 1271 printk("arlan intr: transmit OK\n"); 1272 priv->stats.tx_packets++; 1273 priv->bad = 0; 1274 priv->reset = 0; 1275 priv->retransmissions = 0; 1276 if (priv->Conf->tx_delay_ms) 1277 { 1278 priv->tx_done_delayed = jiffies + (priv->Conf->tx_delay_ms * HZ) / 1000 + 1; 1279 } 1280 else 1281 { 1282 TXLAST(dev).offset = 0; 1283 if (priv->txLast) 1284 priv->txLast = 0; 1285 else if (TXTAIL(dev).offset) 1286 priv->txLast = 1; 1287 if (TXLAST(dev).offset) 1288 { 1289 arlan_retransmit_now(dev); 1290 dev->trans_start = jiffies; 1291 } 1292 if (!TXHEAD(dev).offset || !TXTAIL(dev).offset) 1293 { 1294 netif_wake_queue (dev); 1295 } 1296 } 1297 } 1298 break; 1299 1300 case 2: 1301 { 1302 IFDEBUG(ARLAN_DEBUG_TX_CHAIN) 1303 printk("arlan intr: transmit timed out\n"); 1304 priv->bad += 1; 1305 //arlan_queue_retransmit(dev); 1306 RetryOrFail(dev); 1307 } 1308 break; 1309 1310 case 3: 1311 { 1312 IFDEBUG(ARLAN_DEBUG_TX_CHAIN) 1313 printk("arlan intr: transmit max retries\n"); 1314 priv->bad += 1; 1315 priv->reset = 0; 1316 //arlan_queue_retransmit(dev); 1317 RetryOrFail(dev); 1318 } 1319 break; 1320 1321 case 4: 1322 { 1323 IFDEBUG(ARLAN_DEBUG_TX_CHAIN) 1324 printk("arlan intr: transmit aborted\n"); 1325 priv->bad += 1; 1326 arlan_queue_retransmit(dev); 1327 //RetryOrFail(dev); 1328 } 1329 break; 1330 1331 case 5: 1332 { 1333 IFDEBUG(ARLAN_DEBUG_TX_CHAIN) 1334 printk("arlan intr: transmit not registered\n"); 1335 priv->bad += 1; 1336 //debug=101; 1337 arlan_queue_retransmit(dev); 1338 } 1339 break; 1340 1341 case 6: 1342 { 1343 IFDEBUG(ARLAN_DEBUG_TX_CHAIN) 1344 printk("arlan intr: transmit destination full\n"); 1345 priv->bad += 1; 1346 priv->reset = 0; 1347 //arlan_drop_tx(dev); 1348 arlan_queue_retransmit(dev); 1349 } 1350 break; 1351 1352 case 7: 1353 { 1354 IFDEBUG(ARLAN_DEBUG_TX_CHAIN) 1355 printk("arlan intr: transmit unknown ack\n"); 1356 priv->bad += 1; 1357 priv->reset = 0; 1358 arlan_queue_retransmit(dev); 1359 } 1360 break; 1361 1362 case 8: 1363 { 1364 IFDEBUG(ARLAN_DEBUG_TX_CHAIN) 1365 printk("arlan intr: transmit dest mail box full\n"); 1366 priv->bad += 1; 1367 priv->reset = 0; 1368 //arlan_drop_tx(dev); 1369 arlan_queue_retransmit(dev); 1370 } 1371 break; 1372 1373 case 9: 1374 { 1375 IFDEBUG(ARLAN_DEBUG_TX_CHAIN) 1376 printk("arlan intr: transmit root dest not reg.\n"); 1377 priv->bad += 1; 1378 priv->reset = 1; 1379 //arlan_drop_tx(dev); 1380 arlan_queue_retransmit(dev); 1381 } 1382 break; 1383 1384 default: 1385 { 1386 printk(KERN_ERR "arlan intr: transmit status unknown\n"); 1387 priv->bad += 1; 1388 priv->reset = 1; 1389 arlan_drop_tx(dev); 1390 } 1391 } 1392 1393 ARLAN_DEBUG_EXIT("arlan_tx_done_interrupt"); 1394} 1395 1396 1397static void arlan_rx_interrupt(struct net_device *dev, u_char rxStatus, u_short rxOffset, u_short pkt_len) 1398{ 1399 char *skbtmp; 1400 int i = 0; 1401 1402 struct arlan_private *priv = netdev_priv(dev); 1403 volatile struct arlan_shmem __iomem *arlan = priv->card; 1404 struct arlan_conf_stru *conf = priv->Conf; 1405 1406 1407 ARLAN_DEBUG_ENTRY("arlan_rx_interrupt"); 1408 // by spec, not WRITESHMB(arlan->rxStatus,0x00); 1409 // prohibited here arlan_command(dev, ARLAN_COMMAND_RX); 1410 1411 if (pkt_len < 10 || pkt_len > 2048) 1412 { 1413 printk(KERN_WARNING "%s: got too short or long packet, len %d \n", dev->name, pkt_len); 1414 return; 1415 } 1416 if (rxOffset + pkt_len > 0x2000) 1417 { 1418 printk("%s: got too long packet, len %d offset %x\n", dev->name, pkt_len, rxOffset); 1419 return; 1420 } 1421 priv->in_bytes += pkt_len; 1422 priv->in_bytes10 += pkt_len; 1423 if (conf->measure_rate < 1) 1424 conf->measure_rate = 1; 1425 if (time_after(jiffies, priv->in_time + conf->measure_rate * HZ)) 1426 { 1427 conf->in_speed = priv->in_bytes / conf->measure_rate; 1428 priv->in_bytes = 0; 1429 priv->in_time = jiffies; 1430 } 1431 if (time_after(jiffies, priv->in_time10 + conf->measure_rate * 10*HZ)) 1432 { 1433 conf->in_speed10 = priv->in_bytes10 / (10 * conf->measure_rate); 1434 priv->in_bytes10 = 0; 1435 priv->in_time10 = jiffies; 1436 } 1437 DEBUGSHM(1, "arlan rcv pkt rxStatus= %d ", arlan->rxStatus, u_char); 1438 switch (rxStatus) 1439 { 1440 case 1: 1441 case 2: 1442 case 3: 1443 { 1444 /* Malloc up new buffer. */ 1445 struct sk_buff *skb; 1446 1447 DEBUGSHM(50, "arlan recv pkt offs=%d\n", arlan->rxOffset, u_short); 1448 DEBUGSHM(1, "arlan rxFrmType = %d \n", arlan->rxFrmType, u_char); 1449 DEBUGSHM(1, KERN_INFO "arlan rx scrambled = %d \n", arlan->scrambled, u_char); 1450 1451 /* here we do multicast filtering to avoid slow 8-bit memcopy */ 1452#ifdef ARLAN_MULTICAST 1453 if (!(dev->flags & IFF_ALLMULTI) && 1454 !(dev->flags & IFF_PROMISC) && 1455 dev->mc_list) 1456 { 1457 char hw_dst_addr[6]; 1458 struct dev_mc_list *dmi = dev->mc_list; 1459 int i; 1460 1461 memcpy_fromio(hw_dst_addr, arlan->ultimateDestAddress, 6); 1462 if (hw_dst_addr[0] == 0x01) 1463 { 1464 if (mdebug) 1465 if (hw_dst_addr[1] == 0x00) 1466 printk(KERN_ERR "%s mcast 0x0100 \n", dev->name); 1467 else if (hw_dst_addr[1] == 0x40) 1468 printk(KERN_ERR "%s m/bcast 0x0140 \n", dev->name); 1469 while (dmi) 1470 { if (dmi->dmi_addrlen == 6) 1471 { 1472 if (arlan_debug & ARLAN_DEBUG_HEADER_DUMP) 1473 printk(KERN_ERR "%s mcl %2x:%2x:%2x:%2x:%2x:%2x \n", dev->name, 1474 dmi->dmi_addr[0], dmi->dmi_addr[1], dmi->dmi_addr[2], 1475 dmi->dmi_addr[3], dmi->dmi_addr[4], dmi->dmi_addr[5]); 1476 for (i = 0; i < 6; i++) 1477 if (dmi->dmi_addr[i] != hw_dst_addr[i]) 1478 break; 1479 if (i == 6) 1480 break; 1481 } 1482 else 1483 printk(KERN_ERR "%s: invalid multicast address length given.\n", dev->name); 1484 dmi = dmi->next; 1485 } 1486 /* we reach here if multicast filtering is on and packet 1487 * is multicast and not for receive */ 1488 goto end_of_interrupt; 1489 } 1490 } 1491#endif // ARLAN_MULTICAST 1492 /* multicast filtering ends here */ 1493 pkt_len += ARLAN_FAKE_HDR_LEN; 1494 1495 skb = dev_alloc_skb(pkt_len + 4); 1496 if (skb == NULL) 1497 { 1498 printk(KERN_ERR "%s: Memory squeeze, dropping packet.\n", dev->name); 1499 priv->stats.rx_dropped++; 1500 break; 1501 } 1502 skb_reserve(skb, 2); 1503 skbtmp = skb_put(skb, pkt_len); 1504 1505 memcpy_fromio(skbtmp + ARLAN_FAKE_HDR_LEN, ((char __iomem *) arlan) + rxOffset, pkt_len - ARLAN_FAKE_HDR_LEN); 1506 memcpy_fromio(skbtmp, arlan->ultimateDestAddress, 6); 1507 memcpy_fromio(skbtmp + 6, arlan->rxSrc, 6); 1508 WRITESHMB(arlan->rxStatus, 0x00); 1509 arlan_command(dev, ARLAN_COMMAND_RX); 1510 1511 IFDEBUG(ARLAN_DEBUG_HEADER_DUMP) 1512 { 1513 char immedDestAddress[6]; 1514 char immedSrcAddress[6]; 1515 memcpy_fromio(immedDestAddress, arlan->immedDestAddress, 6); 1516 memcpy_fromio(immedSrcAddress, arlan->immedSrcAddress, 6); 1517 1518 printk(KERN_WARNING "%s t %2x:%2x:%2x:%2x:%2x:%2x f %2x:%2x:%2x:%2x:%2x:%2x imd %2x:%2x:%2x:%2x:%2x:%2x ims %2x:%2x:%2x:%2x:%2x:%2x\n", dev->name, 1519 (unsigned char) skbtmp[0], (unsigned char) skbtmp[1], (unsigned char) skbtmp[2], (unsigned char) skbtmp[3], 1520 (unsigned char) skbtmp[4], (unsigned char) skbtmp[5], (unsigned char) skbtmp[6], (unsigned char) skbtmp[7], 1521 (unsigned char) skbtmp[8], (unsigned char) skbtmp[9], (unsigned char) skbtmp[10], (unsigned char) skbtmp[11], 1522 immedDestAddress[0], immedDestAddress[1], immedDestAddress[2], 1523 immedDestAddress[3], immedDestAddress[4], immedDestAddress[5], 1524 immedSrcAddress[0], immedSrcAddress[1], immedSrcAddress[2], 1525 immedSrcAddress[3], immedSrcAddress[4], immedSrcAddress[5]); 1526 } 1527 skb->protocol = eth_type_trans(skb, dev); 1528 IFDEBUG(ARLAN_DEBUG_HEADER_DUMP) 1529 if (skb->protocol != 0x608 && skb->protocol != 0x8) 1530 { 1531 for (i = 0; i <= 22; i++) 1532 printk("%02x:", (u_char) skbtmp[i + 12]); 1533 printk(KERN_ERR "\n"); 1534 printk(KERN_WARNING "arlan kernel pkt type trans %x \n", skb->protocol); 1535 } 1536 netif_rx(skb); 1537 dev->last_rx = jiffies; 1538 priv->stats.rx_packets++; 1539 priv->stats.rx_bytes += pkt_len; 1540 } 1541 break; 1542 1543 default: 1544 printk(KERN_ERR "arlan intr: received unknown status\n"); 1545 priv->stats.rx_crc_errors++; 1546 break; 1547 } 1548 ARLAN_DEBUG_EXIT("arlan_rx_interrupt"); 1549} 1550 1551static void arlan_process_interrupt(struct net_device *dev) 1552{ 1553 struct arlan_private *priv = netdev_priv(dev); 1554 volatile struct arlan_shmem __iomem *arlan = priv->card; 1555 u_char rxStatus = READSHMB(arlan->rxStatus); 1556 u_char txStatus = READSHMB(arlan->txStatus); 1557 u_short rxOffset = READSHMS(arlan->rxOffset); 1558 u_short pkt_len = READSHMS(arlan->rxLength); 1559 int interrupt_count = 0; 1560 1561 ARLAN_DEBUG_ENTRY("arlan_process_interrupt"); 1562 1563 if (test_and_set_bit(0, (void *) &priv->interrupt_processing_active)) 1564 { 1565 if (arlan_debug & ARLAN_DEBUG_CHAIN_LOCKS) 1566 printk(KERN_ERR "interrupt chain reentering \n"); 1567 goto end_int_process; 1568 } 1569 while ((rxStatus || txStatus || priv->interrupt_ack_requested) 1570 && (interrupt_count < 5)) 1571 { 1572 if (rxStatus) 1573 priv->last_rx_int_ack_time = jiffies; 1574 1575 arlan_command(dev, ARLAN_COMMAND_INT_ACK); 1576 arlan_command(dev, ARLAN_COMMAND_INT_ENABLE); 1577 1578 IFDEBUG(ARLAN_DEBUG_INTERRUPT) 1579 printk(KERN_ERR "%s: got IRQ rx %x tx %x comm %x rxOff %x rxLen %x \n", 1580 dev->name, rxStatus, txStatus, READSHMB(arlan->commandByte), 1581 rxOffset, pkt_len); 1582 1583 if (rxStatus == 0 && txStatus == 0) 1584 { 1585 if (priv->irq_test_done) 1586 { 1587 if (!registrationBad(dev)) 1588 IFDEBUG(ARLAN_DEBUG_INTERRUPT) printk(KERN_ERR "%s unknown interrupt(nop? regLost ?) reason tx %d rx %d ", 1589 dev->name, txStatus, rxStatus); 1590 } else { 1591 IFDEBUG(ARLAN_DEBUG_INTERRUPT) 1592 printk(KERN_INFO "%s irq $%d test OK \n", dev->name, dev->irq); 1593 1594 } 1595 priv->interrupt_ack_requested = 0; 1596 goto ends; 1597 } 1598 if (txStatus != 0) 1599 { 1600 WRITESHMB(arlan->txStatus, 0x00); 1601 arlan_tx_done_interrupt(dev, txStatus); 1602 goto ends; 1603 } 1604 if (rxStatus == 1 || rxStatus == 2) 1605 { /* a packet waiting */ 1606 arlan_rx_interrupt(dev, rxStatus, rxOffset, pkt_len); 1607 goto ends; 1608 } 1609 if (rxStatus > 2 && rxStatus < 0xff) 1610 { 1611 WRITESHMB(arlan->rxStatus, 0x00); 1612 printk(KERN_ERR "%s unknown rxStatus reason tx %d rx %d ", 1613 dev->name, txStatus, rxStatus); 1614 goto ends; 1615 } 1616 if (rxStatus == 0xff) 1617 { 1618 WRITESHMB(arlan->rxStatus, 0x00); 1619 arlan_command(dev, ARLAN_COMMAND_RX); 1620 if (registrationBad(dev)) 1621 netif_device_detach(dev); 1622 if (!registrationBad(dev)) 1623 { 1624 priv->registrationLastSeen = jiffies; 1625 if (!netif_queue_stopped(dev) && !priv->under_reset && !priv->under_config) 1626 netif_wake_queue (dev); 1627 } 1628 goto ends; 1629 } 1630ends: 1631 1632 arlan_command_process(dev); 1633 1634 rxStatus = READSHMB(arlan->rxStatus); 1635 txStatus = READSHMB(arlan->txStatus); 1636 rxOffset = READSHMS(arlan->rxOffset); 1637 pkt_len = READSHMS(arlan->rxLength); 1638 1639 1640 priv->irq_test_done = 1; 1641 1642 interrupt_count++; 1643 } 1644 priv->interrupt_processing_active = 0; 1645 1646end_int_process: 1647 arlan_command_process(dev); 1648 1649 ARLAN_DEBUG_EXIT("arlan_process_interrupt"); 1650 return; 1651} 1652 1653static irqreturn_t arlan_interrupt(int irq, void *dev_id) 1654{ 1655 struct net_device *dev = dev_id; 1656 struct arlan_private *priv = netdev_priv(dev); 1657 volatile struct arlan_shmem __iomem *arlan = priv->card; 1658 u_char rxStatus = READSHMB(arlan->rxStatus); 1659 u_char txStatus = READSHMB(arlan->txStatus); 1660 1661 ARLAN_DEBUG_ENTRY("arlan_interrupt"); 1662 1663 1664 if (!rxStatus && !txStatus) 1665 priv->interrupt_ack_requested++; 1666 1667 arlan_process_interrupt(dev); 1668 1669 priv->irq_test_done = 1; 1670 1671 ARLAN_DEBUG_EXIT("arlan_interrupt"); 1672 return IRQ_HANDLED; 1673 1674} 1675 1676 1677static int arlan_close(struct net_device *dev) 1678{ 1679 struct arlan_private *priv = netdev_priv(dev); 1680 1681 ARLAN_DEBUG_ENTRY("arlan_close"); 1682 1683 del_timer_sync(&priv->timer); 1684 1685 arlan_command(dev, ARLAN_COMMAND_POWERDOWN); 1686 1687 IFDEBUG(ARLAN_DEBUG_STARTUP) 1688 printk(KERN_NOTICE "%s: Closing device\n", dev->name); 1689 1690 netif_stop_queue(dev); 1691 free_irq(dev->irq, dev); 1692 1693 ARLAN_DEBUG_EXIT("arlan_close"); 1694 return 0; 1695} 1696 1697#ifdef ARLAN_DEBUGGING 1698static long alignLong(volatile u_char * ptr) 1699{ 1700 long ret; 1701 memcpy_fromio(&ret, (void *) ptr, 4); 1702 return ret; 1703} 1704#endif 1705 1706/* 1707 * Get the current statistics. 1708 * This may be called with the card open or closed. 1709 */ 1710 1711static struct net_device_stats *arlan_statistics(struct net_device *dev) 1712{ 1713 struct arlan_private *priv = netdev_priv(dev); 1714 volatile struct arlan_shmem __iomem *arlan = priv->card; 1715 1716 1717 ARLAN_DEBUG_ENTRY("arlan_statistics"); 1718 1719 /* Update the statistics from the device registers. */ 1720 1721 READSHM(priv->stats.collisions, arlan->numReTransmissions, u_int); 1722 READSHM(priv->stats.rx_crc_errors, arlan->numCRCErrors, u_int); 1723 READSHM(priv->stats.rx_dropped, arlan->numFramesDiscarded, u_int); 1724 READSHM(priv->stats.rx_fifo_errors, arlan->numRXBufferOverflows, u_int); 1725 READSHM(priv->stats.rx_frame_errors, arlan->numReceiveFramesLost, u_int); 1726 READSHM(priv->stats.rx_over_errors, arlan->numRXOverruns, u_int); 1727 READSHM(priv->stats.rx_packets, arlan->numDatagramsReceived, u_int); 1728 READSHM(priv->stats.tx_aborted_errors, arlan->numAbortErrors, u_int); 1729 READSHM(priv->stats.tx_carrier_errors, arlan->numStatusTimeouts, u_int); 1730 READSHM(priv->stats.tx_dropped, arlan->numDatagramsDiscarded, u_int); 1731 READSHM(priv->stats.tx_fifo_errors, arlan->numTXUnderruns, u_int); 1732 READSHM(priv->stats.tx_packets, arlan->numDatagramsTransmitted, u_int); 1733 READSHM(priv->stats.tx_window_errors, arlan->numHoldOffs, u_int); 1734 1735 ARLAN_DEBUG_EXIT("arlan_statistics"); 1736 1737 return &priv->stats; 1738} 1739 1740 1741static void arlan_set_multicast(struct net_device *dev) 1742{ 1743 struct arlan_private *priv = netdev_priv(dev); 1744 volatile struct arlan_shmem __iomem *arlan = priv->card; 1745 struct arlan_conf_stru *conf = priv->Conf; 1746 int board_conf_needed = 0; 1747 1748 1749 ARLAN_DEBUG_ENTRY("arlan_set_multicast"); 1750 1751 if (dev->flags & IFF_PROMISC) 1752 { 1753 unsigned char recMode; 1754 READSHM(recMode, arlan->receiveMode, u_char); 1755 conf->receiveMode = (ARLAN_RCV_PROMISC | ARLAN_RCV_CONTROL); 1756 if (conf->receiveMode != recMode) 1757 board_conf_needed = 1; 1758 } 1759 else 1760 { 1761 /* turn off promiscuous mode */ 1762 unsigned char recMode; 1763 READSHM(recMode, arlan->receiveMode, u_char); 1764 conf->receiveMode = ARLAN_RCV_CLEAN | ARLAN_RCV_CONTROL; 1765 if (conf->receiveMode != recMode) 1766 board_conf_needed = 1; 1767 } 1768 if (board_conf_needed) 1769 arlan_command(dev, ARLAN_COMMAND_CONF); 1770 1771 ARLAN_DEBUG_EXIT("arlan_set_multicast"); 1772} 1773 1774 1775struct net_device * __init arlan_probe(int unit) 1776{ 1777 struct net_device *dev; 1778 int err; 1779 int m; 1780 1781 ARLAN_DEBUG_ENTRY("arlan_probe"); 1782 1783 if (arlans_found == MAX_ARLANS) 1784 return ERR_PTR(-ENODEV); 1785 1786 /* 1787 * Reserve space for local data and a copy of the shared memory 1788 * that is used by the /proc interface. 1789 */ 1790 dev = alloc_etherdev(sizeof(struct arlan_private) 1791 + sizeof(struct arlan_shmem)); 1792 if (!dev) 1793 return ERR_PTR(-ENOMEM); 1794 1795 SET_MODULE_OWNER(dev); 1796 1797 if (unit >= 0) { 1798 sprintf(dev->name, "eth%d", unit); 1799 netdev_boot_setup_check(dev); 1800 1801 if (dev->mem_start) { 1802 if (arlan_probe_here(dev, dev->mem_start) == 0) 1803 goto found; 1804 goto not_found; 1805 } 1806 1807 } 1808 1809 1810 for (m = (int)phys_to_virt(lastFoundAt) + ARLAN_SHMEM_SIZE; 1811 m <= (int)phys_to_virt(0xDE000); 1812 m += ARLAN_SHMEM_SIZE) 1813 { 1814 if (arlan_probe_here(dev, m) == 0) 1815 { 1816 lastFoundAt = (int)virt_to_phys((void*)m); 1817 goto found; 1818 } 1819 } 1820 1821 if (lastFoundAt == 0xbe000) 1822 printk(KERN_ERR "arlan: No Arlan devices found \n"); 1823 1824 not_found: 1825 free_netdev(dev); 1826 return ERR_PTR(-ENODEV); 1827 1828 found: 1829 err = arlan_setup_device(dev, arlans_found); 1830 if (err) 1831 dev = ERR_PTR(err); 1832 else if (!arlans_found++) 1833 printk(KERN_INFO "Arlan driver %s\n", arlan_version); 1834 1835 return dev; 1836} 1837 1838#ifdef MODULE 1839int __init init_module(void) 1840{ 1841 int i = 0; 1842 1843 ARLAN_DEBUG_ENTRY("init_module"); 1844 1845 if (channelSet != channelSetUNKNOWN || channelNumber != channelNumberUNKNOWN || systemId != systemIdUNKNOWN) 1846 return -EINVAL; 1847 1848 for (i = 0; i < MAX_ARLANS; i++) { 1849 struct net_device *dev = arlan_probe(i); 1850 1851 if (IS_ERR(dev)) 1852 return PTR_ERR(dev); 1853 } 1854 init_arlan_proc(); 1855 printk(KERN_INFO "Arlan driver %s\n", arlan_version); 1856 ARLAN_DEBUG_EXIT("init_module"); 1857 return 0; 1858} 1859 1860 1861void __exit cleanup_module(void) 1862{ 1863 int i = 0; 1864 struct net_device *dev; 1865 1866 ARLAN_DEBUG_ENTRY("cleanup_module"); 1867 1868 IFDEBUG(ARLAN_DEBUG_SHUTDOWN) 1869 printk(KERN_INFO "arlan: unloading module\n"); 1870 1871 cleanup_arlan_proc(); 1872 1873 for (i = 0; i < MAX_ARLANS; i++) 1874 { 1875 dev = arlan_device[i]; 1876 if (dev) { 1877 arlan_command(dev, ARLAN_COMMAND_POWERDOWN ); 1878 1879 unregister_netdev(dev); 1880 release_mem_region(virt_to_phys((void *) dev->mem_start), 1881 ARLAN_SHMEM_SIZE); 1882 free_netdev(dev); 1883 arlan_device[i] = NULL; 1884 } 1885 } 1886 1887 ARLAN_DEBUG_EXIT("cleanup_module"); 1888} 1889 1890 1891#endif 1892MODULE_LICENSE("GPL"); 1893