wcn36xx.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. /*
  2. * Copyright (c) 2013 Eugene Krasnikov <k.eugene.e@gmail.com>
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
  11. * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  13. * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  14. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #ifndef _WCN36XX_H_
  17. #define _WCN36XX_H_
  18. #include <linux/completion.h>
  19. #include <linux/printk.h>
  20. #include <linux/spinlock.h>
  21. #include <net/mac80211.h>
  22. #include "hal.h"
  23. #include "smd.h"
  24. #include "txrx.h"
  25. #include "dxe.h"
  26. #include "pmc.h"
  27. #include "debug.h"
  28. #define WLAN_NV_FILE "wlan/prima/WCNSS_qcom_wlan_nv.bin"
  29. #define WCN36XX_AGGR_BUFFER_SIZE 64
  30. /* How many frames until we start a-mpdu TX session */
  31. #define WCN36XX_AMPDU_START_THRESH 20
  32. #define WCN36XX_MAX_SCAN_SSIDS 9
  33. #define WCN36XX_MAX_SCAN_IE_LEN 500
  34. extern unsigned int wcn36xx_dbg_mask;
  35. enum wcn36xx_debug_mask {
  36. WCN36XX_DBG_DXE = 0x00000001,
  37. WCN36XX_DBG_DXE_DUMP = 0x00000002,
  38. WCN36XX_DBG_SMD = 0x00000004,
  39. WCN36XX_DBG_SMD_DUMP = 0x00000008,
  40. WCN36XX_DBG_RX = 0x00000010,
  41. WCN36XX_DBG_RX_DUMP = 0x00000020,
  42. WCN36XX_DBG_TX = 0x00000040,
  43. WCN36XX_DBG_TX_DUMP = 0x00000080,
  44. WCN36XX_DBG_HAL = 0x00000100,
  45. WCN36XX_DBG_HAL_DUMP = 0x00000200,
  46. WCN36XX_DBG_MAC = 0x00000400,
  47. WCN36XX_DBG_BEACON = 0x00000800,
  48. WCN36XX_DBG_BEACON_DUMP = 0x00001000,
  49. WCN36XX_DBG_PMC = 0x00002000,
  50. WCN36XX_DBG_PMC_DUMP = 0x00004000,
  51. WCN36XX_DBG_ANY = 0xffffffff,
  52. };
  53. #define wcn36xx_err(fmt, arg...) \
  54. printk(KERN_ERR pr_fmt("ERROR " fmt), ##arg)
  55. #define wcn36xx_warn(fmt, arg...) \
  56. printk(KERN_WARNING pr_fmt("WARNING " fmt), ##arg)
  57. #define wcn36xx_info(fmt, arg...) \
  58. printk(KERN_INFO pr_fmt(fmt), ##arg)
  59. #define wcn36xx_dbg(mask, fmt, arg...) do { \
  60. if (wcn36xx_dbg_mask & mask) \
  61. printk(KERN_DEBUG pr_fmt(fmt), ##arg); \
  62. } while (0)
  63. #define wcn36xx_dbg_dump(mask, prefix_str, buf, len) do { \
  64. if (wcn36xx_dbg_mask & mask) \
  65. print_hex_dump(KERN_DEBUG, pr_fmt(prefix_str), \
  66. DUMP_PREFIX_OFFSET, 32, 1, \
  67. buf, len, false); \
  68. } while (0)
  69. enum wcn36xx_ampdu_state {
  70. WCN36XX_AMPDU_NONE,
  71. WCN36XX_AMPDU_INIT,
  72. WCN36XX_AMPDU_START,
  73. WCN36XX_AMPDU_OPERATIONAL,
  74. };
  75. #define WCN36XX_HW_CHANNEL(__wcn) (__wcn->hw->conf.chandef.chan->hw_value)
  76. #define WCN36XX_BAND(__wcn) (__wcn->hw->conf.chandef.chan->band)
  77. #define WCN36XX_CENTER_FREQ(__wcn) (__wcn->hw->conf.chandef.chan->center_freq)
  78. #define WCN36XX_LISTEN_INTERVAL(__wcn) (__wcn->hw->conf.listen_interval)
  79. #define WCN36XX_FLAGS(__wcn) (__wcn->hw->flags)
  80. #define WCN36XX_MAX_POWER(__wcn) (__wcn->hw->conf.chandef.chan->max_power)
  81. static inline void buff_to_be(u32 *buf, size_t len)
  82. {
  83. int i;
  84. for (i = 0; i < len; i++)
  85. buf[i] = cpu_to_be32(buf[i]);
  86. }
  87. struct nv_data {
  88. int is_valid;
  89. u8 table;
  90. };
  91. /**
  92. * struct wcn36xx_vif - holds VIF related fields
  93. *
  94. * @bss_index: bss_index is initially set to 0xFF. bss_index is received from
  95. * HW after first config_bss call and must be used in delete_bss and
  96. * enter/exit_bmps.
  97. */
  98. struct wcn36xx_vif {
  99. struct list_head list;
  100. u8 dtim_period;
  101. enum ani_ed_type encrypt_type;
  102. bool is_joining;
  103. bool sta_assoc;
  104. struct wcn36xx_hal_mac_ssid ssid;
  105. /* Power management */
  106. enum wcn36xx_power_state pw_state;
  107. u8 bss_index;
  108. /* Returned from WCN36XX_HAL_ADD_STA_SELF_RSP */
  109. u8 self_sta_index;
  110. u8 self_dpu_desc_index;
  111. u8 self_ucast_dpu_sign;
  112. };
  113. /**
  114. * struct wcn36xx_sta - holds STA related fields
  115. *
  116. * @tid: traffic ID that is used during AMPDU and in TX BD.
  117. * @sta_index: STA index is returned from HW after config_sta call and is
  118. * used in both SMD channel and TX BD.
  119. * @dpu_desc_index: DPU descriptor index is returned from HW after config_sta
  120. * call and is used in TX BD.
  121. * @bss_sta_index: STA index is returned from HW after config_bss call and is
  122. * used in both SMD channel and TX BD. See table bellow when it is used.
  123. * @bss_dpu_desc_index: DPU descriptor index is returned from HW after
  124. * config_bss call and is used in TX BD.
  125. * ______________________________________________
  126. * | | STA | AP |
  127. * |______________|_____________|_______________|
  128. * | TX BD |bss_sta_index| sta_index |
  129. * |______________|_____________|_______________|
  130. * |all SMD calls |bss_sta_index| sta_index |
  131. * |______________|_____________|_______________|
  132. * |smd_delete_sta| sta_index | sta_index |
  133. * |______________|_____________|_______________|
  134. */
  135. struct wcn36xx_sta {
  136. struct wcn36xx_vif *vif;
  137. u16 aid;
  138. u16 tid;
  139. u8 sta_index;
  140. u8 dpu_desc_index;
  141. u8 ucast_dpu_sign;
  142. u8 bss_sta_index;
  143. u8 bss_dpu_desc_index;
  144. bool is_data_encrypted;
  145. /* Rates */
  146. struct wcn36xx_hal_supported_rates supported_rates;
  147. spinlock_t ampdu_lock; /* protects next two fields */
  148. enum wcn36xx_ampdu_state ampdu_state[16];
  149. int non_agg_frame_ct;
  150. };
  151. struct wcn36xx_dxe_ch;
  152. struct wcn36xx {
  153. struct ieee80211_hw *hw;
  154. struct device *dev;
  155. struct list_head vif_list;
  156. const struct firmware *nv;
  157. u8 fw_revision;
  158. u8 fw_version;
  159. u8 fw_minor;
  160. u8 fw_major;
  161. u32 fw_feat_caps[WCN36XX_HAL_CAPS_SIZE];
  162. bool is_pronto;
  163. /* extra byte for the NULL termination */
  164. u8 crm_version[WCN36XX_HAL_VERSION_LENGTH + 1];
  165. u8 wlan_version[WCN36XX_HAL_VERSION_LENGTH + 1];
  166. /* IRQs */
  167. int tx_irq;
  168. int rx_irq;
  169. void __iomem *ccu_base;
  170. void __iomem *dxe_base;
  171. struct qcom_smd_channel *smd_channel;
  172. struct qcom_smem_state *tx_enable_state;
  173. unsigned tx_enable_state_bit;
  174. struct qcom_smem_state *tx_rings_empty_state;
  175. unsigned tx_rings_empty_state_bit;
  176. /*
  177. * smd_buf must be protected with smd_mutex to garantee
  178. * that all messages are sent one after another
  179. */
  180. u8 *hal_buf;
  181. size_t hal_rsp_len;
  182. struct mutex hal_mutex;
  183. struct completion hal_rsp_compl;
  184. struct workqueue_struct *hal_ind_wq;
  185. struct work_struct hal_ind_work;
  186. spinlock_t hal_ind_lock;
  187. struct list_head hal_ind_queue;
  188. struct work_struct scan_work;
  189. struct cfg80211_scan_request *scan_req;
  190. int scan_freq;
  191. int scan_band;
  192. struct mutex scan_lock;
  193. bool scan_aborted;
  194. /* DXE channels */
  195. struct wcn36xx_dxe_ch dxe_tx_l_ch; /* TX low */
  196. struct wcn36xx_dxe_ch dxe_tx_h_ch; /* TX high */
  197. struct wcn36xx_dxe_ch dxe_rx_l_ch; /* RX low */
  198. struct wcn36xx_dxe_ch dxe_rx_h_ch; /* RX high */
  199. /* For synchronization of DXE resources from BH, IRQ and WQ contexts */
  200. spinlock_t dxe_lock;
  201. bool queues_stopped;
  202. /* Memory pools */
  203. struct wcn36xx_dxe_mem_pool mgmt_mem_pool;
  204. struct wcn36xx_dxe_mem_pool data_mem_pool;
  205. struct sk_buff *tx_ack_skb;
  206. #ifdef CONFIG_WCN36XX_DEBUGFS
  207. /* Debug file system entry */
  208. struct wcn36xx_dfs_entry dfs;
  209. #endif /* CONFIG_WCN36XX_DEBUGFS */
  210. };
  211. static inline bool wcn36xx_is_fw_version(struct wcn36xx *wcn,
  212. u8 major,
  213. u8 minor,
  214. u8 version,
  215. u8 revision)
  216. {
  217. return (wcn->fw_major == major &&
  218. wcn->fw_minor == minor &&
  219. wcn->fw_version == version &&
  220. wcn->fw_revision == revision);
  221. }
  222. void wcn36xx_set_default_rates(struct wcn36xx_hal_supported_rates *rates);
  223. static inline
  224. struct ieee80211_sta *wcn36xx_priv_to_sta(struct wcn36xx_sta *sta_priv)
  225. {
  226. return container_of((void *)sta_priv, struct ieee80211_sta, drv_priv);
  227. }
  228. static inline
  229. struct wcn36xx_vif *wcn36xx_vif_to_priv(struct ieee80211_vif *vif)
  230. {
  231. return (struct wcn36xx_vif *) vif->drv_priv;
  232. }
  233. static inline
  234. struct ieee80211_vif *wcn36xx_priv_to_vif(struct wcn36xx_vif *vif_priv)
  235. {
  236. return container_of((void *) vif_priv, struct ieee80211_vif, drv_priv);
  237. }
  238. static inline
  239. struct wcn36xx_sta *wcn36xx_sta_to_priv(struct ieee80211_sta *sta)
  240. {
  241. return (struct wcn36xx_sta *)sta->drv_priv;
  242. }
  243. #endif /* _WCN36XX_H_ */