2012-04-19 03:08:28 +00:00
|
|
|
/*
|
2020-02-12 16:17:10 +00:00
|
|
|
* NXP Wireless LAN device driver: USB specific handling
|
2012-04-19 03:08:28 +00:00
|
|
|
*
|
2020-02-12 16:17:10 +00:00
|
|
|
* Copyright 2011-2020 NXP
|
2012-04-19 03:08:28 +00:00
|
|
|
*
|
2020-02-12 16:17:10 +00:00
|
|
|
* This software file (the "File") is distributed by NXP
|
|
|
|
* under the terms of the GNU General Public License Version 2, June 1991
|
2012-04-19 03:08:28 +00:00
|
|
|
* (the "License"). You may use, redistribute and/or modify this File in
|
|
|
|
* accordance with the terms and conditions of the License, a copy of which
|
|
|
|
* is available by writing to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
|
|
|
|
* worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
|
|
|
|
*
|
|
|
|
* THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE EXPRESSLY DISCLAIMED. The License provides additional details about
|
|
|
|
* this warranty disclaimer.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "main.h"
|
|
|
|
#include "usb.h"
|
|
|
|
|
|
|
|
#define USB_VERSION "1.0"
|
|
|
|
|
|
|
|
static struct mwifiex_if_ops usb_ops;
|
|
|
|
|
2017-08-09 16:27:59 +00:00
|
|
|
static const struct usb_device_id mwifiex_usb_table[] = {
|
2014-11-20 15:52:58 +00:00
|
|
|
/* 8766 */
|
|
|
|
{USB_DEVICE(USB8XXX_VID, USB8766_PID_1)},
|
|
|
|
{USB_DEVICE_AND_INTERFACE_INFO(USB8XXX_VID, USB8766_PID_2,
|
|
|
|
USB_CLASS_VENDOR_SPEC,
|
|
|
|
USB_SUBCLASS_VENDOR_SPEC, 0xff)},
|
2014-01-10 03:36:55 +00:00
|
|
|
/* 8797 */
|
|
|
|
{USB_DEVICE(USB8XXX_VID, USB8797_PID_1)},
|
|
|
|
{USB_DEVICE_AND_INTERFACE_INFO(USB8XXX_VID, USB8797_PID_2,
|
|
|
|
USB_CLASS_VENDOR_SPEC,
|
|
|
|
USB_SUBCLASS_VENDOR_SPEC, 0xff)},
|
2015-01-23 11:39:18 +00:00
|
|
|
/* 8801 */
|
|
|
|
{USB_DEVICE(USB8XXX_VID, USB8801_PID_1)},
|
|
|
|
{USB_DEVICE_AND_INTERFACE_INFO(USB8XXX_VID, USB8801_PID_2,
|
|
|
|
USB_CLASS_VENDOR_SPEC,
|
|
|
|
USB_SUBCLASS_VENDOR_SPEC, 0xff)},
|
2015-08-05 13:09:40 +00:00
|
|
|
/* 8997 */
|
|
|
|
{USB_DEVICE(USB8XXX_VID, USB8997_PID_1)},
|
|
|
|
{USB_DEVICE_AND_INTERFACE_INFO(USB8XXX_VID, USB8997_PID_2,
|
|
|
|
USB_CLASS_VENDOR_SPEC,
|
|
|
|
USB_SUBCLASS_VENDOR_SPEC, 0xff)},
|
2012-04-19 03:08:28 +00:00
|
|
|
{ } /* Terminating entry */
|
|
|
|
};
|
|
|
|
|
|
|
|
MODULE_DEVICE_TABLE(usb, mwifiex_usb_table);
|
|
|
|
|
|
|
|
static int mwifiex_usb_submit_rx_urb(struct urb_context *ctx, int size);
|
|
|
|
|
|
|
|
/* This function handles received packet. Necessary action is taken based on
|
|
|
|
* cmd/event/data.
|
|
|
|
*/
|
|
|
|
static int mwifiex_usb_recv(struct mwifiex_adapter *adapter,
|
|
|
|
struct sk_buff *skb, u8 ep)
|
|
|
|
{
|
|
|
|
u32 recv_type;
|
|
|
|
__le32 tmp;
|
2012-06-21 03:21:13 +00:00
|
|
|
int ret;
|
2012-04-19 03:08:28 +00:00
|
|
|
|
|
|
|
if (adapter->hs_activated)
|
|
|
|
mwifiex_process_hs_config(adapter);
|
|
|
|
|
|
|
|
if (skb->len < INTF_HEADER_LEN) {
|
2015-05-11 19:18:20 +00:00
|
|
|
mwifiex_dbg(adapter, ERROR,
|
|
|
|
"%s: invalid skb->len\n", __func__);
|
2012-04-19 03:08:28 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (ep) {
|
|
|
|
case MWIFIEX_USB_EP_CMD_EVENT:
|
2015-05-11 19:18:20 +00:00
|
|
|
mwifiex_dbg(adapter, EVENT,
|
|
|
|
"%s: EP_CMD_EVENT\n", __func__);
|
2012-04-19 03:08:28 +00:00
|
|
|
skb_copy_from_linear_data(skb, &tmp, INTF_HEADER_LEN);
|
|
|
|
recv_type = le32_to_cpu(tmp);
|
|
|
|
skb_pull(skb, INTF_HEADER_LEN);
|
|
|
|
|
|
|
|
switch (recv_type) {
|
|
|
|
case MWIFIEX_USB_TYPE_CMD:
|
|
|
|
if (skb->len > MWIFIEX_SIZE_OF_CMD_BUFFER) {
|
2015-05-11 19:18:20 +00:00
|
|
|
mwifiex_dbg(adapter, ERROR,
|
|
|
|
"CMD: skb->len too large\n");
|
2012-06-21 03:21:13 +00:00
|
|
|
ret = -1;
|
|
|
|
goto exit_restore_skb;
|
2012-04-19 03:08:28 +00:00
|
|
|
} else if (!adapter->curr_cmd) {
|
2015-05-11 19:18:20 +00:00
|
|
|
mwifiex_dbg(adapter, WARN, "CMD: no curr_cmd\n");
|
2012-04-19 03:08:28 +00:00
|
|
|
if (adapter->ps_state == PS_STATE_SLEEP_CFM) {
|
|
|
|
mwifiex_process_sleep_confirm_resp(
|
|
|
|
adapter, skb->data,
|
|
|
|
skb->len);
|
2012-06-21 03:21:13 +00:00
|
|
|
ret = 0;
|
|
|
|
goto exit_restore_skb;
|
2012-04-19 03:08:28 +00:00
|
|
|
}
|
2012-06-21 03:21:13 +00:00
|
|
|
ret = -1;
|
|
|
|
goto exit_restore_skb;
|
2012-04-19 03:08:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
adapter->curr_cmd->resp_skb = skb;
|
|
|
|
adapter->cmd_resp_received = true;
|
|
|
|
break;
|
|
|
|
case MWIFIEX_USB_TYPE_EVENT:
|
|
|
|
if (skb->len < sizeof(u32)) {
|
2015-05-11 19:18:20 +00:00
|
|
|
mwifiex_dbg(adapter, ERROR,
|
|
|
|
"EVENT: skb->len too small\n");
|
2012-06-21 03:21:13 +00:00
|
|
|
ret = -1;
|
|
|
|
goto exit_restore_skb;
|
2012-04-19 03:08:28 +00:00
|
|
|
}
|
|
|
|
skb_copy_from_linear_data(skb, &tmp, sizeof(u32));
|
|
|
|
adapter->event_cause = le32_to_cpu(tmp);
|
2015-05-11 19:18:20 +00:00
|
|
|
mwifiex_dbg(adapter, EVENT,
|
|
|
|
"event_cause %#x\n", adapter->event_cause);
|
2012-04-19 03:08:28 +00:00
|
|
|
|
|
|
|
if (skb->len > MAX_EVENT_SIZE) {
|
2015-05-11 19:18:20 +00:00
|
|
|
mwifiex_dbg(adapter, ERROR,
|
|
|
|
"EVENT: event body too large\n");
|
2012-06-21 03:21:13 +00:00
|
|
|
ret = -1;
|
|
|
|
goto exit_restore_skb;
|
2012-04-19 03:08:28 +00:00
|
|
|
}
|
|
|
|
|
2012-06-21 03:21:12 +00:00
|
|
|
memcpy(adapter->event_body, skb->data +
|
|
|
|
MWIFIEX_EVENT_HEADER_LEN, skb->len);
|
|
|
|
|
2012-04-19 03:08:28 +00:00
|
|
|
adapter->event_received = true;
|
|
|
|
adapter->event_skb = skb;
|
|
|
|
break;
|
|
|
|
default:
|
2015-05-11 19:18:20 +00:00
|
|
|
mwifiex_dbg(adapter, ERROR,
|
|
|
|
"unknown recv_type %#x\n", recv_type);
|
2021-10-31 02:42:50 +00:00
|
|
|
ret = -1;
|
|
|
|
goto exit_restore_skb;
|
2012-04-19 03:08:28 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MWIFIEX_USB_EP_DATA:
|
2015-05-11 19:18:20 +00:00
|
|
|
mwifiex_dbg(adapter, DATA, "%s: EP_DATA\n", __func__);
|
2012-04-19 03:08:28 +00:00
|
|
|
if (skb->len > MWIFIEX_RX_DATA_BUF_SIZE) {
|
2015-05-11 19:18:20 +00:00
|
|
|
mwifiex_dbg(adapter, ERROR,
|
|
|
|
"DATA: skb->len too large\n");
|
2012-04-19 03:08:28 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2014-11-05 11:34:27 +00:00
|
|
|
|
|
|
|
skb_queue_tail(&adapter->rx_data_q, skb);
|
2012-04-19 03:08:28 +00:00
|
|
|
adapter->data_received = true;
|
2014-11-05 11:34:27 +00:00
|
|
|
atomic_inc(&adapter->rx_pending);
|
2012-04-19 03:08:28 +00:00
|
|
|
break;
|
|
|
|
default:
|
2015-05-11 19:18:20 +00:00
|
|
|
mwifiex_dbg(adapter, ERROR,
|
|
|
|
"%s: unknown endport %#x\n", __func__, ep);
|
2012-04-19 03:08:28 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -EINPROGRESS;
|
2012-06-21 03:21:13 +00:00
|
|
|
|
|
|
|
exit_restore_skb:
|
|
|
|
/* The buffer will be reused for further cmds/events */
|
|
|
|
skb_push(skb, INTF_HEADER_LEN);
|
|
|
|
|
|
|
|
return ret;
|
2012-04-19 03:08:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void mwifiex_usb_rx_complete(struct urb *urb)
|
|
|
|
{
|
|
|
|
struct urb_context *context = (struct urb_context *)urb->context;
|
|
|
|
struct mwifiex_adapter *adapter = context->adapter;
|
|
|
|
struct sk_buff *skb = context->skb;
|
|
|
|
struct usb_card_rec *card;
|
|
|
|
int recv_length = urb->actual_length;
|
|
|
|
int size, status;
|
|
|
|
|
|
|
|
if (!adapter || !adapter->card) {
|
|
|
|
pr_err("mwifiex adapter or card structure is not valid\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
card = (struct usb_card_rec *)adapter->card;
|
|
|
|
if (card->rx_cmd_ep == context->ep)
|
|
|
|
atomic_dec(&card->rx_cmd_urb_pending);
|
|
|
|
else
|
|
|
|
atomic_dec(&card->rx_data_urb_pending);
|
|
|
|
|
|
|
|
if (recv_length) {
|
2018-07-13 12:26:35 +00:00
|
|
|
if (urb->status ||
|
|
|
|
test_bit(MWIFIEX_SURPRISE_REMOVED, &adapter->work_flags)) {
|
2015-05-11 19:18:20 +00:00
|
|
|
mwifiex_dbg(adapter, ERROR,
|
|
|
|
"URB status is failed: %d\n", urb->status);
|
2012-04-19 03:08:28 +00:00
|
|
|
/* Do not free skb in case of command ep */
|
|
|
|
if (card->rx_cmd_ep != context->ep)
|
|
|
|
dev_kfree_skb_any(skb);
|
|
|
|
goto setup_for_next;
|
|
|
|
}
|
|
|
|
if (skb->len > recv_length)
|
|
|
|
skb_trim(skb, recv_length);
|
|
|
|
else
|
|
|
|
skb_put(skb, recv_length - skb->len);
|
|
|
|
|
|
|
|
status = mwifiex_usb_recv(adapter, skb, context->ep);
|
|
|
|
|
2015-05-11 19:18:20 +00:00
|
|
|
mwifiex_dbg(adapter, INFO,
|
|
|
|
"info: recv_length=%d, status=%d\n",
|
|
|
|
recv_length, status);
|
2012-04-19 03:08:28 +00:00
|
|
|
if (status == -EINPROGRESS) {
|
2015-03-13 12:07:54 +00:00
|
|
|
mwifiex_queue_main_work(adapter);
|
2012-04-19 03:08:28 +00:00
|
|
|
|
|
|
|
/* urb for data_ep is re-submitted now;
|
|
|
|
* urb for cmd_ep will be re-submitted in callback
|
|
|
|
* mwifiex_usb_recv_complete
|
|
|
|
*/
|
|
|
|
if (card->rx_cmd_ep == context->ep)
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
if (status == -1)
|
2015-05-11 19:18:20 +00:00
|
|
|
mwifiex_dbg(adapter, ERROR,
|
|
|
|
"received data processing failed!\n");
|
2012-04-19 03:08:28 +00:00
|
|
|
|
|
|
|
/* Do not free skb in case of command ep */
|
|
|
|
if (card->rx_cmd_ep != context->ep)
|
|
|
|
dev_kfree_skb_any(skb);
|
|
|
|
}
|
|
|
|
} else if (urb->status) {
|
2018-07-13 12:26:35 +00:00
|
|
|
if (!test_bit(MWIFIEX_IS_SUSPENDED, &adapter->work_flags)) {
|
2015-05-11 19:18:20 +00:00
|
|
|
mwifiex_dbg(adapter, FATAL,
|
|
|
|
"Card is removed: %d\n", urb->status);
|
2018-07-13 12:26:35 +00:00
|
|
|
set_bit(MWIFIEX_SURPRISE_REMOVED, &adapter->work_flags);
|
2012-04-19 03:08:28 +00:00
|
|
|
}
|
|
|
|
dev_kfree_skb_any(skb);
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
/* Do not free skb in case of command ep */
|
|
|
|
if (card->rx_cmd_ep != context->ep)
|
|
|
|
dev_kfree_skb_any(skb);
|
|
|
|
|
|
|
|
/* fall through setup_for_next */
|
|
|
|
}
|
|
|
|
|
|
|
|
setup_for_next:
|
|
|
|
if (card->rx_cmd_ep == context->ep)
|
|
|
|
size = MWIFIEX_RX_CMD_BUF_SIZE;
|
|
|
|
else
|
|
|
|
size = MWIFIEX_RX_DATA_BUF_SIZE;
|
|
|
|
|
2014-11-05 11:34:29 +00:00
|
|
|
if (card->rx_cmd_ep == context->ep) {
|
|
|
|
mwifiex_usb_submit_rx_urb(context, size);
|
|
|
|
} else {
|
2016-02-24 19:19:56 +00:00
|
|
|
if (atomic_read(&adapter->rx_pending) <= HIGH_RX_PENDING) {
|
2014-11-05 11:34:29 +00:00
|
|
|
mwifiex_usb_submit_rx_urb(context, size);
|
2016-02-24 19:19:56 +00:00
|
|
|
} else {
|
2015-06-29 01:07:38 +00:00
|
|
|
context->skb = NULL;
|
|
|
|
}
|
2014-11-05 11:34:29 +00:00
|
|
|
}
|
2012-04-19 03:08:28 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mwifiex_usb_tx_complete(struct urb *urb)
|
|
|
|
{
|
|
|
|
struct urb_context *context = (struct urb_context *)(urb->context);
|
|
|
|
struct mwifiex_adapter *adapter = context->adapter;
|
|
|
|
struct usb_card_rec *card = adapter->card;
|
2015-09-18 13:32:16 +00:00
|
|
|
struct usb_tx_data_port *port;
|
|
|
|
int i;
|
2012-04-19 03:08:28 +00:00
|
|
|
|
2015-05-11 19:18:20 +00:00
|
|
|
mwifiex_dbg(adapter, INFO,
|
|
|
|
"%s: status: %d\n", __func__, urb->status);
|
2012-04-19 03:08:28 +00:00
|
|
|
|
|
|
|
if (context->ep == card->tx_cmd_ep) {
|
2015-05-11 19:18:20 +00:00
|
|
|
mwifiex_dbg(adapter, CMD,
|
|
|
|
"%s: CMD\n", __func__);
|
2012-04-19 03:08:28 +00:00
|
|
|
atomic_dec(&card->tx_cmd_urb_pending);
|
|
|
|
adapter->cmd_sent = false;
|
|
|
|
} else {
|
2015-05-11 19:18:20 +00:00
|
|
|
mwifiex_dbg(adapter, DATA,
|
|
|
|
"%s: DATA\n", __func__);
|
2016-09-20 15:19:02 +00:00
|
|
|
mwifiex_write_data_complete(adapter, context->skb, 0,
|
|
|
|
urb->status ? -1 : 0);
|
2015-09-18 13:32:16 +00:00
|
|
|
for (i = 0; i < MWIFIEX_TX_DATA_PORT; i++) {
|
|
|
|
port = &card->port[i];
|
|
|
|
if (context->ep == port->tx_data_ep) {
|
|
|
|
atomic_dec(&port->tx_data_urb_pending);
|
2015-09-18 13:32:18 +00:00
|
|
|
port->block_status = false;
|
2015-09-18 13:32:16 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-09-18 13:32:14 +00:00
|
|
|
adapter->data_sent = false;
|
2012-04-19 03:08:28 +00:00
|
|
|
}
|
|
|
|
|
2015-09-18 13:32:17 +00:00
|
|
|
if (card->mc_resync_flag)
|
|
|
|
mwifiex_multi_chan_resync(adapter);
|
|
|
|
|
2015-03-13 12:07:54 +00:00
|
|
|
mwifiex_queue_main_work(adapter);
|
2012-04-19 03:08:28 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mwifiex_usb_submit_rx_urb(struct urb_context *ctx, int size)
|
|
|
|
{
|
|
|
|
struct mwifiex_adapter *adapter = ctx->adapter;
|
|
|
|
struct usb_card_rec *card = (struct usb_card_rec *)adapter->card;
|
|
|
|
|
2018-08-21 07:53:01 +00:00
|
|
|
if (test_bit(MWIFIEX_IS_SUSPENDED, &adapter->work_flags)) {
|
2018-08-21 07:53:02 +00:00
|
|
|
if (card->rx_cmd_ep == ctx->ep) {
|
|
|
|
mwifiex_dbg(adapter, INFO, "%s: free rx_cmd skb\n",
|
|
|
|
__func__);
|
|
|
|
dev_kfree_skb_any(ctx->skb);
|
|
|
|
ctx->skb = NULL;
|
|
|
|
}
|
2018-08-21 07:53:01 +00:00
|
|
|
mwifiex_dbg(adapter, ERROR,
|
|
|
|
"%s: card removed/suspended, EP %d rx_cmd URB submit skipped\n",
|
|
|
|
__func__, ctx->ep);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-04-19 03:08:28 +00:00
|
|
|
if (card->rx_cmd_ep != ctx->ep) {
|
|
|
|
ctx->skb = dev_alloc_skb(size);
|
|
|
|
if (!ctx->skb) {
|
2015-05-11 19:18:20 +00:00
|
|
|
mwifiex_dbg(adapter, ERROR,
|
|
|
|
"%s: dev_alloc_skb failed\n", __func__);
|
2012-04-19 03:08:28 +00:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-27 12:57:44 +00:00
|
|
|
if (card->rx_cmd_ep == ctx->ep &&
|
|
|
|
card->rx_cmd_ep_type == USB_ENDPOINT_XFER_INT)
|
|
|
|
usb_fill_int_urb(ctx->urb, card->udev,
|
|
|
|
usb_rcvintpipe(card->udev, ctx->ep),
|
|
|
|
ctx->skb->data, size, mwifiex_usb_rx_complete,
|
|
|
|
(void *)ctx, card->rx_cmd_interval);
|
|
|
|
else
|
|
|
|
usb_fill_bulk_urb(ctx->urb, card->udev,
|
|
|
|
usb_rcvbulkpipe(card->udev, ctx->ep),
|
|
|
|
ctx->skb->data, size, mwifiex_usb_rx_complete,
|
|
|
|
(void *)ctx);
|
2012-04-19 03:08:28 +00:00
|
|
|
|
|
|
|
if (card->rx_cmd_ep == ctx->ep)
|
|
|
|
atomic_inc(&card->rx_cmd_urb_pending);
|
|
|
|
else
|
|
|
|
atomic_inc(&card->rx_data_urb_pending);
|
|
|
|
|
|
|
|
if (usb_submit_urb(ctx->urb, GFP_ATOMIC)) {
|
2015-05-11 19:18:20 +00:00
|
|
|
mwifiex_dbg(adapter, ERROR, "usb_submit_urb failed\n");
|
2012-04-19 03:08:28 +00:00
|
|
|
dev_kfree_skb_any(ctx->skb);
|
|
|
|
ctx->skb = NULL;
|
|
|
|
|
|
|
|
if (card->rx_cmd_ep == ctx->ep)
|
|
|
|
atomic_dec(&card->rx_cmd_urb_pending);
|
|
|
|
else
|
|
|
|
atomic_dec(&card->rx_data_urb_pending);
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mwifiex_usb_free(struct usb_card_rec *card)
|
|
|
|
{
|
2015-09-18 13:32:16 +00:00
|
|
|
struct usb_tx_data_port *port;
|
|
|
|
int i, j;
|
2012-04-19 03:08:28 +00:00
|
|
|
|
|
|
|
if (atomic_read(&card->rx_cmd_urb_pending) && card->rx_cmd.urb)
|
|
|
|
usb_kill_urb(card->rx_cmd.urb);
|
|
|
|
|
|
|
|
usb_free_urb(card->rx_cmd.urb);
|
|
|
|
card->rx_cmd.urb = NULL;
|
|
|
|
|
|
|
|
if (atomic_read(&card->rx_data_urb_pending))
|
|
|
|
for (i = 0; i < MWIFIEX_RX_DATA_URB; i++)
|
|
|
|
if (card->rx_data_list[i].urb)
|
|
|
|
usb_kill_urb(card->rx_data_list[i].urb);
|
|
|
|
|
|
|
|
for (i = 0; i < MWIFIEX_RX_DATA_URB; i++) {
|
|
|
|
usb_free_urb(card->rx_data_list[i].urb);
|
|
|
|
card->rx_data_list[i].urb = NULL;
|
|
|
|
}
|
|
|
|
|
2015-09-18 13:32:16 +00:00
|
|
|
for (i = 0; i < MWIFIEX_TX_DATA_PORT; i++) {
|
|
|
|
port = &card->port[i];
|
|
|
|
for (j = 0; j < MWIFIEX_TX_DATA_URB; j++) {
|
2017-05-23 07:12:31 +00:00
|
|
|
usb_kill_urb(port->tx_data_list[j].urb);
|
2015-09-18 13:32:16 +00:00
|
|
|
usb_free_urb(port->tx_data_list[j].urb);
|
|
|
|
port->tx_data_list[j].urb = NULL;
|
|
|
|
}
|
2012-04-19 03:08:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
usb_free_urb(card->tx_cmd.urb);
|
|
|
|
card->tx_cmd.urb = NULL;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This function probes an mwifiex device and registers it. It allocates
|
|
|
|
* the card structure, initiates the device registration and initialization
|
|
|
|
* procedure by adding a logical interface.
|
|
|
|
*/
|
|
|
|
static int mwifiex_usb_probe(struct usb_interface *intf,
|
|
|
|
const struct usb_device_id *id)
|
|
|
|
{
|
|
|
|
struct usb_device *udev = interface_to_usbdev(intf);
|
|
|
|
struct usb_host_interface *iface_desc = intf->cur_altsetting;
|
|
|
|
struct usb_endpoint_descriptor *epd;
|
|
|
|
int ret, i;
|
|
|
|
struct usb_card_rec *card;
|
2016-11-24 01:27:10 +00:00
|
|
|
u16 id_vendor, id_product, bcd_device;
|
2012-04-19 03:08:28 +00:00
|
|
|
|
2016-10-26 23:29:20 +00:00
|
|
|
card = devm_kzalloc(&intf->dev, sizeof(*card), GFP_KERNEL);
|
2012-04-19 03:08:28 +00:00
|
|
|
if (!card)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
mwifiex: resolve races between async FW init (failure) and device removal
It's possible for the FW init sequence to fail, which will trigger a
device cleanup sequence in mwifiex_fw_dpc(). This sequence can race with
device suspend() or remove() (e.g., reboot or unbind), and can trigger
use-after-free issues. Currently, this driver attempts (poorly) to
synchronize remove() using a semaphore, but it doesn't protect some of
the critical sections properly. Particularly, we grab a pointer to the
adapter struct (card->adapter) without checking if it's being freed or
not. We later do a NULL check on the adapter, but that doesn't work if
the adapter was freed.
Also note that the PCIe interface driver doesn't ever set card->adapter
to NULL, so even if we get the synchronization right, we still might try
to redo the cleanup in ->remove(), even if the FW init failure sequence
already did it.
This patch replaces the static semaphore with a per-device completion
struct, and uses that completion to synchronize the remove() thread with
the mwifiex_fw_dpc(). A future patch will utilize this completion to
synchronize the suspend() thread as well.
Signed-off-by: Brian Norris <briannorris@chromium.org>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
2016-11-18 14:00:26 +00:00
|
|
|
init_completion(&card->fw_done);
|
|
|
|
|
2012-04-19 03:08:28 +00:00
|
|
|
id_vendor = le16_to_cpu(udev->descriptor.idVendor);
|
|
|
|
id_product = le16_to_cpu(udev->descriptor.idProduct);
|
|
|
|
bcd_device = le16_to_cpu(udev->descriptor.bcdDevice);
|
|
|
|
pr_debug("info: VID/PID = %X/%X, Boot2 version = %X\n",
|
|
|
|
id_vendor, id_product, bcd_device);
|
|
|
|
|
|
|
|
/* PID_1 is used for firmware downloading only */
|
2014-01-10 03:36:55 +00:00
|
|
|
switch (id_product) {
|
2014-11-20 15:52:58 +00:00
|
|
|
case USB8766_PID_1:
|
2014-01-10 03:36:55 +00:00
|
|
|
case USB8797_PID_1:
|
2015-01-23 11:39:18 +00:00
|
|
|
case USB8801_PID_1:
|
2015-08-05 13:09:40 +00:00
|
|
|
case USB8997_PID_1:
|
2014-01-10 03:36:55 +00:00
|
|
|
card->usb_boot_state = USB8XXX_FW_DNLD;
|
|
|
|
break;
|
2014-11-20 15:52:58 +00:00
|
|
|
case USB8766_PID_2:
|
2014-01-10 03:36:55 +00:00
|
|
|
case USB8797_PID_2:
|
2015-01-23 11:39:18 +00:00
|
|
|
case USB8801_PID_2:
|
2015-08-05 13:09:40 +00:00
|
|
|
case USB8997_PID_2:
|
2014-01-10 03:36:55 +00:00
|
|
|
card->usb_boot_state = USB8XXX_FW_READY;
|
|
|
|
break;
|
|
|
|
default:
|
2014-09-10 03:27:44 +00:00
|
|
|
pr_warn("unknown id_product %#x\n", id_product);
|
2014-01-10 03:36:55 +00:00
|
|
|
card->usb_boot_state = USB8XXX_FW_DNLD;
|
|
|
|
break;
|
|
|
|
}
|
2012-04-19 03:08:28 +00:00
|
|
|
|
|
|
|
card->udev = udev;
|
|
|
|
card->intf = intf;
|
|
|
|
|
2012-11-30 13:08:31 +00:00
|
|
|
pr_debug("info: bcdUSB=%#x Device Class=%#x SubClass=%#x Protocol=%#x\n",
|
2017-05-12 10:15:55 +00:00
|
|
|
le16_to_cpu(udev->descriptor.bcdUSB),
|
|
|
|
udev->descriptor.bDeviceClass,
|
2012-04-19 03:08:28 +00:00
|
|
|
udev->descriptor.bDeviceSubClass,
|
|
|
|
udev->descriptor.bDeviceProtocol);
|
|
|
|
|
|
|
|
for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
|
|
|
|
epd = &iface_desc->endpoint[i].desc;
|
|
|
|
if (usb_endpoint_dir_in(epd) &&
|
|
|
|
usb_endpoint_num(epd) == MWIFIEX_USB_EP_CMD_EVENT &&
|
2017-03-27 12:57:44 +00:00
|
|
|
(usb_endpoint_xfer_bulk(epd) ||
|
|
|
|
usb_endpoint_xfer_int(epd))) {
|
|
|
|
card->rx_cmd_ep_type = usb_endpoint_type(epd);
|
|
|
|
card->rx_cmd_interval = epd->bInterval;
|
|
|
|
pr_debug("info: Rx CMD/EVT:: max pkt size: %d, addr: %d, ep_type: %d\n",
|
2012-04-19 03:08:28 +00:00
|
|
|
le16_to_cpu(epd->wMaxPacketSize),
|
2017-03-27 12:57:44 +00:00
|
|
|
epd->bEndpointAddress, card->rx_cmd_ep_type);
|
2012-04-19 03:08:28 +00:00
|
|
|
card->rx_cmd_ep = usb_endpoint_num(epd);
|
|
|
|
atomic_set(&card->rx_cmd_urb_pending, 0);
|
|
|
|
}
|
|
|
|
if (usb_endpoint_dir_in(epd) &&
|
|
|
|
usb_endpoint_num(epd) == MWIFIEX_USB_EP_DATA &&
|
|
|
|
usb_endpoint_xfer_bulk(epd)) {
|
|
|
|
pr_debug("info: bulk IN: max pkt size: %d, addr: %d\n",
|
|
|
|
le16_to_cpu(epd->wMaxPacketSize),
|
|
|
|
epd->bEndpointAddress);
|
|
|
|
card->rx_data_ep = usb_endpoint_num(epd);
|
|
|
|
atomic_set(&card->rx_data_urb_pending, 0);
|
|
|
|
}
|
|
|
|
if (usb_endpoint_dir_out(epd) &&
|
|
|
|
usb_endpoint_num(epd) == MWIFIEX_USB_EP_DATA &&
|
|
|
|
usb_endpoint_xfer_bulk(epd)) {
|
|
|
|
pr_debug("info: bulk OUT: max pkt size: %d, addr: %d\n",
|
|
|
|
le16_to_cpu(epd->wMaxPacketSize),
|
|
|
|
epd->bEndpointAddress);
|
2015-09-18 13:32:16 +00:00
|
|
|
card->port[0].tx_data_ep = usb_endpoint_num(epd);
|
|
|
|
atomic_set(&card->port[0].tx_data_urb_pending, 0);
|
|
|
|
}
|
|
|
|
if (usb_endpoint_dir_out(epd) &&
|
|
|
|
usb_endpoint_num(epd) == MWIFIEX_USB_EP_DATA_CH2 &&
|
|
|
|
usb_endpoint_xfer_bulk(epd)) {
|
|
|
|
pr_debug("info: bulk OUT chan2:\t"
|
|
|
|
"max pkt size: %d, addr: %d\n",
|
|
|
|
le16_to_cpu(epd->wMaxPacketSize),
|
|
|
|
epd->bEndpointAddress);
|
|
|
|
card->port[1].tx_data_ep = usb_endpoint_num(epd);
|
|
|
|
atomic_set(&card->port[1].tx_data_urb_pending, 0);
|
2012-04-19 03:08:28 +00:00
|
|
|
}
|
|
|
|
if (usb_endpoint_dir_out(epd) &&
|
|
|
|
usb_endpoint_num(epd) == MWIFIEX_USB_EP_CMD_EVENT &&
|
2017-03-27 12:57:44 +00:00
|
|
|
(usb_endpoint_xfer_bulk(epd) ||
|
|
|
|
usb_endpoint_xfer_int(epd))) {
|
|
|
|
card->tx_cmd_ep_type = usb_endpoint_type(epd);
|
|
|
|
card->tx_cmd_interval = epd->bInterval;
|
2012-04-19 03:08:28 +00:00
|
|
|
pr_debug("info: bulk OUT: max pkt size: %d, addr: %d\n",
|
|
|
|
le16_to_cpu(epd->wMaxPacketSize),
|
|
|
|
epd->bEndpointAddress);
|
2017-03-27 12:57:44 +00:00
|
|
|
pr_debug("info: Tx CMD:: max pkt size: %d, addr: %d, ep_type: %d\n",
|
|
|
|
le16_to_cpu(epd->wMaxPacketSize),
|
|
|
|
epd->bEndpointAddress, card->tx_cmd_ep_type);
|
2012-04-19 03:08:28 +00:00
|
|
|
card->tx_cmd_ep = usb_endpoint_num(epd);
|
|
|
|
atomic_set(&card->tx_cmd_urb_pending, 0);
|
|
|
|
card->bulk_out_maxpktsize =
|
|
|
|
le16_to_cpu(epd->wMaxPacketSize);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-27 08:08:19 +00:00
|
|
|
switch (card->usb_boot_state) {
|
|
|
|
case USB8XXX_FW_DNLD:
|
|
|
|
/* Reject broken descriptors. */
|
|
|
|
if (!card->rx_cmd_ep || !card->tx_cmd_ep)
|
|
|
|
return -ENODEV;
|
|
|
|
if (card->bulk_out_maxpktsize == 0)
|
|
|
|
return -ENODEV;
|
|
|
|
break;
|
|
|
|
case USB8XXX_FW_READY:
|
|
|
|
/* Assume the driver can handle missing endpoints for now. */
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
WARN_ON(1);
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
2012-04-19 03:08:28 +00:00
|
|
|
usb_set_intfdata(intf, card);
|
|
|
|
|
mwifiex: resolve races between async FW init (failure) and device removal
It's possible for the FW init sequence to fail, which will trigger a
device cleanup sequence in mwifiex_fw_dpc(). This sequence can race with
device suspend() or remove() (e.g., reboot or unbind), and can trigger
use-after-free issues. Currently, this driver attempts (poorly) to
synchronize remove() using a semaphore, but it doesn't protect some of
the critical sections properly. Particularly, we grab a pointer to the
adapter struct (card->adapter) without checking if it's being freed or
not. We later do a NULL check on the adapter, but that doesn't work if
the adapter was freed.
Also note that the PCIe interface driver doesn't ever set card->adapter
to NULL, so even if we get the synchronization right, we still might try
to redo the cleanup in ->remove(), even if the FW init failure sequence
already did it.
This patch replaces the static semaphore with a per-device completion
struct, and uses that completion to synchronize the remove() thread with
the mwifiex_fw_dpc(). A future patch will utilize this completion to
synchronize the suspend() thread as well.
Signed-off-by: Brian Norris <briannorris@chromium.org>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
2016-11-18 14:00:26 +00:00
|
|
|
ret = mwifiex_add_card(card, &card->fw_done, &usb_ops,
|
2016-11-15 13:36:02 +00:00
|
|
|
MWIFIEX_USB, &card->udev->dev);
|
2012-04-19 03:08:28 +00:00
|
|
|
if (ret) {
|
|
|
|
pr_err("%s: mwifiex_add_card failed: %d\n", __func__, ret);
|
|
|
|
usb_reset_device(udev);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
usb_get_dev(udev);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Kernel needs to suspend all functions separately. Therefore all
|
|
|
|
* registered functions must have drivers with suspend and resume
|
|
|
|
* methods. Failing that the kernel simply removes the whole card.
|
|
|
|
*
|
|
|
|
* If already not suspended, this function allocates and sends a
|
|
|
|
* 'host sleep activate' request to the firmware and turns off the traffic.
|
|
|
|
*/
|
|
|
|
static int mwifiex_usb_suspend(struct usb_interface *intf, pm_message_t message)
|
|
|
|
{
|
|
|
|
struct usb_card_rec *card = usb_get_intfdata(intf);
|
|
|
|
struct mwifiex_adapter *adapter;
|
2015-09-18 13:32:16 +00:00
|
|
|
struct usb_tx_data_port *port;
|
|
|
|
int i, j;
|
2012-04-19 03:08:28 +00:00
|
|
|
|
2016-11-18 14:00:29 +00:00
|
|
|
/* Might still be loading firmware */
|
|
|
|
wait_for_completion(&card->fw_done);
|
|
|
|
|
2012-04-19 03:08:28 +00:00
|
|
|
adapter = card->adapter;
|
2016-11-18 14:00:29 +00:00
|
|
|
if (!adapter) {
|
|
|
|
dev_err(&intf->dev, "card is not valid\n");
|
|
|
|
return 0;
|
|
|
|
}
|
2012-04-19 03:08:28 +00:00
|
|
|
|
2018-07-13 12:26:35 +00:00
|
|
|
if (unlikely(test_bit(MWIFIEX_IS_SUSPENDED, &adapter->work_flags)))
|
2015-05-11 19:18:20 +00:00
|
|
|
mwifiex_dbg(adapter, WARN,
|
|
|
|
"Device already suspended\n");
|
2012-04-19 03:08:28 +00:00
|
|
|
|
2016-11-18 14:00:31 +00:00
|
|
|
/* Enable the Host Sleep */
|
|
|
|
if (!mwifiex_enable_hs(adapter)) {
|
|
|
|
mwifiex_dbg(adapter, ERROR,
|
|
|
|
"cmd: failed to suspend\n");
|
2018-07-13 12:26:35 +00:00
|
|
|
clear_bit(MWIFIEX_IS_HS_ENABLING, &adapter->work_flags);
|
2016-11-18 14:00:31 +00:00
|
|
|
return -EFAULT;
|
|
|
|
}
|
|
|
|
|
2012-04-19 03:08:28 +00:00
|
|
|
|
2018-07-13 12:26:35 +00:00
|
|
|
/* 'MWIFIEX_IS_SUSPENDED' bit indicates device is suspended.
|
2012-04-19 03:08:28 +00:00
|
|
|
* It must be set here before the usb_kill_urb() calls. Reason
|
|
|
|
* is in the complete handlers, urb->status(= -ENOENT) and
|
|
|
|
* this flag is used in combination to distinguish between a
|
|
|
|
* 'suspended' state and a 'disconnect' one.
|
|
|
|
*/
|
2018-07-13 12:26:35 +00:00
|
|
|
set_bit(MWIFIEX_IS_SUSPENDED, &adapter->work_flags);
|
|
|
|
clear_bit(MWIFIEX_IS_HS_ENABLING, &adapter->work_flags);
|
2012-04-19 03:08:28 +00:00
|
|
|
|
|
|
|
if (atomic_read(&card->rx_cmd_urb_pending) && card->rx_cmd.urb)
|
|
|
|
usb_kill_urb(card->rx_cmd.urb);
|
|
|
|
|
|
|
|
if (atomic_read(&card->rx_data_urb_pending))
|
|
|
|
for (i = 0; i < MWIFIEX_RX_DATA_URB; i++)
|
|
|
|
if (card->rx_data_list[i].urb)
|
|
|
|
usb_kill_urb(card->rx_data_list[i].urb);
|
|
|
|
|
2015-09-18 13:32:16 +00:00
|
|
|
for (i = 0; i < MWIFIEX_TX_DATA_PORT; i++) {
|
|
|
|
port = &card->port[i];
|
|
|
|
for (j = 0; j < MWIFIEX_TX_DATA_URB; j++) {
|
|
|
|
if (port->tx_data_list[j].urb)
|
|
|
|
usb_kill_urb(port->tx_data_list[j].urb);
|
|
|
|
}
|
|
|
|
}
|
2012-04-19 03:08:28 +00:00
|
|
|
|
|
|
|
if (card->tx_cmd.urb)
|
|
|
|
usb_kill_urb(card->tx_cmd.urb);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Kernel needs to suspend all functions separately. Therefore all
|
|
|
|
* registered functions must have drivers with suspend and resume
|
|
|
|
* methods. Failing that the kernel simply removes the whole card.
|
|
|
|
*
|
|
|
|
* If already not resumed, this function turns on the traffic and
|
|
|
|
* sends a 'host sleep cancel' request to the firmware.
|
|
|
|
*/
|
|
|
|
static int mwifiex_usb_resume(struct usb_interface *intf)
|
|
|
|
{
|
|
|
|
struct usb_card_rec *card = usb_get_intfdata(intf);
|
|
|
|
struct mwifiex_adapter *adapter;
|
|
|
|
int i;
|
|
|
|
|
2016-11-18 14:00:33 +00:00
|
|
|
if (!card->adapter) {
|
|
|
|
dev_err(&intf->dev, "%s: card->adapter is NULL\n",
|
|
|
|
__func__);
|
2012-04-19 03:08:28 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
adapter = card->adapter;
|
|
|
|
|
2018-07-13 12:26:35 +00:00
|
|
|
if (unlikely(!test_bit(MWIFIEX_IS_SUSPENDED, &adapter->work_flags))) {
|
2015-05-11 19:18:20 +00:00
|
|
|
mwifiex_dbg(adapter, WARN,
|
|
|
|
"Device already resumed\n");
|
2012-04-19 03:08:28 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Indicate device resumed. The netdev queue will be resumed only
|
|
|
|
* after the urbs have been re-submitted
|
|
|
|
*/
|
2018-07-13 12:26:35 +00:00
|
|
|
clear_bit(MWIFIEX_IS_SUSPENDED, &adapter->work_flags);
|
2012-04-19 03:08:28 +00:00
|
|
|
|
|
|
|
if (!atomic_read(&card->rx_data_urb_pending))
|
|
|
|
for (i = 0; i < MWIFIEX_RX_DATA_URB; i++)
|
|
|
|
mwifiex_usb_submit_rx_urb(&card->rx_data_list[i],
|
|
|
|
MWIFIEX_RX_DATA_BUF_SIZE);
|
|
|
|
|
|
|
|
if (!atomic_read(&card->rx_cmd_urb_pending)) {
|
|
|
|
card->rx_cmd.skb = dev_alloc_skb(MWIFIEX_RX_CMD_BUF_SIZE);
|
|
|
|
if (card->rx_cmd.skb)
|
|
|
|
mwifiex_usb_submit_rx_urb(&card->rx_cmd,
|
|
|
|
MWIFIEX_RX_CMD_BUF_SIZE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Disable Host Sleep */
|
|
|
|
if (adapter->hs_activated)
|
|
|
|
mwifiex_cancel_hs(mwifiex_get_priv(adapter,
|
|
|
|
MWIFIEX_BSS_ROLE_ANY),
|
|
|
|
MWIFIEX_ASYNC_CMD);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mwifiex_usb_disconnect(struct usb_interface *intf)
|
|
|
|
{
|
|
|
|
struct usb_card_rec *card = usb_get_intfdata(intf);
|
2014-04-14 22:32:54 +00:00
|
|
|
struct mwifiex_adapter *adapter;
|
2012-04-19 03:08:28 +00:00
|
|
|
|
mwifiex: resolve races between async FW init (failure) and device removal
It's possible for the FW init sequence to fail, which will trigger a
device cleanup sequence in mwifiex_fw_dpc(). This sequence can race with
device suspend() or remove() (e.g., reboot or unbind), and can trigger
use-after-free issues. Currently, this driver attempts (poorly) to
synchronize remove() using a semaphore, but it doesn't protect some of
the critical sections properly. Particularly, we grab a pointer to the
adapter struct (card->adapter) without checking if it's being freed or
not. We later do a NULL check on the adapter, but that doesn't work if
the adapter was freed.
Also note that the PCIe interface driver doesn't ever set card->adapter
to NULL, so even if we get the synchronization right, we still might try
to redo the cleanup in ->remove(), even if the FW init failure sequence
already did it.
This patch replaces the static semaphore with a per-device completion
struct, and uses that completion to synchronize the remove() thread with
the mwifiex_fw_dpc(). A future patch will utilize this completion to
synchronize the suspend() thread as well.
Signed-off-by: Brian Norris <briannorris@chromium.org>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
2016-11-18 14:00:26 +00:00
|
|
|
wait_for_completion(&card->fw_done);
|
|
|
|
|
2014-04-14 22:32:54 +00:00
|
|
|
adapter = card->adapter;
|
mwifiex: resolve races between async FW init (failure) and device removal
It's possible for the FW init sequence to fail, which will trigger a
device cleanup sequence in mwifiex_fw_dpc(). This sequence can race with
device suspend() or remove() (e.g., reboot or unbind), and can trigger
use-after-free issues. Currently, this driver attempts (poorly) to
synchronize remove() using a semaphore, but it doesn't protect some of
the critical sections properly. Particularly, we grab a pointer to the
adapter struct (card->adapter) without checking if it's being freed or
not. We later do a NULL check on the adapter, but that doesn't work if
the adapter was freed.
Also note that the PCIe interface driver doesn't ever set card->adapter
to NULL, so even if we get the synchronization right, we still might try
to redo the cleanup in ->remove(), even if the FW init failure sequence
already did it.
This patch replaces the static semaphore with a per-device completion
struct, and uses that completion to synchronize the remove() thread with
the mwifiex_fw_dpc(). A future patch will utilize this completion to
synchronize the suspend() thread as well.
Signed-off-by: Brian Norris <briannorris@chromium.org>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
2016-11-18 14:00:26 +00:00
|
|
|
if (!adapter || !adapter->priv_num)
|
2014-04-14 22:32:54 +00:00
|
|
|
return;
|
2012-04-19 03:08:28 +00:00
|
|
|
|
2016-11-30 14:52:17 +00:00
|
|
|
if (card->udev->state != USB_STATE_NOTATTACHED && !adapter->mfg_mode) {
|
2014-04-14 22:32:54 +00:00
|
|
|
mwifiex_deauthenticate_all(adapter);
|
2013-11-15 03:10:42 +00:00
|
|
|
|
2014-04-14 22:32:54 +00:00
|
|
|
mwifiex_init_shutdown_fw(mwifiex_get_priv(adapter,
|
|
|
|
MWIFIEX_BSS_ROLE_ANY),
|
|
|
|
MWIFIEX_FUNC_SHUTDOWN);
|
2013-11-15 03:10:42 +00:00
|
|
|
}
|
2012-04-19 03:08:28 +00:00
|
|
|
|
2015-05-11 19:18:20 +00:00
|
|
|
mwifiex_dbg(adapter, FATAL,
|
|
|
|
"%s: removing card\n", __func__);
|
mwifiex: resolve races between async FW init (failure) and device removal
It's possible for the FW init sequence to fail, which will trigger a
device cleanup sequence in mwifiex_fw_dpc(). This sequence can race with
device suspend() or remove() (e.g., reboot or unbind), and can trigger
use-after-free issues. Currently, this driver attempts (poorly) to
synchronize remove() using a semaphore, but it doesn't protect some of
the critical sections properly. Particularly, we grab a pointer to the
adapter struct (card->adapter) without checking if it's being freed or
not. We later do a NULL check on the adapter, but that doesn't work if
the adapter was freed.
Also note that the PCIe interface driver doesn't ever set card->adapter
to NULL, so even if we get the synchronization right, we still might try
to redo the cleanup in ->remove(), even if the FW init failure sequence
already did it.
This patch replaces the static semaphore with a per-device completion
struct, and uses that completion to synchronize the remove() thread with
the mwifiex_fw_dpc(). A future patch will utilize this completion to
synchronize the suspend() thread as well.
Signed-off-by: Brian Norris <briannorris@chromium.org>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
2016-11-18 14:00:26 +00:00
|
|
|
mwifiex_remove_card(adapter);
|
2014-04-14 22:32:54 +00:00
|
|
|
|
2012-04-19 03:08:28 +00:00
|
|
|
usb_put_dev(interface_to_usbdev(intf));
|
|
|
|
}
|
|
|
|
|
2018-05-16 12:12:00 +00:00
|
|
|
static void mwifiex_usb_coredump(struct device *dev)
|
|
|
|
{
|
|
|
|
struct usb_interface *intf = to_usb_interface(dev);
|
|
|
|
struct usb_card_rec *card = usb_get_intfdata(intf);
|
|
|
|
|
2018-05-24 11:06:28 +00:00
|
|
|
mwifiex_fw_dump_event(mwifiex_get_priv(card->adapter,
|
|
|
|
MWIFIEX_BSS_ROLE_ANY));
|
2018-05-16 12:12:00 +00:00
|
|
|
}
|
|
|
|
|
2012-04-19 03:08:28 +00:00
|
|
|
static struct usb_driver mwifiex_usb_driver = {
|
2014-02-21 20:23:00 +00:00
|
|
|
.name = "mwifiex_usb",
|
2012-04-19 03:08:28 +00:00
|
|
|
.probe = mwifiex_usb_probe,
|
|
|
|
.disconnect = mwifiex_usb_disconnect,
|
|
|
|
.id_table = mwifiex_usb_table,
|
|
|
|
.suspend = mwifiex_usb_suspend,
|
|
|
|
.resume = mwifiex_usb_resume,
|
2014-04-14 22:32:54 +00:00
|
|
|
.soft_unbind = 1,
|
2018-05-16 12:12:00 +00:00
|
|
|
.drvwrap.driver = {
|
|
|
|
.coredump = mwifiex_usb_coredump,
|
|
|
|
},
|
2012-04-19 03:08:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static int mwifiex_write_data_sync(struct mwifiex_adapter *adapter, u8 *pbuf,
|
|
|
|
u32 *len, u8 ep, u32 timeout)
|
|
|
|
{
|
|
|
|
struct usb_card_rec *card = adapter->card;
|
|
|
|
int actual_length, ret;
|
|
|
|
|
|
|
|
if (!(*len % card->bulk_out_maxpktsize))
|
|
|
|
(*len)++;
|
|
|
|
|
|
|
|
/* Send the data block */
|
|
|
|
ret = usb_bulk_msg(card->udev, usb_sndbulkpipe(card->udev, ep), pbuf,
|
|
|
|
*len, &actual_length, timeout);
|
|
|
|
if (ret) {
|
2015-05-11 19:18:20 +00:00
|
|
|
mwifiex_dbg(adapter, ERROR,
|
|
|
|
"usb_bulk_msg for tx failed: %d\n", ret);
|
2013-01-26 02:23:00 +00:00
|
|
|
return ret;
|
2012-04-19 03:08:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
*len = actual_length;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mwifiex_read_data_sync(struct mwifiex_adapter *adapter, u8 *pbuf,
|
|
|
|
u32 *len, u8 ep, u32 timeout)
|
|
|
|
{
|
|
|
|
struct usb_card_rec *card = adapter->card;
|
|
|
|
int actual_length, ret;
|
|
|
|
|
|
|
|
/* Receive the data response */
|
|
|
|
ret = usb_bulk_msg(card->udev, usb_rcvbulkpipe(card->udev, ep), pbuf,
|
|
|
|
*len, &actual_length, timeout);
|
|
|
|
if (ret) {
|
2015-05-11 19:18:20 +00:00
|
|
|
mwifiex_dbg(adapter, ERROR,
|
|
|
|
"usb_bulk_msg for rx failed: %d\n", ret);
|
2013-01-26 02:23:00 +00:00
|
|
|
return ret;
|
2012-04-19 03:08:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
*len = actual_length;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-09-18 13:32:17 +00:00
|
|
|
static void mwifiex_usb_port_resync(struct mwifiex_adapter *adapter)
|
|
|
|
{
|
|
|
|
struct usb_card_rec *card = adapter->card;
|
|
|
|
u8 active_port = MWIFIEX_USB_EP_DATA;
|
|
|
|
struct mwifiex_private *priv = NULL;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (adapter->usb_mc_status) {
|
|
|
|
for (i = 0; i < adapter->priv_num; i++) {
|
|
|
|
priv = adapter->priv[i];
|
|
|
|
if (!priv)
|
|
|
|
continue;
|
|
|
|
if ((priv->bss_role == MWIFIEX_BSS_ROLE_UAP &&
|
|
|
|
!priv->bss_started) ||
|
|
|
|
(priv->bss_role == MWIFIEX_BSS_ROLE_STA &&
|
|
|
|
!priv->media_connected))
|
|
|
|
priv->usb_port = MWIFIEX_USB_EP_DATA;
|
|
|
|
}
|
|
|
|
for (i = 0; i < MWIFIEX_TX_DATA_PORT; i++)
|
|
|
|
card->port[i].block_status = false;
|
|
|
|
} else {
|
|
|
|
for (i = 0; i < adapter->priv_num; i++) {
|
|
|
|
priv = adapter->priv[i];
|
|
|
|
if (!priv)
|
|
|
|
continue;
|
|
|
|
if ((priv->bss_role == MWIFIEX_BSS_ROLE_UAP &&
|
|
|
|
priv->bss_started) ||
|
|
|
|
(priv->bss_role == MWIFIEX_BSS_ROLE_STA &&
|
|
|
|
priv->media_connected)) {
|
|
|
|
active_port = priv->usb_port;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (i = 0; i < adapter->priv_num; i++) {
|
|
|
|
priv = adapter->priv[i];
|
|
|
|
if (priv)
|
|
|
|
priv->usb_port = active_port;
|
|
|
|
}
|
|
|
|
for (i = 0; i < MWIFIEX_TX_DATA_PORT; i++) {
|
|
|
|
if (active_port == card->port[i].tx_data_ep)
|
|
|
|
card->port[i].block_status = false;
|
|
|
|
else
|
|
|
|
card->port[i].block_status = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-18 13:32:18 +00:00
|
|
|
static bool mwifiex_usb_is_port_ready(struct mwifiex_private *priv)
|
|
|
|
{
|
|
|
|
struct usb_card_rec *card = priv->adapter->card;
|
|
|
|
int idx;
|
|
|
|
|
|
|
|
for (idx = 0; idx < MWIFIEX_TX_DATA_PORT; idx++) {
|
|
|
|
if (priv->usb_port == card->port[idx].tx_data_ep)
|
|
|
|
return !card->port[idx].block_status;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline u8 mwifiex_usb_data_sent(struct mwifiex_adapter *adapter)
|
|
|
|
{
|
|
|
|
struct usb_card_rec *card = adapter->card;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < MWIFIEX_TX_DATA_PORT; i++)
|
|
|
|
if (!card->port[i].block_status)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-05-23 07:12:32 +00:00
|
|
|
static int mwifiex_usb_construct_send_urb(struct mwifiex_adapter *adapter,
|
|
|
|
struct usb_tx_data_port *port, u8 ep,
|
|
|
|
struct urb_context *context,
|
|
|
|
struct sk_buff *skb_send)
|
2012-04-19 03:08:28 +00:00
|
|
|
{
|
|
|
|
struct usb_card_rec *card = adapter->card;
|
2017-05-23 07:12:32 +00:00
|
|
|
int ret = -EINPROGRESS;
|
2012-04-19 03:08:28 +00:00
|
|
|
struct urb *tx_urb;
|
|
|
|
|
|
|
|
context->adapter = adapter;
|
|
|
|
context->ep = ep;
|
2017-05-23 07:12:32 +00:00
|
|
|
context->skb = skb_send;
|
2012-04-19 03:08:28 +00:00
|
|
|
tx_urb = context->urb;
|
|
|
|
|
2017-03-27 12:57:44 +00:00
|
|
|
if (ep == card->tx_cmd_ep &&
|
|
|
|
card->tx_cmd_ep_type == USB_ENDPOINT_XFER_INT)
|
|
|
|
usb_fill_int_urb(tx_urb, card->udev,
|
2017-05-23 07:12:32 +00:00
|
|
|
usb_sndintpipe(card->udev, ep), skb_send->data,
|
|
|
|
skb_send->len, mwifiex_usb_tx_complete,
|
2017-03-27 12:57:44 +00:00
|
|
|
(void *)context, card->tx_cmd_interval);
|
|
|
|
else
|
|
|
|
usb_fill_bulk_urb(tx_urb, card->udev,
|
2017-05-23 07:12:32 +00:00
|
|
|
usb_sndbulkpipe(card->udev, ep),
|
|
|
|
skb_send->data, skb_send->len,
|
|
|
|
mwifiex_usb_tx_complete, (void *)context);
|
2012-04-19 03:08:28 +00:00
|
|
|
|
|
|
|
tx_urb->transfer_flags |= URB_ZERO_PACKET;
|
|
|
|
|
|
|
|
if (ep == card->tx_cmd_ep)
|
|
|
|
atomic_inc(&card->tx_cmd_urb_pending);
|
|
|
|
else
|
2015-09-18 13:32:16 +00:00
|
|
|
atomic_inc(&port->tx_data_urb_pending);
|
2012-04-19 03:08:28 +00:00
|
|
|
|
2016-09-20 15:19:03 +00:00
|
|
|
if (ep != card->tx_cmd_ep &&
|
|
|
|
atomic_read(&port->tx_data_urb_pending) ==
|
|
|
|
MWIFIEX_TX_DATA_URB) {
|
|
|
|
port->block_status = true;
|
|
|
|
adapter->data_sent = mwifiex_usb_data_sent(adapter);
|
2016-09-20 15:19:04 +00:00
|
|
|
ret = -ENOSR;
|
2016-09-20 15:19:03 +00:00
|
|
|
}
|
|
|
|
|
2012-04-19 03:08:28 +00:00
|
|
|
if (usb_submit_urb(tx_urb, GFP_ATOMIC)) {
|
2015-05-11 19:18:20 +00:00
|
|
|
mwifiex_dbg(adapter, ERROR,
|
|
|
|
"%s: usb_submit_urb failed\n", __func__);
|
2012-04-19 03:08:28 +00:00
|
|
|
if (ep == card->tx_cmd_ep) {
|
|
|
|
atomic_dec(&card->tx_cmd_urb_pending);
|
|
|
|
} else {
|
2015-09-18 13:32:16 +00:00
|
|
|
atomic_dec(&port->tx_data_urb_pending);
|
2015-09-18 13:32:18 +00:00
|
|
|
port->block_status = false;
|
2016-09-20 15:19:03 +00:00
|
|
|
adapter->data_sent = false;
|
2015-09-18 13:32:16 +00:00
|
|
|
if (port->tx_data_ix)
|
|
|
|
port->tx_data_ix--;
|
2012-04-19 03:08:28 +00:00
|
|
|
else
|
2015-09-18 13:32:16 +00:00
|
|
|
port->tx_data_ix = MWIFIEX_TX_DATA_URB;
|
2012-04-19 03:08:28 +00:00
|
|
|
}
|
2016-09-20 15:19:04 +00:00
|
|
|
ret = -1;
|
2012-04-19 03:08:28 +00:00
|
|
|
}
|
|
|
|
|
2015-09-18 13:32:18 +00:00
|
|
|
return ret;
|
2012-04-19 03:08:28 +00:00
|
|
|
}
|
|
|
|
|
2017-05-23 07:12:32 +00:00
|
|
|
static int mwifiex_usb_prepare_tx_aggr_skb(struct mwifiex_adapter *adapter,
|
|
|
|
struct usb_tx_data_port *port,
|
|
|
|
struct sk_buff **skb_send)
|
|
|
|
{
|
|
|
|
struct sk_buff *skb_aggr, *skb_tmp;
|
|
|
|
u8 *payload, pad;
|
|
|
|
u16 align = adapter->bus_aggr.tx_aggr_align;
|
|
|
|
struct mwifiex_txinfo *tx_info = NULL;
|
|
|
|
bool is_txinfo_set = false;
|
|
|
|
|
2017-05-23 07:12:33 +00:00
|
|
|
/* Packets in aggr_list will be send in either skb_aggr or
|
|
|
|
* write complete, delete the tx_aggr timer
|
|
|
|
*/
|
|
|
|
if (port->tx_aggr.timer_cnxt.is_hold_timer_set) {
|
|
|
|
del_timer(&port->tx_aggr.timer_cnxt.hold_timer);
|
|
|
|
port->tx_aggr.timer_cnxt.is_hold_timer_set = false;
|
|
|
|
port->tx_aggr.timer_cnxt.hold_tmo_msecs = 0;
|
|
|
|
}
|
|
|
|
|
2017-05-23 07:12:32 +00:00
|
|
|
skb_aggr = mwifiex_alloc_dma_align_buf(port->tx_aggr.aggr_len,
|
|
|
|
GFP_ATOMIC);
|
|
|
|
if (!skb_aggr) {
|
|
|
|
mwifiex_dbg(adapter, ERROR,
|
|
|
|
"%s: alloc skb_aggr failed\n", __func__);
|
|
|
|
|
|
|
|
while ((skb_tmp = skb_dequeue(&port->tx_aggr.aggr_list)))
|
|
|
|
mwifiex_write_data_complete(adapter, skb_tmp, 0, -1);
|
|
|
|
|
|
|
|
port->tx_aggr.aggr_num = 0;
|
|
|
|
port->tx_aggr.aggr_len = 0;
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
|
|
|
|
tx_info = MWIFIEX_SKB_TXCB(skb_aggr);
|
|
|
|
memset(tx_info, 0, sizeof(*tx_info));
|
|
|
|
|
|
|
|
while ((skb_tmp = skb_dequeue(&port->tx_aggr.aggr_list))) {
|
|
|
|
/* padding for aligning next packet header*/
|
|
|
|
pad = (align - (skb_tmp->len & (align - 1))) % align;
|
|
|
|
payload = skb_put(skb_aggr, skb_tmp->len + pad);
|
|
|
|
memcpy(payload, skb_tmp->data, skb_tmp->len);
|
|
|
|
if (skb_queue_empty(&port->tx_aggr.aggr_list)) {
|
|
|
|
/* do not padding for last packet*/
|
|
|
|
*(u16 *)payload = cpu_to_le16(skb_tmp->len);
|
|
|
|
*(u16 *)&payload[2] =
|
|
|
|
cpu_to_le16(MWIFIEX_TYPE_AGGR_DATA_V2 | 0x80);
|
|
|
|
skb_trim(skb_aggr, skb_aggr->len - pad);
|
|
|
|
} else {
|
|
|
|
/* add aggregation interface header */
|
|
|
|
*(u16 *)payload = cpu_to_le16(skb_tmp->len + pad);
|
|
|
|
*(u16 *)&payload[2] =
|
|
|
|
cpu_to_le16(MWIFIEX_TYPE_AGGR_DATA_V2);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!is_txinfo_set) {
|
|
|
|
tx_info->bss_num = MWIFIEX_SKB_TXCB(skb_tmp)->bss_num;
|
|
|
|
tx_info->bss_type = MWIFIEX_SKB_TXCB(skb_tmp)->bss_type;
|
|
|
|
is_txinfo_set = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
port->tx_aggr.aggr_num--;
|
|
|
|
port->tx_aggr.aggr_len -= (skb_tmp->len + pad);
|
|
|
|
mwifiex_write_data_complete(adapter, skb_tmp, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
tx_info->pkt_len = skb_aggr->len -
|
|
|
|
(sizeof(struct txpd) + adapter->intf_hdr_len);
|
|
|
|
tx_info->flags |= MWIFIEX_BUF_FLAG_AGGR_PKT;
|
|
|
|
|
|
|
|
port->tx_aggr.aggr_num = 0;
|
|
|
|
port->tx_aggr.aggr_len = 0;
|
|
|
|
*skb_send = skb_aggr;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This function prepare data packet to be send under usb tx aggregation
|
|
|
|
* protocol, check current usb aggregation status, link packet to aggrgation
|
|
|
|
* list if possible, work flow as below:
|
|
|
|
* (1) if only 1 packet available, add usb tx aggregation header and send.
|
|
|
|
* (2) if packet is able to aggregated, link it to current aggregation list.
|
|
|
|
* (3) if packet is not able to aggregated, aggregate and send exist packets
|
|
|
|
* in aggrgation list. Then, link packet in the list if there is more
|
|
|
|
* packet in transmit queue, otherwise try to transmit single packet.
|
|
|
|
*/
|
|
|
|
static int mwifiex_usb_aggr_tx_data(struct mwifiex_adapter *adapter, u8 ep,
|
|
|
|
struct sk_buff *skb,
|
|
|
|
struct mwifiex_tx_param *tx_param,
|
|
|
|
struct usb_tx_data_port *port)
|
|
|
|
{
|
|
|
|
u8 *payload, pad;
|
|
|
|
u16 align = adapter->bus_aggr.tx_aggr_align;
|
|
|
|
struct sk_buff *skb_send = NULL;
|
|
|
|
struct urb_context *context = NULL;
|
|
|
|
struct txpd *local_tx_pd =
|
|
|
|
(struct txpd *)((u8 *)skb->data + adapter->intf_hdr_len);
|
|
|
|
u8 f_send_aggr_buf = 0;
|
|
|
|
u8 f_send_cur_buf = 0;
|
|
|
|
u8 f_precopy_cur_buf = 0;
|
|
|
|
u8 f_postcopy_cur_buf = 0;
|
2017-05-23 07:12:33 +00:00
|
|
|
u32 timeout;
|
2017-05-23 07:12:32 +00:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* padding to ensure each packet alginment */
|
|
|
|
pad = (align - (skb->len & (align - 1))) % align;
|
|
|
|
|
|
|
|
if (tx_param && tx_param->next_pkt_len) {
|
|
|
|
/* next packet available in tx queue*/
|
|
|
|
if (port->tx_aggr.aggr_len + skb->len + pad >
|
|
|
|
adapter->bus_aggr.tx_aggr_max_size) {
|
|
|
|
f_send_aggr_buf = 1;
|
|
|
|
f_postcopy_cur_buf = 1;
|
|
|
|
} else {
|
|
|
|
/* current packet could be aggregated*/
|
|
|
|
f_precopy_cur_buf = 1;
|
|
|
|
|
|
|
|
if (port->tx_aggr.aggr_len + skb->len + pad +
|
|
|
|
tx_param->next_pkt_len >
|
|
|
|
adapter->bus_aggr.tx_aggr_max_size ||
|
|
|
|
port->tx_aggr.aggr_num + 2 >
|
|
|
|
adapter->bus_aggr.tx_aggr_max_num) {
|
|
|
|
/* next packet could not be aggregated
|
|
|
|
* send current aggregation buffer
|
|
|
|
*/
|
|
|
|
f_send_aggr_buf = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* last packet in tx queue */
|
|
|
|
if (port->tx_aggr.aggr_num > 0) {
|
|
|
|
/* pending packets in aggregation buffer*/
|
|
|
|
if (port->tx_aggr.aggr_len + skb->len + pad >
|
|
|
|
adapter->bus_aggr.tx_aggr_max_size) {
|
|
|
|
/* current packet not be able to aggregated,
|
|
|
|
* send aggr buffer first, then send packet.
|
|
|
|
*/
|
|
|
|
f_send_cur_buf = 1;
|
|
|
|
} else {
|
|
|
|
/* last packet, Aggregation and send */
|
|
|
|
f_precopy_cur_buf = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
f_send_aggr_buf = 1;
|
|
|
|
} else {
|
|
|
|
/* no pending packets in aggregation buffer,
|
|
|
|
* send current packet immediately
|
|
|
|
*/
|
|
|
|
f_send_cur_buf = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (local_tx_pd->flags & MWIFIEX_TxPD_POWER_MGMT_NULL_PACKET) {
|
|
|
|
/* Send NULL packet immediately*/
|
|
|
|
if (f_precopy_cur_buf) {
|
|
|
|
if (skb_queue_empty(&port->tx_aggr.aggr_list)) {
|
|
|
|
f_precopy_cur_buf = 0;
|
|
|
|
f_send_aggr_buf = 0;
|
|
|
|
f_send_cur_buf = 1;
|
|
|
|
} else {
|
|
|
|
f_send_aggr_buf = 1;
|
|
|
|
}
|
|
|
|
} else if (f_postcopy_cur_buf) {
|
|
|
|
f_send_cur_buf = 1;
|
|
|
|
f_postcopy_cur_buf = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (f_precopy_cur_buf) {
|
|
|
|
skb_queue_tail(&port->tx_aggr.aggr_list, skb);
|
|
|
|
port->tx_aggr.aggr_len += (skb->len + pad);
|
|
|
|
port->tx_aggr.aggr_num++;
|
2017-05-23 07:12:33 +00:00
|
|
|
if (f_send_aggr_buf)
|
|
|
|
goto send_aggr_buf;
|
|
|
|
|
|
|
|
/* packet will not been send immediately,
|
|
|
|
* set a timer to make sure it will be sent under
|
|
|
|
* strict time limit. Dynamically fit the timeout
|
|
|
|
* value, according to packets number in aggr_list
|
|
|
|
*/
|
|
|
|
if (!port->tx_aggr.timer_cnxt.is_hold_timer_set) {
|
|
|
|
port->tx_aggr.timer_cnxt.hold_tmo_msecs =
|
|
|
|
MWIFIEX_USB_TX_AGGR_TMO_MIN;
|
|
|
|
timeout =
|
|
|
|
port->tx_aggr.timer_cnxt.hold_tmo_msecs;
|
|
|
|
mod_timer(&port->tx_aggr.timer_cnxt.hold_timer,
|
|
|
|
jiffies + msecs_to_jiffies(timeout));
|
|
|
|
port->tx_aggr.timer_cnxt.is_hold_timer_set = true;
|
|
|
|
} else {
|
|
|
|
if (port->tx_aggr.timer_cnxt.hold_tmo_msecs <
|
|
|
|
MWIFIEX_USB_TX_AGGR_TMO_MAX) {
|
|
|
|
/* Dyanmic fit timeout */
|
|
|
|
timeout =
|
|
|
|
++port->tx_aggr.timer_cnxt.hold_tmo_msecs;
|
|
|
|
mod_timer(&port->tx_aggr.timer_cnxt.hold_timer,
|
|
|
|
jiffies + msecs_to_jiffies(timeout));
|
|
|
|
}
|
|
|
|
}
|
2017-05-23 07:12:32 +00:00
|
|
|
}
|
|
|
|
|
2017-05-23 07:12:33 +00:00
|
|
|
send_aggr_buf:
|
2017-05-23 07:12:32 +00:00
|
|
|
if (f_send_aggr_buf) {
|
|
|
|
ret = mwifiex_usb_prepare_tx_aggr_skb(adapter, port, &skb_send);
|
|
|
|
if (!ret) {
|
|
|
|
context = &port->tx_data_list[port->tx_data_ix++];
|
|
|
|
ret = mwifiex_usb_construct_send_urb(adapter, port, ep,
|
|
|
|
context, skb_send);
|
|
|
|
if (ret == -1)
|
|
|
|
mwifiex_write_data_complete(adapter, skb_send,
|
|
|
|
0, -1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (f_send_cur_buf) {
|
|
|
|
if (f_send_aggr_buf) {
|
|
|
|
if (atomic_read(&port->tx_data_urb_pending) >=
|
|
|
|
MWIFIEX_TX_DATA_URB) {
|
|
|
|
port->block_status = true;
|
|
|
|
adapter->data_sent =
|
|
|
|
mwifiex_usb_data_sent(adapter);
|
|
|
|
/* no available urb, postcopy packet*/
|
|
|
|
f_postcopy_cur_buf = 1;
|
|
|
|
goto postcopy_cur_buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (port->tx_data_ix >= MWIFIEX_TX_DATA_URB)
|
|
|
|
port->tx_data_ix = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
payload = skb->data;
|
|
|
|
*(u16 *)&payload[2] =
|
|
|
|
cpu_to_le16(MWIFIEX_TYPE_AGGR_DATA_V2 | 0x80);
|
|
|
|
*(u16 *)payload = cpu_to_le16(skb->len);
|
|
|
|
skb_send = skb;
|
|
|
|
context = &port->tx_data_list[port->tx_data_ix++];
|
|
|
|
return mwifiex_usb_construct_send_urb(adapter, port, ep,
|
|
|
|
context, skb_send);
|
|
|
|
}
|
|
|
|
|
|
|
|
postcopy_cur_buf:
|
|
|
|
if (f_postcopy_cur_buf) {
|
|
|
|
skb_queue_tail(&port->tx_aggr.aggr_list, skb);
|
|
|
|
port->tx_aggr.aggr_len += (skb->len + pad);
|
|
|
|
port->tx_aggr.aggr_num++;
|
2017-05-23 07:12:33 +00:00
|
|
|
/* New aggregation begin, start timer */
|
|
|
|
if (!port->tx_aggr.timer_cnxt.is_hold_timer_set) {
|
|
|
|
port->tx_aggr.timer_cnxt.hold_tmo_msecs =
|
|
|
|
MWIFIEX_USB_TX_AGGR_TMO_MIN;
|
|
|
|
timeout = port->tx_aggr.timer_cnxt.hold_tmo_msecs;
|
|
|
|
mod_timer(&port->tx_aggr.timer_cnxt.hold_timer,
|
|
|
|
jiffies + msecs_to_jiffies(timeout));
|
|
|
|
port->tx_aggr.timer_cnxt.is_hold_timer_set = true;
|
|
|
|
}
|
2017-05-23 07:12:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return -EINPROGRESS;
|
|
|
|
}
|
|
|
|
|
2017-10-24 09:29:19 +00:00
|
|
|
static void mwifiex_usb_tx_aggr_tmo(struct timer_list *t)
|
2017-05-23 07:12:33 +00:00
|
|
|
{
|
|
|
|
struct urb_context *urb_cnxt = NULL;
|
|
|
|
struct sk_buff *skb_send = NULL;
|
|
|
|
struct tx_aggr_tmr_cnxt *timer_context =
|
2017-10-24 09:29:19 +00:00
|
|
|
from_timer(timer_context, t, hold_timer);
|
2017-05-23 07:12:33 +00:00
|
|
|
struct mwifiex_adapter *adapter = timer_context->adapter;
|
|
|
|
struct usb_tx_data_port *port = timer_context->port;
|
|
|
|
int err = 0;
|
|
|
|
|
2019-06-25 17:40:45 +00:00
|
|
|
spin_lock_bh(&port->tx_aggr_lock);
|
2017-05-23 07:12:33 +00:00
|
|
|
err = mwifiex_usb_prepare_tx_aggr_skb(adapter, port, &skb_send);
|
|
|
|
if (err) {
|
|
|
|
mwifiex_dbg(adapter, ERROR,
|
|
|
|
"prepare tx aggr skb failed, err=%d\n", err);
|
2017-07-10 07:21:15 +00:00
|
|
|
goto unlock;
|
2017-05-23 07:12:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (atomic_read(&port->tx_data_urb_pending) >=
|
|
|
|
MWIFIEX_TX_DATA_URB) {
|
|
|
|
port->block_status = true;
|
|
|
|
adapter->data_sent =
|
|
|
|
mwifiex_usb_data_sent(adapter);
|
|
|
|
err = -1;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (port->tx_data_ix >= MWIFIEX_TX_DATA_URB)
|
|
|
|
port->tx_data_ix = 0;
|
|
|
|
|
|
|
|
urb_cnxt = &port->tx_data_list[port->tx_data_ix++];
|
|
|
|
err = mwifiex_usb_construct_send_urb(adapter, port, port->tx_data_ep,
|
|
|
|
urb_cnxt, skb_send);
|
|
|
|
done:
|
|
|
|
if (err == -1)
|
|
|
|
mwifiex_write_data_complete(adapter, skb_send, 0, -1);
|
2017-07-10 07:21:15 +00:00
|
|
|
unlock:
|
2019-06-25 17:40:45 +00:00
|
|
|
spin_unlock_bh(&port->tx_aggr_lock);
|
2017-05-23 07:12:33 +00:00
|
|
|
}
|
|
|
|
|
2017-05-23 07:12:32 +00:00
|
|
|
/* This function write a command/data packet to card. */
|
|
|
|
static int mwifiex_usb_host_to_card(struct mwifiex_adapter *adapter, u8 ep,
|
|
|
|
struct sk_buff *skb,
|
|
|
|
struct mwifiex_tx_param *tx_param)
|
|
|
|
{
|
|
|
|
struct usb_card_rec *card = adapter->card;
|
|
|
|
struct urb_context *context = NULL;
|
|
|
|
struct usb_tx_data_port *port = NULL;
|
2017-05-23 07:12:33 +00:00
|
|
|
int idx, ret;
|
2017-05-23 07:12:32 +00:00
|
|
|
|
2018-07-13 12:26:35 +00:00
|
|
|
if (test_bit(MWIFIEX_IS_SUSPENDED, &adapter->work_flags)) {
|
2017-05-23 07:12:32 +00:00
|
|
|
mwifiex_dbg(adapter, ERROR,
|
|
|
|
"%s: not allowed while suspended\n", __func__);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2018-07-13 12:26:35 +00:00
|
|
|
if (test_bit(MWIFIEX_SURPRISE_REMOVED, &adapter->work_flags)) {
|
2017-05-23 07:12:32 +00:00
|
|
|
mwifiex_dbg(adapter, ERROR, "%s: device removed\n", __func__);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
mwifiex_dbg(adapter, INFO, "%s: ep=%d\n", __func__, ep);
|
|
|
|
|
|
|
|
if (ep == card->tx_cmd_ep) {
|
|
|
|
context = &card->tx_cmd;
|
|
|
|
} else {
|
|
|
|
/* get the data port structure for endpoint */
|
|
|
|
for (idx = 0; idx < MWIFIEX_TX_DATA_PORT; idx++) {
|
|
|
|
if (ep == card->port[idx].tx_data_ep) {
|
|
|
|
port = &card->port[idx];
|
|
|
|
if (atomic_read(&port->tx_data_urb_pending)
|
|
|
|
>= MWIFIEX_TX_DATA_URB) {
|
|
|
|
port->block_status = true;
|
|
|
|
adapter->data_sent =
|
|
|
|
mwifiex_usb_data_sent(adapter);
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
if (port->tx_data_ix >= MWIFIEX_TX_DATA_URB)
|
|
|
|
port->tx_data_ix = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!port) {
|
|
|
|
mwifiex_dbg(adapter, ERROR, "Wrong usb tx data port\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2017-05-23 07:12:33 +00:00
|
|
|
if (adapter->bus_aggr.enable) {
|
2019-06-25 17:40:45 +00:00
|
|
|
spin_lock_bh(&port->tx_aggr_lock);
|
2017-05-23 07:12:33 +00:00
|
|
|
ret = mwifiex_usb_aggr_tx_data(adapter, ep, skb,
|
2017-05-23 07:12:32 +00:00
|
|
|
tx_param, port);
|
2019-06-25 17:40:45 +00:00
|
|
|
spin_unlock_bh(&port->tx_aggr_lock);
|
2017-05-23 07:12:33 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2017-05-23 07:12:32 +00:00
|
|
|
|
|
|
|
context = &port->tx_data_list[port->tx_data_ix++];
|
|
|
|
}
|
|
|
|
|
|
|
|
return mwifiex_usb_construct_send_urb(adapter, port, ep, context, skb);
|
|
|
|
}
|
|
|
|
|
2017-05-23 07:12:33 +00:00
|
|
|
static int mwifiex_usb_tx_init(struct mwifiex_adapter *adapter)
|
|
|
|
{
|
|
|
|
struct usb_card_rec *card = (struct usb_card_rec *)adapter->card;
|
|
|
|
struct usb_tx_data_port *port;
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
card->tx_cmd.adapter = adapter;
|
|
|
|
card->tx_cmd.ep = card->tx_cmd_ep;
|
|
|
|
|
|
|
|
card->tx_cmd.urb = usb_alloc_urb(0, GFP_KERNEL);
|
|
|
|
if (!card->tx_cmd.urb)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
for (i = 0; i < MWIFIEX_TX_DATA_PORT; i++) {
|
|
|
|
port = &card->port[i];
|
|
|
|
if (!port->tx_data_ep)
|
|
|
|
continue;
|
|
|
|
port->tx_data_ix = 0;
|
|
|
|
skb_queue_head_init(&port->tx_aggr.aggr_list);
|
|
|
|
if (port->tx_data_ep == MWIFIEX_USB_EP_DATA)
|
|
|
|
port->block_status = false;
|
|
|
|
else
|
|
|
|
port->block_status = true;
|
|
|
|
for (j = 0; j < MWIFIEX_TX_DATA_URB; j++) {
|
|
|
|
port->tx_data_list[j].adapter = adapter;
|
|
|
|
port->tx_data_list[j].ep = port->tx_data_ep;
|
|
|
|
port->tx_data_list[j].urb =
|
|
|
|
usb_alloc_urb(0, GFP_KERNEL);
|
|
|
|
if (!port->tx_data_list[j].urb)
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
port->tx_aggr.timer_cnxt.adapter = adapter;
|
|
|
|
port->tx_aggr.timer_cnxt.port = port;
|
|
|
|
port->tx_aggr.timer_cnxt.is_hold_timer_set = false;
|
|
|
|
port->tx_aggr.timer_cnxt.hold_tmo_msecs = 0;
|
2017-10-24 09:29:19 +00:00
|
|
|
timer_setup(&port->tx_aggr.timer_cnxt.hold_timer,
|
|
|
|
mwifiex_usb_tx_aggr_tmo, 0);
|
2017-05-23 07:12:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mwifiex_usb_rx_init(struct mwifiex_adapter *adapter)
|
|
|
|
{
|
|
|
|
struct usb_card_rec *card = (struct usb_card_rec *)adapter->card;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
card->rx_cmd.adapter = adapter;
|
|
|
|
card->rx_cmd.ep = card->rx_cmd_ep;
|
|
|
|
|
|
|
|
card->rx_cmd.urb = usb_alloc_urb(0, GFP_KERNEL);
|
|
|
|
if (!card->rx_cmd.urb)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
card->rx_cmd.skb = dev_alloc_skb(MWIFIEX_RX_CMD_BUF_SIZE);
|
|
|
|
if (!card->rx_cmd.skb)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
if (mwifiex_usb_submit_rx_urb(&card->rx_cmd, MWIFIEX_RX_CMD_BUF_SIZE))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
for (i = 0; i < MWIFIEX_RX_DATA_URB; i++) {
|
|
|
|
card->rx_data_list[i].adapter = adapter;
|
|
|
|
card->rx_data_list[i].ep = card->rx_data_ep;
|
|
|
|
|
|
|
|
card->rx_data_list[i].urb = usb_alloc_urb(0, GFP_KERNEL);
|
|
|
|
if (!card->rx_data_list[i].urb)
|
|
|
|
return -1;
|
|
|
|
if (mwifiex_usb_submit_rx_urb(&card->rx_data_list[i],
|
|
|
|
MWIFIEX_RX_DATA_BUF_SIZE))
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-04-19 03:08:28 +00:00
|
|
|
/* This function register usb device and initialize parameter. */
|
|
|
|
static int mwifiex_register_dev(struct mwifiex_adapter *adapter)
|
|
|
|
{
|
|
|
|
struct usb_card_rec *card = (struct usb_card_rec *)adapter->card;
|
|
|
|
|
|
|
|
card->adapter = adapter;
|
|
|
|
|
2014-01-10 03:36:55 +00:00
|
|
|
switch (le16_to_cpu(card->udev->descriptor.idProduct)) {
|
2015-08-05 13:09:40 +00:00
|
|
|
case USB8997_PID_1:
|
|
|
|
case USB8997_PID_2:
|
|
|
|
adapter->tx_buf_size = MWIFIEX_TX_DATA_BUF_SIZE_4K;
|
|
|
|
strcpy(adapter->fw_name, USB8997_DEFAULT_FW_NAME);
|
|
|
|
adapter->ext_scan = true;
|
|
|
|
break;
|
2014-11-20 15:52:58 +00:00
|
|
|
case USB8766_PID_1:
|
|
|
|
case USB8766_PID_2:
|
|
|
|
adapter->tx_buf_size = MWIFIEX_TX_DATA_BUF_SIZE_2K;
|
|
|
|
strcpy(adapter->fw_name, USB8766_DEFAULT_FW_NAME);
|
2015-01-23 11:39:19 +00:00
|
|
|
adapter->ext_scan = true;
|
2014-11-20 15:52:58 +00:00
|
|
|
break;
|
2015-01-23 11:39:18 +00:00
|
|
|
case USB8801_PID_1:
|
|
|
|
case USB8801_PID_2:
|
|
|
|
adapter->tx_buf_size = MWIFIEX_TX_DATA_BUF_SIZE_2K;
|
|
|
|
strcpy(adapter->fw_name, USB8801_DEFAULT_FW_NAME);
|
2015-01-23 11:39:19 +00:00
|
|
|
adapter->ext_scan = false;
|
2015-01-23 11:39:18 +00:00
|
|
|
break;
|
2014-01-10 03:36:55 +00:00
|
|
|
case USB8797_PID_1:
|
|
|
|
case USB8797_PID_2:
|
|
|
|
default:
|
2014-02-28 03:35:13 +00:00
|
|
|
adapter->tx_buf_size = MWIFIEX_TX_DATA_BUF_SIZE_2K;
|
2014-01-10 03:36:55 +00:00
|
|
|
strcpy(adapter->fw_name, USB8797_DEFAULT_FW_NAME);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-09-18 13:32:15 +00:00
|
|
|
adapter->usb_mc_status = false;
|
2015-09-18 13:32:17 +00:00
|
|
|
adapter->usb_mc_setup = false;
|
2015-09-18 13:32:15 +00:00
|
|
|
|
2012-04-19 03:08:28 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-05-23 07:12:32 +00:00
|
|
|
static void mwifiex_usb_cleanup_tx_aggr(struct mwifiex_adapter *adapter)
|
|
|
|
{
|
|
|
|
struct usb_card_rec *card = (struct usb_card_rec *)adapter->card;
|
|
|
|
struct usb_tx_data_port *port;
|
|
|
|
struct sk_buff *skb_tmp;
|
|
|
|
int idx;
|
|
|
|
|
2017-05-23 07:12:33 +00:00
|
|
|
for (idx = 0; idx < MWIFIEX_TX_DATA_PORT; idx++) {
|
|
|
|
port = &card->port[idx];
|
|
|
|
if (adapter->bus_aggr.enable)
|
2017-05-23 07:12:32 +00:00
|
|
|
while ((skb_tmp =
|
|
|
|
skb_dequeue(&port->tx_aggr.aggr_list)))
|
|
|
|
mwifiex_write_data_complete(adapter, skb_tmp,
|
|
|
|
0, -1);
|
2020-08-21 08:27:19 +00:00
|
|
|
if (port->tx_aggr.timer_cnxt.hold_timer.function)
|
|
|
|
del_timer_sync(&port->tx_aggr.timer_cnxt.hold_timer);
|
2017-05-23 07:12:33 +00:00
|
|
|
port->tx_aggr.timer_cnxt.is_hold_timer_set = false;
|
|
|
|
port->tx_aggr.timer_cnxt.hold_tmo_msecs = 0;
|
2017-05-23 07:12:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-23 02:17:51 +00:00
|
|
|
static void mwifiex_unregister_dev(struct mwifiex_adapter *adapter)
|
|
|
|
{
|
|
|
|
struct usb_card_rec *card = (struct usb_card_rec *)adapter->card;
|
|
|
|
|
2018-06-01 10:41:20 +00:00
|
|
|
mwifiex_usb_free(card);
|
|
|
|
|
2017-05-23 07:12:33 +00:00
|
|
|
mwifiex_usb_cleanup_tx_aggr(adapter);
|
2017-05-23 07:12:32 +00:00
|
|
|
|
2013-11-15 03:10:42 +00:00
|
|
|
card->adapter = NULL;
|
2013-07-23 02:17:51 +00:00
|
|
|
}
|
|
|
|
|
2012-04-19 03:08:28 +00:00
|
|
|
static int mwifiex_prog_fw_w_helper(struct mwifiex_adapter *adapter,
|
|
|
|
struct mwifiex_fw_image *fw)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
u8 *firmware = fw->fw_buf, *recv_buff;
|
2016-04-19 14:23:44 +00:00
|
|
|
u32 retries = USB8XXX_FW_MAX_RETRY + 1;
|
|
|
|
u32 dlen;
|
2012-04-19 03:08:28 +00:00
|
|
|
u32 fw_seqnum = 0, tlen = 0, dnld_cmd = 0;
|
|
|
|
struct fw_data *fwdata;
|
|
|
|
struct fw_sync_header sync_fw;
|
|
|
|
u8 check_winner = 1;
|
|
|
|
|
|
|
|
if (!firmware) {
|
2015-05-11 19:18:20 +00:00
|
|
|
mwifiex_dbg(adapter, ERROR,
|
|
|
|
"No firmware image found! Terminating download\n");
|
2012-04-19 03:08:28 +00:00
|
|
|
ret = -1;
|
|
|
|
goto fw_exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Allocate memory for transmit */
|
|
|
|
fwdata = kzalloc(FW_DNLD_TX_BUF_SIZE, GFP_KERNEL);
|
2015-08-04 07:49:27 +00:00
|
|
|
if (!fwdata) {
|
|
|
|
ret = -ENOMEM;
|
2012-04-19 03:08:28 +00:00
|
|
|
goto fw_exit;
|
2015-08-04 07:49:27 +00:00
|
|
|
}
|
2012-04-19 03:08:28 +00:00
|
|
|
|
|
|
|
/* Allocate memory for receive */
|
|
|
|
recv_buff = kzalloc(FW_DNLD_RX_BUF_SIZE, GFP_KERNEL);
|
2016-04-19 14:21:58 +00:00
|
|
|
if (!recv_buff) {
|
|
|
|
ret = -ENOMEM;
|
2012-04-19 03:08:28 +00:00
|
|
|
goto cleanup;
|
2016-04-19 14:21:58 +00:00
|
|
|
}
|
2012-04-19 03:08:28 +00:00
|
|
|
|
|
|
|
do {
|
|
|
|
/* Send pseudo data to check winner status first */
|
|
|
|
if (check_winner) {
|
|
|
|
memset(&fwdata->fw_hdr, 0, sizeof(struct fw_header));
|
|
|
|
dlen = 0;
|
|
|
|
} else {
|
|
|
|
/* copy the header of the fw_data to get the length */
|
2013-01-03 00:23:01 +00:00
|
|
|
memcpy(&fwdata->fw_hdr, &firmware[tlen],
|
|
|
|
sizeof(struct fw_header));
|
2012-04-19 03:08:28 +00:00
|
|
|
|
|
|
|
dlen = le32_to_cpu(fwdata->fw_hdr.data_len);
|
|
|
|
dnld_cmd = le32_to_cpu(fwdata->fw_hdr.dnld_cmd);
|
|
|
|
tlen += sizeof(struct fw_header);
|
|
|
|
|
2016-09-12 13:25:27 +00:00
|
|
|
/* Command 7 doesn't have data length field */
|
|
|
|
if (dnld_cmd == FW_CMD_7)
|
|
|
|
dlen = 0;
|
|
|
|
|
2013-01-03 00:23:01 +00:00
|
|
|
memcpy(fwdata->data, &firmware[tlen], dlen);
|
2012-04-19 03:08:28 +00:00
|
|
|
|
|
|
|
fwdata->seq_num = cpu_to_le32(fw_seqnum);
|
|
|
|
tlen += dlen;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If the send/receive fails or CRC occurs then retry */
|
2016-04-19 14:23:44 +00:00
|
|
|
while (--retries) {
|
2012-04-19 03:08:28 +00:00
|
|
|
u8 *buf = (u8 *)fwdata;
|
|
|
|
u32 len = FW_DATA_XMIT_SIZE;
|
|
|
|
|
|
|
|
/* send the firmware block */
|
|
|
|
ret = mwifiex_write_data_sync(adapter, buf, &len,
|
|
|
|
MWIFIEX_USB_EP_CMD_EVENT,
|
|
|
|
MWIFIEX_USB_TIMEOUT);
|
|
|
|
if (ret) {
|
2015-05-11 19:18:20 +00:00
|
|
|
mwifiex_dbg(adapter, ERROR,
|
|
|
|
"write_data_sync: failed: %d\n",
|
|
|
|
ret);
|
2012-04-19 03:08:28 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
buf = recv_buff;
|
|
|
|
len = FW_DNLD_RX_BUF_SIZE;
|
|
|
|
|
|
|
|
/* Receive the firmware block response */
|
|
|
|
ret = mwifiex_read_data_sync(adapter, buf, &len,
|
|
|
|
MWIFIEX_USB_EP_CMD_EVENT,
|
|
|
|
MWIFIEX_USB_TIMEOUT);
|
|
|
|
if (ret) {
|
2015-05-11 19:18:20 +00:00
|
|
|
mwifiex_dbg(adapter, ERROR,
|
|
|
|
"read_data_sync: failed: %d\n",
|
|
|
|
ret);
|
2012-04-19 03:08:28 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(&sync_fw, recv_buff,
|
|
|
|
sizeof(struct fw_sync_header));
|
|
|
|
|
|
|
|
/* check 1st firmware block resp for highest bit set */
|
|
|
|
if (check_winner) {
|
|
|
|
if (le32_to_cpu(sync_fw.cmd) & 0x80000000) {
|
2015-05-11 19:18:20 +00:00
|
|
|
mwifiex_dbg(adapter, WARN,
|
|
|
|
"USB is not the winner %#x\n",
|
|
|
|
sync_fw.cmd);
|
2012-04-19 03:08:28 +00:00
|
|
|
|
|
|
|
/* returning success */
|
|
|
|
ret = 0;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2015-05-11 19:18:20 +00:00
|
|
|
mwifiex_dbg(adapter, MSG,
|
|
|
|
"start to download FW...\n");
|
2012-04-19 03:08:28 +00:00
|
|
|
|
|
|
|
check_winner = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check the firmware block response for CRC errors */
|
|
|
|
if (sync_fw.cmd) {
|
2015-05-11 19:18:20 +00:00
|
|
|
mwifiex_dbg(adapter, ERROR,
|
|
|
|
"FW received block with CRC %#x\n",
|
|
|
|
sync_fw.cmd);
|
2012-04-19 03:08:28 +00:00
|
|
|
ret = -1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-04-19 14:23:44 +00:00
|
|
|
retries = USB8XXX_FW_MAX_RETRY + 1;
|
2012-04-19 03:08:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
fw_seqnum++;
|
|
|
|
} while ((dnld_cmd != FW_HAS_LAST_BLOCK) && retries);
|
|
|
|
|
|
|
|
cleanup:
|
2015-05-11 19:18:20 +00:00
|
|
|
mwifiex_dbg(adapter, MSG,
|
|
|
|
"info: FW download over, size %d bytes\n", tlen);
|
2012-04-19 03:08:28 +00:00
|
|
|
|
|
|
|
kfree(recv_buff);
|
|
|
|
kfree(fwdata);
|
|
|
|
|
|
|
|
if (retries)
|
|
|
|
ret = 0;
|
|
|
|
fw_exit:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mwifiex_usb_dnld_fw(struct mwifiex_adapter *adapter,
|
|
|
|
struct mwifiex_fw_image *fw)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
struct usb_card_rec *card = (struct usb_card_rec *)adapter->card;
|
|
|
|
|
2014-01-10 03:36:55 +00:00
|
|
|
if (card->usb_boot_state == USB8XXX_FW_DNLD) {
|
2012-04-19 03:08:28 +00:00
|
|
|
ret = mwifiex_prog_fw_w_helper(adapter, fw);
|
|
|
|
if (ret)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* Boot state changes after successful firmware download */
|
2014-01-10 03:36:55 +00:00
|
|
|
if (card->usb_boot_state == USB8XXX_FW_DNLD)
|
2012-04-19 03:08:28 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = mwifiex_usb_rx_init(adapter);
|
|
|
|
if (!ret)
|
|
|
|
ret = mwifiex_usb_tx_init(adapter);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mwifiex_submit_rx_urb(struct mwifiex_adapter *adapter, u8 ep)
|
|
|
|
{
|
|
|
|
struct usb_card_rec *card = (struct usb_card_rec *)adapter->card;
|
|
|
|
|
|
|
|
skb_push(card->rx_cmd.skb, INTF_HEADER_LEN);
|
|
|
|
if ((ep == card->rx_cmd_ep) &&
|
|
|
|
(!atomic_read(&card->rx_cmd_urb_pending)))
|
|
|
|
mwifiex_usb_submit_rx_urb(&card->rx_cmd,
|
|
|
|
MWIFIEX_RX_CMD_BUF_SIZE);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mwifiex_usb_cmd_event_complete(struct mwifiex_adapter *adapter,
|
|
|
|
struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
mwifiex_submit_rx_urb(adapter, MWIFIEX_USB_EP_CMD_EVENT);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This function wakes up the card. */
|
|
|
|
static int mwifiex_pm_wakeup_card(struct mwifiex_adapter *adapter)
|
|
|
|
{
|
|
|
|
/* Simulation of HS_AWAKE event */
|
|
|
|
adapter->pm_wakeup_fw_try = false;
|
2015-03-12 07:38:40 +00:00
|
|
|
del_timer(&adapter->wakeup_timer);
|
2012-04-19 03:08:28 +00:00
|
|
|
adapter->pm_wakeup_card_req = false;
|
|
|
|
adapter->ps_state = PS_STATE_AWAKE;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-11-05 11:34:29 +00:00
|
|
|
static void mwifiex_usb_submit_rem_rx_urbs(struct mwifiex_adapter *adapter)
|
|
|
|
{
|
|
|
|
struct usb_card_rec *card = (struct usb_card_rec *)adapter->card;
|
|
|
|
int i;
|
|
|
|
struct urb_context *ctx;
|
|
|
|
|
|
|
|
for (i = 0; i < MWIFIEX_RX_DATA_URB; i++) {
|
|
|
|
if (card->rx_data_list[i].skb)
|
|
|
|
continue;
|
|
|
|
ctx = &card->rx_data_list[i];
|
|
|
|
mwifiex_usb_submit_rx_urb(ctx, MWIFIEX_RX_DATA_BUF_SIZE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-23 13:44:08 +00:00
|
|
|
/* This function is called after the card has woken up. */
|
|
|
|
static inline int
|
|
|
|
mwifiex_pm_wakeup_card_complete(struct mwifiex_adapter *adapter)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-04-19 03:08:28 +00:00
|
|
|
static struct mwifiex_if_ops usb_ops = {
|
|
|
|
.register_dev = mwifiex_register_dev,
|
2013-07-23 02:17:51 +00:00
|
|
|
.unregister_dev = mwifiex_unregister_dev,
|
2012-04-19 03:08:28 +00:00
|
|
|
.wakeup = mwifiex_pm_wakeup_card,
|
|
|
|
.wakeup_complete = mwifiex_pm_wakeup_card_complete,
|
|
|
|
|
|
|
|
/* USB specific */
|
|
|
|
.dnld_fw = mwifiex_usb_dnld_fw,
|
|
|
|
.cmdrsp_complete = mwifiex_usb_cmd_event_complete,
|
|
|
|
.event_complete = mwifiex_usb_cmd_event_complete,
|
|
|
|
.host_to_card = mwifiex_usb_host_to_card,
|
2014-11-05 11:34:29 +00:00
|
|
|
.submit_rem_rx_urbs = mwifiex_usb_submit_rem_rx_urbs,
|
2015-09-18 13:32:17 +00:00
|
|
|
.multi_port_resync = mwifiex_usb_port_resync,
|
2015-09-18 13:32:18 +00:00
|
|
|
.is_port_ready = mwifiex_usb_is_port_ready,
|
2012-04-19 03:08:28 +00:00
|
|
|
};
|
|
|
|
|
2016-12-01 13:08:20 +00:00
|
|
|
module_usb_driver(mwifiex_usb_driver);
|
2012-04-19 03:08:28 +00:00
|
|
|
|
|
|
|
MODULE_AUTHOR("Marvell International Ltd.");
|
|
|
|
MODULE_DESCRIPTION("Marvell WiFi-Ex USB Driver version" USB_VERSION);
|
|
|
|
MODULE_VERSION(USB_VERSION);
|
|
|
|
MODULE_LICENSE("GPL v2");
|
2014-11-20 15:52:58 +00:00
|
|
|
MODULE_FIRMWARE(USB8766_DEFAULT_FW_NAME);
|
2014-01-10 03:36:55 +00:00
|
|
|
MODULE_FIRMWARE(USB8797_DEFAULT_FW_NAME);
|
2015-01-23 11:39:18 +00:00
|
|
|
MODULE_FIRMWARE(USB8801_DEFAULT_FW_NAME);
|
2015-08-05 13:09:40 +00:00
|
|
|
MODULE_FIRMWARE(USB8997_DEFAULT_FW_NAME);
|