iwl_trans.h 5.7 KB

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