Skip to content

Commit 639c1b2

Browse files
steen-hegelund-mchpdavem330
authored andcommitted
net: mscc: ocelot: Register poll timeout should be wall time not attempts
When doing indirect access in the Ocelot chip, a command is setup, issued and then we need to poll until the result is ready. The polling timeout is specified in milliseconds in the datasheet and not in register access attempts. It is not a bug on the currently supported platform, but we observed that the code does not work properly on other platforms that we want to support as the timing requirements there are different. Signed-off-by: Steen Hegelund <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 463561e commit 639c1b2

File tree

1 file changed

+27
-28
lines changed

1 file changed

+27
-28
lines changed

drivers/net/ethernet/mscc/ocelot.c

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,17 @@
1515
#include <linux/netdevice.h>
1616
#include <linux/phy.h>
1717
#include <linux/skbuff.h>
18+
#include <linux/iopoll.h>
1819
#include <net/arp.h>
1920
#include <net/netevent.h>
2021
#include <net/rtnetlink.h>
2122
#include <net/switchdev.h>
2223

2324
#include "ocelot.h"
2425

26+
#define TABLE_UPDATE_SLEEP_US 10
27+
#define TABLE_UPDATE_TIMEOUT_US 100000
28+
2529
/* MAC table entry types.
2630
* ENTRYTYPE_NORMAL is subject to aging.
2731
* ENTRYTYPE_LOCKED is not subject to aging.
@@ -41,23 +45,20 @@ struct ocelot_mact_entry {
4145
enum macaccess_entry_type type;
4246
};
4347

44-
static inline int ocelot_mact_wait_for_completion(struct ocelot *ocelot)
48+
static inline u32 ocelot_mact_read_macaccess(struct ocelot *ocelot)
4549
{
46-
unsigned int val, timeout = 10;
47-
48-
/* Wait for the issued mac table command to be completed, or timeout.
49-
* When the command read from ANA_TABLES_MACACCESS is
50-
* MACACCESS_CMD_IDLE, the issued command completed successfully.
51-
*/
52-
do {
53-
val = ocelot_read(ocelot, ANA_TABLES_MACACCESS);
54-
val &= ANA_TABLES_MACACCESS_MAC_TABLE_CMD_M;
55-
} while (val != MACACCESS_CMD_IDLE && timeout--);
50+
return ocelot_read(ocelot, ANA_TABLES_MACACCESS);
51+
}
5652

57-
if (!timeout)
58-
return -ETIMEDOUT;
53+
static inline int ocelot_mact_wait_for_completion(struct ocelot *ocelot)
54+
{
55+
u32 val;
5956

60-
return 0;
57+
return readx_poll_timeout(ocelot_mact_read_macaccess,
58+
ocelot, val,
59+
(val & ANA_TABLES_MACACCESS_MAC_TABLE_CMD_M) ==
60+
MACACCESS_CMD_IDLE,
61+
TABLE_UPDATE_SLEEP_US, TABLE_UPDATE_TIMEOUT_US);
6162
}
6263

6364
static void ocelot_mact_select(struct ocelot *ocelot,
@@ -129,23 +130,21 @@ static void ocelot_mact_init(struct ocelot *ocelot)
129130
ocelot_write(ocelot, MACACCESS_CMD_INIT, ANA_TABLES_MACACCESS);
130131
}
131132

132-
static inline int ocelot_vlant_wait_for_completion(struct ocelot *ocelot)
133+
static inline u32 ocelot_vlant_read_vlanaccess(struct ocelot *ocelot)
133134
{
134-
unsigned int val, timeout = 10;
135-
136-
/* Wait for the issued vlan table command to be completed, or timeout.
137-
* When the command read from ANA_TABLES_VLANACCESS is
138-
* VLANACCESS_CMD_IDLE, the issued command completed successfully.
139-
*/
140-
do {
141-
val = ocelot_read(ocelot, ANA_TABLES_VLANACCESS);
142-
val &= ANA_TABLES_VLANACCESS_VLAN_TBL_CMD_M;
143-
} while (val != ANA_TABLES_VLANACCESS_CMD_IDLE && timeout--);
135+
return ocelot_read(ocelot, ANA_TABLES_VLANACCESS);
136+
}
144137

145-
if (!timeout)
146-
return -ETIMEDOUT;
138+
static inline int ocelot_vlant_wait_for_completion(struct ocelot *ocelot)
139+
{
140+
u32 val;
147141

148-
return 0;
142+
return readx_poll_timeout(ocelot_vlant_read_vlanaccess,
143+
ocelot,
144+
val,
145+
(val & ANA_TABLES_VLANACCESS_VLAN_TBL_CMD_M) ==
146+
ANA_TABLES_VLANACCESS_CMD_IDLE,
147+
TABLE_UPDATE_SLEEP_US, TABLE_UPDATE_TIMEOUT_US);
149148
}
150149

151150
static int ocelot_vlant_set_mask(struct ocelot *ocelot, u16 vid, u32 mask)

0 commit comments

Comments
 (0)