From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 3D64546C25 for ; Sun, 27 Jul 2025 14:29:02 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id EA4984021E; Sun, 27 Jul 2025 14:29:01 +0200 (CEST) Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam04on2040.outbound.protection.outlook.com [40.107.100.40]) by mails.dpdk.org (Postfix) with ESMTP id DB9784021E for ; Sun, 27 Jul 2025 14:28:59 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ecyD9ADwm9HdRe0HO++gEK9CL+fG0xtFb6uQqiNbI8c7H1FoFM7voKm5OKLacNz2gka5+FgPeFQU/JXKGwlW+5EqDwRlC27uaaNDx/2UTWm6CMAdRa2IcnyFokp6j9i5N0f2LSPJP/hlhFP4tRLRDtZSaCuOIOSMg8LRq1lJDsW7tlh57oIR3eFVbAm0O+IwHCQRu085kyj9PRkFtDVKQQbo0niy8bRmtBl6C83HtcTyi/WoDEJLnhh0mXVuXelovKWLOgog9SJthiDe4Ey9wNCNzwEq6DozlZbeVUxgts41vUPm9P/APlohioUEeTZM1/SSYBspOOtm2nicAT6W8Q== 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=uRZ6gqA0uPfRsUzVmjCxcuHs6HQEN6iJXULy555KOCI=; b=S3H67AEFHQC9S6CpwrXzl8svC8hbziZn4qlW/KPkv/X5/JvFXihXayPXBr2DBrfOSXD3e1Yqas7h0SknIZVmbomTrij5QsS2CeRGoB24Iczz4RyL9Hzr3tCpS5E969H7OoCBpHhztrJ5EECTyoqg6PklqV/ZLNRvLw90+9D+SGVFc5K1/oMlD2ugG9z6lgUGCd1+fgLl95DIt0ti3+DpAk3/WrfLBbFQvHKb+b3D/8qVT3TL8OvaqZwjNLaWcGQEMBSqtykYqpw/ux4DFRhnQW3RhUvKB866JxZR8mjqmpNBL2KFqcI2JnHk/OZtAYflx2JglgpvgZWRmFOfjSRTcA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=uRZ6gqA0uPfRsUzVmjCxcuHs6HQEN6iJXULy555KOCI=; b=QFQvSFJTIH7tzRt0eSPEAzoQXtChkhhdMyoDtKMCM0DxD+X0oDUmmsbXJtpewxYzio2jzggbFkzop4qaQQey1xL6a6TTrxd5H8hQRX7y8vJ+9YzlitcPJSbHBioLMULBa0WfwepFN0ObLQvJyAkJ8bnp95ShKpTiA7IxXUuAeqJkmEjERCRsXI9q3KNl2ykyLwQFKudkwB1+YGvOPldMTqavNhhBkYKiY219+vW8Sl+rxjnrvJ3gx7EGTgDjJasgPLCqbkMa3Ta9XHh6SIXgfFFnBS+GhbaaO4rcbfL8n6tBTz/YtBC7MGOjwcJgqYMdbNZLKwiutap+iFj7WPOVJQ== Received: from CH3PR12MB8658.namprd12.prod.outlook.com (2603:10b6:610:175::8) by MN0PR12MB6224.namprd12.prod.outlook.com (2603:10b6:208:3c0::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8964.25; Sun, 27 Jul 2025 12:28:54 +0000 Received: from CH3PR12MB8658.namprd12.prod.outlook.com ([fe80::d5cc:cc84:5e00:2f42]) by CH3PR12MB8658.namprd12.prod.outlook.com ([fe80::d5cc:cc84:5e00:2f42%4]) with mapi id 15.20.8964.024; Sun, 27 Jul 2025 12:28:54 +0000 From: Xueming Li To: Dengdui Huang , "stable@dpdk.org" Subject: Re: [PATCH 23.11 2/2] net/hns3: fix Rx packet without CRC data Thread-Topic: [PATCH 23.11 2/2] net/hns3: fix Rx packet without CRC data Thread-Index: AQHb9TbtdGqyS5XWrkyMY93WDCIduLRF+WK/ Date: Sun, 27 Jul 2025 12:28:54 +0000 Message-ID: References: <20250715031649.3250453-1-huangdengdui@huawei.com> <20250715031649.3250453-2-huangdengdui@huawei.com> In-Reply-To: <20250715031649.3250453-2-huangdengdui@huawei.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: msip_labels: authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: CH3PR12MB8658:EE_|MN0PR12MB6224:EE_ x-ms-office365-filtering-correlation-id: 0f83e967-40bf-4eb2-1d71-08ddcd0926a9 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; ARA:13230040|376014|1800799024|366016|8096899003|7053199007|38070700018; x-microsoft-antispam-message-info: =?us-ascii?Q?KwL/sAPNalkirb8BFHW4WyjGYEQe9b7uEBQBDIu6IdJNklzDQ5Dt7eWCv/bX?= =?us-ascii?Q?709REwL7wtCG9USfXj/qgazTd88rYdCigpfNXnPTXClEk/DayqDPdA+M+mtm?= =?us-ascii?Q?kBy3LJ48rNZHcURxlHvAoukk6ic2sl5lXq5+CEfTCny2YvXT5CsalZSpP83P?= =?us-ascii?Q?MaPuCWZCOTyQykxoD/JIzs3SCPKOTQkk4EnGUmTT4sQnSj0Dogbb5VNb057k?= =?us-ascii?Q?fU+CaoYbs4GmGnR5Rp6m6StzBng+4TcUM72zKBJgTQxK0wY92X5wLfdJW8S6?= =?us-ascii?Q?GZbYh5DaUujq05xKLPQlC4a4pFwBQCkfwIQpnDc/uWYgenqpWh/NOdMBGs2Y?= =?us-ascii?Q?GWCUUabUOuPu/DYnmbBTuJPYyCq2MjQEXJwuNGHzZDqzPxZZ6cLaK8UFNfvt?= =?us-ascii?Q?a/d1LL8urFvLXU+nias4ov5ZZAVAxovKzcR1Hjwc7RyBJQympy2HnLud5p/3?= =?us-ascii?Q?hcuFRBRF6bnegQOCEKUvHGaJr9neuXCnVj3XaZQjmtrsjz7bddXREFRYFlsm?= =?us-ascii?Q?zSdjkSAsxPXxcXaqp2MMeQAVe+9x4i1J83imYaxyfJT/7COmkUTLclsyc1Jx?= =?us-ascii?Q?RUZwAuthAWxNse1WzeNFy/0OQ3yXjOLQlD7TWxYZZw1Uxmd+NqExSQGHhAAv?= =?us-ascii?Q?51FIqnUGUCq8EWGKdmJtyQboeDzQpEjTiIv1LXjlpaiKp/0vzeYy4vOETXZg?= =?us-ascii?Q?H0Y4SahIzad2geUfEwkPOr5jqPfAB36qzyj4ufPifva4IaEj2D7dlFB/xC+i?= =?us-ascii?Q?2zVGPjQXJhN9bh86eCAwbR8GiZrlRm1Ullr80djvmdFwFQ8pIbHc2n92HtV+?= =?us-ascii?Q?R57RaISCi5d9XyC8d8vmAfWROO4zDzemi7g/M78F7WeT4ojqX2H2IeDk1VE0?= =?us-ascii?Q?l0xbQSE0Hac6Q6/nZiW78Zo9ldXhBcIQ93p/xb1S6mqxK6QlB+hJ3CTxvKsc?= =?us-ascii?Q?MiSp7HYhRKam24CwfM6qK439ExBeULwQySD8A2K5fEgQNkmH1EQVVM/C7Y8V?= =?us-ascii?Q?Ja9UQKuji6zc+NpzZUhdiImQlZ77cvfEUOKfqVJB3hBvPQNQTEtzZFjjmpE7?= =?us-ascii?Q?6hw4nnpcc5k5gHJwpAFEU1Ggv83PNQ8UW7XAasMIQ1YLuJ8balSC2fToKT5m?= =?us-ascii?Q?IWU9Jgh8+UqW9xk62TRImxVQg6Sl+lAdHrCdmtwFCfCydmK4dSIgMBScSjIp?= =?us-ascii?Q?EojQDKN0Ld+UGzj2SX+MIEM0i1qUm2Qm4F55y6WQrORyyOR27MYqpoW/sEGv?= =?us-ascii?Q?bkrWoIUsltZbd2S6m2srU/W1jgYev+aXrTeqYhJAjZ5gJPSECBPdIdjZgpYH?= =?us-ascii?Q?liYH1kHIG0cbXZ6pIvMkQkoQEQAy6UL+au7h7AuUXcwBvot9V7m7hXEQ4dWh?= =?us-ascii?Q?WOKnXhXu6j8cT3MyRaBw60VqTKdLsiGuSZWWMmMq4y5xrWPy+5dajOQiB7OQ?= =?us-ascii?Q?+psw9JWBNtRYh5vUbgla8ir50+h/N+++EifLqw/2SdwJtF1zNr2gGg=3D=3D?= x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CH3PR12MB8658.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(376014)(1800799024)(366016)(8096899003)(7053199007)(38070700018); DIR:OUT; SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?YX4CfNoN+weSjAHmIL13jeHYxStrvcDb6ZaPB3J5luG/+UU+wrozlpN9qZJ9?= =?us-ascii?Q?JPZcCiFyXu+YsUNUJ8JAawA4+GeOZcgczQdmAAEEJ/XVddsqKMtr0Xhm668B?= =?us-ascii?Q?90LlSgKoqRDCU1as2Gh0Hw12j3EP/mj7EKbopcNgh68UI9ejaFSIDv0blXP2?= =?us-ascii?Q?ONxKImGA2KPRehWjaRx0axqM/aeGk93Py1WEXKGtaaEdGozlq1YHpzSM6kc0?= =?us-ascii?Q?BqtXsDR5dQLMsG7LuzT616q4GQQyCRWYe+U0wSL3uecQ4vjQhIvRUkYoO2+k?= =?us-ascii?Q?pghQ5eQRP2bqgedaYkLzIeNL81OoCBmuTEQlBVuPHIA8cDC4qWqOxL/9Zf/C?= =?us-ascii?Q?pihPV1DbPFOMSGnp8SMYn487XILv8JhZuBQ9YquvTlK3HqKSApmXmCLL1Ehb?= =?us-ascii?Q?Z/LvEoQsx1Nhjxcnj1YwdXyCp74tEkrDbL+WgVIEyO9kGzZpJQP8JuNwQrUJ?= =?us-ascii?Q?pyvtYDyMn5QH3UNDlDYp6q5BFX7cGhJNOFzKGOCYF8FiRIfBYpTpc0XvmfJy?= =?us-ascii?Q?+ovti9Ji9cB7fQwNrHvBC0uNe9DE0/Rg/6pHzX5b/gksQXY2ibKAMzKOjpzU?= =?us-ascii?Q?hu6qewXvedFnlsVAxyHTtCEBA8rwaDGkl0TupLbgPe7RlB2YwEkRYPRm2oSl?= =?us-ascii?Q?wH+zU73KgpKmbd6pwWXG1C5Oh+9ea69lWsKIiTTSjI+3KL041YElE5ueUEAu?= =?us-ascii?Q?+jj/ETO3ssW7kRyINcGHN60s47XY4vh/L9dyWNFDybqSsstsD7z0Y6iHdzVO?= =?us-ascii?Q?c1QqcNr64pJXX4r9UwlTORawD3wAQWWxnyV7OpL3G75deQgyoaQUtie6Pkzi?= =?us-ascii?Q?xBLgrki7hddBiVq9iWQZGelgySQIDkUTe5uxQecXzLyGWyKEkUQME68gJ3A5?= =?us-ascii?Q?0ExQLPqKSK9L57U8PWcqIOYs9g+m8KWFpFfpWHGyCL/cYsebQjkcJ2mGv+Ff?= =?us-ascii?Q?1VguQcYrinkCkWbojLp2//yca7OzAqPvjpphQtzxeJv1Q1Rvic2XoRZDIUEP?= =?us-ascii?Q?98v8gNcGAKcidxlJwRFuclqNeSeriannNH4z+rtWkcdjOYJnh7wK/vfdRc0W?= =?us-ascii?Q?+I6LXnt+mPolvP8NnZ+aBgaIprvKzwtthMbwCzctGZmhbRZJ80VH22yUEnTK?= =?us-ascii?Q?O8yZAkoccc1Psek+9XEwmBQgnK07HCwyzIInXaLOJYc1ZROe9djdGGc5ue9B?= =?us-ascii?Q?VAnzN8zsuxbIHApHEL8hsHP0JN/URG5dfOejNU8osfopdSmRq+vqXgeoW71o?= =?us-ascii?Q?GjjI+BJYGphqF3euKvPSzAZZwyrmWt9dUr2SWYzFHYxoHafo9GLyx/BiaQDd?= =?us-ascii?Q?1eUB6ve74CV4yAwmNDCy2+jukAPocWLiLEBKVKKfxvFioeiP56/l5l2Qepag?= =?us-ascii?Q?CP1d0irq4S5JYze5+w/YwYl6g7QuSP+PCg4FgQ3vqhlfJMYcmQsJ+dDmA5w1?= =?us-ascii?Q?I/KRTsQBvNWM/ULQaxxSylG/DSrloHHk+DpY2FZB4ckORVXAKIc5VqaZuMWN?= =?us-ascii?Q?Qe5U8oFYc0Q96vPy6mJpjOwLFkc+PD6vjC4qSDY1JerqtS8FAaAUdpb7+/z9?= =?us-ascii?Q?upZ/XquE8ZJ3skTzWCU=3D?= Content-Type: multipart/alternative; boundary="_000_CH3PR12MB86586F356A796D48F62D06B4A15BACH3PR12MB8658namp_" MIME-Version: 1.0 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: CH3PR12MB8658.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0f83e967-40bf-4eb2-1d71-08ddcd0926a9 X-MS-Exchange-CrossTenant-originalarrivaltime: 27 Jul 2025 12:28:54.2851 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: xoiNqhG6oYz1Ub/boUm3zyipU8GOS6HwZpu9fhCnYVRFySRVTEiHs57SAJlfTEtC+e290GV0ybQ1zFG4n2N3jQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB6224 X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org --_000_CH3PR12MB86586F356A796D48F62D06B4A15BACH3PR12MB8658namp_ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hi Dengdui, Thanks for your backport, patch enqueued to 23.11 LTS release candidate que= ue. Regards, Xueming Li ________________________________ From: Dengdui Huang Sent: Tuesday, July 15, 2025 11:16 AM To: stable@dpdk.org Cc: Xueming Li Subject: [PATCH 23.11 2/2] net/hns3: fix Rx packet without CRC data [ upstream commit 99c065da47c432e9529f761b457cde1fd8c89f20 ] When KEEP_CRC offload is enabled, the CRC data is still stripped in following cases: 1. For HIP08 network engine, the packet type is TCP and the length is less than or equal to 60B. 2. For HIP09 network engine, the packet type is IP and the length is less than or equal to 60B. So driver has to recaculate packet CRC for this rare scenarios. In addition, to avoid impacting performance, KEEP_CRC is not supported when NEON or SVE algorithm is used. Fixes: 8973d7c4ca12 ("net/hns3: support keeping CRC") Cc: stable@dpdk.org Signed-off-by: Dengdui Huang Acked-by: Huisong Li Acked-by: Jie Hai --- drivers/net/hns3/hns3_ethdev.c | 2 + drivers/net/hns3/hns3_ethdev.h | 23 +++++ drivers/net/hns3/hns3_rxtx.c | 119 +++++++++++++++++++++----- drivers/net/hns3/hns3_rxtx.h | 3 + drivers/net/hns3/hns3_rxtx_vec.c | 3 +- drivers/net/hns3/hns3_rxtx_vec_neon.h | 19 ---- drivers/net/hns3/hns3_rxtx_vec_sve.c | 3 +- 7 files changed, 128 insertions(+), 44 deletions(-) diff --git a/drivers/net/hns3/hns3_ethdev.c b/drivers/net/hns3/hns3_ethdev.= c index dd450cddaa..b2294e68cb 100644 --- a/drivers/net/hns3/hns3_ethdev.c +++ b/drivers/net/hns3/hns3_ethdev.c @@ -2739,6 +2739,7 @@ hns3_get_capability(struct hns3_hw *hw) hw->udp_cksum_mode =3D HNS3_SPECIAL_PORT_SW_CKSUM_MODE; pf->support_multi_tc_pause =3D false; hw->rx_dma_addr_align =3D HNS3_RX_DMA_ADDR_ALIGN_64; + hw->strip_crc_ptype =3D HNS3_STRIP_CRC_PTYPE_TCP; return 0; } @@ -2760,6 +2761,7 @@ hns3_get_capability(struct hns3_hw *hw) hw->udp_cksum_mode =3D HNS3_SPECIAL_PORT_HW_CKSUM_MODE; pf->support_multi_tc_pause =3D true; hw->rx_dma_addr_align =3D HNS3_RX_DMA_ADDR_ALIGN_128; + hw->strip_crc_ptype =3D HNS3_STRIP_CRC_PTYPE_IP; return 0; } diff --git a/drivers/net/hns3/hns3_ethdev.h b/drivers/net/hns3/hns3_ethdev.= h index 00d226d71c..0ce4974da6 100644 --- a/drivers/net/hns3/hns3_ethdev.h +++ b/drivers/net/hns3/hns3_ethdev.h @@ -54,6 +54,10 @@ #define HNS3_SPECIAL_PORT_SW_CKSUM_MODE 0 #define HNS3_SPECIAL_PORT_HW_CKSUM_MODE 1 +#define HNS3_STRIP_CRC_PTYPE_NONE 0 +#define HNS3_STRIP_CRC_PTYPE_TCP 1 +#define HNS3_STRIP_CRC_PTYPE_IP 2 + #define HNS3_UC_MACADDR_NUM 128 #define HNS3_VF_UC_MACADDR_NUM 48 #define HNS3_MC_MACADDR_NUM 128 @@ -655,6 +659,25 @@ struct hns3_hw { */ uint8_t udp_cksum_mode; + /* + * When KEEP_CRC offload is enabled, the CRC data of some type pack= ets + * whose length is less than or equal to HNS3_KEEP_CRC_OK_MIN_PKT_L= EN + * is still be stripped on some network engine. So here has to use = this + * field to distinguish the difference between different network en= gines. + * value range: + * - HNS3_STRIP_CRC_PTYPE_TCP + * This value for HIP08 network engine. + * Indicates that only the IP-TCP packet type is stripped. + * + * - HNS3_STRIP_CRC_PTYPE_IP + * This value for HIP09 network engine. + * Indicates that all IP packet types are stripped. + * + * - HNS3_STRIP_CRC_PTYPE_NONE + * Indicates that all packet types are not stripped. + */ + uint8_t strip_crc_ptype; + struct hns3_port_base_vlan_config port_base_vlan_cfg; pthread_mutex_t flows_lock; /* rte_flow ops lock */ diff --git a/drivers/net/hns3/hns3_rxtx.c b/drivers/net/hns3/hns3_rxtx.c index 58aa6edff4..5b0916233c 100644 --- a/drivers/net/hns3/hns3_rxtx.c +++ b/drivers/net/hns3/hns3_rxtx.c @@ -11,6 +11,7 @@ #include #include #include +#include #if defined(RTE_ARCH_ARM64) #include #include @@ -1766,8 +1767,9 @@ hns3_rx_buf_len_calc(struct rte_mempool *mp, uint16_t= *rx_buf_len) } static int -hns3_rxq_conf_runtime_check(struct hns3_hw *hw, uint16_t buf_size, - uint16_t nb_desc) +hns3_rxq_conf_runtime_check(struct hns3_hw *hw, + const struct rte_eth_rxconf *conf, + uint16_t buf_size, uint16_t nb_desc) { struct rte_eth_dev *dev =3D &rte_eth_devices[hw->data->port_id]; eth_rx_burst_t pkt_burst =3D dev->rx_pkt_burst; @@ -1800,6 +1802,14 @@ hns3_rxq_conf_runtime_check(struct hns3_hw *hw, uint= 16_t buf_size, return -EINVAL; } } + + if ((conf->offloads & RTE_ETH_RX_OFFLOAD_KEEP_CRC) && + pkt_burst !=3D hns3_recv_pkts_simple && + pkt_burst !=3D hns3_recv_scattered_pkts) { + hns3_err(hw, "KEEP_CRC offload is not supported with the cu= rrent Rx function."); + return -EINVAL; + } + return 0; } @@ -1836,7 +1846,7 @@ hns3_rx_queue_conf_check(struct hns3_hw *hw, const st= ruct rte_eth_rxconf *conf, } if (hw->data->dev_started) { - ret =3D hns3_rxq_conf_runtime_check(hw, *buf_size, nb_desc)= ; + ret =3D hns3_rxq_conf_runtime_check(hw, conf, *buf_size, nb= _desc); if (ret) { hns3_err(hw, "Rx queue runtime setup fail."); return ret; @@ -1957,6 +1967,8 @@ hns3_rx_queue_setup(struct rte_eth_dev *dev, uint16_t= idx, uint16_t nb_desc, else rxq->crc_len =3D 0; + rxq->keep_crc_fail_ptype =3D hw->strip_crc_ptype; + rxq->bulk_mbuf_num =3D 0; rte_spinlock_lock(&hw->lock); @@ -2430,6 +2442,55 @@ hns3_rx_ptp_timestamp_handle(struct hns3_rx_queue *r= xq, struct rte_mbuf *mbuf, pf->rx_timestamp =3D timestamp; } +static inline bool +hns3_need_recalculate_crc(struct hns3_rx_queue *rxq, struct rte_mbuf *m) +{ + uint32_t ptype =3D m->packet_type; + + if (rxq->keep_crc_fail_ptype =3D=3D HNS3_STRIP_CRC_PTYPE_NONE) + return false; + + if (m->pkt_len > HNS3_KEEP_CRC_OK_MIN_PKT_LEN) + return false; + + if (!(RTE_ETH_IS_IPV4_HDR(ptype) || RTE_ETH_IS_IPV6_HDR(ptype))) + return false; + + if (rxq->keep_crc_fail_ptype =3D=3D HNS3_STRIP_CRC_PTYPE_TCP) + return (ptype & RTE_PTYPE_L4_MASK) =3D=3D RTE_PTYPE_L4_TCP; + + return true; +} + +/* + * The hns3 driver requires that mbuf size must be at least 512B. + * When CRC is stripped by hardware, the pkt_len must be less than + * or equal to 60B. Therefore, the space of the mbuf is enough + * to insert the CRC. + */ +static_assert(HNS3_KEEP_CRC_OK_MIN_PKT_LEN < HNS3_MIN_BD_BUF_SIZE, + "buffer size too small to insert CRC"); + +static inline void +hns3_recalculate_crc(struct rte_mbuf *m) +{ + char *append_data; + uint32_t crc; + + crc =3D rte_net_crc_calc(rte_pktmbuf_mtod(m, void *), + m->data_len, RTE_NET_CRC32_ETH); + + /* + * After CRC is stripped by hardware, pkt_len and data_len do not + * contain the CRC length. Therefore, after CRC data is appended + * by PMD again. + */ + append_data =3D rte_pktmbuf_append(m, RTE_ETHER_CRC_LEN); + + /* CRC data is binary data and does not care about the byte order. = */ + memcpy(append_data, &crc, RTE_ETHER_CRC_LEN); +} + uint16_t hns3_recv_pkts_simple(void *rx_queue, struct rte_mbuf **rx_pkts, @@ -2500,8 +2561,7 @@ hns3_recv_pkts_simple(void *rx_queue, rxdp->rx.bd_base_info =3D 0; rxm->data_off =3D RTE_PKTMBUF_HEADROOM; - rxm->pkt_len =3D (uint16_t)(rte_le_to_cpu_16(rxd.rx.pkt_len= )) - - rxq->crc_len; + rxm->pkt_len =3D (uint16_t)(rte_le_to_cpu_16(rxd.rx.pkt_len= )); rxm->data_len =3D rxm->pkt_len; rxm->port =3D rxq->port_id; rxm->hash.rss =3D rte_le_to_cpu_32(rxd.rx.rss_hash); @@ -2526,6 +2586,12 @@ hns3_recv_pkts_simple(void *rx_queue, if (rxm->packet_type =3D=3D RTE_PTYPE_L2_ETHER_TIMESYNC) rxm->ol_flags |=3D RTE_MBUF_F_RX_IEEE1588_PTP; + if (unlikely(rxq->crc_len > 0) && + hns3_need_recalculate_crc(rxq, rxm)) + hns3_recalculate_crc(rxm); + rxm->pkt_len -=3D rxq->crc_len; + rxm->data_len -=3D rxq->crc_len; + hns3_rxd_to_vlan_tci(rxq, rxm, l234_info, &rxd); /* Increment bytes counter */ @@ -2692,10 +2758,10 @@ hns3_recv_scattered_pkts(void *rx_queue, rxm->data_off =3D RTE_PKTMBUF_HEADROOM; rxm->data_len =3D rte_le_to_cpu_16(rxd.rx.size); + rxm->next =3D NULL; if (!(bd_base_info & BIT(HNS3_RXD_FE_B))) { last_seg =3D rxm; - rxm->next =3D NULL; continue; } @@ -2710,22 +2776,6 @@ hns3_recv_scattered_pkts(void *rx_queue, */ first_seg->pkt_len =3D rte_le_to_cpu_16(rxd.rx.pkt_len); - /* - * This is the last buffer of the received packet. If the C= RC - * is not stripped by the hardware: - * - Subtract the CRC length from the total packet length. - * - If the last buffer only contains the whole CRC or a p= art - * of it, free the mbuf associated to the last buffer. If = part - * of the CRC is also contained in the previous mbuf, subt= ract - * the length of that CRC part from the data length of the - * previous mbuf. - */ - rxm->next =3D NULL; - if (unlikely(rxq->crc_len > 0)) { - first_seg->pkt_len -=3D rxq->crc_len; - recalculate_data_len(last_seg, rxm, rxq); - } - first_seg->port =3D rxq->port_id; first_seg->hash.rss =3D rte_le_to_cpu_32(rxd.rx.rss_hash); first_seg->ol_flags |=3D RTE_MBUF_F_RX_RSS_HASH; @@ -2754,6 +2804,31 @@ hns3_recv_scattered_pkts(void *rx_queue, if (first_seg->packet_type =3D=3D RTE_PTYPE_L2_ETHER_TIMES= YNC) rxm->ol_flags |=3D RTE_MBUF_F_RX_IEEE1588_PTP; + /* + * This is the last buffer of the received packet. If the C= RC + * is not stripped by the hardware: + * - Subtract the CRC length from the total packet length. + * - If the last buffer only contains the whole CRC or a p= art + * of it, free the mbuf associated to the last buffer. If = part + * of the CRC is also contained in the previous mbuf, subt= ract + * the length of that CRC part from the data length of the + * previous mbuf. + * + * In addition, the CRC is still stripped for a kind of pac= kets + * in hns3 NIC: + * 1. All IP-TCP packet whose the length is less than and e= qual + * to 60 Byte (no CRC) on HIP08 network engine. + * 2. All IP packet whose the length is less than and equal= to + * 60 Byte (no CRC) on HIP09 network engine. + * In this case, the PMD calculates the CRC and appends it = to + * mbuf. + */ + if (unlikely(rxq->crc_len > 0)) { + if (hns3_need_recalculate_crc(rxq, first_seg)) + hns3_recalculate_crc(first_seg); + first_seg->pkt_len -=3D rxq->crc_len; + recalculate_data_len(last_seg, rxm, rxq); + } hns3_rxd_to_vlan_tci(rxq, first_seg, l234_info, &rxd); diff --git a/drivers/net/hns3/hns3_rxtx.h b/drivers/net/hns3/hns3_rxtx.h index b6a6513307..f182ff6a9d 100644 --- a/drivers/net/hns3/hns3_rxtx.h +++ b/drivers/net/hns3/hns3_rxtx.h @@ -178,6 +178,8 @@ (HNS3_TXD_VLD_CMD | HNS3_TXD_FE_CMD | HNS3_TXD_DEFAULT_BDT= YPE) #define HNS3_TXD_SEND_SIZE_SHIFT 16 +#define HNS3_KEEP_CRC_OK_MIN_PKT_LEN 60 + enum hns3_pkt_l2t_type { HNS3_L2_TYPE_UNICAST, HNS3_L2_TYPE_MULTICAST, @@ -341,6 +343,7 @@ struct hns3_rx_queue { */ uint8_t pvid_sw_discard_en:1; uint8_t ptype_en:1; /* indicate if the ptype field enable= d */ + uint8_t keep_crc_fail_ptype:2; uint64_t mbuf_initializer; /* value to init mbufs used with vector= rx */ /* offset_table: used for vector, to solve execute re-order proble= m */ diff --git a/drivers/net/hns3/hns3_rxtx_vec.c b/drivers/net/hns3/hns3_rxtx_= vec.c index 9708ec614e..bf37ce51b1 100644 --- a/drivers/net/hns3/hns3_rxtx_vec.c +++ b/drivers/net/hns3/hns3_rxtx_vec.c @@ -185,7 +185,8 @@ hns3_rx_check_vec_support(struct rte_eth_dev *dev) struct rte_eth_rxmode *rxmode =3D &dev->data->dev_conf.rxmode; uint64_t offloads_mask =3D RTE_ETH_RX_OFFLOAD_TCP_LRO | RTE_ETH_RX_OFFLOAD_VLAN | - RTE_ETH_RX_OFFLOAD_TIMESTAMP; + RTE_ETH_RX_OFFLOAD_TIMESTAMP | + RTE_ETH_RX_OFFLOAD_KEEP_CRC; if (dev->data->scattered_rx) return -ENOTSUP; diff --git a/drivers/net/hns3/hns3_rxtx_vec_neon.h b/drivers/net/hns3/hns3_= rxtx_vec_neon.h index 0dc6b9f0a2..60ec501a2a 100644 --- a/drivers/net/hns3/hns3_rxtx_vec_neon.h +++ b/drivers/net/hns3/hns3_rxtx_vec_neon.h @@ -148,14 +148,6 @@ hns3_recv_burst_vec(struct hns3_rx_queue *__restrict r= xq, 8, 9, 10, 11, /* rx.rss_hash to rte_mbuf.hash.r= ss */ }; - uint16x8_t crc_adjust =3D { - 0, 0, /* ignore pkt_type field */ - rxq->crc_len, /* sub crc on pkt_len */ - 0, /* ignore high-16bits of pkt_len */ - rxq->crc_len, /* sub crc on data_len */ - 0, 0, 0, /* ignore non-length fields */ - }; - /* compile-time verifies the shuffle mask */ RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, pkt_len) !=3D offsetof(struct rte_mbuf, rx_descriptor_fields1) = + 4); @@ -171,7 +163,6 @@ hns3_recv_burst_vec(struct hns3_rx_queue *__restrict rx= q, uint8x16_t pkt_mb1, pkt_mb2, pkt_mb3, pkt_mb4; uint64x2_t mbp1, mbp2; uint16x4_t bd_vld =3D {0}; - uint16x8_t tmp; uint64_t stat; /* calc how many bd valid */ @@ -225,16 +216,6 @@ hns3_recv_burst_vec(struct hns3_rx_queue *__restrict r= xq, pkt_mb3 =3D vqtbl2q_u8(pkt_mbuf3, shuf_desc_fields_msk); pkt_mb4 =3D vqtbl2q_u8(pkt_mbuf4, shuf_desc_fields_msk); - /* 4 packets remove crc */ - tmp =3D vsubq_u16(vreinterpretq_u16_u8(pkt_mb1), crc_adjust= ); - pkt_mb1 =3D vreinterpretq_u8_u16(tmp); - tmp =3D vsubq_u16(vreinterpretq_u16_u8(pkt_mb2), crc_adjust= ); - pkt_mb2 =3D vreinterpretq_u8_u16(tmp); - tmp =3D vsubq_u16(vreinterpretq_u16_u8(pkt_mb3), crc_adjust= ); - pkt_mb3 =3D vreinterpretq_u8_u16(tmp); - tmp =3D vsubq_u16(vreinterpretq_u16_u8(pkt_mb4), crc_adjust= ); - pkt_mb4 =3D vreinterpretq_u8_u16(tmp); - /* save packet info to rx_pkts mbuf */ vst1q_u8((void *)&sw_ring[pos + 0].mbuf->rx_descriptor_fie= lds1, pkt_mb1); diff --git a/drivers/net/hns3/hns3_rxtx_vec_sve.c b/drivers/net/hns3/hns3_r= xtx_vec_sve.c index 8aa4448558..67c87f570e 100644 --- a/drivers/net/hns3/hns3_rxtx_vec_sve.c +++ b/drivers/net/hns3/hns3_rxtx_vec_sve.c @@ -36,8 +36,7 @@ hns3_desc_parse_field_sve(struct hns3_rx_queue *rxq, /* init rte_mbuf.rearm_data last 64-bit */ rx_pkts[i]->ol_flags =3D RTE_MBUF_F_RX_RSS_HASH; rx_pkts[i]->hash.rss =3D rxdp[i].rx.rss_hash; - rx_pkts[i]->pkt_len =3D rte_le_to_cpu_16(rxdp[i].rx.pkt_len= ) - - rxq->crc_len; + rx_pkts[i]->pkt_len =3D rte_le_to_cpu_16(rxdp[i].rx.pkt_len= ); rx_pkts[i]->data_len =3D rx_pkts[i]->pkt_len; l234_info =3D rxdp[i].rx.l234_info; -- 2.33.0 --_000_CH3PR12MB86586F356A796D48F62D06B4A15BACH3PR12MB8658namp_ Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable
Hi Dengdui,

Thanks for your backport, patch enqueued to 23.11 LTS release candidate que= ue.


Regards,
Xueming Li

From: Dengdui Huang <hua= ngdengdui@huawei.com>
Sent: Tuesday, July 15, 2025 11:16 AM
To: stable@dpdk.org <stable@dpdk.org>
Cc: Xueming Li <xuemingl@nvidia.com>
Subject: [PATCH 23.11 2/2] net/hns3: fix Rx packet without CRC data<= /font>
 
[ upstream commit 99c065da47c432e9529f761b457cde1f= d8c89f20 ]

When KEEP_CRC offload is enabled, the CRC data is still stripped
in following cases:
1. For HIP08 network engine, the packet type is TCP and the length
   is less than or equal to 60B.
2. For HIP09 network engine, the packet type is IP and the length
   is less than or equal to 60B.

So driver has to recaculate packet CRC for this rare scenarios.

In addition, to avoid impacting performance, KEEP_CRC is not
supported when NEON or SVE algorithm is used.

Fixes: 8973d7c4ca12 ("net/hns3: support keeping CRC")
Cc: stable@dpdk.org

Signed-off-by: Dengdui Huang <huangdengdui@huawei.com>
Acked-by: Huisong Li <lihuisong@huawei.com>
Acked-by: Jie Hai <haijie1@huawei.com>
---
 drivers/net/hns3/hns3_ethdev.c      &nb= sp; |   2 +
 drivers/net/hns3/hns3_ethdev.h      &nb= sp; |  23 +++++
 drivers/net/hns3/hns3_rxtx.c       = ;   | 119 +++++++++++++++++++++-----
 drivers/net/hns3/hns3_rxtx.h       = ;   |   3 +
 drivers/net/hns3/hns3_rxtx_vec.c      | = ;  3 +-
 drivers/net/hns3/hns3_rxtx_vec_neon.h |  19 ----
 drivers/net/hns3/hns3_rxtx_vec_sve.c  |   3 +-
 7 files changed, 128 insertions(+), 44 deletions(-)

diff --git a/drivers/net/hns3/hns3_ethdev.c b/drivers/net/hns3/hns3_ethdev.= c
index dd450cddaa..b2294e68cb 100644
--- a/drivers/net/hns3/hns3_ethdev.c
+++ b/drivers/net/hns3/hns3_ethdev.c
@@ -2739,6 +2739,7 @@ hns3_get_capability(struct hns3_hw *hw)
            &nb= sp;    hw->udp_cksum_mode =3D HNS3_SPECIAL_PORT_SW_CKSUM_= MODE;
            &nb= sp;    pf->support_multi_tc_pause =3D false;
            &nb= sp;    hw->rx_dma_addr_align =3D HNS3_RX_DMA_ADDR_ALIGN_6= 4;
+            &n= bsp;  hw->strip_crc_ptype =3D HNS3_STRIP_CRC_PTYPE_TCP;
            &nb= sp;    return 0;
         }
 
