1 /*********************************************************************
3 * Filename: netwave_cs.c
5 * Description: Netwave AirSurfer Wireless LAN PC Card driver
6 * Status: Experimental.
7 * Authors: John Markus Bjørndalen <johnm@cs.uit.no>
8 * Dag Brattli <dagb@cs.uit.no>
9 * David Hinds <dahinds@users.sourceforge.net>
10 * Created at: A long time ago!
11 * Modified at: Mon Nov 10 11:54:37 1997
12 * Modified by: Dag Brattli <dagb@cs.uit.no>
14 * Copyright (c) 1997 University of Tromsø, Norway
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)
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
32 * - Started to add wireless extensions, but still needs some coding
33 * - Added watchdog for better handling of transmission timeouts
34 * (hopefully this works better)
35 ********************************************************************/
37 /* To have statistics (just packets sent) define this */
40 #include <linux/config.h>
41 #include <linux/module.h>
42 #include <linux/kernel.h>
43 #include <linux/init.h>
44 #include <linux/sched.h>
45 #include <linux/types.h>
46 #include <linux/fcntl.h>
47 #include <linux/interrupt.h>
48 #include <linux/ptrace.h>
49 #include <linux/ioport.h>
51 #include <linux/malloc.h>
52 #include <linux/string.h>
53 #include <linux/timer.h>
54 #include <asm/system.h>
55 #include <asm/bitops.h>
58 #include <linux/errno.h>
60 #include <linux/netdevice.h>
61 #include <linux/etherdevice.h>
62 #include <linux/skbuff.h>
64 #ifdef CONFIG_NET_PCMCIA_RADIO
65 #include <linux/wireless.h>
68 #include <pcmcia/version.h>
69 #include <pcmcia/cs_types.h>
70 #include <pcmcia/cs.h>
71 #include <pcmcia/cistpl.h>
72 #include <pcmcia/cisreg.h>
73 #include <pcmcia/ds.h>
74 #include <pcmcia/mem_op.h>
76 #define NETWAVE_REGOFF 0x8000
77 /* The Netwave IO registers, offsets to iobase */
78 #define NETWAVE_REG_COR 0x0
79 #define NETWAVE_REG_CCSR 0x2
80 #define NETWAVE_REG_ASR 0x4
81 #define NETWAVE_REG_IMR 0xa
82 #define NETWAVE_REG_PMR 0xc
83 #define NETWAVE_REG_IOLOW 0x6
84 #define NETWAVE_REG_IOHI 0x7
85 #define NETWAVE_REG_IOCONTROL 0x8
86 #define NETWAVE_REG_DATA 0xf
87 /* The Netwave Extended IO registers, offsets to RamBase */
88 #define NETWAVE_EREG_ASCC 0x114
89 #define NETWAVE_EREG_RSER 0x120
90 #define NETWAVE_EREG_RSERW 0x124
91 #define NETWAVE_EREG_TSER 0x130
92 #define NETWAVE_EREG_TSERW 0x134
93 #define NETWAVE_EREG_CB 0x100
94 #define NETWAVE_EREG_SPCQ 0x154
95 #define NETWAVE_EREG_SPU 0x155
96 #define NETWAVE_EREG_LIF 0x14e
97 #define NETWAVE_EREG_ISPLQ 0x156
98 #define NETWAVE_EREG_HHC 0x158
99 #define NETWAVE_EREG_NI 0x16e
100 #define NETWAVE_EREG_MHS 0x16b
101 #define NETWAVE_EREG_TDP 0x140
102 #define NETWAVE_EREG_RDP 0x150
103 #define NETWAVE_EREG_PA 0x160
104 #define NETWAVE_EREG_EC 0x180
105 #define NETWAVE_EREG_CRBP 0x17a
106 #define NETWAVE_EREG_ARW 0x166
109 * Commands used in the extended command buffer
110 * NETWAVE_EREG_CB (0x100-0x10F)
112 #define NETWAVE_CMD_NOP 0x00
113 #define NETWAVE_CMD_SRC 0x01
114 #define NETWAVE_CMD_STC 0x02
115 #define NETWAVE_CMD_AMA 0x03
116 #define NETWAVE_CMD_DMA 0x04
117 #define NETWAVE_CMD_SAMA 0x05
118 #define NETWAVE_CMD_ER 0x06
119 #define NETWAVE_CMD_DR 0x07
120 #define NETWAVE_CMD_TL 0x08
121 #define NETWAVE_CMD_SRP 0x09
122 #define NETWAVE_CMD_SSK 0x0a
123 #define NETWAVE_CMD_SMD 0x0b
124 #define NETWAVE_CMD_SAPD 0x0c
125 #define NETWAVE_CMD_SSS 0x11
126 /* End of Command marker */
127 #define NETWAVE_CMD_EOC 0x00
129 /* ASR register bits */
130 #define NETWAVE_ASR_RXRDY 0x80
131 #define NETWAVE_ASR_TXBA 0x01
133 #define TX_TIMEOUT ((32*HZ)/100)
135 static const unsigned int imrConfRFU1
= 0x10; /* RFU interrupt mask, keep high */
136 static const unsigned int imrConfIENA
= 0x02; /* Interrupt enable */
138 static const unsigned int corConfIENA
= 0x01; /* Interrupt enable */
139 static const unsigned int corConfLVLREQ
= 0x40; /* Keep high */
141 static const unsigned int rxConfRxEna
= 0x80; /* Receive Enable */
142 static const unsigned int rxConfMAC
= 0x20; /* MAC host receive mode*/
143 static const unsigned int rxConfPro
= 0x10; /* Promiscuous */
144 static const unsigned int rxConfAMP
= 0x08; /* Accept Multicast Packets */
145 static const unsigned int rxConfBcast
= 0x04; /* Accept Broadcast Packets */
147 static const unsigned int txConfTxEna
= 0x80; /* Transmit Enable */
148 static const unsigned int txConfMAC
= 0x20; /* Host sends MAC mode */
149 static const unsigned int txConfEUD
= 0x10; /* Enable Uni-Data packets */
150 static const unsigned int txConfKey
= 0x02; /* Scramble data packets */
151 static const unsigned int txConfLoop
= 0x01; /* Loopback mode */
154 All the PCMCIA modules use PCMCIA_DEBUG to control debugging. If
155 you do not define PCMCIA_DEBUG at all, all the debug code will be
156 left out. If you compile with PCMCIA_DEBUG=0, the debug code will
157 be present but disabled -- but it can then be enabled for specific
158 modules at load time with a 'pc_debug=#' option to insmod.
162 static int pc_debug
= PCMCIA_DEBUG
;
163 MODULE_PARM(pc_debug
, "i");
164 #define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args)
165 static char *version
=
166 "netwave_cs.c 0.3.0 Thu Jul 17 14:36:02 1997 (John Markus Bjørndalen)\n";
168 #define DEBUG(n, args...)
171 static dev_info_t dev_info
= "netwave_cs";
173 /*====================================================================*/
175 /* Parameters that can be set with 'insmod' */
177 /* Choose the domain, default is 0x100 */
178 static u_int domain
= 0x100;
180 /* Scramble key, range from 0x0 to 0xffff.
181 * 0x0 is no scrambling.
183 static u_int scramble_key
= 0x0;
185 /* Shared memory speed, in ns. The documentation states that
186 * the card should not be read faster than every 400ns.
187 * This timing should be provided by the HBA. If it becomes a
188 * problem, try setting mem_speed to 400.
190 static int mem_speed
= 0;
192 /* Bit map of interrupts to choose from */
193 /* This means pick from 15, 14, 12, 11, 10, 9, 7, 5, 4, and 3 */
194 static u_int irq_mask
= 0xdeb8;
195 static int irq_list
[4] = { -1 };
197 MODULE_PARM(domain
, "i");
198 MODULE_PARM(scramble_key
, "i");
199 MODULE_PARM(mem_speed
, "i");
200 MODULE_PARM(irq_mask
, "i");
201 MODULE_PARM(irq_list
, "1-4i");
203 /*====================================================================*/
205 /* PCMCIA (Card Services) related functions */
206 static void netwave_release(u_long arg
); /* Card removal */
207 static int netwave_event(event_t event
, int priority
,
208 event_callback_args_t
*args
);
209 static void netwave_pcmcia_config(dev_link_t
*arg
); /* Runs after card
211 static dev_link_t
*netwave_attach(void); /* Create instance */
212 static void netwave_detach(dev_link_t
*); /* Destroy instance */
213 static void netwave_flush_stale_links(void); /* Destroy all staled instances */
215 /* Hardware configuration */
216 static void netwave_doreset(ioaddr_t iobase
, u_char
* ramBase
);
217 static void netwave_reset(struct net_device
*dev
);
219 /* Misc device stuff */
220 static int netwave_open(struct net_device
*dev
); /* Open the device */
221 static int netwave_close(struct net_device
*dev
); /* Close the device */
222 static int netwave_config(struct net_device
*dev
, struct ifmap
*map
);
224 /* Packet transmission and Packet reception */
225 static int netwave_start_xmit( struct sk_buff
*skb
, struct net_device
*dev
);
226 static int netwave_rx( struct net_device
*dev
);
228 /* Interrupt routines */
229 static void netwave_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
);
230 static void netwave_watchdog(struct net_device
*);
233 static void update_stats(struct net_device
*dev
);
234 static struct net_device_stats
*netwave_get_stats(struct net_device
*dev
);
236 /* Wireless extensions */
238 static struct iw_statistics
* netwave_get_wireless_stats(struct net_device
*dev
);
240 static int netwave_ioctl(struct net_device
*, struct ifreq
*, int);
242 static void set_multicast_list(struct net_device
*dev
);
245 A linked list of "instances" of the skeleton device. Each actual
246 PCMCIA card corresponds to one device instance, and is described
247 by one dev_link_t structure (defined in ds.h).
249 You may not want to use a linked list for this -- for example, the
250 memory card driver uses an array of dev_link_t pointers, where minor
251 device numbers are used to derive the corresponding array index.
253 static dev_link_t
*dev_list
= NULL
;
256 A dev_link_t structure has fields for most things that are needed
257 to keep track of a socket, but there will usually be some device
258 specific information that also needs to be kept track of. The
259 'priv' pointer in a dev_link_t structure can be used to point to
260 a device-specific private data structure, like this.
262 A driver needs to provide a dev_node_t structure for each device
263 on a card. In some cases, there is only one device per card (for
264 example, ethernet cards, modems). In other cases, there may be
265 many actual or logical devices (SCSI adapters, memory cards with
266 multiple partitions). The dev_node_t structures need to be kept
267 in a linked list starting at the 'dev' field of a dev_link_t
268 structure. We allocate them in the card's private data structure,
269 because they generally can't be allocated dynamically.
272 #define SIOCGIPSNAP SIOCDEVPRIVATE /* Site Survey Snapshot */
273 /*#define SIOCGIPQTHR SIOCDEVPRIVATE + 1*/
277 typedef struct net_addr
{
283 u_char struct_revision
;
284 u_char roaming_state
;
286 u_char sp_existsFlag
;
287 u_char sp_link_quality
;
288 u_char sp_max_link_quality
;
289 u_char linkQualityGoodFairBoundary
;
290 u_char linkQualityFairPoorBoundary
;
291 u_char sp_utilization
;
293 u_char sp_hotheadcount
;
294 u_char roaming_condition
;
298 net_addr nearByAccessPoints
[MAX_ESA
];
301 typedef struct netwave_private
{
303 struct net_device dev
;
308 struct timer_list watchdog
; /* To avoid blocking state */
309 struct site_survey nss
;
310 struct net_device_stats stats
;
312 struct iw_statistics iw_stats
; /* Wireless stats */
317 static struct net_device_stats
*netwave_get_stats(struct net_device
*dev
);
321 * The Netwave card is little-endian, so won't work for big endian
324 static inline unsigned short get_uint16(u_char
* staddr
)
326 return readw(staddr
); /* Return only 16 bits */
329 static inline short get_int16(u_char
* staddr
)
331 return readw(staddr
);
334 /**************************************************************************/
336 static void cs_error(client_handle_t handle
, int func
, int ret
)
338 error_info_t err
= { func
, ret
};
339 CardServices(ReportError
, handle
, &err
);
343 * Wait until the WOC (Write Operation Complete) bit in the
344 * ASR (Adapter Status Register) is asserted.
345 * This should have aborted if it takes too long time.
347 static inline void wait_WOC(unsigned int iobase
)
350 while ((inb(iobase
+ NETWAVE_REG_ASR
) & 0x8) != 0x8) ;
354 static void netwave_snapshot(netwave_private
*priv
, u_char
*ramBase
,
356 u_short resultBuffer
;
358 /* if time since last snapshot is > 1 sec. (100 jiffies?) then take
359 * new snapshot, else return cached data. This is the recommended rate.
361 if ( jiffies
- priv
->lastExec
> 100) {
362 /* Take site survey snapshot */
363 /*printk( KERN_DEBUG "Taking new snapshot. %ld\n", jiffies -
366 writeb(NETWAVE_CMD_SSS
, ramBase
+ NETWAVE_EREG_CB
+ 0);
367 writeb(NETWAVE_CMD_EOC
, ramBase
+ NETWAVE_EREG_CB
+ 1);
370 /* Get result and copy to cach */
371 resultBuffer
= readw(ramBase
+ NETWAVE_EREG_CRBP
);
372 copy_from_pc( &priv
->nss
, ramBase
+resultBuffer
,
373 sizeof(struct site_survey
));
380 * Function netwave_get_wireless_stats (dev)
382 * Wireless extensions statistics
385 static struct iw_statistics
*netwave_get_wireless_stats(struct net_device
*dev
)
388 ioaddr_t iobase
= dev
->base_addr
;
389 netwave_private
*priv
= (netwave_private
*) dev
->priv
;
390 u_char
*ramBase
= priv
->ramBase
;
391 struct iw_statistics
* wstats
;
393 wstats
= &priv
->iw_stats
;
398 netwave_snapshot( priv
, ramBase
, iobase
);
400 wstats
->status
= priv
->nss
.roaming_state
;
401 wstats
->qual
.qual
= readb( ramBase
+ NETWAVE_EREG_SPCQ
);
402 wstats
->qual
.level
= readb( ramBase
+ NETWAVE_EREG_ISPLQ
);
403 wstats
->qual
.noise
= readb( ramBase
+ NETWAVE_EREG_SPU
) & 0x3f;
404 wstats
->discard
.nwid
= 0L;
405 wstats
->discard
.code
= 0L;
406 wstats
->discard
.misc
= 0L;
408 restore_flags(flags
);
410 return &priv
->iw_stats
;
415 * Function netwave_attach (void)
417 * Creates an "instance" of the driver, allocating local data
418 * structures for one device. The device is registered with Card
421 * The dev_link structure is initialized, but we don't actually
422 * configure the card at this point -- we wait until we receive a
423 * card insertion event.
425 static dev_link_t
*netwave_attach(void)
427 client_reg_t client_reg
;
429 struct net_device
*dev
;
430 netwave_private
*priv
;
433 DEBUG(0, "netwave_attach()\n");
435 /* Perform some cleanup */
436 netwave_flush_stale_links();
438 /* Initialize the dev_link_t structure */
439 priv
= kmalloc(sizeof(*priv
), GFP_KERNEL
);
440 if (!priv
) return NULL
;
441 memset(priv
, 0, sizeof(*priv
));
442 link
= &priv
->link
; dev
= &priv
->dev
;
443 link
->priv
= dev
->priv
= priv
;
444 link
->release
.function
= &netwave_release
;
445 link
->release
.data
= (u_long
)link
;
447 /* The io structure describes IO port mapping */
448 link
->io
.NumPorts1
= 16;
449 link
->io
.Attributes1
= IO_DATA_PATH_WIDTH_16
;
450 /* link->io.NumPorts2 = 16;
451 link->io.Attributes2 = IO_DATA_PATH_WIDTH_16; */
452 link
->io
.IOAddrLines
= 5;
454 /* Interrupt setup */
455 link
->irq
.Attributes
= IRQ_TYPE_EXCLUSIVE
| IRQ_HANDLE_PRESENT
;
456 link
->irq
.IRQInfo1
= IRQ_INFO2_VALID
|IRQ_LEVEL_ID
;
457 if (irq_list
[0] == -1)
458 link
->irq
.IRQInfo2
= irq_mask
;
460 for (i
= 0; i
< 4; i
++)
461 link
->irq
.IRQInfo2
|= 1 << irq_list
[i
];
462 link
->irq
.Handler
= &netwave_interrupt
;
464 /* General socket configuration */
465 link
->conf
.Attributes
= CONF_ENABLE_IRQ
;
467 link
->conf
.IntType
= INT_MEMORY_AND_IO
;
468 link
->conf
.ConfigIndex
= 1;
469 link
->conf
.Present
= PRESENT_OPTION
;
471 /* Netwave specific entries in the device structure */
472 dev
->hard_start_xmit
= &netwave_start_xmit
;
473 dev
->set_config
= &netwave_config
;
474 dev
->get_stats
= &netwave_get_stats
;
475 dev
->set_multicast_list
= &set_multicast_list
;
476 /* wireless extensions */
478 dev
->get_wireless_stats
= &netwave_get_wireless_stats
;
480 dev
->do_ioctl
= &netwave_ioctl
;
482 dev
->tx_timeout
= &netwave_watchdog
;
483 dev
->watchdog_timeo
= TX_TIMEOUT
;
486 dev
->open
= &netwave_open
;
487 dev
->stop
= &netwave_close
;
488 link
->irq
.Instance
= dev
;
490 /* Register with Card Services */
491 link
->next
= dev_list
;
493 client_reg
.dev_info
= &dev_info
;
494 client_reg
.Attributes
= INFO_IO_CLIENT
| INFO_CARD_SHARE
;
495 client_reg
.EventMask
=
496 CS_EVENT_CARD_INSERTION
| CS_EVENT_CARD_REMOVAL
|
497 CS_EVENT_RESET_PHYSICAL
| CS_EVENT_CARD_RESET
|
498 CS_EVENT_PM_SUSPEND
| CS_EVENT_PM_RESUME
;
499 client_reg
.event_handler
= &netwave_event
;
500 client_reg
.Version
= 0x0210;
501 client_reg
.event_callback_args
.client_data
= link
;
502 ret
= CardServices(RegisterClient
, &link
->handle
, &client_reg
);
504 cs_error(link
->handle
, RegisterClient
, ret
);
505 netwave_detach(link
);
510 } /* netwave_attach */
513 * Function netwave_detach (link)
515 * This deletes a driver "instance". The device is de-registered
516 * with Card Services. If it has been released, all local data
517 * structures are freed. Otherwise, the structures will be freed
518 * when the device is released.
520 static void netwave_detach(dev_link_t
*link
)
522 netwave_private
*priv
= link
->priv
;
525 DEBUG(0, "netwave_detach(0x%p)\n", link
);
528 If the device is currently configured and active, we won't
529 actually delete it yet. Instead, it is marked so that when
530 the release() function is called, that will trigger a proper
533 del_timer(&link
->release
);
534 if (link
->state
& DEV_CONFIG
) {
535 netwave_release((u_long
) link
);
536 if (link
->state
& DEV_STALE_CONFIG
) {
537 DEBUG(1, "netwave_cs: detach postponed, '%s' still "
538 "locked\n", link
->dev
->dev_name
);
539 link
->state
|= DEV_STALE_LINK
;
544 /* Break the link with Card Services */
546 CardServices(DeregisterClient
, link
->handle
);
548 /* Locate device structure */
549 for (linkp
= &dev_list
; *linkp
; linkp
= &(*linkp
)->next
)
550 if (*linkp
== link
) break;
553 DEBUG(1, "netwave_cs: detach fail, '%s' not in list\n",
554 link
->dev
->dev_name
);
558 /* Unlink device structure, free pieces */
561 unregister_netdev(&priv
->dev
);
564 } /* netwave_detach */
567 * Function netwave_flush_stale_links (void)
569 * This deletes all driver "instances" that need to be deleted.
570 * Sometimes, netwave_detach can't be performed following a call from
571 * cardmgr (device still open) and the device is put in a STALE_LINK
573 * This function is in charge of making the cleanup...
575 static void netwave_flush_stale_links(void)
577 dev_link_t
* link
; /* Current node in linked list */
578 dev_link_t
* next
; /* Next node in linked list */
580 DEBUG(1, "netwave_flush_stale_links(0x%p)\n", dev_list
);
582 /* Go through the list */
583 for (link
= dev_list
; link
; link
= next
) {
585 /* Check if in need of being removed */
586 if(link
->state
& DEV_STALE_LINK
)
587 netwave_detach(link
);
589 } /* netwave_flush_stale_links */
592 * Function netwave_ioctl (dev, rq, cmd)
594 * Perform ioctl : config & info stuff
595 * This is the stuff that are treated the wireless extensions (iwconfig)
598 static int netwave_ioctl(struct net_device
*dev
, /* ioctl device */
599 struct ifreq
*rq
, /* Data passed */
600 int cmd
) /* Ioctl number */
605 ioaddr_t iobase
= dev
->base_addr
;
606 netwave_private
*priv
= (netwave_private
*) dev
->priv
;
607 u_char
*ramBase
= priv
->ramBase
;
608 struct iwreq
*wrq
= (struct iwreq
*) rq
;
611 DEBUG(0, "%s: ->netwave_ioctl(cmd=0x%X)\n", dev
->name
, cmd
);
613 /* Disable interrupts & save flags */
617 /* Look what is the request */
619 /* --------------- WIRELESS EXTENSIONS --------------- */
623 strcpy(wrq
->u
.name
, "Netwave");
628 if(!wrq
->u
.nwid
.disabled
) {
629 domain
= wrq
->u
.nwid
.value
;
630 #else /* WIRELESS_EXT > 8 */
632 domain
= wrq
->u
.nwid
.nwid
;
633 #endif /* WIRELESS_EXT > 8 */
634 printk( KERN_DEBUG
"Setting domain to 0x%x%02x\n",
635 (domain
>> 8) & 0x01, domain
& 0xff);
637 writeb(NETWAVE_CMD_SMD
, ramBase
+ NETWAVE_EREG_CB
+ 0);
638 writeb( domain
& 0xff, ramBase
+ NETWAVE_EREG_CB
+ 1);
639 writeb((domain
>>8 ) & 0x01,ramBase
+ NETWAVE_EREG_CB
+2);
640 writeb(NETWAVE_CMD_EOC
, ramBase
+ NETWAVE_EREG_CB
+ 3);
645 wrq
->u
.nwid
.value
= domain
;
646 wrq
->u
.nwid
.disabled
= 0;
647 wrq
->u
.nwid
.fixed
= 1;
648 #else /* WIRELESS_EXT > 8 */
649 wrq
->u
.nwid
.nwid
= domain
;
651 #endif /* WIRELESS_EXT > 8 */
653 #if WIRELESS_EXT > 8 /* Note : The API did change... */
655 /* Get scramble key */
656 if(wrq
->u
.encoding
.pointer
!= (caddr_t
) 0)
659 key
[1] = scramble_key
& 0xff;
660 key
[0] = (scramble_key
>>8) & 0xff;
661 wrq
->u
.encoding
.flags
= IW_ENCODE_ENABLED
;
662 wrq
->u
.encoding
.length
= 2;
663 if(copy_to_user(wrq
->u
.encoding
.pointer
, key
, 2))
668 /* Set scramble key */
669 if(wrq
->u
.encoding
.pointer
!= (caddr_t
) 0)
672 if(copy_from_user(key
, wrq
->u
.encoding
.pointer
, 2))
677 scramble_key
= (key
[0] << 8) | key
[1];
679 writeb(NETWAVE_CMD_SSK
, ramBase
+ NETWAVE_EREG_CB
+ 0);
680 writeb(scramble_key
& 0xff, ramBase
+ NETWAVE_EREG_CB
+ 1);
681 writeb((scramble_key
>>8) & 0xff, ramBase
+ NETWAVE_EREG_CB
+ 2);
682 writeb(NETWAVE_CMD_EOC
, ramBase
+ NETWAVE_EREG_CB
+ 3);
686 /* Mode of operation */
688 wrq
->u
.mode
= IW_MODE_INFRA
;
690 wrq
->u
.mode
= IW_MODE_ADHOC
;
692 #else /* WIRELESS_EXT > 8 */
694 /* Get scramble key */
695 wrq
->u
.encoding
.code
= scramble_key
;
696 wrq
->u
.encoding
.method
= 1;
699 /* Set scramble key */
700 scramble_key
= wrq
->u
.encoding
.code
;
702 writeb(NETWAVE_CMD_SSK
, ramBase
+ NETWAVE_EREG_CB
+ 0);
703 writeb(scramble_key
& 0xff, ramBase
+ NETWAVE_EREG_CB
+ 1);
704 writeb((scramble_key
>>8) & 0xff, ramBase
+ NETWAVE_EREG_CB
+ 2);
705 writeb(NETWAVE_CMD_EOC
, ramBase
+ NETWAVE_EREG_CB
+ 3);
707 #endif /* WIRELESS_EXT > 8 */
709 /* Basic checking... */
710 if(wrq
->u
.data
.pointer
!= (caddr_t
) 0) {
711 struct iw_range range
;
713 /* Set the length (useless : its constant...) */
714 wrq
->u
.data
.length
= sizeof(struct iw_range
);
716 /* Set information in the range struct */
717 range
.throughput
= 450 * 1000; /* don't argue on this ! */
718 range
.min_nwid
= 0x0000;
719 range
.max_nwid
= 0x01FF;
721 range
.num_channels
= range
.num_frequency
= 0;
723 range
.sensitivity
= 0x3F;
724 range
.max_qual
.qual
= 255;
725 range
.max_qual
.level
= 255;
726 range
.max_qual
.noise
= 0;
729 range
.num_bitrates
= 1;
730 range
.bitrate
[0] = 1000000; /* 1 Mb/s */
731 #endif /* WIRELESS_EXT > 7 */
734 range
.encoding_size
[0] = 2; /* 16 bits scrambling */
735 range
.num_encoding_sizes
= 1;
736 range
.max_encoding_tokens
= 1; /* Only one key possible */
737 #endif /* WIRELESS_EXT > 8 */
739 /* Copy structure to the user buffer */
740 if(copy_to_user(wrq
->u
.data
.pointer
, &range
,
741 sizeof(struct iw_range
)))
746 /* Basic checking... */
747 if(wrq
->u
.data
.pointer
!= (caddr_t
) 0) {
748 struct iw_priv_args priv
[] =
749 { /* cmd, set_args, get_args, name */
750 { SIOCGIPSNAP
, IW_PRIV_TYPE_BYTE
| IW_PRIV_SIZE_FIXED
| 0,
751 sizeof(struct site_survey
),
755 /* Set the number of ioctl available */
756 wrq
->u
.data
.length
= 1;
758 /* Copy structure to the user buffer */
759 if(copy_to_user(wrq
->u
.data
.pointer
, (u_char
*) priv
,
765 if(wrq
->u
.data
.pointer
!= (caddr_t
) 0) {
766 /* Take snapshot of environment */
767 netwave_snapshot( priv
, ramBase
, iobase
);
768 wrq
->u
.data
.length
= priv
->nss
.length
;
769 /* Copy structure to the user buffer */
770 if(copy_to_user(wrq
->u
.data
.pointer
,
771 (u_char
*) &priv
->nss
,
772 sizeof( struct site_survey
)))
774 printk(KERN_DEBUG
"Bad buffer!\n");
778 priv
->lastExec
= jiffies
;
786 /* ReEnable interrupts & restore flags */
787 restore_flags(flags
);
793 * Function netwave_pcmcia_config (link)
795 * netwave_pcmcia_config() is scheduled to run after a CARD_INSERTION
796 * event is received, to configure the PCMCIA socket, and to make the
797 * device available to the system.
801 #define CS_CHECK(fn, args...) \
802 while ((last_ret=CardServices(last_fn=(fn), args))!=0) goto cs_failed
804 static void netwave_pcmcia_config(dev_link_t
*link
) {
805 client_handle_t handle
= link
->handle
;
806 netwave_private
*priv
= link
->priv
;
807 struct net_device
*dev
= &priv
->dev
;
810 int i
, j
, last_ret
, last_fn
;
814 u_char
*ramBase
= NULL
;
816 DEBUG(0, "netwave_pcmcia_config(0x%p)\n", link
);
819 This reads the card's CONFIG tuple to find its configuration
822 tuple
.Attributes
= 0;
823 tuple
.TupleData
= (cisdata_t
*) buf
;
824 tuple
.TupleDataMax
= 64;
825 tuple
.TupleOffset
= 0;
826 tuple
.DesiredTuple
= CISTPL_CONFIG
;
827 CS_CHECK(GetFirstTuple
, handle
, &tuple
);
828 CS_CHECK(GetTupleData
, handle
, &tuple
);
829 CS_CHECK(ParseTuple
, handle
, &tuple
, &parse
);
830 link
->conf
.ConfigBase
= parse
.config
.base
;
831 link
->conf
.Present
= parse
.config
.rmask
[0];
834 link
->state
|= DEV_CONFIG
;
837 * Try allocating IO ports. This tries a few fixed addresses.
838 * If you want, you can also read the card's config table to
839 * pick addresses -- see the serial driver for an example.
841 for (i
= j
= 0x0; j
< 0x400; j
+= 0x20) {
842 link
->io
.BasePort1
= j
^ 0x300;
843 i
= CardServices(RequestIO
, link
->handle
, &link
->io
);
844 if (i
== CS_SUCCESS
) break;
846 if (i
!= CS_SUCCESS
) {
847 cs_error(link
->handle
, RequestIO
, i
);
852 * Now allocate an interrupt line. Note that this does not
853 * actually assign a handler to the interrupt.
855 CS_CHECK(RequestIRQ
, handle
, &link
->irq
);
858 * This actually configures the PCMCIA socket -- setting up
859 * the I/O windows and the interrupt mapping.
861 CS_CHECK(RequestConfiguration
, handle
, &link
->conf
);
864 * Allocate a 32K memory window. Note that the dev_link_t
865 * structure provides space for one window handle -- if your
866 * device needs several windows, you'll need to keep track of
867 * the handles in your private data structure, link->priv.
869 DEBUG(1, "Setting mem speed of %d\n", mem_speed
);
871 req
.Attributes
= WIN_DATA_WIDTH_8
|WIN_MEMORY_TYPE_CM
|WIN_ENABLE
;
872 req
.Base
= 0; req
.Size
= 0x8000;
873 req
.AccessSpeed
= mem_speed
;
874 link
->win
= (window_handle_t
)link
->handle
;
875 CS_CHECK(RequestWindow
, &link
->win
, &req
);
876 mem
.CardOffset
= 0x20000; mem
.Page
= 0;
877 CS_CHECK(MapMemPage
, link
->win
, &mem
);
879 /* Store base address of the common window frame */
880 ramBase
= ioremap(req
.Base
, 0x8000);
881 ((netwave_private
*)dev
->priv
)->ramBase
= ramBase
;
883 dev
->irq
= link
->irq
.AssignedIRQ
;
884 dev
->base_addr
= link
->io
.BasePort1
;
885 if (register_netdev(dev
) != 0) {
886 printk(KERN_DEBUG
"netwave_cs: register_netdev() failed\n");
890 strcpy(priv
->node
.dev_name
, dev
->name
);
891 link
->dev
= &priv
->node
;
892 link
->state
&= ~DEV_CONFIG_PENDING
;
894 /* Reset card before reading physical address */
895 netwave_doreset(dev
->base_addr
, ramBase
);
897 /* Read the ethernet address and fill in the Netwave registers. */
898 for (i
= 0; i
< 6; i
++)
899 dev
->dev_addr
[i
] = readb(ramBase
+ NETWAVE_EREG_PA
+ i
);
901 printk(KERN_INFO
"%s: Netwave: port %#3lx, irq %d, mem %lx id "
902 "%c%c, hw_addr ", dev
->name
, dev
->base_addr
, dev
->irq
,
903 (u_long
) ramBase
, (int) readb(ramBase
+NETWAVE_EREG_NI
),
904 (int) readb(ramBase
+NETWAVE_EREG_NI
+1));
905 for (i
= 0; i
< 6; i
++)
906 printk("%02X%s", dev
->dev_addr
[i
], ((i
<5) ? ":" : "\n"));
908 /* get revision words */
909 printk(KERN_DEBUG
"Netwave_reset: revision %04x %04x\n",
910 get_uint16(ramBase
+ NETWAVE_EREG_ARW
),
911 get_uint16(ramBase
+ NETWAVE_EREG_ARW
+2));
915 cs_error(link
->handle
, last_fn
, last_ret
);
917 netwave_release((u_long
)link
);
918 } /* netwave_pcmcia_config */
921 * Function netwave_release (arg)
923 * After a card is removed, netwave_release() will unregister the net
924 * device, and release the PCMCIA configuration. If the device is
925 * still open, this will be postponed until it is closed.
927 static void netwave_release(u_long arg
) {
928 dev_link_t
*link
= (dev_link_t
*)arg
;
929 netwave_private
*priv
= link
->priv
;
931 DEBUG(0, "netwave_release(0x%p)\n", link
);
934 If the device is currently in use, we won't release until it
938 printk(KERN_DEBUG
"netwave_cs: release postponed, '%s' still open\n",
939 link
->dev
->dev_name
);
940 link
->state
|= DEV_STALE_CONFIG
;
944 /* Don't bother checking to see if these succeed or not */
946 iounmap(priv
->ramBase
);
947 CardServices(ReleaseWindow
, link
->win
);
949 CardServices(ReleaseConfiguration
, link
->handle
);
950 CardServices(ReleaseIO
, link
->handle
, &link
->io
);
951 CardServices(ReleaseIRQ
, link
->handle
, &link
->irq
);
953 link
->state
&= ~(DEV_CONFIG
| DEV_STALE_CONFIG
);
955 } /* netwave_release */
958 * Function netwave_event (event, priority, args)
960 * The card status event handler. Mostly, this schedules other
961 * stuff to run after an event is received. A CARD_REMOVAL event
962 * also sets some flags to discourage the net drivers from trying
963 * to talk to the card any more.
965 * When a CARD_REMOVAL event is received, we immediately set a flag
966 * to block future accesses to this device. All the functions that
967 * actually access the device should check this flag to make sure
968 * the card is still present.
971 static int netwave_event(event_t event
, int priority
,
972 event_callback_args_t
*args
) {
973 dev_link_t
*link
= args
->client_data
;
974 netwave_private
*priv
= link
->priv
;
975 struct net_device
*dev
= &priv
->dev
;
977 DEBUG(1, "netwave_event(0x%06x)\n", event
);
980 case CS_EVENT_REGISTRATION_COMPLETE
:
981 DEBUG(0, "netwave_cs: registration complete\n");
984 case CS_EVENT_CARD_REMOVAL
:
985 link
->state
&= ~DEV_PRESENT
;
986 if (link
->state
& DEV_CONFIG
) {
987 netif_device_detach(dev
);
988 mod_timer(&link
->release
, jiffies
+ HZ
/20);
991 case CS_EVENT_CARD_INSERTION
:
992 link
->state
|= DEV_PRESENT
| DEV_CONFIG_PENDING
;
993 netwave_pcmcia_config( link
);
995 case CS_EVENT_PM_SUSPEND
:
996 link
->state
|= DEV_SUSPEND
;
997 /* Fall through... */
998 case CS_EVENT_RESET_PHYSICAL
:
999 if (link
->state
& DEV_CONFIG
) {
1001 netif_device_detach(dev
);
1002 CardServices(ReleaseConfiguration
, link
->handle
);
1005 case CS_EVENT_PM_RESUME
:
1006 link
->state
&= ~DEV_SUSPEND
;
1007 /* Fall through... */
1008 case CS_EVENT_CARD_RESET
:
1009 if (link
->state
& DEV_CONFIG
) {
1010 CardServices(RequestConfiguration
, link
->handle
, &link
->conf
);
1013 netif_device_attach(dev
);
1019 } /* netwave_event */
1022 * Function netwave_doreset (ioBase, ramBase)
1024 * Proper hardware reset of the card.
1026 static void netwave_doreset(ioaddr_t ioBase
, u_char
* ramBase
) {
1029 outb(0x80, ioBase
+ NETWAVE_REG_PMR
);
1030 writeb(0x08, ramBase
+ NETWAVE_EREG_ASCC
); /* Bit 3 is WOC */
1031 outb(0x0, ioBase
+ NETWAVE_REG_PMR
); /* release reset */
1035 * Function netwave_reset (dev)
1037 * Reset and restore all of the netwave registers
1039 static void netwave_reset(struct net_device
*dev
) {
1041 netwave_private
*priv
= (netwave_private
*) dev
->priv
;
1042 u_char
*ramBase
= priv
->ramBase
;
1043 ioaddr_t iobase
= dev
->base_addr
;
1045 DEBUG(0, "netwave_reset: Done with hardware reset\n");
1047 priv
->timeoutCounter
= 0;
1050 netwave_doreset(iobase
, ramBase
);
1051 printk(KERN_DEBUG
"netwave_reset: Done with hardware reset\n");
1053 /* Write a NOP to check the card */
1055 writeb(NETWAVE_CMD_NOP
, ramBase
+ NETWAVE_EREG_CB
+ 0);
1056 writeb(NETWAVE_CMD_EOC
, ramBase
+ NETWAVE_EREG_CB
+ 1);
1058 /* Set receive conf */
1060 writeb(NETWAVE_CMD_SRC
, ramBase
+ NETWAVE_EREG_CB
+ 0);
1061 writeb(rxConfRxEna
+ rxConfBcast
, ramBase
+ NETWAVE_EREG_CB
+ 1);
1062 writeb(NETWAVE_CMD_EOC
, ramBase
+ NETWAVE_EREG_CB
+ 2);
1064 /* Set transmit conf */
1066 writeb(NETWAVE_CMD_STC
, ramBase
+ NETWAVE_EREG_CB
+ 0);
1067 writeb(txConfTxEna
, ramBase
+ NETWAVE_EREG_CB
+ 1);
1068 writeb(NETWAVE_CMD_EOC
, ramBase
+ NETWAVE_EREG_CB
+ 2);
1070 /* Now set the MU Domain */
1071 printk(KERN_DEBUG
"Setting domain to 0x%x%02x\n", (domain
>> 8) & 0x01, domain
& 0xff);
1073 writeb(NETWAVE_CMD_SMD
, ramBase
+ NETWAVE_EREG_CB
+ 0);
1074 writeb(domain
& 0xff, ramBase
+ NETWAVE_EREG_CB
+ 1);
1075 writeb((domain
>>8) & 0x01, ramBase
+ NETWAVE_EREG_CB
+ 2);
1076 writeb(NETWAVE_CMD_EOC
, ramBase
+ NETWAVE_EREG_CB
+ 3);
1078 /* Set scramble key */
1079 printk(KERN_DEBUG
"Setting scramble key to 0x%x\n", scramble_key
);
1081 writeb(NETWAVE_CMD_SSK
, ramBase
+ NETWAVE_EREG_CB
+ 0);
1082 writeb(scramble_key
& 0xff, ramBase
+ NETWAVE_EREG_CB
+ 1);
1083 writeb((scramble_key
>>8) & 0xff, ramBase
+ NETWAVE_EREG_CB
+ 2);
1084 writeb(NETWAVE_CMD_EOC
, ramBase
+ NETWAVE_EREG_CB
+ 3);
1086 /* Enable interrupts, bit 4 high to keep unused
1087 * source from interrupting us, bit 2 high to
1088 * set interrupt enable, 567 to enable TxDN,
1092 outb(imrConfIENA
+imrConfRFU1
, iobase
+ NETWAVE_REG_IMR
);
1094 /* Hent 4 bytes fra 0x170. Skal vaere 0a,29,88,36
1096 * skriv 80 til d000:3688
1097 * sjekk om det ble 80
1100 /* Enable Receiver */
1102 writeb(NETWAVE_CMD_ER
, ramBase
+ NETWAVE_EREG_CB
+ 0);
1103 writeb(NETWAVE_CMD_EOC
, ramBase
+ NETWAVE_EREG_CB
+ 1);
1105 /* Set the IENA bit in COR */
1107 outb(corConfIENA
+ corConfLVLREQ
, iobase
+ NETWAVE_REG_COR
);
1111 * Function netwave_config (dev, map)
1113 * Configure device, this work is done by netwave_pcmcia_config when a
1116 static int netwave_config(struct net_device
*dev
, struct ifmap
*map
) {
1121 * Function netwave_hw_xmit (data, len, dev)
1123 static int netwave_hw_xmit(unsigned char* data
, int len
,
1124 struct net_device
* dev
) {
1125 unsigned long flags
;
1126 unsigned int TxFreeList
,
1132 netwave_private
*priv
= (netwave_private
*) dev
->priv
;
1133 u_char
* ramBase
= priv
->ramBase
;
1134 ioaddr_t iobase
= dev
->base_addr
;
1136 /* Disable interrupts & save flags */
1140 /* Check if there are transmit buffers available */
1142 if ((inb(iobase
+NETWAVE_REG_ASR
) & NETWAVE_ASR_TXBA
) == 0) {
1143 /* No buffers available */
1144 printk(KERN_DEBUG
"netwave_hw_xmit: %s - no xmit buffers available.\n",
1146 restore_flags(flags
);
1150 priv
->stats
.tx_bytes
+= len
;
1152 DEBUG(3, "Transmitting with SPCQ %x SPU %x LIF %x ISPLQ %x\n",
1153 readb(ramBase
+ NETWAVE_EREG_SPCQ
),
1154 readb(ramBase
+ NETWAVE_EREG_SPU
),
1155 readb(ramBase
+ NETWAVE_EREG_LIF
),
1156 readb(ramBase
+ NETWAVE_EREG_ISPLQ
));
1158 /* Now try to insert it into the adapters free memory */
1160 TxFreeList
= get_uint16(ramBase
+ NETWAVE_EREG_TDP
);
1161 MaxData
= get_uint16(ramBase
+ NETWAVE_EREG_TDP
+2);
1162 DataOffset
= get_uint16(ramBase
+ NETWAVE_EREG_TDP
+4);
1164 DEBUG(3, "TxFreeList %x, MaxData %x, DataOffset %x\n",
1165 TxFreeList
, MaxData
, DataOffset
);
1167 /* Copy packet to the adapter fragment buffers */
1168 curBuff
= TxFreeList
;
1170 while (tmpcount
< len
) {
1171 int tmplen
= len
- tmpcount
;
1172 copy_to_pc(ramBase
+ curBuff
+ DataOffset
, data
+ tmpcount
,
1173 (tmplen
< MaxData
) ? tmplen
: MaxData
);
1174 tmpcount
+= MaxData
;
1176 /* Advance to next buffer */
1177 curBuff
= get_uint16(ramBase
+ curBuff
);
1180 /* Now issue transmit list */
1182 writeb(NETWAVE_CMD_TL
, ramBase
+ NETWAVE_EREG_CB
+ 0);
1183 writeb(len
& 0xff, ramBase
+ NETWAVE_EREG_CB
+ 1);
1184 writeb((len
>>8) & 0xff, ramBase
+ NETWAVE_EREG_CB
+ 2);
1185 writeb(NETWAVE_CMD_EOC
, ramBase
+ NETWAVE_EREG_CB
+ 3);
1187 restore_flags( flags
);
1191 static int netwave_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
) {
1192 /* This flag indicate that the hardware can't perform a transmission.
1193 * Theoritically, NET3 check it before sending a packet to the driver,
1194 * but in fact it never do that and pool continuously.
1195 * As the watchdog will abort too long transmissions, we are quite safe...
1198 netif_stop_queue(dev
);
1201 short length
= ETH_ZLEN
< skb
->len
? skb
->len
: ETH_ZLEN
;
1202 unsigned char* buf
= skb
->data
;
1204 if (netwave_hw_xmit( buf
, length
, dev
) == 1) {
1205 /* Some error, let's make them call us another time? */
1206 netif_start_queue(dev
);
1208 dev
->trans_start
= jiffies
;
1213 } /* netwave_start_xmit */
1216 * Function netwave_interrupt (irq, dev_id, regs)
1218 * This function is the interrupt handler for the Netwave card. This
1219 * routine will be called whenever:
1220 * 1. A packet is received.
1221 * 2. A packet has successfully been transfered and the unit is
1222 * ready to transmit another packet.
1223 * 3. A command has completed execution.
1225 static void netwave_interrupt(int irq
, void* dev_id
, struct pt_regs
*regs
) {
1228 struct net_device
*dev
= (struct net_device
*)dev_id
;
1229 struct netwave_private
*priv
= dev
->priv
;
1230 dev_link_t
*link
= &priv
->link
;
1233 if (!netif_device_present(dev
))
1236 iobase
= dev
->base_addr
;
1237 ramBase
= priv
->ramBase
;
1239 /* Now find what caused the interrupt, check while interrupts ready */
1240 for (i
= 0; i
< 10; i
++) {
1244 if (!(inb(iobase
+NETWAVE_REG_CCSR
) & 0x02))
1245 break; /* None of the interrupt sources asserted */
1247 status
= inb(iobase
+ NETWAVE_REG_ASR
);
1249 if (!DEV_OK(link
)) {
1250 DEBUG(1, "netwave_interrupt: Interrupt with status 0x%x "
1251 "from removed or suspended card!\n", status
);
1256 if (status
& 0x80) {
1258 /* wait_WOC(iobase); */
1259 /* RxRdy cannot be reset directly by the host */
1262 if (status
& 0x40) {
1265 rser
= readb(ramBase
+ NETWAVE_EREG_RSER
);
1268 ++priv
->stats
.rx_dropped
;
1269 ++priv
->stats
.rx_crc_errors
;
1272 ++priv
->stats
.rx_frame_errors
;
1274 /* Clear the RxErr bit in RSER. RSER+4 is the
1275 * write part. Also clear the RxCRC (0x04) and
1276 * RxBig (0x02) bits if present */
1278 writeb(0x40 | (rser
& 0x06), ramBase
+ NETWAVE_EREG_RSER
+ 4);
1280 /* Write bit 6 high to ASCC to clear RxErr in ASR,
1281 * WOC must be set first!
1284 writeb(0x40, ramBase
+ NETWAVE_EREG_ASCC
);
1286 /* Remember to count up priv->stats on error packets */
1287 ++priv
->stats
.rx_errors
;
1290 if (status
& 0x20) {
1293 txStatus
= readb(ramBase
+ NETWAVE_EREG_TSER
);
1294 DEBUG(3, "Transmit done. TSER = %x id %x\n",
1295 txStatus
, readb(ramBase
+ NETWAVE_EREG_TSER
+ 1));
1297 if (txStatus
& 0x20) {
1298 /* Transmitting was okay, clear bits */
1300 writeb(0x2f, ramBase
+ NETWAVE_EREG_TSER
+ 4);
1301 ++priv
->stats
.tx_packets
;
1304 if (txStatus
& 0xd0) {
1305 if (txStatus
& 0x80) {
1306 ++priv
->stats
.collisions
; /* Because of /proc/net/dev*/
1307 /* ++priv->stats.tx_aborted_errors; */
1308 /* printk("Collision. %ld\n", jiffies - dev->trans_start); */
1310 if (txStatus
& 0x40)
1311 ++priv
->stats
.tx_carrier_errors
;
1312 /* 0x80 TxGU Transmit giveup - nine times and no luck
1313 * 0x40 TxNOAP No access point. Discarded packet.
1314 * 0x10 TxErr Transmit error. Always set when
1315 * TxGU and TxNOAP is set. (Those are the only ones
1318 DEBUG(3, "netwave_interrupt: TxDN with error status %x\n",
1321 /* Clear out TxGU, TxNOAP, TxErr and TxTrys */
1323 writeb(0xdf & txStatus
, ramBase
+NETWAVE_EREG_TSER
+4);
1324 ++priv
->stats
.tx_errors
;
1326 DEBUG(3, "New status is TSER %x ASR %x\n",
1327 readb(ramBase
+ NETWAVE_EREG_TSER
),
1328 inb(iobase
+ NETWAVE_REG_ASR
));
1330 netif_wake_queue(dev
);
1332 /* TxBA, this would trigger on all error packets received */
1333 /* if (status & 0x01) {
1334 DEBUG(4, "Transmit buffers available, %x\n", status);
1338 } /* netwave_interrupt */
1341 * Function netwave_watchdog (a)
1343 * Watchdog : when we start a transmission, we set a timer in the
1344 * kernel. If the transmission complete, this timer is disabled. If
1345 * it expire, we reset the card.
1348 static void netwave_watchdog(struct net_device
*dev
) {
1350 DEBUG(1, "%s: netwave_watchdog: watchdog timer expired\n", dev
->name
);
1352 dev
->trans_start
= jiffies
;
1353 netif_start_queue(dev
);
1354 } /* netwave_watchdog */
1356 static struct net_device_stats
*netwave_get_stats(struct net_device
*dev
) {
1357 netwave_private
*priv
= (netwave_private
*)dev
->priv
;
1361 DEBUG(2, "netwave: SPCQ %x SPU %x LIF %x ISPLQ %x MHS %x rxtx %x"
1362 " %x tx %x %x %x %x\n",
1363 readb(priv
->ramBase
+ NETWAVE_EREG_SPCQ
),
1364 readb(priv
->ramBase
+ NETWAVE_EREG_SPU
),
1365 readb(priv
->ramBase
+ NETWAVE_EREG_LIF
),
1366 readb(priv
->ramBase
+ NETWAVE_EREG_ISPLQ
),
1367 readb(priv
->ramBase
+ NETWAVE_EREG_MHS
),
1368 readb(priv
->ramBase
+ NETWAVE_EREG_EC
+ 0xe),
1369 readb(priv
->ramBase
+ NETWAVE_EREG_EC
+ 0xf),
1370 readb(priv
->ramBase
+ NETWAVE_EREG_EC
+ 0x18),
1371 readb(priv
->ramBase
+ NETWAVE_EREG_EC
+ 0x19),
1372 readb(priv
->ramBase
+ NETWAVE_EREG_EC
+ 0x1a),
1373 readb(priv
->ramBase
+ NETWAVE_EREG_EC
+ 0x1b));
1375 return &priv
->stats
;
1378 static void update_stats(struct net_device
*dev
) {
1379 unsigned long flags
;
1384 /* netwave_private *priv = (netwave_private*) dev->priv;
1385 priv->stats.rx_packets = readb(priv->ramBase + 0x18e);
1386 priv->stats.tx_packets = readb(priv->ramBase + 0x18f); */
1388 restore_flags(flags
);
1391 static int netwave_rx(struct net_device
*dev
) {
1392 netwave_private
*priv
= (netwave_private
*)(dev
->priv
);
1393 u_char
*ramBase
= priv
->ramBase
;
1394 ioaddr_t iobase
= dev
->base_addr
;
1396 struct sk_buff
*skb
= NULL
;
1397 unsigned int curBuffer
,
1401 int dataCount
, dataOffset
;
1405 DEBUG(3, "xinw_rx: Receiving ... \n");
1407 /* Receive max 10 packets for now. */
1408 for (i
= 0; i
< 10; i
++) {
1411 rxStatus
= readb(ramBase
+ NETWAVE_EREG_RSER
);
1412 if ( !( rxStatus
& 0x80)) /* No more packets */
1415 /* Check if multicast/broadcast or other */
1416 /* multicast = (rxStatus & 0x20); */
1418 /* The receive list pointer and length of the packet */
1420 rcvLen
= get_int16( ramBase
+ NETWAVE_EREG_RDP
);
1421 rcvList
= get_uint16( ramBase
+ NETWAVE_EREG_RDP
+ 2);
1424 printk(KERN_DEBUG
"netwave_rx: Receive packet with len %d\n",
1429 skb
= dev_alloc_skb(rcvLen
+5);
1431 DEBUG(1, "netwave_rx: Could not allocate an sk_buff of "
1432 "length %d\n", rcvLen
);
1433 ++priv
->stats
.rx_dropped
;
1434 /* Tell the adapter to skip the packet */
1436 writeb(NETWAVE_CMD_SRP
, ramBase
+ NETWAVE_EREG_CB
+ 0);
1437 writeb(NETWAVE_CMD_EOC
, ramBase
+ NETWAVE_EREG_CB
+ 1);
1441 skb_reserve( skb
, 2); /* Align IP on 16 byte */
1442 skb_put( skb
, rcvLen
);
1445 /* Copy packet fragments to the skb data area */
1446 ptr
= (u_char
*) skb
->data
;
1447 curBuffer
= rcvList
;
1449 while ( tmpcount
< rcvLen
) {
1450 /* Get length and offset of current buffer */
1451 dataCount
= get_uint16( ramBase
+curBuffer
+2);
1452 dataOffset
= get_uint16( ramBase
+curBuffer
+4);
1454 copy_from_pc( ptr
+ tmpcount
,
1455 ramBase
+curBuffer
+dataOffset
, dataCount
);
1457 tmpcount
+= dataCount
;
1459 /* Point to next buffer */
1460 curBuffer
= get_uint16(ramBase
+ curBuffer
);
1463 skb
->protocol
= eth_type_trans(skb
,dev
);
1464 /* Queue packet for network layer */
1467 /* Got the packet, tell the adapter to skip it */
1469 writeb(NETWAVE_CMD_SRP
, ramBase
+ NETWAVE_EREG_CB
+ 0);
1470 writeb(NETWAVE_CMD_EOC
, ramBase
+ NETWAVE_EREG_CB
+ 1);
1471 DEBUG(3, "Packet reception ok\n");
1473 priv
->stats
.rx_packets
++;
1475 priv
->stats
.rx_bytes
+= skb
->len
;
1480 static int netwave_open(struct net_device
*dev
) {
1481 netwave_private
*priv
= dev
->priv
;
1482 dev_link_t
*link
= &priv
->link
;
1484 DEBUG(1, "netwave_open: starting.\n");
1492 netif_start_queue(dev
);
1498 static int netwave_close(struct net_device
*dev
) {
1499 netwave_private
*priv
= (netwave_private
*)dev
->priv
;
1500 dev_link_t
*link
= &priv
->link
;
1502 DEBUG(1, "netwave_close: finishing.\n");
1505 netif_stop_queue(dev
);
1506 if (link
->state
& DEV_STALE_CONFIG
)
1507 mod_timer(&link
->release
, jiffies
+ HZ
/20);
1513 static int __init
init_netwave_cs(void) {
1516 DEBUG(0, "%s\n", version
);
1518 CardServices(GetCardServicesInfo
, &serv
);
1519 if (serv
.Revision
!= CS_RELEASE_CODE
) {
1520 printk("netwave_cs: Card Services release does not match!\n");
1524 register_pccard_driver(&dev_info
, &netwave_attach
, &netwave_detach
);
1529 static void __exit
exit_netwave_cs(void) {
1530 DEBUG(1, "netwave_cs: unloading\n");
1532 unregister_pccard_driver(&dev_info
);
1534 /* Do some cleanup of the device list */
1535 netwave_flush_stale_links();
1536 if(dev_list
!= NULL
) /* Critical situation */
1537 printk("netwave_cs: devices remaining when removing module\n");
1540 module_init(init_netwave_cs
);
1541 module_exit(exit_netwave_cs
);
1543 /* Set or clear the multicast filter for this adaptor.
1544 num_addrs == -1 Promiscuous mode, receive all packets
1545 num_addrs == 0 Normal mode, clear multicast list
1546 num_addrs > 0 Multicast mode, receive normal and MC packets, and do
1547 best-effort filtering.
1549 static void set_multicast_list(struct net_device
*dev
)
1551 ioaddr_t iobase
= dev
->base_addr
;
1552 u_char
* ramBase
= ((netwave_private
*) dev
->priv
)->ramBase
;
1558 if (old
!= dev
->mc_count
) {
1559 old
= dev
->mc_count
;
1560 DEBUG(0, "%s: setting Rx mode to %d addresses.\n",
1561 dev
->name
, dev
->mc_count
);
1566 if (dev
->mc_count
|| (dev
->flags
& IFF_ALLMULTI
)) {
1567 /* Multicast Mode */
1568 rcvMode
= rxConfRxEna
+ rxConfAMP
+ rxConfBcast
;
1569 } else if (dev
->flags
& IFF_PROMISC
) {
1570 /* Promiscous mode */
1571 rcvMode
= rxConfRxEna
+ rxConfPro
+ rxConfAMP
+ rxConfBcast
;
1574 rcvMode
= rxConfRxEna
+ rxConfBcast
;
1577 /* printk("netwave set_multicast_list: rcvMode to %x\n", rcvMode);*/
1578 /* Now set receive mode */
1580 writeb(NETWAVE_CMD_SRC
, ramBase
+ NETWAVE_EREG_CB
+ 0);
1581 writeb(rcvMode
, ramBase
+ NETWAVE_EREG_CB
+ 1);
1582 writeb(NETWAVE_CMD_EOC
, ramBase
+ NETWAVE_EREG_CB
+ 2);