From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 92405C02192 for ; Mon, 3 Feb 2025 17:13:08 +0000 (UTC) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4YmtMh1h70z3vgQ for ; Tue, 4 Feb 2025 04:12:00 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; arc=none smtp.remote-ip=212.199.177.27 ARC-Seal: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1738602713; cv=none; b=ItaCvNDMt09BCnw4iveC2g/XttSv/HZqPPBrjCj6hDC1nArOh+6bWFMSUFWWOblRUboqXG4qQxUd6BtLrAh7zeDw2sGKaoRrMDoTxMLOrvnZIHxrR2Hz03xRuImbl/brCt8Gp3gqbn21bfMX3Sp5QBBx3JaBnBSWY3RqjXTnR9hVquIMM1MdD1DoZ1NDiVyU5mjJDmzHOmdTCJx+0EVi2uv2bjjU3Emyx7OBwPf86XEWjFggUUAkb/vUx4tKwRYJt34h3ga/+tmb7mZGzUNyENzaEov5yDODK6nqE2J/hVw/OBmgobc28/FLSvOLDK90mj4x9Dt9pN9o1rOUHe6raw== ARC-Message-Signature: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1738602713; c=relaxed/relaxed; bh=CE48jNRbCMJjzwxvUnZKPr2PP4f6gDslXVSrkY2nmH4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Q5mmXuXV3VVZuSozdMHR1wR140qhhQAnfDoA7jeQrP6x3GE+ht29uq1+aZHUHalJWYCGFe2FUB+2ihpTJdx0+b7b0pq4SX7ksOv6/J02Il/CCCdat11X4J/iTn7J7qCP026+SclnypDafpYdgN3ybgXJqH2dkVAbrOq/XNyFppaBPqtCTI0OYWZNEEnlqni9nFuraIdLeVI8QHANJePpE28ZMe/xih15Hsjs313VnRujoMGSXbhaNk5GW4AqoXDSGxXbRYy7RLiCJmA0iGczyVM6k0XC82QGoti/xNADE4Jh1oDsc2I17aIRxSseDKgnRpORpf0aRh7D+deZnUOSww== ARC-Authentication-Results: i=1; lists.ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com; spf=none (client-ip=212.199.177.27; helo=herzl.nuvoton.co.il; envelope-from=tmaimon@taln60.nuvoton.co.il; receiver=lists.ozlabs.org) smtp.mailfrom=taln60.nuvoton.co.il Authentication-Results: lists.ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=taln60.nuvoton.co.il (client-ip=212.199.177.27; helo=herzl.nuvoton.co.il; envelope-from=tmaimon@taln60.nuvoton.co.il; receiver=lists.ozlabs.org) Received: from herzl.nuvoton.co.il (unknown [212.199.177.27]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4YmtMW2Ftkz3bTf for ; Tue, 4 Feb 2025 04:11:50 +1100 (AEDT) Received: from NTILML01.nuvoton.com (212.199.177.18.static.012.net.il [212.199.177.18]) by herzl.nuvoton.co.il (8.13.8/8.13.8) with ESMTP id 513GF1Sx006493 for ; Mon, 3 Feb 2025 18:15:01 +0200 Received: from NTHCCAS01.nuvoton.com (10.1.8.28) by NTILML01.nuvoton.com (10.190.1.46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.43; Mon, 3 Feb 2025 18:15:00 +0200 Received: from NTHCCAS01.nuvoton.com (10.1.8.28) by NTHCCAS01.nuvoton.com (10.1.8.28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Tue, 4 Feb 2025 00:14:57 +0800 Received: from taln58.nuvoton.co.il (10.191.1.178) by NTHCCAS01.nuvoton.com (10.1.8.28) with Microsoft SMTP Server id 15.1.2507.39 via Frontend Transport; Tue, 4 Feb 2025 00:14:57 +0800 Received: from taln60.nuvoton.co.il (taln60 [10.191.1.180]) by taln58.nuvoton.co.il (Postfix) with ESMTP id 647925F651; Mon, 3 Feb 2025 18:14:55 +0200 (IST) Received: by taln60.nuvoton.co.il (Postfix, from userid 10070) id 64AA4DC3281; Mon, 3 Feb 2025 18:14:55 +0200 (IST) From: Tomer Maimon To: Subject: [PATCH linux dev-6.6 v1 5/8] i2c: npcm: Modify timeout evaluation mechanism Date: Mon, 3 Feb 2025 18:14:47 +0200 Message-ID: <20250203161450.265480-6-tmaimon77@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250203161450.265480-1-tmaimon77@gmail.com> References: <20250203161450.265480-1-tmaimon77@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-NotSetDelaration: True X-BeenThere: openbmc@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development list for OpenBMC List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tyrone Ting , Andi Shyti , Joel Stanley , Tali Perry Errors-To: openbmc-bounces+openbmc=archiver.kernel.org@lists.ozlabs.org Sender: "openbmc" From: Tyrone Ting The users want to connect a lot of masters on the same bus. This timeout is used to determine the time it takes to take bus ownership. The transactions are very long, so waiting 35ms is not enough. Increase the timeout and treat it as the total timeout, including retries. The total timeout is 2 seconds now. The i2c core layer will have chances to retry to call the i2c driver transfer function if the i2c driver reports that the bus is busy and returns -EAGAIN. Signed-off-by: Tyrone Ting Reviewed-by: Tali Perry Link: https://lore.kernel.org/r/20241219090859.18722-2-kfting@nuvoton.com Signed-off-by: Andi Shyti --- drivers/i2c/busses/i2c-npcm7xx.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/drivers/i2c/busses/i2c-npcm7xx.c b/drivers/i2c/busses/i2c-npcm7xx.c index 3a695ad24018..bef27c517b38 100644 --- a/drivers/i2c/busses/i2c-npcm7xx.c +++ b/drivers/i2c/busses/i2c-npcm7xx.c @@ -2133,19 +2133,12 @@ static int npcm_i2c_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, } } - /* - * Adaptive TimeOut: estimated time in usec + 100% margin: - * 2: double the timeout for clock stretching case - * 9: bits per transaction (including the ack/nack) - */ - timeout_usec = (2 * 9 * USEC_PER_SEC / bus->bus_freq) * (2 + nread + nwrite); - timeout = max_t(unsigned long, bus->adap.timeout, usecs_to_jiffies(timeout_usec)); if (nwrite >= 32 * 1024 || nread >= 32 * 1024) { dev_err(bus->dev, "i2c%d buffer too big\n", bus->num); return -EINVAL; } - time_left = jiffies + timeout + 1; + time_left = jiffies + bus->adap.timeout / bus->adap.retries + 1; do { /* * we must clear slave address immediately when the bus is not @@ -2193,6 +2186,14 @@ static int npcm_i2c_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, if (npcm_i2c_master_start_xmit(bus, slave_addr, nwrite, nread, write_data, read_data, read_PEC, read_block)) { + /* + * Adaptive TimeOut: estimated time in usec + 100% margin: + * 2: double the timeout for clock stretching case + * 9: bits per transaction (including the ack/nack) + */ + timeout_usec = (2 * 9 * USEC_PER_SEC / bus->bus_freq) * (2 + nread + nwrite); + timeout = max_t(unsigned long, bus->adap.timeout / bus->adap.retries, + usecs_to_jiffies(timeout_usec)); time_left = wait_for_completion_timeout(&bus->cmd_complete, timeout); @@ -2330,7 +2331,12 @@ static int npcm_i2c_probe_bus(struct platform_device *pdev) adap = &bus->adap; adap->owner = THIS_MODULE; adap->retries = 3; - adap->timeout = msecs_to_jiffies(35); + /* + * The users want to connect a lot of masters on the same bus. + * This timeout is used to determine the time it takes to take bus ownership. + * The transactions are very long, so waiting 35ms is not enough. + */ + adap->timeout = 2 * HZ; adap->algo = &npcm_i2c_algo; adap->quirks = &npcm_i2c_quirks; adap->algo_data = bus; -- 2.34.1