From patchwork Wed Aug 4 18:21:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bean Huo X-Patchwork-Id: 492008 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 46F79C4338F for ; Wed, 4 Aug 2021 18:21:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2B780610CD for ; Wed, 4 Aug 2021 18:21:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240208AbhHDSV4 (ORCPT ); Wed, 4 Aug 2021 14:21:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52268 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238225AbhHDSVy (ORCPT ); Wed, 4 Aug 2021 14:21:54 -0400 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 25B4CC06179E; Wed, 4 Aug 2021 11:21:40 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id n11so1728924wmd.2; Wed, 04 Aug 2021 11:21:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=X9/XirZyPGqfcWkK+RkVlCuaFc9xmCxe9G0B+gDsYv0=; b=ky2CiTZ9wjVXtdkptRoOWXQmScPD6SAaQUWeq/D/V+/qQ1fM2OQuy8ZbelPSbeaVAK ZTfL3IKxlnQizo7JEoqQwbxHvWNBNyrqbCHFQTfQ/izOMg7Too+Fa0hZhmjlEWkMBHJ1 CAqJZQ3KdJ9sU8nRbmDfM47ug2yJKME9K6oFt+69pth1EtcrUcUrgzoFjF4U8RV9p0PK zrQWYgkwdvgDquts2AoV6q12sWfy0nQu5x+JaTovrCENjRQ67vb+Jtn9wR/Qt/vIgewf IIDuzWPoqHTtZ9rFSopRu2Q2pM1FTPvMDKu9FehpY2r8QPuQsity8ynstddSFqsnODnp vYSQ== 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:mime-version:content-transfer-encoding; bh=X9/XirZyPGqfcWkK+RkVlCuaFc9xmCxe9G0B+gDsYv0=; b=J6wITgT2jRI6FWSNJ74wZsKjL8AU8c9p7ZCAWLTrMoTDZdhHjEUPfsejBNbFrMEw1l rQRXyvFrLEMnsQY/RAQPnbk3pstKdM9p8o4GmVmcQob02GtBQXXj3zsKsGZ0AZeKszfQ AX/Uxo+UMBgDi1QefK+1TF93R0EGZzEFw9sWCIydeIn4L1wU9SYaRHeEyiatT0POyTcc 9f6nWfBNR+VdIwJSMugcKY6YXZYSUF74NaXKuxZVgnJ6o6TVfqUaiQVTKG0GIUUcn3/1 PLSubGyVg2Yte4wDYpDIO66rqCfrUwViy10Pbu6tbLOLOU4RNzgv5Ju7Pmto/noVXSaH hk5g== X-Gm-Message-State: AOAM533Gy24xEt9D9l440qnlDcJ4g280P8TqPM0o3Vfo+HogOLDcT6MQ v/yBXjnEfgaLW+lEUrF9wW0= X-Google-Smtp-Source: ABdhPJztFy1g8TAyEPNqF2wldkPnT4N1xzOx4EfbYvqig+9IcCgBfIDyjwMOrtAInST6Gc+6LSZnHw== X-Received: by 2002:a1c:980e:: with SMTP id a14mr826899wme.123.1628101298817; Wed, 04 Aug 2021 11:21:38 -0700 (PDT) Received: from localhost.localdomain (ip5f5bfdd7.dynamic.kabel-deutschland.de. [95.91.253.215]) by smtp.gmail.com with ESMTPSA id n5sm2914880wme.47.2021.08.04.11.21.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Aug 2021 11:21:38 -0700 (PDT) From: Bean Huo To: alim.akhtar@samsung.com, avri.altman@wdc.com, asutoshd@codeaurora.org, jejb@linux.ibm.com, martin.petersen@oracle.com, stanley.chu@mediatek.com, beanhuo@micron.com, bvanassche@acm.org, cang@codeaurora.org, daejun7.park@samsung.com Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 1/2] scsi: ufs: Add L2P entry swap quirk for Micron UFS in HPB READ command Date: Wed, 4 Aug 2021 20:21:27 +0200 Message-Id: <20210804182128.458356-2-huobean@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210804182128.458356-1-huobean@gmail.com> References: <20210804182128.458356-1-huobean@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org From: Bean Huo For the Micron UFS, L2P entry need to be swapped in HPB READ command before sending HPB READ command to the UFS device. Add this quirk UFS_DEVICE_QUIRK_SWAP_L2P_ENTRY_FOR_HPB_READ to fix this inconsistency. Fixes: 2fff76f87542 ("scsi: ufs: ufshpb: Prepare HPB read for cached sub-region") Signed-off-by: Bean Huo Reviewed-by: Avri Altman --- drivers/scsi/ufs/ufs_quirks.h | 6 ++++++ drivers/scsi/ufs/ufshcd.c | 3 ++- drivers/scsi/ufs/ufshpb.c | 15 ++++++++++----- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/drivers/scsi/ufs/ufs_quirks.h b/drivers/scsi/ufs/ufs_quirks.h index 07f559ac5883..35ec9ea79869 100644 --- a/drivers/scsi/ufs/ufs_quirks.h +++ b/drivers/scsi/ufs/ufs_quirks.h @@ -116,4 +116,10 @@ struct ufs_dev_fix { */ #define UFS_DEVICE_QUIRK_DELAY_AFTER_LPM (1 << 11) +/* + * Some UFS devices require L2P entry should be swapped before being sent to the + * UFS device for HPB READ command. + */ +#define UFS_DEVICE_QUIRK_SWAP_L2P_ENTRY_FOR_HPB_READ (1 << 12) + #endif /* UFS_QUIRKS_H_ */ diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index 47a5085f16a9..c3a14d3b0030 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -199,7 +199,8 @@ ufs_get_desired_pm_lvl_for_dev_link_state(enum ufs_dev_pwr_mode dev_state, static struct ufs_dev_fix ufs_fixups[] = { /* UFS cards deviations table */ UFS_FIX(UFS_VENDOR_MICRON, UFS_ANY_MODEL, - UFS_DEVICE_QUIRK_DELAY_BEFORE_LPM), + UFS_DEVICE_QUIRK_DELAY_BEFORE_LPM | + UFS_DEVICE_QUIRK_SWAP_L2P_ENTRY_FOR_HPB_READ), UFS_FIX(UFS_VENDOR_SAMSUNG, UFS_ANY_MODEL, UFS_DEVICE_QUIRK_DELAY_BEFORE_LPM | UFS_DEVICE_QUIRK_HOST_PA_TACTIVATE | diff --git a/drivers/scsi/ufs/ufshpb.c b/drivers/scsi/ufs/ufshpb.c index 54e8e019bdbe..d0eb14be47a3 100644 --- a/drivers/scsi/ufs/ufshpb.c +++ b/drivers/scsi/ufs/ufshpb.c @@ -323,15 +323,19 @@ ufshpb_get_pos_from_lpn(struct ufshpb_lu *hpb, unsigned long lpn, int *rgn_idx, } static void -ufshpb_set_hpb_read_to_upiu(struct ufshpb_lu *hpb, struct ufshcd_lrb *lrbp, - u32 lpn, __be64 ppn, u8 transfer_len, int read_id) +ufshpb_set_hpb_read_to_upiu(struct ufs_hba *hba, struct ufshpb_lu *hpb, + struct ufshcd_lrb *lrbp, u32 lpn, __be64 ppn, + u8 transfer_len, int read_id) { unsigned char *cdb = lrbp->cmd->cmnd; - + __be64 ppn_tmp = ppn; cdb[0] = UFSHPB_READ; + if (hba->dev_quirks & UFS_DEVICE_QUIRK_SWAP_L2P_ENTRY_FOR_HPB_READ) + ppn_tmp = swab64(ppn); + /* ppn value is stored as big-endian in the host memory */ - memcpy(&cdb[6], &ppn, sizeof(__be64)); + memcpy(&cdb[6], &ppn_tmp, sizeof(__be64)); cdb[14] = transfer_len; cdb[15] = read_id; @@ -689,7 +693,8 @@ int ufshpb_prep(struct ufs_hba *hba, struct ufshcd_lrb *lrbp) } } - ufshpb_set_hpb_read_to_upiu(hpb, lrbp, lpn, ppn, transfer_len, read_id); + ufshpb_set_hpb_read_to_upiu(hba, hpb, lrbp, lpn, ppn, transfer_len, + read_id); hpb->stats.hit_cnt++; return 0; From patchwork Wed Aug 4 18:21:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bean Huo X-Patchwork-Id: 492590 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4E9CDC432BE for ; Wed, 4 Aug 2021 18:21:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3144260F94 for ; Wed, 4 Aug 2021 18:21:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240187AbhHDSVz (ORCPT ); Wed, 4 Aug 2021 14:21:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52270 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238100AbhHDSVy (ORCPT ); Wed, 4 Aug 2021 14:21:54 -0400 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0903BC06179F; Wed, 4 Aug 2021 11:21:41 -0700 (PDT) Received: by mail-wr1-x429.google.com with SMTP id n12so3263354wrr.2; Wed, 04 Aug 2021 11:21:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=EOPlhYtr33hzE6rG/6rS7PK/XlL3T5iZcV6qTZqwXjw=; b=OxGHXpFpgxFvDxbfcfFzN07Btb8Rpq7xEIQJKo0JULaMaODbAeJQ8Ji+o0m/WKqwxR dv3ncuTXEjyHOQvpwAd0pCVAoqPr2gY7ArH7e6M5B3+Il1o3CGlwHjZHYBY+Sk2So2vt assUFRK9nfl66oEsD3o4gxoudYFZJUuN2RuenfKglIrwiU4yopaVi4cp8ReJuxlZNSz9 6Wtt3VnRNvNjKvGVMjUAgxfzKyvjmqDqqvYUVJ3G2wRA+6mVn/xky9YbTvOU39uijSZr lPUMNaLUgWH5Qq96mog9kV1YDO4VS52HlzUbxSQ443pAhYX9ryciLh+n77XqUpd9oFmZ cMBQ== 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:mime-version:content-transfer-encoding; bh=EOPlhYtr33hzE6rG/6rS7PK/XlL3T5iZcV6qTZqwXjw=; b=OcwGebwaUWThVemm0ZIOmmmZpjzwhGBBrdCXaYWdNtvzDmhOvBJIjMnxteLQZW9xql 6f9oYSsg/HOxULjd7pqcI1bbwjIZGM0vrjDlkqMDvHVyEqleDgOt/cl+5YHemcluacSn /rr6VWZcKeXcpLpgO7Fw7Ad6VL/8USE7zKRmnfOhgdv2hJgcdDAhF+4y2ahN34zQZN2f wv5/zIde/gi2tqxRwJ1RFj9bAq96wn6emg/9DVUNLTEtOzDa0DpxAStnMfCw1A1pxw2R qSRdm/UH96dCcAVh8KYg/8AntyaCTEUnYdUQRE1HYKOVbUfbqdBYsMfVDwJK+5yiBtw2 xZBg== X-Gm-Message-State: AOAM532MyDofsx8qq7/u+MqnHs5OX/UkFc4/eXa2V7APu5/sBXLr0l2l Ua0gozDFQMGe2l5qzMkXPtE= X-Google-Smtp-Source: ABdhPJwayXyL/xUPIOKLuSpUajUSYK+zKSnOhHrfzwSEPWAqNjBJkZFDKgBp0ENEBp/s9CkzVsNhZA== X-Received: by 2002:adf:f602:: with SMTP id t2mr690777wrp.232.1628101299580; Wed, 04 Aug 2021 11:21:39 -0700 (PDT) Received: from localhost.localdomain (ip5f5bfdd7.dynamic.kabel-deutschland.de. [95.91.253.215]) by smtp.gmail.com with ESMTPSA id n5sm2914880wme.47.2021.08.04.11.21.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Aug 2021 11:21:39 -0700 (PDT) From: Bean Huo To: alim.akhtar@samsung.com, avri.altman@wdc.com, asutoshd@codeaurora.org, jejb@linux.ibm.com, martin.petersen@oracle.com, stanley.chu@mediatek.com, beanhuo@micron.com, bvanassche@acm.org, cang@codeaurora.org, daejun7.park@samsung.com Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 2/2] scsi: ufs: Add lu_enable sysfs node Date: Wed, 4 Aug 2021 20:21:28 +0200 Message-Id: <20210804182128.458356-3-huobean@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210804182128.458356-1-huobean@gmail.com> References: <20210804182128.458356-1-huobean@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org From: Bean Huo We need to check HPB being enabled on which LU from the userspace tool, so, add lu_enable sysfs node. Signed-off-by: Bean Huo --- drivers/scsi/ufs/ufs-sysfs.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/scsi/ufs/ufs-sysfs.c b/drivers/scsi/ufs/ufs-sysfs.c index 08fe037069bc..5c405ff7b6ea 100644 --- a/drivers/scsi/ufs/ufs-sysfs.c +++ b/drivers/scsi/ufs/ufs-sysfs.c @@ -1163,6 +1163,7 @@ static DEVICE_ATTR_RO(_pname) #define UFS_UNIT_DESC_PARAM(_name, _uname, _size) \ UFS_LUN_DESC_PARAM(_name, _uname, UNIT, _size) +UFS_UNIT_DESC_PARAM(lu_enable, _LU_ENABLE, 1); UFS_UNIT_DESC_PARAM(boot_lun_id, _BOOT_LUN_ID, 1); UFS_UNIT_DESC_PARAM(lun_write_protect, _LU_WR_PROTECT, 1); UFS_UNIT_DESC_PARAM(lun_queue_depth, _LU_Q_DEPTH, 1); @@ -1181,8 +1182,8 @@ UFS_UNIT_DESC_PARAM(hpb_pinned_region_start_offset, _HPB_PIN_RGN_START_OFF, 2); UFS_UNIT_DESC_PARAM(hpb_number_pinned_regions, _HPB_NUM_PIN_RGNS, 2); UFS_UNIT_DESC_PARAM(wb_buf_alloc_units, _WB_BUF_ALLOC_UNITS, 4); - static struct attribute *ufs_sysfs_unit_descriptor[] = { + &dev_attr_lu_enable.attr, &dev_attr_boot_lun_id.attr, &dev_attr_lun_write_protect.attr, &dev_attr_lun_queue_depth.attr,