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