Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp2298372pxp; Mon, 21 Mar 2022 16:14:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxKiFZbllTxoWGWbpwVteQ1yoomr5TflKK/+3pxf0c1bTwIfcS/H6yapnc7ufHmnRCzYdfF X-Received: by 2002:a65:6a46:0:b0:37f:ef34:7b8e with SMTP id o6-20020a656a46000000b0037fef347b8emr19489696pgu.503.1647904458798; Mon, 21 Mar 2022 16:14:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647904458; cv=none; d=google.com; s=arc-20160816; b=Hnlg1MmDz0qRa8kf0SmZn24qveO2Djo98Plb4LYTn2uAS7QFPs/ClXqqIv7DmGhd/a ix9dIqNBMGacf2qB3czmvZqjO9TqnFvF2cIkVXdd1mK2sBUZTgcmrZOziy24u1mPKeO8 d4J7HttVqT0MIMwoNdXFixRUTEPxdu4tX2tEX/k3RxE2hOeV88NpCy1jsx0N7qKQrtnj 5xkVG1Du73XrpG1NB+qTYTVUcM033ZnlJ7WZEzO7VI619uvv+RFQ1dwgIdr9tCjcE/No TkMN45sQFXB5oPJ30VZnHG6WOM8qZJf7f/RwRJYDzUgluEdRNG1i+xi3sv3AMTuRB98e 01hQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=sowasbuJPQ6qmZWH5YmPzRClrcUKvfC0W1W7ysqdOZo=; b=EOdx7fkZWINmdkl/CmXc8doVmZfweI9s6q2ipTUkrAUHZ2KIxTNhGJ7bDPOq9TI0Tu rtUMiAoHOvzSBPBKh7JSicnscRWlXEYJaAjeL6E8bnFtt6kqSzPhPl6Fm9+aNLIlAkYk wbijWips+2uLUUwdItdWJxSQGgYU9dvIiFp2GzLBDjDk7/PDK6jutzUQ8HCpMPkZ2bMy 1ZBrcA6DTQGSYcsNhcGCiiXLrMcj4a/skXFquZ2zFgUMeaN0VptUYAuWrZpAKddBG/VM oL7qaPUOCKA9D49lkmI291OTmWQMPyQ6IWntvNeyKSsQmJzZ7T/0Ta5/cljM02woaxQT Djdw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@microchip.com header.s=mchp header.b=VkyBcVdK; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=microchip.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id t2-20020a63b242000000b003816043ee71si15274355pgo.102.2022.03.21.16.14.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Mar 2022 16:14:18 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=fail header.i=@microchip.com header.s=mchp header.b=VkyBcVdK; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=microchip.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0C0475A081; Mon, 21 Mar 2022 15:12:25 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240802AbiCRUq6 (ORCPT + 99 others); Fri, 18 Mar 2022 16:46:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44452 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240782AbiCRUqt (ORCPT ); Fri, 18 Mar 2022 16:46:49 -0400 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.153.233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F0B4D30CD8A; Fri, 18 Mar 2022 13:45:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1647636327; x=1679172327; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ENqD6ell0yupK/0eeOO9nyCUymoKCdDskrSLaGyrG+U=; b=VkyBcVdKCipE9d3h8DyJ2sAtgISdEUmJWQtiTxe/tp+GWtz9mnjX0JRK +wRlLUJHAvWw5Eiq6BDKdFWkPJLLDzaDm7KhwUYv6n9dACwSnAFob4OYy IxC8WggoEMDVa3BFDO7/hg2Wp8lUrciJVzdfPOyFdm/B9gTOsBxJbc3a1 FzblzgEgxDtH6PXNGcTeD0hOmSp4pbzG+PW3IuotmXmzf+ecjZV+Sgj1D aw7C6zttm4oJnN6C8eVc0AUTvB9AAJtfUAQYe/zHdrsCDakUZP81fxX6S 1umUGVkmGyb0PsPAm3jK+e7vNGvYN48M72nulq0VOBzZsuCXlJlGG8+Z6 w==; X-IronPort-AV: E=Sophos;i="5.90,192,1643698800"; d="scan'208";a="166351434" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa1.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 18 Mar 2022 13:45:27 -0700 Received: from chn-vm-ex02.mchp-main.com (10.10.85.144) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.17; Fri, 18 Mar 2022 13:45:27 -0700 Received: from soft-dev3-1.microsemi.net (10.10.115.15) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server id 15.1.2375.17 via Frontend Transport; Fri, 18 Mar 2022 13:45:25 -0700 From: Horatiu Vultur To: , CC: , , , , Horatiu Vultur Subject: [PATCH net-next v2 4/4] net: lan966x: Update FDMA to change MTU. Date: Fri, 18 Mar 2022 21:47:50 +0100 Message-ID: <20220318204750.1864134-5-horatiu.vultur@microchip.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20220318204750.1864134-1-horatiu.vultur@microchip.com> References: <20220318204750.1864134-1-horatiu.vultur@microchip.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When changing the MTU, it is required to change also the size of the DBs. In case those frames will arrive to CPU. Signed-off-by: Horatiu Vultur --- .../ethernet/microchip/lan966x/lan966x_fdma.c | 95 +++++++++++++++++++ .../ethernet/microchip/lan966x/lan966x_main.c | 2 +- .../ethernet/microchip/lan966x/lan966x_main.h | 1 + 3 files changed, 97 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c b/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c index c3266d07302d..f3245dd713f4 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c @@ -636,6 +636,101 @@ int lan966x_fdma_xmit(struct sk_buff *skb, __be32 *ifh, struct net_device *dev) return err; } +static int lan966x_fdma_get_max_mtu(struct lan966x *lan966x) +{ + int max_mtu = 0; + int i; + + for (i = 0; i < lan966x->num_phys_ports; ++i) { + int mtu; + + if (!lan966x->ports[i]) + continue; + + mtu = lan966x->ports[i]->dev->mtu; + if (mtu > max_mtu) + max_mtu = mtu; + } + + return max_mtu; +} + +static int lan966x_qsys_sw_status(struct lan966x *lan966x) +{ + return lan_rd(lan966x, QSYS_SW_STATUS(CPU_PORT)); +} + +static void lan966x_fdma_reload(struct lan966x *lan966x, int new_mtu) +{ + void *rx_dcb, *tx_dcb, *tx_dcb_buf; + dma_addr_t rx_dma, tx_dma; + unsigned long flags; + u32 size; + + /* Store these for later to free them */ + rx_dma = lan966x->rx.dma; + tx_dma = lan966x->tx.dma; + rx_dcb = lan966x->rx.dcbs; + tx_dcb = lan966x->tx.dcbs; + tx_dcb_buf = lan966x->tx.dcbs_buf; + + lan966x_fdma_rx_disable(&lan966x->rx); + lan966x_fdma_rx_free_skbs(&lan966x->rx); + lan966x->rx.page_order = round_up(new_mtu, PAGE_SIZE) / PAGE_SIZE - 1; + lan966x_fdma_rx_alloc(&lan966x->rx); + lan966x_fdma_rx_start(&lan966x->rx); + + spin_lock_irqsave(&lan966x->tx_lock, flags); + lan966x_fdma_tx_disable(&lan966x->tx); + lan966x_fdma_tx_alloc(&lan966x->tx); + spin_unlock_irqrestore(&lan966x->tx_lock, flags); + + /* Now it is possible to clean */ + size = sizeof(struct lan966x_tx_dcb) * FDMA_DCB_MAX; + size = ALIGN(size, PAGE_SIZE); + dma_free_coherent(lan966x->dev, size, tx_dcb, tx_dma); + + kfree(tx_dcb_buf); + + size = sizeof(struct lan966x_rx_dcb) * FDMA_DCB_MAX; + size = ALIGN(size, PAGE_SIZE); + dma_free_coherent(lan966x->dev, size, rx_dcb, rx_dma); +} + +int lan966x_fdma_change_mtu(struct lan966x *lan966x) +{ + int max_mtu; + u32 val; + + max_mtu = lan966x_fdma_get_max_mtu(lan966x); + if (round_up(max_mtu, PAGE_SIZE) / PAGE_SIZE - 1 == + lan966x->rx.page_order) + return 0; + + /* Disable the CPU port */ + lan_rmw(QSYS_SW_PORT_MODE_PORT_ENA_SET(0), + QSYS_SW_PORT_MODE_PORT_ENA, + lan966x, QSYS_SW_PORT_MODE(CPU_PORT)); + + /* Flush the CPU queues */ + readx_poll_timeout(lan966x_qsys_sw_status, lan966x, + val, !(QSYS_SW_STATUS_EQ_AVAIL_GET(val)), + READL_SLEEP_US, READL_TIMEOUT_US); + + /* Add a sleep in case there are frames between the queues and the CPU + * port + */ + usleep_range(1000, 2000); + + lan966x_fdma_reload(lan966x, max_mtu); + + /* Enable back the CPU port */ + lan_rmw(QSYS_SW_PORT_MODE_PORT_ENA_SET(1), + QSYS_SW_PORT_MODE_PORT_ENA, + lan966x, QSYS_SW_PORT_MODE(CPU_PORT)); + return 0; +} + void lan966x_fdma_netdev_init(struct lan966x *lan966x, struct net_device *dev) { if (lan966x->fdma_ndev) diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_main.c b/drivers/net/ethernet/microchip/lan966x/lan966x_main.c index 6cb9fffc3058..a78fee5471e7 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_main.c +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_main.c @@ -359,7 +359,7 @@ static int lan966x_port_change_mtu(struct net_device *dev, int new_mtu) lan966x, DEV_MAC_MAXLEN_CFG(port->chip_port)); dev->mtu = new_mtu; - return 0; + return !lan966x->fdma ? 0 : lan966x_fdma_change_mtu(lan966x); } static int lan966x_mc_unsync(struct net_device *dev, const unsigned char *addr) diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_main.h b/drivers/net/ethernet/microchip/lan966x/lan966x_main.h index bfa7feea2b56..fa4016f2b5d4 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_main.h +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_main.h @@ -397,6 +397,7 @@ void lan966x_ptp_txtstamp_release(struct lan966x_port *port, irqreturn_t lan966x_ptp_irq_handler(int irq, void *args); int lan966x_fdma_xmit(struct sk_buff *skb, __be32 *ifh, struct net_device *dev); +int lan966x_fdma_change_mtu(struct lan966x *lan966x); void lan966x_fdma_netdev_init(struct lan966x *lan966x, struct net_device *dev); void lan966x_fdma_netdev_deinit(struct lan966x *lan966x, struct net_device *dev); void lan966x_fdma_init(struct lan966x *lan966x); -- 2.33.0