iwl-drv.c 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725
  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 - 2014 Intel Corporation. All rights reserved.
  9. * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
  10. * Copyright(c) 2016 Intel Deutschland GmbH
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of version 2 of the GNU General Public License as
  14. * published by the Free Software Foundation.
  15. *
  16. * This program is distributed in the hope that it will be useful, but
  17. * WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  19. * General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
  24. * USA
  25. *
  26. * The full GNU General Public License is included in this distribution
  27. * in the file called COPYING.
  28. *
  29. * Contact Information:
  30. * Intel Linux Wireless <linuxwifi@intel.com>
  31. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  32. *
  33. * BSD LICENSE
  34. *
  35. * Copyright(c) 2005 - 2014 Intel Corporation. All rights reserved.
  36. * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
  37. * Copyright(c) 2016 Intel Deutschland GmbH
  38. * All rights reserved.
  39. *
  40. * Redistribution and use in source and binary forms, with or without
  41. * modification, are permitted provided that the following conditions
  42. * are met:
  43. *
  44. * * Redistributions of source code must retain the above copyright
  45. * notice, this list of conditions and the following disclaimer.
  46. * * Redistributions in binary form must reproduce the above copyright
  47. * notice, this list of conditions and the following disclaimer in
  48. * the documentation and/or other materials provided with the
  49. * distribution.
  50. * * Neither the name Intel Corporation nor the names of its
  51. * contributors may be used to endorse or promote products derived
  52. * from this software without specific prior written permission.
  53. *
  54. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  55. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  56. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  57. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  58. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  59. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  60. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  61. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  62. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  63. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  64. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  65. *
  66. *****************************************************************************/
  67. #include <linux/completion.h>
  68. #include <linux/dma-mapping.h>
  69. #include <linux/firmware.h>
  70. #include <linux/module.h>
  71. #include <linux/vmalloc.h>
  72. #include "iwl-drv.h"
  73. #include "iwl-csr.h"
  74. #include "iwl-debug.h"
  75. #include "iwl-trans.h"
  76. #include "iwl-op-mode.h"
  77. #include "iwl-agn-hw.h"
  78. #include "iwl-fw.h"
  79. #include "iwl-config.h"
  80. #include "iwl-modparams.h"
  81. /******************************************************************************
  82. *
  83. * module boiler plate
  84. *
  85. ******************************************************************************/
  86. #define DRV_DESCRIPTION "Intel(R) Wireless WiFi driver for Linux"
  87. MODULE_DESCRIPTION(DRV_DESCRIPTION);
  88. MODULE_AUTHOR(DRV_COPYRIGHT " " DRV_AUTHOR);
  89. MODULE_LICENSE("GPL");
  90. #ifdef CONFIG_IWLWIFI_DEBUGFS
  91. static struct dentry *iwl_dbgfs_root;
  92. #endif
  93. /**
  94. * struct iwl_drv - drv common data
  95. * @list: list of drv structures using this opmode
  96. * @fw: the iwl_fw structure
  97. * @op_mode: the running op_mode
  98. * @trans: transport layer
  99. * @dev: for debug prints only
  100. * @cfg: configuration struct
  101. * @fw_index: firmware revision to try loading
  102. * @firmware_name: composite filename of ucode file to load
  103. * @request_firmware_complete: the firmware has been obtained from user space
  104. */
  105. struct iwl_drv {
  106. struct list_head list;
  107. struct iwl_fw fw;
  108. struct iwl_op_mode *op_mode;
  109. struct iwl_trans *trans;
  110. struct device *dev;
  111. const struct iwl_cfg *cfg;
  112. int fw_index; /* firmware we're trying to load */
  113. char firmware_name[64]; /* name of firmware file to load */
  114. struct completion request_firmware_complete;
  115. #ifdef CONFIG_IWLWIFI_DEBUGFS
  116. struct dentry *dbgfs_drv;
  117. struct dentry *dbgfs_trans;
  118. struct dentry *dbgfs_op_mode;
  119. #endif
  120. };
  121. enum {
  122. DVM_OP_MODE,
  123. MVM_OP_MODE,
  124. };
  125. /* Protects the table contents, i.e. the ops pointer & drv list */
  126. static struct mutex iwlwifi_opmode_table_mtx;
  127. static struct iwlwifi_opmode_table {
  128. const char *name; /* name: iwldvm, iwlmvm, etc */
  129. const struct iwl_op_mode_ops *ops; /* pointer to op_mode ops */
  130. struct list_head drv; /* list of devices using this op_mode */
  131. } iwlwifi_opmode_table[] = { /* ops set when driver is initialized */
  132. [DVM_OP_MODE] = { .name = "iwldvm", .ops = NULL },
  133. [MVM_OP_MODE] = { .name = "iwlmvm", .ops = NULL },
  134. };
  135. #define IWL_DEFAULT_SCAN_CHANNELS 40
  136. /*
  137. * struct fw_sec: Just for the image parsing process.
  138. * For the fw storage we are using struct fw_desc.
  139. */
  140. struct fw_sec {
  141. const void *data; /* the sec data */
  142. size_t size; /* section size */
  143. u32 offset; /* offset of writing in the device */
  144. };
  145. static void iwl_free_fw_desc(struct iwl_drv *drv, struct fw_desc *desc)
  146. {
  147. vfree(desc->data);
  148. desc->data = NULL;
  149. desc->len = 0;
  150. }
  151. static void iwl_free_fw_img(struct iwl_drv *drv, struct fw_img *img)
  152. {
  153. int i;
  154. for (i = 0; i < IWL_UCODE_SECTION_MAX; i++)
  155. iwl_free_fw_desc(drv, &img->sec[i]);
  156. }
  157. static void iwl_dealloc_ucode(struct iwl_drv *drv)
  158. {
  159. int i;
  160. kfree(drv->fw.dbg_dest_tlv);
  161. for (i = 0; i < ARRAY_SIZE(drv->fw.dbg_conf_tlv); i++)
  162. kfree(drv->fw.dbg_conf_tlv[i]);
  163. for (i = 0; i < ARRAY_SIZE(drv->fw.dbg_trigger_tlv); i++)
  164. kfree(drv->fw.dbg_trigger_tlv[i]);
  165. for (i = 0; i < ARRAY_SIZE(drv->fw.dbg_mem_tlv); i++)
  166. kfree(drv->fw.dbg_mem_tlv[i]);
  167. for (i = 0; i < IWL_UCODE_TYPE_MAX; i++)
  168. iwl_free_fw_img(drv, drv->fw.img + i);
  169. }
  170. static int iwl_alloc_fw_desc(struct iwl_drv *drv, struct fw_desc *desc,
  171. struct fw_sec *sec)
  172. {
  173. void *data;
  174. desc->data = NULL;
  175. if (!sec || !sec->size)
  176. return -EINVAL;
  177. data = vmalloc(sec->size);
  178. if (!data)
  179. return -ENOMEM;
  180. desc->len = sec->size;
  181. desc->offset = sec->offset;
  182. memcpy(data, sec->data, desc->len);
  183. desc->data = data;
  184. return 0;
  185. }
  186. static void iwl_req_fw_callback(const struct firmware *ucode_raw,
  187. void *context);
  188. static int iwl_request_firmware(struct iwl_drv *drv, bool first)
  189. {
  190. const char *name_pre = drv->cfg->fw_name_pre;
  191. char tag[8];
  192. if (first) {
  193. drv->fw_index = drv->cfg->ucode_api_max;
  194. sprintf(tag, "%d", drv->fw_index);
  195. } else {
  196. drv->fw_index--;
  197. sprintf(tag, "%d", drv->fw_index);
  198. }
  199. if (drv->fw_index < drv->cfg->ucode_api_min) {
  200. IWL_ERR(drv, "no suitable firmware found!\n");
  201. return -ENOENT;
  202. }
  203. snprintf(drv->firmware_name, sizeof(drv->firmware_name), "%s%s.ucode",
  204. name_pre, tag);
  205. IWL_DEBUG_INFO(drv, "attempting to load firmware '%s'\n",
  206. drv->firmware_name);
  207. return request_firmware_nowait(THIS_MODULE, 1, drv->firmware_name,
  208. drv->trans->dev,
  209. GFP_KERNEL, drv, iwl_req_fw_callback);
  210. }
  211. struct fw_img_parsing {
  212. struct fw_sec sec[IWL_UCODE_SECTION_MAX];
  213. int sec_counter;
  214. };
  215. /*
  216. * struct fw_sec_parsing: to extract fw section and it's offset from tlv
  217. */
  218. struct fw_sec_parsing {
  219. __le32 offset;
  220. const u8 data[];
  221. } __packed;
  222. /**
  223. * struct iwl_tlv_calib_data - parse the default calib data from TLV
  224. *
  225. * @ucode_type: the uCode to which the following default calib relates.
  226. * @calib: default calibrations.
  227. */
  228. struct iwl_tlv_calib_data {
  229. __le32 ucode_type;
  230. struct iwl_tlv_calib_ctrl calib;
  231. } __packed;
  232. struct iwl_firmware_pieces {
  233. struct fw_img_parsing img[IWL_UCODE_TYPE_MAX];
  234. u32 init_evtlog_ptr, init_evtlog_size, init_errlog_ptr;
  235. u32 inst_evtlog_ptr, inst_evtlog_size, inst_errlog_ptr;
  236. /* FW debug data parsed for driver usage */
  237. struct iwl_fw_dbg_dest_tlv *dbg_dest_tlv;
  238. struct iwl_fw_dbg_conf_tlv *dbg_conf_tlv[FW_DBG_CONF_MAX];
  239. size_t dbg_conf_tlv_len[FW_DBG_CONF_MAX];
  240. struct iwl_fw_dbg_trigger_tlv *dbg_trigger_tlv[FW_DBG_TRIGGER_MAX];
  241. size_t dbg_trigger_tlv_len[FW_DBG_TRIGGER_MAX];
  242. struct iwl_fw_dbg_mem_seg_tlv *dbg_mem_tlv[FW_DBG_MEM_MAX];
  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. static int iwl_store_cscheme(struct iwl_fw *fw, const u8 *data, const u32 len)
  282. {
  283. int i, j;
  284. struct iwl_fw_cscheme_list *l = (struct iwl_fw_cscheme_list *)data;
  285. struct iwl_fw_cipher_scheme *fwcs;
  286. if (len < sizeof(*l) ||
  287. len < sizeof(l->size) + l->size * sizeof(l->cs[0]))
  288. return -EINVAL;
  289. for (i = 0, j = 0; i < IWL_UCODE_MAX_CS && i < l->size; i++) {
  290. fwcs = &l->cs[j];
  291. /* we skip schemes with zero cipher suite selector */
  292. if (!fwcs->cipher)
  293. continue;
  294. fw->cs[j++] = *fwcs;
  295. }
  296. return 0;
  297. }
  298. static void iwl_store_gscan_capa(struct iwl_fw *fw, const u8 *data,
  299. const u32 len)
  300. {
  301. struct iwl_fw_gscan_capabilities *fw_capa = (void *)data;
  302. struct iwl_gscan_capabilities *capa = &fw->gscan_capa;
  303. capa->max_scan_cache_size = le32_to_cpu(fw_capa->max_scan_cache_size);
  304. capa->max_scan_buckets = le32_to_cpu(fw_capa->max_scan_buckets);
  305. capa->max_ap_cache_per_scan =
  306. le32_to_cpu(fw_capa->max_ap_cache_per_scan);
  307. capa->max_rssi_sample_size = le32_to_cpu(fw_capa->max_rssi_sample_size);
  308. capa->max_scan_reporting_threshold =
  309. le32_to_cpu(fw_capa->max_scan_reporting_threshold);
  310. capa->max_hotlist_aps = le32_to_cpu(fw_capa->max_hotlist_aps);
  311. capa->max_significant_change_aps =
  312. le32_to_cpu(fw_capa->max_significant_change_aps);
  313. capa->max_bssid_history_entries =
  314. le32_to_cpu(fw_capa->max_bssid_history_entries);
  315. capa->max_hotlist_ssids = le32_to_cpu(fw_capa->max_hotlist_ssids);
  316. capa->max_number_epno_networks =
  317. le32_to_cpu(fw_capa->max_number_epno_networks);
  318. capa->max_number_epno_networks_by_ssid =
  319. le32_to_cpu(fw_capa->max_number_epno_networks_by_ssid);
  320. capa->max_number_of_white_listed_ssid =
  321. le32_to_cpu(fw_capa->max_number_of_white_listed_ssid);
  322. capa->max_number_of_black_listed_ssid =
  323. le32_to_cpu(fw_capa->max_number_of_black_listed_ssid);
  324. }
  325. /*
  326. * Gets uCode section from tlv.
  327. */
  328. static int iwl_store_ucode_sec(struct iwl_firmware_pieces *pieces,
  329. const void *data, enum iwl_ucode_type type,
  330. int size)
  331. {
  332. struct fw_img_parsing *img;
  333. struct fw_sec *sec;
  334. struct fw_sec_parsing *sec_parse;
  335. if (WARN_ON(!pieces || !data || type >= IWL_UCODE_TYPE_MAX))
  336. return -1;
  337. sec_parse = (struct fw_sec_parsing *)data;
  338. img = &pieces->img[type];
  339. sec = &img->sec[img->sec_counter];
  340. sec->offset = le32_to_cpu(sec_parse->offset);
  341. sec->data = sec_parse->data;
  342. sec->size = size - sizeof(sec_parse->offset);
  343. ++img->sec_counter;
  344. return 0;
  345. }
  346. static int iwl_set_default_calib(struct iwl_drv *drv, const u8 *data)
  347. {
  348. struct iwl_tlv_calib_data *def_calib =
  349. (struct iwl_tlv_calib_data *)data;
  350. u32 ucode_type = le32_to_cpu(def_calib->ucode_type);
  351. if (ucode_type >= IWL_UCODE_TYPE_MAX) {
  352. IWL_ERR(drv, "Wrong ucode_type %u for default calibration.\n",
  353. ucode_type);
  354. return -EINVAL;
  355. }
  356. drv->fw.default_calib[ucode_type].flow_trigger =
  357. def_calib->calib.flow_trigger;
  358. drv->fw.default_calib[ucode_type].event_trigger =
  359. def_calib->calib.event_trigger;
  360. return 0;
  361. }
  362. static int iwl_set_ucode_api_flags(struct iwl_drv *drv, const u8 *data,
  363. struct iwl_ucode_capabilities *capa)
  364. {
  365. const struct iwl_ucode_api *ucode_api = (void *)data;
  366. u32 api_index = le32_to_cpu(ucode_api->api_index);
  367. u32 api_flags = le32_to_cpu(ucode_api->api_flags);
  368. int i;
  369. if (api_index >= DIV_ROUND_UP(NUM_IWL_UCODE_TLV_API, 32)) {
  370. IWL_ERR(drv,
  371. "api flags index %d larger than supported by driver\n",
  372. api_index);
  373. /* don't return an error so we can load FW that has more bits */
  374. return 0;
  375. }
  376. for (i = 0; i < 32; i++) {
  377. if (api_flags & BIT(i))
  378. __set_bit(i + 32 * api_index, capa->_api);
  379. }
  380. return 0;
  381. }
  382. static int iwl_set_ucode_capabilities(struct iwl_drv *drv, const u8 *data,
  383. struct iwl_ucode_capabilities *capa)
  384. {
  385. const struct iwl_ucode_capa *ucode_capa = (void *)data;
  386. u32 api_index = le32_to_cpu(ucode_capa->api_index);
  387. u32 api_flags = le32_to_cpu(ucode_capa->api_capa);
  388. int i;
  389. if (api_index >= DIV_ROUND_UP(NUM_IWL_UCODE_TLV_CAPA, 32)) {
  390. IWL_ERR(drv,
  391. "capa flags index %d larger than supported by driver\n",
  392. api_index);
  393. /* don't return an error so we can load FW that has more bits */
  394. return 0;
  395. }
  396. for (i = 0; i < 32; i++) {
  397. if (api_flags & BIT(i))
  398. __set_bit(i + 32 * api_index, capa->_capa);
  399. }
  400. return 0;
  401. }
  402. static int iwl_parse_v1_v2_firmware(struct iwl_drv *drv,
  403. const struct firmware *ucode_raw,
  404. struct iwl_firmware_pieces *pieces)
  405. {
  406. struct iwl_ucode_header *ucode = (void *)ucode_raw->data;
  407. u32 api_ver, hdr_size, build;
  408. char buildstr[25];
  409. const u8 *src;
  410. drv->fw.ucode_ver = le32_to_cpu(ucode->ver);
  411. api_ver = IWL_UCODE_API(drv->fw.ucode_ver);
  412. switch (api_ver) {
  413. default:
  414. hdr_size = 28;
  415. if (ucode_raw->size < hdr_size) {
  416. IWL_ERR(drv, "File size too small!\n");
  417. return -EINVAL;
  418. }
  419. build = le32_to_cpu(ucode->u.v2.build);
  420. set_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_INST,
  421. le32_to_cpu(ucode->u.v2.inst_size));
  422. set_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_DATA,
  423. le32_to_cpu(ucode->u.v2.data_size));
  424. set_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST,
  425. le32_to_cpu(ucode->u.v2.init_size));
  426. set_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA,
  427. le32_to_cpu(ucode->u.v2.init_data_size));
  428. src = ucode->u.v2.data;
  429. break;
  430. case 0:
  431. case 1:
  432. case 2:
  433. hdr_size = 24;
  434. if (ucode_raw->size < hdr_size) {
  435. IWL_ERR(drv, "File size too small!\n");
  436. return -EINVAL;
  437. }
  438. build = 0;
  439. set_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_INST,
  440. le32_to_cpu(ucode->u.v1.inst_size));
  441. set_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_DATA,
  442. le32_to_cpu(ucode->u.v1.data_size));
  443. set_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST,
  444. le32_to_cpu(ucode->u.v1.init_size));
  445. set_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA,
  446. le32_to_cpu(ucode->u.v1.init_data_size));
  447. src = ucode->u.v1.data;
  448. break;
  449. }
  450. if (build)
  451. sprintf(buildstr, " build %u", build);
  452. else
  453. buildstr[0] = '\0';
  454. snprintf(drv->fw.fw_version,
  455. sizeof(drv->fw.fw_version),
  456. "%u.%u.%u.%u%s",
  457. IWL_UCODE_MAJOR(drv->fw.ucode_ver),
  458. IWL_UCODE_MINOR(drv->fw.ucode_ver),
  459. IWL_UCODE_API(drv->fw.ucode_ver),
  460. IWL_UCODE_SERIAL(drv->fw.ucode_ver),
  461. buildstr);
  462. /* Verify size of file vs. image size info in file's header */
  463. if (ucode_raw->size != hdr_size +
  464. get_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_INST) +
  465. get_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_DATA) +
  466. get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST) +
  467. get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA)) {
  468. IWL_ERR(drv,
  469. "uCode file size %d does not match expected size\n",
  470. (int)ucode_raw->size);
  471. return -EINVAL;
  472. }
  473. set_sec_data(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_INST, src);
  474. src += get_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_INST);
  475. set_sec_offset(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_INST,
  476. IWLAGN_RTC_INST_LOWER_BOUND);
  477. set_sec_data(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_DATA, src);
  478. src += get_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_DATA);
  479. set_sec_offset(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_DATA,
  480. IWLAGN_RTC_DATA_LOWER_BOUND);
  481. set_sec_data(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST, src);
  482. src += get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST);
  483. set_sec_offset(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST,
  484. IWLAGN_RTC_INST_LOWER_BOUND);
  485. set_sec_data(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA, src);
  486. src += get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA);
  487. set_sec_offset(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA,
  488. IWLAGN_RTC_DATA_LOWER_BOUND);
  489. return 0;
  490. }
  491. static int iwl_parse_tlv_firmware(struct iwl_drv *drv,
  492. const struct firmware *ucode_raw,
  493. struct iwl_firmware_pieces *pieces,
  494. struct iwl_ucode_capabilities *capa,
  495. bool *usniffer_images)
  496. {
  497. struct iwl_tlv_ucode_header *ucode = (void *)ucode_raw->data;
  498. struct iwl_ucode_tlv *tlv;
  499. size_t len = ucode_raw->size;
  500. const u8 *data;
  501. u32 tlv_len;
  502. u32 usniffer_img;
  503. enum iwl_ucode_tlv_type tlv_type;
  504. const u8 *tlv_data;
  505. char buildstr[25];
  506. u32 build, paging_mem_size;
  507. int num_of_cpus;
  508. bool usniffer_req = false;
  509. bool gscan_capa = false;
  510. if (len < sizeof(*ucode)) {
  511. IWL_ERR(drv, "uCode has invalid length: %zd\n", len);
  512. return -EINVAL;
  513. }
  514. if (ucode->magic != cpu_to_le32(IWL_TLV_UCODE_MAGIC)) {
  515. IWL_ERR(drv, "invalid uCode magic: 0X%x\n",
  516. le32_to_cpu(ucode->magic));
  517. return -EINVAL;
  518. }
  519. drv->fw.ucode_ver = le32_to_cpu(ucode->ver);
  520. memcpy(drv->fw.human_readable, ucode->human_readable,
  521. sizeof(drv->fw.human_readable));
  522. build = le32_to_cpu(ucode->build);
  523. if (build)
  524. sprintf(buildstr, " build %u", build);
  525. else
  526. buildstr[0] = '\0';
  527. snprintf(drv->fw.fw_version,
  528. sizeof(drv->fw.fw_version),
  529. "%u.%u.%u.%u%s",
  530. IWL_UCODE_MAJOR(drv->fw.ucode_ver),
  531. IWL_UCODE_MINOR(drv->fw.ucode_ver),
  532. IWL_UCODE_API(drv->fw.ucode_ver),
  533. IWL_UCODE_SERIAL(drv->fw.ucode_ver),
  534. buildstr);
  535. data = ucode->data;
  536. len -= sizeof(*ucode);
  537. while (len >= sizeof(*tlv)) {
  538. len -= sizeof(*tlv);
  539. tlv = (void *)data;
  540. tlv_len = le32_to_cpu(tlv->length);
  541. tlv_type = le32_to_cpu(tlv->type);
  542. tlv_data = tlv->data;
  543. if (len < tlv_len) {
  544. IWL_ERR(drv, "invalid TLV len: %zd/%u\n",
  545. len, tlv_len);
  546. return -EINVAL;
  547. }
  548. len -= ALIGN(tlv_len, 4);
  549. data += sizeof(*tlv) + ALIGN(tlv_len, 4);
  550. switch (tlv_type) {
  551. case IWL_UCODE_TLV_INST:
  552. set_sec_data(pieces, IWL_UCODE_REGULAR,
  553. IWL_UCODE_SECTION_INST, tlv_data);
  554. set_sec_size(pieces, IWL_UCODE_REGULAR,
  555. IWL_UCODE_SECTION_INST, tlv_len);
  556. set_sec_offset(pieces, IWL_UCODE_REGULAR,
  557. IWL_UCODE_SECTION_INST,
  558. IWLAGN_RTC_INST_LOWER_BOUND);
  559. break;
  560. case IWL_UCODE_TLV_DATA:
  561. set_sec_data(pieces, IWL_UCODE_REGULAR,
  562. IWL_UCODE_SECTION_DATA, tlv_data);
  563. set_sec_size(pieces, IWL_UCODE_REGULAR,
  564. IWL_UCODE_SECTION_DATA, tlv_len);
  565. set_sec_offset(pieces, IWL_UCODE_REGULAR,
  566. IWL_UCODE_SECTION_DATA,
  567. IWLAGN_RTC_DATA_LOWER_BOUND);
  568. break;
  569. case IWL_UCODE_TLV_INIT:
  570. set_sec_data(pieces, IWL_UCODE_INIT,
  571. IWL_UCODE_SECTION_INST, tlv_data);
  572. set_sec_size(pieces, IWL_UCODE_INIT,
  573. IWL_UCODE_SECTION_INST, tlv_len);
  574. set_sec_offset(pieces, IWL_UCODE_INIT,
  575. IWL_UCODE_SECTION_INST,
  576. IWLAGN_RTC_INST_LOWER_BOUND);
  577. break;
  578. case IWL_UCODE_TLV_INIT_DATA:
  579. set_sec_data(pieces, IWL_UCODE_INIT,
  580. IWL_UCODE_SECTION_DATA, tlv_data);
  581. set_sec_size(pieces, IWL_UCODE_INIT,
  582. IWL_UCODE_SECTION_DATA, tlv_len);
  583. set_sec_offset(pieces, IWL_UCODE_INIT,
  584. IWL_UCODE_SECTION_DATA,
  585. IWLAGN_RTC_DATA_LOWER_BOUND);
  586. break;
  587. case IWL_UCODE_TLV_BOOT:
  588. IWL_ERR(drv, "Found unexpected BOOT ucode\n");
  589. break;
  590. case IWL_UCODE_TLV_PROBE_MAX_LEN:
  591. if (tlv_len != sizeof(u32))
  592. goto invalid_tlv_len;
  593. capa->max_probe_length =
  594. le32_to_cpup((__le32 *)tlv_data);
  595. break;
  596. case IWL_UCODE_TLV_PAN:
  597. if (tlv_len)
  598. goto invalid_tlv_len;
  599. capa->flags |= IWL_UCODE_TLV_FLAGS_PAN;
  600. break;
  601. case IWL_UCODE_TLV_FLAGS:
  602. /* must be at least one u32 */
  603. if (tlv_len < sizeof(u32))
  604. goto invalid_tlv_len;
  605. /* and a proper number of u32s */
  606. if (tlv_len % sizeof(u32))
  607. goto invalid_tlv_len;
  608. /*
  609. * This driver only reads the first u32 as
  610. * right now no more features are defined,
  611. * if that changes then either the driver
  612. * will not work with the new firmware, or
  613. * it'll not take advantage of new features.
  614. */
  615. capa->flags = le32_to_cpup((__le32 *)tlv_data);
  616. break;
  617. case IWL_UCODE_TLV_API_CHANGES_SET:
  618. if (tlv_len != sizeof(struct iwl_ucode_api))
  619. goto invalid_tlv_len;
  620. if (iwl_set_ucode_api_flags(drv, tlv_data, capa))
  621. goto tlv_error;
  622. break;
  623. case IWL_UCODE_TLV_ENABLED_CAPABILITIES:
  624. if (tlv_len != sizeof(struct iwl_ucode_capa))
  625. goto invalid_tlv_len;
  626. if (iwl_set_ucode_capabilities(drv, tlv_data, capa))
  627. goto tlv_error;
  628. break;
  629. case IWL_UCODE_TLV_INIT_EVTLOG_PTR:
  630. if (tlv_len != sizeof(u32))
  631. goto invalid_tlv_len;
  632. pieces->init_evtlog_ptr =
  633. le32_to_cpup((__le32 *)tlv_data);
  634. break;
  635. case IWL_UCODE_TLV_INIT_EVTLOG_SIZE:
  636. if (tlv_len != sizeof(u32))
  637. goto invalid_tlv_len;
  638. pieces->init_evtlog_size =
  639. le32_to_cpup((__le32 *)tlv_data);
  640. break;
  641. case IWL_UCODE_TLV_INIT_ERRLOG_PTR:
  642. if (tlv_len != sizeof(u32))
  643. goto invalid_tlv_len;
  644. pieces->init_errlog_ptr =
  645. le32_to_cpup((__le32 *)tlv_data);
  646. break;
  647. case IWL_UCODE_TLV_RUNT_EVTLOG_PTR:
  648. if (tlv_len != sizeof(u32))
  649. goto invalid_tlv_len;
  650. pieces->inst_evtlog_ptr =
  651. le32_to_cpup((__le32 *)tlv_data);
  652. break;
  653. case IWL_UCODE_TLV_RUNT_EVTLOG_SIZE:
  654. if (tlv_len != sizeof(u32))
  655. goto invalid_tlv_len;
  656. pieces->inst_evtlog_size =
  657. le32_to_cpup((__le32 *)tlv_data);
  658. break;
  659. case IWL_UCODE_TLV_RUNT_ERRLOG_PTR:
  660. if (tlv_len != sizeof(u32))
  661. goto invalid_tlv_len;
  662. pieces->inst_errlog_ptr =
  663. le32_to_cpup((__le32 *)tlv_data);
  664. break;
  665. case IWL_UCODE_TLV_ENHANCE_SENS_TBL:
  666. if (tlv_len)
  667. goto invalid_tlv_len;
  668. drv->fw.enhance_sensitivity_table = true;
  669. break;
  670. case IWL_UCODE_TLV_WOWLAN_INST:
  671. set_sec_data(pieces, IWL_UCODE_WOWLAN,
  672. IWL_UCODE_SECTION_INST, tlv_data);
  673. set_sec_size(pieces, IWL_UCODE_WOWLAN,
  674. IWL_UCODE_SECTION_INST, tlv_len);
  675. set_sec_offset(pieces, IWL_UCODE_WOWLAN,
  676. IWL_UCODE_SECTION_INST,
  677. IWLAGN_RTC_INST_LOWER_BOUND);
  678. break;
  679. case IWL_UCODE_TLV_WOWLAN_DATA:
  680. set_sec_data(pieces, IWL_UCODE_WOWLAN,
  681. IWL_UCODE_SECTION_DATA, tlv_data);
  682. set_sec_size(pieces, IWL_UCODE_WOWLAN,
  683. IWL_UCODE_SECTION_DATA, tlv_len);
  684. set_sec_offset(pieces, IWL_UCODE_WOWLAN,
  685. IWL_UCODE_SECTION_DATA,
  686. IWLAGN_RTC_DATA_LOWER_BOUND);
  687. break;
  688. case IWL_UCODE_TLV_PHY_CALIBRATION_SIZE:
  689. if (tlv_len != sizeof(u32))
  690. goto invalid_tlv_len;
  691. capa->standard_phy_calibration_size =
  692. le32_to_cpup((__le32 *)tlv_data);
  693. break;
  694. case IWL_UCODE_TLV_SEC_RT:
  695. iwl_store_ucode_sec(pieces, tlv_data, IWL_UCODE_REGULAR,
  696. tlv_len);
  697. drv->fw.type = IWL_FW_MVM;
  698. break;
  699. case IWL_UCODE_TLV_SEC_INIT:
  700. iwl_store_ucode_sec(pieces, tlv_data, IWL_UCODE_INIT,
  701. tlv_len);
  702. drv->fw.type = IWL_FW_MVM;
  703. break;
  704. case IWL_UCODE_TLV_SEC_WOWLAN:
  705. iwl_store_ucode_sec(pieces, tlv_data, IWL_UCODE_WOWLAN,
  706. tlv_len);
  707. drv->fw.type = IWL_FW_MVM;
  708. break;
  709. case IWL_UCODE_TLV_DEF_CALIB:
  710. if (tlv_len != sizeof(struct iwl_tlv_calib_data))
  711. goto invalid_tlv_len;
  712. if (iwl_set_default_calib(drv, tlv_data))
  713. goto tlv_error;
  714. break;
  715. case IWL_UCODE_TLV_PHY_SKU:
  716. if (tlv_len != sizeof(u32))
  717. goto invalid_tlv_len;
  718. drv->fw.phy_config = le32_to_cpup((__le32 *)tlv_data);
  719. drv->fw.valid_tx_ant = (drv->fw.phy_config &
  720. FW_PHY_CFG_TX_CHAIN) >>
  721. FW_PHY_CFG_TX_CHAIN_POS;
  722. drv->fw.valid_rx_ant = (drv->fw.phy_config &
  723. FW_PHY_CFG_RX_CHAIN) >>
  724. FW_PHY_CFG_RX_CHAIN_POS;
  725. break;
  726. case IWL_UCODE_TLV_SECURE_SEC_RT:
  727. iwl_store_ucode_sec(pieces, tlv_data, IWL_UCODE_REGULAR,
  728. tlv_len);
  729. drv->fw.type = IWL_FW_MVM;
  730. break;
  731. case IWL_UCODE_TLV_SECURE_SEC_INIT:
  732. iwl_store_ucode_sec(pieces, tlv_data, IWL_UCODE_INIT,
  733. tlv_len);
  734. drv->fw.type = IWL_FW_MVM;
  735. break;
  736. case IWL_UCODE_TLV_SECURE_SEC_WOWLAN:
  737. iwl_store_ucode_sec(pieces, tlv_data, IWL_UCODE_WOWLAN,
  738. tlv_len);
  739. drv->fw.type = IWL_FW_MVM;
  740. break;
  741. case IWL_UCODE_TLV_NUM_OF_CPU:
  742. if (tlv_len != sizeof(u32))
  743. goto invalid_tlv_len;
  744. num_of_cpus =
  745. le32_to_cpup((__le32 *)tlv_data);
  746. if (num_of_cpus == 2) {
  747. drv->fw.img[IWL_UCODE_REGULAR].is_dual_cpus =
  748. true;
  749. drv->fw.img[IWL_UCODE_INIT].is_dual_cpus =
  750. true;
  751. drv->fw.img[IWL_UCODE_WOWLAN].is_dual_cpus =
  752. true;
  753. } else if ((num_of_cpus > 2) || (num_of_cpus < 1)) {
  754. IWL_ERR(drv, "Driver support upto 2 CPUs\n");
  755. return -EINVAL;
  756. }
  757. break;
  758. case IWL_UCODE_TLV_CSCHEME:
  759. if (iwl_store_cscheme(&drv->fw, tlv_data, tlv_len))
  760. goto invalid_tlv_len;
  761. break;
  762. case IWL_UCODE_TLV_N_SCAN_CHANNELS:
  763. if (tlv_len != sizeof(u32))
  764. goto invalid_tlv_len;
  765. capa->n_scan_channels =
  766. le32_to_cpup((__le32 *)tlv_data);
  767. break;
  768. case IWL_UCODE_TLV_FW_VERSION: {
  769. __le32 *ptr = (void *)tlv_data;
  770. u32 major, minor;
  771. u8 local_comp;
  772. if (tlv_len != sizeof(u32) * 3)
  773. goto invalid_tlv_len;
  774. major = le32_to_cpup(ptr++);
  775. minor = le32_to_cpup(ptr++);
  776. local_comp = le32_to_cpup(ptr);
  777. snprintf(drv->fw.fw_version,
  778. sizeof(drv->fw.fw_version), "%u.%u.%u",
  779. major, minor, local_comp);
  780. break;
  781. }
  782. case IWL_UCODE_TLV_FW_DBG_DEST: {
  783. struct iwl_fw_dbg_dest_tlv *dest = (void *)tlv_data;
  784. if (pieces->dbg_dest_tlv) {
  785. IWL_ERR(drv,
  786. "dbg destination ignored, already exists\n");
  787. break;
  788. }
  789. pieces->dbg_dest_tlv = dest;
  790. IWL_INFO(drv, "Found debug destination: %s\n",
  791. get_fw_dbg_mode_string(dest->monitor_mode));
  792. drv->fw.dbg_dest_reg_num =
  793. tlv_len - offsetof(struct iwl_fw_dbg_dest_tlv,
  794. reg_ops);
  795. drv->fw.dbg_dest_reg_num /=
  796. sizeof(drv->fw.dbg_dest_tlv->reg_ops[0]);
  797. break;
  798. }
  799. case IWL_UCODE_TLV_FW_DBG_CONF: {
  800. struct iwl_fw_dbg_conf_tlv *conf = (void *)tlv_data;
  801. if (!pieces->dbg_dest_tlv) {
  802. IWL_ERR(drv,
  803. "Ignore dbg config %d - no destination configured\n",
  804. conf->id);
  805. break;
  806. }
  807. if (conf->id >= ARRAY_SIZE(drv->fw.dbg_conf_tlv)) {
  808. IWL_ERR(drv,
  809. "Skip unknown configuration: %d\n",
  810. conf->id);
  811. break;
  812. }
  813. if (pieces->dbg_conf_tlv[conf->id]) {
  814. IWL_ERR(drv,
  815. "Ignore duplicate dbg config %d\n",
  816. conf->id);
  817. break;
  818. }
  819. if (conf->usniffer)
  820. usniffer_req = true;
  821. IWL_INFO(drv, "Found debug configuration: %d\n",
  822. conf->id);
  823. pieces->dbg_conf_tlv[conf->id] = conf;
  824. pieces->dbg_conf_tlv_len[conf->id] = tlv_len;
  825. break;
  826. }
  827. case IWL_UCODE_TLV_FW_DBG_TRIGGER: {
  828. struct iwl_fw_dbg_trigger_tlv *trigger =
  829. (void *)tlv_data;
  830. u32 trigger_id = le32_to_cpu(trigger->id);
  831. if (trigger_id >= ARRAY_SIZE(drv->fw.dbg_trigger_tlv)) {
  832. IWL_ERR(drv,
  833. "Skip unknown trigger: %u\n",
  834. trigger->id);
  835. break;
  836. }
  837. if (pieces->dbg_trigger_tlv[trigger_id]) {
  838. IWL_ERR(drv,
  839. "Ignore duplicate dbg trigger %u\n",
  840. trigger->id);
  841. break;
  842. }
  843. IWL_INFO(drv, "Found debug trigger: %u\n", trigger->id);
  844. pieces->dbg_trigger_tlv[trigger_id] = trigger;
  845. pieces->dbg_trigger_tlv_len[trigger_id] = tlv_len;
  846. break;
  847. }
  848. case IWL_UCODE_TLV_SEC_RT_USNIFFER:
  849. *usniffer_images = true;
  850. iwl_store_ucode_sec(pieces, tlv_data,
  851. IWL_UCODE_REGULAR_USNIFFER,
  852. tlv_len);
  853. break;
  854. case IWL_UCODE_TLV_PAGING:
  855. if (tlv_len != sizeof(u32))
  856. goto invalid_tlv_len;
  857. paging_mem_size = le32_to_cpup((__le32 *)tlv_data);
  858. IWL_DEBUG_FW(drv,
  859. "Paging: paging enabled (size = %u bytes)\n",
  860. paging_mem_size);
  861. if (paging_mem_size > MAX_PAGING_IMAGE_SIZE) {
  862. IWL_ERR(drv,
  863. "Paging: driver supports up to %lu bytes for paging image\n",
  864. MAX_PAGING_IMAGE_SIZE);
  865. return -EINVAL;
  866. }
  867. if (paging_mem_size & (FW_PAGING_SIZE - 1)) {
  868. IWL_ERR(drv,
  869. "Paging: image isn't multiple %lu\n",
  870. FW_PAGING_SIZE);
  871. return -EINVAL;
  872. }
  873. drv->fw.img[IWL_UCODE_REGULAR].paging_mem_size =
  874. paging_mem_size;
  875. usniffer_img = IWL_UCODE_REGULAR_USNIFFER;
  876. drv->fw.img[usniffer_img].paging_mem_size =
  877. paging_mem_size;
  878. break;
  879. case IWL_UCODE_TLV_SDIO_ADMA_ADDR:
  880. if (tlv_len != sizeof(u32))
  881. goto invalid_tlv_len;
  882. drv->fw.sdio_adma_addr =
  883. le32_to_cpup((__le32 *)tlv_data);
  884. break;
  885. case IWL_UCODE_TLV_FW_GSCAN_CAPA:
  886. /*
  887. * Don't return an error in case of a shorter tlv_len
  888. * to enable loading of FW that has an old format
  889. * of GSCAN capabilities TLV.
  890. */
  891. if (tlv_len < sizeof(struct iwl_fw_gscan_capabilities))
  892. break;
  893. iwl_store_gscan_capa(&drv->fw, tlv_data, tlv_len);
  894. gscan_capa = true;
  895. break;
  896. case IWL_UCODE_TLV_FW_MEM_SEG: {
  897. struct iwl_fw_dbg_mem_seg_tlv *dbg_mem =
  898. (void *)tlv_data;
  899. u32 type;
  900. if (tlv_len != (sizeof(*dbg_mem)))
  901. goto invalid_tlv_len;
  902. type = le32_to_cpu(dbg_mem->data_type);
  903. drv->fw.dbg_dynamic_mem = true;
  904. if (type >= ARRAY_SIZE(drv->fw.dbg_mem_tlv)) {
  905. IWL_ERR(drv,
  906. "Skip unknown dbg mem segment: %u\n",
  907. dbg_mem->data_type);
  908. break;
  909. }
  910. if (pieces->dbg_mem_tlv[type]) {
  911. IWL_ERR(drv,
  912. "Ignore duplicate mem segment: %u\n",
  913. dbg_mem->data_type);
  914. break;
  915. }
  916. IWL_DEBUG_INFO(drv, "Found debug memory segment: %u\n",
  917. dbg_mem->data_type);
  918. pieces->dbg_mem_tlv[type] = dbg_mem;
  919. break;
  920. }
  921. default:
  922. IWL_DEBUG_INFO(drv, "unknown TLV: %d\n", tlv_type);
  923. break;
  924. }
  925. }
  926. if (!fw_has_capa(capa, IWL_UCODE_TLV_CAPA_USNIFFER_UNIFIED) &&
  927. usniffer_req && !*usniffer_images) {
  928. IWL_ERR(drv,
  929. "user selected to work with usniffer but usniffer image isn't available in ucode package\n");
  930. return -EINVAL;
  931. }
  932. if (len) {
  933. IWL_ERR(drv, "invalid TLV after parsing: %zd\n", len);
  934. iwl_print_hex_dump(drv, IWL_DL_FW, (u8 *)data, len);
  935. return -EINVAL;
  936. }
  937. /*
  938. * If ucode advertises that it supports GSCAN but GSCAN
  939. * capabilities TLV is not present, or if it has an old format,
  940. * warn and continue without GSCAN.
  941. */
  942. if (fw_has_capa(capa, IWL_UCODE_TLV_CAPA_GSCAN_SUPPORT) &&
  943. !gscan_capa) {
  944. IWL_DEBUG_INFO(drv,
  945. "GSCAN is supported but capabilities TLV is unavailable\n");
  946. __clear_bit((__force long)IWL_UCODE_TLV_CAPA_GSCAN_SUPPORT,
  947. capa->_capa);
  948. }
  949. return 0;
  950. invalid_tlv_len:
  951. IWL_ERR(drv, "TLV %d has invalid size: %u\n", tlv_type, tlv_len);
  952. tlv_error:
  953. iwl_print_hex_dump(drv, IWL_DL_FW, tlv_data, tlv_len);
  954. return -EINVAL;
  955. }
  956. static int iwl_alloc_ucode(struct iwl_drv *drv,
  957. struct iwl_firmware_pieces *pieces,
  958. enum iwl_ucode_type type)
  959. {
  960. int i;
  961. for (i = 0;
  962. i < IWL_UCODE_SECTION_MAX && get_sec_size(pieces, type, i);
  963. i++)
  964. if (iwl_alloc_fw_desc(drv, &(drv->fw.img[type].sec[i]),
  965. get_sec(pieces, type, i)))
  966. return -ENOMEM;
  967. return 0;
  968. }
  969. static int validate_sec_sizes(struct iwl_drv *drv,
  970. struct iwl_firmware_pieces *pieces,
  971. const struct iwl_cfg *cfg)
  972. {
  973. IWL_DEBUG_INFO(drv, "f/w package hdr runtime inst size = %Zd\n",
  974. get_sec_size(pieces, IWL_UCODE_REGULAR,
  975. IWL_UCODE_SECTION_INST));
  976. IWL_DEBUG_INFO(drv, "f/w package hdr runtime data size = %Zd\n",
  977. get_sec_size(pieces, IWL_UCODE_REGULAR,
  978. IWL_UCODE_SECTION_DATA));
  979. IWL_DEBUG_INFO(drv, "f/w package hdr init inst size = %Zd\n",
  980. get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST));
  981. IWL_DEBUG_INFO(drv, "f/w package hdr init data size = %Zd\n",
  982. get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA));
  983. /* Verify that uCode images will fit in card's SRAM. */
  984. if (get_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_INST) >
  985. cfg->max_inst_size) {
  986. IWL_ERR(drv, "uCode instr len %Zd too large to fit in\n",
  987. get_sec_size(pieces, IWL_UCODE_REGULAR,
  988. IWL_UCODE_SECTION_INST));
  989. return -1;
  990. }
  991. if (get_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_DATA) >
  992. cfg->max_data_size) {
  993. IWL_ERR(drv, "uCode data len %Zd too large to fit in\n",
  994. get_sec_size(pieces, IWL_UCODE_REGULAR,
  995. IWL_UCODE_SECTION_DATA));
  996. return -1;
  997. }
  998. if (get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST) >
  999. cfg->max_inst_size) {
  1000. IWL_ERR(drv, "uCode init instr len %Zd too large to fit in\n",
  1001. get_sec_size(pieces, IWL_UCODE_INIT,
  1002. IWL_UCODE_SECTION_INST));
  1003. return -1;
  1004. }
  1005. if (get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA) >
  1006. cfg->max_data_size) {
  1007. IWL_ERR(drv, "uCode init data len %Zd too large to fit in\n",
  1008. get_sec_size(pieces, IWL_UCODE_REGULAR,
  1009. IWL_UCODE_SECTION_DATA));
  1010. return -1;
  1011. }
  1012. return 0;
  1013. }
  1014. static struct iwl_op_mode *
  1015. _iwl_op_mode_start(struct iwl_drv *drv, struct iwlwifi_opmode_table *op)
  1016. {
  1017. const struct iwl_op_mode_ops *ops = op->ops;
  1018. struct dentry *dbgfs_dir = NULL;
  1019. struct iwl_op_mode *op_mode = NULL;
  1020. #ifdef CONFIG_IWLWIFI_DEBUGFS
  1021. drv->dbgfs_op_mode = debugfs_create_dir(op->name,
  1022. drv->dbgfs_drv);
  1023. if (!drv->dbgfs_op_mode) {
  1024. IWL_ERR(drv,
  1025. "failed to create opmode debugfs directory\n");
  1026. return op_mode;
  1027. }
  1028. dbgfs_dir = drv->dbgfs_op_mode;
  1029. #endif
  1030. op_mode = ops->start(drv->trans, drv->cfg, &drv->fw, dbgfs_dir);
  1031. #ifdef CONFIG_IWLWIFI_DEBUGFS
  1032. if (!op_mode) {
  1033. debugfs_remove_recursive(drv->dbgfs_op_mode);
  1034. drv->dbgfs_op_mode = NULL;
  1035. }
  1036. #endif
  1037. return op_mode;
  1038. }
  1039. static void _iwl_op_mode_stop(struct iwl_drv *drv)
  1040. {
  1041. /* op_mode can be NULL if its start failed */
  1042. if (drv->op_mode) {
  1043. iwl_op_mode_stop(drv->op_mode);
  1044. drv->op_mode = NULL;
  1045. #ifdef CONFIG_IWLWIFI_DEBUGFS
  1046. debugfs_remove_recursive(drv->dbgfs_op_mode);
  1047. drv->dbgfs_op_mode = NULL;
  1048. #endif
  1049. }
  1050. }
  1051. /**
  1052. * iwl_req_fw_callback - callback when firmware was loaded
  1053. *
  1054. * If loaded successfully, copies the firmware into buffers
  1055. * for the card to fetch (via DMA).
  1056. */
  1057. static void iwl_req_fw_callback(const struct firmware *ucode_raw, void *context)
  1058. {
  1059. struct iwl_drv *drv = context;
  1060. struct iwl_fw *fw = &drv->fw;
  1061. struct iwl_ucode_header *ucode;
  1062. struct iwlwifi_opmode_table *op;
  1063. int err;
  1064. struct iwl_firmware_pieces *pieces;
  1065. const unsigned int api_max = drv->cfg->ucode_api_max;
  1066. const unsigned int api_min = drv->cfg->ucode_api_min;
  1067. size_t trigger_tlv_sz[FW_DBG_TRIGGER_MAX];
  1068. u32 api_ver;
  1069. int i;
  1070. bool load_module = false;
  1071. bool usniffer_images = false;
  1072. fw->ucode_capa.max_probe_length = IWL_DEFAULT_MAX_PROBE_LENGTH;
  1073. fw->ucode_capa.standard_phy_calibration_size =
  1074. IWL_DEFAULT_STANDARD_PHY_CALIBRATE_TBL_SIZE;
  1075. fw->ucode_capa.n_scan_channels = IWL_DEFAULT_SCAN_CHANNELS;
  1076. pieces = kzalloc(sizeof(*pieces), GFP_KERNEL);
  1077. if (!pieces)
  1078. return;
  1079. if (!ucode_raw)
  1080. goto try_again;
  1081. IWL_DEBUG_INFO(drv, "Loaded firmware file '%s' (%zd bytes).\n",
  1082. drv->firmware_name, ucode_raw->size);
  1083. /* Make sure that we got at least the API version number */
  1084. if (ucode_raw->size < 4) {
  1085. IWL_ERR(drv, "File size way too small!\n");
  1086. goto try_again;
  1087. }
  1088. /* Data from ucode file: header followed by uCode images */
  1089. ucode = (struct iwl_ucode_header *)ucode_raw->data;
  1090. if (ucode->ver)
  1091. err = iwl_parse_v1_v2_firmware(drv, ucode_raw, pieces);
  1092. else
  1093. err = iwl_parse_tlv_firmware(drv, ucode_raw, pieces,
  1094. &fw->ucode_capa, &usniffer_images);
  1095. if (err)
  1096. goto try_again;
  1097. if (fw_has_api(&drv->fw.ucode_capa, IWL_UCODE_TLV_API_NEW_VERSION))
  1098. api_ver = drv->fw.ucode_ver;
  1099. else
  1100. api_ver = IWL_UCODE_API(drv->fw.ucode_ver);
  1101. /*
  1102. * api_ver should match the api version forming part of the
  1103. * firmware filename ... but we don't check for that and only rely
  1104. * on the API version read from firmware header from here on forward
  1105. */
  1106. if (api_ver < api_min || api_ver > api_max) {
  1107. IWL_ERR(drv,
  1108. "Driver unable to support your firmware API. "
  1109. "Driver supports v%u, firmware is v%u.\n",
  1110. api_max, api_ver);
  1111. goto try_again;
  1112. }
  1113. /*
  1114. * In mvm uCode there is no difference between data and instructions
  1115. * sections.
  1116. */
  1117. if (fw->type == IWL_FW_DVM && validate_sec_sizes(drv, pieces, drv->cfg))
  1118. goto try_again;
  1119. /* Allocate ucode buffers for card's bus-master loading ... */
  1120. /* Runtime instructions and 2 copies of data:
  1121. * 1) unmodified from disk
  1122. * 2) backup cache for save/restore during power-downs */
  1123. for (i = 0; i < IWL_UCODE_TYPE_MAX; i++)
  1124. if (iwl_alloc_ucode(drv, pieces, i))
  1125. goto out_free_fw;
  1126. if (pieces->dbg_dest_tlv) {
  1127. drv->fw.dbg_dest_tlv =
  1128. kmemdup(pieces->dbg_dest_tlv,
  1129. sizeof(*pieces->dbg_dest_tlv) +
  1130. sizeof(pieces->dbg_dest_tlv->reg_ops[0]) *
  1131. drv->fw.dbg_dest_reg_num, GFP_KERNEL);
  1132. if (!drv->fw.dbg_dest_tlv)
  1133. goto out_free_fw;
  1134. }
  1135. for (i = 0; i < ARRAY_SIZE(drv->fw.dbg_conf_tlv); i++) {
  1136. if (pieces->dbg_conf_tlv[i]) {
  1137. drv->fw.dbg_conf_tlv_len[i] =
  1138. pieces->dbg_conf_tlv_len[i];
  1139. drv->fw.dbg_conf_tlv[i] =
  1140. kmemdup(pieces->dbg_conf_tlv[i],
  1141. drv->fw.dbg_conf_tlv_len[i],
  1142. GFP_KERNEL);
  1143. if (!drv->fw.dbg_conf_tlv[i])
  1144. goto out_free_fw;
  1145. }
  1146. }
  1147. memset(&trigger_tlv_sz, 0xff, sizeof(trigger_tlv_sz));
  1148. trigger_tlv_sz[FW_DBG_TRIGGER_MISSED_BEACONS] =
  1149. sizeof(struct iwl_fw_dbg_trigger_missed_bcon);
  1150. trigger_tlv_sz[FW_DBG_TRIGGER_CHANNEL_SWITCH] = 0;
  1151. trigger_tlv_sz[FW_DBG_TRIGGER_FW_NOTIF] =
  1152. sizeof(struct iwl_fw_dbg_trigger_cmd);
  1153. trigger_tlv_sz[FW_DBG_TRIGGER_MLME] =
  1154. sizeof(struct iwl_fw_dbg_trigger_mlme);
  1155. trigger_tlv_sz[FW_DBG_TRIGGER_STATS] =
  1156. sizeof(struct iwl_fw_dbg_trigger_stats);
  1157. trigger_tlv_sz[FW_DBG_TRIGGER_RSSI] =
  1158. sizeof(struct iwl_fw_dbg_trigger_low_rssi);
  1159. trigger_tlv_sz[FW_DBG_TRIGGER_TXQ_TIMERS] =
  1160. sizeof(struct iwl_fw_dbg_trigger_txq_timer);
  1161. trigger_tlv_sz[FW_DBG_TRIGGER_TIME_EVENT] =
  1162. sizeof(struct iwl_fw_dbg_trigger_time_event);
  1163. trigger_tlv_sz[FW_DBG_TRIGGER_BA] =
  1164. sizeof(struct iwl_fw_dbg_trigger_ba);
  1165. trigger_tlv_sz[FW_DBG_TRIGGER_TDLS] =
  1166. sizeof(struct iwl_fw_dbg_trigger_tdls);
  1167. for (i = 0; i < ARRAY_SIZE(drv->fw.dbg_trigger_tlv); i++) {
  1168. if (pieces->dbg_trigger_tlv[i]) {
  1169. /*
  1170. * If the trigger isn't long enough, WARN and exit.
  1171. * Someone is trying to debug something and he won't
  1172. * be able to catch the bug he is trying to chase.
  1173. * We'd better be noisy to be sure he knows what's
  1174. * going on.
  1175. */
  1176. if (WARN_ON(pieces->dbg_trigger_tlv_len[i] <
  1177. (trigger_tlv_sz[i] +
  1178. sizeof(struct iwl_fw_dbg_trigger_tlv))))
  1179. goto out_free_fw;
  1180. drv->fw.dbg_trigger_tlv_len[i] =
  1181. pieces->dbg_trigger_tlv_len[i];
  1182. drv->fw.dbg_trigger_tlv[i] =
  1183. kmemdup(pieces->dbg_trigger_tlv[i],
  1184. drv->fw.dbg_trigger_tlv_len[i],
  1185. GFP_KERNEL);
  1186. if (!drv->fw.dbg_trigger_tlv[i])
  1187. goto out_free_fw;
  1188. }
  1189. }
  1190. for (i = 0; i < ARRAY_SIZE(drv->fw.dbg_mem_tlv); i++) {
  1191. if (pieces->dbg_mem_tlv[i]) {
  1192. drv->fw.dbg_mem_tlv[i] =
  1193. kmemdup(pieces->dbg_mem_tlv[i],
  1194. sizeof(*drv->fw.dbg_mem_tlv[i]),
  1195. GFP_KERNEL);
  1196. if (!drv->fw.dbg_mem_tlv[i])
  1197. goto out_free_fw;
  1198. }
  1199. }
  1200. /* Now that we can no longer fail, copy information */
  1201. /*
  1202. * The (size - 16) / 12 formula is based on the information recorded
  1203. * for each event, which is of mode 1 (including timestamp) for all
  1204. * new microcodes that include this information.
  1205. */
  1206. fw->init_evtlog_ptr = pieces->init_evtlog_ptr;
  1207. if (pieces->init_evtlog_size)
  1208. fw->init_evtlog_size = (pieces->init_evtlog_size - 16)/12;
  1209. else
  1210. fw->init_evtlog_size =
  1211. drv->cfg->base_params->max_event_log_size;
  1212. fw->init_errlog_ptr = pieces->init_errlog_ptr;
  1213. fw->inst_evtlog_ptr = pieces->inst_evtlog_ptr;
  1214. if (pieces->inst_evtlog_size)
  1215. fw->inst_evtlog_size = (pieces->inst_evtlog_size - 16)/12;
  1216. else
  1217. fw->inst_evtlog_size =
  1218. drv->cfg->base_params->max_event_log_size;
  1219. fw->inst_errlog_ptr = pieces->inst_errlog_ptr;
  1220. /*
  1221. * figure out the offset of chain noise reset and gain commands
  1222. * base on the size of standard phy calibration commands table size
  1223. */
  1224. if (fw->ucode_capa.standard_phy_calibration_size >
  1225. IWL_MAX_PHY_CALIBRATE_TBL_SIZE)
  1226. fw->ucode_capa.standard_phy_calibration_size =
  1227. IWL_MAX_STANDARD_PHY_CALIBRATE_TBL_SIZE;
  1228. /* We have our copies now, allow OS release its copies */
  1229. release_firmware(ucode_raw);
  1230. mutex_lock(&iwlwifi_opmode_table_mtx);
  1231. switch (fw->type) {
  1232. case IWL_FW_DVM:
  1233. op = &iwlwifi_opmode_table[DVM_OP_MODE];
  1234. break;
  1235. default:
  1236. WARN(1, "Invalid fw type %d\n", fw->type);
  1237. case IWL_FW_MVM:
  1238. op = &iwlwifi_opmode_table[MVM_OP_MODE];
  1239. break;
  1240. }
  1241. IWL_INFO(drv, "loaded firmware version %s op_mode %s\n",
  1242. drv->fw.fw_version, op->name);
  1243. /* add this device to the list of devices using this op_mode */
  1244. list_add_tail(&drv->list, &op->drv);
  1245. if (op->ops) {
  1246. drv->op_mode = _iwl_op_mode_start(drv, op);
  1247. if (!drv->op_mode) {
  1248. mutex_unlock(&iwlwifi_opmode_table_mtx);
  1249. goto out_unbind;
  1250. }
  1251. } else {
  1252. load_module = true;
  1253. }
  1254. mutex_unlock(&iwlwifi_opmode_table_mtx);
  1255. /*
  1256. * Complete the firmware request last so that
  1257. * a driver unbind (stop) doesn't run while we
  1258. * are doing the start() above.
  1259. */
  1260. complete(&drv->request_firmware_complete);
  1261. /*
  1262. * Load the module last so we don't block anything
  1263. * else from proceeding if the module fails to load
  1264. * or hangs loading.
  1265. */
  1266. if (load_module) {
  1267. err = request_module("%s", op->name);
  1268. #ifdef CONFIG_IWLWIFI_OPMODE_MODULAR
  1269. if (err)
  1270. IWL_ERR(drv,
  1271. "failed to load module %s (error %d), is dynamic loading enabled?\n",
  1272. op->name, err);
  1273. #endif
  1274. }
  1275. kfree(pieces);
  1276. return;
  1277. try_again:
  1278. /* try next, if any */
  1279. release_firmware(ucode_raw);
  1280. if (iwl_request_firmware(drv, false))
  1281. goto out_unbind;
  1282. kfree(pieces);
  1283. return;
  1284. out_free_fw:
  1285. IWL_ERR(drv, "failed to allocate pci memory\n");
  1286. iwl_dealloc_ucode(drv);
  1287. release_firmware(ucode_raw);
  1288. out_unbind:
  1289. kfree(pieces);
  1290. complete(&drv->request_firmware_complete);
  1291. device_release_driver(drv->trans->dev);
  1292. }
  1293. struct iwl_drv *iwl_drv_start(struct iwl_trans *trans,
  1294. const struct iwl_cfg *cfg)
  1295. {
  1296. struct iwl_drv *drv;
  1297. int ret;
  1298. drv = kzalloc(sizeof(*drv), GFP_KERNEL);
  1299. if (!drv) {
  1300. ret = -ENOMEM;
  1301. goto err;
  1302. }
  1303. drv->trans = trans;
  1304. drv->dev = trans->dev;
  1305. drv->cfg = cfg;
  1306. init_completion(&drv->request_firmware_complete);
  1307. INIT_LIST_HEAD(&drv->list);
  1308. #ifdef CONFIG_IWLWIFI_DEBUGFS
  1309. /* Create the device debugfs entries. */
  1310. drv->dbgfs_drv = debugfs_create_dir(dev_name(trans->dev),
  1311. iwl_dbgfs_root);
  1312. if (!drv->dbgfs_drv) {
  1313. IWL_ERR(drv, "failed to create debugfs directory\n");
  1314. ret = -ENOMEM;
  1315. goto err_free_drv;
  1316. }
  1317. /* Create transport layer debugfs dir */
  1318. drv->trans->dbgfs_dir = debugfs_create_dir("trans", drv->dbgfs_drv);
  1319. if (!drv->trans->dbgfs_dir) {
  1320. IWL_ERR(drv, "failed to create transport debugfs directory\n");
  1321. ret = -ENOMEM;
  1322. goto err_free_dbgfs;
  1323. }
  1324. #endif
  1325. ret = iwl_request_firmware(drv, true);
  1326. if (ret) {
  1327. IWL_ERR(trans, "Couldn't request the fw\n");
  1328. goto err_fw;
  1329. }
  1330. return drv;
  1331. err_fw:
  1332. #ifdef CONFIG_IWLWIFI_DEBUGFS
  1333. err_free_dbgfs:
  1334. debugfs_remove_recursive(drv->dbgfs_drv);
  1335. err_free_drv:
  1336. #endif
  1337. kfree(drv);
  1338. err:
  1339. return ERR_PTR(ret);
  1340. }
  1341. void iwl_drv_stop(struct iwl_drv *drv)
  1342. {
  1343. wait_for_completion(&drv->request_firmware_complete);
  1344. _iwl_op_mode_stop(drv);
  1345. iwl_dealloc_ucode(drv);
  1346. mutex_lock(&iwlwifi_opmode_table_mtx);
  1347. /*
  1348. * List is empty (this item wasn't added)
  1349. * when firmware loading failed -- in that
  1350. * case we can't remove it from any list.
  1351. */
  1352. if (!list_empty(&drv->list))
  1353. list_del(&drv->list);
  1354. mutex_unlock(&iwlwifi_opmode_table_mtx);
  1355. #ifdef CONFIG_IWLWIFI_DEBUGFS
  1356. debugfs_remove_recursive(drv->dbgfs_drv);
  1357. #endif
  1358. kfree(drv);
  1359. }
  1360. /* shared module parameters */
  1361. struct iwl_mod_params iwlwifi_mod_params = {
  1362. .restart_fw = true,
  1363. .bt_coex_active = true,
  1364. .power_level = IWL_POWER_INDEX_1,
  1365. .d0i3_disable = true,
  1366. .d0i3_entry_delay = 1000,
  1367. .uapsd_disable = IWL_DISABLE_UAPSD_BSS | IWL_DISABLE_UAPSD_P2P_CLIENT,
  1368. /* the rest are 0 by default */
  1369. };
  1370. IWL_EXPORT_SYMBOL(iwlwifi_mod_params);
  1371. int iwl_opmode_register(const char *name, const struct iwl_op_mode_ops *ops)
  1372. {
  1373. int i;
  1374. struct iwl_drv *drv;
  1375. struct iwlwifi_opmode_table *op;
  1376. mutex_lock(&iwlwifi_opmode_table_mtx);
  1377. for (i = 0; i < ARRAY_SIZE(iwlwifi_opmode_table); i++) {
  1378. op = &iwlwifi_opmode_table[i];
  1379. if (strcmp(op->name, name))
  1380. continue;
  1381. op->ops = ops;
  1382. /* TODO: need to handle exceptional case */
  1383. list_for_each_entry(drv, &op->drv, list)
  1384. drv->op_mode = _iwl_op_mode_start(drv, op);
  1385. mutex_unlock(&iwlwifi_opmode_table_mtx);
  1386. return 0;
  1387. }
  1388. mutex_unlock(&iwlwifi_opmode_table_mtx);
  1389. return -EIO;
  1390. }
  1391. IWL_EXPORT_SYMBOL(iwl_opmode_register);
  1392. void iwl_opmode_deregister(const char *name)
  1393. {
  1394. int i;
  1395. struct iwl_drv *drv;
  1396. mutex_lock(&iwlwifi_opmode_table_mtx);
  1397. for (i = 0; i < ARRAY_SIZE(iwlwifi_opmode_table); i++) {
  1398. if (strcmp(iwlwifi_opmode_table[i].name, name))
  1399. continue;
  1400. iwlwifi_opmode_table[i].ops = NULL;
  1401. /* call the stop routine for all devices */
  1402. list_for_each_entry(drv, &iwlwifi_opmode_table[i].drv, list)
  1403. _iwl_op_mode_stop(drv);
  1404. mutex_unlock(&iwlwifi_opmode_table_mtx);
  1405. return;
  1406. }
  1407. mutex_unlock(&iwlwifi_opmode_table_mtx);
  1408. }
  1409. IWL_EXPORT_SYMBOL(iwl_opmode_deregister);
  1410. static int __init iwl_drv_init(void)
  1411. {
  1412. int i;
  1413. mutex_init(&iwlwifi_opmode_table_mtx);
  1414. for (i = 0; i < ARRAY_SIZE(iwlwifi_opmode_table); i++)
  1415. INIT_LIST_HEAD(&iwlwifi_opmode_table[i].drv);
  1416. pr_info(DRV_DESCRIPTION "\n");
  1417. pr_info(DRV_COPYRIGHT "\n");
  1418. #ifdef CONFIG_IWLWIFI_DEBUGFS
  1419. /* Create the root of iwlwifi debugfs subsystem. */
  1420. iwl_dbgfs_root = debugfs_create_dir(DRV_NAME, NULL);
  1421. if (!iwl_dbgfs_root)
  1422. return -EFAULT;
  1423. #endif
  1424. return iwl_pci_register_driver();
  1425. }
  1426. module_init(iwl_drv_init);
  1427. static void __exit iwl_drv_exit(void)
  1428. {
  1429. iwl_pci_unregister_driver();
  1430. #ifdef CONFIG_IWLWIFI_DEBUGFS
  1431. debugfs_remove_recursive(iwl_dbgfs_root);
  1432. #endif
  1433. }
  1434. module_exit(iwl_drv_exit);
  1435. #ifdef CONFIG_IWLWIFI_DEBUG
  1436. module_param_named(debug, iwlwifi_mod_params.debug_level, uint,
  1437. S_IRUGO | S_IWUSR);
  1438. MODULE_PARM_DESC(debug, "debug output mask");
  1439. #endif
  1440. module_param_named(swcrypto, iwlwifi_mod_params.sw_crypto, int, S_IRUGO);
  1441. MODULE_PARM_DESC(swcrypto, "using crypto in software (default 0 [hardware])");
  1442. module_param_named(11n_disable, iwlwifi_mod_params.disable_11n, uint, S_IRUGO);
  1443. MODULE_PARM_DESC(11n_disable,
  1444. "disable 11n functionality, bitmap: 1: full, 2: disable agg TX, 4: disable agg RX, 8 enable agg TX");
  1445. module_param_named(amsdu_size, iwlwifi_mod_params.amsdu_size,
  1446. int, S_IRUGO);
  1447. MODULE_PARM_DESC(amsdu_size,
  1448. "amsdu size 0: 12K for multi Rx queue devices, 4K for other devices 1:4K 2:8K 3:12K (default 0)");
  1449. module_param_named(fw_restart, iwlwifi_mod_params.restart_fw, bool, S_IRUGO);
  1450. MODULE_PARM_DESC(fw_restart, "restart firmware in case of error (default true)");
  1451. module_param_named(antenna_coupling, iwlwifi_mod_params.ant_coupling,
  1452. int, S_IRUGO);
  1453. MODULE_PARM_DESC(antenna_coupling,
  1454. "specify antenna coupling in dB (default: 0 dB)");
  1455. module_param_named(nvm_file, iwlwifi_mod_params.nvm_file, charp, S_IRUGO);
  1456. MODULE_PARM_DESC(nvm_file, "NVM file name");
  1457. module_param_named(d0i3_disable, iwlwifi_mod_params.d0i3_disable,
  1458. bool, S_IRUGO);
  1459. MODULE_PARM_DESC(d0i3_disable, "disable d0i3 functionality (default: Y)");
  1460. module_param_named(lar_disable, iwlwifi_mod_params.lar_disable,
  1461. bool, S_IRUGO);
  1462. MODULE_PARM_DESC(lar_disable, "disable LAR functionality (default: N)");
  1463. module_param_named(uapsd_disable, iwlwifi_mod_params.uapsd_disable,
  1464. uint, S_IRUGO | S_IWUSR);
  1465. MODULE_PARM_DESC(uapsd_disable,
  1466. "disable U-APSD functionality bitmap 1: BSS 2: P2P Client (default: 3)");
  1467. /*
  1468. * set bt_coex_active to true, uCode will do kill/defer
  1469. * every time the priority line is asserted (BT is sending signals on the
  1470. * priority line in the PCIx).
  1471. * set bt_coex_active to false, uCode will ignore the BT activity and
  1472. * perform the normal operation
  1473. *
  1474. * User might experience transmit issue on some platform due to WiFi/BT
  1475. * co-exist problem. The possible behaviors are:
  1476. * Able to scan and finding all the available AP
  1477. * Not able to associate with any AP
  1478. * On those platforms, WiFi communication can be restored by set
  1479. * "bt_coex_active" module parameter to "false"
  1480. *
  1481. * default: bt_coex_active = true (BT_COEX_ENABLE)
  1482. */
  1483. module_param_named(bt_coex_active, iwlwifi_mod_params.bt_coex_active,
  1484. bool, S_IRUGO);
  1485. MODULE_PARM_DESC(bt_coex_active, "enable wifi/bt co-exist (default: enable)");
  1486. module_param_named(led_mode, iwlwifi_mod_params.led_mode, int, S_IRUGO);
  1487. MODULE_PARM_DESC(led_mode, "0=system default, "
  1488. "1=On(RF On)/Off(RF Off), 2=blinking, 3=Off (default: 0)");
  1489. module_param_named(power_save, iwlwifi_mod_params.power_save,
  1490. bool, S_IRUGO);
  1491. MODULE_PARM_DESC(power_save,
  1492. "enable WiFi power management (default: disable)");
  1493. module_param_named(power_level, iwlwifi_mod_params.power_level,
  1494. int, S_IRUGO);
  1495. MODULE_PARM_DESC(power_level,
  1496. "default power save level (range from 1 - 5, default: 1)");
  1497. module_param_named(fw_monitor, iwlwifi_mod_params.fw_monitor, bool, S_IRUGO);
  1498. MODULE_PARM_DESC(fw_monitor,
  1499. "firmware monitor - to debug FW (default: false - needs lots of memory)");
  1500. module_param_named(d0i3_timeout, iwlwifi_mod_params.d0i3_entry_delay,
  1501. uint, S_IRUGO);
  1502. MODULE_PARM_DESC(d0i3_timeout, "Timeout to D0i3 entry when idle (ms)");
  1503. module_param_named(disable_11ac, iwlwifi_mod_params.disable_11ac, bool,
  1504. S_IRUGO);
  1505. MODULE_PARM_DESC(disable_11ac, "Disable VHT capabilities (default: false)");