From patchwork Tue Feb 12 12:05:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hong Liu X-Patchwork-Id: 10807803 X-Patchwork-Delegate: jikos@jikos.cz Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DAB38922 for ; Tue, 12 Feb 2019 12:04:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C9B732B41C for ; Tue, 12 Feb 2019 12:04:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BD86F2B500; Tue, 12 Feb 2019 12:04:07 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 4A1D52B41C for ; Tue, 12 Feb 2019 12:04:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729189AbfBLMEG (ORCPT ); Tue, 12 Feb 2019 07:04:06 -0500 Received: from mga05.intel.com ([192.55.52.43]:24440 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726026AbfBLMEG (ORCPT ); Tue, 12 Feb 2019 07:04:06 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 Feb 2019 04:04:05 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.58,361,1544515200"; d="scan'208";a="125828925" Received: from honglinux.sh.intel.com ([10.239.153.39]) by orsmga003.jf.intel.com with ESMTP; 12 Feb 2019 04:04:03 -0800 From: Hong Liu To: Srinivas Pandruvada , Jiri Kosina , Benjamin Tissoires Cc: linux-input@vger.kernel.org, Hongyan Song , Even Xu , Hong Liu Subject: [PATCH 1/4] HID: intel-ish-hid: avoid binding wrong ishtp_cl_device Date: Tue, 12 Feb 2019 20:05:20 +0800 Message-Id: <20190212120523.27463-1-hong.liu@intel.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When performing a warm reset in ishtp bus driver, the ishtp_cl_device will not be removed, its fw_client still points to the already freed ishtp_device.fw_clients array. Later after driver finishing ishtp client enumeration, this dangling pointer may cause driver to bind the wrong ishtp_cl_device to the new client, causing wrong callback to be called for messages intended for the new client. This helps in development of firmware where frequent switching of firmwares is required without Linux reboot. Signed-off-by: Hong Liu Tested-by: Hongyan Song Acked-by: Srinivas Pandruvada --- drivers/hid/intel-ish-hid/ishtp/bus.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/hid/intel-ish-hid/ishtp/bus.c b/drivers/hid/intel-ish-hid/ishtp/bus.c index 728dc6d4561a..a271d6d169b1 100644 --- a/drivers/hid/intel-ish-hid/ishtp/bus.c +++ b/drivers/hid/intel-ish-hid/ishtp/bus.c @@ -675,7 +675,8 @@ int ishtp_cl_device_bind(struct ishtp_cl *cl) spin_lock_irqsave(&cl->dev->device_list_lock, flags); list_for_each_entry(cl_device, &cl->dev->device_list, device_link) { - if (cl_device->fw_client->client_id == cl->fw_client_id) { + if (cl_device->fw_client && + cl_device->fw_client->client_id == cl->fw_client_id) { cl->device = cl_device; rv = 0; break; @@ -735,6 +736,7 @@ void ishtp_bus_remove_all_clients(struct ishtp_device *ishtp_dev, spin_lock_irqsave(&ishtp_dev->device_list_lock, flags); list_for_each_entry_safe(cl_device, n, &ishtp_dev->device_list, device_link) { + cl_device->fw_client = NULL; if (warm_reset && cl_device->reference_count) continue; From patchwork Tue Feb 12 12:05:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hong Liu X-Patchwork-Id: 10807805 X-Patchwork-Delegate: jikos@jikos.cz Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 419E813BF for ; Tue, 12 Feb 2019 12:04:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 31CDC2B41C for ; Tue, 12 Feb 2019 12:04:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 25FDB2B42D; Tue, 12 Feb 2019 12:04:08 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 B549A2B432 for ; Tue, 12 Feb 2019 12:04:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729190AbfBLMEH (ORCPT ); Tue, 12 Feb 2019 07:04:07 -0500 Received: from mga05.intel.com ([192.55.52.43]:24440 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726026AbfBLMEH (ORCPT ); Tue, 12 Feb 2019 07:04:07 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 Feb 2019 04:04:06 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.58,361,1544515200"; d="scan'208";a="125828931" Received: from honglinux.sh.intel.com ([10.239.153.39]) by orsmga003.jf.intel.com with ESMTP; 12 Feb 2019 04:04:05 -0800 From: Hong Liu To: Srinivas Pandruvada , Jiri Kosina , Benjamin Tissoires Cc: linux-input@vger.kernel.org, Hongyan Song , Even Xu , Hong Liu Subject: [PATCH 2/4] HID: intel-ish-hid: Optimize writing ipc message from queue Date: Tue, 12 Feb 2019 20:05:21 +0800 Message-Id: <20190212120523.27463-2-hong.liu@intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190212120523.27463-1-hong.liu@intel.com> References: <20190212120523.27463-1-hong.liu@intel.com> MIME-Version: 1.0 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Currently we are using one additional static variable and a spinlock to prevent contention of writing IPC messages to ISH hardware, which is not necessary. Once ISH is ready to accept new data, we can push new data to hardware. This pushing of new data is already protected by wr_processing_spinlock for contention, which is enough. So use this spinlock to check both readiness for accepting new data and once ready allow writing of ipc message from queue to ISH hardware. While here, cleaned up some space after return. Signed-off-by: Hong Liu Tested-by: Hongyan Song Acked-by: Srinivas Pandruvada --- drivers/hid/intel-ish-hid/ipc/ipc.c | 19 +++---------------- drivers/hid/intel-ish-hid/ishtp/ishtp-dev.h | 2 -- 2 files changed, 3 insertions(+), 18 deletions(-) diff --git a/drivers/hid/intel-ish-hid/ipc/ipc.c b/drivers/hid/intel-ish-hid/ipc/ipc.c index 742191bb24c6..ff8eca11ff73 100644 --- a/drivers/hid/intel-ish-hid/ipc/ipc.c +++ b/drivers/hid/intel-ish-hid/ipc/ipc.c @@ -256,33 +256,22 @@ static int write_ipc_from_queue(struct ishtp_device *dev) int i; void (*ipc_send_compl)(void *); void *ipc_send_compl_prm; - static int out_ipc_locked; - unsigned long out_ipc_flags; if (dev->dev_state == ISHTP_DEV_DISABLED) - return -EINVAL; + return -EINVAL; - spin_lock_irqsave(&dev->out_ipc_spinlock, out_ipc_flags); - if (out_ipc_locked) { - spin_unlock_irqrestore(&dev->out_ipc_spinlock, out_ipc_flags); - return -EBUSY; - } - out_ipc_locked = 1; + spin_lock_irqsave(&dev->wr_processing_spinlock, flags); if (!ish_is_input_ready(dev)) { - out_ipc_locked = 0; - spin_unlock_irqrestore(&dev->out_ipc_spinlock, out_ipc_flags); + spin_unlock_irqrestore(&dev->wr_processing_spinlock, flags); return -EBUSY; } - spin_unlock_irqrestore(&dev->out_ipc_spinlock, out_ipc_flags); - spin_lock_irqsave(&dev->wr_processing_spinlock, flags); /* * if tx send list is empty - return 0; * may happen, as RX_COMPLETE handler doesn't check list emptiness. */ if (list_empty(&dev->wr_processing_list)) { spin_unlock_irqrestore(&dev->wr_processing_spinlock, flags); - out_ipc_locked = 0; return 0; } @@ -333,7 +322,6 @@ static int write_ipc_from_queue(struct ishtp_device *dev) dev->ipc_tx_bytes_cnt += IPC_HEADER_GET_LENGTH(doorbell_val); ish_reg_write(dev, IPC_REG_HOST2ISH_DRBL, doorbell_val); - out_ipc_locked = 0; ipc_send_compl = ipc_link->ipc_send_compl; ipc_send_compl_prm = ipc_link->ipc_send_compl_prm; @@ -914,7 +902,6 @@ struct ishtp_device *ish_dev_init(struct pci_dev *pdev) init_waitqueue_head(&dev->wait_hw_ready); spin_lock_init(&dev->wr_processing_spinlock); - spin_lock_init(&dev->out_ipc_spinlock); /* Init IPC processing and free lists */ INIT_LIST_HEAD(&dev->wr_processing_list); diff --git a/drivers/hid/intel-ish-hid/ishtp/ishtp-dev.h b/drivers/hid/intel-ish-hid/ishtp/ishtp-dev.h index e7c6bfefaf9e..e54ce1ef27dd 100644 --- a/drivers/hid/intel-ish-hid/ishtp/ishtp-dev.h +++ b/drivers/hid/intel-ish-hid/ishtp/ishtp-dev.h @@ -211,8 +211,6 @@ struct ishtp_device { /* For both processing list and free list */ spinlock_t wr_processing_spinlock; - spinlock_t out_ipc_spinlock; - struct ishtp_fw_client *fw_clients; /*Note:memory has to be allocated*/ DECLARE_BITMAP(fw_clients_map, ISHTP_CLIENTS_MAX); DECLARE_BITMAP(host_clients_map, ISHTP_CLIENTS_MAX); From patchwork Tue Feb 12 12:05:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hong Liu X-Patchwork-Id: 10807807 X-Patchwork-Delegate: jikos@jikos.cz Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9678B13BF for ; Tue, 12 Feb 2019 12:04:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 856072B42D for ; Tue, 12 Feb 2019 12:04:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7977A2B500; Tue, 12 Feb 2019 12:04:09 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 2503D2B42D for ; Tue, 12 Feb 2019 12:04:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729192AbfBLMEI (ORCPT ); Tue, 12 Feb 2019 07:04:08 -0500 Received: from mga05.intel.com ([192.55.52.43]:24440 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726026AbfBLMEI (ORCPT ); Tue, 12 Feb 2019 07:04:08 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 Feb 2019 04:04:08 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.58,361,1544515200"; d="scan'208";a="125828938" Received: from honglinux.sh.intel.com ([10.239.153.39]) by orsmga003.jf.intel.com with ESMTP; 12 Feb 2019 04:04:06 -0800 From: Hong Liu To: Srinivas Pandruvada , Jiri Kosina , Benjamin Tissoires Cc: linux-input@vger.kernel.org, Hongyan Song , Even Xu , Hong Liu Subject: [PATCH 3/4] HID: intel-ish-hid: move doorbell writing before flush Date: Tue, 12 Feb 2019 20:05:22 +0800 Message-Id: <20190212120523.27463-3-hong.liu@intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190212120523.27463-1-hong.liu@intel.com> References: <20190212120523.27463-1-hong.liu@intel.com> MIME-Version: 1.0 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Reading of IPC_REG_ISH_HOST_FWSTS will flush both message register and doorbell. So move the doorbell write before reading of IPC_REG_ISH_HOST_FWSTS. Signed-off-by: Hong Liu Tested-by: Hongyan Song Acked-by: Srinivas Pandruvada --- drivers/hid/intel-ish-hid/ipc/ipc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/hid/intel-ish-hid/ipc/ipc.c b/drivers/hid/intel-ish-hid/ipc/ipc.c index ff8eca11ff73..30d8a639a5bb 100644 --- a/drivers/hid/intel-ish-hid/ipc/ipc.c +++ b/drivers/hid/intel-ish-hid/ipc/ipc.c @@ -314,6 +314,8 @@ static int write_ipc_from_queue(struct ishtp_device *dev) memcpy(®, &r_buf[length >> 2], rem); ish_reg_write(dev, reg_addr, reg); } + ish_reg_write(dev, IPC_REG_HOST2ISH_DRBL, doorbell_val); + /* Flush writes to msg registers and doorbell */ ish_reg_read(dev, IPC_REG_ISH_HOST_FWSTS); @@ -321,8 +323,6 @@ static int write_ipc_from_queue(struct ishtp_device *dev) ++dev->ipc_tx_cnt; dev->ipc_tx_bytes_cnt += IPC_HEADER_GET_LENGTH(doorbell_val); - ish_reg_write(dev, IPC_REG_HOST2ISH_DRBL, doorbell_val); - ipc_send_compl = ipc_link->ipc_send_compl; ipc_send_compl_prm = ipc_link->ipc_send_compl_prm; list_del_init(&ipc_link->link); From patchwork Tue Feb 12 12:05:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hong Liu X-Patchwork-Id: 10807809 X-Patchwork-Delegate: jikos@jikos.cz Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 90E8413BF for ; Tue, 12 Feb 2019 12:04:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 802F42B42D for ; Tue, 12 Feb 2019 12:04:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 740C92B500; Tue, 12 Feb 2019 12:04:11 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 C4CAB2B42D for ; Tue, 12 Feb 2019 12:04:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729194AbfBLMEK (ORCPT ); Tue, 12 Feb 2019 07:04:10 -0500 Received: from mga05.intel.com ([192.55.52.43]:24440 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726026AbfBLMEK (ORCPT ); Tue, 12 Feb 2019 07:04:10 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 Feb 2019 04:04:09 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.58,361,1544515200"; d="scan'208";a="125828943" Received: from honglinux.sh.intel.com ([10.239.153.39]) by orsmga003.jf.intel.com with ESMTP; 12 Feb 2019 04:04:08 -0800 From: Hong Liu To: Srinivas Pandruvada , Jiri Kosina , Benjamin Tissoires Cc: linux-input@vger.kernel.org, Hongyan Song , Even Xu , Hong Liu Subject: [PATCH 4/4] HID: intel-ish-hid: remove data[128] usage on stack when sending HBM request Date: Tue, 12 Feb 2019 20:05:23 +0800 Message-Id: <20190212120523.27463-4-hong.liu@intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190212120523.27463-1-hong.liu@intel.com> References: <20190212120523.27463-1-hong.liu@intel.com> MIME-Version: 1.0 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Instead of using an 128-byte on-stack array to store the request, we can instantiate the request on stack directly. This can save the stack usage of these functions, since most of the requests are much smaller than 128 bytes. Signed-off-by: Hong Liu Tested-by: Hongyan Song Acked-by: Srinivas Pandruvada --- drivers/hid/intel-ish-hid/ishtp/bus.c | 2 +- drivers/hid/intel-ish-hid/ishtp/bus.h | 2 +- drivers/hid/intel-ish-hid/ishtp/hbm.c | 97 ++++++++++----------------- 3 files changed, 38 insertions(+), 63 deletions(-) diff --git a/drivers/hid/intel-ish-hid/ishtp/bus.c b/drivers/hid/intel-ish-hid/ishtp/bus.c index a271d6d169b1..f358a02325da 100644 --- a/drivers/hid/intel-ish-hid/ishtp/bus.c +++ b/drivers/hid/intel-ish-hid/ishtp/bus.c @@ -119,7 +119,7 @@ int ishtp_send_msg(struct ishtp_device *dev, struct ishtp_msg_hdr *hdr, * Return: This returns IPC send message status. */ int ishtp_write_message(struct ishtp_device *dev, struct ishtp_msg_hdr *hdr, - unsigned char *buf) + void *buf) { return ishtp_send_msg(dev, hdr, buf, NULL, NULL); } diff --git a/drivers/hid/intel-ish-hid/ishtp/bus.h b/drivers/hid/intel-ish-hid/ishtp/bus.h index b8a5bcc82536..5c4763d73f8b 100644 --- a/drivers/hid/intel-ish-hid/ishtp/bus.h +++ b/drivers/hid/intel-ish-hid/ishtp/bus.h @@ -85,7 +85,7 @@ int ishtp_send_msg(struct ishtp_device *dev, /* Write a single-fragment message */ int ishtp_write_message(struct ishtp_device *dev, struct ishtp_msg_hdr *hdr, - unsigned char *buf); + void *buf); /* Use DMA to send/receive messages */ int ishtp_use_dma_transfer(void); diff --git a/drivers/hid/intel-ish-hid/ishtp/hbm.c b/drivers/hid/intel-ish-hid/ishtp/hbm.c index 8b5dd580ceec..d0b847c86935 100644 --- a/drivers/hid/intel-ish-hid/ishtp/hbm.c +++ b/drivers/hid/intel-ish-hid/ishtp/hbm.c @@ -136,19 +136,14 @@ int ishtp_hbm_start_wait(struct ishtp_device *dev) int ishtp_hbm_start_req(struct ishtp_device *dev) { struct ishtp_msg_hdr hdr; - unsigned char data[128]; - struct ishtp_msg_hdr *ishtp_hdr = &hdr; - struct hbm_host_version_request *start_req; - const size_t len = sizeof(struct hbm_host_version_request); + struct hbm_host_version_request start_req = { 0 }; - ishtp_hbm_hdr(ishtp_hdr, len); + ishtp_hbm_hdr(&hdr, sizeof(start_req)); /* host start message */ - start_req = (struct hbm_host_version_request *)data; - memset(start_req, 0, len); - start_req->hbm_cmd = HOST_START_REQ_CMD; - start_req->host_version.major_version = HBM_MAJOR_VERSION; - start_req->host_version.minor_version = HBM_MINOR_VERSION; + start_req.hbm_cmd = HOST_START_REQ_CMD; + start_req.host_version.major_version = HBM_MAJOR_VERSION; + start_req.host_version.minor_version = HBM_MINOR_VERSION; /* * (!) Response to HBM start may be so quick that this thread would get @@ -156,7 +151,7 @@ int ishtp_hbm_start_req(struct ishtp_device *dev) * So set it at first, change back to ISHTP_HBM_IDLE upon failure */ dev->hbm_state = ISHTP_HBM_START; - if (ishtp_write_message(dev, ishtp_hdr, data)) { + if (ishtp_write_message(dev, &hdr, &start_req)) { dev_err(dev->devc, "version message send failed\n"); dev->dev_state = ISHTP_DEV_RESETTING; dev->hbm_state = ISHTP_HBM_IDLE; @@ -178,19 +173,13 @@ int ishtp_hbm_start_req(struct ishtp_device *dev) void ishtp_hbm_enum_clients_req(struct ishtp_device *dev) { struct ishtp_msg_hdr hdr; - unsigned char data[128]; - struct ishtp_msg_hdr *ishtp_hdr = &hdr; - struct hbm_host_enum_request *enum_req; - const size_t len = sizeof(struct hbm_host_enum_request); + struct hbm_host_enum_request enum_req = { 0 }; /* enumerate clients */ - ishtp_hbm_hdr(ishtp_hdr, len); + ishtp_hbm_hdr(&hdr, sizeof(enum_req)); + enum_req.hbm_cmd = HOST_ENUM_REQ_CMD; - enum_req = (struct hbm_host_enum_request *)data; - memset(enum_req, 0, len); - enum_req->hbm_cmd = HOST_ENUM_REQ_CMD; - - if (ishtp_write_message(dev, ishtp_hdr, data)) { + if (ishtp_write_message(dev, &hdr, &enum_req)) { dev->dev_state = ISHTP_DEV_RESETTING; dev_err(dev->devc, "enumeration request send failed\n"); ish_hw_reset(dev); @@ -208,12 +197,8 @@ void ishtp_hbm_enum_clients_req(struct ishtp_device *dev) */ static int ishtp_hbm_prop_req(struct ishtp_device *dev) { - struct ishtp_msg_hdr hdr; - unsigned char data[128]; - struct ishtp_msg_hdr *ishtp_hdr = &hdr; - struct hbm_props_request *prop_req; - const size_t len = sizeof(struct hbm_props_request); + struct hbm_props_request prop_req = { 0 }; unsigned long next_client_index; uint8_t client_num; @@ -237,15 +222,12 @@ static int ishtp_hbm_prop_req(struct ishtp_device *dev) dev->fw_clients[client_num].client_id = next_client_index; - ishtp_hbm_hdr(ishtp_hdr, len); - prop_req = (struct hbm_props_request *)data; + ishtp_hbm_hdr(&hdr, sizeof(prop_req)); - memset(prop_req, 0, sizeof(struct hbm_props_request)); + prop_req.hbm_cmd = HOST_CLIENT_PROPERTIES_REQ_CMD; + prop_req.address = next_client_index; - prop_req->hbm_cmd = HOST_CLIENT_PROPERTIES_REQ_CMD; - prop_req->address = next_client_index; - - if (ishtp_write_message(dev, ishtp_hdr, data)) { + if (ishtp_write_message(dev, &hdr, &prop_req)) { dev->dev_state = ISHTP_DEV_RESETTING; dev_err(dev->devc, "properties request send failed\n"); ish_hw_reset(dev); @@ -266,19 +248,14 @@ static int ishtp_hbm_prop_req(struct ishtp_device *dev) static void ishtp_hbm_stop_req(struct ishtp_device *dev) { struct ishtp_msg_hdr hdr; - unsigned char data[128]; - struct ishtp_msg_hdr *ishtp_hdr = &hdr; - struct hbm_host_stop_request *req; - const size_t len = sizeof(struct hbm_host_stop_request); + struct hbm_host_stop_request stop_req = { 0 } ; - ishtp_hbm_hdr(ishtp_hdr, len); - req = (struct hbm_host_stop_request *)data; + ishtp_hbm_hdr(&hdr, sizeof(stop_req)); - memset(req, 0, sizeof(struct hbm_host_stop_request)); - req->hbm_cmd = HOST_STOP_REQ_CMD; - req->reason = DRIVER_STOP_REQUEST; + stop_req.hbm_cmd = HOST_STOP_REQ_CMD; + stop_req.reason = DRIVER_STOP_REQUEST; - ishtp_write_message(dev, ishtp_hdr, data); + ishtp_write_message(dev, &hdr, &stop_req); } /** @@ -294,15 +271,15 @@ int ishtp_hbm_cl_flow_control_req(struct ishtp_device *dev, struct ishtp_cl *cl) { struct ishtp_msg_hdr hdr; - unsigned char data[128]; - struct ishtp_msg_hdr *ishtp_hdr = &hdr; - const size_t len = sizeof(struct hbm_flow_control); + struct hbm_flow_control flow_ctrl; + const size_t len = sizeof(flow_ctrl); int rv; unsigned long flags; spin_lock_irqsave(&cl->fc_spinlock, flags); - ishtp_hbm_hdr(ishtp_hdr, len); - ishtp_hbm_cl_hdr(cl, ISHTP_FLOW_CONTROL_CMD, data, len); + + ishtp_hbm_hdr(&hdr, len); + ishtp_hbm_cl_hdr(cl, ISHTP_FLOW_CONTROL_CMD, &flow_ctrl, len); /* * Sync possible race when RB recycle and packet receive paths @@ -315,7 +292,7 @@ int ishtp_hbm_cl_flow_control_req(struct ishtp_device *dev, cl->recv_msg_num_frags = 0; - rv = ishtp_write_message(dev, ishtp_hdr, data); + rv = ishtp_write_message(dev, &hdr, &flow_ctrl); if (!rv) { ++cl->out_flow_ctrl_creds; ++cl->out_flow_ctrl_cnt; @@ -345,14 +322,13 @@ int ishtp_hbm_cl_flow_control_req(struct ishtp_device *dev, int ishtp_hbm_cl_disconnect_req(struct ishtp_device *dev, struct ishtp_cl *cl) { struct ishtp_msg_hdr hdr; - unsigned char data[128]; - struct ishtp_msg_hdr *ishtp_hdr = &hdr; - const size_t len = sizeof(struct hbm_client_connect_request); + struct hbm_client_connect_request disconn_req; + const size_t len = sizeof(disconn_req); - ishtp_hbm_hdr(ishtp_hdr, len); - ishtp_hbm_cl_hdr(cl, CLIENT_DISCONNECT_REQ_CMD, data, len); + ishtp_hbm_hdr(&hdr, len); + ishtp_hbm_cl_hdr(cl, CLIENT_DISCONNECT_REQ_CMD, &disconn_req, len); - return ishtp_write_message(dev, ishtp_hdr, data); + return ishtp_write_message(dev, &hdr, &disconn_req); } /** @@ -391,14 +367,13 @@ static void ishtp_hbm_cl_disconnect_res(struct ishtp_device *dev, int ishtp_hbm_cl_connect_req(struct ishtp_device *dev, struct ishtp_cl *cl) { struct ishtp_msg_hdr hdr; - unsigned char data[128]; - struct ishtp_msg_hdr *ishtp_hdr = &hdr; - const size_t len = sizeof(struct hbm_client_connect_request); + struct hbm_client_connect_request conn_req; + const size_t len = sizeof(conn_req); - ishtp_hbm_hdr(ishtp_hdr, len); - ishtp_hbm_cl_hdr(cl, CLIENT_CONNECT_REQ_CMD, data, len); + ishtp_hbm_hdr(&hdr, len); + ishtp_hbm_cl_hdr(cl, CLIENT_CONNECT_REQ_CMD, &conn_req, len); - return ishtp_write_message(dev, ishtp_hdr, data); + return ishtp_write_message(dev, &hdr, &conn_req); } /**