| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170 |
- /* 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"
- #define FW_PATH "firmware/iwlwifi-7265D-29.ucode"
- /* ---- 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_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;
- };
- 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)
- {
- switch (devid) {
- case 0x095a: case 0x095b: return "Intel Wireless 7265";
- case 0x3165: case 0x3166: return "Intel Wireless 3165";
- }
- return 0;
- }
- 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;
- const char *name;
- if ((idf & 0xffffu) != 0x8086)
- continue;
- name = chip_for(idf >> 16);
- 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;
- 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 (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);
- }
- 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(FW_PATH, &size);
- if (!d || size < 88 || le32(d) != 0 || le32(d + 4) != 0x0a4c5749u) {
- iwl_log("firmware " FW_PATH " missing or 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). */
- 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(IWL_Q_CMD, CMD_SLOTS, CMD_BUF) < 0 ||
- alloc_txq(IWL_Q_AUX, 8, DATA_BUF) < 0 ||
- alloc_txq(IWL_Q_BSS, DATA_SLOTS, 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 | SCD_GP_31_QUEUES);
- }
- /* ---- 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_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;
- 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;
- rx_init();
- tx_init();
- 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()). */
- void iwl_fw_alive(unsigned int scd_base)
- {
- struct txq *q = &S->q[IWL_Q_CMD];
- 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 + IWL_NUM_Q * 2) & 0xfffcu) -
- SCD_CONTEXT_MEM) / 4);
- iwl_wr_prph(SCD_DRAM_BASE_ADDR, (unsigned int)S->bc >> 10);
- /* iwl_trans_ac_txq_enable(cmd queue, FIFO 7). */
- iwl_wr_prph(SCD_EN_CTRL, 0);
- iwl_wr_prph(scd_queue_status(IWL_Q_CMD), 1u << SCD_STTS_ACT_EN);
- prph_clr(SCD_AGGR_SEL, 1u << IWL_Q_CMD);
- q->wptr = q->rptr = 0;
- iwl_wr(HBUS_TARG_WRPTR, 0 | (IWL_Q_CMD << 8));
- iwl_wr_prph(scd_queue_rdptr(IWL_Q_CMD), 0);
- mem_wr32(S->scd_base + SCD_CONTEXT_MEM + IWL_Q_CMD * 8, 0);
- mem_wr32(S->scd_base + SCD_CONTEXT_MEM + IWL_Q_CMD * 8 + 4,
- (64u & 0x7f) | ((64u << 16) & 0x7f0000u));
- iwl_wr_prph(scd_queue_status(IWL_Q_CMD),
- (1u << SCD_STTS_ACTIVE) | (7u << SCD_STTS_TXF) |
- (1u << SCD_STTS_WSL) | SCD_STTS_MSK);
- iwl_wr_prph(SCD_EN_CTRL, 1u << IWL_Q_CMD);
- q->active = 1;
- 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 (bc_table_dword on 7000). */
- v = (unsigned short)((((bytes + 8) + 3) / 4) | (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)
- {
- struct txq *q = &S->q[IWL_Q_CMD];
- /* 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). */
- unsigned char group = (id >> 8) & 0xff ? (id >> 8) & 0xff : 1;
- unsigned char *buf, *tfd;
- unsigned int hdr = 8, 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)((IWL_Q_CMD << 8) | idx);
- buf[0] = id & 0xff;
- buf[1] = group;
- buf[2] = seq & 0xff;
- buf[3] = seq >> 8;
- 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(IWL_Q_CMD);
- 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[IWL_Q_CMD].rptr = S->q[IWL_Q_CMD].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);
- }
|