aboutsummaryrefslogtreecommitdiff
path: root/drivers/net/wireless/netwave_cs.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/wireless/netwave_cs.c')
-rw-r--r--drivers/net/wireless/netwave_cs.c1736
1 files changed, 1736 insertions, 0 deletions
diff --git a/drivers/net/wireless/netwave_cs.c b/drivers/net/wireless/netwave_cs.c
new file mode 100644
index 00000000000..382241e7edb
--- /dev/null
+++ b/drivers/net/wireless/netwave_cs.c
@@ -0,0 +1,1736 @@
+/*********************************************************************
+ *
+ * Filename: netwave_cs.c
+ * Version: 0.4.1
+ * Description: Netwave AirSurfer Wireless LAN PC Card driver
+ * Status: Experimental.
+ * Authors: John Markus Bjørndalen <johnm@cs.uit.no>
+ * Dag Brattli <dagb@cs.uit.no>
+ * David Hinds <dahinds@users.sourceforge.net>
+ * Created at: A long time ago!
+ * Modified at: Mon Nov 10 11:54:37 1997
+ * Modified by: Dag Brattli <dagb@cs.uit.no>
+ *
+ * Copyright (c) 1997 University of Tromsø, Norway
+ *
+ * Revision History:
+ *
+ * 08-Nov-97 15:14:47 John Markus Bjørndalen <johnm@cs.uit.no>
+ * - Fixed some bugs in netwave_rx and cleaned it up a bit.
+ * (One of the bugs would have destroyed packets when receiving
+ * multiple packets per interrupt).
+ * - Cleaned up parts of newave_hw_xmit.
+ * - A few general cleanups.
+ * 24-Oct-97 13:17:36 Dag Brattli <dagb@cs.uit.no>
+ * - Fixed netwave_rx receive function (got updated docs)
+ * Others:
+ * - Changed name from xircnw to netwave, take a look at
+ * http://www.netwave-wireless.com
+ * - Some reorganizing of the code
+ * - Removed possible race condition between interrupt handler and transmit
+ * function
+ * - Started to add wireless extensions, but still needs some coding
+ * - Added watchdog for better handling of transmission timeouts
+ * (hopefully this works better)
+ ********************************************************************/
+
+/* To have statistics (just packets sent) define this */
+#undef NETWAVE_STATS
+
+#include <linux/config.h>
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/types.h>
+#include <linux/fcntl.h>
+#include <linux/interrupt.h>
+#include <linux/ptrace.h>
+#include <linux/ioport.h>
+#include <linux/in.h>
+#include <linux/slab.h>
+#include <linux/string.h>
+#include <linux/timer.h>
+#include <linux/errno.h>
+#include <linux/netdevice.h>
+#include <linux/etherdevice.h>
+#include <linux/skbuff.h>
+#include <linux/bitops.h>
+#ifdef CONFIG_NET_RADIO
+#include <linux/wireless.h>
+#if WIRELESS_EXT > 12
+#include <net/iw_handler.h>
+#endif /* WIRELESS_EXT > 12 */
+#endif
+
+#include <pcmcia/version.h>
+#include <pcmcia/cs_types.h>
+#include <pcmcia/cs.h>
+#include <pcmcia/cistpl.h>
+#include <pcmcia/cisreg.h>
+#include <pcmcia/ds.h>
+#include <pcmcia/mem_op.h>
+
+#include <asm/system.h>
+#include <asm/io.h>
+#include <asm/dma.h>
+
+#define NETWAVE_REGOFF 0x8000
+/* The Netwave IO registers, offsets to iobase */
+#define NETWAVE_REG_COR 0x0
+#define NETWAVE_REG_CCSR 0x2
+#define NETWAVE_REG_ASR 0x4
+#define NETWAVE_REG_IMR 0xa
+#define NETWAVE_REG_PMR 0xc
+#define NETWAVE_REG_IOLOW 0x6
+#define NETWAVE_REG_IOHI 0x7
+#define NETWAVE_REG_IOCONTROL 0x8
+#define NETWAVE_REG_DATA 0xf
+/* The Netwave Extended IO registers, offsets to RamBase */
+#define NETWAVE_EREG_ASCC 0x114
+#define NETWAVE_EREG_RSER 0x120
+#define NETWAVE_EREG_RSERW 0x124
+#define NETWAVE_EREG_TSER 0x130
+#define NETWAVE_EREG_TSERW 0x134
+#define NETWAVE_EREG_CB 0x100
+#define NETWAVE_EREG_SPCQ 0x154
+#define NETWAVE_EREG_SPU 0x155
+#define NETWAVE_EREG_LIF 0x14e
+#define NETWAVE_EREG_ISPLQ 0x156
+#define NETWAVE_EREG_HHC 0x158
+#define NETWAVE_EREG_NI 0x16e
+#define NETWAVE_EREG_MHS 0x16b
+#define NETWAVE_EREG_TDP 0x140
+#define NETWAVE_EREG_RDP 0x150
+#define NETWAVE_EREG_PA 0x160
+#define NETWAVE_EREG_EC 0x180
+#define NETWAVE_EREG_CRBP 0x17a
+#define NETWAVE_EREG_ARW 0x166
+
+/*
+ * Commands used in the extended command buffer
+ * NETWAVE_EREG_CB (0x100-0x10F)
+ */
+#define NETWAVE_CMD_NOP 0x00
+#define NETWAVE_CMD_SRC 0x01
+#define NETWAVE_CMD_STC 0x02
+#define NETWAVE_CMD_AMA 0x03
+#define NETWAVE_CMD_DMA 0x04
+#define NETWAVE_CMD_SAMA 0x05
+#define NETWAVE_CMD_ER 0x06
+#define NETWAVE_CMD_DR 0x07
+#define NETWAVE_CMD_TL 0x08
+#define NETWAVE_CMD_SRP 0x09
+#define NETWAVE_CMD_SSK 0x0a
+#define NETWAVE_CMD_SMD 0x0b
+#define NETWAVE_CMD_SAPD 0x0c
+#define NETWAVE_CMD_SSS 0x11
+/* End of Command marker */
+#define NETWAVE_CMD_EOC 0x00
+
+/* ASR register bits */
+#define NETWAVE_ASR_RXRDY 0x80
+#define NETWAVE_ASR_TXBA 0x01
+
+#define TX_TIMEOUT ((32*HZ)/100)
+
+static const unsigned int imrConfRFU1 = 0x10; /* RFU interrupt mask, keep high */
+static const unsigned int imrConfIENA = 0x02; /* Interrupt enable */
+
+static const unsigned int corConfIENA = 0x01; /* Interrupt enable */
+static const unsigned int corConfLVLREQ = 0x40; /* Keep high */
+
+static const unsigned int rxConfRxEna = 0x80; /* Receive Enable */
+static const unsigned int rxConfMAC = 0x20; /* MAC host receive mode*/
+static const unsigned int rxConfPro = 0x10; /* Promiscuous */
+static const unsigned int rxConfAMP = 0x08; /* Accept Multicast Packets */
+static const unsigned int rxConfBcast = 0x04; /* Accept Broadcast Packets */
+
+static const unsigned int txConfTxEna = 0x80; /* Transmit Enable */
+static const unsigned int txConfMAC = 0x20; /* Host sends MAC mode */
+static const unsigned int txConfEUD = 0x10; /* Enable Uni-Data packets */
+static const unsigned int txConfKey = 0x02; /* Scramble data packets */
+static const unsigned int txConfLoop = 0x01; /* Loopback mode */
+
+/*
+ All the PCMCIA modules use PCMCIA_DEBUG to control debugging. If
+ you do not define PCMCIA_DEBUG at all, all the debug code will be
+ left out. If you compile with PCMCIA_DEBUG=0, the debug code will
+ be present but disabled -- but it can then be enabled for specific
+ modules at load time with a 'pc_debug=#' option to insmod.
+*/
+
+#ifdef PCMCIA_DEBUG
+static int pc_debug = PCMCIA_DEBUG;
+module_param(pc_debug, int, 0);
+#define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args)
+static char *version =
+"netwave_cs.c 0.3.0 Thu Jul 17 14:36:02 1997 (John Markus Bjørndalen)\n";
+#else
+#define DEBUG(n, args...)
+#endif
+
+static dev_info_t dev_info = "netwave_cs";
+
+/*====================================================================*/
+
+/* Parameters that can be set with 'insmod' */
+
+/* Choose the domain, default is 0x100 */
+static u_int domain = 0x100;
+
+/* Scramble key, range from 0x0 to 0xffff.
+ * 0x0 is no scrambling.
+ */
+static u_int scramble_key = 0x0;
+
+/* Shared memory speed, in ns. The documentation states that
+ * the card should not be read faster than every 400ns.
+ * This timing should be provided by the HBA. If it becomes a
+ * problem, try setting mem_speed to 400.
+ */
+static int mem_speed;
+
+module_param(domain, int, 0);
+module_param(scramble_key, int, 0);
+module_param(mem_speed, int, 0);
+
+/*====================================================================*/
+
+/* PCMCIA (Card Services) related functions */
+static void netwave_release(dev_link_t *link); /* Card removal */
+static int netwave_event(event_t event, int priority,
+ event_callback_args_t *args);
+static void netwave_pcmcia_config(dev_link_t *arg); /* Runs after card
+ insertion */
+static dev_link_t *netwave_attach(void); /* Create instance */
+static void netwave_detach(dev_link_t *); /* Destroy instance */
+
+/* Hardware configuration */
+static void netwave_doreset(kio_addr_t iobase, u_char __iomem *ramBase);
+static void netwave_reset(struct net_device *dev);
+
+/* Misc device stuff */
+static int netwave_open(struct net_device *dev); /* Open the device */
+static int netwave_close(struct net_device *dev); /* Close the device */
+
+/* Packet transmission and Packet reception */
+static int netwave_start_xmit( struct sk_buff *skb, struct net_device *dev);
+static int netwave_rx( struct net_device *dev);
+
+/* Interrupt routines */
+static irqreturn_t netwave_interrupt(int irq, void *dev_id, struct pt_regs *regs);
+static void netwave_watchdog(struct net_device *);
+
+/* Statistics */
+static void update_stats(struct net_device *dev);
+static struct net_device_stats *netwave_get_stats(struct net_device *dev);
+
+/* Wireless extensions */
+#ifdef WIRELESS_EXT
+static struct iw_statistics* netwave_get_wireless_stats(struct net_device *dev);
+#endif
+static int netwave_ioctl(struct net_device *, struct ifreq *, int);
+
+static void set_multicast_list(struct net_device *dev);
+
+/*
+ A linked list of "instances" of the skeleton device. Each actual
+ PCMCIA card corresponds to one device instance, and is described
+ by one dev_link_t structure (defined in ds.h).
+
+ You may not want to use a linked list for this -- for example, the
+ memory card driver uses an array of dev_link_t pointers, where minor
+ device numbers are used to derive the corresponding array index.
+*/
+static dev_link_t *dev_list;
+
+/*
+ A dev_link_t structure has fields for most things that are needed
+ to keep track of a socket, but there will usually be some device
+ specific information that also needs to be kept track of. The
+ 'priv' pointer in a dev_link_t structure can be used to point to
+ a device-specific private data structure, like this.
+
+ A driver needs to provide a dev_node_t structure for each device
+ on a card. In some cases, there is only one device per card (for
+ example, ethernet cards, modems). In other cases, there may be
+ many actual or logical devices (SCSI adapters, memory cards with
+ multiple partitions). The dev_node_t structures need to be kept
+ in a linked list starting at the 'dev' field of a dev_link_t
+ structure. We allocate them in the card's private data structure,
+ because they generally can't be allocated dynamically.
+*/
+
+#if WIRELESS_EXT <= 12
+/* Wireless extensions backward compatibility */
+
+/* Part of iw_handler prototype we need */
+struct iw_request_info
+{
+ __u16 cmd; /* Wireless Extension command */
+ __u16 flags; /* More to come ;-) */
+};
+
+/* Wireless Extension Backward compatibility - Jean II
+ * If the new wireless device private ioctl range is not defined,
+ * default to standard device private ioctl range */
+#ifndef SIOCIWFIRSTPRIV
+#define SIOCIWFIRSTPRIV SIOCDEVPRIVATE
+#endif /* SIOCIWFIRSTPRIV */
+
+#else /* WIRELESS_EXT <= 12 */
+static const struct iw_handler_def netwave_handler_def;
+#endif /* WIRELESS_EXT <= 12 */
+
+#define SIOCGIPSNAP SIOCIWFIRSTPRIV + 1 /* Site Survey Snapshot */
+
+#define MAX_ESA 10
+
+typedef struct net_addr {
+ u_char addr48[6];
+} net_addr;
+
+struct site_survey {
+ u_short length;
+ u_char struct_revision;
+ u_char roaming_state;
+
+ u_char sp_existsFlag;
+ u_char sp_link_quality;
+ u_char sp_max_link_quality;
+ u_char linkQualityGoodFairBoundary;
+ u_char linkQualityFairPoorBoundary;
+ u_char sp_utilization;
+ u_char sp_goodness;
+ u_char sp_hotheadcount;
+ u_char roaming_condition;
+
+ net_addr sp;
+ u_char numAPs;
+ net_addr nearByAccessPoints[MAX_ESA];
+};
+
+typedef struct netwave_private {
+ dev_link_t link;
+ spinlock_t spinlock; /* Serialize access to the hardware (SMP) */
+ dev_node_t node;
+ u_char __iomem *ramBase;
+ int timeoutCounter;
+ int lastExec;
+ struct timer_list watchdog; /* To avoid blocking state */
+ struct site_survey nss;
+ struct net_device_stats stats;
+#ifdef WIRELESS_EXT
+ struct iw_statistics iw_stats; /* Wireless stats */
+#endif
+} netwave_private;
+
+#ifdef NETWAVE_STATS
+static struct net_device_stats *netwave_get_stats(struct net_device *dev);
+#endif
+
+/*
+ * The Netwave card is little-endian, so won't work for big endian
+ * systems.
+ */
+static inline unsigned short get_uint16(u_char __iomem *staddr)
+{
+ return readw(staddr); /* Return only 16 bits */
+}
+
+static inline short get_int16(u_char __iomem * staddr)
+{
+ return readw(staddr);
+}
+
+/*
+ * Wait until the WOC (Write Operation Complete) bit in the
+ * ASR (Adapter Status Register) is asserted.
+ * This should have aborted if it takes too long time.
+ */
+static inline void wait_WOC(unsigned int iobase)
+{
+ /* Spin lock */
+ while ((inb(iobase + NETWAVE_REG_ASR) & 0x8) != 0x8) ;
+}
+
+#ifdef WIRELESS_EXT
+static void netwave_snapshot(netwave_private *priv, u_char __iomem *ramBase,
+ kio_addr_t iobase) {
+ u_short resultBuffer;
+
+ /* if time since last snapshot is > 1 sec. (100 jiffies?) then take
+ * new snapshot, else return cached data. This is the recommended rate.
+ */
+ if ( jiffies - priv->lastExec > 100) {
+ /* Take site survey snapshot */
+ /*printk( KERN_DEBUG "Taking new snapshot. %ld\n", jiffies -
+ priv->lastExec); */
+ wait_WOC(iobase);
+ writeb(NETWAVE_CMD_SSS, ramBase + NETWAVE_EREG_CB + 0);
+ writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 1);
+ wait_WOC(iobase);
+
+ /* Get result and copy to cach */
+ resultBuffer = readw(ramBase + NETWAVE_EREG_CRBP);
+ copy_from_pc( &priv->nss, ramBase+resultBuffer,
+ sizeof(struct site_survey));
+ }
+}
+#endif
+
+#ifdef WIRELESS_EXT
+/*
+ * Function netwave_get_wireless_stats (dev)
+ *
+ * Wireless extensions statistics
+ *
+ */
+static struct iw_statistics *netwave_get_wireless_stats(struct net_device *dev)
+{
+ unsigned long flags;
+ kio_addr_t iobase = dev->base_addr;
+ netwave_private *priv = netdev_priv(dev);
+ u_char __iomem *ramBase = priv->ramBase;
+ struct iw_statistics* wstats;
+
+ wstats = &priv->iw_stats;
+
+ spin_lock_irqsave(&priv->spinlock, flags);
+
+ netwave_snapshot( priv, ramBase, iobase);
+
+ wstats->status = priv->nss.roaming_state;
+ wstats->qual.qual = readb( ramBase + NETWAVE_EREG_SPCQ);
+ wstats->qual.level = readb( ramBase + NETWAVE_EREG_ISPLQ);
+ wstats->qual.noise = readb( ramBase + NETWAVE_EREG_SPU) & 0x3f;
+ wstats->discard.nwid = 0L;
+ wstats->discard.code = 0L;
+ wstats->discard.misc = 0L;
+
+ spin_unlock_irqrestore(&priv->spinlock, flags);
+
+ return &priv->iw_stats;
+}
+#endif
+
+/*
+ * Function netwave_attach (void)
+ *
+ * Creates an "instance" of the driver, allocating local data
+ * structures for one device. The device is registered with Card
+ * Services.
+ *
+ * The dev_link structure is initialized, but we don't actually
+ * configure the card at this point -- we wait until we receive a
+ * card insertion event.
+ */
+static dev_link_t *netwave_attach(void)
+{
+ client_reg_t client_reg;
+ dev_link_t *link;
+ struct net_device *dev;
+ netwave_private *priv;
+ int ret;
+
+ DEBUG(0, "netwave_attach()\n");
+
+ /* Initialize the dev_link_t structure */
+ dev = alloc_etherdev(sizeof(netwave_private));
+ if (!dev)
+ return NULL;
+ priv = netdev_priv(dev);
+ link = &priv->link;
+ link->priv = dev;
+
+ /* The io structure describes IO port mapping */
+ link->io.NumPorts1 = 16;
+ link->io.Attributes1 = IO_DATA_PATH_WIDTH_16;
+ /* link->io.NumPorts2 = 16;
+ link->io.Attributes2 = IO_DATA_PATH_WIDTH_16; */
+ link->io.IOAddrLines = 5;
+
+ /* Interrupt setup */
+ link->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT;
+ link->irq.IRQInfo1 = IRQ_LEVEL_ID;
+ link->irq.Handler = &netwave_interrupt;
+
+ /* General socket configuration */
+ link->conf.Attributes = CONF_ENABLE_IRQ;
+ link->conf.Vcc = 50;
+ link->conf.IntType = INT_MEMORY_AND_IO;
+ link->conf.ConfigIndex = 1;
+ link->conf.Present = PRESENT_OPTION;
+
+ /* Netwave private struct init. link/dev/node already taken care of,
+ * other stuff zero'd - Jean II */
+ spin_lock_init(&priv->spinlock);
+
+ /* Netwave specific entries in the device structure */
+ SET_MODULE_OWNER(dev);
+ dev->hard_start_xmit = &netwave_start_xmit;
+ dev->get_stats = &netwave_get_stats;
+ dev->set_multicast_list = &set_multicast_list;
+ /* wireless extensions */
+#ifdef WIRELESS_EXT
+ dev->get_wireless_stats = &netwave_get_wireless_stats;
+#if WIRELESS_EXT > 12
+ dev->wireless_handlers = (struct iw_handler_def *)&netwave_handler_def;
+#endif /* WIRELESS_EXT > 12 */
+#endif /* WIRELESS_EXT */
+ dev->do_ioctl = &netwave_ioctl;
+
+ dev->tx_timeout = &netwave_watchdog;
+ dev->watchdog_timeo = TX_TIMEOUT;
+
+ dev->open = &netwave_open;
+ dev->stop = &netwave_close;
+ link->irq.Instance = dev;
+
+ /* Register with Card Services */
+ link->next = dev_list;
+ dev_list = link;
+ client_reg.dev_info = &dev_info;
+ client_reg.EventMask =
+ CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL |
+ CS_EVENT_RESET_PHYSICAL | CS_EVENT_CARD_RESET |
+ CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME;
+ client_reg.event_handler = &netwave_event;
+ client_reg.Version = 0x0210;
+ client_reg.event_callback_args.client_data = link;
+ ret = pcmcia_register_client(&link->handle, &client_reg);
+ if (ret != 0) {
+ cs_error(link->handle, RegisterClient, ret);
+ netwave_detach(link);
+ return NULL;
+ }
+
+ return link;
+} /* netwave_attach */
+
+/*
+ * Function netwave_detach (link)
+ *
+ * This deletes a driver "instance". The device is de-registered
+ * with Card Services. If it has been released, all local data
+ * structures are freed. Otherwise, the structures will be freed
+ * when the device is released.
+ */
+static void netwave_detach(dev_link_t *link)
+{
+ struct net_device *dev = link->priv;
+ dev_link_t **linkp;
+
+ DEBUG(0, "netwave_detach(0x%p)\n", link);
+
+ /*
+ If the device is currently configured and active, we won't
+ actually delete it yet. Instead, it is marked so that when
+ the release() function is called, that will trigger a proper
+ detach().
+ */
+ if (link->state & DEV_CONFIG)
+ netwave_release(link);
+
+ /* Break the link with Card Services */
+ if (link->handle)
+ pcmcia_deregister_client(link->handle);
+
+ /* Locate device structure */
+ for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next)
+ if (*linkp == link) break;
+ if (*linkp == NULL)
+ {
+ DEBUG(1, "netwave_cs: detach fail, '%s' not in list\n",
+ link->dev->dev_name);
+ return;
+ }
+
+ /* Unlink device structure, free pieces */
+ *linkp = link->next;
+ if (link->dev)
+ unregister_netdev(dev);
+ free_netdev(dev);
+
+} /* netwave_detach */
+
+/*
+ * Wireless Handler : get protocol name
+ */
+static int netwave_get_name(struct net_device *dev,
+ struct iw_request_info *info,
+ union iwreq_data *wrqu,
+ char *extra)
+{
+ strcpy(wrqu->name, "Netwave");
+ return 0;
+}
+
+/*
+ * Wireless Handler : set Network ID
+ */
+static int netwave_set_nwid(struct net_device *dev,
+ struct iw_request_info *info,
+ union iwreq_data *wrqu,
+ char *extra)
+{
+ unsigned long flags;
+ kio_addr_t iobase = dev->base_addr;
+ netwave_private *priv = netdev_priv(dev);
+ u_char __iomem *ramBase = priv->ramBase;
+
+ /* Disable interrupts & save flags */
+ spin_lock_irqsave(&priv->spinlock, flags);
+
+#if WIRELESS_EXT > 8
+ if(!wrqu->nwid.disabled) {
+ domain = wrqu->nwid.value;
+#else /* WIRELESS_EXT > 8 */
+ if(wrqu->nwid.on) {
+ domain = wrqu->nwid.nwid;
+#endif /* WIRELESS_EXT > 8 */
+ printk( KERN_DEBUG "Setting domain to 0x%x%02x\n",
+ (domain >> 8) & 0x01, domain & 0xff);
+ wait_WOC(iobase);
+ writeb(NETWAVE_CMD_SMD, ramBase + NETWAVE_EREG_CB + 0);
+ writeb( domain & 0xff, ramBase + NETWAVE_EREG_CB + 1);
+ writeb((domain >>8 ) & 0x01,ramBase + NETWAVE_EREG_CB+2);
+ writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 3);
+ }
+
+ /* ReEnable interrupts & restore flags */
+ spin_unlock_irqrestore(&priv->spinlock, flags);
+
+ return 0;
+}
+
+/*
+ * Wireless Handler : get Network ID
+ */
+static int netwave_get_nwid(struct net_device *dev,
+ struct iw_request_info *info,
+ union iwreq_data *wrqu,
+ char *extra)
+{
+#if WIRELESS_EXT > 8
+ wrqu->nwid.value = domain;
+ wrqu->nwid.disabled = 0;
+ wrqu->nwid.fixed = 1;
+#else /* WIRELESS_EXT > 8 */
+ wrqu->nwid.nwid = domain;
+ wrqu->nwid.on = 1;
+#endif /* WIRELESS_EXT > 8 */
+
+ return 0;
+}
+
+/*
+ * Wireless Handler : set scramble key
+ */
+static int netwave_set_scramble(struct net_device *dev,
+ struct iw_request_info *info,
+ union iwreq_data *wrqu,
+ char *key)
+{
+ unsigned long flags;
+ kio_addr_t iobase = dev->base_addr;
+ netwave_private *priv = netdev_priv(dev);
+ u_char __iomem *ramBase = priv->ramBase;
+
+ /* Disable interrupts & save flags */
+ spin_lock_irqsave(&priv->spinlock, flags);
+
+ scramble_key = (key[0] << 8) | key[1];
+ wait_WOC(iobase);
+ writeb(NETWAVE_CMD_SSK, ramBase + NETWAVE_EREG_CB + 0);
+ writeb(scramble_key & 0xff, ramBase + NETWAVE_EREG_CB + 1);
+ writeb((scramble_key>>8) & 0xff, ramBase + NETWAVE_EREG_CB + 2);
+ writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 3);
+
+ /* ReEnable interrupts & restore flags */
+ spin_unlock_irqrestore(&priv->spinlock, flags);
+
+ return 0;
+}
+
+/*
+ * Wireless Handler : get scramble key
+ */
+static int netwave_get_scramble(struct net_device *dev,
+ struct iw_request_info *info,
+ union iwreq_data *wrqu,
+ char *key)
+{
+ key[1] = scramble_key & 0xff;
+ key[0] = (scramble_key>>8) & 0xff;
+#if WIRELESS_EXT > 8
+ wrqu->encoding.flags = IW_ENCODE_ENABLED;
+ wrqu->encoding.length = 2;
+#else /* WIRELESS_EXT > 8 */
+ wrqu->encoding.method = 1;
+#endif /* WIRELESS_EXT > 8 */
+
+ return 0;
+}
+
+#if WIRELESS_EXT > 8
+/*
+ * Wireless Handler : get mode
+ */
+static int netwave_get_mode(struct net_device *dev,
+ struct iw_request_info *info,
+ union iwreq_data *wrqu,
+ char *extra)
+{
+ if(domain & 0x100)
+ wrqu->mode = IW_MODE_INFRA;
+ else
+ wrqu->mode = IW_MODE_ADHOC;
+
+ return 0;
+}
+#endif /* WIRELESS_EXT > 8 */
+
+/*
+ * Wireless Handler : get range info
+ */
+static int netwave_get_range(struct net_device *dev,
+ struct iw_request_info *info,
+ union iwreq_data *wrqu,
+ char *extra)
+{
+ struct iw_range *range = (struct iw_range *) extra;
+ int ret = 0;
+
+ /* Set the length (very important for backward compatibility) */
+ wrqu->data.length = sizeof(struct iw_range);
+
+ /* Set all the info we don't care or don't know about to zero */
+ memset(range, 0, sizeof(struct iw_range));
+
+#if WIRELESS_EXT > 10
+ /* Set the Wireless Extension versions */
+ range->we_version_compiled = WIRELESS_EXT;
+ range->we_version_source = 9; /* Nothing for us in v10 and v11 */
+#endif /* WIRELESS_EXT > 10 */
+
+ /* Set information in the range struct */
+ range->throughput = 450 * 1000; /* don't argue on this ! */
+ range->min_nwid = 0x0000;
+ range->max_nwid = 0x01FF;
+
+ range->num_channels = range->num_frequency = 0;
+
+ range->sensitivity = 0x3F;
+ range->max_qual.qual = 255;
+ range->max_qual.level = 255;
+ range->max_qual.noise = 0;
+
+#if WIRELESS_EXT > 7
+ range->num_bitrates = 1;
+ range->bitrate[0] = 1000000; /* 1 Mb/s */
+#endif /* WIRELESS_EXT > 7 */
+
+#if WIRELESS_EXT > 8
+ range->encoding_size[0] = 2; /* 16 bits scrambling */
+ range->num_encoding_sizes = 1;
+ range->max_encoding_tokens = 1; /* Only one key possible */
+#endif /* WIRELESS_EXT > 8 */
+
+ return ret;
+}
+
+/*
+ * Wireless Private Handler : get snapshot
+ */
+static int netwave_get_snap(struct net_device *dev,
+ struct iw_request_info *info,
+ union iwreq_data *wrqu,
+ char *extra)
+{
+ unsigned long flags;
+ kio_addr_t iobase = dev->base_addr;
+ netwave_private *priv = netdev_priv(dev);
+ u_char __iomem *ramBase = priv->ramBase;
+
+ /* Disable interrupts & save flags */
+ spin_lock_irqsave(&priv->spinlock, flags);
+
+ /* Take snapshot of environment */
+ netwave_snapshot( priv, ramBase, iobase);
+ wrqu->data.length = priv->nss.length;
+ memcpy(extra, (u_char *) &priv->nss, sizeof( struct site_survey));
+
+ priv->lastExec = jiffies;
+
+ /* ReEnable interrupts & restore flags */
+ spin_unlock_irqrestore(&priv->spinlock, flags);
+
+ return(0);
+}
+
+/*
+ * Structures to export the Wireless Handlers
+ * This is the stuff that are treated the wireless extensions (iwconfig)
+ */
+
+static const struct iw_priv_args netwave_private_args[] = {
+/*{ cmd, set_args, get_args, name } */
+ { SIOCGIPSNAP, 0,
+ IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | sizeof(struct site_survey),
+ "getsitesurvey" },
+};
+
+#if WIRELESS_EXT > 12
+
+static const iw_handler netwave_handler[] =
+{
+ NULL, /* SIOCSIWNAME */
+ netwave_get_name, /* SIOCGIWNAME */
+ netwave_set_nwid, /* SIOCSIWNWID */
+ netwave_get_nwid, /* SIOCGIWNWID */
+ NULL, /* SIOCSIWFREQ */
+ NULL, /* SIOCGIWFREQ */
+ NULL, /* SIOCSIWMODE */
+ netwave_get_mode, /* SIOCGIWMODE */
+ NULL, /* SIOCSIWSENS */
+ NULL, /* SIOCGIWSENS */
+ NULL, /* SIOCSIWRANGE */
+ netwave_get_range, /* SIOCGIWRANGE */
+ NULL, /* SIOCSIWPRIV */
+ NULL, /* SIOCGIWPRIV */
+ NULL, /* SIOCSIWSTATS */
+ NULL, /* SIOCGIWSTATS */
+ NULL, /* SIOCSIWSPY */
+ NULL, /* SIOCGIWSPY */
+ NULL, /* -- hole -- */
+ NULL, /* -- hole -- */
+ NULL, /* SIOCSIWAP */
+ NULL, /* SIOCGIWAP */
+ NULL, /* -- hole -- */
+ NULL, /* SIOCGIWAPLIST */
+ NULL, /* -- hole -- */
+ NULL, /* -- hole -- */
+ NULL, /* SIOCSIWESSID */
+ NULL, /* SIOCGIWESSID */
+ NULL, /* SIOCSIWNICKN */
+ NULL, /* SIOCGIWNICKN */
+ NULL, /* -- hole -- */
+ NULL, /* -- hole -- */
+ NULL, /* SIOCSIWRATE */
+ NULL, /* SIOCGIWRATE */
+ NULL, /* SIOCSIWRTS */
+ NULL, /* SIOCGIWRTS */
+ NULL, /* SIOCSIWFRAG */
+ NULL, /* SIOCGIWFRAG */
+ NULL, /* SIOCSIWTXPOW */
+ NULL, /* SIOCGIWTXPOW */
+ NULL, /* SIOCSIWRETRY */
+ NULL, /* SIOCGIWRETRY */
+ netwave_set_scramble, /* SIOCSIWENCODE */
+ netwave_get_scramble, /* SIOCGIWENCODE */
+};
+
+static const iw_handler netwave_private_handler[] =
+{
+ NULL, /* SIOCIWFIRSTPRIV */
+ netwave_get_snap, /* SIOCIWFIRSTPRIV + 1 */
+};
+
+static const struct iw_handler_def netwave_handler_def =
+{
+ .num_standard = sizeof(netwave_handler)/sizeof(iw_handler),
+ .num_private = sizeof(netwave_private_handler)/sizeof(iw_handler),
+ .num_private_args = sizeof(netwave_private_args)/sizeof(struct iw_priv_args),
+ .standard = (iw_handler *) netwave_handler,
+ .private = (iw_handler *) netwave_private_handler,
+ .private_args = (struct iw_priv_args *) netwave_private_args,
+};
+#endif /* WIRELESS_EXT > 12 */
+
+/*
+ * Function netwave_ioctl (dev, rq, cmd)
+ *
+ * Perform ioctl : config & info stuff
+ * This is the stuff that are treated the wireless extensions (iwconfig)
+ *
+ */
+static int netwave_ioctl(struct net_device *dev, /* ioctl device */
+ struct ifreq *rq, /* Data passed */
+ int cmd) /* Ioctl number */
+{
+ int ret = 0;
+#ifdef WIRELESS_EXT
+#if WIRELESS_EXT <= 12
+ struct iwreq *wrq = (struct iwreq *) rq;
+#endif
+#endif
+
+ DEBUG(0, "%s: ->netwave_ioctl(cmd=0x%X)\n", dev->name, cmd);
+
+ /* Look what is the request */
+ switch(cmd) {
+ /* --------------- WIRELESS EXTENSIONS --------------- */
+#ifdef WIRELESS_EXT
+#if WIRELESS_EXT <= 12
+ case SIOCGIWNAME:
+ netwave_get_name(dev, NULL, &(wrq->u), NULL);
+ break;
+ case SIOCSIWNWID:
+ ret = netwave_set_nwid(dev, NULL, &(wrq->u), NULL);
+ break;
+ case SIOCGIWNWID:
+ ret = netwave_get_nwid(dev, NULL, &(wrq->u), NULL);
+ break;
+#if WIRELESS_EXT > 8 /* Note : The API did change... */
+ case SIOCGIWENCODE:
+ /* Get scramble key */
+ if(wrq->u.encoding.pointer != (caddr_t) 0)
+ {
+ char key[2];
+ ret = netwave_get_scramble(dev, NULL, &(wrq->u), key);
+ if(copy_to_user(wrq->u.encoding.pointer, key, 2))
+ ret = -EFAULT;
+ }
+ break;
+ case SIOCSIWENCODE:
+ /* Set scramble key */
+ if(wrq->u.encoding.pointer != (caddr_t) 0)
+ {
+ char key[2];
+ if(copy_from_user(key, wrq->u.encoding.pointer, 2))
+ {
+ ret = -EFAULT;
+ break;
+ }
+ ret = netwave_set_scramble(dev, NULL, &(wrq->u), key);
+ }
+ break;
+ case SIOCGIWMODE:
+ /* Mode of operation */
+ ret = netwave_get_mode(dev, NULL, &(wrq->u), NULL);
+ break;
+#else /* WIRELESS_EXT > 8 */
+ case SIOCGIWENCODE:
+ /* Get scramble key */
+ ret = netwave_get_scramble(dev, NULL, &(wrq->u),
+ (char *) &wrq->u.encoding.code);
+ break;
+ case SIOCSIWENCODE:
+ /* Set scramble key */
+ ret = netwave_set_scramble(dev, NULL, &(wrq->u),
+ (char *) &wrq->u.encoding.code);
+ break;
+#endif /* WIRELESS_EXT > 8 */
+ case SIOCGIWRANGE:
+ /* Basic checking... */
+ if(wrq->u.data.pointer != (caddr_t) 0) {
+ struct iw_range range;
+ ret = netwave_get_range(dev, NULL, &(wrq->u), (char *) &range);
+ if (copy_to_user(wrq->u.data.pointer, &range,
+ sizeof(struct iw_range)))
+ ret = -EFAULT;
+ }
+ break;
+ case SIOCGIWPRIV:
+ /* Basic checking... */
+ if(wrq->u.data.pointer != (caddr_t) 0) {
+ /* Set the number of ioctl available */
+ wrq->u.data.length = sizeof(netwave_private_args) / sizeof(netwave_private_args[0]);
+
+ /* Copy structure to the user buffer */
+ if(copy_to_user(wrq->u.data.pointer,
+ (u_char *) netwave_private_args,
+ sizeof(netwave_private_args)))
+ ret = -EFAULT;
+ }
+ break;
+ case SIOCGIPSNAP:
+ if(wrq->u.data.pointer != (caddr_t) 0) {
+ char buffer[sizeof( struct site_survey)];
+ ret = netwave_get_snap(dev, NULL, &(wrq->u), buffer);
+ /* Copy structure to the user buffer */
+ if(copy_to_user(wrq->u.data.pointer,
+ buffer,
+ sizeof( struct site_survey)))
+ {
+ printk(KERN_DEBUG "Bad buffer!\n");
+ break;
+ }
+ }
+ break;
+#endif /* WIRELESS_EXT <= 12 */
+#endif /* WIRELESS_EXT */
+ default:
+ ret = -EOPNOTSUPP;
+ }
+
+ return ret;
+}
+
+/*
+ * Function netwave_pcmcia_config (link)
+ *
+ * netwave_pcmcia_config() is scheduled to run after a CARD_INSERTION
+ * event is received, to configure the PCMCIA socket, and to make the
+ * device available to the system.
+ *
+ */
+
+#define CS_CHECK(fn, ret) \
+do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
+
+static void netwave_pcmcia_config(dev_link_t *link) {
+ client_handle_t handle = link->handle;
+ struct net_device *dev = link->priv;
+ netwave_private *priv = netdev_priv(dev);
+ tuple_t tuple;
+ cisparse_t parse;
+ int i, j, last_ret, last_fn;
+ u_char buf[64];
+ win_req_t req;
+ memreq_t mem;
+ u_char __iomem *ramBase = NULL;
+
+ DEBUG(0, "netwave_pcmcia_config(0x%p)\n", link);
+
+ /*
+ This reads the card's CONFIG tuple to find its configuration
+ registers.
+ */
+ tuple.Attributes = 0;
+ tuple.TupleData = (cisdata_t *) buf;
+ tuple.TupleDataMax = 64;
+ tuple.TupleOffset = 0;
+ tuple.DesiredTuple = CISTPL_CONFIG;
+ CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple));
+ CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple));
+ CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse));
+ link->conf.ConfigBase = parse.config.base;
+ link->conf.Present = parse.config.rmask[0];
+
+ /* Configure card */
+ link->state |= DEV_CONFIG;
+
+ /*
+ * Try allocating IO ports. This tries a few fixed addresses.
+ * If you want, you can also read the card's config table to
+ * pick addresses -- see the serial driver for an example.
+ */
+ for (i = j = 0x0; j < 0x400; j += 0x20) {
+ link->io.BasePort1 = j ^ 0x300;
+ i = pcmcia_request_io(link->handle, &link->io);
+ if (i == CS_SUCCESS) break;
+ }
+ if (i != CS_SUCCESS) {
+ cs_error(link->handle, RequestIO, i);
+ goto failed;
+ }
+
+ /*
+ * Now allocate an interrupt line. Note that this does not
+ * actually assign a handler to the interrupt.
+ */
+ CS_CHECK(RequestIRQ, pcmcia_request_irq(handle, &link->irq));
+
+ /*
+ * This actually configures the PCMCIA socket -- setting up
+ * the I/O windows and the interrupt mapping.
+ */
+ CS_CHECK(RequestConfiguration, pcmcia_request_configuration(handle, &link->conf));
+
+ /*
+ * Allocate a 32K memory window. Note that the dev_link_t
+ * structure provides space for one window handle -- if your
+ * device needs several windows, you'll need to keep track of
+ * the handles in your private data structure, dev->priv.
+ */
+ DEBUG(1, "Setting mem speed of %d\n", mem_speed);
+
+ req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_CM|WIN_ENABLE;
+ req.Base = 0; req.Size = 0x8000;
+ req.AccessSpeed = mem_speed;
+ CS_CHECK(RequestWindow, pcmcia_request_window(&link->handle, &req, &link->win));
+ mem.CardOffset = 0x20000; mem.Page = 0;
+ CS_CHECK(MapMemPage, pcmcia_map_mem_page(link->win, &mem));
+
+ /* Store base address of the common window frame */
+ ramBase = ioremap(req.Base, 0x8000);
+ priv->ramBase = ramBase;
+
+ dev->irq = link->irq.AssignedIRQ;
+ dev->base_addr = link->io.BasePort1;
+ SET_NETDEV_DEV(dev, &handle_to_dev(handle));
+
+ if (register_netdev(dev) != 0) {
+ printk(KERN_DEBUG "netwave_cs: register_netdev() failed\n");
+ goto failed;
+ }
+
+ strcpy(priv->node.dev_name, dev->name);
+ link->dev = &priv->node;
+ link->state &= ~DEV_CONFIG_PENDING;
+
+ /* Reset card before reading physical address */
+ netwave_doreset(dev->base_addr, ramBase);
+
+ /* Read the ethernet address and fill in the Netwave registers. */
+ for (i = 0; i < 6; i++)
+ dev->dev_addr[i] = readb(ramBase + NETWAVE_EREG_PA + i);
+
+ printk(KERN_INFO "%s: Netwave: port %#3lx, irq %d, mem %lx id "
+ "%c%c, hw_addr ", dev->name, dev->base_addr, dev->irq,
+ (u_long) ramBase, (int) readb(ramBase+NETWAVE_EREG_NI),
+ (int) readb(ramBase+NETWAVE_EREG_NI+1));
+ for (i = 0; i < 6; i++)
+ printk("%02X%s", dev->dev_addr[i], ((i<5) ? ":" : "\n"));
+
+ /* get revision words */
+ printk(KERN_DEBUG "Netwave_reset: revision %04x %04x\n",
+ get_uint16(ramBase + NETWAVE_EREG_ARW),
+ get_uint16(ramBase + NETWAVE_EREG_ARW+2));
+ return;
+
+cs_failed:
+ cs_error(link->handle, last_fn