@@ -2760,6 +2761,7 @@ hns3_get_capability(struct hns3_hw *hw)
         hw->udp_cksum_mode =3D = HNS3_SPECIAL_PORT_HW_CKSUM_MODE;
         pf->support_multi_tc_pa= use =3D true;
         hw->rx_dma_addr_align = =3D HNS3_RX_DMA_ADDR_ALIGN_128;
+       hw->strip_crc_ptype =3D HNS3_STRIP= _CRC_PTYPE_IP;
 
         return 0;
 }
diff --git a/drivers/net/hns3/hns3_ethdev.h b/drivers/net/hns3/hns3_ethdev.= h
index 00d226d71c..0ce4974da6 100644
--- a/drivers/net/hns3/hns3_ethdev.h
+++ b/drivers/net/hns3/hns3_ethdev.h
@@ -54,6 +54,10 @@
 #define HNS3_SPECIAL_PORT_SW_CKSUM_MODE     =     0
 #define HNS3_SPECIAL_PORT_HW_CKSUM_MODE     =     1
 
+#define HNS3_STRIP_CRC_PTYPE_NONE       = ;  0
+#define HNS3_STRIP_CRC_PTYPE_TCP       =    1
+#define HNS3_STRIP_CRC_PTYPE_IP       &= nbsp;   2
+
 #define HNS3_UC_MACADDR_NUM       =       128
 #define HNS3_VF_UC_MACADDR_NUM      &nb= sp;   48
 #define HNS3_MC_MACADDR_NUM       =       128
