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.
11 #include "libertas_tf.h"
13 static const struct channel_range channel_ranges
[] = {
14 { LBTF_REGDOMAIN_US
, 1, 12 },
15 { LBTF_REGDOMAIN_CA
, 1, 12 },
16 { LBTF_REGDOMAIN_EU
, 1, 14 },
17 { LBTF_REGDOMAIN_JP
, 1, 14 },
18 { LBTF_REGDOMAIN_SP
, 1, 14 },
19 { LBTF_REGDOMAIN_FR
, 1, 14 },
22 static u16 lbtf_region_code_to_index
[MRVDRV_MAX_REGION_CODE
] =
24 LBTF_REGDOMAIN_US
, LBTF_REGDOMAIN_CA
, LBTF_REGDOMAIN_EU
,
25 LBTF_REGDOMAIN_SP
, LBTF_REGDOMAIN_FR
, LBTF_REGDOMAIN_JP
,
28 static struct cmd_ctrl_node
*lbtf_get_cmd_ctrl_node(struct lbtf_private
*priv
);
32 * lbtf_cmd_copyback - Simple callback that copies response back into command
34 * @priv A pointer to struct lbtf_private structure
35 * @extra A pointer to the original command structure for which
36 * 'resp' is a response
37 * @resp A pointer to the command response
39 * Returns: 0 on success, error on failure
41 int lbtf_cmd_copyback(struct lbtf_private
*priv
, unsigned long extra
,
42 struct cmd_header
*resp
)
44 struct cmd_header
*buf
= (void *)extra
;
47 copy_len
= min(le16_to_cpu(buf
->size
), le16_to_cpu(resp
->size
));
48 memcpy(buf
, resp
, copy_len
);
51 EXPORT_SYMBOL_GPL(lbtf_cmd_copyback
);
53 #define CHAN_TO_IDX(chan) ((chan) - 1)
55 static void lbtf_geo_init(struct lbtf_private
*priv
)
57 const struct channel_range
*range
= channel_ranges
;
61 for (i
= 0; i
< ARRAY_SIZE(channel_ranges
); i
++)
62 if (channel_ranges
[i
].regdomain
== priv
->regioncode
) {
63 range
= &channel_ranges
[i
];
67 for (ch
= priv
->range
.start
; ch
< priv
->range
.end
; ch
++)
68 priv
->channels
[CHAN_TO_IDX(ch
)].flags
= 0;
72 * lbtf_update_hw_spec: Updates the hardware details.
74 * @priv A pointer to struct lbtf_private structure
76 * Returns: 0 on success, error on failure
78 int lbtf_update_hw_spec(struct lbtf_private
*priv
)
80 struct cmd_ds_get_hw_spec cmd
;
84 lbtf_deb_enter(LBTF_DEB_CMD
);
86 memset(&cmd
, 0, sizeof(cmd
));
87 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
88 memcpy(cmd
.permanentaddr
, priv
->current_addr
, ETH_ALEN
);
89 ret
= lbtf_cmd_with_response(priv
, CMD_GET_HW_SPEC
, &cmd
);
93 priv
->fwcapinfo
= le32_to_cpu(cmd
.fwcapinfo
);
95 /* The firmware release is in an interesting format: the patch
96 * level is in the most significant nibble ... so fix that: */
97 priv
->fwrelease
= le32_to_cpu(cmd
.fwrelease
);
98 priv
->fwrelease
= (priv
->fwrelease
<< 8) |
99 (priv
->fwrelease
>> 24 & 0xff);
101 printk(KERN_INFO
"libertastf: %pM, fw %u.%u.%up%u, cap 0x%08x\n",
103 priv
->fwrelease
>> 24 & 0xff,
104 priv
->fwrelease
>> 16 & 0xff,
105 priv
->fwrelease
>> 8 & 0xff,
106 priv
->fwrelease
& 0xff,
108 lbtf_deb_cmd("GET_HW_SPEC: hardware interface 0x%x, hardware spec 0x%04x\n",
109 cmd
.hwifversion
, cmd
.version
);
111 /* Clamp region code to 8-bit since FW spec indicates that it should
112 * only ever be 8-bit, even though the field size is 16-bit. Some
113 * firmware returns non-zero high 8 bits here.
115 priv
->regioncode
= le16_to_cpu(cmd
.regioncode
) & 0xFF;
117 for (i
= 0; i
< MRVDRV_MAX_REGION_CODE
; i
++) {
118 /* use the region code to search for the index */
119 if (priv
->regioncode
== lbtf_region_code_to_index
[i
])
123 /* if it's unidentified region code, use the default (USA) */
124 if (i
>= MRVDRV_MAX_REGION_CODE
) {
125 priv
->regioncode
= 0x10;
126 pr_info("unidentified region code; using the default (USA)\n");
129 if (priv
->current_addr
[0] == 0xff)
130 memmove(priv
->current_addr
, cmd
.permanentaddr
, ETH_ALEN
);
132 SET_IEEE80211_PERM_ADDR(priv
->hw
, priv
->current_addr
);
136 lbtf_deb_leave(LBTF_DEB_CMD
);
141 * lbtf_set_channel: Set the radio channel
143 * @priv A pointer to struct lbtf_private structure
144 * @channel The desired channel, or 0 to clear a locked channel
146 * Returns: 0 on success, error on failure
148 int lbtf_set_channel(struct lbtf_private
*priv
, u8 channel
)
151 struct cmd_ds_802_11_rf_channel cmd
;
153 lbtf_deb_enter(LBTF_DEB_CMD
);
155 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
156 cmd
.action
= cpu_to_le16(CMD_OPT_802_11_RF_CHANNEL_SET
);
157 cmd
.channel
= cpu_to_le16(channel
);
159 ret
= lbtf_cmd_with_response(priv
, CMD_802_11_RF_CHANNEL
, &cmd
);
160 lbtf_deb_leave_args(LBTF_DEB_CMD
, "ret %d", ret
);
164 int lbtf_beacon_set(struct lbtf_private
*priv
, struct sk_buff
*beacon
)
166 struct cmd_ds_802_11_beacon_set cmd
;
169 lbtf_deb_enter(LBTF_DEB_CMD
);
171 if (beacon
->len
> MRVL_MAX_BCN_SIZE
) {
172 lbtf_deb_leave_args(LBTF_DEB_CMD
, "ret %d", -1);
175 size
= sizeof(cmd
) - sizeof(cmd
.beacon
) + beacon
->len
;
176 cmd
.hdr
.size
= cpu_to_le16(size
);
177 cmd
.len
= cpu_to_le16(beacon
->len
);
178 memcpy(cmd
.beacon
, (u8
*) beacon
->data
, beacon
->len
);
180 lbtf_cmd_async(priv
, CMD_802_11_BEACON_SET
, &cmd
.hdr
, size
);
182 lbtf_deb_leave_args(LBTF_DEB_CMD
, "ret %d", 0);
186 int lbtf_beacon_ctrl(struct lbtf_private
*priv
, bool beacon_enable
,
189 struct cmd_ds_802_11_beacon_control cmd
;
190 lbtf_deb_enter(LBTF_DEB_CMD
);
192 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
193 cmd
.action
= cpu_to_le16(CMD_ACT_SET
);
194 cmd
.beacon_enable
= cpu_to_le16(beacon_enable
);
195 cmd
.beacon_period
= cpu_to_le16(beacon_int
);
197 lbtf_cmd_async(priv
, CMD_802_11_BEACON_CTRL
, &cmd
.hdr
, sizeof(cmd
));
199 lbtf_deb_leave(LBTF_DEB_CMD
);
203 static void lbtf_queue_cmd(struct lbtf_private
*priv
,
204 struct cmd_ctrl_node
*cmdnode
)
207 lbtf_deb_enter(LBTF_DEB_HOST
);
210 lbtf_deb_host("QUEUE_CMD: cmdnode is NULL\n");
214 if (!cmdnode
->cmdbuf
->size
) {
215 lbtf_deb_host("DNLD_CMD: cmd size is zero\n");
220 spin_lock_irqsave(&priv
->driver_lock
, flags
);
221 list_add_tail(&cmdnode
->list
, &priv
->cmdpendingq
);
222 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
224 lbtf_deb_host("QUEUE_CMD: inserted command 0x%04x into cmdpendingq\n",
225 le16_to_cpu(cmdnode
->cmdbuf
->command
));
228 lbtf_deb_leave(LBTF_DEB_HOST
);
231 static void lbtf_submit_command(struct lbtf_private
*priv
,
232 struct cmd_ctrl_node
*cmdnode
)
235 struct cmd_header
*cmd
;
241 lbtf_deb_enter(LBTF_DEB_HOST
);
243 cmd
= cmdnode
->cmdbuf
;
245 spin_lock_irqsave(&priv
->driver_lock
, flags
);
246 priv
->cur_cmd
= cmdnode
;
247 cmdsize
= le16_to_cpu(cmd
->size
);
248 command
= le16_to_cpu(cmd
->command
);
250 lbtf_deb_cmd("DNLD_CMD: command 0x%04x, seq %d, size %d\n",
251 command
, le16_to_cpu(cmd
->seqnum
), cmdsize
);
252 lbtf_deb_hex(LBTF_DEB_CMD
, "DNLD_CMD", (void *) cmdnode
->cmdbuf
, cmdsize
);
254 ret
= priv
->hw_host_to_card(priv
, MVMS_CMD
, (u8
*) cmd
, cmdsize
);
255 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
258 pr_info("DNLD_CMD: hw_host_to_card failed: %d\n", ret
);
259 /* Let the timer kick in and retry, and potentially reset
260 the whole thing if the condition persists */
264 /* Setup the timer after transmit command */
265 mod_timer(&priv
->command_timer
, jiffies
+ timeo
);
267 lbtf_deb_leave(LBTF_DEB_HOST
);
271 * This function inserts command node to cmdfreeq
272 * after cleans it. Requires priv->driver_lock held.
274 static void __lbtf_cleanup_and_insert_cmd(struct lbtf_private
*priv
,
275 struct cmd_ctrl_node
*cmdnode
)
277 lbtf_deb_enter(LBTF_DEB_HOST
);
282 cmdnode
->callback
= NULL
;
283 cmdnode
->callback_arg
= 0;
285 memset(cmdnode
->cmdbuf
, 0, LBS_CMD_BUFFER_SIZE
);
287 list_add_tail(&cmdnode
->list
, &priv
->cmdfreeq
);
290 lbtf_deb_leave(LBTF_DEB_HOST
);
293 static void lbtf_cleanup_and_insert_cmd(struct lbtf_private
*priv
,
294 struct cmd_ctrl_node
*ptempcmd
)
298 spin_lock_irqsave(&priv
->driver_lock
, flags
);
299 __lbtf_cleanup_and_insert_cmd(priv
, ptempcmd
);
300 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
303 void lbtf_complete_command(struct lbtf_private
*priv
, struct cmd_ctrl_node
*cmd
,
306 cmd
->result
= result
;
307 cmd
->cmdwaitqwoken
= 1;
308 wake_up_interruptible(&cmd
->cmdwait_q
);
311 __lbtf_cleanup_and_insert_cmd(priv
, cmd
);
312 priv
->cur_cmd
= NULL
;
315 int lbtf_cmd_set_mac_multicast_addr(struct lbtf_private
*priv
)
317 struct cmd_ds_mac_multicast_addr cmd
;
319 lbtf_deb_enter(LBTF_DEB_CMD
);
321 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
322 cmd
.action
= cpu_to_le16(CMD_ACT_SET
);
324 cmd
.nr_of_adrs
= cpu_to_le16((u16
) priv
->nr_of_multicastmacaddr
);
326 lbtf_deb_cmd("MULTICAST_ADR: setting %d addresses\n", cmd
.nr_of_adrs
);
328 memcpy(cmd
.maclist
, priv
->multicastlist
,
329 priv
->nr_of_multicastmacaddr
* ETH_ALEN
);
331 lbtf_cmd_async(priv
, CMD_MAC_MULTICAST_ADR
, &cmd
.hdr
, sizeof(cmd
));
333 lbtf_deb_leave(LBTF_DEB_CMD
);
337 void lbtf_set_mode(struct lbtf_private
*priv
, enum lbtf_mode mode
)
339 struct cmd_ds_set_mode cmd
;
340 lbtf_deb_enter(LBTF_DEB_WEXT
);
342 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
343 cmd
.mode
= cpu_to_le16(mode
);
344 lbtf_deb_wext("Switching to mode: 0x%x\n", mode
);
345 lbtf_cmd_async(priv
, CMD_802_11_SET_MODE
, &cmd
.hdr
, sizeof(cmd
));
347 lbtf_deb_leave(LBTF_DEB_WEXT
);
350 void lbtf_set_bssid(struct lbtf_private
*priv
, bool activate
, const u8
*bssid
)
352 struct cmd_ds_set_bssid cmd
;
353 lbtf_deb_enter(LBTF_DEB_CMD
);
355 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
356 cmd
.activate
= activate
? 1 : 0;
358 memcpy(cmd
.bssid
, bssid
, ETH_ALEN
);
360 lbtf_cmd_async(priv
, CMD_802_11_SET_BSSID
, &cmd
.hdr
, sizeof(cmd
));
361 lbtf_deb_leave(LBTF_DEB_CMD
);
364 int lbtf_set_mac_address(struct lbtf_private
*priv
, uint8_t *mac_addr
)
366 struct cmd_ds_802_11_mac_address cmd
;
367 lbtf_deb_enter(LBTF_DEB_CMD
);
369 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
370 cmd
.action
= cpu_to_le16(CMD_ACT_SET
);
372 memcpy(cmd
.macadd
, mac_addr
, ETH_ALEN
);
374 lbtf_cmd_async(priv
, CMD_802_11_MAC_ADDRESS
, &cmd
.hdr
, sizeof(cmd
));
375 lbtf_deb_leave(LBTF_DEB_CMD
);
379 int lbtf_set_radio_control(struct lbtf_private
*priv
)
382 struct cmd_ds_802_11_radio_control cmd
;
384 lbtf_deb_enter(LBTF_DEB_CMD
);
386 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
387 cmd
.action
= cpu_to_le16(CMD_ACT_SET
);
389 switch (priv
->preamble
) {
390 case CMD_TYPE_SHORT_PREAMBLE
:
391 cmd
.control
= cpu_to_le16(SET_SHORT_PREAMBLE
);
394 case CMD_TYPE_LONG_PREAMBLE
:
395 cmd
.control
= cpu_to_le16(SET_LONG_PREAMBLE
);
398 case CMD_TYPE_AUTO_PREAMBLE
:
400 cmd
.control
= cpu_to_le16(SET_AUTO_PREAMBLE
);
405 cmd
.control
|= cpu_to_le16(TURN_ON_RF
);
407 cmd
.control
&= cpu_to_le16(~TURN_ON_RF
);
409 lbtf_deb_cmd("RADIO_SET: radio %d, preamble %d\n", priv
->radioon
,
412 ret
= lbtf_cmd_with_response(priv
, CMD_802_11_RADIO_CONTROL
, &cmd
);
414 lbtf_deb_leave_args(LBTF_DEB_CMD
, "ret %d", ret
);
418 void lbtf_set_mac_control(struct lbtf_private
*priv
)
420 struct cmd_ds_mac_control cmd
;
421 lbtf_deb_enter(LBTF_DEB_CMD
);
423 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
424 cmd
.action
= cpu_to_le16(priv
->mac_control
);
427 lbtf_cmd_async(priv
, CMD_MAC_CONTROL
,
428 &cmd
.hdr
, sizeof(cmd
));
430 lbtf_deb_leave(LBTF_DEB_CMD
);
434 * lbtf_allocate_cmd_buffer - Allocates cmd buffer, links it to free cmd queue
436 * @priv A pointer to struct lbtf_private structure
438 * Returns: 0 on success.
440 int lbtf_allocate_cmd_buffer(struct lbtf_private
*priv
)
445 struct cmd_ctrl_node
*cmdarray
;
447 lbtf_deb_enter(LBTF_DEB_HOST
);
449 /* Allocate and initialize the command array */
450 bufsize
= sizeof(struct cmd_ctrl_node
) * LBS_NUM_CMD_BUFFERS
;
451 cmdarray
= kzalloc(bufsize
, GFP_KERNEL
);
453 lbtf_deb_host("ALLOC_CMD_BUF: tempcmd_array is NULL\n");
457 priv
->cmd_array
= cmdarray
;
459 /* Allocate and initialize each command buffer in the command array */
460 for (i
= 0; i
< LBS_NUM_CMD_BUFFERS
; i
++) {
461 cmdarray
[i
].cmdbuf
= kzalloc(LBS_CMD_BUFFER_SIZE
, GFP_KERNEL
);
462 if (!cmdarray
[i
].cmdbuf
) {
463 lbtf_deb_host("ALLOC_CMD_BUF: ptempvirtualaddr is NULL\n");
469 for (i
= 0; i
< LBS_NUM_CMD_BUFFERS
; i
++) {
470 init_waitqueue_head(&cmdarray
[i
].cmdwait_q
);
471 lbtf_cleanup_and_insert_cmd(priv
, &cmdarray
[i
]);
477 lbtf_deb_leave_args(LBTF_DEB_HOST
, "ret %d", ret
);
482 * lbtf_free_cmd_buffer - Frees the cmd buffer.
484 * @priv A pointer to struct lbtf_private structure
488 int lbtf_free_cmd_buffer(struct lbtf_private
*priv
)
490 struct cmd_ctrl_node
*cmdarray
;
493 lbtf_deb_enter(LBTF_DEB_HOST
);
495 /* need to check if cmd array is allocated or not */
496 if (priv
->cmd_array
== NULL
) {
497 lbtf_deb_host("FREE_CMD_BUF: cmd_array is NULL\n");
501 cmdarray
= priv
->cmd_array
;
503 /* Release shared memory buffers */
504 for (i
= 0; i
< LBS_NUM_CMD_BUFFERS
; i
++) {
505 kfree(cmdarray
[i
].cmdbuf
);
506 cmdarray
[i
].cmdbuf
= NULL
;
509 /* Release cmd_ctrl_node */
510 kfree(priv
->cmd_array
);
511 priv
->cmd_array
= NULL
;
514 lbtf_deb_leave(LBTF_DEB_HOST
);
519 * lbtf_get_cmd_ctrl_node - Gets free cmd node from free cmd queue.
521 * @priv A pointer to struct lbtf_private structure
523 * Returns: pointer to a struct cmd_ctrl_node or NULL if none available.
525 static struct cmd_ctrl_node
*lbtf_get_cmd_ctrl_node(struct lbtf_private
*priv
)
527 struct cmd_ctrl_node
*tempnode
;
530 lbtf_deb_enter(LBTF_DEB_HOST
);
535 spin_lock_irqsave(&priv
->driver_lock
, flags
);
537 if (!list_empty(&priv
->cmdfreeq
)) {
538 tempnode
= list_first_entry(&priv
->cmdfreeq
,
539 struct cmd_ctrl_node
, list
);
540 list_del(&tempnode
->list
);
542 lbtf_deb_host("GET_CMD_NODE: cmd_ctrl_node is not available\n");
546 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
548 lbtf_deb_leave(LBTF_DEB_HOST
);
553 * lbtf_execute_next_command: execute next command in cmd pending queue.
555 * @priv A pointer to struct lbtf_private structure
557 * Returns: 0 on success.
559 int lbtf_execute_next_command(struct lbtf_private
*priv
)
561 struct cmd_ctrl_node
*cmdnode
= NULL
;
562 struct cmd_header
*cmd
;
566 /* Debug group is lbtf_deb_THREAD and not lbtf_deb_HOST, because the
567 * only caller to us is lbtf_thread() and we get even when a
568 * data packet is received */
569 lbtf_deb_enter(LBTF_DEB_THREAD
);
571 spin_lock_irqsave(&priv
->driver_lock
, flags
);
574 pr_alert("EXEC_NEXT_CMD: already processing command!\n");
575 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
580 if (!list_empty(&priv
->cmdpendingq
)) {
581 cmdnode
= list_first_entry(&priv
->cmdpendingq
,
582 struct cmd_ctrl_node
, list
);
586 cmd
= cmdnode
->cmdbuf
;
588 list_del(&cmdnode
->list
);
589 lbtf_deb_host("EXEC_NEXT_CMD: sending command 0x%04x\n",
590 le16_to_cpu(cmd
->command
));
591 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
592 lbtf_submit_command(priv
, cmdnode
);
594 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
598 lbtf_deb_leave(LBTF_DEB_THREAD
);
602 static struct cmd_ctrl_node
*__lbtf_cmd_async(struct lbtf_private
*priv
,
603 uint16_t command
, struct cmd_header
*in_cmd
, int in_cmd_size
,
604 int (*callback
)(struct lbtf_private
*, unsigned long,
605 struct cmd_header
*),
606 unsigned long callback_arg
)
608 struct cmd_ctrl_node
*cmdnode
;
610 lbtf_deb_enter(LBTF_DEB_HOST
);
612 if (priv
->surpriseremoved
) {
613 lbtf_deb_host("PREP_CMD: card removed\n");
614 cmdnode
= ERR_PTR(-ENOENT
);
618 cmdnode
= lbtf_get_cmd_ctrl_node(priv
);
619 if (cmdnode
== NULL
) {
620 lbtf_deb_host("PREP_CMD: cmdnode is NULL\n");
622 /* Wake up main thread to execute next command */
623 queue_work(lbtf_wq
, &priv
->cmd_work
);
624 cmdnode
= ERR_PTR(-ENOBUFS
);
628 cmdnode
->callback
= callback
;
629 cmdnode
->callback_arg
= callback_arg
;
631 /* Copy the incoming command to the buffer */
632 memcpy(cmdnode
->cmdbuf
, in_cmd
, in_cmd_size
);
634 /* Set sequence number, clean result, move to buffer */
636 cmdnode
->cmdbuf
->command
= cpu_to_le16(command
);
637 cmdnode
->cmdbuf
->size
= cpu_to_le16(in_cmd_size
);
638 cmdnode
->cmdbuf
->seqnum
= cpu_to_le16(priv
->seqnum
);
639 cmdnode
->cmdbuf
->result
= 0;
641 lbtf_deb_host("PREP_CMD: command 0x%04x\n", command
);
643 cmdnode
->cmdwaitqwoken
= 0;
644 lbtf_queue_cmd(priv
, cmdnode
);
645 queue_work(lbtf_wq
, &priv
->cmd_work
);
648 lbtf_deb_leave_args(LBTF_DEB_HOST
, "ret %p", cmdnode
);
652 void lbtf_cmd_async(struct lbtf_private
*priv
, uint16_t command
,
653 struct cmd_header
*in_cmd
, int in_cmd_size
)
655 lbtf_deb_enter(LBTF_DEB_CMD
);
656 __lbtf_cmd_async(priv
, command
, in_cmd
, in_cmd_size
, NULL
, 0);
657 lbtf_deb_leave(LBTF_DEB_CMD
);
660 int __lbtf_cmd(struct lbtf_private
*priv
, uint16_t command
,
661 struct cmd_header
*in_cmd
, int in_cmd_size
,
662 int (*callback
)(struct lbtf_private
*,
663 unsigned long, struct cmd_header
*),
664 unsigned long callback_arg
)
666 struct cmd_ctrl_node
*cmdnode
;
670 lbtf_deb_enter(LBTF_DEB_HOST
);
672 cmdnode
= __lbtf_cmd_async(priv
, command
, in_cmd
, in_cmd_size
,
673 callback
, callback_arg
);
674 if (IS_ERR(cmdnode
)) {
675 ret
= PTR_ERR(cmdnode
);
680 ret
= wait_event_interruptible(cmdnode
->cmdwait_q
,
681 cmdnode
->cmdwaitqwoken
);
683 pr_info("PREP_CMD: command 0x%04x interrupted by signal: %d\n",
688 spin_lock_irqsave(&priv
->driver_lock
, flags
);
689 ret
= cmdnode
->result
;
691 pr_info("PREP_CMD: command 0x%04x failed: %d\n",
694 __lbtf_cleanup_and_insert_cmd(priv
, cmdnode
);
695 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
698 lbtf_deb_leave_args(LBTF_DEB_HOST
, "ret %d", ret
);
701 EXPORT_SYMBOL_GPL(__lbtf_cmd
);
703 /* Call holding driver_lock */
704 void lbtf_cmd_response_rx(struct lbtf_private
*priv
)
706 priv
->cmd_response_rxed
= 1;
707 queue_work(lbtf_wq
, &priv
->cmd_work
);
709 EXPORT_SYMBOL_GPL(lbtf_cmd_response_rx
);
711 int lbtf_process_rx_command(struct lbtf_private
*priv
)
713 uint16_t respcmd
, curcmd
;
714 struct cmd_header
*resp
;
719 lbtf_deb_enter(LBTF_DEB_CMD
);
721 mutex_lock(&priv
->lock
);
722 spin_lock_irqsave(&priv
->driver_lock
, flags
);
724 if (!priv
->cur_cmd
) {
726 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
730 resp
= (void *)priv
->cmd_resp_buff
;
731 curcmd
= le16_to_cpu(priv
->cur_cmd
->cmdbuf
->command
);
732 respcmd
= le16_to_cpu(resp
->command
);
733 result
= le16_to_cpu(resp
->result
);
736 pr_info("libertastf: cmd response 0x%04x, seq %d, size %d\n",
737 respcmd
, le16_to_cpu(resp
->seqnum
),
738 le16_to_cpu(resp
->size
));
740 if (resp
->seqnum
!= priv
->cur_cmd
->cmdbuf
->seqnum
) {
741 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
745 if (respcmd
!= CMD_RET(curcmd
)) {
746 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
751 if (resp
->result
== cpu_to_le16(0x0004)) {
752 /* 0x0004 means -EAGAIN. Drop the response, let it time out
753 and be resubmitted */
754 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
759 /* Now we got response from FW, cancel the command timer */
760 del_timer(&priv
->command_timer
);
761 priv
->cmd_timed_out
= 0;
762 if (priv
->nr_retries
)
763 priv
->nr_retries
= 0;
765 /* If the command is not successful, cleanup and return failure */
766 if ((result
!= 0 || !(respcmd
& 0x8000))) {
768 * Handling errors here
771 case CMD_RET(CMD_GET_HW_SPEC
):
772 case CMD_RET(CMD_802_11_RESET
):
773 pr_info("libertastf: reset failed\n");
777 lbtf_complete_command(priv
, priv
->cur_cmd
, result
);
778 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
784 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
786 if (priv
->cur_cmd
&& priv
->cur_cmd
->callback
) {
787 ret
= priv
->cur_cmd
->callback(priv
, priv
->cur_cmd
->callback_arg
,
790 spin_lock_irqsave(&priv
->driver_lock
, flags
);
793 /* Clean up and Put current command back to cmdfreeq */
794 lbtf_complete_command(priv
, priv
->cur_cmd
, result
);
796 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
799 mutex_unlock(&priv
->lock
);
800 lbtf_deb_leave_args(LBTF_DEB_CMD
, "ret %d", ret
);