Lines Matching +full:timer +full:- +full:cannot +full:- +full:wake +full:- +full:cpu

20 /*-
21 * Based on BSD-licensed source modules in the Linux iwlwifi driver,
34 * Copyright(c) 2007 - 2013 Intel Corporation. All rights reserved.
55 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
60 * Copyright(c) 2005 - 2013 Intel Corporation. All rights reserved.
90 /*-
91 * Copyright (c) 2007-2010 Damien Bergamini <damien.bergamini@free.fr>
173 #define mtodoff(m, t, off) ((t)((m)->m_data + (off)))
230 #define IWM_RIDX_MAX (nitems(iwm_rates)-1)
440 dlen < sizeof(l->size) + l->size * sizeof(*l->cs))
460 fws = &sc->sc_fw.img[type];
461 if (fws->fw_count >= IWM_UCODE_SECTION_MAX)
464 fwone = &fws->sec[fws->fw_count];
467 memcpy(&fwone->offset, data, sizeof(uint32_t));
470 fwone->data = data + sizeof(uint32_t);
471 fwone->len = dlen - sizeof(uint32_t);
473 fws->fw_count++;
480 /* iwlwifi: iwl-drv.c */
490 uint32_t ucode_type = le32toh(def_calib->ucode_type);
493 device_printf(sc->sc_dev,
499 sc->sc_default_calib[ucode_type].flow_trigger =
500 def_calib->calib.flow_trigger;
501 sc->sc_default_calib[ucode_type].event_trigger =
502 def_calib->calib.event_trigger;
512 uint32_t api_index = le32toh(ucode_api->api_index);
513 uint32_t api_flags = le32toh(ucode_api->api_flags);
517 device_printf(sc->sc_dev,
526 setbit(capa->enabled_api, i + 32 * api_index);
537 uint32_t api_index = le32toh(ucode_capa->api_index);
538 uint32_t api_flags = le32toh(ucode_capa->api_capa);
542 device_printf(sc->sc_dev,
551 setbit(capa->enabled_capa, i + 32 * api_index);
560 firmware_put(fw->fw_fp, FIRMWARE_UNLOAD);
561 fw->fw_fp = NULL;
562 memset(fw->img, 0, sizeof(fw->img));
568 struct iwm_fw_info *fw = &sc->sc_fw;
571 struct iwm_ucode_capabilities *capa = &sc->sc_fw.ucode_capa;
587 fwp = firmware_get(sc->cfg->fw_name);
589 device_printf(sc->sc_dev,
591 sc->cfg->fw_name, error);
594 fw->fw_fp = fwp;
596 /* (Re-)Initialize default values. */
597 capa->flags = 0;
598 capa->max_probe_length = IWM_DEFAULT_MAX_PROBE_LENGTH;
599 capa->n_scan_channels = IWM_DEFAULT_SCAN_CHANNELS;
600 memset(capa->enabled_capa, 0, sizeof(capa->enabled_capa));
601 memset(capa->enabled_api, 0, sizeof(capa->enabled_api));
602 memset(sc->sc_fw_mcc, 0, sizeof(sc->sc_fw_mcc));
608 uhdr = (const void *)fw->fw_fp->data;
609 if (*(const uint32_t *)fw->fw_fp->data != 0
610 || le32toh(uhdr->magic) != IWM_TLV_UCODE_MAGIC) {
611 device_printf(sc->sc_dev, "invalid firmware %s\n",
612 sc->cfg->fw_name);
617 snprintf(sc->sc_fwver, sizeof(sc->sc_fwver), "%u.%u (API ver %u)",
618 IWM_UCODE_MAJOR(le32toh(uhdr->ver)),
619 IWM_UCODE_MINOR(le32toh(uhdr->ver)),
620 IWM_UCODE_API(le32toh(uhdr->ver)));
621 data = uhdr->data;
622 len = fw->fw_fp->datasize - sizeof(*uhdr);
625 len -= sizeof(*tlv);
628 tlv_len = le32toh(tlv->length);
629 tlv_type = le32toh(tlv->type);
630 tlv_data = tlv->data;
633 device_printf(sc->sc_dev,
639 len -= roundup2(tlv_len, 4);
645 device_printf(sc->sc_dev,
651 capa->max_probe_length =
654 if (capa->max_probe_length >
665 device_printf(sc->sc_dev,
671 capa->flags |= IWM_UCODE_TLV_FLAGS_PAN;
675 device_printf(sc->sc_dev,
682 device_printf(sc->sc_dev,
699 capa->flags = le32_to_cpup((const uint32_t *)tlv_data);
704 device_printf(sc->sc_dev,
712 device_printf(sc->sc_dev,
720 fw->img[IWM_UCODE_REGULAR].is_dual_cpus =
722 fw->img[IWM_UCODE_INIT].is_dual_cpus =
724 fw->img[IWM_UCODE_WOWLAN].is_dual_cpus =
727 device_printf(sc->sc_dev,
737 device_printf(sc->sc_dev,
746 device_printf(sc->sc_dev,
755 device_printf(sc->sc_dev,
763 device_printf(sc->sc_dev,
771 device_printf(sc->sc_dev,
780 device_printf(sc->sc_dev,
785 sc->sc_fw.phy_config =
787 sc->sc_fw.valid_tx_ant = (sc->sc_fw.phy_config &
790 sc->sc_fw.valid_rx_ant = (sc->sc_fw.phy_config &
843 device_printf(sc->sc_dev,
849 if (paging_mem_size & (IWM_FW_PAGING_SIZE - 1)) {
850 device_printf(sc->sc_dev,
857 sc->sc_fw.img[IWM_UCODE_REGULAR].paging_mem_size =
860 sc->sc_fw.img[usniffer_img].paging_mem_size =
869 capa->n_scan_channels =
878 snprintf(sc->sc_fwver, sizeof(sc->sc_fwver),
889 device_printf(sc->sc_dev,
901 device_printf(sc->sc_dev, "firmware parse error %d, "
907 if (fw->fw_fp != NULL)
922 /* Must be aligned on a 16-byte boundary. */
923 return iwm_dma_contig_alloc(sc->sc_dmat, &sc->fw_dma,
932 return iwm_dma_contig_alloc(sc->sc_dmat, &sc->sched_dma,
933 nitems(sc->txq) * sizeof(struct iwm_agn_scd_bc_tbl), 1024);
936 /* keep-warm page is used internally by the card. see iwl-fh.h for more info */
940 return iwm_dma_contig_alloc(sc->sc_dmat, &sc->kw_dma, 4096, 4096);
947 return iwm_dma_contig_alloc(sc->sc_dmat, &sc->ict_dma,
958 ring->cur = 0;
959 if (sc->cfg->mqrx_supported) {
967 /* Allocate RX descriptors (256-byte aligned). */
969 error = iwm_dma_contig_alloc(sc->sc_dmat, &ring->free_desc_dma, size,
972 device_printf(sc->sc_dev,
976 ring->desc = ring->free_desc_dma.vaddr;
978 /* Allocate RX status area (16-byte aligned). */
979 error = iwm_dma_contig_alloc(sc->sc_dmat, &ring->stat_dma,
980 sizeof(*ring->stat), 16);
982 device_printf(sc->sc_dev,
986 ring->stat = ring->stat_dma.vaddr;
988 if (sc->cfg->mqrx_supported) {
990 error = iwm_dma_contig_alloc(sc->sc_dmat, &ring->used_desc_dma,
993 device_printf(sc->sc_dev,
1000 error = bus_dma_tag_create(sc->sc_dmat, 1, 0,
1002 IWM_RBUF_SIZE, 1, IWM_RBUF_SIZE, 0, NULL, NULL, &ring->data_dmat);
1004 device_printf(sc->sc_dev,
1011 error = bus_dmamap_create(ring->data_dmat, 0, &ring->spare_map);
1013 device_printf(sc->sc_dev,
1023 struct iwm_rx_data *data = &ring->data[i];
1024 error = bus_dmamap_create(ring->data_dmat, 0, &data->map);
1026 device_printf(sc->sc_dev,
1031 data->m = NULL;
1047 ring->cur = 0;
1053 if (sc->rxq.stat)
1054 memset(sc->rxq.stat, 0, sizeof(*sc->rxq.stat));
1062 iwm_dma_contig_free(&ring->free_desc_dma);
1063 iwm_dma_contig_free(&ring->stat_dma);
1064 iwm_dma_contig_free(&ring->used_desc_dma);
1066 count = sc->cfg->mqrx_supported ? IWM_RX_MQ_RING_COUNT :
1070 struct iwm_rx_data *data = &ring->data[i];
1072 if (data->m != NULL) {
1073 bus_dmamap_sync(ring->data_dmat, data->map,
1075 bus_dmamap_unload(ring->data_dmat, data->map);
1076 m_freem(data->m);
1077 data->m = NULL;
1079 if (data->map != NULL) {
1080 bus_dmamap_destroy(ring->data_dmat, data->map);
1081 data->map = NULL;
1084 if (ring->spare_map != NULL) {
1085 bus_dmamap_destroy(ring->data_dmat, ring->spare_map);
1086 ring->spare_map = NULL;
1088 if (ring->data_dmat != NULL) {
1089 bus_dma_tag_destroy(ring->data_dmat);
1090 ring->data_dmat = NULL;
1103 ring->qid = qid;
1104 ring->queued = 0;
1105 ring->cur = 0;
1107 /* Allocate TX descriptors (256-byte aligned). */
1109 error = iwm_dma_contig_alloc(sc->sc_dmat, &ring->desc_dma, size, 256);
1111 device_printf(sc->sc_dev,
1115 ring->desc = ring->desc_dma.vaddr;
1125 error = iwm_dma_contig_alloc(sc->sc_dmat, &ring->cmd_dma, size, 4);
1127 device_printf(sc->sc_dev,
1131 ring->cmd = ring->cmd_dma.vaddr;
1139 nsegments = IWM_MAX_SCATTER - 2;
1142 error = bus_dma_tag_create(sc->sc_dmat, 1, 0,
1144 nsegments, maxsize, 0, NULL, NULL, &ring->data_dmat);
1146 device_printf(sc->sc_dev, "could not create TX buf DMA tag\n");
1150 paddr = ring->cmd_dma.paddr;
1152 struct iwm_tx_data *data = &ring->data[i];
1154 data->cmd_paddr = paddr;
1155 data->scratch_paddr = paddr + sizeof(struct iwm_cmd_header)
1159 error = bus_dmamap_create(ring->data_dmat, 0, &data->map);
1161 device_printf(sc->sc_dev,
1166 KASSERT(paddr == ring->cmd_dma.paddr + size,
1180 struct iwm_tx_data *data = &ring->data[i];
1182 if (data->m != NULL) {
1183 bus_dmamap_sync(ring->data_dmat, data->map,
1185 bus_dmamap_unload(ring->data_dmat, data->map);
1186 m_freem(data->m);
1187 data->m = NULL;
1191 memset(ring->desc, 0, ring->desc_dma.size);
1192 bus_dmamap_sync(ring->desc_dma.tag, ring->desc_dma.map,
1194 sc->qfullmsk &= ~(1 << ring->qid);
1195 ring->queued = 0;
1196 ring->cur = 0;
1198 if (ring->qid == IWM_CMD_QUEUE && sc->cmd_hold_nic_awake)
1207 iwm_dma_contig_free(&ring->desc_dma);
1208 iwm_dma_contig_free(&ring->cmd_dma);
1211 struct iwm_tx_data *data = &ring->data[i];
1213 if (data->m != NULL) {
1214 bus_dmamap_sync(ring->data_dmat, data->map,
1216 bus_dmamap_unload(ring->data_dmat, data->map);
1217 m_freem(data->m);
1218 data->m = NULL;
1220 if (data->map != NULL) {
1221 bus_dmamap_destroy(ring->data_dmat, data->map);
1222 data->map = NULL;
1225 if (ring->data_dmat != NULL) {
1226 bus_dma_tag_destroy(ring->data_dmat);
1227 ring->data_dmat = NULL;
1232 * High-level hardware frobbing routines
1238 sc->sc_intmask = IWM_CSR_INI_SET_MASK;
1239 IWM_WRITE(sc, IWM_CSR_INT_MASK, sc->sc_intmask);
1245 IWM_WRITE(sc, IWM_CSR_INT_MASK, sc->sc_intmask);
1265 memset(sc->ict_dma.vaddr, 0, IWM_ICT_SIZE);
1266 sc->ict_cur = 0;
1273 | sc->ict_dma.paddr >> IWM_ICT_PADDR_SHIFT);
1276 sc->sc_flags |= IWM_FLAG_USE_ICT;
1278 /* Re-enable interrupts. */
1286 * Since this .. hard-resets things, it's time to actually
1295 struct ieee80211com *ic = &sc->sc_ic;
1296 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps);
1304 * FreeBSD-local: mark the first vap as not-uploaded,
1310 iv->phy_ctxt = NULL;
1311 iv->is_uploaded = 0;
1313 sc->sc_firmware_state = 0;
1314 sc->sc_flags &= ~IWM_FLAG_TE_ACTIVE;
1317 sc->sc_flags &= ~IWM_FLAG_USE_ICT;
1334 device_printf(sc->sc_dev,
1343 iwm_reset_rx_ring(sc, &sc->rxq);
1346 for (qid = 0; qid < nitems(sc->txq); qid++)
1347 iwm_reset_tx_ring(sc, &sc->txq[qid]);
1349 if (sc->cfg->device_family == IWM_DEVICE_FAMILY_7000) {
1350 /* Power-down device's busmaster DMA clocks */
1366 /* stop and reset the on-board processor */
1401 reg_val |= IWM_CSR_HW_REV_STEP(sc->sc_hw_rev) <<
1403 reg_val |= IWM_CSR_HW_REV_DASH(sc->sc_hw_rev) <<
1422 "Radio type=0x%x-0x%x-0x%x\n", radio_cfg_type,
1430 if (sc->cfg->device_family == IWM_DEVICE_FAMILY_7000) {
1451 sc->rxq.free_desc_dma.paddr);
1453 sc->rxq.used_desc_dma.paddr);
1455 sc->rxq.stat_dma.paddr);
1475 (sc->cfg->integrated ? IWM_RFH_GEN_CFG_RB_CHUNK_SIZE_64 :
1506 /* Set physical address of RX ring (256-byte aligned). */
1509 sc->rxq.free_desc_dma.paddr >> 8);
1511 /* Set physical address of RX status (16-byte aligned). */
1513 IWM_FH_RSCSR_CHNL0_STTS_WPTR_REG, sc->rxq.stat_dma.paddr >> 4);
1535 if (sc->cfg->host_interrupt_operation_mode)
1548 if (sc->cfg->mqrx_supported)
1565 /* Set physical address of "keep warm" page (16-byte aligned). */
1566 IWM_WRITE(sc, IWM_FH_KW_MEM_ADDR_REG, sc->kw_dma.paddr >> 4);
1569 for (qid = 0; qid < nitems(sc->txq); qid++) {
1570 struct iwm_tx_ring *txq = &sc->txq[qid];
1572 /* Set physical address of TX ring (256-byte aligned). */
1574 txq->desc_dma.paddr >> 8);
1578 qid, txq->desc,
1579 (unsigned long) (txq->desc_dma.paddr >> 8));
1597 if (sc->cfg->device_family == IWM_DEVICE_FAMILY_7000)
1626 device_printf(sc->sc_dev, "%s: cannot enable txq %d\n",
1648 device_printf(sc->sc_dev,
1649 "%s: cannot enable txq %d\n", __func__, qid);
1656 sc->scd_base_addr + IWM_SCD_CONTEXT_QUEUE_OFFSET(qid), 0);
1659 sc->scd_base_addr + IWM_SCD_CONTEXT_QUEUE_OFFSET(qid) +
1667 device_printf(sc->sc_dev,
1668 "%s: cannot enable txq %d\n", __func__, qid);
1696 device_printf(sc->sc_dev,
1697 "cannot enable txq %d\n", qid);
1718 int clear_dwords = (IWM_SCD_TRANS_TBL_MEM_UPPER_BOUND -
1726 sc->scd_base_addr = iwm_read_prph(sc, IWM_SCD_SRAM_BASE_ADDR);
1728 scd_base_addr != sc->scd_base_addr) {
1729 device_printf(sc->sc_dev,
1731 __func__, sc->scd_base_addr, scd_base_addr);
1738 sc->scd_base_addr + IWM_SCD_CONTEXT_MEM_LOWER_BOUND,
1747 iwm_write_prph(sc, IWM_SCD_DRAM_BASE_ADDR, sc->sched_dma.paddr >> 10);
1775 /* Enable L1-Active */
1776 if (sc->cfg->device_family < IWM_DEVICE_FAMILY_8000) {
1826 device_printf(sc->sc_dev,
1834 nvm_resp = (void *)pkt->data;
1835 ret = le16toh(nvm_resp->status);
1836 bytes_read = le16toh(nvm_resp->length);
1837 offset_read = le16toh(nvm_resp->offset);
1838 resp_data = nvm_resp->data;
1864 device_printf(sc->sc_dev,
1872 device_printf(sc->sc_dev,
1915 sc->cfg->eeprom_size) {
1916 device_printf(sc->sc_dev,
1924 "Cannot read NVM from section %d offset %d, length %d\n",
1941 /* iwlwifi/iwl-nvm-parse.c */
1970 const uint16_t * const nvm_ch_flags = sc->nvm_data->nvm_ch_flags;
1978 if (sc->cfg->device_family == IWM_DEVICE_FAMILY_7000)
1985 "Ch. %d Flags %x [%sGHz] - No traffic\n",
1999 "Ch. %d Flags %x [%sGHz] - Added\n",
2010 struct iwm_softc *sc = ic->ic_softc;
2011 struct iwm_nvm_data *data = sc->nvm_data;
2016 /* 1-13: 11b/g channels. */
2020 IWM_NUM_2GHZ_CHANNELS - 1, bands);
2025 IWM_NUM_2GHZ_CHANNELS - 1, IWM_NUM_2GHZ_CHANNELS, bands);
2027 if (data->sku_cap_band_52GHz_enable) {
2028 if (sc->cfg->device_family == IWM_DEVICE_FAMILY_7000)
2057 IEEE80211_ADDR_COPY(data->hw_addr, hw_addr);
2064 !IEEE80211_ADDR_EQ(ieee80211broadcastaddr, data->hw_addr) &&
2065 iwm_is_valid_ether_addr(data->hw_addr) &&
2066 !IEEE80211_IS_MULTICAST(data->hw_addr))
2082 data->hw_addr[0] = hw_addr[3];
2083 data->hw_addr[1] = hw_addr[2];
2084 data->hw_addr[2] = hw_addr[1];
2085 data->hw_addr[3] = hw_addr[0];
2088 data->hw_addr[4] = hw_addr[1];
2089 data->hw_addr[5] = hw_addr[0];
2094 device_printf(sc->sc_dev, "%s: mac address not found\n", __func__);
2095 memset(data->hw_addr, 0, sizeof(data->hw_addr));
2102 if (sc->cfg->device_family < IWM_DEVICE_FAMILY_8000)
2111 if (sc->cfg->device_family < IWM_DEVICE_FAMILY_8000)
2122 if (sc->cfg->device_family < IWM_DEVICE_FAMILY_8000)
2133 if (sc->cfg->device_family < IWM_DEVICE_FAMILY_8000)
2145 if (sc->cfg->device_family < IWM_DEVICE_FAMILY_8000) {
2146 data->radio_cfg_type = IWM_NVM_RF_CFG_TYPE_MSK(radio_cfg);
2147 data->radio_cfg_step = IWM_NVM_RF_CFG_STEP_MSK(radio_cfg);
2148 data->radio_cfg_dash = IWM_NVM_RF_CFG_DASH_MSK(radio_cfg);
2149 data->radio_cfg_pnum = IWM_NVM_RF_CFG_PNUM_MSK(radio_cfg);
2154 data->radio_cfg_type = IWM_NVM_RF_CFG_TYPE_MSK_8000(radio_cfg);
2155 data->radio_cfg_step = IWM_NVM_RF_CFG_STEP_MSK_8000(radio_cfg);
2156 data->radio_cfg_dash = IWM_NVM_RF_CFG_DASH_MSK_8000(radio_cfg);
2157 data->radio_cfg_pnum = IWM_NVM_RF_CFG_PNUM_MSK_8000(radio_cfg);
2158 data->valid_tx_ant = IWM_NVM_RF_CFG_TX_ANT_MSK_8000(radio_cfg);
2159 data->valid_rx_ant = IWM_NVM_RF_CFG_RX_ANT_MSK_8000(radio_cfg);
2167 if (cfg->mac_addr_from_csr) {
2171 if (sc->cfg->device_family < IWM_DEVICE_FAMILY_8000) {
2175 data->hw_addr[0] = hw_addr[1];
2176 data->hw_addr[1] = hw_addr[0];
2177 data->hw_addr[2] = hw_addr[3];
2178 data->hw_addr[3] = hw_addr[2];
2179 data->hw_addr[4] = hw_addr[5];
2180 data->hw_addr[5] = hw_addr[4];
2185 if (!iwm_is_valid_ether_addr(data->hw_addr)) {
2186 device_printf(sc->sc_dev, "no valid mac address was found\n");
2203 if (sc->cfg->device_family < IWM_DEVICE_FAMILY_8000) {
2215 data->nvm_version = iwm_get_nvm_version(sc, nvm_sw);
2221 data->sku_cap_band_24GHz_enable = sku & IWM_NVM_SKU_CAP_BAND_24GHZ;
2222 data->sku_cap_band_52GHz_enable = sku & IWM_NVM_SKU_CAP_BAND_52GHZ;
2223 data->sku_cap_11n_enable = sku & IWM_NVM_SKU_CAP_11N_ENABLE;
2224 data->sku_cap_mimo_disable = sku & IWM_NVM_SKU_CAP_MIMO_DISABLE;
2226 data->n_hw_addrs = iwm_get_n_hw_addrs(sc, nvm_sw);
2228 if (sc->cfg->device_family >= IWM_DEVICE_FAMILY_8000) {
2230 uint16_t lar_offset = data->nvm_version < 0xE39 ?
2235 data->lar_enabled = !!(lar_config &
2239 /* If no valid mac address was found - bail out */
2245 if (sc->cfg->device_family == IWM_DEVICE_FAMILY_7000) {
2246 memcpy(data->nvm_ch_flags, sc->cfg->nvm_type == IWM_NVM_SDP ?
2250 memcpy(data->nvm_ch_flags, &regulatory[IWM_NVM_CHANNELS_8000],
2270 if (sc->cfg->device_family == IWM_DEVICE_FAMILY_7000) {
2272 !sections[sc->cfg->nvm_hw_section_num].data) {
2273 device_printf(sc->sc_dev,
2277 } else if (sc->cfg->device_family >= IWM_DEVICE_FAMILY_8000) {
2281 device_printf(sc->sc_dev,
2286 if (!sections[sc->cfg->nvm_hw_section_num].data &&
2288 device_printf(sc->sc_dev,
2295 device_printf(sc->sc_dev,
2300 panic("unknown device family %d\n", sc->cfg->device_family);
2303 hw = (const uint16_t *) sections[sc->cfg->nvm_hw_section_num].data;
2307 regulatory = sc->cfg->nvm_type == IWM_NVM_SDP ?
2329 if (sc->cfg->nvm_hw_section_num >= IWM_NVM_NUM_OF_SECTIONS)
2336 nvm_buffer = malloc(sc->cfg->eeprom_size, M_DEVBUF, M_NOWAIT | M_ZERO);
2357 device_printf(sc->sc_dev, "OTP is blank\n");
2360 sc->nvm_data = iwm_parse_nvm_sections(sc, nvm_sections);
2361 if (!sc->nvm_data)
2364 "nvm version = %x\n", sc->nvm_data->nvm_version);
2378 struct iwm_dma_info *dma = &sc->fw_dma;
2381 uint32_t offset, chunk_sz = MIN(IWM_FH_MEM_TB_MAX_LENGTH, section->len);
2388 v_addr = dma->vaddr;
2389 p_addr = dma->paddr;
2391 for (offset = 0; offset < section->len; offset += chunk_sz) {
2395 copy_size = MIN(chunk_sz, section->len - offset);
2396 dst_addr = section->offset + offset;
2406 memcpy(v_addr, (const uint8_t *)section->data + offset,
2408 bus_dmamap_sync(dma->tag, dma->map, BUS_DMASYNC_PREWRITE);
2417 device_printf(sc->sc_dev,
2434 sc->sc_fw_chunk_done = 0;
2465 msleep(&sc->sc_fw, &sc->sc_mtx, 0, "iwmfw", hz * 5);
2467 if (!sc->sc_fw_chunk_done) {
2468 device_printf(sc->sc_dev,
2479 const struct iwm_fw_img *image, int cpu, int *first_ucode_section)
2485 if (cpu == 1) {
2497 * CPU1_CPU2_SEPARATOR_SECTION delimiter - separate between
2499 * PAGING_SEPARATOR_SECTION delimiter - separate between
2502 if (!image->sec[i].data ||
2503 image->sec[i].offset == IWM_CPU1_CPU2_SEPARATOR_SECTION ||
2504 image->sec[i].offset == IWM_PAGING_SEPARATOR_SECTION) {
2510 ret = iwm_pcie_load_section(sc, i, &image->sec[i]);
2529 if (cpu == 1)
2541 const struct iwm_fw_img *image, int cpu, int *first_ucode_section)
2546 if (cpu == 1) {
2556 * CPU1_CPU2_SEPARATOR_SECTION delimiter - separate between
2558 * PAGING_SEPARATOR_SECTION delimiter - separate between
2561 if (!image->sec[i].data ||
2562 image->sec[i].offset == IWM_CPU1_CPU2_SEPARATOR_SECTION ||
2563 image->sec[i].offset == IWM_PAGING_SEPARATOR_SECTION) {
2570 ret = iwm_pcie_load_section(sc, i, &image->sec[i]);
2587 IWM_DPRINTF(sc, IWM_DEBUG_RESET, "working with %s CPU\n",
2588 image->is_dual_cpus ? "Dual" : "Single");
2595 if (image->is_dual_cpus) {
2613 /* release CPU reset */
2626 IWM_DPRINTF(sc, IWM_DEBUG_RESET, "working with %s CPU\n",
2627 image->is_dual_cpus ? "Dual" : "Single");
2630 /* release CPU reset */
2653 sc->sc_intmask = IWM_CSR_INT_BIT_FH_TX;
2654 IWM_WRITE(sc, IWM_CSR_INT_MASK, sc->sc_intmask);
2665 device_printf(sc->sc_dev,
2685 device_printf(sc->sc_dev, "%s: Unable to init nic\n", __func__);
2691 * by the RF-Kill interrupt (hence mask all the interrupt besides the
2693 * RF-Kill switch is toggled, we will find out after having loaded
2704 if (sc->cfg->device_family >= IWM_DEVICE_FAMILY_8000)
2709 /* XXX re-check RF-Kill state */
2731 enum iwm_ucode_type ucode_type = sc->cur_ucode;
2736 sc->sc_default_calib[ucode_type].event_trigger;
2738 sc->sc_default_calib[ucode_type].flow_trigger;
2758 palive = (void *)pkt->data;
2759 umac = &palive->umac_data;
2760 lmac1 = &palive->lmac_data[0];
2761 lmac2 = &palive->lmac_data[1];
2762 status = le16toh(palive->status);
2764 palive3 = (void *)pkt->data;
2765 umac = &palive3->umac_data;
2766 lmac1 = &palive3->lmac_data;
2767 status = le16toh(palive3->status);
2770 sc->error_event_table[0] = le32toh(lmac1->error_event_table_ptr);
2772 sc->error_event_table[1] =
2773 le32toh(lmac2->error_event_table_ptr);
2774 sc->log_event_table = le32toh(lmac1->log_event_table_ptr);
2775 sc->umac_error_event_table = le32toh(umac->error_info_addr);
2776 alive_data->scd_base_addr = le32toh(lmac1->scd_base_ptr);
2777 alive_data->valid = status == IWM_ALIVE_STATUS_OK;
2778 if (sc->umac_error_event_table)
2779 sc->support_umac_log = TRUE;
2783 status, lmac1->ver_type, lmac1->ver_subtype);
2789 "UMAC version: Major - 0x%x, Minor - 0x%x\n",
2790 le32toh(umac->umac_major),
2791 le32toh(umac->umac_minor));
2802 if (pkt->hdr.code != IWM_CALIB_RES_NOTIF_PHY_DB) {
2803 if(pkt->hdr.code != IWM_INIT_COMPLETE_NOTIF) {
2804 device_printf(sc->sc_dev, "%s: Unexpected cmd: %d\n",
2805 __func__, pkt->hdr.code);
2811 device_printf(sc->sc_dev,
2825 enum iwm_ucode_type old_type = sc->cur_ucode;
2829 fw = &sc->sc_fw.img[ucode_type];
2830 sc->cur_ucode = ucode_type;
2831 sc->ucode_loaded = FALSE;
2834 iwm_init_notification_wait(sc->sc_notif_wait, &alive_wait,
2840 device_printf(sc->sc_dev, "iwm_start_fw: failed %d\n", error);
2841 sc->cur_ucode = old_type;
2842 iwm_remove_notification(sc->sc_notif_wait, &alive_wait);
2851 error = iwm_wait_notification(sc->sc_notif_wait, &alive_wait,
2855 if (sc->cfg->device_family >= IWM_DEVICE_FAMILY_8000) {
2862 device_printf(sc->sc_dev,
2866 sc->cur_ucode = old_type;
2871 device_printf(sc->sc_dev, "%s: Loaded ucode is not valid\n",
2873 sc->cur_ucode = old_type;
2884 if (fw->paging_mem_size) {
2887 device_printf(sc->sc_dev,
2895 device_printf(sc->sc_dev,
2903 sc->ucode_loaded = TRUE;
2925 if ((sc->sc_flags & IWM_FLAG_RFKILL) && !justnvm) {
2926 device_printf(sc->sc_dev,
2931 iwm_init_notification_wait(sc->sc_notif_wait,
2936 sc->sc_phy_db);
2941 device_printf(sc->sc_dev, "Failed to start INIT ucode: %d\n",
2946 if (sc->cfg->device_family < IWM_DEVICE_FAMILY_8000) {
2949 device_printf(sc->sc_dev,
2959 device_printf(sc->sc_dev, "failed to read nvm\n");
2962 IEEE80211_ADDR_COPY(sc->sc_ic.ic_macaddr, sc->nvm_data->hw_addr);
2969 device_printf(sc->sc_dev,
2980 device_printf(sc->sc_dev,
2991 ret = iwm_wait_notification(sc->sc_notif_wait, &calib_wait,
2999 iwm_remove_notification(sc->sc_notif_wait, &calib_wait);
3011 if (!sc->sc_ltr_enabled)
3021 /* (re)stock rx ring, called at init-time and at runtime */
3025 struct iwm_rx_ring *ring = &sc->rxq;
3026 struct iwm_rx_data *data = &ring->data[idx];
3036 m->m_len = m->m_pkthdr.len = m->m_ext.ext_size;
3037 error = bus_dmamap_load_mbuf_sg(ring->data_dmat, ring->spare_map, m,
3040 device_printf(sc->sc_dev,
3046 if (data->m != NULL)
3047 bus_dmamap_unload(ring->data_dmat, data->map);
3049 /* Swap ring->spare_map with data->map */
3050 dmamap = data->map;
3051 data->map = ring->spare_map;
3052 ring->spare_map = dmamap;
3054 bus_dmamap_sync(ring->data_dmat, data->map, BUS_DMASYNC_PREREAD);
3055 data->m = m;
3059 if (sc->cfg->mqrx_supported)
3060 ((uint64_t *)ring->desc)[idx] = htole64(seg.ds_addr);
3062 ((uint32_t *)ring->desc)[idx] = htole32(seg.ds_addr >> 8);
3063 bus_dmamap_sync(ring->free_desc_dma.tag, ring->free_desc_dma.map,
3072 struct iwm_rx_phy_info *phy_info = (void *)pkt->data;
3076 memcpy(&sc->sc_last_phy_info, phy_info, sizeof(sc->sc_last_phy_info));
3095 noise = le32toh(stats->beacon_silence_rssi[i]) & 0xff;
3111 return (nbant == 0) ? -127 : (total / nbant) - 107;
3113 /* For now, just hard-code it to -96 to be safe */
3114 return (-96);
3121 struct iwm_notif_statistics *stats = (void *)&pkt->data;
3123 memcpy(&sc->sc_stats, stats, sizeof(sc->sc_stats));
3124 sc->sc_noise = iwm_get_noise(sc, &stats->rx.general);
3129 * iwm_get_signal_strength - use new rx PHY INFO API
3130 * values are reported by the fw as positive values - need to negate
3132 * values by -256dBm: practically 0 power and a non-feasible 8 bit value.
3141 val = le32toh(phy_info->non_cfg_phy[IWM_RX_INFO_ENERGY_ANT_ABC_IDX]);
3144 energy_a = energy_a ? -energy_a : -256;
3147 energy_b = energy_b ? -energy_b : -256;
3150 energy_c = energy_c ? -energy_c : -256;
3167 energy_a = desc->v1.energy_a;
3168 energy_b = desc->v1.energy_b;
3169 energy_a = energy_a ? -energy_a : -256;
3170 energy_b = energy_b ? -energy_b : -256;
3175 * iwm_rx_rx_mpdu - IWM_REPLY_RX_MPDU_CMD handler
3183 struct ieee80211com *ic = &sc->sc_ic;
3184 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps);
3193 phy_info = &sc->sc_last_phy_info;
3194 rx_res = (struct iwm_rx_mpdu_res_start *)pkt->data;
3195 len = le16toh(rx_res->byte_count);
3196 rx_pkt_status = le32toh(*(uint32_t *)(pkt->data + sizeof(*rx_res) + len));
3198 if (__predict_false(phy_info->cfg_phy_cnt > 20)) {
3199 device_printf(sc->sc_dev,
3201 phy_info->cfg_phy_cnt);
3215 rssi = rssi - sc->sc_noise;
3218 if (!stolen && iwm_rx_addbuf(sc, IWM_RBUF_SIZE, sc->rxq.cur) != 0) {
3219 device_printf(sc->sc_dev, "%s: unable to add more buffers\n",
3224 m->m_data = pkt->data + sizeof(*rx_res);
3225 m->m_pkthdr.len = m->m_len = len;
3228 "%s: rssi=%d, noise=%d\n", __func__, rssi, sc->sc_noise);
3233 le16toh(phy_info->channel),
3234 le16toh(phy_info->phy_flags));
3243 rxs.c_ieee = le16toh(phy_info->channel);
3244 if (le16toh(phy_info->phy_flags & IWM_RX_RES_PHY_FLAGS_BAND_24)) {
3254 rxs.c_nf = sc->sc_noise;
3259 struct iwm_rx_radiotap_header *tap = &sc->sc_rxtap;
3261 tap->wr_flags = 0;
3262 if (phy_info->phy_flags & htole16(IWM_PHY_INFO_FLAG_SHPREAMBLE))
3263 tap->wr_flags |= IEEE80211_RADIOTAP_F_SHORTPRE;
3264 tap->wr_chan_freq = htole16(rxs.c_freq);
3265 /* XXX only if ic->ic_curchan->ic_ieee == rxs.c_ieee */
3266 tap->wr_chan_flags = htole16(ic->ic_curchan->ic_flags);
3267 tap->wr_dbm_antsignal = (int8_t)rssi;
3268 tap->wr_dbm_antnoise = (int8_t)sc->sc_noise;
3269 tap->wr_tsft = phy_info->system_timestamp;
3270 switch (phy_info->rate) {
3272 case 10: tap->wr_rate = 2; break;
3273 case 20: tap->wr_rate = 4; break;
3274 case 55: tap->wr_rate = 11; break;
3275 case 110: tap->wr_rate = 22; break;
3277 case 0xd: tap->wr_rate = 12; break;
3278 case 0xf: tap->wr_rate = 18; break;
3279 case 0x5: tap->wr_rate = 24; break;
3280 case 0x7: tap->wr_rate = 36; break;
3281 case 0x9: tap->wr_rate = 48; break;
3282 case 0xb: tap->wr_rate = 72; break;
3283 case 0x1: tap->wr_rate = 96; break;
3284 case 0x3: tap->wr_rate = 108; break;
3286 default: tap->wr_rate = 0;
3297 struct ieee80211com *ic = &sc->sc_ic;
3298 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps);
3309 desc = (void *)pkt->data;
3311 if (!(desc->status & htole16(IWM_RX_MPDU_RES_STATUS_CRC_OK)) ||
3312 !(desc->status & htole16(IWM_RX_MPDU_RES_STATUS_OVERRUN_OK))) {
3314 "Bad CRC or FIFO: 0x%08X.\n", desc->status);
3318 channel = desc->v1.channel;
3319 len = le16toh(desc->mpdu_len);
3320 phy_info = le16toh(desc->phy_info);
3321 rate_n_flags = desc->v1.rate_n_flags;
3324 m->m_data = pkt->data + sizeof(*desc);
3325 m->m_pkthdr.len = m->m_len = len;
3326 m->m_len = len;
3329 if ((desc->mac_flags2 & IWM_RX_MPDU_MFLG2_PAD)) {
3332 m->m_data = mtodo(m, 2);
3338 rssi = rssi - sc->sc_noise;
3341 if (!stolen && iwm_rx_addbuf(sc, IWM_RBUF_SIZE, sc->rxq.cur) != 0) {
3342 device_printf(sc->sc_dev, "%s: unable to add more buffers\n",
3348 "%s: rssi=%d, noise=%d\n", __func__, rssi, sc->sc_noise);
3364 rxs.c_nf = sc->sc_noise;
3369 struct iwm_rx_radiotap_header *tap = &sc->sc_rxtap;
3371 tap->wr_flags = 0;
3373 tap->wr_flags |= IEEE80211_RADIOTAP_F_SHORTPRE;
3374 tap->wr_chan_freq = htole16(rxs.c_freq);
3375 /* XXX only if ic->ic_curchan->ic_ieee == rxs.c_ieee */
3376 tap->wr_chan_flags = htole16(ic->ic_curchan->ic_flags);
3377 tap->wr_dbm_antsignal = (int8_t)rssi;
3378 tap->wr_dbm_antnoise = (int8_t)sc->sc_noise;
3379 tap->wr_tsft = desc->v1.gp2_on_air_rise;
3382 case 10: tap->wr_rate = 2; break;
3383 case 20: tap->wr_rate = 4; break;
3384 case 55: tap->wr_rate = 11; break;
3385 case 110: tap->wr_rate = 22; break;
3387 case 0xd: tap->wr_rate = 12; break;
3388 case 0xf: tap->wr_rate = 18; break;
3389 case 0x5: tap->wr_rate = 24; break;
3390 case 0x7: tap->wr_rate = 36; break;
3391 case 0x9: tap->wr_rate = 48; break;
3392 case 0xb: tap->wr_rate = 72; break;
3393 case 0x1: tap->wr_rate = 96; break;
3394 case 0x3: tap->wr_rate = 108; break;
3396 default: tap->wr_rate = 0;
3412 ic = &sc->sc_ic;
3414 ret = sc->cfg->mqrx_supported ?
3418 counter_u64_add(ic->ic_ierrors, 1);
3443 struct iwm_tx_resp *tx_resp = (void *)pkt->data;
3444 struct ieee80211_ratectl_tx_status *txs = &sc->sc_txs;
3445 struct ieee80211_node *ni = &in->in_ni;
3446 struct ieee80211vap *vap = ni->ni_vap;
3447 int status = le16toh(tx_resp->status.status) & IWM_TX_STATUS_MSK;
3448 int new_rate, cur_rate = vap->iv_bss->ni_txrate;
3452 KASSERT(tx_resp->frame_count == 1, ("too many frames"));
3457 (int) le16toh(tx_resp->status.status),
3458 (int) le16toh(tx_resp->status.sequence),
3459 tx_resp->frame_count,
3460 tx_resp->bt_kill_count,
3461 tx_resp->failure_rts,
3462 tx_resp->failure_frame,
3463 le32toh(tx_resp->initial_rate),
3464 (int) le16toh(tx_resp->wireless_media_time));
3466 tx_resp_rate = iwm_rate_from_ucode_rate(le32toh(tx_resp->initial_rate));
3477 txs->flags = IEEE80211_RATECTL_STATUS_SHORT_RETRY |
3479 txs->short_retries = tx_resp->failure_rts;
3480 txs->long_retries = tx_resp->failure_frame;
3485 txs->status = IEEE80211_RATECTL_TX_FAIL_SHORT;
3488 txs->status = IEEE80211_RATECTL_TX_FAIL_LONG;
3491 txs->status = IEEE80211_RATECTL_TX_FAIL_EXPIRED;
3494 txs->status = IEEE80211_RATECTL_TX_FAIL_UNSPECIFIED;
3498 txs->status = IEEE80211_RATECTL_TX_SUCCESS;
3504 int rix = ieee80211_ratectl_rate(vap->iv_bss, NULL, 0);
3505 new_rate = vap->iv_bss->ni_txrate;
3507 struct iwm_node *in = IWM_NODE(vap->iv_bss);
3509 iwm_send_lq_cmd(sc, &in->in_lq, FALSE);
3513 return (txs->status != IEEE80211_RATECTL_TX_SUCCESS);
3526 cmd_hdr = &pkt->hdr;
3527 idx = cmd_hdr->idx;
3528 qid = cmd_hdr->qid;
3530 ring = &sc->txq[qid];
3531 txd = &ring->data[idx];
3532 in = txd->in;
3533 m = txd->m;
3535 KASSERT(txd->done == 0, ("txd not done"));
3536 KASSERT(txd->in != NULL, ("txd without node"));
3537 KASSERT(txd->m != NULL, ("txd without mbuf"));
3539 sc->sc_tx_timer = 0;
3544 bus_dmamap_sync(ring->data_dmat, txd->map, BUS_DMASYNC_POSTWRITE);
3545 bus_dmamap_unload(ring->data_dmat, txd->map);
3548 "free txd %p, in %p\n", txd, txd->in);
3549 txd->done = 1;
3550 txd->m = NULL;
3551 txd->in = NULL;
3553 ieee80211_tx_complete(&in->in_ni, m, status);
3556 if (--ring->queued < IWM_TX_RING_LOMARK && (sc->qfullmsk & qmsk) != 0) {
3557 sc->qfullmsk &= ~qmsk;
3558 if (sc->qfullmsk == 0)
3575 struct iwm_tx_ring *ring = &sc->txq[IWM_CMD_QUEUE];
3578 if (pkt->hdr.qid != IWM_CMD_QUEUE) {
3585 pkt->hdr.code, pkt->hdr.qid, pkt->hdr.idx);
3587 data = &ring->data[pkt->hdr.idx];
3590 if (data->m != NULL) {
3591 bus_dmamap_sync(ring->data_dmat, data->map,
3593 bus_dmamap_unload(ring->data_dmat, data->map);
3594 m_freem(data->m);
3595 data->m = NULL;
3597 wakeup(&ring->desc[pkt->hdr.idx]);
3599 if (((pkt->hdr.idx + ring->queued) % IWM_TX_RING_COUNT) != ring->cur) {
3600 device_printf(sc->sc_dev,
3602 __func__, pkt->hdr.idx, ring->queued, ring->cur);
3606 KASSERT(ring->queued > 0, ("ring->queued is empty?"));
3607 ring->queued--;
3608 if (ring->queued == 0)
3623 scd_bc_tbl = sc->sched_dma.vaddr;
3632 bus_dmamap_sync(sc->sched_dma.tag, sc->sched_dma.map,
3638 bus_dmamap_sync(sc->sched_dma.tag, sc->sched_dma.map,
3668 struct ieee80211_node *ni = &in->in_ni;
3670 const struct ieee80211_txparam *tp = ni->ni_txparms;
3676 type = wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK;
3678 tx->rts_retry_limit = IWM_RTS_DFAULT_RETRY_LIMIT;
3679 tx->data_retry_limit = IWM_DEFAULT_TX_RETRY;
3683 (m->m_flags & M_EAPOL) != 0) {
3684 ridx = iwm_tx_rateidx_global_lookup(sc, tp->mgmtrate);
3686 "%s: MGT (%d)\n", __func__, tp->mgmtrate);
3687 } else if (IEEE80211_IS_MULTICAST(wh->i_addr1)) {
3688 ridx = iwm_tx_rateidx_global_lookup(sc, tp->mcastrate);
3690 "%s: MCAST (%d)\n", __func__, tp->mcastrate);
3691 } else if (tp->ucastrate != IEEE80211_FIXED_RATE_NONE) {
3692 ridx = iwm_tx_rateidx_global_lookup(sc, tp->ucastrate);
3694 "%s: FIXED_RATE (%d)\n", __func__, tp->ucastrate);
3698 ridx = iwm_rate2ridx(sc, ni->ni_txrate);
3699 if (ridx == -1)
3703 tx->initial_rate_index = 0;
3704 tx->tx_flags |= htole32(IWM_TX_CMD_FLG_STA_RATE);
3715 rinfo->rate,
3719 /* XXX TODO: hard-coded TX antenna? */
3720 if (sc->cfg->device_family == IWM_DEVICE_FAMILY_9000)
3726 tx->rate_n_flags = htole32(rate_flags | rinfo->plcp);
3735 struct ieee80211com *ic = &sc->sc_ic;
3736 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps);
3756 type = wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK;
3758 ring = &sc->txq[ac];
3759 desc = &ring->desc[ring->cur];
3760 data = &ring->data[ring->cur];
3763 cmd = &ring->cmd[ring->cur];
3764 cmd->hdr.code = IWM_TX_CMD;
3765 cmd->hdr.flags = 0;
3766 cmd->hdr.qid = ring->qid;
3767 cmd->hdr.idx = ring->cur;
3769 tx = (void *)cmd->data;
3775 if (wh->i_fc[1] & IEEE80211_FC1_PROTECTED) {
3787 struct iwm_tx_radiotap_header *tap = &sc->sc_txtap;
3789 tap->wt_flags = 0;
3790 tap->wt_chan_freq = htole16(ni->ni_chan->ic_freq);
3791 tap->wt_chan_flags = htole16(ni->ni_chan->ic_flags);
3792 tap->wt_rate = rinfo->rate;
3794 tap->wt_flags |= IEEE80211_RADIOTAP_F_WEP;
3799 totlen = m->m_pkthdr.len;
3800 if (!IEEE80211_IS_MULTICAST(wh->i_addr1)) {
3805 totlen + IEEE80211_CRC_LEN > vap->iv_rtsthreshold &&
3806 !IEEE80211_IS_MULTICAST(wh->i_addr1)) {
3810 tx->sta_id = IWM_STATION_ID;
3813 uint8_t subtype = wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK;
3817 tx->pm_frame_timeout = htole16(IWM_PM_FRAME_ASSOC);
3819 tx->pm_frame_timeout = htole16(IWM_PM_FRAME_NONE);
3821 tx->pm_frame_timeout = htole16(IWM_PM_FRAME_MGMT);
3824 tx->pm_frame_timeout = htole16(IWM_PM_FRAME_NONE);
3830 tx->offload_assist |= htole16(IWM_TX_CMD_OFFLD_PAD);
3831 pad = 4 - (hdrlen & 3);
3833 tx->offload_assist = 0;
3837 tx->len = htole16(totlen);
3838 tx->tid_tspec = tid;
3839 tx->life_time = htole32(IWM_TX_CMD_LIFE_TIME_INFINITE);
3842 tx->dram_lsb_ptr = htole32(data->scratch_paddr);
3843 tx->dram_msb_ptr = iwm_get_dma_hi_addr(data->scratch_paddr);
3850 tx->sec_ctl = 0;
3851 tx->tx_flags |= htole32(flags);
3855 error = bus_dmamap_load_mbuf_sg(ring->data_dmat, data->map, m,
3859 device_printf(sc->sc_dev, "can't map mbuf (error %d)\n",
3865 m1 = m_collapse(m, M_NOWAIT, IWM_MAX_SCATTER - 2);
3867 device_printf(sc->sc_dev,
3874 error = bus_dmamap_load_mbuf_sg(ring->data_dmat, data->map, m,
3877 device_printf(sc->sc_dev, "can't map mbuf (error %d)\n",
3883 data->m = m;
3884 data->in = in;
3885 data->done = 0;
3888 "sending txd %p, in %p\n", data, data->in);
3889 KASSERT(data->in != NULL, ("node is NULL"));
3893 ring->qid, ring->cur, totlen, nsegs,
3894 le32toh(tx->tx_flags),
3895 le32toh(tx->rate_n_flags),
3896 tx->initial_rate_index
3901 desc->num_tbs = 2 + nsegs;
3903 desc->tbs[0].lo = htole32(data->cmd_paddr);
3904 desc->tbs[0].hi_n_len = htole16(iwm_get_dma_hi_addr(data->cmd_paddr) |
3906 desc->tbs[1].lo = htole32(data->cmd_paddr + TB0_SIZE);
3907 desc->tbs[1].hi_n_len = htole16(iwm_get_dma_hi_addr(data->cmd_paddr) |
3909 hdrlen + pad - TB0_SIZE) << 4));
3914 desc->tbs[i + 2].lo = htole32(seg->ds_addr);
3915 desc->tbs[i + 2].hi_n_len =
3916 htole16(iwm_get_dma_hi_addr(seg->ds_addr)) |
3917 (seg->ds_len << 4);
3920 bus_dmamap_sync(ring->data_dmat, data->map,
3922 bus_dmamap_sync(ring->cmd_dma.tag, ring->cmd_dma.map,
3924 bus_dmamap_sync(ring->desc_dma.tag, ring->desc_dma.map,
3928 iwm_update_sched(sc, ring->qid, ring->cur, tx->sta_id, le16toh(tx->len));
3932 ring->cur = (ring->cur + 1) % IWM_TX_RING_COUNT;
3933 IWM_WRITE(sc, IWM_HBUS_TARG_WRPTR, ring->qid << 8 | ring->cur);
3936 if (++ring->queued > IWM_TX_RING_HIMARK) {
3937 sc->qfullmsk |= 1 << ring->qid;
3947 struct ieee80211com *ic = ni->ni_ic;
3948 struct iwm_softc *sc = ic->ic_softc;
3952 "->%s begin\n", __func__);
3954 if ((sc->sc_flags & IWM_FLAG_HW_INITED) == 0) {
3957 "<-%s not RUNNING\n", __func__);
3968 if (sc->sc_tx_timer == 0)
3969 callout_reset(&sc->sc_watchdog_to, hz, iwm_watchdog, sc);
3970 sc->sc_tx_timer = 5;
3983 * queue might not be empty. The race-free way to handle this is to:
4000 device_printf(sc->sc_dev,
4014 int colors[IWM_MAX_BINDINGS] = { -1, -1, -1, -1, };
4022 id = ivp->phy_ctxt->id;
4024 colors[id] = ivp->phy_ctxt->color;
4071 device_printf(sc->sc_dev,
4101 ni = ieee80211_ref_node(vap->iv_bss);
4109 __func__, ether_sprintf(ni->ni_bssid));
4111 in->in_assoc = 0;
4112 iv->iv_auth = 1;
4115 * Firmware bug - it'll crash if the beacon interval is less
4121 if (ni->ni_intval < 16) {
4122 device_printf(sc->sc_dev,
4124 ether_sprintf(ni->ni_bssid), ni->ni_intval);
4131 device_printf(sc->sc_dev,
4143 * The openbsd port doesn't attempt to do that - it reset things
4148 * the NIC back to IDLE, re-setup and re-add all the mac/phy
4151 if (iv->is_uploaded) {
4153 device_printf(sc->sc_dev,
4159 device_printf(sc->sc_dev,
4164 sc->sc_firmware_state = 1;
4166 if ((error = iwm_phy_ctxt_changed(sc, &sc->sc_phyctxt[0],
4167 in->in_ni.ni_chan, 1, 1)) != 0) {
4168 device_printf(sc->sc_dev,
4172 iv->phy_ctxt = &sc->sc_phyctxt[0];
4175 device_printf(sc->sc_dev,
4179 sc->sc_firmware_state = 2;
4185 iv->ps_disabled = TRUE;
4187 iv->ps_disabled = FALSE;
4189 device_printf(sc->sc_dev,
4195 device_printf(sc->sc_dev,
4199 sc->sc_firmware_state = 3;
4212 iv->iv_auth = 0;
4243 for (i = 0; i < rs->rs_nrates; i++) {
4244 rval = (rs->rs_rates[i] & IEEE80211_RATE_VAL);
4246 return rs->rs_rates[i];
4262 device_printf(sc->sc_dev,
4266 return -1;
4273 struct ieee80211_node *ni = &in->in_ni;
4274 struct iwm_lq_cmd *lq = &in->in_lq;
4275 struct ieee80211_rateset *rs = &ni->ni_rates;
4276 int nrates = rs->rs_nrates;
4282 if (nrates > nitems(lq->rs_table)) {
4283 device_printf(sc->sc_dev,
4285 "only %zu\n", __func__, nrates, nitems(lq->rs_table));
4289 device_printf(sc->sc_dev,
4300 lq->sta_id = IWM_STATION_ID;
4303 if (ni->ni_flags & IEEE80211_NODE_HT)
4304 lq->flags |= IWM_LQ_FLAG_USE_RTS_MSK;
4308 * need to set them to non-zero, though, or we get an error.
4310 lq->single_stream_ant_msk = 1;
4311 lq->dual_stream_ant_msk = 1;
4322 int rate = rs->rs_rates[rix - i] & IEEE80211_RATE_VAL;
4327 if (ridx == -1)
4333 nextant = 1<<(ffs(txant)-1);
4345 lq->rs_table[i] = htole32(tab);
4348 for (i = nrates; i < nitems(lq->rs_table); i++) {
4350 lq->rs_table[i] = htole32(tab);
4361 sc->sc_tx_timer = 0;
4363 ivp->iv_auth = 0;
4364 if (sc->sc_firmware_state == 3) {
4369 device_printf(sc->sc_dev,
4374 if (sc->sc_firmware_state == 3) {
4377 device_printf(sc->sc_dev,
4382 if (sc->sc_firmware_state == 3) {
4385 device_printf(sc->sc_dev,
4390 if (sc->sc_firmware_state == 3) {
4393 device_printf(sc->sc_dev,
4398 if (sc->sc_firmware_state == 3) {
4401 device_printf(sc->sc_dev,
4406 if (sc->sc_firmware_state == 3) {
4410 device_printf(sc->sc_dev,
4415 if (sc->sc_firmware_state == 3) {
4416 sc->sc_firmware_state = 2;
4418 if (sc->sc_firmware_state > 1) {
4421 device_printf(sc->sc_dev,
4426 if (sc->sc_firmware_state > 1) {
4427 sc->sc_firmware_state = 1;
4429 ivp->phy_ctxt = NULL;
4430 if (sc->sc_firmware_state > 0) {
4433 device_printf(sc->sc_dev,
4438 if (sc->sc_firmware_state > 0) {
4441 device_printf(sc->sc_dev,
4446 sc->sc_firmware_state = 0;
4453 struct ieee80211com *ic = vap->iv_ic;
4454 struct iwm_softc *sc = ic->ic_softc;
4459 "switching state %s -> %s arg=0x%x\n",
4460 ieee80211_state_name[vap->iv_state],
4467 if ((sc->sc_flags & IWM_FLAG_SCAN_RUNNING) &&
4475 if (vap->iv_state == IEEE80211_S_RUN && nstate != IEEE80211_S_RUN) {
4479 if (((in = IWM_NODE(vap->iv_bss)) != NULL))
4480 in->in_assoc = 0;
4483 if ((vap->iv_state == IEEE80211_S_AUTH ||
4484 vap->iv_state == IEEE80211_S_ASSOC ||
4485 vap->iv_state == IEEE80211_S_RUN) &&
4492 if ((vap->iv_state == IEEE80211_S_RUN ||
4493 vap->iv_state == IEEE80211_S_ASSOC) &&
4502 ivp->iv_newstate(vap, nstate, arg);
4519 device_printf(sc->sc_dev,
4534 sc->last_ebs_successful = TRUE;
4538 in = IWM_NODE(vap->iv_bss);
4543 device_printf(sc->sc_dev,
4549 in->in_assoc = 1;
4552 device_printf(sc->sc_dev,
4560 int rix = ieee80211_ratectl_rate(&in->in_ni, NULL, 0);
4563 if ((error = iwm_send_lq_cmd(sc, &in->in_lq, TRUE)) != 0) {
4564 device_printf(sc->sc_dev,
4577 return (ivp->iv_newstate(vap, nstate, arg));
4584 struct ieee80211com *ic = &sc->sc_ic;
4590 ieee80211_scan_done(TAILQ_FIRST(&ic->ic_vaps));
4608 boolean_t nvm_lar = sc->nvm_data->lar_enabled;
4618 if (sc->cfg->device_family >= IWM_DEVICE_FAMILY_8000)
4681 mcc_resp = (void *)pkt->data;
4682 mcc = mcc_resp->mcc;
4683 n_channels = le32toh(mcc_resp->n_channels);
4685 mcc_resp_v1 = (void *)pkt->data;
4686 mcc = mcc_resp_v1->mcc;
4687 n_channels = le32toh(mcc_resp_v1->n_channels);
4690 /* W/A for a FW/NVM issue - returns 0x00 for the world domain */
4692 mcc = 0x3030; /* "00" - world */
4713 device_printf(sc->sc_dev,
4721 struct ieee80211com *ic = &sc->sc_ic;
4724 sc->sf_state = IWM_SF_UNINIT;
4741 sc->sc_ps_disabled = FALSE;
4743 device_printf(sc->sc_dev, "could not initialize hardware\n");
4750 device_printf(sc->sc_dev, "could not load firmware\n");
4756 device_printf(sc->sc_dev, "Failed to initialize Smart Fifo\n");
4759 device_printf(sc->sc_dev, "bt init conf failed\n");
4765 device_printf(sc->sc_dev, "antenna config failed\n");
4770 if ((error = iwm_send_phy_db_data(sc->sc_phy_db)) != 0)
4774 device_printf(sc->sc_dev, "phy_cfg_cmd failed\n");
4780 device_printf(sc->sc_dev, "add_aux_sta failed\n");
4791 &sc->sc_phyctxt[i], &ic->ic_channels[1], 1, 1)) != 0)
4796 if (sc->cfg->device_family == IWM_DEVICE_FAMILY_7000)
4800 device_printf(sc->sc_dev, "PCIe LTR configuration failed\n");
4823 device_printf(sc->sc_dev, "failed to disable beacon filter\n");
4838 struct ieee80211_node *ni = vap->iv_bss;
4847 cmd->filter_own = 1;
4848 cmd->port_id = 0;
4849 cmd->count = 0;
4850 cmd->pass_all = 1;
4851 IEEE80211_ADDR_COPY(cmd->bssid, ni->ni_bssid);
4869 if (sc->sc_flags & IWM_FLAG_HW_INITED) {
4872 sc->sc_generation++;
4873 sc->sc_flags &= ~IWM_FLAG_STOPPED;
4884 sc->sc_flags |= IWM_FLAG_HW_INITED;
4893 sc = ic->ic_softc;
4896 if ((sc->sc_flags & IWM_FLAG_HW_INITED) == 0) {
4900 error = mbufq_enqueue(&sc->sc_snd, m);
4920 IWM_DPRINTF(sc, IWM_DEBUG_XMIT | IWM_DEBUG_TRACE, "->%s\n", __func__);
4921 while (sc->qfullmsk == 0 &&
4922 (m = mbufq_dequeue(&sc->sc_snd)) != NULL) {
4923 ni = (struct ieee80211_node *)m->m_pkthdr.rcvif;
4925 if_inc_counter(ni->ni_vap->iv_ifp,
4930 if (sc->sc_tx_timer == 0) {
4931 callout_reset(&sc->sc_watchdog_to, hz, iwm_watchdog,
4934 sc->sc_tx_timer = 15;
4936 IWM_DPRINTF(sc, IWM_DEBUG_XMIT | IWM_DEBUG_TRACE, "<-%s\n", __func__);
4943 sc->sc_flags &= ~IWM_FLAG_HW_INITED;
4944 sc->sc_flags |= IWM_FLAG_STOPPED;
4945 sc->sc_generation++;
4947 sc->sc_tx_timer = 0;
4949 sc->sc_flags &= ~IWM_FLAG_SCAN_RUNNING;
4956 struct ieee80211com *ic = &sc->sc_ic;
4958 if (sc->sc_attached == 0)
4961 if (sc->sc_tx_timer > 0) {
4962 if (--sc->sc_tx_timer == 0) {
4963 device_printf(sc->sc_dev, "device timeout\n");
4968 counter_u64_add(sc->sc_ic.ic_oerrors, 1);
4971 callout_reset(&sc->sc_watchdog_to, hz, iwm_watchdog, sc);
4978 struct iwm_softc *sc = ic->ic_softc;
4983 if (ic->ic_nrunning > 0) {
4984 if (!(sc->sc_flags & IWM_FLAG_HW_INITED)) {
4990 } else if (sc->sc_flags & IWM_FLAG_HW_INITED)
4996 taskqueue_enqueue(sc->sc_tq, &sc->sc_rftoggle_task);
5003 struct ieee80211com *ic = &sc->sc_ic;
5010 device_printf(sc->sc_dev,
5015 device_printf(sc->sc_dev,
5016 "%s: rfkill cleared, re-enabling interface\n", __func__);
5033 * read with uint32_t-sized accesses, any members with a different size
5044 uint32_t data1; /* error-specific data */
5045 uint32_t data2; /* error-specific data */
5046 uint32_t data3; /* error-specific data */
5047 uint32_t bcon_time; /* beacon timer */
5048 uint32_t tsf_low; /* network timestamp function timer */
5049 uint32_t tsf_hi; /* network timestamp function timer */
5050 uint32_t gp1; /* GP1 timer register */
5051 uint32_t gp2; /* GP2 timer register */
5085 * UMAC error struct - relevant starting from family 8000 chip.
5088 * read with u32-sized accesses, any members with a different size
5098 uint32_t data1; /* error-specific data */
5099 uint32_t data2; /* error-specific data */
5100 uint32_t data3; /* error-specific data */
5140 for (i = 0; i < nitems(advanced_lookup) - 1; i++)
5154 base = sc->umac_error_event_table;
5157 device_printf(sc->sc_dev, "Invalid error log pointer 0x%08x\n",
5163 device_printf(sc->sc_dev, "reading errlog failed\n");
5168 device_printf(sc->sc_dev, "Start UMAC Error Log Dump:\n");
5169 device_printf(sc->sc_dev, "Status: 0x%x, count: %d\n",
5170 sc->sc_flags, table.valid);
5173 device_printf(sc->sc_dev, "0x%08X | %s\n", table.error_id,
5175 device_printf(sc->sc_dev, "0x%08X | umac branchlink1\n", table.blink1);
5176 device_printf(sc->sc_dev, "0x%08X | umac branchlink2\n", table.blink2);
5177 device_printf(sc->sc_dev, "0x%08X | umac interruptlink1\n",
5179 device_printf(sc->sc_dev, "0x%08X | umac interruptlink2\n",
5181 device_printf(sc->sc_dev, "0x%08X | umac data1\n", table.data1);
5182 device_printf(sc->sc_dev, "0x%08X | umac data2\n", table.data2);
5183 device_printf(sc->sc_dev, "0x%08X | umac data3\n", table.data3);
5184 device_printf(sc->sc_dev, "0x%08X | umac major\n", table.umac_major);
5185 device_printf(sc->sc_dev, "0x%08X | umac minor\n", table.umac_minor);
5186 device_printf(sc->sc_dev, "0x%08X | frame pointer\n",
5188 device_printf(sc->sc_dev, "0x%08X | stack pointer\n",
5190 device_printf(sc->sc_dev, "0x%08X | last host cmd\n", table.cmd_header);
5191 device_printf(sc->sc_dev, "0x%08X | isr status reg\n",
5208 device_printf(sc->sc_dev, "dumping device error log\n");
5209 base = sc->error_event_table[0];
5211 device_printf(sc->sc_dev,
5217 device_printf(sc->sc_dev, "reading errlog failed\n");
5222 device_printf(sc->sc_dev, "errlog not found, skipping\n");
5227 device_printf(sc->sc_dev, "Start Error Log Dump:\n");
5228 device_printf(sc->sc_dev, "Status: 0x%x, count: %d\n",
5229 sc->sc_flags, table.valid);
5232 device_printf(sc->sc_dev, "0x%08X | %-28s\n", table.error_id,
5234 device_printf(sc->sc_dev, "%08X | trm_hw_status0\n",
5236 device_printf(sc->sc_dev, "%08X | trm_hw_status1\n",
5238 device_printf(sc->sc_dev, "%08X | branchlink2\n", table.blink2);
5239 device_printf(sc->sc_dev, "%08X | interruptlink1\n", table.ilink1);
5240 device_printf(sc->sc_dev, "%08X | interruptlink2\n", table.ilink2);
5241 device_printf(sc->sc_dev, "%08X | data1\n", table.data1);
5242 device_printf(sc->sc_dev, "%08X | data2\n", table.data2);
5243 device_printf(sc->sc_dev, "%08X | data3\n", table.data3);
5244 device_printf(sc->sc_dev, "%08X | beacon time\n", table.bcon_time);
5245 device_printf(sc->sc_dev, "%08X | tsf low\n", table.tsf_low);
5246 device_printf(sc->sc_dev, "%08X | tsf hi\n", table.tsf_hi);
5247 device_printf(sc->sc_dev, "%08X | time gp1\n", table.gp1);
5248 device_printf(sc->sc_dev, "%08X | time gp2\n", table.gp2);
5249 device_printf(sc->sc_dev, "%08X | uCode revision type\n",
5251 device_printf(sc->sc_dev, "%08X | uCode version major\n", table.major);
5252 device_printf(sc->sc_dev, "%08X | uCode version minor\n", table.minor);
5253 device_printf(sc->sc_dev, "%08X | hw version\n", table.hw_ver);
5254 device_printf(sc->sc_dev, "%08X | board version\n", table.brd_ver);
5255 device_printf(sc->sc_dev, "%08X | hcmd\n", table.hcmd);
5256 device_printf(sc->sc_dev, "%08X | isr0\n", table.isr0);
5257 device_printf(sc->sc_dev, "%08X | isr1\n", table.isr1);
5258 device_printf(sc->sc_dev, "%08X | isr2\n", table.isr2);
5259 device_printf(sc->sc_dev, "%08X | isr3\n", table.isr3);
5260 device_printf(sc->sc_dev, "%08X | isr4\n", table.isr4);
5261 device_printf(sc->sc_dev, "%08X | last cmd Id\n", table.last_cmd_id);
5262 device_printf(sc->sc_dev, "%08X | wait_event\n", table.wait_event);
5263 device_printf(sc->sc_dev, "%08X | l2p_control\n", table.l2p_control);
5264 device_printf(sc->sc_dev, "%08X | l2p_duration\n", table.l2p_duration);
5265 device_printf(sc->sc_dev, "%08X | l2p_mhvalid\n", table.l2p_mhvalid);
5266 device_printf(sc->sc_dev, "%08X | l2p_addr_match\n", table.l2p_addr_match);
5267 device_printf(sc->sc_dev, "%08X | lmpm_pmg_sel\n", table.lmpm_pmg_sel);
5268 device_printf(sc->sc_dev, "%08X | timestamp\n", table.u_timestamp);
5269 device_printf(sc->sc_dev, "%08X | flow_handler\n", table.flow_handler);
5271 if (sc->umac_error_event_table)
5279 struct ieee80211com *ic = &sc->sc_ic;
5295 qid = pkt->hdr.qid;
5296 idx = pkt->hdr.idx;
5298 code = IWM_WIDE_ID(pkt->hdr.flags, pkt->hdr.code);
5304 if ((pkt->hdr.code == 0 && (qid & ~0x80) == 0 && idx == 0) ||
5305 pkt->len_n_flags == htole32(IWM_FH_RSCSR_FRAME_INVALID)) {
5311 qid & ~0x80, pkt->hdr.idx, code);
5317 iwm_notification_wait_notify(sc->sc_notif_wait, code, pkt);
5332 (nextpkt->hdr.code == 0 &&
5333 (nextpkt->hdr.qid & ~0x80) == 0 &&
5334 nextpkt->hdr.idx == 0) ||
5335 (nextpkt->len_n_flags ==
5372 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps);
5374 resp = (void *)pkt->data;
5375 missed = le32toh(resp->consec_missed_beacons);
5382 le32toh(resp->mac_id),
5383 le32toh(resp->consec_missed_beacons_since_last_rx),
5384 le32toh(resp->consec_missed_beacons),
5385 le32toh(resp->num_expected_beacons),
5386 le32toh(resp->num_recvd_beacons));
5393 if (vap->iv_state == IEEE80211_S_RUN &&
5394 (ic->ic_flags & IEEE80211_F_SCAN) == 0) {
5395 if (missed > vap->iv_bmissthreshold) {
5421 if (sc->sc_wantresp == (((qid & ~0x80) << 16) | idx)) {
5422 memcpy(sc->sc_cmd_resp,
5423 pkt, sizeof(sc->sc_cmd_resp));
5429 notif = (void *)pkt->data;
5431 sc->sc_fw_mcc[0] = (notif->mcc & 0xff00) >> 8;
5432 sc->sc_fw_mcc[1] = notif->mcc & 0xff;
5433 sc->sc_fw_mcc[2] = '\0';
5436 notif->source_id, sc->sc_fw_mcc);
5446 device_printf(sc->sc_dev,
5450 notif = (void *)pkt->data;
5452 "IWM_DTS_MEASUREMENT_NOTIFICATION - %d\n",
5453 notif->temp);
5482 cresp = (void *)pkt->data;
5483 if (sc->sc_wantresp == (((qid & ~0x80) << 16) | idx)) {
5484 memcpy(sc->sc_cmd_resp,
5498 if (sc->sc_flags & IWM_FLAG_SCAN_RUNNING) {
5499 sc->sc_flags &= ~IWM_FLAG_SCAN_RUNNING;
5500 ieee80211_runtask(ic, &sc->sc_es_task);
5510 if (sc->sc_flags & IWM_FLAG_SCAN_RUNNING) {
5511 sc->sc_flags &= ~IWM_FLAG_SCAN_RUNNING;
5512 ieee80211_runtask(ic, &sc->sc_es_task);
5519 notif = (void *)pkt->data;
5523 notif->status, notif->scanned_channels);
5530 resp = (void *)pkt->data;
5532 device_printf(sc->sc_dev,
5534 le32toh(resp->error_type),
5535 resp->cmd_id);
5556 rsp = (void *)pkt->data;
5561 rsp->token, rsp->sta_id, rsp->tid,
5562 rsp->scd_queue);
5568 device_printf(sc->sc_dev,
5570 code, qid & ~0x80, idx, pkt->len_n_flags);
5585 * uses a slightly different format for pkt->hdr, and "qid"
5586 * is actually the upper byte of a two-byte field.
5609 bus_dmamap_sync(sc->rxq.stat_dma.tag, sc->rxq.stat_dma.map,
5612 if (sc->cfg->mqrx_supported) {
5620 hw = le16toh(sc->rxq.stat->closed_rb_num) & 0xfff;
5625 while (sc->rxq.cur != hw) {
5626 struct iwm_rx_ring *ring = &sc->rxq;
5627 struct iwm_rx_data *data = &ring->data[ring->cur];
5629 bus_dmamap_sync(ring->data_dmat, data->map,
5633 "%s: hw = %d cur = %d\n", __func__, hw, ring->cur);
5634 iwm_handle_rxb(sc, data->m);
5636 ring->cur = (ring->cur + 1) % count;
5645 hw = (hw == 0) ? count - 1 : hw - 1;
5660 if (sc->sc_flags & IWM_FLAG_USE_ICT) {
5661 uint32_t *ict = sc->ict_dma.vaddr;
5664 tmp = htole32(ict[sc->ict_cur]);
5674 ict[sc->ict_cur] = 0;
5675 sc->ict_cur = (sc->ict_cur+1) % IWM_ICT_COUNT;
5676 tmp = htole32(ict[sc->ict_cur]);
5698 IWM_WRITE(sc, IWM_CSR_INT, r1 | ~sc->sc_intmask);
5705 struct ieee80211com *ic = &sc->sc_ic;
5706 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps);
5712 device_printf(sc->sc_dev, "driver status:\n");
5714 struct iwm_tx_ring *ring = &sc->txq[i];
5715 device_printf(sc->sc_dev,
5716 " tx ring %2d: qid=%-2d cur=%-3d "
5717 "queued=%-3d\n",
5718 i, ring->qid, ring->cur, ring->queued);
5720 device_printf(sc->sc_dev,
5721 " rx ring: cur=%d\n", sc->rxq.cur);
5722 device_printf(sc->sc_dev,
5723 " 802.11 state %d\n", (vap == NULL) ? -1 : vap->iv_state);
5726 sc->sc_firmware_state = 0;
5735 device_printf(sc->sc_dev, "%s: controller panicked, iv_state = %d; "
5736 "restarting\n", __func__, vap->iv_state);
5744 device_printf(sc->sc_dev, "hardware error, stopping device\n");
5753 sc->sc_fw_chunk_done = 1;
5754 wakeup(&sc->sc_fw);
5759 taskqueue_enqueue(sc->sc_tq, &sc->sc_rftoggle_task);
5764 * We cargo-cult like it's going out of fashion.
5798 * Autoconf glue-sniffing
5848 device_set_desc(dev, iwm_devices[i].cfg->name);
5868 sc->cfg = iwm_devices[i].cfg;
5889 * PCI Tx retries from interfering with C3 CPU state */
5892 /* Enable bus-mastering and hardware bug workaround. */
5902 sc->sc_mem = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid,
5904 if (sc->sc_mem == NULL) {
5905 device_printf(sc->sc_dev, "can't map mem space\n");
5908 sc->sc_st = rman_get_bustag(sc->sc_mem);
5909 sc->sc_sh = rman_get_bushandle(sc->sc_mem);
5916 sc->sc_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, RF_ACTIVE |
5918 if (sc->sc_irq == NULL) {
5922 error = bus_setup_intr(dev, sc->sc_irq, INTR_TYPE_NET | INTR_MPSAFE,
5923 NULL, iwm_intr, sc, &sc->sc_ih);
5928 sc->sc_dmat = bus_get_dma_tag(sc->sc_dev);
5938 if (sc->sc_irq != NULL) {
5939 bus_teardown_intr(dev, sc->sc_irq, sc->sc_ih);
5941 rman_get_rid(sc->sc_irq), sc->sc_irq);
5944 if (sc->sc_mem != NULL)
5946 rman_get_rid(sc->sc_mem), sc->sc_mem);
5953 struct ieee80211com *ic = &sc->sc_ic;
5957 sc->sc_dev = dev;
5958 sc->sc_attached = 1;
5960 mbufq_init(&sc->sc_snd, ifqmaxlen);
5961 callout_init_mtx(&sc->sc_watchdog_to, &sc->sc_mtx, 0);
5962 callout_init_mtx(&sc->sc_led_blink_to, &sc->sc_mtx, 0);
5963 TASK_INIT(&sc->sc_es_task, 0, iwm_endscan_cb, sc);
5964 TASK_INIT(&sc->sc_rftoggle_task, 0, iwm_rftoggle_task, sc);
5966 sc->sc_tq = taskqueue_create("iwm_taskq", M_WAITOK,
5967 taskqueue_thread_enqueue, &sc->sc_tq);
5968 error = taskqueue_start_threads(&sc->sc_tq, 1, 0, "iwm_taskq");
5979 sc->sc_notif_wait = iwm_notification_wait_init(sc);
5980 if (sc->sc_notif_wait == NULL) {
5985 sc->sf_state = IWM_SF_UNINIT;
5988 sc->sc_phy_db = iwm_phy_db_init(sc);
5989 if (!sc->sc_phy_db) {
5990 device_printf(dev, "Cannot init phy_db\n");
5995 sc->last_ebs_successful = TRUE;
6002 sc->sc_wantresp = -1;
6004 sc->sc_hw_rev = IWM_READ(sc, IWM_CSR_HW_REV);
6007 * changed, and now the revision step also includes bit 0-1 (no more
6008 * "dash" value). To keep hw_rev backwards compatible - we'll store it
6011 if (sc->cfg->device_family >= IWM_DEVICE_FAMILY_8000) {
6015 sc->sc_hw_rev = (sc->sc_hw_rev & 0xfff0) |
6016 (IWM_CSR_HW_REV_STEP(sc->sc_hw_rev << 2) << 2);
6036 device_printf(sc->sc_dev,
6037 "Failed to wake up the nic\n");
6048 sc->sc_hw_rev = (sc->sc_hw_rev & 0xFFFFFFF3) |
6052 device_printf(sc->sc_dev, "Failed to lock the nic\n");
6057 /* special-case 7265D, it has the same PCI IDs. */
6058 if (sc->cfg == &iwm7265_cfg &&
6059 (sc->sc_hw_rev & IWM_CSR_HW_REV_TYPE_MSK) == IWM_CSR_HW_REV_TYPE_7265D) {
6060 sc->cfg = &iwm7265d_cfg;
6088 for (txq_i = 0; txq_i < nitems(sc->txq); txq_i++) {
6090 &sc->txq[txq_i], txq_i)) != 0) {
6099 if ((error = iwm_alloc_rx_ring(sc, &sc->rxq)) != 0) {
6107 ic->ic_softc = sc;
6108 ic->ic_name = device_get_nameunit(sc->sc_dev);
6109 ic->ic_phytype = IEEE80211_T_OFDM; /* not only, but not used */
6110 ic->ic_opmode = IEEE80211_M_STA; /* default to BSS mode */
6113 ic->ic_caps =
6122 /* Advertise full-offload scanning */
6123 ic->ic_flags_ext = IEEE80211_FEXT_SCAN_OFFLOAD;
6124 for (i = 0; i < nitems(sc->sc_phyctxt); i++) {
6125 sc->sc_phyctxt[i].id = i;
6126 sc->sc_phyctxt[i].color = 0;
6127 sc->sc_phyctxt[i].ref = 0;
6128 sc->sc_phyctxt[i].channel = NULL;
6132 sc->sc_noise = -96;
6135 sc->sc_max_rssi = IWM_MAX_DBM - IWM_MIN_DBM;
6140 CTLFLAG_RW, &sc->sc_debug, 0, "control debugging");
6146 } else if (sc->sc_fw.fw_fp == NULL) {
6153 sc->sc_preinit_hook.ich_func = iwm_preinit;
6154 sc->sc_preinit_hook.ich_arg = sc;
6155 if (config_intrhook_establish(&sc->sc_preinit_hook) != 0) {
6163 "<-%s\n", __func__);
6188 #define IWM_EXP2(x) ((1 << (x)) - 1) /* CWmin = 2^ECWmin - 1 */
6189 struct iwm_softc *sc = ic->ic_softc;
6191 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps);
6210 ivp->queue_params[aci].aifsn = ac->wmep_aifsn;
6211 ivp->queue_params[aci].cw_min = IWM_EXP2(ac->wmep_logcwmin);
6212 ivp->queue_params[aci].cw_max = IWM_EXP2(ac->wmep_logcwmax);
6213 ivp->queue_params[aci].edca_txop =
6214 IEEE80211_TXOP_TO_US(ac->wmep_txopLimit);
6216 ivp->have_wme = TRUE;
6217 if (ivp->is_uploaded && vap->iv_bss != NULL) {
6218 in = IWM_NODE(vap->iv_bss);
6219 if (in->in_assoc) {
6221 device_printf(sc->sc_dev,
6236 device_t dev = sc->sc_dev;
6237 struct ieee80211com *ic = &sc->sc_ic;
6241 "->%s\n", __func__);
6258 sc->sc_hw_rev & IWM_CSR_HW_REV_TYPE_MSK,
6259 sc->sc_fwver, ether_sprintf(sc->nvm_data->hw_addr));
6262 if (!sc->nvm_data->sku_cap_band_52GHz_enable)
6263 memset(&ic->ic_sup_rates[IEEE80211_MODE_11A], 0,
6264 sizeof(ic->ic_sup_rates[IEEE80211_MODE_11A]));
6267 iwm_init_channel_map(ic, IEEE80211_CHAN_MAX, &ic->ic_nchans,
6268 ic->ic_channels);
6271 * At this point we've committed - if we fail to do setup,
6275 ic->ic_vap_create = iwm_vap_create;
6276 ic->ic_vap_delete = iwm_vap_delete;
6277 ic->ic_raw_xmit = iwm_raw_xmit;
6278 ic->ic_node_alloc = iwm_node_alloc;
6279 ic->ic_scan_start = iwm_scan_start;
6280 ic->ic_scan_end = iwm_scan_end;
6281 ic->ic_update_mcast = iwm_update_mcast;
6282 ic->ic_getradiocaps = iwm_init_channel_map;
6283 ic->ic_set_channel = iwm_set_channel;
6284 ic->ic_scan_curchan = iwm_scan_curchan;
6285 ic->ic_scan_mindwell = iwm_scan_mindwell;
6286 ic->ic_wme.wme_update = iwm_wme_update;
6287 ic->ic_parent = iwm_parent;
6288 ic->ic_transmit = iwm_transmit;
6294 "<-%s\n", __func__);
6295 config_intrhook_disestablish(&sc->sc_preinit_hook);
6299 config_intrhook_disestablish(&sc->sc_preinit_hook);
6309 struct ieee80211com *ic = &sc->sc_ic;
6312 "->%s begin\n", __func__);
6314 &sc->sc_txtap.wt_ihdr, sizeof(sc->sc_txtap),
6316 &sc->sc_rxtap.wr_ihdr, sizeof(sc->sc_rxtap),
6319 "->%s end\n", __func__);
6331 if (!TAILQ_EMPTY(&ic->ic_vaps)) /* only one at a time */
6334 vap = &ivp->iv_vap;
6336 vap->iv_bmissthreshold = 10; /* override default */
6338 ivp->iv_newstate = vap->iv_newstate;
6339 vap->iv_newstate = iwm_newstate;
6341 ivp->id = IWM_DEFAULT_MACID;
6342 ivp->color = IWM_DEFAULT_COLOR;
6344 ivp->have_wme = FALSE;
6345 ivp->ps_disabled = FALSE;
6351 ic->ic_opmode = opmode;
6372 while ((m = mbufq_dequeue(&sc->sc_snd)) != NULL) {
6373 ni = (struct ieee80211_node *)m->m_pkthdr.rcvif;
6382 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps);
6383 struct iwm_softc *sc = ic->ic_softc;
6387 if (sc->sc_flags & IWM_FLAG_SCAN_RUNNING) {
6389 device_printf(sc->sc_dev,
6397 device_printf(sc->sc_dev, "could not initiate scan\n");
6401 sc->sc_flags |= IWM_FLAG_SCAN_RUNNING;
6410 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps);
6411 struct iwm_softc *sc = ic->ic_softc;
6415 if (vap->iv_state == IEEE80211_S_RUN)
6417 if (sc->sc_flags & IWM_FLAG_SCAN_RUNNING) {
6420 * both iwm_scan_end and iwm_scan_start run in the ic->ic_tq
6423 sc->sc_flags &= ~IWM_FLAG_SCAN_RUNNING;
6433 taskqueue_cancel(ic->ic_tq, &sc->sc_es_task, NULL);
6462 while (sc->sc_flags & IWM_FLAG_BUSY)
6463 msleep(&sc->sc_flags, &sc->sc_mtx, 0, "iwmpwr", 0);
6464 sc->sc_flags |= IWM_FLAG_BUSY;
6466 if (sc->sc_ic.ic_nrunning > 0)
6468 sc->sc_flags &= ~IWM_FLAG_BUSY;
6469 wakeup(&sc->sc_flags);
6481 * PCI Tx retries from interfering with C3 CPU state.
6485 if (!sc->sc_attached)
6491 if (sc->sc_flags & IWM_FLAG_SCANNING) {
6492 sc->sc_flags &= ~IWM_FLAG_SCANNING;
6498 ieee80211_resume_all(&sc->sc_ic);
6509 do_stop = !! (sc->sc_ic.ic_nrunning > 0);
6511 if (!sc->sc_attached)
6514 ieee80211_suspend_all(&sc->sc_ic);
6519 sc->sc_flags |= IWM_FLAG_SCANNING;
6529 struct iwm_fw_info *fw = &sc->sc_fw;
6530 device_t dev = sc->sc_dev;
6533 if (!sc->sc_attached)
6535 sc->sc_attached = 0;
6537 ieee80211_draintask(&sc->sc_ic, &sc->sc_es_task);
6540 taskqueue_drain_all(sc->sc_tq);
6541 taskqueue_free(sc->sc_tq);
6546 ieee80211_ifdetach(&sc->sc_ic);
6548 callout_drain(&sc->sc_led_blink_to);
6549 callout_drain(&sc->sc_watchdog_to);
6551 iwm_phy_db_free(sc->sc_phy_db);
6552 sc->sc_phy_db = NULL;
6554 iwm_free_nvm_data(sc->nvm_data);
6557 iwm_free_rx_ring(sc, &sc->rxq);
6558 for (i = 0; i < nitems(sc->txq); i++)
6559 iwm_free_tx_ring(sc, &sc->txq[i]);
6562 if (fw->fw_fp != NULL)
6566 iwm_dma_contig_free(&sc->sched_dma);
6567 iwm_dma_contig_free(&sc->ict_dma);
6568 iwm_dma_contig_free(&sc->kw_dma);
6569 iwm_dma_contig_free(&sc->fw_dma);
6573 /* Finished with the hardware - detach things */
6576 if (sc->sc_notif_wait != NULL) {
6577 iwm_notification_wait_free(sc->sc_notif_wait);
6578 sc->sc_notif_wait = NULL;