iwl-drv.c 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262
  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 - 2012 Intel Corporation. All rights reserved.
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of version 2 of the GNU General Public License as
  12. * published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful, but
  15. * WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
  22. * USA
  23. *
  24. * The full GNU General Public License is included in this distribution
  25. * in the file called LICENSE.GPL.
  26. *
  27. * Contact Information:
  28. * Intel Linux Wireless <ilw@linux.intel.com>
  29. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  30. *
  31. * BSD LICENSE
  32. *
  33. * Copyright(c) 2005 - 2012 Intel Corporation. All rights reserved.
  34. * All rights reserved.
  35. *
  36. * Redistribution and use in source and binary forms, with or without
  37. * modification, are permitted provided that the following conditions
  38. * are met:
  39. *
  40. * * Redistributions of source code must retain the above copyright
  41. * notice, this list of conditions and the following disclaimer.
  42. * * Redistributions in binary form must reproduce the above copyright
  43. * notice, this list of conditions and the following disclaimer in
  44. * the documentation and/or other materials provided with the
  45. * distribution.
  46. * * Neither the name Intel Corporation nor the names of its
  47. * contributors may be used to endorse or promote products derived
  48. * from this software without specific prior written permission.
  49. *
  50. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  51. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  52. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  53. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  54. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  55. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  56. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  57. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  58. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  59. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  60. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  61. *
  62. *****************************************************************************/
  63. #include <linux/completion.h>
  64. #include <linux/dma-mapping.h>
  65. #include <linux/firmware.h>
  66. #include <linux/module.h>
  67. #include "iwl-drv.h"
  68. #include "iwl-debug.h"
  69. #include "iwl-trans.h"
  70. #include "iwl-op-mode.h"
  71. #include "iwl-agn-hw.h"
  72. #include "iwl-fw.h"
  73. #include "iwl-config.h"
  74. #include "iwl-modparams.h"
  75. /* private includes */
  76. #include "iwl-fw-file.h"
  77. /******************************************************************************
  78. *
  79. * module boiler plate
  80. *
  81. ******************************************************************************/
  82. /*
  83. * module name, copyright, version, etc.
  84. */
  85. #define DRV_DESCRIPTION "Intel(R) Wireless WiFi driver for Linux"
  86. #ifdef CONFIG_IWLWIFI_DEBUG
  87. #define VD "d"
  88. #else
  89. #define VD
  90. #endif
  91. #define DRV_VERSION IWLWIFI_VERSION VD
  92. MODULE_DESCRIPTION(DRV_DESCRIPTION);
  93. MODULE_VERSION(DRV_VERSION);
  94. MODULE_AUTHOR(DRV_COPYRIGHT " " DRV_AUTHOR);
  95. MODULE_LICENSE("GPL");
  96. #ifdef CONFIG_IWLWIFI_DEBUGFS
  97. static struct dentry *iwl_dbgfs_root;
  98. #endif
  99. /**
  100. * struct iwl_drv - drv common data
  101. * @list: list of drv structures using this opmode
  102. * @fw: the iwl_fw structure
  103. * @op_mode: the running op_mode
  104. * @trans: transport layer
  105. * @dev: for debug prints only
  106. * @cfg: configuration struct
  107. * @fw_index: firmware revision to try loading
  108. * @firmware_name: composite filename of ucode file to load
  109. * @request_firmware_complete: the firmware has been obtained from user space
  110. */
  111. struct iwl_drv {
  112. struct list_head list;
  113. struct iwl_fw fw;
  114. struct iwl_op_mode *op_mode;
  115. struct iwl_trans *trans;
  116. struct device *dev;
  117. const struct iwl_cfg *cfg;
  118. int fw_index; /* firmware we're trying to load */
  119. char firmware_name[25]; /* name of firmware file to load */
  120. struct completion request_firmware_complete;
  121. #ifdef CONFIG_IWLWIFI_DEBUGFS
  122. struct dentry *dbgfs_drv;
  123. struct dentry *dbgfs_trans;
  124. struct dentry *dbgfs_op_mode;
  125. #endif
  126. };
  127. #define DVM_OP_MODE 0
  128. #define MVM_OP_MODE 1
  129. /* Protects the table contents, i.e. the ops pointer & drv list */
  130. static struct mutex iwlwifi_opmode_table_mtx;
  131. static struct iwlwifi_opmode_table {
  132. const char *name; /* name: iwldvm, iwlmvm, etc */
  133. const struct iwl_op_mode_ops *ops; /* pointer to op_mode ops */
  134. struct list_head drv; /* list of devices using this op_mode */
  135. } iwlwifi_opmode_table[] = { /* ops set when driver is initialized */
  136. { .name = "iwldvm", .ops = NULL },
  137. { .name = "iwlmvm", .ops = NULL },
  138. };
  139. /*
  140. * struct fw_sec: Just for the image parsing proccess.
  141. * For the fw storage we are using struct fw_desc.
  142. */
  143. struct fw_sec {
  144. const void *data; /* the sec data */
  145. size_t size; /* section size */
  146. u32 offset; /* offset of writing in the device */
  147. };
  148. static void iwl_free_fw_desc(struct iwl_drv *drv, struct fw_desc *desc)
  149. {
  150. if (desc->v_addr)
  151. dma_free_coherent(drv->trans->dev, desc->len,
  152. desc->v_addr, desc->p_addr);
  153. desc->v_addr = NULL;
  154. desc->len = 0;
  155. }
  156. static void iwl_free_fw_img(struct iwl_drv *drv, struct fw_img *img)
  157. {
  158. int i;
  159. for (i = 0; i < IWL_UCODE_SECTION_MAX; i++)
  160. iwl_free_fw_desc(drv, &img->sec[i]);
  161. }
  162. static void iwl_dealloc_ucode(struct iwl_drv *drv)
  163. {
  164. int 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. if (!sec || !sec->size) {
  172. desc->v_addr = NULL;
  173. return -EINVAL;
  174. }
  175. desc->v_addr = dma_alloc_coherent(drv->trans->dev, sec->size,
  176. &desc->p_addr, GFP_KERNEL);
  177. if (!desc->v_addr)
  178. return -ENOMEM;
  179. desc->len = sec->size;
  180. desc->offset = sec->offset;
  181. memcpy(desc->v_addr, sec->data, sec->size);
  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. sprintf(drv->firmware_name, "%s%s%s", name_pre, tag, ".ucode");
  209. IWL_DEBUG_INFO(drv, "attempting to load firmware %s'%s'\n",
  210. (drv->fw_index == UCODE_EXPERIMENTAL_INDEX)
  211. ? "EXPERIMENTAL " : "",
  212. drv->firmware_name);
  213. return request_firmware_nowait(THIS_MODULE, 1, drv->firmware_name,
  214. drv->trans->dev,
  215. GFP_KERNEL, drv, iwl_req_fw_callback);
  216. }
  217. struct fw_img_parsing {
  218. struct fw_sec sec[IWL_UCODE_SECTION_MAX];
  219. int sec_counter;
  220. };
  221. /*
  222. * struct fw_sec_parsing: to extract fw section and it's offset from tlv
  223. */
  224. struct fw_sec_parsing {
  225. __le32 offset;
  226. const u8 data[];
  227. } __packed;
  228. /**
  229. * struct iwl_tlv_calib_data - parse the default calib data from TLV
  230. *
  231. * @ucode_type: the uCode to which the following default calib relates.
  232. * @calib: default calibrations.
  233. */
  234. struct iwl_tlv_calib_data {
  235. __le32 ucode_type;
  236. __le64 calib;
  237. } __packed;
  238. struct iwl_firmware_pieces {
  239. struct fw_img_parsing img[IWL_UCODE_TYPE_MAX];
  240. u32 init_evtlog_ptr, init_evtlog_size, init_errlog_ptr;
  241. u32 inst_evtlog_ptr, inst_evtlog_size, inst_errlog_ptr;
  242. };
  243. /*
  244. * These functions are just to extract uCode section data from the pieces
  245. * structure.
  246. */
  247. static struct fw_sec *get_sec(struct iwl_firmware_pieces *pieces,
  248. enum iwl_ucode_type type,
  249. int sec)
  250. {
  251. return &pieces->img[type].sec[sec];
  252. }
  253. static void set_sec_data(struct iwl_firmware_pieces *pieces,
  254. enum iwl_ucode_type type,
  255. int sec,
  256. const void *data)
  257. {
  258. pieces->img[type].sec[sec].data = data;
  259. }
  260. static void set_sec_size(struct iwl_firmware_pieces *pieces,
  261. enum iwl_ucode_type type,
  262. int sec,
  263. size_t size)
  264. {
  265. pieces->img[type].sec[sec].size = size;
  266. }
  267. static size_t get_sec_size(struct iwl_firmware_pieces *pieces,
  268. enum iwl_ucode_type type,
  269. int sec)
  270. {
  271. return pieces->img[type].sec[sec].size;
  272. }
  273. static void set_sec_offset(struct iwl_firmware_pieces *pieces,
  274. enum iwl_ucode_type type,
  275. int sec,
  276. u32 offset)
  277. {
  278. pieces->img[type].sec[sec].offset = offset;
  279. }
  280. /*
  281. * Gets uCode section from tlv.
  282. */
  283. static int iwl_store_ucode_sec(struct iwl_firmware_pieces *pieces,
  284. const void *data, enum iwl_ucode_type type,
  285. int size)
  286. {
  287. struct fw_img_parsing *img;
  288. struct fw_sec *sec;
  289. struct fw_sec_parsing *sec_parse;
  290. if (WARN_ON(!pieces || !data || type >= IWL_UCODE_TYPE_MAX))
  291. return -1;
  292. sec_parse = (struct fw_sec_parsing *)data;
  293. img = &pieces->img[type];
  294. sec = &img->sec[img->sec_counter];
  295. sec->offset = le32_to_cpu(sec_parse->offset);
  296. sec->data = sec_parse->data;
  297. sec->size = size - sizeof(sec_parse->offset);
  298. ++img->sec_counter;
  299. return 0;
  300. }
  301. static int iwl_set_default_calib(struct iwl_drv *drv, const u8 *data)
  302. {
  303. struct iwl_tlv_calib_data *def_calib =
  304. (struct iwl_tlv_calib_data *)data;
  305. u32 ucode_type = le32_to_cpu(def_calib->ucode_type);
  306. if (ucode_type >= IWL_UCODE_TYPE_MAX) {
  307. IWL_ERR(drv, "Wrong ucode_type %u for default calibration.\n",
  308. ucode_type);
  309. return -EINVAL;
  310. }
  311. drv->fw.default_calib[ucode_type] = le64_to_cpu(def_calib->calib);
  312. return 0;
  313. }
  314. static int iwl_parse_v1_v2_firmware(struct iwl_drv *drv,
  315. const struct firmware *ucode_raw,
  316. struct iwl_firmware_pieces *pieces)
  317. {
  318. struct iwl_ucode_header *ucode = (void *)ucode_raw->data;
  319. u32 api_ver, hdr_size, build;
  320. char buildstr[25];
  321. const u8 *src;
  322. drv->fw.ucode_ver = le32_to_cpu(ucode->ver);
  323. api_ver = IWL_UCODE_API(drv->fw.ucode_ver);
  324. switch (api_ver) {
  325. default:
  326. hdr_size = 28;
  327. if (ucode_raw->size < hdr_size) {
  328. IWL_ERR(drv, "File size too small!\n");
  329. return -EINVAL;
  330. }
  331. build = le32_to_cpu(ucode->u.v2.build);
  332. set_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_INST,
  333. le32_to_cpu(ucode->u.v2.inst_size));
  334. set_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_DATA,
  335. le32_to_cpu(ucode->u.v2.data_size));
  336. set_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST,
  337. le32_to_cpu(ucode->u.v2.init_size));
  338. set_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA,
  339. le32_to_cpu(ucode->u.v2.init_data_size));
  340. src = ucode->u.v2.data;
  341. break;
  342. case 0:
  343. case 1:
  344. case 2:
  345. hdr_size = 24;
  346. if (ucode_raw->size < hdr_size) {
  347. IWL_ERR(drv, "File size too small!\n");
  348. return -EINVAL;
  349. }
  350. build = 0;
  351. set_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_INST,
  352. le32_to_cpu(ucode->u.v1.inst_size));
  353. set_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_DATA,
  354. le32_to_cpu(ucode->u.v1.data_size));
  355. set_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST,
  356. le32_to_cpu(ucode->u.v1.init_size));
  357. set_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA,
  358. le32_to_cpu(ucode->u.v1.init_data_size));
  359. src = ucode->u.v1.data;
  360. break;
  361. }
  362. if (build)
  363. sprintf(buildstr, " build %u%s", build,
  364. (drv->fw_index == UCODE_EXPERIMENTAL_INDEX)
  365. ? " (EXP)" : "");
  366. else
  367. buildstr[0] = '\0';
  368. snprintf(drv->fw.fw_version,
  369. sizeof(drv->fw.fw_version),
  370. "%u.%u.%u.%u%s",
  371. IWL_UCODE_MAJOR(drv->fw.ucode_ver),
  372. IWL_UCODE_MINOR(drv->fw.ucode_ver),
  373. IWL_UCODE_API(drv->fw.ucode_ver),
  374. IWL_UCODE_SERIAL(drv->fw.ucode_ver),
  375. buildstr);
  376. /* Verify size of file vs. image size info in file's header */
  377. if (ucode_raw->size != hdr_size +
  378. get_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_INST) +
  379. get_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_DATA) +
  380. get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST) +
  381. get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA)) {
  382. IWL_ERR(drv,
  383. "uCode file size %d does not match expected size\n",
  384. (int)ucode_raw->size);
  385. return -EINVAL;
  386. }
  387. set_sec_data(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_INST, src);
  388. src += get_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_INST);
  389. set_sec_offset(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_INST,
  390. IWLAGN_RTC_INST_LOWER_BOUND);
  391. set_sec_data(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_DATA, src);
  392. src += get_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_DATA);
  393. set_sec_offset(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_DATA,
  394. IWLAGN_RTC_DATA_LOWER_BOUND);
  395. set_sec_data(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST, src);
  396. src += get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST);
  397. set_sec_offset(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST,
  398. IWLAGN_RTC_INST_LOWER_BOUND);
  399. set_sec_data(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA, src);
  400. src += get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA);
  401. set_sec_offset(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA,
  402. IWLAGN_RTC_DATA_LOWER_BOUND);
  403. return 0;
  404. }
  405. static int iwl_parse_tlv_firmware(struct iwl_drv *drv,
  406. const struct firmware *ucode_raw,
  407. struct iwl_firmware_pieces *pieces,
  408. struct iwl_ucode_capabilities *capa)
  409. {
  410. struct iwl_tlv_ucode_header *ucode = (void *)ucode_raw->data;
  411. struct iwl_ucode_tlv *tlv;
  412. size_t len = ucode_raw->size;
  413. const u8 *data;
  414. u32 tlv_len;
  415. enum iwl_ucode_tlv_type tlv_type;
  416. const u8 *tlv_data;
  417. char buildstr[25];
  418. u32 build;
  419. if (len < sizeof(*ucode)) {
  420. IWL_ERR(drv, "uCode has invalid length: %zd\n", len);
  421. return -EINVAL;
  422. }
  423. if (ucode->magic != cpu_to_le32(IWL_TLV_UCODE_MAGIC)) {
  424. IWL_ERR(drv, "invalid uCode magic: 0X%x\n",
  425. le32_to_cpu(ucode->magic));
  426. return -EINVAL;
  427. }
  428. drv->fw.ucode_ver = le32_to_cpu(ucode->ver);
  429. build = le32_to_cpu(ucode->build);
  430. if (build)
  431. sprintf(buildstr, " build %u%s", build,
  432. (drv->fw_index == UCODE_EXPERIMENTAL_INDEX)
  433. ? " (EXP)" : "");
  434. else
  435. buildstr[0] = '\0';
  436. snprintf(drv->fw.fw_version,
  437. sizeof(drv->fw.fw_version),
  438. "%u.%u.%u.%u%s",
  439. IWL_UCODE_MAJOR(drv->fw.ucode_ver),
  440. IWL_UCODE_MINOR(drv->fw.ucode_ver),
  441. IWL_UCODE_API(drv->fw.ucode_ver),
  442. IWL_UCODE_SERIAL(drv->fw.ucode_ver),
  443. buildstr);
  444. data = ucode->data;
  445. len -= sizeof(*ucode);
  446. while (len >= sizeof(*tlv)) {
  447. len -= sizeof(*tlv);
  448. tlv = (void *)data;
  449. tlv_len = le32_to_cpu(tlv->length);
  450. tlv_type = le32_to_cpu(tlv->type);
  451. tlv_data = tlv->data;
  452. if (len < tlv_len) {
  453. IWL_ERR(drv, "invalid TLV len: %zd/%u\n",
  454. len, tlv_len);
  455. return -EINVAL;
  456. }
  457. len -= ALIGN(tlv_len, 4);
  458. data += sizeof(*tlv) + ALIGN(tlv_len, 4);
  459. switch (tlv_type) {
  460. case IWL_UCODE_TLV_INST:
  461. set_sec_data(pieces, IWL_UCODE_REGULAR,
  462. IWL_UCODE_SECTION_INST, tlv_data);
  463. set_sec_size(pieces, IWL_UCODE_REGULAR,
  464. IWL_UCODE_SECTION_INST, tlv_len);
  465. set_sec_offset(pieces, IWL_UCODE_REGULAR,
  466. IWL_UCODE_SECTION_INST,
  467. IWLAGN_RTC_INST_LOWER_BOUND);
  468. break;
  469. case IWL_UCODE_TLV_DATA:
  470. set_sec_data(pieces, IWL_UCODE_REGULAR,
  471. IWL_UCODE_SECTION_DATA, tlv_data);
  472. set_sec_size(pieces, IWL_UCODE_REGULAR,
  473. IWL_UCODE_SECTION_DATA, tlv_len);
  474. set_sec_offset(pieces, IWL_UCODE_REGULAR,
  475. IWL_UCODE_SECTION_DATA,
  476. IWLAGN_RTC_DATA_LOWER_BOUND);
  477. break;
  478. case IWL_UCODE_TLV_INIT:
  479. set_sec_data(pieces, IWL_UCODE_INIT,
  480. IWL_UCODE_SECTION_INST, tlv_data);
  481. set_sec_size(pieces, IWL_UCODE_INIT,
  482. IWL_UCODE_SECTION_INST, tlv_len);
  483. set_sec_offset(pieces, IWL_UCODE_INIT,
  484. IWL_UCODE_SECTION_INST,
  485. IWLAGN_RTC_INST_LOWER_BOUND);
  486. break;
  487. case IWL_UCODE_TLV_INIT_DATA:
  488. set_sec_data(pieces, IWL_UCODE_INIT,
  489. IWL_UCODE_SECTION_DATA, tlv_data);
  490. set_sec_size(pieces, IWL_UCODE_INIT,
  491. IWL_UCODE_SECTION_DATA, tlv_len);
  492. set_sec_offset(pieces, IWL_UCODE_INIT,
  493. IWL_UCODE_SECTION_DATA,
  494. IWLAGN_RTC_DATA_LOWER_BOUND);
  495. break;
  496. case IWL_UCODE_TLV_BOOT:
  497. IWL_ERR(drv, "Found unexpected BOOT ucode\n");
  498. break;
  499. case IWL_UCODE_TLV_PROBE_MAX_LEN:
  500. if (tlv_len != sizeof(u32))
  501. goto invalid_tlv_len;
  502. capa->max_probe_length =
  503. le32_to_cpup((__le32 *)tlv_data);
  504. break;
  505. case IWL_UCODE_TLV_PAN:
  506. if (tlv_len)
  507. goto invalid_tlv_len;
  508. capa->flags |= IWL_UCODE_TLV_FLAGS_PAN;
  509. break;
  510. case IWL_UCODE_TLV_FLAGS:
  511. /* must be at least one u32 */
  512. if (tlv_len < sizeof(u32))
  513. goto invalid_tlv_len;
  514. /* and a proper number of u32s */
  515. if (tlv_len % sizeof(u32))
  516. goto invalid_tlv_len;
  517. /*
  518. * This driver only reads the first u32 as
  519. * right now no more features are defined,
  520. * if that changes then either the driver
  521. * will not work with the new firmware, or
  522. * it'll not take advantage of new features.
  523. */
  524. capa->flags = le32_to_cpup((__le32 *)tlv_data);
  525. break;
  526. case IWL_UCODE_TLV_INIT_EVTLOG_PTR:
  527. if (tlv_len != sizeof(u32))
  528. goto invalid_tlv_len;
  529. pieces->init_evtlog_ptr =
  530. le32_to_cpup((__le32 *)tlv_data);
  531. break;
  532. case IWL_UCODE_TLV_INIT_EVTLOG_SIZE:
  533. if (tlv_len != sizeof(u32))
  534. goto invalid_tlv_len;
  535. pieces->init_evtlog_size =
  536. le32_to_cpup((__le32 *)tlv_data);
  537. break;
  538. case IWL_UCODE_TLV_INIT_ERRLOG_PTR:
  539. if (tlv_len != sizeof(u32))
  540. goto invalid_tlv_len;
  541. pieces->init_errlog_ptr =
  542. le32_to_cpup((__le32 *)tlv_data);
  543. break;
  544. case IWL_UCODE_TLV_RUNT_EVTLOG_PTR:
  545. if (tlv_len != sizeof(u32))
  546. goto invalid_tlv_len;
  547. pieces->inst_evtlog_ptr =
  548. le32_to_cpup((__le32 *)tlv_data);
  549. break;
  550. case IWL_UCODE_TLV_RUNT_EVTLOG_SIZE:
  551. if (tlv_len != sizeof(u32))
  552. goto invalid_tlv_len;
  553. pieces->inst_evtlog_size =
  554. le32_to_cpup((__le32 *)tlv_data);
  555. break;
  556. case IWL_UCODE_TLV_RUNT_ERRLOG_PTR:
  557. if (tlv_len != sizeof(u32))
  558. goto invalid_tlv_len;
  559. pieces->inst_errlog_ptr =
  560. le32_to_cpup((__le32 *)tlv_data);
  561. break;
  562. case IWL_UCODE_TLV_ENHANCE_SENS_TBL:
  563. if (tlv_len)
  564. goto invalid_tlv_len;
  565. drv->fw.enhance_sensitivity_table = true;
  566. break;
  567. case IWL_UCODE_TLV_WOWLAN_INST:
  568. set_sec_data(pieces, IWL_UCODE_WOWLAN,
  569. IWL_UCODE_SECTION_INST, tlv_data);
  570. set_sec_size(pieces, IWL_UCODE_WOWLAN,
  571. IWL_UCODE_SECTION_INST, tlv_len);
  572. set_sec_offset(pieces, IWL_UCODE_WOWLAN,
  573. IWL_UCODE_SECTION_INST,
  574. IWLAGN_RTC_INST_LOWER_BOUND);
  575. break;
  576. case IWL_UCODE_TLV_WOWLAN_DATA:
  577. set_sec_data(pieces, IWL_UCODE_WOWLAN,
  578. IWL_UCODE_SECTION_DATA, tlv_data);
  579. set_sec_size(pieces, IWL_UCODE_WOWLAN,
  580. IWL_UCODE_SECTION_DATA, tlv_len);
  581. set_sec_offset(pieces, IWL_UCODE_WOWLAN,
  582. IWL_UCODE_SECTION_DATA,
  583. IWLAGN_RTC_DATA_LOWER_BOUND);
  584. break;
  585. case IWL_UCODE_TLV_PHY_CALIBRATION_SIZE:
  586. if (tlv_len != sizeof(u32))
  587. goto invalid_tlv_len;
  588. capa->standard_phy_calibration_size =
  589. le32_to_cpup((__le32 *)tlv_data);
  590. break;
  591. case IWL_UCODE_TLV_SEC_RT:
  592. iwl_store_ucode_sec(pieces, tlv_data, IWL_UCODE_REGULAR,
  593. tlv_len);
  594. drv->fw.mvm_fw = true;
  595. break;
  596. case IWL_UCODE_TLV_SEC_INIT:
  597. iwl_store_ucode_sec(pieces, tlv_data, IWL_UCODE_INIT,
  598. tlv_len);
  599. drv->fw.mvm_fw = true;
  600. break;
  601. case IWL_UCODE_TLV_SEC_WOWLAN:
  602. iwl_store_ucode_sec(pieces, tlv_data, IWL_UCODE_WOWLAN,
  603. tlv_len);
  604. drv->fw.mvm_fw = true;
  605. break;
  606. case IWL_UCODE_TLV_DEF_CALIB:
  607. if (tlv_len != sizeof(struct iwl_tlv_calib_data))
  608. goto invalid_tlv_len;
  609. if (iwl_set_default_calib(drv, tlv_data))
  610. goto tlv_error;
  611. break;
  612. case IWL_UCODE_TLV_PHY_SKU:
  613. if (tlv_len != sizeof(u32))
  614. goto invalid_tlv_len;
  615. drv->fw.phy_config = le32_to_cpup((__le32 *)tlv_data);
  616. break;
  617. default:
  618. IWL_DEBUG_INFO(drv, "unknown TLV: %d\n", tlv_type);
  619. break;
  620. }
  621. }
  622. if (len) {
  623. IWL_ERR(drv, "invalid TLV after parsing: %zd\n", len);
  624. iwl_print_hex_dump(drv, IWL_DL_FW, (u8 *)data, len);
  625. return -EINVAL;
  626. }
  627. return 0;
  628. invalid_tlv_len:
  629. IWL_ERR(drv, "TLV %d has invalid size: %u\n", tlv_type, tlv_len);
  630. tlv_error:
  631. iwl_print_hex_dump(drv, IWL_DL_FW, tlv_data, tlv_len);
  632. return -EINVAL;
  633. }
  634. static int iwl_alloc_ucode(struct iwl_drv *drv,
  635. struct iwl_firmware_pieces *pieces,
  636. enum iwl_ucode_type type)
  637. {
  638. int i;
  639. for (i = 0;
  640. i < IWL_UCODE_SECTION_MAX && get_sec_size(pieces, type, i);
  641. i++)
  642. if (iwl_alloc_fw_desc(drv, &(drv->fw.img[type].sec[i]),
  643. get_sec(pieces, type, i)))
  644. return -ENOMEM;
  645. return 0;
  646. }
  647. static int validate_sec_sizes(struct iwl_drv *drv,
  648. struct iwl_firmware_pieces *pieces,
  649. const struct iwl_cfg *cfg)
  650. {
  651. IWL_DEBUG_INFO(drv, "f/w package hdr runtime inst size = %Zd\n",
  652. get_sec_size(pieces, IWL_UCODE_REGULAR,
  653. IWL_UCODE_SECTION_INST));
  654. IWL_DEBUG_INFO(drv, "f/w package hdr runtime data size = %Zd\n",
  655. get_sec_size(pieces, IWL_UCODE_REGULAR,
  656. IWL_UCODE_SECTION_DATA));
  657. IWL_DEBUG_INFO(drv, "f/w package hdr init inst size = %Zd\n",
  658. get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST));
  659. IWL_DEBUG_INFO(drv, "f/w package hdr init data size = %Zd\n",
  660. get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA));
  661. /* Verify that uCode images will fit in card's SRAM. */
  662. if (get_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_INST) >
  663. cfg->max_inst_size) {
  664. IWL_ERR(drv, "uCode instr len %Zd too large to fit in\n",
  665. get_sec_size(pieces, IWL_UCODE_REGULAR,
  666. IWL_UCODE_SECTION_INST));
  667. return -1;
  668. }
  669. if (get_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_DATA) >
  670. cfg->max_data_size) {
  671. IWL_ERR(drv, "uCode data len %Zd too large to fit in\n",
  672. get_sec_size(pieces, IWL_UCODE_REGULAR,
  673. IWL_UCODE_SECTION_DATA));
  674. return -1;
  675. }
  676. if (get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST) >
  677. cfg->max_inst_size) {
  678. IWL_ERR(drv, "uCode init instr len %Zd too large to fit in\n",
  679. get_sec_size(pieces, IWL_UCODE_INIT,
  680. IWL_UCODE_SECTION_INST));
  681. return -1;
  682. }
  683. if (get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA) >
  684. cfg->max_data_size) {
  685. IWL_ERR(drv, "uCode init data len %Zd too large to fit in\n",
  686. get_sec_size(pieces, IWL_UCODE_REGULAR,
  687. IWL_UCODE_SECTION_DATA));
  688. return -1;
  689. }
  690. return 0;
  691. }
  692. static struct iwl_op_mode *
  693. _iwl_op_mode_start(struct iwl_drv *drv, struct iwlwifi_opmode_table *op)
  694. {
  695. const struct iwl_op_mode_ops *ops = op->ops;
  696. struct dentry *dbgfs_dir = NULL;
  697. struct iwl_op_mode *op_mode = NULL;
  698. #ifdef CONFIG_IWLWIFI_DEBUGFS
  699. drv->dbgfs_op_mode = debugfs_create_dir(op->name,
  700. drv->dbgfs_drv);
  701. if (!drv->dbgfs_op_mode) {
  702. IWL_ERR(drv,
  703. "failed to create opmode debugfs directory\n");
  704. return op_mode;
  705. }
  706. dbgfs_dir = drv->dbgfs_op_mode;
  707. #endif
  708. op_mode = ops->start(drv->trans, drv->cfg, &drv->fw, dbgfs_dir);
  709. #ifdef CONFIG_IWLWIFI_DEBUGFS
  710. if (!op_mode) {
  711. debugfs_remove_recursive(drv->dbgfs_op_mode);
  712. drv->dbgfs_op_mode = NULL;
  713. }
  714. #endif
  715. return op_mode;
  716. }
  717. static void _iwl_op_mode_stop(struct iwl_drv *drv)
  718. {
  719. /* op_mode can be NULL if its start failed */
  720. if (drv->op_mode) {
  721. iwl_op_mode_stop(drv->op_mode);
  722. drv->op_mode = NULL;
  723. #ifdef CONFIG_IWLWIFI_DEBUGFS
  724. debugfs_remove_recursive(drv->dbgfs_op_mode);
  725. drv->dbgfs_op_mode = NULL;
  726. #endif
  727. }
  728. }
  729. /**
  730. * iwl_req_fw_callback - callback when firmware was loaded
  731. *
  732. * If loaded successfully, copies the firmware into buffers
  733. * for the card to fetch (via DMA).
  734. */
  735. static void iwl_req_fw_callback(const struct firmware *ucode_raw, void *context)
  736. {
  737. struct iwl_drv *drv = context;
  738. struct iwl_fw *fw = &drv->fw;
  739. struct iwl_ucode_header *ucode;
  740. struct iwlwifi_opmode_table *op;
  741. int err;
  742. struct iwl_firmware_pieces pieces;
  743. const unsigned int api_max = drv->cfg->ucode_api_max;
  744. unsigned int api_ok = drv->cfg->ucode_api_ok;
  745. const unsigned int api_min = drv->cfg->ucode_api_min;
  746. u32 api_ver;
  747. int i;
  748. bool load_module = false;
  749. fw->ucode_capa.max_probe_length = 200;
  750. fw->ucode_capa.standard_phy_calibration_size =
  751. IWL_DEFAULT_STANDARD_PHY_CALIBRATE_TBL_SIZE;
  752. if (!api_ok)
  753. api_ok = api_max;
  754. memset(&pieces, 0, sizeof(pieces));
  755. if (!ucode_raw) {
  756. if (drv->fw_index <= api_ok)
  757. IWL_ERR(drv,
  758. "request for firmware file '%s' failed.\n",
  759. drv->firmware_name);
  760. goto try_again;
  761. }
  762. IWL_DEBUG_INFO(drv, "Loaded firmware file '%s' (%zd bytes).\n",
  763. drv->firmware_name, ucode_raw->size);
  764. /* Make sure that we got at least the API version number */
  765. if (ucode_raw->size < 4) {
  766. IWL_ERR(drv, "File size way too small!\n");
  767. goto try_again;
  768. }
  769. /* Data from ucode file: header followed by uCode images */
  770. ucode = (struct iwl_ucode_header *)ucode_raw->data;
  771. if (ucode->ver)
  772. err = iwl_parse_v1_v2_firmware(drv, ucode_raw, &pieces);
  773. else
  774. err = iwl_parse_tlv_firmware(drv, ucode_raw, &pieces,
  775. &fw->ucode_capa);
  776. if (err)
  777. goto try_again;
  778. api_ver = IWL_UCODE_API(drv->fw.ucode_ver);
  779. /*
  780. * api_ver should match the api version forming part of the
  781. * firmware filename ... but we don't check for that and only rely
  782. * on the API version read from firmware header from here on forward
  783. */
  784. /* no api version check required for experimental uCode */
  785. if (drv->fw_index != UCODE_EXPERIMENTAL_INDEX) {
  786. if (api_ver < api_min || api_ver > api_max) {
  787. IWL_ERR(drv,
  788. "Driver unable to support your firmware API. "
  789. "Driver supports v%u, firmware is v%u.\n",
  790. api_max, api_ver);
  791. goto try_again;
  792. }
  793. if (api_ver < api_ok) {
  794. if (api_ok != api_max)
  795. IWL_ERR(drv, "Firmware has old API version, "
  796. "expected v%u through v%u, got v%u.\n",
  797. api_ok, api_max, api_ver);
  798. else
  799. IWL_ERR(drv, "Firmware has old API version, "
  800. "expected v%u, got v%u.\n",
  801. api_max, api_ver);
  802. IWL_ERR(drv, "New firmware can be obtained from "
  803. "http://www.intellinuxwireless.org/.\n");
  804. }
  805. }
  806. IWL_INFO(drv, "loaded firmware version %s", drv->fw.fw_version);
  807. /*
  808. * In mvm uCode there is no difference between data and instructions
  809. * sections.
  810. */
  811. if (!fw->mvm_fw && validate_sec_sizes(drv, &pieces, drv->cfg))
  812. goto try_again;
  813. /* Allocate ucode buffers for card's bus-master loading ... */
  814. /* Runtime instructions and 2 copies of data:
  815. * 1) unmodified from disk
  816. * 2) backup cache for save/restore during power-downs */
  817. for (i = 0; i < IWL_UCODE_TYPE_MAX; i++)
  818. if (iwl_alloc_ucode(drv, &pieces, i))
  819. goto out_free_fw;
  820. /* Now that we can no longer fail, copy information */
  821. /*
  822. * The (size - 16) / 12 formula is based on the information recorded
  823. * for each event, which is of mode 1 (including timestamp) for all
  824. * new microcodes that include this information.
  825. */
  826. fw->init_evtlog_ptr = pieces.init_evtlog_ptr;
  827. if (pieces.init_evtlog_size)
  828. fw->init_evtlog_size = (pieces.init_evtlog_size - 16)/12;
  829. else
  830. fw->init_evtlog_size =
  831. drv->cfg->base_params->max_event_log_size;
  832. fw->init_errlog_ptr = pieces.init_errlog_ptr;
  833. fw->inst_evtlog_ptr = pieces.inst_evtlog_ptr;
  834. if (pieces.inst_evtlog_size)
  835. fw->inst_evtlog_size = (pieces.inst_evtlog_size - 16)/12;
  836. else
  837. fw->inst_evtlog_size =
  838. drv->cfg->base_params->max_event_log_size;
  839. fw->inst_errlog_ptr = pieces.inst_errlog_ptr;
  840. /*
  841. * figure out the offset of chain noise reset and gain commands
  842. * base on the size of standard phy calibration commands table size
  843. */
  844. if (fw->ucode_capa.standard_phy_calibration_size >
  845. IWL_MAX_PHY_CALIBRATE_TBL_SIZE)
  846. fw->ucode_capa.standard_phy_calibration_size =
  847. IWL_MAX_STANDARD_PHY_CALIBRATE_TBL_SIZE;
  848. /* We have our copies now, allow OS release its copies */
  849. release_firmware(ucode_raw);
  850. mutex_lock(&iwlwifi_opmode_table_mtx);
  851. op = &iwlwifi_opmode_table[DVM_OP_MODE];
  852. /* add this device to the list of devices using this op_mode */
  853. list_add_tail(&drv->list, &op->drv);
  854. if (op->ops) {
  855. drv->op_mode = _iwl_op_mode_start(drv, op);
  856. if (!drv->op_mode) {
  857. mutex_unlock(&iwlwifi_opmode_table_mtx);
  858. goto out_unbind;
  859. }
  860. } else {
  861. load_module = true;
  862. }
  863. mutex_unlock(&iwlwifi_opmode_table_mtx);
  864. /*
  865. * Complete the firmware request last so that
  866. * a driver unbind (stop) doesn't run while we
  867. * are doing the start() above.
  868. */
  869. complete(&drv->request_firmware_complete);
  870. /*
  871. * Load the module last so we don't block anything
  872. * else from proceeding if the module fails to load
  873. * or hangs loading.
  874. */
  875. if (load_module)
  876. request_module("%s", op->name);
  877. return;
  878. try_again:
  879. /* try next, if any */
  880. release_firmware(ucode_raw);
  881. if (iwl_request_firmware(drv, false))
  882. goto out_unbind;
  883. return;
  884. out_free_fw:
  885. IWL_ERR(drv, "failed to allocate pci memory\n");
  886. iwl_dealloc_ucode(drv);
  887. release_firmware(ucode_raw);
  888. out_unbind:
  889. complete(&drv->request_firmware_complete);
  890. device_release_driver(drv->trans->dev);
  891. }
  892. struct iwl_drv *iwl_drv_start(struct iwl_trans *trans,
  893. const struct iwl_cfg *cfg)
  894. {
  895. struct iwl_drv *drv;
  896. int ret;
  897. drv = kzalloc(sizeof(*drv), GFP_KERNEL);
  898. if (!drv)
  899. return NULL;
  900. drv->trans = trans;
  901. drv->dev = trans->dev;
  902. drv->cfg = cfg;
  903. init_completion(&drv->request_firmware_complete);
  904. INIT_LIST_HEAD(&drv->list);
  905. #ifdef CONFIG_IWLWIFI_DEBUGFS
  906. /* Create the device debugfs entries. */
  907. drv->dbgfs_drv = debugfs_create_dir(dev_name(trans->dev),
  908. iwl_dbgfs_root);
  909. if (!drv->dbgfs_drv) {
  910. IWL_ERR(drv, "failed to create debugfs directory\n");
  911. goto err_free_drv;
  912. }
  913. /* Create transport layer debugfs dir */
  914. drv->trans->dbgfs_dir = debugfs_create_dir("trans", drv->dbgfs_drv);
  915. if (!drv->trans->dbgfs_dir) {
  916. IWL_ERR(drv, "failed to create transport debugfs directory\n");
  917. goto err_free_dbgfs;
  918. }
  919. #endif
  920. ret = iwl_request_firmware(drv, true);
  921. if (ret) {
  922. IWL_ERR(trans, "Couldn't request the fw\n");
  923. goto err_fw;
  924. }
  925. return drv;
  926. err_fw:
  927. #ifdef CONFIG_IWLWIFI_DEBUGFS
  928. err_free_dbgfs:
  929. debugfs_remove_recursive(drv->dbgfs_drv);
  930. err_free_drv:
  931. #endif
  932. kfree(drv);
  933. drv = NULL;
  934. return drv;
  935. }
  936. void iwl_drv_stop(struct iwl_drv *drv)
  937. {
  938. wait_for_completion(&drv->request_firmware_complete);
  939. _iwl_op_mode_stop(drv);
  940. iwl_dealloc_ucode(drv);
  941. mutex_lock(&iwlwifi_opmode_table_mtx);
  942. /*
  943. * List is empty (this item wasn't added)
  944. * when firmware loading failed -- in that
  945. * case we can't remove it from any list.
  946. */
  947. if (!list_empty(&drv->list))
  948. list_del(&drv->list);
  949. mutex_unlock(&iwlwifi_opmode_table_mtx);
  950. #ifdef CONFIG_IWLWIFI_DEBUGFS
  951. debugfs_remove_recursive(drv->dbgfs_drv);
  952. #endif
  953. kfree(drv);
  954. }
  955. /* shared module parameters */
  956. struct iwl_mod_params iwlwifi_mod_params = {
  957. .amsdu_size_8K = 1,
  958. .restart_fw = 1,
  959. .plcp_check = true,
  960. .bt_coex_active = true,
  961. .power_level = IWL_POWER_INDEX_1,
  962. .bt_ch_announce = true,
  963. .auto_agg = true,
  964. .wd_disable = true,
  965. /* the rest are 0 by default */
  966. };
  967. EXPORT_SYMBOL_GPL(iwlwifi_mod_params);
  968. int iwl_opmode_register(const char *name, const struct iwl_op_mode_ops *ops)
  969. {
  970. int i;
  971. struct iwl_drv *drv;
  972. struct iwlwifi_opmode_table *op;
  973. mutex_lock(&iwlwifi_opmode_table_mtx);
  974. for (i = 0; i < ARRAY_SIZE(iwlwifi_opmode_table); i++) {
  975. op = &iwlwifi_opmode_table[i];
  976. if (strcmp(op->name, name))
  977. continue;
  978. op->ops = ops;
  979. /* TODO: need to handle exceptional case */
  980. list_for_each_entry(drv, &op->drv, list)
  981. drv->op_mode = _iwl_op_mode_start(drv, op);
  982. mutex_unlock(&iwlwifi_opmode_table_mtx);
  983. return 0;
  984. }
  985. mutex_unlock(&iwlwifi_opmode_table_mtx);
  986. return -EIO;
  987. }
  988. EXPORT_SYMBOL_GPL(iwl_opmode_register);
  989. void iwl_opmode_deregister(const char *name)
  990. {
  991. int i;
  992. struct iwl_drv *drv;
  993. mutex_lock(&iwlwifi_opmode_table_mtx);
  994. for (i = 0; i < ARRAY_SIZE(iwlwifi_opmode_table); i++) {
  995. if (strcmp(iwlwifi_opmode_table[i].name, name))
  996. continue;
  997. iwlwifi_opmode_table[i].ops = NULL;
  998. /* call the stop routine for all devices */
  999. list_for_each_entry(drv, &iwlwifi_opmode_table[i].drv, list)
  1000. _iwl_op_mode_stop(drv);
  1001. mutex_unlock(&iwlwifi_opmode_table_mtx);
  1002. return;
  1003. }
  1004. mutex_unlock(&iwlwifi_opmode_table_mtx);
  1005. }
  1006. EXPORT_SYMBOL_GPL(iwl_opmode_deregister);
  1007. static int __init iwl_drv_init(void)
  1008. {
  1009. int i;
  1010. mutex_init(&iwlwifi_opmode_table_mtx);
  1011. for (i = 0; i < ARRAY_SIZE(iwlwifi_opmode_table); i++)
  1012. INIT_LIST_HEAD(&iwlwifi_opmode_table[i].drv);
  1013. pr_info(DRV_DESCRIPTION ", " DRV_VERSION "\n");
  1014. pr_info(DRV_COPYRIGHT "\n");
  1015. #ifdef CONFIG_IWLWIFI_DEBUGFS
  1016. /* Create the root of iwlwifi debugfs subsystem. */
  1017. iwl_dbgfs_root = debugfs_create_dir(DRV_NAME, NULL);
  1018. if (!iwl_dbgfs_root)
  1019. return -EFAULT;
  1020. #endif
  1021. return iwl_pci_register_driver();
  1022. }
  1023. module_init(iwl_drv_init);
  1024. static void __exit iwl_drv_exit(void)
  1025. {
  1026. iwl_pci_unregister_driver();
  1027. #ifdef CONFIG_IWLWIFI_DEBUGFS
  1028. debugfs_remove_recursive(iwl_dbgfs_root);
  1029. #endif
  1030. }
  1031. module_exit(iwl_drv_exit);
  1032. #ifdef CONFIG_IWLWIFI_DEBUG
  1033. module_param_named(debug, iwlwifi_mod_params.debug_level, uint,
  1034. S_IRUGO | S_IWUSR);
  1035. MODULE_PARM_DESC(debug, "debug output mask");
  1036. #endif
  1037. module_param_named(swcrypto, iwlwifi_mod_params.sw_crypto, int, S_IRUGO);
  1038. MODULE_PARM_DESC(swcrypto, "using crypto in software (default 0 [hardware])");
  1039. module_param_named(11n_disable, iwlwifi_mod_params.disable_11n, uint, S_IRUGO);
  1040. MODULE_PARM_DESC(11n_disable,
  1041. "disable 11n functionality, bitmap: 1: full, 2: agg TX, 4: agg RX");
  1042. module_param_named(amsdu_size_8K, iwlwifi_mod_params.amsdu_size_8K,
  1043. int, S_IRUGO);
  1044. MODULE_PARM_DESC(amsdu_size_8K, "enable 8K amsdu size");
  1045. module_param_named(fw_restart, iwlwifi_mod_params.restart_fw, int, S_IRUGO);
  1046. MODULE_PARM_DESC(fw_restart, "restart firmware in case of error");
  1047. module_param_named(antenna_coupling, iwlwifi_mod_params.ant_coupling,
  1048. int, S_IRUGO);
  1049. MODULE_PARM_DESC(antenna_coupling,
  1050. "specify antenna coupling in dB (defualt: 0 dB)");
  1051. module_param_named(bt_ch_inhibition, iwlwifi_mod_params.bt_ch_announce,
  1052. bool, S_IRUGO);
  1053. MODULE_PARM_DESC(bt_ch_inhibition,
  1054. "Enable BT channel inhibition (default: enable)");
  1055. module_param_named(plcp_check, iwlwifi_mod_params.plcp_check, bool, S_IRUGO);
  1056. MODULE_PARM_DESC(plcp_check, "Check plcp health (default: 1 [enabled])");
  1057. module_param_named(wd_disable, iwlwifi_mod_params.wd_disable, int, S_IRUGO);
  1058. MODULE_PARM_DESC(wd_disable,
  1059. "Disable stuck queue watchdog timer 0=system default, "
  1060. "1=disable, 2=enable (default: 0)");
  1061. /*
  1062. * set bt_coex_active to true, uCode will do kill/defer
  1063. * every time the priority line is asserted (BT is sending signals on the
  1064. * priority line in the PCIx).
  1065. * set bt_coex_active to false, uCode will ignore the BT activity and
  1066. * perform the normal operation
  1067. *
  1068. * User might experience transmit issue on some platform due to WiFi/BT
  1069. * co-exist problem. The possible behaviors are:
  1070. * Able to scan and finding all the available AP
  1071. * Not able to associate with any AP
  1072. * On those platforms, WiFi communication can be restored by set
  1073. * "bt_coex_active" module parameter to "false"
  1074. *
  1075. * default: bt_coex_active = true (BT_COEX_ENABLE)
  1076. */
  1077. module_param_named(bt_coex_active, iwlwifi_mod_params.bt_coex_active,
  1078. bool, S_IRUGO);
  1079. MODULE_PARM_DESC(bt_coex_active, "enable wifi/bt co-exist (default: enable)");
  1080. module_param_named(led_mode, iwlwifi_mod_params.led_mode, int, S_IRUGO);
  1081. MODULE_PARM_DESC(led_mode, "0=system default, "
  1082. "1=On(RF On)/Off(RF Off), 2=blinking, 3=Off (default: 0)");
  1083. module_param_named(power_save, iwlwifi_mod_params.power_save,
  1084. bool, S_IRUGO);
  1085. MODULE_PARM_DESC(power_save,
  1086. "enable WiFi power management (default: disable)");
  1087. module_param_named(power_level, iwlwifi_mod_params.power_level,
  1088. int, S_IRUGO);
  1089. MODULE_PARM_DESC(power_level,
  1090. "default power save level (range from 1 - 5, default: 1)");
  1091. module_param_named(auto_agg, iwlwifi_mod_params.auto_agg,
  1092. bool, S_IRUGO);
  1093. MODULE_PARM_DESC(auto_agg,
  1094. "enable agg w/o check traffic load (default: enable)");
  1095. module_param_named(5ghz_disable, iwlwifi_mod_params.disable_5ghz,
  1096. bool, S_IRUGO);
  1097. MODULE_PARM_DESC(5ghz_disable, "disable 5GHz band (default: 0 [enabled])");