[PATCH] missing include of dma-mapping.h
[linux-2.6/x86.git] / drivers / net / wireless / netwave_cs.c
blob6714e0dfa8d6ebadd95490477ddb259999a73b2e
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>
14 * Copyright (c) 1997 University of Tromsø, Norway
16 * Revision History:
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 ********************************************************************/
37 /* To have statistics (just packets sent) define this */
38 #undef NETWAVE_STATS
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/slab.h>
50 #include <linux/string.h>
51 #include <linux/timer.h>
52 #include <linux/errno.h>
53 #include <linux/netdevice.h>
54 #include <linux/etherdevice.h>
55 #include <linux/skbuff.h>
56 #include <linux/bitops.h>
57 #include <linux/wireless.h>
58 #include <net/iw_handler.h>
60 #include <pcmcia/cs_types.h>
61 #include <pcmcia/cs.h>
62 #include <pcmcia/cistpl.h>
63 #include <pcmcia/cisreg.h>
64 #include <pcmcia/ds.h>
65 #include <pcmcia/mem_op.h>
67 #include <asm/system.h>
68 #include <asm/io.h>
69 #include <asm/dma.h>
71 #define NETWAVE_REGOFF 0x8000
72 /* The Netwave IO registers, offsets to iobase */
73 #define NETWAVE_REG_COR 0x0
74 #define NETWAVE_REG_CCSR 0x2
75 #define NETWAVE_REG_ASR 0x4
76 #define NETWAVE_REG_IMR 0xa
77 #define NETWAVE_REG_PMR 0xc
78 #define NETWAVE_REG_IOLOW 0x6
79 #define NETWAVE_REG_IOHI 0x7
80 #define NETWAVE_REG_IOCONTROL 0x8
81 #define NETWAVE_REG_DATA 0xf
82 /* The Netwave Extended IO registers, offsets to RamBase */
83 #define NETWAVE_EREG_ASCC 0x114
84 #define NETWAVE_EREG_RSER 0x120
85 #define NETWAVE_EREG_RSERW 0x124
86 #define NETWAVE_EREG_TSER 0x130
87 #define NETWAVE_EREG_TSERW 0x134
88 #define NETWAVE_EREG_CB 0x100
89 #define NETWAVE_EREG_SPCQ 0x154
90 #define NETWAVE_EREG_SPU 0x155
91 #define NETWAVE_EREG_LIF 0x14e
92 #define NETWAVE_EREG_ISPLQ 0x156
93 #define NETWAVE_EREG_HHC 0x158
94 #define NETWAVE_EREG_NI 0x16e
95 #define NETWAVE_EREG_MHS 0x16b
96 #define NETWAVE_EREG_TDP 0x140
97 #define NETWAVE_EREG_RDP 0x150
98 #define NETWAVE_EREG_PA 0x160
99 #define NETWAVE_EREG_EC 0x180
100 #define NETWAVE_EREG_CRBP 0x17a
101 #define NETWAVE_EREG_ARW 0x166
104 * Commands used in the extended command buffer
105 * NETWAVE_EREG_CB (0x100-0x10F)
107 #define NETWAVE_CMD_NOP 0x00
108 #define NETWAVE_CMD_SRC 0x01
109 #define NETWAVE_CMD_STC 0x02
110 #define NETWAVE_CMD_AMA 0x03
111 #define NETWAVE_CMD_DMA 0x04
112 #define NETWAVE_CMD_SAMA 0x05
113 #define NETWAVE_CMD_ER 0x06
114 #define NETWAVE_CMD_DR 0x07
115 #define NETWAVE_CMD_TL 0x08
116 #define NETWAVE_CMD_SRP 0x09
117 #define NETWAVE_CMD_SSK 0x0a
118 #define NETWAVE_CMD_SMD 0x0b
119 #define NETWAVE_CMD_SAPD 0x0c
120 #define NETWAVE_CMD_SSS 0x11
121 /* End of Command marker */
122 #define NETWAVE_CMD_EOC 0x00
124 /* ASR register bits */
125 #define NETWAVE_ASR_RXRDY 0x80
126 #define NETWAVE_ASR_TXBA 0x01
128 #define TX_TIMEOUT ((32*HZ)/100)
130 static const unsigned int imrConfRFU1 = 0x10; /* RFU interrupt mask, keep high */
131 static const unsigned int imrConfIENA = 0x02; /* Interrupt enable */
133 static const unsigned int corConfIENA = 0x01; /* Interrupt enable */
134 static const unsigned int corConfLVLREQ = 0x40; /* Keep high */
136 static const unsigned int rxConfRxEna = 0x80; /* Receive Enable */
137 static const unsigned int rxConfMAC = 0x20; /* MAC host receive mode*/
138 static const unsigned int rxConfPro = 0x10; /* Promiscuous */
139 static const unsigned int rxConfAMP = 0x08; /* Accept Multicast Packets */
140 static const unsigned int rxConfBcast = 0x04; /* Accept Broadcast Packets */
142 static const unsigned int txConfTxEna = 0x80; /* Transmit Enable */
143 static const unsigned int txConfMAC = 0x20; /* Host sends MAC mode */
144 static const unsigned int txConfEUD = 0x10; /* Enable Uni-Data packets */
145 static const unsigned int txConfKey = 0x02; /* Scramble data packets */
146 static const unsigned int txConfLoop = 0x01; /* Loopback mode */
149 All the PCMCIA modules use PCMCIA_DEBUG to control debugging. If
150 you do not define PCMCIA_DEBUG at all, all the debug code will be
151 left out. If you compile with PCMCIA_DEBUG=0, the debug code will
152 be present but disabled -- but it can then be enabled for specific
153 modules at load time with a 'pc_debug=#' option to insmod.
156 #ifdef PCMCIA_DEBUG
157 static int pc_debug = PCMCIA_DEBUG;
158 module_param(pc_debug, int, 0);
159 #define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args)
160 static char *version =
161 "netwave_cs.c 0.3.0 Thu Jul 17 14:36:02 1997 (John Markus Bjørndalen)\n";
162 #else
163 #define DEBUG(n, args...)
164 #endif
166 /*====================================================================*/
168 /* Parameters that can be set with 'insmod' */
170 /* Choose the domain, default is 0x100 */
171 static u_int domain = 0x100;
173 /* Scramble key, range from 0x0 to 0xffff.
174 * 0x0 is no scrambling.
176 static u_int scramble_key = 0x0;
178 /* Shared memory speed, in ns. The documentation states that
179 * the card should not be read faster than every 400ns.
180 * This timing should be provided by the HBA. If it becomes a
181 * problem, try setting mem_speed to 400.
183 static int mem_speed;
185 module_param(domain, int, 0);
186 module_param(scramble_key, int, 0);
187 module_param(mem_speed, int, 0);
189 /*====================================================================*/
191 /* PCMCIA (Card Services) related functions */
192 static void netwave_release(struct pcmcia_device *link); /* Card removal */
193 static int netwave_pcmcia_config(struct pcmcia_device *arg); /* Runs after card
194 insertion */
195 static void netwave_detach(struct pcmcia_device *p_dev); /* Destroy instance */
197 /* Hardware configuration */
198 static void netwave_doreset(kio_addr_t iobase, u_char __iomem *ramBase);
199 static void netwave_reset(struct net_device *dev);
201 /* Misc device stuff */
202 static int netwave_open(struct net_device *dev); /* Open the device */
203 static int netwave_close(struct net_device *dev); /* Close the device */
205 /* Packet transmission and Packet reception */
206 static int netwave_start_xmit( struct sk_buff *skb, struct net_device *dev);
207 static int netwave_rx( struct net_device *dev);
209 /* Interrupt routines */
210 static irqreturn_t netwave_interrupt(int irq, void *dev_id);
211 static void netwave_watchdog(struct net_device *);
213 /* Statistics */
214 static void update_stats(struct net_device *dev);
215 static struct net_device_stats *netwave_get_stats(struct net_device *dev);
217 /* Wireless extensions */
218 static struct iw_statistics* netwave_get_wireless_stats(struct net_device *dev);
220 static void set_multicast_list(struct net_device *dev);
223 A struct pcmcia_device structure has fields for most things that are needed
224 to keep track of a socket, but there will usually be some device
225 specific information that also needs to be kept track of. The
226 'priv' pointer in a struct pcmcia_device structure can be used to point to
227 a device-specific private data structure, like this.
229 A driver needs to provide a dev_node_t structure for each device
230 on a card. In some cases, there is only one device per card (for
231 example, ethernet cards, modems). In other cases, there may be
232 many actual or logical devices (SCSI adapters, memory cards with
233 multiple partitions). The dev_node_t structures need to be kept
234 in a linked list starting at the 'dev' field of a struct pcmcia_device
235 structure. We allocate them in the card's private data structure,
236 because they generally can't be allocated dynamically.
239 static const struct iw_handler_def netwave_handler_def;
241 #define SIOCGIPSNAP SIOCIWFIRSTPRIV + 1 /* Site Survey Snapshot */
243 #define MAX_ESA 10
245 typedef struct net_addr {
246 u_char addr48[6];
247 } net_addr;
249 struct site_survey {
250 u_short length;
251 u_char struct_revision;
252 u_char roaming_state;
254 u_char sp_existsFlag;
255 u_char sp_link_quality;
256 u_char sp_max_link_quality;
257 u_char linkQualityGoodFairBoundary;
258 u_char linkQualityFairPoorBoundary;
259 u_char sp_utilization;
260 u_char sp_goodness;
261 u_char sp_hotheadcount;
262 u_char roaming_condition;
264 net_addr sp;
265 u_char numAPs;
266 net_addr nearByAccessPoints[MAX_ESA];
269 typedef struct netwave_private {
270 struct pcmcia_device *p_dev;
271 spinlock_t spinlock; /* Serialize access to the hardware (SMP) */
272 dev_node_t node;
273 u_char __iomem *ramBase;
274 int timeoutCounter;
275 int lastExec;
276 struct timer_list watchdog; /* To avoid blocking state */
277 struct site_survey nss;
278 struct net_device_stats stats;
279 struct iw_statistics iw_stats; /* Wireless stats */
280 } netwave_private;
282 #ifdef NETWAVE_STATS
283 static struct net_device_stats *netwave_get_stats(struct net_device *dev);
284 #endif
287 * The Netwave card is little-endian, so won't work for big endian
288 * systems.
290 static inline unsigned short get_uint16(u_char __iomem *staddr)
292 return readw(staddr); /* Return only 16 bits */
295 static inline short get_int16(u_char __iomem * staddr)
297 return readw(staddr);
301 * Wait until the WOC (Write Operation Complete) bit in the
302 * ASR (Adapter Status Register) is asserted.
303 * This should have aborted if it takes too long time.
305 static inline void wait_WOC(unsigned int iobase)
307 /* Spin lock */
308 while ((inb(iobase + NETWAVE_REG_ASR) & 0x8) != 0x8) ;
311 static void netwave_snapshot(netwave_private *priv, u_char __iomem *ramBase,
312 kio_addr_t iobase) {
313 u_short resultBuffer;
315 /* if time since last snapshot is > 1 sec. (100 jiffies?) then take
316 * new snapshot, else return cached data. This is the recommended rate.
318 if ( jiffies - priv->lastExec > 100) {
319 /* Take site survey snapshot */
320 /*printk( KERN_DEBUG "Taking new snapshot. %ld\n", jiffies -
321 priv->lastExec); */
322 wait_WOC(iobase);
323 writeb(NETWAVE_CMD_SSS, ramBase + NETWAVE_EREG_CB + 0);
324 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 1);
325 wait_WOC(iobase);
327 /* Get result and copy to cach */
328 resultBuffer = readw(ramBase + NETWAVE_EREG_CRBP);
329 copy_from_pc( &priv->nss, ramBase+resultBuffer,
330 sizeof(struct site_survey));
335 * Function netwave_get_wireless_stats (dev)
337 * Wireless extensions statistics
340 static struct iw_statistics *netwave_get_wireless_stats(struct net_device *dev)
342 unsigned long flags;
343 kio_addr_t iobase = dev->base_addr;
344 netwave_private *priv = netdev_priv(dev);
345 u_char __iomem *ramBase = priv->ramBase;
346 struct iw_statistics* wstats;
348 wstats = &priv->iw_stats;
350 spin_lock_irqsave(&priv->spinlock, flags);
352 netwave_snapshot( priv, ramBase, iobase);
354 wstats->status = priv->nss.roaming_state;
355 wstats->qual.qual = readb( ramBase + NETWAVE_EREG_SPCQ);
356 wstats->qual.level = readb( ramBase + NETWAVE_EREG_ISPLQ);
357 wstats->qual.noise = readb( ramBase + NETWAVE_EREG_SPU) & 0x3f;
358 wstats->discard.nwid = 0L;
359 wstats->discard.code = 0L;
360 wstats->discard.misc = 0L;
362 spin_unlock_irqrestore(&priv->spinlock, flags);
364 return &priv->iw_stats;
368 * Function netwave_attach (void)
370 * Creates an "instance" of the driver, allocating local data
371 * structures for one device. The device is registered with Card
372 * Services.
374 * The dev_link structure is initialized, but we don't actually
375 * configure the card at this point -- we wait until we receive a
376 * card insertion event.
378 static int netwave_probe(struct pcmcia_device *link)
380 struct net_device *dev;
381 netwave_private *priv;
383 DEBUG(0, "netwave_attach()\n");
385 /* Initialize the struct pcmcia_device structure */
386 dev = alloc_etherdev(sizeof(netwave_private));
387 if (!dev)
388 return -ENOMEM;
389 priv = netdev_priv(dev);
390 priv->p_dev = link;
391 link->priv = dev;
393 /* The io structure describes IO port mapping */
394 link->io.NumPorts1 = 16;
395 link->io.Attributes1 = IO_DATA_PATH_WIDTH_16;
396 /* link->io.NumPorts2 = 16;
397 link->io.Attributes2 = IO_DATA_PATH_WIDTH_16; */
398 link->io.IOAddrLines = 5;
400 /* Interrupt setup */
401 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT;
402 link->irq.IRQInfo1 = IRQ_LEVEL_ID;
403 link->irq.Handler = &netwave_interrupt;
405 /* General socket configuration */
406 link->conf.Attributes = CONF_ENABLE_IRQ;
407 link->conf.IntType = INT_MEMORY_AND_IO;
408 link->conf.ConfigIndex = 1;
409 link->conf.Present = PRESENT_OPTION;
411 /* Netwave private struct init. link/dev/node already taken care of,
412 * other stuff zero'd - Jean II */
413 spin_lock_init(&priv->spinlock);
415 /* Netwave specific entries in the device structure */
416 SET_MODULE_OWNER(dev);
417 dev->hard_start_xmit = &netwave_start_xmit;
418 dev->get_stats = &netwave_get_stats;
419 dev->set_multicast_list = &set_multicast_list;
420 /* wireless extensions */
421 dev->wireless_handlers = (struct iw_handler_def *)&netwave_handler_def;
423 dev->tx_timeout = &netwave_watchdog;
424 dev->watchdog_timeo = TX_TIMEOUT;
426 dev->open = &netwave_open;
427 dev->stop = &netwave_close;
428 link->irq.Instance = dev;
430 return netwave_pcmcia_config( link);
431 } /* netwave_attach */
434 * Function netwave_detach (link)
436 * This deletes a driver "instance". The device is de-registered
437 * with Card Services. If it has been released, all local data
438 * structures are freed. Otherwise, the structures will be freed
439 * when the device is released.
441 static void netwave_detach(struct pcmcia_device *link)
443 struct net_device *dev = link->priv;
445 DEBUG(0, "netwave_detach(0x%p)\n", link);
447 netwave_release(link);
449 if (link->dev_node)
450 unregister_netdev(dev);
452 free_netdev(dev);
453 } /* netwave_detach */
456 * Wireless Handler : get protocol name
458 static int netwave_get_name(struct net_device *dev,
459 struct iw_request_info *info,
460 union iwreq_data *wrqu,
461 char *extra)
463 strcpy(wrqu->name, "Netwave");
464 return 0;
468 * Wireless Handler : set Network ID
470 static int netwave_set_nwid(struct net_device *dev,
471 struct iw_request_info *info,
472 union iwreq_data *wrqu,
473 char *extra)
475 unsigned long flags;
476 kio_addr_t iobase = dev->base_addr;
477 netwave_private *priv = netdev_priv(dev);
478 u_char __iomem *ramBase = priv->ramBase;
480 /* Disable interrupts & save flags */
481 spin_lock_irqsave(&priv->spinlock, flags);
483 if(!wrqu->nwid.disabled) {
484 domain = wrqu->nwid.value;
485 printk( KERN_DEBUG "Setting domain to 0x%x%02x\n",
486 (domain >> 8) & 0x01, domain & 0xff);
487 wait_WOC(iobase);
488 writeb(NETWAVE_CMD_SMD, ramBase + NETWAVE_EREG_CB + 0);
489 writeb( domain & 0xff, ramBase + NETWAVE_EREG_CB + 1);
490 writeb((domain >>8 ) & 0x01,ramBase + NETWAVE_EREG_CB+2);
491 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 3);
494 /* ReEnable interrupts & restore flags */
495 spin_unlock_irqrestore(&priv->spinlock, flags);
497 return 0;
501 * Wireless Handler : get Network ID
503 static int netwave_get_nwid(struct net_device *dev,
504 struct iw_request_info *info,
505 union iwreq_data *wrqu,
506 char *extra)
508 wrqu->nwid.value = domain;
509 wrqu->nwid.disabled = 0;
510 wrqu->nwid.fixed = 1;
511 return 0;
515 * Wireless Handler : set scramble key
517 static int netwave_set_scramble(struct net_device *dev,
518 struct iw_request_info *info,
519 union iwreq_data *wrqu,
520 char *key)
522 unsigned long flags;
523 kio_addr_t iobase = dev->base_addr;
524 netwave_private *priv = netdev_priv(dev);
525 u_char __iomem *ramBase = priv->ramBase;
527 /* Disable interrupts & save flags */
528 spin_lock_irqsave(&priv->spinlock, flags);
530 scramble_key = (key[0] << 8) | key[1];
531 wait_WOC(iobase);
532 writeb(NETWAVE_CMD_SSK, ramBase + NETWAVE_EREG_CB + 0);
533 writeb(scramble_key & 0xff, ramBase + NETWAVE_EREG_CB + 1);
534 writeb((scramble_key>>8) & 0xff, ramBase + NETWAVE_EREG_CB + 2);
535 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 3);
537 /* ReEnable interrupts & restore flags */
538 spin_unlock_irqrestore(&priv->spinlock, flags);
540 return 0;
544 * Wireless Handler : get scramble key
546 static int netwave_get_scramble(struct net_device *dev,
547 struct iw_request_info *info,
548 union iwreq_data *wrqu,
549 char *key)
551 key[1] = scramble_key & 0xff;
552 key[0] = (scramble_key>>8) & 0xff;
553 wrqu->encoding.flags = IW_ENCODE_ENABLED;
554 wrqu->encoding.length = 2;
555 return 0;
559 * Wireless Handler : get mode
561 static int netwave_get_mode(struct net_device *dev,
562 struct iw_request_info *info,
563 union iwreq_data *wrqu,
564 char *extra)
566 if(domain & 0x100)
567 wrqu->mode = IW_MODE_INFRA;
568 else
569 wrqu->mode = IW_MODE_ADHOC;
571 return 0;
575 * Wireless Handler : get range info
577 static int netwave_get_range(struct net_device *dev,
578 struct iw_request_info *info,
579 union iwreq_data *wrqu,
580 char *extra)
582 struct iw_range *range = (struct iw_range *) extra;
583 int ret = 0;
585 /* Set the length (very important for backward compatibility) */
586 wrqu->data.length = sizeof(struct iw_range);
588 /* Set all the info we don't care or don't know about to zero */
589 memset(range, 0, sizeof(struct iw_range));
591 /* Set the Wireless Extension versions */
592 range->we_version_compiled = WIRELESS_EXT;
593 range->we_version_source = 9; /* Nothing for us in v10 and v11 */
595 /* Set information in the range struct */
596 range->throughput = 450 * 1000; /* don't argue on this ! */
597 range->min_nwid = 0x0000;
598 range->max_nwid = 0x01FF;
600 range->num_channels = range->num_frequency = 0;
602 range->sensitivity = 0x3F;
603 range->max_qual.qual = 255;
604 range->max_qual.level = 255;
605 range->max_qual.noise = 0;
607 range->num_bitrates = 1;
608 range->bitrate[0] = 1000000; /* 1 Mb/s */
610 range->encoding_size[0] = 2; /* 16 bits scrambling */
611 range->num_encoding_sizes = 1;
612 range->max_encoding_tokens = 1; /* Only one key possible */
614 return ret;
618 * Wireless Private Handler : get snapshot
620 static int netwave_get_snap(struct net_device *dev,
621 struct iw_request_info *info,
622 union iwreq_data *wrqu,
623 char *extra)
625 unsigned long flags;
626 kio_addr_t iobase = dev->base_addr;
627 netwave_private *priv = netdev_priv(dev);
628 u_char __iomem *ramBase = priv->ramBase;
630 /* Disable interrupts & save flags */
631 spin_lock_irqsave(&priv->spinlock, flags);
633 /* Take snapshot of environment */
634 netwave_snapshot( priv, ramBase, iobase);
635 wrqu->data.length = priv->nss.length;
636 memcpy(extra, (u_char *) &priv->nss, sizeof( struct site_survey));
638 priv->lastExec = jiffies;
640 /* ReEnable interrupts & restore flags */
641 spin_unlock_irqrestore(&priv->spinlock, flags);
643 return(0);
647 * Structures to export the Wireless Handlers
648 * This is the stuff that are treated the wireless extensions (iwconfig)
651 static const struct iw_priv_args netwave_private_args[] = {
652 /*{ cmd, set_args, get_args, name } */
653 { SIOCGIPSNAP, 0,
654 IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | sizeof(struct site_survey),
655 "getsitesurvey" },
658 static const iw_handler netwave_handler[] =
660 NULL, /* SIOCSIWNAME */
661 netwave_get_name, /* SIOCGIWNAME */
662 netwave_set_nwid, /* SIOCSIWNWID */
663 netwave_get_nwid, /* SIOCGIWNWID */
664 NULL, /* SIOCSIWFREQ */
665 NULL, /* SIOCGIWFREQ */
666 NULL, /* SIOCSIWMODE */
667 netwave_get_mode, /* SIOCGIWMODE */
668 NULL, /* SIOCSIWSENS */
669 NULL, /* SIOCGIWSENS */
670 NULL, /* SIOCSIWRANGE */
671 netwave_get_range, /* SIOCGIWRANGE */
672 NULL, /* SIOCSIWPRIV */
673 NULL, /* SIOCGIWPRIV */
674 NULL, /* SIOCSIWSTATS */
675 NULL, /* SIOCGIWSTATS */
676 NULL, /* SIOCSIWSPY */
677 NULL, /* SIOCGIWSPY */
678 NULL, /* -- hole -- */
679 NULL, /* -- hole -- */
680 NULL, /* SIOCSIWAP */
681 NULL, /* SIOCGIWAP */
682 NULL, /* -- hole -- */
683 NULL, /* SIOCGIWAPLIST */
684 NULL, /* -- hole -- */
685 NULL, /* -- hole -- */
686 NULL, /* SIOCSIWESSID */
687 NULL, /* SIOCGIWESSID */
688 NULL, /* SIOCSIWNICKN */
689 NULL, /* SIOCGIWNICKN */
690 NULL, /* -- hole -- */
691 NULL, /* -- hole -- */
692 NULL, /* SIOCSIWRATE */
693 NULL, /* SIOCGIWRATE */
694 NULL, /* SIOCSIWRTS */
695 NULL, /* SIOCGIWRTS */
696 NULL, /* SIOCSIWFRAG */
697 NULL, /* SIOCGIWFRAG */
698 NULL, /* SIOCSIWTXPOW */
699 NULL, /* SIOCGIWTXPOW */
700 NULL, /* SIOCSIWRETRY */
701 NULL, /* SIOCGIWRETRY */
702 netwave_set_scramble, /* SIOCSIWENCODE */
703 netwave_get_scramble, /* SIOCGIWENCODE */
706 static const iw_handler netwave_private_handler[] =
708 NULL, /* SIOCIWFIRSTPRIV */
709 netwave_get_snap, /* SIOCIWFIRSTPRIV + 1 */
712 static const struct iw_handler_def netwave_handler_def =
714 .num_standard = sizeof(netwave_handler)/sizeof(iw_handler),
715 .num_private = sizeof(netwave_private_handler)/sizeof(iw_handler),
716 .num_private_args = sizeof(netwave_private_args)/sizeof(struct iw_priv_args),
717 .standard = (iw_handler *) netwave_handler,
718 .private = (iw_handler *) netwave_private_handler,
719 .private_args = (struct iw_priv_args *) netwave_private_args,
720 .get_wireless_stats = netwave_get_wireless_stats,
724 * Function netwave_pcmcia_config (link)
726 * netwave_pcmcia_config() is scheduled to run after a CARD_INSERTION
727 * event is received, to configure the PCMCIA socket, and to make the
728 * device available to the system.
732 #define CS_CHECK(fn, ret) \
733 do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
735 static int netwave_pcmcia_config(struct pcmcia_device *link) {
736 struct net_device *dev = link->priv;
737 netwave_private *priv = netdev_priv(dev);
738 tuple_t tuple;
739 cisparse_t parse;
740 int i, j, last_ret, last_fn;
741 u_char buf[64];
742 win_req_t req;
743 memreq_t mem;
744 u_char __iomem *ramBase = NULL;
746 DEBUG(0, "netwave_pcmcia_config(0x%p)\n", link);
749 This reads the card's CONFIG tuple to find its configuration
750 registers.
752 tuple.Attributes = 0;
753 tuple.TupleData = (cisdata_t *) buf;
754 tuple.TupleDataMax = 64;
755 tuple.TupleOffset = 0;
756 tuple.DesiredTuple = CISTPL_CONFIG;
757 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
758 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
759 CS_CHECK(ParseTuple, pcmcia_parse_tuple(link, &tuple, &parse));
760 link->conf.ConfigBase = parse.config.base;
761 link->conf.Present = parse.config.rmask[0];
764 * Try allocating IO ports. This tries a few fixed addresses.
765 * If you want, you can also read the card's config table to
766 * pick addresses -- see the serial driver for an example.
768 for (i = j = 0x0; j < 0x400; j += 0x20) {
769 link->io.BasePort1 = j ^ 0x300;
770 i = pcmcia_request_io(link, &link->io);
771 if (i == CS_SUCCESS) break;
773 if (i != CS_SUCCESS) {
774 cs_error(link, RequestIO, i);
775 goto failed;
779 * Now allocate an interrupt line. Note that this does not
780 * actually assign a handler to the interrupt.
782 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
785 * This actually configures the PCMCIA socket -- setting up
786 * the I/O windows and the interrupt mapping.
788 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
791 * Allocate a 32K memory window. Note that the struct pcmcia_device
792 * structure provides space for one window handle -- if your
793 * device needs several windows, you'll need to keep track of
794 * the handles in your private data structure, dev->priv.
796 DEBUG(1, "Setting mem speed of %d\n", mem_speed);
798 req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_CM|WIN_ENABLE;
799 req.Base = 0; req.Size = 0x8000;
800 req.AccessSpeed = mem_speed;
801 CS_CHECK(RequestWindow, pcmcia_request_window(&link, &req, &link->win));
802 mem.CardOffset = 0x20000; mem.Page = 0;
803 CS_CHECK(MapMemPage, pcmcia_map_mem_page(link->win, &mem));
805 /* Store base address of the common window frame */
806 ramBase = ioremap(req.Base, 0x8000);
807 priv->ramBase = ramBase;
809 dev->irq = link->irq.AssignedIRQ;
810 dev->base_addr = link->io.BasePort1;
811 SET_NETDEV_DEV(dev, &handle_to_dev(link));
813 if (register_netdev(dev) != 0) {
814 printk(KERN_DEBUG "netwave_cs: register_netdev() failed\n");
815 goto failed;
818 strcpy(priv->node.dev_name, dev->name);
819 link->dev_node = &priv->node;
821 /* Reset card before reading physical address */
822 netwave_doreset(dev->base_addr, ramBase);
824 /* Read the ethernet address and fill in the Netwave registers. */
825 for (i = 0; i < 6; i++)
826 dev->dev_addr[i] = readb(ramBase + NETWAVE_EREG_PA + i);
828 printk(KERN_INFO "%s: Netwave: port %#3lx, irq %d, mem %lx id "
829 "%c%c, hw_addr ", dev->name, dev->base_addr, dev->irq,
830 (u_long) ramBase, (int) readb(ramBase+NETWAVE_EREG_NI),
831 (int) readb(ramBase+NETWAVE_EREG_NI+1));
832 for (i = 0; i < 6; i++)
833 printk("%02X%s", dev->dev_addr[i], ((i<5) ? ":" : "\n"));
835 /* get revision words */
836 printk(KERN_DEBUG "Netwave_reset: revision %04x %04x\n",
837 get_uint16(ramBase + NETWAVE_EREG_ARW),
838 get_uint16(ramBase + NETWAVE_EREG_ARW+2));
839 return 0;
841 cs_failed:
842 cs_error(link, last_fn, last_ret);
843 failed:
844 netwave_release(link);
845 return -ENODEV;
846 } /* netwave_pcmcia_config */
849 * Function netwave_release (arg)
851 * After a card is removed, netwave_release() will unregister the net
852 * device, and release the PCMCIA configuration. If the device is
853 * still open, this will be postponed until it is closed.
855 static void netwave_release(struct pcmcia_device *link)
857 struct net_device *dev = link->priv;
858 netwave_private *priv = netdev_priv(dev);
860 DEBUG(0, "netwave_release(0x%p)\n", link);
862 pcmcia_disable_device(link);
863 if (link->win)
864 iounmap(priv->ramBase);
867 static int netwave_suspend(struct pcmcia_device *link)
869 struct net_device *dev = link->priv;
871 if (link->open)
872 netif_device_detach(dev);
874 return 0;
877 static int netwave_resume(struct pcmcia_device *link)
879 struct net_device *dev = link->priv;
881 if (link->open) {
882 netwave_reset(dev);
883 netif_device_attach(dev);
886 return 0;
891 * Function netwave_doreset (ioBase, ramBase)
893 * Proper hardware reset of the card.
895 static void netwave_doreset(kio_addr_t ioBase, u_char __iomem *ramBase)
897 /* Reset card */
898 wait_WOC(ioBase);
899 outb(0x80, ioBase + NETWAVE_REG_PMR);
900 writeb(0x08, ramBase + NETWAVE_EREG_ASCC); /* Bit 3 is WOC */
901 outb(0x0, ioBase + NETWAVE_REG_PMR); /* release reset */
905 * Function netwave_reset (dev)
907 * Reset and restore all of the netwave registers
909 static void netwave_reset(struct net_device *dev) {
910 /* u_char state; */
911 netwave_private *priv = netdev_priv(dev);
912 u_char __iomem *ramBase = priv->ramBase;
913 kio_addr_t iobase = dev->base_addr;
915 DEBUG(0, "netwave_reset: Done with hardware reset\n");
917 priv->timeoutCounter = 0;
919 /* Reset card */
920 netwave_doreset(iobase, ramBase);
921 printk(KERN_DEBUG "netwave_reset: Done with hardware reset\n");
923 /* Write a NOP to check the card */
924 wait_WOC(iobase);
925 writeb(NETWAVE_CMD_NOP, ramBase + NETWAVE_EREG_CB + 0);
926 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 1);
928 /* Set receive conf */
929 wait_WOC(iobase);
930 writeb(NETWAVE_CMD_SRC, ramBase + NETWAVE_EREG_CB + 0);
931 writeb(rxConfRxEna + rxConfBcast, ramBase + NETWAVE_EREG_CB + 1);
932 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 2);
934 /* Set transmit conf */
935 wait_WOC(iobase);
936 writeb(NETWAVE_CMD_STC, ramBase + NETWAVE_EREG_CB + 0);
937 writeb(txConfTxEna, ramBase + NETWAVE_EREG_CB + 1);
938 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 2);
940 /* Now set the MU Domain */
941 printk(KERN_DEBUG "Setting domain to 0x%x%02x\n", (domain >> 8) & 0x01, domain & 0xff);
942 wait_WOC(iobase);
943 writeb(NETWAVE_CMD_SMD, ramBase + NETWAVE_EREG_CB + 0);
944 writeb(domain & 0xff, ramBase + NETWAVE_EREG_CB + 1);
945 writeb((domain>>8) & 0x01, ramBase + NETWAVE_EREG_CB + 2);
946 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 3);
948 /* Set scramble key */
949 printk(KERN_DEBUG "Setting scramble key to 0x%x\n", scramble_key);
950 wait_WOC(iobase);
951 writeb(NETWAVE_CMD_SSK, ramBase + NETWAVE_EREG_CB + 0);
952 writeb(scramble_key & 0xff, ramBase + NETWAVE_EREG_CB + 1);
953 writeb((scramble_key>>8) & 0xff, ramBase + NETWAVE_EREG_CB + 2);
954 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 3);
956 /* Enable interrupts, bit 4 high to keep unused
957 * source from interrupting us, bit 2 high to
958 * set interrupt enable, 567 to enable TxDN,
959 * RxErr and RxRdy
961 wait_WOC(iobase);
962 outb(imrConfIENA+imrConfRFU1, iobase + NETWAVE_REG_IMR);
964 /* Hent 4 bytes fra 0x170. Skal vaere 0a,29,88,36
965 * waitWOC
966 * skriv 80 til d000:3688
967 * sjekk om det ble 80
970 /* Enable Receiver */
971 wait_WOC(iobase);
972 writeb(NETWAVE_CMD_ER, ramBase + NETWAVE_EREG_CB + 0);
973 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 1);
975 /* Set the IENA bit in COR */
976 wait_WOC(iobase);
977 outb(corConfIENA + corConfLVLREQ, iobase + NETWAVE_REG_COR);
981 * Function netwave_hw_xmit (data, len, dev)
983 static int netwave_hw_xmit(unsigned char* data, int len,
984 struct net_device* dev) {
985 unsigned long flags;
986 unsigned int TxFreeList,
987 curBuff,
988 MaxData,
989 DataOffset;
990 int tmpcount;
992 netwave_private *priv = netdev_priv(dev);
993 u_char __iomem * ramBase = priv->ramBase;
994 kio_addr_t iobase = dev->base_addr;
996 /* Disable interrupts & save flags */
997 spin_lock_irqsave(&priv->spinlock, flags);
999 /* Check if there are transmit buffers available */
1000 wait_WOC(iobase);
1001 if ((inb(iobase+NETWAVE_REG_ASR) & NETWAVE_ASR_TXBA) == 0) {
1002 /* No buffers available */
1003 printk(KERN_DEBUG "netwave_hw_xmit: %s - no xmit buffers available.\n",
1004 dev->name);
1005 spin_unlock_irqrestore(&priv->spinlock, flags);
1006 return 1;
1009 priv->stats.tx_bytes += len;
1011 DEBUG(3, "Transmitting with SPCQ %x SPU %x LIF %x ISPLQ %x\n",
1012 readb(ramBase + NETWAVE_EREG_SPCQ),
1013 readb(ramBase + NETWAVE_EREG_SPU),
1014 readb(ramBase + NETWAVE_EREG_LIF),
1015 readb(ramBase + NETWAVE_EREG_ISPLQ));
1017 /* Now try to insert it into the adapters free memory */
1018 wait_WOC(iobase);
1019 TxFreeList = get_uint16(ramBase + NETWAVE_EREG_TDP);
1020 MaxData = get_uint16(ramBase + NETWAVE_EREG_TDP+2);
1021 DataOffset = get_uint16(ramBase + NETWAVE_EREG_TDP+4);
1023 DEBUG(3, "TxFreeList %x, MaxData %x, DataOffset %x\n",
1024 TxFreeList, MaxData, DataOffset);
1026 /* Copy packet to the adapter fragment buffers */
1027 curBuff = TxFreeList;
1028 tmpcount = 0;
1029 while (tmpcount < len) {
1030 int tmplen = len - tmpcount;
1031 copy_to_pc(ramBase + curBuff + DataOffset, data + tmpcount,
1032 (tmplen < MaxData) ? tmplen : MaxData);
1033 tmpcount += MaxData;
1035 /* Advance to next buffer */
1036 curBuff = get_uint16(ramBase + curBuff);
1039 /* Now issue transmit list */
1040 wait_WOC(iobase);
1041 writeb(NETWAVE_CMD_TL, ramBase + NETWAVE_EREG_CB + 0);
1042 writeb(len & 0xff, ramBase + NETWAVE_EREG_CB + 1);
1043 writeb((len>>8) & 0xff, ramBase + NETWAVE_EREG_CB + 2);
1044 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 3);
1046 spin_unlock_irqrestore(&priv->spinlock, flags);
1047 return 0;
1050 static int netwave_start_xmit(struct sk_buff *skb, struct net_device *dev) {
1051 /* This flag indicate that the hardware can't perform a transmission.
1052 * Theoritically, NET3 check it before sending a packet to the driver,
1053 * but in fact it never do that and pool continuously.
1054 * As the watchdog will abort too long transmissions, we are quite safe...
1057 netif_stop_queue(dev);
1060 short length = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
1061 unsigned char* buf = skb->data;
1063 if (netwave_hw_xmit( buf, length, dev) == 1) {
1064 /* Some error, let's make them call us another time? */
1065 netif_start_queue(dev);
1067 dev->trans_start = jiffies;
1069 dev_kfree_skb(skb);
1071 return 0;
1072 } /* netwave_start_xmit */
1075 * Function netwave_interrupt (irq, dev_id)
1077 * This function is the interrupt handler for the Netwave card. This
1078 * routine will be called whenever:
1079 * 1. A packet is received.
1080 * 2. A packet has successfully been transferred and the unit is
1081 * ready to transmit another packet.
1082 * 3. A command has completed execution.
1084 static irqreturn_t netwave_interrupt(int irq, void* dev_id)
1086 kio_addr_t iobase;
1087 u_char __iomem *ramBase;
1088 struct net_device *dev = (struct net_device *)dev_id;
1089 struct netwave_private *priv = netdev_priv(dev);
1090 struct pcmcia_device *link = priv->p_dev;
1091 int i;
1093 if (!netif_device_present(dev))
1094 return IRQ_NONE;
1096 iobase = dev->base_addr;
1097 ramBase = priv->ramBase;
1099 /* Now find what caused the interrupt, check while interrupts ready */
1100 for (i = 0; i < 10; i++) {
1101 u_char status;
1103 wait_WOC(iobase);
1104 if (!(inb(iobase+NETWAVE_REG_CCSR) & 0x02))
1105 break; /* None of the interrupt sources asserted (normal exit) */
1107 status = inb(iobase + NETWAVE_REG_ASR);
1109 if (!pcmcia_dev_present(link)) {
1110 DEBUG(1, "netwave_interrupt: Interrupt with status 0x%x "
1111 "from removed or suspended card!\n", status);
1112 break;
1115 /* RxRdy */
1116 if (status & 0x80) {
1117 netwave_rx(dev);
1118 /* wait_WOC(iobase); */
1119 /* RxRdy cannot be reset directly by the host */
1121 /* RxErr */
1122 if (status & 0x40) {
1123 u_char rser;
1125 rser = readb(ramBase + NETWAVE_EREG_RSER);
1127 if (rser & 0x04) {
1128 ++priv->stats.rx_dropped;
1129 ++priv->stats.rx_crc_errors;
1131 if (rser & 0x02)
1132 ++priv->stats.rx_frame_errors;
1134 /* Clear the RxErr bit in RSER. RSER+4 is the
1135 * write part. Also clear the RxCRC (0x04) and
1136 * RxBig (0x02) bits if present */
1137 wait_WOC(iobase);
1138 writeb(0x40 | (rser & 0x06), ramBase + NETWAVE_EREG_RSER + 4);
1140 /* Write bit 6 high to ASCC to clear RxErr in ASR,
1141 * WOC must be set first!
1143 wait_WOC(iobase);
1144 writeb(0x40, ramBase + NETWAVE_EREG_ASCC);
1146 /* Remember to count up priv->stats on error packets */
1147 ++priv->stats.rx_errors;
1149 /* TxDN */
1150 if (status & 0x20) {
1151 int txStatus;
1153 txStatus = readb(ramBase + NETWAVE_EREG_TSER);
1154 DEBUG(3, "Transmit done. TSER = %x id %x\n",
1155 txStatus, readb(ramBase + NETWAVE_EREG_TSER + 1));
1157 if (txStatus & 0x20) {
1158 /* Transmitting was okay, clear bits */
1159 wait_WOC(iobase);
1160 writeb(0x2f, ramBase + NETWAVE_EREG_TSER + 4);
1161 ++priv->stats.tx_packets;
1164 if (txStatus & 0xd0) {
1165 if (txStatus & 0x80) {
1166 ++priv->stats.collisions; /* Because of /proc/net/dev*/
1167 /* ++priv->stats.tx_aborted_errors; */
1168 /* printk("Collision. %ld\n", jiffies - dev->trans_start); */
1170 if (txStatus & 0x40)
1171 ++priv->stats.tx_carrier_errors;
1172 /* 0x80 TxGU Transmit giveup - nine times and no luck
1173 * 0x40 TxNOAP No access point. Discarded packet.
1174 * 0x10 TxErr Transmit error. Always set when
1175 * TxGU and TxNOAP is set. (Those are the only ones
1176 * to set TxErr).
1178 DEBUG(3, "netwave_interrupt: TxDN with error status %x\n",
1179 txStatus);
1181 /* Clear out TxGU, TxNOAP, TxErr and TxTrys */
1182 wait_WOC(iobase);
1183 writeb(0xdf & txStatus, ramBase+NETWAVE_EREG_TSER+4);
1184 ++priv->stats.tx_errors;
1186 DEBUG(3, "New status is TSER %x ASR %x\n",
1187 readb(ramBase + NETWAVE_EREG_TSER),
1188 inb(iobase + NETWAVE_REG_ASR));
1190 netif_wake_queue(dev);
1192 /* TxBA, this would trigger on all error packets received */
1193 /* if (status & 0x01) {
1194 DEBUG(4, "Transmit buffers available, %x\n", status);
1198 /* Handled if we looped at least one time - Jean II */
1199 return IRQ_RETVAL(i);
1200 } /* netwave_interrupt */
1203 * Function netwave_watchdog (a)
1205 * Watchdog : when we start a transmission, we set a timer in the
1206 * kernel. If the transmission complete, this timer is disabled. If
1207 * it expire, we reset the card.
1210 static void netwave_watchdog(struct net_device *dev) {
1212 DEBUG(1, "%s: netwave_watchdog: watchdog timer expired\n", dev->name);
1213 netwave_reset(dev);
1214 dev->trans_start = jiffies;
1215 netif_wake_queue(dev);
1216 } /* netwave_watchdog */
1218 static struct net_device_stats *netwave_get_stats(struct net_device *dev) {
1219 netwave_private *priv = netdev_priv(dev);
1221 update_stats(dev);
1223 DEBUG(2, "netwave: SPCQ %x SPU %x LIF %x ISPLQ %x MHS %x rxtx %x"
1224 " %x tx %x %x %x %x\n",
1225 readb(priv->ramBase + NETWAVE_EREG_SPCQ),
1226 readb(priv->ramBase + NETWAVE_EREG_SPU),
1227 readb(priv->ramBase + NETWAVE_EREG_LIF),
1228 readb(priv->ramBase + NETWAVE_EREG_ISPLQ),
1229 readb(priv->ramBase + NETWAVE_EREG_MHS),
1230 readb(priv->ramBase + NETWAVE_EREG_EC + 0xe),
1231 readb(priv->ramBase + NETWAVE_EREG_EC + 0xf),
1232 readb(priv->ramBase + NETWAVE_EREG_EC + 0x18),
1233 readb(priv->ramBase + NETWAVE_EREG_EC + 0x19),
1234 readb(priv->ramBase + NETWAVE_EREG_EC + 0x1a),
1235 readb(priv->ramBase + NETWAVE_EREG_EC + 0x1b));
1237 return &priv->stats;
1240 static void update_stats(struct net_device *dev) {
1241 //unsigned long flags;
1242 /* netwave_private *priv = netdev_priv(dev); */
1244 //spin_lock_irqsave(&priv->spinlock, flags);
1246 /* priv->stats.rx_packets = readb(priv->ramBase + 0x18e);
1247 priv->stats.tx_packets = readb(priv->ramBase + 0x18f); */
1249 //spin_unlock_irqrestore(&priv->spinlock, flags);
1252 static int netwave_rx(struct net_device *dev)
1254 netwave_private *priv = netdev_priv(dev);
1255 u_char __iomem *ramBase = priv->ramBase;
1256 kio_addr_t iobase = dev->base_addr;
1257 u_char rxStatus;
1258 struct sk_buff *skb = NULL;
1259 unsigned int curBuffer,
1260 rcvList;
1261 int rcvLen;
1262 int tmpcount = 0;
1263 int dataCount, dataOffset;
1264 int i;
1265 u_char *ptr;
1267 DEBUG(3, "xinw_rx: Receiving ... \n");
1269 /* Receive max 10 packets for now. */
1270 for (i = 0; i < 10; i++) {
1271 /* Any packets? */
1272 wait_WOC(iobase);
1273 rxStatus = readb(ramBase + NETWAVE_EREG_RSER);
1274 if ( !( rxStatus & 0x80)) /* No more packets */
1275 break;
1277 /* Check if multicast/broadcast or other */
1278 /* multicast = (rxStatus & 0x20); */
1280 /* The receive list pointer and length of the packet */
1281 wait_WOC(iobase);
1282 rcvLen = get_int16( ramBase + NETWAVE_EREG_RDP);
1283 rcvList = get_uint16( ramBase + NETWAVE_EREG_RDP + 2);
1285 if (rcvLen < 0) {
1286 printk(KERN_DEBUG "netwave_rx: Receive packet with len %d\n",
1287 rcvLen);
1288 return 0;
1291 skb = dev_alloc_skb(rcvLen+5);
1292 if (skb == NULL) {
1293 DEBUG(1, "netwave_rx: Could not allocate an sk_buff of "
1294 "length %d\n", rcvLen);
1295 ++priv->stats.rx_dropped;
1296 /* Tell the adapter to skip the packet */
1297 wait_WOC(iobase);
1298 writeb(NETWAVE_CMD_SRP, ramBase + NETWAVE_EREG_CB + 0);
1299 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 1);
1300 return 0;
1303 skb_reserve( skb, 2); /* Align IP on 16 byte */
1304 skb_put( skb, rcvLen);
1305 skb->dev = dev;
1307 /* Copy packet fragments to the skb data area */
1308 ptr = (u_char*) skb->data;
1309 curBuffer = rcvList;
1310 tmpcount = 0;
1311 while ( tmpcount < rcvLen) {
1312 /* Get length and offset of current buffer */
1313 dataCount = get_uint16( ramBase+curBuffer+2);
1314 dataOffset = get_uint16( ramBase+curBuffer+4);
1316 copy_from_pc( ptr + tmpcount,
1317 ramBase+curBuffer+dataOffset, dataCount);
1319 tmpcount += dataCount;
1321 /* Point to next buffer */
1322 curBuffer = get_uint16(ramBase + curBuffer);
1325 skb->protocol = eth_type_trans(skb,dev);
1326 /* Queue packet for network layer */
1327 netif_rx(skb);
1329 dev->last_rx = jiffies;
1330 priv->stats.rx_packets++;
1331 priv->stats.rx_bytes += rcvLen;
1333 /* Got the packet, tell the adapter to skip it */
1334 wait_WOC(iobase);
1335 writeb(NETWAVE_CMD_SRP, ramBase + NETWAVE_EREG_CB + 0);
1336 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 1);
1337 DEBUG(3, "Packet reception ok\n");
1339 return 0;
1342 static int netwave_open(struct net_device *dev) {
1343 netwave_private *priv = netdev_priv(dev);
1344 struct pcmcia_device *link = priv->p_dev;
1346 DEBUG(1, "netwave_open: starting.\n");
1348 if (!pcmcia_dev_present(link))
1349 return -ENODEV;
1351 link->open++;
1353 netif_start_queue(dev);
1354 netwave_reset(dev);
1356 return 0;
1359 static int netwave_close(struct net_device *dev) {
1360 netwave_private *priv = netdev_priv(dev);
1361 struct pcmcia_device *link = priv->p_dev;
1363 DEBUG(1, "netwave_close: finishing.\n");
1365 link->open--;
1366 netif_stop_queue(dev);
1368 return 0;
1371 static struct pcmcia_device_id netwave_ids[] = {
1372 PCMCIA_DEVICE_PROD_ID12("Xircom", "CreditCard Netwave", 0x2e3ee845, 0x54e28a28),
1373 PCMCIA_DEVICE_NULL,
1375 MODULE_DEVICE_TABLE(pcmcia, netwave_ids);
1377 static struct pcmcia_driver netwave_driver = {
1378 .owner = THIS_MODULE,
1379 .drv = {
1380 .name = "netwave_cs",
1382 .probe = netwave_probe,
1383 .remove = netwave_detach,
1384 .id_table = netwave_ids,
1385 .suspend = netwave_suspend,
1386 .resume = netwave_resume,
1389 static int __init init_netwave_cs(void)
1391 return pcmcia_register_driver(&netwave_driver);
1394 static void __exit exit_netwave_cs(void)
1396 pcmcia_unregister_driver(&netwave_driver);
1399 module_init(init_netwave_cs);
1400 module_exit(exit_netwave_cs);
1402 /* Set or clear the multicast filter for this adaptor.
1403 num_addrs == -1 Promiscuous mode, receive all packets
1404 num_addrs == 0 Normal mode, clear multicast list
1405 num_addrs > 0 Multicast mode, receive normal and MC packets, and do
1406 best-effort filtering.
1408 static void set_multicast_list(struct net_device *dev)
1410 kio_addr_t iobase = dev->base_addr;
1411 netwave_private *priv = netdev_priv(dev);
1412 u_char __iomem * ramBase = priv->ramBase;
1413 u_char rcvMode = 0;
1415 #ifdef PCMCIA_DEBUG
1416 if (pc_debug > 2) {
1417 static int old;
1418 if (old != dev->mc_count) {
1419 old = dev->mc_count;
1420 DEBUG(0, "%s: setting Rx mode to %d addresses.\n",
1421 dev->name, dev->mc_count);
1424 #endif
1426 if (dev->mc_count || (dev->flags & IFF_ALLMULTI)) {
1427 /* Multicast Mode */
1428 rcvMode = rxConfRxEna + rxConfAMP + rxConfBcast;
1429 } else if (dev->flags & IFF_PROMISC) {
1430 /* Promiscous mode */
1431 rcvMode = rxConfRxEna + rxConfPro + rxConfAMP + rxConfBcast;
1432 } else {
1433 /* Normal mode */
1434 rcvMode = rxConfRxEna + rxConfBcast;
1437 /* printk("netwave set_multicast_list: rcvMode to %x\n", rcvMode);*/
1438 /* Now set receive mode */
1439 wait_WOC(iobase);
1440 writeb(NETWAVE_CMD_SRC, ramBase + NETWAVE_EREG_CB + 0);
1441 writeb(rcvMode, ramBase + NETWAVE_EREG_CB + 1);
1442 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 2);
1444 MODULE_LICENSE("GPL");