From patchwork Tue Jul 19 01:32:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 12921977 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9DF6FC433EF for ; Tue, 19 Jul 2022 01:51:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=2PssndL4f2fut8KbHa6upiJxFSagNMmu7Hh/copoMME=; b=Ie1qJUKtCE23E/ rNWQu6hPxfgp9jVi0G8g5UUXAI/6Z5s8P2+9dUdW97IvmltlqRljMNnmcB04+o/YdbmMEV4b0XPZ6 qDRet3o050REO7KHDy5RWJqrZHA192bAOIuRTTAbSlfOcxVdmPH6dAacVw/CEtEZWsmff1D9d+tSy zPt9FrjQO+MR102XvDk2WcaOb+ZOcyOOOp36mWN4lOCtnX8ZGkclNWoyn2khSis9KhchqwwnJ4wvf AVbra+s/SgQ+Zwv467GCAc/ajK0v0M+C9JkD3LY/9Xano4buVqquh4KaHSbBmD6gDR3YiI+sKWsHL xFRhzyqPbraY8TubEhvw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oDcNH-003gQ2-QA; Tue, 19 Jul 2022 01:50:11 +0000 Received: from mail-wr1-x433.google.com ([2a00:1450:4864:20::433]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oDcMp-003gIn-T6 for linux-arm-kernel@lists.infradead.org; Tue, 19 Jul 2022 01:49:45 +0000 Received: by mail-wr1-x433.google.com with SMTP id d16so19485364wrv.10 for ; Mon, 18 Jul 2022 18:49:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=LlfQtelztTsNiTqcVZLiFHCSHDMpr2L71yJcP2UP5Tc=; b=ix6JP89EESpFq6vPoyv42Rmw9s1JazmPo2Qt0NnDqNPha4M0FF3HuJ37klC7aI6SLh mX/tXnXMA44du9BgEn20TGrV69Re3MCo5lc05ok4xi8mFQPPnpsSbsWF3/aQzkHzBiya yw+NdH5j9rB9ph/HTzcuBs3+1qoFGhh4NQQT0mdOmTFSJ0ZvAKcxWoaOsdSCXFvjSV5w X/4FUy5YOSiMtP8EDtavKmvLCwhVxX1MZwleusEjpHjn5qTM6gVzBCLrftuWZt2bUL93 uxih86BRt9YPQ1KPGkO/Dt+OVZ9+wJ17irhzXjCfQ/qbOgtZr1lPV1Qh6jqcy2RrhBNY adtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=LlfQtelztTsNiTqcVZLiFHCSHDMpr2L71yJcP2UP5Tc=; b=aGlrWqrgQJorfeiFl3l4PIAT2BeQIb/jVWRURpntys0ogMW1K1/kq6zKvkhQa4XgI8 Zs216TUATWNBvkQK1Rh3l3U0eEsely3NS7BX2IbuFLA16ApPrIz3zhVff0Y7dYjTbZ3Q 3exF1R4WpXJP1Omqtv3PIM/v1chPkd+r6Q4zJ/ZLTuHqHn+xsDbkvLDyuTd6vOAoO1ZG cDYGAn/8gNtDXHPDy5QQlBHa1msJjV+qkysEqEJulxEX9h2Fxs/J+THIUjBtzFvhPWsX Dps2W1m8uJTCMT+MlhQQDb1VklI0+2AC/ObcTWcNeesndcuGykWlyOL6yRadhv9HUdHc zN8A== X-Gm-Message-State: AJIora8N2tnEt5HqkoAFB3kQXljtQYDJmzNUvbh9fcISxSWSPEvUA1AD HTGKJdUpDXP9Cd475yeZliw= X-Google-Smtp-Source: AGRyM1sotsOcKG/9pLDZZ7aw8EvbuQ4EGef5Wv/ScQtYnvD7MPxwSRbvCBr70W1/CiFdJdc05vp9sQ== X-Received: by 2002:a5d:4a8f:0:b0:21e:28a8:f44d with SMTP id o15-20020a5d4a8f000000b0021e28a8f44dmr3046841wrq.663.1658195375865; Mon, 18 Jul 2022 18:49:35 -0700 (PDT) Received: from localhost.localdomain (93-42-70-190.ip85.fastwebnet.it. [93.42.70.190]) by smtp.googlemail.com with ESMTPSA id v10-20020a05600c428a00b003a2fc754313sm16193600wmc.10.2022.07.18.18.49.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Jul 2022 18:49:35 -0700 (PDT) From: Christian Marangi To: Giuseppe Cavallaro , Alexandre Torgue , Jose Abreu , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Maxime Coquelin , Russell King , netdev@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Christian Marangi Subject: [net-next PATCH v4 5/5] net: ethernet: stmicro: stmmac: permit MTU change with interface up Date: Tue, 19 Jul 2022 03:32:19 +0200 Message-Id: <20220719013219.11843-6-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220719013219.11843-1-ansuelsmth@gmail.com> References: <20220719013219.11843-1-ansuelsmth@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220718_184943_958126_3FE85937 X-CRM114-Status: GOOD ( 19.57 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Remove the limitation where the interface needs to be down to change MTU by releasing and opening the stmmac driver to set the new MTU. Also call the set_filter function to correctly init the port. This permits to remove the EBUSY error while the ethernet port is running permitting a correct MTU change if for example a DSA request a MTU change for a switch CPU port. Signed-off-by: Christian Marangi --- .../net/ethernet/stmicro/stmmac/stmmac_main.c | 30 +++++++++++++++---- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index a3bb132db3a5..1eda1e1038b4 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -5551,18 +5551,15 @@ static int stmmac_change_mtu(struct net_device *dev, int new_mtu) { struct stmmac_priv *priv = netdev_priv(dev); int txfifosz = priv->plat->tx_fifo_size; + struct stmmac_dma_conf *dma_conf; const int mtu = new_mtu; + int ret; if (txfifosz == 0) txfifosz = priv->dma_cap.tx_fifo_size; txfifosz /= priv->plat->tx_queues_to_use; - if (netif_running(dev)) { - netdev_err(priv->dev, "must be stopped to change its MTU\n"); - return -EBUSY; - } - if (stmmac_xdp_is_enabled(priv) && new_mtu > ETH_DATA_LEN) { netdev_dbg(priv->dev, "Jumbo frames not supported for XDP\n"); return -EINVAL; @@ -5574,8 +5571,29 @@ static int stmmac_change_mtu(struct net_device *dev, int new_mtu) if ((txfifosz < new_mtu) || (new_mtu > BUF_SIZE_16KiB)) return -EINVAL; - dev->mtu = mtu; + if (netif_running(dev)) { + netdev_dbg(priv->dev, "restarting interface to change its MTU\n"); + /* Try to allocate the new DMA conf with the new mtu */ + dma_conf = stmmac_setup_dma_desc(priv, mtu); + if (IS_ERR(dma_conf)) { + netdev_err(priv->dev, "failed allocating new dma conf for new MTU %d\n", + mtu); + return PTR_ERR(dma_conf); + } + stmmac_release(dev); + + ret = __stmmac_open(dev, dma_conf); + kfree(dma_conf); + if (ret) { + netdev_err(priv->dev, "failed reopening the interface after MTU change\n"); + return ret; + } + + stmmac_set_rx_mode(dev); + } + + dev->mtu = mtu; netdev_update_features(dev); return 0;