iwl-drv.c 36 KB

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