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_PARM(pc_debug, "i");
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 /* Bit map of interrupts to choose from */
194 /* This means pick from 15, 14, 12, 11, 10, 9, 7, 5, 4, and 3 */
195 static u_int irq_mask = 0xdeb8;
196 static int irq_list[4] = { -1 };
198 MODULE_PARM(domain, "i");
199 MODULE_PARM(scramble_key, "i");
200 MODULE_PARM(mem_speed, "i");
201 MODULE_PARM(irq_mask, "i");
202 MODULE_PARM(irq_list, "1-4i");
204 /*====================================================================*/
206 /* PCMCIA (Card Services) related functions */
207 static void netwave_release(dev_link_t *link); /* Card removal */
208 static int netwave_event(event_t event, int priority,
209 event_callback_args_t *args);
210 static void netwave_pcmcia_config(dev_link_t *arg); /* Runs after card
212 static dev_link_t *netwave_attach(void); /* Create instance */
213 static void netwave_detach(dev_link_t *); /* Destroy instance */
215 /* Hardware configuration */
216 static void netwave_doreset(ioaddr_t iobase, u_char* ramBase);
217 static void netwave_reset(struct net_device *dev);
219 /* Misc device stuff */
220 static int netwave_open(struct net_device *dev); /* Open the device */
221 static int netwave_close(struct net_device *dev); /* Close the device */
223 /* Packet transmission and Packet reception */
224 static int netwave_start_xmit( struct sk_buff *skb, struct net_device *dev);
225 static int netwave_rx( struct net_device *dev);
227 /* Interrupt routines */
228 static irqreturn_t netwave_interrupt(int irq, void *dev_id, struct pt_regs *regs);
229 static void netwave_watchdog(struct net_device *);
232 static void update_stats(struct net_device *dev);
233 static struct net_device_stats *netwave_get_stats(struct net_device *dev);
235 /* Wireless extensions */
237 static struct iw_statistics* netwave_get_wireless_stats(struct net_device *dev);
239 static int netwave_ioctl(struct net_device *, struct ifreq *, int);
241 static void set_multicast_list(struct net_device *dev);
244 A linked list of "instances" of the skeleton device. Each actual
245 PCMCIA card corresponds to one device instance, and is described
246 by one dev_link_t structure (defined in ds.h).
248 You may not want to use a linked list for this -- for example, the
249 memory card driver uses an array of dev_link_t pointers, where minor
250 device numbers are used to derive the corresponding array index.
252 static dev_link_t *dev_list;
255 A dev_link_t structure has fields for most things that are needed
256 to keep track of a socket, but there will usually be some device
257 specific information that also needs to be kept track of. The
258 'priv' pointer in a dev_link_t structure can be used to point to
259 a device-specific private data structure, like this.
261 A driver needs to provide a dev_node_t structure for each device
262 on a card. In some cases, there is only one device per card (for
263 example, ethernet cards, modems). In other cases, there may be
264 many actual or logical devices (SCSI adapters, memory cards with
265 multiple partitions). The dev_node_t structures need to be kept
266 in a linked list starting at the 'dev' field of a dev_link_t
267 structure. We allocate them in the card's private data structure,
268 because they generally can't be allocated dynamically.
271 #if WIRELESS_EXT <= 12
272 /* Wireless extensions backward compatibility */
274 /* Part of iw_handler prototype we need */
275 struct iw_request_info
277 __u16 cmd; /* Wireless Extension command */
278 __u16 flags; /* More to come ;-) */
281 /* Wireless Extension Backward compatibility - Jean II
282 * If the new wireless device private ioctl range is not defined,
283 * default to standard device private ioctl range */
284 #ifndef SIOCIWFIRSTPRIV
285 #define SIOCIWFIRSTPRIV SIOCDEVPRIVATE
286 #endif /* SIOCIWFIRSTPRIV */
288 #else /* WIRELESS_EXT <= 12 */
289 static const struct iw_handler_def netwave_handler_def;
290 #endif /* WIRELESS_EXT <= 12 */
292 #define SIOCGIPSNAP SIOCIWFIRSTPRIV + 1 /* Site Survey Snapshot */
296 typedef struct net_addr {
302 u_char struct_revision;
303 u_char roaming_state;
305 u_char sp_existsFlag;
306 u_char sp_link_quality;
307 u_char sp_max_link_quality;
308 u_char linkQualityGoodFairBoundary;
309 u_char linkQualityFairPoorBoundary;
310 u_char sp_utilization;
312 u_char sp_hotheadcount;
313 u_char roaming_condition;
317 net_addr nearByAccessPoints[MAX_ESA];
320 typedef struct netwave_private {
322 spinlock_t spinlock; /* Serialize access to the hardware (SMP) */
327 struct timer_list watchdog; /* To avoid blocking state */
328 struct site_survey nss;
329 struct net_device_stats stats;
331 struct iw_statistics iw_stats; /* Wireless stats */
336 static struct net_device_stats *netwave_get_stats(struct net_device *dev);
340 * The Netwave card is little-endian, so won't work for big endian
343 static inline unsigned short get_uint16(u_char* staddr)
345 return readw(staddr); /* Return only 16 bits */
348 static inline short get_int16(u_char* staddr)
350 return readw(staddr);
354 * Wait until the WOC (Write Operation Complete) bit in the
355 * ASR (Adapter Status Register) is asserted.
356 * This should have aborted if it takes too long time.
358 static inline void wait_WOC(unsigned int iobase)
361 while ((inb(iobase + NETWAVE_REG_ASR) & 0x8) != 0x8) ;
365 static void netwave_snapshot(netwave_private *priv, u_char *ramBase,
367 u_short resultBuffer;
369 /* if time since last snapshot is > 1 sec. (100 jiffies?) then take
370 * new snapshot, else return cached data. This is the recommended rate.
372 if ( jiffies - priv->lastExec > 100) {
373 /* Take site survey snapshot */
374 /*printk( KERN_DEBUG "Taking new snapshot. %ld\n", jiffies -
377 writeb(NETWAVE_CMD_SSS, ramBase + NETWAVE_EREG_CB + 0);
378 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 1);
381 /* Get result and copy to cach */
382 resultBuffer = readw(ramBase + NETWAVE_EREG_CRBP);
383 copy_from_pc( &priv->nss, ramBase+resultBuffer,
384 sizeof(struct site_survey));
391 * Function netwave_get_wireless_stats (dev)
393 * Wireless extensions statistics
396 static struct iw_statistics *netwave_get_wireless_stats(struct net_device *dev)
399 ioaddr_t iobase = dev->base_addr;
400 netwave_private *priv = (netwave_private *) dev->priv;
401 u_char *ramBase = priv->ramBase;
402 struct iw_statistics* wstats;
404 wstats = &priv->iw_stats;
406 spin_lock_irqsave(&priv->spinlock, flags);
408 netwave_snapshot( priv, ramBase, iobase);
410 wstats->status = priv->nss.roaming_state;
411 wstats->qual.qual = readb( ramBase + NETWAVE_EREG_SPCQ);
412 wstats->qual.level = readb( ramBase + NETWAVE_EREG_ISPLQ);
413 wstats->qual.noise = readb( ramBase + NETWAVE_EREG_SPU) & 0x3f;
414 wstats->discard.nwid = 0L;
415 wstats->discard.code = 0L;
416 wstats->discard.misc = 0L;
418 spin_unlock_irqrestore(&priv->spinlock, flags);
420 return &priv->iw_stats;
425 * Function netwave_attach (void)
427 * Creates an "instance" of the driver, allocating local data
428 * structures for one device. The device is registered with Card
431 * The dev_link structure is initialized, but we don't actually
432 * configure the card at this point -- we wait until we receive a
433 * card insertion event.
435 static dev_link_t *netwave_attach(void)
437 client_reg_t client_reg;
439 struct net_device *dev;
440 netwave_private *priv;
443 DEBUG(0, "netwave_attach()\n");
445 /* Initialize the dev_link_t structure */
446 dev = alloc_etherdev(sizeof(netwave_private));
453 /* The io structure describes IO port mapping */
454 link->io.NumPorts1 = 16;
455 link->io.Attributes1 = IO_DATA_PATH_WIDTH_16;
456 /* link->io.NumPorts2 = 16;
457 link->io.Attributes2 = IO_DATA_PATH_WIDTH_16; */
458 link->io.IOAddrLines = 5;
460 /* Interrupt setup */
461 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT;
462 link->irq.IRQInfo1 = IRQ_INFO2_VALID|IRQ_LEVEL_ID;
463 if (irq_list[0] == -1)
464 link->irq.IRQInfo2 = irq_mask;
466 for (i = 0; i < 4; i++)
467 link->irq.IRQInfo2 |= 1 << irq_list[i];
468 link->irq.Handler = &netwave_interrupt;
470 /* General socket configuration */
471 link->conf.Attributes = CONF_ENABLE_IRQ;
473 link->conf.IntType = INT_MEMORY_AND_IO;
474 link->conf.ConfigIndex = 1;
475 link->conf.Present = PRESENT_OPTION;
477 /* Netwave private struct init. link/dev/node already taken care of,
478 * other stuff zero'd - Jean II */
479 spin_lock_init(&priv->spinlock);
481 /* Netwave specific entries in the device structure */
482 SET_MODULE_OWNER(dev);
483 dev->hard_start_xmit = &netwave_start_xmit;
484 dev->get_stats = &netwave_get_stats;
485 dev->set_multicast_list = &set_multicast_list;
486 /* wireless extensions */
488 dev->get_wireless_stats = &netwave_get_wireless_stats;
489 #if WIRELESS_EXT > 12
490 dev->wireless_handlers = (struct iw_handler_def *)&netwave_handler_def;
491 #endif /* WIRELESS_EXT > 12 */
492 #endif /* WIRELESS_EXT */
493 dev->do_ioctl = &netwave_ioctl;
495 dev->tx_timeout = &netwave_watchdog;
496 dev->watchdog_timeo = TX_TIMEOUT;
498 dev->open = &netwave_open;
499 dev->stop = &netwave_close;
500 link->irq.Instance = dev;
502 /* Register with Card Services */
503 link->next = dev_list;
505 client_reg.dev_info = &dev_info;
506 client_reg.Attributes = INFO_IO_CLIENT | INFO_CARD_SHARE;
507 client_reg.EventMask =
508 CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL |
509 CS_EVENT_RESET_PHYSICAL | CS_EVENT_CARD_RESET |
510 CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME;
511 client_reg.event_handler = &netwave_event;
512 client_reg.Version = 0x0210;
513 client_reg.event_callback_args.client_data = link;
514 ret = pcmcia_register_client(&link->handle, &client_reg);
516 cs_error(link->handle, RegisterClient, ret);
517 netwave_detach(link);
522 } /* netwave_attach */
525 * Function netwave_detach (link)
527 * This deletes a driver "instance". The device is de-registered
528 * with Card Services. If it has been released, all local data
529 * structures are freed. Otherwise, the structures will be freed
530 * when the device is released.
532 static void netwave_detach(dev_link_t *link)
534 struct net_device *dev = link->priv;
537 DEBUG(0, "netwave_detach(0x%p)\n", link);
540 If the device is currently configured and active, we won't
541 actually delete it yet. Instead, it is marked so that when
542 the release() function is called, that will trigger a proper
545 if (link->state & DEV_CONFIG)
546 netwave_release(link);
548 /* Break the link with Card Services */
550 pcmcia_deregister_client(link->handle);
552 /* Locate device structure */
553 for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next)
554 if (*linkp == link) break;
557 DEBUG(1, "netwave_cs: detach fail, '%s' not in list\n",
558 link->dev->dev_name);
562 /* Unlink device structure, free pieces */
565 unregister_netdev(dev);
568 } /* netwave_detach */
571 * Wireless Handler : get protocol name
573 static int netwave_get_name(struct net_device *dev,
574 struct iw_request_info *info,
575 union iwreq_data *wrqu,
578 strcpy(wrqu->name, "Netwave");
583 * Wireless Handler : set Network ID
585 static int netwave_set_nwid(struct net_device *dev,
586 struct iw_request_info *info,
587 union iwreq_data *wrqu,
591 ioaddr_t iobase = dev->base_addr;
592 netwave_private *priv = (netwave_private *) dev->priv;
593 u_char *ramBase = priv->ramBase;
595 /* Disable interrupts & save flags */
596 spin_lock_irqsave(&priv->spinlock, flags);
599 if(!wrqu->nwid.disabled) {
600 domain = wrqu->nwid.value;
601 #else /* WIRELESS_EXT > 8 */
603 domain = wrqu->nwid.nwid;
604 #endif /* WIRELESS_EXT > 8 */
605 printk( KERN_DEBUG "Setting domain to 0x%x%02x\n",
606 (domain >> 8) & 0x01, domain & 0xff);
608 writeb(NETWAVE_CMD_SMD, ramBase + NETWAVE_EREG_CB + 0);
609 writeb( domain & 0xff, ramBase + NETWAVE_EREG_CB + 1);
610 writeb((domain >>8 ) & 0x01,ramBase + NETWAVE_EREG_CB+2);
611 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 3);
614 /* ReEnable interrupts & restore flags */
615 spin_unlock_irqrestore(&priv->spinlock, flags);
621 * Wireless Handler : get Network ID
623 static int netwave_get_nwid(struct net_device *dev,
624 struct iw_request_info *info,
625 union iwreq_data *wrqu,
629 wrqu->nwid.value = domain;
630 wrqu->nwid.disabled = 0;
631 wrqu->nwid.fixed = 1;
632 #else /* WIRELESS_EXT > 8 */
633 wrqu->nwid.nwid = domain;
635 #endif /* WIRELESS_EXT > 8 */
641 * Wireless Handler : set scramble key
643 static int netwave_set_scramble(struct net_device *dev,
644 struct iw_request_info *info,
645 union iwreq_data *wrqu,
649 ioaddr_t iobase = dev->base_addr;
650 netwave_private *priv = (netwave_private *) dev->priv;
651 u_char *ramBase = priv->ramBase;
653 /* Disable interrupts & save flags */
654 spin_lock_irqsave(&priv->spinlock, flags);
656 scramble_key = (key[0] << 8) | key[1];
658 writeb(NETWAVE_CMD_SSK, ramBase + NETWAVE_EREG_CB + 0);
659 writeb(scramble_key & 0xff, ramBase + NETWAVE_EREG_CB + 1);
660 writeb((scramble_key>>8) & 0xff, ramBase + NETWAVE_EREG_CB + 2);
661 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 3);
663 /* ReEnable interrupts & restore flags */
664 spin_unlock_irqrestore(&priv->spinlock, flags);
670 * Wireless Handler : get scramble key
672 static int netwave_get_scramble(struct net_device *dev,
673 struct iw_request_info *info,
674 union iwreq_data *wrqu,
677 key[1] = scramble_key & 0xff;
678 key[0] = (scramble_key>>8) & 0xff;
680 wrqu->encoding.flags = IW_ENCODE_ENABLED;
681 wrqu->encoding.length = 2;
682 #else /* WIRELESS_EXT > 8 */
683 wrqu->encoding.method = 1;
684 #endif /* WIRELESS_EXT > 8 */
691 * Wireless Handler : get mode
693 static int netwave_get_mode(struct net_device *dev,
694 struct iw_request_info *info,
695 union iwreq_data *wrqu,
699 wrqu->mode = IW_MODE_INFRA;
701 wrqu->mode = IW_MODE_ADHOC;
705 #endif /* WIRELESS_EXT > 8 */
708 * Wireless Handler : get range info
710 static int netwave_get_range(struct net_device *dev,
711 struct iw_request_info *info,
712 union iwreq_data *wrqu,
715 struct iw_range *range = (struct iw_range *) extra;
718 /* Set the length (very important for backward compatibility) */
719 wrqu->data.length = sizeof(struct iw_range);
721 /* Set all the info we don't care or don't know about to zero */
722 memset(range, 0, sizeof(struct iw_range));
724 #if WIRELESS_EXT > 10
725 /* Set the Wireless Extension versions */
726 range->we_version_compiled = WIRELESS_EXT;
727 range->we_version_source = 9; /* Nothing for us in v10 and v11 */
728 #endif /* WIRELESS_EXT > 10 */
730 /* Set information in the range struct */
731 range->throughput = 450 * 1000; /* don't argue on this ! */
732 range->min_nwid = 0x0000;
733 range->max_nwid = 0x01FF;
735 range->num_channels = range->num_frequency = 0;
737 range->sensitivity = 0x3F;
738 range->max_qual.qual = 255;
739 range->max_qual.level = 255;
740 range->max_qual.noise = 0;
743 range->num_bitrates = 1;
744 range->bitrate[0] = 1000000; /* 1 Mb/s */
745 #endif /* WIRELESS_EXT > 7 */
748 range->encoding_size[0] = 2; /* 16 bits scrambling */
749 range->num_encoding_sizes = 1;
750 range->max_encoding_tokens = 1; /* Only one key possible */
751 #endif /* WIRELESS_EXT > 8 */
757 * Wireless Private Handler : get snapshot
759 static int netwave_get_snap(struct net_device *dev,
760 struct iw_request_info *info,
761 union iwreq_data *wrqu,
765 ioaddr_t iobase = dev->base_addr;
766 netwave_private *priv = (netwave_private *) dev->priv;
767 u_char *ramBase = priv->ramBase;
769 /* Disable interrupts & save flags */
770 spin_lock_irqsave(&priv->spinlock, flags);
772 /* Take snapshot of environment */
773 netwave_snapshot( priv, ramBase, iobase);
774 wrqu->data.length = priv->nss.length;
775 memcpy(extra, (u_char *) &priv->nss, sizeof( struct site_survey));
777 priv->lastExec = jiffies;
779 /* ReEnable interrupts & restore flags */
780 spin_unlock_irqrestore(&priv->spinlock, flags);
786 * Structures to export the Wireless Handlers
787 * This is the stuff that are treated the wireless extensions (iwconfig)
790 static const struct iw_priv_args netwave_private_args[] = {
791 /*{ cmd, set_args, get_args, name } */
793 IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | sizeof(struct site_survey),
797 #if WIRELESS_EXT > 12
799 static const iw_handler netwave_handler[] =
801 NULL, /* SIOCSIWNAME */
802 netwave_get_name, /* SIOCGIWNAME */
803 netwave_set_nwid, /* SIOCSIWNWID */
804 netwave_get_nwid, /* SIOCGIWNWID */
805 NULL, /* SIOCSIWFREQ */
806 NULL, /* SIOCGIWFREQ */
807 NULL, /* SIOCSIWMODE */
808 netwave_get_mode, /* SIOCGIWMODE */
809 NULL, /* SIOCSIWSENS */
810 NULL, /* SIOCGIWSENS */
811 NULL, /* SIOCSIWRANGE */
812 netwave_get_range, /* SIOCGIWRANGE */
813 NULL, /* SIOCSIWPRIV */
814 NULL, /* SIOCGIWPRIV */
815 NULL, /* SIOCSIWSTATS */
816 NULL, /* SIOCGIWSTATS */
817 NULL, /* SIOCSIWSPY */
818 NULL, /* SIOCGIWSPY */
819 NULL, /* -- hole -- */
820 NULL, /* -- hole -- */
821 NULL, /* SIOCSIWAP */
822 NULL, /* SIOCGIWAP */
823 NULL, /* -- hole -- */
824 NULL, /* SIOCGIWAPLIST */
825 NULL, /* -- hole -- */
826 NULL, /* -- hole -- */
827 NULL, /* SIOCSIWESSID */
828 NULL, /* SIOCGIWESSID */
829 NULL, /* SIOCSIWNICKN */
830 NULL, /* SIOCGIWNICKN */
831 NULL, /* -- hole -- */
832 NULL, /* -- hole -- */
833 NULL, /* SIOCSIWRATE */
834 NULL, /* SIOCGIWRATE */
835 NULL, /* SIOCSIWRTS */
836 NULL, /* SIOCGIWRTS */
837 NULL, /* SIOCSIWFRAG */
838 NULL, /* SIOCGIWFRAG */
839 NULL, /* SIOCSIWTXPOW */
840 NULL, /* SIOCGIWTXPOW */
841 NULL, /* SIOCSIWRETRY */
842 NULL, /* SIOCGIWRETRY */
843 netwave_set_scramble, /* SIOCSIWENCODE */
844 netwave_get_scramble, /* SIOCGIWENCODE */
847 static const iw_handler netwave_private_handler[] =
849 NULL, /* SIOCIWFIRSTPRIV */
850 netwave_get_snap, /* SIOCIWFIRSTPRIV + 1 */
853 static const struct iw_handler_def netwave_handler_def =
855 .num_standard = sizeof(netwave_handler)/sizeof(iw_handler),
856 .num_private = sizeof(netwave_private_handler)/sizeof(iw_handler),
857 .num_private_args = sizeof(netwave_private_args)/sizeof(struct iw_priv_args),
858 .standard = (iw_handler *) netwave_handler,
859 .private = (iw_handler *) netwave_private_handler,
860 .private_args = (struct iw_priv_args *) netwave_private_args,
862 #endif /* WIRELESS_EXT > 12 */
865 * Function netwave_ioctl (dev, rq, cmd)
867 * Perform ioctl : config & info stuff
868 * This is the stuff that are treated the wireless extensions (iwconfig)
871 static int netwave_ioctl(struct net_device *dev, /* ioctl device */
872 struct ifreq *rq, /* Data passed */
873 int cmd) /* Ioctl number */
877 #if WIRELESS_EXT <= 12
878 struct iwreq *wrq = (struct iwreq *) rq;
882 DEBUG(0, "%s: ->netwave_ioctl(cmd=0x%X)\n", dev->name, cmd);
884 /* Look what is the request */
886 /* --------------- WIRELESS EXTENSIONS --------------- */
888 #if WIRELESS_EXT <= 12
890 netwave_get_name(dev, NULL, &(wrq->u), NULL);
893 ret = netwave_set_nwid(dev, NULL, &(wrq->u), NULL);
896 ret = netwave_get_nwid(dev, NULL, &(wrq->u), NULL);
898 #if WIRELESS_EXT > 8 /* Note : The API did change... */
900 /* Get scramble key */
901 if(wrq->u.encoding.pointer != (caddr_t) 0)
904 ret = netwave_get_scramble(dev, NULL, &(wrq->u), key);
905 if(copy_to_user(wrq->u.encoding.pointer, key, 2))
910 /* Set scramble key */
911 if(wrq->u.encoding.pointer != (caddr_t) 0)
914 if(copy_from_user(key, wrq->u.encoding.pointer, 2))
919 ret = netwave_set_scramble(dev, NULL, &(wrq->u), key);
923 /* Mode of operation */
924 ret = netwave_get_mode(dev, NULL, &(wrq->u), NULL);
926 #else /* WIRELESS_EXT > 8 */
928 /* Get scramble key */
929 ret = netwave_get_scramble(dev, NULL, &(wrq->u),
930 (char *) &wrq->u.encoding.code);
933 /* Set scramble key */
934 ret = netwave_set_scramble(dev, NULL, &(wrq->u),
935 (char *) &wrq->u.encoding.code);
937 #endif /* WIRELESS_EXT > 8 */
939 /* Basic checking... */
940 if(wrq->u.data.pointer != (caddr_t) 0) {
941 struct iw_range range;
942 ret = netwave_get_range(dev, NULL, &(wrq->u), (char *) &range);
943 if (copy_to_user(wrq->u.data.pointer, &range,
944 sizeof(struct iw_range)))
949 /* Basic checking... */
950 if(wrq->u.data.pointer != (caddr_t) 0) {
951 /* Set the number of ioctl available */
952 wrq->u.data.length = sizeof(netwave_private_args) / sizeof(netwave_private_args[0]);
954 /* Copy structure to the user buffer */
955 if(copy_to_user(wrq->u.data.pointer,
956 (u_char *) netwave_private_args,
957 sizeof(netwave_private_args)))
962 if(wrq->u.data.pointer != (caddr_t) 0) {
963 char buffer[sizeof( struct site_survey)];
964 ret = netwave_get_snap(dev, NULL, &(wrq->u), buffer);
965 /* Copy structure to the user buffer */
966 if(copy_to_user(wrq->u.data.pointer,
968 sizeof( struct site_survey)))
970 printk(KERN_DEBUG "Bad buffer!\n");
975 #endif /* WIRELESS_EXT <= 12 */
976 #endif /* WIRELESS_EXT */
985 * Function netwave_pcmcia_config (link)
987 * netwave_pcmcia_config() is scheduled to run after a CARD_INSERTION
988 * event is received, to configure the PCMCIA socket, and to make the
989 * device available to the system.
993 #define CS_CHECK(fn, ret) \
994 do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
996 static void netwave_pcmcia_config(dev_link_t *link) {
997 client_handle_t handle = link->handle;
998 struct net_device *dev = link->priv;
999 netwave_private *priv = dev->priv;
1002 int i, j, last_ret, last_fn;
1006 u_char *ramBase = NULL;
1008 DEBUG(0, "netwave_pcmcia_config(0x%p)\n", link);
1011 This reads the card's CONFIG tuple to find its configuration
1014 tuple.Attributes = 0;
1015 tuple.TupleData = (cisdata_t *) buf;
1016 tuple.TupleDataMax = 64;
1017 tuple.TupleOffset = 0;
1018 tuple.DesiredTuple = CISTPL_CONFIG;
1019 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple));
1020 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple));
1021 CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse));
1022 link->conf.ConfigBase = parse.config.base;
1023 link->conf.Present = parse.config.rmask[0];
1025 /* Configure card */
1026 link->state |= DEV_CONFIG;
1029 * Try allocating IO ports. This tries a few fixed addresses.
1030 * If you want, you can also read the card's config table to
1031 * pick addresses -- see the serial driver for an example.
1033 for (i = j = 0x0; j < 0x400; j += 0x20) {
1034 link->io.BasePort1 = j ^ 0x300;
1035 i = pcmcia_request_io(link->handle, &link->io);
1036 if (i == CS_SUCCESS) break;
1038 if (i != CS_SUCCESS) {
1039 cs_error(link->handle, RequestIO, i);
1044 * Now allocate an interrupt line. Note that this does not
1045 * actually assign a handler to the interrupt.
1047 CS_CHECK(RequestIRQ, pcmcia_request_irq(handle, &link->irq));
1050 * This actually configures the PCMCIA socket -- setting up
1051 * the I/O windows and the interrupt mapping.
1053 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(handle, &link->conf));
1056 * Allocate a 32K memory window. Note that the dev_link_t
1057 * structure provides space for one window handle -- if your
1058 * device needs several windows, you'll need to keep track of
1059 * the handles in your private data structure, dev->priv.
1061 DEBUG(1, "Setting mem speed of %d\n", mem_speed);
1063 req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_CM|WIN_ENABLE;
1064 req.Base = 0; req.Size = 0x8000;
1065 req.AccessSpeed = mem_speed;
1066 CS_CHECK(RequestWindow, pcmcia_request_window(&link->handle, &req, &link->win));
1067 mem.CardOffset = 0x20000; mem.Page = 0;
1068 CS_CHECK(MapMemPage, pcmcia_map_mem_page(link->win, &mem));
1070 /* Store base address of the common window frame */
1071 ramBase = ioremap(req.Base, 0x8000);
1072 ((netwave_private*)dev->priv)->ramBase = ramBase;
1074 dev->irq = link->irq.AssignedIRQ;
1075 dev->base_addr = link->io.BasePort1;
1076 if (register_netdev(dev) != 0) {
1077 printk(KERN_DEBUG "netwave_cs: register_netdev() failed\n");
1081 strcpy(priv->node.dev_name, dev->name);
1082 link->dev = &priv->node;
1083 link->state &= ~DEV_CONFIG_PENDING;
1085 /* Reset card before reading physical address */
1086 netwave_doreset(dev->base_addr, ramBase);
1088 /* Read the ethernet address and fill in the Netwave registers. */
1089 for (i = 0; i < 6; i++)
1090 dev->dev_addr[i] = readb(ramBase + NETWAVE_EREG_PA + i);
1092 printk(KERN_INFO "%s: Netwave: port %#3lx, irq %d, mem %lx id "
1093 "%c%c, hw_addr ", dev->name, dev->base_addr, dev->irq,
1094 (u_long) ramBase, (int) readb(ramBase+NETWAVE_EREG_NI),
1095 (int) readb(ramBase+NETWAVE_EREG_NI+1));
1096 for (i = 0; i < 6; i++)
1097 printk("%02X%s", dev->dev_addr[i], ((i<5) ? ":" : "\n"));
1099 /* get revision words */
1100 printk(KERN_DEBUG "Netwave_reset: revision %04x %04x\n",
1101 get_uint16(ramBase + NETWAVE_EREG_ARW),
1102 get_uint16(ramBase + NETWAVE_EREG_ARW+2));
1106 cs_error(link->handle, last_fn, last_ret);
1108 netwave_release(link);
1109 } /* netwave_pcmcia_config */
1112 * Function netwave_release (arg)
1114 * After a card is removed, netwave_release() will unregister the net
1115 * device, and release the PCMCIA configuration. If the device is
1116 * still open, this will be postponed until it is closed.
1118 static void netwave_release(dev_link_t *link)
1120 struct net_device *dev = link->priv;
1121 netwave_private *priv = dev->priv;
1123 DEBUG(0, "netwave_release(0x%p)\n", link);
1125 /* Don't bother checking to see if these succeed or not */
1127 iounmap(priv->ramBase);
1128 pcmcia_release_window(link->win);
1130 pcmcia_release_configuration(link->handle);
1131 pcmcia_release_io(link->handle, &link->io);
1132 pcmcia_release_irq(link->handle, &link->irq);
1134 link->state &= ~DEV_CONFIG;
1138 * Function netwave_event (event, priority, args)
1140 * The card status event handler. Mostly, this schedules other
1141 * stuff to run after an event is received. A CARD_REMOVAL event
1142 * also sets some flags to discourage the net drivers from trying
1143 * to talk to the card any more.
1145 * When a CARD_REMOVAL event is received, we immediately set a flag
1146 * to block future accesses to this device. All the functions that
1147 * actually access the device should check this flag to make sure
1148 * the card is still present.
1151 static int netwave_event(event_t event, int priority,
1152 event_callback_args_t *args) {
1153 dev_link_t *link = args->client_data;
1154 struct net_device *dev = link->priv;
1156 DEBUG(1, "netwave_event(0x%06x)\n", event);
1159 case CS_EVENT_REGISTRATION_COMPLETE:
1160 DEBUG(0, "netwave_cs: registration complete\n");
1163 case CS_EVENT_CARD_REMOVAL:
1164 link->state &= ~DEV_PRESENT;
1165 if (link->state & DEV_CONFIG) {
1166 netif_device_detach(dev);
1167 netwave_release(link);
1170 case CS_EVENT_CARD_INSERTION:
1171 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
1172 netwave_pcmcia_config( link);
1174 case CS_EVENT_PM_SUSPEND:
1175 link->state |= DEV_SUSPEND;
1176 /* Fall through... */
1177 case CS_EVENT_RESET_PHYSICAL:
1178 if (link->state & DEV_CONFIG) {
1180 netif_device_detach(dev);
1181 pcmcia_release_configuration(link->handle);
1184 case CS_EVENT_PM_RESUME:
1185 link->state &= ~DEV_SUSPEND;
1186 /* Fall through... */
1187 case CS_EVENT_CARD_RESET:
1188 if (link->state & DEV_CONFIG) {
1189 pcmcia_request_configuration(link->handle, &link->conf);
1192 netif_device_attach(dev);
1198 } /* netwave_event */
1201 * Function netwave_doreset (ioBase, ramBase)
1203 * Proper hardware reset of the card.
1205 static void netwave_doreset(ioaddr_t ioBase, u_char* ramBase) {
1208 outb(0x80, ioBase + NETWAVE_REG_PMR);
1209 writeb(0x08, ramBase + NETWAVE_EREG_ASCC); /* Bit 3 is WOC */
1210 outb(0x0, ioBase + NETWAVE_REG_PMR); /* release reset */
1214 * Function netwave_reset (dev)
1216 * Reset and restore all of the netwave registers
1218 static void netwave_reset(struct net_device *dev) {
1220 netwave_private *priv = (netwave_private*) dev->priv;
1221 u_char *ramBase = priv->ramBase;
1222 ioaddr_t iobase = dev->base_addr;
1224 DEBUG(0, "netwave_reset: Done with hardware reset\n");
1226 priv->timeoutCounter = 0;
1229 netwave_doreset(iobase, ramBase);
1230 printk(KERN_DEBUG "netwave_reset: Done with hardware reset\n");
1232 /* Write a NOP to check the card */
1234 writeb(NETWAVE_CMD_NOP, ramBase + NETWAVE_EREG_CB + 0);
1235 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 1);
1237 /* Set receive conf */
1239 writeb(NETWAVE_CMD_SRC, ramBase + NETWAVE_EREG_CB + 0);
1240 writeb(rxConfRxEna + rxConfBcast, ramBase + NETWAVE_EREG_CB + 1);
1241 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 2);
1243 /* Set transmit conf */
1245 writeb(NETWAVE_CMD_STC, ramBase + NETWAVE_EREG_CB + 0);
1246 writeb(txConfTxEna, ramBase + NETWAVE_EREG_CB + 1);
1247 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 2);
1249 /* Now set the MU Domain */
1250 printk(KERN_DEBUG "Setting domain to 0x%x%02x\n", (domain >> 8) & 0x01, domain & 0xff);
1252 writeb(NETWAVE_CMD_SMD, ramBase + NETWAVE_EREG_CB + 0);
1253 writeb(domain & 0xff, ramBase + NETWAVE_EREG_CB + 1);
1254 writeb((domain>>8) & 0x01, ramBase + NETWAVE_EREG_CB + 2);
1255 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 3);
1257 /* Set scramble key */
1258 printk(KERN_DEBUG "Setting scramble key to 0x%x\n", scramble_key);
1260 writeb(NETWAVE_CMD_SSK, ramBase + NETWAVE_EREG_CB + 0);
1261 writeb(scramble_key & 0xff, ramBase + NETWAVE_EREG_CB + 1);
1262 writeb((scramble_key>>8) & 0xff, ramBase + NETWAVE_EREG_CB + 2);
1263 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 3);
1265 /* Enable interrupts, bit 4 high to keep unused
1266 * source from interrupting us, bit 2 high to
1267 * set interrupt enable, 567 to enable TxDN,
1271 outb(imrConfIENA+imrConfRFU1, iobase + NETWAVE_REG_IMR);
1273 /* Hent 4 bytes fra 0x170. Skal vaere 0a,29,88,36
1275 * skriv 80 til d000:3688
1276 * sjekk om det ble 80
1279 /* Enable Receiver */
1281 writeb(NETWAVE_CMD_ER, ramBase + NETWAVE_EREG_CB + 0);
1282 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 1);
1284 /* Set the IENA bit in COR */
1286 outb(corConfIENA + corConfLVLREQ, iobase + NETWAVE_REG_COR);
1290 * Function netwave_hw_xmit (data, len, dev)
1292 static int netwave_hw_xmit(unsigned char* data, int len,
1293 struct net_device* dev) {
1294 unsigned long flags;
1295 unsigned int TxFreeList,
1301 netwave_private *priv = (netwave_private *) dev->priv;
1302 u_char* ramBase = priv->ramBase;
1303 ioaddr_t iobase = dev->base_addr;
1305 /* Disable interrupts & save flags */
1306 spin_lock_irqsave(&priv->spinlock, flags);
1308 /* Check if there are transmit buffers available */
1310 if ((inb(iobase+NETWAVE_REG_ASR) & NETWAVE_ASR_TXBA) == 0) {
1311 /* No buffers available */
1312 printk(KERN_DEBUG "netwave_hw_xmit: %s - no xmit buffers available.\n",
1314 spin_unlock_irqrestore(&priv->spinlock, flags);
1318 priv->stats.tx_bytes += len;
1320 DEBUG(3, "Transmitting with SPCQ %x SPU %x LIF %x ISPLQ %x\n",
1321 readb(ramBase + NETWAVE_EREG_SPCQ),
1322 readb(ramBase + NETWAVE_EREG_SPU),
1323 readb(ramBase + NETWAVE_EREG_LIF),
1324 readb(ramBase + NETWAVE_EREG_ISPLQ));
1326 /* Now try to insert it into the adapters free memory */
1328 TxFreeList = get_uint16(ramBase + NETWAVE_EREG_TDP);
1329 MaxData = get_uint16(ramBase + NETWAVE_EREG_TDP+2);
1330 DataOffset = get_uint16(ramBase + NETWAVE_EREG_TDP+4);
1332 DEBUG(3, "TxFreeList %x, MaxData %x, DataOffset %x\n",
1333 TxFreeList, MaxData, DataOffset);
1335 /* Copy packet to the adapter fragment buffers */
1336 curBuff = TxFreeList;
1338 while (tmpcount < len) {
1339 int tmplen = len - tmpcount;
1340 copy_to_pc(ramBase + curBuff + DataOffset, data + tmpcount,
1341 (tmplen < MaxData) ? tmplen : MaxData);
1342 tmpcount += MaxData;
1344 /* Advance to next buffer */
1345 curBuff = get_uint16(ramBase + curBuff);
1348 /* Now issue transmit list */
1350 writeb(NETWAVE_CMD_TL, ramBase + NETWAVE_EREG_CB + 0);
1351 writeb(len & 0xff, ramBase + NETWAVE_EREG_CB + 1);
1352 writeb((len>>8) & 0xff, ramBase + NETWAVE_EREG_CB + 2);
1353 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 3);
1355 spin_unlock_irqrestore(&priv->spinlock, flags);
1359 static int netwave_start_xmit(struct sk_buff *skb, struct net_device *dev) {
1360 /* This flag indicate that the hardware can't perform a transmission.
1361 * Theoritically, NET3 check it before sending a packet to the driver,
1362 * but in fact it never do that and pool continuously.
1363 * As the watchdog will abort too long transmissions, we are quite safe...
1366 netif_stop_queue(dev);
1369 short length = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
1370 unsigned char* buf = skb->data;
1372 if (netwave_hw_xmit( buf, length, dev) == 1) {
1373 /* Some error, let's make them call us another time? */
1374 netif_start_queue(dev);
1376 dev->trans_start = jiffies;
1381 } /* netwave_start_xmit */
1384 * Function netwave_interrupt (irq, dev_id, regs)
1386 * This function is the interrupt handler for the Netwave card. This
1387 * routine will be called whenever:
1388 * 1. A packet is received.
1389 * 2. A packet has successfully been transferred and the unit is
1390 * ready to transmit another packet.
1391 * 3. A command has completed execution.
1393 static irqreturn_t netwave_interrupt(int irq, void* dev_id, struct pt_regs *regs) {
1396 struct net_device *dev = (struct net_device *)dev_id;
1397 struct netwave_private *priv = dev->priv;
1398 dev_link_t *link = &priv->link;
1401 if (!netif_device_present(dev))
1404 iobase = dev->base_addr;
1405 ramBase = priv->ramBase;
1407 /* Now find what caused the interrupt, check while interrupts ready */
1408 for (i = 0; i < 10; i++) {
1412 if (!(inb(iobase+NETWAVE_REG_CCSR) & 0x02))
1413 break; /* None of the interrupt sources asserted (normal exit) */
1415 status = inb(iobase + NETWAVE_REG_ASR);
1417 if (!DEV_OK(link)) {
1418 DEBUG(1, "netwave_interrupt: Interrupt with status 0x%x "
1419 "from removed or suspended card!\n", status);
1424 if (status & 0x80) {
1426 /* wait_WOC(iobase); */
1427 /* RxRdy cannot be reset directly by the host */
1430 if (status & 0x40) {
1433 rser = readb(ramBase + NETWAVE_EREG_RSER);
1436 ++priv->stats.rx_dropped;
1437 ++priv->stats.rx_crc_errors;
1440 ++priv->stats.rx_frame_errors;
1442 /* Clear the RxErr bit in RSER. RSER+4 is the
1443 * write part. Also clear the RxCRC (0x04) and
1444 * RxBig (0x02) bits if present */
1446 writeb(0x40 | (rser & 0x06), ramBase + NETWAVE_EREG_RSER + 4);
1448 /* Write bit 6 high to ASCC to clear RxErr in ASR,
1449 * WOC must be set first!
1452 writeb(0x40, ramBase + NETWAVE_EREG_ASCC);
1454 /* Remember to count up priv->stats on error packets */
1455 ++priv->stats.rx_errors;
1458 if (status & 0x20) {
1461 txStatus = readb(ramBase + NETWAVE_EREG_TSER);
1462 DEBUG(3, "Transmit done. TSER = %x id %x\n",
1463 txStatus, readb(ramBase + NETWAVE_EREG_TSER + 1));
1465 if (txStatus & 0x20) {
1466 /* Transmitting was okay, clear bits */
1468 writeb(0x2f, ramBase + NETWAVE_EREG_TSER + 4);
1469 ++priv->stats.tx_packets;
1472 if (txStatus & 0xd0) {
1473 if (txStatus & 0x80) {
1474 ++priv->stats.collisions; /* Because of /proc/net/dev*/
1475 /* ++priv->stats.tx_aborted_errors; */
1476 /* printk("Collision. %ld\n", jiffies - dev->trans_start); */
1478 if (txStatus & 0x40)
1479 ++priv->stats.tx_carrier_errors;
1480 /* 0x80 TxGU Transmit giveup - nine times and no luck
1481 * 0x40 TxNOAP No access point. Discarded packet.
1482 * 0x10 TxErr Transmit error. Always set when
1483 * TxGU and TxNOAP is set. (Those are the only ones
1486 DEBUG(3, "netwave_interrupt: TxDN with error status %x\n",
1489 /* Clear out TxGU, TxNOAP, TxErr and TxTrys */
1491 writeb(0xdf & txStatus, ramBase+NETWAVE_EREG_TSER+4);
1492 ++priv->stats.tx_errors;
1494 DEBUG(3, "New status is TSER %x ASR %x\n",
1495 readb(ramBase + NETWAVE_EREG_TSER),
1496 inb(iobase + NETWAVE_REG_ASR));
1498 netif_wake_queue(dev);
1500 /* TxBA, this would trigger on all error packets received */
1501 /* if (status & 0x01) {
1502 DEBUG(4, "Transmit buffers available, %x\n", status);
1506 /* Handled if we looped at least one time - Jean II */
1507 return IRQ_RETVAL(i);
1508 } /* netwave_interrupt */
1511 * Function netwave_watchdog (a)
1513 * Watchdog : when we start a transmission, we set a timer in the
1514 * kernel. If the transmission complete, this timer is disabled. If
1515 * it expire, we reset the card.
1518 static void netwave_watchdog(struct net_device *dev) {
1520 DEBUG(1, "%s: netwave_watchdog: watchdog timer expired\n", dev->name);
1522 dev->trans_start = jiffies;
1523 netif_wake_queue(dev);
1524 } /* netwave_watchdog */
1526 static struct net_device_stats *netwave_get_stats(struct net_device *dev) {
1527 netwave_private *priv = (netwave_private*)dev->priv;
1531 DEBUG(2, "netwave: SPCQ %x SPU %x LIF %x ISPLQ %x MHS %x rxtx %x"
1532 " %x tx %x %x %x %x\n",
1533 readb(priv->ramBase + NETWAVE_EREG_SPCQ),
1534 readb(priv->ramBase + NETWAVE_EREG_SPU),
1535 readb(priv->ramBase + NETWAVE_EREG_LIF),
1536 readb(priv->ramBase + NETWAVE_EREG_ISPLQ),
1537 readb(priv->ramBase + NETWAVE_EREG_MHS),
1538 readb(priv->ramBase + NETWAVE_EREG_EC + 0xe),
1539 readb(priv->ramBase + NETWAVE_EREG_EC + 0xf),
1540 readb(priv->ramBase + NETWAVE_EREG_EC + 0x18),
1541 readb(priv->ramBase + NETWAVE_EREG_EC + 0x19),
1542 readb(priv->ramBase + NETWAVE_EREG_EC + 0x1a),
1543 readb(priv->ramBase + NETWAVE_EREG_EC + 0x1b));
1545 return &priv->stats;
1548 static void update_stats(struct net_device *dev) {
1549 //unsigned long flags;
1550 /* netwave_private *priv = (netwave_private*) dev->priv; */
1552 //spin_lock_irqsave(&priv->spinlock, flags);
1554 /* priv->stats.rx_packets = readb(priv->ramBase + 0x18e);
1555 priv->stats.tx_packets = readb(priv->ramBase + 0x18f); */
1557 //spin_unlock_irqrestore(&priv->spinlock, flags);
1560 static int netwave_rx(struct net_device *dev) {
1561 netwave_private *priv = (netwave_private*)(dev->priv);
1562 u_char *ramBase = priv->ramBase;
1563 ioaddr_t iobase = dev->base_addr;
1565 struct sk_buff *skb = NULL;
1566 unsigned int curBuffer,
1570 int dataCount, dataOffset;
1574 DEBUG(3, "xinw_rx: Receiving ... \n");
1576 /* Receive max 10 packets for now. */
1577 for (i = 0; i < 10; i++) {
1580 rxStatus = readb(ramBase + NETWAVE_EREG_RSER);
1581 if ( !( rxStatus & 0x80)) /* No more packets */
1584 /* Check if multicast/broadcast or other */
1585 /* multicast = (rxStatus & 0x20); */
1587 /* The receive list pointer and length of the packet */
1589 rcvLen = get_int16( ramBase + NETWAVE_EREG_RDP);
1590 rcvList = get_uint16( ramBase + NETWAVE_EREG_RDP + 2);
1593 printk(KERN_DEBUG "netwave_rx: Receive packet with len %d\n",
1598 skb = dev_alloc_skb(rcvLen+5);
1600 DEBUG(1, "netwave_rx: Could not allocate an sk_buff of "
1601 "length %d\n", rcvLen);
1602 ++priv->stats.rx_dropped;
1603 /* Tell the adapter to skip the packet */
1605 writeb(NETWAVE_CMD_SRP, ramBase + NETWAVE_EREG_CB + 0);
1606 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 1);
1610 skb_reserve( skb, 2); /* Align IP on 16 byte */
1611 skb_put( skb, rcvLen);
1614 /* Copy packet fragments to the skb data area */
1615 ptr = (u_char*) skb->data;
1616 curBuffer = rcvList;
1618 while ( tmpcount < rcvLen) {
1619 /* Get length and offset of current buffer */
1620 dataCount = get_uint16( ramBase+curBuffer+2);
1621 dataOffset = get_uint16( ramBase+curBuffer+4);
1623 copy_from_pc( ptr + tmpcount,
1624 ramBase+curBuffer+dataOffset, dataCount);
1626 tmpcount += dataCount;
1628 /* Point to next buffer */
1629 curBuffer = get_uint16(ramBase + curBuffer);
1632 skb->protocol = eth_type_trans(skb,dev);
1633 /* Queue packet for network layer */
1636 dev->last_rx = jiffies;
1637 priv->stats.rx_packets++;
1638 priv->stats.rx_bytes += rcvLen;
1640 /* Got the packet, tell the adapter to skip it */
1642 writeb(NETWAVE_CMD_SRP, ramBase + NETWAVE_EREG_CB + 0);
1643 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 1);
1644 DEBUG(3, "Packet reception ok\n");
1649 static int netwave_open(struct net_device *dev) {
1650 netwave_private *priv = dev->priv;
1651 dev_link_t *link = &priv->link;
1653 DEBUG(1, "netwave_open: starting.\n");
1660 netif_start_queue(dev);
1666 static int netwave_close(struct net_device *dev) {
1667 netwave_private *priv = (netwave_private *)dev->priv;
1668 dev_link_t *link = &priv->link;
1670 DEBUG(1, "netwave_close: finishing.\n");
1673 netif_stop_queue(dev);
1678 static struct pcmcia_driver netwave_driver = {
1679 .owner = THIS_MODULE,
1681 .name = "netwave_cs",
1683 .attach = netwave_attach,
1684 .detach = netwave_detach,
1687 static int __init init_netwave_cs(void)
1689 return pcmcia_register_driver(&netwave_driver);
1692 static void __exit exit_netwave_cs(void)
1694 pcmcia_unregister_driver(&netwave_driver);
1696 if (dev_list != NULL) /* Critical situation */
1697 printk("netwave_cs: devices remaining when removing module\n");
1700 module_init(init_netwave_cs);
1701 module_exit(exit_netwave_cs);
1703 /* Set or clear the multicast filter for this adaptor.
1704 num_addrs == -1 Promiscuous mode, receive all packets
1705 num_addrs == 0 Normal mode, clear multicast list
1706 num_addrs > 0 Multicast mode, receive normal and MC packets, and do
1707 best-effort filtering.
1709 static void set_multicast_list(struct net_device *dev)
1711 ioaddr_t iobase = dev->base_addr;
1712 u_char* ramBase = ((netwave_private*) dev->priv)->ramBase;
1718 if (old != dev->mc_count) {
1719 old = dev->mc_count;
1720 DEBUG(0, "%s: setting Rx mode to %d addresses.\n",
1721 dev->name, dev->mc_count);
1726 if (dev->mc_count || (dev->flags & IFF_ALLMULTI)) {
1727 /* Multicast Mode */
1728 rcvMode = rxConfRxEna + rxConfAMP + rxConfBcast;
1729 } else if (dev->flags & IFF_PROMISC) {
1730 /* Promiscous mode */
1731 rcvMode = rxConfRxEna + rxConfPro + rxConfAMP + rxConfBcast;
1734 rcvMode = rxConfRxEna + rxConfBcast;
1737 /* printk("netwave set_multicast_list: rcvMode to %x\n", rcvMode);*/
1738 /* Now set receive mode */
1740 writeb(NETWAVE_CMD_SRC, ramBase + NETWAVE_EREG_CB + 0);
1741 writeb(rcvMode, ramBase + NETWAVE_EREG_CB + 1);
1742 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 2);
1744 MODULE_LICENSE("GPL");