Lines Matching refs:sc

315 wpi_load_firmware(struct wpi_softc *sc)
318 struct wpi_dma_info *dma = &sc->fw_dma;
327 WPI_UNLOCK(sc);
329 if (sc->fw_fp == NULL && (sc->fw_fp = firmware_get("wpifw")) == NULL) {
330 device_printf(sc->sc_dev,
333 WPI_LOCK(sc);
337 fp = sc->fw_fp;
339 WPI_LOCK(sc);
343 device_printf(sc->sc_dev,
352 device_printf(sc->sc_dev,
372 device_printf(sc->sc_dev,
407 device_printf(sc->sc_dev, "firmware invalid\n");
419 wpi_mem_lock(sc);
420 wpi_mem_write(sc, WPI_MEM_DATA_BASE, dma->paddr);
421 wpi_mem_write(sc, WPI_MEM_DATA_SIZE, idatasz);
422 wpi_mem_write(sc, WPI_MEM_TEXT_BASE,
424 wpi_mem_write(sc, WPI_MEM_TEXT_SIZE, itextsz);
425 wpi_mem_unlock(sc);
428 if ((error = wpi_load_microcode(sc, btext, btextsz)) != 0) {
429 device_printf(sc->sc_dev, "Failed to load microcode\n");
434 WPI_WRITE(sc, WPI_RESET, 0);
437 if ((error = msleep(sc, &sc->sc_mtx, PCATCH, "wpiinit", hz)) != 0) {
438 device_printf(sc->sc_dev,
449 wpi_mem_lock(sc);
450 wpi_mem_write(sc, WPI_MEM_DATA_BASE, dma->paddr);
451 wpi_mem_write(sc, WPI_MEM_DATA_SIZE, rdatasz);
452 wpi_mem_write(sc, WPI_MEM_TEXT_BASE,
454 wpi_mem_write(sc, WPI_MEM_TEXT_SIZE, WPI_FW_UPDATED | rtextsz);
455 wpi_mem_unlock(sc);
458 if ((error = msleep(sc, &sc->sc_mtx, PCATCH, "wpiinit", hz)) != 0) {
459 device_printf(sc->sc_dev,
468 wpi_unload_firmware(sc);
476 wpi_unload_firmware(struct wpi_softc *sc)
479 if (sc->fw_fp) {
480 WPI_UNLOCK(sc);
481 firmware_put(sc->fw_fp, FIRMWARE_UNLOAD);
482 WPI_LOCK(sc);
483 sc->fw_fp = NULL;
490 struct wpi_softc *sc = device_get_softc(dev);
498 sc->sc_dev = dev;
501 device_printf(sc->sc_dev,"Driver Revision %s\n", VERSION);
517 TASK_INIT(&sc->sc_restarttask, 0, wpi_hwreset, sc);
518 TASK_INIT(&sc->sc_radiotask, 0, wpi_rfreset, sc);
520 WPI_LOCK_INIT(sc);
522 callout_init_mtx(&sc->calib_to, &sc->sc_mtx, 0);
523 callout_init_mtx(&sc->watchdog_to, &sc->sc_mtx, 0);
537 sc->mem_rid = PCIR_BAR(0);
538 sc->mem = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &sc->mem_rid,
540 if (sc->mem == NULL) {
546 sc->sc_st = rman_get_bustag(sc->mem);
547 sc->sc_sh = rman_get_bushandle(sc->mem);
549 sc->irq_rid = 0;
550 sc->irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &sc->irq_rid,
552 if (sc->irq == NULL) {
561 if ((error = wpi_alloc_fwmem(sc)) != 0) {
570 if ((error = wpi_reset(sc)) != 0) {
575 wpi_mem_lock(sc);
576 tmp = wpi_mem_read(sc, WPI_MEM_PCIDEV);
578 device_printf(sc->sc_dev, "Hardware Revision (0x%X)\n", tmp);
580 wpi_mem_unlock(sc);
583 if ((error = wpi_alloc_shared(sc)) != 0) {
590 error = wpi_alloc_tx_ring(sc, &sc->txq[ac], WPI_TX_RING_COUNT, ac);
598 error = wpi_alloc_tx_ring(sc, &sc->cmdq, WPI_CMD_RING_COUNT, 4);
605 error = wpi_alloc_rx_ring(sc, &sc->rxq);
611 ifp = sc->sc_ifp = if_alloc(IFT_IEEE80211);
644 wpi_read_eeprom(sc, macaddr);
647 device_printf(sc->sc_dev, "Regulatory Domain: %.4s\n", sc->domain);
648 device_printf(sc->sc_dev, "Hardware Type: %c\n",
649 sc->type > 1 ? 'B': '?');
650 device_printf(sc->sc_dev, "Hardware Revision: %c\n",
651 ((le16toh(sc->rev) & 0xf0) == 0xd0) ? 'D': '?');
652 device_printf(sc->sc_dev, "SKU %s support 802.11a\n",
656 what sc->rev really represents - benjsc 20070615 */
660 ifp->if_softc = sc;
683 &sc->sc_txtap.wt_ihdr, sizeof(sc->sc_txtap),
685 &sc->sc_rxtap.wr_ihdr, sizeof(sc->sc_rxtap),
691 error = bus_setup_intr(dev, sc->irq, INTR_TYPE_NET |INTR_MPSAFE,
692 NULL, wpi_intr, sc, &sc->sc_ih);
712 struct wpi_softc *sc = device_get_softc(dev);
713 struct ifnet *ifp = sc->sc_ifp;
720 ieee80211_draintask(ic, &sc->sc_restarttask);
721 ieee80211_draintask(ic, &sc->sc_radiotask);
722 wpi_stop(sc);
723 callout_drain(&sc->watchdog_to);
724 callout_drain(&sc->calib_to);
728 WPI_LOCK(sc);
729 if (sc->txq[0].data_dmat) {
731 wpi_free_tx_ring(sc, &sc->txq[ac]);
733 wpi_free_tx_ring(sc, &sc->cmdq);
734 wpi_free_rx_ring(sc, &sc->rxq);
735 wpi_free_shared(sc);
738 if (sc->fw_fp != NULL) {
739 wpi_unload_firmware(sc);
742 if (sc->fw_dma.tag)
743 wpi_free_fwmem(sc);
744 WPI_UNLOCK(sc);
746 if (sc->irq != NULL) {
747 bus_teardown_intr(dev, sc->irq, sc->sc_ih);
748 bus_release_resource(dev, SYS_RES_IRQ, sc->irq_rid, sc->irq);
751 if (sc->mem != NULL)
752 bus_release_resource(dev, SYS_RES_MEMORY, sc->mem_rid, sc->mem);
757 WPI_LOCK_DESTROY(sc);
820 wpi_dma_contig_alloc(struct wpi_softc *sc, struct wpi_dma_info *dma,
840 error = bus_dma_tag_create(bus_get_dma_tag(sc->sc_dev), align,
846 device_printf(sc->sc_dev,
853 device_printf(sc->sc_dev,
880 device_printf(sc->sc_dev,
887 device_printf(sc->sc_dev,
922 wpi_alloc_shared(struct wpi_softc *sc)
926 error = wpi_dma_contig_alloc(sc, &sc->shared_dma,
927 (void **)&sc->shared, sizeof (struct wpi_shared),
932 device_printf(sc->sc_dev,
940 wpi_free_shared(struct wpi_softc *sc)
942 wpi_dma_contig_free(&sc->shared_dma);
946 wpi_alloc_rx_ring(struct wpi_softc *sc, struct wpi_rx_ring *ring)
953 error = wpi_dma_contig_alloc(sc, &ring->desc_dma,
958 device_printf(sc->sc_dev,
964 error = bus_dma_tag_create(bus_get_dma_tag(sc->sc_dev), 1, 0,
969 device_printf(sc->sc_dev,
985 device_printf(sc->sc_dev,
992 device_printf(sc->sc_dev,
1002 device_printf(sc->sc_dev,
1019 wpi_free_rx_ring(sc, ring);
1024 wpi_reset_rx_ring(struct wpi_softc *sc, struct wpi_rx_ring *ring)
1028 wpi_mem_lock(sc);
1030 WPI_WRITE(sc, WPI_RX_CONFIG, 0);
1033 if (WPI_READ(sc, WPI_RX_STATUS) & WPI_RX_IDLE)
1038 wpi_mem_unlock(sc);
1042 device_printf(sc->sc_dev, "timeout resetting Rx ring\n");
1049 wpi_free_rx_ring(struct wpi_softc *sc, struct wpi_rx_ring *ring)
1070 wpi_alloc_tx_ring(struct wpi_softc *sc, struct wpi_tx_ring *ring, int count,
1082 error = wpi_dma_contig_alloc(sc, &ring->desc_dma,
1087 device_printf(sc->sc_dev, "could not allocate tx dma memory\n");
1092 sc->shared->txbase[qid] = htole32(ring->desc_dma.paddr);
1094 error = wpi_dma_contig_alloc(sc, &ring->cmd_dma, (void **)&ring->cmd,
1099 device_printf(sc->sc_dev,
1107 device_printf(sc->sc_dev,
1112 error = bus_dma_tag_create(bus_get_dma_tag(sc->sc_dev), 1, 0,
1117 device_printf(sc->sc_dev, "could not create data DMA tag\n");
1126 device_printf(sc->sc_dev,
1137 wpi_free_tx_ring(sc, ring);
1142 wpi_reset_tx_ring(struct wpi_softc *sc, struct wpi_tx_ring *ring)
1147 wpi_mem_lock(sc);
1149 WPI_WRITE(sc, WPI_TX_CONFIG(ring->qid), 0);
1151 if (WPI_READ(sc, WPI_TX_STATUS) & WPI_TX_IDLE(ring->qid))
1157 device_printf(sc->sc_dev, "timeout resetting Tx ring %d\n",
1160 wpi_mem_unlock(sc);
1177 wpi_free_tx_ring(struct wpi_softc *sc, struct wpi_tx_ring *ring)
1207 struct wpi_softc *sc = device_get_softc(dev);
1209 WPI_LOCK(sc);
1210 wpi_stop_locked(sc);
1211 wpi_unload_firmware(sc);
1212 WPI_UNLOCK(sc);
1220 struct wpi_softc *sc = device_get_softc(dev);
1221 struct ieee80211com *ic = sc->sc_ifp->if_l2com;
1230 struct wpi_softc *sc = device_get_softc(dev);
1231 struct ieee80211com *ic = sc->sc_ifp->if_l2com;
1248 struct wpi_softc *sc = ifp->if_softc;
1253 ieee80211_state_name[nstate], sc->flags));
1256 WPI_LOCK(sc);
1262 error = wpi_config(sc);
1264 device_printf(sc->sc_dev,
1276 error = wpi_auth(sc, vap);
1278 device_printf(sc->sc_dev,
1284 error = wpi_run(sc, vap);
1286 device_printf(sc->sc_dev,
1293 wpi_calib_timeout(sc);
1296 WPI_UNLOCK(sc);
1305 wpi_mem_lock(struct wpi_softc *sc)
1310 tmp = WPI_READ(sc, WPI_GPIO_CTL);
1311 WPI_WRITE(sc, WPI_GPIO_CTL, tmp | WPI_GPIO_MAC);
1315 if ((WPI_READ(sc, WPI_GPIO_CTL) &
1321 device_printf(sc->sc_dev, "could not lock memory\n");
1328 wpi_mem_unlock(struct wpi_softc *sc)
1330 uint32_t tmp = WPI_READ(sc, WPI_GPIO_CTL);
1331 WPI_WRITE(sc, WPI_GPIO_CTL, tmp & ~WPI_GPIO_MAC);
1335 wpi_mem_read(struct wpi_softc *sc, uint16_t addr)
1337 WPI_WRITE(sc, WPI_READ_MEM_ADDR, WPI_MEM_4 | addr);
1338 return WPI_READ(sc, WPI_READ_MEM_DATA);
1342 wpi_mem_write(struct wpi_softc *sc, uint16_t addr, uint32_t data)
1344 WPI_WRITE(sc, WPI_WRITE_MEM_ADDR, WPI_MEM_4 | addr);
1345 WPI_WRITE(sc, WPI_WRITE_MEM_DATA, data);
1349 wpi_mem_write_region_4(struct wpi_softc *sc, uint16_t addr,
1353 wpi_mem_write(sc, addr, *data);
1362 wpi_read_prom_data(struct wpi_softc *sc, uint32_t addr, void *data, int len)
1368 wpi_mem_lock(sc);
1371 WPI_WRITE(sc, WPI_EEPROM_CTL, addr << 2);
1374 if ((val = WPI_READ(sc, WPI_EEPROM_CTL)) & WPI_EEPROM_READY)
1380 device_printf(sc->sc_dev, "could not read EEPROM\n");
1389 wpi_mem_unlock(sc);
1401 wpi_load_microcode(struct wpi_softc *sc, const uint8_t *fw, int size)
1409 wpi_mem_lock(sc);
1411 wpi_mem_write_region_4(sc, WPI_MEM_UCODE_BASE,
1414 wpi_mem_write(sc, WPI_MEM_UCODE_SRC, 0);
1415 wpi_mem_write(sc, WPI_MEM_UCODE_DST, WPI_FW_TEXT);
1416 wpi_mem_write(sc, WPI_MEM_UCODE_SIZE, size);
1419 wpi_mem_write(sc, WPI_MEM_UCODE_CTL, WPI_UC_RUN);
1423 uint32_t status = WPI_READ(sc, WPI_TX_STATUS);
1435 device_printf(sc->sc_dev, "timeout transferring firmware\n");
1440 wpi_mem_write(sc, WPI_MEM_UCODE_CTL, WPI_UC_ENABLE);
1442 wpi_mem_unlock(sc);
1448 wpi_rx_intr(struct wpi_softc *sc, struct wpi_rx_desc *desc,
1451 struct ifnet *ifp = sc->sc_ifp;
1453 struct wpi_rx_ring *ring = &sc->rxq;
1465 device_printf(sc->sc_dev, "invalid rx statistic header\n");
1507 device_printf(sc->sc_dev,
1526 struct wpi_rx_radiotap_header *tap = &sc->sc_rxtap;
1559 WPI_UNLOCK(sc);
1568 WPI_LOCK(sc);
1572 wpi_tx_intr(struct wpi_softc *sc, struct wpi_rx_desc *desc)
1574 struct ifnet *ifp = sc->sc_ifp;
1575 struct wpi_tx_ring *ring = &sc->txq[desc->qid & 0x3];
1616 sc->sc_tx_timer = 0;
1622 wpi_cmd_intr(struct wpi_softc *sc, struct wpi_rx_desc *desc)
1624 struct wpi_tx_ring *ring = &sc->cmdq;
1644 sc->flags &= ~WPI_FLAG_BUSY;
1649 wpi_notif_intr(struct wpi_softc *sc)
1651 struct ifnet *ifp = sc->sc_ifp;
1657 bus_dmamap_sync(sc->shared_dma.tag, sc->shared_dma.map,
1660 hw = le32toh(sc->shared->next);
1661 while (sc->rxq.cur != hw) {
1662 data = &sc->rxq.data[sc->rxq.cur];
1664 bus_dmamap_sync(sc->rxq.data_dmat, data->map,
1677 wpi_cmd_intr(sc, desc);
1682 wpi_rx_intr(sc, desc, data);
1687 wpi_tx_intr(sc, desc);
1701 device_printf(sc->sc_dev,
1703 wpi_stop_locked(sc);
1715 device_printf(sc->sc_dev,
1717 sc->flags |= WPI_FLAG_HW_RADIO_OFF;
1720 WPI_WRITE(sc, WPI_UCODE_SET, WPI_DISABLE_CMD);
1748 sc->sc_scan_timer = 0;
1769 sc->rxq.cur = (sc->rxq.cur + 1) % WPI_RX_RING_COUNT;
1774 WPI_WRITE(sc, WPI_RX_WIDX, hw & ~7);
1780 struct wpi_softc *sc = arg;
1783 WPI_LOCK(sc);
1786 r = WPI_READ(sc, WPI_INTR);
1788 WPI_UNLOCK(sc);
1793 WPI_WRITE(sc, WPI_MASK, 0);
1795 r = atomic_get((int32 *)&sc->sc_intr_status);
1799 WPI_WRITE(sc, WPI_INTR, r);
1802 struct ifnet *ifp = sc->sc_ifp;
1806 device_printf(sc->sc_dev, "fatal firmware error\n");
1811 ieee80211_runtask(ic, &sc->sc_restarttask);
1812 sc->flags &= ~WPI_FLAG_BUSY;
1813 WPI_UNLOCK(sc);
1818 wpi_notif_intr(sc);
1821 wakeup(sc);
1824 if (sc->sc_ifp->if_flags & IFF_UP)
1825 WPI_WRITE(sc, WPI_MASK, WPI_INTR_MASK);
1827 WPI_UNLOCK(sc);
1865 wpi_tx_data(struct wpi_softc *sc, struct mbuf *m0, struct ieee80211_node *ni,
1869 struct ifnet *ifp = sc->sc_ifp;
1872 struct wpi_tx_ring *ring = &sc->txq[ac];
1957 struct wpi_tx_radiotap_header *tap = &sc->sc_txtap;
1974 device_printf(sc->sc_dev, "could not map mbuf (error %d)\n",
1983 device_printf(sc->sc_dev,
1993 device_printf(sc->sc_dev,
2025 WPI_WRITE(sc, WPI_TX_WIDX, ring->qid << 8 | ring->cur);
2036 struct wpi_softc *sc = ifp->if_softc;
2038 WPI_LOCK(sc);
2040 WPI_UNLOCK(sc);
2046 struct wpi_softc *sc = ifp->if_softc;
2051 WPI_LOCK_ASSERT(sc);
2061 if (sc->txq[ac].queued > sc->txq[ac].count - 8) {
2068 if (wpi_tx_data(sc, m, ni, ac) != 0) {
2073 sc->sc_tx_timer = 5;
2083 struct wpi_softc *sc = ifp->if_softc;
2091 WPI_LOCK(sc);
2094 if (sc->txq[0].queued > sc->txq[0].count - 8) {
2097 WPI_UNLOCK(sc);
2103 if (wpi_tx_data(sc, m, ni, 0) != 0)
2105 sc->sc_tx_timer = 5;
2106 callout_reset(&sc->watchdog_to, hz, wpi_watchdog, sc);
2108 WPI_UNLOCK(sc);
2112 WPI_UNLOCK(sc);
2120 struct wpi_softc *sc = ifp->if_softc;
2127 WPI_LOCK(sc);
2130 wpi_init_locked(sc, 0);
2134 (sc->flags & WPI_FLAG_HW_RADIO_OFF))
2135 wpi_stop_locked(sc);
2136 WPI_UNLOCK(sc);
2157 wpi_read_eeprom(struct wpi_softc *sc, uint8_t macaddr[IEEE80211_ADDR_LEN])
2162 wpi_read_prom_data(sc, WPI_EEPROM_CAPABILITIES, &sc->cap,1);
2163 wpi_read_prom_data(sc, WPI_EEPROM_REVISION, &sc->rev,2);
2164 wpi_read_prom_data(sc, WPI_EEPROM_TYPE, &sc->type, 1);
2167 wpi_read_prom_data(sc, WPI_EEPROM_DOMAIN, sc->domain, 4);
2170 wpi_read_prom_data(sc, WPI_EEPROM_MAC, macaddr, 6);
2174 wpi_read_eeprom_channels(sc,i);
2178 wpi_read_eeprom_group(sc,i);
2185 wpi_cmd(struct wpi_softc *sc, int code, const void *buf, int size, int async)
2187 struct wpi_tx_ring *ring = &sc->cmdq;
2193 WPI_LOCK_ASSERT(sc);
2200 if (sc->flags & WPI_FLAG_BUSY) {
2201 device_printf(sc->sc_dev, "%s: cmd %d not sent, busy\n",
2205 sc->flags|= WPI_FLAG_BUSY;
2226 WPI_WRITE(sc, WPI_TX_WIDX, ring->qid << 8 | ring->cur);
2229 sc->flags &= ~ WPI_FLAG_BUSY;
2233 return msleep(cmd, &sc->sc_mtx, PCATCH, "wpicmd", hz);
2241 struct wpi_softc *sc = ic->ic_ifp->if_softc;
2262 return wpi_cmd(sc, WPI_CMD_SET_WME, &wme, sizeof wme, 1);
2271 wpi_mrr_setup(struct wpi_softc *sc)
2273 struct ifnet *ifp = sc->sc_ifp;
2306 error = wpi_cmd(sc, WPI_CMD_MRR_SETUP, &mrr, sizeof mrr, 0);
2308 device_printf(sc->sc_dev,
2315 error = wpi_cmd(sc, WPI_CMD_MRR_SETUP, &mrr, sizeof mrr, 0);
2317 device_printf(sc->sc_dev,
2326 wpi_set_led(struct wpi_softc *sc, uint8_t which, uint8_t off, uint8_t on)
2335 (void)wpi_cmd(sc, WPI_CMD_SET_LED, &led, sizeof led, 1);
2339 wpi_enable_tsf(struct wpi_softc *sc, struct ieee80211_node *ni)
2354 if (wpi_cmd(sc, WPI_CMD_TSF, &tsf, sizeof tsf, 1) != 0)
2355 device_printf(sc->sc_dev, "could not enable TSF\n");
2364 wpi_setup_beacon(struct wpi_softc *sc, struct ieee80211_node *ni)
2366 struct ifnet *ifp = sc->sc_ifp;
2368 struct wpi_tx_ring *ring = &sc->cmdq;
2383 device_printf(sc->sc_dev, "could not allocate beacon frame\n");
2412 device_printf(sc->sc_dev, "could not map beacon\n");
2429 WPI_WRITE(sc, WPI_TX_WIDX, ring->qid << 8 | ring->cur);
2436 wpi_auth(struct wpi_softc *sc, struct ieee80211vap *vap)
2445 sc->config.associd = 0;
2446 sc->config.filter &= ~htole32(WPI_FILTER_BSS);
2447 IEEE80211_ADDR_COPY(sc->config.bssid, ni->ni_bssid);
2448 sc->config.chan = ieee80211_chan2ieee(ic, ni->ni_chan);
2450 sc->config.flags |= htole32(WPI_CONFIG_AUTO |
2453 sc->config.flags &= ~htole32(WPI_CONFIG_AUTO |
2457 sc->config.cck_mask = 0;
2458 sc->config.ofdm_mask = 0x15;
2460 sc->config.cck_mask = 0x03;
2461 sc->config.ofdm_mask = 0;
2464 sc->config.cck_mask = 0x0f;
2465 sc->config.ofdm_mask = 0x15;
2468 DPRINTF(("config chan %d flags %x cck %x ofdm %x\n", sc->config.chan,
2469 sc->config.flags, sc->config.cck_mask, sc->config.ofdm_mask));
2470 error = wpi_cmd(sc, WPI_CMD_CONFIGURE, &sc->config,
2473 device_printf(sc->sc_dev, "could not configure\n");
2478 if ((error = wpi_set_txpower(sc, ni->ni_chan, 1)) != 0) {
2479 device_printf(sc->sc_dev, "could not set Tx power\n");
2491 error = wpi_cmd(sc, WPI_CMD_ADD_NODE, &node, sizeof node, 1);
2493 device_printf(sc->sc_dev, "could not add BSS node\n");
2499 wpi_run(struct wpi_softc *sc, struct ieee80211vap *vap)
2507 wpi_set_led(sc, WPI_LED_LINK, 5, 5);
2511 wpi_enable_tsf(sc, ni);
2514 sc->config.associd = htole16(ni->ni_associd & ~0xc000);
2516 sc->config.flags &= ~htole32(WPI_CONFIG_SHPREAMBLE |
2519 sc->config.flags |= htole32(WPI_CONFIG_SHSLOT);
2521 sc->config.flags |= htole32(WPI_CONFIG_SHPREAMBLE);
2522 sc->config.filter |= htole32(WPI_FILTER_BSS);
2526 DPRINTF(("config chan %d flags %x\n", sc->config.chan,
2527 sc->config.flags));
2528 error = wpi_cmd(sc, WPI_CMD_CONFIGURE, &sc->config, sizeof (struct
2531 device_printf(sc->sc_dev, "could not update configuration\n");
2535 error = wpi_set_txpower(sc, ni->ni_chan, 1);
2537 device_printf(sc->sc_dev, "could set txpower\n");
2542 wpi_set_led(sc, WPI_LED_LINK, 0, 1);
2545 callout_reset(&sc->calib_to, 60*hz, wpi_calib_timeout, sc);
2559 wpi_scan(struct wpi_softc *sc)
2561 struct ifnet *ifp = sc->sc_ifp;
2564 struct wpi_tx_ring *ring = &sc->cmdq;
2583 device_printf(sc->sc_dev,
2758 device_printf(sc->sc_dev, "could not map scan command\n");
2774 WPI_WRITE(sc, WPI_TX_WIDX, ring->qid << 8 | ring->cur);
2776 sc->sc_scan_timer = 5;
2785 wpi_config(struct wpi_softc *sc)
2787 struct ifnet *ifp = sc->sc_ifp;
2797 error = wpi_cmd(sc, WPI_CMD_SET_POWER_MODE, &power, sizeof power, 0);
2799 device_printf(sc->sc_dev, "could not set power mode\n");
2808 error = wpi_cmd(sc, WPI_CMD_BLUETOOTH, &bluetooth, sizeof bluetooth,
2811 device_printf(sc->sc_dev,
2817 memset(&sc->config, 0, sizeof (struct wpi_config));
2818 IEEE80211_ADDR_COPY(sc->config.myaddr, IF_LLADDR(ifp));
2820 sc->config.chan = htole16(ieee80211_chan2ieee(ic, ic->ic_curchan));
2821 sc->config.flags = htole32(WPI_CONFIG_TSF);
2823 sc->config.flags |= htole32(WPI_CONFIG_AUTO |
2826 sc->config.filter = 0;
2830 sc->config.mode = WPI_MODE_STA;
2831 sc->config.filter |= htole32(WPI_FILTER_MULTICAST);
2835 sc->config.mode = WPI_MODE_IBSS;
2836 sc->config.filter |= htole32(WPI_FILTER_BEACON |
2840 sc->config.mode = WPI_MODE_HOSTAP;
2843 sc->config.mode = WPI_MODE_MONITOR;
2844 sc->config.filter |= htole32(WPI_FILTER_MULTICAST |
2848 device_printf(sc->sc_dev, "unknown opmode %d\n", ic->ic_opmode);
2851 sc->config.cck_mask = 0x0f; /* not yet negotiated */
2852 sc->config.ofdm_mask = 0xff; /* not yet negotiated */
2853 error = wpi_cmd(sc, WPI_CMD_CONFIGURE, &sc->config,
2856 device_printf(sc->sc_dev, "configure command failed\n");
2861 if ((error = wpi_set_txpower(sc, ic->ic_curchan, 0)) != 0) {
2862 device_printf(sc->sc_dev, "could not set Tx power\n");
2871 error = wpi_cmd(sc, WPI_CMD_ADD_NODE, &node, sizeof node, 0);
2873 device_printf(sc->sc_dev, "could not add broadcast node\n");
2878 error = wpi_mrr_setup(sc);
2880 device_printf(sc->sc_dev, "could not setup MRR\n");
2888 wpi_stop_master(struct wpi_softc *sc)
2895 tmp = WPI_READ(sc, WPI_RESET);
2896 WPI_WRITE(sc, WPI_RESET, tmp | WPI_STOP_MASTER | WPI_NEVO_RESET);
2898 tmp = WPI_READ(sc, WPI_GPIO_CTL);
2903 if (WPI_READ(sc, WPI_RESET) & WPI_MASTER_DISABLED)
2908 device_printf(sc->sc_dev, "timeout waiting for master\n");
2913 wpi_power_up(struct wpi_softc *sc)
2918 wpi_mem_lock(sc);
2919 tmp = wpi_mem_read(sc, WPI_MEM_POWER);
2920 wpi_mem_write(sc, WPI_MEM_POWER, tmp & ~0x03000000);
2921 wpi_mem_unlock(sc);
2924 if (WPI_READ(sc, WPI_GPIO_STATUS) & WPI_POWERED)
2929 device_printf(sc->sc_dev,
2937 wpi_reset(struct wpi_softc *sc)
2946 WPI_WRITE(sc, WPI_INTR, 0xffffffff);
2948 tmp = WPI_READ(sc, WPI_PLL_CTL);
2949 WPI_WRITE(sc, WPI_PLL_CTL, tmp | WPI_PLL_INIT);
2951 tmp = WPI_READ(sc, WPI_CHICKEN);
2952 WPI_WRITE(sc, WPI_CHICKEN, tmp | WPI_CHICKEN_RXNOLOS);
2954 tmp = WPI_READ(sc, WPI_GPIO_CTL);
2955 WPI_WRITE(sc, WPI_GPIO_CTL, tmp | WPI_GPIO_INIT);
2959 if (WPI_READ(sc, WPI_GPIO_CTL) & WPI_GPIO_CLOCK)
2964 device_printf(sc->sc_dev,
2970 tmp = WPI_READ(sc, WPI_EEPROM_STATUS);
2973 device_printf(sc->sc_dev, "EEPROM not found\n");
2976 WPI_WRITE(sc, WPI_EEPROM_STATUS, tmp & ~WPI_EEPROM_LOCKED);
2982 wpi_hw_config(struct wpi_softc *sc)
2987 hw = WPI_READ(sc, WPI_HWCONFIG);
2989 rev = pci_read_config(sc->sc_dev, PCIR_REVID, 1);
2995 if (sc->cap == 0x80)
2999 if ((le16toh(sc->rev) & 0xf0) == 0xd0)
3002 if (sc->type > 1)
3005 WPI_WRITE(sc, WPI_HWCONFIG, hw);
3009 wpi_rfkill_resume(struct wpi_softc *sc)
3011 struct ifnet *ifp = sc->sc_ifp;
3017 WPI_WRITE(sc, WPI_UCODE_CLR, WPI_RADIO_OFF);
3018 WPI_WRITE(sc, WPI_UCODE_CLR, WPI_DISABLE_CMD);
3022 if ((sc->temp = (int)WPI_READ(sc, WPI_TEMPERATURE)) != 0)
3028 device_printf(sc->sc_dev,
3032 DPRINTFN(WPI_DEBUG_TEMP,("temperature %d\n", sc->temp));
3034 if (wpi_config(sc) != 0) {
3035 device_printf(sc->sc_dev, "device config failed\n");
3041 sc->flags &= ~WPI_FLAG_HW_RADIO_OFF;
3047 wpi_set_led(sc, WPI_LED_LINK, 0, 1);
3049 wpi_set_led(sc, WPI_LED_LINK, 5, 5);
3052 wpi_set_led(sc, WPI_LED_LINK, 20, 2);
3056 callout_reset(&sc->watchdog_to, hz, wpi_watchdog, sc);
3060 wpi_init_locked(struct wpi_softc *sc, int force)
3062 struct ifnet *ifp = sc->sc_ifp;
3066 wpi_stop_locked(sc);
3067 (void)wpi_reset(sc);
3069 wpi_mem_lock(sc);
3070 wpi_mem_write(sc, WPI_MEM_CLOCK1, 0xa00);
3072 tmp = wpi_mem_read(sc, WPI_MEM_PCIDEV);
3073 wpi_mem_write(sc, WPI_MEM_PCIDEV, tmp | 0x800);
3074 wpi_mem_unlock(sc);
3076 (void)wpi_power_up(sc);
3077 wpi_hw_config(sc);
3080 wpi_mem_lock(sc);
3081 WPI_WRITE(sc, WPI_RX_BASE, sc->rxq.desc_dma.paddr);
3082 WPI_WRITE(sc, WPI_RX_RIDX_PTR, sc->shared_dma.paddr +
3084 WPI_WRITE(sc, WPI_RX_WIDX, (WPI_RX_RING_COUNT - 1) & ~7);
3085 WPI_WRITE(sc, WPI_RX_CONFIG, 0xa9601010);
3086 wpi_mem_unlock(sc);
3089 wpi_mem_lock(sc);
3090 wpi_mem_write(sc, WPI_MEM_MODE, 2); /* bypass mode */
3091 wpi_mem_write(sc, WPI_MEM_RA, 1); /* enable RA0 */
3092 wpi_mem_write(sc, WPI_MEM_TXCFG, 0x3f); /* enable all 6 Tx rings */
3093 wpi_mem_write(sc, WPI_MEM_BYPASS1, 0x10000);
3094 wpi_mem_write(sc, WPI_MEM_BYPASS2, 0x30002);
3095 wpi_mem_write(sc, WPI_MEM_MAGIC4, 4);
3096 wpi_mem_write(sc, WPI_MEM_MAGIC5, 5);
3098 WPI_WRITE(sc, WPI_TX_BASE_PTR, sc->shared_dma.paddr);
3099 WPI_WRITE(sc, WPI_MSG_CONFIG, 0xffff05a5);
3102 WPI_WRITE(sc, WPI_TX_CTL(qid), 0);
3103 WPI_WRITE(sc, WPI_TX_BASE(qid), 0);
3104 WPI_WRITE(sc, WPI_TX_CONFIG(qid), 0x80200008);
3106 wpi_mem_unlock(sc);
3109 WPI_WRITE(sc, WPI_UCODE_CLR, WPI_RADIO_OFF);
3110 WPI_WRITE(sc, WPI_UCODE_CLR, WPI_DISABLE_CMD);
3111 sc->flags &= ~WPI_FLAG_HW_RADIO_OFF;
3114 WPI_WRITE(sc, WPI_INTR, 0xffffffff);
3117 WPI_WRITE(sc, WPI_MASK, WPI_INTR_MASK);
3119 WPI_WRITE(sc, WPI_UCODE_CLR, WPI_RADIO_OFF);
3120 WPI_WRITE(sc, WPI_UCODE_CLR, WPI_RADIO_OFF);
3122 if ((wpi_load_firmware(sc)) != 0) {
3123 device_printf(sc->sc_dev,
3133 wpi_mem_lock(sc);
3134 tmp = wpi_mem_read(sc, WPI_MEM_HW_RADIO_OFF);
3135 wpi_mem_unlock(sc);
3138 sc->flags |= WPI_FLAG_HW_RADIO_OFF;
3139 device_printf(sc->sc_dev,"Radio Transmitter is switched off\n");
3145 if ((sc->temp = (int)WPI_READ(sc, WPI_TEMPERATURE)) != 0)
3151 device_printf(sc->sc_dev,
3155 DPRINTFN(WPI_DEBUG_TEMP,("temperature %d\n", sc->temp));
3157 if (wpi_config(sc) != 0) {
3158 device_printf(sc->sc_dev, "device config failed\n");
3165 callout_reset(&sc->watchdog_to, hz, wpi_watchdog, sc);
3171 struct wpi_softc *sc = arg;
3172 struct ifnet *ifp = sc->sc_ifp;
3175 WPI_LOCK(sc);
3176 wpi_init_locked(sc, 0);
3177 WPI_UNLOCK(sc);
3184 wpi_stop_locked(struct wpi_softc *sc)
3186 struct ifnet *ifp = sc->sc_ifp;
3190 sc->sc_tx_timer = 0;
3191 sc->sc_scan_timer = 0;
3193 sc->flags &= ~WPI_FLAG_HW_RADIO_OFF;
3194 callout_stop(&sc->watchdog_to);
3195 callout_stop(&sc->calib_to);
3199 WPI_WRITE(sc, WPI_MASK, 0);
3200 WPI_WRITE(sc, WPI_INTR, WPI_INTR_MASK);
3201 WPI_WRITE(sc, WPI_INTR_STATUS, 0xff);
3202 WPI_WRITE(sc, WPI_INTR_STATUS, 0x00070000);
3204 wpi_mem_lock(sc);
3205 wpi_mem_write(sc, WPI_MEM_MODE, 0);
3206 wpi_mem_unlock(sc);
3210 wpi_reset_tx_ring(sc, &sc->txq[ac]);
3211 wpi_reset_tx_ring(sc, &sc->cmdq);
3214 wpi_reset_rx_ring(sc, &sc->rxq);
3216 wpi_mem_lock(sc);
3217 wpi_mem_write(sc, WPI_MEM_CLOCK2, 0x200);
3218 wpi_mem_unlock(sc);
3222 wpi_stop_master(sc);
3224 tmp = WPI_READ(sc, WPI_RESET);
3225 WPI_WRITE(sc, WPI_RESET, tmp | WPI_SW_RESET);
3226 sc->flags &= ~WPI_FLAG_BUSY;
3230 wpi_stop(struct wpi_softc *sc)
3232 WPI_LOCK(sc);
3233 wpi_stop_locked(sc);
3234 WPI_UNLOCK(sc);
3240 struct wpi_softc *sc = arg;
3241 struct ifnet *ifp = sc->sc_ifp;
3250 temp = (int)WPI_READ(sc, WPI_TEMPERATURE);
3253 wpi_power_calibration(sc, temp);
3255 callout_reset(&sc->calib_to, 60*hz, wpi_calib_timeout, sc);
3263 wpi_power_calibration(struct wpi_softc *sc, int temp)
3265 struct ifnet *ifp = sc->sc_ifp;
3277 DPRINTFN(WPI_DEBUG_TEMP,("temperature %d->%d\n", sc->temp, temp));
3280 if (abs(temp - sc->temp) <= 6)
3283 sc->temp = temp;
3285 if (wpi_set_txpower(sc, vap->iv_bss->ni_chan, 1) != 0) {
3287 device_printf(sc->sc_dev,"could not adjust Tx power\n");
3296 wpi_read_eeprom_channels(struct wpi_softc *sc, int n)
3298 struct ifnet *ifp = sc->sc_ifp;
3305 wpi_read_prom_data(sc, band->addr, channels,
3355 sc->maxpwr[chan] = channels[i].maxpwr;
3366 channels[i].flags, sc->maxpwr[chan],
3373 wpi_read_eeprom_group(struct wpi_softc *sc, int n)
3375 struct wpi_power_group *group = &sc->groups[n];
3379 wpi_read_prom_data(sc, WPI_EEPROM_POWER_GRP + n * 32, &rgroup,
3404 wpi_set_txpower(struct wpi_softc *sc, struct ieee80211_channel *c, int async)
3406 struct ifnet *ifp = sc->sc_ifp;
3418 for (group = &sc->groups[1]; group < &sc->groups[4]; group++)
3422 group = &sc->groups[0];
3431 int idx = wpi_get_power_index(sc, group, c,
3447 return wpi_cmd(sc, WPI_CMD_TXPOWER, &txpower, sizeof txpower, async);
3456 wpi_get_power_index(struct wpi_softc *sc, struct wpi_power_group *group,
3467 struct ifnet *ifp = sc->sc_ifp;
3493 pwr = min(pwr, sc->maxpwr[chan]);
3508 idx -= (sc->temp - group->temp) * 11 / 100;
3536 struct wpi_softc *sc = ifp->if_softc;
3538 WPI_LOCK(sc);
3539 wpi_set_led(sc, WPI_LED_LINK, 20, 2);
3540 WPI_UNLOCK(sc);
3562 struct wpi_softc *sc = ifp->if_softc;
3570 WPI_LOCK(sc);
3571 error = wpi_config(sc);
3572 WPI_UNLOCK(sc);
3574 device_printf(sc->sc_dev,
3589 struct wpi_softc *sc = ifp->if_softc;
3591 WPI_LOCK(sc);
3592 if (wpi_scan(sc))
3594 WPI_UNLOCK(sc);
3612 struct wpi_softc *sc = arg;
3614 WPI_LOCK(sc);
3615 wpi_init_locked(sc, 0);
3616 WPI_UNLOCK(sc);
3622 struct wpi_softc *sc = arg;
3624 WPI_LOCK(sc);
3625 wpi_rfkill_resume(sc);
3626 WPI_UNLOCK(sc);
3633 wpi_alloc_fwmem(struct wpi_softc *sc)
3636 return wpi_dma_contig_alloc(sc, &sc->fw_dma, NULL,
3642 wpi_free_fwmem(struct wpi_softc *sc)
3644 wpi_dma_contig_free(&sc->fw_dma);
3654 struct wpi_softc *sc = arg;
3655 struct ifnet *ifp = sc->sc_ifp;
3661 if (sc->flags & WPI_FLAG_HW_RADIO_OFF) {
3663 tmp = wpi_mem_read(sc, WPI_MEM_HW_RADIO_OFF);
3667 callout_reset(&sc->watchdog_to, hz, wpi_watchdog, sc);
3671 device_printf(sc->sc_dev, "Hardware Switch Enabled\n");
3672 ieee80211_runtask(ic, &sc->sc_radiotask);
3676 if (sc->sc_tx_timer > 0) {
3677 if (--sc->sc_tx_timer == 0) {
3678 device_printf(sc->sc_dev,"device timeout\n");
3680 ieee80211_runtask(ic, &sc->sc_restarttask);
3683 if (sc->sc_scan_timer > 0) {
3685 if (--sc->sc_scan_timer == 0 && vap != NULL) {
3686 device_printf(sc->sc_dev,"scan timeout\n");
3688 ieee80211_runtask(ic, &sc->sc_restarttask);
3693 callout_reset(&sc->watchdog_to, hz, wpi_watchdog, sc);