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