@@ -655,6 +659,25 @@ struct hns3_hw {
          */
         uint8_t udp_cksum_mode;  
+       /*
+        * When KEEP_CRC offload is enab= led, the CRC data of some type packets
+        * whose length is less than or = equal to HNS3_KEEP_CRC_OK_MIN_PKT_LEN
+        * is still be stripped on some = network engine. So here has to use this
+        * field to distinguish the diff= erence between different network engines.
+        * value range:
+        *  - HNS3_STRIP_CRC_PTYPE_= TCP
+        *     This = value for HIP08 network engine.
+        *     Indic= ates that only the IP-TCP packet type is stripped.
+        *
+        *  - HNS3_STRIP_CRC_PTYPE_= IP
+        *     This = value for HIP09 network engine.
+        *     Indic= ates that all IP packet types are stripped.
+        *
+        *  - HNS3_STRIP_CRC_PTYPE_= NONE
+        *     Indic= ates that all packet types are not stripped.
+        */
+       uint8_t strip_crc_ptype;
+
         struct hns3_port_base_vlan= _config port_base_vlan_cfg;
 
         pthread_mutex_t flows_lock= ; /* rte_flow ops lock */
diff --git a/drivers/net/hns3/hns3_rxtx.c b/drivers/net/hns3/hns3_rxtx.c index 58aa6edff4..5b0916233c 100644
--- a/drivers/net/hns3/hns3_rxtx.c
+++ b/drivers/net/hns3/hns3_rxtx.c
@@ -11,6 +11,7 @@
 #include <rte_io.h>
 #include <rte_net.h>
 #include <rte_malloc.h>
+#include <rte_net_crc.h>
 #if defined(RTE_ARCH_ARM64)
 #include <rte_cpuflags.h>
 #include <rte_vect.h>
@@ -1766,8 +1767,9 @@ hns3_rx_buf_len_calc(struct rte_mempool *mp, uint16_t= *rx_buf_len)
 }
 
 static int
