From patchwork Mon Nov 18 06:06:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Fang X-Patchwork-Id: 13878156 Received: from EUR03-AM7-obe.outbound.protection.outlook.com (mail-am7eur03on2075.outbound.protection.outlook.com [40.107.105.75]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9A3CF3C488 for ; Mon, 18 Nov 2024 06:22:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.105.75 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731910942; cv=fail; b=k2LZASjf/uDzemcdan1uFuytqBYi0csYFV+jblhd4rEYa3vJ85XJYwirJ+2nL2v84ncEdowsW5mT2BnvwC5aR6N/577vh3M79bJAPLiSTlcLIAKZjF0y2cb3iIrRqRIIg8sKEBBSrNpODMaeii8shxlahZ7ZWP2t4bhC5I8h5vg= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731910942; c=relaxed/simple; bh=aqhWNWDIxxhXGramADdKy+U88193GWHDHuY/Dhqm4tM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=V6IIYIlt1g3CWViS2X1vI60UcJMHH6nl+/L7r6OYTrTfWkraq7IqGkBXRLDUv2OE5i36Te+Sb/raW7Em/hOrgqkqrB3xJhw6lI9FZ4jq09au8DOuBw9ME0DYGyiyiNTcgzA3gPLC3KmAhao6TNm1moa4kHwcZQCg0ZIcmTsKjgY= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com; spf=pass smtp.mailfrom=nxp.com; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b=Q9mH5bBi; arc=fail smtp.client-ip=40.107.105.75 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b="Q9mH5bBi" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=KorvlBMy7YcbkxzpGmf5BFUiDaM38vzfeHGqyPY69DYjDi2ytfPv/E4ELwaYewhYNcv6vUaosQPQFxyr1AmlM5RNupyJrMExC5uwoNWK7xT3cI+ojboib3Nl9hSYrBpPLbs5W3Pcd5G7LFc7bhRINELzKSDyYvcNsDetZPJCCUfHB1ifosAeC4FUF43ogc2xciZBtKvZixWsBkzfoY6vW25yJ1KxzBSrwLO1TPoaTsUH2uXw/UbDnfx2po/NodiHoxvxA436Ed/OhYrILba4wm538+RrWU42hir/6wOuWC3aDOlvWEO1fI9kFBE5rIVbMgvsTCuHu5Di+lPrHzEWow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=WFRKqyrcnNeg/ky4xnpikrrjOl8BV/aWrWZ3k4bHFp0=; b=y0bzKeT3NW/CjQpV4t3hn65wvfEzwfjyb2fYcynGBKd0IX5m3r4MrA5hWZW4uaRCa8nfYSOYD/Df2FGNWD1ipkS8SBuG0DpSb8l4gibtTGLXF5tVTq3hDu2jLDQn3tCLhOuokvtxlFzKZskIDLmWXZPWIQr7SOrhaXoczkd/W8lzSbRid80mRBtiYAVOMsrQM4JgBKhhe/djO5kUenKWOLkWmJk4+O+BTxWA09MBJkAQtphdGsNRjZv3127C4SF5HtDnjpIIJuua3wKNlr+z1DwnqBaCeIwljgp6v5WYRwdjy6FZyQpmKNBiJTmCxC+vuhIsqR5rgGnckbXDRNrJxQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=WFRKqyrcnNeg/ky4xnpikrrjOl8BV/aWrWZ3k4bHFp0=; b=Q9mH5bBiUGsz29D1rAGlYHr6MoxkdPR6fOG6XpCtWm0F0EAkWOBMtN4xO6cFn3VpCq72nJkRaW1hWChMfRQ0hShwS0+b2y0QPVO//wg4KQbQuPJD9Lxkl1m4j26qb2jrbxkWtmSNny7rd4OhH9Q/2UvSDVB3U75Nu6z2bxNdLpsu5ug1rwX5xwCr6GvnN+LZPUPeJY/RVFaFqcBpX75insL7SB33Wxp1augq65A3sTdddLNnPpDhwuNkeojM39LJfRvOrpfgvKD6QcdizoLlWT/nW/Fe9rKBwPfDM0UdheOnr+vFVBQfH4M8dynwnqbYVt3dqdFyBF0C2RzQA0x3xw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from PAXPR04MB8510.eurprd04.prod.outlook.com (2603:10a6:102:211::7) by VI1PR04MB9739.eurprd04.prod.outlook.com (2603:10a6:800:1df::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8158.22; Mon, 18 Nov 2024 06:22:18 +0000 Received: from PAXPR04MB8510.eurprd04.prod.outlook.com ([fe80::a7c2:e2fa:8e04:40db]) by PAXPR04MB8510.eurprd04.prod.outlook.com ([fe80::a7c2:e2fa:8e04:40db%7]) with mapi id 15.20.8158.023; Mon, 18 Nov 2024 06:22:18 +0000 From: Wei Fang To: claudiu.manoil@nxp.com, vladimir.oltean@nxp.com, xiaoning.wang@nxp.com, andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, frank.li@nxp.com Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, imx@lists.linux.dev Subject: [PATCH v5 net-next 1/5] net: enetc: add Rx checksum offload for i.MX95 ENETC Date: Mon, 18 Nov 2024 14:06:26 +0800 Message-Id: <20241118060630.1956134-2-wei.fang@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241118060630.1956134-1-wei.fang@nxp.com> References: <20241118060630.1956134-1-wei.fang@nxp.com> X-ClientProxiedBy: SI2P153CA0007.APCP153.PROD.OUTLOOK.COM (2603:1096:4:140::8) To PAXPR04MB8510.eurprd04.prod.outlook.com (2603:10a6:102:211::7) Precedence: bulk X-Mailing-List: imx@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB8510:EE_|VI1PR04MB9739:EE_ X-MS-Office365-Filtering-Correlation-Id: 692365a2-fa28-4e63-5bea-08dd07995a1c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|52116014|376014|1800799024|366016|38350700014; X-Microsoft-Antispam-Message-Info: wDNpCRTcA1OwS9jDDcdxdDtGbOQ8aN64fZcl4Jubn7GiaM7EjJoKuMQRyQVQ+W2N42NdTSe1S34wWyfe4JEpYTCRzpkjk+NIbrMb+CURFFIPf04H9eyVoNEKZAhQsrwMV4IuedyYFJrwWSmi3Kc7JhfvcvQiOYe1J/LkXNtAwz7G5CyPua710NoZoVovAxc1ux4fkp2YVjekAqjU+H8xTLxQyahpOuZ7eOImbAQ/LTnzcbEXpMZlmMJYQU3ljTa5KCPuuGpBDrzPwayIgjHNZ4Jai4zGIKvbItePqdAAKHTANRloW9VxXQRAXaU/lLzBdaE9JyvReZc7srLh6rcknc+J7+9yN1dGYqGYBmXp6laPVcxyTd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M;H:PAXPR04MB8510.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(52116014)(376014)(1800799024)(366016)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: GjB0ESlT+6HxjSYZVOZ4q0MbPtjuSG3MTjtmSZplTj77CN19WUyV919y13qAIBHA+1CxxW9vvTbpGceBOGfc5WSTUE+UoBEXwJV9+f/qVg82xQex0UxufdA91nwWTSj9WdZPJe0Zy6/7K0rIw/rE8Zi3j4tuq/+JeMzHfDPt2jI48j+yCzBvXAX/GHo2ViFrWks80PXzQ6EWakv28z35xMAnLIIDPuoI1sIBx0CHsbcbpMlO32Vk/W1GCpnmx1DvEcADx0m4DjLQ4W7exuUtbq54w9M8+MB1I4ByGmQe7p/Tx+HLKxc9tNfuiNSYvceMgSyIQePYXEW6QBZdM/6lExTMOgthqe2Cdb/fDVK7/AVJhS0gzY6ffv1w/LV0VHw0RmpiPrVzlvEPlL9PRwi6e+HoeUCErs2/vFHnlp4UkK6yERCY+ZkVsLwieW1W9+G58nqJ4q7eXE7FYerSQXBqH1FBIROdagAJxSo5xQsYOKiH7X/yy1iTOOAZiEy8F7whgOUg5Qu5CoZh+CQSn+IK9GhevAILhXBvt77PgFwf7VRqlxONBjs0AHn2NhVMKaqoR2xr6FmRuvIl0O0k11rzoABB7PuPWl6lalQ0vcLZMbnRfaBlSpyppbqsID6Cvt6m9HV25REks7uKwbsI3ePEdAxLqVyq9tKZx3D9QFjckZpHrCUcxPXe8jpd1IEw4Xju9D5bffJm0xzRWXH3i8cj4KnEc5G/bOr+nU5vTDA21acojc5yJWdGzBizGOezzDIHB5XqHUsjuH61h45VPorG/bqlVn6uU09SlKgd3qEWu4x8ySwhrgkrOmlwNN/YkuvcOQ9Cj/uze9W7WtexdLlfEJXrwCu5Z/I3TkVRv44jKfErzUYDCqlhGW436qC0IMlAWnXSPFnvkH8oRhfH+DljuSPWJcrkvz1f2FxaiU1JKYTY81xsMu3R6pw1rpAy4pzgjLHYTZSQc7llf3ySnfBvXCIOUv4ve+yzttksZi8ghOSEpZYDLJ5/pMSuz+bNL7G8ILb1WtL6pNNNqgVvrS3hLjG9c7m1tv8RsKFdgf2sZq+x+kEXE+G8qKvY+GL3qe0ldgufu7FmgacfGIhzeU5u+yfC+CZHziw022ebFSzfrBmRigxb7xtWb+SpizxD4LffwGYqmXss0S9K+IeC0K0ov/mrO1UXUTTcPKk20qTntA1mIX7r1QRWa/vWaud03TBVQlHHsCKn2BtUW5Lv6dlCGxyjrqLdrjp7w6PldbrUQRHKow0qY3M/ykbV65PuxKNOIabzMxGCUM35Av4EEDHUSDRidwBUFSGh4sFgmmEBiN2BZ6483mWVy68wilB3tuqq9YmNj57DbWumt3IambM7ByYW9jWHKvX49G3W2HLRBeqTRPNPnbl6umDHCwuATRNFUve7+2hiasICPg+iBee86N7SIxtYi4pkx0VK4l7AhimlorlE0NlAOCDg96QsMYAJmaoP2SXwWkud38Jt9ajMDQKbV70UAKl7uQrK5yPQI2Z0I7m3Co1CdRTDROcfjuzRbCgvR4LdtSCaoEL6ZIfIVhkKNbd4TOc9OLG27mN6jLX1BXfnktur3iQ62eVvtY0x X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 692365a2-fa28-4e63-5bea-08dd07995a1c X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB8510.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Nov 2024 06:22:18.2038 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: tAptnOMA4hJ9eIlAS0SGUFG8H5VP1uUFguluD2Fh+UCW8mtdy4mHpi2lU/VOpM7ah8yRTFnGajEazJNDQJduNQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB9739 ENETC rev 4.1 supports TCP and UDP checksum offload for receive, the bit 108 of the Rx BD will be set if the TCP/UDP checksum is correct. Since this capability is not defined in register, the rx_csum bit is added to struct enetc_drvdata to indicate whether the device supports Rx checksum offload. Signed-off-by: Wei Fang Reviewed-by: Frank Li Reviewed-by: Claudiu Manoil --- v2: no changes v3: no changes v4: no changes v5: no changes --- drivers/net/ethernet/freescale/enetc/enetc.c | 14 ++++++++++---- drivers/net/ethernet/freescale/enetc/enetc.h | 2 ++ drivers/net/ethernet/freescale/enetc/enetc_hw.h | 2 ++ .../net/ethernet/freescale/enetc/enetc_pf_common.c | 3 +++ 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/freescale/enetc/enetc.c b/drivers/net/ethernet/freescale/enetc/enetc.c index 35634c516e26..3137b6ee62d3 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc.c +++ b/drivers/net/ethernet/freescale/enetc/enetc.c @@ -1011,10 +1011,15 @@ static void enetc_get_offloads(struct enetc_bdr *rx_ring, /* TODO: hashing */ if (rx_ring->ndev->features & NETIF_F_RXCSUM) { - u16 inet_csum = le16_to_cpu(rxbd->r.inet_csum); - - skb->csum = csum_unfold((__force __sum16)~htons(inet_csum)); - skb->ip_summed = CHECKSUM_COMPLETE; + if (priv->active_offloads & ENETC_F_RXCSUM && + le16_to_cpu(rxbd->r.flags) & ENETC_RXBD_FLAG_L4_CSUM_OK) { + skb->ip_summed = CHECKSUM_UNNECESSARY; + } else { + u16 inet_csum = le16_to_cpu(rxbd->r.inet_csum); + + skb->csum = csum_unfold((__force __sum16)~htons(inet_csum)); + skb->ip_summed = CHECKSUM_COMPLETE; + } } if (le16_to_cpu(rxbd->r.flags) & ENETC_RXBD_FLAG_VLAN) { @@ -3281,6 +3286,7 @@ static const struct enetc_drvdata enetc_pf_data = { static const struct enetc_drvdata enetc4_pf_data = { .sysclk_freq = ENETC_CLK_333M, .pmac_offset = ENETC4_PMAC_OFFSET, + .rx_csum = 1, .eth_ops = &enetc4_pf_ethtool_ops, }; diff --git a/drivers/net/ethernet/freescale/enetc/enetc.h b/drivers/net/ethernet/freescale/enetc/enetc.h index 72fa03dbc2dd..5b65f79e05be 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc.h +++ b/drivers/net/ethernet/freescale/enetc/enetc.h @@ -234,6 +234,7 @@ enum enetc_errata { struct enetc_drvdata { u32 pmac_offset; /* Only valid for PSI which supports 802.1Qbu */ + u8 rx_csum:1; u64 sysclk_freq; const struct ethtool_ops *eth_ops; }; @@ -341,6 +342,7 @@ enum enetc_active_offloads { ENETC_F_QBV = BIT(9), ENETC_F_QCI = BIT(10), ENETC_F_QBU = BIT(11), + ENETC_F_RXCSUM = BIT(12), }; enum enetc_flags_bit { diff --git a/drivers/net/ethernet/freescale/enetc/enetc_hw.h b/drivers/net/ethernet/freescale/enetc/enetc_hw.h index 7c3285584f8a..4b8fd1879005 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc_hw.h +++ b/drivers/net/ethernet/freescale/enetc/enetc_hw.h @@ -645,6 +645,8 @@ union enetc_rx_bd { #define ENETC_RXBD_LSTATUS(flags) ((flags) << 16) #define ENETC_RXBD_FLAG_VLAN BIT(9) #define ENETC_RXBD_FLAG_TSTMP BIT(10) +/* UDP and TCP checksum offload, for ENETC 4.1 and later */ +#define ENETC_RXBD_FLAG_L4_CSUM_OK BIT(12) #define ENETC_RXBD_FLAG_TPID GENMASK(1, 0) #define ENETC_MAC_ADDR_FILT_CNT 8 /* # of supported entries per port */ diff --git a/drivers/net/ethernet/freescale/enetc/enetc_pf_common.c b/drivers/net/ethernet/freescale/enetc/enetc_pf_common.c index 0eecfc833164..91e79582a541 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc_pf_common.c +++ b/drivers/net/ethernet/freescale/enetc/enetc_pf_common.c @@ -119,6 +119,9 @@ void enetc_pf_netdev_setup(struct enetc_si *si, struct net_device *ndev, ndev->priv_flags |= IFF_UNICAST_FLT; + if (si->drvdata->rx_csum) + priv->active_offloads |= ENETC_F_RXCSUM; + /* TODO: currently, i.MX95 ENETC driver does not support advanced features */ if (!is_enetc_rev1(si)) { ndev->hw_features &= ~(NETIF_F_HW_VLAN_CTAG_FILTER | NETIF_F_LOOPBACK);