Received: by 2002:a05:6500:1b8f:b0:1fa:5c73:8e2d with SMTP id df15csp1167385lqb; Thu, 30 May 2024 02:13:21 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXRJEs05R8qx9A4FFo9nP4kTK9UByY6m11Y/X1UGI+3s3E82X3RkFV6eSJYCKiNaKy+RT2tBmsK1esSSIjQwTbx21AEVYhHBtcTwuVv8Q== X-Google-Smtp-Source: AGHT+IGjkY1c6Ge/mLCfFyEvc8jZClZpyNNskI+oua3o+gxSeja82kRb3/g19nHgKW8MlvuISjIx X-Received: by 2002:a17:906:55d6:b0:a59:b359:3e18 with SMTP id a640c23a62f3a-a65e90f59b5mr104405966b.47.1717060401225; Thu, 30 May 2024 02:13:21 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717060401; cv=pass; d=google.com; s=arc-20160816; b=MPkKH/Nux1iuclNTnTEAjSXY3oDe75JkUlAg0IPqvVskk8dWNsnc/K4omnUN/v6D+1 MijdTCCal4nn9gtqYMstt25YsCC4ssVBpRSpGXqKQu92ldUck93bP+r/sYw4m8YrrWaw V0ldMHV/ntB6rjwdH9gACpCL6XDMx7rpYX3/iPDYG1fj6TGHmlGShl/3l4Y2CI8hRduJ I7IDN2pp3nAW8NO/rFJpGkOyIZK3YnOKE6lWlQ80QJa9RPbVVO1uMsgZQc0gVUIyDxTY WbhsJ7BEI7m1zFa/G8yxfBBbPRVNZzFeRc63YPd/0h5Ag4iinCrgiGaIldZkXTLXpWIE lrqg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :user-agent:content-transfer-encoding:autocrypt:references :in-reply-to:date:cc:to:from:subject:message-id:dkim-signature; bh=fa4RT2lgTkaA5/fy0D+M4ZVApJB7iK4FR//N3+opHgw=; fh=3PFGSwSU1dvhW98cH43c6V+nyIzUd+Pll20roXsGtOU=; b=oW+QTEY+Mss65C9/Jvw5M+Ffa+4y0a4AEVdw9D5z+7Qjkh0b9ezAh/cl0oDRQqXivP 7W6R0Uy5+2WiKFzbayU3BVHo+1LioLgrLtGAQIeJuviGLSEVQAuHEDG7+UJYQUZyIpEg gJO8fvKalH8E32Z1smf+nrdTH1uQJB4Q0IdZet7xJDOeHsKZFKO2Y8KxXjXD3qymeTwq 3+w9nKBc4lTJSex0kvf5ANHx+waVbqjH9JrI9hn/VBvI9qZO3LSLum348J2GobQd6iyq OBEM71qtgdt6WR6606DdKiGIHQw51aFHTKgwddQmytAwURU3/0D7RqlLoZMyZ3f+ueTa CY/Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=DRx3fq5G; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-195146-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-195146-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id a640c23a62f3a-a65f8231e13si44201766b.1002.2024.05.30.02.13.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 May 2024 02:13:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-195146-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=@redhat.com header.s=mimecast20190719 header.b=DRx3fq5G; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-195146-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-195146-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.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 A88191F219C1 for ; Thu, 30 May 2024 09:13:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 145DC183993; Thu, 30 May 2024 09:13:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="DRx3fq5G" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 56085183973 for ; Thu, 30 May 2024 09:13:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717060390; cv=none; b=OPrZjlUY8ELnU+jv1eueOe+IgwYaR5kU/FDxxkuMUC+lZIJy5xzVIlJKKw4r/BcaxJQlx67WyXf27oYP1w4OZowuCtHwjCUz8OPBFkTfzgvnZeeMnQLTjCiJImo5yWFCgJqVvU2HTnlHAmjiPyoPanRRkroxo8FEjvRQZemdsn4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717060390; c=relaxed/simple; bh=xCpzaDdKWW9AW8tDLtRBP9eTGLx1aULWHWwVDHvvqeM=; h=Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References: Content-Type:MIME-Version; b=keE/MAPRtVWx/Tq5Fm/TtWQD7nHmonOycAxM3BjIvMl1h1zY5bZWcWsJl42eWv517vout8jyEESpHx6qzhu+n5u9HV5sqKYqCS6EPmpp6gFJ+HOs3gdnWy/QKQNdXVj41btAvTlnCBxiDKKhV5UICAjX47nhrTwJrtwUEewtFlE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=DRx3fq5G; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717060387; 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:autocrypt:autocrypt; bh=fa4RT2lgTkaA5/fy0D+M4ZVApJB7iK4FR//N3+opHgw=; b=DRx3fq5GWUPFS/Icyak+9Xc/CmEwAcc6fY/SLPK9xAhIPFkUsD2G2ksfdsBRKPkqBsXx+p z6yt7AW0ZGeACsqvWvJ/5HBimEOKwHIJ/Q4uIFGLMo8aSncGTQGxpwN6eXmG8hCJh38b7a lv66uDcTyuTdgP7pRCOWlYBNq2PUYTw= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-195--WlxsgArM1yOeEiOPtqXEg-1; Thu, 30 May 2024 05:13:04 -0400 X-MC-Unique: -WlxsgArM1yOeEiOPtqXEg-1 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-421110ba697so1059165e9.0 for ; Thu, 30 May 2024 02:13:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717060383; x=1717665183; h=mime-version:user-agent:content-transfer-encoding:autocrypt :references:in-reply-to:date:cc:to:from:subject:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=fa4RT2lgTkaA5/fy0D+M4ZVApJB7iK4FR//N3+opHgw=; b=OpbIkX7JUFjHwaMSS/B5ayO1Gj4BupYcMFRto0cYM/2iAh//YAhXUJEpHHx5TDRulJ YjG4Tzce9JLkCO/ZeMRblgVv+VS1xZVvSUBrSg1ZGL4riDbQYTJrdXmgC+EfoMBtOJ/2 EXDbFg9gX7JLIP9gHXGcM+fkGpYGOqZdvepqASDNIhoDvfk6TJ/NLPer0mCsNpMDa2PD mBaF+dA5OKMkJRlMwIRvjEIgXPvtsCVpJqj6hsomvA0I8kh01fxw7HMO0FF/gGPVVgYj 1W5CPB7gAr6DBIM7+PrZhQKL1lrsQi2CziYoH6QclHO0HQQ/8hgaRdH/KTUTXdMZjFwF EXGg== X-Forwarded-Encrypted: i=1; AJvYcCXoXLbY+mUu/Api+1Tn30TLvDyrx20w3TPFIt4Zi8C7H2JD6kPglaSkbJeKlCOD2sdo3I7ApklnrowBCPFMc9zXCWqo1VnBUrZovYj9 X-Gm-Message-State: AOJu0Yz6CT1lKN7SolQRcvXdzJaNBM8CODebGh7FuXKuChnhnXOqUZDl VUC1l+ySv/yduyACyYN0/PyZe9b0m8YkTmGzntDxYK1TdoPz2Ebas3tHMyOapruVX+CoSEBxF9l u9oOrXltHAKvsTxbJd90fYnlmwBa5vavQbLxUti9yppQNkaU5crDhgYv3NladSw== X-Received: by 2002:a05:600c:1d16:b0:41f:cfe6:3646 with SMTP id 5b1f17b1804b1-421279376c9mr12905325e9.4.1717060383030; Thu, 30 May 2024 02:13:03 -0700 (PDT) X-Received: by 2002:a05:600c:1d16:b0:41f:cfe6:3646 with SMTP id 5b1f17b1804b1-421279376c9mr12905025e9.4.1717060382620; Thu, 30 May 2024 02:13:02 -0700 (PDT) Received: from gerbillo.redhat.com ([2a0d:3341:b094:ab10:29ae:cdc:4db4:a22a]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42123458a5bsm23676725e9.1.2024.05.30.02.13.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 May 2024 02:13:02 -0700 (PDT) Message-ID: <4a467adcdb3ca8e272bd3ae1be54272610aabc9b.camel@redhat.com> Subject: Re: [PATCH net] net: dsa: microchip: fix KSZ9477 set_ageing_time function From: Paolo Abeni To: Tristram.Ha@microchip.com, Arun Ramadoss , Woojung Huh , Andrew Lunn , Vivien Didelot , Florian Fainelli , Vladimir Oltean Cc: "David S. Miller" , Eric Dumazet , Jakub Kicinski , UNGLinuxDriver@microchip.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Date: Thu, 30 May 2024 11:13:00 +0200 In-Reply-To: <1716932192-3555-1-git-send-email-Tristram.Ha@microchip.com> References: <1716932192-3555-1-git-send-email-Tristram.Ha@microchip.com> Autocrypt: addr=pabeni@redhat.com; prefer-encrypt=mutual; keydata=mQINBGISiDUBEAC5uMdJicjm3ZlWQJG4u2EU1EhWUSx8IZLUTmEE8zmjPJFSYDcjtfGcbzLPb63BvX7FADmTOkO7gwtDgm501XnQaZgBUnCOUT8qv5MkKsFH20h1XJyqjPeGM55YFAXc+a4WD0YyO5M0+KhDeRLoildeRna1ey944VlZ6Inf67zMYw9vfE5XozBtytFIrRyGEWkQwkjaYhr1cGM8ia24QQVQid3P7SPkR78kJmrT32sGk+TdR4YnZzBvVaojX4AroZrrAQVdOLQWR+w4w1mONfJvahNdjq73tKv51nIpu4SAC1Zmnm3x4u9r22mbMDr0uWqDqwhsvkanYmn4umDKc1ZkBnDIbbumd40x9CKgG6ogVlLYeJa9WyfVMOHDF6f0wRjFjxVoPO6p/ZDkuEa67KCpJnXNYipLJ3MYhdKWBZw0xc3LKiKc+nMfQlo76T/qHMDfRMaMhk+L8gWc3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QvAP0EAakWsqHoKZ5WdpeOcH9iVlUQhRgemQSkhfNaP9LqR1XKujlTuUTpoyT3xwAzkmSxN1nABoutHEO/N87fpIbpbZaIdinF7b9srwUvDOKsywfs5HMiUZhLKoZzCcU/AEFjQsPTATACGsWf3JYPnWxL9 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.50.4 (3.50.4-1.fc39) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 On Tue, 2024-05-28 at 14:36 -0700, Tristram.Ha@microchip.com wrote: > From: Tristram Ha >=20 > The aging count is not a simple 11-bit value but comprises a 3-bit > multiplier and an 8-bit second count. The code tries to find a set of > values with result close to the specifying value. >=20 > Note LAN937X has similar operation but provides an option to use > millisecond instead of second so there will be a separate fix in the > future. >=20 > Fixes: 2c119d9982b1 ("net: dsa: microchip: add the support for set_ageing= _time") > Signed-off-by: Tristram Ha > --- > drivers/net/dsa/microchip/ksz9477.c | 64 +++++++++++++++++++++---- > drivers/net/dsa/microchip/ksz9477_reg.h | 1 - > 2 files changed, 54 insertions(+), 11 deletions(-) >=20 > diff --git a/drivers/net/dsa/microchip/ksz9477.c b/drivers/net/dsa/microc= hip/ksz9477.c > index f8ad7833f5d9..1af11aee3119 100644 > --- a/drivers/net/dsa/microchip/ksz9477.c > +++ b/drivers/net/dsa/microchip/ksz9477.c > @@ -1099,26 +1099,70 @@ void ksz9477_get_caps(struct ksz_device *dev, int= port, > int ksz9477_set_ageing_time(struct ksz_device *dev, unsigned int msecs) > { > u32 secs =3D msecs / 1000; > + u8 first, last, mult, i; > + int min, ret; > + int diff[8]; > u8 value; > u8 data; > - int ret; > =20 > - value =3D FIELD_GET(SW_AGE_PERIOD_7_0_M, secs); > + /* The aging timer comprises a 3-bit multiplier and an 8-bit second > + * value. Either of them cannot be zero. The maximum timer is then > + * 7 * 255 =3D 1785. > + */ > + if (!secs) > + secs =3D 1; > =20 > - ret =3D ksz_write8(dev, REG_SW_LUE_CTRL_3, value); > + ret =3D ksz_read8(dev, REG_SW_LUE_CTRL_0, &value); > if (ret < 0) > return ret; > =20 > - data =3D FIELD_GET(SW_AGE_PERIOD_10_8_M, secs); > + /* Check whether there is need to update the multiplier. */ > + mult =3D FIELD_GET(SW_AGE_CNT_M, value); > + if (mult > 0) { > + /* Try to use the same multiplier already in the register. */ > + min =3D secs / mult; > + if (min <=3D 0xff && min * mult =3D=3D secs) > + return ksz_write8(dev, REG_SW_LUE_CTRL_3, min); > + } > =20 > - ret =3D ksz_read8(dev, REG_SW_LUE_CTRL_0, &value); > - if (ret < 0) > - return ret; > + /* Return error if too large. */ > + if (secs > 7 * 0xff) > + return -EINVAL; > + > + /* Find out which combination of multiplier * value results in a timer > + * value close to the specified timer value. > + */ > + first =3D (secs + 0xfe) / 0xff; > + for (i =3D first; i <=3D 7; i++) { > + min =3D secs / i; > + diff[i] =3D secs - i * min; > + if (!diff[i]) { > + i++; > + break; > + } > + } > + > + last =3D i; > + min =3D 0xff; > + for (i =3D last - 1; i >=3D first; i--) { > + if (diff[i] < min) { > + data =3D i; > + min =3D diff[i]; > + } > + if (!min) > + break; > + } Is the additional accuracy worthy the added complexity WRT: mult =3D DIV_ROUND_UP(secs, 0xff); ? Paolo