Commit 4893b8b3 authored by Lukasz Majewski's avatar Lukasz Majewski Committed by Jakub Kicinski

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: f421436a ("net/hsr: Add support for the High-availability Seamless Redundancy protocol (HSRv0)")
Signed-off-by: default avatarLukasz Majewski <lukma@denx.de>
Reviewed-by: default avatarSimon Horman <horms@kernel.org>
Link: https://lore.kernel.org/r/20240507111214.3519800-1-lukma@denx.deSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent d101291b
...@@ -61,39 +61,36 @@ static bool hsr_check_carrier(struct hsr_port *master) ...@@ -61,39 +61,36 @@ static bool hsr_check_carrier(struct hsr_port *master)
return false; return false;
} }
static void hsr_check_announce(struct net_device *hsr_dev, static void hsr_check_announce(struct net_device *hsr_dev)
unsigned char old_operstate)
{ {
struct hsr_priv *hsr; struct hsr_priv *hsr;
hsr = netdev_priv(hsr_dev); hsr = netdev_priv(hsr_dev);
if (netif_running(hsr_dev) && netif_oper_up(hsr_dev)) {
if (READ_ONCE(hsr_dev->operstate) == IF_OPER_UP && old_operstate != IF_OPER_UP) { /* Enable announce timer and start sending supervisory frames */
/* Went up */ if (!timer_pending(&hsr->announce_timer)) {
hsr->announce_count = 0; hsr->announce_count = 0;
mod_timer(&hsr->announce_timer, mod_timer(&hsr->announce_timer, jiffies +
jiffies + msecs_to_jiffies(HSR_ANNOUNCE_INTERVAL)); msecs_to_jiffies(HSR_ANNOUNCE_INTERVAL));
}
} else {
/* Deactivate the announce timer */
timer_delete(&hsr->announce_timer);
} }
if (READ_ONCE(hsr_dev->operstate) != IF_OPER_UP && old_operstate == IF_OPER_UP)
/* Went down */
del_timer(&hsr->announce_timer);
} }
void hsr_check_carrier_and_operstate(struct hsr_priv *hsr) void hsr_check_carrier_and_operstate(struct hsr_priv *hsr)
{ {
struct hsr_port *master; struct hsr_port *master;
unsigned char old_operstate;
bool has_carrier; bool has_carrier;
master = hsr_port_get_hsr(hsr, HSR_PT_MASTER); master = hsr_port_get_hsr(hsr, HSR_PT_MASTER);
/* netif_stacked_transfer_operstate() cannot be used here since /* netif_stacked_transfer_operstate() cannot be used here since
* it doesn't set IF_OPER_LOWERLAYERDOWN (?) * it doesn't set IF_OPER_LOWERLAYERDOWN (?)
*/ */
old_operstate = READ_ONCE(master->dev->operstate);
has_carrier = hsr_check_carrier(master); has_carrier = hsr_check_carrier(master);
hsr_set_operstate(master, has_carrier); hsr_set_operstate(master, has_carrier);
hsr_check_announce(master->dev, old_operstate); hsr_check_announce(master->dev);
} }
int hsr_get_max_mtu(struct hsr_priv *hsr) int hsr_get_max_mtu(struct hsr_priv *hsr)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment