From patchwork Thu Jun 30 15:01:14 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amitkumar Karwar X-Patchwork-Id: 9208403 X-Patchwork-Delegate: kvalo@adurom.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 436206075A for ; Thu, 30 Jun 2016 15:05:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3220B2868D for ; Thu, 30 Jun 2016 15:05:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 255102868F; Thu, 30 Jun 2016 15:05:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6245A2868D for ; Thu, 30 Jun 2016 15:05:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932240AbcF3PEr (ORCPT ); Thu, 30 Jun 2016 11:04:47 -0400 Received: from mx0a-0016f401.pphosted.com ([67.231.148.174]:61622 "EHLO mx0a-0016f401.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932228AbcF3PEq (ORCPT ); Thu, 30 Jun 2016 11:04:46 -0400 Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.16.0.17/8.16.0.17) with SMTP id u5UF1uJO003104 for ; Thu, 30 Jun 2016 08:03:56 -0700 Received: from sc-exch04.marvell.com ([199.233.58.184]) by mx0a-0016f401.pphosted.com with ESMTP id 23sqakucgy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Thu, 30 Jun 2016 08:03:55 -0700 Received: from SC-EXCH03.marvell.com (10.93.176.83) by SC-EXCH04.marvell.com (10.93.176.84) with Microsoft SMTP Server (TLS) id 15.0.1104.5; Thu, 30 Jun 2016 08:03:54 -0700 Received: from maili.marvell.com (10.93.176.43) by SC-EXCH03.marvell.com (10.93.176.83) with Microsoft SMTP Server id 15.0.1104.5 via Frontend Transport; Thu, 30 Jun 2016 08:03:54 -0700 Received: from pe-lt949 (unknown [10.31.130.198]) by maili.marvell.com (Postfix) with ESMTP id 7AA7F3F703F; Thu, 30 Jun 2016 08:03:54 -0700 (PDT) Received: from pe-lt949 (localhost [127.0.0.1]) by pe-lt949 (8.14.4/8.14.4/Debian-4.1ubuntu1) with ESMTP id u5UF3mgt003620; Thu, 30 Jun 2016 20:33:48 +0530 Received: (from root@localhost) by pe-lt949 (8.14.4/8.14.4/Submit) id u5UF3lrQ003619; Thu, 30 Jun 2016 20:33:47 +0530 From: Amitkumar Karwar To: CC: Nishant Sarmukadam , Cathy Luo , Xinming Hu , Amitkumar Karwar Subject: [PATCH 1/2] mwifiex: add hostcmd wext ioctl support Date: Thu, 30 Jun 2016 20:31:14 +0530 Message-ID: <1467298875-3581-2-git-send-email-akarwar@marvell.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1467298875-3581-1-git-send-email-akarwar@marvell.com> References: <1467298875-3581-1-git-send-email-akarwar@marvell.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2016-06-30_06:, , signatures=0 X-Proofpoint-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=3 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1604210000 definitions=main-1606300143 Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Xinming Hu This patch adds ndo_ioctl support to mwifiex netdev handlers. This will be used to download hostcmds to firmware from userspace. This is needed for manufacturing mode support in mwifiex. ndo_ioctl is allowed only when mfg mode is enabled via module load parameters. Signed-off-by: Xinming Hu Signed-off-by: Amitkumar Karwar --- drivers/net/wireless/marvell/mwifiex/cmdevt.c | 59 +++++++++++++++++++++++++++ drivers/net/wireless/marvell/mwifiex/main.c | 38 +++++++++++++++++ drivers/net/wireless/marvell/mwifiex/main.h | 9 +++- 3 files changed, 105 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/marvell/mwifiex/cmdevt.c b/drivers/net/wireless/marvell/mwifiex/cmdevt.c index c29f26d..fcfe556 100644 --- a/drivers/net/wireless/marvell/mwifiex/cmdevt.c +++ b/drivers/net/wireless/marvell/mwifiex/cmdevt.c @@ -818,6 +818,8 @@ int mwifiex_process_cmdresp(struct mwifiex_adapter *adapter) hostcmd = adapter->curr_cmd->data_buf; hostcmd->len = size; memcpy(hostcmd->cmd, resp, size); + adapter->hostcmd_resp_data.len = size; + memcpy(adapter->hostcmd_resp_data.cmd, resp, size); } } orig_cmdresp_no = le16_to_cpu(resp->command); @@ -1200,6 +1202,63 @@ mwifiex_process_hs_config(struct mwifiex_adapter *adapter) false); } EXPORT_SYMBOL_GPL(mwifiex_process_hs_config); +/* This function get hostcmd data from userspace and construct a cmd + * to be download to FW. + */ +int mwifiex_process_host_command(struct mwifiex_private *priv, + struct iwreq *wrq) +{ + struct mwifiex_ds_misc_cmd *hostcmd_buf; + struct host_cmd_ds_command *cmd; + struct mwifiex_adapter *adapter = priv->adapter; + int ret; + + hostcmd_buf = kzalloc(sizeof(*hostcmd_buf), GFP_KERNEL); + if (!hostcmd_buf) + return -ENOMEM; + + cmd = (void *)hostcmd_buf->cmd; + + if (copy_from_user(cmd, wrq->u.data.pointer, + sizeof(cmd->command) + sizeof(cmd->size))) { + ret = -EFAULT; + goto done; + } + + hostcmd_buf->len = le16_to_cpu(cmd->size); + if (hostcmd_buf->len > MWIFIEX_SIZE_OF_CMD_BUFFER) { + ret = -EINVAL; + goto done; + } + + if (copy_from_user(cmd, wrq->u.data.pointer, hostcmd_buf->len)) { + ret = -EFAULT; + goto done; + } + + if (mwifiex_send_cmd(priv, 0, 0, 0, hostcmd_buf, true)) { + dev_err(priv->adapter->dev, "Failed to process hostcmd\n"); + ret = -EFAULT; + goto done; + } + + if (adapter->hostcmd_resp_data.len > hostcmd_buf->len) { + ret = -EFBIG; + goto done; + } + + if (copy_to_user(wrq->u.data.pointer, adapter->hostcmd_resp_data.cmd, + adapter->hostcmd_resp_data.len)) { + ret = -EFAULT; + goto done; + } + wrq->u.data.length = adapter->hostcmd_resp_data.len; + + ret = 0; +done: + kfree(hostcmd_buf); + return ret; +} /* * This function handles the command response of a sleep confirm command. diff --git a/drivers/net/wireless/marvell/mwifiex/main.c b/drivers/net/wireless/marvell/mwifiex/main.c index 0e280f8..8b06d1d 100644 --- a/drivers/net/wireless/marvell/mwifiex/main.c +++ b/drivers/net/wireless/marvell/mwifiex/main.c @@ -1211,17 +1211,54 @@ mwifiex_netdev_select_wmm_queue(struct net_device *dev, struct sk_buff *skb, return mwifiex_1d_to_wmm_queue[skb->priority]; } +static int mwifiex_do_ioctl(struct net_device *dev, struct ifreq *req, int cmd) +{ + struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev); + struct iwreq *wrq = (struct iwreq *)req; + int ret; + + if (!priv->adapter->mfg_mode) + return -EINVAL; + + dev_dbg(priv->adapter->dev, "ioctl cmd = 0x%x\n", cmd); + + switch (cmd) { + case MWIFIEX_HOSTCMD_IOCTL: + ret = mwifiex_process_host_command(priv, wrq); + break; + default: + ret = -EINVAL; + break; + } + + return ret; +} + /* Network device handlers */ static const struct net_device_ops mwifiex_netdev_ops = { .ndo_open = mwifiex_open, .ndo_stop = mwifiex_close, .ndo_start_xmit = mwifiex_hard_start_xmit, .ndo_set_mac_address = mwifiex_set_mac_address, + .ndo_do_ioctl = mwifiex_do_ioctl, .ndo_validate_addr = eth_validate_addr, .ndo_tx_timeout = mwifiex_tx_timeout, .ndo_get_stats = mwifiex_get_stats, .ndo_set_rx_mode = mwifiex_set_multicast_list, .ndo_select_queue = mwifiex_netdev_select_wmm_queue, + }; + +static const struct iw_priv_args mwifiex_iwpriv_args[] = { + { MWIFIEX_HOSTCMD_IOCTL, + IW_PRIV_TYPE_BYTE | 2047, + IW_PRIV_TYPE_BYTE | 2047, + "hostcmd" + }, +}; + +static struct iw_handler_def mwifiex_iwpriv_handler_def = { + .num_private_args = ARRAY_SIZE(mwifiex_iwpriv_args), + .private_args = (struct iw_priv_args *)mwifiex_iwpriv_args, }; /* @@ -1249,6 +1286,7 @@ void mwifiex_init_priv_params(struct mwifiex_private *priv, { dev->netdev_ops = &mwifiex_netdev_ops; dev->destructor = free_netdev; + dev->wireless_handlers = &mwifiex_iwpriv_handler_def; /* Initialize private structure */ priv->current_key_index = 0; priv->media_connected = false; diff --git a/drivers/net/wireless/marvell/mwifiex/main.h b/drivers/net/wireless/marvell/mwifiex/main.h index 9f6bb40..23532cf 100644 --- a/drivers/net/wireless/marvell/mwifiex/main.h +++ b/drivers/net/wireless/marvell/mwifiex/main.h @@ -48,6 +48,8 @@ #include #include #include +#include +#include #include "decl.h" #include "ioctl.h" @@ -157,6 +159,9 @@ enum { /* Threshold for tx_timeout_cnt before we trigger a card reset */ #define TX_TIMEOUT_THRESHOLD 6 +/* IOCTL number used for hostcmd process*/ +#define MWIFIEX_HOSTCMD_IOCTL (SIOCIWFIRSTPRIV + 17) + #define MWIFIEX_DRV_INFO_SIZE_MAX 0x40000 /* Address alignment */ @@ -892,6 +897,7 @@ struct mwifiex_adapter { u8 event_received; u8 data_received; u16 seq_num; + struct mwifiex_ds_misc_cmd hostcmd_resp_data; struct cmd_ctrl_node *cmd_pool; struct cmd_ctrl_node *curr_cmd; /* spin lock for command */ @@ -1553,7 +1559,8 @@ bool mwifiex_is_bss_in_11ac_mode(struct mwifiex_private *priv); u8 mwifiex_get_center_freq_index(struct mwifiex_private *priv, u8 band, u32 pri_chan, u8 chan_bw); int mwifiex_init_channel_scan_gap(struct mwifiex_adapter *adapter); - +int mwifiex_process_host_command(struct mwifiex_private *priv, + struct iwreq *wrq); int mwifiex_tdls_check_tx(struct mwifiex_private *priv, struct sk_buff *skb); void mwifiex_flush_auto_tdls_list(struct mwifiex_private *priv); void mwifiex_auto_tdls_update_peer_status(struct mwifiex_private *priv,