-hns3_rxq_conf_runtime_check(struct hns3_hw *hw, uint16_t buf_size,
-            &n= bsp;            = ;      uint16_t nb_desc)
+hns3_rxq_conf_runtime_check(struct hns3_hw *hw,
+            &n= bsp;            = ;  const struct rte_eth_rxconf *conf,
+            &n= bsp;            = ;  uint16_t buf_size, uint16_t nb_desc)
 {
         struct rte_eth_dev *dev = =3D &rte_eth_devices[hw->data->port_id];
         eth_rx_burst_t pkt_burst = =3D dev->rx_pkt_burst;
@@ -1800,6 +1802,14 @@ hns3_rxq_conf_runtime_check(struct hns3_hw *hw, uint= 16_t buf_size,
            &nb= sp;            retur= n -EINVAL;
            &nb= sp;    }
         }
+
+       if ((conf->offloads & RTE_ETH_= RX_OFFLOAD_KEEP_CRC) &&
+           pkt_burst != =3D hns3_recv_pkts_simple &&
+           pkt_burst != =3D hns3_recv_scattered_pkts) {
+            &n= bsp;  hns3_err(hw, "KEEP_CRC offload is not supported with the cu= rrent Rx function.");
+            &n= bsp;  return -EINVAL;
+       }
+
         return 0;
 }
 
