From: Roger Quadros <rogerq@kernel.org>
To: Siddharth Vadapalli <s-vadapalli@ti.com>,
davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
pabeni@redhat.com
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org, srk@ti.com
Subject: Re: [PATCH net] net: ethernet: ti: cpsw_ale: Fix cpsw_ale_get_field()/cpsw_ale_set_field()
Date: Wed, 12 Jul 2023 16:50:55 +0300 [thread overview]
Message-ID: <837f1d5f-64fa-2496-6379-09e5e95252f4@kernel.org> (raw)
In-Reply-To: <20230712110657.1282499-1-s-vadapalli@ti.com>
On 12/07/2023 14:06, Siddharth Vadapalli wrote:
> From: Tanmay Patil <t-patil@ti.com>
>
> CPSW ALE has 75 bit ALE entries which are stored within three 32 bit words.
> The cpsw_ale_get_field() and cpsw_ale_set_field() functions assume that the
> field will be strictly contained within one word. However, this is not
> guaranteed to be the case and it is possible for ALE field entries to span
> across up to two words at the most.
>
> Fix the methods to handle getting/setting fields spanning up to two words.
>
> Fixes: db82173f23c5 ("netdev: driver: ethernet: add cpsw address lookup engine support")
> Signed-off-by: Tanmay Patil <t-patil@ti.com>
> [s-vadapalli@ti.com: rephrased commit message and added Fixes tag]
> Signed-off-by: Siddharth Vadapalli <s-vadapalli@ti.com>
> ---
> drivers/net/ethernet/ti/cpsw_ale.c | 24 +++++++++++++++++++-----
> 1 file changed, 19 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/net/ethernet/ti/cpsw_ale.c b/drivers/net/ethernet/ti/cpsw_ale.c
> index 0c5e783e574c..64bf22cd860c 100644
> --- a/drivers/net/ethernet/ti/cpsw_ale.c
> +++ b/drivers/net/ethernet/ti/cpsw_ale.c
> @@ -106,23 +106,37 @@ struct cpsw_ale_dev_id {
>
> static inline int cpsw_ale_get_field(u32 *ale_entry, u32 start, u32 bits)
> {
> - int idx;
> + int idx, idx2;
> + u32 hi_val = 0;
>
> idx = start / 32;
> + idx2 = (start + bits - 1) / 32;
> + /* Check if bits to be fetched exceed a word */
> + if (idx != idx2) {
> + idx2 = 2 - idx2; /* flip */
> + hi_val = ale_entry[idx2] << ((idx2 * 32) - start);
> + }
> start -= idx * 32;
> idx = 2 - idx; /* flip */
> - return (ale_entry[idx] >> start) & BITMASK(bits);
> + return (hi_val + (ale_entry[idx] >> start)) & BITMASK(bits);
Should this be bit-wise OR instead of ADD?
> }
>
> static inline void cpsw_ale_set_field(u32 *ale_entry, u32 start, u32 bits,
> u32 value)
> {
> - int idx;
> + int idx, idx2;
>
> value &= BITMASK(bits);
> - idx = start / 32;
> + idx = start / 32;
> + idx2 = (start + bits - 1) / 32;
> + /* Check if bits to be set exceed a word */
> + if (idx != idx2) {
> + idx2 = 2 - idx2; /* flip */
> + ale_entry[idx2] &= ~(BITMASK(bits + start - (idx2 * 32)));
> + ale_entry[idx2] |= (value >> ((idx2 * 32) - start));
> + }
> start -= idx * 32;
> - idx = 2 - idx; /* flip */
> + idx = 2 - idx; /* flip */
> ale_entry[idx] &= ~(BITMASK(bits) << start);
> ale_entry[idx] |= (value << start);
> }
--
cheers,
-roger
next prev parent reply other threads:[~2023-07-12 13:51 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-12 11:06 Siddharth Vadapalli
2023-07-12 13:50 ` Roger Quadros [this message]
2023-07-13 6:30 ` Patil, Tanmay
2023-07-14 7:40 ` patchwork-bot+netdevbpf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=837f1d5f-64fa-2496-6379-09e5e95252f4@kernel.org \
--to=rogerq@kernel.org \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=s-vadapalli@ti.com \
--cc=srk@ti.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®