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>
60 #include <net/iw_handler.h>
63 #include <pcmcia/cs_types.h>
64 #include <pcmcia/cs.h>
65 #include <pcmcia/cistpl.h>
66 #include <pcmcia/cisreg.h>
67 #include <pcmcia/ds.h>
68 #include <pcmcia/mem_op.h>
70 #include <asm/system.h>
74 #define NETWAVE_REGOFF 0x8000
75 /* The Netwave IO registers, offsets to iobase */
76 #define NETWAVE_REG_COR 0x0
77 #define NETWAVE_REG_CCSR 0x2
78 #define NETWAVE_REG_ASR 0x4
79 #define NETWAVE_REG_IMR 0xa
80 #define NETWAVE_REG_PMR 0xc
81 #define NETWAVE_REG_IOLOW 0x6
82 #define NETWAVE_REG_IOHI 0x7
83 #define NETWAVE_REG_IOCONTROL 0x8
84 #define NETWAVE_REG_DATA 0xf
85 /* The Netwave Extended IO registers, offsets to RamBase */
86 #define NETWAVE_EREG_ASCC 0x114
87 #define NETWAVE_EREG_RSER 0x120
88 #define NETWAVE_EREG_RSERW 0x124
89 #define NETWAVE_EREG_TSER 0x130
90 #define NETWAVE_EREG_TSERW 0x134
91 #define NETWAVE_EREG_CB 0x100
92 #define NETWAVE_EREG_SPCQ 0x154
93 #define NETWAVE_EREG_SPU 0x155
94 #define NETWAVE_EREG_LIF 0x14e
95 #define NETWAVE_EREG_ISPLQ 0x156
96 #define NETWAVE_EREG_HHC 0x158
97 #define NETWAVE_EREG_NI 0x16e
98 #define NETWAVE_EREG_MHS 0x16b
99 #define NETWAVE_EREG_TDP 0x140
100 #define NETWAVE_EREG_RDP 0x150
101 #define NETWAVE_EREG_PA 0x160
102 #define NETWAVE_EREG_EC 0x180
103 #define NETWAVE_EREG_CRBP 0x17a
104 #define NETWAVE_EREG_ARW 0x166
107 * Commands used in the extended command buffer
108 * NETWAVE_EREG_CB (0x100-0x10F)
110 #define NETWAVE_CMD_NOP 0x00
111 #define NETWAVE_CMD_SRC 0x01
112 #define NETWAVE_CMD_STC 0x02
113 #define NETWAVE_CMD_AMA 0x03
114 #define NETWAVE_CMD_DMA 0x04
115 #define NETWAVE_CMD_SAMA 0x05
116 #define NETWAVE_CMD_ER 0x06
117 #define NETWAVE_CMD_DR 0x07
118 #define NETWAVE_CMD_TL 0x08
119 #define NETWAVE_CMD_SRP 0x09
120 #define NETWAVE_CMD_SSK 0x0a
121 #define NETWAVE_CMD_SMD 0x0b
122 #define NETWAVE_CMD_SAPD 0x0c
123 #define NETWAVE_CMD_SSS 0x11
124 /* End of Command marker */
125 #define NETWAVE_CMD_EOC 0x00
127 /* ASR register bits */
128 #define NETWAVE_ASR_RXRDY 0x80
129 #define NETWAVE_ASR_TXBA 0x01
131 #define TX_TIMEOUT ((32*HZ)/100)
133 static const unsigned int imrConfRFU1 = 0x10; /* RFU interrupt mask, keep high */
134 static const unsigned int imrConfIENA = 0x02; /* Interrupt enable */
136 static const unsigned int corConfIENA = 0x01; /* Interrupt enable */
137 static const unsigned int corConfLVLREQ = 0x40; /* Keep high */
139 static const unsigned int rxConfRxEna = 0x80; /* Receive Enable */
140 static const unsigned int rxConfMAC = 0x20; /* MAC host receive mode*/
141 static const unsigned int rxConfPro = 0x10; /* Promiscuous */
142 static const unsigned int rxConfAMP = 0x08; /* Accept Multicast Packets */
143 static const unsigned int rxConfBcast = 0x04; /* Accept Broadcast Packets */
145 static const unsigned int txConfTxEna = 0x80; /* Transmit Enable */
146 static const unsigned int txConfMAC = 0x20; /* Host sends MAC mode */
147 static const unsigned int txConfEUD = 0x10; /* Enable Uni-Data packets */
148 static const unsigned int txConfKey = 0x02; /* Scramble data packets */
149 static const unsigned int txConfLoop = 0x01; /* Loopback mode */
152 All the PCMCIA modules use PCMCIA_DEBUG to control debugging. If
153 you do not define PCMCIA_DEBUG at all, all the debug code will be
154 left out. If you compile with PCMCIA_DEBUG=0, the debug code will
155 be present but disabled -- but it can then be enabled for specific
156 modules at load time with a 'pc_debug=#' option to insmod.
160 static int pc_debug = PCMCIA_DEBUG;
161 module_param(pc_debug, int, 0);
162 #define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args)
163 static char *version =
164 "netwave_cs.c 0.3.0 Thu Jul 17 14:36:02 1997 (John Markus Bjørndalen)\n";
166 #define DEBUG(n, args...)
169 static dev_info_t dev_info = "netwave_cs";
171 /*====================================================================*/
173 /* Parameters that can be set with 'insmod' */
175 /* Choose the domain, default is 0x100 */
176 static u_int domain = 0x100;
178 /* Scramble key, range from 0x0 to 0xffff.
179 * 0x0 is no scrambling.
181 static u_int scramble_key = 0x0;
183 /* Shared memory speed, in ns. The documentation states that
184 * the card should not be read faster than every 400ns.
185 * This timing should be provided by the HBA. If it becomes a
186 * problem, try setting mem_speed to 400.
188 static int mem_speed;
190 module_param(domain, int, 0);
191 module_param(scramble_key, int, 0);
192 module_param(mem_speed, int, 0);
194 /*====================================================================*/
196 /* PCMCIA (Card Services) related functions */
197 static void netwave_release(dev_link_t *link); /* Card removal */
198 static int netwave_event(event_t event, int priority,
199 event_callback_args_t *args);
200 static void netwave_pcmcia_config(dev_link_t *arg); /* Runs after card
202 static dev_link_t *netwave_attach(void); /* Create instance */
203 static void netwave_detach(struct pcmcia_device *p_dev); /* Destroy instance */
205 /* Hardware configuration */
206 static void netwave_doreset(kio_addr_t iobase, u_char __iomem *ramBase);
207 static void netwave_reset(struct net_device *dev);
209 /* Misc device stuff */
210 static int netwave_open(struct net_device *dev); /* Open the device */
211 static int netwave_close(struct net_device *dev); /* Close the device */
213 /* Packet transmission and Packet reception */
214 static int netwave_start_xmit( struct sk_buff *skb, struct net_device *dev);
215 static int netwave_rx( struct net_device *dev);
217 /* Interrupt routines */
218 static irqreturn_t netwave_interrupt(int irq, void *dev_id, struct pt_regs *regs);
219 static void netwave_watchdog(struct net_device *);
222 static void update_stats(struct net_device *dev);
223 static struct net_device_stats *netwave_get_stats(struct net_device *dev);
225 /* Wireless extensions */
226 static struct iw_statistics* netwave_get_wireless_stats(struct net_device *dev);
228 static void set_multicast_list(struct net_device *dev);
231 A linked list of "instances" of the skeleton device. Each actual
232 PCMCIA card corresponds to one device instance, and is described
233 by one dev_link_t structure (defined in ds.h).
235 You may not want to use a linked list for this -- for example, the
236 memory card driver uses an array of dev_link_t pointers, where minor
237 device numbers are used to derive the corresponding array index.
239 static dev_link_t *dev_list;
242 A dev_link_t structure has fields for most things that are needed
243 to keep track of a socket, but there will usually be some device
244 specific information that also needs to be kept track of. The
245 'priv' pointer in a dev_link_t structure can be used to point to
246 a device-specific private data structure, like this.
248 A driver needs to provide a dev_node_t structure for each device
249 on a card. In some cases, there is only one device per card (for
250 example, ethernet cards, modems). In other cases, there may be
251 many actual or logical devices (SCSI adapters, memory cards with
252 multiple partitions). The dev_node_t structures need to be kept
253 in a linked list starting at the 'dev' field of a dev_link_t
254 structure. We allocate them in the card's private data structure,
255 because they generally can't be allocated dynamically.
258 static const struct iw_handler_def netwave_handler_def;
260 #define SIOCGIPSNAP SIOCIWFIRSTPRIV + 1 /* Site Survey Snapshot */
264 typedef struct net_addr {
270 u_char struct_revision;
271 u_char roaming_state;
273 u_char sp_existsFlag;
274 u_char sp_link_quality;
275 u_char sp_max_link_quality;
276 u_char linkQualityGoodFairBoundary;
277 u_char linkQualityFairPoorBoundary;
278 u_char sp_utilization;
280 u_char sp_hotheadcount;
281 u_char roaming_condition;
285 net_addr nearByAccessPoints[MAX_ESA];
288 typedef struct netwave_private {
290 spinlock_t spinlock; /* Serialize access to the hardware (SMP) */
292 u_char __iomem *ramBase;
295 struct timer_list watchdog; /* To avoid blocking state */
296 struct site_survey nss;
297 struct net_device_stats stats;
298 struct iw_statistics iw_stats; /* Wireless stats */
302 static struct net_device_stats *netwave_get_stats(struct net_device *dev);
306 * The Netwave card is little-endian, so won't work for big endian
309 static inline unsigned short get_uint16(u_char __iomem *staddr)
311 return readw(staddr); /* Return only 16 bits */
314 static inline short get_int16(u_char __iomem * staddr)
316 return readw(staddr);
320 * Wait until the WOC (Write Operation Complete) bit in the
321 * ASR (Adapter Status Register) is asserted.
322 * This should have aborted if it takes too long time.
324 static inline void wait_WOC(unsigned int iobase)
327 while ((inb(iobase + NETWAVE_REG_ASR) & 0x8) != 0x8) ;
330 static void netwave_snapshot(netwave_private *priv, u_char __iomem *ramBase,
332 u_short resultBuffer;
334 /* if time since last snapshot is > 1 sec. (100 jiffies?) then take
335 * new snapshot, else return cached data. This is the recommended rate.
337 if ( jiffies - priv->lastExec > 100) {
338 /* Take site survey snapshot */
339 /*printk( KERN_DEBUG "Taking new snapshot. %ld\n", jiffies -
342 writeb(NETWAVE_CMD_SSS, ramBase + NETWAVE_EREG_CB + 0);
343 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 1);
346 /* Get result and copy to cach */
347 resultBuffer = readw(ramBase + NETWAVE_EREG_CRBP);
348 copy_from_pc( &priv->nss, ramBase+resultBuffer,
349 sizeof(struct site_survey));
354 * Function netwave_get_wireless_stats (dev)
356 * Wireless extensions statistics
359 static struct iw_statistics *netwave_get_wireless_stats(struct net_device *dev)
362 kio_addr_t iobase = dev->base_addr;
363 netwave_private *priv = netdev_priv(dev);
364 u_char __iomem *ramBase = priv->ramBase;
365 struct iw_statistics* wstats;
367 wstats = &priv->iw_stats;
369 spin_lock_irqsave(&priv->spinlock, flags);
371 netwave_snapshot( priv, ramBase, iobase);
373 wstats->status = priv->nss.roaming_state;
374 wstats->qual.qual = readb( ramBase + NETWAVE_EREG_SPCQ);
375 wstats->qual.level = readb( ramBase + NETWAVE_EREG_ISPLQ);
376 wstats->qual.noise = readb( ramBase + NETWAVE_EREG_SPU) & 0x3f;
377 wstats->discard.nwid = 0L;
378 wstats->discard.code = 0L;
379 wstats->discard.misc = 0L;
381 spin_unlock_irqrestore(&priv->spinlock, flags);
383 return &priv->iw_stats;
387 * Function netwave_attach (void)
389 * Creates an "instance" of the driver, allocating local data
390 * structures for one device. The device is registered with Card
393 * The dev_link structure is initialized, but we don't actually
394 * configure the card at this point -- we wait until we receive a
395 * card insertion event.
397 static dev_link_t *netwave_attach(void)
399 client_reg_t client_reg;
401 struct net_device *dev;
402 netwave_private *priv;
405 DEBUG(0, "netwave_attach()\n");
407 /* Initialize the dev_link_t structure */
408 dev = alloc_etherdev(sizeof(netwave_private));
411 priv = netdev_priv(dev);
415 /* The io structure describes IO port mapping */
416 link->io.NumPorts1 = 16;
417 link->io.Attributes1 = IO_DATA_PATH_WIDTH_16;
418 /* link->io.NumPorts2 = 16;
419 link->io.Attributes2 = IO_DATA_PATH_WIDTH_16; */
420 link->io.IOAddrLines = 5;
422 /* Interrupt setup */
423 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT;
424 link->irq.IRQInfo1 = IRQ_LEVEL_ID;
425 link->irq.Handler = &netwave_interrupt;
427 /* General socket configuration */
428 link->conf.Attributes = CONF_ENABLE_IRQ;
430 link->conf.IntType = INT_MEMORY_AND_IO;
431 link->conf.ConfigIndex = 1;
432 link->conf.Present = PRESENT_OPTION;
434 /* Netwave private struct init. link/dev/node already taken care of,
435 * other stuff zero'd - Jean II */
436 spin_lock_init(&priv->spinlock);
438 /* Netwave specific entries in the device structure */
439 SET_MODULE_OWNER(dev);
440 dev->hard_start_xmit = &netwave_start_xmit;
441 dev->get_stats = &netwave_get_stats;
442 dev->set_multicast_list = &set_multicast_list;
443 /* wireless extensions */
444 dev->wireless_handlers = (struct iw_handler_def *)&netwave_handler_def;
446 dev->tx_timeout = &netwave_watchdog;
447 dev->watchdog_timeo = TX_TIMEOUT;
449 dev->open = &netwave_open;
450 dev->stop = &netwave_close;
451 link->irq.Instance = dev;
453 /* Register with Card Services */
454 link->next = dev_list;
456 client_reg.dev_info = &dev_info;
457 client_reg.Version = 0x0210;
458 client_reg.event_callback_args.client_data = link;
459 ret = pcmcia_register_client(&link->handle, &client_reg);
461 cs_error(link->handle, RegisterClient, ret);
462 netwave_detach(link->handle);
467 } /* netwave_attach */
470 * Function netwave_detach (link)
472 * This deletes a driver "instance". The device is de-registered
473 * with Card Services. If it has been released, all local data
474 * structures are freed. Otherwise, the structures will be freed
475 * when the device is released.
477 static void netwave_detach(struct pcmcia_device *p_dev)
479 dev_link_t *link = dev_to_instance(p_dev);
480 struct net_device *dev = link->priv;
483 DEBUG(0, "netwave_detach(0x%p)\n", link);
486 If the device is currently configured and active, we won't
487 actually delete it yet. Instead, it is marked so that when
488 the release() function is called, that will trigger a proper
491 if (link->state & DEV_CONFIG)
492 netwave_release(link);
494 /* Locate device structure */
495 for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next)
496 if (*linkp == link) break;
499 DEBUG(1, "netwave_cs: detach fail, '%s' not in list\n",
500 link->dev->dev_name);
504 /* Unlink device structure, free pieces */
507 unregister_netdev(dev);
510 } /* netwave_detach */
513 * Wireless Handler : get protocol name
515 static int netwave_get_name(struct net_device *dev,
516 struct iw_request_info *info,
517 union iwreq_data *wrqu,
520 strcpy(wrqu->name, "Netwave");
525 * Wireless Handler : set Network ID
527 static int netwave_set_nwid(struct net_device *dev,
528 struct iw_request_info *info,
529 union iwreq_data *wrqu,
533 kio_addr_t iobase = dev->base_addr;
534 netwave_private *priv = netdev_priv(dev);
535 u_char __iomem *ramBase = priv->ramBase;
537 /* Disable interrupts & save flags */
538 spin_lock_irqsave(&priv->spinlock, flags);
540 if(!wrqu->nwid.disabled) {
541 domain = wrqu->nwid.value;
542 printk( KERN_DEBUG "Setting domain to 0x%x%02x\n",
543 (domain >> 8) & 0x01, domain & 0xff);
545 writeb(NETWAVE_CMD_SMD, ramBase + NETWAVE_EREG_CB + 0);
546 writeb( domain & 0xff, ramBase + NETWAVE_EREG_CB + 1);
547 writeb((domain >>8 ) & 0x01,ramBase + NETWAVE_EREG_CB+2);
548 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 3);
551 /* ReEnable interrupts & restore flags */
552 spin_unlock_irqrestore(&priv->spinlock, flags);
558 * Wireless Handler : get Network ID
560 static int netwave_get_nwid(struct net_device *dev,
561 struct iw_request_info *info,
562 union iwreq_data *wrqu,
565 wrqu->nwid.value = domain;
566 wrqu->nwid.disabled = 0;
567 wrqu->nwid.fixed = 1;
572 * Wireless Handler : set scramble key
574 static int netwave_set_scramble(struct net_device *dev,
575 struct iw_request_info *info,
576 union iwreq_data *wrqu,
580 kio_addr_t iobase = dev->base_addr;
581 netwave_private *priv = netdev_priv(dev);
582 u_char __iomem *ramBase = priv->ramBase;
584 /* Disable interrupts & save flags */
585 spin_lock_irqsave(&priv->spinlock, flags);
587 scramble_key = (key[0] << 8) | key[1];
589 writeb(NETWAVE_CMD_SSK, ramBase + NETWAVE_EREG_CB + 0);
590 writeb(scramble_key & 0xff, ramBase + NETWAVE_EREG_CB + 1);
591 writeb((scramble_key>>8) & 0xff, ramBase + NETWAVE_EREG_CB + 2);
592 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 3);
594 /* ReEnable interrupts & restore flags */
595 spin_unlock_irqrestore(&priv->spinlock, flags);
601 * Wireless Handler : get scramble key
603 static int netwave_get_scramble(struct net_device *dev,
604 struct iw_request_info *info,
605 union iwreq_data *wrqu,
608 key[1] = scramble_key & 0xff;
609 key[0] = (scramble_key>>8) & 0xff;
610 wrqu->encoding.flags = IW_ENCODE_ENABLED;
611 wrqu->encoding.length = 2;
616 * Wireless Handler : get mode
618 static int netwave_get_mode(struct net_device *dev,
619 struct iw_request_info *info,
620 union iwreq_data *wrqu,
624 wrqu->mode = IW_MODE_INFRA;
626 wrqu->mode = IW_MODE_ADHOC;
632 * Wireless Handler : get range info
634 static int netwave_get_range(struct net_device *dev,
635 struct iw_request_info *info,
636 union iwreq_data *wrqu,
639 struct iw_range *range = (struct iw_range *) extra;
642 /* Set the length (very important for backward compatibility) */
643 wrqu->data.length = sizeof(struct iw_range);
645 /* Set all the info we don't care or don't know about to zero */
646 memset(range, 0, sizeof(struct iw_range));
648 /* Set the Wireless Extension versions */
649 range->we_version_compiled = WIRELESS_EXT;
650 range->we_version_source = 9; /* Nothing for us in v10 and v11 */
652 /* Set information in the range struct */
653 range->throughput = 450 * 1000; /* don't argue on this ! */
654 range->min_nwid = 0x0000;
655 range->max_nwid = 0x01FF;
657 range->num_channels = range->num_frequency = 0;
659 range->sensitivity = 0x3F;
660 range->max_qual.qual = 255;
661 range->max_qual.level = 255;
662 range->max_qual.noise = 0;
664 range->num_bitrates = 1;
665 range->bitrate[0] = 1000000; /* 1 Mb/s */
667 range->encoding_size[0] = 2; /* 16 bits scrambling */
668 range->num_encoding_sizes = 1;
669 range->max_encoding_tokens = 1; /* Only one key possible */
675 * Wireless Private Handler : get snapshot
677 static int netwave_get_snap(struct net_device *dev,
678 struct iw_request_info *info,
679 union iwreq_data *wrqu,
683 kio_addr_t iobase = dev->base_addr;
684 netwave_private *priv = netdev_priv(dev);
685 u_char __iomem *ramBase = priv->ramBase;
687 /* Disable interrupts & save flags */
688 spin_lock_irqsave(&priv->spinlock, flags);
690 /* Take snapshot of environment */
691 netwave_snapshot( priv, ramBase, iobase);
692 wrqu->data.length = priv->nss.length;
693 memcpy(extra, (u_char *) &priv->nss, sizeof( struct site_survey));
695 priv->lastExec = jiffies;
697 /* ReEnable interrupts & restore flags */
698 spin_unlock_irqrestore(&priv->spinlock, flags);
704 * Structures to export the Wireless Handlers
705 * This is the stuff that are treated the wireless extensions (iwconfig)
708 static const struct iw_priv_args netwave_private_args[] = {
709 /*{ cmd, set_args, get_args, name } */
711 IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | sizeof(struct site_survey),
715 static const iw_handler netwave_handler[] =
717 NULL, /* SIOCSIWNAME */
718 netwave_get_name, /* SIOCGIWNAME */
719 netwave_set_nwid, /* SIOCSIWNWID */
720 netwave_get_nwid, /* SIOCGIWNWID */
721 NULL, /* SIOCSIWFREQ */
722 NULL, /* SIOCGIWFREQ */
723 NULL, /* SIOCSIWMODE */
724 netwave_get_mode, /* SIOCGIWMODE */
725 NULL, /* SIOCSIWSENS */
726 NULL, /* SIOCGIWSENS */
727 NULL, /* SIOCSIWRANGE */
728 netwave_get_range, /* SIOCGIWRANGE */
729 NULL, /* SIOCSIWPRIV */
730 NULL, /* SIOCGIWPRIV */
731 NULL, /* SIOCSIWSTATS */
732 NULL, /* SIOCGIWSTATS */
733 NULL, /* SIOCSIWSPY */
734 NULL, /* SIOCGIWSPY */
735 NULL, /* -- hole -- */
736 NULL, /* -- hole -- */
737 NULL, /* SIOCSIWAP */
738 NULL, /* SIOCGIWAP */
739 NULL, /* -- hole -- */
740 NULL, /* SIOCGIWAPLIST */
741 NULL, /* -- hole -- */
742 NULL, /* -- hole -- */
743 NULL, /* SIOCSIWESSID */
744 NULL, /* SIOCGIWESSID */
745 NULL, /* SIOCSIWNICKN */
746 NULL, /* SIOCGIWNICKN */
747 NULL, /* -- hole -- */
748 NULL, /* -- hole -- */
749 NULL, /* SIOCSIWRATE */
750 NULL, /* SIOCGIWRATE */
751 NULL, /* SIOCSIWRTS */
752 NULL, /* SIOCGIWRTS */
753 NULL, /* SIOCSIWFRAG */
754 NULL, /* SIOCGIWFRAG */
755 NULL, /* SIOCSIWTXPOW */
756 NULL, /* SIOCGIWTXPOW */
757 NULL, /* SIOCSIWRETRY */
758 NULL, /* SIOCGIWRETRY */
759 netwave_set_scramble, /* SIOCSIWENCODE */
760 netwave_get_scramble, /* SIOCGIWENCODE */
763 static const iw_handler netwave_private_handler[] =
765 NULL, /* SIOCIWFIRSTPRIV */
766 netwave_get_snap, /* SIOCIWFIRSTPRIV + 1 */
769 static const struct iw_handler_def netwave_handler_def =
771 .num_standard = sizeof(netwave_handler)/sizeof(iw_handler),
772 .num_private = sizeof(netwave_private_handler)/sizeof(iw_handler),
773 .num_private_args = sizeof(netwave_private_args)/sizeof(struct iw_priv_args),
774 .standard = (iw_handler *) netwave_handler,
775 .private = (iw_handler *) netwave_private_handler,
776 .private_args = (struct iw_priv_args *) netwave_private_args,
777 .get_wireless_stats = netwave_get_wireless_stats,
781 * Function netwave_pcmcia_config (link)
783 * netwave_pcmcia_config() is scheduled to run after a CARD_INSERTION
784 * event is received, to configure the PCMCIA socket, and to make the
785 * device available to the system.
789 #define CS_CHECK(fn, ret) \
790 do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
792 static void netwave_pcmcia_config(dev_link_t *link) {
793 client_handle_t handle = link->handle;
794 struct net_device *dev = link->priv;
795 netwave_private *priv = netdev_priv(dev);
798 int i, j, last_ret, last_fn;
802 u_char __iomem *ramBase = NULL;
804 DEBUG(0, "netwave_pcmcia_config(0x%p)\n", link);
807 This reads the card's CONFIG tuple to find its configuration
810 tuple.Attributes = 0;
811 tuple.TupleData = (cisdata_t *) buf;
812 tuple.TupleDataMax = 64;
813 tuple.TupleOffset = 0;
814 tuple.DesiredTuple = CISTPL_CONFIG;
815 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple));
816 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple));
817 CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse));
818 link->conf.ConfigBase = parse.config.base;
819 link->conf.Present = parse.config.rmask[0];
822 link->state |= DEV_CONFIG;
825 * Try allocating IO ports. This tries a few fixed addresses.
826 * If you want, you can also read the card's config table to
827 * pick addresses -- see the serial driver for an example.
829 for (i = j = 0x0; j < 0x400; j += 0x20) {
830 link->io.BasePort1 = j ^ 0x300;
831 i = pcmcia_request_io(link->handle, &link->io);
832 if (i == CS_SUCCESS) break;
834 if (i != CS_SUCCESS) {
835 cs_error(link->handle, RequestIO, i);
840 * Now allocate an interrupt line. Note that this does not
841 * actually assign a handler to the interrupt.
843 CS_CHECK(RequestIRQ, pcmcia_request_irq(handle, &link->irq));
846 * This actually configures the PCMCIA socket -- setting up
847 * the I/O windows and the interrupt mapping.
849 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(handle, &link->conf));
852 * Allocate a 32K memory window. Note that the dev_link_t
853 * structure provides space for one window handle -- if your
854 * device needs several windows, you'll need to keep track of
855 * the handles in your private data structure, dev->priv.
857 DEBUG(1, "Setting mem speed of %d\n", mem_speed);
859 req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_CM|WIN_ENABLE;
860 req.Base = 0; req.Size = 0x8000;
861 req.AccessSpeed = mem_speed;
862 CS_CHECK(RequestWindow, pcmcia_request_window(&link->handle, &req, &link->win));
863 mem.CardOffset = 0x20000; mem.Page = 0;
864 CS_CHECK(MapMemPage, pcmcia_map_mem_page(link->win, &mem));
866 /* Store base address of the common window frame */
867 ramBase = ioremap(req.Base, 0x8000);
868 priv->ramBase = ramBase;
870 dev->irq = link->irq.AssignedIRQ;
871 dev->base_addr = link->io.BasePort1;
872 SET_NETDEV_DEV(dev, &handle_to_dev(handle));
874 if (register_netdev(dev) != 0) {
875 printk(KERN_DEBUG "netwave_cs: register_netdev() failed\n");
879 strcpy(priv->node.dev_name, dev->name);
880 link->dev = &priv->node;
881 link->state &= ~DEV_CONFIG_PENDING;
883 /* Reset card before reading physical address */
884 netwave_doreset(dev->base_addr, ramBase);
886 /* Read the ethernet address and fill in the Netwave registers. */
887 for (i = 0; i < 6; i++)
888 dev->dev_addr[i] = readb(ramBase + NETWAVE_EREG_PA + i);
890 printk(KERN_INFO "%s: Netwave: port %#3lx, irq %d, mem %lx id "
891 "%c%c, hw_addr ", dev->name, dev->base_addr, dev->irq,
892 (u_long) ramBase, (int) readb(ramBase+NETWAVE_EREG_NI),
893 (int) readb(ramBase+NETWAVE_EREG_NI+1));
894 for (i = 0; i < 6; i++)
895 printk("%02X%s", dev->dev_addr[i], ((i<5) ? ":" : "\n"));
897 /* get revision words */
898 printk(KERN_DEBUG "Netwave_reset: revision %04x %04x\n",
899 get_uint16(ramBase + NETWAVE_EREG_ARW),
900 get_uint16(ramBase + NETWAVE_EREG_ARW+2));
904 cs_error(link->handle, last_fn, last_ret);
906 netwave_release(link);
907 } /* netwave_pcmcia_config */
910 * Function netwave_release (arg)
912 * After a card is removed, netwave_release() will unregister the net
913 * device, and release the PCMCIA configuration. If the device is
914 * still open, this will be postponed until it is closed.
916 static void netwave_release(dev_link_t *link)
918 struct net_device *dev = link->priv;
919 netwave_private *priv = netdev_priv(dev);
921 DEBUG(0, "netwave_release(0x%p)\n", link);
923 /* Don't bother checking to see if these succeed or not */
925 iounmap(priv->ramBase);
926 pcmcia_release_window(link->win);
928 pcmcia_release_configuration(link->handle);
929 pcmcia_release_io(link->handle, &link->io);
930 pcmcia_release_irq(link->handle, &link->irq);
932 link->state &= ~DEV_CONFIG;
935 static int netwave_suspend(struct pcmcia_device *p_dev)
937 dev_link_t *link = dev_to_instance(p_dev);
938 struct net_device *dev = link->priv;
940 link->state |= DEV_SUSPEND;
941 if (link->state & DEV_CONFIG) {
943 netif_device_detach(dev);
944 pcmcia_release_configuration(link->handle);
950 static int netwave_resume(struct pcmcia_device *p_dev)
952 dev_link_t *link = dev_to_instance(p_dev);
953 struct net_device *dev = link->priv;
955 link->state &= ~DEV_SUSPEND;
956 if (link->state & DEV_CONFIG) {
957 pcmcia_request_configuration(link->handle, &link->conf);
960 netif_device_attach(dev);
969 * Function netwave_event (event, priority, args)
971 * The card status event handler. Mostly, this schedules other
972 * stuff to run after an event is received. A CARD_REMOVAL event
973 * also sets some flags to discourage the net drivers from trying
974 * to talk to the card any more.
976 * When a CARD_REMOVAL event is received, we immediately set a flag
977 * to block future accesses to this device. All the functions that
978 * actually access the device should check this flag to make sure
979 * the card is still present.
982 static int netwave_event(event_t event, int priority,
983 event_callback_args_t *args)
985 dev_link_t *link = args->client_data;
987 DEBUG(1, "netwave_event(0x%06x)\n", event);
990 case CS_EVENT_CARD_INSERTION:
991 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
992 netwave_pcmcia_config( link);
996 } /* netwave_event */
999 * Function netwave_doreset (ioBase, ramBase)
1001 * Proper hardware reset of the card.
1003 static void netwave_doreset(kio_addr_t ioBase, u_char __iomem *ramBase)
1007 outb(0x80, ioBase + NETWAVE_REG_PMR);
1008 writeb(0x08, ramBase + NETWAVE_EREG_ASCC); /* Bit 3 is WOC */
1009 outb(0x0, ioBase + NETWAVE_REG_PMR); /* release reset */
1013 * Function netwave_reset (dev)
1015 * Reset and restore all of the netwave registers
1017 static void netwave_reset(struct net_device *dev) {
1019 netwave_private *priv = netdev_priv(dev);
1020 u_char __iomem *ramBase = priv->ramBase;
1021 kio_addr_t iobase = dev->base_addr;
1023 DEBUG(0, "netwave_reset: Done with hardware reset\n");
1025 priv->timeoutCounter = 0;
1028 netwave_doreset(iobase, ramBase);
1029 printk(KERN_DEBUG "netwave_reset: Done with hardware reset\n");
1031 /* Write a NOP to check the card */
1033 writeb(NETWAVE_CMD_NOP, ramBase + NETWAVE_EREG_CB + 0);
1034 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 1);
1036 /* Set receive conf */
1038 writeb(NETWAVE_CMD_SRC, ramBase + NETWAVE_EREG_CB + 0);
1039 writeb(rxConfRxEna + rxConfBcast, ramBase + NETWAVE_EREG_CB + 1);
1040 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 2);
1042 /* Set transmit conf */
1044 writeb(NETWAVE_CMD_STC, ramBase + NETWAVE_EREG_CB + 0);
1045 writeb(txConfTxEna, ramBase + NETWAVE_EREG_CB + 1);
1046 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 2);
1048 /* Now set the MU Domain */
1049 printk(KERN_DEBUG "Setting domain to 0x%x%02x\n", (domain >> 8) & 0x01, domain & 0xff);
1051 writeb(NETWAVE_CMD_SMD, ramBase + NETWAVE_EREG_CB + 0);
1052 writeb(domain & 0xff, ramBase + NETWAVE_EREG_CB + 1);
1053 writeb((domain>>8) & 0x01, ramBase + NETWAVE_EREG_CB + 2);
1054 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 3);
1056 /* Set scramble key */
1057 printk(KERN_DEBUG "Setting scramble key to 0x%x\n", scramble_key);
1059 writeb(NETWAVE_CMD_SSK, ramBase + NETWAVE_EREG_CB + 0);
1060 writeb(scramble_key & 0xff, ramBase + NETWAVE_EREG_CB + 1);
1061 writeb((scramble_key>>8) & 0xff, ramBase + NETWAVE_EREG_CB + 2);
1062 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 3);
1064 /* Enable interrupts, bit 4 high to keep unused
1065 * source from interrupting us, bit 2 high to
1066 * set interrupt enable, 567 to enable TxDN,
1070 outb(imrConfIENA+imrConfRFU1, iobase + NETWAVE_REG_IMR);
1072 /* Hent 4 bytes fra 0x170. Skal vaere 0a,29,88,36
1074 * skriv 80 til d000:3688
1075 * sjekk om det ble 80
1078 /* Enable Receiver */
1080 writeb(NETWAVE_CMD_ER, ramBase + NETWAVE_EREG_CB + 0);
1081 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 1);
1083 /* Set the IENA bit in COR */
1085 outb(corConfIENA + corConfLVLREQ, iobase + NETWAVE_REG_COR);
1089 * Function netwave_hw_xmit (data, len, dev)
1091 static int netwave_hw_xmit(unsigned char* data, int len,
1092 struct net_device* dev) {
1093 unsigned long flags;
1094 unsigned int TxFreeList,
1100 netwave_private *priv = netdev_priv(dev);
1101 u_char __iomem * ramBase = priv->ramBase;
1102 kio_addr_t iobase = dev->base_addr;
1104 /* Disable interrupts & save flags */
1105 spin_lock_irqsave(&priv->spinlock, flags);
1107 /* Check if there are transmit buffers available */
1109 if ((inb(iobase+NETWAVE_REG_ASR) & NETWAVE_ASR_TXBA) == 0) {
1110 /* No buffers available */
1111 printk(KERN_DEBUG "netwave_hw_xmit: %s - no xmit buffers available.\n",
1113 spin_unlock_irqrestore(&priv->spinlock, flags);
1117 priv->stats.tx_bytes += len;
1119 DEBUG(3, "Transmitting with SPCQ %x SPU %x LIF %x ISPLQ %x\n",
1120 readb(ramBase + NETWAVE_EREG_SPCQ),
1121 readb(ramBase + NETWAVE_EREG_SPU),
1122 readb(ramBase + NETWAVE_EREG_LIF),
1123 readb(ramBase + NETWAVE_EREG_ISPLQ));
1125 /* Now try to insert it into the adapters free memory */
1127 TxFreeList = get_uint16(ramBase + NETWAVE_EREG_TDP);
1128 MaxData = get_uint16(ramBase + NETWAVE_EREG_TDP+2);
1129 DataOffset = get_uint16(ramBase + NETWAVE_EREG_TDP+4);
1131 DEBUG(3, "TxFreeList %x, MaxData %x, DataOffset %x\n",
1132 TxFreeList, MaxData, DataOffset);
1134 /* Copy packet to the adapter fragment buffers */
1135 curBuff = TxFreeList;
1137 while (tmpcount < len) {
1138 int tmplen = len - tmpcount;
1139 copy_to_pc(ramBase + curBuff + DataOffset, data + tmpcount,
1140 (tmplen < MaxData) ? tmplen : MaxData);
1141 tmpcount += MaxData;
1143 /* Advance to next buffer */
1144 curBuff = get_uint16(ramBase + curBuff);
1147 /* Now issue transmit list */
1149 writeb(NETWAVE_CMD_TL, ramBase + NETWAVE_EREG_CB + 0);
1150 writeb(len & 0xff, ramBase + NETWAVE_EREG_CB + 1);
1151 writeb((len>>8) & 0xff, ramBase + NETWAVE_EREG_CB + 2);
1152 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 3);
1154 spin_unlock_irqrestore(&priv->spinlock, flags);
1158 static int netwave_start_xmit(struct sk_buff *skb, struct net_device *dev) {
1159 /* This flag indicate that the hardware can't perform a transmission.
1160 * Theoritically, NET3 check it before sending a packet to the driver,
1161 * but in fact it never do that and pool continuously.
1162 * As the watchdog will abort too long transmissions, we are quite safe...
1165 netif_stop_queue(dev);
1168 short length = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
1169 unsigned char* buf = skb->data;
1171 if (netwave_hw_xmit( buf, length, dev) == 1) {
1172 /* Some error, let's make them call us another time? */
1173 netif_start_queue(dev);
1175 dev->trans_start = jiffies;
1180 } /* netwave_start_xmit */
1183 * Function netwave_interrupt (irq, dev_id, regs)
1185 * This function is the interrupt handler for the Netwave card. This
1186 * routine will be called whenever:
1187 * 1. A packet is received.
1188 * 2. A packet has successfully been transferred and the unit is
1189 * ready to transmit another packet.
1190 * 3. A command has completed execution.
1192 static irqreturn_t netwave_interrupt(int irq, void* dev_id, struct pt_regs *regs)
1195 u_char __iomem *ramBase;
1196 struct net_device *dev = (struct net_device *)dev_id;
1197 struct netwave_private *priv = netdev_priv(dev);
1198 dev_link_t *link = &priv->link;
1201 if (!netif_device_present(dev))
1204 iobase = dev->base_addr;
1205 ramBase = priv->ramBase;
1207 /* Now find what caused the interrupt, check while interrupts ready */
1208 for (i = 0; i < 10; i++) {
1212 if (!(inb(iobase+NETWAVE_REG_CCSR) & 0x02))
1213 break; /* None of the interrupt sources asserted (normal exit) */
1215 status = inb(iobase + NETWAVE_REG_ASR);
1217 if (!DEV_OK(link)) {
1218 DEBUG(1, "netwave_interrupt: Interrupt with status 0x%x "
1219 "from removed or suspended card!\n", status);
1224 if (status & 0x80) {
1226 /* wait_WOC(iobase); */
1227 /* RxRdy cannot be reset directly by the host */
1230 if (status & 0x40) {
1233 rser = readb(ramBase + NETWAVE_EREG_RSER);
1236 ++priv->stats.rx_dropped;
1237 ++priv->stats.rx_crc_errors;
1240 ++priv->stats.rx_frame_errors;
1242 /* Clear the RxErr bit in RSER. RSER+4 is the
1243 * write part. Also clear the RxCRC (0x04) and
1244 * RxBig (0x02) bits if present */
1246 writeb(0x40 | (rser & 0x06), ramBase + NETWAVE_EREG_RSER + 4);
1248 /* Write bit 6 high to ASCC to clear RxErr in ASR,
1249 * WOC must be set first!
1252 writeb(0x40, ramBase + NETWAVE_EREG_ASCC);
1254 /* Remember to count up priv->stats on error packets */
1255 ++priv->stats.rx_errors;
1258 if (status & 0x20) {
1261 txStatus = readb(ramBase + NETWAVE_EREG_TSER);
1262 DEBUG(3, "Transmit done. TSER = %x id %x\n",
1263 txStatus, readb(ramBase + NETWAVE_EREG_TSER + 1));
1265 if (txStatus & 0x20) {
1266 /* Transmitting was okay, clear bits */
1268 writeb(0x2f, ramBase + NETWAVE_EREG_TSER + 4);
1269 ++priv->stats.tx_packets;
1272 if (txStatus & 0xd0) {
1273 if (txStatus & 0x80) {
1274 ++priv->stats.collisions; /* Because of /proc/net/dev*/
1275 /* ++priv->stats.tx_aborted_errors; */
1276 /* printk("Collision. %ld\n", jiffies - dev->trans_start); */
1278 if (txStatus & 0x40)
1279 ++priv->stats.tx_carrier_errors;
1280 /* 0x80 TxGU Transmit giveup - nine times and no luck
1281 * 0x40 TxNOAP No access point. Discarded packet.
1282 * 0x10 TxErr Transmit error. Always set when
1283 * TxGU and TxNOAP is set. (Those are the only ones
1286 DEBUG(3, "netwave_interrupt: TxDN with error status %x\n",
1289 /* Clear out TxGU, TxNOAP, TxErr and TxTrys */
1291 writeb(0xdf & txStatus, ramBase+NETWAVE_EREG_TSER+4);
1292 ++priv->stats.tx_errors;
1294 DEBUG(3, "New status is TSER %x ASR %x\n",
1295 readb(ramBase + NETWAVE_EREG_TSER),
1296 inb(iobase + NETWAVE_REG_ASR));
1298 netif_wake_queue(dev);
1300 /* TxBA, this would trigger on all error packets received */
1301 /* if (status & 0x01) {
1302 DEBUG(4, "Transmit buffers available, %x\n", status);
1306 /* Handled if we looped at least one time - Jean II */
1307 return IRQ_RETVAL(i);
1308 } /* netwave_interrupt */
1311 * Function netwave_watchdog (a)
1313 * Watchdog : when we start a transmission, we set a timer in the
1314 * kernel. If the transmission complete, this timer is disabled. If
1315 * it expire, we reset the card.
1318 static void netwave_watchdog(struct net_device *dev) {
1320 DEBUG(1, "%s: netwave_watchdog: watchdog timer expired\n", dev->name);
1322 dev->trans_start = jiffies;
1323 netif_wake_queue(dev);
1324 } /* netwave_watchdog */
1326 static struct net_device_stats *netwave_get_stats(struct net_device *dev) {
1327 netwave_private *priv = netdev_priv(dev);
1331 DEBUG(2, "netwave: SPCQ %x SPU %x LIF %x ISPLQ %x MHS %x rxtx %x"
1332 " %x tx %x %x %x %x\n",
1333 readb(priv->ramBase + NETWAVE_EREG_SPCQ),
1334 readb(priv->ramBase + NETWAVE_EREG_SPU),
1335 readb(priv->ramBase + NETWAVE_EREG_LIF),
1336 readb(priv->ramBase + NETWAVE_EREG_ISPLQ),
1337 readb(priv->ramBase + NETWAVE_EREG_MHS),
1338 readb(priv->ramBase + NETWAVE_EREG_EC + 0xe),
1339 readb(priv->ramBase + NETWAVE_EREG_EC + 0xf),
1340 readb(priv->ramBase + NETWAVE_EREG_EC + 0x18),
1341 readb(priv->ramBase + NETWAVE_EREG_EC + 0x19),
1342 readb(priv->ramBase + NETWAVE_EREG_EC + 0x1a),
1343 readb(priv->ramBase + NETWAVE_EREG_EC + 0x1b));
1345 return &priv->stats;
1348 static void update_stats(struct net_device *dev) {
1349 //unsigned long flags;
1350 /* netwave_private *priv = netdev_priv(dev); */
1352 //spin_lock_irqsave(&priv->spinlock, flags);
1354 /* priv->stats.rx_packets = readb(priv->ramBase + 0x18e);
1355 priv->stats.tx_packets = readb(priv->ramBase + 0x18f); */
1357 //spin_unlock_irqrestore(&priv->spinlock, flags);
1360 static int netwave_rx(struct net_device *dev)
1362 netwave_private *priv = netdev_priv(dev);
1363 u_char __iomem *ramBase = priv->ramBase;
1364 kio_addr_t iobase = dev->base_addr;
1366 struct sk_buff *skb = NULL;
1367 unsigned int curBuffer,
1371 int dataCount, dataOffset;
1375 DEBUG(3, "xinw_rx: Receiving ... \n");
1377 /* Receive max 10 packets for now. */
1378 for (i = 0; i < 10; i++) {
1381 rxStatus = readb(ramBase + NETWAVE_EREG_RSER);
1382 if ( !( rxStatus & 0x80)) /* No more packets */
1385 /* Check if multicast/broadcast or other */
1386 /* multicast = (rxStatus & 0x20); */
1388 /* The receive list pointer and length of the packet */
1390 rcvLen = get_int16( ramBase + NETWAVE_EREG_RDP);
1391 rcvList = get_uint16( ramBase + NETWAVE_EREG_RDP + 2);
1394 printk(KERN_DEBUG "netwave_rx: Receive packet with len %d\n",
1399 skb = dev_alloc_skb(rcvLen+5);
1401 DEBUG(1, "netwave_rx: Could not allocate an sk_buff of "
1402 "length %d\n", rcvLen);
1403 ++priv->stats.rx_dropped;
1404 /* Tell the adapter to skip the packet */
1406 writeb(NETWAVE_CMD_SRP, ramBase + NETWAVE_EREG_CB + 0);
1407 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 1);
1411 skb_reserve( skb, 2); /* Align IP on 16 byte */
1412 skb_put( skb, rcvLen);
1415 /* Copy packet fragments to the skb data area */
1416 ptr = (u_char*) skb->data;
1417 curBuffer = rcvList;
1419 while ( tmpcount < rcvLen) {
1420 /* Get length and offset of current buffer */
1421 dataCount = get_uint16( ramBase+curBuffer+2);
1422 dataOffset = get_uint16( ramBase+curBuffer+4);
1424 copy_from_pc( ptr + tmpcount,
1425 ramBase+curBuffer+dataOffset, dataCount);
1427 tmpcount += dataCount;
1429 /* Point to next buffer */
1430 curBuffer = get_uint16(ramBase + curBuffer);
1433 skb->protocol = eth_type_trans(skb,dev);
1434 /* Queue packet for network layer */
1437 dev->last_rx = jiffies;
1438 priv->stats.rx_packets++;
1439 priv->stats.rx_bytes += rcvLen;
1441 /* Got the packet, tell the adapter to skip it */
1443 writeb(NETWAVE_CMD_SRP, ramBase + NETWAVE_EREG_CB + 0);
1444 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 1);
1445 DEBUG(3, "Packet reception ok\n");
1450 static int netwave_open(struct net_device *dev) {
1451 netwave_private *priv = netdev_priv(dev);
1452 dev_link_t *link = &priv->link;
1454 DEBUG(1, "netwave_open: starting.\n");
1461 netif_start_queue(dev);
1467 static int netwave_close(struct net_device *dev) {
1468 netwave_private *priv = netdev_priv(dev);
1469 dev_link_t *link = &priv->link;
1471 DEBUG(1, "netwave_close: finishing.\n");
1474 netif_stop_queue(dev);
1479 static struct pcmcia_device_id netwave_ids[] = {
1480 PCMCIA_DEVICE_PROD_ID12("Xircom", "CreditCard Netwave", 0x2e3ee845, 0x54e28a28),
1483 MODULE_DEVICE_TABLE(pcmcia, netwave_ids);
1485 static struct pcmcia_driver netwave_driver = {
1486 .owner = THIS_MODULE,
1488 .name = "netwave_cs",
1490 .attach = netwave_attach,
1491 .event = netwave_event,
1492 .remove = netwave_detach,
1493 .id_table = netwave_ids,
1494 .suspend = netwave_suspend,
1495 .resume = netwave_resume,
1498 static int __init init_netwave_cs(void)
1500 return pcmcia_register_driver(&netwave_driver);
1503 static void __exit exit_netwave_cs(void)
1505 pcmcia_unregister_driver(&netwave_driver);
1506 BUG_ON(dev_list != NULL);
1509 module_init(init_netwave_cs);
1510 module_exit(exit_netwave_cs);
1512 /* Set or clear the multicast filter for this adaptor.
1513 num_addrs == -1 Promiscuous mode, receive all packets
1514 num_addrs == 0 Normal mode, clear multicast list
1515 num_addrs > 0 Multicast mode, receive normal and MC packets, and do
1516 best-effort filtering.
1518 static void set_multicast_list(struct net_device *dev)
1520 kio_addr_t iobase = dev->base_addr;
1521 netwave_private *priv = netdev_priv(dev);
1522 u_char __iomem * ramBase = priv->ramBase;
1528 if (old != dev->mc_count) {
1529 old = dev->mc_count;
1530 DEBUG(0, "%s: setting Rx mode to %d addresses.\n",
1531 dev->name, dev->mc_count);
1536 if (dev->mc_count || (dev->flags & IFF_ALLMULTI)) {
1537 /* Multicast Mode */
1538 rcvMode = rxConfRxEna + rxConfAMP + rxConfBcast;
1539 } else if (dev->flags & IFF_PROMISC) {
1540 /* Promiscous mode */
1541 rcvMode = rxConfRxEna + rxConfPro + rxConfAMP + rxConfBcast;
1544 rcvMode = rxConfRxEna + rxConfBcast;
1547 /* printk("netwave set_multicast_list: rcvMode to %x\n", rcvMode);*/
1548 /* Now set receive mode */
1550 writeb(NETWAVE_CMD_SRC, ramBase + NETWAVE_EREG_CB + 0);
1551 writeb(rcvMode, ramBase + NETWAVE_EREG_CB + 1);
1552 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 2);
1554 MODULE_LICENSE("GPL");