Skip to content

Commit 03d120f

Browse files
Sudheer Kumar Doredlakuba-moo
authored andcommitted
net: ethernet: ti: cpsw_ale: Fix cpsw_ale_get_field()
CPSW ALE has 75-bit ALE entries stored across three 32-bit words. The cpsw_ale_get_field() and cpsw_ale_set_field() functions support ALE field entries spanning up to two words at the most. The cpsw_ale_get_field() and cpsw_ale_set_field() functions work as expected when ALE field spanned across word1 and word2, but fails when ALE field spanned across word2 and word3. For example, while reading the ALE field spanned across word2 and word3 (i.e. bits 62 to 64), the word3 data shifted to an incorrect position due to the index becoming zero while flipping. The same issue occurred when setting an ALE entry. This issue has not been seen in practice but will be an issue in the future if the driver supports accessing ALE fields spanning word2 and word3 Fix the methods to handle getting/setting fields spanning up to two words. Fixes: b685f1a ("net: ethernet: ti: cpsw_ale: Fix cpsw_ale_get_field()/cpsw_ale_set_field()") Signed-off-by: Sudheer Kumar Doredla <[email protected]> Reviewed-by: Simon Horman <[email protected]> Reviewed-by: Roger Quadros <[email protected]> Reviewed-by: Siddharth Vadapalli <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent c77cd47 commit 03d120f

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

drivers/net/ethernet/ti/cpsw_ale.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,15 @@ struct cpsw_ale_dev_id {
127127

128128
static inline int cpsw_ale_get_field(u32 *ale_entry, u32 start, u32 bits)
129129
{
130-
int idx, idx2;
130+
int idx, idx2, index;
131131
u32 hi_val = 0;
132132

133133
idx = start / 32;
134134
idx2 = (start + bits - 1) / 32;
135135
/* Check if bits to be fetched exceed a word */
136136
if (idx != idx2) {
137-
idx2 = 2 - idx2; /* flip */
138-
hi_val = ale_entry[idx2] << ((idx2 * 32) - start);
137+
index = 2 - idx2; /* flip */
138+
hi_val = ale_entry[index] << ((idx2 * 32) - start);
139139
}
140140
start -= idx * 32;
141141
idx = 2 - idx; /* flip */
@@ -145,16 +145,16 @@ static inline int cpsw_ale_get_field(u32 *ale_entry, u32 start, u32 bits)
145145
static inline void cpsw_ale_set_field(u32 *ale_entry, u32 start, u32 bits,
146146
u32 value)
147147
{
148-
int idx, idx2;
148+
int idx, idx2, index;
149149

150150
value &= BITMASK(bits);
151151
idx = start / 32;
152152
idx2 = (start + bits - 1) / 32;
153153
/* Check if bits to be set exceed a word */
154154
if (idx != idx2) {
155-
idx2 = 2 - idx2; /* flip */
156-
ale_entry[idx2] &= ~(BITMASK(bits + start - (idx2 * 32)));
157-
ale_entry[idx2] |= (value >> ((idx2 * 32) - start));
155+
index = 2 - idx2; /* flip */
156+
ale_entry[index] &= ~(BITMASK(bits + start - (idx2 * 32)));
157+
ale_entry[index] |= (value >> ((idx2 * 32) - start));
158158
}
159159
start -= idx * 32;
160160
idx = 2 - idx; /* flip */

0 commit comments

Comments
 (0)