iwl-drv.c 36 KB

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