1 /* $OpenBSD: if_zyd.c,v 1.52 2007/02/11 00:08:04 jsg Exp $ */
2 /* $NetBSD: if_zyd.c,v 1.7 2007/06/21 04:04:29 kiyohara Exp $ */
6 * Copyright (c) 2006 by Damien Bergamini <damien.bergamini@free.fr>
7 * Copyright (c) 2006 by Florian Stoehr <ich@florian-stoehr.de>
9 * Permission to use, copy, modify, and distribute this software for any
10 * purpose with or without fee is hereby granted, provided that the above
11 * copyright notice and this permission notice appear in all copies.
13 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
14 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
15 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
16 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
17 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
18 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
19 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23 * ZyDAS ZD1211/ZD1211B USB WLAN driver.
26 #include <sys/param.h>
27 #include <sys/systm.h>
28 #include <sys/sockio.h>
30 #include <sys/malloc.h>
31 #include <sys/kernel.h>
32 #include <sys/module.h>
33 #include <sys/socket.h>
34 #include <sys/sysctl.h>
35 #include <sys/endian.h>
36 #include <sys/linker.h>
39 #include <net/if_arp.h>
40 #include <net/ethernet.h>
41 #include <net/if_dl.h>
42 #include <net/if_media.h>
43 #include <net/if_types.h>
46 #include <machine/bus.h>
48 #include <net80211/ieee80211_var.h>
49 #include <net80211/ieee80211_amrr.h>
50 #include <net80211/ieee80211_phy.h>
51 #include <net80211/ieee80211_radiotap.h>
52 #include <net80211/ieee80211_regdomain.h>
56 #include <dev/usb/usb.h>
57 #include <dev/usb/usbdi.h>
58 #include <dev/usb/usbdi_util.h>
59 #include <dev/usb/usbdivar.h>
61 #include <dev/usb/usb_ethersubr.h>
63 #include <dev/mii/mii.h>
64 #include <dev/mii/miivar.h>
66 #include <dev/usb/if_zydreg.h>
67 #include <dev/usb/if_zydfw.h>
71 #define DPRINTF(x) do { if (zyddebug > 0) printf x; } while (0)
72 #define DPRINTFN(n, x) do { if (zyddebug > (n)) printf x; } while (0)
76 #define DPRINTFN(n, x)
79 static const struct zyd_phy_pair zyd_def_phy[] = ZYD_DEF_PHY;
80 static const struct zyd_phy_pair zyd_def_phyB[] = ZYD_DEF_PHYB;
82 /* various supported device vendors/products */
83 #define ZYD_ZD1211_DEV(v, p) \
84 { { USB_VENDOR_##v, USB_PRODUCT_##v##_##p }, ZYD_ZD1211 }
85 #define ZYD_ZD1211B_DEV(v, p) \
86 { { USB_VENDOR_##v, USB_PRODUCT_##v##_##p }, ZYD_ZD1211B }
87 static const struct zyd_type {
93 ZYD_ZD1211_DEV(3COM2, 3CRUSB10075),
94 ZYD_ZD1211_DEV(ABOCOM, WL54),
95 ZYD_ZD1211_DEV(ASUS, WL159G),
96 ZYD_ZD1211_DEV(CYBERTAN, TG54USB),
97 ZYD_ZD1211_DEV(DRAYTEK, VIGOR550),
98 ZYD_ZD1211_DEV(PLANEX2, GWUS54GD),
99 ZYD_ZD1211_DEV(PLANEX2, GWUS54GZL),
100 ZYD_ZD1211_DEV(PLANEX3, GWUS54GZ),
101 ZYD_ZD1211_DEV(PLANEX3, GWUS54MINI),
102 ZYD_ZD1211_DEV(SAGEM, XG760A),
103 ZYD_ZD1211_DEV(SENAO, NUB8301),
104 ZYD_ZD1211_DEV(SITECOMEU, WL113),
105 ZYD_ZD1211_DEV(SWEEX, ZD1211),
106 ZYD_ZD1211_DEV(TEKRAM, QUICKWLAN),
107 ZYD_ZD1211_DEV(TEKRAM, ZD1211_1),
108 ZYD_ZD1211_DEV(TEKRAM, ZD1211_2),
109 ZYD_ZD1211_DEV(TWINMOS, G240),
110 ZYD_ZD1211_DEV(UMEDIA, ALL0298V2),
111 ZYD_ZD1211_DEV(UMEDIA, TEW429UB_A),
112 ZYD_ZD1211_DEV(UMEDIA, TEW429UB),
113 ZYD_ZD1211_DEV(WISTRONNEWEB, UR055G),
114 ZYD_ZD1211_DEV(ZCOM, ZD1211),
115 ZYD_ZD1211_DEV(ZYDAS, ZD1211),
116 ZYD_ZD1211_DEV(ZYXEL, AG225H),
117 ZYD_ZD1211_DEV(ZYXEL, ZYAIRG220),
118 ZYD_ZD1211_DEV(ZYXEL, G200V2),
119 ZYD_ZD1211_DEV(ZYXEL, G202),
121 ZYD_ZD1211B_DEV(ACCTON, SMCWUSBG),
122 ZYD_ZD1211B_DEV(ACCTON, ZD1211B),
123 ZYD_ZD1211B_DEV(ASUS, A9T_WIFI),
124 ZYD_ZD1211B_DEV(BELKIN, F5D7050_V4000),
125 ZYD_ZD1211B_DEV(BELKIN, ZD1211B),
126 ZYD_ZD1211B_DEV(CISCOLINKSYS, WUSBF54G),
127 ZYD_ZD1211B_DEV(FIBERLINE, WL430U),
128 ZYD_ZD1211B_DEV(MELCO, KG54L),
129 ZYD_ZD1211B_DEV(PHILIPS, SNU5600),
130 ZYD_ZD1211B_DEV(PLANEX2, GW_US54GXS),
131 ZYD_ZD1211B_DEV(SAGEM, XG76NA),
132 ZYD_ZD1211B_DEV(SITECOMEU, ZD1211B),
133 ZYD_ZD1211B_DEV(UMEDIA, TEW429UBC1),
134 #if 0 /* Shall we needs? */
135 ZYD_ZD1211B_DEV(UNKNOWN1, ZD1211B_1),
136 ZYD_ZD1211B_DEV(UNKNOWN1, ZD1211B_2),
137 ZYD_ZD1211B_DEV(UNKNOWN2, ZD1211B),
138 ZYD_ZD1211B_DEV(UNKNOWN3, ZD1211B),
140 ZYD_ZD1211B_DEV(USR, USR5423),
141 ZYD_ZD1211B_DEV(VTECH, ZD1211B),
142 ZYD_ZD1211B_DEV(ZCOM, ZD1211B),
143 ZYD_ZD1211B_DEV(ZYDAS, ZD1211B),
144 ZYD_ZD1211B_DEV(ZYXEL, M202),
145 ZYD_ZD1211B_DEV(ZYXEL, G220V2),
147 #define zyd_lookup(v, p) \
148 ((const struct zyd_type *)usb_lookup(zyd_devs, v, p))
150 static device_probe_t zyd_match;
151 static device_attach_t zyd_attach;
152 static device_detach_t zyd_detach;
154 static struct ieee80211vap *zyd_vap_create(struct ieee80211com *,
155 const char name[IFNAMSIZ], int unit, int opmode,
156 int flags, const uint8_t bssid[IEEE80211_ADDR_LEN],
157 const uint8_t mac[IEEE80211_ADDR_LEN]);
158 static void zyd_vap_delete(struct ieee80211vap *);
159 static int zyd_attachhook(struct zyd_softc *);
160 static int zyd_complete_attach(struct zyd_softc *);
161 static int zyd_open_pipes(struct zyd_softc *);
162 static void zyd_close_pipes(struct zyd_softc *);
163 static int zyd_alloc_tx_list(struct zyd_softc *);
164 static void zyd_free_tx_list(struct zyd_softc *);
165 static int zyd_alloc_rx_list(struct zyd_softc *);
166 static void zyd_free_rx_list(struct zyd_softc *);
167 static struct ieee80211_node *zyd_node_alloc(struct ieee80211vap *,
168 const uint8_t mac[IEEE80211_ADDR_LEN]);
169 static void zyd_task(void *);
170 static int zyd_newstate(struct ieee80211vap *, enum ieee80211_state, int);
171 static int zyd_cmd(struct zyd_softc *, uint16_t, const void *, int,
173 static int zyd_read16(struct zyd_softc *, uint16_t, uint16_t *);
174 static int zyd_read32(struct zyd_softc *, uint16_t, uint32_t *);
175 static int zyd_write16(struct zyd_softc *, uint16_t, uint16_t);
176 static int zyd_write32(struct zyd_softc *, uint16_t, uint32_t);
177 static int zyd_rfwrite(struct zyd_softc *, uint32_t);
178 static void zyd_lock_phy(struct zyd_softc *);
179 static void zyd_unlock_phy(struct zyd_softc *);
180 static int zyd_rfmd_init(struct zyd_rf *);
181 static int zyd_rfmd_switch_radio(struct zyd_rf *, int);
182 static int zyd_rfmd_set_channel(struct zyd_rf *, uint8_t);
183 static int zyd_al2230_init(struct zyd_rf *);
184 static int zyd_al2230_switch_radio(struct zyd_rf *, int);
185 static int zyd_al2230_set_channel(struct zyd_rf *, uint8_t);
186 static int zyd_al2230_init_b(struct zyd_rf *);
187 static int zyd_al7230B_init(struct zyd_rf *);
188 static int zyd_al7230B_switch_radio(struct zyd_rf *, int);
189 static int zyd_al7230B_set_channel(struct zyd_rf *, uint8_t);
190 static int zyd_al2210_init(struct zyd_rf *);
191 static int zyd_al2210_switch_radio(struct zyd_rf *, int);
192 static int zyd_al2210_set_channel(struct zyd_rf *, uint8_t);
193 static int zyd_gct_init(struct zyd_rf *);
194 static int zyd_gct_switch_radio(struct zyd_rf *, int);
195 static int zyd_gct_set_channel(struct zyd_rf *, uint8_t);
196 static int zyd_maxim_init(struct zyd_rf *);
197 static int zyd_maxim_switch_radio(struct zyd_rf *, int);
198 static int zyd_maxim_set_channel(struct zyd_rf *, uint8_t);
199 static int zyd_maxim2_init(struct zyd_rf *);
200 static int zyd_maxim2_switch_radio(struct zyd_rf *, int);
201 static int zyd_maxim2_set_channel(struct zyd_rf *, uint8_t);
202 static int zyd_rf_attach(struct zyd_softc *, uint8_t);
203 static const char *zyd_rf_name(uint8_t);
204 static int zyd_hw_init(struct zyd_softc *);
205 static int zyd_read_eeprom(struct zyd_softc *);
206 static int zyd_set_macaddr(struct zyd_softc *, const uint8_t *);
207 static int zyd_set_bssid(struct zyd_softc *, const uint8_t *);
208 static int zyd_switch_radio(struct zyd_softc *, int);
209 static void zyd_set_led(struct zyd_softc *, int, int);
210 static void zyd_set_multi(void *);
211 static void zyd_update_mcast(struct ifnet *);
212 static int zyd_set_rxfilter(struct zyd_softc *);
213 static void zyd_set_chan(struct zyd_softc *, struct ieee80211_channel *);
214 static int zyd_set_beacon_interval(struct zyd_softc *, int);
215 static void zyd_intr(usbd_xfer_handle, usbd_private_handle, usbd_status);
216 static void zyd_rx_data(struct zyd_softc *, const uint8_t *, uint16_t);
217 static void zyd_rxeof(usbd_xfer_handle, usbd_private_handle, usbd_status);
218 static void zyd_txeof(usbd_xfer_handle, usbd_private_handle, usbd_status);
219 static int zyd_tx_mgt(struct zyd_softc *, struct mbuf *,
220 struct ieee80211_node *);
221 static int zyd_tx_data(struct zyd_softc *, struct mbuf *,
222 struct ieee80211_node *);
223 static void zyd_start(struct ifnet *);
224 static int zyd_raw_xmit(struct ieee80211_node *, struct mbuf *,
225 const struct ieee80211_bpf_params *);
226 static void zyd_watchdog(void *);
227 static int zyd_ioctl(struct ifnet *, u_long, caddr_t);
228 static void zyd_init_locked(struct zyd_softc *);
229 static void zyd_init(void *);
230 static void zyd_stop(struct zyd_softc *, int);
231 static int zyd_loadfirmware(struct zyd_softc *, u_char *, size_t);
232 static void zyd_newassoc(struct ieee80211_node *, int);
233 static void zyd_scantask(void *);
234 static void zyd_scan_start(struct ieee80211com *);
235 static void zyd_scan_end(struct ieee80211com *);
236 static void zyd_set_channel(struct ieee80211com *);
237 static void zyd_wakeup(struct zyd_softc *);
240 zyd_match(device_t dev)
242 struct usb_attach_arg *uaa = device_get_ivars(dev);
247 return (zyd_lookup(uaa->vendor, uaa->product) != NULL) ?
248 UMATCH_VENDOR_PRODUCT : UMATCH_NONE;
252 zyd_attachhook(struct zyd_softc *sc)
257 if (sc->mac_rev == ZYD_ZD1211) {
258 firmware = (u_char *)zd1211_firmware;
259 len = sizeof(zd1211_firmware);
261 firmware = (u_char *)zd1211b_firmware;
262 len = sizeof(zd1211b_firmware);
265 error = zyd_loadfirmware(sc, firmware, len);
267 device_printf(sc->sc_dev,
268 "could not load firmware (error=%d)\n", error);
272 sc->sc_flags |= ZYD_FLAG_FWLOADED;
274 /* complete the attach process */
275 return zyd_complete_attach(sc);
279 zyd_attach(device_t dev)
282 struct zyd_softc *sc = device_get_softc(dev);
283 struct usb_attach_arg *uaa = device_get_ivars(dev);
284 usb_device_descriptor_t* ddesc;
289 ifp = sc->sc_ifp = if_alloc(IFT_IEEE80211);
291 device_printf(dev, "can not if_alloc()\n");
295 sc->sc_udev = uaa->device;
297 sc->mac_rev = zyd_lookup(uaa->vendor, uaa->product)->rev;
299 ddesc = usbd_get_device_descriptor(sc->sc_udev);
300 if (UGETW(ddesc->bcdDevice) < 0x4330) {
301 device_printf(dev, "device version mismatch: 0x%x "
302 "(only >= 43.30 supported)\n",
303 UGETW(ddesc->bcdDevice));
308 if_initname(ifp, "zyd", device_get_unit(sc->sc_dev));
309 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST |
310 IFF_NEEDSGIANT; /* USB stack is still under Giant lock */
311 ifp->if_init = zyd_init;
312 ifp->if_ioctl = zyd_ioctl;
313 ifp->if_start = zyd_start;
314 IFQ_SET_MAXLEN(&ifp->if_snd, IFQ_MAXLEN);
315 IFQ_SET_READY(&ifp->if_snd);
317 STAILQ_INIT(&sc->sc_rqh);
319 error = zyd_attachhook(sc);
330 zyd_complete_attach(struct zyd_softc *sc)
332 struct ifnet *ifp = sc->sc_ifp;
333 struct ieee80211com *ic = ifp->if_l2com;
337 mtx_init(&sc->sc_mtx, device_get_nameunit(sc->sc_dev), MTX_NETWORK_LOCK,
338 MTX_DEF | MTX_RECURSE);
340 usb_init_task(&sc->sc_scantask, zyd_scantask, sc);
341 usb_init_task(&sc->sc_task, zyd_task, sc);
342 usb_init_task(&sc->sc_mcasttask, zyd_set_multi, sc);
344 callout_init(&sc->sc_watchdog_ch, 0);
346 error = usbd_set_config_no(sc->sc_udev, ZYD_CONFIG_NO, 1);
348 device_printf(sc->sc_dev, "setting config no failed\n");
353 error = usbd_device2interface_handle(sc->sc_udev, ZYD_IFACE_INDEX,
356 device_printf(sc->sc_dev, "getting interface handle failed\n");
361 if ((error = zyd_open_pipes(sc)) != 0) {
362 device_printf(sc->sc_dev, "could not open pipes\n");
366 if ((error = zyd_read_eeprom(sc)) != 0) {
367 device_printf(sc->sc_dev, "could not read EEPROM\n");
371 if ((error = zyd_rf_attach(sc, sc->rf_rev)) != 0) {
372 device_printf(sc->sc_dev, "could not attach RF, rev 0x%x\n",
377 if ((error = zyd_hw_init(sc)) != 0) {
378 device_printf(sc->sc_dev, "hardware initialization failed\n");
382 device_printf(sc->sc_dev,
383 "HMAC ZD1211%s, FW %02x.%02x, RF %s, PA %x, address %s\n",
384 (sc->mac_rev == ZYD_ZD1211) ? "": "B",
385 sc->fw_rev >> 8, sc->fw_rev & 0xff, zyd_rf_name(sc->rf_rev),
386 sc->pa_rev, ether_sprintf(ic->ic_myaddr));
388 IEEE80211_ADDR_COPY(sc->sc_bssid, ic->ic_myaddr);
391 ic->ic_phytype = IEEE80211_T_OFDM; /* not only, but not used */
392 ic->ic_opmode = IEEE80211_M_STA;
394 /* set device capabilities */
396 IEEE80211_C_STA /* station mode */
397 | IEEE80211_C_MONITOR /* monitor mode */
398 | IEEE80211_C_SHPREAMBLE /* short preamble supported */
399 | IEEE80211_C_SHSLOT /* short slot time supported */
400 | IEEE80211_C_BGSCAN /* capable of bg scanning */
401 | IEEE80211_C_WPA /* 802.11i */
405 setbit(&bands, IEEE80211_MODE_11B);
406 setbit(&bands, IEEE80211_MODE_11G);
407 ieee80211_init_channels(ic, NULL, &bands);
409 ieee80211_ifattach(ic);
410 ic->ic_newassoc = zyd_newassoc;
411 ic->ic_raw_xmit = zyd_raw_xmit;
412 ic->ic_node_alloc = zyd_node_alloc;
413 ic->ic_scan_start = zyd_scan_start;
414 ic->ic_scan_end = zyd_scan_end;
415 ic->ic_set_channel = zyd_set_channel;
417 ic->ic_vap_create = zyd_vap_create;
418 ic->ic_vap_delete = zyd_vap_delete;
419 ic->ic_update_mcast = zyd_update_mcast;
421 bpfattach(ifp, DLT_IEEE802_11_RADIO,
422 sizeof(struct ieee80211_frame) + sizeof(sc->sc_txtap));
424 sc->sc_rxtap_len = sizeof(sc->sc_rxtap);
425 sc->sc_rxtap.wr_ihdr.it_len = htole16(sc->sc_rxtap_len);
426 sc->sc_rxtap.wr_ihdr.it_present = htole32(ZYD_RX_RADIOTAP_PRESENT);
428 sc->sc_txtap_len = sizeof(sc->sc_txtap);
429 sc->sc_txtap.wt_ihdr.it_len = htole16(sc->sc_txtap_len);
430 sc->sc_txtap.wt_ihdr.it_present = htole32(ZYD_TX_RADIOTAP_PRESENT);
433 ieee80211_announce(ic);
435 usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, sc->sc_udev, sc->sc_dev);
440 mtx_destroy(&sc->sc_mtx);
446 zyd_detach(device_t dev)
448 struct zyd_softc *sc = device_get_softc(dev);
449 struct ifnet *ifp = sc->sc_ifp;
450 struct ieee80211com *ic = ifp->if_l2com;
452 if (!device_is_attached(dev))
455 /* protect a race when we have listeners related with the driver. */
456 ifp->if_flags &= ~IFF_UP;
460 ieee80211_ifdetach(ic);
462 /* set a flag to indicate we're detaching. */
463 sc->sc_flags |= ZYD_FLAG_DETACHING;
465 usb_rem_task(sc->sc_udev, &sc->sc_scantask);
466 usb_rem_task(sc->sc_udev, &sc->sc_task);
467 callout_stop(&sc->sc_watchdog_ch);
473 mtx_destroy(&sc->sc_mtx);
475 usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->sc_udev, sc->sc_dev);
480 static struct ieee80211vap *
481 zyd_vap_create(struct ieee80211com *ic,
482 const char name[IFNAMSIZ], int unit, int opmode, int flags,
483 const uint8_t bssid[IEEE80211_ADDR_LEN],
484 const uint8_t mac[IEEE80211_ADDR_LEN])
487 struct ieee80211vap *vap;
489 if (!TAILQ_EMPTY(&ic->ic_vaps)) /* only one at a time */
491 zvp = (struct zyd_vap *) malloc(sizeof(struct zyd_vap),
492 M_80211_VAP, M_NOWAIT | M_ZERO);
496 /* enable s/w bmiss handling for sta mode */
497 ieee80211_vap_setup(ic, vap, name, unit, opmode,
498 flags | IEEE80211_CLONE_NOBEACONS, bssid, mac);
500 /* override state transition machine */
501 zvp->newstate = vap->iv_newstate;
502 vap->iv_newstate = zyd_newstate;
504 ieee80211_amrr_init(&zvp->amrr, vap,
505 IEEE80211_AMRR_MIN_SUCCESS_THRESHOLD,
506 IEEE80211_AMRR_MAX_SUCCESS_THRESHOLD,
510 ieee80211_vap_attach(vap, ieee80211_media_change, ieee80211_media_status);
511 ic->ic_opmode = opmode;
516 zyd_vap_delete(struct ieee80211vap *vap)
518 struct zyd_vap *zvp = ZYD_VAP(vap);
520 ieee80211_amrr_cleanup(&zvp->amrr);
521 ieee80211_vap_detach(vap);
522 free(zvp, M_80211_VAP);
526 zyd_open_pipes(struct zyd_softc *sc)
528 usb_endpoint_descriptor_t *edesc;
533 edesc = usbd_get_endpoint_descriptor(sc->sc_iface, 0x83);
537 isize = UGETW(edesc->wMaxPacketSize);
538 if (isize == 0) /* should not happen */
541 sc->ibuf = malloc(isize, M_USBDEV, M_NOWAIT);
542 if (sc->ibuf == NULL)
545 error = usbd_open_pipe_intr(sc->sc_iface, 0x83, USBD_SHORT_XFER_OK,
546 &sc->zyd_ep[ZYD_ENDPT_IIN], sc, sc->ibuf, isize, zyd_intr,
547 USBD_DEFAULT_INTERVAL);
549 device_printf(sc->sc_dev, "open rx intr pipe failed: %s\n",
554 /* interrupt out (not necessarily an interrupt pipe) */
555 error = usbd_open_pipe(sc->sc_iface, 0x04, USBD_EXCLUSIVE_USE,
556 &sc->zyd_ep[ZYD_ENDPT_IOUT]);
558 device_printf(sc->sc_dev, "open tx intr pipe failed: %s\n",
564 error = usbd_open_pipe(sc->sc_iface, 0x82, USBD_EXCLUSIVE_USE,
565 &sc->zyd_ep[ZYD_ENDPT_BIN]);
567 device_printf(sc->sc_dev, "open rx pipe failed: %s\n",
573 error = usbd_open_pipe(sc->sc_iface, 0x01, USBD_EXCLUSIVE_USE,
574 &sc->zyd_ep[ZYD_ENDPT_BOUT]);
576 device_printf(sc->sc_dev, "open tx pipe failed: %s\n",
583 fail: zyd_close_pipes(sc);
588 zyd_close_pipes(struct zyd_softc *sc)
592 for (i = 0; i < ZYD_ENDPT_CNT; i++) {
593 if (sc->zyd_ep[i] != NULL) {
594 usbd_abort_pipe(sc->zyd_ep[i]);
595 usbd_close_pipe(sc->zyd_ep[i]);
596 sc->zyd_ep[i] = NULL;
599 if (sc->ibuf != NULL) {
600 free(sc->ibuf, M_USBDEV);
606 zyd_alloc_tx_list(struct zyd_softc *sc)
612 for (i = 0; i < ZYD_TX_LIST_CNT; i++) {
613 struct zyd_tx_data *data = &sc->tx_data[i];
615 data->sc = sc; /* backpointer for callbacks */
617 data->xfer = usbd_alloc_xfer(sc->sc_udev);
618 if (data->xfer == NULL) {
619 device_printf(sc->sc_dev,
620 "could not allocate tx xfer\n");
624 data->buf = usbd_alloc_buffer(data->xfer, ZYD_MAX_TXBUFSZ);
625 if (data->buf == NULL) {
626 device_printf(sc->sc_dev,
627 "could not allocate tx buffer\n");
632 /* clear Tx descriptor */
633 bzero(data->buf, sizeof(struct zyd_tx_desc));
637 fail: zyd_free_tx_list(sc);
642 zyd_free_tx_list(struct zyd_softc *sc)
646 for (i = 0; i < ZYD_TX_LIST_CNT; i++) {
647 struct zyd_tx_data *data = &sc->tx_data[i];
649 if (data->xfer != NULL) {
650 usbd_free_xfer(data->xfer);
653 if (data->ni != NULL) {
654 ieee80211_free_node(data->ni);
661 zyd_alloc_rx_list(struct zyd_softc *sc)
665 for (i = 0; i < ZYD_RX_LIST_CNT; i++) {
666 struct zyd_rx_data *data = &sc->rx_data[i];
668 data->sc = sc; /* backpointer for callbacks */
670 data->xfer = usbd_alloc_xfer(sc->sc_udev);
671 if (data->xfer == NULL) {
672 device_printf(sc->sc_dev,
673 "could not allocate rx xfer\n");
677 data->buf = usbd_alloc_buffer(data->xfer, ZYX_MAX_RXBUFSZ);
678 if (data->buf == NULL) {
679 device_printf(sc->sc_dev,
680 "could not allocate rx buffer\n");
687 fail: zyd_free_rx_list(sc);
692 zyd_free_rx_list(struct zyd_softc *sc)
696 for (i = 0; i < ZYD_RX_LIST_CNT; i++) {
697 struct zyd_rx_data *data = &sc->rx_data[i];
699 if (data->xfer != NULL) {
700 usbd_free_xfer(data->xfer);
707 static struct ieee80211_node *
708 zyd_node_alloc(struct ieee80211vap *vap __unused,
709 const uint8_t mac[IEEE80211_ADDR_LEN] __unused)
713 zn = malloc(sizeof(struct zyd_node), M_80211_NODE, M_NOWAIT | M_ZERO);
714 return zn != NULL ? &zn->ni : NULL;
720 struct zyd_softc *sc = arg;
721 struct ifnet *ifp = sc->sc_ifp;
722 struct ieee80211com *ic = ifp->if_l2com;
723 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps);
724 struct zyd_vap *zvp = ZYD_VAP(vap);
726 switch (sc->sc_state) {
727 case IEEE80211_S_RUN:
729 struct ieee80211_node *ni = vap->iv_bss;
731 zyd_set_chan(sc, ic->ic_curchan);
733 if (vap->iv_opmode != IEEE80211_M_MONITOR) {
734 /* turn link LED on */
735 zyd_set_led(sc, ZYD_LED1, 1);
737 /* make data LED blink upon Tx */
738 zyd_write32(sc, sc->fwbase + ZYD_FW_LINK_STATUS, 1);
740 IEEE80211_ADDR_COPY(sc->sc_bssid, ni->ni_bssid);
741 zyd_set_bssid(sc, sc->sc_bssid);
744 if (vap->iv_opmode == IEEE80211_M_STA) {
745 /* fake a join to init the tx rate */
755 zvp->newstate(vap, sc->sc_state, sc->sc_arg);
756 if (vap->iv_newstate_cb != NULL)
757 vap->iv_newstate_cb(vap, sc->sc_state, sc->sc_arg);
758 IEEE80211_UNLOCK(ic);
762 zyd_newstate(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg)
764 struct zyd_vap *zvp = ZYD_VAP(vap);
765 struct ieee80211com *ic = vap->iv_ic;
766 struct zyd_softc *sc = ic->ic_ifp->if_softc;
768 usb_rem_task(sc->sc_udev, &sc->sc_scantask);
769 usb_rem_task(sc->sc_udev, &sc->sc_task);
770 callout_stop(&sc->sc_watchdog_ch);
772 /* do it in a process context */
773 sc->sc_state = nstate;
776 if (nstate == IEEE80211_S_INIT) {
777 zvp->newstate(vap, nstate, arg);
780 usb_add_task(sc->sc_udev, &sc->sc_task, USB_TASKQ_DRIVER);
786 zyd_cmd(struct zyd_softc *sc, uint16_t code, const void *idata, int ilen,
787 void *odata, int olen, u_int flags)
789 usbd_xfer_handle xfer;
795 if (sc->sc_flags & ZYD_FLAG_DETACHING)
798 if ((xfer = usbd_alloc_xfer(sc->sc_udev)) == NULL)
801 cmd.code = htole16(code);
802 bcopy(idata, cmd.data, ilen);
804 xferflags = USBD_FORCE_SHORT_XFER;
805 if (!(flags & ZYD_CMD_FLAG_READ))
806 xferflags |= USBD_SYNCHRONOUS;
810 rq.len = olen / sizeof(struct zyd_pair);
811 STAILQ_INSERT_TAIL(&sc->sc_rqh, &rq, rq);
814 usbd_setup_xfer(xfer, sc->zyd_ep[ZYD_ENDPT_IOUT], 0, &cmd,
815 sizeof(uint16_t) + ilen, xferflags, ZYD_INTR_TIMEOUT, NULL);
816 error = usbd_transfer(xfer);
817 if (error != USBD_IN_PROGRESS && error != 0) {
818 device_printf(sc->sc_dev, "could not send command (error=%s)\n",
820 (void)usbd_free_xfer(xfer);
823 if (!(flags & ZYD_CMD_FLAG_READ)) {
824 (void)usbd_free_xfer(xfer);
825 return 0; /* write: don't wait for reply */
827 /* wait at most one second for command reply */
828 error = tsleep(odata, PCATCH, "zydcmd", hz);
829 if (error == EWOULDBLOCK)
830 device_printf(sc->sc_dev, "zyd_read sleep timeout\n");
831 STAILQ_REMOVE(&sc->sc_rqh, &rq, rq, rq);
833 (void)usbd_free_xfer(xfer);
838 zyd_read16(struct zyd_softc *sc, uint16_t reg, uint16_t *val)
844 error = zyd_cmd(sc, ZYD_CMD_IORD, ®, sizeof(reg), &tmp, sizeof(tmp),
847 *val = le16toh(tmp.val);
852 zyd_read32(struct zyd_softc *sc, uint16_t reg, uint32_t *val)
854 struct zyd_pair tmp[2];
858 regs[0] = htole16(ZYD_REG32_HI(reg));
859 regs[1] = htole16(ZYD_REG32_LO(reg));
860 error = zyd_cmd(sc, ZYD_CMD_IORD, regs, sizeof(regs), tmp, sizeof(tmp),
863 *val = le16toh(tmp[0].val) << 16 | le16toh(tmp[1].val);
868 zyd_write16(struct zyd_softc *sc, uint16_t reg, uint16_t val)
870 struct zyd_pair pair;
872 pair.reg = htole16(reg);
873 pair.val = htole16(val);
875 return zyd_cmd(sc, ZYD_CMD_IOWR, &pair, sizeof(pair), NULL, 0, 0);
879 zyd_write32(struct zyd_softc *sc, uint16_t reg, uint32_t val)
881 struct zyd_pair pair[2];
883 pair[0].reg = htole16(ZYD_REG32_HI(reg));
884 pair[0].val = htole16(val >> 16);
885 pair[1].reg = htole16(ZYD_REG32_LO(reg));
886 pair[1].val = htole16(val & 0xffff);
888 return zyd_cmd(sc, ZYD_CMD_IOWR, pair, sizeof(pair), NULL, 0, 0);
892 zyd_rfwrite(struct zyd_softc *sc, uint32_t val)
894 struct zyd_rf *rf = &sc->sc_rf;
895 struct zyd_rfwrite req;
899 (void)zyd_read16(sc, ZYD_CR203, &cr203);
900 cr203 &= ~(ZYD_RF_IF_LE | ZYD_RF_CLK | ZYD_RF_DATA);
902 req.code = htole16(2);
903 req.width = htole16(rf->width);
904 for (i = 0; i < rf->width; i++) {
905 req.bit[i] = htole16(cr203);
906 if (val & (1 << (rf->width - 1 - i)))
907 req.bit[i] |= htole16(ZYD_RF_DATA);
909 return zyd_cmd(sc, ZYD_CMD_RFCFG, &req, 4 + 2 * rf->width, NULL, 0, 0);
913 zyd_lock_phy(struct zyd_softc *sc)
917 (void)zyd_read32(sc, ZYD_MAC_MISC, &tmp);
918 tmp &= ~ZYD_UNLOCK_PHY_REGS;
919 (void)zyd_write32(sc, ZYD_MAC_MISC, tmp);
923 zyd_unlock_phy(struct zyd_softc *sc)
927 (void)zyd_read32(sc, ZYD_MAC_MISC, &tmp);
928 tmp |= ZYD_UNLOCK_PHY_REGS;
929 (void)zyd_write32(sc, ZYD_MAC_MISC, tmp);
936 zyd_rfmd_init(struct zyd_rf *rf)
938 #define N(a) (sizeof(a) / sizeof((a)[0]))
939 struct zyd_softc *sc = rf->rf_sc;
940 static const struct zyd_phy_pair phyini[] = ZYD_RFMD_PHY;
941 static const uint32_t rfini[] = ZYD_RFMD_RF;
944 /* init RF-dependent PHY registers */
945 for (i = 0; i < N(phyini); i++) {
946 error = zyd_write16(sc, phyini[i].reg, phyini[i].val);
951 /* init RFMD radio */
952 for (i = 0; i < N(rfini); i++) {
953 if ((error = zyd_rfwrite(sc, rfini[i])) != 0)
961 zyd_rfmd_switch_radio(struct zyd_rf *rf, int on)
963 struct zyd_softc *sc = rf->rf_sc;
965 (void)zyd_write16(sc, ZYD_CR10, on ? 0x89 : 0x15);
966 (void)zyd_write16(sc, ZYD_CR11, on ? 0x00 : 0x81);
972 zyd_rfmd_set_channel(struct zyd_rf *rf, uint8_t chan)
974 struct zyd_softc *sc = rf->rf_sc;
975 static const struct {
977 } rfprog[] = ZYD_RFMD_CHANTABLE;
979 (void)zyd_rfwrite(sc, rfprog[chan - 1].r1);
980 (void)zyd_rfwrite(sc, rfprog[chan - 1].r2);
989 zyd_al2230_init(struct zyd_rf *rf)
991 #define N(a) (sizeof(a) / sizeof((a)[0]))
992 struct zyd_softc *sc = rf->rf_sc;
993 static const struct zyd_phy_pair phyini[] = ZYD_AL2230_PHY;
994 static const uint32_t rfini[] = ZYD_AL2230_RF;
997 /* init RF-dependent PHY registers */
998 for (i = 0; i < N(phyini); i++) {
999 error = zyd_write16(sc, phyini[i].reg, phyini[i].val);
1004 /* init AL2230 radio */
1005 for (i = 0; i < N(rfini); i++) {
1006 if ((error = zyd_rfwrite(sc, rfini[i])) != 0)
1014 zyd_al2230_init_b(struct zyd_rf *rf)
1016 #define N(a) (sizeof(a) / sizeof((a)[0]))
1017 struct zyd_softc *sc = rf->rf_sc;
1018 static const struct zyd_phy_pair phyini[] = ZYD_AL2230_PHY_B;
1019 static const uint32_t rfini[] = ZYD_AL2230_RF_B;
1022 /* init RF-dependent PHY registers */
1023 for (i = 0; i < N(phyini); i++) {
1024 error = zyd_write16(sc, phyini[i].reg, phyini[i].val);
1029 /* init AL2230 radio */
1030 for (i = 0; i < N(rfini); i++) {
1031 if ((error = zyd_rfwrite(sc, rfini[i])) != 0)
1039 zyd_al2230_switch_radio(struct zyd_rf *rf, int on)
1041 struct zyd_softc *sc = rf->rf_sc;
1042 int on251 = (sc->mac_rev == ZYD_ZD1211) ? 0x3f : 0x7f;
1044 (void)zyd_write16(sc, ZYD_CR11, on ? 0x00 : 0x04);
1045 (void)zyd_write16(sc, ZYD_CR251, on ? on251 : 0x2f);
1051 zyd_al2230_set_channel(struct zyd_rf *rf, uint8_t chan)
1053 struct zyd_softc *sc = rf->rf_sc;
1054 static const struct {
1055 uint32_t r1, r2, r3;
1056 } rfprog[] = ZYD_AL2230_CHANTABLE;
1058 (void)zyd_rfwrite(sc, rfprog[chan - 1].r1);
1059 (void)zyd_rfwrite(sc, rfprog[chan - 1].r2);
1060 (void)zyd_rfwrite(sc, rfprog[chan - 1].r3);
1062 (void)zyd_write16(sc, ZYD_CR138, 0x28);
1063 (void)zyd_write16(sc, ZYD_CR203, 0x06);
1069 * AL7230B RF methods.
1072 zyd_al7230B_init(struct zyd_rf *rf)
1074 #define N(a) (sizeof(a) / sizeof((a)[0]))
1075 struct zyd_softc *sc = rf->rf_sc;
1076 static const struct zyd_phy_pair phyini_1[] = ZYD_AL7230B_PHY_1;
1077 static const struct zyd_phy_pair phyini_2[] = ZYD_AL7230B_PHY_2;
1078 static const struct zyd_phy_pair phyini_3[] = ZYD_AL7230B_PHY_3;
1079 static const uint32_t rfini_1[] = ZYD_AL7230B_RF_1;
1080 static const uint32_t rfini_2[] = ZYD_AL7230B_RF_2;
1083 /* for AL7230B, PHY and RF need to be initialized in "phases" */
1085 /* init RF-dependent PHY registers, part one */
1086 for (i = 0; i < N(phyini_1); i++) {
1087 error = zyd_write16(sc, phyini_1[i].reg, phyini_1[i].val);
1091 /* init AL7230B radio, part one */
1092 for (i = 0; i < N(rfini_1); i++) {
1093 if ((error = zyd_rfwrite(sc, rfini_1[i])) != 0)
1096 /* init RF-dependent PHY registers, part two */
1097 for (i = 0; i < N(phyini_2); i++) {
1098 error = zyd_write16(sc, phyini_2[i].reg, phyini_2[i].val);
1102 /* init AL7230B radio, part two */
1103 for (i = 0; i < N(rfini_2); i++) {
1104 if ((error = zyd_rfwrite(sc, rfini_2[i])) != 0)
1107 /* init RF-dependent PHY registers, part three */
1108 for (i = 0; i < N(phyini_3); i++) {
1109 error = zyd_write16(sc, phyini_3[i].reg, phyini_3[i].val);
1119 zyd_al7230B_switch_radio(struct zyd_rf *rf, int on)
1121 struct zyd_softc *sc = rf->rf_sc;
1123 (void)zyd_write16(sc, ZYD_CR11, on ? 0x00 : 0x04);
1124 (void)zyd_write16(sc, ZYD_CR251, on ? 0x3f : 0x2f);
1130 zyd_al7230B_set_channel(struct zyd_rf *rf, uint8_t chan)
1132 #define N(a) (sizeof(a) / sizeof((a)[0]))
1133 struct zyd_softc *sc = rf->rf_sc;
1134 static const struct {
1136 } rfprog[] = ZYD_AL7230B_CHANTABLE;
1137 static const uint32_t rfsc[] = ZYD_AL7230B_RF_SETCHANNEL;
1140 (void)zyd_write16(sc, ZYD_CR240, 0x57);
1141 (void)zyd_write16(sc, ZYD_CR251, 0x2f);
1143 for (i = 0; i < N(rfsc); i++) {
1144 if ((error = zyd_rfwrite(sc, rfsc[i])) != 0)
1148 (void)zyd_write16(sc, ZYD_CR128, 0x14);
1149 (void)zyd_write16(sc, ZYD_CR129, 0x12);
1150 (void)zyd_write16(sc, ZYD_CR130, 0x10);
1151 (void)zyd_write16(sc, ZYD_CR38, 0x38);
1152 (void)zyd_write16(sc, ZYD_CR136, 0xdf);
1154 (void)zyd_rfwrite(sc, rfprog[chan - 1].r1);
1155 (void)zyd_rfwrite(sc, rfprog[chan - 1].r2);
1156 (void)zyd_rfwrite(sc, 0x3c9000);
1158 (void)zyd_write16(sc, ZYD_CR251, 0x3f);
1159 (void)zyd_write16(sc, ZYD_CR203, 0x06);
1160 (void)zyd_write16(sc, ZYD_CR240, 0x08);
1167 * AL2210 RF methods.
1170 zyd_al2210_init(struct zyd_rf *rf)
1172 #define N(a) (sizeof(a) / sizeof((a)[0]))
1173 struct zyd_softc *sc = rf->rf_sc;
1174 static const struct zyd_phy_pair phyini[] = ZYD_AL2210_PHY;
1175 static const uint32_t rfini[] = ZYD_AL2210_RF;
1179 (void)zyd_write32(sc, ZYD_CR18, 2);
1181 /* init RF-dependent PHY registers */
1182 for (i = 0; i < N(phyini); i++) {
1183 error = zyd_write16(sc, phyini[i].reg, phyini[i].val);
1187 /* init AL2210 radio */
1188 for (i = 0; i < N(rfini); i++) {
1189 if ((error = zyd_rfwrite(sc, rfini[i])) != 0)
1192 (void)zyd_write16(sc, ZYD_CR47, 0x1e);
1193 (void)zyd_read32(sc, ZYD_CR_RADIO_PD, &tmp);
1194 (void)zyd_write32(sc, ZYD_CR_RADIO_PD, tmp & ~1);
1195 (void)zyd_write32(sc, ZYD_CR_RADIO_PD, tmp | 1);
1196 (void)zyd_write32(sc, ZYD_CR_RFCFG, 0x05);
1197 (void)zyd_write32(sc, ZYD_CR_RFCFG, 0x00);
1198 (void)zyd_write16(sc, ZYD_CR47, 0x1e);
1199 (void)zyd_write32(sc, ZYD_CR18, 3);
1206 zyd_al2210_switch_radio(struct zyd_rf *rf, int on)
1208 /* vendor driver does nothing for this RF chip */
1214 zyd_al2210_set_channel(struct zyd_rf *rf, uint8_t chan)
1216 struct zyd_softc *sc = rf->rf_sc;
1217 static const uint32_t rfprog[] = ZYD_AL2210_CHANTABLE;
1220 (void)zyd_write32(sc, ZYD_CR18, 2);
1221 (void)zyd_write16(sc, ZYD_CR47, 0x1e);
1222 (void)zyd_read32(sc, ZYD_CR_RADIO_PD, &tmp);
1223 (void)zyd_write32(sc, ZYD_CR_RADIO_PD, tmp & ~1);
1224 (void)zyd_write32(sc, ZYD_CR_RADIO_PD, tmp | 1);
1225 (void)zyd_write32(sc, ZYD_CR_RFCFG, 0x05);
1227 (void)zyd_write32(sc, ZYD_CR_RFCFG, 0x00);
1228 (void)zyd_write16(sc, ZYD_CR47, 0x1e);
1230 /* actually set the channel */
1231 (void)zyd_rfwrite(sc, rfprog[chan - 1]);
1233 (void)zyd_write32(sc, ZYD_CR18, 3);
1242 zyd_gct_init(struct zyd_rf *rf)
1244 #define N(a) (sizeof(a) / sizeof((a)[0]))
1245 struct zyd_softc *sc = rf->rf_sc;
1246 static const struct zyd_phy_pair phyini[] = ZYD_GCT_PHY;
1247 static const uint32_t rfini[] = ZYD_GCT_RF;
1250 /* init RF-dependent PHY registers */
1251 for (i = 0; i < N(phyini); i++) {
1252 error = zyd_write16(sc, phyini[i].reg, phyini[i].val);
1256 /* init cgt radio */
1257 for (i = 0; i < N(rfini); i++) {
1258 if ((error = zyd_rfwrite(sc, rfini[i])) != 0)
1266 zyd_gct_switch_radio(struct zyd_rf *rf, int on)
1268 /* vendor driver does nothing for this RF chip */
1274 zyd_gct_set_channel(struct zyd_rf *rf, uint8_t chan)
1276 struct zyd_softc *sc = rf->rf_sc;
1277 static const uint32_t rfprog[] = ZYD_GCT_CHANTABLE;
1279 (void)zyd_rfwrite(sc, 0x1c0000);
1280 (void)zyd_rfwrite(sc, rfprog[chan - 1]);
1281 (void)zyd_rfwrite(sc, 0x1c0008);
1290 zyd_maxim_init(struct zyd_rf *rf)
1292 #define N(a) (sizeof(a) / sizeof((a)[0]))
1293 struct zyd_softc *sc = rf->rf_sc;
1294 static const struct zyd_phy_pair phyini[] = ZYD_MAXIM_PHY;
1295 static const uint32_t rfini[] = ZYD_MAXIM_RF;
1299 /* init RF-dependent PHY registers */
1300 for (i = 0; i < N(phyini); i++) {
1301 error = zyd_write16(sc, phyini[i].reg, phyini[i].val);
1305 (void)zyd_read16(sc, ZYD_CR203, &tmp);
1306 (void)zyd_write16(sc, ZYD_CR203, tmp & ~(1 << 4));
1308 /* init maxim radio */
1309 for (i = 0; i < N(rfini); i++) {
1310 if ((error = zyd_rfwrite(sc, rfini[i])) != 0)
1313 (void)zyd_read16(sc, ZYD_CR203, &tmp);
1314 (void)zyd_write16(sc, ZYD_CR203, tmp | (1 << 4));
1321 zyd_maxim_switch_radio(struct zyd_rf *rf, int on)
1323 /* vendor driver does nothing for this RF chip */
1329 zyd_maxim_set_channel(struct zyd_rf *rf, uint8_t chan)
1331 #define N(a) (sizeof(a) / sizeof((a)[0]))
1332 struct zyd_softc *sc = rf->rf_sc;
1333 static const struct zyd_phy_pair phyini[] = ZYD_MAXIM_PHY;
1334 static const uint32_t rfini[] = ZYD_MAXIM_RF;
1335 static const struct {
1337 } rfprog[] = ZYD_MAXIM_CHANTABLE;
1342 * Do the same as we do when initializing it, except for the channel
1343 * values coming from the two channel tables.
1346 /* init RF-dependent PHY registers */
1347 for (i = 0; i < N(phyini); i++) {
1348 error = zyd_write16(sc, phyini[i].reg, phyini[i].val);
1352 (void)zyd_read16(sc, ZYD_CR203, &tmp);
1353 (void)zyd_write16(sc, ZYD_CR203, tmp & ~(1 << 4));
1355 /* first two values taken from the chantables */
1356 (void)zyd_rfwrite(sc, rfprog[chan - 1].r1);
1357 (void)zyd_rfwrite(sc, rfprog[chan - 1].r2);
1359 /* init maxim radio - skipping the two first values */
1360 for (i = 2; i < N(rfini); i++) {
1361 if ((error = zyd_rfwrite(sc, rfini[i])) != 0)
1364 (void)zyd_read16(sc, ZYD_CR203, &tmp);
1365 (void)zyd_write16(sc, ZYD_CR203, tmp | (1 << 4));
1372 * Maxim2 RF methods.
1375 zyd_maxim2_init(struct zyd_rf *rf)
1377 #define N(a) (sizeof(a) / sizeof((a)[0]))
1378 struct zyd_softc *sc = rf->rf_sc;
1379 static const struct zyd_phy_pair phyini[] = ZYD_MAXIM2_PHY;
1380 static const uint32_t rfini[] = ZYD_MAXIM2_RF;
1384 /* init RF-dependent PHY registers */
1385 for (i = 0; i < N(phyini); i++) {
1386 error = zyd_write16(sc, phyini[i].reg, phyini[i].val);
1390 (void)zyd_read16(sc, ZYD_CR203, &tmp);
1391 (void)zyd_write16(sc, ZYD_CR203, tmp & ~(1 << 4));
1393 /* init maxim2 radio */
1394 for (i = 0; i < N(rfini); i++) {
1395 if ((error = zyd_rfwrite(sc, rfini[i])) != 0)
1398 (void)zyd_read16(sc, ZYD_CR203, &tmp);
1399 (void)zyd_write16(sc, ZYD_CR203, tmp | (1 << 4));
1406 zyd_maxim2_switch_radio(struct zyd_rf *rf, int on)
1408 /* vendor driver does nothing for this RF chip */
1414 zyd_maxim2_set_channel(struct zyd_rf *rf, uint8_t chan)
1416 #define N(a) (sizeof(a) / sizeof((a)[0]))
1417 struct zyd_softc *sc = rf->rf_sc;
1418 static const struct zyd_phy_pair phyini[] = ZYD_MAXIM2_PHY;
1419 static const uint32_t rfini[] = ZYD_MAXIM2_RF;
1420 static const struct {
1422 } rfprog[] = ZYD_MAXIM2_CHANTABLE;
1427 * Do the same as we do when initializing it, except for the channel
1428 * values coming from the two channel tables.
1431 /* init RF-dependent PHY registers */
1432 for (i = 0; i < N(phyini); i++) {
1433 error = zyd_write16(sc, phyini[i].reg, phyini[i].val);
1437 (void)zyd_read16(sc, ZYD_CR203, &tmp);
1438 (void)zyd_write16(sc, ZYD_CR203, tmp & ~(1 << 4));
1440 /* first two values taken from the chantables */
1441 (void)zyd_rfwrite(sc, rfprog[chan - 1].r1);
1442 (void)zyd_rfwrite(sc, rfprog[chan - 1].r2);
1444 /* init maxim2 radio - skipping the two first values */
1445 for (i = 2; i < N(rfini); i++) {
1446 if ((error = zyd_rfwrite(sc, rfini[i])) != 0)
1449 (void)zyd_read16(sc, ZYD_CR203, &tmp);
1450 (void)zyd_write16(sc, ZYD_CR203, tmp | (1 << 4));
1457 zyd_rf_attach(struct zyd_softc *sc, uint8_t type)
1459 struct zyd_rf *rf = &sc->sc_rf;
1465 rf->init = zyd_rfmd_init;
1466 rf->switch_radio = zyd_rfmd_switch_radio;
1467 rf->set_channel = zyd_rfmd_set_channel;
1468 rf->width = 24; /* 24-bit RF values */
1471 if (sc->mac_rev == ZYD_ZD1211B)
1472 rf->init = zyd_al2230_init_b;
1474 rf->init = zyd_al2230_init;
1475 rf->switch_radio = zyd_al2230_switch_radio;
1476 rf->set_channel = zyd_al2230_set_channel;
1477 rf->width = 24; /* 24-bit RF values */
1479 case ZYD_RF_AL7230B:
1480 rf->init = zyd_al7230B_init;
1481 rf->switch_radio = zyd_al7230B_switch_radio;
1482 rf->set_channel = zyd_al7230B_set_channel;
1483 rf->width = 24; /* 24-bit RF values */
1486 rf->init = zyd_al2210_init;
1487 rf->switch_radio = zyd_al2210_switch_radio;
1488 rf->set_channel = zyd_al2210_set_channel;
1489 rf->width = 24; /* 24-bit RF values */
1492 rf->init = zyd_gct_init;
1493 rf->switch_radio = zyd_gct_switch_radio;
1494 rf->set_channel = zyd_gct_set_channel;
1495 rf->width = 21; /* 21-bit RF values */
1497 case ZYD_RF_MAXIM_NEW:
1498 rf->init = zyd_maxim_init;
1499 rf->switch_radio = zyd_maxim_switch_radio;
1500 rf->set_channel = zyd_maxim_set_channel;
1501 rf->width = 18; /* 18-bit RF values */
1503 case ZYD_RF_MAXIM_NEW2:
1504 rf->init = zyd_maxim2_init;
1505 rf->switch_radio = zyd_maxim2_switch_radio;
1506 rf->set_channel = zyd_maxim2_set_channel;
1507 rf->width = 18; /* 18-bit RF values */
1510 device_printf(sc->sc_dev,
1511 "sorry, radio \"%s\" is not supported yet\n",
1519 zyd_rf_name(uint8_t type)
1521 static const char * const zyd_rfs[] = {
1522 "unknown", "unknown", "UW2451", "UCHIP", "AL2230",
1523 "AL7230B", "THETA", "AL2210", "MAXIM_NEW", "GCT",
1524 "PV2000", "RALINK", "INTERSIL", "RFMD", "MAXIM_NEW2",
1528 return zyd_rfs[(type > 15) ? 0 : type];
1532 zyd_hw_init(struct zyd_softc *sc)
1534 struct zyd_rf *rf = &sc->sc_rf;
1535 const struct zyd_phy_pair *phyp;
1539 /* specify that the plug and play is finished */
1540 (void)zyd_write32(sc, ZYD_MAC_AFTER_PNP, 1);
1542 (void)zyd_read16(sc, ZYD_FIRMWARE_BASE_ADDR, &sc->fwbase);
1543 DPRINTF(("firmware base address=0x%04x\n", sc->fwbase));
1545 /* retrieve firmware revision number */
1546 (void)zyd_read16(sc, sc->fwbase + ZYD_FW_FIRMWARE_REV, &sc->fw_rev);
1548 (void)zyd_write32(sc, ZYD_CR_GPI_EN, 0);
1549 (void)zyd_write32(sc, ZYD_MAC_CONT_WIN_LIMIT, 0x7f043f);
1551 /* disable interrupts */
1552 (void)zyd_write32(sc, ZYD_CR_INTERRUPT, 0);
1556 phyp = (sc->mac_rev == ZYD_ZD1211B) ? zyd_def_phyB : zyd_def_phy;
1557 for (; phyp->reg != 0; phyp++) {
1558 if ((error = zyd_write16(sc, phyp->reg, phyp->val)) != 0)
1561 if (sc->fix_cr157) {
1562 if (zyd_read32(sc, ZYD_EEPROM_PHY_REG, &tmp) == 0)
1563 (void)zyd_write32(sc, ZYD_CR157, tmp >> 8);
1568 zyd_write32(sc, ZYD_MAC_ACK_EXT, 0x00000020);
1569 zyd_write32(sc, ZYD_CR_ADDA_MBIAS_WT, 0x30000808);
1571 if (sc->mac_rev == ZYD_ZD1211) {
1572 zyd_write32(sc, ZYD_MAC_RETRY, 0x00000002);
1574 zyd_write32(sc, ZYD_MACB_MAX_RETRY, 0x02020202);
1575 zyd_write32(sc, ZYD_MACB_TXPWR_CTL4, 0x007f003f);
1576 zyd_write32(sc, ZYD_MACB_TXPWR_CTL3, 0x007f003f);
1577 zyd_write32(sc, ZYD_MACB_TXPWR_CTL2, 0x003f001f);
1578 zyd_write32(sc, ZYD_MACB_TXPWR_CTL1, 0x001f000f);
1579 zyd_write32(sc, ZYD_MACB_AIFS_CTL1, 0x00280028);
1580 zyd_write32(sc, ZYD_MACB_AIFS_CTL2, 0x008C003C);
1581 zyd_write32(sc, ZYD_MACB_TXOP, 0x01800824);
1584 zyd_write32(sc, ZYD_MAC_SNIFFER, 0x00000000);
1585 zyd_write32(sc, ZYD_MAC_RXFILTER, 0x00000000);
1586 zyd_write32(sc, ZYD_MAC_GHTBL, 0x00000000);
1587 zyd_write32(sc, ZYD_MAC_GHTBH, 0x80000000);
1588 zyd_write32(sc, ZYD_MAC_MISC, 0x000000a4);
1589 zyd_write32(sc, ZYD_CR_ADDA_PWR_DWN, 0x0000007f);
1590 zyd_write32(sc, ZYD_MAC_BCNCFG, 0x00f00401);
1591 zyd_write32(sc, ZYD_MAC_PHY_DELAY2, 0x00000000);
1592 zyd_write32(sc, ZYD_MAC_ACK_EXT, 0x00000080);
1593 zyd_write32(sc, ZYD_CR_ADDA_PWR_DWN, 0x00000000);
1594 zyd_write32(sc, ZYD_MAC_SIFS_ACK_TIME, 0x00000100);
1595 zyd_write32(sc, ZYD_MAC_DIFS_EIFS_SIFS, 0x0547c032);
1596 zyd_write32(sc, ZYD_CR_RX_PE_DELAY, 0x00000070);
1597 zyd_write32(sc, ZYD_CR_PS_CTRL, 0x10000000);
1598 zyd_write32(sc, ZYD_MAC_RTSCTSRATE, 0x02030203);
1599 zyd_write32(sc, ZYD_MAC_RX_THRESHOLD, 0x000c0640);
1600 zyd_write32(sc, ZYD_MAC_BACKOFF_PROTECT, 0x00000114);
1604 error = (*rf->init)(rf);
1607 device_printf(sc->sc_dev,
1608 "radio initialization failed, error %d\n", error);
1612 /* init beacon interval to 100ms */
1613 if ((error = zyd_set_beacon_interval(sc, 100)) != 0)
1620 zyd_read_eeprom(struct zyd_softc *sc)
1622 struct ifnet *ifp = sc->sc_ifp;
1623 struct ieee80211com *ic = ifp->if_l2com;
1628 /* read MAC address */
1629 (void)zyd_read32(sc, ZYD_EEPROM_MAC_ADDR_P1, &tmp);
1630 ic->ic_myaddr[0] = tmp & 0xff;
1631 ic->ic_myaddr[1] = tmp >> 8;
1632 ic->ic_myaddr[2] = tmp >> 16;
1633 ic->ic_myaddr[3] = tmp >> 24;
1634 (void)zyd_read32(sc, ZYD_EEPROM_MAC_ADDR_P2, &tmp);
1635 ic->ic_myaddr[4] = tmp & 0xff;
1636 ic->ic_myaddr[5] = tmp >> 8;
1638 (void)zyd_read32(sc, ZYD_EEPROM_POD, &tmp);
1639 sc->rf_rev = tmp & 0x0f;
1640 sc->fix_cr47 = (tmp >> 8 ) & 0x01;
1641 sc->fix_cr157 = (tmp >> 13) & 0x01;
1642 sc->pa_rev = (tmp >> 16) & 0x0f;
1644 /* read regulatory domain (currently unused) */
1645 (void)zyd_read32(sc, ZYD_EEPROM_SUBID, &tmp);
1646 sc->regdomain = tmp >> 16;
1647 DPRINTF(("regulatory domain %x\n", sc->regdomain));
1648 /* XXX propagate to net80211 after mapping to SKU */
1650 /* read Tx power calibration tables */
1651 for (i = 0; i < 7; i++) {
1652 (void)zyd_read16(sc, ZYD_EEPROM_PWR_CAL + i, &val);
1653 sc->pwr_cal[i * 2] = val >> 8;
1654 sc->pwr_cal[i * 2 + 1] = val & 0xff;
1656 (void)zyd_read16(sc, ZYD_EEPROM_PWR_INT + i, &val);
1657 sc->pwr_int[i * 2] = val >> 8;
1658 sc->pwr_int[i * 2 + 1] = val & 0xff;
1660 (void)zyd_read16(sc, ZYD_EEPROM_36M_CAL + i, &val);
1661 sc->ofdm36_cal[i * 2] = val >> 8;
1662 sc->ofdm36_cal[i * 2 + 1] = val & 0xff;
1664 (void)zyd_read16(sc, ZYD_EEPROM_48M_CAL + i, &val);
1665 sc->ofdm48_cal[i * 2] = val >> 8;
1666 sc->ofdm48_cal[i * 2 + 1] = val & 0xff;
1668 (void)zyd_read16(sc, ZYD_EEPROM_54M_CAL + i, &val);
1669 sc->ofdm54_cal[i * 2] = val >> 8;
1670 sc->ofdm54_cal[i * 2 + 1] = val & 0xff;
1676 zyd_set_macaddr(struct zyd_softc *sc, const uint8_t *addr)
1680 tmp = addr[3] << 24 | addr[2] << 16 | addr[1] << 8 | addr[0];
1681 (void)zyd_write32(sc, ZYD_MAC_MACADRL, tmp);
1683 tmp = addr[5] << 8 | addr[4];
1684 (void)zyd_write32(sc, ZYD_MAC_MACADRH, tmp);
1690 zyd_set_bssid(struct zyd_softc *sc, const uint8_t *addr)
1694 tmp = addr[3] << 24 | addr[2] << 16 | addr[1] << 8 | addr[0];
1695 (void)zyd_write32(sc, ZYD_MAC_BSSADRL, tmp);
1697 tmp = addr[5] << 8 | addr[4];
1698 (void)zyd_write32(sc, ZYD_MAC_BSSADRH, tmp);
1704 zyd_switch_radio(struct zyd_softc *sc, int on)
1706 struct zyd_rf *rf = &sc->sc_rf;
1710 error = (*rf->switch_radio)(rf, on);
1717 zyd_set_led(struct zyd_softc *sc, int which, int on)
1721 (void)zyd_read32(sc, ZYD_MAC_TX_PE_CONTROL, &tmp);
1725 (void)zyd_write32(sc, ZYD_MAC_TX_PE_CONTROL, tmp);
1729 zyd_set_multi(void *arg)
1731 struct zyd_softc *sc = arg;
1732 struct ifnet *ifp = sc->sc_ifp;
1733 struct ieee80211com *ic = ifp->if_l2com;
1734 struct ifmultiaddr *ifma;
1738 if (!(ifp->if_flags & IFF_UP))
1744 if (ic->ic_opmode == IEEE80211_M_MONITOR ||
1745 (ifp->if_flags & (IFF_ALLMULTI | IFF_PROMISC))) {
1750 TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
1751 if (ifma->ifma_addr->sa_family != AF_LINK)
1753 v = ((uint8_t *)LLADDR((struct sockaddr_dl *)
1754 ifma->ifma_addr))[5] >> 2;
1758 high |= 1 << (v - 32);
1760 IF_ADDR_UNLOCK(ifp);
1763 /* reprogram multicast global hash table */
1764 zyd_write32(sc, ZYD_MAC_GHTBL, low);
1765 zyd_write32(sc, ZYD_MAC_GHTBH, high);
1769 zyd_update_mcast(struct ifnet *ifp)
1771 struct zyd_softc *sc = ifp->if_softc;
1773 usb_add_task(sc->sc_udev, &sc->sc_mcasttask, USB_TASKQ_DRIVER);
1777 zyd_set_rxfilter(struct zyd_softc *sc)
1779 struct ifnet *ifp = sc->sc_ifp;
1780 struct ieee80211com *ic = ifp->if_l2com;
1783 switch (ic->ic_opmode) {
1784 case IEEE80211_M_STA:
1785 rxfilter = ZYD_FILTER_BSS;
1787 case IEEE80211_M_IBSS:
1788 case IEEE80211_M_HOSTAP:
1789 rxfilter = ZYD_FILTER_HOSTAP;
1791 case IEEE80211_M_MONITOR:
1792 rxfilter = ZYD_FILTER_MONITOR;
1795 /* should not get there */
1798 return zyd_write32(sc, ZYD_MAC_RXFILTER, rxfilter);
1802 zyd_set_chan(struct zyd_softc *sc, struct ieee80211_channel *c)
1804 struct ifnet *ifp = sc->sc_ifp;
1805 struct ieee80211com *ic = ifp->if_l2com;
1806 struct zyd_rf *rf = &sc->sc_rf;
1810 chan = ieee80211_chan2ieee(ic, c);
1811 if (chan == 0 || chan == IEEE80211_CHAN_ANY) {
1812 /* XXX should NEVER happen */
1813 device_printf(sc->sc_dev,
1814 "%s: invalid channel %x\n", __func__, chan);
1820 (*rf->set_channel)(rf, chan);
1822 /* update Tx power */
1823 (void)zyd_write16(sc, ZYD_CR31, sc->pwr_int[chan - 1]);
1825 if (sc->mac_rev == ZYD_ZD1211B) {
1826 (void)zyd_write16(sc, ZYD_CR67, sc->ofdm36_cal[chan - 1]);
1827 (void)zyd_write16(sc, ZYD_CR66, sc->ofdm48_cal[chan - 1]);
1828 (void)zyd_write16(sc, ZYD_CR65, sc->ofdm54_cal[chan - 1]);
1830 (void)zyd_write16(sc, ZYD_CR68, sc->pwr_cal[chan - 1]);
1832 (void)zyd_write16(sc, ZYD_CR69, 0x28);
1833 (void)zyd_write16(sc, ZYD_CR69, 0x2a);
1837 /* set CCK baseband gain from EEPROM */
1838 if (zyd_read32(sc, ZYD_EEPROM_PHY_REG, &tmp) == 0)
1839 (void)zyd_write16(sc, ZYD_CR47, tmp & 0xff);
1842 (void)zyd_write32(sc, ZYD_CR_CONFIG_PHILIPS, 0);
1846 sc->sc_rxtap.wr_chan_freq = sc->sc_txtap.wt_chan_freq =
1847 htole16(c->ic_freq);
1848 sc->sc_rxtap.wr_chan_flags = sc->sc_txtap.wt_chan_flags =
1849 htole16(c->ic_flags);
1853 zyd_set_beacon_interval(struct zyd_softc *sc, int bintval)
1855 /* XXX this is probably broken.. */
1856 (void)zyd_write32(sc, ZYD_CR_ATIM_WND_PERIOD, bintval - 2);
1857 (void)zyd_write32(sc, ZYD_CR_PRE_TBTT, bintval - 1);
1858 (void)zyd_write32(sc, ZYD_CR_BCN_INTERVAL, bintval);
1864 zyd_intr(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status)
1866 struct zyd_softc *sc = (struct zyd_softc *)priv;
1867 struct zyd_cmd *cmd;
1870 if (status != USBD_NORMAL_COMPLETION) {
1871 if (status == USBD_NOT_STARTED || status == USBD_CANCELLED)
1874 if (status == USBD_STALLED) {
1875 usbd_clear_endpoint_stall_async(
1876 sc->zyd_ep[ZYD_ENDPT_IIN]);
1881 cmd = (struct zyd_cmd *)sc->ibuf;
1883 if (le16toh(cmd->code) == ZYD_NOTIF_RETRYSTATUS) {
1884 struct zyd_notif_retry *retry =
1885 (struct zyd_notif_retry *)cmd->data;
1886 struct ifnet *ifp = sc->sc_ifp;
1887 struct ieee80211com *ic = ifp->if_l2com;
1888 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps);
1889 struct ieee80211_node *ni;
1891 DPRINTF(("retry intr: rate=0x%x addr=%s count=%d (0x%x)\n",
1892 le16toh(retry->rate), ether_sprintf(retry->macaddr),
1893 le16toh(retry->count) & 0xff, le16toh(retry->count)));
1896 * Find the node to which the packet was sent and update its
1897 * retry statistics. In BSS mode, this node is the AP we're
1898 * associated to so no lookup is actually needed.
1900 ni = ieee80211_find_txnode(vap, retry->macaddr);
1902 ieee80211_amrr_tx_complete(&ZYD_NODE(ni)->amn,
1903 IEEE80211_AMRR_FAILURE, 1);
1904 ieee80211_free_node(ni);
1906 if (le16toh(retry->count) & 0x100)
1907 ifp->if_oerrors++; /* too many retries */
1908 } else if (le16toh(cmd->code) == ZYD_NOTIF_IORD) {
1911 if (le16toh(*(uint16_t *)cmd->data) == ZYD_CR_INTERRUPT)
1912 return; /* HMAC interrupt */
1914 usbd_get_xfer_status(xfer, NULL, NULL, &datalen, NULL);
1915 datalen -= sizeof(cmd->code);
1916 datalen -= 2; /* XXX: padding? */
1918 STAILQ_FOREACH(rqp, &sc->sc_rqh, rq) {
1921 if (sizeof(struct zyd_pair) * rqp->len != datalen)
1923 for (i = 0; i < rqp->len; i++) {
1924 if (*(((const uint16_t *)rqp->idata) + i) !=
1925 (((struct zyd_pair *)cmd->data) + i)->reg)
1931 /* copy answer into caller-supplied buffer */
1932 bcopy(cmd->data, rqp->odata,
1933 sizeof(struct zyd_pair) * rqp->len);
1934 wakeup(rqp->odata); /* wakeup caller */
1938 return; /* unexpected IORD notification */
1940 device_printf(sc->sc_dev, "unknown notification %x\n",
1941 le16toh(cmd->code));
1946 zyd_rx_data(struct zyd_softc *sc, const uint8_t *buf, uint16_t len)
1948 struct ifnet *ifp = sc->sc_ifp;
1949 struct ieee80211com *ic = ifp->if_l2com;
1950 struct ieee80211_node *ni;
1951 const struct zyd_plcphdr *plcp;
1952 const struct zyd_rx_stat *stat;
1956 if (len < ZYD_MIN_FRAGSZ) {
1957 DPRINTF(("%s: frame too short (length=%d)\n",
1958 device_get_nameunit(sc->sc_dev), len));
1963 plcp = (const struct zyd_plcphdr *)buf;
1964 stat = (const struct zyd_rx_stat *)
1965 (buf + len - sizeof(struct zyd_rx_stat));
1967 if (stat->flags & ZYD_RX_ERROR) {
1968 DPRINTF(("%s: RX status indicated error (%x)\n",
1969 device_get_nameunit(sc->sc_dev), stat->flags));
1974 /* compute actual frame length */
1975 rlen = len - sizeof(struct zyd_plcphdr) -
1976 sizeof(struct zyd_rx_stat) - IEEE80211_CRC_LEN;
1978 /* allocate a mbuf to store the frame */
1980 m = m_getcl(M_DONTWAIT, MT_DATA, M_PKTHDR);
1982 m = m_gethdr(M_DONTWAIT, MT_DATA);
1984 DPRINTF(("%s: could not allocate rx mbuf\n",
1985 device_get_nameunit(sc->sc_dev)));
1989 m->m_pkthdr.rcvif = ifp;
1990 m->m_pkthdr.len = m->m_len = rlen;
1991 bcopy((const uint8_t *)(plcp + 1), mtod(m, uint8_t *), rlen);
1993 if (bpf_peers_present(ifp->if_bpf)) {
1994 struct zyd_rx_radiotap_header *tap = &sc->sc_rxtap;
1997 if (stat->flags & (ZYD_RX_BADCRC16 | ZYD_RX_BADCRC32))
1998 tap->wr_flags |= IEEE80211_RADIOTAP_F_BADFCS;
1999 /* XXX toss, no way to express errors */
2000 if (stat->flags & ZYD_RX_DECRYPTERR)
2001 tap->wr_flags |= IEEE80211_RADIOTAP_F_BADFCS;
2002 tap->wr_rate = ieee80211_plcp2rate(plcp->signal,
2003 (stat->flags & ZYD_RX_OFDM) ?
2004 IEEE80211_T_OFDM : IEEE80211_T_CCK);
2005 tap->wr_antsignal = stat->rssi + -95;
2006 tap->wr_antnoise = -95; /* XXX */
2008 bpf_mtap2(ifp->if_bpf, tap, sc->sc_rxtap_len, m);
2011 rssi = stat->rssi > 63 ? 127 : 2 * stat->rssi;
2014 ni = ieee80211_find_rxnode(ic, mtod(m, struct ieee80211_frame_min *));
2016 (void) ieee80211_input(ni, m, rssi, nf, 0);
2017 ieee80211_free_node(ni);
2019 (void) ieee80211_input_all(ic, m, rssi, nf, 0);
2023 zyd_rxeof(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status)
2025 struct zyd_rx_data *data = priv;
2026 struct zyd_softc *sc = data->sc;
2027 struct ifnet *ifp = sc->sc_ifp;
2028 const struct zyd_rx_desc *desc;
2031 if (status != USBD_NORMAL_COMPLETION) {
2032 if (status == USBD_NOT_STARTED || status == USBD_CANCELLED)
2035 if (status == USBD_STALLED)
2036 usbd_clear_endpoint_stall(sc->zyd_ep[ZYD_ENDPT_BIN]);
2040 usbd_get_xfer_status(xfer, NULL, NULL, &len, NULL);
2042 if (len < ZYD_MIN_RXBUFSZ) {
2043 DPRINTFN(3, ("%s: xfer too short (length=%d)\n",
2044 device_get_nameunit(sc->sc_dev), len));
2045 ifp->if_ierrors++; /* XXX not really errors */
2049 desc = (const struct zyd_rx_desc *)
2050 (data->buf + len - sizeof(struct zyd_rx_desc));
2052 if (UGETW(desc->tag) == ZYD_TAG_MULTIFRAME) {
2053 const uint8_t *p = data->buf, *end = p + len;
2056 DPRINTFN(3, ("received multi-frame transfer\n"));
2058 for (i = 0; i < ZYD_MAX_RXFRAMECNT; i++) {
2059 const uint16_t len16 = UGETW(desc->len[i]);
2061 if (len16 == 0 || p + len16 > end)
2064 zyd_rx_data(sc, p, len16);
2065 /* next frame is aligned on a 32-bit boundary */
2066 p += (len16 + 3) & ~3;
2069 DPRINTFN(3, ("received single-frame transfer\n"));
2071 zyd_rx_data(sc, data->buf, len);
2074 skip: /* setup a new transfer */
2075 usbd_setup_xfer(xfer, sc->zyd_ep[ZYD_ENDPT_BIN], data, NULL,
2076 ZYX_MAX_RXBUFSZ, USBD_NO_COPY | USBD_SHORT_XFER_OK,
2077 USBD_NO_TIMEOUT, zyd_rxeof);
2078 (void)usbd_transfer(xfer);
2082 zyd_plcp_signal(int rate)
2085 /* OFDM rates (cf IEEE Std 802.11a-1999, pp. 14 Table 80) */
2086 case 12: return 0xb;
2087 case 18: return 0xf;
2088 case 24: return 0xa;
2089 case 36: return 0xe;
2090 case 48: return 0x9;
2091 case 72: return 0xd;
2092 case 96: return 0x8;
2093 case 108: return 0xc;
2095 /* CCK rates (NB: not IEEE std, device-specific) */
2098 case 11: return 0x2;
2099 case 22: return 0x3;
2101 return 0xff; /* XXX unsupported/unknown rate */
2105 zyd_tx_mgt(struct zyd_softc *sc, struct mbuf *m0, struct ieee80211_node *ni)
2107 struct ieee80211vap *vap = ni->ni_vap;
2108 struct ieee80211com *ic = ni->ni_ic;
2109 struct ifnet *ifp = sc->sc_ifp;
2110 struct zyd_tx_desc *desc;
2111 struct zyd_tx_data *data;
2112 struct ieee80211_frame *wh;
2113 struct ieee80211_key *k;
2114 int xferlen, totlen, rate;
2118 data = &sc->tx_data[0];
2119 desc = (struct zyd_tx_desc *)data->buf;
2121 rate = IEEE80211_IS_CHAN_5GHZ(ic->ic_curchan) ? 12 : 2;
2123 wh = mtod(m0, struct ieee80211_frame *);
2125 if (wh->i_fc[1] & IEEE80211_FC1_WEP) {
2126 k = ieee80211_crypto_encap(ni, m0);
2136 wh = mtod(m0, struct ieee80211_frame *);
2138 xferlen = sizeof(struct zyd_tx_desc) + m0->m_pkthdr.len;
2139 totlen = m0->m_pkthdr.len + IEEE80211_CRC_LEN;
2141 /* fill Tx descriptor */
2142 desc->len = htole16(totlen);
2144 desc->flags = ZYD_TX_FLAG_BACKOFF;
2145 if (!IEEE80211_IS_MULTICAST(wh->i_addr1)) {
2146 /* multicast frames are not sent at OFDM rates in 802.11b/g */
2147 if (totlen > vap->iv_rtsthreshold) {
2148 desc->flags |= ZYD_TX_FLAG_RTS;
2149 } else if (ZYD_RATE_IS_OFDM(rate) &&
2150 (ic->ic_flags & IEEE80211_F_USEPROT)) {
2151 if (ic->ic_protmode == IEEE80211_PROT_CTSONLY)
2152 desc->flags |= ZYD_TX_FLAG_CTS_TO_SELF;
2153 else if (ic->ic_protmode == IEEE80211_PROT_RTSCTS)
2154 desc->flags |= ZYD_TX_FLAG_RTS;
2157 desc->flags |= ZYD_TX_FLAG_MULTICAST;
2160 (IEEE80211_FC0_TYPE_MASK | IEEE80211_FC0_SUBTYPE_MASK)) ==
2161 (IEEE80211_FC0_TYPE_CTL | IEEE80211_FC0_SUBTYPE_PS_POLL))
2162 desc->flags |= ZYD_TX_FLAG_TYPE(ZYD_TX_TYPE_PS_POLL);
2164 desc->phy = zyd_plcp_signal(rate);
2165 if (ZYD_RATE_IS_OFDM(rate)) {
2166 desc->phy |= ZYD_TX_PHY_OFDM;
2167 if (IEEE80211_IS_CHAN_5GHZ(ic->ic_curchan))
2168 desc->phy |= ZYD_TX_PHY_5GHZ;
2169 } else if (rate != 2 && (ic->ic_flags & IEEE80211_F_SHPREAMBLE))
2170 desc->phy |= ZYD_TX_PHY_SHPREAMBLE;
2172 /* actual transmit length (XXX why +10?) */
2173 pktlen = sizeof(struct zyd_tx_desc) + 10;
2174 if (sc->mac_rev == ZYD_ZD1211)
2176 desc->pktlen = htole16(pktlen);
2178 desc->plcp_length = (16 * totlen + rate - 1) / rate;
2179 desc->plcp_service = 0;
2181 const int remainder = (16 * totlen) % 22;
2182 if (remainder != 0 && remainder < 7)
2183 desc->plcp_service |= ZYD_PLCP_LENGEXT;
2186 if (bpf_peers_present(ifp->if_bpf)) {
2187 struct zyd_tx_radiotap_header *tap = &sc->sc_txtap;
2190 tap->wt_rate = rate;
2192 bpf_mtap2(ifp->if_bpf, tap, sc->sc_txtap_len, m0);
2195 m_copydata(m0, 0, m0->m_pkthdr.len,
2196 data->buf + sizeof(struct zyd_tx_desc));
2198 DPRINTFN(10, ("%s: sending mgt frame len=%zu rate=%u xferlen=%u\n",
2199 device_get_nameunit(sc->sc_dev), (size_t)m0->m_pkthdr.len,
2202 usbd_setup_xfer(data->xfer, sc->zyd_ep[ZYD_ENDPT_BOUT], data,
2203 data->buf, xferlen, USBD_FORCE_SHORT_XFER | USBD_NO_COPY,
2204 ZYD_TX_TIMEOUT, zyd_txeof);
2205 error = usbd_transfer(data->xfer);
2206 if (error != USBD_IN_PROGRESS && error != 0) {
2216 zyd_txeof(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status)
2218 struct zyd_tx_data *data = priv;
2219 struct zyd_softc *sc = data->sc;
2220 struct ifnet *ifp = sc->sc_ifp;
2221 struct ieee80211_node *ni;
2224 if (status != USBD_NORMAL_COMPLETION) {
2225 if (status == USBD_NOT_STARTED || status == USBD_CANCELLED)
2228 device_printf(sc->sc_dev, "could not transmit buffer: %s\n",
2229 usbd_errstr(status));
2231 if (status == USBD_STALLED) {
2232 usbd_clear_endpoint_stall_async(
2233 sc->zyd_ep[ZYD_ENDPT_BOUT]);
2240 /* update rate control statistics */
2241 ieee80211_amrr_tx_complete(&ZYD_NODE(ni)->amn,
2242 IEEE80211_AMRR_SUCCESS, 0);
2245 * Do any tx complete callback. Note this must
2246 * be done before releasing the node reference.
2249 if (m != NULL && m->m_flags & M_TXCB) {
2250 ieee80211_process_callback(ni, m, 0); /* XXX status? */
2255 ieee80211_free_node(ni);
2262 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
2267 zyd_tx_data(struct zyd_softc *sc, struct mbuf *m0, struct ieee80211_node *ni)
2269 struct ieee80211vap *vap = ni->ni_vap;
2270 struct ieee80211com *ic = ni->ni_ic;
2271 struct ifnet *ifp = sc->sc_ifp;
2272 struct zyd_tx_desc *desc;
2273 struct zyd_tx_data *data;
2274 struct ieee80211_frame *wh;
2275 const struct ieee80211_txparam *tp;
2276 struct ieee80211_key *k;
2277 int xferlen, totlen, rate;
2281 wh = mtod(m0, struct ieee80211_frame *);
2282 data = &sc->tx_data[0];
2283 desc = (struct zyd_tx_desc *)data->buf;
2285 desc->flags = ZYD_TX_FLAG_BACKOFF;
2286 tp = &vap->iv_txparms[ieee80211_chan2mode(ni->ni_chan)];
2287 if (IEEE80211_IS_MULTICAST(wh->i_addr1)) {
2288 rate = tp->mcastrate;
2289 desc->flags |= ZYD_TX_FLAG_MULTICAST;
2290 } else if (tp->ucastrate != IEEE80211_FIXED_RATE_NONE) {
2291 rate = tp->ucastrate;
2293 (void) ieee80211_amrr_choose(ni, &ZYD_NODE(ni)->amn);
2294 rate = ni->ni_txrate;
2297 if (wh->i_fc[1] & IEEE80211_FC1_WEP) {
2298 k = ieee80211_crypto_encap(ni, m0);
2304 /* packet header may have moved, reset our local pointer */
2305 wh = mtod(m0, struct ieee80211_frame *);
2311 xferlen = sizeof(struct zyd_tx_desc) + m0->m_pkthdr.len;
2312 totlen = m0->m_pkthdr.len + IEEE80211_CRC_LEN;
2314 /* fill Tx descriptor */
2315 desc->len = htole16(totlen);
2317 if (!IEEE80211_IS_MULTICAST(wh->i_addr1)) {
2318 /* multicast frames are not sent at OFDM rates in 802.11b/g */
2319 if (totlen > vap->iv_rtsthreshold) {
2320 desc->flags |= ZYD_TX_FLAG_RTS;
2321 } else if (ZYD_RATE_IS_OFDM(rate) &&
2322 (ic->ic_flags & IEEE80211_F_USEPROT)) {
2323 if (ic->ic_protmode == IEEE80211_PROT_CTSONLY)
2324 desc->flags |= ZYD_TX_FLAG_CTS_TO_SELF;
2325 else if (ic->ic_protmode == IEEE80211_PROT_RTSCTS)
2326 desc->flags |= ZYD_TX_FLAG_RTS;
2331 (IEEE80211_FC0_TYPE_MASK | IEEE80211_FC0_SUBTYPE_MASK)) ==
2332 (IEEE80211_FC0_TYPE_CTL | IEEE80211_FC0_SUBTYPE_PS_POLL))
2333 desc->flags |= ZYD_TX_FLAG_TYPE(ZYD_TX_TYPE_PS_POLL);
2335 desc->phy = zyd_plcp_signal(rate);
2336 if (ZYD_RATE_IS_OFDM(rate)) {
2337 desc->phy |= ZYD_TX_PHY_OFDM;
2338 if (IEEE80211_IS_CHAN_5GHZ(ic->ic_curchan))
2339 desc->phy |= ZYD_TX_PHY_5GHZ;
2340 } else if (rate != 2 && (ic->ic_flags & IEEE80211_F_SHPREAMBLE))
2341 desc->phy |= ZYD_TX_PHY_SHPREAMBLE;
2343 /* actual transmit length (XXX why +10?) */
2344 pktlen = sizeof(struct zyd_tx_desc) + 10;
2345 if (sc->mac_rev == ZYD_ZD1211)
2347 desc->pktlen = htole16(pktlen);
2349 desc->plcp_length = (16 * totlen + rate - 1) / rate;
2350 desc->plcp_service = 0;
2352 const int remainder = (16 * totlen) % 22;
2353 if (remainder != 0 && remainder < 7)
2354 desc->plcp_service |= ZYD_PLCP_LENGEXT;
2357 if (bpf_peers_present(ifp->if_bpf)) {
2358 struct zyd_tx_radiotap_header *tap = &sc->sc_txtap;
2361 tap->wt_rate = rate;
2362 tap->wt_chan_freq = htole16(ic->ic_curchan->ic_freq);
2363 tap->wt_chan_flags = htole16(ic->ic_curchan->ic_flags);
2365 bpf_mtap2(ifp->if_bpf, tap, sc->sc_txtap_len, m0);
2368 m_copydata(m0, 0, m0->m_pkthdr.len,
2369 data->buf + sizeof(struct zyd_tx_desc));
2371 DPRINTFN(10, ("%s: sending data frame len=%zu rate=%u xferlen=%u\n",
2372 device_get_nameunit(sc->sc_dev), (size_t)m0->m_pkthdr.len,
2375 m_freem(m0); /* mbuf no longer needed */
2377 usbd_setup_xfer(data->xfer, sc->zyd_ep[ZYD_ENDPT_BOUT], data,
2378 data->buf, xferlen, USBD_FORCE_SHORT_XFER | USBD_NO_COPY,
2379 ZYD_TX_TIMEOUT, zyd_txeof);
2380 error = usbd_transfer(data->xfer);
2381 if (error != USBD_IN_PROGRESS && error != 0) {
2391 zyd_start(struct ifnet *ifp)
2393 struct zyd_softc *sc = ifp->if_softc;
2394 struct ieee80211_node *ni;
2398 IFQ_DRV_DEQUEUE(&ifp->if_snd, m);
2401 if (sc->tx_queued >= ZYD_TX_LIST_CNT) {
2402 IFQ_DRV_PREPEND(&ifp->if_snd, m);
2403 ifp->if_drv_flags |= IFF_DRV_OACTIVE;
2406 ni = (struct ieee80211_node *)m->m_pkthdr.rcvif;
2407 m = ieee80211_encap(ni, m);
2409 ieee80211_free_node(ni);
2413 if (zyd_tx_data(sc, m, ni) != 0) {
2414 ieee80211_free_node(ni);
2420 callout_reset(&sc->sc_watchdog_ch, hz, zyd_watchdog, sc);
2425 zyd_raw_xmit(struct ieee80211_node *ni, struct mbuf *m,
2426 const struct ieee80211_bpf_params *params)
2428 struct ieee80211com *ic = ni->ni_ic;
2429 struct ifnet *ifp = ic->ic_ifp;
2430 struct zyd_softc *sc = ifp->if_softc;
2432 /* prevent management frames from being sent if we're not ready */
2433 if (!(ifp->if_drv_flags & IFF_DRV_RUNNING)) {
2435 ieee80211_free_node(ni);
2438 if (sc->tx_queued >= ZYD_TX_LIST_CNT) {
2439 ifp->if_drv_flags |= IFF_DRV_OACTIVE;
2441 ieee80211_free_node(ni);
2442 return ENOBUFS; /* XXX */
2448 * Legacy path; interpret frame contents to decide
2449 * precisely how to send the frame.
2452 if (zyd_tx_mgt(sc, m, ni) != 0)
2455 callout_reset(&sc->sc_watchdog_ch, hz, zyd_watchdog, sc);
2460 ieee80211_free_node(ni);
2461 return EIO; /* XXX */
2465 zyd_watchdog(void *arg)
2467 struct zyd_softc *sc = arg;
2468 struct ifnet *ifp = sc->sc_ifp;
2470 if (sc->tx_timer > 0) {
2471 if (--sc->tx_timer == 0) {
2472 device_printf(sc->sc_dev, "device timeout\n");
2473 /* zyd_init(ifp); XXX needs a process context ? */
2477 callout_reset(&sc->sc_watchdog_ch, hz, zyd_watchdog, sc);
2482 zyd_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
2484 struct zyd_softc *sc = ifp->if_softc;
2485 struct ieee80211com *ic = ifp->if_l2com;
2486 struct ifreq *ifr = (struct ifreq *) data;
2487 int error = 0, startall = 0;
2492 if (ifp->if_flags & IFF_UP) {
2493 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
2494 if ((ifp->if_flags ^ sc->sc_if_flags) &
2495 (IFF_ALLMULTI | IFF_PROMISC))
2498 zyd_init_locked(sc);
2502 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
2505 sc->sc_if_flags = ifp->if_flags;
2508 ieee80211_start_all(ic);
2511 error = ifmedia_ioctl(ifp, ifr, &ic->ic_media, cmd);
2514 error = ether_ioctl(ifp, cmd, data);
2524 zyd_init_locked(struct zyd_softc *sc)
2526 struct ifnet *ifp = sc->sc_ifp;
2527 struct ieee80211com *ic = ifp->if_l2com;
2532 IEEE80211_ADDR_COPY(ic->ic_myaddr, IF_LLADDR(ifp));
2533 DPRINTF(("setting MAC address to %s\n", ether_sprintf(ic->ic_myaddr)));
2534 error = zyd_set_macaddr(sc, ic->ic_myaddr);
2538 /* we'll do software WEP decryption for now */
2539 DPRINTF(("setting encryption type\n"));
2540 error = zyd_write32(sc, ZYD_MAC_ENCRYPTION_TYPE, ZYD_ENC_SNIFFER);
2544 /* promiscuous mode */
2545 (void)zyd_write32(sc, ZYD_MAC_SNIFFER, 0);
2547 /* multicast setup */
2548 (void)zyd_set_multi(sc);
2550 (void)zyd_set_rxfilter(sc);
2552 /* switch radio transmitter ON */
2553 (void)zyd_switch_radio(sc, 1);
2555 /* XXX wrong, can't set here */
2556 /* set basic rates */
2557 if (ic->ic_curmode == IEEE80211_MODE_11B)
2558 (void)zyd_write32(sc, ZYD_MAC_BAS_RATE, 0x0003);
2559 else if (ic->ic_curmode == IEEE80211_MODE_11A)
2560 (void)zyd_write32(sc, ZYD_MAC_BAS_RATE, 0x1500);
2561 else /* assumes 802.11b/g */
2562 (void)zyd_write32(sc, ZYD_MAC_BAS_RATE, 0x000f);
2564 /* set mandatory rates */
2565 if (ic->ic_curmode == IEEE80211_MODE_11B)
2566 (void)zyd_write32(sc, ZYD_MAC_MAN_RATE, 0x000f);
2567 else if (ic->ic_curmode == IEEE80211_MODE_11A)
2568 (void)zyd_write32(sc, ZYD_MAC_MAN_RATE, 0x1500);
2569 else /* assumes 802.11b/g */
2570 (void)zyd_write32(sc, ZYD_MAC_MAN_RATE, 0x150f);
2572 /* set default BSS channel */
2573 zyd_set_chan(sc, ic->ic_curchan);
2575 /* enable interrupts */
2576 (void)zyd_write32(sc, ZYD_CR_INTERRUPT, ZYD_HWINT_MASK);
2579 * Allocate Tx and Rx xfer queues.
2581 if ((error = zyd_alloc_tx_list(sc)) != 0) {
2582 device_printf(sc->sc_dev, "could not allocate Tx list\n");
2585 if ((error = zyd_alloc_rx_list(sc)) != 0) {
2586 device_printf(sc->sc_dev, "could not allocate Rx list\n");
2591 * Start up the receive pipe.
2593 for (i = 0; i < ZYD_RX_LIST_CNT; i++) {
2594 struct zyd_rx_data *data = &sc->rx_data[i];
2596 usbd_setup_xfer(data->xfer, sc->zyd_ep[ZYD_ENDPT_BIN], data,
2597 NULL, ZYX_MAX_RXBUFSZ, USBD_NO_COPY | USBD_SHORT_XFER_OK,
2598 USBD_NO_TIMEOUT, zyd_rxeof);
2599 error = usbd_transfer(data->xfer);
2600 if (error != USBD_IN_PROGRESS && error != 0) {
2601 device_printf(sc->sc_dev,
2602 "could not queue Rx transfer\n");
2607 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
2608 ifp->if_drv_flags |= IFF_DRV_RUNNING;
2611 fail: zyd_stop(sc, 1);
2616 zyd_init(void *priv)
2618 struct zyd_softc *sc = priv;
2619 struct ifnet *ifp = sc->sc_ifp;
2620 struct ieee80211com *ic = ifp->if_l2com;
2623 zyd_init_locked(sc);
2626 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
2627 ieee80211_start_all(ic); /* start all vap's */
2631 zyd_stop(struct zyd_softc *sc, int disable)
2633 struct ifnet *ifp = sc->sc_ifp;
2636 ifp->if_drv_flags &= ~(IFF_DRV_RUNNING | IFF_DRV_OACTIVE);
2638 /* switch radio transmitter OFF */
2639 (void)zyd_switch_radio(sc, 0);
2642 (void)zyd_write32(sc, ZYD_MAC_RXFILTER, 0);
2644 /* disable interrupts */
2645 (void)zyd_write32(sc, ZYD_CR_INTERRUPT, 0);
2647 usbd_abort_pipe(sc->zyd_ep[ZYD_ENDPT_BIN]);
2648 usbd_abort_pipe(sc->zyd_ep[ZYD_ENDPT_BOUT]);
2650 zyd_free_rx_list(sc);
2651 zyd_free_tx_list(sc);
2655 zyd_loadfirmware(struct zyd_softc *sc, u_char *fw, size_t size)
2657 usb_device_request_t req;
2661 DPRINTF(("firmware size=%zu\n", size));
2663 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
2664 req.bRequest = ZYD_DOWNLOADREQ;
2665 USETW(req.wIndex, 0);
2667 addr = ZYD_FIRMWARE_START_ADDR;
2670 const int mlen = min(size, 4096);
2673 * XXXX: When the transfer size is 4096 bytes, it is not
2674 * likely to be able to transfer it.
2675 * The cause is port or machine or chip?
2677 const int mlen = min(size, 64);
2680 DPRINTF(("loading firmware block: len=%d, addr=0x%x\n", mlen,
2683 USETW(req.wValue, addr);
2684 USETW(req.wLength, mlen);
2685 if (usbd_do_request(sc->sc_udev, &req, fw) != 0)
2693 /* check whether the upload succeeded */
2694 req.bmRequestType = UT_READ_VENDOR_DEVICE;
2695 req.bRequest = ZYD_DOWNLOADSTS;
2696 USETW(req.wValue, 0);
2697 USETW(req.wIndex, 0);
2698 USETW(req.wLength, sizeof(stat));
2699 if (usbd_do_request(sc->sc_udev, &req, &stat) != 0)
2702 return (stat & 0x80) ? EIO : 0;
2706 zyd_newassoc(struct ieee80211_node *ni, int isnew)
2708 struct ieee80211vap *vap = ni->ni_vap;
2710 ieee80211_amrr_node_init(&ZYD_VAP(vap)->amrr, &ZYD_NODE(ni)->amn, ni);
2714 zyd_scan_start(struct ieee80211com *ic)
2716 struct zyd_softc *sc = ic->ic_ifp->if_softc;
2718 usb_rem_task(sc->sc_udev, &sc->sc_scantask);
2720 /* do it in a process context */
2721 sc->sc_scan_action = ZYD_SCAN_START;
2722 usb_add_task(sc->sc_udev, &sc->sc_scantask, USB_TASKQ_DRIVER);
2726 zyd_scan_end(struct ieee80211com *ic)
2728 struct zyd_softc *sc = ic->ic_ifp->if_softc;
2730 usb_rem_task(sc->sc_udev, &sc->sc_scantask);
2732 /* do it in a process context */
2733 sc->sc_scan_action = ZYD_SCAN_END;
2734 usb_add_task(sc->sc_udev, &sc->sc_scantask, USB_TASKQ_DRIVER);
2738 zyd_set_channel(struct ieee80211com *ic)
2740 struct zyd_softc *sc = ic->ic_ifp->if_softc;
2742 usb_rem_task(sc->sc_udev, &sc->sc_scantask);
2744 /* do it in a process context */
2745 sc->sc_scan_action = ZYD_SET_CHANNEL;
2746 usb_add_task(sc->sc_udev, &sc->sc_scantask, USB_TASKQ_DRIVER);
2750 zyd_scantask(void *arg)
2752 struct zyd_softc *sc = arg;
2753 struct ifnet *ifp = sc->sc_ifp;
2754 struct ieee80211com *ic = ifp->if_l2com;
2758 switch (sc->sc_scan_action) {
2759 case ZYD_SCAN_START:
2760 /* want broadcast address while scanning */
2761 zyd_set_bssid(sc, ifp->if_broadcastaddr);
2765 /* restore previous bssid */
2766 zyd_set_bssid(sc, sc->sc_bssid);
2769 case ZYD_SET_CHANNEL:
2771 zyd_set_chan(sc, ic->ic_curchan);
2776 device_printf(sc->sc_dev, "unknown scan action %d\n",
2777 sc->sc_scan_action);
2785 zyd_wakeup(struct zyd_softc *sc)
2789 STAILQ_FOREACH(rqp, &sc->sc_rqh, rq) {
2790 wakeup(rqp->odata); /* wakeup sleeping caller */
2794 static device_method_t zyd_methods[] = {
2795 /* Device interface */
2796 DEVMETHOD(device_probe, zyd_match),
2797 DEVMETHOD(device_attach, zyd_attach),
2798 DEVMETHOD(device_detach, zyd_detach),
2803 static driver_t zyd_driver = {
2806 sizeof(struct zyd_softc)
2809 static devclass_t zyd_devclass;
2811 DRIVER_MODULE(zyd, uhub, zyd_driver, zyd_devclass, usbd_driver_load, 0);
2812 MODULE_DEPEND(zyd, wlan, 1, 1, 1);
2813 MODULE_DEPEND(zyd, wlan_amrr, 1, 1, 1);
2814 MODULE_DEPEND(zyd, usb, 1, 1, 1);