From patchwork Wed Nov 4 13:45:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthias Schiffer X-Patchwork-Id: 1393944 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ew.tq-group.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=tq-group.com header.i=@tq-group.com header.a=rsa-sha256 header.s=key1 header.b=fIBabziV; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CR7GS324sz9sTL for ; Thu, 5 Nov 2020 00:45:57 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 94E33822EC; Wed, 4 Nov 2020 14:45:38 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=ew.tq-group.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=tq-group.com header.i=@tq-group.com header.b="fIBabziV"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id CA60B82364; Wed, 4 Nov 2020 14:45:36 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mx1.tq-group.com (mx1.tq-group.com [93.104.207.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id BC66B822DF for ; Wed, 4 Nov 2020 14:45:31 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=ew.tq-group.com Authentication-Results: phobos.denx.de; spf=none smtp.mailfrom=matthias.schiffer@ew.tq-group.com IronPort-SDR: XsgkL7wzYE7aq4tu5OQd9QahlGpCV2czPFF7Fj0ZbFwPbO+Wp3P3scgxFO82a6uqLumcvWAtwK OfWSdjmoxtto1sFMTMtOobsjsBynB+ADmkukhPzlZ02Ykt6REBzmOePVNjRLYFdDCFiduCxns9 1hfUKrxmjZ7PUNNw9G9KsOeAWiZSHKZTTTm9qGk806FFi6Jn6A+mQH6bplfEk8Fhhk4ripMiKp i+9cjPJtPsMNHHUtRbf2BFGzm6D8Ul6V/SvCyiq0J+L//J5BvlqvpT7Rnt5vXC7b/c1NE+6M3w /OI= X-IronPort-AV: E=Sophos;i="5.77,451,1596492000"; d="scan'208";a="14580231" Received: from unknown (HELO tq-pgp-pr1.tq-net.de) ([192.168.6.15]) by mx1-pgp.tq-group.com with ESMTP; 04 Nov 2020 14:45:31 +0100 Received: from mx1.tq-group.com ([192.168.6.7]) by tq-pgp-pr1.tq-net.de (PGP Universal service); Wed, 04 Nov 2020 14:45:30 +0100 X-PGP-Universal: processed; by tq-pgp-pr1.tq-net.de on Wed, 04 Nov 2020 14:45:30 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=tq-group.com; i=@tq-group.com; q=dns/txt; s=key1; t=1604497531; x=1636033531; h=from:to:cc:subject:date:message-id; bh=azQ4yd5iJzQTFw1dQszMJFYjQZNTm1HyhMB1BVBlzPQ=; b=fIBabziV9tm8TJC0lBbZNzre414DufuM7cSLu1exnM8D8l1KQJx+psyS lpPWla5iptR+Zf/M5XUQdmTLgazdOx9Sct9wedUky+7Y/q0OrH02wk5Hb N1LMO83+A9uvRtG8vww6oKDxvXFoOJR3FxeSpCIGOmflEwerj69F0iTUR dEjLZ1odplJcKu8ex34+X4voY9jyc72ypJ7s0W/wEBmuWsaqLDO0uGnk/ M7BBs/cJqCXq6QlcBDMXp9HdINjQf32kishUd1vW/YUhzI+yodiMh74XK uI0qDOTD832UcpkklLfRVcGNDBDwbFltHDBpAOG/ESlnhDwFJR0ikRRga A==; IronPort-SDR: pebjUvX3fG0yJHSq3EVEGJfUAsgEw9XX5uYb4V7a8FdyV6J0Iu8eDotuKzZJJQ29dpa86ND60D X8wMmJlc38NWV8ZNi0SQzb+ZfBk4CgXYk59syoStWpWl9ec77xKFRvt1Cgaa7pDz4y3L52Iyiv d3Skus7+rs/eVCPBEpAj9GJXKODf8YpmXs8PbotjHuSEZvUVQlqlLcn1bFdJfg1qeIAAaBwqe5 +m8SAFaM74WXgqY+BCHGZ2B25KPk0G3IC93pvsVS+0LNKaZs70AAbIo/uKYsYdCJhgduaiuvnx gog= X-IronPort-AV: E=Sophos;i="5.77,451,1596492000"; d="scan'208";a="14580230" Received: from vtuxmail01.tq-net.de ([10.115.0.20]) by mx1.tq-group.com with ESMTP; 04 Nov 2020 14:45:31 +0100 Received: from schifferm-ubuntu4.tq-net.de (schifferm-ubuntu4.tq-net.de [10.117.48.12]) by vtuxmail01.tq-net.de (Postfix) with ESMTPA id 0B156280070; Wed, 4 Nov 2020 14:45:31 +0100 (CET) From: Matthias Schiffer To: u-boot@lists.denx.de Cc: Matthias Schiffer Subject: [PATCH] net: eth-uclass: avoid running start() twice without stop() Date: Wed, 4 Nov 2020 14:45:14 +0100 Message-Id: <20201104134514.28413-1-matthias.schiffer@ew.tq-group.com> X-Mailer: git-send-email 2.17.1 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean Running the start() handler twice without a stop() inbetween completely breaks communication for some ethernet drivers like fec_mxc. eth_halt() is called before each eth_init(). Due to the switch to eth_is_active() in commit 68acb51f442f ("net: Only call halt on a driver that has been init'ed"), this is not sufficient anymore when netconsole is active: eth_init_state_only()/eth_halt_state_only() manipulate the state check that is performed by eth_is_active() without actually calling into the driver. The issue can be triggered by starting a network operation (e.g. ping or tftp) while netconsole is active. Add an additional "running" flag that reflects the actual state of the driver and use it to ensure that eth_halt() actually stops the device as it is supposed to. Fixes: 68acb51f442f ("net: Only call halt on a driver that has been init'ed") Signed-off-by: Matthias Schiffer --- net/eth-uclass.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/net/eth-uclass.c b/net/eth-uclass.c index e14695c0f1..7c9278f3a9 100644 --- a/net/eth-uclass.c +++ b/net/eth-uclass.c @@ -26,6 +26,7 @@ DECLARE_GLOBAL_DATA_PTR; */ struct eth_device_priv { enum eth_state_t state; + bool running; }; /** @@ -293,6 +294,7 @@ int eth_init(void) current->uclass_priv; priv->state = ETH_STATE_ACTIVE; + priv->running = true; return 0; } } else { @@ -322,13 +324,16 @@ void eth_halt(void) struct eth_device_priv *priv; current = eth_get_dev(); - if (!current || !eth_is_active(current)) + if (!current) return; - eth_get_ops(current)->stop(current); priv = current->uclass_priv; - if (priv) - priv->state = ETH_STATE_PASSIVE; + if (!priv || !priv->running) + return; + + eth_get_ops(current)->stop(current); + priv->state = ETH_STATE_PASSIVE; + priv->running = false; } int eth_is_active(struct udevice *dev) @@ -537,6 +542,7 @@ static int eth_post_probe(struct udevice *dev) #endif priv->state = ETH_STATE_INIT; + priv->running = false; /* Check if the device has a valid MAC address in device tree */ if (!eth_dev_get_mac_address(dev, pdata->enetaddr) ||