iwl-drv.c 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273
  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. .amsdu_size_8K = 1,
  966. .restart_fw = 1,
  967. .plcp_check = true,
  968. .bt_coex_active = true,
  969. .power_level = IWL_POWER_INDEX_1,
  970. .bt_ch_announce = true,
  971. .auto_agg = true,
  972. .wd_disable = true,
  973. /* the rest are 0 by default */
  974. };
  975. EXPORT_SYMBOL_GPL(iwlwifi_mod_params);
  976. int iwl_opmode_register(const char *name, const struct iwl_op_mode_ops *ops)
  977. {
  978. int i;
  979. struct iwl_drv *drv;
  980. struct iwlwifi_opmode_table *op;
  981. mutex_lock(&iwlwifi_opmode_table_mtx);
  982. for (i = 0; i < ARRAY_SIZE(iwlwifi_opmode_table); i++) {
  983. op = &iwlwifi_opmode_table[i];
  984. if (strcmp(op->name, name))
  985. continue;
  986. op->ops = ops;
  987. /* TODO: need to handle exceptional case */
  988. list_for_each_entry(drv, &op->drv, list)
  989. drv->op_mode = _iwl_op_mode_start(drv, op);
  990. mutex_unlock(&iwlwifi_opmode_table_mtx);
  991. return 0;
  992. }
  993. mutex_unlock(&iwlwifi_opmode_table_mtx);
  994. return -EIO;
  995. }
  996. EXPORT_SYMBOL_GPL(iwl_opmode_register);
  997. void iwl_opmode_deregister(const char *name)
  998. {
  999. int i;
  1000. struct iwl_drv *drv;
  1001. mutex_lock(&iwlwifi_opmode_table_mtx);
  1002. for (i = 0; i < ARRAY_SIZE(iwlwifi_opmode_table); i++) {
  1003. if (strcmp(iwlwifi_opmode_table[i].name, name))
  1004. continue;
  1005. iwlwifi_opmode_table[i].ops = NULL;
  1006. /* call the stop routine for all devices */
  1007. list_for_each_entry(drv, &iwlwifi_opmode_table[i].drv, list)
  1008. _iwl_op_mode_stop(drv);
  1009. mutex_unlock(&iwlwifi_opmode_table_mtx);
  1010. return;
  1011. }
  1012. mutex_unlock(&iwlwifi_opmode_table_mtx);
  1013. }
  1014. EXPORT_SYMBOL_GPL(iwl_opmode_deregister);
  1015. static int __init iwl_drv_init(void)
  1016. {
  1017. int i;
  1018. mutex_init(&iwlwifi_opmode_table_mtx);
  1019. for (i = 0; i < ARRAY_SIZE(iwlwifi_opmode_table); i++)
  1020. INIT_LIST_HEAD(&iwlwifi_opmode_table[i].drv);
  1021. pr_info(DRV_DESCRIPTION ", " DRV_VERSION "\n");
  1022. pr_info(DRV_COPYRIGHT "\n");
  1023. #ifdef CONFIG_IWLWIFI_DEBUGFS
  1024. /* Create the root of iwlwifi debugfs subsystem. */
  1025. iwl_dbgfs_root = debugfs_create_dir(DRV_NAME, NULL);
  1026. if (!iwl_dbgfs_root)
  1027. return -EFAULT;
  1028. #endif
  1029. return iwl_pci_register_driver();
  1030. }
  1031. module_init(iwl_drv_init);
  1032. static void __exit iwl_drv_exit(void)
  1033. {
  1034. iwl_pci_unregister_driver();
  1035. #ifdef CONFIG_IWLWIFI_DEBUGFS
  1036. debugfs_remove_recursive(iwl_dbgfs_root);
  1037. #endif
  1038. }
  1039. module_exit(iwl_drv_exit);
  1040. #ifdef CONFIG_IWLWIFI_DEBUG
  1041. module_param_named(debug, iwlwifi_mod_params.debug_level, uint,
  1042. S_IRUGO | S_IWUSR);
  1043. MODULE_PARM_DESC(debug, "debug output mask");
  1044. #endif
  1045. module_param_named(swcrypto, iwlwifi_mod_params.sw_crypto, int, S_IRUGO);
  1046. MODULE_PARM_DESC(swcrypto, "using crypto in software (default 0 [hardware])");
  1047. module_param_named(11n_disable, iwlwifi_mod_params.disable_11n, uint, S_IRUGO);
  1048. MODULE_PARM_DESC(11n_disable,
  1049. "disable 11n functionality, bitmap: 1: full, 2: agg TX, 4: agg RX");
  1050. module_param_named(amsdu_size_8K, iwlwifi_mod_params.amsdu_size_8K,
  1051. int, S_IRUGO);
  1052. MODULE_PARM_DESC(amsdu_size_8K, "enable 8K amsdu size");
  1053. module_param_named(fw_restart, iwlwifi_mod_params.restart_fw, int, S_IRUGO);
  1054. MODULE_PARM_DESC(fw_restart, "restart firmware in case of error");
  1055. module_param_named(antenna_coupling, iwlwifi_mod_params.ant_coupling,
  1056. int, S_IRUGO);
  1057. MODULE_PARM_DESC(antenna_coupling,
  1058. "specify antenna coupling in dB (defualt: 0 dB)");
  1059. module_param_named(bt_ch_inhibition, iwlwifi_mod_params.bt_ch_announce,
  1060. bool, S_IRUGO);
  1061. MODULE_PARM_DESC(bt_ch_inhibition,
  1062. "Enable BT channel inhibition (default: enable)");
  1063. module_param_named(plcp_check, iwlwifi_mod_params.plcp_check, bool, S_IRUGO);
  1064. MODULE_PARM_DESC(plcp_check, "Check plcp health (default: 1 [enabled])");
  1065. module_param_named(wd_disable, iwlwifi_mod_params.wd_disable, int, S_IRUGO);
  1066. MODULE_PARM_DESC(wd_disable,
  1067. "Disable stuck queue watchdog timer 0=system default, "
  1068. "1=disable, 2=enable (default: 0)");
  1069. /*
  1070. * set bt_coex_active to true, uCode will do kill/defer
  1071. * every time the priority line is asserted (BT is sending signals on the
  1072. * priority line in the PCIx).
  1073. * set bt_coex_active to false, uCode will ignore the BT activity and
  1074. * perform the normal operation
  1075. *
  1076. * User might experience transmit issue on some platform due to WiFi/BT
  1077. * co-exist problem. The possible behaviors are:
  1078. * Able to scan and finding all the available AP
  1079. * Not able to associate with any AP
  1080. * On those platforms, WiFi communication can be restored by set
  1081. * "bt_coex_active" module parameter to "false"
  1082. *
  1083. * default: bt_coex_active = true (BT_COEX_ENABLE)
  1084. */
  1085. module_param_named(bt_coex_active, iwlwifi_mod_params.bt_coex_active,
  1086. bool, S_IRUGO);
  1087. MODULE_PARM_DESC(bt_coex_active, "enable wifi/bt co-exist (default: enable)");
  1088. module_param_named(led_mode, iwlwifi_mod_params.led_mode, int, S_IRUGO);
  1089. MODULE_PARM_DESC(led_mode, "0=system default, "
  1090. "1=On(RF On)/Off(RF Off), 2=blinking, 3=Off (default: 0)");
  1091. module_param_named(power_save, iwlwifi_mod_params.power_save,
  1092. bool, S_IRUGO);
  1093. MODULE_PARM_DESC(power_save,
  1094. "enable WiFi power management (default: disable)");
  1095. module_param_named(power_level, iwlwifi_mod_params.power_level,
  1096. int, S_IRUGO);
  1097. MODULE_PARM_DESC(power_level,
  1098. "default power save level (range from 1 - 5, default: 1)");
  1099. module_param_named(auto_agg, iwlwifi_mod_params.auto_agg,
  1100. bool, S_IRUGO);
  1101. MODULE_PARM_DESC(auto_agg,
  1102. "enable agg w/o check traffic load (default: enable)");
  1103. module_param_named(5ghz_disable, iwlwifi_mod_params.disable_5ghz,
  1104. bool, S_IRUGO);
  1105. MODULE_PARM_DESC(5ghz_disable, "disable 5GHz band (default: 0 [enabled])");