6 * Reorganisation and extension of the driver.
8 * This file contains all definitions and declarations necessary for the
9 * WaveLAN ISA driver. This file is a private header, so it should
10 * be included only in wavelan.c!
16 /************************** DOCUMENTATION ***************************/
18 * This driver provides a Linux interface to the WaveLAN ISA hardware.
19 * The WaveLAN is a product of Lucent (http://www.wavelan.com/).
20 * This division was formerly part of NCR and then AT&T.
21 * WaveLANs are also distributed by DEC (RoamAbout DS) and Digital Ocean.
23 * To learn how to use this driver, read the NET3 HOWTO.
24 * If you want to exploit the many other functionalities, read the comments
27 * This driver is the result of the effort of many people (see below).
30 /* ------------------------ SPECIFIC NOTES ------------------------ */
34 * I try to maintain a web page with the Wireless LAN Howto at :
35 * http://www.hpl.hp.com/personal/Jean_Tourrilhes/Linux/Wavelan.html
37 * Debugging and options
38 * ---------------------
39 * You will find below a set of '#define" allowing a very fine control
40 * on the driver behaviour and the debug messages printed.
41 * The main options are :
42 * o SET_PSA_CRC, to have your card correctly recognised by
43 * an access point and the Point-to-Point diagnostic tool.
44 * o USE_PSA_CONFIG, to read configuration from the PSA (EEprom)
45 * (otherwise we always start afresh with some defaults)
47 * wavelan.o is too darned big
48 * ---------------------------
49 * That's true! There is a very simple way to reduce the driver
50 * object by 33%! Comment out the following line:
51 * #include <linux/wireless.h>
52 * Other compile options can also reduce the size of it...
54 * MAC address and hardware detection:
55 * -----------------------------------
56 * The detection code for the WaveLAN checks that the first three
57 * octets of the MAC address fit the company code. This type of
58 * detection works well for AT&T cards (because the AT&T code is
59 * hardcoded in wavelan.h), but of course will fail for other
62 * If you are sure that your card is derived from the WaveLAN,
63 * here is the way to configure it:
64 * 1) Get your MAC address
65 * a) With your card utilities (wfreqsel, instconf, etc.)
67 * o compile the kernel with DEBUG_CONFIG_INFO enabled
68 * o Boot and look the card messages
69 * 2) Set your MAC code (3 octets) in MAC_ADDRESSES[][3] (wavelan.h)
70 * 3) Compile and verify
71 * 4) Send me the MAC code. I will include it in the next version.
75 /* --------------------- WIRELESS EXTENSIONS --------------------- */
77 * This driver is the first to support "wireless extensions".
78 * This set of extensions provides a standard way to control the wireless
79 * characteristics of the hardware. Applications such as mobile IP may
80 * take advantage of it.
82 * You will need to enable the CONFIG_NET_RADIO define in the kernel
83 * configuration to enable the wireless extensions (this is the one
84 * giving access to the radio network device choice).
86 * It might also be a good idea as well to fetch the wireless tools to
87 * configure the device and play a bit.
90 /* ---------------------------- FILES ---------------------------- */
92 * wavelan.c: actual code for the driver: C functions
94 * wavelan.p.h: private header: local types and variables for driver
96 * wavelan.h: description of the hardware interface and structs
98 * i82586.h: description of the Ethernet controller
101 /* --------------------------- HISTORY --------------------------- */
103 * This is based on information in the drivers' headers. It may not be
104 * accurate, and I guarantee only my best effort.
106 * The history of the WaveLAN drivers is as complicated as the history of
107 * the WaveLAN itself (NCR -> AT&T -> Lucent).
109 * It all started with Anders Klemets <klemets@paul.rutgers.edu>
110 * writing a WaveLAN ISA driver for the Mach microkernel. Girish
111 * Welling <welling@paul.rutgers.edu> had also worked on it.
112 * Keith Moore modified this for the PCMCIA hardware.
114 * Robert Morris <rtm@das.harvard.edu> ported these two drivers to BSDI
115 * and added specific PCMCIA support (there is currently no equivalent
116 * of the PCMCIA package under BSD).
118 * Jim Binkley <jrb@cs.pdx.edu> ported both BSDI drivers to FreeBSD.
120 * Bruce Janson <bruce@cs.usyd.edu.au> ported the BSDI ISA driver to Linux.
122 * Anthony D. Joseph <adj@lcs.mit.edu> started to modify Bruce's driver
123 * (with help of the BSDI PCMCIA driver) for PCMCIA.
124 * Yunzhou Li <yunzhou@strat.iol.unh.edu> finished this work.
125 * Joe Finney <joe@comp.lancs.ac.uk> patched the driver to start
126 * 2.00 cards correctly (2.4 GHz with frequency selection).
127 * David Hinds <dhinds@hyper.stanford.edu> integrated the whole in his
128 * PCMCIA package (and bug corrections).
130 * I (Jean Tourrilhes - jt@hplb.hpl.hp.com) then started to make some
131 * patches to the PCMCIA driver. Later, I added code in the ISA driver
132 * for Wireless Extensions and full support of frequency selection
133 * cards. Then, I did the same to the PCMCIA driver, and did some
134 * reorganisation. Finally, I came back to the ISA driver to
135 * upgrade it at the same level as the PCMCIA one and reorganise
137 * Loeke Brederveld <lbrederv@wavelan.com> from Lucent has given me
138 * much needed information on the WaveLAN hardware.
141 /* The original copyrights and literature mention others' names and
142 * credits. I don't know what their part in this development was.
145 /* By the way, for the copyright and legal stuff:
146 * almost everybody wrote code under the GNU or BSD license (or similar),
147 * and want their original copyright to remain somewhere in the
148 * code (for myself, I go with the GPL).
149 * Nobody wants to take responsibility for anything, except the fame.
152 /* --------------------------- CREDITS --------------------------- */
154 * This software was developed as a component of the
155 * Linux operating system.
156 * It is based on other device drivers and information
157 * either written or supplied by:
158 * Ajay Bakre <bakre@paul.rutgers.edu>,
159 * Donald Becker <becker@cesdis.gsfc.nasa.gov>,
160 * Loeke Brederveld <Loeke.Brederveld@Utrecht.NCR.com>,
161 * Brent Elphick <belphick@uwaterloo.ca>,
162 * Anders Klemets <klemets@it.kth.se>,
163 * Vladimir V. Kolpakov <w@stier.koenig.ru>,
164 * Marc Meertens <Marc.Meertens@Utrecht.NCR.com>,
165 * Pauline Middelink <middelin@polyware.iaf.nl>,
166 * Robert Morris <rtm@das.harvard.edu>,
167 * Jean Tourrilhes <jt@hpl.hp.com>,
168 * Girish Welling <welling@paul.rutgers.edu>,
169 * Clark Woodworth <clark@hiway1.exit109.com>
170 * Yongguang Zhang <ygz@isl.hrl.hac.com>
173 * James Ashton <jaa101@syseng.anu.edu.au>,
174 * Alan Cox <iialan@iiit.swan.ac.uk>,
175 * Allan Creighton <allanc@cs.usyd.edu.au>,
176 * Matthew Geier <matthew@cs.usyd.edu.au>,
177 * Remo di Giovanni <remo@cs.usyd.edu.au>,
178 * Eckhard Grah <grah@wrcs1.urz.uni-wuppertal.de>,
179 * Vipul Gupta <vgupta@cs.binghamton.edu>,
180 * Mark Hagan <mhagan@wtcpost.daytonoh.NCR.COM>,
181 * Tim Nicholson <tim@cs.usyd.edu.au>,
182 * Ian Parkin <ian@cs.usyd.edu.au>,
183 * John Rosenberg <johnr@cs.usyd.edu.au>,
184 * George Rossi <george@phm.gov.au>,
185 * Arthur Scott <arthur@cs.usyd.edu.au>,
186 * Stanislav Sinyagin <stas@isf.ru>
187 * and Peter Storey for their assistance and advice.
189 * Additional Credits:
191 * My development has been done under Linux 2.0.x (Debian 1.1) with
192 * an HP Vectra XP/60.
196 /* ------------------------- IMPROVEMENTS ------------------------- */
200 * Changes made in first pre-release:
201 * ----------------------------------
202 * - reorganisation of the code, function name change
203 * - creation of private header (wavelan.p.h)
204 * - reorganised debug messages
205 * - more comments, history, etc.
206 * - mmc_init: configure the PSA if not done
207 * - mmc_init: correct default value of level threshold for PCMCIA
208 * - mmc_init: 2.00 detection better code for 2.00 initialization
209 * - better info at startup
210 * - IRQ setting (note: this setting is permanent)
211 * - watchdog: change strategy (and solve module removal problems)
212 * - add wireless extensions (ioctl and get_wireless_stats)
213 * get/set nwid/frequency on fly, info for /proc/net/wireless
214 * - more wireless extensions: SETSPY and GETSPY
215 * - make wireless extensions optional
216 * - private ioctl to set/get quality and level threshold, histogram
217 * - remove /proc/net/wavelan
218 * - suppress useless stuff from lp (net_local)
219 * - kernel 2.1 support (copy_to/from_user instead of memcpy_to/fromfs)
220 * - add message level (debug stuff in /var/adm/debug and errors not
221 * displayed at console and still in /var/adm/messages)
222 * - multi device support
223 * - start fixing the probe (init code)
226 * - many other minor details and cleanups
228 * Changes made in second pre-release:
229 * -----------------------------------
230 * - clean up init code (probe and module init)
231 * - better multiple device support (module)
232 * - name assignment (module)
234 * Changes made in third pre-release:
235 * ----------------------------------
236 * - be more conservative on timers
237 * - preliminary support for multicast (I still lack some details)
239 * Changes made in fourth pre-release:
240 * -----------------------------------
241 * - multicast (revisited and finished)
242 * - avoid reset in set_multicast_list (a really big hack)
243 * if somebody could apply this code for other i82586 based drivers
244 * - share onboard memory 75% RU and 25% CU (instead of 50/50)
246 * Changes made for release in 2.1.15:
247 * -----------------------------------
248 * - change the detection code for multi manufacturer code support
250 * Changes made for release in 2.1.17:
251 * -----------------------------------
252 * - update to wireless extensions changes
253 * - silly bug in card initial configuration (psa_conf_status)
255 * Changes made for release in 2.1.27 & 2.0.30:
256 * --------------------------------------------
257 * - small bug in debug code (probably not the last one...)
258 * - remove extern keyword for wavelan_probe()
259 * - level threshold is now a standard wireless extension (version 4 !)
260 * - modules parameters types (new module interface)
262 * Changes made for release in 2.1.36:
263 * -----------------------------------
264 * - byte count stats (courtesy of David Hinds)
265 * - remove dev_tint stuff (courtesy of David Hinds)
266 * - encryption setting from Brent Elphick (thanks a lot!)
267 * - 'ioaddr' to 'u_long' for the Alpha (thanks to Stanislav Sinyagin)
269 * Other changes (not by me) :
270 * -------------------------
271 * - Spelling and gramar "rectification".
273 * Changes made for release in 2.0.37 & 2.2.2 :
274 * ------------------------------------------
275 * - Correct status in /proc/net/wireless
276 * - Set PSA CRC to make PtP diagnostic tool happy (Bob Gray)
277 * - Module init code don't fail if we found at least one card in
278 * the address list (Karlis Peisenieks)
279 * - Missing parenthesis (Christopher Peterson)
280 * - Correct i82586 configuration parameters
281 * - Encryption initialisation bug (Robert McCormack)
282 * - New mac addresses detected in the probe
283 * - Increase watchdog for busy environments
285 * Changes made for release in 2.0.38 & 2.2.7 :
286 * ------------------------------------------
287 * - Correct the reception logic to better report errors and avoid
288 * sending bogus packet up the stack
289 * - Delay RU config to avoid corrupting first received packet
290 * - Change config completion code (to actually check something)
291 * - Avoid reading out of bound in skbuf to transmit
292 * - Rectify a lot of (useless) debugging code
293 * - Change the way to `#ifdef SET_PSA_CRC'
295 * Changes made for release in 2.2.11 & 2.3.13 :
296 * -------------------------------------------
297 * - Change e-mail and web page addresses
298 * - Watchdog timer is now correctly expressed in HZ, not in jiffies
299 * - Add channel number to the list of frequencies in range
300 * - Add the (short) list of bit-rates in range
301 * - Developp a new sensitivity... (sens.value & sens.fixed)
305 * - roaming (see Pcmcia driver)
308 /***************************** INCLUDES *****************************/
310 #include <linux/module.h>
312 #include <linux/kernel.h>
313 #include <linux/sched.h>
314 #include <linux/types.h>
315 #include <linux/fcntl.h>
316 #include <linux/interrupt.h>
317 #include <linux/stat.h>
318 #include <linux/ptrace.h>
319 #include <linux/ioport.h>
320 #include <linux/in.h>
321 #include <linux/string.h>
322 #include <linux/delay.h>
323 #include <asm/system.h>
324 #include <asm/bitops.h>
327 #include <asm/uaccess.h>
328 #include <linux/errno.h>
329 #include <linux/netdevice.h>
330 #include <linux/etherdevice.h>
331 #include <linux/skbuff.h>
332 #include <linux/malloc.h>
333 #include <linux/timer.h>
334 #include <linux/init.h>
336 #include <linux/wireless.h> /* Wireless extensions */
338 /* WaveLAN declarations */
342 /************************** DRIVER OPTIONS **************************/
344 * `#define' or `#undef' the following constant to change the behaviour
347 #undef SET_PSA_CRC /* Calculate and set the CRC on PSA (slower) */
348 #define USE_PSA_CONFIG /* Use info from the PSA. */
349 #undef STRUCT_CHECK /* Verify padding of structures. */
350 #undef EEPROM_IS_PROTECTED /* doesn't seem to be necessary */
351 #define MULTICAST_AVOID /* Avoid extra multicast (I'm sceptical). */
352 #undef SET_MAC_ADDRESS /* Experimental */
354 #ifdef WIRELESS_EXT /* If wireless extensions exist in the kernel */
355 /* Warning: this stuff will slow down the driver. */
356 #define WIRELESS_SPY /* Enable spying addresses. */
357 #undef HISTOGRAM /* Enable histogram of signal level. */
360 /****************************** DEBUG ******************************/
362 #undef DEBUG_MODULE_TRACE /* module insertion/removal */
363 #undef DEBUG_CALLBACK_TRACE /* calls made by Linux */
364 #undef DEBUG_INTERRUPT_TRACE /* calls to handler */
365 #undef DEBUG_INTERRUPT_INFO /* type of interrupt and so on */
366 #define DEBUG_INTERRUPT_ERROR /* problems */
367 #undef DEBUG_CONFIG_TRACE /* Trace the config functions. */
368 #undef DEBUG_CONFIG_INFO /* what's going on */
369 #define DEBUG_CONFIG_ERROR /* errors on configuration */
370 #undef DEBUG_TX_TRACE /* transmission calls */
371 #undef DEBUG_TX_INFO /* header of the transmitted packet */
372 #undef DEBUG_TX_FAIL /* Normal failure conditions */
373 #define DEBUG_TX_ERROR /* Unexpected conditions */
374 #undef DEBUG_RX_TRACE /* transmission calls */
375 #undef DEBUG_RX_INFO /* header of the received packet */
376 #undef DEBUG_RX_FAIL /* Normal failure conditions */
377 #define DEBUG_RX_ERROR /* Unexpected conditions */
378 #undef DEBUG_PACKET_DUMP 32 /* Dump packet on the screen. */
379 #undef DEBUG_IOCTL_TRACE /* misc. call by Linux */
380 #undef DEBUG_IOCTL_INFO /* various debugging info */
381 #define DEBUG_IOCTL_ERROR /* what's going wrong */
382 #define DEBUG_BASIC_SHOW /* Show basic startup info. */
383 #undef DEBUG_VERSION_SHOW /* Print version info. */
384 #undef DEBUG_PSA_SHOW /* Dump PSA to screen. */
385 #undef DEBUG_MMC_SHOW /* Dump mmc to screen. */
386 #undef DEBUG_SHOW_UNUSED /* Show unused fields too. */
387 #undef DEBUG_I82586_SHOW /* Show i82586 status. */
388 #undef DEBUG_DEVICE_SHOW /* Show device parameters. */
390 /************************ CONSTANTS & MACROS ************************/
392 #ifdef DEBUG_VERSION_SHOW
393 static const char *version
= "wavelan.c : v20 (wireless extensions) 29/7/99\n";
396 /* Watchdog temporisation */
397 #define WATCHDOG_JIFFIES (256*HZ/100)
399 /* Macro to get the number of elements in an array */
400 #define NELS(a) (sizeof(a) / sizeof(a[0]))
402 /* ------------------------ PRIVATE IOCTL ------------------------ */
404 #define SIOCSIPQTHR SIOCDEVPRIVATE /* Set quality threshold */
405 #define SIOCGIPQTHR SIOCDEVPRIVATE + 1 /* Get quality threshold */
406 #define SIOCSIPLTHR SIOCDEVPRIVATE + 2 /* Set level threshold */
407 #define SIOCGIPLTHR SIOCDEVPRIVATE + 3 /* Get level threshold */
409 #define SIOCSIPHISTO SIOCDEVPRIVATE + 6 /* Set histogram ranges */
410 #define SIOCGIPHISTO SIOCDEVPRIVATE + 7 /* Get histogram values */
412 /****************************** TYPES ******************************/
415 typedef struct net_device device
;
416 typedef struct net_device_stats en_stats
;
417 typedef struct iw_statistics iw_stats
;
418 typedef struct iw_quality iw_qual
;
419 typedef struct iw_freq iw_freq
;
420 typedef struct net_local net_local
;
421 typedef struct timer_list timer_list
;
424 typedef u_char mac_addr
[WAVELAN_ADDR_SIZE
]; /* Hardware address */
427 * Static specific data for the interface.
429 * For each network interface, Linux keeps data in two structures: "device"
430 * keeps the generic data (same format for everybody) and "net_local" keeps
431 * additional specific data.
432 * Note that some of this specific data is in fact generic (en_stats, for
437 net_local
* next
; /* linked list of the devices */
438 device
* dev
; /* reverse link */
439 en_stats stats
; /* Ethernet interface statistics */
440 int nresets
; /* number of hardware resets */
441 u_char reconfig_82586
; /* We need to reconfigure the controller. */
442 u_char promiscuous
; /* promiscuous mode */
443 int mc_count
; /* number of multicast addresses */
444 timer_list watchdog
; /* to avoid blocking state */
445 u_short hacr
; /* current host interface state */
450 u_short tx_first_free
;
451 u_short tx_first_in_use
;
454 iw_stats wstats
; /* Wireless-specific statistics */
458 int spy_number
; /* number of addresses to spy */
459 mac_addr spy_address
[IW_MAX_SPY
]; /* the addresses to spy */
460 iw_qual spy_stat
[IW_MAX_SPY
]; /* statistics gathered */
461 #endif /* WIRELESS_SPY */
464 int his_number
; /* number of intervals */
465 u_char his_range
[16]; /* boundaries of interval ]n-1; n] */
466 u_long his_sum
[16]; /* sum in interval */
467 #endif /* HISTOGRAM */
470 /**************************** PROTOTYPES ****************************/
472 /* ----------------------- MISC. SUBROUTINES ------------------------ */
473 static inline unsigned long /* flags */
474 wv_splhi(void); /* Disable interrupts */
476 wv_splx(unsigned long); /* Enable interrupts: flags */
480 wv_psa_to_irq(u_char
);
481 /* ------------------- HOST ADAPTER SUBROUTINES ------------------- */
482 static inline u_short
/* data */
483 hasr_read(u_long
); /* Read the host interface: base address */
485 hacr_write(u_long
, /* Write to host interface: base address */
487 hacr_write_slow(u_long
,
489 set_chan_attn(u_long
, /* ioaddr */
491 wv_hacr_reset(u_long
), /* ioaddr */
492 wv_16_off(u_long
, /* ioaddr */
494 wv_16_on(u_long
, /* ioaddr */
496 wv_ints_off(device
*),
497 wv_ints_on(device
*);
498 /* ----------------- MODEM MANAGEMENT SUBROUTINES ----------------- */
500 psa_read(u_long
, /* Read the Parameter Storage Area. */
502 int, /* offset in PSA */
503 u_char
*, /* buffer to fill */
504 int), /* size to read */
505 psa_write(u_long
, /* Write to the PSA. */
507 int, /* offset in PSA */
508 u_char
*, /* buffer in memory */
509 int); /* length of buffer */
511 mmc_out(u_long
, /* Write 1 byte to the Modem Manag Control. */
514 mmc_write(u_long
, /* Write n bytes to the MMC. */
518 static inline u_char
/* Read 1 byte from the MMC. */
522 mmc_read(u_long
, /* Read n bytes from the MMC. */
526 fee_wait(u_long
, /* Wait for frequency EEPROM: base address */
527 int, /* base delay to wait for */
528 int); /* time to wait */
530 fee_read(u_long
, /* Read the frequency EEPROM: base address */
531 u_short
, /* destination offset */
532 u_short
*, /* data buffer */
533 int); /* number of registers */
534 /* ---------------------- I82586 SUBROUTINES ----------------------- */
535 static /*inline*/ void
536 obram_read(u_long
, /* ioaddr */
541 obram_write(u_long
, /* ioaddr */
548 wv_synchronous_cmd(device
*,
550 wv_config_complete(device
*,
554 wv_complete(device
*,
558 wv_82586_reconfig(device
*);
559 /* ------------------- DEBUG & INFO SUBROUTINES ------------------- */
560 #ifdef DEBUG_I82586_SHOW
562 wv_scb_show(unsigned short);
565 wv_init_info(device
*); /* display startup info */
566 /* ------------------- IOCTL, STATS & RECONFIG ------------------- */
568 wavelan_get_stats(device
*); /* Give stats /proc/net/dev */
570 wavelan_set_multicast_list(device
*);
571 /* ----------------------- PACKET RECEPTION ----------------------- */
573 wv_packet_read(device
*, /* Read a packet from a frame. */
576 wv_receive(device
*); /* Read all packets waiting. */
577 /* --------------------- PACKET TRANSMISSION --------------------- */
579 wv_packet_write(device
*, /* Write a packet to the Tx buffer. */
583 wavelan_packet_xmit(struct sk_buff
*, /* Send a packet. */
585 /* -------------------- HARDWARE CONFIGURATION -------------------- */
587 wv_mmc_init(device
*), /* Initialize the modem. */
588 wv_ru_start(device
*), /* Start the i82586 receiver unit. */
589 wv_cu_start(device
*), /* Start the i82586 command unit. */
590 wv_82586_start(device
*); /* Start the i82586. */
592 wv_82586_config(device
*); /* Configure the i82586. */
594 wv_82586_stop(device
*);
596 wv_hw_reset(device
*), /* Reset the WaveLAN hardware. */
597 wv_check_ioaddr(u_long
, /* ioaddr */
598 u_char
*); /* mac address (read) */
599 /* ---------------------- INTERRUPT HANDLING ---------------------- */
601 wavelan_interrupt(int, /* interrupt handler */
605 wavelan_watchdog(u_long
); /* transmission watchdog */
606 /* ------------------- CONFIGURATION CALLBACKS ------------------- */
608 wavelan_open(device
*), /* Open the device. */
609 wavelan_close(device
*), /* Close the device. */
610 wavelan_config(device
*); /* Configure one device. */
612 wavelan_probe(device
*); /* See Space.c. */
614 /**************************** VARIABLES ****************************/
617 * This is the root of the linked list of WaveLAN drivers
618 * It is use to verify that we don't reuse the same base address
619 * for two different drivers and to clean up when removing the module.
621 static net_local
* wavelan_list
= (net_local
*) NULL
;
624 * This table is used to translate the PSA value to IRQ number
627 static u_char irqvals
[] =
636 * Table of the available I/O addresses (base addresses) for WaveLAN
638 static unsigned short iobase
[] =
641 /* Leave out 0x3C0 for now -- seems to clash with some video
643 * Leave out the others too -- we will always use 0x390 and leave
644 * 0x300 for the Ethernet device.
645 * Jean II: 0x3E0 is fine as well.
647 0x300, 0x390, 0x3E0, 0x3C0
653 /* Parameters set by insmod */
654 static int io
[4] = { 0, 0, 0, 0 };
655 static int irq
[4] = { 0, 0, 0, 0 };
656 static char name
[4][IFNAMSIZ
] = { "", "", "", "" };
657 MODULE_PARM(io
, "1-4i");
658 MODULE_PARM(irq
, "1-4i");
659 MODULE_PARM(name
, "1-4c" __MODULE_STRING(IFNAMSIZ
));
662 #endif /* WAVELAN_P_H */