2 * Copyright (C) 2008, cozybit Inc.
3 * Copyright (C) 2003-2006, Marvell International Ltd.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or (at
8 * your option) any later version.
10 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
12 #include <linux/slab.h>
14 #include "libertas_tf.h"
16 static const struct channel_range channel_ranges
[] = {
17 { LBTF_REGDOMAIN_US
, 1, 12 },
18 { LBTF_REGDOMAIN_CA
, 1, 12 },
19 { LBTF_REGDOMAIN_EU
, 1, 14 },
20 { LBTF_REGDOMAIN_JP
, 1, 14 },
21 { LBTF_REGDOMAIN_SP
, 1, 14 },
22 { LBTF_REGDOMAIN_FR
, 1, 14 },
25 static u16 lbtf_region_code_to_index
[MRVDRV_MAX_REGION_CODE
] =
27 LBTF_REGDOMAIN_US
, LBTF_REGDOMAIN_CA
, LBTF_REGDOMAIN_EU
,
28 LBTF_REGDOMAIN_SP
, LBTF_REGDOMAIN_FR
, LBTF_REGDOMAIN_JP
,
31 static struct cmd_ctrl_node
*lbtf_get_cmd_ctrl_node(struct lbtf_private
*priv
);
35 * lbtf_cmd_copyback - Simple callback that copies response back into command
37 * @priv A pointer to struct lbtf_private structure
38 * @extra A pointer to the original command structure for which
39 * 'resp' is a response
40 * @resp A pointer to the command response
42 * Returns: 0 on success, error on failure
44 int lbtf_cmd_copyback(struct lbtf_private
*priv
, unsigned long extra
,
45 struct cmd_header
*resp
)
47 struct cmd_header
*buf
= (void *)extra
;
50 copy_len
= min(le16_to_cpu(buf
->size
), le16_to_cpu(resp
->size
));
51 memcpy(buf
, resp
, copy_len
);
54 EXPORT_SYMBOL_GPL(lbtf_cmd_copyback
);
56 #define CHAN_TO_IDX(chan) ((chan) - 1)
58 static void lbtf_geo_init(struct lbtf_private
*priv
)
60 const struct channel_range
*range
= channel_ranges
;
64 for (i
= 0; i
< ARRAY_SIZE(channel_ranges
); i
++)
65 if (channel_ranges
[i
].regdomain
== priv
->regioncode
) {
66 range
= &channel_ranges
[i
];
70 for (ch
= priv
->range
.start
; ch
< priv
->range
.end
; ch
++)
71 priv
->channels
[CHAN_TO_IDX(ch
)].flags
= 0;
75 * lbtf_update_hw_spec: Updates the hardware details.
77 * @priv A pointer to struct lbtf_private structure
79 * Returns: 0 on success, error on failure
81 int lbtf_update_hw_spec(struct lbtf_private
*priv
)
83 struct cmd_ds_get_hw_spec cmd
;
87 lbtf_deb_enter(LBTF_DEB_CMD
);
89 memset(&cmd
, 0, sizeof(cmd
));
90 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
91 memcpy(cmd
.permanentaddr
, priv
->current_addr
, ETH_ALEN
);
92 ret
= lbtf_cmd_with_response(priv
, CMD_GET_HW_SPEC
, &cmd
);
96 priv
->fwcapinfo
= le32_to_cpu(cmd
.fwcapinfo
);
98 /* The firmware release is in an interesting format: the patch
99 * level is in the most significant nibble ... so fix that: */
100 priv
->fwrelease
= le32_to_cpu(cmd
.fwrelease
);
101 priv
->fwrelease
= (priv
->fwrelease
<< 8) |
102 (priv
->fwrelease
>> 24 & 0xff);
104 printk(KERN_INFO
"libertastf: %pM, fw %u.%u.%up%u, cap 0x%08x\n",
106 priv
->fwrelease
>> 24 & 0xff,
107 priv
->fwrelease
>> 16 & 0xff,
108 priv
->fwrelease
>> 8 & 0xff,
109 priv
->fwrelease
& 0xff,
111 lbtf_deb_cmd("GET_HW_SPEC: hardware interface 0x%x, hardware spec 0x%04x\n",
112 cmd
.hwifversion
, cmd
.version
);
114 /* Clamp region code to 8-bit since FW spec indicates that it should
115 * only ever be 8-bit, even though the field size is 16-bit. Some
116 * firmware returns non-zero high 8 bits here.
118 priv
->regioncode
= le16_to_cpu(cmd
.regioncode
) & 0xFF;
120 for (i
= 0; i
< MRVDRV_MAX_REGION_CODE
; i
++) {
121 /* use the region code to search for the index */
122 if (priv
->regioncode
== lbtf_region_code_to_index
[i
])
126 /* if it's unidentified region code, use the default (USA) */
127 if (i
>= MRVDRV_MAX_REGION_CODE
) {
128 priv
->regioncode
= 0x10;
129 pr_info("unidentified region code; using the default (USA)\n");
132 if (priv
->current_addr
[0] == 0xff)
133 memmove(priv
->current_addr
, cmd
.permanentaddr
, ETH_ALEN
);
135 SET_IEEE80211_PERM_ADDR(priv
->hw
, priv
->current_addr
);
139 lbtf_deb_leave(LBTF_DEB_CMD
);
144 * lbtf_set_channel: Set the radio channel
146 * @priv A pointer to struct lbtf_private structure
147 * @channel The desired channel, or 0 to clear a locked channel
149 * Returns: 0 on success, error on failure
151 int lbtf_set_channel(struct lbtf_private
*priv
, u8 channel
)
154 struct cmd_ds_802_11_rf_channel cmd
;
156 lbtf_deb_enter(LBTF_DEB_CMD
);
158 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
159 cmd
.action
= cpu_to_le16(CMD_OPT_802_11_RF_CHANNEL_SET
);
160 cmd
.channel
= cpu_to_le16(channel
);
162 ret
= lbtf_cmd_with_response(priv
, CMD_802_11_RF_CHANNEL
, &cmd
);
163 lbtf_deb_leave_args(LBTF_DEB_CMD
, "ret %d", ret
);
167 int lbtf_beacon_set(struct lbtf_private
*priv
, struct sk_buff
*beacon
)
169 struct cmd_ds_802_11_beacon_set cmd
;
172 lbtf_deb_enter(LBTF_DEB_CMD
);
174 if (beacon
->len
> MRVL_MAX_BCN_SIZE
) {
175 lbtf_deb_leave_args(LBTF_DEB_CMD
, "ret %d", -1);
178 size
= sizeof(cmd
) - sizeof(cmd
.beacon
) + beacon
->len
;
179 cmd
.hdr
.size
= cpu_to_le16(size
);
180 cmd
.len
= cpu_to_le16(beacon
->len
);
181 memcpy(cmd
.beacon
, (u8
*) beacon
->data
, beacon
->len
);
183 lbtf_cmd_async(priv
, CMD_802_11_BEACON_SET
, &cmd
.hdr
, size
);
185 lbtf_deb_leave_args(LBTF_DEB_CMD
, "ret %d", 0);
189 int lbtf_beacon_ctrl(struct lbtf_private
*priv
, bool beacon_enable
,
192 struct cmd_ds_802_11_beacon_control cmd
;
193 lbtf_deb_enter(LBTF_DEB_CMD
);
195 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
196 cmd
.action
= cpu_to_le16(CMD_ACT_SET
);
197 cmd
.beacon_enable
= cpu_to_le16(beacon_enable
);
198 cmd
.beacon_period
= cpu_to_le16(beacon_int
);
200 lbtf_cmd_async(priv
, CMD_802_11_BEACON_CTRL
, &cmd
.hdr
, sizeof(cmd
));
202 lbtf_deb_leave(LBTF_DEB_CMD
);
206 static void lbtf_queue_cmd(struct lbtf_private
*priv
,
207 struct cmd_ctrl_node
*cmdnode
)
210 lbtf_deb_enter(LBTF_DEB_HOST
);
213 lbtf_deb_host("QUEUE_CMD: cmdnode is NULL\n");
217 if (!cmdnode
->cmdbuf
->size
) {
218 lbtf_deb_host("DNLD_CMD: cmd size is zero\n");
223 spin_lock_irqsave(&priv
->driver_lock
, flags
);
224 list_add_tail(&cmdnode
->list
, &priv
->cmdpendingq
);
225 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
227 lbtf_deb_host("QUEUE_CMD: inserted command 0x%04x into cmdpendingq\n",
228 le16_to_cpu(cmdnode
->cmdbuf
->command
));
231 lbtf_deb_leave(LBTF_DEB_HOST
);
234 static void lbtf_submit_command(struct lbtf_private
*priv
,
235 struct cmd_ctrl_node
*cmdnode
)
238 struct cmd_header
*cmd
;
244 lbtf_deb_enter(LBTF_DEB_HOST
);
246 cmd
= cmdnode
->cmdbuf
;
248 spin_lock_irqsave(&priv
->driver_lock
, flags
);
249 priv
->cur_cmd
= cmdnode
;
250 cmdsize
= le16_to_cpu(cmd
->size
);
251 command
= le16_to_cpu(cmd
->command
);
253 lbtf_deb_cmd("DNLD_CMD: command 0x%04x, seq %d, size %d\n",
254 command
, le16_to_cpu(cmd
->seqnum
), cmdsize
);
255 lbtf_deb_hex(LBTF_DEB_CMD
, "DNLD_CMD", (void *) cmdnode
->cmdbuf
, cmdsize
);
257 ret
= priv
->hw_host_to_card(priv
, MVMS_CMD
, (u8
*) cmd
, cmdsize
);
258 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
261 pr_info("DNLD_CMD: hw_host_to_card failed: %d\n", ret
);
262 /* Let the timer kick in and retry, and potentially reset
263 the whole thing if the condition persists */
267 /* Setup the timer after transmit command */
268 mod_timer(&priv
->command_timer
, jiffies
+ timeo
);
270 lbtf_deb_leave(LBTF_DEB_HOST
);
274 * This function inserts command node to cmdfreeq
275 * after cleans it. Requires priv->driver_lock held.
277 static void __lbtf_cleanup_and_insert_cmd(struct lbtf_private
*priv
,
278 struct cmd_ctrl_node
*cmdnode
)
280 lbtf_deb_enter(LBTF_DEB_HOST
);
285 cmdnode
->callback
= NULL
;
286 cmdnode
->callback_arg
= 0;
288 memset(cmdnode
->cmdbuf
, 0, LBS_CMD_BUFFER_SIZE
);
290 list_add_tail(&cmdnode
->list
, &priv
->cmdfreeq
);
293 lbtf_deb_leave(LBTF_DEB_HOST
);
296 static void lbtf_cleanup_and_insert_cmd(struct lbtf_private
*priv
,
297 struct cmd_ctrl_node
*ptempcmd
)
301 spin_lock_irqsave(&priv
->driver_lock
, flags
);
302 __lbtf_cleanup_and_insert_cmd(priv
, ptempcmd
);
303 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
306 void lbtf_complete_command(struct lbtf_private
*priv
, struct cmd_ctrl_node
*cmd
,
309 cmd
->result
= result
;
310 cmd
->cmdwaitqwoken
= 1;
311 wake_up_interruptible(&cmd
->cmdwait_q
);
314 __lbtf_cleanup_and_insert_cmd(priv
, cmd
);
315 priv
->cur_cmd
= NULL
;
318 int lbtf_cmd_set_mac_multicast_addr(struct lbtf_private
*priv
)
320 struct cmd_ds_mac_multicast_addr cmd
;
322 lbtf_deb_enter(LBTF_DEB_CMD
);
324 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
325 cmd
.action
= cpu_to_le16(CMD_ACT_SET
);
327 cmd
.nr_of_adrs
= cpu_to_le16((u16
) priv
->nr_of_multicastmacaddr
);
329 lbtf_deb_cmd("MULTICAST_ADR: setting %d addresses\n", cmd
.nr_of_adrs
);
331 memcpy(cmd
.maclist
, priv
->multicastlist
,
332 priv
->nr_of_multicastmacaddr
* ETH_ALEN
);
334 lbtf_cmd_async(priv
, CMD_MAC_MULTICAST_ADR
, &cmd
.hdr
, sizeof(cmd
));
336 lbtf_deb_leave(LBTF_DEB_CMD
);
340 void lbtf_set_mode(struct lbtf_private
*priv
, enum lbtf_mode mode
)
342 struct cmd_ds_set_mode cmd
;
343 lbtf_deb_enter(LBTF_DEB_WEXT
);
345 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
346 cmd
.mode
= cpu_to_le16(mode
);
347 lbtf_deb_wext("Switching to mode: 0x%x\n", mode
);
348 lbtf_cmd_async(priv
, CMD_802_11_SET_MODE
, &cmd
.hdr
, sizeof(cmd
));
350 lbtf_deb_leave(LBTF_DEB_WEXT
);
353 void lbtf_set_bssid(struct lbtf_private
*priv
, bool activate
, const u8
*bssid
)
355 struct cmd_ds_set_bssid cmd
;
356 lbtf_deb_enter(LBTF_DEB_CMD
);
358 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
359 cmd
.activate
= activate
? 1 : 0;
361 memcpy(cmd
.bssid
, bssid
, ETH_ALEN
);
363 lbtf_cmd_async(priv
, CMD_802_11_SET_BSSID
, &cmd
.hdr
, sizeof(cmd
));
364 lbtf_deb_leave(LBTF_DEB_CMD
);
367 int lbtf_set_mac_address(struct lbtf_private
*priv
, uint8_t *mac_addr
)
369 struct cmd_ds_802_11_mac_address cmd
;
370 lbtf_deb_enter(LBTF_DEB_CMD
);
372 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
373 cmd
.action
= cpu_to_le16(CMD_ACT_SET
);
375 memcpy(cmd
.macadd
, mac_addr
, ETH_ALEN
);
377 lbtf_cmd_async(priv
, CMD_802_11_MAC_ADDRESS
, &cmd
.hdr
, sizeof(cmd
));
378 lbtf_deb_leave(LBTF_DEB_CMD
);
382 int lbtf_set_radio_control(struct lbtf_private
*priv
)
385 struct cmd_ds_802_11_radio_control cmd
;
387 lbtf_deb_enter(LBTF_DEB_CMD
);
389 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
390 cmd
.action
= cpu_to_le16(CMD_ACT_SET
);
392 switch (priv
->preamble
) {
393 case CMD_TYPE_SHORT_PREAMBLE
:
394 cmd
.control
= cpu_to_le16(SET_SHORT_PREAMBLE
);
397 case CMD_TYPE_LONG_PREAMBLE
:
398 cmd
.control
= cpu_to_le16(SET_LONG_PREAMBLE
);
401 case CMD_TYPE_AUTO_PREAMBLE
:
403 cmd
.control
= cpu_to_le16(SET_AUTO_PREAMBLE
);
408 cmd
.control
|= cpu_to_le16(TURN_ON_RF
);
410 cmd
.control
&= cpu_to_le16(~TURN_ON_RF
);
412 lbtf_deb_cmd("RADIO_SET: radio %d, preamble %d\n", priv
->radioon
,
415 ret
= lbtf_cmd_with_response(priv
, CMD_802_11_RADIO_CONTROL
, &cmd
);
417 lbtf_deb_leave_args(LBTF_DEB_CMD
, "ret %d", ret
);
421 void lbtf_set_mac_control(struct lbtf_private
*priv
)
423 struct cmd_ds_mac_control cmd
;
424 lbtf_deb_enter(LBTF_DEB_CMD
);
426 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
427 cmd
.action
= cpu_to_le16(priv
->mac_control
);
430 lbtf_cmd_async(priv
, CMD_MAC_CONTROL
,
431 &cmd
.hdr
, sizeof(cmd
));
433 lbtf_deb_leave(LBTF_DEB_CMD
);
437 * lbtf_allocate_cmd_buffer - Allocates cmd buffer, links it to free cmd queue
439 * @priv A pointer to struct lbtf_private structure
441 * Returns: 0 on success.
443 int lbtf_allocate_cmd_buffer(struct lbtf_private
*priv
)
448 struct cmd_ctrl_node
*cmdarray
;
450 lbtf_deb_enter(LBTF_DEB_HOST
);
452 /* Allocate and initialize the command array */
453 bufsize
= sizeof(struct cmd_ctrl_node
) * LBS_NUM_CMD_BUFFERS
;
454 cmdarray
= kzalloc(bufsize
, GFP_KERNEL
);
456 lbtf_deb_host("ALLOC_CMD_BUF: tempcmd_array is NULL\n");
460 priv
->cmd_array
= cmdarray
;
462 /* Allocate and initialize each command buffer in the command array */
463 for (i
= 0; i
< LBS_NUM_CMD_BUFFERS
; i
++) {
464 cmdarray
[i
].cmdbuf
= kzalloc(LBS_CMD_BUFFER_SIZE
, GFP_KERNEL
);
465 if (!cmdarray
[i
].cmdbuf
) {
466 lbtf_deb_host("ALLOC_CMD_BUF: ptempvirtualaddr is NULL\n");
472 for (i
= 0; i
< LBS_NUM_CMD_BUFFERS
; i
++) {
473 init_waitqueue_head(&cmdarray
[i
].cmdwait_q
);
474 lbtf_cleanup_and_insert_cmd(priv
, &cmdarray
[i
]);
480 lbtf_deb_leave_args(LBTF_DEB_HOST
, "ret %d", ret
);
485 * lbtf_free_cmd_buffer - Frees the cmd buffer.
487 * @priv A pointer to struct lbtf_private structure
491 int lbtf_free_cmd_buffer(struct lbtf_private
*priv
)
493 struct cmd_ctrl_node
*cmdarray
;
496 lbtf_deb_enter(LBTF_DEB_HOST
);
498 /* need to check if cmd array is allocated or not */
499 if (priv
->cmd_array
== NULL
) {
500 lbtf_deb_host("FREE_CMD_BUF: cmd_array is NULL\n");
504 cmdarray
= priv
->cmd_array
;
506 /* Release shared memory buffers */
507 for (i
= 0; i
< LBS_NUM_CMD_BUFFERS
; i
++) {
508 kfree(cmdarray
[i
].cmdbuf
);
509 cmdarray
[i
].cmdbuf
= NULL
;
512 /* Release cmd_ctrl_node */
513 kfree(priv
->cmd_array
);
514 priv
->cmd_array
= NULL
;
517 lbtf_deb_leave(LBTF_DEB_HOST
);
522 * lbtf_get_cmd_ctrl_node - Gets free cmd node from free cmd queue.
524 * @priv A pointer to struct lbtf_private structure
526 * Returns: pointer to a struct cmd_ctrl_node or NULL if none available.
528 static struct cmd_ctrl_node
*lbtf_get_cmd_ctrl_node(struct lbtf_private
*priv
)
530 struct cmd_ctrl_node
*tempnode
;
533 lbtf_deb_enter(LBTF_DEB_HOST
);
538 spin_lock_irqsave(&priv
->driver_lock
, flags
);
540 if (!list_empty(&priv
->cmdfreeq
)) {
541 tempnode
= list_first_entry(&priv
->cmdfreeq
,
542 struct cmd_ctrl_node
, list
);
543 list_del(&tempnode
->list
);
545 lbtf_deb_host("GET_CMD_NODE: cmd_ctrl_node is not available\n");
549 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
551 lbtf_deb_leave(LBTF_DEB_HOST
);
556 * lbtf_execute_next_command: execute next command in cmd pending queue.
558 * @priv A pointer to struct lbtf_private structure
560 * Returns: 0 on success.
562 int lbtf_execute_next_command(struct lbtf_private
*priv
)
564 struct cmd_ctrl_node
*cmdnode
= NULL
;
565 struct cmd_header
*cmd
;
569 /* Debug group is lbtf_deb_THREAD and not lbtf_deb_HOST, because the
570 * only caller to us is lbtf_thread() and we get even when a
571 * data packet is received */
572 lbtf_deb_enter(LBTF_DEB_THREAD
);
574 spin_lock_irqsave(&priv
->driver_lock
, flags
);
577 pr_alert("EXEC_NEXT_CMD: already processing command!\n");
578 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
583 if (!list_empty(&priv
->cmdpendingq
)) {
584 cmdnode
= list_first_entry(&priv
->cmdpendingq
,
585 struct cmd_ctrl_node
, list
);
589 cmd
= cmdnode
->cmdbuf
;
591 list_del(&cmdnode
->list
);
592 lbtf_deb_host("EXEC_NEXT_CMD: sending command 0x%04x\n",
593 le16_to_cpu(cmd
->command
));
594 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
595 lbtf_submit_command(priv
, cmdnode
);
597 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
601 lbtf_deb_leave(LBTF_DEB_THREAD
);
605 static struct cmd_ctrl_node
*__lbtf_cmd_async(struct lbtf_private
*priv
,
606 uint16_t command
, struct cmd_header
*in_cmd
, int in_cmd_size
,
607 int (*callback
)(struct lbtf_private
*, unsigned long,
608 struct cmd_header
*),
609 unsigned long callback_arg
)
611 struct cmd_ctrl_node
*cmdnode
;
613 lbtf_deb_enter(LBTF_DEB_HOST
);
615 if (priv
->surpriseremoved
) {
616 lbtf_deb_host("PREP_CMD: card removed\n");
617 cmdnode
= ERR_PTR(-ENOENT
);
621 cmdnode
= lbtf_get_cmd_ctrl_node(priv
);
622 if (cmdnode
== NULL
) {
623 lbtf_deb_host("PREP_CMD: cmdnode is NULL\n");
625 /* Wake up main thread to execute next command */
626 queue_work(lbtf_wq
, &priv
->cmd_work
);
627 cmdnode
= ERR_PTR(-ENOBUFS
);
631 cmdnode
->callback
= callback
;
632 cmdnode
->callback_arg
= callback_arg
;
634 /* Copy the incoming command to the buffer */
635 memcpy(cmdnode
->cmdbuf
, in_cmd
, in_cmd_size
);
637 /* Set sequence number, clean result, move to buffer */
639 cmdnode
->cmdbuf
->command
= cpu_to_le16(command
);
640 cmdnode
->cmdbuf
->size
= cpu_to_le16(in_cmd_size
);
641 cmdnode
->cmdbuf
->seqnum
= cpu_to_le16(priv
->seqnum
);
642 cmdnode
->cmdbuf
->result
= 0;
644 lbtf_deb_host("PREP_CMD: command 0x%04x\n", command
);
646 cmdnode
->cmdwaitqwoken
= 0;
647 lbtf_queue_cmd(priv
, cmdnode
);
648 queue_work(lbtf_wq
, &priv
->cmd_work
);
651 lbtf_deb_leave_args(LBTF_DEB_HOST
, "ret %p", cmdnode
);
655 void lbtf_cmd_async(struct lbtf_private
*priv
, uint16_t command
,
656 struct cmd_header
*in_cmd
, int in_cmd_size
)
658 lbtf_deb_enter(LBTF_DEB_CMD
);
659 __lbtf_cmd_async(priv
, command
, in_cmd
, in_cmd_size
, NULL
, 0);
660 lbtf_deb_leave(LBTF_DEB_CMD
);
663 int __lbtf_cmd(struct lbtf_private
*priv
, uint16_t command
,
664 struct cmd_header
*in_cmd
, int in_cmd_size
,
665 int (*callback
)(struct lbtf_private
*,
666 unsigned long, struct cmd_header
*),
667 unsigned long callback_arg
)
669 struct cmd_ctrl_node
*cmdnode
;
673 lbtf_deb_enter(LBTF_DEB_HOST
);
675 cmdnode
= __lbtf_cmd_async(priv
, command
, in_cmd
, in_cmd_size
,
676 callback
, callback_arg
);
677 if (IS_ERR(cmdnode
)) {
678 ret
= PTR_ERR(cmdnode
);
683 ret
= wait_event_interruptible(cmdnode
->cmdwait_q
,
684 cmdnode
->cmdwaitqwoken
);
686 pr_info("PREP_CMD: command 0x%04x interrupted by signal: %d\n",
691 spin_lock_irqsave(&priv
->driver_lock
, flags
);
692 ret
= cmdnode
->result
;
694 pr_info("PREP_CMD: command 0x%04x failed: %d\n",
697 __lbtf_cleanup_and_insert_cmd(priv
, cmdnode
);
698 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
701 lbtf_deb_leave_args(LBTF_DEB_HOST
, "ret %d", ret
);
704 EXPORT_SYMBOL_GPL(__lbtf_cmd
);
706 /* Call holding driver_lock */
707 void lbtf_cmd_response_rx(struct lbtf_private
*priv
)
709 priv
->cmd_response_rxed
= 1;
710 queue_work(lbtf_wq
, &priv
->cmd_work
);
712 EXPORT_SYMBOL_GPL(lbtf_cmd_response_rx
);
714 int lbtf_process_rx_command(struct lbtf_private
*priv
)
716 uint16_t respcmd
, curcmd
;
717 struct cmd_header
*resp
;
722 lbtf_deb_enter(LBTF_DEB_CMD
);
724 mutex_lock(&priv
->lock
);
725 spin_lock_irqsave(&priv
->driver_lock
, flags
);
727 if (!priv
->cur_cmd
) {
729 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
733 resp
= (void *)priv
->cmd_resp_buff
;
734 curcmd
= le16_to_cpu(priv
->cur_cmd
->cmdbuf
->command
);
735 respcmd
= le16_to_cpu(resp
->command
);
736 result
= le16_to_cpu(resp
->result
);
739 pr_info("libertastf: cmd response 0x%04x, seq %d, size %d\n",
740 respcmd
, le16_to_cpu(resp
->seqnum
),
741 le16_to_cpu(resp
->size
));
743 if (resp
->seqnum
!= priv
->cur_cmd
->cmdbuf
->seqnum
) {
744 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
748 if (respcmd
!= CMD_RET(curcmd
)) {
749 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
754 if (resp
->result
== cpu_to_le16(0x0004)) {
755 /* 0x0004 means -EAGAIN. Drop the response, let it time out
756 and be resubmitted */
757 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
762 /* Now we got response from FW, cancel the command timer */
763 del_timer(&priv
->command_timer
);
764 priv
->cmd_timed_out
= 0;
765 if (priv
->nr_retries
)
766 priv
->nr_retries
= 0;
768 /* If the command is not successful, cleanup and return failure */
769 if ((result
!= 0 || !(respcmd
& 0x8000))) {
771 * Handling errors here
774 case CMD_RET(CMD_GET_HW_SPEC
):
775 case CMD_RET(CMD_802_11_RESET
):
776 pr_info("libertastf: reset failed\n");
780 lbtf_complete_command(priv
, priv
->cur_cmd
, result
);
781 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
787 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
789 if (priv
->cur_cmd
&& priv
->cur_cmd
->callback
) {
790 ret
= priv
->cur_cmd
->callback(priv
, priv
->cur_cmd
->callback_arg
,
793 spin_lock_irqsave(&priv
->driver_lock
, flags
);
796 /* Clean up and Put current command back to cmdfreeq */
797 lbtf_complete_command(priv
, priv
->cur_cmd
, result
);
799 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
802 mutex_unlock(&priv
->lock
);
803 lbtf_deb_leave_args(LBTF_DEB_CMD
, "ret %d", ret
);