3 * Dr. Duncan McLennan Barclay, dmlb@ragnet.demon.co.uk.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the author nor the names of any co-contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY DUNCAN BARCLAY AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL DUNCAN BARCLAY OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * $FreeBSD: src/sys/dev/ray/if_ray.c,v 1.47.2.4 2001/08/14 22:54:05 dmlb Exp $
32 * $DragonFly: src/sys/dev/netif/ray/Attic/if_ray.c,v 1.20 2005/05/27 15:36:10 joerg Exp $
36 /* $NetBSD: if_ray.c,v 1.12 2000/02/07 09:36:27 augustss Exp $ */
38 * Copyright (c) 2000 Christian E. Hopps
39 * All rights reserved.
41 * Redistribution and use in source and binary forms, with or without
42 * modification, are permitted provided that the following conditions
44 * 1. Redistributions of source code must retain the above copyright
45 * notice, this list of conditions and the following disclaimer.
46 * 2. Redistributions in binary form must reproduce the above copyright
47 * notice, this list of conditions and the following disclaimer in the
48 * documentation and/or other materials provided with the distribution.
49 * 3. Neither the name of the author nor the names of any co-contributors
50 * may be used to endorse or promote products derived from this software
51 * without specific prior written permission.
53 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
54 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
55 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
56 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
57 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
58 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
59 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
60 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
61 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
62 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
70 * This card is unusual in that it uses both common and attribute
71 * memory whilst working. It should use common memory and an IO port.
73 * The bus resource allocations need to work around the brain deadness
74 * of pccardd (where it reads the CIS for common memory, sets it all
75 * up and then throws it all away assuming the card is an ed
76 * driver...). Note that this could be dangerous (because it doesn't
77 * interact with pccardd) if you use other memory mapped cards in the
78 * same pccard slot as currently old mappings are not cleaned up very well
79 * by the bus_release_resource methods or pccardd.
81 * There is no support for running this driver on 4.0.
83 * Ad-hoc and infra-structure modes
84 * ================================
86 * The driver supports ad-hoc mode for V4 firmware and infrastructure
87 * mode for V5 firmware. V5 firmware in ad-hoc mode is untested and should
90 * The Linux driver also seems to have the capability to act as an AP.
91 * I wonder what facilities the "AP" can provide within a driver? We can
92 * probably use the BRIDGE code to form an ESS but I don't think
93 * power saving etc. is easy.
96 * Packet framing/encapsulation/translation
97 * ========================================
99 * Currently we support the Webgear encapsulation:
100 * 802.11 header <net/if_ieee80211.h>struct ieee80211_frame
101 * 802.3 header <net/ethernet.h>struct ether_header
104 * and RFC1042 encapsulation of IP datagrams (translation):
105 * 802.11 header <net/if_ieee80211.h>struct ieee80211_frame
111 * Framing should be selected via if_media stuff or link types but
112 * is currently hardcoded to:
120 * 802.11 provides two authentication mechanisms. The first is a very
121 * simple host based mechanism (like xhost) called Open System and the
122 * second is a more complex challenge/response called Shared Key built
125 * This driver only supports Open System and does not implement any
126 * host based control lists. In otherwords authentication is always
127 * granted to hosts wanting to authenticate with this station. This is
128 * the only sensible behaviour as the Open System mechanism uses MAC
129 * addresses to identify hosts. Send me patches if you need it!
133 * ***check all XXX_INFRA code - reassoc not done well at all!
134 * ***watchdog to catch screwed up removals?
135 * ***error handling of RAY_COM_RUNQ
136 * ***error handling of ECF command completions
137 * ***can't seem to create a n/w that Win95 wants to see.
138 * ***remove panic in ray_com_ecf by re-quing or timeout
139 * ***use new ioctl stuff - probably need to change RAY_COM_FCHKRUNNING things?
140 * consider user doing:
141 * ifconfig ray0 192.168.200.38 -bssid "freed"
142 * ifconfig ray0 192.168.200.38 -bssid "fred"
143 * here the second one would be missed in this code
144 * check that v5 needs timeouts on ecf commands
145 * write up driver structure in comments above
146 * UPDATE_PARAMS seems to return via an interrupt - maybe the timeout
147 * is needed for wrong values?
148 * proper setting of mib_hop_seq_len with country code for v4 firmware
149 * best done with raycontrol?
150 * countrycode setting is broken I think
151 * userupdate should trap and do via startjoin etc.
152 * fragmentation when rx level drops?
153 * v5 might not need download
154 * defaults are as documented apart from hop_seq_length
155 * settings are sane for ad-hoc not infra
158 * most state is implied by the sequence of commands in the runq
159 * but in fact any of the rx and tx path that uses variables
160 * in the sc_c are potentially going to get screwed?
163 * proper handling of the basic rate set - see the manual
164 * all ray_sj, ray_assoc sequencues need a "nicer" solution as we
165 * remember association and authentication
166 * need to consider WEP
167 * acting as ap - should be able to get working from the manual
168 * need to finish RAY_ECMD_REJOIN_DONE
169 * finish authenitcation code, it doesn't handle errors/timeouts/
173 * promisc in here too? - done
174 * should be able to update the parameters before we download to the
175 * device. This means we must attach a desired struct to the
176 * runq entry and maybe have another big case statement to
177 * move these desired into current when not running.
178 * init must then use the current settings (pre-loaded
179 * in attach now!) and pass to download. But we can't access
180 * current nw params outside of the runq - ahhh
181 * differeniate between parameters set in attach and init
182 * sc_station_addr in here too (for changing mac address)
183 * move desired into the command structure?
184 * take downloaded MIB from a complete nw_param?
185 * longer term need to attach a desired nw params to the runq entry
188 * RAY_COM_RUNQ errors
190 * if sleeping in ccs_alloc with eintr/erestart/enxio/enodev
191 * erestart try again from the top
192 * XXX do not malloc more comqs
193 * XXX ccs allocation hard
194 * eintr clean up and return
195 * enxio clean up and return - done in macro
197 * if sleeping in runq_arr itself with eintr/erestart/enxio/enodev
198 * erestart try again from the top
199 * XXX do not malloc more comqs
200 * XXX ccs allocation hard
201 * XXX reinsert comqs at head of list
202 * eintr clean up and return
203 * enxio clean up and return - done in macro
207 #define XXX_ACTING_AP 0
209 #define RAY_DEBUG ( \
210 /* RAY_DBG_AUTH | */ \
211 /* RAY_DBG_SUBR | */ \
212 /* RAY_DBG_BOOTPARAM | */ \
213 /* RAY_DBG_STARTJOIN | */ \
214 /* RAY_DBG_CCS | */ \
215 /* RAY_DBG_IOCTL | */ \
216 /* RAY_DBG_MBUF | */ \
219 /* RAY_DBG_COM | */ \
220 /* RAY_DBG_STOP | */ \
221 /* RAY_DBG_CTL | */ \
222 /* RAY_DBG_MGT | */ \
224 /* RAY_DBG_DCOM | */ \
229 * XXX build options - move to LINT
231 #define RAY_CM_RID 0 /* pccardd abuses windows 0 and 1 */
232 #define RAY_AM_RID 3 /* pccardd abuses windows 0 and 1 */
233 #define RAY_COM_TIMEOUT (hz/2) /* Timeout for CCS commands */
234 #define RAY_TX_TIMEOUT (hz/2) /* Timeout for rescheduling TX */
235 #define RAY_ECF_SPIN_DELAY 1000 /* Wait 1ms before checking ECF ready */
236 #define RAY_ECF_SPIN_TRIES 10 /* Wait this many times for ECF ready */
238 * XXX build options - move to LINT
242 #define RAY_DEBUG 0x0000
243 #endif /* RAY_DEBUG */
245 #include <sys/param.h>
246 #include <sys/systm.h>
247 #include <sys/malloc.h>
248 #include <sys/kernel.h>
250 #include <machine/bus.h>
251 #include <machine/resource.h>
252 #include <machine/clock.h>
254 #include <sys/rman.h>
256 #include <sys/mbuf.h>
257 #include <sys/socket.h>
258 #include <sys/sockio.h>
261 #include <net/ethernet.h>
263 #include <net/ifq_var.h>
264 #include <net/if_arp.h>
265 #include <net/if_dl.h>
266 #include <net/if_llc.h>
268 #include <netproto/802_11/ieee80211.h>
269 #include <netproto/802_11/ieee80211_ioctl.h>
271 #include <machine/limits.h>
273 #include <bus/pccard/pccardvar.h>
276 #include "if_rayreg.h"
277 #include "if_raymib.h"
278 #include "if_raydbg.h"
279 #include "if_rayvar.h"
284 static int ray_attach (device_t);
285 static int ray_ccs_alloc (struct ray_softc *sc, size_t *ccsp, char *wmesg);
286 static void ray_ccs_fill (struct ray_softc *sc, size_t ccs, u_int cmd);
287 static void ray_ccs_free (struct ray_softc *sc, size_t ccs);
288 static int ray_ccs_tx (struct ray_softc *sc, size_t *ccsp, size_t *bufpp);
289 static void ray_com_ecf (struct ray_softc *sc, struct ray_comq_entry *com);
290 static void ray_com_ecf_done (struct ray_softc *sc);
291 static void ray_com_ecf_timo (void *xsc);
292 static struct ray_comq_entry *
293 ray_com_init (struct ray_comq_entry *com, ray_comqfn_t function, int flags, char *mesg);
294 static struct ray_comq_entry *
295 ray_com_malloc (ray_comqfn_t function, int flags, char *mesg);
296 static void ray_com_runq (struct ray_softc *sc);
297 static int ray_com_runq_add (struct ray_softc *sc, struct ray_comq_entry *com[], int ncom, char *wmesg);
298 static void ray_com_runq_done (struct ray_softc *sc);
299 static int ray_detach (device_t);
300 static void ray_init (void *xsc);
301 static int ray_init_user (struct ray_softc *sc);
302 static void ray_init_assoc (struct ray_softc *sc, struct ray_comq_entry *com);
303 static void ray_init_assoc_done (struct ray_softc *sc, u_int8_t status, size_t ccs);
304 static void ray_init_auth (struct ray_softc *sc, struct ray_comq_entry *com);
305 static int ray_init_auth_send (struct ray_softc *sc, u_int8_t *dst, int sequence);
306 static void ray_init_auth_done (struct ray_softc *sc, u_int8_t status);
307 static void ray_init_download (struct ray_softc *sc, struct ray_comq_entry *com);
308 static void ray_init_download_done (struct ray_softc *sc, u_int8_t status, size_t ccs);
309 static void ray_init_download_v4 (struct ray_softc *sc, struct ray_comq_entry *com);
310 static void ray_init_download_v5 (struct ray_softc *sc, struct ray_comq_entry *com);
311 static void ray_init_mcast (struct ray_softc *sc, struct ray_comq_entry *com);
312 static void ray_init_sj (struct ray_softc *sc, struct ray_comq_entry *com);
313 static void ray_init_sj_done (struct ray_softc *sc, u_int8_t status, size_t ccs);
314 static void ray_intr (void *xsc);
315 static void ray_intr_ccs (struct ray_softc *sc, u_int8_t cmd, u_int8_t status, size_t ccs);
316 static void ray_intr_rcs (struct ray_softc *sc, u_int8_t cmd, size_t ccs);
317 static void ray_intr_updt_errcntrs (struct ray_softc *sc);
318 static int ray_ioctl (struct ifnet *ifp, u_long command, caddr_t data, struct ucred *cr);
319 static void ray_mcast (struct ray_softc *sc, struct ray_comq_entry *com);
320 static void ray_mcast_done (struct ray_softc *sc, u_int8_t status, size_t ccs);
321 static int ray_mcast_user (struct ray_softc *sc);
322 static int ray_probe (device_t);
323 static void ray_promisc (struct ray_softc *sc, struct ray_comq_entry *com);
324 static void ray_repparams (struct ray_softc *sc, struct ray_comq_entry *com);
325 static void ray_repparams_done (struct ray_softc *sc, u_int8_t status, size_t ccs);
326 static int ray_repparams_user (struct ray_softc *sc, struct ray_param_req *pr);
327 static int ray_repstats_user (struct ray_softc *sc, struct ray_stats_req *sr);
328 static int ray_res_alloc_am (struct ray_softc *sc);
329 static int ray_res_alloc_cm (struct ray_softc *sc);
330 static int ray_res_alloc_irq (struct ray_softc *sc);
331 static void ray_res_release (struct ray_softc *sc);
332 static void ray_rx (struct ray_softc *sc, size_t rcs);
333 static void ray_rx_ctl (struct ray_softc *sc, struct mbuf *m0);
334 static void ray_rx_data (struct ray_softc *sc, struct mbuf *m0, u_int8_t siglev, u_int8_t antenna);
335 static void ray_rx_mgt (struct ray_softc *sc, struct mbuf *m0);
336 static void ray_rx_mgt_auth (struct ray_softc *sc, struct mbuf *m0);
337 static void ray_rx_mgt_beacon (struct ray_softc *sc, struct mbuf *m0);
338 static void ray_rx_mgt_info (struct ray_softc *sc, struct mbuf *m0, struct ieee80211_information *elements);
339 static void ray_rx_update_cache (struct ray_softc *sc, u_int8_t *src, u_int8_t siglev, u_int8_t antenna);
340 static void ray_stop (struct ray_softc *sc, struct ray_comq_entry *com);
341 static int ray_stop_user (struct ray_softc *sc);
342 static void ray_tx (struct ifnet *ifp);
343 static void ray_tx_done (struct ray_softc *sc, u_int8_t status, size_t ccs);
344 static void ray_tx_timo (void *xsc);
345 static int ray_tx_send (struct ray_softc *sc, size_t ccs, int pktlen, u_int8_t *dst);
346 static size_t ray_tx_wrhdr (struct ray_softc *sc, size_t bufp, u_int8_t type, u_int8_t fc1, u_int8_t *addr1, u_int8_t *addr2, u_int8_t *addr3);
347 static void ray_upparams (struct ray_softc *sc, struct ray_comq_entry *com);
348 static void ray_upparams_done (struct ray_softc *sc, u_int8_t status, size_t ccs);
349 static int ray_upparams_user (struct ray_softc *sc, struct ray_param_req *pr);
350 static void ray_watchdog (struct ifnet *ifp);
351 static u_int8_t ray_tx_best_antenna (struct ray_softc *sc, u_int8_t *dst);
353 #if RAY_DEBUG & RAY_DBG_COM
354 static void ray_com_ecf_check (struct ray_softc *sc, size_t ccs, char *mesg);
355 #endif /* RAY_DEBUG & RAY_DBG_COM */
356 #if RAY_DEBUG & RAY_DBG_MBUF
357 static void ray_dump_mbuf (struct ray_softc *sc, struct mbuf *m, char *s);
358 #endif /* RAY_DEBUG & RAY_DBG_MBUF */
361 * PC-Card (PCMCIA) driver definition
363 static device_method_t ray_methods[] = {
364 /* Device interface */
365 DEVMETHOD(device_probe, ray_probe),
366 DEVMETHOD(device_attach, ray_attach),
367 DEVMETHOD(device_detach, ray_detach),
372 static driver_t ray_driver = {
375 sizeof(struct ray_softc)
378 static devclass_t ray_devclass;
380 DECLARE_DUMMY_MODULE(if_ray);
381 DRIVER_MODULE(if_ray, pccard, ray_driver, ray_devclass, 0, 0);
384 * Probe for the card by checking its startup results.
386 * Fixup any bugs/quirks for different firmware.
389 ray_probe(device_t dev)
391 struct ray_softc *sc = device_get_softc(dev);
392 struct ray_ecf_startup_v5 *ep = &sc->sc_ecf_startup;
396 RAY_DPRINTF(sc, RAY_DBG_SUBR, "");
399 * Read startup results from the card.
401 error = ray_res_alloc_cm(sc);
404 error = ray_res_alloc_am(sc);
410 SRAM_READ_REGION(sc, RAY_ECF_TO_HOST_BASE, ep,
411 sizeof(sc->sc_ecf_startup));
415 * Check the card is okay and work out what version we are using.
417 if (ep->e_status != RAY_ECFS_CARD_OK) {
418 RAY_PRINTF(sc, "card failed self test 0x%b",
419 ep->e_status, RAY_ECFS_PRINTFB);
422 if (sc->sc_version != RAY_ECFS_BUILD_4 &&
423 sc->sc_version != RAY_ECFS_BUILD_5) {
424 RAY_PRINTF(sc, "unsupported firmware version 0x%0x",
425 ep->e_fw_build_string);
428 RAY_DPRINTF(sc, RAY_DBG_BOOTPARAM, "found a card");
432 * Fixup tib size to be correct - on build 4 it is garbage
434 if (sc->sc_version == RAY_ECFS_BUILD_4 && sc->sc_tibsize == 0x55)
435 sc->sc_tibsize = sizeof(struct ray_tx_tib);
441 * Attach the card into the kernel
444 ray_attach(device_t dev)
446 struct ray_softc *sc = device_get_softc(dev);
447 struct ray_ecf_startup_v5 *ep = &sc->sc_ecf_startup;
448 struct ifnet *ifp = &sc->arpcom.ac_if;
452 RAY_DPRINTF(sc, RAY_DBG_SUBR, "");
454 if ((sc == NULL) || (sc->sc_gone))
458 * Grab the resources I need
460 error = ray_res_alloc_cm(sc);
463 error = ray_res_alloc_am(sc);
468 error = ray_res_alloc_irq(sc);
475 * Reset any pending interrupts
477 RAY_HCS_CLEAR_INTR(sc);
480 * Set the parameters that will survive stop/init and
481 * reset a few things on the card.
483 * Do not update these in ray_init_download's parameter setup
485 * XXX see the ray_init_download section for stuff to move
488 bzero(&sc->sc_d, sizeof(struct ray_nw_param));
489 bzero(&sc->sc_c, sizeof(struct ray_nw_param));
491 /* Clear statistics counters */
492 sc->sc_rxoverflow = 0;
497 /* Clear signal and antenna cache */
498 bzero(sc->sc_siglevs, sizeof(sc->sc_siglevs));
500 /* Set all ccs to be free */
501 bzero(sc->sc_ccsinuse, sizeof(sc->sc_ccsinuse));
502 ccs = RAY_CCS_ADDRESS(0);
503 for (i = 0; i < RAY_CCS_LAST; ccs += RAY_CCS_SIZE, i++)
504 RAY_CCS_FREE(sc, ccs);
507 * Initialise the network interface structure
509 if_initname(ifp, "ray", device_get_unit(dev));
512 ifp->if_flags = (IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST);
513 ifp->if_hdrlen = sizeof(struct ieee80211_frame) +
514 sizeof(struct ether_header);
515 ifp->if_baudrate = 1000000; /* Is this baud or bps ;-) */
516 ifp->if_start = ray_tx;
517 ifp->if_ioctl = ray_ioctl;
518 ifp->if_watchdog = ray_watchdog;
519 ifp->if_init = ray_init;
520 ifq_set_maxlen(&ifp->if_snd, IFQ_MAXLEN);
521 ifq_set_ready(&ifp->if_snd);
524 * Initialise the timers and driver
526 callout_init(&sc->com_timer);
527 callout_init(&sc->tx_timer);
528 TAILQ_INIT(&sc->sc_comq);
530 ether_ifattach(ifp, ep->e_station_addr);
533 * Print out some useful information
535 if (bootverbose || (RAY_DEBUG & RAY_DBG_BOOTPARAM)) {
536 RAY_PRINTF(sc, "start up results");
537 if (sc->sc_version == RAY_ECFS_BUILD_4)
538 printf(". Firmware version 4\n");
540 printf(". Firmware version 5\n");
541 printf(". Status 0x%b\n", ep->e_status, RAY_ECFS_PRINTFB);
542 if (sc->sc_version == RAY_ECFS_BUILD_4) {
543 printf(". Program checksum %0x\n", ep->e_resv0);
544 printf(". CIS checksum %0x\n", ep->e_rates[0]);
546 printf(". (reserved word) %0x\n", ep->e_resv0);
547 printf(". Supported rates %8D\n", ep->e_rates, ":");
549 printf(". Japan call sign %12D\n", ep->e_japan_callsign, ":");
550 if (sc->sc_version == RAY_ECFS_BUILD_5) {
551 printf(". Program checksum %0x\n", ep->e_prg_cksum);
552 printf(". CIS checksum %0x\n", ep->e_cis_cksum);
553 printf(". Firmware version %0x\n",
554 ep->e_fw_build_string);
555 printf(". Firmware revision %0x\n", ep->e_fw_build);
556 printf(". (reserved word) %0x\n", ep->e_fw_resv);
557 printf(". ASIC version %0x\n", ep->e_asic_version);
558 printf(". TIB size %0x\n", ep->e_tibsize);
568 * This is usually called when the card is ejected, but
569 * can be caused by a modunload of a controller driver.
570 * The idea is to reset the driver's view of the device
571 * and ensure that any driver entry points such as
572 * read and write do not hang.
575 ray_detach(device_t dev)
577 struct ray_softc *sc = device_get_softc(dev);
578 struct ifnet *ifp = &sc->arpcom.ac_if;
579 struct ray_comq_entry *com;
584 RAY_DPRINTF(sc, RAY_DBG_SUBR | RAY_DBG_STOP, "");
586 if ((sc == NULL) || (sc->sc_gone))
590 * Mark as not running and detach the interface.
592 * N.B. if_detach can trigger ioctls so we do it first and
593 * then clean the runq.
596 sc->sc_c.np_havenet = 0;
597 ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
601 * Stop the runq and wake up anyone sleeping for us.
603 callout_stop(&sc->com_timer);
604 callout_stop(&sc->tx_timer);
605 com = TAILQ_FIRST(&sc->sc_comq);
606 for (com = TAILQ_FIRST(&sc->sc_comq); com != NULL;
607 com = TAILQ_NEXT(com, c_chain)) {
608 com->c_flags |= RAY_COM_FDETACHED;
610 RAY_DPRINTF(sc, RAY_DBG_STOP, "looking at com %p %b",
611 com, com->c_flags, RAY_COM_FLAGS_PRINTFB);
612 if (com->c_flags & RAY_COM_FWOK) {
613 RAY_DPRINTF(sc, RAY_DBG_STOP, "waking com %p", com);
614 wakeup(com->c_wakeup);
622 RAY_DPRINTF(sc, RAY_DBG_STOP, "unloading complete");
630 * Network ioctl request.
633 ray_ioctl(register struct ifnet *ifp, u_long command, caddr_t data,
636 struct ray_softc *sc = ifp->if_softc;
637 struct ray_param_req pr;
638 struct ray_stats_req sr;
639 struct ifreq *ifr = (struct ifreq *)data;
640 int s, error, error2;
642 RAY_DPRINTF(sc, RAY_DBG_SUBR | RAY_DBG_IOCTL, "");
644 if ((sc == NULL) || (sc->sc_gone))
652 RAY_DPRINTF(sc, RAY_DBG_IOCTL, "SIFFLAGS 0x%0x", ifp->if_flags);
654 * If the interface is marked up we call ray_init_user.
655 * This will deal with mcast and promisc flags as well as
656 * initialising the hardware if it needs it.
658 if (ifp->if_flags & IFF_UP)
659 error = ray_init_user(sc);
661 error = ray_stop_user(sc);
666 RAY_DPRINTF(sc, RAY_DBG_IOCTL, "ADDMULTI/DELMULTI");
667 error = ray_mcast_user(sc);
671 RAY_DPRINTF(sc, RAY_DBG_IOCTL, "SRAYPARAM");
672 if ((error = copyin(ifr->ifr_data, &pr, sizeof(pr))))
674 error = ray_upparams_user(sc, &pr);
675 error2 = copyout(&pr, ifr->ifr_data, sizeof(pr));
676 error = error2 ? error2 : error;
680 RAY_DPRINTF(sc, RAY_DBG_IOCTL, "GRAYPARAM");
681 if ((error = copyin(ifr->ifr_data, &pr, sizeof(pr))))
683 error = ray_repparams_user(sc, &pr);
684 error2 = copyout(&pr, ifr->ifr_data, sizeof(pr));
685 error = error2 ? error2 : error;
689 RAY_DPRINTF(sc, RAY_DBG_IOCTL, "GRAYSTATS");
690 error = ray_repstats_user(sc, &sr);
691 error2 = copyout(&sr, ifr->ifr_data, sizeof(sr));
692 error = error2 ? error2 : error;
696 RAY_DPRINTF(sc, RAY_DBG_IOCTL, "GRAYSIGLEV");
697 error = copyout(sc->sc_siglevs, ifr->ifr_data,
698 sizeof(sc->sc_siglevs));
702 RAY_DPRINTF(sc, RAY_DBG_IOCTL, "GIFFLAGS");
707 RAY_DPRINTF(sc, RAY_DBG_IOCTL, "GIFMETRIC");
712 RAY_DPRINTF(sc, RAY_DBG_IOCTL, "GIFMTU");
717 RAY_DPRINTF(sc, RAY_DBG_IOCTL, "GIFPYHS");
722 RAY_DPRINTF(sc, RAY_DBG_IOCTL, "SIFMEDIA");
727 RAY_DPRINTF(sc, RAY_DBG_IOCTL, "GIFMEDIA");
732 error = ether_ioctl(ifp, command, data);
742 * Ethernet layer entry to ray_init - discard errors
747 struct ray_softc *sc = (struct ray_softc *)xsc;
753 * User land entry to network initialisation and changes in interface flags.
755 * We do a very little work here, just creating runq entries to
756 * processes the actions needed to cope with interface flags. We do it
757 * this way in case there are runq entries outstanding from earlier
758 * ioctls that modify the interface flags.
760 * Returns values are either 0 for success, a varity of resource allocation
761 * failures or errors in the command sent to the card.
763 * Note, IFF_RUNNING is eventually set by init_sj_done or init_assoc_done
766 ray_init_user(struct ray_softc *sc)
768 struct ray_comq_entry *com[6];
771 RAY_DPRINTF(sc, RAY_DBG_SUBR | RAY_DBG_STARTJOIN, "");
774 * Create the following runq entries to bring the card up.
776 * init_download - download the network to the card
777 * init_mcast - reset multicast list
778 * init_sj - find or start a BSS
779 * init_auth - authenticate with a ESSID if needed
780 * init_assoc - associate with a ESSID if needed
782 * They are only actually executed if the card is not running.
783 * We may enter this routine from a simple change of IP
784 * address and do not need to get the card to do these things.
785 * However, we cannot perform the check here as there may be
786 * commands in the runq that change the IFF_RUNNING state of
790 com[ncom++] = RAY_COM_MALLOC(ray_init_download, RAY_COM_FCHKRUNNING);
791 com[ncom++] = RAY_COM_MALLOC(ray_init_mcast, RAY_COM_FCHKRUNNING);
792 com[ncom++] = RAY_COM_MALLOC(ray_init_sj, RAY_COM_FCHKRUNNING);
793 com[ncom++] = RAY_COM_MALLOC(ray_init_auth, RAY_COM_FCHKRUNNING);
794 com[ncom++] = RAY_COM_MALLOC(ray_init_assoc, RAY_COM_FCHKRUNNING);
797 * Create runq entries to process flags
799 * promisc - set/reset PROMISC and ALLMULTI flags
801 * They are only actually executed if the card is running
803 com[ncom++] = RAY_COM_MALLOC(ray_promisc, 0);
805 RAY_COM_RUNQ(sc, com, ncom, "rayinit", error);
807 /* XXX no real error processing from anything yet! */
809 RAY_COM_FREE(com, ncom);
815 * Runq entry for resetting driver and downloading start up structures to card
818 ray_init_download(struct ray_softc *sc, struct ray_comq_entry *com)
820 struct ifnet *ifp = &sc->arpcom.ac_if;
822 RAY_DPRINTF(sc, RAY_DBG_SUBR | RAY_DBG_STARTJOIN, "");
824 /* If the card already running we might not need to download */
825 RAY_COM_CHKRUNNING(sc, com, ifp);
828 * Reset instance variables
830 * The first set are network parameters that are read back when
831 * the card starts or joins the network.
833 * The second set are network parameters that are downloaded to
836 * The third set are driver parameters.
838 * All of the variables in these sets can be updated by the
841 * XXX see the ray_attach section for stuff to move
843 sc->sc_d.np_upd_param = 0;
844 bzero(sc->sc_d.np_bss_id, ETHER_ADDR_LEN);
845 sc->sc_d.np_inited = 0;
846 sc->sc_d.np_def_txrate = RAY_MIB_BASIC_RATE_SET_DEFAULT;
847 sc->sc_d.np_encrypt = 0;
849 bzero(sc->sc_d.np_ssid, IEEE80211_NWID_LEN);
850 if (sc->sc_version == RAY_ECFS_BUILD_4) {
851 sc->sc_d.np_net_type = RAY_MIB_NET_TYPE_V4;
852 strncpy(sc->sc_d.np_ssid, RAY_MIB_SSID_V4, IEEE80211_NWID_LEN);
853 sc->sc_d.np_ap_status = RAY_MIB_AP_STATUS_V4;
854 sc->sc_d.np_framing = RAY_FRAMING_ENCAPSULATION;
856 sc->sc_d.np_net_type = RAY_MIB_NET_TYPE_V5;
857 strncpy(sc->sc_d.np_ssid, RAY_MIB_SSID_V5, IEEE80211_NWID_LEN);
858 sc->sc_d.np_ap_status = RAY_MIB_AP_STATUS_V5;
859 sc->sc_d.np_framing = RAY_FRAMING_TRANSLATION;
861 sc->sc_d.np_priv_start = RAY_MIB_PRIVACY_MUST_START_DEFAULT;
862 sc->sc_d.np_priv_join = RAY_MIB_PRIVACY_CAN_JOIN_DEFAULT;
863 sc->sc_d.np_promisc = !!(ifp->if_flags & (IFF_PROMISC | IFF_ALLMULTI));
865 /* XXX this is a hack whilst I transition the code. The instance
866 * XXX variables above should be set somewhere else. This is needed for
868 bcopy(&sc->sc_d, &com->c_desired, sizeof(struct ray_nw_param));
871 * Download the right firmware defaults
873 if (sc->sc_version == RAY_ECFS_BUILD_4)
874 ray_init_download_v4(sc, com);
876 ray_init_download_v5(sc, com);
881 ray_ccs_fill(sc, com->c_ccs, RAY_CMD_DOWNLOAD_PARAMS);
882 ray_com_ecf(sc, com);
886 do { (p)[0] = ((v >> 8) & 0xff); (p)[1] = (v & 0xff); } while(0)
888 * Firmware version 4 defaults - see if_raymib.h for details
891 ray_init_download_v4(struct ray_softc *sc, struct ray_comq_entry *com)
893 struct ray_mib_4 ray_mib_4_default;
895 RAY_DPRINTF(sc, RAY_DBG_SUBR | RAY_DBG_STARTJOIN, "");
898 #define MIB4(m) ray_mib_4_default.m
900 MIB4(mib_net_type) = com->c_desired.np_net_type;
901 MIB4(mib_ap_status) = com->c_desired.np_ap_status;
902 bcopy(com->c_desired.np_ssid, MIB4(mib_ssid), IEEE80211_NWID_LEN);
903 MIB4(mib_scan_mode) = RAY_MIB_SCAN_MODE_V4;
904 MIB4(mib_apm_mode) = RAY_MIB_APM_MODE_V4;
905 bcopy(sc->sc_station_addr, MIB4(mib_mac_addr), ETHER_ADDR_LEN);
906 PUT2(MIB4(mib_frag_thresh), RAY_MIB_FRAG_THRESH_V4);
907 PUT2(MIB4(mib_dwell_time), RAY_MIB_DWELL_TIME_V4);
908 PUT2(MIB4(mib_beacon_period), RAY_MIB_BEACON_PERIOD_V4);
909 MIB4(mib_dtim_interval) = RAY_MIB_DTIM_INTERVAL_V4;
910 MIB4(mib_max_retry) = RAY_MIB_MAX_RETRY_V4;
911 MIB4(mib_ack_timo) = RAY_MIB_ACK_TIMO_V4;
912 MIB4(mib_sifs) = RAY_MIB_SIFS_V4;
913 MIB4(mib_difs) = RAY_MIB_DIFS_V4;
914 MIB4(mib_pifs) = RAY_MIB_PIFS_V4;
915 PUT2(MIB4(mib_rts_thresh), RAY_MIB_RTS_THRESH_V4);
916 PUT2(MIB4(mib_scan_dwell), RAY_MIB_SCAN_DWELL_V4);
917 PUT2(MIB4(mib_scan_max_dwell), RAY_MIB_SCAN_MAX_DWELL_V4);
918 MIB4(mib_assoc_timo) = RAY_MIB_ASSOC_TIMO_V4;
919 MIB4(mib_adhoc_scan_cycle) = RAY_MIB_ADHOC_SCAN_CYCLE_V4;
920 MIB4(mib_infra_scan_cycle) = RAY_MIB_INFRA_SCAN_CYCLE_V4;
921 MIB4(mib_infra_super_scan_cycle)
922 = RAY_MIB_INFRA_SUPER_SCAN_CYCLE_V4;
923 MIB4(mib_promisc) = com->c_desired.np_promisc;
924 PUT2(MIB4(mib_uniq_word), RAY_MIB_UNIQ_WORD_V4);
925 MIB4(mib_slot_time) = RAY_MIB_SLOT_TIME_V4;
926 MIB4(mib_roam_low_snr_thresh) = RAY_MIB_ROAM_LOW_SNR_THRESH_V4;
927 MIB4(mib_low_snr_count) = RAY_MIB_LOW_SNR_COUNT_V4;
928 MIB4(mib_infra_missed_beacon_count)
929 = RAY_MIB_INFRA_MISSED_BEACON_COUNT_V4;
930 MIB4(mib_adhoc_missed_beacon_count)
931 = RAY_MIB_ADHOC_MISSED_BEACON_COUNT_V4;
932 MIB4(mib_country_code) = RAY_MIB_COUNTRY_CODE_V4;
933 MIB4(mib_hop_seq) = RAY_MIB_HOP_SEQ_V4;
934 MIB4(mib_hop_seq_len) = RAY_MIB_HOP_SEQ_LEN_V4;
935 MIB4(mib_cw_max) = RAY_MIB_CW_MAX_V4;
936 MIB4(mib_cw_min) = RAY_MIB_CW_MIN_V4;
937 MIB4(mib_noise_filter_gain) = RAY_MIB_NOISE_FILTER_GAIN_DEFAULT;
938 MIB4(mib_noise_limit_offset) = RAY_MIB_NOISE_LIMIT_OFFSET_DEFAULT;
939 MIB4(mib_rssi_thresh_offset) = RAY_MIB_RSSI_THRESH_OFFSET_DEFAULT;
940 MIB4(mib_busy_thresh_offset) = RAY_MIB_BUSY_THRESH_OFFSET_DEFAULT;
941 MIB4(mib_sync_thresh) = RAY_MIB_SYNC_THRESH_DEFAULT;
942 MIB4(mib_test_mode) = RAY_MIB_TEST_MODE_DEFAULT;
943 MIB4(mib_test_min_chan) = RAY_MIB_TEST_MIN_CHAN_DEFAULT;
944 MIB4(mib_test_max_chan) = RAY_MIB_TEST_MAX_CHAN_DEFAULT;
947 SRAM_WRITE_REGION(sc, RAY_HOST_TO_ECF_BASE,
948 &ray_mib_4_default, sizeof(ray_mib_4_default));
952 * Firmware version 5 defaults - see if_raymib.h for details
955 ray_init_download_v5(struct ray_softc *sc, struct ray_comq_entry *com)
957 struct ray_mib_5 ray_mib_5_default;
959 RAY_DPRINTF(sc, RAY_DBG_SUBR | RAY_DBG_STARTJOIN, "");
962 #define MIB5(m) ray_mib_5_default.m
963 MIB5(mib_net_type) = com->c_desired.np_net_type;
964 MIB5(mib_ap_status) = com->c_desired.np_ap_status;
965 bcopy(com->c_desired.np_ssid, MIB5(mib_ssid), IEEE80211_NWID_LEN);
966 MIB5(mib_scan_mode) = RAY_MIB_SCAN_MODE_V5;
967 MIB5(mib_apm_mode) = RAY_MIB_APM_MODE_V5;
968 bcopy(sc->sc_station_addr, MIB5(mib_mac_addr), ETHER_ADDR_LEN);
969 PUT2(MIB5(mib_frag_thresh), RAY_MIB_FRAG_THRESH_V5);
970 PUT2(MIB5(mib_dwell_time), RAY_MIB_DWELL_TIME_V5);
971 PUT2(MIB5(mib_beacon_period), RAY_MIB_BEACON_PERIOD_V5);
972 MIB5(mib_dtim_interval) = RAY_MIB_DTIM_INTERVAL_V5;
973 MIB5(mib_max_retry) = RAY_MIB_MAX_RETRY_V5;
974 MIB5(mib_ack_timo) = RAY_MIB_ACK_TIMO_V5;
975 MIB5(mib_sifs) = RAY_MIB_SIFS_V5;
976 MIB5(mib_difs) = RAY_MIB_DIFS_V5;
977 MIB5(mib_pifs) = RAY_MIB_PIFS_V5;
978 PUT2(MIB5(mib_rts_thresh), RAY_MIB_RTS_THRESH_V5);
979 PUT2(MIB5(mib_scan_dwell), RAY_MIB_SCAN_DWELL_V5);
980 PUT2(MIB5(mib_scan_max_dwell), RAY_MIB_SCAN_MAX_DWELL_V5);
981 MIB5(mib_assoc_timo) = RAY_MIB_ASSOC_TIMO_V5;
982 MIB5(mib_adhoc_scan_cycle) = RAY_MIB_ADHOC_SCAN_CYCLE_V5;
983 MIB5(mib_infra_scan_cycle) = RAY_MIB_INFRA_SCAN_CYCLE_V5;
984 MIB5(mib_infra_super_scan_cycle)
985 = RAY_MIB_INFRA_SUPER_SCAN_CYCLE_V5;
986 MIB5(mib_promisc) = com->c_desired.np_promisc;
987 PUT2(MIB5(mib_uniq_word), RAY_MIB_UNIQ_WORD_V5);
988 MIB5(mib_slot_time) = RAY_MIB_SLOT_TIME_V5;
989 MIB5(mib_roam_low_snr_thresh) = RAY_MIB_ROAM_LOW_SNR_THRESH_V5;
990 MIB5(mib_low_snr_count) = RAY_MIB_LOW_SNR_COUNT_V5;
991 MIB5(mib_infra_missed_beacon_count)
992 = RAY_MIB_INFRA_MISSED_BEACON_COUNT_V5;
993 MIB5(mib_adhoc_missed_beacon_count)
994 = RAY_MIB_ADHOC_MISSED_BEACON_COUNT_V5;
995 MIB5(mib_country_code) = RAY_MIB_COUNTRY_CODE_V5;
996 MIB5(mib_hop_seq) = RAY_MIB_HOP_SEQ_V5;
997 MIB5(mib_hop_seq_len) = RAY_MIB_HOP_SEQ_LEN_V5;
998 PUT2(MIB5(mib_cw_max), RAY_MIB_CW_MAX_V5);
999 PUT2(MIB5(mib_cw_min), RAY_MIB_CW_MIN_V5);
1000 MIB5(mib_noise_filter_gain) = RAY_MIB_NOISE_FILTER_GAIN_DEFAULT;
1001 MIB5(mib_noise_limit_offset) = RAY_MIB_NOISE_LIMIT_OFFSET_DEFAULT;
1002 MIB5(mib_rssi_thresh_offset) = RAY_MIB_RSSI_THRESH_OFFSET_DEFAULT;
1003 MIB5(mib_busy_thresh_offset) = RAY_MIB_BUSY_THRESH_OFFSET_DEFAULT;
1004 MIB5(mib_sync_thresh) = RAY_MIB_SYNC_THRESH_DEFAULT;
1005 MIB5(mib_test_mode) = RAY_MIB_TEST_MODE_DEFAULT;
1006 MIB5(mib_test_min_chan) = RAY_MIB_TEST_MIN_CHAN_DEFAULT;
1007 MIB5(mib_test_max_chan) = RAY_MIB_TEST_MAX_CHAN_DEFAULT;
1008 MIB5(mib_allow_probe_resp) = RAY_MIB_ALLOW_PROBE_RESP_DEFAULT;
1009 MIB5(mib_privacy_must_start) = com->c_desired.np_priv_start;
1010 MIB5(mib_privacy_can_join) = com->c_desired.np_priv_join;
1011 MIB5(mib_basic_rate_set[0]) = com->c_desired.np_def_txrate;
1014 SRAM_WRITE_REGION(sc, RAY_HOST_TO_ECF_BASE,
1015 &ray_mib_5_default, sizeof(ray_mib_5_default));
1020 * Download completion routine
1023 ray_init_download_done(struct ray_softc *sc, u_int8_t status, size_t ccs)
1025 RAY_DPRINTF(sc, RAY_DBG_SUBR | RAY_DBG_STARTJOIN, "");
1026 RAY_COM_CHECK(sc, ccs);
1028 RAY_CCSERR(sc, status, if_oerrors); /* XXX error counter */
1030 ray_com_ecf_done(sc);
1034 * Runq entry to empty the multicast filter list
1037 ray_init_mcast(struct ray_softc *sc, struct ray_comq_entry *com)
1039 struct ifnet *ifp = &sc->arpcom.ac_if;
1041 RAY_DPRINTF(sc, RAY_DBG_SUBR | RAY_DBG_STARTJOIN, "");
1044 /* If the card already running we might not need to reset the list */
1045 RAY_COM_CHKRUNNING(sc, com, ifp);
1050 ray_ccs_fill(sc, com->c_ccs, RAY_CMD_UPDATE_MCAST);
1051 SRAM_WRITE_FIELD_1(sc, com->c_ccs, ray_cmd_update_mcast, c_nmcast, 0);
1053 ray_com_ecf(sc, com);
1057 * Runq entry to starting or joining a network
1060 ray_init_sj(struct ray_softc *sc, struct ray_comq_entry *com)
1062 struct ifnet *ifp = &sc->arpcom.ac_if;
1063 struct ray_net_params np;
1066 RAY_DPRINTF(sc, RAY_DBG_SUBR | RAY_DBG_STARTJOIN, "");
1069 /* If the card already running we might not need to start the n/w */
1070 RAY_COM_CHKRUNNING(sc, com, ifp);
1073 * Set up the right start or join command and determine
1074 * whether we should tell the card about a change in operating
1077 sc->sc_c.np_havenet = 0;
1078 if (sc->sc_d.np_net_type == RAY_MIB_NET_TYPE_ADHOC)
1079 ray_ccs_fill(sc, com->c_ccs, RAY_CMD_START_NET);
1081 ray_ccs_fill(sc, com->c_ccs, RAY_CMD_JOIN_NET);
1084 if (sc->sc_c.np_net_type != sc->sc_d.np_net_type)
1086 if (bcmp(sc->sc_c.np_ssid, sc->sc_d.np_ssid, IEEE80211_NWID_LEN))
1088 if (sc->sc_c.np_priv_join != sc->sc_d.np_priv_join)
1090 if (sc->sc_c.np_priv_start != sc->sc_d.np_priv_start)
1092 RAY_DPRINTF(sc, RAY_DBG_STARTJOIN,
1093 "%s updating nw params", update?"is":"not");
1095 bzero(&np, sizeof(np));
1096 np.p_net_type = sc->sc_d.np_net_type;
1097 bcopy(sc->sc_d.np_ssid, np.p_ssid, IEEE80211_NWID_LEN);
1098 np.p_privacy_must_start = sc->sc_d.np_priv_start;
1099 np.p_privacy_can_join = sc->sc_d.np_priv_join;
1100 SRAM_WRITE_REGION(sc, RAY_HOST_TO_ECF_BASE, &np, sizeof(np));
1101 SRAM_WRITE_FIELD_1(sc, com->c_ccs, ray_cmd_net, c_upd_param, 1);
1103 SRAM_WRITE_FIELD_1(sc, com->c_ccs, ray_cmd_net, c_upd_param, 0);
1108 ray_com_ecf(sc, com);
1112 * Complete start command or intermediate step in assoc command
1115 ray_init_sj_done(struct ray_softc *sc, u_int8_t status, size_t ccs)
1117 struct ifnet *ifp = &sc->arpcom.ac_if;
1119 RAY_DPRINTF(sc, RAY_DBG_SUBR | RAY_DBG_STARTJOIN, "");
1121 RAY_COM_CHECK(sc, ccs);
1123 RAY_CCSERR(sc, status, if_oerrors); /* XXX error counter */
1126 * Read back network parameters that the ECF sets
1128 SRAM_READ_REGION(sc, ccs, &sc->sc_c.p_1, sizeof(struct ray_cmd_net));
1130 /* Adjust values for buggy firmware */
1131 if (sc->sc_c.np_inited == 0x55)
1132 sc->sc_c.np_inited = 0;
1133 if (sc->sc_c.np_def_txrate == 0x55)
1134 sc->sc_c.np_def_txrate = sc->sc_d.np_def_txrate;
1135 if (sc->sc_c.np_encrypt == 0x55)
1136 sc->sc_c.np_encrypt = sc->sc_d.np_encrypt;
1139 * Update our local state if we updated the network parameters
1140 * when the START_NET or JOIN_NET was issued.
1142 if (sc->sc_c.np_upd_param) {
1143 RAY_DPRINTF(sc, RAY_DBG_STARTJOIN, "updated parameters");
1144 SRAM_READ_REGION(sc, RAY_HOST_TO_ECF_BASE,
1145 &sc->sc_c.p_2, sizeof(struct ray_net_params));
1149 * Hurrah! The network is now active.
1151 * Clearing IFF_OACTIVE will ensure that the system will send us
1152 * packets. Just before we return from the interrupt context
1153 * we check to see if packets have been queued.
1155 if (SRAM_READ_FIELD_1(sc, ccs, ray_cmd, c_cmd) == RAY_CMD_START_NET) {
1156 sc->sc_c.np_havenet = 1;
1157 sc->sc_c.np_framing = sc->sc_d.np_framing;
1158 ifp->if_flags |= IFF_RUNNING;
1159 ifp->if_flags &= ~IFF_OACTIVE;
1162 ray_com_ecf_done(sc);
1166 * Runq entry to authenticate with an access point or another station
1169 ray_init_auth(struct ray_softc *sc, struct ray_comq_entry *com)
1171 struct ifnet *ifp = &sc->arpcom.ac_if;
1173 RAY_DPRINTF(sc, RAY_DBG_SUBR | RAY_DBG_STARTJOIN | RAY_DBG_AUTH, "");
1175 /* If card already running we might not need to authenticate */
1176 RAY_COM_CHKRUNNING(sc, com, ifp);
1179 * XXX Don't do anything if we are not in a managed network
1181 * XXX V4 adhoc does not need this, V5 adhoc unknown
1183 if (sc->sc_c.np_net_type != RAY_MIB_NET_TYPE_INFRA) {
1184 ray_com_runq_done(sc);
1189 * XXX_AUTH need to think of run queue when doing auths from request i.e. would
1190 * XXX_AUTH need to have auth at top of runq?
1191 * XXX_AUTH ditto for sending any auth response packets...what about timeouts?
1197 /* XXX_AUTH check exit status and retry or fail as we can't associate without this */
1198 ray_init_auth_send(sc, sc->sc_c.np_bss_id, IEEE80211_AUTH_OPEN_REQUEST);
1202 * Build and send an authentication packet
1204 * If an error occurs, returns 1 else returns 0.
1207 ray_init_auth_send(struct ray_softc *sc, u_int8_t *dst, int sequence)
1212 RAY_DPRINTF(sc, RAY_DBG_SUBR | RAY_DBG_STARTJOIN | RAY_DBG_AUTH, "");
1214 /* Get a control block */
1215 if (ray_ccs_tx(sc, &ccs, &bufp)) {
1216 RAY_RECERR(sc, "could not obtain a ccs");
1220 /* Fill the header in */
1221 bufp = ray_tx_wrhdr(sc, bufp,
1222 IEEE80211_FC0_TYPE_MGT | IEEE80211_FC0_SUBTYPE_AUTH,
1223 IEEE80211_FC1_DIR_NODS,
1225 sc->arpcom.ac_enaddr,
1226 sc->sc_c.np_bss_id);
1228 /* Add algorithm number */
1229 SRAM_WRITE_1(sc, bufp + pktlen++, IEEE80211_AUTH_ALG_OPEN);
1230 SRAM_WRITE_1(sc, bufp + pktlen++, 0);
1232 /* Add sequence number */
1233 SRAM_WRITE_1(sc, bufp + pktlen++, sequence);
1234 SRAM_WRITE_1(sc, bufp + pktlen++, 0);
1236 /* Add status code */
1237 SRAM_WRITE_1(sc, bufp + pktlen++, 0);
1238 SRAM_WRITE_1(sc, bufp + pktlen++, 0);
1239 pktlen += sizeof(struct ieee80211_frame);
1241 return (ray_tx_send(sc, ccs, pktlen, dst));
1245 * Complete authentication runq
1248 ray_init_auth_done(struct ray_softc *sc, u_int8_t status)
1250 RAY_DPRINTF(sc, RAY_DBG_SUBR | RAY_DBG_STARTJOIN | RAY_DBG_AUTH, "");
1252 if (status != IEEE80211_STATUS_SUCCESS)
1253 RAY_RECERR(sc, "authentication failed with status %d", status);
1255 * XXX_AUTH retry? if not just recall ray_init_auth_send and dont clear runq?
1256 * XXX_AUTH association requires that authenitcation is successful
1257 * XXX_AUTH before we associate, and the runq is the only way to halt the
1258 * XXX_AUTH progress of associate.
1259 * XXX_AUTH In this case I might not need the RAY_AUTH_NEEDED state
1261 ray_com_runq_done(sc);
1265 * Runq entry to starting an association with an access point
1268 ray_init_assoc(struct ray_softc *sc, struct ray_comq_entry *com)
1270 struct ifnet *ifp = &sc->arpcom.ac_if;
1272 RAY_DPRINTF(sc, RAY_DBG_SUBR | RAY_DBG_STARTJOIN, "");
1274 /* If the card already running we might not need to associate */
1275 RAY_COM_CHKRUNNING(sc, com, ifp);
1278 * Don't do anything if we are not in a managed network
1280 if (sc->sc_c.np_net_type != RAY_MIB_NET_TYPE_INFRA) {
1281 ray_com_runq_done(sc);
1288 ray_ccs_fill(sc, com->c_ccs, RAY_CMD_START_ASSOC);
1289 ray_com_ecf(sc, com);
1293 * Complete association
1296 ray_init_assoc_done(struct ray_softc *sc, u_int8_t status, size_t ccs)
1298 struct ifnet *ifp = &sc->arpcom.ac_if;
1300 RAY_DPRINTF(sc, RAY_DBG_SUBR | RAY_DBG_STARTJOIN, "");
1301 RAY_COM_CHECK(sc, ccs);
1303 RAY_CCSERR(sc, status, if_oerrors); /* XXX error counter */
1306 * Hurrah! The network is now active.
1308 * Clearing IFF_OACTIVE will ensure that the system will send us
1309 * packets. Just before we return from the interrupt context
1310 * we check to see if packets have been queued.
1312 sc->sc_c.np_havenet = 1;
1313 sc->sc_c.np_framing = sc->sc_d.np_framing;
1314 ifp->if_flags |= IFF_RUNNING;
1315 ifp->if_flags &= ~IFF_OACTIVE;
1317 ray_com_ecf_done(sc);
1323 * Inhibit card - if we can't prevent reception then do not worry;
1324 * stopping a NIC only guarantees no TX.
1326 * The change to the interface flags is done via the runq so that any
1327 * existing commands can execute normally.
1330 ray_stop_user(struct ray_softc *sc)
1332 struct ray_comq_entry *com[1];
1335 RAY_DPRINTF(sc, RAY_DBG_SUBR | RAY_DBG_STOP, "");
1338 * Schedule the real stop routine
1341 com[ncom++] = RAY_COM_MALLOC(ray_stop, 0);
1343 RAY_COM_RUNQ(sc, com, ncom, "raystop", error);
1345 /* XXX no real error processing from anything yet! */
1347 RAY_COM_FREE(com, ncom);
1353 * Runq entry for stopping the interface activity
1356 ray_stop(struct ray_softc *sc, struct ray_comq_entry *com)
1358 struct ifnet *ifp = &sc->arpcom.ac_if;
1360 RAY_DPRINTF(sc, RAY_DBG_SUBR | RAY_DBG_STOP, "");
1363 * Mark as not running and drain output queue
1365 ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
1367 ifq_purge(&ifp->if_snd);
1368 ray_com_runq_done(sc);
1372 ray_watchdog(struct ifnet *ifp)
1374 struct ray_softc *sc = ifp->if_softc;
1376 RAY_DPRINTF(sc, RAY_DBG_SUBR, "");
1379 if ((sc == NULL) || (sc->sc_gone))
1382 RAY_PRINTF(sc, "watchdog timeout");
1386 * Transmit packet handling
1392 * We make two assumptions here:
1393 * 1) That the current priority is set to splimp _before_ this code
1394 * is called *and* is returned to the appropriate priority after
1396 * 2) That the IFF_OACTIVE flag is checked before this code is called
1397 * (i.e. that the output part of the interface is idle)
1399 * A simple one packet at a time TX routine is used - we don't bother
1400 * chaining TX buffers. Performance is sufficient to max out the
1401 * wireless link on a P75.
1403 * AST J30 Windows 95A (100MHz Pentium) to
1404 * Libretto 50CT FreeBSD-3.1 (75MHz Pentium) 167.37kB/s
1405 * Nonname box FreeBSD-3.4 (233MHz AMD K6) 161.82kB/s
1407 * Libretto 50CT FreeBSD-3.1 (75MHz Pentium) to
1408 * AST J30 Windows 95A (100MHz Pentium) 167.37kB/s
1409 * Nonname box FreeBSD-3.4 (233MHz AMD K6) 161.38kB/s
1411 * Given that 160kB/s is saturating the 2Mb/s wireless link we
1414 * In short I'm happy that the added complexity of chaining TX
1415 * packets together isn't worth it for my machines.
1418 ray_tx(struct ifnet *ifp)
1420 struct ray_softc *sc = ifp->if_softc;
1421 struct mbuf *m0, *m;
1422 struct ether_header *eh;
1427 RAY_DPRINTF(sc, RAY_DBG_SUBR | RAY_DBG_TX, "");
1431 * Some simple checks first - some are overkill
1433 if ((sc == NULL) || (sc->sc_gone))
1435 if (!(ifp->if_flags & IFF_RUNNING)) {
1436 RAY_RECERR(sc, "cannot transmit - not running");
1439 if (!sc->sc_c.np_havenet) {
1440 RAY_RECERR(sc, "cannot transmit - no network");
1443 if (!RAY_ECF_READY(sc)) {
1444 /* Can't assume that the ECF is busy because of this driver */
1445 if (!callout_active(&sc->tx_timer)) {
1446 callout_reset(&sc->tx_timer, RAY_TX_TIMEOUT,
1451 callout_stop(&sc->tx_timer);
1454 * We find a ccs before we process the mbuf so that we are sure it
1455 * is worthwhile processing the packet. All errors in the mbuf
1456 * processing are either errors in the mbuf or gross configuration
1457 * errors and the packet wouldn't get through anyway.
1459 if (ray_ccs_tx(sc, &ccs, &bufp)) {
1460 ifp->if_flags |= IFF_OACTIVE;
1465 * Get the mbuf and process it - we have to remember to free the
1466 * ccs if there are any errors.
1468 m0 = ifq_dequeue(&ifp->if_snd);
1470 RAY_CCS_FREE(sc, ccs);
1474 pktlen = m0->m_pkthdr.len;
1475 if (pktlen > ETHER_MAX_LEN - ETHER_CRC_LEN) {
1476 RAY_RECERR(sc, "mbuf too long %d", pktlen);
1477 RAY_CCS_FREE(sc, ccs);
1483 m0 = m_pullup(m0, sizeof(struct ether_header));
1485 RAY_RECERR(sc, "could not pullup ether");
1486 RAY_CCS_FREE(sc, ccs);
1490 eh = mtod(m0, struct ether_header *);
1493 * Write the 802.11 header according to network type etc.
1495 if (sc->sc_c.np_net_type == RAY_MIB_NET_TYPE_ADHOC)
1496 bufp = ray_tx_wrhdr(sc, bufp,
1497 IEEE80211_FC0_TYPE_DATA,
1498 IEEE80211_FC1_DIR_NODS,
1501 sc->sc_c.np_bss_id);
1503 if (sc->sc_c.np_ap_status == RAY_MIB_AP_STATUS_TERMINAL)
1504 bufp = ray_tx_wrhdr(sc, bufp,
1505 IEEE80211_FC0_TYPE_DATA,
1506 IEEE80211_FC1_DIR_TODS,
1511 bufp = ray_tx_wrhdr(sc, bufp,
1512 IEEE80211_FC0_TYPE_DATA,
1513 IEEE80211_FC1_DIR_FROMDS,
1523 switch (sc->sc_c.np_framing) {
1525 case RAY_FRAMING_ENCAPSULATION:
1526 /* Nice and easy - nothing! (just add an 802.11 header) */
1529 case RAY_FRAMING_TRANSLATION:
1531 * Drop the first address in the ethernet header and
1532 * write an LLC and SNAP header over the second.
1534 m_adj(m0, ETHER_ADDR_LEN);
1536 RAY_RECERR(sc, "could not get space for 802.2 header");
1537 RAY_CCS_FREE(sc, ccs);
1541 llc = mtod(m0, struct llc *);
1542 llc->llc_dsap = LLC_SNAP_LSAP;
1543 llc->llc_ssap = LLC_SNAP_LSAP;
1544 llc->llc_control = LLC_UI;
1545 llc->llc_un.type_snap.org_code[0] = 0;
1546 llc->llc_un.type_snap.org_code[1] = 0;
1547 llc->llc_un.type_snap.org_code[2] = 0;
1551 RAY_RECERR(sc, "unknown framing type %d", sc->sc_c.np_framing);
1552 RAY_CCS_FREE(sc, ccs);
1559 RAY_RECERR(sc, "could not frame packet");
1560 RAY_CCS_FREE(sc, ccs);
1564 RAY_MBUF_DUMP(sc, RAY_DBG_TX, m0, "framed packet");
1567 * Copy the mbuf to the buffer in common memory
1569 * We drop and don't bother wrapping as Ethernet packets are 1518
1570 * bytes, we checked the mbuf earlier, and our TX buffers are 2048
1571 * bytes. We don't have 530 bytes of headers etc. so something
1574 pktlen = sizeof(struct ieee80211_frame);
1575 for (m = m0; m != NULL; m = m->m_next) {
1577 if ((len = m->m_len) == 0)
1579 if ((bufp + len) < RAY_TX_END)
1580 SRAM_WRITE_REGION(sc, bufp, mtod(m, u_int8_t *), len);
1582 RAY_RECERR(sc, "tx buffer overflow");
1583 RAY_CCS_FREE(sc, ccs);
1594 if (ray_tx_send(sc, ccs, pktlen, eh->ether_dhost))
1602 * Start timeout routine.
1604 * Used when card was busy but we needed to send a packet.
1607 ray_tx_timo(void *xsc)
1609 struct ray_softc *sc = (struct ray_softc *)xsc;
1610 struct ifnet *ifp = &sc->arpcom.ac_if;
1613 RAY_DPRINTF(sc, RAY_DBG_SUBR, "");
1615 if ((ifp->if_flags & IFF_OACTIVE) == 0 && !ifq_is_empty(&ifp->if_snd)) {
1623 * Write an 802.11 header into the Tx buffer space and return the
1624 * adjusted buffer pointer.
1627 ray_tx_wrhdr(struct ray_softc *sc, size_t bufp, u_int8_t type, u_int8_t fc1, u_int8_t *addr1, u_int8_t *addr2, u_int8_t *addr3)
1629 struct ieee80211_frame header;
1631 RAY_DPRINTF(sc, RAY_DBG_SUBR | RAY_DBG_TX, "");
1634 bzero(&header, sizeof(struct ieee80211_frame));
1635 header.i_fc[0] = (IEEE80211_FC0_VERSION_0 | type);
1636 header.i_fc[1] = fc1;
1637 bcopy(addr1, header.i_addr1, ETHER_ADDR_LEN);
1638 bcopy(addr2, header.i_addr2, ETHER_ADDR_LEN);
1639 bcopy(addr3, header.i_addr3, ETHER_ADDR_LEN);
1641 SRAM_WRITE_REGION(sc, bufp, (u_int8_t *)&header,
1642 sizeof(struct ieee80211_frame));
1644 return (bufp + sizeof(struct ieee80211_frame));
1648 * Fill in a few loose ends and kick the card to send the packet
1650 * Returns 0 on success, 1 on failure
1653 ray_tx_send(struct ray_softc *sc, size_t ccs, int pktlen, u_int8_t *dst)
1657 RAY_DPRINTF(sc, RAY_DBG_SUBR | RAY_DBG_TX, "");
1660 while (!RAY_ECF_READY(sc)) {
1661 DELAY(RAY_ECF_SPIN_DELAY);
1662 if (++i > RAY_ECF_SPIN_TRIES) {
1663 RAY_RECERR(sc, "ECF busy, dropping packet");
1664 RAY_CCS_FREE(sc, ccs);
1669 RAY_RECERR(sc, "spun %d times", i);
1671 SRAM_WRITE_FIELD_2(sc, ccs, ray_cmd_tx, c_len, pktlen);
1672 SRAM_WRITE_FIELD_1(sc, ccs, ray_cmd_tx, c_antenna,
1673 ray_tx_best_antenna(sc, dst));
1674 SRAM_WRITE_1(sc, RAY_SCB_CCSI, RAY_CCS_INDEX(ccs));
1675 RAY_ECF_START_CMD(sc);
1681 * Determine best antenna to use from rx level and antenna cache
1684 ray_tx_best_antenna(struct ray_softc *sc, u_int8_t *dst)
1686 struct ray_siglev *sl;
1690 RAY_DPRINTF(sc, RAY_DBG_SUBR | RAY_DBG_TX, "");
1692 if (sc->sc_version == RAY_ECFS_BUILD_4)
1695 /* try to find host */
1696 for (i = 0; i < RAY_NSIGLEVRECS; i++) {
1697 sl = &sc->sc_siglevs[i];
1698 if (bcmp(sl->rsl_host, dst, ETHER_ADDR_LEN) == 0)
1701 /* not found, return default setting */
1705 /* This is a simple thresholding scheme that takes the mean
1706 * of the best antenna history. This is okay but as it is a
1707 * filter, it adds a bit of lag in situations where the
1708 * best antenna swaps from one side to the other slowly. Don't know
1709 * how likely this is given the horrible fading though.
1712 for (i = 0; i < RAY_NANTENNA; i++) {
1713 antenna += sl->rsl_antennas[i];
1716 return (antenna > (RAY_NANTENNA >> 1));
1720 * Transmit now complete so clear ccs and network flags.
1723 ray_tx_done(struct ray_softc *sc, u_int8_t status, size_t ccs)
1725 struct ifnet *ifp = &sc->arpcom.ac_if;
1727 RAY_DPRINTF(sc, RAY_DBG_SUBR | RAY_DBG_TX, "");
1729 RAY_CCSERR(sc, status, if_oerrors);
1731 RAY_CCS_FREE(sc, ccs);
1733 if (ifp->if_flags & IFF_OACTIVE)
1734 ifp->if_flags &= ~IFF_OACTIVE;
1738 * Receiver packet handling
1742 * Receive a packet from the card
1745 ray_rx(struct ray_softc *sc, size_t rcs)
1747 struct ieee80211_frame *header;
1748 struct ifnet *ifp = &sc->arpcom.ac_if;
1750 size_t pktlen, fraglen, readlen, tmplen;
1752 u_int8_t siglev, antenna;
1756 RAY_DPRINTF(sc, RAY_DBG_SUBR, "");
1759 RAY_DPRINTF(sc, RAY_DBG_CCS, "using rcs 0x%x", rcs);
1765 * Get first part of packet and the length. Do some sanity checks
1768 first = RAY_CCS_INDEX(rcs);
1769 pktlen = SRAM_READ_FIELD_2(sc, rcs, ray_cmd_rx, c_pktlen);
1770 siglev = SRAM_READ_FIELD_1(sc, rcs, ray_cmd_rx, c_siglev);
1771 antenna = SRAM_READ_FIELD_1(sc, rcs, ray_cmd_rx, c_antenna);
1773 if ((pktlen > MCLBYTES) || (pktlen < sizeof(struct ieee80211_frame))) {
1774 RAY_RECERR(sc, "packet too big or too small");
1779 MGETHDR(m0, MB_DONTWAIT, MT_DATA);
1781 RAY_RECERR(sc, "MGETHDR failed");
1785 if (pktlen > MHLEN) {
1786 MCLGET(m0, MB_DONTWAIT);
1787 if (!(m0->m_flags & M_EXT)) {
1788 RAY_RECERR(sc, "MCLGET failed");
1795 m0->m_pkthdr.rcvif = ifp;
1796 m0->m_pkthdr.len = pktlen;
1798 mp = mtod(m0, u_int8_t *);
1801 * Walk the fragment chain to build the complete packet.
1803 * The use of two index variables removes a race with the
1804 * hardware. If one index were used the clearing of the CCS would
1805 * happen before reading the next pointer and the hardware can get in.
1806 * Not my idea but verbatim from the NetBSD driver.
1809 while ((i = ni) && (i != RAY_CCS_LINK_NULL)) {
1810 rcs = RAY_CCS_ADDRESS(i);
1811 ni = SRAM_READ_FIELD_1(sc, rcs, ray_cmd_rx, c_nextfrag);
1812 bufp = SRAM_READ_FIELD_2(sc, rcs, ray_cmd_rx, c_bufp);
1813 fraglen = SRAM_READ_FIELD_2(sc, rcs, ray_cmd_rx, c_len);
1814 if (fraglen + readlen > pktlen) {
1815 RAY_RECERR(sc, "bad length current 0x%x pktlen 0x%x",
1816 fraglen + readlen, pktlen);
1822 if ((i < RAY_RCS_FIRST) || (i > RAY_RCS_LAST)) {
1823 RAY_RECERR(sc, "bad rcs index 0x%x", i);
1830 ebufp = bufp + fraglen;
1831 if (ebufp <= RAY_RX_END)
1832 SRAM_READ_REGION(sc, bufp, mp, fraglen);
1834 SRAM_READ_REGION(sc, bufp, mp,
1835 (tmplen = RAY_RX_END - bufp));
1836 SRAM_READ_REGION(sc, RAY_RX_BASE, mp + tmplen,
1837 ebufp - RAY_RX_END);
1846 * Walk the chain again to free the rcss.
1849 while ((i = ni) && (i != RAY_CCS_LINK_NULL)) {
1850 rcs = RAY_CCS_ADDRESS(i);
1851 ni = SRAM_READ_FIELD_1(sc, rcs, ray_cmd_rx, c_nextfrag);
1852 RAY_CCS_FREE(sc, rcs);
1859 * Check the 802.11 packet type and hand off to
1860 * appropriate functions.
1862 header = mtod(m0, struct ieee80211_frame *);
1863 if ((header->i_fc[0] & IEEE80211_FC0_VERSION_MASK)
1864 != IEEE80211_FC0_VERSION_0) {
1865 RAY_RECERR(sc, "header not version 0 fc0 0x%x",
1871 switch (header->i_fc[0] & IEEE80211_FC0_TYPE_MASK) {
1873 case IEEE80211_FC0_TYPE_DATA:
1874 ray_rx_data(sc, m0, siglev, antenna);
1877 case IEEE80211_FC0_TYPE_MGT:
1881 case IEEE80211_FC0_TYPE_CTL:
1886 RAY_RECERR(sc, "unknown packet fc0 0x%x", header->i_fc[0]);
1893 * Deal with DATA packet types
1896 ray_rx_data(struct ray_softc *sc, struct mbuf *m0, u_int8_t siglev, u_int8_t antenna)
1898 struct ifnet *ifp = &sc->arpcom.ac_if;
1899 struct ieee80211_frame *header = mtod(m0, struct ieee80211_frame *);
1900 struct ether_header *eh;
1902 u_int8_t *sa = NULL, *da = NULL, *ra = NULL, *ta = NULL;
1905 RAY_DPRINTF(sc, RAY_DBG_SUBR | RAY_DBG_RX, "");
1908 * Check the the data packet subtype, some packets have
1909 * nothing in them so we will drop them here.
1911 switch (header->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK) {
1913 case IEEE80211_FC0_SUBTYPE_DATA:
1914 case IEEE80211_FC0_SUBTYPE_CF_ACK:
1915 case IEEE80211_FC0_SUBTYPE_CF_POLL:
1916 case IEEE80211_FC0_SUBTYPE_CF_ACPL:
1917 RAY_DPRINTF(sc, RAY_DBG_RX, "DATA packet");
1920 case IEEE80211_FC0_SUBTYPE_NODATA:
1921 case IEEE80211_FC0_SUBTYPE_CFACK:
1922 case IEEE80211_FC0_SUBTYPE_CFPOLL:
1923 case IEEE80211_FC0_SUBTYPE_CF_ACK_CF_ACK:
1924 RAY_DPRINTF(sc, RAY_DBG_RX, "NULL packet");
1930 RAY_RECERR(sc, "reserved DATA packet subtype 0x%x",
1931 header->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK);
1938 * Parse the To DS and From DS fields to determine the length
1939 * of the 802.11 header for use later on.
1941 * Additionally, furtle out the right destination and
1942 * source MAC addresses for the packet. Packets may come via
1943 * APs so the MAC addresses of the immediate node may be
1944 * different from the node that actually sent us the packet.
1946 * da destination address of final recipient
1947 * sa source address of orginator
1948 * ra receiver address of immediate recipient
1949 * ta transmitter address of immediate orginator
1951 * Address matching is performed on da or sa with the AP or
1952 * BSSID in ra and ta.
1954 RAY_MBUF_DUMP(sc, RAY_DBG_RX, m0, "(1) packet before framing");
1955 switch (header->i_fc[1] & IEEE80211_FC1_DIR_MASK) {
1957 case IEEE80211_FC1_DIR_NODS:
1958 da = ra = header->i_addr1;
1959 sa = ta = header->i_addr2;
1960 trim = sizeof(struct ieee80211_frame);
1961 RAY_DPRINTF(sc, RAY_DBG_RX, "from %6D to %6D",
1965 case IEEE80211_FC1_DIR_FROMDS:
1966 da = ra = header->i_addr1;
1967 ta = header->i_addr2;
1968 sa = header->i_addr3;
1969 trim = sizeof(struct ieee80211_frame);
1970 RAY_DPRINTF(sc, RAY_DBG_RX, "ap %6D from %6D to %6D",
1971 ta, ":", sa, ":", da, ":");
1974 case IEEE80211_FC1_DIR_TODS:
1975 ra = header->i_addr1;
1976 sa = ta = header->i_addr2;
1977 da = header->i_addr3;
1978 trim = sizeof(struct ieee80211_frame);
1979 RAY_DPRINTF(sc, RAY_DBG_RX, "from %6D to %6D ap %6D",
1980 sa, ":", da, ":", ra, ":");
1983 case IEEE80211_FC1_DIR_DSTODS:
1984 ra = header->i_addr1;
1985 ta = header->i_addr2;
1986 da = header->i_addr3;
1987 sa = (u_int8_t *)header+1;
1988 trim = sizeof(struct ieee80211_frame) + ETHER_ADDR_LEN;
1989 RAY_DPRINTF(sc, RAY_DBG_RX, "from %6D to %6D ap %6D to %6D",
1990 sa, ":", da, ":", ta, ":", ra, ":");
1997 * Each case must leave an Ethernet header and adjust trim.
1999 switch (sc->sc_c.np_framing) {
2001 case RAY_FRAMING_ENCAPSULATION:
2002 /* A NOP as the Ethernet header is in the packet */
2005 case RAY_FRAMING_TRANSLATION:
2006 /* Check that we have an LLC and SNAP sequence */
2007 llc = (struct llc *)((u_int8_t *)header + trim);
2008 if (llc->llc_dsap == LLC_SNAP_LSAP &&
2009 llc->llc_ssap == LLC_SNAP_LSAP &&
2010 llc->llc_control == LLC_UI &&
2011 llc->llc_un.type_snap.org_code[0] == 0 &&
2012 llc->llc_un.type_snap.org_code[1] == 0 &&
2013 llc->llc_un.type_snap.org_code[2] == 0) {
2015 * This is not magic. RFC1042 header is 8
2016 * bytes, with the last two bytes being the
2017 * ether type. So all we need is another
2018 * ETHER_ADDR_LEN bytes to write the
2021 trim -= ETHER_ADDR_LEN;
2022 eh = (struct ether_header *)((u_int8_t *)header + trim);
2025 * Copy carefully to avoid mashing the MAC
2026 * addresses. The address layout in the .11 header
2027 * does make sense, honest, but it is a pain.
2029 * NODS da sa no risk
2030 * FROMDS da ta sa sa then da
2031 * DSTODS ra ta da sa sa then da
2032 * TODS ra sa da da then sa
2036 bcopy(sa, eh->ether_shost, ETHER_ADDR_LEN);
2037 bcopy(da, eh->ether_dhost, ETHER_ADDR_LEN);
2040 bcopy(da, eh->ether_dhost, ETHER_ADDR_LEN);
2041 bcopy(sa, eh->ether_shost, ETHER_ADDR_LEN);
2046 /* Assume RAY_FRAMING_ENCAPSULATION */
2048 "got encapsulated packet but in translation mode");
2054 RAY_RECERR(sc, "unknown framing type %d", sc->sc_c.np_framing);
2059 RAY_MBUF_DUMP(sc, RAY_DBG_RX, m0, "(2) packet after framing");
2062 * Finally, do a bit of house keeping before sending the packet
2066 RAY_MBUF_DUMP(sc, RAY_DBG_RX, m0, "(3) packet after trimming");
2068 ray_rx_update_cache(sc, header->i_addr2, siglev, antenna);
2069 (*ifp->if_input)(ifp, m0);
2073 * Deal with MGT packet types
2076 ray_rx_mgt(struct ray_softc *sc, struct mbuf *m0)
2078 struct ifnet *ifp = &sc->arpcom.ac_if;
2079 struct ieee80211_frame *header = mtod(m0, struct ieee80211_frame *);
2081 RAY_DPRINTF(sc, RAY_DBG_SUBR | RAY_DBG_MGT, "");
2083 if ((header->i_fc[1] & IEEE80211_FC1_DIR_MASK) !=
2084 IEEE80211_FC1_DIR_NODS) {
2085 RAY_RECERR(sc, "MGT TODS/FROMDS wrong fc1 0x%x",
2086 header->i_fc[1] & IEEE80211_FC1_DIR_MASK);
2093 * Check the the mgt packet subtype, some packets should be
2094 * dropped depending on the mode the station is in. See pg
2097 * P - proccess, J - Junk, E - ECF deals with, I - Illegal
2099 * AHDOC procces or junk
2100 * INFRA STA process or junk
2101 * INFRA AP process or jumk
2103 * +PPP IEEE80211_FC0_SUBTYPE_BEACON
2104 * +EEE IEEE80211_FC0_SUBTYPE_PROBE_REQ
2105 * +EEE IEEE80211_FC0_SUBTYPE_PROBE_RESP
2106 * PPP IEEE80211_FC0_SUBTYPE_AUTH
2107 * PPP IEEE80211_FC0_SUBTYPE_DEAUTH
2108 * JJP IEEE80211_FC0_SUBTYPE_ASSOC_REQ
2109 * JPJ IEEE80211_FC0_SUBTYPE_ASSOC_RESP
2110 * JPP IEEE80211_FC0_SUBTYPE_DISASSOC
2111 * JJP IEEE80211_FC0_SUBTYPE_REASSOC_REQ
2112 * JPJ IEEE80211_FC0_SUBTYPE_REASSOC_RESP
2113 * +EEE IEEE80211_FC0_SUBTYPE_ATIM
2115 RAY_MBUF_DUMP(sc, RAY_DBG_MGT, m0, "MGT packet");
2116 switch (header->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK) {
2118 case IEEE80211_FC0_SUBTYPE_BEACON:
2119 RAY_DPRINTF(sc, RAY_DBG_MGT, "BEACON MGT packet");
2120 ray_rx_mgt_beacon(sc, m0);
2123 case IEEE80211_FC0_SUBTYPE_AUTH:
2124 RAY_DPRINTF(sc, RAY_DBG_MGT, "AUTH MGT packet");
2125 ray_rx_mgt_auth(sc, m0);
2128 case IEEE80211_FC0_SUBTYPE_DEAUTH:
2129 RAY_DPRINTF(sc, RAY_DBG_MGT, "DEAUTH MGT packet");
2130 /* XXX ray_rx_mgt_deauth(sc, m0); */
2133 case IEEE80211_FC0_SUBTYPE_ASSOC_REQ:
2134 case IEEE80211_FC0_SUBTYPE_REASSOC_REQ:
2135 RAY_DPRINTF(sc, RAY_DBG_MGT, "(RE)ASSOC_REQ MGT packet");
2136 if ((sc->sc_c.np_net_type == RAY_MIB_NET_TYPE_INFRA) &&
2137 (sc->sc_c.np_ap_status == RAY_MIB_AP_STATUS_AP))
2138 RAY_RECERR(sc, "can't be an AP yet"); /* XXX_ACTING_AP */
2141 case IEEE80211_FC0_SUBTYPE_ASSOC_RESP:
2142 case IEEE80211_FC0_SUBTYPE_REASSOC_RESP:
2143 RAY_DPRINTF(sc, RAY_DBG_MGT, "(RE)ASSOC_RESP MGT packet");
2144 if ((sc->sc_c.np_net_type == RAY_MIB_NET_TYPE_INFRA) &&
2145 (sc->sc_c.np_ap_status == RAY_MIB_AP_STATUS_TERMINAL))
2146 RAY_RECERR(sc, "can't be in INFRA yet"); /* XXX_INFRA */
2149 case IEEE80211_FC0_SUBTYPE_DISASSOC:
2150 RAY_DPRINTF(sc, RAY_DBG_MGT, "DISASSOC MGT packet");
2151 if (sc->sc_c.np_net_type == RAY_MIB_NET_TYPE_INFRA)
2152 RAY_RECERR(sc, "can't be in INFRA yet"); /* XXX_INFRA */
2155 case IEEE80211_FC0_SUBTYPE_PROBE_REQ:
2156 case IEEE80211_FC0_SUBTYPE_PROBE_RESP:
2157 case IEEE80211_FC0_SUBTYPE_ATIM:
2158 RAY_RECERR(sc, "unexpected MGT packet subtype 0x%0x",
2159 header->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK);
2164 RAY_RECERR(sc, "reserved MGT packet subtype 0x%x",
2165 header->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK);
2173 * Deal with BEACON management packet types
2174 * XXX furtle anything interesting out
2175 * XXX Note that there are rules governing what beacons to read
2176 * XXX see 8802 S7.2.3, S11.1.2.3
2177 * XXX is this actually useful?
2180 ray_rx_mgt_beacon(struct ray_softc *sc, struct mbuf *m0)
2182 struct ieee80211_frame *header = mtod(m0, struct ieee80211_frame *);
2183 ieee80211_mgt_beacon_t beacon = (u_int8_t *)(header+1);
2184 struct ieee80211_information elements;
2186 u_int64_t *timestamp;
2188 RAY_DPRINTF(sc, RAY_DBG_SUBR | RAY_DBG_MGT, "");
2190 timestamp = (u_int64_t *)beacon;
2192 RAY_DPRINTF(sc, RAY_DBG_MGT, "timestamp\t0x%x", *timestamp);
2193 RAY_DPRINTF(sc, RAY_DBG_MGT, "interval\t\t0x%x", IEEE80211_BEACON_INTERVAL(beacon));
2194 RAY_DPRINTF(sc, RAY_DBG_MGT, "capability\t0x%x", IEEE80211_BEACON_CAPABILITY(beacon));
2196 ray_rx_mgt_info(sc, m0, &elements);
2201 ray_rx_mgt_info(struct ray_softc *sc, struct mbuf *m0, struct ieee80211_information *elements)
2203 struct ifnet *ifp = &sc->arpcom.ac_if;
2204 struct ieee80211_frame *header = mtod(m0, struct ieee80211_frame *);
2205 ieee80211_mgt_beacon_t beacon = (u_int8_t *)(header+1);
2206 ieee80211_mgt_beacon_t bp, be;
2209 RAY_DPRINTF(sc, RAY_DBG_SUBR | RAY_DBG_MGT, "");
2212 be = mtod(m0, u_int8_t *) + m0->m_len;
2216 RAY_DPRINTF(sc, RAY_DBG_MGT, "id 0x%02x length %d", *bp, len);
2220 case IEEE80211_ELEMID_SSID:
2221 if (len > IEEE80211_NWID_LEN) {
2222 RAY_RECERR(sc, "bad SSD length: %d from %6D",
2223 len, header->i_addr2, ":");
2225 strncpy(elements->ssid, bp + 2, len);
2226 elements->ssid[len] = 0;
2227 RAY_DPRINTF(sc, RAY_DBG_MGT,
2228 "beacon ssid %s", elements->ssid);
2231 case IEEE80211_ELEMID_RATES:
2232 RAY_DPRINTF(sc, RAY_DBG_MGT, "rates");
2235 case IEEE80211_ELEMID_FHPARMS:
2236 elements->fh.dwell = bp[2] + (bp[3] << 8);
2237 elements->fh.set = bp[4];
2238 elements->fh.pattern = bp[5];
2239 elements->fh.index = bp[6];
2240 RAY_DPRINTF(sc, RAY_DBG_MGT,
2241 "fhparams dwell\t0x%04x", elements->fh.dwell);
2242 RAY_DPRINTF(sc, RAY_DBG_MGT,
2243 "fhparams set\t0x%02x", elements->fh.set);
2244 RAY_DPRINTF(sc, RAY_DBG_MGT,
2245 "fhparams pattern\t0x%02x", elements->fh.pattern);
2246 RAY_DPRINTF(sc, RAY_DBG_MGT,
2247 "fhparams index\t0x%02x", elements->fh.index);
2250 case IEEE80211_ELEMID_DSPARMS:
2251 RAY_RECERR(sc, "got direct sequence params!");
2254 case IEEE80211_ELEMID_CFPARMS:
2255 RAY_DPRINTF(sc, RAY_DBG_MGT, "cfparams");
2258 case IEEE80211_ELEMID_TIM:
2259 elements->tim.count = bp[2];
2260 elements->tim.period = bp[3];
2261 elements->tim.bitctl = bp[4];
2262 RAY_DPRINTF(sc, RAY_DBG_MGT,
2263 "tim count\t0x%02x", elements->tim.count);
2264 RAY_DPRINTF(sc, RAY_DBG_MGT,
2265 "tim period\t0x%02x", elements->tim.period);
2266 RAY_DPRINTF(sc, RAY_DBG_MGT,
2267 "tim bitctl\t0x%02x", elements->tim.bitctl);
2268 #if RAY_DEBUG & RAY_DBG_MGT
2271 for (i = 5; i < len + 1; i++)
2272 RAY_DPRINTF(sc, RAY_DBG_MGT,
2273 "tim pvt[%03d]\t0x%02x", i-5, bp[i]);
2278 case IEEE80211_ELEMID_IBSSPARMS:
2279 elements->ibss.atim = bp[2] + (bp[3] << 8);
2280 RAY_DPRINTF(sc, RAY_DBG_MGT,
2281 "ibssparams atim\t0x%02x", elements->ibss.atim);
2284 case IEEE80211_ELEMID_CHALLENGE:
2285 RAY_DPRINTF(sc, RAY_DBG_MGT, "challenge");
2289 RAY_RECERR(sc, "reserved MGT element id 0x%x", *bp);
2290 ifp->if_ierrors++;break;
2297 * Deal with AUTH management packet types
2300 ray_rx_mgt_auth(struct ray_softc *sc, struct mbuf *m0)
2302 struct ieee80211_frame *header = mtod(m0, struct ieee80211_frame *);
2303 ieee80211_mgt_auth_t auth = (u_int8_t *)(header+1);
2305 RAY_DPRINTF(sc, RAY_DBG_SUBR | RAY_DBG_AUTH, "");
2307 switch (IEEE80211_AUTH_ALGORITHM(auth)) {
2309 case IEEE80211_AUTH_ALG_OPEN:
2310 RAY_DPRINTF(sc, RAY_DBG_AUTH,
2311 "open system authentication sequence number %d",
2312 IEEE80211_AUTH_TRANSACTION(auth));
2313 if (IEEE80211_AUTH_TRANSACTION(auth) ==
2314 IEEE80211_AUTH_OPEN_REQUEST) {
2316 /* XXX_AUTH use ray_init_auth_send */
2318 } else if (IEEE80211_AUTH_TRANSACTION(auth) ==
2319 IEEE80211_AUTH_OPEN_RESPONSE)
2320 ray_init_auth_done(sc, IEEE80211_AUTH_STATUS(auth));
2323 case IEEE80211_AUTH_ALG_SHARED:
2325 "shared key authentication sequence number %d",
2326 IEEE80211_AUTH_TRANSACTION(auth));
2331 "reserved authentication subtype 0x%04hx",
2332 IEEE80211_AUTH_ALGORITHM(auth));
2338 * Deal with CTL packet types
2341 ray_rx_ctl(struct ray_softc *sc, struct mbuf *m0)
2343 struct ifnet *ifp = &sc->arpcom.ac_if;
2344 struct ieee80211_frame *header = mtod(m0, struct ieee80211_frame *);
2346 RAY_DPRINTF(sc, RAY_DBG_SUBR | RAY_DBG_CTL, "");
2348 if ((header->i_fc[1] & IEEE80211_FC1_DIR_MASK) !=
2349 IEEE80211_FC1_DIR_NODS) {
2350 RAY_RECERR(sc, "CTL TODS/FROMDS wrong fc1 0x%x",
2351 header->i_fc[1] & IEEE80211_FC1_DIR_MASK);
2358 * Check the the ctl packet subtype, some packets should be
2359 * dropped depending on the mode the station is in. The ECF
2360 * should deal with everything but the power save poll to an
2361 * AP. See pg 52(60) of docs.
2363 RAY_MBUF_DUMP(sc, RAY_DBG_CTL, m0, "CTL packet");
2364 switch (header->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK) {
2366 case IEEE80211_FC0_SUBTYPE_PS_POLL:
2367 RAY_DPRINTF(sc, RAY_DBG_CTL, "PS_POLL CTL packet");
2368 if ((sc->sc_d.np_net_type == RAY_MIB_NET_TYPE_INFRA) &&
2369 (sc->sc_c.np_ap_status == RAY_MIB_AP_STATUS_AP))
2370 RAY_RECERR(sc, "can't be an AP yet"); /* XXX_ACTING_AP */
2373 case IEEE80211_FC0_SUBTYPE_RTS:
2374 case IEEE80211_FC0_SUBTYPE_CTS:
2375 case IEEE80211_FC0_SUBTYPE_ACK:
2376 case IEEE80211_FC0_SUBTYPE_CF_END:
2377 case IEEE80211_FC0_SUBTYPE_CF_END_ACK:
2378 RAY_RECERR(sc, "unexpected CTL packet subtype 0x%0x",
2379 header->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK);
2384 RAY_RECERR(sc, "reserved CTL packet subtype 0x%x",
2385 header->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK);
2393 * Update rx level and antenna cache
2396 ray_rx_update_cache(struct ray_softc *sc, u_int8_t *src, u_int8_t siglev, u_int8_t antenna)
2398 struct timeval mint;
2399 struct ray_siglev *sl;
2402 RAY_DPRINTF(sc, RAY_DBG_SUBR, "");
2404 /* Try to find host */
2405 for (i = 0; i < RAY_NSIGLEVRECS; i++) {
2406 sl = &sc->sc_siglevs[i];
2407 if (bcmp(sl->rsl_host, src, ETHER_ADDR_LEN) == 0)
2410 /* Not found, find oldest slot */
2412 mint.tv_sec = LONG_MAX;
2414 for (i = 0; i < RAY_NSIGLEVRECS; i++) {
2415 sl = &sc->sc_siglevs[i];
2416 if (timevalcmp(&sl->rsl_time, &mint, <)) {
2418 mint = sl->rsl_time;
2421 sl = &sc->sc_siglevs[mini];
2422 bzero(sl->rsl_siglevs, RAY_NSIGLEV);
2423 bzero(sl->rsl_antennas, RAY_NANTENNA);
2424 bcopy(src, sl->rsl_host, ETHER_ADDR_LEN);
2427 microtime(&sl->rsl_time);
2428 bcopy(sl->rsl_siglevs, &sl->rsl_siglevs[1], RAY_NSIGLEV-1);
2429 sl->rsl_siglevs[0] = siglev;
2430 if (sc->sc_version != RAY_ECFS_BUILD_4) {
2431 bcopy(sl->rsl_antennas, &sl->rsl_antennas[1], RAY_NANTENNA-1);
2432 sl->rsl_antennas[0] = antenna;
2437 * Interrupt handling
2441 * Process an interrupt
2446 struct ray_softc *sc = (struct ray_softc *)xsc;
2447 struct ifnet *ifp = &sc->arpcom.ac_if;
2449 u_int8_t cmd, status;
2452 RAY_DPRINTF(sc, RAY_DBG_SUBR, "");
2455 if ((sc == NULL) || (sc->sc_gone))
2459 * Check that the interrupt was for us, if so get the rcs/ccs
2460 * and vector on the command contained within it.
2462 if (RAY_HCS_INTR(sc)) {
2463 ccsi = SRAM_READ_1(sc, RAY_SCB_RCSI);
2464 ccs = RAY_CCS_ADDRESS(ccsi);
2465 cmd = SRAM_READ_FIELD_1(sc, ccs, ray_cmd, c_cmd);
2466 status = SRAM_READ_FIELD_1(sc, ccs, ray_cmd, c_status);
2467 if (ccsi <= RAY_CCS_LAST)
2468 ray_intr_ccs(sc, cmd, status, ccs);
2469 else if (ccsi <= RAY_RCS_LAST)
2470 ray_intr_rcs(sc, cmd, ccs);
2472 RAY_RECERR(sc, "bad ccs index 0x%x", ccsi);
2473 RAY_HCS_CLEAR_INTR(sc);
2476 /* Send any packets lying around and update error counters */
2477 if ((ifp->if_flags & IFF_OACTIVE) == 0 && !ifq_is_empty(&ifp->if_snd))
2479 if ((++sc->sc_checkcounters % 32) == 0)
2480 ray_intr_updt_errcntrs(sc);
2484 * Read the error counters.
2487 ray_intr_updt_errcntrs(struct ray_softc *sc)
2491 RAY_DPRINTF(sc, RAY_DBG_SUBR, "");
2495 * The card implements the following protocol to keep the
2496 * values from being changed while read: It checks the `own'
2497 * bit and if zero writes the current internal counter value,
2498 * it then sets the `own' bit to 1. If the `own' bit was 1 it
2499 * incremenets its internal counter. The user thus reads the
2500 * counter if the `own' bit is one and then sets the own bit
2503 csc = RAY_STATUS_BASE;
2504 if (SRAM_READ_FIELD_1(sc, csc, ray_csc, csc_mrxo_own)) {
2505 sc->sc_rxoverflow +=
2506 SRAM_READ_FIELD_2(sc, csc, ray_csc, csc_mrx_overflow);
2507 SRAM_WRITE_FIELD_1(sc, csc, ray_csc, csc_mrxo_own, 0);
2509 if (SRAM_READ_FIELD_1(sc, csc, ray_csc, csc_mrxc_own)) {
2511 SRAM_READ_FIELD_2(sc, csc, ray_csc, csc_mrx_overflow);
2512 SRAM_WRITE_FIELD_1(sc, csc, ray_csc, csc_mrxc_own, 0);
2514 if (SRAM_READ_FIELD_1(sc, csc, ray_csc, csc_rxhc_own)) {
2516 SRAM_READ_FIELD_2(sc, csc, ray_csc, csc_rx_hcksum);
2517 SRAM_WRITE_FIELD_1(sc, csc, ray_csc, csc_rxhc_own, 0);
2519 sc->sc_rxnoise = SRAM_READ_FIELD_1(sc, csc, ray_csc, csc_rx_noise);
2523 * Process CCS command completion
2526 ray_intr_ccs(struct ray_softc *sc, u_int8_t cmd, u_int8_t status, size_t ccs)
2528 RAY_DPRINTF(sc, RAY_DBG_SUBR, "");
2532 case RAY_CMD_DOWNLOAD_PARAMS:
2533 RAY_DPRINTF(sc, RAY_DBG_COM, "START_PARAMS");
2534 ray_init_download_done(sc, status, ccs);
2537 case RAY_CMD_UPDATE_PARAMS:
2538 RAY_DPRINTF(sc, RAY_DBG_COM, "UPDATE_PARAMS");
2539 ray_upparams_done(sc, status, ccs);
2542 case RAY_CMD_REPORT_PARAMS:
2543 RAY_DPRINTF(sc, RAY_DBG_COM, "REPORT_PARAMS");
2544 ray_repparams_done(sc, status, ccs);
2547 case RAY_CMD_UPDATE_MCAST:
2548 RAY_DPRINTF(sc, RAY_DBG_COM, "UPDATE_MCAST");
2549 ray_mcast_done(sc, status, ccs);
2552 case RAY_CMD_START_NET:
2553 case RAY_CMD_JOIN_NET:
2554 RAY_DPRINTF(sc, RAY_DBG_COM, "START|JOIN_NET");
2555 ray_init_sj_done(sc, status, ccs);
2558 case RAY_CMD_TX_REQ:
2559 RAY_DPRINTF(sc, RAY_DBG_COM, "TX_REQ");
2560 ray_tx_done(sc, status, ccs);
2563 case RAY_CMD_START_ASSOC:
2564 RAY_DPRINTF(sc, RAY_DBG_COM, "START_ASSOC");
2565 ray_init_assoc_done(sc, status, ccs);
2568 case RAY_CMD_UPDATE_APM:
2569 RAY_RECERR(sc, "unexpected UPDATE_APM");
2572 case RAY_CMD_TEST_MEM:
2573 RAY_RECERR(sc, "unexpected TEST_MEM");
2576 case RAY_CMD_SHUTDOWN:
2577 RAY_RECERR(sc, "unexpected SHUTDOWN");
2580 case RAY_CMD_DUMP_MEM:
2581 RAY_RECERR(sc, "unexpected DUMP_MEM");
2584 case RAY_CMD_START_TIMER:
2585 RAY_RECERR(sc, "unexpected START_TIMER");
2589 RAY_RECERR(sc, "unknown command 0x%x", cmd);
2595 * Process ECF command request
2598 ray_intr_rcs(struct ray_softc *sc, u_int8_t cmd, size_t rcs)
2600 RAY_DPRINTF(sc, RAY_DBG_SUBR, "");
2604 case RAY_ECMD_RX_DONE:
2605 RAY_DPRINTF(sc, RAY_DBG_RX, "RX_DONE");
2609 case RAY_ECMD_REJOIN_DONE:
2610 RAY_DPRINTF(sc, RAY_DBG_RX, "REJOIN_DONE");
2611 sc->sc_c.np_havenet = 1; /* XXX Should not be here but in function */
2614 case RAY_ECMD_ROAM_START:
2615 RAY_DPRINTF(sc, RAY_DBG_RX, "ROAM_START");
2616 sc->sc_c.np_havenet = 0; /* XXX Should not be here but in function */
2619 case RAY_ECMD_JAPAN_CALL_SIGNAL:
2620 RAY_RECERR(sc, "unexpected JAPAN_CALL_SIGNAL");
2624 RAY_RECERR(sc, "unknown command 0x%x", cmd);
2628 RAY_CCS_FREE(sc, rcs);
2632 * User land entry to multicast list changes
2635 ray_mcast_user(struct ray_softc *sc)
2637 struct ray_comq_entry *com[2];
2640 RAY_DPRINTF(sc, RAY_DBG_SUBR, "");
2643 * Do all checking in the runq to preserve ordering.
2645 * We run promisc to pick up changes to the ALL_MULTI
2649 com[ncom++] = RAY_COM_MALLOC(ray_mcast, 0);
2650 com[ncom++] = RAY_COM_MALLOC(ray_promisc, 0);
2652 RAY_COM_RUNQ(sc, com, ncom, "raymcast", error);
2654 /* XXX no real error processing from anything yet! */
2656 RAY_COM_FREE(com, ncom);
2662 * Runq entry to setting the multicast filter list
2664 * MUST always be followed by a call to ray_promisc to pick up changes
2668 ray_mcast(struct ray_softc *sc, struct ray_comq_entry *com)
2670 struct ifnet *ifp = &sc->arpcom.ac_if;
2671 struct ifmultiaddr *ifma;
2675 RAY_DPRINTF(sc, RAY_DBG_SUBR, "");
2679 * If card is not running we don't need to update this.
2681 if (!(ifp->if_flags & IFF_RUNNING)) {
2682 RAY_DPRINTF(sc, RAY_DBG_IOCTL, "not running");
2683 ray_com_runq_done(sc);
2688 * The multicast list is only 16 items long so use promiscuous
2689 * mode and don't bother updating the multicast list.
2691 for (ifma = ifp->if_multiaddrs.lh_first; ifma != NULL;
2692 ifma = ifma->ifma_link.le_next)
2695 ray_com_runq_done(sc);
2697 } else if (count > 16) {
2698 ifp->if_flags |= IFF_ALLMULTI;
2699 ray_com_runq_done(sc);
2701 } else if (ifp->if_flags & IFF_ALLMULTI)
2702 ifp->if_flags &= ~IFF_ALLMULTI;
2707 ray_ccs_fill(sc, com->c_ccs, RAY_CMD_UPDATE_MCAST);
2708 SRAM_WRITE_FIELD_1(sc, com->c_ccs,
2709 ray_cmd_update_mcast, c_nmcast, count);
2710 bufp = RAY_HOST_TO_ECF_BASE;
2711 for (ifma = ifp->if_multiaddrs.lh_first; ifma != NULL;
2712 ifma = ifma->ifma_link.le_next) {
2716 LLADDR((struct sockaddr_dl *)ifma->ifma_addr),
2719 bufp += ETHER_ADDR_LEN;
2722 ray_com_ecf(sc, com);
2726 * Complete the multicast filter list update
2729 ray_mcast_done(struct ray_softc *sc, u_int8_t status, size_t ccs)
2731 RAY_DPRINTF(sc, RAY_DBG_SUBR | RAY_DBG_STARTJOIN, "");
2732 RAY_COM_CHECK(sc, ccs);
2734 RAY_CCSERR(sc, status, if_oerrors); /* XXX error counter */
2736 ray_com_ecf_done(sc);
2740 * Runq entry to set/reset promiscuous mode
2743 ray_promisc(struct ray_softc *sc, struct ray_comq_entry *com)
2745 struct ifnet *ifp = &sc->arpcom.ac_if;
2747 RAY_DPRINTF(sc, RAY_DBG_SUBR, "");
2751 * If card not running or we already have the right flags
2752 * we don't need to update this
2754 sc->sc_d.np_promisc = !!(ifp->if_flags & (IFF_PROMISC | IFF_ALLMULTI));
2755 if (!(ifp->if_flags & IFF_RUNNING) ||
2756 (sc->sc_c.np_promisc == sc->sc_d.np_promisc)) {
2757 ray_com_runq_done(sc);
2764 ray_ccs_fill(sc, com->c_ccs, RAY_CMD_UPDATE_PARAMS);
2765 SRAM_WRITE_FIELD_1(sc, com->c_ccs,
2766 ray_cmd_update, c_paramid, RAY_MIB_PROMISC);
2767 SRAM_WRITE_FIELD_1(sc, com->c_ccs, ray_cmd_update, c_nparam, 1);
2768 SRAM_WRITE_1(sc, RAY_HOST_TO_ECF_BASE, sc->sc_d.np_promisc);
2770 ray_com_ecf(sc, com);
2774 * User land entry to parameter reporting
2776 * As we by pass the runq to report current parameters this function
2777 * only provides a snap shot of the driver's state.
2780 ray_repparams_user(struct ray_softc *sc, struct ray_param_req *pr)
2782 struct ray_comq_entry *com[1];
2785 RAY_DPRINTF(sc, RAY_DBG_SUBR, "");
2788 * Test for illegal values or immediate responses
2790 if (pr->r_paramid > RAY_MIB_MAX)
2792 if ((sc->sc_version == RAY_ECFS_BUILD_4) &&
2793 !(mib_info[pr->r_paramid][0] & RAY_V4))
2795 if ((sc->sc_version == RAY_ECFS_BUILD_5) &&
2796 !(mib_info[pr->r_paramid][0] & RAY_V5))
2798 if (pr->r_paramid > RAY_MIB_LASTUSER) {
2799 switch (pr->r_paramid) {
2801 case RAY_MIB_VERSION:
2802 if (sc->sc_version == RAY_ECFS_BUILD_4)
2803 *pr->r_data = RAY_V4;
2805 *pr->r_data = RAY_V5;
2807 case RAY_MIB_CUR_BSSID:
2808 bcopy(sc->sc_c.np_bss_id, pr->r_data, ETHER_ADDR_LEN);
2810 case RAY_MIB_CUR_INITED:
2811 *pr->r_data = sc->sc_c.np_inited;
2813 case RAY_MIB_CUR_DEF_TXRATE:
2814 *pr->r_data = sc->sc_c.np_def_txrate;
2816 case RAY_MIB_CUR_ENCRYPT:
2817 *pr->r_data = sc->sc_c.np_encrypt;
2819 case RAY_MIB_CUR_NET_TYPE:
2820 *pr->r_data = sc->sc_c.np_net_type;
2822 case RAY_MIB_CUR_SSID:
2823 bcopy(sc->sc_c.np_ssid, pr->r_data, IEEE80211_NWID_LEN);
2825 case RAY_MIB_CUR_PRIV_START:
2826 *pr->r_data = sc->sc_c.np_priv_start;
2828 case RAY_MIB_CUR_PRIV_JOIN:
2829 *pr->r_data = sc->sc_c.np_priv_join;
2831 case RAY_MIB_DES_BSSID:
2832 bcopy(sc->sc_d.np_bss_id, pr->r_data, ETHER_ADDR_LEN);
2834 case RAY_MIB_DES_INITED:
2835 *pr->r_data = sc->sc_d.np_inited;
2837 case RAY_MIB_DES_DEF_TXRATE:
2838 *pr->r_data = sc->sc_d.np_def_txrate;
2840 case RAY_MIB_DES_ENCRYPT:
2841 *pr->r_data = sc->sc_d.np_encrypt;
2843 case RAY_MIB_DES_NET_TYPE:
2844 *pr->r_data = sc->sc_d.np_net_type;
2846 case RAY_MIB_DES_SSID:
2847 bcopy(sc->sc_d.np_ssid, pr->r_data, IEEE80211_NWID_LEN);
2849 case RAY_MIB_DES_PRIV_START:
2850 *pr->r_data = sc->sc_d.np_priv_start;
2852 case RAY_MIB_DES_PRIV_JOIN:
2853 *pr->r_data = sc->sc_d.np_priv_join;
2855 case RAY_MIB_CUR_AP_STATUS:
2856 *pr->r_data = sc->sc_c.np_ap_status;
2858 case RAY_MIB_CUR_PROMISC:
2859 *pr->r_data = sc->sc_c.np_promisc;
2861 case RAY_MIB_DES_AP_STATUS:
2862 *pr->r_data = sc->sc_d.np_ap_status;
2864 case RAY_MIB_DES_PROMISC:
2865 *pr->r_data = sc->sc_d.np_promisc;
2867 case RAY_MIB_CUR_FRAMING:
2868 *pr->r_data = sc->sc_c.np_framing;
2870 case RAY_MIB_DES_FRAMING:
2871 *pr->r_data = sc->sc_d.np_framing;
2878 pr->r_failcause = 0;
2879 if (sc->sc_version == RAY_ECFS_BUILD_4)
2880 pr->r_len = mib_info[pr->r_paramid][RAY_MIB_INFO_SIZ4];
2881 else if (sc->sc_version == RAY_ECFS_BUILD_5)
2882 pr->r_len = mib_info[pr->r_paramid][RAY_MIB_INFO_SIZ5];
2886 pr->r_failcause = 0;
2888 com[ncom++] = RAY_COM_MALLOC(ray_repparams, RAY_COM_FWOK);
2889 com[ncom-1]->c_pr = pr;
2891 RAY_COM_RUNQ(sc, com, ncom, "rayrparm", error);
2893 /* XXX no real error processing from anything yet! */
2894 if (!com[0]->c_retval && pr->r_failcause)
2897 RAY_COM_FREE(com, ncom);
2903 * Runq entry to read the required parameter
2905 * The card and driver are happy for parameters to be read
2906 * whenever the card is plugged in
2909 ray_repparams(struct ray_softc *sc, struct ray_comq_entry *com)
2911 RAY_DPRINTF(sc, RAY_DBG_SUBR, "");
2917 ray_ccs_fill(sc, com->c_ccs, RAY_CMD_REPORT_PARAMS);
2918 SRAM_WRITE_FIELD_1(sc, com->c_ccs,
2919 ray_cmd_report, c_paramid, com->c_pr->r_paramid);
2920 SRAM_WRITE_FIELD_1(sc, com->c_ccs, ray_cmd_report, c_nparam, 1);
2922 ray_com_ecf(sc, com);
2926 * Complete the parameter reporting
2929 ray_repparams_done(struct ray_softc *sc, u_int8_t status, size_t ccs)
2931 struct ray_comq_entry *com;
2933 RAY_DPRINTF(sc, RAY_DBG_SUBR, "");
2935 RAY_COM_CHECK(sc, ccs);
2937 RAY_CCSERR(sc, status, if_oerrors); /* XXX error counter */
2939 com = TAILQ_FIRST(&sc->sc_comq);
2940 com->c_pr->r_failcause =
2941 SRAM_READ_FIELD_1(sc, ccs, ray_cmd_report, c_failcause);
2943 SRAM_READ_FIELD_1(sc, ccs, ray_cmd_report, c_len);
2944 SRAM_READ_REGION(sc, RAY_ECF_TO_HOST_BASE,
2945 com->c_pr->r_data, com->c_pr->r_len);
2947 ray_com_ecf_done(sc);
2951 * User land entry (and exit) to the error counters
2954 ray_repstats_user(struct ray_softc *sc, struct ray_stats_req *sr)
2956 RAY_DPRINTF(sc, RAY_DBG_SUBR, "");
2958 sr->rxoverflow = sc->sc_rxoverflow;
2959 sr->rxcksum = sc->sc_rxcksum;
2960 sr->rxhcksum = sc->sc_rxhcksum;
2961 sr->rxnoise = sc->sc_rxnoise;
2967 * User land entry to parameter update changes
2969 * As a parameter change can cause the network parameters to be
2970 * invalid we have to re-start/join.
2973 ray_upparams_user(struct ray_softc *sc, struct ray_param_req *pr)
2975 struct ray_comq_entry *com[4];
2976 int error, ncom, todo;
2977 #define RAY_UPP_SJ 0x1
2978 #define RAY_UPP_PARAMS 0x2
2980 RAY_DPRINTF(sc, RAY_DBG_SUBR, "");
2983 * Check that the parameter is available based on firmware version
2985 pr->r_failcause = 0;
2986 if (pr->r_paramid > RAY_MIB_LASTUSER)
2988 if ((sc->sc_version == RAY_ECFS_BUILD_4) &&
2989 !(mib_info[pr->r_paramid][0] & RAY_V4))
2991 if ((sc->sc_version == RAY_ECFS_BUILD_5) &&
2992 !(mib_info[pr->r_paramid][0] & RAY_V5))
2996 * Handle certain parameters specially
2999 switch (pr->r_paramid) {
3000 case RAY_MIB_NET_TYPE: /* Updated via START_NET JOIN_NET */
3001 sc->sc_d.np_net_type = *pr->r_data;
3005 case RAY_MIB_SSID: /* Updated via START_NET JOIN_NET */
3006 bcopy(pr->r_data, sc->sc_d.np_ssid, IEEE80211_NWID_LEN);
3010 case RAY_MIB_PRIVACY_MUST_START:/* Updated via START_NET */
3011 if (sc->sc_c.np_net_type != RAY_MIB_NET_TYPE_ADHOC)
3013 sc->sc_d.np_priv_start = *pr->r_data;
3017 case RAY_MIB_PRIVACY_CAN_JOIN: /* Updated via START_NET JOIN_NET */
3018 sc->sc_d.np_priv_join = *pr->r_data;
3022 case RAY_MIB_BASIC_RATE_SET:
3023 sc->sc_d.np_def_txrate = *pr->r_data;
3024 todo |= RAY_UPP_PARAMS;
3027 case RAY_MIB_AP_STATUS: /* Unsupported */
3028 case RAY_MIB_MAC_ADDR: /* XXX Need interface up but could be done */
3029 case RAY_MIB_PROMISC: /* BPF */
3034 todo |= RAY_UPP_PARAMS;
3040 * Generate the runq entries as needed
3043 if (todo & RAY_UPP_PARAMS) {
3044 com[ncom++] = RAY_COM_MALLOC(ray_upparams, 0);
3045 com[ncom-1]->c_pr = pr;
3047 if (todo & RAY_UPP_SJ) {
3048 com[ncom++] = RAY_COM_MALLOC(ray_init_sj, 0);
3049 com[ncom++] = RAY_COM_MALLOC(ray_init_auth, 0);
3050 com[ncom++] = RAY_COM_MALLOC(ray_init_assoc, 0);
3053 RAY_COM_RUNQ(sc, com, ncom, "rayuparam", error);
3055 /* XXX no real error processing from anything yet! */
3056 if (!com[0]->c_retval && pr->r_failcause)
3059 RAY_COM_FREE(com, ncom);
3065 * Runq entry to update a parameter
3067 * The card and driver are happy for parameters to be updated
3068 * whenever the card is plugged in
3070 * XXX the above is a little bit of a lie until _download is sorted out and we
3071 * XXX keep local copies of things
3074 ray_upparams(struct ray_softc *sc, struct ray_comq_entry *com)
3076 RAY_DPRINTF(sc, RAY_DBG_SUBR, "");
3079 ray_ccs_fill(sc, com->c_ccs, RAY_CMD_UPDATE_PARAMS);
3081 SRAM_WRITE_FIELD_1(sc, com->c_ccs,
3082 ray_cmd_update, c_paramid, com->c_pr->r_paramid);
3083 SRAM_WRITE_FIELD_1(sc, com->c_ccs, ray_cmd_update, c_nparam, 1);
3084 SRAM_WRITE_REGION(sc, RAY_HOST_TO_ECF_BASE,
3085 com->c_pr->r_data, com->c_pr->r_len);
3087 ray_com_ecf(sc, com);
3091 * Complete the parameter update, note that promisc finishes up here too
3094 ray_upparams_done(struct ray_softc *sc, u_int8_t status, size_t ccs)
3096 struct ray_comq_entry *com;
3098 RAY_DPRINTF(sc, RAY_DBG_SUBR, "");
3100 RAY_COM_CHECK(sc, ccs);
3102 RAY_CCSERR(sc, status, if_oerrors); /* XXX error counter */
3104 com = TAILQ_FIRST(&sc->sc_comq);
3106 switch (SRAM_READ_FIELD_1(sc, ccs, ray_cmd_update, c_paramid)) {
3108 case RAY_MIB_PROMISC:
3109 sc->sc_c.np_promisc = SRAM_READ_1(sc, RAY_HOST_TO_ECF_BASE);
3110 RAY_DPRINTF(sc, RAY_DBG_IOCTL,
3111 "promisc value %d", sc->sc_c.np_promisc);
3115 com->c_pr->r_failcause =
3116 SRAM_READ_FIELD_1(sc, ccs, ray_cmd_update, c_failcause);
3121 ray_com_ecf_done(sc);
3125 * Command queuing and execution
3129 * Set up a comq entry struct
3131 static struct ray_comq_entry *
3132 ray_com_init(struct ray_comq_entry *com, ray_comqfn_t function, int flags, char *mesg)
3134 com->c_function = function;
3135 com->c_flags = flags;
3138 com->c_wakeup = NULL;
3146 * Malloc and set up a comq entry struct
3148 static struct ray_comq_entry *
3149 ray_com_malloc(ray_comqfn_t function, int flags, char *mesg)
3151 struct ray_comq_entry *com;
3153 MALLOC(com, struct ray_comq_entry *,
3154 sizeof(struct ray_comq_entry), M_RAYCOM, M_WAITOK);
3156 return (ray_com_init(com, function, flags, mesg));
3160 * Add an array of commands to the runq, get some ccs's for them and
3161 * then run, waiting on the last command.
3163 * We add the commands to the queue first to preserve ioctl ordering.
3165 * On recoverable errors, this routine removes the entries from the
3166 * runq. A caller can requeue the commands (and still preserve its own
3167 * processes ioctl ordering) but doesn't have to. When the card is
3168 * detached we get out quickly to prevent panics and don't bother
3172 ray_com_runq_add(struct ray_softc *sc, struct ray_comq_entry *com[], int ncom, char *wmesg)
3176 RAY_DPRINTF(sc, RAY_DBG_SUBR | RAY_DBG_COM, "");
3180 * Add the commands to the runq but don't let it run until
3181 * the ccs's are allocated successfully
3183 com[0]->c_flags |= RAY_COM_FWAIT;
3184 for (i = 0; i < ncom; i++) {
3185 com[i]->c_wakeup = com[ncom-1];
3186 RAY_DPRINTF(sc, RAY_DBG_COM, "adding %p", com[i]);
3187 RAY_DCOM(sc, RAY_DBG_DCOM, com[i], "adding");
3188 TAILQ_INSERT_TAIL(&sc->sc_comq, com[i], c_chain);
3190 com[ncom-1]->c_flags |= RAY_COM_FWOK;
3193 * Allocate ccs's for each command.
3195 for (i = 0; i < ncom; i++) {
3196 error = ray_ccs_alloc(sc, &com[i]->c_ccs, wmesg);
3204 * Allow the queue to run and sleep if needed.
3206 * Iff the FDETACHED flag is set in the com entry we waited on
3207 * the driver is in a zombie state! The softc structure has been
3208 * freed by the generic bus detach methods - eek. We tread very
3211 com[0]->c_flags &= ~RAY_COM_FWAIT;
3213 if (TAILQ_FIRST(&sc->sc_comq) != NULL) {
3214 RAY_DPRINTF(sc, RAY_DBG_COM, "sleeping");
3215 error = tsleep(com[ncom-1], PCATCH, wmesg, 0);
3216 if (com[ncom-1]->c_flags & RAY_COM_FDETACHED)
3218 RAY_DPRINTF(sc, RAY_DBG_COM,
3219 "awakened, tsleep returned 0x%x", error);
3225 * Only clean the queue on real errors - we don't care about it
3226 * when we detach as the queue entries are freed by the callers.
3228 if (error && (error != ENXIO))
3229 for (i = 0; i < ncom; i++)
3230 if (!(com[i]->c_flags & RAY_COM_FCOMPLETED)) {
3231 RAY_DPRINTF(sc, RAY_DBG_COM, "removing %p",
3233 RAY_DCOM(sc, RAY_DBG_DCOM, com[i], "removing");
3234 TAILQ_REMOVE(&sc->sc_comq, com[i], c_chain);
3235 ray_ccs_free(sc, com[i]->c_ccs);
3236 com[i]->c_ccs = NULL;
3243 * Run the command at the head of the queue (if not already running)
3246 ray_com_runq(struct ray_softc *sc)
3248 struct ray_comq_entry *com;
3250 RAY_DPRINTF(sc, RAY_DBG_SUBR | RAY_DBG_COM, "");
3252 com = TAILQ_FIRST(&sc->sc_comq);
3253 if ((com == NULL) ||
3254 (com->c_flags & RAY_COM_FRUNNING) ||
3255 (com->c_flags & RAY_COM_FWAIT) ||
3256 (com->c_flags & RAY_COM_FDETACHED))
3259 com->c_flags |= RAY_COM_FRUNNING;
3260 RAY_DPRINTF(sc, RAY_DBG_COM, "running %p", com);
3261 RAY_DCOM(sc, RAY_DBG_DCOM, com, "running");
3262 com->c_function(sc, com);
3266 * Remove run command, free ccs and wakeup caller.
3268 * Minimal checks are done here as we ensure that the com and command
3269 * handler were matched up earlier. Must be called at splnet or higher
3270 * so that entries on the command queue are correctly removed.
3272 * Remove the com from the comq, and wakeup the caller if it requested
3273 * to be woken. This is used for ensuring a sequence of commands
3274 * completes. Finally, re-run the queue.
3277 ray_com_runq_done(struct ray_softc *sc)
3279 struct ray_comq_entry *com;
3281 RAY_DPRINTF(sc, RAY_DBG_SUBR | RAY_DBG_COM, "");
3283 com = TAILQ_FIRST(&sc->sc_comq); /* XXX shall we check this as below */
3284 RAY_DPRINTF(sc, RAY_DBG_COM, "removing %p", com);
3285 RAY_DCOM(sc, RAY_DBG_DCOM, com, "removing");
3286 TAILQ_REMOVE(&sc->sc_comq, com, c_chain);
3288 com->c_flags &= ~RAY_COM_FRUNNING;
3289 com->c_flags |= RAY_COM_FCOMPLETED;
3291 ray_ccs_free(sc, com->c_ccs);
3294 if (com->c_flags & RAY_COM_FWOK)
3295 wakeup(com->c_wakeup);
3299 /* XXX what about error on completion then? deal with when i fix
3300 * XXX the status checking
3302 * XXX all the runq_done calls from IFF_RUNNING checks in runq
3303 * XXX routines should return EIO but shouldn't abort the runq
3308 * Send a command to the ECF.
3311 ray_com_ecf(struct ray_softc *sc, struct ray_comq_entry *com)
3315 RAY_DPRINTF(sc, RAY_DBG_SUBR | RAY_DBG_COM, "");
3318 while (!RAY_ECF_READY(sc)) {
3319 DELAY(RAY_ECF_SPIN_DELAY);
3320 if (++i > RAY_ECF_SPIN_TRIES)
3321 RAY_PANIC(sc, "spun too long");
3324 RAY_RECERR(sc, "spun %d times", i);
3326 RAY_DPRINTF(sc, RAY_DBG_COM, "sending %p", com);
3327 RAY_DCOM(sc, RAY_DBG_DCOM, com, "sending");
3328 SRAM_WRITE_1(sc, RAY_SCB_CCSI, RAY_CCS_INDEX(com->c_ccs));
3329 RAY_ECF_START_CMD(sc);
3331 if (RAY_COM_NEEDS_TIMO(
3332 SRAM_READ_FIELD_1(sc, com->c_ccs, ray_cmd, c_cmd))) {
3333 RAY_DPRINTF(sc, RAY_DBG_COM, "adding timeout");
3334 callout_reset(&sc->com_timer, RAY_COM_TIMEOUT,
3335 ray_com_ecf_timo, sc);
3340 * Deal with commands that require a timeout to test completion.
3342 * This routine is coded to only expect one outstanding request for the
3343 * timed out requests at a time, but thats all that can be outstanding
3344 * per hardware limitations and all that we issue anyway.
3346 * We don't do any fancy testing of the command currently issued as we
3347 * know it must be a timeout based one...unless I've got this wrong!
3350 ray_com_ecf_timo(void *xsc)
3352 struct ray_softc *sc = (struct ray_softc *)xsc;
3353 struct ray_comq_entry *com;
3354 u_int8_t cmd, status;
3359 RAY_DPRINTF(sc, RAY_DBG_SUBR | RAY_DBG_COM, "");
3362 com = TAILQ_FIRST(&sc->sc_comq);
3364 cmd = SRAM_READ_FIELD_1(sc, com->c_ccs, ray_cmd, c_cmd);
3365 status = SRAM_READ_FIELD_1(sc, com->c_ccs, ray_cmd, c_status);
3368 case RAY_CCS_STATUS_COMPLETE:
3369 case RAY_CCS_STATUS_FREE: /* Buggy firmware */
3370 ray_intr_ccs(sc, cmd, status, com->c_ccs);
3373 case RAY_CCS_STATUS_BUSY:
3374 callout_reset(&sc->com_timer, RAY_COM_TIMEOUT,
3375 ray_com_ecf_timo, sc);
3378 default: /* Replicates NetBSD */
3379 if (sc->sc_ccsinuse[RAY_CCS_INDEX(com->c_ccs)] == 1) {
3380 /* give a chance for the interrupt to occur */
3381 sc->sc_ccsinuse[RAY_CCS_INDEX(com->c_ccs)] = 2;
3382 callout_reset(&sc->com_timer, RAY_COM_TIMEOUT,
3383 ray_com_ecf_timo, sc);
3385 ray_intr_ccs(sc, cmd, status, com->c_ccs);
3394 * Called when interrupt handler for the command has done all it
3395 * needs to. Will be called at splnet.
3398 ray_com_ecf_done(struct ray_softc *sc)
3400 RAY_DPRINTF(sc, RAY_DBG_SUBR | RAY_DBG_COM, "");
3402 callout_stop(&sc->com_timer);
3404 ray_com_runq_done(sc);
3407 #if RAY_DEBUG & RAY_DBG_COM
3409 * Process completed ECF commands that probably came from the command queue
3411 * This routine is called after vectoring the completed ECF command
3412 * to the appropriate _done routine. It helps check everything is okay.
3415 ray_com_ecf_check(struct ray_softc *sc, size_t ccs, char *mesg)
3417 struct ray_comq_entry *com;
3419 RAY_DPRINTF(sc, RAY_DBG_SUBR | RAY_DBG_COM, "%s", mesg);
3421 com = TAILQ_FIRST(&sc->sc_comq);
3424 RAY_PANIC(sc, "no command queue");
3425 if (com->c_ccs != ccs)
3426 RAY_PANIC(sc, "ccs's don't match");
3428 #endif /* RAY_DEBUG & RAY_DBG_COM */
3435 * Obtain a ccs for a commmand
3437 * Returns 0 and in `ccsp' the bus offset of the free ccs. Will block
3438 * awaiting free ccs if needed - if the sleep is interrupted
3439 * EINTR/ERESTART is returned, if the card is ejected we return ENXIO.
3442 ray_ccs_alloc(struct ray_softc *sc, size_t *ccsp, char *wmesg)
3448 RAY_DPRINTF(sc, RAY_DBG_SUBR | RAY_DBG_CCS, "");
3452 for (i = RAY_CCS_CMD_FIRST; i <= RAY_CCS_CMD_LAST; i++) {
3453 /* we probe here to make the card go */
3454 (void)SRAM_READ_FIELD_1(sc, RAY_CCS_ADDRESS(i), ray_cmd,
3456 if (!sc->sc_ccsinuse[i])
3459 if (i > RAY_CCS_CMD_LAST) {
3460 RAY_DPRINTF(sc, RAY_DBG_CCS, "sleeping");
3461 error = tsleep(ray_ccs_alloc, PCATCH, wmesg, 0);
3462 if ((sc == NULL) || (sc->sc_gone))
3464 RAY_DPRINTF(sc, RAY_DBG_CCS,
3465 "awakened, tsleep returned 0x%x", error);
3471 RAY_DPRINTF(sc, RAY_DBG_CCS, "allocated 0x%02x", i);
3472 sc->sc_ccsinuse[i] = 1;
3473 ccs = RAY_CCS_ADDRESS(i);
3480 * Fill the easy bits in of a pre-allocated CCS
3483 ray_ccs_fill(struct ray_softc *sc, size_t ccs, u_int cmd)
3485 RAY_DPRINTF(sc, RAY_DBG_SUBR | RAY_DBG_CCS, "");
3489 RAY_PANIC(sc, "ccs not allocated");
3491 SRAM_WRITE_FIELD_1(sc, ccs, ray_cmd, c_status, RAY_CCS_STATUS_BUSY);
3492 SRAM_WRITE_FIELD_1(sc, ccs, ray_cmd, c_cmd, cmd);
3493 SRAM_WRITE_FIELD_1(sc, ccs, ray_cmd, c_link, RAY_CCS_LINK_NULL);
3497 * Free up a ccs allocated via ray_ccs_alloc
3499 * Return the old status. This routine is only used for ccs allocated via
3500 * ray_ccs_alloc (not tx, rx or ECF command requests).
3503 ray_ccs_free(struct ray_softc *sc, size_t ccs)
3505 RAY_DPRINTF(sc, RAY_DBG_SUBR | RAY_DBG_CCS, "");
3508 #if 1 | (RAY_DEBUG & RAY_DBG_CCS)
3509 if (!sc->sc_ccsinuse[RAY_CCS_INDEX(ccs)])
3510 RAY_RECERR(sc, "freeing free ccs 0x%02x", RAY_CCS_INDEX(ccs));
3511 #endif /* RAY_DEBUG & RAY_DBG_CCS */
3513 RAY_CCS_FREE(sc, ccs);
3514 sc->sc_ccsinuse[RAY_CCS_INDEX(ccs)] = 0;
3515 RAY_DPRINTF(sc, RAY_DBG_CCS, "freed 0x%02x", RAY_CCS_INDEX(ccs));
3516 wakeup(ray_ccs_alloc);
3520 * Obtain a ccs and tx buffer to transmit with and fill them in.
3522 * Returns 0 and in `ccsp' the bus offset of the free ccs. Will not block
3523 * and if none available and will returns EAGAIN.
3525 * The caller must fill in the length later.
3526 * The caller must clear the ccs on errors.
3529 ray_ccs_tx(struct ray_softc *sc, size_t *ccsp, size_t *bufpp)
3535 RAY_DPRINTF(sc, RAY_DBG_SUBR | RAY_DBG_CCS, "");
3538 i = RAY_CCS_TX_FIRST;
3540 status = SRAM_READ_FIELD_1(sc, RAY_CCS_ADDRESS(i),
3542 if (status == RAY_CCS_STATUS_FREE)
3545 } while (i <= RAY_CCS_TX_LAST);
3546 if (i > RAY_CCS_TX_LAST) {
3549 RAY_DPRINTF(sc, RAY_DBG_CCS, "allocated 0x%02x", i);
3552 * Reserve and fill the ccs - must do the length later.
3554 * Even though build 4 and build 5 have different fields all these
3555 * are common apart from tx_rate. Neither the NetBSD driver or Linux
3556 * driver bother to overwrite this for build 4 cards.
3558 * The start of the buffer must be aligned to a 256 byte boundary
3559 * (least significant byte of address = 0x00).
3561 ccs = RAY_CCS_ADDRESS(i);
3562 bufp = RAY_TX_BASE + i * RAY_TX_BUF_SIZE;
3563 bufp += sc->sc_tibsize;
3564 SRAM_WRITE_FIELD_1(sc, ccs, ray_cmd_tx, c_status, RAY_CCS_STATUS_BUSY);
3565 SRAM_WRITE_FIELD_1(sc, ccs, ray_cmd_tx, c_cmd, RAY_CMD_TX_REQ);
3566 SRAM_WRITE_FIELD_1(sc, ccs, ray_cmd_tx, c_link, RAY_CCS_LINK_NULL);
3567 SRAM_WRITE_FIELD_2(sc, ccs, ray_cmd_tx, c_bufp, bufp);
3568 SRAM_WRITE_FIELD_1(sc,
3569 ccs, ray_cmd_tx, c_tx_rate, sc->sc_c.np_def_txrate);
3570 SRAM_WRITE_FIELD_1(sc, ccs, ray_cmd_tx, c_apm_mode, 0);
3571 bufp += sizeof(struct ray_tx_phy_header);
3579 * Routines to obtain resources for the card
3583 * Allocate the attribute memory on the card
3585 * The attribute memory space is abused by these devices as IO space. As such
3586 * the OS card services don't have a chance of knowing that they need to keep
3587 * the attribute space mapped. We have to do it manually.
3590 ray_res_alloc_am(struct ray_softc *sc)
3594 RAY_DPRINTF(sc, RAY_DBG_SUBR | RAY_DBG_CM, "");
3596 sc->am_rid = RAY_AM_RID;
3597 sc->am_res = bus_alloc_resource(sc->dev, SYS_RES_MEMORY,
3598 &sc->am_rid, 0UL, ~0UL, 0x1000, RF_ACTIVE);
3600 RAY_PRINTF(sc, "Cannot allocate attribute memory");
3603 error = CARD_SET_MEMORY_OFFSET(device_get_parent(sc->dev), sc->dev,
3604 sc->am_rid, 0, NULL);
3606 RAY_PRINTF(sc, "CARD_SET_MEMORY_OFFSET returned 0x%0x", error);
3609 error = CARD_SET_RES_FLAGS(device_get_parent(sc->dev), sc->dev,
3610 SYS_RES_MEMORY, sc->am_rid, PCCARD_A_MEM_ATTR);
3612 RAY_PRINTF(sc, "CARD_SET_RES_FLAGS returned 0x%0x", error);
3615 error = CARD_SET_RES_FLAGS(device_get_parent(sc->dev), sc->dev,
3616 SYS_RES_MEMORY, sc->am_rid, PCCARD_A_MEM_8BIT);
3618 RAY_PRINTF(sc, "CARD_SET_RES_FLAGS returned 0x%0x", error);
3621 sc->am_bsh = rman_get_bushandle(sc->am_res);
3622 sc->am_bst = rman_get_bustag(sc->am_res);
3624 #if RAY_DEBUG & (RAY_DBG_CM | RAY_DBG_BOOTPARAM)
3628 CARD_GET_RES_FLAGS(device_get_parent(sc->dev), sc->dev,
3629 SYS_RES_MEMORY, sc->am_rid, &flags);
3630 CARD_GET_MEMORY_OFFSET(device_get_parent(sc->dev), sc->dev,
3631 sc->am_rid, &offset);
3632 RAY_PRINTF(sc, "allocated attribute memory:\n"
3633 ". start 0x%0lx count 0x%0lx flags 0x%0lx offset 0x%0x",
3634 bus_get_resource_start(sc->dev, SYS_RES_MEMORY, sc->am_rid),
3635 bus_get_resource_count(sc->dev, SYS_RES_MEMORY, sc->am_rid),
3638 #endif /* RAY_DEBUG & (RAY_DBG_CM | RAY_DBG_BOOTPARAM) */
3644 * Allocate the common memory on the card
3646 * As this memory is described in the CIS, the OS card services should
3647 * have set the map up okay, but the card uses 8 bit RAM. This is not
3648 * described in the CIS.
3651 ray_res_alloc_cm(struct ray_softc *sc)
3653 u_long start, count, end;
3656 RAY_DPRINTF(sc, RAY_DBG_SUBR | RAY_DBG_CM, "");
3658 RAY_DPRINTF(sc,RAY_DBG_CM | RAY_DBG_BOOTPARAM,
3659 "cm start 0x%0lx count 0x%0lx",
3660 bus_get_resource_start(sc->dev, SYS_RES_MEMORY, RAY_CM_RID),
3661 bus_get_resource_count(sc->dev, SYS_RES_MEMORY, RAY_CM_RID));
3663 sc->cm_rid = RAY_CM_RID;
3664 start = bus_get_resource_start(sc->dev, SYS_RES_MEMORY, sc->cm_rid);
3665 count = bus_get_resource_count(sc->dev, SYS_RES_MEMORY, sc->cm_rid);
3666 end = start + count - 1;
3667 sc->cm_res = bus_alloc_resource(sc->dev, SYS_RES_MEMORY,
3668 &sc->cm_rid, start, end, count, RF_ACTIVE);
3670 RAY_PRINTF(sc, "Cannot allocate common memory");
3673 error = CARD_SET_MEMORY_OFFSET(device_get_parent(sc->dev), sc->dev,
3674 sc->cm_rid, 0, NULL);
3676 RAY_PRINTF(sc, "CARD_SET_MEMORY_OFFSET returned 0x%0x", error);
3679 error = CARD_SET_RES_FLAGS(device_get_parent(sc->dev), sc->dev,
3680 SYS_RES_MEMORY, sc->cm_rid, PCCARD_A_MEM_COM);
3682 RAY_PRINTF(sc, "CARD_SET_RES_FLAGS returned 0x%0x", error);
3685 error = CARD_SET_RES_FLAGS(device_get_parent(sc->dev), sc->dev,
3686 SYS_RES_MEMORY, sc->cm_rid, PCCARD_A_MEM_8BIT);
3688 RAY_PRINTF(sc, "CARD_SET_RES_FLAGS returned 0x%0x", error);
3691 sc->cm_bsh = rman_get_bushandle(sc->cm_res);
3692 sc->cm_bst = rman_get_bustag(sc->cm_res);
3694 #if RAY_DEBUG & (RAY_DBG_CM | RAY_DBG_BOOTPARAM)
3698 CARD_GET_RES_FLAGS(device_get_parent(sc->dev), sc->dev,
3699 SYS_RES_MEMORY, sc->cm_rid, &flags);
3700 CARD_GET_MEMORY_OFFSET(device_get_parent(sc->dev), sc->dev,
3701 sc->cm_rid, &offset);
3702 RAY_PRINTF(sc, "allocated common memory:\n"
3703 ". start 0x%0lx count 0x%0lx flags 0x%0lx offset 0x%0x",
3704 bus_get_resource_start(sc->dev, SYS_RES_MEMORY, sc->cm_rid),
3705 bus_get_resource_count(sc->dev, SYS_RES_MEMORY, sc->cm_rid),
3708 #endif /* RAY_DEBUG & (RAY_DBG_CM | RAY_DBG_BOOTPARAM) */
3714 * Get an irq and attach it to the bus
3717 ray_res_alloc_irq(struct ray_softc *sc)
3721 RAY_DPRINTF(sc, RAY_DBG_SUBR, "");
3723 RAY_DPRINTF(sc,RAY_DBG_CM | RAY_DBG_BOOTPARAM,
3724 "irq start 0x%0lx count 0x%0lx",
3725 bus_get_resource_start(sc->dev, SYS_RES_IRQ, 0),
3726 bus_get_resource_count(sc->dev, SYS_RES_IRQ, 0));
3729 sc->irq_res = bus_alloc_resource_any(sc->dev, SYS_RES_IRQ,
3730 &sc->irq_rid, RF_ACTIVE);
3732 RAY_PRINTF(sc, "Cannot allocate irq");
3735 error = bus_setup_intr(sc->dev, sc->irq_res, INTR_TYPE_NET,
3736 ray_intr, sc, &sc->irq_handle, NULL);
3738 RAY_PRINTF(sc, "Failed to setup irq");
3741 RAY_DPRINTF(sc, RAY_DBG_CM | RAY_DBG_BOOTPARAM, "allocated irq:\n"
3742 ". start 0x%0lx count 0x%0lx",
3743 bus_get_resource_start(sc->dev, SYS_RES_IRQ, sc->irq_rid),
3744 bus_get_resource_count(sc->dev, SYS_RES_IRQ, sc->irq_rid));
3750 * Release all of the card's resources
3753 ray_res_release(struct ray_softc *sc)
3755 if (sc->irq_res != 0) {
3756 bus_teardown_intr(sc->dev, sc->irq_res, sc->irq_handle);
3757 bus_release_resource(sc->dev, SYS_RES_IRQ,
3758 sc->irq_rid, sc->irq_res);
3761 if (sc->am_res != 0) {
3762 bus_release_resource(sc->dev, SYS_RES_MEMORY,
3763 sc->am_rid, sc->am_res);
3766 if (sc->cm_res != 0) {
3767 bus_release_resource(sc->dev, SYS_RES_MEMORY,
3768 sc->cm_rid, sc->cm_res);
3776 #if RAY_DEBUG & RAY_DBG_MBUF
3778 ray_dump_mbuf(struct ray_softc *sc, struct mbuf *m, char *s)
3784 RAY_PRINTF(sc, "%s", s);
3785 RAY_PRINTF(sc, "\nm0->data\t0x%p\nm_pkthdr.len\t%d\nm_len\t%d",
3786 mtod(m, u_int8_t *), m->m_pkthdr.len, m->m_len);
3789 for (; m; m = m->m_next) {
3790 d = mtod(m, u_int8_t *);
3793 for (; d < ed; i++, d++) {
3794 if ((i % 16) == 0) {
3795 printf(" %s\n\t", p);
3796 } else if ((i % 8) == 0)
3798 printf(" %02x", *d);
3799 p[i % 16] = ((*d >= 0x20) && (*d < 0x80)) ? *d : '.';
3805 #endif /* RAY_DEBUG & RAY_DBG_MBUF */