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