Skip to content

Commit 4893b8b

Browse files
Lukasz Majewskikuba-moo
authored andcommitted
hsr: Simplify code for announcing HSR nodes timer setup
Up till now the code to start HSR announce timer, which triggers sending supervisory frames, was assuming that hsr_netdev_notify() would be called at least twice for hsrX interface. This was required to have different values for old and current values of network device's operstate. This is problematic for a case where hsrX interface is already in the operational state when hsr_netdev_notify() is called, so timer is not configured to trigger and as a result the hsrX is not sending supervisory frames to HSR ring. This error has been discovered when hsr_ping.sh script was run. To be more specific - for the hsr1 and hsr2 the hsr_netdev_notify() was called at least twice with different IF_OPER_{LOWERDOWN|DOWN|UP} states assigned in hsr_check_carrier_and_operstate(hsr). As a result there was no issue with sending supervisory frames. However, with hsr3, the notify function was called only once with operstate set to IF_OPER_UP and timer responsible for triggering supervisory frames was not fired. The solution is to use netif_oper_up() and netif_running() helper functions to assess if network hsrX device is up. Only then, when the timer is not already pending, it is started. Otherwise it is deactivated. Fixes: f421436 ("net/hsr: Add support for the High-availability Seamless Redundancy protocol (HSRv0)") Signed-off-by: Lukasz Majewski <lukma@denx.de> Reviewed-by: Simon Horman <horms@kernel.org> Link: https://lore.kernel.org/r/20240507111214.3519800-1-lukma@denx.de Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent d101291 commit 4893b8b

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

net/hsr/hsr_device.c

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -61,39 +61,36 @@ static bool hsr_check_carrier(struct hsr_port *master)
6161
return false;
6262
}
6363

64-
static void hsr_check_announce(struct net_device *hsr_dev,
65-
unsigned char old_operstate)
64+
static void hsr_check_announce(struct net_device *hsr_dev)
6665
{
6766
struct hsr_priv *hsr;
6867

6968
hsr = netdev_priv(hsr_dev);
70-
71-
if (READ_ONCE(hsr_dev->operstate) == IF_OPER_UP && old_operstate != IF_OPER_UP) {
72-
/* Went up */
73-
hsr->announce_count = 0;
74-
mod_timer(&hsr->announce_timer,
75-
jiffies + msecs_to_jiffies(HSR_ANNOUNCE_INTERVAL));
69+
if (netif_running(hsr_dev) && netif_oper_up(hsr_dev)) {
70+
/* Enable announce timer and start sending supervisory frames */
71+
if (!timer_pending(&hsr->announce_timer)) {
72+
hsr->announce_count = 0;
73+
mod_timer(&hsr->announce_timer, jiffies +
74+
msecs_to_jiffies(HSR_ANNOUNCE_INTERVAL));
75+
}
76+
} else {
77+
/* Deactivate the announce timer */
78+
timer_delete(&hsr->announce_timer);
7679
}
77-
78-
if (READ_ONCE(hsr_dev->operstate) != IF_OPER_UP && old_operstate == IF_OPER_UP)
79-
/* Went down */
80-
del_timer(&hsr->announce_timer);
8180
}
8281

8382
void hsr_check_carrier_and_operstate(struct hsr_priv *hsr)
8483
{
8584
struct hsr_port *master;
86-
unsigned char old_operstate;
8785
bool has_carrier;
8886

8987
master = hsr_port_get_hsr(hsr, HSR_PT_MASTER);
9088
/* netif_stacked_transfer_operstate() cannot be used here since
9189
* it doesn't set IF_OPER_LOWERLAYERDOWN (?)
9290
*/
93-
old_operstate = READ_ONCE(master->dev->operstate);
9491
has_carrier = hsr_check_carrier(master);
9592
hsr_set_operstate(master, has_carrier);
96-
hsr_check_announce(master->dev, old_operstate);
93+
hsr_check_announce(master->dev);
9794
}
9895

9996
int hsr_get_max_mtu(struct hsr_priv *hsr)

0 commit comments

Comments
 (0)