iwl_trans.h 4.5 KB

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