blob: 7ab2d70ffddf39723dc12f09dfb45ece04716722 [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
169static dev_info_t dev_info = "netwave_cs";
170
171/*====================================================================*/
172
173/* Parameters that can be set with 'insmod' */
174
175/* Choose the domain, default is 0x100 */
176static u_int domain = 0x100;
177
178/* Scramble key, range from 0x0 to 0xffff.
179 * 0x0 is no scrambling.
180 */
181static u_int scramble_key = 0x0;
182
183/* Shared memory speed, in ns. The documentation states that
184 * the card should not be read faster than every 400ns.
185 * This timing should be provided by the HBA. If it becomes a
186 * problem, try setting mem_speed to 400.
187 */
188static int mem_speed;
189
190module_param(domain, int, 0);
191module_param(scramble_key, int, 0);
192module_param(mem_speed, int, 0);
193
194/*====================================================================*/
195
196/* PCMCIA (Card Services) related functions */
197static void netwave_release(dev_link_t *link); /* Card removal */
198static int netwave_event(event_t event, int priority,
199 event_callback_args_t *args);
200static void netwave_pcmcia_config(dev_link_t *arg); /* Runs after card
201 insertion */
202static dev_link_t *netwave_attach(void); /* Create instance */
203static void netwave_detach(dev_link_t *); /* Destroy instance */
204
205/* Hardware configuration */
206static void netwave_doreset(kio_addr_t iobase, u_char __iomem *ramBase);
207static void netwave_reset(struct net_device *dev);
208
209/* Misc device stuff */
210static int netwave_open(struct net_device *dev); /* Open the device */
211static int netwave_close(struct net_device *dev); /* Close the device */
212
213/* Packet transmission and Packet reception */
214static int netwave_start_xmit( struct sk_buff *skb, struct net_device *dev);
215static int netwave_rx( struct net_device *dev);
216
217/* Interrupt routines */
218static irqreturn_t netwave_interrupt(int irq, void *dev_id, struct pt_regs *regs);
219static void netwave_watchdog(struct net_device *);
220
221/* Statistics */
222static void update_stats(struct net_device *dev);
223static struct net_device_stats *netwave_get_stats(struct net_device *dev);
224
225/* Wireless extensions */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226static struct iw_statistics* netwave_get_wireless_stats(struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227
228static void set_multicast_list(struct net_device *dev);
229
230/*
231 A linked list of "instances" of the skeleton device. Each actual
232 PCMCIA card corresponds to one device instance, and is described
233 by one dev_link_t structure (defined in ds.h).
234
235 You may not want to use a linked list for this -- for example, the
236 memory card driver uses an array of dev_link_t pointers, where minor
237 device numbers are used to derive the corresponding array index.
238*/
239static dev_link_t *dev_list;
240
241/*
242 A dev_link_t structure has fields for most things that are needed
243 to keep track of a socket, but there will usually be some device
244 specific information that also needs to be kept track of. The
245 'priv' pointer in a dev_link_t structure can be used to point to
246 a device-specific private data structure, like this.
247
248 A driver needs to provide a dev_node_t structure for each device
249 on a card. In some cases, there is only one device per card (for
250 example, ethernet cards, modems). In other cases, there may be
251 many actual or logical devices (SCSI adapters, memory cards with
252 multiple partitions). The dev_node_t structures need to be kept
253 in a linked list starting at the 'dev' field of a dev_link_t
254 structure. We allocate them in the card's private data structure,
255 because they generally can't be allocated dynamically.
256*/
257
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258static const struct iw_handler_def netwave_handler_def;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259
260#define SIOCGIPSNAP SIOCIWFIRSTPRIV + 1 /* Site Survey Snapshot */
261
262#define MAX_ESA 10
263
264typedef struct net_addr {
265 u_char addr48[6];
266} net_addr;
267
268struct site_survey {
269 u_short length;
270 u_char struct_revision;
271 u_char roaming_state;
272
273 u_char sp_existsFlag;
274 u_char sp_link_quality;
275 u_char sp_max_link_quality;
276 u_char linkQualityGoodFairBoundary;
277 u_char linkQualityFairPoorBoundary;
278 u_char sp_utilization;
279 u_char sp_goodness;
280 u_char sp_hotheadcount;
281 u_char roaming_condition;
282
283 net_addr sp;
284 u_char numAPs;
285 net_addr nearByAccessPoints[MAX_ESA];
286};
287
288typedef struct netwave_private {
289 dev_link_t link;
290 spinlock_t spinlock; /* Serialize access to the hardware (SMP) */
291 dev_node_t node;
292 u_char __iomem *ramBase;
293 int timeoutCounter;
294 int lastExec;
295 struct timer_list watchdog; /* To avoid blocking state */
296 struct site_survey nss;
297 struct net_device_stats stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 struct iw_statistics iw_stats; /* Wireless stats */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299} netwave_private;
300
301#ifdef NETWAVE_STATS
302static struct net_device_stats *netwave_get_stats(struct net_device *dev);
303#endif
304
305/*
306 * The Netwave card is little-endian, so won't work for big endian
307 * systems.
308 */
309static inline unsigned short get_uint16(u_char __iomem *staddr)
310{
311 return readw(staddr); /* Return only 16 bits */
312}
313
314static inline short get_int16(u_char __iomem * staddr)
315{
316 return readw(staddr);
317}
318
319/*
320 * Wait until the WOC (Write Operation Complete) bit in the
321 * ASR (Adapter Status Register) is asserted.
322 * This should have aborted if it takes too long time.
323 */
324static inline void wait_WOC(unsigned int iobase)
325{
326 /* Spin lock */
327 while ((inb(iobase + NETWAVE_REG_ASR) & 0x8) != 0x8) ;
328}
329
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330static void netwave_snapshot(netwave_private *priv, u_char __iomem *ramBase,
331 kio_addr_t iobase) {
332 u_short resultBuffer;
333
334 /* if time since last snapshot is > 1 sec. (100 jiffies?) then take
335 * new snapshot, else return cached data. This is the recommended rate.
336 */
337 if ( jiffies - priv->lastExec > 100) {
338 /* Take site survey snapshot */
339 /*printk( KERN_DEBUG "Taking new snapshot. %ld\n", jiffies -
340 priv->lastExec); */
341 wait_WOC(iobase);
342 writeb(NETWAVE_CMD_SSS, ramBase + NETWAVE_EREG_CB + 0);
343 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 1);
344 wait_WOC(iobase);
345
346 /* Get result and copy to cach */
347 resultBuffer = readw(ramBase + NETWAVE_EREG_CRBP);
348 copy_from_pc( &priv->nss, ramBase+resultBuffer,
349 sizeof(struct site_survey));
350 }
351}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353/*
354 * Function netwave_get_wireless_stats (dev)
355 *
356 * Wireless extensions statistics
357 *
358 */
359static struct iw_statistics *netwave_get_wireless_stats(struct net_device *dev)
360{
361 unsigned long flags;
362 kio_addr_t iobase = dev->base_addr;
363 netwave_private *priv = netdev_priv(dev);
364 u_char __iomem *ramBase = priv->ramBase;
365 struct iw_statistics* wstats;
366
367 wstats = &priv->iw_stats;
368
369 spin_lock_irqsave(&priv->spinlock, flags);
370
371 netwave_snapshot( priv, ramBase, iobase);
372
373 wstats->status = priv->nss.roaming_state;
374 wstats->qual.qual = readb( ramBase + NETWAVE_EREG_SPCQ);
375 wstats->qual.level = readb( ramBase + NETWAVE_EREG_ISPLQ);
376 wstats->qual.noise = readb( ramBase + NETWAVE_EREG_SPU) & 0x3f;
377 wstats->discard.nwid = 0L;
378 wstats->discard.code = 0L;
379 wstats->discard.misc = 0L;
380
381 spin_unlock_irqrestore(&priv->spinlock, flags);
382
383 return &priv->iw_stats;
384}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385
386/*
387 * Function netwave_attach (void)
388 *
389 * Creates an "instance" of the driver, allocating local data
390 * structures for one device. The device is registered with Card
391 * Services.
392 *
393 * The dev_link structure is initialized, but we don't actually
394 * configure the card at this point -- we wait until we receive a
395 * card insertion event.
396 */
397static dev_link_t *netwave_attach(void)
398{
399 client_reg_t client_reg;
400 dev_link_t *link;
401 struct net_device *dev;
402 netwave_private *priv;
403 int ret;
404
405 DEBUG(0, "netwave_attach()\n");
406
407 /* Initialize the dev_link_t structure */
408 dev = alloc_etherdev(sizeof(netwave_private));
409 if (!dev)
410 return NULL;
411 priv = netdev_priv(dev);
412 link = &priv->link;
413 link->priv = dev;
414
415 /* The io structure describes IO port mapping */
416 link->io.NumPorts1 = 16;
417 link->io.Attributes1 = IO_DATA_PATH_WIDTH_16;
418 /* link->io.NumPorts2 = 16;
419 link->io.Attributes2 = IO_DATA_PATH_WIDTH_16; */
420 link->io.IOAddrLines = 5;
421
422 /* Interrupt setup */
423 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT;
424 link->irq.IRQInfo1 = IRQ_LEVEL_ID;
425 link->irq.Handler = &netwave_interrupt;
426
427 /* General socket configuration */
428 link->conf.Attributes = CONF_ENABLE_IRQ;
429 link->conf.Vcc = 50;
430 link->conf.IntType = INT_MEMORY_AND_IO;
431 link->conf.ConfigIndex = 1;
432 link->conf.Present = PRESENT_OPTION;
433
434 /* Netwave private struct init. link/dev/node already taken care of,
435 * other stuff zero'd - Jean II */
436 spin_lock_init(&priv->spinlock);
437
438 /* Netwave specific entries in the device structure */
439 SET_MODULE_OWNER(dev);
440 dev->hard_start_xmit = &netwave_start_xmit;
441 dev->get_stats = &netwave_get_stats;
442 dev->set_multicast_list = &set_multicast_list;
443 /* wireless extensions */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444 dev->wireless_handlers = (struct iw_handler_def *)&netwave_handler_def;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445
446 dev->tx_timeout = &netwave_watchdog;
447 dev->watchdog_timeo = TX_TIMEOUT;
448
449 dev->open = &netwave_open;
450 dev->stop = &netwave_close;
451 link->irq.Instance = dev;
452
453 /* Register with Card Services */
454 link->next = dev_list;
455 dev_list = link;
456 client_reg.dev_info = &dev_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 client_reg.Version = 0x0210;
458 client_reg.event_callback_args.client_data = link;
459 ret = pcmcia_register_client(&link->handle, &client_reg);
460 if (ret != 0) {
461 cs_error(link->handle, RegisterClient, ret);
462 netwave_detach(link);
463 return NULL;
464 }
465
466 return link;
467} /* netwave_attach */
468
469/*
470 * Function netwave_detach (link)
471 *
472 * This deletes a driver "instance". The device is de-registered
473 * with Card Services. If it has been released, all local data
474 * structures are freed. Otherwise, the structures will be freed
475 * when the device is released.
476 */
477static void netwave_detach(dev_link_t *link)
478{
479 struct net_device *dev = link->priv;
480 dev_link_t **linkp;
481
482 DEBUG(0, "netwave_detach(0x%p)\n", link);
483
484 /*
485 If the device is currently configured and active, we won't
486 actually delete it yet. Instead, it is marked so that when
487 the release() function is called, that will trigger a proper
488 detach().
489 */
490 if (link->state & DEV_CONFIG)
491 netwave_release(link);
492
493 /* Break the link with Card Services */
494 if (link->handle)
495 pcmcia_deregister_client(link->handle);
496
497 /* Locate device structure */
498 for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next)
499 if (*linkp == link) break;
500 if (*linkp == NULL)
501 {
502 DEBUG(1, "netwave_cs: detach fail, '%s' not in list\n",
503 link->dev->dev_name);
504 return;
505 }
506
507 /* Unlink device structure, free pieces */
508 *linkp = link->next;
509 if (link->dev)
510 unregister_netdev(dev);
511 free_netdev(dev);
512
513} /* netwave_detach */
514
515/*
516 * Wireless Handler : get protocol name
517 */
518static int netwave_get_name(struct net_device *dev,
519 struct iw_request_info *info,
520 union iwreq_data *wrqu,
521 char *extra)
522{
523 strcpy(wrqu->name, "Netwave");
524 return 0;
525}
526
527/*
528 * Wireless Handler : set Network ID
529 */
530static int netwave_set_nwid(struct net_device *dev,
531 struct iw_request_info *info,
532 union iwreq_data *wrqu,
533 char *extra)
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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 if(!wrqu->nwid.disabled) {
544 domain = wrqu->nwid.value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 printk( KERN_DEBUG "Setting domain to 0x%x%02x\n",
546 (domain >> 8) & 0x01, domain & 0xff);
547 wait_WOC(iobase);
548 writeb(NETWAVE_CMD_SMD, ramBase + NETWAVE_EREG_CB + 0);
549 writeb( domain & 0xff, ramBase + NETWAVE_EREG_CB + 1);
550 writeb((domain >>8 ) & 0x01,ramBase + NETWAVE_EREG_CB+2);
551 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 3);
552 }
553
554 /* ReEnable interrupts & restore flags */
555 spin_unlock_irqrestore(&priv->spinlock, flags);
556
557 return 0;
558}
559
560/*
561 * Wireless Handler : get Network ID
562 */
563static int netwave_get_nwid(struct net_device *dev,
564 struct iw_request_info *info,
565 union iwreq_data *wrqu,
566 char *extra)
567{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 wrqu->nwid.value = domain;
569 wrqu->nwid.disabled = 0;
570 wrqu->nwid.fixed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 return 0;
572}
573
574/*
575 * Wireless Handler : set scramble key
576 */
577static int netwave_set_scramble(struct net_device *dev,
578 struct iw_request_info *info,
579 union iwreq_data *wrqu,
580 char *key)
581{
582 unsigned long flags;
583 kio_addr_t iobase = dev->base_addr;
584 netwave_private *priv = netdev_priv(dev);
585 u_char __iomem *ramBase = priv->ramBase;
586
587 /* Disable interrupts & save flags */
588 spin_lock_irqsave(&priv->spinlock, flags);
589
590 scramble_key = (key[0] << 8) | key[1];
591 wait_WOC(iobase);
592 writeb(NETWAVE_CMD_SSK, ramBase + NETWAVE_EREG_CB + 0);
593 writeb(scramble_key & 0xff, ramBase + NETWAVE_EREG_CB + 1);
594 writeb((scramble_key>>8) & 0xff, ramBase + NETWAVE_EREG_CB + 2);
595 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 3);
596
597 /* ReEnable interrupts & restore flags */
598 spin_unlock_irqrestore(&priv->spinlock, flags);
599
600 return 0;
601}
602
603/*
604 * Wireless Handler : get scramble key
605 */
606static int netwave_get_scramble(struct net_device *dev,
607 struct iw_request_info *info,
608 union iwreq_data *wrqu,
609 char *key)
610{
611 key[1] = scramble_key & 0xff;
612 key[0] = (scramble_key>>8) & 0xff;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 wrqu->encoding.flags = IW_ENCODE_ENABLED;
614 wrqu->encoding.length = 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 return 0;
616}
617
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618/*
619 * Wireless Handler : get mode
620 */
621static int netwave_get_mode(struct net_device *dev,
622 struct iw_request_info *info,
623 union iwreq_data *wrqu,
624 char *extra)
625{
626 if(domain & 0x100)
627 wrqu->mode = IW_MODE_INFRA;
628 else
629 wrqu->mode = IW_MODE_ADHOC;
630
631 return 0;
632}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633
634/*
635 * Wireless Handler : get range info
636 */
637static int netwave_get_range(struct net_device *dev,
638 struct iw_request_info *info,
639 union iwreq_data *wrqu,
640 char *extra)
641{
642 struct iw_range *range = (struct iw_range *) extra;
643 int ret = 0;
644
645 /* Set the length (very important for backward compatibility) */
646 wrqu->data.length = sizeof(struct iw_range);
647
648 /* Set all the info we don't care or don't know about to zero */
649 memset(range, 0, sizeof(struct iw_range));
650
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 /* Set the Wireless Extension versions */
652 range->we_version_compiled = WIRELESS_EXT;
653 range->we_version_source = 9; /* Nothing for us in v10 and v11 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654
655 /* Set information in the range struct */
656 range->throughput = 450 * 1000; /* don't argue on this ! */
657 range->min_nwid = 0x0000;
658 range->max_nwid = 0x01FF;
659
660 range->num_channels = range->num_frequency = 0;
661
662 range->sensitivity = 0x3F;
663 range->max_qual.qual = 255;
664 range->max_qual.level = 255;
665 range->max_qual.noise = 0;
666
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 range->num_bitrates = 1;
668 range->bitrate[0] = 1000000; /* 1 Mb/s */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 range->encoding_size[0] = 2; /* 16 bits scrambling */
671 range->num_encoding_sizes = 1;
672 range->max_encoding_tokens = 1; /* Only one key possible */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673
674 return ret;
675}
676
677/*
678 * Wireless Private Handler : get snapshot
679 */
680static int netwave_get_snap(struct net_device *dev,
681 struct iw_request_info *info,
682 union iwreq_data *wrqu,
683 char *extra)
684{
685 unsigned long flags;
686 kio_addr_t iobase = dev->base_addr;
687 netwave_private *priv = netdev_priv(dev);
688 u_char __iomem *ramBase = priv->ramBase;
689
690 /* Disable interrupts & save flags */
691 spin_lock_irqsave(&priv->spinlock, flags);
692
693 /* Take snapshot of environment */
694 netwave_snapshot( priv, ramBase, iobase);
695 wrqu->data.length = priv->nss.length;
696 memcpy(extra, (u_char *) &priv->nss, sizeof( struct site_survey));
697
698 priv->lastExec = jiffies;
699
700 /* ReEnable interrupts & restore flags */
701 spin_unlock_irqrestore(&priv->spinlock, flags);
702
703 return(0);
704}
705
706/*
707 * Structures to export the Wireless Handlers
708 * This is the stuff that are treated the wireless extensions (iwconfig)
709 */
710
711static const struct iw_priv_args netwave_private_args[] = {
712/*{ cmd, set_args, get_args, name } */
713 { SIOCGIPSNAP, 0,
714 IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | sizeof(struct site_survey),
715 "getsitesurvey" },
716};
717
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718static const iw_handler netwave_handler[] =
719{
720 NULL, /* SIOCSIWNAME */
721 netwave_get_name, /* SIOCGIWNAME */
722 netwave_set_nwid, /* SIOCSIWNWID */
723 netwave_get_nwid, /* SIOCGIWNWID */
724 NULL, /* SIOCSIWFREQ */
725 NULL, /* SIOCGIWFREQ */
726 NULL, /* SIOCSIWMODE */
727 netwave_get_mode, /* SIOCGIWMODE */
728 NULL, /* SIOCSIWSENS */
729 NULL, /* SIOCGIWSENS */
730 NULL, /* SIOCSIWRANGE */
731 netwave_get_range, /* SIOCGIWRANGE */
732 NULL, /* SIOCSIWPRIV */
733 NULL, /* SIOCGIWPRIV */
734 NULL, /* SIOCSIWSTATS */
735 NULL, /* SIOCGIWSTATS */
736 NULL, /* SIOCSIWSPY */
737 NULL, /* SIOCGIWSPY */
738 NULL, /* -- hole -- */
739 NULL, /* -- hole -- */
740 NULL, /* SIOCSIWAP */
741 NULL, /* SIOCGIWAP */
742 NULL, /* -- hole -- */
743 NULL, /* SIOCGIWAPLIST */
744 NULL, /* -- hole -- */
745 NULL, /* -- hole -- */
746 NULL, /* SIOCSIWESSID */
747 NULL, /* SIOCGIWESSID */
748 NULL, /* SIOCSIWNICKN */
749 NULL, /* SIOCGIWNICKN */
750 NULL, /* -- hole -- */
751 NULL, /* -- hole -- */
752 NULL, /* SIOCSIWRATE */
753 NULL, /* SIOCGIWRATE */
754 NULL, /* SIOCSIWRTS */
755 NULL, /* SIOCGIWRTS */
756 NULL, /* SIOCSIWFRAG */
757 NULL, /* SIOCGIWFRAG */
758 NULL, /* SIOCSIWTXPOW */
759 NULL, /* SIOCGIWTXPOW */
760 NULL, /* SIOCSIWRETRY */
761 NULL, /* SIOCGIWRETRY */
762 netwave_set_scramble, /* SIOCSIWENCODE */
763 netwave_get_scramble, /* SIOCGIWENCODE */
764};
765
766static const iw_handler netwave_private_handler[] =
767{
768 NULL, /* SIOCIWFIRSTPRIV */
769 netwave_get_snap, /* SIOCIWFIRSTPRIV + 1 */
770};
771
772static const struct iw_handler_def netwave_handler_def =
773{
774 .num_standard = sizeof(netwave_handler)/sizeof(iw_handler),
775 .num_private = sizeof(netwave_private_handler)/sizeof(iw_handler),
776 .num_private_args = sizeof(netwave_private_args)/sizeof(struct iw_priv_args),
777 .standard = (iw_handler *) netwave_handler,
778 .private = (iw_handler *) netwave_private_handler,
779 .private_args = (struct iw_priv_args *) netwave_private_args,
Jean Tourrilhes62337dd2005-09-02 11:39:02 -0700780 .get_wireless_stats = netwave_get_wireless_stats,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782
783/*
784 * Function netwave_pcmcia_config (link)
785 *
786 * netwave_pcmcia_config() is scheduled to run after a CARD_INSERTION
787 * event is received, to configure the PCMCIA socket, and to make the
788 * device available to the system.
789 *
790 */
791
792#define CS_CHECK(fn, ret) \
793do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
794
795static void netwave_pcmcia_config(dev_link_t *link) {
796 client_handle_t handle = link->handle;
797 struct net_device *dev = link->priv;
798 netwave_private *priv = netdev_priv(dev);
799 tuple_t tuple;
800 cisparse_t parse;
801 int i, j, last_ret, last_fn;
802 u_char buf[64];
803 win_req_t req;
804 memreq_t mem;
805 u_char __iomem *ramBase = NULL;
806
807 DEBUG(0, "netwave_pcmcia_config(0x%p)\n", link);
808
809 /*
810 This reads the card's CONFIG tuple to find its configuration
811 registers.
812 */
813 tuple.Attributes = 0;
814 tuple.TupleData = (cisdata_t *) buf;
815 tuple.TupleDataMax = 64;
816 tuple.TupleOffset = 0;
817 tuple.DesiredTuple = CISTPL_CONFIG;
818 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple));
819 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple));
820 CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse));
821 link->conf.ConfigBase = parse.config.base;
822 link->conf.Present = parse.config.rmask[0];
823
824 /* Configure card */
825 link->state |= DEV_CONFIG;
826
827 /*
828 * Try allocating IO ports. This tries a few fixed addresses.
829 * If you want, you can also read the card's config table to
830 * pick addresses -- see the serial driver for an example.
831 */
832 for (i = j = 0x0; j < 0x400; j += 0x20) {
833 link->io.BasePort1 = j ^ 0x300;
834 i = pcmcia_request_io(link->handle, &link->io);
835 if (i == CS_SUCCESS) break;
836 }
837 if (i != CS_SUCCESS) {
838 cs_error(link->handle, RequestIO, i);
839 goto failed;
840 }
841
842 /*
843 * Now allocate an interrupt line. Note that this does not
844 * actually assign a handler to the interrupt.
845 */
846 CS_CHECK(RequestIRQ, pcmcia_request_irq(handle, &link->irq));
847
848 /*
849 * This actually configures the PCMCIA socket -- setting up
850 * the I/O windows and the interrupt mapping.
851 */
852 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(handle, &link->conf));
853
854 /*
855 * Allocate a 32K memory window. Note that the dev_link_t
856 * structure provides space for one window handle -- if your
857 * device needs several windows, you'll need to keep track of
858 * the handles in your private data structure, dev->priv.
859 */
860 DEBUG(1, "Setting mem speed of %d\n", mem_speed);
861
862 req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_CM|WIN_ENABLE;
863 req.Base = 0; req.Size = 0x8000;
864 req.AccessSpeed = mem_speed;
865 CS_CHECK(RequestWindow, pcmcia_request_window(&link->handle, &req, &link->win));
866 mem.CardOffset = 0x20000; mem.Page = 0;
867 CS_CHECK(MapMemPage, pcmcia_map_mem_page(link->win, &mem));
868
869 /* Store base address of the common window frame */
870 ramBase = ioremap(req.Base, 0x8000);
871 priv->ramBase = ramBase;
872
873 dev->irq = link->irq.AssignedIRQ;
874 dev->base_addr = link->io.BasePort1;
875 SET_NETDEV_DEV(dev, &handle_to_dev(handle));
876
877 if (register_netdev(dev) != 0) {
878 printk(KERN_DEBUG "netwave_cs: register_netdev() failed\n");
879 goto failed;
880 }
881
882 strcpy(priv->node.dev_name, dev->name);
883 link->dev = &priv->node;
884 link->state &= ~DEV_CONFIG_PENDING;
885
886 /* Reset card before reading physical address */
887 netwave_doreset(dev->base_addr, ramBase);
888
889 /* Read the ethernet address and fill in the Netwave registers. */
890 for (i = 0; i < 6; i++)
891 dev->dev_addr[i] = readb(ramBase + NETWAVE_EREG_PA + i);
892
893 printk(KERN_INFO "%s: Netwave: port %#3lx, irq %d, mem %lx id "
894 "%c%c, hw_addr ", dev->name, dev->base_addr, dev->irq,
895 (u_long) ramBase, (int) readb(ramBase+NETWAVE_EREG_NI),
896 (int) readb(ramBase+NETWAVE_EREG_NI+1));
897 for (i = 0; i < 6; i++)
898 printk("%02X%s", dev->dev_addr[i], ((i<5) ? ":" : "\n"));
899
900 /* get revision words */
901 printk(KERN_DEBUG "Netwave_reset: revision %04x %04x\n",
902 get_uint16(ramBase + NETWAVE_EREG_ARW),
903 get_uint16(ramBase + NETWAVE_EREG_ARW+2));
904 return;
905
906cs_failed:
907 cs_error(link->handle, last_fn, last_ret);
908failed:
909 netwave_release(link);
910} /* netwave_pcmcia_config */
911
912/*
913 * Function netwave_release (arg)
914 *
915 * After a card is removed, netwave_release() will unregister the net
916 * device, and release the PCMCIA configuration. If the device is
917 * still open, this will be postponed until it is closed.
918 */
919static void netwave_release(dev_link_t *link)
920{
921 struct net_device *dev = link->priv;
922 netwave_private *priv = netdev_priv(dev);
923
924 DEBUG(0, "netwave_release(0x%p)\n", link);
925
926 /* Don't bother checking to see if these succeed or not */
927 if (link->win) {
928 iounmap(priv->ramBase);
929 pcmcia_release_window(link->win);
930 }
931 pcmcia_release_configuration(link->handle);
932 pcmcia_release_io(link->handle, &link->io);
933 pcmcia_release_irq(link->handle, &link->irq);
934
935 link->state &= ~DEV_CONFIG;
936}
937
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100938static int netwave_suspend(struct pcmcia_device *p_dev)
939{
940 dev_link_t *link = dev_to_instance(p_dev);
941 struct net_device *dev = link->priv;
942
943 link->state |= DEV_SUSPEND;
944 if (link->state & DEV_CONFIG) {
945 if (link->open)
946 netif_device_detach(dev);
947 pcmcia_release_configuration(link->handle);
948 }
949
950 return 0;
951}
952
953static int netwave_resume(struct pcmcia_device *p_dev)
954{
955 dev_link_t *link = dev_to_instance(p_dev);
956 struct net_device *dev = link->priv;
957
958 link->state &= ~DEV_SUSPEND;
959 if (link->state & DEV_CONFIG) {
960 pcmcia_request_configuration(link->handle, &link->conf);
961 if (link->open) {
962 netwave_reset(dev);
963 netif_device_attach(dev);
964 }
965 }
966
967 return 0;
968}
969
970
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971/*
972 * Function netwave_event (event, priority, args)
973 *
974 * The card status event handler. Mostly, this schedules other
975 * stuff to run after an event is received. A CARD_REMOVAL event
976 * also sets some flags to discourage the net drivers from trying
977 * to talk to the card any more.
978 *
979 * When a CARD_REMOVAL event is received, we immediately set a flag
980 * to block future accesses to this device. All the functions that
981 * actually access the device should check this flag to make sure
982 * the card is still present.
983 *
984 */
985static int netwave_event(event_t event, int priority,
986 event_callback_args_t *args)
987{
988 dev_link_t *link = args->client_data;
989 struct net_device *dev = link->priv;
990
991 DEBUG(1, "netwave_event(0x%06x)\n", event);
992
993 switch (event) {
994 case CS_EVENT_REGISTRATION_COMPLETE:
995 DEBUG(0, "netwave_cs: registration complete\n");
996 break;
997
998 case CS_EVENT_CARD_REMOVAL:
999 link->state &= ~DEV_PRESENT;
1000 if (link->state & DEV_CONFIG) {
1001 netif_device_detach(dev);
1002 netwave_release(link);
1003 }
1004 break;
1005 case CS_EVENT_CARD_INSERTION:
1006 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
1007 netwave_pcmcia_config( link);
1008 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009 }
1010 return 0;
1011} /* netwave_event */
1012
1013/*
1014 * Function netwave_doreset (ioBase, ramBase)
1015 *
1016 * Proper hardware reset of the card.
1017 */
1018static void netwave_doreset(kio_addr_t ioBase, u_char __iomem *ramBase)
1019{
1020 /* Reset card */
1021 wait_WOC(ioBase);
1022 outb(0x80, ioBase + NETWAVE_REG_PMR);
1023 writeb(0x08, ramBase + NETWAVE_EREG_ASCC); /* Bit 3 is WOC */
1024 outb(0x0, ioBase + NETWAVE_REG_PMR); /* release reset */
1025}
1026
1027/*
1028 * Function netwave_reset (dev)
1029 *
1030 * Reset and restore all of the netwave registers
1031 */
1032static void netwave_reset(struct net_device *dev) {
1033 /* u_char state; */
1034 netwave_private *priv = netdev_priv(dev);
1035 u_char __iomem *ramBase = priv->ramBase;
1036 kio_addr_t iobase = dev->base_addr;
1037
1038 DEBUG(0, "netwave_reset: Done with hardware reset\n");
1039
1040 priv->timeoutCounter = 0;
1041
1042 /* Reset card */
1043 netwave_doreset(iobase, ramBase);
1044 printk(KERN_DEBUG "netwave_reset: Done with hardware reset\n");
1045
1046 /* Write a NOP to check the card */
1047 wait_WOC(iobase);
1048 writeb(NETWAVE_CMD_NOP, ramBase + NETWAVE_EREG_CB + 0);
1049 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 1);
1050
1051 /* Set receive conf */
1052 wait_WOC(iobase);
1053 writeb(NETWAVE_CMD_SRC, ramBase + NETWAVE_EREG_CB + 0);
1054 writeb(rxConfRxEna + rxConfBcast, ramBase + NETWAVE_EREG_CB + 1);
1055 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 2);
1056
1057 /* Set transmit conf */
1058 wait_WOC(iobase);
1059 writeb(NETWAVE_CMD_STC, ramBase + NETWAVE_EREG_CB + 0);
1060 writeb(txConfTxEna, ramBase + NETWAVE_EREG_CB + 1);
1061 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 2);
1062
1063 /* Now set the MU Domain */
1064 printk(KERN_DEBUG "Setting domain to 0x%x%02x\n", (domain >> 8) & 0x01, domain & 0xff);
1065 wait_WOC(iobase);
1066 writeb(NETWAVE_CMD_SMD, ramBase + NETWAVE_EREG_CB + 0);
1067 writeb(domain & 0xff, ramBase + NETWAVE_EREG_CB + 1);
1068 writeb((domain>>8) & 0x01, ramBase + NETWAVE_EREG_CB + 2);
1069 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 3);
1070
1071 /* Set scramble key */
1072 printk(KERN_DEBUG "Setting scramble key to 0x%x\n", scramble_key);
1073 wait_WOC(iobase);
1074 writeb(NETWAVE_CMD_SSK, ramBase + NETWAVE_EREG_CB + 0);
1075 writeb(scramble_key & 0xff, ramBase + NETWAVE_EREG_CB + 1);
1076 writeb((scramble_key>>8) & 0xff, ramBase + NETWAVE_EREG_CB + 2);
1077 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 3);
1078
1079 /* Enable interrupts, bit 4 high to keep unused
1080 * source from interrupting us, bit 2 high to
1081 * set interrupt enable, 567 to enable TxDN,
1082 * RxErr and RxRdy
1083 */
1084 wait_WOC(iobase);
1085 outb(imrConfIENA+imrConfRFU1, iobase + NETWAVE_REG_IMR);
1086
1087 /* Hent 4 bytes fra 0x170. Skal vaere 0a,29,88,36
1088 * waitWOC
1089 * skriv 80 til d000:3688
1090 * sjekk om det ble 80
1091 */
1092
1093 /* Enable Receiver */
1094 wait_WOC(iobase);
1095 writeb(NETWAVE_CMD_ER, ramBase + NETWAVE_EREG_CB + 0);
1096 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 1);
1097
1098 /* Set the IENA bit in COR */
1099 wait_WOC(iobase);
1100 outb(corConfIENA + corConfLVLREQ, iobase + NETWAVE_REG_COR);
1101}
1102
1103/*
1104 * Function netwave_hw_xmit (data, len, dev)
1105 */
1106static int netwave_hw_xmit(unsigned char* data, int len,
1107 struct net_device* dev) {
1108 unsigned long flags;
1109 unsigned int TxFreeList,
1110 curBuff,
1111 MaxData,
1112 DataOffset;
1113 int tmpcount;
1114
1115 netwave_private *priv = netdev_priv(dev);
1116 u_char __iomem * ramBase = priv->ramBase;
1117 kio_addr_t iobase = dev->base_addr;
1118
1119 /* Disable interrupts & save flags */
1120 spin_lock_irqsave(&priv->spinlock, flags);
1121
1122 /* Check if there are transmit buffers available */
1123 wait_WOC(iobase);
1124 if ((inb(iobase+NETWAVE_REG_ASR) & NETWAVE_ASR_TXBA) == 0) {
1125 /* No buffers available */
1126 printk(KERN_DEBUG "netwave_hw_xmit: %s - no xmit buffers available.\n",
1127 dev->name);
1128 spin_unlock_irqrestore(&priv->spinlock, flags);
1129 return 1;
1130 }
1131
1132 priv->stats.tx_bytes += len;
1133
1134 DEBUG(3, "Transmitting with SPCQ %x SPU %x LIF %x ISPLQ %x\n",
1135 readb(ramBase + NETWAVE_EREG_SPCQ),
1136 readb(ramBase + NETWAVE_EREG_SPU),
1137 readb(ramBase + NETWAVE_EREG_LIF),
1138 readb(ramBase + NETWAVE_EREG_ISPLQ));
1139
1140 /* Now try to insert it into the adapters free memory */
1141 wait_WOC(iobase);
1142 TxFreeList = get_uint16(ramBase + NETWAVE_EREG_TDP);
1143 MaxData = get_uint16(ramBase + NETWAVE_EREG_TDP+2);
1144 DataOffset = get_uint16(ramBase + NETWAVE_EREG_TDP+4);
1145
1146 DEBUG(3, "TxFreeList %x, MaxData %x, DataOffset %x\n",
1147 TxFreeList, MaxData, DataOffset);
1148
1149 /* Copy packet to the adapter fragment buffers */
1150 curBuff = TxFreeList;
1151 tmpcount = 0;
1152 while (tmpcount < len) {
1153 int tmplen = len - tmpcount;
1154 copy_to_pc(ramBase + curBuff + DataOffset, data + tmpcount,
1155 (tmplen < MaxData) ? tmplen : MaxData);
1156 tmpcount += MaxData;
1157
1158 /* Advance to next buffer */
1159 curBuff = get_uint16(ramBase + curBuff);
1160 }
1161
1162 /* Now issue transmit list */
1163 wait_WOC(iobase);
1164 writeb(NETWAVE_CMD_TL, ramBase + NETWAVE_EREG_CB + 0);
1165 writeb(len & 0xff, ramBase + NETWAVE_EREG_CB + 1);
1166 writeb((len>>8) & 0xff, ramBase + NETWAVE_EREG_CB + 2);
1167 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 3);
1168
1169 spin_unlock_irqrestore(&priv->spinlock, flags);
1170 return 0;
1171}
1172
1173static int netwave_start_xmit(struct sk_buff *skb, struct net_device *dev) {
1174 /* This flag indicate that the hardware can't perform a transmission.
1175 * Theoritically, NET3 check it before sending a packet to the driver,
1176 * but in fact it never do that and pool continuously.
1177 * As the watchdog will abort too long transmissions, we are quite safe...
1178 */
1179
1180 netif_stop_queue(dev);
1181
1182 {
1183 short length = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
1184 unsigned char* buf = skb->data;
1185
1186 if (netwave_hw_xmit( buf, length, dev) == 1) {
1187 /* Some error, let's make them call us another time? */
1188 netif_start_queue(dev);
1189 }
1190 dev->trans_start = jiffies;
1191 }
1192 dev_kfree_skb(skb);
1193
1194 return 0;
1195} /* netwave_start_xmit */
1196
1197/*
1198 * Function netwave_interrupt (irq, dev_id, regs)
1199 *
1200 * This function is the interrupt handler for the Netwave card. This
1201 * routine will be called whenever:
1202 * 1. A packet is received.
1203 * 2. A packet has successfully been transferred and the unit is
1204 * ready to transmit another packet.
1205 * 3. A command has completed execution.
1206 */
1207static irqreturn_t netwave_interrupt(int irq, void* dev_id, struct pt_regs *regs)
1208{
1209 kio_addr_t iobase;
1210 u_char __iomem *ramBase;
1211 struct net_device *dev = (struct net_device *)dev_id;
1212 struct netwave_private *priv = netdev_priv(dev);
1213 dev_link_t *link = &priv->link;
1214 int i;
1215
1216 if (!netif_device_present(dev))
1217 return IRQ_NONE;
1218
1219 iobase = dev->base_addr;
1220 ramBase = priv->ramBase;
1221
1222 /* Now find what caused the interrupt, check while interrupts ready */
1223 for (i = 0; i < 10; i++) {
1224 u_char status;
1225
1226 wait_WOC(iobase);
1227 if (!(inb(iobase+NETWAVE_REG_CCSR) & 0x02))
1228 break; /* None of the interrupt sources asserted (normal exit) */
1229
1230 status = inb(iobase + NETWAVE_REG_ASR);
1231
1232 if (!DEV_OK(link)) {
1233 DEBUG(1, "netwave_interrupt: Interrupt with status 0x%x "
1234 "from removed or suspended card!\n", status);
1235 break;
1236 }
1237
1238 /* RxRdy */
1239 if (status & 0x80) {
1240 netwave_rx(dev);
1241 /* wait_WOC(iobase); */
1242 /* RxRdy cannot be reset directly by the host */
1243 }
1244 /* RxErr */
1245 if (status & 0x40) {
1246 u_char rser;
1247
1248 rser = readb(ramBase + NETWAVE_EREG_RSER);
1249
1250 if (rser & 0x04) {
1251 ++priv->stats.rx_dropped;
1252 ++priv->stats.rx_crc_errors;
1253 }
1254 if (rser & 0x02)
1255 ++priv->stats.rx_frame_errors;
1256
1257 /* Clear the RxErr bit in RSER. RSER+4 is the
1258 * write part. Also clear the RxCRC (0x04) and
1259 * RxBig (0x02) bits if present */
1260 wait_WOC(iobase);
1261 writeb(0x40 | (rser & 0x06), ramBase + NETWAVE_EREG_RSER + 4);
1262
1263 /* Write bit 6 high to ASCC to clear RxErr in ASR,
1264 * WOC must be set first!
1265 */
1266 wait_WOC(iobase);
1267 writeb(0x40, ramBase + NETWAVE_EREG_ASCC);
1268
1269 /* Remember to count up priv->stats on error packets */
1270 ++priv->stats.rx_errors;
1271 }
1272 /* TxDN */
1273 if (status & 0x20) {
1274 int txStatus;
1275
1276 txStatus = readb(ramBase + NETWAVE_EREG_TSER);
1277 DEBUG(3, "Transmit done. TSER = %x id %x\n",
1278 txStatus, readb(ramBase + NETWAVE_EREG_TSER + 1));
1279
1280 if (txStatus & 0x20) {
1281 /* Transmitting was okay, clear bits */
1282 wait_WOC(iobase);
1283 writeb(0x2f, ramBase + NETWAVE_EREG_TSER + 4);
1284 ++priv->stats.tx_packets;
1285 }
1286
1287 if (txStatus & 0xd0) {
1288 if (txStatus & 0x80) {
1289 ++priv->stats.collisions; /* Because of /proc/net/dev*/
1290 /* ++priv->stats.tx_aborted_errors; */
1291 /* printk("Collision. %ld\n", jiffies - dev->trans_start); */
1292 }
1293 if (txStatus & 0x40)
1294 ++priv->stats.tx_carrier_errors;
1295 /* 0x80 TxGU Transmit giveup - nine times and no luck
1296 * 0x40 TxNOAP No access point. Discarded packet.
1297 * 0x10 TxErr Transmit error. Always set when
1298 * TxGU and TxNOAP is set. (Those are the only ones
1299 * to set TxErr).
1300 */
1301 DEBUG(3, "netwave_interrupt: TxDN with error status %x\n",
1302 txStatus);
1303
1304 /* Clear out TxGU, TxNOAP, TxErr and TxTrys */
1305 wait_WOC(iobase);
1306 writeb(0xdf & txStatus, ramBase+NETWAVE_EREG_TSER+4);
1307 ++priv->stats.tx_errors;
1308 }
1309 DEBUG(3, "New status is TSER %x ASR %x\n",
1310 readb(ramBase + NETWAVE_EREG_TSER),
1311 inb(iobase + NETWAVE_REG_ASR));
1312
1313 netif_wake_queue(dev);
1314 }
1315 /* TxBA, this would trigger on all error packets received */
1316 /* if (status & 0x01) {
1317 DEBUG(4, "Transmit buffers available, %x\n", status);
1318 }
1319 */
1320 }
1321 /* Handled if we looped at least one time - Jean II */
1322 return IRQ_RETVAL(i);
1323} /* netwave_interrupt */
1324
1325/*
1326 * Function netwave_watchdog (a)
1327 *
1328 * Watchdog : when we start a transmission, we set a timer in the
1329 * kernel. If the transmission complete, this timer is disabled. If
1330 * it expire, we reset the card.
1331 *
1332 */
1333static void netwave_watchdog(struct net_device *dev) {
1334
1335 DEBUG(1, "%s: netwave_watchdog: watchdog timer expired\n", dev->name);
1336 netwave_reset(dev);
1337 dev->trans_start = jiffies;
1338 netif_wake_queue(dev);
1339} /* netwave_watchdog */
1340
1341static struct net_device_stats *netwave_get_stats(struct net_device *dev) {
1342 netwave_private *priv = netdev_priv(dev);
1343
1344 update_stats(dev);
1345
1346 DEBUG(2, "netwave: SPCQ %x SPU %x LIF %x ISPLQ %x MHS %x rxtx %x"
1347 " %x tx %x %x %x %x\n",
1348 readb(priv->ramBase + NETWAVE_EREG_SPCQ),
1349 readb(priv->ramBase + NETWAVE_EREG_SPU),
1350 readb(priv->ramBase + NETWAVE_EREG_LIF),
1351 readb(priv->ramBase + NETWAVE_EREG_ISPLQ),
1352 readb(priv->ramBase + NETWAVE_EREG_MHS),
1353 readb(priv->ramBase + NETWAVE_EREG_EC + 0xe),
1354 readb(priv->ramBase + NETWAVE_EREG_EC + 0xf),
1355 readb(priv->ramBase + NETWAVE_EREG_EC + 0x18),
1356 readb(priv->ramBase + NETWAVE_EREG_EC + 0x19),
1357 readb(priv->ramBase + NETWAVE_EREG_EC + 0x1a),
1358 readb(priv->ramBase + NETWAVE_EREG_EC + 0x1b));
1359
1360 return &priv->stats;
1361}
1362
1363static void update_stats(struct net_device *dev) {
1364 //unsigned long flags;
1365/* netwave_private *priv = netdev_priv(dev); */
1366
1367 //spin_lock_irqsave(&priv->spinlock, flags);
1368
1369/* priv->stats.rx_packets = readb(priv->ramBase + 0x18e);
1370 priv->stats.tx_packets = readb(priv->ramBase + 0x18f); */
1371
1372 //spin_unlock_irqrestore(&priv->spinlock, flags);
1373}
1374
1375static int netwave_rx(struct net_device *dev)
1376{
1377 netwave_private *priv = netdev_priv(dev);
1378 u_char __iomem *ramBase = priv->ramBase;
1379 kio_addr_t iobase = dev->base_addr;
1380 u_char rxStatus;
1381 struct sk_buff *skb = NULL;
1382 unsigned int curBuffer,
1383 rcvList;
1384 int rcvLen;
1385 int tmpcount = 0;
1386 int dataCount, dataOffset;
1387 int i;
1388 u_char *ptr;
1389
1390 DEBUG(3, "xinw_rx: Receiving ... \n");
1391
1392 /* Receive max 10 packets for now. */
1393 for (i = 0; i < 10; i++) {
1394 /* Any packets? */
1395 wait_WOC(iobase);
1396 rxStatus = readb(ramBase + NETWAVE_EREG_RSER);
1397 if ( !( rxStatus & 0x80)) /* No more packets */
1398 break;
1399
1400 /* Check if multicast/broadcast or other */
1401 /* multicast = (rxStatus & 0x20); */
1402
1403 /* The receive list pointer and length of the packet */
1404 wait_WOC(iobase);
1405 rcvLen = get_int16( ramBase + NETWAVE_EREG_RDP);
1406 rcvList = get_uint16( ramBase + NETWAVE_EREG_RDP + 2);
1407
1408 if (rcvLen < 0) {
1409 printk(KERN_DEBUG "netwave_rx: Receive packet with len %d\n",
1410 rcvLen);
1411 return 0;
1412 }
1413
1414 skb = dev_alloc_skb(rcvLen+5);
1415 if (skb == NULL) {
1416 DEBUG(1, "netwave_rx: Could not allocate an sk_buff of "
1417 "length %d\n", rcvLen);
1418 ++priv->stats.rx_dropped;
1419 /* Tell the adapter to skip the packet */
1420 wait_WOC(iobase);
1421 writeb(NETWAVE_CMD_SRP, ramBase + NETWAVE_EREG_CB + 0);
1422 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 1);
1423 return 0;
1424 }
1425
1426 skb_reserve( skb, 2); /* Align IP on 16 byte */
1427 skb_put( skb, rcvLen);
1428 skb->dev = dev;
1429
1430 /* Copy packet fragments to the skb data area */
1431 ptr = (u_char*) skb->data;
1432 curBuffer = rcvList;
1433 tmpcount = 0;
1434 while ( tmpcount < rcvLen) {
1435 /* Get length and offset of current buffer */
1436 dataCount = get_uint16( ramBase+curBuffer+2);
1437 dataOffset = get_uint16( ramBase+curBuffer+4);
1438
1439 copy_from_pc( ptr + tmpcount,
1440 ramBase+curBuffer+dataOffset, dataCount);
1441
1442 tmpcount += dataCount;
1443
1444 /* Point to next buffer */
1445 curBuffer = get_uint16(ramBase + curBuffer);
1446 }
1447
1448 skb->protocol = eth_type_trans(skb,dev);
1449 /* Queue packet for network layer */
1450 netif_rx(skb);
1451
1452 dev->last_rx = jiffies;
1453 priv->stats.rx_packets++;
1454 priv->stats.rx_bytes += rcvLen;
1455
1456 /* Got the packet, tell the adapter to skip it */
1457 wait_WOC(iobase);
1458 writeb(NETWAVE_CMD_SRP, ramBase + NETWAVE_EREG_CB + 0);
1459 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 1);
1460 DEBUG(3, "Packet reception ok\n");
1461 }
1462 return 0;
1463}
1464
1465static int netwave_open(struct net_device *dev) {
1466 netwave_private *priv = netdev_priv(dev);
1467 dev_link_t *link = &priv->link;
1468
1469 DEBUG(1, "netwave_open: starting.\n");
1470
1471 if (!DEV_OK(link))
1472 return -ENODEV;
1473
1474 link->open++;
1475
1476 netif_start_queue(dev);
1477 netwave_reset(dev);
1478
1479 return 0;
1480}
1481
1482static int netwave_close(struct net_device *dev) {
1483 netwave_private *priv = netdev_priv(dev);
1484 dev_link_t *link = &priv->link;
1485
1486 DEBUG(1, "netwave_close: finishing.\n");
1487
1488 link->open--;
1489 netif_stop_queue(dev);
1490
1491 return 0;
1492}
1493
Dominik Brodowski5d402e92005-06-27 16:28:23 -07001494static struct pcmcia_device_id netwave_ids[] = {
1495 PCMCIA_DEVICE_PROD_ID12("Xircom", "CreditCard Netwave", 0x2e3ee845, 0x54e28a28),
1496 PCMCIA_DEVICE_NULL,
1497};
1498MODULE_DEVICE_TABLE(pcmcia, netwave_ids);
1499
Linus Torvalds1da177e2005-04-16 15:20:36 -07001500static struct pcmcia_driver netwave_driver = {
1501 .owner = THIS_MODULE,
1502 .drv = {
1503 .name = "netwave_cs",
1504 },
1505 .attach = netwave_attach,
Dominik Brodowski1e212f32005-07-07 17:59:00 -07001506 .event = netwave_event,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001507 .detach = netwave_detach,
Dominik Brodowski5d402e92005-06-27 16:28:23 -07001508 .id_table = netwave_ids,
Dominik Brodowski98e4c282005-11-14 21:21:18 +01001509 .suspend = netwave_suspend,
1510 .resume = netwave_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001511};
1512
1513static int __init init_netwave_cs(void)
1514{
1515 return pcmcia_register_driver(&netwave_driver);
1516}
1517
1518static void __exit exit_netwave_cs(void)
1519{
1520 pcmcia_unregister_driver(&netwave_driver);
1521 BUG_ON(dev_list != NULL);
1522}
1523
1524module_init(init_netwave_cs);
1525module_exit(exit_netwave_cs);
1526
1527/* Set or clear the multicast filter for this adaptor.
1528 num_addrs == -1 Promiscuous mode, receive all packets
1529 num_addrs == 0 Normal mode, clear multicast list
1530 num_addrs > 0 Multicast mode, receive normal and MC packets, and do
1531 best-effort filtering.
1532 */
1533static void set_multicast_list(struct net_device *dev)
1534{
1535 kio_addr_t iobase = dev->base_addr;
1536 netwave_private *priv = netdev_priv(dev);
1537 u_char __iomem * ramBase = priv->ramBase;
1538 u_char rcvMode = 0;
1539
1540#ifdef PCMCIA_DEBUG
1541 if (pc_debug > 2) {
1542 static int old;
1543 if (old != dev->mc_count) {
1544 old = dev->mc_count;
1545 DEBUG(0, "%s: setting Rx mode to %d addresses.\n",
1546 dev->name, dev->mc_count);
1547 }
1548 }
1549#endif
1550
1551 if (dev->mc_count || (dev->flags & IFF_ALLMULTI)) {
1552 /* Multicast Mode */
1553 rcvMode = rxConfRxEna + rxConfAMP + rxConfBcast;
1554 } else if (dev->flags & IFF_PROMISC) {
1555 /* Promiscous mode */
1556 rcvMode = rxConfRxEna + rxConfPro + rxConfAMP + rxConfBcast;
1557 } else {
1558 /* Normal mode */
1559 rcvMode = rxConfRxEna + rxConfBcast;
1560 }
1561
1562 /* printk("netwave set_multicast_list: rcvMode to %x\n", rcvMode);*/
1563 /* Now set receive mode */
1564 wait_WOC(iobase);
1565 writeb(NETWAVE_CMD_SRC, ramBase + NETWAVE_EREG_CB + 0);
1566 writeb(rcvMode, ramBase + NETWAVE_EREG_CB + 1);
1567 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 2);
1568}
1569MODULE_LICENSE("GPL");