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