Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp2543849rbb; Wed, 28 Feb 2024 05:22:56 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVfRR/V+u+BYAMB1z1x7Yxn8rZTDEXPu5CwsJcJFMl4RN3rNN084Epm2CSvtgjJZADuZZpl0V7vD7R4FpmVzlqfag6KfDW0Uk/4UrZd4g== X-Google-Smtp-Source: AGHT+IGTij3YOmUPQoxsALj+4a+95gqiKiMxtC3I80qlWIo+Rks0YyT2ksTuL3q/ipAITvQBXnB4 X-Received: by 2002:a17:906:d102:b0:a44:1ace:2186 with SMTP id b2-20020a170906d10200b00a441ace2186mr445270ejz.22.1709126575824; Wed, 28 Feb 2024 05:22:55 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709126575; cv=pass; d=google.com; s=arc-20160816; b=mt3hxn8enGdsj/TtrfwLUHlfqVW75XxnkX1jbrh9sRBgQHLvmysJzFxy1C+Gw4o/ze xOmGVlTT+d1Y9jMh97L5b5My5+MXKo0CMZ07RiX3DmpGTekxxIwWBuOQLA6fFWGsy+9L gAUdj7Z0Fo2fgyyxkpPZp1kk99uJic1db/Zb7HffK+MDFqE87aGWS1hhUYpFiUi+bbq8 wQpL48BJop4YC6fyDxIKYniLY+Tsi1xf8iJWV6zHxOZ1djYtr2sn+CoHCLhfc1c/lqTV zn02yT0+E9h3SlOTM2+/PCPIwjrQkcAu3J/c4Z4XpoAZInFKhGDCXZWiR+GW4SAD9uFq 7x0A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:organization:from:references :cc:to:content-language:subject:user-agent:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:date:message-id :dkim-signature; bh=ptbJ2DwMoB/iKQCFJocIt8hQ7Ber7IrBMZoL5BSnwgQ=; fh=qXnBc03/9iztUFRn+H1vkgcKmkYKQ3LO1jSygc04qxY=; b=00bRmHx0rBgmXCDrDEW7c6jpwFnlwUDD90X59Hwc20nebZ5S9ZBOz78L4jgiy1eWgW 0eQF/JLsY9s4L6AEDaX3TRznnhA9k5K//8Bs+YVinq6xUw4q2gFDLShv2I4Hhly9WAjX NuMRNhBSqQYiUUZI87hYCDDW+WsEb7AZCpv6jYfhWh2ajsI61MIQxcezltv/fcaJIhAp bfmdQcsnjP/lAtXNqUvZyPr8cZj/kEeryg1WE+xmn8nGRBQV+TMpyAIo3obOo2CQ9tlV iIzweMrGW3DbQX9lEeePfhLf+GPVmKfA7DL4SDIxFYagHda2A/yqanWysrhhcRlTRjQp BIBQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=G2CrOEQD; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-85082-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-85082-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id v24-20020a170906489800b00a4306abc237si1671535ejq.381.2024.02.28.05.22.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 05:22:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-85082-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=G2CrOEQD; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-85082-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-85082-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 754A11F25C35 for ; Wed, 28 Feb 2024 13:22:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5DC1414EFC9; Wed, 28 Feb 2024 13:21:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="G2CrOEQD" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.20]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8A2D11E493; Wed, 28 Feb 2024 13:21:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.20 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709126515; cv=none; b=VmNRH1+w+DCisSP+Od64ourI/k51AjReKmOe44aNogOzi6N7VFLFODm0rVBYkARW6m8xVk3KUj7zx5zv5q8s3NuqonDswBqLi6vb+kpheR0mk73l/tJzQ8r9Mh/Muajgv0RwkYMASS8PjKmYsz+Hk1j8BtKrC+UZQg8Qjq2XbNQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709126515; c=relaxed/simple; bh=7r4vZZPJYXmHBCI3JedHoQntu3Jc2TVJ9jZ97EA73XI=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=Y76yEyeMAnl/rfyJTPk5XewsGMIyQ6YTJn/zSQlux8i/1ikMLvuHVlmbsNoOOQUatnFMUNWsRnPUeRwB38ZreDwMKaNA0dhum0dTKc+w4oO7FWT1XOTRJ6mdT0/WmBp1d6USaxaN7s9t2w1lZVNT4x3aQ2FHirUKr6dyPH1qGhI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=G2CrOEQD; arc=none smtp.client-ip=198.175.65.20 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1709126514; x=1740662514; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=7r4vZZPJYXmHBCI3JedHoQntu3Jc2TVJ9jZ97EA73XI=; b=G2CrOEQDv8QAdfJahVysEP0tZc2Q/r4MwPP9oGg25Q9OUGz4Y4EX6zfb XC75PTcDxHm8FBAeDcd5y6q79Wp6ZF2awZBs+0juQSeC/4ORfHkLmWHfN 51uGrvCgGjc3g+oMncTIzR2KDv2QQJD01qkzmYrdX2weziGxD/LxSBCLE ACCZ4AZAw1FepQ2lxuZJOs+8qiw01L5KsxeTTXx87hIOcNE501+rM6HnI OHeZwnzA+oK6lcXoT6cudNjbmh93wHVtFPMMVOBy1JJ07Ajl+WV647i1m aI732vnXm9u2TcpkAM6byPPY8amWoZgkxt0052oJuXtey+w4S5FoGroH8 Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="3398010" X-IronPort-AV: E=Sophos;i="6.06,190,1705392000"; d="scan'208";a="3398010" Received: from orviesa004.jf.intel.com ([10.64.159.144]) by orvoesa112.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Feb 2024 05:21:53 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,190,1705392000"; d="scan'208";a="12100689" Received: from ahunter6-mobl1.ger.corp.intel.com (HELO [10.0.2.15]) ([10.252.50.3]) by orviesa004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Feb 2024 05:21:51 -0800 Message-ID: <4618f19d-0b7d-4844-83f7-ff2f4be083d9@intel.com> Date: Wed, 28 Feb 2024 15:21:46 +0200 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 1/7] mmc: sdhci_am654: Add tuning algorithm for delay chain Content-Language: en-US To: Judith Mendez Cc: linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org, Ulf Hansson References: <20240207011520.3128382-1-jm@ti.com> <20240207011520.3128382-2-jm@ti.com> <461a19cd-36ce-4c34-890e-655a05a81c58@intel.com> <6d939482-9a3a-4923-b74b-ceb31b0ba7e9@ti.com> From: Adrian Hunter Organization: Intel Finland Oy, Registered Address: PL 281, 00181 Helsinki, Business Identity Code: 0357606 - 4, Domiciled in Helsinki In-Reply-To: <6d939482-9a3a-4923-b74b-ceb31b0ba7e9@ti.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On 20/02/24 22:10, Judith Mendez wrote: > On 2/16/24 11:09 AM, Adrian Hunter wrote: >> On 7/02/24 03:15, Judith Mendez wrote: >>> + >>> +    if (!num_fails) >>> +        return ITAPDLY_LAST_INDEX >> 1; >>> + >>> +    if (fail_window->length == ITAPDLY_LENGTH) { >>> +        dev_err(dev, "No passing ITAPDLY, return 0\n"); >>> +        return 0; >>> +    } >>> + >>> +    first_fail_start = fail_window->start; >>> +    last_fail_end = fail_window[num_fails - 1].end; >>> + >>> +    for (i = 0; i < num_fails; i++) { >>> +        start_fail = fail_window[i].start; >>> +        end_fail = fail_window[i].end; >>> +        pass_length = start_fail - (prev_fail_end + 1); >>> + >>> +        if (pass_length > pass_window.length) { >>> +            pass_window.start = prev_fail_end + 1; >>> +            pass_window.length = pass_length; >>> +        } >>> +        prev_fail_end = end_fail; >>> +    } >>> + >>> +    if (!circular_buffer) >>> +        pass_length = ITAPDLY_LAST_INDEX - last_fail_end; >>> +    else >>> +        pass_length = ITAPDLY_LAST_INDEX - last_fail_end + first_fail_start; >>> + >>> +    if (pass_length > pass_window.length) { >>> +        pass_window.start = last_fail_end + 1; >>> +        pass_window.length = pass_length; >>> +    } >>> + >>> +    if (!circular_buffer) >>> +        itap = pass_window.start + (pass_window.length >> 1); >>> +    else >>> +        itap = (pass_window.start + (pass_window.length >> 1)) % ITAPDLY_LENGTH; >>> + >>> +    return (itap < 0 || itap > ITAPDLY_LAST_INDEX ? 0 : itap); >> >> Parentheses are not needed where they are but putting >> them around the condition would make it more readable e.g. >> >>     return (itap < 0 || itap > ITAPDLY_LAST_INDEX) ? 0 : itap; >> >> However (itap < 0) is not possible because itap is an unsigned type >> and if (itap > ITAPDLY_LAST_INDEX) then maybe it would be better >> to return ITAPDLY_LAST_INDEX > > You are right about itap < 0, thanks will fix. > > About itap > ITAPDLY_LAST_INDEX, this is an error. Why > return ITAPDLY_LAST_INDEX instead of 0? It doesn't matter. Just if a value has a better chance to work if the calculation fails, like maybe ITAPDLY_LAST_INDEX / 2, but presumably it should not fail.