[TG3]: Set minimal hw interrupt mitigation.
[linux-2.6/verdex.git] / drivers / net / wireless / orinoco.c
bloba3a32430ae9d719e105d945b3eb7071523a44e37
1 /* orinoco.c - (formerly known as dldwd_cs.c and orinoco_cs.c)
3 * A driver for Hermes or Prism 2 chipset based PCMCIA wireless
4 * adaptors, with Lucent/Agere, Intersil or Symbol firmware.
6 * Current maintainers (as of 29 September 2003) are:
7 * Pavel Roskin <proski AT gnu.org>
8 * and David Gibson <hermes AT gibson.dropbear.id.au>
10 * (C) Copyright David Gibson, IBM Corporation 2001-2003.
11 * Copyright (C) 2000 David Gibson, Linuxcare Australia.
12 * With some help from :
13 * Copyright (C) 2001 Jean Tourrilhes, HP Labs
14 * Copyright (C) 2001 Benjamin Herrenschmidt
16 * Based on dummy_cs.c 1.27 2000/06/12 21:27:25
18 * Portions based on wvlan_cs.c 1.0.6, Copyright Andreas Neuhaus <andy
19 * AT fasta.fh-dortmund.de>
20 * http://www.stud.fh-dortmund.de/~andy/wvlan/
22 * The contents of this file are subject to the Mozilla Public License
23 * Version 1.1 (the "License"); you may not use this file except in
24 * compliance with the License. You may obtain a copy of the License
25 * at http://www.mozilla.org/MPL/
27 * Software distributed under the License is distributed on an "AS IS"
28 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
29 * the License for the specific language governing rights and
30 * limitations under the License.
32 * The initial developer of the original code is David A. Hinds
33 * <dahinds AT users.sourceforge.net>. Portions created by David
34 * A. Hinds are Copyright (C) 1999 David A. Hinds. All Rights
35 * Reserved.
37 * Alternatively, the contents of this file may be used under the
38 * terms of the GNU General Public License version 2 (the "GPL"), in
39 * which case the provisions of the GPL are applicable instead of the
40 * above. If you wish to allow the use of your version of this file
41 * only under the terms of the GPL and not to allow others to use your
42 * version of this file under the MPL, indicate your decision by
43 * deleting the provisions above and replace them with the notice and
44 * other provisions required by the GPL. If you do not delete the
45 * provisions above, a recipient may use your version of this file
46 * under either the MPL or the GPL. */
49 * v0.01 -> v0.02 - 21/3/2001 - Jean II
50 * o Allow to use regular ethX device name instead of dldwdX
51 * o Warning on IBSS with ESSID=any for firmware 6.06
52 * o Put proper range.throughput values (optimistic)
53 * o IWSPY support (IOCTL and stat gather in Rx path)
54 * o Allow setting frequency in Ad-Hoc mode
55 * o Disable WEP setting if !has_wep to work on old firmware
56 * o Fix txpower range
57 * o Start adding support for Samsung/Compaq firmware
59 * v0.02 -> v0.03 - 23/3/2001 - Jean II
60 * o Start adding Symbol support - need to check all that
61 * o Fix Prism2/Symbol WEP to accept 128 bits keys
62 * o Add Symbol WEP (add authentication type)
63 * o Add Prism2/Symbol rate
64 * o Add PM timeout (holdover duration)
65 * o Enable "iwconfig eth0 key off" and friends (toggle flags)
66 * o Enable "iwconfig eth0 power unicast/all" (toggle flags)
67 * o Try with an Intel card. It report firmware 1.01, behave like
68 * an antiquated firmware, however on windows it says 2.00. Yuck !
69 * o Workaround firmware bug in allocate buffer (Intel 1.01)
70 * o Finish external renaming to orinoco...
71 * o Testing with various Wavelan firmwares
73 * v0.03 -> v0.04 - 30/3/2001 - Jean II
74 * o Update to Wireless 11 -> add retry limit/lifetime support
75 * o Tested with a D-Link DWL 650 card, fill in firmware support
76 * o Warning on Vcc mismatch (D-Link 3.3v card in Lucent 5v only slot)
77 * o Fixed the Prism2 WEP bugs that I introduced in v0.03 :-(
78 * It works on D-Link *only* after a tcpdump. Weird...
79 * And still doesn't work on Intel card. Grrrr...
80 * o Update the mode after a setport3
81 * o Add preamble setting for Symbol cards (not yet enabled)
82 * o Don't complain as much about Symbol cards...
84 * v0.04 -> v0.04b - 22/4/2001 - David Gibson
85 * o Removed the 'eth' parameter - always use ethXX as the
86 * interface name instead of dldwdXX. The other was racy
87 * anyway.
88 * o Clean up RID definitions in hermes.h, other cleanups
90 * v0.04b -> v0.04c - 24/4/2001 - Jean II
91 * o Tim Hurley <timster AT seiki.bliztech.com> reported a D-Link card
92 * with vendor 02 and firmware 0.08. Added in the capabilities...
93 * o Tested Lucent firmware 7.28, everything works...
95 * v0.04c -> v0.05 - 3/5/2001 - Benjamin Herrenschmidt
96 * o Spin-off Pcmcia code. This file is renamed orinoco.c,
97 * and orinoco_cs.c now contains only the Pcmcia specific stuff
98 * o Add Airport driver support on top of orinoco.c (see airport.c)
100 * v0.05 -> v0.05a - 4/5/2001 - Jean II
101 * o Revert to old Pcmcia code to fix breakage of Ben's changes...
103 * v0.05a -> v0.05b - 4/5/2001 - Jean II
104 * o add module parameter 'ignore_cis_vcc' for D-Link @ 5V
105 * o D-Link firmware doesn't support multicast. We just print a few
106 * error messages, but otherwise everything works...
107 * o For David : set/getport3 works fine, just upgrade iwpriv...
109 * v0.05b -> v0.05c - 5/5/2001 - Benjamin Herrenschmidt
110 * o Adapt airport.c to latest changes in orinoco.c
111 * o Remove deferred power enabling code
113 * v0.05c -> v0.05d - 5/5/2001 - Jean II
114 * o Workaround to SNAP decapsulate frame from Linksys AP
115 * original patch from : Dong Liu <dliu AT research.bell-labs.com>
116 * (note : the memcmp bug was mine - fixed)
117 * o Remove set_retry stuff, no firmware support it (bloat--).
119 * v0.05d -> v0.06 - 25/5/2001 - Jean II
120 * Original patch from "Hong Lin" <alin AT redhat.com>,
121 * "Ian Kinner" <ikinner AT redhat.com>
122 * and "David Smith" <dsmith AT redhat.com>
123 * o Init of priv->tx_rate_ctrl in firmware specific section.
124 * o Prism2/Symbol rate, upto should be 0xF and not 0x15. Doh !
125 * o Spectrum card always need cor_reset (for every reset)
126 * o Fix cor_reset to not lose bit 7 in the register
127 * o flush_stale_links to remove zombie Pcmcia instances
128 * o Ack previous hermes event before reset
129 * Me (with my little hands)
130 * o Allow orinoco.c to call cor_reset via priv->card_reset_handler
131 * o Add priv->need_card_reset to toggle this feature
132 * o Fix various buglets when setting WEP in Symbol firmware
133 * Now, encryption is fully functional on Symbol cards. Youpi !
135 * v0.06 -> v0.06b - 25/5/2001 - Jean II
136 * o IBSS on Symbol use port_mode = 4. Please don't ask...
138 * v0.06b -> v0.06c - 29/5/2001 - Jean II
139 * o Show first spy address in /proc/net/wireless for IBSS mode as well
141 * v0.06c -> v0.06d - 6/7/2001 - David Gibson
142 * o Change a bunch of KERN_INFO messages to KERN_DEBUG, as per Linus'
143 * wishes to reduce the number of unnecessary messages.
144 * o Removed bogus message on CRC error.
145 * o Merged fixes for v0.08 Prism 2 firmware from William Waghorn
146 * <willwaghorn AT yahoo.co.uk>
147 * o Slight cleanup/re-arrangement of firmware detection code.
149 * v0.06d -> v0.06e - 1/8/2001 - David Gibson
150 * o Removed some redundant global initializers (orinoco_cs.c).
151 * o Added some module metadata
153 * v0.06e -> v0.06f - 14/8/2001 - David Gibson
154 * o Wording fix to license
155 * o Added a 'use_alternate_encaps' module parameter for APs which need an
156 * oui of 00:00:00. We really need a better way of handling this, but
157 * the module flag is better than nothing for now.
159 * v0.06f -> v0.07 - 20/8/2001 - David Gibson
160 * o Removed BAP error retries from hermes_bap_seek(). For Tx we now
161 * let the upper layers handle the retry, we retry explicitly in the
162 * Rx path, but don't make as much noise about it.
163 * o Firmware detection cleanups.
165 * v0.07 -> v0.07a - 1/10/3001 - Jean II
166 * o Add code to read Symbol firmware revision, inspired by latest code
167 * in Spectrum24 by Lee John Keyser-Allen - Thanks Lee !
168 * o Thanks to Jared Valentine <hidden AT xmission.com> for "providing" me
169 * a 3Com card with a recent firmware, fill out Symbol firmware
170 * capabilities of latest rev (2.20), as well as older Symbol cards.
171 * o Disable Power Management in newer Symbol firmware, the API
172 * has changed (documentation needed).
174 * v0.07a -> v0.08 - 3/10/2001 - David Gibson
175 * o Fixed a possible buffer overrun found by the Stanford checker (in
176 * dldwd_ioctl_setiwencode()). Can only be called by root anyway, so not
177 * a big problem.
178 * o Turned has_big_wep on for Intersil cards. That's not true for all of
179 * them but we should at least let the capable ones try.
180 * o Wait for BUSY to clear at the beginning of hermes_bap_seek(). I
181 * realized that my assumption that the driver's serialization
182 * would prevent the BAP being busy on entry was possibly false, because
183 * things other than seeks may make the BAP busy.
184 * o Use "alternate" (oui 00:00:00) encapsulation by default.
185 * Setting use_old_encaps will mimic the old behaviour, but I think we
186 * will be able to eliminate this.
187 * o Don't try to make __initdata const (the version string). This can't
188 * work because of the way the __initdata sectioning works.
189 * o Added MODULE_LICENSE tags.
190 * o Support for PLX (transparent PCMCIA->PCI bridge) cards.
191 * o Changed to using the new type-fascist min/max.
193 * v0.08 -> v0.08a - 9/10/2001 - David Gibson
194 * o Inserted some missing acknowledgements/info into the Changelog.
195 * o Fixed some bugs in the normalization of signal level reporting.
196 * o Fixed bad bug in WEP key handling on Intersil and Symbol firmware,
197 * which led to an instant crash on big-endian machines.
199 * v0.08a -> v0.08b - 20/11/2001 - David Gibson
200 * o Lots of cleanup and bugfixes in orinoco_plx.c
201 * o Cleanup to handling of Tx rate setting.
202 * o Removed support for old encapsulation method.
203 * o Removed old "dldwd" names.
204 * o Split RID constants into a new file hermes_rid.h
205 * o Renamed RID constants to match linux-wlan-ng and prism2.o
206 * o Bugfixes in hermes.c
207 * o Poke the PLX's INTCSR register, so it actually starts
208 * generating interrupts. These cards might actually work now.
209 * o Update to wireless extensions v12 (Jean II)
210 * o Support for tallies and inquire command (Jean II)
211 * o Airport updates for newer PPC kernels (BenH)
213 * v0.08b -> v0.09 - 21/12/2001 - David Gibson
214 * o Some new PCI IDs for PLX cards.
215 * o Removed broken attempt to do ALLMULTI reception. Just use
216 * promiscuous mode instead
217 * o Preliminary work for list-AP (Jean II)
218 * o Airport updates from (BenH)
219 * o Eliminated racy hw_ready stuff
220 * o Fixed generation of fake events in irq handler. This should
221 * finally kill the EIO problems (Jean II & dgibson)
222 * o Fixed breakage of bitrate set/get on Agere firmware (Jean II)
224 * v0.09 -> v0.09a - 2/1/2002 - David Gibson
225 * o Fixed stupid mistake in multicast list handling, triggering
226 * a BUG()
228 * v0.09a -> v0.09b - 16/1/2002 - David Gibson
229 * o Fixed even stupider mistake in new interrupt handling, which
230 * seriously broke things on big-endian machines.
231 * o Removed a bunch of redundant includes and exports.
232 * o Removed a redundant MOD_{INC,DEC}_USE_COUNT pair in airport.c
233 * o Don't attempt to do hardware level multicast reception on
234 * Intersil firmware, just go promisc instead.
235 * o Typo fixed in hermes_issue_cmd()
236 * o Eliminated WIRELESS_SPY #ifdefs
237 * o Status code reported on Tx exceptions
238 * o Moved netif_wake_queue() from ALLOC interrupts to TX and TXEXC
239 * interrupts, which should fix the timeouts we're seeing.
241 * v0.09b -> v0.10 - 25 Feb 2002 - David Gibson
242 * o Removed nested structures used for header parsing, so the
243 * driver should now work without hackery on ARM
244 * o Fix for WEP handling on Intersil (Hawk Newton)
245 * o Eliminated the /proc/hermes/ethXX/regs debugging file. It
246 * was never very useful.
247 * o Make Rx errors less noisy.
249 * v0.10 -> v0.11 - 5 Apr 2002 - David Gibson
250 * o Laid the groundwork in hermes.[ch] for devices which map
251 * into PCI memory space rather than IO space.
252 * o Fixed bug in multicast handling (cleared multicast list when
253 * leaving promiscuous mode).
254 * o Relegated Tx error messages to debug.
255 * o Cleaned up / corrected handling of allocation lengths.
256 * o Set OWNSSID in IBSS mode for WinXP interoperability (jimc).
257 * o Change to using alloc_etherdev() for structure allocations.
258 * o Check for and drop undersized packets.
259 * o Fixed a race in stopping/waking the queue. This should fix
260 * the timeout problems (Pavel Roskin)
261 * o Reverted to netif_wake_queue() on the ALLOC event.
262 * o Fixes for recent Symbol firmwares which lack AP density
263 * (Pavel Roskin).
265 * v0.11 -> v0.11a - 29 Apr 2002 - David Gibson
266 * o Handle different register spacing, necessary for Prism 2.5
267 * PCI adaptors (Steve Hill).
268 * o Cleaned up initialization of card structures in orinoco_cs
269 * and airport. Removed card->priv field.
270 * o Make response structure optional for hermes_docmd_wait()
271 * Pavel Roskin)
272 * o Added PCI id for Nortel emobility to orinoco_plx.c.
273 * o Cleanup to handling of Symbol's allocation bug. (Pavel Roskin)
274 * o Cleanups to firmware capability detection.
275 * o Arrange for orinoco_pci.c to override firmware detection.
276 * We should be able to support the PCI Intersil cards now.
277 * o Cleanup handling of reset_cor and hard_reset (Pavel Roskin).
278 * o Remove erroneous use of USER_BAP in the TxExc handler (Jouni
279 * Malinen).
280 * o Makefile changes for better integration into David Hinds
281 * pcmcia-cs package.
283 * v0.11a -> v0.11b - 1 May 2002 - David Gibson
284 * o Better error reporting in orinoco_plx_init_one()
285 * o Fixed multiple bad kfree() bugs introduced by the
286 * alloc_orinocodev() changes.
288 * v0.11b -> v0.12 - 19 Jun 2002 - David Gibson
289 * o Support changing the MAC address.
290 * o Correct display of Intersil firmware revision numbers.
291 * o Entirely revised locking scheme. Should be both simpler and
292 * better.
293 * o Merged some common code in orinoco_plx, orinoco_pci and
294 * airport by creating orinoco_default_{open,stop,reset}()
295 * which are used as the dev->open, dev->stop, priv->reset
296 * callbacks if none are specified when alloc_orinocodev() is
297 * called.
298 * o Removed orinoco_plx_interrupt() and orinoco_pci_interrupt().
299 * They didn't do anything.
301 * v0.12 -> v0.12a - 4 Jul 2002 - David Gibson
302 * o Some rearrangement of code.
303 * o Numerous fixups to locking and rest handling, particularly
304 * for PCMCIA.
305 * o This allows open and stop net_device methods to be in
306 * orinoco.c now, rather than in the init modules.
307 * o In orinoco_cs.c link->priv now points to the struct
308 * net_device not to the struct orinoco_private.
309 * o Added a check for undersized SNAP frames, which could cause
310 * crashes.
312 * v0.12a -> v0.12b - 11 Jul 2002 - David Gibson
313 * o Fix hw->num_init testing code, so num_init is actually
314 * incremented.
315 * o Fix very stupid bug in orinoco_cs which broke compile with
316 * CONFIG_SMP.
317 * o Squashed a warning.
319 * v0.12b -> v0.12c - 26 Jul 2002 - David Gibson
320 * o Change to C9X style designated initializers.
321 * o Add support for 3Com AirConnect PCI.
322 * o No longer ignore the hard_reset argument to
323 * alloc_orinocodev(). Oops.
325 * v0.12c -> v0.13beta1 - 13 Sep 2002 - David Gibson
326 * o Revert the broken 0.12* locking scheme and go to a new yet
327 * simpler scheme.
328 * o Do firmware resets only in orinoco_init() and when waking
329 * the card from hard sleep.
331 * v0.13beta1 -> v0.13 - 27 Sep 2002 - David Gibson
332 * o Re-introduced full resets (via schedule_task()) on Tx
333 * timeout.
335 * v0.13 -> v0.13a - 30 Sep 2002 - David Gibson
336 * o Minor cleanups to info frame handling. Add basic support
337 * for linkstatus info frames.
338 * o Include required kernel headers in orinoco.h, to avoid
339 * compile problems.
341 * v0.13a -> v0.13b - 10 Feb 2003 - David Gibson
342 * o Implemented hard reset for Airport cards
343 * o Experimental suspend/resume implementation for orinoco_pci
344 * o Abolished /proc debugging support, replaced with a debugging
345 * iwpriv. Now it's ugly and simple instead of ugly and complex.
346 * o Bugfix in hermes.c if the firmware returned a record length
347 * of 0, we could go clobbering memory.
348 * o Bugfix in orinoco_stop() - it used to fail if hw_unavailable
349 * was set, which was usually true on PCMCIA hot removes.
350 * o Track LINKSTATUS messages, silently drop Tx packets before
351 * we are connected (avoids confusing the firmware), and only
352 * give LINKSTATUS printk()s if the status has changed.
354 * v0.13b -> v0.13c - 11 Mar 2003 - David Gibson
355 * o Cleanup: use dev instead of priv in various places.
356 * o Bug fix: Don't ReleaseConfiguration on RESET_PHYSICAL event
357 * if we're in the middle of a (driver initiated) hard reset.
358 * o Bug fix: ETH_ZLEN is supposed to include the header
359 * (Dionysus Blazakis & Manish Karir)
360 * o Convert to using workqueues instead of taskqueues (and
361 * backwards compatibility macros for pre 2.5.41 kernels).
362 * o Drop redundant (I think...) MOD_{INC,DEC}_USE_COUNT in
363 * airport.c
364 * o New orinoco_tmd.c init module from Joerg Dorchain for
365 * TMD7160 based PCI to PCMCIA bridges (similar to
366 * orinoco_plx.c).
368 * v0.13c -> v0.13d - 22 Apr 2003 - David Gibson
369 * o Make hw_unavailable a counter, rather than just a flag, this
370 * is necessary to avoid some races (such as a card being
371 * removed in the middle of orinoco_reset().
372 * o Restore Release/RequestConfiguration in the PCMCIA event handler
373 * when dealing with a driver initiated hard reset. This is
374 * necessary to prevent hangs due to a spurious interrupt while
375 * the reset is in progress.
376 * o Clear the 802.11 header when transmitting, even though we
377 * don't use it. This fixes a long standing bug on some
378 * firmwares, which seem to get confused if that isn't done.
379 * o Be less eager to de-encapsulate SNAP frames, only do so if
380 * the OUI is 00:00:00 or 00:00:f8, leave others alone. The old
381 * behaviour broke CDP (Cisco Discovery Protocol).
382 * o Use dev instead of priv for free_irq() as well as
383 * request_irq() (oops).
384 * o Attempt to reset rather than giving up if we get too many
385 * IRQs.
386 * o Changed semantics of __orinoco_down() so it can be called
387 * safely with hw_unavailable set. It also now clears the
388 * linkstatus (since we're going to have to reassociate).
390 * v0.13d -> v0.13e - 12 May 2003 - David Gibson
391 * o Support for post-2.5.68 return values from irq handler.
392 * o Fixed bug where underlength packets would be double counted
393 * in the rx_dropped statistics.
394 * o Provided a module parameter to suppress linkstatus messages.
396 * v0.13e -> v0.14alpha1 - 30 Sep 2003 - David Gibson
397 * o Replaced priv->connected logic with netif_carrier_on/off()
398 * calls.
399 * o Remove has_ibss_any and never set the CREATEIBSS RID when
400 * the ESSID is empty. Too many firmwares break if we do.
401 * o 2.6 merges: Replace pdev->slot_name with pci_name(), remove
402 * __devinitdata from PCI ID tables, use free_netdev().
403 * o Enabled shared-key authentication for Agere firmware (from
404 * Robert J. Moore <Robert.J.Moore AT allanbank.com>
405 * o Move netif_wake_queue() (back) to the Tx completion from the
406 * ALLOC event. This seems to prevent/mitigate the rolling
407 * error -110 problems at least on some Intersil firmwares.
408 * Theoretically reduces performance, but I can't measure it.
409 * Patch from Andrew Tridgell <tridge AT samba.org>
411 * v0.14alpha1 -> v0.14alpha2 - 20 Oct 2003 - David Gibson
412 * o Correctly turn off shared-key authentication when requested
413 * (bugfix from Robert J. Moore).
414 * o Correct airport sleep interfaces for current 2.6 kernels.
415 * o Add code for key change without disabling/enabling the MAC
416 * port. This is supposed to allow 802.1x to work sanely, but
417 * doesn't seem to yet.
419 * TODO
420 * o New wireless extensions API (patch from Moustafa
421 * Youssef, updated by Jim Carter and Pavel Roskin).
422 * o Handle de-encapsulation within network layer, provide 802.11
423 * headers (patch from Thomas 'Dent' Mirlacher)
424 * o RF monitor mode support
425 * o Fix possible races in SPY handling.
426 * o Disconnect wireless extensions from fundamental configuration.
427 * o (maybe) Software WEP support (patch from Stano Meduna).
428 * o (maybe) Use multiple Tx buffers - driver handling queue
429 * rather than firmware.
432 /* Locking and synchronization:
434 * The basic principle is that everything is serialized through a
435 * single spinlock, priv->lock. The lock is used in user, bh and irq
436 * context, so when taken outside hardirq context it should always be
437 * taken with interrupts disabled. The lock protects both the
438 * hardware and the struct orinoco_private.
440 * Another flag, priv->hw_unavailable indicates that the hardware is
441 * unavailable for an extended period of time (e.g. suspended, or in
442 * the middle of a hard reset). This flag is protected by the
443 * spinlock. All code which touches the hardware should check the
444 * flag after taking the lock, and if it is set, give up on whatever
445 * they are doing and drop the lock again. The orinoco_lock()
446 * function handles this (it unlocks and returns -EBUSY if
447 * hw_unavailable is non-zero).
450 #define DRIVER_NAME "orinoco"
452 #include <linux/config.h>
454 #include <linux/module.h>
455 #include <linux/kernel.h>
456 #include <linux/init.h>
457 #include <linux/ptrace.h>
458 #include <linux/slab.h>
459 #include <linux/string.h>
460 #include <linux/timer.h>
461 #include <linux/ioport.h>
462 #include <linux/netdevice.h>
463 #include <linux/if_arp.h>
464 #include <linux/etherdevice.h>
465 #include <linux/wireless.h>
467 #include <asm/uaccess.h>
468 #include <asm/io.h>
469 #include <asm/system.h>
471 #include "hermes.h"
472 #include "hermes_rid.h"
473 #include "orinoco.h"
474 #include "ieee802_11.h"
476 /********************************************************************/
477 /* Module information */
478 /********************************************************************/
480 MODULE_AUTHOR("Pavel Roskin <proski@gnu.org> & David Gibson <hermes@gibson.dropbear.id.au>");
481 MODULE_DESCRIPTION("Driver for Lucent Orinoco, Prism II based and similar wireless cards");
482 MODULE_LICENSE("Dual MPL/GPL");
484 /* Level of debugging. Used in the macros in orinoco.h */
485 #ifdef ORINOCO_DEBUG
486 int orinoco_debug = ORINOCO_DEBUG;
487 module_param(orinoco_debug, int, 0644);
488 MODULE_PARM_DESC(orinoco_debug, "Debug level");
489 EXPORT_SYMBOL(orinoco_debug);
490 #endif
492 static int suppress_linkstatus; /* = 0 */
493 module_param(suppress_linkstatus, bool, 0644);
494 MODULE_PARM_DESC(suppress_linkstatus, "Don't log link status changes");
496 /********************************************************************/
497 /* Compile time configuration and compatibility stuff */
498 /********************************************************************/
500 /* We do this this way to avoid ifdefs in the actual code */
501 #ifdef WIRELESS_SPY
502 #define SPY_NUMBER(priv) (priv->spy_number)
503 #else
504 #define SPY_NUMBER(priv) 0
505 #endif /* WIRELESS_SPY */
507 /********************************************************************/
508 /* Internal constants */
509 /********************************************************************/
511 #define ORINOCO_MIN_MTU 256
512 #define ORINOCO_MAX_MTU (IEEE802_11_DATA_LEN - ENCAPS_OVERHEAD)
514 #define SYMBOL_MAX_VER_LEN (14)
515 #define USER_BAP 0
516 #define IRQ_BAP 1
517 #define MAX_IRQLOOPS_PER_IRQ 10
518 #define MAX_IRQLOOPS_PER_JIFFY (20000/HZ) /* Based on a guestimate of
519 * how many events the
520 * device could
521 * legitimately generate */
522 #define SMALL_KEY_SIZE 5
523 #define LARGE_KEY_SIZE 13
524 #define TX_NICBUF_SIZE_BUG 1585 /* Bug in Symbol firmware */
526 #define DUMMY_FID 0xFFFF
528 /*#define MAX_MULTICAST(priv) (priv->firmware_type == FIRMWARE_TYPE_AGERE ? \
529 HERMES_MAX_MULTICAST : 0)*/
530 #define MAX_MULTICAST(priv) (HERMES_MAX_MULTICAST)
532 #define ORINOCO_INTEN (HERMES_EV_RX | HERMES_EV_ALLOC \
533 | HERMES_EV_TX | HERMES_EV_TXEXC \
534 | HERMES_EV_WTERR | HERMES_EV_INFO \
535 | HERMES_EV_INFDROP )
537 /********************************************************************/
538 /* Data tables */
539 /********************************************************************/
541 /* The frequency of each channel in MHz */
542 static const long channel_frequency[] = {
543 2412, 2417, 2422, 2427, 2432, 2437, 2442,
544 2447, 2452, 2457, 2462, 2467, 2472, 2484
546 #define NUM_CHANNELS ARRAY_SIZE(channel_frequency)
548 /* This tables gives the actual meanings of the bitrate IDs returned
549 * by the firmware. */
550 static struct {
551 int bitrate; /* in 100s of kilobits */
552 int automatic;
553 u16 agere_txratectrl;
554 u16 intersil_txratectrl;
555 } bitrate_table[] = {
556 {110, 1, 3, 15}, /* Entry 0 is the default */
557 {10, 0, 1, 1},
558 {10, 1, 1, 1},
559 {20, 0, 2, 2},
560 {20, 1, 6, 3},
561 {55, 0, 4, 4},
562 {55, 1, 7, 7},
563 {110, 0, 5, 8},
565 #define BITRATE_TABLE_SIZE ARRAY_SIZE(bitrate_table)
567 /********************************************************************/
568 /* Data types */
569 /********************************************************************/
571 struct header_struct {
572 /* 802.3 */
573 u8 dest[ETH_ALEN];
574 u8 src[ETH_ALEN];
575 u16 len;
576 /* 802.2 */
577 u8 dsap;
578 u8 ssap;
579 u8 ctrl;
580 /* SNAP */
581 u8 oui[3];
582 u16 ethertype;
583 } __attribute__ ((packed));
585 /* 802.2 LLC/SNAP header used for Ethernet encapsulation over 802.11 */
586 u8 encaps_hdr[] = {0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00};
588 #define ENCAPS_OVERHEAD (sizeof(encaps_hdr) + 2)
590 struct hermes_rx_descriptor {
591 u16 status;
592 u32 time;
593 u8 silence;
594 u8 signal;
595 u8 rate;
596 u8 rxflow;
597 u32 reserved;
598 } __attribute__ ((packed));
600 /********************************************************************/
601 /* Function prototypes */
602 /********************************************************************/
604 static int orinoco_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
605 static int __orinoco_program_rids(struct net_device *dev);
606 static void __orinoco_set_multicast_list(struct net_device *dev);
607 static int orinoco_debug_dump_recs(struct net_device *dev);
609 /********************************************************************/
610 /* Internal helper functions */
611 /********************************************************************/
613 static inline void set_port_type(struct orinoco_private *priv)
615 switch (priv->iw_mode) {
616 case IW_MODE_INFRA:
617 priv->port_type = 1;
618 priv->createibss = 0;
619 break;
620 case IW_MODE_ADHOC:
621 if (priv->prefer_port3) {
622 priv->port_type = 3;
623 priv->createibss = 0;
624 } else {
625 priv->port_type = priv->ibss_port;
626 priv->createibss = 1;
628 break;
629 default:
630 printk(KERN_ERR "%s: Invalid priv->iw_mode in set_port_type()\n",
631 priv->ndev->name);
635 /********************************************************************/
636 /* Device methods */
637 /********************************************************************/
639 static int orinoco_open(struct net_device *dev)
641 struct orinoco_private *priv = netdev_priv(dev);
642 unsigned long flags;
643 int err;
645 if (orinoco_lock(priv, &flags) != 0)
646 return -EBUSY;
648 err = __orinoco_up(dev);
650 if (! err)
651 priv->open = 1;
653 orinoco_unlock(priv, &flags);
655 return err;
658 int orinoco_stop(struct net_device *dev)
660 struct orinoco_private *priv = netdev_priv(dev);
661 int err = 0;
663 /* We mustn't use orinoco_lock() here, because we need to be
664 able to close the interface even if hw_unavailable is set
665 (e.g. as we're released after a PC Card removal) */
666 spin_lock_irq(&priv->lock);
668 priv->open = 0;
670 err = __orinoco_down(dev);
672 spin_unlock_irq(&priv->lock);
674 return err;
677 static struct net_device_stats *orinoco_get_stats(struct net_device *dev)
679 struct orinoco_private *priv = netdev_priv(dev);
681 return &priv->stats;
684 static struct iw_statistics *orinoco_get_wireless_stats(struct net_device *dev)
686 struct orinoco_private *priv = netdev_priv(dev);
687 hermes_t *hw = &priv->hw;
688 struct iw_statistics *wstats = &priv->wstats;
689 int err = 0;
690 unsigned long flags;
692 if (! netif_device_present(dev)) {
693 printk(KERN_WARNING "%s: get_wireless_stats() called while device not present\n",
694 dev->name);
695 return NULL; /* FIXME: Can we do better than this? */
698 if (orinoco_lock(priv, &flags) != 0)
699 return NULL; /* FIXME: Erg, we've been signalled, how
700 * do we propagate this back up? */
702 if (priv->iw_mode == IW_MODE_ADHOC) {
703 memset(&wstats->qual, 0, sizeof(wstats->qual));
704 /* If a spy address is defined, we report stats of the
705 * first spy address - Jean II */
706 if (SPY_NUMBER(priv)) {
707 wstats->qual.qual = priv->spy_stat[0].qual;
708 wstats->qual.level = priv->spy_stat[0].level;
709 wstats->qual.noise = priv->spy_stat[0].noise;
710 wstats->qual.updated = priv->spy_stat[0].updated;
712 } else {
713 struct {
714 u16 qual, signal, noise;
715 } __attribute__ ((packed)) cq;
717 err = HERMES_READ_RECORD(hw, USER_BAP,
718 HERMES_RID_COMMSQUALITY, &cq);
720 wstats->qual.qual = (int)le16_to_cpu(cq.qual);
721 wstats->qual.level = (int)le16_to_cpu(cq.signal) - 0x95;
722 wstats->qual.noise = (int)le16_to_cpu(cq.noise) - 0x95;
723 wstats->qual.updated = 7;
726 /* We can't really wait for the tallies inquiry command to
727 * complete, so we just use the previous results and trigger
728 * a new tallies inquiry command for next time - Jean II */
729 /* FIXME: We're in user context (I think?), so we should just
730 wait for the tallies to come through */
731 err = hermes_inquire(hw, HERMES_INQ_TALLIES);
733 orinoco_unlock(priv, &flags);
735 if (err)
736 return NULL;
738 return wstats;
741 static void orinoco_set_multicast_list(struct net_device *dev)
743 struct orinoco_private *priv = netdev_priv(dev);
744 unsigned long flags;
746 if (orinoco_lock(priv, &flags) != 0) {
747 printk(KERN_DEBUG "%s: orinoco_set_multicast_list() "
748 "called when hw_unavailable\n", dev->name);
749 return;
752 __orinoco_set_multicast_list(dev);
753 orinoco_unlock(priv, &flags);
756 static int orinoco_change_mtu(struct net_device *dev, int new_mtu)
758 struct orinoco_private *priv = netdev_priv(dev);
760 if ( (new_mtu < ORINOCO_MIN_MTU) || (new_mtu > ORINOCO_MAX_MTU) )
761 return -EINVAL;
763 if ( (new_mtu + ENCAPS_OVERHEAD + IEEE802_11_HLEN) >
764 (priv->nicbuf_size - ETH_HLEN) )
765 return -EINVAL;
767 dev->mtu = new_mtu;
769 return 0;
772 /********************************************************************/
773 /* Tx path */
774 /********************************************************************/
776 static int orinoco_xmit(struct sk_buff *skb, struct net_device *dev)
778 struct orinoco_private *priv = netdev_priv(dev);
779 struct net_device_stats *stats = &priv->stats;
780 hermes_t *hw = &priv->hw;
781 int err = 0;
782 u16 txfid = priv->txfid;
783 char *p;
784 struct ethhdr *eh;
785 int len, data_len, data_off;
786 struct hermes_tx_descriptor desc;
787 unsigned long flags;
789 TRACE_ENTER(dev->name);
791 if (! netif_running(dev)) {
792 printk(KERN_ERR "%s: Tx on stopped device!\n",
793 dev->name);
794 TRACE_EXIT(dev->name);
795 return 1;
798 if (netif_queue_stopped(dev)) {
799 printk(KERN_DEBUG "%s: Tx while transmitter busy!\n",
800 dev->name);
801 TRACE_EXIT(dev->name);
802 return 1;
805 if (orinoco_lock(priv, &flags) != 0) {
806 printk(KERN_ERR "%s: orinoco_xmit() called while hw_unavailable\n",
807 dev->name);
808 TRACE_EXIT(dev->name);
809 return 1;
812 if (! netif_carrier_ok(dev)) {
813 /* Oops, the firmware hasn't established a connection,
814 silently drop the packet (this seems to be the
815 safest approach). */
816 stats->tx_errors++;
817 orinoco_unlock(priv, &flags);
818 dev_kfree_skb(skb);
819 TRACE_EXIT(dev->name);
820 return 0;
823 /* Length of the packet body */
824 /* FIXME: what if the skb is smaller than this? */
825 len = max_t(int,skb->len - ETH_HLEN, ETH_ZLEN - ETH_HLEN);
827 eh = (struct ethhdr *)skb->data;
829 memset(&desc, 0, sizeof(desc));
830 desc.tx_control = cpu_to_le16(HERMES_TXCTRL_TX_OK | HERMES_TXCTRL_TX_EX);
831 err = hermes_bap_pwrite(hw, USER_BAP, &desc, sizeof(desc), txfid, 0);
832 if (err) {
833 if (net_ratelimit())
834 printk(KERN_ERR "%s: Error %d writing Tx descriptor "
835 "to BAP\n", dev->name, err);
836 stats->tx_errors++;
837 goto fail;
840 /* Clear the 802.11 header and data length fields - some
841 * firmwares (e.g. Lucent/Agere 8.xx) appear to get confused
842 * if this isn't done. */
843 hermes_clear_words(hw, HERMES_DATA0,
844 HERMES_802_3_OFFSET - HERMES_802_11_OFFSET);
846 /* Encapsulate Ethernet-II frames */
847 if (ntohs(eh->h_proto) > ETH_DATA_LEN) { /* Ethernet-II frame */
848 struct header_struct hdr;
849 data_len = len;
850 data_off = HERMES_802_3_OFFSET + sizeof(hdr);
851 p = skb->data + ETH_HLEN;
853 /* 802.3 header */
854 memcpy(hdr.dest, eh->h_dest, ETH_ALEN);
855 memcpy(hdr.src, eh->h_source, ETH_ALEN);
856 hdr.len = htons(data_len + ENCAPS_OVERHEAD);
858 /* 802.2 header */
859 memcpy(&hdr.dsap, &encaps_hdr, sizeof(encaps_hdr));
861 hdr.ethertype = eh->h_proto;
862 err = hermes_bap_pwrite(hw, USER_BAP, &hdr, sizeof(hdr),
863 txfid, HERMES_802_3_OFFSET);
864 if (err) {
865 if (net_ratelimit())
866 printk(KERN_ERR "%s: Error %d writing packet "
867 "header to BAP\n", dev->name, err);
868 stats->tx_errors++;
869 goto fail;
871 } else { /* IEEE 802.3 frame */
872 data_len = len + ETH_HLEN;
873 data_off = HERMES_802_3_OFFSET;
874 p = skb->data;
877 /* Round up for odd length packets */
878 err = hermes_bap_pwrite(hw, USER_BAP, p, ALIGN(data_len, 2),
879 txfid, data_off);
880 if (err) {
881 printk(KERN_ERR "%s: Error %d writing packet to BAP\n",
882 dev->name, err);
883 stats->tx_errors++;
884 goto fail;
887 /* Finally, we actually initiate the send */
888 netif_stop_queue(dev);
890 err = hermes_docmd_wait(hw, HERMES_CMD_TX | HERMES_CMD_RECL,
891 txfid, NULL);
892 if (err) {
893 netif_start_queue(dev);
894 printk(KERN_ERR "%s: Error %d transmitting packet\n",
895 dev->name, err);
896 stats->tx_errors++;
897 goto fail;
900 dev->trans_start = jiffies;
901 stats->tx_bytes += data_off + data_len;
903 orinoco_unlock(priv, &flags);
905 dev_kfree_skb(skb);
907 TRACE_EXIT(dev->name);
909 return 0;
910 fail:
911 TRACE_EXIT(dev->name);
913 orinoco_unlock(priv, &flags);
914 return err;
917 static void __orinoco_ev_alloc(struct net_device *dev, hermes_t *hw)
919 struct orinoco_private *priv = netdev_priv(dev);
920 u16 fid = hermes_read_regn(hw, ALLOCFID);
922 if (fid != priv->txfid) {
923 if (fid != DUMMY_FID)
924 printk(KERN_WARNING "%s: Allocate event on unexpected fid (%04X)\n",
925 dev->name, fid);
926 return;
929 hermes_write_regn(hw, ALLOCFID, DUMMY_FID);
932 static void __orinoco_ev_tx(struct net_device *dev, hermes_t *hw)
934 struct orinoco_private *priv = netdev_priv(dev);
935 struct net_device_stats *stats = &priv->stats;
937 stats->tx_packets++;
939 netif_wake_queue(dev);
941 hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
944 static void __orinoco_ev_txexc(struct net_device *dev, hermes_t *hw)
946 struct orinoco_private *priv = netdev_priv(dev);
947 struct net_device_stats *stats = &priv->stats;
948 u16 fid = hermes_read_regn(hw, TXCOMPLFID);
949 struct hermes_tx_descriptor desc;
950 int err = 0;
952 if (fid == DUMMY_FID)
953 return; /* Nothing's really happened */
955 err = hermes_bap_pread(hw, IRQ_BAP, &desc, sizeof(desc), fid, 0);
956 if (err) {
957 printk(KERN_WARNING "%s: Unable to read descriptor on Tx error "
958 "(FID=%04X error %d)\n",
959 dev->name, fid, err);
960 } else {
961 DEBUG(1, "%s: Tx error, status %d\n",
962 dev->name, le16_to_cpu(desc.status));
965 stats->tx_errors++;
967 netif_wake_queue(dev);
968 hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
971 static void orinoco_tx_timeout(struct net_device *dev)
973 struct orinoco_private *priv = netdev_priv(dev);
974 struct net_device_stats *stats = &priv->stats;
975 struct hermes *hw = &priv->hw;
977 printk(KERN_WARNING "%s: Tx timeout! "
978 "ALLOCFID=%04x, TXCOMPLFID=%04x, EVSTAT=%04x\n",
979 dev->name, hermes_read_regn(hw, ALLOCFID),
980 hermes_read_regn(hw, TXCOMPLFID), hermes_read_regn(hw, EVSTAT));
982 stats->tx_errors++;
984 schedule_work(&priv->reset_work);
987 /********************************************************************/
988 /* Rx path (data frames) */
989 /********************************************************************/
991 /* Does the frame have a SNAP header indicating it should be
992 * de-encapsulated to Ethernet-II? */
993 static inline int is_ethersnap(void *_hdr)
995 u8 *hdr = _hdr;
997 /* We de-encapsulate all packets which, a) have SNAP headers
998 * (i.e. SSAP=DSAP=0xaa and CTRL=0x3 in the 802.2 LLC header
999 * and where b) the OUI of the SNAP header is 00:00:00 or
1000 * 00:00:f8 - we need both because different APs appear to use
1001 * different OUIs for some reason */
1002 return (memcmp(hdr, &encaps_hdr, 5) == 0)
1003 && ( (hdr[5] == 0x00) || (hdr[5] == 0xf8) );
1006 static inline void orinoco_spy_gather(struct net_device *dev, u_char *mac,
1007 int level, int noise)
1009 struct orinoco_private *priv = netdev_priv(dev);
1010 int i;
1012 /* Gather wireless spy statistics: for each packet, compare the
1013 * source address with out list, and if match, get the stats... */
1014 for (i = 0; i < priv->spy_number; i++)
1015 if (!memcmp(mac, priv->spy_address[i], ETH_ALEN)) {
1016 priv->spy_stat[i].level = level - 0x95;
1017 priv->spy_stat[i].noise = noise - 0x95;
1018 priv->spy_stat[i].qual = (level > noise) ? (level - noise) : 0;
1019 priv->spy_stat[i].updated = 7;
1023 static void orinoco_stat_gather(struct net_device *dev,
1024 struct sk_buff *skb,
1025 struct hermes_rx_descriptor *desc)
1027 struct orinoco_private *priv = netdev_priv(dev);
1029 /* Using spy support with lots of Rx packets, like in an
1030 * infrastructure (AP), will really slow down everything, because
1031 * the MAC address must be compared to each entry of the spy list.
1032 * If the user really asks for it (set some address in the
1033 * spy list), we do it, but he will pay the price.
1034 * Note that to get here, you need both WIRELESS_SPY
1035 * compiled in AND some addresses in the list !!!
1037 /* Note : gcc will optimise the whole section away if
1038 * WIRELESS_SPY is not defined... - Jean II */
1039 if (SPY_NUMBER(priv)) {
1040 orinoco_spy_gather(dev, skb->mac.raw + ETH_ALEN,
1041 desc->signal, desc->silence);
1045 static void __orinoco_ev_rx(struct net_device *dev, hermes_t *hw)
1047 struct orinoco_private *priv = netdev_priv(dev);
1048 struct net_device_stats *stats = &priv->stats;
1049 struct iw_statistics *wstats = &priv->wstats;
1050 struct sk_buff *skb = NULL;
1051 u16 rxfid, status;
1052 int length, data_len, data_off;
1053 char *p;
1054 struct hermes_rx_descriptor desc;
1055 struct header_struct hdr;
1056 struct ethhdr *eh;
1057 int err;
1059 rxfid = hermes_read_regn(hw, RXFID);
1061 err = hermes_bap_pread(hw, IRQ_BAP, &desc, sizeof(desc),
1062 rxfid, 0);
1063 if (err) {
1064 printk(KERN_ERR "%s: error %d reading Rx descriptor. "
1065 "Frame dropped.\n", dev->name, err);
1066 stats->rx_errors++;
1067 goto drop;
1070 status = le16_to_cpu(desc.status);
1072 if (status & HERMES_RXSTAT_ERR) {
1073 if (status & HERMES_RXSTAT_UNDECRYPTABLE) {
1074 wstats->discard.code++;
1075 DEBUG(1, "%s: Undecryptable frame on Rx. Frame dropped.\n",
1076 dev->name);
1077 } else {
1078 stats->rx_crc_errors++;
1079 DEBUG(1, "%s: Bad CRC on Rx. Frame dropped.\n", dev->name);
1081 stats->rx_errors++;
1082 goto drop;
1085 /* For now we ignore the 802.11 header completely, assuming
1086 that the card's firmware has handled anything vital */
1088 err = hermes_bap_pread(hw, IRQ_BAP, &hdr, sizeof(hdr),
1089 rxfid, HERMES_802_3_OFFSET);
1090 if (err) {
1091 printk(KERN_ERR "%s: error %d reading frame header. "
1092 "Frame dropped.\n", dev->name, err);
1093 stats->rx_errors++;
1094 goto drop;
1097 length = ntohs(hdr.len);
1099 /* Sanity checks */
1100 if (length < 3) { /* No for even an 802.2 LLC header */
1101 /* At least on Symbol firmware with PCF we get quite a
1102 lot of these legitimately - Poll frames with no
1103 data. */
1104 stats->rx_dropped++;
1105 goto drop;
1107 if (length > IEEE802_11_DATA_LEN) {
1108 printk(KERN_WARNING "%s: Oversized frame received (%d bytes)\n",
1109 dev->name, length);
1110 stats->rx_length_errors++;
1111 stats->rx_errors++;
1112 goto drop;
1115 /* We need space for the packet data itself, plus an ethernet
1116 header, plus 2 bytes so we can align the IP header on a
1117 32bit boundary, plus 1 byte so we can read in odd length
1118 packets from the card, which has an IO granularity of 16
1119 bits */
1120 skb = dev_alloc_skb(length+ETH_HLEN+2+1);
1121 if (!skb) {
1122 printk(KERN_WARNING "%s: Can't allocate skb for Rx\n",
1123 dev->name);
1124 goto drop;
1127 skb_reserve(skb, 2); /* This way the IP header is aligned */
1129 /* Handle decapsulation
1130 * In most cases, the firmware tell us about SNAP frames.
1131 * For some reason, the SNAP frames sent by LinkSys APs
1132 * are not properly recognised by most firmwares.
1133 * So, check ourselves */
1134 if (((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_1042) ||
1135 ((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_TUNNEL) ||
1136 is_ethersnap(&hdr)) {
1137 /* These indicate a SNAP within 802.2 LLC within
1138 802.11 frame which we'll need to de-encapsulate to
1139 the original EthernetII frame. */
1141 if (length < ENCAPS_OVERHEAD) { /* No room for full LLC+SNAP */
1142 stats->rx_length_errors++;
1143 goto drop;
1146 /* Remove SNAP header, reconstruct EthernetII frame */
1147 data_len = length - ENCAPS_OVERHEAD;
1148 data_off = HERMES_802_3_OFFSET + sizeof(hdr);
1150 eh = (struct ethhdr *)skb_put(skb, ETH_HLEN);
1152 memcpy(eh, &hdr, 2 * ETH_ALEN);
1153 eh->h_proto = hdr.ethertype;
1154 } else {
1155 /* All other cases indicate a genuine 802.3 frame. No
1156 decapsulation needed. We just throw the whole
1157 thing in, and hope the protocol layer can deal with
1158 it as 802.3 */
1159 data_len = length;
1160 data_off = HERMES_802_3_OFFSET;
1161 /* FIXME: we re-read from the card data we already read here */
1164 p = skb_put(skb, data_len);
1165 err = hermes_bap_pread(hw, IRQ_BAP, p, ALIGN(data_len, 2),
1166 rxfid, data_off);
1167 if (err) {
1168 printk(KERN_ERR "%s: error %d reading frame. "
1169 "Frame dropped.\n", dev->name, err);
1170 stats->rx_errors++;
1171 goto drop;
1174 dev->last_rx = jiffies;
1175 skb->dev = dev;
1176 skb->protocol = eth_type_trans(skb, dev);
1177 skb->ip_summed = CHECKSUM_NONE;
1179 /* Process the wireless stats if needed */
1180 orinoco_stat_gather(dev, skb, &desc);
1182 /* Pass the packet to the networking stack */
1183 netif_rx(skb);
1184 stats->rx_packets++;
1185 stats->rx_bytes += length;
1187 return;
1189 drop:
1190 stats->rx_dropped++;
1192 if (skb)
1193 dev_kfree_skb_irq(skb);
1194 return;
1197 /********************************************************************/
1198 /* Rx path (info frames) */
1199 /********************************************************************/
1201 static void print_linkstatus(struct net_device *dev, u16 status)
1203 char * s;
1205 if (suppress_linkstatus)
1206 return;
1208 switch (status) {
1209 case HERMES_LINKSTATUS_NOT_CONNECTED:
1210 s = "Not Connected";
1211 break;
1212 case HERMES_LINKSTATUS_CONNECTED:
1213 s = "Connected";
1214 break;
1215 case HERMES_LINKSTATUS_DISCONNECTED:
1216 s = "Disconnected";
1217 break;
1218 case HERMES_LINKSTATUS_AP_CHANGE:
1219 s = "AP Changed";
1220 break;
1221 case HERMES_LINKSTATUS_AP_OUT_OF_RANGE:
1222 s = "AP Out of Range";
1223 break;
1224 case HERMES_LINKSTATUS_AP_IN_RANGE:
1225 s = "AP In Range";
1226 break;
1227 case HERMES_LINKSTATUS_ASSOC_FAILED:
1228 s = "Association Failed";
1229 break;
1230 default:
1231 s = "UNKNOWN";
1234 printk(KERN_INFO "%s: New link status: %s (%04x)\n",
1235 dev->name, s, status);
1238 static void __orinoco_ev_info(struct net_device *dev, hermes_t *hw)
1240 struct orinoco_private *priv = netdev_priv(dev);
1241 u16 infofid;
1242 struct {
1243 u16 len;
1244 u16 type;
1245 } __attribute__ ((packed)) info;
1246 int len, type;
1247 int err;
1249 /* This is an answer to an INQUIRE command that we did earlier,
1250 * or an information "event" generated by the card
1251 * The controller return to us a pseudo frame containing
1252 * the information in question - Jean II */
1253 infofid = hermes_read_regn(hw, INFOFID);
1255 /* Read the info frame header - don't try too hard */
1256 err = hermes_bap_pread(hw, IRQ_BAP, &info, sizeof(info),
1257 infofid, 0);
1258 if (err) {
1259 printk(KERN_ERR "%s: error %d reading info frame. "
1260 "Frame dropped.\n", dev->name, err);
1261 return;
1264 len = HERMES_RECLEN_TO_BYTES(le16_to_cpu(info.len));
1265 type = le16_to_cpu(info.type);
1267 switch (type) {
1268 case HERMES_INQ_TALLIES: {
1269 struct hermes_tallies_frame tallies;
1270 struct iw_statistics *wstats = &priv->wstats;
1272 if (len > sizeof(tallies)) {
1273 printk(KERN_WARNING "%s: Tallies frame too long (%d bytes)\n",
1274 dev->name, len);
1275 len = sizeof(tallies);
1278 /* Read directly the data (no seek) */
1279 hermes_read_words(hw, HERMES_DATA1, (void *) &tallies,
1280 len / 2); /* FIXME: blech! */
1282 /* Increment our various counters */
1283 /* wstats->discard.nwid - no wrong BSSID stuff */
1284 wstats->discard.code +=
1285 le16_to_cpu(tallies.RxWEPUndecryptable);
1286 if (len == sizeof(tallies))
1287 wstats->discard.code +=
1288 le16_to_cpu(tallies.RxDiscards_WEPICVError) +
1289 le16_to_cpu(tallies.RxDiscards_WEPExcluded);
1290 wstats->discard.misc +=
1291 le16_to_cpu(tallies.TxDiscardsWrongSA);
1292 wstats->discard.fragment +=
1293 le16_to_cpu(tallies.RxMsgInBadMsgFragments);
1294 wstats->discard.retries +=
1295 le16_to_cpu(tallies.TxRetryLimitExceeded);
1296 /* wstats->miss.beacon - no match */
1298 break;
1299 case HERMES_INQ_LINKSTATUS: {
1300 struct hermes_linkstatus linkstatus;
1301 u16 newstatus;
1302 int connected;
1304 if (len != sizeof(linkstatus)) {
1305 printk(KERN_WARNING "%s: Unexpected size for linkstatus frame (%d bytes)\n",
1306 dev->name, len);
1307 break;
1310 hermes_read_words(hw, HERMES_DATA1, (void *) &linkstatus,
1311 len / 2);
1312 newstatus = le16_to_cpu(linkstatus.linkstatus);
1314 connected = (newstatus == HERMES_LINKSTATUS_CONNECTED)
1315 || (newstatus == HERMES_LINKSTATUS_AP_CHANGE)
1316 || (newstatus == HERMES_LINKSTATUS_AP_IN_RANGE);
1318 if (connected)
1319 netif_carrier_on(dev);
1320 else
1321 netif_carrier_off(dev);
1323 if (newstatus != priv->last_linkstatus)
1324 print_linkstatus(dev, newstatus);
1326 priv->last_linkstatus = newstatus;
1328 break;
1329 default:
1330 printk(KERN_DEBUG "%s: Unknown information frame received: "
1331 "type 0x%04x, length %d\n", dev->name, type, len);
1332 /* We don't actually do anything about it */
1333 break;
1337 static void __orinoco_ev_infdrop(struct net_device *dev, hermes_t *hw)
1339 if (net_ratelimit())
1340 printk(KERN_DEBUG "%s: Information frame lost.\n", dev->name);
1343 /********************************************************************/
1344 /* Internal hardware control routines */
1345 /********************************************************************/
1347 int __orinoco_up(struct net_device *dev)
1349 struct orinoco_private *priv = netdev_priv(dev);
1350 struct hermes *hw = &priv->hw;
1351 int err;
1353 err = __orinoco_program_rids(dev);
1354 if (err) {
1355 printk(KERN_ERR "%s: Error %d configuring card\n",
1356 dev->name, err);
1357 return err;
1360 /* Fire things up again */
1361 hermes_set_irqmask(hw, ORINOCO_INTEN);
1362 err = hermes_enable_port(hw, 0);
1363 if (err) {
1364 printk(KERN_ERR "%s: Error %d enabling MAC port\n",
1365 dev->name, err);
1366 return err;
1369 netif_start_queue(dev);
1371 return 0;
1374 int __orinoco_down(struct net_device *dev)
1376 struct orinoco_private *priv = netdev_priv(dev);
1377 struct hermes *hw = &priv->hw;
1378 int err;
1380 netif_stop_queue(dev);
1382 if (! priv->hw_unavailable) {
1383 if (! priv->broken_disableport) {
1384 err = hermes_disable_port(hw, 0);
1385 if (err) {
1386 /* Some firmwares (e.g. Intersil 1.3.x) seem
1387 * to have problems disabling the port, oh
1388 * well, too bad. */
1389 printk(KERN_WARNING "%s: Error %d disabling MAC port\n",
1390 dev->name, err);
1391 priv->broken_disableport = 1;
1394 hermes_set_irqmask(hw, 0);
1395 hermes_write_regn(hw, EVACK, 0xffff);
1398 /* firmware will have to reassociate */
1399 netif_carrier_off(dev);
1400 priv->last_linkstatus = 0xffff;
1402 return 0;
1405 int orinoco_reinit_firmware(struct net_device *dev)
1407 struct orinoco_private *priv = netdev_priv(dev);
1408 struct hermes *hw = &priv->hw;
1409 int err;
1411 err = hermes_init(hw);
1412 if (err)
1413 return err;
1415 err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
1416 if (err == -EIO) {
1417 /* Try workaround for old Symbol firmware bug */
1418 printk(KERN_WARNING "%s: firmware ALLOC bug detected "
1419 "(old Symbol firmware?). Trying to work around... ",
1420 dev->name);
1422 priv->nicbuf_size = TX_NICBUF_SIZE_BUG;
1423 err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
1424 if (err)
1425 printk("failed!\n");
1426 else
1427 printk("ok.\n");
1430 return err;
1433 static int __orinoco_hw_set_bitrate(struct orinoco_private *priv)
1435 hermes_t *hw = &priv->hw;
1436 int err = 0;
1438 if (priv->bitratemode >= BITRATE_TABLE_SIZE) {
1439 printk(KERN_ERR "%s: BUG: Invalid bitrate mode %d\n",
1440 priv->ndev->name, priv->bitratemode);
1441 return -EINVAL;
1444 switch (priv->firmware_type) {
1445 case FIRMWARE_TYPE_AGERE:
1446 err = hermes_write_wordrec(hw, USER_BAP,
1447 HERMES_RID_CNFTXRATECONTROL,
1448 bitrate_table[priv->bitratemode].agere_txratectrl);
1449 break;
1450 case FIRMWARE_TYPE_INTERSIL:
1451 case FIRMWARE_TYPE_SYMBOL:
1452 err = hermes_write_wordrec(hw, USER_BAP,
1453 HERMES_RID_CNFTXRATECONTROL,
1454 bitrate_table[priv->bitratemode].intersil_txratectrl);
1455 break;
1456 default:
1457 BUG();
1460 return err;
1463 /* Change the WEP keys and/or the current keys. Can be called
1464 * either from __orinoco_hw_setup_wep() or directly from
1465 * orinoco_ioctl_setiwencode(). In the later case the association
1466 * with the AP is not broken (if the firmware can handle it),
1467 * which is needed for 802.1x implementations. */
1468 static int __orinoco_hw_setup_wepkeys(struct orinoco_private *priv)
1470 hermes_t *hw = &priv->hw;
1471 int err = 0;
1473 switch (priv->firmware_type) {
1474 case FIRMWARE_TYPE_AGERE:
1475 err = HERMES_WRITE_RECORD(hw, USER_BAP,
1476 HERMES_RID_CNFWEPKEYS_AGERE,
1477 &priv->keys);
1478 if (err)
1479 return err;
1480 err = hermes_write_wordrec(hw, USER_BAP,
1481 HERMES_RID_CNFTXKEY_AGERE,
1482 priv->tx_key);
1483 if (err)
1484 return err;
1485 break;
1486 case FIRMWARE_TYPE_INTERSIL:
1487 case FIRMWARE_TYPE_SYMBOL:
1489 int keylen;
1490 int i;
1492 /* Force uniform key length to work around firmware bugs */
1493 keylen = le16_to_cpu(priv->keys[priv->tx_key].len);
1495 if (keylen > LARGE_KEY_SIZE) {
1496 printk(KERN_ERR "%s: BUG: Key %d has oversize length %d.\n",
1497 priv->ndev->name, priv->tx_key, keylen);
1498 return -E2BIG;
1501 /* Write all 4 keys */
1502 for(i = 0; i < ORINOCO_MAX_KEYS; i++) {
1503 err = hermes_write_ltv(hw, USER_BAP,
1504 HERMES_RID_CNFDEFAULTKEY0 + i,
1505 HERMES_BYTES_TO_RECLEN(keylen),
1506 priv->keys[i].data);
1507 if (err)
1508 return err;
1511 /* Write the index of the key used in transmission */
1512 err = hermes_write_wordrec(hw, USER_BAP,
1513 HERMES_RID_CNFWEPDEFAULTKEYID,
1514 priv->tx_key);
1515 if (err)
1516 return err;
1518 break;
1521 return 0;
1524 static int __orinoco_hw_setup_wep(struct orinoco_private *priv)
1526 hermes_t *hw = &priv->hw;
1527 int err = 0;
1528 int master_wep_flag;
1529 int auth_flag;
1531 if (priv->wep_on)
1532 __orinoco_hw_setup_wepkeys(priv);
1534 if (priv->wep_restrict)
1535 auth_flag = HERMES_AUTH_SHARED_KEY;
1536 else
1537 auth_flag = HERMES_AUTH_OPEN;
1539 switch (priv->firmware_type) {
1540 case FIRMWARE_TYPE_AGERE: /* Agere style WEP */
1541 if (priv->wep_on) {
1542 /* Enable the shared-key authentication. */
1543 err = hermes_write_wordrec(hw, USER_BAP,
1544 HERMES_RID_CNFAUTHENTICATION_AGERE,
1545 auth_flag);
1547 err = hermes_write_wordrec(hw, USER_BAP,
1548 HERMES_RID_CNFWEPENABLED_AGERE,
1549 priv->wep_on);
1550 if (err)
1551 return err;
1552 break;
1554 case FIRMWARE_TYPE_INTERSIL: /* Intersil style WEP */
1555 case FIRMWARE_TYPE_SYMBOL: /* Symbol style WEP */
1556 if (priv->wep_on) {
1557 if (priv->wep_restrict ||
1558 (priv->firmware_type == FIRMWARE_TYPE_SYMBOL))
1559 master_wep_flag = HERMES_WEP_PRIVACY_INVOKED |
1560 HERMES_WEP_EXCL_UNENCRYPTED;
1561 else
1562 master_wep_flag = HERMES_WEP_PRIVACY_INVOKED;
1564 err = hermes_write_wordrec(hw, USER_BAP,
1565 HERMES_RID_CNFAUTHENTICATION,
1566 auth_flag);
1567 if (err)
1568 return err;
1569 } else
1570 master_wep_flag = 0;
1572 if (priv->iw_mode == IW_MODE_MONITOR)
1573 master_wep_flag |= HERMES_WEP_HOST_DECRYPT;
1575 /* Master WEP setting : on/off */
1576 err = hermes_write_wordrec(hw, USER_BAP,
1577 HERMES_RID_CNFWEPFLAGS_INTERSIL,
1578 master_wep_flag);
1579 if (err)
1580 return err;
1582 break;
1585 return 0;
1588 static int __orinoco_program_rids(struct net_device *dev)
1590 struct orinoco_private *priv = netdev_priv(dev);
1591 hermes_t *hw = &priv->hw;
1592 int err;
1593 struct hermes_idstring idbuf;
1595 /* Set the MAC address */
1596 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
1597 HERMES_BYTES_TO_RECLEN(ETH_ALEN), dev->dev_addr);
1598 if (err) {
1599 printk(KERN_ERR "%s: Error %d setting MAC address\n",
1600 dev->name, err);
1601 return err;
1604 /* Set up the link mode */
1605 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFPORTTYPE,
1606 priv->port_type);
1607 if (err) {
1608 printk(KERN_ERR "%s: Error %d setting port type\n",
1609 dev->name, err);
1610 return err;
1612 /* Set the channel/frequency */
1613 if (priv->channel == 0) {
1614 printk(KERN_DEBUG "%s: Channel is 0 in __orinoco_program_rids()\n", dev->name);
1615 if (priv->createibss)
1616 priv->channel = 10;
1618 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFOWNCHANNEL,
1619 priv->channel);
1620 if (err) {
1621 printk(KERN_ERR "%s: Error %d setting channel\n",
1622 dev->name, err);
1623 return err;
1626 if (priv->has_ibss) {
1627 u16 createibss;
1629 if ((strlen(priv->desired_essid) == 0) && (priv->createibss)) {
1630 printk(KERN_WARNING "%s: This firmware requires an "
1631 "ESSID in IBSS-Ad-Hoc mode.\n", dev->name);
1632 /* With wvlan_cs, in this case, we would crash.
1633 * hopefully, this driver will behave better...
1634 * Jean II */
1635 createibss = 0;
1636 } else {
1637 createibss = priv->createibss;
1640 err = hermes_write_wordrec(hw, USER_BAP,
1641 HERMES_RID_CNFCREATEIBSS,
1642 createibss);
1643 if (err) {
1644 printk(KERN_ERR "%s: Error %d setting CREATEIBSS\n",
1645 dev->name, err);
1646 return err;
1650 /* Set the desired ESSID */
1651 idbuf.len = cpu_to_le16(strlen(priv->desired_essid));
1652 memcpy(&idbuf.val, priv->desired_essid, sizeof(idbuf.val));
1653 /* WinXP wants partner to configure OWNSSID even in IBSS mode. (jimc) */
1654 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNSSID,
1655 HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
1656 &idbuf);
1657 if (err) {
1658 printk(KERN_ERR "%s: Error %d setting OWNSSID\n",
1659 dev->name, err);
1660 return err;
1662 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFDESIREDSSID,
1663 HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
1664 &idbuf);
1665 if (err) {
1666 printk(KERN_ERR "%s: Error %d setting DESIREDSSID\n",
1667 dev->name, err);
1668 return err;
1671 /* Set the station name */
1672 idbuf.len = cpu_to_le16(strlen(priv->nick));
1673 memcpy(&idbuf.val, priv->nick, sizeof(idbuf.val));
1674 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
1675 HERMES_BYTES_TO_RECLEN(strlen(priv->nick)+2),
1676 &idbuf);
1677 if (err) {
1678 printk(KERN_ERR "%s: Error %d setting nickname\n",
1679 dev->name, err);
1680 return err;
1683 /* Set AP density */
1684 if (priv->has_sensitivity) {
1685 err = hermes_write_wordrec(hw, USER_BAP,
1686 HERMES_RID_CNFSYSTEMSCALE,
1687 priv->ap_density);
1688 if (err) {
1689 printk(KERN_WARNING "%s: Error %d setting SYSTEMSCALE. "
1690 "Disabling sensitivity control\n",
1691 dev->name, err);
1693 priv->has_sensitivity = 0;
1697 /* Set RTS threshold */
1698 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
1699 priv->rts_thresh);
1700 if (err) {
1701 printk(KERN_ERR "%s: Error %d setting RTS threshold\n",
1702 dev->name, err);
1703 return err;
1706 /* Set fragmentation threshold or MWO robustness */
1707 if (priv->has_mwo)
1708 err = hermes_write_wordrec(hw, USER_BAP,
1709 HERMES_RID_CNFMWOROBUST_AGERE,
1710 priv->mwo_robust);
1711 else
1712 err = hermes_write_wordrec(hw, USER_BAP,
1713 HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
1714 priv->frag_thresh);
1715 if (err) {
1716 printk(KERN_ERR "%s: Error %d setting fragmentation\n",
1717 dev->name, err);
1718 return err;
1721 /* Set bitrate */
1722 err = __orinoco_hw_set_bitrate(priv);
1723 if (err) {
1724 printk(KERN_ERR "%s: Error %d setting bitrate\n",
1725 dev->name, err);
1726 return err;
1729 /* Set power management */
1730 if (priv->has_pm) {
1731 err = hermes_write_wordrec(hw, USER_BAP,
1732 HERMES_RID_CNFPMENABLED,
1733 priv->pm_on);
1734 if (err) {
1735 printk(KERN_ERR "%s: Error %d setting up PM\n",
1736 dev->name, err);
1737 return err;
1740 err = hermes_write_wordrec(hw, USER_BAP,
1741 HERMES_RID_CNFMULTICASTRECEIVE,
1742 priv->pm_mcast);
1743 if (err) {
1744 printk(KERN_ERR "%s: Error %d setting up PM\n",
1745 dev->name, err);
1746 return err;
1748 err = hermes_write_wordrec(hw, USER_BAP,
1749 HERMES_RID_CNFMAXSLEEPDURATION,
1750 priv->pm_period);
1751 if (err) {
1752 printk(KERN_ERR "%s: Error %d setting up PM\n",
1753 dev->name, err);
1754 return err;
1756 err = hermes_write_wordrec(hw, USER_BAP,
1757 HERMES_RID_CNFPMHOLDOVERDURATION,
1758 priv->pm_timeout);
1759 if (err) {
1760 printk(KERN_ERR "%s: Error %d setting up PM\n",
1761 dev->name, err);
1762 return err;
1766 /* Set preamble - only for Symbol so far... */
1767 if (priv->has_preamble) {
1768 err = hermes_write_wordrec(hw, USER_BAP,
1769 HERMES_RID_CNFPREAMBLE_SYMBOL,
1770 priv->preamble);
1771 if (err) {
1772 printk(KERN_ERR "%s: Error %d setting preamble\n",
1773 dev->name, err);
1774 return err;
1778 /* Set up encryption */
1779 if (priv->has_wep) {
1780 err = __orinoco_hw_setup_wep(priv);
1781 if (err) {
1782 printk(KERN_ERR "%s: Error %d activating WEP\n",
1783 dev->name, err);
1784 return err;
1788 /* Set promiscuity / multicast*/
1789 priv->promiscuous = 0;
1790 priv->mc_count = 0;
1791 __orinoco_set_multicast_list(dev); /* FIXME: what about the xmit_lock */
1793 return 0;
1796 /* FIXME: return int? */
1797 static void
1798 __orinoco_set_multicast_list(struct net_device *dev)
1800 struct orinoco_private *priv = netdev_priv(dev);
1801 hermes_t *hw = &priv->hw;
1802 int err = 0;
1803 int promisc, mc_count;
1805 /* The Hermes doesn't seem to have an allmulti mode, so we go
1806 * into promiscuous mode and let the upper levels deal. */
1807 if ( (dev->flags & IFF_PROMISC) || (dev->flags & IFF_ALLMULTI) ||
1808 (dev->mc_count > MAX_MULTICAST(priv)) ) {
1809 promisc = 1;
1810 mc_count = 0;
1811 } else {
1812 promisc = 0;
1813 mc_count = dev->mc_count;
1816 if (promisc != priv->promiscuous) {
1817 err = hermes_write_wordrec(hw, USER_BAP,
1818 HERMES_RID_CNFPROMISCUOUSMODE,
1819 promisc);
1820 if (err) {
1821 printk(KERN_ERR "%s: Error %d setting PROMISCUOUSMODE to 1.\n",
1822 dev->name, err);
1823 } else
1824 priv->promiscuous = promisc;
1827 if (! promisc && (mc_count || priv->mc_count) ) {
1828 struct dev_mc_list *p = dev->mc_list;
1829 struct hermes_multicast mclist;
1830 int i;
1832 for (i = 0; i < mc_count; i++) {
1833 /* paranoia: is list shorter than mc_count? */
1834 BUG_ON(! p);
1835 /* paranoia: bad address size in list? */
1836 BUG_ON(p->dmi_addrlen != ETH_ALEN);
1838 memcpy(mclist.addr[i], p->dmi_addr, ETH_ALEN);
1839 p = p->next;
1842 if (p)
1843 printk(KERN_WARNING "%s: Multicast list is "
1844 "longer than mc_count\n", dev->name);
1846 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFGROUPADDRESSES,
1847 HERMES_BYTES_TO_RECLEN(priv->mc_count * ETH_ALEN),
1848 &mclist);
1849 if (err)
1850 printk(KERN_ERR "%s: Error %d setting multicast list.\n",
1851 dev->name, err);
1852 else
1853 priv->mc_count = mc_count;
1856 /* Since we can set the promiscuous flag when it wasn't asked
1857 for, make sure the net_device knows about it. */
1858 if (priv->promiscuous)
1859 dev->flags |= IFF_PROMISC;
1860 else
1861 dev->flags &= ~IFF_PROMISC;
1864 static int orinoco_reconfigure(struct net_device *dev)
1866 struct orinoco_private *priv = netdev_priv(dev);
1867 struct hermes *hw = &priv->hw;
1868 unsigned long flags;
1869 int err = 0;
1871 if (priv->broken_disableport) {
1872 schedule_work(&priv->reset_work);
1873 return 0;
1876 if (orinoco_lock(priv, &flags) != 0)
1877 return -EBUSY;
1879 err = hermes_disable_port(hw, 0);
1880 if (err) {
1881 printk(KERN_WARNING "%s: Unable to disable port while reconfiguring card\n",
1882 dev->name);
1883 priv->broken_disableport = 1;
1884 goto out;
1887 err = __orinoco_program_rids(dev);
1888 if (err) {
1889 printk(KERN_WARNING "%s: Unable to reconfigure card\n",
1890 dev->name);
1891 goto out;
1894 err = hermes_enable_port(hw, 0);
1895 if (err) {
1896 printk(KERN_WARNING "%s: Unable to enable port while reconfiguring card\n",
1897 dev->name);
1898 goto out;
1901 out:
1902 if (err) {
1903 printk(KERN_WARNING "%s: Resetting instead...\n", dev->name);
1904 schedule_work(&priv->reset_work);
1905 err = 0;
1908 orinoco_unlock(priv, &flags);
1909 return err;
1913 /* This must be called from user context, without locks held - use
1914 * schedule_work() */
1915 static void orinoco_reset(struct net_device *dev)
1917 struct orinoco_private *priv = netdev_priv(dev);
1918 struct hermes *hw = &priv->hw;
1919 int err = 0;
1920 unsigned long flags;
1922 if (orinoco_lock(priv, &flags) != 0)
1923 /* When the hardware becomes available again, whatever
1924 * detects that is responsible for re-initializing
1925 * it. So no need for anything further */
1926 return;
1928 netif_stop_queue(dev);
1930 /* Shut off interrupts. Depending on what state the hardware
1931 * is in, this might not work, but we'll try anyway */
1932 hermes_set_irqmask(hw, 0);
1933 hermes_write_regn(hw, EVACK, 0xffff);
1935 priv->hw_unavailable++;
1936 priv->last_linkstatus = 0xffff; /* firmware will have to reassociate */
1937 netif_carrier_off(dev);
1939 orinoco_unlock(priv, &flags);
1941 if (priv->hard_reset)
1942 err = (*priv->hard_reset)(priv);
1943 if (err) {
1944 printk(KERN_ERR "%s: orinoco_reset: Error %d "
1945 "performing hard reset\n", dev->name, err);
1946 /* FIXME: shutdown of some sort */
1947 return;
1950 err = orinoco_reinit_firmware(dev);
1951 if (err) {
1952 printk(KERN_ERR "%s: orinoco_reset: Error %d re-initializing firmware\n",
1953 dev->name, err);
1954 return;
1957 spin_lock_irq(&priv->lock); /* This has to be called from user context */
1959 priv->hw_unavailable--;
1961 /* priv->open or priv->hw_unavailable might have changed while
1962 * we dropped the lock */
1963 if (priv->open && (! priv->hw_unavailable)) {
1964 err = __orinoco_up(dev);
1965 if (err) {
1966 printk(KERN_ERR "%s: orinoco_reset: Error %d reenabling card\n",
1967 dev->name, err);
1968 } else
1969 dev->trans_start = jiffies;
1972 spin_unlock_irq(&priv->lock);
1974 return;
1977 /********************************************************************/
1978 /* Interrupt handler */
1979 /********************************************************************/
1981 static void __orinoco_ev_tick(struct net_device *dev, hermes_t *hw)
1983 printk(KERN_DEBUG "%s: TICK\n", dev->name);
1986 static void __orinoco_ev_wterr(struct net_device *dev, hermes_t *hw)
1988 /* This seems to happen a fair bit under load, but ignoring it
1989 seems to work fine...*/
1990 printk(KERN_DEBUG "%s: MAC controller error (WTERR). Ignoring.\n",
1991 dev->name);
1994 irqreturn_t orinoco_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1996 struct net_device *dev = (struct net_device *)dev_id;
1997 struct orinoco_private *priv = netdev_priv(dev);
1998 hermes_t *hw = &priv->hw;
1999 int count = MAX_IRQLOOPS_PER_IRQ;
2000 u16 evstat, events;
2001 /* These are used to detect a runaway interrupt situation */
2002 /* If we get more than MAX_IRQLOOPS_PER_JIFFY iterations in a jiffy,
2003 * we panic and shut down the hardware */
2004 static int last_irq_jiffy = 0; /* jiffies value the last time
2005 * we were called */
2006 static int loops_this_jiffy = 0;
2007 unsigned long flags;
2009 if (orinoco_lock(priv, &flags) != 0) {
2010 /* If hw is unavailable - we don't know if the irq was
2011 * for us or not */
2012 return IRQ_HANDLED;
2015 evstat = hermes_read_regn(hw, EVSTAT);
2016 events = evstat & hw->inten;
2017 if (! events) {
2018 orinoco_unlock(priv, &flags);
2019 return IRQ_NONE;
2022 if (jiffies != last_irq_jiffy)
2023 loops_this_jiffy = 0;
2024 last_irq_jiffy = jiffies;
2026 while (events && count--) {
2027 if (++loops_this_jiffy > MAX_IRQLOOPS_PER_JIFFY) {
2028 printk(KERN_WARNING "%s: IRQ handler is looping too "
2029 "much! Resetting.\n", dev->name);
2030 /* Disable interrupts for now */
2031 hermes_set_irqmask(hw, 0);
2032 schedule_work(&priv->reset_work);
2033 break;
2036 /* Check the card hasn't been removed */
2037 if (! hermes_present(hw)) {
2038 DEBUG(0, "orinoco_interrupt(): card removed\n");
2039 break;
2042 if (events & HERMES_EV_TICK)
2043 __orinoco_ev_tick(dev, hw);
2044 if (events & HERMES_EV_WTERR)
2045 __orinoco_ev_wterr(dev, hw);
2046 if (events & HERMES_EV_INFDROP)
2047 __orinoco_ev_infdrop(dev, hw);
2048 if (events & HERMES_EV_INFO)
2049 __orinoco_ev_info(dev, hw);
2050 if (events & HERMES_EV_RX)
2051 __orinoco_ev_rx(dev, hw);
2052 if (events & HERMES_EV_TXEXC)
2053 __orinoco_ev_txexc(dev, hw);
2054 if (events & HERMES_EV_TX)
2055 __orinoco_ev_tx(dev, hw);
2056 if (events & HERMES_EV_ALLOC)
2057 __orinoco_ev_alloc(dev, hw);
2059 hermes_write_regn(hw, EVACK, events);
2061 evstat = hermes_read_regn(hw, EVSTAT);
2062 events = evstat & hw->inten;
2065 orinoco_unlock(priv, &flags);
2066 return IRQ_HANDLED;
2069 /********************************************************************/
2070 /* Initialization */
2071 /********************************************************************/
2073 struct comp_id {
2074 u16 id, variant, major, minor;
2075 } __attribute__ ((packed));
2077 static inline fwtype_t determine_firmware_type(struct comp_id *nic_id)
2079 if (nic_id->id < 0x8000)
2080 return FIRMWARE_TYPE_AGERE;
2081 else if (nic_id->id == 0x8000 && nic_id->major == 0)
2082 return FIRMWARE_TYPE_SYMBOL;
2083 else
2084 return FIRMWARE_TYPE_INTERSIL;
2087 /* Set priv->firmware type, determine firmware properties */
2088 static int determine_firmware(struct net_device *dev)
2090 struct orinoco_private *priv = netdev_priv(dev);
2091 hermes_t *hw = &priv->hw;
2092 int err;
2093 struct comp_id nic_id, sta_id;
2094 unsigned int firmver;
2095 char tmp[SYMBOL_MAX_VER_LEN+1];
2097 /* Get the hardware version */
2098 err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_NICID, &nic_id);
2099 if (err) {
2100 printk(KERN_ERR "%s: Cannot read hardware identity: error %d\n",
2101 dev->name, err);
2102 return err;
2105 le16_to_cpus(&nic_id.id);
2106 le16_to_cpus(&nic_id.variant);
2107 le16_to_cpus(&nic_id.major);
2108 le16_to_cpus(&nic_id.minor);
2109 printk(KERN_DEBUG "%s: Hardware identity %04x:%04x:%04x:%04x\n",
2110 dev->name, nic_id.id, nic_id.variant,
2111 nic_id.major, nic_id.minor);
2113 priv->firmware_type = determine_firmware_type(&nic_id);
2115 /* Get the firmware version */
2116 err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_STAID, &sta_id);
2117 if (err) {
2118 printk(KERN_ERR "%s: Cannot read station identity: error %d\n",
2119 dev->name, err);
2120 return err;
2123 le16_to_cpus(&sta_id.id);
2124 le16_to_cpus(&sta_id.variant);
2125 le16_to_cpus(&sta_id.major);
2126 le16_to_cpus(&sta_id.minor);
2127 printk(KERN_DEBUG "%s: Station identity %04x:%04x:%04x:%04x\n",
2128 dev->name, sta_id.id, sta_id.variant,
2129 sta_id.major, sta_id.minor);
2131 switch (sta_id.id) {
2132 case 0x15:
2133 printk(KERN_ERR "%s: Primary firmware is active\n",
2134 dev->name);
2135 return -ENODEV;
2136 case 0x14b:
2137 printk(KERN_ERR "%s: Tertiary firmware is active\n",
2138 dev->name);
2139 return -ENODEV;
2140 case 0x1f: /* Intersil, Agere, Symbol Spectrum24 */
2141 case 0x21: /* Symbol Spectrum24 Trilogy */
2142 break;
2143 default:
2144 printk(KERN_NOTICE "%s: Unknown station ID, please report\n",
2145 dev->name);
2146 break;
2149 /* Default capabilities */
2150 priv->has_sensitivity = 1;
2151 priv->has_mwo = 0;
2152 priv->has_preamble = 0;
2153 priv->has_port3 = 1;
2154 priv->has_ibss = 1;
2155 priv->has_wep = 0;
2156 priv->has_big_wep = 0;
2158 /* Determine capabilities from the firmware version */
2159 switch (priv->firmware_type) {
2160 case FIRMWARE_TYPE_AGERE:
2161 /* Lucent Wavelan IEEE, Lucent Orinoco, Cabletron RoamAbout,
2162 ELSA, Melco, HP, IBM, Dell 1150, Compaq 110/210 */
2163 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
2164 "Lucent/Agere %d.%02d", sta_id.major, sta_id.minor);
2166 firmver = ((unsigned long)sta_id.major << 16) | sta_id.minor;
2168 priv->has_ibss = (firmver >= 0x60006);
2169 priv->has_wep = (firmver >= 0x40020);
2170 priv->has_big_wep = 1; /* FIXME: this is wrong - how do we tell
2171 Gold cards from the others? */
2172 priv->has_mwo = (firmver >= 0x60000);
2173 priv->has_pm = (firmver >= 0x40020); /* Don't work in 7.52 ? */
2174 priv->ibss_port = 1;
2176 /* Tested with Agere firmware :
2177 * 1.16 ; 4.08 ; 4.52 ; 6.04 ; 6.16 ; 7.28 => Jean II
2178 * Tested CableTron firmware : 4.32 => Anton */
2179 break;
2180 case FIRMWARE_TYPE_SYMBOL:
2181 /* Symbol , 3Com AirConnect, Intel, Ericsson WLAN */
2182 /* Intel MAC : 00:02:B3:* */
2183 /* 3Com MAC : 00:50:DA:* */
2184 memset(tmp, 0, sizeof(tmp));
2185 /* Get the Symbol firmware version */
2186 err = hermes_read_ltv(hw, USER_BAP,
2187 HERMES_RID_SECONDARYVERSION_SYMBOL,
2188 SYMBOL_MAX_VER_LEN, NULL, &tmp);
2189 if (err) {
2190 printk(KERN_WARNING
2191 "%s: Error %d reading Symbol firmware info. Wildly guessing capabilities...\n",
2192 dev->name, err);
2193 firmver = 0;
2194 tmp[0] = '\0';
2195 } else {
2196 /* The firmware revision is a string, the format is
2197 * something like : "V2.20-01".
2198 * Quick and dirty parsing... - Jean II
2200 firmver = ((tmp[1] - '0') << 16) | ((tmp[3] - '0') << 12)
2201 | ((tmp[4] - '0') << 8) | ((tmp[6] - '0') << 4)
2202 | (tmp[7] - '0');
2204 tmp[SYMBOL_MAX_VER_LEN] = '\0';
2207 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
2208 "Symbol %s", tmp);
2210 priv->has_ibss = (firmver >= 0x20000);
2211 priv->has_wep = (firmver >= 0x15012);
2212 priv->has_big_wep = (firmver >= 0x20000);
2213 priv->has_pm = (firmver >= 0x20000 && firmver < 0x22000) ||
2214 (firmver >= 0x29000 && firmver < 0x30000) ||
2215 firmver >= 0x31000;
2216 priv->has_preamble = (firmver >= 0x20000);
2217 priv->ibss_port = 4;
2218 /* Tested with Intel firmware : 0x20015 => Jean II */
2219 /* Tested with 3Com firmware : 0x15012 & 0x22001 => Jean II */
2220 break;
2221 case FIRMWARE_TYPE_INTERSIL:
2222 /* D-Link, Linksys, Adtron, ZoomAir, and many others...
2223 * Samsung, Compaq 100/200 and Proxim are slightly
2224 * different and less well tested */
2225 /* D-Link MAC : 00:40:05:* */
2226 /* Addtron MAC : 00:90:D1:* */
2227 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
2228 "Intersil %d.%d.%d", sta_id.major, sta_id.minor,
2229 sta_id.variant);
2231 firmver = ((unsigned long)sta_id.major << 16) |
2232 ((unsigned long)sta_id.minor << 8) | sta_id.variant;
2234 priv->has_ibss = (firmver >= 0x000700); /* FIXME */
2235 priv->has_big_wep = priv->has_wep = (firmver >= 0x000800);
2236 priv->has_pm = (firmver >= 0x000700);
2238 if (firmver >= 0x000800)
2239 priv->ibss_port = 0;
2240 else {
2241 printk(KERN_NOTICE "%s: Intersil firmware earlier "
2242 "than v0.8.x - several features not supported\n",
2243 dev->name);
2244 priv->ibss_port = 1;
2246 break;
2248 printk(KERN_DEBUG "%s: Firmware determined as %s\n", dev->name,
2249 priv->fw_name);
2251 return 0;
2254 static int orinoco_init(struct net_device *dev)
2256 struct orinoco_private *priv = netdev_priv(dev);
2257 hermes_t *hw = &priv->hw;
2258 int err = 0;
2259 struct hermes_idstring nickbuf;
2260 u16 reclen;
2261 int len;
2263 TRACE_ENTER(dev->name);
2265 /* No need to lock, the hw_unavailable flag is already set in
2266 * alloc_orinocodev() */
2267 priv->nicbuf_size = IEEE802_11_FRAME_LEN + ETH_HLEN;
2269 /* Initialize the firmware */
2270 err = hermes_init(hw);
2271 if (err != 0) {
2272 printk(KERN_ERR "%s: failed to initialize firmware (err = %d)\n",
2273 dev->name, err);
2274 goto out;
2277 err = determine_firmware(dev);
2278 if (err != 0) {
2279 printk(KERN_ERR "%s: Incompatible firmware, aborting\n",
2280 dev->name);
2281 goto out;
2284 if (priv->has_port3)
2285 printk(KERN_DEBUG "%s: Ad-hoc demo mode supported\n", dev->name);
2286 if (priv->has_ibss)
2287 printk(KERN_DEBUG "%s: IEEE standard IBSS ad-hoc mode supported\n",
2288 dev->name);
2289 if (priv->has_wep) {
2290 printk(KERN_DEBUG "%s: WEP supported, ", dev->name);
2291 if (priv->has_big_wep)
2292 printk("104-bit key\n");
2293 else
2294 printk("40-bit key\n");
2297 /* Get the MAC address */
2298 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
2299 ETH_ALEN, NULL, dev->dev_addr);
2300 if (err) {
2301 printk(KERN_WARNING "%s: failed to read MAC address!\n",
2302 dev->name);
2303 goto out;
2306 printk(KERN_DEBUG "%s: MAC address %02X:%02X:%02X:%02X:%02X:%02X\n",
2307 dev->name, dev->dev_addr[0], dev->dev_addr[1],
2308 dev->dev_addr[2], dev->dev_addr[3], dev->dev_addr[4],
2309 dev->dev_addr[5]);
2311 /* Get the station name */
2312 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
2313 sizeof(nickbuf), &reclen, &nickbuf);
2314 if (err) {
2315 printk(KERN_ERR "%s: failed to read station name\n",
2316 dev->name);
2317 goto out;
2319 if (nickbuf.len)
2320 len = min(IW_ESSID_MAX_SIZE, (int)le16_to_cpu(nickbuf.len));
2321 else
2322 len = min(IW_ESSID_MAX_SIZE, 2 * reclen);
2323 memcpy(priv->nick, &nickbuf.val, len);
2324 priv->nick[len] = '\0';
2326 printk(KERN_DEBUG "%s: Station name \"%s\"\n", dev->name, priv->nick);
2328 /* Get allowed channels */
2329 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CHANNELLIST,
2330 &priv->channel_mask);
2331 if (err) {
2332 printk(KERN_ERR "%s: failed to read channel list!\n",
2333 dev->name);
2334 goto out;
2337 /* Get initial AP density */
2338 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFSYSTEMSCALE,
2339 &priv->ap_density);
2340 if (err || priv->ap_density < 1 || priv->ap_density > 3) {
2341 priv->has_sensitivity = 0;
2344 /* Get initial RTS threshold */
2345 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
2346 &priv->rts_thresh);
2347 if (err) {
2348 printk(KERN_ERR "%s: failed to read RTS threshold!\n",
2349 dev->name);
2350 goto out;
2353 /* Get initial fragmentation settings */
2354 if (priv->has_mwo)
2355 err = hermes_read_wordrec(hw, USER_BAP,
2356 HERMES_RID_CNFMWOROBUST_AGERE,
2357 &priv->mwo_robust);
2358 else
2359 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
2360 &priv->frag_thresh);
2361 if (err) {
2362 printk(KERN_ERR "%s: failed to read fragmentation settings!\n",
2363 dev->name);
2364 goto out;
2367 /* Power management setup */
2368 if (priv->has_pm) {
2369 priv->pm_on = 0;
2370 priv->pm_mcast = 1;
2371 err = hermes_read_wordrec(hw, USER_BAP,
2372 HERMES_RID_CNFMAXSLEEPDURATION,
2373 &priv->pm_period);
2374 if (err) {
2375 printk(KERN_ERR "%s: failed to read power management period!\n",
2376 dev->name);
2377 goto out;
2379 err = hermes_read_wordrec(hw, USER_BAP,
2380 HERMES_RID_CNFPMHOLDOVERDURATION,
2381 &priv->pm_timeout);
2382 if (err) {
2383 printk(KERN_ERR "%s: failed to read power management timeout!\n",
2384 dev->name);
2385 goto out;
2389 /* Preamble setup */
2390 if (priv->has_preamble) {
2391 err = hermes_read_wordrec(hw, USER_BAP,
2392 HERMES_RID_CNFPREAMBLE_SYMBOL,
2393 &priv->preamble);
2394 if (err)
2395 goto out;
2398 /* Set up the default configuration */
2399 priv->iw_mode = IW_MODE_INFRA;
2400 /* By default use IEEE/IBSS ad-hoc mode if we have it */
2401 priv->prefer_port3 = priv->has_port3 && (! priv->has_ibss);
2402 set_port_type(priv);
2403 priv->channel = 10; /* default channel, more-or-less arbitrary */
2405 priv->promiscuous = 0;
2406 priv->wep_on = 0;
2407 priv->tx_key = 0;
2409 err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
2410 if (err == -EIO) {
2411 /* Try workaround for old Symbol firmware bug */
2412 printk(KERN_WARNING "%s: firmware ALLOC bug detected "
2413 "(old Symbol firmware?). Trying to work around... ",
2414 dev->name);
2416 priv->nicbuf_size = TX_NICBUF_SIZE_BUG;
2417 err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
2418 if (err)
2419 printk("failed!\n");
2420 else
2421 printk("ok.\n");
2423 if (err) {
2424 printk("%s: Error %d allocating Tx buffer\n", dev->name, err);
2425 goto out;
2428 /* Make the hardware available, as long as it hasn't been
2429 * removed elsewhere (e.g. by PCMCIA hot unplug) */
2430 spin_lock_irq(&priv->lock);
2431 priv->hw_unavailable--;
2432 spin_unlock_irq(&priv->lock);
2434 printk(KERN_DEBUG "%s: ready\n", dev->name);
2436 out:
2437 TRACE_EXIT(dev->name);
2438 return err;
2441 struct net_device *alloc_orinocodev(int sizeof_card,
2442 int (*hard_reset)(struct orinoco_private *))
2444 struct net_device *dev;
2445 struct orinoco_private *priv;
2447 dev = alloc_etherdev(sizeof(struct orinoco_private) + sizeof_card);
2448 if (! dev)
2449 return NULL;
2450 priv = netdev_priv(dev);
2451 priv->ndev = dev;
2452 if (sizeof_card)
2453 priv->card = (void *)((unsigned long)netdev_priv(dev)
2454 + sizeof(struct orinoco_private));
2455 else
2456 priv->card = NULL;
2458 /* Setup / override net_device fields */
2459 dev->init = orinoco_init;
2460 dev->hard_start_xmit = orinoco_xmit;
2461 dev->tx_timeout = orinoco_tx_timeout;
2462 dev->watchdog_timeo = HZ; /* 1 second timeout */
2463 dev->get_stats = orinoco_get_stats;
2464 dev->get_wireless_stats = orinoco_get_wireless_stats;
2465 dev->do_ioctl = orinoco_ioctl;
2466 dev->change_mtu = orinoco_change_mtu;
2467 dev->set_multicast_list = orinoco_set_multicast_list;
2468 /* we use the default eth_mac_addr for setting the MAC addr */
2470 /* Set up default callbacks */
2471 dev->open = orinoco_open;
2472 dev->stop = orinoco_stop;
2473 priv->hard_reset = hard_reset;
2475 spin_lock_init(&priv->lock);
2476 priv->open = 0;
2477 priv->hw_unavailable = 1; /* orinoco_init() must clear this
2478 * before anything else touches the
2479 * hardware */
2480 INIT_WORK(&priv->reset_work, (void (*)(void *))orinoco_reset, dev);
2482 netif_carrier_off(dev);
2483 priv->last_linkstatus = 0xffff;
2485 return dev;
2489 void free_orinocodev(struct net_device *dev)
2491 free_netdev(dev);
2494 /********************************************************************/
2495 /* Wireless extensions */
2496 /********************************************************************/
2498 static int orinoco_hw_get_bssid(struct orinoco_private *priv,
2499 char buf[ETH_ALEN])
2501 hermes_t *hw = &priv->hw;
2502 int err = 0;
2503 unsigned long flags;
2505 if (orinoco_lock(priv, &flags) != 0)
2506 return -EBUSY;
2508 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTBSSID,
2509 ETH_ALEN, NULL, buf);
2511 orinoco_unlock(priv, &flags);
2513 return err;
2516 static int orinoco_hw_get_essid(struct orinoco_private *priv, int *active,
2517 char buf[IW_ESSID_MAX_SIZE+1])
2519 hermes_t *hw = &priv->hw;
2520 int err = 0;
2521 struct hermes_idstring essidbuf;
2522 char *p = (char *)(&essidbuf.val);
2523 int len;
2524 unsigned long flags;
2526 if (orinoco_lock(priv, &flags) != 0)
2527 return -EBUSY;
2529 if (strlen(priv->desired_essid) > 0) {
2530 /* We read the desired SSID from the hardware rather
2531 than from priv->desired_essid, just in case the
2532 firmware is allowed to change it on us. I'm not
2533 sure about this */
2534 /* My guess is that the OWNSSID should always be whatever
2535 * we set to the card, whereas CURRENT_SSID is the one that
2536 * may change... - Jean II */
2537 u16 rid;
2539 *active = 1;
2541 rid = (priv->port_type == 3) ? HERMES_RID_CNFOWNSSID :
2542 HERMES_RID_CNFDESIREDSSID;
2544 err = hermes_read_ltv(hw, USER_BAP, rid, sizeof(essidbuf),
2545 NULL, &essidbuf);
2546 if (err)
2547 goto fail_unlock;
2548 } else {
2549 *active = 0;
2551 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTSSID,
2552 sizeof(essidbuf), NULL, &essidbuf);
2553 if (err)
2554 goto fail_unlock;
2557 len = le16_to_cpu(essidbuf.len);
2559 memset(buf, 0, IW_ESSID_MAX_SIZE+1);
2560 memcpy(buf, p, len);
2561 buf[len] = '\0';
2563 fail_unlock:
2564 orinoco_unlock(priv, &flags);
2566 return err;
2569 static long orinoco_hw_get_freq(struct orinoco_private *priv)
2572 hermes_t *hw = &priv->hw;
2573 int err = 0;
2574 u16 channel;
2575 long freq = 0;
2576 unsigned long flags;
2578 if (orinoco_lock(priv, &flags) != 0)
2579 return -EBUSY;
2581 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CURRENTCHANNEL, &channel);
2582 if (err)
2583 goto out;
2585 /* Intersil firmware 1.3.5 returns 0 when the interface is down */
2586 if (channel == 0) {
2587 err = -EBUSY;
2588 goto out;
2591 if ( (channel < 1) || (channel > NUM_CHANNELS) ) {
2592 printk(KERN_WARNING "%s: Channel out of range (%d)!\n",
2593 priv->ndev->name, channel);
2594 err = -EBUSY;
2595 goto out;
2598 freq = channel_frequency[channel-1] * 100000;
2600 out:
2601 orinoco_unlock(priv, &flags);
2603 if (err > 0)
2604 err = -EBUSY;
2605 return err ? err : freq;
2608 static int orinoco_hw_get_bitratelist(struct orinoco_private *priv,
2609 int *numrates, s32 *rates, int max)
2611 hermes_t *hw = &priv->hw;
2612 struct hermes_idstring list;
2613 unsigned char *p = (unsigned char *)&list.val;
2614 int err = 0;
2615 int num;
2616 int i;
2617 unsigned long flags;
2619 if (orinoco_lock(priv, &flags) != 0)
2620 return -EBUSY;
2622 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_SUPPORTEDDATARATES,
2623 sizeof(list), NULL, &list);
2624 orinoco_unlock(priv, &flags);
2626 if (err)
2627 return err;
2629 num = le16_to_cpu(list.len);
2630 *numrates = num;
2631 num = min(num, max);
2633 for (i = 0; i < num; i++) {
2634 rates[i] = (p[i] & 0x7f) * 500000; /* convert to bps */
2637 return 0;
2640 static int orinoco_ioctl_getiwrange(struct net_device *dev, struct iw_point *rrq)
2642 struct orinoco_private *priv = netdev_priv(dev);
2643 int err = 0;
2644 int mode;
2645 struct iw_range range;
2646 int numrates;
2647 int i, k;
2648 unsigned long flags;
2650 TRACE_ENTER(dev->name);
2652 if (!access_ok(VERIFY_WRITE, rrq->pointer, sizeof(range)))
2653 return -EFAULT;
2655 rrq->length = sizeof(range);
2657 if (orinoco_lock(priv, &flags) != 0)
2658 return -EBUSY;
2660 mode = priv->iw_mode;
2661 orinoco_unlock(priv, &flags);
2663 memset(&range, 0, sizeof(range));
2665 /* Much of this shamelessly taken from wvlan_cs.c. No idea
2666 * what it all means -dgibson */
2667 range.we_version_compiled = WIRELESS_EXT;
2668 range.we_version_source = 11;
2670 range.min_nwid = range.max_nwid = 0; /* We don't use nwids */
2672 /* Set available channels/frequencies */
2673 range.num_channels = NUM_CHANNELS;
2674 k = 0;
2675 for (i = 0; i < NUM_CHANNELS; i++) {
2676 if (priv->channel_mask & (1 << i)) {
2677 range.freq[k].i = i + 1;
2678 range.freq[k].m = channel_frequency[i] * 100000;
2679 range.freq[k].e = 1;
2680 k++;
2683 if (k >= IW_MAX_FREQUENCIES)
2684 break;
2686 range.num_frequency = k;
2688 range.sensitivity = 3;
2690 if ((mode == IW_MODE_ADHOC) && (priv->spy_number == 0)){
2691 /* Quality stats meaningless in ad-hoc mode */
2692 range.max_qual.qual = 0;
2693 range.max_qual.level = 0;
2694 range.max_qual.noise = 0;
2695 range.avg_qual.qual = 0;
2696 range.avg_qual.level = 0;
2697 range.avg_qual.noise = 0;
2698 } else {
2699 range.max_qual.qual = 0x8b - 0x2f;
2700 range.max_qual.level = 0x2f - 0x95 - 1;
2701 range.max_qual.noise = 0x2f - 0x95 - 1;
2702 /* Need to get better values */
2703 range.avg_qual.qual = 0x24;
2704 range.avg_qual.level = 0xC2;
2705 range.avg_qual.noise = 0x9E;
2708 err = orinoco_hw_get_bitratelist(priv, &numrates,
2709 range.bitrate, IW_MAX_BITRATES);
2710 if (err)
2711 return err;
2712 range.num_bitrates = numrates;
2714 /* Set an indication of the max TCP throughput in bit/s that we can
2715 * expect using this interface. May be use for QoS stuff...
2716 * Jean II */
2717 if(numrates > 2)
2718 range.throughput = 5 * 1000 * 1000; /* ~5 Mb/s */
2719 else
2720 range.throughput = 1.5 * 1000 * 1000; /* ~1.5 Mb/s */
2722 range.min_rts = 0;
2723 range.max_rts = 2347;
2724 range.min_frag = 256;
2725 range.max_frag = 2346;
2727 if (orinoco_lock(priv, &flags) != 0)
2728 return -EBUSY;
2729 if (priv->has_wep) {
2730 range.max_encoding_tokens = ORINOCO_MAX_KEYS;
2732 range.encoding_size[0] = SMALL_KEY_SIZE;
2733 range.num_encoding_sizes = 1;
2735 if (priv->has_big_wep) {
2736 range.encoding_size[1] = LARGE_KEY_SIZE;
2737 range.num_encoding_sizes = 2;
2739 } else {
2740 range.num_encoding_sizes = 0;
2741 range.max_encoding_tokens = 0;
2743 orinoco_unlock(priv, &flags);
2745 range.min_pmp = 0;
2746 range.max_pmp = 65535000;
2747 range.min_pmt = 0;
2748 range.max_pmt = 65535 * 1000; /* ??? */
2749 range.pmp_flags = IW_POWER_PERIOD;
2750 range.pmt_flags = IW_POWER_TIMEOUT;
2751 range.pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_UNICAST_R;
2753 range.num_txpower = 1;
2754 range.txpower[0] = 15; /* 15dBm */
2755 range.txpower_capa = IW_TXPOW_DBM;
2757 range.retry_capa = IW_RETRY_LIMIT | IW_RETRY_LIFETIME;
2758 range.retry_flags = IW_RETRY_LIMIT;
2759 range.r_time_flags = IW_RETRY_LIFETIME;
2760 range.min_retry = 0;
2761 range.max_retry = 65535; /* ??? */
2762 range.min_r_time = 0;
2763 range.max_r_time = 65535 * 1000; /* ??? */
2765 if (copy_to_user(rrq->pointer, &range, sizeof(range)))
2766 return -EFAULT;
2768 TRACE_EXIT(dev->name);
2770 return 0;
2773 static int orinoco_ioctl_setiwencode(struct net_device *dev, struct iw_point *erq)
2775 struct orinoco_private *priv = netdev_priv(dev);
2776 int index = (erq->flags & IW_ENCODE_INDEX) - 1;
2777 int setindex = priv->tx_key;
2778 int enable = priv->wep_on;
2779 int restricted = priv->wep_restrict;
2780 u16 xlen = 0;
2781 int err = 0;
2782 char keybuf[ORINOCO_MAX_KEY_SIZE];
2783 unsigned long flags;
2785 if (! priv->has_wep)
2786 return -EOPNOTSUPP;
2788 if (erq->pointer) {
2789 /* We actually have a key to set - check its length */
2790 if (erq->length > LARGE_KEY_SIZE)
2791 return -E2BIG;
2793 if ( (erq->length > SMALL_KEY_SIZE) && !priv->has_big_wep )
2794 return -E2BIG;
2796 if (copy_from_user(keybuf, erq->pointer, erq->length))
2797 return -EFAULT;
2800 if (orinoco_lock(priv, &flags) != 0)
2801 return -EBUSY;
2803 if (erq->pointer) {
2804 if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
2805 index = priv->tx_key;
2807 /* Adjust key length to a supported value */
2808 if (erq->length > SMALL_KEY_SIZE) {
2809 xlen = LARGE_KEY_SIZE;
2810 } else if (erq->length > 0) {
2811 xlen = SMALL_KEY_SIZE;
2812 } else
2813 xlen = 0;
2815 /* Switch on WEP if off */
2816 if ((!enable) && (xlen > 0)) {
2817 setindex = index;
2818 enable = 1;
2820 } else {
2821 /* Important note : if the user do "iwconfig eth0 enc off",
2822 * we will arrive there with an index of -1. This is valid
2823 * but need to be taken care off... Jean II */
2824 if ((index < 0) || (index >= ORINOCO_MAX_KEYS)) {
2825 if((index != -1) || (erq->flags == 0)) {
2826 err = -EINVAL;
2827 goto out;
2829 } else {
2830 /* Set the index : Check that the key is valid */
2831 if(priv->keys[index].len == 0) {
2832 err = -EINVAL;
2833 goto out;
2835 setindex = index;
2839 if (erq->flags & IW_ENCODE_DISABLED)
2840 enable = 0;
2841 if (erq->flags & IW_ENCODE_OPEN)
2842 restricted = 0;
2843 if (erq->flags & IW_ENCODE_RESTRICTED)
2844 restricted = 1;
2846 if (erq->pointer) {
2847 priv->keys[index].len = cpu_to_le16(xlen);
2848 memset(priv->keys[index].data, 0,
2849 sizeof(priv->keys[index].data));
2850 memcpy(priv->keys[index].data, keybuf, erq->length);
2852 priv->tx_key = setindex;
2854 /* Try fast key change if connected and only keys are changed */
2855 if (priv->wep_on && enable && (priv->wep_restrict == restricted) &&
2856 netif_carrier_ok(dev)) {
2857 err = __orinoco_hw_setup_wepkeys(priv);
2858 /* No need to commit if successful */
2859 goto out;
2862 priv->wep_on = enable;
2863 priv->wep_restrict = restricted;
2865 out:
2866 orinoco_unlock(priv, &flags);
2868 return err;
2871 static int orinoco_ioctl_getiwencode(struct net_device *dev, struct iw_point *erq)
2873 struct orinoco_private *priv = netdev_priv(dev);
2874 int index = (erq->flags & IW_ENCODE_INDEX) - 1;
2875 u16 xlen = 0;
2876 char keybuf[ORINOCO_MAX_KEY_SIZE];
2877 unsigned long flags;
2879 if (! priv->has_wep)
2880 return -EOPNOTSUPP;
2882 if (orinoco_lock(priv, &flags) != 0)
2883 return -EBUSY;
2885 if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
2886 index = priv->tx_key;
2888 erq->flags = 0;
2889 if (! priv->wep_on)
2890 erq->flags |= IW_ENCODE_DISABLED;
2891 erq->flags |= index + 1;
2893 if (priv->wep_restrict)
2894 erq->flags |= IW_ENCODE_RESTRICTED;
2895 else
2896 erq->flags |= IW_ENCODE_OPEN;
2898 xlen = le16_to_cpu(priv->keys[index].len);
2900 erq->length = xlen;
2902 memcpy(keybuf, priv->keys[index].data, ORINOCO_MAX_KEY_SIZE);
2904 orinoco_unlock(priv, &flags);
2906 if (erq->pointer) {
2907 if (copy_to_user(erq->pointer, keybuf, xlen))
2908 return -EFAULT;
2911 return 0;
2914 static int orinoco_ioctl_setessid(struct net_device *dev, struct iw_point *erq)
2916 struct orinoco_private *priv = netdev_priv(dev);
2917 char essidbuf[IW_ESSID_MAX_SIZE+1];
2918 unsigned long flags;
2920 /* Note : ESSID is ignored in Ad-Hoc demo mode, but we can set it
2921 * anyway... - Jean II */
2923 memset(&essidbuf, 0, sizeof(essidbuf));
2925 if (erq->flags) {
2926 if (erq->length > IW_ESSID_MAX_SIZE)
2927 return -E2BIG;
2929 if (copy_from_user(&essidbuf, erq->pointer, erq->length))
2930 return -EFAULT;
2932 essidbuf[erq->length] = '\0';
2935 if (orinoco_lock(priv, &flags) != 0)
2936 return -EBUSY;
2938 memcpy(priv->desired_essid, essidbuf, sizeof(priv->desired_essid));
2940 orinoco_unlock(priv, &flags);
2942 return 0;
2945 static int orinoco_ioctl_getessid(struct net_device *dev, struct iw_point *erq)
2947 struct orinoco_private *priv = netdev_priv(dev);
2948 char essidbuf[IW_ESSID_MAX_SIZE+1];
2949 int active;
2950 int err = 0;
2951 unsigned long flags;
2953 TRACE_ENTER(dev->name);
2955 if (netif_running(dev)) {
2956 err = orinoco_hw_get_essid(priv, &active, essidbuf);
2957 if (err)
2958 return err;
2959 } else {
2960 if (orinoco_lock(priv, &flags) != 0)
2961 return -EBUSY;
2962 memcpy(essidbuf, priv->desired_essid, sizeof(essidbuf));
2963 orinoco_unlock(priv, &flags);
2966 erq->flags = 1;
2967 erq->length = strlen(essidbuf) + 1;
2968 if (erq->pointer)
2969 if (copy_to_user(erq->pointer, essidbuf, erq->length))
2970 return -EFAULT;
2972 TRACE_EXIT(dev->name);
2974 return 0;
2977 static int orinoco_ioctl_setnick(struct net_device *dev, struct iw_point *nrq)
2979 struct orinoco_private *priv = netdev_priv(dev);
2980 char nickbuf[IW_ESSID_MAX_SIZE+1];
2981 unsigned long flags;
2983 if (nrq->length > IW_ESSID_MAX_SIZE)
2984 return -E2BIG;
2986 memset(nickbuf, 0, sizeof(nickbuf));
2988 if (copy_from_user(nickbuf, nrq->pointer, nrq->length))
2989 return -EFAULT;
2991 nickbuf[nrq->length] = '\0';
2993 if (orinoco_lock(priv, &flags) != 0)
2994 return -EBUSY;
2996 memcpy(priv->nick, nickbuf, sizeof(priv->nick));
2998 orinoco_unlock(priv, &flags);
3000 return 0;
3003 static int orinoco_ioctl_getnick(struct net_device *dev, struct iw_point *nrq)
3005 struct orinoco_private *priv = netdev_priv(dev);
3006 char nickbuf[IW_ESSID_MAX_SIZE+1];
3007 unsigned long flags;
3009 if (orinoco_lock(priv, &flags) != 0)
3010 return -EBUSY;
3012 memcpy(nickbuf, priv->nick, IW_ESSID_MAX_SIZE+1);
3013 orinoco_unlock(priv, &flags);
3015 nrq->length = strlen(nickbuf)+1;
3017 if (copy_to_user(nrq->pointer, nickbuf, sizeof(nickbuf)))
3018 return -EFAULT;
3020 return 0;
3023 static int orinoco_ioctl_setfreq(struct net_device *dev, struct iw_freq *frq)
3025 struct orinoco_private *priv = netdev_priv(dev);
3026 int chan = -1;
3027 unsigned long flags;
3029 /* We can only use this in Ad-Hoc demo mode to set the operating
3030 * frequency, or in IBSS mode to set the frequency where the IBSS
3031 * will be created - Jean II */
3032 if (priv->iw_mode != IW_MODE_ADHOC)
3033 return -EOPNOTSUPP;
3035 if ( (frq->e == 0) && (frq->m <= 1000) ) {
3036 /* Setting by channel number */
3037 chan = frq->m;
3038 } else {
3039 /* Setting by frequency - search the table */
3040 int mult = 1;
3041 int i;
3043 for (i = 0; i < (6 - frq->e); i++)
3044 mult *= 10;
3046 for (i = 0; i < NUM_CHANNELS; i++)
3047 if (frq->m == (channel_frequency[i] * mult))
3048 chan = i+1;
3051 if ( (chan < 1) || (chan > NUM_CHANNELS) ||
3052 ! (priv->channel_mask & (1 << (chan-1)) ) )
3053 return -EINVAL;
3055 if (orinoco_lock(priv, &flags) != 0)
3056 return -EBUSY;
3057 priv->channel = chan;
3058 orinoco_unlock(priv, &flags);
3060 return 0;
3063 static int orinoco_ioctl_getsens(struct net_device *dev, struct iw_param *srq)
3065 struct orinoco_private *priv = netdev_priv(dev);
3066 hermes_t *hw = &priv->hw;
3067 u16 val;
3068 int err;
3069 unsigned long flags;
3071 if (!priv->has_sensitivity)
3072 return -EOPNOTSUPP;
3074 if (orinoco_lock(priv, &flags) != 0)
3075 return -EBUSY;
3076 err = hermes_read_wordrec(hw, USER_BAP,
3077 HERMES_RID_CNFSYSTEMSCALE, &val);
3078 orinoco_unlock(priv, &flags);
3080 if (err)
3081 return err;
3083 srq->value = val;
3084 srq->fixed = 0; /* auto */
3086 return 0;
3089 static int orinoco_ioctl_setsens(struct net_device *dev, struct iw_param *srq)
3091 struct orinoco_private *priv = netdev_priv(dev);
3092 int val = srq->value;
3093 unsigned long flags;
3095 if (!priv->has_sensitivity)
3096 return -EOPNOTSUPP;
3098 if ((val < 1) || (val > 3))
3099 return -EINVAL;
3101 if (orinoco_lock(priv, &flags) != 0)
3102 return -EBUSY;
3103 priv->ap_density = val;
3104 orinoco_unlock(priv, &flags);
3106 return 0;
3109 static int orinoco_ioctl_setrts(struct net_device *dev, struct iw_param *rrq)
3111 struct orinoco_private *priv = netdev_priv(dev);
3112 int val = rrq->value;
3113 unsigned long flags;
3115 if (rrq->disabled)
3116 val = 2347;
3118 if ( (val < 0) || (val > 2347) )
3119 return -EINVAL;
3121 if (orinoco_lock(priv, &flags) != 0)
3122 return -EBUSY;
3124 priv->rts_thresh = val;
3125 orinoco_unlock(priv, &flags);
3127 return 0;
3130 static int orinoco_ioctl_setfrag(struct net_device *dev, struct iw_param *frq)
3132 struct orinoco_private *priv = netdev_priv(dev);
3133 int err = 0;
3134 unsigned long flags;
3136 if (orinoco_lock(priv, &flags) != 0)
3137 return -EBUSY;
3139 if (priv->has_mwo) {
3140 if (frq->disabled)
3141 priv->mwo_robust = 0;
3142 else {
3143 if (frq->fixed)
3144 printk(KERN_WARNING "%s: Fixed fragmentation is "
3145 "not supported on this firmware. "
3146 "Using MWO robust instead.\n", dev->name);
3147 priv->mwo_robust = 1;
3149 } else {
3150 if (frq->disabled)
3151 priv->frag_thresh = 2346;
3152 else {
3153 if ( (frq->value < 256) || (frq->value > 2346) )
3154 err = -EINVAL;
3155 else
3156 priv->frag_thresh = frq->value & ~0x1; /* must be even */
3160 orinoco_unlock(priv, &flags);
3162 return err;
3165 static int orinoco_ioctl_getfrag(struct net_device *dev, struct iw_param *frq)
3167 struct orinoco_private *priv = netdev_priv(dev);
3168 hermes_t *hw = &priv->hw;
3169 int err = 0;
3170 u16 val;
3171 unsigned long flags;
3173 if (orinoco_lock(priv, &flags) != 0)
3174 return -EBUSY;
3176 if (priv->has_mwo) {
3177 err = hermes_read_wordrec(hw, USER_BAP,
3178 HERMES_RID_CNFMWOROBUST_AGERE,
3179 &val);
3180 if (err)
3181 val = 0;
3183 frq->value = val ? 2347 : 0;
3184 frq->disabled = ! val;
3185 frq->fixed = 0;
3186 } else {
3187 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
3188 &val);
3189 if (err)
3190 val = 0;
3192 frq->value = val;
3193 frq->disabled = (val >= 2346);
3194 frq->fixed = 1;
3197 orinoco_unlock(priv, &flags);
3199 return err;
3202 static int orinoco_ioctl_setrate(struct net_device *dev, struct iw_param *rrq)
3204 struct orinoco_private *priv = netdev_priv(dev);
3205 int err = 0;
3206 int ratemode = -1;
3207 int bitrate; /* 100s of kilobits */
3208 int i;
3209 unsigned long flags;
3211 /* As the user space doesn't know our highest rate, it uses -1
3212 * to ask us to set the highest rate. Test it using "iwconfig
3213 * ethX rate auto" - Jean II */
3214 if (rrq->value == -1)
3215 bitrate = 110;
3216 else {
3217 if (rrq->value % 100000)
3218 return -EINVAL;
3219 bitrate = rrq->value / 100000;
3222 if ( (bitrate != 10) && (bitrate != 20) &&
3223 (bitrate != 55) && (bitrate != 110) )
3224 return -EINVAL;
3226 for (i = 0; i < BITRATE_TABLE_SIZE; i++)
3227 if ( (bitrate_table[i].bitrate == bitrate) &&
3228 (bitrate_table[i].automatic == ! rrq->fixed) ) {
3229 ratemode = i;
3230 break;
3233 if (ratemode == -1)
3234 return -EINVAL;
3236 if (orinoco_lock(priv, &flags) != 0)
3237 return -EBUSY;
3238 priv->bitratemode = ratemode;
3239 orinoco_unlock(priv, &flags);
3241 return err;
3244 static int orinoco_ioctl_getrate(struct net_device *dev, struct iw_param *rrq)
3246 struct orinoco_private *priv = netdev_priv(dev);
3247 hermes_t *hw = &priv->hw;
3248 int err = 0;
3249 int ratemode;
3250 int i;
3251 u16 val;
3252 unsigned long flags;
3254 if (orinoco_lock(priv, &flags) != 0)
3255 return -EBUSY;
3257 ratemode = priv->bitratemode;
3259 BUG_ON((ratemode < 0) || (ratemode >= BITRATE_TABLE_SIZE));
3261 rrq->value = bitrate_table[ratemode].bitrate * 100000;
3262 rrq->fixed = ! bitrate_table[ratemode].automatic;
3263 rrq->disabled = 0;
3265 /* If the interface is running we try to find more about the
3266 current mode */
3267 if (netif_running(dev)) {
3268 err = hermes_read_wordrec(hw, USER_BAP,
3269 HERMES_RID_CURRENTTXRATE, &val);
3270 if (err)
3271 goto out;
3273 switch (priv->firmware_type) {
3274 case FIRMWARE_TYPE_AGERE: /* Lucent style rate */
3275 /* Note : in Lucent firmware, the return value of
3276 * HERMES_RID_CURRENTTXRATE is the bitrate in Mb/s,
3277 * and therefore is totally different from the
3278 * encoding of HERMES_RID_CNFTXRATECONTROL.
3279 * Don't forget that 6Mb/s is really 5.5Mb/s */
3280 if (val == 6)
3281 rrq->value = 5500000;
3282 else
3283 rrq->value = val * 1000000;
3284 break;
3285 case FIRMWARE_TYPE_INTERSIL: /* Intersil style rate */
3286 case FIRMWARE_TYPE_SYMBOL: /* Symbol style rate */
3287 for (i = 0; i < BITRATE_TABLE_SIZE; i++)
3288 if (bitrate_table[i].intersil_txratectrl == val) {
3289 ratemode = i;
3290 break;
3292 if (i >= BITRATE_TABLE_SIZE)
3293 printk(KERN_INFO "%s: Unable to determine current bitrate (0x%04hx)\n",
3294 dev->name, val);
3296 rrq->value = bitrate_table[ratemode].bitrate * 100000;
3297 break;
3298 default:
3299 BUG();
3303 out:
3304 orinoco_unlock(priv, &flags);
3306 return err;
3309 static int orinoco_ioctl_setpower(struct net_device *dev, struct iw_param *prq)
3311 struct orinoco_private *priv = netdev_priv(dev);
3312 int err = 0;
3313 unsigned long flags;
3315 if (orinoco_lock(priv, &flags) != 0)
3316 return -EBUSY;
3318 if (prq->disabled) {
3319 priv->pm_on = 0;
3320 } else {
3321 switch (prq->flags & IW_POWER_MODE) {
3322 case IW_POWER_UNICAST_R:
3323 priv->pm_mcast = 0;
3324 priv->pm_on = 1;
3325 break;
3326 case IW_POWER_ALL_R:
3327 priv->pm_mcast = 1;
3328 priv->pm_on = 1;
3329 break;
3330 case IW_POWER_ON:
3331 /* No flags : but we may have a value - Jean II */
3332 break;
3333 default:
3334 err = -EINVAL;
3336 if (err)
3337 goto out;
3339 if (prq->flags & IW_POWER_TIMEOUT) {
3340 priv->pm_on = 1;
3341 priv->pm_timeout = prq->value / 1000;
3343 if (prq->flags & IW_POWER_PERIOD) {
3344 priv->pm_on = 1;
3345 priv->pm_period = prq->value / 1000;
3347 /* It's valid to not have a value if we are just toggling
3348 * the flags... Jean II */
3349 if(!priv->pm_on) {
3350 err = -EINVAL;
3351 goto out;
3355 out:
3356 orinoco_unlock(priv, &flags);
3358 return err;
3361 static int orinoco_ioctl_getpower(struct net_device *dev, struct iw_param *prq)
3363 struct orinoco_private *priv = netdev_priv(dev);
3364 hermes_t *hw = &priv->hw;
3365 int err = 0;
3366 u16 enable, period, timeout, mcast;
3367 unsigned long flags;
3369 if (orinoco_lock(priv, &flags) != 0)
3370 return -EBUSY;
3372 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFPMENABLED, &enable);
3373 if (err)
3374 goto out;
3376 err = hermes_read_wordrec(hw, USER_BAP,
3377 HERMES_RID_CNFMAXSLEEPDURATION, &period);
3378 if (err)
3379 goto out;
3381 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFPMHOLDOVERDURATION, &timeout);
3382 if (err)
3383 goto out;
3385 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFMULTICASTRECEIVE, &mcast);
3386 if (err)
3387 goto out;
3389 prq->disabled = !enable;
3390 /* Note : by default, display the period */
3391 if ((prq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
3392 prq->flags = IW_POWER_TIMEOUT;
3393 prq->value = timeout * 1000;
3394 } else {
3395 prq->flags = IW_POWER_PERIOD;
3396 prq->value = period * 1000;
3398 if (mcast)
3399 prq->flags |= IW_POWER_ALL_R;
3400 else
3401 prq->flags |= IW_POWER_UNICAST_R;
3403 out:
3404 orinoco_unlock(priv, &flags);
3406 return err;
3409 static int orinoco_ioctl_getretry(struct net_device *dev, struct iw_param *rrq)
3411 struct orinoco_private *priv = netdev_priv(dev);
3412 hermes_t *hw = &priv->hw;
3413 int err = 0;
3414 u16 short_limit, long_limit, lifetime;
3415 unsigned long flags;
3417 if (orinoco_lock(priv, &flags) != 0)
3418 return -EBUSY;
3420 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_SHORTRETRYLIMIT,
3421 &short_limit);
3422 if (err)
3423 goto out;
3425 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_LONGRETRYLIMIT,
3426 &long_limit);
3427 if (err)
3428 goto out;
3430 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_MAXTRANSMITLIFETIME,
3431 &lifetime);
3432 if (err)
3433 goto out;
3435 rrq->disabled = 0; /* Can't be disabled */
3437 /* Note : by default, display the retry number */
3438 if ((rrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
3439 rrq->flags = IW_RETRY_LIFETIME;
3440 rrq->value = lifetime * 1000; /* ??? */
3441 } else {
3442 /* By default, display the min number */
3443 if ((rrq->flags & IW_RETRY_MAX)) {
3444 rrq->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
3445 rrq->value = long_limit;
3446 } else {
3447 rrq->flags = IW_RETRY_LIMIT;
3448 rrq->value = short_limit;
3449 if(short_limit != long_limit)
3450 rrq->flags |= IW_RETRY_MIN;
3454 out:
3455 orinoco_unlock(priv, &flags);
3457 return err;
3460 static int orinoco_ioctl_setibssport(struct net_device *dev, struct iwreq *wrq)
3462 struct orinoco_private *priv = netdev_priv(dev);
3463 int val = *( (int *) wrq->u.name );
3464 unsigned long flags;
3466 if (orinoco_lock(priv, &flags) != 0)
3467 return -EBUSY;
3469 priv->ibss_port = val ;
3471 /* Actually update the mode we are using */
3472 set_port_type(priv);
3474 orinoco_unlock(priv, &flags);
3475 return 0;
3478 static int orinoco_ioctl_getibssport(struct net_device *dev, struct iwreq *wrq)
3480 struct orinoco_private *priv = netdev_priv(dev);
3481 int *val = (int *)wrq->u.name;
3482 unsigned long flags;
3484 if (orinoco_lock(priv, &flags) != 0)
3485 return -EBUSY;
3487 *val = priv->ibss_port;
3488 orinoco_unlock(priv, &flags);
3490 return 0;
3493 static int orinoco_ioctl_setport3(struct net_device *dev, struct iwreq *wrq)
3495 struct orinoco_private *priv = netdev_priv(dev);
3496 int val = *( (int *) wrq->u.name );
3497 int err = 0;
3498 unsigned long flags;
3500 if (orinoco_lock(priv, &flags) != 0)
3501 return -EBUSY;
3503 switch (val) {
3504 case 0: /* Try to do IEEE ad-hoc mode */
3505 if (! priv->has_ibss) {
3506 err = -EINVAL;
3507 break;
3509 priv->prefer_port3 = 0;
3511 break;
3513 case 1: /* Try to do Lucent proprietary ad-hoc mode */
3514 if (! priv->has_port3) {
3515 err = -EINVAL;
3516 break;
3518 priv->prefer_port3 = 1;
3519 break;
3521 default:
3522 err = -EINVAL;
3525 if (! err)
3526 /* Actually update the mode we are using */
3527 set_port_type(priv);
3529 orinoco_unlock(priv, &flags);
3531 return err;
3534 static int orinoco_ioctl_getport3(struct net_device *dev, struct iwreq *wrq)
3536 struct orinoco_private *priv = netdev_priv(dev);
3537 int *val = (int *)wrq->u.name;
3538 unsigned long flags;
3540 if (orinoco_lock(priv, &flags) != 0)
3541 return -EBUSY;
3543 *val = priv->prefer_port3;
3544 orinoco_unlock(priv, &flags);
3545 return 0;
3548 /* Spy is used for link quality/strength measurements in Ad-Hoc mode
3549 * Jean II */
3550 static int orinoco_ioctl_setspy(struct net_device *dev, struct iw_point *srq)
3552 struct orinoco_private *priv = netdev_priv(dev);
3553 struct sockaddr address[IW_MAX_SPY];
3554 int number = srq->length;
3555 int i;
3556 int err = 0;
3557 unsigned long flags;
3559 /* Check the number of addresses */
3560 if (number > IW_MAX_SPY)
3561 return -E2BIG;
3563 /* Get the data in the driver */
3564 if (srq->pointer) {
3565 if (copy_from_user(address, srq->pointer,
3566 sizeof(struct sockaddr) * number))
3567 return -EFAULT;
3570 /* Make sure nobody mess with the structure while we do */
3571 if (orinoco_lock(priv, &flags) != 0)
3572 return -EBUSY;
3574 /* orinoco_lock() doesn't disable interrupts, so make sure the
3575 * interrupt rx path don't get confused while we copy */
3576 priv->spy_number = 0;
3578 if (number > 0) {
3579 /* Extract the addresses */
3580 for (i = 0; i < number; i++)
3581 memcpy(priv->spy_address[i], address[i].sa_data,
3582 ETH_ALEN);
3583 /* Reset stats */
3584 memset(priv->spy_stat, 0,
3585 sizeof(struct iw_quality) * IW_MAX_SPY);
3586 /* Set number of addresses */
3587 priv->spy_number = number;
3590 /* Now, let the others play */
3591 orinoco_unlock(priv, &flags);
3593 return err;
3596 static int orinoco_ioctl_getspy(struct net_device *dev, struct iw_point *srq)
3598 struct orinoco_private *priv = netdev_priv(dev);
3599 struct sockaddr address[IW_MAX_SPY];
3600 struct iw_quality spy_stat[IW_MAX_SPY];
3601 int number;
3602 int i;
3603 unsigned long flags;
3605 if (orinoco_lock(priv, &flags) != 0)
3606 return -EBUSY;
3608 number = priv->spy_number;
3609 if ((number > 0) && (srq->pointer)) {
3610 /* Create address struct */
3611 for (i = 0; i < number; i++) {
3612 memcpy(address[i].sa_data, priv->spy_address[i],
3613 ETH_ALEN);
3614 address[i].sa_family = AF_UNIX;
3616 /* Copy stats */
3617 /* In theory, we should disable irqs while copying the stats
3618 * because the rx path might update it in the middle...
3619 * Bah, who care ? - Jean II */
3620 memcpy(&spy_stat, priv->spy_stat,
3621 sizeof(struct iw_quality) * IW_MAX_SPY);
3622 for (i=0; i < number; i++)
3623 priv->spy_stat[i].updated = 0;
3626 orinoco_unlock(priv, &flags);
3628 /* Push stuff to user space */
3629 srq->length = number;
3630 if(copy_to_user(srq->pointer, address,
3631 sizeof(struct sockaddr) * number))
3632 return -EFAULT;
3633 if(copy_to_user(srq->pointer + (sizeof(struct sockaddr)*number),
3634 &spy_stat, sizeof(struct iw_quality) * number))
3635 return -EFAULT;
3637 return 0;
3640 static int
3641 orinoco_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
3643 struct orinoco_private *priv = netdev_priv(dev);
3644 struct iwreq *wrq = (struct iwreq *)rq;
3645 int err = 0;
3646 int tmp;
3647 int changed = 0;
3648 unsigned long flags;
3650 TRACE_ENTER(dev->name);
3652 /* In theory, we could allow most of the the SET stuff to be
3653 * done. In practice, the lapse of time at startup when the
3654 * card is not ready is very short, so why bother... Note
3655 * that netif_device_present is different from up/down
3656 * (ifconfig), when the device is not yet up, it is usually
3657 * already ready... Jean II */
3658 if (! netif_device_present(dev))
3659 return -ENODEV;
3661 switch (cmd) {
3662 case SIOCGIWNAME:
3663 strcpy(wrq->u.name, "IEEE 802.11-DS");
3664 break;
3666 case SIOCGIWAP:
3667 wrq->u.ap_addr.sa_family = ARPHRD_ETHER;
3668 err = orinoco_hw_get_bssid(priv, wrq->u.ap_addr.sa_data);
3669 break;
3671 case SIOCGIWRANGE:
3672 err = orinoco_ioctl_getiwrange(dev, &wrq->u.data);
3673 break;
3675 case SIOCSIWMODE:
3676 if (orinoco_lock(priv, &flags) != 0)
3677 return -EBUSY;
3678 switch (wrq->u.mode) {
3679 case IW_MODE_ADHOC:
3680 if (! (priv->has_ibss || priv->has_port3) )
3681 err = -EINVAL;
3682 else {
3683 priv->iw_mode = IW_MODE_ADHOC;
3684 changed = 1;
3686 break;
3688 case IW_MODE_INFRA:
3689 priv->iw_mode = IW_MODE_INFRA;
3690 changed = 1;
3691 break;
3693 default:
3694 err = -EINVAL;
3695 break;
3697 set_port_type(priv);
3698 orinoco_unlock(priv, &flags);
3699 break;
3701 case SIOCGIWMODE:
3702 if (orinoco_lock(priv, &flags) != 0)
3703 return -EBUSY;
3704 wrq->u.mode = priv->iw_mode;
3705 orinoco_unlock(priv, &flags);
3706 break;
3708 case SIOCSIWENCODE:
3709 err = orinoco_ioctl_setiwencode(dev, &wrq->u.encoding);
3710 if (! err)
3711 changed = 1;
3712 break;
3714 case SIOCGIWENCODE:
3715 if (! capable(CAP_NET_ADMIN)) {
3716 err = -EPERM;
3717 break;
3720 err = orinoco_ioctl_getiwencode(dev, &wrq->u.encoding);
3721 break;
3723 case SIOCSIWESSID:
3724 err = orinoco_ioctl_setessid(dev, &wrq->u.essid);
3725 if (! err)
3726 changed = 1;
3727 break;
3729 case SIOCGIWESSID:
3730 err = orinoco_ioctl_getessid(dev, &wrq->u.essid);
3731 break;
3733 case SIOCSIWNICKN:
3734 err = orinoco_ioctl_setnick(dev, &wrq->u.data);
3735 if (! err)
3736 changed = 1;
3737 break;
3739 case SIOCGIWNICKN:
3740 err = orinoco_ioctl_getnick(dev, &wrq->u.data);
3741 break;
3743 case SIOCGIWFREQ:
3744 tmp = orinoco_hw_get_freq(priv);
3745 if (tmp < 0) {
3746 err = tmp;
3747 } else {
3748 wrq->u.freq.m = tmp;
3749 wrq->u.freq.e = 1;
3751 break;
3753 case SIOCSIWFREQ:
3754 err = orinoco_ioctl_setfreq(dev, &wrq->u.freq);
3755 if (! err)
3756 changed = 1;
3757 break;
3759 case SIOCGIWSENS:
3760 err = orinoco_ioctl_getsens(dev, &wrq->u.sens);
3761 break;
3763 case SIOCSIWSENS:
3764 err = orinoco_ioctl_setsens(dev, &wrq->u.sens);
3765 if (! err)
3766 changed = 1;
3767 break;
3769 case SIOCGIWRTS:
3770 wrq->u.rts.value = priv->rts_thresh;
3771 wrq->u.rts.disabled = (wrq->u.rts.value == 2347);
3772 wrq->u.rts.fixed = 1;
3773 break;
3775 case SIOCSIWRTS:
3776 err = orinoco_ioctl_setrts(dev, &wrq->u.rts);
3777 if (! err)
3778 changed = 1;
3779 break;
3781 case SIOCSIWFRAG:
3782 err = orinoco_ioctl_setfrag(dev, &wrq->u.frag);
3783 if (! err)
3784 changed = 1;
3785 break;
3787 case SIOCGIWFRAG:
3788 err = orinoco_ioctl_getfrag(dev, &wrq->u.frag);
3789 break;
3791 case SIOCSIWRATE:
3792 err = orinoco_ioctl_setrate(dev, &wrq->u.bitrate);
3793 if (! err)
3794 changed = 1;
3795 break;
3797 case SIOCGIWRATE:
3798 err = orinoco_ioctl_getrate(dev, &wrq->u.bitrate);
3799 break;
3801 case SIOCSIWPOWER:
3802 err = orinoco_ioctl_setpower(dev, &wrq->u.power);
3803 if (! err)
3804 changed = 1;
3805 break;
3807 case SIOCGIWPOWER:
3808 err = orinoco_ioctl_getpower(dev, &wrq->u.power);
3809 break;
3811 case SIOCGIWTXPOW:
3812 /* The card only supports one tx power, so this is easy */
3813 wrq->u.txpower.value = 15; /* dBm */
3814 wrq->u.txpower.fixed = 1;
3815 wrq->u.txpower.disabled = 0;
3816 wrq->u.txpower.flags = IW_TXPOW_DBM;
3817 break;
3819 case SIOCSIWRETRY:
3820 err = -EOPNOTSUPP;
3821 break;
3823 case SIOCGIWRETRY:
3824 err = orinoco_ioctl_getretry(dev, &wrq->u.retry);
3825 break;
3827 case SIOCSIWSPY:
3828 err = orinoco_ioctl_setspy(dev, &wrq->u.data);
3829 break;
3831 case SIOCGIWSPY:
3832 err = orinoco_ioctl_getspy(dev, &wrq->u.data);
3833 break;
3835 case SIOCGIWPRIV:
3836 if (wrq->u.data.pointer) {
3837 struct iw_priv_args privtab[] = {
3838 { SIOCIWFIRSTPRIV + 0x0, 0, 0, "force_reset" },
3839 { SIOCIWFIRSTPRIV + 0x1, 0, 0, "card_reset" },
3840 { SIOCIWFIRSTPRIV + 0x2,
3841 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3842 0, "set_port3" },
3843 { SIOCIWFIRSTPRIV + 0x3, 0,
3844 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3845 "get_port3" },
3846 { SIOCIWFIRSTPRIV + 0x4,
3847 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3848 0, "set_preamble" },
3849 { SIOCIWFIRSTPRIV + 0x5, 0,
3850 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3851 "get_preamble" },
3852 { SIOCIWFIRSTPRIV + 0x6,
3853 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3854 0, "set_ibssport" },
3855 { SIOCIWFIRSTPRIV + 0x7, 0,
3856 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3857 "get_ibssport" },
3858 { SIOCIWLASTPRIV, 0, 0, "dump_recs" },
3861 wrq->u.data.length = sizeof(privtab) / sizeof(privtab[0]);
3862 if (copy_to_user(wrq->u.data.pointer, privtab, sizeof(privtab)))
3863 err = -EFAULT;
3865 break;
3867 case SIOCIWFIRSTPRIV + 0x0: /* force_reset */
3868 case SIOCIWFIRSTPRIV + 0x1: /* card_reset */
3869 if (! capable(CAP_NET_ADMIN)) {
3870 err = -EPERM;
3871 break;
3874 printk(KERN_DEBUG "%s: Force scheduling reset!\n", dev->name);
3876 schedule_work(&priv->reset_work);
3877 break;
3879 case SIOCIWFIRSTPRIV + 0x2: /* set_port3 */
3880 if (! capable(CAP_NET_ADMIN)) {
3881 err = -EPERM;
3882 break;
3885 err = orinoco_ioctl_setport3(dev, wrq);
3886 if (! err)
3887 changed = 1;
3888 break;
3890 case SIOCIWFIRSTPRIV + 0x3: /* get_port3 */
3891 err = orinoco_ioctl_getport3(dev, wrq);
3892 break;
3894 case SIOCIWFIRSTPRIV + 0x4: /* set_preamble */
3895 if (! capable(CAP_NET_ADMIN)) {
3896 err = -EPERM;
3897 break;
3900 /* 802.11b has recently defined some short preamble.
3901 * Basically, the Phy header has been reduced in size.
3902 * This increase performance, especially at high rates
3903 * (the preamble is transmitted at 1Mb/s), unfortunately
3904 * this give compatibility troubles... - Jean II */
3905 if(priv->has_preamble) {
3906 int val = *( (int *) wrq->u.name );
3908 if (orinoco_lock(priv, &flags) != 0)
3909 return -EBUSY;
3910 if (val)
3911 priv->preamble = 1;
3912 else
3913 priv->preamble = 0;
3914 orinoco_unlock(priv, &flags);
3915 changed = 1;
3916 } else
3917 err = -EOPNOTSUPP;
3918 break;
3920 case SIOCIWFIRSTPRIV + 0x5: /* get_preamble */
3921 if(priv->has_preamble) {
3922 int *val = (int *)wrq->u.name;
3924 if (orinoco_lock(priv, &flags) != 0)
3925 return -EBUSY;
3926 *val = priv->preamble;
3927 orinoco_unlock(priv, &flags);
3928 } else
3929 err = -EOPNOTSUPP;
3930 break;
3931 case SIOCIWFIRSTPRIV + 0x6: /* set_ibssport */
3932 if (! capable(CAP_NET_ADMIN)) {
3933 err = -EPERM;
3934 break;
3937 err = orinoco_ioctl_setibssport(dev, wrq);
3938 if (! err)
3939 changed = 1;
3940 break;
3942 case SIOCIWFIRSTPRIV + 0x7: /* get_ibssport */
3943 err = orinoco_ioctl_getibssport(dev, wrq);
3944 break;
3946 case SIOCIWLASTPRIV:
3947 err = orinoco_debug_dump_recs(dev);
3948 if (err)
3949 printk(KERN_ERR "%s: Unable to dump records (%d)\n",
3950 dev->name, err);
3951 break;
3954 default:
3955 err = -EOPNOTSUPP;
3958 if (! err && changed && netif_running(dev)) {
3959 err = orinoco_reconfigure(dev);
3962 TRACE_EXIT(dev->name);
3964 return err;
3967 struct {
3968 u16 rid;
3969 char *name;
3970 int displaytype;
3971 #define DISPLAY_WORDS 0
3972 #define DISPLAY_BYTES 1
3973 #define DISPLAY_STRING 2
3974 #define DISPLAY_XSTRING 3
3975 } record_table[] = {
3976 #define DEBUG_REC(name,type) { HERMES_RID_##name, #name, DISPLAY_##type }
3977 DEBUG_REC(CNFPORTTYPE,WORDS),
3978 DEBUG_REC(CNFOWNMACADDR,BYTES),
3979 DEBUG_REC(CNFDESIREDSSID,STRING),
3980 DEBUG_REC(CNFOWNCHANNEL,WORDS),
3981 DEBUG_REC(CNFOWNSSID,STRING),
3982 DEBUG_REC(CNFOWNATIMWINDOW,WORDS),
3983 DEBUG_REC(CNFSYSTEMSCALE,WORDS),
3984 DEBUG_REC(CNFMAXDATALEN,WORDS),
3985 DEBUG_REC(CNFPMENABLED,WORDS),
3986 DEBUG_REC(CNFPMEPS,WORDS),
3987 DEBUG_REC(CNFMULTICASTRECEIVE,WORDS),
3988 DEBUG_REC(CNFMAXSLEEPDURATION,WORDS),
3989 DEBUG_REC(CNFPMHOLDOVERDURATION,WORDS),
3990 DEBUG_REC(CNFOWNNAME,STRING),
3991 DEBUG_REC(CNFOWNDTIMPERIOD,WORDS),
3992 DEBUG_REC(CNFMULTICASTPMBUFFERING,WORDS),
3993 DEBUG_REC(CNFWEPENABLED_AGERE,WORDS),
3994 DEBUG_REC(CNFMANDATORYBSSID_SYMBOL,WORDS),
3995 DEBUG_REC(CNFWEPDEFAULTKEYID,WORDS),
3996 DEBUG_REC(CNFDEFAULTKEY0,BYTES),
3997 DEBUG_REC(CNFDEFAULTKEY1,BYTES),
3998 DEBUG_REC(CNFMWOROBUST_AGERE,WORDS),
3999 DEBUG_REC(CNFDEFAULTKEY2,BYTES),
4000 DEBUG_REC(CNFDEFAULTKEY3,BYTES),
4001 DEBUG_REC(CNFWEPFLAGS_INTERSIL,WORDS),
4002 DEBUG_REC(CNFWEPKEYMAPPINGTABLE,WORDS),
4003 DEBUG_REC(CNFAUTHENTICATION,WORDS),
4004 DEBUG_REC(CNFMAXASSOCSTA,WORDS),
4005 DEBUG_REC(CNFKEYLENGTH_SYMBOL,WORDS),
4006 DEBUG_REC(CNFTXCONTROL,WORDS),
4007 DEBUG_REC(CNFROAMINGMODE,WORDS),
4008 DEBUG_REC(CNFHOSTAUTHENTICATION,WORDS),
4009 DEBUG_REC(CNFRCVCRCERROR,WORDS),
4010 DEBUG_REC(CNFMMLIFE,WORDS),
4011 DEBUG_REC(CNFALTRETRYCOUNT,WORDS),
4012 DEBUG_REC(CNFBEACONINT,WORDS),
4013 DEBUG_REC(CNFAPPCFINFO,WORDS),
4014 DEBUG_REC(CNFSTAPCFINFO,WORDS),
4015 DEBUG_REC(CNFPRIORITYQUSAGE,WORDS),
4016 DEBUG_REC(CNFTIMCTRL,WORDS),
4017 DEBUG_REC(CNFTHIRTY2TALLY,WORDS),
4018 DEBUG_REC(CNFENHSECURITY,WORDS),
4019 DEBUG_REC(CNFGROUPADDRESSES,BYTES),
4020 DEBUG_REC(CNFCREATEIBSS,WORDS),
4021 DEBUG_REC(CNFFRAGMENTATIONTHRESHOLD,WORDS),
4022 DEBUG_REC(CNFRTSTHRESHOLD,WORDS),
4023 DEBUG_REC(CNFTXRATECONTROL,WORDS),
4024 DEBUG_REC(CNFPROMISCUOUSMODE,WORDS),
4025 DEBUG_REC(CNFBASICRATES_SYMBOL,WORDS),
4026 DEBUG_REC(CNFPREAMBLE_SYMBOL,WORDS),
4027 DEBUG_REC(CNFSHORTPREAMBLE,WORDS),
4028 DEBUG_REC(CNFWEPKEYS_AGERE,BYTES),
4029 DEBUG_REC(CNFEXCLUDELONGPREAMBLE,WORDS),
4030 DEBUG_REC(CNFTXKEY_AGERE,WORDS),
4031 DEBUG_REC(CNFAUTHENTICATIONRSPTO,WORDS),
4032 DEBUG_REC(CNFBASICRATES,WORDS),
4033 DEBUG_REC(CNFSUPPORTEDRATES,WORDS),
4034 DEBUG_REC(CNFTICKTIME,WORDS),
4035 DEBUG_REC(CNFSCANREQUEST,WORDS),
4036 DEBUG_REC(CNFJOINREQUEST,WORDS),
4037 DEBUG_REC(CNFAUTHENTICATESTATION,WORDS),
4038 DEBUG_REC(CNFCHANNELINFOREQUEST,WORDS),
4039 DEBUG_REC(MAXLOADTIME,WORDS),
4040 DEBUG_REC(DOWNLOADBUFFER,WORDS),
4041 DEBUG_REC(PRIID,WORDS),
4042 DEBUG_REC(PRISUPRANGE,WORDS),
4043 DEBUG_REC(CFIACTRANGES,WORDS),
4044 DEBUG_REC(NICSERNUM,XSTRING),
4045 DEBUG_REC(NICID,WORDS),
4046 DEBUG_REC(MFISUPRANGE,WORDS),
4047 DEBUG_REC(CFISUPRANGE,WORDS),
4048 DEBUG_REC(CHANNELLIST,WORDS),
4049 DEBUG_REC(REGULATORYDOMAINS,WORDS),
4050 DEBUG_REC(TEMPTYPE,WORDS),
4051 /* DEBUG_REC(CIS,BYTES), */
4052 DEBUG_REC(STAID,WORDS),
4053 DEBUG_REC(CURRENTSSID,STRING),
4054 DEBUG_REC(CURRENTBSSID,BYTES),
4055 DEBUG_REC(COMMSQUALITY,WORDS),
4056 DEBUG_REC(CURRENTTXRATE,WORDS),
4057 DEBUG_REC(CURRENTBEACONINTERVAL,WORDS),
4058 DEBUG_REC(CURRENTSCALETHRESHOLDS,WORDS),
4059 DEBUG_REC(PROTOCOLRSPTIME,WORDS),
4060 DEBUG_REC(SHORTRETRYLIMIT,WORDS),
4061 DEBUG_REC(LONGRETRYLIMIT,WORDS),
4062 DEBUG_REC(MAXTRANSMITLIFETIME,WORDS),
4063 DEBUG_REC(MAXRECEIVELIFETIME,WORDS),
4064 DEBUG_REC(CFPOLLABLE,WORDS),
4065 DEBUG_REC(AUTHENTICATIONALGORITHMS,WORDS),
4066 DEBUG_REC(PRIVACYOPTIONIMPLEMENTED,WORDS),
4067 DEBUG_REC(OWNMACADDR,BYTES),
4068 DEBUG_REC(SCANRESULTSTABLE,WORDS),
4069 DEBUG_REC(PHYTYPE,WORDS),
4070 DEBUG_REC(CURRENTCHANNEL,WORDS),
4071 DEBUG_REC(CURRENTPOWERSTATE,WORDS),
4072 DEBUG_REC(CCAMODE,WORDS),
4073 DEBUG_REC(SUPPORTEDDATARATES,WORDS),
4074 DEBUG_REC(BUILDSEQ,BYTES),
4075 DEBUG_REC(FWID,XSTRING)
4076 #undef DEBUG_REC
4079 #define DEBUG_LTV_SIZE 128
4081 static int orinoco_debug_dump_recs(struct net_device *dev)
4083 struct orinoco_private *priv = netdev_priv(dev);
4084 hermes_t *hw = &priv->hw;
4085 u8 *val8;
4086 u16 *val16;
4087 int i,j;
4088 u16 length;
4089 int err;
4091 /* I'm not sure: we might have a lock here, so we'd better go
4092 atomic, just in case. */
4093 val8 = kmalloc(DEBUG_LTV_SIZE + 2, GFP_ATOMIC);
4094 if (! val8)
4095 return -ENOMEM;
4096 val16 = (u16 *)val8;
4098 for (i = 0; i < ARRAY_SIZE(record_table); i++) {
4099 u16 rid = record_table[i].rid;
4100 int len;
4102 memset(val8, 0, DEBUG_LTV_SIZE + 2);
4104 err = hermes_read_ltv(hw, USER_BAP, rid, DEBUG_LTV_SIZE,
4105 &length, val8);
4106 if (err) {
4107 DEBUG(0, "Error %d reading RID 0x%04x\n", err, rid);
4108 continue;
4110 val16 = (u16 *)val8;
4111 if (length == 0)
4112 continue;
4114 printk(KERN_DEBUG "%-15s (0x%04x): length=%d (%d bytes)\tvalue=",
4115 record_table[i].name,
4116 rid, length, (length-1)*2);
4117 len = min(((int)length-1)*2, DEBUG_LTV_SIZE);
4119 switch (record_table[i].displaytype) {
4120 case DISPLAY_WORDS:
4121 for (j = 0; j < len / 2; j++)
4122 printk("%04X-", le16_to_cpu(val16[j]));
4123 break;
4125 case DISPLAY_BYTES:
4126 default:
4127 for (j = 0; j < len; j++)
4128 printk("%02X:", val8[j]);
4129 break;
4131 case DISPLAY_STRING:
4132 len = min(len, le16_to_cpu(val16[0])+2);
4133 val8[len] = '\0';
4134 printk("\"%s\"", (char *)&val16[1]);
4135 break;
4137 case DISPLAY_XSTRING:
4138 printk("'%s'", (char *)val8);
4141 printk("\n");
4144 kfree(val8);
4146 return 0;
4149 /********************************************************************/
4150 /* Debugging */
4151 /********************************************************************/
4153 #if 0
4154 static void show_rx_frame(struct orinoco_rxframe_hdr *frame)
4156 printk(KERN_DEBUG "RX descriptor:\n");
4157 printk(KERN_DEBUG " status = 0x%04x\n", frame->desc.status);
4158 printk(KERN_DEBUG " time = 0x%08x\n", frame->desc.time);
4159 printk(KERN_DEBUG " silence = 0x%02x\n", frame->desc.silence);
4160 printk(KERN_DEBUG " signal = 0x%02x\n", frame->desc.signal);
4161 printk(KERN_DEBUG " rate = 0x%02x\n", frame->desc.rate);
4162 printk(KERN_DEBUG " rxflow = 0x%02x\n", frame->desc.rxflow);
4163 printk(KERN_DEBUG " reserved = 0x%08x\n", frame->desc.reserved);
4165 printk(KERN_DEBUG "IEEE 802.11 header:\n");
4166 printk(KERN_DEBUG " frame_ctl = 0x%04x\n",
4167 frame->p80211.frame_ctl);
4168 printk(KERN_DEBUG " duration_id = 0x%04x\n",
4169 frame->p80211.duration_id);
4170 printk(KERN_DEBUG " addr1 = %02x:%02x:%02x:%02x:%02x:%02x\n",
4171 frame->p80211.addr1[0], frame->p80211.addr1[1],
4172 frame->p80211.addr1[2], frame->p80211.addr1[3],
4173 frame->p80211.addr1[4], frame->p80211.addr1[5]);
4174 printk(KERN_DEBUG " addr2 = %02x:%02x:%02x:%02x:%02x:%02x\n",
4175 frame->p80211.addr2[0], frame->p80211.addr2[1],
4176 frame->p80211.addr2[2], frame->p80211.addr2[3],
4177 frame->p80211.addr2[4], frame->p80211.addr2[5]);
4178 printk(KERN_DEBUG " addr3 = %02x:%02x:%02x:%02x:%02x:%02x\n",
4179 frame->p80211.addr3[0], frame->p80211.addr3[1],
4180 frame->p80211.addr3[2], frame->p80211.addr3[3],
4181 frame->p80211.addr3[4], frame->p80211.addr3[5]);
4182 printk(KERN_DEBUG " seq_ctl = 0x%04x\n",
4183 frame->p80211.seq_ctl);
4184 printk(KERN_DEBUG " addr4 = %02x:%02x:%02x:%02x:%02x:%02x\n",
4185 frame->p80211.addr4[0], frame->p80211.addr4[1],
4186 frame->p80211.addr4[2], frame->p80211.addr4[3],
4187 frame->p80211.addr4[4], frame->p80211.addr4[5]);
4188 printk(KERN_DEBUG " data_len = 0x%04x\n",
4189 frame->p80211.data_len);
4191 printk(KERN_DEBUG "IEEE 802.3 header:\n");
4192 printk(KERN_DEBUG " dest = %02x:%02x:%02x:%02x:%02x:%02x\n",
4193 frame->p8023.h_dest[0], frame->p8023.h_dest[1],
4194 frame->p8023.h_dest[2], frame->p8023.h_dest[3],
4195 frame->p8023.h_dest[4], frame->p8023.h_dest[5]);
4196 printk(KERN_DEBUG " src = %02x:%02x:%02x:%02x:%02x:%02x\n",
4197 frame->p8023.h_source[0], frame->p8023.h_source[1],
4198 frame->p8023.h_source[2], frame->p8023.h_source[3],
4199 frame->p8023.h_source[4], frame->p8023.h_source[5]);
4200 printk(KERN_DEBUG " len = 0x%04x\n", frame->p8023.h_proto);
4202 printk(KERN_DEBUG "IEEE 802.2 LLC/SNAP header:\n");
4203 printk(KERN_DEBUG " DSAP = 0x%02x\n", frame->p8022.dsap);
4204 printk(KERN_DEBUG " SSAP = 0x%02x\n", frame->p8022.ssap);
4205 printk(KERN_DEBUG " ctrl = 0x%02x\n", frame->p8022.ctrl);
4206 printk(KERN_DEBUG " OUI = %02x:%02x:%02x\n",
4207 frame->p8022.oui[0], frame->p8022.oui[1], frame->p8022.oui[2]);
4208 printk(KERN_DEBUG " ethertype = 0x%04x\n", frame->ethertype);
4210 #endif /* 0 */
4212 /********************************************************************/
4213 /* Module initialization */
4214 /********************************************************************/
4216 EXPORT_SYMBOL(alloc_orinocodev);
4217 EXPORT_SYMBOL(free_orinocodev);
4219 EXPORT_SYMBOL(__orinoco_up);
4220 EXPORT_SYMBOL(__orinoco_down);
4221 EXPORT_SYMBOL(orinoco_stop);
4222 EXPORT_SYMBOL(orinoco_reinit_firmware);
4224 EXPORT_SYMBOL(orinoco_interrupt);
4226 /* Can't be declared "const" or the whole __initdata section will
4227 * become const */
4228 static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
4229 " (David Gibson <hermes@gibson.dropbear.id.au>, "
4230 "Pavel Roskin <proski@gnu.org>, et al)";
4232 static int __init init_orinoco(void)
4234 printk(KERN_DEBUG "%s\n", version);
4235 return 0;
4238 static void __exit exit_orinoco(void)
4242 module_init(init_orinoco);
4243 module_exit(exit_orinoco);