From patchwork Wed Apr 18 08:33:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Magnus Damm X-Patchwork-Id: 10347583 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 83ABF6053F for ; Wed, 18 Apr 2018 08:32:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7628D285A8 for ; Wed, 18 Apr 2018 08:32:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6AF1A285AA; Wed, 18 Apr 2018 08:32:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B66B2285A8 for ; Wed, 18 Apr 2018 08:32:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753738AbeDRIcf (ORCPT ); Wed, 18 Apr 2018 04:32:35 -0400 Received: from mail-pl0-f66.google.com ([209.85.160.66]:40323 "EHLO mail-pl0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753723AbeDRIcc (ORCPT ); Wed, 18 Apr 2018 04:32:32 -0400 Received: by mail-pl0-f66.google.com with SMTP id t22-v6so679621plo.7 for ; Wed, 18 Apr 2018 01:32:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:date:message-id:in-reply-to:references:subject; bh=zq9NBn/eI8ttnIbyIzrEFfzipv5sYBdq+4GcEE9yZSI=; b=cCuqmms3u5P0IxfBp9NujOLFM679rur9Kv7RK3k7+GrAj2vl3A5KUMw5w1mBf6G7F3 +iEidtsOBN/l34IO7Z1XEmsPr3gS2Ki4yej2KUJbabZg9OQd0jY6g9VuhPxjr5ovBmRW gA26UniYh+vUw+FyiFOT5CoZSR64woB8H6FFsldeZhwI5T2rKZFTNt3ybLvwvWrxOahj jv6ZrcBeEEQjftEpq/0GZJkrbkLxYjLOSEADBOewrwCpBPVjUfju71ihKhJHUxgeqs6N lx7TmatlRyJoIHtoruQXQHk0W73lwlcddL4cawRQ0wxeSu2xRU5EB9OwbHVltEzAGNC2 GASw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:date:message-id:in-reply-to :references:subject; bh=zq9NBn/eI8ttnIbyIzrEFfzipv5sYBdq+4GcEE9yZSI=; b=E4LRkdiH3n/m5uZEUXpP0MI3vb0OSIHP4DnfweYzsNLV/h9SRjCC4xdWyIwrdOOqIa eDrBwaHuxIDbTOxwFt+isB4rt9PhM7jkt5HpBUKYCffW5j42r8Txol8sEFBngsB0C6JJ yMuuYmWZGk9swdzLyasbqAuag2KtwQWB4MRaYOzh/I5f372myFHvGW+pFSQvJxVEtwGk P5gp2G2cZnmyu435PvHKvtDu4NqVAk+ypB5LkiGQcbrJ5/IoakORqadtyT59VA0EEz3y JV5h5zu5aftD5dGYAYzO3p9HDvB1OWLJEyuGy220OCivCMH6Thxgb1mByWUO2EPqG95c lJ1w== X-Gm-Message-State: ALQs6tCy4rpjpGe4fAqeaxuy7K9CtidpQqg39Uiimc9MgRgcfI5C19UM vKzveW8IGB5MgDDspunFE92Cg5O+ X-Google-Smtp-Source: AIpwx48NKAE2yLWLl45gHa39v9JdKx1Y8tibqr7QRgcGul6TrW0FGM7d4GPtgmgz70dg71ppXLgmow== X-Received: by 2002:a17:902:8c94:: with SMTP id t20-v6mr1197497plo.129.1524040351899; Wed, 18 Apr 2018 01:32:31 -0700 (PDT) Received: from [127.0.0.1] (s214090.ppp.asahi-net.or.jp. [220.157.214.90]) by smtp.gmail.com with ESMTPSA id k7sm2202414pfi.77.2018.04.18.01.32.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 Apr 2018 01:32:30 -0700 (PDT) From: Magnus Damm To: linux-renesas-soc@vger.kernel.org Cc: Magnus Damm Date: Wed, 18 Apr 2018 17:33:14 +0900 Message-Id: <152404039431.7843.7752537511570314504.sendpatchset@little-apple> In-Reply-To: <152404037580.7843.5140455339218102749.sendpatchset@little-apple> References: <152404037580.7843.5140455339218102749.sendpatchset@little-apple> Subject: [PATCH 02/03] ravb: MTU support and minor fix Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Magnus Damm This is a back port to v4.16 of the following commits merged in v4.17-rc1: 5c3d0fd4b2c0 ravb: remove erroneous comment 75efa06f457b ravb: add support for changing MTU Thanks to Niklas, Sergei and Dave Miller for the upstreaming efforts. Not-Signed-off-by: Magnus Damm --- drivers/net/ethernet/renesas/ravb.h | 1 drivers/net/ethernet/renesas/ravb_main.c | 33 +++++++++++++++++++++++------- 2 files changed, 27 insertions(+), 7 deletions(-) --- 0001/drivers/net/ethernet/renesas/ravb.h +++ work/drivers/net/ethernet/renesas/ravb.h 2018-04-17 16:47:02.940607110 +0900 @@ -1018,6 +1018,7 @@ struct ravb_private { u32 dirty_rx[NUM_RX_QUEUE]; /* Producer ring indices */ u32 cur_tx[NUM_TX_QUEUE]; u32 dirty_tx[NUM_TX_QUEUE]; + u32 rx_buf_sz; /* Based on MTU+slack. */ struct napi_struct napi[NUM_RX_QUEUE]; struct work_struct work; /* MII transceiver section. */ --- 0001/drivers/net/ethernet/renesas/ravb_main.c +++ work/drivers/net/ethernet/renesas/ravb_main.c 2018-04-17 16:47:12.030607110 +0900 @@ -238,7 +238,7 @@ static void ravb_ring_free(struct net_de le32_to_cpu(desc->dptr))) dma_unmap_single(ndev->dev.parent, le32_to_cpu(desc->dptr), - PKT_BUF_SZ, + priv->rx_buf_sz, DMA_FROM_DEVICE); } ring_size = sizeof(struct ravb_ex_rx_desc) * @@ -300,9 +300,9 @@ static void ravb_ring_format(struct net_ for (i = 0; i < priv->num_rx_ring[q]; i++) { /* RX descriptor */ rx_desc = &priv->rx_ring[q][i]; - rx_desc->ds_cc = cpu_to_le16(PKT_BUF_SZ); + rx_desc->ds_cc = cpu_to_le16(priv->rx_buf_sz); dma_addr = dma_map_single(ndev->dev.parent, priv->rx_skb[q][i]->data, - PKT_BUF_SZ, + priv->rx_buf_sz, DMA_FROM_DEVICE); /* We just set the data size to 0 for a failed mapping which * should prevent DMA from happening... @@ -346,6 +346,9 @@ static int ravb_ring_init(struct net_dev int ring_size; int i; + priv->rx_buf_sz = (ndev->mtu <= 1492 ? PKT_BUF_SZ : ndev->mtu) + + ETH_HLEN + VLAN_HLEN; + /* Allocate RX and TX skb rings */ priv->rx_skb[q] = kcalloc(priv->num_rx_ring[q], sizeof(*priv->rx_skb[q]), GFP_KERNEL); @@ -355,7 +358,7 @@ static int ravb_ring_init(struct net_dev goto error; for (i = 0; i < priv->num_rx_ring[q]; i++) { - skb = netdev_alloc_skb(ndev, PKT_BUF_SZ + RAVB_ALIGN - 1); + skb = netdev_alloc_skb(ndev, priv->rx_buf_sz + RAVB_ALIGN - 1); if (!skb) goto error; ravb_set_buffer_align(skb); @@ -586,7 +589,7 @@ static bool ravb_rx(struct net_device *n skb = priv->rx_skb[q][entry]; priv->rx_skb[q][entry] = NULL; dma_unmap_single(ndev->dev.parent, le32_to_cpu(desc->dptr), - PKT_BUF_SZ, + priv->rx_buf_sz, DMA_FROM_DEVICE); get_ts &= (q == RAVB_NC) ? RAVB_RXTSTAMP_TYPE_V2_L2_EVENT : @@ -619,11 +622,12 @@ static bool ravb_rx(struct net_device *n for (; priv->cur_rx[q] - priv->dirty_rx[q] > 0; priv->dirty_rx[q]++) { entry = priv->dirty_rx[q] % priv->num_rx_ring[q]; desc = &priv->rx_ring[q][entry]; - desc->ds_cc = cpu_to_le16(PKT_BUF_SZ); + desc->ds_cc = cpu_to_le16(priv->rx_buf_sz); if (!priv->rx_skb[q][entry]) { skb = netdev_alloc_skb(ndev, - PKT_BUF_SZ + RAVB_ALIGN - 1); + priv->rx_buf_sz + + RAVB_ALIGN - 1); if (!skb) break; /* Better luck next round. */ ravb_set_buffer_align(skb); @@ -1854,6 +1858,17 @@ static int ravb_do_ioctl(struct net_devi return phy_mii_ioctl(phydev, req, cmd); } +static int ravb_change_mtu(struct net_device *ndev, int new_mtu) +{ + if (netif_running(ndev)) + return -EBUSY; + + ndev->mtu = new_mtu; + netdev_update_features(ndev); + + return 0; +} + static void ravb_set_rx_csum(struct net_device *ndev, bool enable) { struct ravb_private *priv = netdev_priv(ndev); @@ -1895,6 +1910,7 @@ static const struct net_device_ops ravb_ .ndo_set_rx_mode = ravb_set_rx_mode, .ndo_tx_timeout = ravb_tx_timeout, .ndo_do_ioctl = ravb_do_ioctl, + .ndo_change_mtu = ravb_change_mtu, .ndo_validate_addr = eth_validate_addr, .ndo_set_mac_address = eth_mac_addr, .ndo_set_features = ravb_set_features, @@ -2117,6 +2133,9 @@ static int ravb_probe(struct platform_de goto out_release; } + ndev->max_mtu = 2048 - (ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN); + ndev->min_mtu = ETH_MIN_MTU; + /* Set function */ ndev->netdev_ops = &ravb_netdev_ops; ndev->ethtool_ops = &ravb_ethtool_ops;