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