Received: by 2002:a05:6a10:5594:0:0:0:0 with SMTP id ee20csp197076pxb; Mon, 25 Apr 2022 08:21:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxPa40tUWMwu44cFDLAknDBhJdgOiIBD6UgM8E9XFMfuAuoQOdPQVmFARhyaZV9z/zaRSZw X-Received: by 2002:a05:6a02:20c:b0:381:f276:98d6 with SMTP id bh12-20020a056a02020c00b00381f27698d6mr15276412pgb.39.1650900101784; Mon, 25 Apr 2022 08:21:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650900101; cv=none; d=google.com; s=arc-20160816; b=M2hdnoepgvaQqr8vt9PfpAaDcMMFlBWK4jau9DEhAVfUCKa/iWZL7ldL7oKxdL6zBv 1Csdhh2VOQ+nLn11DESIhCjeevqjEIpdl6OjFZxFsalkeQ8JqXW3Tq8HnQXZe7dvqBUk Jf1A8pTi2uhmBbzq2zDkpnKKXbj0QSejyMYLs0O1gCRcAVq6jKpVBzMfwn2CwynT5Uef IFaogue7JwEeyNc6VkxkNLJPt378Sp0NdOg5wzrdKAcB9Cbh9TSysh43sIgck69RFPgB KbPCOj7L3RH0XWLw0Yft4vJ00zfO75Ik7BOKc6jHTlROHoohe7YL0R0Rnb06a6/SY0eK 4rkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=3Y91YY01N7UrHQaQhke//8ISQGGOkcgPe3+Pz+wp220=; b=KSqVf6hhxdZc4TmIqcd6AmrGuFTnjl44b1/X7Y7jDZNI/dsWm6t/LHMVQehY49ZJrg tPIc6qobRWh45ZdAmbpuFUthmvUW+2R1LdsKgebFR2g957+28zM/r6v2TstO0w31RYxA FFG3JPzZIELpilHFyVJEzkoxd0dQH9ohcwhU/2bvSYf1kiUXMAA1l7D0nuue3aenwbye C+h2LSWShmfJ6fKGxjyTK4VX09fxtzvekg9z8nVsRvnlI5pVuipOPKAmr8k01UflJuIv EnOXB8w/WfhPM/Qvjl2p4DvAuCkss4aZKomACGdmDrU7K/BMl+7rWn29pXKUN/18nITQ 5tfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=a91AdZ5R; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t22-20020a1709028c9600b00153b2d16483si14963614plo.139.2022.04.25.08.21.17; Mon, 25 Apr 2022 08:21:41 -0700 (PDT) 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=@redhat.com header.s=mimecast20190719 header.b=a91AdZ5R; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240540AbiDYKno (ORCPT + 99 others); Mon, 25 Apr 2022 06:43:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240223AbiDYKn1 (ORCPT ); Mon, 25 Apr 2022 06:43:27 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 541061BEA7 for ; Mon, 25 Apr 2022 03:40:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650883220; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3Y91YY01N7UrHQaQhke//8ISQGGOkcgPe3+Pz+wp220=; b=a91AdZ5R3mmFPVXYfDS8+B482x8zf7thMir50II1Qvws0HLCro1GD58zN0ChrxI+a31eQM SOP6AzNudTsAWndmii5UT+tSx45fVmFKJLfvhrb+UqiNeMnxZ4Lid2O3cyiR3cvwOWkFAe xnGwbmqIm8XVMhWO7vWCd1nNXmkGwVs= Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-50-gzCYhoypMVSyd7w2O3lxLg-1; Mon, 25 Apr 2022 06:40:19 -0400 X-MC-Unique: gzCYhoypMVSyd7w2O3lxLg-1 Received: by mail-ej1-f72.google.com with SMTP id nc20-20020a1709071c1400b006f3726da7d3so2520711ejc.15 for ; Mon, 25 Apr 2022 03:40:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=3Y91YY01N7UrHQaQhke//8ISQGGOkcgPe3+Pz+wp220=; b=IRj9/lZtMw8Q6hDfJtDwfOCFg2sdDcZ5IL1+RbXnaWjdL8zUFUU/mo3rFKE7bxXG7m BBEOOlgL9WW0R178Gt7Z/qmIphGHPlL5G7RCCxyWyBnmbyGMVSuRQiytO8BTOpYqZhe5 WYEKv8qiBiXe5BDRQtuvJt2GJM43i7H/4DrVEDcRkl/rQYEkM9j76r9/G+Q0HfJZGSS8 ZHDta6lt09uqUPdl6Z+ELSLA8SA6qRkQY8XxICKOu8DsZhggq4SZIgsvaM3ab+KWkAC4 bs+F3bsSmMWJmz6PGZkNqBdFxPnD2HRCa0BO6dDD8YIYXIDKbd0z1+ehW/ERx8CYIjbr 10Gg== X-Gm-Message-State: AOAM530DG23wg/ueVfZ6ZuT2enPExV9c65aRiSgIBiO8E5/p3CQTrbnC lRi7c5KzOApevXO1aVWkU8PvodCAz6Nzt0RFr7WyEEMUA+PyrgdkPMkddhP04Vj5/n2LiifgnNP 1FGwfctDLHi846Sv0J9/ubJiN X-Received: by 2002:a17:907:c243:b0:6f3:953d:6e2 with SMTP id tj3-20020a170907c24300b006f3953d06e2mr4143257ejc.506.1650883217951; Mon, 25 Apr 2022 03:40:17 -0700 (PDT) X-Received: by 2002:a17:907:c243:b0:6f3:953d:6e2 with SMTP id tj3-20020a170907c24300b006f3953d06e2mr4143246ejc.506.1650883217736; Mon, 25 Apr 2022 03:40:17 -0700 (PDT) Received: from ?IPV6:2001:1c00:c1e:bf00:d69d:5353:dba5:ee81? (2001-1c00-0c1e-bf00-d69d-5353-dba5-ee81.cable.dynamic.v6.ziggo.nl. [2001:1c00:c1e:bf00:d69d:5353:dba5:ee81]) by smtp.gmail.com with ESMTPSA id q11-20020a170906144b00b006cf61dfb03esm3481489ejc.62.2022.04.25.03.40.16 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 25 Apr 2022 03:40:16 -0700 (PDT) Message-ID: Date: Mon, 25 Apr 2022 12:40:15 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.8.0 Subject: Re: [PATCH] mmc: sunxi-mmc: Correct the maximum segment size Content-Language: en-US To: Samuel Holland , Ulf Hansson , linux-mmc@vger.kernel.org Cc: Arnd Bergmann , Chen-Yu Tsai , Chris Ball , Jernej Skrabec , Maxime Ripard , Mike Turquette , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-sunxi@lists.linux.dev References: <20220424230640.31735-1-samuel@sholland.org> From: Hans de Goede In-Reply-To: <20220424230640.31735-1-samuel@sholland.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-5.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,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 Hi Samuel, On 4/25/22 01:06, Samuel Holland wrote: > According to the DMA descriptor documentation, the lowest two bits of > the size field are ignored, so the size must be rounded up to a multiple > of 4 bytes. Furthermore, 0 is not a valid buffer size; setting the size > to 0 will cause that DMA descriptor to be ignored. > > Together, these restrictions limit the maximum DMA segment size to 4 > less than the power-of-two width of the size field. I assume that you were seeing some problems where things where not working which caused you to investigate this; and that this patch fixes those problems? If yes then it would be good to also mention the problems + investigative process in the commit message. I'm no longer involved in sunxi development, but still I wonder if the substraction of 4 from the max_seg_size is really necessary? This seems to be based on the notion that as you say "0 is not a valid buffer size" where as the code so far has been operating under the assumption that putting 0 in sunxi_idma_des.buf_size means maximum buf-size. I'm pretty sure that 0 meaning maximum buf-size is correct for at least the older chips where idma_des_size_bits equals 13, which means that only 2 4K pages fit in a single desc, so we almost certainly have been hitting this code path ? Although: drivers/mmc/host/dw_mmc.c which seems to be for similar hw suggests that on designs where idma_des_size_bits == 13 only 4k can be used, which sorta matches what you are doing here except that you limit things to 8k - 4 instead of to just 4k. Anyways I was just wondering about all this... Regards, Hans > > Fixes: 3cbcb16095f9 ("mmc: sunxi: Add driver for SD/MMC hosts found on Allwinner sunxi SoCs") > Signed-off-by: Samuel Holland > --- > > drivers/mmc/host/sunxi-mmc.c | 14 ++++++++------ > 1 file changed, 8 insertions(+), 6 deletions(-) > > diff --git a/drivers/mmc/host/sunxi-mmc.c b/drivers/mmc/host/sunxi-mmc.c > index c62afd212692..4bd5f37b1036 100644 > --- a/drivers/mmc/host/sunxi-mmc.c > +++ b/drivers/mmc/host/sunxi-mmc.c > @@ -214,6 +214,9 @@ > #define SDXC_IDMAC_DES0_CES BIT(30) /* card error summary */ > #define SDXC_IDMAC_DES0_OWN BIT(31) /* 1-idma owns it, 0-host owns it */ > > +/* Buffer size must be a multiple of 4 bytes. */ > +#define SDXC_IDMAC_SIZE_ALIGN 4 > + > #define SDXC_CLK_400K 0 > #define SDXC_CLK_25M 1 > #define SDXC_CLK_50M 2 > @@ -361,17 +364,15 @@ static void sunxi_mmc_init_idma_des(struct sunxi_mmc_host *host, > { > struct sunxi_idma_des *pdes = (struct sunxi_idma_des *)host->sg_cpu; > dma_addr_t next_desc = host->sg_dma; > - int i, max_len = (1 << host->cfg->idma_des_size_bits); > + int i; > > for (i = 0; i < data->sg_len; i++) { > pdes[i].config = cpu_to_le32(SDXC_IDMAC_DES0_CH | > SDXC_IDMAC_DES0_OWN | > SDXC_IDMAC_DES0_DIC); > > - if (data->sg[i].length == max_len) > - pdes[i].buf_size = 0; /* 0 == max_len */ > - else > - pdes[i].buf_size = cpu_to_le32(data->sg[i].length); > + pdes[i].buf_size = cpu_to_le32(ALIGN(data->sg[i].length, > + SDXC_IDMAC_SIZE_ALIGN)); > > next_desc += sizeof(struct sunxi_idma_des); > pdes[i].buf_addr_ptr1 = > @@ -1420,7 +1421,8 @@ static int sunxi_mmc_probe(struct platform_device *pdev) > mmc->max_blk_count = 8192; > mmc->max_blk_size = 4096; > mmc->max_segs = PAGE_SIZE / sizeof(struct sunxi_idma_des); > - mmc->max_seg_size = (1 << host->cfg->idma_des_size_bits); > + mmc->max_seg_size = (1 << host->cfg->idma_des_size_bits) - > + SDXC_IDMAC_SIZE_ALIGN; > mmc->max_req_size = mmc->max_seg_size * mmc->max_segs; > /* 400kHz ~ 52MHz */ > mmc->f_min = 400000;