blob: ff570027e9dd9fa02f3e8360af6966b480c68069 [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 *
Johannes Berg128e63e2013-01-21 21:39:26 +01008 * Copyright(c) 2007 - 2013 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 *
Johannes Berg128e63e2013-01-21 21:39:26 +010033 * Copyright(c) 2005 - 2013 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 Berg15854ef2012-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 Berg965974a2012-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 Berg965974a2012-03-06 13:30:38 -0800112 * @fw: the iwl_fw structure
Johannes Berg965974a2012-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 Berg965974a2012-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 Berg965974a2012-03-06 13:30:38 -0800123 struct iwl_fw fw;
124
Johannes Berg965974a2012-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 Berg965974a2012-03-06 13:30:38 -0800129
130 int fw_index; /* firmware we're trying to load */
131 char firmware_name[25]; /* name of firmware file to load */
132
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 Berg965974a2012-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 Berg965974a2012-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 Berg965974a2012-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 Berg965974a2012-03-06 13:30:38 -0800168static void iwl_free_fw_desc(struct iwl_drv *drv, struct fw_desc *desc)
Johannes Berg15854ef2012-03-05 11:24:50 -0800169{
Johannes Berg83f84d72012-09-10 11:50:18 +0200170 vfree(desc->data);
171 desc->data = NULL;
Johannes Berg15854ef2012-03-05 11:24:50 -0800172 desc->len = 0;
173}
174
Johannes Berg965974a2012-03-06 13:30:38 -0800175static void iwl_free_fw_img(struct iwl_drv *drv, struct fw_img *img)
Johannes Berg15854ef2012-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 Berg15854ef2012-03-05 11:24:50 -0800180}
181
Johannes Berg965974a2012-03-06 13:30:38 -0800182static void iwl_dealloc_ucode(struct iwl_drv *drv)
Johannes Berg15854ef2012-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 Berg15854ef2012-03-05 11:24:50 -0800187}
188
Johannes Berg965974a2012-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 Berg15854ef2012-03-05 11:24:50 -0800191{
Johannes Berg83f84d72012-09-10 11:50:18 +0200192 void *data;
Johannes Berg15854ef2012-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 Berg15854ef2012-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 Berg15854ef2012-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 Berg15854ef2012-03-05 11:24:50 -0800213
214#define UCODE_EXPERIMENTAL_INDEX 100
215#define UCODE_EXPERIMENTAL_TAG "exp"
216
Johannes Berg965974a2012-03-06 13:30:38 -0800217static int iwl_request_firmware(struct iwl_drv *drv, bool first)
Johannes Berg15854ef2012-03-05 11:24:50 -0800218{
Emmanuel Grumbach68f360d2012-03-22 17:51:44 +0200219 const char *name_pre = drv->cfg->fw_name_pre;
Johannes Berg15854ef2012-03-05 11:24:50 -0800220 char tag[8];
221
222 if (first) {
223#ifdef CONFIG_IWLWIFI_DEBUG_EXPERIMENTAL_UCODE
Johannes Berg965974a2012-03-06 13:30:38 -0800224 drv->fw_index = UCODE_EXPERIMENTAL_INDEX;
Johannes Berg15854ef2012-03-05 11:24:50 -0800225 strcpy(tag, UCODE_EXPERIMENTAL_TAG);
Johannes Berg965974a2012-03-06 13:30:38 -0800226 } else if (drv->fw_index == UCODE_EXPERIMENTAL_INDEX) {
Johannes Berg15854ef2012-03-05 11:24:50 -0800227#endif
Emmanuel Grumbach68f360d2012-03-22 17:51:44 +0200228 drv->fw_index = drv->cfg->ucode_api_max;
Johannes Berg965974a2012-03-06 13:30:38 -0800229 sprintf(tag, "%d", drv->fw_index);
Johannes Berg15854ef2012-03-05 11:24:50 -0800230 } else {
Johannes Berg965974a2012-03-06 13:30:38 -0800231 drv->fw_index--;
232 sprintf(tag, "%d", drv->fw_index);
Johannes Berg15854ef2012-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 Berg965974a2012-03-06 13:30:38 -0800236 IWL_ERR(drv, "no suitable firmware found!\n");
Johannes Berg15854ef2012-03-05 11:24:50 -0800237 return -ENOENT;
238 }
239
Johannes Berg965974a2012-03-06 13:30:38 -0800240 sprintf(drv->firmware_name, "%s%s%s", name_pre, tag, ".ucode");
Johannes Berg15854ef2012-03-05 11:24:50 -0800241
Johannes Berg965974a2012-03-06 13:30:38 -0800242 IWL_DEBUG_INFO(drv, "attempting to load firmware %s'%s'\n",
243 (drv->fw_index == UCODE_EXPERIMENTAL_INDEX)
Johannes Berg15854ef2012-03-05 11:24:50 -0800244 ? "EXPERIMENTAL " : "",
Johannes Berg965974a2012-03-06 13:30:38 -0800245 drv->firmware_name);
Johannes Berg15854ef2012-03-05 11:24:50 -0800246
Johannes Berg965974a2012-03-06 13:30:38 -0800247 return request_firmware_nowait(THIS_MODULE, 1, drv->firmware_name,
Emmanuel Grumbach93faaee2012-03-22 17:51:44 +0200248 drv->trans->dev,
Emmanuel Grumbach1c8e11e2012-07-16 12:31:28 +0300249 GFP_KERNEL, drv, iwl_req_fw_callback);
Johannes Berg15854ef2012-03-05 11:24:50 -0800250}
251
David Spinadel0cedacc2012-03-10 13:00:12 -0800252struct fw_img_parsing {
David Spinadel6dfa8d02012-03-10 13:00:14 -0800253 struct fw_sec sec[IWL_UCODE_SECTION_MAX];
David Spinadel0cedacc2012-03-10 13:00:12 -0800254 int sec_counter;
255};
256
David Spinadeled8c8362012-03-10 13:00:13 -0800257/*
258 * struct fw_sec_parsing: to extract fw section and it's offset from tlv
259 */
260struct fw_sec_parsing {
261 __le32 offset;
262 const u8 data[];
263} __packed;
264
265/**
266 * struct iwl_tlv_calib_data - parse the default calib data from TLV
267 *
268 * @ucode_type: the uCode to which the following default calib relates.
269 * @calib: default calibrations.
270 */
271struct iwl_tlv_calib_data {
272 __le32 ucode_type;
Johannes Bergaa2b1772013-01-24 14:12:07 +0100273 struct iwl_tlv_calib_ctrl calib;
David Spinadeled8c8362012-03-10 13:00:13 -0800274} __packed;
275
David Spinadel0cedacc2012-03-10 13:00:12 -0800276struct iwl_firmware_pieces {
277 struct fw_img_parsing img[IWL_UCODE_TYPE_MAX];
Johannes Berg15854ef2012-03-05 11:24:50 -0800278
279 u32 init_evtlog_ptr, init_evtlog_size, init_errlog_ptr;
280 u32 inst_evtlog_ptr, inst_evtlog_size, inst_errlog_ptr;
281};
282
David Spinadel0cedacc2012-03-10 13:00:12 -0800283/*
284 * These functions are just to extract uCode section data from the pieces
285 * structure.
286 */
287static struct fw_sec *get_sec(struct iwl_firmware_pieces *pieces,
288 enum iwl_ucode_type type,
289 int sec)
290{
291 return &pieces->img[type].sec[sec];
292}
293
294static void set_sec_data(struct iwl_firmware_pieces *pieces,
295 enum iwl_ucode_type type,
296 int sec,
297 const void *data)
298{
299 pieces->img[type].sec[sec].data = data;
300}
301
302static void set_sec_size(struct iwl_firmware_pieces *pieces,
303 enum iwl_ucode_type type,
304 int sec,
305 size_t size)
306{
307 pieces->img[type].sec[sec].size = size;
308}
309
310static size_t get_sec_size(struct iwl_firmware_pieces *pieces,
311 enum iwl_ucode_type type,
312 int sec)
313{
314 return pieces->img[type].sec[sec].size;
315}
316
317static void set_sec_offset(struct iwl_firmware_pieces *pieces,
318 enum iwl_ucode_type type,
319 int sec,
320 u32 offset)
321{
322 pieces->img[type].sec[sec].offset = offset;
323}
324
David Spinadeled8c8362012-03-10 13:00:13 -0800325/*
326 * Gets uCode section from tlv.
327 */
328static int iwl_store_ucode_sec(struct iwl_firmware_pieces *pieces,
329 const void *data, enum iwl_ucode_type type,
330 int size)
331{
332 struct fw_img_parsing *img;
333 struct fw_sec *sec;
334 struct fw_sec_parsing *sec_parse;
335
336 if (WARN_ON(!pieces || !data || type >= IWL_UCODE_TYPE_MAX))
337 return -1;
338
339 sec_parse = (struct fw_sec_parsing *)data;
340
341 img = &pieces->img[type];
342 sec = &img->sec[img->sec_counter];
343
344 sec->offset = le32_to_cpu(sec_parse->offset);
345 sec->data = sec_parse->data;
David Spinadel1176f432012-03-13 14:32:48 +0200346 sec->size = size - sizeof(sec_parse->offset);
David Spinadeled8c8362012-03-10 13:00:13 -0800347
348 ++img->sec_counter;
349
350 return 0;
351}
352
353static int iwl_set_default_calib(struct iwl_drv *drv, const u8 *data)
354{
355 struct iwl_tlv_calib_data *def_calib =
356 (struct iwl_tlv_calib_data *)data;
357 u32 ucode_type = le32_to_cpu(def_calib->ucode_type);
358 if (ucode_type >= IWL_UCODE_TYPE_MAX) {
359 IWL_ERR(drv, "Wrong ucode_type %u for default calibration.\n",
360 ucode_type);
361 return -EINVAL;
362 }
Johannes Bergaa2b1772013-01-24 14:12:07 +0100363 drv->fw.default_calib[ucode_type].flow_trigger =
364 def_calib->calib.flow_trigger;
365 drv->fw.default_calib[ucode_type].event_trigger =
366 def_calib->calib.event_trigger;
367
David Spinadeled8c8362012-03-10 13:00:13 -0800368 return 0;
369}
370
Johannes Berg965974a2012-03-06 13:30:38 -0800371static int iwl_parse_v1_v2_firmware(struct iwl_drv *drv,
David Spinadel0cedacc2012-03-10 13:00:12 -0800372 const struct firmware *ucode_raw,
373 struct iwl_firmware_pieces *pieces)
Johannes Berg15854ef2012-03-05 11:24:50 -0800374{
375 struct iwl_ucode_header *ucode = (void *)ucode_raw->data;
376 u32 api_ver, hdr_size, build;
377 char buildstr[25];
378 const u8 *src;
379
Johannes Berg965974a2012-03-06 13:30:38 -0800380 drv->fw.ucode_ver = le32_to_cpu(ucode->ver);
381 api_ver = IWL_UCODE_API(drv->fw.ucode_ver);
Johannes Berg15854ef2012-03-05 11:24:50 -0800382
383 switch (api_ver) {
384 default:
385 hdr_size = 28;
386 if (ucode_raw->size < hdr_size) {
Johannes Berg965974a2012-03-06 13:30:38 -0800387 IWL_ERR(drv, "File size too small!\n");
Johannes Berg15854ef2012-03-05 11:24:50 -0800388 return -EINVAL;
389 }
390 build = le32_to_cpu(ucode->u.v2.build);
David Spinadel0cedacc2012-03-10 13:00:12 -0800391 set_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_INST,
392 le32_to_cpu(ucode->u.v2.inst_size));
393 set_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_DATA,
394 le32_to_cpu(ucode->u.v2.data_size));
395 set_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST,
396 le32_to_cpu(ucode->u.v2.init_size));
397 set_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA,
398 le32_to_cpu(ucode->u.v2.init_data_size));
Johannes Berg15854ef2012-03-05 11:24:50 -0800399 src = ucode->u.v2.data;
400 break;
401 case 0:
402 case 1:
403 case 2:
404 hdr_size = 24;
405 if (ucode_raw->size < hdr_size) {
Johannes Berg965974a2012-03-06 13:30:38 -0800406 IWL_ERR(drv, "File size too small!\n");
Johannes Berg15854ef2012-03-05 11:24:50 -0800407 return -EINVAL;
408 }
409 build = 0;
David Spinadel0cedacc2012-03-10 13:00:12 -0800410 set_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_INST,
411 le32_to_cpu(ucode->u.v1.inst_size));
412 set_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_DATA,
413 le32_to_cpu(ucode->u.v1.data_size));
414 set_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST,
415 le32_to_cpu(ucode->u.v1.init_size));
416 set_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA,
417 le32_to_cpu(ucode->u.v1.init_data_size));
Johannes Berg15854ef2012-03-05 11:24:50 -0800418 src = ucode->u.v1.data;
419 break;
420 }
421
422 if (build)
423 sprintf(buildstr, " build %u%s", build,
Johannes Berg965974a2012-03-06 13:30:38 -0800424 (drv->fw_index == UCODE_EXPERIMENTAL_INDEX)
Johannes Berg15854ef2012-03-05 11:24:50 -0800425 ? " (EXP)" : "");
426 else
427 buildstr[0] = '\0';
428
Johannes Berg965974a2012-03-06 13:30:38 -0800429 snprintf(drv->fw.fw_version,
430 sizeof(drv->fw.fw_version),
Johannes Berg15854ef2012-03-05 11:24:50 -0800431 "%u.%u.%u.%u%s",
Johannes Berg965974a2012-03-06 13:30:38 -0800432 IWL_UCODE_MAJOR(drv->fw.ucode_ver),
433 IWL_UCODE_MINOR(drv->fw.ucode_ver),
434 IWL_UCODE_API(drv->fw.ucode_ver),
435 IWL_UCODE_SERIAL(drv->fw.ucode_ver),
Johannes Berg15854ef2012-03-05 11:24:50 -0800436 buildstr);
437
438 /* Verify size of file vs. image size info in file's header */
David Spinadel0cedacc2012-03-10 13:00:12 -0800439
440 if (ucode_raw->size != hdr_size +
441 get_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_INST) +
442 get_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_DATA) +
443 get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST) +
444 get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA)) {
Johannes Berg15854ef2012-03-05 11:24:50 -0800445
Johannes Berg965974a2012-03-06 13:30:38 -0800446 IWL_ERR(drv,
Johannes Berg15854ef2012-03-05 11:24:50 -0800447 "uCode file size %d does not match expected size\n",
448 (int)ucode_raw->size);
449 return -EINVAL;
450 }
451
Johannes Berg15854ef2012-03-05 11:24:50 -0800452
David Spinadel0cedacc2012-03-10 13:00:12 -0800453 set_sec_data(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_INST, src);
454 src += get_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_INST);
455 set_sec_offset(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_INST,
456 IWLAGN_RTC_INST_LOWER_BOUND);
457 set_sec_data(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_DATA, src);
458 src += get_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_DATA);
459 set_sec_offset(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_DATA,
460 IWLAGN_RTC_DATA_LOWER_BOUND);
461 set_sec_data(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST, src);
462 src += get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST);
463 set_sec_offset(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST,
464 IWLAGN_RTC_INST_LOWER_BOUND);
465 set_sec_data(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA, src);
466 src += get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA);
467 set_sec_offset(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA,
468 IWLAGN_RTC_DATA_LOWER_BOUND);
Johannes Berg15854ef2012-03-05 11:24:50 -0800469 return 0;
470}
471
Johannes Berg965974a2012-03-06 13:30:38 -0800472static int iwl_parse_tlv_firmware(struct iwl_drv *drv,
Johannes Berg15854ef2012-03-05 11:24:50 -0800473 const struct firmware *ucode_raw,
David Spinadel0cedacc2012-03-10 13:00:12 -0800474 struct iwl_firmware_pieces *pieces,
Johannes Berg15854ef2012-03-05 11:24:50 -0800475 struct iwl_ucode_capabilities *capa)
476{
477 struct iwl_tlv_ucode_header *ucode = (void *)ucode_raw->data;
478 struct iwl_ucode_tlv *tlv;
479 size_t len = ucode_raw->size;
480 const u8 *data;
Johannes Berg15854ef2012-03-05 11:24:50 -0800481 u32 tlv_len;
482 enum iwl_ucode_tlv_type tlv_type;
483 const u8 *tlv_data;
484 char buildstr[25];
485 u32 build;
Eran Hararye2d6f4e2013-10-02 13:53:40 +0300486 int num_of_cpus;
Johannes Berg15854ef2012-03-05 11:24:50 -0800487
488 if (len < sizeof(*ucode)) {
Johannes Berg965974a2012-03-06 13:30:38 -0800489 IWL_ERR(drv, "uCode has invalid length: %zd\n", len);
Johannes Berg15854ef2012-03-05 11:24:50 -0800490 return -EINVAL;
491 }
492
493 if (ucode->magic != cpu_to_le32(IWL_TLV_UCODE_MAGIC)) {
Johannes Berg965974a2012-03-06 13:30:38 -0800494 IWL_ERR(drv, "invalid uCode magic: 0X%x\n",
Johannes Berg15854ef2012-03-05 11:24:50 -0800495 le32_to_cpu(ucode->magic));
496 return -EINVAL;
497 }
498
Johannes Berg965974a2012-03-06 13:30:38 -0800499 drv->fw.ucode_ver = le32_to_cpu(ucode->ver);
Johannes Berg15854ef2012-03-05 11:24:50 -0800500 build = le32_to_cpu(ucode->build);
501
502 if (build)
503 sprintf(buildstr, " build %u%s", build,
Johannes Berg965974a2012-03-06 13:30:38 -0800504 (drv->fw_index == UCODE_EXPERIMENTAL_INDEX)
Johannes Berg15854ef2012-03-05 11:24:50 -0800505 ? " (EXP)" : "");
506 else
507 buildstr[0] = '\0';
508
Johannes Berg965974a2012-03-06 13:30:38 -0800509 snprintf(drv->fw.fw_version,
510 sizeof(drv->fw.fw_version),
Johannes Berg15854ef2012-03-05 11:24:50 -0800511 "%u.%u.%u.%u%s",
Johannes Berg965974a2012-03-06 13:30:38 -0800512 IWL_UCODE_MAJOR(drv->fw.ucode_ver),
513 IWL_UCODE_MINOR(drv->fw.ucode_ver),
514 IWL_UCODE_API(drv->fw.ucode_ver),
515 IWL_UCODE_SERIAL(drv->fw.ucode_ver),
Johannes Berg15854ef2012-03-05 11:24:50 -0800516 buildstr);
517
518 data = ucode->data;
519
520 len -= sizeof(*ucode);
521
522 while (len >= sizeof(*tlv)) {
Johannes Berg15854ef2012-03-05 11:24:50 -0800523 len -= sizeof(*tlv);
524 tlv = (void *)data;
525
526 tlv_len = le32_to_cpu(tlv->length);
Johannes Berg0479c192012-03-09 09:16:35 +0100527 tlv_type = le32_to_cpu(tlv->type);
Johannes Berg15854ef2012-03-05 11:24:50 -0800528 tlv_data = tlv->data;
529
530 if (len < tlv_len) {
Johannes Berg965974a2012-03-06 13:30:38 -0800531 IWL_ERR(drv, "invalid TLV len: %zd/%u\n",
Johannes Berg15854ef2012-03-05 11:24:50 -0800532 len, tlv_len);
533 return -EINVAL;
534 }
535 len -= ALIGN(tlv_len, 4);
536 data += sizeof(*tlv) + ALIGN(tlv_len, 4);
537
Johannes Berg15854ef2012-03-05 11:24:50 -0800538 switch (tlv_type) {
539 case IWL_UCODE_TLV_INST:
David Spinadel0cedacc2012-03-10 13:00:12 -0800540 set_sec_data(pieces, IWL_UCODE_REGULAR,
541 IWL_UCODE_SECTION_INST, tlv_data);
542 set_sec_size(pieces, IWL_UCODE_REGULAR,
543 IWL_UCODE_SECTION_INST, tlv_len);
544 set_sec_offset(pieces, IWL_UCODE_REGULAR,
545 IWL_UCODE_SECTION_INST,
546 IWLAGN_RTC_INST_LOWER_BOUND);
Johannes Berg15854ef2012-03-05 11:24:50 -0800547 break;
548 case IWL_UCODE_TLV_DATA:
David Spinadel0cedacc2012-03-10 13:00:12 -0800549 set_sec_data(pieces, IWL_UCODE_REGULAR,
550 IWL_UCODE_SECTION_DATA, tlv_data);
551 set_sec_size(pieces, IWL_UCODE_REGULAR,
552 IWL_UCODE_SECTION_DATA, tlv_len);
553 set_sec_offset(pieces, IWL_UCODE_REGULAR,
554 IWL_UCODE_SECTION_DATA,
555 IWLAGN_RTC_DATA_LOWER_BOUND);
Johannes Berg15854ef2012-03-05 11:24:50 -0800556 break;
557 case IWL_UCODE_TLV_INIT:
David Spinadel0cedacc2012-03-10 13:00:12 -0800558 set_sec_data(pieces, IWL_UCODE_INIT,
559 IWL_UCODE_SECTION_INST, tlv_data);
560 set_sec_size(pieces, IWL_UCODE_INIT,
561 IWL_UCODE_SECTION_INST, tlv_len);
562 set_sec_offset(pieces, IWL_UCODE_INIT,
563 IWL_UCODE_SECTION_INST,
564 IWLAGN_RTC_INST_LOWER_BOUND);
Johannes Berg15854ef2012-03-05 11:24:50 -0800565 break;
566 case IWL_UCODE_TLV_INIT_DATA:
David Spinadel0cedacc2012-03-10 13:00:12 -0800567 set_sec_data(pieces, IWL_UCODE_INIT,
568 IWL_UCODE_SECTION_DATA, tlv_data);
569 set_sec_size(pieces, IWL_UCODE_INIT,
570 IWL_UCODE_SECTION_DATA, tlv_len);
571 set_sec_offset(pieces, IWL_UCODE_INIT,
572 IWL_UCODE_SECTION_DATA,
573 IWLAGN_RTC_DATA_LOWER_BOUND);
Johannes Berg15854ef2012-03-05 11:24:50 -0800574 break;
575 case IWL_UCODE_TLV_BOOT:
Johannes Berg965974a2012-03-06 13:30:38 -0800576 IWL_ERR(drv, "Found unexpected BOOT ucode\n");
Johannes Berg15854ef2012-03-05 11:24:50 -0800577 break;
578 case IWL_UCODE_TLV_PROBE_MAX_LEN:
579 if (tlv_len != sizeof(u32))
580 goto invalid_tlv_len;
581 capa->max_probe_length =
582 le32_to_cpup((__le32 *)tlv_data);
583 break;
584 case IWL_UCODE_TLV_PAN:
585 if (tlv_len)
586 goto invalid_tlv_len;
587 capa->flags |= IWL_UCODE_TLV_FLAGS_PAN;
588 break;
589 case IWL_UCODE_TLV_FLAGS:
590 /* must be at least one u32 */
591 if (tlv_len < sizeof(u32))
592 goto invalid_tlv_len;
593 /* and a proper number of u32s */
594 if (tlv_len % sizeof(u32))
595 goto invalid_tlv_len;
596 /*
597 * This driver only reads the first u32 as
598 * right now no more features are defined,
599 * if that changes then either the driver
600 * will not work with the new firmware, or
601 * it'll not take advantage of new features.
602 */
603 capa->flags = le32_to_cpup((__le32 *)tlv_data);
604 break;
605 case IWL_UCODE_TLV_INIT_EVTLOG_PTR:
606 if (tlv_len != sizeof(u32))
607 goto invalid_tlv_len;
608 pieces->init_evtlog_ptr =
609 le32_to_cpup((__le32 *)tlv_data);
610 break;
611 case IWL_UCODE_TLV_INIT_EVTLOG_SIZE:
612 if (tlv_len != sizeof(u32))
613 goto invalid_tlv_len;
614 pieces->init_evtlog_size =
615 le32_to_cpup((__le32 *)tlv_data);
616 break;
617 case IWL_UCODE_TLV_INIT_ERRLOG_PTR:
618 if (tlv_len != sizeof(u32))
619 goto invalid_tlv_len;
620 pieces->init_errlog_ptr =
621 le32_to_cpup((__le32 *)tlv_data);
622 break;
623 case IWL_UCODE_TLV_RUNT_EVTLOG_PTR:
624 if (tlv_len != sizeof(u32))
625 goto invalid_tlv_len;
626 pieces->inst_evtlog_ptr =
627 le32_to_cpup((__le32 *)tlv_data);
628 break;
629 case IWL_UCODE_TLV_RUNT_EVTLOG_SIZE:
630 if (tlv_len != sizeof(u32))
631 goto invalid_tlv_len;
632 pieces->inst_evtlog_size =
633 le32_to_cpup((__le32 *)tlv_data);
634 break;
635 case IWL_UCODE_TLV_RUNT_ERRLOG_PTR:
636 if (tlv_len != sizeof(u32))
637 goto invalid_tlv_len;
638 pieces->inst_errlog_ptr =
639 le32_to_cpup((__le32 *)tlv_data);
640 break;
641 case IWL_UCODE_TLV_ENHANCE_SENS_TBL:
642 if (tlv_len)
643 goto invalid_tlv_len;
Johannes Berg965974a2012-03-06 13:30:38 -0800644 drv->fw.enhance_sensitivity_table = true;
Johannes Berg15854ef2012-03-05 11:24:50 -0800645 break;
646 case IWL_UCODE_TLV_WOWLAN_INST:
David Spinadel0cedacc2012-03-10 13:00:12 -0800647 set_sec_data(pieces, IWL_UCODE_WOWLAN,
648 IWL_UCODE_SECTION_INST, tlv_data);
649 set_sec_size(pieces, IWL_UCODE_WOWLAN,
650 IWL_UCODE_SECTION_INST, tlv_len);
651 set_sec_offset(pieces, IWL_UCODE_WOWLAN,
652 IWL_UCODE_SECTION_INST,
653 IWLAGN_RTC_INST_LOWER_BOUND);
Johannes Berg15854ef2012-03-05 11:24:50 -0800654 break;
655 case IWL_UCODE_TLV_WOWLAN_DATA:
David Spinadel0cedacc2012-03-10 13:00:12 -0800656 set_sec_data(pieces, IWL_UCODE_WOWLAN,
657 IWL_UCODE_SECTION_DATA, tlv_data);
658 set_sec_size(pieces, IWL_UCODE_WOWLAN,
659 IWL_UCODE_SECTION_DATA, tlv_len);
660 set_sec_offset(pieces, IWL_UCODE_WOWLAN,
661 IWL_UCODE_SECTION_DATA,
662 IWLAGN_RTC_DATA_LOWER_BOUND);
Johannes Berg15854ef2012-03-05 11:24:50 -0800663 break;
664 case IWL_UCODE_TLV_PHY_CALIBRATION_SIZE:
665 if (tlv_len != sizeof(u32))
666 goto invalid_tlv_len;
667 capa->standard_phy_calibration_size =
668 le32_to_cpup((__le32 *)tlv_data);
669 break;
David Spinadeled8c8362012-03-10 13:00:13 -0800670 case IWL_UCODE_TLV_SEC_RT:
671 iwl_store_ucode_sec(pieces, tlv_data, IWL_UCODE_REGULAR,
672 tlv_len);
David Spinadel4db2c9a2012-03-10 13:00:15 -0800673 drv->fw.mvm_fw = true;
David Spinadeled8c8362012-03-10 13:00:13 -0800674 break;
675 case IWL_UCODE_TLV_SEC_INIT:
676 iwl_store_ucode_sec(pieces, tlv_data, IWL_UCODE_INIT,
677 tlv_len);
David Spinadel4db2c9a2012-03-10 13:00:15 -0800678 drv->fw.mvm_fw = true;
David Spinadeled8c8362012-03-10 13:00:13 -0800679 break;
680 case IWL_UCODE_TLV_SEC_WOWLAN:
681 iwl_store_ucode_sec(pieces, tlv_data, IWL_UCODE_WOWLAN,
682 tlv_len);
David Spinadel4db2c9a2012-03-10 13:00:15 -0800683 drv->fw.mvm_fw = true;
David Spinadeled8c8362012-03-10 13:00:13 -0800684 break;
685 case IWL_UCODE_TLV_DEF_CALIB:
686 if (tlv_len != sizeof(struct iwl_tlv_calib_data))
687 goto invalid_tlv_len;
688 if (iwl_set_default_calib(drv, tlv_data))
689 goto tlv_error;
690 break;
691 case IWL_UCODE_TLV_PHY_SKU:
692 if (tlv_len != sizeof(u32))
693 goto invalid_tlv_len;
694 drv->fw.phy_config = le32_to_cpup((__le32 *)tlv_data);
695 break;
Eran Hararye2d6f4e2013-10-02 13:53:40 +0300696 case IWL_UCODE_TLV_SECURE_SEC_RT:
697 iwl_store_ucode_sec(pieces, tlv_data, IWL_UCODE_REGULAR,
698 tlv_len);
699 drv->fw.mvm_fw = true;
700 drv->fw.img[IWL_UCODE_REGULAR].is_secure = true;
701 break;
702 case IWL_UCODE_TLV_SECURE_SEC_INIT:
703 iwl_store_ucode_sec(pieces, tlv_data, IWL_UCODE_INIT,
704 tlv_len);
705 drv->fw.mvm_fw = true;
706 drv->fw.img[IWL_UCODE_INIT].is_secure = true;
707 break;
708 case IWL_UCODE_TLV_SECURE_SEC_WOWLAN:
709 iwl_store_ucode_sec(pieces, tlv_data, IWL_UCODE_WOWLAN,
710 tlv_len);
711 drv->fw.mvm_fw = true;
712 drv->fw.img[IWL_UCODE_WOWLAN].is_secure = true;
713 break;
714 case IWL_UCODE_TLV_NUM_OF_CPU:
715 if (tlv_len != sizeof(u32))
716 goto invalid_tlv_len;
717 num_of_cpus =
718 le32_to_cpup((__le32 *)tlv_data);
719
720 if (num_of_cpus == 2) {
721 drv->fw.img[IWL_UCODE_REGULAR].is_dual_cpus =
722 true;
723 drv->fw.img[IWL_UCODE_INIT].is_dual_cpus =
724 true;
725 drv->fw.img[IWL_UCODE_WOWLAN].is_dual_cpus =
726 true;
727 } else if ((num_of_cpus > 2) || (num_of_cpus < 1)) {
728 IWL_ERR(drv, "Driver support upto 2 CPUs\n");
729 return -EINVAL;
730 }
731 break;
Johannes Berg15854ef2012-03-05 11:24:50 -0800732 default:
Johannes Berg965974a2012-03-06 13:30:38 -0800733 IWL_DEBUG_INFO(drv, "unknown TLV: %d\n", tlv_type);
Johannes Berg15854ef2012-03-05 11:24:50 -0800734 break;
735 }
736 }
737
738 if (len) {
Johannes Berg965974a2012-03-06 13:30:38 -0800739 IWL_ERR(drv, "invalid TLV after parsing: %zd\n", len);
740 iwl_print_hex_dump(drv, IWL_DL_FW, (u8 *)data, len);
Johannes Berg15854ef2012-03-05 11:24:50 -0800741 return -EINVAL;
742 }
743
744 return 0;
745
746 invalid_tlv_len:
Johannes Berg965974a2012-03-06 13:30:38 -0800747 IWL_ERR(drv, "TLV %d has invalid size: %u\n", tlv_type, tlv_len);
David Spinadeled8c8362012-03-10 13:00:13 -0800748 tlv_error:
Johannes Berg965974a2012-03-06 13:30:38 -0800749 iwl_print_hex_dump(drv, IWL_DL_FW, tlv_data, tlv_len);
Johannes Berg15854ef2012-03-05 11:24:50 -0800750
751 return -EINVAL;
752}
753
Johannes Berg75813bd2012-05-16 22:49:49 +0200754static int iwl_alloc_ucode(struct iwl_drv *drv,
755 struct iwl_firmware_pieces *pieces,
756 enum iwl_ucode_type type)
David Spinadel6dfa8d02012-03-10 13:00:14 -0800757{
758 int i;
759 for (i = 0;
760 i < IWL_UCODE_SECTION_MAX && get_sec_size(pieces, type, i);
761 i++)
762 if (iwl_alloc_fw_desc(drv, &(drv->fw.img[type].sec[i]),
Johannes Berg75813bd2012-05-16 22:49:49 +0200763 get_sec(pieces, type, i)))
764 return -ENOMEM;
David Spinadel6dfa8d02012-03-10 13:00:14 -0800765 return 0;
766}
767
768static int validate_sec_sizes(struct iwl_drv *drv,
769 struct iwl_firmware_pieces *pieces,
770 const struct iwl_cfg *cfg)
771{
772 IWL_DEBUG_INFO(drv, "f/w package hdr runtime inst size = %Zd\n",
773 get_sec_size(pieces, IWL_UCODE_REGULAR,
774 IWL_UCODE_SECTION_INST));
775 IWL_DEBUG_INFO(drv, "f/w package hdr runtime data size = %Zd\n",
776 get_sec_size(pieces, IWL_UCODE_REGULAR,
777 IWL_UCODE_SECTION_DATA));
778 IWL_DEBUG_INFO(drv, "f/w package hdr init inst size = %Zd\n",
779 get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST));
780 IWL_DEBUG_INFO(drv, "f/w package hdr init data size = %Zd\n",
781 get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA));
782
783 /* Verify that uCode images will fit in card's SRAM. */
784 if (get_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_INST) >
785 cfg->max_inst_size) {
786 IWL_ERR(drv, "uCode instr len %Zd too large to fit in\n",
787 get_sec_size(pieces, IWL_UCODE_REGULAR,
788 IWL_UCODE_SECTION_INST));
789 return -1;
790 }
791
792 if (get_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_DATA) >
793 cfg->max_data_size) {
794 IWL_ERR(drv, "uCode data len %Zd too large to fit in\n",
795 get_sec_size(pieces, IWL_UCODE_REGULAR,
796 IWL_UCODE_SECTION_DATA));
797 return -1;
798 }
799
800 if (get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST) >
801 cfg->max_inst_size) {
802 IWL_ERR(drv, "uCode init instr len %Zd too large to fit in\n",
803 get_sec_size(pieces, IWL_UCODE_INIT,
804 IWL_UCODE_SECTION_INST));
805 return -1;
806 }
807
808 if (get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA) >
809 cfg->max_data_size) {
810 IWL_ERR(drv, "uCode init data len %Zd too large to fit in\n",
811 get_sec_size(pieces, IWL_UCODE_REGULAR,
812 IWL_UCODE_SECTION_DATA));
813 return -1;
814 }
815 return 0;
816}
817
Meenakshi Venkataraman9da987a2012-07-16 18:43:56 -0700818static struct iwl_op_mode *
819_iwl_op_mode_start(struct iwl_drv *drv, struct iwlwifi_opmode_table *op)
820{
821 const struct iwl_op_mode_ops *ops = op->ops;
822 struct dentry *dbgfs_dir = NULL;
823 struct iwl_op_mode *op_mode = NULL;
824
825#ifdef CONFIG_IWLWIFI_DEBUGFS
826 drv->dbgfs_op_mode = debugfs_create_dir(op->name,
827 drv->dbgfs_drv);
828 if (!drv->dbgfs_op_mode) {
829 IWL_ERR(drv,
830 "failed to create opmode debugfs directory\n");
831 return op_mode;
832 }
833 dbgfs_dir = drv->dbgfs_op_mode;
834#endif
835
836 op_mode = ops->start(drv->trans, drv->cfg, &drv->fw, dbgfs_dir);
837
838#ifdef CONFIG_IWLWIFI_DEBUGFS
839 if (!op_mode) {
840 debugfs_remove_recursive(drv->dbgfs_op_mode);
841 drv->dbgfs_op_mode = NULL;
842 }
843#endif
844
845 return op_mode;
846}
847
848static void _iwl_op_mode_stop(struct iwl_drv *drv)
849{
850 /* op_mode can be NULL if its start failed */
851 if (drv->op_mode) {
852 iwl_op_mode_stop(drv->op_mode);
853 drv->op_mode = NULL;
854
855#ifdef CONFIG_IWLWIFI_DEBUGFS
856 debugfs_remove_recursive(drv->dbgfs_op_mode);
857 drv->dbgfs_op_mode = NULL;
858#endif
859 }
860}
861
Johannes Berg15854ef2012-03-05 11:24:50 -0800862/**
Emmanuel Grumbach1c8e11e2012-07-16 12:31:28 +0300863 * iwl_req_fw_callback - callback when firmware was loaded
Johannes Berg15854ef2012-03-05 11:24:50 -0800864 *
865 * If loaded successfully, copies the firmware into buffers
866 * for the card to fetch (via DMA).
867 */
Emmanuel Grumbach1c8e11e2012-07-16 12:31:28 +0300868static void iwl_req_fw_callback(const struct firmware *ucode_raw, void *context)
Johannes Berg15854ef2012-03-05 11:24:50 -0800869{
Johannes Berg965974a2012-03-06 13:30:38 -0800870 struct iwl_drv *drv = context;
Johannes Berg965974a2012-03-06 13:30:38 -0800871 struct iwl_fw *fw = &drv->fw;
Johannes Berg15854ef2012-03-05 11:24:50 -0800872 struct iwl_ucode_header *ucode;
Don Frycc5f7e32012-05-16 22:54:27 +0200873 struct iwlwifi_opmode_table *op;
Johannes Berg15854ef2012-03-05 11:24:50 -0800874 int err;
David Spinadel0cedacc2012-03-10 13:00:12 -0800875 struct iwl_firmware_pieces pieces;
Emmanuel Grumbach68f360d2012-03-22 17:51:44 +0200876 const unsigned int api_max = drv->cfg->ucode_api_max;
877 unsigned int api_ok = drv->cfg->ucode_api_ok;
878 const unsigned int api_min = drv->cfg->ucode_api_min;
Johannes Berg15854ef2012-03-05 11:24:50 -0800879 u32 api_ver;
David Spinadel6dfa8d02012-03-10 13:00:14 -0800880 int i;
Johannes Bergd4b10482012-06-12 19:50:43 +0200881 bool load_module = false;
Johannes Berg15854ef2012-03-05 11:24:50 -0800882
Luciano Coelho66140ad2013-08-12 19:30:21 +0300883 fw->ucode_capa.max_probe_length = IWL_DEFAULT_MAX_PROBE_LENGTH;
Johannes Berg15854ef2012-03-05 11:24:50 -0800884 fw->ucode_capa.standard_phy_calibration_size =
885 IWL_DEFAULT_STANDARD_PHY_CALIBRATE_TBL_SIZE;
886
887 if (!api_ok)
888 api_ok = api_max;
889
890 memset(&pieces, 0, sizeof(pieces));
891
892 if (!ucode_raw) {
Johannes Berg965974a2012-03-06 13:30:38 -0800893 if (drv->fw_index <= api_ok)
894 IWL_ERR(drv,
Johannes Berg15854ef2012-03-05 11:24:50 -0800895 "request for firmware file '%s' failed.\n",
Johannes Berg965974a2012-03-06 13:30:38 -0800896 drv->firmware_name);
Johannes Berg15854ef2012-03-05 11:24:50 -0800897 goto try_again;
898 }
899
Johannes Berg965974a2012-03-06 13:30:38 -0800900 IWL_DEBUG_INFO(drv, "Loaded firmware file '%s' (%zd bytes).\n",
901 drv->firmware_name, ucode_raw->size);
Johannes Berg15854ef2012-03-05 11:24:50 -0800902
903 /* Make sure that we got at least the API version number */
904 if (ucode_raw->size < 4) {
Johannes Berg965974a2012-03-06 13:30:38 -0800905 IWL_ERR(drv, "File size way too small!\n");
Johannes Berg15854ef2012-03-05 11:24:50 -0800906 goto try_again;
907 }
908
909 /* Data from ucode file: header followed by uCode images */
910 ucode = (struct iwl_ucode_header *)ucode_raw->data;
911
912 if (ucode->ver)
Johannes Berg965974a2012-03-06 13:30:38 -0800913 err = iwl_parse_v1_v2_firmware(drv, ucode_raw, &pieces);
Johannes Berg15854ef2012-03-05 11:24:50 -0800914 else
Johannes Berg965974a2012-03-06 13:30:38 -0800915 err = iwl_parse_tlv_firmware(drv, ucode_raw, &pieces,
Johannes Berg15854ef2012-03-05 11:24:50 -0800916 &fw->ucode_capa);
917
918 if (err)
919 goto try_again;
920
Johannes Berg965974a2012-03-06 13:30:38 -0800921 api_ver = IWL_UCODE_API(drv->fw.ucode_ver);
Johannes Berg15854ef2012-03-05 11:24:50 -0800922
923 /*
924 * api_ver should match the api version forming part of the
925 * firmware filename ... but we don't check for that and only rely
926 * on the API version read from firmware header from here on forward
927 */
928 /* no api version check required for experimental uCode */
Johannes Berg965974a2012-03-06 13:30:38 -0800929 if (drv->fw_index != UCODE_EXPERIMENTAL_INDEX) {
Johannes Berg15854ef2012-03-05 11:24:50 -0800930 if (api_ver < api_min || api_ver > api_max) {
Johannes Berg965974a2012-03-06 13:30:38 -0800931 IWL_ERR(drv,
Johannes Berg15854ef2012-03-05 11:24:50 -0800932 "Driver unable to support your firmware API. "
933 "Driver supports v%u, firmware is v%u.\n",
934 api_max, api_ver);
935 goto try_again;
936 }
937
938 if (api_ver < api_ok) {
939 if (api_ok != api_max)
Johannes Berg965974a2012-03-06 13:30:38 -0800940 IWL_ERR(drv, "Firmware has old API version, "
Johannes Berg15854ef2012-03-05 11:24:50 -0800941 "expected v%u through v%u, got v%u.\n",
942 api_ok, api_max, api_ver);
943 else
Johannes Berg965974a2012-03-06 13:30:38 -0800944 IWL_ERR(drv, "Firmware has old API version, "
Johannes Berg15854ef2012-03-05 11:24:50 -0800945 "expected v%u, got v%u.\n",
946 api_max, api_ver);
Johannes Berg965974a2012-03-06 13:30:38 -0800947 IWL_ERR(drv, "New firmware can be obtained from "
Johannes Berg15854ef2012-03-05 11:24:50 -0800948 "http://www.intellinuxwireless.org/.\n");
949 }
950 }
951
Johannes Berg15854ef2012-03-05 11:24:50 -0800952 /*
David Spinadel4db2c9a2012-03-10 13:00:15 -0800953 * In mvm uCode there is no difference between data and instructions
954 * sections.
955 */
Emmanuel Grumbach68f360d2012-03-22 17:51:44 +0200956 if (!fw->mvm_fw && validate_sec_sizes(drv, &pieces, drv->cfg))
Johannes Berg15854ef2012-03-05 11:24:50 -0800957 goto try_again;
Johannes Berg15854ef2012-03-05 11:24:50 -0800958
959 /* Allocate ucode buffers for card's bus-master loading ... */
960
961 /* Runtime instructions and 2 copies of data:
962 * 1) unmodified from disk
963 * 2) backup cache for save/restore during power-downs */
David Spinadel6dfa8d02012-03-10 13:00:14 -0800964 for (i = 0; i < IWL_UCODE_TYPE_MAX; i++)
Johannes Berg75813bd2012-05-16 22:49:49 +0200965 if (iwl_alloc_ucode(drv, &pieces, i))
966 goto out_free_fw;
Johannes Berg15854ef2012-03-05 11:24:50 -0800967
968 /* Now that we can no longer fail, copy information */
969
970 /*
971 * The (size - 16) / 12 formula is based on the information recorded
972 * for each event, which is of mode 1 (including timestamp) for all
973 * new microcodes that include this information.
974 */
Johannes Berg0692fe42012-03-06 13:30:37 -0800975 fw->init_evtlog_ptr = pieces.init_evtlog_ptr;
Johannes Berg15854ef2012-03-05 11:24:50 -0800976 if (pieces.init_evtlog_size)
Johannes Berg0692fe42012-03-06 13:30:37 -0800977 fw->init_evtlog_size = (pieces.init_evtlog_size - 16)/12;
Johannes Berg15854ef2012-03-05 11:24:50 -0800978 else
Johannes Berg0692fe42012-03-06 13:30:37 -0800979 fw->init_evtlog_size =
Emmanuel Grumbach68f360d2012-03-22 17:51:44 +0200980 drv->cfg->base_params->max_event_log_size;
Johannes Berg0692fe42012-03-06 13:30:37 -0800981 fw->init_errlog_ptr = pieces.init_errlog_ptr;
982 fw->inst_evtlog_ptr = pieces.inst_evtlog_ptr;
Johannes Berg15854ef2012-03-05 11:24:50 -0800983 if (pieces.inst_evtlog_size)
Johannes Berg0692fe42012-03-06 13:30:37 -0800984 fw->inst_evtlog_size = (pieces.inst_evtlog_size - 16)/12;
Johannes Berg15854ef2012-03-05 11:24:50 -0800985 else
Johannes Berg0692fe42012-03-06 13:30:37 -0800986 fw->inst_evtlog_size =
Emmanuel Grumbach68f360d2012-03-22 17:51:44 +0200987 drv->cfg->base_params->max_event_log_size;
Johannes Berg0692fe42012-03-06 13:30:37 -0800988 fw->inst_errlog_ptr = pieces.inst_errlog_ptr;
Johannes Berg15854ef2012-03-05 11:24:50 -0800989
990 /*
991 * figure out the offset of chain noise reset and gain commands
992 * base on the size of standard phy calibration commands table size
993 */
994 if (fw->ucode_capa.standard_phy_calibration_size >
995 IWL_MAX_PHY_CALIBRATE_TBL_SIZE)
996 fw->ucode_capa.standard_phy_calibration_size =
997 IWL_MAX_STANDARD_PHY_CALIBRATE_TBL_SIZE;
998
999 /* We have our copies now, allow OS release its copies */
1000 release_firmware(ucode_raw);
Johannes Berg15854ef2012-03-05 11:24:50 -08001001
Johannes Bergff1ffb82012-06-06 09:42:57 +02001002 mutex_lock(&iwlwifi_opmode_table_mtx);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001003 if (fw->mvm_fw)
1004 op = &iwlwifi_opmode_table[MVM_OP_MODE];
1005 else
1006 op = &iwlwifi_opmode_table[DVM_OP_MODE];
Johannes Berg15854ef2012-03-05 11:24:50 -08001007
Johannes Berg2b2719c2013-03-26 11:41:51 +01001008 IWL_INFO(drv, "loaded firmware version %s op_mode %s\n",
1009 drv->fw.fw_version, op->name);
1010
Don Frycc5f7e32012-05-16 22:54:27 +02001011 /* add this device to the list of devices using this op_mode */
1012 list_add_tail(&drv->list, &op->drv);
1013
1014 if (op->ops) {
Meenakshi Venkataraman9da987a2012-07-16 18:43:56 -07001015 drv->op_mode = _iwl_op_mode_start(drv, op);
John W. Linville7c9c46c2012-06-06 14:40:06 -04001016
Dan Carpenterdaf67ce2012-06-14 21:35:26 +03001017 if (!drv->op_mode) {
1018 mutex_unlock(&iwlwifi_opmode_table_mtx);
John W. Linville7c9c46c2012-06-06 14:40:06 -04001019 goto out_unbind;
Dan Carpenterdaf67ce2012-06-14 21:35:26 +03001020 }
Don Frycc5f7e32012-05-16 22:54:27 +02001021 } else {
Johannes Bergd4b10482012-06-12 19:50:43 +02001022 load_module = true;
Don Frycc5f7e32012-05-16 22:54:27 +02001023 }
Johannes Bergff1ffb82012-06-06 09:42:57 +02001024 mutex_unlock(&iwlwifi_opmode_table_mtx);
Johannes Berg15854ef2012-03-05 11:24:50 -08001025
Johannes Bergf69a23b2012-06-05 19:56:06 +02001026 /*
1027 * Complete the firmware request last so that
1028 * a driver unbind (stop) doesn't run while we
1029 * are doing the start() above.
1030 */
1031 complete(&drv->request_firmware_complete);
Johannes Bergd4b10482012-06-12 19:50:43 +02001032
1033 /*
1034 * Load the module last so we don't block anything
1035 * else from proceeding if the module fails to load
1036 * or hangs loading.
1037 */
Johannes Berg1618b2b2013-04-04 10:35:23 +02001038 if (load_module) {
1039 err = request_module("%s", op->name);
Johannes Berg8edf3fd2013-05-28 21:32:47 +02001040#ifdef CONFIG_IWLWIFI_OPMODE_MODULAR
Johannes Berg1618b2b2013-04-04 10:35:23 +02001041 if (err)
1042 IWL_ERR(drv,
1043 "failed to load module %s (error %d), is dynamic loading enabled?\n",
1044 op->name, err);
Johannes Berg8edf3fd2013-05-28 21:32:47 +02001045#endif
Johannes Berg1618b2b2013-04-04 10:35:23 +02001046 }
Johannes Berg15854ef2012-03-05 11:24:50 -08001047 return;
1048
1049 try_again:
1050 /* try next, if any */
1051 release_firmware(ucode_raw);
Johannes Berg965974a2012-03-06 13:30:38 -08001052 if (iwl_request_firmware(drv, false))
Johannes Berg15854ef2012-03-05 11:24:50 -08001053 goto out_unbind;
1054 return;
1055
Johannes Berg75813bd2012-05-16 22:49:49 +02001056 out_free_fw:
Johannes Berg965974a2012-03-06 13:30:38 -08001057 IWL_ERR(drv, "failed to allocate pci memory\n");
1058 iwl_dealloc_ucode(drv);
Johannes Berg15854ef2012-03-05 11:24:50 -08001059 release_firmware(ucode_raw);
1060 out_unbind:
Johannes Berg965974a2012-03-06 13:30:38 -08001061 complete(&drv->request_firmware_complete);
Emmanuel Grumbach93faaee2012-03-22 17:51:44 +02001062 device_release_driver(drv->trans->dev);
Johannes Berg15854ef2012-03-05 11:24:50 -08001063}
1064
Emmanuel Grumbach87ce05a2012-03-26 09:03:18 -07001065struct iwl_drv *iwl_drv_start(struct iwl_trans *trans,
Emmanuel Grumbach9130bab2012-03-26 08:51:09 -07001066 const struct iwl_cfg *cfg)
Emmanuel Grumbach5c58edc2012-02-07 14:18:40 +02001067{
Johannes Berg965974a2012-03-06 13:30:38 -08001068 struct iwl_drv *drv;
Emmanuel Grumbach5c58edc2012-02-07 14:18:40 +02001069 int ret;
1070
Johannes Berg965974a2012-03-06 13:30:38 -08001071 drv = kzalloc(sizeof(*drv), GFP_KERNEL);
Luciano Coelhoeafe25e2013-08-13 10:34:55 +03001072 if (!drv) {
1073 ret = -ENOMEM;
1074 goto err;
1075 }
Emmanuel Grumbachc15797e2012-04-19 10:29:58 +03001076
Emmanuel Grumbach9130bab2012-03-26 08:51:09 -07001077 drv->trans = trans;
Emmanuel Grumbach4b9844f2012-03-22 23:59:52 +02001078 drv->dev = trans->dev;
Emmanuel Grumbach68f360d2012-03-22 17:51:44 +02001079 drv->cfg = cfg;
Emmanuel Grumbach5c58edc2012-02-07 14:18:40 +02001080
Johannes Berg965974a2012-03-06 13:30:38 -08001081 init_completion(&drv->request_firmware_complete);
Johannes Bergff1ffb82012-06-06 09:42:57 +02001082 INIT_LIST_HEAD(&drv->list);
Emmanuel Grumbach5c58edc2012-02-07 14:18:40 +02001083
Meenakshi Venkataraman9da987a2012-07-16 18:43:56 -07001084#ifdef CONFIG_IWLWIFI_DEBUGFS
1085 /* Create the device debugfs entries. */
1086 drv->dbgfs_drv = debugfs_create_dir(dev_name(trans->dev),
1087 iwl_dbgfs_root);
1088
1089 if (!drv->dbgfs_drv) {
1090 IWL_ERR(drv, "failed to create debugfs directory\n");
Emmanuel Grumbach59f547a2012-11-28 16:42:09 +02001091 ret = -ENOMEM;
Meenakshi Venkataraman9da987a2012-07-16 18:43:56 -07001092 goto err_free_drv;
1093 }
1094
1095 /* Create transport layer debugfs dir */
1096 drv->trans->dbgfs_dir = debugfs_create_dir("trans", drv->dbgfs_drv);
1097
1098 if (!drv->trans->dbgfs_dir) {
1099 IWL_ERR(drv, "failed to create transport debugfs directory\n");
Emmanuel Grumbach59f547a2012-11-28 16:42:09 +02001100 ret = -ENOMEM;
Meenakshi Venkataraman9da987a2012-07-16 18:43:56 -07001101 goto err_free_dbgfs;
1102 }
1103#endif
1104
Johannes Berg965974a2012-03-06 13:30:38 -08001105 ret = iwl_request_firmware(drv, true);
Emmanuel Grumbach5c58edc2012-02-07 14:18:40 +02001106 if (ret) {
Emmanuel Grumbachc15797e2012-04-19 10:29:58 +03001107 IWL_ERR(trans, "Couldn't request the fw\n");
Meenakshi Venkataraman9da987a2012-07-16 18:43:56 -07001108 goto err_fw;
Emmanuel Grumbach5c58edc2012-02-07 14:18:40 +02001109 }
1110
Emmanuel Grumbach9130bab2012-03-26 08:51:09 -07001111 return drv;
Meenakshi Venkataraman9da987a2012-07-16 18:43:56 -07001112
1113err_fw:
1114#ifdef CONFIG_IWLWIFI_DEBUGFS
1115err_free_dbgfs:
1116 debugfs_remove_recursive(drv->dbgfs_drv);
1117err_free_drv:
1118#endif
1119 kfree(drv);
Luciano Coelhoeafe25e2013-08-13 10:34:55 +03001120err:
Emmanuel Grumbach59f547a2012-11-28 16:42:09 +02001121 return ERR_PTR(ret);
Emmanuel Grumbach5c58edc2012-02-07 14:18:40 +02001122}
1123
Emmanuel Grumbach9130bab2012-03-26 08:51:09 -07001124void iwl_drv_stop(struct iwl_drv *drv)
Emmanuel Grumbach07590f02012-02-07 14:27:31 +02001125{
Johannes Berg965974a2012-03-06 13:30:38 -08001126 wait_for_completion(&drv->request_firmware_complete);
Johannes Berg2e7eb112012-03-05 11:24:51 -08001127
Meenakshi Venkataraman9da987a2012-07-16 18:43:56 -07001128 _iwl_op_mode_stop(drv);
Emmanuel Grumbach07590f02012-02-07 14:27:31 +02001129
Johannes Berg965974a2012-03-06 13:30:38 -08001130 iwl_dealloc_ucode(drv);
Johannes Berg7db5b982012-03-05 11:24:48 -08001131
Johannes Bergff1ffb82012-06-06 09:42:57 +02001132 mutex_lock(&iwlwifi_opmode_table_mtx);
1133 /*
1134 * List is empty (this item wasn't added)
1135 * when firmware loading failed -- in that
1136 * case we can't remove it from any list.
1137 */
1138 if (!list_empty(&drv->list))
1139 list_del(&drv->list);
1140 mutex_unlock(&iwlwifi_opmode_table_mtx);
1141
Meenakshi Venkataraman9da987a2012-07-16 18:43:56 -07001142#ifdef CONFIG_IWLWIFI_DEBUGFS
1143 debugfs_remove_recursive(drv->dbgfs_drv);
1144#endif
1145
Johannes Berg965974a2012-03-06 13:30:38 -08001146 kfree(drv);
Emmanuel Grumbach07590f02012-02-07 14:27:31 +02001147}
Johannes Berg65de7e82012-04-17 07:36:30 -07001148
1149
1150/* shared module parameters */
1151struct iwl_mod_params iwlwifi_mod_params = {
Emmanuel Grumbach490953a2013-03-04 08:53:07 +02001152 .restart_fw = true,
Johannes Berg65de7e82012-04-17 07:36:30 -07001153 .bt_coex_active = true,
1154 .power_level = IWL_POWER_INDEX_1,
Emmanuel Grumbach020c8762012-06-24 15:51:59 +03001155 .wd_disable = true,
Johannes Berg65de7e82012-04-17 07:36:30 -07001156 /* the rest are 0 by default */
1157};
Johannes Berg48e29342013-03-01 00:13:33 +01001158IWL_EXPORT_SYMBOL(iwlwifi_mod_params);
Don Frycc5f7e32012-05-16 22:54:27 +02001159
1160int iwl_opmode_register(const char *name, const struct iwl_op_mode_ops *ops)
1161{
1162 int i;
1163 struct iwl_drv *drv;
Meenakshi Venkataraman9da987a2012-07-16 18:43:56 -07001164 struct iwlwifi_opmode_table *op;
Don Frycc5f7e32012-05-16 22:54:27 +02001165
Johannes Bergff1ffb82012-06-06 09:42:57 +02001166 mutex_lock(&iwlwifi_opmode_table_mtx);
Don Frycc5f7e32012-05-16 22:54:27 +02001167 for (i = 0; i < ARRAY_SIZE(iwlwifi_opmode_table); i++) {
Meenakshi Venkataraman9da987a2012-07-16 18:43:56 -07001168 op = &iwlwifi_opmode_table[i];
1169 if (strcmp(op->name, name))
Don Frycc5f7e32012-05-16 22:54:27 +02001170 continue;
Meenakshi Venkataraman9da987a2012-07-16 18:43:56 -07001171 op->ops = ops;
1172 /* TODO: need to handle exceptional case */
1173 list_for_each_entry(drv, &op->drv, list)
1174 drv->op_mode = _iwl_op_mode_start(drv, op);
1175
Johannes Bergff1ffb82012-06-06 09:42:57 +02001176 mutex_unlock(&iwlwifi_opmode_table_mtx);
Don Frycc5f7e32012-05-16 22:54:27 +02001177 return 0;
1178 }
Johannes Bergff1ffb82012-06-06 09:42:57 +02001179 mutex_unlock(&iwlwifi_opmode_table_mtx);
Don Frycc5f7e32012-05-16 22:54:27 +02001180 return -EIO;
1181}
Johannes Berg48e29342013-03-01 00:13:33 +01001182IWL_EXPORT_SYMBOL(iwl_opmode_register);
Don Frycc5f7e32012-05-16 22:54:27 +02001183
1184void iwl_opmode_deregister(const char *name)
1185{
1186 int i;
1187 struct iwl_drv *drv;
1188
Johannes Bergff1ffb82012-06-06 09:42:57 +02001189 mutex_lock(&iwlwifi_opmode_table_mtx);
Don Frycc5f7e32012-05-16 22:54:27 +02001190 for (i = 0; i < ARRAY_SIZE(iwlwifi_opmode_table); i++) {
1191 if (strcmp(iwlwifi_opmode_table[i].name, name))
1192 continue;
1193 iwlwifi_opmode_table[i].ops = NULL;
1194
1195 /* call the stop routine for all devices */
Meenakshi Venkataraman9da987a2012-07-16 18:43:56 -07001196 list_for_each_entry(drv, &iwlwifi_opmode_table[i].drv, list)
1197 _iwl_op_mode_stop(drv);
1198
Johannes Bergff1ffb82012-06-06 09:42:57 +02001199 mutex_unlock(&iwlwifi_opmode_table_mtx);
Don Frycc5f7e32012-05-16 22:54:27 +02001200 return;
1201 }
Johannes Bergff1ffb82012-06-06 09:42:57 +02001202 mutex_unlock(&iwlwifi_opmode_table_mtx);
Don Frycc5f7e32012-05-16 22:54:27 +02001203}
Johannes Berg48e29342013-03-01 00:13:33 +01001204IWL_EXPORT_SYMBOL(iwl_opmode_deregister);
Don Frycc5f7e32012-05-16 22:54:27 +02001205
1206static int __init iwl_drv_init(void)
1207{
1208 int i;
1209
Johannes Bergff1ffb82012-06-06 09:42:57 +02001210 mutex_init(&iwlwifi_opmode_table_mtx);
1211
Don Frycc5f7e32012-05-16 22:54:27 +02001212 for (i = 0; i < ARRAY_SIZE(iwlwifi_opmode_table); i++)
1213 INIT_LIST_HEAD(&iwlwifi_opmode_table[i].drv);
1214
1215 pr_info(DRV_DESCRIPTION ", " DRV_VERSION "\n");
1216 pr_info(DRV_COPYRIGHT "\n");
1217
Meenakshi Venkataraman9da987a2012-07-16 18:43:56 -07001218#ifdef CONFIG_IWLWIFI_DEBUGFS
1219 /* Create the root of iwlwifi debugfs subsystem. */
1220 iwl_dbgfs_root = debugfs_create_dir(DRV_NAME, NULL);
1221
1222 if (!iwl_dbgfs_root)
1223 return -EFAULT;
1224#endif
1225
Don Frycc5f7e32012-05-16 22:54:27 +02001226 return iwl_pci_register_driver();
1227}
1228module_init(iwl_drv_init);
1229
1230static void __exit iwl_drv_exit(void)
1231{
1232 iwl_pci_unregister_driver();
Meenakshi Venkataraman9da987a2012-07-16 18:43:56 -07001233
1234#ifdef CONFIG_IWLWIFI_DEBUGFS
1235 debugfs_remove_recursive(iwl_dbgfs_root);
1236#endif
Don Frycc5f7e32012-05-16 22:54:27 +02001237}
1238module_exit(iwl_drv_exit);
Johannes Berg65de7e82012-04-17 07:36:30 -07001239
1240#ifdef CONFIG_IWLWIFI_DEBUG
1241module_param_named(debug, iwlwifi_mod_params.debug_level, uint,
1242 S_IRUGO | S_IWUSR);
1243MODULE_PARM_DESC(debug, "debug output mask");
1244#endif
1245
1246module_param_named(swcrypto, iwlwifi_mod_params.sw_crypto, int, S_IRUGO);
1247MODULE_PARM_DESC(swcrypto, "using crypto in software (default 0 [hardware])");
1248module_param_named(11n_disable, iwlwifi_mod_params.disable_11n, uint, S_IRUGO);
1249MODULE_PARM_DESC(11n_disable,
1250 "disable 11n functionality, bitmap: 1: full, 2: agg TX, 4: agg RX");
1251module_param_named(amsdu_size_8K, iwlwifi_mod_params.amsdu_size_8K,
1252 int, S_IRUGO);
Emmanuel Grumbachaed7d9a2013-02-20 11:33:00 +02001253MODULE_PARM_DESC(amsdu_size_8K, "enable 8K amsdu size (default 0)");
Emmanuel Grumbach490953a2013-03-04 08:53:07 +02001254module_param_named(fw_restart, iwlwifi_mod_params.restart_fw, bool, S_IRUGO);
1255MODULE_PARM_DESC(fw_restart, "restart firmware in case of error (default true)");
Johannes Berg65de7e82012-04-17 07:36:30 -07001256
1257module_param_named(antenna_coupling, iwlwifi_mod_params.ant_coupling,
1258 int, S_IRUGO);
1259MODULE_PARM_DESC(antenna_coupling,
1260 "specify antenna coupling in dB (defualt: 0 dB)");
1261
Johannes Berg65de7e82012-04-17 07:36:30 -07001262module_param_named(wd_disable, iwlwifi_mod_params.wd_disable, int, S_IRUGO);
1263MODULE_PARM_DESC(wd_disable,
1264 "Disable stuck queue watchdog timer 0=system default, "
1265 "1=disable, 2=enable (default: 0)");
1266
Eran Harary12147552013-05-09 08:07:59 +03001267module_param_named(nvm_file, iwlwifi_mod_params.nvm_file, charp, S_IRUGO);
1268MODULE_PARM_DESC(nvm_file, "NVM file name");
1269
Johannes Berg65de7e82012-04-17 07:36:30 -07001270/*
1271 * set bt_coex_active to true, uCode will do kill/defer
1272 * every time the priority line is asserted (BT is sending signals on the
1273 * priority line in the PCIx).
1274 * set bt_coex_active to false, uCode will ignore the BT activity and
1275 * perform the normal operation
1276 *
1277 * User might experience transmit issue on some platform due to WiFi/BT
1278 * co-exist problem. The possible behaviors are:
1279 * Able to scan and finding all the available AP
1280 * Not able to associate with any AP
1281 * On those platforms, WiFi communication can be restored by set
1282 * "bt_coex_active" module parameter to "false"
1283 *
1284 * default: bt_coex_active = true (BT_COEX_ENABLE)
1285 */
1286module_param_named(bt_coex_active, iwlwifi_mod_params.bt_coex_active,
1287 bool, S_IRUGO);
1288MODULE_PARM_DESC(bt_coex_active, "enable wifi/bt co-exist (default: enable)");
1289
1290module_param_named(led_mode, iwlwifi_mod_params.led_mode, int, S_IRUGO);
1291MODULE_PARM_DESC(led_mode, "0=system default, "
1292 "1=On(RF On)/Off(RF Off), 2=blinking, 3=Off (default: 0)");
1293
1294module_param_named(power_save, iwlwifi_mod_params.power_save,
1295 bool, S_IRUGO);
1296MODULE_PARM_DESC(power_save,
1297 "enable WiFi power management (default: disable)");
1298
1299module_param_named(power_level, iwlwifi_mod_params.power_level,
1300 int, S_IRUGO);
1301MODULE_PARM_DESC(power_level,
1302 "default power save level (range from 1 - 5, default: 1)");