From patchwork Sat May 30 15:13:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanley Chu X-Patchwork-Id: 11580459 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 1D0201391 for ; Sat, 30 May 2020 15:13:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EDE452081A for ; Sat, 30 May 2020 15:13:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="Za6SzSBV" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729095AbgE3PNz (ORCPT ); Sat, 30 May 2020 11:13:55 -0400 Received: from mailgw01.mediatek.com ([210.61.82.183]:32535 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1728989AbgE3PNy (ORCPT ); Sat, 30 May 2020 11:13:54 -0400 X-UUID: 3e742bac3b94497687f8547066c3a365-20200530 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=zs+0w6nLPCOoHeMZRQqu4tfYpdiCBTOiMbmuhn2fSSA=; b=Za6SzSBVD07QQQKOooZ9IGD/6meVbqGw+Jkiyb3Fd5LsMazvqtiYCHGZ9safLXcV42dZR8ADnMigVDj0RgnKCiuDYgbsVHxJige64Rei9ds1NGmRTXyqsGVgBEMHZu2HlBinVuPsDkhlAFqC6B3VRYW9VEsTSB/1D6xu2uhzQnA=; X-UUID: 3e742bac3b94497687f8547066c3a365-20200530 Received: from mtkexhb01.mediatek.inc [(172.21.101.102)] by mailgw01.mediatek.com (envelope-from ) (Cellopoint E-mail Firewall v4.1.10 Build 0809 with TLS) with ESMTP id 19106460; Sat, 30 May 2020 23:13:47 +0800 Received: from mtkcas08.mediatek.inc (172.21.101.126) by mtkmbs02n1.mediatek.inc (172.21.101.77) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Sat, 30 May 2020 23:13:36 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkcas08.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Sat, 30 May 2020 23:13:36 +0800 From: Stanley Chu To: , , , , CC: , , , , , , , , , , , , , , Stanley Chu Subject: [PATCH v1 1/2] scsi: ufs: Support WriteBooster on Samsung UFS devices Date: Sat, 30 May 2020 23:13:36 +0800 Message-ID: <20200530151337.6182-2-stanley.chu@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20200530151337.6182-1-stanley.chu@mediatek.com> References: <20200530151337.6182-1-stanley.chu@mediatek.com> MIME-Version: 1.0 X-MTK: N Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Samsung UFS devices are widely used in the market, however these devices need some special handling to support WriteBooster. The major part is that Samsung UFS devices need to use specific "selector" value for WriteBooster related query operations. Therefore, introduce a device quirk to handle the special requirement and then WriteBooster can be enabled on these devices. Signed-off-by: Stanley Chu --- drivers/scsi/ufs/ufs-sysfs.c | 12 ---------- drivers/scsi/ufs/ufs.h | 1 + drivers/scsi/ufs/ufs_quirks.h | 7 ++++++ drivers/scsi/ufs/ufshcd.c | 43 ++++++++++++++++++++++++++++++++++- drivers/scsi/ufs/ufshcd.h | 20 ++++++++++++++++ 5 files changed, 70 insertions(+), 13 deletions(-) diff --git a/drivers/scsi/ufs/ufs-sysfs.c b/drivers/scsi/ufs/ufs-sysfs.c index 2d71d232a69d..fa5fdfcd2611 100644 --- a/drivers/scsi/ufs/ufs-sysfs.c +++ b/drivers/scsi/ufs/ufs-sysfs.c @@ -622,12 +622,6 @@ static const struct attribute_group ufs_sysfs_string_descriptors_group = { .attrs = ufs_sysfs_string_descriptors, }; -static inline bool ufshcd_is_wb_flags(enum flag_idn idn) -{ - return ((idn >= QUERY_FLAG_IDN_WB_EN) && - (idn <= QUERY_FLAG_IDN_WB_BUFF_FLUSH_DURING_HIBERN8)); -} - #define UFS_FLAG(_name, _uname) \ static ssize_t _name##_show(struct device *dev, \ struct device_attribute *attr, char *buf) \ @@ -680,12 +674,6 @@ static const struct attribute_group ufs_sysfs_flags_group = { .attrs = ufs_sysfs_device_flags, }; -static inline bool ufshcd_is_wb_attrs(enum attr_idn idn) -{ - return ((idn >= QUERY_ATTR_IDN_WB_FLUSH_STATUS) && - (idn <= QUERY_ATTR_IDN_CURR_WB_BUFF_SIZE)); -} - #define UFS_ATTRIBUTE(_name, _uname) \ static ssize_t _name##_show(struct device *dev, \ struct device_attribute *attr, char *buf) \ diff --git a/drivers/scsi/ufs/ufs.h b/drivers/scsi/ufs/ufs.h index c70845d41449..88ec87e2811c 100644 --- a/drivers/scsi/ufs/ufs.h +++ b/drivers/scsi/ufs/ufs.h @@ -61,6 +61,7 @@ * This means max. LUN number reported from UFS device could be 0xC17F. */ #define UFS_UPIU_MAX_UNIT_NUM_ID 0x7F +#define UFS_UPIU_RPMB_QUERY_INDEX 0xC4 #define UFS_MAX_LUNS (SCSI_W_LUN_BASE + UFS_UPIU_MAX_UNIT_NUM_ID) #define UFS_UPIU_WLUN_ID (1 << 7) diff --git a/drivers/scsi/ufs/ufs_quirks.h b/drivers/scsi/ufs/ufs_quirks.h index e3175a63c676..f9ed868cf330 100644 --- a/drivers/scsi/ufs/ufs_quirks.h +++ b/drivers/scsi/ufs/ufs_quirks.h @@ -108,4 +108,11 @@ struct ufs_dev_fix { */ #define UFS_DEVICE_QUIRK_SUPPORT_EXTENDED_FEATURES (1 << 10) +/* + * Some UFS devices need to use special selector to operate WriteBooster + * related flags and attributes. Enable this quirk to make these devices + * work normally. + */ +#define UFS_DEVICE_QUIRK_WB_SPECIAL_SELECTOR (1 << 11) + #endif /* UFS_QUIRKS_H_ */ diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index f11be69e50e9..5e38c471877c 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -2801,11 +2801,17 @@ int ufshcd_query_flag(struct ufs_hba *hba, enum query_opcode opcode, { struct ufs_query_req *request = NULL; struct ufs_query_res *response = NULL; - int err, selector = 0; + int err; int timeout = QUERY_REQ_TIMEOUT; + u8 selector = 0; BUG_ON(!hba); + if (hba->dev_quirks & UFS_DEVICE_QUIRK_WB_SPECIAL_SELECTOR) { + if (ufshcd_is_wb_flags(idn)) + selector = 1; + } + ufshcd_hold(hba, false); mutex_lock(&hba->dev_cmd.lock); ufshcd_init_query(hba, &request, &response, opcode, idn, index, @@ -2882,6 +2888,11 @@ int ufshcd_query_attr(struct ufs_hba *hba, enum query_opcode opcode, goto out; } + if (hba->dev_quirks & UFS_DEVICE_QUIRK_WB_SPECIAL_SELECTOR) { + if (ufshcd_is_wb_attrs(idn)) + selector = 1; + } + mutex_lock(&hba->dev_cmd.lock); ufshcd_init_query(hba, &request, &response, opcode, idn, index, selector); @@ -3042,6 +3053,11 @@ int ufshcd_query_descriptor_retry(struct ufs_hba *hba, int err; int retries; + if (hba->dev_quirks & UFS_DEVICE_QUIRK_WB_SPECIAL_SELECTOR) { + if (ufshcd_is_wb_desc(idn, index)) + selector = 1; + } + for (retries = QUERY_REQ_RETRIES; retries > 0; retries--) { err = __ufshcd_query_descriptor(hba, opcode, idn, index, selector, desc_buf, buf_len); @@ -6907,8 +6923,10 @@ static int ufs_get_device_desc(struct ufs_hba *hba) size_t buff_len; u8 model_index; u8 *desc_buf; + u8 retry_cnt = 0; struct ufs_dev_info *dev_info = &hba->dev_info; +retry: buff_len = max_t(size_t, hba->desc_size.dev_desc, QUERY_DESC_MAX_SIZE + 1); desc_buf = kmalloc(buff_len, GFP_KERNEL); @@ -6948,6 +6966,29 @@ static int ufs_get_device_desc(struct ufs_hba *hba) ufs_fixup_device_setup(hba); + if (!retry_cnt && (hba->dev_quirks & + UFS_DEVICE_QUIRK_WB_SPECIAL_SELECTOR)) { + /* + * Update WriteBooster related descriptor length with specific + * seletor used. + */ + ufshcd_read_desc_length(hba, QUERY_DESC_IDN_DEVICE, 0, + &hba->desc_size.dev_desc); + ufshcd_read_desc_length(hba, QUERY_DESC_IDN_CONFIGURATION, 0, + &hba->desc_size.conf_desc); + ufshcd_read_desc_length(hba, QUERY_DESC_IDN_UNIT, 0, + &hba->desc_size.unit_desc); + ufshcd_read_desc_length(hba, QUERY_DESC_IDN_GEOMETRY, 0, + &hba->desc_size.geom_desc); + /* + * Read device descriptor again with specific selector used to + * get WriteBooster related fileds. + */ + kfree(desc_buf); + retry_cnt++; + goto retry; + } + /* * Probe WB only for UFS-3.1 devices or UFS devices with quirk * UFS_DEVICE_QUIRK_SUPPORT_EXTENDED_FEATURES enabled diff --git a/drivers/scsi/ufs/ufshcd.h b/drivers/scsi/ufs/ufshcd.h index bf97d616e597..d850c47e8ae0 100644 --- a/drivers/scsi/ufs/ufshcd.h +++ b/drivers/scsi/ufs/ufshcd.h @@ -876,6 +876,26 @@ static inline u8 ufshcd_wb_get_query_index(struct ufs_hba *hba) return 0; } +static inline bool ufshcd_is_wb_attrs(enum attr_idn idn) +{ + return ((idn >= QUERY_ATTR_IDN_WB_FLUSH_STATUS) && + (idn <= QUERY_ATTR_IDN_CURR_WB_BUFF_SIZE)); +} + +static inline bool ufshcd_is_wb_desc(enum desc_idn idn, u8 index) +{ + return (idn <= QUERY_DESC_IDN_CONFIGURATION) || + ((idn == QUERY_DESC_IDN_UNIT) && + (index != UFS_UPIU_RPMB_QUERY_INDEX)) || + (idn == QUERY_DESC_IDN_GEOMETRY); +} + +static inline bool ufshcd_is_wb_flags(enum flag_idn idn) +{ + return ((idn >= QUERY_FLAG_IDN_WB_EN) && + (idn <= QUERY_FLAG_IDN_WB_BUFF_FLUSH_DURING_HIBERN8)); +} + extern int ufshcd_runtime_suspend(struct ufs_hba *hba); extern int ufshcd_runtime_resume(struct ufs_hba *hba); extern int ufshcd_runtime_idle(struct ufs_hba *hba); From patchwork Sat May 30 15:13:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanley Chu X-Patchwork-Id: 11580461 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 47435166C for ; Sat, 30 May 2020 15:13:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 22ACD207D5 for ; Sat, 30 May 2020 15:13:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="Kza9OG7A" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729123AbgE3PN6 (ORCPT ); Sat, 30 May 2020 11:13:58 -0400 Received: from mailgw02.mediatek.com ([210.61.82.184]:57381 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1728927AbgE3PNz (ORCPT ); Sat, 30 May 2020 11:13:55 -0400 X-UUID: 3f1c7e5bf82a4482ac02fdac71eec81b-20200530 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=SPJ40cDjqiU6ZOCt6LvTtGZM/kEwgPDknQLr1x5cZfY=; b=Kza9OG7AGv27NbJbLE9OIiD+PFPwgDGluPkAC3Im8IQv9jDqOzohNkWZM/9L7oJPBaYnu85pfTndcy0E82Xb0Q0veNl8YsScOl/UtHcbGDESH1//7koFAAJ2gvtsCibjdetxPwVEZBVL7p0KrpyLjuRFDgF8LuLuYFQvDf+XMFI=; X-UUID: 3f1c7e5bf82a4482ac02fdac71eec81b-20200530 Received: from mtkexhb01.mediatek.inc [(172.21.101.102)] by mailgw02.mediatek.com (envelope-from ) (Cellopoint E-mail Firewall v4.1.10 Build 0809 with TLS) with ESMTP id 1014182968; Sat, 30 May 2020 23:13:51 +0800 Received: from mtkcas08.mediatek.inc (172.21.101.126) by mtkmbs02n2.mediatek.inc (172.21.101.101) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Sat, 30 May 2020 23:13:37 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkcas08.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Sat, 30 May 2020 23:13:37 +0800 From: Stanley Chu To: , , , , CC: , , , , , , , , , , , , , , Stanley Chu Subject: [PATCH v1 2/2] scsi: ufs-mediatek: Support WriteBooster on Samsung UFS devices Date: Sat, 30 May 2020 23:13:37 +0800 Message-ID: <20200530151337.6182-3-stanley.chu@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20200530151337.6182-1-stanley.chu@mediatek.com> References: <20200530151337.6182-1-stanley.chu@mediatek.com> MIME-Version: 1.0 X-TM-SNTS-SMTP: D9C1B2FE1DB9811E2C52585261D356E405E346685F5B7B75511E572B46C88C132000:8 X-MTK: N Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Add device quirk "UFS_DEVICE_QUIRK_WB_USING_SPECIAL_SELECTOR" on all Samsung UFS devices to enable WriteBooster on those devices. Signed-off-by: Stanley Chu --- drivers/scsi/ufs/ufs-mediatek.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/scsi/ufs/ufs-mediatek.c b/drivers/scsi/ufs/ufs-mediatek.c index d587b3276aa8..078a1e3d05d3 100644 --- a/drivers/scsi/ufs/ufs-mediatek.c +++ b/drivers/scsi/ufs/ufs-mediatek.c @@ -32,6 +32,9 @@ ufs_mtk_smc(UFS_MTK_SIP_DEVICE_RESET, high, res) static struct ufs_dev_fix ufs_mtk_dev_fixups[] = { + UFS_FIX(UFS_VENDOR_SAMSUNG, UFS_ANY_MODEL, + UFS_DEVICE_QUIRK_SUPPORT_EXTENDED_FEATURES | + UFS_DEVICE_QUIRK_WB_SPECIAL_SELECTOR), UFS_FIX(UFS_VENDOR_SKHYNIX, "H9HQ21AFAMZDAR", UFS_DEVICE_QUIRK_SUPPORT_EXTENDED_FEATURES), END_FIX