iwl-drv.c 50 KB

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