iwl_trans.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /* Intel iwlwifi PCIe transport: the 7000 family (7265D/3165, MVM firmware)
  2. * and the 6000 family (6200/6300, DVM firmware).
  3. *
  4. * Polled, single RX queue, gen1 TFD TX queues. Every ring and buffer comes
  5. * from the page allocator (nothing big in BSS: the kernel image must stay
  6. * below 0x90000). iwl_mvm.c sits on top and speaks the firmware command
  7. * protocol; wifi.c is the netdev / 802.11 layer. */
  8. #ifndef IWL_TRANS_H
  9. #define IWL_TRANS_H
  10. /* TX queues used in DQA mode (fw/api/txq.h). */
  11. #define IWL_Q_CMD 0 /* host commands, FIFO 7 */
  12. #define IWL_Q_AUX 1 /* aux station (scan probes) */
  13. #define IWL_Q_BSS 4 /* AP station: management + data */
  14. #define IWL_NUM_Q 31
  15. /* DVM (6000 family) queues: the four AC queues in Linux's default
  16. * iwlagn_default_queue_to_tx_fifo order, command queue on 4. */
  17. #define IWL_DVM_Q_VO 0 /* FIFO 3: management frames */
  18. #define IWL_DVM_Q_VI 1 /* FIFO 2 */
  19. #define IWL_DVM_Q_BE 2 /* FIFO 1: non-QoS data */
  20. #define IWL_DVM_Q_BK 3 /* FIFO 0 */
  21. #define IWL_DVM_Q_CMD 4 /* IWL_DEFAULT_CMD_QUEUE_NUM, FIFO 7 */
  22. /* Device sub-families (iwl_subfamily()). */
  23. #define IWL_SUB_7265 1 /* 7265D / 3165: MVM firmware */
  24. #define IWL_SUB_6000I 2 /* 6200 (6000i): DVM, antennas B+C */
  25. #define IWL_SUB_6000 3 /* 6300: DVM, antennas A+B+C */
  26. /* Firmware images in the .ucode file. */
  27. #define IWL_IMG_RT 0
  28. #define IWL_IMG_INIT 1
  29. /* Received firmware packet (struct iwl_rx_packet). */
  30. struct iwl_pkt {
  31. unsigned int len_n_flags; /* bits 0..13: length incl. 4-byte hdr */
  32. unsigned char cmd;
  33. unsigned char group;
  34. unsigned short seq; /* bit 15: unsolicited (SEQ_RX_FRAME) */
  35. unsigned char data[];
  36. } __attribute__((packed));
  37. static inline unsigned int iwl_pkt_payload_len(const struct iwl_pkt *p)
  38. {
  39. unsigned int l = p->len_n_flags & 0x3FFFu;
  40. return l >= 4 ? l - 4 : 0;
  41. }
  42. /* Notification handler (set by iwl_mvm.c): called for every packet that is
  43. * not the response a synchronous command is waiting for. */
  44. typedef void (*iwl_rx_handler)(const struct iwl_pkt *pkt);
  45. struct iwl_fw_info {
  46. unsigned int api[4], capa[4];
  47. unsigned int phy_sku;
  48. unsigned int flow_trigger[2], event_trigger[2]; /* [IWL_IMG_*] */
  49. unsigned int ver; /* ucode API version from the header */
  50. char human[24];
  51. int present;
  52. };
  53. /* --- probe / lifecycle ------------------------------------------------- */
  54. int iwl_probe(void); /* PCI scan + BAR map: 0 = found */
  55. int iwl_present(void);
  56. const char *iwl_chip_name(void);
  57. unsigned int iwl_hw_rev(void);
  58. const struct iwl_fw_info *iwl_fw(void);
  59. int iwl_fw_parse(void); /* find + parse firmware in /ramfs */
  60. int iwl_start_hw(void); /* prepare, reset, APM init */
  61. int iwl_load_fw(int img); /* rings + sections + release reset */
  62. void iwl_fw_alive(unsigned int scd_base); /* SCD setup + cmd queue enable */
  63. void iwl_stop_device(void); /* stop DMA, APM stop (kexec, retry) */
  64. int iwl_is_dvm(void); /* 6000 family (DVM firmware) */
  65. int iwl_fatal(void); /* firmware crashed (SW/HW error) */
  66. unsigned int iwl_subfamily(void); /* IWL_SUB_* */
  67. /* DVM: radio SKU / config bits written during NIC init, before rings. */
  68. void iwl_set_nic_config(void (*fn)(void));
  69. /* DVM AC queue: scheduler programmed by the transport (FIFO, window). */
  70. void iwl_txq_enable_fifo(int q, unsigned int fifo);
  71. int iwl_rfkill(void); /* 1 = hardware RF-kill asserted */
  72. /* --- firmware I/O ------------------------------------------------------- */
  73. void iwl_set_rx_handler(iwl_rx_handler h);
  74. /* Poll the RX ring once; returns the number of packets handled, -1 on a
  75. * firmware error (CSR_INT SW_ERR / HW_ERR). */
  76. int iwl_rx_poll(void);
  77. /* Wait for a notification (cmd id in the legacy group) for up to `ms`.
  78. * The handler still sees it; returns 0 when it arrived. */
  79. int iwl_wait_notif(unsigned char cmd, unsigned int ms);
  80. /* Synchronous host command. `id` is (group << 8) | opcode; `resp` (may be
  81. * NULL) receives up to `resp_max` payload bytes. Returns the payload
  82. * length, or -1 on timeout/error. */
  83. int iwl_send_cmd(unsigned int id, const void *data, unsigned int len,
  84. void *resp, unsigned int resp_max);
  85. /* Fire-and-forget command (no response expected or awaited). */
  86. int iwl_send_cmd_async(unsigned int id, const void *data, unsigned int len);
  87. /* TX_CMD on a data/management queue: `txcmd` is the struct iwl_tx_cmd
  88. * (header copied in, 802.11 header + payload follow in `frame`). */
  89. int iwl_tx(int q, const void *txcmd, unsigned int txlen,
  90. const void *frame, unsigned int flen, unsigned char sta_id,
  91. unsigned int mic_len);
  92. /* TX response for queue q, slot idx: release the entries up to idx. */
  93. void iwl_tx_reclaim(int q, unsigned int idx);
  94. /* Activate a data/mgmt queue (trans side of SCD_QUEUE_CFG, DQA mode). */
  95. void iwl_txq_enable(int q, unsigned short ssn);
  96. unsigned int iwl_txq_wptr(int q);
  97. /* Firmware section data (for the NVM/PHY-DB helpers): returns the image. */
  98. const unsigned char *iwl_fw_data(unsigned int *size);
  99. /* Byte helpers (`rep movsb/stosb`; the kernel has no libc). */
  100. void iwl_memcpy(void *dst, const void *src, unsigned int n);
  101. void iwl_memzero(void *dst, unsigned int n);
  102. unsigned int iwl_mem_rd32(unsigned int addr); /* device SRAM */
  103. /* Register helpers (also used by the mvm layer for diagnostics). */
  104. unsigned int iwl_rd(unsigned int reg);
  105. void iwl_wr(unsigned int reg, unsigned int val);
  106. unsigned int iwl_rd_prph(unsigned int addr);
  107. void iwl_wr_prph(unsigned int addr, unsigned int val);
  108. void iwl_udelay(unsigned int us);
  109. void iwl_log(const char *s);
  110. void iwl_loghex(const char *s, unsigned int v);
  111. #endif