xref: /linux/drivers/net/wireless/intel/iwlwifi/iwl-drv.c (revision dbf8fe85a16a33d6b6bd01f2bc606fc017771465)
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 
iwl_free_fw_desc(struct iwl_drv * drv,struct fw_desc * desc)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 
iwl_free_fw_img(struct iwl_drv * drv,struct fw_img * img)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 
iwl_dealloc_ucode(struct iwl_drv * drv)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 
iwl_alloc_fw_desc(struct fw_desc * desc,struct fw_sec * sec)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 
iwl_drv_get_step(int step)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 
iwl_drv_is_wifi7_supported(struct iwl_trans * trans)180 bool iwl_drv_is_wifi7_supported(struct iwl_trans *trans)
181 {
182 	return trans->mac_cfg->device_family >= IWL_DEVICE_FAMILY_BZ &&
183 	       CSR_HW_RFID_TYPE(trans->info.hw_rf_id) >= IWL_CFG_RF_TYPE_FM;
184 }
185 
iwl_drv_get_fwname_pre(struct iwl_trans * trans,char * buf)186 const char *iwl_drv_get_fwname_pre(struct iwl_trans *trans, char *buf)
187 {
188 	char mac_step, rf_step;
189 	const char *mac, *rf, *cdb;
190 
191 	if (trans->cfg->fw_name_pre)
192 		return trans->cfg->fw_name_pre;
193 
194 	mac_step = iwl_drv_get_step(trans->info.hw_rev_step);
195 
196 	switch (CSR_HW_REV_TYPE(trans->info.hw_rev)) {
197 	case IWL_CFG_MAC_TYPE_PU:
198 		mac = "9000-pu";
199 		mac_step = 'b';
200 		break;
201 	case IWL_CFG_MAC_TYPE_TH:
202 		mac = "9260-th";
203 		mac_step = 'b';
204 		break;
205 	case IWL_CFG_MAC_TYPE_QU:
206 		mac = "Qu";
207 		break;
208 	case IWL_CFG_MAC_TYPE_CC:
209 		/* special case - no RF since it's fixed (discrete) */
210 		scnprintf(buf, FW_NAME_PRE_BUFSIZE, "iwlwifi-cc-a0");
211 		return buf;
212 	case IWL_CFG_MAC_TYPE_QUZ:
213 		mac = "QuZ";
214 		/* all QuZ use A0 firmware */
215 		mac_step = 'a';
216 		break;
217 	case IWL_CFG_MAC_TYPE_SO:
218 	case IWL_CFG_MAC_TYPE_SOF:
219 		mac = "so";
220 		mac_step = 'a';
221 		break;
222 	case IWL_CFG_MAC_TYPE_TY:
223 		mac = "ty";
224 		mac_step = 'a';
225 		break;
226 	case IWL_CFG_MAC_TYPE_MA:
227 		mac = "ma";
228 		break;
229 	case IWL_CFG_MAC_TYPE_BZ:
230 	case IWL_CFG_MAC_TYPE_BZ_W:
231 		mac = "bz";
232 		break;
233 	case IWL_CFG_MAC_TYPE_GL:
234 		mac = "gl";
235 		break;
236 	case IWL_CFG_MAC_TYPE_SC:
237 		mac = "sc";
238 		break;
239 	case IWL_CFG_MAC_TYPE_SC2:
240 	/* Uses the same firmware as SC2 */
241 	case IWL_CFG_MAC_TYPE_SC2F:
242 		mac = "sc2";
243 		break;
244 	case IWL_CFG_MAC_TYPE_BR:
245 		mac = "br";
246 		break;
247 	case IWL_CFG_MAC_TYPE_DR:
248 		mac = "dr";
249 		break;
250 	default:
251 		return "unknown-mac";
252 	}
253 
254 	rf_step = iwl_drv_get_step(CSR_HW_RFID_STEP(trans->info.hw_rf_id));
255 
256 	switch (CSR_HW_RFID_TYPE(trans->info.hw_rf_id)) {
257 	case IWL_CFG_RF_TYPE_JF1:
258 	case IWL_CFG_RF_TYPE_JF2:
259 		rf = "jf";
260 		rf_step = 'b';
261 		break;
262 	case IWL_CFG_RF_TYPE_HR1:
263 	case IWL_CFG_RF_TYPE_HR2:
264 		rf = "hr";
265 		rf_step = 'b';
266 		break;
267 	case IWL_CFG_RF_TYPE_GF:
268 		rf = "gf";
269 		rf_step = 'a';
270 		break;
271 	case IWL_CFG_RF_TYPE_FM:
272 		rf = "fm";
273 		break;
274 	case IWL_CFG_RF_TYPE_WH:
275 		rf = "wh";
276 		break;
277 	case IWL_CFG_RF_TYPE_PE:
278 		rf = "pe";
279 		break;
280 	default:
281 		return "unknown-rf";
282 	}
283 
284 	cdb = CSR_HW_RFID_IS_CDB(trans->info.hw_rf_id) ? "4" : "";
285 
286 	scnprintf(buf, FW_NAME_PRE_BUFSIZE,
287 		  "iwlwifi-%s-%c0-%s%s-%c0",
288 		  mac, mac_step, rf, cdb, rf_step);
289 
290 	return buf;
291 }
292 IWL_EXPORT_SYMBOL(iwl_drv_get_fwname_pre);
293 
294 static void iwl_req_fw_callback(const struct firmware *ucode_raw,
295 				void *context);
296 
iwl_get_ucode_api_versions(struct iwl_trans * trans,unsigned int * api_min,unsigned int * api_max)297 static void iwl_get_ucode_api_versions(struct iwl_trans *trans,
298 				       unsigned int *api_min,
299 				       unsigned int *api_max)
300 {
301 	const struct iwl_family_base_params *base = trans->mac_cfg->base;
302 	const struct iwl_rf_cfg *cfg = trans->cfg;
303 
304 	/* if the MAC doesn't have range or if its range it higher than the RF's */
305 	if (!base->ucode_api_max ||
306 	    (cfg->ucode_api_max && base->ucode_api_min > cfg->ucode_api_max)) {
307 		*api_min = cfg->ucode_api_min;
308 		*api_max = cfg->ucode_api_max;
309 		return;
310 	}
311 
312 	/* if the RF doesn't have range or if its range it higher than the MAC's */
313 	if (!cfg->ucode_api_max ||
314 	    (base->ucode_api_max && cfg->ucode_api_min > base->ucode_api_max)) {
315 		*api_min = base->ucode_api_min;
316 		*api_max = base->ucode_api_max;
317 		return;
318 	}
319 
320 	*api_min = max(cfg->ucode_api_min, base->ucode_api_min);
321 	*api_max = min(cfg->ucode_api_max, base->ucode_api_max);
322 }
323 
iwl_request_firmware(struct iwl_drv * drv,bool first)324 static int iwl_request_firmware(struct iwl_drv *drv, bool first)
325 {
326 	char _fw_name_pre[FW_NAME_PRE_BUFSIZE];
327 	unsigned int ucode_api_max, ucode_api_min;
328 	const char *fw_name_pre;
329 
330 	iwl_get_ucode_api_versions(drv->trans, &ucode_api_min, &ucode_api_max);
331 
332 	if (drv->trans->mac_cfg->device_family == IWL_DEVICE_FAMILY_9000 &&
333 	    (drv->trans->info.hw_rev_step != SILICON_B_STEP &&
334 	     drv->trans->info.hw_rev_step != SILICON_C_STEP)) {
335 		IWL_ERR(drv,
336 			"Only HW steps B and C are currently supported (0x%0x)\n",
337 			drv->trans->info.hw_rev);
338 		return -EINVAL;
339 	}
340 
341 	if (CSR_HW_RFID_TYPE(drv->trans->info.hw_rf_id) == IWL_CFG_RF_TYPE_WH &&
342 	    CSR_HW_RFID_STEP(drv->trans->info.hw_rf_id) == SILICON_A_STEP) {
343 		IWL_ERR(drv, "WH A step is not supported\n");
344 		return -EINVAL;
345 	}
346 
347 	fw_name_pre = iwl_drv_get_fwname_pre(drv->trans, _fw_name_pre);
348 
349 	if (first)
350 		drv->fw_index = ucode_api_max;
351 	else if (drv->fw_index == ENCODE_CORE_AS_API(100))
352 		drv->fw_index = 102; /* last API-scheme number below core 100 */
353 	else
354 		drv->fw_index--;
355 
356 	if (drv->fw_index < ucode_api_min) {
357 		IWL_ERR(drv, "no suitable firmware found!\n");
358 
359 		if (ucode_api_min == ucode_api_max) {
360 			IWL_ERR(drv, "%s-" FW_API_FMT " is required\n",
361 				fw_name_pre, FW_API_ARG(ucode_api_max));
362 		} else {
363 			IWL_ERR(drv,
364 				"minimum version required: %s-" FW_API_FMT "\n",
365 				fw_name_pre, FW_API_ARG(ucode_api_min));
366 			IWL_ERR(drv,
367 				"maximum version supported: %s-" FW_API_FMT "\n",
368 				fw_name_pre, FW_API_ARG(ucode_api_max));
369 		}
370 
371 		IWL_ERR(drv,
372 			"check git://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git\n");
373 		return -ENOENT;
374 	}
375 
376 	snprintf(drv->firmware_name, sizeof(drv->firmware_name),
377 		 "%s-" FW_API_FMT ".ucode",
378 		 fw_name_pre, FW_API_ARG(drv->fw_index));
379 
380 	IWL_DEBUG_FW_INFO(drv, "attempting to load firmware '%s'\n",
381 			  drv->firmware_name);
382 
383 	return request_firmware_nowait(THIS_MODULE, 1, drv->firmware_name,
384 				       drv->trans->dev,
385 				       GFP_KERNEL, drv, iwl_req_fw_callback);
386 }
387 
388 struct fw_img_parsing {
389 	struct fw_sec *sec;
390 	int sec_counter;
391 };
392 
393 /*
394  * struct fw_sec_parsing: to extract fw section and it's offset from tlv
395  */
396 struct fw_sec_parsing {
397 	__le32 offset;
398 	const u8 data[];
399 } __packed;
400 
401 /**
402  * struct iwl_tlv_calib_data - parse the default calib data from TLV
403  *
404  * @ucode_type: the uCode to which the following default calib relates.
405  * @calib: default calibrations.
406  */
407 struct iwl_tlv_calib_data {
408 	__le32 ucode_type;
409 	struct iwl_tlv_calib_ctrl calib;
410 } __packed;
411 
412 struct iwl_firmware_pieces {
413 	struct fw_img_parsing img[IWL_UCODE_TYPE_MAX];
414 
415 	u32 init_evtlog_ptr, init_evtlog_size, init_errlog_ptr;
416 	u32 inst_evtlog_ptr, inst_evtlog_size, inst_errlog_ptr;
417 
418 	/* FW debug data parsed for driver usage */
419 	bool dbg_dest_tlv_init;
420 	const u8 *dbg_dest_ver;
421 	union {
422 		const struct iwl_fw_dbg_dest_tlv *dbg_dest_tlv;
423 		const struct iwl_fw_dbg_dest_tlv_v1 *dbg_dest_tlv_v1;
424 	};
425 	const struct iwl_fw_dbg_conf_tlv *dbg_conf_tlv[FW_DBG_CONF_MAX];
426 	size_t dbg_conf_tlv_len[FW_DBG_CONF_MAX];
427 	const struct iwl_fw_dbg_trigger_tlv *dbg_trigger_tlv[FW_DBG_TRIGGER_MAX];
428 	size_t dbg_trigger_tlv_len[FW_DBG_TRIGGER_MAX];
429 	struct iwl_fw_dbg_mem_seg_tlv *dbg_mem_tlv;
430 	size_t n_mem_tlv;
431 };
432 
alloc_sec_data(struct iwl_firmware_pieces * pieces,enum iwl_ucode_type type,int sec)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 
set_sec_data(struct iwl_firmware_pieces * pieces,enum iwl_ucode_type type,int sec,const void * data)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 
set_sec_size(struct iwl_firmware_pieces * pieces,enum iwl_ucode_type type,int sec,size_t size)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 
get_sec_size(struct iwl_firmware_pieces * pieces,enum iwl_ucode_type type,int sec)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 
set_sec_offset(struct iwl_firmware_pieces * pieces,enum iwl_ucode_type type,int sec,u32 offset)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  */
iwl_store_ucode_sec(struct fw_img_parsing * img,const void * data,int size)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 
iwl_set_default_calib(struct iwl_drv * drv,const u8 * data)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 
iwl_set_ucode_api_flags(struct iwl_drv * drv,const u8 * data,struct iwl_ucode_capabilities * capa)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 
iwl_set_ucode_capabilities(struct iwl_drv * drv,const u8 * data,struct iwl_ucode_capabilities * capa)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 
iwl_reduced_fw_name(struct iwl_drv * drv)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 
iwl_parse_v1_v2_firmware(struct iwl_drv * drv,const struct firmware * ucode_raw,struct iwl_firmware_pieces * pieces)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 
iwl_drv_set_dump_exclude(struct iwl_drv * drv,enum iwl_ucode_tlv_type tlv_type,const void * tlv_data,u32 tlv_len)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 
iwl_parse_dbg_tlv_assert_tables(struct iwl_drv * drv,const struct iwl_ucode_tlv * tlv)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 
iwl_parse_tlv_firmware(struct iwl_drv * drv,const struct firmware * ucode_raw,struct iwl_firmware_pieces * pieces,struct iwl_ucode_capabilities * capa,bool * usniffer_images)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 major, minor;
1073 			u8 local_comp;
1074 
1075 			if (tlv_len != sizeof(u32) * 3)
1076 				goto invalid_tlv_len;
1077 
1078 			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", 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 
iwl_alloc_ucode_mem(struct fw_img * out,struct fw_img_parsing * img)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 
iwl_alloc_ucode(struct iwl_drv * drv,struct iwl_firmware_pieces * pieces,enum iwl_ucode_type type)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 
validate_sec_sizes(struct iwl_drv * drv,struct iwl_firmware_pieces * pieces,const struct iwl_rf_cfg * cfg)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 *
_iwl_op_mode_start(struct iwl_drv * drv,struct iwlwifi_opmode_table * op)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 
_iwl_op_mode_stop(struct iwl_drv * drv)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 /*
1593  * iwl_req_fw_callback - callback when firmware was loaded
1594  *
1595  * If loaded successfully, copies the firmware into buffers
1596  * for the card to fetch (via DMA).
1597  */
iwl_req_fw_callback(const struct firmware * ucode_raw,void * context)1598 static void iwl_req_fw_callback(const struct firmware *ucode_raw, void *context)
1599 {
1600 	int min_core, max_core, loaded_core;
1601 	struct iwl_drv *drv = context;
1602 	struct iwl_fw *fw = &drv->fw;
1603 	const struct iwl_ucode_header *ucode;
1604 	struct iwlwifi_opmode_table *op;
1605 	int err;
1606 	struct iwl_firmware_pieces *pieces;
1607 	unsigned int api_min, api_max;
1608 	size_t trigger_tlv_sz[FW_DBG_TRIGGER_MAX];
1609 	u32 api_ver;
1610 	int i;
1611 	bool usniffer_images = false;
1612 	bool failure = true;
1613 
1614 	iwl_get_ucode_api_versions(drv->trans, &api_min, &api_max);
1615 
1616 	fw->ucode_capa.max_probe_length = IWL_DEFAULT_MAX_PROBE_LENGTH;
1617 	fw->ucode_capa.standard_phy_calibration_size =
1618 			IWL_DEFAULT_STANDARD_PHY_CALIBRATE_TBL_SIZE;
1619 	fw->ucode_capa.n_scan_channels = IWL_DEFAULT_SCAN_CHANNELS;
1620 	fw->ucode_capa.num_stations = IWL_STATION_COUNT_MAX;
1621 	fw->ucode_capa.num_beacons = 1;
1622 	/* dump all fw memory areas by default */
1623 	fw->dbg.dump_mask = 0xffffffff;
1624 
1625 	pieces = kzalloc(sizeof(*pieces), GFP_KERNEL);
1626 	if (!pieces)
1627 		goto out_free_fw;
1628 
1629 	if (!ucode_raw)
1630 		goto try_again;
1631 
1632 	IWL_DEBUG_FW_INFO(drv, "Loaded firmware file '%s' (%zd bytes).\n",
1633 			  drv->firmware_name, ucode_raw->size);
1634 
1635 	/* Make sure that we got at least the API version number */
1636 	if (ucode_raw->size < 4) {
1637 		IWL_ERR(drv, "File size way too small!\n");
1638 		goto try_again;
1639 	}
1640 
1641 	/* Data from ucode file:  header followed by uCode images */
1642 	ucode = (const struct iwl_ucode_header *)ucode_raw->data;
1643 
1644 	if (ucode->ver)
1645 		err = iwl_parse_v1_v2_firmware(drv, ucode_raw, pieces);
1646 	else
1647 		err = iwl_parse_tlv_firmware(drv, ucode_raw, pieces,
1648 					     &fw->ucode_capa, &usniffer_images);
1649 
1650 	if (err)
1651 		goto try_again;
1652 
1653 	if (fw_has_api(&drv->fw.ucode_capa, IWL_UCODE_TLV_API_NEW_VERSION))
1654 		api_ver = drv->fw.ucode_ver;
1655 	else
1656 		api_ver = IWL_UCODE_API(drv->fw.ucode_ver);
1657 
1658 	/*
1659 	 * api_ver should match the api version forming part of the
1660 	 * firmware filename ... but we don't check for that and only rely
1661 	 * on the API version read from firmware header from here on forward
1662 	 */
1663 
1664 	/*
1665 	 * if -cN.ucode file was loaded, core version == file version,
1666 	 * otherwise core version == file version (API version) - 3
1667 	 */
1668 	if (iwl_api_is_core_number(drv->fw_index))
1669 		loaded_core = api_ver;
1670 	else
1671 		loaded_core = api_ver - API_TO_CORE_OFFS;
1672 
1673 	min_core = iwl_api_to_core(api_min);
1674 	max_core = iwl_api_to_core(api_max);
1675 
1676 	if (loaded_core < min_core || loaded_core > max_core) {
1677 		IWL_ERR(drv,
1678 			"Driver unable to support your firmware API. "
1679 			"Driver supports FW core %d..%d, firmware is %d.\n",
1680 			min_core, max_core, loaded_core);
1681 		goto try_again;
1682 	}
1683 
1684 	/*
1685 	 * In mvm uCode there is no difference between data and instructions
1686 	 * sections.
1687 	 */
1688 	if (fw->type == IWL_FW_DVM && validate_sec_sizes(drv, pieces,
1689 							 drv->trans->cfg))
1690 		goto try_again;
1691 
1692 	/* Allocate ucode buffers for card's bus-master loading ... */
1693 
1694 	/* Runtime instructions and 2 copies of data:
1695 	 * 1) unmodified from disk
1696 	 * 2) backup cache for save/restore during power-downs
1697 	 */
1698 	for (i = 0; i < IWL_UCODE_TYPE_MAX; i++)
1699 		if (iwl_alloc_ucode(drv, pieces, i))
1700 			goto out_free_fw;
1701 
1702 	if (pieces->dbg_dest_tlv_init) {
1703 		size_t dbg_dest_size = sizeof(*drv->fw.dbg.dest_tlv) +
1704 			sizeof(drv->fw.dbg.dest_tlv->reg_ops[0]) *
1705 			drv->fw.dbg.n_dest_reg;
1706 
1707 		drv->fw.dbg.dest_tlv = kmalloc(dbg_dest_size, GFP_KERNEL);
1708 
1709 		if (!drv->fw.dbg.dest_tlv)
1710 			goto out_free_fw;
1711 
1712 		if (*pieces->dbg_dest_ver == 0) {
1713 			memcpy(drv->fw.dbg.dest_tlv, pieces->dbg_dest_tlv_v1,
1714 			       dbg_dest_size);
1715 		} else {
1716 			struct iwl_fw_dbg_dest_tlv_v1 *dest_tlv =
1717 				drv->fw.dbg.dest_tlv;
1718 
1719 			dest_tlv->version = pieces->dbg_dest_tlv->version;
1720 			dest_tlv->monitor_mode =
1721 				pieces->dbg_dest_tlv->monitor_mode;
1722 			dest_tlv->size_power =
1723 				pieces->dbg_dest_tlv->size_power;
1724 			dest_tlv->wrap_count =
1725 				pieces->dbg_dest_tlv->wrap_count;
1726 			dest_tlv->write_ptr_reg =
1727 				pieces->dbg_dest_tlv->write_ptr_reg;
1728 			dest_tlv->base_shift =
1729 				pieces->dbg_dest_tlv->base_shift;
1730 			memcpy(dest_tlv->reg_ops,
1731 			       pieces->dbg_dest_tlv->reg_ops,
1732 			       sizeof(drv->fw.dbg.dest_tlv->reg_ops[0]) *
1733 			       drv->fw.dbg.n_dest_reg);
1734 
1735 			/* In version 1 of the destination tlv, which is
1736 			 * relevant for internal buffer exclusively,
1737 			 * the base address is part of given with the length
1738 			 * of the buffer, and the size shift is give instead of
1739 			 * end shift. We now store these values in base_reg,
1740 			 * and end shift, and when dumping the data we'll
1741 			 * manipulate it for extracting both the length and
1742 			 * base address */
1743 			dest_tlv->base_reg = pieces->dbg_dest_tlv->cfg_reg;
1744 			dest_tlv->end_shift =
1745 				pieces->dbg_dest_tlv->size_shift;
1746 		}
1747 	}
1748 
1749 	for (i = 0; i < ARRAY_SIZE(drv->fw.dbg.conf_tlv); i++) {
1750 		if (pieces->dbg_conf_tlv[i]) {
1751 			drv->fw.dbg.conf_tlv[i] =
1752 				kmemdup(pieces->dbg_conf_tlv[i],
1753 					pieces->dbg_conf_tlv_len[i],
1754 					GFP_KERNEL);
1755 			if (!drv->fw.dbg.conf_tlv[i])
1756 				goto out_free_fw;
1757 		}
1758 	}
1759 
1760 	memset(&trigger_tlv_sz, 0xff, sizeof(trigger_tlv_sz));
1761 
1762 	trigger_tlv_sz[FW_DBG_TRIGGER_MISSED_BEACONS] =
1763 		sizeof(struct iwl_fw_dbg_trigger_missed_bcon);
1764 	trigger_tlv_sz[FW_DBG_TRIGGER_CHANNEL_SWITCH] = 0;
1765 	trigger_tlv_sz[FW_DBG_TRIGGER_FW_NOTIF] =
1766 		sizeof(struct iwl_fw_dbg_trigger_cmd);
1767 	trigger_tlv_sz[FW_DBG_TRIGGER_MLME] =
1768 		sizeof(struct iwl_fw_dbg_trigger_mlme);
1769 	trigger_tlv_sz[FW_DBG_TRIGGER_STATS] =
1770 		sizeof(struct iwl_fw_dbg_trigger_stats);
1771 	trigger_tlv_sz[FW_DBG_TRIGGER_RSSI] =
1772 		sizeof(struct iwl_fw_dbg_trigger_low_rssi);
1773 	trigger_tlv_sz[FW_DBG_TRIGGER_TXQ_TIMERS] =
1774 		sizeof(struct iwl_fw_dbg_trigger_txq_timer);
1775 	trigger_tlv_sz[FW_DBG_TRIGGER_TIME_EVENT] =
1776 		sizeof(struct iwl_fw_dbg_trigger_time_event);
1777 	trigger_tlv_sz[FW_DBG_TRIGGER_BA] =
1778 		sizeof(struct iwl_fw_dbg_trigger_ba);
1779 	trigger_tlv_sz[FW_DBG_TRIGGER_TDLS] =
1780 		sizeof(struct iwl_fw_dbg_trigger_tdls);
1781 
1782 	for (i = 0; i < ARRAY_SIZE(drv->fw.dbg.trigger_tlv); i++) {
1783 		if (pieces->dbg_trigger_tlv[i]) {
1784 			/*
1785 			 * If the trigger isn't long enough, WARN and exit.
1786 			 * Someone is trying to debug something and he won't
1787 			 * be able to catch the bug he is trying to chase.
1788 			 * We'd better be noisy to be sure he knows what's
1789 			 * going on.
1790 			 */
1791 			if (WARN_ON(pieces->dbg_trigger_tlv_len[i] <
1792 				    (trigger_tlv_sz[i] +
1793 				     sizeof(struct iwl_fw_dbg_trigger_tlv))))
1794 				goto out_free_fw;
1795 			drv->fw.dbg.trigger_tlv_len[i] =
1796 				pieces->dbg_trigger_tlv_len[i];
1797 			drv->fw.dbg.trigger_tlv[i] =
1798 				kmemdup(pieces->dbg_trigger_tlv[i],
1799 					drv->fw.dbg.trigger_tlv_len[i],
1800 					GFP_KERNEL);
1801 			if (!drv->fw.dbg.trigger_tlv[i])
1802 				goto out_free_fw;
1803 		}
1804 	}
1805 
1806 	/* Now that we can no longer fail, copy information */
1807 
1808 	drv->fw.dbg.mem_tlv = pieces->dbg_mem_tlv;
1809 	pieces->dbg_mem_tlv = NULL;
1810 	drv->fw.dbg.n_mem_tlv = pieces->n_mem_tlv;
1811 
1812 	/*
1813 	 * The (size - 16) / 12 formula is based on the information recorded
1814 	 * for each event, which is of mode 1 (including timestamp) for all
1815 	 * new microcodes that include this information.
1816 	 */
1817 	fw->init_evtlog_ptr = pieces->init_evtlog_ptr;
1818 	if (pieces->init_evtlog_size)
1819 		fw->init_evtlog_size = (pieces->init_evtlog_size - 16)/12;
1820 	else
1821 		fw->init_evtlog_size =
1822 			drv->trans->mac_cfg->base->max_event_log_size;
1823 	fw->init_errlog_ptr = pieces->init_errlog_ptr;
1824 	fw->inst_evtlog_ptr = pieces->inst_evtlog_ptr;
1825 	if (pieces->inst_evtlog_size)
1826 		fw->inst_evtlog_size = (pieces->inst_evtlog_size - 16)/12;
1827 	else
1828 		fw->inst_evtlog_size =
1829 			drv->trans->mac_cfg->base->max_event_log_size;
1830 	fw->inst_errlog_ptr = pieces->inst_errlog_ptr;
1831 
1832 	/*
1833 	 * figure out the offset of chain noise reset and gain commands
1834 	 * base on the size of standard phy calibration commands table size
1835 	 */
1836 	if (fw->ucode_capa.standard_phy_calibration_size >
1837 	    IWL_MAX_PHY_CALIBRATE_TBL_SIZE)
1838 		fw->ucode_capa.standard_phy_calibration_size =
1839 			IWL_MAX_STANDARD_PHY_CALIBRATE_TBL_SIZE;
1840 
1841 	/* We have our copies now, allow OS release its copies */
1842 	release_firmware(ucode_raw);
1843 
1844 	iwl_dbg_tlv_load_bin(drv->trans->dev, drv->trans);
1845 
1846 	mutex_lock(&iwlwifi_opmode_table_mtx);
1847 	switch (fw->type) {
1848 	case IWL_FW_DVM:
1849 		op = &iwlwifi_opmode_table[DVM_OP_MODE];
1850 		break;
1851 	default:
1852 		WARN(1, "Invalid fw type %d\n", fw->type);
1853 		fallthrough;
1854 	case IWL_FW_MVM:
1855 		op = &iwlwifi_opmode_table[MVM_OP_MODE];
1856 		break;
1857 	}
1858 
1859 #if IS_ENABLED(CONFIG_IWLMLD)
1860 	if (iwl_drv_is_wifi7_supported(drv->trans))
1861 		op = &iwlwifi_opmode_table[MLD_OP_MODE];
1862 #endif
1863 
1864 	IWL_INFO(drv, "loaded firmware version %s op_mode %s\n",
1865 		 drv->fw.fw_version, op->name);
1866 
1867 	/* add this device to the list of devices using this op_mode */
1868 	list_add_tail(&drv->list, &op->drv);
1869 
1870 	if (op->ops) {
1871 		drv->op_mode = _iwl_op_mode_start(drv, op);
1872 
1873 		if (!drv->op_mode) {
1874 			mutex_unlock(&iwlwifi_opmode_table_mtx);
1875 			goto out_unbind;
1876 		}
1877 	} else {
1878 		request_module_nowait("%s", op->name);
1879 	}
1880 	mutex_unlock(&iwlwifi_opmode_table_mtx);
1881 
1882 	complete(&drv->request_firmware_complete);
1883 
1884 	failure = false;
1885 	goto free;
1886 
1887  try_again:
1888 	/* try next, if any */
1889 	release_firmware(ucode_raw);
1890 	if (iwl_request_firmware(drv, false))
1891 		goto out_unbind;
1892 	goto free;
1893 
1894  out_free_fw:
1895 	release_firmware(ucode_raw);
1896  out_unbind:
1897 	complete(&drv->request_firmware_complete);
1898 	device_release_driver(drv->trans->dev);
1899 	/* drv has just been freed by the release */
1900 	failure = false;
1901  free:
1902 	if (failure)
1903 		iwl_dealloc_ucode(drv);
1904 
1905 	if (pieces) {
1906 		for (i = 0; i < ARRAY_SIZE(pieces->img); i++)
1907 			kfree(pieces->img[i].sec);
1908 		kfree(pieces->dbg_mem_tlv);
1909 		kfree(pieces);
1910 	}
1911 }
1912 
iwl_drv_start(struct iwl_trans * trans)1913 struct iwl_drv *iwl_drv_start(struct iwl_trans *trans)
1914 {
1915 	struct iwl_drv *drv;
1916 	int ret;
1917 
1918 	drv = kzalloc(sizeof(*drv), GFP_KERNEL);
1919 	if (!drv) {
1920 		ret = -ENOMEM;
1921 		goto err;
1922 	}
1923 
1924 	drv->trans = trans;
1925 	drv->dev = trans->dev;
1926 
1927 	init_completion(&drv->request_firmware_complete);
1928 	INIT_LIST_HEAD(&drv->list);
1929 
1930 #ifdef CONFIG_IWLWIFI_DEBUGFS
1931 	/* Create the device debugfs entries. */
1932 	drv->dbgfs_drv = debugfs_create_dir(dev_name(trans->dev),
1933 					    iwl_dbgfs_root);
1934 
1935 	/* Create transport layer debugfs dir */
1936 	drv->trans->dbgfs_dir = debugfs_create_dir("trans", drv->dbgfs_drv);
1937 #endif
1938 
1939 	drv->trans->dbg.domains_bitmap = IWL_TRANS_FW_DBG_DOMAIN(drv->trans);
1940 	if (iwlwifi_mod_params.enable_ini != ENABLE_INI) {
1941 		/* We have a non-default value in the module parameter,
1942 		 * take its value
1943 		 */
1944 		drv->trans->dbg.domains_bitmap &= 0xffff;
1945 		if (iwlwifi_mod_params.enable_ini != IWL_FW_INI_PRESET_DISABLE) {
1946 			if (iwlwifi_mod_params.enable_ini > ENABLE_INI) {
1947 				IWL_ERR(trans,
1948 					"invalid enable_ini module parameter value: max = %d, using 0 instead\n",
1949 					ENABLE_INI);
1950 				iwlwifi_mod_params.enable_ini = 0;
1951 			}
1952 			drv->trans->dbg.domains_bitmap =
1953 				BIT(IWL_FW_DBG_DOMAIN_POS + iwlwifi_mod_params.enable_ini);
1954 		}
1955 	}
1956 
1957 	ret = iwl_request_firmware(drv, true);
1958 	if (ret) {
1959 		IWL_ERR(trans, "Couldn't request the fw\n");
1960 		goto err_fw;
1961 	}
1962 
1963 	return drv;
1964 
1965 err_fw:
1966 #ifdef CONFIG_IWLWIFI_DEBUGFS
1967 	debugfs_remove_recursive(drv->dbgfs_drv);
1968 #endif
1969 	iwl_dbg_tlv_free(drv->trans);
1970 	kfree(drv);
1971 err:
1972 	return ERR_PTR(ret);
1973 }
1974 
iwl_drv_stop(struct iwl_drv * drv)1975 void iwl_drv_stop(struct iwl_drv *drv)
1976 {
1977 	wait_for_completion(&drv->request_firmware_complete);
1978 
1979 	mutex_lock(&iwlwifi_opmode_table_mtx);
1980 
1981 	_iwl_op_mode_stop(drv);
1982 
1983 	iwl_dealloc_ucode(drv);
1984 
1985 	/*
1986 	 * List is empty (this item wasn't added)
1987 	 * when firmware loading failed -- in that
1988 	 * case we can't remove it from any list.
1989 	 */
1990 	if (!list_empty(&drv->list))
1991 		list_del(&drv->list);
1992 	mutex_unlock(&iwlwifi_opmode_table_mtx);
1993 
1994 #ifdef CONFIG_IWLWIFI_DEBUGFS
1995 	iwl_trans_debugfs_cleanup(drv->trans);
1996 
1997 	debugfs_remove_recursive(drv->dbgfs_drv);
1998 #endif
1999 
2000 	iwl_dbg_tlv_free(drv->trans);
2001 
2002 	kfree(drv);
2003 }
2004 
2005 /* shared module parameters */
2006 struct iwl_mod_params iwlwifi_mod_params = {
2007 	.fw_restart = true,
2008 	.bt_coex_active = true,
2009 	.power_level = IWL_POWER_INDEX_1,
2010 	.uapsd_disable = IWL_DISABLE_UAPSD_BSS | IWL_DISABLE_UAPSD_P2P_CLIENT,
2011 	.enable_ini = ENABLE_INI,
2012 	/* the rest are 0 by default */
2013 };
2014 IWL_EXPORT_SYMBOL(iwlwifi_mod_params);
2015 
iwl_opmode_register(const char * name,const struct iwl_op_mode_ops * ops)2016 int iwl_opmode_register(const char *name, const struct iwl_op_mode_ops *ops)
2017 {
2018 	int i;
2019 	struct iwl_drv *drv;
2020 	struct iwlwifi_opmode_table *op;
2021 
2022 	mutex_lock(&iwlwifi_opmode_table_mtx);
2023 	for (i = 0; i < ARRAY_SIZE(iwlwifi_opmode_table); i++) {
2024 		op = &iwlwifi_opmode_table[i];
2025 		if (strcmp(op->name, name))
2026 			continue;
2027 		op->ops = ops;
2028 		/* TODO: need to handle exceptional case */
2029 		list_for_each_entry(drv, &op->drv, list)
2030 			drv->op_mode = _iwl_op_mode_start(drv, op);
2031 
2032 		mutex_unlock(&iwlwifi_opmode_table_mtx);
2033 		return 0;
2034 	}
2035 	mutex_unlock(&iwlwifi_opmode_table_mtx);
2036 	return -EIO;
2037 }
2038 IWL_EXPORT_SYMBOL(iwl_opmode_register);
2039 
iwl_opmode_deregister(const char * name)2040 void iwl_opmode_deregister(const char *name)
2041 {
2042 	int i;
2043 	struct iwl_drv *drv;
2044 
2045 	mutex_lock(&iwlwifi_opmode_table_mtx);
2046 	for (i = 0; i < ARRAY_SIZE(iwlwifi_opmode_table); i++) {
2047 		if (strcmp(iwlwifi_opmode_table[i].name, name))
2048 			continue;
2049 		iwlwifi_opmode_table[i].ops = NULL;
2050 
2051 		/* call the stop routine for all devices */
2052 		list_for_each_entry(drv, &iwlwifi_opmode_table[i].drv, list)
2053 			_iwl_op_mode_stop(drv);
2054 
2055 		mutex_unlock(&iwlwifi_opmode_table_mtx);
2056 		return;
2057 	}
2058 	mutex_unlock(&iwlwifi_opmode_table_mtx);
2059 }
2060 IWL_EXPORT_SYMBOL(iwl_opmode_deregister);
2061 
iwl_drv_init(void)2062 static int __init iwl_drv_init(void)
2063 {
2064 	int i, err;
2065 
2066 	for (i = 0; i < ARRAY_SIZE(iwlwifi_opmode_table); i++)
2067 		INIT_LIST_HEAD(&iwlwifi_opmode_table[i].drv);
2068 
2069 #ifdef CONFIG_IWLWIFI_DEBUGFS
2070 	/* Create the root of iwlwifi debugfs subsystem. */
2071 	iwl_dbgfs_root = debugfs_create_dir(DRV_NAME, NULL);
2072 #endif
2073 
2074 	err = iwl_pci_register_driver();
2075 	if (err)
2076 		goto cleanup_debugfs;
2077 
2078 	return 0;
2079 
2080 cleanup_debugfs:
2081 #ifdef CONFIG_IWLWIFI_DEBUGFS
2082 	debugfs_remove_recursive(iwl_dbgfs_root);
2083 #endif
2084 	return err;
2085 }
2086 module_init(iwl_drv_init);
2087 
iwl_drv_exit(void)2088 static void __exit iwl_drv_exit(void)
2089 {
2090 	iwl_pci_unregister_driver();
2091 	iwl_trans_free_restart_list();
2092 
2093 #ifdef CONFIG_IWLWIFI_DEBUGFS
2094 	debugfs_remove_recursive(iwl_dbgfs_root);
2095 #endif
2096 }
2097 module_exit(iwl_drv_exit);
2098 
2099 #ifdef CONFIG_IWLWIFI_DEBUG
2100 module_param_named(debug, iwlwifi_mod_params.debug_level, uint, 0644);
2101 MODULE_PARM_DESC(debug, "debug output mask");
2102 #endif
2103 
2104 module_param_named(swcrypto, iwlwifi_mod_params.swcrypto, int, 0444);
2105 MODULE_PARM_DESC(swcrypto, "using crypto in software (default 0 [hardware])");
2106 module_param_named(11n_disable, iwlwifi_mod_params.disable_11n, uint, 0444);
2107 MODULE_PARM_DESC(11n_disable,
2108 	"disable 11n functionality, bitmap: 1: full, 2: disable agg TX, 4: disable agg RX, 8 enable agg TX");
2109 module_param_named(amsdu_size, iwlwifi_mod_params.amsdu_size, int, 0444);
2110 MODULE_PARM_DESC(amsdu_size,
2111 		 "amsdu size 0: 12K for multi Rx queue devices, 2K for AX210 devices, "
2112 		 "4K for other devices 1:4K 2:8K 3:12K (16K buffers) 4: 2K (default 0)");
2113 module_param_named(fw_restart, iwlwifi_mod_params.fw_restart, bool, 0444);
2114 MODULE_PARM_DESC(fw_restart, "restart firmware in case of error (default true)");
2115 
2116 module_param_named(nvm_file, iwlwifi_mod_params.nvm_file, charp, 0444);
2117 MODULE_PARM_DESC(nvm_file, "NVM file name");
2118 
2119 module_param_named(uapsd_disable, iwlwifi_mod_params.uapsd_disable, uint, 0644);
2120 MODULE_PARM_DESC(uapsd_disable,
2121 		 "disable U-APSD functionality bitmap 1: BSS 2: P2P Client (default: 3)");
2122 
2123 module_param_named(enable_ini, iwlwifi_mod_params.enable_ini, uint, 0444);
2124 MODULE_PARM_DESC(enable_ini,
2125 		 "0:disable, 1-15:FW_DBG_PRESET Values, 16:enabled without preset value defined,"
2126 		 "Debug INI TLV FW debug infrastructure (default: 16)");
2127 
2128 /*
2129  * set bt_coex_active to true, uCode will do kill/defer
2130  * every time the priority line is asserted (BT is sending signals on the
2131  * priority line in the PCIx).
2132  * set bt_coex_active to false, uCode will ignore the BT activity and
2133  * perform the normal operation
2134  *
2135  * User might experience transmit issue on some platform due to WiFi/BT
2136  * co-exist problem. The possible behaviors are:
2137  *   Able to scan and finding all the available AP
2138  *   Not able to associate with any AP
2139  * On those platforms, WiFi communication can be restored by set
2140  * "bt_coex_active" module parameter to "false"
2141  *
2142  * default: bt_coex_active = true (BT_COEX_ENABLE)
2143  */
2144 module_param_named(bt_coex_active, iwlwifi_mod_params.bt_coex_active,
2145 		   bool, 0444);
2146 MODULE_PARM_DESC(bt_coex_active, "enable wifi/bt co-exist (default: enable)");
2147 
2148 module_param_named(led_mode, iwlwifi_mod_params.led_mode, int, 0444);
2149 MODULE_PARM_DESC(led_mode, "0=system default, "
2150 		"1=On(RF On)/Off(RF Off), 2=blinking, 3=Off (default: 0)");
2151 
2152 module_param_named(power_save, iwlwifi_mod_params.power_save, bool, 0444);
2153 MODULE_PARM_DESC(power_save,
2154 		 "enable WiFi power management (default: disable)");
2155 
2156 module_param_named(power_level, iwlwifi_mod_params.power_level, int, 0444);
2157 MODULE_PARM_DESC(power_level,
2158 		 "default power save level (range from 1 - 5, default: 1)");
2159 
2160 module_param_named(disable_11ac, iwlwifi_mod_params.disable_11ac, bool, 0444);
2161 MODULE_PARM_DESC(disable_11ac, "Disable VHT capabilities (default: false)");
2162 
2163 module_param_named(remove_when_gone,
2164 		   iwlwifi_mod_params.remove_when_gone, bool,
2165 		   0444);
2166 MODULE_PARM_DESC(remove_when_gone,
2167 		 "Remove dev from PCIe bus if it is deemed inaccessible (default: false)");
2168 
2169 module_param_named(disable_11ax, iwlwifi_mod_params.disable_11ax, bool,
2170 		   S_IRUGO);
2171 MODULE_PARM_DESC(disable_11ax, "Disable HE capabilities (default: false)");
2172 
2173 module_param_named(disable_11be, iwlwifi_mod_params.disable_11be, bool, 0444);
2174 MODULE_PARM_DESC(disable_11be, "Disable EHT capabilities (default: false)");
2175