/* Intel 7265D/3165 PCIe transport: see iwl_trans.h. * * Register sequences follow Linux iwlwifi (pcie/trans.c, pcie/rx.c, * pcie/tx.c) for the 7000 device family: no MSI-X, no ICT, legacy single * RX queue (256 x 4 KB RBDs), gen1 128-byte TFDs, byte-count table in * dwords. Everything is polled; CSR_INT_MASK stays zero and PCI INTx is * disabled, so the card never raises an interrupt. * * The NIC is kept awake (MAC_ACCESS_REQ held) the whole time it is up: the * firmware is configured without power save, and holding the request is * what Linux does while host commands are in flight (apmg_wake_up_wa). */ #include "iwl_trans.h" #include "mm.h" #include "paging.h" #include "pci.h" #include "process.h" #include "ramfs.h" #include "serial.h" /* Per-family transport parameters (Linux: iwl_cfg_trans_params plus the * op_mode's iwl_trans_config). The 7000 family runs the MVM firmware with * DQA queues and wide command headers; the 6000 family runs the DVM * firmware with the four AC queues, the command queue on 4 and 4-byte * headers. */ struct iwl_family { const char *fw_path; unsigned char dvm; /* DVM firmware (6000) vs MVM (7000) */ unsigned char tlv; /* TLV .ucode vs the v2 fixed header */ unsigned char cmd_q, cmd_fifo, nq; unsigned char wide_hdr; /* mvm: trans->wide_cmd_header */ unsigned char bc_dword; /* byte-count table in dwords */ unsigned char scd_set_active; /* mvm: trans_cfg.scd_set_active */ unsigned char chain_ext_wa; /* base_params->scd_chain_ext_wa */ unsigned char shadow_reg; /* base_params->shadow_reg_enable */ unsigned char wake_me; /* tell ME we leave (7000 family) */ unsigned char q[4], q_slots[4]; /* data/mgmt queues to allocate */ }; static const struct iwl_family fam_7000 = { "firmware/iwlwifi-7265D-29.ucode", 0, 1, IWL_Q_CMD, 7, 31, 1, 1, 1, 0, 1, 1, { IWL_Q_AUX, IWL_Q_BSS, 0xff, 0xff }, { 8, 32, 0, 0 }, }; static const struct iwl_family fam_6000 = { "firmware/iwlwifi-6000-4.ucode", 1, 0, IWL_DVM_Q_CMD, 7, 20, 0, 0, 0, 1, 0, 0, { IWL_DVM_Q_VO, IWL_DVM_Q_VI, IWL_DVM_Q_BE, IWL_DVM_Q_BK }, { 16, 4, 32, 4 }, }; /* ---- CSR / HBUS / FH / PRPH registers (iwl-csr.h, iwl-fh.h, iwl-prph.h) */ #define CSR_HW_IF_CONFIG_REG 0x000 #define CSR_INT_COALESCING 0x004 #define CSR_INT 0x008 #define CSR_INT_MASK 0x00c #define CSR_FH_INT_STATUS 0x010 #define CSR_RESET 0x020 #define CSR_GP_CNTRL 0x024 #define CSR_HW_REV 0x028 #define CSR_GIO_REG 0x03c #define CSR_UCODE_DRV_GP1_CLR 0x05c #define CSR_MBOX_SET_REG 0x088 #define CSR_MAC_SHADOW_REG_CTRL 0x0a8 #define CSR_GIO_CHICKEN_BITS 0x100 #define CSR_DBG_HPET_MEM_REG 0x240 #define CSR_DBG_LINK_PWR_MGMT_REG 0x250 #define HW_IF_NIC_READY 0x00400000u #define HW_IF_PREPARE 0x08000000u #define HW_IF_HAP_WAKE_L1A 0x00080000u #define INT_FH_RX (1u << 31) #define INT_HW_ERR (1u << 29) #define INT_FH_TX (1u << 27) #define INT_SW_ERR (1u << 25) #define INT_SW_RX (1u << 3) #define INT_ALIVE (1u << 0) #define RESET_SW_RESET 0x00000080u #define RESET_MASTER_DISABLED 0x00000100u #define RESET_STOP_MASTER 0x00000200u #define GP_MAC_CLOCK_READY 0x00000001u #define GP_INIT_DONE 0x00000004u #define GP_MAC_ACCESS_REQ 0x00000008u #define GP_GOING_TO_SLEEP 0x00000010u #define GP_HW_RF_KILL_SW 0x08000000u #define UCODE_SW_BIT_RFKILL 0x00000002u #define UCODE_CMD_BLOCKED 0x00000004u #define MBOX_OS_ALIVE (1u << 5) #define GIO_L0S_DISABLED 0x00000002u #define GIO_CHICKEN_L1A_NO_L0S_RX 0x00800000u #define GIO_CHICKEN_DIS_L0S_TIMER 0x20000000u #define LINK_PWR_MGMT_DISABLED 0x80000000u #define HBUS_TARG_MEM_WADDR 0x410 #define HBUS_TARG_MEM_WDAT 0x418 #define HBUS_TARG_PRPH_WADDR 0x444 #define HBUS_TARG_PRPH_RADDR 0x448 #define HBUS_TARG_PRPH_WDAT 0x44c #define HBUS_TARG_PRPH_RDAT 0x450 #define HBUS_TARG_WRPTR 0x460 #define FH_KW_MEM_ADDR_REG 0x197c #define FH_RSCSR_STTS_WPTR 0x1bc0 #define FH_RSCSR_RBDCB_BASE 0x1bc4 #define FH_RSCSR_RBDCB_WPTR 0x1bc8 #define FH_RSCSR_RDPTR 0x1bcc #define FH_RCSR_CONFIG 0x1c00 #define FH_RCSR_RBDCB_WPTR 0x1c08 #define FH_RCSR_FLUSH_RB_REQ 0x1c10 #define FH_TFDIB_CTRL0(c) (0x1900 + 8 * (c)) #define FH_TFDIB_CTRL1(c) (0x1904 + 8 * (c)) #define FH_TCSR_CONFIG(c) (0x1d00 + 0x20 * (c)) #define FH_TCSR_BUF_STS(c) (0x1d08 + 0x20 * (c)) #define FH_SRVC_CHNL 9 #define FH_SRVC_SRAM_ADDR 0x19c8 #define FH_TX_CHICKEN_BITS 0x1e98 #define FH_TCSR_DMA_ENABLE 0x80000000u #define FH_TCSR_CREDIT_ENABLE 0x00000008u #define FH_TCSR_HOST_ENDTFD 0x00100000u #define FH_MEM_TB_MAX_LENGTH 0x20000u #define APMG_CLK_EN_REG 0x3004 #define APMG_PS_CTRL_REG 0x300c #define APMG_PCIDEV_STT_REG 0x3010 #define APMG_RTC_INT_STT_REG 0x301c #define APMG_CLK_DMA_RQT 0x00000200u #define APMG_PS_PWR_SRC_MSK 0x03000000u #define APMG_PCIDEV_L1_ACT_DIS 0x00000800u #define APMG_PCIDEV_WAKE_ME 0x00004000u #define APMG_RTC_INT_RFKILL 0x10000000u #define LMPM_CHICK 0xa01ff8 #define LMPM_EXTENDED_ADDR 0x1u #define FW_MEM_EXT_START 0x40000u #define FW_MEM_EXT_END 0x57fffu #define SCD_BASE 0xa02c00 #define SCD_SRAM_BASE_ADDR (SCD_BASE + 0x0) #define SCD_DRAM_BASE_ADDR (SCD_BASE + 0x8) #define SCD_TXFACT (SCD_BASE + 0x10) #define SCD_QUEUECHAIN_SEL (SCD_BASE + 0xe8) #define SCD_CHAINEXT_EN (SCD_BASE + 0x244) #define SCD_AGGR_SEL (SCD_BASE + 0x248) #define SCD_GP_CTRL (SCD_BASE + 0x1a8) #define SCD_EN_CTRL (SCD_BASE + 0x254) #define SCD_GP_AUTO_ACTIVE (1u << 18) #define SCD_GP_31_QUEUES (1u << 0) #define SCD_CONTEXT_MEM 0x600 #define SCD_TRANS_TBL_MEM 0x7e0 #define SCD_STTS_ACTIVE 3 #define SCD_STTS_TXF 0 #define SCD_STTS_WSL 4 #define SCD_STTS_ACT_EN 19 #define SCD_STTS_MSK 0x017f0000u static unsigned int scd_queue_rdptr(unsigned int q) { return q < 20 ? SCD_BASE + 0x68 + q * 4 : SCD_BASE + 0x2b4 + q * 4; } static unsigned int scd_queue_status(unsigned int q) { return q < 20 ? SCD_BASE + 0x10c + q * 4 : SCD_BASE + 0x334 + (q - 20) * 4; } static unsigned int fh_cbbc(unsigned int q) { if (q < 16) return 0x19d0 + 4 * q; if (q < 20) return 0x1bf0 + 4 * (q - 16); return 0x1b20 + 4 * (q - 20); } /* ---- device state ------------------------------------------------------ */ #define RX_RING 256 #define TFD_SIZE 128 #define TFD_RING 256 #define BC_ENTRIES 320 /* 256 + 64 duplicate */ #define CMD_SLOTS 32 #define CMD_BUF 4096 /* one page per command slot */ #define DATA_SLOTS 32 #define DATA_BUF 2048 #define FIRST_TB 20 /* IWL_FIRST_TB_SIZE */ struct txq { unsigned char *tfds; /* 256 x 128-byte TFDs */ unsigned char *bufs; /* slots x bufsize */ unsigned int nslots, bufsize; unsigned int wptr, rptr; /* 0..255 */ int active; }; struct iwl_state { volatile unsigned char *mmio; unsigned int bar, bus, dev, func, devid, hw_rev; const char *chip; unsigned int *rbd; /* RX descriptors (page) */ unsigned char *rb[RX_RING]; /* RX buffers (4 KB pages) */ volatile unsigned short *rb_stts; unsigned int rx_read; unsigned short *bc; /* byte-count tables, IWL_NUM_Q x 320 */ unsigned char *kw; /* keep-warm page */ unsigned char *fwbuf; /* 128 KB firmware chunk bounce buffer */ struct txq q[IWL_NUM_Q]; unsigned int scd_base; iwl_rx_handler handler; /* synchronous command bookkeeping */ int waiting; /* a command is waiting for its response */ unsigned short wait_seq; void *resp; unsigned int resp_max; int resp_len, resp_done; unsigned char wait_notif; int notif_seen; int fatal; struct iwl_fw_info fw; const unsigned char *fw_data; unsigned int fw_size; const struct iwl_family *fam; unsigned int sub; /* IWL_SUB_* within the family */ void (*nic_config)(void); /* op-mode NIC config (DVM), may be 0 */ /* v2 (pre-TLV) image: [IWL_IMG_*] instruction and data sections */ const unsigned char *img_inst[2], *img_data[2]; unsigned int img_inst_len[2], img_data_len[2]; }; static struct iwl_state *S; /* page-allocated on probe */ typedef char iwl_state_fits_page[sizeof(struct iwl_state) <= 4096 ? 1 : -1]; void iwl_log(const char *s) { serial_puts(SERIAL_COM1, "iwl: "); serial_puts(SERIAL_COM1, s); serial_puts(SERIAL_COM1, "\n"); } void iwl_loghex(const char *s, unsigned int v) { serial_puts(SERIAL_COM1, "iwl: "); serial_puts(SERIAL_COM1, s); serial_puts(SERIAL_COM1, " "); serial_puthex(SERIAL_COM1, v); serial_puts(SERIAL_COM1, "\n"); } /* Byte helpers: the kernel has no libc, and `rep` string ops keep gcc from * turning a loop back into a memcpy/memset call. */ void iwl_memcpy(void *dst, const void *src, unsigned int n) { __asm__ volatile ("cld; rep movsb" : "+D"(dst), "+S"(src), "+c"(n) : : "memory"); } void iwl_memzero(void *dst, unsigned int n) { __asm__ volatile ("cld; rep stosb" : "+D"(dst), "+c"(n) : "a"(0) : "memory"); } /* ~1 us per port-0x80 write on every chipset; works with interrupts off * (some network syscalls run with IF=0, which freezes get_ticks_ms()). */ void iwl_udelay(unsigned int us) { while (us--) port_outb(0x80, 0); } unsigned int iwl_rd(unsigned int reg) { return *(volatile unsigned int *)(S->mmio + reg); } void iwl_wr(unsigned int reg, unsigned int val) { *(volatile unsigned int *)(S->mmio + reg) = val; } static void iwl_set(unsigned int reg, unsigned int bits) { iwl_wr(reg, iwl_rd(reg) | bits); } static void iwl_clr(unsigned int reg, unsigned int bits) { iwl_wr(reg, iwl_rd(reg) & ~bits); } /* Poll until (reg & mask) == (bits & mask); timeout in microseconds. */ static int iwl_poll(unsigned int reg, unsigned int bits, unsigned int mask, unsigned int us) { unsigned int t; for (t = 0; t < us; t += 10) { if ((iwl_rd(reg) & mask) == (bits & mask)) return 0; iwl_udelay(10); } return -1; } unsigned int iwl_rd_prph(unsigned int addr) { iwl_wr(HBUS_TARG_PRPH_RADDR, (addr & 0x000fffffu) | (3u << 24)); return iwl_rd(HBUS_TARG_PRPH_RDAT); } void iwl_wr_prph(unsigned int addr, unsigned int val) { iwl_wr(HBUS_TARG_PRPH_WADDR, (addr & 0x000fffffu) | (3u << 24)); iwl_wr(HBUS_TARG_PRPH_WDAT, val); } static void prph_set(unsigned int addr, unsigned int bits) { iwl_wr_prph(addr, iwl_rd_prph(addr) | bits); } static void prph_clr(unsigned int addr, unsigned int bits) { iwl_wr_prph(addr, iwl_rd_prph(addr) & ~bits); } unsigned int iwl_mem_rd32(unsigned int addr) { iwl_wr(0x40c /* HBUS_TARG_MEM_RADDR */, addr); return iwl_rd(0x41c /* HBUS_TARG_MEM_RDAT */); } static void mem_wr32(unsigned int addr, unsigned int val) { iwl_wr(HBUS_TARG_MEM_WADDR, addr); iwl_wr(HBUS_TARG_MEM_WDAT, val); } static void mem_zero(unsigned int addr, unsigned int dwords) { iwl_wr(HBUS_TARG_MEM_WADDR, addr); while (dwords--) iwl_wr(HBUS_TARG_MEM_WDAT, 0); } /* Wake the MAC and keep it awake (MAC_ACCESS_REQ stays set). */ static int grab_nic(void) { iwl_set(CSR_GP_CNTRL, GP_MAC_ACCESS_REQ); if (iwl_poll(CSR_GP_CNTRL, GP_MAC_CLOCK_READY, GP_MAC_CLOCK_READY | GP_GOING_TO_SLEEP, 15000) < 0) { iwl_loghex("nic access timeout, GP_CNTRL", iwl_rd(CSR_GP_CNTRL)); return -1; } return 0; } /* ---- probe --------------------------------------------------------------- */ static const char *chip_for(unsigned int devid, const struct iwl_family **fam, unsigned int *sub) { *fam = &fam_7000; *sub = IWL_SUB_7265; switch (devid) { case 0x095a: case 0x095b: return "Intel Wireless 7265"; case 0x3165: case 0x3166: return "Intel Wireless 3165"; } *fam = &fam_6000; switch (devid) { case 0x4239: case 0x422c: *sub = IWL_SUB_6000I; return "Intel Centrino Advanced-N 6200"; case 0x4238: case 0x422b: *sub = IWL_SUB_6000; return "Intel Centrino Ultimate-N 6300"; } return 0; } /* The firmware reported SW_ERR/HW_ERR: it is dead until reloaded. */ int iwl_fatal(void) { return S && S->fatal; } int iwl_is_dvm(void) { return S && S->fam->dvm; } unsigned int iwl_subfamily(void) { return S ? S->sub : 0; } void iwl_set_nic_config(void (*fn)(void)) { if (S) S->nic_config = fn; } int iwl_present(void) { return S != 0; } const char *iwl_chip_name(void) { return S ? S->chip : "none"; } unsigned int iwl_hw_rev(void) { return S ? S->hw_rev : 0; } const struct iwl_fw_info *iwl_fw(void) { return S ? &S->fw : 0; } const unsigned char *iwl_fw_data(unsigned int *size) { if (!S) return 0; *size = S->fw_size; return S->fw_data; } /* Put the function in D0 (PCI PM capability), as pci_enable_device() * does; firmware can leave an unused WiFi card in D3hot. */ static void pci_d0(unsigned int bus, unsigned int dev, unsigned int func) { unsigned int cap, n; if (!((pci_cfg_read32(bus, dev, func, 0x04) >> 16) & 0x10)) return; cap = pci_cfg_read32(bus, dev, func, 0x34) & 0xfcu; for (n = 0; cap && n < 48; n++) { unsigned int hdr = pci_cfg_read32(bus, dev, func, cap); if ((hdr & 0xff) == 0x01) { unsigned int pmcsr = pci_cfg_read32(bus, dev, func, cap + 4); if (pmcsr & 3u) { pci_cfg_write32(bus, dev, func, cap + 4, pmcsr & ~3u); iwl_udelay(10000); iwl_log("PCI D3 -> D0"); } return; } cap = (hdr >> 8) & 0xfcu; } } int iwl_probe(void) { unsigned int bus, dev, func; if (S) return 0; for (bus = 0; bus < 256; bus++) { for (dev = 0; dev < 32; dev++) { unsigned int id = pci_cfg_read32(bus, dev, 0, 0); unsigned int nfunc; if (id == 0xffffffffu || id == 0) continue; nfunc = (pci_cfg_read32(bus, dev, 0, 0x0c) & 0x800000u) ? 8 : 1; for (func = 0; func < nfunc; func++) { unsigned int idf = pci_cfg_read32(bus, dev, func, 0); unsigned int bar, cmd, page, sub; const struct iwl_family *fam; const char *name; if ((idf & 0xffffu) != 0x8086) continue; name = chip_for(idf >> 16, &fam, &sub); if (!name) continue; bar = pci_cfg_read32(bus, dev, func, 0x10); if (bar & 1u) continue; bar &= 0xfffffff0u; if (!bar) { iwl_log("BAR0 unassigned"); continue; } page = mm_alloc_page(); if (!page) return -1; S = (struct iwl_state *)page; iwl_memzero(S, 4096); S->bar = bar; S->bus = bus; S->dev = dev; S->func = func; S->devid = idf >> 16; S->chip = name; S->fam = fam; S->sub = sub; pci_d0(bus, dev, func); /* Memory + bus master, INTx off (polled). */ cmd = pci_cfg_read32(bus, dev, func, 0x04); pci_cfg_write32(bus, dev, func, 0x04, (cmd & 0xffffu) | 0x0006u | 0x0400u); /* PCI_CFG_RETRY_TIMEOUT (0x41) = 0, like Linux. */ pci_cfg_write8(bus, dev, func, 0x41, 0); /* Map the 8 KB CSR window in every address space * (probe may run after processes exist). */ process_map_mmio_all(bar, 0x2000); S->mmio = (volatile unsigned char *)bar; iwl_wr(CSR_INT_MASK, 0); S->hw_rev = iwl_rd(CSR_HW_REV); serial_puts(SERIAL_COM1, "iwl: "); serial_puts(SERIAL_COM1, name); serial_puts(SERIAL_COM1, " dev "); serial_puthex(SERIAL_COM1, S->devid); serial_puts(SERIAL_COM1, " hw_rev "); serial_puthex(SERIAL_COM1, S->hw_rev); serial_puts(SERIAL_COM1, " bar "); serial_puthex(SERIAL_COM1, bar); serial_puts(SERIAL_COM1, "\n"); if (S->hw_rev == 0xffffffffu) { iwl_log("HW_REV reads ~0: PCI issue"); S = 0; return -1; } /* 0x095a/b: only rev-D silicon runs the 7265D * firmware (Linux: CSR_HW_REV_TYPE_7265D). */ if (!fam->dvm && S->devid != 0x3165 && S->devid != 0x3166 && (S->hw_rev & 0xfff0u) != 0x210u) iwl_log("warning: not a 7265D; the 7265D firmware may fail"); return 0; } } } return -1; } /* ---- firmware file ------------------------------------------------------- */ #define TLV_INST 1 #define TLV_FLAGS 18 #define TLV_SEC_RT 19 #define TLV_SEC_INIT 20 #define TLV_DEF_CALIB 22 #define TLV_PHY_SKU 23 #define TLV_API_CHANGES 29 #define TLV_ENABLED_CAPA 30 static unsigned int le32(const unsigned char *p) { return p[0] | (p[1] << 8) | (p[2] << 16) | ((unsigned int)p[3] << 24); } /* Pre-TLV image (iwl-drv.c iwl_parse_v1_v2_firmware(), API >= 3 = v2): * ver, build, inst, data, init, init_data, boot sizes, then the sections * in that order. */ static int fw_parse_v2(const unsigned char *d, unsigned int size) { unsigned int inst, data, init, initd, boot, o = 28; if (size < 28) return -1; S->fw.ver = le32(d); inst = le32(d + 8); data = le32(d + 12); init = le32(d + 16); initd = le32(d + 20); boot = le32(d + 24); if (((S->fw.ver >> 8) & 0xff) < 3 || o + inst + data + init + initd + boot != size || !inst || !init) { iwl_log("firmware is not a v2 .ucode image"); return -1; } S->img_inst[IWL_IMG_RT] = d + o; S->img_inst_len[IWL_IMG_RT] = inst; o += inst; S->img_data[IWL_IMG_RT] = d + o; S->img_data_len[IWL_IMG_RT] = data; o += data; S->img_inst[IWL_IMG_INIT] = d + o; S->img_inst_len[IWL_IMG_INIT] = init; o += init; S->img_data[IWL_IMG_INIT] = d + o; S->img_data_len[IWL_IMG_INIT] = initd; { static const char hx[] = "0123456789abcdef"; unsigned int i, v = S->fw.ver; char *h = S->fw.human; /* "6000 v9.221.4.1", like Linux's "%u.%u.%u.%u" */ h[0] = 'v'; for (i = 0; i < 4; i++) { unsigned int b = (v >> (24 - 8 * i)) & 0xff; *++h = hx[b >> 4 & 0xf]; *++h = hx[b & 0xf]; if (i < 3) *++h = '.'; } *++h = 0; } return 0; } int iwl_fw_parse(void) { const unsigned char *d; unsigned int size, off, i; if (!S) return -1; if (S->fw.present) return 0; d = ramfs_lookup(S->fam->fw_path, &size); if (!d) { iwl_log("firmware missing from /ramfs:"); iwl_log(S->fam->fw_path); return -1; } if (!S->fam->tlv) { if (fw_parse_v2(d, size) < 0) return -1; S->fw_data = d; S->fw_size = size; S->fw.present = 1; iwl_log(S->fw.human); return 0; } if (size < 88 || le32(d) != 0 || le32(d + 4) != 0x0a4c5749u) { iwl_log("firmware is not a TLV image"); return -1; } S->fw_data = d; S->fw_size = size; for (i = 0; i < sizeof(S->fw.human) - 1 && d[8 + i]; i++) S->fw.human[i] = (char)d[8 + i]; S->fw.ver = le32(d + 72); off = 88; while (off + 8 <= size) { unsigned int t = le32(d + off), l = le32(d + off + 4); const unsigned char *p = d + off + 8; if (off + 8 + l > size) break; if (t == TLV_API_CHANGES && l >= 8 && le32(p) < 4) S->fw.api[le32(p)] = le32(p + 4); else if (t == TLV_ENABLED_CAPA && l >= 8 && le32(p) < 4) S->fw.capa[le32(p)] = le32(p + 4); else if (t == TLV_PHY_SKU && l >= 4) S->fw.phy_sku = le32(p); else if (t == TLV_DEF_CALIB && l >= 12) { unsigned int type = le32(p); /* enum iwl_ucode_type: 0 REGULAR, 1 INIT */ if (type < 2) { S->fw.flow_trigger[type] = le32(p + 4); S->fw.event_trigger[type] = le32(p + 8); } } off += 8 + ((l + 3) & ~3u); } S->fw.present = 1; iwl_log(S->fw.human); return 0; } /* ---- hardware bring-up ------------------------------------------------- */ int iwl_rfkill(void) { return S && !(iwl_rd(CSR_GP_CNTRL) & GP_HW_RF_KILL_SW); } static int set_hw_ready(void) { iwl_set(CSR_HW_IF_CONFIG_REG, HW_IF_NIC_READY); if (iwl_poll(CSR_HW_IF_CONFIG_REG, HW_IF_NIC_READY, HW_IF_NIC_READY, 50) < 0) return -1; iwl_set(CSR_MBOX_SET_REG, MBOX_OS_ALIVE); return 0; } static int prepare_card(void) { int iter, t; if (set_hw_ready() == 0) return 0; iwl_set(CSR_DBG_LINK_PWR_MGMT_REG, LINK_PWR_MGMT_DISABLED); iwl_udelay(1000); for (iter = 0; iter < 10; iter++) { iwl_set(CSR_HW_IF_CONFIG_REG, HW_IF_PREPARE); for (t = 0; t < 150000; t += 200) { if (set_hw_ready() == 0) return 0; iwl_udelay(200); } iwl_udelay(25000); } iwl_log("card not ready (owned by ME/AMT?)"); return -1; } static int apm_init(void) { iwl_set(CSR_GIO_CHICKEN_BITS, GIO_CHICKEN_DIS_L0S_TIMER); iwl_set(CSR_GIO_CHICKEN_BITS, GIO_CHICKEN_L1A_NO_L0S_RX); iwl_set(CSR_DBG_HPET_MEM_REG, 0xffff0000u); iwl_set(CSR_HW_IF_CONFIG_REG, HW_IF_HAP_WAKE_L1A); iwl_set(CSR_GIO_REG, GIO_L0S_DISABLED); /* iwl_finish_nic_init(): INIT_DONE, then wait for the MAC clock. */ iwl_set(CSR_GP_CNTRL, GP_INIT_DONE); if (iwl_poll(CSR_GP_CNTRL, GP_MAC_CLOCK_READY, GP_MAC_CLOCK_READY, 25000) < 0) { iwl_log("MAC clock not ready"); return -1; } if (grab_nic() < 0) return -1; iwl_wr_prph(APMG_CLK_EN_REG, APMG_CLK_DMA_RQT); iwl_udelay(20); prph_set(APMG_PCIDEV_STT_REG, APMG_PCIDEV_L1_ACT_DIS); iwl_wr_prph(APMG_RTC_INT_STT_REG, APMG_RTC_INT_RFKILL); return 0; } static void stop_master(void) { iwl_set(CSR_RESET, RESET_STOP_MASTER); if (iwl_poll(CSR_RESET, RESET_MASTER_DISABLED, RESET_MASTER_DISABLED, 100) < 0) iwl_log("master disable timed out"); } int iwl_start_hw(void) { if (!S) return -1; if (prepare_card() < 0) return -1; iwl_set(CSR_RESET, RESET_SW_RESET); iwl_udelay(6000); if (prepare_card() < 0) return -1; if (apm_init() < 0) return -1; iwl_wr(CSR_INT, 0xffffffffu); iwl_wr(CSR_FH_INT_STATUS, 0xffffffffu); return 0; } static void rx_stop(void) { iwl_wr(FH_RCSR_CONFIG, 0); iwl_poll(0x1c44 /* FH_MEM_RSSR_RX_STATUS_REG */, 0x01000000u, 0x01000000u, 1000); } void iwl_stop_device(void) { unsigned int c; if (!S || !S->mmio) return; iwl_wr(CSR_INT_MASK, 0); if (iwl_rd(CSR_GP_CNTRL) & GP_MAC_CLOCK_READY) { /* Stop the scheduler, every TX DMA channel and RX DMA. */ iwl_wr_prph(SCD_TXFACT, 0); for (c = 0; c < 8; c++) iwl_wr(FH_TCSR_CONFIG(c), 0); rx_stop(); iwl_wr_prph(APMG_CLK_EN_REG, APMG_CLK_DMA_RQT); /* Inform ME that we are leaving (7000 family). */ if (S->fam->wake_me) { prph_set(APMG_PCIDEV_STT_REG, APMG_PCIDEV_WAKE_ME); iwl_udelay(5000); } } stop_master(); iwl_set(CSR_RESET, RESET_SW_RESET); iwl_udelay(6000); iwl_clr(CSR_GP_CNTRL, GP_INIT_DONE | GP_MAC_ACCESS_REQ); iwl_wr(CSR_INT, 0xffffffffu); iwl_wr(CSR_FH_INT_STATUS, 0xffffffffu); for (c = 0; c < IWL_NUM_Q; c++) S->q[c].active = 0; } /* ---- ring allocation ---------------------------------------------------- */ static void *alloc_zero(unsigned int pages) { unsigned int p = mm_alloc_pages(pages); if (p) iwl_memzero((void *)p, pages * 4096); return (void *)p; } static int alloc_txq(int qn, unsigned int slots, unsigned int bufsize) { struct txq *q = &S->q[qn]; if (!q->tfds) { q->tfds = alloc_zero(TFD_RING * TFD_SIZE / 4096); q->bufs = alloc_zero((slots * bufsize + 4095) / 4096); if (!q->tfds || !q->bufs) return -1; q->nslots = slots; q->bufsize = bufsize; } iwl_memzero(q->tfds, TFD_RING * TFD_SIZE); q->wptr = q->rptr = 0; q->active = 0; return 0; } static int alloc_rings(void) { unsigned int i; if (!S->rbd) { S->rbd = alloc_zero(1); S->rb_stts = alloc_zero(1); S->bc = alloc_zero((IWL_NUM_Q * BC_ENTRIES * 2 + 4095) / 4096); S->kw = alloc_zero(1); S->fwbuf = alloc_zero(FH_MEM_TB_MAX_LENGTH / 4096); if (!S->rbd || !S->rb_stts || !S->bc || !S->kw || !S->fwbuf) return -1; for (i = 0; i < RX_RING; i++) { S->rb[i] = (unsigned char *)mm_alloc_page(); if (!S->rb[i]) return -1; } } if (alloc_txq(S->fam->cmd_q, CMD_SLOTS, CMD_BUF) < 0) return -1; for (i = 0; i < 4; i++) if (S->fam->q[i] != 0xff && alloc_txq(S->fam->q[i], S->fam->q_slots[i], DATA_BUF) < 0) return -1; return 0; } static void rx_init(void) { unsigned int i; for (i = 0; i < RX_RING; i++) { *(volatile unsigned int *)S->rb[i] = 0x55550000u; /* FRAME_INVALID */ S->rbd[i] = (unsigned int)S->rb[i] >> 8; } iwl_memzero((void *)S->rb_stts, 16); S->rx_read = 0; iwl_wr(FH_RCSR_CONFIG, 0); iwl_wr(FH_RCSR_RBDCB_WPTR, 0); iwl_wr(FH_RCSR_FLUSH_RB_REQ, 0); iwl_wr(FH_RSCSR_RDPTR, 0); iwl_wr(FH_RSCSR_RBDCB_WPTR, 0); iwl_wr(FH_RSCSR_RBDCB_BASE, (unsigned int)S->rbd >> 8); iwl_wr(FH_RSCSR_STTS_WPTR, (unsigned int)S->rb_stts >> 4); /* enable | ignore RXF empty | irq to host | 4K RBs | RB timeout 0x11 | * 256 RBDs (log 8). */ iwl_wr(FH_RCSR_CONFIG, 0x80000000u | 0x4u | 0x1000u | 0 | (0x11u << 4) | (8u << 20)); *(volatile unsigned char *)(S->mmio + CSR_INT_COALESCING) = 0x40; /* Hand every buffer but the last 8 to the hardware (write pointer * moves in multiples of 8). */ iwl_wr(FH_RSCSR_RBDCB_WPTR, (RX_RING - 8) & ~7u); } static void tx_init(void) { unsigned int q; iwl_wr_prph(SCD_TXFACT, 0); iwl_wr(FH_KW_MEM_ADDR_REG, (unsigned int)S->kw >> 4); for (q = 0; q < IWL_NUM_Q; q++) if (S->q[q].tfds) iwl_wr(fh_cbbc(q), (unsigned int)S->q[q].tfds >> 8); prph_set(SCD_GP_CTRL, SCD_GP_AUTO_ACTIVE | (S->fam->nq > 20 ? SCD_GP_31_QUEUES : 0)); } /* ---- firmware load ------------------------------------------------------ */ static int load_chunk(unsigned int dst, const unsigned char *src, unsigned int n) { int ext = dst >= FW_MEM_EXT_START && dst <= FW_MEM_EXT_END; unsigned int t; iwl_memcpy(S->fwbuf, src, n); if (ext) prph_set(LMPM_CHICK, LMPM_EXTENDED_ADDR); iwl_wr(CSR_INT, INT_FH_TX); iwl_wr(CSR_FH_INT_STATUS, 0xffffffffu); iwl_wr(FH_TCSR_CONFIG(FH_SRVC_CHNL), 0); iwl_wr(FH_SRVC_SRAM_ADDR, dst); iwl_wr(FH_TFDIB_CTRL0(FH_SRVC_CHNL), (unsigned int)S->fwbuf); iwl_wr(FH_TFDIB_CTRL1(FH_SRVC_CHNL), n); iwl_wr(FH_TCSR_BUF_STS(FH_SRVC_CHNL), (1u << 20) | (1u << 12) | 3u); iwl_wr(FH_TCSR_CONFIG(FH_SRVC_CHNL), FH_TCSR_DMA_ENABLE | FH_TCSR_HOST_ENDTFD); for (t = 0; t < 5000000; t += 10) { if (iwl_rd(CSR_INT) & INT_FH_TX) break; iwl_udelay(10); } iwl_wr(CSR_INT, INT_FH_TX); iwl_wr(CSR_FH_INT_STATUS, 0xffffffffu); if (ext) prph_clr(LMPM_CHICK, LMPM_EXTENDED_ADDR); if (t >= 5000000) { iwl_loghex("firmware chunk timeout at", dst); return -1; } return 0; } static int load_section(unsigned int dst, const unsigned char *p, unsigned int len) { unsigned int o; for (o = 0; o < len; o += FH_MEM_TB_MAX_LENGTH) { unsigned int n = len - o; if (n > FH_MEM_TB_MAX_LENGTH) n = FH_MEM_TB_MAX_LENGTH; if (load_chunk(dst + o, p + o, n) < 0) return -1; } return 0; } static int load_sections(int img) { unsigned int want = img == IWL_IMG_INIT ? TLV_SEC_INIT : TLV_SEC_RT; const unsigned char *d = S->fw_data; unsigned int off = 88, nsec = 0; if (!S->fam->tlv) { /* IWLAGN_RTC_INST_LOWER_BOUND / IWLAGN_RTC_DATA_LOWER_BOUND */ if (load_section(0x000000, S->img_inst[img], S->img_inst_len[img]) < 0 || load_section(0x800000, S->img_data[img], S->img_data_len[img]) < 0) return -1; return 0; } while (off + 8 <= S->fw_size) { unsigned int t = le32(d + off), l = le32(d + off + 4); const unsigned char *p = d + off + 8; if (t == want && l > 4) { unsigned int dst = le32(p), len = l - 4, o; /* CPU1_CPU2 / paging separators end the CPU1 list * (single-CPU image: nothing follows that we load). */ if (dst == 0xffffccccu || dst == 0xaaaabbbbu) break; for (o = 0; o < len; o += FH_MEM_TB_MAX_LENGTH) { unsigned int n = len - o; if (n > FH_MEM_TB_MAX_LENGTH) n = FH_MEM_TB_MAX_LENGTH; if (load_chunk(dst + o, p + 4 + o, n) < 0) return -1; } nsec++; } off += 8 + ((l + 3) & ~3u); } return nsec ? 0 : -1; } int iwl_load_fw(int img) { if (!S || !S->fw.present) return -1; if (prepare_card() < 0) return -1; iwl_wr(CSR_INT, 0xffffffffu); iwl_wr(CSR_UCODE_DRV_GP1_CLR, UCODE_SW_BIT_RFKILL); iwl_wr(CSR_UCODE_DRV_GP1_CLR, UCODE_CMD_BLOCKED); iwl_wr(CSR_INT, 0xffffffffu); /* iwl_pcie_nic_init(): APM, power source VMAIN, NIC config, rings. */ if (apm_init() < 0) return -1; iwl_wr_prph(APMG_PS_CTRL_REG, iwl_rd_prph(APMG_PS_CTRL_REG) & ~APMG_PS_PWR_SRC_MSK); if (alloc_rings() < 0) { iwl_log("out of memory for rings"); return -1; } S->fatal = 0; S->waiting = 0; /* iwl_op_mode_nic_config(): radio SKU bits (DVM) before the rings. */ if (S->nic_config) S->nic_config(); rx_init(); tx_init(); if (S->fam->shadow_reg) iwl_wr(CSR_MAC_SHADOW_REG_CTRL, iwl_rd(CSR_MAC_SHADOW_REG_CTRL) | 0x800fffffu); iwl_wr(CSR_UCODE_DRV_GP1_CLR, UCODE_SW_BIT_RFKILL); if (load_sections(img) < 0) { iwl_log("firmware section load failed"); return -1; } iwl_wr(CSR_INT, 0xffffffffu); iwl_wr(CSR_RESET, 0); /* release the CPU */ return 0; } /* After ALIVE: scheduler context, byte-count tables, cmd queue on FIFO 7, * TX DMA channels (iwl_pcie_tx_start()). */ /* iwl_trans_pcie_txq_enable() with a cfg (the transport programs the * scheduler: FIFO, window, frame limit), as iwl_trans_ac_txq_enable() * does for the command queue and for DVM's AC queues. */ static void scd_enable_queue(unsigned int qn, unsigned int fifo) { struct txq *q = &S->q[qn]; int cmdq = qn == S->fam->cmd_q; if (cmdq && S->fam->scd_set_active) iwl_wr_prph(SCD_EN_CTRL, 0); iwl_wr_prph(scd_queue_status(qn), 1u << SCD_STTS_ACT_EN); if (!cmdq) prph_set(SCD_QUEUECHAIN_SEL, 1u << qn); prph_clr(SCD_AGGR_SEL, 1u << qn); q->wptr = q->rptr = 0; iwl_wr(HBUS_TARG_WRPTR, 0 | (qn << 8)); iwl_wr_prph(scd_queue_rdptr(qn), 0); mem_wr32(S->scd_base + SCD_CONTEXT_MEM + qn * 8, 0); mem_wr32(S->scd_base + SCD_CONTEXT_MEM + qn * 8 + 4, (64u & 0x7f) | ((64u << 16) & 0x7f0000u)); iwl_wr_prph(scd_queue_status(qn), (1u << SCD_STTS_ACTIVE) | (fifo << SCD_STTS_TXF) | (1u << SCD_STTS_WSL) | SCD_STTS_MSK); if (cmdq && S->fam->scd_set_active) iwl_wr_prph(SCD_EN_CTRL, 1u << qn); q->active = 1; } void iwl_txq_enable_fifo(int qn, unsigned int fifo) { if (S && qn >= 0 && qn < IWL_NUM_Q && S->q[qn].tfds) scd_enable_queue((unsigned int)qn, fifo); } void iwl_fw_alive(unsigned int scd_base) { unsigned int c; S->scd_base = iwl_rd_prph(SCD_SRAM_BASE_ADDR); if (scd_base && scd_base != S->scd_base) iwl_loghex("scd base mismatch, alive says", scd_base); mem_zero(S->scd_base + SCD_CONTEXT_MEM, (((SCD_TRANS_TBL_MEM + S->fam->nq * 2) & 0xfffcu) - SCD_CONTEXT_MEM) / 4); iwl_wr_prph(SCD_DRAM_BASE_ADDR, (unsigned int)S->bc >> 10); /* The SCD chain extension misbehaves on the 6000 family. */ if (S->fam->chain_ext_wa) iwl_wr_prph(SCD_CHAINEXT_EN, 0); scd_enable_queue(S->fam->cmd_q, S->fam->cmd_fifo); iwl_wr_prph(SCD_TXFACT, 0xffu); /* FIFOs 0..7 */ for (c = 0; c < 8; c++) iwl_wr(FH_TCSR_CONFIG(c), FH_TCSR_DMA_ENABLE | FH_TCSR_CREDIT_ENABLE); iwl_wr(FH_TX_CHICKEN_BITS, iwl_rd(FH_TX_CHICKEN_BITS) | 0x2u); prph_clr(APMG_PCIDEV_STT_REG, APMG_PCIDEV_L1_ACT_DIS); } /* DQA data/mgmt queue (iwl_trans_pcie_txq_enable() with cfg == NULL: the * firmware's SCD_QUEUE_CFG command configures the scheduler itself). */ void iwl_txq_enable(int qn, unsigned short ssn) { struct txq *q = &S->q[qn]; /* SCD write-pointer quirk: never move by a multiple of 0x40. */ if (!((ssn - q->wptr) & 0x3f) && ssn != q->wptr) ssn++; q->rptr = q->wptr = ssn & 0xff; iwl_wr(HBUS_TARG_WRPTR, (ssn & 0xff) | ((unsigned int)qn << 8)); q->active = 1; } unsigned int iwl_txq_wptr(int q) { return S->q[q].wptr; } /* ---- TX ---------------------------------------------------------------- */ static void tfd_set(unsigned char *tfd, unsigned int tb, unsigned int addr, unsigned int len) { unsigned char *e = tfd + 4 + tb * 6; e[0] = addr; e[1] = addr >> 8; e[2] = addr >> 16; e[3] = addr >> 24; e[4] = (len << 4) & 0xf0; e[5] = len >> 4; tfd[3] = (unsigned char)(tb + 1); } static void bc_set(int qn, unsigned int idx, unsigned int bytes, unsigned int sta) { unsigned short *t = S->bc + qn * BC_ENTRIES; unsigned short v; /* + CRC + delimiter; in dwords with bc_table_dword (7000), else * bytes (iwl_txq_gen1_update_byte_cnt_tbl()). */ bytes += 8; if (S->fam->bc_dword) bytes = (bytes + 3) / 4; v = (unsigned short)(bytes | (sta << 12)); t[idx] = v; if (idx < BC_ENTRIES - TFD_RING) t[TFD_RING + idx] = v; } static int txq_space(struct txq *q) { return ((q->wptr - q->rptr) & 0xff) < q->nslots - 1; } static unsigned char *slot_buf(struct txq *q, unsigned int idx) { return q->bufs + (idx & (q->nslots - 1)) * q->bufsize; } static void ring_doorbell(int qn) { struct txq *q = &S->q[qn]; q->wptr = (q->wptr + 1) & 0xff; iwl_wr(HBUS_TARG_WRPTR, q->wptr | ((unsigned int)qn << 8)); } static int enqueue_cmd(unsigned int id, const void *data, unsigned int len, unsigned short *seq_out) { unsigned int cq = S->fam->cmd_q; struct txq *q = &S->q[cq]; /* mvm sets wide_cmd_header: legacy (group 0) commands are sent as * group 1 with the 8-byte header (iwl_trans_send_cmd(), DEF_ID). * DVM uses the plain 4-byte iwl_cmd_header. */ unsigned char group = (id >> 8) & 0xff ? (id >> 8) & 0xff : 1; unsigned char *buf, *tfd; unsigned int hdr = S->fam->wide_hdr ? 8 : 4, total = hdr + len, idx; unsigned short seq; if (!q->active || total > CMD_BUF) return -1; if (!txq_space(q)) { /* Command responses reclaim; every one we sent was synchronous, * so the ring can simply be considered drained. */ q->rptr = q->wptr; } idx = q->wptr; buf = slot_buf(q, idx); seq = (unsigned short)((cq << 8) | idx); buf[0] = id & 0xff; buf[1] = S->fam->wide_hdr ? group : 0; buf[2] = seq & 0xff; buf[3] = seq >> 8; if (S->fam->wide_hdr) { buf[4] = len & 0xff; buf[5] = len >> 8; buf[6] = 0; buf[7] = (id >> 16) & 0xff; } iwl_memcpy(buf + hdr, data, len); tfd = q->tfds + idx * TFD_SIZE; iwl_memzero(tfd, TFD_SIZE); if (total <= FIRST_TB) { tfd_set(tfd, 0, (unsigned int)buf, total); } else { tfd_set(tfd, 0, (unsigned int)buf, FIRST_TB); tfd_set(tfd, 1, (unsigned int)buf + FIRST_TB, total - FIRST_TB); } *seq_out = seq; ring_doorbell(cq); return 0; } int iwl_tx(int qn, const void *txcmd, unsigned int txlen, const void *frame, unsigned int flen, unsigned char sta_id, unsigned int mic_len) { struct txq *q = &S->q[qn]; unsigned char *buf, *tfd; unsigned int idx, total, t; if (!q->active || 4 + txlen + flen > q->bufsize) return -1; for (t = 0; !txq_space(q); t++) { if (t > 2000 || iwl_rx_poll() < 0) return -1; iwl_udelay(50); } idx = q->wptr; buf = slot_buf(q, idx); /* struct iwl_device_tx_cmd: 4-byte header (TX_CMD, seq) + tx_cmd. */ buf[0] = 0x1c; /* TX_CMD */ buf[1] = 0; buf[2] = idx; buf[3] = (unsigned char)qn; iwl_memcpy(buf + 4, txcmd, txlen); iwl_memcpy(buf + 4 + txlen, frame, flen); /* dram_lsb_ptr/msb: where the firmware writes the tx_cmd scratch * (offset 8 of struct iwl_tx_cmd), as iwl_pcie_tx() does. */ if (txlen >= 56) { unsigned int scratch = (unsigned int)buf + 4 + 8; buf[4 + 44] = scratch; buf[4 + 45] = scratch >> 8; buf[4 + 46] = scratch >> 16; buf[4 + 47] = scratch >> 24; buf[4 + 48] = 0; } total = 4 + txlen + flen; tfd = q->tfds + idx * TFD_SIZE; iwl_memzero(tfd, TFD_SIZE); tfd_set(tfd, 0, (unsigned int)buf, FIRST_TB); tfd_set(tfd, 1, (unsigned int)buf + FIRST_TB, total - FIRST_TB); /* Byte count: the over-the-air MPDU (tx_cmd->len) plus the MIC the * firmware appends for a hardware-encrypted frame. */ bc_set(qn, idx, flen + mic_len, sta_id); ring_doorbell(qn); return 0; } void iwl_tx_reclaim(int qn, unsigned int idx) { if (qn >= 0 && qn < IWL_NUM_Q) S->q[qn].rptr = (idx + 1) & 0xff; } /* ---- RX ---------------------------------------------------------------- */ void iwl_set_rx_handler(iwl_rx_handler h) { S->handler = h; } static void handle_pkt(const struct iwl_pkt *pkt) { if (S->waiting && !(pkt->seq & 0x8000u) && pkt->seq == S->wait_seq) { unsigned int n = iwl_pkt_payload_len(pkt); if (n > S->resp_max) n = S->resp_max; if (S->resp && n) iwl_memcpy(S->resp, pkt->data, n); S->resp_len = (int)iwl_pkt_payload_len(pkt); S->resp_done = 1; return; } if (S->wait_notif && pkt->group == 0 && pkt->cmd == S->wait_notif) S->notif_seen = 1; if (S->handler) S->handler(pkt); } int iwl_rx_poll(void) { unsigned int r, n = 0, ints; if (!S || !S->rbd) return 0; ints = iwl_rd(CSR_INT); if (ints & (INT_SW_ERR | INT_HW_ERR)) { if (!S->fatal) { iwl_loghex("firmware/hardware error, CSR_INT", ints); iwl_loghex("GP_CNTRL", iwl_rd(CSR_GP_CNTRL)); } S->fatal = 1; iwl_wr(CSR_INT, ints); return -1; } if (ints) iwl_wr(CSR_INT, ints); if (iwl_rd(CSR_FH_INT_STATUS)) iwl_wr(CSR_FH_INT_STATUS, 0xffffffffu); r = S->rb_stts[0] & 0x0fff; r &= RX_RING - 1; while (S->rx_read != r) { unsigned char *page = S->rb[S->rx_read]; unsigned int off = 0; while (off + 12 < 4096) { const struct iwl_pkt *pkt = (const struct iwl_pkt *)(page + off); unsigned int len; if (pkt->len_n_flags == 0x55550000u) break; len = (pkt->len_n_flags & 0x3fffu) + 4; if (len < 8 || off + len > 4096) break; handle_pkt(pkt); off += (len + 63) & ~63u; } *(volatile unsigned int *)page = 0x55550000u; S->rx_read = (S->rx_read + 1) & (RX_RING - 1); n++; /* Give the hardware the slot 8 behind us (multiple of 8). */ if ((S->rx_read & 7) == 0) iwl_wr(FH_RSCSR_RBDCB_WPTR, (S->rx_read + RX_RING - 8) & (RX_RING - 1)); } return S->fatal ? -1 : (int)n; } int iwl_wait_notif(unsigned char cmd, unsigned int ms) { unsigned int t; S->wait_notif = cmd; S->notif_seen = 0; for (t = 0; t < ms * 10; t++) { if (iwl_rx_poll() < 0) break; if (S->notif_seen) break; iwl_udelay(100); } S->wait_notif = 0; return S->notif_seen ? 0 : -1; } int iwl_send_cmd(unsigned int id, const void *data, unsigned int len, void *resp, unsigned int resp_max) { unsigned short seq; unsigned int t; if (!S || S->fatal) return -1; S->resp = resp; S->resp_max = resp_max; S->resp_done = 0; S->resp_len = -1; if (enqueue_cmd(id, data, len, &seq) < 0) return -1; S->wait_seq = seq; S->waiting = 1; for (t = 0; t < 20000 && !S->resp_done; t++) { /* 2 s */ if (iwl_rx_poll() < 0) break; if (!S->resp_done) iwl_udelay(100); } S->waiting = 0; S->q[S->fam->cmd_q].rptr = S->q[S->fam->cmd_q].wptr; if (!S->resp_done) { iwl_loghex("command timeout, id", id); return -1; } return S->resp_len; } int iwl_send_cmd_async(unsigned int id, const void *data, unsigned int len) { unsigned short seq; if (!S || S->fatal) return -1; return enqueue_cmd(id, data, len, &seq); }