From nobody Sat Nov 23 03:51:40 2024 Received: from EUR03-AM7-obe.outbound.protection.outlook.com (mail-am7eur03on2085.outbound.protection.outlook.com [40.107.105.85]) (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 82A6114F9D9; Fri, 15 Nov 2024 03:03:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.105.85 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731639831; cv=fail; b=j+lxo0RL7sHGzn3ve0UsANd2T4/sZHKtwwaOaesSJBA8UpjtoCykaW24Cwi7oV5+nqymk3mJirHHS+YOfN+2MOLCBMvPj81UtIQ3xpuUBLIKGnV0gGXZBvzHSIAaHu20tuNQcybaPWKQgipAY/fgMIGCAyxdY+FYTPgsgXqPUxw= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731639831; c=relaxed/simple; bh=jDzdflMFBGLq7JisXPAx45zswPL1Xdmze9bB6OwstL4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=rP+EcZ8pyPksyhmXlGnNhktT075ahxGCwPKGNgieiuEWtBJj/GpQXC3E60W7XqYndileP0ZgqBTfg3ayP5QBQPtUOxgPMHjMFTvRR/PeskMPZJyAHv6E8VWQIIqfof6cazpCpUpaUJelZ5t/yFd9QzZhfCyqYeBigUgbH/XmpbY= 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=i5ok+M9B; arc=fail smtp.client-ip=40.107.105.85 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="i5ok+M9B" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=q9QkM/ek08CSyHpFyQZRXxdFvrf4bA78rMAPWNMT7F8FLcZo7I5tPUWfPUO4hbeuyU/Yp7uOIv3EWJaX9u8eFmD4jqYjESQRt7yjPWfV7RJA8IgW/gAjl4hNKRkm7BUtwKxuhPj1wjkoMZeCFNWk/1gutwCCal4dAt3nBFzwSW8aOGpolDyou1L0Qx5VJ5AAD347i5H/kV9mSDxcMrT58orRQCbyxBHBZqL2Ab7lMoys2CuuL4X03N1C73cIO1q2XkIDfm9ynzHL4iRIn44fuI9FPCJDblXVTB2owQLrEtdZrn/TITkrgmCDt2erqAloWOOTki3BNDHqktaiMHlIuA== 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=BVIfY2blyRDn27O2nVcGRh/gl54CkwsBRLjQmOShMIs=; b=HGtsL6YGz+bgQ3JHGQLzsMHLvUn0G1wIakD0AaIzmTV8/z9tW0WcAbD8f8UBRnYEZoYy72fof83pj7XIVscFG8ShAmyERBvb+t+0d65tn7MRFPe6UR8q2gqWESB448vEdAxjEFv7ytLsKQZ4eM50G6qrs2cYz+mU0ewYXWGPmBFF/el+qcyoO0qj0bn54t2Eg7I2rOCsc+4JOjbs9Dj9q62VXsFv8tm1OwK7XpdjafvIpjXORP99OnfePzw/f8z+O0hbdH2hlzcHHLKI6/M4lqrl1tBMIUZIoVwJmY4CN8AX44U1MZO9rKHkSLeCaK148+qgB7hWleQw+TJvrPCWWQ== 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=BVIfY2blyRDn27O2nVcGRh/gl54CkwsBRLjQmOShMIs=; b=i5ok+M9Ba1HKdmjD/bKXn/yxkooVp35Nx6KAfllZkc42aBgyBOm3iwv57vIyOdXTksJfrsTEJfMpIuzp/hpsAPT7KAdTYZYD/zuA9SbmN6aC2k8007peJjq4BCLgKtPlNEFYMIZ1KqsMbb3f4Ll5t+g6rtBRTlPSs/kneMBT3i7teqBV/7zhNGRnjFdT6A+TxynE5UJ9UrrgskHYOcVGxQ7yFYt7yaAX/wk3dv80e7Fy+yoXY68vuyKp9wtsQGZ7JP1pxwAMKNAK6cVg/RRaoVlmZzZUsqmHZ8zpD7UkuM2nASCMBngkGSM3qgRre1t+Djr3gDh+tEJpHreCLSjDEQ== 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 VI1PR04MB10028.eurprd04.prod.outlook.com (2603:10a6:800:1db::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8158.18; Fri, 15 Nov 2024 03:03:45 +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.017; Fri, 15 Nov 2024 03:03:45 +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 v4 net-next 4/5] net: enetc: add LSO support for i.MX95 ENETC PF Date: Fri, 15 Nov 2024 10:47:43 +0800 Message-Id: <20241115024744.1903377-5-wei.fang@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241115024744.1903377-1-wei.fang@nxp.com> References: <20241115024744.1903377-1-wei.fang@nxp.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SI1PR02CA0047.apcprd02.prod.outlook.com (2603:1096:4:1f5::15) To PAXPR04MB8510.eurprd04.prod.outlook.com (2603:10a6:102:211::7) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB8510:EE_|VI1PR04MB10028:EE_ X-MS-Office365-Filtering-Correlation-Id: 64069a76-83b1-4241-b178-08dd05221e69 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|52116014|1800799024|366016|38350700014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?LkzXnqPJ3A3vnLKh2q74ZHIP2BXxSvtapyiHG8T5hWFwa9u8WiBIF9uxRMbO?= =?us-ascii?Q?tEVsrp3l74nmMOfMN2mDjThftQBQSwl1yioNcbgA0AohYjU/r33/M3SnqdDE?= =?us-ascii?Q?AbH0NFo64aGcYCrxCUeKilSijDYOeEnwEQqdLr0HziEcUW7AGJV5EuEZ6+mx?= =?us-ascii?Q?NUeocJaKSToUc0cZtcOhfz1oks/OR/zVAzBMuK2kwKFpFJI9OX9/lR9nsxwQ?= =?us-ascii?Q?OJ1yWe5DbmJDe9yOS6GkZJW/38Al1bce9/727Z/aMIeu22lV3eHKX0JpgEWp?= =?us-ascii?Q?NBv7OF3NFIhtiDwpOE/4ajHCifrsExVwxoNeXMsF6U/b7Cf7OR/EZgCfawZm?= =?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4q3WyXnXu/PH5hJmEz5zyqcq3CZ2F9l8ue6YQG?= =?us-ascii?Q?tN2G9+Tusx9JTbxfkBJEDN8juXrZsHSdbfo9e+Zg6oF78Xye54tMGWR4WIWN?= =?us-ascii?Q?1ILN05A7L7ugG0t00/zPxOlxPu8Fej03NTNhAwX0/W1zKLt4WO0/w4mmP6tq?= =?us-ascii?Q?6GtCQy0=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PAXPR04MB8510.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(376014)(52116014)(1800799024)(366016)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?vx5bRDgcoFlART4O7sPX0VXUhkjhPkIsLRqmv8gKBQg9lJEi0SuY9mW+wnsV?= =?us-ascii?Q?7hjm4E4Kt4Qha0JY0qI9u79YU8YIHncAwch6R7dqTXRVv37nYuv8IRgpZiHs?= =?us-ascii?Q?mtuYrUUAVml5PMNvOjmuYloHghpWe6cTbxxgimOflHY/7wHlQvzzBz1XcZba?= =?us-ascii?Q?YV2W9xv8eYz/OM9SoO+8UM+JFdles34FyOTQRihxoWHJKE4r4JqWwNl6+2O2?= =?us-ascii?Q?zvMSWjSWj0L0tFoHcc5/MMa8ehblveO00CDa8/XPr27F0zNScg1pv2aUd+5z?= =?us-ascii?Q?rKAbbc590uwG2XE7gjZb904PkJ7nXk2rwQGiaidY8ryyfIW+sVMUmRA6f+Yw?= =?us-ascii?Q?IjHGsLx0CP1ICWnxaGM9E7AXLGqlkeGdf7XhcLSoDqFubwDQ2hZd61+sjbqg?= =?us-ascii?Q?LahTOSb2XmZGGopwtCz5PxEFaw4pIku7g64Q3KeBpOVquXIkPZ3cOQeeRA+F?= =?us-ascii?Q?UsiSNQA6sL57znqthhrMRfMiPYjdcfZxksvbKEchAGk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McXwRtH5Q6vwD7okpGH0TGI+EoEGIScil9s/DE+3fdYTJ+KV8fZ4P4oF0?= =?us-ascii?Q?lqYS6i8qAWd/5Zhiq9WVXLGrxpwuLxHWETn7oPAeRab9VFHKxjJBv4v5THhB?= =?us-ascii?Q?oVc9jCaaFmFuhmbwQt2TzI1y7VVJH+wtFEd3v84EXJZ1mma0gH55WJq39BVM?= =?us-ascii?Q?t7Qxea4C21UMk6z6cpdlSmhWNJk+Z8ZJM6WorJE1?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 64069a76-83b1-4241-b178-08dd05221e69 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB8510.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Nov 2024 03:03:45.7634 (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: BraBmCBOXLj4R/RXAku5836VPIvo7zcjvJa0yYrUgRhpoSw6oe4ZDO91CJf74wesNTQz/4skKMKaW0IDC3n87A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB10028 Content-Type: text/plain; charset="utf-8" ENETC rev 4.1 supports large send offload (LSO), segmenting large TCP and UDP transmit units into multiple Ethernet frames. To support LSO, software needs to fill some auxiliary information in Tx BD, such as LSO header length, frame length, LSO maximum segment size, etc. At 1Gbps link rate, TCP segmentation was tested using iperf3, and the CPU performance before and after applying the patch was compared through the top command. It can be seen that LSO saves a significant amount of CPU cycles compared to software TSO. Before applying the patch: %Cpu(s): 0.1 us, 4.1 sy, 0.0 ni, 85.7 id, 0.0 wa, 0.5 hi, 9.7 si After applying the patch: %Cpu(s): 0.1 us, 2.3 sy, 0.0 ni, 94.5 id, 0.0 wa, 0.4 hi, 2.6 si Signed-off-by: Wei Fang Reviewed-by: Frank Li Reviewed-by: Claudiu Manoil --- v2: no changes v3: use enetc_skb_is_ipv6() helper fucntion which is added in patch 2 v4: fix a typo --- drivers/net/ethernet/freescale/enetc/enetc.c | 266 +++++++++++++++++- drivers/net/ethernet/freescale/enetc/enetc.h | 15 + .../net/ethernet/freescale/enetc/enetc4_hw.h | 22 ++ .../net/ethernet/freescale/enetc/enetc_hw.h | 15 +- .../freescale/enetc/enetc_pf_common.c | 3 + 5 files changed, 311 insertions(+), 10 deletions(-) diff --git a/drivers/net/ethernet/freescale/enetc/enetc.c b/drivers/net/eth= ernet/freescale/enetc/enetc.c index 7c6b844c2e96..d05eaaf8a812 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc.c +++ b/drivers/net/ethernet/freescale/enetc/enetc.c @@ -527,6 +527,233 @@ static void enetc_tso_complete_csum(struct enetc_bdr = *tx_ring, struct tso_t *tso } } =20 +static inline int enetc_lso_count_descs(const struct sk_buff *skb) +{ + /* 4 BDs: 1 BD for LSO header + 1 BD for extended BD + 1 BD + * for linear area data but not include LSO header, namely + * skb_headlen(skb) - lso_hdr_len. And 1 BD for gap. + */ + return skb_shinfo(skb)->nr_frags + 4; +} + +static int enetc_lso_get_hdr_len(const struct sk_buff *skb) +{ + int hdr_len, tlen; + + tlen =3D skb_is_gso_tcp(skb) ? tcp_hdrlen(skb) : sizeof(struct udphdr); + hdr_len =3D skb_transport_offset(skb) + tlen; + + return hdr_len; +} + +static void enetc_lso_start(struct sk_buff *skb, struct enetc_lso_t *lso) +{ + lso->lso_seg_size =3D skb_shinfo(skb)->gso_size; + lso->ipv6 =3D enetc_skb_is_ipv6(skb); + lso->tcp =3D skb_is_gso_tcp(skb); + lso->l3_hdr_len =3D skb_network_header_len(skb); + lso->l3_start =3D skb_network_offset(skb); + lso->hdr_len =3D enetc_lso_get_hdr_len(skb); + lso->total_len =3D skb->len - lso->hdr_len; +} + +static void enetc_lso_map_hdr(struct enetc_bdr *tx_ring, struct sk_buff *s= kb, + int *i, struct enetc_lso_t *lso) +{ + union enetc_tx_bd txbd_tmp, *txbd; + struct enetc_tx_swbd *tx_swbd; + u16 frm_len, frm_len_ext; + u8 flags, e_flags =3D 0; + dma_addr_t addr; + char *hdr; + + /* Get the first BD of the LSO BDs chain */ + txbd =3D ENETC_TXBD(*tx_ring, *i); + tx_swbd =3D &tx_ring->tx_swbd[*i]; + prefetchw(txbd); + + /* Prepare LSO header: MAC + IP + TCP/UDP */ + hdr =3D tx_ring->tso_headers + *i * TSO_HEADER_SIZE; + memcpy(hdr, skb->data, lso->hdr_len); + addr =3D tx_ring->tso_headers_dma + *i * TSO_HEADER_SIZE; + + frm_len =3D lso->total_len & 0xffff; + frm_len_ext =3D (lso->total_len >> 16) & 0xf; + + /* Set the flags of the first BD */ + flags =3D ENETC_TXBD_FLAGS_EX | ENETC_TXBD_FLAGS_CSUM_LSO | + ENETC_TXBD_FLAGS_LSO | ENETC_TXBD_FLAGS_L4CS; + + enetc_clear_tx_bd(&txbd_tmp); + txbd_tmp.addr =3D cpu_to_le64(addr); + txbd_tmp.hdr_len =3D cpu_to_le16(lso->hdr_len); + + /* first BD needs frm_len and offload flags set */ + txbd_tmp.frm_len =3D cpu_to_le16(frm_len); + txbd_tmp.flags =3D flags; + + if (lso->tcp) + txbd_tmp.l4t =3D ENETC_TXBD_L4T_TCP; + else + txbd_tmp.l4t =3D ENETC_TXBD_L4T_UDP; + + if (lso->ipv6) + txbd_tmp.l3t =3D 1; + else + txbd_tmp.ipcs =3D 1; + + /* l3_hdr_size in 32-bits (4 bytes) */ + txbd_tmp.l3_hdr_size =3D lso->l3_hdr_len / 4; + txbd_tmp.l3_start =3D lso->l3_start; + + /* For the LSO header we do not set the dma address since + * we do not want it unmapped when we do cleanup. We still + * set len so that we count the bytes sent. + */ + tx_swbd->len =3D lso->hdr_len; + tx_swbd->do_twostep_tstamp =3D false; + tx_swbd->check_wb =3D false; + + /* Actually write the header in the BD */ + *txbd =3D txbd_tmp; + + /* Get the next BD, and the next BD is extended BD */ + enetc_bdr_idx_inc(tx_ring, i); + txbd =3D ENETC_TXBD(*tx_ring, *i); + tx_swbd =3D &tx_ring->tx_swbd[*i]; + prefetchw(txbd); + + enetc_clear_tx_bd(&txbd_tmp); + if (skb_vlan_tag_present(skb)) { + /* Setup the VLAN fields */ + txbd_tmp.ext.vid =3D cpu_to_le16(skb_vlan_tag_get(skb)); + txbd_tmp.ext.tpid =3D 0; /* < C-TAG */ + e_flags =3D ENETC_TXBD_E_FLAGS_VLAN_INS; + } + + /* Write the BD */ + txbd_tmp.ext.e_flags =3D e_flags; + txbd_tmp.ext.lso_sg_size =3D cpu_to_le16(lso->lso_seg_size); + txbd_tmp.ext.frm_len_ext =3D cpu_to_le16(frm_len_ext); + *txbd =3D txbd_tmp; +} + +static int enetc_lso_map_data(struct enetc_bdr *tx_ring, struct sk_buff *s= kb, + int *i, struct enetc_lso_t *lso, int *count) +{ + union enetc_tx_bd txbd_tmp, *txbd =3D NULL; + struct enetc_tx_swbd *tx_swbd; + skb_frag_t *frag; + dma_addr_t dma; + u8 flags =3D 0; + int len, f; + + len =3D skb_headlen(skb) - lso->hdr_len; + if (len > 0) { + dma =3D dma_map_single(tx_ring->dev, skb->data + lso->hdr_len, + len, DMA_TO_DEVICE); + if (unlikely(dma_mapping_error(tx_ring->dev, dma))) { + netdev_err(tx_ring->ndev, "DMA map error\n"); + goto dma_err; + } + + enetc_bdr_idx_inc(tx_ring, i); + txbd =3D ENETC_TXBD(*tx_ring, *i); + tx_swbd =3D &tx_ring->tx_swbd[*i]; + prefetchw(txbd); + *count +=3D 1; + + enetc_clear_tx_bd(&txbd_tmp); + txbd_tmp.addr =3D cpu_to_le64(dma); + txbd_tmp.buf_len =3D cpu_to_le16(len); + + tx_swbd->dma =3D dma; + tx_swbd->len =3D len; + tx_swbd->is_dma_page =3D 0; + tx_swbd->dir =3D DMA_TO_DEVICE; + } + + frag =3D &skb_shinfo(skb)->frags[0]; + for (f =3D 0; f < skb_shinfo(skb)->nr_frags; f++, frag++) { + if (txbd) + *txbd =3D txbd_tmp; + + len =3D skb_frag_size(frag); + dma =3D skb_frag_dma_map(tx_ring->dev, frag, 0, len, + DMA_TO_DEVICE); + if (unlikely(dma_mapping_error(tx_ring->dev, dma))) { + netdev_err(tx_ring->ndev, "DMA map error\n"); + goto dma_err; + } + + /* Get the next BD */ + enetc_bdr_idx_inc(tx_ring, i); + txbd =3D ENETC_TXBD(*tx_ring, *i); + tx_swbd =3D &tx_ring->tx_swbd[*i]; + prefetchw(txbd); + *count +=3D 1; + + enetc_clear_tx_bd(&txbd_tmp); + txbd_tmp.addr =3D cpu_to_le64(dma); + txbd_tmp.buf_len =3D cpu_to_le16(len); + + tx_swbd->dma =3D dma; + tx_swbd->len =3D len; + tx_swbd->is_dma_page =3D 1; + tx_swbd->dir =3D DMA_TO_DEVICE; + } + + /* Last BD needs 'F' bit set */ + flags |=3D ENETC_TXBD_FLAGS_F; + txbd_tmp.flags =3D flags; + *txbd =3D txbd_tmp; + + tx_swbd->is_eof =3D 1; + tx_swbd->skb =3D skb; + + return 0; + +dma_err: + return -ENOMEM; +} + +static int enetc_lso_hw_offload(struct enetc_bdr *tx_ring, struct sk_buff = *skb) +{ + struct enetc_tx_swbd *tx_swbd; + struct enetc_lso_t lso =3D {0}; + int err, i, count =3D 0; + + /* Initialize the LSO handler */ + enetc_lso_start(skb, &lso); + i =3D tx_ring->next_to_use; + + enetc_lso_map_hdr(tx_ring, skb, &i, &lso); + /* First BD and an extend BD */ + count +=3D 2; + + err =3D enetc_lso_map_data(tx_ring, skb, &i, &lso, &count); + if (err) + goto dma_err; + + /* Go to the next BD */ + enetc_bdr_idx_inc(tx_ring, &i); + tx_ring->next_to_use =3D i; + enetc_update_tx_ring_tail(tx_ring); + + return count; + +dma_err: + do { + tx_swbd =3D &tx_ring->tx_swbd[i]; + enetc_free_tx_frame(tx_ring, tx_swbd); + if (i =3D=3D 0) + i =3D tx_ring->bd_count; + i--; + } while (count--); + + return 0; +} + static int enetc_map_tx_tso_buffs(struct enetc_bdr *tx_ring, struct sk_buf= f *skb) { struct enetc_ndev_priv *priv =3D netdev_priv(tx_ring->ndev); @@ -647,14 +874,26 @@ static netdev_tx_t enetc_start_xmit(struct sk_buff *s= kb, tx_ring =3D priv->tx_ring[skb->queue_mapping]; =20 if (skb_is_gso(skb)) { - if (enetc_bd_unused(tx_ring) < tso_count_descs(skb)) { - netif_stop_subqueue(ndev, tx_ring->index); - return NETDEV_TX_BUSY; - } + /* LSO data unit lengths of up to 256KB are supported */ + if (priv->active_offloads & ENETC_F_LSO && + (skb->len - enetc_lso_get_hdr_len(skb)) <=3D + ENETC_LSO_MAX_DATA_LEN) { + if (enetc_bd_unused(tx_ring) < enetc_lso_count_descs(skb)) { + netif_stop_subqueue(ndev, tx_ring->index); + return NETDEV_TX_BUSY; + } =20 - enetc_lock_mdio(); - count =3D enetc_map_tx_tso_buffs(tx_ring, skb); - enetc_unlock_mdio(); + count =3D enetc_lso_hw_offload(tx_ring, skb); + } else { + if (enetc_bd_unused(tx_ring) < tso_count_descs(skb)) { + netif_stop_subqueue(ndev, tx_ring->index); + return NETDEV_TX_BUSY; + } + + enetc_lock_mdio(); + count =3D enetc_map_tx_tso_buffs(tx_ring, skb); + enetc_unlock_mdio(); + } } else { if (unlikely(skb_shinfo(skb)->nr_frags > priv->max_frags)) if (unlikely(skb_linearize(skb))) @@ -1800,6 +2039,9 @@ void enetc_get_si_caps(struct enetc_si *si) si->num_rss =3D ENETC_SIRSSCAPR_GET_NUM_RSS(rss); } =20 + if (val & ENETC_SIPCAPR0_LSO) + si->hw_features |=3D ENETC_SI_F_LSO; + if (val & ENETC_SIPCAPR0_QBV) si->hw_features |=3D ENETC_SI_F_QBV; =20 @@ -2104,6 +2346,13 @@ static int enetc_setup_default_rss_table(struct enet= c_si *si, int num_groups) return 0; } =20 +static void enetc_set_lso_flags_mask(struct enetc_hw *hw) +{ + enetc_wr(hw, ENETC4_SILSOSFMR0, + SILSOSFMR0_VAL_SET(TCP_NL_SEG_FLAGS_DMASK, TCP_NL_SEG_FLAGS_DMASK)); + enetc_wr(hw, ENETC4_SILSOSFMR1, 0); +} + int enetc_configure_si(struct enetc_ndev_priv *priv) { struct enetc_si *si =3D priv->si; @@ -2117,6 +2366,9 @@ int enetc_configure_si(struct enetc_ndev_priv *priv) /* enable SI */ enetc_wr(hw, ENETC_SIMR, ENETC_SIMR_EN); =20 + if (si->hw_features & ENETC_SI_F_LSO) + enetc_set_lso_flags_mask(hw); + /* TODO: RSS support for i.MX95 will be supported later, and the * is_enetc_rev1() condition will be removed */ diff --git a/drivers/net/ethernet/freescale/enetc/enetc.h b/drivers/net/eth= ernet/freescale/enetc/enetc.h index a78af4f624e0..0a69f72fe8ec 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc.h +++ b/drivers/net/ethernet/freescale/enetc/enetc.h @@ -41,6 +41,19 @@ struct enetc_tx_swbd { u8 qbv_en:1; }; =20 +struct enetc_lso_t { + bool ipv6; + bool tcp; + u8 l3_hdr_len; + u8 hdr_len; /* LSO header length */ + u8 l3_start; + u16 lso_seg_size; + int total_len; /* total data length, not include LSO header */ +}; + +#define ENETC_1KB_SIZE 1024 +#define ENETC_LSO_MAX_DATA_LEN (256 * ENETC_1KB_SIZE) + #define ENETC_RX_MAXFRM_SIZE ENETC_MAC_MAXFRM_SIZE #define ENETC_RXB_TRUESIZE 2048 /* PAGE_SIZE >> 1 */ #define ENETC_RXB_PAD NET_SKB_PAD /* add extra space if needed */ @@ -238,6 +251,7 @@ enum enetc_errata { #define ENETC_SI_F_PSFP BIT(0) #define ENETC_SI_F_QBV BIT(1) #define ENETC_SI_F_QBU BIT(2) +#define ENETC_SI_F_LSO BIT(3) =20 struct enetc_drvdata { u32 pmac_offset; /* Only valid for PSI which supports 802.1Qbu */ @@ -353,6 +367,7 @@ enum enetc_active_offloads { ENETC_F_QBU =3D BIT(11), ENETC_F_RXCSUM =3D BIT(12), ENETC_F_TXCSUM =3D BIT(13), + ENETC_F_LSO =3D BIT(14), }; =20 enum enetc_flags_bit { diff --git a/drivers/net/ethernet/freescale/enetc/enetc4_hw.h b/drivers/net= /ethernet/freescale/enetc/enetc4_hw.h index 26b220677448..cdde8e93a73c 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc4_hw.h +++ b/drivers/net/ethernet/freescale/enetc/enetc4_hw.h @@ -12,6 +12,28 @@ #define NXP_ENETC_VENDOR_ID 0x1131 #define NXP_ENETC_PF_DEV_ID 0xe101 =20 +/**********************Station interface registers************************/ +/* Station interface LSO segmentation flag mask register 0/1 */ +#define ENETC4_SILSOSFMR0 0x1300 +#define SILSOSFMR0_TCP_MID_SEG GENMASK(27, 16) +#define SILSOSFMR0_TCP_1ST_SEG GENMASK(11, 0) +#define SILSOSFMR0_VAL_SET(first, mid) ((((mid) << 16) & SILSOSFMR0_TCP_M= ID_SEG) | \ + ((first) & SILSOSFMR0_TCP_1ST_SEG)) + +#define ENETC4_SILSOSFMR1 0x1304 +#define SILSOSFMR1_TCP_LAST_SEG GENMASK(11, 0) +#define TCP_FLAGS_FIN BIT(0) +#define TCP_FLAGS_SYN BIT(1) +#define TCP_FLAGS_RST BIT(2) +#define TCP_FLAGS_PSH BIT(3) +#define TCP_FLAGS_ACK BIT(4) +#define TCP_FLAGS_URG BIT(5) +#define TCP_FLAGS_ECE BIT(6) +#define TCP_FLAGS_CWR BIT(7) +#define TCP_FLAGS_NS BIT(8) +/* According to tso_build_hdr(), clear all special flags for not last pack= et. */ +#define TCP_NL_SEG_FLAGS_DMASK (TCP_FLAGS_FIN | TCP_FLAGS_RST | TCP_FLAGS= _PSH) + /***************************ENETC port registers**************************/ #define ENETC4_ECAPR0 0x0 #define ECAPR0_RFS BIT(2) diff --git a/drivers/net/ethernet/freescale/enetc/enetc_hw.h b/drivers/net/= ethernet/freescale/enetc/enetc_hw.h index 590b1412fadf..34a3e8f1496e 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc_hw.h +++ b/drivers/net/ethernet/freescale/enetc/enetc_hw.h @@ -28,6 +28,8 @@ #define ENETC_SIPCAPR0_QBV BIT(4) #define ENETC_SIPCAPR0_QBU BIT(3) #define ENETC_SIPCAPR0_RFS BIT(2) +#define ENETC_SIPCAPR0_LSO BIT(1) +#define ENETC_SIPCAPR0_RSC BIT(0) #define ENETC_SIPCAPR1 0x24 #define ENETC_SITGTGR 0x30 #define ENETC_SIRBGCR 0x38 @@ -554,7 +556,10 @@ static inline u64 _enetc_rd_reg64_wa(void __iomem *reg) union enetc_tx_bd { struct { __le64 addr; - __le16 buf_len; + union { + __le16 buf_len; + __le16 hdr_len; /* For LSO, ENETC 4.1 and later */ + }; __le16 frm_len; union { struct { @@ -574,13 +579,16 @@ union enetc_tx_bd { __le32 tstamp; __le16 tpid; __le16 vid; - u8 reserved[6]; + __le16 lso_sg_size; /* For ENETC 4.1 and later */ + __le16 frm_len_ext; /* For ENETC 4.1 and later */ + u8 reserved[2]; u8 e_flags; u8 flags; } ext; /* Tx BD extension */ struct { __le32 tstamp; - u8 reserved[10]; + u8 reserved[8]; + __le16 lso_err_count; /* For ENETC 4.1 and later */ u8 status; u8 flags; } wb; /* writeback descriptor */ @@ -589,6 +597,7 @@ union enetc_tx_bd { enum enetc_txbd_flags { ENETC_TXBD_FLAGS_L4CS =3D BIT(0), /* For ENETC 4.1 and later */ ENETC_TXBD_FLAGS_TSE =3D BIT(1), + ENETC_TXBD_FLAGS_LSO =3D BIT(1), /* For ENETC 4.1 and later */ ENETC_TXBD_FLAGS_W =3D BIT(2), ENETC_TXBD_FLAGS_CSUM_LSO =3D BIT(3), /* For ENETC 4.1 and later */ ENETC_TXBD_FLAGS_TXSTART =3D BIT(4), diff --git a/drivers/net/ethernet/freescale/enetc/enetc_pf_common.c b/drive= rs/net/ethernet/freescale/enetc/enetc_pf_common.c index 2c4c6af672e7..82a67356abe4 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc_pf_common.c +++ b/drivers/net/ethernet/freescale/enetc/enetc_pf_common.c @@ -126,6 +126,9 @@ void enetc_pf_netdev_setup(struct enetc_si *si, struct = net_device *ndev, if (si->drvdata->tx_csum) priv->active_offloads |=3D ENETC_F_TXCSUM; =20 + if (si->hw_features & ENETC_SI_F_LSO) + priv->active_offloads |=3D ENETC_F_LSO; + /* TODO: currently, i.MX95 ENETC driver does not support advanced feature= s */ if (!is_enetc_rev1(si)) { ndev->hw_features &=3D ~(NETIF_F_HW_VLAN_CTAG_FILTER | NETIF_F_LOOPBACK); --=20 2.34.1