]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/net/wireless/iwlwifi/iwl-drv.c
48d6d44c16d03053e36f5f04aa9e3baf1db8eaf7
[karo-tx-linux.git] / drivers / net / wireless / iwlwifi / iwl-drv.c
1 /******************************************************************************
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  *
8  * Copyright(c) 2007 - 2012 Intel Corporation. All rights reserved.
9  *
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
25  * in the file called LICENSE.GPL.
26  *
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  *
33  * Copyright(c) 2005 - 2012 Intel Corporation. All rights reserved.
34  * 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>
64 #include <linux/dma-mapping.h>
65 #include <linux/firmware.h>
66 #include <linux/module.h>
67
68 #include "iwl-drv.h"
69 #include "iwl-debug.h"
70 #include "iwl-trans.h"
71 #include "iwl-op-mode.h"
72 #include "iwl-agn-hw.h"
73 #include "iwl-fw.h"
74 #include "iwl-config.h"
75 #include "iwl-modparams.h"
76
77 /* private includes */
78 #include "iwl-fw-file.h"
79
80 /******************************************************************************
81  *
82  * module boiler plate
83  *
84  ******************************************************************************/
85
86 /*
87  * module name, copyright, version, etc.
88  */
89 #define DRV_DESCRIPTION "Intel(R) Wireless WiFi driver for Linux"
90
91 #ifdef CONFIG_IWLWIFI_DEBUG
92 #define VD "d"
93 #else
94 #define VD
95 #endif
96
97 #define DRV_VERSION     IWLWIFI_VERSION VD
98
99 MODULE_DESCRIPTION(DRV_DESCRIPTION);
100 MODULE_VERSION(DRV_VERSION);
101 MODULE_AUTHOR(DRV_COPYRIGHT " " DRV_AUTHOR);
102 MODULE_LICENSE("GPL");
103
104 #ifdef CONFIG_IWLWIFI_DEBUGFS
105 static struct dentry *iwl_dbgfs_root;
106 #endif
107
108 /**
109  * struct iwl_drv - drv common data
110  * @list: list of drv structures using this opmode
111  * @fw: the iwl_fw structure
112  * @op_mode: the running op_mode
113  * @trans: transport layer
114  * @dev: for debug prints only
115  * @cfg: configuration struct
116  * @fw_index: firmware revision to try loading
117  * @firmware_name: composite filename of ucode file to load
118  * @request_firmware_complete: the firmware has been obtained from user space
119  */
120 struct iwl_drv {
121         struct list_head list;
122         struct iwl_fw fw;
123
124         struct iwl_op_mode *op_mode;
125         struct iwl_trans *trans;
126         struct device *dev;
127         const struct iwl_cfg *cfg;
128
129         int fw_index;                   /* firmware we're trying to load */
130         char firmware_name[25];         /* name of firmware file to load */
131
132         struct completion request_firmware_complete;
133
134 #ifdef CONFIG_IWLWIFI_DEBUGFS
135         struct dentry *dbgfs_drv;
136         struct dentry *dbgfs_trans;
137         struct dentry *dbgfs_op_mode;
138 #endif
139 };
140
141 #define DVM_OP_MODE     0
142 #define MVM_OP_MODE     1
143
144 /* Protects the table contents, i.e. the ops pointer & drv list */
145 static struct mutex iwlwifi_opmode_table_mtx;
146 static struct iwlwifi_opmode_table {
147         const char *name;                       /* name: iwldvm, iwlmvm, etc */
148         const struct iwl_op_mode_ops *ops;      /* pointer to op_mode ops */
149         struct list_head drv;           /* list of devices using this op_mode */
150 } iwlwifi_opmode_table[] = {            /* ops set when driver is initialized */
151         { .name = "iwldvm", .ops = NULL },
152         { .name = "iwlmvm", .ops = NULL },
153 };
154
155 /*
156  * struct fw_sec: Just for the image parsing proccess.
157  * For the fw storage we are using struct fw_desc.
158  */
159 struct fw_sec {
160         const void *data;               /* the sec data */
161         size_t size;                    /* section size */
162         u32 offset;                     /* offset of writing in the device */
163 };
164
165 static void iwl_free_fw_desc(struct iwl_drv *drv, struct fw_desc *desc)
166 {
167         if (desc->v_addr)
168                 dma_free_coherent(drv->trans->dev, desc->len,
169                                   desc->v_addr, desc->p_addr);
170         desc->v_addr = NULL;
171         desc->len = 0;
172 }
173
174 static void iwl_free_fw_img(struct iwl_drv *drv, struct fw_img *img)
175 {
176         int i;
177         for (i = 0; i < IWL_UCODE_SECTION_MAX; i++)
178                 iwl_free_fw_desc(drv, &img->sec[i]);
179 }
180
181 static void iwl_dealloc_ucode(struct iwl_drv *drv)
182 {
183         int i;
184         for (i = 0; i < IWL_UCODE_TYPE_MAX; i++)
185                 iwl_free_fw_img(drv, drv->fw.img + i);
186 }
187
188 static int iwl_alloc_fw_desc(struct iwl_drv *drv, struct fw_desc *desc,
189                       struct fw_sec *sec)
190 {
191         if (!sec || !sec->size) {
192                 desc->v_addr = NULL;
193                 return -EINVAL;
194         }
195
196         desc->v_addr = dma_alloc_coherent(drv->trans->dev, sec->size,
197                                           &desc->p_addr, GFP_KERNEL);
198         if (!desc->v_addr)
199                 return -ENOMEM;
200
201         desc->len = sec->size;
202         desc->offset = sec->offset;
203         memcpy(desc->v_addr, sec->data, sec->size);
204         return 0;
205 }
206
207 static void iwl_req_fw_callback(const struct firmware *ucode_raw,
208                                 void *context);
209
210 #define UCODE_EXPERIMENTAL_INDEX        100
211 #define UCODE_EXPERIMENTAL_TAG          "exp"
212
213 static int iwl_request_firmware(struct iwl_drv *drv, bool first)
214 {
215         const char *name_pre = drv->cfg->fw_name_pre;
216         char tag[8];
217
218         if (first) {
219 #ifdef CONFIG_IWLWIFI_DEBUG_EXPERIMENTAL_UCODE
220                 drv->fw_index = UCODE_EXPERIMENTAL_INDEX;
221                 strcpy(tag, UCODE_EXPERIMENTAL_TAG);
222         } else if (drv->fw_index == UCODE_EXPERIMENTAL_INDEX) {
223 #endif
224                 drv->fw_index = drv->cfg->ucode_api_max;
225                 sprintf(tag, "%d", drv->fw_index);
226         } else {
227                 drv->fw_index--;
228                 sprintf(tag, "%d", drv->fw_index);
229         }
230
231         if (drv->fw_index < drv->cfg->ucode_api_min) {
232                 IWL_ERR(drv, "no suitable firmware found!\n");
233                 return -ENOENT;
234         }
235
236         sprintf(drv->firmware_name, "%s%s%s", name_pre, tag, ".ucode");
237
238         IWL_DEBUG_INFO(drv, "attempting to load firmware %s'%s'\n",
239                        (drv->fw_index == UCODE_EXPERIMENTAL_INDEX)
240                                 ? "EXPERIMENTAL " : "",
241                        drv->firmware_name);
242
243         return request_firmware_nowait(THIS_MODULE, 1, drv->firmware_name,
244                                        drv->trans->dev,
245                                        GFP_KERNEL, drv, iwl_req_fw_callback);
246 }
247
248 struct fw_img_parsing {
249         struct fw_sec sec[IWL_UCODE_SECTION_MAX];
250         int sec_counter;
251 };
252
253 /*
254  * struct fw_sec_parsing: to extract fw section and it's offset from tlv
255  */
256 struct fw_sec_parsing {
257         __le32 offset;
258         const u8 data[];
259 } __packed;
260
261 /**
262  * struct iwl_tlv_calib_data - parse the default calib data from TLV
263  *
264  * @ucode_type: the uCode to which the following default calib relates.
265  * @calib: default calibrations.
266  */
267 struct iwl_tlv_calib_data {
268         __le32 ucode_type;
269         __le64 calib;
270 } __packed;
271
272 struct iwl_firmware_pieces {
273         struct fw_img_parsing img[IWL_UCODE_TYPE_MAX];
274
275         u32 init_evtlog_ptr, init_evtlog_size, init_errlog_ptr;
276         u32 inst_evtlog_ptr, inst_evtlog_size, inst_errlog_ptr;
277 };
278
279 /*
280  * These functions are just to extract uCode section data from the pieces
281  * structure.
282  */
283 static struct fw_sec *get_sec(struct iwl_firmware_pieces *pieces,
284                               enum iwl_ucode_type type,
285                               int  sec)
286 {
287         return &pieces->img[type].sec[sec];
288 }
289
290 static void set_sec_data(struct iwl_firmware_pieces *pieces,
291                          enum iwl_ucode_type type,
292                          int sec,
293                          const void *data)
294 {
295         pieces->img[type].sec[sec].data = data;
296 }
297
298 static void set_sec_size(struct iwl_firmware_pieces *pieces,
299                          enum iwl_ucode_type type,
300                          int sec,
301                          size_t size)
302 {
303         pieces->img[type].sec[sec].size = size;
304 }
305
306 static size_t get_sec_size(struct iwl_firmware_pieces *pieces,
307                            enum iwl_ucode_type type,
308                            int sec)
309 {
310         return pieces->img[type].sec[sec].size;
311 }
312
313 static void set_sec_offset(struct iwl_firmware_pieces *pieces,
314                            enum iwl_ucode_type type,
315                            int sec,
316                            u32 offset)
317 {
318         pieces->img[type].sec[sec].offset = offset;
319 }
320
321 /*
322  * Gets uCode section from tlv.
323  */
324 static int iwl_store_ucode_sec(struct iwl_firmware_pieces *pieces,
325                                const void *data, enum iwl_ucode_type type,
326                                int size)
327 {
328         struct fw_img_parsing *img;
329         struct fw_sec *sec;
330         struct fw_sec_parsing *sec_parse;
331
332         if (WARN_ON(!pieces || !data || type >= IWL_UCODE_TYPE_MAX))
333                 return -1;
334
335         sec_parse = (struct fw_sec_parsing *)data;
336
337         img = &pieces->img[type];
338         sec = &img->sec[img->sec_counter];
339
340         sec->offset = le32_to_cpu(sec_parse->offset);
341         sec->data = sec_parse->data;
342         sec->size = size - sizeof(sec_parse->offset);
343
344         ++img->sec_counter;
345
346         return 0;
347 }
348
349 static int iwl_set_default_calib(struct iwl_drv *drv, const u8 *data)
350 {
351         struct iwl_tlv_calib_data *def_calib =
352                                         (struct iwl_tlv_calib_data *)data;
353         u32 ucode_type = le32_to_cpu(def_calib->ucode_type);
354         if (ucode_type >= IWL_UCODE_TYPE_MAX) {
355                 IWL_ERR(drv, "Wrong ucode_type %u for default calibration.\n",
356                         ucode_type);
357                 return -EINVAL;
358         }
359         drv->fw.default_calib[ucode_type] = le64_to_cpu(def_calib->calib);
360         return 0;
361 }
362
363 static int iwl_parse_v1_v2_firmware(struct iwl_drv *drv,
364                                     const struct firmware *ucode_raw,
365                                     struct iwl_firmware_pieces *pieces)
366 {
367         struct iwl_ucode_header *ucode = (void *)ucode_raw->data;
368         u32 api_ver, hdr_size, build;
369         char buildstr[25];
370         const u8 *src;
371
372         drv->fw.ucode_ver = le32_to_cpu(ucode->ver);
373         api_ver = IWL_UCODE_API(drv->fw.ucode_ver);
374
375         switch (api_ver) {
376         default:
377                 hdr_size = 28;
378                 if (ucode_raw->size < hdr_size) {
379                         IWL_ERR(drv, "File size too small!\n");
380                         return -EINVAL;
381                 }
382                 build = le32_to_cpu(ucode->u.v2.build);
383                 set_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_INST,
384                              le32_to_cpu(ucode->u.v2.inst_size));
385                 set_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_DATA,
386                              le32_to_cpu(ucode->u.v2.data_size));
387                 set_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST,
388                              le32_to_cpu(ucode->u.v2.init_size));
389                 set_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA,
390                              le32_to_cpu(ucode->u.v2.init_data_size));
391                 src = ucode->u.v2.data;
392                 break;
393         case 0:
394         case 1:
395         case 2:
396                 hdr_size = 24;
397                 if (ucode_raw->size < hdr_size) {
398                         IWL_ERR(drv, "File size too small!\n");
399                         return -EINVAL;
400                 }
401                 build = 0;
402                 set_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_INST,
403                              le32_to_cpu(ucode->u.v1.inst_size));
404                 set_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_DATA,
405                              le32_to_cpu(ucode->u.v1.data_size));
406                 set_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST,
407                              le32_to_cpu(ucode->u.v1.init_size));
408                 set_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA,
409                              le32_to_cpu(ucode->u.v1.init_data_size));
410                 src = ucode->u.v1.data;
411                 break;
412         }
413
414         if (build)
415                 sprintf(buildstr, " build %u%s", build,
416                        (drv->fw_index == UCODE_EXPERIMENTAL_INDEX)
417                                 ? " (EXP)" : "");
418         else
419                 buildstr[0] = '\0';
420
421         snprintf(drv->fw.fw_version,
422                  sizeof(drv->fw.fw_version),
423                  "%u.%u.%u.%u%s",
424                  IWL_UCODE_MAJOR(drv->fw.ucode_ver),
425                  IWL_UCODE_MINOR(drv->fw.ucode_ver),
426                  IWL_UCODE_API(drv->fw.ucode_ver),
427                  IWL_UCODE_SERIAL(drv->fw.ucode_ver),
428                  buildstr);
429
430         /* Verify size of file vs. image size info in file's header */
431
432         if (ucode_raw->size != hdr_size +
433             get_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_INST) +
434             get_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_DATA) +
435             get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST) +
436             get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA)) {
437
438                 IWL_ERR(drv,
439                         "uCode file size %d does not match expected size\n",
440                         (int)ucode_raw->size);
441                 return -EINVAL;
442         }
443
444
445         set_sec_data(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_INST, src);
446         src += get_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_INST);
447         set_sec_offset(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_INST,
448                        IWLAGN_RTC_INST_LOWER_BOUND);
449         set_sec_data(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_DATA, src);
450         src += get_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_DATA);
451         set_sec_offset(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_DATA,
452                        IWLAGN_RTC_DATA_LOWER_BOUND);
453         set_sec_data(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST, src);
454         src += get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST);
455         set_sec_offset(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST,
456                        IWLAGN_RTC_INST_LOWER_BOUND);
457         set_sec_data(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA, src);
458         src += get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA);
459         set_sec_offset(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA,
460                        IWLAGN_RTC_DATA_LOWER_BOUND);
461         return 0;
462 }
463
464 static int iwl_parse_tlv_firmware(struct iwl_drv *drv,
465                                 const struct firmware *ucode_raw,
466                                 struct iwl_firmware_pieces *pieces,
467                                 struct iwl_ucode_capabilities *capa)
468 {
469         struct iwl_tlv_ucode_header *ucode = (void *)ucode_raw->data;
470         struct iwl_ucode_tlv *tlv;
471         size_t len = ucode_raw->size;
472         const u8 *data;
473         u32 tlv_len;
474         enum iwl_ucode_tlv_type tlv_type;
475         const u8 *tlv_data;
476         char buildstr[25];
477         u32 build;
478
479         if (len < sizeof(*ucode)) {
480                 IWL_ERR(drv, "uCode has invalid length: %zd\n", len);
481                 return -EINVAL;
482         }
483
484         if (ucode->magic != cpu_to_le32(IWL_TLV_UCODE_MAGIC)) {
485                 IWL_ERR(drv, "invalid uCode magic: 0X%x\n",
486                         le32_to_cpu(ucode->magic));
487                 return -EINVAL;
488         }
489
490         drv->fw.ucode_ver = le32_to_cpu(ucode->ver);
491         build = le32_to_cpu(ucode->build);
492
493         if (build)
494                 sprintf(buildstr, " build %u%s", build,
495                        (drv->fw_index == UCODE_EXPERIMENTAL_INDEX)
496                                 ? " (EXP)" : "");
497         else
498                 buildstr[0] = '\0';
499
500         snprintf(drv->fw.fw_version,
501                  sizeof(drv->fw.fw_version),
502                  "%u.%u.%u.%u%s",
503                  IWL_UCODE_MAJOR(drv->fw.ucode_ver),
504                  IWL_UCODE_MINOR(drv->fw.ucode_ver),
505                  IWL_UCODE_API(drv->fw.ucode_ver),
506                  IWL_UCODE_SERIAL(drv->fw.ucode_ver),
507                  buildstr);
508
509         data = ucode->data;
510
511         len -= sizeof(*ucode);
512
513         while (len >= sizeof(*tlv)) {
514                 len -= sizeof(*tlv);
515                 tlv = (void *)data;
516
517                 tlv_len = le32_to_cpu(tlv->length);
518                 tlv_type = le32_to_cpu(tlv->type);
519                 tlv_data = tlv->data;
520
521                 if (len < tlv_len) {
522                         IWL_ERR(drv, "invalid TLV len: %zd/%u\n",
523                                 len, tlv_len);
524                         return -EINVAL;
525                 }
526                 len -= ALIGN(tlv_len, 4);
527                 data += sizeof(*tlv) + ALIGN(tlv_len, 4);
528
529                 switch (tlv_type) {
530                 case IWL_UCODE_TLV_INST:
531                         set_sec_data(pieces, IWL_UCODE_REGULAR,
532                                      IWL_UCODE_SECTION_INST, tlv_data);
533                         set_sec_size(pieces, IWL_UCODE_REGULAR,
534                                      IWL_UCODE_SECTION_INST, tlv_len);
535                         set_sec_offset(pieces, IWL_UCODE_REGULAR,
536                                        IWL_UCODE_SECTION_INST,
537                                        IWLAGN_RTC_INST_LOWER_BOUND);
538                         break;
539                 case IWL_UCODE_TLV_DATA:
540                         set_sec_data(pieces, IWL_UCODE_REGULAR,
541                                      IWL_UCODE_SECTION_DATA, tlv_data);
542                         set_sec_size(pieces, IWL_UCODE_REGULAR,
543                                      IWL_UCODE_SECTION_DATA, tlv_len);
544                         set_sec_offset(pieces, IWL_UCODE_REGULAR,
545                                        IWL_UCODE_SECTION_DATA,
546                                        IWLAGN_RTC_DATA_LOWER_BOUND);
547                         break;
548                 case IWL_UCODE_TLV_INIT:
549                         set_sec_data(pieces, IWL_UCODE_INIT,
550                                      IWL_UCODE_SECTION_INST, tlv_data);
551                         set_sec_size(pieces, IWL_UCODE_INIT,
552                                      IWL_UCODE_SECTION_INST, tlv_len);
553                         set_sec_offset(pieces, IWL_UCODE_INIT,
554                                        IWL_UCODE_SECTION_INST,
555                                        IWLAGN_RTC_INST_LOWER_BOUND);
556                         break;
557                 case IWL_UCODE_TLV_INIT_DATA:
558                         set_sec_data(pieces, IWL_UCODE_INIT,
559                                      IWL_UCODE_SECTION_DATA, tlv_data);
560                         set_sec_size(pieces, IWL_UCODE_INIT,
561                                      IWL_UCODE_SECTION_DATA, tlv_len);
562                         set_sec_offset(pieces, IWL_UCODE_INIT,
563                                        IWL_UCODE_SECTION_DATA,
564                                        IWLAGN_RTC_DATA_LOWER_BOUND);
565                         break;
566                 case IWL_UCODE_TLV_BOOT:
567                         IWL_ERR(drv, "Found unexpected BOOT ucode\n");
568                         break;
569                 case IWL_UCODE_TLV_PROBE_MAX_LEN:
570                         if (tlv_len != sizeof(u32))
571                                 goto invalid_tlv_len;
572                         capa->max_probe_length =
573                                         le32_to_cpup((__le32 *)tlv_data);
574                         break;
575                 case IWL_UCODE_TLV_PAN:
576                         if (tlv_len)
577                                 goto invalid_tlv_len;
578                         capa->flags |= IWL_UCODE_TLV_FLAGS_PAN;
579                         break;
580                 case IWL_UCODE_TLV_FLAGS:
581                         /* must be at least one u32 */
582                         if (tlv_len < sizeof(u32))
583                                 goto invalid_tlv_len;
584                         /* and a proper number of u32s */
585                         if (tlv_len % sizeof(u32))
586                                 goto invalid_tlv_len;
587                         /*
588                          * This driver only reads the first u32 as
589                          * right now no more features are defined,
590                          * if that changes then either the driver
591                          * will not work with the new firmware, or
592                          * it'll not take advantage of new features.
593                          */
594                         capa->flags = le32_to_cpup((__le32 *)tlv_data);
595                         break;
596                 case IWL_UCODE_TLV_INIT_EVTLOG_PTR:
597                         if (tlv_len != sizeof(u32))
598                                 goto invalid_tlv_len;
599                         pieces->init_evtlog_ptr =
600                                         le32_to_cpup((__le32 *)tlv_data);
601                         break;
602                 case IWL_UCODE_TLV_INIT_EVTLOG_SIZE:
603                         if (tlv_len != sizeof(u32))
604                                 goto invalid_tlv_len;
605                         pieces->init_evtlog_size =
606                                         le32_to_cpup((__le32 *)tlv_data);
607                         break;
608                 case IWL_UCODE_TLV_INIT_ERRLOG_PTR:
609                         if (tlv_len != sizeof(u32))
610                                 goto invalid_tlv_len;
611                         pieces->init_errlog_ptr =
612                                         le32_to_cpup((__le32 *)tlv_data);
613                         break;
614                 case IWL_UCODE_TLV_RUNT_EVTLOG_PTR:
615                         if (tlv_len != sizeof(u32))
616                                 goto invalid_tlv_len;
617                         pieces->inst_evtlog_ptr =
618                                         le32_to_cpup((__le32 *)tlv_data);
619                         break;
620                 case IWL_UCODE_TLV_RUNT_EVTLOG_SIZE:
621                         if (tlv_len != sizeof(u32))
622                                 goto invalid_tlv_len;
623                         pieces->inst_evtlog_size =
624                                         le32_to_cpup((__le32 *)tlv_data);
625                         break;
626                 case IWL_UCODE_TLV_RUNT_ERRLOG_PTR:
627                         if (tlv_len != sizeof(u32))
628                                 goto invalid_tlv_len;
629                         pieces->inst_errlog_ptr =
630                                         le32_to_cpup((__le32 *)tlv_data);
631                         break;
632                 case IWL_UCODE_TLV_ENHANCE_SENS_TBL:
633                         if (tlv_len)
634                                 goto invalid_tlv_len;
635                         drv->fw.enhance_sensitivity_table = true;
636                         break;
637                 case IWL_UCODE_TLV_WOWLAN_INST:
638                         set_sec_data(pieces, IWL_UCODE_WOWLAN,
639                                      IWL_UCODE_SECTION_INST, tlv_data);
640                         set_sec_size(pieces, IWL_UCODE_WOWLAN,
641                                      IWL_UCODE_SECTION_INST, tlv_len);
642                         set_sec_offset(pieces, IWL_UCODE_WOWLAN,
643                                        IWL_UCODE_SECTION_INST,
644                                        IWLAGN_RTC_INST_LOWER_BOUND);
645                         break;
646                 case IWL_UCODE_TLV_WOWLAN_DATA:
647                         set_sec_data(pieces, IWL_UCODE_WOWLAN,
648                                      IWL_UCODE_SECTION_DATA, tlv_data);
649                         set_sec_size(pieces, IWL_UCODE_WOWLAN,
650                                      IWL_UCODE_SECTION_DATA, tlv_len);
651                         set_sec_offset(pieces, IWL_UCODE_WOWLAN,
652                                        IWL_UCODE_SECTION_DATA,
653                                        IWLAGN_RTC_DATA_LOWER_BOUND);
654                         break;
655                 case IWL_UCODE_TLV_PHY_CALIBRATION_SIZE:
656                         if (tlv_len != sizeof(u32))
657                                 goto invalid_tlv_len;
658                         capa->standard_phy_calibration_size =
659                                         le32_to_cpup((__le32 *)tlv_data);
660                         break;
661                  case IWL_UCODE_TLV_SEC_RT:
662                         iwl_store_ucode_sec(pieces, tlv_data, IWL_UCODE_REGULAR,
663                                             tlv_len);
664                         drv->fw.mvm_fw = true;
665                         break;
666                 case IWL_UCODE_TLV_SEC_INIT:
667                         iwl_store_ucode_sec(pieces, tlv_data, IWL_UCODE_INIT,
668                                             tlv_len);
669                         drv->fw.mvm_fw = true;
670                         break;
671                 case IWL_UCODE_TLV_SEC_WOWLAN:
672                         iwl_store_ucode_sec(pieces, tlv_data, IWL_UCODE_WOWLAN,
673                                             tlv_len);
674                         drv->fw.mvm_fw = true;
675                         break;
676                 case IWL_UCODE_TLV_DEF_CALIB:
677                         if (tlv_len != sizeof(struct iwl_tlv_calib_data))
678                                 goto invalid_tlv_len;
679                         if (iwl_set_default_calib(drv, tlv_data))
680                                 goto tlv_error;
681                         break;
682                 case IWL_UCODE_TLV_PHY_SKU:
683                         if (tlv_len != sizeof(u32))
684                                 goto invalid_tlv_len;
685                         drv->fw.phy_config = le32_to_cpup((__le32 *)tlv_data);
686                         break;
687                 default:
688                         IWL_DEBUG_INFO(drv, "unknown TLV: %d\n", tlv_type);
689                         break;
690                 }
691         }
692
693         if (len) {
694                 IWL_ERR(drv, "invalid TLV after parsing: %zd\n", len);
695                 iwl_print_hex_dump(drv, IWL_DL_FW, (u8 *)data, len);
696                 return -EINVAL;
697         }
698
699         return 0;
700
701  invalid_tlv_len:
702         IWL_ERR(drv, "TLV %d has invalid size: %u\n", tlv_type, tlv_len);
703  tlv_error:
704         iwl_print_hex_dump(drv, IWL_DL_FW, tlv_data, tlv_len);
705
706         return -EINVAL;
707 }
708
709 static int iwl_alloc_ucode(struct iwl_drv *drv,
710                            struct iwl_firmware_pieces *pieces,
711                            enum iwl_ucode_type type)
712 {
713         int i;
714         for (i = 0;
715              i < IWL_UCODE_SECTION_MAX && get_sec_size(pieces, type, i);
716              i++)
717                 if (iwl_alloc_fw_desc(drv, &(drv->fw.img[type].sec[i]),
718                                       get_sec(pieces, type, i)))
719                         return -ENOMEM;
720         return 0;
721 }
722
723 static int validate_sec_sizes(struct iwl_drv *drv,
724                               struct iwl_firmware_pieces *pieces,
725                               const struct iwl_cfg *cfg)
726 {
727         IWL_DEBUG_INFO(drv, "f/w package hdr runtime inst size = %Zd\n",
728                 get_sec_size(pieces, IWL_UCODE_REGULAR,
729                              IWL_UCODE_SECTION_INST));
730         IWL_DEBUG_INFO(drv, "f/w package hdr runtime data size = %Zd\n",
731                 get_sec_size(pieces, IWL_UCODE_REGULAR,
732                              IWL_UCODE_SECTION_DATA));
733         IWL_DEBUG_INFO(drv, "f/w package hdr init inst size = %Zd\n",
734                 get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST));
735         IWL_DEBUG_INFO(drv, "f/w package hdr init data size = %Zd\n",
736                 get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA));
737
738         /* Verify that uCode images will fit in card's SRAM. */
739         if (get_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_INST) >
740                                                         cfg->max_inst_size) {
741                 IWL_ERR(drv, "uCode instr len %Zd too large to fit in\n",
742                         get_sec_size(pieces, IWL_UCODE_REGULAR,
743                                                 IWL_UCODE_SECTION_INST));
744                 return -1;
745         }
746
747         if (get_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_DATA) >
748                                                         cfg->max_data_size) {
749                 IWL_ERR(drv, "uCode data len %Zd too large to fit in\n",
750                         get_sec_size(pieces, IWL_UCODE_REGULAR,
751                                                 IWL_UCODE_SECTION_DATA));
752                 return -1;
753         }
754
755          if (get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST) >
756                                                         cfg->max_inst_size) {
757                 IWL_ERR(drv, "uCode init instr len %Zd too large to fit in\n",
758                         get_sec_size(pieces, IWL_UCODE_INIT,
759                                                 IWL_UCODE_SECTION_INST));
760                 return -1;
761         }
762
763         if (get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA) >
764                                                         cfg->max_data_size) {
765                 IWL_ERR(drv, "uCode init data len %Zd too large to fit in\n",
766                         get_sec_size(pieces, IWL_UCODE_REGULAR,
767                                                 IWL_UCODE_SECTION_DATA));
768                 return -1;
769         }
770         return 0;
771 }
772
773 static struct iwl_op_mode *
774 _iwl_op_mode_start(struct iwl_drv *drv, struct iwlwifi_opmode_table *op)
775 {
776         const struct iwl_op_mode_ops *ops = op->ops;
777         struct dentry *dbgfs_dir = NULL;
778         struct iwl_op_mode *op_mode = NULL;
779
780 #ifdef CONFIG_IWLWIFI_DEBUGFS
781         drv->dbgfs_op_mode = debugfs_create_dir(op->name,
782                                                 drv->dbgfs_drv);
783         if (!drv->dbgfs_op_mode) {
784                 IWL_ERR(drv,
785                         "failed to create opmode debugfs directory\n");
786                 return op_mode;
787         }
788         dbgfs_dir = drv->dbgfs_op_mode;
789 #endif
790
791         op_mode = ops->start(drv->trans, drv->cfg, &drv->fw, dbgfs_dir);
792
793 #ifdef CONFIG_IWLWIFI_DEBUGFS
794         if (!op_mode) {
795                 debugfs_remove_recursive(drv->dbgfs_op_mode);
796                 drv->dbgfs_op_mode = NULL;
797         }
798 #endif
799
800         return op_mode;
801 }
802
803 static void _iwl_op_mode_stop(struct iwl_drv *drv)
804 {
805         /* op_mode can be NULL if its start failed */
806         if (drv->op_mode) {
807                 iwl_op_mode_stop(drv->op_mode);
808                 drv->op_mode = NULL;
809
810 #ifdef CONFIG_IWLWIFI_DEBUGFS
811                 debugfs_remove_recursive(drv->dbgfs_op_mode);
812                 drv->dbgfs_op_mode = NULL;
813 #endif
814         }
815 }
816
817 /**
818  * iwl_req_fw_callback - callback when firmware was loaded
819  *
820  * If loaded successfully, copies the firmware into buffers
821  * for the card to fetch (via DMA).
822  */
823 static void iwl_req_fw_callback(const struct firmware *ucode_raw, void *context)
824 {
825         struct iwl_drv *drv = context;
826         struct iwl_fw *fw = &drv->fw;
827         struct iwl_ucode_header *ucode;
828         struct iwlwifi_opmode_table *op;
829         int err;
830         struct iwl_firmware_pieces pieces;
831         const unsigned int api_max = drv->cfg->ucode_api_max;
832         unsigned int api_ok = drv->cfg->ucode_api_ok;
833         const unsigned int api_min = drv->cfg->ucode_api_min;
834         u32 api_ver;
835         int i;
836         bool load_module = false;
837
838         fw->ucode_capa.max_probe_length = 200;
839         fw->ucode_capa.standard_phy_calibration_size =
840                         IWL_DEFAULT_STANDARD_PHY_CALIBRATE_TBL_SIZE;
841
842         if (!api_ok)
843                 api_ok = api_max;
844
845         memset(&pieces, 0, sizeof(pieces));
846
847         if (!ucode_raw) {
848                 if (drv->fw_index <= api_ok)
849                         IWL_ERR(drv,
850                                 "request for firmware file '%s' failed.\n",
851                                 drv->firmware_name);
852                 goto try_again;
853         }
854
855         IWL_DEBUG_INFO(drv, "Loaded firmware file '%s' (%zd bytes).\n",
856                        drv->firmware_name, ucode_raw->size);
857
858         /* Make sure that we got at least the API version number */
859         if (ucode_raw->size < 4) {
860                 IWL_ERR(drv, "File size way too small!\n");
861                 goto try_again;
862         }
863
864         /* Data from ucode file:  header followed by uCode images */
865         ucode = (struct iwl_ucode_header *)ucode_raw->data;
866
867         if (ucode->ver)
868                 err = iwl_parse_v1_v2_firmware(drv, ucode_raw, &pieces);
869         else
870                 err = iwl_parse_tlv_firmware(drv, ucode_raw, &pieces,
871                                            &fw->ucode_capa);
872
873         if (err)
874                 goto try_again;
875
876         api_ver = IWL_UCODE_API(drv->fw.ucode_ver);
877
878         /*
879          * api_ver should match the api version forming part of the
880          * firmware filename ... but we don't check for that and only rely
881          * on the API version read from firmware header from here on forward
882          */
883         /* no api version check required for experimental uCode */
884         if (drv->fw_index != UCODE_EXPERIMENTAL_INDEX) {
885                 if (api_ver < api_min || api_ver > api_max) {
886                         IWL_ERR(drv,
887                                 "Driver unable to support your firmware API. "
888                                 "Driver supports v%u, firmware is v%u.\n",
889                                 api_max, api_ver);
890                         goto try_again;
891                 }
892
893                 if (api_ver < api_ok) {
894                         if (api_ok != api_max)
895                                 IWL_ERR(drv, "Firmware has old API version, "
896                                         "expected v%u through v%u, got v%u.\n",
897                                         api_ok, api_max, api_ver);
898                         else
899                                 IWL_ERR(drv, "Firmware has old API version, "
900                                         "expected v%u, got v%u.\n",
901                                         api_max, api_ver);
902                         IWL_ERR(drv, "New firmware can be obtained from "
903                                       "http://www.intellinuxwireless.org/.\n");
904                 }
905         }
906
907         IWL_INFO(drv, "loaded firmware version %s", drv->fw.fw_version);
908
909         /*
910          * In mvm uCode there is no difference between data and instructions
911          * sections.
912          */
913         if (!fw->mvm_fw && validate_sec_sizes(drv, &pieces, drv->cfg))
914                 goto try_again;
915
916         /* Allocate ucode buffers for card's bus-master loading ... */
917
918         /* Runtime instructions and 2 copies of data:
919          * 1) unmodified from disk
920          * 2) backup cache for save/restore during power-downs */
921         for (i = 0; i < IWL_UCODE_TYPE_MAX; i++)
922                 if (iwl_alloc_ucode(drv, &pieces, i))
923                         goto out_free_fw;
924
925         /* Now that we can no longer fail, copy information */
926
927         /*
928          * The (size - 16) / 12 formula is based on the information recorded
929          * for each event, which is of mode 1 (including timestamp) for all
930          * new microcodes that include this information.
931          */
932         fw->init_evtlog_ptr = pieces.init_evtlog_ptr;
933         if (pieces.init_evtlog_size)
934                 fw->init_evtlog_size = (pieces.init_evtlog_size - 16)/12;
935         else
936                 fw->init_evtlog_size =
937                         drv->cfg->base_params->max_event_log_size;
938         fw->init_errlog_ptr = pieces.init_errlog_ptr;
939         fw->inst_evtlog_ptr = pieces.inst_evtlog_ptr;
940         if (pieces.inst_evtlog_size)
941                 fw->inst_evtlog_size = (pieces.inst_evtlog_size - 16)/12;
942         else
943                 fw->inst_evtlog_size =
944                         drv->cfg->base_params->max_event_log_size;
945         fw->inst_errlog_ptr = pieces.inst_errlog_ptr;
946
947         /*
948          * figure out the offset of chain noise reset and gain commands
949          * base on the size of standard phy calibration commands table size
950          */
951         if (fw->ucode_capa.standard_phy_calibration_size >
952             IWL_MAX_PHY_CALIBRATE_TBL_SIZE)
953                 fw->ucode_capa.standard_phy_calibration_size =
954                         IWL_MAX_STANDARD_PHY_CALIBRATE_TBL_SIZE;
955
956         /* We have our copies now, allow OS release its copies */
957         release_firmware(ucode_raw);
958
959         mutex_lock(&iwlwifi_opmode_table_mtx);
960         op = &iwlwifi_opmode_table[DVM_OP_MODE];
961
962         /* add this device to the list of devices using this op_mode */
963         list_add_tail(&drv->list, &op->drv);
964
965         if (op->ops) {
966                 drv->op_mode = _iwl_op_mode_start(drv, op);
967
968                 if (!drv->op_mode) {
969                         mutex_unlock(&iwlwifi_opmode_table_mtx);
970                         goto out_unbind;
971                 }
972         } else {
973                 load_module = true;
974         }
975         mutex_unlock(&iwlwifi_opmode_table_mtx);
976
977         /*
978          * Complete the firmware request last so that
979          * a driver unbind (stop) doesn't run while we
980          * are doing the start() above.
981          */
982         complete(&drv->request_firmware_complete);
983
984         /*
985          * Load the module last so we don't block anything
986          * else from proceeding if the module fails to load
987          * or hangs loading.
988          */
989         if (load_module)
990                 request_module("%s", op->name);
991         return;
992
993  try_again:
994         /* try next, if any */
995         release_firmware(ucode_raw);
996         if (iwl_request_firmware(drv, false))
997                 goto out_unbind;
998         return;
999
1000  out_free_fw:
1001         IWL_ERR(drv, "failed to allocate pci memory\n");
1002         iwl_dealloc_ucode(drv);
1003         release_firmware(ucode_raw);
1004  out_unbind:
1005         complete(&drv->request_firmware_complete);
1006         device_release_driver(drv->trans->dev);
1007 }
1008
1009 struct iwl_drv *iwl_drv_start(struct iwl_trans *trans,
1010                               const struct iwl_cfg *cfg)
1011 {
1012         struct iwl_drv *drv;
1013         int ret;
1014
1015         drv = kzalloc(sizeof(*drv), GFP_KERNEL);
1016         if (!drv)
1017                 return NULL;
1018
1019         drv->trans = trans;
1020         drv->dev = trans->dev;
1021         drv->cfg = cfg;
1022
1023         init_completion(&drv->request_firmware_complete);
1024         INIT_LIST_HEAD(&drv->list);
1025
1026 #ifdef CONFIG_IWLWIFI_DEBUGFS
1027         /* Create the device debugfs entries. */
1028         drv->dbgfs_drv = debugfs_create_dir(dev_name(trans->dev),
1029                                             iwl_dbgfs_root);
1030
1031         if (!drv->dbgfs_drv) {
1032                 IWL_ERR(drv, "failed to create debugfs directory\n");
1033                 goto err_free_drv;
1034         }
1035
1036         /* Create transport layer debugfs dir */
1037         drv->trans->dbgfs_dir = debugfs_create_dir("trans", drv->dbgfs_drv);
1038
1039         if (!drv->trans->dbgfs_dir) {
1040                 IWL_ERR(drv, "failed to create transport debugfs directory\n");
1041                 goto err_free_dbgfs;
1042         }
1043 #endif
1044
1045         ret = iwl_request_firmware(drv, true);
1046
1047         if (ret) {
1048                 IWL_ERR(trans, "Couldn't request the fw\n");
1049                 goto err_fw;
1050         }
1051
1052         return drv;
1053
1054 err_fw:
1055 #ifdef CONFIG_IWLWIFI_DEBUGFS
1056 err_free_dbgfs:
1057         debugfs_remove_recursive(drv->dbgfs_drv);
1058 err_free_drv:
1059 #endif
1060         kfree(drv);
1061         drv = NULL;
1062
1063         return drv;
1064 }
1065
1066 void iwl_drv_stop(struct iwl_drv *drv)
1067 {
1068         wait_for_completion(&drv->request_firmware_complete);
1069
1070         _iwl_op_mode_stop(drv);
1071
1072         iwl_dealloc_ucode(drv);
1073
1074         mutex_lock(&iwlwifi_opmode_table_mtx);
1075         /*
1076          * List is empty (this item wasn't added)
1077          * when firmware loading failed -- in that
1078          * case we can't remove it from any list.
1079          */
1080         if (!list_empty(&drv->list))
1081                 list_del(&drv->list);
1082         mutex_unlock(&iwlwifi_opmode_table_mtx);
1083
1084 #ifdef CONFIG_IWLWIFI_DEBUGFS
1085         debugfs_remove_recursive(drv->dbgfs_drv);
1086 #endif
1087
1088         kfree(drv);
1089 }
1090
1091
1092 /* shared module parameters */
1093 struct iwl_mod_params iwlwifi_mod_params = {
1094         .amsdu_size_8K = 1,
1095         .restart_fw = 1,
1096         .plcp_check = true,
1097         .bt_coex_active = true,
1098         .power_level = IWL_POWER_INDEX_1,
1099         .bt_ch_announce = true,
1100         .auto_agg = true,
1101         .wd_disable = true,
1102         /* the rest are 0 by default */
1103 };
1104 EXPORT_SYMBOL_GPL(iwlwifi_mod_params);
1105
1106 int iwl_opmode_register(const char *name, const struct iwl_op_mode_ops *ops)
1107 {
1108         int i;
1109         struct iwl_drv *drv;
1110         struct iwlwifi_opmode_table *op;
1111
1112         mutex_lock(&iwlwifi_opmode_table_mtx);
1113         for (i = 0; i < ARRAY_SIZE(iwlwifi_opmode_table); i++) {
1114                 op = &iwlwifi_opmode_table[i];
1115                 if (strcmp(op->name, name))
1116                         continue;
1117                 op->ops = ops;
1118                 /* TODO: need to handle exceptional case */
1119                 list_for_each_entry(drv, &op->drv, list)
1120                         drv->op_mode = _iwl_op_mode_start(drv, op);
1121
1122                 mutex_unlock(&iwlwifi_opmode_table_mtx);
1123                 return 0;
1124         }
1125         mutex_unlock(&iwlwifi_opmode_table_mtx);
1126         return -EIO;
1127 }
1128 EXPORT_SYMBOL_GPL(iwl_opmode_register);
1129
1130 void iwl_opmode_deregister(const char *name)
1131 {
1132         int i;
1133         struct iwl_drv *drv;
1134
1135         mutex_lock(&iwlwifi_opmode_table_mtx);
1136         for (i = 0; i < ARRAY_SIZE(iwlwifi_opmode_table); i++) {
1137                 if (strcmp(iwlwifi_opmode_table[i].name, name))
1138                         continue;
1139                 iwlwifi_opmode_table[i].ops = NULL;
1140
1141                 /* call the stop routine for all devices */
1142                 list_for_each_entry(drv, &iwlwifi_opmode_table[i].drv, list)
1143                         _iwl_op_mode_stop(drv);
1144
1145                 mutex_unlock(&iwlwifi_opmode_table_mtx);
1146                 return;
1147         }
1148         mutex_unlock(&iwlwifi_opmode_table_mtx);
1149 }
1150 EXPORT_SYMBOL_GPL(iwl_opmode_deregister);
1151
1152 static int __init iwl_drv_init(void)
1153 {
1154         int i;
1155
1156         mutex_init(&iwlwifi_opmode_table_mtx);
1157
1158         for (i = 0; i < ARRAY_SIZE(iwlwifi_opmode_table); i++)
1159                 INIT_LIST_HEAD(&iwlwifi_opmode_table[i].drv);
1160
1161         pr_info(DRV_DESCRIPTION ", " DRV_VERSION "\n");
1162         pr_info(DRV_COPYRIGHT "\n");
1163
1164 #ifdef CONFIG_IWLWIFI_DEBUGFS
1165         /* Create the root of iwlwifi debugfs subsystem. */
1166         iwl_dbgfs_root = debugfs_create_dir(DRV_NAME, NULL);
1167
1168         if (!iwl_dbgfs_root)
1169                 return -EFAULT;
1170 #endif
1171
1172         return iwl_pci_register_driver();
1173 }
1174 module_init(iwl_drv_init);
1175
1176 static void __exit iwl_drv_exit(void)
1177 {
1178         iwl_pci_unregister_driver();
1179
1180 #ifdef CONFIG_IWLWIFI_DEBUGFS
1181         debugfs_remove_recursive(iwl_dbgfs_root);
1182 #endif
1183 }
1184 module_exit(iwl_drv_exit);
1185
1186 #ifdef CONFIG_IWLWIFI_DEBUG
1187 module_param_named(debug, iwlwifi_mod_params.debug_level, uint,
1188                    S_IRUGO | S_IWUSR);
1189 MODULE_PARM_DESC(debug, "debug output mask");
1190 #endif
1191
1192 module_param_named(swcrypto, iwlwifi_mod_params.sw_crypto, int, S_IRUGO);
1193 MODULE_PARM_DESC(swcrypto, "using crypto in software (default 0 [hardware])");
1194 module_param_named(11n_disable, iwlwifi_mod_params.disable_11n, uint, S_IRUGO);
1195 MODULE_PARM_DESC(11n_disable,
1196         "disable 11n functionality, bitmap: 1: full, 2: agg TX, 4: agg RX");
1197 module_param_named(amsdu_size_8K, iwlwifi_mod_params.amsdu_size_8K,
1198                    int, S_IRUGO);
1199 MODULE_PARM_DESC(amsdu_size_8K, "enable 8K amsdu size");
1200 module_param_named(fw_restart, iwlwifi_mod_params.restart_fw, int, S_IRUGO);
1201 MODULE_PARM_DESC(fw_restart, "restart firmware in case of error");
1202
1203 module_param_named(antenna_coupling, iwlwifi_mod_params.ant_coupling,
1204                    int, S_IRUGO);
1205 MODULE_PARM_DESC(antenna_coupling,
1206                  "specify antenna coupling in dB (defualt: 0 dB)");
1207
1208 module_param_named(bt_ch_inhibition, iwlwifi_mod_params.bt_ch_announce,
1209                    bool, S_IRUGO);
1210 MODULE_PARM_DESC(bt_ch_inhibition,
1211                  "Enable BT channel inhibition (default: enable)");
1212
1213 module_param_named(plcp_check, iwlwifi_mod_params.plcp_check, bool, S_IRUGO);
1214 MODULE_PARM_DESC(plcp_check, "Check plcp health (default: 1 [enabled])");
1215
1216 module_param_named(wd_disable, iwlwifi_mod_params.wd_disable, int, S_IRUGO);
1217 MODULE_PARM_DESC(wd_disable,
1218                 "Disable stuck queue watchdog timer 0=system default, "
1219                 "1=disable, 2=enable (default: 0)");
1220
1221 /*
1222  * set bt_coex_active to true, uCode will do kill/defer
1223  * every time the priority line is asserted (BT is sending signals on the
1224  * priority line in the PCIx).
1225  * set bt_coex_active to false, uCode will ignore the BT activity and
1226  * perform the normal operation
1227  *
1228  * User might experience transmit issue on some platform due to WiFi/BT
1229  * co-exist problem. The possible behaviors are:
1230  *   Able to scan and finding all the available AP
1231  *   Not able to associate with any AP
1232  * On those platforms, WiFi communication can be restored by set
1233  * "bt_coex_active" module parameter to "false"
1234  *
1235  * default: bt_coex_active = true (BT_COEX_ENABLE)
1236  */
1237 module_param_named(bt_coex_active, iwlwifi_mod_params.bt_coex_active,
1238                 bool, S_IRUGO);
1239 MODULE_PARM_DESC(bt_coex_active, "enable wifi/bt co-exist (default: enable)");
1240
1241 module_param_named(led_mode, iwlwifi_mod_params.led_mode, int, S_IRUGO);
1242 MODULE_PARM_DESC(led_mode, "0=system default, "
1243                 "1=On(RF On)/Off(RF Off), 2=blinking, 3=Off (default: 0)");
1244
1245 module_param_named(power_save, iwlwifi_mod_params.power_save,
1246                 bool, S_IRUGO);
1247 MODULE_PARM_DESC(power_save,
1248                  "enable WiFi power management (default: disable)");
1249
1250 module_param_named(power_level, iwlwifi_mod_params.power_level,
1251                 int, S_IRUGO);
1252 MODULE_PARM_DESC(power_level,
1253                  "default power save level (range from 1 - 5, default: 1)");
1254
1255 module_param_named(auto_agg, iwlwifi_mod_params.auto_agg,
1256                 bool, S_IRUGO);
1257 MODULE_PARM_DESC(auto_agg,
1258                  "enable agg w/o check traffic load (default: enable)");
1259
1260 module_param_named(5ghz_disable, iwlwifi_mod_params.disable_5ghz,
1261                 bool, S_IRUGO);
1262 MODULE_PARM_DESC(5ghz_disable, "disable 5GHz band (default: 0 [enabled])");