blob: 662d9936485c409bdc7c759d1f8d10936ef7da40 [file] [log] [blame]
Emmanuel Grumbach5c58edc2012-02-07 14:18:40 +02001/******************************************************************************
2 *
3 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license.
5 *
6 * GPL LICENSE SUMMARY
7 *
Emmanuel Grumbach51368bf2013-12-30 13:15:54 +02008 * Copyright(c) 2007 - 2014 Intel Corporation. All rights reserved.
Emmanuel Grumbach5c58edc2012-02-07 14:18:40 +02009 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
22 * USA
23 *
24 * The full GNU General Public License is included in this distribution
Emmanuel Grumbach410dc5a2013-02-18 09:22:28 +020025 * in the file called COPYING.
Emmanuel Grumbach5c58edc2012-02-07 14:18:40 +020026 *
27 * Contact Information:
28 * Intel Linux Wireless <ilw@linux.intel.com>
29 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
30 *
31 * BSD LICENSE
32 *
Emmanuel Grumbach51368bf2013-12-30 13:15:54 +020033 * Copyright(c) 2005 - 2014 Intel Corporation. All rights reserved.
Emmanuel Grumbach5c58edc2012-02-07 14:18:40 +020034 * All rights reserved.
35 *
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
38 * are met:
39 *
40 * * Redistributions of source code must retain the above copyright
41 * notice, this list of conditions and the following disclaimer.
42 * * Redistributions in binary form must reproduce the above copyright
43 * notice, this list of conditions and the following disclaimer in
44 * the documentation and/or other materials provided with the
45 * distribution.
46 * * Neither the name Intel Corporation nor the names of its
47 * contributors may be used to endorse or promote products derived
48 * from this software without specific prior written permission.
49 *
50 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
51 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
52 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
53 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
54 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
55 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
56 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
57 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
58 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
59 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
60 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
61 *
62 *****************************************************************************/
63#include <linux/completion.h>
Johannes Berg15854ef92012-03-05 11:24:50 -080064#include <linux/dma-mapping.h>
65#include <linux/firmware.h>
66#include <linux/module.h>
Johannes Berg83f84d72012-09-10 11:50:18 +020067#include <linux/vmalloc.h>
Emmanuel Grumbach5c58edc2012-02-07 14:18:40 +020068
69#include "iwl-drv.h"
Emmanuel Grumbachc15797e2012-04-19 10:29:58 +030070#include "iwl-debug.h"
Emmanuel Grumbach5c58edc2012-02-07 14:18:40 +020071#include "iwl-trans.h"
Emmanuel Grumbachd0f76d62012-02-09 16:08:15 +020072#include "iwl-op-mode.h"
David Spinadel0cedacc2012-03-10 13:00:12 -080073#include "iwl-agn-hw.h"
Johannes Berg6238b002012-04-02 15:04:33 +020074#include "iwl-fw.h"
75#include "iwl-config.h"
Johannes Berg65de7e82012-04-17 07:36:30 -070076#include "iwl-modparams.h"
Emmanuel Grumbach5c58edc2012-02-07 14:18:40 +020077
Johannes Berg0692fe42012-03-06 13:30:37 -080078/* private includes */
Johannes Berg3995dea2012-03-06 13:30:44 -080079#include "iwl-fw-file.h"
Johannes Berg0692fe42012-03-06 13:30:37 -080080
Don Frycc5f7e32012-05-16 22:54:27 +020081/******************************************************************************
82 *
83 * module boiler plate
84 *
85 ******************************************************************************/
86
87/*
88 * module name, copyright, version, etc.
89 */
90#define DRV_DESCRIPTION "Intel(R) Wireless WiFi driver for Linux"
91
92#ifdef CONFIG_IWLWIFI_DEBUG
93#define VD "d"
94#else
95#define VD
96#endif
97
98#define DRV_VERSION IWLWIFI_VERSION VD
99
100MODULE_DESCRIPTION(DRV_DESCRIPTION);
101MODULE_VERSION(DRV_VERSION);
102MODULE_AUTHOR(DRV_COPYRIGHT " " DRV_AUTHOR);
103MODULE_LICENSE("GPL");
104
Meenakshi Venkataraman9da987a2012-07-16 18:43:56 -0700105#ifdef CONFIG_IWLWIFI_DEBUGFS
106static struct dentry *iwl_dbgfs_root;
107#endif
108
Johannes Berg965974a62012-03-06 13:30:38 -0800109/**
110 * struct iwl_drv - drv common data
Don Frycc5f7e32012-05-16 22:54:27 +0200111 * @list: list of drv structures using this opmode
Johannes Berg965974a62012-03-06 13:30:38 -0800112 * @fw: the iwl_fw structure
Johannes Berg965974a62012-03-06 13:30:38 -0800113 * @op_mode: the running op_mode
Emmanuel Grumbach68f360d2012-03-22 17:51:44 +0200114 * @trans: transport layer
Emmanuel Grumbach4b9844f2012-03-22 23:59:52 +0200115 * @dev: for debug prints only
Emmanuel Grumbach68f360d2012-03-22 17:51:44 +0200116 * @cfg: configuration struct
Johannes Berg965974a62012-03-06 13:30:38 -0800117 * @fw_index: firmware revision to try loading
118 * @firmware_name: composite filename of ucode file to load
119 * @request_firmware_complete: the firmware has been obtained from user space
120 */
121struct iwl_drv {
Don Frycc5f7e32012-05-16 22:54:27 +0200122 struct list_head list;
Johannes Berg965974a62012-03-06 13:30:38 -0800123 struct iwl_fw fw;
124
Johannes Berg965974a62012-03-06 13:30:38 -0800125 struct iwl_op_mode *op_mode;
Emmanuel Grumbach9130bab2012-03-26 08:51:09 -0700126 struct iwl_trans *trans;
Emmanuel Grumbach4b9844f2012-03-22 23:59:52 +0200127 struct device *dev;
Emmanuel Grumbach68f360d2012-03-22 17:51:44 +0200128 const struct iwl_cfg *cfg;
Johannes Berg965974a62012-03-06 13:30:38 -0800129
130 int fw_index; /* firmware we're trying to load */
Liad Kaufman84b03122014-01-27 16:34:23 +0200131 char firmware_name[32]; /* name of firmware file to load */
Johannes Berg965974a62012-03-06 13:30:38 -0800132
133 struct completion request_firmware_complete;
Meenakshi Venkataraman9da987a2012-07-16 18:43:56 -0700134
135#ifdef CONFIG_IWLWIFI_DEBUGFS
136 struct dentry *dbgfs_drv;
137 struct dentry *dbgfs_trans;
138 struct dentry *dbgfs_op_mode;
139#endif
Johannes Berg965974a62012-03-06 13:30:38 -0800140};
141
Johannes Berg8ca151b2013-01-24 14:25:36 +0100142enum {
143 DVM_OP_MODE = 0,
144 MVM_OP_MODE = 1,
145};
Johannes Berg965974a62012-03-06 13:30:38 -0800146
Johannes Bergff1ffb82012-06-06 09:42:57 +0200147/* Protects the table contents, i.e. the ops pointer & drv list */
148static struct mutex iwlwifi_opmode_table_mtx;
Don Frycc5f7e32012-05-16 22:54:27 +0200149static struct iwlwifi_opmode_table {
150 const char *name; /* name: iwldvm, iwlmvm, etc */
151 const struct iwl_op_mode_ops *ops; /* pointer to op_mode ops */
152 struct list_head drv; /* list of devices using this op_mode */
153} iwlwifi_opmode_table[] = { /* ops set when driver is initialized */
Johannes Berg8ca151b2013-01-24 14:25:36 +0100154 [DVM_OP_MODE] = { .name = "iwldvm", .ops = NULL },
155 [MVM_OP_MODE] = { .name = "iwlmvm", .ops = NULL },
Don Frycc5f7e32012-05-16 22:54:27 +0200156};
Johannes Berg965974a62012-03-06 13:30:38 -0800157
David Spinadel0cedacc2012-03-10 13:00:12 -0800158/*
159 * struct fw_sec: Just for the image parsing proccess.
160 * For the fw storage we are using struct fw_desc.
161 */
162struct fw_sec {
163 const void *data; /* the sec data */
164 size_t size; /* section size */
165 u32 offset; /* offset of writing in the device */
166};
167
Johannes Berg965974a62012-03-06 13:30:38 -0800168static void iwl_free_fw_desc(struct iwl_drv *drv, struct fw_desc *desc)
Johannes Berg15854ef92012-03-05 11:24:50 -0800169{
Johannes Berg83f84d72012-09-10 11:50:18 +0200170 vfree(desc->data);
171 desc->data = NULL;
Johannes Berg15854ef92012-03-05 11:24:50 -0800172 desc->len = 0;
173}
174
Johannes Berg965974a62012-03-06 13:30:38 -0800175static void iwl_free_fw_img(struct iwl_drv *drv, struct fw_img *img)
Johannes Berg15854ef92012-03-05 11:24:50 -0800176{
David Spinadel6dfa8d02012-03-10 13:00:14 -0800177 int i;
178 for (i = 0; i < IWL_UCODE_SECTION_MAX; i++)
179 iwl_free_fw_desc(drv, &img->sec[i]);
Johannes Berg15854ef92012-03-05 11:24:50 -0800180}
181
Johannes Berg965974a62012-03-06 13:30:38 -0800182static void iwl_dealloc_ucode(struct iwl_drv *drv)
Johannes Berg15854ef92012-03-05 11:24:50 -0800183{
David Spinadel6dfa8d02012-03-10 13:00:14 -0800184 int i;
185 for (i = 0; i < IWL_UCODE_TYPE_MAX; i++)
186 iwl_free_fw_img(drv, drv->fw.img + i);
Johannes Berg15854ef92012-03-05 11:24:50 -0800187}
188
Johannes Berg965974a62012-03-06 13:30:38 -0800189static int iwl_alloc_fw_desc(struct iwl_drv *drv, struct fw_desc *desc,
Johannes Berg83f84d72012-09-10 11:50:18 +0200190 struct fw_sec *sec)
Johannes Berg15854ef92012-03-05 11:24:50 -0800191{
Johannes Berg83f84d72012-09-10 11:50:18 +0200192 void *data;
Johannes Berg15854ef92012-03-05 11:24:50 -0800193
Johannes Berg83f84d72012-09-10 11:50:18 +0200194 desc->data = NULL;
195
196 if (!sec || !sec->size)
197 return -EINVAL;
198
199 data = vmalloc(sec->size);
200 if (!data)
Johannes Berg15854ef92012-03-05 11:24:50 -0800201 return -ENOMEM;
202
David Spinadel0cedacc2012-03-10 13:00:12 -0800203 desc->len = sec->size;
204 desc->offset = sec->offset;
Johannes Berg83f84d72012-09-10 11:50:18 +0200205 memcpy(data, sec->data, desc->len);
206 desc->data = data;
207
Johannes Berg15854ef92012-03-05 11:24:50 -0800208 return 0;
209}
210
Emmanuel Grumbach1c8e11e2012-07-16 12:31:28 +0300211static void iwl_req_fw_callback(const struct firmware *ucode_raw,
212 void *context);
Johannes Berg15854ef92012-03-05 11:24:50 -0800213
214#define UCODE_EXPERIMENTAL_INDEX 100
215#define UCODE_EXPERIMENTAL_TAG "exp"
216
Johannes Berg965974a62012-03-06 13:30:38 -0800217static int iwl_request_firmware(struct iwl_drv *drv, bool first)
Johannes Berg15854ef92012-03-05 11:24:50 -0800218{
Emmanuel Grumbach68f360d2012-03-22 17:51:44 +0200219 const char *name_pre = drv->cfg->fw_name_pre;
Johannes Berg15854ef92012-03-05 11:24:50 -0800220 char tag[8];
221
222 if (first) {
223#ifdef CONFIG_IWLWIFI_DEBUG_EXPERIMENTAL_UCODE
Johannes Berg965974a62012-03-06 13:30:38 -0800224 drv->fw_index = UCODE_EXPERIMENTAL_INDEX;
Johannes Berg15854ef92012-03-05 11:24:50 -0800225 strcpy(tag, UCODE_EXPERIMENTAL_TAG);
Johannes Berg965974a62012-03-06 13:30:38 -0800226 } else if (drv->fw_index == UCODE_EXPERIMENTAL_INDEX) {
Johannes Berg15854ef92012-03-05 11:24:50 -0800227#endif
Emmanuel Grumbach68f360d2012-03-22 17:51:44 +0200228 drv->fw_index = drv->cfg->ucode_api_max;
Johannes Berg965974a62012-03-06 13:30:38 -0800229 sprintf(tag, "%d", drv->fw_index);
Johannes Berg15854ef92012-03-05 11:24:50 -0800230 } else {
Johannes Berg965974a62012-03-06 13:30:38 -0800231 drv->fw_index--;
232 sprintf(tag, "%d", drv->fw_index);
Johannes Berg15854ef92012-03-05 11:24:50 -0800233 }
234
Emmanuel Grumbach68f360d2012-03-22 17:51:44 +0200235 if (drv->fw_index < drv->cfg->ucode_api_min) {
Johannes Berg965974a62012-03-06 13:30:38 -0800236 IWL_ERR(drv, "no suitable firmware found!\n");
Johannes Berg15854ef92012-03-05 11:24:50 -0800237 return -ENOENT;
238 }
239
Liad Kaufman84b03122014-01-27 16:34:23 +0200240 snprintf(drv->firmware_name, sizeof(drv->firmware_name), "%s%s.ucode",
241 name_pre, tag);
Johannes Berg15854ef92012-03-05 11:24:50 -0800242
Johannes Berg965974a62012-03-06 13:30:38 -0800243 IWL_DEBUG_INFO(drv, "attempting to load firmware %s'%s'\n",
244 (drv->fw_index == UCODE_EXPERIMENTAL_INDEX)
Johannes Berg15854ef92012-03-05 11:24:50 -0800245 ? "EXPERIMENTAL " : "",
Johannes Berg965974a62012-03-06 13:30:38 -0800246 drv->firmware_name);
Johannes Berg15854ef92012-03-05 11:24:50 -0800247
Johannes Berg965974a62012-03-06 13:30:38 -0800248 return request_firmware_nowait(THIS_MODULE, 1, drv->firmware_name,
Emmanuel Grumbach93faaee2012-03-22 17:51:44 +0200249 drv->trans->dev,
Emmanuel Grumbach1c8e11e2012-07-16 12:31:28 +0300250 GFP_KERNEL, drv, iwl_req_fw_callback);
Johannes Berg15854ef92012-03-05 11:24:50 -0800251}
252
David Spinadel0cedacc2012-03-10 13:00:12 -0800253struct fw_img_parsing {
David Spinadel6dfa8d02012-03-10 13:00:14 -0800254 struct fw_sec sec[IWL_UCODE_SECTION_MAX];
David Spinadel0cedacc2012-03-10 13:00:12 -0800255 int sec_counter;
256};
257
David Spinadeled8c8362012-03-10 13:00:13 -0800258/*
259 * struct fw_sec_parsing: to extract fw section and it's offset from tlv
260 */
261struct fw_sec_parsing {
262 __le32 offset;
263 const u8 data[];
264} __packed;
265
266/**
267 * struct iwl_tlv_calib_data - parse the default calib data from TLV
268 *
269 * @ucode_type: the uCode to which the following default calib relates.
270 * @calib: default calibrations.
271 */
272struct iwl_tlv_calib_data {
273 __le32 ucode_type;
Johannes Bergaa2b1772013-01-24 14:12:07 +0100274 struct iwl_tlv_calib_ctrl calib;
David Spinadeled8c8362012-03-10 13:00:13 -0800275} __packed;
276
David Spinadel0cedacc2012-03-10 13:00:12 -0800277struct iwl_firmware_pieces {
278 struct fw_img_parsing img[IWL_UCODE_TYPE_MAX];
Johannes Berg15854ef92012-03-05 11:24:50 -0800279
280 u32 init_evtlog_ptr, init_evtlog_size, init_errlog_ptr;
281 u32 inst_evtlog_ptr, inst_evtlog_size, inst_errlog_ptr;
282};
283
David Spinadel0cedacc2012-03-10 13:00:12 -0800284/*
285 * These functions are just to extract uCode section data from the pieces
286 * structure.
287 */
288static struct fw_sec *get_sec(struct iwl_firmware_pieces *pieces,
289 enum iwl_ucode_type type,
290 int sec)
291{
292 return &pieces->img[type].sec[sec];
293}
294
295static void set_sec_data(struct iwl_firmware_pieces *pieces,
296 enum iwl_ucode_type type,
297 int sec,
298 const void *data)
299{
300 pieces->img[type].sec[sec].data = data;
301}
302
303static void set_sec_size(struct iwl_firmware_pieces *pieces,
304 enum iwl_ucode_type type,
305 int sec,
306 size_t size)
307{
308 pieces->img[type].sec[sec].size = size;
309}
310
311static size_t get_sec_size(struct iwl_firmware_pieces *pieces,
312 enum iwl_ucode_type type,
313 int sec)
314{
315 return pieces->img[type].sec[sec].size;
316}
317
318static void set_sec_offset(struct iwl_firmware_pieces *pieces,
319 enum iwl_ucode_type type,
320 int sec,
321 u32 offset)
322{
323 pieces->img[type].sec[sec].offset = offset;
324}
325
Max Stepanove36e5432013-08-27 19:56:13 +0300326static int iwl_store_cscheme(struct iwl_fw *fw, const u8 *data, const u32 len)
327{
328 int i, j;
329 struct iwl_fw_cscheme_list *l = (struct iwl_fw_cscheme_list *)data;
330 struct iwl_fw_cipher_scheme *fwcs;
331 struct ieee80211_cipher_scheme *cs;
332 u32 cipher;
333
334 if (len < sizeof(*l) ||
335 len < sizeof(l->size) + l->size * sizeof(l->cs[0]))
336 return -EINVAL;
337
338 for (i = 0, j = 0; i < IWL_UCODE_MAX_CS && i < l->size; i++) {
339 fwcs = &l->cs[j];
340 cipher = le32_to_cpu(fwcs->cipher);
341
342 /* we skip schemes with zero cipher suite selector */
343 if (!cipher)
344 continue;
345
346 cs = &fw->cs[j++];
347 cs->cipher = cipher;
348 cs->iftype = BIT(NL80211_IFTYPE_STATION);
349 cs->hdr_len = fwcs->hdr_len;
350 cs->pn_len = fwcs->pn_len;
351 cs->pn_off = fwcs->pn_off;
352 cs->key_idx_off = fwcs->key_idx_off;
353 cs->key_idx_mask = fwcs->key_idx_mask;
354 cs->key_idx_shift = fwcs->key_idx_shift;
355 cs->mic_len = fwcs->mic_len;
356 }
357
358 return 0;
359}
360
David Spinadeled8c8362012-03-10 13:00:13 -0800361/*
362 * Gets uCode section from tlv.
363 */
364static int iwl_store_ucode_sec(struct iwl_firmware_pieces *pieces,
365 const void *data, enum iwl_ucode_type type,
366 int size)
367{
368 struct fw_img_parsing *img;
369 struct fw_sec *sec;
370 struct fw_sec_parsing *sec_parse;
371
372 if (WARN_ON(!pieces || !data || type >= IWL_UCODE_TYPE_MAX))
373 return -1;
374
375 sec_parse = (struct fw_sec_parsing *)data;
376
377 img = &pieces->img[type];
378 sec = &img->sec[img->sec_counter];
379
380 sec->offset = le32_to_cpu(sec_parse->offset);
381 sec->data = sec_parse->data;
David Spinadel1176f432012-03-13 14:32:48 +0200382 sec->size = size - sizeof(sec_parse->offset);
David Spinadeled8c8362012-03-10 13:00:13 -0800383
384 ++img->sec_counter;
385
386 return 0;
387}
388
389static int iwl_set_default_calib(struct iwl_drv *drv, const u8 *data)
390{
391 struct iwl_tlv_calib_data *def_calib =
392 (struct iwl_tlv_calib_data *)data;
393 u32 ucode_type = le32_to_cpu(def_calib->ucode_type);
394 if (ucode_type >= IWL_UCODE_TYPE_MAX) {
395 IWL_ERR(drv, "Wrong ucode_type %u for default calibration.\n",
396 ucode_type);
397 return -EINVAL;
398 }
Johannes Bergaa2b1772013-01-24 14:12:07 +0100399 drv->fw.default_calib[ucode_type].flow_trigger =
400 def_calib->calib.flow_trigger;
401 drv->fw.default_calib[ucode_type].event_trigger =
402 def_calib->calib.event_trigger;
403
David Spinadeled8c8362012-03-10 13:00:13 -0800404 return 0;
405}
406
Johannes Berg965974a62012-03-06 13:30:38 -0800407static int iwl_parse_v1_v2_firmware(struct iwl_drv *drv,
David Spinadel0cedacc2012-03-10 13:00:12 -0800408 const struct firmware *ucode_raw,
409 struct iwl_firmware_pieces *pieces)
Johannes Berg15854ef92012-03-05 11:24:50 -0800410{
411 struct iwl_ucode_header *ucode = (void *)ucode_raw->data;
412 u32 api_ver, hdr_size, build;
413 char buildstr[25];
414 const u8 *src;
415
Johannes Berg965974a62012-03-06 13:30:38 -0800416 drv->fw.ucode_ver = le32_to_cpu(ucode->ver);
417 api_ver = IWL_UCODE_API(drv->fw.ucode_ver);
Johannes Berg15854ef92012-03-05 11:24:50 -0800418
419 switch (api_ver) {
420 default:
421 hdr_size = 28;
422 if (ucode_raw->size < hdr_size) {
Johannes Berg965974a62012-03-06 13:30:38 -0800423 IWL_ERR(drv, "File size too small!\n");
Johannes Berg15854ef92012-03-05 11:24:50 -0800424 return -EINVAL;
425 }
426 build = le32_to_cpu(ucode->u.v2.build);
David Spinadel0cedacc2012-03-10 13:00:12 -0800427 set_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_INST,
428 le32_to_cpu(ucode->u.v2.inst_size));
429 set_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_DATA,
430 le32_to_cpu(ucode->u.v2.data_size));
431 set_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST,
432 le32_to_cpu(ucode->u.v2.init_size));
433 set_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA,
434 le32_to_cpu(ucode->u.v2.init_data_size));
Johannes Berg15854ef92012-03-05 11:24:50 -0800435 src = ucode->u.v2.data;
436 break;
437 case 0:
438 case 1:
439 case 2:
440 hdr_size = 24;
441 if (ucode_raw->size < hdr_size) {
Johannes Berg965974a62012-03-06 13:30:38 -0800442 IWL_ERR(drv, "File size too small!\n");
Johannes Berg15854ef92012-03-05 11:24:50 -0800443 return -EINVAL;
444 }
445 build = 0;
David Spinadel0cedacc2012-03-10 13:00:12 -0800446 set_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_INST,
447 le32_to_cpu(ucode->u.v1.inst_size));
448 set_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_DATA,
449 le32_to_cpu(ucode->u.v1.data_size));
450 set_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST,
451 le32_to_cpu(ucode->u.v1.init_size));
452 set_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA,
453 le32_to_cpu(ucode->u.v1.init_data_size));
Johannes Berg15854ef92012-03-05 11:24:50 -0800454 src = ucode->u.v1.data;
455 break;
456 }
457
458 if (build)
459 sprintf(buildstr, " build %u%s", build,
Johannes Berg965974a62012-03-06 13:30:38 -0800460 (drv->fw_index == UCODE_EXPERIMENTAL_INDEX)
Johannes Berg15854ef92012-03-05 11:24:50 -0800461 ? " (EXP)" : "");
462 else
463 buildstr[0] = '\0';
464
Johannes Berg965974a62012-03-06 13:30:38 -0800465 snprintf(drv->fw.fw_version,
466 sizeof(drv->fw.fw_version),
Johannes Berg15854ef92012-03-05 11:24:50 -0800467 "%u.%u.%u.%u%s",
Johannes Berg965974a62012-03-06 13:30:38 -0800468 IWL_UCODE_MAJOR(drv->fw.ucode_ver),
469 IWL_UCODE_MINOR(drv->fw.ucode_ver),
470 IWL_UCODE_API(drv->fw.ucode_ver),
471 IWL_UCODE_SERIAL(drv->fw.ucode_ver),
Johannes Berg15854ef92012-03-05 11:24:50 -0800472 buildstr);
473
474 /* Verify size of file vs. image size info in file's header */
David Spinadel0cedacc2012-03-10 13:00:12 -0800475
476 if (ucode_raw->size != hdr_size +
477 get_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_INST) +
478 get_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_DATA) +
479 get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST) +
480 get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA)) {
Johannes Berg15854ef92012-03-05 11:24:50 -0800481
Johannes Berg965974a62012-03-06 13:30:38 -0800482 IWL_ERR(drv,
Johannes Berg15854ef92012-03-05 11:24:50 -0800483 "uCode file size %d does not match expected size\n",
484 (int)ucode_raw->size);
485 return -EINVAL;
486 }
487
Johannes Berg15854ef92012-03-05 11:24:50 -0800488
David Spinadel0cedacc2012-03-10 13:00:12 -0800489 set_sec_data(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_INST, src);
490 src += get_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_INST);
491 set_sec_offset(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_INST,
492 IWLAGN_RTC_INST_LOWER_BOUND);
493 set_sec_data(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_DATA, src);
494 src += get_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_DATA);
495 set_sec_offset(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_DATA,
496 IWLAGN_RTC_DATA_LOWER_BOUND);
497 set_sec_data(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST, src);
498 src += get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST);
499 set_sec_offset(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST,
500 IWLAGN_RTC_INST_LOWER_BOUND);
501 set_sec_data(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA, src);
502 src += get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA);
503 set_sec_offset(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA,
504 IWLAGN_RTC_DATA_LOWER_BOUND);
Johannes Berg15854ef92012-03-05 11:24:50 -0800505 return 0;
506}
507
Johannes Berg965974a62012-03-06 13:30:38 -0800508static int iwl_parse_tlv_firmware(struct iwl_drv *drv,
Johannes Berg15854ef92012-03-05 11:24:50 -0800509 const struct firmware *ucode_raw,
David Spinadel0cedacc2012-03-10 13:00:12 -0800510 struct iwl_firmware_pieces *pieces,
Johannes Berg15854ef92012-03-05 11:24:50 -0800511 struct iwl_ucode_capabilities *capa)
512{
513 struct iwl_tlv_ucode_header *ucode = (void *)ucode_raw->data;
514 struct iwl_ucode_tlv *tlv;
515 size_t len = ucode_raw->size;
516 const u8 *data;
Johannes Berg15854ef92012-03-05 11:24:50 -0800517 u32 tlv_len;
518 enum iwl_ucode_tlv_type tlv_type;
519 const u8 *tlv_data;
520 char buildstr[25];
521 u32 build;
Eran Hararye2d6f4e2013-10-02 13:53:40 +0300522 int num_of_cpus;
Johannes Berg15854ef92012-03-05 11:24:50 -0800523
524 if (len < sizeof(*ucode)) {
Johannes Berg965974a62012-03-06 13:30:38 -0800525 IWL_ERR(drv, "uCode has invalid length: %zd\n", len);
Johannes Berg15854ef92012-03-05 11:24:50 -0800526 return -EINVAL;
527 }
528
529 if (ucode->magic != cpu_to_le32(IWL_TLV_UCODE_MAGIC)) {
Johannes Berg965974a62012-03-06 13:30:38 -0800530 IWL_ERR(drv, "invalid uCode magic: 0X%x\n",
Johannes Berg15854ef92012-03-05 11:24:50 -0800531 le32_to_cpu(ucode->magic));
532 return -EINVAL;
533 }
534
Johannes Berg965974a62012-03-06 13:30:38 -0800535 drv->fw.ucode_ver = le32_to_cpu(ucode->ver);
Johannes Berg15854ef92012-03-05 11:24:50 -0800536 build = le32_to_cpu(ucode->build);
537
538 if (build)
539 sprintf(buildstr, " build %u%s", build,
Johannes Berg965974a62012-03-06 13:30:38 -0800540 (drv->fw_index == UCODE_EXPERIMENTAL_INDEX)
Johannes Berg15854ef92012-03-05 11:24:50 -0800541 ? " (EXP)" : "");
542 else
543 buildstr[0] = '\0';
544
Johannes Berg965974a62012-03-06 13:30:38 -0800545 snprintf(drv->fw.fw_version,
546 sizeof(drv->fw.fw_version),
Johannes Berg15854ef92012-03-05 11:24:50 -0800547 "%u.%u.%u.%u%s",
Johannes Berg965974a62012-03-06 13:30:38 -0800548 IWL_UCODE_MAJOR(drv->fw.ucode_ver),
549 IWL_UCODE_MINOR(drv->fw.ucode_ver),
550 IWL_UCODE_API(drv->fw.ucode_ver),
551 IWL_UCODE_SERIAL(drv->fw.ucode_ver),
Johannes Berg15854ef92012-03-05 11:24:50 -0800552 buildstr);
553
554 data = ucode->data;
555
556 len -= sizeof(*ucode);
557
558 while (len >= sizeof(*tlv)) {
Johannes Berg15854ef92012-03-05 11:24:50 -0800559 len -= sizeof(*tlv);
560 tlv = (void *)data;
561
562 tlv_len = le32_to_cpu(tlv->length);
Johannes Berg0479c192012-03-09 09:16:35 +0100563 tlv_type = le32_to_cpu(tlv->type);
Johannes Berg15854ef92012-03-05 11:24:50 -0800564 tlv_data = tlv->data;
565
566 if (len < tlv_len) {
Johannes Berg965974a62012-03-06 13:30:38 -0800567 IWL_ERR(drv, "invalid TLV len: %zd/%u\n",
Johannes Berg15854ef92012-03-05 11:24:50 -0800568 len, tlv_len);
569 return -EINVAL;
570 }
571 len -= ALIGN(tlv_len, 4);
572 data += sizeof(*tlv) + ALIGN(tlv_len, 4);
573
Johannes Berg15854ef92012-03-05 11:24:50 -0800574 switch (tlv_type) {
575 case IWL_UCODE_TLV_INST:
David Spinadel0cedacc2012-03-10 13:00:12 -0800576 set_sec_data(pieces, IWL_UCODE_REGULAR,
577 IWL_UCODE_SECTION_INST, tlv_data);
578 set_sec_size(pieces, IWL_UCODE_REGULAR,
579 IWL_UCODE_SECTION_INST, tlv_len);
580 set_sec_offset(pieces, IWL_UCODE_REGULAR,
581 IWL_UCODE_SECTION_INST,
582 IWLAGN_RTC_INST_LOWER_BOUND);
Johannes Berg15854ef92012-03-05 11:24:50 -0800583 break;
584 case IWL_UCODE_TLV_DATA:
David Spinadel0cedacc2012-03-10 13:00:12 -0800585 set_sec_data(pieces, IWL_UCODE_REGULAR,
586 IWL_UCODE_SECTION_DATA, tlv_data);
587 set_sec_size(pieces, IWL_UCODE_REGULAR,
588 IWL_UCODE_SECTION_DATA, tlv_len);
589 set_sec_offset(pieces, IWL_UCODE_REGULAR,
590 IWL_UCODE_SECTION_DATA,
591 IWLAGN_RTC_DATA_LOWER_BOUND);
Johannes Berg15854ef92012-03-05 11:24:50 -0800592 break;
593 case IWL_UCODE_TLV_INIT:
David Spinadel0cedacc2012-03-10 13:00:12 -0800594 set_sec_data(pieces, IWL_UCODE_INIT,
595 IWL_UCODE_SECTION_INST, tlv_data);
596 set_sec_size(pieces, IWL_UCODE_INIT,
597 IWL_UCODE_SECTION_INST, tlv_len);
598 set_sec_offset(pieces, IWL_UCODE_INIT,
599 IWL_UCODE_SECTION_INST,
600 IWLAGN_RTC_INST_LOWER_BOUND);
Johannes Berg15854ef92012-03-05 11:24:50 -0800601 break;
602 case IWL_UCODE_TLV_INIT_DATA:
David Spinadel0cedacc2012-03-10 13:00:12 -0800603 set_sec_data(pieces, IWL_UCODE_INIT,
604 IWL_UCODE_SECTION_DATA, tlv_data);
605 set_sec_size(pieces, IWL_UCODE_INIT,
606 IWL_UCODE_SECTION_DATA, tlv_len);
607 set_sec_offset(pieces, IWL_UCODE_INIT,
608 IWL_UCODE_SECTION_DATA,
609 IWLAGN_RTC_DATA_LOWER_BOUND);
Johannes Berg15854ef92012-03-05 11:24:50 -0800610 break;
611 case IWL_UCODE_TLV_BOOT:
Johannes Berg965974a62012-03-06 13:30:38 -0800612 IWL_ERR(drv, "Found unexpected BOOT ucode\n");
Johannes Berg15854ef92012-03-05 11:24:50 -0800613 break;
614 case IWL_UCODE_TLV_PROBE_MAX_LEN:
615 if (tlv_len != sizeof(u32))
616 goto invalid_tlv_len;
617 capa->max_probe_length =
618 le32_to_cpup((__le32 *)tlv_data);
619 break;
620 case IWL_UCODE_TLV_PAN:
621 if (tlv_len)
622 goto invalid_tlv_len;
623 capa->flags |= IWL_UCODE_TLV_FLAGS_PAN;
624 break;
625 case IWL_UCODE_TLV_FLAGS:
626 /* must be at least one u32 */
627 if (tlv_len < sizeof(u32))
628 goto invalid_tlv_len;
629 /* and a proper number of u32s */
630 if (tlv_len % sizeof(u32))
631 goto invalid_tlv_len;
632 /*
633 * This driver only reads the first u32 as
634 * right now no more features are defined,
635 * if that changes then either the driver
636 * will not work with the new firmware, or
637 * it'll not take advantage of new features.
638 */
639 capa->flags = le32_to_cpup((__le32 *)tlv_data);
640 break;
641 case IWL_UCODE_TLV_INIT_EVTLOG_PTR:
642 if (tlv_len != sizeof(u32))
643 goto invalid_tlv_len;
644 pieces->init_evtlog_ptr =
645 le32_to_cpup((__le32 *)tlv_data);
646 break;
647 case IWL_UCODE_TLV_INIT_EVTLOG_SIZE:
648 if (tlv_len != sizeof(u32))
649 goto invalid_tlv_len;
650 pieces->init_evtlog_size =
651 le32_to_cpup((__le32 *)tlv_data);
652 break;
653 case IWL_UCODE_TLV_INIT_ERRLOG_PTR:
654 if (tlv_len != sizeof(u32))
655 goto invalid_tlv_len;
656 pieces->init_errlog_ptr =
657 le32_to_cpup((__le32 *)tlv_data);
658 break;
659 case IWL_UCODE_TLV_RUNT_EVTLOG_PTR:
660 if (tlv_len != sizeof(u32))
661 goto invalid_tlv_len;
662 pieces->inst_evtlog_ptr =
663 le32_to_cpup((__le32 *)tlv_data);
664 break;
665 case IWL_UCODE_TLV_RUNT_EVTLOG_SIZE:
666 if (tlv_len != sizeof(u32))
667 goto invalid_tlv_len;
668 pieces->inst_evtlog_size =
669 le32_to_cpup((__le32 *)tlv_data);
670 break;
671 case IWL_UCODE_TLV_RUNT_ERRLOG_PTR:
672 if (tlv_len != sizeof(u32))
673 goto invalid_tlv_len;
674 pieces->inst_errlog_ptr =
675 le32_to_cpup((__le32 *)tlv_data);
676 break;
677 case IWL_UCODE_TLV_ENHANCE_SENS_TBL:
678 if (tlv_len)
679 goto invalid_tlv_len;
Johannes Berg965974a62012-03-06 13:30:38 -0800680 drv->fw.enhance_sensitivity_table = true;
Johannes Berg15854ef92012-03-05 11:24:50 -0800681 break;
682 case IWL_UCODE_TLV_WOWLAN_INST:
David Spinadel0cedacc2012-03-10 13:00:12 -0800683 set_sec_data(pieces, IWL_UCODE_WOWLAN,
684 IWL_UCODE_SECTION_INST, tlv_data);
685 set_sec_size(pieces, IWL_UCODE_WOWLAN,
686 IWL_UCODE_SECTION_INST, tlv_len);
687 set_sec_offset(pieces, IWL_UCODE_WOWLAN,
688 IWL_UCODE_SECTION_INST,
689 IWLAGN_RTC_INST_LOWER_BOUND);
Johannes Berg15854ef92012-03-05 11:24:50 -0800690 break;
691 case IWL_UCODE_TLV_WOWLAN_DATA:
David Spinadel0cedacc2012-03-10 13:00:12 -0800692 set_sec_data(pieces, IWL_UCODE_WOWLAN,
693 IWL_UCODE_SECTION_DATA, tlv_data);
694 set_sec_size(pieces, IWL_UCODE_WOWLAN,
695 IWL_UCODE_SECTION_DATA, tlv_len);
696 set_sec_offset(pieces, IWL_UCODE_WOWLAN,
697 IWL_UCODE_SECTION_DATA,
698 IWLAGN_RTC_DATA_LOWER_BOUND);
Johannes Berg15854ef92012-03-05 11:24:50 -0800699 break;
700 case IWL_UCODE_TLV_PHY_CALIBRATION_SIZE:
701 if (tlv_len != sizeof(u32))
702 goto invalid_tlv_len;
703 capa->standard_phy_calibration_size =
704 le32_to_cpup((__le32 *)tlv_data);
705 break;
David Spinadeled8c8362012-03-10 13:00:13 -0800706 case IWL_UCODE_TLV_SEC_RT:
707 iwl_store_ucode_sec(pieces, tlv_data, IWL_UCODE_REGULAR,
708 tlv_len);
David Spinadel4db2c9a2012-03-10 13:00:15 -0800709 drv->fw.mvm_fw = true;
David Spinadeled8c8362012-03-10 13:00:13 -0800710 break;
711 case IWL_UCODE_TLV_SEC_INIT:
712 iwl_store_ucode_sec(pieces, tlv_data, IWL_UCODE_INIT,
713 tlv_len);
David Spinadel4db2c9a2012-03-10 13:00:15 -0800714 drv->fw.mvm_fw = true;
David Spinadeled8c8362012-03-10 13:00:13 -0800715 break;
716 case IWL_UCODE_TLV_SEC_WOWLAN:
717 iwl_store_ucode_sec(pieces, tlv_data, IWL_UCODE_WOWLAN,
718 tlv_len);
David Spinadel4db2c9a2012-03-10 13:00:15 -0800719 drv->fw.mvm_fw = true;
David Spinadeled8c8362012-03-10 13:00:13 -0800720 break;
721 case IWL_UCODE_TLV_DEF_CALIB:
722 if (tlv_len != sizeof(struct iwl_tlv_calib_data))
723 goto invalid_tlv_len;
724 if (iwl_set_default_calib(drv, tlv_data))
725 goto tlv_error;
726 break;
727 case IWL_UCODE_TLV_PHY_SKU:
728 if (tlv_len != sizeof(u32))
729 goto invalid_tlv_len;
730 drv->fw.phy_config = le32_to_cpup((__le32 *)tlv_data);
Eran Harary77db0a32014-02-04 14:21:38 +0200731 drv->fw.valid_tx_ant = (drv->fw.phy_config &
732 FW_PHY_CFG_TX_CHAIN) >>
733 FW_PHY_CFG_TX_CHAIN_POS;
734 drv->fw.valid_rx_ant = (drv->fw.phy_config &
735 FW_PHY_CFG_RX_CHAIN) >>
736 FW_PHY_CFG_RX_CHAIN_POS;
David Spinadeled8c8362012-03-10 13:00:13 -0800737 break;
Eran Hararye2d6f4e2013-10-02 13:53:40 +0300738 case IWL_UCODE_TLV_SECURE_SEC_RT:
739 iwl_store_ucode_sec(pieces, tlv_data, IWL_UCODE_REGULAR,
740 tlv_len);
741 drv->fw.mvm_fw = true;
742 drv->fw.img[IWL_UCODE_REGULAR].is_secure = true;
743 break;
744 case IWL_UCODE_TLV_SECURE_SEC_INIT:
745 iwl_store_ucode_sec(pieces, tlv_data, IWL_UCODE_INIT,
746 tlv_len);
747 drv->fw.mvm_fw = true;
748 drv->fw.img[IWL_UCODE_INIT].is_secure = true;
749 break;
750 case IWL_UCODE_TLV_SECURE_SEC_WOWLAN:
751 iwl_store_ucode_sec(pieces, tlv_data, IWL_UCODE_WOWLAN,
752 tlv_len);
753 drv->fw.mvm_fw = true;
754 drv->fw.img[IWL_UCODE_WOWLAN].is_secure = true;
755 break;
756 case IWL_UCODE_TLV_NUM_OF_CPU:
757 if (tlv_len != sizeof(u32))
758 goto invalid_tlv_len;
759 num_of_cpus =
760 le32_to_cpup((__le32 *)tlv_data);
761
762 if (num_of_cpus == 2) {
763 drv->fw.img[IWL_UCODE_REGULAR].is_dual_cpus =
764 true;
765 drv->fw.img[IWL_UCODE_INIT].is_dual_cpus =
766 true;
767 drv->fw.img[IWL_UCODE_WOWLAN].is_dual_cpus =
768 true;
769 } else if ((num_of_cpus > 2) || (num_of_cpus < 1)) {
770 IWL_ERR(drv, "Driver support upto 2 CPUs\n");
771 return -EINVAL;
772 }
773 break;
Max Stepanove36e5432013-08-27 19:56:13 +0300774 case IWL_UCODE_TLV_CSCHEME:
775 if (iwl_store_cscheme(&drv->fw, tlv_data, tlv_len))
776 goto invalid_tlv_len;
777 break;
Johannes Berg15854ef92012-03-05 11:24:50 -0800778 default:
Johannes Berg965974a62012-03-06 13:30:38 -0800779 IWL_DEBUG_INFO(drv, "unknown TLV: %d\n", tlv_type);
Johannes Berg15854ef92012-03-05 11:24:50 -0800780 break;
781 }
782 }
783
784 if (len) {
Johannes Berg965974a62012-03-06 13:30:38 -0800785 IWL_ERR(drv, "invalid TLV after parsing: %zd\n", len);
786 iwl_print_hex_dump(drv, IWL_DL_FW, (u8 *)data, len);
Johannes Berg15854ef92012-03-05 11:24:50 -0800787 return -EINVAL;
788 }
789
790 return 0;
791
792 invalid_tlv_len:
Johannes Berg965974a62012-03-06 13:30:38 -0800793 IWL_ERR(drv, "TLV %d has invalid size: %u\n", tlv_type, tlv_len);
David Spinadeled8c8362012-03-10 13:00:13 -0800794 tlv_error:
Johannes Berg965974a62012-03-06 13:30:38 -0800795 iwl_print_hex_dump(drv, IWL_DL_FW, tlv_data, tlv_len);
Johannes Berg15854ef92012-03-05 11:24:50 -0800796
797 return -EINVAL;
798}
799
Johannes Berg75813bd2012-05-16 22:49:49 +0200800static int iwl_alloc_ucode(struct iwl_drv *drv,
801 struct iwl_firmware_pieces *pieces,
802 enum iwl_ucode_type type)
David Spinadel6dfa8d02012-03-10 13:00:14 -0800803{
804 int i;
805 for (i = 0;
806 i < IWL_UCODE_SECTION_MAX && get_sec_size(pieces, type, i);
807 i++)
808 if (iwl_alloc_fw_desc(drv, &(drv->fw.img[type].sec[i]),
Johannes Berg75813bd2012-05-16 22:49:49 +0200809 get_sec(pieces, type, i)))
810 return -ENOMEM;
David Spinadel6dfa8d02012-03-10 13:00:14 -0800811 return 0;
812}
813
814static int validate_sec_sizes(struct iwl_drv *drv,
815 struct iwl_firmware_pieces *pieces,
816 const struct iwl_cfg *cfg)
817{
818 IWL_DEBUG_INFO(drv, "f/w package hdr runtime inst size = %Zd\n",
819 get_sec_size(pieces, IWL_UCODE_REGULAR,
820 IWL_UCODE_SECTION_INST));
821 IWL_DEBUG_INFO(drv, "f/w package hdr runtime data size = %Zd\n",
822 get_sec_size(pieces, IWL_UCODE_REGULAR,
823 IWL_UCODE_SECTION_DATA));
824 IWL_DEBUG_INFO(drv, "f/w package hdr init inst size = %Zd\n",
825 get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST));
826 IWL_DEBUG_INFO(drv, "f/w package hdr init data size = %Zd\n",
827 get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA));
828
829 /* Verify that uCode images will fit in card's SRAM. */
830 if (get_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_INST) >
831 cfg->max_inst_size) {
832 IWL_ERR(drv, "uCode instr len %Zd too large to fit in\n",
833 get_sec_size(pieces, IWL_UCODE_REGULAR,
834 IWL_UCODE_SECTION_INST));
835 return -1;
836 }
837
838 if (get_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_DATA) >
839 cfg->max_data_size) {
840 IWL_ERR(drv, "uCode data len %Zd too large to fit in\n",
841 get_sec_size(pieces, IWL_UCODE_REGULAR,
842 IWL_UCODE_SECTION_DATA));
843 return -1;
844 }
845
846 if (get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST) >
847 cfg->max_inst_size) {
848 IWL_ERR(drv, "uCode init instr len %Zd too large to fit in\n",
849 get_sec_size(pieces, IWL_UCODE_INIT,
850 IWL_UCODE_SECTION_INST));
851 return -1;
852 }
853
854 if (get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA) >
855 cfg->max_data_size) {
856 IWL_ERR(drv, "uCode init data len %Zd too large to fit in\n",
857 get_sec_size(pieces, IWL_UCODE_REGULAR,
858 IWL_UCODE_SECTION_DATA));
859 return -1;
860 }
861 return 0;
862}
863
Meenakshi Venkataraman9da987a2012-07-16 18:43:56 -0700864static struct iwl_op_mode *
865_iwl_op_mode_start(struct iwl_drv *drv, struct iwlwifi_opmode_table *op)
866{
867 const struct iwl_op_mode_ops *ops = op->ops;
868 struct dentry *dbgfs_dir = NULL;
869 struct iwl_op_mode *op_mode = NULL;
870
871#ifdef CONFIG_IWLWIFI_DEBUGFS
872 drv->dbgfs_op_mode = debugfs_create_dir(op->name,
873 drv->dbgfs_drv);
874 if (!drv->dbgfs_op_mode) {
875 IWL_ERR(drv,
876 "failed to create opmode debugfs directory\n");
877 return op_mode;
878 }
879 dbgfs_dir = drv->dbgfs_op_mode;
880#endif
881
882 op_mode = ops->start(drv->trans, drv->cfg, &drv->fw, dbgfs_dir);
883
884#ifdef CONFIG_IWLWIFI_DEBUGFS
885 if (!op_mode) {
886 debugfs_remove_recursive(drv->dbgfs_op_mode);
887 drv->dbgfs_op_mode = NULL;
888 }
889#endif
890
891 return op_mode;
892}
893
894static void _iwl_op_mode_stop(struct iwl_drv *drv)
895{
896 /* op_mode can be NULL if its start failed */
897 if (drv->op_mode) {
898 iwl_op_mode_stop(drv->op_mode);
899 drv->op_mode = NULL;
900
901#ifdef CONFIG_IWLWIFI_DEBUGFS
902 debugfs_remove_recursive(drv->dbgfs_op_mode);
903 drv->dbgfs_op_mode = NULL;
904#endif
905 }
906}
907
Johannes Berg15854ef92012-03-05 11:24:50 -0800908/**
Emmanuel Grumbach1c8e11e2012-07-16 12:31:28 +0300909 * iwl_req_fw_callback - callback when firmware was loaded
Johannes Berg15854ef92012-03-05 11:24:50 -0800910 *
911 * If loaded successfully, copies the firmware into buffers
912 * for the card to fetch (via DMA).
913 */
Emmanuel Grumbach1c8e11e2012-07-16 12:31:28 +0300914static void iwl_req_fw_callback(const struct firmware *ucode_raw, void *context)
Johannes Berg15854ef92012-03-05 11:24:50 -0800915{
Johannes Berg965974a62012-03-06 13:30:38 -0800916 struct iwl_drv *drv = context;
Johannes Berg965974a62012-03-06 13:30:38 -0800917 struct iwl_fw *fw = &drv->fw;
Johannes Berg15854ef92012-03-05 11:24:50 -0800918 struct iwl_ucode_header *ucode;
Don Frycc5f7e32012-05-16 22:54:27 +0200919 struct iwlwifi_opmode_table *op;
Johannes Berg15854ef92012-03-05 11:24:50 -0800920 int err;
David Spinadel0cedacc2012-03-10 13:00:12 -0800921 struct iwl_firmware_pieces pieces;
Emmanuel Grumbach68f360d2012-03-22 17:51:44 +0200922 const unsigned int api_max = drv->cfg->ucode_api_max;
923 unsigned int api_ok = drv->cfg->ucode_api_ok;
924 const unsigned int api_min = drv->cfg->ucode_api_min;
Johannes Berg15854ef92012-03-05 11:24:50 -0800925 u32 api_ver;
David Spinadel6dfa8d02012-03-10 13:00:14 -0800926 int i;
Johannes Bergd4b10482012-06-12 19:50:43 +0200927 bool load_module = false;
Johannes Berg15854ef92012-03-05 11:24:50 -0800928
Luciano Coelho66140ad2013-08-12 19:30:21 +0300929 fw->ucode_capa.max_probe_length = IWL_DEFAULT_MAX_PROBE_LENGTH;
Johannes Berg15854ef92012-03-05 11:24:50 -0800930 fw->ucode_capa.standard_phy_calibration_size =
931 IWL_DEFAULT_STANDARD_PHY_CALIBRATE_TBL_SIZE;
932
933 if (!api_ok)
934 api_ok = api_max;
935
936 memset(&pieces, 0, sizeof(pieces));
937
938 if (!ucode_raw) {
Johannes Berg965974a62012-03-06 13:30:38 -0800939 if (drv->fw_index <= api_ok)
940 IWL_ERR(drv,
Johannes Berg15854ef92012-03-05 11:24:50 -0800941 "request for firmware file '%s' failed.\n",
Johannes Berg965974a62012-03-06 13:30:38 -0800942 drv->firmware_name);
Johannes Berg15854ef92012-03-05 11:24:50 -0800943 goto try_again;
944 }
945
Johannes Berg965974a62012-03-06 13:30:38 -0800946 IWL_DEBUG_INFO(drv, "Loaded firmware file '%s' (%zd bytes).\n",
947 drv->firmware_name, ucode_raw->size);
Johannes Berg15854ef92012-03-05 11:24:50 -0800948
949 /* Make sure that we got at least the API version number */
950 if (ucode_raw->size < 4) {
Johannes Berg965974a62012-03-06 13:30:38 -0800951 IWL_ERR(drv, "File size way too small!\n");
Johannes Berg15854ef92012-03-05 11:24:50 -0800952 goto try_again;
953 }
954
955 /* Data from ucode file: header followed by uCode images */
956 ucode = (struct iwl_ucode_header *)ucode_raw->data;
957
958 if (ucode->ver)
Johannes Berg965974a62012-03-06 13:30:38 -0800959 err = iwl_parse_v1_v2_firmware(drv, ucode_raw, &pieces);
Johannes Berg15854ef92012-03-05 11:24:50 -0800960 else
Johannes Berg965974a62012-03-06 13:30:38 -0800961 err = iwl_parse_tlv_firmware(drv, ucode_raw, &pieces,
Johannes Berg15854ef92012-03-05 11:24:50 -0800962 &fw->ucode_capa);
963
964 if (err)
965 goto try_again;
966
Johannes Berg965974a62012-03-06 13:30:38 -0800967 api_ver = IWL_UCODE_API(drv->fw.ucode_ver);
Johannes Berg15854ef92012-03-05 11:24:50 -0800968
969 /*
970 * api_ver should match the api version forming part of the
971 * firmware filename ... but we don't check for that and only rely
972 * on the API version read from firmware header from here on forward
973 */
974 /* no api version check required for experimental uCode */
Johannes Berg965974a62012-03-06 13:30:38 -0800975 if (drv->fw_index != UCODE_EXPERIMENTAL_INDEX) {
Johannes Berg15854ef92012-03-05 11:24:50 -0800976 if (api_ver < api_min || api_ver > api_max) {
Johannes Berg965974a62012-03-06 13:30:38 -0800977 IWL_ERR(drv,
Johannes Berg15854ef92012-03-05 11:24:50 -0800978 "Driver unable to support your firmware API. "
979 "Driver supports v%u, firmware is v%u.\n",
980 api_max, api_ver);
981 goto try_again;
982 }
983
984 if (api_ver < api_ok) {
985 if (api_ok != api_max)
Johannes Berg965974a62012-03-06 13:30:38 -0800986 IWL_ERR(drv, "Firmware has old API version, "
Johannes Berg15854ef92012-03-05 11:24:50 -0800987 "expected v%u through v%u, got v%u.\n",
988 api_ok, api_max, api_ver);
989 else
Johannes Berg965974a62012-03-06 13:30:38 -0800990 IWL_ERR(drv, "Firmware has old API version, "
Johannes Berg15854ef92012-03-05 11:24:50 -0800991 "expected v%u, got v%u.\n",
992 api_max, api_ver);
Johannes Berg965974a62012-03-06 13:30:38 -0800993 IWL_ERR(drv, "New firmware can be obtained from "
Johannes Berg15854ef92012-03-05 11:24:50 -0800994 "http://www.intellinuxwireless.org/.\n");
995 }
996 }
997
Johannes Berg15854ef92012-03-05 11:24:50 -0800998 /*
David Spinadel4db2c9a2012-03-10 13:00:15 -0800999 * In mvm uCode there is no difference between data and instructions
1000 * sections.
1001 */
Emmanuel Grumbach68f360d2012-03-22 17:51:44 +02001002 if (!fw->mvm_fw && validate_sec_sizes(drv, &pieces, drv->cfg))
Johannes Berg15854ef92012-03-05 11:24:50 -08001003 goto try_again;
Johannes Berg15854ef92012-03-05 11:24:50 -08001004
1005 /* Allocate ucode buffers for card's bus-master loading ... */
1006
1007 /* Runtime instructions and 2 copies of data:
1008 * 1) unmodified from disk
1009 * 2) backup cache for save/restore during power-downs */
David Spinadel6dfa8d02012-03-10 13:00:14 -08001010 for (i = 0; i < IWL_UCODE_TYPE_MAX; i++)
Johannes Berg75813bd2012-05-16 22:49:49 +02001011 if (iwl_alloc_ucode(drv, &pieces, i))
1012 goto out_free_fw;
Johannes Berg15854ef92012-03-05 11:24:50 -08001013
1014 /* Now that we can no longer fail, copy information */
1015
1016 /*
1017 * The (size - 16) / 12 formula is based on the information recorded
1018 * for each event, which is of mode 1 (including timestamp) for all
1019 * new microcodes that include this information.
1020 */
Johannes Berg0692fe42012-03-06 13:30:37 -08001021 fw->init_evtlog_ptr = pieces.init_evtlog_ptr;
Johannes Berg15854ef92012-03-05 11:24:50 -08001022 if (pieces.init_evtlog_size)
Johannes Berg0692fe42012-03-06 13:30:37 -08001023 fw->init_evtlog_size = (pieces.init_evtlog_size - 16)/12;
Johannes Berg15854ef92012-03-05 11:24:50 -08001024 else
Johannes Berg0692fe42012-03-06 13:30:37 -08001025 fw->init_evtlog_size =
Emmanuel Grumbach68f360d2012-03-22 17:51:44 +02001026 drv->cfg->base_params->max_event_log_size;
Johannes Berg0692fe42012-03-06 13:30:37 -08001027 fw->init_errlog_ptr = pieces.init_errlog_ptr;
1028 fw->inst_evtlog_ptr = pieces.inst_evtlog_ptr;
Johannes Berg15854ef92012-03-05 11:24:50 -08001029 if (pieces.inst_evtlog_size)
Johannes Berg0692fe42012-03-06 13:30:37 -08001030 fw->inst_evtlog_size = (pieces.inst_evtlog_size - 16)/12;
Johannes Berg15854ef92012-03-05 11:24:50 -08001031 else
Johannes Berg0692fe42012-03-06 13:30:37 -08001032 fw->inst_evtlog_size =
Emmanuel Grumbach68f360d2012-03-22 17:51:44 +02001033 drv->cfg->base_params->max_event_log_size;
Johannes Berg0692fe42012-03-06 13:30:37 -08001034 fw->inst_errlog_ptr = pieces.inst_errlog_ptr;
Johannes Berg15854ef92012-03-05 11:24:50 -08001035
1036 /*
1037 * figure out the offset of chain noise reset and gain commands
1038 * base on the size of standard phy calibration commands table size
1039 */
1040 if (fw->ucode_capa.standard_phy_calibration_size >
1041 IWL_MAX_PHY_CALIBRATE_TBL_SIZE)
1042 fw->ucode_capa.standard_phy_calibration_size =
1043 IWL_MAX_STANDARD_PHY_CALIBRATE_TBL_SIZE;
1044
1045 /* We have our copies now, allow OS release its copies */
1046 release_firmware(ucode_raw);
Johannes Berg15854ef92012-03-05 11:24:50 -08001047
Johannes Bergff1ffb82012-06-06 09:42:57 +02001048 mutex_lock(&iwlwifi_opmode_table_mtx);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001049 if (fw->mvm_fw)
1050 op = &iwlwifi_opmode_table[MVM_OP_MODE];
1051 else
1052 op = &iwlwifi_opmode_table[DVM_OP_MODE];
Johannes Berg15854ef92012-03-05 11:24:50 -08001053
Johannes Berg2b2719c2013-03-26 11:41:51 +01001054 IWL_INFO(drv, "loaded firmware version %s op_mode %s\n",
1055 drv->fw.fw_version, op->name);
1056
Don Frycc5f7e32012-05-16 22:54:27 +02001057 /* add this device to the list of devices using this op_mode */
1058 list_add_tail(&drv->list, &op->drv);
1059
1060 if (op->ops) {
Meenakshi Venkataraman9da987a2012-07-16 18:43:56 -07001061 drv->op_mode = _iwl_op_mode_start(drv, op);
John W. Linville7c9c46c2012-06-06 14:40:06 -04001062
Dan Carpenterdaf67ce2012-06-14 21:35:26 +03001063 if (!drv->op_mode) {
1064 mutex_unlock(&iwlwifi_opmode_table_mtx);
John W. Linville7c9c46c2012-06-06 14:40:06 -04001065 goto out_unbind;
Dan Carpenterdaf67ce2012-06-14 21:35:26 +03001066 }
Don Frycc5f7e32012-05-16 22:54:27 +02001067 } else {
Johannes Bergd4b10482012-06-12 19:50:43 +02001068 load_module = true;
Don Frycc5f7e32012-05-16 22:54:27 +02001069 }
Johannes Bergff1ffb82012-06-06 09:42:57 +02001070 mutex_unlock(&iwlwifi_opmode_table_mtx);
Johannes Berg15854ef92012-03-05 11:24:50 -08001071
Johannes Bergf69a23b2012-06-05 19:56:06 +02001072 /*
1073 * Complete the firmware request last so that
1074 * a driver unbind (stop) doesn't run while we
1075 * are doing the start() above.
1076 */
1077 complete(&drv->request_firmware_complete);
Johannes Bergd4b10482012-06-12 19:50:43 +02001078
1079 /*
1080 * Load the module last so we don't block anything
1081 * else from proceeding if the module fails to load
1082 * or hangs loading.
1083 */
Johannes Berg1618b2b2013-04-04 10:35:23 +02001084 if (load_module) {
1085 err = request_module("%s", op->name);
Johannes Berg8edf3fd2013-05-28 21:32:47 +02001086#ifdef CONFIG_IWLWIFI_OPMODE_MODULAR
Johannes Berg1618b2b2013-04-04 10:35:23 +02001087 if (err)
1088 IWL_ERR(drv,
1089 "failed to load module %s (error %d), is dynamic loading enabled?\n",
1090 op->name, err);
Johannes Berg8edf3fd2013-05-28 21:32:47 +02001091#endif
Johannes Berg1618b2b2013-04-04 10:35:23 +02001092 }
Johannes Berg15854ef92012-03-05 11:24:50 -08001093 return;
1094
1095 try_again:
1096 /* try next, if any */
1097 release_firmware(ucode_raw);
Johannes Berg965974a62012-03-06 13:30:38 -08001098 if (iwl_request_firmware(drv, false))
Johannes Berg15854ef92012-03-05 11:24:50 -08001099 goto out_unbind;
1100 return;
1101
Johannes Berg75813bd2012-05-16 22:49:49 +02001102 out_free_fw:
Johannes Berg965974a62012-03-06 13:30:38 -08001103 IWL_ERR(drv, "failed to allocate pci memory\n");
1104 iwl_dealloc_ucode(drv);
Johannes Berg15854ef92012-03-05 11:24:50 -08001105 release_firmware(ucode_raw);
1106 out_unbind:
Johannes Berg965974a62012-03-06 13:30:38 -08001107 complete(&drv->request_firmware_complete);
Emmanuel Grumbach93faaee2012-03-22 17:51:44 +02001108 device_release_driver(drv->trans->dev);
Johannes Berg15854ef92012-03-05 11:24:50 -08001109}
1110
Emmanuel Grumbach87ce05a2012-03-26 09:03:18 -07001111struct iwl_drv *iwl_drv_start(struct iwl_trans *trans,
Emmanuel Grumbach9130bab2012-03-26 08:51:09 -07001112 const struct iwl_cfg *cfg)
Emmanuel Grumbach5c58edc2012-02-07 14:18:40 +02001113{
Johannes Berg965974a62012-03-06 13:30:38 -08001114 struct iwl_drv *drv;
Emmanuel Grumbach5c58edc2012-02-07 14:18:40 +02001115 int ret;
1116
Johannes Berg965974a62012-03-06 13:30:38 -08001117 drv = kzalloc(sizeof(*drv), GFP_KERNEL);
Luciano Coelhoeafe25e2013-08-13 10:34:55 +03001118 if (!drv) {
1119 ret = -ENOMEM;
1120 goto err;
1121 }
Emmanuel Grumbachc15797e2012-04-19 10:29:58 +03001122
Emmanuel Grumbach9130bab2012-03-26 08:51:09 -07001123 drv->trans = trans;
Emmanuel Grumbach4b9844f2012-03-22 23:59:52 +02001124 drv->dev = trans->dev;
Emmanuel Grumbach68f360d2012-03-22 17:51:44 +02001125 drv->cfg = cfg;
Emmanuel Grumbach5c58edc2012-02-07 14:18:40 +02001126
Johannes Berg965974a62012-03-06 13:30:38 -08001127 init_completion(&drv->request_firmware_complete);
Johannes Bergff1ffb82012-06-06 09:42:57 +02001128 INIT_LIST_HEAD(&drv->list);
Emmanuel Grumbach5c58edc2012-02-07 14:18:40 +02001129
Meenakshi Venkataraman9da987a2012-07-16 18:43:56 -07001130#ifdef CONFIG_IWLWIFI_DEBUGFS
1131 /* Create the device debugfs entries. */
1132 drv->dbgfs_drv = debugfs_create_dir(dev_name(trans->dev),
1133 iwl_dbgfs_root);
1134
1135 if (!drv->dbgfs_drv) {
1136 IWL_ERR(drv, "failed to create debugfs directory\n");
Emmanuel Grumbach59f547a2012-11-28 16:42:09 +02001137 ret = -ENOMEM;
Meenakshi Venkataraman9da987a2012-07-16 18:43:56 -07001138 goto err_free_drv;
1139 }
1140
1141 /* Create transport layer debugfs dir */
1142 drv->trans->dbgfs_dir = debugfs_create_dir("trans", drv->dbgfs_drv);
1143
1144 if (!drv->trans->dbgfs_dir) {
1145 IWL_ERR(drv, "failed to create transport debugfs directory\n");
Emmanuel Grumbach59f547a2012-11-28 16:42:09 +02001146 ret = -ENOMEM;
Meenakshi Venkataraman9da987a2012-07-16 18:43:56 -07001147 goto err_free_dbgfs;
1148 }
1149#endif
1150
Johannes Berg965974a62012-03-06 13:30:38 -08001151 ret = iwl_request_firmware(drv, true);
Emmanuel Grumbach5c58edc2012-02-07 14:18:40 +02001152 if (ret) {
Emmanuel Grumbachc15797e2012-04-19 10:29:58 +03001153 IWL_ERR(trans, "Couldn't request the fw\n");
Meenakshi Venkataraman9da987a2012-07-16 18:43:56 -07001154 goto err_fw;
Emmanuel Grumbach5c58edc2012-02-07 14:18:40 +02001155 }
1156
Emmanuel Grumbach9130bab2012-03-26 08:51:09 -07001157 return drv;
Meenakshi Venkataraman9da987a2012-07-16 18:43:56 -07001158
1159err_fw:
1160#ifdef CONFIG_IWLWIFI_DEBUGFS
1161err_free_dbgfs:
1162 debugfs_remove_recursive(drv->dbgfs_drv);
1163err_free_drv:
1164#endif
1165 kfree(drv);
Luciano Coelhoeafe25e2013-08-13 10:34:55 +03001166err:
Emmanuel Grumbach59f547a2012-11-28 16:42:09 +02001167 return ERR_PTR(ret);
Emmanuel Grumbach5c58edc2012-02-07 14:18:40 +02001168}
1169
Emmanuel Grumbach9130bab2012-03-26 08:51:09 -07001170void iwl_drv_stop(struct iwl_drv *drv)
Emmanuel Grumbach07590f02012-02-07 14:27:31 +02001171{
Johannes Berg965974a62012-03-06 13:30:38 -08001172 wait_for_completion(&drv->request_firmware_complete);
Johannes Berg2e7eb112012-03-05 11:24:51 -08001173
Meenakshi Venkataraman9da987a2012-07-16 18:43:56 -07001174 _iwl_op_mode_stop(drv);
Emmanuel Grumbach07590f02012-02-07 14:27:31 +02001175
Johannes Berg965974a62012-03-06 13:30:38 -08001176 iwl_dealloc_ucode(drv);
Johannes Berg7db5b982012-03-05 11:24:48 -08001177
Johannes Bergff1ffb82012-06-06 09:42:57 +02001178 mutex_lock(&iwlwifi_opmode_table_mtx);
1179 /*
1180 * List is empty (this item wasn't added)
1181 * when firmware loading failed -- in that
1182 * case we can't remove it from any list.
1183 */
1184 if (!list_empty(&drv->list))
1185 list_del(&drv->list);
1186 mutex_unlock(&iwlwifi_opmode_table_mtx);
1187
Meenakshi Venkataraman9da987a2012-07-16 18:43:56 -07001188#ifdef CONFIG_IWLWIFI_DEBUGFS
1189 debugfs_remove_recursive(drv->dbgfs_drv);
1190#endif
1191
Johannes Berg965974a62012-03-06 13:30:38 -08001192 kfree(drv);
Emmanuel Grumbach07590f02012-02-07 14:27:31 +02001193}
Johannes Berg65de7e82012-04-17 07:36:30 -07001194
1195
1196/* shared module parameters */
1197struct iwl_mod_params iwlwifi_mod_params = {
Emmanuel Grumbach490953a2013-03-04 08:53:07 +02001198 .restart_fw = true,
Johannes Berg65de7e82012-04-17 07:36:30 -07001199 .bt_coex_active = true,
1200 .power_level = IWL_POWER_INDEX_1,
Emmanuel Grumbach020c8762012-06-24 15:51:59 +03001201 .wd_disable = true,
Johannes Berg65de7e82012-04-17 07:36:30 -07001202 /* the rest are 0 by default */
1203};
Johannes Berg48e29342013-03-01 00:13:33 +01001204IWL_EXPORT_SYMBOL(iwlwifi_mod_params);
Don Frycc5f7e32012-05-16 22:54:27 +02001205
1206int iwl_opmode_register(const char *name, const struct iwl_op_mode_ops *ops)
1207{
1208 int i;
1209 struct iwl_drv *drv;
Meenakshi Venkataraman9da987a2012-07-16 18:43:56 -07001210 struct iwlwifi_opmode_table *op;
Don Frycc5f7e32012-05-16 22:54:27 +02001211
Johannes Bergff1ffb82012-06-06 09:42:57 +02001212 mutex_lock(&iwlwifi_opmode_table_mtx);
Don Frycc5f7e32012-05-16 22:54:27 +02001213 for (i = 0; i < ARRAY_SIZE(iwlwifi_opmode_table); i++) {
Meenakshi Venkataraman9da987a2012-07-16 18:43:56 -07001214 op = &iwlwifi_opmode_table[i];
1215 if (strcmp(op->name, name))
Don Frycc5f7e32012-05-16 22:54:27 +02001216 continue;
Meenakshi Venkataraman9da987a2012-07-16 18:43:56 -07001217 op->ops = ops;
1218 /* TODO: need to handle exceptional case */
1219 list_for_each_entry(drv, &op->drv, list)
1220 drv->op_mode = _iwl_op_mode_start(drv, op);
1221
Johannes Bergff1ffb82012-06-06 09:42:57 +02001222 mutex_unlock(&iwlwifi_opmode_table_mtx);
Don Frycc5f7e32012-05-16 22:54:27 +02001223 return 0;
1224 }
Johannes Bergff1ffb82012-06-06 09:42:57 +02001225 mutex_unlock(&iwlwifi_opmode_table_mtx);
Don Frycc5f7e32012-05-16 22:54:27 +02001226 return -EIO;
1227}
Johannes Berg48e29342013-03-01 00:13:33 +01001228IWL_EXPORT_SYMBOL(iwl_opmode_register);
Don Frycc5f7e32012-05-16 22:54:27 +02001229
1230void iwl_opmode_deregister(const char *name)
1231{
1232 int i;
1233 struct iwl_drv *drv;
1234
Johannes Bergff1ffb82012-06-06 09:42:57 +02001235 mutex_lock(&iwlwifi_opmode_table_mtx);
Don Frycc5f7e32012-05-16 22:54:27 +02001236 for (i = 0; i < ARRAY_SIZE(iwlwifi_opmode_table); i++) {
1237 if (strcmp(iwlwifi_opmode_table[i].name, name))
1238 continue;
1239 iwlwifi_opmode_table[i].ops = NULL;
1240
1241 /* call the stop routine for all devices */
Meenakshi Venkataraman9da987a2012-07-16 18:43:56 -07001242 list_for_each_entry(drv, &iwlwifi_opmode_table[i].drv, list)
1243 _iwl_op_mode_stop(drv);
1244
Johannes Bergff1ffb82012-06-06 09:42:57 +02001245 mutex_unlock(&iwlwifi_opmode_table_mtx);
Don Frycc5f7e32012-05-16 22:54:27 +02001246 return;
1247 }
Johannes Bergff1ffb82012-06-06 09:42:57 +02001248 mutex_unlock(&iwlwifi_opmode_table_mtx);
Don Frycc5f7e32012-05-16 22:54:27 +02001249}
Johannes Berg48e29342013-03-01 00:13:33 +01001250IWL_EXPORT_SYMBOL(iwl_opmode_deregister);
Don Frycc5f7e32012-05-16 22:54:27 +02001251
1252static int __init iwl_drv_init(void)
1253{
1254 int i;
1255
Johannes Bergff1ffb82012-06-06 09:42:57 +02001256 mutex_init(&iwlwifi_opmode_table_mtx);
1257
Don Frycc5f7e32012-05-16 22:54:27 +02001258 for (i = 0; i < ARRAY_SIZE(iwlwifi_opmode_table); i++)
1259 INIT_LIST_HEAD(&iwlwifi_opmode_table[i].drv);
1260
1261 pr_info(DRV_DESCRIPTION ", " DRV_VERSION "\n");
1262 pr_info(DRV_COPYRIGHT "\n");
1263
Meenakshi Venkataraman9da987a2012-07-16 18:43:56 -07001264#ifdef CONFIG_IWLWIFI_DEBUGFS
1265 /* Create the root of iwlwifi debugfs subsystem. */
1266 iwl_dbgfs_root = debugfs_create_dir(DRV_NAME, NULL);
1267
1268 if (!iwl_dbgfs_root)
1269 return -EFAULT;
1270#endif
1271
Don Frycc5f7e32012-05-16 22:54:27 +02001272 return iwl_pci_register_driver();
1273}
1274module_init(iwl_drv_init);
1275
1276static void __exit iwl_drv_exit(void)
1277{
1278 iwl_pci_unregister_driver();
Meenakshi Venkataraman9da987a2012-07-16 18:43:56 -07001279
1280#ifdef CONFIG_IWLWIFI_DEBUGFS
1281 debugfs_remove_recursive(iwl_dbgfs_root);
1282#endif
Don Frycc5f7e32012-05-16 22:54:27 +02001283}
1284module_exit(iwl_drv_exit);
Johannes Berg65de7e82012-04-17 07:36:30 -07001285
1286#ifdef CONFIG_IWLWIFI_DEBUG
1287module_param_named(debug, iwlwifi_mod_params.debug_level, uint,
1288 S_IRUGO | S_IWUSR);
1289MODULE_PARM_DESC(debug, "debug output mask");
1290#endif
1291
1292module_param_named(swcrypto, iwlwifi_mod_params.sw_crypto, int, S_IRUGO);
1293MODULE_PARM_DESC(swcrypto, "using crypto in software (default 0 [hardware])");
1294module_param_named(11n_disable, iwlwifi_mod_params.disable_11n, uint, S_IRUGO);
1295MODULE_PARM_DESC(11n_disable,
1296 "disable 11n functionality, bitmap: 1: full, 2: agg TX, 4: agg RX");
1297module_param_named(amsdu_size_8K, iwlwifi_mod_params.amsdu_size_8K,
1298 int, S_IRUGO);
Emmanuel Grumbachaed7d9a2013-02-20 11:33:00 +02001299MODULE_PARM_DESC(amsdu_size_8K, "enable 8K amsdu size (default 0)");
Emmanuel Grumbach490953a2013-03-04 08:53:07 +02001300module_param_named(fw_restart, iwlwifi_mod_params.restart_fw, bool, S_IRUGO);
1301MODULE_PARM_DESC(fw_restart, "restart firmware in case of error (default true)");
Johannes Berg65de7e82012-04-17 07:36:30 -07001302
1303module_param_named(antenna_coupling, iwlwifi_mod_params.ant_coupling,
1304 int, S_IRUGO);
1305MODULE_PARM_DESC(antenna_coupling,
1306 "specify antenna coupling in dB (defualt: 0 dB)");
1307
Johannes Berg65de7e82012-04-17 07:36:30 -07001308module_param_named(wd_disable, iwlwifi_mod_params.wd_disable, int, S_IRUGO);
1309MODULE_PARM_DESC(wd_disable,
1310 "Disable stuck queue watchdog timer 0=system default, "
1311 "1=disable, 2=enable (default: 0)");
1312
Eran Harary12147552013-05-09 08:07:59 +03001313module_param_named(nvm_file, iwlwifi_mod_params.nvm_file, charp, S_IRUGO);
1314MODULE_PARM_DESC(nvm_file, "NVM file name");
1315
Johannes Berg65de7e82012-04-17 07:36:30 -07001316/*
1317 * set bt_coex_active to true, uCode will do kill/defer
1318 * every time the priority line is asserted (BT is sending signals on the
1319 * priority line in the PCIx).
1320 * set bt_coex_active to false, uCode will ignore the BT activity and
1321 * perform the normal operation
1322 *
1323 * User might experience transmit issue on some platform due to WiFi/BT
1324 * co-exist problem. The possible behaviors are:
1325 * Able to scan and finding all the available AP
1326 * Not able to associate with any AP
1327 * On those platforms, WiFi communication can be restored by set
1328 * "bt_coex_active" module parameter to "false"
1329 *
1330 * default: bt_coex_active = true (BT_COEX_ENABLE)
1331 */
1332module_param_named(bt_coex_active, iwlwifi_mod_params.bt_coex_active,
1333 bool, S_IRUGO);
1334MODULE_PARM_DESC(bt_coex_active, "enable wifi/bt co-exist (default: enable)");
1335
1336module_param_named(led_mode, iwlwifi_mod_params.led_mode, int, S_IRUGO);
1337MODULE_PARM_DESC(led_mode, "0=system default, "
1338 "1=On(RF On)/Off(RF Off), 2=blinking, 3=Off (default: 0)");
1339
1340module_param_named(power_save, iwlwifi_mod_params.power_save,
1341 bool, S_IRUGO);
1342MODULE_PARM_DESC(power_save,
1343 "enable WiFi power management (default: disable)");
1344
1345module_param_named(power_level, iwlwifi_mod_params.power_level,
1346 int, S_IRUGO);
1347MODULE_PARM_DESC(power_level,
1348 "default power save level (range from 1 - 5, default: 1)");