iwlagn: more ucode error log info
[deliverable/linux.git] / drivers / net / wireless / iwlwifi / iwl-sv-open.c
CommitLineData
4613e72d
CK
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) 2010 - 2011 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) 2010 - 2011 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/init.h>
64#include <linux/kernel.h>
65#include <linux/module.h>
66#include <net/net_namespace.h>
67#include <linux/netdevice.h>
68#include <net/cfg80211.h>
69#include <net/mac80211.h>
70#include <net/netlink.h>
71
72
73#include "iwl-dev.h"
74#include "iwl-core.h"
75#include "iwl-debug.h"
76#include "iwl-fh.h"
77#include "iwl-io.h"
78#include "iwl-agn.h"
79#include "iwl-testmode.h"
80
81
82/* The TLVs used in the gnl message policy between the kernel module and
83 * user space application. iwl_testmode_gnl_msg_policy is to be carried
84 * through the NL80211_CMD_TESTMODE channel regulated by nl80211.
85 * See iwl-testmode.h
86 */
87static
88struct nla_policy iwl_testmode_gnl_msg_policy[IWL_TM_ATTR_MAX] = {
89 [IWL_TM_ATTR_COMMAND] = { .type = NLA_U32, },
90
91 [IWL_TM_ATTR_UCODE_CMD_ID] = { .type = NLA_U8, },
92 [IWL_TM_ATTR_UCODE_CMD_DATA] = { .type = NLA_UNSPEC, },
93
94 [IWL_TM_ATTR_REG_OFFSET] = { .type = NLA_U32, },
95 [IWL_TM_ATTR_REG_VALUE8] = { .type = NLA_U8, },
96 [IWL_TM_ATTR_REG_VALUE32] = { .type = NLA_U32, },
97
98 [IWL_TM_ATTR_SYNC_RSP] = { .type = NLA_UNSPEC, },
99 [IWL_TM_ATTR_UCODE_RX_PKT] = { .type = NLA_UNSPEC, },
100};
101
102/*
103 * See the struct iwl_rx_packet in iwl-commands.h for the format of the
104 * received events from the device
105 */
106static inline int get_event_length(struct iwl_rx_mem_buffer *rxb)
107{
108 struct iwl_rx_packet *pkt = rxb_addr(rxb);
109 if (pkt)
110 return le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK;
111 else
112 return 0;
113}
114
115
116/*
117 * This function multicasts the spontaneous messages from the device to the
118 * user space. It is invoked whenever there is a received messages
119 * from the device. This function is called within the ISR of the rx handlers
120 * in iwlagn driver.
121 *
122 * The parsing of the message content is left to the user space application,
123 * The message content is treated as unattacked raw data and is encapsulated
124 * with IWL_TM_ATTR_UCODE_RX_PKT multicasting to the user space.
125 *
126 * @priv: the instance of iwlwifi device
127 * @rxb: pointer to rx data content received by the ISR
128 *
129 * See the message policies and TLVs in iwl_testmode_gnl_msg_policy[].
130 * For the messages multicasting to the user application, the mandatory
131 * TLV fields are :
132 * IWL_TM_ATTR_COMMAND must be IWL_TM_CMD_DEV2APP_UCODE_RX_PKT
133 * IWL_TM_ATTR_UCODE_RX_PKT for carrying the message content
134 */
135
136static void iwl_testmode_ucode_rx_pkt(struct iwl_priv *priv,
137 struct iwl_rx_mem_buffer *rxb)
138{
139 struct ieee80211_hw *hw = priv->hw;
140 struct sk_buff *skb;
141 void *data;
142 int length;
143
144 data = (void *)rxb_addr(rxb);
145 length = get_event_length(rxb);
146
147 if (!data || length == 0)
148 return;
149
150 skb = cfg80211_testmode_alloc_event_skb(hw->wiphy, 20 + length,
151 GFP_ATOMIC);
152 if (skb == NULL) {
153 IWL_DEBUG_INFO(priv,
154 "Run out of memory for messages to user space ?\n");
155 return;
156 }
157 NLA_PUT_U32(skb, IWL_TM_ATTR_COMMAND, IWL_TM_CMD_DEV2APP_UCODE_RX_PKT);
158 NLA_PUT(skb, IWL_TM_ATTR_UCODE_RX_PKT, length, data);
159 cfg80211_testmode_event(skb, GFP_ATOMIC);
160 return;
161
162nla_put_failure:
163 kfree_skb(skb);
164 IWL_DEBUG_INFO(priv, "Ouch, overran buffer, check allocation!\n");
165}
166
167void iwl_testmode_init(struct iwl_priv *priv)
168{
169 priv->pre_rx_handler = iwl_testmode_ucode_rx_pkt;
170}
171
172/*
173 * This function handles the user application commands to the ucode.
174 *
175 * It retrieves the mandatory fields IWL_TM_ATTR_UCODE_CMD_ID and
176 * IWL_TM_ATTR_UCODE_CMD_DATA and calls to the handler to send the
177 * host command to the ucode.
178 *
179 * If any mandatory field is missing, -ENOMSG is replied to the user space
180 * application; otherwise, the actual execution result of the host command to
181 * ucode is replied.
182 *
183 * @hw: ieee80211_hw object that represents the device
184 * @tb: gnl message fields from the user space
185 */
186static int iwl_testmode_ucode(struct ieee80211_hw *hw, struct nlattr **tb)
187{
188 struct iwl_priv *priv = hw->priv;
189 struct iwl_host_cmd cmd;
190
191 memset(&cmd, 0, sizeof(struct iwl_host_cmd));
192
193 if (!tb[IWL_TM_ATTR_UCODE_CMD_ID] ||
194 !tb[IWL_TM_ATTR_UCODE_CMD_DATA]) {
195 IWL_DEBUG_INFO(priv,
196 "Error finding ucode command mandatory fields\n");
197 return -ENOMSG;
198 }
199
200 cmd.id = nla_get_u8(tb[IWL_TM_ATTR_UCODE_CMD_ID]);
3fa50738
JB
201 cmd.data[0] = nla_data(tb[IWL_TM_ATTR_UCODE_CMD_DATA]);
202 cmd.len[0] = nla_len(tb[IWL_TM_ATTR_UCODE_CMD_DATA]);
4ce7cc2b 203 cmd.dataflags[0] = IWL_HCMD_DFL_NOCOPY;
4613e72d 204 IWL_INFO(priv, "testmode ucode command ID 0x%x, flags 0x%x,"
3fa50738 205 " len %d\n", cmd.id, cmd.flags, cmd.len[0]);
4613e72d
CK
206 /* ok, let's submit the command to ucode */
207 return iwl_send_cmd(priv, &cmd);
208}
209
210
211/*
212 * This function handles the user application commands for register access.
213 *
214 * It retrieves command ID carried with IWL_TM_ATTR_COMMAND and calls to the
215 * handlers respectively.
216 *
217 * If it's an unknown commdn ID, -ENOSYS is returned; or -ENOMSG if the
218 * mandatory fields(IWL_TM_ATTR_REG_OFFSET,IWL_TM_ATTR_REG_VALUE32,
219 * IWL_TM_ATTR_REG_VALUE8) are missing; Otherwise 0 is replied indicating
220 * the success of the command execution.
221 *
222 * If IWL_TM_ATTR_COMMAND is IWL_TM_CMD_APP2DEV_REG_READ32, the register read
223 * value is returned with IWL_TM_ATTR_REG_VALUE32.
224 *
225 * @hw: ieee80211_hw object that represents the device
226 * @tb: gnl message fields from the user space
227 */
228static int iwl_testmode_reg(struct ieee80211_hw *hw, struct nlattr **tb)
229{
230 struct iwl_priv *priv = hw->priv;
231 u32 ofs, val32;
232 u8 val8;
233 struct sk_buff *skb;
234 int status = 0;
235
236 if (!tb[IWL_TM_ATTR_REG_OFFSET]) {
237 IWL_DEBUG_INFO(priv, "Error finding register offset\n");
238 return -ENOMSG;
239 }
240 ofs = nla_get_u32(tb[IWL_TM_ATTR_REG_OFFSET]);
241 IWL_INFO(priv, "testmode register access command offset 0x%x\n", ofs);
242
243 switch (nla_get_u32(tb[IWL_TM_ATTR_COMMAND])) {
244 case IWL_TM_CMD_APP2DEV_REG_READ32:
245 val32 = iwl_read32(priv, ofs);
246 IWL_INFO(priv, "32bit value to read 0x%x\n", val32);
247
248 skb = cfg80211_testmode_alloc_reply_skb(hw->wiphy, 20);
249 if (!skb) {
250 IWL_DEBUG_INFO(priv, "Error allocating memory\n");
251 return -ENOMEM;
252 }
253 NLA_PUT_U32(skb, IWL_TM_ATTR_REG_VALUE32, val32);
254 status = cfg80211_testmode_reply(skb);
255 if (status < 0)
256 IWL_DEBUG_INFO(priv,
257 "Error sending msg : %d\n", status);
258 break;
259 case IWL_TM_CMD_APP2DEV_REG_WRITE32:
260 if (!tb[IWL_TM_ATTR_REG_VALUE32]) {
261 IWL_DEBUG_INFO(priv,
262 "Error finding value to write\n");
263 return -ENOMSG;
264 } else {
265 val32 = nla_get_u32(tb[IWL_TM_ATTR_REG_VALUE32]);
266 IWL_INFO(priv, "32bit value to write 0x%x\n", val32);
267 iwl_write32(priv, ofs, val32);
268 }
269 break;
270 case IWL_TM_CMD_APP2DEV_REG_WRITE8:
271 if (!tb[IWL_TM_ATTR_REG_VALUE8]) {
272 IWL_DEBUG_INFO(priv, "Error finding value to write\n");
273 return -ENOMSG;
274 } else {
275 val8 = nla_get_u8(tb[IWL_TM_ATTR_REG_VALUE8]);
276 IWL_INFO(priv, "8bit value to write 0x%x\n", val8);
277 iwl_write8(priv, ofs, val8);
278 }
279 break;
280 default:
281 IWL_DEBUG_INFO(priv, "Unknown testmode register command ID\n");
282 return -ENOSYS;
283 }
284
285 return status;
286
287nla_put_failure:
288 kfree_skb(skb);
289 return -EMSGSIZE;
290}
291
292
293static int iwl_testmode_cfg_init_calib(struct iwl_priv *priv)
294{
295 struct iwl_notification_wait calib_wait;
296 int ret;
297
298 iwlagn_init_notification_wait(priv, &calib_wait,
299 CALIBRATION_COMPLETE_NOTIFICATION,
300 NULL, NULL);
301 ret = iwlagn_init_alive_start(priv);
302 if (ret) {
303 IWL_DEBUG_INFO(priv,
304 "Error configuring init calibration: %d\n", ret);
305 goto cfg_init_calib_error;
306 }
307
308 ret = iwlagn_wait_notification(priv, &calib_wait, 2 * HZ);
309 if (ret)
310 IWL_DEBUG_INFO(priv, "Error detecting"
311 " CALIBRATION_COMPLETE_NOTIFICATION: %d\n", ret);
312 return ret;
313
314cfg_init_calib_error:
315 iwlagn_remove_notification(priv, &calib_wait);
316 return ret;
317}
318
319/*
320 * This function handles the user application commands for driver.
321 *
322 * It retrieves command ID carried with IWL_TM_ATTR_COMMAND and calls to the
323 * handlers respectively.
324 *
325 * If it's an unknown commdn ID, -ENOSYS is replied; otherwise, the returned
326 * value of the actual command execution is replied to the user application.
327 *
328 * If there's any message responding to the user space, IWL_TM_ATTR_SYNC_RSP
329 * is used for carry the message while IWL_TM_ATTR_COMMAND must set to
330 * IWL_TM_CMD_DEV2APP_SYNC_RSP.
331 *
332 * @hw: ieee80211_hw object that represents the device
333 * @tb: gnl message fields from the user space
334 */
335static int iwl_testmode_driver(struct ieee80211_hw *hw, struct nlattr **tb)
336{
337 struct iwl_priv *priv = hw->priv;
338 struct sk_buff *skb;
339 unsigned char *rsp_data_ptr = NULL;
340 int status = 0, rsp_data_len = 0;
341
342 switch (nla_get_u32(tb[IWL_TM_ATTR_COMMAND])) {
343 case IWL_TM_CMD_APP2DEV_GET_DEVICENAME:
344 rsp_data_ptr = (unsigned char *)priv->cfg->name;
345 rsp_data_len = strlen(priv->cfg->name);
346 skb = cfg80211_testmode_alloc_reply_skb(hw->wiphy,
347 rsp_data_len + 20);
348 if (!skb) {
349 IWL_DEBUG_INFO(priv,
350 "Error allocating memory\n");
351 return -ENOMEM;
352 }
353 NLA_PUT_U32(skb, IWL_TM_ATTR_COMMAND,
354 IWL_TM_CMD_DEV2APP_SYNC_RSP);
355 NLA_PUT(skb, IWL_TM_ATTR_SYNC_RSP,
356 rsp_data_len, rsp_data_ptr);
357 status = cfg80211_testmode_reply(skb);
358 if (status < 0)
359 IWL_DEBUG_INFO(priv, "Error sending msg : %d\n",
360 status);
361 break;
362
363 case IWL_TM_CMD_APP2DEV_LOAD_INIT_FW:
364 status = iwlagn_load_ucode_wait_alive(priv, &priv->ucode_init,
365 UCODE_SUBTYPE_INIT, -1);
366 if (status)
367 IWL_DEBUG_INFO(priv,
368 "Error loading init ucode: %d\n", status);
369 break;
370
371 case IWL_TM_CMD_APP2DEV_CFG_INIT_CALIB:
372 iwl_testmode_cfg_init_calib(priv);
373 iwlagn_stop_device(priv);
374 break;
375
376 case IWL_TM_CMD_APP2DEV_LOAD_RUNTIME_FW:
377 status = iwlagn_load_ucode_wait_alive(priv,
378 &priv->ucode_rt,
379 UCODE_SUBTYPE_REGULAR,
380 UCODE_SUBTYPE_REGULAR_NEW);
381 if (status) {
382 IWL_DEBUG_INFO(priv,
383 "Error loading runtime ucode: %d\n", status);
384 break;
385 }
386 status = iwl_alive_start(priv);
387 if (status)
388 IWL_DEBUG_INFO(priv,
389 "Error starting the device: %d\n", status);
390 break;
391
392 default:
393 IWL_DEBUG_INFO(priv, "Unknown testmode driver command ID\n");
394 return -ENOSYS;
395 }
396 return status;
397
398nla_put_failure:
399 kfree_skb(skb);
400 return -EMSGSIZE;
401}
402
403/* The testmode gnl message handler that takes the gnl message from the
404 * user space and parses it per the policy iwl_testmode_gnl_msg_policy, then
405 * invoke the corresponding handlers.
406 *
407 * This function is invoked when there is user space application sending
408 * gnl message through the testmode tunnel NL80211_CMD_TESTMODE regulated
409 * by nl80211.
410 *
411 * It retrieves the mandatory field, IWL_TM_ATTR_COMMAND, before
412 * dispatching it to the corresponding handler.
413 *
414 * If IWL_TM_ATTR_COMMAND is missing, -ENOMSG is replied to user application;
415 * -ENOSYS is replied to the user application if the command is unknown;
416 * Otherwise, the command is dispatched to the respective handler.
417 *
418 * @hw: ieee80211_hw object that represents the device
419 * @data: pointer to user space message
420 * @len: length in byte of @data
421 */
422int iwl_testmode_cmd(struct ieee80211_hw *hw, void *data, int len)
423{
424 struct nlattr *tb[IWL_TM_ATTR_MAX - 1];
425 struct iwl_priv *priv = hw->priv;
426 int result;
427
428 result = nla_parse(tb, IWL_TM_ATTR_MAX - 1, data, len,
429 iwl_testmode_gnl_msg_policy);
430 if (result != 0) {
431 IWL_DEBUG_INFO(priv,
432 "Error parsing the gnl message : %d\n", result);
433 return result;
434 }
435
436 /* IWL_TM_ATTR_COMMAND is absolutely mandatory */
437 if (!tb[IWL_TM_ATTR_COMMAND]) {
438 IWL_DEBUG_INFO(priv, "Error finding testmode command type\n");
439 return -ENOMSG;
440 }
441 /* in case multiple accesses to the device happens */
442 mutex_lock(&priv->mutex);
443
444 switch (nla_get_u32(tb[IWL_TM_ATTR_COMMAND])) {
445 case IWL_TM_CMD_APP2DEV_UCODE:
446 IWL_DEBUG_INFO(priv, "testmode cmd to uCode\n");
447 result = iwl_testmode_ucode(hw, tb);
448 break;
449 case IWL_TM_CMD_APP2DEV_REG_READ32:
450 case IWL_TM_CMD_APP2DEV_REG_WRITE32:
451 case IWL_TM_CMD_APP2DEV_REG_WRITE8:
452 IWL_DEBUG_INFO(priv, "testmode cmd to register\n");
453 result = iwl_testmode_reg(hw, tb);
454 break;
455 case IWL_TM_CMD_APP2DEV_GET_DEVICENAME:
456 case IWL_TM_CMD_APP2DEV_LOAD_INIT_FW:
457 case IWL_TM_CMD_APP2DEV_CFG_INIT_CALIB:
458 case IWL_TM_CMD_APP2DEV_LOAD_RUNTIME_FW:
459 IWL_DEBUG_INFO(priv, "testmode cmd to driver\n");
460 result = iwl_testmode_driver(hw, tb);
461 break;
462 default:
463 IWL_DEBUG_INFO(priv, "Unknown testmode command\n");
464 result = -ENOSYS;
465 break;
466 }
467
468 mutex_unlock(&priv->mutex);
469 return result;
470}
This page took 0.059915 seconds and 5 git commands to generate.