1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3 * nxpwifi: main data structures and prototypes
4 *
5 * Copyright 2011-2024 NXP
6 */
7
8 #ifndef _NXPWIFI_MAIN_H_
9 #define _NXPWIFI_MAIN_H_
10
11 #include <linux/completion.h>
12 #include <linux/kernel.h>
13 #include <linux/kstrtox.h>
14 #include <linux/module.h>
15 #include <linux/sched.h>
16 #include <linux/ip.h>
17 #include <linux/skbuff.h>
18 #include <linux/if_arp.h>
19 #include <linux/etherdevice.h>
20 #include <net/sock.h>
21 #include <linux/vmalloc.h>
22 #include <linux/firmware.h>
23 #include <linux/ctype.h>
24 #include <linux/of.h>
25 #include <linux/xarray.h>
26 #include <linux/inetdevice.h>
27 #include <linux/devcoredump.h>
28 #include <linux/err.h>
29 #include <linux/gfp.h>
30 #include <linux/interrupt.h>
31 #include <linux/io.h>
32 #include <linux/of_platform.h>
33 #include <linux/platform_device.h>
34 #include <linux/pm_runtime.h>
35 #include <linux/slab.h>
36 #include <linux/of_irq.h>
37 #include <linux/workqueue.h>
38 #include <net/ieee80211_radiotap.h>
39
40 #include "cfg.h"
41 #include "util.h"
42 #include "fw.h"
43 #include "sdio.h"
44
45 extern char nxpwifi_driver_version[];
46
47 struct nxpwifi_adapter;
48 struct nxpwifi_private;
49
50 /* command type */
51 enum {
52 NXPWIFI_ASYNC_CMD,
53 NXPWIFI_SYNC_CMD
54 };
55
56 #define NXPWIFI_MAX_AP 64
57
58 #define NXPWIFI_MAX_PKTS_TXQ 16
59
60 #define NXPWIFI_DEFAULT_WATCHDOG_TIMEOUT (5 * HZ)
61
62 #define NXPWIFI_TIMER_10S 10000
63 #define NXPWIFI_TIMER_1S 1000
64
65 #define MAX_TX_PENDING 400
66 #define LOW_TX_PENDING 380
67
68 #define HIGH_RX_PENDING 50
69 #define LOW_RX_PENDING 20
70
71 #define NXPWIFI_UPLD_SIZE (2312)
72
73 #define MAX_EVENT_SIZE 2048
74
75 #define NXPWIFI_FW_DUMP_SIZE (2 * 1024 * 1024)
76
77 #define ARP_FILTER_MAX_BUF_SIZE 68
78
79 #define NXPWIFI_KEY_BUFFER_SIZE 16
80 #define NXPWIFI_DEFAULT_LISTEN_INTERVAL 10
81 #define NXPWIFI_MAX_REGION_CODE 9
82
83 #define DEFAULT_BCN_AVG_FACTOR 8
84 #define DEFAULT_DATA_AVG_FACTOR 8
85
86 #define FIRST_VALID_CHANNEL 0xff
87
88 #define DEFAULT_BCN_MISS_TIMEOUT 5
89
90 #define MAX_SCAN_BEACON_BUFFER 8000
91
92 #define SCAN_BEACON_ENTRY_PAD 6
93
94 #define NXPWIFI_PASSIVE_SCAN_CHAN_TIME 110
95 #define NXPWIFI_ACTIVE_SCAN_CHAN_TIME 40
96 #define NXPWIFI_SPECIFIC_SCAN_CHAN_TIME 40
97 #define NXPWIFI_DEF_SCAN_CHAN_GAP_TIME 50
98
99 #define SCAN_RSSI(RSSI) (0x100 - ((u8)(RSSI)))
100
101 #define NXPWIFI_MAX_TOTAL_SCAN_TIME (NXPWIFI_TIMER_10S - NXPWIFI_TIMER_1S)
102
103 #define WPA_GTK_OUI_OFFSET 2
104 #define RSN_GTK_OUI_OFFSET 2
105
106 #define NXPWIFI_OUI_NOT_PRESENT 0
107 #define NXPWIFI_OUI_PRESENT 1
108
109 #define PKT_TYPE_MGMT 0xE5
110 #define PKT_TYPE_802DOT11 0x05
111 /* check if any data / resp / event is received from card */
112 #define IS_CARD_RX_RCVD(adapter) ({ \
113 typeof(adapter) (_adapter) = adapter; \
114 ((_adapter)->cmd_resp_received || \
115 (_adapter)->event_received || \
116 (_adapter)->data_received); \
117 })
118
119 #define NXPWIFI_TYPE_DATA 0
120 #define NXPWIFI_TYPE_CMD 1
121 #define NXPWIFI_TYPE_EVENT 3
122 #define NXPWIFI_TYPE_VDLL 4
123 #define NXPWIFI_TYPE_AGGR_DATA 10
124
125 #define MAX_BITMAP_RATES_SIZE 18
126
127 #define MAX_CHANNEL_BAND_BG 14
128 #define MAX_CHANNEL_BAND_A 165
129
130 #define MAX_FREQUENCY_BAND_BG 2484
131
132 #define NXPWIFI_EVENT_HEADER_LEN 4
133 #define NXPWIFI_UAP_EVENT_EXTRA_HEADER 2
134
135 #define NXPWIFI_TYPE_LEN 4
136 #define NXPWIFI_USB_TYPE_CMD 0xF00DFACE
137 #define NXPWIFI_USB_TYPE_DATA 0xBEADC0DE
138 #define NXPWIFI_USB_TYPE_EVENT 0xBEEFFACE
139
140 /* tx_timeout threshold to trigger card reset */
141 #define TX_TIMEOUT_THRESHOLD 6
142
143 #define NXPWIFI_DRV_INFO_SIZE_MAX 0x40000
144
145 /* address alignment helper */
146 #define NXPWIFI_ALIGN_ADDR(p, a) ({ \
147 typeof(a) (_a) = a; \
148 (((long)(p) + (_a) - 1) & ~((_a) - 1)); \
149 })
150
151 #define NXPWIFI_MAC_LOCAL_ADMIN_BIT 41
152
153 /* bit helper */
154 #define MBIT(x) (((u32)1) << (x))
155
156 /* enum nxpwifi_debug_level - nxp wifi debug level */
157 enum NXPWIFI_DEBUG_LEVEL {
158 NXPWIFI_DBG_MSG = 0x00000001,
159 NXPWIFI_DBG_FATAL = 0x00000002,
160 NXPWIFI_DBG_ERROR = 0x00000004,
161 NXPWIFI_DBG_DATA = 0x00000008,
162 NXPWIFI_DBG_CMD = 0x00000010,
163 NXPWIFI_DBG_EVENT = 0x00000020,
164 NXPWIFI_DBG_INTR = 0x00000040,
165 NXPWIFI_DBG_IOCTL = 0x00000080,
166 NXPWIFI_DBG_MPA_D = 0x00008000,
167 NXPWIFI_DBG_DAT_D = 0x00010000,
168 NXPWIFI_DBG_CMD_D = 0x00020000,
169 NXPWIFI_DBG_EVT_D = 0x00040000,
170 NXPWIFI_DBG_FW_D = 0x00080000,
171 NXPWIFI_DBG_IF_D = 0x00100000,
172 NXPWIFI_DBG_ENTRY = 0x10000000,
173 NXPWIFI_DBG_WARN = 0x20000000,
174 NXPWIFI_DBG_INFO = 0x40000000,
175 NXPWIFI_DBG_DUMP = 0x80000000,
176 NXPWIFI_DBG_ANY = 0xffffffff
177 };
178
179 #define NXPWIFI_DEFAULT_DEBUG_MASK (NXPWIFI_DBG_MSG | \
180 NXPWIFI_DBG_FATAL | \
181 NXPWIFI_DBG_ERROR)
182
183 __printf(3, 4)
184 void _nxpwifi_dbg(const struct nxpwifi_adapter *adapter, int mask,
185 const char *fmt, ...);
186 #define nxpwifi_dbg(adapter, mask, fmt, ...) \
187 _nxpwifi_dbg(adapter, NXPWIFI_DBG_##mask, fmt, ##__VA_ARGS__)
188
189 #define DEBUG_DUMP_DATA_MAX_LEN 128
190 #define nxpwifi_dbg_dump(adapter, dbg_mask, str, buf, len) \
191 do { \
192 if ((adapter)->debug_mask & NXPWIFI_DBG_##dbg_mask) \
193 print_hex_dump(KERN_DEBUG, str, \
194 DUMP_PREFIX_OFFSET, 16, 1, \
195 buf, len, false); \
196 } while (0)
197
198 /* Min BGSCAN interval 15 second */
199 #define NXPWIFI_BGSCAN_INTERVAL 15000
200 /* bgscan interval (ms) and default repeat count */
201 #define NXPWIFI_BGSCAN_REPEAT_COUNT 6
202
203 struct nxpwifi_dbg {
204 u32 num_cmd_host_to_card_failure;
205 u32 num_cmd_sleep_cfm_host_to_card_failure;
206 u32 num_tx_host_to_card_failure;
207 u32 num_event_deauth;
208 u32 num_event_disassoc;
209 u32 num_event_link_lost;
210 u32 num_cmd_deauth;
211 u32 num_cmd_assoc_success;
212 u32 num_cmd_assoc_failure;
213 u32 num_tx_timeout;
214 u16 timeout_cmd_id;
215 u16 timeout_cmd_act;
216 u16 last_cmd_id[DBG_CMD_NUM];
217 u16 last_cmd_act[DBG_CMD_NUM];
218 u16 last_cmd_index;
219 u16 last_cmd_resp_id[DBG_CMD_NUM];
220 u16 last_cmd_resp_index;
221 u16 last_event[DBG_CMD_NUM];
222 u16 last_event_index;
223 u32 last_mp_wr_bitmap[NXPWIFI_DBG_SDIO_MP_NUM];
224 u32 last_mp_wr_ports[NXPWIFI_DBG_SDIO_MP_NUM];
225 u32 last_mp_wr_len[NXPWIFI_DBG_SDIO_MP_NUM];
226 u32 last_mp_curr_wr_port[NXPWIFI_DBG_SDIO_MP_NUM];
227 u8 last_sdio_mp_index;
228 };
229
230 enum NXPWIFI_HARDWARE_STATUS {
231 NXPWIFI_HW_STATUS_READY,
232 NXPWIFI_HW_STATUS_INITIALIZING,
233 NXPWIFI_HW_STATUS_RESET,
234 NXPWIFI_HW_STATUS_NOT_READY
235 };
236
237 enum NXPWIFI_802_11_POWER_MODE {
238 NXPWIFI_802_11_POWER_MODE_CAM,
239 NXPWIFI_802_11_POWER_MODE_PSP
240 };
241
242 struct nxpwifi_tx_param {
243 u32 next_pkt_len;
244 };
245
246 enum NXPWIFI_PS_STATE {
247 PS_STATE_AWAKE,
248 PS_STATE_PRE_SLEEP,
249 PS_STATE_SLEEP_CFM,
250 PS_STATE_SLEEP
251 };
252
253 enum nxpwifi_iface_type {
254 NXPWIFI_SDIO
255 };
256
257 struct nxpwifi_add_ba_param {
258 u32 tx_win_size;
259 u32 rx_win_size;
260 u32 timeout;
261 u8 tx_amsdu;
262 u8 rx_amsdu;
263 };
264
265 struct nxpwifi_tx_aggr {
266 u8 ampdu_user;
267 u8 ampdu_ap;
268 u8 amsdu;
269 };
270
271 enum nxpwifi_ba_status {
272 BA_SETUP_NONE = 0,
273 BA_SETUP_INPROGRESS,
274 BA_SETUP_COMPLETE
275 };
276
277 struct nxpwifi_ra_list_tbl {
278 struct list_head list;
279 struct sk_buff_head skb_head;
280 u8 ra[ETH_ALEN];
281 u32 is_11n_enabled;
282 u16 max_amsdu;
283 u16 ba_pkt_count;
284 u8 ba_packet_thr;
285 enum nxpwifi_ba_status ba_status;
286 u8 amsdu_in_ampdu;
287 u16 total_pkt_count;
288 bool tx_paused;
289 };
290
291 struct nxpwifi_tid_tbl {
292 struct list_head ra_list;
293 };
294
295 #define WMM_HIGHEST_PRIORITY 7
296 #define HIGH_PRIO_TID 7
297 #define LOW_PRIO_TID 0
298 #define NO_PKT_PRIO_TID -1
299 #define NXPWIFI_WMM_DRV_DELAY_MAX 510
300
301 struct nxpwifi_wmm_desc {
302 struct nxpwifi_tid_tbl tid_tbl_ptr[MAX_NUM_TID];
303 u32 packets_out[MAX_NUM_TID];
304 u32 pkts_paused[MAX_NUM_TID];
305 /* protects ra_list */
306 spinlock_t ra_list_spinlock;
307 struct nxpwifi_wmm_ac_status ac_status[IEEE80211_NUM_ACS];
308 enum nxpwifi_wmm_ac_e ac_down_graded_vals[IEEE80211_NUM_ACS];
309 u32 drv_pkt_delay_max;
310 u8 queue_priority[IEEE80211_NUM_ACS];
311 u32 user_pri_pkt_tx_ctrl[WMM_HIGHEST_PRIORITY + 1]; /* UP: 0 to 7 */
312 /* number of queued TX packets */
313 atomic_t tx_pkts_queued;
314 /* highest priority currently queued */
315 atomic_t highest_queued_prio;
316 };
317
318 struct nxpwifi_802_11_security {
319 u8 wpa_enabled;
320 u8 wpa2_enabled;
321 u8 wep_enabled;
322 u32 authentication_mode;
323 u8 is_authtype_auto;
324 u32 encryption_mode;
325 };
326
327 struct ieee_types_vendor_specific {
328 struct ieee80211_vendor_ie vend_hdr;
329 u8 data[IEEE_MAX_IE_SIZE - sizeof(struct ieee80211_vendor_ie)];
330 } __packed;
331
332 struct nxpwifi_bssdescriptor {
333 u8 mac_address[ETH_ALEN];
334 struct cfg80211_ssid ssid;
335 u32 privacy;
336 s32 rssi;
337 u32 channel;
338 u32 freq;
339 u16 beacon_period;
340 u8 erp_flags;
341 u32 bss_mode;
342 u8 supported_rates[NXPWIFI_SUPPORTED_RATES];
343 u8 data_rates[NXPWIFI_SUPPORTED_RATES];
344 u16 bss_band;
345 u64 fw_tsf;
346 u64 timestamp;
347 union ieee_types_phy_param_set phy_param_set;
348 struct ieee_types_cf_param_set cf_param_set;
349 u16 cap_info_bitmap;
350 struct ieee80211_wmm_param_ie wmm_ie;
351 u8 disable_11n;
352 struct ieee80211_ht_cap *bcn_ht_cap;
353 u16 ht_cap_offset;
354 struct ieee80211_ht_operation *bcn_ht_oper;
355 u16 ht_info_offset;
356 u8 *bcn_bss_co_2040;
357 u16 bss_co_2040_offset;
358 u8 *bcn_ext_cap;
359 u16 ext_cap_offset;
360 struct ieee80211_vht_cap *bcn_vht_cap;
361 u16 vht_cap_offset;
362 struct ieee80211_vht_operation *bcn_vht_oper;
363 u16 vht_info_offset;
364 struct ieee_types_oper_mode_ntf *oper_mode;
365 u16 oper_mode_offset;
366 u8 disable_11ac;
367 struct ieee80211_he_cap_elem *bcn_he_cap;
368 u16 he_cap_offset;
369 struct ieee80211_he_operation *bcn_he_oper;
370 u16 he_info_offset;
371 u8 disable_11ax;
372 struct ieee_types_vendor_specific *bcn_wpa_ie;
373 u16 wpa_offset;
374 struct element *bcn_rsn_ie;
375 u16 rsn_offset;
376 struct element *bcn_rsnx_ie;
377 u16 rsnx_offset;
378 u8 *beacon_buf;
379 u32 beacon_buf_size;
380 u8 sensed_11h;
381 u8 local_constraint;
382 u8 chan_sw_ie_present;
383 };
384
385 struct nxpwifi_current_bss_params {
386 struct nxpwifi_bssdescriptor bss_descriptor;
387 bool wmm_enabled;
388 bool wmm_uapsd_enabled;
389 u8 band;
390 u32 num_of_rates;
391 u8 data_rates[NXPWIFI_SUPPORTED_RATES];
392 };
393
394 struct nxpwifi_sleep_period {
395 u16 period;
396 u16 reserved;
397 };
398
399 struct nxpwifi_wep_key {
400 u32 length;
401 u32 key_index;
402 u32 key_length;
403 u8 key_material[NXPWIFI_KEY_BUFFER_SIZE];
404 };
405
406 #define MAX_REGION_CHANNEL_NUM 2
407
408 struct nxpwifi_chan_freq_power {
409 u16 channel;
410 u32 freq;
411 u16 max_tx_power;
412 u8 unsupported;
413 };
414
415 enum state_11d_t {
416 DISABLE_11D = 0,
417 ENABLE_11D = 1,
418 };
419
420 #define NXPWIFI_MAX_TRIPLET_802_11D 83
421
422 struct nxpwifi_802_11d_domain_reg {
423 u8 dfs_region;
424 u8 country_code[IEEE80211_COUNTRY_STRING_LEN];
425 u8 no_of_triplet;
426 struct ieee80211_country_ie_triplet
427 triplet[NXPWIFI_MAX_TRIPLET_802_11D];
428 };
429
430 struct nxpwifi_vendor_spec_cfg_ie {
431 u16 mask;
432 u16 flag;
433 u8 ie[NXPWIFI_MAX_VSIE_LEN];
434 };
435
436 struct wps {
437 u8 session_enable;
438 };
439
440 struct nxpwifi_roc_cfg {
441 u64 cookie;
442 struct ieee80211_channel chan;
443 };
444
445 enum nxpwifi_iface_work_flags {
446 NXPWIFI_IFACE_WORK_DEVICE_DUMP,
447 NXPWIFI_IFACE_WORK_CARD_RESET,
448 };
449
450 enum nxpwifi_adapter_work_flags {
451 NXPWIFI_SURPRISE_REMOVED,
452 NXPWIFI_IS_CMD_TIMEDOUT,
453 NXPWIFI_IS_SUSPENDED,
454 NXPWIFI_IS_HS_CONFIGURED,
455 NXPWIFI_IS_HS_ENABLING,
456 NXPWIFI_IS_REQUESTING_FW_VEREXT,
457 };
458
459 struct nxpwifi_band_config {
460 u8 chan_band:2;
461 u8 chan_width:2;
462 u8 chan2_offset:2;
463 u8 scan_mode:2;
464 } __packed;
465
466 struct nxpwifi_channel_band {
467 struct nxpwifi_band_config band_config;
468 u8 channel;
469 };
470
471 struct nxpwifi_private {
472 struct nxpwifi_adapter *adapter;
473 u8 bss_type;
474 u8 bss_role;
475 u8 bss_priority;
476 u8 bss_num;
477 u8 bss_started;
478 u8 auth_flag;
479 u16 auth_alg;
480 u8 frame_type;
481 u8 curr_addr[ETH_ALEN];
482 u8 media_connected;
483 u8 port_open;
484 u8 usb_port;
485 u32 num_tx_timeout;
486 /* track consecutive timeout */
487 u8 tx_timeout_cnt;
488 struct net_device *netdev;
489 struct net_device_stats stats;
490 u32 curr_pkt_filter;
491 u32 bss_mode;
492 u32 pkt_tx_ctrl;
493 u16 tx_power_level;
494 u8 max_tx_power_level;
495 u8 min_tx_power_level;
496 u32 tx_ant;
497 u32 rx_ant;
498 u8 tx_rate;
499 u8 tx_htinfo;
500 u8 rxpd_htinfo;
501 u8 rxpd_rate;
502 u16 rate_bitmap;
503 u16 bitmap_rates[MAX_BITMAP_RATES_SIZE];
504 u32 data_rate;
505 u8 is_data_rate_auto;
506 u16 bcn_avg_factor;
507 u16 data_avg_factor;
508 s16 data_rssi_last;
509 s16 data_nf_last;
510 s16 data_rssi_avg;
511 s16 data_nf_avg;
512 s16 bcn_rssi_last;
513 s16 bcn_nf_last;
514 s16 bcn_rssi_avg;
515 s16 bcn_nf_avg;
516 struct nxpwifi_bssdescriptor *attempted_bss_desc;
517 struct cfg80211_ssid prev_ssid;
518 u8 prev_bssid[ETH_ALEN];
519 struct nxpwifi_current_bss_params curr_bss_params;
520 u16 beacon_period;
521 u8 dtim_period;
522 u16 listen_interval;
523 u16 atim_window;
524 struct nxpwifi_802_11_security sec_info;
525 struct nxpwifi_wep_key wep_key[NUM_WEP_KEYS];
526 u16 wep_key_curr_index;
527 u8 wpa_ie[256];
528 u16 wpa_ie_len;
529 u8 wpa_is_gtk_set;
530 struct host_cmd_ds_802_11_key_material aes_key;
531 u8 *wps_ie;
532 u16 wps_ie_len;
533 u8 wmm_required;
534 bool wmm_enabled;
535 u8 wmm_qosinfo;
536 struct nxpwifi_wmm_desc wmm;
537 atomic_t wmm_tx_pending[IEEE80211_NUM_ACS];
538 struct list_head sta_list;
539 /* spin lock for associated station list */
540 spinlock_t sta_list_spinlock;
541 struct list_head tx_ba_stream_tbl_ptr[MAX_NUM_TID];
542 /* spin lock for tx_ba_stream_tbl_ptr queue */
543 struct spinlock tx_ba_stream_tbl_lock[MAX_NUM_TID];
544 struct nxpwifi_tx_aggr aggr_prio_tbl[MAX_NUM_TID];
545 struct nxpwifi_add_ba_param add_ba_param;
546 u16 rx_seq[MAX_NUM_TID];
547 u8 tos_to_tid_inv[MAX_NUM_TID];
548 struct list_head rx_reorder_tbl_ptr[MAX_NUM_TID];
549 /* spin lock for rx_reorder_tbl_ptr queue */
550 struct spinlock rx_reorder_tbl_lock[MAX_NUM_TID];
551 #define NXPWIFI_ASSOC_RSP_BUF_SIZE 500
552 u8 assoc_rsp_buf[NXPWIFI_ASSOC_RSP_BUF_SIZE];
553 u32 assoc_rsp_size;
554 struct cfg80211_bss *req_bss;
555
556 #define NXPWIFI_GENIE_BUF_SIZE 256
557 u8 gen_ie_buf[NXPWIFI_GENIE_BUF_SIZE];
558 u8 gen_ie_buf_len;
559
560 struct nxpwifi_vendor_spec_cfg_ie vs_ie[NXPWIFI_MAX_VSIE_NUM];
561
562 #define NXPWIFI_ASSOC_TLV_BUF_SIZE 256
563 u8 assoc_tlv_buf[NXPWIFI_ASSOC_TLV_BUF_SIZE];
564 u8 assoc_tlv_buf_len;
565
566 u8 *curr_bcn_buf;
567 u32 curr_bcn_size;
568 /* spin lock for beacon buffer */
569 spinlock_t curr_bcn_buf_lock;
570 struct wireless_dev wdev;
571 struct nxpwifi_chan_freq_power cfp;
572 u32 versionstrsel;
573 char version_str[NXPWIFI_VERSION_STR_LENGTH];
574 #ifdef CONFIG_DEBUG_FS
575 struct dentry *dfs_dev_dir;
576 #endif
577 u16 current_key_index;
578 struct cfg80211_scan_request *scan_request;
579 u8 cfg_bssid[6];
580 struct wps wps;
581 u8 scan_block;
582 s32 cqm_rssi_thold;
583 u32 cqm_rssi_hyst;
584 u8 subsc_evt_rssi_state;
585 struct nxpwifi_ds_misc_subsc_evt async_subsc_evt_storage;
586 struct nxpwifi_ie mgmt_ie[MAX_MGMT_IE_INDEX];
587 u16 beacon_idx;
588 u16 proberesp_idx;
589 u16 assocresp_idx;
590 u16 gen_idx;
591 u8 ap_11n_enabled;
592 u8 ap_11ac_enabled;
593 u8 ap_11ax_enabled;
594 u16 config_bands;
595 /* 11AX */
596 u8 user_he_cap_len;
597 u8 user_he_cap[HE_CAP_MAX_SIZE];
598 u8 user_2g_he_cap_len;
599 u8 user_2g_he_cap[HE_CAP_MAX_SIZE];
600 bool host_mlme_reg;
601 u32 mgmt_frame_mask;
602 struct nxpwifi_roc_cfg roc_cfg;
603 bool scan_aborting;
604 u8 sched_scanning;
605 u8 csa_chan;
606 unsigned long csa_expire_time;
607 u8 del_list_idx;
608 bool hs2_enabled;
609 struct nxpwifi_uap_bss_param bss_cfg;
610 struct cfg80211_chan_def bss_chandef;
611 struct station_parameters *sta_params;
612 struct xarray ack_status_frames;
613 /* spin lock for ack status */
614 spinlock_t ack_status_lock;
615 /** rx histogram data */
616 struct nxpwifi_histogram_data *hist_data;
617 struct cfg80211_chan_def dfs_chandef;
618 struct wiphy_work reset_conn_state_work;
619 struct wiphy_delayed_work dfs_cac_work;
620 struct wiphy_delayed_work dfs_chan_sw_work;
621 bool uap_stop_tx;
622 struct cfg80211_ap_update ap_update_info;
623 struct nxpwifi_11h_intf_state state_11h;
624 struct nxpwifi_ds_mem_rw mem_rw;
625 struct sk_buff_head bypass_txq;
626 struct nxpwifi_user_scan_chan hidden_chan[NXPWIFI_USER_SCAN_CHAN_MAX];
627 u8 assoc_resp_ht_param;
628 bool ht_param_present;
629 u16 last_deauth_reason;
630 };
631
632 struct nxpwifi_tx_ba_stream_tbl {
633 struct list_head list;
634 struct rcu_head rcu;
635 int tid;
636 u8 ra[ETH_ALEN];
637 enum nxpwifi_ba_status ba_status;
638 u8 amsdu;
639 };
640
641 struct nxpwifi_rx_reorder_tbl;
642
643 struct reorder_tmr_cnxt {
644 struct timer_list timer;
645 struct nxpwifi_rx_reorder_tbl *ptr;
646 struct nxpwifi_private *priv;
647 u8 timer_is_set;
648 };
649
650 struct nxpwifi_rx_reorder_tbl {
651 struct list_head list;
652 struct list_head tmp_list;
653 struct rcu_head rcu;
654 int tid;
655 u8 ta[ETH_ALEN];
656 int init_win;
657 int start_win;
658 int win_size;
659 struct reorder_tmr_cnxt timer_context;
660 u8 amsdu;
661 u8 flags;
662 struct sk_buff *rx_reorder_ptr[] __counted_by(win_size);
663 };
664
665 struct nxpwifi_bss_prio_node {
666 struct list_head list;
667 struct nxpwifi_private *priv;
668 };
669
670 struct nxpwifi_bss_prio_tbl {
671 struct list_head bss_prio_head;
672 spinlock_t bss_prio_lock; /* protects BSS priority */
673 struct nxpwifi_bss_prio_node *bss_prio_cur;
674 };
675
676 struct cmd_ctrl_node {
677 struct list_head list;
678 struct nxpwifi_private *priv;
679 u32 cmd_no;
680 u32 cmd_flag;
681 struct sk_buff *cmd_skb;
682 struct sk_buff *resp_skb;
683 void *data_buf;
684 u32 wait_q_enabled;
685 struct sk_buff *skb;
686 u8 *condition;
687 u8 cmd_wait_q_woken;
688 int (*cmd_resp)(struct nxpwifi_private *priv,
689 struct host_cmd_ds_command *resp,
690 u16 cmdresp_no,
691 void *data_buf);
692 };
693
694 struct nxpwifi_bss_priv {
695 u16 band;
696 u64 fw_tsf;
697 };
698
699 struct nxpwifi_station_stats {
700 u64 last_rx;
701 s8 rssi;
702 u64 rx_bytes;
703 u64 tx_bytes;
704 u32 rx_packets;
705 u32 tx_packets;
706 u32 tx_failed;
707 u8 last_tx_rate;
708 u8 last_tx_htinfo;
709 };
710
711 /*AP - side structure tracking associated STA info */
712 struct nxpwifi_sta_node {
713 struct list_head list;
714 struct rcu_head rcu;
715 u8 mac_addr[ETH_ALEN];
716 u8 is_wmm_enabled;
717 u8 is_11n_enabled;
718 u8 is_11ac_enabled;
719 u8 is_11ax_enabled;
720 u8 ampdu_sta[MAX_NUM_TID];
721 u16 rx_seq[MAX_NUM_TID];
722 u16 max_amsdu;
723 struct nxpwifi_station_stats stats;
724 u8 tx_pause;
725 };
726
727 #define NXPWIFI_TYPE_AGGR_DATA_V2 11
728 #define NXPWIFI_BUS_AGGR_MODE_LEN_V2 (2)
729 #define NXPWIFI_BUS_AGGR_MAX_LEN 16000
730 #define NXPWIFI_BUS_AGGR_MAX_NUM 10
731 struct bus_aggr_params {
732 u16 enable;
733 u16 mode;
734 u16 tx_aggr_max_size;
735 u16 tx_aggr_max_num;
736 u16 tx_aggr_align;
737 };
738
739 struct vdll_dnld_ctrl {
740 u8 *pending_block;
741 u16 pending_block_len;
742 u8 *vdll_mem;
743 u32 vdll_len;
744 struct sk_buff *skb;
745 };
746
747 struct nxpwifi_if_ops {
748 int (*init_if)(struct nxpwifi_adapter *adapter);
749 void (*cleanup_if)(struct nxpwifi_adapter *adapter);
750 int (*check_fw_status)(struct nxpwifi_adapter *adapter, u32 poll_num);
751 int (*check_winner_status)(struct nxpwifi_adapter *adapter);
752 int (*prog_fw)(struct nxpwifi_adapter *adapter,
753 struct nxpwifi_fw_image *fw);
754 int (*register_dev)(struct nxpwifi_adapter *adapter);
755 void (*unregister_dev)(struct nxpwifi_adapter *adapter);
756 int (*enable_int)(struct nxpwifi_adapter *adapter);
757 void (*disable_int)(struct nxpwifi_adapter *adapter);
758 int (*process_int_status)(struct nxpwifi_adapter *adapter, u8 istat);
759 int (*host_to_card)(struct nxpwifi_adapter *adapter, u8 type,
760 struct sk_buff *skb,
761 struct nxpwifi_tx_param *tx_param);
762 int (*wakeup)(struct nxpwifi_adapter *adapter);
763 int (*wakeup_complete)(struct nxpwifi_adapter *adapter);
764
765 /* interface-specific operations */
766 void (*update_mp_end_port)(struct nxpwifi_adapter *adapter, u16 port);
767 void (*cleanup_mpa_buf)(struct nxpwifi_adapter *adapter);
768 int (*cmdrsp_complete)(struct nxpwifi_adapter *adapter,
769 struct sk_buff *skb);
770 int (*event_complete)(struct nxpwifi_adapter *adapter,
771 struct sk_buff *skb);
772 int (*dnld_fw)(struct nxpwifi_adapter *adapter,
773 struct nxpwifi_fw_image *fw);
774 void (*card_reset)(struct nxpwifi_adapter *adapter);
775 int (*reg_dump)(struct nxpwifi_adapter *adapter, char *drv_buf);
776 void (*device_dump)(struct nxpwifi_adapter *adapter);
777 void (*deaggr_pkt)(struct nxpwifi_adapter *adapter,
778 struct sk_buff *skb);
779 void (*up_dev)(struct nxpwifi_adapter *adapter);
780 };
781
782 #define NXPWIFI_DEFAULT_REGION_CODE NXPWIFI_REGION_FCC
783
784 struct nxpwifi_adapter {
785 u8 iface_type;
786 unsigned int debug_mask;
787 struct nxpwifi_iface_comb iface_limit;
788 struct nxpwifi_iface_comb curr_iface_comb;
789 struct nxpwifi_private *priv[NXPWIFI_MAX_BSS_NUM];
790 u8 priv_num;
791 const struct firmware *firmware;
792 char fw_name[32];
793 int winner;
794 struct device *dev;
795 struct wiphy *wiphy;
796 u8 perm_addr[ETH_ALEN];
797 unsigned long work_flags;
798 u32 fw_release_number;
799 u8 intf_hdr_len;
800 void *card;
801 struct nxpwifi_if_ops if_ops;
802 atomic_t bypass_tx_pending;
803 atomic_t rx_pending;
804 atomic_t tx_pending;
805 atomic_t cmd_pending;
806 atomic_t tx_hw_pending;
807 struct workqueue_struct *workqueue;
808 struct work_struct main_work;
809 struct workqueue_struct *rx_workqueue;
810 struct work_struct rx_work;
811 struct wiphy_work host_mlme_work;
812 bool rx_work_enabled;
813 bool rx_processing;
814 bool delay_main_work;
815 atomic_t rx_ba_teardown_pending;
816 atomic_t iface_changing;
817 struct nxpwifi_bss_prio_tbl bss_prio_tbl[NXPWIFI_MAX_BSS_NUM];
818 u32 nxpwifi_processing;
819 u16 tx_buf_size;
820 u16 curr_tx_buf_size;
821 /* SDIO single port rx aggregation capability */
822 bool host_disable_sdio_rx_aggr;
823 bool sdio_rx_aggr_enable;
824 u16 sdio_rx_block_size;
825 u32 ioport;
826 enum NXPWIFI_HARDWARE_STATUS hw_status;
827 u16 number_of_antenna;
828 u32 fw_cap_info;
829 u32 fw_cap_ext;
830 u16 user_htstream;
831 u64 uuid_lo;
832 u64 uuid_hi;
833 /* interrupt lock */
834 spinlock_t int_lock;
835 u8 int_status;
836 u32 event_cause;
837 struct sk_buff *event_skb;
838 u8 upld_buf[NXPWIFI_UPLD_SIZE];
839 u8 data_sent;
840 u8 cmd_sent;
841 u8 cmd_resp_received;
842 bool event_received;
843 u8 data_received;
844 u8 assoc_resp_received;
845 struct nxpwifi_private *priv_link_lost;
846 u8 host_mlme_link_lost;
847 u16 seq_num;
848 struct cmd_ctrl_node *cmd_pool;
849 struct cmd_ctrl_node *curr_cmd;
850 /* spin lock for command */
851 spinlock_t nxpwifi_cmd_lock;
852 struct timer_list cmd_timer;
853 struct list_head cmd_free_q;
854 spinlock_t cmd_free_q_lock; /* protects cmd_free_q */
855 struct list_head cmd_pending_q;
856 spinlock_t cmd_pending_q_lock; /* protects cmd_pending_q */
857 struct list_head scan_pending_q;
858 spinlock_t scan_pending_q_lock; /* protects scan_pending_q */
859 struct sk_buff_head tx_data_q;
860 atomic_t tx_queued;
861 u32 scan_processing;
862 enum nxpwifi_region_code region_code;
863 struct nxpwifi_802_11d_domain_reg domain_reg;
864 u16 scan_probes;
865 u32 scan_mode;
866 u16 specific_scan_time;
867 u16 active_scan_time;
868 u16 passive_scan_time;
869 u16 scan_chan_gap_time;
870 u16 fw_bands;
871 u8 tx_lock_flag;
872 struct nxpwifi_sleep_period sleep_period;
873 u16 ps_mode;
874 u32 ps_state;
875 u8 need_to_wakeup;
876 u16 multiple_dtim;
877 u16 local_listen_interval;
878 u16 null_pkt_interval;
879 struct sk_buff *sleep_cfm;
880 u16 bcn_miss_time_out;
881 u8 is_deep_sleep;
882 u8 delay_null_pkt;
883 u16 delay_to_ps;
884 u16 enhanced_ps_mode;
885 u8 pm_wakeup_card_req;
886 u16 gen_null_pkt;
887 u16 pps_uapsd_mode;
888 u32 pm_wakeup_fw_try;
889 struct timer_list wakeup_timer;
890 struct nxpwifi_hs_config_param hs_cfg;
891 u8 hs_activated;
892 u8 hs_activated_manually;
893 u16 hs_activate_wait_q_woken;
894 wait_queue_head_t hs_activate_wait_q;
895 u8 event_body[MAX_EVENT_SIZE];
896 u32 hw_dot_11n_dev_cap;
897 u8 hw_dev_mcs_support;
898 u8 hw_mpdu_density;
899 u8 user_dev_mcs_support;
900 u8 sec_chan_offset;
901 struct nxpwifi_dbg dbg;
902 u8 arp_filter[ARP_FILTER_MAX_BUF_SIZE];
903 u32 arp_filter_size;
904 struct nxpwifi_wait_queue cmd_wait_q;
905 u8 scan_wait_q_woken;
906 spinlock_t queue_lock; /* protects TX queues */
907 u8 dfs_region;
908 u8 country_code[IEEE80211_COUNTRY_STRING_LEN];
909 u16 max_mgmt_ie_index;
910 const struct firmware *cal_data;
911 /* 11AC capability fields */
912 u32 is_hw_11ac_capable;
913 u32 hw_dot_11ac_dev_cap;
914 u32 hw_dot_11ac_mcs_support;
915 u32 usr_dot_11ac_dev_cap_bg;
916 u32 usr_dot_11ac_dev_cap_a;
917 u32 usr_dot_11ac_mcs_support;
918 /* 11AX capability fields */
919 u8 is_hw_11ax_capable;
920 u8 hw_he_cap_len;
921 u8 hw_he_cap[HE_CAP_MAX_SIZE];
922 u8 hw_2g_he_cap_len;
923 u8 hw_2g_he_cap[HE_CAP_MAX_SIZE];
924 atomic_t pending_bridged_pkts;
925 struct completion *fw_done; /* FW init completion */
926 bool is_up;
927 bool ext_scan;
928 u8 fw_api_ver;
929 u8 fw_hotfix_ver;
930 u8 key_api_major_ver, key_api_minor_ver;
931 u8 max_sta_conn;
932 struct memory_type_mapping *mem_type_mapping_tbl;
933 u8 num_mem_types;
934 bool scan_chan_gap_enabled;
935 struct sk_buff_head rx_mlme_q;
936 struct sk_buff_head rx_data_q;
937 struct nxpwifi_chan_stats *chan_stats;
938 u32 num_in_chan_stats;
939 int survey_idx;
940 u8 coex_scan;
941 u8 coex_min_scan_time;
942 u8 coex_max_scan_time;
943 u8 coex_win_size;
944 u8 coex_tx_win_size;
945 u8 coex_rx_win_size;
946 u8 active_scan_triggered;
947 bool usb_mc_status;
948 bool usb_mc_setup;
949 struct cfg80211_wowlan_nd_info *nd_info;
950 struct ieee80211_regdomain *regd;
951 /* Aggregation parameters*/
952 struct bus_aggr_params bus_aggr;
953 void *devdump_data; /* device dump storage */
954 int devdump_len; /* device dump length */
955 bool ignore_btcoex_events;
956 struct vdll_dnld_ctrl vdll_ctrl;
957 u64 roc_cookie_counter;
958 u32 enable_net_mon;
959 bool wowlan_enabled;
960 bool chandef_valid;
961 struct cfg80211_chan_def chandef;
962 atomic_t uap_count;
963 };
964
965 void nxpwifi_process_tx_queue(struct nxpwifi_adapter *adapter);
966
967 void nxpwifi_init_lock_list(struct nxpwifi_adapter *adapter);
968
969 void nxpwifi_set_trans_start(struct net_device *dev);
970
971 void nxpwifi_stop_net_dev_queue(struct net_device *netdev,
972 struct nxpwifi_adapter *adapter);
973
974 void nxpwifi_wake_up_net_dev_queue(struct net_device *netdev,
975 struct nxpwifi_adapter *adapter);
976
977 int nxpwifi_init_priv(struct nxpwifi_private *priv);
978 void nxpwifi_free_priv(struct nxpwifi_private *priv);
979
980 int nxpwifi_init_fw(struct nxpwifi_adapter *adapter);
981
982 void nxpwifi_shutdown_drv(struct nxpwifi_adapter *adapter);
983
984 int nxpwifi_dnld_fw(struct nxpwifi_adapter *adapter,
985 struct nxpwifi_fw_image *fw);
986
987 int nxpwifi_recv_packet(struct nxpwifi_private *priv, struct sk_buff *skb);
988 int nxpwifi_uap_recv_packet(struct nxpwifi_private *priv,
989 struct sk_buff *skb);
990
991 void nxpwifi_host_mlme_disconnect(struct nxpwifi_private *priv,
992 u16 reason_code, u8 *sa);
993
994 int nxpwifi_process_mgmt_packet(struct nxpwifi_private *priv,
995 struct sk_buff *skb);
996 int nxpwifi_recv_packet_to_monif(struct nxpwifi_private *priv,
997 struct sk_buff *skb);
998 int nxpwifi_complete_cmd(struct nxpwifi_adapter *adapter,
999 struct cmd_ctrl_node *cmd_node);
1000
1001 void nxpwifi_cmd_timeout_func(struct timer_list *t);
1002
1003 int nxpwifi_get_debug_info(struct nxpwifi_private *priv,
1004 struct nxpwifi_debug_info *info);
1005
1006 int nxpwifi_alloc_cmd_buffer(struct nxpwifi_adapter *adapter);
1007 void nxpwifi_free_cmd_buffer(struct nxpwifi_adapter *adapter);
1008 void nxpwifi_free_cmd_buffers(struct nxpwifi_adapter *adapter);
1009 void nxpwifi_cancel_all_pending_cmd(struct nxpwifi_adapter *adapter);
1010 void nxpwifi_cancel_pending_scan_cmd(struct nxpwifi_adapter *adapter);
1011 void nxpwifi_cancel_scan(struct nxpwifi_adapter *adapter);
1012
1013 void nxpwifi_recycle_cmd_node(struct nxpwifi_adapter *adapter,
1014 struct cmd_ctrl_node *cmd_node);
1015
1016 void nxpwifi_insert_cmd_to_pending_q(struct nxpwifi_adapter *adapter,
1017 struct cmd_ctrl_node *cmd_node);
1018
1019 int nxpwifi_exec_next_cmd(struct nxpwifi_adapter *adapter);
1020 int nxpwifi_process_cmdresp(struct nxpwifi_adapter *adapter);
1021 void nxpwifi_process_assoc_resp(struct nxpwifi_adapter *adapter);
1022 int nxpwifi_handle_rx_packet(struct nxpwifi_adapter *adapter,
1023 struct sk_buff *skb);
1024 int nxpwifi_process_tx(struct nxpwifi_private *priv, struct sk_buff *skb,
1025 struct nxpwifi_tx_param *tx_param);
1026 int nxpwifi_send_null_packet(struct nxpwifi_private *priv, u8 flags);
1027 int nxpwifi_write_data_complete(struct nxpwifi_adapter *adapter,
1028 struct sk_buff *skb, int aggr, int status);
1029 void nxpwifi_clean_txrx(struct nxpwifi_private *priv);
1030 u8 nxpwifi_check_last_packet_indication(struct nxpwifi_private *priv);
1031 void nxpwifi_check_ps_cond(struct nxpwifi_adapter *adapter);
1032 void nxpwifi_process_sleep_confirm_resp(struct nxpwifi_adapter *adapter,
1033 u8 *pbuf, u32 upld_len);
1034 void nxpwifi_process_hs_config(struct nxpwifi_adapter *adapter);
1035 void nxpwifi_hs_activated_event(struct nxpwifi_private *priv,
1036 u8 activated);
1037 int nxpwifi_set_hs_params(struct nxpwifi_private *priv, u16 action,
1038 int cmd_type, struct nxpwifi_ds_hs_cfg *hs_cfg);
1039 int nxpwifi_ret_802_11_hs_cfg(struct nxpwifi_private *priv,
1040 struct host_cmd_ds_command *resp);
1041 int nxpwifi_process_rx_packet(struct nxpwifi_private *priv,
1042 struct sk_buff *skb);
1043 int nxpwifi_process_sta_rx_packet(struct nxpwifi_private *priv,
1044 struct sk_buff *skb);
1045 int nxpwifi_process_uap_rx_packet(struct nxpwifi_private *priv,
1046 struct sk_buff *skb);
1047 int nxpwifi_handle_uap_rx_forward(struct nxpwifi_private *priv,
1048 struct sk_buff *skb);
1049 void nxpwifi_delete_all_station_list(struct nxpwifi_private *priv);
1050 void nxpwifi_wmm_del_peer_ra_list(struct nxpwifi_private *priv,
1051 const u8 *ra_addr);
1052 void nxpwifi_process_sta_txpd(struct nxpwifi_private *priv,
1053 struct sk_buff *skb);
1054 void nxpwifi_process_uap_txpd(struct nxpwifi_private *priv,
1055 struct sk_buff *skb);
1056 int nxpwifi_cmd_802_11_scan(struct host_cmd_ds_command *cmd,
1057 struct nxpwifi_scan_cmd_config *scan_cfg);
1058 void nxpwifi_queue_scan_cmd(struct nxpwifi_private *priv,
1059 struct cmd_ctrl_node *cmd_node);
1060 int nxpwifi_ret_802_11_scan(struct nxpwifi_private *priv,
1061 struct host_cmd_ds_command *resp);
1062 int nxpwifi_associate(struct nxpwifi_private *priv,
1063 struct nxpwifi_bssdescriptor *bss_desc);
1064 int nxpwifi_cmd_802_11_associate(struct nxpwifi_private *priv,
1065 struct host_cmd_ds_command *cmd,
1066 struct nxpwifi_bssdescriptor *bss_desc);
1067 int nxpwifi_ret_802_11_associate(struct nxpwifi_private *priv,
1068 struct host_cmd_ds_command *resp);
1069 u8 nxpwifi_band_to_radio_type(u16 config_bands);
1070 int nxpwifi_deauthenticate(struct nxpwifi_private *priv, u8 *mac);
1071 void nxpwifi_deauthenticate_all(struct nxpwifi_adapter *adapter);
1072 int nxpwifi_cmd_802_11_bg_scan_query(struct host_cmd_ds_command *cmd);
1073 struct nxpwifi_chan_freq_power *nxpwifi_get_cfp(struct nxpwifi_private *priv,
1074 u8 band, u16 channel, u32 freq);
1075 u32 nxpwifi_index_to_data_rate(struct nxpwifi_private *priv,
1076 u8 index, u8 ht_info);
1077 u32 nxpwifi_index_to_acs_data_rate(struct nxpwifi_private *priv,
1078 u8 index, u8 ht_info);
1079 int nxpwifi_cmd_append_vsie_tlv(struct nxpwifi_private *priv, u16 vsie_mask,
1080 u8 **buffer);
1081 u32 nxpwifi_get_active_data_rates(struct nxpwifi_private *priv,
1082 u8 *rates);
1083 u32 nxpwifi_get_supported_rates(struct nxpwifi_private *priv, u8 *rates);
1084 u32 nxpwifi_get_rates_from_cfg80211(struct nxpwifi_private *priv,
1085 u8 *rates, u8 radio_type);
1086 u8 nxpwifi_is_rate_auto(struct nxpwifi_private *priv);
1087 void nxpwifi_save_curr_bcn(struct nxpwifi_private *priv);
1088 void nxpwifi_free_curr_bcn(struct nxpwifi_private *priv);
1089 int nxpwifi_is_command_pending(struct nxpwifi_adapter *adapter);
1090 void nxpwifi_init_priv_params(struct nxpwifi_private *priv,
1091 struct net_device *dev);
1092 void nxpwifi_set_ba_params(struct nxpwifi_private *priv);
1093 void nxpwifi_update_ampdu_txwinsize(struct nxpwifi_adapter *pmadapter);
1094 void nxpwifi_set_11ac_ba_params(struct nxpwifi_private *priv);
1095 int nxpwifi_cmd_802_11_scan_ext(struct nxpwifi_private *priv,
1096 struct host_cmd_ds_command *cmd,
1097 void *data_buf);
1098 int nxpwifi_ret_802_11_scan_ext(struct nxpwifi_private *priv,
1099 struct host_cmd_ds_command *resp);
1100 int nxpwifi_handle_event_ext_scan_report(struct nxpwifi_private *priv,
1101 void *buf);
1102 int nxpwifi_cmd_802_11_bg_scan_config(struct nxpwifi_private *priv,
1103 struct host_cmd_ds_command *cmd,
1104 void *data_buf);
1105 int nxpwifi_stop_bg_scan(struct nxpwifi_private *priv);
1106
1107 /* check if RA-based queuing */
1108 static inline u8
nxpwifi_queuing_ra_based(struct nxpwifi_private * priv)1109 nxpwifi_queuing_ra_based(struct nxpwifi_private *priv)
1110 {
1111 /* In STA mode DA==RA; subject to future revision */
1112 if (priv->bss_mode == NL80211_IFTYPE_STATION &&
1113 (GET_BSS_ROLE(priv) == NXPWIFI_BSS_ROLE_STA))
1114 return false;
1115
1116 return true;
1117 }
1118
1119 /* copy rates from src to dest */
1120 static inline u32
nxpwifi_copy_rates(u8 * dest,u32 pos,u8 * src,int len)1121 nxpwifi_copy_rates(u8 *dest, u32 pos, u8 *src, int len)
1122 {
1123 int i;
1124
1125 for (i = 0; i < len && src[i]; i++, pos++) {
1126 if (pos >= NXPWIFI_SUPPORTED_RATES)
1127 break;
1128 dest[pos] = src[i];
1129 }
1130
1131 return pos;
1132 }
1133
1134 /* return priv matching the given BSS type and number */
1135 static inline struct nxpwifi_private *
nxpwifi_get_priv_by_id(struct nxpwifi_adapter * adapter,u8 bss_num,u8 bss_type)1136 nxpwifi_get_priv_by_id(struct nxpwifi_adapter *adapter,
1137 u8 bss_num, u8 bss_type)
1138 {
1139 int i;
1140
1141 for (i = 0; i < adapter->priv_num; i++) {
1142 if (adapter->priv[i]->bss_mode ==
1143 NL80211_IFTYPE_UNSPECIFIED)
1144 continue;
1145 if (adapter->priv[i]->bss_num == bss_num &&
1146 adapter->priv[i]->bss_type == bss_type)
1147 break;
1148 }
1149 return ((i < adapter->priv_num) ? adapter->priv[i] : NULL);
1150 }
1151
1152 /* return first priv matching BSS role */
1153 static inline struct nxpwifi_private *
nxpwifi_get_priv(struct nxpwifi_adapter * adapter,enum nxpwifi_bss_role bss_role)1154 nxpwifi_get_priv(struct nxpwifi_adapter *adapter,
1155 enum nxpwifi_bss_role bss_role)
1156 {
1157 int i;
1158
1159 for (i = 0; i < adapter->priv_num; i++) {
1160 if (bss_role == NXPWIFI_BSS_ROLE_ANY ||
1161 GET_BSS_ROLE(adapter->priv[i]) == bss_role)
1162 break;
1163 }
1164
1165 return ((i < adapter->priv_num) ? adapter->priv[i] : NULL);
1166 }
1167
1168 /* find unused BSS number for new interface */
1169 static inline int
nxpwifi_get_unused_bss_num(struct nxpwifi_adapter * adapter,u8 bss_type,u8 * bss_num)1170 nxpwifi_get_unused_bss_num(struct nxpwifi_adapter *adapter, u8 bss_type,
1171 u8 *bss_num)
1172 {
1173 u8 i, j;
1174 int index[NXPWIFI_MAX_BSS_NUM];
1175
1176 memset(index, 0, sizeof(index));
1177 for (i = 0; i < adapter->priv_num; i++)
1178 if (adapter->priv[i]->bss_type == bss_type &&
1179 !(adapter->priv[i]->bss_mode ==
1180 NL80211_IFTYPE_UNSPECIFIED)) {
1181 index[adapter->priv[i]->bss_num] = 1;
1182 }
1183
1184 for (j = 0; j < NXPWIFI_MAX_BSS_NUM; j++) {
1185 if (!index[j]) {
1186 *bss_num = j;
1187 return 0;
1188 }
1189 }
1190
1191 return -ENOENT;
1192 }
1193
1194 /* return unused private entry for requested bss type */
1195 static inline struct nxpwifi_private *
nxpwifi_get_unused_priv_by_bss_type(struct nxpwifi_adapter * adapter,u8 bss_type)1196 nxpwifi_get_unused_priv_by_bss_type(struct nxpwifi_adapter *adapter,
1197 u8 bss_type)
1198 {
1199 u8 i;
1200
1201 for (i = 0; i < adapter->priv_num; i++)
1202 if (adapter->priv[i]->bss_mode ==
1203 NL80211_IFTYPE_UNSPECIFIED) {
1204 if (nxpwifi_get_unused_bss_num(adapter, bss_type,
1205 &adapter->priv[i]->bss_num))
1206 return NULL;
1207 break;
1208 }
1209
1210 return ((i < adapter->priv_num) ? adapter->priv[i] : NULL);
1211 }
1212
1213 /* return private structure attached to netdev */
1214 static inline struct nxpwifi_private *
nxpwifi_netdev_get_priv(struct net_device * dev)1215 nxpwifi_netdev_get_priv(struct net_device *dev)
1216 {
1217 return (struct nxpwifi_private *)(*(unsigned long *)netdev_priv(dev));
1218 }
1219
1220 /* return true if skb contains a management frame */
nxpwifi_is_skb_mgmt_frame(struct sk_buff * skb)1221 static inline bool nxpwifi_is_skb_mgmt_frame(struct sk_buff *skb)
1222 {
1223 return (get_unaligned_le32(skb->data) == PKT_TYPE_MGMT);
1224 }
1225
1226 /* channel closed by CSA */
1227 static inline u8
nxpwifi_11h_get_csa_closed_channel(struct nxpwifi_private * priv)1228 nxpwifi_11h_get_csa_closed_channel(struct nxpwifi_private *priv)
1229 {
1230 if (!priv->csa_chan)
1231 return 0;
1232
1233 /* clear CSA if DFS switch timeout expired */
1234 if (time_after(jiffies, priv->csa_expire_time)) {
1235 priv->csa_chan = 0;
1236 priv->csa_expire_time = 0;
1237 }
1238
1239 return priv->csa_chan;
1240 }
1241
nxpwifi_is_any_intf_active(struct nxpwifi_private * priv)1242 static inline u8 nxpwifi_is_any_intf_active(struct nxpwifi_private *priv)
1243 {
1244 struct nxpwifi_private *priv_tmp;
1245 int i;
1246
1247 for (i = 0; i < priv->adapter->priv_num; i++) {
1248 priv_tmp = priv->adapter->priv[i];
1249 if ((GET_BSS_ROLE(priv_tmp) == NXPWIFI_BSS_ROLE_UAP &&
1250 priv_tmp->bss_started) ||
1251 (GET_BSS_ROLE(priv_tmp) == NXPWIFI_BSS_ROLE_STA &&
1252 priv_tmp->media_connected))
1253 return 1;
1254 }
1255
1256 return 0;
1257 }
1258
1259 int nxpwifi_init_shutdown_fw(struct nxpwifi_private *priv,
1260 u32 func_init_shutdown);
1261
1262 int nxpwifi_add_card(void *card, struct completion *fw_done,
1263 struct nxpwifi_if_ops *if_ops, u8 iface_type,
1264 struct device *dev);
1265 void nxpwifi_remove_card(struct nxpwifi_adapter *adapter);
1266
1267 void nxpwifi_get_version(struct nxpwifi_adapter *adapter, char *version,
1268 int maxlen);
1269 int
1270 nxpwifi_request_set_multicast_list(struct nxpwifi_private *priv,
1271 struct nxpwifi_multicast_list *mcast_list);
1272 int nxpwifi_copy_mcast_addr(struct nxpwifi_multicast_list *mlist,
1273 struct net_device *dev);
1274 int nxpwifi_wait_queue_complete(struct nxpwifi_adapter *adapter,
1275 struct cmd_ctrl_node *cmd_queued);
1276 int nxpwifi_bss_start(struct nxpwifi_private *priv, struct cfg80211_bss *bss,
1277 struct cfg80211_ssid *req_ssid);
1278 int nxpwifi_cancel_hs(struct nxpwifi_private *priv, int cmd_type);
1279 bool nxpwifi_enable_hs(struct nxpwifi_adapter *adapter);
1280 int nxpwifi_disable_auto_ds(struct nxpwifi_private *priv);
1281 int nxpwifi_drv_get_data_rate(struct nxpwifi_private *priv, u32 *rate);
1282
1283 int nxpwifi_scan_networks(struct nxpwifi_private *priv,
1284 const struct nxpwifi_user_scan_cfg *user_scan_in);
1285 int nxpwifi_set_radio(struct nxpwifi_private *priv, u8 option);
1286
1287 int nxpwifi_set_encode(struct nxpwifi_private *priv, struct key_params *kp,
1288 const u8 *key, int key_len, u8 key_index,
1289 const u8 *mac_addr, int disable);
1290
1291 int nxpwifi_set_gen_ie(struct nxpwifi_private *priv, const u8 *ie, int ie_len);
1292
1293 int nxpwifi_get_ver_ext(struct nxpwifi_private *priv, u32 version_str_sel);
1294
1295 int nxpwifi_remain_on_chan_cfg(struct nxpwifi_private *priv, u16 action,
1296 struct ieee80211_channel *chan,
1297 unsigned int duration);
1298
1299 int nxpwifi_get_stats_info(struct nxpwifi_private *priv,
1300 struct nxpwifi_ds_get_stats *log);
1301
1302 int nxpwifi_reg_write(struct nxpwifi_private *priv, u32 reg_type,
1303 u32 reg_offset, u32 reg_value);
1304
1305 int nxpwifi_reg_read(struct nxpwifi_private *priv, u32 reg_type,
1306 u32 reg_offset, u32 *value);
1307
1308 int nxpwifi_eeprom_read(struct nxpwifi_private *priv, u16 offset, u16 bytes,
1309 u8 *value);
1310
1311 int nxpwifi_set_11n_httx_cfg(struct nxpwifi_private *priv, int data);
1312
1313 int nxpwifi_get_11n_httx_cfg(struct nxpwifi_private *priv, int *data);
1314
1315 int nxpwifi_set_tx_rate_cfg(struct nxpwifi_private *priv, int tx_rate_index);
1316
1317 int nxpwifi_get_tx_rate_cfg(struct nxpwifi_private *priv, int *tx_rate_index);
1318
1319 int nxpwifi_drv_set_power(struct nxpwifi_private *priv, u32 *ps_mode);
1320
1321 int nxpwifi_drv_get_driver_version(struct nxpwifi_adapter *adapter,
1322 char *version, int max_len);
1323
1324 int nxpwifi_set_tx_power(struct nxpwifi_private *priv,
1325 struct nxpwifi_power_cfg *power_cfg);
1326
1327 void nxpwifi_main_process(struct nxpwifi_adapter *adapter);
1328
1329 void nxpwifi_queue_tx_pkt(struct nxpwifi_private *priv, struct sk_buff *skb);
1330
1331 int nxpwifi_get_bss_info(struct nxpwifi_private *priv,
1332 struct nxpwifi_bss_info *info);
1333 int nxpwifi_fill_new_bss_desc(struct nxpwifi_private *priv,
1334 struct cfg80211_bss *bss,
1335 struct nxpwifi_bssdescriptor *bss_desc);
1336 int nxpwifi_update_bss_desc_with_ie(struct nxpwifi_adapter *adapter,
1337 struct nxpwifi_bssdescriptor *bss_entry);
1338 int nxpwifi_check_network_compatibility(struct nxpwifi_private *priv,
1339 struct nxpwifi_bssdescriptor *bss_desc);
1340
1341 u8 nxpwifi_chan_type_to_sec_chan_offset(enum nl80211_channel_type chan_type);
1342 u8 nxpwifi_get_chan_type(struct nxpwifi_private *priv);
1343
1344 struct wireless_dev *nxpwifi_add_virtual_intf(struct wiphy *wiphy,
1345 const char *name,
1346 unsigned char name_assign_type,
1347 enum nl80211_iftype type,
1348 struct vif_params *params);
1349 int nxpwifi_del_virtual_intf(struct wiphy *wiphy, struct wireless_dev *wdev);
1350
1351 int nxpwifi_add_wowlan_magic_pkt_filter(struct nxpwifi_adapter *adapter);
1352
1353 int nxpwifi_set_mgmt_ies(struct nxpwifi_private *priv,
1354 struct cfg80211_beacon_data *data);
1355 int nxpwifi_del_mgmt_ies(struct nxpwifi_private *priv);
1356 u8 *nxpwifi_11d_code_2_region(u8 code);
1357 void nxpwifi_init_11h_params(struct nxpwifi_private *priv);
1358 int nxpwifi_is_11h_active(struct nxpwifi_private *priv);
1359 int nxpwifi_11h_activate(struct nxpwifi_private *priv, bool flag);
1360 void nxpwifi_11h_process_join(struct nxpwifi_private *priv, u8 **buffer,
1361 struct nxpwifi_bssdescriptor *bss_desc);
1362 int nxpwifi_11h_handle_event_chanswann(struct nxpwifi_private *priv);
1363
1364 extern const struct ethtool_ops nxpwifi_ethtool_ops;
1365
1366 void nxpwifi_del_all_sta_list(struct nxpwifi_private *priv);
1367 void nxpwifi_del_sta_entry(struct nxpwifi_private *priv, const u8 *mac);
1368 void
1369 nxpwifi_set_sta_ht_cap(struct nxpwifi_private *priv, const u8 *ies,
1370 int ies_len, struct nxpwifi_sta_node *node);
1371 struct nxpwifi_sta_node *
1372 nxpwifi_add_sta_entry(struct nxpwifi_private *priv, const u8 *mac);
1373 struct nxpwifi_sta_node *
1374 nxpwifi_get_sta_entry(struct nxpwifi_private *priv, const u8 *mac);
1375 struct nxpwifi_sta_node *
1376 nxpwifi_get_sta_entry_rcu(struct nxpwifi_private *priv, const u8 *mac);
1377 int nxpwifi_init_channel_scan_gap(struct nxpwifi_adapter *adapter);
1378
1379 int nxpwifi_cmd_issue_chan_report_request(struct nxpwifi_private *priv,
1380 struct host_cmd_ds_command *cmd,
1381 void *data_buf);
1382 int nxpwifi_11h_handle_chanrpt_ready(struct nxpwifi_private *priv,
1383 struct sk_buff *skb);
1384
1385 void nxpwifi_parse_tx_status_event(struct nxpwifi_private *priv,
1386 void *event_body);
1387
1388 struct sk_buff *
1389 nxpwifi_clone_skb_for_tx_status(struct nxpwifi_private *priv,
1390 struct sk_buff *skb, u8 flag, u64 *cookie);
1391 void nxpwifi_reset_conn_state_work(struct wiphy *wiphy, struct wiphy_work *work);
1392 void nxpwifi_dfs_cac_work(struct wiphy *wiphy, struct wiphy_work *work);
1393 void nxpwifi_dfs_chan_sw_work(struct wiphy *wiphy, struct wiphy_work *work);
1394 void nxpwifi_abort_cac(struct nxpwifi_private *priv);
1395 int nxpwifi_stop_radar_detection(struct nxpwifi_private *priv,
1396 struct cfg80211_chan_def *chandef);
1397 int nxpwifi_11h_handle_radar_detected(struct nxpwifi_private *priv,
1398 struct sk_buff *skb);
1399
1400 void nxpwifi_hist_data_set(struct nxpwifi_private *priv, u8 rx_rate, s8 snr,
1401 s8 nflr);
1402 void nxpwifi_hist_data_reset(struct nxpwifi_private *priv);
1403 void nxpwifi_hist_data_add(struct nxpwifi_private *priv,
1404 u8 rx_rate, s8 snr, s8 nflr);
1405 u8 nxpwifi_adjust_data_rate(struct nxpwifi_private *priv,
1406 u8 rx_rate, u8 ht_info);
1407
1408 void nxpwifi_drv_info_dump(struct nxpwifi_adapter *adapter);
1409 void nxpwifi_prepare_fw_dump_info(struct nxpwifi_adapter *adapter);
1410 void nxpwifi_upload_device_dump(struct nxpwifi_adapter *adapter);
1411 void *nxpwifi_alloc_dma_align_buf(int rx_len, gfp_t flags);
1412 void nxpwifi_fw_dump_event(struct nxpwifi_private *priv);
1413 int nxpwifi_get_wakeup_reason(struct nxpwifi_private *priv, u16 action,
1414 int cmd_type,
1415 struct nxpwifi_ds_wakeup_reason *wakeup_reason);
1416 int nxpwifi_get_chan_info(struct nxpwifi_private *priv,
1417 struct nxpwifi_channel_band *channel_band);
1418 void nxpwifi_coex_ampdu_rxwinsize(struct nxpwifi_adapter *adapter);
1419 void nxpwifi_11n_delba(struct nxpwifi_private *priv, int tid);
1420 int nxpwifi_send_domain_info_cmd_fw(struct wiphy *wiphy, enum nl80211_band band);
1421 int nxpwifi_set_mac_address(struct nxpwifi_private *priv,
1422 struct net_device *dev,
1423 bool external, u8 *new_mac);
1424 void nxpwifi_devdump_tmo_func(unsigned long function_context);
1425
1426 #ifdef CONFIG_DEBUG_FS
1427 void nxpwifi_debugfs_init(void);
1428 void nxpwifi_debugfs_remove(void);
1429
1430 void nxpwifi_dev_debugfs_init(struct nxpwifi_private *priv);
1431 void nxpwifi_dev_debugfs_remove(struct nxpwifi_private *priv);
1432 #endif
1433 int nxpwifi_reinit_sw(struct nxpwifi_adapter *adapter);
1434 void nxpwifi_shutdown_sw(struct nxpwifi_adapter *adapter);
1435 bool nxpwifi_is_valid_region_code(enum nxpwifi_region_code code);
1436 #endif /* !_NXPWIFI_MAIN_H_ */
1437