@@ -1836,7 +1846,7 @@ hns3_rx_queue_conf_check(struct hns3_hw *hw, const st= ruct rte_eth_rxconf *conf,
         }
 
         if (hw->data->dev_st= arted) {
-            &n= bsp;  ret =3D hns3_rxq_conf_runtime_check(hw, *buf_size, nb_desc);
+            &n= bsp;  ret =3D hns3_rxq_conf_runtime_check(hw, conf, *buf_size, nb_desc= );
            &nb= sp;    if (ret) {
            &nb= sp;            hns3_= err(hw, "Rx queue runtime setup fail.");
            &nb= sp;            retur= n ret;
@@ -1957,6 +1967,8 @@ hns3_rx_queue_setup(struct rte_eth_dev *dev, uint16_t= idx, uint16_t nb_desc,
         else
            &nb= sp;    rxq->crc_len =3D 0;
 
+       rxq->keep_crc_fail_ptype =3D hw-&g= t;strip_crc_ptype;
+
         rxq->bulk_mbuf_num =3D = 0;
 
         rte_spinlock_lock(&hw-= >lock);
@@ -2430,6 +2442,55 @@ hns3_rx_ptp_timestamp_handle(struct hns3_rx_queue *r= xq, struct rte_mbuf *mbuf,
         pf->rx_timestamp =3D ti= mestamp;
 }
 
+static inline bool
+hns3_need_recalculate_crc(struct hns3_rx_queue *rxq, struct rte_mbuf *m) +{
+       uint32_t ptype =3D m->packet_type;=
+
+       if (rxq->keep_crc_fail_ptype =3D= =3D HNS3_STRIP_CRC_PTYPE_NONE)
+            &n= bsp;  return false;
+
+       if (m->pkt_len > HNS3_KEEP_CRC_= OK_MIN_PKT_LEN)
+            &n= bsp;  return false;
+
+       if (!(RTE_ETH_IS_IPV4_HDR(ptype) || R= TE_ETH_IS_IPV6_HDR(ptype)))
+            &n= bsp;  return false;
+
+       if (rxq->keep_crc_fail_ptype =3D= =3D HNS3_STRIP_CRC_PTYPE_TCP)
+            &n= bsp;  return (ptype & RTE_PTYPE_L4_MASK) =3D=3D RTE_PTYPE_L4_TCP;<= br> +
+       return true;
+}
+
+/*
+ * The hns3 driver requires that mbuf size must be at least 512B.
+ * When CRC is stripped by hardware, the pkt_len must be less than
+ * or equal to 60B. Therefore, the space of the mbuf is enough
+ * to insert the CRC.
+ */
+static_assert(HNS3_KEEP_CRC_OK_MIN_PKT_LEN < HNS3_MIN_BD_BUF_SIZE,
+             &= quot;buffer size too small to insert CRC");
+
+static inline void
+hns3_recalculate_crc(struct rte_mbuf *m)
+{
+       char *append_data;
+       uint32_t crc;
+
+       crc =3D rte_net_crc_calc(rte_pktmbuf_= mtod(m, void *),
+            &n= bsp;            = ;     m->data_len, RTE_NET_CRC32_ETH);
+
+       /*
+        * After CRC is stripped by hard= ware, pkt_len and data_len do not
+        * contain the CRC length. There= fore, after CRC data is appended
+        * by PMD again.
+        */
+       append_data =3D rte_pktmbuf_append(m,= RTE_ETHER_CRC_LEN);
+
+       /* CRC data is binary data and does n= ot care about the byte order. */
+       memcpy(append_data, &crc, RTE_ETH= ER_CRC_LEN);
+}
+
 uint16_t
 hns3_recv_pkts_simple(void *rx_queue,
            &nb= sp;          struct rte_mbuf *= *rx_pkts,
@@ -2500,8 +2561,7 @@ hns3_recv_pkts_simple(void *rx_queue,
            &nb= sp;    rxdp->rx.bd_base_info =3D 0;
 
            &nb= sp;    rxm->data_off =3D RTE_PKTMBUF_HEADROOM;
-            &n= bsp;  rxm->pkt_len =3D (uint16_t)(rte_le_to_cpu_16(rxd.rx.pkt_len))= -
-            &n= bsp;            = ;      rxq->crc_len;
+            &n= bsp;  rxm->pkt_len =3D (uint16_t)(rte_le_to_cpu_16(rxd.rx.pkt_len))= ;
            &nb= sp;    rxm->data_len =3D rxm->pkt_len;
            &nb= sp;    rxm->port =3D rxq->port_id;
            &nb= sp;    rxm->hash.rss =3D rte_le_to_cpu_32(rxd.rx.rss_hash= );
@@ -2526,6 +2586,12 @@ hns3_recv_pkts_simple(void *rx_queue,
            &nb= sp;    if (rxm->packet_type =3D=3D RTE_PTYPE_L2_ETHER_TIM= ESYNC)
            &nb= sp;            rxm-&= gt;ol_flags |=3D RTE_MBUF_F_RX_IEEE1588_PTP;
 
+            &n= bsp;  if (unlikely(rxq->crc_len > 0) &&
+            &n= bsp;      hns3_need_recalculate_crc(rxq, rxm))
+            &n= bsp;          hns3_recalculate= _crc(rxm);
+            &n= bsp;  rxm->pkt_len -=3D rxq->crc_len;
+            &n= bsp;  rxm->data_len -=3D rxq->crc_len;
+
            &nb= sp;    hns3_rxd_to_vlan_tci(rxq, rxm, l234_info, &rxd);<= br>  
            &nb= sp;    /* Increment bytes counter  */
@@ -2692,10 +2758,10 @@ hns3_recv_scattered_pkts(void *rx_queue,
 
            &nb= sp;    rxm->data_off =3D RTE_PKTMBUF_HEADROOM;
            &nb= sp;    rxm->data_len =3D rte_le_to_cpu_16(rxd.rx.size); +            &n= bsp;  rxm->next =3D NULL;
 
            &nb= sp;    if (!(bd_base_info & BIT(HNS3_RXD_FE_B))) {
            &nb= sp;            last_= seg =3D rxm;
-            &n= bsp;          rxm->next =3D= NULL;
            &nb= sp;            conti= nue;
            &nb= sp;    }
 
@@ -2710,22 +2776,6 @@ hns3_recv_scattered_pkts(void *rx_queue,
            &nb= sp;     */
            &nb= sp;    first_seg->pkt_len =3D rte_le_to_cpu_16(rxd.rx.pkt= _len);
 
-            &n= bsp;  /*
-            &n= bsp;   * This is the last buffer of the received packet. If the C= RC
-            &n= bsp;   * is not stripped by the hardware:
-            &n= bsp;   *  - Subtract the CRC length from the total packet le= ngth.
-            &n= bsp;   *  - If the last buffer only contains the whole CRC o= r a part
-            &n= bsp;   *  of it, free the mbuf associated to the last buffer= . If part
-            &n= bsp;   *  of the CRC is also contained in the previous mbuf,= subtract
-            &n= bsp;   *  the length of that CRC part from the data length o= f the
-            &n= bsp;   *  previous mbuf.
-            &n= bsp;   */
-            &n= bsp;  rxm->next =3D NULL;
-            &n= bsp;  if (unlikely(rxq->crc_len > 0)) {
-            &n= bsp;          first_seg->pk= t_len -=3D rxq->crc_len;
-            &n= bsp;          recalculate_data= _len(last_seg, rxm, rxq);
-            &n= bsp;  }
-
            &nb= sp;    first_seg->port =3D rxq->port_id;
            &nb= sp;    first_seg->hash.rss =3D rte_le_to_cpu_32(rxd.rx.rs= s_hash);
            &nb= sp;    first_seg->ol_flags |=3D RTE_MBUF_F_RX_RSS_HASH; @@ -2754,6 +2804,31 @@ hns3_recv_scattered_pkts(void *rx_queue,
 
            &nb= sp;    if (first_seg->packet_type =3D=3D RTE_PTYPE_L2_ETH= ER_TIMESYNC)
            &nb= sp;            rxm-&= gt;ol_flags |=3D RTE_MBUF_F_RX_IEEE1588_PTP;
+            &n= bsp;  /*
+            &n= bsp;   * This is the last buffer of the received packet. If the C= RC
+            &n= bsp;   * is not stripped by the hardware:
+            &n= bsp;   *  - Subtract the CRC length from the total packet le= ngth.
+            &n= bsp;   *  - If the last buffer only contains the whole CRC o= r a part
+            &n= bsp;   *  of it, free the mbuf associated to the last buffer= . If part
+            &n= bsp;   *  of the CRC is also contained in the previous mbuf,= subtract
+            &n= bsp;   *  the length of that CRC part from the data length o= f the
+            &n= bsp;   *  previous mbuf.
+            &n= bsp;   *
+            &n= bsp;   * In addition, the CRC is still stripped for a kind of pac= kets
+            &n= bsp;   * in hns3 NIC:
+            &n= bsp;   * 1. All IP-TCP packet whose the length is less than and e= qual
+            &n= bsp;   *    to 60 Byte (no CRC) on HIP08 network e= ngine.
+            &n= bsp;   * 2. All IP packet whose the length is less than and equal= to
+            &n= bsp;   *    60 Byte (no CRC) on HIP09 network engi= ne.
+            &n= bsp;   * In this case, the PMD calculates the CRC and appends it = to
+            &n= bsp;   * mbuf.
+            &n= bsp;   */
+            &n= bsp;  if (unlikely(rxq->crc_len > 0)) {
+            &n= bsp;          if (hns3_need_re= calculate_crc(rxq, first_seg))
+            &n= bsp;            = ;      hns3_recalculate_crc(first_seg);
+            &n= bsp;          first_seg->pk= t_len -=3D rxq->crc_len;
+            &n= bsp;          recalculate_data= _len(last_seg, rxm, rxq);
+            &n= bsp;  }
 
            &nb= sp;    hns3_rxd_to_vlan_tci(rxq, first_seg, l234_info, &= rxd);
 
diff --git a/drivers/net/hns3/hns3_rxtx.h b/drivers/net/hns3/hns3_rxtx.h index b6a6513307..f182ff6a9d 100644
--- a/drivers/net/hns3/hns3_rxtx.h
+++ b/drivers/net/hns3/hns3_rxtx.h
@@ -178,6 +178,8 @@
            &nb= sp;    (HNS3_TXD_VLD_CMD | HNS3_TXD_FE_CMD | HNS3_TXD_DEFAUL= T_BDTYPE)
 #define HNS3_TXD_SEND_SIZE_SHIFT      &= nbsp; 16
 
+#define HNS3_KEEP_CRC_OK_MIN_PKT_LEN   60
+
 enum hns3_pkt_l2t_type {
         HNS3_L2_TYPE_UNICAST,
         HNS3_L2_TYPE_MULTICAST, @@ -341,6 +343,7 @@ struct hns3_rx_queue {
          */
         uint8_t pvid_sw_discard_en= :1;
         uint8_t ptype_en:1; &= nbsp;        /* indicate if the ptype fi= eld enabled */
+       uint8_t keep_crc_fail_ptype:2;
 
         uint64_t mbuf_initializer;= /* value to init mbufs used with vector rx */
         /* offset_table: used for = vector, to solve execute re-order problem */
diff --git a/drivers/net/hns3/hns3_rxtx_vec.c b/drivers/net/hns3/hns3_rxtx_= vec.c
index 9708ec614e..bf37ce51b1 100644
--- a/drivers/net/hns3/hns3_rxtx_vec.c
+++ b/drivers/net/hns3/hns3_rxtx_vec.c
@@ -185,7 +185,8 @@ hns3_rx_check_vec_support(struct rte_eth_dev *dev)
         struct rte_eth_rxmode *rxm= ode =3D &dev->data->dev_conf.rxmode;
         uint64_t offloads_mask =3D= RTE_ETH_RX_OFFLOAD_TCP_LRO |
            &nb= sp;            =          RTE_ETH_RX_OFFLOAD_VLAN |<= br> -            &n= bsp;            = ;       RTE_ETH_RX_OFFLOAD_TIMESTAMP;
+            &n= bsp;            = ;       RTE_ETH_RX_OFFLOAD_TIMESTAMP |
+            &n= bsp;            = ;       RTE_ETH_RX_OFFLOAD_KEEP_CRC;
 
         if (dev->data->scatt= ered_rx)
            &nb= sp;    return -ENOTSUP;
diff --git a/drivers/net/hns3/hns3_rxtx_vec_neon.h b/drivers/net/hns3/hns3_= rxtx_vec_neon.h
index 0dc6b9f0a2..60ec501a2a 100644
--- a/drivers/net/hns3/hns3_rxtx_vec_neon.h
+++ b/drivers/net/hns3/hns3_rxtx_vec_neon.h
@@ -148,14 +148,6 @@ hns3_recv_burst_vec(struct hns3_rx_queue *__restrict r= xq,
            &nb= sp;    8, 9, 10, 11,      &nbs= p;     /* rx.rss_hash to rte_mbuf.hash.rss */
         };
 
-       uint16x8_t crc_adjust =3D {
-            &n= bsp;  0, 0,         /* ignore = pkt_type field */
-            &n= bsp;  rxq->crc_len, /* sub crc on pkt_len */
-            &n= bsp;  0,          &n= bsp; /* ignore high-16bits of pkt_len */
-            &n= bsp;  rxq->crc_len, /* sub crc on data_len */
-            &n= bsp;  0, 0, 0,      /* ignore non-length fiel= ds */
-       };
-
         /* compile-time verifies t= he shuffle mask */
         RTE_BUILD_BUG_ON(offsetof(= struct rte_mbuf, pkt_len) !=3D
            &nb= sp;            = offsetof(struct rte_mbuf, rx_descriptor_fields1) + 4);
@@ -171,7 +163,6 @@ hns3_recv_burst_vec(struct hns3_rx_queue *__restrict rx= q,
            &nb= sp;    uint8x16_t pkt_mb1, pkt_mb2, pkt_mb3, pkt_mb4;
            &nb= sp;    uint64x2_t mbp1, mbp2;
            &nb= sp;    uint16x4_t bd_vld =3D {0};
-            &n= bsp;  uint16x8_t tmp;
            &nb= sp;    uint64_t stat;
 
            &nb= sp;    /* calc how many bd valid */
@@ -225,16 +216,6 @@ hns3_recv_burst_vec(struct hns3_rx_queue *__restrict r= xq,
            &nb= sp;    pkt_mb3 =3D vqtbl2q_u8(pkt_mbuf3, shuf_desc_fields_ms= k);
            &nb= sp;    pkt_mb4 =3D vqtbl2q_u8(pkt_mbuf4, shuf_desc_fields_ms= k);
 
-            &n= bsp;  /* 4 packets remove crc */
-            &n= bsp;  tmp =3D vsubq_u16(vreinterpretq_u16_u8(pkt_mb1), crc_adjust); -            &n= bsp;  pkt_mb1 =3D vreinterpretq_u8_u16(tmp);
-            &n= bsp;  tmp =3D vsubq_u16(vreinterpretq_u16_u8(pkt_mb2), crc_adjust); -            &n= bsp;  pkt_mb2 =3D vreinterpretq_u8_u16(tmp);
-            &n= bsp;  tmp =3D vsubq_u16(vreinterpretq_u16_u8(pkt_mb3), crc_adjust); -            &n= bsp;  pkt_mb3 =3D vreinterpretq_u8_u16(tmp);
-            &n= bsp;  tmp =3D vsubq_u16(vreinterpretq_u16_u8(pkt_mb4), crc_adjust); -            &n= bsp;  pkt_mb4 =3D vreinterpretq_u8_u16(tmp);
-
            &nb= sp;    /* save packet info to rx_pkts mbuf */
            &nb= sp;    vst1q_u8((void *)&sw_ring[pos + 0].mbuf->rx_de= scriptor_fields1,
            &nb= sp;            = pkt_mb1);
diff --git a/drivers/net/hns3/hns3_rxtx_vec_sve.c b/drivers/net/hns3/hns3_r= xtx_vec_sve.c
index 8aa4448558..67c87f570e 100644
--- a/drivers/net/hns3/hns3_rxtx_vec_sve.c
+++ b/drivers/net/hns3/hns3_rxtx_vec_sve.c
@@ -36,8 +36,7 @@ hns3_desc_parse_field_sve(struct hns3_rx_queue *rxq,
            &nb= sp;    /* init rte_mbuf.rearm_data last 64-bit */
            &nb= sp;    rx_pkts[i]->ol_flags =3D RTE_MBUF_F_RX_RSS_HASH;             &nb= sp;    rx_pkts[i]->hash.rss =3D rxdp[i].rx.rss_hash;
-            &n= bsp;  rx_pkts[i]->pkt_len =3D rte_le_to_cpu_16(rxdp[i].rx.pkt_len) = -
-            &n= bsp;            = ;            &n= bsp; rxq->crc_len;
+            &n= bsp;  rx_pkts[i]->pkt_len =3D rte_le_to_cpu_16(rxdp[i].rx.pkt_len);=
            &nb= sp;    rx_pkts[i]->data_len =3D rx_pkts[i]->pkt_len;  
            &nb= sp;    l234_info =3D rxdp[i].rx.l234_info;
--
2.33.0

--_000_CH3PR12MB86586F356A796D48F62D06B4A15BACH3PR12MB8658namp_--