iwl-drv.c 49 KB

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