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.16 2004/09/15 00:33:40 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/if_arp.h>
264 #include <net/if_dl.h>
265 #include <net/if_llc.h>
267 #include <netproto/802_11/ieee80211.h>
268 #include <netproto/802_11/ieee80211_ioctl.h>
270 #include <machine/limits.h>
272 #include <bus/pccard/pccardvar.h>
275 #include "if_rayreg.h"
276 #include "if_raymib.h"
277 #include "if_raydbg.h"
278 #include "if_rayvar.h"
283 static int ray_attach (device_t);
284 static int ray_ccs_alloc (struct ray_softc *sc, size_t *ccsp, char *wmesg);
285 static void ray_ccs_fill (struct ray_softc *sc, size_t ccs, u_int cmd);
286 static void ray_ccs_free (struct ray_softc *sc, size_t ccs);
287 static int ray_ccs_tx (struct ray_softc *sc, size_t *ccsp, size_t *bufpp);
288 static void ray_com_ecf (struct ray_softc *sc, struct ray_comq_entry *com);
289 static void ray_com_ecf_done (struct ray_softc *sc);
290 static void ray_com_ecf_timo (void *xsc);
291 static struct ray_comq_entry *
292 ray_com_init (struct ray_comq_entry *com, ray_comqfn_t function, int flags, char *mesg);
293 static struct ray_comq_entry *
294 ray_com_malloc (ray_comqfn_t function, int flags, char *mesg);
295 static void ray_com_runq (struct ray_softc *sc);
296 static int ray_com_runq_add (struct ray_softc *sc, struct ray_comq_entry *com[], int ncom, char *wmesg);
297 static void ray_com_runq_done (struct ray_softc *sc);
298 static int ray_detach (device_t);
299 static void ray_init (void *xsc);
300 static int ray_init_user (struct ray_softc *sc);
301 static void ray_init_assoc (struct ray_softc *sc, struct ray_comq_entry *com);
302 static void ray_init_assoc_done (struct ray_softc *sc, u_int8_t status, size_t ccs);
303 static void ray_init_auth (struct ray_softc *sc, struct ray_comq_entry *com);
304 static int ray_init_auth_send (struct ray_softc *sc, u_int8_t *dst, int sequence);
305 static void ray_init_auth_done (struct ray_softc *sc, u_int8_t status);
306 static void ray_init_download (struct ray_softc *sc, struct ray_comq_entry *com);
307 static void ray_init_download_done (struct ray_softc *sc, u_int8_t status, size_t ccs);
308 static void ray_init_download_v4 (struct ray_softc *sc, struct ray_comq_entry *com);
309 static void ray_init_download_v5 (struct ray_softc *sc, struct ray_comq_entry *com);
310 static void ray_init_mcast (struct ray_softc *sc, struct ray_comq_entry *com);
311 static void ray_init_sj (struct ray_softc *sc, struct ray_comq_entry *com);
312 static void ray_init_sj_done (struct ray_softc *sc, u_int8_t status, size_t ccs);
313 static void ray_intr (void *xsc);
314 static void ray_intr_ccs (struct ray_softc *sc, u_int8_t cmd, u_int8_t status, size_t ccs);
315 static void ray_intr_rcs (struct ray_softc *sc, u_int8_t cmd, size_t ccs);
316 static void ray_intr_updt_errcntrs (struct ray_softc *sc);
317 static int ray_ioctl (struct ifnet *ifp, u_long command, caddr_t data, struct ucred *cr);
318 static void ray_mcast (struct ray_softc *sc, struct ray_comq_entry *com);
319 static void ray_mcast_done (struct ray_softc *sc, u_int8_t status, size_t ccs);
320 static int ray_mcast_user (struct ray_softc *sc);
321 static int ray_probe (device_t);
322 static void ray_promisc (struct ray_softc *sc, struct ray_comq_entry *com);
323 static void ray_repparams (struct ray_softc *sc, struct ray_comq_entry *com);
324 static void ray_repparams_done (struct ray_softc *sc, u_int8_t status, size_t ccs);
325 static int ray_repparams_user (struct ray_softc *sc, struct ray_param_req *pr);
326 static int ray_repstats_user (struct ray_softc *sc, struct ray_stats_req *sr);
327 static int ray_res_alloc_am (struct ray_softc *sc);
328 static int ray_res_alloc_cm (struct ray_softc *sc);
329 static int ray_res_alloc_irq (struct ray_softc *sc);
330 static void ray_res_release (struct ray_softc *sc);
331 static void ray_rx (struct ray_softc *sc, size_t rcs);
332 static void ray_rx_ctl (struct ray_softc *sc, struct mbuf *m0);
333 static void ray_rx_data (struct ray_softc *sc, struct mbuf *m0, u_int8_t siglev, u_int8_t antenna);
334 static void ray_rx_mgt (struct ray_softc *sc, struct mbuf *m0);
335 static void ray_rx_mgt_auth (struct ray_softc *sc, struct mbuf *m0);
336 static void ray_rx_mgt_beacon (struct ray_softc *sc, struct mbuf *m0);
337 static void ray_rx_mgt_info (struct ray_softc *sc, struct mbuf *m0, struct ieee80211_information *elements);
338 static void ray_rx_update_cache (struct ray_softc *sc, u_int8_t *src, u_int8_t siglev, u_int8_t antenna);
339 static void ray_stop (struct ray_softc *sc, struct ray_comq_entry *com);
340 static int ray_stop_user (struct ray_softc *sc);
341 static void ray_tx (struct ifnet *ifp);
342 static void ray_tx_done (struct ray_softc *sc, u_int8_t status, size_t ccs);
343 static void ray_tx_timo (void *xsc);
344 static int ray_tx_send (struct ray_softc *sc, size_t ccs, int pktlen, u_int8_t *dst);
345 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);
346 static void ray_upparams (struct ray_softc *sc, struct ray_comq_entry *com);
347 static void ray_upparams_done (struct ray_softc *sc, u_int8_t status, size_t ccs);
348 static int ray_upparams_user (struct ray_softc *sc, struct ray_param_req *pr);
349 static void ray_watchdog (struct ifnet *ifp);
350 static u_int8_t ray_tx_best_antenna (struct ray_softc *sc, u_int8_t *dst);
352 #if RAY_DEBUG & RAY_DBG_COM
353 static void ray_com_ecf_check (struct ray_softc *sc, size_t ccs, char *mesg);
354 #endif /* RAY_DEBUG & RAY_DBG_COM */
355 #if RAY_DEBUG & RAY_DBG_MBUF
356 static void ray_dump_mbuf (struct ray_softc *sc, struct mbuf *m, char *s);
357 #endif /* RAY_DEBUG & RAY_DBG_MBUF */
360 * PC-Card (PCMCIA) driver definition
362 static device_method_t ray_methods[] = {
363 /* Device interface */
364 DEVMETHOD(device_probe, ray_probe),
365 DEVMETHOD(device_attach, ray_attach),
366 DEVMETHOD(device_detach, ray_detach),
371 static driver_t ray_driver = {
374 sizeof(struct ray_softc)
377 static devclass_t ray_devclass;
379 DECLARE_DUMMY_MODULE(if_ray);
380 DRIVER_MODULE(if_ray, pccard, ray_driver, ray_devclass, 0, 0);
383 * Probe for the card by checking its startup results.
385 * Fixup any bugs/quirks for different firmware.
388 ray_probe(device_t dev)
390 struct ray_softc *sc = device_get_softc(dev);
391 struct ray_ecf_startup_v5 *ep = &sc->sc_ecf_startup;
395 RAY_DPRINTF(sc, RAY_DBG_SUBR, "");
398 * Read startup results from the card.
400 error = ray_res_alloc_cm(sc);
403 error = ray_res_alloc_am(sc);
409 SRAM_READ_REGION(sc, RAY_ECF_TO_HOST_BASE, ep,
410 sizeof(sc->sc_ecf_startup));
414 * Check the card is okay and work out what version we are using.
416 if (ep->e_status != RAY_ECFS_CARD_OK) {
417 RAY_PRINTF(sc, "card failed self test 0x%b",
418 ep->e_status, RAY_ECFS_PRINTFB);
421 if (sc->sc_version != RAY_ECFS_BUILD_4 &&
422 sc->sc_version != RAY_ECFS_BUILD_5) {
423 RAY_PRINTF(sc, "unsupported firmware version 0x%0x",
424 ep->e_fw_build_string);
427 RAY_DPRINTF(sc, RAY_DBG_BOOTPARAM, "found a card");
431 * Fixup tib size to be correct - on build 4 it is garbage
433 if (sc->sc_version == RAY_ECFS_BUILD_4 && sc->sc_tibsize == 0x55)
434 sc->sc_tibsize = sizeof(struct ray_tx_tib);
440 * Attach the card into the kernel
443 ray_attach(device_t dev)
445 struct ray_softc *sc = device_get_softc(dev);
446 struct ray_ecf_startup_v5 *ep = &sc->sc_ecf_startup;
447 struct ifnet *ifp = &sc->arpcom.ac_if;
451 RAY_DPRINTF(sc, RAY_DBG_SUBR, "");
453 if ((sc == NULL) || (sc->sc_gone))
457 * Grab the resources I need
459 error = ray_res_alloc_cm(sc);
462 error = ray_res_alloc_am(sc);
467 error = ray_res_alloc_irq(sc);
474 * Reset any pending interrupts
476 RAY_HCS_CLEAR_INTR(sc);
479 * Set the parameters that will survive stop/init and
480 * reset a few things on the card.
482 * Do not update these in ray_init_download's parameter setup
484 * XXX see the ray_init_download section for stuff to move
487 bzero(&sc->sc_d, sizeof(struct ray_nw_param));
488 bzero(&sc->sc_c, sizeof(struct ray_nw_param));
490 /* Clear statistics counters */
491 sc->sc_rxoverflow = 0;
496 /* Clear signal and antenna cache */
497 bzero(sc->sc_siglevs, sizeof(sc->sc_siglevs));
499 /* Set all ccs to be free */
500 bzero(sc->sc_ccsinuse, sizeof(sc->sc_ccsinuse));
501 ccs = RAY_CCS_ADDRESS(0);
502 for (i = 0; i < RAY_CCS_LAST; ccs += RAY_CCS_SIZE, i++)
503 RAY_CCS_FREE(sc, ccs);
506 * Initialise the network interface structure
508 if_initname(ifp, "ray", device_get_unit(dev));
511 ifp->if_flags = (IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST);
512 ifp->if_hdrlen = sizeof(struct ieee80211_frame) +
513 sizeof(struct ether_header);
514 ifp->if_baudrate = 1000000; /* Is this baud or bps ;-) */
515 ifp->if_start = ray_tx;
516 ifp->if_ioctl = ray_ioctl;
517 ifp->if_watchdog = ray_watchdog;
518 ifp->if_init = ray_init;
519 ifp->if_snd.ifq_maxlen = IFQ_MAXLEN;
522 * Initialise the timers and driver
524 callout_init(&sc->com_timer);
525 callout_init(&sc->tx_timer);
526 TAILQ_INIT(&sc->sc_comq);
528 ether_ifattach(ifp, ep->e_station_addr);
531 * Print out some useful information
533 if (bootverbose || (RAY_DEBUG & RAY_DBG_BOOTPARAM)) {
534 RAY_PRINTF(sc, "start up results");
535 if (sc->sc_version == RAY_ECFS_BUILD_4)
536 printf(". Firmware version 4\n");
538 printf(". Firmware version 5\n");
539 printf(". Status 0x%b\n", ep->e_status, RAY_ECFS_PRINTFB);
540 if (sc->sc_version == RAY_ECFS_BUILD_4) {
541 printf(". Program checksum %0x\n", ep->e_resv0);
542 printf(". CIS checksum %0x\n", ep->e_rates[0]);
544 printf(". (reserved word) %0x\n", ep->e_resv0);
545 printf(". Supported rates %8D\n", ep->e_rates, ":");
547 printf(". Japan call sign %12D\n", ep->e_japan_callsign, ":");
548 if (sc->sc_version == RAY_ECFS_BUILD_5) {
549 printf(". Program checksum %0x\n", ep->e_prg_cksum);
550 printf(". CIS checksum %0x\n", ep->e_cis_cksum);
551 printf(". Firmware version %0x\n",
552 ep->e_fw_build_string);
553 printf(". Firmware revision %0x\n", ep->e_fw_build);
554 printf(". (reserved word) %0x\n", ep->e_fw_resv);
555 printf(". ASIC version %0x\n", ep->e_asic_version);
556 printf(". TIB size %0x\n", ep->e_tibsize);
566 * This is usually called when the card is ejected, but
567 * can be caused by a modunload of a controller driver.
568 * The idea is to reset the driver's view of the device
569 * and ensure that any driver entry points such as
570 * read and write do not hang.
573 ray_detach(device_t dev)
575 struct ray_softc *sc = device_get_softc(dev);
576 struct ifnet *ifp = &sc->arpcom.ac_if;
577 struct ray_comq_entry *com;
582 RAY_DPRINTF(sc, RAY_DBG_SUBR | RAY_DBG_STOP, "");
584 if ((sc == NULL) || (sc->sc_gone))
588 * Mark as not running and detach the interface.
590 * N.B. if_detach can trigger ioctls so we do it first and
591 * then clean the runq.
594 sc->sc_c.np_havenet = 0;
595 ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
599 * Stop the runq and wake up anyone sleeping for us.
601 callout_stop(&sc->com_timer);
602 callout_stop(&sc->tx_timer);
603 com = TAILQ_FIRST(&sc->sc_comq);
604 for (com = TAILQ_FIRST(&sc->sc_comq); com != NULL;
605 com = TAILQ_NEXT(com, c_chain)) {
606 com->c_flags |= RAY_COM_FDETACHED;
608 RAY_DPRINTF(sc, RAY_DBG_STOP, "looking at com %p %b",
609 com, com->c_flags, RAY_COM_FLAGS_PRINTFB);
610 if (com->c_flags & RAY_COM_FWOK) {
611 RAY_DPRINTF(sc, RAY_DBG_STOP, "waking com %p", com);
612 wakeup(com->c_wakeup);
620 RAY_DPRINTF(sc, RAY_DBG_STOP, "unloading complete");
628 * Network ioctl request.
631 ray_ioctl(register struct ifnet *ifp, u_long command, caddr_t data,
634 struct ray_softc *sc = ifp->if_softc;
635 struct ray_param_req pr;
636 struct ray_stats_req sr;
637 struct ifreq *ifr = (struct ifreq *)data;
638 int s, error, error2;
640 RAY_DPRINTF(sc, RAY_DBG_SUBR | RAY_DBG_IOCTL, "");
642 if ((sc == NULL) || (sc->sc_gone))
653 RAY_DPRINTF(sc, RAY_DBG_IOCTL, "GIFADDR/SIFMTU");
654 error = ether_ioctl(ifp, command, data);
655 /* XXX SIFADDR used to fall through to SIOCSIFFLAGS */
659 RAY_DPRINTF(sc, RAY_DBG_IOCTL, "SIFFLAGS 0x%0x", ifp->if_flags);
661 * If the interface is marked up we call ray_init_user.
662 * This will deal with mcast and promisc flags as well as
663 * initialising the hardware if it needs it.
665 if (ifp->if_flags & IFF_UP)
666 error = ray_init_user(sc);
668 error = ray_stop_user(sc);
673 RAY_DPRINTF(sc, RAY_DBG_IOCTL, "ADDMULTI/DELMULTI");
674 error = ray_mcast_user(sc);
678 RAY_DPRINTF(sc, RAY_DBG_IOCTL, "SRAYPARAM");
679 if ((error = copyin(ifr->ifr_data, &pr, sizeof(pr))))
681 error = ray_upparams_user(sc, &pr);
682 error2 = copyout(&pr, ifr->ifr_data, sizeof(pr));
683 error = error2 ? error2 : error;
687 RAY_DPRINTF(sc, RAY_DBG_IOCTL, "GRAYPARAM");
688 if ((error = copyin(ifr->ifr_data, &pr, sizeof(pr))))
690 error = ray_repparams_user(sc, &pr);
691 error2 = copyout(&pr, ifr->ifr_data, sizeof(pr));
692 error = error2 ? error2 : error;
696 RAY_DPRINTF(sc, RAY_DBG_IOCTL, "GRAYSTATS");
697 error = ray_repstats_user(sc, &sr);
698 error2 = copyout(&sr, ifr->ifr_data, sizeof(sr));
699 error = error2 ? error2 : error;
703 RAY_DPRINTF(sc, RAY_DBG_IOCTL, "GRAYSIGLEV");
704 error = copyout(sc->sc_siglevs, ifr->ifr_data,
705 sizeof(sc->sc_siglevs));
709 RAY_DPRINTF(sc, RAY_DBG_IOCTL, "GIFFLAGS");
714 RAY_DPRINTF(sc, RAY_DBG_IOCTL, "GIFMETRIC");
719 RAY_DPRINTF(sc, RAY_DBG_IOCTL, "GIFMTU");
724 RAY_DPRINTF(sc, RAY_DBG_IOCTL, "GIFPYHS");
729 RAY_DPRINTF(sc, RAY_DBG_IOCTL, "SIFMEDIA");
734 RAY_DPRINTF(sc, RAY_DBG_IOCTL, "GIFMEDIA");
749 * Ethernet layer entry to ray_init - discard errors
754 struct ray_softc *sc = (struct ray_softc *)xsc;
760 * User land entry to network initialisation and changes in interface flags.
762 * We do a very little work here, just creating runq entries to
763 * processes the actions needed to cope with interface flags. We do it
764 * this way in case there are runq entries outstanding from earlier
765 * ioctls that modify the interface flags.
767 * Returns values are either 0 for success, a varity of resource allocation
768 * failures or errors in the command sent to the card.
770 * Note, IFF_RUNNING is eventually set by init_sj_done or init_assoc_done
773 ray_init_user(struct ray_softc *sc)
775 struct ray_comq_entry *com[6];
778 RAY_DPRINTF(sc, RAY_DBG_SUBR | RAY_DBG_STARTJOIN, "");
781 * Create the following runq entries to bring the card up.
783 * init_download - download the network to the card
784 * init_mcast - reset multicast list
785 * init_sj - find or start a BSS
786 * init_auth - authenticate with a ESSID if needed
787 * init_assoc - associate with a ESSID if needed
789 * They are only actually executed if the card is not running.
790 * We may enter this routine from a simple change of IP
791 * address and do not need to get the card to do these things.
792 * However, we cannot perform the check here as there may be
793 * commands in the runq that change the IFF_RUNNING state of
797 com[ncom++] = RAY_COM_MALLOC(ray_init_download, RAY_COM_FCHKRUNNING);
798 com[ncom++] = RAY_COM_MALLOC(ray_init_mcast, RAY_COM_FCHKRUNNING);
799 com[ncom++] = RAY_COM_MALLOC(ray_init_sj, RAY_COM_FCHKRUNNING);
800 com[ncom++] = RAY_COM_MALLOC(ray_init_auth, RAY_COM_FCHKRUNNING);
801 com[ncom++] = RAY_COM_MALLOC(ray_init_assoc, RAY_COM_FCHKRUNNING);
804 * Create runq entries to process flags
806 * promisc - set/reset PROMISC and ALLMULTI flags
808 * They are only actually executed if the card is running
810 com[ncom++] = RAY_COM_MALLOC(ray_promisc, 0);
812 RAY_COM_RUNQ(sc, com, ncom, "rayinit", error);
814 /* XXX no real error processing from anything yet! */
816 RAY_COM_FREE(com, ncom);
822 * Runq entry for resetting driver and downloading start up structures to card
825 ray_init_download(struct ray_softc *sc, struct ray_comq_entry *com)
827 struct ifnet *ifp = &sc->arpcom.ac_if;
829 RAY_DPRINTF(sc, RAY_DBG_SUBR | RAY_DBG_STARTJOIN, "");
831 /* If the card already running we might not need to download */
832 RAY_COM_CHKRUNNING(sc, com, ifp);
835 * Reset instance variables
837 * The first set are network parameters that are read back when
838 * the card starts or joins the network.
840 * The second set are network parameters that are downloaded to
843 * The third set are driver parameters.
845 * All of the variables in these sets can be updated by the
848 * XXX see the ray_attach section for stuff to move
850 sc->sc_d.np_upd_param = 0;
851 bzero(sc->sc_d.np_bss_id, ETHER_ADDR_LEN);
852 sc->sc_d.np_inited = 0;
853 sc->sc_d.np_def_txrate = RAY_MIB_BASIC_RATE_SET_DEFAULT;
854 sc->sc_d.np_encrypt = 0;
856 bzero(sc->sc_d.np_ssid, IEEE80211_NWID_LEN);
857 if (sc->sc_version == RAY_ECFS_BUILD_4) {
858 sc->sc_d.np_net_type = RAY_MIB_NET_TYPE_V4;
859 strncpy(sc->sc_d.np_ssid, RAY_MIB_SSID_V4, IEEE80211_NWID_LEN);
860 sc->sc_d.np_ap_status = RAY_MIB_AP_STATUS_V4;
861 sc->sc_d.np_framing = RAY_FRAMING_ENCAPSULATION;
863 sc->sc_d.np_net_type = RAY_MIB_NET_TYPE_V5;
864 strncpy(sc->sc_d.np_ssid, RAY_MIB_SSID_V5, IEEE80211_NWID_LEN);
865 sc->sc_d.np_ap_status = RAY_MIB_AP_STATUS_V5;
866 sc->sc_d.np_framing = RAY_FRAMING_TRANSLATION;
868 sc->sc_d.np_priv_start = RAY_MIB_PRIVACY_MUST_START_DEFAULT;
869 sc->sc_d.np_priv_join = RAY_MIB_PRIVACY_CAN_JOIN_DEFAULT;
870 sc->sc_d.np_promisc = !!(ifp->if_flags & (IFF_PROMISC | IFF_ALLMULTI));
872 /* XXX this is a hack whilst I transition the code. The instance
873 * XXX variables above should be set somewhere else. This is needed for
875 bcopy(&sc->sc_d, &com->c_desired, sizeof(struct ray_nw_param));
878 * Download the right firmware defaults
880 if (sc->sc_version == RAY_ECFS_BUILD_4)
881 ray_init_download_v4(sc, com);
883 ray_init_download_v5(sc, com);
888 ray_ccs_fill(sc, com->c_ccs, RAY_CMD_DOWNLOAD_PARAMS);
889 ray_com_ecf(sc, com);
893 do { (p)[0] = ((v >> 8) & 0xff); (p)[1] = (v & 0xff); } while(0)
895 * Firmware version 4 defaults - see if_raymib.h for details
898 ray_init_download_v4(struct ray_softc *sc, struct ray_comq_entry *com)
900 struct ray_mib_4 ray_mib_4_default;
902 RAY_DPRINTF(sc, RAY_DBG_SUBR | RAY_DBG_STARTJOIN, "");
905 #define MIB4(m) ray_mib_4_default.m
907 MIB4(mib_net_type) = com->c_desired.np_net_type;
908 MIB4(mib_ap_status) = com->c_desired.np_ap_status;
909 bcopy(com->c_desired.np_ssid, MIB4(mib_ssid), IEEE80211_NWID_LEN);
910 MIB4(mib_scan_mode) = RAY_MIB_SCAN_MODE_V4;
911 MIB4(mib_apm_mode) = RAY_MIB_APM_MODE_V4;
912 bcopy(sc->sc_station_addr, MIB4(mib_mac_addr), ETHER_ADDR_LEN);
913 PUT2(MIB4(mib_frag_thresh), RAY_MIB_FRAG_THRESH_V4);
914 PUT2(MIB4(mib_dwell_time), RAY_MIB_DWELL_TIME_V4);
915 PUT2(MIB4(mib_beacon_period), RAY_MIB_BEACON_PERIOD_V4);
916 MIB4(mib_dtim_interval) = RAY_MIB_DTIM_INTERVAL_V4;
917 MIB4(mib_max_retry) = RAY_MIB_MAX_RETRY_V4;
918 MIB4(mib_ack_timo) = RAY_MIB_ACK_TIMO_V4;
919 MIB4(mib_sifs) = RAY_MIB_SIFS_V4;
920 MIB4(mib_difs) = RAY_MIB_DIFS_V4;
921 MIB4(mib_pifs) = RAY_MIB_PIFS_V4;
922 PUT2(MIB4(mib_rts_thresh), RAY_MIB_RTS_THRESH_V4);
923 PUT2(MIB4(mib_scan_dwell), RAY_MIB_SCAN_DWELL_V4);
924 PUT2(MIB4(mib_scan_max_dwell), RAY_MIB_SCAN_MAX_DWELL_V4);
925 MIB4(mib_assoc_timo) = RAY_MIB_ASSOC_TIMO_V4;
926 MIB4(mib_adhoc_scan_cycle) = RAY_MIB_ADHOC_SCAN_CYCLE_V4;
927 MIB4(mib_infra_scan_cycle) = RAY_MIB_INFRA_SCAN_CYCLE_V4;
928 MIB4(mib_infra_super_scan_cycle)
929 = RAY_MIB_INFRA_SUPER_SCAN_CYCLE_V4;
930 MIB4(mib_promisc) = com->c_desired.np_promisc;
931 PUT2(MIB4(mib_uniq_word), RAY_MIB_UNIQ_WORD_V4);
932 MIB4(mib_slot_time) = RAY_MIB_SLOT_TIME_V4;
933 MIB4(mib_roam_low_snr_thresh) = RAY_MIB_ROAM_LOW_SNR_THRESH_V4;
934 MIB4(mib_low_snr_count) = RAY_MIB_LOW_SNR_COUNT_V4;
935 MIB4(mib_infra_missed_beacon_count)
936 = RAY_MIB_INFRA_MISSED_BEACON_COUNT_V4;
937 MIB4(mib_adhoc_missed_beacon_count)
938 = RAY_MIB_ADHOC_MISSED_BEACON_COUNT_V4;
939 MIB4(mib_country_code) = RAY_MIB_COUNTRY_CODE_V4;
940 MIB4(mib_hop_seq) = RAY_MIB_HOP_SEQ_V4;
941 MIB4(mib_hop_seq_len) = RAY_MIB_HOP_SEQ_LEN_V4;
942 MIB4(mib_cw_max) = RAY_MIB_CW_MAX_V4;
943 MIB4(mib_cw_min) = RAY_MIB_CW_MIN_V4;
944 MIB4(mib_noise_filter_gain) = RAY_MIB_NOISE_FILTER_GAIN_DEFAULT;
945 MIB4(mib_noise_limit_offset) = RAY_MIB_NOISE_LIMIT_OFFSET_DEFAULT;
946 MIB4(mib_rssi_thresh_offset) = RAY_MIB_RSSI_THRESH_OFFSET_DEFAULT;
947 MIB4(mib_busy_thresh_offset) = RAY_MIB_BUSY_THRESH_OFFSET_DEFAULT;
948 MIB4(mib_sync_thresh) = RAY_MIB_SYNC_THRESH_DEFAULT;
949 MIB4(mib_test_mode) = RAY_MIB_TEST_MODE_DEFAULT;
950 MIB4(mib_test_min_chan) = RAY_MIB_TEST_MIN_CHAN_DEFAULT;
951 MIB4(mib_test_max_chan) = RAY_MIB_TEST_MAX_CHAN_DEFAULT;
954 SRAM_WRITE_REGION(sc, RAY_HOST_TO_ECF_BASE,
955 &ray_mib_4_default, sizeof(ray_mib_4_default));
959 * Firmware version 5 defaults - see if_raymib.h for details
962 ray_init_download_v5(struct ray_softc *sc, struct ray_comq_entry *com)
964 struct ray_mib_5 ray_mib_5_default;
966 RAY_DPRINTF(sc, RAY_DBG_SUBR | RAY_DBG_STARTJOIN, "");
969 #define MIB5(m) ray_mib_5_default.m
970 MIB5(mib_net_type) = com->c_desired.np_net_type;
971 MIB5(mib_ap_status) = com->c_desired.np_ap_status;
972 bcopy(com->c_desired.np_ssid, MIB5(mib_ssid), IEEE80211_NWID_LEN);
973 MIB5(mib_scan_mode) = RAY_MIB_SCAN_MODE_V5;
974 MIB5(mib_apm_mode) = RAY_MIB_APM_MODE_V5;
975 bcopy(sc->sc_station_addr, MIB5(mib_mac_addr), ETHER_ADDR_LEN);
976 PUT2(MIB5(mib_frag_thresh), RAY_MIB_FRAG_THRESH_V5);
977 PUT2(MIB5(mib_dwell_time), RAY_MIB_DWELL_TIME_V5);
978 PUT2(MIB5(mib_beacon_period), RAY_MIB_BEACON_PERIOD_V5);
979 MIB5(mib_dtim_interval) = RAY_MIB_DTIM_INTERVAL_V5;
980 MIB5(mib_max_retry) = RAY_MIB_MAX_RETRY_V5;
981 MIB5(mib_ack_timo) = RAY_MIB_ACK_TIMO_V5;
982 MIB5(mib_sifs) = RAY_MIB_SIFS_V5;
983 MIB5(mib_difs) = RAY_MIB_DIFS_V5;
984 MIB5(mib_pifs) = RAY_MIB_PIFS_V5;
985 PUT2(MIB5(mib_rts_thresh), RAY_MIB_RTS_THRESH_V5);
986 PUT2(MIB5(mib_scan_dwell), RAY_MIB_SCAN_DWELL_V5);
987 PUT2(MIB5(mib_scan_max_dwell), RAY_MIB_SCAN_MAX_DWELL_V5);
988 MIB5(mib_assoc_timo) = RAY_MIB_ASSOC_TIMO_V5;
989 MIB5(mib_adhoc_scan_cycle) = RAY_MIB_ADHOC_SCAN_CYCLE_V5;
990 MIB5(mib_infra_scan_cycle) = RAY_MIB_INFRA_SCAN_CYCLE_V5;
991 MIB5(mib_infra_super_scan_cycle)
992 = RAY_MIB_INFRA_SUPER_SCAN_CYCLE_V5;
993 MIB5(mib_promisc) = com->c_desired.np_promisc;
994 PUT2(MIB5(mib_uniq_word), RAY_MIB_UNIQ_WORD_V5);
995 MIB5(mib_slot_time) = RAY_MIB_SLOT_TIME_V5;
996 MIB5(mib_roam_low_snr_thresh) = RAY_MIB_ROAM_LOW_SNR_THRESH_V5;
997 MIB5(mib_low_snr_count) = RAY_MIB_LOW_SNR_COUNT_V5;
998 MIB5(mib_infra_missed_beacon_count)
999 = RAY_MIB_INFRA_MISSED_BEACON_COUNT_V5;
1000 MIB5(mib_adhoc_missed_beacon_count)
1001 = RAY_MIB_ADHOC_MISSED_BEACON_COUNT_V5;
1002 MIB5(mib_country_code) = RAY_MIB_COUNTRY_CODE_V5;
1003 MIB5(mib_hop_seq) = RAY_MIB_HOP_SEQ_V5;
1004 MIB5(mib_hop_seq_len) = RAY_MIB_HOP_SEQ_LEN_V5;
1005 PUT2(MIB5(mib_cw_max), RAY_MIB_CW_MAX_V5);
1006 PUT2(MIB5(mib_cw_min), RAY_MIB_CW_MIN_V5);
1007 MIB5(mib_noise_filter_gain) = RAY_MIB_NOISE_FILTER_GAIN_DEFAULT;
1008 MIB5(mib_noise_limit_offset) = RAY_MIB_NOISE_LIMIT_OFFSET_DEFAULT;
1009 MIB5(mib_rssi_thresh_offset) = RAY_MIB_RSSI_THRESH_OFFSET_DEFAULT;
1010 MIB5(mib_busy_thresh_offset) = RAY_MIB_BUSY_THRESH_OFFSET_DEFAULT;
1011 MIB5(mib_sync_thresh) = RAY_MIB_SYNC_THRESH_DEFAULT;
1012 MIB5(mib_test_mode) = RAY_MIB_TEST_MODE_DEFAULT;
1013 MIB5(mib_test_min_chan) = RAY_MIB_TEST_MIN_CHAN_DEFAULT;
1014 MIB5(mib_test_max_chan) = RAY_MIB_TEST_MAX_CHAN_DEFAULT;
1015 MIB5(mib_allow_probe_resp) = RAY_MIB_ALLOW_PROBE_RESP_DEFAULT;
1016 MIB5(mib_privacy_must_start) = com->c_desired.np_priv_start;
1017 MIB5(mib_privacy_can_join) = com->c_desired.np_priv_join;
1018 MIB5(mib_basic_rate_set[0]) = com->c_desired.np_def_txrate;
1021 SRAM_WRITE_REGION(sc, RAY_HOST_TO_ECF_BASE,
1022 &ray_mib_5_default, sizeof(ray_mib_5_default));
1027 * Download completion routine
1030 ray_init_download_done(struct ray_softc *sc, u_int8_t status, size_t ccs)
1032 RAY_DPRINTF(sc, RAY_DBG_SUBR | RAY_DBG_STARTJOIN, "");
1033 RAY_COM_CHECK(sc, ccs);
1035 RAY_CCSERR(sc, status, if_oerrors); /* XXX error counter */
1037 ray_com_ecf_done(sc);
1041 * Runq entry to empty the multicast filter list
1044 ray_init_mcast(struct ray_softc *sc, struct ray_comq_entry *com)
1046 struct ifnet *ifp = &sc->arpcom.ac_if;
1048 RAY_DPRINTF(sc, RAY_DBG_SUBR | RAY_DBG_STARTJOIN, "");
1051 /* If the card already running we might not need to reset the list */
1052 RAY_COM_CHKRUNNING(sc, com, ifp);
1057 ray_ccs_fill(sc, com->c_ccs, RAY_CMD_UPDATE_MCAST);
1058 SRAM_WRITE_FIELD_1(sc, com->c_ccs, ray_cmd_update_mcast, c_nmcast, 0);
1060 ray_com_ecf(sc, com);
1064 * Runq entry to starting or joining a network
1067 ray_init_sj(struct ray_softc *sc, struct ray_comq_entry *com)
1069 struct ifnet *ifp = &sc->arpcom.ac_if;
1070 struct ray_net_params np;
1073 RAY_DPRINTF(sc, RAY_DBG_SUBR | RAY_DBG_STARTJOIN, "");
1076 /* If the card already running we might not need to start the n/w */
1077 RAY_COM_CHKRUNNING(sc, com, ifp);
1080 * Set up the right start or join command and determine
1081 * whether we should tell the card about a change in operating
1084 sc->sc_c.np_havenet = 0;
1085 if (sc->sc_d.np_net_type == RAY_MIB_NET_TYPE_ADHOC)
1086 ray_ccs_fill(sc, com->c_ccs, RAY_CMD_START_NET);
1088 ray_ccs_fill(sc, com->c_ccs, RAY_CMD_JOIN_NET);
1091 if (sc->sc_c.np_net_type != sc->sc_d.np_net_type)
1093 if (bcmp(sc->sc_c.np_ssid, sc->sc_d.np_ssid, IEEE80211_NWID_LEN))
1095 if (sc->sc_c.np_priv_join != sc->sc_d.np_priv_join)
1097 if (sc->sc_c.np_priv_start != sc->sc_d.np_priv_start)
1099 RAY_DPRINTF(sc, RAY_DBG_STARTJOIN,
1100 "%s updating nw params", update?"is":"not");
1102 bzero(&np, sizeof(np));
1103 np.p_net_type = sc->sc_d.np_net_type;
1104 bcopy(sc->sc_d.np_ssid, np.p_ssid, IEEE80211_NWID_LEN);
1105 np.p_privacy_must_start = sc->sc_d.np_priv_start;
1106 np.p_privacy_can_join = sc->sc_d.np_priv_join;
1107 SRAM_WRITE_REGION(sc, RAY_HOST_TO_ECF_BASE, &np, sizeof(np));
1108 SRAM_WRITE_FIELD_1(sc, com->c_ccs, ray_cmd_net, c_upd_param, 1);
1110 SRAM_WRITE_FIELD_1(sc, com->c_ccs, ray_cmd_net, c_upd_param, 0);
1115 ray_com_ecf(sc, com);
1119 * Complete start command or intermediate step in assoc command
1122 ray_init_sj_done(struct ray_softc *sc, u_int8_t status, size_t ccs)
1124 struct ifnet *ifp = &sc->arpcom.ac_if;
1126 RAY_DPRINTF(sc, RAY_DBG_SUBR | RAY_DBG_STARTJOIN, "");
1128 RAY_COM_CHECK(sc, ccs);
1130 RAY_CCSERR(sc, status, if_oerrors); /* XXX error counter */
1133 * Read back network parameters that the ECF sets
1135 SRAM_READ_REGION(sc, ccs, &sc->sc_c.p_1, sizeof(struct ray_cmd_net));
1137 /* Adjust values for buggy firmware */
1138 if (sc->sc_c.np_inited == 0x55)
1139 sc->sc_c.np_inited = 0;
1140 if (sc->sc_c.np_def_txrate == 0x55)
1141 sc->sc_c.np_def_txrate = sc->sc_d.np_def_txrate;
1142 if (sc->sc_c.np_encrypt == 0x55)
1143 sc->sc_c.np_encrypt = sc->sc_d.np_encrypt;
1146 * Update our local state if we updated the network parameters
1147 * when the START_NET or JOIN_NET was issued.
1149 if (sc->sc_c.np_upd_param) {
1150 RAY_DPRINTF(sc, RAY_DBG_STARTJOIN, "updated parameters");
1151 SRAM_READ_REGION(sc, RAY_HOST_TO_ECF_BASE,
1152 &sc->sc_c.p_2, sizeof(struct ray_net_params));
1156 * Hurrah! The network is now active.
1158 * Clearing IFF_OACTIVE will ensure that the system will send us
1159 * packets. Just before we return from the interrupt context
1160 * we check to see if packets have been queued.
1162 if (SRAM_READ_FIELD_1(sc, ccs, ray_cmd, c_cmd) == RAY_CMD_START_NET) {
1163 sc->sc_c.np_havenet = 1;
1164 sc->sc_c.np_framing = sc->sc_d.np_framing;
1165 ifp->if_flags |= IFF_RUNNING;
1166 ifp->if_flags &= ~IFF_OACTIVE;
1169 ray_com_ecf_done(sc);
1173 * Runq entry to authenticate with an access point or another station
1176 ray_init_auth(struct ray_softc *sc, struct ray_comq_entry *com)
1178 struct ifnet *ifp = &sc->arpcom.ac_if;
1180 RAY_DPRINTF(sc, RAY_DBG_SUBR | RAY_DBG_STARTJOIN | RAY_DBG_AUTH, "");
1182 /* If card already running we might not need to authenticate */
1183 RAY_COM_CHKRUNNING(sc, com, ifp);
1186 * XXX Don't do anything if we are not in a managed network
1188 * XXX V4 adhoc does not need this, V5 adhoc unknown
1190 if (sc->sc_c.np_net_type != RAY_MIB_NET_TYPE_INFRA) {
1191 ray_com_runq_done(sc);
1196 * XXX_AUTH need to think of run queue when doing auths from request i.e. would
1197 * XXX_AUTH need to have auth at top of runq?
1198 * XXX_AUTH ditto for sending any auth response packets...what about timeouts?
1204 /* XXX_AUTH check exit status and retry or fail as we can't associate without this */
1205 ray_init_auth_send(sc, sc->sc_c.np_bss_id, IEEE80211_AUTH_OPEN_REQUEST);
1209 * Build and send an authentication packet
1211 * If an error occurs, returns 1 else returns 0.
1214 ray_init_auth_send(struct ray_softc *sc, u_int8_t *dst, int sequence)
1219 RAY_DPRINTF(sc, RAY_DBG_SUBR | RAY_DBG_STARTJOIN | RAY_DBG_AUTH, "");
1221 /* Get a control block */
1222 if (ray_ccs_tx(sc, &ccs, &bufp)) {
1223 RAY_RECERR(sc, "could not obtain a ccs");
1227 /* Fill the header in */
1228 bufp = ray_tx_wrhdr(sc, bufp,
1229 IEEE80211_FC0_TYPE_MGT | IEEE80211_FC0_SUBTYPE_AUTH,
1230 IEEE80211_FC1_DIR_NODS,
1232 sc->arpcom.ac_enaddr,
1233 sc->sc_c.np_bss_id);
1235 /* Add algorithm number */
1236 SRAM_WRITE_1(sc, bufp + pktlen++, IEEE80211_AUTH_ALG_OPEN);
1237 SRAM_WRITE_1(sc, bufp + pktlen++, 0);
1239 /* Add sequence number */
1240 SRAM_WRITE_1(sc, bufp + pktlen++, sequence);
1241 SRAM_WRITE_1(sc, bufp + pktlen++, 0);
1243 /* Add status code */
1244 SRAM_WRITE_1(sc, bufp + pktlen++, 0);
1245 SRAM_WRITE_1(sc, bufp + pktlen++, 0);
1246 pktlen += sizeof(struct ieee80211_frame);
1248 return (ray_tx_send(sc, ccs, pktlen, dst));
1252 * Complete authentication runq
1255 ray_init_auth_done(struct ray_softc *sc, u_int8_t status)
1257 RAY_DPRINTF(sc, RAY_DBG_SUBR | RAY_DBG_STARTJOIN | RAY_DBG_AUTH, "");
1259 if (status != IEEE80211_STATUS_SUCCESS)
1260 RAY_RECERR(sc, "authentication failed with status %d", status);
1262 * XXX_AUTH retry? if not just recall ray_init_auth_send and dont clear runq?
1263 * XXX_AUTH association requires that authenitcation is successful
1264 * XXX_AUTH before we associate, and the runq is the only way to halt the
1265 * XXX_AUTH progress of associate.
1266 * XXX_AUTH In this case I might not need the RAY_AUTH_NEEDED state
1268 ray_com_runq_done(sc);
1272 * Runq entry to starting an association with an access point
1275 ray_init_assoc(struct ray_softc *sc, struct ray_comq_entry *com)
1277 struct ifnet *ifp = &sc->arpcom.ac_if;
1279 RAY_DPRINTF(sc, RAY_DBG_SUBR | RAY_DBG_STARTJOIN, "");
1281 /* If the card already running we might not need to associate */
1282 RAY_COM_CHKRUNNING(sc, com, ifp);
1285 * Don't do anything if we are not in a managed network
1287 if (sc->sc_c.np_net_type != RAY_MIB_NET_TYPE_INFRA) {
1288 ray_com_runq_done(sc);
1295 ray_ccs_fill(sc, com->c_ccs, RAY_CMD_START_ASSOC);
1296 ray_com_ecf(sc, com);
1300 * Complete association
1303 ray_init_assoc_done(struct ray_softc *sc, u_int8_t status, size_t ccs)
1305 struct ifnet *ifp = &sc->arpcom.ac_if;
1307 RAY_DPRINTF(sc, RAY_DBG_SUBR | RAY_DBG_STARTJOIN, "");
1308 RAY_COM_CHECK(sc, ccs);
1310 RAY_CCSERR(sc, status, if_oerrors); /* XXX error counter */
1313 * Hurrah! The network is now active.
1315 * Clearing IFF_OACTIVE will ensure that the system will send us
1316 * packets. Just before we return from the interrupt context
1317 * we check to see if packets have been queued.
1319 sc->sc_c.np_havenet = 1;
1320 sc->sc_c.np_framing = sc->sc_d.np_framing;
1321 ifp->if_flags |= IFF_RUNNING;
1322 ifp->if_flags &= ~IFF_OACTIVE;
1324 ray_com_ecf_done(sc);
1330 * Inhibit card - if we can't prevent reception then do not worry;
1331 * stopping a NIC only guarantees no TX.
1333 * The change to the interface flags is done via the runq so that any
1334 * existing commands can execute normally.
1337 ray_stop_user(struct ray_softc *sc)
1339 struct ray_comq_entry *com[1];
1342 RAY_DPRINTF(sc, RAY_DBG_SUBR | RAY_DBG_STOP, "");
1345 * Schedule the real stop routine
1348 com[ncom++] = RAY_COM_MALLOC(ray_stop, 0);
1350 RAY_COM_RUNQ(sc, com, ncom, "raystop", error);
1352 /* XXX no real error processing from anything yet! */
1354 RAY_COM_FREE(com, ncom);
1360 * Runq entry for stopping the interface activity
1363 ray_stop(struct ray_softc *sc, struct ray_comq_entry *com)
1365 struct ifnet *ifp = &sc->arpcom.ac_if;
1368 RAY_DPRINTF(sc, RAY_DBG_SUBR | RAY_DBG_STOP, "");
1371 * Mark as not running and drain output queue
1373 ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
1376 IF_DEQUEUE(&ifp->if_snd, m);
1382 ray_com_runq_done(sc);
1386 ray_watchdog(struct ifnet *ifp)
1388 struct ray_softc *sc = ifp->if_softc;
1390 RAY_DPRINTF(sc, RAY_DBG_SUBR, "");
1393 if ((sc == NULL) || (sc->sc_gone))
1396 RAY_PRINTF(sc, "watchdog timeout");
1400 * Transmit packet handling
1406 * We make two assumptions here:
1407 * 1) That the current priority is set to splimp _before_ this code
1408 * is called *and* is returned to the appropriate priority after
1410 * 2) That the IFF_OACTIVE flag is checked before this code is called
1411 * (i.e. that the output part of the interface is idle)
1413 * A simple one packet at a time TX routine is used - we don't bother
1414 * chaining TX buffers. Performance is sufficient to max out the
1415 * wireless link on a P75.
1417 * AST J30 Windows 95A (100MHz Pentium) to
1418 * Libretto 50CT FreeBSD-3.1 (75MHz Pentium) 167.37kB/s
1419 * Nonname box FreeBSD-3.4 (233MHz AMD K6) 161.82kB/s
1421 * Libretto 50CT FreeBSD-3.1 (75MHz Pentium) to
1422 * AST J30 Windows 95A (100MHz Pentium) 167.37kB/s
1423 * Nonname box FreeBSD-3.4 (233MHz AMD K6) 161.38kB/s
1425 * Given that 160kB/s is saturating the 2Mb/s wireless link we
1428 * In short I'm happy that the added complexity of chaining TX
1429 * packets together isn't worth it for my machines.
1432 ray_tx(struct ifnet *ifp)
1434 struct ray_softc *sc = ifp->if_softc;
1435 struct mbuf *m0, *m;
1436 struct ether_header *eh;
1441 RAY_DPRINTF(sc, RAY_DBG_SUBR | RAY_DBG_TX, "");
1445 * Some simple checks first - some are overkill
1447 if ((sc == NULL) || (sc->sc_gone))
1449 if (!(ifp->if_flags & IFF_RUNNING)) {
1450 RAY_RECERR(sc, "cannot transmit - not running");
1453 if (!sc->sc_c.np_havenet) {
1454 RAY_RECERR(sc, "cannot transmit - no network");
1457 if (!RAY_ECF_READY(sc)) {
1458 /* Can't assume that the ECF is busy because of this driver */
1459 if (!callout_active(&sc->tx_timer)) {
1460 callout_reset(&sc->tx_timer, RAY_TX_TIMEOUT,
1465 callout_stop(&sc->tx_timer);
1468 * We find a ccs before we process the mbuf so that we are sure it
1469 * is worthwhile processing the packet. All errors in the mbuf
1470 * processing are either errors in the mbuf or gross configuration
1471 * errors and the packet wouldn't get through anyway.
1473 if (ray_ccs_tx(sc, &ccs, &bufp)) {
1474 ifp->if_flags |= IFF_OACTIVE;
1479 * Get the mbuf and process it - we have to remember to free the
1480 * ccs if there are any errors.
1482 IF_DEQUEUE(&ifp->if_snd, m0);
1484 RAY_CCS_FREE(sc, ccs);
1488 pktlen = m0->m_pkthdr.len;
1489 if (pktlen > ETHER_MAX_LEN - ETHER_CRC_LEN) {
1490 RAY_RECERR(sc, "mbuf too long %d", pktlen);
1491 RAY_CCS_FREE(sc, ccs);
1497 m0 = m_pullup(m0, sizeof(struct ether_header));
1499 RAY_RECERR(sc, "could not pullup ether");
1500 RAY_CCS_FREE(sc, ccs);
1504 eh = mtod(m0, struct ether_header *);
1507 * Write the 802.11 header according to network type etc.
1509 if (sc->sc_c.np_net_type == RAY_MIB_NET_TYPE_ADHOC)
1510 bufp = ray_tx_wrhdr(sc, bufp,
1511 IEEE80211_FC0_TYPE_DATA,
1512 IEEE80211_FC1_DIR_NODS,
1515 sc->sc_c.np_bss_id);
1517 if (sc->sc_c.np_ap_status == RAY_MIB_AP_STATUS_TERMINAL)
1518 bufp = ray_tx_wrhdr(sc, bufp,
1519 IEEE80211_FC0_TYPE_DATA,
1520 IEEE80211_FC1_DIR_TODS,
1525 bufp = ray_tx_wrhdr(sc, bufp,
1526 IEEE80211_FC0_TYPE_DATA,
1527 IEEE80211_FC1_DIR_FROMDS,
1537 switch (sc->sc_c.np_framing) {
1539 case RAY_FRAMING_ENCAPSULATION:
1540 /* Nice and easy - nothing! (just add an 802.11 header) */
1543 case RAY_FRAMING_TRANSLATION:
1545 * Drop the first address in the ethernet header and
1546 * write an LLC and SNAP header over the second.
1548 m_adj(m0, ETHER_ADDR_LEN);
1550 RAY_RECERR(sc, "could not get space for 802.2 header");
1551 RAY_CCS_FREE(sc, ccs);
1555 llc = mtod(m0, struct llc *);
1556 llc->llc_dsap = LLC_SNAP_LSAP;
1557 llc->llc_ssap = LLC_SNAP_LSAP;
1558 llc->llc_control = LLC_UI;
1559 llc->llc_un.type_snap.org_code[0] = 0;
1560 llc->llc_un.type_snap.org_code[1] = 0;
1561 llc->llc_un.type_snap.org_code[2] = 0;
1565 RAY_RECERR(sc, "unknown framing type %d", sc->sc_c.np_framing);
1566 RAY_CCS_FREE(sc, ccs);
1573 RAY_RECERR(sc, "could not frame packet");
1574 RAY_CCS_FREE(sc, ccs);
1578 RAY_MBUF_DUMP(sc, RAY_DBG_TX, m0, "framed packet");
1581 * Copy the mbuf to the buffer in common memory
1583 * We drop and don't bother wrapping as Ethernet packets are 1518
1584 * bytes, we checked the mbuf earlier, and our TX buffers are 2048
1585 * bytes. We don't have 530 bytes of headers etc. so something
1588 pktlen = sizeof(struct ieee80211_frame);
1589 for (m = m0; m != NULL; m = m->m_next) {
1591 if ((len = m->m_len) == 0)
1593 if ((bufp + len) < RAY_TX_END)
1594 SRAM_WRITE_REGION(sc, bufp, mtod(m, u_int8_t *), len);
1596 RAY_RECERR(sc, "tx buffer overflow");
1597 RAY_CCS_FREE(sc, ccs);
1608 if (ray_tx_send(sc, ccs, pktlen, eh->ether_dhost))
1616 * Start timeout routine.
1618 * Used when card was busy but we needed to send a packet.
1621 ray_tx_timo(void *xsc)
1623 struct ray_softc *sc = (struct ray_softc *)xsc;
1624 struct ifnet *ifp = &sc->arpcom.ac_if;
1627 RAY_DPRINTF(sc, RAY_DBG_SUBR, "");
1629 if (!(ifp->if_flags & IFF_OACTIVE) && (ifp->if_snd.ifq_head != NULL)) {
1637 * Write an 802.11 header into the Tx buffer space and return the
1638 * adjusted buffer pointer.
1641 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)
1643 struct ieee80211_frame header;
1645 RAY_DPRINTF(sc, RAY_DBG_SUBR | RAY_DBG_TX, "");
1648 bzero(&header, sizeof(struct ieee80211_frame));
1649 header.i_fc[0] = (IEEE80211_FC0_VERSION_0 | type);
1650 header.i_fc[1] = fc1;
1651 bcopy(addr1, header.i_addr1, ETHER_ADDR_LEN);
1652 bcopy(addr2, header.i_addr2, ETHER_ADDR_LEN);
1653 bcopy(addr3, header.i_addr3, ETHER_ADDR_LEN);
1655 SRAM_WRITE_REGION(sc, bufp, (u_int8_t *)&header,
1656 sizeof(struct ieee80211_frame));
1658 return (bufp + sizeof(struct ieee80211_frame));
1662 * Fill in a few loose ends and kick the card to send the packet
1664 * Returns 0 on success, 1 on failure
1667 ray_tx_send(struct ray_softc *sc, size_t ccs, int pktlen, u_int8_t *dst)
1671 RAY_DPRINTF(sc, RAY_DBG_SUBR | RAY_DBG_TX, "");
1674 while (!RAY_ECF_READY(sc)) {
1675 DELAY(RAY_ECF_SPIN_DELAY);
1676 if (++i > RAY_ECF_SPIN_TRIES) {
1677 RAY_RECERR(sc, "ECF busy, dropping packet");
1678 RAY_CCS_FREE(sc, ccs);
1683 RAY_RECERR(sc, "spun %d times", i);
1685 SRAM_WRITE_FIELD_2(sc, ccs, ray_cmd_tx, c_len, pktlen);
1686 SRAM_WRITE_FIELD_1(sc, ccs, ray_cmd_tx, c_antenna,
1687 ray_tx_best_antenna(sc, dst));
1688 SRAM_WRITE_1(sc, RAY_SCB_CCSI, RAY_CCS_INDEX(ccs));
1689 RAY_ECF_START_CMD(sc);
1695 * Determine best antenna to use from rx level and antenna cache
1698 ray_tx_best_antenna(struct ray_softc *sc, u_int8_t *dst)
1700 struct ray_siglev *sl;
1704 RAY_DPRINTF(sc, RAY_DBG_SUBR | RAY_DBG_TX, "");
1706 if (sc->sc_version == RAY_ECFS_BUILD_4)
1709 /* try to find host */
1710 for (i = 0; i < RAY_NSIGLEVRECS; i++) {
1711 sl = &sc->sc_siglevs[i];
1712 if (bcmp(sl->rsl_host, dst, ETHER_ADDR_LEN) == 0)
1715 /* not found, return default setting */
1719 /* This is a simple thresholding scheme that takes the mean
1720 * of the best antenna history. This is okay but as it is a
1721 * filter, it adds a bit of lag in situations where the
1722 * best antenna swaps from one side to the other slowly. Don't know
1723 * how likely this is given the horrible fading though.
1726 for (i = 0; i < RAY_NANTENNA; i++) {
1727 antenna += sl->rsl_antennas[i];
1730 return (antenna > (RAY_NANTENNA >> 1));
1734 * Transmit now complete so clear ccs and network flags.
1737 ray_tx_done(struct ray_softc *sc, u_int8_t status, size_t ccs)
1739 struct ifnet *ifp = &sc->arpcom.ac_if;
1741 RAY_DPRINTF(sc, RAY_DBG_SUBR | RAY_DBG_TX, "");
1743 RAY_CCSERR(sc, status, if_oerrors);
1745 RAY_CCS_FREE(sc, ccs);
1747 if (ifp->if_flags & IFF_OACTIVE)
1748 ifp->if_flags &= ~IFF_OACTIVE;
1752 * Receiver packet handling
1756 * Receive a packet from the card
1759 ray_rx(struct ray_softc *sc, size_t rcs)
1761 struct ieee80211_frame *header;
1762 struct ifnet *ifp = &sc->arpcom.ac_if;
1764 size_t pktlen, fraglen, readlen, tmplen;
1766 u_int8_t siglev, antenna;
1770 RAY_DPRINTF(sc, RAY_DBG_SUBR, "");
1773 RAY_DPRINTF(sc, RAY_DBG_CCS, "using rcs 0x%x", rcs);
1779 * Get first part of packet and the length. Do some sanity checks
1782 first = RAY_CCS_INDEX(rcs);
1783 pktlen = SRAM_READ_FIELD_2(sc, rcs, ray_cmd_rx, c_pktlen);
1784 siglev = SRAM_READ_FIELD_1(sc, rcs, ray_cmd_rx, c_siglev);
1785 antenna = SRAM_READ_FIELD_1(sc, rcs, ray_cmd_rx, c_antenna);
1787 if ((pktlen > MCLBYTES) || (pktlen < sizeof(struct ieee80211_frame))) {
1788 RAY_RECERR(sc, "packet too big or too small");
1793 MGETHDR(m0, MB_DONTWAIT, MT_DATA);
1795 RAY_RECERR(sc, "MGETHDR failed");
1799 if (pktlen > MHLEN) {
1800 MCLGET(m0, MB_DONTWAIT);
1801 if (!(m0->m_flags & M_EXT)) {
1802 RAY_RECERR(sc, "MCLGET failed");
1809 m0->m_pkthdr.rcvif = ifp;
1810 m0->m_pkthdr.len = pktlen;
1812 mp = mtod(m0, u_int8_t *);
1815 * Walk the fragment chain to build the complete packet.
1817 * The use of two index variables removes a race with the
1818 * hardware. If one index were used the clearing of the CCS would
1819 * happen before reading the next pointer and the hardware can get in.
1820 * Not my idea but verbatim from the NetBSD driver.
1823 while ((i = ni) && (i != RAY_CCS_LINK_NULL)) {
1824 rcs = RAY_CCS_ADDRESS(i);
1825 ni = SRAM_READ_FIELD_1(sc, rcs, ray_cmd_rx, c_nextfrag);
1826 bufp = SRAM_READ_FIELD_2(sc, rcs, ray_cmd_rx, c_bufp);
1827 fraglen = SRAM_READ_FIELD_2(sc, rcs, ray_cmd_rx, c_len);
1828 if (fraglen + readlen > pktlen) {
1829 RAY_RECERR(sc, "bad length current 0x%x pktlen 0x%x",
1830 fraglen + readlen, pktlen);
1836 if ((i < RAY_RCS_FIRST) || (i > RAY_RCS_LAST)) {
1837 RAY_RECERR(sc, "bad rcs index 0x%x", i);
1844 ebufp = bufp + fraglen;
1845 if (ebufp <= RAY_RX_END)
1846 SRAM_READ_REGION(sc, bufp, mp, fraglen);
1848 SRAM_READ_REGION(sc, bufp, mp,
1849 (tmplen = RAY_RX_END - bufp));
1850 SRAM_READ_REGION(sc, RAY_RX_BASE, mp + tmplen,
1851 ebufp - RAY_RX_END);
1860 * Walk the chain again to free the rcss.
1863 while ((i = ni) && (i != RAY_CCS_LINK_NULL)) {
1864 rcs = RAY_CCS_ADDRESS(i);
1865 ni = SRAM_READ_FIELD_1(sc, rcs, ray_cmd_rx, c_nextfrag);
1866 RAY_CCS_FREE(sc, rcs);
1873 * Check the 802.11 packet type and hand off to
1874 * appropriate functions.
1876 header = mtod(m0, struct ieee80211_frame *);
1877 if ((header->i_fc[0] & IEEE80211_FC0_VERSION_MASK)
1878 != IEEE80211_FC0_VERSION_0) {
1879 RAY_RECERR(sc, "header not version 0 fc0 0x%x",
1885 switch (header->i_fc[0] & IEEE80211_FC0_TYPE_MASK) {
1887 case IEEE80211_FC0_TYPE_DATA:
1888 ray_rx_data(sc, m0, siglev, antenna);
1891 case IEEE80211_FC0_TYPE_MGT:
1895 case IEEE80211_FC0_TYPE_CTL:
1900 RAY_RECERR(sc, "unknown packet fc0 0x%x", header->i_fc[0]);
1907 * Deal with DATA packet types
1910 ray_rx_data(struct ray_softc *sc, struct mbuf *m0, u_int8_t siglev, u_int8_t antenna)
1912 struct ifnet *ifp = &sc->arpcom.ac_if;
1913 struct ieee80211_frame *header = mtod(m0, struct ieee80211_frame *);
1914 struct ether_header *eh;
1916 u_int8_t *sa = NULL, *da = NULL, *ra = NULL, *ta = NULL;
1919 RAY_DPRINTF(sc, RAY_DBG_SUBR | RAY_DBG_RX, "");
1922 * Check the the data packet subtype, some packets have
1923 * nothing in them so we will drop them here.
1925 switch (header->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK) {
1927 case IEEE80211_FC0_SUBTYPE_DATA:
1928 case IEEE80211_FC0_SUBTYPE_CF_ACK:
1929 case IEEE80211_FC0_SUBTYPE_CF_POLL:
1930 case IEEE80211_FC0_SUBTYPE_CF_ACPL:
1931 RAY_DPRINTF(sc, RAY_DBG_RX, "DATA packet");
1934 case IEEE80211_FC0_SUBTYPE_NODATA:
1935 case IEEE80211_FC0_SUBTYPE_CFACK:
1936 case IEEE80211_FC0_SUBTYPE_CFPOLL:
1937 case IEEE80211_FC0_SUBTYPE_CF_ACK_CF_ACK:
1938 RAY_DPRINTF(sc, RAY_DBG_RX, "NULL packet");
1944 RAY_RECERR(sc, "reserved DATA packet subtype 0x%x",
1945 header->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK);
1952 * Parse the To DS and From DS fields to determine the length
1953 * of the 802.11 header for use later on.
1955 * Additionally, furtle out the right destination and
1956 * source MAC addresses for the packet. Packets may come via
1957 * APs so the MAC addresses of the immediate node may be
1958 * different from the node that actually sent us the packet.
1960 * da destination address of final recipient
1961 * sa source address of orginator
1962 * ra receiver address of immediate recipient
1963 * ta transmitter address of immediate orginator
1965 * Address matching is performed on da or sa with the AP or
1966 * BSSID in ra and ta.
1968 RAY_MBUF_DUMP(sc, RAY_DBG_RX, m0, "(1) packet before framing");
1969 switch (header->i_fc[1] & IEEE80211_FC1_DIR_MASK) {
1971 case IEEE80211_FC1_DIR_NODS:
1972 da = ra = header->i_addr1;
1973 sa = ta = header->i_addr2;
1974 trim = sizeof(struct ieee80211_frame);
1975 RAY_DPRINTF(sc, RAY_DBG_RX, "from %6D to %6D",
1979 case IEEE80211_FC1_DIR_FROMDS:
1980 da = ra = header->i_addr1;
1981 ta = header->i_addr2;
1982 sa = header->i_addr3;
1983 trim = sizeof(struct ieee80211_frame);
1984 RAY_DPRINTF(sc, RAY_DBG_RX, "ap %6D from %6D to %6D",
1985 ta, ":", sa, ":", da, ":");
1988 case IEEE80211_FC1_DIR_TODS:
1989 ra = header->i_addr1;
1990 sa = ta = header->i_addr2;
1991 da = header->i_addr3;
1992 trim = sizeof(struct ieee80211_frame);
1993 RAY_DPRINTF(sc, RAY_DBG_RX, "from %6D to %6D ap %6D",
1994 sa, ":", da, ":", ra, ":");
1997 case IEEE80211_FC1_DIR_DSTODS:
1998 ra = header->i_addr1;
1999 ta = header->i_addr2;
2000 da = header->i_addr3;
2001 sa = (u_int8_t *)header+1;
2002 trim = sizeof(struct ieee80211_frame) + ETHER_ADDR_LEN;
2003 RAY_DPRINTF(sc, RAY_DBG_RX, "from %6D to %6D ap %6D to %6D",
2004 sa, ":", da, ":", ta, ":", ra, ":");
2011 * Each case must leave an Ethernet header and adjust trim.
2013 switch (sc->sc_c.np_framing) {
2015 case RAY_FRAMING_ENCAPSULATION:
2016 /* A NOP as the Ethernet header is in the packet */
2019 case RAY_FRAMING_TRANSLATION:
2020 /* Check that we have an LLC and SNAP sequence */
2021 llc = (struct llc *)((u_int8_t *)header + trim);
2022 if (llc->llc_dsap == LLC_SNAP_LSAP &&
2023 llc->llc_ssap == LLC_SNAP_LSAP &&
2024 llc->llc_control == LLC_UI &&
2025 llc->llc_un.type_snap.org_code[0] == 0 &&
2026 llc->llc_un.type_snap.org_code[1] == 0 &&
2027 llc->llc_un.type_snap.org_code[2] == 0) {
2029 * This is not magic. RFC1042 header is 8
2030 * bytes, with the last two bytes being the
2031 * ether type. So all we need is another
2032 * ETHER_ADDR_LEN bytes to write the
2035 trim -= ETHER_ADDR_LEN;
2036 eh = (struct ether_header *)((u_int8_t *)header + trim);
2039 * Copy carefully to avoid mashing the MAC
2040 * addresses. The address layout in the .11 header
2041 * does make sense, honest, but it is a pain.
2043 * NODS da sa no risk
2044 * FROMDS da ta sa sa then da
2045 * DSTODS ra ta da sa sa then da
2046 * TODS ra sa da da then sa
2050 bcopy(sa, eh->ether_shost, ETHER_ADDR_LEN);
2051 bcopy(da, eh->ether_dhost, ETHER_ADDR_LEN);
2054 bcopy(da, eh->ether_dhost, ETHER_ADDR_LEN);
2055 bcopy(sa, eh->ether_shost, ETHER_ADDR_LEN);
2060 /* Assume RAY_FRAMING_ENCAPSULATION */
2062 "got encapsulated packet but in translation mode");
2068 RAY_RECERR(sc, "unknown framing type %d", sc->sc_c.np_framing);
2073 RAY_MBUF_DUMP(sc, RAY_DBG_RX, m0, "(2) packet after framing");
2076 * Finally, do a bit of house keeping before sending the packet
2080 RAY_MBUF_DUMP(sc, RAY_DBG_RX, m0, "(3) packet after trimming");
2082 ray_rx_update_cache(sc, header->i_addr2, siglev, antenna);
2083 (*ifp->if_input)(ifp, m0);
2087 * Deal with MGT packet types
2090 ray_rx_mgt(struct ray_softc *sc, struct mbuf *m0)
2092 struct ifnet *ifp = &sc->arpcom.ac_if;
2093 struct ieee80211_frame *header = mtod(m0, struct ieee80211_frame *);
2095 RAY_DPRINTF(sc, RAY_DBG_SUBR | RAY_DBG_MGT, "");
2097 if ((header->i_fc[1] & IEEE80211_FC1_DIR_MASK) !=
2098 IEEE80211_FC1_DIR_NODS) {
2099 RAY_RECERR(sc, "MGT TODS/FROMDS wrong fc1 0x%x",
2100 header->i_fc[1] & IEEE80211_FC1_DIR_MASK);
2107 * Check the the mgt packet subtype, some packets should be
2108 * dropped depending on the mode the station is in. See pg
2111 * P - proccess, J - Junk, E - ECF deals with, I - Illegal
2113 * AHDOC procces or junk
2114 * INFRA STA process or junk
2115 * INFRA AP process or jumk
2117 * +PPP IEEE80211_FC0_SUBTYPE_BEACON
2118 * +EEE IEEE80211_FC0_SUBTYPE_PROBE_REQ
2119 * +EEE IEEE80211_FC0_SUBTYPE_PROBE_RESP
2120 * PPP IEEE80211_FC0_SUBTYPE_AUTH
2121 * PPP IEEE80211_FC0_SUBTYPE_DEAUTH
2122 * JJP IEEE80211_FC0_SUBTYPE_ASSOC_REQ
2123 * JPJ IEEE80211_FC0_SUBTYPE_ASSOC_RESP
2124 * JPP IEEE80211_FC0_SUBTYPE_DISASSOC
2125 * JJP IEEE80211_FC0_SUBTYPE_REASSOC_REQ
2126 * JPJ IEEE80211_FC0_SUBTYPE_REASSOC_RESP
2127 * +EEE IEEE80211_FC0_SUBTYPE_ATIM
2129 RAY_MBUF_DUMP(sc, RAY_DBG_MGT, m0, "MGT packet");
2130 switch (header->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK) {
2132 case IEEE80211_FC0_SUBTYPE_BEACON:
2133 RAY_DPRINTF(sc, RAY_DBG_MGT, "BEACON MGT packet");
2134 ray_rx_mgt_beacon(sc, m0);
2137 case IEEE80211_FC0_SUBTYPE_AUTH:
2138 RAY_DPRINTF(sc, RAY_DBG_MGT, "AUTH MGT packet");
2139 ray_rx_mgt_auth(sc, m0);
2142 case IEEE80211_FC0_SUBTYPE_DEAUTH:
2143 RAY_DPRINTF(sc, RAY_DBG_MGT, "DEAUTH MGT packet");
2144 /* XXX ray_rx_mgt_deauth(sc, m0); */
2147 case IEEE80211_FC0_SUBTYPE_ASSOC_REQ:
2148 case IEEE80211_FC0_SUBTYPE_REASSOC_REQ:
2149 RAY_DPRINTF(sc, RAY_DBG_MGT, "(RE)ASSOC_REQ MGT packet");
2150 if ((sc->sc_c.np_net_type == RAY_MIB_NET_TYPE_INFRA) &&
2151 (sc->sc_c.np_ap_status == RAY_MIB_AP_STATUS_AP))
2152 RAY_RECERR(sc, "can't be an AP yet"); /* XXX_ACTING_AP */
2155 case IEEE80211_FC0_SUBTYPE_ASSOC_RESP:
2156 case IEEE80211_FC0_SUBTYPE_REASSOC_RESP:
2157 RAY_DPRINTF(sc, RAY_DBG_MGT, "(RE)ASSOC_RESP MGT packet");
2158 if ((sc->sc_c.np_net_type == RAY_MIB_NET_TYPE_INFRA) &&
2159 (sc->sc_c.np_ap_status == RAY_MIB_AP_STATUS_TERMINAL))
2160 RAY_RECERR(sc, "can't be in INFRA yet"); /* XXX_INFRA */
2163 case IEEE80211_FC0_SUBTYPE_DISASSOC:
2164 RAY_DPRINTF(sc, RAY_DBG_MGT, "DISASSOC MGT packet");
2165 if (sc->sc_c.np_net_type == RAY_MIB_NET_TYPE_INFRA)
2166 RAY_RECERR(sc, "can't be in INFRA yet"); /* XXX_INFRA */
2169 case IEEE80211_FC0_SUBTYPE_PROBE_REQ:
2170 case IEEE80211_FC0_SUBTYPE_PROBE_RESP:
2171 case IEEE80211_FC0_SUBTYPE_ATIM:
2172 RAY_RECERR(sc, "unexpected MGT packet subtype 0x%0x",
2173 header->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK);
2178 RAY_RECERR(sc, "reserved MGT packet subtype 0x%x",
2179 header->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK);
2187 * Deal with BEACON management packet types
2188 * XXX furtle anything interesting out
2189 * XXX Note that there are rules governing what beacons to read
2190 * XXX see 8802 S7.2.3, S11.1.2.3
2191 * XXX is this actually useful?
2194 ray_rx_mgt_beacon(struct ray_softc *sc, struct mbuf *m0)
2196 struct ieee80211_frame *header = mtod(m0, struct ieee80211_frame *);
2197 ieee80211_mgt_beacon_t beacon = (u_int8_t *)(header+1);
2198 struct ieee80211_information elements;
2200 u_int64_t *timestamp;
2202 RAY_DPRINTF(sc, RAY_DBG_SUBR | RAY_DBG_MGT, "");
2204 timestamp = (u_int64_t *)beacon;
2206 RAY_DPRINTF(sc, RAY_DBG_MGT, "timestamp\t0x%x", *timestamp);
2207 RAY_DPRINTF(sc, RAY_DBG_MGT, "interval\t\t0x%x", IEEE80211_BEACON_INTERVAL(beacon));
2208 RAY_DPRINTF(sc, RAY_DBG_MGT, "capability\t0x%x", IEEE80211_BEACON_CAPABILITY(beacon));
2210 ray_rx_mgt_info(sc, m0, &elements);
2215 ray_rx_mgt_info(struct ray_softc *sc, struct mbuf *m0, struct ieee80211_information *elements)
2217 struct ifnet *ifp = &sc->arpcom.ac_if;
2218 struct ieee80211_frame *header = mtod(m0, struct ieee80211_frame *);
2219 ieee80211_mgt_beacon_t beacon = (u_int8_t *)(header+1);
2220 ieee80211_mgt_beacon_t bp, be;
2223 RAY_DPRINTF(sc, RAY_DBG_SUBR | RAY_DBG_MGT, "");
2226 be = mtod(m0, u_int8_t *) + m0->m_len;
2230 RAY_DPRINTF(sc, RAY_DBG_MGT, "id 0x%02x length %d", *bp, len);
2234 case IEEE80211_ELEMID_SSID:
2235 if (len > IEEE80211_NWID_LEN) {
2236 RAY_RECERR(sc, "bad SSD length: %d from %6D",
2237 len, header->i_addr2, ":");
2239 strncpy(elements->ssid, bp + 2, len);
2240 elements->ssid[len] = 0;
2241 RAY_DPRINTF(sc, RAY_DBG_MGT,
2242 "beacon ssid %s", elements->ssid);
2245 case IEEE80211_ELEMID_RATES:
2246 RAY_DPRINTF(sc, RAY_DBG_MGT, "rates");
2249 case IEEE80211_ELEMID_FHPARMS:
2250 elements->fh.dwell = bp[2] + (bp[3] << 8);
2251 elements->fh.set = bp[4];
2252 elements->fh.pattern = bp[5];
2253 elements->fh.index = bp[6];
2254 RAY_DPRINTF(sc, RAY_DBG_MGT,
2255 "fhparams dwell\t0x%04x", elements->fh.dwell);
2256 RAY_DPRINTF(sc, RAY_DBG_MGT,
2257 "fhparams set\t0x%02x", elements->fh.set);
2258 RAY_DPRINTF(sc, RAY_DBG_MGT,
2259 "fhparams pattern\t0x%02x", elements->fh.pattern);
2260 RAY_DPRINTF(sc, RAY_DBG_MGT,
2261 "fhparams index\t0x%02x", elements->fh.index);
2264 case IEEE80211_ELEMID_DSPARMS:
2265 RAY_RECERR(sc, "got direct sequence params!");
2268 case IEEE80211_ELEMID_CFPARMS:
2269 RAY_DPRINTF(sc, RAY_DBG_MGT, "cfparams");
2272 case IEEE80211_ELEMID_TIM:
2273 elements->tim.count = bp[2];
2274 elements->tim.period = bp[3];
2275 elements->tim.bitctl = bp[4];
2276 RAY_DPRINTF(sc, RAY_DBG_MGT,
2277 "tim count\t0x%02x", elements->tim.count);
2278 RAY_DPRINTF(sc, RAY_DBG_MGT,
2279 "tim period\t0x%02x", elements->tim.period);
2280 RAY_DPRINTF(sc, RAY_DBG_MGT,
2281 "tim bitctl\t0x%02x", elements->tim.bitctl);
2282 #if RAY_DEBUG & RAY_DBG_MGT
2285 for (i = 5; i < len + 1; i++)
2286 RAY_DPRINTF(sc, RAY_DBG_MGT,
2287 "tim pvt[%03d]\t0x%02x", i-5, bp[i]);
2292 case IEEE80211_ELEMID_IBSSPARMS:
2293 elements->ibss.atim = bp[2] + (bp[3] << 8);
2294 RAY_DPRINTF(sc, RAY_DBG_MGT,
2295 "ibssparams atim\t0x%02x", elements->ibss.atim);
2298 case IEEE80211_ELEMID_CHALLENGE:
2299 RAY_DPRINTF(sc, RAY_DBG_MGT, "challenge");
2303 RAY_RECERR(sc, "reserved MGT element id 0x%x", *bp);
2304 ifp->if_ierrors++;break;
2311 * Deal with AUTH management packet types
2314 ray_rx_mgt_auth(struct ray_softc *sc, struct mbuf *m0)
2316 struct ieee80211_frame *header = mtod(m0, struct ieee80211_frame *);
2317 ieee80211_mgt_auth_t auth = (u_int8_t *)(header+1);
2319 RAY_DPRINTF(sc, RAY_DBG_SUBR | RAY_DBG_AUTH, "");
2321 switch (IEEE80211_AUTH_ALGORITHM(auth)) {
2323 case IEEE80211_AUTH_ALG_OPEN:
2324 RAY_DPRINTF(sc, RAY_DBG_AUTH,
2325 "open system authentication sequence number %d",
2326 IEEE80211_AUTH_TRANSACTION(auth));
2327 if (IEEE80211_AUTH_TRANSACTION(auth) ==
2328 IEEE80211_AUTH_OPEN_REQUEST) {
2330 /* XXX_AUTH use ray_init_auth_send */
2332 } else if (IEEE80211_AUTH_TRANSACTION(auth) ==
2333 IEEE80211_AUTH_OPEN_RESPONSE)
2334 ray_init_auth_done(sc, IEEE80211_AUTH_STATUS(auth));
2337 case IEEE80211_AUTH_ALG_SHARED:
2339 "shared key authentication sequence number %d",
2340 IEEE80211_AUTH_TRANSACTION(auth));
2345 "reserved authentication subtype 0x%04hx",
2346 IEEE80211_AUTH_ALGORITHM(auth));
2352 * Deal with CTL packet types
2355 ray_rx_ctl(struct ray_softc *sc, struct mbuf *m0)
2357 struct ifnet *ifp = &sc->arpcom.ac_if;
2358 struct ieee80211_frame *header = mtod(m0, struct ieee80211_frame *);
2360 RAY_DPRINTF(sc, RAY_DBG_SUBR | RAY_DBG_CTL, "");
2362 if ((header->i_fc[1] & IEEE80211_FC1_DIR_MASK) !=
2363 IEEE80211_FC1_DIR_NODS) {
2364 RAY_RECERR(sc, "CTL TODS/FROMDS wrong fc1 0x%x",
2365 header->i_fc[1] & IEEE80211_FC1_DIR_MASK);
2372 * Check the the ctl packet subtype, some packets should be
2373 * dropped depending on the mode the station is in. The ECF
2374 * should deal with everything but the power save poll to an
2375 * AP. See pg 52(60) of docs.
2377 RAY_MBUF_DUMP(sc, RAY_DBG_CTL, m0, "CTL packet");
2378 switch (header->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK) {
2380 case IEEE80211_FC0_SUBTYPE_PS_POLL:
2381 RAY_DPRINTF(sc, RAY_DBG_CTL, "PS_POLL CTL packet");
2382 if ((sc->sc_d.np_net_type == RAY_MIB_NET_TYPE_INFRA) &&
2383 (sc->sc_c.np_ap_status == RAY_MIB_AP_STATUS_AP))
2384 RAY_RECERR(sc, "can't be an AP yet"); /* XXX_ACTING_AP */
2387 case IEEE80211_FC0_SUBTYPE_RTS:
2388 case IEEE80211_FC0_SUBTYPE_CTS:
2389 case IEEE80211_FC0_SUBTYPE_ACK:
2390 case IEEE80211_FC0_SUBTYPE_CF_END:
2391 case IEEE80211_FC0_SUBTYPE_CF_END_ACK:
2392 RAY_RECERR(sc, "unexpected CTL packet subtype 0x%0x",
2393 header->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK);
2398 RAY_RECERR(sc, "reserved CTL packet subtype 0x%x",
2399 header->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK);
2407 * Update rx level and antenna cache
2410 ray_rx_update_cache(struct ray_softc *sc, u_int8_t *src, u_int8_t siglev, u_int8_t antenna)
2412 struct timeval mint;
2413 struct ray_siglev *sl;
2416 RAY_DPRINTF(sc, RAY_DBG_SUBR, "");
2418 /* Try to find host */
2419 for (i = 0; i < RAY_NSIGLEVRECS; i++) {
2420 sl = &sc->sc_siglevs[i];
2421 if (bcmp(sl->rsl_host, src, ETHER_ADDR_LEN) == 0)
2424 /* Not found, find oldest slot */
2426 mint.tv_sec = LONG_MAX;
2428 for (i = 0; i < RAY_NSIGLEVRECS; i++) {
2429 sl = &sc->sc_siglevs[i];
2430 if (timevalcmp(&sl->rsl_time, &mint, <)) {
2432 mint = sl->rsl_time;
2435 sl = &sc->sc_siglevs[mini];
2436 bzero(sl->rsl_siglevs, RAY_NSIGLEV);
2437 bzero(sl->rsl_antennas, RAY_NANTENNA);
2438 bcopy(src, sl->rsl_host, ETHER_ADDR_LEN);
2441 microtime(&sl->rsl_time);
2442 bcopy(sl->rsl_siglevs, &sl->rsl_siglevs[1], RAY_NSIGLEV-1);
2443 sl->rsl_siglevs[0] = siglev;
2444 if (sc->sc_version != RAY_ECFS_BUILD_4) {
2445 bcopy(sl->rsl_antennas, &sl->rsl_antennas[1], RAY_NANTENNA-1);
2446 sl->rsl_antennas[0] = antenna;
2451 * Interrupt handling
2455 * Process an interrupt
2460 struct ray_softc *sc = (struct ray_softc *)xsc;
2461 struct ifnet *ifp = &sc->arpcom.ac_if;
2463 u_int8_t cmd, status;
2466 RAY_DPRINTF(sc, RAY_DBG_SUBR, "");
2469 if ((sc == NULL) || (sc->sc_gone))
2473 * Check that the interrupt was for us, if so get the rcs/ccs
2474 * and vector on the command contained within it.
2476 if (RAY_HCS_INTR(sc)) {
2477 ccsi = SRAM_READ_1(sc, RAY_SCB_RCSI);
2478 ccs = RAY_CCS_ADDRESS(ccsi);
2479 cmd = SRAM_READ_FIELD_1(sc, ccs, ray_cmd, c_cmd);
2480 status = SRAM_READ_FIELD_1(sc, ccs, ray_cmd, c_status);
2481 if (ccsi <= RAY_CCS_LAST)
2482 ray_intr_ccs(sc, cmd, status, ccs);
2483 else if (ccsi <= RAY_RCS_LAST)
2484 ray_intr_rcs(sc, cmd, ccs);
2486 RAY_RECERR(sc, "bad ccs index 0x%x", ccsi);
2487 RAY_HCS_CLEAR_INTR(sc);
2490 /* Send any packets lying around and update error counters */
2491 if (!(ifp->if_flags & IFF_OACTIVE) && (ifp->if_snd.ifq_head != NULL))
2493 if ((++sc->sc_checkcounters % 32) == 0)
2494 ray_intr_updt_errcntrs(sc);
2498 * Read the error counters.
2501 ray_intr_updt_errcntrs(struct ray_softc *sc)
2505 RAY_DPRINTF(sc, RAY_DBG_SUBR, "");
2509 * The card implements the following protocol to keep the
2510 * values from being changed while read: It checks the `own'
2511 * bit and if zero writes the current internal counter value,
2512 * it then sets the `own' bit to 1. If the `own' bit was 1 it
2513 * incremenets its internal counter. The user thus reads the
2514 * counter if the `own' bit is one and then sets the own bit
2517 csc = RAY_STATUS_BASE;
2518 if (SRAM_READ_FIELD_1(sc, csc, ray_csc, csc_mrxo_own)) {
2519 sc->sc_rxoverflow +=
2520 SRAM_READ_FIELD_2(sc, csc, ray_csc, csc_mrx_overflow);
2521 SRAM_WRITE_FIELD_1(sc, csc, ray_csc, csc_mrxo_own, 0);
2523 if (SRAM_READ_FIELD_1(sc, csc, ray_csc, csc_mrxc_own)) {
2525 SRAM_READ_FIELD_2(sc, csc, ray_csc, csc_mrx_overflow);
2526 SRAM_WRITE_FIELD_1(sc, csc, ray_csc, csc_mrxc_own, 0);
2528 if (SRAM_READ_FIELD_1(sc, csc, ray_csc, csc_rxhc_own)) {
2530 SRAM_READ_FIELD_2(sc, csc, ray_csc, csc_rx_hcksum);
2531 SRAM_WRITE_FIELD_1(sc, csc, ray_csc, csc_rxhc_own, 0);
2533 sc->sc_rxnoise = SRAM_READ_FIELD_1(sc, csc, ray_csc, csc_rx_noise);
2537 * Process CCS command completion
2540 ray_intr_ccs(struct ray_softc *sc, u_int8_t cmd, u_int8_t status, size_t ccs)
2542 RAY_DPRINTF(sc, RAY_DBG_SUBR, "");
2546 case RAY_CMD_DOWNLOAD_PARAMS:
2547 RAY_DPRINTF(sc, RAY_DBG_COM, "START_PARAMS");
2548 ray_init_download_done(sc, status, ccs);
2551 case RAY_CMD_UPDATE_PARAMS:
2552 RAY_DPRINTF(sc, RAY_DBG_COM, "UPDATE_PARAMS");
2553 ray_upparams_done(sc, status, ccs);
2556 case RAY_CMD_REPORT_PARAMS:
2557 RAY_DPRINTF(sc, RAY_DBG_COM, "REPORT_PARAMS");
2558 ray_repparams_done(sc, status, ccs);
2561 case RAY_CMD_UPDATE_MCAST:
2562 RAY_DPRINTF(sc, RAY_DBG_COM, "UPDATE_MCAST");
2563 ray_mcast_done(sc, status, ccs);
2566 case RAY_CMD_START_NET:
2567 case RAY_CMD_JOIN_NET:
2568 RAY_DPRINTF(sc, RAY_DBG_COM, "START|JOIN_NET");
2569 ray_init_sj_done(sc, status, ccs);
2572 case RAY_CMD_TX_REQ:
2573 RAY_DPRINTF(sc, RAY_DBG_COM, "TX_REQ");
2574 ray_tx_done(sc, status, ccs);
2577 case RAY_CMD_START_ASSOC:
2578 RAY_DPRINTF(sc, RAY_DBG_COM, "START_ASSOC");
2579 ray_init_assoc_done(sc, status, ccs);
2582 case RAY_CMD_UPDATE_APM:
2583 RAY_RECERR(sc, "unexpected UPDATE_APM");
2586 case RAY_CMD_TEST_MEM:
2587 RAY_RECERR(sc, "unexpected TEST_MEM");
2590 case RAY_CMD_SHUTDOWN:
2591 RAY_RECERR(sc, "unexpected SHUTDOWN");
2594 case RAY_CMD_DUMP_MEM:
2595 RAY_RECERR(sc, "unexpected DUMP_MEM");
2598 case RAY_CMD_START_TIMER:
2599 RAY_RECERR(sc, "unexpected START_TIMER");
2603 RAY_RECERR(sc, "unknown command 0x%x", cmd);
2609 * Process ECF command request
2612 ray_intr_rcs(struct ray_softc *sc, u_int8_t cmd, size_t rcs)
2614 RAY_DPRINTF(sc, RAY_DBG_SUBR, "");
2618 case RAY_ECMD_RX_DONE:
2619 RAY_DPRINTF(sc, RAY_DBG_RX, "RX_DONE");
2623 case RAY_ECMD_REJOIN_DONE:
2624 RAY_DPRINTF(sc, RAY_DBG_RX, "REJOIN_DONE");
2625 sc->sc_c.np_havenet = 1; /* XXX Should not be here but in function */
2628 case RAY_ECMD_ROAM_START:
2629 RAY_DPRINTF(sc, RAY_DBG_RX, "ROAM_START");
2630 sc->sc_c.np_havenet = 0; /* XXX Should not be here but in function */
2633 case RAY_ECMD_JAPAN_CALL_SIGNAL:
2634 RAY_RECERR(sc, "unexpected JAPAN_CALL_SIGNAL");
2638 RAY_RECERR(sc, "unknown command 0x%x", cmd);
2642 RAY_CCS_FREE(sc, rcs);
2646 * User land entry to multicast list changes
2649 ray_mcast_user(struct ray_softc *sc)
2651 struct ray_comq_entry *com[2];
2654 RAY_DPRINTF(sc, RAY_DBG_SUBR, "");
2657 * Do all checking in the runq to preserve ordering.
2659 * We run promisc to pick up changes to the ALL_MULTI
2663 com[ncom++] = RAY_COM_MALLOC(ray_mcast, 0);
2664 com[ncom++] = RAY_COM_MALLOC(ray_promisc, 0);
2666 RAY_COM_RUNQ(sc, com, ncom, "raymcast", error);
2668 /* XXX no real error processing from anything yet! */
2670 RAY_COM_FREE(com, ncom);
2676 * Runq entry to setting the multicast filter list
2678 * MUST always be followed by a call to ray_promisc to pick up changes
2682 ray_mcast(struct ray_softc *sc, struct ray_comq_entry *com)
2684 struct ifnet *ifp = &sc->arpcom.ac_if;
2685 struct ifmultiaddr *ifma;
2689 RAY_DPRINTF(sc, RAY_DBG_SUBR, "");
2693 * If card is not running we don't need to update this.
2695 if (!(ifp->if_flags & IFF_RUNNING)) {
2696 RAY_DPRINTF(sc, RAY_DBG_IOCTL, "not running");
2697 ray_com_runq_done(sc);
2702 * The multicast list is only 16 items long so use promiscuous
2703 * mode and don't bother updating the multicast list.
2705 for (ifma = ifp->if_multiaddrs.lh_first; ifma != NULL;
2706 ifma = ifma->ifma_link.le_next)
2709 ray_com_runq_done(sc);
2711 } else if (count > 16) {
2712 ifp->if_flags |= IFF_ALLMULTI;
2713 ray_com_runq_done(sc);
2715 } else if (ifp->if_flags & IFF_ALLMULTI)
2716 ifp->if_flags &= ~IFF_ALLMULTI;
2721 ray_ccs_fill(sc, com->c_ccs, RAY_CMD_UPDATE_MCAST);
2722 SRAM_WRITE_FIELD_1(sc, com->c_ccs,
2723 ray_cmd_update_mcast, c_nmcast, count);
2724 bufp = RAY_HOST_TO_ECF_BASE;
2725 for (ifma = ifp->if_multiaddrs.lh_first; ifma != NULL;
2726 ifma = ifma->ifma_link.le_next) {
2730 LLADDR((struct sockaddr_dl *)ifma->ifma_addr),
2733 bufp += ETHER_ADDR_LEN;
2736 ray_com_ecf(sc, com);
2740 * Complete the multicast filter list update
2743 ray_mcast_done(struct ray_softc *sc, u_int8_t status, size_t ccs)
2745 RAY_DPRINTF(sc, RAY_DBG_SUBR | RAY_DBG_STARTJOIN, "");
2746 RAY_COM_CHECK(sc, ccs);
2748 RAY_CCSERR(sc, status, if_oerrors); /* XXX error counter */
2750 ray_com_ecf_done(sc);
2754 * Runq entry to set/reset promiscuous mode
2757 ray_promisc(struct ray_softc *sc, struct ray_comq_entry *com)
2759 struct ifnet *ifp = &sc->arpcom.ac_if;
2761 RAY_DPRINTF(sc, RAY_DBG_SUBR, "");
2765 * If card not running or we already have the right flags
2766 * we don't need to update this
2768 sc->sc_d.np_promisc = !!(ifp->if_flags & (IFF_PROMISC | IFF_ALLMULTI));
2769 if (!(ifp->if_flags & IFF_RUNNING) ||
2770 (sc->sc_c.np_promisc == sc->sc_d.np_promisc)) {
2771 ray_com_runq_done(sc);
2778 ray_ccs_fill(sc, com->c_ccs, RAY_CMD_UPDATE_PARAMS);
2779 SRAM_WRITE_FIELD_1(sc, com->c_ccs,
2780 ray_cmd_update, c_paramid, RAY_MIB_PROMISC);
2781 SRAM_WRITE_FIELD_1(sc, com->c_ccs, ray_cmd_update, c_nparam, 1);
2782 SRAM_WRITE_1(sc, RAY_HOST_TO_ECF_BASE, sc->sc_d.np_promisc);
2784 ray_com_ecf(sc, com);
2788 * User land entry to parameter reporting
2790 * As we by pass the runq to report current parameters this function
2791 * only provides a snap shot of the driver's state.
2794 ray_repparams_user(struct ray_softc *sc, struct ray_param_req *pr)
2796 struct ray_comq_entry *com[1];
2799 RAY_DPRINTF(sc, RAY_DBG_SUBR, "");
2802 * Test for illegal values or immediate responses
2804 if (pr->r_paramid > RAY_MIB_MAX)
2806 if ((sc->sc_version == RAY_ECFS_BUILD_4) &&
2807 !(mib_info[pr->r_paramid][0] & RAY_V4))
2809 if ((sc->sc_version == RAY_ECFS_BUILD_5) &&
2810 !(mib_info[pr->r_paramid][0] & RAY_V5))
2812 if (pr->r_paramid > RAY_MIB_LASTUSER) {
2813 switch (pr->r_paramid) {
2815 case RAY_MIB_VERSION:
2816 if (sc->sc_version == RAY_ECFS_BUILD_4)
2817 *pr->r_data = RAY_V4;
2819 *pr->r_data = RAY_V5;
2821 case RAY_MIB_CUR_BSSID:
2822 bcopy(sc->sc_c.np_bss_id, pr->r_data, ETHER_ADDR_LEN);
2824 case RAY_MIB_CUR_INITED:
2825 *pr->r_data = sc->sc_c.np_inited;
2827 case RAY_MIB_CUR_DEF_TXRATE:
2828 *pr->r_data = sc->sc_c.np_def_txrate;
2830 case RAY_MIB_CUR_ENCRYPT:
2831 *pr->r_data = sc->sc_c.np_encrypt;
2833 case RAY_MIB_CUR_NET_TYPE:
2834 *pr->r_data = sc->sc_c.np_net_type;
2836 case RAY_MIB_CUR_SSID:
2837 bcopy(sc->sc_c.np_ssid, pr->r_data, IEEE80211_NWID_LEN);
2839 case RAY_MIB_CUR_PRIV_START:
2840 *pr->r_data = sc->sc_c.np_priv_start;
2842 case RAY_MIB_CUR_PRIV_JOIN:
2843 *pr->r_data = sc->sc_c.np_priv_join;
2845 case RAY_MIB_DES_BSSID:
2846 bcopy(sc->sc_d.np_bss_id, pr->r_data, ETHER_ADDR_LEN);
2848 case RAY_MIB_DES_INITED:
2849 *pr->r_data = sc->sc_d.np_inited;
2851 case RAY_MIB_DES_DEF_TXRATE:
2852 *pr->r_data = sc->sc_d.np_def_txrate;
2854 case RAY_MIB_DES_ENCRYPT:
2855 *pr->r_data = sc->sc_d.np_encrypt;
2857 case RAY_MIB_DES_NET_TYPE:
2858 *pr->r_data = sc->sc_d.np_net_type;
2860 case RAY_MIB_DES_SSID:
2861 bcopy(sc->sc_d.np_ssid, pr->r_data, IEEE80211_NWID_LEN);
2863 case RAY_MIB_DES_PRIV_START:
2864 *pr->r_data = sc->sc_d.np_priv_start;
2866 case RAY_MIB_DES_PRIV_JOIN:
2867 *pr->r_data = sc->sc_d.np_priv_join;
2869 case RAY_MIB_CUR_AP_STATUS:
2870 *pr->r_data = sc->sc_c.np_ap_status;
2872 case RAY_MIB_CUR_PROMISC:
2873 *pr->r_data = sc->sc_c.np_promisc;
2875 case RAY_MIB_DES_AP_STATUS:
2876 *pr->r_data = sc->sc_d.np_ap_status;
2878 case RAY_MIB_DES_PROMISC:
2879 *pr->r_data = sc->sc_d.np_promisc;
2881 case RAY_MIB_CUR_FRAMING:
2882 *pr->r_data = sc->sc_c.np_framing;
2884 case RAY_MIB_DES_FRAMING:
2885 *pr->r_data = sc->sc_d.np_framing;
2892 pr->r_failcause = 0;
2893 if (sc->sc_version == RAY_ECFS_BUILD_4)
2894 pr->r_len = mib_info[pr->r_paramid][RAY_MIB_INFO_SIZ4];
2895 else if (sc->sc_version == RAY_ECFS_BUILD_5)
2896 pr->r_len = mib_info[pr->r_paramid][RAY_MIB_INFO_SIZ5];
2900 pr->r_failcause = 0;
2902 com[ncom++] = RAY_COM_MALLOC(ray_repparams, RAY_COM_FWOK);
2903 com[ncom-1]->c_pr = pr;
2905 RAY_COM_RUNQ(sc, com, ncom, "rayrparm", error);
2907 /* XXX no real error processing from anything yet! */
2908 if (!com[0]->c_retval && pr->r_failcause)
2911 RAY_COM_FREE(com, ncom);
2917 * Runq entry to read the required parameter
2919 * The card and driver are happy for parameters to be read
2920 * whenever the card is plugged in
2923 ray_repparams(struct ray_softc *sc, struct ray_comq_entry *com)
2925 RAY_DPRINTF(sc, RAY_DBG_SUBR, "");
2931 ray_ccs_fill(sc, com->c_ccs, RAY_CMD_REPORT_PARAMS);
2932 SRAM_WRITE_FIELD_1(sc, com->c_ccs,
2933 ray_cmd_report, c_paramid, com->c_pr->r_paramid);
2934 SRAM_WRITE_FIELD_1(sc, com->c_ccs, ray_cmd_report, c_nparam, 1);
2936 ray_com_ecf(sc, com);
2940 * Complete the parameter reporting
2943 ray_repparams_done(struct ray_softc *sc, u_int8_t status, size_t ccs)
2945 struct ray_comq_entry *com;
2947 RAY_DPRINTF(sc, RAY_DBG_SUBR, "");
2949 RAY_COM_CHECK(sc, ccs);
2951 RAY_CCSERR(sc, status, if_oerrors); /* XXX error counter */
2953 com = TAILQ_FIRST(&sc->sc_comq);
2954 com->c_pr->r_failcause =
2955 SRAM_READ_FIELD_1(sc, ccs, ray_cmd_report, c_failcause);
2957 SRAM_READ_FIELD_1(sc, ccs, ray_cmd_report, c_len);
2958 SRAM_READ_REGION(sc, RAY_ECF_TO_HOST_BASE,
2959 com->c_pr->r_data, com->c_pr->r_len);
2961 ray_com_ecf_done(sc);
2965 * User land entry (and exit) to the error counters
2968 ray_repstats_user(struct ray_softc *sc, struct ray_stats_req *sr)
2970 RAY_DPRINTF(sc, RAY_DBG_SUBR, "");
2972 sr->rxoverflow = sc->sc_rxoverflow;
2973 sr->rxcksum = sc->sc_rxcksum;
2974 sr->rxhcksum = sc->sc_rxhcksum;
2975 sr->rxnoise = sc->sc_rxnoise;
2981 * User land entry to parameter update changes
2983 * As a parameter change can cause the network parameters to be
2984 * invalid we have to re-start/join.
2987 ray_upparams_user(struct ray_softc *sc, struct ray_param_req *pr)
2989 struct ray_comq_entry *com[4];
2990 int error, ncom, todo;
2991 #define RAY_UPP_SJ 0x1
2992 #define RAY_UPP_PARAMS 0x2
2994 RAY_DPRINTF(sc, RAY_DBG_SUBR, "");
2997 * Check that the parameter is available based on firmware version
2999 pr->r_failcause = 0;
3000 if (pr->r_paramid > RAY_MIB_LASTUSER)
3002 if ((sc->sc_version == RAY_ECFS_BUILD_4) &&
3003 !(mib_info[pr->r_paramid][0] & RAY_V4))
3005 if ((sc->sc_version == RAY_ECFS_BUILD_5) &&
3006 !(mib_info[pr->r_paramid][0] & RAY_V5))
3010 * Handle certain parameters specially
3013 switch (pr->r_paramid) {
3014 case RAY_MIB_NET_TYPE: /* Updated via START_NET JOIN_NET */
3015 sc->sc_d.np_net_type = *pr->r_data;
3019 case RAY_MIB_SSID: /* Updated via START_NET JOIN_NET */
3020 bcopy(pr->r_data, sc->sc_d.np_ssid, IEEE80211_NWID_LEN);
3024 case RAY_MIB_PRIVACY_MUST_START:/* Updated via START_NET */
3025 if (sc->sc_c.np_net_type != RAY_MIB_NET_TYPE_ADHOC)
3027 sc->sc_d.np_priv_start = *pr->r_data;
3031 case RAY_MIB_PRIVACY_CAN_JOIN: /* Updated via START_NET JOIN_NET */
3032 sc->sc_d.np_priv_join = *pr->r_data;
3036 case RAY_MIB_BASIC_RATE_SET:
3037 sc->sc_d.np_def_txrate = *pr->r_data;
3038 todo |= RAY_UPP_PARAMS;
3041 case RAY_MIB_AP_STATUS: /* Unsupported */
3042 case RAY_MIB_MAC_ADDR: /* XXX Need interface up but could be done */
3043 case RAY_MIB_PROMISC: /* BPF */
3048 todo |= RAY_UPP_PARAMS;
3054 * Generate the runq entries as needed
3057 if (todo & RAY_UPP_PARAMS) {
3058 com[ncom++] = RAY_COM_MALLOC(ray_upparams, 0);
3059 com[ncom-1]->c_pr = pr;
3061 if (todo & RAY_UPP_SJ) {
3062 com[ncom++] = RAY_COM_MALLOC(ray_init_sj, 0);
3063 com[ncom++] = RAY_COM_MALLOC(ray_init_auth, 0);
3064 com[ncom++] = RAY_COM_MALLOC(ray_init_assoc, 0);
3067 RAY_COM_RUNQ(sc, com, ncom, "rayuparam", error);
3069 /* XXX no real error processing from anything yet! */
3070 if (!com[0]->c_retval && pr->r_failcause)
3073 RAY_COM_FREE(com, ncom);
3079 * Runq entry to update a parameter
3081 * The card and driver are happy for parameters to be updated
3082 * whenever the card is plugged in
3084 * XXX the above is a little bit of a lie until _download is sorted out and we
3085 * XXX keep local copies of things
3088 ray_upparams(struct ray_softc *sc, struct ray_comq_entry *com)
3090 RAY_DPRINTF(sc, RAY_DBG_SUBR, "");
3093 ray_ccs_fill(sc, com->c_ccs, RAY_CMD_UPDATE_PARAMS);
3095 SRAM_WRITE_FIELD_1(sc, com->c_ccs,
3096 ray_cmd_update, c_paramid, com->c_pr->r_paramid);
3097 SRAM_WRITE_FIELD_1(sc, com->c_ccs, ray_cmd_update, c_nparam, 1);
3098 SRAM_WRITE_REGION(sc, RAY_HOST_TO_ECF_BASE,
3099 com->c_pr->r_data, com->c_pr->r_len);
3101 ray_com_ecf(sc, com);
3105 * Complete the parameter update, note that promisc finishes up here too
3108 ray_upparams_done(struct ray_softc *sc, u_int8_t status, size_t ccs)
3110 struct ray_comq_entry *com;
3112 RAY_DPRINTF(sc, RAY_DBG_SUBR, "");
3114 RAY_COM_CHECK(sc, ccs);
3116 RAY_CCSERR(sc, status, if_oerrors); /* XXX error counter */
3118 com = TAILQ_FIRST(&sc->sc_comq);
3120 switch (SRAM_READ_FIELD_1(sc, ccs, ray_cmd_update, c_paramid)) {
3122 case RAY_MIB_PROMISC:
3123 sc->sc_c.np_promisc = SRAM_READ_1(sc, RAY_HOST_TO_ECF_BASE);
3124 RAY_DPRINTF(sc, RAY_DBG_IOCTL,
3125 "promisc value %d", sc->sc_c.np_promisc);
3129 com->c_pr->r_failcause =
3130 SRAM_READ_FIELD_1(sc, ccs, ray_cmd_update, c_failcause);
3135 ray_com_ecf_done(sc);
3139 * Command queuing and execution
3143 * Set up a comq entry struct
3145 static struct ray_comq_entry *
3146 ray_com_init(struct ray_comq_entry *com, ray_comqfn_t function, int flags, char *mesg)
3148 com->c_function = function;
3149 com->c_flags = flags;
3152 com->c_wakeup = NULL;
3160 * Malloc and set up a comq entry struct
3162 static struct ray_comq_entry *
3163 ray_com_malloc(ray_comqfn_t function, int flags, char *mesg)
3165 struct ray_comq_entry *com;
3167 MALLOC(com, struct ray_comq_entry *,
3168 sizeof(struct ray_comq_entry), M_RAYCOM, M_WAITOK);
3170 return (ray_com_init(com, function, flags, mesg));
3174 * Add an array of commands to the runq, get some ccs's for them and
3175 * then run, waiting on the last command.
3177 * We add the commands to the queue first to preserve ioctl ordering.
3179 * On recoverable errors, this routine removes the entries from the
3180 * runq. A caller can requeue the commands (and still preserve its own
3181 * processes ioctl ordering) but doesn't have to. When the card is
3182 * detached we get out quickly to prevent panics and don't bother
3186 ray_com_runq_add(struct ray_softc *sc, struct ray_comq_entry *com[], int ncom, char *wmesg)
3190 RAY_DPRINTF(sc, RAY_DBG_SUBR | RAY_DBG_COM, "");
3194 * Add the commands to the runq but don't let it run until
3195 * the ccs's are allocated successfully
3197 com[0]->c_flags |= RAY_COM_FWAIT;
3198 for (i = 0; i < ncom; i++) {
3199 com[i]->c_wakeup = com[ncom-1];
3200 RAY_DPRINTF(sc, RAY_DBG_COM, "adding %p", com[i]);
3201 RAY_DCOM(sc, RAY_DBG_DCOM, com[i], "adding");
3202 TAILQ_INSERT_TAIL(&sc->sc_comq, com[i], c_chain);
3204 com[ncom-1]->c_flags |= RAY_COM_FWOK;
3207 * Allocate ccs's for each command.
3209 for (i = 0; i < ncom; i++) {
3210 error = ray_ccs_alloc(sc, &com[i]->c_ccs, wmesg);
3218 * Allow the queue to run and sleep if needed.
3220 * Iff the FDETACHED flag is set in the com entry we waited on
3221 * the driver is in a zombie state! The softc structure has been
3222 * freed by the generic bus detach methods - eek. We tread very
3225 com[0]->c_flags &= ~RAY_COM_FWAIT;
3227 if (TAILQ_FIRST(&sc->sc_comq) != NULL) {
3228 RAY_DPRINTF(sc, RAY_DBG_COM, "sleeping");
3229 error = tsleep(com[ncom-1], PCATCH, wmesg, 0);
3230 if (com[ncom-1]->c_flags & RAY_COM_FDETACHED)
3232 RAY_DPRINTF(sc, RAY_DBG_COM,
3233 "awakened, tsleep returned 0x%x", error);
3239 * Only clean the queue on real errors - we don't care about it
3240 * when we detach as the queue entries are freed by the callers.
3242 if (error && (error != ENXIO))
3243 for (i = 0; i < ncom; i++)
3244 if (!(com[i]->c_flags & RAY_COM_FCOMPLETED)) {
3245 RAY_DPRINTF(sc, RAY_DBG_COM, "removing %p",
3247 RAY_DCOM(sc, RAY_DBG_DCOM, com[i], "removing");
3248 TAILQ_REMOVE(&sc->sc_comq, com[i], c_chain);
3249 ray_ccs_free(sc, com[i]->c_ccs);
3250 com[i]->c_ccs = NULL;
3257 * Run the command at the head of the queue (if not already running)
3260 ray_com_runq(struct ray_softc *sc)
3262 struct ray_comq_entry *com;
3264 RAY_DPRINTF(sc, RAY_DBG_SUBR | RAY_DBG_COM, "");
3266 com = TAILQ_FIRST(&sc->sc_comq);
3267 if ((com == NULL) ||
3268 (com->c_flags & RAY_COM_FRUNNING) ||
3269 (com->c_flags & RAY_COM_FWAIT) ||
3270 (com->c_flags & RAY_COM_FDETACHED))
3273 com->c_flags |= RAY_COM_FRUNNING;
3274 RAY_DPRINTF(sc, RAY_DBG_COM, "running %p", com);
3275 RAY_DCOM(sc, RAY_DBG_DCOM, com, "running");
3276 com->c_function(sc, com);
3280 * Remove run command, free ccs and wakeup caller.
3282 * Minimal checks are done here as we ensure that the com and command
3283 * handler were matched up earlier. Must be called at splnet or higher
3284 * so that entries on the command queue are correctly removed.
3286 * Remove the com from the comq, and wakeup the caller if it requested
3287 * to be woken. This is used for ensuring a sequence of commands
3288 * completes. Finally, re-run the queue.
3291 ray_com_runq_done(struct ray_softc *sc)
3293 struct ray_comq_entry *com;
3295 RAY_DPRINTF(sc, RAY_DBG_SUBR | RAY_DBG_COM, "");
3297 com = TAILQ_FIRST(&sc->sc_comq); /* XXX shall we check this as below */
3298 RAY_DPRINTF(sc, RAY_DBG_COM, "removing %p", com);
3299 RAY_DCOM(sc, RAY_DBG_DCOM, com, "removing");
3300 TAILQ_REMOVE(&sc->sc_comq, com, c_chain);
3302 com->c_flags &= ~RAY_COM_FRUNNING;
3303 com->c_flags |= RAY_COM_FCOMPLETED;
3305 ray_ccs_free(sc, com->c_ccs);
3308 if (com->c_flags & RAY_COM_FWOK)
3309 wakeup(com->c_wakeup);
3313 /* XXX what about error on completion then? deal with when i fix
3314 * XXX the status checking
3316 * XXX all the runq_done calls from IFF_RUNNING checks in runq
3317 * XXX routines should return EIO but shouldn't abort the runq
3322 * Send a command to the ECF.
3325 ray_com_ecf(struct ray_softc *sc, struct ray_comq_entry *com)
3329 RAY_DPRINTF(sc, RAY_DBG_SUBR | RAY_DBG_COM, "");
3332 while (!RAY_ECF_READY(sc)) {
3333 DELAY(RAY_ECF_SPIN_DELAY);
3334 if (++i > RAY_ECF_SPIN_TRIES)
3335 RAY_PANIC(sc, "spun too long");
3338 RAY_RECERR(sc, "spun %d times", i);
3340 RAY_DPRINTF(sc, RAY_DBG_COM, "sending %p", com);
3341 RAY_DCOM(sc, RAY_DBG_DCOM, com, "sending");
3342 SRAM_WRITE_1(sc, RAY_SCB_CCSI, RAY_CCS_INDEX(com->c_ccs));
3343 RAY_ECF_START_CMD(sc);
3345 if (RAY_COM_NEEDS_TIMO(
3346 SRAM_READ_FIELD_1(sc, com->c_ccs, ray_cmd, c_cmd))) {
3347 RAY_DPRINTF(sc, RAY_DBG_COM, "adding timeout");
3348 callout_reset(&sc->com_timer, RAY_COM_TIMEOUT,
3349 ray_com_ecf_timo, sc);
3354 * Deal with commands that require a timeout to test completion.
3356 * This routine is coded to only expect one outstanding request for the
3357 * timed out requests at a time, but thats all that can be outstanding
3358 * per hardware limitations and all that we issue anyway.
3360 * We don't do any fancy testing of the command currently issued as we
3361 * know it must be a timeout based one...unless I've got this wrong!
3364 ray_com_ecf_timo(void *xsc)
3366 struct ray_softc *sc = (struct ray_softc *)xsc;
3367 struct ray_comq_entry *com;
3368 u_int8_t cmd, status;
3373 RAY_DPRINTF(sc, RAY_DBG_SUBR | RAY_DBG_COM, "");
3376 com = TAILQ_FIRST(&sc->sc_comq);
3378 cmd = SRAM_READ_FIELD_1(sc, com->c_ccs, ray_cmd, c_cmd);
3379 status = SRAM_READ_FIELD_1(sc, com->c_ccs, ray_cmd, c_status);
3382 case RAY_CCS_STATUS_COMPLETE:
3383 case RAY_CCS_STATUS_FREE: /* Buggy firmware */
3384 ray_intr_ccs(sc, cmd, status, com->c_ccs);
3387 case RAY_CCS_STATUS_BUSY:
3388 callout_reset(&sc->com_timer, RAY_COM_TIMEOUT,
3389 ray_com_ecf_timo, sc);
3392 default: /* Replicates NetBSD */
3393 if (sc->sc_ccsinuse[RAY_CCS_INDEX(com->c_ccs)] == 1) {
3394 /* give a chance for the interrupt to occur */
3395 sc->sc_ccsinuse[RAY_CCS_INDEX(com->c_ccs)] = 2;
3396 callout_reset(&sc->com_timer, RAY_COM_TIMEOUT,
3397 ray_com_ecf_timo, sc);
3399 ray_intr_ccs(sc, cmd, status, com->c_ccs);
3408 * Called when interrupt handler for the command has done all it
3409 * needs to. Will be called at splnet.
3412 ray_com_ecf_done(struct ray_softc *sc)
3414 RAY_DPRINTF(sc, RAY_DBG_SUBR | RAY_DBG_COM, "");
3416 callout_stop(&sc->com_timer);
3418 ray_com_runq_done(sc);
3421 #if RAY_DEBUG & RAY_DBG_COM
3423 * Process completed ECF commands that probably came from the command queue
3425 * This routine is called after vectoring the completed ECF command
3426 * to the appropriate _done routine. It helps check everything is okay.
3429 ray_com_ecf_check(struct ray_softc *sc, size_t ccs, char *mesg)
3431 struct ray_comq_entry *com;
3433 RAY_DPRINTF(sc, RAY_DBG_SUBR | RAY_DBG_COM, "%s", mesg);
3435 com = TAILQ_FIRST(&sc->sc_comq);
3438 RAY_PANIC(sc, "no command queue");
3439 if (com->c_ccs != ccs)
3440 RAY_PANIC(sc, "ccs's don't match");
3442 #endif /* RAY_DEBUG & RAY_DBG_COM */
3449 * Obtain a ccs for a commmand
3451 * Returns 0 and in `ccsp' the bus offset of the free ccs. Will block
3452 * awaiting free ccs if needed - if the sleep is interrupted
3453 * EINTR/ERESTART is returned, if the card is ejected we return ENXIO.
3456 ray_ccs_alloc(struct ray_softc *sc, size_t *ccsp, char *wmesg)
3462 RAY_DPRINTF(sc, RAY_DBG_SUBR | RAY_DBG_CCS, "");
3466 for (i = RAY_CCS_CMD_FIRST; i <= RAY_CCS_CMD_LAST; i++) {
3467 /* we probe here to make the card go */
3468 (void)SRAM_READ_FIELD_1(sc, RAY_CCS_ADDRESS(i), ray_cmd,
3470 if (!sc->sc_ccsinuse[i])
3473 if (i > RAY_CCS_CMD_LAST) {
3474 RAY_DPRINTF(sc, RAY_DBG_CCS, "sleeping");
3475 error = tsleep(ray_ccs_alloc, PCATCH, wmesg, 0);
3476 if ((sc == NULL) || (sc->sc_gone))
3478 RAY_DPRINTF(sc, RAY_DBG_CCS,
3479 "awakened, tsleep returned 0x%x", error);
3485 RAY_DPRINTF(sc, RAY_DBG_CCS, "allocated 0x%02x", i);
3486 sc->sc_ccsinuse[i] = 1;
3487 ccs = RAY_CCS_ADDRESS(i);
3494 * Fill the easy bits in of a pre-allocated CCS
3497 ray_ccs_fill(struct ray_softc *sc, size_t ccs, u_int cmd)
3499 RAY_DPRINTF(sc, RAY_DBG_SUBR | RAY_DBG_CCS, "");
3503 RAY_PANIC(sc, "ccs not allocated");
3505 SRAM_WRITE_FIELD_1(sc, ccs, ray_cmd, c_status, RAY_CCS_STATUS_BUSY);
3506 SRAM_WRITE_FIELD_1(sc, ccs, ray_cmd, c_cmd, cmd);
3507 SRAM_WRITE_FIELD_1(sc, ccs, ray_cmd, c_link, RAY_CCS_LINK_NULL);
3511 * Free up a ccs allocated via ray_ccs_alloc
3513 * Return the old status. This routine is only used for ccs allocated via
3514 * ray_ccs_alloc (not tx, rx or ECF command requests).
3517 ray_ccs_free(struct ray_softc *sc, size_t ccs)
3519 RAY_DPRINTF(sc, RAY_DBG_SUBR | RAY_DBG_CCS, "");
3522 #if 1 | (RAY_DEBUG & RAY_DBG_CCS)
3523 if (!sc->sc_ccsinuse[RAY_CCS_INDEX(ccs)])
3524 RAY_RECERR(sc, "freeing free ccs 0x%02x", RAY_CCS_INDEX(ccs));
3525 #endif /* RAY_DEBUG & RAY_DBG_CCS */
3527 RAY_CCS_FREE(sc, ccs);
3528 sc->sc_ccsinuse[RAY_CCS_INDEX(ccs)] = 0;
3529 RAY_DPRINTF(sc, RAY_DBG_CCS, "freed 0x%02x", RAY_CCS_INDEX(ccs));
3530 wakeup(ray_ccs_alloc);
3534 * Obtain a ccs and tx buffer to transmit with and fill them in.
3536 * Returns 0 and in `ccsp' the bus offset of the free ccs. Will not block
3537 * and if none available and will returns EAGAIN.
3539 * The caller must fill in the length later.
3540 * The caller must clear the ccs on errors.
3543 ray_ccs_tx(struct ray_softc *sc, size_t *ccsp, size_t *bufpp)
3549 RAY_DPRINTF(sc, RAY_DBG_SUBR | RAY_DBG_CCS, "");
3552 i = RAY_CCS_TX_FIRST;
3554 status = SRAM_READ_FIELD_1(sc, RAY_CCS_ADDRESS(i),
3556 if (status == RAY_CCS_STATUS_FREE)
3559 } while (i <= RAY_CCS_TX_LAST);
3560 if (i > RAY_CCS_TX_LAST) {
3563 RAY_DPRINTF(sc, RAY_DBG_CCS, "allocated 0x%02x", i);
3566 * Reserve and fill the ccs - must do the length later.
3568 * Even though build 4 and build 5 have different fields all these
3569 * are common apart from tx_rate. Neither the NetBSD driver or Linux
3570 * driver bother to overwrite this for build 4 cards.
3572 * The start of the buffer must be aligned to a 256 byte boundary
3573 * (least significant byte of address = 0x00).
3575 ccs = RAY_CCS_ADDRESS(i);
3576 bufp = RAY_TX_BASE + i * RAY_TX_BUF_SIZE;
3577 bufp += sc->sc_tibsize;
3578 SRAM_WRITE_FIELD_1(sc, ccs, ray_cmd_tx, c_status, RAY_CCS_STATUS_BUSY);
3579 SRAM_WRITE_FIELD_1(sc, ccs, ray_cmd_tx, c_cmd, RAY_CMD_TX_REQ);
3580 SRAM_WRITE_FIELD_1(sc, ccs, ray_cmd_tx, c_link, RAY_CCS_LINK_NULL);
3581 SRAM_WRITE_FIELD_2(sc, ccs, ray_cmd_tx, c_bufp, bufp);
3582 SRAM_WRITE_FIELD_1(sc,
3583 ccs, ray_cmd_tx, c_tx_rate, sc->sc_c.np_def_txrate);
3584 SRAM_WRITE_FIELD_1(sc, ccs, ray_cmd_tx, c_apm_mode, 0);
3585 bufp += sizeof(struct ray_tx_phy_header);
3593 * Routines to obtain resources for the card
3597 * Allocate the attribute memory on the card
3599 * The attribute memory space is abused by these devices as IO space. As such
3600 * the OS card services don't have a chance of knowing that they need to keep
3601 * the attribute space mapped. We have to do it manually.
3604 ray_res_alloc_am(struct ray_softc *sc)
3608 RAY_DPRINTF(sc, RAY_DBG_SUBR | RAY_DBG_CM, "");
3610 sc->am_rid = RAY_AM_RID;
3611 sc->am_res = bus_alloc_resource(sc->dev, SYS_RES_MEMORY,
3612 &sc->am_rid, 0UL, ~0UL, 0x1000, RF_ACTIVE);
3614 RAY_PRINTF(sc, "Cannot allocate attribute memory");
3617 error = CARD_SET_MEMORY_OFFSET(device_get_parent(sc->dev), sc->dev,
3618 sc->am_rid, 0, NULL);
3620 RAY_PRINTF(sc, "CARD_SET_MEMORY_OFFSET returned 0x%0x", error);
3623 error = CARD_SET_RES_FLAGS(device_get_parent(sc->dev), sc->dev,
3624 SYS_RES_MEMORY, sc->am_rid, PCCARD_A_MEM_ATTR);
3626 RAY_PRINTF(sc, "CARD_SET_RES_FLAGS returned 0x%0x", error);
3629 error = CARD_SET_RES_FLAGS(device_get_parent(sc->dev), sc->dev,
3630 SYS_RES_MEMORY, sc->am_rid, PCCARD_A_MEM_8BIT);
3632 RAY_PRINTF(sc, "CARD_SET_RES_FLAGS returned 0x%0x", error);
3635 sc->am_bsh = rman_get_bushandle(sc->am_res);
3636 sc->am_bst = rman_get_bustag(sc->am_res);
3638 #if RAY_DEBUG & (RAY_DBG_CM | RAY_DBG_BOOTPARAM)
3642 CARD_GET_RES_FLAGS(device_get_parent(sc->dev), sc->dev,
3643 SYS_RES_MEMORY, sc->am_rid, &flags);
3644 CARD_GET_MEMORY_OFFSET(device_get_parent(sc->dev), sc->dev,
3645 sc->am_rid, &offset);
3646 RAY_PRINTF(sc, "allocated attribute memory:\n"
3647 ". start 0x%0lx count 0x%0lx flags 0x%0lx offset 0x%0x",
3648 bus_get_resource_start(sc->dev, SYS_RES_MEMORY, sc->am_rid),
3649 bus_get_resource_count(sc->dev, SYS_RES_MEMORY, sc->am_rid),
3652 #endif /* RAY_DEBUG & (RAY_DBG_CM | RAY_DBG_BOOTPARAM) */
3658 * Allocate the common memory on the card
3660 * As this memory is described in the CIS, the OS card services should
3661 * have set the map up okay, but the card uses 8 bit RAM. This is not
3662 * described in the CIS.
3665 ray_res_alloc_cm(struct ray_softc *sc)
3667 u_long start, count, end;
3670 RAY_DPRINTF(sc, RAY_DBG_SUBR | RAY_DBG_CM, "");
3672 RAY_DPRINTF(sc,RAY_DBG_CM | RAY_DBG_BOOTPARAM,
3673 "cm start 0x%0lx count 0x%0lx",
3674 bus_get_resource_start(sc->dev, SYS_RES_MEMORY, RAY_CM_RID),
3675 bus_get_resource_count(sc->dev, SYS_RES_MEMORY, RAY_CM_RID));
3677 sc->cm_rid = RAY_CM_RID;
3678 start = bus_get_resource_start(sc->dev, SYS_RES_MEMORY, sc->cm_rid);
3679 count = bus_get_resource_count(sc->dev, SYS_RES_MEMORY, sc->cm_rid);
3680 end = start + count - 1;
3681 sc->cm_res = bus_alloc_resource(sc->dev, SYS_RES_MEMORY,
3682 &sc->cm_rid, start, end, count, RF_ACTIVE);
3684 RAY_PRINTF(sc, "Cannot allocate common memory");
3687 error = CARD_SET_MEMORY_OFFSET(device_get_parent(sc->dev), sc->dev,
3688 sc->cm_rid, 0, NULL);
3690 RAY_PRINTF(sc, "CARD_SET_MEMORY_OFFSET returned 0x%0x", error);
3693 error = CARD_SET_RES_FLAGS(device_get_parent(sc->dev), sc->dev,
3694 SYS_RES_MEMORY, sc->cm_rid, PCCARD_A_MEM_COM);
3696 RAY_PRINTF(sc, "CARD_SET_RES_FLAGS returned 0x%0x", error);
3699 error = CARD_SET_RES_FLAGS(device_get_parent(sc->dev), sc->dev,
3700 SYS_RES_MEMORY, sc->cm_rid, PCCARD_A_MEM_8BIT);
3702 RAY_PRINTF(sc, "CARD_SET_RES_FLAGS returned 0x%0x", error);
3705 sc->cm_bsh = rman_get_bushandle(sc->cm_res);
3706 sc->cm_bst = rman_get_bustag(sc->cm_res);
3708 #if RAY_DEBUG & (RAY_DBG_CM | RAY_DBG_BOOTPARAM)
3712 CARD_GET_RES_FLAGS(device_get_parent(sc->dev), sc->dev,
3713 SYS_RES_MEMORY, sc->cm_rid, &flags);
3714 CARD_GET_MEMORY_OFFSET(device_get_parent(sc->dev), sc->dev,
3715 sc->cm_rid, &offset);
3716 RAY_PRINTF(sc, "allocated common memory:\n"
3717 ". start 0x%0lx count 0x%0lx flags 0x%0lx offset 0x%0x",
3718 bus_get_resource_start(sc->dev, SYS_RES_MEMORY, sc->cm_rid),
3719 bus_get_resource_count(sc->dev, SYS_RES_MEMORY, sc->cm_rid),
3722 #endif /* RAY_DEBUG & (RAY_DBG_CM | RAY_DBG_BOOTPARAM) */
3728 * Get an irq and attach it to the bus
3731 ray_res_alloc_irq(struct ray_softc *sc)
3735 RAY_DPRINTF(sc, RAY_DBG_SUBR, "");
3737 RAY_DPRINTF(sc,RAY_DBG_CM | RAY_DBG_BOOTPARAM,
3738 "irq start 0x%0lx count 0x%0lx",
3739 bus_get_resource_start(sc->dev, SYS_RES_IRQ, 0),
3740 bus_get_resource_count(sc->dev, SYS_RES_IRQ, 0));
3743 sc->irq_res = bus_alloc_resource(sc->dev, SYS_RES_IRQ, &sc->irq_rid,
3744 0, ~0, 1, RF_ACTIVE);
3746 RAY_PRINTF(sc, "Cannot allocate irq");
3749 if ((error = bus_setup_intr(sc->dev, sc->irq_res, INTR_TYPE_NET,
3750 ray_intr, sc, &sc->irq_handle)) != 0) {
3751 RAY_PRINTF(sc, "Failed to setup irq");
3754 RAY_DPRINTF(sc, RAY_DBG_CM | RAY_DBG_BOOTPARAM, "allocated irq:\n"
3755 ". start 0x%0lx count 0x%0lx",
3756 bus_get_resource_start(sc->dev, SYS_RES_IRQ, sc->irq_rid),
3757 bus_get_resource_count(sc->dev, SYS_RES_IRQ, sc->irq_rid));
3763 * Release all of the card's resources
3766 ray_res_release(struct ray_softc *sc)
3768 if (sc->irq_res != 0) {
3769 bus_teardown_intr(sc->dev, sc->irq_res, sc->irq_handle);
3770 bus_release_resource(sc->dev, SYS_RES_IRQ,
3771 sc->irq_rid, sc->irq_res);
3774 if (sc->am_res != 0) {
3775 bus_release_resource(sc->dev, SYS_RES_MEMORY,
3776 sc->am_rid, sc->am_res);
3779 if (sc->cm_res != 0) {
3780 bus_release_resource(sc->dev, SYS_RES_MEMORY,
3781 sc->cm_rid, sc->cm_res);
3789 #if RAY_DEBUG & RAY_DBG_MBUF
3791 ray_dump_mbuf(struct ray_softc *sc, struct mbuf *m, char *s)
3797 RAY_PRINTF(sc, "%s", s);
3798 RAY_PRINTF(sc, "\nm0->data\t0x%p\nm_pkthdr.len\t%d\nm_len\t%d",
3799 mtod(m, u_int8_t *), m->m_pkthdr.len, m->m_len);
3802 for (; m; m = m->m_next) {
3803 d = mtod(m, u_int8_t *);
3806 for (; d < ed; i++, d++) {
3807 if ((i % 16) == 0) {
3808 printf(" %s\n\t", p);
3809 } else if ((i % 8) == 0)
3811 printf(" %02x", *d);
3812 p[i % 16] = ((*d >= 0x20) && (*d < 0x80)) ? *d : '.';
3818 #endif /* RAY_DEBUG & RAY_DBG_MBUF */