xref: /freebsd/sys/contrib/dev/iwlwifi/iwl-drv.c (revision 8ac82ba19efbaeec065621215c3843f054fa419e)
1 // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
2 /*
3  * Copyright (C) 2005-2014, 2018-2024 Intel Corporation
4  * Copyright (C) 2013-2015 Intel Mobile Communications GmbH
5  * Copyright (C) 2016-2017 Intel Deutschland GmbH
6  */
7 #if defined(__FreeBSD__)
8 #define	LINUXKPI_PARAM_PREFIX	iwlwifi_
9 #endif
10 #include <linux/completion.h>
11 #include <linux/dma-mapping.h>
12 #include <linux/firmware.h>
13 #include <linux/module.h>
14 #include <linux/vmalloc.h>
15 
16 #include "iwl-drv.h"
17 #include "iwl-csr.h"
18 #include "iwl-debug.h"
19 #include "iwl-trans.h"
20 #include "iwl-op-mode.h"
21 #include "iwl-agn-hw.h"
22 #include "fw/img.h"
23 #include "iwl-dbg-tlv.h"
24 #include "iwl-config.h"
25 #include "iwl-modparams.h"
26 #include "fw/api/alive.h"
27 #include "fw/api/mac.h"
28 
29 /******************************************************************************
30  *
31  * module boiler plate
32  *
33  ******************************************************************************/
34 
35 #if defined(__linux__)
36 #define DRV_DESCRIPTION	"Intel(R) Wireless WiFi driver for Linux"
37 MODULE_DESCRIPTION(DRV_DESCRIPTION);
38 MODULE_LICENSE("GPL");
39 #elif defined(__FreeBSD__)
40 #define DRV_DESCRIPTION	"Intel(R) Wireless WiFi based driver for FreeBSD"
41 MODULE_DESCRIPTION(DRV_DESCRIPTION);
42 MODULE_LICENSE("BSD");
43 MODULE_VERSION(if_iwlwifi, 1);
44 MODULE_DEPEND(if_iwlwifi, linuxkpi, 1, 1, 1);
45 MODULE_DEPEND(if_iwlwifi, linuxkpi_wlan, 1, 1, 1);
46 #ifdef CONFIG_IWLWIFI_DEBUGFS
47 MODULE_DEPEND(if_iwlwifi, lindebugfs, 1, 1, 1);
48 #endif
49 #endif
50 
51 #ifdef CONFIG_IWLWIFI_DEBUGFS
52 static struct dentry *iwl_dbgfs_root;
53 #endif
54 
55 /**
56  * struct iwl_drv - drv common data
57  * @list: list of drv structures using this opmode
58  * @fw: the iwl_fw structure
59  * @op_mode: the running op_mode
60  * @trans: transport layer
61  * @dev: for debug prints only
62  * @fw_index: firmware revision to try loading
63  * @firmware_name: composite filename of ucode file to load
64  * @request_firmware_complete: the firmware has been obtained from user space
65  * @dbgfs_drv: debugfs root directory entry
66  * @dbgfs_trans: debugfs transport directory entry
67  * @dbgfs_op_mode: debugfs op_mode directory entry
68  */
69 struct iwl_drv {
70 	struct list_head list;
71 	struct iwl_fw fw;
72 
73 	struct iwl_op_mode *op_mode;
74 	struct iwl_trans *trans;
75 	struct device *dev;
76 
77 	int fw_index;                   /* firmware we're trying to load */
78 	char firmware_name[64];         /* name of firmware file to load */
79 
80 	struct completion request_firmware_complete;
81 #if defined(__FreeBSD__)
82 	struct completion drv_start_complete;
83 #endif
84 
85 #ifdef CONFIG_IWLWIFI_DEBUGFS
86 	struct dentry *dbgfs_drv;
87 	struct dentry *dbgfs_trans;
88 	struct dentry *dbgfs_op_mode;
89 #endif
90 };
91 
92 enum {
93 	DVM_OP_MODE,
94 	MVM_OP_MODE,
95 };
96 
97 /* Protects the table contents, i.e. the ops pointer & drv list */
98 static DEFINE_MUTEX(iwlwifi_opmode_table_mtx);
99 static struct iwlwifi_opmode_table {
100 	const char *name;			/* name: iwldvm, iwlmvm, etc */
101 	const struct iwl_op_mode_ops *ops;	/* pointer to op_mode ops */
102 	struct list_head drv;		/* list of devices using this op_mode */
103 } iwlwifi_opmode_table[] = {		/* ops set when driver is initialized */
104 	[DVM_OP_MODE] = { .name = "iwldvm", .ops = NULL },
105 	[MVM_OP_MODE] = { .name = "iwlmvm", .ops = NULL },
106 };
107 
108 #define IWL_DEFAULT_SCAN_CHANNELS 40
109 
110 /*
111  * struct fw_sec: Just for the image parsing process.
112  * For the fw storage we are using struct fw_desc.
113  */
114 struct fw_sec {
115 	const void *data;		/* the sec data */
116 	size_t size;			/* section size */
117 	u32 offset;			/* offset of writing in the device */
118 };
119 
iwl_free_fw_desc(struct iwl_drv * drv,struct fw_desc * desc)120 static void iwl_free_fw_desc(struct iwl_drv *drv, struct fw_desc *desc)
121 {
122 	vfree(desc->data);
123 	desc->data = NULL;
124 	desc->len = 0;
125 }
126 
iwl_free_fw_img(struct iwl_drv * drv,struct fw_img * img)127 static void iwl_free_fw_img(struct iwl_drv *drv, struct fw_img *img)
128 {
129 	int i;
130 	for (i = 0; i < img->num_sec; i++)
131 		iwl_free_fw_desc(drv, &img->sec[i]);
132 	kfree(img->sec);
133 }
134 
iwl_dealloc_ucode(struct iwl_drv * drv)135 static void iwl_dealloc_ucode(struct iwl_drv *drv)
136 {
137 	int i;
138 
139 	kfree(drv->fw.dbg.dest_tlv);
140 	for (i = 0; i < ARRAY_SIZE(drv->fw.dbg.conf_tlv); i++)
141 		kfree(drv->fw.dbg.conf_tlv[i]);
142 	for (i = 0; i < ARRAY_SIZE(drv->fw.dbg.trigger_tlv); i++)
143 		kfree(drv->fw.dbg.trigger_tlv[i]);
144 	kfree(drv->fw.dbg.mem_tlv);
145 	kfree(drv->fw.iml);
146 	kfree(drv->fw.ucode_capa.cmd_versions);
147 	kfree(drv->fw.phy_integration_ver);
148 	kfree(drv->trans->dbg.pc_data);
149 	drv->trans->dbg.pc_data = NULL;
150 
151 	for (i = 0; i < IWL_UCODE_TYPE_MAX; i++)
152 		iwl_free_fw_img(drv, drv->fw.img + i);
153 
154 	/* clear the data for the aborted load case */
155 	memset(&drv->fw, 0, sizeof(drv->fw));
156 }
157 
iwl_alloc_fw_desc(struct iwl_drv * drv,struct fw_desc * desc,struct fw_sec * sec)158 static int iwl_alloc_fw_desc(struct iwl_drv *drv, struct fw_desc *desc,
159 			     struct fw_sec *sec)
160 {
161 	void *data;
162 
163 	desc->data = NULL;
164 
165 	if (!sec || !sec->size)
166 		return -EINVAL;
167 
168 	data = vmalloc(sec->size);
169 	if (!data)
170 		return -ENOMEM;
171 
172 	desc->len = sec->size;
173 	desc->offset = sec->offset;
174 	memcpy(data, sec->data, desc->len);
175 	desc->data = data;
176 
177 	return 0;
178 }
179 
iwl_drv_get_step(int step)180 static inline char iwl_drv_get_step(int step)
181 {
182 	if (step == SILICON_Z_STEP)
183 		return 'z';
184 	if (step == SILICON_TC_STEP)
185 		return 'a';
186 	return 'a' + step;
187 }
188 
iwl_drv_get_fwname_pre(struct iwl_trans * trans,char * buf)189 const char *iwl_drv_get_fwname_pre(struct iwl_trans *trans, char *buf)
190 {
191 	char mac_step, rf_step;
192 	const char *rf, *cdb;
193 
194 	if (trans->cfg->fw_name_pre)
195 		return trans->cfg->fw_name_pre;
196 
197 	if (WARN_ON(!trans->cfg->fw_name_mac))
198 		return "unconfigured";
199 
200 	mac_step = iwl_drv_get_step(trans->hw_rev_step);
201 
202 	rf_step = iwl_drv_get_step(CSR_HW_RFID_STEP(trans->hw_rf_id));
203 
204 	switch (CSR_HW_RFID_TYPE(trans->hw_rf_id)) {
205 	case IWL_CFG_RF_TYPE_HR1:
206 	case IWL_CFG_RF_TYPE_HR2:
207 		rf = "hr";
208 		rf_step = 'b';
209 		break;
210 	case IWL_CFG_RF_TYPE_GF:
211 		rf = "gf";
212 		break;
213 	case IWL_CFG_RF_TYPE_FM:
214 		rf = "fm";
215 		break;
216 	case IWL_CFG_RF_TYPE_WH:
217 		if (SILICON_Z_STEP ==
218 		    CSR_HW_RFID_STEP(trans->hw_rf_id)) {
219 			rf = "whtc";
220 			rf_step = 'a';
221 		} else {
222 			rf = "wh";
223 		}
224 		break;
225 	default:
226 		return "unknown-rf";
227 	}
228 
229 	cdb = CSR_HW_RFID_IS_CDB(trans->hw_rf_id) ? "4" : "";
230 
231 	scnprintf(buf, FW_NAME_PRE_BUFSIZE,
232 		  "iwlwifi-%s-%c0-%s%s-%c0",
233 		  trans->cfg->fw_name_mac, mac_step,
234 		  rf, cdb, rf_step);
235 
236 	return buf;
237 }
238 IWL_EXPORT_SYMBOL(iwl_drv_get_fwname_pre);
239 
240 static void iwl_req_fw_callback(const struct firmware *ucode_raw,
241 				void *context);
242 
iwl_request_firmware(struct iwl_drv * drv,bool first)243 static int iwl_request_firmware(struct iwl_drv *drv, bool first)
244 {
245 	const struct iwl_cfg *cfg = drv->trans->cfg;
246 	char _fw_name_pre[FW_NAME_PRE_BUFSIZE];
247 	const char *fw_name_pre;
248 
249 	if (drv->trans->trans_cfg->device_family == IWL_DEVICE_FAMILY_9000 &&
250 	    (drv->trans->hw_rev_step != SILICON_B_STEP &&
251 	     drv->trans->hw_rev_step != SILICON_C_STEP)) {
252 		IWL_ERR(drv,
253 			"Only HW steps B and C are currently supported (0x%0x)\n",
254 			drv->trans->hw_rev);
255 		return -EINVAL;
256 	}
257 
258 	fw_name_pre = iwl_drv_get_fwname_pre(drv->trans, _fw_name_pre);
259 
260 	if (first)
261 		drv->fw_index = cfg->ucode_api_max;
262 	else
263 		drv->fw_index--;
264 
265 	if (drv->fw_index < cfg->ucode_api_min) {
266 		IWL_ERR(drv, "no suitable firmware found!\n");
267 
268 		if (cfg->ucode_api_min == cfg->ucode_api_max) {
269 			IWL_ERR(drv, "%s-%d is required\n", fw_name_pre,
270 				cfg->ucode_api_max);
271 		} else {
272 			IWL_ERR(drv, "minimum version required: %s-%d\n",
273 				fw_name_pre, cfg->ucode_api_min);
274 			IWL_ERR(drv, "maximum version supported: %s-%d\n",
275 				fw_name_pre, cfg->ucode_api_max);
276 		}
277 
278 		IWL_ERR(drv,
279 			"check git://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git\n");
280 #if defined(__FreeBSD__)
281 		IWL_ERR(drv, "On FreeBSD the firmware package can be installed running fwget(8).\n");
282 #endif
283 		return -ENOENT;
284 	}
285 
286 	snprintf(drv->firmware_name, sizeof(drv->firmware_name), "%s-%d.ucode",
287 		 fw_name_pre, drv->fw_index);
288 
289 	IWL_DEBUG_FW_INFO(drv, "attempting to load firmware '%s'\n",
290 			  drv->firmware_name);
291 
292 	return request_firmware_nowait(THIS_MODULE, 1, drv->firmware_name,
293 				       drv->trans->dev,
294 				       GFP_KERNEL, drv, iwl_req_fw_callback);
295 }
296 
297 struct fw_img_parsing {
298 	struct fw_sec *sec;
299 	int sec_counter;
300 };
301 
302 /*
303  * struct fw_sec_parsing: to extract fw section and it's offset from tlv
304  */
305 struct fw_sec_parsing {
306 	__le32 offset;
307 	const u8 data[];
308 } __packed;
309 
310 /**
311  * struct iwl_tlv_calib_data - parse the default calib data from TLV
312  *
313  * @ucode_type: the uCode to which the following default calib relates.
314  * @calib: default calibrations.
315  */
316 struct iwl_tlv_calib_data {
317 	__le32 ucode_type;
318 	struct iwl_tlv_calib_ctrl calib;
319 } __packed;
320 
321 struct iwl_firmware_pieces {
322 	struct fw_img_parsing img[IWL_UCODE_TYPE_MAX];
323 
324 	u32 init_evtlog_ptr, init_evtlog_size, init_errlog_ptr;
325 	u32 inst_evtlog_ptr, inst_evtlog_size, inst_errlog_ptr;
326 
327 	/* FW debug data parsed for driver usage */
328 	bool dbg_dest_tlv_init;
329 	const u8 *dbg_dest_ver;
330 	union {
331 		const struct iwl_fw_dbg_dest_tlv *dbg_dest_tlv;
332 		const struct iwl_fw_dbg_dest_tlv_v1 *dbg_dest_tlv_v1;
333 	};
334 	const struct iwl_fw_dbg_conf_tlv *dbg_conf_tlv[FW_DBG_CONF_MAX];
335 	size_t dbg_conf_tlv_len[FW_DBG_CONF_MAX];
336 	const struct iwl_fw_dbg_trigger_tlv *dbg_trigger_tlv[FW_DBG_TRIGGER_MAX];
337 	size_t dbg_trigger_tlv_len[FW_DBG_TRIGGER_MAX];
338 	struct iwl_fw_dbg_mem_seg_tlv *dbg_mem_tlv;
339 	size_t n_mem_tlv;
340 };
341 
342 /*
343  * These functions are just to extract uCode section data from the pieces
344  * structure.
345  */
get_sec(struct iwl_firmware_pieces * pieces,enum iwl_ucode_type type,int sec)346 static struct fw_sec *get_sec(struct iwl_firmware_pieces *pieces,
347 			      enum iwl_ucode_type type,
348 			      int  sec)
349 {
350 	return &pieces->img[type].sec[sec];
351 }
352 
alloc_sec_data(struct iwl_firmware_pieces * pieces,enum iwl_ucode_type type,int sec)353 static void alloc_sec_data(struct iwl_firmware_pieces *pieces,
354 			   enum iwl_ucode_type type,
355 			   int sec)
356 {
357 	struct fw_img_parsing *img = &pieces->img[type];
358 	struct fw_sec *sec_memory;
359 	int size = sec + 1;
360 	size_t alloc_size = sizeof(*img->sec) * size;
361 
362 	if (img->sec && img->sec_counter >= size)
363 		return;
364 
365 	sec_memory = krealloc(img->sec, alloc_size, GFP_KERNEL);
366 	if (!sec_memory)
367 		return;
368 
369 	img->sec = sec_memory;
370 	img->sec_counter = size;
371 }
372 
set_sec_data(struct iwl_firmware_pieces * pieces,enum iwl_ucode_type type,int sec,const void * data)373 static void set_sec_data(struct iwl_firmware_pieces *pieces,
374 			 enum iwl_ucode_type type,
375 			 int sec,
376 			 const void *data)
377 {
378 	alloc_sec_data(pieces, type, sec);
379 
380 	pieces->img[type].sec[sec].data = data;
381 }
382 
set_sec_size(struct iwl_firmware_pieces * pieces,enum iwl_ucode_type type,int sec,size_t size)383 static void set_sec_size(struct iwl_firmware_pieces *pieces,
384 			 enum iwl_ucode_type type,
385 			 int sec,
386 			 size_t size)
387 {
388 	alloc_sec_data(pieces, type, sec);
389 
390 	pieces->img[type].sec[sec].size = size;
391 }
392 
get_sec_size(struct iwl_firmware_pieces * pieces,enum iwl_ucode_type type,int sec)393 static size_t get_sec_size(struct iwl_firmware_pieces *pieces,
394 			   enum iwl_ucode_type type,
395 			   int sec)
396 {
397 	return pieces->img[type].sec[sec].size;
398 }
399 
set_sec_offset(struct iwl_firmware_pieces * pieces,enum iwl_ucode_type type,int sec,u32 offset)400 static void set_sec_offset(struct iwl_firmware_pieces *pieces,
401 			   enum iwl_ucode_type type,
402 			   int sec,
403 			   u32 offset)
404 {
405 	alloc_sec_data(pieces, type, sec);
406 
407 	pieces->img[type].sec[sec].offset = offset;
408 }
409 
410 /*
411  * Gets uCode section from tlv.
412  */
iwl_store_ucode_sec(struct iwl_firmware_pieces * pieces,const void * data,enum iwl_ucode_type type,int size)413 static int iwl_store_ucode_sec(struct iwl_firmware_pieces *pieces,
414 			       const void *data, enum iwl_ucode_type type,
415 			       int size)
416 {
417 	struct fw_img_parsing *img;
418 	struct fw_sec *sec;
419 	const struct fw_sec_parsing *sec_parse;
420 	size_t alloc_size;
421 
422 	if (WARN_ON(!pieces || !data || type >= IWL_UCODE_TYPE_MAX))
423 		return -1;
424 
425 	sec_parse = (const struct fw_sec_parsing *)data;
426 
427 	img = &pieces->img[type];
428 
429 	alloc_size = sizeof(*img->sec) * (img->sec_counter + 1);
430 	sec = krealloc(img->sec, alloc_size, GFP_KERNEL);
431 	if (!sec)
432 		return -ENOMEM;
433 	img->sec = sec;
434 
435 	sec = &img->sec[img->sec_counter];
436 
437 	sec->offset = le32_to_cpu(sec_parse->offset);
438 	sec->data = sec_parse->data;
439 	sec->size = size - sizeof(sec_parse->offset);
440 
441 	++img->sec_counter;
442 
443 	return 0;
444 }
445 
iwl_set_default_calib(struct iwl_drv * drv,const u8 * data)446 static int iwl_set_default_calib(struct iwl_drv *drv, const u8 *data)
447 {
448 	const struct iwl_tlv_calib_data *def_calib =
449 					(const struct iwl_tlv_calib_data *)data;
450 	u32 ucode_type = le32_to_cpu(def_calib->ucode_type);
451 	if (ucode_type >= IWL_UCODE_TYPE_MAX) {
452 		IWL_ERR(drv, "Wrong ucode_type %u for default calibration.\n",
453 			ucode_type);
454 		return -EINVAL;
455 	}
456 	drv->fw.default_calib[ucode_type].flow_trigger =
457 		def_calib->calib.flow_trigger;
458 	drv->fw.default_calib[ucode_type].event_trigger =
459 		def_calib->calib.event_trigger;
460 
461 	return 0;
462 }
463 
iwl_set_ucode_api_flags(struct iwl_drv * drv,const u8 * data,struct iwl_ucode_capabilities * capa)464 static void iwl_set_ucode_api_flags(struct iwl_drv *drv, const u8 *data,
465 				    struct iwl_ucode_capabilities *capa)
466 {
467 	const struct iwl_ucode_api *ucode_api = (const void *)data;
468 	u32 api_index = le32_to_cpu(ucode_api->api_index);
469 	u32 api_flags = le32_to_cpu(ucode_api->api_flags);
470 	int i;
471 
472 	if (api_index >= DIV_ROUND_UP(NUM_IWL_UCODE_TLV_API, 32)) {
473 		IWL_WARN(drv,
474 			 "api flags index %d larger than supported by driver\n",
475 			 api_index);
476 		return;
477 	}
478 
479 	for (i = 0; i < 32; i++) {
480 		if (api_flags & BIT(i))
481 			__set_bit(i + 32 * api_index, capa->_api);
482 	}
483 }
484 
iwl_set_ucode_capabilities(struct iwl_drv * drv,const u8 * data,struct iwl_ucode_capabilities * capa)485 static void iwl_set_ucode_capabilities(struct iwl_drv *drv, const u8 *data,
486 				       struct iwl_ucode_capabilities *capa)
487 {
488 	const struct iwl_ucode_capa *ucode_capa = (const void *)data;
489 	u32 api_index = le32_to_cpu(ucode_capa->api_index);
490 	u32 api_flags = le32_to_cpu(ucode_capa->api_capa);
491 	int i;
492 
493 	if (api_index >= DIV_ROUND_UP(NUM_IWL_UCODE_TLV_CAPA, 32)) {
494 		IWL_WARN(drv,
495 			 "capa flags index %d larger than supported by driver\n",
496 			 api_index);
497 		return;
498 	}
499 
500 	for (i = 0; i < 32; i++) {
501 		if (api_flags & BIT(i))
502 			__set_bit(i + 32 * api_index, capa->_capa);
503 	}
504 }
505 
iwl_reduced_fw_name(struct iwl_drv * drv)506 static const char *iwl_reduced_fw_name(struct iwl_drv *drv)
507 {
508 	const char *name = drv->firmware_name;
509 
510 	if (strncmp(name, "iwlwifi-", 8) == 0)
511 		name += 8;
512 
513 	return name;
514 }
515 
iwl_parse_v1_v2_firmware(struct iwl_drv * drv,const struct firmware * ucode_raw,struct iwl_firmware_pieces * pieces)516 static int iwl_parse_v1_v2_firmware(struct iwl_drv *drv,
517 				    const struct firmware *ucode_raw,
518 				    struct iwl_firmware_pieces *pieces)
519 {
520 	const struct iwl_ucode_header *ucode = (const void *)ucode_raw->data;
521 	u32 api_ver, hdr_size, build;
522 	char buildstr[25];
523 	const u8 *src;
524 
525 	drv->fw.ucode_ver = le32_to_cpu(ucode->ver);
526 	api_ver = IWL_UCODE_API(drv->fw.ucode_ver);
527 
528 	switch (api_ver) {
529 	default:
530 		hdr_size = 28;
531 		if (ucode_raw->size < hdr_size) {
532 			IWL_ERR(drv, "File size too small!\n");
533 			return -EINVAL;
534 		}
535 		build = le32_to_cpu(ucode->u.v2.build);
536 		set_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_INST,
537 			     le32_to_cpu(ucode->u.v2.inst_size));
538 		set_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_DATA,
539 			     le32_to_cpu(ucode->u.v2.data_size));
540 		set_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST,
541 			     le32_to_cpu(ucode->u.v2.init_size));
542 		set_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA,
543 			     le32_to_cpu(ucode->u.v2.init_data_size));
544 		src = ucode->u.v2.data;
545 		break;
546 	case 0:
547 	case 1:
548 	case 2:
549 		hdr_size = 24;
550 		if (ucode_raw->size < hdr_size) {
551 			IWL_ERR(drv, "File size too small!\n");
552 			return -EINVAL;
553 		}
554 		build = 0;
555 		set_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_INST,
556 			     le32_to_cpu(ucode->u.v1.inst_size));
557 		set_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_DATA,
558 			     le32_to_cpu(ucode->u.v1.data_size));
559 		set_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST,
560 			     le32_to_cpu(ucode->u.v1.init_size));
561 		set_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA,
562 			     le32_to_cpu(ucode->u.v1.init_data_size));
563 		src = ucode->u.v1.data;
564 		break;
565 	}
566 
567 	if (build)
568 		sprintf(buildstr, " build %u", build);
569 	else
570 		buildstr[0] = '\0';
571 
572 	snprintf(drv->fw.fw_version,
573 		 sizeof(drv->fw.fw_version),
574 		 "%u.%u.%u.%u%s %s",
575 		 IWL_UCODE_MAJOR(drv->fw.ucode_ver),
576 		 IWL_UCODE_MINOR(drv->fw.ucode_ver),
577 		 IWL_UCODE_API(drv->fw.ucode_ver),
578 		 IWL_UCODE_SERIAL(drv->fw.ucode_ver),
579 		 buildstr, iwl_reduced_fw_name(drv));
580 
581 	/* Verify size of file vs. image size info in file's header */
582 
583 	if (ucode_raw->size != hdr_size +
584 	    get_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_INST) +
585 	    get_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_DATA) +
586 	    get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST) +
587 	    get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA)) {
588 
589 		IWL_ERR(drv,
590 			"uCode file size %d does not match expected size\n",
591 			(int)ucode_raw->size);
592 		return -EINVAL;
593 	}
594 
595 
596 	set_sec_data(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_INST, src);
597 	src += get_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_INST);
598 	set_sec_offset(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_INST,
599 		       IWLAGN_RTC_INST_LOWER_BOUND);
600 	set_sec_data(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_DATA, src);
601 	src += get_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_DATA);
602 	set_sec_offset(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_DATA,
603 		       IWLAGN_RTC_DATA_LOWER_BOUND);
604 	set_sec_data(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST, src);
605 	src += get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST);
606 	set_sec_offset(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST,
607 		       IWLAGN_RTC_INST_LOWER_BOUND);
608 	set_sec_data(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA, src);
609 	src += get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA);
610 	set_sec_offset(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA,
611 		       IWLAGN_RTC_DATA_LOWER_BOUND);
612 	return 0;
613 }
614 
iwl_drv_set_dump_exclude(struct iwl_drv * drv,enum iwl_ucode_tlv_type tlv_type,const void * tlv_data,u32 tlv_len)615 static void iwl_drv_set_dump_exclude(struct iwl_drv *drv,
616 				     enum iwl_ucode_tlv_type tlv_type,
617 				     const void *tlv_data, u32 tlv_len)
618 {
619 	const struct iwl_fw_dump_exclude *fw = tlv_data;
620 	struct iwl_dump_exclude *excl;
621 
622 	if (tlv_len < sizeof(*fw))
623 		return;
624 
625 	if (tlv_type == IWL_UCODE_TLV_SEC_TABLE_ADDR) {
626 		excl = &drv->fw.dump_excl[0];
627 
628 		/* second time we find this, it's for WoWLAN */
629 		if (excl->addr)
630 			excl = &drv->fw.dump_excl_wowlan[0];
631 	} else if (fw_has_capa(&drv->fw.ucode_capa,
632 			       IWL_UCODE_TLV_CAPA_CNSLDTD_D3_D0_IMG)) {
633 		/* IWL_UCODE_TLV_D3_KEK_KCK_ADDR is regular image */
634 		excl = &drv->fw.dump_excl[0];
635 	} else {
636 		/* IWL_UCODE_TLV_D3_KEK_KCK_ADDR is WoWLAN image */
637 		excl = &drv->fw.dump_excl_wowlan[0];
638 	}
639 
640 	if (excl->addr)
641 		excl++;
642 
643 	if (excl->addr) {
644 		IWL_DEBUG_FW_INFO(drv, "found too many excludes in fw file\n");
645 		return;
646 	}
647 
648 	excl->addr = le32_to_cpu(fw->addr) & ~FW_ADDR_CACHE_CONTROL;
649 	excl->size = le32_to_cpu(fw->size);
650 }
651 
iwl_parse_dbg_tlv_assert_tables(struct iwl_drv * drv,const struct iwl_ucode_tlv * tlv)652 static void iwl_parse_dbg_tlv_assert_tables(struct iwl_drv *drv,
653 					    const struct iwl_ucode_tlv *tlv)
654 {
655 	const struct iwl_fw_ini_region_tlv *region;
656 	u32 length = le32_to_cpu(tlv->length);
657 	u32 addr;
658 
659 	if (length < offsetof(typeof(*region), special_mem) +
660 		     sizeof(region->special_mem))
661 		return;
662 
663 	region = (const void *)tlv->data;
664 	addr = le32_to_cpu(region->special_mem.base_addr);
665 	addr += le32_to_cpu(region->special_mem.offset);
666 	addr &= ~FW_ADDR_CACHE_CONTROL;
667 
668 	if (region->type != IWL_FW_INI_REGION_SPECIAL_DEVICE_MEMORY)
669 		return;
670 
671 	switch (region->sub_type) {
672 	case IWL_FW_INI_REGION_DEVICE_MEMORY_SUBTYPE_UMAC_ERROR_TABLE:
673 		drv->trans->dbg.umac_error_event_table = addr;
674 		drv->trans->dbg.error_event_table_tlv_status |=
675 			IWL_ERROR_EVENT_TABLE_UMAC;
676 		break;
677 	case IWL_FW_INI_REGION_DEVICE_MEMORY_SUBTYPE_LMAC_1_ERROR_TABLE:
678 		drv->trans->dbg.lmac_error_event_table[0] = addr;
679 		drv->trans->dbg.error_event_table_tlv_status |=
680 			IWL_ERROR_EVENT_TABLE_LMAC1;
681 		break;
682 	case IWL_FW_INI_REGION_DEVICE_MEMORY_SUBTYPE_LMAC_2_ERROR_TABLE:
683 		drv->trans->dbg.lmac_error_event_table[1] = addr;
684 		drv->trans->dbg.error_event_table_tlv_status |=
685 			IWL_ERROR_EVENT_TABLE_LMAC2;
686 		break;
687 	case IWL_FW_INI_REGION_DEVICE_MEMORY_SUBTYPE_TCM_1_ERROR_TABLE:
688 		drv->trans->dbg.tcm_error_event_table[0] = addr;
689 		drv->trans->dbg.error_event_table_tlv_status |=
690 			IWL_ERROR_EVENT_TABLE_TCM1;
691 		break;
692 	case IWL_FW_INI_REGION_DEVICE_MEMORY_SUBTYPE_TCM_2_ERROR_TABLE:
693 		drv->trans->dbg.tcm_error_event_table[1] = addr;
694 		drv->trans->dbg.error_event_table_tlv_status |=
695 			IWL_ERROR_EVENT_TABLE_TCM2;
696 		break;
697 	case IWL_FW_INI_REGION_DEVICE_MEMORY_SUBTYPE_RCM_1_ERROR_TABLE:
698 		drv->trans->dbg.rcm_error_event_table[0] = addr;
699 		drv->trans->dbg.error_event_table_tlv_status |=
700 			IWL_ERROR_EVENT_TABLE_RCM1;
701 		break;
702 	case IWL_FW_INI_REGION_DEVICE_MEMORY_SUBTYPE_RCM_2_ERROR_TABLE:
703 		drv->trans->dbg.rcm_error_event_table[1] = addr;
704 		drv->trans->dbg.error_event_table_tlv_status |=
705 			IWL_ERROR_EVENT_TABLE_RCM2;
706 		break;
707 	default:
708 		break;
709 	}
710 }
711 
iwl_parse_tlv_firmware(struct iwl_drv * drv,const struct firmware * ucode_raw,struct iwl_firmware_pieces * pieces,struct iwl_ucode_capabilities * capa,bool * usniffer_images)712 static int iwl_parse_tlv_firmware(struct iwl_drv *drv,
713 				const struct firmware *ucode_raw,
714 				struct iwl_firmware_pieces *pieces,
715 				struct iwl_ucode_capabilities *capa,
716 				bool *usniffer_images)
717 {
718 	const struct iwl_tlv_ucode_header *ucode = (const void *)ucode_raw->data;
719 	const struct iwl_ucode_tlv *tlv;
720 	size_t len = ucode_raw->size;
721 	const u8 *data;
722 	u32 tlv_len;
723 	u32 usniffer_img;
724 	enum iwl_ucode_tlv_type tlv_type;
725 	const u8 *tlv_data;
726 	char buildstr[25];
727 	u32 build, paging_mem_size;
728 	int num_of_cpus;
729 	bool usniffer_req = false;
730 
731 	if (len < sizeof(*ucode)) {
732 		IWL_ERR(drv, "uCode has invalid length: %zd\n", len);
733 		return -EINVAL;
734 	}
735 
736 	if (ucode->magic != cpu_to_le32(IWL_TLV_UCODE_MAGIC)) {
737 		IWL_ERR(drv, "invalid uCode magic: 0X%x\n",
738 			le32_to_cpu(ucode->magic));
739 		return -EINVAL;
740 	}
741 
742 	drv->fw.ucode_ver = le32_to_cpu(ucode->ver);
743 	memcpy(drv->fw.human_readable, ucode->human_readable,
744 	       sizeof(drv->fw.human_readable));
745 	build = le32_to_cpu(ucode->build);
746 
747 	if (build)
748 		sprintf(buildstr, " build %u", build);
749 	else
750 		buildstr[0] = '\0';
751 
752 	snprintf(drv->fw.fw_version,
753 		 sizeof(drv->fw.fw_version),
754 		 "%u.%u.%u.%u%s %s",
755 		 IWL_UCODE_MAJOR(drv->fw.ucode_ver),
756 		 IWL_UCODE_MINOR(drv->fw.ucode_ver),
757 		 IWL_UCODE_API(drv->fw.ucode_ver),
758 		 IWL_UCODE_SERIAL(drv->fw.ucode_ver),
759 		 buildstr, iwl_reduced_fw_name(drv));
760 
761 	data = ucode->data;
762 
763 	len -= sizeof(*ucode);
764 
765 	while (len >= sizeof(*tlv)) {
766 		len -= sizeof(*tlv);
767 
768 		tlv = (const void *)data;
769 		tlv_len = le32_to_cpu(tlv->length);
770 		tlv_type = le32_to_cpu(tlv->type);
771 		tlv_data = tlv->data;
772 
773 		if (len < tlv_len) {
774 			IWL_ERR(drv, "invalid TLV len: %zd/%u\n",
775 				len, tlv_len);
776 			return -EINVAL;
777 		}
778 		len -= ALIGN(tlv_len, 4);
779 		data += sizeof(*tlv) + ALIGN(tlv_len, 4);
780 
781 		switch (tlv_type) {
782 		case IWL_UCODE_TLV_INST:
783 			set_sec_data(pieces, IWL_UCODE_REGULAR,
784 				     IWL_UCODE_SECTION_INST, tlv_data);
785 			set_sec_size(pieces, IWL_UCODE_REGULAR,
786 				     IWL_UCODE_SECTION_INST, tlv_len);
787 			set_sec_offset(pieces, IWL_UCODE_REGULAR,
788 				       IWL_UCODE_SECTION_INST,
789 				       IWLAGN_RTC_INST_LOWER_BOUND);
790 			break;
791 		case IWL_UCODE_TLV_DATA:
792 			set_sec_data(pieces, IWL_UCODE_REGULAR,
793 				     IWL_UCODE_SECTION_DATA, tlv_data);
794 			set_sec_size(pieces, IWL_UCODE_REGULAR,
795 				     IWL_UCODE_SECTION_DATA, tlv_len);
796 			set_sec_offset(pieces, IWL_UCODE_REGULAR,
797 				       IWL_UCODE_SECTION_DATA,
798 				       IWLAGN_RTC_DATA_LOWER_BOUND);
799 			break;
800 		case IWL_UCODE_TLV_INIT:
801 			set_sec_data(pieces, IWL_UCODE_INIT,
802 				     IWL_UCODE_SECTION_INST, tlv_data);
803 			set_sec_size(pieces, IWL_UCODE_INIT,
804 				     IWL_UCODE_SECTION_INST, tlv_len);
805 			set_sec_offset(pieces, IWL_UCODE_INIT,
806 				       IWL_UCODE_SECTION_INST,
807 				       IWLAGN_RTC_INST_LOWER_BOUND);
808 			break;
809 		case IWL_UCODE_TLV_INIT_DATA:
810 			set_sec_data(pieces, IWL_UCODE_INIT,
811 				     IWL_UCODE_SECTION_DATA, tlv_data);
812 			set_sec_size(pieces, IWL_UCODE_INIT,
813 				     IWL_UCODE_SECTION_DATA, tlv_len);
814 			set_sec_offset(pieces, IWL_UCODE_INIT,
815 				       IWL_UCODE_SECTION_DATA,
816 				       IWLAGN_RTC_DATA_LOWER_BOUND);
817 			break;
818 		case IWL_UCODE_TLV_BOOT:
819 			IWL_ERR(drv, "Found unexpected BOOT ucode\n");
820 			break;
821 		case IWL_UCODE_TLV_PROBE_MAX_LEN:
822 			if (tlv_len != sizeof(u32))
823 				goto invalid_tlv_len;
824 			capa->max_probe_length =
825 					le32_to_cpup((const __le32 *)tlv_data);
826 			break;
827 		case IWL_UCODE_TLV_PAN:
828 			if (tlv_len)
829 				goto invalid_tlv_len;
830 			capa->flags |= IWL_UCODE_TLV_FLAGS_PAN;
831 			break;
832 		case IWL_UCODE_TLV_FLAGS:
833 			/* must be at least one u32 */
834 			if (tlv_len < sizeof(u32))
835 				goto invalid_tlv_len;
836 			/* and a proper number of u32s */
837 			if (tlv_len % sizeof(u32))
838 				goto invalid_tlv_len;
839 			/*
840 			 * This driver only reads the first u32 as
841 			 * right now no more features are defined,
842 			 * if that changes then either the driver
843 			 * will not work with the new firmware, or
844 			 * it'll not take advantage of new features.
845 			 */
846 			capa->flags = le32_to_cpup((const __le32 *)tlv_data);
847 			break;
848 		case IWL_UCODE_TLV_API_CHANGES_SET:
849 			if (tlv_len != sizeof(struct iwl_ucode_api))
850 				goto invalid_tlv_len;
851 			iwl_set_ucode_api_flags(drv, tlv_data, capa);
852 			break;
853 		case IWL_UCODE_TLV_ENABLED_CAPABILITIES:
854 			if (tlv_len != sizeof(struct iwl_ucode_capa))
855 				goto invalid_tlv_len;
856 			iwl_set_ucode_capabilities(drv, tlv_data, capa);
857 			break;
858 		case IWL_UCODE_TLV_INIT_EVTLOG_PTR:
859 			if (tlv_len != sizeof(u32))
860 				goto invalid_tlv_len;
861 			pieces->init_evtlog_ptr =
862 					le32_to_cpup((const __le32 *)tlv_data);
863 			break;
864 		case IWL_UCODE_TLV_INIT_EVTLOG_SIZE:
865 			if (tlv_len != sizeof(u32))
866 				goto invalid_tlv_len;
867 			pieces->init_evtlog_size =
868 					le32_to_cpup((const __le32 *)tlv_data);
869 			break;
870 		case IWL_UCODE_TLV_INIT_ERRLOG_PTR:
871 			if (tlv_len != sizeof(u32))
872 				goto invalid_tlv_len;
873 			pieces->init_errlog_ptr =
874 					le32_to_cpup((const __le32 *)tlv_data);
875 			break;
876 		case IWL_UCODE_TLV_RUNT_EVTLOG_PTR:
877 			if (tlv_len != sizeof(u32))
878 				goto invalid_tlv_len;
879 			pieces->inst_evtlog_ptr =
880 					le32_to_cpup((const __le32 *)tlv_data);
881 			break;
882 		case IWL_UCODE_TLV_RUNT_EVTLOG_SIZE:
883 			if (tlv_len != sizeof(u32))
884 				goto invalid_tlv_len;
885 			pieces->inst_evtlog_size =
886 					le32_to_cpup((const __le32 *)tlv_data);
887 			break;
888 		case IWL_UCODE_TLV_RUNT_ERRLOG_PTR:
889 			if (tlv_len != sizeof(u32))
890 				goto invalid_tlv_len;
891 			pieces->inst_errlog_ptr =
892 					le32_to_cpup((const __le32 *)tlv_data);
893 			break;
894 		case IWL_UCODE_TLV_ENHANCE_SENS_TBL:
895 			if (tlv_len)
896 				goto invalid_tlv_len;
897 			drv->fw.enhance_sensitivity_table = true;
898 			break;
899 		case IWL_UCODE_TLV_WOWLAN_INST:
900 			set_sec_data(pieces, IWL_UCODE_WOWLAN,
901 				     IWL_UCODE_SECTION_INST, tlv_data);
902 			set_sec_size(pieces, IWL_UCODE_WOWLAN,
903 				     IWL_UCODE_SECTION_INST, tlv_len);
904 			set_sec_offset(pieces, IWL_UCODE_WOWLAN,
905 				       IWL_UCODE_SECTION_INST,
906 				       IWLAGN_RTC_INST_LOWER_BOUND);
907 			break;
908 		case IWL_UCODE_TLV_WOWLAN_DATA:
909 			set_sec_data(pieces, IWL_UCODE_WOWLAN,
910 				     IWL_UCODE_SECTION_DATA, tlv_data);
911 			set_sec_size(pieces, IWL_UCODE_WOWLAN,
912 				     IWL_UCODE_SECTION_DATA, tlv_len);
913 			set_sec_offset(pieces, IWL_UCODE_WOWLAN,
914 				       IWL_UCODE_SECTION_DATA,
915 				       IWLAGN_RTC_DATA_LOWER_BOUND);
916 			break;
917 		case IWL_UCODE_TLV_PHY_CALIBRATION_SIZE:
918 			if (tlv_len != sizeof(u32))
919 				goto invalid_tlv_len;
920 			capa->standard_phy_calibration_size =
921 					le32_to_cpup((const __le32 *)tlv_data);
922 			break;
923 		case IWL_UCODE_TLV_SEC_RT:
924 			iwl_store_ucode_sec(pieces, tlv_data, IWL_UCODE_REGULAR,
925 					    tlv_len);
926 			drv->fw.type = IWL_FW_MVM;
927 			break;
928 		case IWL_UCODE_TLV_SEC_INIT:
929 			iwl_store_ucode_sec(pieces, tlv_data, IWL_UCODE_INIT,
930 					    tlv_len);
931 			drv->fw.type = IWL_FW_MVM;
932 			break;
933 		case IWL_UCODE_TLV_SEC_WOWLAN:
934 			iwl_store_ucode_sec(pieces, tlv_data, IWL_UCODE_WOWLAN,
935 					    tlv_len);
936 			drv->fw.type = IWL_FW_MVM;
937 			break;
938 		case IWL_UCODE_TLV_DEF_CALIB:
939 			if (tlv_len != sizeof(struct iwl_tlv_calib_data))
940 				goto invalid_tlv_len;
941 			if (iwl_set_default_calib(drv, tlv_data))
942 				goto tlv_error;
943 			break;
944 		case IWL_UCODE_TLV_PHY_SKU:
945 			if (tlv_len != sizeof(u32))
946 				goto invalid_tlv_len;
947 			drv->fw.phy_config = le32_to_cpup((const __le32 *)tlv_data);
948 			drv->fw.valid_tx_ant = (drv->fw.phy_config &
949 						FW_PHY_CFG_TX_CHAIN) >>
950 						FW_PHY_CFG_TX_CHAIN_POS;
951 			drv->fw.valid_rx_ant = (drv->fw.phy_config &
952 						FW_PHY_CFG_RX_CHAIN) >>
953 						FW_PHY_CFG_RX_CHAIN_POS;
954 			break;
955 		case IWL_UCODE_TLV_SECURE_SEC_RT:
956 			iwl_store_ucode_sec(pieces, tlv_data, IWL_UCODE_REGULAR,
957 					    tlv_len);
958 			drv->fw.type = IWL_FW_MVM;
959 			break;
960 		case IWL_UCODE_TLV_SECURE_SEC_INIT:
961 			iwl_store_ucode_sec(pieces, tlv_data, IWL_UCODE_INIT,
962 					    tlv_len);
963 			drv->fw.type = IWL_FW_MVM;
964 			break;
965 		case IWL_UCODE_TLV_SECURE_SEC_WOWLAN:
966 			iwl_store_ucode_sec(pieces, tlv_data, IWL_UCODE_WOWLAN,
967 					    tlv_len);
968 			drv->fw.type = IWL_FW_MVM;
969 			break;
970 		case IWL_UCODE_TLV_NUM_OF_CPU:
971 			if (tlv_len != sizeof(u32))
972 				goto invalid_tlv_len;
973 			num_of_cpus =
974 				le32_to_cpup((const __le32 *)tlv_data);
975 
976 			if (num_of_cpus == 2) {
977 				drv->fw.img[IWL_UCODE_REGULAR].is_dual_cpus =
978 					true;
979 				drv->fw.img[IWL_UCODE_INIT].is_dual_cpus =
980 					true;
981 				drv->fw.img[IWL_UCODE_WOWLAN].is_dual_cpus =
982 					true;
983 			} else if ((num_of_cpus > 2) || (num_of_cpus < 1)) {
984 				IWL_ERR(drv, "Driver support up to 2 CPUs\n");
985 				return -EINVAL;
986 			}
987 			break;
988 		case IWL_UCODE_TLV_N_SCAN_CHANNELS:
989 			if (tlv_len != sizeof(u32))
990 				goto invalid_tlv_len;
991 			capa->n_scan_channels =
992 				le32_to_cpup((const __le32 *)tlv_data);
993 			break;
994 		case IWL_UCODE_TLV_FW_VERSION: {
995 			const __le32 *ptr = (const void *)tlv_data;
996 			u32 major, minor;
997 			u8 local_comp;
998 
999 			if (tlv_len != sizeof(u32) * 3)
1000 				goto invalid_tlv_len;
1001 
1002 			major = le32_to_cpup(ptr++);
1003 			minor = le32_to_cpup(ptr++);
1004 			local_comp = le32_to_cpup(ptr);
1005 
1006 			snprintf(drv->fw.fw_version,
1007 				 sizeof(drv->fw.fw_version),
1008 				 "%u.%08x.%u %s", major, minor,
1009 				 local_comp, iwl_reduced_fw_name(drv));
1010 			break;
1011 			}
1012 		case IWL_UCODE_TLV_FW_DBG_DEST: {
1013 			const struct iwl_fw_dbg_dest_tlv *dest = NULL;
1014 			const struct iwl_fw_dbg_dest_tlv_v1 *dest_v1 = NULL;
1015 			u8 mon_mode;
1016 
1017 			pieces->dbg_dest_ver = (const u8 *)tlv_data;
1018 			if (*pieces->dbg_dest_ver == 1) {
1019 				dest = (const void *)tlv_data;
1020 			} else if (*pieces->dbg_dest_ver == 0) {
1021 				dest_v1 = (const void *)tlv_data;
1022 			} else {
1023 				IWL_ERR(drv,
1024 					"The version is %d, and it is invalid\n",
1025 					*pieces->dbg_dest_ver);
1026 				break;
1027 			}
1028 
1029 			if (pieces->dbg_dest_tlv_init) {
1030 				IWL_ERR(drv,
1031 					"dbg destination ignored, already exists\n");
1032 				break;
1033 			}
1034 
1035 			pieces->dbg_dest_tlv_init = true;
1036 
1037 			if (dest_v1) {
1038 				pieces->dbg_dest_tlv_v1 = dest_v1;
1039 				mon_mode = dest_v1->monitor_mode;
1040 			} else {
1041 				pieces->dbg_dest_tlv = dest;
1042 				mon_mode = dest->monitor_mode;
1043 			}
1044 
1045 			IWL_INFO(drv, "Found debug destination: %s\n",
1046 				 get_fw_dbg_mode_string(mon_mode));
1047 
1048 			drv->fw.dbg.n_dest_reg = (dest_v1) ?
1049 				tlv_len -
1050 				offsetof(struct iwl_fw_dbg_dest_tlv_v1,
1051 					 reg_ops) :
1052 				tlv_len -
1053 				offsetof(struct iwl_fw_dbg_dest_tlv,
1054 					 reg_ops);
1055 
1056 			drv->fw.dbg.n_dest_reg /=
1057 				sizeof(drv->fw.dbg.dest_tlv->reg_ops[0]);
1058 
1059 			break;
1060 			}
1061 		case IWL_UCODE_TLV_FW_DBG_CONF: {
1062 			const struct iwl_fw_dbg_conf_tlv *conf =
1063 				(const void *)tlv_data;
1064 
1065 			if (!pieces->dbg_dest_tlv_init) {
1066 				IWL_ERR(drv,
1067 					"Ignore dbg config %d - no destination configured\n",
1068 					conf->id);
1069 				break;
1070 			}
1071 
1072 			if (conf->id >= ARRAY_SIZE(drv->fw.dbg.conf_tlv)) {
1073 				IWL_ERR(drv,
1074 					"Skip unknown configuration: %d\n",
1075 					conf->id);
1076 				break;
1077 			}
1078 
1079 			if (pieces->dbg_conf_tlv[conf->id]) {
1080 				IWL_ERR(drv,
1081 					"Ignore duplicate dbg config %d\n",
1082 					conf->id);
1083 				break;
1084 			}
1085 
1086 			if (conf->usniffer)
1087 				usniffer_req = true;
1088 
1089 			IWL_INFO(drv, "Found debug configuration: %d\n",
1090 				 conf->id);
1091 
1092 			pieces->dbg_conf_tlv[conf->id] = conf;
1093 			pieces->dbg_conf_tlv_len[conf->id] = tlv_len;
1094 			break;
1095 			}
1096 		case IWL_UCODE_TLV_FW_DBG_TRIGGER: {
1097 			const struct iwl_fw_dbg_trigger_tlv *trigger =
1098 				(const void *)tlv_data;
1099 			u32 trigger_id = le32_to_cpu(trigger->id);
1100 
1101 			if (trigger_id >= ARRAY_SIZE(drv->fw.dbg.trigger_tlv)) {
1102 				IWL_ERR(drv,
1103 					"Skip unknown trigger: %u\n",
1104 					trigger->id);
1105 				break;
1106 			}
1107 
1108 			if (pieces->dbg_trigger_tlv[trigger_id]) {
1109 				IWL_ERR(drv,
1110 					"Ignore duplicate dbg trigger %u\n",
1111 					trigger->id);
1112 				break;
1113 			}
1114 
1115 			IWL_INFO(drv, "Found debug trigger: %u\n", trigger->id);
1116 
1117 			pieces->dbg_trigger_tlv[trigger_id] = trigger;
1118 			pieces->dbg_trigger_tlv_len[trigger_id] = tlv_len;
1119 			break;
1120 			}
1121 		case IWL_UCODE_TLV_FW_DBG_DUMP_LST: {
1122 			if (tlv_len != sizeof(u32)) {
1123 				IWL_ERR(drv,
1124 					"dbg lst mask size incorrect, skip\n");
1125 				break;
1126 			}
1127 
1128 			drv->fw.dbg.dump_mask =
1129 				le32_to_cpup((const __le32 *)tlv_data);
1130 			break;
1131 			}
1132 		case IWL_UCODE_TLV_SEC_RT_USNIFFER:
1133 			*usniffer_images = true;
1134 			iwl_store_ucode_sec(pieces, tlv_data,
1135 					    IWL_UCODE_REGULAR_USNIFFER,
1136 					    tlv_len);
1137 			break;
1138 		case IWL_UCODE_TLV_PAGING:
1139 			if (tlv_len != sizeof(u32))
1140 				goto invalid_tlv_len;
1141 			paging_mem_size = le32_to_cpup((const __le32 *)tlv_data);
1142 
1143 			IWL_DEBUG_FW(drv,
1144 				     "Paging: paging enabled (size = %u bytes)\n",
1145 				     paging_mem_size);
1146 
1147 			if (paging_mem_size > MAX_PAGING_IMAGE_SIZE) {
1148 				IWL_ERR(drv,
1149 					"Paging: driver supports up to %lu bytes for paging image\n",
1150 					MAX_PAGING_IMAGE_SIZE);
1151 				return -EINVAL;
1152 			}
1153 
1154 			if (paging_mem_size & (FW_PAGING_SIZE - 1)) {
1155 				IWL_ERR(drv,
1156 					"Paging: image isn't multiple %lu\n",
1157 					FW_PAGING_SIZE);
1158 				return -EINVAL;
1159 			}
1160 
1161 			drv->fw.img[IWL_UCODE_REGULAR].paging_mem_size =
1162 				paging_mem_size;
1163 			usniffer_img = IWL_UCODE_REGULAR_USNIFFER;
1164 			drv->fw.img[usniffer_img].paging_mem_size =
1165 				paging_mem_size;
1166 			break;
1167 		case IWL_UCODE_TLV_FW_GSCAN_CAPA:
1168 			/* ignored */
1169 			break;
1170 		case IWL_UCODE_TLV_FW_MEM_SEG: {
1171 			const struct iwl_fw_dbg_mem_seg_tlv *dbg_mem =
1172 				(const void *)tlv_data;
1173 			size_t size;
1174 			struct iwl_fw_dbg_mem_seg_tlv *n;
1175 
1176 			if (tlv_len != (sizeof(*dbg_mem)))
1177 				goto invalid_tlv_len;
1178 
1179 			IWL_DEBUG_INFO(drv, "Found debug memory segment: %u\n",
1180 				       dbg_mem->data_type);
1181 
1182 			size = sizeof(*pieces->dbg_mem_tlv) *
1183 			       (pieces->n_mem_tlv + 1);
1184 			n = krealloc(pieces->dbg_mem_tlv, size, GFP_KERNEL);
1185 			if (!n)
1186 				return -ENOMEM;
1187 			pieces->dbg_mem_tlv = n;
1188 			pieces->dbg_mem_tlv[pieces->n_mem_tlv] = *dbg_mem;
1189 			pieces->n_mem_tlv++;
1190 			break;
1191 			}
1192 		case IWL_UCODE_TLV_IML: {
1193 			drv->fw.iml_len = tlv_len;
1194 			drv->fw.iml = kmemdup(tlv_data, tlv_len, GFP_KERNEL);
1195 			if (!drv->fw.iml)
1196 				return -ENOMEM;
1197 			break;
1198 			}
1199 		case IWL_UCODE_TLV_FW_RECOVERY_INFO: {
1200 			const struct {
1201 				__le32 buf_addr;
1202 				__le32 buf_size;
1203 			} *recov_info = (const void *)tlv_data;
1204 
1205 			if (tlv_len != sizeof(*recov_info))
1206 				goto invalid_tlv_len;
1207 			capa->error_log_addr =
1208 				le32_to_cpu(recov_info->buf_addr);
1209 			capa->error_log_size =
1210 				le32_to_cpu(recov_info->buf_size);
1211 			}
1212 			break;
1213 		case IWL_UCODE_TLV_FW_FSEQ_VERSION: {
1214 			const struct {
1215 				u8 version[32];
1216 				u8 sha1[20];
1217 			} *fseq_ver = (const void *)tlv_data;
1218 
1219 			if (tlv_len != sizeof(*fseq_ver))
1220 				goto invalid_tlv_len;
1221 			IWL_INFO(drv, "TLV_FW_FSEQ_VERSION: %s\n",
1222 				 fseq_ver->version);
1223 			}
1224 			break;
1225 		case IWL_UCODE_TLV_FW_NUM_STATIONS:
1226 			if (tlv_len != sizeof(u32))
1227 				goto invalid_tlv_len;
1228 			if (le32_to_cpup((const __le32 *)tlv_data) >
1229 			    IWL_MVM_STATION_COUNT_MAX) {
1230 				IWL_ERR(drv,
1231 					"%d is an invalid number of station\n",
1232 					le32_to_cpup((const __le32 *)tlv_data));
1233 				goto tlv_error;
1234 			}
1235 			capa->num_stations =
1236 				le32_to_cpup((const __le32 *)tlv_data);
1237 			break;
1238 		case IWL_UCODE_TLV_FW_NUM_BEACONS:
1239 			if (tlv_len != sizeof(u32))
1240 				goto invalid_tlv_len;
1241 			capa->num_beacons =
1242 				le32_to_cpup((const __le32 *)tlv_data);
1243 			break;
1244 		case IWL_UCODE_TLV_UMAC_DEBUG_ADDRS: {
1245 			const struct iwl_umac_debug_addrs *dbg_ptrs =
1246 				(const void *)tlv_data;
1247 
1248 			if (tlv_len != sizeof(*dbg_ptrs))
1249 				goto invalid_tlv_len;
1250 			if (drv->trans->trans_cfg->device_family <
1251 			    IWL_DEVICE_FAMILY_22000)
1252 				break;
1253 			drv->trans->dbg.umac_error_event_table =
1254 				le32_to_cpu(dbg_ptrs->error_info_addr) &
1255 				~FW_ADDR_CACHE_CONTROL;
1256 			drv->trans->dbg.error_event_table_tlv_status |=
1257 				IWL_ERROR_EVENT_TABLE_UMAC;
1258 			break;
1259 			}
1260 		case IWL_UCODE_TLV_LMAC_DEBUG_ADDRS: {
1261 			const struct iwl_lmac_debug_addrs *dbg_ptrs =
1262 				(const void *)tlv_data;
1263 
1264 			if (tlv_len != sizeof(*dbg_ptrs))
1265 				goto invalid_tlv_len;
1266 			if (drv->trans->trans_cfg->device_family <
1267 			    IWL_DEVICE_FAMILY_22000)
1268 				break;
1269 			drv->trans->dbg.lmac_error_event_table[0] =
1270 				le32_to_cpu(dbg_ptrs->error_event_table_ptr) &
1271 				~FW_ADDR_CACHE_CONTROL;
1272 			drv->trans->dbg.error_event_table_tlv_status |=
1273 				IWL_ERROR_EVENT_TABLE_LMAC1;
1274 			break;
1275 			}
1276 		case IWL_UCODE_TLV_TYPE_REGIONS:
1277 			iwl_parse_dbg_tlv_assert_tables(drv, tlv);
1278 			fallthrough;
1279 		case IWL_UCODE_TLV_TYPE_DEBUG_INFO:
1280 		case IWL_UCODE_TLV_TYPE_BUFFER_ALLOCATION:
1281 		case IWL_UCODE_TLV_TYPE_HCMD:
1282 		case IWL_UCODE_TLV_TYPE_TRIGGERS:
1283 		case IWL_UCODE_TLV_TYPE_CONF_SET:
1284 			if (iwlwifi_mod_params.enable_ini)
1285 				iwl_dbg_tlv_alloc(drv->trans, tlv, false);
1286 			break;
1287 		case IWL_UCODE_TLV_CMD_VERSIONS:
1288 			if (tlv_len % sizeof(struct iwl_fw_cmd_version)) {
1289 				IWL_ERR(drv,
1290 					"Invalid length for command versions: %u\n",
1291 					tlv_len);
1292 				tlv_len /= sizeof(struct iwl_fw_cmd_version);
1293 				tlv_len *= sizeof(struct iwl_fw_cmd_version);
1294 			}
1295 			if (WARN_ON(capa->cmd_versions))
1296 				return -EINVAL;
1297 			capa->cmd_versions = kmemdup(tlv_data, tlv_len,
1298 						     GFP_KERNEL);
1299 			if (!capa->cmd_versions)
1300 				return -ENOMEM;
1301 			capa->n_cmd_versions =
1302 				tlv_len / sizeof(struct iwl_fw_cmd_version);
1303 			break;
1304 		case IWL_UCODE_TLV_PHY_INTEGRATION_VERSION:
1305 			if (drv->fw.phy_integration_ver) {
1306 				IWL_ERR(drv,
1307 					"phy integration str ignored, already exists\n");
1308 				break;
1309 			}
1310 
1311 			drv->fw.phy_integration_ver =
1312 				kmemdup(tlv_data, tlv_len, GFP_KERNEL);
1313 			if (!drv->fw.phy_integration_ver)
1314 				return -ENOMEM;
1315 			drv->fw.phy_integration_ver_len = tlv_len;
1316 			break;
1317 		case IWL_UCODE_TLV_SEC_TABLE_ADDR:
1318 		case IWL_UCODE_TLV_D3_KEK_KCK_ADDR:
1319 			iwl_drv_set_dump_exclude(drv, tlv_type,
1320 						 tlv_data, tlv_len);
1321 			break;
1322 		case IWL_UCODE_TLV_CURRENT_PC:
1323 			if (tlv_len < sizeof(struct iwl_pc_data))
1324 				goto invalid_tlv_len;
1325 			drv->trans->dbg.pc_data =
1326 				kmemdup(tlv_data, tlv_len, GFP_KERNEL);
1327 			if (!drv->trans->dbg.pc_data)
1328 				return -ENOMEM;
1329 			drv->trans->dbg.num_pc =
1330 				tlv_len / sizeof(struct iwl_pc_data);
1331 			break;
1332 		default:
1333 			IWL_DEBUG_INFO(drv, "unknown TLV: %d\n", tlv_type);
1334 			break;
1335 		}
1336 	}
1337 
1338 	if (!fw_has_capa(capa, IWL_UCODE_TLV_CAPA_USNIFFER_UNIFIED) &&
1339 	    usniffer_req && !*usniffer_images) {
1340 		IWL_ERR(drv,
1341 			"user selected to work with usniffer but usniffer image isn't available in ucode package\n");
1342 		return -EINVAL;
1343 	}
1344 
1345 	if (len) {
1346 		IWL_ERR(drv, "invalid TLV after parsing: %zd\n", len);
1347 #if defined(__linux__)
1348 		iwl_print_hex_dump(drv, IWL_DL_FW, data, len);
1349 #elif defined(__FreeBSD__)
1350 #ifdef CONFIG_IWLWIFI_DEBUGFS
1351 		iwl_print_hex_dump(drv, IWL_DL_FW, "TLV ", data, len);
1352 #endif
1353 #endif
1354 		return -EINVAL;
1355 	}
1356 
1357 	return 0;
1358 
1359  invalid_tlv_len:
1360 	IWL_ERR(drv, "TLV %d has invalid size: %u\n", tlv_type, tlv_len);
1361  tlv_error:
1362 #if defined(__linux__)
1363 	iwl_print_hex_dump(drv, IWL_DL_FW, tlv_data, tlv_len);
1364 #elif defined(__FreeBSD__)
1365 #ifdef CONFIG_IWLWIFI_DEBUGFS
1366 	iwl_print_hex_dump(drv, IWL_DL_FW, "TLV ", tlv_data, tlv_len);
1367 #endif
1368 #endif
1369 
1370 	return -EINVAL;
1371 }
1372 
iwl_alloc_ucode(struct iwl_drv * drv,struct iwl_firmware_pieces * pieces,enum iwl_ucode_type type)1373 static int iwl_alloc_ucode(struct iwl_drv *drv,
1374 			   struct iwl_firmware_pieces *pieces,
1375 			   enum iwl_ucode_type type)
1376 {
1377 	int i;
1378 	struct fw_desc *sec;
1379 
1380 	sec = kcalloc(pieces->img[type].sec_counter, sizeof(*sec), GFP_KERNEL);
1381 	if (!sec)
1382 		return -ENOMEM;
1383 	drv->fw.img[type].sec = sec;
1384 	drv->fw.img[type].num_sec = pieces->img[type].sec_counter;
1385 
1386 	for (i = 0; i < pieces->img[type].sec_counter; i++)
1387 		if (iwl_alloc_fw_desc(drv, &sec[i], get_sec(pieces, type, i)))
1388 			return -ENOMEM;
1389 
1390 	return 0;
1391 }
1392 
validate_sec_sizes(struct iwl_drv * drv,struct iwl_firmware_pieces * pieces,const struct iwl_cfg * cfg)1393 static int validate_sec_sizes(struct iwl_drv *drv,
1394 			      struct iwl_firmware_pieces *pieces,
1395 			      const struct iwl_cfg *cfg)
1396 {
1397 	IWL_DEBUG_INFO(drv, "f/w package hdr runtime inst size = %zd\n",
1398 		get_sec_size(pieces, IWL_UCODE_REGULAR,
1399 			     IWL_UCODE_SECTION_INST));
1400 	IWL_DEBUG_INFO(drv, "f/w package hdr runtime data size = %zd\n",
1401 		get_sec_size(pieces, IWL_UCODE_REGULAR,
1402 			     IWL_UCODE_SECTION_DATA));
1403 	IWL_DEBUG_INFO(drv, "f/w package hdr init inst size = %zd\n",
1404 		get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST));
1405 	IWL_DEBUG_INFO(drv, "f/w package hdr init data size = %zd\n",
1406 		get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA));
1407 
1408 	/* Verify that uCode images will fit in card's SRAM. */
1409 	if (get_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_INST) >
1410 	    cfg->max_inst_size) {
1411 		IWL_ERR(drv, "uCode instr len %zd too large to fit in\n",
1412 			get_sec_size(pieces, IWL_UCODE_REGULAR,
1413 				     IWL_UCODE_SECTION_INST));
1414 		return -1;
1415 	}
1416 
1417 	if (get_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_DATA) >
1418 	    cfg->max_data_size) {
1419 		IWL_ERR(drv, "uCode data len %zd too large to fit in\n",
1420 			get_sec_size(pieces, IWL_UCODE_REGULAR,
1421 				     IWL_UCODE_SECTION_DATA));
1422 		return -1;
1423 	}
1424 
1425 	if (get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST) >
1426 	     cfg->max_inst_size) {
1427 		IWL_ERR(drv, "uCode init instr len %zd too large to fit in\n",
1428 			get_sec_size(pieces, IWL_UCODE_INIT,
1429 				     IWL_UCODE_SECTION_INST));
1430 		return -1;
1431 	}
1432 
1433 	if (get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA) >
1434 	    cfg->max_data_size) {
1435 		IWL_ERR(drv, "uCode init data len %zd too large to fit in\n",
1436 			get_sec_size(pieces, IWL_UCODE_REGULAR,
1437 				     IWL_UCODE_SECTION_DATA));
1438 		return -1;
1439 	}
1440 	return 0;
1441 }
1442 
1443 static struct iwl_op_mode *
_iwl_op_mode_start(struct iwl_drv * drv,struct iwlwifi_opmode_table * op)1444 _iwl_op_mode_start(struct iwl_drv *drv, struct iwlwifi_opmode_table *op)
1445 {
1446 	const struct iwl_op_mode_ops *ops = op->ops;
1447 	struct dentry *dbgfs_dir = NULL;
1448 	struct iwl_op_mode *op_mode = NULL;
1449 
1450 	/* also protects start/stop from racing against each other */
1451 	lockdep_assert_held(&iwlwifi_opmode_table_mtx);
1452 
1453 #ifdef CONFIG_IWLWIFI_DEBUGFS
1454 	drv->dbgfs_op_mode = debugfs_create_dir(op->name,
1455 						drv->dbgfs_drv);
1456 	dbgfs_dir = drv->dbgfs_op_mode;
1457 #endif
1458 
1459 	op_mode = ops->start(drv->trans, drv->trans->cfg,
1460 			     &drv->fw, dbgfs_dir);
1461 	if (op_mode)
1462 		return op_mode;
1463 
1464 #ifdef CONFIG_IWLWIFI_DEBUGFS
1465 	debugfs_remove_recursive(drv->dbgfs_op_mode);
1466 	drv->dbgfs_op_mode = NULL;
1467 #endif
1468 
1469 	return NULL;
1470 }
1471 
_iwl_op_mode_stop(struct iwl_drv * drv)1472 static void _iwl_op_mode_stop(struct iwl_drv *drv)
1473 {
1474 	/* also protects start/stop from racing against each other */
1475 	lockdep_assert_held(&iwlwifi_opmode_table_mtx);
1476 
1477 	/* op_mode can be NULL if its start failed */
1478 	if (drv->op_mode) {
1479 		iwl_op_mode_stop(drv->op_mode);
1480 		drv->op_mode = NULL;
1481 
1482 #ifdef CONFIG_IWLWIFI_DEBUGFS
1483 		debugfs_remove_recursive(drv->dbgfs_op_mode);
1484 		drv->dbgfs_op_mode = NULL;
1485 #endif
1486 	}
1487 }
1488 
1489 /*
1490  * iwl_req_fw_callback - callback when firmware was loaded
1491  *
1492  * If loaded successfully, copies the firmware into buffers
1493  * for the card to fetch (via DMA).
1494  */
iwl_req_fw_callback(const struct firmware * ucode_raw,void * context)1495 static void iwl_req_fw_callback(const struct firmware *ucode_raw, void *context)
1496 {
1497 	struct iwl_drv *drv = context;
1498 	struct iwl_fw *fw = &drv->fw;
1499 	const struct iwl_ucode_header *ucode;
1500 	struct iwlwifi_opmode_table *op;
1501 	int err;
1502 	struct iwl_firmware_pieces *pieces;
1503 	const unsigned int api_max = drv->trans->cfg->ucode_api_max;
1504 	const unsigned int api_min = drv->trans->cfg->ucode_api_min;
1505 	size_t trigger_tlv_sz[FW_DBG_TRIGGER_MAX];
1506 	u32 api_ver;
1507 	int i;
1508 	bool usniffer_images = false;
1509 	bool failure = true;
1510 
1511 	fw->ucode_capa.max_probe_length = IWL_DEFAULT_MAX_PROBE_LENGTH;
1512 	fw->ucode_capa.standard_phy_calibration_size =
1513 			IWL_DEFAULT_STANDARD_PHY_CALIBRATE_TBL_SIZE;
1514 	fw->ucode_capa.n_scan_channels = IWL_DEFAULT_SCAN_CHANNELS;
1515 	fw->ucode_capa.num_stations = IWL_MVM_STATION_COUNT_MAX;
1516 	fw->ucode_capa.num_beacons = 1;
1517 	/* dump all fw memory areas by default */
1518 	fw->dbg.dump_mask = 0xffffffff;
1519 
1520 	pieces = kzalloc(sizeof(*pieces), GFP_KERNEL);
1521 	if (!pieces)
1522 		goto out_free_fw;
1523 
1524 	if (!ucode_raw)
1525 		goto try_again;
1526 
1527 	IWL_DEBUG_FW_INFO(drv, "Loaded firmware file '%s' (%zd bytes).\n",
1528 			  drv->firmware_name, ucode_raw->size);
1529 
1530 	/* Make sure that we got at least the API version number */
1531 	if (ucode_raw->size < 4) {
1532 		IWL_ERR(drv, "File size way too small!\n");
1533 		goto try_again;
1534 	}
1535 
1536 	/* Data from ucode file:  header followed by uCode images */
1537 	ucode = (const struct iwl_ucode_header *)ucode_raw->data;
1538 
1539 	if (ucode->ver)
1540 		err = iwl_parse_v1_v2_firmware(drv, ucode_raw, pieces);
1541 	else
1542 		err = iwl_parse_tlv_firmware(drv, ucode_raw, pieces,
1543 					     &fw->ucode_capa, &usniffer_images);
1544 
1545 	if (err)
1546 		goto try_again;
1547 
1548 	if (fw_has_api(&drv->fw.ucode_capa, IWL_UCODE_TLV_API_NEW_VERSION))
1549 		api_ver = drv->fw.ucode_ver;
1550 	else
1551 		api_ver = IWL_UCODE_API(drv->fw.ucode_ver);
1552 
1553 	/*
1554 	 * api_ver should match the api version forming part of the
1555 	 * firmware filename ... but we don't check for that and only rely
1556 	 * on the API version read from firmware header from here on forward
1557 	 */
1558 	if (api_ver < api_min || api_ver > api_max) {
1559 		IWL_ERR(drv,
1560 			"Driver unable to support your firmware API. "
1561 			"Driver supports v%u, firmware is v%u.\n",
1562 			api_max, api_ver);
1563 		goto try_again;
1564 	}
1565 
1566 	/*
1567 	 * In mvm uCode there is no difference between data and instructions
1568 	 * sections.
1569 	 */
1570 	if (fw->type == IWL_FW_DVM && validate_sec_sizes(drv, pieces,
1571 							 drv->trans->cfg))
1572 		goto try_again;
1573 
1574 	/* Allocate ucode buffers for card's bus-master loading ... */
1575 
1576 	/* Runtime instructions and 2 copies of data:
1577 	 * 1) unmodified from disk
1578 	 * 2) backup cache for save/restore during power-downs
1579 	 */
1580 	for (i = 0; i < IWL_UCODE_TYPE_MAX; i++)
1581 		if (iwl_alloc_ucode(drv, pieces, i))
1582 			goto out_free_fw;
1583 
1584 	if (pieces->dbg_dest_tlv_init) {
1585 		size_t dbg_dest_size = sizeof(*drv->fw.dbg.dest_tlv) +
1586 			sizeof(drv->fw.dbg.dest_tlv->reg_ops[0]) *
1587 			drv->fw.dbg.n_dest_reg;
1588 
1589 		drv->fw.dbg.dest_tlv = kmalloc(dbg_dest_size, GFP_KERNEL);
1590 
1591 		if (!drv->fw.dbg.dest_tlv)
1592 			goto out_free_fw;
1593 
1594 		if (*pieces->dbg_dest_ver == 0) {
1595 			memcpy(drv->fw.dbg.dest_tlv, pieces->dbg_dest_tlv_v1,
1596 			       dbg_dest_size);
1597 		} else {
1598 			struct iwl_fw_dbg_dest_tlv_v1 *dest_tlv =
1599 				drv->fw.dbg.dest_tlv;
1600 
1601 			dest_tlv->version = pieces->dbg_dest_tlv->version;
1602 			dest_tlv->monitor_mode =
1603 				pieces->dbg_dest_tlv->monitor_mode;
1604 			dest_tlv->size_power =
1605 				pieces->dbg_dest_tlv->size_power;
1606 			dest_tlv->wrap_count =
1607 				pieces->dbg_dest_tlv->wrap_count;
1608 			dest_tlv->write_ptr_reg =
1609 				pieces->dbg_dest_tlv->write_ptr_reg;
1610 			dest_tlv->base_shift =
1611 				pieces->dbg_dest_tlv->base_shift;
1612 			memcpy(dest_tlv->reg_ops,
1613 			       pieces->dbg_dest_tlv->reg_ops,
1614 			       sizeof(drv->fw.dbg.dest_tlv->reg_ops[0]) *
1615 			       drv->fw.dbg.n_dest_reg);
1616 
1617 			/* In version 1 of the destination tlv, which is
1618 			 * relevant for internal buffer exclusively,
1619 			 * the base address is part of given with the length
1620 			 * of the buffer, and the size shift is give instead of
1621 			 * end shift. We now store these values in base_reg,
1622 			 * and end shift, and when dumping the data we'll
1623 			 * manipulate it for extracting both the length and
1624 			 * base address */
1625 			dest_tlv->base_reg = pieces->dbg_dest_tlv->cfg_reg;
1626 			dest_tlv->end_shift =
1627 				pieces->dbg_dest_tlv->size_shift;
1628 		}
1629 	}
1630 
1631 	for (i = 0; i < ARRAY_SIZE(drv->fw.dbg.conf_tlv); i++) {
1632 		if (pieces->dbg_conf_tlv[i]) {
1633 			drv->fw.dbg.conf_tlv[i] =
1634 				kmemdup(pieces->dbg_conf_tlv[i],
1635 					pieces->dbg_conf_tlv_len[i],
1636 					GFP_KERNEL);
1637 			if (!drv->fw.dbg.conf_tlv[i])
1638 				goto out_free_fw;
1639 		}
1640 	}
1641 
1642 	memset(&trigger_tlv_sz, 0xff, sizeof(trigger_tlv_sz));
1643 
1644 	trigger_tlv_sz[FW_DBG_TRIGGER_MISSED_BEACONS] =
1645 		sizeof(struct iwl_fw_dbg_trigger_missed_bcon);
1646 	trigger_tlv_sz[FW_DBG_TRIGGER_CHANNEL_SWITCH] = 0;
1647 	trigger_tlv_sz[FW_DBG_TRIGGER_FW_NOTIF] =
1648 		sizeof(struct iwl_fw_dbg_trigger_cmd);
1649 	trigger_tlv_sz[FW_DBG_TRIGGER_MLME] =
1650 		sizeof(struct iwl_fw_dbg_trigger_mlme);
1651 	trigger_tlv_sz[FW_DBG_TRIGGER_STATS] =
1652 		sizeof(struct iwl_fw_dbg_trigger_stats);
1653 	trigger_tlv_sz[FW_DBG_TRIGGER_RSSI] =
1654 		sizeof(struct iwl_fw_dbg_trigger_low_rssi);
1655 	trigger_tlv_sz[FW_DBG_TRIGGER_TXQ_TIMERS] =
1656 		sizeof(struct iwl_fw_dbg_trigger_txq_timer);
1657 	trigger_tlv_sz[FW_DBG_TRIGGER_TIME_EVENT] =
1658 		sizeof(struct iwl_fw_dbg_trigger_time_event);
1659 	trigger_tlv_sz[FW_DBG_TRIGGER_BA] =
1660 		sizeof(struct iwl_fw_dbg_trigger_ba);
1661 	trigger_tlv_sz[FW_DBG_TRIGGER_TDLS] =
1662 		sizeof(struct iwl_fw_dbg_trigger_tdls);
1663 
1664 	for (i = 0; i < ARRAY_SIZE(drv->fw.dbg.trigger_tlv); i++) {
1665 		if (pieces->dbg_trigger_tlv[i]) {
1666 			/*
1667 			 * If the trigger isn't long enough, WARN and exit.
1668 			 * Someone is trying to debug something and he won't
1669 			 * be able to catch the bug he is trying to chase.
1670 			 * We'd better be noisy to be sure he knows what's
1671 			 * going on.
1672 			 */
1673 			if (WARN_ON(pieces->dbg_trigger_tlv_len[i] <
1674 				    (trigger_tlv_sz[i] +
1675 				     sizeof(struct iwl_fw_dbg_trigger_tlv))))
1676 				goto out_free_fw;
1677 			drv->fw.dbg.trigger_tlv_len[i] =
1678 				pieces->dbg_trigger_tlv_len[i];
1679 			drv->fw.dbg.trigger_tlv[i] =
1680 				kmemdup(pieces->dbg_trigger_tlv[i],
1681 					drv->fw.dbg.trigger_tlv_len[i],
1682 					GFP_KERNEL);
1683 			if (!drv->fw.dbg.trigger_tlv[i])
1684 				goto out_free_fw;
1685 		}
1686 	}
1687 
1688 	/* Now that we can no longer fail, copy information */
1689 
1690 	drv->fw.dbg.mem_tlv = pieces->dbg_mem_tlv;
1691 	pieces->dbg_mem_tlv = NULL;
1692 	drv->fw.dbg.n_mem_tlv = pieces->n_mem_tlv;
1693 
1694 	/*
1695 	 * The (size - 16) / 12 formula is based on the information recorded
1696 	 * for each event, which is of mode 1 (including timestamp) for all
1697 	 * new microcodes that include this information.
1698 	 */
1699 	fw->init_evtlog_ptr = pieces->init_evtlog_ptr;
1700 	if (pieces->init_evtlog_size)
1701 		fw->init_evtlog_size = (pieces->init_evtlog_size - 16)/12;
1702 	else
1703 		fw->init_evtlog_size =
1704 			drv->trans->trans_cfg->base_params->max_event_log_size;
1705 	fw->init_errlog_ptr = pieces->init_errlog_ptr;
1706 	fw->inst_evtlog_ptr = pieces->inst_evtlog_ptr;
1707 	if (pieces->inst_evtlog_size)
1708 		fw->inst_evtlog_size = (pieces->inst_evtlog_size - 16)/12;
1709 	else
1710 		fw->inst_evtlog_size =
1711 			drv->trans->trans_cfg->base_params->max_event_log_size;
1712 	fw->inst_errlog_ptr = pieces->inst_errlog_ptr;
1713 
1714 	/*
1715 	 * figure out the offset of chain noise reset and gain commands
1716 	 * base on the size of standard phy calibration commands table size
1717 	 */
1718 	if (fw->ucode_capa.standard_phy_calibration_size >
1719 	    IWL_MAX_PHY_CALIBRATE_TBL_SIZE)
1720 		fw->ucode_capa.standard_phy_calibration_size =
1721 			IWL_MAX_STANDARD_PHY_CALIBRATE_TBL_SIZE;
1722 
1723 	/* We have our copies now, allow OS release its copies */
1724 	release_firmware(ucode_raw);
1725 
1726 	iwl_dbg_tlv_load_bin(drv->trans->dev, drv->trans);
1727 
1728 	mutex_lock(&iwlwifi_opmode_table_mtx);
1729 	switch (fw->type) {
1730 	case IWL_FW_DVM:
1731 		op = &iwlwifi_opmode_table[DVM_OP_MODE];
1732 		break;
1733 	default:
1734 		WARN(1, "Invalid fw type %d\n", fw->type);
1735 		fallthrough;
1736 	case IWL_FW_MVM:
1737 		op = &iwlwifi_opmode_table[MVM_OP_MODE];
1738 		break;
1739 	}
1740 
1741 	IWL_INFO(drv, "loaded firmware version %s op_mode %s\n",
1742 		 drv->fw.fw_version, op->name);
1743 
1744 	/* add this device to the list of devices using this op_mode */
1745 	list_add_tail(&drv->list, &op->drv);
1746 
1747 	if (op->ops) {
1748 		drv->op_mode = _iwl_op_mode_start(drv, op);
1749 
1750 		if (!drv->op_mode) {
1751 			mutex_unlock(&iwlwifi_opmode_table_mtx);
1752 			goto out_unbind;
1753 		}
1754 	} else {
1755 #if defined(__linux__)
1756 		request_module_nowait("%s", op->name);
1757 #elif defined(__FreeBSD__)
1758 		/*
1759 		 * In FreeBSD if_iwlwifi contains all drv modules in a single
1760 		 * module.  SYSINIT will do the job later.  We cannot call
1761 		 * into kern_kldload() while being called from kern_kldload():
1762 		 * LinuxKPI request_module[_nowait] will hang hard.
1763 		 * Given this is request_module_nowait() we can simply skip it.
1764 		 */
1765 		if (bootverbose)
1766 			printf("%s: module '%s' not yet available; will be initialized in a moment\n",
1767 			    __func__, op->name);
1768 #endif
1769 	}
1770 	mutex_unlock(&iwlwifi_opmode_table_mtx);
1771 
1772 	complete(&drv->request_firmware_complete);
1773 
1774 	failure = false;
1775 	goto free;
1776 
1777  try_again:
1778 	/* try next, if any */
1779 	release_firmware(ucode_raw);
1780 	if (iwl_request_firmware(drv, false))
1781 		goto out_unbind;
1782 	goto free;
1783 
1784  out_free_fw:
1785 	release_firmware(ucode_raw);
1786  out_unbind:
1787 	complete(&drv->request_firmware_complete);
1788 	device_release_driver(drv->trans->dev);
1789 	/* drv has just been freed by the release */
1790 	failure = false;
1791  free:
1792 	if (failure)
1793 		iwl_dealloc_ucode(drv);
1794 
1795 	if (pieces) {
1796 		for (i = 0; i < ARRAY_SIZE(pieces->img); i++)
1797 			kfree(pieces->img[i].sec);
1798 		kfree(pieces->dbg_mem_tlv);
1799 		kfree(pieces);
1800 	}
1801 }
1802 
iwl_drv_start(struct iwl_trans * trans)1803 struct iwl_drv *iwl_drv_start(struct iwl_trans *trans)
1804 {
1805 	struct iwl_drv *drv;
1806 	int ret;
1807 
1808 	drv = kzalloc(sizeof(*drv), GFP_KERNEL);
1809 	if (!drv) {
1810 		ret = -ENOMEM;
1811 		goto err;
1812 	}
1813 
1814 	drv->trans = trans;
1815 	drv->dev = trans->dev;
1816 
1817 	init_completion(&drv->request_firmware_complete);
1818 #if defined(__FreeBSD__)
1819 	init_completion(&drv->drv_start_complete);
1820 #endif
1821 	INIT_LIST_HEAD(&drv->list);
1822 
1823 #ifdef CONFIG_IWLWIFI_DEBUGFS
1824 	/* Create the device debugfs entries. */
1825 	drv->dbgfs_drv = debugfs_create_dir(dev_name(trans->dev),
1826 					    iwl_dbgfs_root);
1827 
1828 	/* Create transport layer debugfs dir */
1829 	drv->trans->dbgfs_dir = debugfs_create_dir("trans", drv->dbgfs_drv);
1830 #endif
1831 
1832 	drv->trans->dbg.domains_bitmap = IWL_TRANS_FW_DBG_DOMAIN(drv->trans);
1833 	if (iwlwifi_mod_params.enable_ini != ENABLE_INI) {
1834 		/* We have a non-default value in the module parameter,
1835 		 * take its value
1836 		 */
1837 		drv->trans->dbg.domains_bitmap &= 0xffff;
1838 		if (iwlwifi_mod_params.enable_ini != IWL_FW_INI_PRESET_DISABLE) {
1839 			if (iwlwifi_mod_params.enable_ini > ENABLE_INI) {
1840 				IWL_ERR(trans,
1841 					"invalid enable_ini module parameter value: max = %d, using 0 instead\n",
1842 					ENABLE_INI);
1843 				iwlwifi_mod_params.enable_ini = 0;
1844 			}
1845 			drv->trans->dbg.domains_bitmap =
1846 				BIT(IWL_FW_DBG_DOMAIN_POS + iwlwifi_mod_params.enable_ini);
1847 		}
1848 	}
1849 
1850 	ret = iwl_request_firmware(drv, true);
1851 	if (ret) {
1852 		IWL_ERR(trans, "Couldn't request the fw\n");
1853 		goto err_fw;
1854 	}
1855 
1856 #if defined(__FreeBSD__)
1857 	/*
1858 	 * Wait until initilization is done before returning in order to
1859 	 * replicate FreeBSD's synchronous behaviour -- we cannot create
1860 	 * a vap before the com is fully created but if LinuxKPI "probe"
1861 	 * returned before it was all done that is what could happen.
1862 	 */
1863 	wait_for_completion(&drv->request_firmware_complete);
1864 	complete(&drv->drv_start_complete);
1865 #endif
1866 
1867 	return drv;
1868 
1869 err_fw:
1870 #ifdef CONFIG_IWLWIFI_DEBUGFS
1871 	debugfs_remove_recursive(drv->dbgfs_drv);
1872 #endif
1873 	iwl_dbg_tlv_free(drv->trans);
1874 	kfree(drv);
1875 err:
1876 	return ERR_PTR(ret);
1877 }
1878 
iwl_drv_stop(struct iwl_drv * drv)1879 void iwl_drv_stop(struct iwl_drv *drv)
1880 {
1881 #if defined(__linux__)
1882 	wait_for_completion(&drv->request_firmware_complete);
1883 #elif defined(__FreeBSD__)
1884 	wait_for_completion(&drv->drv_start_complete);
1885 #endif
1886 
1887 	mutex_lock(&iwlwifi_opmode_table_mtx);
1888 
1889 	_iwl_op_mode_stop(drv);
1890 
1891 	iwl_dealloc_ucode(drv);
1892 
1893 	/*
1894 	 * List is empty (this item wasn't added)
1895 	 * when firmware loading failed -- in that
1896 	 * case we can't remove it from any list.
1897 	 */
1898 	if (!list_empty(&drv->list))
1899 		list_del(&drv->list);
1900 	mutex_unlock(&iwlwifi_opmode_table_mtx);
1901 
1902 #ifdef CONFIG_IWLWIFI_DEBUGFS
1903 	iwl_trans_debugfs_cleanup(drv->trans);
1904 
1905 	debugfs_remove_recursive(drv->dbgfs_drv);
1906 #endif
1907 
1908 	iwl_dbg_tlv_free(drv->trans);
1909 
1910 	kfree(drv);
1911 }
1912 
1913 /* shared module parameters */
1914 struct iwl_mod_params iwlwifi_mod_params = {
1915 	.fw_restart = true,
1916 	.bt_coex_active = true,
1917 	.power_level = IWL_POWER_INDEX_1,
1918 	.uapsd_disable = IWL_DISABLE_UAPSD_BSS | IWL_DISABLE_UAPSD_P2P_CLIENT,
1919 	.enable_ini = ENABLE_INI,
1920 #if defined(__FreeBSD__)
1921 	.disable_11n = 1,
1922 	.disable_11ac = true,
1923 	.disable_11ax = true,
1924 	.disable_11be = true,
1925 #endif
1926 	/* the rest are 0 by default */
1927 };
1928 IWL_EXPORT_SYMBOL(iwlwifi_mod_params);
1929 
iwl_opmode_register(const char * name,const struct iwl_op_mode_ops * ops)1930 int iwl_opmode_register(const char *name, const struct iwl_op_mode_ops *ops)
1931 {
1932 	int i;
1933 	struct iwl_drv *drv;
1934 	struct iwlwifi_opmode_table *op;
1935 
1936 	mutex_lock(&iwlwifi_opmode_table_mtx);
1937 	for (i = 0; i < ARRAY_SIZE(iwlwifi_opmode_table); i++) {
1938 		op = &iwlwifi_opmode_table[i];
1939 		if (strcmp(op->name, name))
1940 			continue;
1941 		op->ops = ops;
1942 		/* TODO: need to handle exceptional case */
1943 		list_for_each_entry(drv, &op->drv, list)
1944 			drv->op_mode = _iwl_op_mode_start(drv, op);
1945 
1946 		mutex_unlock(&iwlwifi_opmode_table_mtx);
1947 		return 0;
1948 	}
1949 	mutex_unlock(&iwlwifi_opmode_table_mtx);
1950 	return -EIO;
1951 }
1952 IWL_EXPORT_SYMBOL(iwl_opmode_register);
1953 
iwl_opmode_deregister(const char * name)1954 void iwl_opmode_deregister(const char *name)
1955 {
1956 	int i;
1957 	struct iwl_drv *drv;
1958 
1959 	mutex_lock(&iwlwifi_opmode_table_mtx);
1960 	for (i = 0; i < ARRAY_SIZE(iwlwifi_opmode_table); i++) {
1961 		if (strcmp(iwlwifi_opmode_table[i].name, name))
1962 			continue;
1963 		iwlwifi_opmode_table[i].ops = NULL;
1964 
1965 		/* call the stop routine for all devices */
1966 		list_for_each_entry(drv, &iwlwifi_opmode_table[i].drv, list)
1967 			_iwl_op_mode_stop(drv);
1968 
1969 		mutex_unlock(&iwlwifi_opmode_table_mtx);
1970 		return;
1971 	}
1972 	mutex_unlock(&iwlwifi_opmode_table_mtx);
1973 }
1974 IWL_EXPORT_SYMBOL(iwl_opmode_deregister);
1975 
iwl_drv_init(void)1976 static int __init iwl_drv_init(void)
1977 {
1978 	int i, err;
1979 
1980 	for (i = 0; i < ARRAY_SIZE(iwlwifi_opmode_table); i++)
1981 		INIT_LIST_HEAD(&iwlwifi_opmode_table[i].drv);
1982 
1983 	pr_info(DRV_DESCRIPTION "\n");
1984 
1985 #ifdef CONFIG_IWLWIFI_DEBUGFS
1986 	/* Create the root of iwlwifi debugfs subsystem. */
1987 	iwl_dbgfs_root = debugfs_create_dir(DRV_NAME, NULL);
1988 #endif
1989 
1990 	err = iwl_pci_register_driver();
1991 	if (err)
1992 		goto cleanup_debugfs;
1993 
1994 	return 0;
1995 
1996 cleanup_debugfs:
1997 #ifdef CONFIG_IWLWIFI_DEBUGFS
1998 	debugfs_remove_recursive(iwl_dbgfs_root);
1999 #endif
2000 	return err;
2001 }
2002 module_init(iwl_drv_init);
2003 
iwl_drv_exit(void)2004 static void __exit iwl_drv_exit(void)
2005 {
2006 	iwl_pci_unregister_driver();
2007 
2008 #ifdef CONFIG_IWLWIFI_DEBUGFS
2009 	debugfs_remove_recursive(iwl_dbgfs_root);
2010 #endif
2011 }
2012 module_exit(iwl_drv_exit);
2013 
2014 #ifdef CONFIG_IWLWIFI_DEBUG
2015 module_param_named(debug, iwlwifi_mod_params.debug_level, uint, 0644);
2016 MODULE_PARM_DESC(debug, "debug output mask");
2017 #endif
2018 
2019 module_param_named(swcrypto, iwlwifi_mod_params.swcrypto, int, 0444);
2020 MODULE_PARM_DESC(swcrypto, "using crypto in software (default 0 [hardware])");
2021 module_param_named(11n_disable, iwlwifi_mod_params.disable_11n, uint, 0444);
2022 MODULE_PARM_DESC(11n_disable,
2023 	"disable 11n functionality, bitmap: 1: full, 2: disable agg TX, 4: disable agg RX, 8 enable agg TX");
2024 module_param_named(amsdu_size, iwlwifi_mod_params.amsdu_size, int, 0444);
2025 MODULE_PARM_DESC(amsdu_size,
2026 		 "amsdu size 0: 12K for multi Rx queue devices, 2K for AX210 devices, "
2027 		 "4K for other devices 1:4K 2:8K 3:12K (16K buffers) 4: 2K (default 0)");
2028 module_param_named(fw_restart, iwlwifi_mod_params.fw_restart, bool, 0444);
2029 MODULE_PARM_DESC(fw_restart, "restart firmware in case of error (default true)");
2030 
2031 module_param_named(nvm_file, iwlwifi_mod_params.nvm_file, charp, 0444);
2032 MODULE_PARM_DESC(nvm_file, "NVM file name");
2033 
2034 module_param_named(uapsd_disable, iwlwifi_mod_params.uapsd_disable, uint, 0644);
2035 MODULE_PARM_DESC(uapsd_disable,
2036 		 "disable U-APSD functionality bitmap 1: BSS 2: P2P Client (default: 3)");
2037 
2038 module_param_named(enable_ini, iwlwifi_mod_params.enable_ini, uint, 0444);
2039 MODULE_PARM_DESC(enable_ini,
2040 		 "0:disable, 1-15:FW_DBG_PRESET Values, 16:enabled without preset value defined,"
2041 		 "Debug INI TLV FW debug infrastructure (default: 16)");
2042 
2043 /*
2044  * set bt_coex_active to true, uCode will do kill/defer
2045  * every time the priority line is asserted (BT is sending signals on the
2046  * priority line in the PCIx).
2047  * set bt_coex_active to false, uCode will ignore the BT activity and
2048  * perform the normal operation
2049  *
2050  * User might experience transmit issue on some platform due to WiFi/BT
2051  * co-exist problem. The possible behaviors are:
2052  *   Able to scan and finding all the available AP
2053  *   Not able to associate with any AP
2054  * On those platforms, WiFi communication can be restored by set
2055  * "bt_coex_active" module parameter to "false"
2056  *
2057  * default: bt_coex_active = true (BT_COEX_ENABLE)
2058  */
2059 module_param_named(bt_coex_active, iwlwifi_mod_params.bt_coex_active,
2060 		   bool, 0444);
2061 MODULE_PARM_DESC(bt_coex_active, "enable wifi/bt co-exist (default: enable)");
2062 
2063 module_param_named(led_mode, iwlwifi_mod_params.led_mode, int, 0444);
2064 MODULE_PARM_DESC(led_mode, "0=system default, "
2065 		"1=On(RF On)/Off(RF Off), 2=blinking, 3=Off (default: 0)");
2066 
2067 module_param_named(power_save, iwlwifi_mod_params.power_save, bool, 0444);
2068 MODULE_PARM_DESC(power_save,
2069 		 "enable WiFi power management (default: disable)");
2070 
2071 module_param_named(power_level, iwlwifi_mod_params.power_level, int, 0444);
2072 MODULE_PARM_DESC(power_level,
2073 		 "default power save level (range from 1 - 5, default: 1)");
2074 
2075 module_param_named(disable_11ac, iwlwifi_mod_params.disable_11ac, bool, 0444);
2076 MODULE_PARM_DESC(disable_11ac, "Disable VHT capabilities (default: false)");
2077 
2078 module_param_named(remove_when_gone,
2079 		   iwlwifi_mod_params.remove_when_gone, bool,
2080 		   0444);
2081 MODULE_PARM_DESC(remove_when_gone,
2082 		 "Remove dev from PCIe bus if it is deemed inaccessible (default: false)");
2083 
2084 module_param_named(disable_11ax, iwlwifi_mod_params.disable_11ax, bool,
2085 		   S_IRUGO);
2086 MODULE_PARM_DESC(disable_11ax, "Disable HE capabilities (default: false)");
2087 
2088 module_param_named(disable_11be, iwlwifi_mod_params.disable_11be, bool, 0444);
2089 MODULE_PARM_DESC(disable_11be, "Disable EHT capabilities (default: false)");
2090