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