Lines Matching defs:mac
539 struct bwn_mac *mac;
551 mac = NULL;
617 mac = malloc(sizeof(*mac), M_DEVBUF, M_WAITOK | M_ZERO);
618 mac->mac_sc = sc;
619 mac->mac_status = BWN_MAC_STATUS_UNINIT;
621 mac->mac_flags |= BWN_MAC_FLAG_BADFRAME_PREEMP;
623 TASK_INIT(&mac->mac_hwreset, 0, bwn_hwreset, mac);
624 NET_TASK_INIT(&mac->mac_intrtask, 0, bwn_intrtask, mac);
625 TASK_INIT(&mac->mac_txpower, 0, bwn_txpwr, mac);
627 error = bwn_attach_core(mac);
630 error = bwn_led_attach(mac);
638 sc->sc_board_info.board_srom_rev, mac->mac_phy.analog,
639 mac->mac_phy.type, mac->mac_phy.rev, mac->mac_phy.rf_manuf,
640 mac->mac_phy.rf_ver, mac->mac_phy.rf_rev);
641 if (mac->mac_flags & BWN_MAC_FLAG_DMA)
642 device_printf(sc->sc_dev, "DMA (%d bits)\n", mac->mac_dmatype);
651 mac->mac_rid_irq = 0;
652 mac->mac_res_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ,
653 &mac->mac_rid_irq, RF_ACTIVE | RF_SHAREABLE);
655 if (mac->mac_res_irq == NULL) {
661 error = bus_setup_intr(dev, mac->mac_res_irq,
662 INTR_TYPE_NET | INTR_MPSAFE, bwn_intr, NULL, mac,
663 &mac->mac_intrhand);
670 TAILQ_INSERT_TAIL(&sc->sc_maclist, mac, mac_list);
680 if (mac != NULL && mac->mac_res_irq != NULL) {
681 bus_release_resource(dev, SYS_RES_IRQ, mac->mac_rid_irq,
682 mac->mac_res_irq);
685 free(mac, M_DEVBUF);
842 bwn_phy_detach(struct bwn_mac *mac)
845 if (mac->mac_phy.detach != NULL)
846 mac->mac_phy.detach(mac);
853 struct bwn_mac *mac = sc->sc_curmac;
862 bwn_dma_free(mac);
867 bwn_phy_detach(mac);
868 ieee80211_draintask(ic, &mac->mac_hwreset);
869 ieee80211_draintask(ic, &mac->mac_txpower);
872 taskqueue_drain(sc->sc_tq, &mac->mac_intrtask);
875 if (mac->mac_intrhand != NULL) {
876 bus_teardown_intr(dev, mac->mac_res_irq, mac->mac_intrhand);
877 mac->mac_intrhand = NULL;
883 bus_release_resource(dev, SYS_RES_IRQ, mac->mac_rid_irq,
884 mac->mac_res_irq);
886 bwn_release_firmware(mac);
983 struct bwn_mac *mac = sc->sc_curmac;
991 if ((sc->sc_flags & BWN_FLAG_RUNNING) == 0 || mac == NULL ||
992 mac->mac_status < BWN_MAC_STATUS_STARTED)
1033 struct bwn_mac *mac = sc->sc_curmac;
1035 int pktlen = roundup(m->m_pkthdr.len + BWN_HDRSIZE(mac), 4);
1039 if (mac->mac_flags & BWN_MAC_FLAG_DMA) {
1040 dr = bwn_dma_select(mac, M_WME_GETAC(m));
1047 tq = bwn_pio_select(mac, M_WME_GETAC(m));
1061 struct bwn_mac *mac = sc->sc_curmac;
1066 if (m->m_pkthdr.len < IEEE80211_MIN_LEN || mac == NULL) {
1071 error = (mac->mac_flags & BWN_MAC_FLAG_DMA) ?
1072 bwn_dma_tx_start(mac, ni, &m) : bwn_pio_tx_start(mac, ni, &m);
1081 bwn_pio_tx_start(struct bwn_mac *mac, struct ieee80211_node *ni,
1086 struct bwn_softc *sc = mac->mac_sc;
1098 tq = bwn_pio_select(mac, M_WME_GETAC(m));
1104 error = bwn_set_txhdr(mac, ni, m, &txhdr, BWN_PIO_COOKIE(tq, tp));
1111 tq->tq_used += roundup(m->m_pkthdr.len + BWN_HDRSIZE(mac), 4);
1132 ctl32 = bwn_pio_write_multi_4(mac, tq,
1133 (BWN_PIO_READ_4(mac, tq, BWN_PIO8_TXCTL) |
1135 (const uint8_t *)&txhdr, BWN_HDRSIZE(mac));
1137 ctl32 = bwn_pio_write_multi_4(mac, tq, ctl32,
1139 bwn_pio_write_4(mac, tq, BWN_PIO_TXCTL,
1142 ctl16 = bwn_pio_write_multi_2(mac, tq,
1143 (bwn_pio_read_2(mac, tq, BWN_PIO_TXCTL) |
1145 (const uint8_t *)&txhdr, BWN_HDRSIZE(mac));
1146 ctl16 = bwn_pio_write_mbuf_2(mac, tq, ctl16, m);
1147 BWN_PIO_WRITE_2(mac, tq, BWN_PIO_TXCTL,
1155 bwn_pio_select(struct bwn_mac *mac, uint8_t prio)
1158 if ((mac->mac_flags & BWN_MAC_FLAG_WME) == 0)
1159 return (&mac->mac_method.pio.wme[WME_AC_BE]);
1163 return (&mac->mac_method.pio.wme[WME_AC_BE]);
1165 return (&mac->mac_method.pio.wme[WME_AC_BK]);
1167 return (&mac->mac_method.pio.wme[WME_AC_VI]);
1169 return (&mac->mac_method.pio.wme[WME_AC_VO]);
1176 bwn_dma_tx_start(struct bwn_mac *mac, struct ieee80211_node *ni,
1180 &(txhdr_cache[(slot / BWN_TX_SLOTS_PER_FRAME) * BWN_HDRSIZE(mac)])
1181 struct bwn_dma *dma = &mac->mac_method.dma;
1182 struct bwn_dma_ring *dr = bwn_dma_select(mac, M_WME_GETAC(*mp));
1185 struct bwn_softc *sc = mac->mac_sc;
1207 BWN_GET_TXHDRCACHE(slot), BWN_HDRSIZE(mac), bwn_dma_ring_addr,
1216 dr->setdesc(dr, desc, mt->mt_paddr, BWN_HDRSIZE(mac), 1, 0, 0);
1286 bwn_attach_core(struct bwn_mac *mac)
1288 struct bwn_softc *sc = mac->mac_sc;
1295 if ((error = bwn_core_forceclk(mac, true)))
1327 error = bwn_reset_core(mac, have_bg);
1335 mac->mac_dmatype = BHND_DMA_ADDR_64BIT;
1341 BWN_WRITE_4(mac, base + BWN_DMA32_TXCTL,
1343 tmp = BWN_READ_4(mac, base + BWN_DMA32_TXCTL);
1345 mac->mac_dmatype = BHND_DMA_ADDR_32BIT;
1347 mac->mac_dmatype = BHND_DMA_ADDR_30BIT;
1354 error = bwn_phy_getinfo(mac, have_bg);
1369 if (mac->mac_phy.type == BWN_PHYTYPE_A)
1371 else if (mac->mac_phy.type == BWN_PHYTYPE_G ||
1372 mac->mac_phy.type == BWN_PHYTYPE_N ||
1373 mac->mac_phy.type == BWN_PHYTYPE_LP)
1377 mac->mac_phy.type));
1383 if (mac->mac_phy.type != BWN_PHYTYPE_LP &&
1384 mac->mac_phy.type != BWN_PHYTYPE_N) {
1392 mac->mac_phy.phy_n = NULL;
1394 if (mac->mac_phy.type == BWN_PHYTYPE_G) {
1395 mac->mac_phy.attach = bwn_phy_g_attach;
1396 mac->mac_phy.detach = bwn_phy_g_detach;
1397 mac->mac_phy.prepare_hw = bwn_phy_g_prepare_hw;
1398 mac->mac_phy.init_pre = bwn_phy_g_init_pre;
1399 mac->mac_phy.init = bwn_phy_g_init;
1400 mac->mac_phy.exit = bwn_phy_g_exit;
1401 mac->mac_phy.phy_read = bwn_phy_g_read;
1402 mac->mac_phy.phy_write = bwn_phy_g_write;
1403 mac->mac_phy.rf_read = bwn_phy_g_rf_read;
1404 mac->mac_phy.rf_write = bwn_phy_g_rf_write;
1405 mac->mac_phy.use_hwpctl = bwn_phy_g_hwpctl;
1406 mac->mac_phy.rf_onoff = bwn_phy_g_rf_onoff;
1407 mac->mac_phy.switch_analog = bwn_phy_switch_analog;
1408 mac->mac_phy.switch_channel = bwn_phy_g_switch_channel;
1409 mac->mac_phy.get_default_chan = bwn_phy_g_get_default_chan;
1410 mac->mac_phy.set_antenna = bwn_phy_g_set_antenna;
1411 mac->mac_phy.set_im = bwn_phy_g_im;
1412 mac->mac_phy.recalc_txpwr = bwn_phy_g_recalc_txpwr;
1413 mac->mac_phy.set_txpwr = bwn_phy_g_set_txpwr;
1414 mac->mac_phy.task_15s = bwn_phy_g_task_15s;
1415 mac->mac_phy.task_60s = bwn_phy_g_task_60s;
1416 } else if (mac->mac_phy.type == BWN_PHYTYPE_LP) {
1417 mac->mac_phy.init_pre = bwn_phy_lp_init_pre;
1418 mac->mac_phy.init = bwn_phy_lp_init;
1419 mac->mac_phy.phy_read = bwn_phy_lp_read;
1420 mac->mac_phy.phy_write = bwn_phy_lp_write;
1421 mac->mac_phy.phy_maskset = bwn_phy_lp_maskset;
1422 mac->mac_phy.rf_read = bwn_phy_lp_rf_read;
1423 mac->mac_phy.rf_write = bwn_phy_lp_rf_write;
1424 mac->mac_phy.rf_onoff = bwn_phy_lp_rf_onoff;
1425 mac->mac_phy.switch_analog = bwn_phy_lp_switch_analog;
1426 mac->mac_phy.switch_channel = bwn_phy_lp_switch_channel;
1427 mac->mac_phy.get_default_chan = bwn_phy_lp_get_default_chan;
1428 mac->mac_phy.set_antenna = bwn_phy_lp_set_antenna;
1429 mac->mac_phy.task_60s = bwn_phy_lp_task_60s;
1430 } else if (mac->mac_phy.type == BWN_PHYTYPE_N) {
1431 mac->mac_phy.attach = bwn_phy_n_attach;
1432 mac->mac_phy.detach = bwn_phy_n_detach;
1433 mac->mac_phy.prepare_hw = bwn_phy_n_prepare_hw;
1434 mac->mac_phy.init_pre = bwn_phy_n_init_pre;
1435 mac->mac_phy.init = bwn_phy_n_init;
1436 mac->mac_phy.exit = bwn_phy_n_exit;
1437 mac->mac_phy.phy_read = bwn_phy_n_read;
1438 mac->mac_phy.phy_write = bwn_phy_n_write;
1439 mac->mac_phy.rf_read = bwn_phy_n_rf_read;
1440 mac->mac_phy.rf_write = bwn_phy_n_rf_write;
1441 mac->mac_phy.use_hwpctl = bwn_phy_n_hwpctl;
1442 mac->mac_phy.rf_onoff = bwn_phy_n_rf_onoff;
1443 mac->mac_phy.switch_analog = bwn_phy_n_switch_analog;
1444 mac->mac_phy.switch_channel = bwn_phy_n_switch_channel;
1445 mac->mac_phy.get_default_chan = bwn_phy_n_get_default_chan;
1446 mac->mac_phy.set_antenna = bwn_phy_n_set_antenna;
1447 mac->mac_phy.set_im = bwn_phy_n_im;
1448 mac->mac_phy.recalc_txpwr = bwn_phy_n_recalc_txpwr;
1449 mac->mac_phy.set_txpwr = bwn_phy_n_set_txpwr;
1450 mac->mac_phy.task_15s = bwn_phy_n_task_15s;
1451 mac->mac_phy.task_60s = bwn_phy_n_task_60s;
1454 mac->mac_phy.type);
1459 mac->mac_phy.gmode = have_bg;
1460 if (mac->mac_phy.attach != NULL) {
1461 error = mac->mac_phy.attach(mac);
1468 error = bwn_reset_core(mac, have_bg);
1472 error = bwn_chiptest(mac);
1475 error = bwn_setup_channels(mac, have_bg, have_a);
1482 sc->sc_curmac = mac;
1484 error = bwn_dma_attach(mac);
1490 mac->mac_phy.switch_analog(mac, 0);
1494 bwn_release_firmware(mac);
1502 bwn_reset_core(struct bwn_mac *mac, int g_mode)
1509 sc = mac->mac_sc;
1519 if (mac->mac_phy.type == BWN_PHYTYPE_N)
1552 if (mac->mac_phy.switch_analog != NULL)
1553 mac->mac_phy.switch_analog(mac, 1);
1555 ctl = BWN_READ_4(mac, BWN_MACCTL) & ~BWN_MACCTL_GMODE;
1558 BWN_WRITE_4(mac, BWN_MACCTL, ctl | BWN_MACCTL_IHR_ON);
1564 bwn_phy_getinfo(struct bwn_mac *mac, int gmode)
1566 struct bwn_phy *phy = &mac->mac_phy;
1567 struct bwn_softc *sc = mac->mac_sc;
1571 tmp = BWN_READ_2(mac, BWN_PHYVER);
1586 BWN_WRITE_2(mac, BWN_RFCTL, BWN_RFCTL_ID);
1587 tmp = BWN_READ_2(mac, BWN_RFDATALO);
1588 BWN_WRITE_2(mac, BWN_RFCTL, BWN_RFCTL_ID);
1589 tmp |= (uint32_t)BWN_READ_2(mac, BWN_RFDATAHI) << 16;
1627 bwn_chiptest(struct bwn_mac *mac)
1631 struct bwn_softc *sc = mac->mac_sc;
1636 backup = bwn_shm_read_4(mac, BWN_SHARED, 0);
1638 bwn_shm_write_4(mac, BWN_SHARED, 0, TESTVAL0);
1639 if (bwn_shm_read_4(mac, BWN_SHARED, 0) != TESTVAL0)
1641 bwn_shm_write_4(mac, BWN_SHARED, 0, TESTVAL1);
1642 if (bwn_shm_read_4(mac, BWN_SHARED, 0) != TESTVAL1)
1645 bwn_shm_write_4(mac, BWN_SHARED, 0, backup);
1649 BWN_WRITE_2(mac, BWN_TSF_CFP_START, 0xaaaa);
1650 BWN_WRITE_4(mac, BWN_TSF_CFP_START, 0xccccbbbb);
1651 if (BWN_READ_2(mac, BWN_TSF_CFP_START_LOW) != 0xbbbb)
1653 if (BWN_READ_2(mac, BWN_TSF_CFP_START_HIGH) != 0xcccc)
1656 BWN_WRITE_4(mac, BWN_TSF_CFP_START, 0);
1658 v = BWN_READ_4(mac, BWN_MACCTL) | BWN_MACCTL_GMODE;
1671 bwn_setup_channels(struct bwn_mac *mac, int have_bg, int have_a)
1673 struct bwn_softc *sc = mac->mac_sc;
1700 mac->mac_phy.supports_2ghz = have_bg;
1701 mac->mac_phy.supports_5ghz = have_a;
1707 bwn_shm_read_4(struct bwn_mac *mac, uint16_t way, uint16_t offset)
1711 BWN_ASSERT_LOCKED(mac->mac_sc);
1717 bwn_shm_ctlword(mac, way, offset >> 2);
1718 ret = BWN_READ_2(mac, BWN_SHM_DATA_UNALIGNED);
1720 bwn_shm_ctlword(mac, way, (offset >> 2) + 1);
1721 ret |= BWN_READ_2(mac, BWN_SHM_DATA);
1726 bwn_shm_ctlword(mac, way, offset);
1727 ret = BWN_READ_4(mac, BWN_SHM_DATA);
1733 bwn_shm_read_2(struct bwn_mac *mac, uint16_t way, uint16_t offset)
1737 BWN_ASSERT_LOCKED(mac->mac_sc);
1743 bwn_shm_ctlword(mac, way, offset >> 2);
1744 ret = BWN_READ_2(mac, BWN_SHM_DATA_UNALIGNED);
1749 bwn_shm_ctlword(mac, way, offset);
1750 ret = BWN_READ_2(mac, BWN_SHM_DATA);
1757 bwn_shm_ctlword(struct bwn_mac *mac, uint16_t way,
1765 BWN_WRITE_4(mac, BWN_SHM_CONTROL, control);
1769 bwn_shm_write_4(struct bwn_mac *mac, uint16_t way, uint16_t offset,
1772 BWN_ASSERT_LOCKED(mac->mac_sc);
1778 bwn_shm_ctlword(mac, way, offset >> 2);
1779 BWN_WRITE_2(mac, BWN_SHM_DATA_UNALIGNED,
1781 bwn_shm_ctlword(mac, way, (offset >> 2) + 1);
1782 BWN_WRITE_2(mac, BWN_SHM_DATA, value & 0xffff);
1787 bwn_shm_ctlword(mac, way, offset);
1788 BWN_WRITE_4(mac, BWN_SHM_DATA, value);
1792 bwn_shm_write_2(struct bwn_mac *mac, uint16_t way, uint16_t offset,
1795 BWN_ASSERT_LOCKED(mac->mac_sc);
1801 bwn_shm_ctlword(mac, way, offset >> 2);
1802 BWN_WRITE_2(mac, BWN_SHM_DATA_UNALIGNED, value);
1807 bwn_shm_ctlword(mac, way, offset);
1808 BWN_WRITE_2(mac, BWN_SHM_DATA, value);
1831 struct bwn_mac *mac = sc->sc_curmac;
1835 mac->mac_status < BWN_MAC_STATUS_STARTED) {
1864 struct bwn_mac *mac;
1868 mac = (struct bwn_mac *)sc->sc_curmac;
1869 bwn_set_slot_time(mac, IEEE80211_GET_SLOTTIME(ic));
1885 struct bwn_mac *mac = sc->sc_curmac;
1888 mac = sc->sc_curmac;
1889 if (mac != NULL && mac->mac_status >= BWN_MAC_STATUS_INITED) {
1894 bwn_set_opmode(mac);
1906 struct bwn_mac *mac = sc->sc_curmac;
1914 mac = sc->sc_curmac;
1915 if (mac != NULL && mac->mac_status >= BWN_MAC_STATUS_INITED) {
1916 bwn_mac_suspend(mac);
1919 bwn_wme_loadparams(mac, wmep, bwn_wme_shm_offsets[i]);
1921 bwn_mac_enable(mac);
1931 struct bwn_mac *mac;
1934 mac = sc->sc_curmac;
1935 if (mac != NULL && mac->mac_status >= BWN_MAC_STATUS_INITED) {
1937 bwn_set_opmode(mac);
1939 bwn_hf_write(mac, bwn_hf_read(mac) | BWN_HF_SKIP_CFP_UPDATE);
1948 struct bwn_mac *mac;
1951 mac = sc->sc_curmac;
1952 if (mac != NULL && mac->mac_status >= BWN_MAC_STATUS_INITED) {
1954 bwn_set_opmode(mac);
1955 bwn_hf_write(mac, bwn_hf_read(mac) & ~BWN_HF_SKIP_CFP_UPDATE);
1964 struct bwn_mac *mac = sc->sc_curmac;
1965 struct bwn_phy *phy = &mac->mac_phy;
1973 bwn_mac_suspend(mac);
1974 bwn_set_txretry(mac, BWN_RETRY_SHORT, BWN_RETRY_LONG);
1977 bwn_switch_channel(mac, chan);
1983 bwn_phy_txpower_check(mac, BWN_TXPWR_IGNORE_TIME |
1987 bwn_set_txantenna(mac, BWN_ANT_DEFAULT);
1989 phy->set_antenna(mac, BWN_ANT_DEFAULT);
1993 bwn_rf_turnon(mac);
1994 if (!(mac->mac_flags & BWN_MAC_FLAG_RADIO_ON))
1998 bwn_rf_turnoff(mac);
2001 bwn_mac_enable(mac);
2011 const uint8_t mac[IEEE80211_ADDR_LEN])
2043 ieee80211_media_status, mac);
2060 struct bwn_mac *mac;
2074 mac = sc->sc_curmac;
2075 if (mac->mac_status == BWN_MAC_STATUS_UNINIT) {
2076 error = bwn_core_init(mac);
2080 if (mac->mac_status == BWN_MAC_STATUS_INITED)
2081 bwn_core_start(mac);
2083 bwn_set_opmode(mac);
2084 bwn_set_pretbtt(mac);
2085 bwn_spu_setdelay(mac, 0);
2086 bwn_set_macaddr(mac);
2098 struct bwn_mac *mac = sc->sc_curmac;
2104 if (mac->mac_status >= BWN_MAC_STATUS_INITED) {
2106 bwn_set_opmode(mac);
2107 bwn_set_macaddr(mac);
2110 if (mac->mac_status >= BWN_MAC_STATUS_STARTED)
2111 bwn_core_stop(mac);
2116 bwn_core_exit(mac);
2178 bwn_core_forceclk(struct bwn_mac *mac, bool force)
2184 sc = mac->mac_sc;
2206 bwn_core_init(struct bwn_mac *mac)
2208 struct bwn_softc *sc = mac->mac_sc;
2212 KASSERT(mac->mac_status == BWN_MAC_STATUS_UNINIT,
2215 DPRINTF(mac->mac_sc, BWN_DEBUG_RESET, "%s: called\n", __func__);
2217 if ((error = bwn_core_forceclk(mac, true)))
2221 if ((error = bwn_reset_core(mac, mac->mac_phy.gmode)))
2225 mac->mac_flags &= ~BWN_MAC_FLAG_DFQVALID;
2226 mac->mac_flags |= BWN_MAC_FLAG_RADIO_ON;
2227 mac->mac_phy.hwpctl = (bwn_hwpctl) ? 1 : 0;
2228 BWN_GETTIME(mac->mac_phy.nexttime);
2229 mac->mac_phy.txerrors = BWN_TXERROR_MAX;
2230 bzero(&mac->mac_stats, sizeof(mac->mac_stats));
2231 mac->mac_stats.link_noise = -95;
2232 mac->mac_reason_intr = 0;
2233 bzero(mac->mac_reason, sizeof(mac->mac_reason));
2234 mac->mac_intr_mask = BWN_INTR_MASKTEMPLATE;
2237 mac->mac_intr_mask &= ~BWN_INTR_PHY_TXERR;
2239 mac->mac_suspended = 1;
2240 mac->mac_task_state = 0;
2241 memset(&mac->mac_noise, 0, sizeof(mac->mac_noise));
2243 mac->mac_phy.init_pre(mac);
2245 bwn_bt_disable(mac);
2246 if (mac->mac_phy.prepare_hw) {
2247 error = mac->mac_phy.prepare_hw(mac);
2251 DPRINTF(mac->mac_sc, BWN_DEBUG_RESET, "%s: chip_init\n", __func__);
2252 error = bwn_chip_init(mac);
2255 bwn_shm_write_2(mac, BWN_SHARED, BWN_SHARED_COREREV,
2257 hf = bwn_hf_read(mac);
2258 if (mac->mac_phy.type == BWN_PHYTYPE_G) {
2262 if (mac->mac_phy.rev == 1)
2265 if (mac->mac_phy.rf_ver == 0x2050) {
2266 if (mac->mac_phy.rf_rev < 6)
2268 if (mac->mac_phy.rf_rev == 6)
2276 bwn_hf_write(mac, hf);
2281 cap = BWN_READ_4(mac, BWN_MAC_HW_CAP);
2285 bwn_shm_write_2(mac, BWN_SHARED, BWN_SHARED_MACHW_L,
2287 bwn_shm_write_2(mac, BWN_SHARED, BWN_SHARED_MACHW_H,
2291 bwn_set_txretry(mac, BWN_RETRY_SHORT, BWN_RETRY_LONG);
2292 bwn_shm_write_2(mac, BWN_SHARED, BWN_SHARED_SHORT_RETRY_FALLBACK, 3);
2293 bwn_shm_write_2(mac, BWN_SHARED, BWN_SHARED_LONG_RETRY_FALLBACK, 2);
2294 bwn_shm_write_2(mac, BWN_SHARED, BWN_SHARED_PROBE_RESP_MAXTIME, 1);
2296 bwn_rate_init(mac);
2297 bwn_set_phytxctl(mac);
2299 bwn_shm_write_2(mac, BWN_SCRATCH, BWN_SCRATCH_CONT_MIN,
2300 (mac->mac_phy.type == BWN_PHYTYPE_B) ? 0x1f : 0xf);
2301 bwn_shm_write_2(mac, BWN_SCRATCH, BWN_SCRATCH_CONT_MAX, 0x3ff);
2304 bwn_pio_init(mac);
2306 bwn_dma_init(mac);
2307 bwn_wme_init(mac);
2308 bwn_spu_setdelay(mac, 1);
2309 bwn_bt_enable(mac);
2311 DPRINTF(mac->mac_sc, BWN_DEBUG_RESET, "%s: powerup\n", __func__);
2313 bwn_core_forceclk(mac, true);
2315 bwn_core_forceclk(mac, false);
2317 bwn_set_macaddr(mac);
2318 bwn_crypt_init(mac);
2322 mac->mac_status = BWN_MAC_STATUS_INITED;
2324 DPRINTF(mac->mac_sc, BWN_DEBUG_RESET, "%s: done\n", __func__);
2329 KASSERT(mac->mac_status == BWN_MAC_STATUS_UNINIT,
2331 DPRINTF(mac->mac_sc, BWN_DEBUG_RESET, "%s: fail\n", __func__);
2336 bwn_core_start(struct bwn_mac *mac)
2338 struct bwn_softc *sc = mac->mac_sc;
2341 KASSERT(mac->mac_status == BWN_MAC_STATUS_INITED,
2348 tmp = BWN_READ_4(mac, BWN_XMITSTAT_0);
2351 tmp = BWN_READ_4(mac, BWN_XMITSTAT_1);
2354 bwn_mac_enable(mac);
2355 BWN_WRITE_4(mac, BWN_INTR_MASK, mac->mac_intr_mask);
2356 callout_reset(&sc->sc_task_ch, hz * 15, bwn_tasks, mac);
2358 mac->mac_status = BWN_MAC_STATUS_STARTED;
2362 bwn_core_exit(struct bwn_mac *mac)
2364 struct bwn_softc *sc = mac->mac_sc;
2367 BWN_ASSERT_LOCKED(mac->mac_sc);
2369 KASSERT(mac->mac_status <= BWN_MAC_STATUS_INITED,
2372 if (mac->mac_status != BWN_MAC_STATUS_INITED)
2374 mac->mac_status = BWN_MAC_STATUS_UNINIT;
2376 macctl = BWN_READ_4(mac, BWN_MACCTL);
2379 BWN_WRITE_4(mac, BWN_MACCTL, macctl);
2381 bwn_dma_stop(mac);
2382 bwn_pio_stop(mac);
2383 bwn_chip_exit(mac);
2384 mac->mac_phy.switch_analog(mac, 0);
2389 bwn_bt_disable(struct bwn_mac *mac)
2391 struct bwn_softc *sc = mac->mac_sc;
2398 bwn_chip_init(struct bwn_mac *mac)
2400 struct bwn_softc *sc = mac->mac_sc;
2401 struct bwn_phy *phy = &mac->mac_phy;
2409 BWN_WRITE_4(mac, BWN_MACCTL, macctl);
2411 error = bwn_fw_fillinfo(mac);
2414 error = bwn_fw_loaducode(mac);
2418 error = bwn_gpio_init(mac);
2422 error = bwn_fw_loadinitvals(mac);
2426 phy->switch_analog(mac, 1);
2427 error = bwn_phy_init(mac);
2432 phy->set_im(mac, BWN_IMMODE_NONE);
2434 phy->set_antenna(mac, BWN_ANT_DEFAULT);
2435 bwn_set_txantenna(mac, BWN_ANT_DEFAULT);
2438 BWN_WRITE_2(mac, 0x005e, BWN_READ_2(mac, 0x005e) | 0x0004);
2439 BWN_WRITE_4(mac, 0x0100, 0x01000000);
2441 BWN_WRITE_4(mac, 0x010c, 0x01000000);
2443 BWN_WRITE_4(mac, BWN_MACCTL,
2444 BWN_READ_4(mac, BWN_MACCTL) & ~BWN_MACCTL_STA);
2445 BWN_WRITE_4(mac, BWN_MACCTL,
2446 BWN_READ_4(mac, BWN_MACCTL) | BWN_MACCTL_STA);
2447 bwn_shm_write_2(mac, BWN_SHARED, 0x0074, 0x0000);
2449 bwn_set_opmode(mac);
2451 BWN_WRITE_2(mac, 0x060e, 0x0000);
2452 BWN_WRITE_2(mac, 0x0610, 0x8000);
2453 BWN_WRITE_2(mac, 0x0604, 0x0000);
2454 BWN_WRITE_2(mac, 0x0606, 0x0200);
2456 BWN_WRITE_4(mac, 0x0188, 0x80000000);
2457 BWN_WRITE_4(mac, 0x018c, 0x02000000);
2459 BWN_WRITE_4(mac, BWN_INTR_REASON, 0x00004000);
2460 BWN_WRITE_4(mac, BWN_DMA0_INTR_MASK, 0x0001dc00);
2461 BWN_WRITE_4(mac, BWN_DMA1_INTR_MASK, 0x0000dc00);
2462 BWN_WRITE_4(mac, BWN_DMA2_INTR_MASK, 0x0000dc00);
2463 BWN_WRITE_4(mac, BWN_DMA3_INTR_MASK, 0x0001dc00);
2464 BWN_WRITE_4(mac, BWN_DMA4_INTR_MASK, 0x0000dc00);
2465 BWN_WRITE_4(mac, BWN_DMA5_INTR_MASK, 0x0000dc00);
2467 bwn_mac_phy_clock_set(mac, true);
2483 BWN_WRITE_2(mac, BWN_POWERUP_DELAY, delay);
2489 bwn_hf_read(struct bwn_mac *mac)
2493 ret = bwn_shm_read_2(mac, BWN_SHARED, BWN_SHARED_HFHI);
2495 ret |= bwn_shm_read_2(mac, BWN_SHARED, BWN_SHARED_HFMI);
2497 ret |= bwn_shm_read_2(mac, BWN_SHARED, BWN_SHARED_HFLO);
2502 bwn_hf_write(struct bwn_mac *mac, uint64_t value)
2505 bwn_shm_write_2(mac, BWN_SHARED, BWN_SHARED_HFLO,
2507 bwn_shm_write_2(mac, BWN_SHARED, BWN_SHARED_HFMI,
2509 bwn_shm_write_2(mac, BWN_SHARED, BWN_SHARED_HFHI,
2514 bwn_set_txretry(struct bwn_mac *mac, int s, int l)
2517 bwn_shm_write_2(mac, BWN_SCRATCH, BWN_SCRATCH_SHORT_RETRY, MIN(s, 0xf));
2518 bwn_shm_write_2(mac, BWN_SCRATCH, BWN_SCRATCH_LONG_RETRY, MIN(l, 0xf));
2522 bwn_rate_init(struct bwn_mac *mac)
2525 switch (mac->mac_phy.type) {
2530 bwn_rate_write(mac, BWN_OFDM_RATE_6MB, 1);
2531 bwn_rate_write(mac, BWN_OFDM_RATE_12MB, 1);
2532 bwn_rate_write(mac, BWN_OFDM_RATE_18MB, 1);
2533 bwn_rate_write(mac, BWN_OFDM_RATE_24MB, 1);
2534 bwn_rate_write(mac, BWN_OFDM_RATE_36MB, 1);
2535 bwn_rate_write(mac, BWN_OFDM_RATE_48MB, 1);
2536 bwn_rate_write(mac, BWN_OFDM_RATE_54MB, 1);
2537 if (mac->mac_phy.type == BWN_PHYTYPE_A)
2541 bwn_rate_write(mac, BWN_CCK_RATE_1MB, 0);
2542 bwn_rate_write(mac, BWN_CCK_RATE_2MB, 0);
2543 bwn_rate_write(mac, BWN_CCK_RATE_5MB, 0);
2544 bwn_rate_write(mac, BWN_CCK_RATE_11MB, 0);
2552 bwn_rate_write(struct bwn_mac *mac, uint16_t rate, int ofdm)
2563 bwn_shm_write_2(mac, BWN_SHARED, offset + 0x20,
2564 bwn_shm_read_2(mac, BWN_SHARED, offset));
2612 bwn_set_phytxctl(struct bwn_mac *mac)
2618 bwn_shm_write_2(mac, BWN_SHARED, BWN_SHARED_BEACON_PHYCTL, ctl);
2619 bwn_shm_write_2(mac, BWN_SHARED, BWN_SHARED_ACKCTS_PHYCTL, ctl);
2620 bwn_shm_write_2(mac, BWN_SHARED, BWN_SHARED_PROBE_RESP_PHYCTL, ctl);
2624 bwn_pio_init(struct bwn_mac *mac)
2626 struct bwn_pio *pio = &mac->mac_method.pio;
2628 BWN_WRITE_4(mac, BWN_MACCTL, BWN_READ_4(mac, BWN_MACCTL)
2630 bwn_shm_write_2(mac, BWN_SHARED, BWN_SHARED_RX_PADOFFSET, 0);
2632 bwn_pio_set_txqueue(mac, &pio->wme[WME_AC_BK], 0);
2633 bwn_pio_set_txqueue(mac, &pio->wme[WME_AC_BE], 1);
2634 bwn_pio_set_txqueue(mac, &pio->wme[WME_AC_VI], 2);
2635 bwn_pio_set_txqueue(mac, &pio->wme[WME_AC_VO], 3);
2636 bwn_pio_set_txqueue(mac, &pio->mcast, 4);
2637 bwn_pio_setupqueue_rx(mac, &pio->rx, 0);
2641 bwn_pio_set_txqueue(struct bwn_mac *mac, struct bwn_pio_txqueue *tq,
2645 struct bwn_softc *sc = mac->mac_sc;
2648 tq->tq_base = bwn_pio_idx2base(mac, index) + BWN_PIO_TXQOFFSET(mac);
2655 tq->tq_size = bwn_pio_read_2(mac, tq, BWN_PIO_TXQBUFSIZE);
2669 bwn_pio_idx2base(struct bwn_mac *mac, int index)
2671 struct bwn_softc *sc = mac->mac_sc;
2702 bwn_pio_setupqueue_rx(struct bwn_mac *mac, struct bwn_pio_rxqueue *prq,
2705 struct bwn_softc *sc = mac->mac_sc;
2707 prq->prq_mac = mac;
2709 prq->prq_base = bwn_pio_idx2base(mac, index) + BWN_PIO_RXQOFFSET(mac);
2710 bwn_dma_rxdirectfifo(mac, index, 1);
2729 bwn_pio_read_2(struct bwn_mac *mac, struct bwn_pio_txqueue *tq,
2733 return (BWN_READ_2(mac, tq->tq_base + offset));
2737 bwn_dma_rxdirectfifo(struct bwn_mac *mac, int idx, uint8_t enable)
2742 base = bwn_dma_base(mac->mac_dmatype, idx);
2743 if (mac->mac_dmatype == BHND_DMA_ADDR_64BIT) {
2744 ctl = BWN_READ_4(mac, base + BWN_DMA64_RXCTL);
2748 BWN_WRITE_4(mac, base + BWN_DMA64_RXCTL, ctl);
2750 ctl = BWN_READ_4(mac, base + BWN_DMA32_RXCTL);
2754 BWN_WRITE_4(mac, base + BWN_DMA32_RXCTL, ctl);
2804 bwn_dma_init(struct bwn_mac *mac)
2806 struct bwn_dma *dma = &mac->mac_method.dma;
2819 bwn_dma_ringsetup(struct bwn_mac *mac, int controller_index,
2822 struct bwn_dma *dma = &mac->mac_method.dma;
2826 struct bwn_softc *sc = mac->mac_sc;
2841 dr->dr_type = mac->mac_dmatype;
2842 dr->dr_mac = mac;
2867 switch (mac->mac_fw.fw_hdr_format) {
2916 BWN_HDRSIZE(mac),
3227 struct bwn_mac *mac = dr->dr_mac;
3228 struct bwn_dma *dma = &mac->mac_method.dma;
3229 struct bwn_softc *sc = mac->mac_sc;
3272 struct bwn_mac *mac;
3278 mac = dr->dr_mac;
3279 dma = &mac->mac_method.dma;
3374 struct bwn_mac *mac = dr->dr_mac;
3375 struct bwn_dma *dma = &mac->mac_method.dma;
3376 struct bwn_softc *sc = mac->mac_sc;
3404 bwn_dma_tx_reset(struct bwn_mac *mac, uint16_t base,
3407 struct bwn_softc *sc = mac->mac_sc;
3415 value = BWN_READ_4(mac, base + offset);
3433 BWN_WRITE_4(mac, base + offset, 0);
3437 value = BWN_READ_4(mac, base + offset);
3463 bwn_dma_rx_reset(struct bwn_mac *mac, uint16_t base,
3466 struct bwn_softc *sc = mac->mac_sc;
3473 BWN_WRITE_4(mac, base + offset, 0);
3477 value = BWN_READ_4(mac, base + offset);
3542 bwn_wme_init(struct bwn_mac *mac)
3545 bwn_wme_load(mac);
3548 bwn_hf_write(mac, bwn_hf_read(mac) | BWN_HF_EDCF);
3549 BWN_WRITE_2(mac, BWN_IFSCTL, BWN_READ_2(mac, BWN_IFSCTL) |
3554 bwn_spu_setdelay(struct bwn_mac *mac, int idle)
3556 struct bwn_softc *sc = mac->mac_sc;
3560 delay = (mac->mac_phy.type == BWN_PHYTYPE_A) ? 3700 : 1050;
3563 if ((mac->mac_phy.rf_ver == 0x2050) && (mac->mac_phy.rf_rev == 8))
3566 bwn_shm_write_2(mac, BWN_SHARED, BWN_SHARED_SPU_WAKEUP, delay);
3570 bwn_bt_enable(struct bwn_mac *mac)
3572 struct bwn_softc *sc = mac->mac_sc;
3579 if (mac->mac_phy.type != BWN_PHYTYPE_B && !mac->mac_phy.gmode)
3582 hf = bwn_hf_read(mac);
3587 bwn_hf_write(mac, hf);
3591 bwn_set_macaddr(struct bwn_mac *mac)
3594 bwn_mac_write_bssid(mac);
3595 bwn_mac_setfilter(mac, BWN_MACFILTER_SELF,
3596 mac->mac_sc->sc_ic.ic_macaddr);
3600 bwn_clear_keys(struct bwn_mac *mac)
3604 for (i = 0; i < mac->mac_max_nr_keys; i++) {
3605 KASSERT(i >= 0 && i < mac->mac_max_nr_keys,
3608 bwn_key_dowrite(mac, i, BWN_SEC_ALGO_NONE,
3610 if ((i <= 3) && !BWN_SEC_NEWAPI(mac)) {
3611 bwn_key_dowrite(mac, i + 4, BWN_SEC_ALGO_NONE,
3614 mac->mac_key[i].keyconf = NULL;
3619 bwn_crypt_init(struct bwn_mac *mac)
3621 struct bwn_softc *sc = mac->mac_sc;
3623 mac->mac_max_nr_keys = (bhnd_get_hwrev(sc->sc_dev) >= 5) ? 58 : 20;
3624 KASSERT(mac->mac_max_nr_keys <= N(mac->mac_key),
3626 mac->mac_ktp = bwn_shm_read_2(mac, BWN_SHARED, BWN_SHARED_KEY_TABLEP);
3627 mac->mac_ktp *= 2;
3629 BWN_WRITE_2(mac, BWN_RCMTA_COUNT, mac->mac_max_nr_keys - 8);
3630 bwn_clear_keys(mac);
3634 bwn_chip_exit(struct bwn_mac *mac)
3636 bwn_phy_exit(mac);
3640 bwn_fw_fillinfo(struct bwn_mac *mac)
3644 error = bwn_fw_gets(mac, BWN_FWTYPE_DEFAULT);
3647 error = bwn_fw_gets(mac, BWN_FWTYPE_OPENSOURCE);
3657 * @param mac bwn MAC state.
3662 bwn_gpio_control(struct bwn_mac *mac, uint32_t pins)
3668 sc = mac->mac_sc;
3695 bwn_gpio_init(struct bwn_mac *mac)
3700 sc = mac->mac_sc;
3704 BWN_WRITE_4(mac, BWN_MACCTL,
3705 BWN_READ_4(mac, BWN_MACCTL) & ~BWN_MACCTL_GPOUT_MASK);
3706 BWN_WRITE_2(mac, BWN_GPIO_MASK,
3707 BWN_READ_2(mac, BWN_GPIO_MASK) | pins);
3711 BWN_WRITE_2(mac, BWN_GPIO_MASK,
3712 BWN_READ_2(mac, BWN_GPIO_MASK) | BHND_GPIO_BOARD_PACTRL);
3717 return (bwn_gpio_control(mac, pins));
3721 bwn_fw_loadinitvals(struct bwn_mac *mac)
3727 struct bwn_fw *fw = &mac->mac_fw;
3731 error = bwn_fwinitvals_write(mac, GETFWOFFSET(fw->initvals, hdr_len),
3737 error = bwn_fwinitvals_write(mac,
3747 bwn_phy_init(struct bwn_mac *mac)
3749 struct bwn_softc *sc = mac->mac_sc;
3752 mac->mac_phy.chan = mac->mac_phy.get_default_chan(mac);
3753 mac->mac_phy.rf_onoff(mac, 1);
3754 error = mac->mac_phy.init(mac);
3759 error = bwn_switch_channel(mac,
3760 mac->mac_phy.get_default_chan(mac));
3768 if (mac->mac_phy.exit)
3769 mac->mac_phy.exit(mac);
3771 mac->mac_phy.rf_onoff(mac, 0);
3777 bwn_set_txantenna(struct bwn_mac *mac, int antenna)
3785 tmp = bwn_shm_read_2(mac, BWN_SHARED, BWN_SHARED_ACKCTS_PHYCTL);
3787 bwn_shm_write_2(mac, BWN_SHARED, BWN_SHARED_ACKCTS_PHYCTL, tmp);
3789 tmp = bwn_shm_read_2(mac, BWN_SHARED, BWN_SHARED_PROBE_RESP_PHYCTL);
3791 bwn_shm_write_2(mac, BWN_SHARED, BWN_SHARED_PROBE_RESP_PHYCTL, tmp);
3795 bwn_set_opmode(struct bwn_mac *mac)
3797 struct bwn_softc *sc = mac->mac_sc;
3802 ctl = BWN_READ_4(mac, BWN_MACCTL);
3818 BWN_WRITE_4(mac, BWN_MACCTL, ctl);
3828 BWN_WRITE_2(mac, 0x612, cfp_pretbtt);
3841 bwn_dummy_transmission(struct bwn_mac *mac, int ofdm, int paon)
3843 struct bwn_phy *phy = &mac->mac_phy;
3844 struct bwn_softc *sc = mac->mac_sc;
3859 BWN_ASSERT_LOCKED(mac->mac_sc);
3862 bwn_ram_write(mac, i * 4, buffer[i]);
3864 BWN_WRITE_2(mac, 0x0568, 0x0000);
3865 BWN_WRITE_2(mac, 0x07c0,
3869 BWN_WRITE_2(mac, 0x050c, value);
3873 BWN_WRITE_2(mac, 0x0514, 0x1a02);
3874 BWN_WRITE_2(mac, 0x0508, 0x0000);
3875 BWN_WRITE_2(mac, 0x050a, 0x0000);
3876 BWN_WRITE_2(mac, 0x054c, 0x0000);
3877 BWN_WRITE_2(mac, 0x056a, 0x0014);
3878 BWN_WRITE_2(mac, 0x0568, 0x0826);
3879 BWN_WRITE_2(mac, 0x0500, 0x0000);
3886 BWN_WRITE_2(mac, 0x0502, 0x00d0);
3889 BWN_WRITE_2(mac, 0x0502, 0x0050);
3892 BWN_WRITE_2(mac, 0x0502, 0x0030);
3897 BWN_READ_2(mac, 0x0502);
3900 BWN_RF_WRITE(mac, 0x0051, 0x0017);
3902 value = BWN_READ_2(mac, 0x050e);
3908 value = BWN_READ_2(mac, 0x050e);
3914 value = BWN_READ_2(mac, 0x0690);
3920 BWN_RF_WRITE(mac, 0x0051, 0x0037);
3924 bwn_ram_write(struct bwn_mac *mac, uint16_t offset, uint32_t val)
3930 macctl = BWN_READ_4(mac, BWN_MACCTL);
3934 BWN_WRITE_4(mac, BWN_RAM_CONTROL, offset);
3935 BWN_BARRIER(mac, BWN_RAM_CONTROL, 4, BUS_SPACE_BARRIER_WRITE);
3936 BWN_WRITE_4(mac, BWN_RAM_DATA, val);
3940 bwn_mac_suspend(struct bwn_mac *mac)
3942 struct bwn_softc *sc = mac->mac_sc;
3946 KASSERT(mac->mac_suspended >= 0,
3949 DPRINTF(mac->mac_sc, BWN_DEBUG_RESET, "%s: suspended=%d\n",
3950 __func__, mac->mac_suspended);
3952 if (mac->mac_suspended == 0) {
3953 bwn_psctl(mac, BWN_PS_AWAKE);
3954 BWN_WRITE_4(mac, BWN_MACCTL,
3955 BWN_READ_4(mac, BWN_MACCTL)
3957 BWN_READ_4(mac, BWN_MACCTL);
3959 tmp = BWN_READ_4(mac, BWN_INTR_REASON);
3965 tmp = BWN_READ_4(mac, BWN_INTR_REASON);
3973 mac->mac_suspended++;
3977 bwn_mac_enable(struct bwn_mac *mac)
3979 struct bwn_softc *sc = mac->mac_sc;
3982 DPRINTF(mac->mac_sc, BWN_DEBUG_RESET, "%s: suspended=%d\n",
3983 __func__, mac->mac_suspended);
3985 state = bwn_shm_read_2(mac, BWN_SHARED,
3994 mac->mac_suspended--;
3995 KASSERT(mac->mac_suspended >= 0,
3997 if (mac->mac_suspended == 0) {
3998 BWN_WRITE_4(mac, BWN_MACCTL,
3999 BWN_READ_4(mac, BWN_MACCTL) | BWN_MACCTL_ON);
4000 BWN_WRITE_4(mac, BWN_INTR_REASON, BWN_INTR_MAC_SUSPENDED);
4001 BWN_READ_4(mac, BWN_MACCTL);
4002 BWN_READ_4(mac, BWN_INTR_REASON);
4003 bwn_psctl(mac, 0);
4008 bwn_psctl(struct bwn_mac *mac, uint32_t flags)
4010 struct bwn_softc *sc = mac->mac_sc;
4021 BWN_WRITE_4(mac, BWN_MACCTL,
4022 (BWN_READ_4(mac, BWN_MACCTL) | BWN_MACCTL_AWAKE) &
4024 BWN_READ_4(mac, BWN_MACCTL);
4027 ucstat = bwn_shm_read_2(mac, BWN_SHARED,
4034 DPRINTF(mac->mac_sc, BWN_DEBUG_RESET, "%s: ucstat=%d\n", __func__,
4039 bwn_fw_gets(struct bwn_mac *mac, enum bwn_fwtype type)
4041 struct bwn_softc *sc = mac->mac_sc;
4042 struct bwn_fw *fw = &mac->mac_fw;
4052 if (mac->mac_phy.type == BWN_PHYTYPE_AC)
4056 if (mac->mac_phy.type == BWN_PHYTYPE_AC)
4060 if (mac->mac_phy.type == BWN_PHYTYPE_LCN40)
4064 if (mac->mac_phy.type == BWN_PHYTYPE_N)
4068 if (mac->mac_phy.type == BWN_PHYTYPE_HT)
4072 if (mac->mac_phy.type == BWN_PHYTYPE_HT)
4077 if (mac->mac_phy.type == BWN_PHYTYPE_N)
4079 else if (mac->mac_phy.type == BWN_PHYTYPE_LCN)
4083 if (mac->mac_phy.type == BWN_PHYTYPE_LCN)
4087 if (mac->mac_phy.type == BWN_PHYTYPE_N)
4094 if (mac->mac_phy.type == BWN_PHYTYPE_N)
4096 else if (mac->mac_phy.type == BWN_PHYTYPE_LP)
4122 bwn_release_firmware(mac);
4127 error = bwn_fw_get(mac, type, filename, &fw->ucode);
4129 bwn_release_firmware(mac);
4136 error = bwn_fw_get(mac, type, "pcm5", &fw->pcm);
4140 bwn_release_firmware(mac);
4145 bwn_release_firmware(mac);
4154 switch (mac->mac_phy.type) {
4200 error = bwn_fw_get(mac, type, filename, &fw->initvals);
4202 bwn_release_firmware(mac);
4207 switch (mac->mac_phy.type) {
4255 mac->mac_phy.type);
4258 error = bwn_fw_get(mac, type, filename, &fw->initvals_band);
4260 bwn_release_firmware(mac);
4266 rev, mac->mac_phy.type);
4267 bwn_release_firmware(mac);
4272 bwn_fw_get(struct bwn_mac *mac, enum bwn_fwtype type,
4276 struct bwn_softc *sc = mac->mac_sc;
4292 (mac->mac_phy.type == BWN_PHYTYPE_LP) ? "lp_" : "", name);
4329 bwn_release_firmware(struct bwn_mac *mac)
4332 bwn_do_release_fw(&mac->mac_fw.ucode);
4333 bwn_do_release_fw(&mac->mac_fw.pcm);
4334 bwn_do_release_fw(&mac->mac_fw.initvals);
4335 bwn_do_release_fw(&mac->mac_fw.initvals_band);
4349 bwn_fw_loaducode(struct bwn_mac *mac)
4355 struct bwn_softc *sc = mac->mac_sc;
4362 ctl = BWN_READ_4(mac, BWN_MACCTL);
4366 BWN_WRITE_4(mac, BWN_MACCTL, ctl);
4368 bwn_shm_write_2(mac, BWN_SCRATCH, i, 0);
4370 bwn_shm_write_2(mac, BWN_SHARED, i, 0);
4372 data = GETFWOFFSET(mac->mac_fw.ucode, sizeof(struct bwn_fwhdr));
4373 bwn_shm_ctlword(mac, BWN_UCODE | BWN_SHARED_AUTOINC, 0x0000);
4374 for (i = 0; i < GETFWSIZE(mac->mac_fw.ucode, sizeof(struct bwn_fwhdr));
4376 BWN_WRITE_4(mac, BWN_SHM_DATA, be32toh(data[i]));
4380 if (mac->mac_fw.pcm.fw) {
4381 data = GETFWOFFSET(mac->mac_fw.pcm, sizeof(struct bwn_fwhdr));
4382 bwn_shm_ctlword(mac, BWN_HW, 0x01ea);
4383 BWN_WRITE_4(mac, BWN_SHM_DATA, 0x00004000);
4384 bwn_shm_ctlword(mac, BWN_HW, 0x01eb);
4385 for (i = 0; i < GETFWSIZE(mac->mac_fw.pcm,
4387 BWN_WRITE_4(mac, BWN_SHM_DATA, be32toh(data[i]));
4392 BWN_WRITE_4(mac, BWN_INTR_REASON, BWN_INTR_ALL);
4393 BWN_WRITE_4(mac, BWN_MACCTL,
4394 (BWN_READ_4(mac, BWN_MACCTL) & ~BWN_MACCTL_MCODE_JMP0) |
4398 if (BWN_READ_4(mac, BWN_INTR_REASON) == BWN_INTR_MAC_SUSPENDED)
4407 BWN_READ_4(mac, BWN_INTR_REASON);
4409 mac->mac_fw.rev = bwn_shm_read_2(mac, BWN_SHARED, BWN_SHARED_UCODE_REV);
4410 if (mac->mac_fw.rev <= 0x128) {
4420 if (mac->mac_fw.rev >= 598)
4421 mac->mac_fw.fw_hdr_format = BWN_FW_HDR_598;
4422 else if (mac->mac_fw.rev >= 410)
4423 mac->mac_fw.fw_hdr_format = BWN_FW_HDR_410;
4425 mac->mac_fw.fw_hdr_format = BWN_FW_HDR_351;
4436 if (mac->mac_fw.fw_hdr_format == BWN_FW_HDR_598) {
4444 mac->mac_fw.patch = bwn_shm_read_2(mac, BWN_SHARED,
4446 date = bwn_shm_read_2(mac, BWN_SHARED, BWN_SHARED_UCODE_DATE);
4447 mac->mac_fw.opensource = (date == 0xffff);
4449 mac->mac_flags |= BWN_MAC_FLAG_WME;
4450 mac->mac_flags |= BWN_MAC_FLAG_HWCRYPTO;
4452 time = bwn_shm_read_2(mac, BWN_SHARED, BWN_SHARED_UCODE_TIME);
4453 if (mac->mac_fw.opensource == 0) {
4456 mac->mac_fw.rev, mac->mac_fw.patch, date, time);
4457 if (mac->mac_fw.no_pcmfile)
4461 mac->mac_fw.patch = time;
4462 fwcaps = bwn_fwcaps_read(mac);
4463 if (!(fwcaps & BWN_FWCAPS_HWCRYPTO) || mac->mac_fw.no_pcmfile) {
4466 mac->mac_flags &= ~BWN_MAC_FLAG_HWCRYPTO;
4470 mac->mac_flags &= ~BWN_MAC_FLAG_WME;
4474 if (BWN_ISOLDFMT(mac))
4480 BWN_WRITE_4(mac, BWN_MACCTL,
4481 (BWN_READ_4(mac, BWN_MACCTL) & ~BWN_MACCTL_MCODE_RUN) |
4491 bwn_fwcaps_read(struct bwn_mac *mac)
4494 KASSERT(mac->mac_fw.opensource == 1,
4496 return (bwn_shm_read_2(mac, BWN_SHARED, BWN_SHARED_FWCAPS));
4500 bwn_fwinitvals_write(struct bwn_mac *mac, const struct bwn_fwinitvals *ivals,
4509 struct bwn_softc *sc = mac->mac_sc;
4531 BWN_WRITE_4(mac, offset, be32toh(iv->data.d32));
4537 BWN_WRITE_2(mac, offset, be16toh(iv->data.d16));
4553 bwn_switch_channel(struct bwn_mac *mac, int chan)
4555 struct bwn_phy *phy = &(mac->mac_phy);
4556 struct bwn_softc *sc = mac->mac_sc;
4562 chan = phy->get_default_chan(mac);
4567 savedcookie = bwn_shm_read_2(mac, BWN_SHARED, BWN_SHARED_CHAN);
4568 bwn_shm_write_2(mac, BWN_SHARED, BWN_SHARED_CHAN, channelcookie);
4569 error = phy->switch_channel(mac, chan);
4573 mac->mac_phy.chan = chan;
4578 bwn_shm_write_2(mac, BWN_SHARED, BWN_SHARED_CHAN, savedcookie);
4603 bwn_wme_load(struct bwn_mac *mac)
4605 struct bwn_softc *sc = mac->mac_sc;
4611 bwn_mac_suspend(mac);
4613 bwn_wme_loadparams(mac, &(sc->sc_wmeParams[i]),
4615 bwn_mac_enable(mac);
4619 bwn_wme_loadparams(struct bwn_mac *mac,
4622 struct bwn_softc *sc = mac->mac_sc;
4627 slot = BWN_READ_2(mac, BWN_RNG) &
4649 tmp = bwn_shm_read_2(mac, BWN_SHARED,
4652 bwn_shm_write_2(mac, BWN_SHARED, shm_offset + (i * 2),
4655 bwn_shm_write_2(mac, BWN_SHARED, shm_offset + (i * 2),
4662 bwn_mac_write_bssid(struct bwn_mac *mac)
4664 struct bwn_softc *sc = mac->mac_sc;
4669 bwn_mac_setfilter(mac, BWN_MACFILTER_BSSID, sc->sc_bssid);
4679 bwn_ram_write(mac, 0x20 + i, tmp);
4684 bwn_mac_setfilter(struct bwn_mac *mac, uint16_t offset,
4690 if (!mac)
4694 BWN_WRITE_2(mac, BWN_MACFILTER_CONTROL, offset);
4698 BWN_WRITE_2(mac, BWN_MACFILTER_DATA, data);
4701 BWN_WRITE_2(mac, BWN_MACFILTER_DATA, data);
4704 BWN_WRITE_2(mac, BWN_MACFILTER_DATA, data);
4708 bwn_key_dowrite(struct bwn_mac *mac, uint8_t index, uint8_t algorithm,
4714 if (BWN_SEC_NEWAPI(mac))
4717 KASSERT(index < mac->mac_max_nr_keys,
4723 bwn_key_macwrite(mac, index, NULL);
4726 bwn_key_write(mac, index, algorithm, buf);
4728 bwn_key_macwrite(mac, index, mac_addr);
4730 mac->mac_key[index].algorithm = algorithm;
4734 bwn_key_macwrite(struct bwn_mac *mac, uint8_t index, const uint8_t *addr)
4736 struct bwn_softc *sc = mac->mac_sc;
4740 if (BWN_SEC_NEWAPI(mac))
4757 bwn_shm_write_4(mac, BWN_RCMTA, (index * 2) + 0, addrtmp[0]);
4758 bwn_shm_write_2(mac, BWN_RCMTA, (index * 2) + 1, addrtmp[1]);
4761 bwn_shm_write_4(mac, BWN_SHARED,
4763 bwn_shm_write_2(mac, BWN_SHARED,
4770 bwn_key_write(struct bwn_mac *mac, uint8_t index, uint8_t algorithm,
4777 kidx = BWN_SEC_KEY2FW(mac, index);
4778 bwn_shm_write_2(mac, BWN_SHARED,
4781 offset = mac->mac_ktp + (index * BWN_SEC_KEYSIZE);
4785 bwn_shm_write_2(mac, BWN_SHARED, offset + i, value);
4790 bwn_phy_exit(struct bwn_mac *mac)
4793 mac->mac_phy.rf_onoff(mac, 0);
4794 if (mac->mac_phy.exit != NULL)
4795 mac->mac_phy.exit(mac);
4799 bwn_dma_free(struct bwn_mac *mac)
4803 if ((mac->mac_flags & BWN_MAC_FLAG_DMA) == 0)
4805 dma = &mac->mac_method.dma;
4816 bwn_core_stop(struct bwn_mac *mac)
4818 struct bwn_softc *sc = mac->mac_sc;
4822 if (mac->mac_status < BWN_MAC_STATUS_STARTED)
4829 BWN_WRITE_4(mac, BWN_INTR_MASK, 0);
4830 BWN_READ_4(mac, BWN_INTR_MASK);
4831 bwn_mac_suspend(mac);
4833 mac->mac_status = BWN_MAC_STATUS_INITED;
4841 struct bwn_mac *mac;
4847 TAILQ_FOREACH(mac, &sc->sc_maclist, mac_list) {
4849 mac->mac_phy.supports_2ghz) {
4850 up_dev = mac;
4853 mac->mac_phy.supports_5ghz) {
4854 up_dev = mac;
4909 bwn_rf_turnon(struct bwn_mac *mac)
4912 DPRINTF(mac->mac_sc, BWN_DEBUG_RESET, "%s: called\n", __func__);
4914 bwn_mac_suspend(mac);
4915 mac->mac_phy.rf_onoff(mac, 1);
4916 mac->mac_phy.rf_on = 1;
4917 bwn_mac_enable(mac);
4921 bwn_rf_turnoff(struct bwn_mac *mac)
4924 DPRINTF(mac->mac_sc, BWN_DEBUG_RESET, "%s: called\n", __func__);
4926 bwn_mac_suspend(mac);
4927 mac->mac_phy.rf_onoff(mac, 0);
4928 mac->mac_phy.rf_on = 0;
4929 bwn_mac_enable(mac);
4936 bwn_phy_reset(struct bwn_mac *mac)
4942 sc = mac->mac_sc;
4969 struct bwn_mac *mac = sc->sc_curmac;
4982 bwn_led_newstate(mac, nstate);
4997 bwn_set_macaddr(mac);
5007 bwn_set_opmode(mac);
5008 bwn_set_pretbtt(mac);
5009 bwn_spu_setdelay(mac, 0);
5010 bwn_set_macaddr(mac);
5019 bwn_set_pretbtt(struct bwn_mac *mac)
5021 struct bwn_softc *sc = mac->mac_sc;
5028 pretbtt = (mac->mac_phy.type == BWN_PHYTYPE_A) ? 120 : 250;
5029 bwn_shm_write_2(mac, BWN_SHARED, BWN_SHARED_PRETBTT, pretbtt);
5030 BWN_WRITE_2(mac, BWN_TSF_CFP_PRETBTT, pretbtt);
5036 struct bwn_mac *mac = arg;
5037 struct bwn_softc *sc = mac->mac_sc;
5040 if (mac->mac_status < BWN_MAC_STATUS_STARTED ||
5046 reason = BWN_READ_4(mac, BWN_INTR_REASON);
5049 reason &= mac->mac_intr_mask;
5054 mac->mac_reason[0] = BWN_READ_4(mac, BWN_DMA0_REASON) & 0x0001dc00;
5055 mac->mac_reason[1] = BWN_READ_4(mac, BWN_DMA1_REASON) & 0x0000dc00;
5056 mac->mac_reason[2] = BWN_READ_4(mac, BWN_DMA2_REASON) & 0x0000dc00;
5057 mac->mac_reason[3] = BWN_READ_4(mac, BWN_DMA3_REASON) & 0x0001dc00;
5058 mac->mac_reason[4] = BWN_READ_4(mac, BWN_DMA4_REASON) & 0x0000dc00;
5059 BWN_WRITE_4(mac, BWN_INTR_REASON, reason);
5060 BWN_WRITE_4(mac, BWN_DMA0_REASON, mac->mac_reason[0]);
5061 BWN_WRITE_4(mac, BWN_DMA1_REASON, mac->mac_reason[1]);
5062 BWN_WRITE_4(mac, BWN_DMA2_REASON, mac->mac_reason[2]);
5063 BWN_WRITE_4(mac, BWN_DMA3_REASON, mac->mac_reason[3]);
5064 BWN_WRITE_4(mac, BWN_DMA4_REASON, mac->mac_reason[4]);
5067 BWN_WRITE_4(mac, BWN_INTR_MASK, 0);
5069 mac->mac_reason_intr = reason;
5071 BWN_BARRIER(mac, 0, 0, BUS_SPACE_BARRIER_READ|BUS_SPACE_BARRIER_WRITE);
5073 taskqueue_enqueue(sc->sc_tq, &mac->mac_intrtask);
5081 struct bwn_mac *mac = arg;
5082 struct bwn_softc *sc = mac->mac_sc;
5087 if (mac->mac_status < BWN_MAC_STATUS_STARTED ||
5093 for (i = 0; i < N(mac->mac_reason); i++)
5094 merged |= mac->mac_reason[i];
5096 if (mac->mac_reason_intr & BWN_INTR_MAC_TXERR)
5099 if (mac->mac_reason_intr & BWN_INTR_PHY_TXERR) {
5101 mac->mac_phy.txerrors--;
5102 if (mac->mac_phy.txerrors == 0) {
5103 mac->mac_phy.txerrors = BWN_TXERROR_MAX;
5104 bwn_restart(mac, "PHY TX errors");
5112 mac->mac_reason[0], mac->mac_reason[1],
5113 mac->mac_reason[2], mac->mac_reason[3],
5114 mac->mac_reason[4], mac->mac_reason[5]);
5115 bwn_restart(mac, "DMA error");
5122 mac->mac_reason[0], mac->mac_reason[1],
5123 mac->mac_reason[2], mac->mac_reason[3],
5124 mac->mac_reason[4], mac->mac_reason[5]);
5128 if (mac->mac_reason_intr & BWN_INTR_UCODE_DEBUG)
5129 bwn_intr_ucode_debug(mac);
5130 if (mac->mac_reason_intr & BWN_INTR_TBTT_INDI)
5131 bwn_intr_tbtt_indication(mac);
5132 if (mac->mac_reason_intr & BWN_INTR_ATIM_END)
5133 bwn_intr_atim_end(mac);
5134 if (mac->mac_reason_intr & BWN_INTR_BEACON)
5135 bwn_intr_beacon(mac);
5136 if (mac->mac_reason_intr & BWN_INTR_PMQ)
5137 bwn_intr_pmq(mac);
5138 if (mac->mac_reason_intr & BWN_INTR_NOISESAMPLE_OK)
5139 bwn_intr_noise(mac);
5142 if (mac->mac_flags & BWN_MAC_FLAG_DMA) {
5143 if (mac->mac_reason[0] & BWN_DMAINTR_RX_DONE) {
5144 bwn_dma_rx(mac->mac_method.dma.rx);
5148 rx = bwn_pio_rx(&mac->mac_method.pio.rx);
5151 KASSERT(!(mac->mac_reason[1] & BWN_DMAINTR_RX_DONE), ("%s", __func__));
5152 KASSERT(!(mac->mac_reason[2] & BWN_DMAINTR_RX_DONE), ("%s", __func__));
5153 KASSERT(!(mac->mac_reason[3] & BWN_DMAINTR_RX_DONE), ("%s", __func__));
5154 KASSERT(!(mac->mac_reason[4] & BWN_DMAINTR_RX_DONE), ("%s", __func__));
5155 KASSERT(!(mac->mac_reason[5] & BWN_DMAINTR_RX_DONE), ("%s", __func__));
5157 if (mac->mac_reason_intr & BWN_INTR_TX_OK) {
5158 bwn_intr_txeof(mac);
5162 BWN_WRITE_4(mac, BWN_INTR_MASK, mac->mac_intr_mask);
5181 bwn_led_event(mac, evt);
5187 BWN_BARRIER(mac, 0, 0, BUS_SPACE_BARRIER_READ|BUS_SPACE_BARRIER_WRITE);
5193 bwn_restart(struct bwn_mac *mac, const char *msg)
5195 struct bwn_softc *sc = mac->mac_sc;
5198 if (mac->mac_status < BWN_MAC_STATUS_INITED)
5202 ieee80211_runtask(ic, &mac->mac_hwreset);
5206 bwn_intr_ucode_debug(struct bwn_mac *mac)
5208 struct bwn_softc *sc = mac->mac_sc;
5211 if (mac->mac_fw.opensource == 0)
5214 reason = bwn_shm_read_2(mac, BWN_SCRATCH, BWN_DEBUGINTR_REASON_REG);
5217 bwn_handle_fwpanic(mac);
5233 bwn_shm_write_2(mac, BWN_SCRATCH, BWN_DEBUGINTR_REASON_REG,
5238 bwn_intr_tbtt_indication(struct bwn_mac *mac)
5240 struct bwn_softc *sc = mac->mac_sc;
5244 bwn_psctl(mac, 0);
5246 mac->mac_flags |= BWN_MAC_FLAG_DFQVALID;
5250 bwn_intr_atim_end(struct bwn_mac *mac)
5253 if (mac->mac_flags & BWN_MAC_FLAG_DFQVALID) {
5254 BWN_WRITE_4(mac, BWN_MACCMD,
5255 BWN_READ_4(mac, BWN_MACCMD) | BWN_MACCMD_DFQ_VALID);
5256 mac->mac_flags &= ~BWN_MAC_FLAG_DFQVALID;
5261 bwn_intr_beacon(struct bwn_mac *mac)
5263 struct bwn_softc *sc = mac->mac_sc;
5271 mac->mac_intr_mask &= ~BWN_INTR_BEACON;
5273 cmd = BWN_READ_4(mac, BWN_MACCMD);
5278 BWN_WRITE_4(mac, BWN_INTR_REASON, BWN_INTR_BEACON);
5279 mac->mac_intr_mask |= BWN_INTR_BEACON;
5285 bwn_load_beacon0(mac);
5286 bwn_load_beacon1(mac);
5287 cmd = BWN_READ_4(mac, BWN_MACCMD);
5289 BWN_WRITE_4(mac, BWN_MACCMD, cmd);
5292 bwn_load_beacon0(mac);
5293 cmd = BWN_READ_4(mac, BWN_MACCMD);
5295 BWN_WRITE_4(mac, BWN_MACCMD, cmd);
5297 bwn_load_beacon1(mac);
5298 cmd = BWN_READ_4(mac, BWN_MACCMD);
5300 BWN_WRITE_4(mac, BWN_MACCMD, cmd);
5306 bwn_intr_pmq(struct bwn_mac *mac)
5311 tmp = BWN_READ_4(mac, BWN_PS_STATUS);
5315 BWN_WRITE_2(mac, BWN_PS_STATUS, 0x0002);
5319 bwn_intr_noise(struct bwn_mac *mac)
5321 struct bwn_phy_g *pg = &mac->mac_phy.phy_g;
5327 if (mac->mac_phy.type != BWN_PHYTYPE_G)
5330 KASSERT(mac->mac_noise.noi_running, ("%s: fail", __func__));
5331 *((uint32_t *)noise) = htole32(bwn_jssi_read(mac));
5336 KASSERT(mac->mac_noise.noi_nsamples < 8,
5338 i = mac->mac_noise.noi_nsamples;
5343 mac->mac_noise.noi_samples[i][0] = pg->pg_nrssi_lt[noise[0]];
5344 mac->mac_noise.noi_samples[i][1] = pg->pg_nrssi_lt[noise[1]];
5345 mac->mac_noise.noi_samples[i][2] = pg->pg_nrssi_lt[noise[2]];
5346 mac->mac_noise.noi_samples[i][3] = pg->pg_nrssi_lt[noise[3]];
5347 mac->mac_noise.noi_nsamples++;
5348 if (mac->mac_noise.noi_nsamples == 8) {
5352 average += mac->mac_noise.noi_samples[i][j];
5355 tmp = (bwn_shm_read_2(mac, BWN_SHARED, 0x40c) / 128) & 0x1f;
5362 mac->mac_stats.link_noise = average;
5363 mac->mac_noise.noi_running = 0;
5367 bwn_noise_gensample(mac);
5373 struct bwn_mac *mac = prq->prq_mac;
5374 struct bwn_softc *sc = mac->mac_sc;
5379 if (mac->mac_status < BWN_MAC_STATUS_STARTED)
5413 bwn_intr_txeof(struct bwn_mac *mac)
5419 BWN_ASSERT_LOCKED(mac->mac_sc);
5422 stat0 = BWN_READ_4(mac, BWN_XMITSTAT_0);
5425 stat1 = BWN_READ_4(mac, BWN_XMITSTAT_1);
5427 DPRINTF(mac->mac_sc, BWN_DEBUG_XMIT,
5445 DPRINTF(mac->mac_sc, BWN_DEBUG_XMIT,
5460 bwn_handle_txeof(mac, &stat);
5467 struct bwn_mac *mac = arg;
5468 struct bwn_softc *sc = mac->mac_sc;
5474 prev_status = mac->mac_status;
5476 bwn_core_stop(mac);
5478 bwn_core_exit(mac);
5481 error = bwn_core_init(mac);
5486 bwn_core_start(mac);
5496 bwn_handle_fwpanic(struct bwn_mac *mac)
5498 struct bwn_softc *sc = mac->mac_sc;
5501 reason = bwn_shm_read_2(mac, BWN_SCRATCH, BWN_FWPANIC_REASON_REG);
5505 bwn_restart(mac, "ucode panic");
5509 bwn_load_beacon0(struct bwn_mac *mac)
5516 bwn_load_beacon1(struct bwn_mac *mac)
5523 bwn_jssi_read(struct bwn_mac *mac)
5527 val = bwn_shm_read_2(mac, BWN_SHARED, 0x08a);
5529 val |= bwn_shm_read_2(mac, BWN_SHARED, 0x088);
5535 bwn_noise_gensample(struct bwn_mac *mac)
5539 bwn_shm_write_2(mac, BWN_SHARED, 0x088, (jssi & 0x0000ffff));
5540 bwn_shm_write_2(mac, BWN_SHARED, 0x08a, (jssi & 0xffff0000) >> 16);
5541 BWN_WRITE_4(mac, BWN_MACCMD,
5542 BWN_READ_4(mac, BWN_MACCMD) | BWN_MACCMD_BGNOISE);
5568 struct bwn_mac *mac = dr->dr_mac;
5569 struct bwn_softc *sc = mac->mac_sc;
5570 struct bwn_dma *dma = &mac->mac_method.dma;
5622 switch (mac->mac_fw.fw_hdr_format) {
5633 if (!(mac->mac_sc->sc_filters & BWN_MACCTL_PASS_BADFCS)) {
5646 bwn_handle_txeof(struct bwn_mac *mac, const struct bwn_txstatus *status)
5648 struct bwn_softc *sc = mac->mac_sc;
5649 struct bwn_stats *stats = &mac->mac_stats;
5651 BWN_ASSERT_LOCKED(mac->mac_sc);
5664 if (mac->mac_flags & BWN_MAC_FLAG_DMA) {
5665 bwn_dma_handle_txeof(mac, status);
5667 bwn_pio_handle_txeof(mac, status);
5670 bwn_phy_txpower_check(mac, 0);
5676 struct bwn_mac *mac = prq->prq_mac;
5677 struct bwn_softc *sc = mac->mac_sc;
5735 switch (mac->mac_fw.fw_hdr_format) {
5746 if (!(mac->mac_sc->sc_filters & BWN_MACCTL_PASS_BADFCS)) {
5805 struct bwn_mac *mac = dr->dr_mac;
5806 struct bwn_dma *dma = &mac->mac_method.dma;
5929 bwn_rx_rssi_calc(struct bwn_mac *mac, uint8_t in_rssi,
5932 struct bwn_phy *phy = &mac->mac_phy;
5948 if (mac->mac_sc->sc_board_info.board_flags
5981 bwn_rxeof(struct bwn_mac *mac, struct mbuf *m, const void *_rxhdr)
5985 struct bwn_softc *sc = mac->mac_sc;
6004 switch (mac->mac_fw.fw_hdr_format) {
6043 BWN_ISOLDFMT(mac),
6048 rate = bwn_plcp_get_ofdmrate(mac, plcp,
6051 rate = bwn_plcp_get_cckrate(mac, plcp);
6053 if (!(mac->mac_sc->sc_filters & BWN_MACCTL_PASS_BADPLCP))
6064 rssi = bwn_rx_rssi_calc(mac, rxhdr->phy.abg.rssi,
6076 DPRINTF(mac->mac_sc, BWN_DEBUG_RECV,
6092 noise = mac->mac_stats.link_noise;
6097 bwn_rx_radiotap(mac, m, rxhdr, plcp, rate, rssi, noise);
6143 bwn_dma_handle_txeof(struct bwn_mac *mac,
6146 struct bwn_dma *dma = &mac->mac_method.dma;
6150 struct bwn_softc *sc = mac->mac_sc;
6155 dr = bwn_dma_parse_cookie(mac, status, status->cookie, &slot);
6198 bwn_pio_handle_txeof(struct bwn_mac *mac,
6203 struct bwn_softc *sc = mac->mac_sc;
6207 tq = bwn_pio_parse_cookie(mac, status->cookie, &tp);
6211 tq->tq_used -= roundup(tp->tp_m->m_pkthdr.len + BWN_HDRSIZE(mac), 4);
6230 bwn_phy_txpower_check(struct bwn_mac *mac, uint32_t flags)
6232 struct bwn_softc *sc = mac->mac_sc;
6233 struct bwn_phy *phy = &mac->mac_phy;
6249 result = phy->recalc_txpwr(mac,
6257 ieee80211_runtask(ic, &mac->mac_txpower);
6327 bwn_set_txhdr_phyctl1(struct bwn_mac *mac, uint8_t bitrate)
6329 struct bwn_phy *phy = &mac->mac_phy;
6398 bwn_set_txhdr(struct bwn_mac *mac, struct ieee80211_node *ni,
6401 const struct bwn_phy *phy = &mac->mac_phy;
6402 struct bwn_softc *sc = mac->mac_sc;
6470 switch (mac->mac_fw.fw_hdr_format) {
6503 switch (bwn_antenna_sanitize(mac, 0)) {
6550 switch (mac->mac_fw.fw_hdr_format) {
6574 switch (mac->mac_fw.fw_hdr_format) {
6592 switch (mac->mac_fw.fw_hdr_format) {
6620 txhdr->phyctl_1rts = htole16(bwn_set_txhdr_phyctl1(mac, rts_rate));
6621 txhdr->phyctl_1rtsfb = htole16(bwn_set_txhdr_phyctl1(mac, rts_rate_fb));
6626 txhdr->phyctl_1 = htole16(bwn_set_txhdr_phyctl1(mac, rate));
6627 txhdr->phyctl_1fb = htole16(bwn_set_txhdr_phyctl1(mac, rate_fb));
6630 switch (mac->mac_fw.fw_hdr_format) {
6694 bwn_antenna_sanitize(struct bwn_mac *mac, uint8_t n)
6696 struct bwn_softc *sc = mac->mac_sc;
6701 if (mac->mac_phy.gmode)
6752 bwn_pio_write_multi_4(struct bwn_mac *mac, struct bwn_pio_txqueue *tq,
6755 struct bwn_softc *sc = mac->mac_sc;
6761 bwn_pio_write_4(mac, tq, BWN_PIO8_TXCTL, ctl);
6781 bwn_pio_write_4(mac, tq, BWN_PIO8_TXCTL, ctl);
6782 bwn_pio_write_4(mac, tq, BWN_PIO8_TXDATA, value);
6789 bwn_pio_write_4(struct bwn_mac *mac, struct bwn_pio_txqueue *tq,
6793 BWN_WRITE_4(mac, tq->tq_base + offset, value);
6797 bwn_pio_write_multi_2(struct bwn_mac *mac, struct bwn_pio_txqueue *tq,
6800 struct bwn_softc *sc = mac->mac_sc;
6804 BWN_PIO_WRITE_2(mac, tq, BWN_PIO_TXCTL, ctl);
6810 BWN_PIO_WRITE_2(mac, tq, BWN_PIO_TXCTL, ctl);
6811 BWN_PIO_WRITE_2(mac, tq, BWN_PIO_TXDATA, data[len - 1]);
6818 bwn_pio_write_mbuf_2(struct bwn_mac *mac, struct bwn_pio_txqueue *tq,
6827 BWN_PIO_WRITE_2(mac, tq, BWN_PIO_TXCTL, ctl);
6836 BWN_PIO_WRITE_2(mac, tq, BWN_PIO_TXDATA, data);
6843 BWN_PIO_WRITE_2(mac, tq, BWN_PIO_TXCTL, ctl);
6844 BWN_PIO_WRITE_2(mac, tq, BWN_PIO_TXDATA, data);
6851 bwn_set_slot_time(struct bwn_mac *mac, uint16_t time)
6855 if (mac->mac_phy.type != BWN_PHYTYPE_G)
6858 BWN_WRITE_2(mac, 0x684, 510 + time);
6861 bwn_shm_write_2(mac, BWN_SHARED, 0x0010, time);
6866 bwn_dma_select(struct bwn_mac *mac, uint8_t prio)
6869 if ((mac->mac_flags & BWN_MAC_FLAG_WME) == 0)
6870 return (mac->mac_method.dma.wme[WME_AC_BE]);
6874 return (mac->mac_method.dma.wme[WME_AC_VO]);
6876 return (mac->mac_method.dma.wme[WME_AC_VI]);
6878 return (mac->mac_method.dma.wme[WME_AC_BE]);
6880 return (mac->mac_method.dma.wme[WME_AC_BK]);
6906 bwn_pio_parse_cookie(struct bwn_mac *mac, uint16_t cookie,
6909 struct bwn_pio *pio = &mac->mac_method.pio;
6945 struct bwn_mac *mac = arg;
6948 if (mac == NULL)
6951 sc = mac->mac_sc;
6954 if (mac->mac_status >= BWN_MAC_STATUS_STARTED &&
6955 mac->mac_phy.set_txpwr != NULL)
6956 mac->mac_phy.set_txpwr(mac);
6961 bwn_task_15s(struct bwn_mac *mac)
6965 if (mac->mac_fw.opensource) {
6966 reg = bwn_shm_read_2(mac, BWN_SCRATCH, BWN_WATCHDOG_REG);
6968 bwn_restart(mac, "fw watchdog");
6971 bwn_shm_write_2(mac, BWN_SCRATCH, BWN_WATCHDOG_REG, 1);
6973 if (mac->mac_phy.task_15s)
6974 mac->mac_phy.task_15s(mac);
6976 mac->mac_phy.txerrors = BWN_TXERROR_MAX;
6980 bwn_task_30s(struct bwn_mac *mac)
6983 if (mac->mac_phy.type != BWN_PHYTYPE_G || mac->mac_noise.noi_running)
6985 mac->mac_noise.noi_running = 1;
6986 mac->mac_noise.noi_nsamples = 0;
6988 bwn_noise_gensample(mac);
6992 bwn_task_60s(struct bwn_mac *mac)
6995 if (mac->mac_phy.task_60s)
6996 mac->mac_phy.task_60s(mac);
6997 bwn_phy_txpower_check(mac, BWN_TXPWR_IGNORE_TIME);
7003 struct bwn_mac *mac = arg;
7004 struct bwn_softc *sc = mac->mac_sc;
7007 if (mac->mac_status != BWN_MAC_STATUS_STARTED)
7010 if (mac->mac_task_state % 4 == 0)
7011 bwn_task_60s(mac);
7012 if (mac->mac_task_state % 2 == 0)
7013 bwn_task_30s(mac);
7014 bwn_task_15s(mac);
7016 mac->mac_task_state++;
7017 callout_reset(&sc->sc_task_ch, hz * 15, bwn_tasks, mac);
7021 bwn_plcp_get_ofdmrate(struct bwn_mac *mac, struct bwn_plcp6 *plcp, uint8_t a)
7023 struct bwn_softc *sc = mac->mac_sc;
7051 bwn_plcp_get_cckrate(struct bwn_mac *mac, struct bwn_plcp6 *plcp)
7053 struct bwn_softc *sc = mac->mac_sc;
7070 bwn_rx_radiotap(struct bwn_mac *mac, struct mbuf *m,
7074 struct bwn_softc *sc = mac->mac_sc;
7087 bwn_tsf_read(mac, &tsf);
7091 switch (mac->mac_fw.fw_hdr_format) {
7112 bwn_tsf_read(struct bwn_mac *mac, uint64_t *tsf)
7116 KASSERT(bhnd_get_hwrev(mac->mac_sc->sc_dev) >= 3,
7119 low = BWN_READ_4(mac, BWN_REV3PLUS_TSF_LOW);
7120 high = BWN_READ_4(mac, BWN_REV3PLUS_TSF_HIGH);
7127 bwn_dma_attach(struct bwn_mac *mac)
7138 dma = &mac->mac_method.dma;
7139 sc = mac->mac_sc;
7149 switch (mac->mac_dmatype) {
7175 mac->mac_dmatype);
7206 mac->mac_flags |= BWN_MAC_FLAG_DMA;
7271 dma->wme[WME_AC_BK] = bwn_dma_ringsetup(mac, 0, 1);
7275 dma->wme[WME_AC_BE] = bwn_dma_ringsetup(mac, 1, 1);
7279 dma->wme[WME_AC_VI] = bwn_dma_ringsetup(mac, 2, 1);
7283 dma->wme[WME_AC_VO] = bwn_dma_ringsetup(mac, 3, 1);
7287 dma->mcast = bwn_dma_ringsetup(mac, 4, 1);
7290 dma->rx = bwn_dma_ringsetup(mac, 0, 0);
7308 bwn_dma_parse_cookie(struct bwn_mac *mac, const struct bwn_txstatus *status,
7311 struct bwn_dma *dma = &mac->mac_method.dma;
7313 struct bwn_softc *sc = mac->mac_sc;
7315 BWN_ASSERT_LOCKED(mac->mac_sc);
7357 bwn_dma_stop(struct bwn_mac *mac)
7361 if ((mac->mac_flags & BWN_MAC_FLAG_DMA) == 0)
7363 dma = &mac->mac_method.dma;
7384 bwn_pio_stop(struct bwn_mac *mac)
7388 if (mac->mac_flags & BWN_MAC_FLAG_DMA)
7390 pio = &mac->mac_method.pio;
7400 bwn_led_attach(struct bwn_mac *mac)
7402 struct bwn_softc *sc = mac->mac_sc;
7487 bwn_led_newstate(struct bwn_mac *mac, enum ieee80211_state nstate)
7489 struct bwn_softc *sc = mac->mac_sc;
7502 val = BWN_READ_2(mac, BWN_GPIO_CONTROL);
7544 BWN_WRITE_2(mac, BWN_GPIO_CONTROL, val);
7548 bwn_led_event(struct bwn_mac *mac, int event)
7550 struct bwn_softc *sc = mac->mac_sc;
7579 bwn_led_blink_start(mac, bwn_led_duration[rate].on_dur,
7584 bwn_led_blink_start(struct bwn_mac *mac, int on_dur, int off_dur)
7586 struct bwn_softc *sc = mac->mac_sc;
7590 val = BWN_READ_2(mac, BWN_GPIO_CONTROL);
7592 BWN_WRITE_2(mac, BWN_GPIO_CONTROL, val);
7602 callout_reset(&sc->sc_led_blink_ch, on_dur, bwn_led_blink_next, mac);
7608 struct bwn_mac *mac = arg;
7609 struct bwn_softc *sc = mac->mac_sc;
7612 val = BWN_READ_2(mac, BWN_GPIO_CONTROL);
7614 BWN_WRITE_2(mac, BWN_GPIO_CONTROL, val);
7617 bwn_led_blink_end, mac);
7623 struct bwn_mac *mac = arg;
7624 struct bwn_softc *sc = mac->mac_sc;
7659 struct bwn_mac *mac = sc->sc_curmac;
7662 KASSERT(mac->mac_status >= BWN_MAC_STATUS_STARTED,
7663 ("%s: invalid MAC status %d", __func__, mac->mac_status));
7665 if (mac->mac_phy.rev >= 3 || mac->mac_phy.type == BWN_PHYTYPE_LP
7666 || mac->mac_phy.type == BWN_PHYTYPE_N) {
7667 if (!(BWN_READ_4(mac, BWN_RF_HWENABLED_HI)
7671 if (BWN_READ_2(mac, BWN_RF_HWENABLED_LO)
7676 if (mac->mac_flags & BWN_MAC_FLAG_RADIO_ON)
7684 mac->mac_flags |= BWN_MAC_FLAG_RADIO_ON;
7686 mac->mac_flags &= ~BWN_MAC_FLAG_RADIO_ON;
7691 if (cur != mac->mac_phy.rf_on) {
7693 bwn_rf_turnon(mac);
7695 bwn_rf_turnoff(mac);
7706 struct bwn_mac *mac;
7711 if ((mac = sc->sc_curmac) == NULL)
7713 stats = &mac->mac_stats;