Lines Matching +full:reg +full:- +full:init

4 /*-
6 * Copyright (c) 2006 by Florian Stoehr <ich@florian-stoehr.de>
86 ZYD_DEBUG_INIT = 0x00000008, /* device init */
106 usbd_do_request_flags((sc)->sc_udev, &(sc)->sc_mtx, req, data, 0, NULL, 5000)
319 if (uaa->usb_mode != USB_MODE_HOST) in zyd_match()
321 if (uaa->info.bConfigIndex != ZYD_CONFIG_INDEX) in zyd_match()
323 if (uaa->info.bIfaceIndex != ZYD_IFACE_INDEX) in zyd_match()
334 struct ieee80211com *ic = &sc->sc_ic; in zyd_attach()
338 if (uaa->info.bcdDevice < 0x4330) { in zyd_attach()
341 uaa->info.bcdDevice); in zyd_attach()
346 sc->sc_dev = dev; in zyd_attach()
347 sc->sc_udev = uaa->device; in zyd_attach()
348 sc->sc_macrev = USB_GET_DRIVER_INFO(uaa); in zyd_attach()
350 mtx_init(&sc->sc_mtx, device_get_nameunit(sc->sc_dev), in zyd_attach()
352 STAILQ_INIT(&sc->sc_rqh); in zyd_attach()
353 mbufq_init(&sc->sc_snd, ifqmaxlen); in zyd_attach()
356 error = usbd_transfer_setup(uaa->device, in zyd_attach()
357 &iface_index, sc->sc_xfer, zyd_config, in zyd_attach()
358 ZYD_N_TRANSFER, sc, &sc->sc_mtx); in zyd_attach()
367 device_printf(sc->sc_dev, "could not read EEPROM\n"); in zyd_attach()
373 ic->ic_softc = sc; in zyd_attach()
374 ic->ic_name = device_get_nameunit(dev); in zyd_attach()
375 ic->ic_phytype = IEEE80211_T_OFDM; /* not only, but not used */ in zyd_attach()
376 ic->ic_opmode = IEEE80211_M_STA; in zyd_attach()
379 ic->ic_caps = in zyd_attach()
388 zyd_getradiocaps(ic, IEEE80211_CHAN_MAX, &ic->ic_nchans, in zyd_attach()
389 ic->ic_channels); in zyd_attach()
392 ic->ic_raw_xmit = zyd_raw_xmit; in zyd_attach()
393 ic->ic_scan_start = zyd_scan_start; in zyd_attach()
394 ic->ic_scan_end = zyd_scan_end; in zyd_attach()
395 ic->ic_getradiocaps = zyd_getradiocaps; in zyd_attach()
396 ic->ic_set_channel = zyd_set_channel; in zyd_attach()
397 ic->ic_vap_create = zyd_vap_create; in zyd_attach()
398 ic->ic_vap_delete = zyd_vap_delete; in zyd_attach()
399 ic->ic_update_mcast = zyd_update_mcast; in zyd_attach()
400 ic->ic_update_promisc = zyd_update_mcast; in zyd_attach()
401 ic->ic_parent = zyd_parent; in zyd_attach()
402 ic->ic_transmit = zyd_transmit; in zyd_attach()
405 &sc->sc_txtap.wt_ihdr, sizeof(sc->sc_txtap), in zyd_attach()
407 &sc->sc_rxtap.wr_ihdr, sizeof(sc->sc_rxtap), in zyd_attach()
427 while ((m = mbufq_dequeue(&sc->sc_snd)) != NULL) { in zyd_drain_mbufq()
428 ni = (struct ieee80211_node *)m->m_pkthdr.rcvif; in zyd_drain_mbufq()
429 m->m_pkthdr.rcvif = NULL; in zyd_drain_mbufq()
439 struct ieee80211com *ic = &sc->sc_ic; in zyd_detach()
447 sc->sc_flags |= ZYD_FLAG_DETACHED; in zyd_detach()
449 STAILQ_INIT(&sc->tx_q); in zyd_detach()
450 STAILQ_INIT(&sc->tx_free); in zyd_detach()
455 usbd_transfer_drain(sc->sc_xfer[x]); in zyd_detach()
463 usbd_transfer_unsetup(sc->sc_xfer, ZYD_N_TRANSFER); in zyd_detach()
465 if (ic->ic_softc == sc) in zyd_detach()
467 mtx_destroy(&sc->sc_mtx); in zyd_detach()
481 if (!TAILQ_EMPTY(&ic->ic_vaps)) /* only one at a time */ in zyd_vap_create()
484 vap = &zvp->vap; in zyd_vap_create()
495 zvp->newstate = vap->iv_newstate; in zyd_vap_create()
496 vap->iv_newstate = zyd_newstate; in zyd_vap_create()
504 ic->ic_opmode = opmode; in zyd_vap_create()
521 struct zyd_softc *sc = data->sc; in zyd_tx_free()
523 if (data->m != NULL) { in zyd_tx_free()
524 ieee80211_tx_complete(data->ni, data->m, txerr); in zyd_tx_free()
525 data->m = NULL; in zyd_tx_free()
526 data->ni = NULL; in zyd_tx_free()
528 STAILQ_INSERT_TAIL(&sc->tx_free, data, next); in zyd_tx_free()
529 sc->tx_nfree++; in zyd_tx_free()
538 sc->tx_nfree = 0; in zyd_setup_tx_list()
539 STAILQ_INIT(&sc->tx_q); in zyd_setup_tx_list()
540 STAILQ_INIT(&sc->tx_free); in zyd_setup_tx_list()
543 data = &sc->tx_data[i]; in zyd_setup_tx_list()
545 data->sc = sc; in zyd_setup_tx_list()
546 STAILQ_INSERT_TAIL(&sc->tx_free, data, next); in zyd_setup_tx_list()
547 sc->tx_nfree++; in zyd_setup_tx_list()
558 sc->tx_nfree = 0; in zyd_unsetup_tx_list()
559 STAILQ_INIT(&sc->tx_q); in zyd_unsetup_tx_list()
560 STAILQ_INIT(&sc->tx_free); in zyd_unsetup_tx_list()
564 data = &sc->tx_data[i]; in zyd_unsetup_tx_list()
566 if (data->m != NULL) { in zyd_unsetup_tx_list()
567 m_freem(data->m); in zyd_unsetup_tx_list()
568 data->m = NULL; in zyd_unsetup_tx_list()
570 if (data->ni != NULL) { in zyd_unsetup_tx_list()
571 ieee80211_free_node(data->ni); in zyd_unsetup_tx_list()
572 data->ni = NULL; in zyd_unsetup_tx_list()
581 struct ieee80211com *ic = vap->iv_ic; in zyd_newstate()
582 struct zyd_softc *sc = ic->ic_softc; in zyd_newstate()
585 DPRINTF(sc, ZYD_DEBUG_STATE, "%s: %s -> %s\n", __func__, in zyd_newstate()
586 ieee80211_state_name[vap->iv_state], in zyd_newstate()
593 zyd_set_chan(sc, ic->ic_curchan); in zyd_newstate()
596 if (vap->iv_opmode == IEEE80211_M_MONITOR) in zyd_newstate()
605 zyd_write32_m(sc, sc->sc_fwbase + ZYD_FW_LINK_STATUS, 1); in zyd_newstate()
607 IEEE80211_ADDR_COPY(sc->sc_bssid, vap->iv_bss->ni_bssid); in zyd_newstate()
608 zyd_set_bssid(sc, sc->sc_bssid); in zyd_newstate()
616 return (zvp->newstate(vap, nstate, arg)); in zyd_newstate()
626 struct ieee80211com *ic = &sc->sc_ic; in zyd_intr_read_callback()
627 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps); in zyd_intr_read_callback()
629 struct zyd_cmd *cmd = &sc->sc_ibuf; in zyd_intr_read_callback()
641 switch (le16toh(cmd->code)) { in zyd_intr_read_callback()
645 (struct zyd_notif_retry *)cmd->data; in zyd_intr_read_callback()
646 uint16_t count = le16toh(retry->count); in zyd_intr_read_callback()
650 le16toh(retry->rate), ether_sprintf(retry->macaddr), in zyd_intr_read_callback()
659 ni = ieee80211_find_txnode(vap, retry->macaddr); in zyd_intr_read_callback()
662 &sc->sc_txs; in zyd_intr_read_callback()
665 txs->flags = in zyd_intr_read_callback()
667 txs->long_retries = retrycnt; in zyd_intr_read_callback()
669 txs->status = in zyd_intr_read_callback()
672 txs->status = in zyd_intr_read_callback()
681 if_inc_counter(vap->iv_ifp, IFCOUNTER_OERRORS, in zyd_intr_read_callback()
689 if (le16toh(*(uint16_t *)cmd->data) == ZYD_CR_INTERRUPT) in zyd_intr_read_callback()
692 datalen = actlen - sizeof(cmd->code); in zyd_intr_read_callback()
693 datalen -= 2; /* XXX: padding? */ in zyd_intr_read_callback()
695 STAILQ_FOREACH(rqp, &sc->sc_rqh, rq) { in zyd_intr_read_callback()
699 if (rqp->olen != datalen) in zyd_intr_read_callback()
701 count = rqp->olen / sizeof(struct zyd_pair); in zyd_intr_read_callback()
703 if (*(((const uint16_t *)rqp->idata) + i) != in zyd_intr_read_callback()
704 (((struct zyd_pair *)cmd->data) + i)->reg) in zyd_intr_read_callback()
709 /* copy answer into caller-supplied buffer */ in zyd_intr_read_callback()
710 memcpy(rqp->odata, cmd->data, rqp->olen); in zyd_intr_read_callback()
713 rqp, rqp->olen, (char *)rqp->odata, ":"); in zyd_intr_read_callback()
718 device_printf(sc->sc_dev, in zyd_intr_read_callback()
720 datalen, cmd->data, ":"); in zyd_intr_read_callback()
725 device_printf(sc->sc_dev, "unknown notification %x\n", in zyd_intr_read_callback()
726 le16toh(cmd->code)); in zyd_intr_read_callback()
760 STAILQ_FOREACH(rqp, &sc->sc_rqh, rq) { in zyd_intr_write_callback()
763 (rqp->flags & ZYD_CMD_FLAG_READ) == 0) in zyd_intr_write_callback()
770 STAILQ_FOREACH(rqp, &sc->sc_rqh, rq) { in zyd_intr_write_callback()
771 if (rqp->flags & ZYD_CMD_FLAG_SENT) in zyd_intr_write_callback()
775 usbd_copy_in(pc, 0, rqp->cmd, rqp->ilen); in zyd_intr_write_callback()
777 usbd_xfer_set_frame_len(xfer, 0, rqp->ilen); in zyd_intr_write_callback()
779 rqp->flags |= ZYD_CMD_FLAG_SENT; in zyd_intr_write_callback()
820 STAILQ_INSERT_TAIL(&sc->sc_rqh, &rq, rq); in zyd_cmd()
821 usbd_transfer_start(sc->sc_xfer[ZYD_INTR_RD]); in zyd_cmd()
822 usbd_transfer_start(sc->sc_xfer[ZYD_INTR_WR]); in zyd_cmd()
825 error = mtx_sleep(&rq, &sc->sc_mtx, 0 , "zydcmd", hz); in zyd_cmd()
827 device_printf(sc->sc_dev, "command timeout\n"); in zyd_cmd()
828 STAILQ_REMOVE(&sc->sc_rqh, &rq, zyd_rq, rq); in zyd_cmd()
836 zyd_read16(struct zyd_softc *sc, uint16_t reg, uint16_t *val) in zyd_read16() argument
841 reg = htole16(reg); in zyd_read16()
842 error = zyd_cmd(sc, ZYD_CMD_IORD, &reg, sizeof(reg), &tmp, sizeof(tmp), in zyd_read16()
850 zyd_read32(struct zyd_softc *sc, uint16_t reg, uint32_t *val) in zyd_read32() argument
856 regs[0] = htole16(ZYD_REG32_HI(reg)); in zyd_read32()
857 regs[1] = htole16(ZYD_REG32_LO(reg)); in zyd_read32()
866 zyd_write16(struct zyd_softc *sc, uint16_t reg, uint16_t val) in zyd_write16() argument
870 pair.reg = htole16(reg); in zyd_write16()
877 zyd_write32(struct zyd_softc *sc, uint16_t reg, uint32_t val) in zyd_write32() argument
881 pair[0].reg = htole16(ZYD_REG32_HI(reg)); in zyd_write32()
883 pair[1].reg = htole16(ZYD_REG32_LO(reg)); in zyd_write32()
892 struct zyd_rf *rf = &sc->sc_rf; in zyd_rfwrite()
901 req.width = htole16(rf->width); in zyd_rfwrite()
902 for (i = 0; i < rf->width; i++) { in zyd_rfwrite()
904 if (val & (1 << (rf->width - 1 - i))) in zyd_rfwrite()
907 error = zyd_cmd(sc, ZYD_CMD_RFCFG, &req, 4 + 2 * rf->width, NULL, 0, 0); in zyd_rfwrite()
956 struct zyd_softc *sc = rf->rf_sc; in zyd_rfmd_init()
961 /* init RF-dependent PHY registers */ in zyd_rfmd_init()
963 zyd_write16_m(sc, phyini[i].reg, phyini[i].val); in zyd_rfmd_init()
966 /* init RFMD radio */ in zyd_rfmd_init()
979 struct zyd_softc *sc = rf->rf_sc; in zyd_rfmd_switch_radio()
991 struct zyd_softc *sc = rf->rf_sc; in zyd_rfmd_set_channel()
996 error = zyd_rfwrite(sc, rfprog[chan - 1].r1); in zyd_rfmd_set_channel()
999 error = zyd_rfwrite(sc, rfprog[chan - 1].r2); in zyd_rfmd_set_channel()
1013 struct zyd_softc *sc = rf->rf_sc; in zyd_al2230_init()
1025 /* init RF-dependent PHY registers */ in zyd_al2230_init()
1027 zyd_write16_m(sc, phyini[i].reg, phyini[i].val); in zyd_al2230_init()
1029 if (sc->sc_rfrev == ZYD_RF_AL2230S || sc->sc_al2230s != 0) { in zyd_al2230_init()
1031 zyd_write16_m(sc, phy2230s[i].reg, phy2230s[i].val); in zyd_al2230_init()
1034 /* init AL2230 radio */ in zyd_al2230_init()
1041 if (sc->sc_rfrev == ZYD_RF_AL2230S || sc->sc_al2230s != 0) in zyd_al2230_init()
1055 zyd_write16_m(sc, phypll[i].reg, phypll[i].val); in zyd_al2230_init()
1070 struct zyd_softc *sc = rf->rf_sc; in zyd_al2230_fini()
1074 zyd_write16_m(sc, phy[i].reg, phy[i].val); in zyd_al2230_fini()
1076 if (sc->sc_newphy != 0) in zyd_al2230_fini()
1087 struct zyd_softc *sc = rf->rf_sc; in zyd_al2230_init_b()
1100 zyd_write16_m(sc, phy1[i].reg, phy1[i].val); in zyd_al2230_init_b()
1102 /* init RF-dependent PHY registers */ in zyd_al2230_init_b()
1104 zyd_write16_m(sc, phyini[i].reg, phyini[i].val); in zyd_al2230_init_b()
1106 if (sc->sc_rfrev == ZYD_RF_AL2230S || sc->sc_al2230s != 0) { in zyd_al2230_init_b()
1108 zyd_write16_m(sc, phy2230s[i].reg, phy2230s[i].val); in zyd_al2230_init_b()
1123 if (sc->sc_rfrev == ZYD_RF_AL2230S || sc->sc_al2230s != 0) in zyd_al2230_init_b()
1137 zyd_write16_m(sc, phy2[i].reg, phy2[i].val); in zyd_al2230_init_b()
1146 zyd_write16_m(sc, phy3[i].reg, phy3[i].val); in zyd_al2230_init_b()
1156 struct zyd_softc *sc = rf->rf_sc; in zyd_al2230_switch_radio()
1157 int error, on251 = (sc->sc_macrev == ZYD_ZD1211) ? 0x3f : 0x7f; in zyd_al2230_switch_radio()
1169 struct zyd_softc *sc = rf->rf_sc; in zyd_al2230_set_channel()
1177 error = zyd_rfwrite(sc, rfprog[chan - 1].r1); in zyd_al2230_set_channel()
1180 error = zyd_rfwrite(sc, rfprog[chan - 1].r2); in zyd_al2230_set_channel()
1183 error = zyd_rfwrite(sc, rfprog[chan - 1].r3); in zyd_al2230_set_channel()
1188 zyd_write16_m(sc, phy1[i].reg, phy1[i].val); in zyd_al2230_set_channel()
1197 struct zyd_softc *sc = rf->rf_sc; in zyd_al2230_set_channel_b()
1204 zyd_write16_m(sc, phy1[i].reg, phy1[i].val); in zyd_al2230_set_channel_b()
1206 error = zyd_rfwrite_cr(sc, rfprog[chan - 1].r1); in zyd_al2230_set_channel_b()
1209 error = zyd_rfwrite_cr(sc, rfprog[chan - 1].r2); in zyd_al2230_set_channel_b()
1212 error = zyd_rfwrite_cr(sc, rfprog[chan - 1].r3); in zyd_al2230_set_channel_b()
1230 struct zyd_softc *sc = rf->rf_sc; in zyd_al2230_bandedge6()
1231 struct ieee80211com *ic = &sc->sc_ic; in zyd_al2230_bandedge6()
1239 zyd_write16_m(sc, r[i].reg, r[i].val); in zyd_al2230_bandedge6()
1250 struct zyd_softc *sc = rf->rf_sc; in zyd_al7230B_init()
1260 /* init RF-dependent PHY registers, part one */ in zyd_al7230B_init()
1262 zyd_write16_m(sc, phyini_1[i].reg, phyini_1[i].val); in zyd_al7230B_init()
1264 /* init AL7230B radio, part one */ in zyd_al7230B_init()
1269 /* init RF-dependent PHY registers, part two */ in zyd_al7230B_init()
1271 zyd_write16_m(sc, phyini_2[i].reg, phyini_2[i].val); in zyd_al7230B_init()
1273 /* init AL7230B radio, part two */ in zyd_al7230B_init()
1278 /* init RF-dependent PHY registers, part three */ in zyd_al7230B_init()
1280 zyd_write16_m(sc, phyini_3[i].reg, phyini_3[i].val); in zyd_al7230B_init()
1289 struct zyd_softc *sc = rf->rf_sc; in zyd_al7230B_switch_radio()
1300 struct zyd_softc *sc = rf->rf_sc; in zyd_al7230B_set_channel()
1321 error = zyd_rfwrite(sc, rfprog[chan - 1].r1); in zyd_al7230B_set_channel()
1324 error = zyd_rfwrite(sc, rfprog[chan - 1].r2); in zyd_al7230B_set_channel()
1344 struct zyd_softc *sc = rf->rf_sc; in zyd_al2210_init()
1352 /* init RF-dependent PHY registers */ in zyd_al2210_init()
1354 zyd_write16_m(sc, phyini[i].reg, phyini[i].val); in zyd_al2210_init()
1356 /* init AL2210 radio */ in zyd_al2210_init()
1385 struct zyd_softc *sc = rf->rf_sc; in zyd_al2210_set_channel()
1399 error = zyd_rfwrite(sc, rfprog[chan - 1]); in zyd_al2210_set_channel()
1415 struct zyd_softc *sc = rf->rf_sc; in zyd_gct_init()
1419 int i, idx = -1, error; in zyd_gct_init()
1422 /* init RF-dependent PHY registers */ in zyd_gct_init()
1424 zyd_write16_m(sc, phyini[i].reg, phyini[i].val); in zyd_gct_init()
1426 /* init cgt radio */ in zyd_gct_init()
1436 for (i = 0; i < (int)(nitems(vco) - 1); i++) { in zyd_gct_init()
1450 if (idx == -1) { in zyd_gct_init()
1459 rf->idx = idx; in zyd_gct_init()
1469 struct zyd_softc *sc = rf->rf_sc; in zyd_gct_mode()
1485 int error, idx = chan - 1; in zyd_gct_set_channel_synth()
1486 struct zyd_softc *sc = rf->rf_sc; in zyd_gct_set_channel_synth()
1501 struct zyd_softc *sc = rf->rf_sc; in zyd_gct_write()
1510 struct zyd_softc *sc = rf->rf_sc; in zyd_gct_switch_radio()
1518 on ? ((sc->sc_macrev == ZYD_ZD1211B) ? 0x7f : 0x3f) : 0x2f); in zyd_gct_switch_radio()
1527 struct zyd_softc *sc = rf->rf_sc; in zyd_gct_set_channel()
1537 error = zyd_gct_write(rf, (rf->idx == -1) ? 0x6662 : in zyd_gct_set_channel()
1538 vco[rf->idx][((chan - 1) / 2)]); in zyd_gct_set_channel()
1545 zyd_write16_m(sc, cmd[i].reg, cmd[i].val); in zyd_gct_set_channel()
1557 struct zyd_softc *sc = rf->rf_sc; in zyd_gct_txgain()
1559 uint8_t idx = sc->sc_pwrint[chan - 1]; in zyd_gct_txgain()
1562 device_printf(sc->sc_dev, "could not set TX gain (%d %#x)\n", in zyd_gct_txgain()
1576 struct zyd_softc *sc = rf->rf_sc; in zyd_maxim2_init()
1582 /* init RF-dependent PHY registers */ in zyd_maxim2_init()
1584 zyd_write16_m(sc, phyini[i].reg, phyini[i].val); in zyd_maxim2_init()
1589 /* init maxim2 radio */ in zyd_maxim2_init()
1611 struct zyd_softc *sc = rf->rf_sc; in zyd_maxim2_set_channel()
1625 /* init RF-dependent PHY registers */ in zyd_maxim2_set_channel()
1627 zyd_write16_m(sc, phyini[i].reg, phyini[i].val); in zyd_maxim2_set_channel()
1633 error = zyd_rfwrite(sc, rfprog[chan - 1].r1); in zyd_maxim2_set_channel()
1636 error = zyd_rfwrite(sc, rfprog[chan - 1].r2); in zyd_maxim2_set_channel()
1640 /* init maxim2 radio - skipping the two first values */ in zyd_maxim2_set_channel()
1654 struct zyd_rf *rf = &sc->sc_rf; in zyd_rf_attach()
1656 rf->rf_sc = sc; in zyd_rf_attach()
1657 rf->update_pwr = 1; in zyd_rf_attach()
1661 rf->init = zyd_rfmd_init; in zyd_rf_attach()
1662 rf->switch_radio = zyd_rfmd_switch_radio; in zyd_rf_attach()
1663 rf->set_channel = zyd_rfmd_set_channel; in zyd_rf_attach()
1664 rf->width = 24; /* 24-bit RF values */ in zyd_rf_attach()
1668 if (sc->sc_macrev == ZYD_ZD1211B) { in zyd_rf_attach()
1669 rf->init = zyd_al2230_init_b; in zyd_rf_attach()
1670 rf->set_channel = zyd_al2230_set_channel_b; in zyd_rf_attach()
1672 rf->init = zyd_al2230_init; in zyd_rf_attach()
1673 rf->set_channel = zyd_al2230_set_channel; in zyd_rf_attach()
1675 rf->switch_radio = zyd_al2230_switch_radio; in zyd_rf_attach()
1676 rf->bandedge6 = zyd_al2230_bandedge6; in zyd_rf_attach()
1677 rf->width = 24; /* 24-bit RF values */ in zyd_rf_attach()
1680 rf->init = zyd_al7230B_init; in zyd_rf_attach()
1681 rf->switch_radio = zyd_al7230B_switch_radio; in zyd_rf_attach()
1682 rf->set_channel = zyd_al7230B_set_channel; in zyd_rf_attach()
1683 rf->width = 24; /* 24-bit RF values */ in zyd_rf_attach()
1686 rf->init = zyd_al2210_init; in zyd_rf_attach()
1687 rf->switch_radio = zyd_al2210_switch_radio; in zyd_rf_attach()
1688 rf->set_channel = zyd_al2210_set_channel; in zyd_rf_attach()
1689 rf->width = 24; /* 24-bit RF values */ in zyd_rf_attach()
1693 rf->init = zyd_gct_init; in zyd_rf_attach()
1694 rf->switch_radio = zyd_gct_switch_radio; in zyd_rf_attach()
1695 rf->set_channel = zyd_gct_set_channel; in zyd_rf_attach()
1696 rf->width = 24; /* 24-bit RF values */ in zyd_rf_attach()
1697 rf->update_pwr = 0; in zyd_rf_attach()
1700 rf->init = zyd_maxim2_init; in zyd_rf_attach()
1701 rf->switch_radio = zyd_maxim2_switch_radio; in zyd_rf_attach()
1702 rf->set_channel = zyd_maxim2_set_channel; in zyd_rf_attach()
1703 rf->width = 18; /* 18-bit RF values */ in zyd_rf_attach()
1706 device_printf(sc->sc_dev, in zyd_rf_attach()
1732 struct zyd_rf *rf = &sc->sc_rf; in zyd_hw_init()
1737 zyd_read16_m(sc, ZYD_FIRMWARE_BASE_ADDR, &sc->sc_fwbase); in zyd_hw_init()
1739 sc->sc_fwbase); in zyd_hw_init()
1742 zyd_read16_m(sc, sc->sc_fwbase + ZYD_FW_FIRMWARE_REV, &sc->sc_fwrev); in zyd_hw_init()
1745 /* set mandatory rates - XXX assumes 802.11b/g */ in zyd_hw_init()
1752 device_printf(sc->sc_dev, "could not read EEPROM\n"); in zyd_hw_init()
1756 /* PHY init (resetting) */ in zyd_hw_init()
1760 phyp = (sc->sc_macrev == ZYD_ZD1211B) ? zyd_def_phyB : zyd_def_phy; in zyd_hw_init()
1761 for (; phyp->reg != 0; phyp++) in zyd_hw_init()
1762 zyd_write16_m(sc, phyp->reg, phyp->val); in zyd_hw_init()
1763 if (sc->sc_macrev == ZYD_ZD1211 && sc->sc_fix_cr157 != 0) { in zyd_hw_init()
1771 /* HMAC init */ in zyd_hw_init()
1793 if (sc->sc_macrev == ZYD_ZD1211) { in zyd_hw_init()
1808 /* init beacon interval to 100ms */ in zyd_hw_init()
1812 if ((error = zyd_rf_attach(sc, sc->sc_rfrev)) != 0) { in zyd_hw_init()
1813 device_printf(sc->sc_dev, "could not attach RF, rev 0x%x\n", in zyd_hw_init()
1814 sc->sc_rfrev); in zyd_hw_init()
1818 /* RF chip init */ in zyd_hw_init()
1822 error = (*rf->init)(rf); in zyd_hw_init()
1824 device_printf(sc->sc_dev, in zyd_hw_init()
1833 device_printf(sc->sc_dev, "could not read EEPROM\n"); in zyd_hw_init()
1847 sc->sc_rfrev = tmp & 0x0f; in zyd_read_pod()
1848 sc->sc_ledtype = (tmp >> 4) & 0x01; in zyd_read_pod()
1849 sc->sc_al2230s = (tmp >> 7) & 0x01; in zyd_read_pod()
1850 sc->sc_cckgain = (tmp >> 8) & 0x01; in zyd_read_pod()
1851 sc->sc_fix_cr157 = (tmp >> 13) & 0x01; in zyd_read_pod()
1852 sc->sc_parev = (tmp >> 16) & 0x0f; in zyd_read_pod()
1853 sc->sc_bandedge6 = (tmp >> 21) & 0x01; in zyd_read_pod()
1854 sc->sc_newphy = (tmp >> 31) & 0x01; in zyd_read_pod()
1855 sc->sc_txled = ((tmp & (1 << 24)) && (tmp & (1 << 29))) ? 0 : 1; in zyd_read_pod()
1869 sc->sc_pwrcal[i * 2] = val >> 8; in zyd_read_eeprom()
1870 sc->sc_pwrcal[i * 2 + 1] = val & 0xff; in zyd_read_eeprom()
1872 sc->sc_pwrint[i * 2] = val >> 8; in zyd_read_eeprom()
1873 sc->sc_pwrint[i * 2 + 1] = val & 0xff; in zyd_read_eeprom()
1875 sc->sc_ofdm36_cal[i * 2] = val >> 8; in zyd_read_eeprom()
1876 sc->sc_ofdm36_cal[i * 2 + 1] = val & 0xff; in zyd_read_eeprom()
1878 sc->sc_ofdm48_cal[i * 2] = val >> 8; in zyd_read_eeprom()
1879 sc->sc_ofdm48_cal[i * 2 + 1] = val & 0xff; in zyd_read_eeprom()
1881 sc->sc_ofdm54_cal[i * 2] = val >> 8; in zyd_read_eeprom()
1882 sc->sc_ofdm54_cal[i * 2 + 1] = val & 0xff; in zyd_read_eeprom()
1900 error = zyd_do_request(sc, &req, sc->sc_ic.ic_macaddr); in zyd_get_macaddr()
1902 device_printf(sc->sc_dev, "could not read EEPROM: %s\n", in zyd_get_macaddr()
1940 struct zyd_rf *rf = &sc->sc_rf; in zyd_switch_radio()
1946 error = (*rf->switch_radio)(rf, on); in zyd_switch_radio()
1979 hash[1] |= 1 << (v - 32); in zyd_hash_maddr()
1987 struct ieee80211com *ic = &sc->sc_ic; in zyd_set_multi()
1991 if ((sc->sc_flags & ZYD_FLAG_RUNNING) == 0) in zyd_set_multi()
1997 if (ic->ic_opmode == IEEE80211_M_MONITOR || ic->ic_allmulti > 0 || in zyd_set_multi()
1998 ic->ic_promisc > 0) { in zyd_set_multi()
2004 TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next) in zyd_set_multi()
2005 if_foreach_llmaddr(vap->iv_ifp, zyd_hash_maddr, &hash); in zyd_set_multi()
2013 device_printf(sc->sc_dev, in zyd_set_multi()
2020 struct zyd_softc *sc = ic->ic_softc; in zyd_update_mcast()
2030 struct ieee80211com *ic = &sc->sc_ic; in zyd_set_rxfilter()
2033 switch (ic->ic_opmode) { in zyd_set_rxfilter()
2055 struct ieee80211com *ic = &sc->sc_ic; in zyd_set_chan()
2056 struct zyd_rf *rf = &sc->sc_rf; in zyd_set_chan()
2063 device_printf(sc->sc_dev, in zyd_set_chan()
2072 error = (*rf->set_channel)(rf, chan); in zyd_set_chan()
2076 if (rf->update_pwr) { in zyd_set_chan()
2078 zyd_write16_m(sc, ZYD_CR31, sc->sc_pwrint[chan - 1]); in zyd_set_chan()
2080 if (sc->sc_macrev == ZYD_ZD1211B) { in zyd_set_chan()
2082 sc->sc_ofdm36_cal[chan - 1]); in zyd_set_chan()
2084 sc->sc_ofdm48_cal[chan - 1]); in zyd_set_chan()
2086 sc->sc_ofdm54_cal[chan - 1]); in zyd_set_chan()
2087 zyd_write16_m(sc, ZYD_CR68, sc->sc_pwrcal[chan - 1]); in zyd_set_chan()
2092 if (sc->sc_cckgain) { in zyd_set_chan()
2097 if (sc->sc_bandedge6 && rf->bandedge6 != NULL) { in zyd_set_chan()
2098 error = (*rf->bandedge6)(rf, c); in zyd_set_chan()
2108 sc->sc_rxtap.wr_chan_freq = sc->sc_txtap.wt_chan_freq = in zyd_set_chan()
2109 htole16(c->ic_freq); in zyd_set_chan()
2110 sc->sc_rxtap.wr_chan_flags = sc->sc_txtap.wt_chan_flags = in zyd_set_chan()
2111 htole16(c->ic_flags); in zyd_set_chan()
2123 sc->sc_atim_wnd = val; in zyd_set_beacon_interval()
2125 sc->sc_pre_tbtt = val; in zyd_set_beacon_interval()
2126 sc->sc_bcn_int = bintval; in zyd_set_beacon_interval()
2128 if (sc->sc_bcn_int <= 5) in zyd_set_beacon_interval()
2129 sc->sc_bcn_int = 5; in zyd_set_beacon_interval()
2130 if (sc->sc_pre_tbtt < 4 || sc->sc_pre_tbtt >= sc->sc_bcn_int) in zyd_set_beacon_interval()
2131 sc->sc_pre_tbtt = sc->sc_bcn_int - 1; in zyd_set_beacon_interval()
2132 if (sc->sc_atim_wnd >= sc->sc_pre_tbtt) in zyd_set_beacon_interval()
2133 sc->sc_atim_wnd = sc->sc_pre_tbtt - 1; in zyd_set_beacon_interval()
2135 zyd_write32_m(sc, ZYD_CR_ATIM_WND_PERIOD, sc->sc_atim_wnd); in zyd_set_beacon_interval()
2136 zyd_write32_m(sc, ZYD_CR_PRE_TBTT, sc->sc_pre_tbtt); in zyd_set_beacon_interval()
2137 zyd_write32_m(sc, ZYD_CR_BCN_INTERVAL, sc->sc_bcn_int); in zyd_set_beacon_interval()
2146 struct ieee80211com *ic = &sc->sc_ic; in zyd_rx_data()
2155 device_get_nameunit(sc->sc_dev), len); in zyd_rx_data()
2156 counter_u64_add(ic->ic_ierrors, 1); in zyd_rx_data()
2161 usbd_copy_out(pc, offset + len - sizeof(stat), &stat, sizeof(stat)); in zyd_rx_data()
2166 device_get_nameunit(sc->sc_dev), stat.flags); in zyd_rx_data()
2167 counter_u64_add(ic->ic_ierrors, 1); in zyd_rx_data()
2172 rlen = len - sizeof(struct zyd_plcphdr) - in zyd_rx_data()
2173 sizeof(struct zyd_rx_stat) - IEEE80211_CRC_LEN; in zyd_rx_data()
2178 device_get_nameunit(sc->sc_dev), rlen); in zyd_rx_data()
2179 counter_u64_add(ic->ic_ierrors, 1); in zyd_rx_data()
2187 device_get_nameunit(sc->sc_dev)); in zyd_rx_data()
2188 counter_u64_add(ic->ic_ierrors, 1); in zyd_rx_data()
2191 m->m_pkthdr.len = m->m_len = rlen; in zyd_rx_data()
2195 struct zyd_rx_radiotap_header *tap = &sc->sc_rxtap; in zyd_rx_data()
2197 tap->wr_flags = 0; in zyd_rx_data()
2199 tap->wr_flags |= IEEE80211_RADIOTAP_F_BADFCS; in zyd_rx_data()
2202 tap->wr_flags |= IEEE80211_RADIOTAP_F_BADFCS; in zyd_rx_data()
2203 tap->wr_rate = ieee80211_plcp2rate(plcp.signal, in zyd_rx_data()
2206 tap->wr_antsignal = stat.rssi + -95; in zyd_rx_data()
2207 tap->wr_antnoise = -95; /* XXX */ in zyd_rx_data()
2211 sc->sc_rx_data[sc->sc_rx_count].rssi = rssi; in zyd_rx_data()
2212 sc->sc_rx_data[sc->sc_rx_count].m = m; in zyd_rx_data()
2213 sc->sc_rx_count++; in zyd_rx_data()
2220 struct ieee80211com *ic = &sc->sc_ic; in zyd_bulk_read_callback()
2233 sc->sc_rx_count = 0; in zyd_bulk_read_callback()
2237 usbd_copy_out(pc, actlen - sizeof(desc), &desc, sizeof(desc)); in zyd_bulk_read_callback()
2242 "%s: received multi-frame transfer\n", __func__); in zyd_bulk_read_callback()
2252 /* next frame is aligned on a 32-bit boundary */ in zyd_bulk_read_callback()
2257 actlen -= len16; in zyd_bulk_read_callback()
2261 "%s: received single-frame transfer\n", __func__); in zyd_bulk_read_callback()
2277 for (i = 0; i < sc->sc_rx_count; i++) { in zyd_bulk_read_callback()
2278 rssi = sc->sc_rx_data[i].rssi; in zyd_bulk_read_callback()
2279 m = sc->sc_rx_data[i].m; in zyd_bulk_read_callback()
2280 sc->sc_rx_data[i].m = NULL; in zyd_bulk_read_callback()
2282 nf = -95; /* XXX */ in zyd_bulk_read_callback()
2312 /* OFDM rates (cf IEEE Std 802.11a-1999, pp. 14 Table 80) */ in zyd_plcp_signal()
2329 /* CCK rates (NB: not IEEE std, device-specific) */ in zyd_plcp_signal()
2340 device_printf(sc->sc_dev, "unsupported rate %d\n", rate); in zyd_plcp_signal()
2369 data = STAILQ_FIRST(&sc->tx_q); in zyd_bulk_write_callback()
2371 STAILQ_REMOVE_HEAD(&sc->tx_q, next); in zyd_bulk_write_callback()
2372 m = data->m; in zyd_bulk_write_callback()
2374 if (m->m_pkthdr.len > (int)ZYD_MAX_TXBUFSZ) { in zyd_bulk_write_callback()
2376 m->m_pkthdr.len); in zyd_bulk_write_callback()
2377 m->m_pkthdr.len = ZYD_MAX_TXBUFSZ; in zyd_bulk_write_callback()
2380 usbd_copy_in(pc, 0, &data->desc, ZYD_TX_DESC_SIZE); in zyd_bulk_write_callback()
2382 m->m_pkthdr.len); in zyd_bulk_write_callback()
2384 vap = data->ni->ni_vap; in zyd_bulk_write_callback()
2386 struct zyd_tx_radiotap_header *tap = &sc->sc_txtap; in zyd_bulk_write_callback()
2388 tap->wt_flags = 0; in zyd_bulk_write_callback()
2389 tap->wt_rate = data->rate; in zyd_bulk_write_callback()
2394 usbd_xfer_set_frame_len(xfer, 0, ZYD_TX_DESC_SIZE + m->m_pkthdr.len); in zyd_bulk_write_callback()
2405 counter_u64_add(sc->sc_ic.ic_oerrors, 1); in zyd_bulk_write_callback()
2413 device_printf(sc->sc_dev, "device timeout\n"); in zyd_bulk_write_callback()
2430 struct ieee80211vap *vap = ni->ni_vap; in zyd_tx_start()
2431 struct ieee80211com *ic = ni->ni_ic; in zyd_tx_start()
2435 const struct ieee80211_txparam *tp = ni->ni_txparms; in zyd_tx_start()
2444 data = STAILQ_FIRST(&sc->tx_free); in zyd_tx_start()
2445 STAILQ_REMOVE_HEAD(&sc->tx_free, next); in zyd_tx_start()
2446 sc->tx_nfree--; in zyd_tx_start()
2448 ismcast = IEEE80211_IS_MULTICAST(wh->i_addr1); in zyd_tx_start()
2449 type = wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK; in zyd_tx_start()
2453 (m0->m_flags & M_EAPOL) != 0) { in zyd_tx_start()
2454 rate = tp->mgmtrate; in zyd_tx_start()
2458 rate = tp->mcastrate; in zyd_tx_start()
2459 else if (tp->ucastrate != IEEE80211_FIXED_RATE_NONE) in zyd_tx_start()
2460 rate = tp->ucastrate; in zyd_tx_start()
2463 rate = ni->ni_txrate; in zyd_tx_start()
2467 if (wh->i_fc[1] & IEEE80211_FC1_PROTECTED) { in zyd_tx_start()
2476 data->ni = ni; in zyd_tx_start()
2477 data->m = m0; in zyd_tx_start()
2478 data->rate = rate; in zyd_tx_start()
2481 desc = &data->desc; in zyd_tx_start()
2483 desc->phy = phy; in zyd_tx_start()
2485 desc->phy |= ZYD_TX_PHY_OFDM; in zyd_tx_start()
2486 if (IEEE80211_IS_CHAN_5GHZ(ic->ic_curchan)) in zyd_tx_start()
2487 desc->phy |= ZYD_TX_PHY_5GHZ; in zyd_tx_start()
2488 } else if (rate != 2 && (ic->ic_flags & IEEE80211_F_SHPREAMBLE)) in zyd_tx_start()
2489 desc->phy |= ZYD_TX_PHY_SHPREAMBLE; in zyd_tx_start()
2491 totlen = m0->m_pkthdr.len + IEEE80211_CRC_LEN; in zyd_tx_start()
2492 desc->len = htole16(totlen); in zyd_tx_start()
2494 desc->flags = ZYD_TX_FLAG_BACKOFF; in zyd_tx_start()
2497 if (totlen > vap->iv_rtsthreshold) { in zyd_tx_start()
2498 desc->flags |= ZYD_TX_FLAG_RTS; in zyd_tx_start()
2500 (ic->ic_flags & IEEE80211_F_USEPROT)) { in zyd_tx_start()
2501 if (ic->ic_protmode == IEEE80211_PROT_CTSONLY) in zyd_tx_start()
2502 desc->flags |= ZYD_TX_FLAG_CTS_TO_SELF; in zyd_tx_start()
2503 else if (ic->ic_protmode == IEEE80211_PROT_RTSCTS) in zyd_tx_start()
2504 desc->flags |= ZYD_TX_FLAG_RTS; in zyd_tx_start()
2507 desc->flags |= ZYD_TX_FLAG_MULTICAST; in zyd_tx_start()
2509 desc->flags |= ZYD_TX_FLAG_TYPE(ZYD_TX_TYPE_PS_POLL); in zyd_tx_start()
2513 if (sc->sc_macrev == ZYD_ZD1211) in zyd_tx_start()
2515 desc->pktlen = htole16(pktlen); in zyd_tx_start()
2519 desc->plcp_length = htole16(bits / ratediv[phy]); in zyd_tx_start()
2520 desc->plcp_service = 0; in zyd_tx_start()
2522 desc->plcp_service |= ZYD_PLCP_LENGEXT; in zyd_tx_start()
2523 desc->nextlen = 0; in zyd_tx_start()
2526 struct zyd_tx_radiotap_header *tap = &sc->sc_txtap; in zyd_tx_start()
2528 tap->wt_flags = 0; in zyd_tx_start()
2529 tap->wt_rate = rate; in zyd_tx_start()
2536 device_get_nameunit(sc->sc_dev), (size_t)m0->m_pkthdr.len, in zyd_tx_start()
2539 STAILQ_INSERT_TAIL(&sc->tx_q, data, next); in zyd_tx_start()
2540 usbd_transfer_start(sc->sc_xfer[ZYD_BULK_WR]); in zyd_tx_start()
2548 struct zyd_softc *sc = ic->ic_softc; in zyd_transmit()
2552 if ((sc->sc_flags & ZYD_FLAG_RUNNING) == 0) { in zyd_transmit()
2556 error = mbufq_enqueue(&sc->sc_snd, m); in zyd_transmit()
2575 while (sc->tx_nfree > 0 && (m = mbufq_dequeue(&sc->sc_snd)) != NULL) { in zyd_start()
2576 ni = (struct ieee80211_node *)m->m_pkthdr.rcvif; in zyd_start()
2579 if_inc_counter(ni->ni_vap->iv_ifp, in zyd_start()
2591 struct ieee80211com *ic = ni->ni_ic; in zyd_raw_xmit()
2592 struct zyd_softc *sc = ic->ic_softc; in zyd_raw_xmit()
2596 if (!(sc->sc_flags & ZYD_FLAG_RUNNING)) { in zyd_raw_xmit()
2601 if (sc->tx_nfree == 0) { in zyd_raw_xmit()
2624 struct zyd_softc *sc = ic->ic_softc; in zyd_parent()
2628 if (sc->sc_flags & ZYD_FLAG_DETACHED) { in zyd_parent()
2632 if (ic->ic_nrunning > 0) { in zyd_parent()
2633 if ((sc->sc_flags & ZYD_FLAG_RUNNING) == 0) { in zyd_parent()
2638 } else if (sc->sc_flags & ZYD_FLAG_RUNNING) in zyd_parent()
2648 struct ieee80211com *ic = &sc->sc_ic; in zyd_init_locked()
2649 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps); in zyd_init_locked()
2656 if (!(sc->sc_flags & ZYD_FLAG_INITONCE)) { in zyd_init_locked()
2659 device_printf(sc->sc_dev, in zyd_init_locked()
2665 cd = usbd_get_config_descriptor(sc->sc_udev); in zyd_init_locked()
2666 error = usbd_req_set_config(sc->sc_udev, &sc->sc_mtx, in zyd_init_locked()
2667 cd->bConfigurationValue); in zyd_init_locked()
2669 device_printf(sc->sc_dev, "reset failed, continuing\n"); in zyd_init_locked()
2673 device_printf(sc->sc_dev, in zyd_init_locked()
2678 device_printf(sc->sc_dev, in zyd_init_locked()
2681 (sc->sc_macrev == ZYD_ZD1211) ? "": "B", in zyd_init_locked()
2682 sc->sc_fwrev >> 8, sc->sc_fwrev & 0xff, in zyd_init_locked()
2683 zyd_rf_name(sc->sc_rfrev), sc->sc_al2230s, sc->sc_parev, in zyd_init_locked()
2684 sc->sc_ledtype, sc->sc_bandedge6, sc->sc_newphy, in zyd_init_locked()
2685 sc->sc_cckgain, sc->sc_fix_cr157); in zyd_init_locked()
2689 sc->sc_regdomain = val >> 16; in zyd_init_locked()
2691 sc->sc_regdomain); in zyd_init_locked()
2698 sc->sc_flags |= ZYD_FLAG_INITONCE; in zyd_init_locked()
2701 if (sc->sc_flags & ZYD_FLAG_RUNNING) in zyd_init_locked()
2705 vap ? vap->iv_myaddr : ic->ic_macaddr, ":"); in zyd_init_locked()
2706 error = zyd_set_macaddr(sc, vap ? vap->iv_myaddr : ic->ic_macaddr); in zyd_init_locked()
2711 if (ic->ic_curmode == IEEE80211_MODE_11B) in zyd_init_locked()
2713 else if (ic->ic_curmode == IEEE80211_MODE_11A) in zyd_init_locked()
2732 zyd_set_chan(sc, ic->ic_curchan); in zyd_init_locked()
2742 sc->sc_flags |= ZYD_FLAG_RUNNING; in zyd_init_locked()
2743 usbd_xfer_set_stall(sc->sc_xfer[ZYD_BULK_WR]); in zyd_init_locked()
2744 usbd_transfer_start(sc->sc_xfer[ZYD_BULK_RD]); in zyd_init_locked()
2745 usbd_transfer_start(sc->sc_xfer[ZYD_INTR_RD]); in zyd_init_locked()
2760 sc->sc_flags &= ~ZYD_FLAG_RUNNING; in zyd_stop()
2767 usbd_transfer_drain(sc->sc_xfer[ZYD_BULK_WR]); in zyd_stop()
2768 usbd_transfer_drain(sc->sc_xfer[ZYD_BULK_RD]); in zyd_stop()
2774 if (!(sc->sc_flags & ZYD_FLAG_INITONCE)) in zyd_stop()
2799 if (sc->sc_flags & ZYD_FLAG_FWLOADED) in zyd_loadfirmware()
2802 if (sc->sc_macrev == ZYD_ZD1211) { in zyd_loadfirmware()
2833 size -= mlen; in zyd_loadfirmware()
2845 sc->sc_flags |= ZYD_FLAG_FWLOADED; in zyd_loadfirmware()
2853 struct zyd_softc *sc = ic->ic_softc; in zyd_scan_start()
2864 struct zyd_softc *sc = ic->ic_softc; in zyd_scan_end()
2868 zyd_set_bssid(sc, sc->sc_bssid); in zyd_scan_end()
2887 struct zyd_softc *sc = ic->ic_softc; in zyd_set_channel()
2890 zyd_set_chan(sc, ic->ic_curchan); in zyd_set_channel()