blob: 4e08262cc6b307d2c7d492a5a873b5f34d309234 [file] [log] [blame]
Jon West96501cc2021-04-06 13:09:18 -04001/* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
2/* Copyright(c) 2018-2019 Realtek Corporation
3 */
4
5#ifndef __RTK_MAIN_H_
6#define __RTK_MAIN_H_
7
8#include <linux/version.h>
9#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 11, 0)
10#include "compiler.h"
11#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0)
12#include "sch_generic.h"
13#endif
14#endif
15#include <net/mac80211.h>
16#include <linux/vmalloc.h>
17#include <linux/firmware.h>
18#include <linux/average.h>
19#include <linux/bitops.h>
20#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 19, 0)
21#include <linux/bitfield.h>
22#else
23#include "bitfield.h"
24#endif
25#include <linux/iopoll.h>
26#include <linux/interrupt.h>
27#include <linux/workqueue.h>
28
29#include "util.h"
30#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 8, 0)
31#include <linux/etherdevice.h>
32#endif
33
34#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 7, 0)
35#define NUM_NL80211_BANDS IEEE80211_NUM_BANDS
36#endif
37
38#define RTW_NAPI_WEIGHT_NUM 32
39#define RTW_MAX_MAC_ID_NUM 32
40#define RTW_MAX_SEC_CAM_NUM 32
41#define MAX_PG_CAM_BACKUP_NUM 8
42
43#define RTW_MAX_PATTERN_NUM 12
44#define RTW_MAX_PATTERN_MASK_SIZE 16
45#define RTW_MAX_PATTERN_SIZE 128
46
47#define RTW_WATCH_DOG_DELAY_TIME round_jiffies_relative(HZ * 2)
48
49#define RFREG_MASK 0xfffff
50#define INV_RF_DATA 0xffffffff
51#define TX_PAGE_SIZE_SHIFT 7
52
53#define RTW_CHANNEL_WIDTH_MAX 3
54#define RTW_RF_PATH_MAX 4
55#define HW_FEATURE_LEN 13
56
57#define RTW_TP_SHIFT 18 /* bytes/2s --> Mbps */
58
59#ifndef read_poll_timeout
60#define read_poll_timeout(op, val, cond, sleep_us, timeout_us, \
61 sleep_before_read, args...) \
62({ \
63 u64 __timeout_us = (timeout_us); \
64 unsigned long __sleep_us = (sleep_us); \
65 ktime_t __timeout = ktime_add_us(ktime_get(), __timeout_us); \
66 might_sleep_if((__sleep_us) != 0); \
67 if (sleep_before_read && __sleep_us) \
68 usleep_range((__sleep_us >> 2) + 1, __sleep_us); \
69 for (;;) { \
70 (val) = op(args); \
71 if (cond) \
72 break; \
73 if (__timeout_us && \
74 ktime_compare(ktime_get(), __timeout) > 0) { \
75 (val) = op(args); \
76 break; \
77 } \
78 if (__sleep_us) \
79 usleep_range((__sleep_us >> 2) + 1, __sleep_us); \
80 } \
81 (cond) ? 0 : -ETIMEDOUT; \
82})
83#endif
84
85#ifndef fallthrough
86#define fallthrough do {} while (0)
87#endif
88
89#ifndef static_assert
90#define static_assert(expr, ...) __static_assert(expr, ##__VA_ARGS__, #expr)
91#define __static_assert(expr, msg, ...) _Static_assert(expr, msg)
92#endif
93
94#ifndef read_poll_timeout_atomic
95#define read_poll_timeout_atomic(op, val, cond, delay_us, timeout_us, \
96 delay_before_read, args...) \
97({ \
98 u64 __timeout_us = (timeout_us); \
99 unsigned long __delay_us = (delay_us); \
100 ktime_t __timeout = ktime_add_us(ktime_get(), __timeout_us); \
101 if (delay_before_read && __delay_us) \
102 udelay(__delay_us); \
103 for (;;) { \
104 (val) = op(args); \
105 if (cond) \
106 break; \
107 if (__timeout_us && \
108 ktime_compare(ktime_get(), __timeout) > 0) { \
109 (val) = op(args); \
110 break; \
111 } \
112 if (__delay_us) \
113 udelay(__delay_us); \
114 } \
115 (cond) ? 0 : -ETIMEDOUT; \
116})
117#endif
118
119extern bool rtw_bf_support;
120extern bool rtw_disable_lps_deep_mode;
121extern unsigned int rtw_debug_mask;
122extern const struct ieee80211_ops rtw_ops;
123
124#define RTW_MAX_CHANNEL_NUM_2G 14
125#define RTW_MAX_CHANNEL_NUM_5G 49
126
127struct rtw_dev;
128
129enum rtw_hci_type {
130 RTW_HCI_TYPE_PCIE,
131 RTW_HCI_TYPE_USB,
132 RTW_HCI_TYPE_SDIO,
133
134 RTW_HCI_TYPE_UNDEFINE,
135};
136
137struct rtw_hci {
138 struct rtw_hci_ops *ops;
139 enum rtw_hci_type type;
140
141 u32 rpwm_addr;
142 u32 cpwm_addr;
143
144 u8 bulkout_num;
145};
146
147#define IS_CH_5G_BAND_1(channel) ((channel) >= 36 && (channel <= 48))
148#define IS_CH_5G_BAND_2(channel) ((channel) >= 52 && (channel <= 64))
149#define IS_CH_5G_BAND_3(channel) ((channel) >= 100 && (channel <= 144))
150#define IS_CH_5G_BAND_4(channel) ((channel) >= 149 && (channel <= 177))
151
152#define IS_CH_5G_BAND_MID(channel) \
153 (IS_CH_5G_BAND_2(channel) || IS_CH_5G_BAND_3(channel))
154
155#define IS_CH_2G_BAND(channel) ((channel) <= 14)
156#define IS_CH_5G_BAND(channel) \
157 (IS_CH_5G_BAND_1(channel) || IS_CH_5G_BAND_2(channel) || \
158 IS_CH_5G_BAND_3(channel) || IS_CH_5G_BAND_4(channel))
159
160enum rtw_supported_band {
161 RTW_BAND_2G = 1 << 0,
162 RTW_BAND_5G = 1 << 1,
163 RTW_BAND_60G = 1 << 2,
164
165 RTW_BAND_MAX,
166};
167
168/* now, support upto 80M bw */
169#define RTW_MAX_CHANNEL_WIDTH RTW_CHANNEL_WIDTH_80
170
171enum rtw_bandwidth {
172 RTW_CHANNEL_WIDTH_20 = 0,
173 RTW_CHANNEL_WIDTH_40 = 1,
174 RTW_CHANNEL_WIDTH_80 = 2,
175 RTW_CHANNEL_WIDTH_160 = 3,
176 RTW_CHANNEL_WIDTH_80_80 = 4,
177 RTW_CHANNEL_WIDTH_5 = 5,
178 RTW_CHANNEL_WIDTH_10 = 6,
179};
180
181enum rtw_sc_offset {
182 RTW_SC_DONT_CARE = 0,
183 RTW_SC_20_UPPER = 1,
184 RTW_SC_20_LOWER = 2,
185 RTW_SC_20_UPMOST = 3,
186 RTW_SC_20_LOWEST = 4,
187 RTW_SC_40_UPPER = 9,
188 RTW_SC_40_LOWER = 10,
189};
190
191enum rtw_net_type {
192 RTW_NET_NO_LINK = 0,
193 RTW_NET_AD_HOC = 1,
194 RTW_NET_MGD_LINKED = 2,
195 RTW_NET_AP_MODE = 3,
196};
197
198enum rtw_rf_type {
199 RF_1T1R = 0,
200 RF_1T2R = 1,
201 RF_2T2R = 2,
202 RF_2T3R = 3,
203 RF_2T4R = 4,
204 RF_3T3R = 5,
205 RF_3T4R = 6,
206 RF_4T4R = 7,
207 RF_TYPE_MAX,
208};
209
210enum rtw_rf_path {
211 RF_PATH_A = 0,
212 RF_PATH_B = 1,
213 RF_PATH_C = 2,
214 RF_PATH_D = 3,
215};
216
217enum rtw_bb_path {
218 BB_PATH_A = BIT(0),
219 BB_PATH_B = BIT(1),
220 BB_PATH_C = BIT(2),
221 BB_PATH_D = BIT(3),
222
223 BB_PATH_AB = (BB_PATH_A | BB_PATH_B),
224 BB_PATH_AC = (BB_PATH_A | BB_PATH_C),
225 BB_PATH_AD = (BB_PATH_A | BB_PATH_D),
226 BB_PATH_BC = (BB_PATH_B | BB_PATH_C),
227 BB_PATH_BD = (BB_PATH_B | BB_PATH_D),
228 BB_PATH_CD = (BB_PATH_C | BB_PATH_D),
229
230 BB_PATH_ABC = (BB_PATH_A | BB_PATH_B | BB_PATH_C),
231 BB_PATH_ABD = (BB_PATH_A | BB_PATH_B | BB_PATH_D),
232 BB_PATH_ACD = (BB_PATH_A | BB_PATH_C | BB_PATH_D),
233 BB_PATH_BCD = (BB_PATH_B | BB_PATH_C | BB_PATH_D),
234
235 BB_PATH_ABCD = (BB_PATH_A | BB_PATH_B | BB_PATH_C | BB_PATH_D),
236};
237
238enum rtw_rate_section {
239 RTW_RATE_SECTION_CCK = 0,
240 RTW_RATE_SECTION_OFDM,
241 RTW_RATE_SECTION_HT_1S,
242 RTW_RATE_SECTION_HT_2S,
243 RTW_RATE_SECTION_VHT_1S,
244 RTW_RATE_SECTION_VHT_2S,
245
246 /* keep last */
247 RTW_RATE_SECTION_MAX,
248};
249
250enum rtw_wireless_set {
251 WIRELESS_CCK = 0x00000001,
252 WIRELESS_OFDM = 0x00000002,
253 WIRELESS_HT = 0x00000004,
254 WIRELESS_VHT = 0x00000008,
255};
256
257#define HT_STBC_EN BIT(0)
258#define VHT_STBC_EN BIT(1)
259#define HT_LDPC_EN BIT(0)
260#define VHT_LDPC_EN BIT(1)
261
262enum rtw_chip_type {
263 RTW_CHIP_TYPE_8822B,
264 RTW_CHIP_TYPE_8822C,
265 RTW_CHIP_TYPE_8723D,
266 RTW_CHIP_TYPE_8821C,
267};
268
269enum rtw_tx_queue_type {
270 /* the order of AC queues matters */
271 RTW_TX_QUEUE_BK = 0x0,
272 RTW_TX_QUEUE_BE = 0x1,
273 RTW_TX_QUEUE_VI = 0x2,
274 RTW_TX_QUEUE_VO = 0x3,
275
276 RTW_TX_QUEUE_BCN = 0x4,
277 RTW_TX_QUEUE_MGMT = 0x5,
278 RTW_TX_QUEUE_HI0 = 0x6,
279 RTW_TX_QUEUE_H2C = 0x7,
280 /* keep it last */
281 RTK_MAX_TX_QUEUE_NUM
282};
283
284enum rtw_rx_queue_type {
285 RTW_RX_QUEUE_MPDU = 0x0,
286 RTW_RX_QUEUE_C2H = 0x1,
287 /* keep it last */
288 RTK_MAX_RX_QUEUE_NUM
289};
290
291enum rtw_fw_type {
292 RTW_NORMAL_FW = 0x0,
293 RTW_WOWLAN_FW = 0x1,
294};
295
296enum rtw_rate_index {
297 RTW_RATEID_BGN_40M_2SS = 0,
298 RTW_RATEID_BGN_40M_1SS = 1,
299 RTW_RATEID_BGN_20M_2SS = 2,
300 RTW_RATEID_BGN_20M_1SS = 3,
301 RTW_RATEID_GN_N2SS = 4,
302 RTW_RATEID_GN_N1SS = 5,
303 RTW_RATEID_BG = 6,
304 RTW_RATEID_G = 7,
305 RTW_RATEID_B_20M = 8,
306 RTW_RATEID_ARFR0_AC_2SS = 9,
307 RTW_RATEID_ARFR1_AC_1SS = 10,
308 RTW_RATEID_ARFR2_AC_2G_1SS = 11,
309 RTW_RATEID_ARFR3_AC_2G_2SS = 12,
310 RTW_RATEID_ARFR4_AC_3SS = 13,
311 RTW_RATEID_ARFR5_N_3SS = 14,
312 RTW_RATEID_ARFR7_N_4SS = 15,
313 RTW_RATEID_ARFR6_AC_4SS = 16
314};
315
316enum rtw_trx_desc_rate {
317 DESC_RATE1M = 0x00,
318 DESC_RATE2M = 0x01,
319 DESC_RATE5_5M = 0x02,
320 DESC_RATE11M = 0x03,
321
322 DESC_RATE6M = 0x04,
323 DESC_RATE9M = 0x05,
324 DESC_RATE12M = 0x06,
325 DESC_RATE18M = 0x07,
326 DESC_RATE24M = 0x08,
327 DESC_RATE36M = 0x09,
328 DESC_RATE48M = 0x0a,
329 DESC_RATE54M = 0x0b,
330
331 DESC_RATEMCS0 = 0x0c,
332 DESC_RATEMCS1 = 0x0d,
333 DESC_RATEMCS2 = 0x0e,
334 DESC_RATEMCS3 = 0x0f,
335 DESC_RATEMCS4 = 0x10,
336 DESC_RATEMCS5 = 0x11,
337 DESC_RATEMCS6 = 0x12,
338 DESC_RATEMCS7 = 0x13,
339 DESC_RATEMCS8 = 0x14,
340 DESC_RATEMCS9 = 0x15,
341 DESC_RATEMCS10 = 0x16,
342 DESC_RATEMCS11 = 0x17,
343 DESC_RATEMCS12 = 0x18,
344 DESC_RATEMCS13 = 0x19,
345 DESC_RATEMCS14 = 0x1a,
346 DESC_RATEMCS15 = 0x1b,
347 DESC_RATEMCS16 = 0x1c,
348 DESC_RATEMCS17 = 0x1d,
349 DESC_RATEMCS18 = 0x1e,
350 DESC_RATEMCS19 = 0x1f,
351 DESC_RATEMCS20 = 0x20,
352 DESC_RATEMCS21 = 0x21,
353 DESC_RATEMCS22 = 0x22,
354 DESC_RATEMCS23 = 0x23,
355 DESC_RATEMCS24 = 0x24,
356 DESC_RATEMCS25 = 0x25,
357 DESC_RATEMCS26 = 0x26,
358 DESC_RATEMCS27 = 0x27,
359 DESC_RATEMCS28 = 0x28,
360 DESC_RATEMCS29 = 0x29,
361 DESC_RATEMCS30 = 0x2a,
362 DESC_RATEMCS31 = 0x2b,
363
364 DESC_RATEVHT1SS_MCS0 = 0x2c,
365 DESC_RATEVHT1SS_MCS1 = 0x2d,
366 DESC_RATEVHT1SS_MCS2 = 0x2e,
367 DESC_RATEVHT1SS_MCS3 = 0x2f,
368 DESC_RATEVHT1SS_MCS4 = 0x30,
369 DESC_RATEVHT1SS_MCS5 = 0x31,
370 DESC_RATEVHT1SS_MCS6 = 0x32,
371 DESC_RATEVHT1SS_MCS7 = 0x33,
372 DESC_RATEVHT1SS_MCS8 = 0x34,
373 DESC_RATEVHT1SS_MCS9 = 0x35,
374
375 DESC_RATEVHT2SS_MCS0 = 0x36,
376 DESC_RATEVHT2SS_MCS1 = 0x37,
377 DESC_RATEVHT2SS_MCS2 = 0x38,
378 DESC_RATEVHT2SS_MCS3 = 0x39,
379 DESC_RATEVHT2SS_MCS4 = 0x3a,
380 DESC_RATEVHT2SS_MCS5 = 0x3b,
381 DESC_RATEVHT2SS_MCS6 = 0x3c,
382 DESC_RATEVHT2SS_MCS7 = 0x3d,
383 DESC_RATEVHT2SS_MCS8 = 0x3e,
384 DESC_RATEVHT2SS_MCS9 = 0x3f,
385
386 DESC_RATEVHT3SS_MCS0 = 0x40,
387 DESC_RATEVHT3SS_MCS1 = 0x41,
388 DESC_RATEVHT3SS_MCS2 = 0x42,
389 DESC_RATEVHT3SS_MCS3 = 0x43,
390 DESC_RATEVHT3SS_MCS4 = 0x44,
391 DESC_RATEVHT3SS_MCS5 = 0x45,
392 DESC_RATEVHT3SS_MCS6 = 0x46,
393 DESC_RATEVHT3SS_MCS7 = 0x47,
394 DESC_RATEVHT3SS_MCS8 = 0x48,
395 DESC_RATEVHT3SS_MCS9 = 0x49,
396
397 DESC_RATEVHT4SS_MCS0 = 0x4a,
398 DESC_RATEVHT4SS_MCS1 = 0x4b,
399 DESC_RATEVHT4SS_MCS2 = 0x4c,
400 DESC_RATEVHT4SS_MCS3 = 0x4d,
401 DESC_RATEVHT4SS_MCS4 = 0x4e,
402 DESC_RATEVHT4SS_MCS5 = 0x4f,
403 DESC_RATEVHT4SS_MCS6 = 0x50,
404 DESC_RATEVHT4SS_MCS7 = 0x51,
405 DESC_RATEVHT4SS_MCS8 = 0x52,
406 DESC_RATEVHT4SS_MCS9 = 0x53,
407
408 DESC_RATE_MAX,
409};
410
411enum rtw_regulatory_domains {
412 RTW_REGD_FCC = 0,
413 RTW_REGD_MKK = 1,
414 RTW_REGD_ETSI = 2,
415 RTW_REGD_IC = 3,
416 RTW_REGD_KCC = 4,
417 RTW_REGD_ACMA = 5,
418 RTW_REGD_CHILE = 6,
419 RTW_REGD_UKRAINE = 7,
420 RTW_REGD_MEXICO = 8,
421 RTW_REGD_CN = 9,
422 RTW_REGD_WW,
423
424 RTW_REGD_MAX
425};
426
427enum rtw_txq_flags {
428 RTW_TXQ_AMPDU,
429 RTW_TXQ_BLOCK_BA,
430};
431
432enum rtw_flags {
433 RTW_FLAG_RUNNING,
434 RTW_FLAG_FW_RUNNING,
435 RTW_FLAG_SCANNING,
436 RTW_FLAG_INACTIVE_PS,
437 RTW_FLAG_LEISURE_PS,
438 RTW_FLAG_LEISURE_PS_DEEP,
439 RTW_FLAG_DIG_DISABLE,
440 RTW_FLAG_BUSY_TRAFFIC,
441 RTW_FLAG_WOWLAN,
442 RTW_FLAG_RESTARTING,
443
444 NUM_OF_RTW_FLAGS,
445};
446
447enum rtw_evm {
448 RTW_EVM_OFDM = 0,
449 RTW_EVM_1SS,
450 RTW_EVM_2SS_A,
451 RTW_EVM_2SS_B,
452 /* keep it last */
453 RTW_EVM_NUM
454};
455
456enum rtw_snr {
457 RTW_SNR_OFDM_A = 0,
458 RTW_SNR_OFDM_B,
459 RTW_SNR_OFDM_C,
460 RTW_SNR_OFDM_D,
461 RTW_SNR_1SS_A,
462 RTW_SNR_1SS_B,
463 RTW_SNR_1SS_C,
464 RTW_SNR_1SS_D,
465 RTW_SNR_2SS_A,
466 RTW_SNR_2SS_B,
467 RTW_SNR_2SS_C,
468 RTW_SNR_2SS_D,
469 /* keep it last */
470 RTW_SNR_NUM
471};
472
473enum rtw_wow_flags {
474 RTW_WOW_FLAG_EN_MAGIC_PKT,
475 RTW_WOW_FLAG_EN_REKEY_PKT,
476 RTW_WOW_FLAG_EN_DISCONNECT,
477
478 /* keep it last */
479 RTW_WOW_FLAG_MAX,
480};
481
482/* the power index is represented by differences, which cck-1s & ht40-1s are
483 * the base values, so for 1s's differences, there are only ht20 & ofdm
484 */
485struct rtw_2g_1s_pwr_idx_diff {
486#ifdef __LITTLE_ENDIAN
487 s8 ofdm:4;
488 s8 bw20:4;
489#else
490 s8 bw20:4;
491 s8 ofdm:4;
492#endif
493} __packed;
494
495struct rtw_2g_ns_pwr_idx_diff {
496#ifdef __LITTLE_ENDIAN
497 s8 bw20:4;
498 s8 bw40:4;
499 s8 cck:4;
500 s8 ofdm:4;
501#else
502 s8 ofdm:4;
503 s8 cck:4;
504 s8 bw40:4;
505 s8 bw20:4;
506#endif
507} __packed;
508
509struct rtw_2g_txpwr_idx {
510 u8 cck_base[6];
511 u8 bw40_base[5];
512 struct rtw_2g_1s_pwr_idx_diff ht_1s_diff;
513 struct rtw_2g_ns_pwr_idx_diff ht_2s_diff;
514 struct rtw_2g_ns_pwr_idx_diff ht_3s_diff;
515 struct rtw_2g_ns_pwr_idx_diff ht_4s_diff;
516};
517
518struct rtw_5g_ht_1s_pwr_idx_diff {
519#ifdef __LITTLE_ENDIAN
520 s8 ofdm:4;
521 s8 bw20:4;
522#else
523 s8 bw20:4;
524 s8 ofdm:4;
525#endif
526} __packed;
527
528struct rtw_5g_ht_ns_pwr_idx_diff {
529#ifdef __LITTLE_ENDIAN
530 s8 bw20:4;
531 s8 bw40:4;
532#else
533 s8 bw40:4;
534 s8 bw20:4;
535#endif
536} __packed;
537
538struct rtw_5g_ofdm_ns_pwr_idx_diff {
539#ifdef __LITTLE_ENDIAN
540 s8 ofdm_3s:4;
541 s8 ofdm_2s:4;
542 s8 ofdm_4s:4;
543 s8 res:4;
544#else
545 s8 res:4;
546 s8 ofdm_4s:4;
547 s8 ofdm_2s:4;
548 s8 ofdm_3s:4;
549#endif
550} __packed;
551
552struct rtw_5g_vht_ns_pwr_idx_diff {
553#ifdef __LITTLE_ENDIAN
554 s8 bw160:4;
555 s8 bw80:4;
556#else
557 s8 bw80:4;
558 s8 bw160:4;
559#endif
560} __packed;
561
562struct rtw_5g_txpwr_idx {
563 u8 bw40_base[14];
564 struct rtw_5g_ht_1s_pwr_idx_diff ht_1s_diff;
565 struct rtw_5g_ht_ns_pwr_idx_diff ht_2s_diff;
566 struct rtw_5g_ht_ns_pwr_idx_diff ht_3s_diff;
567 struct rtw_5g_ht_ns_pwr_idx_diff ht_4s_diff;
568 struct rtw_5g_ofdm_ns_pwr_idx_diff ofdm_diff;
569 struct rtw_5g_vht_ns_pwr_idx_diff vht_1s_diff;
570 struct rtw_5g_vht_ns_pwr_idx_diff vht_2s_diff;
571 struct rtw_5g_vht_ns_pwr_idx_diff vht_3s_diff;
572 struct rtw_5g_vht_ns_pwr_idx_diff vht_4s_diff;
573};
574
575struct rtw_txpwr_idx {
576 struct rtw_2g_txpwr_idx pwr_idx_2g;
577 struct rtw_5g_txpwr_idx pwr_idx_5g;
578};
579
580struct rtw_timer_list {
581 struct timer_list timer;
582 void (*function)(void *data);
583 void *args;
584};
585
586struct rtw_channel_params {
587 u8 center_chan;
588 u8 bandwidth;
589 u8 primary_chan_idx;
590 /* center channel by different available bandwidth,
591 * val of (bw > current bandwidth) is invalid
592 */
593 u8 cch_by_bw[RTW_MAX_CHANNEL_WIDTH + 1];
594};
595
596struct rtw_hw_reg {
597 u32 addr;
598 u32 mask;
599};
600
601struct rtw_ltecoex_addr {
602 u32 ctrl;
603 u32 wdata;
604 u32 rdata;
605};
606
607struct rtw_reg_domain {
608 u32 addr;
609 u32 mask;
610#define RTW_REG_DOMAIN_MAC32 0
611#define RTW_REG_DOMAIN_MAC16 1
612#define RTW_REG_DOMAIN_MAC8 2
613#define RTW_REG_DOMAIN_RF_A 3
614#define RTW_REG_DOMAIN_RF_B 4
615#define RTW_REG_DOMAIN_NL 0xFF
616 u8 domain;
617};
618
619struct rtw_rf_sipi_addr {
620 u32 hssi_1;
621 u32 hssi_2;
622 u32 lssi_read;
623 u32 lssi_read_pi;
624};
625
626struct rtw_backup_info {
627 u8 len;
628 u32 reg;
629 u32 val;
630};
631
632enum rtw_vif_port_set {
633 PORT_SET_MAC_ADDR = BIT(0),
634 PORT_SET_BSSID = BIT(1),
635 PORT_SET_NET_TYPE = BIT(2),
636 PORT_SET_AID = BIT(3),
637 PORT_SET_BCN_CTRL = BIT(4),
638};
639
640struct rtw_vif_port {
641 struct rtw_hw_reg mac_addr;
642 struct rtw_hw_reg bssid;
643 struct rtw_hw_reg net_type;
644 struct rtw_hw_reg aid;
645 struct rtw_hw_reg bcn_ctrl;
646};
647
648struct rtw_tx_pkt_info {
649 u32 tx_pkt_size;
650 u8 offset;
651 u8 pkt_offset;
652 u8 mac_id;
653 u8 rate_id;
654 u8 rate;
655 u8 qsel;
656 u8 bw;
657 u8 sec_type;
658 u8 sn;
659 bool ampdu_en;
660 u8 ampdu_factor;
661 u8 ampdu_density;
662 u16 seq;
663 bool stbc;
664 bool ldpc;
665 bool dis_rate_fallback;
666 bool bmc;
667 bool use_rate;
668 bool ls;
669 bool fs;
670 bool short_gi;
671 bool report;
672 bool rts;
673 bool dis_qselseq;
674 bool en_hwseq;
675 u8 hw_ssn_sel;
676 bool nav_use_hdr;
677 bool bt_null;
678};
679
680struct rtw_rx_pkt_stat {
681 bool phy_status;
682 bool icv_err;
683 bool crc_err;
684 bool decrypted;
685 bool is_c2h;
686
687 s32 signal_power;
688 u16 pkt_len;
689 u8 bw;
690 u8 drv_info_sz;
691 u8 shift;
692 u8 rate;
693 u8 mac_id;
694 u8 cam_id;
695 u8 ppdu_cnt;
696 u32 tsf_low;
697 s8 rx_power[RTW_RF_PATH_MAX];
698 u8 rssi;
699 u8 rxsc;
700 s8 rx_snr[RTW_RF_PATH_MAX];
701 u8 rx_evm[RTW_RF_PATH_MAX];
702 s8 cfo_tail[RTW_RF_PATH_MAX];
703
704 struct rtw_sta_info *si;
705 struct ieee80211_vif *vif;
706};
707
708DECLARE_EWMA(tp, 10, 2);
709
710struct rtw_traffic_stats {
711 /* units in bytes */
712 u64 tx_unicast;
713 u64 rx_unicast;
714
715 /* count for packets */
716 u64 tx_cnt;
717 u64 rx_cnt;
718
719 /* units in Mbps */
720 u32 tx_throughput;
721 u32 rx_throughput;
722 struct ewma_tp tx_ewma_tp;
723 struct ewma_tp rx_ewma_tp;
724};
725
726enum rtw_lps_mode {
727 RTW_MODE_ACTIVE = 0,
728 RTW_MODE_LPS = 1,
729 RTW_MODE_WMM_PS = 2,
730};
731
732enum rtw_lps_deep_mode {
733 LPS_DEEP_MODE_NONE = 0,
734 LPS_DEEP_MODE_LCLK = 1,
735 LPS_DEEP_MODE_PG = 2,
736};
737
738enum rtw_pwr_state {
739 RTW_RF_OFF = 0x0,
740 RTW_RF_ON = 0x4,
741 RTW_ALL_ON = 0xc,
742};
743
744struct rtw_lps_conf {
745 enum rtw_lps_mode mode;
746 enum rtw_lps_deep_mode deep_mode;
747 enum rtw_lps_deep_mode wow_deep_mode;
748 enum rtw_pwr_state state;
749 u8 awake_interval;
750 u8 rlbm;
751 u8 smart_ps;
752 u8 port_id;
753 bool sec_cam_backup;
754 bool pattern_cam_backup;
755};
756
757enum rtw_hw_key_type {
758 RTW_CAM_NONE = 0,
759 RTW_CAM_WEP40 = 1,
760 RTW_CAM_TKIP = 2,
761 RTW_CAM_AES = 4,
762 RTW_CAM_WEP104 = 5,
763};
764
765struct rtw_cam_entry {
766 bool valid;
767 bool group;
768 u8 addr[ETH_ALEN];
769 u8 hw_key_type;
770 struct ieee80211_key_conf *key;
771};
772
773struct rtw_sec_desc {
774 /* search strategy */
775 bool default_key_search;
776
777 u32 total_cam_num;
778 struct rtw_cam_entry cam_table[RTW_MAX_SEC_CAM_NUM];
779 DECLARE_BITMAP(cam_map, RTW_MAX_SEC_CAM_NUM);
780};
781
782struct rtw_tx_report {
783 /* protect the tx report queue */
784 spinlock_t q_lock;
785 struct sk_buff_head queue;
786 atomic_t sn;
787 struct timer_list purge_timer;
788};
789
790struct rtw_ra_report {
791 struct rate_info txrate;
792 u32 bit_rate;
793 u8 desc_rate;
794};
795
796struct rtw_txq {
797 struct list_head list;
798
799 unsigned long flags;
800 unsigned long last_push;
801};
802
803#define RTW_BC_MC_MACID 1
804DECLARE_EWMA(rssi, 10, 16);
805
806struct rtw_sta_info {
807 struct ieee80211_sta *sta;
808 struct ieee80211_vif *vif;
809
810 struct ewma_rssi avg_rssi;
811 u8 rssi_level;
812
813 u8 mac_id;
814 u8 rate_id;
815 enum rtw_bandwidth bw_mode;
816 enum rtw_rf_type rf_type;
817 enum rtw_wireless_set wireless_set;
818 u8 stbc_en:2;
819 u8 ldpc_en:2;
820 bool sgi_enable;
821 bool vht_enable;
822 bool updated;
823 u8 init_ra_lv;
824 u64 ra_mask;
825
826 DECLARE_BITMAP(tid_ba, IEEE80211_NUM_TIDS);
827
828 struct rtw_ra_report ra_report;
829
830 bool use_cfg_mask;
831 struct cfg80211_bitrate_mask *mask;
832};
833
834enum rtw_bfee_role {
835 RTW_BFEE_NONE,
836 RTW_BFEE_SU,
837 RTW_BFEE_MU
838};
839
840struct rtw_bfee {
841 enum rtw_bfee_role role;
842
843 u16 p_aid;
844 u8 g_id;
845 u8 mac_addr[ETH_ALEN];
846 u8 sound_dim;
847
848 /* SU-MIMO */
849 u8 su_reg_index;
850
851 /* MU-MIMO */
852 u16 aid;
853};
854
855struct rtw_bf_info {
856 u8 bfer_mu_cnt;
857 u8 bfer_su_cnt;
858 DECLARE_BITMAP(bfer_su_reg_maping, 2);
859 u8 cur_csi_rpt_rate;
860};
861
862struct rtw_vif {
863 enum rtw_net_type net_type;
864 u16 aid;
865 u8 mac_addr[ETH_ALEN];
866 u8 bssid[ETH_ALEN];
867 u8 port;
868 u8 bcn_ctrl;
869 struct list_head rsvd_page_list;
870 struct ieee80211_tx_queue_params tx_params[IEEE80211_NUM_ACS];
871 const struct rtw_vif_port *conf;
872
873 struct rtw_traffic_stats stats;
874
875 struct rtw_bfee bfee;
876};
877
878struct rtw_regulatory {
879 char alpha2[2];
880 u8 chplan;
881 u8 txpwr_regd;
882};
883
884struct rtw_chip_ops {
885 int (*mac_init)(struct rtw_dev *rtwdev);
886 void (*shutdown)(struct rtw_dev *rtwdev);
887 int (*read_efuse)(struct rtw_dev *rtwdev, u8 *map);
888 void (*phy_set_param)(struct rtw_dev *rtwdev);
889 void (*set_channel)(struct rtw_dev *rtwdev, u8 channel,
890 u8 bandwidth, u8 primary_chan_idx);
891 void (*query_rx_desc)(struct rtw_dev *rtwdev, u8 *rx_desc,
892 struct rtw_rx_pkt_stat *pkt_stat,
893 struct ieee80211_rx_status *rx_status);
894 u32 (*read_rf)(struct rtw_dev *rtwdev, enum rtw_rf_path rf_path,
895 u32 addr, u32 mask);
896 bool (*write_rf)(struct rtw_dev *rtwdev, enum rtw_rf_path rf_path,
897 u32 addr, u32 mask, u32 data);
898 void (*set_tx_power_index)(struct rtw_dev *rtwdev);
899 int (*rsvd_page_dump)(struct rtw_dev *rtwdev, u8 *buf, u32 offset,
900 u32 size);
901 int (*set_antenna)(struct rtw_dev *rtwdev,
902 u32 antenna_tx,
903 u32 antenna_rx);
904 void (*cfg_ldo25)(struct rtw_dev *rtwdev, bool enable);
905 void (*efuse_grant)(struct rtw_dev *rtwdev, bool enable);
906 void (*false_alarm_statistics)(struct rtw_dev *rtwdev);
907 void (*phy_calibration)(struct rtw_dev *rtwdev);
908 void (*dpk_track)(struct rtw_dev *rtwdev);
909 void (*cck_pd_set)(struct rtw_dev *rtwdev, u8 level);
910 void (*pwr_track)(struct rtw_dev *rtwdev);
911 void (*config_bfee)(struct rtw_dev *rtwdev, struct rtw_vif *vif,
912 struct rtw_bfee *bfee, bool enable);
913 void (*set_gid_table)(struct rtw_dev *rtwdev,
914 struct ieee80211_vif *vif,
915 struct ieee80211_bss_conf *conf);
916 void (*cfg_csi_rate)(struct rtw_dev *rtwdev, u8 rssi, u8 cur_rate,
917 u8 fixrate_en, u8 *new_rate);
918
919 /* for coex */
920 void (*coex_set_init)(struct rtw_dev *rtwdev);
921 void (*coex_set_ant_switch)(struct rtw_dev *rtwdev,
922 u8 ctrl_type, u8 pos_type);
923 void (*coex_set_gnt_fix)(struct rtw_dev *rtwdev);
924 void (*coex_set_gnt_debug)(struct rtw_dev *rtwdev);
925 void (*coex_set_rfe_type)(struct rtw_dev *rtwdev);
926 void (*coex_set_wl_tx_power)(struct rtw_dev *rtwdev, u8 wl_pwr);
927 void (*coex_set_wl_rx_gain)(struct rtw_dev *rtwdev, bool low_gain);
928};
929
930#define RTW_PWR_POLLING_CNT 20000
931
932#define RTW_PWR_CMD_READ 0x00
933#define RTW_PWR_CMD_WRITE 0x01
934#define RTW_PWR_CMD_POLLING 0x02
935#define RTW_PWR_CMD_DELAY 0x03
936#define RTW_PWR_CMD_END 0x04
937
938/* define the base address of each block */
939#define RTW_PWR_ADDR_MAC 0x00
940#define RTW_PWR_ADDR_USB 0x01
941#define RTW_PWR_ADDR_PCIE 0x02
942#define RTW_PWR_ADDR_SDIO 0x03
943
944#define RTW_PWR_INTF_SDIO_MSK BIT(0)
945#define RTW_PWR_INTF_USB_MSK BIT(1)
946#define RTW_PWR_INTF_PCI_MSK BIT(2)
947#define RTW_PWR_INTF_ALL_MSK (BIT(0) | BIT(1) | BIT(2) | BIT(3))
948
949#define RTW_PWR_CUT_TEST_MSK BIT(0)
950#define RTW_PWR_CUT_A_MSK BIT(1)
951#define RTW_PWR_CUT_B_MSK BIT(2)
952#define RTW_PWR_CUT_C_MSK BIT(3)
953#define RTW_PWR_CUT_D_MSK BIT(4)
954#define RTW_PWR_CUT_E_MSK BIT(5)
955#define RTW_PWR_CUT_F_MSK BIT(6)
956#define RTW_PWR_CUT_G_MSK BIT(7)
957#define RTW_PWR_CUT_ALL_MSK 0xFF
958
959enum rtw_pwr_seq_cmd_delay_unit {
960 RTW_PWR_DELAY_US,
961 RTW_PWR_DELAY_MS,
962};
963
964struct rtw_pwr_seq_cmd {
965 u16 offset;
966 u8 cut_mask;
967 u8 intf_mask;
968 u8 base:4;
969 u8 cmd:4;
970 u8 mask;
971 u8 value;
972};
973
974enum rtw_chip_ver {
975 RTW_CHIP_VER_CUT_A = 0x00,
976 RTW_CHIP_VER_CUT_B = 0x01,
977 RTW_CHIP_VER_CUT_C = 0x02,
978 RTW_CHIP_VER_CUT_D = 0x03,
979 RTW_CHIP_VER_CUT_E = 0x04,
980 RTW_CHIP_VER_CUT_F = 0x05,
981 RTW_CHIP_VER_CUT_G = 0x06,
982};
983
984#define RTW_INTF_PHY_PLATFORM_ALL 0
985
986enum rtw_intf_phy_cut {
987 RTW_INTF_PHY_CUT_A = BIT(0),
988 RTW_INTF_PHY_CUT_B = BIT(1),
989 RTW_INTF_PHY_CUT_C = BIT(2),
990 RTW_INTF_PHY_CUT_D = BIT(3),
991 RTW_INTF_PHY_CUT_E = BIT(4),
992 RTW_INTF_PHY_CUT_F = BIT(5),
993 RTW_INTF_PHY_CUT_G = BIT(6),
994 RTW_INTF_PHY_CUT_ALL = 0xFFFF,
995};
996
997enum rtw_ip_sel {
998 RTW_IP_SEL_PHY = 0,
999 RTW_IP_SEL_MAC = 1,
1000 RTW_IP_SEL_DBI = 2,
1001
1002 RTW_IP_SEL_UNDEF = 0xFFFF
1003};
1004
1005enum rtw_pq_map_id {
1006 RTW_PQ_MAP_VO = 0x0,
1007 RTW_PQ_MAP_VI = 0x1,
1008 RTW_PQ_MAP_BE = 0x2,
1009 RTW_PQ_MAP_BK = 0x3,
1010 RTW_PQ_MAP_MG = 0x4,
1011 RTW_PQ_MAP_HI = 0x5,
1012 RTW_PQ_MAP_NUM = 0x6,
1013
1014 RTW_PQ_MAP_UNDEF,
1015};
1016
1017enum rtw_dma_mapping {
1018 RTW_DMA_MAPPING_EXTRA = 0,
1019 RTW_DMA_MAPPING_LOW = 1,
1020 RTW_DMA_MAPPING_NORMAL = 2,
1021 RTW_DMA_MAPPING_HIGH = 3,
1022
1023 RTW_DMA_MAPPING_MAX,
1024 RTW_DMA_MAPPING_UNDEF,
1025};
1026
1027struct rtw_rqpn {
1028 enum rtw_dma_mapping dma_map_vo;
1029 enum rtw_dma_mapping dma_map_vi;
1030 enum rtw_dma_mapping dma_map_be;
1031 enum rtw_dma_mapping dma_map_bk;
1032 enum rtw_dma_mapping dma_map_mg;
1033 enum rtw_dma_mapping dma_map_hi;
1034};
1035
1036struct rtw_prioq_addr {
1037 u32 rsvd;
1038 u32 avail;
1039};
1040
1041struct rtw_prioq_addrs {
1042 struct rtw_prioq_addr prio[RTW_DMA_MAPPING_MAX];
1043 bool wsize;
1044};
1045
1046struct rtw_page_table {
1047 u16 hq_num;
1048 u16 nq_num;
1049 u16 lq_num;
1050 u16 exq_num;
1051 u16 gapq_num;
1052};
1053
1054struct rtw_intf_phy_para {
1055 u16 offset;
1056 u16 value;
1057 u16 ip_sel;
1058 u16 cut_mask;
1059 u16 platform;
1060};
1061
1062struct rtw_wow_pattern {
1063 u16 crc;
1064 u8 type;
1065 u8 valid;
1066 u8 mask[RTW_MAX_PATTERN_MASK_SIZE];
1067};
1068
1069struct rtw_pno_request {
1070 bool inited;
1071 u32 match_set_cnt;
1072 struct cfg80211_match_set *match_sets;
1073 u8 channel_cnt;
1074 struct ieee80211_channel *channels;
1075 struct cfg80211_sched_scan_plan scan_plan;
1076};
1077
1078struct rtw_wow_param {
1079 struct ieee80211_vif *wow_vif;
1080 DECLARE_BITMAP(flags, RTW_WOW_FLAG_MAX);
1081 u8 txpause;
1082 u8 pattern_cnt;
1083 struct rtw_wow_pattern patterns[RTW_MAX_PATTERN_NUM];
1084
1085 bool ips_enabled;
1086 struct rtw_pno_request pno_req;
1087};
1088
1089struct rtw_intf_phy_para_table {
1090 const struct rtw_intf_phy_para *usb2_para;
1091 const struct rtw_intf_phy_para *usb3_para;
1092 const struct rtw_intf_phy_para *gen1_para;
1093 const struct rtw_intf_phy_para *gen2_para;
1094 u8 n_usb2_para;
1095 u8 n_usb3_para;
1096 u8 n_gen1_para;
1097 u8 n_gen2_para;
1098};
1099
1100struct rtw_table {
1101 const void *data;
1102 const u32 size;
1103 void (*parse)(struct rtw_dev *rtwdev, const struct rtw_table *tbl);
1104 void (*do_cfg)(struct rtw_dev *rtwdev, const struct rtw_table *tbl,
1105 u32 addr, u32 data);
1106 enum rtw_rf_path rf_path;
1107};
1108
1109static inline void rtw_load_table(struct rtw_dev *rtwdev,
1110 const struct rtw_table *tbl)
1111{
1112 (*tbl->parse)(rtwdev, tbl);
1113}
1114
1115enum rtw_rfe_fem {
1116 RTW_RFE_IFEM,
1117 RTW_RFE_EFEM,
1118 RTW_RFE_IFEM2G_EFEM5G,
1119 RTW_RFE_NUM,
1120};
1121
1122struct rtw_rfe_def {
1123 const struct rtw_table *phy_pg_tbl;
1124 const struct rtw_table *txpwr_lmt_tbl;
1125 const struct rtw_table *agc_btg_tbl;
1126};
1127
1128#define RTW_DEF_RFE(chip, bb_pg, pwrlmt) { \
1129 .phy_pg_tbl = &rtw ## chip ## _bb_pg_type ## bb_pg ## _tbl, \
1130 .txpwr_lmt_tbl = &rtw ## chip ## _txpwr_lmt_type ## pwrlmt ## _tbl, \
1131 }
1132
1133#define RTW_DEF_RFE_EXT(chip, bb_pg, pwrlmt, btg) { \
1134 .phy_pg_tbl = &rtw ## chip ## _bb_pg_type ## bb_pg ## _tbl, \
1135 .txpwr_lmt_tbl = &rtw ## chip ## _txpwr_lmt_type ## pwrlmt ## _tbl, \
1136 .agc_btg_tbl = &rtw ## chip ## _agc_btg_type ## btg ## _tbl, \
1137 }
1138
1139#define RTW_PWR_TRK_5G_1 0
1140#define RTW_PWR_TRK_5G_2 1
1141#define RTW_PWR_TRK_5G_3 2
1142#define RTW_PWR_TRK_5G_NUM 3
1143
1144#define RTW_PWR_TRK_TBL_SZ 30
1145
1146/* This table stores the values of TX power that will be adjusted by power
1147 * tracking.
1148 *
1149 * For 5G bands, there are 3 different settings.
1150 * For 2G there are cck rate and ofdm rate with different settings.
1151 */
1152struct rtw_pwr_track_tbl {
1153 const u8 *pwrtrk_5gb_n[RTW_PWR_TRK_5G_NUM];
1154 const u8 *pwrtrk_5gb_p[RTW_PWR_TRK_5G_NUM];
1155 const u8 *pwrtrk_5ga_n[RTW_PWR_TRK_5G_NUM];
1156 const u8 *pwrtrk_5ga_p[RTW_PWR_TRK_5G_NUM];
1157 const u8 *pwrtrk_2gb_n;
1158 const u8 *pwrtrk_2gb_p;
1159 const u8 *pwrtrk_2ga_n;
1160 const u8 *pwrtrk_2ga_p;
1161 const u8 *pwrtrk_2g_cckb_n;
1162 const u8 *pwrtrk_2g_cckb_p;
1163 const u8 *pwrtrk_2g_ccka_n;
1164 const u8 *pwrtrk_2g_ccka_p;
1165 const s8 *pwrtrk_xtal_n;
1166 const s8 *pwrtrk_xtal_p;
1167};
1168
1169enum rtw_wlan_cpu {
1170 RTW_WCPU_11AC,
1171 RTW_WCPU_11N,
1172};
1173
1174enum rtw_fw_fifo_sel {
1175 RTW_FW_FIFO_SEL_TX,
1176 RTW_FW_FIFO_SEL_RX,
1177 RTW_FW_FIFO_SEL_RSVD_PAGE,
1178 RTW_FW_FIFO_SEL_REPORT,
1179 RTW_FW_FIFO_SEL_LLT,
1180 RTW_FW_FIFO_SEL_RXBUF_FW,
1181
1182 RTW_FW_FIFO_MAX,
1183};
1184
1185/* hardware configuration for each IC */
1186struct rtw_chip_info {
1187 struct rtw_chip_ops *ops;
1188 u8 id;
1189
1190 const char *fw_name;
1191 enum rtw_wlan_cpu wlan_cpu;
1192 u8 tx_pkt_desc_sz;
1193 u8 tx_buf_desc_sz;
1194 u8 rx_pkt_desc_sz;
1195 u8 rx_buf_desc_sz;
1196 u32 phy_efuse_size;
1197 u32 log_efuse_size;
1198 u32 ptct_efuse_size;
1199 u32 txff_size;
1200 u32 rxff_size;
1201 u32 fw_rxff_size;
1202 u8 band;
1203 u8 page_size;
1204 u8 csi_buf_pg_num;
1205 u8 dig_max;
1206 u8 dig_min;
1207 u8 txgi_factor;
1208 bool is_pwr_by_rate_dec;
1209 bool rx_ldpc;
1210 u8 max_power_index;
1211
1212 u16 fw_fifo_addr[RTW_FW_FIFO_MAX];
1213
1214 bool ht_supported;
1215 bool vht_supported;
1216 u8 lps_deep_mode_supported;
1217
1218 /* init values */
1219 u8 sys_func_en;
1220 const struct rtw_pwr_seq_cmd **pwr_on_seq;
1221 const struct rtw_pwr_seq_cmd **pwr_off_seq;
1222 const struct rtw_rqpn *rqpn_table;
1223 const struct rtw_prioq_addrs *prioq_addrs;
1224 const struct rtw_page_table *page_table;
1225 const struct rtw_intf_phy_para_table *intf_table;
1226
1227 const struct rtw_hw_reg *dig;
1228 const struct rtw_hw_reg *dig_cck;
1229 u32 rf_base_addr[2];
1230 u32 rf_sipi_addr[2];
1231 const struct rtw_rf_sipi_addr *rf_sipi_read_addr;
1232 u8 fix_rf_phy_num;
1233 const struct rtw_ltecoex_addr *ltecoex_addr;
1234
1235 const struct rtw_table *mac_tbl;
1236 const struct rtw_table *agc_tbl;
1237 const struct rtw_table *bb_tbl;
1238 const struct rtw_table *rf_tbl[RTW_RF_PATH_MAX];
1239 const struct rtw_table *rfk_init_tbl;
1240
1241 const struct rtw_rfe_def *rfe_defs;
1242 u32 rfe_defs_size;
1243
1244 bool en_dis_dpd;
1245 u16 dpd_ratemask;
1246 u8 iqk_threshold;
1247 const struct rtw_pwr_track_tbl *pwr_track_tbl;
1248
1249 u8 bfer_su_max_num;
1250 u8 bfer_mu_max_num;
1251
1252 const char *wow_fw_name;
1253 const struct wiphy_wowlan_support *wowlan_stub;
1254 const u8 max_sched_scan_ssids;
1255
1256 /* for 8821c set channel */
1257 u32 ch_param[3];
1258
1259 /* coex paras */
1260 u32 coex_para_ver;
1261 u8 bt_desired_ver;
1262 bool scbd_support;
1263 bool new_scbd10_def; /* true: fix 2M(8822c) */
1264 bool ble_hid_profile_support;
1265 u8 pstdma_type; /* 0: LPSoff, 1:LPSon */
1266 u8 bt_rssi_type;
1267 u8 ant_isolation;
1268 u8 rssi_tolerance;
1269 u8 table_sant_num;
1270 u8 table_nsant_num;
1271 u8 tdma_sant_num;
1272 u8 tdma_nsant_num;
1273 u8 bt_afh_span_bw20;
1274 u8 bt_afh_span_bw40;
1275 u8 afh_5g_num;
1276 u8 wl_rf_para_num;
1277 u8 coex_info_hw_regs_num;
1278 const u8 *bt_rssi_step;
1279 const u8 *wl_rssi_step;
1280 const struct coex_table_para *table_nsant;
1281 const struct coex_table_para *table_sant;
1282 const struct coex_tdma_para *tdma_sant;
1283 const struct coex_tdma_para *tdma_nsant;
1284 const struct coex_rf_para *wl_rf_para_tx;
1285 const struct coex_rf_para *wl_rf_para_rx;
1286 const struct coex_5g_afh_map *afh_5g;
1287 const struct rtw_hw_reg *btg_reg;
1288 const struct rtw_reg_domain *coex_info_hw_regs;
1289 u32 wl_fw_desired_ver;
1290};
1291
1292enum rtw_coex_bt_state_cnt {
1293 COEX_CNT_BT_RETRY,
1294 COEX_CNT_BT_REINIT,
1295 COEX_CNT_BT_REENABLE,
1296 COEX_CNT_BT_POPEVENT,
1297 COEX_CNT_BT_SETUPLINK,
1298 COEX_CNT_BT_IGNWLANACT,
1299 COEX_CNT_BT_INQ,
1300 COEX_CNT_BT_PAGE,
1301 COEX_CNT_BT_ROLESWITCH,
1302 COEX_CNT_BT_AFHUPDATE,
1303 COEX_CNT_BT_INFOUPDATE,
1304 COEX_CNT_BT_IQK,
1305 COEX_CNT_BT_IQKFAIL,
1306
1307 COEX_CNT_BT_MAX
1308};
1309
1310enum rtw_coex_wl_state_cnt {
1311 COEX_CNT_WL_SCANAP,
1312 COEX_CNT_WL_CONNPKT,
1313 COEX_CNT_WL_COEXRUN,
1314 COEX_CNT_WL_NOISY0,
1315 COEX_CNT_WL_NOISY1,
1316 COEX_CNT_WL_NOISY2,
1317 COEX_CNT_WL_5MS_NOEXTEND,
1318 COEX_CNT_WL_FW_NOTIFY,
1319
1320 COEX_CNT_WL_MAX
1321};
1322
1323struct rtw_coex_rfe {
1324 bool ant_switch_exist;
1325 bool ant_switch_diversity;
1326 bool ant_switch_with_bt;
1327 u8 rfe_module_type;
1328 u8 ant_switch_polarity;
1329
1330 /* true if WLG at BTG, else at WLAG */
1331 bool wlg_at_btg;
1332};
1333
1334#define COEX_WL_TDMA_PARA_LENGTH 5
1335
1336struct rtw_coex_dm {
1337 bool cur_ps_tdma_on;
1338 bool cur_wl_rx_low_gain_en;
1339 bool ignore_wl_act;
1340
1341 u8 reason;
1342 u8 bt_rssi_state[4];
1343 u8 wl_rssi_state[4];
1344 u8 wl_ch_info[3];
1345 u8 cur_ps_tdma;
1346 u8 cur_table;
1347 u8 ps_tdma_para[5];
1348 u8 cur_bt_pwr_lvl;
1349 u8 cur_bt_lna_lvl;
1350 u8 cur_wl_pwr_lvl;
1351 u8 bt_status;
1352 u32 cur_ant_pos_type;
1353 u32 cur_switch_status;
1354 u32 setting_tdma;
1355 u8 fw_tdma_para[COEX_WL_TDMA_PARA_LENGTH];
1356};
1357
1358#define COEX_BTINFO_SRC_WL_FW 0x0
1359#define COEX_BTINFO_SRC_BT_RSP 0x1
1360#define COEX_BTINFO_SRC_BT_ACT 0x2
1361#define COEX_BTINFO_SRC_BT_IQK 0x3
1362#define COEX_BTINFO_SRC_BT_SCBD 0x4
1363#define COEX_BTINFO_SRC_H2C60 0x5
1364#define COEX_BTINFO_SRC_MAX 0x6
1365
1366#define COEX_INFO_FTP BIT(7)
1367#define COEX_INFO_A2DP BIT(6)
1368#define COEX_INFO_HID BIT(5)
1369#define COEX_INFO_SCO_BUSY BIT(4)
1370#define COEX_INFO_ACL_BUSY BIT(3)
1371#define COEX_INFO_INQ_PAGE BIT(2)
1372#define COEX_INFO_SCO_ESCO BIT(1)
1373#define COEX_INFO_CONNECTION BIT(0)
1374#define COEX_BTINFO_LENGTH_MAX 10
1375#define COEX_BTINFO_LENGTH 7
1376
1377struct rtw_coex_stat {
1378 bool bt_disabled;
1379 bool bt_disabled_pre;
1380 bool bt_link_exist;
1381 bool bt_whck_test;
1382 bool bt_inq_page;
1383 bool bt_inq_remain;
1384 bool bt_inq;
1385 bool bt_page;
1386 bool bt_ble_voice;
1387 bool bt_ble_exist;
1388 bool bt_hfp_exist;
1389 bool bt_a2dp_exist;
1390 bool bt_hid_exist;
1391 bool bt_pan_exist; /* PAN or OPP */
1392 bool bt_opp_exist; /* OPP only */
1393 bool bt_acl_busy;
1394 bool bt_fix_2M;
1395 bool bt_setup_link;
1396 bool bt_multi_link;
1397 bool bt_multi_link_pre;
1398 bool bt_multi_link_remain;
1399 bool bt_a2dp_sink;
1400 bool bt_a2dp_active;
1401 bool bt_reenable;
1402 bool bt_ble_scan_en;
1403 bool bt_init_scan;
1404 bool bt_slave;
1405 bool bt_418_hid_exist;
1406 bool bt_ble_hid_exist;
1407 bool bt_mailbox_reply;
1408
1409 bool wl_under_lps;
1410 bool wl_under_ips;
1411 bool wl_hi_pri_task1;
1412 bool wl_hi_pri_task2;
1413 bool wl_force_lps_ctrl;
1414 bool wl_gl_busy;
1415 bool wl_linkscan_proc;
1416 bool wl_ps_state_fail;
1417 bool wl_tx_limit_en;
1418 bool wl_ampdu_limit_en;
1419 bool wl_connected;
1420 bool wl_slot_extend;
1421 bool wl_cck_lock;
1422 bool wl_cck_lock_pre;
1423 bool wl_cck_lock_ever;
1424 bool wl_connecting;
1425 bool wl_slot_toggle;
1426 bool wl_slot_toggle_change; /* if toggle to no-toggle */
1427
1428 u32 bt_supported_version;
1429 u32 bt_supported_feature;
1430 u32 hi_pri_tx;
1431 u32 hi_pri_rx;
1432 u32 lo_pri_tx;
1433 u32 lo_pri_rx;
1434 u32 patch_ver;
1435 u16 bt_reg_vendor_ae;
1436 u16 bt_reg_vendor_ac;
1437 s8 bt_rssi;
1438 u8 kt_ver;
1439 u8 gnt_workaround_state;
1440 u8 tdma_timer_base;
1441 u8 bt_profile_num;
1442 u8 bt_info_c2h[COEX_BTINFO_SRC_MAX][COEX_BTINFO_LENGTH_MAX];
1443 u8 bt_info_lb2;
1444 u8 bt_info_lb3;
1445 u8 bt_info_hb0;
1446 u8 bt_info_hb1;
1447 u8 bt_info_hb2;
1448 u8 bt_info_hb3;
1449 u8 bt_ble_scan_type;
1450 u8 bt_hid_pair_num;
1451 u8 bt_hid_slot;
1452 u8 bt_a2dp_bitpool;
1453 u8 bt_iqk_state;
1454
1455 u16 wl_beacon_interval;
1456 u8 wl_noisy_level;
1457 u8 wl_fw_dbg_info[10];
1458 u8 wl_fw_dbg_info_pre[10];
1459 u8 wl_rx_rate;
1460 u8 wl_tx_rate;
1461 u8 wl_rts_rx_rate;
1462 u8 wl_coex_mode;
1463 u8 wl_iot_peer;
1464 u8 ampdu_max_time;
1465 u8 wl_tput_dir;
1466
1467 u8 wl_toggle_para[6];
1468 u8 wl_toggle_interval;
1469
1470 u16 score_board;
1471 u16 retry_limit;
1472
1473 /* counters to record bt states */
1474 u32 cnt_bt[COEX_CNT_BT_MAX];
1475
1476 /* counters to record wifi states */
1477 u32 cnt_wl[COEX_CNT_WL_MAX];
1478
1479 /* counters to record bt c2h data */
1480 u32 cnt_bt_info_c2h[COEX_BTINFO_SRC_MAX];
1481
1482 u32 darfrc;
1483 u32 darfrch;
1484};
1485
1486struct rtw_coex {
1487 /* protects coex info request section */
1488 struct mutex mutex;
1489 struct sk_buff_head queue;
1490 wait_queue_head_t wait;
1491
1492 bool under_5g;
1493 bool stop_dm;
1494 bool freeze;
1495 bool freerun;
1496 bool wl_rf_off;
1497 bool manual_control;
1498
1499 struct rtw_coex_stat stat;
1500 struct rtw_coex_dm dm;
1501 struct rtw_coex_rfe rfe;
1502
1503 struct delayed_work bt_relink_work;
1504 struct delayed_work bt_reenable_work;
1505 struct delayed_work defreeze_work;
1506 struct delayed_work wl_remain_work;
1507 struct delayed_work bt_remain_work;
1508 struct delayed_work wl_connecting_work;
1509 struct delayed_work bt_multi_link_remain_work;
1510 struct delayed_work wl_ccklock_work;
1511
1512};
1513
1514#define DPK_RF_REG_NUM 7
1515#define DPK_RF_PATH_NUM 2
1516#define DPK_BB_REG_NUM 18
1517#define DPK_CHANNEL_WIDTH_80 1
1518
1519DECLARE_EWMA(thermal, 10, 4);
1520
1521struct rtw_dpk_info {
1522 bool is_dpk_pwr_on;
1523 bool is_reload;
1524
1525 DECLARE_BITMAP(dpk_path_ok, DPK_RF_PATH_NUM);
1526
1527 u8 thermal_dpk[DPK_RF_PATH_NUM];
1528 struct ewma_thermal avg_thermal[DPK_RF_PATH_NUM];
1529
1530 u32 gnt_control;
1531 u32 gnt_value;
1532
1533 u8 result[RTW_RF_PATH_MAX];
1534 u8 dpk_txagc[RTW_RF_PATH_MAX];
1535 u32 coef[RTW_RF_PATH_MAX][20];
1536 u16 dpk_gs[RTW_RF_PATH_MAX];
1537 u8 thermal_dpk_delta[RTW_RF_PATH_MAX];
1538 u8 pre_pwsf[RTW_RF_PATH_MAX];
1539
1540 u8 dpk_band;
1541 u8 dpk_ch;
1542 u8 dpk_bw;
1543};
1544
1545struct rtw_phy_cck_pd_reg {
1546 u32 reg_pd;
1547 u32 mask_pd;
1548 u32 reg_cs;
1549 u32 mask_cs;
1550};
1551
1552#define DACK_MSBK_BACKUP_NUM 0xf
1553#define DACK_DCK_BACKUP_NUM 0x2
1554
1555struct rtw_swing_table {
1556 const u8 *p[RTW_RF_PATH_MAX];
1557 const u8 *n[RTW_RF_PATH_MAX];
1558};
1559
1560struct rtw_pkt_count {
1561 u16 num_bcn_pkt;
1562 u16 num_qry_pkt[DESC_RATE_MAX];
1563};
1564
1565DECLARE_EWMA(evm, 10, 4);
1566DECLARE_EWMA(snr, 10, 4);
1567
1568struct rtw_iqk_info {
1569 bool done;
1570 struct {
1571 u32 s1_x;
1572 u32 s1_y;
1573 u32 s0_x;
1574 u32 s0_y;
1575 } result;
1576};
1577
1578#define RRSR_INIT_2G 0x15f
1579#define RRSR_INIT_5G 0x150
1580
1581struct rtw_dm_info {
1582 u32 cck_fa_cnt;
1583 u32 ofdm_fa_cnt;
1584 u32 total_fa_cnt;
1585 u32 cck_cca_cnt;
1586 u32 ofdm_cca_cnt;
1587 u32 total_cca_cnt;
1588
1589 u32 cck_ok_cnt;
1590 u32 cck_err_cnt;
1591 u32 ofdm_ok_cnt;
1592 u32 ofdm_err_cnt;
1593 u32 ht_ok_cnt;
1594 u32 ht_err_cnt;
1595 u32 vht_ok_cnt;
1596 u32 vht_err_cnt;
1597
1598 u8 min_rssi;
1599 u8 pre_min_rssi;
1600 u16 fa_history[4];
1601 u8 igi_history[4];
1602 u8 igi_bitmap;
1603 bool damping;
1604 u8 damping_cnt;
1605 u8 damping_rssi;
1606
1607 u8 cck_gi_u_bnd;
1608 u8 cck_gi_l_bnd;
1609
1610 u8 tx_rate;
1611 u32 rrsr_val_init;
1612 u32 rrsr_mask_min;
1613 u8 thermal_avg[RTW_RF_PATH_MAX];
1614 u8 thermal_meter_k;
1615 s8 delta_power_index[RTW_RF_PATH_MAX];
1616 s8 delta_power_index_last[RTW_RF_PATH_MAX];
1617 u8 default_ofdm_index;
1618 bool pwr_trk_triggered;
1619 bool pwr_trk_init_trigger;
1620 struct ewma_thermal avg_thermal[RTW_RF_PATH_MAX];
1621 s8 txagc_remnant_cck;
1622 s8 txagc_remnant_ofdm;
1623
1624 /* backup dack results for each path and I/Q */
1625 u32 dack_adck[RTW_RF_PATH_MAX];
1626 u16 dack_msbk[RTW_RF_PATH_MAX][2][DACK_MSBK_BACKUP_NUM];
1627 u8 dack_dck[RTW_RF_PATH_MAX][2][DACK_DCK_BACKUP_NUM];
1628
1629 struct rtw_dpk_info dpk_info;
1630
1631 /* [bandwidth 0:20M/1:40M][number of path] */
1632 u8 cck_pd_lv[2][RTW_RF_PATH_MAX];
1633 u32 cck_fa_avg;
1634 u8 cck_pd_default;
1635
1636 /* save the last rx phy status for debug */
1637 s8 rx_snr[RTW_RF_PATH_MAX];
1638 u8 rx_evm_dbm[RTW_RF_PATH_MAX];
1639 s16 cfo_tail[RTW_RF_PATH_MAX];
1640 u8 rssi[RTW_RF_PATH_MAX];
1641 u8 curr_rx_rate;
1642 struct rtw_pkt_count cur_pkt_count;
1643 struct rtw_pkt_count last_pkt_count;
1644 struct ewma_evm ewma_evm[RTW_EVM_NUM];
1645 struct ewma_snr ewma_snr[RTW_SNR_NUM];
1646
1647 struct rtw_iqk_info iqk;
1648};
1649
1650struct rtw_efuse {
1651 u32 size;
1652 u32 physical_size;
1653 u32 logical_size;
1654 u32 protect_size;
1655
1656 u8 addr[ETH_ALEN];
1657 u8 channel_plan;
1658 u8 country_code[2];
1659 u8 rf_board_option;
1660 u8 rfe_option;
1661 u8 power_track_type;
1662 u8 thermal_meter[RTW_RF_PATH_MAX];
1663 u8 thermal_meter_k;
1664 u8 crystal_cap;
1665 u8 ant_div_cfg;
1666 u8 ant_div_type;
1667 u8 regd;
1668 u8 afe;
1669
1670 u8 lna_type_2g;
1671 u8 lna_type_5g;
1672 u8 glna_type;
1673 u8 alna_type;
1674 bool ext_lna_2g;
1675 bool ext_lna_5g;
1676 u8 pa_type_2g;
1677 u8 pa_type_5g;
1678 u8 gpa_type;
1679 u8 apa_type;
1680 bool ext_pa_2g;
1681 bool ext_pa_5g;
1682 u8 tx_bb_swing_setting_2g;
1683 u8 tx_bb_swing_setting_5g;
1684
1685 bool btcoex;
1686 /* bt share antenna with wifi */
1687 bool share_ant;
1688 u8 bt_setting;
1689
1690 struct {
1691 u8 hci;
1692 u8 bw;
1693 u8 ptcl;
1694 u8 nss;
1695 u8 ant_num;
1696 } hw_cap;
1697
1698 struct rtw_txpwr_idx txpwr_idx_table[4];
1699};
1700
1701struct rtw_phy_cond {
1702#ifdef __LITTLE_ENDIAN
1703 u32 rfe:8;
1704 u32 intf:4;
1705 u32 pkg:4;
1706 u32 plat:4;
1707 u32 intf_rsvd:4;
1708 u32 cut:4;
1709 u32 branch:2;
1710 u32 neg:1;
1711 u32 pos:1;
1712#else
1713 u32 pos:1;
1714 u32 neg:1;
1715 u32 branch:2;
1716 u32 cut:4;
1717 u32 intf_rsvd:4;
1718 u32 plat:4;
1719 u32 pkg:4;
1720 u32 intf:4;
1721 u32 rfe:8;
1722#endif
1723 /* for intf:4 */
1724 #define INTF_PCIE BIT(0)
1725 #define INTF_USB BIT(1)
1726 #define INTF_SDIO BIT(2)
1727 /* for branch:2 */
1728 #define BRANCH_IF 0
1729 #define BRANCH_ELIF 1
1730 #define BRANCH_ELSE 2
1731 #define BRANCH_ENDIF 3
1732};
1733
1734struct rtw_fifo_conf {
1735 /* tx fifo information */
1736 u16 rsvd_boundary;
1737 u16 rsvd_pg_num;
1738 u16 rsvd_drv_pg_num;
1739 u16 txff_pg_num;
1740 u16 acq_pg_num;
1741 u16 rsvd_drv_addr;
1742 u16 rsvd_h2c_info_addr;
1743 u16 rsvd_h2c_sta_info_addr;
1744 u16 rsvd_h2cq_addr;
1745 u16 rsvd_cpu_instr_addr;
1746 u16 rsvd_fw_txbuf_addr;
1747 u16 rsvd_csibuf_addr;
1748 const struct rtw_rqpn *rqpn;
1749};
1750
1751#define FW_CD_TYPE 0xffff
1752#define FW_CD_LEN 4
1753#define FW_CD_VAL 0xaabbccdd
1754struct rtw_fw_state {
1755 const struct firmware *firmware;
1756 struct rtw_dev *rtwdev;
1757 struct completion completion;
1758 u16 version;
1759 u8 sub_version;
1760 u8 sub_index;
1761 u16 h2c_version;
1762 u8 prev_dump_seq;
1763 u32 feature;
1764};
1765
1766struct rtw_hal {
1767 u32 rcr;
1768
1769 u32 chip_version;
1770 u8 cut_version;
1771 u8 mp_chip;
1772 u8 oem_id;
1773 struct rtw_phy_cond phy_cond;
1774
1775 u8 ps_mode;
1776 u8 current_channel;
1777 u8 current_band_width;
1778 u8 current_band_type;
1779
1780 /* center channel for different available bandwidth,
1781 * val of (bw > current_band_width) is invalid
1782 */
1783 u8 cch_by_bw[RTW_MAX_CHANNEL_WIDTH + 1];
1784
1785 u8 sec_ch_offset;
1786 u8 rf_type;
1787 u8 rf_path_num;
1788 u8 rf_phy_num;
1789 u32 antenna_tx;
1790 u32 antenna_rx;
1791 u8 bfee_sts_cap;
1792
1793 /* protect tx power section */
1794 struct mutex tx_power_mutex;
1795 s8 tx_pwr_by_rate_offset_2g[RTW_RF_PATH_MAX]
1796 [DESC_RATE_MAX];
1797 s8 tx_pwr_by_rate_offset_5g[RTW_RF_PATH_MAX]
1798 [DESC_RATE_MAX];
1799 s8 tx_pwr_by_rate_base_2g[RTW_RF_PATH_MAX]
1800 [RTW_RATE_SECTION_MAX];
1801 s8 tx_pwr_by_rate_base_5g[RTW_RF_PATH_MAX]
1802 [RTW_RATE_SECTION_MAX];
1803 s8 tx_pwr_limit_2g[RTW_REGD_MAX]
1804 [RTW_CHANNEL_WIDTH_MAX]
1805 [RTW_RATE_SECTION_MAX]
1806 [RTW_MAX_CHANNEL_NUM_2G];
1807 s8 tx_pwr_limit_5g[RTW_REGD_MAX]
1808 [RTW_CHANNEL_WIDTH_MAX]
1809 [RTW_RATE_SECTION_MAX]
1810 [RTW_MAX_CHANNEL_NUM_5G];
1811 s8 tx_pwr_tbl[RTW_RF_PATH_MAX]
1812 [DESC_RATE_MAX];
1813};
1814
1815struct rtw_dev {
1816 struct ieee80211_hw *hw;
1817 struct device *dev;
1818
1819 struct rtw_hci hci;
1820
1821 struct rtw_chip_info *chip;
1822 struct rtw_hal hal;
1823 struct rtw_fifo_conf fifo;
1824 struct rtw_fw_state fw;
1825 struct rtw_efuse efuse;
1826 struct rtw_sec_desc sec;
1827 struct rtw_traffic_stats stats;
1828 struct rtw_regulatory regd;
1829 struct rtw_bf_info bf_info;
1830
1831 struct rtw_dm_info dm_info;
1832 struct rtw_coex coex;
1833
1834 /* ensures exclusive access from mac80211 callbacks */
1835 struct mutex mutex;
1836
1837 /* read/write rf register */
1838 spinlock_t rf_lock;
1839
1840 /* watch dog every 2 sec */
1841 struct delayed_work watch_dog_work;
1842 u32 watch_dog_cnt;
1843
1844 struct list_head rsvd_page_list;
1845
1846 /* c2h cmd queue & handler work */
1847 struct sk_buff_head c2h_queue;
1848 struct work_struct c2h_work;
1849 struct work_struct fw_recovery_work;
1850
1851 /* used to protect txqs list */
1852 spinlock_t txq_lock;
1853 struct list_head txqs;
1854 struct workqueue_struct *tx_wq;
1855 struct work_struct tx_work;
1856 struct work_struct ba_work;
1857
1858 struct rtw_tx_report tx_report;
1859
1860 struct {
1861 /* incicate the mail box to use with fw */
1862 u8 last_box_num;
1863 /* protect to send h2c to fw */
1864 spinlock_t lock;
1865 u32 seq;
1866 } h2c;
1867
1868 /* lps power state & handler work */
1869 struct rtw_lps_conf lps_conf;
1870 bool ps_enabled;
1871 struct completion lps_leave_check;
1872
1873 struct dentry *debugfs;
1874
1875 u8 sta_cnt;
1876 u32 rts_threshold;
1877
1878 DECLARE_BITMAP(mac_id_map, RTW_MAX_MAC_ID_NUM);
1879 DECLARE_BITMAP(flags, NUM_OF_RTW_FLAGS);
1880
1881 u8 mp_mode;
1882
1883 struct rtw_fw_state wow_fw;
1884 struct rtw_wow_param wow;
1885
1886 bool need_rfk;
1887
1888 /* hci related data, must be last */
1889 u8 priv[] __aligned(sizeof(void *));
1890};
1891
1892#include "hci.h"
1893
1894static inline bool rtw_is_assoc(struct rtw_dev *rtwdev)
1895{
1896 return !!rtwdev->sta_cnt;
1897}
1898
1899static inline struct ieee80211_txq *rtwtxq_to_txq(struct rtw_txq *rtwtxq)
1900{
1901 void *p = rtwtxq;
1902
1903 return container_of(p, struct ieee80211_txq, drv_priv);
1904}
1905
1906static inline struct ieee80211_vif *rtwvif_to_vif(struct rtw_vif *rtwvif)
1907{
1908 void *p = rtwvif;
1909
1910 return container_of(p, struct ieee80211_vif, drv_priv);
1911}
1912
1913static inline bool rtw_ssid_equal(struct cfg80211_ssid *a,
1914 struct cfg80211_ssid *b)
1915{
1916 if (!a || !b || a->ssid_len != b->ssid_len)
1917 return false;
1918
1919 if (memcmp(a->ssid, b->ssid, a->ssid_len))
1920 return false;
1921
1922 return true;
1923}
1924
1925static inline void rtw_chip_efuse_grant_on(struct rtw_dev *rtwdev)
1926{
1927 if (rtwdev->chip->ops->efuse_grant)
1928 rtwdev->chip->ops->efuse_grant(rtwdev, true);
1929}
1930
1931static inline void rtw_chip_efuse_grant_off(struct rtw_dev *rtwdev)
1932{
1933 if (rtwdev->chip->ops->efuse_grant)
1934 rtwdev->chip->ops->efuse_grant(rtwdev, false);
1935}
1936
1937static inline bool rtw_chip_wcpu_11n(struct rtw_dev *rtwdev)
1938{
1939 return rtwdev->chip->wlan_cpu == RTW_WCPU_11N;
1940}
1941
1942static inline bool rtw_chip_wcpu_11ac(struct rtw_dev *rtwdev)
1943{
1944 return rtwdev->chip->wlan_cpu == RTW_WCPU_11AC;
1945}
1946
1947static inline bool rtw_chip_has_rx_ldpc(struct rtw_dev *rtwdev)
1948{
1949 return rtwdev->chip->rx_ldpc;
1950}
1951
1952static inline void rtw_release_macid(struct rtw_dev *rtwdev, u8 mac_id)
1953{
1954 clear_bit(mac_id, rtwdev->mac_id_map);
1955}
1956
1957void rtw_get_channel_params(struct cfg80211_chan_def *chandef,
1958 struct rtw_channel_params *ch_param);
1959bool check_hw_ready(struct rtw_dev *rtwdev, u32 addr, u32 mask, u32 target);
1960bool ltecoex_read_reg(struct rtw_dev *rtwdev, u16 offset, u32 *val);
1961bool ltecoex_reg_write(struct rtw_dev *rtwdev, u16 offset, u32 value);
1962void rtw_restore_reg(struct rtw_dev *rtwdev,
1963 struct rtw_backup_info *bckp, u32 num);
1964void rtw_desc_to_mcsrate(u16 rate, u8 *mcs, u8 *nss);
1965void rtw_set_channel(struct rtw_dev *rtwdev);
1966void rtw_chip_prepare_tx(struct rtw_dev *rtwdev);
1967void rtw_vif_port_config(struct rtw_dev *rtwdev, struct rtw_vif *rtwvif,
1968 u32 config);
1969#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 14, 0)
1970void rtw_tx_report_purge_timer(void *ctx);
1971#else
1972void rtw_tx_report_purge_timer(struct timer_list *t);
1973#endif
1974void rtw_update_sta_info(struct rtw_dev *rtwdev, struct rtw_sta_info *si);
1975int rtw_core_start(struct rtw_dev *rtwdev);
1976void rtw_core_stop(struct rtw_dev *rtwdev);
1977int rtw_chip_info_setup(struct rtw_dev *rtwdev);
1978int rtw_core_init(struct rtw_dev *rtwdev);
1979void rtw_core_deinit(struct rtw_dev *rtwdev);
1980int rtw_register_hw(struct rtw_dev *rtwdev, struct ieee80211_hw *hw);
1981void rtw_unregister_hw(struct rtw_dev *rtwdev, struct ieee80211_hw *hw);
1982u16 rtw_desc_to_bitrate(u8 desc_rate);
1983void rtw_vif_assoc_changed(struct rtw_vif *rtwvif,
1984 struct ieee80211_bss_conf *conf);
1985int rtw_sta_add(struct rtw_dev *rtwdev, struct ieee80211_sta *sta,
1986 struct ieee80211_vif *vif);
1987void rtw_sta_remove(struct rtw_dev *rtwdev, struct ieee80211_sta *sta,
1988 bool fw_exist);
1989void rtw_fw_recovery(struct rtw_dev *rtwdev);
1990
1991#endif