1 /*********************************************************************
3 * Filename: netwave_cs.c
5 * Description: Netwave AirSurfer Wireless LAN PC Card driver
6 * Status: Experimental.
7 * Authors: John Markus Bjørndalen <johnm@cs.uit.no>
8 * Dag Brattli <dagb@cs.uit.no>
9 * David Hinds <dahinds@users.sourceforge.net>
10 * Created at: A long time ago!
11 * Modified at: Mon Nov 10 11:54:37 1997
12 * Modified by: Dag Brattli <dagb@cs.uit.no>
14 * Copyright (c) 1997 University of Tromsø, Norway
18 * 08-Nov-97 15:14:47 John Markus Bjørndalen <johnm@cs.uit.no>
19 * - Fixed some bugs in netwave_rx and cleaned it up a bit.
20 * (One of the bugs would have destroyed packets when receiving
21 * multiple packets per interrupt).
22 * - Cleaned up parts of newave_hw_xmit.
23 * - A few general cleanups.
24 * 24-Oct-97 13:17:36 Dag Brattli <dagb@cs.uit.no>
25 * - Fixed netwave_rx receive function (got updated docs)
27 * - Changed name from xircnw to netwave, take a look at
28 * http://www.netwave-wireless.com
29 * - Some reorganizing of the code
30 * - Removed possible race condition between interrupt handler and transmit
32 * - Started to add wireless extensions, but still needs some coding
33 * - Added watchdog for better handling of transmission timeouts
34 * (hopefully this works better)
35 ********************************************************************/
37 /* To have statistics (just packets sent) define this */
40 #include <linux/module.h>
41 #include <linux/kernel.h>
42 #include <linux/init.h>
43 #include <linux/types.h>
44 #include <linux/fcntl.h>
45 #include <linux/interrupt.h>
46 #include <linux/ptrace.h>
47 #include <linux/ioport.h>
49 #include <linux/string.h>
50 #include <linux/timer.h>
51 #include <linux/errno.h>
52 #include <linux/netdevice.h>
53 #include <linux/etherdevice.h>
54 #include <linux/skbuff.h>
55 #include <linux/bitops.h>
56 #include <linux/wireless.h>
57 #include <net/iw_handler.h>
59 #include <pcmcia/cs_types.h>
60 #include <pcmcia/cs.h>
61 #include <pcmcia/cistpl.h>
62 #include <pcmcia/cisreg.h>
63 #include <pcmcia/ds.h>
65 #include <asm/system.h>
69 #define NETWAVE_REGOFF 0x8000
70 /* The Netwave IO registers, offsets to iobase */
71 #define NETWAVE_REG_COR 0x0
72 #define NETWAVE_REG_CCSR 0x2
73 #define NETWAVE_REG_ASR 0x4
74 #define NETWAVE_REG_IMR 0xa
75 #define NETWAVE_REG_PMR 0xc
76 #define NETWAVE_REG_IOLOW 0x6
77 #define NETWAVE_REG_IOHI 0x7
78 #define NETWAVE_REG_IOCONTROL 0x8
79 #define NETWAVE_REG_DATA 0xf
80 /* The Netwave Extended IO registers, offsets to RamBase */
81 #define NETWAVE_EREG_ASCC 0x114
82 #define NETWAVE_EREG_RSER 0x120
83 #define NETWAVE_EREG_RSERW 0x124
84 #define NETWAVE_EREG_TSER 0x130
85 #define NETWAVE_EREG_TSERW 0x134
86 #define NETWAVE_EREG_CB 0x100
87 #define NETWAVE_EREG_SPCQ 0x154
88 #define NETWAVE_EREG_SPU 0x155
89 #define NETWAVE_EREG_LIF 0x14e
90 #define NETWAVE_EREG_ISPLQ 0x156
91 #define NETWAVE_EREG_HHC 0x158
92 #define NETWAVE_EREG_NI 0x16e
93 #define NETWAVE_EREG_MHS 0x16b
94 #define NETWAVE_EREG_TDP 0x140
95 #define NETWAVE_EREG_RDP 0x150
96 #define NETWAVE_EREG_PA 0x160
97 #define NETWAVE_EREG_EC 0x180
98 #define NETWAVE_EREG_CRBP 0x17a
99 #define NETWAVE_EREG_ARW 0x166
102 * Commands used in the extended command buffer
103 * NETWAVE_EREG_CB (0x100-0x10F)
105 #define NETWAVE_CMD_NOP 0x00
106 #define NETWAVE_CMD_SRC 0x01
107 #define NETWAVE_CMD_STC 0x02
108 #define NETWAVE_CMD_AMA 0x03
109 #define NETWAVE_CMD_DMA 0x04
110 #define NETWAVE_CMD_SAMA 0x05
111 #define NETWAVE_CMD_ER 0x06
112 #define NETWAVE_CMD_DR 0x07
113 #define NETWAVE_CMD_TL 0x08
114 #define NETWAVE_CMD_SRP 0x09
115 #define NETWAVE_CMD_SSK 0x0a
116 #define NETWAVE_CMD_SMD 0x0b
117 #define NETWAVE_CMD_SAPD 0x0c
118 #define NETWAVE_CMD_SSS 0x11
119 /* End of Command marker */
120 #define NETWAVE_CMD_EOC 0x00
122 /* ASR register bits */
123 #define NETWAVE_ASR_RXRDY 0x80
124 #define NETWAVE_ASR_TXBA 0x01
126 #define TX_TIMEOUT ((32*HZ)/100)
128 static const unsigned int imrConfRFU1 = 0x10; /* RFU interrupt mask, keep high */
129 static const unsigned int imrConfIENA = 0x02; /* Interrupt enable */
131 static const unsigned int corConfIENA = 0x01; /* Interrupt enable */
132 static const unsigned int corConfLVLREQ = 0x40; /* Keep high */
134 static const unsigned int rxConfRxEna = 0x80; /* Receive Enable */
135 static const unsigned int rxConfMAC = 0x20; /* MAC host receive mode*/
136 static const unsigned int rxConfPro = 0x10; /* Promiscuous */
137 static const unsigned int rxConfAMP = 0x08; /* Accept Multicast Packets */
138 static const unsigned int rxConfBcast = 0x04; /* Accept Broadcast Packets */
140 static const unsigned int txConfTxEna = 0x80; /* Transmit Enable */
141 static const unsigned int txConfMAC = 0x20; /* Host sends MAC mode */
142 static const unsigned int txConfEUD = 0x10; /* Enable Uni-Data packets */
143 static const unsigned int txConfKey = 0x02; /* Scramble data packets */
144 static const unsigned int txConfLoop = 0x01; /* Loopback mode */
147 /*====================================================================*/
149 /* Parameters that can be set with 'insmod' */
151 /* Choose the domain, default is 0x100 */
152 static u_int domain = 0x100;
154 /* Scramble key, range from 0x0 to 0xffff.
155 * 0x0 is no scrambling.
157 static u_int scramble_key = 0x0;
159 /* Shared memory speed, in ns. The documentation states that
160 * the card should not be read faster than every 400ns.
161 * This timing should be provided by the HBA. If it becomes a
162 * problem, try setting mem_speed to 400.
164 static int mem_speed;
166 module_param(domain, int, 0);
167 module_param(scramble_key, int, 0);
168 module_param(mem_speed, int, 0);
170 /*====================================================================*/
172 /* PCMCIA (Card Services) related functions */
173 static void netwave_release(struct pcmcia_device *link); /* Card removal */
174 static int netwave_pcmcia_config(struct pcmcia_device *arg); /* Runs after card
176 static void netwave_detach(struct pcmcia_device *p_dev); /* Destroy instance */
178 /* Hardware configuration */
179 static void netwave_doreset(unsigned int iobase, u_char __iomem *ramBase);
180 static void netwave_reset(struct net_device *dev);
182 /* Misc device stuff */
183 static int netwave_open(struct net_device *dev); /* Open the device */
184 static int netwave_close(struct net_device *dev); /* Close the device */
186 /* Packet transmission and Packet reception */
187 static netdev_tx_t netwave_start_xmit( struct sk_buff *skb,
188 struct net_device *dev);
189 static int netwave_rx( struct net_device *dev);
191 /* Interrupt routines */
192 static irqreturn_t netwave_interrupt(int irq, void *dev_id);
193 static void netwave_watchdog(struct net_device *);
195 /* Wireless extensions */
196 static struct iw_statistics* netwave_get_wireless_stats(struct net_device *dev);
198 static void set_multicast_list(struct net_device *dev);
201 A struct pcmcia_device structure has fields for most things that are needed
202 to keep track of a socket, but there will usually be some device
203 specific information that also needs to be kept track of. The
204 'priv' pointer in a struct pcmcia_device structure can be used to point to
205 a device-specific private data structure, like this.
207 A driver needs to provide a dev_node_t structure for each device
208 on a card. In some cases, there is only one device per card (for
209 example, ethernet cards, modems). In other cases, there may be
210 many actual or logical devices (SCSI adapters, memory cards with
211 multiple partitions). The dev_node_t structures need to be kept
212 in a linked list starting at the 'dev' field of a struct pcmcia_device
213 structure. We allocate them in the card's private data structure,
214 because they generally can't be allocated dynamically.
217 static const struct iw_handler_def netwave_handler_def;
219 #define SIOCGIPSNAP SIOCIWFIRSTPRIV + 1 /* Site Survey Snapshot */
223 typedef struct net_addr {
229 u_char struct_revision;
230 u_char roaming_state;
232 u_char sp_existsFlag;
233 u_char sp_link_quality;
234 u_char sp_max_link_quality;
235 u_char linkQualityGoodFairBoundary;
236 u_char linkQualityFairPoorBoundary;
237 u_char sp_utilization;
239 u_char sp_hotheadcount;
240 u_char roaming_condition;
244 net_addr nearByAccessPoints[MAX_ESA];
247 typedef struct netwave_private {
248 struct pcmcia_device *p_dev;
249 spinlock_t spinlock; /* Serialize access to the hardware (SMP) */
251 u_char __iomem *ramBase;
254 struct timer_list watchdog; /* To avoid blocking state */
255 struct site_survey nss;
256 struct iw_statistics iw_stats; /* Wireless stats */
260 * The Netwave card is little-endian, so won't work for big endian
263 static inline unsigned short get_uint16(u_char __iomem *staddr)
265 return readw(staddr); /* Return only 16 bits */
268 static inline short get_int16(u_char __iomem * staddr)
270 return readw(staddr);
274 * Wait until the WOC (Write Operation Complete) bit in the
275 * ASR (Adapter Status Register) is asserted.
276 * This should have aborted if it takes too long time.
278 static inline void wait_WOC(unsigned int iobase)
281 while ((inb(iobase + NETWAVE_REG_ASR) & 0x8) != 0x8) ;
284 static void netwave_snapshot(netwave_private *priv, u_char __iomem *ramBase,
285 unsigned int iobase) {
286 u_short resultBuffer;
288 /* if time since last snapshot is > 1 sec. (100 jiffies?) then take
289 * new snapshot, else return cached data. This is the recommended rate.
291 if ( jiffies - priv->lastExec > 100) {
292 /* Take site survey snapshot */
293 /*printk( KERN_DEBUG "Taking new snapshot. %ld\n", jiffies -
296 writeb(NETWAVE_CMD_SSS, ramBase + NETWAVE_EREG_CB + 0);
297 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 1);
300 /* Get result and copy to cach */
301 resultBuffer = readw(ramBase + NETWAVE_EREG_CRBP);
302 copy_from_pc( &priv->nss, ramBase+resultBuffer,
303 sizeof(struct site_survey));
308 * Function netwave_get_wireless_stats (dev)
310 * Wireless extensions statistics
313 static struct iw_statistics *netwave_get_wireless_stats(struct net_device *dev)
316 unsigned int iobase = dev->base_addr;
317 netwave_private *priv = netdev_priv(dev);
318 u_char __iomem *ramBase = priv->ramBase;
319 struct iw_statistics* wstats;
321 wstats = &priv->iw_stats;
323 spin_lock_irqsave(&priv->spinlock, flags);
325 netwave_snapshot( priv, ramBase, iobase);
327 wstats->status = priv->nss.roaming_state;
328 wstats->qual.qual = readb( ramBase + NETWAVE_EREG_SPCQ);
329 wstats->qual.level = readb( ramBase + NETWAVE_EREG_ISPLQ);
330 wstats->qual.noise = readb( ramBase + NETWAVE_EREG_SPU) & 0x3f;
331 wstats->discard.nwid = 0L;
332 wstats->discard.code = 0L;
333 wstats->discard.misc = 0L;
335 spin_unlock_irqrestore(&priv->spinlock, flags);
337 return &priv->iw_stats;
340 static const struct net_device_ops netwave_netdev_ops = {
341 .ndo_open = netwave_open,
342 .ndo_stop = netwave_close,
343 .ndo_start_xmit = netwave_start_xmit,
344 .ndo_set_multicast_list = set_multicast_list,
345 .ndo_tx_timeout = netwave_watchdog,
346 .ndo_change_mtu = eth_change_mtu,
347 .ndo_set_mac_address = eth_mac_addr,
348 .ndo_validate_addr = eth_validate_addr,
352 * Function netwave_attach (void)
354 * Creates an "instance" of the driver, allocating local data
355 * structures for one device. The device is registered with Card
358 * The dev_link structure is initialized, but we don't actually
359 * configure the card at this point -- we wait until we receive a
360 * card insertion event.
362 static int netwave_probe(struct pcmcia_device *link)
364 struct net_device *dev;
365 netwave_private *priv;
367 dev_dbg(&link->dev, "netwave_attach()\n");
369 /* Initialize the struct pcmcia_device structure */
370 dev = alloc_etherdev(sizeof(netwave_private));
373 priv = netdev_priv(dev);
377 /* The io structure describes IO port mapping */
378 link->io.NumPorts1 = 16;
379 link->io.Attributes1 = IO_DATA_PATH_WIDTH_16;
380 /* link->io.NumPorts2 = 16;
381 link->io.Attributes2 = IO_DATA_PATH_WIDTH_16; */
382 link->io.IOAddrLines = 5;
384 /* General socket configuration */
385 link->conf.Attributes = CONF_ENABLE_IRQ;
386 link->conf.IntType = INT_MEMORY_AND_IO;
387 link->conf.ConfigIndex = 1;
389 /* Netwave private struct init. link/dev/node already taken care of,
390 * other stuff zero'd - Jean II */
391 spin_lock_init(&priv->spinlock);
393 /* Netwave specific entries in the device structure */
394 dev->netdev_ops = &netwave_netdev_ops;
395 /* wireless extensions */
396 dev->wireless_handlers = &netwave_handler_def;
398 dev->watchdog_timeo = TX_TIMEOUT;
400 return netwave_pcmcia_config( link);
401 } /* netwave_attach */
404 * Function netwave_detach (link)
406 * This deletes a driver "instance". The device is de-registered
407 * with Card Services. If it has been released, all local data
408 * structures are freed. Otherwise, the structures will be freed
409 * when the device is released.
411 static void netwave_detach(struct pcmcia_device *link)
413 struct net_device *dev = link->priv;
415 dev_dbg(&link->dev, "netwave_detach\n");
417 netwave_release(link);
420 unregister_netdev(dev);
423 } /* netwave_detach */
426 * Wireless Handler : get protocol name
428 static int netwave_get_name(struct net_device *dev,
429 struct iw_request_info *info,
430 union iwreq_data *wrqu,
433 strcpy(wrqu->name, "Netwave");
438 * Wireless Handler : set Network ID
440 static int netwave_set_nwid(struct net_device *dev,
441 struct iw_request_info *info,
442 union iwreq_data *wrqu,
446 unsigned int iobase = dev->base_addr;
447 netwave_private *priv = netdev_priv(dev);
448 u_char __iomem *ramBase = priv->ramBase;
450 /* Disable interrupts & save flags */
451 spin_lock_irqsave(&priv->spinlock, flags);
453 if(!wrqu->nwid.disabled) {
454 domain = wrqu->nwid.value;
455 printk( KERN_DEBUG "Setting domain to 0x%x%02x\n",
456 (domain >> 8) & 0x01, domain & 0xff);
458 writeb(NETWAVE_CMD_SMD, ramBase + NETWAVE_EREG_CB + 0);
459 writeb( domain & 0xff, ramBase + NETWAVE_EREG_CB + 1);
460 writeb((domain >>8 ) & 0x01,ramBase + NETWAVE_EREG_CB+2);
461 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 3);
464 /* ReEnable interrupts & restore flags */
465 spin_unlock_irqrestore(&priv->spinlock, flags);
471 * Wireless Handler : get Network ID
473 static int netwave_get_nwid(struct net_device *dev,
474 struct iw_request_info *info,
475 union iwreq_data *wrqu,
478 wrqu->nwid.value = domain;
479 wrqu->nwid.disabled = 0;
480 wrqu->nwid.fixed = 1;
485 * Wireless Handler : set scramble key
487 static int netwave_set_scramble(struct net_device *dev,
488 struct iw_request_info *info,
489 union iwreq_data *wrqu,
493 unsigned int iobase = dev->base_addr;
494 netwave_private *priv = netdev_priv(dev);
495 u_char __iomem *ramBase = priv->ramBase;
497 /* Disable interrupts & save flags */
498 spin_lock_irqsave(&priv->spinlock, flags);
500 scramble_key = (key[0] << 8) | key[1];
502 writeb(NETWAVE_CMD_SSK, ramBase + NETWAVE_EREG_CB + 0);
503 writeb(scramble_key & 0xff, ramBase + NETWAVE_EREG_CB + 1);
504 writeb((scramble_key>>8) & 0xff, ramBase + NETWAVE_EREG_CB + 2);
505 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 3);
507 /* ReEnable interrupts & restore flags */
508 spin_unlock_irqrestore(&priv->spinlock, flags);
514 * Wireless Handler : get scramble key
516 static int netwave_get_scramble(struct net_device *dev,
517 struct iw_request_info *info,
518 union iwreq_data *wrqu,
521 key[1] = scramble_key & 0xff;
522 key[0] = (scramble_key>>8) & 0xff;
523 wrqu->encoding.flags = IW_ENCODE_ENABLED;
524 wrqu->encoding.length = 2;
529 * Wireless Handler : get mode
531 static int netwave_get_mode(struct net_device *dev,
532 struct iw_request_info *info,
533 union iwreq_data *wrqu,
537 wrqu->mode = IW_MODE_INFRA;
539 wrqu->mode = IW_MODE_ADHOC;
545 * Wireless Handler : get range info
547 static int netwave_get_range(struct net_device *dev,
548 struct iw_request_info *info,
549 union iwreq_data *wrqu,
552 struct iw_range *range = (struct iw_range *) extra;
555 /* Set the length (very important for backward compatibility) */
556 wrqu->data.length = sizeof(struct iw_range);
558 /* Set all the info we don't care or don't know about to zero */
559 memset(range, 0, sizeof(struct iw_range));
561 /* Set the Wireless Extension versions */
562 range->we_version_compiled = WIRELESS_EXT;
563 range->we_version_source = 9; /* Nothing for us in v10 and v11 */
565 /* Set information in the range struct */
566 range->throughput = 450 * 1000; /* don't argue on this ! */
567 range->min_nwid = 0x0000;
568 range->max_nwid = 0x01FF;
570 range->num_channels = range->num_frequency = 0;
572 range->sensitivity = 0x3F;
573 range->max_qual.qual = 255;
574 range->max_qual.level = 255;
575 range->max_qual.noise = 0;
577 range->num_bitrates = 1;
578 range->bitrate[0] = 1000000; /* 1 Mb/s */
580 range->encoding_size[0] = 2; /* 16 bits scrambling */
581 range->num_encoding_sizes = 1;
582 range->max_encoding_tokens = 1; /* Only one key possible */
588 * Wireless Private Handler : get snapshot
590 static int netwave_get_snap(struct net_device *dev,
591 struct iw_request_info *info,
592 union iwreq_data *wrqu,
596 unsigned int iobase = dev->base_addr;
597 netwave_private *priv = netdev_priv(dev);
598 u_char __iomem *ramBase = priv->ramBase;
600 /* Disable interrupts & save flags */
601 spin_lock_irqsave(&priv->spinlock, flags);
603 /* Take snapshot of environment */
604 netwave_snapshot( priv, ramBase, iobase);
605 wrqu->data.length = priv->nss.length;
606 memcpy(extra, (u_char *) &priv->nss, sizeof( struct site_survey));
608 priv->lastExec = jiffies;
610 /* ReEnable interrupts & restore flags */
611 spin_unlock_irqrestore(&priv->spinlock, flags);
617 * Structures to export the Wireless Handlers
618 * This is the stuff that are treated the wireless extensions (iwconfig)
621 static const struct iw_priv_args netwave_private_args[] = {
622 /*{ cmd, set_args, get_args, name } */
624 IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | sizeof(struct site_survey),
628 static const iw_handler netwave_handler[] =
630 NULL, /* SIOCSIWNAME */
631 netwave_get_name, /* SIOCGIWNAME */
632 netwave_set_nwid, /* SIOCSIWNWID */
633 netwave_get_nwid, /* SIOCGIWNWID */
634 NULL, /* SIOCSIWFREQ */
635 NULL, /* SIOCGIWFREQ */
636 NULL, /* SIOCSIWMODE */
637 netwave_get_mode, /* SIOCGIWMODE */
638 NULL, /* SIOCSIWSENS */
639 NULL, /* SIOCGIWSENS */
640 NULL, /* SIOCSIWRANGE */
641 netwave_get_range, /* SIOCGIWRANGE */
642 NULL, /* SIOCSIWPRIV */
643 NULL, /* SIOCGIWPRIV */
644 NULL, /* SIOCSIWSTATS */
645 NULL, /* SIOCGIWSTATS */
646 NULL, /* SIOCSIWSPY */
647 NULL, /* SIOCGIWSPY */
648 NULL, /* -- hole -- */
649 NULL, /* -- hole -- */
650 NULL, /* SIOCSIWAP */
651 NULL, /* SIOCGIWAP */
652 NULL, /* -- hole -- */
653 NULL, /* SIOCGIWAPLIST */
654 NULL, /* -- hole -- */
655 NULL, /* -- hole -- */
656 NULL, /* SIOCSIWESSID */
657 NULL, /* SIOCGIWESSID */
658 NULL, /* SIOCSIWNICKN */
659 NULL, /* SIOCGIWNICKN */
660 NULL, /* -- hole -- */
661 NULL, /* -- hole -- */
662 NULL, /* SIOCSIWRATE */
663 NULL, /* SIOCGIWRATE */
664 NULL, /* SIOCSIWRTS */
665 NULL, /* SIOCGIWRTS */
666 NULL, /* SIOCSIWFRAG */
667 NULL, /* SIOCGIWFRAG */
668 NULL, /* SIOCSIWTXPOW */
669 NULL, /* SIOCGIWTXPOW */
670 NULL, /* SIOCSIWRETRY */
671 NULL, /* SIOCGIWRETRY */
672 netwave_set_scramble, /* SIOCSIWENCODE */
673 netwave_get_scramble, /* SIOCGIWENCODE */
676 static const iw_handler netwave_private_handler[] =
678 NULL, /* SIOCIWFIRSTPRIV */
679 netwave_get_snap, /* SIOCIWFIRSTPRIV + 1 */
682 static const struct iw_handler_def netwave_handler_def =
684 .num_standard = ARRAY_SIZE(netwave_handler),
685 .num_private = ARRAY_SIZE(netwave_private_handler),
686 .num_private_args = ARRAY_SIZE(netwave_private_args),
687 .standard = (iw_handler *) netwave_handler,
688 .private = (iw_handler *) netwave_private_handler,
689 .private_args = (struct iw_priv_args *) netwave_private_args,
690 .get_wireless_stats = netwave_get_wireless_stats,
694 * Function netwave_pcmcia_config (link)
696 * netwave_pcmcia_config() is scheduled to run after a CARD_INSERTION
697 * event is received, to configure the PCMCIA socket, and to make the
698 * device available to the system.
702 static int netwave_pcmcia_config(struct pcmcia_device *link) {
703 struct net_device *dev = link->priv;
704 netwave_private *priv = netdev_priv(dev);
708 u_char __iomem *ramBase = NULL;
710 dev_dbg(&link->dev, "netwave_pcmcia_config\n");
713 * Try allocating IO ports. This tries a few fixed addresses.
714 * If you want, you can also read the card's config table to
715 * pick addresses -- see the serial driver for an example.
717 for (i = j = 0x0; j < 0x400; j += 0x20) {
718 link->io.BasePort1 = j ^ 0x300;
719 i = pcmcia_request_io(link, &link->io);
727 * Now allocate an interrupt line. Note that this does not
728 * actually assign a handler to the interrupt.
730 ret = pcmcia_request_irq(link, netwave_interrupt);
735 * This actually configures the PCMCIA socket -- setting up
736 * the I/O windows and the interrupt mapping.
738 ret = pcmcia_request_configuration(link, &link->conf);
743 * Allocate a 32K memory window. Note that the struct pcmcia_device
744 * structure provides space for one window handle -- if your
745 * device needs several windows, you'll need to keep track of
746 * the handles in your private data structure, dev->priv.
748 dev_dbg(&link->dev, "Setting mem speed of %d\n", mem_speed);
750 req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_CM|WIN_ENABLE;
751 req.Base = 0; req.Size = 0x8000;
752 req.AccessSpeed = mem_speed;
753 ret = pcmcia_request_window(link, &req, &link->win);
756 mem.CardOffset = 0x20000; mem.Page = 0;
757 ret = pcmcia_map_mem_page(link, link->win, &mem);
761 /* Store base address of the common window frame */
762 ramBase = ioremap(req.Base, 0x8000);
763 priv->ramBase = ramBase;
765 dev->irq = link->irq;
766 dev->base_addr = link->io.BasePort1;
767 SET_NETDEV_DEV(dev, &link->dev);
769 if (register_netdev(dev) != 0) {
770 printk(KERN_DEBUG "netwave_cs: register_netdev() failed\n");
774 strcpy(priv->node.dev_name, dev->name);
775 link->dev_node = &priv->node;
777 /* Reset card before reading physical address */
778 netwave_doreset(dev->base_addr, ramBase);
780 /* Read the ethernet address and fill in the Netwave registers. */
781 for (i = 0; i < 6; i++)
782 dev->dev_addr[i] = readb(ramBase + NETWAVE_EREG_PA + i);
784 printk(KERN_INFO "%s: Netwave: port %#3lx, irq %d, mem %lx, "
785 "id %c%c, hw_addr %pM\n",
786 dev->name, dev->base_addr, dev->irq,
788 (int) readb(ramBase+NETWAVE_EREG_NI),
789 (int) readb(ramBase+NETWAVE_EREG_NI+1),
792 /* get revision words */
793 printk(KERN_DEBUG "Netwave_reset: revision %04x %04x\n",
794 get_uint16(ramBase + NETWAVE_EREG_ARW),
795 get_uint16(ramBase + NETWAVE_EREG_ARW+2));
799 netwave_release(link);
801 } /* netwave_pcmcia_config */
804 * Function netwave_release (arg)
806 * After a card is removed, netwave_release() will unregister the net
807 * device, and release the PCMCIA configuration. If the device is
808 * still open, this will be postponed until it is closed.
810 static void netwave_release(struct pcmcia_device *link)
812 struct net_device *dev = link->priv;
813 netwave_private *priv = netdev_priv(dev);
815 dev_dbg(&link->dev, "netwave_release\n");
817 pcmcia_disable_device(link);
819 iounmap(priv->ramBase);
822 static int netwave_suspend(struct pcmcia_device *link)
824 struct net_device *dev = link->priv;
827 netif_device_detach(dev);
832 static int netwave_resume(struct pcmcia_device *link)
834 struct net_device *dev = link->priv;
838 netif_device_attach(dev);
846 * Function netwave_doreset (ioBase, ramBase)
848 * Proper hardware reset of the card.
850 static void netwave_doreset(unsigned int ioBase, u_char __iomem *ramBase)
854 outb(0x80, ioBase + NETWAVE_REG_PMR);
855 writeb(0x08, ramBase + NETWAVE_EREG_ASCC); /* Bit 3 is WOC */
856 outb(0x0, ioBase + NETWAVE_REG_PMR); /* release reset */
860 * Function netwave_reset (dev)
862 * Reset and restore all of the netwave registers
864 static void netwave_reset(struct net_device *dev) {
866 netwave_private *priv = netdev_priv(dev);
867 u_char __iomem *ramBase = priv->ramBase;
868 unsigned int iobase = dev->base_addr;
870 pr_debug("netwave_reset: Done with hardware reset\n");
872 priv->timeoutCounter = 0;
875 netwave_doreset(iobase, ramBase);
876 printk(KERN_DEBUG "netwave_reset: Done with hardware reset\n");
878 /* Write a NOP to check the card */
880 writeb(NETWAVE_CMD_NOP, ramBase + NETWAVE_EREG_CB + 0);
881 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 1);
883 /* Set receive conf */
885 writeb(NETWAVE_CMD_SRC, ramBase + NETWAVE_EREG_CB + 0);
886 writeb(rxConfRxEna + rxConfBcast, ramBase + NETWAVE_EREG_CB + 1);
887 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 2);
889 /* Set transmit conf */
891 writeb(NETWAVE_CMD_STC, ramBase + NETWAVE_EREG_CB + 0);
892 writeb(txConfTxEna, ramBase + NETWAVE_EREG_CB + 1);
893 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 2);
895 /* Now set the MU Domain */
896 printk(KERN_DEBUG "Setting domain to 0x%x%02x\n", (domain >> 8) & 0x01, domain & 0xff);
898 writeb(NETWAVE_CMD_SMD, ramBase + NETWAVE_EREG_CB + 0);
899 writeb(domain & 0xff, ramBase + NETWAVE_EREG_CB + 1);
900 writeb((domain>>8) & 0x01, ramBase + NETWAVE_EREG_CB + 2);
901 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 3);
903 /* Set scramble key */
904 printk(KERN_DEBUG "Setting scramble key to 0x%x\n", scramble_key);
906 writeb(NETWAVE_CMD_SSK, ramBase + NETWAVE_EREG_CB + 0);
907 writeb(scramble_key & 0xff, ramBase + NETWAVE_EREG_CB + 1);
908 writeb((scramble_key>>8) & 0xff, ramBase + NETWAVE_EREG_CB + 2);
909 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 3);
911 /* Enable interrupts, bit 4 high to keep unused
912 * source from interrupting us, bit 2 high to
913 * set interrupt enable, 567 to enable TxDN,
917 outb(imrConfIENA+imrConfRFU1, iobase + NETWAVE_REG_IMR);
919 /* Hent 4 bytes fra 0x170. Skal vaere 0a,29,88,36
921 * skriv 80 til d000:3688
922 * sjekk om det ble 80
925 /* Enable Receiver */
927 writeb(NETWAVE_CMD_ER, ramBase + NETWAVE_EREG_CB + 0);
928 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 1);
930 /* Set the IENA bit in COR */
932 outb(corConfIENA + corConfLVLREQ, iobase + NETWAVE_REG_COR);
936 * Function netwave_hw_xmit (data, len, dev)
938 static int netwave_hw_xmit(unsigned char* data, int len,
939 struct net_device* dev) {
941 unsigned int TxFreeList,
947 netwave_private *priv = netdev_priv(dev);
948 u_char __iomem * ramBase = priv->ramBase;
949 unsigned int iobase = dev->base_addr;
951 /* Disable interrupts & save flags */
952 spin_lock_irqsave(&priv->spinlock, flags);
954 /* Check if there are transmit buffers available */
956 if ((inb(iobase+NETWAVE_REG_ASR) & NETWAVE_ASR_TXBA) == 0) {
957 /* No buffers available */
958 printk(KERN_DEBUG "netwave_hw_xmit: %s - no xmit buffers available.\n",
960 spin_unlock_irqrestore(&priv->spinlock, flags);
964 dev->stats.tx_bytes += len;
966 pr_debug("Transmitting with SPCQ %x SPU %x LIF %x ISPLQ %x\n",
967 readb(ramBase + NETWAVE_EREG_SPCQ),
968 readb(ramBase + NETWAVE_EREG_SPU),
969 readb(ramBase + NETWAVE_EREG_LIF),
970 readb(ramBase + NETWAVE_EREG_ISPLQ));
972 /* Now try to insert it into the adapters free memory */
974 TxFreeList = get_uint16(ramBase + NETWAVE_EREG_TDP);
975 MaxData = get_uint16(ramBase + NETWAVE_EREG_TDP+2);
976 DataOffset = get_uint16(ramBase + NETWAVE_EREG_TDP+4);
978 pr_debug("TxFreeList %x, MaxData %x, DataOffset %x\n",
979 TxFreeList, MaxData, DataOffset);
981 /* Copy packet to the adapter fragment buffers */
982 curBuff = TxFreeList;
984 while (tmpcount < len) {
985 int tmplen = len - tmpcount;
986 copy_to_pc(ramBase + curBuff + DataOffset, data + tmpcount,
987 (tmplen < MaxData) ? tmplen : MaxData);
990 /* Advance to next buffer */
991 curBuff = get_uint16(ramBase + curBuff);
994 /* Now issue transmit list */
996 writeb(NETWAVE_CMD_TL, ramBase + NETWAVE_EREG_CB + 0);
997 writeb(len & 0xff, ramBase + NETWAVE_EREG_CB + 1);
998 writeb((len>>8) & 0xff, ramBase + NETWAVE_EREG_CB + 2);
999 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 3);
1001 spin_unlock_irqrestore(&priv->spinlock, flags);
1005 static netdev_tx_t netwave_start_xmit(struct sk_buff *skb,
1006 struct net_device *dev) {
1007 /* This flag indicate that the hardware can't perform a transmission.
1008 * Theoritically, NET3 check it before sending a packet to the driver,
1009 * but in fact it never do that and pool continuously.
1010 * As the watchdog will abort too long transmissions, we are quite safe...
1013 netif_stop_queue(dev);
1016 short length = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
1017 unsigned char* buf = skb->data;
1019 if (netwave_hw_xmit( buf, length, dev) == 1) {
1020 /* Some error, let's make them call us another time? */
1021 netif_start_queue(dev);
1023 dev->trans_start = jiffies;
1027 return NETDEV_TX_OK;
1028 } /* netwave_start_xmit */
1031 * Function netwave_interrupt (irq, dev_id)
1033 * This function is the interrupt handler for the Netwave card. This
1034 * routine will be called whenever:
1035 * 1. A packet is received.
1036 * 2. A packet has successfully been transferred and the unit is
1037 * ready to transmit another packet.
1038 * 3. A command has completed execution.
1040 static irqreturn_t netwave_interrupt(int irq, void* dev_id)
1042 unsigned int iobase;
1043 u_char __iomem *ramBase;
1044 struct net_device *dev = (struct net_device *)dev_id;
1045 struct netwave_private *priv = netdev_priv(dev);
1046 struct pcmcia_device *link = priv->p_dev;
1049 if (!netif_device_present(dev))
1052 iobase = dev->base_addr;
1053 ramBase = priv->ramBase;
1055 /* Now find what caused the interrupt, check while interrupts ready */
1056 for (i = 0; i < 10; i++) {
1060 if (!(inb(iobase+NETWAVE_REG_CCSR) & 0x02))
1061 break; /* None of the interrupt sources asserted (normal exit) */
1063 status = inb(iobase + NETWAVE_REG_ASR);
1065 if (!pcmcia_dev_present(link)) {
1066 pr_debug("netwave_interrupt: Interrupt with status 0x%x "
1067 "from removed or suspended card!\n", status);
1072 if (status & 0x80) {
1074 /* wait_WOC(iobase); */
1075 /* RxRdy cannot be reset directly by the host */
1078 if (status & 0x40) {
1081 rser = readb(ramBase + NETWAVE_EREG_RSER);
1084 ++dev->stats.rx_dropped;
1085 ++dev->stats.rx_crc_errors;
1088 ++dev->stats.rx_frame_errors;
1090 /* Clear the RxErr bit in RSER. RSER+4 is the
1091 * write part. Also clear the RxCRC (0x04) and
1092 * RxBig (0x02) bits if present */
1094 writeb(0x40 | (rser & 0x06), ramBase + NETWAVE_EREG_RSER + 4);
1096 /* Write bit 6 high to ASCC to clear RxErr in ASR,
1097 * WOC must be set first!
1100 writeb(0x40, ramBase + NETWAVE_EREG_ASCC);
1102 /* Remember to count up dev->stats on error packets */
1103 ++dev->stats.rx_errors;
1106 if (status & 0x20) {
1109 txStatus = readb(ramBase + NETWAVE_EREG_TSER);
1110 pr_debug("Transmit done. TSER = %x id %x\n",
1111 txStatus, readb(ramBase + NETWAVE_EREG_TSER + 1));
1113 if (txStatus & 0x20) {
1114 /* Transmitting was okay, clear bits */
1116 writeb(0x2f, ramBase + NETWAVE_EREG_TSER + 4);
1117 ++dev->stats.tx_packets;
1120 if (txStatus & 0xd0) {
1121 if (txStatus & 0x80) {
1122 ++dev->stats.collisions; /* Because of /proc/net/dev*/
1123 /* ++dev->stats.tx_aborted_errors; */
1124 /* printk("Collision. %ld\n", jiffies - dev->trans_start); */
1126 if (txStatus & 0x40)
1127 ++dev->stats.tx_carrier_errors;
1128 /* 0x80 TxGU Transmit giveup - nine times and no luck
1129 * 0x40 TxNOAP No access point. Discarded packet.
1130 * 0x10 TxErr Transmit error. Always set when
1131 * TxGU and TxNOAP is set. (Those are the only ones
1134 pr_debug("netwave_interrupt: TxDN with error status %x\n",
1137 /* Clear out TxGU, TxNOAP, TxErr and TxTrys */
1139 writeb(0xdf & txStatus, ramBase+NETWAVE_EREG_TSER+4);
1140 ++dev->stats.tx_errors;
1142 pr_debug("New status is TSER %x ASR %x\n",
1143 readb(ramBase + NETWAVE_EREG_TSER),
1144 inb(iobase + NETWAVE_REG_ASR));
1146 netif_wake_queue(dev);
1148 /* TxBA, this would trigger on all error packets received */
1149 /* if (status & 0x01) {
1150 pr_debug("Transmit buffers available, %x\n", status);
1154 /* Handled if we looped at least one time - Jean II */
1155 return IRQ_RETVAL(i);
1156 } /* netwave_interrupt */
1159 * Function netwave_watchdog (a)
1161 * Watchdog : when we start a transmission, we set a timer in the
1162 * kernel. If the transmission complete, this timer is disabled. If
1163 * it expire, we reset the card.
1166 static void netwave_watchdog(struct net_device *dev) {
1168 pr_debug("%s: netwave_watchdog: watchdog timer expired\n", dev->name);
1170 dev->trans_start = jiffies;
1171 netif_wake_queue(dev);
1172 } /* netwave_watchdog */
1174 static int netwave_rx(struct net_device *dev)
1176 netwave_private *priv = netdev_priv(dev);
1177 u_char __iomem *ramBase = priv->ramBase;
1178 unsigned int iobase = dev->base_addr;
1180 struct sk_buff *skb = NULL;
1181 unsigned int curBuffer,
1185 int dataCount, dataOffset;
1189 pr_debug("xinw_rx: Receiving ... \n");
1191 /* Receive max 10 packets for now. */
1192 for (i = 0; i < 10; i++) {
1195 rxStatus = readb(ramBase + NETWAVE_EREG_RSER);
1196 if ( !( rxStatus & 0x80)) /* No more packets */
1199 /* Check if multicast/broadcast or other */
1200 /* multicast = (rxStatus & 0x20); */
1202 /* The receive list pointer and length of the packet */
1204 rcvLen = get_int16( ramBase + NETWAVE_EREG_RDP);
1205 rcvList = get_uint16( ramBase + NETWAVE_EREG_RDP + 2);
1208 printk(KERN_DEBUG "netwave_rx: Receive packet with len %d\n",
1213 skb = dev_alloc_skb(rcvLen+5);
1215 pr_debug("netwave_rx: Could not allocate an sk_buff of "
1216 "length %d\n", rcvLen);
1217 ++dev->stats.rx_dropped;
1218 /* Tell the adapter to skip the packet */
1220 writeb(NETWAVE_CMD_SRP, ramBase + NETWAVE_EREG_CB + 0);
1221 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 1);
1225 skb_reserve( skb, 2); /* Align IP on 16 byte */
1226 skb_put( skb, rcvLen);
1228 /* Copy packet fragments to the skb data area */
1229 ptr = (u_char*) skb->data;
1230 curBuffer = rcvList;
1232 while ( tmpcount < rcvLen) {
1233 /* Get length and offset of current buffer */
1234 dataCount = get_uint16( ramBase+curBuffer+2);
1235 dataOffset = get_uint16( ramBase+curBuffer+4);
1237 copy_from_pc( ptr + tmpcount,
1238 ramBase+curBuffer+dataOffset, dataCount);
1240 tmpcount += dataCount;
1242 /* Point to next buffer */
1243 curBuffer = get_uint16(ramBase + curBuffer);
1246 skb->protocol = eth_type_trans(skb,dev);
1247 /* Queue packet for network layer */
1250 dev->stats.rx_packets++;
1251 dev->stats.rx_bytes += rcvLen;
1253 /* Got the packet, tell the adapter to skip it */
1255 writeb(NETWAVE_CMD_SRP, ramBase + NETWAVE_EREG_CB + 0);
1256 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 1);
1257 pr_debug("Packet reception ok\n");
1262 static int netwave_open(struct net_device *dev) {
1263 netwave_private *priv = netdev_priv(dev);
1264 struct pcmcia_device *link = priv->p_dev;
1266 dev_dbg(&link->dev, "netwave_open: starting.\n");
1268 if (!pcmcia_dev_present(link))
1273 netif_start_queue(dev);
1279 static int netwave_close(struct net_device *dev) {
1280 netwave_private *priv = netdev_priv(dev);
1281 struct pcmcia_device *link = priv->p_dev;
1283 dev_dbg(&link->dev, "netwave_close: finishing.\n");
1286 netif_stop_queue(dev);
1291 static struct pcmcia_device_id netwave_ids[] = {
1292 PCMCIA_DEVICE_PROD_ID12("Xircom", "CreditCard Netwave", 0x2e3ee845, 0x54e28a28),
1295 MODULE_DEVICE_TABLE(pcmcia, netwave_ids);
1297 static struct pcmcia_driver netwave_driver = {
1298 .owner = THIS_MODULE,
1300 .name = "netwave_cs",
1302 .probe = netwave_probe,
1303 .remove = netwave_detach,
1304 .id_table = netwave_ids,
1305 .suspend = netwave_suspend,
1306 .resume = netwave_resume,
1309 static int __init init_netwave_cs(void)
1311 return pcmcia_register_driver(&netwave_driver);
1314 static void __exit exit_netwave_cs(void)
1316 pcmcia_unregister_driver(&netwave_driver);
1319 module_init(init_netwave_cs);
1320 module_exit(exit_netwave_cs);
1322 /* Set or clear the multicast filter for this adaptor.
1323 num_addrs == -1 Promiscuous mode, receive all packets
1324 num_addrs == 0 Normal mode, clear multicast list
1325 num_addrs > 0 Multicast mode, receive normal and MC packets, and do
1326 best-effort filtering.
1328 static void set_multicast_list(struct net_device *dev)
1330 unsigned int iobase = dev->base_addr;
1331 netwave_private *priv = netdev_priv(dev);
1332 u_char __iomem * ramBase = priv->ramBase;
1338 if (old != netdev_mc_count(dev)) {
1339 old = netdev_mc_count(dev);
1340 pr_debug("%s: setting Rx mode to %d addresses.\n",
1341 dev->name, netdev_mc_count(dev));
1346 if (!netdev_mc_empty(dev) || (dev->flags & IFF_ALLMULTI)) {
1347 /* Multicast Mode */
1348 rcvMode = rxConfRxEna + rxConfAMP + rxConfBcast;
1349 } else if (dev->flags & IFF_PROMISC) {
1350 /* Promiscous mode */
1351 rcvMode = rxConfRxEna + rxConfPro + rxConfAMP + rxConfBcast;
1354 rcvMode = rxConfRxEna + rxConfBcast;
1357 /* printk("netwave set_multicast_list: rcvMode to %x\n", rcvMode);*/
1358 /* Now set receive mode */
1360 writeb(NETWAVE_CMD_SRC, ramBase + NETWAVE_EREG_CB + 0);
1361 writeb(rcvMode, ramBase + NETWAVE_EREG_CB + 1);
1362 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 2);
1364 MODULE_LICENSE("GPL");