From patchwork Mon Jul 20 10:40:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SEO HOYOUNG X-Patchwork-Id: 11673461 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 C4D696C1 for ; Mon, 20 Jul 2020 10:39:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A825A22BF3 for ; Mon, 20 Jul 2020 10:39:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="RYgbbTdO" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728418AbgGTKjz (ORCPT ); Mon, 20 Jul 2020 06:39:55 -0400 Received: from mailout2.samsung.com ([203.254.224.25]:28314 "EHLO mailout2.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728402AbgGTKjy (ORCPT ); Mon, 20 Jul 2020 06:39:54 -0400 Received: from epcas2p2.samsung.com (unknown [182.195.41.54]) by mailout2.samsung.com (KnoxPortal) with ESMTP id 20200720103951epoutp02354b6c53207f918bde87d6768ba35bbd~jb8ahEIa01906719067epoutp02K for ; Mon, 20 Jul 2020 10:39:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.samsung.com 20200720103951epoutp02354b6c53207f918bde87d6768ba35bbd~jb8ahEIa01906719067epoutp02K DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1595241591; bh=msJooRWxm5c4IIG3ZDyJ9Td1DXn7tpICLv05au1ohFo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RYgbbTdOkVgOgLGVDb59qbqHmf87vxogbZrEOW/nEKSUP+6HwEqzXBVlu9YxmP++w CyfeboAfWBKUe33PkM3ge3CVtNiIc3fYCucLcAcfXe1bg/luGFw7BssoqO9M3OrJWj 4nRNPHTdl6E719mmmZrZ9HLJ8ibbumHXOGF+WjSg= Received: from epsnrtp3.localdomain (unknown [182.195.42.164]) by epcas2p1.samsung.com (KnoxPortal) with ESMTP id 20200720103951epcas2p1fa872f4b3ac13e0f41f16bf0f5f3d279~jb8aFb9ns1933419334epcas2p16; Mon, 20 Jul 2020 10:39:51 +0000 (GMT) Received: from epsmges2p3.samsung.com (unknown [182.195.40.191]) by epsnrtp3.localdomain (Postfix) with ESMTP id 4B9JBs3G7wzMqYkY; Mon, 20 Jul 2020 10:39:49 +0000 (GMT) Received: from epcas2p2.samsung.com ( [182.195.41.54]) by epsmges2p3.samsung.com (Symantec Messaging Gateway) with SMTP id 41.A0.27441.574751F5; Mon, 20 Jul 2020 19:39:49 +0900 (KST) Received: from epsmtrp2.samsung.com (unknown [182.195.40.14]) by epcas2p4.samsung.com (KnoxPortal) with ESMTPA id 20200720103949epcas2p4a49b245d9cebf0478d42fb6c607fc236~jb8X6IcQ43088630886epcas2p4Q; Mon, 20 Jul 2020 10:39:49 +0000 (GMT) Received: from epsmgms1p2.samsung.com (unknown [182.195.42.42]) by epsmtrp2.samsung.com (KnoxPortal) with ESMTP id 20200720103949epsmtrp2e9794047573b488d69059729d55a8c27~jb8X5ZG3_2144421444epsmtrp2h; Mon, 20 Jul 2020 10:39:49 +0000 (GMT) X-AuditID: b6c32a47-fafff70000006b31-06-5f15747588ce Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgms1p2.samsung.com (Symantec Messaging Gateway) with SMTP id 13.3D.08303.474751F5; Mon, 20 Jul 2020 19:39:49 +0900 (KST) Received: from rack03.dsn.sec.samsung.com (unknown [12.36.155.109]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20200720103948epsmtip20563830e08c88fa97994587ce5f05143~jb8Xsk7XO0960109601epsmtip2k; Mon, 20 Jul 2020 10:39:48 +0000 (GMT) From: SEO HOYOUNG To: linux-scsi@vger.kernel.org, alim.akhtar@samsung.com, avri.altman@wdc.com, jejb@linux.ibm.com, martin.petersen@oracle.com, beanhuo@micron.com, asutoshd@codeaurora.org, cang@codeaurora.org, bvanassche@acm.org, grant.jung@samsung.com Cc: SEO HOYOUNG Subject: [RFC PATCH v2 1/3] scsi: ufs: modify write booster Date: Mon, 20 Jul 2020 19:40:11 +0900 Message-Id: X-Mailer: git-send-email 2.26.0 In-Reply-To: MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrHJsWRmVeSWpSXmKPExsWy7bCmmW5piWi8wbLf4hYP5m1js9jbdoLd 4uXPq2wWBx92slhM+/CT2eLT+mWsFr/+rme3WL34AYvFohvbmCy6r+9gs1h+/B+TA7fH5Sve Hpf7epk8Jiw6wOjxfX0Hm8fHp7dYPPq2rGL0+LxJzqP9QDdTAEdUjk1GamJKapFCal5yfkpm XrqtkndwvHO8qZmBoa6hpYW5kkJeYm6qrZKLT4CuW2YO0KFKCmWJOaVAoYDE4mIlfTubovzS klSFjPziElul1IKUnAJDwwK94sTc4tK8dL3k/FwrQwMDI1OgyoScjGXbulkKfmtWrLy2jq2B cYVSFyMnh4SAicTKo3fZuhi5OIQEdjBKLNg6gxHC+cQosaP9OlTmM6NE+7bTLDAtT1uvQiV2 MUr0LD/BBJIQEvjBKLHxaBmIzSagIbHm2CEmkCIRgQ+MEkdXzGYFSTALqEl8vrsMbJKwgLXE tgP32UBsFgFVid4Nd4FqODh4BaIk3jeXQiyTl1jU8BtsPqeAhcScjY/AynkFBCVOznzCAjFS XqJ562xmkF0SAjM5JJb/ecMM0ewi0XD7IiOELSzx6vgWdghbSuLzu71sEHa9xJR7q1ggmnsY JfasgPhGQsBYYtazdkaQg5gFNCXW79IHMSUElCWO3ILayyfRcfgvO0SYV6KjTQiiUUnizNzb UGEJiYOzcyDCHhKLzr5nhgRbNzDYWi6zTWBUmIXkm1lIvpmFsHcBI/MqRrHUguLc9NRiowJj 5Ajex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Io9wvBBvSmJlVWpRfnxRaU5q8SFGaQ4WJXHer7MWxgkJ pCeWpGanphakFsFkmTg4pRqYmAJ37zMVXn79q1KIi/yXT3b+whOXL6yXXdE173Shlt/6RY1n vrEWiF5zU86qiV2ytmEv1+4TftrS7MefbjXW2ydwrbjxuBtjmtHDvlkv/7v/s/sb5J/FNcth L9uG3Oq483NfCDtczlrfaL/remf+4c7UlKmW1/W5nsutUcqbFWFv+1rsmJa6TdXXY4kKAlH2 8+be3lz/T2luSdZVFo/jUoqm7g1+la/1fzzuizh7dP/EY5xBu17V5+vlNoSdPL8v68Pn/T9b t9VeehMoHX13yZRN4eoBUtN67k/f/PPPmuy87IsxzydGPVW4J90T6Xktw5aPpXa9Ms/B9g0+ ua8KrK4z7LHmF1r3cPv0y8G/lViKMxINtZiLihMBS2TDI/oCAAA= X-CMS-MailID: 20200720103949epcas2p4a49b245d9cebf0478d42fb6c607fc236 X-Msg-Generator: CA X-Sendblock-Type: AUTO_CONFIDENTIAL CMS-TYPE: 102P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20200720103949epcas2p4a49b245d9cebf0478d42fb6c607fc236 References: Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Add vendor specific functions for WB Use callback additional setting when use write booster. Signed-off-by: SEO HOYOUNG --- drivers/scsi/ufs/ufshcd.c | 23 ++++++++++++++++----- drivers/scsi/ufs/ufshcd.h | 43 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 5 deletions(-) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index efc0a6cbfe22..efa16bf4fd76 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -3306,11 +3306,11 @@ int ufshcd_read_string_desc(struct ufs_hba *hba, u8 desc_index, * * Return 0 in case of success, non-zero otherwise */ -static inline int ufshcd_read_unit_desc_param(struct ufs_hba *hba, - int lun, - enum unit_desc_param param_offset, - u8 *param_read_buf, - u32 param_size) +int ufshcd_read_unit_desc_param(struct ufs_hba *hba, + int lun, + enum unit_desc_param param_offset, + u8 *param_read_buf, + u32 param_size) { /* * Unit descriptors are only available for general purpose LUs (LUN id @@ -3322,6 +3322,7 @@ static inline int ufshcd_read_unit_desc_param(struct ufs_hba *hba, return ufshcd_read_desc_param(hba, QUERY_DESC_IDN_UNIT, lun, param_offset, param_read_buf, param_size); } +EXPORT_SYMBOL_GPL(ufshcd_read_unit_desc_param); static int ufshcd_get_ref_clk_gating_wait(struct ufs_hba *hba) { @@ -5257,6 +5258,10 @@ static int ufshcd_wb_ctrl(struct ufs_hba *hba, bool enable) if (!(enable ^ hba->wb_enabled)) return 0; + + if (!ufshcd_wb_ctrl_vendor(hba, enable)) + return 0; + if (enable) opcode = UPIU_QUERY_OPCODE_SET_FLAG; else @@ -6610,6 +6615,8 @@ static int ufshcd_reset_and_restore(struct ufs_hba *hba) int err = 0; int retries = MAX_HOST_RESET_RETRIES; + ufshcd_reset_vendor(hba); + do { /* Reset the attached device */ ufshcd_vops_device_reset(hba); @@ -6903,6 +6910,9 @@ static void ufshcd_wb_probe(struct ufs_hba *hba, u8 *desc_buf) if (!(dev_info->d_ext_ufs_feature_sup & UFS_DEV_WRITE_BOOSTER_SUP)) goto wb_disabled; + if (!ufshcd_wb_alloc_units_vendor(hba)) + return; + /* * WB may be supported but not configured while provisioning. * The spec says, in dedicated wb buffer mode, @@ -8260,6 +8270,7 @@ static int ufshcd_suspend(struct ufs_hba *hba, enum ufs_pm_op pm_op) /* make sure that auto bkops is disabled */ ufshcd_disable_auto_bkops(hba); } + /* * If device needs to do BKOP or WB buffer flush during * Hibern8, keep device power mode as "active power mode" @@ -8273,6 +8284,8 @@ static int ufshcd_suspend(struct ufs_hba *hba, enum ufs_pm_op pm_op) ufshcd_wb_need_flush(hba)); } + ufshcd_wb_toggle_flush_vendor(hba, pm_op); + if (req_dev_pwr_mode != hba->curr_dev_pwr_mode) { if ((ufshcd_is_runtime_pm(pm_op) && !hba->auto_bkops_enabled) || !ufshcd_is_runtime_pm(pm_op)) { diff --git a/drivers/scsi/ufs/ufshcd.h b/drivers/scsi/ufs/ufshcd.h index 656c0691c858..deb9577e0eaa 100644 --- a/drivers/scsi/ufs/ufshcd.h +++ b/drivers/scsi/ufs/ufshcd.h @@ -254,6 +254,13 @@ struct ufs_pwr_mode_info { struct ufs_pa_layer_attr info; }; +struct ufs_wb_ops { + int (*wb_toggle_flush_vendor)(struct ufs_hba *hba, enum ufs_pm_op pm_op); + int (*wb_alloc_units_vendor)(struct ufs_hba *hba); + int (*wb_ctrl_vendor)(struct ufs_hba *hba, bool enable); + int (*wb_reset_vendor)(struct ufs_hba *hba, bool force); +}; + /** * struct ufs_hba_variant_ops - variant specific callbacks * @name: variant name @@ -752,6 +759,7 @@ struct ufs_hba { struct request_queue *bsg_queue; bool wb_buf_flush_enabled; bool wb_enabled; + struct ufs_wb_ops *wb_ops; struct delayed_work rpm_dev_flush_recheck_work; #ifdef CONFIG_SCSI_UFS_CRYPTO @@ -1004,6 +1012,10 @@ int ufshcd_exec_raw_upiu_cmd(struct ufs_hba *hba, u8 *desc_buff, int *buff_len, enum query_opcode desc_op); +int ufshcd_read_unit_desc_param(struct ufs_hba *hba, + int lun, enum unit_desc_param param_offset, + u8 *param_read_buf, u32 param_size); + /* Wrapper functions for safely calling variant operations */ static inline const char *ufshcd_get_var_name(struct ufs_hba *hba) { @@ -1181,4 +1193,35 @@ static inline u8 ufshcd_scsi_to_upiu_lun(unsigned int scsi_lun) int ufshcd_dump_regs(struct ufs_hba *hba, size_t offset, size_t len, const char *prefix); +static inline int ufshcd_wb_toggle_flush_vendor(struct ufs_hba *hba, enum ufs_pm_op pm_op) +{ + if (!hba->wb_ops || !hba->wb_ops->wb_toggle_flush_vendor) + return -1; + + return hba->wb_ops->wb_toggle_flush_vendor(hba, pm_op); +} + +static int ufshcd_wb_alloc_units_vendor(struct ufs_hba *hba) +{ + if (!hba->wb_ops || !hba->wb_ops->wb_alloc_units_vendor) + return -1; + + return hba->wb_ops->wb_alloc_units_vendor(hba); +} + +static int ufshcd_wb_ctrl_vendor(struct ufs_hba *hba, bool enable) +{ + if (!hba->wb_ops || !hba->wb_ops->wb_ctrl_vendor) + return -1; + + return hba->wb_ops->wb_ctrl_vendor(hba, enable); +} + +static int ufshcd_reset_vendor(struct ufs_hba *hba) +{ + if (!hba->wb_ops || !hba->wb_ops->wb_reset_vendor) + return -1; + + return hba->wb_ops->wb_reset_vendor(hba, false); +} #endif /* End of Header */ From patchwork Mon Jul 20 10:40:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SEO HOYOUNG X-Patchwork-Id: 11673463 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 70A06913 for ; Mon, 20 Jul 2020 10:39:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 58D2622482 for ; Mon, 20 Jul 2020 10:39:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="Tl+zao0b" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728428AbgGTKj6 (ORCPT ); Mon, 20 Jul 2020 06:39:58 -0400 Received: from mailout4.samsung.com ([203.254.224.34]:41878 "EHLO mailout4.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728402AbgGTKj5 (ORCPT ); Mon, 20 Jul 2020 06:39:57 -0400 Received: from epcas2p2.samsung.com (unknown [182.195.41.54]) by mailout4.samsung.com (KnoxPortal) with ESMTP id 20200720103955epoutp04fc68890e5c00557b71c36dfd7fdd394f~jb8dknWGD0078500785epoutp04R for ; Mon, 20 Jul 2020 10:39:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout4.samsung.com 20200720103955epoutp04fc68890e5c00557b71c36dfd7fdd394f~jb8dknWGD0078500785epoutp04R DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1595241595; bh=XuMxHD/Gxlj+yR3CegW2oYFQ5WE9UqL8Bp0Wv+112Bs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Tl+zao0bgB0I4DlL5Yh2zFgCNc+SVXUFimiP9ZWDKzWgT76G2MYk4MCqCGprPJhS1 uOXU+Oa4iHNoDu+nhSrrD36TyleQQeL6qG5ubOSIs8skNy3GRsM1KfPlft+59v5H9+ iMTy2pKjFlLoeiDHW3CqK0vA8DRPlEguQIq1bE08= Received: from epsnrtp1.localdomain (unknown [182.195.42.162]) by epcas2p4.samsung.com (KnoxPortal) with ESMTP id 20200720103953epcas2p4aca088be9c1f8b73fe5e247fa5be3d81~jb8cZiNsB3088630886epcas2p4Y; Mon, 20 Jul 2020 10:39:53 +0000 (GMT) Received: from epsmges2p3.samsung.com (unknown [182.195.40.181]) by epsnrtp1.localdomain (Postfix) with ESMTP id 4B9JBv0RBvzMqYlv; Mon, 20 Jul 2020 10:39:51 +0000 (GMT) Received: from epcas2p1.samsung.com ( [182.195.41.53]) by epsmges2p3.samsung.com (Symantec Messaging Gateway) with SMTP id 62.A0.27441.674751F5; Mon, 20 Jul 2020 19:39:50 +0900 (KST) Received: from epsmtrp1.samsung.com (unknown [182.195.40.13]) by epcas2p1.samsung.com (KnoxPortal) with ESMTPA id 20200720103950epcas2p16278643a6f62b446b653c834de448543~jb8ZVfQ3b1933419334epcas2p14; Mon, 20 Jul 2020 10:39:50 +0000 (GMT) Received: from epsmgms1p1new.samsung.com (unknown [182.195.42.41]) by epsmtrp1.samsung.com (KnoxPortal) with ESMTP id 20200720103950epsmtrp1e9ebd6ea6e39829ee7461fd09a045c6b~jb8ZUzNc_1624116241epsmtrp1i; Mon, 20 Jul 2020 10:39:50 +0000 (GMT) X-AuditID: b6c32a47-fafff70000006b31-0c-5f157476fa62 Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgms1p1new.samsung.com (Symantec Messaging Gateway) with SMTP id 7B.45.08382.674751F5; Mon, 20 Jul 2020 19:39:50 +0900 (KST) Received: from rack03.dsn.sec.samsung.com (unknown [12.36.155.109]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20200720103950epsmtip26b3b661f438aef171a3bae57d94ca6fe~jb8ZIFvb90949409494epsmtip2n; Mon, 20 Jul 2020 10:39:50 +0000 (GMT) From: SEO HOYOUNG To: linux-scsi@vger.kernel.org, alim.akhtar@samsung.com, avri.altman@wdc.com, jejb@linux.ibm.com, martin.petersen@oracle.com, beanhuo@micron.com, asutoshd@codeaurora.org, cang@codeaurora.org, bvanassche@acm.org, grant.jung@samsung.com Cc: SEO HOYOUNG Subject: [RFC PATCH v2 2/3] scsi: ufs: modify function call name When ufs reset and restore, need to disable write booster Date: Mon, 20 Jul 2020 19:40:12 +0900 Message-Id: <98b5339dc9c5dc57ed72e83bc7c39c4211d20b6a.1595240433.git.hy50.seo@samsung.com> X-Mailer: git-send-email 2.26.0 In-Reply-To: MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrPJsWRmVeSWpSXmKPExsWy7bCmqW5ZiWi8wb4ZlhYP5m1js9jbdoLd 4uXPq2wWBx92slhM+/CT2eLT+mWsFr/+rme3WL34AYvFohvbmCy6r+9gs1h+/B+TA7fH5Sve Hpf7epk8Jiw6wOjxfX0Hm8fHp7dYPPq2rGL0+LxJzqP9QDdTAEdUjk1GamJKapFCal5yfkpm XrqtkndwvHO8qZmBoa6hpYW5kkJeYm6qrZKLT4CuW2YO0KFKCmWJOaVAoYDE4mIlfTubovzS klSFjPziElul1IKUnAJDwwK94sTc4tK8dL3k/FwrQwMDI1OgyoScjL1X5jMWPOWoeLr9FmsD 4272LkYODgkBE4knzVFdjF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+/B+TA7fH5Sve Hpf7epk8Jiw6wOjxfX0Hm8fHp7dYPPq2rGL0+LxJzqP9QDdTAEcUl01Kak5mWWqRvl0CV8be K/MZC55yVDzdfou1gXE3excjJ4eEgInE7x9fGbsYuTiEBHYzSszdcw8qISHxf3ETE4QtLHG/ 5QgrRNE3RonbExaxgSTYBDQk1hw7BFYkIvCHUWLS6TgQm1lATeLz3WUsILawQJXE7vOTwYay CKhKbJzyAyzOKxAl0fF1EtQCeYlFDb/BbE4BC4k5Gx+BzRcSMJc4v6uRGaJeUOLkzCcsEPPl JZq3zmaewCgwC0lqFpLUAkamVYySqQXFuem5xYYFhnmp5XrFibnFpXnpesn5uZsYwbGhpbmD cfuqD3qHGJk4GA8xSnAwK4nwTuQRjhfiTUmsrEotyo8vKs1JLT7EKM3BoiTOe6NwYZyQQHpi SWp2ampBahFMlomDU6qBabeqPu+91Os/cjtke5P6Z71Vyvt1I3+dgnblnhm8Ya5uwpPb7y5J 6LaZd3OTVUY6uzv3v/dbbvpv4pW/ablq/UJ9Nv1FR6d0ni+Vm1watD9V8Of9pu9Or4wnxii9 u15y/m5e1L7v9x5brXxytmH71wih4vrPjssEi0N16uwvOK1+cL8ooUXmiYHQA2Z51tlyyXun XT1y2zCVl+mB2c7HqUoJG95ND5n6UFv5wted37czmB1bu/qFFsuPCulA8YLt9VHBBS+c7S5f Pyu6VCa06NnHRu/NvxcI7azapGH1la/hUf+5kwodRrf1ZQxP/mef02wUvjT7zrd3N/j+n32Y /NFMcla67+7gfdbR19iuJCmxFGckGmoxFxUnAgAbiohy/AIAAA== X-CMS-MailID: 20200720103950epcas2p16278643a6f62b446b653c834de448543 X-Msg-Generator: CA X-Sendblock-Type: AUTO_CONFIDENTIAL CMS-TYPE: 102P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20200720103950epcas2p16278643a6f62b446b653c834de448543 References: Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Signed-off-by: SEO HOYOUNG --- drivers/scsi/ufs/ufshcd.c | 2 +- drivers/scsi/ufs/ufshcd.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index efa16bf4fd76..419d3dd7e183 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -6615,7 +6615,7 @@ static int ufshcd_reset_and_restore(struct ufs_hba *hba) int err = 0; int retries = MAX_HOST_RESET_RETRIES; - ufshcd_reset_vendor(hba); + ufshcd_wb_reset_vendor(hba); do { /* Reset the attached device */ diff --git a/drivers/scsi/ufs/ufshcd.h b/drivers/scsi/ufs/ufshcd.h index deb9577e0eaa..61ae5259c62a 100644 --- a/drivers/scsi/ufs/ufshcd.h +++ b/drivers/scsi/ufs/ufshcd.h @@ -1217,7 +1217,7 @@ static int ufshcd_wb_ctrl_vendor(struct ufs_hba *hba, bool enable) return hba->wb_ops->wb_ctrl_vendor(hba, enable); } -static int ufshcd_reset_vendor(struct ufs_hba *hba) +static int ufshcd_wb_reset_vendor(struct ufs_hba *hba) { if (!hba->wb_ops || !hba->wb_ops->wb_reset_vendor) return -1; From patchwork Mon Jul 20 10:40:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SEO HOYOUNG X-Patchwork-Id: 11673467 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 4B9726C1 for ; Mon, 20 Jul 2020 10:40:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2B1D422BF3 for ; Mon, 20 Jul 2020 10:40:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="fqKv0tD3" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728444AbgGTKkB (ORCPT ); Mon, 20 Jul 2020 06:40:01 -0400 Received: from mailout4.samsung.com ([203.254.224.34]:41880 "EHLO mailout4.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728419AbgGTKkA (ORCPT ); Mon, 20 Jul 2020 06:40:00 -0400 Received: from epcas2p2.samsung.com (unknown [182.195.41.54]) by mailout4.samsung.com (KnoxPortal) with ESMTP id 20200720103955epoutp04b5195427fdc4f87e804df6add6fdb779~jb8d-u8N33188231882epoutp04j for ; Mon, 20 Jul 2020 10:39:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout4.samsung.com 20200720103955epoutp04b5195427fdc4f87e804df6add6fdb779~jb8d-u8N33188231882epoutp04j DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1595241595; bh=EuJB1xrfeujR6eUit1EgR6dmpQuSU8qWpNo3MsQhUwk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fqKv0tD3s7ePTosXhEzFysNsEn9RcECLn9N4jugPY05W1o4HnkNzwh83grLwmwkok doQ4yCxFgSi99cCxNhV7psPs2GQMSGYsENYI255t5xCStaC8AypA5WM04kxiitduBm y7+tDwXAXsIwEb7xRY5J153JJFtR6N2dbov1gxq0= Received: from epsnrtp4.localdomain (unknown [182.195.42.165]) by epcas2p4.samsung.com (KnoxPortal) with ESMTP id 20200720103955epcas2p4a9ae20756e5a1f5467365a962bdc297c~jb8dkiXnP1702317023epcas2p47; Mon, 20 Jul 2020 10:39:55 +0000 (GMT) Received: from epsmges2p4.samsung.com (unknown [182.195.40.183]) by epsnrtp4.localdomain (Postfix) with ESMTP id 4B9JBw2XbXzMqYkd; Mon, 20 Jul 2020 10:39:52 +0000 (GMT) Received: from epcas2p4.samsung.com ( [182.195.41.56]) by epsmges2p4.samsung.com (Symantec Messaging Gateway) with SMTP id 36.AD.27013.874751F5; Mon, 20 Jul 2020 19:39:52 +0900 (KST) Received: from epsmtrp1.samsung.com (unknown [182.195.40.13]) by epcas2p2.samsung.com (KnoxPortal) with ESMTPA id 20200720103951epcas2p246072985a70a459f0acb31d339298a47~jb8aPYfiv0180201802epcas2p2Q; Mon, 20 Jul 2020 10:39:51 +0000 (GMT) Received: from epsmgms1p2.samsung.com (unknown [182.195.42.42]) by epsmtrp1.samsung.com (KnoxPortal) with ESMTP id 20200720103951epsmtrp1edf80d2712371739ef98b93ed7c5d071~jb8aOqShr1624216242epsmtrp1g; Mon, 20 Jul 2020 10:39:51 +0000 (GMT) X-AuditID: b6c32a48-d35ff70000006985-02-5f1574783146 Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgms1p2.samsung.com (Symantec Messaging Gateway) with SMTP id F4.3D.08303.774751F5; Mon, 20 Jul 2020 19:39:51 +0900 (KST) Received: from rack03.dsn.sec.samsung.com (unknown [12.36.155.109]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20200720103951epsmtip23343784f1a7bd140dbadf19da1478657~jb8Z-eVTF0943709437epsmtip2y; Mon, 20 Jul 2020 10:39:51 +0000 (GMT) From: SEO HOYOUNG To: linux-scsi@vger.kernel.org, alim.akhtar@samsung.com, avri.altman@wdc.com, jejb@linux.ibm.com, martin.petersen@oracle.com, beanhuo@micron.com, asutoshd@codeaurora.org, cang@codeaurora.org, bvanassche@acm.org, grant.jung@samsung.com Cc: SEO HOYOUNG Subject: [RFC PATCH v2 3/3] scsi: ufs: add vendor specific write booster To support the fuction of writebooster by vendor. The WB behavior that the vendor wants is slightly different. But we have to support it Date: Mon, 20 Jul 2020 19:40:13 +0900 Message-Id: <5be595eb83365ec97a8ee0ddafb748029ee8cdf9.1595240433.git.hy50.seo@samsung.com> X-Mailer: git-send-email 2.26.0 In-Reply-To: MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrAJsWRmVeSWpSXmKPExsWy7bCmhW5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dft08BXT+X1bFv/7WPbUTupMR8Cs5okF04/bFZ2NkPgqKp8gtuSs/PuVuv15T6zbbNPnff7U njF78bOGcxVJ91ZLbFQVY3OvuPNLiaU4I9FQi7moOBEA7bCPXP0CAAA= X-CMS-MailID: 20200720103951epcas2p246072985a70a459f0acb31d339298a47 X-Msg-Generator: CA X-Sendblock-Type: AUTO_CONFIDENTIAL CMS-TYPE: 102P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20200720103951epcas2p246072985a70a459f0acb31d339298a47 References: Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Signed-off-by: SEO HOYOUNG --- drivers/scsi/ufs/Makefile | 1 + drivers/scsi/ufs/ufs-exynos.c | 6 + drivers/scsi/ufs/ufs_ctmwb.c | 279 ++++++++++++++++++++++++++++++++++ drivers/scsi/ufs/ufs_ctmwb.h | 27 ++++ 4 files changed, 313 insertions(+) create mode 100644 drivers/scsi/ufs/ufs_ctmwb.c create mode 100644 drivers/scsi/ufs/ufs_ctmwb.h diff --git a/drivers/scsi/ufs/Makefile b/drivers/scsi/ufs/Makefile index 9810963bc049..b1ba36c7d66f 100644 --- a/drivers/scsi/ufs/Makefile +++ b/drivers/scsi/ufs/Makefile @@ -5,6 +5,7 @@ obj-$(CONFIG_SCSI_UFS_DWC_TC_PLATFORM) += tc-dwc-g210-pltfrm.o ufshcd-dwc.o tc-d obj-$(CONFIG_SCSI_UFS_CDNS_PLATFORM) += cdns-pltfrm.o obj-$(CONFIG_SCSI_UFS_QCOM) += ufs-qcom.o obj-$(CONFIG_SCSI_UFS_EXYNOS) += ufs-exynos.o +obj-$(CONFIG_SCSI_UFS_VENDOR_WB) += ufs_ctmwb.o obj-$(CONFIG_SCSI_UFSHCD) += ufshcd-core.o ufshcd-core-y += ufshcd.o ufs-sysfs.o ufshcd-core-$(CONFIG_SCSI_UFS_BSG) += ufs_bsg.o diff --git a/drivers/scsi/ufs/ufs-exynos.c b/drivers/scsi/ufs/ufs-exynos.c index 32b61ba77241..f127f5f2bf36 100644 --- a/drivers/scsi/ufs/ufs-exynos.c +++ b/drivers/scsi/ufs/ufs-exynos.c @@ -22,6 +22,9 @@ #include "ufs-exynos.h" +#ifdef CONFIG_SCSI_UFS_VENDOR_WB +#include "ufs_ctmwb.h" +#endif /* * Exynos's Vendor specific registers for UFSHCI */ @@ -989,6 +992,9 @@ static int exynos_ufs_init(struct ufs_hba *hba) goto phy_off; ufs->hba = hba; +#ifdef CONFIG_SCSI_UFS_VENDOR_WB + ufs->hba->wb_ops = ufshcd_ctmwb_init(); +#endif ufs->opts = ufs->drv_data->opts; ufs->rx_sel_idx = PA_MAXDATALANES; if (ufs->opts & EXYNOS_UFS_OPT_BROKEN_RX_SEL_IDX) diff --git a/drivers/scsi/ufs/ufs_ctmwb.c b/drivers/scsi/ufs/ufs_ctmwb.c new file mode 100644 index 000000000000..ab39f40721ae --- /dev/null +++ b/drivers/scsi/ufs/ufs_ctmwb.c @@ -0,0 +1,279 @@ +#include "ufshcd.h" +#include "ufshci.h" +#include "ufs_ctmwb.h" + +static struct ufshba_ctmwb hba_ctmwb; + +/* Query request retries */ +#define QUERY_REQ_RETRIES 3 + +static int ufshcd_query_attr_retry(struct ufs_hba *hba, + enum query_opcode opcode, enum attr_idn idn, u8 index, u8 selector, + u32 *attr_val) +{ + int ret = 0; + u32 retries; + + for (retries = QUERY_REQ_RETRIES; retries > 0; retries--) { + ret = ufshcd_query_attr(hba, opcode, idn, index, + selector, attr_val); + if (ret) + dev_dbg(hba->dev, "%s: failed with error %d, retries %d\n", + __func__, ret, retries); + else + break; + } + + if (ret) + dev_err(hba->dev, + "%s: query attribute, idn %d, failed with error %d after %d retires\n", + __func__, idn, ret, QUERY_REQ_RETRIES); + return ret; +} + +static int ufshcd_query_flag_retry(struct ufs_hba *hba, + enum query_opcode opcode, enum flag_idn idn, bool *flag_res) +{ + int ret; + int retries; + + for (retries = 0; retries < QUERY_REQ_RETRIES; retries++) { + ret = ufshcd_query_flag(hba, opcode, idn, flag_res); + if (ret) + dev_dbg(hba->dev, + "%s: failed with error %d, retries %d\n", + __func__, ret, retries); + else + break; + } + + if (ret) + dev_err(hba->dev, + "%s: query attribute, opcode %d, idn %d, failed with error %d after %d retries\n", + __func__, (int)opcode, (int)idn, ret, retries); + return ret; +} + +static int ufshcd_reset_ctmwb(struct ufs_hba *hba, bool force) +{ + int err = 0; + + if (!hba_ctmwb.support_ctmwb) + return 0; + + if (ufshcd_is_ctmwb_off(hba_ctmwb)) { + dev_info(hba->dev, "%s: turbo write already disabled. ctmwb_state = %d\n", + __func__, hba_ctmwb.ufs_ctmwb_state); + return 0; + } + + if (ufshcd_is_ctmwb_err(hba_ctmwb)) + dev_err(hba->dev, "%s: previous turbo write control was failed.\n", + __func__); + + if (force) + err = ufshcd_query_flag_retry(hba, UPIU_QUERY_OPCODE_CLEAR_FLAG, + QUERY_FLAG_IDN_WB_EN, NULL); + + if (err) { + ufshcd_set_ctmwb_err(hba_ctmwb); + dev_err(hba->dev, "%s: disable turbo write failed. err = %d\n", + __func__, err); + } else { + ufshcd_set_ctmwb_off(hba_ctmwb); + dev_info(hba->dev, "%s: ufs turbo write disabled \n", __func__); + } + + return 0; +} + +static int ufshcd_get_ctmwb_buf_status(struct ufs_hba *hba, u32 *status) +{ + return ufshcd_query_attr_retry(hba, UPIU_QUERY_OPCODE_READ_ATTR, + QUERY_ATTR_IDN_AVAIL_WB_BUFF_SIZE, 0, 0, status); +} + +static int ufshcd_ctmwb_manual_flush_ctrl(struct ufs_hba *hba, int en) +{ + int err = 0; + + dev_info(hba->dev, "%s: %sable turbo write manual flush\n", + __func__, en ? "en" : "dis"); + if (en) { + err = ufshcd_query_flag_retry(hba, UPIU_QUERY_OPCODE_SET_FLAG, + QUERY_FLAG_IDN_WB_BUFF_FLUSH_EN, NULL); + if (err) + dev_err(hba->dev, "%s: enable turbo write failed. err = %d\n", + __func__, err); + } else { + err = ufshcd_query_flag_retry(hba, UPIU_QUERY_OPCODE_CLEAR_FLAG, + QUERY_FLAG_IDN_WB_BUFF_FLUSH_EN, NULL); + if (err) + dev_err(hba->dev, "%s: disable turbo write failed. err = %d\n", + __func__, err); + } + + return err; +} + +static int ufshcd_ctmwb_flush_ctrl(struct ufs_hba *hba) +{ + int err = 0; + u32 curr_status = 0; + + err = ufshcd_get_ctmwb_buf_status(hba, &curr_status); + + if (!err && (curr_status <= UFS_WB_MANUAL_FLUSH_THRESHOLD)) { + dev_info(hba->dev, "%s: enable ctmwb manual flush, buf status : %d\n", + __func__, curr_status); + scsi_block_requests(hba->host); + err = ufshcd_ctmwb_manual_flush_ctrl(hba, 1); + if (!err) { + mdelay(100); + err = ufshcd_ctmwb_manual_flush_ctrl(hba, 0); + if (err) + dev_err(hba->dev, "%s: disable ctmwb manual flush failed. err = %d\n", + __func__, err); + } else + dev_err(hba->dev, "%s: enable ctmwb manual flush failed. err = %d\n", + __func__, err); + scsi_unblock_requests(hba->host); + } + return err; +} + +static int ufshcd_ctmwb_ctrl(struct ufs_hba *hba, bool enable) +{ + int err; +#if 0 + if (!hba->support_ctmwb) + return; + + if (hba->pm_op_in_progress) { + dev_err(hba->dev, "%s: ctmwb ctrl during pm operation is not allowed.\n", + __func__); + return; + } + + if (hba->ufshcd_state != UFSHCD_STATE_OPERATIONAL) { + dev_err(hba->dev, "%s: ufs host is not available.\n", + __func__); + return; + } + if (ufshcd_is_ctmwb_err(hba_ctmwb)) + dev_err(hba->dev, "%s: previous turbo write control was failed.\n", + __func__); +#endif + if (enable) { + if (ufshcd_is_ctmwb_on(hba_ctmwb)) { + dev_err(hba->dev, "%s: turbo write already enabled. ctmwb_state = %d\n", + __func__, hba_ctmwb.ufs_ctmwb_state); + return 0; + } + pm_runtime_get_sync(hba->dev); + err = ufshcd_query_flag_retry(hba, UPIU_QUERY_OPCODE_SET_FLAG, + QUERY_FLAG_IDN_WB_EN, NULL); + if (err) { + ufshcd_set_ctmwb_err(hba_ctmwb); + dev_err(hba->dev, "%s: enable turbo write failed. err = %d\n", + __func__, err); + } else { + ufshcd_set_ctmwb_on(hba_ctmwb); + dev_info(hba->dev, "%s: ufs turbo write enabled \n", __func__); + } + } else { + if (ufshcd_is_ctmwb_off(hba_ctmwb)) { + dev_err(hba->dev, "%s: turbo write already disabled. ctmwb_state = %d\n", + __func__, hba_ctmwb.ufs_ctmwb_state); + return 0; + } + pm_runtime_get_sync(hba->dev); + err = ufshcd_query_flag_retry(hba, UPIU_QUERY_OPCODE_CLEAR_FLAG, + QUERY_FLAG_IDN_WB_EN, NULL); + if (err) { + ufshcd_set_ctmwb_err(hba_ctmwb); + dev_err(hba->dev, "%s: disable turbo write failed. err = %d\n", + __func__, err); + } else { + ufshcd_set_ctmwb_off(hba_ctmwb); + dev_info(hba->dev, "%s: ufs turbo write disabled \n", __func__); + } + } + + pm_runtime_put_sync(hba->dev); + + return 0; +} + +/** + * ufshcd_get_ctmwbbuf_unit - get ctmwb buffer alloc units + * @sdev: pointer to SCSI device + * + * Read dLUNumTurboWriteBufferAllocUnits in UNIT Descriptor + * to check if LU supports turbo write feature + */ +static int ufshcd_get_ctmwbbuf_unit(struct ufs_hba *hba) +{ + struct scsi_device *sdev = hba->sdev_ufs_device; + struct ufshba_ctmwb *hba_ctmwb = (struct ufshba_ctmwb *)hba->wb_ops; + int ret = 0; + + u32 dLUNumTurboWriteBufferAllocUnits = 0; + u8 desc_buf[4]; + + if (!hba_ctmwb->support_ctmwb) + return 0; + + ret = ufshcd_read_unit_desc_param(hba, + ufshcd_scsi_to_upiu_lun(sdev->lun), + UNIT_DESC_PARAM_WB_BUF_ALLOC_UNITS, + desc_buf, + sizeof(dLUNumTurboWriteBufferAllocUnits)); + + /* Some WLUN doesn't support unit descriptor */ + if ((ret == -EOPNOTSUPP) || scsi_is_wlun(sdev->lun)){ + hba_ctmwb->support_ctmwb_lu = false; + dev_info(hba->dev,"%s: do not support WB\n", __func__); + return 0; + } + + dLUNumTurboWriteBufferAllocUnits = ((desc_buf[0] << 24)| + (desc_buf[1] << 16) | + (desc_buf[2] << 8) | + desc_buf[3]); + + if (dLUNumTurboWriteBufferAllocUnits) { + hba_ctmwb->support_ctmwb_lu = true; + dev_info(hba->dev, "%s: LU %d supports ctmwb, ctmwbbuf unit : 0x%x\n", + __func__, (int)sdev->lun, dLUNumTurboWriteBufferAllocUnits); + } else + hba_ctmwb->support_ctmwb_lu = false; + + return 0; +} + +static inline int ufshcd_ctmwb_toggle_flush(struct ufs_hba *hba, enum ufs_pm_op pm_op) +{ + ufshcd_ctmwb_flush_ctrl(hba); + + if (ufshcd_is_system_pm(pm_op)) + ufshcd_reset_ctmwb(hba, true); + + return 0; +} + +static struct ufs_wb_ops exynos_ctmwb_ops = { + .wb_toggle_flush_vendor = ufshcd_ctmwb_toggle_flush, + .wb_alloc_units_vendor = ufshcd_get_ctmwbbuf_unit, + .wb_ctrl_vendor = ufshcd_ctmwb_ctrl, + .wb_reset_vendor = ufshcd_reset_ctmwb, +}; + +struct ufs_wb_ops *ufshcd_ctmwb_init(void) +{ + hba_ctmwb.support_ctmwb = 1; + + return &exynos_ctmwb_ops; +} +EXPORT_SYMBOL_GPL(ufshcd_ctmwb_init); + diff --git a/drivers/scsi/ufs/ufs_ctmwb.h b/drivers/scsi/ufs/ufs_ctmwb.h new file mode 100644 index 000000000000..073e21a4900b --- /dev/null +++ b/drivers/scsi/ufs/ufs_ctmwb.h @@ -0,0 +1,27 @@ +#ifndef _UFS_CTMWB_H_ +#define _UFS_CTMWB_H_ + +enum ufs_ctmwb_state { + UFS_WB_OFF_STATE = 0, /* turbo write disabled state */ + UFS_WB_ON_STATE = 1, /* turbo write enabled state */ + UFS_WB_ERR_STATE = 2, /* turbo write error state */ +}; + +#define ufshcd_is_ctmwb_off(hba) ((hba).ufs_ctmwb_state == UFS_WB_OFF_STATE) +#define ufshcd_is_ctmwb_on(hba) ((hba).ufs_ctmwb_state == UFS_WB_ON_STATE) +#define ufshcd_is_ctmwb_err(hba) ((hba).ufs_ctmwb_state == UFS_WB_ERR_STATE) +#define ufshcd_set_ctmwb_off(hba) ((hba).ufs_ctmwb_state = UFS_WB_OFF_STATE) +#define ufshcd_set_ctmwb_on(hba) ((hba).ufs_ctmwb_state = UFS_WB_ON_STATE) +#define ufshcd_set_ctmwb_err(hba) ((hba).ufs_ctmwb_state = UFS_WB_ERR_STATE) + +#define UFS_WB_MANUAL_FLUSH_THRESHOLD 5 + +struct ufshba_ctmwb { + enum ufs_ctmwb_state ufs_ctmwb_state; + bool support_ctmwb; + + bool support_ctmwb_lu; +}; + +struct ufs_wb_ops *ufshcd_ctmwb_init(void); +#endif