arlan.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:57k
- /*
- * Copyright (C) 1997 Cullen Jennings
- * Copyright (C) 1998 Elmer Joandiu, elmer@ylenurme.ee
- * GNU General Public License applies
- * This module provides support for the Arlan 655 card made by Aironet
- */
- #include <linux/config.h>
- #include "arlan.h"
- #if BITS_PER_LONG != 32
- # error FIXME: this driver requires a 32-bit platform
- #endif
- static const char *arlan_version = "C.Jennigs 97 & Elmer.Joandi@ut.ee Oct'98, http://www.ylenurme.ee/~elmer/655/";
- struct net_device *arlan_device[MAX_ARLANS];
- int last_arlan;
- static int SID = SIDUNKNOWN;
- static int radioNodeId = radioNodeIdUNKNOWN;
- static char encryptionKey[12] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'};
- static char *siteName = siteNameUNKNOWN;
- static int mem = memUNKNOWN;
- int arlan_debug = debugUNKNOWN;
- static int probe = probeUNKNOWN;
- static int numDevices = numDevicesUNKNOWN;
- static int spreadingCode = spreadingCodeUNKNOWN;
- static int channelNumber = channelNumberUNKNOWN;
- static int channelSet = channelSetUNKNOWN;
- static int systemId = systemIdUNKNOWN;
- static int registrationMode = registrationModeUNKNOWN;
- static int keyStart;
- static int tx_delay_ms;
- static int retries = 5;
- static int async = 1;
- static int tx_queue_len = 1;
- static int arlan_EEPROM_bad;
- #ifdef ARLAN_DEBUGGING
- static int arlan_entry_debug;
- static int arlan_exit_debug;
- static int testMemory = testMemoryUNKNOWN;
- static int irq = irqUNKNOWN;
- static int txScrambled = 1;
- static int mdebug;
- #endif
- #if LINUX_VERSION_CODE > 0x20100
- MODULE_PARM(irq, "i");
- MODULE_PARM(mem, "i");
- MODULE_PARM(probe, "i");
- MODULE_PARM(arlan_debug, "i");
- MODULE_PARM(numDevices, "i");
- MODULE_PARM(testMemory, "i");
- MODULE_PARM(spreadingCode, "i");
- MODULE_PARM(channelNumber, "i");
- MODULE_PARM(channelSet, "i");
- MODULE_PARM(systemId, "i");
- MODULE_PARM(registrationMode, "i");
- MODULE_PARM(radioNodeId, "i");
- MODULE_PARM(SID, "i");
- MODULE_PARM(txScrambled, "i");
- MODULE_PARM(keyStart, "i");
- MODULE_PARM(mdebug, "i");
- MODULE_PARM(tx_delay_ms, "i");
- MODULE_PARM(retries, "i");
- MODULE_PARM(async, "i");
- MODULE_PARM(tx_queue_len, "i");
- MODULE_PARM(arlan_entry_debug, "i");
- MODULE_PARM(arlan_exit_debug, "i");
- MODULE_PARM(arlan_entry_and_exit_debug, "i");
- MODULE_PARM(arlan_EEPROM_bad, "i");
- MODULE_PARM_DESC(irq, "(unused)");
- MODULE_PARM_DESC(mem, "Arlan memory address for single device probing");
- MODULE_PARM_DESC(probe, "Arlan probe at initialization (0-1)");
- MODULE_PARM_DESC(arlan_debug, "Arlan debug enable (0-1)");
- MODULE_PARM_DESC(numDevices, "Number of Arlan devices; ignored if >1");
- MODULE_PARM_DESC(testMemory, "(unused)");
- MODULE_PARM_DESC(mdebug, "Arlan multicast debugging (0-1)");
- MODULE_PARM_DESC(retries, "Arlan maximum packet retransmisions");
- #ifdef ARLAN_ENTRY_EXIT_DEBUGGING
- MODULE_PARM_DESC(arlan_entry_debug, "Arlan driver function entry debugging");
- MODULE_PARM_DESC(arlan_exit_debug, "Arlan driver function exit debugging");
- MODULE_PARM_DESC(arlan_entry_and_exit_debug, "Arlan driver function entry and exit debugging");
- #else
- MODULE_PARM_DESC(arlan_entry_debug, "(ignored)");
- MODULE_PARM_DESC(arlan_exit_debug, "(ignored)");
- MODULE_PARM_DESC(arlan_entry_and_exit_debug, "(ignored)");
- #endif
- EXPORT_SYMBOL(arlan_device);
- EXPORT_SYMBOL(arlan_conf);
- EXPORT_SYMBOL(last_arlan);
- // #warning kernel 2.1.110 tested
- #define myATOMIC_INIT(a,b) atomic_set(&(a),b)
- #else
- #define test_and_set_bit set_bit
- #if LINUX_VERSION_CODE != 0x20024
- // #warning kernel 2.0.36 tested
- #endif
- #define myATOMIC_INIT(a,b) a = b;
- #endif
- struct arlan_conf_stru arlan_conf[MAX_ARLANS];
- static int arlans_found;
- static int arlan_probe_here(struct net_device *dev, int ioaddr);
- static int arlan_open(struct net_device *dev);
- static int arlan_tx(struct sk_buff *skb, struct net_device *dev);
- static void arlan_interrupt(int irq, void *dev_id, struct pt_regs *regs);
- static int arlan_close(struct net_device *dev);
- static struct net_device_stats *
- arlan_statistics (struct net_device *dev);
- static void arlan_set_multicast (struct net_device *dev);
- static int arlan_hw_tx (struct net_device* dev, char *buf, int length );
- static int arlan_hw_config (struct net_device * dev);
- static void arlan_tx_done_interrupt (struct net_device * dev, int status);
- static void arlan_rx_interrupt (struct net_device * dev, u_char rxStatus, u_short, u_short);
- static void arlan_process_interrupt (struct net_device * dev);
- static void arlan_tx_timeout (struct net_device *dev);
- int arlan_command(struct net_device * dev, int command);
- EXPORT_SYMBOL(arlan_command);
- static inline long long arlan_time(void)
- {
- struct timeval timev;
- do_gettimeofday(&timev);
- return ((long long) timev.tv_sec * 1000000 + timev.tv_usec);
- };
- #ifdef ARLAN_ENTRY_EXIT_DEBUGGING
- #define ARLAN_DEBUG_ENTRY(name)
- {
- struct timeval timev;
- do_gettimeofday(&timev);
- if (arlan_entry_debug || arlan_entry_and_exit_debug)
- printk("--->>>" name " %ld " "n",((long int) timev.tv_sec * 1000000 + timev.tv_usec));
- }
- #define ARLAN_DEBUG_EXIT(name)
- {
- struct timeval timev;
- do_gettimeofday(&timev);
- if (arlan_exit_debug || arlan_entry_and_exit_debug)
- printk("<<<---" name " %ld " "n",((long int) timev.tv_sec * 1000000 + timev.tv_usec) );
- }
- #else
- #define ARLAN_DEBUG_ENTRY(name)
- #define ARLAN_DEBUG_EXIT(name)
- #endif
- #define arlan_interrupt_ack(dev)
- clearClearInterrupt(dev);
- setClearInterrupt(dev);
- #define ARLAN_COMMAND_LOCK(dev)
- if (atomic_dec_and_test(&((struct arlan_private * )dev->priv)->card_users))
- arlan_wait_command_complete_short(dev,__LINE__);
- #define ARLAN_COMMAND_UNLOCK(dev)
- atomic_inc(&((struct arlan_private * )dev->priv)->card_users);
- #define ARLAN_COMMAND_INC(dev)
- {((struct arlan_private *) dev->priv)->under_command++;}
- #define ARLAN_COMMAND_ZERO(dev)
- {((struct arlan_private *) dev->priv)->under_command =0;}
- #define ARLAN_UNDER_COMMAND(dev)
- (((struct arlan_private *) dev->priv)->under_command)
- #define ARLAN_COMMAND_START(dev) ARLAN_COMMAND_INC(dev)
- #define ARLAN_COMMAND_END(dev) ARLAN_COMMAND_ZERO(dev)
- #define ARLAN_TOGGLE_START(dev)
- {((struct arlan_private *) dev->priv)->under_toggle++;}
- #define ARLAN_TOGGLE_END(dev)
- {((struct arlan_private *) dev->priv)->under_toggle=0;}
- #define ARLAN_UNDER_TOGGLE(dev)
- (((struct arlan_private *) dev->priv)->under_toggle)
- static inline int arlan_drop_tx(struct net_device *dev)
- {
- struct arlan_private *priv = ((struct arlan_private *) dev->priv);
- priv->stats.tx_errors++;
- if (priv->Conf->tx_delay_ms)
- {
- priv->tx_done_delayed = jiffies + priv->Conf->tx_delay_ms * HZ / 1000 + 1;
- }
- else
- {
- priv->waiting_command_mask &= ~ARLAN_COMMAND_TX;
- TXHEAD(dev).offset = 0;
- TXTAIL(dev).offset = 0;
- priv->txLast = 0;
- priv->txOffset = 0;
- priv->bad = 0;
- if (!priv->under_reset && !priv->under_config)
- netif_wake_queue (dev);
- }
- return 1;
- };
- int arlan_command(struct net_device *dev, int command_p)
- {
- volatile struct arlan_shmem *arlan = ((struct arlan_private *) dev->priv)->card;
- struct arlan_conf_stru *conf = ((struct arlan_private *) dev->priv)->Conf;
- struct arlan_private *priv = (struct arlan_private *) dev->priv;
- int udelayed = 0;
- int i = 0;
- long long time_mks = arlan_time();
- ARLAN_DEBUG_ENTRY("arlan_command");
- if (priv->card_polling_interval)
- priv->card_polling_interval = 1;
- if (arlan_debug & ARLAN_DEBUG_CHAIN_LOCKS)
- printk(KERN_DEBUG "arlan_command, %lx lock %lx commandByte %x waiting %x incoming %x n",
- jiffies, priv->command_lock, READSHMB(arlan->commandByte),
- priv->waiting_command_mask, command_p);
- priv->waiting_command_mask |= command_p;
- if (priv->waiting_command_mask & ARLAN_COMMAND_RESET)
- if (jiffies - priv->lastReset < 5 * HZ)
- priv->waiting_command_mask &= ~ARLAN_COMMAND_RESET;
- if (priv->waiting_command_mask & ARLAN_COMMAND_INT_ACK)
- {
- arlan_interrupt_ack(dev);
- priv->waiting_command_mask &= ~ARLAN_COMMAND_INT_ACK;
- }
- if (priv->waiting_command_mask & ARLAN_COMMAND_INT_ENABLE)
- {
- setInterruptEnable(dev);
- priv->waiting_command_mask &= ~ARLAN_COMMAND_INT_ENABLE;
- }
- /* Card access serializing lock */
- if (test_and_set_bit(0, (void *) &priv->command_lock))
- {
- if (arlan_debug & ARLAN_DEBUG_CHAIN_LOCKS)
- printk(KERN_DEBUG "arlan_command: entered when command locked n");
- goto command_busy_end;
- }
- /* Check cards status and waiting */
- if (priv->waiting_command_mask & (ARLAN_COMMAND_LONG_WAIT_NOW | ARLAN_COMMAND_WAIT_NOW))
- {
- while (priv->waiting_command_mask & (ARLAN_COMMAND_LONG_WAIT_NOW | ARLAN_COMMAND_WAIT_NOW))
- {
- if (READSHMB(arlan->resetFlag) ||
- READSHMB(arlan->commandByte)) /* ||
- (readControlRegister(dev) & ARLAN_ACCESS))
- */
- udelay(40);
- else
- priv->waiting_command_mask &= ~(ARLAN_COMMAND_LONG_WAIT_NOW | ARLAN_COMMAND_WAIT_NOW);
- udelayed++;
- if (priv->waiting_command_mask & ARLAN_COMMAND_LONG_WAIT_NOW)
- {
- if (udelayed * 40 > 1000000)
- {
- printk(KERN_ERR "%s long wait too long n", dev->name);
- priv->waiting_command_mask |= ARLAN_COMMAND_RESET;
- break;
- }
- }
- else if (priv->waiting_command_mask & ARLAN_COMMAND_WAIT_NOW)
- {
- if (udelayed * 40 > 1000)
- {
- printk(KERN_ERR "%s short wait too long n", dev->name);
- goto bad_end;
- }
- }
- }
- }
- else
- {
- i = 0;
- while ((READSHMB(arlan->resetFlag) ||
- READSHMB(arlan->commandByte)) &&
- conf->pre_Command_Wait > (i++) * 10)
- udelay(10);
- if ((READSHMB(arlan->resetFlag) ||
- READSHMB(arlan->commandByte)) &&
- !(priv->waiting_command_mask & ARLAN_COMMAND_RESET))
- {
- goto card_busy_end;
- }
- }
- if (priv->waiting_command_mask & ARLAN_COMMAND_RESET)
- priv->under_reset = 1;
- if (priv->waiting_command_mask & ARLAN_COMMAND_CONF)
- priv->under_config = 1;
- /* Issuing command */
- arlan_lock_card_access(dev);
- if (priv->waiting_command_mask & ARLAN_COMMAND_POWERUP)
- {
- // if (readControlRegister(dev) & (ARLAN_ACCESS && ARLAN_POWER))
- setPowerOn(dev);
- arlan_interrupt_lancpu(dev);
- priv->waiting_command_mask &= ~ARLAN_COMMAND_POWERUP;
- priv->waiting_command_mask |= ARLAN_COMMAND_RESET;
- priv->card_polling_interval = HZ / 10;
- }
- else if (priv->waiting_command_mask & ARLAN_COMMAND_ACTIVATE)
- {
- WRITESHMB(arlan->commandByte, ARLAN_COM_ACTIVATE);
- arlan_interrupt_lancpu(dev);
- priv->waiting_command_mask &= ~ARLAN_COMMAND_ACTIVATE;
- priv->card_polling_interval = HZ / 10;
- }
- else if (priv->waiting_command_mask & ARLAN_COMMAND_RX_ABORT)
- {
- if (priv->rx_command_given)
- {
- WRITESHMB(arlan->commandByte, ARLAN_COM_RX_ABORT);
- arlan_interrupt_lancpu(dev);
- priv->rx_command_given = 0;
- }
- priv->waiting_command_mask &= ~ARLAN_COMMAND_RX_ABORT;
- priv->card_polling_interval = 1;
- }
- else if (priv->waiting_command_mask & ARLAN_COMMAND_TX_ABORT)
- {
- if (priv->tx_command_given)
- {
- WRITESHMB(arlan->commandByte, ARLAN_COM_TX_ABORT);
- arlan_interrupt_lancpu(dev);
- priv->tx_command_given = 0;
- }
- priv->waiting_command_mask &= ~ARLAN_COMMAND_TX_ABORT;
- priv->card_polling_interval = 1;
- }
- else if (priv->waiting_command_mask & ARLAN_COMMAND_RESET)
- {
- priv->under_reset=1;
- netif_stop_queue (dev);
- arlan_drop_tx(dev);
- if (priv->tx_command_given || priv->rx_command_given)
- {
- printk(KERN_ERR "%s: Reset under tx or rx command n", dev->name);
- };
- netif_stop_queue (dev);
- if (arlan_debug & ARLAN_DEBUG_RESET)
- printk(KERN_ERR "%s: Doing chip resetn", dev->name);
- priv->lastReset = jiffies;
- WRITESHM(arlan->commandByte, 0, u_char);
- /* hold card in reset state */
- setHardwareReset(dev);
- /* set reset flag and then release reset */
- WRITESHM(arlan->resetFlag, 0xff, u_char);
- clearChannelAttention(dev);
- clearHardwareReset(dev);
- priv->numResets++;
- priv->card_polling_interval = HZ / 4;
- priv->waiting_command_mask &= ~ARLAN_COMMAND_RESET;
- priv->waiting_command_mask |= ARLAN_COMMAND_INT_RACK;
- // priv->waiting_command_mask |= ARLAN_COMMAND_INT_RENABLE;
- // priv->waiting_command_mask |= ARLAN_COMMAND_RX;
- }
- else if (priv->waiting_command_mask & ARLAN_COMMAND_INT_RACK)
- {
- clearHardwareReset(dev);
- clearClearInterrupt(dev);
- setClearInterrupt(dev);
- setInterruptEnable(dev);
- priv->waiting_command_mask &= ~ARLAN_COMMAND_INT_RACK;
- priv->waiting_command_mask |= ARLAN_COMMAND_CONF;
- priv->under_config = 1;
- priv->under_reset = 0;
- }
- else if (priv->waiting_command_mask & ARLAN_COMMAND_INT_RENABLE)
- {
- setInterruptEnable(dev);
- priv->waiting_command_mask &= ~ARLAN_COMMAND_INT_RENABLE;
- }
- else if (priv->waiting_command_mask & ARLAN_COMMAND_CONF)
- {
- if (priv->tx_command_given || priv->rx_command_given)
- {
- printk(KERN_ERR "%s: Reset under tx or rx command n", dev->name);
- }
- arlan_drop_tx(dev);
- setInterruptEnable(dev);
- arlan_hw_config(dev);
- arlan_interrupt_lancpu(dev);
- priv->waiting_command_mask &= ~ARLAN_COMMAND_CONF;
- priv->card_polling_interval = HZ / 10;
- // priv->waiting_command_mask |= ARLAN_COMMAND_INT_RACK;
- // priv->waiting_command_mask |= ARLAN_COMMAND_INT_ENABLE;
- priv->waiting_command_mask |= ARLAN_COMMAND_CONF_WAIT;
- }
- else if (priv->waiting_command_mask & ARLAN_COMMAND_CONF_WAIT)
- {
- if (READSHMB(arlan->configuredStatusFlag) != 0 &&
- READSHMB(arlan->diagnosticInfo) == 0xff)
- {
- priv->waiting_command_mask &= ~ARLAN_COMMAND_CONF_WAIT;
- priv->waiting_command_mask |= ARLAN_COMMAND_RX;
- priv->waiting_command_mask |= ARLAN_COMMAND_TBUSY_CLEAR;
- priv->card_polling_interval = HZ / 10;
- priv->tx_command_given = 0;
- priv->under_config = 0;
- }
- else
- {
- priv->card_polling_interval = 1;
- if (arlan_debug & ARLAN_DEBUG_TIMING)
- printk(KERN_ERR "configure delayed n");
- }
- }
- else if (priv->waiting_command_mask & ARLAN_COMMAND_RX)
- {
- if (!registrationBad(dev))
- {
- setInterruptEnable(dev);
- memset_io((void *) arlan->commandParameter, 0, 0xf);
- WRITESHMB(arlan->commandByte, ARLAN_COM_INT | ARLAN_COM_RX_ENABLE);
- WRITESHMB(arlan->commandParameter[0], conf->rxParameter);
- arlan_interrupt_lancpu(dev);
- priv->rx_command_given = 0; // mnjah, bad
- priv->last_rx_time = arlan_time();
- priv->waiting_command_mask &= ~ARLAN_COMMAND_RX;
- priv->card_polling_interval = 1;
- }
- else
- priv->card_polling_interval = 2;
- }
- else if (priv->waiting_command_mask & ARLAN_COMMAND_TBUSY_CLEAR)
- {
- if ( !registrationBad(dev) &&
- (netif_queue_stopped(dev) || !netif_running(dev)) )
- {
- priv->waiting_command_mask &= ~ARLAN_COMMAND_TBUSY_CLEAR;
- netif_wake_queue (dev);
- };
- }
- else if (priv->waiting_command_mask & ARLAN_COMMAND_TX)
- {
- if (!test_and_set_bit(0, (void *) &priv->tx_command_given))
- {
- if ((time_mks - priv->last_tx_time > conf->rx_tweak1) ||
- (time_mks - priv->last_rx_int_ack_time < conf->rx_tweak2))
- {
- setInterruptEnable(dev);
- memset_io((void *) arlan->commandParameter, 0, 0xf);
- WRITESHMB(arlan->commandByte, ARLAN_COM_TX_ENABLE | ARLAN_COM_INT);
- memcpy_toio((void *) arlan->commandParameter, &TXLAST(dev), 14);
- // for ( i=1 ; i < 15 ; i++) printk("%02x:",READSHMB(arlan->commandParameter[i]));
- priv->last_command_was_rx = 0;
- priv->tx_last_sent = jiffies;
- arlan_interrupt_lancpu(dev);
- priv->last_tx_time = arlan_time();
- priv->tx_command_given = 1;
- priv->waiting_command_mask &= ~ARLAN_COMMAND_TX;
- priv->card_polling_interval = 1;
- }
- else
- {
- priv->tx_command_given = 0;
- priv->card_polling_interval = 1;
- }
- }
- else if (arlan_debug & ARLAN_DEBUG_CHAIN_LOCKS)
- printk(KERN_ERR "tx command when tx chain locked n");
- }
- else if (priv->waiting_command_mask & ARLAN_COMMAND_NOOPINT)
- {
- {
- WRITESHMB(arlan->commandByte, ARLAN_COM_NOP | ARLAN_COM_INT);
- }
- arlan_interrupt_lancpu(dev);
- priv->waiting_command_mask &= ~ARLAN_COMMAND_NOOPINT;
- priv->card_polling_interval = HZ / 3;
- }
- else if (priv->waiting_command_mask & ARLAN_COMMAND_NOOP)
- {
- WRITESHMB(arlan->commandByte, ARLAN_COM_NOP);
- arlan_interrupt_lancpu(dev);
- priv->waiting_command_mask &= ~ARLAN_COMMAND_NOOP;
- priv->card_polling_interval = HZ / 3;
- }
- else if (priv->waiting_command_mask & ARLAN_COMMAND_SLOW_POLL)
- {
- WRITESHMB(arlan->commandByte, ARLAN_COM_GOTO_SLOW_POLL);
- arlan_interrupt_lancpu(dev);
- priv->waiting_command_mask &= ~ARLAN_COMMAND_SLOW_POLL;
- priv->card_polling_interval = HZ / 3;
- }
- else if (priv->waiting_command_mask & ARLAN_COMMAND_POWERDOWN)
- {
- setPowerOff(dev);
- if (arlan_debug & ARLAN_DEBUG_CARD_STATE)
- printk(KERN_WARNING "%s: Arlan Going Standbyn", dev->name);
- priv->waiting_command_mask &= ~ARLAN_COMMAND_POWERDOWN;
- priv->card_polling_interval = 3 * HZ;
- }
- arlan_unlock_card_access(dev);
- for (i = 0; READSHMB(arlan->commandByte) && i < 20; i++)
- udelay(10);
- if (READSHMB(arlan->commandByte))
- if (arlan_debug & ARLAN_DEBUG_CARD_STATE)
- printk(KERN_ERR "card busy leaving command %x n", priv->waiting_command_mask);
- priv->command_lock = 0;
- ARLAN_DEBUG_EXIT("arlan_command");
- priv->last_command_buff_free_time = jiffies;
- return 0;
- card_busy_end:
- if (jiffies - priv->last_command_buff_free_time > HZ)
- priv->waiting_command_mask |= ARLAN_COMMAND_CLEAN_AND_RESET;
- if (arlan_debug & ARLAN_DEBUG_CARD_STATE)
- printk(KERN_ERR "%s arlan_command card busy end n", dev->name);
- priv->command_lock = 0;
- ARLAN_DEBUG_EXIT("arlan_command");
- return 1;
- bad_end:
- printk(KERN_ERR "%s arlan_command bad end n", dev->name);
- priv->command_lock = 0;
- ARLAN_DEBUG_EXIT("arlan_command");
- return -1;
- command_busy_end:
- if (arlan_debug & ARLAN_DEBUG_CARD_STATE)
- printk(KERN_ERR "%s arlan_command command busy end n", dev->name);
- ARLAN_DEBUG_EXIT("arlan_command");
- return 2;
- };
- static inline void arlan_command_process(struct net_device *dev)
- {
- struct arlan_private *priv = ((struct arlan_private *) dev->priv);
- int times = 0;
- while (priv->waiting_command_mask && times < 8)
- {
- if (priv->waiting_command_mask)
- {
- if (arlan_command(dev, 0))
- break;
- times++;
- }
- /* if long command, we wont repeat trying */ ;
- if (priv->card_polling_interval > 1)
- break;
- times++;
- }
- }
- static inline void arlan_retransmit_now(struct net_device *dev)
- {
- struct arlan_private *priv = ((struct arlan_private *) dev->priv);
- ARLAN_DEBUG_ENTRY("arlan_retransmit_now");
- if (TXLAST(dev).offset == 0)
- {
- if (TXHEAD(dev).offset)
- {
- priv->txLast = 0;
- IFDEBUG(ARLAN_DEBUG_TX_CHAIN) printk(KERN_DEBUG "TX buff switch to head n");
- }
- else if (TXTAIL(dev).offset)
- {
- IFDEBUG(ARLAN_DEBUG_TX_CHAIN) printk(KERN_DEBUG "TX buff switch to tail n");
- priv->txLast = 1;
- }
- else
- IFDEBUG(ARLAN_DEBUG_TX_CHAIN) printk(KERN_ERR "ReTransmit buff empty");
- priv->txOffset = 0;
- netif_wake_queue (dev);
- return;
- }
- arlan_command(dev, ARLAN_COMMAND_TX);
- priv->nof_tx++;
- priv->Conf->driverRetransmissions++;
- priv->retransmissions++;
- IFDEBUG(ARLAN_DEBUG_TX_CHAIN) printk("Retransmit %d bytes n", TXLAST(dev).length);
- ARLAN_DEBUG_EXIT("arlan_retransmit_now");
- }
- static void arlan_registration_timer(unsigned long data)
- {
- struct net_device *dev = (struct net_device *) data;
- struct arlan_private *priv = (struct arlan_private *) dev->priv;
- int lostTime = ((int) (jiffies - priv->registrationLastSeen)) * 1000 / HZ;
- int bh_mark_needed = 0;
- int next_tick = 1;
- priv->timer_chain_active = 1;
- if (registrationBad(dev))
- {
- //debug=100;
- priv->registrationLostCount++;
- if (lostTime > 7000 && lostTime < 7200)
- {
- printk(KERN_NOTICE "%s registration Lost n", dev->name);
- }
- if (lostTime / priv->reRegisterExp > 2000)
- arlan_command(dev, ARLAN_COMMAND_CLEAN_AND_CONF);
- if (lostTime / (priv->reRegisterExp) > 3500)
- arlan_command(dev, ARLAN_COMMAND_CLEAN_AND_RESET);
- if (priv->reRegisterExp < 400)
- priv->reRegisterExp += 2;
- if (lostTime > 7200)
- {
- next_tick = HZ;
- arlan_command(dev, ARLAN_COMMAND_CLEAN_AND_RESET);
- }
- }
- else
- {
- if (priv->Conf->registrationMode && lostTime > 10000 &&
- priv->registrationLostCount)
- {
- printk(KERN_NOTICE "%s registration is back after %d millisecondsn", dev->name,
- ((int) (jiffies - priv->registrationLastSeen) * 1000) / HZ);
- }
- priv->registrationLastSeen = jiffies;
- priv->registrationLostCount = 0;
- priv->reRegisterExp = 1;
- if (!netif_running(dev) )
- netif_wake_queue(dev);
- if (priv->tx_last_sent > priv->tx_last_cleared &&
- jiffies - priv->tx_last_sent > 5*HZ ){
- arlan_command(dev, ARLAN_COMMAND_CLEAN_AND_RESET);
- priv->tx_last_cleared = jiffies;
- };
- }
- if (!registrationBad(dev) && priv->ReTransmitRequested)
- {
- IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
- printk(KERN_ERR "Retransmit from timer n");
- priv->ReTransmitRequested = 0;
- arlan_retransmit_now(dev);
- }
- if (!registrationBad(dev) &&
- time_after(jiffies, priv->tx_done_delayed) &&
- priv->tx_done_delayed != 0)
- {
- TXLAST(dev).offset = 0;
- if (priv->txLast)
- priv->txLast = 0;
- else if (TXTAIL(dev).offset)
- priv->txLast = 1;
- if (TXLAST(dev).offset)
- {
- arlan_retransmit_now(dev);
- dev->trans_start = jiffies;
- }
- if (!(TXHEAD(dev).offset && TXTAIL(dev).offset))
- {
- priv->txOffset = 0;
- netif_wake_queue (dev);
- }
- priv->tx_done_delayed = 0;
- bh_mark_needed = 1;
- }
- if (bh_mark_needed)
- {
- priv->txOffset = 0;
- netif_wake_queue (dev);
- }
- arlan_process_interrupt(dev);
- if (next_tick < priv->card_polling_interval)
- next_tick = priv->card_polling_interval;
- priv->timer_chain_active = 0;
- priv->timer.expires = jiffies + next_tick;
- add_timer(&priv->timer);
- }
- #ifdef ARLAN_DEBUGGING
- static void arlan_print_registers(struct net_device *dev, int line)
- {
- volatile struct arlan_shmem *arlan = ((struct arlan_private *) dev->priv)->card;
- u_char hostcpuLock, lancpuLock, controlRegister, cntrlRegImage,
- txStatus, rxStatus, interruptInProgress, commandByte;
- ARLAN_DEBUG_ENTRY("arlan_print_registers");
- READSHM(interruptInProgress, arlan->interruptInProgress, u_char);
- READSHM(hostcpuLock, arlan->hostcpuLock, u_char);
- READSHM(lancpuLock, arlan->lancpuLock, u_char);
- READSHM(controlRegister, arlan->controlRegister, u_char);
- READSHM(cntrlRegImage, arlan->cntrlRegImage, u_char);
- READSHM(txStatus, arlan->txStatus, u_char);
- READSHM(rxStatus, arlan->rxStatus, u_char);
- READSHM(commandByte, arlan->commandByte, u_char);
- printk(KERN_WARNING "line %04d IP %02x HL %02x LL %02x CB %02x CR %02x CRI %02x TX %02x RX %02xn",
- line, interruptInProgress, hostcpuLock, lancpuLock, commandByte,
- controlRegister, cntrlRegImage, txStatus, rxStatus);
- ARLAN_DEBUG_EXIT("arlan_print_registers");
- }
- #endif
- static int arlan_hw_tx(struct net_device *dev, char *buf, int length)
- {
- int i;
- struct arlan_private *priv = (struct arlan_private *) dev->priv;
- volatile struct arlan_shmem *arlan = priv->card;
- struct arlan_conf_stru *conf = priv->Conf;
- int tailStarts = 0x800;
- int headEnds = 0x0;
- ARLAN_DEBUG_ENTRY("arlan_hw_tx");
- if (TXHEAD(dev).offset)
- headEnds = (((TXHEAD(dev).offset + TXHEAD(dev).length - (((int) arlan->txBuffer) - ((int) arlan))) / 64) + 1) * 64;
- if (TXTAIL(dev).offset)
- tailStarts = 0x800 - (((TXTAIL(dev).offset - (((int) arlan->txBuffer) - ((int) arlan))) / 64) + 2) * 64;
- if (!TXHEAD(dev).offset && length < tailStarts)
- {
- IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
- printk(KERN_ERR "TXHEAD insert, tailStart %dn", tailStarts);
- TXHEAD(dev).offset =
- (((int) arlan->txBuffer) - ((int) arlan));
- TXHEAD(dev).length = length - ARLAN_FAKE_HDR_LEN;
- for (i = 0; i < 6; i++)
- TXHEAD(dev).dest[i] = buf[i];
- TXHEAD(dev).clear = conf->txClear;
- TXHEAD(dev).retries = conf->txRetries; /* 0 is use default */
- TXHEAD(dev).routing = conf->txRouting;
- TXHEAD(dev).scrambled = conf->txScrambled;
- memcpy_toio(((char *) arlan + TXHEAD(dev).offset), buf + ARLAN_FAKE_HDR_LEN, TXHEAD(dev).length);
- }
- else if (!TXTAIL(dev).offset && length < (0x800 - headEnds))
- {
- IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
- printk(KERN_ERR "TXTAIL insert, headEnd %dn", headEnds);
- TXTAIL(dev).offset =
- (((int) arlan->txBuffer) - ((int) arlan)) + 0x800 - (length / 64 + 2) * 64;
- TXTAIL(dev).length = length - ARLAN_FAKE_HDR_LEN;
- for (i = 0; i < 6; i++)
- TXTAIL(dev).dest[i] = buf[i];
- TXTAIL(dev).clear = conf->txClear;
- TXTAIL(dev).retries = conf->txRetries;
- TXTAIL(dev).routing = conf->txRouting;
- TXTAIL(dev).scrambled = conf->txScrambled;
- memcpy_toio(((char *) arlan + TXTAIL(dev).offset), buf + ARLAN_FAKE_HDR_LEN, TXTAIL(dev).length);
- }
- else
- {
- netif_stop_queue (dev);
- return -1;
- IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
- printk(KERN_ERR "TX TAIL & HEAD full, return, tailStart %d headEnd %dn", tailStarts, headEnds);
- }
- priv->out_bytes += length;
- priv->out_bytes10 += length;
- if (conf->measure_rate < 1)
- conf->measure_rate = 1;
- if (jiffies - priv->out_time > conf->measure_rate * HZ)
- {
- conf->out_speed = priv->out_bytes / conf->measure_rate;
- priv->out_bytes = 0;
- priv->out_time = jiffies;
- }
- if (jiffies - priv->out_time10 > conf->measure_rate * HZ * 10)
- {
- conf->out_speed10 = priv->out_bytes10 / (10 * conf->measure_rate);
- priv->out_bytes10 = 0;
- priv->out_time10 = jiffies;
- }
- if (TXHEAD(dev).offset && TXTAIL(dev).offset)
- {
- netif_stop_queue (dev);
- return 0;
- }
- else
- netif_start_queue (dev);
- IFDEBUG(ARLAN_DEBUG_HEADER_DUMP)
- printk(KERN_WARNING "%s Transmit t %2x:%2x:%2x:%2x:%2x:%2x f %2x:%2x:%2x:%2x:%2x:%2x n", dev->name,
- (unsigned char) buf[0], (unsigned char) buf[1], (unsigned char) buf[2], (unsigned char) buf[3],
- (unsigned char) buf[4], (unsigned char) buf[5], (unsigned char) buf[6], (unsigned char) buf[7],
- (unsigned char) buf[8], (unsigned char) buf[9], (unsigned char) buf[10], (unsigned char) buf[11]);
- IFDEBUG(ARLAN_DEBUG_TX_CHAIN) printk(KERN_ERR "TX command prepare for buffer %dn", priv->txLast);
- arlan_command(dev, ARLAN_COMMAND_TX);
- priv->last_command_was_rx = 0;
- priv->tx_last_sent = jiffies;
- priv->nof_tx++;
- IFDEBUG(ARLAN_DEBUG_TX_CHAIN) printk("%s TX Qued %d bytes n", dev->name, length);
- ARLAN_DEBUG_EXIT("arlan_hw_tx");
- return 0;
- }
- static int arlan_hw_config(struct net_device *dev)
- {
- volatile struct arlan_shmem *arlan = ((struct arlan_private *) dev->priv)->card;
- struct arlan_conf_stru *conf = ((struct arlan_private *) dev->priv)->Conf;
- struct arlan_private *priv = (struct arlan_private *) dev->priv;
- ARLAN_DEBUG_ENTRY("arlan_hw_config");
- printk(KERN_NOTICE "%s arlan configure called n", dev->name);
- if (arlan_EEPROM_bad)
- printk(KERN_NOTICE "arlan configure with eeprom bad option n");
- WRITESHM(arlan->spreadingCode, conf->spreadingCode, u_char);
- WRITESHM(arlan->channelSet, conf->channelSet, u_char);
- if (arlan_EEPROM_bad)
- WRITESHM(arlan->defaultChannelSet, conf->channelSet, u_char);
- WRITESHM(arlan->channelNumber, conf->channelNumber, u_char);
- WRITESHM(arlan->scramblingDisable, conf->scramblingDisable, u_char);
- WRITESHM(arlan->txAttenuation, conf->txAttenuation, u_char);
- WRITESHM(arlan->systemId, conf->systemId, u_int);
- WRITESHM(arlan->maxRetries, conf->maxRetries, u_char);
- WRITESHM(arlan->receiveMode, conf->receiveMode, u_char);
- WRITESHM(arlan->priority, conf->priority, u_char);
- WRITESHM(arlan->rootOrRepeater, conf->rootOrRepeater, u_char);
- WRITESHM(arlan->SID, conf->SID, u_int);
- WRITESHM(arlan->registrationMode, conf->registrationMode, u_char);
- WRITESHM(arlan->registrationFill, conf->registrationFill, u_char);
- WRITESHM(arlan->localTalkAddress, conf->localTalkAddress, u_char);
- WRITESHM(arlan->codeFormat, conf->codeFormat, u_char);
- WRITESHM(arlan->numChannels, conf->numChannels, u_char);
- WRITESHM(arlan->channel1, conf->channel1, u_char);
- WRITESHM(arlan->channel2, conf->channel2, u_char);
- WRITESHM(arlan->channel3, conf->channel3, u_char);
- WRITESHM(arlan->channel4, conf->channel4, u_char);
- WRITESHM(arlan->radioNodeId, conf->radioNodeId, u_short);
- WRITESHM(arlan->SID, conf->SID, u_int);
- WRITESHM(arlan->waitTime, conf->waitTime, u_short);
- WRITESHM(arlan->lParameter, conf->lParameter, u_short);
- memcpy_toio(&(arlan->_15), &(conf->_15), 3);
- WRITESHM(arlan->_15, conf->_15, u_short);
- WRITESHM(arlan->headerSize, conf->headerSize, u_short);
- if (arlan_EEPROM_bad)
- WRITESHM(arlan->hardwareType, conf->hardwareType, u_char);
- WRITESHM(arlan->radioType, conf->radioType, u_char);
- if (arlan_EEPROM_bad)
- WRITESHM(arlan->radioModule, conf->radioType, u_char);
- memcpy_toio(arlan->encryptionKey + keyStart, encryptionKey, 8);
- memcpy_toio(arlan->name, conf->siteName, 16);
- WRITESHMB(arlan->commandByte, ARLAN_COM_INT | ARLAN_COM_CONF); /* do configure */
- memset_io(arlan->commandParameter, 0, 0xf); /* 0xf */
- memset_io(arlan->commandParameter + 1, 0, 2);
- if (conf->writeEEPROM)
- {
- memset_io(arlan->commandParameter, conf->writeEEPROM, 1);
- // conf->writeEEPROM=0;
- }
- if (conf->registrationMode && conf->registrationInterrupts)
- memset_io(arlan->commandParameter + 3, 1, 1);
- else
- memset_io(arlan->commandParameter + 3, 0, 1);
- priv->irq_test_done = 0;
- if (conf->tx_queue_len)
- dev->tx_queue_len = conf->tx_queue_len;
- udelay(100);
- ARLAN_DEBUG_EXIT("arlan_hw_config");
- return 0;
- }
- static int arlan_read_card_configuration(struct net_device *dev)
- {
- u_char tlx415;
- volatile struct arlan_shmem *arlan = ((struct arlan_private *) dev->priv)->card;
- struct arlan_conf_stru *conf = ((struct arlan_private *) dev->priv)->Conf;
- ARLAN_DEBUG_ENTRY("arlan_read_card_configuration");
- if (radioNodeId == radioNodeIdUNKNOWN)
- {
- READSHM(conf->radioNodeId, arlan->radioNodeId, u_short);
- }
- else
- conf->radioNodeId = radioNodeId;
-
- if (SID == SIDUNKNOWN)
- {
- READSHM(conf->SID, arlan->SID, u_int);
- }
- else conf->SID = SID;
-
- if (spreadingCode == spreadingCodeUNKNOWN)
- {
- READSHM(conf->spreadingCode, arlan->spreadingCode, u_char);
- }
- else
- conf->spreadingCode = spreadingCode;
-
- if (channelSet == channelSetUNKNOWN)
- {
- READSHM(conf->channelSet, arlan->channelSet, u_char);
- }
- else conf->channelSet = channelSet;
- if (channelNumber == channelNumberUNKNOWN)
- {
- READSHM(conf->channelNumber, arlan->channelNumber, u_char);
- }
- else conf->channelNumber = channelNumber;
-
- READSHM(conf->scramblingDisable, arlan->scramblingDisable, u_char);
- READSHM(conf->txAttenuation, arlan->txAttenuation, u_char);
-
- if (systemId == systemIdUNKNOWN)
- {
- READSHM(conf->systemId, arlan->systemId, u_int);
- }
- else conf->systemId = systemId;
-
- READSHM(conf->maxDatagramSize, arlan->maxDatagramSize, u_short);
- READSHM(conf->maxFrameSize, arlan->maxFrameSize, u_short);
- READSHM(conf->maxRetries, arlan->maxRetries, u_char);
- READSHM(conf->receiveMode, arlan->receiveMode, u_char);
- READSHM(conf->priority, arlan->priority, u_char);
- READSHM(conf->rootOrRepeater, arlan->rootOrRepeater, u_char);
- if (SID == SIDUNKNOWN)
- {
- READSHM(conf->SID, arlan->SID, u_int);
- }
- else conf->SID = SID;
-
- if (registrationMode == registrationModeUNKNOWN)
- {
- READSHM(conf->registrationMode, arlan->registrationMode, u_char);
- }
- else conf->registrationMode = registrationMode;
-
- READSHM(conf->registrationFill, arlan->registrationFill, u_char);
- READSHM(conf->localTalkAddress, arlan->localTalkAddress, u_char);
- READSHM(conf->codeFormat, arlan->codeFormat, u_char);
- READSHM(conf->numChannels, arlan->numChannels, u_char);
- READSHM(conf->channel1, arlan->channel1, u_char);
- READSHM(conf->channel2, arlan->channel2, u_char);
- READSHM(conf->channel3, arlan->channel3, u_char);
- READSHM(conf->channel4, arlan->channel4, u_char);
- READSHM(conf->waitTime, arlan->waitTime, u_short);
- READSHM(conf->lParameter, arlan->lParameter, u_short);
- READSHM(conf->_15, arlan->_15, u_short);
- READSHM(conf->headerSize, arlan->headerSize, u_short);
- READSHM(conf->hardwareType, arlan->hardwareType, u_char);
- READSHM(conf->radioType, arlan->radioModule, u_char);
-
- if (conf->radioType == 0)
- conf->radioType = 0xc;
- WRITESHM(arlan->configStatus, 0xA5, u_char);
- READSHM(tlx415, arlan->configStatus, u_char);
-
- if (tlx415 != 0xA5)
- printk(KERN_INFO "%s tlx415 chip n", dev->name);
-
- conf->txClear = 0;
- conf->txRetries = 1;
- conf->txRouting = 1;
- conf->txScrambled = 0;
- conf->rxParameter = 1;
- conf->txTimeoutMs = 4000;
- conf->waitCardTimeout = 100000;
- conf->receiveMode = ARLAN_RCV_CLEAN;
- memcpy_fromio(conf->siteName, arlan->name, 16);
- conf->siteName[16] = ' ';
- conf->retries = retries;
- conf->tx_delay_ms = tx_delay_ms;
- conf->async = async;
- conf->ReTransmitPacketMaxSize = 200;
- conf->waitReTransmitPacketMaxSize = 200;
- conf->txAckTimeoutMs = 900;
- conf->fastReTransCount = 3;
- ARLAN_DEBUG_EXIT("arlan_read_card_configuration");
- return 0;
- }
- static int lastFoundAt = 0xbe000;
- /*
- * This is the real probe routine. Linux has a history of friendly device
- * probes on the ISA bus. A good device probes avoids doing writes, and
- * verifies that the correct device exists and functions.
- */
- static int __init arlan_check_fingerprint(int memaddr)
- {
- static char probeText[] = "TELESYSTEM SLW INC. ARLAN