1 /* orinoco_cs.c 0.03 - (formerly known as dldwd_cs.c)
3 * A driver for "Hermes" chipset based PCMCIA wireless adaptors, such
4 * as the Lucent WavelanIEEE/Orinoco cards and their OEM (Cabletron/
5 * EnteraSys RoamAbout 802.11, ELSA Airlancer, Melco Buffalo and others).
6 * It should also be usable on various Prism II based cards such as the
7 * Linksys, D-Link and Farallon Skyline. It should also work on Symbol
8 * cards such as the 3Com AirConnect and Ericsson WLAN.
10 * Copyright (C) 2000 David Gibson, Linuxcare Australia <hermes@gibson.dropbear.id.au>
11 * With some help from :
12 * Copyright (C) 2001 Jean Tourrilhes, HP Labs <jt@hpl.hp.com>
14 * Based on dummy_cs.c 1.27 2000/06/12 21:27:25
16 * Portions based on wvlan_cs.c 1.0.6, Copyright Andreas Neuhaus <andy@fasta.fh-dortmund.de>
17 * http://www.fasta.fh-dortmund.de/users/andy/wvlan/
19 * The contents of this file are subject to the Mozilla Public License
20 * Version 1.1 (the "License"); you may not use this file except in
21 * compliance with the License. You may obtain a copy of the License
22 * at http://www.mozilla.org/MPL/
24 * Software distributed under the License is distributed on an "AS IS"
25 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
26 * the License for the specific language governing rights and
27 * limitations under the License.
29 * The initial developer of the original code is David A. Hinds
30 * <dahinds@users.sourceforge.net>. Portions created by David
31 * A. Hinds are Copyright (C) 1999 David A. Hinds. All Rights
34 * Alternatively, the contents of this file may be used under the
35 * terms of the GNU Public License version 2 (the "GPL"), in which
36 * case the provisions of the GPL are applicable instead of the above.
37 * If you wish to allow the use of your version of this file only
38 * under the terms of the GPL and not to allow others to use your
39 * version of this file under the MPL, indicate your decision by
40 * deleting the provisions above and replace them with the notice and
41 * other provisions required by the GPL. If you do not delete the
42 * provisions above, a recipient may use your version of this file
43 * under either the MPL or the GPL.
48 * The basic principle of operation is that everything except the
49 * interrupt handler is serialized through a single spinlock in the
50 * dldwd_priv_t structure, using dldwd_lock() and
51 * dldwd_unlock() (which in turn use spin_lock_bh() and spin_unlock_bh()).
53 * The kernel's IRQ handling stuff ensures that the interrupt handler
54 * does not re-enter itself. The interrupt handler is written such
55 * that everything it does is safe without a lock: chiefly this means
56 * that the Rx path uses one of the Hermes chipset's BAPs while
57 * everything else uses the other.
59 * For the moment access to the device statistics from the interrupt
60 * handler is unsafe - we just put up with any resulting errors in the
61 * statisics. FIXME: This should probably be changed to store the
62 * stats in atomic types.
64 * EXCEPT that we don't want the irq handler running when we actually
65 * reset or shut down the card, because strange things might happen
66 * (probably the worst would be one packet of garbage, but you can't
67 * be too careful). For this we use __dldwd_stop_irqs() which will set
68 * a flag to disable the interrupt handler, and wait for any
69 * outstanding instances of the handler to complete. THIS WILL LOSE
70 * INTERRUPTS! so it shouldn't be used except for resets, when we
71 * don't care about that.*/
74 * Tentative changelog...
76 * v0.01 -> v0.02 - 21/3/2001 - Jean II
77 * o Allow to use regular ethX device name instead of dldwdX
78 * o Warning on IBSS with ESSID=any for firmware 6.06
79 * o Put proper range.throughput values (optimistic)
80 * o IWSPY support (IOCTL and stat gather in Rx path)
81 * o Allow setting frequency in Ad-Hoc mode
82 * o Disable WEP setting if !has_wep to work on old firmware
84 * o Start adding support for Samsung/Compaq firmware
86 * v0.02 -> v0.03 - 23/3/2001 - Jean II
87 * o Start adding Symbol support - need to check all that
88 * o Fix Prism2/Symbol WEP to accept 128 bits keys
89 * o Add Symbol WEP (add authentication type)
90 * o Add Prism2/Symbol rate
91 * o Add PM timeout (holdover duration)
92 * o Enable "iwconfig eth0 key off" and friends (toggle flags)
93 * o Enable "iwconfig eth0 power unicast/all" (toggle flags)
94 * o Try with an intel card. It report firmware 1.01, behave like
95 * an antiquated firmware, however on windows it says 2.00. Yuck !
96 * o Workaround firmware bug in allocate buffer (Intel 1.01)
97 * o Finish external renaming to orinoco...
98 * o Testing with various Wavelan firmwares
101 * o inline functions (lot's of candidate, need to reorder code)
102 * o Separate Pcmcia specific code to help Airport/Mini PCI driver
103 * o Test PrismII/Symbol cards & firmware versions
106 #include <linux/module.h>
107 #include <linux/kernel.h>
108 #include <linux/init.h>
109 #include <linux/sched.h>
110 #include <linux/ptrace.h>
111 #include <linux/malloc.h>
112 #include <linux/string.h>
113 #include <linux/timer.h>
114 #include <linux/ioport.h>
115 #include <asm/uaccess.h>
117 #include <asm/system.h>
118 #include <linux/proc_fs.h>
119 #include <linux/netdevice.h>
120 #include <linux/if_arp.h>
121 #include <linux/etherdevice.h>
122 #include <linux/wireless.h>
124 #include <pcmcia/version.h>
125 #include <pcmcia/cs_types.h>
126 #include <pcmcia/cs.h>
127 #include <pcmcia/cistpl.h>
128 #include <pcmcia/cisreg.h>
129 #include <pcmcia/ds.h>
130 #include <pcmcia/bus_ops.h>
135 static int pc_debug = PCMCIA_DEBUG;
136 static char *version = "orinoco_cs.c 0.03 (David Gibson <hermes@gibson.dropbear.id.au>)";
137 MODULE_PARM(pc_debug, "i");
138 #define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args)
139 #define DEBUGMORE(n, args...) do { if (pc_debug>(n)) printk(args); } while (0)
141 #define DEBUG(n, args...) do { } while (0)
142 #define DEBUGMORE(n, args...) do { } while (0)
145 #define TRACE_ENTER(devname) DEBUG(2, "%s: -> " __FUNCTION__ "()\n", devname);
146 #define TRACE_EXIT(devname) DEBUG(2, "%s: <- " __FUNCTION__ "()\n", devname);
148 #define MAX(a, b) ( (a) > (b) ? (a) : (b) )
149 #define MIN(a, b) ( (a) < (b) ? (a) : (b) )
151 #define RUP_EVEN(a) ( (a) % 2 ? (a) + 1 : (a) )
154 #if (! defined (WIRELESS_EXT)) || (WIRELESS_EXT < 10)
155 #error "orinoco_cs requires Wireless extensions v10 or later."
156 #endif /* (! defined (WIRELESS_EXT)) || (WIRELESS_EXT < 10) */
157 #define WIRELESS_SPY // enable iwspy support
159 /*====================================================================*/
161 /* Parameters that can be set with 'insmod' */
163 /* The old way: bit map of interrupts to choose from */
164 /* This means pick from 15, 14, 12, 11, 10, 9, 7, 5, 4, and 3 */
165 static uint irq_mask = 0xdeb8;
166 /* Newer, simpler way of listing specific interrupts */
167 static int irq_list[4] = { -1 };
168 /* Control device name allocation. 0 -> dldwdX ; 1 -> ethX */
171 MODULE_PARM(irq_mask, "i");
172 MODULE_PARM(irq_list, "1-4i");
173 MODULE_PARM(eth, "i");
175 /*====================================================================*/
177 #define DLDWD_MIN_MTU 256
178 #define DLDWD_MAX_MTU (HERMES_FRAME_LEN_MAX - ENCAPS_OVERHEAD)
180 #define LTV_BUF_SIZE 128
183 #define DLDWD_MACPORT 0
184 #define IRQ_LOOP_MAX 10
185 #define TX_NICBUF_SIZE 2048
186 #define TX_NICBUF_SIZE_BUG 1585 /* Bug in Intel firmware */
188 #define MAX_KEY_SIZE 14
189 #define LARGE_KEY_SIZE 13
190 #define SMALL_KEY_SIZE 5
191 #define MAX_FRAME_SIZE 2304
193 const long channel_frequency[] = {
194 2412, 2417, 2422, 2427, 2432, 2437, 2442,
195 2447, 2452, 2457, 2462, 2467, 2472, 2484
198 #define NUM_CHANNELS ( sizeof(channel_frequency) / sizeof(channel_frequency[0]) )
200 /* This tables gives the actual meanings of the bitrate IDs returned by the firmware.
201 It gives the rate in halfMb/s, negative indicates auto mode */
202 const int rate_list[] = { 0, 2, 4, -22, 11, 22, -4, -11, 0, 0, 0, 0};
204 #define NUM_RATES (sizeof(rate_list) / sizeof(rate_list[0]))
205 typedef struct dldwd_key {
207 char data[MAX_KEY_SIZE];
208 } __attribute__ ((packed)) dldwd_key_t;
210 typedef dldwd_key_t dldwd_keys_t[MAX_KEYS];
212 typedef struct dldwd_priv {
219 #define DLDWD_STATE_INIRQ 0
220 #define DLDWD_STATE_DOIRQ 1
222 /* Net device stuff */
223 struct net_device ndev;
224 struct net_device_stats stats;
225 struct iw_statistics wstats;
228 /* Hardware control variables */
232 /* Capabilities of the hardware/firmware */
233 hermes_identity_t firmware_info;
235 #define FIRMWARE_TYPE_LUCENT 1
236 #define FIRMWARE_TYPE_PRISM2 2
237 #define FIRMWARE_TYPE_SYMBOL 3
238 int has_ibss, has_port3, prefer_port3, has_ibss_any;
239 int has_wep, has_big_wep;
242 int broken_reset, broken_allocate;
243 uint16_t channel_mask;
245 /* Current configuration */
247 int port_type, allow_ibss;
248 uint16_t wep_on, wep_auth, tx_key;
250 char nick[IW_ESSID_MAX_SIZE+1];
251 char desired_essid[IW_ESSID_MAX_SIZE+1];
252 uint16_t frag_thresh, mwo_robust;
254 uint16_t ap_density, rts_thresh;
255 uint16_t tx_rate_ctrl;
256 uint16_t pm_on, pm_mcast, pm_period, pm_timeout;
258 int promiscuous, allmulti, mc_count;
262 u_char spy_address[IW_MAX_SPY][ETH_ALEN];
263 struct iw_quality spy_stat[IW_MAX_SPY];
266 /* /proc based debugging stuff */
267 struct proc_dir_entry *dir_dev;
268 struct proc_dir_entry *dir_regs;
269 struct proc_dir_entry *dir_recs;
274 uint16_t duration_id;
275 uint8_t addr1[ETH_ALEN];
276 uint8_t addr2[ETH_ALEN];
277 uint8_t addr3[ETH_ALEN];
279 uint8_t addr4[ETH_ALEN];
281 } __attribute__ ((packed));
283 /* Frame control field constants */
284 #define DLDWD_FCTL_VERS 0x0002
285 #define DLDWD_FCTL_FTYPE 0x000c
286 #define DLDWD_FCTL_STYPE 0x00f0
287 #define DLDWD_FCTL_TODS 0x0100
288 #define DLDWD_FCTL_FROMDS 0x0200
289 #define DLDWD_FCTL_MOREFRAGS 0x0400
290 #define DLDWD_FCTL_RETRY 0x0800
291 #define DLDWD_FCTL_PM 0x1000
292 #define DLDWD_FCTL_MOREDATA 0x2000
293 #define DLDWD_FCTL_WEP 0x4000
294 #define DLDWD_FCTL_ORDER 0x8000
296 #define DLDWD_FTYPE_MGMT 0x0000
297 #define DLDWD_FTYPE_CTL 0x0004
298 #define DLDWD_FTYPE_DATA 0x0008
305 } __attribute__ ((packed));
307 struct dldwd_frame_hdr {
308 hermes_frame_desc_t desc;
309 struct p80211_hdr p80211;
311 struct p8022_hdr p8022;
313 } __attribute__ ((packed));
315 #define P8023_OFFSET (sizeof(hermes_frame_desc_t) + \
316 sizeof(struct p80211_hdr))
317 #define ENCAPS_OVERHEAD (sizeof(struct p8022_hdr) + 2)
320 * Function prototypes
325 static void dldwd_config(dev_link_t * link);
326 static void dldwd_release(u_long arg);
327 static int dldwd_event(event_t event, int priority,
328 event_callback_args_t * args);
330 static dev_link_t *dldwd_attach(void);
331 static void dldwd_detach(dev_link_t *);
333 /* Hardware control routines */
335 static int __dldwd_hw_reset(dldwd_priv_t *priv);
336 static void dldwd_shutdown(dldwd_priv_t *dev);
337 static int dldwd_reset(dldwd_priv_t *dev);
338 static int __dldwd_hw_setup_wep(dldwd_priv_t *priv);
339 static int dldwd_hw_get_bssid(dldwd_priv_t *priv, char buf[ETH_ALEN]);
340 static int dldwd_hw_get_essid(dldwd_priv_t *priv, int *active, char buf[IW_ESSID_MAX_SIZE+1]);
341 static long dldwd_hw_get_freq(dldwd_priv_t *priv);
342 static int dldwd_hw_get_bitratelist(dldwd_priv_t *priv, int *numrates,
343 int32_t *rates, int max);
345 /* Interrupt handling routines */
346 void dldwd_interrupt(int irq, void * dev_id, struct pt_regs *regs);
347 static void __dldwd_ev_tick(dldwd_priv_t *priv, hermes_t *hw);
348 static void __dldwd_ev_wterr(dldwd_priv_t *priv, hermes_t *hw);
349 static void __dldwd_ev_infdrop(dldwd_priv_t *priv, hermes_t *hw);
350 static void __dldwd_ev_info(dldwd_priv_t *priv, hermes_t *hw);
351 static void __dldwd_ev_rx(dldwd_priv_t *priv, hermes_t *hw);
352 static void __dldwd_ev_txexc(dldwd_priv_t *priv, hermes_t *hw);
353 static void __dldwd_ev_tx(dldwd_priv_t *priv, hermes_t *hw);
354 static void __dldwd_ev_alloc(dldwd_priv_t *priv, hermes_t *hw);
356 /* struct net_device methods */
357 static int dldwd_init(struct net_device *dev);
358 static int dldwd_open(struct net_device *dev);
359 static int dldwd_stop(struct net_device *dev);
361 static int dldwd_xmit(struct sk_buff *skb, struct net_device *dev);
362 static void dldwd_tx_timeout(struct net_device *dev);
364 static struct net_device_stats *dldwd_get_stats(struct net_device *dev);
365 static struct iw_statistics *dldwd_get_wireless_stats(struct net_device *dev);
366 static void dldwd_stat_gather(struct net_device *dev,
368 struct dldwd_frame_hdr *hdr);
370 static int dldwd_ioctl_getiwrange(struct net_device *dev, struct iw_point *rrq);
371 static int dldwd_ioctl_setiwencode(struct net_device *dev, struct iw_point *erq);
372 static int dldwd_ioctl_getiwencode(struct net_device *dev, struct iw_point *erq);
373 static int dldwd_ioctl_setessid(struct net_device *dev, struct iw_point *erq);
374 static int dldwd_ioctl_getessid(struct net_device *dev, struct iw_point *erq);
375 static int dldwd_ioctl_setnick(struct net_device *dev, struct iw_point *nrq);
376 static int dldwd_ioctl_getnick(struct net_device *dev, struct iw_point *nrq);
377 static int dldwd_ioctl_setfreq(struct net_device *dev, struct iw_freq *frq);
378 static int dldwd_ioctl_getsens(struct net_device *dev, struct iw_param *srq);
379 static int dldwd_ioctl_setsens(struct net_device *dev, struct iw_param *srq);
380 static int dldwd_ioctl_setrts(struct net_device *dev, struct iw_param *rrq);
381 static int dldwd_ioctl_setfrag(struct net_device *dev, struct iw_param *frq);
382 static int dldwd_ioctl_getfrag(struct net_device *dev, struct iw_param *frq);
383 static int dldwd_ioctl_setrate(struct net_device *dev, struct iw_param *frq);
384 static int dldwd_ioctl_getrate(struct net_device *dev, struct iw_param *frq);
385 static int dldwd_ioctl_setpower(struct net_device *dev, struct iw_param *prq);
386 static int dldwd_ioctl_getpower(struct net_device *dev, struct iw_param *prq);
387 static int dldwd_ioctl_setport3(struct net_device *dev, struct iwreq *wrq);
388 static int dldwd_ioctl_getport3(struct net_device *dev, struct iwreq *wrq);
389 static int dldwd_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
391 static int dldwd_change_mtu(struct net_device *dev, int new_mtu);
392 static void __dldwd_set_multicast_list(struct net_device *dev);
394 /* /proc debugging stuff */
395 static int dldwd_proc_init(void);
396 static void dldwd_proc_cleanup(void);
397 static int dldwd_proc_dev_init(dldwd_priv_t *dev);
398 static void dldwd_proc_dev_cleanup(dldwd_priv_t *dev);
404 dldwd_lock(dldwd_priv_t *priv)
406 spin_lock_bh(&priv->lock);
410 dldwd_unlock(dldwd_priv_t *priv)
412 spin_unlock_bh(&priv->lock);
416 dldwd_irqs_allowed(dldwd_priv_t *priv)
418 return test_bit(DLDWD_STATE_DOIRQ, &priv->state);
422 __dldwd_stop_irqs(dldwd_priv_t *priv)
424 hermes_t *hw = &priv->hw;
426 hermes_set_irqmask(hw, 0);
427 clear_bit(DLDWD_STATE_DOIRQ, &priv->state);
428 while (test_bit(DLDWD_STATE_INIRQ, &priv->state))
433 __dldwd_start_irqs(dldwd_priv_t *priv, uint16_t irqmask)
435 hermes_t *hw = &priv->hw;
437 TRACE_ENTER(priv->ndev.name);
440 set_bit(DLDWD_STATE_DOIRQ, &priv->state);
441 hermes_set_irqmask(hw, irqmask);
444 TRACE_EXIT(priv->ndev.name);
448 set_port_type(dldwd_priv_t *priv)
450 switch (priv->iw_mode) {
453 priv->allow_ibss = 0;
456 if (priv->prefer_port3) {
458 priv->allow_ibss = 0;
461 priv->allow_ibss = 1;
465 printk(KERN_ERR "%s: Invalid priv->iw_mode in set_port_type()\n",
471 dldwd_set_multicast_list(struct net_device *dev)
473 dldwd_priv_t *priv = dev->priv;
476 __dldwd_set_multicast_list(dev);
481 * Hardware control routines
485 __dldwd_hw_reset(dldwd_priv_t *priv)
487 hermes_t *hw = &priv->hw;
490 if (! priv->broken_reset)
491 return hermes_reset(hw);
494 hermes_write_regn(hw, INTEN, 0);
495 err = hermes_disable_port(hw, 0);
496 hermes_write_regn(hw, EVACK, 0xffff);
502 dldwd_shutdown(dldwd_priv_t *priv)
504 /* hermes_t *hw = &priv->hw; */
507 TRACE_ENTER(priv->ndev.name);
510 __dldwd_stop_irqs(priv);
512 err = __dldwd_hw_reset(priv);
513 if (err && err != -ENODEV) /* If the card is gone, we don't care about shutting it down */
514 printk(KERN_ERR "%s: Error %d shutting down Hermes chipset\n", priv->ndev.name, err);
518 TRACE_EXIT(priv->ndev.name);
522 dldwd_reset(dldwd_priv_t *priv)
524 struct net_device *dev = &priv->ndev;
525 hermes_t *hw = &priv->hw;
530 TRACE_ENTER(priv->ndev.name);
534 __dldwd_stop_irqs(priv);
536 err = __dldwd_hw_reset(priv);
540 frame_size = TX_NICBUF_SIZE;
541 /* This stupid bug is present in Intel firmware 1.10, and
542 * may be fixed in later firmwares - Jean II */
543 if(priv->broken_allocate)
544 frame_size = TX_NICBUF_SIZE_BUG;
545 err = hermes_allocate(hw, frame_size, &priv->txfid);
549 /* Now set up all the parameters on the card */
551 /* Set up the link mode */
553 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNF_PORTTYPE, priv->port_type);
556 if (priv->has_ibss) {
557 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNF_CREATEIBSS,
561 if((strlen(priv->desired_essid) == 0) && (priv->allow_ibss)
562 && (!priv->has_ibss_any)) {
563 printk(KERN_WARNING "%s: This firmware requires an \
564 ESSID in IBSS-Ad-Hoc mode.\n", dev->name);
565 /* With wvlan_cs, in this case, we would crash.
566 * hopefully, this driver will behave better...
571 /* Set up encryption */
573 err = __dldwd_hw_setup_wep(priv);
578 /* Set the desired ESSID */
579 idbuf.len = cpu_to_le16(strlen(priv->desired_essid));
580 memcpy(&idbuf.val, priv->desired_essid, sizeof(idbuf.val));
581 err = hermes_write_ltv(hw, USER_BAP, (priv->port_type == 3) ?
582 HERMES_RID_CNF_OWN_SSID : HERMES_RID_CNF_DESIRED_SSID,
583 HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
588 /* Set the station name */
589 idbuf.len = cpu_to_le16(strlen(priv->nick));
590 memcpy(&idbuf.val, priv->nick, sizeof(idbuf.val));
591 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNF_NICKNAME,
592 HERMES_BYTES_TO_RECLEN(strlen(priv->nick)+2),
597 /* Set the channel/frequency */
598 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNF_CHANNEL, priv->channel);
603 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNF_SYSTEM_SCALE, priv->ap_density);
607 /* Set RTS threshold */
608 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNF_RTS_THRESH, priv->rts_thresh);
612 /* Set fragmentation threshold or MWO robustness */
614 err = hermes_write_wordrec(hw, USER_BAP,
615 HERMES_RID_CNF_MWO_ROBUST, priv->mwo_robust);
617 err = hermes_write_wordrec(hw, USER_BAP,
618 HERMES_RID_CNF_FRAG_THRESH, priv->frag_thresh);
623 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNF_TX_RATE_CTRL,
628 /* Set power management */
630 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNF_PM_ENABLE,
634 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNF_PM_MCAST_RX,
638 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNF_PM_PERIOD,
642 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNF_PM_HOLDOVER,
648 /* Set promiscuity / multicast*/
649 priv->promiscuous = 0;
652 __dldwd_set_multicast_list(dev);
654 err = hermes_enable_port(hw, DLDWD_MACPORT);
658 __dldwd_start_irqs(priv, HERMES_EV_RX | HERMES_EV_ALLOC |
659 HERMES_EV_TX | HERMES_EV_TXEXC |
660 HERMES_EV_WTERR | HERMES_EV_INFO |
666 TRACE_EXIT(priv->ndev.name);
671 static int __dldwd_hw_setup_wep(dldwd_priv_t *priv)
673 hermes_t *hw = &priv->hw;
676 switch (priv->firmware_type) {
677 case FIRMWARE_TYPE_LUCENT: /* Lucent style WEP */
679 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNF_TX_KEY, priv->tx_key);
683 err = HERMES_WRITE_RECORD(hw, USER_BAP, HERMES_RID_CNF_KEYS, &priv->keys);
687 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNF_WEP_ON, priv->wep_on);
692 case FIRMWARE_TYPE_PRISM2: /* Prism II style WEP */
693 case FIRMWARE_TYPE_SYMBOL: /* Symbol style WEP */
695 char keybuf[LARGE_KEY_SIZE+1];
699 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNF_PRISM2_TX_KEY,
704 keybuf[LARGE_KEY_SIZE] = '\0';
706 /* Write all 4 keys */
707 for(i = 0; i < MAX_KEYS; i++) {
708 keylen = priv->keys[i].len;
709 keybuf[SMALL_KEY_SIZE] = '\0';
710 memcpy(keybuf, priv->keys[i].data, keylen);
711 err = HERMES_WRITE_RECORD_LEN(hw, USER_BAP, HERMES_RID_CNF_PRISM2_KEY0, &keybuf, keylen);
715 /* Symbol cards : set the authentication :
716 * 0 -> no encryption, 1 -> open,
717 * 2 -> shared key, 3 -> shared key 128bit only */
718 if (priv->firmware_type == FIRMWARE_TYPE_SYMBOL) {
719 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNF_SYMBOL_AUTH_TYPE, priv->wep_auth);
725 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNF_PRISM2_WEP_ON, priv->wep_on);
732 printk(KERN_ERR "%s: WEP enabled, although not supported!\n",
741 static int dldwd_hw_get_bssid(dldwd_priv_t *priv, char buf[ETH_ALEN])
743 hermes_t *hw = &priv->hw;
748 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENT_BSSID,
749 ETH_ALEN, NULL, buf);
756 static int dldwd_hw_get_essid(dldwd_priv_t *priv, int *active,
757 char buf[IW_ESSID_MAX_SIZE+1])
759 hermes_t *hw = &priv->hw;
761 hermes_id_t essidbuf;
762 char *p = (char *)(&essidbuf.val);
765 TRACE_ENTER(priv->ndev.name);
769 if (strlen(priv->desired_essid) > 0) {
770 /* We read the desired SSID from the hardware rather
771 than from priv->desired_essid, just in case the
772 firmware is allowed to change it on us. I'm not
774 /* My guess is that the OWN_SSID should always be whatever
775 * we set to the card, whereas CURRENT_SSID is the one that
776 * may change... - Jean II */
781 rid = (priv->port_type == 3) ? HERMES_RID_CNF_OWN_SSID :
782 HERMES_RID_CNF_DESIRED_SSID;
784 err = hermes_read_ltv(hw, USER_BAP, rid, sizeof(essidbuf),
791 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENT_SSID,
792 sizeof(essidbuf), NULL, &essidbuf);
797 len = le16_to_cpu(essidbuf.len);
799 memset(buf, 0, sizeof(buf));
806 TRACE_EXIT(priv->ndev.name);
811 static long dldwd_hw_get_freq(dldwd_priv_t *priv)
814 hermes_t *hw = &priv->hw;
821 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CURRENT_CHANNEL, &channel);
825 if ( (channel < 1) || (channel > NUM_CHANNELS) ) {
826 struct net_device *dev = &priv->ndev;
828 printk(KERN_WARNING "%s: Channel out of range (%d)!\n", dev->name, channel);
833 freq = channel_frequency[channel-1] * 100000;
840 return err ? err : freq;
843 static int dldwd_hw_get_bitratelist(dldwd_priv_t *priv, int *numrates,
844 int32_t *rates, int max)
846 hermes_t *hw = &priv->hw;
848 unsigned char *p = (unsigned char *)&list.val;
854 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_DATARATES, sizeof(list),
861 num = le16_to_cpu(list.len);
865 for (i = 0; i < num; i++) {
866 rates[i] = (p[i] & 0x7f) * 500000; /* convert to bps */
873 static inline void show_rx_frame(struct dldwd_frame_hdr *frame) {}
875 static void show_rx_frame(struct dldwd_frame_hdr *frame)
877 printk(KERN_DEBUG "RX descriptor:\n");
878 printk(KERN_DEBUG " status = 0x%04x\n", frame->desc.status);
879 printk(KERN_DEBUG " res1 = 0x%04x\n", frame->desc.res1);
880 printk(KERN_DEBUG " res2 = 0x%04x\n", frame->desc.res2);
881 printk(KERN_DEBUG " q_info = 0x%04x\n", frame->desc.q_info);
882 printk(KERN_DEBUG " res3 = 0x%04x\n", frame->desc.res3);
883 printk(KERN_DEBUG " res4 = 0x%04x\n", frame->desc.res4);
884 printk(KERN_DEBUG " tx_ctl = 0x%04x\n", frame->desc.tx_ctl);
886 printk(KERN_DEBUG "IEEE 802.11 header:\n");
887 printk(KERN_DEBUG " frame_ctl = 0x%04x\n",
888 frame->p80211.frame_ctl);
889 printk(KERN_DEBUG " duration_id = 0x%04x\n",
890 frame->p80211.duration_id);
891 printk(KERN_DEBUG " addr1 = %02x:%02x:%02x:%02x:%02x:%02x\n",
892 frame->p80211.addr1[0], frame->p80211.addr1[1],
893 frame->p80211.addr1[2], frame->p80211.addr1[3],
894 frame->p80211.addr1[4], frame->p80211.addr1[5]);
895 printk(KERN_DEBUG " addr2 = %02x:%02x:%02x:%02x:%02x:%02x\n",
896 frame->p80211.addr2[0], frame->p80211.addr2[1],
897 frame->p80211.addr2[2], frame->p80211.addr2[3],
898 frame->p80211.addr2[4], frame->p80211.addr2[5]);
899 printk(KERN_DEBUG " addr3 = %02x:%02x:%02x:%02x:%02x:%02x\n",
900 frame->p80211.addr3[0], frame->p80211.addr3[1],
901 frame->p80211.addr3[2], frame->p80211.addr3[3],
902 frame->p80211.addr3[4], frame->p80211.addr3[5]);
903 printk(KERN_DEBUG " seq_ctl = 0x%04x\n",
904 frame->p80211.seq_ctl);
905 printk(KERN_DEBUG " addr4 = %02x:%02x:%02x:%02x:%02x:%02x\n",
906 frame->p80211.addr4[0], frame->p80211.addr4[1],
907 frame->p80211.addr4[2], frame->p80211.addr4[3],
908 frame->p80211.addr4[4], frame->p80211.addr4[5]);
909 printk(KERN_DEBUG " data_len = 0x%04x\n",
910 frame->p80211.data_len);
912 printk(KERN_DEBUG "IEEE 802.3 header:\n");
913 printk(KERN_DEBUG " dest = %02x:%02x:%02x:%02x:%02x:%02x\n",
914 frame->p8023.h_dest[0], frame->p8023.h_dest[1],
915 frame->p8023.h_dest[2], frame->p8023.h_dest[3],
916 frame->p8023.h_dest[4], frame->p8023.h_dest[5]);
917 printk(KERN_DEBUG " src = %02x:%02x:%02x:%02x:%02x:%02x\n",
918 frame->p8023.h_source[0], frame->p8023.h_source[1],
919 frame->p8023.h_source[2], frame->p8023.h_source[3],
920 frame->p8023.h_source[4], frame->p8023.h_source[5]);
921 printk(KERN_DEBUG " len = 0x%04x\n", frame->p8023.h_proto);
923 printk(KERN_DEBUG "IEEE 802.2 LLC/SNAP header:\n");
924 printk(KERN_DEBUG " DSAP = 0x%02x\n", frame->p8022.dsap);
925 printk(KERN_DEBUG " SSAP = 0x%02x\n", frame->p8022.ssap);
926 printk(KERN_DEBUG " ctrl = 0x%02x\n", frame->p8022.ctrl);
927 printk(KERN_DEBUG " OUI = %02x:%02x:%02x\n",
928 frame->p8022.oui[0], frame->p8022.oui[1], frame->p8022.oui[2]);
929 printk(KERN_DEBUG " ethertype = 0x%04x\n", frame->ethertype);
936 void dldwd_interrupt(int irq, void * dev_id, struct pt_regs *regs)
938 dldwd_priv_t *priv = (dldwd_priv_t *) dev_id;
939 hermes_t *hw = &priv->hw;
940 struct net_device *dev = &priv->ndev;
941 int count = IRQ_LOOP_MAX;
942 uint16_t evstat, events;
943 static int old_time = 0, timecount = 0; /* Eugh, revolting hack for now */
945 if (test_and_set_bit(DLDWD_STATE_INIRQ, &priv->state))
948 if (! dldwd_irqs_allowed(priv)) {
949 clear_bit(DLDWD_STATE_INIRQ, &priv->state);
953 DEBUG(3, "%s: dldwd_interrupt() irq %d\n", priv->ndev.name, irq);
956 if (jiffies != old_time)
958 if ( (++timecount > 50) || (! count--) ) {
959 printk(KERN_CRIT "%s: IRQ handler is looping too \
960 much! Shutting down.\n",
962 /* Perform an emergency shutdown */
963 clear_bit(DLDWD_STATE_DOIRQ, &priv->state);
964 hermes_set_irqmask(hw, 0);
968 evstat = hermes_read_regn(hw, EVSTAT);
969 DEBUG(3, "__dldwd_interrupt(): count=%d EVSTAT=0x%04x inten=0x%04x\n",
970 count, evstat, hw->inten);
972 events = evstat & hw->inten;
975 if (netif_queue_stopped(dev)) {
976 /* There seems to be a firmware bug which
977 sometimes causes the card to give an
978 interrupt with no event set, when there
979 sould be a Tx completed event. */
980 DEBUG(3, "%s: Interrupt with no event (ALLOCFID=0x%04x)\n",
981 dev->name, (int)hermes_read_regn(hw, ALLOCFID));
982 events = HERMES_EV_TX | HERMES_EV_ALLOC;
983 } else /* Nothing's happening, we're done */
987 /* Check the card hasn't been removed */
988 if (! hermes_present(hw)) {
989 DEBUG(0, "dldwd_interrupt(): card removed\n");
993 if (events & HERMES_EV_TICK)
994 __dldwd_ev_tick(priv, hw);
995 if (events & HERMES_EV_WTERR)
996 __dldwd_ev_wterr(priv, hw);
997 if (events & HERMES_EV_INFDROP)
998 __dldwd_ev_infdrop(priv, hw);
999 if (events & HERMES_EV_INFO)
1000 __dldwd_ev_info(priv, hw);
1001 if (events & HERMES_EV_RX)
1002 __dldwd_ev_rx(priv, hw);
1003 if (events & HERMES_EV_TXEXC)
1004 __dldwd_ev_txexc(priv, hw);
1005 if (events & HERMES_EV_TX)
1006 __dldwd_ev_tx(priv, hw);
1007 if (events & HERMES_EV_ALLOC)
1008 __dldwd_ev_alloc(priv, hw);
1010 hermes_write_regn(hw, EVACK, events);
1013 clear_bit(DLDWD_STATE_INIRQ, &priv->state);
1016 static void __dldwd_ev_tick(dldwd_priv_t *priv, hermes_t *hw)
1018 printk(KERN_DEBUG "%s: TICK\n", priv->ndev.name);
1021 static void __dldwd_ev_wterr(dldwd_priv_t *priv, hermes_t *hw)
1023 /* This seems to happen a fair bit under load, but ignoring it
1024 seems to work fine...*/
1025 DEBUG(1, "%s: MAC controller error (WTERR). Ignoring.\n",
1029 static void __dldwd_ev_infdrop(dldwd_priv_t *priv, hermes_t *hw)
1031 printk(KERN_WARNING "%s: Information frame lost.\n", priv->ndev.name);
1034 static void __dldwd_ev_info(dldwd_priv_t *priv, hermes_t *hw)
1036 DEBUG(3, "%s: Information frame received.\n", priv->ndev.name);
1037 /* We don't actually do anything about it - we assume the MAC
1038 controller can deal with it */
1041 static void __dldwd_ev_rx(dldwd_priv_t *priv, hermes_t *hw)
1043 struct net_device *dev = &priv->ndev;
1044 struct net_device_stats *stats = &priv->stats;
1045 struct iw_statistics *wstats = &priv->wstats;
1046 struct sk_buff *skb = NULL;
1047 uint16_t rxfid, status;
1048 int length, data_len, data_off;
1050 struct dldwd_frame_hdr hdr;
1054 rxfid = hermes_read_regn(hw, RXFID);
1055 DEBUG(3, "__dldwd_ev_rx(): RXFID=0x%04x\n", rxfid);
1057 /* We read in the entire frame header here. This isn't really
1058 necessary, since we ignore most of it, but it's
1059 conceptually simpler. We can tune this later if
1061 err = hermes_bap_pread(hw, IRQ_BAP, &hdr, sizeof(hdr), rxfid, 0);
1063 printk(KERN_ERR "%s: error %d reading frame header. "
1064 "Frame dropped.\n", dev->name, err);
1069 status = le16_to_cpu(hdr.desc.status);
1071 if (status & HERMES_RXSTAT_ERR) {
1072 if ((status & HERMES_RXSTAT_ERR) == HERMES_RXSTAT_BADCRC) {
1073 stats->rx_crc_errors++;
1074 printk(KERN_WARNING "%s: Bad CRC on Rx. Frame dropped.\n",
1076 show_rx_frame(&hdr);
1077 } else if ((status & HERMES_RXSTAT_ERR)
1078 == HERMES_RXSTAT_UNDECRYPTABLE) {
1079 wstats->discard.code++;
1080 printk(KERN_WARNING "%s: Undecryptable frame on Rx. Frame dropped.\n",
1083 wstats->discard.misc++;
1084 printk("%s: Unknown Rx error (0x%x). Frame dropped.\n",
1085 dev->name, status & HERMES_RXSTAT_ERR);
1091 length = le16_to_cpu(hdr.p80211.data_len);
1092 /* Yes, you heard right, that's le16. 802.2 and 802.3 are
1093 big-endian, but 802.11 is little-endian believe it or
1095 /* Correct. 802.3 is big-endian byte order and little endian bit
1096 * order, whereas 802.11 is little endian for both byte and bit
1097 * order. That's specified in the 802.11 spec. - Jean II */
1100 if (length > MAX_FRAME_SIZE) {
1101 printk(KERN_WARNING "%s: Oversized frame received (%d bytes)\n",
1103 stats->rx_length_errors++;
1108 /* We need space for the packet data itself, plus an ethernet
1109 header, plus 2 bytes so we can align the IP header on a
1110 32bit boundary, plus 1 byte so we can read in odd length
1111 packets from the card, which has an IO granularity of 16
1113 skb = dev_alloc_skb(length+ETH_HLEN+2+1);
1115 printk(KERN_WARNING "%s: Can't allocate skb for Rx\n",
1117 stats->rx_dropped++;
1121 skb_reserve(skb, 2); /* This way the IP header is aligned */
1123 /* Handle decapsulation */
1124 switch (status & HERMES_RXSTAT_MSGTYPE) {
1125 /* These both indicate a SNAP within 802.2 LLC within
1126 802.3 within 802.11 frame which we'll need to
1127 de-encapsulate. IEEE and ISO OSI have a lot to
1129 case HERMES_RXSTAT_1042:
1130 case HERMES_RXSTAT_TUNNEL:
1131 data_len = length - ENCAPS_OVERHEAD;
1132 data_off = sizeof(hdr);
1134 eh = (struct ethhdr *)skb_put(skb, ETH_HLEN);
1136 memcpy(eh, &hdr.p8023, sizeof(hdr.p8023));
1137 eh->h_proto = hdr.ethertype;
1141 /* Otherwise, we just throw the whole thing in, and hope
1142 the protocol layer can deal with it as 802.3 */
1145 data_off = P8023_OFFSET;
1149 p = skb_put(skb, data_len);
1150 if (hermes_bap_pread(hw, IRQ_BAP, p, RUP_EVEN(data_len),
1151 rxfid, data_off) != 0) {
1152 printk(KERN_WARNING "%s: Error reading packet data\n",
1158 dev->last_rx = jiffies;
1160 skb->protocol = eth_type_trans(skb, dev);
1161 skb->ip_summed = CHECKSUM_NONE;
1163 /* Process the wireless stats if needed */
1164 dldwd_stat_gather(dev, skb, &hdr);
1166 /* Pass the packet to the networking stack */
1168 stats->rx_packets++;
1169 stats->rx_bytes += length;
1175 dev_kfree_skb_irq(skb);
1179 static void __dldwd_ev_txexc(dldwd_priv_t *priv, hermes_t *hw)
1181 struct net_device *dev = &priv->ndev;
1182 struct net_device_stats *stats = &priv->stats;
1184 printk(KERN_WARNING "%s: Tx error!\n", dev->name);
1186 netif_wake_queue(dev);
1190 static void __dldwd_ev_tx(dldwd_priv_t *priv, hermes_t *hw)
1192 struct net_device *dev = &priv->ndev;
1193 struct net_device_stats *stats = &priv->stats;
1195 DEBUG(3, "%s: Transmit completed\n", dev->name);
1197 stats->tx_packets++;
1198 netif_wake_queue(dev);
1201 static void __dldwd_ev_alloc(dldwd_priv_t *priv, hermes_t *hw)
1205 allocfid = hermes_read_regn(hw, ALLOCFID);
1206 DEBUG(3, "%s: Allocation complete FID=0x%04x\n", priv->ndev.name, allocfid);
1208 /* For some reason we don't seem to get transmit completed events properly */
1209 if (allocfid == priv->txfid)
1210 __dldwd_ev_tx(priv, hw);
1212 /* hermes_write_regn(hw, ALLOCFID, 0); */
1216 * struct net_device methods
1219 static int dldwd_init(struct net_device *dev)
1221 dldwd_priv_t *priv = dev->priv;
1222 hermes_t *hw = &priv->hw;
1224 hermes_id_t nickbuf;
1230 TRACE_ENTER("dldwd");
1234 err = hermes_reset(hw);
1236 printk(KERN_ERR "%s: failed to reset hardware\n", dev->name);
1240 /* Get the firmware version */
1241 err = hermes_read_staidentity(hw, USER_BAP, &priv->firmware_info);
1243 printk(KERN_WARNING "%s: Error %d reading firmware info. Wildly guessing capabilities...\n",
1245 memset(&priv->firmware_info, 0, sizeof(priv->firmware_info));
1248 firmver = ((uint32_t)priv->firmware_info.major << 16) | priv->firmware_info.minor;
1250 /* Determine capabilities from the firmware version */
1252 switch (priv->firmware_info.vendor) {
1254 /* Lucent Wavelan IEEE, Lucent Orinoco, Cabletron RoamAbout,
1255 * ELSA, Melco, HP, IBM, Dell 1150 cards */
1256 vendor_str = "Lucent";
1257 /* Lucent MAC : 00:60:1D:* & 00:02:2D:* */
1259 priv->firmware_type = FIRMWARE_TYPE_LUCENT;
1260 priv->broken_reset = 0;
1261 priv->broken_allocate = 0;
1262 priv->has_port3 = 1;
1263 priv->has_ibss = (firmver >= 0x60006);
1264 priv->has_ibss_any = (firmver >= 0x60010);
1265 priv->has_wep = (firmver >= 0x40020);
1266 priv->has_big_wep = 1; /* FIXME: this is wrong - how do we tell
1267 Gold cards from the others? */
1268 priv->has_mwo = (firmver >= 0x60000);
1269 priv->has_pm = (firmver >= 0x40020);
1270 /* Tested with Lucent firmware :
1271 * 1.16 ; 4.08 ; 4.52 ; 6.04 ; 6.16 => Jean II
1272 * Tested CableTron firmware : 4.32 => Anton */
1275 vendor_str = "Generic Prism II";
1276 /* Note : my Intel card report this value, but I can't do
1277 * much with it, so I guess it's broken - Jean II */
1279 priv->firmware_type = FIRMWARE_TYPE_PRISM2;
1280 priv->broken_reset = 0;
1281 priv->broken_allocate = (firmver <= 0x10001);
1282 priv->has_port3 = 1;
1283 priv->has_ibss = 0; /* FIXME: no idea if this is right */
1284 priv->has_wep = (firmver >= 0x20000);
1285 priv->has_big_wep = 1;
1287 priv->has_pm = (firmver >= 0x20000);
1288 /* Tested with Intel firmware : 1.01 => Jean II */
1289 /* Note : firmware 1.01 is *seriously* broken */
1292 vendor_str = "Samsung";
1293 /* To check - Should cover Samsung & Compaq */
1295 priv->firmware_type = FIRMWARE_TYPE_PRISM2;
1296 priv->broken_reset = 0;
1297 priv->broken_allocate = 0;
1298 priv->has_port3 = 1;
1299 priv->has_ibss = 0; /* FIXME: available in later firmwares */
1300 priv->has_wep = (firmver >= 0x20000); /* FIXME */
1301 priv->has_big_wep = 0; /* FIXME */
1303 priv->has_pm = (firmver >= 0x20000); /* FIXME */
1306 vendor_str = "LinkSys/D-Link";
1309 priv->firmware_type = FIRMWARE_TYPE_PRISM2;
1310 priv->broken_reset = 0;
1311 priv->broken_allocate = 0;
1312 priv->has_port3 = 1;
1313 priv->has_ibss = 0; /* FIXME: available in later firmwares */
1314 priv->has_wep = (firmver >= 0x20000); /* FIXME */
1315 priv->has_big_wep = 0;
1317 priv->has_pm = (firmver >= 0x20000); /* FIXME */
1320 case 0x???: /* Could someone help here ??? */
1321 vendor_str = "Symbol";
1322 /* Symbol , 3Com AirConnect, Ericsson WLAN */
1324 priv->firmware_type = FIRMWARE_TYPE_SYMBOL;
1325 priv->broken_reset = 0;
1326 priv->broken_allocate = 0;
1327 priv->has_port3 = 1;
1328 priv->has_ibss = 0; /* FIXME: available in later firmwares */
1329 priv->has_wep = (firmver >= 0x20000); /* FIXME */
1330 priv->has_big_wep = 1; /* Probably RID_SYMBOL_KEY_LENGTH */
1332 priv->has_pm = (firmver >= 0x20000);
1336 vendor_str = "UNKNOWN";
1338 priv->firmware_type = 0;
1339 priv->broken_reset = 0;
1340 priv->broken_allocate = 0;
1341 priv->has_port3 = 0;
1344 priv->has_big_wep = 0;
1349 printk(KERN_INFO "%s: Firmware ID %02X vendor 0x%x (%s) version %d.%02d\n",
1350 dev->name, priv->firmware_info.id, priv->firmware_info.vendor,
1351 vendor_str, priv->firmware_info.major, priv->firmware_info.minor);
1353 if ((priv->broken_reset) || (priv->broken_allocate))
1354 printk(KERN_INFO "%s: Buggy firmware, please upgrade ASAP.\n", dev->name);
1355 if (priv->has_port3)
1356 printk(KERN_INFO "%s: Ad-hoc demo mode supported.\n", dev->name);
1358 printk(KERN_INFO "%s: IEEE standard IBSS ad-hoc mode supported.\n",
1360 if (priv->has_wep) {
1361 printk(KERN_INFO "%s: WEP supported, ", dev->name);
1362 if (priv->has_big_wep)
1363 printk("\"128\"-bit key.\n");
1365 printk("40-bit key.");
1368 /* Get the MAC address */
1369 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNF_MACADDR,
1370 ETH_ALEN, NULL, dev->dev_addr);
1372 printk(KERN_WARNING "%s: failed to read MAC address!\n",
1377 printk(KERN_INFO "%s: MAC address %02X:%02X:%02X:%02X:%02X:%02X\n",
1378 dev->name, dev->dev_addr[0], dev->dev_addr[1],
1379 dev->dev_addr[2], dev->dev_addr[3], dev->dev_addr[4],
1382 /* Get the station name */
1383 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNF_NICKNAME,
1384 sizeof(nickbuf), &reclen, &nickbuf);
1386 printk(KERN_ERR "%s: failed to read station name!n",
1391 len = MIN(IW_ESSID_MAX_SIZE, le16_to_cpu(nickbuf.len));
1393 len = MIN(IW_ESSID_MAX_SIZE, 2 * reclen);
1394 memcpy(priv->nick, &nickbuf.val, len);
1395 priv->nick[len] = '\0';
1397 printk(KERN_INFO "%s: Station name \"%s\"\n", dev->name, priv->nick);
1399 /* Get allowed channels */
1400 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CHANNEL_LIST, &priv->channel_mask);
1402 printk(KERN_ERR "%s: failed to read channel list!\n",
1407 /* Get initial AP density */
1408 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNF_SYSTEM_SCALE, &priv->ap_density);
1410 printk(KERN_ERR "%s: failed to read AP density!\n", dev->name);
1414 /* Get initial RTS threshold */
1415 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNF_RTS_THRESH, &priv->rts_thresh);
1417 printk(KERN_ERR "%s: failed to read RTS threshold!\n", dev->name);
1421 /* Get initial fragmentation settings */
1423 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNF_MWO_ROBUST,
1426 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNF_FRAG_THRESH,
1427 &priv->frag_thresh);
1429 printk(KERN_ERR "%s: failed to read fragmentation settings!\n", dev->name);
1433 /* Set initial bitrate control*/
1434 priv->tx_rate_ctrl = 3;
1436 /* Power management setup */
1440 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNF_PM_PERIOD,
1443 printk(KERN_ERR "%s: failed to read power management period!\n",
1447 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNF_PM_HOLDOVER,
1450 printk(KERN_ERR "%s: failed to read power management timeout!\n",
1456 /* Set up the default configuration */
1457 priv->iw_mode = IW_MODE_INFRA;
1458 /* By default use IEEE/IBSS ad-hoc mode if we have it */
1459 priv->prefer_port3 = priv->has_port3 && (! priv->has_ibss);
1460 set_port_type(priv);
1462 priv->promiscuous = 0;
1467 printk(KERN_INFO "%s: ready\n", dev->name);
1472 TRACE_EXIT("dldwd");
1477 static int dldwd_open(struct net_device *dev)
1479 dldwd_priv_t *priv = (dldwd_priv_t *)dev->priv;
1480 dev_link_t *link = &priv->link;
1483 TRACE_ENTER(dev->name);
1487 netif_device_attach(dev);
1489 err = dldwd_reset(priv);
1493 netif_start_queue(dev);
1495 TRACE_EXIT(dev->name);
1500 static int dldwd_stop(struct net_device *dev)
1502 dldwd_priv_t *priv = (dldwd_priv_t *)dev->priv;
1503 dev_link_t *link = &priv->link;
1505 TRACE_ENTER(dev->name);
1507 netif_stop_queue(dev);
1509 dldwd_shutdown(priv);
1513 if (link->state & DEV_STALE_CONFIG)
1514 mod_timer(&link->release, jiffies + HZ/20);
1518 TRACE_EXIT(dev->name);
1523 static struct net_device_stats *dldwd_get_stats(struct net_device *dev)
1525 dldwd_priv_t *priv = (dldwd_priv_t *)dev->priv;
1527 return &priv->stats;
1530 static struct iw_statistics *dldwd_get_wireless_stats(struct net_device *dev)
1532 dldwd_priv_t *priv = (dldwd_priv_t *)dev->priv;
1533 hermes_t *hw = &priv->hw;
1534 struct iw_statistics *wstats = &priv->wstats;
1536 hermes_commsqual_t cq;
1540 if (priv->port_type == 3) {
1541 memset(&wstats->qual, 0, sizeof(wstats->qual));
1543 /* If a spy address is defined, we report stats of the
1544 * first spy address - Jean II */
1545 if (priv->spy_number > 0) {
1546 wstats->qual.qual = priv->spy_stat[0].qual;
1547 wstats->qual.level = priv->spy_stat[0].level;
1548 wstats->qual.noise = priv->spy_stat[0].noise;
1549 wstats->qual.updated = priv->spy_stat[0].updated;
1551 #endif /* WIRELESS_SPY */
1553 err = hermes_read_commsqual(hw, USER_BAP, &cq);
1555 DEBUG(3, "%s: Global stats = %X-%X-%X\n", dev->name,
1556 cq.qual, cq.signal, cq.noise);
1558 /* Why are we using MIN/MAX ? We don't really care
1559 * if the value goes above max, because we export the
1560 * raw dBm values anyway. The normalisation should be done
1561 * in user space - Jean II */
1562 wstats->qual.qual = MAX(MIN(cq.qual, 0x8b-0x2f), 0);
1563 wstats->qual.level = MAX(MIN(cq.signal, 0x8a), 0x2f) - 0x95;
1564 wstats->qual.noise = MAX(MIN(cq.noise, 0x8a), 0x2f) - 0x95;
1565 wstats->qual.updated = 7;
1577 static inline void dldwd_spy_gather(struct net_device *dev,
1579 hermes_commsqual_t *cq)
1581 dldwd_priv_t *priv = (dldwd_priv_t *)dev->priv;
1584 /* Gather wireless spy statistics: for each packet, compare the
1585 * source address with out list, and if match, get the stats... */
1586 for (i = 0; i < priv->spy_number; i++)
1587 if (!memcmp(mac, priv->spy_address[i], ETH_ALEN)) {
1588 priv->spy_stat[i].qual = MAX(MIN(cq->qual, 0x8b-0x2f), 0);
1589 priv->spy_stat[i].level = MAX(MIN(cq->signal, 0x8a), 0x2f) - 0x95;
1590 priv->spy_stat[i].noise = MAX(MIN(cq->noise, 0x8a), 0x2f) - 0x95;
1591 priv->spy_stat[i].updated = 7;
1594 #endif /* WIRELESS_SPY */
1596 static void dldwd_stat_gather(struct net_device *dev,
1597 struct sk_buff *skb,
1598 struct dldwd_frame_hdr *hdr)
1600 dldwd_priv_t *priv = (dldwd_priv_t *)dev->priv;
1601 hermes_commsqual_t cq;
1603 /* Using spy support with lots of Rx packets, like in an
1604 * infrastructure (AP), will really slow down everything, because
1605 * the MAC address must be compared to each entry of the spy list.
1606 * If the user really asks for it (set some address in the
1607 * spy list), we do it, but he will pay the price.
1608 * Note that to get here, you need both WIRELESS_SPY
1609 * compiled in AND some addresses in the list !!!
1612 /* Note : gcc will optimise the whole section away if
1613 * WIRELESS_SPY is not defined... - Jean II */
1616 (priv->spy_number > 0) ||
1620 u_char *stats = (u_char *) &(hdr->desc.q_info);
1621 /* This code may look strange. Everywhere we are using 16 bit
1622 * ints except here. I've verified that these are are the
1623 * correct values. Please check on PPC - Jean II */
1624 cq.signal = stats[1]; /* High order byte */
1625 cq.noise = stats[0]; /* Low order byte */
1626 cq.qual = stats[0] - stats[1]; /* Better than nothing */
1628 DEBUG(3, "%s: Packet stats = %X-%X-%X\n", dev->name,
1629 cq.qual, cq.signal, cq.noise);
1632 dldwd_spy_gather(dev, skb->mac.raw + ETH_ALEN, &cq);
1635 #endif /* WIRELESS_EXT */
1638 struct p8022_hdr encaps_hdr = {
1639 0xaa, 0xaa, 0x03, {0x00, 0x00, 0xf8}
1642 static int dldwd_xmit(struct sk_buff *skb, struct net_device *dev)
1644 dldwd_priv_t *priv = (dldwd_priv_t *)dev->priv;
1645 struct net_device_stats *stats = &priv->stats;
1646 hermes_t *hw = &priv->hw;
1648 uint16_t txfid = priv->txfid;
1651 int len, data_len, data_off;
1652 struct dldwd_frame_hdr hdr;
1653 hermes_response_t resp;
1655 if (! netif_running(dev)) {
1656 printk(KERN_ERR "%s: Tx on stopped device!\n",
1662 if (netif_queue_stopped(dev)) {
1663 printk(KERN_ERR "%s: Tx while transmitter busy!\n",
1670 /* Length of the packet body */
1671 len = MAX(skb->len - ETH_HLEN, ETH_ZLEN);
1673 eh = (struct ethhdr *)skb->data;
1675 /* Build the IEEE 802.11 header */
1676 memset(&hdr, 0, sizeof(hdr));
1677 memcpy(hdr.p80211.addr1, eh->h_dest, ETH_ALEN);
1678 memcpy(hdr.p80211.addr2, eh->h_source, ETH_ALEN);
1679 hdr.p80211.frame_ctl = DLDWD_FTYPE_DATA;
1681 /* Encapsulate Ethernet-II frames */
1682 if (ntohs(eh->h_proto) > 1500) { /* Ethernet-II frame */
1684 data_off = sizeof(hdr);
1685 p = skb->data + ETH_HLEN;
1688 hdr.p80211.data_len = cpu_to_le16(data_len + ENCAPS_OVERHEAD);
1691 memcpy(hdr.p8023.h_dest, eh->h_dest, ETH_ALEN);
1692 memcpy(hdr.p8023.h_source, eh->h_source, ETH_ALEN);
1693 hdr.p8023.h_proto = htons(data_len + ENCAPS_OVERHEAD);
1696 memcpy(&hdr.p8022, &encaps_hdr, sizeof(encaps_hdr));
1698 hdr.ethertype = eh->h_proto;
1699 err = hermes_bap_pwrite(hw, USER_BAP, &hdr, sizeof(hdr),
1703 "%s: Error %d writing packet header to BAP\n",
1708 } else { /* IEEE 802.3 frame */
1709 data_len = len + ETH_HLEN;
1710 data_off = P8023_OFFSET;
1714 hdr.p80211.data_len = cpu_to_le16(len);
1715 err = hermes_bap_pwrite(hw, USER_BAP, &hdr, P8023_OFFSET,
1719 "%s: Error %d writing packet header to BAP\n",
1726 /* Round up for odd length packets */
1727 err = hermes_bap_pwrite(hw, USER_BAP, p, RUP_EVEN(data_len), txfid, data_off);
1729 printk(KERN_ERR "%s: Error %d writing packet data to BAP\n",
1736 /* Finally, we actually initiate the send */
1737 err = hermes_docmd_wait(hw, HERMES_CMD_TX | HERMES_CMD_RECL, txfid, &resp);
1739 printk(KERN_ERR "%s: Error %d transmitting packet\n", dev->name, err);
1744 dev->trans_start = jiffies;
1745 stats->tx_bytes += data_off + data_len;
1747 netif_stop_queue(dev);
1760 static void dldwd_tx_timeout(struct net_device *dev)
1762 dldwd_priv_t *priv = (dldwd_priv_t *)dev->priv;
1763 struct net_device_stats *stats = &priv->stats;
1766 printk(KERN_WARNING "%s: Tx timeout! Resetting card.\n", dev->name);
1770 err = dldwd_reset(priv);
1772 printk(KERN_ERR "%s: Error %d resetting card on Tx timeout!\n",
1775 dev->trans_start = jiffies;
1776 netif_wake_queue(dev);
1780 static int dldwd_ioctl_getiwrange(struct net_device *dev, struct iw_point *rrq)
1782 dldwd_priv_t *priv = dev->priv;
1785 struct iw_range range;
1789 TRACE_ENTER(dev->name);
1791 err = verify_area(VERIFY_WRITE, rrq->pointer, sizeof(range));
1795 rrq->length = sizeof(range);
1798 ptype = priv->port_type;
1801 memset(&range, 0, sizeof(range));
1803 /* Much of this shamelessly taken from wvlan_cs.c. No idea
1804 * what it all means -dgibson */
1805 range.min_nwid = range.max_nwid = 0; /* We don't use nwids */
1807 /* Set available channels/frequencies */
1808 range.num_channels = NUM_CHANNELS;
1810 for (i = 0; i < NUM_CHANNELS; i++) {
1811 if (priv->channel_mask & (1 << i)) {
1812 range.freq[k].i = i + 1;
1813 range.freq[k].m = channel_frequency[i] * 100000;
1814 range.freq[k].e = 1;
1818 if (k >= IW_MAX_FREQUENCIES)
1821 range.num_frequency = k;
1823 range.sensitivity = 3;
1825 if ((ptype == 3) && (priv->spy_number == 0)){
1826 /* Quality stats meaningless in ad-hoc mode */
1827 range.max_qual.qual = 0;
1828 range.max_qual.level = 0;
1829 range.max_qual.noise = 0;
1831 range.max_qual.qual = 0x8b - 0x2f;
1832 range.max_qual.level = 0x2f - 0x95 - 1;
1833 range.max_qual.noise = 0x2f - 0x95 - 1;
1836 err = dldwd_hw_get_bitratelist(priv, &numrates,
1837 range.bitrate, IW_MAX_BITRATES);
1840 range.num_bitrates = numrates;
1842 /* Set an indication of the max TCP throughput in bit/s that we can
1843 * expect using this interface. May be use for QoS stuff...
1846 range.throughput = 5 * 1000 * 1000; /* ~5 Mb/s */
1848 range.throughput = 1.5 * 1000 * 1000; /* ~1.5 Mb/s */
1851 range.max_rts = 2347;
1852 range.min_frag = 256;
1853 range.max_frag = 2346;
1856 if (priv->has_wep) {
1857 range.max_encoding_tokens = MAX_KEYS;
1859 range.encoding_size[0] = SMALL_KEY_SIZE;
1860 range.num_encoding_sizes = 1;
1862 if (priv->has_big_wep) {
1863 range.encoding_size[1] = LARGE_KEY_SIZE;
1864 range.num_encoding_sizes = 2;
1867 range.num_encoding_sizes = 0;
1868 range.max_encoding_tokens = 0;
1873 range.max_pmp = 65535000;
1875 range.max_pmt = 65535 * 1000; /* ??? */
1876 range.pmp_flags = IW_POWER_PERIOD;
1877 range.pmt_flags = IW_POWER_TIMEOUT;
1878 range.pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_UNICAST_R;
1880 range.num_txpower = 1;
1881 range.txpower[0] = 15; /* 15dBm */
1882 range.txpower_capa = IW_TXPOW_DBM;
1884 if (copy_to_user(rrq->pointer, &range, sizeof(range)))
1887 TRACE_EXIT(dev->name);
1892 static int dldwd_ioctl_setiwencode(struct net_device *dev, struct iw_point *erq)
1894 dldwd_priv_t *priv = dev->priv;
1895 int index = (erq->flags & IW_ENCODE_INDEX) - 1;
1896 int setindex = priv->tx_key;
1897 int enable = priv->wep_on;
1898 int auth = priv->wep_auth;
1901 char keybuf[MAX_KEY_SIZE];
1904 /* We actually have a key to set */
1906 if (copy_from_user(keybuf, erq->pointer, erq->length))
1913 if (erq->length > MAX_KEY_SIZE) {
1918 if ( (erq->length > LARGE_KEY_SIZE)
1919 || ( ! priv->has_big_wep && (erq->length > SMALL_KEY_SIZE)) ) {
1924 if ((index < 0) || (index >= MAX_KEYS))
1925 index = priv->tx_key;
1927 if (erq->length > SMALL_KEY_SIZE) {
1928 xlen = LARGE_KEY_SIZE;
1929 } else if (erq->length > 0) {
1930 xlen = SMALL_KEY_SIZE;
1934 /* Switch on WEP if off */
1935 if ((!enable) && (xlen > 0)) {
1940 /* Important note : if the user do "iwconfig eth0 enc off",
1941 * we will arrive there with an index of -1. This is valid
1942 * but need to be taken care off... Jean II */
1943 if ((index < 0) || (index >= MAX_KEYS)) {
1944 if((index != -1) || (erq->flags == 0)) {
1949 /* Set the index : Check that the key is valid */
1950 if(priv->keys[index].len == 0) {
1958 if (erq->flags & IW_ENCODE_DISABLED)
1960 /* Only for symbol cards (so far) - Jean II */
1961 if (erq->flags & IW_ENCODE_OPEN)
1963 if (erq->flags & IW_ENCODE_RESTRICTED)
1964 auth = 2; /* If all key are 128 -> should be 3 ??? */
1965 /* Agree with master wep setting */
1969 auth = 1; /* Encryption require some authentication */
1972 priv->keys[index].len = cpu_to_le16(xlen);
1973 memset(priv->keys[index].data, 0, sizeof(priv->keys[index].data));
1974 memcpy(priv->keys[index].data, keybuf, erq->length);
1976 priv->tx_key = setindex;
1977 priv->wep_on = enable;
1978 priv->wep_auth = auth;
1986 static int dldwd_ioctl_getiwencode(struct net_device *dev, struct iw_point *erq)
1988 dldwd_priv_t *priv = dev->priv;
1989 int index = (erq->flags & IW_ENCODE_INDEX) - 1;
1991 char keybuf[MAX_KEY_SIZE];
1996 if ((index < 0) || (index >= MAX_KEYS))
1997 index = priv->tx_key;
2001 erq->flags |= IW_ENCODE_DISABLED;
2002 erq->flags |= index + 1;
2004 /* Only for symbol cards - Jean II */
2005 if (priv->firmware_type == FIRMWARE_TYPE_SYMBOL) {
2006 switch(priv->wep_auth) {
2008 erq->flags |= IW_ENCODE_OPEN;
2012 erq->flags |= IW_ENCODE_RESTRICTED;
2020 xlen = le16_to_cpu(priv->keys[index].len);
2025 memcpy(keybuf, priv->keys[index].data, MAX_KEY_SIZE);
2031 if (copy_to_user(erq->pointer, keybuf, xlen))
2038 static int dldwd_ioctl_setessid(struct net_device *dev, struct iw_point *erq)
2040 dldwd_priv_t *priv = dev->priv;
2041 char essidbuf[IW_ESSID_MAX_SIZE+1];
2043 /* Note : ESSID is ignored in Ad-Hoc demo mode, but we can set it
2044 * anyway... - Jean II */
2046 memset(&essidbuf, 0, sizeof(essidbuf));
2049 if (erq->length > IW_ESSID_MAX_SIZE)
2052 if (copy_from_user(&essidbuf, erq->pointer, erq->length))
2055 essidbuf[erq->length] = '\0';
2060 memcpy(priv->desired_essid, essidbuf, IW_ESSID_MAX_SIZE+1);
2067 static int dldwd_ioctl_getessid(struct net_device *dev, struct iw_point *erq)
2069 dldwd_priv_t *priv = dev->priv;
2070 char essidbuf[IW_ESSID_MAX_SIZE+1];
2074 TRACE_ENTER(dev->name);
2076 err = dldwd_hw_get_essid(priv, &active, essidbuf);
2081 erq->length = strlen(essidbuf) + 1;
2083 if ( copy_to_user(erq->pointer, essidbuf, erq->length) )
2086 TRACE_EXIT(dev->name);
2091 static int dldwd_ioctl_setnick(struct net_device *dev, struct iw_point *nrq)
2093 dldwd_priv_t *priv = dev->priv;
2094 char nickbuf[IW_ESSID_MAX_SIZE+1];
2096 if (nrq->length > IW_ESSID_MAX_SIZE)
2099 memset(nickbuf, 0, sizeof(nickbuf));
2101 if (copy_from_user(nickbuf, nrq->pointer, nrq->length))
2104 nickbuf[nrq->length] = '\0';
2108 memcpy(priv->nick, nickbuf, sizeof(priv->nick));
2115 static int dldwd_ioctl_getnick(struct net_device *dev, struct iw_point *nrq)
2117 dldwd_priv_t *priv = dev->priv;
2118 char nickbuf[IW_ESSID_MAX_SIZE+1];
2121 memcpy(nickbuf, priv->nick, IW_ESSID_MAX_SIZE+1);
2124 nrq->length = strlen(nickbuf)+1;
2126 if (copy_to_user(nrq->pointer, nickbuf, sizeof(nickbuf)))
2132 static int dldwd_ioctl_setfreq(struct net_device *dev, struct iw_freq *frq)
2134 dldwd_priv_t *priv = dev->priv;
2137 /* We can only use this in Ad-Hoc demo mode to set the operating
2138 * frequency, or in IBSS mode to set the frequency where the IBSS
2139 * will be created - Jean II */
2140 if (priv->iw_mode != IW_MODE_ADHOC)
2143 if ( (frq->e == 0) && (frq->m <= 1000) ) {
2144 /* Setting by channel number */
2147 /* Setting by frequency - search the table */
2151 for (i = 0; i < (6 - frq->e); i++)
2154 for (i = 0; i < NUM_CHANNELS; i++)
2155 if (frq->m == (channel_frequency[i] * mult))
2159 if ( (chan < 1) || (chan > NUM_CHANNELS) ||
2160 ! (priv->channel_mask & (1 << (chan-1)) ) )
2164 priv->channel = chan;
2170 static int dldwd_ioctl_getsens(struct net_device *dev, struct iw_param *srq)
2172 dldwd_priv_t *priv = dev->priv;
2173 hermes_t *hw = &priv->hw;
2178 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNF_SYSTEM_SCALE, &val);
2185 srq->fixed = 0; /* auto */
2190 static int dldwd_ioctl_setsens(struct net_device *dev, struct iw_param *srq)
2192 dldwd_priv_t *priv = dev->priv;
2193 int val = srq->value;
2195 if ((val < 1) || (val > 3))
2199 priv->ap_density = val;
2205 static int dldwd_ioctl_setrts(struct net_device *dev, struct iw_param *rrq)
2207 dldwd_priv_t *priv = dev->priv;
2208 int val = rrq->value;
2213 if ( (val < 0) || (val > 2347) )
2217 priv->rts_thresh = val;
2223 static int dldwd_ioctl_setfrag(struct net_device *dev, struct iw_param *frq)
2225 dldwd_priv_t *priv = dev->priv;
2230 if (priv->has_mwo) {
2232 priv->mwo_robust = 0;
2235 printk(KERN_WARNING "%s: Fixed fragmentation not \
2236 supported on this firmware. Using MWO robust instead.\n", dev->name);
2237 priv->mwo_robust = 1;
2241 priv->frag_thresh = 2346;
2243 if ( (frq->value < 256) || (frq->value > 2346) )
2246 priv->frag_thresh = frq->value & ~0x1; /* must be even */
2255 static int dldwd_ioctl_getfrag(struct net_device *dev, struct iw_param *frq)
2257 dldwd_priv_t *priv = dev->priv;
2258 hermes_t *hw = &priv->hw;
2264 if (priv->has_mwo) {
2265 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNF_MWO_ROBUST, &val);
2269 frq->value = val ? 2347 : 0;
2270 frq->disabled = ! val;
2273 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNF_FRAG_THRESH, &val);
2278 frq->disabled = (val >= 2346);
2287 static int dldwd_ioctl_setrate(struct net_device *dev, struct iw_param *rrq)
2289 dldwd_priv_t *priv = dev->priv;
2298 /* Normalise value */
2299 brate = rrq->value / 500000;
2301 switch (priv->firmware_type) {
2302 case FIRMWARE_TYPE_LUCENT: /* Lucent style rate */
2310 for (i = 0; i < NUM_RATES; i++)
2311 if (rate_list[i] == brate) {
2316 if ( (rate_ctrl < 1) || (rate_ctrl >= NUM_RATES) )
2319 priv->tx_rate_ctrl = rate_ctrl;
2321 case FIRMWARE_TYPE_PRISM2: /* Prism II style rate */
2322 case FIRMWARE_TYPE_SYMBOL: /* Symbol style rate */
2355 priv->tx_rate_ctrl = rate_ctrl;
2364 static int dldwd_ioctl_getrate(struct net_device *dev, struct iw_param *rrq)
2366 dldwd_priv_t *priv = dev->priv;
2367 hermes_t *hw = &priv->hw;
2373 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNF_TX_RATE_CTRL, &val);
2377 switch (priv->firmware_type) {
2378 case FIRMWARE_TYPE_LUCENT: /* Lucent style rate */
2379 brate = rate_list[val];
2384 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CURRENT_TX_RATE, &val);
2395 case FIRMWARE_TYPE_PRISM2: /* Prism II style rate */
2396 case FIRMWARE_TYPE_SYMBOL: /* Symbol style rate */
2397 /* Check if auto or fixed (crude approximation) */
2398 if((val & 0x1) && (val > 1)) {
2401 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CURRENT_TX_RATE, &val);
2418 rrq->value = brate * 500000;
2427 static int dldwd_ioctl_setpower(struct net_device *dev, struct iw_param *prq)
2429 dldwd_priv_t *priv = dev->priv;
2435 if (prq->disabled) {
2438 switch (prq->flags & IW_POWER_MODE) {
2439 case IW_POWER_UNICAST_R:
2443 case IW_POWER_ALL_R:
2448 /* No flags : but we may have a value - Jean II */
2456 if (prq->flags & IW_POWER_TIMEOUT) {
2458 priv->pm_timeout = prq->value / 1000;
2460 if (prq->flags & IW_POWER_PERIOD) {
2462 priv->pm_period = prq->value / 1000;
2464 /* It's valid to not have a value if we are just toggling
2465 * the flags... Jean II */
2478 static int dldwd_ioctl_getpower(struct net_device *dev, struct iw_param *prq)
2480 dldwd_priv_t *priv = dev->priv;
2481 hermes_t *hw = &priv->hw;
2483 uint16_t enable, period, timeout, mcast;
2487 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNF_PM_ENABLE, &enable);
2491 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNF_PM_PERIOD, &period);
2495 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNF_PM_HOLDOVER, &timeout);
2499 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNF_PM_MCAST_RX, &mcast);
2503 prq->disabled = !enable;
2504 /* Note : by default, display the period */
2505 if ((prq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
2506 prq->flags = IW_POWER_TIMEOUT;
2507 prq->value = timeout * 1000;
2509 prq->flags = IW_POWER_PERIOD;
2510 prq->value = period * 1000;
2513 prq->flags |= IW_POWER_ALL_R;
2515 prq->flags |= IW_POWER_UNICAST_R;
2523 static int dldwd_ioctl_setport3(struct net_device *dev, struct iwreq *wrq)
2525 dldwd_priv_t *priv = dev->priv;
2526 int val = *( (int *) wrq->u.name );
2531 case 0: /* Try to do IEEE ad-hoc mode */
2532 if (! priv->has_ibss) {
2536 priv->prefer_port3 = 0;
2540 case 1: /* Try to do Lucent proprietary ad-hoc mode */
2541 if (! priv->has_port3) {
2545 priv->prefer_port3 = 1;
2557 static int dldwd_ioctl_getport3(struct net_device *dev, struct iwreq *wrq)
2559 dldwd_priv_t *priv = dev->priv;
2560 int *val = (int *)wrq->u.name;
2563 *val = priv->prefer_port3;
2569 /* Spy is used for link quality/strength measurements in Ad-Hoc mode
2571 static int dldwd_ioctl_setspy(struct net_device *dev, struct iw_point *srq)
2573 dldwd_priv_t *priv = dev->priv;
2574 struct sockaddr address[IW_MAX_SPY];
2575 int number = srq->length;
2579 /* Check the number of addresses */
2580 if (number > IW_MAX_SPY)
2583 /* Get the data in the driver */
2585 if (copy_from_user(address, srq->pointer,
2586 sizeof(struct sockaddr) * number))
2590 /* Make sure nobody mess with the structure while we do */
2593 /* dldwd_lock() doesn't disable interrupts, so make sure the
2594 * interrupt rx path don't get confused while we copy */
2595 priv->spy_number = 0;
2598 /* Extract the addresses */
2599 for (i = 0; i < number; i++)
2600 memcpy(priv->spy_address[i], address[i].sa_data,
2603 memset(priv->spy_stat, 0,
2604 sizeof(struct iw_quality) * IW_MAX_SPY);
2605 /* Set number of addresses */
2606 priv->spy_number = number;
2609 /* Time to show what we have done... */
2610 DEBUG(0, "%s: New spy list:\n", dev->name);
2611 for (i = 0; i < number; i++) {
2612 DEBUG(0, "%s: %d - %02x:%02x:%02x:%02x:%02x:%02x\n",
2614 priv->spy_address[i][0], priv->spy_address[i][1],
2615 priv->spy_address[i][2], priv->spy_address[i][3],
2616 priv->spy_address[i][4], priv->spy_address[i][5]);
2619 /* Now, let the others play */
2625 static int dldwd_ioctl_getspy(struct net_device *dev, struct iw_point *srq)
2627 dldwd_priv_t *priv = dev->priv;
2628 struct sockaddr address[IW_MAX_SPY];
2629 struct iw_quality spy_stat[IW_MAX_SPY];
2635 number = priv->spy_number;
2636 if ((number > 0) && (srq->pointer)) {
2637 /* Create address struct */
2638 for (i = 0; i < number; i++) {
2639 memcpy(address[i].sa_data, priv->spy_address[i],
2641 address[i].sa_family = AF_UNIX;
2644 /* In theory, we should disable irqs while copying the stats
2645 * because the rx path migh update it in the middle...
2646 * Bah, who care ? - Jean II */
2647 memcpy(&spy_stat, priv->spy_stat,
2648 sizeof(struct iw_quality) * IW_MAX_SPY);
2649 for (i=0; i < number; i++)
2650 priv->spy_stat[i].updated = 0;
2655 /* Push stuff to user space */
2656 srq->length = number;
2657 if(copy_to_user(srq->pointer, address,
2658 sizeof(struct sockaddr) * number))
2660 if(copy_to_user(srq->pointer + (sizeof(struct sockaddr)*number),
2661 &spy_stat, sizeof(struct iw_quality) * number))
2667 static int dldwd_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
2669 dldwd_priv_t *priv = dev->priv;
2670 struct iwreq *wrq = (struct iwreq *)rq;
2674 TRACE_ENTER(dev->name);
2678 DEBUG(1, "%s: SIOCGIWNAME\n", dev->name);
2679 strcpy(wrq->u.name, "IEEE 802.11-DS");
2683 DEBUG(1, "%s: SIOCGIWAP\n", dev->name);
2684 wrq->u.ap_addr.sa_family = ARPHRD_ETHER;
2685 err = dldwd_hw_get_bssid(priv, wrq->u.ap_addr.sa_data);
2689 DEBUG(1, "%s: SIOCGIWRANGE\n", dev->name);
2690 err = dldwd_ioctl_getiwrange(dev, &wrq->u.data);
2694 DEBUG(1, "%s: SIOCSIWMODE\n", dev->name);
2696 switch (wrq->u.mode) {
2698 if (! (priv->has_ibss || priv->has_port3) )
2701 priv->iw_mode = IW_MODE_ADHOC;
2707 priv->iw_mode = IW_MODE_INFRA;
2715 set_port_type(priv);
2720 DEBUG(1, "%s: SIOCGIWMODE\n", dev->name);
2722 wrq->u.mode = priv->iw_mode;
2727 DEBUG(1, "%s: SIOCSIWENCODE\n", dev->name);
2728 if (! priv->has_wep) {
2733 err = dldwd_ioctl_setiwencode(dev, &wrq->u.encoding);
2739 DEBUG(1, "%s: SIOCGIWENCODE\n", dev->name);
2740 if (! priv->has_wep) {
2745 if (! capable(CAP_NET_ADMIN)) {
2750 err = dldwd_ioctl_getiwencode(dev, &wrq->u.encoding);
2754 DEBUG(1, "%s: SIOCSIWESSID\n", dev->name);
2755 err = dldwd_ioctl_setessid(dev, &wrq->u.essid);
2761 DEBUG(1, "%s: SIOCGIWESSID\n", dev->name);
2762 err = dldwd_ioctl_getessid(dev, &wrq->u.essid);
2766 DEBUG(1, "%s: SIOCSIWNICKN\n", dev->name);
2767 err = dldwd_ioctl_setnick(dev, &wrq->u.data);
2773 DEBUG(1, "%s: SIOCGIWNICKN\n", dev->name);
2774 err = dldwd_ioctl_getnick(dev, &wrq->u.data);
2778 DEBUG(1, "%s: SIOCGIWFREQ\n", dev->name);
2779 wrq->u.freq.m = dldwd_hw_get_freq(priv);
2784 DEBUG(1, "%s: SIOCSIWFREQ\n", dev->name);
2785 err = dldwd_ioctl_setfreq(dev, &wrq->u.freq);
2791 DEBUG(1, "%s: SIOCGIWSENS\n", dev->name);
2792 err = dldwd_ioctl_getsens(dev, &wrq->u.sens);
2796 DEBUG(1, "%s: SIOCSIWSENS\n", dev->name);
2797 err = dldwd_ioctl_setsens(dev, &wrq->u.sens);
2803 DEBUG(1, "%s: SIOCGIWRTS\n", dev->name);
2804 wrq->u.rts.value = priv->rts_thresh;
2805 wrq->u.rts.disabled = (wrq->u.rts.value == 2347);
2806 wrq->u.rts.fixed = 1;
2810 DEBUG(1, "%s: SIOCSIWRTS\n", dev->name);
2811 err = dldwd_ioctl_setrts(dev, &wrq->u.rts);
2817 DEBUG(1, "%s: SIOCSIWFRAG\n", dev->name);
2818 err = dldwd_ioctl_setfrag(dev, &wrq->u.frag);
2824 DEBUG(1, "%s: SIOCGIWFRAG\n", dev->name);
2825 err = dldwd_ioctl_getfrag(dev, &wrq->u.frag);
2829 DEBUG(1, "%s: SIOCSIWRATE\n", dev->name);
2830 err = dldwd_ioctl_setrate(dev, &wrq->u.bitrate);
2836 DEBUG(1, "%s: SIOCGIWRATE\n", dev->name);
2837 err = dldwd_ioctl_getrate(dev, &wrq->u.bitrate);
2841 DEBUG(1, "%s: SIOCSIWPOWER\n", dev->name);
2842 err = dldwd_ioctl_setpower(dev, &wrq->u.power);
2848 DEBUG(1, "%s: SIOCGIWPOWER\n", dev->name);
2849 err = dldwd_ioctl_getpower(dev, &wrq->u.power);
2853 DEBUG(1, "%s: SIOCGIWTXPOW\n", dev->name);
2854 /* The card only supports one tx power, so this is easy */
2855 wrq->u.txpower.value = 15; /* dBm */
2856 wrq->u.txpower.fixed = 1;
2857 wrq->u.txpower.disabled = 0;
2858 wrq->u.txpower.flags = IW_TXPOW_DBM;
2862 DEBUG(1, "%s: SIOCSIWSPY\n", dev->name);
2864 err = dldwd_ioctl_setspy(dev, &wrq->u.data);
2868 DEBUG(1, "%s: SIOCGIWSPY\n", dev->name);
2870 err = dldwd_ioctl_getspy(dev, &wrq->u.data);
2874 DEBUG(1, "%s: SIOCGIWPRIV\n", dev->name);
2875 if (wrq->u.data.pointer) {
2876 struct iw_priv_args privtab[] = {
2877 { SIOCDEVPRIVATE + 0x0, 0, 0, "force_reset" },
2878 { SIOCDEVPRIVATE + 0x2,
2879 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2881 { SIOCDEVPRIVATE + 0x3, 0,
2882 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2886 err = verify_area(VERIFY_WRITE, wrq->u.data.pointer, sizeof(privtab));
2890 wrq->u.data.length = sizeof(privtab) / sizeof(privtab[0]);
2891 if (copy_to_user(wrq->u.data.pointer, privtab, sizeof(privtab)))
2896 case SIOCDEVPRIVATE + 0x0: /* force_reset */
2897 DEBUG(1, "%s: SIOCDEVPRIVATE + 0x0 (force_reset)\n",
2899 if (! capable(CAP_NET_ADMIN)) {
2904 printk(KERN_DEBUG "%s: Forcing reset!\n", dev->name);
2908 case SIOCDEVPRIVATE + 0x2: /* set_port3 */
2909 DEBUG(1, "%s: SIOCDEVPRIVATE + 0x2 (set_port3)\n",
2911 if (! capable(CAP_NET_ADMIN)) {
2916 err = dldwd_ioctl_setport3(dev, wrq);
2921 case SIOCDEVPRIVATE + 0x3: /* get_port3 */
2922 DEBUG(1, "%s: SIOCDEVPRIVATE + 0x3 (get_port3)\n",
2924 err = dldwd_ioctl_getport3(dev, wrq);
2931 if (! err && changed && netif_running(dev)) {
2932 err = dldwd_reset(priv);
2937 TRACE_EXIT(dev->name);
2942 static int dldwd_change_mtu(struct net_device *dev, int new_mtu)
2944 TRACE_ENTER(dev->name);
2946 if ( (new_mtu < DLDWD_MIN_MTU) || (new_mtu > DLDWD_MAX_MTU) )
2951 TRACE_EXIT(dev->name);
2956 static void __dldwd_set_multicast_list(struct net_device *dev)
2958 dldwd_priv_t *priv = dev->priv;
2959 hermes_t *hw = &priv->hw;
2961 int promisc, allmulti, mc_count;
2963 TRACE_ENTER(dev->name);
2965 DEBUG(3, "dev->flags=0x%x, priv->promiscuous=%d, dev->mc_count=%d priv->mc_count=%d\n",
2966 dev->flags, priv->promiscuous, dev->mc_count, priv->mc_count);
2968 /* The Hermes doesn't seem to have an allmulti mode, so we go
2969 * into promiscuous mode and let the upper levels deal. */
2970 if ( (dev->flags & IFF_PROMISC) ) {
2974 } else if ( (dev->flags & IFF_ALLMULTI) ||
2975 (dev->mc_count > HERMES_MAX_MULTICAST) ) {
2978 mc_count = HERMES_MAX_MULTICAST;
2982 mc_count = dev->mc_count;
2985 DEBUG(3, "promisc=%d mc_count=%d\n",
2988 if (promisc != priv->promiscuous) { /* Don't touch the hardware if we don't have to */
2989 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNF_PROMISCUOUS,
2992 printk(KERN_ERR "%s: Error %d setting promiscuity to %d.\n",
2993 dev->name, err, promisc);
2995 priv->promiscuous = promisc;
2999 /* FIXME: This method of doing allmulticast reception
3000 comes from the NetBSD driver. Haven't actually
3001 tested whether it works or not. */
3002 hermes_multicast_t mclist;
3004 memset(&mclist, 0, sizeof(mclist));
3005 err = HERMES_WRITE_RECORD(hw, USER_BAP, HERMES_RID_CNF_MULTICAST_LIST, &mclist);
3007 printk(KERN_ERR "%s: Error %d setting multicast list.\n",
3012 } else if (mc_count || (! mc_count && priv->mc_count) ) {
3013 struct dev_mc_list *p = dev->mc_list;
3014 hermes_multicast_t mclist;
3017 for (i = 0; i < mc_count; i++) {
3018 /* First some paranoid checks */
3020 printk(KERN_ERR "%s: Multicast list shorter than mc_count.\n",
3024 if (p->dmi_addrlen != ETH_ALEN) {
3026 printk(KERN_ERR "%s: Bad address size (%d) in multicast list.\n",
3027 dev->name, p->dmi_addrlen);
3031 memcpy(mclist.addr[i], p->dmi_addr, ETH_ALEN);
3037 printk(KERN_ERR "%s: Multicast list longer than mc_count.\n",
3042 DEBUG(3, "priv->mc_count = %d\n", priv->mc_count);
3044 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNF_MULTICAST_LIST,
3045 HERMES_BYTES_TO_RECLEN(priv->mc_count * ETH_ALEN),
3048 printk(KERN_ERR "%s: Error %d setting multicast list.\n",
3054 /* Since we can set the promiscuous flag when it wasn't asked
3055 for, make sure the net_device knows about it. */
3056 if (priv->promiscuous)
3057 dev->flags |= IFF_PROMISC;
3059 dev->flags &= ~IFF_PROMISC;
3062 dev->flags |= IFF_ALLMULTI;
3064 dev->flags &= ~IFF_ALLMULTI;
3066 TRACE_EXIT(dev->name);
3073 static struct proc_dir_entry *dir_base = NULL;
3076 * This function updates the total amount of data printed so far. It then
3077 * determines if the amount of data printed into a buffer has reached the
3078 * offset requested. If it hasn't, then the buffer is shifted over so that
3079 * the next bit of data can be printed over the old bit. If the total
3080 * amount printed so far exceeds the total amount requested, then this
3081 * function returns 1, otherwise 0.
3085 shift_buffer(char *buffer, int requested_offset, int requested_len,
3086 int *total, int *slop, char **buf)
3090 printed = *buf - buffer;
3091 if (*total + printed <= requested_offset) {
3096 if (*total < requested_offset) {
3097 *slop = requested_offset - *total;
3099 *total = requested_offset + printed - *slop;
3101 if (*total > requested_offset + requested_len) {
3110 * This function calculates the actual start of the requested data
3111 * in the buffer. It also calculates actual length of data returned,
3112 * which could be less that the amount of data requested.
3114 #define PROC_BUFFER_SIZE 4096
3115 #define PROC_SAFE_SIZE 3072
3118 calc_start_len(char *buffer, char **start, int requested_offset,
3119 int requested_len, int total, char *buf)
3121 int return_len, buffer_len;
3123 buffer_len = buf - buffer;
3124 if (buffer_len >= PROC_BUFFER_SIZE - 1) {
3125 printk(KERN_ERR "calc_start_len: exceeded /proc buffer size\n");
3129 * There may be bytes before and after the
3130 * chunk that was actually requested.
3132 return_len = total - requested_offset;
3133 if (return_len < 0) {
3136 *start = buf - return_len;
3137 if (return_len > requested_len) {
3138 return_len = requested_len;
3144 dldwd_proc_get_hermes_regs(char *page, char **start, off_t requested_offset,
3145 int requested_len, int *eof, void *data)
3147 dldwd_priv_t *dev = (dldwd_priv_t *)data;
3148 hermes_t *hw = &dev->hw;
3150 int total = 0, slop = 0;
3154 #define DHERMESREG(name) buf += sprintf(buf, "%-16s: %04x\n", #name, hermes_read_regn(hw, name))
3164 DHERMESREG(INFOFID);
3166 DHERMESREG(ALLOCFID);
3167 DHERMESREG(TXCOMPLFID);
3168 DHERMESREG(SELECT0);
3169 DHERMESREG(OFFSET0);
3170 DHERMESREG(SELECT1);
3171 DHERMESREG(OFFSET1);
3175 DHERMESREG(CONTROL);
3176 DHERMESREG(SWSUPPORT0);
3177 DHERMESREG(SWSUPPORT1);
3178 DHERMESREG(SWSUPPORT2);
3179 DHERMESREG(AUXPAGE);
3180 DHERMESREG(AUXOFFSET);
3181 DHERMESREG(AUXDATA);
3184 shift_buffer(page, requested_offset, requested_len, &total,
3186 return calc_start_len(page, start, requested_offset, requested_len,
3195 #define DISPLAY_WORDS 0
3196 #define DISPLAY_BYTES 1
3197 #define DISPLAY_STRING 2
3198 } record_table[] = {
3199 #define RTCNFENTRY(name, type) { HERMES_RID_CNF_##name, #name, 0, LTV_BUF_SIZE, type }
3200 RTCNFENTRY(PORTTYPE, DISPLAY_WORDS),
3201 RTCNFENTRY(MACADDR, DISPLAY_BYTES),
3202 RTCNFENTRY(DESIRED_SSID, DISPLAY_STRING),
3203 RTCNFENTRY(CHANNEL, DISPLAY_WORDS),
3204 RTCNFENTRY(OWN_SSID, DISPLAY_STRING),
3205 RTCNFENTRY(SYSTEM_SCALE, DISPLAY_WORDS),
3206 RTCNFENTRY(MAX_DATA_LEN, DISPLAY_WORDS),
3207 RTCNFENTRY(PM_ENABLE, DISPLAY_WORDS),
3208 RTCNFENTRY(PM_MCAST_RX, DISPLAY_WORDS),
3209 RTCNFENTRY(PM_PERIOD, DISPLAY_WORDS),
3210 RTCNFENTRY(NICKNAME, DISPLAY_STRING),
3211 RTCNFENTRY(WEP_ON, DISPLAY_WORDS),
3212 RTCNFENTRY(MWO_ROBUST, DISPLAY_WORDS),
3213 RTCNFENTRY(MULTICAST_LIST, DISPLAY_BYTES),
3214 RTCNFENTRY(CREATEIBSS, DISPLAY_WORDS),
3215 RTCNFENTRY(FRAG_THRESH, DISPLAY_WORDS),
3216 RTCNFENTRY(RTS_THRESH, DISPLAY_WORDS),
3217 RTCNFENTRY(TX_RATE_CTRL, DISPLAY_WORDS),
3218 RTCNFENTRY(PROMISCUOUS, DISPLAY_WORDS),
3219 RTCNFENTRY(KEYS, DISPLAY_BYTES),
3220 RTCNFENTRY(TX_KEY, DISPLAY_WORDS),
3221 RTCNFENTRY(TICKTIME, DISPLAY_WORDS),
3222 RTCNFENTRY(PRISM2_TX_KEY, DISPLAY_WORDS),
3223 RTCNFENTRY(PRISM2_KEY0, DISPLAY_BYTES),
3224 RTCNFENTRY(PRISM2_KEY1, DISPLAY_BYTES),
3225 RTCNFENTRY(PRISM2_KEY2, DISPLAY_BYTES),
3226 RTCNFENTRY(PRISM2_KEY3, DISPLAY_BYTES),
3227 RTCNFENTRY(PRISM2_WEP_ON, DISPLAY_WORDS),
3229 #define RTINFENTRY(name,type) { HERMES_RID_##name, #name, 0, LTV_BUF_SIZE, type }
3230 RTINFENTRY(CHANNEL_LIST, DISPLAY_WORDS),
3231 RTINFENTRY(STAIDENTITY, DISPLAY_WORDS),
3232 RTINFENTRY(CURRENT_SSID, DISPLAY_STRING),
3233 RTINFENTRY(CURRENT_BSSID, DISPLAY_BYTES),
3234 RTINFENTRY(COMMSQUALITY, DISPLAY_WORDS),
3235 RTINFENTRY(CURRENT_TX_RATE, DISPLAY_WORDS),
3236 RTINFENTRY(WEP_AVAIL, DISPLAY_WORDS),
3237 RTINFENTRY(CURRENT_CHANNEL, DISPLAY_WORDS),
3238 RTINFENTRY(DATARATES, DISPLAY_BYTES),
3241 #define NUM_RIDS ( sizeof(record_table) / sizeof(record_table[0]) )
3244 dldwd_proc_get_hermes_recs(char *page, char **start, off_t requested_offset,
3245 int requested_len, int *eof, void *data)
3247 dldwd_priv_t *dev = (dldwd_priv_t *)data;
3248 hermes_t *hw = &dev->hw;
3250 int total = 0, slop = 0;
3257 /* print out all the config RIDs */
3258 for (i = 0; i < NUM_RIDS; i++) {
3259 uint16_t rid = record_table[i].rid;
3260 int minlen = record_table[i].minlen;
3261 int maxlen = record_table[i].maxlen;
3267 val8 = kmalloc(maxlen + 2, GFP_KERNEL);
3271 err = hermes_read_ltv(hw, USER_BAP, rid, maxlen,
3274 DEBUG(0, "Error %d reading RID 0x%04x\n", err, rid);
3277 val16 = (uint16_t *)val8;
3279 buf += sprintf(buf, "%-15s (0x%04x): length=%d (%d bytes)\tvalue=", record_table[i].name,
3280 rid, length, (length-1)*2);
3281 len = MIN( MAX(minlen, (length-1)*2), maxlen);
3283 switch (record_table[i].displaytype) {
3285 for (j = 0; j < len / 2; j++) {
3286 buf += sprintf(buf, "%04X-", le16_to_cpu(val16[j]));
3293 for (j = 0; j < len; j++) {
3294 buf += sprintf(buf, "%02X:", val8[j]);
3299 case DISPLAY_STRING:
3300 len = MIN(len, le16_to_cpu(val16[0])+2);
3302 buf += sprintf(buf, "\"%s\"", (char *)&val16[1]);
3306 buf += sprintf(buf, "\n");
3310 if (shift_buffer(page, requested_offset, requested_len,
3311 &total, &slop, &buf))
3314 if ( (buf - page) > PROC_SAFE_SIZE )
3318 return calc_start_len(page, start, requested_offset, requested_len,
3322 /* initialise the /proc subsystem for the hermes driver, creating the
3323 * separate entries */
3325 dldwd_proc_init(void)
3329 TRACE_ENTER("dldwd");
3331 /* create the directory for it to sit in */
3332 dir_base = create_proc_entry("hermes", S_IFDIR, &proc_root);
3333 if (dir_base == NULL) {
3334 printk(KERN_ERR "Unable to initialise /proc/hermes.\n");
3335 dldwd_proc_cleanup();
3339 TRACE_EXIT("dldwd");
3345 dldwd_proc_dev_init(dldwd_priv_t *dev)
3347 dev->dir_dev = NULL;
3348 /* create the directory for it to sit in */
3349 dev->dir_dev = create_proc_entry(dev->node.dev_name, S_IFDIR | S_IRUGO | S_IXUGO,
3351 if (dev->dir_dev == NULL) {
3352 printk(KERN_ERR "Unable to initialise /proc/hermes/%s.\n", dev->node.dev_name);
3356 dev->dir_regs = NULL;
3357 dev->dir_regs = create_proc_read_entry("regs", S_IFREG | S_IRUGO,
3358 dev->dir_dev, dldwd_proc_get_hermes_regs, dev);
3359 if (dev->dir_regs == NULL) {
3360 printk(KERN_ERR "Unable to initialise /proc/hermes/%s/regs.\n", dev->node.dev_name);
3364 dev->dir_recs = NULL;
3365 dev->dir_recs = create_proc_read_entry("recs", S_IFREG | S_IRUGO,
3366 dev->dir_dev, dldwd_proc_get_hermes_recs, dev);
3367 if (dev->dir_recs == NULL) {
3368 printk(KERN_ERR "Unable to initialise /proc/hermes/%s/recs.\n", dev->node.dev_name);
3374 dldwd_proc_dev_cleanup(dev);
3379 dldwd_proc_dev_cleanup(dldwd_priv_t *priv)
3381 if (priv->dir_regs) {
3382 remove_proc_entry("regs", priv->dir_dev);
3383 priv->dir_regs = NULL;
3385 if (priv->dir_recs) {
3386 remove_proc_entry("recs", priv->dir_dev);
3387 priv->dir_recs = NULL;
3389 if (priv->dir_dev) {
3390 remove_proc_entry(priv->node.dev_name, dir_base);
3391 priv->dir_dev = NULL;
3396 dldwd_proc_cleanup(void)
3398 TRACE_ENTER("dldwd");
3401 remove_proc_entry("hermes", &proc_root);
3405 TRACE_EXIT("dldwd");
3408 /*====================================================================*/
3411 * From here on in, it's all PCMCIA junk, taken almost directly from
3416 The dev_info variable is the "key" that is used to match up this
3417 device driver with appropriate cards, through the card configuration
3421 static dev_info_t dev_info = "orinoco_cs";
3424 A linked list of "instances" of the dummy device. Each actual
3425 PCMCIA card corresponds to one device instance, and is described
3426 by one dev_link_t structure (defined in ds.h).
3428 You may not want to use a linked list for this -- for example, the
3429 memory card driver uses an array of dev_link_t pointers, where minor
3430 device numbers are used to derive the corresponding array index.
3433 static dev_link_t *dev_list = NULL;
3434 static int num_instances = 0;
3436 /*====================================================================*/
3438 static void cs_error(client_handle_t handle, int func, int ret)
3440 error_info_t err = { func, ret };
3441 CardServices(ReportError, handle, &err);
3444 /*======================================================================
3445 dldwd_attach() creates an "instance" of the driver, allocating
3446 local data structures for one device. The device is registered
3449 The dev_link structure is initialized, but we don't actually
3450 configure the card at this point -- we wait until we receive a
3451 card insertion event.
3452 ======================================================================*/
3454 static dev_link_t *dldwd_attach(void)
3458 struct net_device *ndev;
3459 client_reg_t client_reg;
3462 TRACE_ENTER("dldwd");
3464 /* Allocate space for private device-specific data */
3465 priv = kmalloc(sizeof(*priv), GFP_KERNEL);
3471 memset(priv, 0, sizeof(*priv));
3472 priv->instance = num_instances++; /* FIXME: Racy? */
3473 spin_lock_init(&priv->lock);
3477 link->priv = ndev->priv = priv;
3479 /* Initialize the dev_link_t structure */
3480 link->release.function = &dldwd_release;
3481 link->release.data = (u_long) link;
3483 /* Interrupt setup */
3484 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE;
3485 link->irq.IRQInfo1 = IRQ_INFO2_VALID | IRQ_LEVEL_ID;
3486 if (irq_list[0] == -1)
3487 link->irq.IRQInfo2 = irq_mask;
3489 for (i = 0; i < 4; i++)
3490 link->irq.IRQInfo2 |= 1 << irq_list[i];
3491 link->irq.Handler = NULL;
3494 General socket configuration defaults can go here. In this
3495 client, we assume very little, and rely on the CIS for almost
3496 everything. In most clients, many details (i.e., number, sizes,
3497 and attributes of IO windows) are fixed by the nature of the
3498 device, and can be hard-wired here.
3500 link->conf.Attributes = 0;
3501 link->conf.IntType = INT_MEMORY_AND_IO;
3503 /* Set up the net_device */
3505 ndev->init = dldwd_init;
3506 ndev->open = dldwd_open;
3507 ndev->stop = dldwd_stop;
3508 ndev->hard_start_xmit = dldwd_xmit;
3509 ndev->tx_timeout = dldwd_tx_timeout;
3510 ndev->watchdog_timeo = 4*HZ; /* 4 second timeout */
3512 ndev->get_stats = dldwd_get_stats;
3513 ndev->get_wireless_stats = dldwd_get_wireless_stats;
3515 ndev->do_ioctl = dldwd_ioctl;
3517 ndev->change_mtu = dldwd_change_mtu;
3518 ndev->set_multicast_list = dldwd_set_multicast_list;
3520 netif_stop_queue(ndev);
3522 /* Register with Card Services */
3523 link->next = dev_list;
3525 client_reg.dev_info = &dev_info;
3526 client_reg.Attributes = INFO_IO_CLIENT | INFO_CARD_SHARE;
3527 client_reg.EventMask =
3528 CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL |
3529 CS_EVENT_RESET_PHYSICAL | CS_EVENT_CARD_RESET |
3530 CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME;
3531 client_reg.event_handler = &dldwd_event;
3532 client_reg.Version = 0x0210;
3533 client_reg.event_callback_args.client_data = link;
3534 ret = CardServices(RegisterClient, &link->handle, &client_reg);
3535 if (ret != CS_SUCCESS) {
3536 cs_error(link->handle, RegisterClient, ret);
3543 TRACE_EXIT("dldwd");
3545 } /* dldwd_attach */
3547 /*======================================================================
3548 This deletes a driver "instance". The device is de-registered
3549 with Card Services. If it has been released, all local data
3550 structures are freed. Otherwise, the structures will be freed
3551 when the device is released.
3552 ======================================================================*/
3554 static void dldwd_detach(dev_link_t * link)
3557 dldwd_priv_t *priv = link->priv;
3559 TRACE_ENTER("dldwd");
3561 /* Locate device structure */
3562 for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next)
3569 If the device is currently configured and active, we won't
3570 actually delete it yet. Instead, it is marked so that when
3571 the release() function is called, that will trigger a proper
3574 if (link->state & DEV_CONFIG) {
3576 printk(KERN_DEBUG "orinoco_cs: detach postponed, '%s' "
3577 "still locked\n", link->dev->dev_name);
3579 link->state |= DEV_STALE_LINK;
3583 /* Break the link with Card Services */
3585 CardServices(DeregisterClient, link->handle);
3587 /* Unlink device structure, and free it */
3588 *linkp = link->next;
3589 DEBUG(0, "orinoco_cs: detach: link=%p link->dev=%p\n", link, link->dev);
3591 DEBUG(0, "orinoco_cs: About to unregister net device %p\n",
3593 unregister_netdev(&priv->ndev);
3597 num_instances--; /* FIXME: Racy? */
3600 TRACE_EXIT("dldwd");
3601 } /* dldwd_detach */
3603 /*======================================================================
3604 dldwd_config() is scheduled to run after a CARD_INSERTION event
3605 is received, to configure the PCMCIA socket, and to make the
3606 device available to the system.
3607 ======================================================================*/
3609 #define CS_CHECK(fn, args...) \
3610 while ((last_ret=CardServices(last_fn=(fn),args))!=0) goto cs_failed
3612 #define CFG_CHECK(fn, args...) \
3613 if (CardServices(fn, args) != 0) goto next_entry
3615 static void dldwd_config(dev_link_t * link)
3617 client_handle_t handle = link->handle;
3618 dldwd_priv_t *priv = link->priv;
3619 hermes_t *hw = &priv->hw;
3620 struct net_device *ndev = &priv->ndev;
3623 int last_fn, last_ret;
3628 TRACE_ENTER("dldwd");
3630 CS_CHECK(ValidateCIS, handle, &info);
3633 This reads the card's CONFIG tuple to find its configuration
3636 tuple.DesiredTuple = CISTPL_CONFIG;
3637 tuple.Attributes = 0;
3638 tuple.TupleData = buf;
3639 tuple.TupleDataMax = sizeof(buf);
3640 tuple.TupleOffset = 0;
3641 CS_CHECK(GetFirstTuple, handle, &tuple);
3642 CS_CHECK(GetTupleData, handle, &tuple);
3643 CS_CHECK(ParseTuple, handle, &tuple, &parse);
3644 link->conf.ConfigBase = parse.config.base;
3645 link->conf.Present = parse.config.rmask[0];
3647 /* Configure card */
3648 link->state |= DEV_CONFIG;
3650 /* Look up the current Vcc */
3651 CS_CHECK(GetConfigurationInfo, handle, &conf);
3652 link->conf.Vcc = conf.Vcc;
3654 DEBUG(0, "dldwd_config: ConfigBase = 0x%x link->conf.Vcc = %d\n",
3655 link->conf.ConfigBase, link->conf.Vcc);
3658 In this loop, we scan the CIS for configuration table entries,
3659 each of which describes a valid card configuration, including
3660 voltage, IO window, memory window, and interrupt settings.
3662 We make no assumptions about the card to be configured: we use
3663 just the information available in the CIS. In an ideal world,
3664 this would work for any PCMCIA card, but it requires a complete
3665 and accurate CIS. In practice, a driver usually "knows" most of
3666 these things without consulting the CIS, and most client drivers
3667 will only use the CIS to fill in implementation-defined details.
3669 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
3670 CS_CHECK(GetFirstTuple, handle, &tuple);
3672 cistpl_cftable_entry_t dflt = { 0 };
3673 cistpl_cftable_entry_t *cfg = &(parse.cftable_entry);
3674 CFG_CHECK(GetTupleData, handle, &tuple);
3675 CFG_CHECK(ParseTuple, handle, &tuple, &parse);
3677 DEBUG(0, "dldwd_config: index = 0x%x, flags = 0x%x\n",
3678 cfg->index, cfg->flags);
3680 if (cfg->flags & CISTPL_CFTABLE_DEFAULT)
3682 if (cfg->index == 0)
3684 link->conf.ConfigIndex = cfg->index;
3686 /* Does this card need audio output? */
3687 if (cfg->flags & CISTPL_CFTABLE_AUDIO) {
3688 link->conf.Attributes |= CONF_ENABLE_SPKR;
3689 link->conf.Status = CCSR_AUDIO_ENA;
3692 /* Use power settings for Vcc and Vpp if present */
3693 /* Note that the CIS values need to be rescaled */
3694 if (cfg->vcc.present & (1 << CISTPL_POWER_VNOM)) {
3696 cfg->vcc.param[CISTPL_POWER_VNOM] /
3697 10000) goto next_entry;
3698 } else if (dflt.vcc.present & (1 << CISTPL_POWER_VNOM)) {
3700 dflt.vcc.param[CISTPL_POWER_VNOM] /
3701 10000) goto next_entry;
3704 if (cfg->vpp1.present & (1 << CISTPL_POWER_VNOM))
3705 link->conf.Vpp1 = link->conf.Vpp2 =
3706 cfg->vpp1.param[CISTPL_POWER_VNOM] / 10000;
3707 else if (dflt.vpp1.present & (1 << CISTPL_POWER_VNOM))
3708 link->conf.Vpp1 = link->conf.Vpp2 =
3709 dflt.vpp1.param[CISTPL_POWER_VNOM] / 10000;
3711 DEBUG(0, "dldwd_config: We seem to have configured Vcc and Vpp\n");
3713 /* Do we need to allocate an interrupt? */
3714 if (cfg->irq.IRQInfo1 || dflt.irq.IRQInfo1)
3715 link->conf.Attributes |= CONF_ENABLE_IRQ;
3717 /* IO window settings */
3718 link->io.NumPorts1 = link->io.NumPorts2 = 0;
3719 if ((cfg->io.nwin > 0) || (dflt.io.nwin > 0)) {
3721 (cfg->io.nwin) ? &cfg->io : &dflt.io;
3722 link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
3723 if (!(io->flags & CISTPL_IO_8BIT))
3724 link->io.Attributes1 =
3725 IO_DATA_PATH_WIDTH_16;
3726 if (!(io->flags & CISTPL_IO_16BIT))
3727 link->io.Attributes1 =
3728 IO_DATA_PATH_WIDTH_8;
3729 link->io.IOAddrLines =
3730 io->flags & CISTPL_IO_LINES_MASK;
3731 link->io.BasePort1 = io->win[0].base;
3732 link->io.NumPorts1 = io->win[0].len;
3734 link->io.Attributes2 =
3735 link->io.Attributes1;
3736 link->io.BasePort2 = io->win[1].base;
3737 link->io.NumPorts2 = io->win[1].len;
3740 /* This reserves IO space but doesn't actually enable it */
3741 CFG_CHECK(RequestIO, link->handle, &link->io);
3745 /* If we got this far, we're cool! */
3750 if (link->io.NumPorts1)
3751 CardServices(ReleaseIO, link->handle, &link->io);
3752 CS_CHECK(GetNextTuple, handle, &tuple);
3756 Allocate an interrupt line. Note that this does not assign a
3757 handler to the interrupt, unless the 'Handler' member of the
3758 irq structure is initialized.
3760 if (link->conf.Attributes & CONF_ENABLE_IRQ) {
3763 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT;
3764 link->irq.IRQInfo1 = IRQ_INFO2_VALID | IRQ_LEVEL_ID;
3765 if (irq_list[0] == -1)
3766 link->irq.IRQInfo2 = irq_mask;
3769 link->irq.IRQInfo2 |= 1 << irq_list[i];
3771 link->irq.Handler = dldwd_interrupt;
3772 link->irq.Instance = priv;
3774 CS_CHECK(RequestIRQ, link->handle, &link->irq);
3777 /* We initialize the hermes structure before completing PCMCIA
3778 configuration just in case the interrupt handler gets
3780 hermes_struct_init(hw, link->io.BasePort1);
3783 This actually configures the PCMCIA socket -- setting up
3784 the I/O windows and the interrupt mapping, and putting the
3785 card and host interface into "Memory and IO" mode.
3787 CS_CHECK(RequestConfiguration, link->handle, &link->conf);
3789 ndev->base_addr = link->io.BasePort1;
3790 ndev->irq = link->irq.AssignedIRQ;
3792 /* Instance name : by default, use hermesX, on demand use the
3793 * regular ethX (less risky) - Jean II */
3795 sprintf(ndev->name, "hermes%d", priv->instance);
3797 ndev->name[0] = '\0';
3798 /* Tell the stack we exist */
3799 if (register_netdev(ndev) != 0) {
3800 printk(KERN_ERR "orinoco_cs: register_netdev() failed\n");
3803 strcpy(priv->node.dev_name, ndev->name);
3805 /* Finally, report what we've done */
3806 printk(KERN_INFO "%s: index 0x%02x: Vcc %d.%d",
3807 priv->node.dev_name, link->conf.ConfigIndex,
3808 link->conf.Vcc / 10, link->conf.Vcc % 10);
3809 if (link->conf.Vpp1)
3810 printk(", Vpp %d.%d", link->conf.Vpp1 / 10,
3811 link->conf.Vpp1 % 10);
3812 if (link->conf.Attributes & CONF_ENABLE_IRQ)
3813 printk(", irq %d", link->irq.AssignedIRQ);
3814 if (link->io.NumPorts1)
3815 printk(", io 0x%04x-0x%04x", link->io.BasePort1,
3816 link->io.BasePort1 + link->io.NumPorts1 - 1);
3817 if (link->io.NumPorts2)
3818 printk(" & 0x%04x-0x%04x", link->io.BasePort2,
3819 link->io.BasePort2 + link->io.NumPorts2 - 1);
3822 /* And give us the proc nodes for debugging */
3823 if (dldwd_proc_dev_init(priv) != 0) {
3824 printk(KERN_ERR "orinoco_cs: Failed to create /proc node for %s\n",
3825 priv->node.dev_name);
3830 At this point, the dev_node_t structure(s) need to be
3831 initialized and arranged in a linked list at link->dev.
3833 priv->node.major = priv->node.minor = 0;
3834 link->dev = &priv->node;
3835 link->state &= ~DEV_CONFIG_PENDING;
3837 TRACE_EXIT("dldwd");
3842 cs_error(link->handle, last_fn, last_ret);
3844 dldwd_release((u_long) link);
3846 TRACE_EXIT("dldwd");
3847 } /* dldwd_config */
3849 /*======================================================================
3850 After a card is removed, dldwd_release() will unregister the
3851 device, and release the PCMCIA configuration. If the device is
3852 still open, this will be postponed until it is closed.
3853 ======================================================================*/
3855 static void dldwd_release(u_long arg)
3857 dev_link_t *link = (dev_link_t *) arg;
3858 dldwd_priv_t *priv = link->priv;
3860 TRACE_ENTER(link->dev->dev_name);
3863 If the device is currently in use, we won't release until it
3864 is actually closed, because until then, we can't be sure that
3865 no one will try to access the device or its data structures.
3868 DEBUG(0, "orinoco_cs: release postponed, '%s' still open\n",
3869 link->dev->dev_name);
3870 link->state |= DEV_STALE_CONFIG;
3875 In a normal driver, additional code may be needed to release
3876 other kernel data structures associated with this device.
3879 dldwd_proc_dev_cleanup(priv);
3881 /* Don't bother checking to see if these succeed or not */
3882 CardServices(ReleaseConfiguration, link->handle);
3883 if (link->io.NumPorts1)
3884 CardServices(ReleaseIO, link->handle, &link->io);
3885 if (link->irq.AssignedIRQ)
3886 CardServices(ReleaseIRQ, link->handle, &link->irq);
3887 link->state &= ~DEV_CONFIG;
3889 TRACE_EXIT(link->dev->dev_name);
3890 } /* dldwd_release */
3892 /*======================================================================
3893 The card status event handler. Mostly, this schedules other
3894 stuff to run after an event is received.
3896 When a CARD_REMOVAL event is received, we immediately set a
3897 private flag to block future accesses to this device. All the
3898 functions that actually access the device should check this flag
3899 to make sure the card is still present.
3900 ======================================================================*/
3902 static int dldwd_event(event_t event, int priority,
3903 event_callback_args_t * args)
3905 dev_link_t *link = args->client_data;
3906 dldwd_priv_t *priv = (dldwd_priv_t *)link->priv;
3907 struct net_device *dev = &priv->ndev;
3909 TRACE_ENTER("dldwd");
3912 case CS_EVENT_CARD_REMOVAL:
3913 dldwd_shutdown(priv);
3914 link->state &= ~DEV_PRESENT;
3915 if (link->state & DEV_CONFIG) {
3916 netif_stop_queue(dev);
3917 netif_device_detach(dev);
3918 mod_timer(&link->release, jiffies + HZ / 20);
3921 case CS_EVENT_CARD_INSERTION:
3922 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
3925 case CS_EVENT_PM_SUSPEND:
3927 link->state |= DEV_SUSPEND;
3928 /* Fall through... */
3929 case CS_EVENT_RESET_PHYSICAL:
3930 dldwd_shutdown(priv);
3931 /* Mark the device as stopped, to block IO until later */
3933 if (link->state & DEV_CONFIG) {
3935 netif_stop_queue(dev);
3936 netif_device_detach(dev);
3938 CardServices(ReleaseConfiguration, link->handle);
3941 case CS_EVENT_PM_RESUME:
3942 link->state &= ~DEV_SUSPEND;
3943 /* Fall through... */
3944 case CS_EVENT_CARD_RESET:
3945 if (link->state & DEV_CONFIG) {
3946 CardServices(RequestConfiguration, link->handle,
3950 if (dldwd_reset(priv) == 0) {
3951 netif_device_attach(dev);
3952 netif_start_queue(dev);
3954 printk(KERN_ERR "%s: Error resetting device on PCMCIA event\n",
3961 In a normal driver, additional code may go here to restore
3962 the device state and restart IO.
3967 TRACE_EXIT("dldwd");
3972 static int __init init_dldwd_cs(void)
3977 TRACE_ENTER("dldwd");
3979 printk(KERN_INFO "dldwd: David's Less Dodgy WaveLAN/IEEE Driver\n");
3981 DEBUG(0, "%s\n", version);
3982 CardServices(GetCardServicesInfo, &serv);
3983 if (serv.Revision != CS_RELEASE_CODE) {
3984 printk(KERN_NOTICE "orinoco_cs: Card Services release "
3985 "does not match!\n");
3988 register_pccard_driver(&dev_info, &dldwd_attach, &dldwd_detach);
3991 err = dldwd_proc_init();
3993 TRACE_EXIT("dldwd");
3997 static void __exit exit_dldwd_cs(void)
3999 TRACE_ENTER("dldwd");
4001 dldwd_proc_cleanup();
4003 unregister_pccard_driver(&dev_info);
4006 DEBUG(0, "orinoco_cs: Removing leftover devices.\n");
4007 while (dev_list != NULL) {
4008 del_timer(&dev_list->release);
4009 if (dev_list->state & DEV_CONFIG)
4010 dldwd_release((u_long) dev_list);
4011 dldwd_detach(dev_list);
4014 TRACE_EXIT("dldwd");
4017 module_init(init_dldwd_cs);
4018 module_exit(exit_dldwd_cs);