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 *);
239 zyd_match(device_t dev)
241 struct usb_attach_arg *uaa = device_get_ivars(dev);
246 return (zyd_lookup(uaa->vendor, uaa->product) != NULL) ?
247 UMATCH_VENDOR_PRODUCT : UMATCH_NONE;
251 zyd_attachhook(struct zyd_softc *sc)
256 if (sc->mac_rev == ZYD_ZD1211) {
257 firmware = (u_char *)zd1211_firmware;
258 len = sizeof(zd1211_firmware);
260 firmware = (u_char *)zd1211b_firmware;
261 len = sizeof(zd1211b_firmware);
264 error = zyd_loadfirmware(sc, firmware, len);
266 device_printf(sc->sc_dev,
267 "could not load firmware (error=%d)\n", error);
271 sc->sc_flags |= ZYD_FLAG_FWLOADED;
273 /* complete the attach process */
274 return zyd_complete_attach(sc);
278 zyd_attach(device_t dev)
281 struct zyd_softc *sc = device_get_softc(dev);
282 struct usb_attach_arg *uaa = device_get_ivars(dev);
283 usb_device_descriptor_t* ddesc;
288 ifp = sc->sc_ifp = if_alloc(IFT_IEEE80211);
290 device_printf(dev, "can not if_alloc()\n");
294 sc->sc_udev = uaa->device;
296 sc->mac_rev = zyd_lookup(uaa->vendor, uaa->product)->rev;
298 ddesc = usbd_get_device_descriptor(sc->sc_udev);
299 if (UGETW(ddesc->bcdDevice) < 0x4330) {
300 device_printf(dev, "device version mismatch: 0x%x "
301 "(only >= 43.30 supported)\n",
302 UGETW(ddesc->bcdDevice));
307 if_initname(ifp, "zyd", device_get_unit(sc->sc_dev));
308 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST |
309 IFF_NEEDSGIANT; /* USB stack is still under Giant lock */
310 ifp->if_init = zyd_init;
311 ifp->if_ioctl = zyd_ioctl;
312 ifp->if_start = zyd_start;
313 IFQ_SET_MAXLEN(&ifp->if_snd, IFQ_MAXLEN);
314 IFQ_SET_READY(&ifp->if_snd);
316 STAILQ_INIT(&sc->sc_rqh);
318 error = zyd_attachhook(sc);
329 zyd_complete_attach(struct zyd_softc *sc)
331 struct ifnet *ifp = sc->sc_ifp;
332 struct ieee80211com *ic = ifp->if_l2com;
336 mtx_init(&sc->sc_mtx, device_get_nameunit(sc->sc_dev), MTX_NETWORK_LOCK,
337 MTX_DEF | MTX_RECURSE);
339 usb_init_task(&sc->sc_scantask, zyd_scantask, sc);
340 usb_init_task(&sc->sc_task, zyd_task, sc);
341 usb_init_task(&sc->sc_mcasttask, zyd_set_multi, sc);
343 callout_init(&sc->sc_watchdog_ch, 0);
345 error = usbd_set_config_no(sc->sc_udev, ZYD_CONFIG_NO, 1);
347 device_printf(sc->sc_dev, "setting config no failed\n");
352 error = usbd_device2interface_handle(sc->sc_udev, ZYD_IFACE_INDEX,
355 device_printf(sc->sc_dev, "getting interface handle failed\n");
360 if ((error = zyd_open_pipes(sc)) != 0) {
361 device_printf(sc->sc_dev, "could not open pipes\n");
365 if ((error = zyd_read_eeprom(sc)) != 0) {
366 device_printf(sc->sc_dev, "could not read EEPROM\n");
370 if ((error = zyd_rf_attach(sc, sc->rf_rev)) != 0) {
371 device_printf(sc->sc_dev, "could not attach RF, rev 0x%x\n",
376 if ((error = zyd_hw_init(sc)) != 0) {
377 device_printf(sc->sc_dev, "hardware initialization failed\n");
381 device_printf(sc->sc_dev,
382 "HMAC ZD1211%s, FW %02x.%02x, RF %s, PA %x, address %s\n",
383 (sc->mac_rev == ZYD_ZD1211) ? "": "B",
384 sc->fw_rev >> 8, sc->fw_rev & 0xff, zyd_rf_name(sc->rf_rev),
385 sc->pa_rev, ether_sprintf(ic->ic_myaddr));
387 IEEE80211_ADDR_COPY(sc->sc_bssid, ic->ic_myaddr);
390 ic->ic_phytype = IEEE80211_T_OFDM; /* not only, but not used */
391 ic->ic_opmode = IEEE80211_M_STA;
393 /* set device capabilities */
395 IEEE80211_C_STA /* station mode */
396 | IEEE80211_C_MONITOR /* monitor mode */
397 | IEEE80211_C_SHPREAMBLE /* short preamble supported */
398 | IEEE80211_C_SHSLOT /* short slot time supported */
399 | IEEE80211_C_BGSCAN /* capable of bg scanning */
400 | IEEE80211_C_WPA /* 802.11i */
404 setbit(&bands, IEEE80211_MODE_11B);
405 setbit(&bands, IEEE80211_MODE_11G);
406 ieee80211_init_channels(ic, NULL, &bands);
408 ieee80211_ifattach(ic);
409 ic->ic_newassoc = zyd_newassoc;
410 ic->ic_raw_xmit = zyd_raw_xmit;
411 ic->ic_node_alloc = zyd_node_alloc;
412 ic->ic_scan_start = zyd_scan_start;
413 ic->ic_scan_end = zyd_scan_end;
414 ic->ic_set_channel = zyd_set_channel;
416 ic->ic_vap_create = zyd_vap_create;
417 ic->ic_vap_delete = zyd_vap_delete;
418 ic->ic_update_mcast = zyd_update_mcast;
420 bpfattach(ifp, DLT_IEEE802_11_RADIO,
421 sizeof(struct ieee80211_frame) + sizeof(sc->sc_txtap));
423 sc->sc_rxtap_len = sizeof(sc->sc_rxtap);
424 sc->sc_rxtap.wr_ihdr.it_len = htole16(sc->sc_rxtap_len);
425 sc->sc_rxtap.wr_ihdr.it_present = htole32(ZYD_RX_RADIOTAP_PRESENT);
427 sc->sc_txtap_len = sizeof(sc->sc_txtap);
428 sc->sc_txtap.wt_ihdr.it_len = htole16(sc->sc_txtap_len);
429 sc->sc_txtap.wt_ihdr.it_present = htole32(ZYD_TX_RADIOTAP_PRESENT);
432 ieee80211_announce(ic);
434 usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, sc->sc_udev, sc->sc_dev);
439 mtx_destroy(&sc->sc_mtx);
445 zyd_detach(device_t dev)
447 struct zyd_softc *sc = device_get_softc(dev);
448 struct ifnet *ifp = sc->sc_ifp;
449 struct ieee80211com *ic = ifp->if_l2com;
451 if (!device_is_attached(dev))
454 /* set a flag to indicate we're detaching. */
455 sc->sc_flags |= ZYD_FLAG_DETACHING;
457 /* protect a race when we have listeners related with the driver. */
458 ifp->if_flags &= ~IFF_UP;
462 ieee80211_ifdetach(ic);
464 usb_rem_task(sc->sc_udev, &sc->sc_scantask);
465 usb_rem_task(sc->sc_udev, &sc->sc_task);
466 callout_stop(&sc->sc_watchdog_ch);
471 mtx_destroy(&sc->sc_mtx);
473 usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->sc_udev, sc->sc_dev);
478 static struct ieee80211vap *
479 zyd_vap_create(struct ieee80211com *ic,
480 const char name[IFNAMSIZ], int unit, int opmode, int flags,
481 const uint8_t bssid[IEEE80211_ADDR_LEN],
482 const uint8_t mac[IEEE80211_ADDR_LEN])
485 struct ieee80211vap *vap;
487 if (!TAILQ_EMPTY(&ic->ic_vaps)) /* only one at a time */
489 zvp = (struct zyd_vap *) malloc(sizeof(struct zyd_vap),
490 M_80211_VAP, M_NOWAIT | M_ZERO);
494 /* enable s/w bmiss handling for sta mode */
495 ieee80211_vap_setup(ic, vap, name, unit, opmode,
496 flags | IEEE80211_CLONE_NOBEACONS, bssid, mac);
498 /* override state transition machine */
499 zvp->newstate = vap->iv_newstate;
500 vap->iv_newstate = zyd_newstate;
502 ieee80211_amrr_init(&zvp->amrr, vap,
503 IEEE80211_AMRR_MIN_SUCCESS_THRESHOLD,
504 IEEE80211_AMRR_MAX_SUCCESS_THRESHOLD,
508 ieee80211_vap_attach(vap, ieee80211_media_change, ieee80211_media_status);
509 ic->ic_opmode = opmode;
514 zyd_vap_delete(struct ieee80211vap *vap)
516 struct zyd_vap *zvp = ZYD_VAP(vap);
518 ieee80211_amrr_cleanup(&zvp->amrr);
519 ieee80211_vap_detach(vap);
520 free(zvp, M_80211_VAP);
524 zyd_open_pipes(struct zyd_softc *sc)
526 usb_endpoint_descriptor_t *edesc;
531 edesc = usbd_get_endpoint_descriptor(sc->sc_iface, 0x83);
535 isize = UGETW(edesc->wMaxPacketSize);
536 if (isize == 0) /* should not happen */
539 sc->ibuf = malloc(isize, M_USBDEV, M_NOWAIT);
540 if (sc->ibuf == NULL)
543 error = usbd_open_pipe_intr(sc->sc_iface, 0x83, USBD_SHORT_XFER_OK,
544 &sc->zyd_ep[ZYD_ENDPT_IIN], sc, sc->ibuf, isize, zyd_intr,
545 USBD_DEFAULT_INTERVAL);
547 device_printf(sc->sc_dev, "open rx intr pipe failed: %s\n",
552 /* interrupt out (not necessarily an interrupt pipe) */
553 error = usbd_open_pipe(sc->sc_iface, 0x04, USBD_EXCLUSIVE_USE,
554 &sc->zyd_ep[ZYD_ENDPT_IOUT]);
556 device_printf(sc->sc_dev, "open tx intr pipe failed: %s\n",
562 error = usbd_open_pipe(sc->sc_iface, 0x82, USBD_EXCLUSIVE_USE,
563 &sc->zyd_ep[ZYD_ENDPT_BIN]);
565 device_printf(sc->sc_dev, "open rx pipe failed: %s\n",
571 error = usbd_open_pipe(sc->sc_iface, 0x01, USBD_EXCLUSIVE_USE,
572 &sc->zyd_ep[ZYD_ENDPT_BOUT]);
574 device_printf(sc->sc_dev, "open tx pipe failed: %s\n",
581 fail: zyd_close_pipes(sc);
586 zyd_close_pipes(struct zyd_softc *sc)
590 for (i = 0; i < ZYD_ENDPT_CNT; i++) {
591 if (sc->zyd_ep[i] != NULL) {
592 usbd_abort_pipe(sc->zyd_ep[i]);
593 usbd_close_pipe(sc->zyd_ep[i]);
594 sc->zyd_ep[i] = NULL;
597 if (sc->ibuf != NULL) {
598 free(sc->ibuf, M_USBDEV);
604 zyd_alloc_tx_list(struct zyd_softc *sc)
610 for (i = 0; i < ZYD_TX_LIST_CNT; i++) {
611 struct zyd_tx_data *data = &sc->tx_data[i];
613 data->sc = sc; /* backpointer for callbacks */
615 data->xfer = usbd_alloc_xfer(sc->sc_udev);
616 if (data->xfer == NULL) {
617 device_printf(sc->sc_dev,
618 "could not allocate tx xfer\n");
622 data->buf = usbd_alloc_buffer(data->xfer, ZYD_MAX_TXBUFSZ);
623 if (data->buf == NULL) {
624 device_printf(sc->sc_dev,
625 "could not allocate tx buffer\n");
630 /* clear Tx descriptor */
631 bzero(data->buf, sizeof(struct zyd_tx_desc));
635 fail: zyd_free_tx_list(sc);
640 zyd_free_tx_list(struct zyd_softc *sc)
644 for (i = 0; i < ZYD_TX_LIST_CNT; i++) {
645 struct zyd_tx_data *data = &sc->tx_data[i];
647 if (data->xfer != NULL) {
648 usbd_free_xfer(data->xfer);
651 if (data->ni != NULL) {
652 ieee80211_free_node(data->ni);
659 zyd_alloc_rx_list(struct zyd_softc *sc)
663 for (i = 0; i < ZYD_RX_LIST_CNT; i++) {
664 struct zyd_rx_data *data = &sc->rx_data[i];
666 data->sc = sc; /* backpointer for callbacks */
668 data->xfer = usbd_alloc_xfer(sc->sc_udev);
669 if (data->xfer == NULL) {
670 device_printf(sc->sc_dev,
671 "could not allocate rx xfer\n");
675 data->buf = usbd_alloc_buffer(data->xfer, ZYX_MAX_RXBUFSZ);
676 if (data->buf == NULL) {
677 device_printf(sc->sc_dev,
678 "could not allocate rx buffer\n");
685 fail: zyd_free_rx_list(sc);
690 zyd_free_rx_list(struct zyd_softc *sc)
694 for (i = 0; i < ZYD_RX_LIST_CNT; i++) {
695 struct zyd_rx_data *data = &sc->rx_data[i];
697 if (data->xfer != NULL) {
698 usbd_free_xfer(data->xfer);
705 static struct ieee80211_node *
706 zyd_node_alloc(struct ieee80211vap *vap __unused,
707 const uint8_t mac[IEEE80211_ADDR_LEN] __unused)
711 zn = malloc(sizeof(struct zyd_node), M_80211_NODE, M_NOWAIT | M_ZERO);
712 return zn != NULL ? &zn->ni : NULL;
718 struct zyd_softc *sc = arg;
719 struct ifnet *ifp = sc->sc_ifp;
720 struct ieee80211com *ic = ifp->if_l2com;
721 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps);
722 struct zyd_vap *zvp = ZYD_VAP(vap);
724 switch (sc->sc_state) {
725 case IEEE80211_S_RUN:
727 struct ieee80211_node *ni = vap->iv_bss;
729 zyd_set_chan(sc, ic->ic_curchan);
731 if (vap->iv_opmode != IEEE80211_M_MONITOR) {
732 /* turn link LED on */
733 zyd_set_led(sc, ZYD_LED1, 1);
735 /* make data LED blink upon Tx */
736 zyd_write32(sc, sc->fwbase + ZYD_FW_LINK_STATUS, 1);
738 IEEE80211_ADDR_COPY(sc->sc_bssid, ni->ni_bssid);
739 zyd_set_bssid(sc, sc->sc_bssid);
742 if (vap->iv_opmode == IEEE80211_M_STA) {
743 /* fake a join to init the tx rate */
753 zvp->newstate(vap, sc->sc_state, sc->sc_arg);
754 if (vap->iv_newstate_cb != NULL)
755 vap->iv_newstate_cb(vap, sc->sc_state, sc->sc_arg);
756 IEEE80211_UNLOCK(ic);
760 zyd_newstate(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg)
762 struct zyd_vap *zvp = ZYD_VAP(vap);
763 struct ieee80211com *ic = vap->iv_ic;
764 struct zyd_softc *sc = ic->ic_ifp->if_softc;
766 usb_rem_task(sc->sc_udev, &sc->sc_task);
768 /* do it in a process context */
769 sc->sc_state = nstate;
772 if (nstate == IEEE80211_S_INIT) {
773 zvp->newstate(vap, nstate, arg);
776 usb_add_task(sc->sc_udev, &sc->sc_task, USB_TASKQ_DRIVER);
782 zyd_cmd(struct zyd_softc *sc, uint16_t code, const void *idata, int ilen,
783 void *odata, int olen, u_int flags)
785 usbd_xfer_handle xfer;
791 if ((xfer = usbd_alloc_xfer(sc->sc_udev)) == NULL)
794 cmd.code = htole16(code);
795 bcopy(idata, cmd.data, ilen);
797 xferflags = USBD_FORCE_SHORT_XFER;
798 if (!(flags & ZYD_CMD_FLAG_READ))
799 xferflags |= USBD_SYNCHRONOUS;
803 rq.len = olen / sizeof(struct zyd_pair);
804 STAILQ_INSERT_TAIL(&sc->sc_rqh, &rq, rq);
807 usbd_setup_xfer(xfer, sc->zyd_ep[ZYD_ENDPT_IOUT], 0, &cmd,
808 sizeof(uint16_t) + ilen, xferflags, ZYD_INTR_TIMEOUT, NULL);
809 error = usbd_transfer(xfer);
810 if (error != USBD_IN_PROGRESS && error != 0) {
811 device_printf(sc->sc_dev, "could not send command (error=%s)\n",
813 (void)usbd_free_xfer(xfer);
816 if (!(flags & ZYD_CMD_FLAG_READ)) {
817 (void)usbd_free_xfer(xfer);
818 return 0; /* write: don't wait for reply */
820 /* wait at most one second for command reply */
821 error = tsleep(odata, PCATCH, "zydcmd", hz);
822 if (error == EWOULDBLOCK)
823 device_printf(sc->sc_dev, "zyd_read sleep timeout\n");
824 STAILQ_REMOVE(&sc->sc_rqh, &rq, rq, rq);
826 (void)usbd_free_xfer(xfer);
831 zyd_read16(struct zyd_softc *sc, uint16_t reg, uint16_t *val)
837 error = zyd_cmd(sc, ZYD_CMD_IORD, ®, sizeof(reg), &tmp, sizeof(tmp),
840 *val = le16toh(tmp.val);
845 zyd_read32(struct zyd_softc *sc, uint16_t reg, uint32_t *val)
847 struct zyd_pair tmp[2];
851 regs[0] = htole16(ZYD_REG32_HI(reg));
852 regs[1] = htole16(ZYD_REG32_LO(reg));
853 error = zyd_cmd(sc, ZYD_CMD_IORD, regs, sizeof(regs), tmp, sizeof(tmp),
856 *val = le16toh(tmp[0].val) << 16 | le16toh(tmp[1].val);
861 zyd_write16(struct zyd_softc *sc, uint16_t reg, uint16_t val)
863 struct zyd_pair pair;
865 pair.reg = htole16(reg);
866 pair.val = htole16(val);
868 return zyd_cmd(sc, ZYD_CMD_IOWR, &pair, sizeof(pair), NULL, 0, 0);
872 zyd_write32(struct zyd_softc *sc, uint16_t reg, uint32_t val)
874 struct zyd_pair pair[2];
876 pair[0].reg = htole16(ZYD_REG32_HI(reg));
877 pair[0].val = htole16(val >> 16);
878 pair[1].reg = htole16(ZYD_REG32_LO(reg));
879 pair[1].val = htole16(val & 0xffff);
881 return zyd_cmd(sc, ZYD_CMD_IOWR, pair, sizeof(pair), NULL, 0, 0);
885 zyd_rfwrite(struct zyd_softc *sc, uint32_t val)
887 struct zyd_rf *rf = &sc->sc_rf;
888 struct zyd_rfwrite req;
892 (void)zyd_read16(sc, ZYD_CR203, &cr203);
893 cr203 &= ~(ZYD_RF_IF_LE | ZYD_RF_CLK | ZYD_RF_DATA);
895 req.code = htole16(2);
896 req.width = htole16(rf->width);
897 for (i = 0; i < rf->width; i++) {
898 req.bit[i] = htole16(cr203);
899 if (val & (1 << (rf->width - 1 - i)))
900 req.bit[i] |= htole16(ZYD_RF_DATA);
902 return zyd_cmd(sc, ZYD_CMD_RFCFG, &req, 4 + 2 * rf->width, NULL, 0, 0);
906 zyd_lock_phy(struct zyd_softc *sc)
910 (void)zyd_read32(sc, ZYD_MAC_MISC, &tmp);
911 tmp &= ~ZYD_UNLOCK_PHY_REGS;
912 (void)zyd_write32(sc, ZYD_MAC_MISC, tmp);
916 zyd_unlock_phy(struct zyd_softc *sc)
920 (void)zyd_read32(sc, ZYD_MAC_MISC, &tmp);
921 tmp |= ZYD_UNLOCK_PHY_REGS;
922 (void)zyd_write32(sc, ZYD_MAC_MISC, tmp);
929 zyd_rfmd_init(struct zyd_rf *rf)
931 #define N(a) (sizeof(a) / sizeof((a)[0]))
932 struct zyd_softc *sc = rf->rf_sc;
933 static const struct zyd_phy_pair phyini[] = ZYD_RFMD_PHY;
934 static const uint32_t rfini[] = ZYD_RFMD_RF;
937 /* init RF-dependent PHY registers */
938 for (i = 0; i < N(phyini); i++) {
939 error = zyd_write16(sc, phyini[i].reg, phyini[i].val);
944 /* init RFMD radio */
945 for (i = 0; i < N(rfini); i++) {
946 if ((error = zyd_rfwrite(sc, rfini[i])) != 0)
954 zyd_rfmd_switch_radio(struct zyd_rf *rf, int on)
956 struct zyd_softc *sc = rf->rf_sc;
958 (void)zyd_write16(sc, ZYD_CR10, on ? 0x89 : 0x15);
959 (void)zyd_write16(sc, ZYD_CR11, on ? 0x00 : 0x81);
965 zyd_rfmd_set_channel(struct zyd_rf *rf, uint8_t chan)
967 struct zyd_softc *sc = rf->rf_sc;
968 static const struct {
970 } rfprog[] = ZYD_RFMD_CHANTABLE;
972 (void)zyd_rfwrite(sc, rfprog[chan - 1].r1);
973 (void)zyd_rfwrite(sc, rfprog[chan - 1].r2);
982 zyd_al2230_init(struct zyd_rf *rf)
984 #define N(a) (sizeof(a) / sizeof((a)[0]))
985 struct zyd_softc *sc = rf->rf_sc;
986 static const struct zyd_phy_pair phyini[] = ZYD_AL2230_PHY;
987 static const uint32_t rfini[] = ZYD_AL2230_RF;
990 /* init RF-dependent PHY registers */
991 for (i = 0; i < N(phyini); i++) {
992 error = zyd_write16(sc, phyini[i].reg, phyini[i].val);
997 /* init AL2230 radio */
998 for (i = 0; i < N(rfini); i++) {
999 if ((error = zyd_rfwrite(sc, rfini[i])) != 0)
1007 zyd_al2230_init_b(struct zyd_rf *rf)
1009 #define N(a) (sizeof(a) / sizeof((a)[0]))
1010 struct zyd_softc *sc = rf->rf_sc;
1011 static const struct zyd_phy_pair phyini[] = ZYD_AL2230_PHY_B;
1012 static const uint32_t rfini[] = ZYD_AL2230_RF_B;
1015 /* init RF-dependent PHY registers */
1016 for (i = 0; i < N(phyini); i++) {
1017 error = zyd_write16(sc, phyini[i].reg, phyini[i].val);
1022 /* init AL2230 radio */
1023 for (i = 0; i < N(rfini); i++) {
1024 if ((error = zyd_rfwrite(sc, rfini[i])) != 0)
1032 zyd_al2230_switch_radio(struct zyd_rf *rf, int on)
1034 struct zyd_softc *sc = rf->rf_sc;
1035 int on251 = (sc->mac_rev == ZYD_ZD1211) ? 0x3f : 0x7f;
1037 (void)zyd_write16(sc, ZYD_CR11, on ? 0x00 : 0x04);
1038 (void)zyd_write16(sc, ZYD_CR251, on ? on251 : 0x2f);
1044 zyd_al2230_set_channel(struct zyd_rf *rf, uint8_t chan)
1046 struct zyd_softc *sc = rf->rf_sc;
1047 static const struct {
1048 uint32_t r1, r2, r3;
1049 } rfprog[] = ZYD_AL2230_CHANTABLE;
1051 (void)zyd_rfwrite(sc, rfprog[chan - 1].r1);
1052 (void)zyd_rfwrite(sc, rfprog[chan - 1].r2);
1053 (void)zyd_rfwrite(sc, rfprog[chan - 1].r3);
1055 (void)zyd_write16(sc, ZYD_CR138, 0x28);
1056 (void)zyd_write16(sc, ZYD_CR203, 0x06);
1062 * AL7230B RF methods.
1065 zyd_al7230B_init(struct zyd_rf *rf)
1067 #define N(a) (sizeof(a) / sizeof((a)[0]))
1068 struct zyd_softc *sc = rf->rf_sc;
1069 static const struct zyd_phy_pair phyini_1[] = ZYD_AL7230B_PHY_1;
1070 static const struct zyd_phy_pair phyini_2[] = ZYD_AL7230B_PHY_2;
1071 static const struct zyd_phy_pair phyini_3[] = ZYD_AL7230B_PHY_3;
1072 static const uint32_t rfini_1[] = ZYD_AL7230B_RF_1;
1073 static const uint32_t rfini_2[] = ZYD_AL7230B_RF_2;
1076 /* for AL7230B, PHY and RF need to be initialized in "phases" */
1078 /* init RF-dependent PHY registers, part one */
1079 for (i = 0; i < N(phyini_1); i++) {
1080 error = zyd_write16(sc, phyini_1[i].reg, phyini_1[i].val);
1084 /* init AL7230B radio, part one */
1085 for (i = 0; i < N(rfini_1); i++) {
1086 if ((error = zyd_rfwrite(sc, rfini_1[i])) != 0)
1089 /* init RF-dependent PHY registers, part two */
1090 for (i = 0; i < N(phyini_2); i++) {
1091 error = zyd_write16(sc, phyini_2[i].reg, phyini_2[i].val);
1095 /* init AL7230B radio, part two */
1096 for (i = 0; i < N(rfini_2); i++) {
1097 if ((error = zyd_rfwrite(sc, rfini_2[i])) != 0)
1100 /* init RF-dependent PHY registers, part three */
1101 for (i = 0; i < N(phyini_3); i++) {
1102 error = zyd_write16(sc, phyini_3[i].reg, phyini_3[i].val);
1112 zyd_al7230B_switch_radio(struct zyd_rf *rf, int on)
1114 struct zyd_softc *sc = rf->rf_sc;
1116 (void)zyd_write16(sc, ZYD_CR11, on ? 0x00 : 0x04);
1117 (void)zyd_write16(sc, ZYD_CR251, on ? 0x3f : 0x2f);
1123 zyd_al7230B_set_channel(struct zyd_rf *rf, uint8_t chan)
1125 #define N(a) (sizeof(a) / sizeof((a)[0]))
1126 struct zyd_softc *sc = rf->rf_sc;
1127 static const struct {
1129 } rfprog[] = ZYD_AL7230B_CHANTABLE;
1130 static const uint32_t rfsc[] = ZYD_AL7230B_RF_SETCHANNEL;
1133 (void)zyd_write16(sc, ZYD_CR240, 0x57);
1134 (void)zyd_write16(sc, ZYD_CR251, 0x2f);
1136 for (i = 0; i < N(rfsc); i++) {
1137 if ((error = zyd_rfwrite(sc, rfsc[i])) != 0)
1141 (void)zyd_write16(sc, ZYD_CR128, 0x14);
1142 (void)zyd_write16(sc, ZYD_CR129, 0x12);
1143 (void)zyd_write16(sc, ZYD_CR130, 0x10);
1144 (void)zyd_write16(sc, ZYD_CR38, 0x38);
1145 (void)zyd_write16(sc, ZYD_CR136, 0xdf);
1147 (void)zyd_rfwrite(sc, rfprog[chan - 1].r1);
1148 (void)zyd_rfwrite(sc, rfprog[chan - 1].r2);
1149 (void)zyd_rfwrite(sc, 0x3c9000);
1151 (void)zyd_write16(sc, ZYD_CR251, 0x3f);
1152 (void)zyd_write16(sc, ZYD_CR203, 0x06);
1153 (void)zyd_write16(sc, ZYD_CR240, 0x08);
1160 * AL2210 RF methods.
1163 zyd_al2210_init(struct zyd_rf *rf)
1165 #define N(a) (sizeof(a) / sizeof((a)[0]))
1166 struct zyd_softc *sc = rf->rf_sc;
1167 static const struct zyd_phy_pair phyini[] = ZYD_AL2210_PHY;
1168 static const uint32_t rfini[] = ZYD_AL2210_RF;
1172 (void)zyd_write32(sc, ZYD_CR18, 2);
1174 /* init RF-dependent PHY registers */
1175 for (i = 0; i < N(phyini); i++) {
1176 error = zyd_write16(sc, phyini[i].reg, phyini[i].val);
1180 /* init AL2210 radio */
1181 for (i = 0; i < N(rfini); i++) {
1182 if ((error = zyd_rfwrite(sc, rfini[i])) != 0)
1185 (void)zyd_write16(sc, ZYD_CR47, 0x1e);
1186 (void)zyd_read32(sc, ZYD_CR_RADIO_PD, &tmp);
1187 (void)zyd_write32(sc, ZYD_CR_RADIO_PD, tmp & ~1);
1188 (void)zyd_write32(sc, ZYD_CR_RADIO_PD, tmp | 1);
1189 (void)zyd_write32(sc, ZYD_CR_RFCFG, 0x05);
1190 (void)zyd_write32(sc, ZYD_CR_RFCFG, 0x00);
1191 (void)zyd_write16(sc, ZYD_CR47, 0x1e);
1192 (void)zyd_write32(sc, ZYD_CR18, 3);
1199 zyd_al2210_switch_radio(struct zyd_rf *rf, int on)
1201 /* vendor driver does nothing for this RF chip */
1207 zyd_al2210_set_channel(struct zyd_rf *rf, uint8_t chan)
1209 struct zyd_softc *sc = rf->rf_sc;
1210 static const uint32_t rfprog[] = ZYD_AL2210_CHANTABLE;
1213 (void)zyd_write32(sc, ZYD_CR18, 2);
1214 (void)zyd_write16(sc, ZYD_CR47, 0x1e);
1215 (void)zyd_read32(sc, ZYD_CR_RADIO_PD, &tmp);
1216 (void)zyd_write32(sc, ZYD_CR_RADIO_PD, tmp & ~1);
1217 (void)zyd_write32(sc, ZYD_CR_RADIO_PD, tmp | 1);
1218 (void)zyd_write32(sc, ZYD_CR_RFCFG, 0x05);
1220 (void)zyd_write32(sc, ZYD_CR_RFCFG, 0x00);
1221 (void)zyd_write16(sc, ZYD_CR47, 0x1e);
1223 /* actually set the channel */
1224 (void)zyd_rfwrite(sc, rfprog[chan - 1]);
1226 (void)zyd_write32(sc, ZYD_CR18, 3);
1235 zyd_gct_init(struct zyd_rf *rf)
1237 #define N(a) (sizeof(a) / sizeof((a)[0]))
1238 struct zyd_softc *sc = rf->rf_sc;
1239 static const struct zyd_phy_pair phyini[] = ZYD_GCT_PHY;
1240 static const uint32_t rfini[] = ZYD_GCT_RF;
1243 /* init RF-dependent PHY registers */
1244 for (i = 0; i < N(phyini); i++) {
1245 error = zyd_write16(sc, phyini[i].reg, phyini[i].val);
1249 /* init cgt radio */
1250 for (i = 0; i < N(rfini); i++) {
1251 if ((error = zyd_rfwrite(sc, rfini[i])) != 0)
1259 zyd_gct_switch_radio(struct zyd_rf *rf, int on)
1261 /* vendor driver does nothing for this RF chip */
1267 zyd_gct_set_channel(struct zyd_rf *rf, uint8_t chan)
1269 struct zyd_softc *sc = rf->rf_sc;
1270 static const uint32_t rfprog[] = ZYD_GCT_CHANTABLE;
1272 (void)zyd_rfwrite(sc, 0x1c0000);
1273 (void)zyd_rfwrite(sc, rfprog[chan - 1]);
1274 (void)zyd_rfwrite(sc, 0x1c0008);
1283 zyd_maxim_init(struct zyd_rf *rf)
1285 #define N(a) (sizeof(a) / sizeof((a)[0]))
1286 struct zyd_softc *sc = rf->rf_sc;
1287 static const struct zyd_phy_pair phyini[] = ZYD_MAXIM_PHY;
1288 static const uint32_t rfini[] = ZYD_MAXIM_RF;
1292 /* init RF-dependent PHY registers */
1293 for (i = 0; i < N(phyini); i++) {
1294 error = zyd_write16(sc, phyini[i].reg, phyini[i].val);
1298 (void)zyd_read16(sc, ZYD_CR203, &tmp);
1299 (void)zyd_write16(sc, ZYD_CR203, tmp & ~(1 << 4));
1301 /* init maxim radio */
1302 for (i = 0; i < N(rfini); i++) {
1303 if ((error = zyd_rfwrite(sc, rfini[i])) != 0)
1306 (void)zyd_read16(sc, ZYD_CR203, &tmp);
1307 (void)zyd_write16(sc, ZYD_CR203, tmp | (1 << 4));
1314 zyd_maxim_switch_radio(struct zyd_rf *rf, int on)
1316 /* vendor driver does nothing for this RF chip */
1322 zyd_maxim_set_channel(struct zyd_rf *rf, uint8_t chan)
1324 #define N(a) (sizeof(a) / sizeof((a)[0]))
1325 struct zyd_softc *sc = rf->rf_sc;
1326 static const struct zyd_phy_pair phyini[] = ZYD_MAXIM_PHY;
1327 static const uint32_t rfini[] = ZYD_MAXIM_RF;
1328 static const struct {
1330 } rfprog[] = ZYD_MAXIM_CHANTABLE;
1335 * Do the same as we do when initializing it, except for the channel
1336 * values coming from the two channel tables.
1339 /* init RF-dependent PHY registers */
1340 for (i = 0; i < N(phyini); i++) {
1341 error = zyd_write16(sc, phyini[i].reg, phyini[i].val);
1345 (void)zyd_read16(sc, ZYD_CR203, &tmp);
1346 (void)zyd_write16(sc, ZYD_CR203, tmp & ~(1 << 4));
1348 /* first two values taken from the chantables */
1349 (void)zyd_rfwrite(sc, rfprog[chan - 1].r1);
1350 (void)zyd_rfwrite(sc, rfprog[chan - 1].r2);
1352 /* init maxim radio - skipping the two first values */
1353 for (i = 2; i < N(rfini); i++) {
1354 if ((error = zyd_rfwrite(sc, rfini[i])) != 0)
1357 (void)zyd_read16(sc, ZYD_CR203, &tmp);
1358 (void)zyd_write16(sc, ZYD_CR203, tmp | (1 << 4));
1365 * Maxim2 RF methods.
1368 zyd_maxim2_init(struct zyd_rf *rf)
1370 #define N(a) (sizeof(a) / sizeof((a)[0]))
1371 struct zyd_softc *sc = rf->rf_sc;
1372 static const struct zyd_phy_pair phyini[] = ZYD_MAXIM2_PHY;
1373 static const uint32_t rfini[] = ZYD_MAXIM2_RF;
1377 /* init RF-dependent PHY registers */
1378 for (i = 0; i < N(phyini); i++) {
1379 error = zyd_write16(sc, phyini[i].reg, phyini[i].val);
1383 (void)zyd_read16(sc, ZYD_CR203, &tmp);
1384 (void)zyd_write16(sc, ZYD_CR203, tmp & ~(1 << 4));
1386 /* init maxim2 radio */
1387 for (i = 0; i < N(rfini); i++) {
1388 if ((error = zyd_rfwrite(sc, rfini[i])) != 0)
1391 (void)zyd_read16(sc, ZYD_CR203, &tmp);
1392 (void)zyd_write16(sc, ZYD_CR203, tmp | (1 << 4));
1399 zyd_maxim2_switch_radio(struct zyd_rf *rf, int on)
1401 /* vendor driver does nothing for this RF chip */
1407 zyd_maxim2_set_channel(struct zyd_rf *rf, uint8_t chan)
1409 #define N(a) (sizeof(a) / sizeof((a)[0]))
1410 struct zyd_softc *sc = rf->rf_sc;
1411 static const struct zyd_phy_pair phyini[] = ZYD_MAXIM2_PHY;
1412 static const uint32_t rfini[] = ZYD_MAXIM2_RF;
1413 static const struct {
1415 } rfprog[] = ZYD_MAXIM2_CHANTABLE;
1420 * Do the same as we do when initializing it, except for the channel
1421 * values coming from the two channel tables.
1424 /* init RF-dependent PHY registers */
1425 for (i = 0; i < N(phyini); i++) {
1426 error = zyd_write16(sc, phyini[i].reg, phyini[i].val);
1430 (void)zyd_read16(sc, ZYD_CR203, &tmp);
1431 (void)zyd_write16(sc, ZYD_CR203, tmp & ~(1 << 4));
1433 /* first two values taken from the chantables */
1434 (void)zyd_rfwrite(sc, rfprog[chan - 1].r1);
1435 (void)zyd_rfwrite(sc, rfprog[chan - 1].r2);
1437 /* init maxim2 radio - skipping the two first values */
1438 for (i = 2; i < N(rfini); i++) {
1439 if ((error = zyd_rfwrite(sc, rfini[i])) != 0)
1442 (void)zyd_read16(sc, ZYD_CR203, &tmp);
1443 (void)zyd_write16(sc, ZYD_CR203, tmp | (1 << 4));
1450 zyd_rf_attach(struct zyd_softc *sc, uint8_t type)
1452 struct zyd_rf *rf = &sc->sc_rf;
1458 rf->init = zyd_rfmd_init;
1459 rf->switch_radio = zyd_rfmd_switch_radio;
1460 rf->set_channel = zyd_rfmd_set_channel;
1461 rf->width = 24; /* 24-bit RF values */
1464 if (sc->mac_rev == ZYD_ZD1211B)
1465 rf->init = zyd_al2230_init_b;
1467 rf->init = zyd_al2230_init;
1468 rf->switch_radio = zyd_al2230_switch_radio;
1469 rf->set_channel = zyd_al2230_set_channel;
1470 rf->width = 24; /* 24-bit RF values */
1472 case ZYD_RF_AL7230B:
1473 rf->init = zyd_al7230B_init;
1474 rf->switch_radio = zyd_al7230B_switch_radio;
1475 rf->set_channel = zyd_al7230B_set_channel;
1476 rf->width = 24; /* 24-bit RF values */
1479 rf->init = zyd_al2210_init;
1480 rf->switch_radio = zyd_al2210_switch_radio;
1481 rf->set_channel = zyd_al2210_set_channel;
1482 rf->width = 24; /* 24-bit RF values */
1485 rf->init = zyd_gct_init;
1486 rf->switch_radio = zyd_gct_switch_radio;
1487 rf->set_channel = zyd_gct_set_channel;
1488 rf->width = 21; /* 21-bit RF values */
1490 case ZYD_RF_MAXIM_NEW:
1491 rf->init = zyd_maxim_init;
1492 rf->switch_radio = zyd_maxim_switch_radio;
1493 rf->set_channel = zyd_maxim_set_channel;
1494 rf->width = 18; /* 18-bit RF values */
1496 case ZYD_RF_MAXIM_NEW2:
1497 rf->init = zyd_maxim2_init;
1498 rf->switch_radio = zyd_maxim2_switch_radio;
1499 rf->set_channel = zyd_maxim2_set_channel;
1500 rf->width = 18; /* 18-bit RF values */
1503 device_printf(sc->sc_dev,
1504 "sorry, radio \"%s\" is not supported yet\n",
1512 zyd_rf_name(uint8_t type)
1514 static const char * const zyd_rfs[] = {
1515 "unknown", "unknown", "UW2451", "UCHIP", "AL2230",
1516 "AL7230B", "THETA", "AL2210", "MAXIM_NEW", "GCT",
1517 "PV2000", "RALINK", "INTERSIL", "RFMD", "MAXIM_NEW2",
1521 return zyd_rfs[(type > 15) ? 0 : type];
1525 zyd_hw_init(struct zyd_softc *sc)
1527 struct zyd_rf *rf = &sc->sc_rf;
1528 const struct zyd_phy_pair *phyp;
1532 /* specify that the plug and play is finished */
1533 (void)zyd_write32(sc, ZYD_MAC_AFTER_PNP, 1);
1535 (void)zyd_read16(sc, ZYD_FIRMWARE_BASE_ADDR, &sc->fwbase);
1536 DPRINTF(("firmware base address=0x%04x\n", sc->fwbase));
1538 /* retrieve firmware revision number */
1539 (void)zyd_read16(sc, sc->fwbase + ZYD_FW_FIRMWARE_REV, &sc->fw_rev);
1541 (void)zyd_write32(sc, ZYD_CR_GPI_EN, 0);
1542 (void)zyd_write32(sc, ZYD_MAC_CONT_WIN_LIMIT, 0x7f043f);
1544 /* disable interrupts */
1545 (void)zyd_write32(sc, ZYD_CR_INTERRUPT, 0);
1549 phyp = (sc->mac_rev == ZYD_ZD1211B) ? zyd_def_phyB : zyd_def_phy;
1550 for (; phyp->reg != 0; phyp++) {
1551 if ((error = zyd_write16(sc, phyp->reg, phyp->val)) != 0)
1554 if (sc->fix_cr157) {
1555 if (zyd_read32(sc, ZYD_EEPROM_PHY_REG, &tmp) == 0)
1556 (void)zyd_write32(sc, ZYD_CR157, tmp >> 8);
1561 zyd_write32(sc, ZYD_MAC_ACK_EXT, 0x00000020);
1562 zyd_write32(sc, ZYD_CR_ADDA_MBIAS_WT, 0x30000808);
1564 if (sc->mac_rev == ZYD_ZD1211) {
1565 zyd_write32(sc, ZYD_MAC_RETRY, 0x00000002);
1567 zyd_write32(sc, ZYD_MACB_MAX_RETRY, 0x02020202);
1568 zyd_write32(sc, ZYD_MACB_TXPWR_CTL4, 0x007f003f);
1569 zyd_write32(sc, ZYD_MACB_TXPWR_CTL3, 0x007f003f);
1570 zyd_write32(sc, ZYD_MACB_TXPWR_CTL2, 0x003f001f);
1571 zyd_write32(sc, ZYD_MACB_TXPWR_CTL1, 0x001f000f);
1572 zyd_write32(sc, ZYD_MACB_AIFS_CTL1, 0x00280028);
1573 zyd_write32(sc, ZYD_MACB_AIFS_CTL2, 0x008C003C);
1574 zyd_write32(sc, ZYD_MACB_TXOP, 0x01800824);
1577 zyd_write32(sc, ZYD_MAC_SNIFFER, 0x00000000);
1578 zyd_write32(sc, ZYD_MAC_RXFILTER, 0x00000000);
1579 zyd_write32(sc, ZYD_MAC_GHTBL, 0x00000000);
1580 zyd_write32(sc, ZYD_MAC_GHTBH, 0x80000000);
1581 zyd_write32(sc, ZYD_MAC_MISC, 0x000000a4);
1582 zyd_write32(sc, ZYD_CR_ADDA_PWR_DWN, 0x0000007f);
1583 zyd_write32(sc, ZYD_MAC_BCNCFG, 0x00f00401);
1584 zyd_write32(sc, ZYD_MAC_PHY_DELAY2, 0x00000000);
1585 zyd_write32(sc, ZYD_MAC_ACK_EXT, 0x00000080);
1586 zyd_write32(sc, ZYD_CR_ADDA_PWR_DWN, 0x00000000);
1587 zyd_write32(sc, ZYD_MAC_SIFS_ACK_TIME, 0x00000100);
1588 zyd_write32(sc, ZYD_MAC_DIFS_EIFS_SIFS, 0x0547c032);
1589 zyd_write32(sc, ZYD_CR_RX_PE_DELAY, 0x00000070);
1590 zyd_write32(sc, ZYD_CR_PS_CTRL, 0x10000000);
1591 zyd_write32(sc, ZYD_MAC_RTSCTSRATE, 0x02030203);
1592 zyd_write32(sc, ZYD_MAC_RX_THRESHOLD, 0x000c0640);
1593 zyd_write32(sc, ZYD_MAC_BACKOFF_PROTECT, 0x00000114);
1597 error = (*rf->init)(rf);
1600 device_printf(sc->sc_dev,
1601 "radio initialization failed, error %d\n", error);
1605 /* init beacon interval to 100ms */
1606 if ((error = zyd_set_beacon_interval(sc, 100)) != 0)
1613 zyd_read_eeprom(struct zyd_softc *sc)
1615 struct ifnet *ifp = sc->sc_ifp;
1616 struct ieee80211com *ic = ifp->if_l2com;
1621 /* read MAC address */
1622 (void)zyd_read32(sc, ZYD_EEPROM_MAC_ADDR_P1, &tmp);
1623 ic->ic_myaddr[0] = tmp & 0xff;
1624 ic->ic_myaddr[1] = tmp >> 8;
1625 ic->ic_myaddr[2] = tmp >> 16;
1626 ic->ic_myaddr[3] = tmp >> 24;
1627 (void)zyd_read32(sc, ZYD_EEPROM_MAC_ADDR_P2, &tmp);
1628 ic->ic_myaddr[4] = tmp & 0xff;
1629 ic->ic_myaddr[5] = tmp >> 8;
1631 (void)zyd_read32(sc, ZYD_EEPROM_POD, &tmp);
1632 sc->rf_rev = tmp & 0x0f;
1633 sc->fix_cr47 = (tmp >> 8 ) & 0x01;
1634 sc->fix_cr157 = (tmp >> 13) & 0x01;
1635 sc->pa_rev = (tmp >> 16) & 0x0f;
1637 /* read regulatory domain (currently unused) */
1638 (void)zyd_read32(sc, ZYD_EEPROM_SUBID, &tmp);
1639 sc->regdomain = tmp >> 16;
1640 DPRINTF(("regulatory domain %x\n", sc->regdomain));
1641 /* XXX propagate to net80211 after mapping to SKU */
1643 /* read Tx power calibration tables */
1644 for (i = 0; i < 7; i++) {
1645 (void)zyd_read16(sc, ZYD_EEPROM_PWR_CAL + i, &val);
1646 sc->pwr_cal[i * 2] = val >> 8;
1647 sc->pwr_cal[i * 2 + 1] = val & 0xff;
1649 (void)zyd_read16(sc, ZYD_EEPROM_PWR_INT + i, &val);
1650 sc->pwr_int[i * 2] = val >> 8;
1651 sc->pwr_int[i * 2 + 1] = val & 0xff;
1653 (void)zyd_read16(sc, ZYD_EEPROM_36M_CAL + i, &val);
1654 sc->ofdm36_cal[i * 2] = val >> 8;
1655 sc->ofdm36_cal[i * 2 + 1] = val & 0xff;
1657 (void)zyd_read16(sc, ZYD_EEPROM_48M_CAL + i, &val);
1658 sc->ofdm48_cal[i * 2] = val >> 8;
1659 sc->ofdm48_cal[i * 2 + 1] = val & 0xff;
1661 (void)zyd_read16(sc, ZYD_EEPROM_54M_CAL + i, &val);
1662 sc->ofdm54_cal[i * 2] = val >> 8;
1663 sc->ofdm54_cal[i * 2 + 1] = val & 0xff;
1669 zyd_set_macaddr(struct zyd_softc *sc, const uint8_t *addr)
1673 tmp = addr[3] << 24 | addr[2] << 16 | addr[1] << 8 | addr[0];
1674 (void)zyd_write32(sc, ZYD_MAC_MACADRL, tmp);
1676 tmp = addr[5] << 8 | addr[4];
1677 (void)zyd_write32(sc, ZYD_MAC_MACADRH, tmp);
1683 zyd_set_bssid(struct zyd_softc *sc, const uint8_t *addr)
1687 tmp = addr[3] << 24 | addr[2] << 16 | addr[1] << 8 | addr[0];
1688 (void)zyd_write32(sc, ZYD_MAC_BSSADRL, tmp);
1690 tmp = addr[5] << 8 | addr[4];
1691 (void)zyd_write32(sc, ZYD_MAC_BSSADRH, tmp);
1697 zyd_switch_radio(struct zyd_softc *sc, int on)
1699 struct zyd_rf *rf = &sc->sc_rf;
1703 error = (*rf->switch_radio)(rf, on);
1710 zyd_set_led(struct zyd_softc *sc, int which, int on)
1714 (void)zyd_read32(sc, ZYD_MAC_TX_PE_CONTROL, &tmp);
1718 (void)zyd_write32(sc, ZYD_MAC_TX_PE_CONTROL, tmp);
1722 zyd_set_multi(void *arg)
1724 struct zyd_softc *sc = arg;
1725 struct ifnet *ifp = sc->sc_ifp;
1726 struct ieee80211com *ic = ifp->if_l2com;
1727 struct ifmultiaddr *ifma;
1731 if (!(ifp->if_flags & IFF_UP))
1737 if (ic->ic_opmode == IEEE80211_M_MONITOR ||
1738 (ifp->if_flags & (IFF_ALLMULTI | IFF_PROMISC))) {
1743 TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
1744 if (ifma->ifma_addr->sa_family != AF_LINK)
1746 v = ((uint8_t *)LLADDR((struct sockaddr_dl *)
1747 ifma->ifma_addr))[5] >> 2;
1751 high |= 1 << (v - 32);
1753 IF_ADDR_UNLOCK(ifp);
1756 /* reprogram multicast global hash table */
1757 zyd_write32(sc, ZYD_MAC_GHTBL, low);
1758 zyd_write32(sc, ZYD_MAC_GHTBH, high);
1762 zyd_update_mcast(struct ifnet *ifp)
1764 struct zyd_softc *sc = ifp->if_softc;
1766 usb_add_task(sc->sc_udev, &sc->sc_mcasttask, USB_TASKQ_DRIVER);
1770 zyd_set_rxfilter(struct zyd_softc *sc)
1772 struct ifnet *ifp = sc->sc_ifp;
1773 struct ieee80211com *ic = ifp->if_l2com;
1776 switch (ic->ic_opmode) {
1777 case IEEE80211_M_STA:
1778 rxfilter = ZYD_FILTER_BSS;
1780 case IEEE80211_M_IBSS:
1781 case IEEE80211_M_HOSTAP:
1782 rxfilter = ZYD_FILTER_HOSTAP;
1784 case IEEE80211_M_MONITOR:
1785 rxfilter = ZYD_FILTER_MONITOR;
1788 /* should not get there */
1791 return zyd_write32(sc, ZYD_MAC_RXFILTER, rxfilter);
1795 zyd_set_chan(struct zyd_softc *sc, struct ieee80211_channel *c)
1797 struct ifnet *ifp = sc->sc_ifp;
1798 struct ieee80211com *ic = ifp->if_l2com;
1799 struct zyd_rf *rf = &sc->sc_rf;
1803 chan = ieee80211_chan2ieee(ic, c);
1804 if (chan == 0 || chan == IEEE80211_CHAN_ANY) {
1805 /* XXX should NEVER happen */
1806 device_printf(sc->sc_dev,
1807 "%s: invalid channel %x\n", __func__, chan);
1813 (*rf->set_channel)(rf, chan);
1815 /* update Tx power */
1816 (void)zyd_write16(sc, ZYD_CR31, sc->pwr_int[chan - 1]);
1818 if (sc->mac_rev == ZYD_ZD1211B) {
1819 (void)zyd_write16(sc, ZYD_CR67, sc->ofdm36_cal[chan - 1]);
1820 (void)zyd_write16(sc, ZYD_CR66, sc->ofdm48_cal[chan - 1]);
1821 (void)zyd_write16(sc, ZYD_CR65, sc->ofdm54_cal[chan - 1]);
1823 (void)zyd_write16(sc, ZYD_CR68, sc->pwr_cal[chan - 1]);
1825 (void)zyd_write16(sc, ZYD_CR69, 0x28);
1826 (void)zyd_write16(sc, ZYD_CR69, 0x2a);
1830 /* set CCK baseband gain from EEPROM */
1831 if (zyd_read32(sc, ZYD_EEPROM_PHY_REG, &tmp) == 0)
1832 (void)zyd_write16(sc, ZYD_CR47, tmp & 0xff);
1835 (void)zyd_write32(sc, ZYD_CR_CONFIG_PHILIPS, 0);
1839 sc->sc_rxtap.wr_chan_freq = sc->sc_txtap.wt_chan_freq =
1840 htole16(c->ic_freq);
1841 sc->sc_rxtap.wr_chan_flags = sc->sc_txtap.wt_chan_flags =
1842 htole16(c->ic_flags);
1846 zyd_set_beacon_interval(struct zyd_softc *sc, int bintval)
1848 /* XXX this is probably broken.. */
1849 (void)zyd_write32(sc, ZYD_CR_ATIM_WND_PERIOD, bintval - 2);
1850 (void)zyd_write32(sc, ZYD_CR_PRE_TBTT, bintval - 1);
1851 (void)zyd_write32(sc, ZYD_CR_BCN_INTERVAL, bintval);
1857 zyd_intr(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status)
1859 struct zyd_softc *sc = (struct zyd_softc *)priv;
1860 struct zyd_cmd *cmd;
1863 if (status != USBD_NORMAL_COMPLETION) {
1864 if (status == USBD_NOT_STARTED || status == USBD_CANCELLED)
1867 if (status == USBD_STALLED) {
1868 usbd_clear_endpoint_stall_async(
1869 sc->zyd_ep[ZYD_ENDPT_IIN]);
1874 cmd = (struct zyd_cmd *)sc->ibuf;
1876 if (le16toh(cmd->code) == ZYD_NOTIF_RETRYSTATUS) {
1877 struct zyd_notif_retry *retry =
1878 (struct zyd_notif_retry *)cmd->data;
1879 struct ifnet *ifp = sc->sc_ifp;
1880 struct ieee80211com *ic = ifp->if_l2com;
1881 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps);
1882 struct ieee80211_node *ni;
1884 DPRINTF(("retry intr: rate=0x%x addr=%s count=%d (0x%x)\n",
1885 le16toh(retry->rate), ether_sprintf(retry->macaddr),
1886 le16toh(retry->count) & 0xff, le16toh(retry->count)));
1889 * Find the node to which the packet was sent and update its
1890 * retry statistics. In BSS mode, this node is the AP we're
1891 * associated to so no lookup is actually needed.
1893 ni = ieee80211_find_txnode(vap, retry->macaddr);
1895 ieee80211_amrr_tx_complete(&ZYD_NODE(ni)->amn,
1896 IEEE80211_AMRR_FAILURE, 1);
1897 ieee80211_free_node(ni);
1899 if (le16toh(retry->count) & 0x100)
1900 ifp->if_oerrors++; /* too many retries */
1901 } else if (le16toh(cmd->code) == ZYD_NOTIF_IORD) {
1904 if (le16toh(*(uint16_t *)cmd->data) == ZYD_CR_INTERRUPT)
1905 return; /* HMAC interrupt */
1907 usbd_get_xfer_status(xfer, NULL, NULL, &datalen, NULL);
1908 datalen -= sizeof(cmd->code);
1909 datalen -= 2; /* XXX: padding? */
1911 STAILQ_FOREACH(rqp, &sc->sc_rqh, rq) {
1914 if (sizeof(struct zyd_pair) * rqp->len != datalen)
1916 for (i = 0; i < rqp->len; i++) {
1917 if (*(((const uint16_t *)rqp->idata) + i) !=
1918 (((struct zyd_pair *)cmd->data) + i)->reg)
1924 /* copy answer into caller-supplied buffer */
1925 bcopy(cmd->data, rqp->odata,
1926 sizeof(struct zyd_pair) * rqp->len);
1927 wakeup(rqp->odata); /* wakeup caller */
1931 return; /* unexpected IORD notification */
1933 device_printf(sc->sc_dev, "unknown notification %x\n",
1934 le16toh(cmd->code));
1939 zyd_rx_data(struct zyd_softc *sc, const uint8_t *buf, uint16_t len)
1941 struct ifnet *ifp = sc->sc_ifp;
1942 struct ieee80211com *ic = ifp->if_l2com;
1943 struct ieee80211_node *ni;
1944 const struct zyd_plcphdr *plcp;
1945 const struct zyd_rx_stat *stat;
1949 if (len < ZYD_MIN_FRAGSZ) {
1950 DPRINTF(("%s: frame too short (length=%d)\n",
1951 device_get_nameunit(sc->sc_dev), len));
1956 plcp = (const struct zyd_plcphdr *)buf;
1957 stat = (const struct zyd_rx_stat *)
1958 (buf + len - sizeof(struct zyd_rx_stat));
1960 if (stat->flags & ZYD_RX_ERROR) {
1961 DPRINTF(("%s: RX status indicated error (%x)\n",
1962 device_get_nameunit(sc->sc_dev), stat->flags));
1967 /* compute actual frame length */
1968 rlen = len - sizeof(struct zyd_plcphdr) -
1969 sizeof(struct zyd_rx_stat) - IEEE80211_CRC_LEN;
1971 /* allocate a mbuf to store the frame */
1973 m = m_getcl(M_DONTWAIT, MT_DATA, M_PKTHDR);
1975 m = m_gethdr(M_DONTWAIT, MT_DATA);
1977 DPRINTF(("%s: could not allocate rx mbuf\n",
1978 device_get_nameunit(sc->sc_dev)));
1982 m->m_pkthdr.rcvif = ifp;
1983 m->m_pkthdr.len = m->m_len = rlen;
1984 bcopy((const uint8_t *)(plcp + 1), mtod(m, uint8_t *), rlen);
1986 if (bpf_peers_present(ifp->if_bpf)) {
1987 struct zyd_rx_radiotap_header *tap = &sc->sc_rxtap;
1990 if (stat->flags & (ZYD_RX_BADCRC16 | ZYD_RX_BADCRC32))
1991 tap->wr_flags |= IEEE80211_RADIOTAP_F_BADFCS;
1992 /* XXX toss, no way to express errors */
1993 if (stat->flags & ZYD_RX_DECRYPTERR)
1994 tap->wr_flags |= IEEE80211_RADIOTAP_F_BADFCS;
1995 tap->wr_rate = ieee80211_plcp2rate(plcp->signal,
1996 (stat->flags & ZYD_RX_OFDM) ?
1997 IEEE80211_T_OFDM : IEEE80211_T_CCK);
1998 tap->wr_antsignal = stat->rssi + -95;
1999 tap->wr_antnoise = -95; /* XXX */
2001 bpf_mtap2(ifp->if_bpf, tap, sc->sc_rxtap_len, m);
2004 rssi = stat->rssi > 63 ? 127 : 2 * stat->rssi;
2007 ni = ieee80211_find_rxnode(ic, mtod(m, struct ieee80211_frame_min *));
2009 (void) ieee80211_input(ni, m, rssi, nf, 0);
2010 ieee80211_free_node(ni);
2012 (void) ieee80211_input_all(ic, m, rssi, nf, 0);
2016 zyd_rxeof(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status)
2018 struct zyd_rx_data *data = priv;
2019 struct zyd_softc *sc = data->sc;
2020 struct ifnet *ifp = sc->sc_ifp;
2021 const struct zyd_rx_desc *desc;
2024 if (status != USBD_NORMAL_COMPLETION) {
2025 if (status == USBD_NOT_STARTED || status == USBD_CANCELLED)
2028 if (status == USBD_STALLED)
2029 usbd_clear_endpoint_stall(sc->zyd_ep[ZYD_ENDPT_BIN]);
2033 usbd_get_xfer_status(xfer, NULL, NULL, &len, NULL);
2035 if (len < ZYD_MIN_RXBUFSZ) {
2036 DPRINTFN(3, ("%s: xfer too short (length=%d)\n",
2037 device_get_nameunit(sc->sc_dev), len));
2038 ifp->if_ierrors++; /* XXX not really errors */
2042 desc = (const struct zyd_rx_desc *)
2043 (data->buf + len - sizeof(struct zyd_rx_desc));
2045 if (UGETW(desc->tag) == ZYD_TAG_MULTIFRAME) {
2046 const uint8_t *p = data->buf, *end = p + len;
2049 DPRINTFN(3, ("received multi-frame transfer\n"));
2051 for (i = 0; i < ZYD_MAX_RXFRAMECNT; i++) {
2052 const uint16_t len16 = UGETW(desc->len[i]);
2054 if (len16 == 0 || p + len16 > end)
2057 zyd_rx_data(sc, p, len16);
2058 /* next frame is aligned on a 32-bit boundary */
2059 p += (len16 + 3) & ~3;
2062 DPRINTFN(3, ("received single-frame transfer\n"));
2064 zyd_rx_data(sc, data->buf, len);
2067 skip: /* setup a new transfer */
2068 usbd_setup_xfer(xfer, sc->zyd_ep[ZYD_ENDPT_BIN], data, NULL,
2069 ZYX_MAX_RXBUFSZ, USBD_NO_COPY | USBD_SHORT_XFER_OK,
2070 USBD_NO_TIMEOUT, zyd_rxeof);
2071 (void)usbd_transfer(xfer);
2075 zyd_plcp_signal(int rate)
2078 /* OFDM rates (cf IEEE Std 802.11a-1999, pp. 14 Table 80) */
2079 case 12: return 0xb;
2080 case 18: return 0xf;
2081 case 24: return 0xa;
2082 case 36: return 0xe;
2083 case 48: return 0x9;
2084 case 72: return 0xd;
2085 case 96: return 0x8;
2086 case 108: return 0xc;
2088 /* CCK rates (NB: not IEEE std, device-specific) */
2091 case 11: return 0x2;
2092 case 22: return 0x3;
2094 return 0xff; /* XXX unsupported/unknown rate */
2098 zyd_tx_mgt(struct zyd_softc *sc, struct mbuf *m0, struct ieee80211_node *ni)
2100 struct ieee80211vap *vap = ni->ni_vap;
2101 struct ieee80211com *ic = ni->ni_ic;
2102 struct ifnet *ifp = sc->sc_ifp;
2103 struct zyd_tx_desc *desc;
2104 struct zyd_tx_data *data;
2105 struct ieee80211_frame *wh;
2106 struct ieee80211_key *k;
2107 int xferlen, totlen, rate;
2111 data = &sc->tx_data[0];
2112 desc = (struct zyd_tx_desc *)data->buf;
2114 rate = IEEE80211_IS_CHAN_5GHZ(ic->ic_curchan) ? 12 : 2;
2116 wh = mtod(m0, struct ieee80211_frame *);
2118 if (wh->i_fc[1] & IEEE80211_FC1_WEP) {
2119 k = ieee80211_crypto_encap(ni, m0);
2129 wh = mtod(m0, struct ieee80211_frame *);
2131 xferlen = sizeof(struct zyd_tx_desc) + m0->m_pkthdr.len;
2132 totlen = m0->m_pkthdr.len + IEEE80211_CRC_LEN;
2134 /* fill Tx descriptor */
2135 desc->len = htole16(totlen);
2137 desc->flags = ZYD_TX_FLAG_BACKOFF;
2138 if (!IEEE80211_IS_MULTICAST(wh->i_addr1)) {
2139 /* multicast frames are not sent at OFDM rates in 802.11b/g */
2140 if (totlen > vap->iv_rtsthreshold) {
2141 desc->flags |= ZYD_TX_FLAG_RTS;
2142 } else if (ZYD_RATE_IS_OFDM(rate) &&
2143 (ic->ic_flags & IEEE80211_F_USEPROT)) {
2144 if (ic->ic_protmode == IEEE80211_PROT_CTSONLY)
2145 desc->flags |= ZYD_TX_FLAG_CTS_TO_SELF;
2146 else if (ic->ic_protmode == IEEE80211_PROT_RTSCTS)
2147 desc->flags |= ZYD_TX_FLAG_RTS;
2150 desc->flags |= ZYD_TX_FLAG_MULTICAST;
2153 (IEEE80211_FC0_TYPE_MASK | IEEE80211_FC0_SUBTYPE_MASK)) ==
2154 (IEEE80211_FC0_TYPE_CTL | IEEE80211_FC0_SUBTYPE_PS_POLL))
2155 desc->flags |= ZYD_TX_FLAG_TYPE(ZYD_TX_TYPE_PS_POLL);
2157 desc->phy = zyd_plcp_signal(rate);
2158 if (ZYD_RATE_IS_OFDM(rate)) {
2159 desc->phy |= ZYD_TX_PHY_OFDM;
2160 if (IEEE80211_IS_CHAN_5GHZ(ic->ic_curchan))
2161 desc->phy |= ZYD_TX_PHY_5GHZ;
2162 } else if (rate != 2 && (ic->ic_flags & IEEE80211_F_SHPREAMBLE))
2163 desc->phy |= ZYD_TX_PHY_SHPREAMBLE;
2165 /* actual transmit length (XXX why +10?) */
2166 pktlen = sizeof(struct zyd_tx_desc) + 10;
2167 if (sc->mac_rev == ZYD_ZD1211)
2169 desc->pktlen = htole16(pktlen);
2171 desc->plcp_length = (16 * totlen + rate - 1) / rate;
2172 desc->plcp_service = 0;
2174 const int remainder = (16 * totlen) % 22;
2175 if (remainder != 0 && remainder < 7)
2176 desc->plcp_service |= ZYD_PLCP_LENGEXT;
2179 if (bpf_peers_present(ifp->if_bpf)) {
2180 struct zyd_tx_radiotap_header *tap = &sc->sc_txtap;
2183 tap->wt_rate = rate;
2185 bpf_mtap2(ifp->if_bpf, tap, sc->sc_txtap_len, m0);
2188 m_copydata(m0, 0, m0->m_pkthdr.len,
2189 data->buf + sizeof(struct zyd_tx_desc));
2191 DPRINTFN(10, ("%s: sending mgt frame len=%zu rate=%u xferlen=%u\n",
2192 device_get_nameunit(sc->sc_dev), (size_t)m0->m_pkthdr.len,
2195 usbd_setup_xfer(data->xfer, sc->zyd_ep[ZYD_ENDPT_BOUT], data,
2196 data->buf, xferlen, USBD_FORCE_SHORT_XFER | USBD_NO_COPY,
2197 ZYD_TX_TIMEOUT, zyd_txeof);
2198 error = usbd_transfer(data->xfer);
2199 if (error != USBD_IN_PROGRESS && error != 0) {
2209 zyd_txeof(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status)
2211 struct zyd_tx_data *data = priv;
2212 struct zyd_softc *sc = data->sc;
2213 struct ifnet *ifp = sc->sc_ifp;
2214 struct ieee80211_node *ni;
2217 if (status != USBD_NORMAL_COMPLETION) {
2218 if (status == USBD_NOT_STARTED || status == USBD_CANCELLED)
2221 device_printf(sc->sc_dev, "could not transmit buffer: %s\n",
2222 usbd_errstr(status));
2224 if (status == USBD_STALLED) {
2225 usbd_clear_endpoint_stall_async(
2226 sc->zyd_ep[ZYD_ENDPT_BOUT]);
2233 /* update rate control statistics */
2234 ieee80211_amrr_tx_complete(&ZYD_NODE(ni)->amn,
2235 IEEE80211_AMRR_SUCCESS, 0);
2238 * Do any tx complete callback. Note this must
2239 * be done before releasing the node reference.
2242 if (m != NULL && m->m_flags & M_TXCB) {
2243 ieee80211_process_callback(ni, m, 0); /* XXX status? */
2248 ieee80211_free_node(ni);
2255 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
2260 zyd_tx_data(struct zyd_softc *sc, struct mbuf *m0, struct ieee80211_node *ni)
2262 struct ieee80211vap *vap = ni->ni_vap;
2263 struct ieee80211com *ic = ni->ni_ic;
2264 struct ifnet *ifp = sc->sc_ifp;
2265 struct zyd_tx_desc *desc;
2266 struct zyd_tx_data *data;
2267 struct ieee80211_frame *wh;
2268 const struct ieee80211_txparam *tp;
2269 struct ieee80211_key *k;
2270 int xferlen, totlen, rate;
2274 wh = mtod(m0, struct ieee80211_frame *);
2275 data = &sc->tx_data[0];
2276 desc = (struct zyd_tx_desc *)data->buf;
2278 desc->flags = ZYD_TX_FLAG_BACKOFF;
2279 tp = &vap->iv_txparms[ieee80211_chan2mode(ni->ni_chan)];
2280 if (IEEE80211_IS_MULTICAST(wh->i_addr1)) {
2281 rate = tp->mcastrate;
2282 desc->flags |= ZYD_TX_FLAG_MULTICAST;
2283 } else if (tp->ucastrate != IEEE80211_FIXED_RATE_NONE) {
2284 rate = tp->ucastrate;
2286 (void) ieee80211_amrr_choose(ni, &ZYD_NODE(ni)->amn);
2287 rate = ni->ni_txrate;
2290 if (wh->i_fc[1] & IEEE80211_FC1_WEP) {
2291 k = ieee80211_crypto_encap(ni, m0);
2297 /* packet header may have moved, reset our local pointer */
2298 wh = mtod(m0, struct ieee80211_frame *);
2304 xferlen = sizeof(struct zyd_tx_desc) + m0->m_pkthdr.len;
2305 totlen = m0->m_pkthdr.len + IEEE80211_CRC_LEN;
2307 /* fill Tx descriptor */
2308 desc->len = htole16(totlen);
2310 if (!IEEE80211_IS_MULTICAST(wh->i_addr1)) {
2311 /* multicast frames are not sent at OFDM rates in 802.11b/g */
2312 if (totlen > vap->iv_rtsthreshold) {
2313 desc->flags |= ZYD_TX_FLAG_RTS;
2314 } else if (ZYD_RATE_IS_OFDM(rate) &&
2315 (ic->ic_flags & IEEE80211_F_USEPROT)) {
2316 if (ic->ic_protmode == IEEE80211_PROT_CTSONLY)
2317 desc->flags |= ZYD_TX_FLAG_CTS_TO_SELF;
2318 else if (ic->ic_protmode == IEEE80211_PROT_RTSCTS)
2319 desc->flags |= ZYD_TX_FLAG_RTS;
2324 (IEEE80211_FC0_TYPE_MASK | IEEE80211_FC0_SUBTYPE_MASK)) ==
2325 (IEEE80211_FC0_TYPE_CTL | IEEE80211_FC0_SUBTYPE_PS_POLL))
2326 desc->flags |= ZYD_TX_FLAG_TYPE(ZYD_TX_TYPE_PS_POLL);
2328 desc->phy = zyd_plcp_signal(rate);
2329 if (ZYD_RATE_IS_OFDM(rate)) {
2330 desc->phy |= ZYD_TX_PHY_OFDM;
2331 if (IEEE80211_IS_CHAN_5GHZ(ic->ic_curchan))
2332 desc->phy |= ZYD_TX_PHY_5GHZ;
2333 } else if (rate != 2 && (ic->ic_flags & IEEE80211_F_SHPREAMBLE))
2334 desc->phy |= ZYD_TX_PHY_SHPREAMBLE;
2336 /* actual transmit length (XXX why +10?) */
2337 pktlen = sizeof(struct zyd_tx_desc) + 10;
2338 if (sc->mac_rev == ZYD_ZD1211)
2340 desc->pktlen = htole16(pktlen);
2342 desc->plcp_length = (16 * totlen + rate - 1) / rate;
2343 desc->plcp_service = 0;
2345 const int remainder = (16 * totlen) % 22;
2346 if (remainder != 0 && remainder < 7)
2347 desc->plcp_service |= ZYD_PLCP_LENGEXT;
2350 if (bpf_peers_present(ifp->if_bpf)) {
2351 struct zyd_tx_radiotap_header *tap = &sc->sc_txtap;
2354 tap->wt_rate = rate;
2355 tap->wt_chan_freq = htole16(ic->ic_curchan->ic_freq);
2356 tap->wt_chan_flags = htole16(ic->ic_curchan->ic_flags);
2358 bpf_mtap2(ifp->if_bpf, tap, sc->sc_txtap_len, m0);
2361 m_copydata(m0, 0, m0->m_pkthdr.len,
2362 data->buf + sizeof(struct zyd_tx_desc));
2364 DPRINTFN(10, ("%s: sending data frame len=%zu rate=%u xferlen=%u\n",
2365 device_get_nameunit(sc->sc_dev), (size_t)m0->m_pkthdr.len,
2368 m_freem(m0); /* mbuf no longer needed */
2370 usbd_setup_xfer(data->xfer, sc->zyd_ep[ZYD_ENDPT_BOUT], data,
2371 data->buf, xferlen, USBD_FORCE_SHORT_XFER | USBD_NO_COPY,
2372 ZYD_TX_TIMEOUT, zyd_txeof);
2373 error = usbd_transfer(data->xfer);
2374 if (error != USBD_IN_PROGRESS && error != 0) {
2384 zyd_start(struct ifnet *ifp)
2386 struct zyd_softc *sc = ifp->if_softc;
2387 struct ieee80211_node *ni;
2391 IFQ_DRV_DEQUEUE(&ifp->if_snd, m);
2394 if (sc->tx_queued >= ZYD_TX_LIST_CNT) {
2395 IFQ_DRV_PREPEND(&ifp->if_snd, m);
2396 ifp->if_drv_flags |= IFF_DRV_OACTIVE;
2399 ni = (struct ieee80211_node *)m->m_pkthdr.rcvif;
2400 m = ieee80211_encap(ni, m);
2402 ieee80211_free_node(ni);
2406 if (zyd_tx_data(sc, m, ni) != 0) {
2407 ieee80211_free_node(ni);
2413 callout_reset(&sc->sc_watchdog_ch, hz, zyd_watchdog, sc);
2418 zyd_raw_xmit(struct ieee80211_node *ni, struct mbuf *m,
2419 const struct ieee80211_bpf_params *params)
2421 struct ieee80211com *ic = ni->ni_ic;
2422 struct ifnet *ifp = ic->ic_ifp;
2423 struct zyd_softc *sc = ifp->if_softc;
2425 /* prevent management frames from being sent if we're not ready */
2426 if (!(ifp->if_drv_flags & IFF_DRV_RUNNING)) {
2428 ieee80211_free_node(ni);
2431 if (sc->tx_queued >= ZYD_TX_LIST_CNT) {
2432 ifp->if_drv_flags |= IFF_DRV_OACTIVE;
2434 ieee80211_free_node(ni);
2435 return ENOBUFS; /* XXX */
2441 * Legacy path; interpret frame contents to decide
2442 * precisely how to send the frame.
2445 if (zyd_tx_mgt(sc, m, ni) != 0)
2448 callout_reset(&sc->sc_watchdog_ch, hz, zyd_watchdog, sc);
2453 ieee80211_free_node(ni);
2454 return EIO; /* XXX */
2458 zyd_watchdog(void *arg)
2460 struct zyd_softc *sc = arg;
2461 struct ifnet *ifp = sc->sc_ifp;
2463 if (sc->tx_timer > 0) {
2464 if (--sc->tx_timer == 0) {
2465 device_printf(sc->sc_dev, "device timeout\n");
2466 /* zyd_init(ifp); XXX needs a process context ? */
2470 callout_reset(&sc->sc_watchdog_ch, hz, zyd_watchdog, sc);
2475 zyd_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
2477 struct zyd_softc *sc = ifp->if_softc;
2478 struct ieee80211com *ic = ifp->if_l2com;
2479 struct ifreq *ifr = (struct ifreq *) data;
2480 int error = 0, startall = 0;
2485 if (ifp->if_flags & IFF_UP) {
2486 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
2487 if ((ifp->if_flags ^ sc->sc_if_flags) &
2488 (IFF_ALLMULTI | IFF_PROMISC))
2491 zyd_init_locked(sc);
2495 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
2498 sc->sc_if_flags = ifp->if_flags;
2501 ieee80211_start_all(ic);
2504 error = ifmedia_ioctl(ifp, ifr, &ic->ic_media, cmd);
2507 error = ether_ioctl(ifp, cmd, data);
2517 zyd_init_locked(struct zyd_softc *sc)
2519 struct ifnet *ifp = sc->sc_ifp;
2520 struct ieee80211com *ic = ifp->if_l2com;
2525 IEEE80211_ADDR_COPY(ic->ic_myaddr, IF_LLADDR(ifp));
2526 DPRINTF(("setting MAC address to %s\n", ether_sprintf(ic->ic_myaddr)));
2527 error = zyd_set_macaddr(sc, ic->ic_myaddr);
2531 /* we'll do software WEP decryption for now */
2532 DPRINTF(("setting encryption type\n"));
2533 error = zyd_write32(sc, ZYD_MAC_ENCRYPTION_TYPE, ZYD_ENC_SNIFFER);
2537 /* promiscuous mode */
2538 (void)zyd_write32(sc, ZYD_MAC_SNIFFER, 0);
2540 /* multicast setup */
2541 (void)zyd_set_multi(sc);
2543 (void)zyd_set_rxfilter(sc);
2545 /* switch radio transmitter ON */
2546 (void)zyd_switch_radio(sc, 1);
2548 /* XXX wrong, can't set here */
2549 /* set basic rates */
2550 if (ic->ic_curmode == IEEE80211_MODE_11B)
2551 (void)zyd_write32(sc, ZYD_MAC_BAS_RATE, 0x0003);
2552 else if (ic->ic_curmode == IEEE80211_MODE_11A)
2553 (void)zyd_write32(sc, ZYD_MAC_BAS_RATE, 0x1500);
2554 else /* assumes 802.11b/g */
2555 (void)zyd_write32(sc, ZYD_MAC_BAS_RATE, 0x000f);
2557 /* set mandatory rates */
2558 if (ic->ic_curmode == IEEE80211_MODE_11B)
2559 (void)zyd_write32(sc, ZYD_MAC_MAN_RATE, 0x000f);
2560 else if (ic->ic_curmode == IEEE80211_MODE_11A)
2561 (void)zyd_write32(sc, ZYD_MAC_MAN_RATE, 0x1500);
2562 else /* assumes 802.11b/g */
2563 (void)zyd_write32(sc, ZYD_MAC_MAN_RATE, 0x150f);
2565 /* set default BSS channel */
2566 zyd_set_chan(sc, ic->ic_curchan);
2568 /* enable interrupts */
2569 (void)zyd_write32(sc, ZYD_CR_INTERRUPT, ZYD_HWINT_MASK);
2572 * Allocate Tx and Rx xfer queues.
2574 if ((error = zyd_alloc_tx_list(sc)) != 0) {
2575 device_printf(sc->sc_dev, "could not allocate Tx list\n");
2578 if ((error = zyd_alloc_rx_list(sc)) != 0) {
2579 device_printf(sc->sc_dev, "could not allocate Rx list\n");
2584 * Start up the receive pipe.
2586 for (i = 0; i < ZYD_RX_LIST_CNT; i++) {
2587 struct zyd_rx_data *data = &sc->rx_data[i];
2589 usbd_setup_xfer(data->xfer, sc->zyd_ep[ZYD_ENDPT_BIN], data,
2590 NULL, ZYX_MAX_RXBUFSZ, USBD_NO_COPY | USBD_SHORT_XFER_OK,
2591 USBD_NO_TIMEOUT, zyd_rxeof);
2592 error = usbd_transfer(data->xfer);
2593 if (error != USBD_IN_PROGRESS && error != 0) {
2594 device_printf(sc->sc_dev,
2595 "could not queue Rx transfer\n");
2600 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
2601 ifp->if_drv_flags |= IFF_DRV_RUNNING;
2604 fail: zyd_stop(sc, 1);
2609 zyd_init(void *priv)
2611 struct zyd_softc *sc = priv;
2612 struct ifnet *ifp = sc->sc_ifp;
2613 struct ieee80211com *ic = ifp->if_l2com;
2616 zyd_init_locked(sc);
2619 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
2620 ieee80211_start_all(ic); /* start all vap's */
2624 zyd_stop(struct zyd_softc *sc, int disable)
2626 struct ifnet *ifp = sc->sc_ifp;
2629 ifp->if_drv_flags &= ~(IFF_DRV_RUNNING | IFF_DRV_OACTIVE);
2631 /* switch radio transmitter OFF */
2632 (void)zyd_switch_radio(sc, 0);
2635 (void)zyd_write32(sc, ZYD_MAC_RXFILTER, 0);
2637 /* disable interrupts */
2638 (void)zyd_write32(sc, ZYD_CR_INTERRUPT, 0);
2640 usbd_abort_pipe(sc->zyd_ep[ZYD_ENDPT_BIN]);
2641 usbd_abort_pipe(sc->zyd_ep[ZYD_ENDPT_BOUT]);
2643 zyd_free_rx_list(sc);
2644 zyd_free_tx_list(sc);
2648 zyd_loadfirmware(struct zyd_softc *sc, u_char *fw, size_t size)
2650 usb_device_request_t req;
2654 DPRINTF(("firmware size=%zu\n", size));
2656 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
2657 req.bRequest = ZYD_DOWNLOADREQ;
2658 USETW(req.wIndex, 0);
2660 addr = ZYD_FIRMWARE_START_ADDR;
2663 const int mlen = min(size, 4096);
2666 * XXXX: When the transfer size is 4096 bytes, it is not
2667 * likely to be able to transfer it.
2668 * The cause is port or machine or chip?
2670 const int mlen = min(size, 64);
2673 DPRINTF(("loading firmware block: len=%d, addr=0x%x\n", mlen,
2676 USETW(req.wValue, addr);
2677 USETW(req.wLength, mlen);
2678 if (usbd_do_request(sc->sc_udev, &req, fw) != 0)
2686 /* check whether the upload succeeded */
2687 req.bmRequestType = UT_READ_VENDOR_DEVICE;
2688 req.bRequest = ZYD_DOWNLOADSTS;
2689 USETW(req.wValue, 0);
2690 USETW(req.wIndex, 0);
2691 USETW(req.wLength, sizeof(stat));
2692 if (usbd_do_request(sc->sc_udev, &req, &stat) != 0)
2695 return (stat & 0x80) ? EIO : 0;
2699 zyd_newassoc(struct ieee80211_node *ni, int isnew)
2701 struct ieee80211vap *vap = ni->ni_vap;
2703 ieee80211_amrr_node_init(&ZYD_VAP(vap)->amrr, &ZYD_NODE(ni)->amn, ni);
2707 zyd_scan_start(struct ieee80211com *ic)
2709 struct zyd_softc *sc = ic->ic_ifp->if_softc;
2711 usb_rem_task(sc->sc_udev, &sc->sc_scantask);
2713 /* do it in a process context */
2714 sc->sc_scan_action = ZYD_SCAN_START;
2715 usb_add_task(sc->sc_udev, &sc->sc_scantask, USB_TASKQ_DRIVER);
2719 zyd_scan_end(struct ieee80211com *ic)
2721 struct zyd_softc *sc = ic->ic_ifp->if_softc;
2723 usb_rem_task(sc->sc_udev, &sc->sc_scantask);
2725 /* do it in a process context */
2726 sc->sc_scan_action = ZYD_SCAN_END;
2727 usb_add_task(sc->sc_udev, &sc->sc_scantask, USB_TASKQ_DRIVER);
2731 zyd_set_channel(struct ieee80211com *ic)
2733 struct zyd_softc *sc = ic->ic_ifp->if_softc;
2735 usb_rem_task(sc->sc_udev, &sc->sc_scantask);
2737 /* do it in a process context */
2738 sc->sc_scan_action = ZYD_SET_CHANNEL;
2739 usb_add_task(sc->sc_udev, &sc->sc_scantask, USB_TASKQ_DRIVER);
2743 zyd_scantask(void *arg)
2745 struct zyd_softc *sc = arg;
2746 struct ifnet *ifp = sc->sc_ifp;
2747 struct ieee80211com *ic = ifp->if_l2com;
2749 if (sc->sc_flags & ZYD_FLAG_DETACHING)
2754 switch (sc->sc_scan_action) {
2755 case ZYD_SCAN_START:
2756 /* want broadcast address while scanning */
2757 zyd_set_bssid(sc, ifp->if_broadcastaddr);
2761 /* restore previous bssid */
2762 zyd_set_bssid(sc, sc->sc_bssid);
2765 case ZYD_SET_CHANNEL:
2767 zyd_set_chan(sc, ic->ic_curchan);
2772 device_printf(sc->sc_dev, "unknown scan action %d\n",
2773 sc->sc_scan_action);
2780 static device_method_t zyd_methods[] = {
2781 /* Device interface */
2782 DEVMETHOD(device_probe, zyd_match),
2783 DEVMETHOD(device_attach, zyd_attach),
2784 DEVMETHOD(device_detach, zyd_detach),
2789 static driver_t zyd_driver = {
2792 sizeof(struct zyd_softc)
2795 static devclass_t zyd_devclass;
2797 DRIVER_MODULE(zyd, uhub, zyd_driver, zyd_devclass, usbd_driver_load, 0);
2798 MODULE_DEPEND(zyd, wlan, 1, 1, 1);
2799 MODULE_DEPEND(zyd, wlan_amrr, 1, 1, 1);
2800 MODULE_DEPEND(zyd, usb, 1, 1, 1);