From patchwork Sun Nov 20 22:22:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bean Huo X-Patchwork-Id: 23470 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1287076wrr; Sun, 20 Nov 2022 14:23:16 -0800 (PST) X-Google-Smtp-Source: AA0mqf4gL2yHIU0S6Fipdz/WWyDANLZOkfyZbp5mG/vMo+p+wk1NV38V/PhfppqEhWhq4hyjP2dK X-Received: by 2002:a17:90a:f2cf:b0:20b:a5e:5c40 with SMTP id gt15-20020a17090af2cf00b0020b0a5e5c40mr17693311pjb.185.1668982996392; Sun, 20 Nov 2022 14:23:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668982996; cv=none; d=google.com; s=arc-20160816; b=uBT9jvPAyztNeOKjEJKvivev7a6Wvdpo2dh+OxRJJmHvtoFzsCtFVJftMMaY2wS9p1 ILH677SA2aWvzwUQiyc6HF4VFUagSIjmAhB618G7B/0sBjqvWagbANLh++eyPcSQyBWq YTU+FP725G3A1UJJC4GyZf6ZzP1JhmBrHc8ooL6CnqF3pLpZHDAoJaKxbxChDZVJ9kYM JDCwSYDY8zjA31ObJV3/wvM553QnMl1Mq2hRX8U7XRkjiB8/o7Boo258OmGzwEv6kN9r SvK5geTKXLGYMAr3GgBohfXywF8vioNiQlqE48eECg7VHfE22WGHdDA3YLTlXI0qFsOd JW6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=AoDuL4Xj3zDQl9TURGe3xsxqp70mUfT+N6ozH7NwzN8=; b=buY5eJ/SVpSSG0U6y/Fe/ixkF2Nzg+vPBzpNUn2VNYem2h2Un94n+AX45HsrHU8Cfg V/oVoKwrQ/r/quwwGCGnbH/Ckg6K2ZADL4dO0CFtNZt7zPCTjDTDjZwZlAiDQqlvkJdt ptvjoXpe8gqHaRLWjTX1/Gv0HuoIO/2i+PqWKOFX/kaw2F0gPin9+TQEJSkssF46ycwK /bL/QmBHapaRIhJy1SI7IfoaBmXzr2VgUZ1U9kH5TS5oefWzEOMYQBM80J17RWg0clpm b0nl/Rw5hqC77lPsd1EOxzj4wzms0bs0vf1r4eXFveTAxvX4/vi2k2oto+hAsOdtADmr kT4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@iokpp.de header.s=strato-dkim-0002 header.b=EycFjyOs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z18-20020aa79e52000000b0056da577864fsi8646136pfq.241.2022.11.20.14.23.03; Sun, 20 Nov 2022 14:23:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@iokpp.de header.s=strato-dkim-0002 header.b=EycFjyOs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229735AbiKTWWg (ORCPT + 99 others); Sun, 20 Nov 2022 17:22:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58724 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229449AbiKTWWe (ORCPT ); Sun, 20 Nov 2022 17:22:34 -0500 Received: from mo4-p03-ob.smtp.rzone.de (mo4-p03-ob.smtp.rzone.de [85.215.255.101]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6CCA795B7; Sun, 20 Nov 2022 14:22:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1668982948; s=strato-dkim-0002; d=iokpp.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=AoDuL4Xj3zDQl9TURGe3xsxqp70mUfT+N6ozH7NwzN8=; b=EycFjyOsj7Lz1Cdm8IvA7YIG41q91u7T5sfpDRfIWBw2dUNnisWK4UpH6Mra/5nFA8 9q3FRiWFUt7vJ53aLJegiyai1E9iFMG2+H75q9/a+/GDhF/LNX6Ms26TNMJNvD3GKgv/ GmTiKCegubsMleIYxNDq1enbvhIUqWw7THNtWIpS6wTwC/oK6rUcA46/D7PUEZQw/+8x xt4ZkqIX0DARDjvcAbfCwScuTdN4EQZBSaXCPEvDofyHeMmQtnZ9B4ZaHdCnqvtKBdv/ 7sCl+Kxo3waKxu07S0EcdBp96Zo4QtAl8O1i8Uddmsc87cUsYZEIeqiH+EefzvLHX1sD kpZA== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":LmkFe0i9dN8c2t4QQyGBB/NDXvjDB6pBSedrgBzPc9DUyubU4DD1QLj68UeUr1+U1RvWtIfZ/7Q8ZGqEBlwxF4QH61wYa9UK/y81Dg==" X-RZG-CLASS-ID: mo03 Received: from blinux.speedport.ip by smtp.strato.de (RZmta 48.2.1 AUTH) with ESMTPSA id z9cfbfyAKMMSWc7 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Sun, 20 Nov 2022 23:22:28 +0100 (CET) From: Bean Huo To: alim.akhtar@samsung.com, avri.altman@wdc.com, jejb@linux.ibm.com, martin.petersen@oracle.com, stanley.chu@mediatek.com, beanhuo@micron.com, bvanassche@acm.org, tomas.winkler@intel.com, daejun7.park@samsung.com, quic_cang@quicinc.com, quic_nguyenb@quicinc.com, quic_xiaosenh@quicinc.com, quic_richardp@quicinc.com, quic_asutoshd@quicinc.com, hare@suse.de Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 3/6] ufs: core: Split ufshcd_map_sg Date: Sun, 20 Nov 2022 23:22:14 +0100 Message-Id: <20221120222217.108492-4-beanhuo@iokpp.de> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221120222217.108492-1-beanhuo@iokpp.de> References: <20221120222217.108492-1-beanhuo@iokpp.de> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_PASS,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750055514122865974?= X-GMAIL-MSGID: =?utf-8?q?1750055514122865974?= From: Bean Huo Take out the "map scatter-gather list to prdt" part of the code in ufshcd_map_sg and split it into a new function ufshcd_sgl_to_prdt. Signed-off-by: Bean Huo Reviewed-by: Avri Altman --- drivers/ufs/core/ufshcd.c | 50 ++++++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 19 deletions(-) diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index 768cb49d269c..1b252e6cf93f 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -2399,38 +2399,30 @@ int ufshcd_send_uic_cmd(struct ufs_hba *hba, struct uic_command *uic_cmd) } /** - * ufshcd_map_sg - Map scatter-gather list to prdt - * @hba: per adapter instance - * @lrbp: pointer to local reference block - * - * Returns 0 in case of success, non-zero value in case of failure + * ufshcd_sgl_to_prdt - SG list to PRTD (Physical Region Description Table, 4DW format) + * @hba: per-adapter instance + * @lrbp: pointer to local reference block + * @sg_entries: The number of sg lists actually used + * @sg_list: Pointer to SG list */ -static int ufshcd_map_sg(struct ufs_hba *hba, struct ufshcd_lrb *lrbp) +static void ufshcd_sgl_to_prdt(struct ufs_hba *hba, struct ufshcd_lrb *lrbp, int sg_entries, + struct scatterlist *sg_list) { struct ufshcd_sg_entry *prd_table; struct scatterlist *sg; - struct scsi_cmnd *cmd; - int sg_segments; int i; - cmd = lrbp->cmd; - sg_segments = scsi_dma_map(cmd); - if (sg_segments < 0) - return sg_segments; - - if (sg_segments) { + if (sg_entries) { if (hba->quirks & UFSHCD_QUIRK_PRDT_BYTE_GRAN) lrbp->utr_descriptor_ptr->prd_table_length = - cpu_to_le16((sg_segments * - sizeof(struct ufshcd_sg_entry))); + cpu_to_le16((sg_entries * sizeof(struct ufshcd_sg_entry))); else - lrbp->utr_descriptor_ptr->prd_table_length = - cpu_to_le16(sg_segments); + lrbp->utr_descriptor_ptr->prd_table_length = cpu_to_le16(sg_entries); prd_table = lrbp->ucd_prdt_ptr; - scsi_for_each_sg(cmd, sg, sg_segments, i) { + for_each_sg(sg_list, sg, sg_entries, i) { const unsigned int len = sg_dma_len(sg); /* @@ -2449,6 +2441,26 @@ static int ufshcd_map_sg(struct ufs_hba *hba, struct ufshcd_lrb *lrbp) } else { lrbp->utr_descriptor_ptr->prd_table_length = 0; } +} + +/** + * ufshcd_map_sg - Map scatter-gather list to prdt + * @hba: per adapter instance + * @lrbp: pointer to local reference block + * + * Returns 0 in case of success, non-zero value in case of failure + */ +static int ufshcd_map_sg(struct ufs_hba *hba, struct ufshcd_lrb *lrbp) +{ + struct scsi_cmnd *cmd; + int sg_segments; + + cmd = lrbp->cmd; + sg_segments = scsi_dma_map(cmd); + if (sg_segments < 0) + return sg_segments; + + ufshcd_sgl_to_prdt(hba, lrbp, sg_segments, scsi_sglist(cmd)); return 0; }