wil6210: RX high threshold interrupt configuration
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / ath / wil6210 / wil6210.h
1 /*
2  * Copyright (c) 2012-2014 Qualcomm Atheros, Inc.
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
11  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16
17 #ifndef __WIL6210_H__
18 #define __WIL6210_H__
19
20 #include <linux/netdevice.h>
21 #include <linux/wireless.h>
22 #include <net/cfg80211.h>
23 #include <linux/timex.h>
24 #include "wil_platform.h"
25
26 extern bool no_fw_recovery;
27 extern unsigned int mtu_max;
28 extern unsigned short rx_ring_overflow_thrsh;
29 extern int agg_wsize;
30
31 #define WIL_NAME "wil6210"
32 #define WIL_FW_NAME "wil6210.fw"
33
34 #define WIL_MAX_BUS_REQUEST_KBPS 800000 /* ~6.1Gbps */
35
36 /**
37  * extract bits [@b0:@b1] (inclusive) from the value @x
38  * it should be @b0 <= @b1, or result is incorrect
39  */
40 static inline u32 WIL_GET_BITS(u32 x, int b0, int b1)
41 {
42         return (x >> b0) & ((1 << (b1 - b0 + 1)) - 1);
43 }
44
45 #define WIL6210_MEM_SIZE (2*1024*1024UL)
46
47 #define WIL_RX_RING_SIZE_ORDER_DEFAULT  (9)
48 #define WIL_TX_RING_SIZE_ORDER_DEFAULT  (9)
49 /* limit ring size in range [32..32k] */
50 #define WIL_RING_SIZE_ORDER_MIN (5)
51 #define WIL_RING_SIZE_ORDER_MAX (15)
52 #define WIL6210_MAX_TX_RINGS    (24) /* HW limit */
53 #define WIL6210_MAX_CID         (8) /* HW limit */
54 #define WIL6210_NAPI_BUDGET     (16) /* arbitrary */
55 #define WIL_MAX_AMPDU_SIZE      (64 * 1024) /* FW/HW limit */
56 #define WIL_MAX_AGG_WSIZE       (32) /* FW/HW limit */
57 /* Hardware offload block adds the following:
58  * 26 bytes - 3-address QoS data header
59  *  8 bytes - IV + EIV (for GCMP)
60  *  8 bytes - SNAP
61  * 16 bytes - MIC (for GCMP)
62  *  4 bytes - CRC
63  */
64 #define WIL_MAX_MPDU_OVERHEAD   (62)
65
66 /* Calculate MAC buffer size for the firmware. It includes all overhead,
67  * as it will go over the air, and need to be 8 byte aligned
68  */
69 static inline u32 wil_mtu2macbuf(u32 mtu)
70 {
71         return ALIGN(mtu + WIL_MAX_MPDU_OVERHEAD, 8);
72 }
73
74 /* MTU for Ethernet need to take into account 8-byte SNAP header
75  * to be added when encapsulating Ethernet frame into 802.11
76  */
77 #define WIL_MAX_ETH_MTU         (IEEE80211_MAX_DATA_LEN_DMG - 8)
78 /* Max supported by wil6210 value for interrupt threshold is 5sec. */
79 #define WIL6210_ITR_TRSH_MAX (5000000)
80 #define WIL6210_ITR_TX_INTERFRAME_TIMEOUT_DEFAULT (15) /* usec */
81 #define WIL6210_ITR_RX_INTERFRAME_TIMEOUT_DEFAULT (15) /* usec */
82 #define WIL6210_ITR_TX_MAX_BURST_DURATION_DEFAULT (500) /* usec */
83 #define WIL6210_ITR_RX_MAX_BURST_DURATION_DEFAULT (500) /* usec */
84 #define WIL6210_FW_RECOVERY_RETRIES     (5) /* try to recover this many times */
85 #define WIL6210_FW_RECOVERY_TO  msecs_to_jiffies(5000)
86 #define WIL6210_SCAN_TO         msecs_to_jiffies(10000)
87 #define WIL6210_RX_HIGH_TRSH_INIT               (0)
88 #define WIL6210_RX_HIGH_TRSH_DEFAULT \
89                                 (1 << (WIL_RX_RING_SIZE_ORDER_DEFAULT - 3))
90 /* Hardware definitions begin */
91
92 /*
93  * Mapping
94  * RGF File      | Host addr    |  FW addr
95  *               |              |
96  * user_rgf      | 0x000000     | 0x880000
97  *  dma_rgf      | 0x001000     | 0x881000
98  * pcie_rgf      | 0x002000     | 0x882000
99  *               |              |
100  */
101
102 /* Where various structures placed in host address space */
103 #define WIL6210_FW_HOST_OFF      (0x880000UL)
104
105 #define HOSTADDR(fwaddr)        (fwaddr - WIL6210_FW_HOST_OFF)
106
107 /*
108  * Interrupt control registers block
109  *
110  * each interrupt controlled by the same bit in all registers
111  */
112 struct RGF_ICR {
113         u32 ICC; /* Cause Control, RW: 0 - W1C, 1 - COR */
114         u32 ICR; /* Cause, W1C/COR depending on ICC */
115         u32 ICM; /* Cause masked (ICR & ~IMV), W1C/COR depending on ICC */
116         u32 ICS; /* Cause Set, WO */
117         u32 IMV; /* Mask, RW+S/C */
118         u32 IMS; /* Mask Set, write 1 to set */
119         u32 IMC; /* Mask Clear, write 1 to clear */
120 } __packed;
121
122 /* registers - FW addresses */
123 #define RGF_USER_USAGE_1                (0x880004)
124 #define RGF_USER_USAGE_6                (0x880018)
125 #define RGF_USER_HW_MACHINE_STATE       (0x8801dc)
126         #define HW_MACHINE_BOOT_DONE    (0x3fffffd)
127 #define RGF_USER_USER_CPU_0             (0x8801e0)
128         #define BIT_USER_USER_CPU_MAN_RST       BIT(1) /* user_cpu_man_rst */
129 #define RGF_USER_MAC_CPU_0              (0x8801fc)
130         #define BIT_USER_MAC_CPU_MAN_RST        BIT(1) /* mac_cpu_man_rst */
131 #define RGF_USER_USER_SCRATCH_PAD       (0x8802bc)
132 #define RGF_USER_FW_REV_ID              (0x880a8c) /* chip revision */
133 #define RGF_USER_CLKS_CTL_0             (0x880abc)
134         #define BIT_USER_CLKS_CAR_AHB_SW_SEL    BIT(1) /* ref clk/PLL */
135         #define BIT_USER_CLKS_RST_PWGD  BIT(11) /* reset on "power good" */
136 #define RGF_USER_CLKS_CTL_SW_RST_VEC_0  (0x880b04)
137 #define RGF_USER_CLKS_CTL_SW_RST_VEC_1  (0x880b08)
138 #define RGF_USER_CLKS_CTL_SW_RST_VEC_2  (0x880b0c)
139 #define RGF_USER_CLKS_CTL_SW_RST_VEC_3  (0x880b10)
140 #define RGF_USER_CLKS_CTL_SW_RST_MASK_0 (0x880b14)
141         #define BIT_HPAL_PERST_FROM_PAD BIT(6)
142         #define BIT_CAR_PERST_RST       BIT(7)
143 #define RGF_USER_USER_ICR               (0x880b4c) /* struct RGF_ICR */
144         #define BIT_USER_USER_ICR_SW_INT_2      BIT(18)
145 #define RGF_USER_CLKS_CTL_EXT_SW_RST_VEC_0      (0x880c18)
146 #define RGF_USER_CLKS_CTL_EXT_SW_RST_VEC_1      (0x880c2c)
147 #define RGF_USER_SPARROW_M_4                    (0x880c50) /* Sparrow */
148         #define BIT_SPARROW_M_4_SEL_SLEEP_OR_REF        BIT(2)
149
150 #define RGF_DMA_EP_TX_ICR               (0x881bb4) /* struct RGF_ICR */
151         #define BIT_DMA_EP_TX_ICR_TX_DONE       BIT(0)
152         #define BIT_DMA_EP_TX_ICR_TX_DONE_N(n)  BIT(n+1) /* n = [0..23] */
153 #define RGF_DMA_EP_RX_ICR               (0x881bd0) /* struct RGF_ICR */
154         #define BIT_DMA_EP_RX_ICR_RX_DONE       BIT(0)
155         #define BIT_DMA_EP_RX_ICR_RX_HTRSH      BIT(1)
156 #define RGF_DMA_EP_MISC_ICR             (0x881bec) /* struct RGF_ICR */
157         #define BIT_DMA_EP_MISC_ICR_RX_HTRSH    BIT(0)
158         #define BIT_DMA_EP_MISC_ICR_TX_NO_ACT   BIT(1)
159         #define BIT_DMA_EP_MISC_ICR_FW_INT(n)   BIT(28+n) /* n = [0..3] */
160
161 /* Legacy interrupt moderation control (before Sparrow v2)*/
162 #define RGF_DMA_ITR_CNT_TRSH            (0x881c5c)
163 #define RGF_DMA_ITR_CNT_DATA            (0x881c60)
164 #define RGF_DMA_ITR_CNT_CRL             (0x881c64)
165         #define BIT_DMA_ITR_CNT_CRL_EN          BIT(0)
166         #define BIT_DMA_ITR_CNT_CRL_EXT_TICK    BIT(1)
167         #define BIT_DMA_ITR_CNT_CRL_FOREVER     BIT(2)
168         #define BIT_DMA_ITR_CNT_CRL_CLR         BIT(3)
169         #define BIT_DMA_ITR_CNT_CRL_REACH_TRSH  BIT(4)
170
171 /* New (sparrow v2+) interrupt moderation control */
172 #define RGF_DMA_ITR_TX_DESQ_NO_MOD              (0x881d40)
173 #define RGF_DMA_ITR_TX_CNT_TRSH                 (0x881d34)
174 #define RGF_DMA_ITR_TX_CNT_DATA                 (0x881d38)
175 #define RGF_DMA_ITR_TX_CNT_CTL                  (0x881d3c)
176         #define BIT_DMA_ITR_TX_CNT_CTL_EN               BIT(0)
177         #define BIT_DMA_ITR_TX_CNT_CTL_EXT_TIC_SEL      BIT(1)
178         #define BIT_DMA_ITR_TX_CNT_CTL_FOREVER          BIT(2)
179         #define BIT_DMA_ITR_TX_CNT_CTL_CLR              BIT(3)
180         #define BIT_DMA_ITR_TX_CNT_CTL_REACHED_TRESH    BIT(4)
181         #define BIT_DMA_ITR_TX_CNT_CTL_CROSS_EN         BIT(5)
182         #define BIT_DMA_ITR_TX_CNT_CTL_FREE_RUNNIG      BIT(6)
183 #define RGF_DMA_ITR_TX_IDL_CNT_TRSH                     (0x881d60)
184 #define RGF_DMA_ITR_TX_IDL_CNT_DATA                     (0x881d64)
185 #define RGF_DMA_ITR_TX_IDL_CNT_CTL                      (0x881d68)
186         #define BIT_DMA_ITR_TX_IDL_CNT_CTL_EN                   BIT(0)
187         #define BIT_DMA_ITR_TX_IDL_CNT_CTL_EXT_TIC_SEL          BIT(1)
188         #define BIT_DMA_ITR_TX_IDL_CNT_CTL_FOREVER              BIT(2)
189         #define BIT_DMA_ITR_TX_IDL_CNT_CTL_CLR                  BIT(3)
190         #define BIT_DMA_ITR_TX_IDL_CNT_CTL_REACHED_TRESH        BIT(4)
191 #define RGF_DMA_ITR_RX_DESQ_NO_MOD              (0x881d50)
192 #define RGF_DMA_ITR_RX_CNT_TRSH                 (0x881d44)
193 #define RGF_DMA_ITR_RX_CNT_DATA                 (0x881d48)
194 #define RGF_DMA_ITR_RX_CNT_CTL                  (0x881d4c)
195         #define BIT_DMA_ITR_RX_CNT_CTL_EN               BIT(0)
196         #define BIT_DMA_ITR_RX_CNT_CTL_EXT_TIC_SEL      BIT(1)
197         #define BIT_DMA_ITR_RX_CNT_CTL_FOREVER          BIT(2)
198         #define BIT_DMA_ITR_RX_CNT_CTL_CLR              BIT(3)
199         #define BIT_DMA_ITR_RX_CNT_CTL_REACHED_TRESH    BIT(4)
200         #define BIT_DMA_ITR_RX_CNT_CTL_CROSS_EN         BIT(5)
201         #define BIT_DMA_ITR_RX_CNT_CTL_FREE_RUNNIG      BIT(6)
202 #define RGF_DMA_ITR_RX_IDL_CNT_TRSH                     (0x881d54)
203 #define RGF_DMA_ITR_RX_IDL_CNT_DATA                     (0x881d58)
204 #define RGF_DMA_ITR_RX_IDL_CNT_CTL                      (0x881d5c)
205         #define BIT_DMA_ITR_RX_IDL_CNT_CTL_EN                   BIT(0)
206         #define BIT_DMA_ITR_RX_IDL_CNT_CTL_EXT_TIC_SEL          BIT(1)
207         #define BIT_DMA_ITR_RX_IDL_CNT_CTL_FOREVER              BIT(2)
208         #define BIT_DMA_ITR_RX_IDL_CNT_CTL_CLR                  BIT(3)
209         #define BIT_DMA_ITR_RX_IDL_CNT_CTL_REACHED_TRESH        BIT(4)
210
211 #define RGF_DMA_PSEUDO_CAUSE            (0x881c68)
212 #define RGF_DMA_PSEUDO_CAUSE_MASK_SW    (0x881c6c)
213 #define RGF_DMA_PSEUDO_CAUSE_MASK_FW    (0x881c70)
214         #define BIT_DMA_PSEUDO_CAUSE_RX         BIT(0)
215         #define BIT_DMA_PSEUDO_CAUSE_TX         BIT(1)
216         #define BIT_DMA_PSEUDO_CAUSE_MISC       BIT(2)
217
218 #define RGF_HP_CTRL                     (0x88265c)
219 #define RGF_PCIE_LOS_COUNTER_CTL        (0x882dc4)
220
221 /* MAC timer, usec, for packet lifetime */
222 #define RGF_MAC_MTRL_COUNTER_0          (0x886aa8)
223
224 #define RGF_CAF_ICR                     (0x88946c) /* struct RGF_ICR */
225 #define RGF_CAF_OSC_CONTROL             (0x88afa4)
226         #define BIT_CAF_OSC_XTAL_EN             BIT(0)
227 #define RGF_CAF_PLL_LOCK_STATUS         (0x88afec)
228         #define BIT_CAF_OSC_DIG_XTAL_STABLE     BIT(0)
229
230 #define RGF_USER_JTAG_DEV_ID    (0x880b34) /* device ID */
231         #define JTAG_DEV_ID_MARLON_B0   (0x0612072f)
232         #define JTAG_DEV_ID_SPARROW_A0  (0x0632072f)
233         #define JTAG_DEV_ID_SPARROW_A1  (0x1632072f)
234         #define JTAG_DEV_ID_SPARROW_B0  (0x2632072f)
235
236 enum {
237         HW_VER_UNKNOWN,
238         HW_VER_MARLON_B0,  /* JTAG_DEV_ID_MARLON_B0  */
239         HW_VER_SPARROW_A0, /* JTAG_DEV_ID_SPARROW_A0 */
240         HW_VER_SPARROW_A1, /* JTAG_DEV_ID_SPARROW_A1 */
241         HW_VER_SPARROW_B0, /* JTAG_DEV_ID_SPARROW_B0 */
242 };
243
244 /* popular locations */
245 #define HOST_MBOX   HOSTADDR(RGF_USER_USER_SCRATCH_PAD)
246 #define HOST_SW_INT (HOSTADDR(RGF_USER_USER_ICR) + \
247         offsetof(struct RGF_ICR, ICS))
248 #define SW_INT_MBOX BIT_USER_USER_ICR_SW_INT_2
249
250 /* ISR register bits */
251 #define ISR_MISC_FW_READY       BIT_DMA_EP_MISC_ICR_FW_INT(0)
252 #define ISR_MISC_MBOX_EVT       BIT_DMA_EP_MISC_ICR_FW_INT(1)
253 #define ISR_MISC_FW_ERROR       BIT_DMA_EP_MISC_ICR_FW_INT(3)
254
255 /* Hardware definitions end */
256 struct fw_map {
257         u32 from; /* linker address - from, inclusive */
258         u32 to;   /* linker address - to, exclusive */
259         u32 host; /* PCI/Host address - BAR0 + 0x880000 */
260         const char *name; /* for debugfs */
261 };
262
263 /* array size should be in sync with actual definition in the wmi.c */
264 extern const struct fw_map fw_mapping[7];
265
266 /**
267  * mk_cidxtid - construct @cidxtid field
268  * @cid: CID value
269  * @tid: TID value
270  *
271  * @cidxtid field encoded as bits 0..3 - CID; 4..7 - TID
272  */
273 static inline u8 mk_cidxtid(u8 cid, u8 tid)
274 {
275         return ((tid & 0xf) << 4) | (cid & 0xf);
276 }
277
278 /**
279  * parse_cidxtid - parse @cidxtid field
280  * @cid: store CID value here
281  * @tid: store TID value here
282  *
283  * @cidxtid field encoded as bits 0..3 - CID; 4..7 - TID
284  */
285 static inline void parse_cidxtid(u8 cidxtid, u8 *cid, u8 *tid)
286 {
287         *cid = cidxtid & 0xf;
288         *tid = (cidxtid >> 4) & 0xf;
289 }
290
291 struct wil6210_mbox_ring {
292         u32 base;
293         u16 entry_size; /* max. size of mbox entry, incl. all headers */
294         u16 size;
295         u32 tail;
296         u32 head;
297 } __packed;
298
299 struct wil6210_mbox_ring_desc {
300         __le32 sync;
301         __le32 addr;
302 } __packed;
303
304 /* at HOST_OFF_WIL6210_MBOX_CTL */
305 struct wil6210_mbox_ctl {
306         struct wil6210_mbox_ring tx;
307         struct wil6210_mbox_ring rx;
308 } __packed;
309
310 struct wil6210_mbox_hdr {
311         __le16 seq;
312         __le16 len; /* payload, bytes after this header */
313         __le16 type;
314         u8 flags;
315         u8 reserved;
316 } __packed;
317
318 #define WIL_MBOX_HDR_TYPE_WMI (0)
319
320 /* max. value for wil6210_mbox_hdr.len */
321 #define MAX_MBOXITEM_SIZE   (240)
322
323 /**
324  * struct wil6210_mbox_hdr_wmi - WMI header
325  *
326  * @mid: MAC ID
327  *      00 - default, created by FW
328  *      01..0f - WiFi ports, driver to create
329  *      10..fe - debug
330  *      ff - broadcast
331  * @id: command/event ID
332  * @timestamp: FW fills for events, free-running msec timer
333  */
334 struct wil6210_mbox_hdr_wmi {
335         u8 mid;
336         u8 reserved;
337         __le16 id;
338         __le32 timestamp;
339 } __packed;
340
341 struct pending_wmi_event {
342         struct list_head list;
343         struct {
344                 struct wil6210_mbox_hdr hdr;
345                 struct wil6210_mbox_hdr_wmi wmi;
346                 u8 data[0];
347         } __packed event;
348 };
349
350 enum { /* for wil_ctx.mapped_as */
351         wil_mapped_as_none = 0,
352         wil_mapped_as_single = 1,
353         wil_mapped_as_page = 2,
354 };
355
356 /**
357  * struct wil_ctx - software context for Vring descriptor
358  */
359 struct wil_ctx {
360         struct sk_buff *skb;
361         u8 nr_frags;
362         u8 mapped_as;
363 };
364
365 union vring_desc;
366
367 struct vring {
368         dma_addr_t pa;
369         volatile union vring_desc *va; /* vring_desc[size], WriteBack by DMA */
370         u16 size; /* number of vring_desc elements */
371         u32 swtail;
372         u32 swhead;
373         u32 hwtail; /* write here to inform hw */
374         struct wil_ctx *ctx; /* ctx[size] - software context */
375 };
376
377 /**
378  * Additional data for Tx Vring
379  */
380 struct vring_tx_data {
381         int enabled;
382         cycles_t idle, last_idle, begin;
383         u8 agg_wsize; /* agreed aggregation window, 0 - no agg */
384         u16 agg_timeout;
385         u8 agg_amsdu;
386         bool addba_in_progress; /* if set, agg_xxx is for request in progress */
387 };
388
389 enum { /* for wil6210_priv.status */
390         wil_status_fwready = 0,
391         wil_status_fwconnecting,
392         wil_status_fwconnected,
393         wil_status_dontscan,
394         wil_status_reset_done,
395         wil_status_irqen, /* FIXME: interrupts enabled - for debug */
396         wil_status_napi_en, /* NAPI enabled protected by wil->mutex */
397         wil_status_last /* keep last */
398 };
399
400 struct pci_dev;
401
402 /**
403  * struct tid_ampdu_rx - TID aggregation information (Rx).
404  *
405  * @reorder_buf: buffer to reorder incoming aggregated MPDUs
406  * @reorder_time: jiffies when skb was added
407  * @session_timer: check if peer keeps Tx-ing on the TID (by timeout value)
408  * @reorder_timer: releases expired frames from the reorder buffer.
409  * @last_rx: jiffies of last rx activity
410  * @head_seq_num: head sequence number in reordering buffer.
411  * @stored_mpdu_num: number of MPDUs in reordering buffer
412  * @ssn: Starting Sequence Number expected to be aggregated.
413  * @buf_size: buffer size for incoming A-MPDUs
414  * @timeout: reset timer value (in TUs).
415  * @dialog_token: dialog token for aggregation session
416  * @rcu_head: RCU head used for freeing this struct
417  *
418  * This structure's lifetime is managed by RCU, assignments to
419  * the array holding it must hold the aggregation mutex.
420  *
421  */
422 struct wil_tid_ampdu_rx {
423         struct sk_buff **reorder_buf;
424         unsigned long *reorder_time;
425         struct timer_list session_timer;
426         struct timer_list reorder_timer;
427         unsigned long last_rx;
428         u16 head_seq_num;
429         u16 stored_mpdu_num;
430         u16 ssn;
431         u16 buf_size;
432         u16 timeout;
433         u16 ssn_last_drop;
434         u8 dialog_token;
435         bool first_time; /* is it 1-st time this buffer used? */
436 };
437
438 enum wil_sta_status {
439         wil_sta_unused = 0,
440         wil_sta_conn_pending = 1,
441         wil_sta_connected = 2,
442 };
443
444 #define WIL_STA_TID_NUM (16)
445
446 struct wil_net_stats {
447         unsigned long   rx_packets;
448         unsigned long   tx_packets;
449         unsigned long   rx_bytes;
450         unsigned long   tx_bytes;
451         unsigned long   tx_errors;
452         unsigned long   rx_dropped;
453         u16 last_mcs_rx;
454 };
455
456 /**
457  * struct wil_sta_info - data for peer
458  *
459  * Peer identified by its CID (connection ID)
460  * NIC performs beam forming for each peer;
461  * if no beam forming done, frame exchange is not
462  * possible.
463  */
464 struct wil_sta_info {
465         u8 addr[ETH_ALEN];
466         enum wil_sta_status status;
467         struct wil_net_stats stats;
468         bool data_port_open; /* can send any data, not only EAPOL */
469         /* Rx BACK */
470         struct wil_tid_ampdu_rx *tid_rx[WIL_STA_TID_NUM];
471         spinlock_t tid_rx_lock; /* guarding tid_rx array */
472         unsigned long tid_rx_timer_expired[BITS_TO_LONGS(WIL_STA_TID_NUM)];
473         unsigned long tid_rx_stop_requested[BITS_TO_LONGS(WIL_STA_TID_NUM)];
474 };
475
476 enum {
477         fw_recovery_idle = 0,
478         fw_recovery_pending = 1,
479         fw_recovery_running = 2,
480 };
481
482 enum {
483         hw_capability_reset_v2 = 0,
484         hw_capability_advanced_itr_moderation = 1,
485         hw_capability_last
486 };
487
488 struct wil_back_rx {
489         struct list_head list;
490         /* request params, converted to CPU byte order - what we asked for */
491         u8 cidxtid;
492         u8 dialog_token;
493         u16 ba_param_set;
494         u16 ba_timeout;
495         u16 ba_seq_ctrl;
496 };
497
498 struct wil_back_tx {
499         struct list_head list;
500         /* request params, converted to CPU byte order - what we asked for */
501         u8 ringid;
502         u8 agg_wsize;
503         u16 agg_timeout;
504 };
505
506 struct wil6210_priv {
507         struct pci_dev *pdev;
508         int n_msi;
509         struct wireless_dev *wdev;
510         void __iomem *csr;
511         DECLARE_BITMAP(status, wil_status_last);
512         u32 fw_version;
513         u32 hw_version;
514         const char *hw_name;
515         DECLARE_BITMAP(hw_capabilities, hw_capability_last);
516         u8 n_mids; /* number of additional MIDs as reported by FW */
517         u32 recovery_count; /* num of FW recovery attempts in a short time */
518         u32 recovery_state; /* FW recovery state machine */
519         unsigned long last_fw_recovery; /* jiffies of last fw recovery */
520         wait_queue_head_t wq; /* for all wait_event() use */
521         /* profile */
522         u32 monitor_flags;
523         u32 secure_pcp; /* create secure PCP? */
524         int sinfo_gen;
525         /* interrupt moderation */
526         u32 tx_max_burst_duration;
527         u32 tx_interframe_timeout;
528         u32 rx_max_burst_duration;
529         u32 rx_interframe_timeout;
530         /* cached ISR registers */
531         u32 isr_misc;
532         /* mailbox related */
533         struct mutex wmi_mutex;
534         struct wil6210_mbox_ctl mbox_ctl;
535         struct completion wmi_ready;
536         struct completion wmi_call;
537         u16 wmi_seq;
538         u16 reply_id; /**< wait for this WMI event */
539         void *reply_buf;
540         u16 reply_size;
541         struct workqueue_struct *wmi_wq; /* for deferred calls */
542         struct work_struct wmi_event_worker;
543         struct workqueue_struct *wq_service;
544         struct work_struct connect_worker;
545         struct work_struct disconnect_worker;
546         struct work_struct fw_error_worker;     /* for FW error recovery */
547         struct timer_list connect_timer;
548         struct timer_list scan_timer; /* detect scan timeout */
549         int pending_connect_cid;
550         struct list_head pending_wmi_ev;
551         /*
552          * protect pending_wmi_ev
553          * - fill in IRQ from wil6210_irq_misc,
554          * - consumed in thread by wmi_event_worker
555          */
556         spinlock_t wmi_ev_lock;
557         struct napi_struct napi_rx;
558         struct napi_struct napi_tx;
559         /* BACK */
560         struct list_head back_rx_pending;
561         struct mutex back_rx_mutex; /* protect @back_rx_pending */
562         struct work_struct back_rx_worker;
563         struct list_head back_tx_pending;
564         struct mutex back_tx_mutex; /* protect @back_tx_pending */
565         struct work_struct back_tx_worker;
566         /* DMA related */
567         struct vring vring_rx;
568         struct vring vring_tx[WIL6210_MAX_TX_RINGS];
569         struct vring_tx_data vring_tx_data[WIL6210_MAX_TX_RINGS];
570         u8 vring2cid_tid[WIL6210_MAX_TX_RINGS][2]; /* [0] - CID, [1] - TID */
571         struct wil_sta_info sta[WIL6210_MAX_CID];
572         /* scan */
573         struct cfg80211_scan_request *scan_request;
574
575         struct mutex mutex; /* for wil6210_priv access in wil_{up|down} */
576         /* statistics */
577         atomic_t isr_count_rx, isr_count_tx;
578         /* debugfs */
579         struct dentry *debug;
580         struct debugfs_blob_wrapper blobs[ARRAY_SIZE(fw_mapping)];
581
582         void *platform_handle;
583         struct wil_platform_ops platform_ops;
584 };
585
586 #define wil_to_wiphy(i) (i->wdev->wiphy)
587 #define wil_to_dev(i) (wiphy_dev(wil_to_wiphy(i)))
588 #define wiphy_to_wil(w) (struct wil6210_priv *)(wiphy_priv(w))
589 #define wil_to_wdev(i) (i->wdev)
590 #define wdev_to_wil(w) (struct wil6210_priv *)(wdev_priv(w))
591 #define wil_to_ndev(i) (wil_to_wdev(i)->netdev)
592 #define ndev_to_wil(n) (wdev_to_wil(n->ieee80211_ptr))
593
594 __printf(2, 3)
595 void wil_dbg_trace(struct wil6210_priv *wil, const char *fmt, ...);
596 __printf(2, 3)
597 void wil_err(struct wil6210_priv *wil, const char *fmt, ...);
598 __printf(2, 3)
599 void wil_err_ratelimited(struct wil6210_priv *wil, const char *fmt, ...);
600 __printf(2, 3)
601 void wil_info(struct wil6210_priv *wil, const char *fmt, ...);
602 #define wil_dbg(wil, fmt, arg...) do { \
603         netdev_dbg(wil_to_ndev(wil), fmt, ##arg); \
604         wil_dbg_trace(wil, fmt, ##arg); \
605 } while (0)
606
607 #define wil_dbg_irq(wil, fmt, arg...) wil_dbg(wil, "DBG[ IRQ]" fmt, ##arg)
608 #define wil_dbg_txrx(wil, fmt, arg...) wil_dbg(wil, "DBG[TXRX]" fmt, ##arg)
609 #define wil_dbg_wmi(wil, fmt, arg...) wil_dbg(wil, "DBG[ WMI]" fmt, ##arg)
610 #define wil_dbg_misc(wil, fmt, arg...) wil_dbg(wil, "DBG[MISC]" fmt, ##arg)
611
612 #if defined(CONFIG_DYNAMIC_DEBUG)
613 #define wil_hex_dump_txrx(prefix_str, prefix_type, rowsize,     \
614                           groupsize, buf, len, ascii)           \
615                           print_hex_dump_debug("DBG[TXRX]" prefix_str,\
616                                          prefix_type, rowsize,  \
617                                          groupsize, buf, len, ascii)
618
619 #define wil_hex_dump_wmi(prefix_str, prefix_type, rowsize,      \
620                          groupsize, buf, len, ascii)            \
621                          print_hex_dump_debug("DBG[ WMI]" prefix_str,\
622                                         prefix_type, rowsize,   \
623                                         groupsize, buf, len, ascii)
624 #else /* defined(CONFIG_DYNAMIC_DEBUG) */
625 static inline
626 void wil_hex_dump_txrx(const char *prefix_str, int prefix_type, int rowsize,
627                        int groupsize, const void *buf, size_t len, bool ascii)
628 {
629 }
630
631 static inline
632 void wil_hex_dump_wmi(const char *prefix_str, int prefix_type, int rowsize,
633                       int groupsize, const void *buf, size_t len, bool ascii)
634 {
635 }
636 #endif /* defined(CONFIG_DYNAMIC_DEBUG) */
637
638 void wil_memcpy_fromio_32(void *dst, const volatile void __iomem *src,
639                           size_t count);
640 void wil_memcpy_toio_32(volatile void __iomem *dst, const void *src,
641                         size_t count);
642
643 void *wil_if_alloc(struct device *dev, void __iomem *csr);
644 void wil_if_free(struct wil6210_priv *wil);
645 int wil_if_add(struct wil6210_priv *wil);
646 void wil_if_remove(struct wil6210_priv *wil);
647 int wil_priv_init(struct wil6210_priv *wil);
648 void wil_priv_deinit(struct wil6210_priv *wil);
649 int wil_reset(struct wil6210_priv *wil);
650 void wil_fw_error_recovery(struct wil6210_priv *wil);
651 void wil_set_recovery_state(struct wil6210_priv *wil, int state);
652 void wil_link_on(struct wil6210_priv *wil);
653 void wil_link_off(struct wil6210_priv *wil);
654 int wil_up(struct wil6210_priv *wil);
655 int __wil_up(struct wil6210_priv *wil);
656 int wil_down(struct wil6210_priv *wil);
657 int __wil_down(struct wil6210_priv *wil);
658 void wil_mbox_ring_le2cpus(struct wil6210_mbox_ring *r);
659 int wil_find_cid(struct wil6210_priv *wil, const u8 *mac);
660 void wil_set_ethtoolops(struct net_device *ndev);
661
662 void __iomem *wmi_buffer(struct wil6210_priv *wil, __le32 ptr);
663 void __iomem *wmi_addr(struct wil6210_priv *wil, u32 ptr);
664 int wmi_read_hdr(struct wil6210_priv *wil, __le32 ptr,
665                  struct wil6210_mbox_hdr *hdr);
666 int wmi_send(struct wil6210_priv *wil, u16 cmdid, void *buf, u16 len);
667 void wmi_recv_cmd(struct wil6210_priv *wil);
668 int wmi_call(struct wil6210_priv *wil, u16 cmdid, void *buf, u16 len,
669              u16 reply_id, void *reply, u8 reply_size, int to_msec);
670 void wmi_event_worker(struct work_struct *work);
671 void wmi_event_flush(struct wil6210_priv *wil);
672 int wmi_set_ssid(struct wil6210_priv *wil, u8 ssid_len, const void *ssid);
673 int wmi_get_ssid(struct wil6210_priv *wil, u8 *ssid_len, void *ssid);
674 int wmi_set_channel(struct wil6210_priv *wil, int channel);
675 int wmi_get_channel(struct wil6210_priv *wil, int *channel);
676 int wmi_del_cipher_key(struct wil6210_priv *wil, u8 key_index,
677                        const void *mac_addr);
678 int wmi_add_cipher_key(struct wil6210_priv *wil, u8 key_index,
679                        const void *mac_addr, int key_len, const void *key);
680 int wmi_echo(struct wil6210_priv *wil);
681 int wmi_set_ie(struct wil6210_priv *wil, u8 type, u16 ie_len, const void *ie);
682 int wmi_rx_chain_add(struct wil6210_priv *wil, struct vring *vring);
683 int wmi_p2p_cfg(struct wil6210_priv *wil, int channel);
684 int wmi_rxon(struct wil6210_priv *wil, bool on);
685 int wmi_get_temperature(struct wil6210_priv *wil, u32 *t_m, u32 *t_r);
686 int wmi_disconnect_sta(struct wil6210_priv *wil, const u8 *mac, u16 reason);
687 int wmi_addba(struct wil6210_priv *wil, u8 ringid, u8 size, u16 timeout);
688 int wmi_delba_tx(struct wil6210_priv *wil, u8 ringid, u16 reason);
689 int wmi_delba_rx(struct wil6210_priv *wil, u8 cidxtid, u16 reason);
690 int wmi_addba_rx_resp(struct wil6210_priv *wil, u8 cid, u8 tid, u8 token,
691                       u16 status, bool amsdu, u16 agg_wsize, u16 timeout);
692 int wil_addba_rx_request(struct wil6210_priv *wil, u8 cidxtid,
693                          u8 dialog_token, __le16 ba_param_set,
694                          __le16 ba_timeout, __le16 ba_seq_ctrl);
695 void wil_back_rx_worker(struct work_struct *work);
696 void wil_back_rx_flush(struct wil6210_priv *wil);
697 int wil_addba_tx_request(struct wil6210_priv *wil, u8 ringid, u16 wsize);
698 void wil_back_tx_worker(struct work_struct *work);
699 void wil_back_tx_flush(struct wil6210_priv *wil);
700
701 void wil6210_clear_irq(struct wil6210_priv *wil);
702 int wil6210_init_irq(struct wil6210_priv *wil, int irq);
703 void wil6210_fini_irq(struct wil6210_priv *wil, int irq);
704 void wil_mask_irq(struct wil6210_priv *wil);
705 void wil_unmask_irq(struct wil6210_priv *wil);
706 void wil_configure_interrupt_moderation(struct wil6210_priv *wil);
707 void wil_disable_irq(struct wil6210_priv *wil);
708 void wil_enable_irq(struct wil6210_priv *wil);
709 int wil_cfg80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
710                          struct cfg80211_mgmt_tx_params *params,
711                          u64 *cookie);
712
713 int wil6210_debugfs_init(struct wil6210_priv *wil);
714 void wil6210_debugfs_remove(struct wil6210_priv *wil);
715 int wil_cid_fill_sinfo(struct wil6210_priv *wil, int cid,
716                        struct station_info *sinfo);
717
718 struct wireless_dev *wil_cfg80211_init(struct device *dev);
719 void wil_wdev_free(struct wil6210_priv *wil);
720
721 int wmi_set_mac_address(struct wil6210_priv *wil, void *addr);
722 int wmi_pcp_start(struct wil6210_priv *wil, int bi, u8 wmi_nettype, u8 chan);
723 int wmi_pcp_stop(struct wil6210_priv *wil);
724 void wil6210_disconnect(struct wil6210_priv *wil, const u8 *bssid,
725                         u16 reason_code, bool from_event);
726
727 int wil_rx_init(struct wil6210_priv *wil, u16 size);
728 void wil_rx_fini(struct wil6210_priv *wil);
729
730 /* TX API */
731 int wil_vring_init_tx(struct wil6210_priv *wil, int id, int size,
732                       int cid, int tid);
733 void wil_vring_fini_tx(struct wil6210_priv *wil, int id);
734
735 netdev_tx_t wil_start_xmit(struct sk_buff *skb, struct net_device *ndev);
736 int wil_tx_complete(struct wil6210_priv *wil, int ringid);
737 void wil6210_unmask_irq_tx(struct wil6210_priv *wil);
738
739 /* RX API */
740 void wil_rx_handle(struct wil6210_priv *wil, int *quota);
741 void wil6210_unmask_irq_rx(struct wil6210_priv *wil);
742
743 int wil_iftype_nl2wmi(enum nl80211_iftype type);
744
745 int wil_ioctl(struct wil6210_priv *wil, void __user *data, int cmd);
746 int wil_request_firmware(struct wil6210_priv *wil, const char *name);
747
748 #endif /* __WIL6210_H__ */