iwl-drv.c 50 KB

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