From patchwork Wed Oct 4 22:43:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 148640 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:254a:b0:403:3b70:6f57 with SMTP id hf10csp445946vqb; Wed, 4 Oct 2023 15:44:31 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFOO+OLeOM594R3NkaN+Bdk5Ut3TzMuZOm7EqJ8m7Xd8zjyOXMqOLh63FD+jnr228diR5Ck X-Received: by 2002:a05:6300:8001:b0:167:f3:4a69 with SMTP id an1-20020a056300800100b0016700f34a69mr3225817pzc.35.1696459471051; Wed, 04 Oct 2023 15:44:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696459471; cv=none; d=google.com; s=arc-20160816; b=tGXbcpHQLOL/His4/xebLc1cLbApfqMFdwALxc+QNpRp1QMxXwqX/GYc2LsVM377TR oRhzR8oUmTNdgRkBzhF/RnJZLaElr6acpv1nLsQBd5o1K0eW0Y6ncpB913xd3jw9AQaT JxtC/anTjM9cp51qLivbCGV4rlP8disloME1lsIo8PP27D+N6c8KkMwBE04RA5CTYjPc /L6zRB4yhd1vCCCfr9arb84BUqqN28uEEhtwrV1aFygQ3UoF4ToFFxg9sYHJK6py/pt9 bI9sW46digfyWNieQLXzJWspXefHhlT25z3NE77Yg11Ra0Q9qiUe5PCxP/hffmKjnMA8 ftag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:message-id:content-transfer-encoding :mime-version:subject:date:from:dkim-signature; bh=9lwczMSD98fajqNb6/mKrj3RaEEEuYyEsq8ivVzfMMQ=; fh=LFA6P2eeoE6KYh/J1shss7yViJJseoiBeI3XIOx+aIM=; b=Z0Yv7TKFpFxAJAU1Ym8SbFYdV58wz7pPbk7J2c1/jRhlx6wIdDvFNor1Tsz7DYtdSI B7jovrl+vIhNTOwJM5yM47bNC1dj/0MbSPqdUCwtX8PjTBukRoY+uQY5rKBVE02FgoWm sl2E0n1jbtLLpXToQTFT9WG+AsTntevTlahGMj90Ibd2Z0guwYmhXsf2BUiWz0cN/yFH X6MjSx4S3E/mFXSf9Vtg1Sw2u7texqGScHM/h2vslQ69P6spiAwaT6vYFDbsDsZ2owyB G9bxRG0NcOqrC2UUtrTS+g2HiJGkJt03ZLQ2V8ET3zPoa+D+isS273hljkpyRttjmDfO 1CWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=POYH5bxd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id x13-20020a170902ec8d00b001c6069b659csi149429plg.384.2023.10.04.15.44.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Oct 2023 15:44:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=POYH5bxd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id DB376810AF6E; Wed, 4 Oct 2023 15:44:27 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233905AbjJDWoD (ORCPT + 19 others); Wed, 4 Oct 2023 18:44:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33688 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233822AbjJDWoC (ORCPT ); Wed, 4 Oct 2023 18:44:02 -0400 Received: from mail-lj1-x233.google.com (mail-lj1-x233.google.com [IPv6:2a00:1450:4864:20::233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D3910C6 for ; Wed, 4 Oct 2023 15:43:58 -0700 (PDT) Received: by mail-lj1-x233.google.com with SMTP id 38308e7fff4ca-2c00df105f8so4260661fa.2 for ; Wed, 04 Oct 2023 15:43:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1696459437; x=1697064237; darn=vger.kernel.org; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:from:to:cc:subject:date:message-id:reply-to; bh=9lwczMSD98fajqNb6/mKrj3RaEEEuYyEsq8ivVzfMMQ=; b=POYH5bxdLtDONsG8xkJhf57vUr666w/IZd8CkVh+HrM9Jgk3jXzlryB7C8j2Fec+4k TVvG6IIVv5bFPzX075hMTB85vcq8TehTWRwD2i75us+1yit6gVi20cECGGUGrXm2b/rz tQnwNOjrHe2y7N8zbnEEOI/E3o7IEfms+uS/hCAVl50nQGeflIcqh78ouiqtlREs0q/z ZjRcNIvvyZCcmSDf1BWPmkCQVIgZTuGIASNCnsnpr744JbgFyWT8bHSMrSnco4EmZ0+D 5kdexPl7+g241TFGsIXyqBb6VvfHXaariezadOkzWwbH4TbFflgYO9v3Iq1JtQt7FXOl PlTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696459437; x=1697064237; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=9lwczMSD98fajqNb6/mKrj3RaEEEuYyEsq8ivVzfMMQ=; b=eGRYNl2ftw09qna8x/u9tG/5LBW/CGo4krHRpgKm/+tzP8Adf3EFwzd6XHyb7M+/cy 3TsPZG8mfVH+Yea4CLRyRoqyMd5b70CL4/iQZRQ++RKYP4JPKFYtpzEYj4orrjKHvoaM wuqnvbYpTWNwH8IPAyPsmPV86aCTR8hRTCViYapUZ5pZrFFlbp1RrIFSeYpHulLAnbBs zMoevfU1JSj37wbpJ3gnIlWcQuXyCqh/lHFZLgGyR7VbIxr6/gK1c2WICODlvZATuqfQ d8GmkCCbKoe44xAU0qajNH4fhGnw41Sb9XZ8cBZUW9ms5+hGXAVD3ojuDziebUcjhe8t Kh8g== X-Gm-Message-State: AOJu0YyQUNqvW4Jd/Lxs+000zd3vNQsMNRQu8ykNj/HlDZzCAe1/zb1o BmqHmxPh5aQuFU4llsLUtZSjug== X-Received: by 2002:a05:6512:10ca:b0:505:6785:d6c6 with SMTP id k10-20020a05651210ca00b005056785d6c6mr4328310lfg.54.1696459436663; Wed, 04 Oct 2023 15:43:56 -0700 (PDT) Received: from [192.168.1.2] (c-21d3225c.014-348-6c756e10.bbcust.telenor.se. [92.34.211.33]) by smtp.gmail.com with ESMTPSA id j13-20020a19f50d000000b005041b7735dbsm41646lfb.53.2023.10.04.15.43.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Oct 2023 15:43:56 -0700 (PDT) From: Linus Walleij Date: Thu, 05 Oct 2023 00:43:53 +0200 Subject: [PATCH net-next v4] net: ixp4xx_eth: Support changing the MTU MIME-Version: 1.0 Message-Id: <20231005-ixp4xx-eth-mtu-v4-1-08c66ed0bc69@linaro.org> X-B4-Tracking: v=1; b=H4sIAKjqHWUC/3XNSwrDIBgE4KsE17X4SIh21XuULtT8TYTWBLViC bl7xVVK6HIYvpkVBfAWAro0K/KQbLCzK6E9NchMyo2A7VAyYoRxIhnHNi9tzhjihF/xjQ1p6dD DAyRnqKDFw8PmOnhDDiJ2kCO6l2ayIc7+U58Srf2/0UQxxRKE0JIIoJpdn9YpP59nP9atxPa+O 3hWPJfcKKX7zmhy8HzvxcHz4o2mApQiMGj547dt+wKpf1iPNwEAAA== To: Krzysztof Halasa , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Jacob Keller , Linus Walleij X-Mailer: b4 0.12.3 X-Spam-Status: No, score=2.7 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Wed, 04 Oct 2023 15:44:27 -0700 (PDT) X-Spam-Level: ** X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778866686174001969 X-GMAIL-MSGID: 1778866686174001969 As we don't specify the MTU in the driver, the framework will fall back to 1500 bytes and this doesn't work very well when we try to attach a DSA switch: eth1: mtu greater than device maximum ixp4xx_eth c800a000.ethernet eth1: error -22 setting MTU to 1504 to include DSA overhead After locating an out-of-tree patch in OpenWrt I found suitable code to set the MTU on the interface and ported it and updated it. Now the MTU gets set properly. Reviewed-by: Jacob Keller Signed-off-by: Linus Walleij --- Changes in v4: - Rebase on the merged patch "net: ixp4xx_eth: Specify min/max MTU" so it can be easily applied. - Link to v3: https://lore.kernel.org/r/20230928-ixp4xx-eth-mtu-v3-1-cb18eaa0edb9@linaro.org Changes in v3: - Fix some coding style and initialization style. - Collect Jacob's review tag. - Link to v2: https://lore.kernel.org/r/20230925-ixp4xx-eth-mtu-v2-1-393caab75cb0@linaro.org Changes in v2: - Don't just set min/max MTU: implement the interface for actually changing it as well. - Link to v1: https://lore.kernel.org/r/20230923-ixp4xx-eth-mtu-v1-1-9e88b908e1b2@linaro.org --- drivers/net/ethernet/xscale/ixp4xx_eth.c | 67 +++++++++++++++++++++++++++++--- 1 file changed, 61 insertions(+), 6 deletions(-) --- base-commit: f22d2ec3d4e72d1f24153533ba0ce8fa926cdd37 change-id: 20230923-ixp4xx-eth-mtu-c041d7efe932 Best regards, diff --git a/drivers/net/ethernet/xscale/ixp4xx_eth.c b/drivers/net/ethernet/xscale/ixp4xx_eth.c index 8f40287c8d58..910094ab553c 100644 --- a/drivers/net/ethernet/xscale/ixp4xx_eth.c +++ b/drivers/net/ethernet/xscale/ixp4xx_eth.c @@ -64,7 +64,15 @@ #define POOL_ALLOC_SIZE (sizeof(struct desc) * (RX_DESCS + TX_DESCS)) #define REGS_SIZE 0x1000 -#define MAX_MRU 1536 /* 0x600 */ + +/* MRU is said to be 14320 in a code dump, the SW manual says that + * MRU/MTU is 16320 and includes VLAN and ethernet headers. + * See "IXP400 Software Programmer's Guide" section 10.3.2, page 161. + * + * FIXME: we have chosen the safe default (14320) but if you can test + * jumboframes, experiment with 16320 and see what happens! + */ +#define MAX_MRU (14320 - VLAN_ETH_HLEN) #define RX_BUFF_SIZE ALIGN((NET_IP_ALIGN) + MAX_MRU, 4) #define NAPI_WEIGHT 16 @@ -1183,6 +1191,54 @@ static void destroy_queues(struct port *port) } } +static int ixp4xx_do_change_mtu(struct net_device *dev, int new_mtu) +{ + struct port *port = netdev_priv(dev); + struct npe *npe = port->npe; + int framesize, chunks; + struct msg msg = {}; + + /* adjust for ethernet headers */ + framesize = new_mtu + VLAN_ETH_HLEN; + /* max rx/tx 64 byte chunks */ + chunks = DIV_ROUND_UP(framesize, 64); + + msg.cmd = NPE_SETMAXFRAMELENGTHS; + msg.eth_id = port->id; + + /* Firmware wants to know buffer size in 64 byte chunks */ + msg.byte2 = chunks << 8; + msg.byte3 = chunks << 8; + + msg.byte4 = msg.byte6 = framesize >> 8; + msg.byte5 = msg.byte7 = framesize & 0xff; + + if (npe_send_recv_message(npe, &msg, "ETH_SET_MAX_FRAME_LENGTH")) + return -EIO; + netdev_dbg(dev, "set MTU on NPE %s to %d bytes\n", + npe_name(npe), new_mtu); + + return 0; +} + +static int ixp4xx_eth_change_mtu(struct net_device *dev, int new_mtu) +{ + int ret; + + /* MTU can only be changed when the interface is up. We also + * set the MTU from dev->mtu when opening the device. + */ + if (dev->flags & IFF_UP) { + ret = ixp4xx_do_change_mtu(dev, new_mtu); + if (ret < 0) + return ret; + } + + dev->mtu = new_mtu; + + return 0; +} + static int eth_open(struct net_device *dev) { struct port *port = netdev_priv(dev); @@ -1233,6 +1289,8 @@ static int eth_open(struct net_device *dev) if (npe_send_recv_message(port->npe, &msg, "ETH_SET_FIREWALL_MODE")) return -EIO; + ixp4xx_do_change_mtu(dev, dev->mtu); + if ((err = request_queues(port)) != 0) return err; @@ -1375,6 +1433,7 @@ static int eth_close(struct net_device *dev) static const struct net_device_ops ixp4xx_netdev_ops = { .ndo_open = eth_open, .ndo_stop = eth_close, + .ndo_change_mtu = ixp4xx_eth_change_mtu, .ndo_start_xmit = eth_xmit, .ndo_set_rx_mode = eth_set_mcast_list, .ndo_eth_ioctl = eth_ioctl, @@ -1489,12 +1548,8 @@ static int ixp4xx_eth_probe(struct platform_device *pdev) ndev->dev.dma_mask = dev->dma_mask; ndev->dev.coherent_dma_mask = dev->coherent_dma_mask; - /* Maximum frame size is 16320 bytes and includes VLAN and - * ethernet headers. See "IXP400 Software Programmer's Guide" - * section 10.3.2, page 161. - */ ndev->min_mtu = ETH_MIN_MTU; - ndev->max_mtu = 16320 - VLAN_ETH_HLEN; + ndev->max_mtu = MAX_MRU; netif_napi_add_weight(ndev, &port->napi, eth_poll, NAPI_WEIGHT);