]>
Commit | Line | Data |
---|---|---|
5c58edc6 EG |
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> | |
15854ef9 JB |
64 | #include <linux/dma-mapping.h> |
65 | #include <linux/firmware.h> | |
66 | #include <linux/module.h> | |
5c58edc6 EG |
67 | |
68 | #include "iwl-drv.h" | |
69 | #include "iwl-trans.h" | |
d0f76d68 | 70 | #include "iwl-op-mode.h" |
0cedacc5 | 71 | #include "iwl-agn-hw.h" |
6238b008 JB |
72 | #include "iwl-fw.h" |
73 | #include "iwl-config.h" | |
5c58edc6 | 74 | |
0692fe41 | 75 | /* private includes */ |
3995deaf | 76 | #include "iwl-fw-file.h" |
0692fe41 | 77 | |
965974a6 JB |
78 | /** |
79 | * struct iwl_drv - drv common data | |
80 | * @fw: the iwl_fw structure | |
965974a6 | 81 | * @op_mode: the running op_mode |
68f360dc | 82 | * @trans: transport layer |
4b9844f5 | 83 | * @dev: for debug prints only |
68f360dc | 84 | * @cfg: configuration struct |
965974a6 JB |
85 | * @fw_index: firmware revision to try loading |
86 | * @firmware_name: composite filename of ucode file to load | |
87 | * @request_firmware_complete: the firmware has been obtained from user space | |
88 | */ | |
89 | struct iwl_drv { | |
90 | struct iwl_fw fw; | |
91 | ||
965974a6 | 92 | struct iwl_op_mode *op_mode; |
9130bab1 | 93 | struct iwl_trans *trans; |
4b9844f5 | 94 | struct device *dev; |
68f360dc | 95 | const struct iwl_cfg *cfg; |
965974a6 JB |
96 | |
97 | int fw_index; /* firmware we're trying to load */ | |
98 | char firmware_name[25]; /* name of firmware file to load */ | |
99 | ||
100 | struct completion request_firmware_complete; | |
101 | }; | |
102 | ||
103 | ||
104 | ||
0cedacc5 DS |
105 | /* |
106 | * struct fw_sec: Just for the image parsing proccess. | |
107 | * For the fw storage we are using struct fw_desc. | |
108 | */ | |
109 | struct fw_sec { | |
110 | const void *data; /* the sec data */ | |
111 | size_t size; /* section size */ | |
112 | u32 offset; /* offset of writing in the device */ | |
113 | }; | |
114 | ||
965974a6 | 115 | static void iwl_free_fw_desc(struct iwl_drv *drv, struct fw_desc *desc) |
15854ef9 JB |
116 | { |
117 | if (desc->v_addr) | |
93faaeea | 118 | dma_free_coherent(drv->trans->dev, desc->len, |
15854ef9 JB |
119 | desc->v_addr, desc->p_addr); |
120 | desc->v_addr = NULL; | |
121 | desc->len = 0; | |
122 | } | |
123 | ||
965974a6 | 124 | static void iwl_free_fw_img(struct iwl_drv *drv, struct fw_img *img) |
15854ef9 | 125 | { |
6dfa8d01 DS |
126 | int i; |
127 | for (i = 0; i < IWL_UCODE_SECTION_MAX; i++) | |
128 | iwl_free_fw_desc(drv, &img->sec[i]); | |
15854ef9 JB |
129 | } |
130 | ||
965974a6 | 131 | static void iwl_dealloc_ucode(struct iwl_drv *drv) |
15854ef9 | 132 | { |
6dfa8d01 DS |
133 | int i; |
134 | for (i = 0; i < IWL_UCODE_TYPE_MAX; i++) | |
135 | iwl_free_fw_img(drv, drv->fw.img + i); | |
15854ef9 JB |
136 | } |
137 | ||
965974a6 | 138 | static int iwl_alloc_fw_desc(struct iwl_drv *drv, struct fw_desc *desc, |
0cedacc5 | 139 | struct fw_sec *sec) |
15854ef9 | 140 | { |
0cedacc5 | 141 | if (!sec || !sec->size) { |
15854ef9 JB |
142 | desc->v_addr = NULL; |
143 | return -EINVAL; | |
144 | } | |
145 | ||
93faaeea | 146 | desc->v_addr = dma_alloc_coherent(drv->trans->dev, sec->size, |
15854ef9 JB |
147 | &desc->p_addr, GFP_KERNEL); |
148 | if (!desc->v_addr) | |
149 | return -ENOMEM; | |
150 | ||
0cedacc5 DS |
151 | desc->len = sec->size; |
152 | desc->offset = sec->offset; | |
153 | memcpy(desc->v_addr, sec->data, sec->size); | |
15854ef9 JB |
154 | return 0; |
155 | } | |
156 | ||
157 | static void iwl_ucode_callback(const struct firmware *ucode_raw, void *context); | |
158 | ||
159 | #define UCODE_EXPERIMENTAL_INDEX 100 | |
160 | #define UCODE_EXPERIMENTAL_TAG "exp" | |
161 | ||
965974a6 | 162 | static int iwl_request_firmware(struct iwl_drv *drv, bool first) |
15854ef9 | 163 | { |
68f360dc | 164 | const char *name_pre = drv->cfg->fw_name_pre; |
15854ef9 JB |
165 | char tag[8]; |
166 | ||
167 | if (first) { | |
168 | #ifdef CONFIG_IWLWIFI_DEBUG_EXPERIMENTAL_UCODE | |
965974a6 | 169 | drv->fw_index = UCODE_EXPERIMENTAL_INDEX; |
15854ef9 | 170 | strcpy(tag, UCODE_EXPERIMENTAL_TAG); |
965974a6 | 171 | } else if (drv->fw_index == UCODE_EXPERIMENTAL_INDEX) { |
15854ef9 | 172 | #endif |
68f360dc | 173 | drv->fw_index = drv->cfg->ucode_api_max; |
965974a6 | 174 | sprintf(tag, "%d", drv->fw_index); |
15854ef9 | 175 | } else { |
965974a6 JB |
176 | drv->fw_index--; |
177 | sprintf(tag, "%d", drv->fw_index); | |
15854ef9 JB |
178 | } |
179 | ||
68f360dc | 180 | if (drv->fw_index < drv->cfg->ucode_api_min) { |
965974a6 | 181 | IWL_ERR(drv, "no suitable firmware found!\n"); |
15854ef9 JB |
182 | return -ENOENT; |
183 | } | |
184 | ||
965974a6 | 185 | sprintf(drv->firmware_name, "%s%s%s", name_pre, tag, ".ucode"); |
15854ef9 | 186 | |
965974a6 JB |
187 | IWL_DEBUG_INFO(drv, "attempting to load firmware %s'%s'\n", |
188 | (drv->fw_index == UCODE_EXPERIMENTAL_INDEX) | |
15854ef9 | 189 | ? "EXPERIMENTAL " : "", |
965974a6 | 190 | drv->firmware_name); |
15854ef9 | 191 | |
965974a6 | 192 | return request_firmware_nowait(THIS_MODULE, 1, drv->firmware_name, |
93faaeea | 193 | drv->trans->dev, |
965974a6 | 194 | GFP_KERNEL, drv, iwl_ucode_callback); |
15854ef9 JB |
195 | } |
196 | ||
0cedacc5 | 197 | struct fw_img_parsing { |
6dfa8d01 | 198 | struct fw_sec sec[IWL_UCODE_SECTION_MAX]; |
0cedacc5 DS |
199 | int sec_counter; |
200 | }; | |
201 | ||
ed8c8365 DS |
202 | /* |
203 | * struct fw_sec_parsing: to extract fw section and it's offset from tlv | |
204 | */ | |
205 | struct fw_sec_parsing { | |
206 | __le32 offset; | |
207 | const u8 data[]; | |
208 | } __packed; | |
209 | ||
210 | /** | |
211 | * struct iwl_tlv_calib_data - parse the default calib data from TLV | |
212 | * | |
213 | * @ucode_type: the uCode to which the following default calib relates. | |
214 | * @calib: default calibrations. | |
215 | */ | |
216 | struct iwl_tlv_calib_data { | |
217 | __le32 ucode_type; | |
218 | __le64 calib; | |
219 | } __packed; | |
220 | ||
0cedacc5 DS |
221 | struct iwl_firmware_pieces { |
222 | struct fw_img_parsing img[IWL_UCODE_TYPE_MAX]; | |
15854ef9 JB |
223 | |
224 | u32 init_evtlog_ptr, init_evtlog_size, init_errlog_ptr; | |
225 | u32 inst_evtlog_ptr, inst_evtlog_size, inst_errlog_ptr; | |
226 | }; | |
227 | ||
0cedacc5 DS |
228 | /* |
229 | * These functions are just to extract uCode section data from the pieces | |
230 | * structure. | |
231 | */ | |
232 | static struct fw_sec *get_sec(struct iwl_firmware_pieces *pieces, | |
233 | enum iwl_ucode_type type, | |
234 | int sec) | |
235 | { | |
236 | return &pieces->img[type].sec[sec]; | |
237 | } | |
238 | ||
239 | static void set_sec_data(struct iwl_firmware_pieces *pieces, | |
240 | enum iwl_ucode_type type, | |
241 | int sec, | |
242 | const void *data) | |
243 | { | |
244 | pieces->img[type].sec[sec].data = data; | |
245 | } | |
246 | ||
247 | static void set_sec_size(struct iwl_firmware_pieces *pieces, | |
248 | enum iwl_ucode_type type, | |
249 | int sec, | |
250 | size_t size) | |
251 | { | |
252 | pieces->img[type].sec[sec].size = size; | |
253 | } | |
254 | ||
255 | static size_t get_sec_size(struct iwl_firmware_pieces *pieces, | |
256 | enum iwl_ucode_type type, | |
257 | int sec) | |
258 | { | |
259 | return pieces->img[type].sec[sec].size; | |
260 | } | |
261 | ||
262 | static void set_sec_offset(struct iwl_firmware_pieces *pieces, | |
263 | enum iwl_ucode_type type, | |
264 | int sec, | |
265 | u32 offset) | |
266 | { | |
267 | pieces->img[type].sec[sec].offset = offset; | |
268 | } | |
269 | ||
ed8c8365 DS |
270 | /* |
271 | * Gets uCode section from tlv. | |
272 | */ | |
273 | static int iwl_store_ucode_sec(struct iwl_firmware_pieces *pieces, | |
274 | const void *data, enum iwl_ucode_type type, | |
275 | int size) | |
276 | { | |
277 | struct fw_img_parsing *img; | |
278 | struct fw_sec *sec; | |
279 | struct fw_sec_parsing *sec_parse; | |
280 | ||
281 | if (WARN_ON(!pieces || !data || type >= IWL_UCODE_TYPE_MAX)) | |
282 | return -1; | |
283 | ||
284 | sec_parse = (struct fw_sec_parsing *)data; | |
285 | ||
286 | img = &pieces->img[type]; | |
287 | sec = &img->sec[img->sec_counter]; | |
288 | ||
289 | sec->offset = le32_to_cpu(sec_parse->offset); | |
290 | sec->data = sec_parse->data; | |
1176f431 | 291 | sec->size = size - sizeof(sec_parse->offset); |
ed8c8365 DS |
292 | |
293 | ++img->sec_counter; | |
294 | ||
295 | return 0; | |
296 | } | |
297 | ||
298 | static int iwl_set_default_calib(struct iwl_drv *drv, const u8 *data) | |
299 | { | |
300 | struct iwl_tlv_calib_data *def_calib = | |
301 | (struct iwl_tlv_calib_data *)data; | |
302 | u32 ucode_type = le32_to_cpu(def_calib->ucode_type); | |
303 | if (ucode_type >= IWL_UCODE_TYPE_MAX) { | |
304 | IWL_ERR(drv, "Wrong ucode_type %u for default calibration.\n", | |
305 | ucode_type); | |
306 | return -EINVAL; | |
307 | } | |
308 | drv->fw.default_calib[ucode_type] = le64_to_cpu(def_calib->calib); | |
309 | return 0; | |
310 | } | |
311 | ||
965974a6 | 312 | static int iwl_parse_v1_v2_firmware(struct iwl_drv *drv, |
0cedacc5 DS |
313 | const struct firmware *ucode_raw, |
314 | struct iwl_firmware_pieces *pieces) | |
15854ef9 JB |
315 | { |
316 | struct iwl_ucode_header *ucode = (void *)ucode_raw->data; | |
317 | u32 api_ver, hdr_size, build; | |
318 | char buildstr[25]; | |
319 | const u8 *src; | |
320 | ||
965974a6 JB |
321 | drv->fw.ucode_ver = le32_to_cpu(ucode->ver); |
322 | api_ver = IWL_UCODE_API(drv->fw.ucode_ver); | |
15854ef9 JB |
323 | |
324 | switch (api_ver) { | |
325 | default: | |
326 | hdr_size = 28; | |
327 | if (ucode_raw->size < hdr_size) { | |
965974a6 | 328 | IWL_ERR(drv, "File size too small!\n"); |
15854ef9 JB |
329 | return -EINVAL; |
330 | } | |
331 | build = le32_to_cpu(ucode->u.v2.build); | |
0cedacc5 DS |
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)); | |
15854ef9 JB |
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) { | |
965974a6 | 347 | IWL_ERR(drv, "File size too small!\n"); |
15854ef9 JB |
348 | return -EINVAL; |
349 | } | |
350 | build = 0; | |
0cedacc5 DS |
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)); | |
15854ef9 JB |
359 | src = ucode->u.v1.data; |
360 | break; | |
361 | } | |
362 | ||
363 | if (build) | |
364 | sprintf(buildstr, " build %u%s", build, | |
965974a6 | 365 | (drv->fw_index == UCODE_EXPERIMENTAL_INDEX) |
15854ef9 JB |
366 | ? " (EXP)" : ""); |
367 | else | |
368 | buildstr[0] = '\0'; | |
369 | ||
965974a6 JB |
370 | snprintf(drv->fw.fw_version, |
371 | sizeof(drv->fw.fw_version), | |
15854ef9 | 372 | "%u.%u.%u.%u%s", |
965974a6 JB |
373 | IWL_UCODE_MAJOR(drv->fw.ucode_ver), |
374 | IWL_UCODE_MINOR(drv->fw.ucode_ver), | |
375 | IWL_UCODE_API(drv->fw.ucode_ver), | |
376 | IWL_UCODE_SERIAL(drv->fw.ucode_ver), | |
15854ef9 JB |
377 | buildstr); |
378 | ||
379 | /* Verify size of file vs. image size info in file's header */ | |
0cedacc5 DS |
380 | |
381 | if (ucode_raw->size != hdr_size + | |
382 | get_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_INST) + | |
383 | get_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_DATA) + | |
384 | get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST) + | |
385 | get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA)) { | |
15854ef9 | 386 | |
965974a6 | 387 | IWL_ERR(drv, |
15854ef9 JB |
388 | "uCode file size %d does not match expected size\n", |
389 | (int)ucode_raw->size); | |
390 | return -EINVAL; | |
391 | } | |
392 | ||
15854ef9 | 393 | |
0cedacc5 DS |
394 | set_sec_data(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_INST, src); |
395 | src += get_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_INST); | |
396 | set_sec_offset(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_INST, | |
397 | IWLAGN_RTC_INST_LOWER_BOUND); | |
398 | set_sec_data(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_DATA, src); | |
399 | src += get_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_DATA); | |
400 | set_sec_offset(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_DATA, | |
401 | IWLAGN_RTC_DATA_LOWER_BOUND); | |
402 | set_sec_data(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST, src); | |
403 | src += get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST); | |
404 | set_sec_offset(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST, | |
405 | IWLAGN_RTC_INST_LOWER_BOUND); | |
406 | set_sec_data(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA, src); | |
407 | src += get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA); | |
408 | set_sec_offset(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA, | |
409 | IWLAGN_RTC_DATA_LOWER_BOUND); | |
15854ef9 JB |
410 | return 0; |
411 | } | |
412 | ||
965974a6 | 413 | static int iwl_parse_tlv_firmware(struct iwl_drv *drv, |
15854ef9 | 414 | const struct firmware *ucode_raw, |
0cedacc5 | 415 | struct iwl_firmware_pieces *pieces, |
15854ef9 JB |
416 | struct iwl_ucode_capabilities *capa) |
417 | { | |
418 | struct iwl_tlv_ucode_header *ucode = (void *)ucode_raw->data; | |
419 | struct iwl_ucode_tlv *tlv; | |
420 | size_t len = ucode_raw->size; | |
421 | const u8 *data; | |
15854ef9 JB |
422 | u32 tlv_len; |
423 | enum iwl_ucode_tlv_type tlv_type; | |
424 | const u8 *tlv_data; | |
425 | char buildstr[25]; | |
426 | u32 build; | |
427 | ||
428 | if (len < sizeof(*ucode)) { | |
965974a6 | 429 | IWL_ERR(drv, "uCode has invalid length: %zd\n", len); |
15854ef9 JB |
430 | return -EINVAL; |
431 | } | |
432 | ||
433 | if (ucode->magic != cpu_to_le32(IWL_TLV_UCODE_MAGIC)) { | |
965974a6 | 434 | IWL_ERR(drv, "invalid uCode magic: 0X%x\n", |
15854ef9 JB |
435 | le32_to_cpu(ucode->magic)); |
436 | return -EINVAL; | |
437 | } | |
438 | ||
965974a6 | 439 | drv->fw.ucode_ver = le32_to_cpu(ucode->ver); |
15854ef9 JB |
440 | build = le32_to_cpu(ucode->build); |
441 | ||
442 | if (build) | |
443 | sprintf(buildstr, " build %u%s", build, | |
965974a6 | 444 | (drv->fw_index == UCODE_EXPERIMENTAL_INDEX) |
15854ef9 JB |
445 | ? " (EXP)" : ""); |
446 | else | |
447 | buildstr[0] = '\0'; | |
448 | ||
965974a6 JB |
449 | snprintf(drv->fw.fw_version, |
450 | sizeof(drv->fw.fw_version), | |
15854ef9 | 451 | "%u.%u.%u.%u%s", |
965974a6 JB |
452 | IWL_UCODE_MAJOR(drv->fw.ucode_ver), |
453 | IWL_UCODE_MINOR(drv->fw.ucode_ver), | |
454 | IWL_UCODE_API(drv->fw.ucode_ver), | |
455 | IWL_UCODE_SERIAL(drv->fw.ucode_ver), | |
15854ef9 JB |
456 | buildstr); |
457 | ||
458 | data = ucode->data; | |
459 | ||
460 | len -= sizeof(*ucode); | |
461 | ||
462 | while (len >= sizeof(*tlv)) { | |
15854ef9 JB |
463 | len -= sizeof(*tlv); |
464 | tlv = (void *)data; | |
465 | ||
466 | tlv_len = le32_to_cpu(tlv->length); | |
0479c19d | 467 | tlv_type = le32_to_cpu(tlv->type); |
15854ef9 JB |
468 | tlv_data = tlv->data; |
469 | ||
470 | if (len < tlv_len) { | |
965974a6 | 471 | IWL_ERR(drv, "invalid TLV len: %zd/%u\n", |
15854ef9 JB |
472 | len, tlv_len); |
473 | return -EINVAL; | |
474 | } | |
475 | len -= ALIGN(tlv_len, 4); | |
476 | data += sizeof(*tlv) + ALIGN(tlv_len, 4); | |
477 | ||
15854ef9 JB |
478 | switch (tlv_type) { |
479 | case IWL_UCODE_TLV_INST: | |
0cedacc5 DS |
480 | set_sec_data(pieces, IWL_UCODE_REGULAR, |
481 | IWL_UCODE_SECTION_INST, tlv_data); | |
482 | set_sec_size(pieces, IWL_UCODE_REGULAR, | |
483 | IWL_UCODE_SECTION_INST, tlv_len); | |
484 | set_sec_offset(pieces, IWL_UCODE_REGULAR, | |
485 | IWL_UCODE_SECTION_INST, | |
486 | IWLAGN_RTC_INST_LOWER_BOUND); | |
15854ef9 JB |
487 | break; |
488 | case IWL_UCODE_TLV_DATA: | |
0cedacc5 DS |
489 | set_sec_data(pieces, IWL_UCODE_REGULAR, |
490 | IWL_UCODE_SECTION_DATA, tlv_data); | |
491 | set_sec_size(pieces, IWL_UCODE_REGULAR, | |
492 | IWL_UCODE_SECTION_DATA, tlv_len); | |
493 | set_sec_offset(pieces, IWL_UCODE_REGULAR, | |
494 | IWL_UCODE_SECTION_DATA, | |
495 | IWLAGN_RTC_DATA_LOWER_BOUND); | |
15854ef9 JB |
496 | break; |
497 | case IWL_UCODE_TLV_INIT: | |
0cedacc5 DS |
498 | set_sec_data(pieces, IWL_UCODE_INIT, |
499 | IWL_UCODE_SECTION_INST, tlv_data); | |
500 | set_sec_size(pieces, IWL_UCODE_INIT, | |
501 | IWL_UCODE_SECTION_INST, tlv_len); | |
502 | set_sec_offset(pieces, IWL_UCODE_INIT, | |
503 | IWL_UCODE_SECTION_INST, | |
504 | IWLAGN_RTC_INST_LOWER_BOUND); | |
15854ef9 JB |
505 | break; |
506 | case IWL_UCODE_TLV_INIT_DATA: | |
0cedacc5 DS |
507 | set_sec_data(pieces, IWL_UCODE_INIT, |
508 | IWL_UCODE_SECTION_DATA, tlv_data); | |
509 | set_sec_size(pieces, IWL_UCODE_INIT, | |
510 | IWL_UCODE_SECTION_DATA, tlv_len); | |
511 | set_sec_offset(pieces, IWL_UCODE_INIT, | |
512 | IWL_UCODE_SECTION_DATA, | |
513 | IWLAGN_RTC_DATA_LOWER_BOUND); | |
15854ef9 JB |
514 | break; |
515 | case IWL_UCODE_TLV_BOOT: | |
965974a6 | 516 | IWL_ERR(drv, "Found unexpected BOOT ucode\n"); |
15854ef9 JB |
517 | break; |
518 | case IWL_UCODE_TLV_PROBE_MAX_LEN: | |
519 | if (tlv_len != sizeof(u32)) | |
520 | goto invalid_tlv_len; | |
521 | capa->max_probe_length = | |
522 | le32_to_cpup((__le32 *)tlv_data); | |
523 | break; | |
524 | case IWL_UCODE_TLV_PAN: | |
525 | if (tlv_len) | |
526 | goto invalid_tlv_len; | |
527 | capa->flags |= IWL_UCODE_TLV_FLAGS_PAN; | |
528 | break; | |
529 | case IWL_UCODE_TLV_FLAGS: | |
530 | /* must be at least one u32 */ | |
531 | if (tlv_len < sizeof(u32)) | |
532 | goto invalid_tlv_len; | |
533 | /* and a proper number of u32s */ | |
534 | if (tlv_len % sizeof(u32)) | |
535 | goto invalid_tlv_len; | |
536 | /* | |
537 | * This driver only reads the first u32 as | |
538 | * right now no more features are defined, | |
539 | * if that changes then either the driver | |
540 | * will not work with the new firmware, or | |
541 | * it'll not take advantage of new features. | |
542 | */ | |
543 | capa->flags = le32_to_cpup((__le32 *)tlv_data); | |
544 | break; | |
545 | case IWL_UCODE_TLV_INIT_EVTLOG_PTR: | |
546 | if (tlv_len != sizeof(u32)) | |
547 | goto invalid_tlv_len; | |
548 | pieces->init_evtlog_ptr = | |
549 | le32_to_cpup((__le32 *)tlv_data); | |
550 | break; | |
551 | case IWL_UCODE_TLV_INIT_EVTLOG_SIZE: | |
552 | if (tlv_len != sizeof(u32)) | |
553 | goto invalid_tlv_len; | |
554 | pieces->init_evtlog_size = | |
555 | le32_to_cpup((__le32 *)tlv_data); | |
556 | break; | |
557 | case IWL_UCODE_TLV_INIT_ERRLOG_PTR: | |
558 | if (tlv_len != sizeof(u32)) | |
559 | goto invalid_tlv_len; | |
560 | pieces->init_errlog_ptr = | |
561 | le32_to_cpup((__le32 *)tlv_data); | |
562 | break; | |
563 | case IWL_UCODE_TLV_RUNT_EVTLOG_PTR: | |
564 | if (tlv_len != sizeof(u32)) | |
565 | goto invalid_tlv_len; | |
566 | pieces->inst_evtlog_ptr = | |
567 | le32_to_cpup((__le32 *)tlv_data); | |
568 | break; | |
569 | case IWL_UCODE_TLV_RUNT_EVTLOG_SIZE: | |
570 | if (tlv_len != sizeof(u32)) | |
571 | goto invalid_tlv_len; | |
572 | pieces->inst_evtlog_size = | |
573 | le32_to_cpup((__le32 *)tlv_data); | |
574 | break; | |
575 | case IWL_UCODE_TLV_RUNT_ERRLOG_PTR: | |
576 | if (tlv_len != sizeof(u32)) | |
577 | goto invalid_tlv_len; | |
578 | pieces->inst_errlog_ptr = | |
579 | le32_to_cpup((__le32 *)tlv_data); | |
580 | break; | |
581 | case IWL_UCODE_TLV_ENHANCE_SENS_TBL: | |
582 | if (tlv_len) | |
583 | goto invalid_tlv_len; | |
965974a6 | 584 | drv->fw.enhance_sensitivity_table = true; |
15854ef9 JB |
585 | break; |
586 | case IWL_UCODE_TLV_WOWLAN_INST: | |
0cedacc5 DS |
587 | set_sec_data(pieces, IWL_UCODE_WOWLAN, |
588 | IWL_UCODE_SECTION_INST, tlv_data); | |
589 | set_sec_size(pieces, IWL_UCODE_WOWLAN, | |
590 | IWL_UCODE_SECTION_INST, tlv_len); | |
591 | set_sec_offset(pieces, IWL_UCODE_WOWLAN, | |
592 | IWL_UCODE_SECTION_INST, | |
593 | IWLAGN_RTC_INST_LOWER_BOUND); | |
15854ef9 JB |
594 | break; |
595 | case IWL_UCODE_TLV_WOWLAN_DATA: | |
0cedacc5 DS |
596 | set_sec_data(pieces, IWL_UCODE_WOWLAN, |
597 | IWL_UCODE_SECTION_DATA, tlv_data); | |
598 | set_sec_size(pieces, IWL_UCODE_WOWLAN, | |
599 | IWL_UCODE_SECTION_DATA, tlv_len); | |
600 | set_sec_offset(pieces, IWL_UCODE_WOWLAN, | |
601 | IWL_UCODE_SECTION_DATA, | |
602 | IWLAGN_RTC_DATA_LOWER_BOUND); | |
15854ef9 JB |
603 | break; |
604 | case IWL_UCODE_TLV_PHY_CALIBRATION_SIZE: | |
605 | if (tlv_len != sizeof(u32)) | |
606 | goto invalid_tlv_len; | |
607 | capa->standard_phy_calibration_size = | |
608 | le32_to_cpup((__le32 *)tlv_data); | |
609 | break; | |
ed8c8365 DS |
610 | case IWL_UCODE_TLV_SEC_RT: |
611 | iwl_store_ucode_sec(pieces, tlv_data, IWL_UCODE_REGULAR, | |
612 | tlv_len); | |
4db2c9ae | 613 | drv->fw.mvm_fw = true; |
ed8c8365 DS |
614 | break; |
615 | case IWL_UCODE_TLV_SEC_INIT: | |
616 | iwl_store_ucode_sec(pieces, tlv_data, IWL_UCODE_INIT, | |
617 | tlv_len); | |
4db2c9ae | 618 | drv->fw.mvm_fw = true; |
ed8c8365 DS |
619 | break; |
620 | case IWL_UCODE_TLV_SEC_WOWLAN: | |
621 | iwl_store_ucode_sec(pieces, tlv_data, IWL_UCODE_WOWLAN, | |
622 | tlv_len); | |
4db2c9ae | 623 | drv->fw.mvm_fw = true; |
ed8c8365 DS |
624 | break; |
625 | case IWL_UCODE_TLV_DEF_CALIB: | |
626 | if (tlv_len != sizeof(struct iwl_tlv_calib_data)) | |
627 | goto invalid_tlv_len; | |
628 | if (iwl_set_default_calib(drv, tlv_data)) | |
629 | goto tlv_error; | |
630 | break; | |
631 | case IWL_UCODE_TLV_PHY_SKU: | |
632 | if (tlv_len != sizeof(u32)) | |
633 | goto invalid_tlv_len; | |
634 | drv->fw.phy_config = le32_to_cpup((__le32 *)tlv_data); | |
635 | break; | |
15854ef9 | 636 | default: |
965974a6 | 637 | IWL_DEBUG_INFO(drv, "unknown TLV: %d\n", tlv_type); |
15854ef9 JB |
638 | break; |
639 | } | |
640 | } | |
641 | ||
642 | if (len) { | |
965974a6 JB |
643 | IWL_ERR(drv, "invalid TLV after parsing: %zd\n", len); |
644 | iwl_print_hex_dump(drv, IWL_DL_FW, (u8 *)data, len); | |
15854ef9 JB |
645 | return -EINVAL; |
646 | } | |
647 | ||
648 | return 0; | |
649 | ||
650 | invalid_tlv_len: | |
965974a6 | 651 | IWL_ERR(drv, "TLV %d has invalid size: %u\n", tlv_type, tlv_len); |
ed8c8365 | 652 | tlv_error: |
965974a6 | 653 | iwl_print_hex_dump(drv, IWL_DL_FW, tlv_data, tlv_len); |
15854ef9 JB |
654 | |
655 | return -EINVAL; | |
656 | } | |
657 | ||
6dfa8d01 DS |
658 | static int alloc_pci_desc(struct iwl_drv *drv, |
659 | struct iwl_firmware_pieces *pieces, | |
660 | enum iwl_ucode_type type) | |
661 | { | |
662 | int i; | |
663 | for (i = 0; | |
664 | i < IWL_UCODE_SECTION_MAX && get_sec_size(pieces, type, i); | |
665 | i++) | |
666 | if (iwl_alloc_fw_desc(drv, &(drv->fw.img[type].sec[i]), | |
667 | get_sec(pieces, type, i))) | |
668 | return -1; | |
669 | return 0; | |
670 | } | |
671 | ||
672 | static int validate_sec_sizes(struct iwl_drv *drv, | |
673 | struct iwl_firmware_pieces *pieces, | |
674 | const struct iwl_cfg *cfg) | |
675 | { | |
676 | IWL_DEBUG_INFO(drv, "f/w package hdr runtime inst size = %Zd\n", | |
677 | get_sec_size(pieces, IWL_UCODE_REGULAR, | |
678 | IWL_UCODE_SECTION_INST)); | |
679 | IWL_DEBUG_INFO(drv, "f/w package hdr runtime data size = %Zd\n", | |
680 | get_sec_size(pieces, IWL_UCODE_REGULAR, | |
681 | IWL_UCODE_SECTION_DATA)); | |
682 | IWL_DEBUG_INFO(drv, "f/w package hdr init inst size = %Zd\n", | |
683 | get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST)); | |
684 | IWL_DEBUG_INFO(drv, "f/w package hdr init data size = %Zd\n", | |
685 | get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA)); | |
686 | ||
687 | /* Verify that uCode images will fit in card's SRAM. */ | |
688 | if (get_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_INST) > | |
689 | cfg->max_inst_size) { | |
690 | IWL_ERR(drv, "uCode instr len %Zd too large to fit in\n", | |
691 | get_sec_size(pieces, IWL_UCODE_REGULAR, | |
692 | IWL_UCODE_SECTION_INST)); | |
693 | return -1; | |
694 | } | |
695 | ||
696 | if (get_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_DATA) > | |
697 | cfg->max_data_size) { | |
698 | IWL_ERR(drv, "uCode data len %Zd too large to fit in\n", | |
699 | get_sec_size(pieces, IWL_UCODE_REGULAR, | |
700 | IWL_UCODE_SECTION_DATA)); | |
701 | return -1; | |
702 | } | |
703 | ||
704 | if (get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST) > | |
705 | cfg->max_inst_size) { | |
706 | IWL_ERR(drv, "uCode init instr len %Zd too large to fit in\n", | |
707 | get_sec_size(pieces, IWL_UCODE_INIT, | |
708 | IWL_UCODE_SECTION_INST)); | |
709 | return -1; | |
710 | } | |
711 | ||
712 | if (get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA) > | |
713 | cfg->max_data_size) { | |
714 | IWL_ERR(drv, "uCode init data len %Zd too large to fit in\n", | |
715 | get_sec_size(pieces, IWL_UCODE_REGULAR, | |
716 | IWL_UCODE_SECTION_DATA)); | |
717 | return -1; | |
718 | } | |
719 | return 0; | |
720 | } | |
721 | ||
722 | ||
15854ef9 JB |
723 | /** |
724 | * iwl_ucode_callback - callback when firmware was loaded | |
725 | * | |
726 | * If loaded successfully, copies the firmware into buffers | |
727 | * for the card to fetch (via DMA). | |
728 | */ | |
729 | static void iwl_ucode_callback(const struct firmware *ucode_raw, void *context) | |
730 | { | |
965974a6 | 731 | struct iwl_drv *drv = context; |
965974a6 | 732 | struct iwl_fw *fw = &drv->fw; |
15854ef9 JB |
733 | struct iwl_ucode_header *ucode; |
734 | int err; | |
0cedacc5 | 735 | struct iwl_firmware_pieces pieces; |
68f360dc EG |
736 | const unsigned int api_max = drv->cfg->ucode_api_max; |
737 | unsigned int api_ok = drv->cfg->ucode_api_ok; | |
738 | const unsigned int api_min = drv->cfg->ucode_api_min; | |
15854ef9 | 739 | u32 api_ver; |
6dfa8d01 | 740 | int i; |
15854ef9 JB |
741 | |
742 | fw->ucode_capa.max_probe_length = 200; | |
743 | fw->ucode_capa.standard_phy_calibration_size = | |
744 | IWL_DEFAULT_STANDARD_PHY_CALIBRATE_TBL_SIZE; | |
745 | ||
746 | if (!api_ok) | |
747 | api_ok = api_max; | |
748 | ||
749 | memset(&pieces, 0, sizeof(pieces)); | |
750 | ||
751 | if (!ucode_raw) { | |
965974a6 JB |
752 | if (drv->fw_index <= api_ok) |
753 | IWL_ERR(drv, | |
15854ef9 | 754 | "request for firmware file '%s' failed.\n", |
965974a6 | 755 | drv->firmware_name); |
15854ef9 JB |
756 | goto try_again; |
757 | } | |
758 | ||
965974a6 JB |
759 | IWL_DEBUG_INFO(drv, "Loaded firmware file '%s' (%zd bytes).\n", |
760 | drv->firmware_name, ucode_raw->size); | |
15854ef9 JB |
761 | |
762 | /* Make sure that we got at least the API version number */ | |
763 | if (ucode_raw->size < 4) { | |
965974a6 | 764 | IWL_ERR(drv, "File size way too small!\n"); |
15854ef9 JB |
765 | goto try_again; |
766 | } | |
767 | ||
768 | /* Data from ucode file: header followed by uCode images */ | |
769 | ucode = (struct iwl_ucode_header *)ucode_raw->data; | |
770 | ||
771 | if (ucode->ver) | |
965974a6 | 772 | err = iwl_parse_v1_v2_firmware(drv, ucode_raw, &pieces); |
15854ef9 | 773 | else |
965974a6 | 774 | err = iwl_parse_tlv_firmware(drv, ucode_raw, &pieces, |
15854ef9 JB |
775 | &fw->ucode_capa); |
776 | ||
777 | if (err) | |
778 | goto try_again; | |
779 | ||
965974a6 | 780 | api_ver = IWL_UCODE_API(drv->fw.ucode_ver); |
15854ef9 JB |
781 | |
782 | /* | |
783 | * api_ver should match the api version forming part of the | |
784 | * firmware filename ... but we don't check for that and only rely | |
785 | * on the API version read from firmware header from here on forward | |
786 | */ | |
787 | /* no api version check required for experimental uCode */ | |
965974a6 | 788 | if (drv->fw_index != UCODE_EXPERIMENTAL_INDEX) { |
15854ef9 | 789 | if (api_ver < api_min || api_ver > api_max) { |
965974a6 | 790 | IWL_ERR(drv, |
15854ef9 JB |
791 | "Driver unable to support your firmware API. " |
792 | "Driver supports v%u, firmware is v%u.\n", | |
793 | api_max, api_ver); | |
794 | goto try_again; | |
795 | } | |
796 | ||
797 | if (api_ver < api_ok) { | |
798 | if (api_ok != api_max) | |
965974a6 | 799 | IWL_ERR(drv, "Firmware has old API version, " |
15854ef9 JB |
800 | "expected v%u through v%u, got v%u.\n", |
801 | api_ok, api_max, api_ver); | |
802 | else | |
965974a6 | 803 | IWL_ERR(drv, "Firmware has old API version, " |
15854ef9 JB |
804 | "expected v%u, got v%u.\n", |
805 | api_max, api_ver); | |
965974a6 | 806 | IWL_ERR(drv, "New firmware can be obtained from " |
15854ef9 JB |
807 | "http://www.intellinuxwireless.org/.\n"); |
808 | } | |
809 | } | |
810 | ||
965974a6 | 811 | IWL_INFO(drv, "loaded firmware version %s", drv->fw.fw_version); |
15854ef9 | 812 | |
4db2c9ae DS |
813 | /* |
814 | * In mvm uCode there is no difference between data and instructions | |
815 | * sections. | |
816 | */ | |
68f360dc | 817 | if (!fw->mvm_fw && validate_sec_sizes(drv, &pieces, drv->cfg)) |
15854ef9 | 818 | goto try_again; |
15854ef9 JB |
819 | |
820 | /* Allocate ucode buffers for card's bus-master loading ... */ | |
821 | ||
822 | /* Runtime instructions and 2 copies of data: | |
823 | * 1) unmodified from disk | |
824 | * 2) backup cache for save/restore during power-downs */ | |
6dfa8d01 DS |
825 | for (i = 0; i < IWL_UCODE_TYPE_MAX; i++) |
826 | if (alloc_pci_desc(drv, &pieces, i)) | |
15854ef9 | 827 | goto err_pci_alloc; |
15854ef9 JB |
828 | |
829 | /* Now that we can no longer fail, copy information */ | |
830 | ||
831 | /* | |
832 | * The (size - 16) / 12 formula is based on the information recorded | |
833 | * for each event, which is of mode 1 (including timestamp) for all | |
834 | * new microcodes that include this information. | |
835 | */ | |
0692fe41 | 836 | fw->init_evtlog_ptr = pieces.init_evtlog_ptr; |
15854ef9 | 837 | if (pieces.init_evtlog_size) |
0692fe41 | 838 | fw->init_evtlog_size = (pieces.init_evtlog_size - 16)/12; |
15854ef9 | 839 | else |
0692fe41 | 840 | fw->init_evtlog_size = |
68f360dc | 841 | drv->cfg->base_params->max_event_log_size; |
0692fe41 JB |
842 | fw->init_errlog_ptr = pieces.init_errlog_ptr; |
843 | fw->inst_evtlog_ptr = pieces.inst_evtlog_ptr; | |
15854ef9 | 844 | if (pieces.inst_evtlog_size) |
0692fe41 | 845 | fw->inst_evtlog_size = (pieces.inst_evtlog_size - 16)/12; |
15854ef9 | 846 | else |
0692fe41 | 847 | fw->inst_evtlog_size = |
68f360dc | 848 | drv->cfg->base_params->max_event_log_size; |
0692fe41 | 849 | fw->inst_errlog_ptr = pieces.inst_errlog_ptr; |
15854ef9 JB |
850 | |
851 | /* | |
852 | * figure out the offset of chain noise reset and gain commands | |
853 | * base on the size of standard phy calibration commands table size | |
854 | */ | |
855 | if (fw->ucode_capa.standard_phy_calibration_size > | |
856 | IWL_MAX_PHY_CALIBRATE_TBL_SIZE) | |
857 | fw->ucode_capa.standard_phy_calibration_size = | |
858 | IWL_MAX_STANDARD_PHY_CALIBRATE_TBL_SIZE; | |
859 | ||
860 | /* We have our copies now, allow OS release its copies */ | |
861 | release_firmware(ucode_raw); | |
965974a6 | 862 | complete(&drv->request_firmware_complete); |
15854ef9 | 863 | |
68f360dc | 864 | drv->op_mode = iwl_dvm_ops.start(drv->trans, drv->cfg, &drv->fw); |
15854ef9 | 865 | |
965974a6 | 866 | if (!drv->op_mode) |
15854ef9 JB |
867 | goto out_unbind; |
868 | ||
869 | return; | |
870 | ||
871 | try_again: | |
872 | /* try next, if any */ | |
873 | release_firmware(ucode_raw); | |
965974a6 | 874 | if (iwl_request_firmware(drv, false)) |
15854ef9 JB |
875 | goto out_unbind; |
876 | return; | |
877 | ||
878 | err_pci_alloc: | |
965974a6 JB |
879 | IWL_ERR(drv, "failed to allocate pci memory\n"); |
880 | iwl_dealloc_ucode(drv); | |
15854ef9 JB |
881 | release_firmware(ucode_raw); |
882 | out_unbind: | |
965974a6 | 883 | complete(&drv->request_firmware_complete); |
93faaeea | 884 | device_release_driver(drv->trans->dev); |
15854ef9 JB |
885 | } |
886 | ||
87ce05a2 | 887 | struct iwl_drv *iwl_drv_start(struct iwl_trans *trans, |
9130bab1 | 888 | const struct iwl_cfg *cfg) |
5c58edc6 | 889 | { |
965974a6 | 890 | struct iwl_drv *drv; |
5c58edc6 EG |
891 | int ret; |
892 | ||
965974a6 JB |
893 | drv = kzalloc(sizeof(*drv), GFP_KERNEL); |
894 | if (!drv) { | |
895 | dev_printk(KERN_ERR, trans->dev, "Couldn't allocate iwl_drv"); | |
9130bab1 | 896 | return NULL; |
5c58edc6 | 897 | } |
9130bab1 | 898 | drv->trans = trans; |
4b9844f5 | 899 | drv->dev = trans->dev; |
68f360dc | 900 | drv->cfg = cfg; |
5c58edc6 | 901 | |
965974a6 | 902 | init_completion(&drv->request_firmware_complete); |
5c58edc6 | 903 | |
965974a6 | 904 | ret = iwl_request_firmware(drv, true); |
5c58edc6 EG |
905 | |
906 | if (ret) { | |
907 | dev_printk(KERN_ERR, trans->dev, "Couldn't request the fw"); | |
965974a6 | 908 | kfree(drv); |
9130bab1 | 909 | drv = NULL; |
5c58edc6 EG |
910 | } |
911 | ||
9130bab1 | 912 | return drv; |
5c58edc6 EG |
913 | } |
914 | ||
9130bab1 | 915 | void iwl_drv_stop(struct iwl_drv *drv) |
07590f08 | 916 | { |
965974a6 | 917 | wait_for_completion(&drv->request_firmware_complete); |
2e7eb117 | 918 | |
d0f76d68 | 919 | /* op_mode can be NULL if its start failed */ |
965974a6 JB |
920 | if (drv->op_mode) |
921 | iwl_op_mode_stop(drv->op_mode); | |
07590f08 | 922 | |
965974a6 | 923 | iwl_dealloc_ucode(drv); |
7db5b989 | 924 | |
965974a6 | 925 | kfree(drv); |
07590f08 | 926 | } |