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/config.h>
41 #include <linux/module.h>
42 #include <linux/kernel.h>
43 #include <linux/init.h>
44 #include <linux/types.h>
45 #include <linux/fcntl.h>
46 #include <linux/interrupt.h>
47 #include <linux/ptrace.h>
48 #include <linux/ioport.h>
50 #include <linux/slab.h>
51 #include <linux/string.h>
52 #include <linux/timer.h>
53 #include <linux/errno.h>
54 #include <linux/netdevice.h>
55 #include <linux/etherdevice.h>
56 #include <linux/skbuff.h>
57 #include <linux/bitops.h>
58 #ifdef CONFIG_NET_RADIO
59 #include <linux/wireless.h>
61 #include <net/iw_handler.h>
62 #endif /* WIRELESS_EXT > 12 */
65 #include <pcmcia/version.h>
66 #include <pcmcia/cs_types.h>
67 #include <pcmcia/cs.h>
68 #include <pcmcia/cistpl.h>
69 #include <pcmcia/cisreg.h>
70 #include <pcmcia/ds.h>
71 #include <pcmcia/mem_op.h>
73 #include <asm/system.h>
77 #define NETWAVE_REGOFF 0x8000
78 /* The Netwave IO registers, offsets to iobase */
79 #define NETWAVE_REG_COR 0x0
80 #define NETWAVE_REG_CCSR 0x2
81 #define NETWAVE_REG_ASR 0x4
82 #define NETWAVE_REG_IMR 0xa
83 #define NETWAVE_REG_PMR 0xc
84 #define NETWAVE_REG_IOLOW 0x6
85 #define NETWAVE_REG_IOHI 0x7
86 #define NETWAVE_REG_IOCONTROL 0x8
87 #define NETWAVE_REG_DATA 0xf
88 /* The Netwave Extended IO registers, offsets to RamBase */
89 #define NETWAVE_EREG_ASCC 0x114
90 #define NETWAVE_EREG_RSER 0x120
91 #define NETWAVE_EREG_RSERW 0x124
92 #define NETWAVE_EREG_TSER 0x130
93 #define NETWAVE_EREG_TSERW 0x134
94 #define NETWAVE_EREG_CB 0x100
95 #define NETWAVE_EREG_SPCQ 0x154
96 #define NETWAVE_EREG_SPU 0x155
97 #define NETWAVE_EREG_LIF 0x14e
98 #define NETWAVE_EREG_ISPLQ 0x156
99 #define NETWAVE_EREG_HHC 0x158
100 #define NETWAVE_EREG_NI 0x16e
101 #define NETWAVE_EREG_MHS 0x16b
102 #define NETWAVE_EREG_TDP 0x140
103 #define NETWAVE_EREG_RDP 0x150
104 #define NETWAVE_EREG_PA 0x160
105 #define NETWAVE_EREG_EC 0x180
106 #define NETWAVE_EREG_CRBP 0x17a
107 #define NETWAVE_EREG_ARW 0x166
110 * Commands used in the extended command buffer
111 * NETWAVE_EREG_CB (0x100-0x10F)
113 #define NETWAVE_CMD_NOP 0x00
114 #define NETWAVE_CMD_SRC 0x01
115 #define NETWAVE_CMD_STC 0x02
116 #define NETWAVE_CMD_AMA 0x03
117 #define NETWAVE_CMD_DMA 0x04
118 #define NETWAVE_CMD_SAMA 0x05
119 #define NETWAVE_CMD_ER 0x06
120 #define NETWAVE_CMD_DR 0x07
121 #define NETWAVE_CMD_TL 0x08
122 #define NETWAVE_CMD_SRP 0x09
123 #define NETWAVE_CMD_SSK 0x0a
124 #define NETWAVE_CMD_SMD 0x0b
125 #define NETWAVE_CMD_SAPD 0x0c
126 #define NETWAVE_CMD_SSS 0x11
127 /* End of Command marker */
128 #define NETWAVE_CMD_EOC 0x00
130 /* ASR register bits */
131 #define NETWAVE_ASR_RXRDY 0x80
132 #define NETWAVE_ASR_TXBA 0x01
134 #define TX_TIMEOUT ((32*HZ)/100)
136 static const unsigned int imrConfRFU1 = 0x10; /* RFU interrupt mask, keep high */
137 static const unsigned int imrConfIENA = 0x02; /* Interrupt enable */
139 static const unsigned int corConfIENA = 0x01; /* Interrupt enable */
140 static const unsigned int corConfLVLREQ = 0x40; /* Keep high */
142 static const unsigned int rxConfRxEna = 0x80; /* Receive Enable */
143 static const unsigned int rxConfMAC = 0x20; /* MAC host receive mode*/
144 static const unsigned int rxConfPro = 0x10; /* Promiscuous */
145 static const unsigned int rxConfAMP = 0x08; /* Accept Multicast Packets */
146 static const unsigned int rxConfBcast = 0x04; /* Accept Broadcast Packets */
148 static const unsigned int txConfTxEna = 0x80; /* Transmit Enable */
149 static const unsigned int txConfMAC = 0x20; /* Host sends MAC mode */
150 static const unsigned int txConfEUD = 0x10; /* Enable Uni-Data packets */
151 static const unsigned int txConfKey = 0x02; /* Scramble data packets */
152 static const unsigned int txConfLoop = 0x01; /* Loopback mode */
155 All the PCMCIA modules use PCMCIA_DEBUG to control debugging. If
156 you do not define PCMCIA_DEBUG at all, all the debug code will be
157 left out. If you compile with PCMCIA_DEBUG=0, the debug code will
158 be present but disabled -- but it can then be enabled for specific
159 modules at load time with a 'pc_debug=#' option to insmod.
163 static int pc_debug = PCMCIA_DEBUG;
164 module_param(pc_debug, int, 0);
165 #define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args)
166 static char *version =
167 "netwave_cs.c 0.3.0 Thu Jul 17 14:36:02 1997 (John Markus Bjørndalen)\n";
169 #define DEBUG(n, args...)
172 static dev_info_t dev_info = "netwave_cs";
174 /*====================================================================*/
176 /* Parameters that can be set with 'insmod' */
178 /* Choose the domain, default is 0x100 */
179 static u_int domain = 0x100;
181 /* Scramble key, range from 0x0 to 0xffff.
182 * 0x0 is no scrambling.
184 static u_int scramble_key = 0x0;
186 /* Shared memory speed, in ns. The documentation states that
187 * the card should not be read faster than every 400ns.
188 * This timing should be provided by the HBA. If it becomes a
189 * problem, try setting mem_speed to 400.
191 static int mem_speed;
193 module_param(domain, int, 0);
194 module_param(scramble_key, int, 0);
195 module_param(mem_speed, int, 0);
197 /*====================================================================*/
199 /* PCMCIA (Card Services) related functions */
200 static void netwave_release(dev_link_t *link); /* Card removal */
201 static int netwave_event(event_t event, int priority,
202 event_callback_args_t *args);
203 static void netwave_pcmcia_config(dev_link_t *arg); /* Runs after card
205 static dev_link_t *netwave_attach(void); /* Create instance */
206 static void netwave_detach(dev_link_t *); /* Destroy instance */
208 /* Hardware configuration */
209 static void netwave_doreset(kio_addr_t iobase, u_char __iomem *ramBase);
210 static void netwave_reset(struct net_device *dev);
212 /* Misc device stuff */
213 static int netwave_open(struct net_device *dev); /* Open the device */
214 static int netwave_close(struct net_device *dev); /* Close the device */
216 /* Packet transmission and Packet reception */
217 static int netwave_start_xmit( struct sk_buff *skb, struct net_device *dev);
218 static int netwave_rx( struct net_device *dev);
220 /* Interrupt routines */
221 static irqreturn_t netwave_interrupt(int irq, void *dev_id, struct pt_regs *regs);
222 static void netwave_watchdog(struct net_device *);
225 static void update_stats(struct net_device *dev);
226 static struct net_device_stats *netwave_get_stats(struct net_device *dev);
228 /* Wireless extensions */
230 static struct iw_statistics* netwave_get_wireless_stats(struct net_device *dev);
232 static int netwave_ioctl(struct net_device *, struct ifreq *, int);
234 static void set_multicast_list(struct net_device *dev);
237 A linked list of "instances" of the skeleton device. Each actual
238 PCMCIA card corresponds to one device instance, and is described
239 by one dev_link_t structure (defined in ds.h).
241 You may not want to use a linked list for this -- for example, the
242 memory card driver uses an array of dev_link_t pointers, where minor
243 device numbers are used to derive the corresponding array index.
245 static dev_link_t *dev_list;
248 A dev_link_t structure has fields for most things that are needed
249 to keep track of a socket, but there will usually be some device
250 specific information that also needs to be kept track of. The
251 'priv' pointer in a dev_link_t structure can be used to point to
252 a device-specific private data structure, like this.
254 A driver needs to provide a dev_node_t structure for each device
255 on a card. In some cases, there is only one device per card (for
256 example, ethernet cards, modems). In other cases, there may be
257 many actual or logical devices (SCSI adapters, memory cards with
258 multiple partitions). The dev_node_t structures need to be kept
259 in a linked list starting at the 'dev' field of a dev_link_t
260 structure. We allocate them in the card's private data structure,
261 because they generally can't be allocated dynamically.
264 #if WIRELESS_EXT <= 12
265 /* Wireless extensions backward compatibility */
267 /* Part of iw_handler prototype we need */
268 struct iw_request_info
270 __u16 cmd; /* Wireless Extension command */
271 __u16 flags; /* More to come ;-) */
274 /* Wireless Extension Backward compatibility - Jean II
275 * If the new wireless device private ioctl range is not defined,
276 * default to standard device private ioctl range */
277 #ifndef SIOCIWFIRSTPRIV
278 #define SIOCIWFIRSTPRIV SIOCDEVPRIVATE
279 #endif /* SIOCIWFIRSTPRIV */
281 #else /* WIRELESS_EXT <= 12 */
282 static const struct iw_handler_def netwave_handler_def;
283 #endif /* WIRELESS_EXT <= 12 */
285 #define SIOCGIPSNAP SIOCIWFIRSTPRIV + 1 /* Site Survey Snapshot */
289 typedef struct net_addr {
295 u_char struct_revision;
296 u_char roaming_state;
298 u_char sp_existsFlag;
299 u_char sp_link_quality;
300 u_char sp_max_link_quality;
301 u_char linkQualityGoodFairBoundary;
302 u_char linkQualityFairPoorBoundary;
303 u_char sp_utilization;
305 u_char sp_hotheadcount;
306 u_char roaming_condition;
310 net_addr nearByAccessPoints[MAX_ESA];
313 typedef struct netwave_private {
315 spinlock_t spinlock; /* Serialize access to the hardware (SMP) */
317 u_char __iomem *ramBase;
320 struct timer_list watchdog; /* To avoid blocking state */
321 struct site_survey nss;
322 struct net_device_stats stats;
324 struct iw_statistics iw_stats; /* Wireless stats */
329 static struct net_device_stats *netwave_get_stats(struct net_device *dev);
333 * The Netwave card is little-endian, so won't work for big endian
336 static inline unsigned short get_uint16(u_char __iomem *staddr)
338 return readw(staddr); /* Return only 16 bits */
341 static inline short get_int16(u_char __iomem * staddr)
343 return readw(staddr);
347 * Wait until the WOC (Write Operation Complete) bit in the
348 * ASR (Adapter Status Register) is asserted.
349 * This should have aborted if it takes too long time.
351 static inline void wait_WOC(unsigned int iobase)
354 while ((inb(iobase + NETWAVE_REG_ASR) & 0x8) != 0x8) ;
358 static void netwave_snapshot(netwave_private *priv, u_char __iomem *ramBase,
360 u_short resultBuffer;
362 /* if time since last snapshot is > 1 sec. (100 jiffies?) then take
363 * new snapshot, else return cached data. This is the recommended rate.
365 if ( jiffies - priv->lastExec > 100) {
366 /* Take site survey snapshot */
367 /*printk( KERN_DEBUG "Taking new snapshot. %ld\n", jiffies -
370 writeb(NETWAVE_CMD_SSS, ramBase + NETWAVE_EREG_CB + 0);
371 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 1);
374 /* Get result and copy to cach */
375 resultBuffer = readw(ramBase + NETWAVE_EREG_CRBP);
376 copy_from_pc( &priv->nss, ramBase+resultBuffer,
377 sizeof(struct site_survey));
384 * Function netwave_get_wireless_stats (dev)
386 * Wireless extensions statistics
389 static struct iw_statistics *netwave_get_wireless_stats(struct net_device *dev)
392 kio_addr_t iobase = dev->base_addr;
393 netwave_private *priv = netdev_priv(dev);
394 u_char __iomem *ramBase = priv->ramBase;
395 struct iw_statistics* wstats;
397 wstats = &priv->iw_stats;
399 spin_lock_irqsave(&priv->spinlock, flags);
401 netwave_snapshot( priv, ramBase, iobase);
403 wstats->status = priv->nss.roaming_state;
404 wstats->qual.qual = readb( ramBase + NETWAVE_EREG_SPCQ);
405 wstats->qual.level = readb( ramBase + NETWAVE_EREG_ISPLQ);
406 wstats->qual.noise = readb( ramBase + NETWAVE_EREG_SPU) & 0x3f;
407 wstats->discard.nwid = 0L;
408 wstats->discard.code = 0L;
409 wstats->discard.misc = 0L;
411 spin_unlock_irqrestore(&priv->spinlock, flags);
413 return &priv->iw_stats;
418 * Function netwave_attach (void)
420 * Creates an "instance" of the driver, allocating local data
421 * structures for one device. The device is registered with Card
424 * The dev_link structure is initialized, but we don't actually
425 * configure the card at this point -- we wait until we receive a
426 * card insertion event.
428 static dev_link_t *netwave_attach(void)
430 client_reg_t client_reg;
432 struct net_device *dev;
433 netwave_private *priv;
436 DEBUG(0, "netwave_attach()\n");
438 /* Initialize the dev_link_t structure */
439 dev = alloc_etherdev(sizeof(netwave_private));
442 priv = netdev_priv(dev);
446 /* The io structure describes IO port mapping */
447 link->io.NumPorts1 = 16;
448 link->io.Attributes1 = IO_DATA_PATH_WIDTH_16;
449 /* link->io.NumPorts2 = 16;
450 link->io.Attributes2 = IO_DATA_PATH_WIDTH_16; */
451 link->io.IOAddrLines = 5;
453 /* Interrupt setup */
454 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT;
455 link->irq.IRQInfo1 = IRQ_LEVEL_ID;
456 link->irq.Handler = &netwave_interrupt;
458 /* General socket configuration */
459 link->conf.Attributes = CONF_ENABLE_IRQ;
461 link->conf.IntType = INT_MEMORY_AND_IO;
462 link->conf.ConfigIndex = 1;
463 link->conf.Present = PRESENT_OPTION;
465 /* Netwave private struct init. link/dev/node already taken care of,
466 * other stuff zero'd - Jean II */
467 spin_lock_init(&priv->spinlock);
469 /* Netwave specific entries in the device structure */
470 SET_MODULE_OWNER(dev);
471 dev->hard_start_xmit = &netwave_start_xmit;
472 dev->get_stats = &netwave_get_stats;
473 dev->set_multicast_list = &set_multicast_list;
474 /* wireless extensions */
476 dev->get_wireless_stats = &netwave_get_wireless_stats;
477 #if WIRELESS_EXT > 12
478 dev->wireless_handlers = (struct iw_handler_def *)&netwave_handler_def;
479 #endif /* WIRELESS_EXT > 12 */
480 #endif /* WIRELESS_EXT */
481 dev->do_ioctl = &netwave_ioctl;
483 dev->tx_timeout = &netwave_watchdog;
484 dev->watchdog_timeo = TX_TIMEOUT;
486 dev->open = &netwave_open;
487 dev->stop = &netwave_close;
488 link->irq.Instance = dev;
490 /* Register with Card Services */
491 link->next = dev_list;
493 client_reg.dev_info = &dev_info;
494 client_reg.Version = 0x0210;
495 client_reg.event_callback_args.client_data = link;
496 ret = pcmcia_register_client(&link->handle, &client_reg);
498 cs_error(link->handle, RegisterClient, ret);
499 netwave_detach(link);
504 } /* netwave_attach */
507 * Function netwave_detach (link)
509 * This deletes a driver "instance". The device is de-registered
510 * with Card Services. If it has been released, all local data
511 * structures are freed. Otherwise, the structures will be freed
512 * when the device is released.
514 static void netwave_detach(dev_link_t *link)
516 struct net_device *dev = link->priv;
519 DEBUG(0, "netwave_detach(0x%p)\n", link);
522 If the device is currently configured and active, we won't
523 actually delete it yet. Instead, it is marked so that when
524 the release() function is called, that will trigger a proper
527 if (link->state & DEV_CONFIG)
528 netwave_release(link);
530 /* Break the link with Card Services */
532 pcmcia_deregister_client(link->handle);
534 /* Locate device structure */
535 for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next)
536 if (*linkp == link) break;
539 DEBUG(1, "netwave_cs: detach fail, '%s' not in list\n",
540 link->dev->dev_name);
544 /* Unlink device structure, free pieces */
547 unregister_netdev(dev);
550 } /* netwave_detach */
553 * Wireless Handler : get protocol name
555 static int netwave_get_name(struct net_device *dev,
556 struct iw_request_info *info,
557 union iwreq_data *wrqu,
560 strcpy(wrqu->name, "Netwave");
565 * Wireless Handler : set Network ID
567 static int netwave_set_nwid(struct net_device *dev,
568 struct iw_request_info *info,
569 union iwreq_data *wrqu,
573 kio_addr_t iobase = dev->base_addr;
574 netwave_private *priv = netdev_priv(dev);
575 u_char __iomem *ramBase = priv->ramBase;
577 /* Disable interrupts & save flags */
578 spin_lock_irqsave(&priv->spinlock, flags);
581 if(!wrqu->nwid.disabled) {
582 domain = wrqu->nwid.value;
583 #else /* WIRELESS_EXT > 8 */
585 domain = wrqu->nwid.nwid;
586 #endif /* WIRELESS_EXT > 8 */
587 printk( KERN_DEBUG "Setting domain to 0x%x%02x\n",
588 (domain >> 8) & 0x01, domain & 0xff);
590 writeb(NETWAVE_CMD_SMD, ramBase + NETWAVE_EREG_CB + 0);
591 writeb( domain & 0xff, ramBase + NETWAVE_EREG_CB + 1);
592 writeb((domain >>8 ) & 0x01,ramBase + NETWAVE_EREG_CB+2);
593 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 3);
596 /* ReEnable interrupts & restore flags */
597 spin_unlock_irqrestore(&priv->spinlock, flags);
603 * Wireless Handler : get Network ID
605 static int netwave_get_nwid(struct net_device *dev,
606 struct iw_request_info *info,
607 union iwreq_data *wrqu,
611 wrqu->nwid.value = domain;
612 wrqu->nwid.disabled = 0;
613 wrqu->nwid.fixed = 1;
614 #else /* WIRELESS_EXT > 8 */
615 wrqu->nwid.nwid = domain;
617 #endif /* WIRELESS_EXT > 8 */
623 * Wireless Handler : set scramble key
625 static int netwave_set_scramble(struct net_device *dev,
626 struct iw_request_info *info,
627 union iwreq_data *wrqu,
631 kio_addr_t iobase = dev->base_addr;
632 netwave_private *priv = netdev_priv(dev);
633 u_char __iomem *ramBase = priv->ramBase;
635 /* Disable interrupts & save flags */
636 spin_lock_irqsave(&priv->spinlock, flags);
638 scramble_key = (key[0] << 8) | key[1];
640 writeb(NETWAVE_CMD_SSK, ramBase + NETWAVE_EREG_CB + 0);
641 writeb(scramble_key & 0xff, ramBase + NETWAVE_EREG_CB + 1);
642 writeb((scramble_key>>8) & 0xff, ramBase + NETWAVE_EREG_CB + 2);
643 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 3);
645 /* ReEnable interrupts & restore flags */
646 spin_unlock_irqrestore(&priv->spinlock, flags);
652 * Wireless Handler : get scramble key
654 static int netwave_get_scramble(struct net_device *dev,
655 struct iw_request_info *info,
656 union iwreq_data *wrqu,
659 key[1] = scramble_key & 0xff;
660 key[0] = (scramble_key>>8) & 0xff;
662 wrqu->encoding.flags = IW_ENCODE_ENABLED;
663 wrqu->encoding.length = 2;
664 #else /* WIRELESS_EXT > 8 */
665 wrqu->encoding.method = 1;
666 #endif /* WIRELESS_EXT > 8 */
673 * Wireless Handler : get mode
675 static int netwave_get_mode(struct net_device *dev,
676 struct iw_request_info *info,
677 union iwreq_data *wrqu,
681 wrqu->mode = IW_MODE_INFRA;
683 wrqu->mode = IW_MODE_ADHOC;
687 #endif /* WIRELESS_EXT > 8 */
690 * Wireless Handler : get range info
692 static int netwave_get_range(struct net_device *dev,
693 struct iw_request_info *info,
694 union iwreq_data *wrqu,
697 struct iw_range *range = (struct iw_range *) extra;
700 /* Set the length (very important for backward compatibility) */
701 wrqu->data.length = sizeof(struct iw_range);
703 /* Set all the info we don't care or don't know about to zero */
704 memset(range, 0, sizeof(struct iw_range));
706 #if WIRELESS_EXT > 10
707 /* Set the Wireless Extension versions */
708 range->we_version_compiled = WIRELESS_EXT;
709 range->we_version_source = 9; /* Nothing for us in v10 and v11 */
710 #endif /* WIRELESS_EXT > 10 */
712 /* Set information in the range struct */
713 range->throughput = 450 * 1000; /* don't argue on this ! */
714 range->min_nwid = 0x0000;
715 range->max_nwid = 0x01FF;
717 range->num_channels = range->num_frequency = 0;
719 range->sensitivity = 0x3F;
720 range->max_qual.qual = 255;
721 range->max_qual.level = 255;
722 range->max_qual.noise = 0;
725 range->num_bitrates = 1;
726 range->bitrate[0] = 1000000; /* 1 Mb/s */
727 #endif /* WIRELESS_EXT > 7 */
730 range->encoding_size[0] = 2; /* 16 bits scrambling */
731 range->num_encoding_sizes = 1;
732 range->max_encoding_tokens = 1; /* Only one key possible */
733 #endif /* WIRELESS_EXT > 8 */
739 * Wireless Private Handler : get snapshot
741 static int netwave_get_snap(struct net_device *dev,
742 struct iw_request_info *info,
743 union iwreq_data *wrqu,
747 kio_addr_t iobase = dev->base_addr;
748 netwave_private *priv = netdev_priv(dev);
749 u_char __iomem *ramBase = priv->ramBase;
751 /* Disable interrupts & save flags */
752 spin_lock_irqsave(&priv->spinlock, flags);
754 /* Take snapshot of environment */
755 netwave_snapshot( priv, ramBase, iobase);
756 wrqu->data.length = priv->nss.length;
757 memcpy(extra, (u_char *) &priv->nss, sizeof( struct site_survey));
759 priv->lastExec = jiffies;
761 /* ReEnable interrupts & restore flags */
762 spin_unlock_irqrestore(&priv->spinlock, flags);
768 * Structures to export the Wireless Handlers
769 * This is the stuff that are treated the wireless extensions (iwconfig)
772 static const struct iw_priv_args netwave_private_args[] = {
773 /*{ cmd, set_args, get_args, name } */
775 IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | sizeof(struct site_survey),
779 #if WIRELESS_EXT > 12
781 static const iw_handler netwave_handler[] =
783 NULL, /* SIOCSIWNAME */
784 netwave_get_name, /* SIOCGIWNAME */
785 netwave_set_nwid, /* SIOCSIWNWID */
786 netwave_get_nwid, /* SIOCGIWNWID */
787 NULL, /* SIOCSIWFREQ */
788 NULL, /* SIOCGIWFREQ */
789 NULL, /* SIOCSIWMODE */
790 netwave_get_mode, /* SIOCGIWMODE */
791 NULL, /* SIOCSIWSENS */
792 NULL, /* SIOCGIWSENS */
793 NULL, /* SIOCSIWRANGE */
794 netwave_get_range, /* SIOCGIWRANGE */
795 NULL, /* SIOCSIWPRIV */
796 NULL, /* SIOCGIWPRIV */
797 NULL, /* SIOCSIWSTATS */
798 NULL, /* SIOCGIWSTATS */
799 NULL, /* SIOCSIWSPY */
800 NULL, /* SIOCGIWSPY */
801 NULL, /* -- hole -- */
802 NULL, /* -- hole -- */
803 NULL, /* SIOCSIWAP */
804 NULL, /* SIOCGIWAP */
805 NULL, /* -- hole -- */
806 NULL, /* SIOCGIWAPLIST */
807 NULL, /* -- hole -- */
808 NULL, /* -- hole -- */
809 NULL, /* SIOCSIWESSID */
810 NULL, /* SIOCGIWESSID */
811 NULL, /* SIOCSIWNICKN */
812 NULL, /* SIOCGIWNICKN */
813 NULL, /* -- hole -- */
814 NULL, /* -- hole -- */
815 NULL, /* SIOCSIWRATE */
816 NULL, /* SIOCGIWRATE */
817 NULL, /* SIOCSIWRTS */
818 NULL, /* SIOCGIWRTS */
819 NULL, /* SIOCSIWFRAG */
820 NULL, /* SIOCGIWFRAG */
821 NULL, /* SIOCSIWTXPOW */
822 NULL, /* SIOCGIWTXPOW */
823 NULL, /* SIOCSIWRETRY */
824 NULL, /* SIOCGIWRETRY */
825 netwave_set_scramble, /* SIOCSIWENCODE */
826 netwave_get_scramble, /* SIOCGIWENCODE */
829 static const iw_handler netwave_private_handler[] =
831 NULL, /* SIOCIWFIRSTPRIV */
832 netwave_get_snap, /* SIOCIWFIRSTPRIV + 1 */
835 static const struct iw_handler_def netwave_handler_def =
837 .num_standard = sizeof(netwave_handler)/sizeof(iw_handler),
838 .num_private = sizeof(netwave_private_handler)/sizeof(iw_handler),
839 .num_private_args = sizeof(netwave_private_args)/sizeof(struct iw_priv_args),
840 .standard = (iw_handler *) netwave_handler,
841 .private = (iw_handler *) netwave_private_handler,
842 .private_args = (struct iw_priv_args *) netwave_private_args,
844 #endif /* WIRELESS_EXT > 12 */
847 * Function netwave_ioctl (dev, rq, cmd)
849 * Perform ioctl : config & info stuff
850 * This is the stuff that are treated the wireless extensions (iwconfig)
853 static int netwave_ioctl(struct net_device *dev, /* ioctl device */
854 struct ifreq *rq, /* Data passed */
855 int cmd) /* Ioctl number */
859 #if WIRELESS_EXT <= 12
860 struct iwreq *wrq = (struct iwreq *) rq;
864 DEBUG(0, "%s: ->netwave_ioctl(cmd=0x%X)\n", dev->name, cmd);
866 /* Look what is the request */
868 /* --------------- WIRELESS EXTENSIONS --------------- */
870 #if WIRELESS_EXT <= 12
872 netwave_get_name(dev, NULL, &(wrq->u), NULL);
875 ret = netwave_set_nwid(dev, NULL, &(wrq->u), NULL);
878 ret = netwave_get_nwid(dev, NULL, &(wrq->u), NULL);
880 #if WIRELESS_EXT > 8 /* Note : The API did change... */
882 /* Get scramble key */
883 if(wrq->u.encoding.pointer != (caddr_t) 0)
886 ret = netwave_get_scramble(dev, NULL, &(wrq->u), key);
887 if(copy_to_user(wrq->u.encoding.pointer, key, 2))
892 /* Set scramble key */
893 if(wrq->u.encoding.pointer != (caddr_t) 0)
896 if(copy_from_user(key, wrq->u.encoding.pointer, 2))
901 ret = netwave_set_scramble(dev, NULL, &(wrq->u), key);
905 /* Mode of operation */
906 ret = netwave_get_mode(dev, NULL, &(wrq->u), NULL);
908 #else /* WIRELESS_EXT > 8 */
910 /* Get scramble key */
911 ret = netwave_get_scramble(dev, NULL, &(wrq->u),
912 (char *) &wrq->u.encoding.code);
915 /* Set scramble key */
916 ret = netwave_set_scramble(dev, NULL, &(wrq->u),
917 (char *) &wrq->u.encoding.code);
919 #endif /* WIRELESS_EXT > 8 */
921 /* Basic checking... */
922 if(wrq->u.data.pointer != (caddr_t) 0) {
923 struct iw_range range;
924 ret = netwave_get_range(dev, NULL, &(wrq->u), (char *) &range);
925 if (copy_to_user(wrq->u.data.pointer, &range,
926 sizeof(struct iw_range)))
931 /* Basic checking... */
932 if(wrq->u.data.pointer != (caddr_t) 0) {
933 /* Set the number of ioctl available */
934 wrq->u.data.length = sizeof(netwave_private_args) / sizeof(netwave_private_args[0]);
936 /* Copy structure to the user buffer */
937 if(copy_to_user(wrq->u.data.pointer,
938 (u_char *) netwave_private_args,
939 sizeof(netwave_private_args)))
944 if(wrq->u.data.pointer != (caddr_t) 0) {
945 char buffer[sizeof( struct site_survey)];
946 ret = netwave_get_snap(dev, NULL, &(wrq->u), buffer);
947 /* Copy structure to the user buffer */
948 if(copy_to_user(wrq->u.data.pointer,
950 sizeof( struct site_survey)))
952 printk(KERN_DEBUG "Bad buffer!\n");
957 #endif /* WIRELESS_EXT <= 12 */
958 #endif /* WIRELESS_EXT */
967 * Function netwave_pcmcia_config (link)
969 * netwave_pcmcia_config() is scheduled to run after a CARD_INSERTION
970 * event is received, to configure the PCMCIA socket, and to make the
971 * device available to the system.
975 #define CS_CHECK(fn, ret) \
976 do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
978 static void netwave_pcmcia_config(dev_link_t *link) {
979 client_handle_t handle = link->handle;
980 struct net_device *dev = link->priv;
981 netwave_private *priv = netdev_priv(dev);
984 int i, j, last_ret, last_fn;
988 u_char __iomem *ramBase = NULL;
990 DEBUG(0, "netwave_pcmcia_config(0x%p)\n", link);
993 This reads the card's CONFIG tuple to find its configuration
996 tuple.Attributes = 0;
997 tuple.TupleData = (cisdata_t *) buf;
998 tuple.TupleDataMax = 64;
999 tuple.TupleOffset = 0;
1000 tuple.DesiredTuple = CISTPL_CONFIG;
1001 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple));
1002 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple));
1003 CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse));
1004 link->conf.ConfigBase = parse.config.base;
1005 link->conf.Present = parse.config.rmask[0];
1007 /* Configure card */
1008 link->state |= DEV_CONFIG;
1011 * Try allocating IO ports. This tries a few fixed addresses.
1012 * If you want, you can also read the card's config table to
1013 * pick addresses -- see the serial driver for an example.
1015 for (i = j = 0x0; j < 0x400; j += 0x20) {
1016 link->io.BasePort1 = j ^ 0x300;
1017 i = pcmcia_request_io(link->handle, &link->io);
1018 if (i == CS_SUCCESS) break;
1020 if (i != CS_SUCCESS) {
1021 cs_error(link->handle, RequestIO, i);
1026 * Now allocate an interrupt line. Note that this does not
1027 * actually assign a handler to the interrupt.
1029 CS_CHECK(RequestIRQ, pcmcia_request_irq(handle, &link->irq));
1032 * This actually configures the PCMCIA socket -- setting up
1033 * the I/O windows and the interrupt mapping.
1035 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(handle, &link->conf));
1038 * Allocate a 32K memory window. Note that the dev_link_t
1039 * structure provides space for one window handle -- if your
1040 * device needs several windows, you'll need to keep track of
1041 * the handles in your private data structure, dev->priv.
1043 DEBUG(1, "Setting mem speed of %d\n", mem_speed);
1045 req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_CM|WIN_ENABLE;
1046 req.Base = 0; req.Size = 0x8000;
1047 req.AccessSpeed = mem_speed;
1048 CS_CHECK(RequestWindow, pcmcia_request_window(&link->handle, &req, &link->win));
1049 mem.CardOffset = 0x20000; mem.Page = 0;
1050 CS_CHECK(MapMemPage, pcmcia_map_mem_page(link->win, &mem));
1052 /* Store base address of the common window frame */
1053 ramBase = ioremap(req.Base, 0x8000);
1054 priv->ramBase = ramBase;
1056 dev->irq = link->irq.AssignedIRQ;
1057 dev->base_addr = link->io.BasePort1;
1058 SET_NETDEV_DEV(dev, &handle_to_dev(handle));
1060 if (register_netdev(dev) != 0) {
1061 printk(KERN_DEBUG "netwave_cs: register_netdev() failed\n");
1065 strcpy(priv->node.dev_name, dev->name);
1066 link->dev = &priv->node;
1067 link->state &= ~DEV_CONFIG_PENDING;
1069 /* Reset card before reading physical address */
1070 netwave_doreset(dev->base_addr, ramBase);
1072 /* Read the ethernet address and fill in the Netwave registers. */
1073 for (i = 0; i < 6; i++)
1074 dev->dev_addr[i] = readb(ramBase + NETWAVE_EREG_PA + i);
1076 printk(KERN_INFO "%s: Netwave: port %#3lx, irq %d, mem %lx id "
1077 "%c%c, hw_addr ", dev->name, dev->base_addr, dev->irq,
1078 (u_long) ramBase, (int) readb(ramBase+NETWAVE_EREG_NI),
1079 (int) readb(ramBase+NETWAVE_EREG_NI+1));
1080 for (i = 0; i < 6; i++)
1081 printk("%02X%s", dev->dev_addr[i], ((i<5) ? ":" : "\n"));
1083 /* get revision words */
1084 printk(KERN_DEBUG "Netwave_reset: revision %04x %04x\n",
1085 get_uint16(ramBase + NETWAVE_EREG_ARW),
1086 get_uint16(ramBase + NETWAVE_EREG_ARW+2));
1090 cs_error(link->handle, last_fn, last_ret);
1092 netwave_release(link);
1093 } /* netwave_pcmcia_config */
1096 * Function netwave_release (arg)
1098 * After a card is removed, netwave_release() will unregister the net
1099 * device, and release the PCMCIA configuration. If the device is
1100 * still open, this will be postponed until it is closed.
1102 static void netwave_release(dev_link_t *link)
1104 struct net_device *dev = link->priv;
1105 netwave_private *priv = netdev_priv(dev);
1107 DEBUG(0, "netwave_release(0x%p)\n", link);
1109 /* Don't bother checking to see if these succeed or not */
1111 iounmap(priv->ramBase);
1112 pcmcia_release_window(link->win);
1114 pcmcia_release_configuration(link->handle);
1115 pcmcia_release_io(link->handle, &link->io);
1116 pcmcia_release_irq(link->handle, &link->irq);
1118 link->state &= ~DEV_CONFIG;
1122 * Function netwave_event (event, priority, args)
1124 * The card status event handler. Mostly, this schedules other
1125 * stuff to run after an event is received. A CARD_REMOVAL event
1126 * also sets some flags to discourage the net drivers from trying
1127 * to talk to the card any more.
1129 * When a CARD_REMOVAL event is received, we immediately set a flag
1130 * to block future accesses to this device. All the functions that
1131 * actually access the device should check this flag to make sure
1132 * the card is still present.
1135 static int netwave_event(event_t event, int priority,
1136 event_callback_args_t *args)
1138 dev_link_t *link = args->client_data;
1139 struct net_device *dev = link->priv;
1141 DEBUG(1, "netwave_event(0x%06x)\n", event);
1144 case CS_EVENT_REGISTRATION_COMPLETE:
1145 DEBUG(0, "netwave_cs: registration complete\n");
1148 case CS_EVENT_CARD_REMOVAL:
1149 link->state &= ~DEV_PRESENT;
1150 if (link->state & DEV_CONFIG) {
1151 netif_device_detach(dev);
1152 netwave_release(link);
1155 case CS_EVENT_CARD_INSERTION:
1156 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
1157 netwave_pcmcia_config( link);
1159 case CS_EVENT_PM_SUSPEND:
1160 link->state |= DEV_SUSPEND;
1161 /* Fall through... */
1162 case CS_EVENT_RESET_PHYSICAL:
1163 if (link->state & DEV_CONFIG) {
1165 netif_device_detach(dev);
1166 pcmcia_release_configuration(link->handle);
1169 case CS_EVENT_PM_RESUME:
1170 link->state &= ~DEV_SUSPEND;
1171 /* Fall through... */
1172 case CS_EVENT_CARD_RESET:
1173 if (link->state & DEV_CONFIG) {
1174 pcmcia_request_configuration(link->handle, &link->conf);
1177 netif_device_attach(dev);
1183 } /* netwave_event */
1186 * Function netwave_doreset (ioBase, ramBase)
1188 * Proper hardware reset of the card.
1190 static void netwave_doreset(kio_addr_t ioBase, u_char __iomem *ramBase)
1194 outb(0x80, ioBase + NETWAVE_REG_PMR);
1195 writeb(0x08, ramBase + NETWAVE_EREG_ASCC); /* Bit 3 is WOC */
1196 outb(0x0, ioBase + NETWAVE_REG_PMR); /* release reset */
1200 * Function netwave_reset (dev)
1202 * Reset and restore all of the netwave registers
1204 static void netwave_reset(struct net_device *dev) {
1206 netwave_private *priv = netdev_priv(dev);
1207 u_char __iomem *ramBase = priv->ramBase;
1208 kio_addr_t iobase = dev->base_addr;
1210 DEBUG(0, "netwave_reset: Done with hardware reset\n");
1212 priv->timeoutCounter = 0;
1215 netwave_doreset(iobase, ramBase);
1216 printk(KERN_DEBUG "netwave_reset: Done with hardware reset\n");
1218 /* Write a NOP to check the card */
1220 writeb(NETWAVE_CMD_NOP, ramBase + NETWAVE_EREG_CB + 0);
1221 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 1);
1223 /* Set receive conf */
1225 writeb(NETWAVE_CMD_SRC, ramBase + NETWAVE_EREG_CB + 0);
1226 writeb(rxConfRxEna + rxConfBcast, ramBase + NETWAVE_EREG_CB + 1);
1227 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 2);
1229 /* Set transmit conf */
1231 writeb(NETWAVE_CMD_STC, ramBase + NETWAVE_EREG_CB + 0);
1232 writeb(txConfTxEna, ramBase + NETWAVE_EREG_CB + 1);
1233 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 2);
1235 /* Now set the MU Domain */
1236 printk(KERN_DEBUG "Setting domain to 0x%x%02x\n", (domain >> 8) & 0x01, domain & 0xff);
1238 writeb(NETWAVE_CMD_SMD, ramBase + NETWAVE_EREG_CB + 0);
1239 writeb(domain & 0xff, ramBase + NETWAVE_EREG_CB + 1);
1240 writeb((domain>>8) & 0x01, ramBase + NETWAVE_EREG_CB + 2);
1241 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 3);
1243 /* Set scramble key */
1244 printk(KERN_DEBUG "Setting scramble key to 0x%x\n", scramble_key);
1246 writeb(NETWAVE_CMD_SSK, ramBase + NETWAVE_EREG_CB + 0);
1247 writeb(scramble_key & 0xff, ramBase + NETWAVE_EREG_CB + 1);
1248 writeb((scramble_key>>8) & 0xff, ramBase + NETWAVE_EREG_CB + 2);
1249 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 3);
1251 /* Enable interrupts, bit 4 high to keep unused
1252 * source from interrupting us, bit 2 high to
1253 * set interrupt enable, 567 to enable TxDN,
1257 outb(imrConfIENA+imrConfRFU1, iobase + NETWAVE_REG_IMR);
1259 /* Hent 4 bytes fra 0x170. Skal vaere 0a,29,88,36
1261 * skriv 80 til d000:3688
1262 * sjekk om det ble 80
1265 /* Enable Receiver */
1267 writeb(NETWAVE_CMD_ER, ramBase + NETWAVE_EREG_CB + 0);
1268 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 1);
1270 /* Set the IENA bit in COR */
1272 outb(corConfIENA + corConfLVLREQ, iobase + NETWAVE_REG_COR);
1276 * Function netwave_hw_xmit (data, len, dev)
1278 static int netwave_hw_xmit(unsigned char* data, int len,
1279 struct net_device* dev) {
1280 unsigned long flags;
1281 unsigned int TxFreeList,
1287 netwave_private *priv = netdev_priv(dev);
1288 u_char __iomem * ramBase = priv->ramBase;
1289 kio_addr_t iobase = dev->base_addr;
1291 /* Disable interrupts & save flags */
1292 spin_lock_irqsave(&priv->spinlock, flags);
1294 /* Check if there are transmit buffers available */
1296 if ((inb(iobase+NETWAVE_REG_ASR) & NETWAVE_ASR_TXBA) == 0) {
1297 /* No buffers available */
1298 printk(KERN_DEBUG "netwave_hw_xmit: %s - no xmit buffers available.\n",
1300 spin_unlock_irqrestore(&priv->spinlock, flags);
1304 priv->stats.tx_bytes += len;
1306 DEBUG(3, "Transmitting with SPCQ %x SPU %x LIF %x ISPLQ %x\n",
1307 readb(ramBase + NETWAVE_EREG_SPCQ),
1308 readb(ramBase + NETWAVE_EREG_SPU),
1309 readb(ramBase + NETWAVE_EREG_LIF),
1310 readb(ramBase + NETWAVE_EREG_ISPLQ));
1312 /* Now try to insert it into the adapters free memory */
1314 TxFreeList = get_uint16(ramBase + NETWAVE_EREG_TDP);
1315 MaxData = get_uint16(ramBase + NETWAVE_EREG_TDP+2);
1316 DataOffset = get_uint16(ramBase + NETWAVE_EREG_TDP+4);
1318 DEBUG(3, "TxFreeList %x, MaxData %x, DataOffset %x\n",
1319 TxFreeList, MaxData, DataOffset);
1321 /* Copy packet to the adapter fragment buffers */
1322 curBuff = TxFreeList;
1324 while (tmpcount < len) {
1325 int tmplen = len - tmpcount;
1326 copy_to_pc(ramBase + curBuff + DataOffset, data + tmpcount,
1327 (tmplen < MaxData) ? tmplen : MaxData);
1328 tmpcount += MaxData;
1330 /* Advance to next buffer */
1331 curBuff = get_uint16(ramBase + curBuff);
1334 /* Now issue transmit list */
1336 writeb(NETWAVE_CMD_TL, ramBase + NETWAVE_EREG_CB + 0);
1337 writeb(len & 0xff, ramBase + NETWAVE_EREG_CB + 1);
1338 writeb((len>>8) & 0xff, ramBase + NETWAVE_EREG_CB + 2);
1339 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 3);
1341 spin_unlock_irqrestore(&priv->spinlock, flags);
1345 static int netwave_start_xmit(struct sk_buff *skb, struct net_device *dev) {
1346 /* This flag indicate that the hardware can't perform a transmission.
1347 * Theoritically, NET3 check it before sending a packet to the driver,
1348 * but in fact it never do that and pool continuously.
1349 * As the watchdog will abort too long transmissions, we are quite safe...
1352 netif_stop_queue(dev);
1355 short length = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
1356 unsigned char* buf = skb->data;
1358 if (netwave_hw_xmit( buf, length, dev) == 1) {
1359 /* Some error, let's make them call us another time? */
1360 netif_start_queue(dev);
1362 dev->trans_start = jiffies;
1367 } /* netwave_start_xmit */
1370 * Function netwave_interrupt (irq, dev_id, regs)
1372 * This function is the interrupt handler for the Netwave card. This
1373 * routine will be called whenever:
1374 * 1. A packet is received.
1375 * 2. A packet has successfully been transferred and the unit is
1376 * ready to transmit another packet.
1377 * 3. A command has completed execution.
1379 static irqreturn_t netwave_interrupt(int irq, void* dev_id, struct pt_regs *regs)
1382 u_char __iomem *ramBase;
1383 struct net_device *dev = (struct net_device *)dev_id;
1384 struct netwave_private *priv = netdev_priv(dev);
1385 dev_link_t *link = &priv->link;
1388 if (!netif_device_present(dev))
1391 iobase = dev->base_addr;
1392 ramBase = priv->ramBase;
1394 /* Now find what caused the interrupt, check while interrupts ready */
1395 for (i = 0; i < 10; i++) {
1399 if (!(inb(iobase+NETWAVE_REG_CCSR) & 0x02))
1400 break; /* None of the interrupt sources asserted (normal exit) */
1402 status = inb(iobase + NETWAVE_REG_ASR);
1404 if (!DEV_OK(link)) {
1405 DEBUG(1, "netwave_interrupt: Interrupt with status 0x%x "
1406 "from removed or suspended card!\n", status);
1411 if (status & 0x80) {
1413 /* wait_WOC(iobase); */
1414 /* RxRdy cannot be reset directly by the host */
1417 if (status & 0x40) {
1420 rser = readb(ramBase + NETWAVE_EREG_RSER);
1423 ++priv->stats.rx_dropped;
1424 ++priv->stats.rx_crc_errors;
1427 ++priv->stats.rx_frame_errors;
1429 /* Clear the RxErr bit in RSER. RSER+4 is the
1430 * write part. Also clear the RxCRC (0x04) and
1431 * RxBig (0x02) bits if present */
1433 writeb(0x40 | (rser & 0x06), ramBase + NETWAVE_EREG_RSER + 4);
1435 /* Write bit 6 high to ASCC to clear RxErr in ASR,
1436 * WOC must be set first!
1439 writeb(0x40, ramBase + NETWAVE_EREG_ASCC);
1441 /* Remember to count up priv->stats on error packets */
1442 ++priv->stats.rx_errors;
1445 if (status & 0x20) {
1448 txStatus = readb(ramBase + NETWAVE_EREG_TSER);
1449 DEBUG(3, "Transmit done. TSER = %x id %x\n",
1450 txStatus, readb(ramBase + NETWAVE_EREG_TSER + 1));
1452 if (txStatus & 0x20) {
1453 /* Transmitting was okay, clear bits */
1455 writeb(0x2f, ramBase + NETWAVE_EREG_TSER + 4);
1456 ++priv->stats.tx_packets;
1459 if (txStatus & 0xd0) {
1460 if (txStatus & 0x80) {
1461 ++priv->stats.collisions; /* Because of /proc/net/dev*/
1462 /* ++priv->stats.tx_aborted_errors; */
1463 /* printk("Collision. %ld\n", jiffies - dev->trans_start); */
1465 if (txStatus & 0x40)
1466 ++priv->stats.tx_carrier_errors;
1467 /* 0x80 TxGU Transmit giveup - nine times and no luck
1468 * 0x40 TxNOAP No access point. Discarded packet.
1469 * 0x10 TxErr Transmit error. Always set when
1470 * TxGU and TxNOAP is set. (Those are the only ones
1473 DEBUG(3, "netwave_interrupt: TxDN with error status %x\n",
1476 /* Clear out TxGU, TxNOAP, TxErr and TxTrys */
1478 writeb(0xdf & txStatus, ramBase+NETWAVE_EREG_TSER+4);
1479 ++priv->stats.tx_errors;
1481 DEBUG(3, "New status is TSER %x ASR %x\n",
1482 readb(ramBase + NETWAVE_EREG_TSER),
1483 inb(iobase + NETWAVE_REG_ASR));
1485 netif_wake_queue(dev);
1487 /* TxBA, this would trigger on all error packets received */
1488 /* if (status & 0x01) {
1489 DEBUG(4, "Transmit buffers available, %x\n", status);
1493 /* Handled if we looped at least one time - Jean II */
1494 return IRQ_RETVAL(i);
1495 } /* netwave_interrupt */
1498 * Function netwave_watchdog (a)
1500 * Watchdog : when we start a transmission, we set a timer in the
1501 * kernel. If the transmission complete, this timer is disabled. If
1502 * it expire, we reset the card.
1505 static void netwave_watchdog(struct net_device *dev) {
1507 DEBUG(1, "%s: netwave_watchdog: watchdog timer expired\n", dev->name);
1509 dev->trans_start = jiffies;
1510 netif_wake_queue(dev);
1511 } /* netwave_watchdog */
1513 static struct net_device_stats *netwave_get_stats(struct net_device *dev) {
1514 netwave_private *priv = netdev_priv(dev);
1518 DEBUG(2, "netwave: SPCQ %x SPU %x LIF %x ISPLQ %x MHS %x rxtx %x"
1519 " %x tx %x %x %x %x\n",
1520 readb(priv->ramBase + NETWAVE_EREG_SPCQ),
1521 readb(priv->ramBase + NETWAVE_EREG_SPU),
1522 readb(priv->ramBase + NETWAVE_EREG_LIF),
1523 readb(priv->ramBase + NETWAVE_EREG_ISPLQ),
1524 readb(priv->ramBase + NETWAVE_EREG_MHS),
1525 readb(priv->ramBase + NETWAVE_EREG_EC + 0xe),
1526 readb(priv->ramBase + NETWAVE_EREG_EC + 0xf),
1527 readb(priv->ramBase + NETWAVE_EREG_EC + 0x18),
1528 readb(priv->ramBase + NETWAVE_EREG_EC + 0x19),
1529 readb(priv->ramBase + NETWAVE_EREG_EC + 0x1a),
1530 readb(priv->ramBase + NETWAVE_EREG_EC + 0x1b));
1532 return &priv->stats;
1535 static void update_stats(struct net_device *dev) {
1536 //unsigned long flags;
1537 /* netwave_private *priv = netdev_priv(dev); */
1539 //spin_lock_irqsave(&priv->spinlock, flags);
1541 /* priv->stats.rx_packets = readb(priv->ramBase + 0x18e);
1542 priv->stats.tx_packets = readb(priv->ramBase + 0x18f); */
1544 //spin_unlock_irqrestore(&priv->spinlock, flags);
1547 static int netwave_rx(struct net_device *dev)
1549 netwave_private *priv = netdev_priv(dev);
1550 u_char __iomem *ramBase = priv->ramBase;
1551 kio_addr_t iobase = dev->base_addr;
1553 struct sk_buff *skb = NULL;
1554 unsigned int curBuffer,
1558 int dataCount, dataOffset;
1562 DEBUG(3, "xinw_rx: Receiving ... \n");
1564 /* Receive max 10 packets for now. */
1565 for (i = 0; i < 10; i++) {
1568 rxStatus = readb(ramBase + NETWAVE_EREG_RSER);
1569 if ( !( rxStatus & 0x80)) /* No more packets */
1572 /* Check if multicast/broadcast or other */
1573 /* multicast = (rxStatus & 0x20); */
1575 /* The receive list pointer and length of the packet */
1577 rcvLen = get_int16( ramBase + NETWAVE_EREG_RDP);
1578 rcvList = get_uint16( ramBase + NETWAVE_EREG_RDP + 2);
1581 printk(KERN_DEBUG "netwave_rx: Receive packet with len %d\n",
1586 skb = dev_alloc_skb(rcvLen+5);
1588 DEBUG(1, "netwave_rx: Could not allocate an sk_buff of "
1589 "length %d\n", rcvLen);
1590 ++priv->stats.rx_dropped;
1591 /* Tell the adapter to skip the packet */
1593 writeb(NETWAVE_CMD_SRP, ramBase + NETWAVE_EREG_CB + 0);
1594 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 1);
1598 skb_reserve( skb, 2); /* Align IP on 16 byte */
1599 skb_put( skb, rcvLen);
1602 /* Copy packet fragments to the skb data area */
1603 ptr = (u_char*) skb->data;
1604 curBuffer = rcvList;
1606 while ( tmpcount < rcvLen) {
1607 /* Get length and offset of current buffer */
1608 dataCount = get_uint16( ramBase+curBuffer+2);
1609 dataOffset = get_uint16( ramBase+curBuffer+4);
1611 copy_from_pc( ptr + tmpcount,
1612 ramBase+curBuffer+dataOffset, dataCount);
1614 tmpcount += dataCount;
1616 /* Point to next buffer */
1617 curBuffer = get_uint16(ramBase + curBuffer);
1620 skb->protocol = eth_type_trans(skb,dev);
1621 /* Queue packet for network layer */
1624 dev->last_rx = jiffies;
1625 priv->stats.rx_packets++;
1626 priv->stats.rx_bytes += rcvLen;
1628 /* Got the packet, tell the adapter to skip it */
1630 writeb(NETWAVE_CMD_SRP, ramBase + NETWAVE_EREG_CB + 0);
1631 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 1);
1632 DEBUG(3, "Packet reception ok\n");
1637 static int netwave_open(struct net_device *dev) {
1638 netwave_private *priv = netdev_priv(dev);
1639 dev_link_t *link = &priv->link;
1641 DEBUG(1, "netwave_open: starting.\n");
1648 netif_start_queue(dev);
1654 static int netwave_close(struct net_device *dev) {
1655 netwave_private *priv = netdev_priv(dev);
1656 dev_link_t *link = &priv->link;
1658 DEBUG(1, "netwave_close: finishing.\n");
1661 netif_stop_queue(dev);
1666 static struct pcmcia_device_id netwave_ids[] = {
1667 PCMCIA_DEVICE_PROD_ID12("Xircom", "CreditCard Netwave", 0x2e3ee845, 0x54e28a28),
1670 MODULE_DEVICE_TABLE(pcmcia, netwave_ids);
1672 static struct pcmcia_driver netwave_driver = {
1673 .owner = THIS_MODULE,
1675 .name = "netwave_cs",
1677 .attach = netwave_attach,
1678 .event = netwave_event,
1679 .detach = netwave_detach,
1680 .id_table = netwave_ids,
1683 static int __init init_netwave_cs(void)
1685 return pcmcia_register_driver(&netwave_driver);
1688 static void __exit exit_netwave_cs(void)
1690 pcmcia_unregister_driver(&netwave_driver);
1691 BUG_ON(dev_list != NULL);
1694 module_init(init_netwave_cs);
1695 module_exit(exit_netwave_cs);
1697 /* Set or clear the multicast filter for this adaptor.
1698 num_addrs == -1 Promiscuous mode, receive all packets
1699 num_addrs == 0 Normal mode, clear multicast list
1700 num_addrs > 0 Multicast mode, receive normal and MC packets, and do
1701 best-effort filtering.
1703 static void set_multicast_list(struct net_device *dev)
1705 kio_addr_t iobase = dev->base_addr;
1706 netwave_private *priv = netdev_priv(dev);
1707 u_char __iomem * ramBase = priv->ramBase;
1713 if (old != dev->mc_count) {
1714 old = dev->mc_count;
1715 DEBUG(0, "%s: setting Rx mode to %d addresses.\n",
1716 dev->name, dev->mc_count);
1721 if (dev->mc_count || (dev->flags & IFF_ALLMULTI)) {
1722 /* Multicast Mode */
1723 rcvMode = rxConfRxEna + rxConfAMP + rxConfBcast;
1724 } else if (dev->flags & IFF_PROMISC) {
1725 /* Promiscous mode */
1726 rcvMode = rxConfRxEna + rxConfPro + rxConfAMP + rxConfBcast;
1729 rcvMode = rxConfRxEna + rxConfBcast;
1732 /* printk("netwave set_multicast_list: rcvMode to %x\n", rcvMode);*/
1733 /* Now set receive mode */
1735 writeb(NETWAVE_CMD_SRC, ramBase + NETWAVE_EREG_CB + 0);
1736 writeb(rcvMode, ramBase + NETWAVE_EREG_CB + 1);
1737 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 2);
1739 MODULE_LICENSE("GPL");