From patchwork Tue Mar 24 06:10:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manivannan Sadhasivam X-Patchwork-Id: 11454533 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7CCA613A4 for ; Tue, 24 Mar 2020 06:11:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5C8382073E for ; Tue, 24 Mar 2020 06:11:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="Y8lXHlji" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727366AbgCXGLK (ORCPT ); Tue, 24 Mar 2020 02:11:10 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:39942 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725922AbgCXGLJ (ORCPT ); Tue, 24 Mar 2020 02:11:09 -0400 Received: by mail-pf1-f196.google.com with SMTP id l184so8771907pfl.7 for ; Mon, 23 Mar 2020 23:11:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=CWXhPTqqgepnsjPzgYIPAI8S04yC8VZS0reJOBbfgeg=; b=Y8lXHljihHsfPKuEdYKtmDrsZdDaz9wsEapDt3e8zKF0S/5gLZIU10e9EcZloh+sNp LvVOZo0gn6ylWSiKDmLVrZUt5xbegyhi6GzOFavzrKgFG6q7cYM8NxMcGsewfIaewakw Ygx+OM6hrFIjFItSy+mz0MuGHIcSyu1cu4RyoV2SvN5P0lqpnN//OdN5p787PlNgDOLR hzjlncNMhx3QSPE3iwlcvzpBfyOhRRxR+cmn6yqCrHIzy05eYUyleCx6mK3EkeMKhwc0 9OOtXf5iDDDC5HlXweWRnIZjE76AFCCDgKq/XKiBW8AUaiHZw4Z45QY7Fc86b+4bXFag QJog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=CWXhPTqqgepnsjPzgYIPAI8S04yC8VZS0reJOBbfgeg=; b=OAb7Bh9cgWMGYQ/ZGxJUIaPpydDKioTjz6m9FWbZgvEO9c5JqWScwA+B13fVOVpxFr nX6tQzEmGrHZt+8SiIOo4uqT6dxpVOgUjxHbEdERyjeGNHt04fioz8BjDTiEPgQSLzF8 RLOpxU0h55F/DTdls9HosFPytHRXERXy1BdhJ9BEPfVD9U2wrHoH3QBqI/QJTdAIp4Sw kbdp35lcT7jcMAVNitu4ZoSCB5GnLw22fAr8DT12C7KCnjc3lnQ+jaEx4Bv14OZ1zl/B JOl8txNL7dwv+fM5+UZ5602BvkOzi0esr0RgGSD6jw3zmQ6ht4rYlyxs2dsJPJNyJ7xq wzgg== X-Gm-Message-State: ANhLgQ3sgtK5QnppYlKqfM225Ehw7NvQJ9hLj8cBVrBuuhn7bFLo1mtz E19P7UrBasPtXCxmppYbmxi3 X-Google-Smtp-Source: ADFU+vtstP2kvPuqcNqNKvrS1i71Dq5mSEmTtY4nnQSokaKvEMztcUtG8h+nY48r6P5HSPyjEHmDMA== X-Received: by 2002:a63:f258:: with SMTP id d24mr26529837pgk.307.1585030266451; Mon, 23 Mar 2020 23:11:06 -0700 (PDT) Received: from localhost.localdomain ([2409:4072:59b:91e:2dd6:dffe:3569:b473]) by smtp.gmail.com with ESMTPSA id d3sm1198230pjc.42.2020.03.23.23.11.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Mar 2020 23:11:05 -0700 (PDT) From: Manivannan Sadhasivam To: gregkh@linuxfoundation.org, davem@davemloft.net Cc: smohanad@codeaurora.org, jhugo@codeaurora.org, kvalo@codeaurora.org, bjorn.andersson@linaro.org, hemantk@codeaurora.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, Manivannan Sadhasivam Subject: [PATCH v3 1/7] bus: mhi: core: Pass module owner during client driver registration Date: Tue, 24 Mar 2020 11:40:44 +0530 Message-Id: <20200324061050.14845-2-manivannan.sadhasivam@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200324061050.14845-1-manivannan.sadhasivam@linaro.org> References: <20200324061050.14845-1-manivannan.sadhasivam@linaro.org> Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org The module owner field can be used to prevent the removal of kernel modules when there are any device files associated with it opened in userspace. Hence, modify the API to pass module owner field. For convenience, module_mhi_driver() macro is used which takes care of passing the module owner through THIS_MODULE of the module of the driver and also avoiding the use of specifying the default MHI client driver register/unregister routines. Suggested-by: Greg Kroah-Hartman Signed-off-by: Manivannan Sadhasivam Reviewed-by: Bjorn Andersson --- drivers/bus/mhi/core/init.c | 5 +++-- include/linux/mhi.h | 21 +++++++++++++++++++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/drivers/bus/mhi/core/init.c b/drivers/bus/mhi/core/init.c index 5fb756ca335e..eb7f556a8531 100644 --- a/drivers/bus/mhi/core/init.c +++ b/drivers/bus/mhi/core/init.c @@ -1189,7 +1189,7 @@ static int mhi_driver_remove(struct device *dev) return 0; } -int mhi_driver_register(struct mhi_driver *mhi_drv) +int __mhi_driver_register(struct mhi_driver *mhi_drv, struct module *owner) { struct device_driver *driver = &mhi_drv->driver; @@ -1197,12 +1197,13 @@ int mhi_driver_register(struct mhi_driver *mhi_drv) return -EINVAL; driver->bus = &mhi_bus_type; + driver->owner = owner; driver->probe = mhi_driver_probe; driver->remove = mhi_driver_remove; return driver_register(driver); } -EXPORT_SYMBOL_GPL(mhi_driver_register); +EXPORT_SYMBOL_GPL(__mhi_driver_register); void mhi_driver_unregister(struct mhi_driver *mhi_drv) { diff --git a/include/linux/mhi.h b/include/linux/mhi.h index 79cb9f898544..d83e7772681b 100644 --- a/include/linux/mhi.h +++ b/include/linux/mhi.h @@ -514,11 +514,28 @@ int mhi_register_controller(struct mhi_controller *mhi_cntrl, */ void mhi_unregister_controller(struct mhi_controller *mhi_cntrl); +/* + * module_mhi_driver() - Helper macro for drivers that don't do + * anything special other than using default mhi_driver_register() and + * mhi_driver_unregister(). This eliminates a lot of boilerplate. + * Each module may only use this macro once. + */ +#define module_mhi_driver(mhi_drv) \ + module_driver(mhi_drv, mhi_driver_register, \ + mhi_driver_unregister) + +/* + * Macro to avoid include chaining to get THIS_MODULE + */ +#define mhi_driver_register(mhi_drv) \ + __mhi_driver_register(mhi_drv, THIS_MODULE) + /** - * mhi_driver_register - Register driver with MHI framework + * __mhi_driver_register - Register driver with MHI framework * @mhi_drv: Driver associated with the device + * @owner: The module owner */ -int mhi_driver_register(struct mhi_driver *mhi_drv); +int __mhi_driver_register(struct mhi_driver *mhi_drv, struct module *owner); /** * mhi_driver_unregister - Unregister a driver for mhi_devices From patchwork Tue Mar 24 06:10:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manivannan Sadhasivam X-Patchwork-Id: 11454535 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DDB7413A4 for ; Tue, 24 Mar 2020 06:11:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B53BD20771 for ; Tue, 24 Mar 2020 06:11:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="KEMRJ4SF" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725922AbgCXGLP (ORCPT ); Tue, 24 Mar 2020 02:11:15 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:39972 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727382AbgCXGLO (ORCPT ); Tue, 24 Mar 2020 02:11:14 -0400 Received: by mail-pf1-f195.google.com with SMTP id l184so8772065pfl.7 for ; Mon, 23 Mar 2020 23:11:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=0rm/hJBOldUA/aelJL/2EPkyPaOyJlZ3C53n4HhDybY=; b=KEMRJ4SFDvRpOJmhr1f/KS419BcRJyaqRe755EAdgeGhjJ2Q8FVBtVAtK3ALS2CBtn K9pOYMZVsG2iu6D4aYIHUsNBiiexxY5M1khLEFQbY0i8ANwYdG4Gt+EjMM0ZuZAY0b7x 8/oZbhA/hEIOuCPH3B20NZlasLhAzHbmFr36vF/flk7zmvulQGDmdr05nqXfDMJAPYn+ P43QRSMo/1MH2Y+39neYdm9e6SN6aDZMxspJ/0HTA071hAquE0jQOqbKFTG0pbcYi5Pr YzvYpjcUH6THCtm/LDvjXrlNEl7YP6IVCmHWflNDWL5lD5lcatOEmD3UuCKv5An5/HcC VPbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=0rm/hJBOldUA/aelJL/2EPkyPaOyJlZ3C53n4HhDybY=; b=RxNof4VYAMcSx69wnU22Jttjgemi549WhXYln3Vff1h+OxcMKBfTkHywNf9WDCtQhs 9TaKfxP+A0WsbGXobr2OAixWEdwSr7FqOqJadGmf+pJkMzmkDk0mGDdrbCIXVdy9tHCG g4mueoWIlGuY7s+9yUQpxqQ+NZUBmXmgZtNhXBq2DFjtpQzLKexFZroUaogi5rWqU1gK UAmlBuwkBk+hceZm56NE/Obykn4aCKXuoT2o8+ClQIGKckGLFH2xvvrZBFp94TeoHS0+ /8o/HA8FYtYEeDFZ4c3EZoIMshfKzpBPJ+TPqWIKrwtT4bEcMKUOvnxLXlcrLDjmUVTP TcqQ== X-Gm-Message-State: ANhLgQ2cER87RzPs4WWDwfUSqZESXQBRNru5Rz2uwPUZb9w1EmT/LRY6 CNW5c904Zk49AHasG/8nqPlE X-Google-Smtp-Source: ADFU+vtdkmKcfs5JkcvwJtgfg9WSWwDNy1nKFYd5TW6336wHwH1zN4PM5212jXW26bwnPfgtG4WjVw== X-Received: by 2002:a63:9248:: with SMTP id s8mr25359532pgn.253.1585030272176; Mon, 23 Mar 2020 23:11:12 -0700 (PDT) Received: from localhost.localdomain ([2409:4072:59b:91e:2dd6:dffe:3569:b473]) by smtp.gmail.com with ESMTPSA id d3sm1198230pjc.42.2020.03.23.23.11.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Mar 2020 23:11:11 -0700 (PDT) From: Manivannan Sadhasivam To: gregkh@linuxfoundation.org, davem@davemloft.net Cc: smohanad@codeaurora.org, jhugo@codeaurora.org, kvalo@codeaurora.org, bjorn.andersson@linaro.org, hemantk@codeaurora.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, Manivannan Sadhasivam Subject: [PATCH v3 2/7] bus: mhi: core: Add support for reading MHI info from device Date: Tue, 24 Mar 2020 11:40:45 +0530 Message-Id: <20200324061050.14845-3-manivannan.sadhasivam@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200324061050.14845-1-manivannan.sadhasivam@linaro.org> References: <20200324061050.14845-1-manivannan.sadhasivam@linaro.org> Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org The MHI register base has several registers used for getting the MHI specific information such as version, family, major, and minor numbers from the device. This information can be used by the controller drivers for usecases such as applying quirks for a specific revision etc... While at it, let's also rearrange the local variables in mhi_register_controller(). Suggested-by: Hemant Kumar Signed-off-by: Manivannan Sadhasivam Reviewed-by: Jeffrey Hugo --- drivers/bus/mhi/core/init.c | 19 +++++++++++++++++-- drivers/bus/mhi/core/internal.h | 10 ++++++++++ include/linux/mhi.h | 17 +++++++++++++++++ 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/drivers/bus/mhi/core/init.c b/drivers/bus/mhi/core/init.c index eb7f556a8531..d136f6c6ca78 100644 --- a/drivers/bus/mhi/core/init.c +++ b/drivers/bus/mhi/core/init.c @@ -802,12 +802,12 @@ static int parse_config(struct mhi_controller *mhi_cntrl, int mhi_register_controller(struct mhi_controller *mhi_cntrl, struct mhi_controller_config *config) { - int ret; - int i; struct mhi_event *mhi_event; struct mhi_chan *mhi_chan; struct mhi_cmd *mhi_cmd; struct mhi_device *mhi_dev; + u32 soc_info; + int ret, i; if (!mhi_cntrl) return -EINVAL; @@ -874,6 +874,21 @@ int mhi_register_controller(struct mhi_controller *mhi_cntrl, mhi_cntrl->unmap_single = mhi_unmap_single_no_bb; } + /* Read the MHI device info */ + ret = mhi_read_reg(mhi_cntrl, mhi_cntrl->regs, + SOC_HW_VERSION_OFFS, &soc_info); + if (ret) + goto error_alloc_dev; + + mhi_cntrl->family_number = (soc_info & SOC_HW_VERSION_FAM_NUM_BMSK) >> + SOC_HW_VERSION_FAM_NUM_SHFT; + mhi_cntrl->device_number = (soc_info & SOC_HW_VERSION_DEV_NUM_BMSK) >> + SOC_HW_VERSION_DEV_NUM_SHFT; + mhi_cntrl->major_version = (soc_info & SOC_HW_VERSION_MAJOR_VER_BMSK) >> + SOC_HW_VERSION_MAJOR_VER_SHFT; + mhi_cntrl->minor_version = (soc_info & SOC_HW_VERSION_MINOR_VER_BMSK) >> + SOC_HW_VERSION_MINOR_VER_SHFT; + /* Register controller with MHI bus */ mhi_dev = mhi_alloc_device(mhi_cntrl); if (IS_ERR(mhi_dev)) { diff --git a/drivers/bus/mhi/core/internal.h b/drivers/bus/mhi/core/internal.h index 18066302e6e2..5deadfaa053a 100644 --- a/drivers/bus/mhi/core/internal.h +++ b/drivers/bus/mhi/core/internal.h @@ -196,6 +196,16 @@ extern struct bus_type mhi_bus_type; #define BHIE_RXVECSTATUS_STATUS_XFER_COMPL (0x02) #define BHIE_RXVECSTATUS_STATUS_ERROR (0x03) +#define SOC_HW_VERSION_OFFS (0x224) +#define SOC_HW_VERSION_FAM_NUM_BMSK (0xF0000000) +#define SOC_HW_VERSION_FAM_NUM_SHFT (28) +#define SOC_HW_VERSION_DEV_NUM_BMSK (0x0FFF0000) +#define SOC_HW_VERSION_DEV_NUM_SHFT (16) +#define SOC_HW_VERSION_MAJOR_VER_BMSK (0x0000FF00) +#define SOC_HW_VERSION_MAJOR_VER_SHFT (8) +#define SOC_HW_VERSION_MINOR_VER_BMSK (0x000000FF) +#define SOC_HW_VERSION_MINOR_VER_SHFT (0) + #define EV_CTX_RESERVED_MASK GENMASK(7, 0) #define EV_CTX_INTMODC_MASK GENMASK(15, 8) #define EV_CTX_INTMODC_SHIFT 8 diff --git a/include/linux/mhi.h b/include/linux/mhi.h index d83e7772681b..ad1996001965 100644 --- a/include/linux/mhi.h +++ b/include/linux/mhi.h @@ -310,6 +310,10 @@ struct mhi_controller_config { * @sw_ev_rings: Number of software event rings * @nr_irqs_req: Number of IRQs required to operate (optional) * @nr_irqs: Number of IRQ allocated by bus master (required) + * @family_number: MHI controller family number + * @device_number: MHI controller device number + * @major_version: MHI controller major revision number + * @minor_version: MHI controller minor revision number * @mhi_event: MHI event ring configurations table * @mhi_cmd: MHI command ring configurations table * @mhi_ctxt: MHI device context, shared memory between host and device @@ -348,6 +352,15 @@ struct mhi_controller_config { * Fields marked as (required) need to be populated by the controller driver * before calling mhi_register_controller(). For the fields marked as (optional) * they can be populated depending on the usecase. + * + * The following fields are present for the purpose of implementing any device + * specific quirks or customizations for specific MHI revisions used in device + * by the controller drivers. The MHI stack will just populate these fields + * during mhi_register_controller(): + * family_number + * device_number + * major_version + * minor_version */ struct mhi_controller { struct device *cntrl_dev; @@ -375,6 +388,10 @@ struct mhi_controller { u32 sw_ev_rings; u32 nr_irqs_req; u32 nr_irqs; + u32 family_number; + u32 device_number; + u32 major_version; + u32 minor_version; struct mhi_event *mhi_event; struct mhi_cmd *mhi_cmd; From patchwork Tue Mar 24 06:10:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manivannan Sadhasivam X-Patchwork-Id: 11454537 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B54D4139A for ; Tue, 24 Mar 2020 06:11:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9745F2076A for ; Tue, 24 Mar 2020 06:11:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="mmLkHpFK" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727395AbgCXGLT (ORCPT ); Tue, 24 Mar 2020 02:11:19 -0400 Received: from mail-pl1-f196.google.com ([209.85.214.196]:42343 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727382AbgCXGLS (ORCPT ); Tue, 24 Mar 2020 02:11:18 -0400 Received: by mail-pl1-f196.google.com with SMTP id e1so1963181plt.9 for ; Mon, 23 Mar 2020 23:11:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=unGw6c2ZufitdrNu+5YBhFURhwCE/NrCJkMv+/OxkYg=; b=mmLkHpFKTPFen+ZlFBI6Y5O7t5YQ+gxaypgDSVkVsy6No15tBsYyZBcivmIjXfDksv b8nhz4EZZ2iBHdAZ7Tf53h3eN7oiBb36Drk1mSKlYwOTqmSdtbBLdT8D520MXrTRurDo 7xqv+yuWmiIwS9kVde5JkGflRvjNS1N0smgCb/x/OBmVu/h62TxHhWMIA3vf2r5q0HI7 EV90UIZSFydnGLXruPL0t4iOGrEzSIZNZJwJkn4ydW3o9zWPxu8ET4+SGNZpv3TXtIK9 Q9+q6KYZv4mAmT9CO61IAZeT3ycG053BCwPz8IEDllMnFHISUO5In3GGDuJQEk0jA6yf qM3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=unGw6c2ZufitdrNu+5YBhFURhwCE/NrCJkMv+/OxkYg=; b=qYEQKAg4onVX7NNqNz1EYr4yc7t0y2Baj0CFGIvxyDuxXosc0b5DpGiA8X8UMqbdKT odiXaRewp7xkXfuWbA1OBvw6NNtKsztER6YYSFZfBbLlve7Ja9t41FDVQCq60KM6Rnmk KYW1E3il76uy9DBNkHmESXXbCgy7s4J8hT46HlFNRl3O8uyraLjLSFyrifuYlpTYcjxt z/mFdyBtf/dxiETMChcGrXmy4zee6/zsq9Npu8sz1cKPY82+ZSTjURMjm0r4hWhFQIzW /EOrCZxQJ+ulVgC0LUqSUDpezp27NnSvSjJ9mfvGUgJpIVkUA6BeiH/AaBxsVwDGsbV0 DH3Q== X-Gm-Message-State: ANhLgQ353PGyFgXW6be7dNF0/3w4T4mtH/bhBNv+znDIHUd/C0BBoU5a /KdlmHnRHti1sxeBxQQT0HRwdxkQX+e+ X-Google-Smtp-Source: ADFU+vtFqc4TbjsXoMhXd7IiEHDc7u0CViodMZ/TFGvHx0UxE3d9nvIjRCj5jVigaJYM4lcFty4yXg== X-Received: by 2002:a17:90a:d101:: with SMTP id l1mr3604492pju.130.1585030277624; Mon, 23 Mar 2020 23:11:17 -0700 (PDT) Received: from localhost.localdomain ([2409:4072:59b:91e:2dd6:dffe:3569:b473]) by smtp.gmail.com with ESMTPSA id d3sm1198230pjc.42.2020.03.23.23.11.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Mar 2020 23:11:17 -0700 (PDT) From: Manivannan Sadhasivam To: gregkh@linuxfoundation.org, davem@davemloft.net Cc: smohanad@codeaurora.org, jhugo@codeaurora.org, kvalo@codeaurora.org, bjorn.andersson@linaro.org, hemantk@codeaurora.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, Manivannan Sadhasivam Subject: [PATCH v3 3/7] bus: mhi: core: Initialize bhie field in mhi_cntrl for RDDM capture Date: Tue, 24 Mar 2020 11:40:46 +0530 Message-Id: <20200324061050.14845-4-manivannan.sadhasivam@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200324061050.14845-1-manivannan.sadhasivam@linaro.org> References: <20200324061050.14845-1-manivannan.sadhasivam@linaro.org> Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org The bhie field in mhi_cntrl needs to be initialized to proper register base in order to make mhi_rddm_prepare() to work. Otherwise, mhi_rddm_prepare() will cause NULL pointer dereference. Fixes: 6fdfdd27328c ("bus: mhi: core: Add support for downloading RDDM image during panic") Reported-by: Hemant Kumar Signed-off-by: Manivannan Sadhasivam Reviewed-by: Jeffrey Hugo --- drivers/bus/mhi/core/init.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/bus/mhi/core/init.c b/drivers/bus/mhi/core/init.c index d136f6c6ca78..f6e3c16225a7 100644 --- a/drivers/bus/mhi/core/init.c +++ b/drivers/bus/mhi/core/init.c @@ -979,7 +979,8 @@ int mhi_prepare_for_power_up(struct mhi_controller *mhi_cntrl) goto bhie_error; } - memset_io(mhi_cntrl->regs + bhie_off + BHIE_RXVECADDR_LOW_OFFS, + mhi_cntrl->bhie = mhi_cntrl->regs + bhie_off; + memset_io(mhi_cntrl->bhie + BHIE_RXVECADDR_LOW_OFFS, 0, BHIE_RXVECSTATUS_OFFS - BHIE_RXVECADDR_LOW_OFFS + 4); From patchwork Tue Mar 24 06:10:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manivannan Sadhasivam X-Patchwork-Id: 11454539 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 59448139A for ; Tue, 24 Mar 2020 06:11:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 394482076A for ; Tue, 24 Mar 2020 06:11:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="pd8UTyaS" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727389AbgCXGLY (ORCPT ); Tue, 24 Mar 2020 02:11:24 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:38153 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727365AbgCXGLY (ORCPT ); Tue, 24 Mar 2020 02:11:24 -0400 Received: by mail-pl1-f193.google.com with SMTP id w3so6985307plz.5 for ; Mon, 23 Mar 2020 23:11:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=0WVYi5XJp4WaCaddQcy1HjEAG2je/Kk0d1P+LoVF1LU=; b=pd8UTyaSYpTKXCN7QrLwOBofh1wKx/kx7MMp7nmsCAGZEbgwlZO4bwiH2fcWXPlA5b p6BEUK/SHbdRxrz/bGGpfCUiH2b6pZ9DuaNLUDODNLt+y0D+EAVXZBjqwNAqyHhzOH48 j/MZWAkuys3pFFFmuX6gzEKE+FaqNrGmyrp+UpWN116KU//zbGN8gF9CHL6vuLLnpwPG NUtuB6aqgewmt1vhEa3oW66kW8eSsWwSyKMnX3JsIIP6ch0VhJ+pEBCE9FOGn4Tvd3YB 5SIOKiucbizWWIuvdeQMKrM5HajVCRo+TOn7VrnP3eHKn/0UVpB6qNzdmLrftimF3M8o LVVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=0WVYi5XJp4WaCaddQcy1HjEAG2je/Kk0d1P+LoVF1LU=; b=C4cr4Y14vi6xsiDBOT6jAJAZZvFmCd5gYdwwQYJYQLAEVCRmgz/ILOdzs/+A+a/qBk Ue2Fcf32OvBtFPiikyffMOrR49tinaasNwCfByP4wq2AUoR/ZyEyaHZ6RzwGHGdQYPS6 Mq9JGi0QhBnMLPW+wZffS5a1A7iN3vI5EouNshwkNcdP7MNSQwBXWA0Sh5aH57sn/IgP 40SrOlCKWmmC9BWDOprIsbFbcQzwCqaNSaEDEDDbYrOO9VJjvhP8p81XhWwSoOaClXFB xv6dhH9O2OmH8EzW5hZdUa0WC/9/BbWHrNkSwwjXBMA3RHZzB0SxSrE05fOJ5cyga16P tWIQ== X-Gm-Message-State: ANhLgQ148rMg1TrkVAEmsGT47lUxVgnAQZyTOtS3LnqVHCXf9KFAvU2q N4mbrkVlDsN1OTuc7d/bsaWu X-Google-Smtp-Source: ADFU+vtjITQ4IqHQogQZiG/IQLbhQZQbc/2nRvw0YUkLGLuZY8TqVftFygLUnF65xwOp2p2QBRHGug== X-Received: by 2002:a17:902:8a8f:: with SMTP id p15mr25265479plo.45.1585030283398; Mon, 23 Mar 2020 23:11:23 -0700 (PDT) Received: from localhost.localdomain ([2409:4072:59b:91e:2dd6:dffe:3569:b473]) by smtp.gmail.com with ESMTPSA id d3sm1198230pjc.42.2020.03.23.23.11.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Mar 2020 23:11:22 -0700 (PDT) From: Manivannan Sadhasivam To: gregkh@linuxfoundation.org, davem@davemloft.net Cc: smohanad@codeaurora.org, jhugo@codeaurora.org, kvalo@codeaurora.org, bjorn.andersson@linaro.org, hemantk@codeaurora.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, Manivannan Sadhasivam Subject: [PATCH v3 4/7] bus: mhi: core: Drop the references to mhi_dev in mhi_destroy_device() Date: Tue, 24 Mar 2020 11:40:47 +0530 Message-Id: <20200324061050.14845-5-manivannan.sadhasivam@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200324061050.14845-1-manivannan.sadhasivam@linaro.org> References: <20200324061050.14845-1-manivannan.sadhasivam@linaro.org> Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org For some scenarios like controller suspend and resume, mhi_destroy_device() will get called without mhi_unregister_controller(). In that case, the references to the mhi_dev created for the channels will not be dropped but the channels will be destroyed as per the spec. This will cause issue during resume as the channels will not be created due to the fact that mhi_dev is not NULL. Hence, this change decrements the refcount for mhi_dev in mhi_destroy_device() for concerned channels and also sets mhi_dev to NULL in release_device(). Reported-by: Carl Huang Signed-off-by: Manivannan Sadhasivam Reviewed-by: Jeffrey Hugo --- drivers/bus/mhi/core/init.c | 12 ++++++++++++ drivers/bus/mhi/core/main.c | 13 +++++++++++++ 2 files changed, 25 insertions(+) diff --git a/drivers/bus/mhi/core/init.c b/drivers/bus/mhi/core/init.c index f6e3c16225a7..b38359c480ea 100644 --- a/drivers/bus/mhi/core/init.c +++ b/drivers/bus/mhi/core/init.c @@ -1028,6 +1028,18 @@ static void mhi_release_device(struct device *dev) { struct mhi_device *mhi_dev = to_mhi_device(dev); + /* + * We need to set the mhi_chan->mhi_dev to NULL here since the MHI + * devices for the channels will only get created if the mhi_dev + * associated with it is NULL. This scenario will happen during the + * controller suspend and resume. + */ + if (mhi_dev->ul_chan) + mhi_dev->ul_chan->mhi_dev = NULL; + + if (mhi_dev->dl_chan) + mhi_dev->dl_chan->mhi_dev = NULL; + kfree(mhi_dev); } diff --git a/drivers/bus/mhi/core/main.c b/drivers/bus/mhi/core/main.c index fa1c9000fc6c..eb4256b81406 100644 --- a/drivers/bus/mhi/core/main.c +++ b/drivers/bus/mhi/core/main.c @@ -244,6 +244,19 @@ int mhi_destroy_device(struct device *dev, void *data) if (mhi_dev->dev_type == MHI_DEVICE_CONTROLLER) return 0; + /* + * For the suspend and resume case, this function will get called + * without mhi_unregister_controller(). Hence, we need to drop the + * references to mhi_dev created for ul and dl channels. We can + * be sure that there will be no instances of mhi_dev left after + * this. + */ + if (mhi_dev->ul_chan) + put_device(&mhi_dev->ul_chan->mhi_dev->dev); + + if (mhi_dev->dl_chan) + put_device(&mhi_dev->dl_chan->mhi_dev->dev); + dev_dbg(&mhi_cntrl->mhi_dev->dev, "destroy device for chan:%s\n", mhi_dev->chan_name); From patchwork Tue Mar 24 06:10:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manivannan Sadhasivam X-Patchwork-Id: 11454543 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 169E81667 for ; Tue, 24 Mar 2020 06:11:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E369320771 for ; Tue, 24 Mar 2020 06:11:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="vrtwUcqh" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727385AbgCXGLb (ORCPT ); Tue, 24 Mar 2020 02:11:31 -0400 Received: from mail-pj1-f66.google.com ([209.85.216.66]:53496 "EHLO mail-pj1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727430AbgCXGLa (ORCPT ); Tue, 24 Mar 2020 02:11:30 -0400 Received: by mail-pj1-f66.google.com with SMTP id l36so995332pjb.3 for ; Mon, 23 Mar 2020 23:11:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=/86LCZpkdCCI2aQCkzyWwEuy6AbVAj1IJKzL58DHDfQ=; b=vrtwUcqhU1l9wLZyKBZEW4mDGC9KBIBLFjtZ3UfXYB/Qz0U0Hc2k9GcoKevL7uDtaS 7GXCtoWPGYDhplHae3R/r5X2o0rrJ2uNfFFMEq2Do9EL7sXt0d031QjzTa3VV40llKc1 Evt248p+agdfSRVHBaks347mtnq4EyD4auzSv41h+mEGm5Z4omkqbHWLnNL2flYrqfIu XPqOXQFWJdUC+TpOezYzq+DBYPqUOs2W7O/f+GGaPRumSz33Ovlu2kri4K8Tjezyv7t1 PRlhPGSyDu3gq+n+3t7puJ+YO9CyZ/EYigHMjV9qqb57JXeMpNq+3cW1/IWqCfPC7o8E y96g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=/86LCZpkdCCI2aQCkzyWwEuy6AbVAj1IJKzL58DHDfQ=; b=TpBM/BKllbnR14Qeh9mrUxerqyz/tDqxOHbSUnXRih66260Y69lSVvGaCf66grAiaY y8N7wuQA4ZN5ay3FmzB216KgOHGIJpG9I4k4tkVudzCTBeo/3YUgw75tlRBIFgmHNnuf +WQjdVRIKZ1t6w9SJjqey+n7uK3AI3pjORpqcrlbZXQlvSKrafs9H9CAl/u1JAF6CKTI rKFBlPtQBpP4HjFlPkkX2OfboTV8EQmlF2LkArdSvl/NzLdtcwko0fuI5QNC2KqiyDMo sj0JuhlPFJUUz6tLYgFayHvZ5G1U+yU/iKYnNKpXdAWyure4ItgDgMqHcS03CGJx4i84 7EUA== X-Gm-Message-State: ANhLgQ2LDx11lrAbKo8PDBM2UWqhoQX3rtpCDvnbj+X3l80117kvvo6j h6Qq/5lf7VbR76Nq8DQ+96Wm X-Google-Smtp-Source: ADFU+vtT7adukjvlk9uTw7E6MHGu38E1BVbffnegU9VP/VYKG7E3XbjWykfRkoNk0VRxDEUGKXKDeA== X-Received: by 2002:a17:902:b7c8:: with SMTP id v8mr13871187plz.174.1585030289088; Mon, 23 Mar 2020 23:11:29 -0700 (PDT) Received: from localhost.localdomain ([2409:4072:59b:91e:2dd6:dffe:3569:b473]) by smtp.gmail.com with ESMTPSA id d3sm1198230pjc.42.2020.03.23.23.11.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Mar 2020 23:11:28 -0700 (PDT) From: Manivannan Sadhasivam To: gregkh@linuxfoundation.org, davem@davemloft.net Cc: smohanad@codeaurora.org, jhugo@codeaurora.org, kvalo@codeaurora.org, bjorn.andersson@linaro.org, hemantk@codeaurora.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, Manivannan Sadhasivam Subject: [PATCH v3 5/7] bus: mhi: core: Add support for MHI suspend and resume Date: Tue, 24 Mar 2020 11:40:48 +0530 Message-Id: <20200324061050.14845-6-manivannan.sadhasivam@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200324061050.14845-1-manivannan.sadhasivam@linaro.org> References: <20200324061050.14845-1-manivannan.sadhasivam@linaro.org> Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org Add support for MHI suspend and resume states. While at it, the mhi_notify() function needs to be exported as well. Signed-off-by: Manivannan Sadhasivam --- drivers/bus/mhi/core/main.c | 3 +- drivers/bus/mhi/core/pm.c | 143 ++++++++++++++++++++++++++++++++++++ include/linux/mhi.h | 19 +++++ 3 files changed, 164 insertions(+), 1 deletion(-) diff --git a/drivers/bus/mhi/core/main.c b/drivers/bus/mhi/core/main.c index eb4256b81406..3e9aa3b2da77 100644 --- a/drivers/bus/mhi/core/main.c +++ b/drivers/bus/mhi/core/main.c @@ -267,7 +267,7 @@ int mhi_destroy_device(struct device *dev, void *data) return 0; } -static void mhi_notify(struct mhi_device *mhi_dev, enum mhi_callback cb_reason) +void mhi_notify(struct mhi_device *mhi_dev, enum mhi_callback cb_reason) { struct mhi_driver *mhi_drv; @@ -279,6 +279,7 @@ static void mhi_notify(struct mhi_device *mhi_dev, enum mhi_callback cb_reason) if (mhi_drv->status_cb) mhi_drv->status_cb(mhi_dev, cb_reason); } +EXPORT_SYMBOL_GPL(mhi_notify); /* Bind MHI channels to MHI devices */ void mhi_create_devices(struct mhi_controller *mhi_cntrl) diff --git a/drivers/bus/mhi/core/pm.c b/drivers/bus/mhi/core/pm.c index 52690cb5c89c..3529419d076b 100644 --- a/drivers/bus/mhi/core/pm.c +++ b/drivers/bus/mhi/core/pm.c @@ -669,6 +669,149 @@ void mhi_pm_st_worker(struct work_struct *work) } } +int mhi_pm_suspend(struct mhi_controller *mhi_cntrl) +{ + struct mhi_chan *itr, *tmp; + struct device *dev = &mhi_cntrl->mhi_dev->dev; + enum mhi_pm_state new_state; + int ret; + + if (mhi_cntrl->pm_state == MHI_PM_DISABLE) + return -EINVAL; + + if (MHI_PM_IN_ERROR_STATE(mhi_cntrl->pm_state)) + return -EIO; + + /* Return busy if there are any pending resources */ + if (atomic_read(&mhi_cntrl->dev_wake)) + return -EBUSY; + + /* Take MHI out of M2 state */ + read_lock_bh(&mhi_cntrl->pm_lock); + mhi_cntrl->wake_get(mhi_cntrl, false); + read_unlock_bh(&mhi_cntrl->pm_lock); + + ret = wait_event_timeout(mhi_cntrl->state_event, + mhi_cntrl->dev_state == MHI_STATE_M0 || + mhi_cntrl->dev_state == MHI_STATE_M1 || + MHI_PM_IN_ERROR_STATE(mhi_cntrl->pm_state), + msecs_to_jiffies(mhi_cntrl->timeout_ms)); + + read_lock_bh(&mhi_cntrl->pm_lock); + mhi_cntrl->wake_put(mhi_cntrl, false); + read_unlock_bh(&mhi_cntrl->pm_lock); + + if (!ret || MHI_PM_IN_ERROR_STATE(mhi_cntrl->pm_state)) { + dev_err(dev, + "Could not enter M0/M1 state"); + return -EIO; + } + + write_lock_irq(&mhi_cntrl->pm_lock); + + if (atomic_read(&mhi_cntrl->dev_wake)) { + write_unlock_irq(&mhi_cntrl->pm_lock); + return -EBUSY; + } + + dev_info(dev, "Allowing M3 transition\n"); + new_state = mhi_tryset_pm_state(mhi_cntrl, MHI_PM_M3_ENTER); + if (new_state != MHI_PM_M3_ENTER) { + write_unlock_irq(&mhi_cntrl->pm_lock); + dev_err(dev, + "Error setting to PM state: %s from: %s\n", + to_mhi_pm_state_str(MHI_PM_M3_ENTER), + to_mhi_pm_state_str(mhi_cntrl->pm_state)); + return -EIO; + } + + /* Set MHI to M3 and wait for completion */ + mhi_set_mhi_state(mhi_cntrl, MHI_STATE_M3); + write_unlock_irq(&mhi_cntrl->pm_lock); + dev_info(dev, "Wait for M3 completion\n"); + + ret = wait_event_timeout(mhi_cntrl->state_event, + mhi_cntrl->dev_state == MHI_STATE_M3 || + MHI_PM_IN_ERROR_STATE(mhi_cntrl->pm_state), + msecs_to_jiffies(mhi_cntrl->timeout_ms)); + + if (!ret || MHI_PM_IN_ERROR_STATE(mhi_cntrl->pm_state)) { + dev_err(dev, + "Did not enter M3 state, MHI state: %s, PM state: %s\n", + TO_MHI_STATE_STR(mhi_cntrl->dev_state), + to_mhi_pm_state_str(mhi_cntrl->pm_state)); + return -EIO; + } + + /* Notify clients about entering LPM */ + list_for_each_entry_safe(itr, tmp, &mhi_cntrl->lpm_chans, node) { + mutex_lock(&itr->mutex); + if (itr->mhi_dev) + mhi_notify(itr->mhi_dev, MHI_CB_LPM_ENTER); + mutex_unlock(&itr->mutex); + } + + return 0; +} +EXPORT_SYMBOL_GPL(mhi_pm_suspend); + +int mhi_pm_resume(struct mhi_controller *mhi_cntrl) +{ + struct mhi_chan *itr, *tmp; + struct device *dev = &mhi_cntrl->mhi_dev->dev; + enum mhi_pm_state cur_state; + int ret; + + dev_info(dev, "Entered with PM state: %s, MHI state: %s\n", + to_mhi_pm_state_str(mhi_cntrl->pm_state), + TO_MHI_STATE_STR(mhi_cntrl->dev_state)); + + if (mhi_cntrl->pm_state == MHI_PM_DISABLE) + return 0; + + if (MHI_PM_IN_ERROR_STATE(mhi_cntrl->pm_state)) + return -EIO; + + /* Notify clients about exiting LPM */ + list_for_each_entry_safe(itr, tmp, &mhi_cntrl->lpm_chans, node) { + mutex_lock(&itr->mutex); + if (itr->mhi_dev) + mhi_notify(itr->mhi_dev, MHI_CB_LPM_EXIT); + mutex_unlock(&itr->mutex); + } + + write_lock_irq(&mhi_cntrl->pm_lock); + cur_state = mhi_tryset_pm_state(mhi_cntrl, MHI_PM_M3_EXIT); + if (cur_state != MHI_PM_M3_EXIT) { + write_unlock_irq(&mhi_cntrl->pm_lock); + dev_info(dev, + "Error setting to PM state: %s from: %s\n", + to_mhi_pm_state_str(MHI_PM_M3_EXIT), + to_mhi_pm_state_str(mhi_cntrl->pm_state)); + return -EIO; + } + + /* Set MHI to M0 and wait for completion */ + mhi_set_mhi_state(mhi_cntrl, MHI_STATE_M0); + write_unlock_irq(&mhi_cntrl->pm_lock); + + ret = wait_event_timeout(mhi_cntrl->state_event, + mhi_cntrl->dev_state == MHI_STATE_M0 || + MHI_PM_IN_ERROR_STATE(mhi_cntrl->pm_state), + msecs_to_jiffies(mhi_cntrl->timeout_ms)); + + if (!ret || MHI_PM_IN_ERROR_STATE(mhi_cntrl->pm_state)) { + dev_err(dev, + "Did not enter M0 state, MHI state: %s, PM state: %s\n", + TO_MHI_STATE_STR(mhi_cntrl->dev_state), + to_mhi_pm_state_str(mhi_cntrl->pm_state)); + return -EIO; + } + + return 0; +} +EXPORT_SYMBOL_GPL(mhi_pm_resume); + int __mhi_device_get_sync(struct mhi_controller *mhi_cntrl) { int ret; diff --git a/include/linux/mhi.h b/include/linux/mhi.h index ad1996001965..a4288f4d656f 100644 --- a/include/linux/mhi.h +++ b/include/linux/mhi.h @@ -568,6 +568,13 @@ void mhi_driver_unregister(struct mhi_driver *mhi_drv); void mhi_set_mhi_state(struct mhi_controller *mhi_cntrl, enum mhi_state state); +/** + * mhi_notify - Notify the MHI client driver about client device status + * @mhi_dev: MHI device instance + * @cb_reason: MHI callback reason + */ +void mhi_notify(struct mhi_device *mhi_dev, enum mhi_callback cb_reason); + /** * mhi_prepare_for_power_up - Do pre-initialization before power up. * This is optional, call this before power up if @@ -604,6 +611,18 @@ void mhi_power_down(struct mhi_controller *mhi_cntrl, bool graceful); */ void mhi_unprepare_after_power_down(struct mhi_controller *mhi_cntrl); +/** + * mhi_pm_suspend - Move MHI into a suspended state + * @mhi_cntrl: MHI controller + */ +int mhi_pm_suspend(struct mhi_controller *mhi_cntrl); + +/** + * mhi_pm_resume - Resume MHI from suspended state + * @mhi_cntrl: MHI controller + */ +int mhi_pm_resume(struct mhi_controller *mhi_cntrl); + /** * mhi_download_rddm_img - Download ramdump image from device for * debugging purpose. From patchwork Tue Mar 24 06:10:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manivannan Sadhasivam X-Patchwork-Id: 11454545 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 35704139A for ; Tue, 24 Mar 2020 06:11:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0CD742076A for ; Tue, 24 Mar 2020 06:11:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="dsNFxkTX" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727298AbgCXGLj (ORCPT ); Tue, 24 Mar 2020 02:11:39 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:39648 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727406AbgCXGLg (ORCPT ); Tue, 24 Mar 2020 02:11:36 -0400 Received: by mail-pg1-f193.google.com with SMTP id b22so8503101pgb.6 for ; Mon, 23 Mar 2020 23:11:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ze2ItdsI6wPt5v1O8KEFX204MaoLii8v3eVvbrQAdcg=; b=dsNFxkTXE8D/BQHaXdFb+SWKr0yvc0saXT0cLxFGUJfHrxFer5CneCCXWrdYodwoJZ qNOyZGnC3HV/pBPsLXarnAUjxzBdkQeBAei3oktwF32vejHHTG73NCSO062SBt2KIR/O 24roE0QIokr6KkYstMNlulQiYQV3nqsSCyAwhywSOYjq6XZTKxHv44nwe2TtLn7IZQsT +6kAEwVh+ZUtogvvrn62Au6gM7qIVuHE87h9x3MiynuEcseO6Y24qOfMLYXkw5YHHjcr +SrttKtV8uGHv7HG+x3CBmribMx2YQvKpbXi2lwey8NEB2C1IJKVVQbuuWNpGKRWu1oG jQ7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ze2ItdsI6wPt5v1O8KEFX204MaoLii8v3eVvbrQAdcg=; b=Ng/+x5DwRhk4/YXy9jYqQuTnPn5uk46GGL43VjTzbzy+AlimF4i68YyTdxtfK+8p9h vzbBn+3iBh5Xklnhy8JUYWJMUXyy8AwGVBZfb17zp2rBcGRXVce2kqyQnyl3zSkhEZ5W yoTIrlnOSuGpOJ6rhxMYm6FlclXVFHlX+r3iCg6fLszEuOoHzhwTE/8B8LdWz4sjceRh NOFHglzub0Jd3YZIY+bR0+KAruRsYpvADpeWLGpCET1CGWFOAT09J+dLTqgjGCeQOhUt Xk9FsF+JZT21vrSqeHuzX9ixPF/wUlK8Hu/eevtDIL+OEn8qY8c1M2J0VSDJOiRAgTth AoOA== X-Gm-Message-State: ANhLgQ3BeoLF4uCrkqyzCjDanDQNxFkH9Ax/DJAI2tj3HVFnUt5rQT3x m/tXb3gC2Joo3jiyFGIwf+GO X-Google-Smtp-Source: ADFU+vs3EbahL/k9ZQfYLcHPyNuXXaKepXG1+OjDqsxyu1WMz23vGBXvGVFx4jefmct9P3m8cmOb6Q== X-Received: by 2002:aa7:83ce:: with SMTP id j14mr14610372pfn.310.1585030294445; Mon, 23 Mar 2020 23:11:34 -0700 (PDT) Received: from localhost.localdomain ([2409:4072:59b:91e:2dd6:dffe:3569:b473]) by smtp.gmail.com with ESMTPSA id d3sm1198230pjc.42.2020.03.23.23.11.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Mar 2020 23:11:33 -0700 (PDT) From: Manivannan Sadhasivam To: gregkh@linuxfoundation.org, davem@davemloft.net Cc: smohanad@codeaurora.org, jhugo@codeaurora.org, kvalo@codeaurora.org, bjorn.andersson@linaro.org, hemantk@codeaurora.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, Manivannan Sadhasivam , netdev@vger.kernel.org Subject: [PATCH v3 6/7] net: qrtr: Add MHI transport layer Date: Tue, 24 Mar 2020 11:40:49 +0530 Message-Id: <20200324061050.14845-7-manivannan.sadhasivam@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200324061050.14845-1-manivannan.sadhasivam@linaro.org> References: <20200324061050.14845-1-manivannan.sadhasivam@linaro.org> Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org MHI is the transport layer used for communicating to the external modems. Hence, this commit adds MHI transport layer support to QRTR for transferring the QMI messages over IPC Router. Cc: "David S. Miller" Cc: netdev@vger.kernel.org Signed-off-by: Manivannan Sadhasivam --- net/qrtr/Kconfig | 7 ++ net/qrtr/Makefile | 2 + net/qrtr/mhi.c | 208 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 217 insertions(+) create mode 100644 net/qrtr/mhi.c diff --git a/net/qrtr/Kconfig b/net/qrtr/Kconfig index 63f89cc6e82c..8eb876471564 100644 --- a/net/qrtr/Kconfig +++ b/net/qrtr/Kconfig @@ -29,4 +29,11 @@ config QRTR_TUN implement endpoints of QRTR, for purpose of tunneling data to other hosts or testing purposes. +config QRTR_MHI + tristate "MHI IPC Router channels" + depends on MHI_BUS + help + Say Y here to support MHI based ipcrouter channels. MHI is the + transport used for communicating to external modems. + endif # QRTR diff --git a/net/qrtr/Makefile b/net/qrtr/Makefile index 1c6d6c120fb7..3dc0a7c9d455 100644 --- a/net/qrtr/Makefile +++ b/net/qrtr/Makefile @@ -5,3 +5,5 @@ obj-$(CONFIG_QRTR_SMD) += qrtr-smd.o qrtr-smd-y := smd.o obj-$(CONFIG_QRTR_TUN) += qrtr-tun.o qrtr-tun-y := tun.o +obj-$(CONFIG_QRTR_MHI) += qrtr-mhi.o +qrtr-mhi-y := mhi.o diff --git a/net/qrtr/mhi.c b/net/qrtr/mhi.c new file mode 100644 index 000000000000..90af208f34c1 --- /dev/null +++ b/net/qrtr/mhi.c @@ -0,0 +1,208 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2018-2020, The Linux Foundation. All rights reserved. + */ + +#include +#include +#include +#include +#include + +#include "qrtr.h" + +struct qrtr_mhi_dev { + struct qrtr_endpoint ep; + struct mhi_device *mhi_dev; + struct device *dev; + spinlock_t ul_lock; /* lock to protect ul_pkts */ + struct list_head ul_pkts; + atomic_t in_reset; +}; + +struct qrtr_mhi_pkt { + struct list_head node; + struct sk_buff *skb; + struct kref refcount; + struct completion done; +}; + +static void qrtr_mhi_pkt_release(struct kref *ref) +{ + struct qrtr_mhi_pkt *pkt = container_of(ref, struct qrtr_mhi_pkt, + refcount); + struct sock *sk = pkt->skb->sk; + + consume_skb(pkt->skb); + if (sk) + sock_put(sk); + + kfree(pkt); +} + +/* From MHI to QRTR */ +static void qcom_mhi_qrtr_dl_callback(struct mhi_device *mhi_dev, + struct mhi_result *mhi_res) +{ + struct qrtr_mhi_dev *qdev = dev_get_drvdata(&mhi_dev->dev); + int rc; + + if (!qdev || mhi_res->transaction_status) + return; + + rc = qrtr_endpoint_post(&qdev->ep, mhi_res->buf_addr, + mhi_res->bytes_xferd); + if (rc == -EINVAL) + dev_err(qdev->dev, "invalid ipcrouter packet\n"); +} + +/* From QRTR to MHI */ +static void qcom_mhi_qrtr_ul_callback(struct mhi_device *mhi_dev, + struct mhi_result *mhi_res) +{ + struct qrtr_mhi_dev *qdev = dev_get_drvdata(&mhi_dev->dev); + struct qrtr_mhi_pkt *pkt; + unsigned long flags; + + spin_lock_irqsave(&qdev->ul_lock, flags); + pkt = list_first_entry(&qdev->ul_pkts, struct qrtr_mhi_pkt, node); + list_del(&pkt->node); + complete_all(&pkt->done); + + kref_put(&pkt->refcount, qrtr_mhi_pkt_release); + spin_unlock_irqrestore(&qdev->ul_lock, flags); +} + +static void qcom_mhi_qrtr_status_callback(struct mhi_device *mhi_dev, + enum mhi_callback mhi_cb) +{ + struct qrtr_mhi_dev *qdev = dev_get_drvdata(&mhi_dev->dev); + struct qrtr_mhi_pkt *pkt; + unsigned long flags; + + if (mhi_cb != MHI_CB_FATAL_ERROR) + return; + + atomic_inc(&qdev->in_reset); + spin_lock_irqsave(&qdev->ul_lock, flags); + list_for_each_entry(pkt, &qdev->ul_pkts, node) + complete_all(&pkt->done); + spin_unlock_irqrestore(&qdev->ul_lock, flags); +} + +/* Send data over MHI */ +static int qcom_mhi_qrtr_send(struct qrtr_endpoint *ep, struct sk_buff *skb) +{ + struct qrtr_mhi_dev *qdev = container_of(ep, struct qrtr_mhi_dev, ep); + struct qrtr_mhi_pkt *pkt; + int rc; + + rc = skb_linearize(skb); + if (rc) { + kfree_skb(skb); + return rc; + } + + pkt = kzalloc(sizeof(*pkt), GFP_KERNEL); + if (!pkt) { + kfree_skb(skb); + return -ENOMEM; + } + + init_completion(&pkt->done); + kref_init(&pkt->refcount); + kref_get(&pkt->refcount); + pkt->skb = skb; + + spin_lock_bh(&qdev->ul_lock); + list_add_tail(&pkt->node, &qdev->ul_pkts); + rc = mhi_queue_skb(qdev->mhi_dev, DMA_TO_DEVICE, skb, skb->len, + MHI_EOT); + if (rc) { + list_del(&pkt->node); + /* Reference count needs to be dropped 2 times */ + kref_put(&pkt->refcount, qrtr_mhi_pkt_release); + kref_put(&pkt->refcount, qrtr_mhi_pkt_release); + kfree_skb(skb); + spin_unlock_bh(&qdev->ul_lock); + return rc; + } + + spin_unlock_bh(&qdev->ul_lock); + if (skb->sk) + sock_hold(skb->sk); + + rc = wait_for_completion_interruptible_timeout(&pkt->done, HZ * 5); + if (atomic_read(&qdev->in_reset)) + rc = -ECONNRESET; + else if (rc == 0) + rc = -ETIMEDOUT; + else if (rc > 0) + rc = 0; + + kref_put(&pkt->refcount, qrtr_mhi_pkt_release); + + return rc; +} + +static int qcom_mhi_qrtr_probe(struct mhi_device *mhi_dev, + const struct mhi_device_id *id) +{ + struct qrtr_mhi_dev *qdev; + u32 net_id; + int rc; + + qdev = devm_kzalloc(&mhi_dev->dev, sizeof(*qdev), GFP_KERNEL); + if (!qdev) + return -ENOMEM; + + qdev->mhi_dev = mhi_dev; + qdev->dev = &mhi_dev->dev; + qdev->ep.xmit = qcom_mhi_qrtr_send; + atomic_set(&qdev->in_reset, 0); + + net_id = QRTR_EP_NID_AUTO; + + INIT_LIST_HEAD(&qdev->ul_pkts); + spin_lock_init(&qdev->ul_lock); + + dev_set_drvdata(&mhi_dev->dev, qdev); + rc = qrtr_endpoint_register(&qdev->ep, net_id); + if (rc) + return rc; + + dev_dbg(qdev->dev, "Qualcomm MHI QRTR driver probed\n"); + + return 0; +} + +static void qcom_mhi_qrtr_remove(struct mhi_device *mhi_dev) +{ + struct qrtr_mhi_dev *qdev = dev_get_drvdata(&mhi_dev->dev); + + qrtr_endpoint_unregister(&qdev->ep); + dev_set_drvdata(&mhi_dev->dev, NULL); +} + +static const struct mhi_device_id qcom_mhi_qrtr_id_table[] = { + { .chan = "IPCR" }, + {} +}; +MODULE_DEVICE_TABLE(mhi, qcom_mhi_qrtr_id_table); + +static struct mhi_driver qcom_mhi_qrtr_driver = { + .probe = qcom_mhi_qrtr_probe, + .remove = qcom_mhi_qrtr_remove, + .dl_xfer_cb = qcom_mhi_qrtr_dl_callback, + .ul_xfer_cb = qcom_mhi_qrtr_ul_callback, + .status_cb = qcom_mhi_qrtr_status_callback, + .id_table = qcom_mhi_qrtr_id_table, + .driver = { + .name = "qcom_mhi_qrtr", + }, +}; + +module_mhi_driver(qcom_mhi_qrtr_driver); + +MODULE_DESCRIPTION("Qualcomm IPC-Router MHI interface driver"); +MODULE_LICENSE("GPL v2"); From patchwork Tue Mar 24 06:10:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manivannan Sadhasivam X-Patchwork-Id: 11454547 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E9D211667 for ; Tue, 24 Mar 2020 06:11:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CA3CF20771 for ; Tue, 24 Mar 2020 06:11:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="LWqoC+ij" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727470AbgCXGLm (ORCPT ); Tue, 24 Mar 2020 02:11:42 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:35029 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727473AbgCXGLl (ORCPT ); Tue, 24 Mar 2020 02:11:41 -0400 Received: by mail-pf1-f193.google.com with SMTP id u68so8777434pfb.2 for ; Mon, 23 Mar 2020 23:11:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=kEUOtzoCcyxMGagaGiuW85PJFCulYHpDp09UxNca9Ic=; b=LWqoC+ijN07fTREV37khZvwLxEKrJVJ8dLjconoL52HWgkoIMQm5u5V6zJr9faWwEu EiA/axtbMM5pm8LWqafW1QlKlEgyLlNkpnn5PzPmvp7OgOUW9zJe6xndMfqJHTNnrIzK AXTT8LKoIkT7rh6tOmvgfjXwOm60cpNWCUyzRRR5uej42sH7YgyQ/NCMOgfVGWy+3KYT eNU8rhn+hJo4VZs3+fpLLjYQ3KVZr1paMqH2EXtgM5bHm1KXAH+ALJXMLGuE9iAYGwaS BrPs4wfnYuLkezc3ZNF/j4sFUFrM2RPfeyWibQ7RhrPjPUvZxUiRirfzkdbZJtIckmY5 Z0Cw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=kEUOtzoCcyxMGagaGiuW85PJFCulYHpDp09UxNca9Ic=; b=MaC8VhuWM3tg8Dh3aQpNr8L+W8Pz1+NGBQIOAnoqbNP5kQAECoJ7VClBMZR3DFC3BE RUc6qr+AppQvgkvMo8/1ZMl77i9rswbqz/gAK50Mp/fRV2L3eVVUoO3r0N4ZU8GjnB9J vxtqhPS2y9ZiMdmz9CZjvs10PeY0D+jBnk3VgL0O68FUJvKclVhDVIEItGQTEE836Uir Fsu4urq6FZHFBWRwoxYmijg9tNsCvRBBHVZicdLVGYwre2INaK3ZIiMJnCYvtzHZcdHr +e7gGHkE2y18ftbCq6FVG/El65dWoLYZByNvX+UhV8oc9L/SaxO1IZuvbg1Q9CodwQ6B s8nA== X-Gm-Message-State: ANhLgQ39c/5OuwIIw5cn2+JzDfBIDnktFce1jV22F9ygL6u64r0c3l1j 44UJbTwINc52aATw3SrZJWO2 X-Google-Smtp-Source: ADFU+vsE1loIykImw3+EDdk0dvEYpS7hbzKWOjzd6Nt2/voPeuQ9B8H8HvVt9opVTI845JEihChDeg== X-Received: by 2002:a63:844a:: with SMTP id k71mr25767936pgd.79.1585030300253; Mon, 23 Mar 2020 23:11:40 -0700 (PDT) Received: from localhost.localdomain ([2409:4072:59b:91e:2dd6:dffe:3569:b473]) by smtp.gmail.com with ESMTPSA id d3sm1198230pjc.42.2020.03.23.23.11.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Mar 2020 23:11:39 -0700 (PDT) From: Manivannan Sadhasivam To: gregkh@linuxfoundation.org, davem@davemloft.net Cc: smohanad@codeaurora.org, jhugo@codeaurora.org, kvalo@codeaurora.org, bjorn.andersson@linaro.org, hemantk@codeaurora.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, Manivannan Sadhasivam , netdev@vger.kernel.org Subject: [PATCH v3 7/7] net: qrtr: Do not depend on ARCH_QCOM Date: Tue, 24 Mar 2020 11:40:50 +0530 Message-Id: <20200324061050.14845-8-manivannan.sadhasivam@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200324061050.14845-1-manivannan.sadhasivam@linaro.org> References: <20200324061050.14845-1-manivannan.sadhasivam@linaro.org> Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org IPC Router protocol is also used by external modems for exchanging the QMI messages. Hence, it doesn't always depend on Qualcomm platforms. One such instance is the QCA6390 WLAN device connected to x86 machine. Cc: "David S. Miller" Cc: netdev@vger.kernel.org Signed-off-by: Manivannan Sadhasivam Reviewed-by: Bjorn Andersson --- net/qrtr/Kconfig | 1 - 1 file changed, 1 deletion(-) diff --git a/net/qrtr/Kconfig b/net/qrtr/Kconfig index 8eb876471564..f362ca316015 100644 --- a/net/qrtr/Kconfig +++ b/net/qrtr/Kconfig @@ -4,7 +4,6 @@ config QRTR tristate "Qualcomm IPC Router support" - depends on ARCH_QCOM || COMPILE_TEST ---help--- Say Y if you intend to use Qualcomm IPC router protocol. The protocol is used to communicate with services provided by other