FreeBSD kernel usb device Code
if_zyd.c
Go to the documentation of this file.
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 $ */
3/* $FreeBSD$ */
4
5/*-
6 * Copyright (c) 2006 by Damien Bergamini <damien.bergamini@free.fr>
7 * Copyright (c) 2006 by Florian Stoehr <ich@florian-stoehr.de>
8 *
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.
12 *
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.
20 */
21
22#include <sys/cdefs.h>
23__FBSDID("$FreeBSD$");
24
25/*
26 * ZyDAS ZD1211/ZD1211B USB WLAN driver.
27 */
28
29#include "opt_wlan.h"
30
31#include <sys/param.h>
32#include <sys/sockio.h>
33#include <sys/sysctl.h>
34#include <sys/lock.h>
35#include <sys/mutex.h>
36#include <sys/condvar.h>
37#include <sys/mbuf.h>
38#include <sys/kernel.h>
39#include <sys/socket.h>
40#include <sys/systm.h>
41#include <sys/malloc.h>
42#include <sys/module.h>
43#include <sys/bus.h>
44#include <sys/endian.h>
45#include <sys/kdb.h>
46
47#include <net/bpf.h>
48#include <net/if.h>
49#include <net/if_var.h>
50#include <net/if_arp.h>
51#include <net/ethernet.h>
52#include <net/if_dl.h>
53#include <net/if_media.h>
54#include <net/if_types.h>
55
56#ifdef INET
57#include <netinet/in.h>
58#include <netinet/in_systm.h>
59#include <netinet/in_var.h>
60#include <netinet/if_ether.h>
61#include <netinet/ip.h>
62#endif
63
64#include <net80211/ieee80211_var.h>
65#include <net80211/ieee80211_regdomain.h>
66#include <net80211/ieee80211_radiotap.h>
67#include <net80211/ieee80211_ratectl.h>
68
69#include <dev/usb/usb.h>
70#include <dev/usb/usbdi.h>
71#include <dev/usb/usbdi_util.h>
72#include "usbdevs.h"
73
76
77#ifdef USB_DEBUG
78static int zyd_debug = 0;
79
80static SYSCTL_NODE(_hw_usb, OID_AUTO, zyd, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
81 "USB zyd");
82SYSCTL_INT(_hw_usb_zyd, OID_AUTO, debug, CTLFLAG_RWTUN, &zyd_debug, 0,
83 "zyd debug level");
84
85enum {
86 ZYD_DEBUG_XMIT = 0x00000001, /* basic xmit operation */
87 ZYD_DEBUG_RECV = 0x00000002, /* basic recv operation */
88 ZYD_DEBUG_RESET = 0x00000004, /* reset processing */
89 ZYD_DEBUG_INIT = 0x00000008, /* device init */
90 ZYD_DEBUG_TX_PROC = 0x00000010, /* tx ISR proc */
91 ZYD_DEBUG_RX_PROC = 0x00000020, /* rx ISR proc */
92 ZYD_DEBUG_STATE = 0x00000040, /* 802.11 state transitions */
93 ZYD_DEBUG_STAT = 0x00000080, /* statistic */
94 ZYD_DEBUG_FW = 0x00000100, /* firmware */
95 ZYD_DEBUG_CMD = 0x00000200, /* fw commands */
96 ZYD_DEBUG_ANY = 0xffffffff
97};
98#define DPRINTF(sc, m, fmt, ...) do { \
99 if (zyd_debug & (m)) \
100 printf("%s: " fmt, __func__, ## __VA_ARGS__); \
101} while (0)
102#else
103#define DPRINTF(sc, m, fmt, ...) do { \
104 (void) sc; \
105} while (0)
106#endif
107
108#define zyd_do_request(sc,req,data) \
109 usbd_do_request_flags((sc)->sc_udev, &(sc)->sc_mtx, req, data, 0, NULL, 5000)
110
111static device_probe_t zyd_match;
112static device_attach_t zyd_attach;
113static device_detach_t zyd_detach;
114
119
120static struct ieee80211vap *zyd_vap_create(struct ieee80211com *,
121 const char [IFNAMSIZ], int, enum ieee80211_opmode, int,
122 const uint8_t [IEEE80211_ADDR_LEN],
123 const uint8_t [IEEE80211_ADDR_LEN]);
124static void zyd_vap_delete(struct ieee80211vap *);
125static void zyd_tx_free(struct zyd_tx_data *, int);
126static void zyd_setup_tx_list(struct zyd_softc *);
127static void zyd_unsetup_tx_list(struct zyd_softc *);
128static int zyd_newstate(struct ieee80211vap *, enum ieee80211_state, int);
129static int zyd_cmd(struct zyd_softc *, uint16_t, const void *, int,
130 void *, int, int);
131static int zyd_read16(struct zyd_softc *, uint16_t, uint16_t *);
132static int zyd_read32(struct zyd_softc *, uint16_t, uint32_t *);
133static int zyd_write16(struct zyd_softc *, uint16_t, uint16_t);
134static int zyd_write32(struct zyd_softc *, uint16_t, uint32_t);
135static int zyd_rfwrite(struct zyd_softc *, uint32_t);
136static int zyd_lock_phy(struct zyd_softc *);
137static int zyd_unlock_phy(struct zyd_softc *);
138static int zyd_rf_attach(struct zyd_softc *, uint8_t);
139static const char *zyd_rf_name(uint8_t);
140static int zyd_hw_init(struct zyd_softc *);
141static int zyd_read_pod(struct zyd_softc *);
142static int zyd_read_eeprom(struct zyd_softc *);
143static int zyd_get_macaddr(struct zyd_softc *);
144static int zyd_set_macaddr(struct zyd_softc *, const uint8_t *);
145static int zyd_set_bssid(struct zyd_softc *, const uint8_t *);
146static int zyd_switch_radio(struct zyd_softc *, int);
147static int zyd_set_led(struct zyd_softc *, int, int);
148static void zyd_set_multi(struct zyd_softc *);
149static void zyd_update_mcast(struct ieee80211com *);
150static int zyd_set_rxfilter(struct zyd_softc *);
151static void zyd_set_chan(struct zyd_softc *, struct ieee80211_channel *);
152static int zyd_set_beacon_interval(struct zyd_softc *, int);
153static void zyd_rx_data(struct usb_xfer *, int, uint16_t);
154static int zyd_tx_start(struct zyd_softc *, struct mbuf *,
155 struct ieee80211_node *);
156static int zyd_transmit(struct ieee80211com *, struct mbuf *);
157static void zyd_start(struct zyd_softc *);
158static int zyd_raw_xmit(struct ieee80211_node *, struct mbuf *,
159 const struct ieee80211_bpf_params *);
160static void zyd_parent(struct ieee80211com *);
161static void zyd_init_locked(struct zyd_softc *);
162static void zyd_stop(struct zyd_softc *);
163static int zyd_loadfirmware(struct zyd_softc *);
164static void zyd_scan_start(struct ieee80211com *);
165static void zyd_scan_end(struct ieee80211com *);
166static void zyd_getradiocaps(struct ieee80211com *, int, int *,
167 struct ieee80211_channel[]);
168static void zyd_set_channel(struct ieee80211com *);
169static int zyd_rfmd_init(struct zyd_rf *);
170static int zyd_rfmd_switch_radio(struct zyd_rf *, int);
171static int zyd_rfmd_set_channel(struct zyd_rf *, uint8_t);
172static int zyd_al2230_init(struct zyd_rf *);
173static int zyd_al2230_switch_radio(struct zyd_rf *, int);
174static int zyd_al2230_set_channel(struct zyd_rf *, uint8_t);
175static int zyd_al2230_set_channel_b(struct zyd_rf *, uint8_t);
176static int zyd_al2230_init_b(struct zyd_rf *);
177static int zyd_al7230B_init(struct zyd_rf *);
178static int zyd_al7230B_switch_radio(struct zyd_rf *, int);
179static int zyd_al7230B_set_channel(struct zyd_rf *, uint8_t);
180static int zyd_al2210_init(struct zyd_rf *);
181static int zyd_al2210_switch_radio(struct zyd_rf *, int);
182static int zyd_al2210_set_channel(struct zyd_rf *, uint8_t);
183static int zyd_gct_init(struct zyd_rf *);
184static int zyd_gct_switch_radio(struct zyd_rf *, int);
185static int zyd_gct_set_channel(struct zyd_rf *, uint8_t);
186static int zyd_gct_mode(struct zyd_rf *);
187static int zyd_gct_set_channel_synth(struct zyd_rf *, int, int);
188static int zyd_gct_write(struct zyd_rf *, uint16_t);
189static int zyd_gct_txgain(struct zyd_rf *, uint8_t);
190static int zyd_maxim2_init(struct zyd_rf *);
191static int zyd_maxim2_switch_radio(struct zyd_rf *, int);
192static int zyd_maxim2_set_channel(struct zyd_rf *, uint8_t);
193
194static const struct zyd_phy_pair zyd_def_phy[] = ZYD_DEF_PHY;
195static const struct zyd_phy_pair zyd_def_phyB[] = ZYD_DEF_PHYB;
196
197/* various supported device vendors/products */
198#define ZYD_ZD1211 0
199#define ZYD_ZD1211B 1
200
201#define ZYD_ZD1211_DEV(v,p) \
202 { USB_VPI(USB_VENDOR_##v, USB_PRODUCT_##v##_##p, ZYD_ZD1211) }
203#define ZYD_ZD1211B_DEV(v,p) \
204 { USB_VPI(USB_VENDOR_##v, USB_PRODUCT_##v##_##p, ZYD_ZD1211B) }
205static const STRUCT_USB_HOST_ID zyd_devs[] = {
206 /* ZYD_ZD1211 */
207 ZYD_ZD1211_DEV(3COM2, 3CRUSB10075),
208 ZYD_ZD1211_DEV(ABOCOM, WL54),
209 ZYD_ZD1211_DEV(ASUS, WL159G),
210 ZYD_ZD1211_DEV(CYBERTAN, TG54USB),
211 ZYD_ZD1211_DEV(DRAYTEK, VIGOR550),
212 ZYD_ZD1211_DEV(PLANEX2, GWUS54GD),
213 ZYD_ZD1211_DEV(PLANEX2, GWUS54GZL),
214 ZYD_ZD1211_DEV(PLANEX3, GWUS54GZ),
215 ZYD_ZD1211_DEV(PLANEX3, GWUS54MINI),
216 ZYD_ZD1211_DEV(SAGEM, XG760A),
217 ZYD_ZD1211_DEV(SENAO, NUB8301),
218 ZYD_ZD1211_DEV(SITECOMEU, WL113),
219 ZYD_ZD1211_DEV(SWEEX, ZD1211),
220 ZYD_ZD1211_DEV(TEKRAM, QUICKWLAN),
221 ZYD_ZD1211_DEV(TEKRAM, ZD1211_1),
222 ZYD_ZD1211_DEV(TEKRAM, ZD1211_2),
223 ZYD_ZD1211_DEV(TWINMOS, G240),
224 ZYD_ZD1211_DEV(UMEDIA, ALL0298V2),
225 ZYD_ZD1211_DEV(UMEDIA, TEW429UB_A),
226 ZYD_ZD1211_DEV(UMEDIA, TEW429UB),
227 ZYD_ZD1211_DEV(WISTRONNEWEB, UR055G),
228 ZYD_ZD1211_DEV(ZCOM, ZD1211),
229 ZYD_ZD1211_DEV(ZYDAS, ZD1211),
230 ZYD_ZD1211_DEV(ZYXEL, AG225H),
231 ZYD_ZD1211_DEV(ZYXEL, ZYAIRG220),
232 ZYD_ZD1211_DEV(ZYXEL, G200V2),
233 /* ZYD_ZD1211B */
234 ZYD_ZD1211B_DEV(ACCTON, SMCWUSBG_NF),
235 ZYD_ZD1211B_DEV(ACCTON, SMCWUSBG),
236 ZYD_ZD1211B_DEV(ACCTON, ZD1211B),
237 ZYD_ZD1211B_DEV(ASUS, A9T_WIFI),
238 ZYD_ZD1211B_DEV(BELKIN, F5D7050_V4000),
239 ZYD_ZD1211B_DEV(BELKIN, ZD1211B),
240 ZYD_ZD1211B_DEV(CISCOLINKSYS, WUSBF54G),
241 ZYD_ZD1211B_DEV(FIBERLINE, WL430U),
242 ZYD_ZD1211B_DEV(MELCO, KG54L),
243 ZYD_ZD1211B_DEV(PHILIPS, SNU5600),
244 ZYD_ZD1211B_DEV(PLANEX2, GW_US54GXS),
245 ZYD_ZD1211B_DEV(SAGEM, XG76NA),
246 ZYD_ZD1211B_DEV(SITECOMEU, ZD1211B),
247 ZYD_ZD1211B_DEV(UMEDIA, TEW429UBC1),
248 ZYD_ZD1211B_DEV(USR, USR5423),
249 ZYD_ZD1211B_DEV(VTECH, ZD1211B),
250 ZYD_ZD1211B_DEV(ZCOM, ZD1211B),
251 ZYD_ZD1211B_DEV(ZYDAS, ZD1211B),
252 ZYD_ZD1211B_DEV(ZYXEL, M202),
253 ZYD_ZD1211B_DEV(ZYXEL, G202),
254 ZYD_ZD1211B_DEV(ZYXEL, G220V2)
255};
256
257static const struct usb_config zyd_config[ZYD_N_TRANSFER] = {
258 [ZYD_BULK_WR] = {
259 .type = UE_BULK,
260 .endpoint = UE_ADDR_ANY,
261 .direction = UE_DIR_OUT,
262 .bufsize = ZYD_MAX_TXBUFSZ,
263 .flags = {.pipe_bof = 1,.force_short_xfer = 1,},
264 .callback = zyd_bulk_write_callback,
265 .ep_index = 0,
266 .timeout = 10000, /* 10 seconds */
267 },
268 [ZYD_BULK_RD] = {
269 .type = UE_BULK,
270 .endpoint = UE_ADDR_ANY,
271 .direction = UE_DIR_IN,
272 .bufsize = ZYX_MAX_RXBUFSZ,
273 .flags = {.pipe_bof = 1,.short_xfer_ok = 1,},
274 .callback = zyd_bulk_read_callback,
275 .ep_index = 0,
276 },
277 [ZYD_INTR_WR] = {
278 .type = UE_BULK_INTR,
279 .endpoint = UE_ADDR_ANY,
280 .direction = UE_DIR_OUT,
281 .bufsize = sizeof(struct zyd_cmd),
282 .flags = {.pipe_bof = 1,.force_short_xfer = 1,},
283 .callback = zyd_intr_write_callback,
284 .timeout = 1000, /* 1 second */
285 .ep_index = 1,
286 },
287 [ZYD_INTR_RD] = {
288 .type = UE_INTERRUPT,
289 .endpoint = UE_ADDR_ANY,
290 .direction = UE_DIR_IN,
291 .bufsize = sizeof(struct zyd_cmd),
292 .flags = {.pipe_bof = 1,.short_xfer_ok = 1,},
293 .callback = zyd_intr_read_callback,
294 },
295};
296#define zyd_read16_m(sc, val, data) do { \
297 error = zyd_read16(sc, val, data); \
298 if (error != 0) \
299 goto fail; \
300} while (0)
301#define zyd_write16_m(sc, val, data) do { \
302 error = zyd_write16(sc, val, data); \
303 if (error != 0) \
304 goto fail; \
305} while (0)
306#define zyd_read32_m(sc, val, data) do { \
307 error = zyd_read32(sc, val, data); \
308 if (error != 0) \
309 goto fail; \
310} while (0)
311#define zyd_write32_m(sc, val, data) do { \
312 error = zyd_write32(sc, val, data); \
313 if (error != 0) \
314 goto fail; \
315} while (0)
316
317static int
318zyd_match(device_t dev)
319{
320 struct usb_attach_arg *uaa = device_get_ivars(dev);
321
322 if (uaa->usb_mode != USB_MODE_HOST)
323 return (ENXIO);
325 return (ENXIO);
326 if (uaa->info.bIfaceIndex != ZYD_IFACE_INDEX)
327 return (ENXIO);
328
329 return (usbd_lookup_id_by_uaa(zyd_devs, sizeof(zyd_devs), uaa));
330}
331
332static int
333zyd_attach(device_t dev)
334{
335 struct usb_attach_arg *uaa = device_get_ivars(dev);
336 struct zyd_softc *sc = device_get_softc(dev);
337 struct ieee80211com *ic = &sc->sc_ic;
338 uint8_t iface_index;
339 int error;
340
341 if (uaa->info.bcdDevice < 0x4330) {
342 device_printf(dev, "device version mismatch: 0x%X "
343 "(only >= 43.30 supported)\n",
344 uaa->info.bcdDevice);
345 return (EINVAL);
346 }
347
349 sc->sc_dev = dev;
350 sc->sc_udev = uaa->device;
352
353 mtx_init(&sc->sc_mtx, device_get_nameunit(sc->sc_dev),
354 MTX_NETWORK_LOCK, MTX_DEF);
355 STAILQ_INIT(&sc->sc_rqh);
356 mbufq_init(&sc->sc_snd, ifqmaxlen);
357
358 iface_index = ZYD_IFACE_INDEX;
360 &iface_index, sc->sc_xfer, zyd_config,
361 ZYD_N_TRANSFER, sc, &sc->sc_mtx);
362 if (error) {
363 device_printf(dev, "could not allocate USB transfers, "
364 "err=%s\n", usbd_errstr(error));
365 goto detach;
366 }
367
368 ZYD_LOCK(sc);
369 if ((error = zyd_get_macaddr(sc)) != 0) {
370 device_printf(sc->sc_dev, "could not read EEPROM\n");
371 ZYD_UNLOCK(sc);
372 goto detach;
373 }
374 ZYD_UNLOCK(sc);
375
376 ic->ic_softc = sc;
377 ic->ic_name = device_get_nameunit(dev);
378 ic->ic_phytype = IEEE80211_T_OFDM; /* not only, but not used */
379 ic->ic_opmode = IEEE80211_M_STA;
380
381 /* set device capabilities */
382 ic->ic_caps =
383 IEEE80211_C_STA /* station mode */
384 | IEEE80211_C_MONITOR /* monitor mode */
385 | IEEE80211_C_SHPREAMBLE /* short preamble supported */
386 | IEEE80211_C_SHSLOT /* short slot time supported */
387 | IEEE80211_C_BGSCAN /* capable of bg scanning */
388 | IEEE80211_C_WPA /* 802.11i */
389 ;
390
391 zyd_getradiocaps(ic, IEEE80211_CHAN_MAX, &ic->ic_nchans,
392 ic->ic_channels);
393
394 ieee80211_ifattach(ic);
395 ic->ic_raw_xmit = zyd_raw_xmit;
396 ic->ic_scan_start = zyd_scan_start;
397 ic->ic_scan_end = zyd_scan_end;
398 ic->ic_getradiocaps = zyd_getradiocaps;
399 ic->ic_set_channel = zyd_set_channel;
400 ic->ic_vap_create = zyd_vap_create;
401 ic->ic_vap_delete = zyd_vap_delete;
402 ic->ic_update_mcast = zyd_update_mcast;
403 ic->ic_update_promisc = zyd_update_mcast;
404 ic->ic_parent = zyd_parent;
405 ic->ic_transmit = zyd_transmit;
406
407 ieee80211_radiotap_attach(ic,
408 &sc->sc_txtap.wt_ihdr, sizeof(sc->sc_txtap),
410 &sc->sc_rxtap.wr_ihdr, sizeof(sc->sc_rxtap),
412
413 if (bootverbose)
414 ieee80211_announce(ic);
415
416 return (0);
417
418detach:
420 return (ENXIO); /* failure */
421}
422
423static void
425{
426 struct mbuf *m;
427 struct ieee80211_node *ni;
428
429 ZYD_LOCK_ASSERT(sc, MA_OWNED);
430 while ((m = mbufq_dequeue(&sc->sc_snd)) != NULL) {
431 ni = (struct ieee80211_node *)m->m_pkthdr.rcvif;
432 m->m_pkthdr.rcvif = NULL;
433 ieee80211_free_node(ni);
434 m_freem(m);
435 }
436}
437
438static int
439zyd_detach(device_t dev)
440{
441 struct zyd_softc *sc = device_get_softc(dev);
442 struct ieee80211com *ic = &sc->sc_ic;
443 unsigned int x;
444
445 /*
446 * Prevent further allocations from RX/TX data
447 * lists and ioctls:
448 */
449 ZYD_LOCK(sc);
451 zyd_drain_mbufq(sc);
452 STAILQ_INIT(&sc->tx_q);
453 STAILQ_INIT(&sc->tx_free);
454 ZYD_UNLOCK(sc);
455
456 /* drain USB transfers */
457 for (x = 0; x != ZYD_N_TRANSFER; x++)
459
460 /* free TX list, if any */
461 ZYD_LOCK(sc);
463 ZYD_UNLOCK(sc);
464
465 /* free USB transfers and some data buffers */
467
468 if (ic->ic_softc == sc)
469 ieee80211_ifdetach(ic);
470 mtx_destroy(&sc->sc_mtx);
471
472 return (0);
473}
474
475static struct ieee80211vap *
476zyd_vap_create(struct ieee80211com *ic, const char name[IFNAMSIZ], int unit,
477 enum ieee80211_opmode opmode, int flags,
478 const uint8_t bssid[IEEE80211_ADDR_LEN],
479 const uint8_t mac[IEEE80211_ADDR_LEN])
480{
481 struct zyd_vap *zvp;
482 struct ieee80211vap *vap;
483
484 if (!TAILQ_EMPTY(&ic->ic_vaps)) /* only one at a time */
485 return (NULL);
486 zvp = malloc(sizeof(struct zyd_vap), M_80211_VAP, M_WAITOK | M_ZERO);
487 vap = &zvp->vap;
488
489 /* enable s/w bmiss handling for sta mode */
490 if (ieee80211_vap_setup(ic, vap, name, unit, opmode,
491 flags | IEEE80211_CLONE_NOBEACONS, bssid) != 0) {
492 /* out of memory */
493 free(zvp, M_80211_VAP);
494 return (NULL);
495 }
496
497 /* override state transition machine */
498 zvp->newstate = vap->iv_newstate;
499 vap->iv_newstate = zyd_newstate;
500
501 ieee80211_ratectl_init(vap);
502 ieee80211_ratectl_setinterval(vap, 1000 /* 1 sec */);
503
504 /* complete setup */
505 ieee80211_vap_attach(vap, ieee80211_media_change,
506 ieee80211_media_status, mac);
507 ic->ic_opmode = opmode;
508 return (vap);
509}
510
511static void
512zyd_vap_delete(struct ieee80211vap *vap)
513{
514 struct zyd_vap *zvp = ZYD_VAP(vap);
515
516 ieee80211_ratectl_deinit(vap);
517 ieee80211_vap_detach(vap);
518 free(zvp, M_80211_VAP);
519}
520
521static void
522zyd_tx_free(struct zyd_tx_data *data, int txerr)
523{
524 struct zyd_softc *sc = data->sc;
525
526 if (data->m != NULL) {
527 ieee80211_tx_complete(data->ni, data->m, txerr);
528 data->m = NULL;
529 data->ni = NULL;
530 }
531 STAILQ_INSERT_TAIL(&sc->tx_free, data, next);
532 sc->tx_nfree++;
533}
534
535static void
537{
538 struct zyd_tx_data *data;
539 int i;
540
541 sc->tx_nfree = 0;
542 STAILQ_INIT(&sc->tx_q);
543 STAILQ_INIT(&sc->tx_free);
544
545 for (i = 0; i < ZYD_TX_LIST_CNT; i++) {
546 data = &sc->tx_data[i];
547
548 data->sc = sc;
549 STAILQ_INSERT_TAIL(&sc->tx_free, data, next);
550 sc->tx_nfree++;
551 }
552}
553
554static void
556{
557 struct zyd_tx_data *data;
558 int i;
559
560 /* make sure any subsequent use of the queues will fail */
561 sc->tx_nfree = 0;
562 STAILQ_INIT(&sc->tx_q);
563 STAILQ_INIT(&sc->tx_free);
564
565 /* free up all node references and mbufs */
566 for (i = 0; i < ZYD_TX_LIST_CNT; i++) {
567 data = &sc->tx_data[i];
568
569 if (data->m != NULL) {
570 m_freem(data->m);
571 data->m = NULL;
572 }
573 if (data->ni != NULL) {
574 ieee80211_free_node(data->ni);
575 data->ni = NULL;
576 }
577 }
578}
579
580static int
581zyd_newstate(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg)
582{
583 struct zyd_vap *zvp = ZYD_VAP(vap);
584 struct ieee80211com *ic = vap->iv_ic;
585 struct zyd_softc *sc = ic->ic_softc;
586 int error;
587
588 DPRINTF(sc, ZYD_DEBUG_STATE, "%s: %s -> %s\n", __func__,
589 ieee80211_state_name[vap->iv_state],
590 ieee80211_state_name[nstate]);
591
592 IEEE80211_UNLOCK(ic);
593 ZYD_LOCK(sc);
594 switch (nstate) {
595 case IEEE80211_S_AUTH:
596 zyd_set_chan(sc, ic->ic_curchan);
597 break;
598 case IEEE80211_S_RUN:
599 if (vap->iv_opmode == IEEE80211_M_MONITOR)
600 break;
601
602 /* turn link LED on */
603 error = zyd_set_led(sc, ZYD_LED1, 1);
604 if (error != 0)
605 break;
606
607 /* make data LED blink upon Tx */
609
610 IEEE80211_ADDR_COPY(sc->sc_bssid, vap->iv_bss->ni_bssid);
611 zyd_set_bssid(sc, sc->sc_bssid);
612 break;
613 default:
614 break;
615 }
616fail:
617 ZYD_UNLOCK(sc);
618 IEEE80211_LOCK(ic);
619 return (zvp->newstate(vap, nstate, arg));
620}
621
622/*
623 * Callback handler for interrupt transfer
624 */
625static void
627{
628 struct zyd_softc *sc = usbd_xfer_softc(xfer);
629 struct ieee80211com *ic = &sc->sc_ic;
630 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps);
631 struct ieee80211_node *ni;
632 struct zyd_cmd *cmd = &sc->sc_ibuf;
633 struct usb_page_cache *pc;
634 int datalen;
635 int actlen;
636
637 usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL);
638
639 switch (USB_GET_STATE(xfer)) {
641 pc = usbd_xfer_get_frame(xfer, 0);
642 usbd_copy_out(pc, 0, cmd, sizeof(*cmd));
643
644 switch (le16toh(cmd->code)) {
646 {
647 struct zyd_notif_retry *retry =
648 (struct zyd_notif_retry *)cmd->data;
649 uint16_t count = le16toh(retry->count);
650
651 DPRINTF(sc, ZYD_DEBUG_TX_PROC,
652 "retry intr: rate=0x%x addr=%s count=%d (0x%x)\n",
653 le16toh(retry->rate), ether_sprintf(retry->macaddr),
654 count & 0xff, count);
655
656 /*
657 * Find the node to which the packet was sent and
658 * update its retry statistics. In BSS mode, this node
659 * is the AP we're associated to so no lookup is
660 * actually needed.
661 */
662 ni = ieee80211_find_txnode(vap, retry->macaddr);
663 if (ni != NULL) {
664 struct ieee80211_ratectl_tx_status *txs =
665 &sc->sc_txs;
666 int retrycnt = count & 0xff;
667
668 txs->flags =
669 IEEE80211_RATECTL_STATUS_LONG_RETRY;
670 txs->long_retries = retrycnt;
671 if (count & 0x100) {
672 txs->status =
673 IEEE80211_RATECTL_TX_FAIL_LONG;
674 } else {
675 txs->status =
676 IEEE80211_RATECTL_TX_SUCCESS;
677 }
678
679 ieee80211_ratectl_tx_complete(ni, txs);
680 ieee80211_free_node(ni);
681 }
682 if (count & 0x100)
683 /* too many retries */
684 if_inc_counter(vap->iv_ifp, IFCOUNTER_OERRORS,
685 1);
686 break;
687 }
688 case ZYD_NOTIF_IORD:
689 {
690 struct zyd_rq *rqp;
691
692 if (le16toh(*(uint16_t *)cmd->data) == ZYD_CR_INTERRUPT)
693 break; /* HMAC interrupt */
694
695 datalen = actlen - sizeof(cmd->code);
696 datalen -= 2; /* XXX: padding? */
697
698 STAILQ_FOREACH(rqp, &sc->sc_rqh, rq) {
699 int i;
700 int count;
701
702 if (rqp->olen != datalen)
703 continue;
704 count = rqp->olen / sizeof(struct zyd_pair);
705 for (i = 0; i < count; i++) {
706 if (*(((const uint16_t *)rqp->idata) + i) !=
707 (((struct zyd_pair *)cmd->data) + i)->reg)
708 break;
709 }
710 if (i != count)
711 continue;
712 /* copy answer into caller-supplied buffer */
713 memcpy(rqp->odata, cmd->data, rqp->olen);
714 DPRINTF(sc, ZYD_DEBUG_CMD,
715 "command %p complete, data = %*D \n",
716 rqp, rqp->olen, (char *)rqp->odata, ":");
717 wakeup(rqp); /* wakeup caller */
718 break;
719 }
720 if (rqp == NULL) {
721 device_printf(sc->sc_dev,
722 "unexpected IORD notification %*D\n",
723 datalen, cmd->data, ":");
724 }
725 break;
726 }
727 default:
728 device_printf(sc->sc_dev, "unknown notification %x\n",
729 le16toh(cmd->code));
730 }
731
732 /* FALLTHROUGH */
733 case USB_ST_SETUP:
734tr_setup:
737 break;
738
739 default: /* Error */
740 DPRINTF(sc, ZYD_DEBUG_CMD, "error = %s\n",
742
743 if (error != USB_ERR_CANCELLED) {
744 /* try to clear stall first */
746 goto tr_setup;
747 }
748 break;
749 }
750}
751
752static void
754{
755 struct zyd_softc *sc = usbd_xfer_softc(xfer);
756 struct zyd_rq *rqp, *cmd;
757 struct usb_page_cache *pc;
758
759 switch (USB_GET_STATE(xfer)) {
761 cmd = usbd_xfer_get_priv(xfer);
762 DPRINTF(sc, ZYD_DEBUG_CMD, "command %p transferred\n", cmd);
763 STAILQ_FOREACH(rqp, &sc->sc_rqh, rq) {
764 /* Ensure the cached rq pointer is still valid */
765 if (rqp == cmd &&
766 (rqp->flags & ZYD_CMD_FLAG_READ) == 0)
767 wakeup(rqp); /* wakeup caller */
768 }
769
770 /* FALLTHROUGH */
771 case USB_ST_SETUP:
772tr_setup:
773 STAILQ_FOREACH(rqp, &sc->sc_rqh, rq) {
774 if (rqp->flags & ZYD_CMD_FLAG_SENT)
775 continue;
776
777 pc = usbd_xfer_get_frame(xfer, 0);
778 usbd_copy_in(pc, 0, rqp->cmd, rqp->ilen);
779
780 usbd_xfer_set_frame_len(xfer, 0, rqp->ilen);
781 usbd_xfer_set_priv(xfer, rqp);
782 rqp->flags |= ZYD_CMD_FLAG_SENT;
784 break;
785 }
786 break;
787
788 default: /* Error */
789 DPRINTF(sc, ZYD_DEBUG_ANY, "error = %s\n",
791
792 if (error != USB_ERR_CANCELLED) {
793 /* try to clear stall first */
795 goto tr_setup;
796 }
797 break;
798 }
799}
800
801static int
802zyd_cmd(struct zyd_softc *sc, uint16_t code, const void *idata, int ilen,
803 void *odata, int olen, int flags)
804{
805 struct zyd_cmd cmd;
806 struct zyd_rq rq;
807 int error;
808
809 if (ilen > (int)sizeof(cmd.data))
810 return (EINVAL);
811
812 cmd.code = htole16(code);
813 memcpy(cmd.data, idata, ilen);
814 DPRINTF(sc, ZYD_DEBUG_CMD, "sending cmd %p = %*D\n",
815 &rq, ilen, idata, ":");
816
817 rq.cmd = &cmd;
818 rq.idata = idata;
819 rq.odata = odata;
820 rq.ilen = sizeof(uint16_t) + ilen;
821 rq.olen = olen;
822 rq.flags = flags;
823 STAILQ_INSERT_TAIL(&sc->sc_rqh, &rq, rq);
826
827 /* wait at most one second for command reply */
828 error = mtx_sleep(&rq, &sc->sc_mtx, 0 , "zydcmd", hz);
829 if (error)
830 device_printf(sc->sc_dev, "command timeout\n");
831 STAILQ_REMOVE(&sc->sc_rqh, &rq, zyd_rq, rq);
832 DPRINTF(sc, ZYD_DEBUG_CMD, "finsihed cmd %p, error = %d \n",
833 &rq, error);
834
835 return (error);
836}
837
838static int
839zyd_read16(struct zyd_softc *sc, uint16_t reg, uint16_t *val)
840{
841 struct zyd_pair tmp;
842 int error;
843
844 reg = htole16(reg);
845 error = zyd_cmd(sc, ZYD_CMD_IORD, &reg, sizeof(reg), &tmp, sizeof(tmp),
847 if (error == 0)
848 *val = le16toh(tmp.val);
849 return (error);
850}
851
852static int
853zyd_read32(struct zyd_softc *sc, uint16_t reg, uint32_t *val)
854{
855 struct zyd_pair tmp[2];
856 uint16_t regs[2];
857 int error;
858
859 regs[0] = htole16(ZYD_REG32_HI(reg));
860 regs[1] = htole16(ZYD_REG32_LO(reg));
861 error = zyd_cmd(sc, ZYD_CMD_IORD, regs, sizeof(regs), tmp, sizeof(tmp),
863 if (error == 0)
864 *val = le16toh(tmp[0].val) << 16 | le16toh(tmp[1].val);
865 return (error);
866}
867
868static int
869zyd_write16(struct zyd_softc *sc, uint16_t reg, uint16_t val)
870{
871 struct zyd_pair pair;
872
873 pair.reg = htole16(reg);
874 pair.val = htole16(val);
875
876 return zyd_cmd(sc, ZYD_CMD_IOWR, &pair, sizeof(pair), NULL, 0, 0);
877}
878
879static int
880zyd_write32(struct zyd_softc *sc, uint16_t reg, uint32_t val)
881{
882 struct zyd_pair pair[2];
883
884 pair[0].reg = htole16(ZYD_REG32_HI(reg));
885 pair[0].val = htole16(val >> 16);
886 pair[1].reg = htole16(ZYD_REG32_LO(reg));
887 pair[1].val = htole16(val & 0xffff);
888
889 return zyd_cmd(sc, ZYD_CMD_IOWR, pair, sizeof(pair), NULL, 0, 0);
890}
891
892static int
893zyd_rfwrite(struct zyd_softc *sc, uint32_t val)
894{
895 struct zyd_rf *rf = &sc->sc_rf;
896 struct zyd_rfwrite_cmd req;
897 uint16_t cr203;
898 int error, i;
899
900 zyd_read16_m(sc, ZYD_CR203, &cr203);
901 cr203 &= ~(ZYD_RF_IF_LE | ZYD_RF_CLK | ZYD_RF_DATA);
902
903 req.code = htole16(2);
904 req.width = htole16(rf->width);
905 for (i = 0; i < rf->width; i++) {
906 req.bit[i] = htole16(cr203);
907 if (val & (1 << (rf->width - 1 - i)))
908 req.bit[i] |= htole16(ZYD_RF_DATA);
909 }
910 error = zyd_cmd(sc, ZYD_CMD_RFCFG, &req, 4 + 2 * rf->width, NULL, 0, 0);
911fail:
912 return (error);
913}
914
915static int
916zyd_rfwrite_cr(struct zyd_softc *sc, uint32_t val)
917{
918 int error;
919
920 zyd_write16_m(sc, ZYD_CR244, (val >> 16) & 0xff);
921 zyd_write16_m(sc, ZYD_CR243, (val >> 8) & 0xff);
922 zyd_write16_m(sc, ZYD_CR242, (val >> 0) & 0xff);
923fail:
924 return (error);
925}
926
927static int
929{
930 int error;
931 uint32_t tmp;
932
933 zyd_read32_m(sc, ZYD_MAC_MISC, &tmp);
934 tmp &= ~ZYD_UNLOCK_PHY_REGS;
935 zyd_write32_m(sc, ZYD_MAC_MISC, tmp);
936fail:
937 return (error);
938}
939
940static int
942{
943 int error;
944 uint32_t tmp;
945
946 zyd_read32_m(sc, ZYD_MAC_MISC, &tmp);
947 tmp |= ZYD_UNLOCK_PHY_REGS;
948 zyd_write32_m(sc, ZYD_MAC_MISC, tmp);
949fail:
950 return (error);
951}
952
953/*
954 * RFMD RF methods.
955 */
956static int
958{
959 struct zyd_softc *sc = rf->rf_sc;
960 static const struct zyd_phy_pair phyini[] = ZYD_RFMD_PHY;
961 static const uint32_t rfini[] = ZYD_RFMD_RF;
962 int i, error;
963
964 /* init RF-dependent PHY registers */
965 for (i = 0; i < nitems(phyini); i++) {
966 zyd_write16_m(sc, phyini[i].reg, phyini[i].val);
967 }
968
969 /* init RFMD radio */
970 for (i = 0; i < nitems(rfini); i++) {
971 if ((error = zyd_rfwrite(sc, rfini[i])) != 0)
972 return (error);
973 }
974fail:
975 return (error);
976}
977
978static int
979zyd_rfmd_switch_radio(struct zyd_rf *rf, int on)
980{
981 int error;
982 struct zyd_softc *sc = rf->rf_sc;
983
984 zyd_write16_m(sc, ZYD_CR10, on ? 0x89 : 0x15);
985 zyd_write16_m(sc, ZYD_CR11, on ? 0x00 : 0x81);
986fail:
987 return (error);
988}
989
990static int
991zyd_rfmd_set_channel(struct zyd_rf *rf, uint8_t chan)
992{
993 int error;
994 struct zyd_softc *sc = rf->rf_sc;
995 static const struct {
996 uint32_t r1, r2;
998
999 error = zyd_rfwrite(sc, rfprog[chan - 1].r1);
1000 if (error != 0)
1001 goto fail;
1002 error = zyd_rfwrite(sc, rfprog[chan - 1].r2);
1003 if (error != 0)
1004 goto fail;
1005
1006fail:
1007 return (error);
1008}
1009
1010/*
1011 * AL2230 RF methods.
1012 */
1013static int
1015{
1016 struct zyd_softc *sc = rf->rf_sc;
1017 static const struct zyd_phy_pair phyini[] = ZYD_AL2230_PHY;
1018 static const struct zyd_phy_pair phy2230s[] = ZYD_AL2230S_PHY_INIT;
1019 static const struct zyd_phy_pair phypll[] = {
1020 { ZYD_CR251, 0x2f }, { ZYD_CR251, 0x3f },
1021 { ZYD_CR138, 0x28 }, { ZYD_CR203, 0x06 }
1022 };
1023 static const uint32_t rfini1[] = ZYD_AL2230_RF_PART1;
1024 static const uint32_t rfini2[] = ZYD_AL2230_RF_PART2;
1025 static const uint32_t rfini3[] = ZYD_AL2230_RF_PART3;
1026 int i, error;
1027
1028 /* init RF-dependent PHY registers */
1029 for (i = 0; i < nitems(phyini); i++)
1030 zyd_write16_m(sc, phyini[i].reg, phyini[i].val);
1031
1032 if (sc->sc_rfrev == ZYD_RF_AL2230S || sc->sc_al2230s != 0) {
1033 for (i = 0; i < nitems(phy2230s); i++)
1034 zyd_write16_m(sc, phy2230s[i].reg, phy2230s[i].val);
1035 }
1036
1037 /* init AL2230 radio */
1038 for (i = 0; i < nitems(rfini1); i++) {
1039 error = zyd_rfwrite(sc, rfini1[i]);
1040 if (error != 0)
1041 goto fail;
1042 }
1043
1044 if (sc->sc_rfrev == ZYD_RF_AL2230S || sc->sc_al2230s != 0)
1045 error = zyd_rfwrite(sc, 0x000824);
1046 else
1047 error = zyd_rfwrite(sc, 0x0005a4);
1048 if (error != 0)
1049 goto fail;
1050
1051 for (i = 0; i < nitems(rfini2); i++) {
1052 error = zyd_rfwrite(sc, rfini2[i]);
1053 if (error != 0)
1054 goto fail;
1055 }
1056
1057 for (i = 0; i < nitems(phypll); i++)
1058 zyd_write16_m(sc, phypll[i].reg, phypll[i].val);
1059
1060 for (i = 0; i < nitems(rfini3); i++) {
1061 error = zyd_rfwrite(sc, rfini3[i]);
1062 if (error != 0)
1063 goto fail;
1064 }
1065fail:
1066 return (error);
1067}
1068
1069static int
1071{
1072 int error, i;
1073 struct zyd_softc *sc = rf->rf_sc;
1074 static const struct zyd_phy_pair phy[] = ZYD_AL2230_PHY_FINI_PART1;
1075
1076 for (i = 0; i < nitems(phy); i++)
1077 zyd_write16_m(sc, phy[i].reg, phy[i].val);
1078
1079 if (sc->sc_newphy != 0)
1080 zyd_write16_m(sc, ZYD_CR9, 0xe1);
1081
1082 zyd_write16_m(sc, ZYD_CR203, 0x6);
1083fail:
1084 return (error);
1085}
1086
1087static int
1089{
1090 struct zyd_softc *sc = rf->rf_sc;
1091 static const struct zyd_phy_pair phy1[] = ZYD_AL2230_PHY_PART1;
1092 static const struct zyd_phy_pair phy2[] = ZYD_AL2230_PHY_PART2;
1093 static const struct zyd_phy_pair phy3[] = ZYD_AL2230_PHY_PART3;
1094 static const struct zyd_phy_pair phy2230s[] = ZYD_AL2230S_PHY_INIT;
1095 static const struct zyd_phy_pair phyini[] = ZYD_AL2230_PHY_B;
1096 static const uint32_t rfini_part1[] = ZYD_AL2230_RF_B_PART1;
1097 static const uint32_t rfini_part2[] = ZYD_AL2230_RF_B_PART2;
1098 static const uint32_t rfini_part3[] = ZYD_AL2230_RF_B_PART3;
1099 static const uint32_t zyd_al2230_chtable[][3] = ZYD_AL2230_CHANTABLE;
1100 int i, error;
1101
1102 for (i = 0; i < nitems(phy1); i++)
1103 zyd_write16_m(sc, phy1[i].reg, phy1[i].val);
1104
1105 /* init RF-dependent PHY registers */
1106 for (i = 0; i < nitems(phyini); i++)
1107 zyd_write16_m(sc, phyini[i].reg, phyini[i].val);
1108
1109 if (sc->sc_rfrev == ZYD_RF_AL2230S || sc->sc_al2230s != 0) {
1110 for (i = 0; i < nitems(phy2230s); i++)
1111 zyd_write16_m(sc, phy2230s[i].reg, phy2230s[i].val);
1112 }
1113
1114 for (i = 0; i < 3; i++) {
1115 error = zyd_rfwrite_cr(sc, zyd_al2230_chtable[0][i]);
1116 if (error != 0)
1117 return (error);
1118 }
1119
1120 for (i = 0; i < nitems(rfini_part1); i++) {
1121 error = zyd_rfwrite_cr(sc, rfini_part1[i]);
1122 if (error != 0)
1123 return (error);
1124 }
1125
1126 if (sc->sc_rfrev == ZYD_RF_AL2230S || sc->sc_al2230s != 0)
1127 error = zyd_rfwrite(sc, 0x241000);
1128 else
1129 error = zyd_rfwrite(sc, 0x25a000);
1130 if (error != 0)
1131 goto fail;
1132
1133 for (i = 0; i < nitems(rfini_part2); i++) {
1134 error = zyd_rfwrite_cr(sc, rfini_part2[i]);
1135 if (error != 0)
1136 return (error);
1137 }
1138
1139 for (i = 0; i < nitems(phy2); i++)
1140 zyd_write16_m(sc, phy2[i].reg, phy2[i].val);
1141
1142 for (i = 0; i < nitems(rfini_part3); i++) {
1143 error = zyd_rfwrite_cr(sc, rfini_part3[i]);
1144 if (error != 0)
1145 return (error);
1146 }
1147
1148 for (i = 0; i < nitems(phy3); i++)
1149 zyd_write16_m(sc, phy3[i].reg, phy3[i].val);
1150
1151 error = zyd_al2230_fini(rf);
1152fail:
1153 return (error);
1154}
1155
1156static int
1158{
1159 struct zyd_softc *sc = rf->rf_sc;
1160 int error, on251 = (sc->sc_macrev == ZYD_ZD1211) ? 0x3f : 0x7f;
1161
1162 zyd_write16_m(sc, ZYD_CR11, on ? 0x00 : 0x04);
1163 zyd_write16_m(sc, ZYD_CR251, on ? on251 : 0x2f);
1164fail:
1165 return (error);
1166}
1167
1168static int
1170{
1171 int error, i;
1172 struct zyd_softc *sc = rf->rf_sc;
1173 static const struct zyd_phy_pair phy1[] = {
1174 { ZYD_CR138, 0x28 }, { ZYD_CR203, 0x06 },
1175 };
1176 static const struct {
1177 uint32_t r1, r2, r3;
1179
1180 error = zyd_rfwrite(sc, rfprog[chan - 1].r1);
1181 if (error != 0)
1182 goto fail;
1183 error = zyd_rfwrite(sc, rfprog[chan - 1].r2);
1184 if (error != 0)
1185 goto fail;
1186 error = zyd_rfwrite(sc, rfprog[chan - 1].r3);
1187 if (error != 0)
1188 goto fail;
1189
1190 for (i = 0; i < nitems(phy1); i++)
1191 zyd_write16_m(sc, phy1[i].reg, phy1[i].val);
1192fail:
1193 return (error);
1194}
1195
1196static int
1198{
1199 int error, i;
1200 struct zyd_softc *sc = rf->rf_sc;
1201 static const struct zyd_phy_pair phy1[] = ZYD_AL2230_PHY_PART1;
1202 static const struct {
1203 uint32_t r1, r2, r3;
1205
1206 for (i = 0; i < nitems(phy1); i++)
1207 zyd_write16_m(sc, phy1[i].reg, phy1[i].val);
1208
1209 error = zyd_rfwrite_cr(sc, rfprog[chan - 1].r1);
1210 if (error != 0)
1211 goto fail;
1212 error = zyd_rfwrite_cr(sc, rfprog[chan - 1].r2);
1213 if (error != 0)
1214 goto fail;
1215 error = zyd_rfwrite_cr(sc, rfprog[chan - 1].r3);
1216 if (error != 0)
1217 goto fail;
1218 error = zyd_al2230_fini(rf);
1219fail:
1220 return (error);
1221}
1222
1223#define ZYD_AL2230_PHY_BANDEDGE6 \
1224{ \
1225 { ZYD_CR128, 0x14 }, { ZYD_CR129, 0x12 }, { ZYD_CR130, 0x10 }, \
1226 { ZYD_CR47, 0x1e } \
1227}
1228
1229static int
1230zyd_al2230_bandedge6(struct zyd_rf *rf, struct ieee80211_channel *c)
1231{
1232 int error = 0, i;
1233 struct zyd_softc *sc = rf->rf_sc;
1234 struct ieee80211com *ic = &sc->sc_ic;
1236 int chan = ieee80211_chan2ieee(ic, c);
1237
1238 if (chan == 1 || chan == 11)
1239 r[0].val = 0x12;
1240
1241 for (i = 0; i < nitems(r); i++)
1242 zyd_write16_m(sc, r[i].reg, r[i].val);
1243fail:
1244 return (error);
1245}
1246
1247/*
1248 * AL7230B RF methods.
1249 */
1250static int
1252{
1253 struct zyd_softc *sc = rf->rf_sc;
1254 static const struct zyd_phy_pair phyini_1[] = ZYD_AL7230B_PHY_1;
1255 static const struct zyd_phy_pair phyini_2[] = ZYD_AL7230B_PHY_2;
1256 static const struct zyd_phy_pair phyini_3[] = ZYD_AL7230B_PHY_3;
1257 static const uint32_t rfini_1[] = ZYD_AL7230B_RF_1;
1258 static const uint32_t rfini_2[] = ZYD_AL7230B_RF_2;
1259 int i, error;
1260
1261 /* for AL7230B, PHY and RF need to be initialized in "phases" */
1262
1263 /* init RF-dependent PHY registers, part one */
1264 for (i = 0; i < nitems(phyini_1); i++)
1265 zyd_write16_m(sc, phyini_1[i].reg, phyini_1[i].val);
1266
1267 /* init AL7230B radio, part one */
1268 for (i = 0; i < nitems(rfini_1); i++) {
1269 if ((error = zyd_rfwrite(sc, rfini_1[i])) != 0)
1270 return (error);
1271 }
1272 /* init RF-dependent PHY registers, part two */
1273 for (i = 0; i < nitems(phyini_2); i++)
1274 zyd_write16_m(sc, phyini_2[i].reg, phyini_2[i].val);
1275
1276 /* init AL7230B radio, part two */
1277 for (i = 0; i < nitems(rfini_2); i++) {
1278 if ((error = zyd_rfwrite(sc, rfini_2[i])) != 0)
1279 return (error);
1280 }
1281 /* init RF-dependent PHY registers, part three */
1282 for (i = 0; i < nitems(phyini_3); i++)
1283 zyd_write16_m(sc, phyini_3[i].reg, phyini_3[i].val);
1284fail:
1285 return (error);
1286}
1287
1288static int
1290{
1291 int error;
1292 struct zyd_softc *sc = rf->rf_sc;
1293
1294 zyd_write16_m(sc, ZYD_CR11, on ? 0x00 : 0x04);
1295 zyd_write16_m(sc, ZYD_CR251, on ? 0x3f : 0x2f);
1296fail:
1297 return (error);
1298}
1299
1300static int
1302{
1303 struct zyd_softc *sc = rf->rf_sc;
1304 static const struct {
1305 uint32_t r1, r2;
1307 static const uint32_t rfsc[] = ZYD_AL7230B_RF_SETCHANNEL;
1308 int i, error;
1309
1310 zyd_write16_m(sc, ZYD_CR240, 0x57);
1311 zyd_write16_m(sc, ZYD_CR251, 0x2f);
1312
1313 for (i = 0; i < nitems(rfsc); i++) {
1314 if ((error = zyd_rfwrite(sc, rfsc[i])) != 0)
1315 return (error);
1316 }
1317
1318 zyd_write16_m(sc, ZYD_CR128, 0x14);
1319 zyd_write16_m(sc, ZYD_CR129, 0x12);
1320 zyd_write16_m(sc, ZYD_CR130, 0x10);
1321 zyd_write16_m(sc, ZYD_CR38, 0x38);
1322 zyd_write16_m(sc, ZYD_CR136, 0xdf);
1323
1324 error = zyd_rfwrite(sc, rfprog[chan - 1].r1);
1325 if (error != 0)
1326 goto fail;
1327 error = zyd_rfwrite(sc, rfprog[chan - 1].r2);
1328 if (error != 0)
1329 goto fail;
1330 error = zyd_rfwrite(sc, 0x3c9000);
1331 if (error != 0)
1332 goto fail;
1333
1334 zyd_write16_m(sc, ZYD_CR251, 0x3f);
1335 zyd_write16_m(sc, ZYD_CR203, 0x06);
1336 zyd_write16_m(sc, ZYD_CR240, 0x08);
1337fail:
1338 return (error);
1339}
1340
1341/*
1342 * AL2210 RF methods.
1343 */
1344static int
1346{
1347 struct zyd_softc *sc = rf->rf_sc;
1348 static const struct zyd_phy_pair phyini[] = ZYD_AL2210_PHY;
1349 static const uint32_t rfini[] = ZYD_AL2210_RF;
1350 uint32_t tmp;
1351 int i, error;
1352
1353 zyd_write32_m(sc, ZYD_CR18, 2);
1354
1355 /* init RF-dependent PHY registers */
1356 for (i = 0; i < nitems(phyini); i++)
1357 zyd_write16_m(sc, phyini[i].reg, phyini[i].val);
1358
1359 /* init AL2210 radio */
1360 for (i = 0; i < nitems(rfini); i++) {
1361 if ((error = zyd_rfwrite(sc, rfini[i])) != 0)
1362 return (error);
1363 }
1364 zyd_write16_m(sc, ZYD_CR47, 0x1e);
1365 zyd_read32_m(sc, ZYD_CR_RADIO_PD, &tmp);
1366 zyd_write32_m(sc, ZYD_CR_RADIO_PD, tmp & ~1);
1367 zyd_write32_m(sc, ZYD_CR_RADIO_PD, tmp | 1);
1368 zyd_write32_m(sc, ZYD_CR_RFCFG, 0x05);
1369 zyd_write32_m(sc, ZYD_CR_RFCFG, 0x00);
1370 zyd_write16_m(sc, ZYD_CR47, 0x1e);
1371 zyd_write32_m(sc, ZYD_CR18, 3);
1372fail:
1373 return (error);
1374}
1375
1376static int
1378{
1379 /* vendor driver does nothing for this RF chip */
1380
1381 return (0);
1382}
1383
1384static int
1386{
1387 int error;
1388 struct zyd_softc *sc = rf->rf_sc;
1389 static const uint32_t rfprog[] = ZYD_AL2210_CHANTABLE;
1390 uint32_t tmp;
1391
1392 zyd_write32_m(sc, ZYD_CR18, 2);
1393 zyd_write16_m(sc, ZYD_CR47, 0x1e);
1394 zyd_read32_m(sc, ZYD_CR_RADIO_PD, &tmp);
1395 zyd_write32_m(sc, ZYD_CR_RADIO_PD, tmp & ~1);
1396 zyd_write32_m(sc, ZYD_CR_RADIO_PD, tmp | 1);
1397 zyd_write32_m(sc, ZYD_CR_RFCFG, 0x05);
1398 zyd_write32_m(sc, ZYD_CR_RFCFG, 0x00);
1399 zyd_write16_m(sc, ZYD_CR47, 0x1e);
1400
1401 /* actually set the channel */
1402 error = zyd_rfwrite(sc, rfprog[chan - 1]);
1403 if (error != 0)
1404 goto fail;
1405
1406 zyd_write32_m(sc, ZYD_CR18, 3);
1407fail:
1408 return (error);
1409}
1410
1411/*
1412 * GCT RF methods.
1413 */
1414static int
1416{
1417#define ZYD_GCT_INTR_REG 0x85c1
1418 struct zyd_softc *sc = rf->rf_sc;
1419 static const struct zyd_phy_pair phyini[] = ZYD_GCT_PHY;
1420 static const uint32_t rfini[] = ZYD_GCT_RF;
1421 static const uint16_t vco[11][7] = ZYD_GCT_VCO;
1422 int i, idx = -1, error;
1423 uint16_t data;
1424
1425 /* init RF-dependent PHY registers */
1426 for (i = 0; i < nitems(phyini); i++)
1427 zyd_write16_m(sc, phyini[i].reg, phyini[i].val);
1428
1429 /* init cgt radio */
1430 for (i = 0; i < nitems(rfini); i++) {
1431 if ((error = zyd_rfwrite(sc, rfini[i])) != 0)
1432 return (error);
1433 }
1434
1435 error = zyd_gct_mode(rf);
1436 if (error != 0)
1437 return (error);
1438
1439 for (i = 0; i < (int)(nitems(vco) - 1); i++) {
1440 error = zyd_gct_set_channel_synth(rf, 1, 0);
1441 if (error != 0)
1442 goto fail;
1443 error = zyd_gct_write(rf, vco[i][0]);
1444 if (error != 0)
1445 goto fail;
1448 if ((data & 0xf) == 0) {
1449 idx = i;
1450 break;
1451 }
1452 }
1453 if (idx == -1) {
1454 error = zyd_gct_set_channel_synth(rf, 1, 1);
1455 if (error != 0)
1456 goto fail;
1457 error = zyd_gct_write(rf, 0x6662);
1458 if (error != 0)
1459 goto fail;
1460 }
1461
1462 rf->idx = idx;
1463 zyd_write16_m(sc, ZYD_CR203, 0x6);
1464fail:
1465 return (error);
1466#undef ZYD_GCT_INTR_REG
1467}
1468
1469static int
1471{
1472 struct zyd_softc *sc = rf->rf_sc;
1473 static const uint32_t mode[] = {
1474 0x25f98, 0x25f9a, 0x25f94, 0x27fd4
1475 };
1476 int i, error;
1477
1478 for (i = 0; i < nitems(mode); i++) {
1479 if ((error = zyd_rfwrite(sc, mode[i])) != 0)
1480 break;
1481 }
1482 return (error);
1483}
1484
1485static int
1486zyd_gct_set_channel_synth(struct zyd_rf *rf, int chan, int acal)
1487{
1488 int error, idx = chan - 1;
1489 struct zyd_softc *sc = rf->rf_sc;
1490 static uint32_t acal_synth[] = ZYD_GCT_CHANNEL_ACAL;
1491 static uint32_t std_synth[] = ZYD_GCT_CHANNEL_STD;
1492 static uint32_t div_synth[] = ZYD_GCT_CHANNEL_DIV;
1493
1494 error = zyd_rfwrite(sc,
1495 (acal == 1) ? acal_synth[idx] : std_synth[idx]);
1496 if (error != 0)
1497 return (error);
1498 return zyd_rfwrite(sc, div_synth[idx]);
1499}
1500
1501static int
1502zyd_gct_write(struct zyd_rf *rf, uint16_t value)
1503{
1504 struct zyd_softc *sc = rf->rf_sc;
1505
1506 return zyd_rfwrite(sc, 0x300000 | 0x40000 | value);
1507}
1508
1509static int
1510zyd_gct_switch_radio(struct zyd_rf *rf, int on)
1511{
1512 int error;
1513 struct zyd_softc *sc = rf->rf_sc;
1514
1515 error = zyd_rfwrite(sc, on ? 0x25f94 : 0x25f90);
1516 if (error != 0)
1517 return (error);
1518
1519 zyd_write16_m(sc, ZYD_CR11, on ? 0x00 : 0x04);
1521 on ? ((sc->sc_macrev == ZYD_ZD1211B) ? 0x7f : 0x3f) : 0x2f);
1522fail:
1523 return (error);
1524}
1525
1526static int
1527zyd_gct_set_channel(struct zyd_rf *rf, uint8_t chan)
1528{
1529 int error, i;
1530 struct zyd_softc *sc = rf->rf_sc;
1531 static const struct zyd_phy_pair cmd[] = {
1532 { ZYD_CR80, 0x30 }, { ZYD_CR81, 0x30 }, { ZYD_CR79, 0x58 },
1533 { ZYD_CR12, 0xf0 }, { ZYD_CR77, 0x1b }, { ZYD_CR78, 0x58 },
1534 };
1535 static const uint16_t vco[11][7] = ZYD_GCT_VCO;
1536
1538 if (error != 0)
1539 goto fail;
1540 error = zyd_gct_write(rf, (rf->idx == -1) ? 0x6662 :
1541 vco[rf->idx][((chan - 1) / 2)]);
1542 if (error != 0)
1543 goto fail;
1544 error = zyd_gct_mode(rf);
1545 if (error != 0)
1546 return (error);
1547 for (i = 0; i < nitems(cmd); i++)
1548 zyd_write16_m(sc, cmd[i].reg, cmd[i].val);
1549 error = zyd_gct_txgain(rf, chan);
1550 if (error != 0)
1551 return (error);
1552 zyd_write16_m(sc, ZYD_CR203, 0x6);
1553fail:
1554 return (error);
1555}
1556
1557static int
1558zyd_gct_txgain(struct zyd_rf *rf, uint8_t chan)
1559{
1560 struct zyd_softc *sc = rf->rf_sc;
1561 static uint32_t txgain[] = ZYD_GCT_TXGAIN;
1562 uint8_t idx = sc->sc_pwrint[chan - 1];
1563
1564 if (idx >= nitems(txgain)) {
1565 device_printf(sc->sc_dev, "could not set TX gain (%d %#x)\n",
1566 chan, idx);
1567 return 0;
1568 }
1569
1570 return zyd_rfwrite(sc, 0x700000 | txgain[idx]);
1571}
1572
1573/*
1574 * Maxim2 RF methods.
1575 */
1576static int
1578{
1579 struct zyd_softc *sc = rf->rf_sc;
1580 static const struct zyd_phy_pair phyini[] = ZYD_MAXIM2_PHY;
1581 static const uint32_t rfini[] = ZYD_MAXIM2_RF;
1582 uint16_t tmp;
1583 int i, error;
1584
1585 /* init RF-dependent PHY registers */
1586 for (i = 0; i < nitems(phyini); i++)
1587 zyd_write16_m(sc, phyini[i].reg, phyini[i].val);
1588
1589 zyd_read16_m(sc, ZYD_CR203, &tmp);
1590 zyd_write16_m(sc, ZYD_CR203, tmp & ~(1 << 4));
1591
1592 /* init maxim2 radio */
1593 for (i = 0; i < nitems(rfini); i++) {
1594 if ((error = zyd_rfwrite(sc, rfini[i])) != 0)
1595 return (error);
1596 }
1597 zyd_read16_m(sc, ZYD_CR203, &tmp);
1598 zyd_write16_m(sc, ZYD_CR203, tmp | (1 << 4));
1599fail:
1600 return (error);
1601}
1602
1603static int
1605{
1606
1607 /* vendor driver does nothing for this RF chip */
1608 return (0);
1609}
1610
1611static int
1613{
1614 struct zyd_softc *sc = rf->rf_sc;
1615 static const struct zyd_phy_pair phyini[] = ZYD_MAXIM2_PHY;
1616 static const uint32_t rfini[] = ZYD_MAXIM2_RF;
1617 static const struct {
1618 uint32_t r1, r2;
1620 uint16_t tmp;
1621 int i, error;
1622
1623 /*
1624 * Do the same as we do when initializing it, except for the channel
1625 * values coming from the two channel tables.
1626 */
1627
1628 /* init RF-dependent PHY registers */
1629 for (i = 0; i < nitems(phyini); i++)
1630 zyd_write16_m(sc, phyini[i].reg, phyini[i].val);
1631
1632 zyd_read16_m(sc, ZYD_CR203, &tmp);
1633 zyd_write16_m(sc, ZYD_CR203, tmp & ~(1 << 4));
1634
1635 /* first two values taken from the chantables */
1636 error = zyd_rfwrite(sc, rfprog[chan - 1].r1);
1637 if (error != 0)
1638 goto fail;
1639 error = zyd_rfwrite(sc, rfprog[chan - 1].r2);
1640 if (error != 0)
1641 goto fail;
1642
1643 /* init maxim2 radio - skipping the two first values */
1644 for (i = 2; i < nitems(rfini); i++) {
1645 if ((error = zyd_rfwrite(sc, rfini[i])) != 0)
1646 return (error);
1647 }
1648 zyd_read16_m(sc, ZYD_CR203, &tmp);
1649 zyd_write16_m(sc, ZYD_CR203, tmp | (1 << 4));
1650fail:
1651 return (error);
1652}
1653
1654static int
1655zyd_rf_attach(struct zyd_softc *sc, uint8_t type)
1656{
1657 struct zyd_rf *rf = &sc->sc_rf;
1658
1659 rf->rf_sc = sc;
1660 rf->update_pwr = 1;
1661
1662 switch (type) {
1663 case ZYD_RF_RFMD:
1664 rf->init = zyd_rfmd_init;
1667 rf->width = 24; /* 24-bit RF values */
1668 break;
1669 case ZYD_RF_AL2230:
1670 case ZYD_RF_AL2230S:
1671 if (sc->sc_macrev == ZYD_ZD1211B) {
1672 rf->init = zyd_al2230_init_b;
1674 } else {
1675 rf->init = zyd_al2230_init;
1677 }
1680 rf->width = 24; /* 24-bit RF values */
1681 break;
1682 case ZYD_RF_AL7230B:
1683 rf->init = zyd_al7230B_init;
1686 rf->width = 24; /* 24-bit RF values */
1687 break;
1688 case ZYD_RF_AL2210:
1689 rf->init = zyd_al2210_init;
1692 rf->width = 24; /* 24-bit RF values */
1693 break;
1694 case ZYD_RF_MAXIM_NEW:
1695 case ZYD_RF_GCT:
1696 rf->init = zyd_gct_init;
1699 rf->width = 24; /* 24-bit RF values */
1700 rf->update_pwr = 0;
1701 break;
1702 case ZYD_RF_MAXIM_NEW2:
1703 rf->init = zyd_maxim2_init;
1706 rf->width = 18; /* 18-bit RF values */
1707 break;
1708 default:
1709 device_printf(sc->sc_dev,
1710 "sorry, radio \"%s\" is not supported yet\n",
1711 zyd_rf_name(type));
1712 return (EINVAL);
1713 }
1714 return (0);
1715}
1716
1717static const char *
1718zyd_rf_name(uint8_t type)
1719{
1720 static const char * const zyd_rfs[] = {
1721 "unknown", "unknown", "UW2451", "UCHIP", "AL2230",
1722 "AL7230B", "THETA", "AL2210", "MAXIM_NEW", "GCT",
1723 "AL2230S", "RALINK", "INTERSIL", "RFMD", "MAXIM_NEW2",
1724 "PHILIPS"
1725 };
1726
1727 return zyd_rfs[(type > 15) ? 0 : type];
1728}
1729
1730static int
1732{
1733 int error;
1734 const struct zyd_phy_pair *phyp;
1735 struct zyd_rf *rf = &sc->sc_rf;
1736 uint16_t val;
1737
1738 /* specify that the plug and play is finished */
1741 DPRINTF(sc, ZYD_DEBUG_FW, "firmware base address=0x%04x\n",
1742 sc->sc_fwbase);
1743
1744 /* retrieve firmware revision number */
1748 /* set mandatory rates - XXX assumes 802.11b/g */
1749 zyd_write32_m(sc, ZYD_MAC_MAN_RATE, 0x150f);
1750
1751 /* disable interrupts */
1753
1754 if ((error = zyd_read_pod(sc)) != 0) {
1755 device_printf(sc->sc_dev, "could not read EEPROM\n");
1756 goto fail;
1757 }
1758
1759 /* PHY init (resetting) */
1760 error = zyd_lock_phy(sc);
1761 if (error != 0)
1762 goto fail;
1763 phyp = (sc->sc_macrev == ZYD_ZD1211B) ? zyd_def_phyB : zyd_def_phy;
1764 for (; phyp->reg != 0; phyp++)
1765 zyd_write16_m(sc, phyp->reg, phyp->val);
1766 if (sc->sc_macrev == ZYD_ZD1211 && sc->sc_fix_cr157 != 0) {
1768 zyd_write32_m(sc, ZYD_CR157, val >> 8);
1769 }
1770 error = zyd_unlock_phy(sc);
1771 if (error != 0)
1772 goto fail;
1773
1774 /* HMAC init */
1775 zyd_write32_m(sc, ZYD_MAC_ACK_EXT, 0x00000020);
1776 zyd_write32_m(sc, ZYD_CR_ADDA_MBIAS_WT, 0x30000808);
1777 zyd_write32_m(sc, ZYD_MAC_SNIFFER, 0x00000000);
1778 zyd_write32_m(sc, ZYD_MAC_RXFILTER, 0x00000000);
1779 zyd_write32_m(sc, ZYD_MAC_GHTBL, 0x00000000);
1780 zyd_write32_m(sc, ZYD_MAC_GHTBH, 0x80000000);
1781 zyd_write32_m(sc, ZYD_MAC_MISC, 0x000000a4);
1782 zyd_write32_m(sc, ZYD_CR_ADDA_PWR_DWN, 0x0000007f);
1783 zyd_write32_m(sc, ZYD_MAC_BCNCFG, 0x00f00401);
1784 zyd_write32_m(sc, ZYD_MAC_PHY_DELAY2, 0x00000000);
1785 zyd_write32_m(sc, ZYD_MAC_ACK_EXT, 0x00000080);
1786 zyd_write32_m(sc, ZYD_CR_ADDA_PWR_DWN, 0x00000000);
1787 zyd_write32_m(sc, ZYD_MAC_SIFS_ACK_TIME, 0x00000100);
1788 zyd_write32_m(sc, ZYD_CR_RX_PE_DELAY, 0x00000070);
1789 zyd_write32_m(sc, ZYD_CR_PS_CTRL, 0x10000000);
1790 zyd_write32_m(sc, ZYD_MAC_RTSCTSRATE, 0x02030203);
1792 zyd_write32_m(sc, ZYD_MAC_BACKOFF_PROTECT, 0x00000114);
1793 zyd_write32_m(sc, ZYD_MAC_DIFS_EIFS_SIFS, 0x0a47c032);
1795
1796 if (sc->sc_macrev == ZYD_ZD1211) {
1797 zyd_write32_m(sc, ZYD_MAC_RETRY, 0x00000002);
1798 zyd_write32_m(sc, ZYD_MAC_RX_THRESHOLD, 0x000c0640);
1799 } else {
1800 zyd_write32_m(sc, ZYD_MACB_MAX_RETRY, 0x02020202);
1801 zyd_write32_m(sc, ZYD_MACB_TXPWR_CTL4, 0x007f003f);
1802 zyd_write32_m(sc, ZYD_MACB_TXPWR_CTL3, 0x007f003f);
1803 zyd_write32_m(sc, ZYD_MACB_TXPWR_CTL2, 0x003f001f);
1804 zyd_write32_m(sc, ZYD_MACB_TXPWR_CTL1, 0x001f000f);
1805 zyd_write32_m(sc, ZYD_MACB_AIFS_CTL1, 0x00280028);
1806 zyd_write32_m(sc, ZYD_MACB_AIFS_CTL2, 0x008C003C);
1807 zyd_write32_m(sc, ZYD_MACB_TXOP, 0x01800824);
1808 zyd_write32_m(sc, ZYD_MAC_RX_THRESHOLD, 0x000c0eff);
1809 }
1810
1811 /* init beacon interval to 100ms */
1812 if ((error = zyd_set_beacon_interval(sc, 100)) != 0)
1813 goto fail;
1814
1815 if ((error = zyd_rf_attach(sc, sc->sc_rfrev)) != 0) {
1816 device_printf(sc->sc_dev, "could not attach RF, rev 0x%x\n",
1817 sc->sc_rfrev);
1818 goto fail;
1819 }
1820
1821 /* RF chip init */
1822 error = zyd_lock_phy(sc);
1823 if (error != 0)
1824 goto fail;
1825 error = (*rf->init)(rf);
1826 if (error != 0) {
1827 device_printf(sc->sc_dev,
1828 "radio initialization failed, error %d\n", error);
1829 goto fail;
1830 }
1831 error = zyd_unlock_phy(sc);
1832 if (error != 0)
1833 goto fail;
1834
1835 if ((error = zyd_read_eeprom(sc)) != 0) {
1836 device_printf(sc->sc_dev, "could not read EEPROM\n");
1837 goto fail;
1838 }
1839
1840fail: return (error);
1841}
1842
1843static int
1845{
1846 int error;
1847 uint32_t tmp;
1848
1849 zyd_read32_m(sc, ZYD_EEPROM_POD, &tmp);
1850 sc->sc_rfrev = tmp & 0x0f;
1851 sc->sc_ledtype = (tmp >> 4) & 0x01;
1852 sc->sc_al2230s = (tmp >> 7) & 0x01;
1853 sc->sc_cckgain = (tmp >> 8) & 0x01;
1854 sc->sc_fix_cr157 = (tmp >> 13) & 0x01;
1855 sc->sc_parev = (tmp >> 16) & 0x0f;
1856 sc->sc_bandedge6 = (tmp >> 21) & 0x01;
1857 sc->sc_newphy = (tmp >> 31) & 0x01;
1858 sc->sc_txled = ((tmp & (1 << 24)) && (tmp & (1 << 29))) ? 0 : 1;
1859fail:
1860 return (error);
1861}
1862
1863static int
1865{
1866 uint16_t val;
1867 int error, i;
1868
1869 /* read Tx power calibration tables */
1870 for (i = 0; i < 7; i++) {
1872 sc->sc_pwrcal[i * 2] = val >> 8;
1873 sc->sc_pwrcal[i * 2 + 1] = val & 0xff;
1875 sc->sc_pwrint[i * 2] = val >> 8;
1876 sc->sc_pwrint[i * 2 + 1] = val & 0xff;
1878 sc->sc_ofdm36_cal[i * 2] = val >> 8;
1879 sc->sc_ofdm36_cal[i * 2 + 1] = val & 0xff;
1881 sc->sc_ofdm48_cal[i * 2] = val >> 8;
1882 sc->sc_ofdm48_cal[i * 2 + 1] = val & 0xff;
1884 sc->sc_ofdm54_cal[i * 2] = val >> 8;
1885 sc->sc_ofdm54_cal[i * 2 + 1] = val & 0xff;
1886 }
1887fail:
1888 return (error);
1889}
1890
1891static int
1893{
1894 struct usb_device_request req;
1896
1897 req.bmRequestType = UT_READ_VENDOR_DEVICE;
1898 req.bRequest = ZYD_READFWDATAREQ;
1900 USETW(req.wIndex, 0);
1901 USETW(req.wLength, IEEE80211_ADDR_LEN);
1902
1903 error = zyd_do_request(sc, &req, sc->sc_ic.ic_macaddr);
1904 if (error != 0) {
1905 device_printf(sc->sc_dev, "could not read EEPROM: %s\n",
1907 }
1908
1909 return (error);
1910}
1911
1912static int
1913zyd_set_macaddr(struct zyd_softc *sc, const uint8_t *addr)
1914{
1915 int error;
1916 uint32_t tmp;
1917
1918 tmp = addr[3] << 24 | addr[2] << 16 | addr[1] << 8 | addr[0];
1920 tmp = addr[5] << 8 | addr[4];
1922fail:
1923 return (error);
1924}
1925
1926static int
1927zyd_set_bssid(struct zyd_softc *sc, const uint8_t *addr)
1928{
1929 int error;
1930 uint32_t tmp;
1931
1932 tmp = addr[3] << 24 | addr[2] << 16 | addr[1] << 8 | addr[0];
1934 tmp = addr[5] << 8 | addr[4];
1936fail:
1937 return (error);
1938}
1939
1940static int
1941zyd_switch_radio(struct zyd_softc *sc, int on)
1942{
1943 struct zyd_rf *rf = &sc->sc_rf;
1944 int error;
1945
1946 error = zyd_lock_phy(sc);
1947 if (error != 0)
1948 goto fail;
1949 error = (*rf->switch_radio)(rf, on);
1950 if (error != 0)
1951 goto fail;
1952 error = zyd_unlock_phy(sc);
1953fail:
1954 return (error);
1955}
1956
1957static int
1958zyd_set_led(struct zyd_softc *sc, int which, int on)
1959{
1960 int error;
1961 uint32_t tmp;
1962
1964 tmp &= ~which;
1965 if (on)
1966 tmp |= which;
1968fail:
1969 return (error);
1970}
1971
1972static u_int
1973zyd_hash_maddr(void *arg, struct sockaddr_dl *sdl, u_int cnt)
1974{
1975 uint32_t *hash = arg;
1976 uint8_t v;
1977
1978 v = ((uint8_t *)LLADDR(sdl))[5] >> 2;
1979 if (v < 32)
1980 hash[0] |= 1 << v;
1981 else
1982 hash[1] |= 1 << (v - 32);
1983
1984 return (1);
1985}
1986
1987static void
1989{
1990 struct ieee80211com *ic = &sc->sc_ic;
1991 uint32_t hash[2];
1992 int error;
1993
1994 if ((sc->sc_flags & ZYD_FLAG_RUNNING) == 0)
1995 return;
1996
1997 hash[0] = 0x00000000;
1998 hash[1] = 0x80000000;
1999
2000 if (ic->ic_opmode == IEEE80211_M_MONITOR || ic->ic_allmulti > 0 ||
2001 ic->ic_promisc > 0) {
2002 hash[0] = 0xffffffff;
2003 hash[1] = 0xffffffff;
2004 } else {
2005 struct ieee80211vap *vap;
2006
2007 TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next)
2008 if_foreach_llmaddr(vap->iv_ifp, zyd_hash_maddr, &hash);
2009 }
2010
2011 /* reprogram multicast global hash table */
2012 zyd_write32_m(sc, ZYD_MAC_GHTBL, hash[0]);
2013 zyd_write32_m(sc, ZYD_MAC_GHTBH, hash[1]);
2014fail:
2015 if (error != 0)
2016 device_printf(sc->sc_dev,
2017 "could not set multicast hash table\n");
2018}
2019
2020static void
2021zyd_update_mcast(struct ieee80211com *ic)
2022{
2023 struct zyd_softc *sc = ic->ic_softc;
2024
2025 ZYD_LOCK(sc);
2026 zyd_set_multi(sc);
2027 ZYD_UNLOCK(sc);
2028}
2029
2030static int
2032{
2033 struct ieee80211com *ic = &sc->sc_ic;
2034 uint32_t rxfilter;
2035
2036 switch (ic->ic_opmode) {
2037 case IEEE80211_M_STA:
2038 rxfilter = ZYD_FILTER_BSS;
2039 break;
2040 case IEEE80211_M_IBSS:
2041 case IEEE80211_M_HOSTAP:
2042 rxfilter = ZYD_FILTER_HOSTAP;
2043 break;
2044 case IEEE80211_M_MONITOR:
2045 rxfilter = ZYD_FILTER_MONITOR;
2046 break;
2047 default:
2048 /* should not get there */
2049 return (EINVAL);
2050 }
2051 return zyd_write32(sc, ZYD_MAC_RXFILTER, rxfilter);
2052}
2053
2054static void
2055zyd_set_chan(struct zyd_softc *sc, struct ieee80211_channel *c)
2056{
2057 int error;
2058 struct ieee80211com *ic = &sc->sc_ic;
2059 struct zyd_rf *rf = &sc->sc_rf;
2060 uint32_t tmp;
2061 int chan;
2062
2063 chan = ieee80211_chan2ieee(ic, c);
2064 if (chan == 0 || chan == IEEE80211_CHAN_ANY) {
2065 /* XXX should NEVER happen */
2066 device_printf(sc->sc_dev,
2067 "%s: invalid channel %x\n", __func__, chan);
2068 return;
2069 }
2070
2071 error = zyd_lock_phy(sc);
2072 if (error != 0)
2073 goto fail;
2074
2075 error = (*rf->set_channel)(rf, chan);
2076 if (error != 0)
2077 goto fail;
2078
2079 if (rf->update_pwr) {
2080 /* update Tx power */
2081 zyd_write16_m(sc, ZYD_CR31, sc->sc_pwrint[chan - 1]);
2082
2083 if (sc->sc_macrev == ZYD_ZD1211B) {
2085 sc->sc_ofdm36_cal[chan - 1]);
2087 sc->sc_ofdm48_cal[chan - 1]);
2089 sc->sc_ofdm54_cal[chan - 1]);
2090 zyd_write16_m(sc, ZYD_CR68, sc->sc_pwrcal[chan - 1]);
2091 zyd_write16_m(sc, ZYD_CR69, 0x28);
2092 zyd_write16_m(sc, ZYD_CR69, 0x2a);
2093 }
2094 }
2095 if (sc->sc_cckgain) {
2096 /* set CCK baseband gain from EEPROM */
2097 if (zyd_read32(sc, ZYD_EEPROM_PHY_REG, &tmp) == 0)
2098 zyd_write16_m(sc, ZYD_CR47, tmp & 0xff);
2099 }
2100 if (sc->sc_bandedge6 && rf->bandedge6 != NULL) {
2101 error = (*rf->bandedge6)(rf, c);
2102 if (error != 0)
2103 goto fail;
2104 }
2106
2107 error = zyd_unlock_phy(sc);
2108 if (error != 0)
2109 goto fail;
2110
2112 htole16(c->ic_freq);
2114 htole16(c->ic_flags);
2115fail:
2116 return;
2117}
2118
2119static int
2120zyd_set_beacon_interval(struct zyd_softc *sc, int bintval)
2121{
2122 int error;
2123 uint32_t val;
2124
2126 sc->sc_atim_wnd = val;
2128 sc->sc_pre_tbtt = val;
2129 sc->sc_bcn_int = bintval;
2130
2131 if (sc->sc_bcn_int <= 5)
2132 sc->sc_bcn_int = 5;
2133 if (sc->sc_pre_tbtt < 4 || sc->sc_pre_tbtt >= sc->sc_bcn_int)
2134 sc->sc_pre_tbtt = sc->sc_bcn_int - 1;
2135 if (sc->sc_atim_wnd >= sc->sc_pre_tbtt)
2136 sc->sc_atim_wnd = sc->sc_pre_tbtt - 1;
2137
2141fail:
2142 return (error);
2143}
2144
2145static void
2146zyd_rx_data(struct usb_xfer *xfer, int offset, uint16_t len)
2147{
2148 struct zyd_softc *sc = usbd_xfer_softc(xfer);
2149 struct ieee80211com *ic = &sc->sc_ic;
2150 struct zyd_plcphdr plcp;
2151 struct zyd_rx_stat stat;
2152 struct usb_page_cache *pc;
2153 struct mbuf *m;
2154 int rlen, rssi;
2155
2156 if (len < ZYD_MIN_FRAGSZ) {
2157 DPRINTF(sc, ZYD_DEBUG_RECV, "%s: frame too short (length=%d)\n",
2158 device_get_nameunit(sc->sc_dev), len);
2159 counter_u64_add(ic->ic_ierrors, 1);
2160 return;
2161 }
2162 pc = usbd_xfer_get_frame(xfer, 0);
2163 usbd_copy_out(pc, offset, &plcp, sizeof(plcp));
2164 usbd_copy_out(pc, offset + len - sizeof(stat), &stat, sizeof(stat));
2165
2166 if (stat.flags & ZYD_RX_ERROR) {
2167 DPRINTF(sc, ZYD_DEBUG_RECV,
2168 "%s: RX status indicated error (%x)\n",
2169 device_get_nameunit(sc->sc_dev), stat.flags);
2170 counter_u64_add(ic->ic_ierrors, 1);
2171 return;
2172 }
2173
2174 /* compute actual frame length */
2175 rlen = len - sizeof(struct zyd_plcphdr) -
2176 sizeof(struct zyd_rx_stat) - IEEE80211_CRC_LEN;
2177
2178 /* allocate a mbuf to store the frame */
2179 if (rlen > (int)MCLBYTES) {
2180 DPRINTF(sc, ZYD_DEBUG_RECV, "%s: frame too long (length=%d)\n",
2181 device_get_nameunit(sc->sc_dev), rlen);
2182 counter_u64_add(ic->ic_ierrors, 1);
2183 return;
2184 } else if (rlen > (int)MHLEN)
2185 m = m_getcl(M_NOWAIT, MT_DATA, M_PKTHDR);
2186 else
2187 m = m_gethdr(M_NOWAIT, MT_DATA);
2188 if (m == NULL) {
2189 DPRINTF(sc, ZYD_DEBUG_RECV, "%s: could not allocate rx mbuf\n",
2190 device_get_nameunit(sc->sc_dev));
2191 counter_u64_add(ic->ic_ierrors, 1);
2192 return;
2193 }
2194 m->m_pkthdr.len = m->m_len = rlen;
2195 usbd_copy_out(pc, offset + sizeof(plcp), mtod(m, uint8_t *), rlen);
2196
2197 if (ieee80211_radiotap_active(ic)) {
2198 struct zyd_rx_radiotap_header *tap = &sc->sc_rxtap;
2199
2200 tap->wr_flags = 0;
2201 if (stat.flags & (ZYD_RX_BADCRC16 | ZYD_RX_BADCRC32))
2202 tap->wr_flags |= IEEE80211_RADIOTAP_F_BADFCS;
2203 /* XXX toss, no way to express errors */
2204 if (stat.flags & ZYD_RX_DECRYPTERR)
2205 tap->wr_flags |= IEEE80211_RADIOTAP_F_BADFCS;
2206 tap->wr_rate = ieee80211_plcp2rate(plcp.signal,
2207 (stat.flags & ZYD_RX_OFDM) ?
2208 IEEE80211_T_OFDM : IEEE80211_T_CCK);
2209 tap->wr_antsignal = stat.rssi + -95;
2210 tap->wr_antnoise = -95; /* XXX */
2211 }
2212 rssi = (stat.rssi > 63) ? 127 : 2 * stat.rssi;
2213
2214 sc->sc_rx_data[sc->sc_rx_count].rssi = rssi;
2215 sc->sc_rx_data[sc->sc_rx_count].m = m;
2216 sc->sc_rx_count++;
2217}
2218
2219static void
2221{
2222 struct zyd_softc *sc = usbd_xfer_softc(xfer);
2223 struct ieee80211com *ic = &sc->sc_ic;
2224 struct ieee80211_node *ni;
2225 struct epoch_tracker et;
2226 struct zyd_rx_desc desc;
2227 struct mbuf *m;
2228 struct usb_page_cache *pc;
2229 uint32_t offset;
2230 uint8_t rssi;
2231 int8_t nf;
2232 int i;
2233 int actlen;
2234
2235 usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL);
2236
2237 sc->sc_rx_count = 0;
2238 switch (USB_GET_STATE(xfer)) {
2239 case USB_ST_TRANSFERRED:
2240 pc = usbd_xfer_get_frame(xfer, 0);
2241 usbd_copy_out(pc, actlen - sizeof(desc), &desc, sizeof(desc));
2242
2243 offset = 0;
2244 if (UGETW(desc.tag) == ZYD_TAG_MULTIFRAME) {
2245 DPRINTF(sc, ZYD_DEBUG_RECV,
2246 "%s: received multi-frame transfer\n", __func__);
2247
2248 for (i = 0; i < ZYD_MAX_RXFRAMECNT; i++) {
2249 uint16_t len16 = UGETW(desc.len[i]);
2250
2251 if (len16 == 0 || len16 > actlen)
2252 break;
2253
2254 zyd_rx_data(xfer, offset, len16);
2255
2256 /* next frame is aligned on a 32-bit boundary */
2257 len16 = (len16 + 3) & ~3;
2258 offset += len16;
2259 if (len16 > actlen)
2260 break;
2261 actlen -= len16;
2262 }
2263 } else {
2264 DPRINTF(sc, ZYD_DEBUG_RECV,
2265 "%s: received single-frame transfer\n", __func__);
2266
2267 zyd_rx_data(xfer, 0, actlen);
2268 }
2269 /* FALLTHROUGH */
2270 case USB_ST_SETUP:
2271tr_setup:
2274
2275 /*
2276 * At the end of a USB callback it is always safe to unlock
2277 * the private mutex of a device! That is why we do the
2278 * "ieee80211_input" here, and not some lines up!
2279 */
2280 ZYD_UNLOCK(sc);
2281 NET_EPOCH_ENTER(et);
2282 for (i = 0; i < sc->sc_rx_count; i++) {
2283 rssi = sc->sc_rx_data[i].rssi;
2284 m = sc->sc_rx_data[i].m;
2285 sc->sc_rx_data[i].m = NULL;
2286
2287 nf = -95; /* XXX */
2288
2289 ni = ieee80211_find_rxnode(ic,
2290 mtod(m, struct ieee80211_frame_min *));
2291 if (ni != NULL) {
2292 (void)ieee80211_input(ni, m, rssi, nf);
2293 ieee80211_free_node(ni);
2294 } else
2295 (void)ieee80211_input_all(ic, m, rssi, nf);
2296 }
2297 NET_EPOCH_EXIT(et);
2298 ZYD_LOCK(sc);
2299 zyd_start(sc);
2300 break;
2301
2302 default: /* Error */
2303 DPRINTF(sc, ZYD_DEBUG_ANY, "frame error: %s\n", usbd_errstr(error));
2304
2305 if (error != USB_ERR_CANCELLED) {
2306 /* try to clear stall first */
2307 usbd_xfer_set_stall(xfer);
2308 goto tr_setup;
2309 }
2310 break;
2311 }
2312}
2313
2314static uint8_t
2315zyd_plcp_signal(struct zyd_softc *sc, int rate)
2316{
2317 switch (rate) {
2318 /* OFDM rates (cf IEEE Std 802.11a-1999, pp. 14 Table 80) */
2319 case 12:
2320 return (0xb);
2321 case 18:
2322 return (0xf);
2323 case 24:
2324 return (0xa);
2325 case 36:
2326 return (0xe);
2327 case 48:
2328 return (0x9);
2329 case 72:
2330 return (0xd);
2331 case 96:
2332 return (0x8);
2333 case 108:
2334 return (0xc);
2335 /* CCK rates (NB: not IEEE std, device-specific) */
2336 case 2:
2337 return (0x0);
2338 case 4:
2339 return (0x1);
2340 case 11:
2341 return (0x2);
2342 case 22:
2343 return (0x3);
2344 }
2345
2346 device_printf(sc->sc_dev, "unsupported rate %d\n", rate);
2347 return (0x0);
2348}
2349
2350static void
2352{
2353 struct zyd_softc *sc = usbd_xfer_softc(xfer);
2354 struct ieee80211vap *vap;
2355 struct zyd_tx_data *data;
2356 struct mbuf *m;
2357 struct usb_page_cache *pc;
2358 int actlen;
2359
2360 usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL);
2361
2362 switch (USB_GET_STATE(xfer)) {
2363 case USB_ST_TRANSFERRED:
2364 DPRINTF(sc, ZYD_DEBUG_ANY, "transfer complete, %u bytes\n",
2365 actlen);
2366
2367 /* free resources */
2368 data = usbd_xfer_get_priv(xfer);
2369 zyd_tx_free(data, 0);
2370 usbd_xfer_set_priv(xfer, NULL);
2371
2372 /* FALLTHROUGH */
2373 case USB_ST_SETUP:
2374tr_setup:
2375 data = STAILQ_FIRST(&sc->tx_q);
2376 if (data) {
2377 STAILQ_REMOVE_HEAD(&sc->tx_q, next);
2378 m = data->m;
2379
2380 if (m->m_pkthdr.len > (int)ZYD_MAX_TXBUFSZ) {
2381 DPRINTF(sc, ZYD_DEBUG_ANY, "data overflow, %u bytes\n",
2382 m->m_pkthdr.len);
2383 m->m_pkthdr.len = ZYD_MAX_TXBUFSZ;
2384 }
2385 pc = usbd_xfer_get_frame(xfer, 0);
2386 usbd_copy_in(pc, 0, &data->desc, ZYD_TX_DESC_SIZE);
2388 m->m_pkthdr.len);
2389
2390 vap = data->ni->ni_vap;
2391 if (ieee80211_radiotap_active_vap(vap)) {
2392 struct zyd_tx_radiotap_header *tap = &sc->sc_txtap;
2393
2394 tap->wt_flags = 0;
2395 tap->wt_rate = data->rate;
2396
2397 ieee80211_radiotap_tx(vap, m);
2398 }
2399
2400 usbd_xfer_set_frame_len(xfer, 0, ZYD_TX_DESC_SIZE + m->m_pkthdr.len);
2401 usbd_xfer_set_priv(xfer, data);
2403 }
2404 zyd_start(sc);
2405 break;
2406
2407 default: /* Error */
2408 DPRINTF(sc, ZYD_DEBUG_ANY, "transfer error, %s\n",
2410
2411 counter_u64_add(sc->sc_ic.ic_oerrors, 1);
2412 data = usbd_xfer_get_priv(xfer);
2413 usbd_xfer_set_priv(xfer, NULL);
2414 if (data != NULL)
2416
2417 if (error != USB_ERR_CANCELLED) {
2418 if (error == USB_ERR_TIMEOUT)
2419 device_printf(sc->sc_dev, "device timeout\n");
2420
2421 /*
2422 * Try to clear stall first, also if other
2423 * errors occur, hence clearing stall
2424 * introduces a 50 ms delay:
2425 */
2426 usbd_xfer_set_stall(xfer);
2427 goto tr_setup;
2428 }
2429 break;
2430 }
2431}
2432
2433static int
2434zyd_tx_start(struct zyd_softc *sc, struct mbuf *m0, struct ieee80211_node *ni)
2435{
2436 struct ieee80211vap *vap = ni->ni_vap;
2437 struct ieee80211com *ic = ni->ni_ic;
2438 struct zyd_tx_desc *desc;
2439 struct zyd_tx_data *data;
2440 struct ieee80211_frame *wh;
2441 const struct ieee80211_txparam *tp = ni->ni_txparms;
2442 struct ieee80211_key *k;
2443 int rate, totlen, type, ismcast;
2444 static const uint8_t ratediv[] = ZYD_TX_RATEDIV;
2445 uint8_t phy;
2446 uint16_t pktlen;
2447 uint32_t bits;
2448
2449 wh = mtod(m0, struct ieee80211_frame *);
2450 data = STAILQ_FIRST(&sc->tx_free);
2451 STAILQ_REMOVE_HEAD(&sc->tx_free, next);
2452 sc->tx_nfree--;
2453
2454 ismcast = IEEE80211_IS_MULTICAST(wh->i_addr1);
2455 type = wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK;
2456
2457 if (type == IEEE80211_FC0_TYPE_MGT ||
2458 type == IEEE80211_FC0_TYPE_CTL ||
2459 (m0->m_flags & M_EAPOL) != 0) {
2460 rate = tp->mgmtrate;
2461 } else {
2462 /* for data frames */
2463 if (ismcast)
2464 rate = tp->mcastrate;
2465 else if (tp->ucastrate != IEEE80211_FIXED_RATE_NONE)
2466 rate = tp->ucastrate;
2467 else {
2468 (void) ieee80211_ratectl_rate(ni, NULL, 0);
2469 rate = ni->ni_txrate;
2470 }
2471 }
2472
2473 if (wh->i_fc[1] & IEEE80211_FC1_PROTECTED) {
2474 k = ieee80211_crypto_encap(ni, m0);
2475 if (k == NULL) {
2476 return (ENOBUFS);
2477 }
2478 /* packet header may have moved, reset our local pointer */
2479 wh = mtod(m0, struct ieee80211_frame *);
2480 }
2481
2482 data->ni = ni;
2483 data->m = m0;
2484 data->rate = rate;
2485
2486 /* fill Tx descriptor */
2487 desc = &data->desc;
2488 phy = zyd_plcp_signal(sc, rate);
2489 desc->phy = phy;
2490 if (ZYD_RATE_IS_OFDM(rate)) {
2491 desc->phy |= ZYD_TX_PHY_OFDM;
2492 if (IEEE80211_IS_CHAN_5GHZ(ic->ic_curchan))
2493 desc->phy |= ZYD_TX_PHY_5GHZ;
2494 } else if (rate != 2 && (ic->ic_flags & IEEE80211_F_SHPREAMBLE))
2496
2497 totlen = m0->m_pkthdr.len + IEEE80211_CRC_LEN;
2498 desc->len = htole16(totlen);
2499
2500 desc->flags = ZYD_TX_FLAG_BACKOFF;
2501 if (!ismcast) {
2502 /* multicast frames are not sent at OFDM rates in 802.11b/g */
2503 if (totlen > vap->iv_rtsthreshold) {
2504 desc->flags |= ZYD_TX_FLAG_RTS;
2505 } else if (ZYD_RATE_IS_OFDM(rate) &&
2506 (ic->ic_flags & IEEE80211_F_USEPROT)) {
2507 if (ic->ic_protmode == IEEE80211_PROT_CTSONLY)
2508 desc->flags |= ZYD_TX_FLAG_CTS_TO_SELF;
2509 else if (ic->ic_protmode == IEEE80211_PROT_RTSCTS)
2510 desc->flags |= ZYD_TX_FLAG_RTS;
2511 }
2512 } else
2513 desc->flags |= ZYD_TX_FLAG_MULTICAST;
2514 if ((wh->i_fc[0] &
2515 (IEEE80211_FC0_TYPE_MASK | IEEE80211_FC0_SUBTYPE_MASK)) ==
2516 (IEEE80211_FC0_TYPE_CTL | IEEE80211_FC0_SUBTYPE_PS_POLL))
2518
2519 /* actual transmit length (XXX why +10?) */
2520 pktlen = ZYD_TX_DESC_SIZE + 10;
2521 if (sc->sc_macrev == ZYD_ZD1211)
2522 pktlen += totlen;
2523 desc->pktlen = htole16(pktlen);
2524
2525 bits = (rate == 11) ? (totlen * 16) + 10 :
2526 ((rate == 22) ? (totlen * 8) + 10 : (totlen * 8));
2527 desc->plcp_length = htole16(bits / ratediv[phy]);
2528 desc->plcp_service = 0;
2529 if (rate == 22 && (bits % 11) > 0 && (bits % 11) <= 3)
2530 desc->plcp_service |= ZYD_PLCP_LENGEXT;
2531 desc->nextlen = 0;
2532
2533 if (ieee80211_radiotap_active_vap(vap)) {
2534 struct zyd_tx_radiotap_header *tap = &sc->sc_txtap;
2535
2536 tap->wt_flags = 0;
2537 tap->wt_rate = rate;
2538
2539 ieee80211_radiotap_tx(vap, m0);
2540 }
2541
2542 DPRINTF(sc, ZYD_DEBUG_XMIT,
2543 "%s: sending data frame len=%zu rate=%u\n",
2544 device_get_nameunit(sc->sc_dev), (size_t)m0->m_pkthdr.len,
2545 rate);
2546
2547 STAILQ_INSERT_TAIL(&sc->tx_q, data, next);
2549
2550 return (0);
2551}
2552
2553static int
2554zyd_transmit(struct ieee80211com *ic, struct mbuf *m)
2555{
2556 struct zyd_softc *sc = ic->ic_softc;
2557 int error;
2558
2559 ZYD_LOCK(sc);
2560 if ((sc->sc_flags & ZYD_FLAG_RUNNING) == 0) {
2561 ZYD_UNLOCK(sc);
2562 return (ENXIO);
2563 }
2564 error = mbufq_enqueue(&sc->sc_snd, m);
2565 if (error) {
2566 ZYD_UNLOCK(sc);
2567 return (error);
2568 }
2569 zyd_start(sc);
2570 ZYD_UNLOCK(sc);
2571
2572 return (0);
2573}
2574
2575static void
2577{
2578 struct ieee80211_node *ni;
2579 struct mbuf *m;
2580
2581 ZYD_LOCK_ASSERT(sc, MA_OWNED);
2582
2583 while (sc->tx_nfree > 0 && (m = mbufq_dequeue(&sc->sc_snd)) != NULL) {
2584 ni = (struct ieee80211_node *)m->m_pkthdr.rcvif;
2585 if (zyd_tx_start(sc, m, ni) != 0) {
2586 m_freem(m);
2587 if_inc_counter(ni->ni_vap->iv_ifp,
2588 IFCOUNTER_OERRORS, 1);
2589 ieee80211_free_node(ni);
2590 break;
2591 }
2592 }
2593}
2594
2595static int
2596zyd_raw_xmit(struct ieee80211_node *ni, struct mbuf *m,
2597 const struct ieee80211_bpf_params *params)
2598{
2599 struct ieee80211com *ic = ni->ni_ic;
2600 struct zyd_softc *sc = ic->ic_softc;
2601
2602 ZYD_LOCK(sc);
2603 /* prevent management frames from being sent if we're not ready */
2604 if (!(sc->sc_flags & ZYD_FLAG_RUNNING)) {
2605 ZYD_UNLOCK(sc);
2606 m_freem(m);
2607 return (ENETDOWN);
2608 }
2609 if (sc->tx_nfree == 0) {
2610 ZYD_UNLOCK(sc);
2611 m_freem(m);
2612 return (ENOBUFS); /* XXX */
2613 }
2614
2615 /*
2616 * Legacy path; interpret frame contents to decide
2617 * precisely how to send the frame.
2618 * XXX raw path
2619 */
2620 if (zyd_tx_start(sc, m, ni) != 0) {
2621 ZYD_UNLOCK(sc);
2622 m_freem(m);
2623 return (EIO);
2624 }
2625 ZYD_UNLOCK(sc);
2626 return (0);
2627}
2628
2629static void
2630zyd_parent(struct ieee80211com *ic)
2631{
2632 struct zyd_softc *sc = ic->ic_softc;
2633 int startall = 0;
2634
2635 ZYD_LOCK(sc);
2636 if (sc->sc_flags & ZYD_FLAG_DETACHED) {
2637 ZYD_UNLOCK(sc);
2638 return;
2639 }
2640 if (ic->ic_nrunning > 0) {
2641 if ((sc->sc_flags & ZYD_FLAG_RUNNING) == 0) {
2642 zyd_init_locked(sc);
2643 startall = 1;
2644 } else
2645 zyd_set_multi(sc);
2646 } else if (sc->sc_flags & ZYD_FLAG_RUNNING)
2647 zyd_stop(sc);
2648 ZYD_UNLOCK(sc);
2649 if (startall)
2650 ieee80211_start_all(ic);
2651}
2652
2653static void
2655{
2656 struct ieee80211com *ic = &sc->sc_ic;
2657 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps);
2658 struct usb_config_descriptor *cd;
2659 int error;
2660 uint32_t val;
2661
2662 ZYD_LOCK_ASSERT(sc, MA_OWNED);
2663
2664 if (!(sc->sc_flags & ZYD_FLAG_INITONCE)) {
2665 error = zyd_loadfirmware(sc);
2666 if (error != 0) {
2667 device_printf(sc->sc_dev,
2668 "could not load firmware (error=%d)\n", error);
2669 goto fail;
2670 }
2671
2672 /* reset device */
2676 if (error)
2677 device_printf(sc->sc_dev, "reset failed, continuing\n");
2678
2679 error = zyd_hw_init(sc);
2680 if (error) {
2681 device_printf(sc->sc_dev,
2682 "hardware initialization failed\n");
2683 goto fail;
2684 }
2685
2686 device_printf(sc->sc_dev,
2687 "HMAC ZD1211%s, FW %02x.%02x, RF %s S%x, PA%x LED %x "
2688 "BE%x NP%x Gain%x F%x\n",
2689 (sc->sc_macrev == ZYD_ZD1211) ? "": "B",
2690 sc->sc_fwrev >> 8, sc->sc_fwrev & 0xff,
2691 zyd_rf_name(sc->sc_rfrev), sc->sc_al2230s, sc->sc_parev,
2692 sc->sc_ledtype, sc->sc_bandedge6, sc->sc_newphy,
2693 sc->sc_cckgain, sc->sc_fix_cr157);
2694
2695 /* read regulatory domain (currently unused) */
2697 sc->sc_regdomain = val >> 16;
2698 DPRINTF(sc, ZYD_DEBUG_INIT, "regulatory domain %x\n",
2699 sc->sc_regdomain);
2700
2701 /* we'll do software WEP decryption for now */
2702 DPRINTF(sc, ZYD_DEBUG_INIT, "%s: setting encryption type\n",
2703 __func__);
2705
2707 }
2708
2709 if (sc->sc_flags & ZYD_FLAG_RUNNING)
2710 zyd_stop(sc);
2711
2712 DPRINTF(sc, ZYD_DEBUG_INIT, "setting MAC address to %6D\n",
2713 vap ? vap->iv_myaddr : ic->ic_macaddr, ":");
2714 error = zyd_set_macaddr(sc, vap ? vap->iv_myaddr : ic->ic_macaddr);
2715 if (error != 0)
2716 return;
2717
2718 /* set basic rates */
2719 if (ic->ic_curmode == IEEE80211_MODE_11B)
2720 zyd_write32_m(sc, ZYD_MAC_BAS_RATE, 0x0003);
2721 else if (ic->ic_curmode == IEEE80211_MODE_11A)
2722 zyd_write32_m(sc, ZYD_MAC_BAS_RATE, 0x1500);
2723 else /* assumes 802.11b/g */
2724 zyd_write32_m(sc, ZYD_MAC_BAS_RATE, 0xff0f);
2725
2726 /* promiscuous mode */
2728 /* multicast setup */
2729 zyd_set_multi(sc);
2730 /* set RX filter */
2731 error = zyd_set_rxfilter(sc);
2732 if (error != 0)
2733 goto fail;
2734
2735 /* switch radio transmitter ON */
2736 error = zyd_switch_radio(sc, 1);
2737 if (error != 0)
2738 goto fail;
2739 /* set default BSS channel */
2740 zyd_set_chan(sc, ic->ic_curchan);
2741
2742 /*
2743 * Allocate Tx and Rx xfer queues.
2744 */
2746
2747 /* enable interrupts */
2749
2754
2755 return;
2756
2757fail: zyd_stop(sc);
2758 return;
2759}
2760
2761static void
2763{
2764 int error;
2765
2766 ZYD_LOCK_ASSERT(sc, MA_OWNED);
2767
2768 sc->sc_flags &= ~ZYD_FLAG_RUNNING;
2769 zyd_drain_mbufq(sc);
2770
2771 /*
2772 * Drain all the transfers, if not already drained:
2773 */
2774 ZYD_UNLOCK(sc);
2777 ZYD_LOCK(sc);
2778
2780
2781 /* Stop now if the device was never set up */
2782 if (!(sc->sc_flags & ZYD_FLAG_INITONCE))
2783 return;
2784
2785 /* switch radio transmitter OFF */
2786 error = zyd_switch_radio(sc, 0);
2787 if (error != 0)
2788 goto fail;
2789 /* disable Rx */
2791 /* disable interrupts */
2793
2794fail:
2795 return;
2796}
2797
2798static int
2800{
2801 struct usb_device_request req;
2802 size_t size;
2803 u_char *fw;
2804 uint8_t stat;
2805 uint16_t addr;
2806
2807 if (sc->sc_flags & ZYD_FLAG_FWLOADED)
2808 return (0);
2809
2810 if (sc->sc_macrev == ZYD_ZD1211) {
2811 fw = (u_char *)zd1211_firmware;
2812 size = sizeof(zd1211_firmware);
2813 } else {
2814 fw = (u_char *)zd1211b_firmware;
2815 size = sizeof(zd1211b_firmware);
2816 }
2817
2818 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
2819 req.bRequest = ZYD_DOWNLOADREQ;
2820 USETW(req.wIndex, 0);
2821
2823 while (size > 0) {
2824 /*
2825 * When the transfer size is 4096 bytes, it is not
2826 * likely to be able to transfer it.
2827 * The cause is port or machine or chip?
2828 */
2829 const int mlen = min(size, 64);
2830
2831 DPRINTF(sc, ZYD_DEBUG_FW,
2832 "loading firmware block: len=%d, addr=0x%x\n", mlen, addr);
2833
2834 USETW(req.wValue, addr);
2835 USETW(req.wLength, mlen);
2836 if (zyd_do_request(sc, &req, fw) != 0)
2837 return (EIO);
2838
2839 addr += mlen / 2;
2840 fw += mlen;
2841 size -= mlen;
2842 }
2843
2844 /* check whether the upload succeeded */
2845 req.bmRequestType = UT_READ_VENDOR_DEVICE;
2846 req.bRequest = ZYD_DOWNLOADSTS;
2847 USETW(req.wValue, 0);
2848 USETW(req.wIndex, 0);
2849 USETW(req.wLength, sizeof(stat));
2850 if (zyd_do_request(sc, &req, &stat) != 0)
2851 return (EIO);
2852
2854
2855 return (stat & 0x80) ? (EIO) : (0);
2856}
2857
2858static void
2859zyd_scan_start(struct ieee80211com *ic)
2860{
2861 struct zyd_softc *sc = ic->ic_softc;
2862
2863 ZYD_LOCK(sc);
2864 /* want broadcast address while scanning */
2865 zyd_set_bssid(sc, ieee80211broadcastaddr);
2866 ZYD_UNLOCK(sc);
2867}
2868
2869static void
2870zyd_scan_end(struct ieee80211com *ic)
2871{
2872 struct zyd_softc *sc = ic->ic_softc;
2873
2874 ZYD_LOCK(sc);
2875 /* restore previous bssid */
2876 zyd_set_bssid(sc, sc->sc_bssid);
2877 ZYD_UNLOCK(sc);
2878}
2879
2880static void
2881zyd_getradiocaps(struct ieee80211com *ic,
2882 int maxchans, int *nchans, struct ieee80211_channel chans[])
2883{
2884 uint8_t bands[IEEE80211_MODE_BYTES];
2885
2886 memset(bands, 0, sizeof(bands));
2887 setbit(bands, IEEE80211_MODE_11B);
2888 setbit(bands, IEEE80211_MODE_11G);
2889 ieee80211_add_channels_default_2ghz(chans, maxchans, nchans, bands, 0);
2890}
2891
2892static void
2893zyd_set_channel(struct ieee80211com *ic)
2894{
2895 struct zyd_softc *sc = ic->ic_softc;
2896
2897 ZYD_LOCK(sc);
2898 zyd_set_chan(sc, ic->ic_curchan);
2899 ZYD_UNLOCK(sc);
2900}
2901
2902static device_method_t zyd_methods[] = {
2903 /* Device interface */
2904 DEVMETHOD(device_probe, zyd_match),
2905 DEVMETHOD(device_attach, zyd_attach),
2906 DEVMETHOD(device_detach, zyd_detach),
2907 DEVMETHOD_END
2908};
2909
2910static driver_t zyd_driver = {
2911 .name = "zyd",
2912 .methods = zyd_methods,
2913 .size = sizeof(struct zyd_softc)
2914};
2915
2916static devclass_t zyd_devclass;
2917
2919MODULE_DEPEND(zyd, usb, 1, 1, 1);
2920MODULE_DEPEND(zyd, wlan, 1, 1, 1);
static int debug
Definition: cfumass.c:73
static SYSCTL_NODE(_hw_usb, OID_AUTO, dwc_otg, CTLFLAG_RW|CTLFLAG_MPSAFE, 0, "USB DWC OTG")
SYSCTL_INT(_hw_usb_dwc_otg, OID_AUTO, phy_type, CTLFLAG_RDTUN, &dwc_otg_phy_type, 0, "DWC OTG PHY TYPE - 0/1/2/3 - ULPI/HSIC/INTERNAL/UTMI+")
struct ehci_itd * next
Definition: ehci.h:29
uint16_t len
Definition: ehci.h:41
uint8_t size
Definition: if_axge.c:89
uint32_t reg
Definition: if_rum.c:283
uint32_t val
Definition: if_rum.c:284
uint8_t r
Definition: if_run.c:612
uint8_t k
Definition: if_run.c:612
uint16_t fail
Definition: if_runreg.h:2
uint16_t retry
Definition: if_runreg.h:7
struct @109 error
uint32_t r1
Definition: if_ural.c:315
uint32_t r2
Definition: if_ural.c:316
uint8_t chan
Definition: if_ural.c:314
#define ZYD_ZD1211
Definition: if_zyd.c:198
static void zyd_scan_start(struct ieee80211com *)
Definition: if_zyd.c:2859
static void zyd_update_mcast(struct ieee80211com *)
Definition: if_zyd.c:2021
static int zyd_al2210_set_channel(struct zyd_rf *, uint8_t)
Definition: if_zyd.c:1385
static void zyd_getradiocaps(struct ieee80211com *, int, int *, struct ieee80211_channel[])
Definition: if_zyd.c:2881
static int zyd_al2230_init_b(struct zyd_rf *)
Definition: if_zyd.c:1088
static u_int zyd_hash_maddr(void *arg, struct sockaddr_dl *sdl, u_int cnt)
Definition: if_zyd.c:1973
#define ZYD_ZD1211B_DEV(v, p)
Definition: if_zyd.c:203
static int zyd_lock_phy(struct zyd_softc *)
Definition: if_zyd.c:928
#define zyd_read16_m(sc, val, data)
Definition: if_zyd.c:296
static int zyd_rf_attach(struct zyd_softc *, uint8_t)
Definition: if_zyd.c:1655
static int zyd_al2230_switch_radio(struct zyd_rf *, int)
Definition: if_zyd.c:1157
#define ZYD_GCT_INTR_REG
static int zyd_al2230_set_channel_b(struct zyd_rf *, uint8_t)
Definition: if_zyd.c:1197
static usb_callback_t zyd_bulk_read_callback
Definition: if_zyd.c:117
static int zyd_get_macaddr(struct zyd_softc *)
Definition: if_zyd.c:1892
static const struct usb_config zyd_config[ZYD_N_TRANSFER]
Definition: if_zyd.c:257
static void zyd_setup_tx_list(struct zyd_softc *)
Definition: if_zyd.c:536
static usb_callback_t zyd_bulk_write_callback
Definition: if_zyd.c:118
static int zyd_al2210_switch_radio(struct zyd_rf *, int)
Definition: if_zyd.c:1377
static struct ieee80211vap * zyd_vap_create(struct ieee80211com *, const char[IFNAMSIZ], int, enum ieee80211_opmode, int, const uint8_t[IEEE80211_ADDR_LEN], const uint8_t[IEEE80211_ADDR_LEN])
Definition: if_zyd.c:476
static int zyd_gct_set_channel(struct zyd_rf *, uint8_t)
Definition: if_zyd.c:1527
static int zyd_gct_txgain(struct zyd_rf *, uint8_t)
Definition: if_zyd.c:1558
static int zyd_tx_start(struct zyd_softc *, struct mbuf *, struct ieee80211_node *)
Definition: if_zyd.c:2434
static int zyd_raw_xmit(struct ieee80211_node *, struct mbuf *, const struct ieee80211_bpf_params *)
Definition: if_zyd.c:2596
static void zyd_vap_delete(struct ieee80211vap *)
Definition: if_zyd.c:512
USB_PNP_HOST_INFO(zyd_devs)
static uint8_t zyd_plcp_signal(struct zyd_softc *sc, int rate)
Definition: if_zyd.c:2315
static int zyd_set_led(struct zyd_softc *, int, int)
Definition: if_zyd.c:1958
static int zyd_al7230B_switch_radio(struct zyd_rf *, int)
Definition: if_zyd.c:1289
static int zyd_loadfirmware(struct zyd_softc *)
Definition: if_zyd.c:2799
static void zyd_parent(struct ieee80211com *)
Definition: if_zyd.c:2630
static int zyd_set_beacon_interval(struct zyd_softc *, int)
Definition: if_zyd.c:2120
static usb_callback_t zyd_intr_read_callback
Definition: if_zyd.c:115
static void zyd_tx_free(struct zyd_tx_data *, int)
Definition: if_zyd.c:522
#define ZYD_AL2230_PHY_BANDEDGE6
Definition: if_zyd.c:1223
static driver_t zyd_driver
Definition: if_zyd.c:2910
static int zyd_gct_set_channel_synth(struct zyd_rf *, int, int)
Definition: if_zyd.c:1486
static int zyd_rfmd_init(struct zyd_rf *)
Definition: if_zyd.c:957
static int zyd_read32(struct zyd_softc *, uint16_t, uint32_t *)
Definition: if_zyd.c:853
static int zyd_gct_mode(struct zyd_rf *)
Definition: if_zyd.c:1470
static int zyd_maxim2_set_channel(struct zyd_rf *, uint8_t)
Definition: if_zyd.c:1612
static int zyd_unlock_phy(struct zyd_softc *)
Definition: if_zyd.c:941
#define zyd_write16_m(sc, val, data)
Definition: if_zyd.c:301
#define ZYD_ZD1211_DEV(v, p)
Definition: if_zyd.c:201
static int zyd_newstate(struct ieee80211vap *, enum ieee80211_state, int)
Definition: if_zyd.c:581
static void zyd_set_chan(struct zyd_softc *, struct ieee80211_channel *)
Definition: if_zyd.c:2055
static const struct zyd_phy_pair zyd_def_phyB[]
Definition: if_zyd.c:195
MODULE_DEPEND(zyd, usb, 1, 1, 1)
static int zyd_rfmd_switch_radio(struct zyd_rf *, int)
Definition: if_zyd.c:979
static void zyd_init_locked(struct zyd_softc *)
Definition: if_zyd.c:2654
static device_detach_t zyd_detach
Definition: if_zyd.c:113
static void zyd_start(struct zyd_softc *)
Definition: if_zyd.c:2576
__FBSDID("$FreeBSD$")
#define DPRINTF(sc, m, fmt,...)
Definition: if_zyd.c:103
static int zyd_al7230B_init(struct zyd_rf *)
Definition: if_zyd.c:1251
static int zyd_maxim2_switch_radio(struct zyd_rf *, int)
Definition: if_zyd.c:1604
static int zyd_set_bssid(struct zyd_softc *, const uint8_t *)
Definition: if_zyd.c:1927
static int zyd_write16(struct zyd_softc *, uint16_t, uint16_t)
Definition: if_zyd.c:869
#define ZYD_ZD1211B
Definition: if_zyd.c:199
#define zyd_write32_m(sc, val, data)
Definition: if_zyd.c:311
static usb_callback_t zyd_intr_write_callback
Definition: if_zyd.c:116
static int zyd_rfwrite_cr(struct zyd_softc *sc, uint32_t val)
Definition: if_zyd.c:916
DRIVER_MODULE(zyd, uhub, zyd_driver, zyd_devclass, NULL, 0)
static int zyd_switch_radio(struct zyd_softc *, int)
Definition: if_zyd.c:1941
static const STRUCT_USB_HOST_ID zyd_devs[]
Definition: if_zyd.c:205
static int zyd_cmd(struct zyd_softc *, uint16_t, const void *, int, void *, int, int)
Definition: if_zyd.c:802
static int zyd_rfmd_set_channel(struct zyd_rf *, uint8_t)
Definition: if_zyd.c:991
static void zyd_scan_end(struct ieee80211com *)
Definition: if_zyd.c:2870
static int zyd_al2230_bandedge6(struct zyd_rf *rf, struct ieee80211_channel *c)
Definition: if_zyd.c:1230
static int zyd_rfwrite(struct zyd_softc *, uint32_t)
Definition: if_zyd.c:893
static void zyd_unsetup_tx_list(struct zyd_softc *)
Definition: if_zyd.c:555
static int zyd_read_pod(struct zyd_softc *)
Definition: if_zyd.c:1844
static int zyd_gct_init(struct zyd_rf *)
Definition: if_zyd.c:1415
static int zyd_hw_init(struct zyd_softc *)
Definition: if_zyd.c:1731
static void zyd_drain_mbufq(struct zyd_softc *sc)
Definition: if_zyd.c:424
MODULE_VERSION(zyd, 1)
static const char * zyd_rf_name(uint8_t)
Definition: if_zyd.c:1718
static device_method_t zyd_methods[]
Definition: if_zyd.c:2902
static void zyd_set_channel(struct ieee80211com *)
Definition: if_zyd.c:2893
static device_attach_t zyd_attach
Definition: if_zyd.c:112
static devclass_t zyd_devclass
Definition: if_zyd.c:2916
static int zyd_transmit(struct ieee80211com *, struct mbuf *)
Definition: if_zyd.c:2554
static int zyd_al7230B_set_channel(struct zyd_rf *, uint8_t)
Definition: if_zyd.c:1301
static device_probe_t zyd_match
Definition: if_zyd.c:111
static int zyd_gct_switch_radio(struct zyd_rf *, int)
Definition: if_zyd.c:1510
static void zyd_set_multi(struct zyd_softc *)
Definition: if_zyd.c:1988
static const struct zyd_phy_pair zyd_def_phy[]
Definition: if_zyd.c:194
static int zyd_al2230_fini(struct zyd_rf *rf)
Definition: if_zyd.c:1070
static int zyd_al2210_init(struct zyd_rf *)
Definition: if_zyd.c:1345
static int zyd_al2230_set_channel(struct zyd_rf *, uint8_t)
Definition: if_zyd.c:1169
static int zyd_maxim2_init(struct zyd_rf *)
Definition: if_zyd.c:1577
static int zyd_read16(struct zyd_softc *, uint16_t, uint16_t *)
Definition: if_zyd.c:839
static int zyd_set_rxfilter(struct zyd_softc *)
Definition: if_zyd.c:2031
static void zyd_rx_data(struct usb_xfer *, int, uint16_t)
Definition: if_zyd.c:2146
static int zyd_gct_write(struct zyd_rf *, uint16_t)
Definition: if_zyd.c:1502
static int zyd_write32(struct zyd_softc *, uint16_t, uint32_t)
Definition: if_zyd.c:880
static int zyd_read_eeprom(struct zyd_softc *)
Definition: if_zyd.c:1864
static void zyd_stop(struct zyd_softc *)
Definition: if_zyd.c:2762
#define zyd_read32_m(sc, val, data)
Definition: if_zyd.c:306
#define zyd_do_request(sc, req, data)
Definition: if_zyd.c:108
static int zyd_al2230_init(struct zyd_rf *)
Definition: if_zyd.c:1014
static int zyd_set_macaddr(struct zyd_softc *, const uint8_t *)
Definition: if_zyd.c:1913
uint8_t zd1211_firmware[]
Definition: if_zydfw.h:31
uint8_t zd1211b_firmware[]
Definition: if_zydfw.h:679
#define ZYD_DEF_PHYB
Definition: if_zydreg.h:488
#define ZYD_TX_DESC_SIZE
Definition: if_zydreg.h:1145
#define ZYD_RFMD_PHY
Definition: if_zydreg.h:539
#define ZYD_TX_FLAG_BACKOFF
Definition: if_zydreg.h:1036
#define ZYD_RF_GCT
Definition: if_zydreg.h:164
#define ZYD_CR_RFCFG
Definition: if_zydreg.h:35
#define ZYD_MAC_RETRY
Definition: if_zydreg.h:79
#define ZYD_CR81
Definition: if_zydreg.h:256
#define ZYD_FILTER_MONITOR
Definition: if_zydreg.h:1013
#define ZYD_CR77
Definition: if_zydreg.h:252
#define ZYD_MAC_TX_PE_CONTROL
Definition: if_zydreg.h:68
#define ZYD_CR_ADDA_PWR_DWN
Definition: if_zydreg.h:44
#define ZYD_FIRMWARE_START_ADDR
Definition: if_zydreg.h:117
#define ZYD_CR9
Definition: if_zydreg.h:184
#define ZYD_NOTIF_IORD
Definition: if_zydreg.h:1106
#define ZYD_ENC_SNIFFER
Definition: if_zydreg.h:991
#define ZYD_AL2230_CHANTABLE
Definition: if_zydreg.h:710
#define ZYD_TX_RADIOTAP_PRESENT
Definition: if_zydreg.h:1205
#define ZYD_LOCK_ASSERT(sc, t)
Definition: if_zydreg.h:1314
#define ZYD_CR_INTERRUPT
Definition: if_zydreg.h:46
#define ZYD_RX_BADCRC16
Definition: if_zydreg.h:1079
#define ZYD_AL2230_RF_PART1
Definition: if_zydreg.h:671
#define ZYD_AL2230_PHY_PART2
Definition: if_zydreg.h:646
#define ZYD_CR_ATIM_WND_PERIOD
Definition: if_zydreg.h:48
#define ZYD_MAC_SNIFFER
Definition: if_zydreg.h:77
#define ZYD_TX_FLAG_TYPE(x)
Definition: if_zydreg.h:1038
#define ZYD_EEPROM_36M_CAL
Definition: if_zydreg.h:133
#define ZYD_CR65
Definition: if_zydreg.h:240
#define ZYD_MAC_PHY_DELAY2
Definition: if_zydreg.h:75
#define ZYD_TX_RATEDIV
Definition: if_zydreg.h:971
#define ZYD_RF_CLK
Definition: if_zydreg.h:1097
#define ZYD_RF_RFMD
Definition: if_zydreg.h:168
#define ZYD_RF_AL2230
Definition: if_zydreg.h:159
#define ZYD_TX_PHY_SHPREAMBLE
Definition: if_zydreg.h:1032
#define ZYD_GCT_TXGAIN
Definition: if_zydreg.h:886
#define ZYD_AL2210_RF
Definition: if_zydreg.h:828
#define ZYD_MAC_GHTBL
Definition: if_zydreg.h:60
#define ZYD_GCT_RF
Definition: if_zydreg.h:865
#define ZYD_CR129
Definition: if_zydreg.h:304
#define ZYD_MAC_BCNCFG
Definition: if_zydreg.h:59
#define ZYD_MAC_ACK_EXT
Definition: if_zydreg.h:84
#define ZYD_AL7230B_RF_2
Definition: if_zydreg.h:787
#define ZYD_CR66
Definition: if_zydreg.h:241
#define ZYD_CR79
Definition: if_zydreg.h:254
#define ZYD_RX_RADIOTAP_PRESENT
Definition: if_zydreg.h:1190
@ ZYD_BULK_WR
Definition: if_zydreg.h:1244
@ ZYD_INTR_WR
Definition: if_zydreg.h:1246
@ ZYD_N_TRANSFER
Definition: if_zydreg.h:1248
@ ZYD_INTR_RD
Definition: if_zydreg.h:1247
@ ZYD_BULK_RD
Definition: if_zydreg.h:1245
#define ZYD_CR_RADIO_PD
Definition: if_zydreg.h:27
#define ZYD_CR_PRE_TBTT
Definition: if_zydreg.h:50
#define ZYD_MAC_RX_THRESHOLD
Definition: if_zydreg.h:67
#define ZYD_CR80
Definition: if_zydreg.h:255
#define ZYD_LED1
Definition: if_zydreg.h:151
#define ZYD_LOCK(sc)
Definition: if_zydreg.h:1312
#define ZYD_EEPROM_54M_CAL
Definition: if_zydreg.h:137
#define ZYD_MACB_MAX_RETRY
Definition: if_zydreg.h:112
#define ZYD_CR244
Definition: if_zydreg.h:416
#define ZYD_MAC_ENCRYPTION_TYPE
Definition: if_zydreg.h:78
#define ZYD_CMD_FLAG_READ
Definition: if_zydreg.h:1149
#define ZYD_CR128
Definition: if_zydreg.h:303
#define ZYD_TX_PHY_5GHZ
Definition: if_zydreg.h:1033
#define ZYD_READFWDATAREQ
Definition: if_zydreg.h:982
#define ZYD_AL2230_CHANTABLE_B
Definition: if_zydreg.h:728
#define ZYD_GCT_CHANNEL_ACAL
Definition: if_zydreg.h:893
#define ZYD_RFMD_CHANTABLE
Definition: if_zydreg.h:575
#define ZYD_MACB_AIFS_CTL2
Definition: if_zydreg.h:110
#define ZYD_EEPROM_48M_CAL
Definition: if_zydreg.h:135
#define ZYD_RF_MAXIM_NEW2
Definition: if_zydreg.h:169
#define ZYD_CR203
Definition: if_zydreg.h:378
#define ZYD_AL7230B_PHY_3
Definition: if_zydreg.h:775
#define ZYD_CR67
Definition: if_zydreg.h:242
#define ZYD_AL7230B_PHY_1
Definition: if_zydreg.h:746
#define ZYX_MAX_RXBUFSZ
Definition: if_zydreg.h:1141
#define ZYD_CMD_IOWR
Definition: if_zydreg.h:1103
#define ZYD_AL2230_PHY_PART1
Definition: if_zydreg.h:641
#define ZYD_GCT_PHY
Definition: if_zydreg.h:841
#define ZYD_AL2210_CHANTABLE
Definition: if_zydreg.h:834
#define ZYD_MAX_RXFRAMECNT
Definition: if_zydreg.h:1085
#define ZYD_CR47
Definition: if_zydreg.h:222
#define ZYD_AL7230B_RF_SETCHANNEL
Definition: if_zydreg.h:792
#define ZYD_MAC_MAN_RATE
Definition: if_zydreg.h:64
#define ZYD_RATE_IS_OFDM(rate)
Definition: if_zydreg.h:1153
#define ZYD_MAC_BSSADRL
Definition: if_zydreg.h:57
#define ZYD_MAX_TXBUFSZ
Definition: if_zydreg.h:1135
#define ZYD_MAC_CONT_WIN_LIMIT
Definition: if_zydreg.h:101
#define ZYD_IFACE_INDEX
Definition: if_zydreg.h:1130
#define ZYD_GCT_CHANNEL_DIV
Definition: if_zydreg.h:907
#define ZYD_AL2230_RF_B_PART2
Definition: if_zydreg.h:699
#define ZYD_AL2230_RF_PART3
Definition: if_zydreg.h:682
#define ZYD_AL2230_RF_PART2
Definition: if_zydreg.h:676
#define ZYD_CR138
Definition: if_zydreg.h:313
#define ZYD_TX_FLAG_MULTICAST
Definition: if_zydreg.h:1037
#define ZYD_GCT_VCO
Definition: if_zydreg.h:871
#define ZYD_REG32_HI(reg)
Definition: if_zydreg.h:1117
#define ZYD_TAG_MULTIFRAME
Definition: if_zydreg.h:1088
#define ZYD_CMD_FLAG_SENT
Definition: if_zydreg.h:1150
#define ZYD_RF_DATA
Definition: if_zydreg.h:1098
#define ZYD_EEPROM_PWR_INT
Definition: if_zydreg.h:129
#define ZYD_RF_IF_LE
Definition: if_zydreg.h:1096
#define ZYD_RX_ERROR
Definition: if_zydreg.h:1080
#define ZYD_FW_LINK_STATUS
Definition: if_zydreg.h:146
#define ZYD_DOWNLOADREQ
Definition: if_zydreg.h:980
#define ZYD_FILTER_HOSTAP
Definition: if_zydreg.h:1023
#define ZYD_CR_ADDA_MBIAS_WT
Definition: if_zydreg.h:45
#define ZYD_DOWNLOADSTS
Definition: if_zydreg.h:981
#define ZYD_MAC_CAM_MODE
Definition: if_zydreg.h:104
#define ZYD_FLAG_INITONCE
Definition: if_zydreg.h:1262
#define ZYD_MAC_BAS_RATE
Definition: if_zydreg.h:63
#define ZYD_CR_CONFIG_PHILIPS
Definition: if_zydreg.h:30
#define ZYD_CR18
Definition: if_zydreg.h:193
#define ZYD_TX_FLAG_RTS
Definition: if_zydreg.h:1044
#define ZYD_CR_RX_PE_DELAY
Definition: if_zydreg.h:39
#define ZYD_EEPROM_MAC_ADDR_P1
Definition: if_zydreg.h:126
#define ZYD_EEPROM_SUBID
Definition: if_zydreg.h:124
#define ZYD_EEPROM_PWR_CAL
Definition: if_zydreg.h:128
#define ZYD_MACB_TXPWR_CTL3
Definition: if_zydreg.h:107
#define ZYD_CONFIG_INDEX
Definition: if_zydreg.h:1129
#define ZYD_RF_AL7230B
Definition: if_zydreg.h:160
#define ZYD_MAC_RTSCTSRATE
Definition: if_zydreg.h:65
#define ZYD_MACB_TXPWR_CTL1
Definition: if_zydreg.h:105
#define ZYD_CR78
Definition: if_zydreg.h:253
#define ZYD_MAC_BACKOFF_PROTECT
Definition: if_zydreg.h:66
#define ZYD_MAXIM2_RF
Definition: if_zydreg.h:941
#define ZYD_MAC_BSSADRH
Definition: if_zydreg.h:58
#define ZYD_AL2230_RF_B_PART3
Definition: if_zydreg.h:705
#define ZYD_RF_AL2230S
Definition: if_zydreg.h:165
#define ZYD_AL2230_PHY_PART3
Definition: if_zydreg.h:651
#define ZYD_VAP(vap)
Definition: if_zydreg.h:1241
#define ZYD_MAC_MACADRL
Definition: if_zydreg.h:55
#define ZYD_FLAG_FWLOADED
Definition: if_zydreg.h:1261
#define ZYD_AL2230S_PHY_INIT
Definition: if_zydreg.h:656
#define ZYD_MACB_TXPWR_CTL4
Definition: if_zydreg.h:108
#define ZYD_CR_BCN_INTERVAL
Definition: if_zydreg.h:49
#define ZYD_FW_FIRMWARE_REV
Definition: if_zydreg.h:143
#define ZYD_MACB_AIFS_CTL1
Definition: if_zydreg.h:109
#define ZYD_MACB_TXPWR_CTL2
Definition: if_zydreg.h:106
#define ZYD_RF_AL2210
Definition: if_zydreg.h:162
#define ZYD_MAC_SIFS_ACK_TIME
Definition: if_zydreg.h:73
#define ZYD_FIRMWARE_BASE_ADDR
Definition: if_zydreg.h:118
#define ZYD_CMD_IORD
Definition: if_zydreg.h:1104
#define ZYD_MAXIM2_PHY
Definition: if_zydreg.h:914
#define ZYD_FLAG_DETACHED
Definition: if_zydreg.h:1264
#define ZYD_MACB_TXOP
Definition: if_zydreg.h:111
#define ZYD_AL7230B_CHANTABLE
Definition: if_zydreg.h:798
#define ZYD_CR38
Definition: if_zydreg.h:213
#define ZYD_CR242
Definition: if_zydreg.h:414
#define ZYD_AL7230B_RF_1
Definition: if_zydreg.h:780
#define ZYD_AL2230_PHY_FINI_PART1
Definition: if_zydreg.h:664
#define ZYD_RFMD_RF
Definition: if_zydreg.h:568
#define ZYD_TX_FLAG_CTS_TO_SELF
Definition: if_zydreg.h:1046
#define ZYD_PLCP_LENGEXT
Definition: if_zydreg.h:1050
#define ZYD_CR251
Definition: if_zydreg.h:418
#define ZYD_MAC_MISC
Definition: if_zydreg.h:80
#define ZYD_MAC_GHTBH
Definition: if_zydreg.h:61
#define ZYD_MAXIM2_CHANTABLE
Definition: if_zydreg.h:953
#define ZYD_CR240
Definition: if_zydreg.h:412
#define ZYD_AL2230_RF_B_PART1
Definition: if_zydreg.h:694
#define ZYD_CR243
Definition: if_zydreg.h:415
#define ZYD_CR69
Definition: if_zydreg.h:244
#define ZYD_REG32_LO(reg)
Definition: if_zydreg.h:1116
#define ZYD_UNLOCK_PHY_REGS
Definition: if_zydreg.h:988
#define ZYD_DEF_PHY
Definition: if_zydreg.h:425
#define ZYD_MIN_FRAGSZ
Definition: if_zydreg.h:1137
#define ZYD_TX_PHY_OFDM
Definition: if_zydreg.h:1031
#define ZYD_UNLOCK(sc)
Definition: if_zydreg.h:1313
#define ZYD_CR11
Definition: if_zydreg.h:186
#define ZYD_HWINT_MASK
Definition: if_zydreg.h:985
#define ZYD_MAC_DIFS_EIFS_SIFS
Definition: if_zydreg.h:86
#define ZYD_NOTIF_RETRYSTATUS
Definition: if_zydreg.h:1108
#define ZYD_CMD_RFCFG
Definition: if_zydreg.h:1105
#define ZYD_RF_MAXIM_NEW
Definition: if_zydreg.h:163
#define ZYD_CR_PS_CTRL
Definition: if_zydreg.h:43
#define ZYD_CR31
Definition: if_zydreg.h:206
#define ZYD_AL2230_PHY
Definition: if_zydreg.h:593
#define ZYD_CR68
Definition: if_zydreg.h:243
#define ZYD_CR130
Definition: if_zydreg.h:305
#define ZYD_AL2210_PHY
Definition: if_zydreg.h:816
#define ZYD_MAC_RXFILTER
Definition: if_zydreg.h:83
#define ZYD_RX_BADCRC32
Definition: if_zydreg.h:1077
#define ZYD_MAC_MACADRH
Definition: if_zydreg.h:56
#define ZYD_AL7230B_PHY_2
Definition: if_zydreg.h:769
#define ZYD_CR_GPI_EN
Definition: if_zydreg.h:26
#define ZYD_CR157
Definition: if_zydreg.h:332
#define ZYD_FLAG_RUNNING
Definition: if_zydreg.h:1265
#define ZYD_FILTER_BSS
Definition: if_zydreg.h:1014
#define ZYD_RX_OFDM
Definition: if_zydreg.h:1073
#define ZYD_AL2230_PHY_B
Definition: if_zydreg.h:616
#define ZYD_RX_DECRYPTERR
Definition: if_zydreg.h:1076
#define ZYD_TX_TYPE_PS_POLL
Definition: if_zydreg.h:1040
#define ZYD_EEPROM_POD
Definition: if_zydreg.h:125
#define ZYD_CR136
Definition: if_zydreg.h:311
#define ZYD_EEPROM_PHY_REG
Definition: if_zydreg.h:132
#define ZYD_MAC_AFTER_PNP
Definition: if_zydreg.h:69
#define ZYD_TX_LIST_CNT
Definition: if_zydreg.h:1148
#define ZYD_CR12
Definition: if_zydreg.h:187
#define ZYD_GCT_CHANNEL_STD
Definition: if_zydreg.h:900
#define ZYD_CR10
Definition: if_zydreg.h:185
uint32_t value
uint16_t data
enum pci_id_type type
const char * name
int * count
device_t dev
uint64_t * addr
Definition: if_rum.c:347
enum usb_hc_mode usb_mode
Definition: usbdi.h:432
struct usbd_lookup_info info
Definition: usbdi.h:426
struct usb_device * device
Definition: usbdi.h:430
uByte bConfigurationValue
Definition: usb.h:390
uint8_t type
Definition: usbdi.h:238
uint8_t bIfaceIndex
Definition: usbdi.h:417
uint8_t bConfigIndex
Definition: usbdi.h:419
uint16_t bcdDevice
Definition: usbdi.h:410
uint8_t data[64]
Definition: if_zydreg.h:1109
uint16_t code
Definition: if_zydreg.h:1102
uint16_t count
Definition: if_zydreg.h:1126
uint16_t val
Definition: if_zydreg.h:1119
uint16_t reg
Definition: if_zydreg.h:1114
uint8_t val
Definition: if_zydreg.h:1157
uint16_t reg
Definition: if_zydreg.h:1156
uint8_t signal
Definition: if_zydreg.h:1055
int(* init)(struct zyd_rf *)
Definition: if_zydreg.h:1214
int idx
Definition: if_zydreg.h:1222
struct zyd_softc * rf_sc
Definition: if_zydreg.h:1220
int width
Definition: if_zydreg.h:1221
int(* set_channel)(struct zyd_rf *, uint8_t)
Definition: if_zydreg.h:1216
int(* bandedge6)(struct zyd_rf *, struct ieee80211_channel *)
Definition: if_zydreg.h:1217
int(* switch_radio)(struct zyd_rf *, int)
Definition: if_zydreg.h:1215
int update_pwr
Definition: if_zydreg.h:1223
struct zyd_cmd * cmd
Definition: if_zydreg.h:1227
int flags
Definition: if_zydreg.h:1232
int olen
Definition: if_zydreg.h:1231
struct zyd_pair * odata
Definition: if_zydreg.h:1229
const uint16_t * idata
Definition: if_zydreg.h:1228
int ilen
Definition: if_zydreg.h:1230
struct mbuf * m
Definition: if_zydreg.h:1176
struct ieee80211_radiotap_header wr_ihdr
Definition: if_zydreg.h:1181
uint8_t rssi
Definition: if_zydreg.h:1062
uint8_t flags
Definition: if_zydreg.h:1072
uint32_t sc_pre_tbtt
Definition: if_zydreg.h:1287
uint8_t sc_parev
Definition: if_zydreg.h:1277
struct ieee80211_ratectl_tx_status sc_txs
Definition: if_zydreg.h:1253
uint8_t sc_newphy
Definition: if_zydreg.h:1280
uint8_t sc_txled
Definition: if_zydreg.h:1284
uint8_t sc_pwrint[14]
Definition: if_zydreg.h:1291
uint8_t sc_ofdm48_cal[14]
Definition: if_zydreg.h:1293
int sc_rx_count
Definition: if_zydreg.h:1304
uint8_t sc_regdomain
Definition: if_zydreg.h:1273
struct mtx sc_mtx
Definition: if_zydreg.h:1297
struct zyd_rx_radiotap_header sc_rxtap
Definition: if_zydreg.h:1308
zyd_txdhead tx_free
Definition: if_zydreg.h:1300
uint8_t sc_ofdm36_cal[14]
Definition: if_zydreg.h:1292
struct zyd_rx_data sc_rx_data[ZYD_MAX_RXFRAMECNT]
Definition: if_zydreg.h:1303
uint8_t sc_al2230s
Definition: if_zydreg.h:1278
uint16_t sc_fwbase
Definition: if_zydreg.h:1272
uint8_t sc_fix_cr157
Definition: if_zydreg.h:1282
struct ieee80211com sc_ic
Definition: if_zydreg.h:1252
struct zyd_tx_radiotap_header sc_txtap
Definition: if_zydreg.h:1309
struct zyd_rf sc_rf
Definition: if_zydreg.h:1267
struct usb_xfer * sc_xfer[ZYD_N_TRANSFER]
Definition: if_zydreg.h:1258
device_t sc_dev
Definition: if_zydreg.h:1255
struct mbufq sc_snd
Definition: if_zydreg.h:1254
uint8_t sc_pwrcal[14]
Definition: if_zydreg.h:1290
uint8_t sc_ofdm54_cal[14]
Definition: if_zydreg.h:1294
uint8_t sc_macrev
Definition: if_zydreg.h:1274
uint8_t sc_rfrev
Definition: if_zydreg.h:1276
struct zyd_cmd sc_ibuf
Definition: if_zydreg.h:1306
uint32_t sc_bcn_int
Definition: if_zydreg.h:1288
uint8_t sc_cckgain
Definition: if_zydreg.h:1281
int sc_flags
Definition: if_zydreg.h:1260
struct zyd_tx_data tx_data[ZYD_TX_LIST_CNT]
Definition: if_zydreg.h:1298
uint32_t sc_atim_wnd
Definition: if_zydreg.h:1286
int tx_nfree
Definition: if_zydreg.h:1301
uint8_t sc_bssid[IEEE80211_ADDR_LEN]
Definition: if_zydreg.h:1295
uint8_t sc_ledtype
Definition: if_zydreg.h:1283
zyd_txdhead tx_q
Definition: if_zydreg.h:1299
uint8_t sc_bandedge6
Definition: if_zydreg.h:1279
struct usb_device * sc_udev
Definition: if_zydreg.h:1256
uint16_t sc_fwrev
Definition: if_zydreg.h:1275
struct zyd_softc * sc
Definition: if_zydreg.h:1167
struct ieee80211_radiotap_header wt_ihdr
Definition: if_zydreg.h:1198
struct ieee80211vap vap
Definition: if_zydreg.h:1237
int(* newstate)(struct ieee80211vap *, enum ieee80211_state, int)
Definition: if_zydreg.h:1238
#define UE_INTERRUPT
Definition: usb.h:544
#define UE_ADDR_ANY
Definition: usb.h:537
#define UE_BULK
Definition: usb.h:543
#define UE_BULK_INTR
Definition: usb.h:545
#define UT_WRITE_VENDOR_DEVICE
Definition: usb.h:184
#define UT_READ_VENDOR_DEVICE
Definition: usb.h:180
#define UE_DIR_IN
Definition: usb.h:531
#define UE_DIR_OUT
Definition: usb.h:532
@ USB_MODE_HOST
Definition: usb.h:778
void usbd_copy_in(struct usb_page_cache *cache, usb_frlength_t offset, const void *ptr, usb_frlength_t len)
Definition: usb_busdma.c:166
void usbd_copy_out(struct usb_page_cache *cache, usb_frlength_t offset, void *ptr, usb_frlength_t len)
Definition: usb_busdma.c:283
struct usb_config_descriptor * usbd_get_config_descriptor(struct usb_device *udev)
Definition: usb_device.c:2616
struct usb_endpoint_descriptor desc
Definition: usb_device.h:0
#define USETW(w, v)
Definition: usb_endian.h:77
#define UGETW(w)
Definition: usb_endian.h:53
const char * usbd_errstr(usb_error_t err)
Definition: usb_error.c:93
uint16_t offset
Definition: usb_if.m:54
const void * req
Definition: usb_if.m:51
INTERFACE usb
Definition: usb_if.m:35
int usbd_lookup_id_by_uaa(const struct usb_device_id *id, usb_size_t sizeof_id, struct usb_attach_arg *uaa)
Definition: usb_lookup.c:143
usb_error_t usbd_req_set_config(struct usb_device *udev, struct mtx *mtx, uint8_t conf)
Definition: usb_request.c:1920
void usbd_transfer_submit(struct usb_xfer *xfer)
void * usbd_xfer_get_priv(struct usb_xfer *xfer)
void usbd_transfer_unsetup(struct usb_xfer **pxfer, uint16_t n_setup)
void usbd_xfer_set_frame_len(struct usb_xfer *xfer, usb_frcount_t frindex, usb_frlength_t len)
struct usb_page_cache * usbd_xfer_get_frame(struct usb_xfer *xfer, usb_frcount_t frindex)
usb_error_t usbd_transfer_setup(struct usb_device *udev, const uint8_t *ifaces, struct usb_xfer **ppxfer, const struct usb_config *setup_start, uint16_t n_setup, void *priv_sc, struct mtx *xfer_mtx)
Definition: usb_transfer.c:987
void usbd_transfer_start(struct usb_xfer *xfer)
void usbd_xfer_set_priv(struct usb_xfer *xfer, void *ptr)
void usbd_transfer_drain(struct usb_xfer *xfer)
void * usbd_xfer_softc(struct usb_xfer *xfer)
void usbd_xfer_set_stall(struct usb_xfer *xfer)
void usbd_xfer_status(struct usb_xfer *xfer, int *actlen, int *sumlen, int *aframes, int *nframes)
usb_frlength_t usbd_xfer_max_len(struct usb_xfer *xfer)
void device_set_usb_desc(device_t dev)
Definition: usb_util.c:73
#define USB_ST_SETUP
Definition: usbdi.h:502
usb_error_t
Definition: usbdi.h:45
@ USB_ERR_CANCELLED
Definition: usbdi.h:51
@ USB_ERR_TIMEOUT
Definition: usbdi.h:66
#define USB_ST_TRANSFERRED
Definition: usbdi.h:503
void usbd_m_copy_in(struct usb_page_cache *cache, usb_frlength_t dst_offset, struct mbuf *m, usb_size_t src_offset, usb_frlength_t src_len)
void() usb_callback_t(struct usb_xfer *, usb_error_t)
Definition: usbdi.h:94
#define STRUCT_USB_HOST_ID
Definition: usbdi.h:258
#define USB_GET_DRIVER_INFO(did)
Definition: usbdi.h:400
#define USB_GET_STATE(xfer)
Definition: usbdi.h:515