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