wcn36xx.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. /*
  2. * Copyright (c) 2013 Eugene Krasnikov <[email protected]>
  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/in6.h>
  20. #include <linux/printk.h>
  21. #include <linux/spinlock.h>
  22. #include <net/mac80211.h>
  23. #include "hal.h"
  24. #include "smd.h"
  25. #include "txrx.h"
  26. #include "dxe.h"
  27. #include "pmc.h"
  28. #include "debug.h"
  29. #define WLAN_NV_FILE "wlan/prima/WCNSS_qcom_wlan_nv.bin"
  30. #define WCN36XX_AGGR_BUFFER_SIZE 64
  31. extern unsigned int wcn36xx_dbg_mask;
  32. enum wcn36xx_debug_mask {
  33. WCN36XX_DBG_DXE = 0x00000001,
  34. WCN36XX_DBG_DXE_DUMP = 0x00000002,
  35. WCN36XX_DBG_SMD = 0x00000004,
  36. WCN36XX_DBG_SMD_DUMP = 0x00000008,
  37. WCN36XX_DBG_RX = 0x00000010,
  38. WCN36XX_DBG_RX_DUMP = 0x00000020,
  39. WCN36XX_DBG_TX = 0x00000040,
  40. WCN36XX_DBG_TX_DUMP = 0x00000080,
  41. WCN36XX_DBG_HAL = 0x00000100,
  42. WCN36XX_DBG_HAL_DUMP = 0x00000200,
  43. WCN36XX_DBG_MAC = 0x00000400,
  44. WCN36XX_DBG_BEACON = 0x00000800,
  45. WCN36XX_DBG_BEACON_DUMP = 0x00001000,
  46. WCN36XX_DBG_PMC = 0x00002000,
  47. WCN36XX_DBG_PMC_DUMP = 0x00004000,
  48. WCN36XX_DBG_TESTMODE = 0x00008000,
  49. WCN36XX_DBG_TESTMODE_DUMP = 0x00010000,
  50. WCN36XX_DBG_ANY = 0xffffffff,
  51. };
  52. #define wcn36xx_err(fmt, arg...) \
  53. printk(KERN_ERR pr_fmt("ERROR " fmt), ##arg)
  54. #define wcn36xx_warn(fmt, arg...) \
  55. printk(KERN_WARNING pr_fmt("WARNING " fmt), ##arg)
  56. #define wcn36xx_info(fmt, arg...) \
  57. printk(KERN_INFO pr_fmt(fmt), ##arg)
  58. #define wcn36xx_dbg(mask, fmt, arg...) do { \
  59. if (wcn36xx_dbg_mask & mask) \
  60. printk(KERN_DEBUG pr_fmt(fmt), ##arg); \
  61. } while (0)
  62. #define wcn36xx_dbg_dump(mask, prefix_str, buf, len) do { \
  63. if (wcn36xx_dbg_mask & mask) \
  64. print_hex_dump(KERN_DEBUG, pr_fmt(prefix_str), \
  65. DUMP_PREFIX_OFFSET, 32, 1, \
  66. buf, len, false); \
  67. } while (0)
  68. enum wcn36xx_ampdu_state {
  69. WCN36XX_AMPDU_NONE,
  70. WCN36XX_AMPDU_INIT,
  71. WCN36XX_AMPDU_START,
  72. WCN36XX_AMPDU_OPERATIONAL,
  73. };
  74. #define HW_VALUE_PHY_SHIFT 8
  75. #define HW_VALUE_PHY(hw_value) ((hw_value) >> HW_VALUE_PHY_SHIFT)
  76. #define HW_VALUE_CHANNEL(hw_value) ((hw_value) & 0xFF)
  77. #define WCN36XX_HW_CHANNEL(__wcn)\
  78. HW_VALUE_CHANNEL(__wcn->hw->conf.chandef.chan->hw_value)
  79. #define WCN36XX_BAND(__wcn) (__wcn->hw->conf.chandef.chan->band)
  80. #define WCN36XX_CENTER_FREQ(__wcn) (__wcn->hw->conf.chandef.chan->center_freq)
  81. #define WCN36XX_LISTEN_INTERVAL(__wcn) (__wcn->hw->conf.listen_interval)
  82. #define WCN36XX_FLAGS(__wcn) (__wcn->hw->flags)
  83. #define WCN36XX_MAX_POWER(__wcn) (__wcn->hw->conf.chandef.chan->max_power)
  84. #define RF_UNKNOWN 0x0000
  85. #define RF_IRIS_WCN3620 0x3620
  86. #define RF_IRIS_WCN3660 0x3660
  87. #define RF_IRIS_WCN3680 0x3680
  88. static inline void buff_to_be(u32 *buf, size_t len)
  89. {
  90. int i;
  91. for (i = 0; i < len; i++)
  92. buf[i] = cpu_to_be32(buf[i]);
  93. }
  94. struct nv_data {
  95. int is_valid;
  96. u8 table;
  97. };
  98. /**
  99. * struct wcn36xx_vif - holds VIF related fields
  100. *
  101. * @bss_index: bss_index is initially set to 0xFF. bss_index is received from
  102. * HW after first config_bss call and must be used in delete_bss and
  103. * enter/exit_bmps.
  104. */
  105. struct wcn36xx_vif {
  106. struct list_head list;
  107. u8 dtim_period;
  108. enum ani_ed_type encrypt_type;
  109. bool is_joining;
  110. bool sta_assoc;
  111. struct wcn36xx_hal_mac_ssid ssid;
  112. enum wcn36xx_hal_bss_type bss_type;
  113. /* Power management */
  114. enum wcn36xx_power_state pw_state;
  115. u8 bss_index;
  116. /* Returned from WCN36XX_HAL_ADD_STA_SELF_RSP */
  117. u8 self_sta_index;
  118. u8 self_dpu_desc_index;
  119. u8 self_ucast_dpu_sign;
  120. #if IS_ENABLED(CONFIG_IPV6)
  121. /* IPv6 addresses for WoWLAN */
  122. struct in6_addr target_ipv6_addrs[WCN36XX_HAL_IPV6_OFFLOAD_ADDR_MAX];
  123. unsigned long tentative_addrs[BITS_TO_LONGS(WCN36XX_HAL_IPV6_OFFLOAD_ADDR_MAX)];
  124. int num_target_ipv6_addrs;
  125. #endif
  126. /* WoWLAN GTK rekey data */
  127. struct {
  128. u8 kck[NL80211_KCK_LEN], kek[NL80211_KEK_LEN];
  129. __le64 replay_ctr;
  130. bool valid;
  131. } rekey_data;
  132. struct list_head sta_list;
  133. int bmps_fail_ct;
  134. };
  135. /**
  136. * struct wcn36xx_sta - holds STA related fields
  137. *
  138. * @tid: traffic ID that is used during AMPDU and in TX BD.
  139. * @sta_index: STA index is returned from HW after config_sta call and is
  140. * used in both SMD channel and TX BD.
  141. * @dpu_desc_index: DPU descriptor index is returned from HW after config_sta
  142. * call and is used in TX BD.
  143. * @bss_sta_index: STA index is returned from HW after config_bss call and is
  144. * used in both SMD channel and TX BD. See table bellow when it is used.
  145. * @bss_dpu_desc_index: DPU descriptor index is returned from HW after
  146. * config_bss call and is used in TX BD.
  147. * ______________________________________________
  148. * | | STA | AP |
  149. * |______________|_____________|_______________|
  150. * | TX BD |bss_sta_index| sta_index |
  151. * |______________|_____________|_______________|
  152. * |all SMD calls |bss_sta_index| sta_index |
  153. * |______________|_____________|_______________|
  154. * |smd_delete_sta| sta_index | sta_index |
  155. * |______________|_____________|_______________|
  156. */
  157. struct wcn36xx_sta {
  158. struct list_head list;
  159. struct wcn36xx_vif *vif;
  160. u16 aid;
  161. u16 tid;
  162. u8 sta_index;
  163. u8 dpu_desc_index;
  164. u8 ucast_dpu_sign;
  165. u8 bss_sta_index;
  166. u8 bss_dpu_desc_index;
  167. bool is_data_encrypted;
  168. /* Rates */
  169. struct wcn36xx_hal_supported_rates_v1 supported_rates;
  170. spinlock_t ampdu_lock; /* protects next two fields */
  171. enum wcn36xx_ampdu_state ampdu_state[16];
  172. int non_agg_frame_ct;
  173. };
  174. struct wcn36xx_dxe_ch;
  175. struct wcn36xx_chan_survey {
  176. s8 rssi;
  177. u8 snr;
  178. };
  179. struct wcn36xx {
  180. struct ieee80211_hw *hw;
  181. struct device *dev;
  182. struct list_head vif_list;
  183. const char *nv_file;
  184. const struct firmware *nv;
  185. u8 fw_revision;
  186. u8 fw_version;
  187. u8 fw_minor;
  188. u8 fw_major;
  189. u32 fw_feat_caps[WCN36XX_HAL_CAPS_SIZE];
  190. bool is_pronto;
  191. /* extra byte for the NULL termination */
  192. u8 crm_version[WCN36XX_HAL_VERSION_LENGTH + 1];
  193. u8 wlan_version[WCN36XX_HAL_VERSION_LENGTH + 1];
  194. bool first_boot;
  195. /* IRQs */
  196. int tx_irq;
  197. int rx_irq;
  198. void __iomem *ccu_base;
  199. void __iomem *dxe_base;
  200. struct rpmsg_endpoint *smd_channel;
  201. struct qcom_smem_state *tx_enable_state;
  202. unsigned tx_enable_state_bit;
  203. struct qcom_smem_state *tx_rings_empty_state;
  204. unsigned tx_rings_empty_state_bit;
  205. /* prevents concurrent FW reconfiguration */
  206. struct mutex conf_mutex;
  207. /*
  208. * smd_buf must be protected with smd_mutex to garantee
  209. * that all messages are sent one after another
  210. */
  211. u8 *hal_buf;
  212. size_t hal_rsp_len;
  213. struct mutex hal_mutex;
  214. struct completion hal_rsp_compl;
  215. struct workqueue_struct *hal_ind_wq;
  216. struct work_struct hal_ind_work;
  217. spinlock_t hal_ind_lock;
  218. struct list_head hal_ind_queue;
  219. struct cfg80211_scan_request *scan_req;
  220. bool sw_scan;
  221. u8 sw_scan_opchannel;
  222. bool sw_scan_init;
  223. u8 sw_scan_channel;
  224. struct ieee80211_vif *sw_scan_vif;
  225. struct mutex scan_lock;
  226. bool scan_aborted;
  227. /* DXE channels */
  228. struct wcn36xx_dxe_ch dxe_tx_l_ch; /* TX low */
  229. struct wcn36xx_dxe_ch dxe_tx_h_ch; /* TX high */
  230. struct wcn36xx_dxe_ch dxe_rx_l_ch; /* RX low */
  231. struct wcn36xx_dxe_ch dxe_rx_h_ch; /* RX high */
  232. /* For synchronization of DXE resources from BH, IRQ and WQ contexts */
  233. spinlock_t dxe_lock;
  234. bool queues_stopped;
  235. /* Memory pools */
  236. struct wcn36xx_dxe_mem_pool mgmt_mem_pool;
  237. struct wcn36xx_dxe_mem_pool data_mem_pool;
  238. struct sk_buff *tx_ack_skb;
  239. struct timer_list tx_ack_timer;
  240. /* For A-MSDU re-aggregation */
  241. struct sk_buff_head amsdu;
  242. /* RF module */
  243. unsigned rf_id;
  244. #ifdef CONFIG_WCN36XX_DEBUGFS
  245. /* Debug file system entry */
  246. struct wcn36xx_dfs_entry dfs;
  247. #endif /* CONFIG_WCN36XX_DEBUGFS */
  248. struct ieee80211_supported_band *band;
  249. struct ieee80211_channel *channel;
  250. spinlock_t survey_lock; /* protects chan_survey */
  251. struct wcn36xx_chan_survey *chan_survey;
  252. };
  253. static inline bool wcn36xx_is_fw_version(struct wcn36xx *wcn,
  254. u8 major,
  255. u8 minor,
  256. u8 version,
  257. u8 revision)
  258. {
  259. return (wcn->fw_major == major &&
  260. wcn->fw_minor == minor &&
  261. wcn->fw_version == version &&
  262. wcn->fw_revision == revision);
  263. }
  264. void wcn36xx_set_default_rates(struct wcn36xx_hal_supported_rates *rates);
  265. void wcn36xx_set_default_rates_v1(struct wcn36xx_hal_supported_rates_v1 *rates);
  266. static inline
  267. struct ieee80211_sta *wcn36xx_priv_to_sta(struct wcn36xx_sta *sta_priv)
  268. {
  269. return container_of((void *)sta_priv, struct ieee80211_sta, drv_priv);
  270. }
  271. static inline
  272. struct wcn36xx_vif *wcn36xx_vif_to_priv(struct ieee80211_vif *vif)
  273. {
  274. return (struct wcn36xx_vif *) vif->drv_priv;
  275. }
  276. static inline
  277. struct ieee80211_vif *wcn36xx_priv_to_vif(struct wcn36xx_vif *vif_priv)
  278. {
  279. return container_of((void *) vif_priv, struct ieee80211_vif, drv_priv);
  280. }
  281. static inline
  282. struct wcn36xx_sta *wcn36xx_sta_to_priv(struct ieee80211_sta *sta)
  283. {
  284. return (struct wcn36xx_sta *)sta->drv_priv;
  285. }
  286. #endif /* _WCN36XX_H_ */