Received: by 2002:a89:48b:0:b0:1f5:f2ab:c469 with SMTP id a11csp1204693lqd; Thu, 25 Apr 2024 08:40:39 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWyIDLchvS9ubUPZ5sjy/n+1WMXmW1TxlXIZccH2fVJ4LG88iDzAiRHcN3YEwgAwU+gMAV/ggmyRnsZ7JFpyfT1vYxPctGB2IMsY5ToZA== X-Google-Smtp-Source: AGHT+IF97Io2z1F+6s0tNjgm23gLk8rIUmyL+nqQYSFmMgkYpvxY0nytI/xL5XA8HDtdv7PZLfD1 X-Received: by 2002:a05:6a21:3286:b0:1ac:3660:4831 with SMTP id yt6-20020a056a21328600b001ac36604831mr62627pzb.1.1714059639032; Thu, 25 Apr 2024 08:40:39 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714059639; cv=pass; d=google.com; s=arc-20160816; b=APlR4qlqJq1RZYz0ZAtl+Hjz/FbZw1Knly70Gb4LDcbFQ6Zz+sg4eXw0/qVzEWbhVe FcwXrYgetnAuTv8TnBhHRHT8gXfKOQ+9Ce4HChB77+MCC2/Hm0bNsqeaMf1lMv29X1fP XDMUrlCU6RCzkMsilcCmbWwB7KgAlHYFbhGW/+D0XHnessq3BQroA2/m2dPU4bFxctxV qhTi8RF0HPEW0P6aLLuD7JREAGIrqblEJEq03G4L6jZAl76WgTXRb5NJywKiT6tAmOzg t8NtOwd79U1AwjY+AK1PmSmDRzlRINIOd5Mo+4ew43B0X0qYV8erFpWjdm+nIenkGMcK LazA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=u//hZdEDeqpd2RqtJe+A8Jdt/tG07v39FbGKhW8tvuk=; fh=iX722pVzQZiPnWYcuZ9GIgONbBh7gnE6P4JCe1DSaeQ=; b=X5Pp3Of0zIHHcbo10KAzS1R5UB0Gt9mx1TBMYU/CShZiF7u9yEWh6kkN0Sxst2gKkP oCDxYdGELIixCITadJp9zIXP/7UV2sL6HrKDtDDMeS+WLJc7tImK/BRtbRK98c22GsEA 29Ky1NZl7EyWgbDyozKi9N03HlaS/TqvcANUnQ6WRlXGVOzM4S5Uv6r3sVZ9OzhhryE4 08yp+ZqhYLHOcDsJX23cXtNp/+Yl5MPz4/NrccJj7nY4DbitVHEn6NxmVmbPfrQu8Jx4 yCrdCDZ5tV2SuKKWur/Y7Yh2gBk0toMYXbqwMjwVXKEXkbmPdV/yzugzoMMMHlRUu4XB IC1Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@denx.de header.s=phobos-20191101 header.b=LbP6KbGP; arc=pass (i=1 spf=pass spfdomain=denx.de dkim=pass dkdomain=denx.de dmarc=pass fromdomain=denx.de); spf=pass (google.com: domain of linux-kernel+bounces-158822-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-158822-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=denx.de Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id o17-20020a056a00215100b006ed189a99f1si13454161pfk.345.2024.04.25.08.40.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Apr 2024 08:40:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-158822-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@denx.de header.s=phobos-20191101 header.b=LbP6KbGP; arc=pass (i=1 spf=pass spfdomain=denx.de dkim=pass dkdomain=denx.de dmarc=pass fromdomain=denx.de); spf=pass (google.com: domain of linux-kernel+bounces-158822-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-158822-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=denx.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 7EEF2282395 for ; Thu, 25 Apr 2024 15:40:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 840FA14C584; Thu, 25 Apr 2024 15:40:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=denx.de header.i=@denx.de header.b="LbP6KbGP" Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CD8EF14B086; Thu, 25 Apr 2024 15:40:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=85.214.62.61 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714059627; cv=none; b=WU1EQ51rCLuQW4jfe5BYu5rtzSw0emZeZi6AL/JGviPr5NNb76+15ivA8/6c8V17TW0Rv7I7Vem1iNN//Ar1eErjO3NUMIhfusGaET9k2VffzH3TP6d507eCN/fwNCQV3wTVjM2rfu0Re4JBtnx860XiATSGBDY2uGEDnBQJ1Ho= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714059627; c=relaxed/simple; bh=NeAGDssrBE1nQvK6n7Y2DS9FDrRvGrFq+guTHdUb4h8=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=tnzCeei0YJhm5ip8dfgH5iGwiEWX91XcqLTkFlOzgl1D8sQBN4FN8+KKgzVevlk+oLwUeEoe2Ot15UlcCBirRzEW16gURfIqNGOB+6wd8Nei56If1hYETA0X1MZihpM3ECf1dQdmtL0/DmlQWVJQc4mMgwhAL5zyRZxunp513Ok= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=denx.de; spf=pass smtp.mailfrom=denx.de; dkim=pass (2048-bit key) header.d=denx.de header.i=@denx.de header.b=LbP6KbGP; arc=none smtp.client-ip=85.214.62.61 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=denx.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=denx.de Received: from localhost.localdomain (85-222-111-42.dynamic.chello.pl [85.222.111.42]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: lukma@denx.de) by phobos.denx.de (Postfix) with ESMTPSA id 1C0FC88FBA; Thu, 25 Apr 2024 17:40:16 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1714059617; bh=u//hZdEDeqpd2RqtJe+A8Jdt/tG07v39FbGKhW8tvuk=; h=From:To:Cc:Subject:Date:From; b=LbP6KbGPMWulym3/278+9gtPppW5KiwrVyc3Y5STTU1TGaYIzT+aHVdfvVpJ/BA4/ LzFp3/LGj/wgm/f5MTkKoDlD4q9MuyMxxhf8GOfxYgvR4TC90pcDgrC+qxvSgPkxiK ehF3jh3z1KrKckCgUpGhi2OIfjZol2kGdxcu8HXBDKLQjuT01KuiLp7OcwGbPHAXFx IWfp+iN+XLcGQXiTuGRKQ2vlBhXrlN680HfLCzFGScECzZkrbEoU27ads0pATEQIjB P83M+koOxY1vdI+wkGApQJmaWuKhKjR9R4ytV+CiuTU8pP0zovTj/2tPQRzND/KY5x F5WhymIsutHmA== From: Lukasz Majewski To: netdev@vger.kernel.org, Paolo Abeni , Casper Andersson Cc: Andrew Lunn , Eric Dumazet , Vladimir Oltean , "David S. Miller" , Jakub Kicinski , Oleksij Rempel , Tristram.Ha@microchip.com, Sebastian Andrzej Siewior , Ravi Gunasekaran , Simon Horman , Nikita Zhandarovich , Murali Karicheri , Jiri Pirko , Dan Carpenter , Ziyang Xuan , Shigeru Yoshida , "Ricardo B. Marliere" , linux-kernel@vger.kernel.org, Lukasz Majewski Subject: [net-next PATCH] hsr: Simplify code for announcing HSR nodes timer setup Date: Thu, 25 Apr 2024 17:39:58 +0200 Message-Id: <20240425153958.2326772-1-lukma@denx.de> X-Mailer: git-send-email 2.39.2 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean 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() helper function to assess if network device is up and then setup timer. Otherwise the timer is activated. Signed-off-by: Lukasz Majewski --- net/hsr/hsr_device.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/net/hsr/hsr_device.c b/net/hsr/hsr_device.c index cd1e7c6d2fc0..e91d897e2cee 100644 --- a/net/hsr/hsr_device.c +++ b/net/hsr/hsr_device.c @@ -61,39 +61,34 @@ static bool hsr_check_carrier(struct hsr_port *master) return false; } -static void hsr_check_announce(struct net_device *hsr_dev, - unsigned char old_operstate) +static void hsr_check_announce(struct net_device *hsr_dev) { struct hsr_priv *hsr; hsr = netdev_priv(hsr_dev); - - if (READ_ONCE(hsr_dev->operstate) == IF_OPER_UP && old_operstate != IF_OPER_UP) { + if (netif_oper_up(hsr_dev)) { /* Went up */ hsr->announce_count = 0; mod_timer(&hsr->announce_timer, jiffies + msecs_to_jiffies(HSR_ANNOUNCE_INTERVAL)); - } - - if (READ_ONCE(hsr_dev->operstate) != IF_OPER_UP && old_operstate == IF_OPER_UP) + } else { /* Went down */ del_timer(&hsr->announce_timer); + } } void hsr_check_carrier_and_operstate(struct hsr_priv *hsr) { struct hsr_port *master; - unsigned char old_operstate; bool has_carrier; master = hsr_port_get_hsr(hsr, HSR_PT_MASTER); /* netif_stacked_transfer_operstate() cannot be used here since * it doesn't set IF_OPER_LOWERLAYERDOWN (?) */ - old_operstate = READ_ONCE(master->dev->operstate); has_carrier = hsr_check_carrier(master); 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) -- 2.20.1