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