From patchwork Tue Nov 23 13:31:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Biju Das X-Patchwork-Id: 12634173 X-Patchwork-Delegate: kuba@kernel.org 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7BF2BC433FE for ; Tue, 23 Nov 2021 13:32:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230469AbhKWNfP (ORCPT ); Tue, 23 Nov 2021 08:35:15 -0500 Received: from relmlor1.renesas.com ([210.160.252.171]:20924 "EHLO relmlie5.idc.renesas.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229599AbhKWNfP (ORCPT ); Tue, 23 Nov 2021 08:35:15 -0500 X-IronPort-AV: E=Sophos;i="5.87,257,1631545200"; d="scan'208";a="101152354" Received: from unknown (HELO relmlir6.idc.renesas.com) ([10.200.68.152]) by relmlie5.idc.renesas.com with ESMTP; 23 Nov 2021 22:32:06 +0900 Received: from localhost.localdomain (unknown [10.226.93.159]) by relmlir6.idc.renesas.com (Postfix) with ESMTP id A67154298F4C; Tue, 23 Nov 2021 22:32:03 +0900 (JST) From: Biju Das To: "David S. Miller" , Jakub Kicinski Cc: Biju Das , Sergey Shtylyov , Lad Prabhakar , Yoshihiro Shimoda , netdev@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Geert Uytterhoeven , Chris Paterson , Biju Das Subject: [RFC 1/2] ravb: Fillup ravb_set_features_gbeth() stub Date: Tue, 23 Nov 2021 13:31:56 +0000 Message-Id: <20211123133157.21829-2-biju.das.jz@bp.renesas.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211123133157.21829-1-biju.das.jz@bp.renesas.com> References: <20211123133157.21829-1-biju.das.jz@bp.renesas.com> Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Fillup ravb_set_features_gbeth() function to support RZ/G2L. Also set the net_hw_features bits with rx checksum offload supported by TOE. Signed-off-by: Biju Das --- drivers/net/ethernet/renesas/ravb.h | 16 ++++++++++++++++ drivers/net/ethernet/renesas/ravb_main.c | 24 +++++++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/renesas/ravb.h b/drivers/net/ethernet/renesas/ravb.h index 08062d73df10..a96552348e2d 100644 --- a/drivers/net/ethernet/renesas/ravb.h +++ b/drivers/net/ethernet/renesas/ravb.h @@ -205,6 +205,7 @@ enum ravb_reg { RFCR = 0x0760, MAFCR = 0x0778, CSR0 = 0x0800, /* RZ/G2L only */ + CSR2 = 0x0808, /* RZ/G2L only */ }; @@ -970,6 +971,21 @@ enum CSR0_BIT { CSR0_RPE = 0x00000020, }; +enum CSR2_BIT { + CSR2_RIP4 = 0x00000001, + CSR2_RTCP4 = 0x00000010, + CSR2_RUDP4 = 0x00000020, + CSR2_RICMP4 = 0x00000040, + CSR2_RTCP6 = 0x00100000, + CSR2_RUDP6 = 0x00200000, + CSR2_RICMP6 = 0x00400000, + CSR2_RHOP = 0x01000000, + CSR2_RROUT = 0x02000000, + CSR2_RAHD = 0x04000000, + CSR2_RDHD = 0x08000000, + CSR2_ALL = 0x0F700071, +}; + #define DBAT_ENTRY_NUM 22 #define RX_QUEUE_OFFSET 4 #define NUM_RX_QUEUE 2 diff --git a/drivers/net/ethernet/renesas/ravb_main.c b/drivers/net/ethernet/renesas/ravb_main.c index ce09bd45527e..c2b92c6a6cd2 100644 --- a/drivers/net/ethernet/renesas/ravb_main.c +++ b/drivers/net/ethernet/renesas/ravb_main.c @@ -2314,7 +2314,28 @@ static void ravb_set_rx_csum(struct net_device *ndev, bool enable) static int ravb_set_features_gbeth(struct net_device *ndev, netdev_features_t features) { - /* Place holder */ + netdev_features_t changed = ndev->features ^ features; + u32 csr0 = ravb_read(ndev, CSR0); + int error; + + ravb_write(ndev, csr0 & ~(CSR0_RPE | CSR0_TPE), CSR0); + error = ravb_wait(ndev, CSR0, CSR0_RPE | CSR0_TPE, 0); + if (error) { + ravb_write(ndev, csr0, CSR0); + return error; + } + + if (changed & NETIF_F_RXCSUM) { + if (features & NETIF_F_RXCSUM) + ravb_write(ndev, CSR2_ALL, CSR2); + else + ravb_write(ndev, 0, CSR2); + } + + ravb_write(ndev, csr0, CSR0); + + ndev->features = features; + return 0; } @@ -2457,6 +2478,7 @@ static const struct ravb_hw_info gbeth_hw_info = { .set_feature = ravb_set_features_gbeth, .dmac_init = ravb_dmac_init_gbeth, .emac_init = ravb_emac_init_gbeth, + .net_hw_features = NETIF_F_RXCSUM, .gstrings_stats = ravb_gstrings_stats_gbeth, .gstrings_size = sizeof(ravb_gstrings_stats_gbeth), .stats_len = ARRAY_SIZE(ravb_gstrings_stats_gbeth), From patchwork Tue Nov 23 13:31:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Biju Das X-Patchwork-Id: 12634175 X-Patchwork-Delegate: kuba@kernel.org 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0A6D9C4332F for ; Tue, 23 Nov 2021 13:32:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233959AbhKWNfR (ORCPT ); Tue, 23 Nov 2021 08:35:17 -0500 Received: from relmlor2.renesas.com ([210.160.252.172]:50482 "EHLO relmlie6.idc.renesas.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229599AbhKWNfR (ORCPT ); Tue, 23 Nov 2021 08:35:17 -0500 X-IronPort-AV: E=Sophos;i="5.87,257,1631545200"; d="scan'208";a="101513529" Received: from unknown (HELO relmlir6.idc.renesas.com) ([10.200.68.152]) by relmlie6.idc.renesas.com with ESMTP; 23 Nov 2021 22:32:08 +0900 Received: from localhost.localdomain (unknown [10.226.93.159]) by relmlir6.idc.renesas.com (Postfix) with ESMTP id 7D45F4298F4C; Tue, 23 Nov 2021 22:32:06 +0900 (JST) From: Biju Das To: "David S. Miller" , Jakub Kicinski Cc: Biju Das , Sergey Shtylyov , Lad Prabhakar , Yoshihiro Shimoda , netdev@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Geert Uytterhoeven , Chris Paterson , Biju Das Subject: [RFC 2/2] ravb: Add Rx checksum offload support Date: Tue, 23 Nov 2021 13:31:57 +0000 Message-Id: <20211123133157.21829-3-biju.das.jz@bp.renesas.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211123133157.21829-1-biju.das.jz@bp.renesas.com> References: <20211123133157.21829-1-biju.das.jz@bp.renesas.com> Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC TOE has hw support for calculating IP header checkum for IPV4 and TCP/UDP/ICMP checksum for both IPV4 and IPV6. This patch adds Rx checksum offload supported by TOE. Signed-off-by: Biju Das --- drivers/net/ethernet/renesas/ravb.h | 4 +++ drivers/net/ethernet/renesas/ravb_main.c | 31 ++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/drivers/net/ethernet/renesas/ravb.h b/drivers/net/ethernet/renesas/ravb.h index a96552348e2d..d0e5eec0636e 100644 --- a/drivers/net/ethernet/renesas/ravb.h +++ b/drivers/net/ethernet/renesas/ravb.h @@ -44,6 +44,10 @@ #define RAVB_RXTSTAMP_TYPE_ALL 0x00000006 #define RAVB_RXTSTAMP_ENABLED 0x00000010 /* Enable RX timestamping */ +/* GbEthernet TOE hardware checksum values */ +#define TOE_RX_CSUM_OK 0x0000 +#define TOE_RX_CSUM_UNSUPPORTED 0xFFFF + enum ravb_reg { /* AVB-DMAC registers */ CCC = 0x0000, diff --git a/drivers/net/ethernet/renesas/ravb_main.c b/drivers/net/ethernet/renesas/ravb_main.c index c2b92c6a6cd2..2533e3401593 100644 --- a/drivers/net/ethernet/renesas/ravb_main.c +++ b/drivers/net/ethernet/renesas/ravb_main.c @@ -720,6 +720,33 @@ static void ravb_get_tx_tstamp(struct net_device *ndev) } } +static void ravb_rx_csum_gbeth(struct sk_buff *skb) +{ + u32 csum_ip_hdr, csum_proto; + u8 *hw_csum; + + /* The hardware checksum is contained in sizeof(__sum16) * 2 = 4 bytes + * appended to packet data. First 2 bytes is ip header csum and last + * 2 bytes is protocol csum. + */ + if (unlikely(skb->len < sizeof(__sum16) * 2)) + return; + hw_csum = skb_tail_pointer(skb) - sizeof(__sum16); + csum_proto = csum_unfold((__force __sum16)get_unaligned_le16(hw_csum)); + + hw_csum = skb_tail_pointer(skb) - 2 * sizeof(__sum16); + csum_ip_hdr = csum_unfold((__force __sum16)get_unaligned_le16(hw_csum)); + + skb->ip_summed = CHECKSUM_NONE; + if (csum_proto == TOE_RX_CSUM_OK) { + if (skb->protocol == htons(ETH_P_IP) && csum_ip_hdr == TOE_RX_CSUM_OK) + skb->ip_summed = CHECKSUM_UNNECESSARY; + else if (skb->protocol == htons(ETH_P_IPV6) && + csum_ip_hdr == TOE_RX_CSUM_UNSUPPORTED) + skb->ip_summed = CHECKSUM_UNNECESSARY; + } +} + static void ravb_rx_csum(struct sk_buff *skb) { u8 *hw_csum; @@ -805,6 +832,8 @@ static bool ravb_rx_gbeth(struct net_device *ndev, int *quota, int q) skb = ravb_get_skb_gbeth(ndev, entry, desc); skb_put(skb, pkt_len); skb->protocol = eth_type_trans(skb, ndev); + if (ndev->features & NETIF_F_RXCSUM) + ravb_rx_csum_gbeth(skb); napi_gro_receive(&priv->napi[q], skb); stats->rx_packets++; stats->rx_bytes += pkt_len; @@ -832,6 +861,8 @@ static bool ravb_rx_gbeth(struct net_device *ndev, int *quota, int q) dev_kfree_skb(skb); priv->rx_1st_skb->protocol = eth_type_trans(priv->rx_1st_skb, ndev); + if (ndev->features & NETIF_F_RXCSUM) + ravb_rx_csum_gbeth(skb); napi_gro_receive(&priv->napi[q], priv->rx_1st_skb); stats->rx_packets++;