]> bbs.cooldavid.org Git - net-next-2.6.git/blob - drivers/staging/netwave/netwave_cs.c
pcmcia: remove unused mem_op.h
[net-next-2.6.git] / drivers / staging / netwave / netwave_cs.c
1 /*********************************************************************
2  *                
3  * Filename:      netwave_cs.c
4  * Version:       0.4.1
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>
13  * 
14  *     Copyright (c) 1997 University of Tromsø, Norway
15  *
16  * Revision History:
17  *
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)
26  *   Others:
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
31  *      function
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  ********************************************************************/
36
37 /* To have statistics (just packets sent) define this */
38 #undef NETWAVE_STATS
39
40 #include <linux/module.h>
41 #include <linux/kernel.h>
42 #include <linux/init.h>
43 #include <linux/types.h>
44 #include <linux/fcntl.h>
45 #include <linux/interrupt.h>
46 #include <linux/ptrace.h>
47 #include <linux/ioport.h>
48 #include <linux/in.h>
49 #include <linux/string.h>
50 #include <linux/timer.h>
51 #include <linux/errno.h>
52 #include <linux/netdevice.h>
53 #include <linux/etherdevice.h>
54 #include <linux/skbuff.h>
55 #include <linux/bitops.h>
56 #include <linux/wireless.h>
57 #include <net/iw_handler.h>
58
59 #include <pcmcia/cs_types.h>
60 #include <pcmcia/cs.h>
61 #include <pcmcia/cistpl.h>
62 #include <pcmcia/cisreg.h>
63 #include <pcmcia/ds.h>
64
65 #include <asm/system.h>
66 #include <asm/io.h>
67 #include <asm/dma.h>
68
69 #define NETWAVE_REGOFF         0x8000
70 /* The Netwave IO registers, offsets to iobase */
71 #define NETWAVE_REG_COR        0x0
72 #define NETWAVE_REG_CCSR       0x2
73 #define NETWAVE_REG_ASR        0x4
74 #define NETWAVE_REG_IMR        0xa
75 #define NETWAVE_REG_PMR        0xc
76 #define NETWAVE_REG_IOLOW      0x6
77 #define NETWAVE_REG_IOHI       0x7
78 #define NETWAVE_REG_IOCONTROL  0x8
79 #define NETWAVE_REG_DATA       0xf
80 /* The Netwave Extended IO registers, offsets to RamBase */
81 #define NETWAVE_EREG_ASCC      0x114
82 #define NETWAVE_EREG_RSER      0x120
83 #define NETWAVE_EREG_RSERW     0x124
84 #define NETWAVE_EREG_TSER      0x130
85 #define NETWAVE_EREG_TSERW     0x134
86 #define NETWAVE_EREG_CB        0x100
87 #define NETWAVE_EREG_SPCQ      0x154
88 #define NETWAVE_EREG_SPU       0x155
89 #define NETWAVE_EREG_LIF       0x14e
90 #define NETWAVE_EREG_ISPLQ     0x156
91 #define NETWAVE_EREG_HHC       0x158
92 #define NETWAVE_EREG_NI        0x16e
93 #define NETWAVE_EREG_MHS       0x16b
94 #define NETWAVE_EREG_TDP       0x140
95 #define NETWAVE_EREG_RDP       0x150
96 #define NETWAVE_EREG_PA        0x160
97 #define NETWAVE_EREG_EC        0x180
98 #define NETWAVE_EREG_CRBP      0x17a
99 #define NETWAVE_EREG_ARW       0x166
100
101 /*
102  * Commands used in the extended command buffer
103  * NETWAVE_EREG_CB (0x100-0x10F) 
104  */
105 #define NETWAVE_CMD_NOP        0x00
106 #define NETWAVE_CMD_SRC        0x01
107 #define NETWAVE_CMD_STC        0x02
108 #define NETWAVE_CMD_AMA        0x03
109 #define NETWAVE_CMD_DMA        0x04
110 #define NETWAVE_CMD_SAMA       0x05
111 #define NETWAVE_CMD_ER         0x06
112 #define NETWAVE_CMD_DR         0x07
113 #define NETWAVE_CMD_TL         0x08
114 #define NETWAVE_CMD_SRP        0x09
115 #define NETWAVE_CMD_SSK        0x0a
116 #define NETWAVE_CMD_SMD        0x0b
117 #define NETWAVE_CMD_SAPD       0x0c
118 #define NETWAVE_CMD_SSS        0x11
119 /* End of Command marker */
120 #define NETWAVE_CMD_EOC        0x00
121
122 /* ASR register bits */
123 #define NETWAVE_ASR_RXRDY   0x80
124 #define NETWAVE_ASR_TXBA    0x01
125
126 #define TX_TIMEOUT              ((32*HZ)/100)
127
128 static const unsigned int imrConfRFU1 = 0x10; /* RFU interrupt mask, keep high */
129 static const unsigned int imrConfIENA = 0x02; /* Interrupt enable */
130
131 static const unsigned int corConfIENA   = 0x01; /* Interrupt enable */
132 static const unsigned int corConfLVLREQ = 0x40; /* Keep high */
133
134 static const unsigned int rxConfRxEna  = 0x80; /* Receive Enable */
135 static const unsigned int rxConfMAC    = 0x20; /* MAC host receive mode*/ 
136 static const unsigned int rxConfPro    = 0x10; /* Promiscuous */
137 static const unsigned int rxConfAMP    = 0x08; /* Accept Multicast Packets */
138 static const unsigned int rxConfBcast  = 0x04; /* Accept Broadcast Packets */
139
140 static const unsigned int txConfTxEna  = 0x80; /* Transmit Enable */
141 static const unsigned int txConfMAC    = 0x20; /* Host sends MAC mode */
142 static const unsigned int txConfEUD    = 0x10; /* Enable Uni-Data packets */
143 static const unsigned int txConfKey    = 0x02; /* Scramble data packets */
144 static const unsigned int txConfLoop   = 0x01; /* Loopback mode */
145
146
147 /*====================================================================*/
148
149 /* Parameters that can be set with 'insmod' */
150
151 /* Choose the domain, default is 0x100 */
152 static u_int  domain = 0x100;
153
154 /* Scramble key, range from 0x0 to 0xffff.  
155  * 0x0 is no scrambling. 
156  */
157 static u_int  scramble_key = 0x0;
158
159 /* Shared memory speed, in ns. The documentation states that 
160  * the card should not be read faster than every 400ns. 
161  * This timing should be provided by the HBA. If it becomes a 
162  * problem, try setting mem_speed to 400. 
163  */
164 static int mem_speed;
165
166 module_param(domain, int, 0);
167 module_param(scramble_key, int, 0);
168 module_param(mem_speed, int, 0);
169
170 /*====================================================================*/
171
172 /* PCMCIA (Card Services) related functions */
173 static void netwave_release(struct pcmcia_device *link);     /* Card removal */
174 static int netwave_pcmcia_config(struct pcmcia_device *arg); /* Runs after card
175                                                                                                            insertion */
176 static void netwave_detach(struct pcmcia_device *p_dev);    /* Destroy instance */
177
178 /* Hardware configuration */
179 static void netwave_doreset(unsigned int iobase, u_char __iomem *ramBase);
180 static void netwave_reset(struct net_device *dev);
181
182 /* Misc device stuff */
183 static int netwave_open(struct net_device *dev);  /* Open the device */
184 static int netwave_close(struct net_device *dev); /* Close the device */
185
186 /* Packet transmission and Packet reception */
187 static netdev_tx_t netwave_start_xmit( struct sk_buff *skb,
188                                              struct net_device *dev);
189 static int netwave_rx( struct net_device *dev);
190
191 /* Interrupt routines */
192 static irqreturn_t netwave_interrupt(int irq, void *dev_id);
193 static void netwave_watchdog(struct net_device *);
194
195 /* Wireless extensions */
196 static struct iw_statistics* netwave_get_wireless_stats(struct net_device *dev);
197
198 static void set_multicast_list(struct net_device *dev);
199
200 /*
201    A struct pcmcia_device structure has fields for most things that are needed
202    to keep track of a socket, but there will usually be some device
203    specific information that also needs to be kept track of.  The
204    'priv' pointer in a struct pcmcia_device structure can be used to point to
205    a device-specific private data structure, like this.
206
207    A driver needs to provide a dev_node_t structure for each device
208    on a card.  In some cases, there is only one device per card (for
209    example, ethernet cards, modems).  In other cases, there may be
210    many actual or logical devices (SCSI adapters, memory cards with
211    multiple partitions).  The dev_node_t structures need to be kept
212    in a linked list starting at the 'dev' field of a struct pcmcia_device
213    structure.  We allocate them in the card's private data structure,
214    because they generally can't be allocated dynamically.
215 */
216
217 static const struct iw_handler_def      netwave_handler_def;
218
219 #define SIOCGIPSNAP     SIOCIWFIRSTPRIV + 1     /* Site Survey Snapshot */
220
221 #define MAX_ESA 10
222
223 typedef struct net_addr {
224     u_char addr48[6];
225 } net_addr;
226
227 struct site_survey {
228     u_short length;
229     u_char  struct_revision;
230     u_char  roaming_state;
231         
232     u_char  sp_existsFlag;
233     u_char  sp_link_quality;
234     u_char  sp_max_link_quality;
235     u_char  linkQualityGoodFairBoundary;
236     u_char  linkQualityFairPoorBoundary;
237     u_char  sp_utilization;
238     u_char  sp_goodness;
239     u_char  sp_hotheadcount;
240     u_char  roaming_condition;
241         
242     net_addr sp;
243     u_char   numAPs;
244     net_addr nearByAccessPoints[MAX_ESA];
245 };      
246    
247 typedef struct netwave_private {
248         struct pcmcia_device    *p_dev;
249     spinlock_t  spinlock;       /* Serialize access to the hardware (SMP) */
250     dev_node_t node;
251     u_char     __iomem *ramBase;
252     int        timeoutCounter;
253     int        lastExec;
254     struct timer_list      watchdog;    /* To avoid blocking state */
255     struct site_survey     nss;
256     struct iw_statistics   iw_stats;    /* Wireless stats */
257 } netwave_private;
258
259 /*
260  * The Netwave card is little-endian, so won't work for big endian
261  * systems.
262  */
263 static inline unsigned short get_uint16(u_char __iomem *staddr) 
264 {
265     return readw(staddr); /* Return only 16 bits */
266 }
267
268 static inline short get_int16(u_char __iomem * staddr)
269 {
270     return readw(staddr);
271 }
272
273 /* 
274  * Wait until the WOC (Write Operation Complete) bit in the 
275  * ASR (Adapter Status Register) is asserted. 
276  * This should have aborted if it takes too long time. 
277  */
278 static inline void wait_WOC(unsigned int iobase)
279 {
280     /* Spin lock */
281     while ((inb(iobase + NETWAVE_REG_ASR) & 0x8) != 0x8) ; 
282 }
283
284 static void netwave_snapshot(netwave_private *priv, u_char __iomem *ramBase, 
285                              unsigned int iobase) {
286     u_short resultBuffer;
287
288     /* if time since last snapshot is > 1 sec. (100 jiffies?)  then take 
289      * new snapshot, else return cached data. This is the recommended rate.  
290      */
291     if ( jiffies - priv->lastExec > 100) { 
292         /* Take site survey  snapshot */ 
293         /*printk( KERN_DEBUG "Taking new snapshot. %ld\n", jiffies -
294           priv->lastExec); */
295         wait_WOC(iobase); 
296         writeb(NETWAVE_CMD_SSS, ramBase + NETWAVE_EREG_CB + 0); 
297         writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 1); 
298         wait_WOC(iobase); 
299
300         /* Get result and copy to cach */ 
301         resultBuffer = readw(ramBase + NETWAVE_EREG_CRBP); 
302         copy_from_pc( &priv->nss, ramBase+resultBuffer, 
303                       sizeof(struct site_survey)); 
304     } 
305 }
306
307 /*
308  * Function netwave_get_wireless_stats (dev)
309  *
310  *    Wireless extensions statistics
311  *
312  */
313 static struct iw_statistics *netwave_get_wireless_stats(struct net_device *dev)
314 {       
315     unsigned long flags;
316     unsigned int iobase = dev->base_addr;
317     netwave_private *priv = netdev_priv(dev);
318     u_char __iomem *ramBase = priv->ramBase;
319     struct iw_statistics* wstats;
320         
321     wstats = &priv->iw_stats;
322
323     spin_lock_irqsave(&priv->spinlock, flags);
324         
325     netwave_snapshot( priv, ramBase, iobase);
326
327     wstats->status = priv->nss.roaming_state;
328     wstats->qual.qual = readb( ramBase + NETWAVE_EREG_SPCQ); 
329     wstats->qual.level = readb( ramBase + NETWAVE_EREG_ISPLQ);
330     wstats->qual.noise = readb( ramBase + NETWAVE_EREG_SPU) & 0x3f;
331     wstats->discard.nwid = 0L;
332     wstats->discard.code = 0L;
333     wstats->discard.misc = 0L;
334
335     spin_unlock_irqrestore(&priv->spinlock, flags);
336     
337     return &priv->iw_stats;
338 }
339
340 static const struct net_device_ops netwave_netdev_ops = {
341         .ndo_open               = netwave_open,
342         .ndo_stop               = netwave_close,
343         .ndo_start_xmit         = netwave_start_xmit,
344         .ndo_set_multicast_list = set_multicast_list,
345         .ndo_tx_timeout         = netwave_watchdog,
346         .ndo_change_mtu         = eth_change_mtu,
347         .ndo_set_mac_address    = eth_mac_addr,
348         .ndo_validate_addr      = eth_validate_addr,
349 };
350
351 /*
352  * Function netwave_attach (void)
353  *
354  *     Creates an "instance" of the driver, allocating local data 
355  *     structures for one device.  The device is registered with Card 
356  *     Services.
357  *
358  *     The dev_link structure is initialized, but we don't actually
359  *     configure the card at this point -- we wait until we receive a
360  *     card insertion event.
361  */
362 static int netwave_probe(struct pcmcia_device *link)
363 {
364     struct net_device *dev;
365     netwave_private *priv;
366
367     dev_dbg(&link->dev, "netwave_attach()\n");
368
369     /* Initialize the struct pcmcia_device structure */
370     dev = alloc_etherdev(sizeof(netwave_private));
371     if (!dev)
372         return -ENOMEM;
373     priv = netdev_priv(dev);
374     priv->p_dev = link;
375     link->priv = dev;
376
377     /* The io structure describes IO port mapping */
378     link->io.NumPorts1 = 16;
379     link->io.Attributes1 = IO_DATA_PATH_WIDTH_16;
380     /* link->io.NumPorts2 = 16; 
381        link->io.Attributes2 = IO_DATA_PATH_WIDTH_16; */
382     link->io.IOAddrLines = 5;
383     
384     /* General socket configuration */
385     link->conf.Attributes = CONF_ENABLE_IRQ;
386     link->conf.IntType = INT_MEMORY_AND_IO;
387     link->conf.ConfigIndex = 1;
388
389     /* Netwave private struct init. link/dev/node already taken care of,
390      * other stuff zero'd - Jean II */
391     spin_lock_init(&priv->spinlock);
392
393     /* Netwave specific entries in the device structure */
394     dev->netdev_ops = &netwave_netdev_ops;
395     /* wireless extensions */
396     dev->wireless_handlers = &netwave_handler_def;
397
398     dev->watchdog_timeo = TX_TIMEOUT;
399
400     return netwave_pcmcia_config( link);
401 } /* netwave_attach */
402
403 /*
404  * Function netwave_detach (link)
405  *
406  *    This deletes a driver "instance".  The device is de-registered
407  *    with Card Services.  If it has been released, all local data
408  *    structures are freed.  Otherwise, the structures will be freed
409  *    when the device is released.
410  */
411 static void netwave_detach(struct pcmcia_device *link)
412 {
413         struct net_device *dev = link->priv;
414
415         dev_dbg(&link->dev, "netwave_detach\n");
416
417         netwave_release(link);
418
419         if (link->dev_node)
420                 unregister_netdev(dev);
421
422         free_netdev(dev);
423 } /* netwave_detach */
424
425 /*
426  * Wireless Handler : get protocol name
427  */
428 static int netwave_get_name(struct net_device *dev,
429                             struct iw_request_info *info,
430                             union iwreq_data *wrqu,
431                             char *extra)
432 {
433         strcpy(wrqu->name, "Netwave");
434         return 0;
435 }
436
437 /*
438  * Wireless Handler : set Network ID
439  */
440 static int netwave_set_nwid(struct net_device *dev,
441                             struct iw_request_info *info,
442                             union iwreq_data *wrqu,
443                             char *extra)
444 {
445         unsigned long flags;
446         unsigned int iobase = dev->base_addr;
447         netwave_private *priv = netdev_priv(dev);
448         u_char __iomem *ramBase = priv->ramBase;
449
450         /* Disable interrupts & save flags */
451         spin_lock_irqsave(&priv->spinlock, flags);
452
453         if(!wrqu->nwid.disabled) {
454             domain = wrqu->nwid.value;
455             printk( KERN_DEBUG "Setting domain to 0x%x%02x\n", 
456                     (domain >> 8) & 0x01, domain & 0xff);
457             wait_WOC(iobase);
458             writeb(NETWAVE_CMD_SMD, ramBase + NETWAVE_EREG_CB + 0);
459             writeb( domain & 0xff, ramBase + NETWAVE_EREG_CB + 1);
460             writeb((domain >>8 ) & 0x01,ramBase + NETWAVE_EREG_CB+2);
461             writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 3);
462         }
463
464         /* ReEnable interrupts & restore flags */
465         spin_unlock_irqrestore(&priv->spinlock, flags);
466     
467         return 0;
468 }
469
470 /*
471  * Wireless Handler : get Network ID
472  */
473 static int netwave_get_nwid(struct net_device *dev,
474                             struct iw_request_info *info,
475                             union iwreq_data *wrqu,
476                             char *extra)
477 {
478         wrqu->nwid.value = domain;
479         wrqu->nwid.disabled = 0;
480         wrqu->nwid.fixed = 1;
481         return 0;
482 }
483
484 /*
485  * Wireless Handler : set scramble key
486  */
487 static int netwave_set_scramble(struct net_device *dev,
488                                 struct iw_request_info *info,
489                                 union iwreq_data *wrqu,
490                                 char *key)
491 {
492         unsigned long flags;
493         unsigned int iobase = dev->base_addr;
494         netwave_private *priv = netdev_priv(dev);
495         u_char __iomem *ramBase = priv->ramBase;
496
497         /* Disable interrupts & save flags */
498         spin_lock_irqsave(&priv->spinlock, flags);
499
500         scramble_key = (key[0] << 8) | key[1];
501         wait_WOC(iobase);
502         writeb(NETWAVE_CMD_SSK, ramBase + NETWAVE_EREG_CB + 0);
503         writeb(scramble_key & 0xff, ramBase + NETWAVE_EREG_CB + 1);
504         writeb((scramble_key>>8) & 0xff, ramBase + NETWAVE_EREG_CB + 2);
505         writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 3);
506
507         /* ReEnable interrupts & restore flags */
508         spin_unlock_irqrestore(&priv->spinlock, flags);
509     
510         return 0;
511 }
512
513 /*
514  * Wireless Handler : get scramble key
515  */
516 static int netwave_get_scramble(struct net_device *dev,
517                                 struct iw_request_info *info,
518                                 union iwreq_data *wrqu,
519                                 char *key)
520 {
521         key[1] = scramble_key & 0xff;
522         key[0] = (scramble_key>>8) & 0xff;
523         wrqu->encoding.flags = IW_ENCODE_ENABLED;
524         wrqu->encoding.length = 2;
525         return 0;
526 }
527
528 /*
529  * Wireless Handler : get mode
530  */
531 static int netwave_get_mode(struct net_device *dev,
532                             struct iw_request_info *info,
533                             union iwreq_data *wrqu,
534                             char *extra)
535 {
536         if(domain & 0x100)
537                 wrqu->mode = IW_MODE_INFRA;
538         else
539                 wrqu->mode = IW_MODE_ADHOC;
540
541         return 0;
542 }
543
544 /*
545  * Wireless Handler : get range info
546  */
547 static int netwave_get_range(struct net_device *dev,
548                              struct iw_request_info *info,
549                              union iwreq_data *wrqu,
550                              char *extra)
551 {
552         struct iw_range *range = (struct iw_range *) extra;
553         int ret = 0;
554
555         /* Set the length (very important for backward compatibility) */
556         wrqu->data.length = sizeof(struct iw_range);
557
558         /* Set all the info we don't care or don't know about to zero */
559         memset(range, 0, sizeof(struct iw_range));
560
561         /* Set the Wireless Extension versions */
562         range->we_version_compiled = WIRELESS_EXT;
563         range->we_version_source = 9;   /* Nothing for us in v10 and v11 */
564                    
565         /* Set information in the range struct */
566         range->throughput = 450 * 1000; /* don't argue on this ! */
567         range->min_nwid = 0x0000;
568         range->max_nwid = 0x01FF;
569
570         range->num_channels = range->num_frequency = 0;
571                    
572         range->sensitivity = 0x3F;
573         range->max_qual.qual = 255;
574         range->max_qual.level = 255;
575         range->max_qual.noise = 0;
576                    
577         range->num_bitrates = 1;
578         range->bitrate[0] = 1000000;    /* 1 Mb/s */
579
580         range->encoding_size[0] = 2;            /* 16 bits scrambling */
581         range->num_encoding_sizes = 1;
582         range->max_encoding_tokens = 1; /* Only one key possible */
583
584         return ret;
585 }
586
587 /*
588  * Wireless Private Handler : get snapshot
589  */
590 static int netwave_get_snap(struct net_device *dev,
591                             struct iw_request_info *info,
592                             union iwreq_data *wrqu,
593                             char *extra)
594 {
595         unsigned long flags;
596         unsigned int iobase = dev->base_addr;
597         netwave_private *priv = netdev_priv(dev);
598         u_char __iomem *ramBase = priv->ramBase;
599
600         /* Disable interrupts & save flags */
601         spin_lock_irqsave(&priv->spinlock, flags);
602
603         /* Take snapshot of environment */
604         netwave_snapshot( priv, ramBase, iobase);
605         wrqu->data.length = priv->nss.length;
606         memcpy(extra, (u_char *) &priv->nss, sizeof( struct site_survey));
607
608         priv->lastExec = jiffies;
609
610         /* ReEnable interrupts & restore flags */
611         spin_unlock_irqrestore(&priv->spinlock, flags);
612     
613         return(0);
614 }
615
616 /*
617  * Structures to export the Wireless Handlers
618  *     This is the stuff that are treated the wireless extensions (iwconfig)
619  */
620
621 static const struct iw_priv_args netwave_private_args[] = {
622 /*{ cmd,         set_args,                            get_args, name } */
623   { SIOCGIPSNAP, 0, 
624     IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | sizeof(struct site_survey), 
625     "getsitesurvey" },
626 };
627
628 static const iw_handler         netwave_handler[] =
629 {
630         NULL,                           /* SIOCSIWNAME */
631         netwave_get_name,               /* SIOCGIWNAME */
632         netwave_set_nwid,               /* SIOCSIWNWID */
633         netwave_get_nwid,               /* SIOCGIWNWID */
634         NULL,                           /* SIOCSIWFREQ */
635         NULL,                           /* SIOCGIWFREQ */
636         NULL,                           /* SIOCSIWMODE */
637         netwave_get_mode,               /* SIOCGIWMODE */
638         NULL,                           /* SIOCSIWSENS */
639         NULL,                           /* SIOCGIWSENS */
640         NULL,                           /* SIOCSIWRANGE */
641         netwave_get_range,              /* SIOCGIWRANGE */
642         NULL,                           /* SIOCSIWPRIV */
643         NULL,                           /* SIOCGIWPRIV */
644         NULL,                           /* SIOCSIWSTATS */
645         NULL,                           /* SIOCGIWSTATS */
646         NULL,                           /* SIOCSIWSPY */
647         NULL,                           /* SIOCGIWSPY */
648         NULL,                           /* -- hole -- */
649         NULL,                           /* -- hole -- */
650         NULL,                           /* SIOCSIWAP */
651         NULL,                           /* SIOCGIWAP */
652         NULL,                           /* -- hole -- */
653         NULL,                           /* SIOCGIWAPLIST */
654         NULL,                           /* -- hole -- */
655         NULL,                           /* -- hole -- */
656         NULL,                           /* SIOCSIWESSID */
657         NULL,                           /* SIOCGIWESSID */
658         NULL,                           /* SIOCSIWNICKN */
659         NULL,                           /* SIOCGIWNICKN */
660         NULL,                           /* -- hole -- */
661         NULL,                           /* -- hole -- */
662         NULL,                           /* SIOCSIWRATE */
663         NULL,                           /* SIOCGIWRATE */
664         NULL,                           /* SIOCSIWRTS */
665         NULL,                           /* SIOCGIWRTS */
666         NULL,                           /* SIOCSIWFRAG */
667         NULL,                           /* SIOCGIWFRAG */
668         NULL,                           /* SIOCSIWTXPOW */
669         NULL,                           /* SIOCGIWTXPOW */
670         NULL,                           /* SIOCSIWRETRY */
671         NULL,                           /* SIOCGIWRETRY */
672         netwave_set_scramble,           /* SIOCSIWENCODE */
673         netwave_get_scramble,           /* SIOCGIWENCODE */
674 };
675
676 static const iw_handler         netwave_private_handler[] =
677 {
678         NULL,                           /* SIOCIWFIRSTPRIV */
679         netwave_get_snap,               /* SIOCIWFIRSTPRIV + 1 */
680 };
681
682 static const struct iw_handler_def      netwave_handler_def =
683 {
684         .num_standard   = ARRAY_SIZE(netwave_handler),
685         .num_private    = ARRAY_SIZE(netwave_private_handler),
686         .num_private_args = ARRAY_SIZE(netwave_private_args),
687         .standard       = (iw_handler *) netwave_handler,
688         .private        = (iw_handler *) netwave_private_handler,
689         .private_args   = (struct iw_priv_args *) netwave_private_args,
690         .get_wireless_stats = netwave_get_wireless_stats,
691 };
692
693 /*
694  * Function netwave_pcmcia_config (link)
695  *
696  *     netwave_pcmcia_config() is scheduled to run after a CARD_INSERTION 
697  *     event is received, to configure the PCMCIA socket, and to make the
698  *     device available to the system. 
699  *
700  */
701
702 static int netwave_pcmcia_config(struct pcmcia_device *link) {
703     struct net_device *dev = link->priv;
704     netwave_private *priv = netdev_priv(dev);
705     int i, j, ret;
706     win_req_t req;
707     memreq_t mem;
708     u_char __iomem *ramBase = NULL;
709
710     dev_dbg(&link->dev, "netwave_pcmcia_config\n");
711
712     /*
713      *  Try allocating IO ports.  This tries a few fixed addresses.
714      *  If you want, you can also read the card's config table to
715      *  pick addresses -- see the serial driver for an example.
716      */
717     for (i = j = 0x0; j < 0x400; j += 0x20) {
718         link->io.BasePort1 = j ^ 0x300;
719         i = pcmcia_request_io(link, &link->io);
720         if (i == 0)
721                 break;
722     }
723     if (i != 0)
724         goto failed;
725
726     /*
727      *  Now allocate an interrupt line.  Note that this does not
728      *  actually assign a handler to the interrupt.
729      */
730     ret = pcmcia_request_irq(link, netwave_interrupt);
731     if (ret)
732             goto failed;
733
734     /*
735      *  This actually configures the PCMCIA socket -- setting up
736      *  the I/O windows and the interrupt mapping.
737      */
738     ret = pcmcia_request_configuration(link, &link->conf);
739     if (ret)
740             goto failed;
741
742     /*
743      *  Allocate a 32K memory window.  Note that the struct pcmcia_device
744      *  structure provides space for one window handle -- if your
745      *  device needs several windows, you'll need to keep track of
746      *  the handles in your private data structure, dev->priv.
747      */
748     dev_dbg(&link->dev, "Setting mem speed of %d\n", mem_speed);
749
750     req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_CM|WIN_ENABLE;
751     req.Base = 0; req.Size = 0x8000;
752     req.AccessSpeed = mem_speed;
753     ret = pcmcia_request_window(link, &req, &link->win);
754     if (ret)
755             goto failed;
756     mem.CardOffset = 0x20000; mem.Page = 0; 
757     ret = pcmcia_map_mem_page(link, link->win, &mem);
758     if (ret)
759             goto failed;
760
761     /* Store base address of the common window frame */
762     ramBase = ioremap(req.Base, 0x8000);
763     priv->ramBase = ramBase;
764
765     dev->irq = link->irq;
766     dev->base_addr = link->io.BasePort1;
767     SET_NETDEV_DEV(dev, &link->dev);
768
769     if (register_netdev(dev) != 0) {
770         printk(KERN_DEBUG "netwave_cs: register_netdev() failed\n");
771         goto failed;
772     }
773
774     strcpy(priv->node.dev_name, dev->name);
775     link->dev_node = &priv->node;
776
777     /* Reset card before reading physical address */
778     netwave_doreset(dev->base_addr, ramBase);
779
780     /* Read the ethernet address and fill in the Netwave registers. */
781     for (i = 0; i < 6; i++) 
782         dev->dev_addr[i] = readb(ramBase + NETWAVE_EREG_PA + i);
783
784     printk(KERN_INFO "%s: Netwave: port %#3lx, irq %d, mem %lx, "
785            "id %c%c, hw_addr %pM\n",
786            dev->name, dev->base_addr, dev->irq,
787            (u_long) ramBase,
788            (int) readb(ramBase+NETWAVE_EREG_NI),
789            (int) readb(ramBase+NETWAVE_EREG_NI+1),
790            dev->dev_addr);
791
792     /* get revision words */
793     printk(KERN_DEBUG "Netwave_reset: revision %04x %04x\n", 
794            get_uint16(ramBase + NETWAVE_EREG_ARW),
795            get_uint16(ramBase + NETWAVE_EREG_ARW+2));
796     return 0;
797
798 failed:
799     netwave_release(link);
800     return -ENODEV;
801 } /* netwave_pcmcia_config */
802
803 /*
804  * Function netwave_release (arg)
805  *
806  *    After a card is removed, netwave_release() will unregister the net
807  *    device, and release the PCMCIA configuration.  If the device is
808  *    still open, this will be postponed until it is closed.
809  */
810 static void netwave_release(struct pcmcia_device *link)
811 {
812         struct net_device *dev = link->priv;
813         netwave_private *priv = netdev_priv(dev);
814
815         dev_dbg(&link->dev, "netwave_release\n");
816
817         pcmcia_disable_device(link);
818         if (link->win)
819                 iounmap(priv->ramBase);
820 }
821
822 static int netwave_suspend(struct pcmcia_device *link)
823 {
824         struct net_device *dev = link->priv;
825
826         if (link->open)
827                 netif_device_detach(dev);
828
829         return 0;
830 }
831
832 static int netwave_resume(struct pcmcia_device *link)
833 {
834         struct net_device *dev = link->priv;
835
836         if (link->open) {
837                 netwave_reset(dev);
838                 netif_device_attach(dev);
839         }
840
841         return 0;
842 }
843
844
845 /*
846  * Function netwave_doreset (ioBase, ramBase)
847  *
848  *    Proper hardware reset of the card.
849  */
850 static void netwave_doreset(unsigned int ioBase, u_char __iomem *ramBase)
851 {
852     /* Reset card */
853     wait_WOC(ioBase);
854     outb(0x80, ioBase + NETWAVE_REG_PMR);
855     writeb(0x08, ramBase + NETWAVE_EREG_ASCC); /* Bit 3 is WOC */
856     outb(0x0, ioBase + NETWAVE_REG_PMR); /* release reset */
857 }
858
859 /*
860  * Function netwave_reset (dev)
861  *
862  *    Reset and restore all of the netwave registers 
863  */
864 static void netwave_reset(struct net_device *dev) {
865     /* u_char state; */
866     netwave_private *priv = netdev_priv(dev);
867     u_char __iomem *ramBase = priv->ramBase;
868     unsigned int iobase = dev->base_addr;
869
870     pr_debug("netwave_reset: Done with hardware reset\n");
871
872     priv->timeoutCounter = 0;
873
874     /* Reset card */
875     netwave_doreset(iobase, ramBase);
876     printk(KERN_DEBUG "netwave_reset: Done with hardware reset\n");
877         
878     /* Write a NOP to check the card */
879     wait_WOC(iobase);
880     writeb(NETWAVE_CMD_NOP, ramBase + NETWAVE_EREG_CB + 0);
881     writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 1);
882         
883     /* Set receive conf */
884     wait_WOC(iobase);
885     writeb(NETWAVE_CMD_SRC, ramBase + NETWAVE_EREG_CB + 0);
886     writeb(rxConfRxEna + rxConfBcast, ramBase + NETWAVE_EREG_CB + 1);
887     writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 2);
888     
889     /* Set transmit conf */
890     wait_WOC(iobase);
891     writeb(NETWAVE_CMD_STC, ramBase + NETWAVE_EREG_CB + 0);
892     writeb(txConfTxEna, ramBase + NETWAVE_EREG_CB + 1);
893     writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 2);
894     
895     /* Now set the MU Domain */
896     printk(KERN_DEBUG "Setting domain to 0x%x%02x\n", (domain >> 8) & 0x01, domain & 0xff);
897     wait_WOC(iobase);
898     writeb(NETWAVE_CMD_SMD, ramBase + NETWAVE_EREG_CB + 0);
899     writeb(domain & 0xff, ramBase + NETWAVE_EREG_CB + 1);
900     writeb((domain>>8) & 0x01, ramBase + NETWAVE_EREG_CB + 2);
901     writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 3);
902         
903     /* Set scramble key */
904     printk(KERN_DEBUG "Setting scramble key to 0x%x\n", scramble_key);
905     wait_WOC(iobase);
906     writeb(NETWAVE_CMD_SSK, ramBase + NETWAVE_EREG_CB + 0);
907     writeb(scramble_key & 0xff, ramBase + NETWAVE_EREG_CB + 1);
908     writeb((scramble_key>>8) & 0xff, ramBase + NETWAVE_EREG_CB + 2);
909     writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 3);
910
911     /* Enable interrupts, bit 4 high to keep unused
912      * source from interrupting us, bit 2 high to 
913      * set interrupt enable, 567 to enable TxDN, 
914      * RxErr and RxRdy
915      */
916     wait_WOC(iobase);
917     outb(imrConfIENA+imrConfRFU1, iobase + NETWAVE_REG_IMR);
918
919     /* Hent 4 bytes fra 0x170. Skal vaere 0a,29,88,36
920      * waitWOC
921      * skriv 80 til d000:3688
922      * sjekk om det ble 80
923      */
924     
925     /* Enable Receiver */
926     wait_WOC(iobase);
927     writeb(NETWAVE_CMD_ER, ramBase + NETWAVE_EREG_CB + 0);
928     writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 1);
929         
930     /* Set the IENA bit in COR */
931     wait_WOC(iobase);
932     outb(corConfIENA + corConfLVLREQ, iobase + NETWAVE_REG_COR);
933 }
934
935 /*
936  * Function netwave_hw_xmit (data, len, dev)    
937  */
938 static int netwave_hw_xmit(unsigned char* data, int len,
939                            struct net_device* dev) {
940     unsigned long flags;
941     unsigned int TxFreeList,
942                  curBuff,
943                  MaxData, 
944                  DataOffset;
945     int tmpcount; 
946         
947     netwave_private *priv = netdev_priv(dev);
948     u_char __iomem * ramBase = priv->ramBase;
949     unsigned int iobase = dev->base_addr;
950
951     /* Disable interrupts & save flags */
952     spin_lock_irqsave(&priv->spinlock, flags);
953
954     /* Check if there are transmit buffers available */
955     wait_WOC(iobase);
956     if ((inb(iobase+NETWAVE_REG_ASR) & NETWAVE_ASR_TXBA) == 0) {
957         /* No buffers available */
958         printk(KERN_DEBUG "netwave_hw_xmit: %s - no xmit buffers available.\n",
959                dev->name);
960         spin_unlock_irqrestore(&priv->spinlock, flags);
961         return 1;
962     }
963
964     dev->stats.tx_bytes += len;
965
966     pr_debug("Transmitting with SPCQ %x SPU %x LIF %x ISPLQ %x\n",
967           readb(ramBase + NETWAVE_EREG_SPCQ),
968           readb(ramBase + NETWAVE_EREG_SPU),
969           readb(ramBase + NETWAVE_EREG_LIF),
970           readb(ramBase + NETWAVE_EREG_ISPLQ));
971
972     /* Now try to insert it into the adapters free memory */
973     wait_WOC(iobase);
974     TxFreeList = get_uint16(ramBase + NETWAVE_EREG_TDP);
975     MaxData    = get_uint16(ramBase + NETWAVE_EREG_TDP+2);
976     DataOffset = get_uint16(ramBase + NETWAVE_EREG_TDP+4);
977         
978     pr_debug("TxFreeList %x, MaxData %x, DataOffset %x\n",
979           TxFreeList, MaxData, DataOffset);
980
981     /* Copy packet to the adapter fragment buffers */
982     curBuff = TxFreeList; 
983     tmpcount = 0; 
984     while (tmpcount < len) {
985         int tmplen = len - tmpcount; 
986         copy_to_pc(ramBase + curBuff + DataOffset, data + tmpcount, 
987                    (tmplen < MaxData) ? tmplen : MaxData);
988         tmpcount += MaxData;
989                         
990         /* Advance to next buffer */
991         curBuff = get_uint16(ramBase + curBuff);
992     }
993     
994     /* Now issue transmit list */
995     wait_WOC(iobase);
996     writeb(NETWAVE_CMD_TL, ramBase + NETWAVE_EREG_CB + 0);
997     writeb(len & 0xff, ramBase + NETWAVE_EREG_CB + 1);
998     writeb((len>>8) & 0xff, ramBase + NETWAVE_EREG_CB + 2);
999     writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 3);
1000
1001     spin_unlock_irqrestore(&priv->spinlock, flags);
1002     return 0;
1003 }
1004
1005 static netdev_tx_t netwave_start_xmit(struct sk_buff *skb,
1006                                             struct net_device *dev) {
1007         /* This flag indicate that the hardware can't perform a transmission.
1008          * Theoritically, NET3 check it before sending a packet to the driver,
1009          * but in fact it never do that and pool continuously.
1010          * As the watchdog will abort too long transmissions, we are quite safe...
1011          */
1012
1013     netif_stop_queue(dev);
1014
1015     {
1016         short length = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
1017         unsigned char* buf = skb->data;
1018         
1019         if (netwave_hw_xmit( buf, length, dev) == 1) {
1020             /* Some error, let's make them call us another time? */
1021             netif_start_queue(dev);
1022         }
1023         dev->trans_start = jiffies;
1024     }
1025     dev_kfree_skb(skb);
1026     
1027     return NETDEV_TX_OK;
1028 } /* netwave_start_xmit */
1029
1030 /*
1031  * Function netwave_interrupt (irq, dev_id)
1032  *
1033  *    This function is the interrupt handler for the Netwave card. This
1034  *    routine will be called whenever: 
1035  *        1. A packet is received.
1036  *        2. A packet has successfully been transferred and the unit is
1037  *           ready to transmit another packet.
1038  *        3. A command has completed execution.
1039  */
1040 static irqreturn_t netwave_interrupt(int irq, void* dev_id)
1041 {
1042     unsigned int iobase;
1043     u_char __iomem *ramBase;
1044     struct net_device *dev = (struct net_device *)dev_id;
1045     struct netwave_private *priv = netdev_priv(dev);
1046     struct pcmcia_device *link = priv->p_dev;
1047     int i;
1048     
1049     if (!netif_device_present(dev))
1050         return IRQ_NONE;
1051     
1052     iobase = dev->base_addr;
1053     ramBase = priv->ramBase;
1054         
1055     /* Now find what caused the interrupt, check while interrupts ready */
1056     for (i = 0; i < 10; i++) {
1057         u_char status;
1058                 
1059         wait_WOC(iobase);       
1060         if (!(inb(iobase+NETWAVE_REG_CCSR) & 0x02))
1061             break; /* None of the interrupt sources asserted (normal exit) */
1062         
1063         status = inb(iobase + NETWAVE_REG_ASR);
1064                 
1065         if (!pcmcia_dev_present(link)) {
1066             pr_debug("netwave_interrupt: Interrupt with status 0x%x "
1067                   "from removed or suspended card!\n", status);
1068             break;
1069         }
1070                 
1071         /* RxRdy */
1072         if (status & 0x80) {
1073             netwave_rx(dev);
1074             /* wait_WOC(iobase); */
1075             /* RxRdy cannot be reset directly by the host */
1076         }
1077         /* RxErr */
1078         if (status & 0x40) {
1079             u_char rser;
1080                         
1081             rser = readb(ramBase + NETWAVE_EREG_RSER);                  
1082             
1083             if (rser & 0x04) {
1084                 ++dev->stats.rx_dropped;
1085                 ++dev->stats.rx_crc_errors;
1086             }
1087             if (rser & 0x02)
1088                 ++dev->stats.rx_frame_errors;
1089                         
1090             /* Clear the RxErr bit in RSER. RSER+4 is the
1091              * write part. Also clear the RxCRC (0x04) and 
1092              * RxBig (0x02) bits if present */
1093             wait_WOC(iobase);
1094             writeb(0x40 | (rser & 0x06), ramBase + NETWAVE_EREG_RSER + 4);
1095
1096             /* Write bit 6 high to ASCC to clear RxErr in ASR,
1097              * WOC must be set first! 
1098              */
1099             wait_WOC(iobase);
1100             writeb(0x40, ramBase + NETWAVE_EREG_ASCC);
1101
1102             /* Remember to count up dev->stats on error packets */
1103             ++dev->stats.rx_errors;
1104         }
1105         /* TxDN */
1106         if (status & 0x20) {
1107             int txStatus;
1108
1109             txStatus = readb(ramBase + NETWAVE_EREG_TSER);
1110             pr_debug("Transmit done. TSER = %x id %x\n",
1111                   txStatus, readb(ramBase + NETWAVE_EREG_TSER + 1));
1112             
1113             if (txStatus & 0x20) {
1114                 /* Transmitting was okay, clear bits */
1115                 wait_WOC(iobase);
1116                 writeb(0x2f, ramBase + NETWAVE_EREG_TSER + 4);
1117                 ++dev->stats.tx_packets;
1118             }
1119                         
1120             if (txStatus & 0xd0) {
1121                 if (txStatus & 0x80) {
1122                     ++dev->stats.collisions; /* Because of /proc/net/dev*/
1123                     /* ++dev->stats.tx_aborted_errors; */
1124                     /* printk("Collision. %ld\n", jiffies - dev->trans_start); */
1125                 }
1126                 if (txStatus & 0x40) 
1127                     ++dev->stats.tx_carrier_errors;
1128                 /* 0x80 TxGU Transmit giveup - nine times and no luck
1129                  * 0x40 TxNOAP No access point. Discarded packet.
1130                  * 0x10 TxErr Transmit error. Always set when 
1131                  *      TxGU and TxNOAP is set. (Those are the only ones
1132                  *      to set TxErr).
1133                  */
1134                 pr_debug("netwave_interrupt: TxDN with error status %x\n",
1135                       txStatus);
1136                 
1137                 /* Clear out TxGU, TxNOAP, TxErr and TxTrys */
1138                 wait_WOC(iobase);
1139                 writeb(0xdf & txStatus, ramBase+NETWAVE_EREG_TSER+4);
1140                 ++dev->stats.tx_errors;
1141             }
1142             pr_debug("New status is TSER %x ASR %x\n",
1143                   readb(ramBase + NETWAVE_EREG_TSER),
1144                   inb(iobase + NETWAVE_REG_ASR));
1145
1146             netif_wake_queue(dev);
1147         }
1148         /* TxBA, this would trigger on all error packets received */
1149         /* if (status & 0x01) {
1150            pr_debug("Transmit buffers available, %x\n", status);
1151            }
1152            */
1153     }
1154     /* Handled if we looped at least one time - Jean II */
1155     return IRQ_RETVAL(i);
1156 } /* netwave_interrupt */
1157
1158 /*
1159  * Function netwave_watchdog (a)
1160  *
1161  *    Watchdog : when we start a transmission, we set a timer in the
1162  *    kernel.  If the transmission complete, this timer is disabled. If
1163  *    it expire, we reset the card.
1164  *
1165  */
1166 static void netwave_watchdog(struct net_device *dev) {
1167
1168     pr_debug("%s: netwave_watchdog: watchdog timer expired\n", dev->name);
1169     netwave_reset(dev);
1170     dev->trans_start = jiffies;
1171     netif_wake_queue(dev);
1172 } /* netwave_watchdog */
1173
1174 static int netwave_rx(struct net_device *dev)
1175 {
1176     netwave_private *priv = netdev_priv(dev);
1177     u_char __iomem *ramBase = priv->ramBase;
1178     unsigned int iobase = dev->base_addr;
1179     u_char rxStatus;
1180     struct sk_buff *skb = NULL;
1181     unsigned int curBuffer,
1182                 rcvList;
1183     int rcvLen;
1184     int tmpcount = 0;
1185     int dataCount, dataOffset;
1186     int i;
1187     u_char *ptr;
1188         
1189     pr_debug("xinw_rx: Receiving ... \n");
1190
1191     /* Receive max 10 packets for now. */
1192     for (i = 0; i < 10; i++) {
1193         /* Any packets? */
1194         wait_WOC(iobase);
1195         rxStatus = readb(ramBase + NETWAVE_EREG_RSER);          
1196         if ( !( rxStatus & 0x80)) /* No more packets */
1197             break;
1198                 
1199         /* Check if multicast/broadcast or other */
1200         /* multicast = (rxStatus & 0x20);  */
1201                 
1202         /* The receive list pointer and length of the packet */
1203         wait_WOC(iobase);
1204         rcvLen  = get_int16( ramBase + NETWAVE_EREG_RDP);
1205         rcvList = get_uint16( ramBase + NETWAVE_EREG_RDP + 2);
1206                 
1207         if (rcvLen < 0) {
1208             printk(KERN_DEBUG "netwave_rx: Receive packet with len %d\n", 
1209                    rcvLen);
1210             return 0;
1211         }
1212                 
1213         skb = dev_alloc_skb(rcvLen+5);
1214         if (skb == NULL) {
1215             pr_debug("netwave_rx: Could not allocate an sk_buff of "
1216                   "length %d\n", rcvLen);
1217             ++dev->stats.rx_dropped;
1218             /* Tell the adapter to skip the packet */
1219             wait_WOC(iobase);
1220             writeb(NETWAVE_CMD_SRP, ramBase + NETWAVE_EREG_CB + 0);
1221             writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 1);
1222             return 0;
1223         }
1224
1225         skb_reserve( skb, 2);  /* Align IP on 16 byte */
1226         skb_put( skb, rcvLen);
1227
1228         /* Copy packet fragments to the skb data area */
1229         ptr = (u_char*) skb->data;
1230         curBuffer = rcvList;
1231         tmpcount = 0; 
1232         while ( tmpcount < rcvLen) {
1233             /* Get length and offset of current buffer */
1234             dataCount  = get_uint16( ramBase+curBuffer+2);
1235             dataOffset = get_uint16( ramBase+curBuffer+4);
1236                 
1237             copy_from_pc( ptr + tmpcount,
1238                           ramBase+curBuffer+dataOffset, dataCount);
1239
1240             tmpcount += dataCount;
1241                 
1242             /* Point to next buffer */
1243             curBuffer = get_uint16(ramBase + curBuffer);
1244         }
1245         
1246         skb->protocol = eth_type_trans(skb,dev);
1247         /* Queue packet for network layer */
1248         netif_rx(skb);
1249
1250         dev->stats.rx_packets++;
1251         dev->stats.rx_bytes += rcvLen;
1252
1253         /* Got the packet, tell the adapter to skip it */
1254         wait_WOC(iobase);
1255         writeb(NETWAVE_CMD_SRP, ramBase + NETWAVE_EREG_CB + 0);
1256         writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 1);
1257         pr_debug("Packet reception ok\n");
1258     }
1259     return 0;
1260 }
1261
1262 static int netwave_open(struct net_device *dev) {
1263     netwave_private *priv = netdev_priv(dev);
1264     struct pcmcia_device *link = priv->p_dev;
1265
1266     dev_dbg(&link->dev, "netwave_open: starting.\n");
1267     
1268     if (!pcmcia_dev_present(link))
1269         return -ENODEV;
1270
1271     link->open++;
1272
1273     netif_start_queue(dev);
1274     netwave_reset(dev);
1275         
1276     return 0;
1277 }
1278
1279 static int netwave_close(struct net_device *dev) {
1280     netwave_private *priv = netdev_priv(dev);
1281     struct pcmcia_device *link = priv->p_dev;
1282
1283     dev_dbg(&link->dev, "netwave_close: finishing.\n");
1284
1285     link->open--;
1286     netif_stop_queue(dev);
1287
1288     return 0;
1289 }
1290
1291 static struct pcmcia_device_id netwave_ids[] = {
1292         PCMCIA_DEVICE_PROD_ID12("Xircom", "CreditCard Netwave", 0x2e3ee845, 0x54e28a28),
1293         PCMCIA_DEVICE_NULL,
1294 };
1295 MODULE_DEVICE_TABLE(pcmcia, netwave_ids);
1296
1297 static struct pcmcia_driver netwave_driver = {
1298         .owner          = THIS_MODULE,
1299         .drv            = {
1300                 .name   = "netwave_cs",
1301         },
1302         .probe          = netwave_probe,
1303         .remove         = netwave_detach,
1304         .id_table       = netwave_ids,
1305         .suspend        = netwave_suspend,
1306         .resume         = netwave_resume,
1307 };
1308
1309 static int __init init_netwave_cs(void)
1310 {
1311         return pcmcia_register_driver(&netwave_driver);
1312 }
1313
1314 static void __exit exit_netwave_cs(void)
1315 {
1316         pcmcia_unregister_driver(&netwave_driver);
1317 }
1318
1319 module_init(init_netwave_cs);
1320 module_exit(exit_netwave_cs);
1321
1322 /* Set or clear the multicast filter for this adaptor.
1323    num_addrs == -1      Promiscuous mode, receive all packets
1324    num_addrs == 0       Normal mode, clear multicast list
1325    num_addrs > 0        Multicast mode, receive normal and MC packets, and do
1326    best-effort filtering.
1327  */
1328 static void set_multicast_list(struct net_device *dev)
1329 {
1330     unsigned int iobase = dev->base_addr;
1331     netwave_private *priv = netdev_priv(dev);
1332     u_char __iomem * ramBase = priv->ramBase;
1333     u_char  rcvMode = 0;
1334    
1335 #ifdef PCMCIA_DEBUG
1336     {
1337         xstatic int old;
1338         if (old != netdev_mc_count(dev)) {
1339             old = netdev_mc_count(dev);
1340             pr_debug("%s: setting Rx mode to %d addresses.\n",
1341                   dev->name, netdev_mc_count(dev));
1342         }
1343     }
1344 #endif
1345         
1346     if (!netdev_mc_empty(dev) || (dev->flags & IFF_ALLMULTI)) {
1347         /* Multicast Mode */
1348         rcvMode = rxConfRxEna + rxConfAMP + rxConfBcast;
1349     } else if (dev->flags & IFF_PROMISC) {
1350         /* Promiscous mode */
1351         rcvMode = rxConfRxEna + rxConfPro + rxConfAMP + rxConfBcast;
1352     } else {
1353         /* Normal mode */
1354         rcvMode = rxConfRxEna + rxConfBcast;
1355     }
1356         
1357     /* printk("netwave set_multicast_list: rcvMode to %x\n", rcvMode);*/
1358     /* Now set receive mode */
1359     wait_WOC(iobase);
1360     writeb(NETWAVE_CMD_SRC, ramBase + NETWAVE_EREG_CB + 0);
1361     writeb(rcvMode, ramBase + NETWAVE_EREG_CB + 1);
1362     writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 2);
1363 }
1364 MODULE_LICENSE("GPL");