From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=40.107.130.52 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796368227; b=WxuGh/p4SpCLeV8QFZ3LM77IB/LdcHxZvAn64lGdAhWYHNvVRujZMtHrXv3Pe/v35uzU 5W346LKR/c1ec1jIho42ObwasjC1SgNoJJRKsYEc/V0o0/Q9VC3BvTf18RmaLh0hpmX// 73t3/BhRLihK52FOng3A/AsGL5bD2x59bZgnLlorIXE9dCSAsv6yWFyfI2IGObxtCV9d8 PLViB5svfJ8MDojqOa/9oioM1dqA82Da3w9dVLD7pRKBUTB2E+ant4YgC/tu+PyAhEJ4b SPxD0I2P1FWDRsS+L2D3ITL47G2zkeoznwTNHqD4itAY1cTDRUXGyMRBMimj8FfTYow== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796368227; h=DMARC-Filter:DKIM-Signature:Received:Received:From:To:Cc:Subject: Date:Message-Id:X-Mailer:In-Reply-To:References: Content-Transfer-Encoding:Content-Type:X-ClientProxiedBy:MIME-Version: X-MS-PublicTrafficType:X-MS-TrafficTypeDiagnostic: X-MS-Office365-Filtering-Correlation-Id:X-MS-Exchange-SenderADCheck: X-MS-Exchange-AntiSpam-Relay:X-Microsoft-Antispam: X-Microsoft-Antispam-Message-Info:X-Forefront-Antispam-Report: X-MS-Exchange-AntiSpam-MessageData-ChunkCount: X-MS-Exchange-AntiSpam-MessageData-0:X-OriginatorOrg: X-MS-Exchange-CrossTenant-Network-Message-Id: X-MS-Exchange-CrossTenant-AuthSource:X-MS-Exchange-CrossTenant-AuthAs: X-MS-Exchange-CrossTenant-OriginalArrivalTime: X-MS-Exchange-CrossTenant-FromEntityHeader: X-MS-Exchange-CrossTenant-Id:X-MS-Exchange-CrossTenant-MailboxType: X-MS-Exchange-CrossTenant-UserPrincipalName: X-MS-Exchange-Transport-CrossTenantHeadersStamped; bh=UNq8Pzq3yWGfP2BAAYhd2CJfknyMqTKMUzRPZaiMj90=; b=ZYAlSxvbRhPE96n4UujW75wS5LxQXYeIGMdYtxTA41j0xKrUS46j4AAIHtigQsMesRP/ HigmxE9cL1IwWpQCl0/cgJw0YMRxWjcvKUZPXhbliEDCLTU+KyZHF8olF7L5AoNs8sT6Y Gtedl2DttWSsCD2Atb3Xr2yc96ak7qaKs6D88D5B7nJodJOls83agBt1BXYH5q6nPUcJm pQrCZiiP1RPlZNI6gZyed9aBYC74dxKR6lm4Gw71YVM9p9D4UMXdzrcKoFtt21a6yQDP9 4Bb4egDnlX0ye3LnQ1ZyDorQL0cJdWS7LKeREBcHBGOn0Zi34con63UPjdPHfPtg2wA== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass header.from=oss.nxp.com; spf=pass smtp.mailfrom=oss.nxp.com; dkim=pass header.d=NXP1.onmicrosoft.com header.i=@NXP1.onmicrosoft.com header.a=rsa-sha256 header.s=selector1-NXP1-onmicrosoft-com header.b=xFzlBiCX; arc=pass header.oldest-pass=0 smtp.remote-ip=40.107.130.52 Received: from MRWPR03CU001.outbound.protection.outlook.com (mail-francesouthazon11011052.outbound.protection.outlook.com [40.107.130.52]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (secp384r1) server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AD903606A32C for ; Fri, 4 Dec 2026 07:10:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org AD903606A32C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=oss.nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=NXP1.onmicrosoft.com header.i=@NXP1.onmicrosoft.com header.a=rsa-sha256 header.s=selector1-NXP1-onmicrosoft-com header.b=xFzlBiCX ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ZLurwhD3P0Bwd1PBGQQ+NYChh9mTA1r3Hh1+84ig6F5yJW8MZMvmJdwUkkMyqBWoytdFFFPRAPD7hUVXn1BQkdbKYu2XpAjT8VMkpfNyWlqVME6eGQ2zrLNfHKrZ1QmBJo+Sy4uZ6PWLvU0Dw8k6SAJwmDnbb04igx2Lqtal60YjypcJAYBh2v/imsD4cnlLLhiObjaGCU/Z6148EfkJFKTsyiCZBA0hxaTFRReEVirYl5rkr9XTIymkfaKL7+5nNV4mfmHnhnaP5NBGQopczBzrT7JaomskTRyYyIcYpp6gyIhmioI4L2hmfvZLI0OUqS2xgnp9zhAG8aTT27McwQ== 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=UNq8Pzq3yWGfP2BAAYhd2CJfknyMqTKMUzRPZaiMj90=; b=PHEXOQL0/wua0ADGEPvxVPPPYZeKE33JIM61kc6dl6IjnpgYTIQlKQjjzEbIG5NjBWP8Xb5mfkVnhgwiVmbr+ES27z2px7DeyAZIPsNnLlem+UL50naW1pWUCnX/YW0ogscx5qPKgMhSpGQJhCXd8bNHVYTqTrOl9PSoRHbdSyQ7m7UDtNZ9P6OnXYWbwXIJhVmobw5QomF5kLRc9YsdlJ0BtXF/gOUmF2UusEhLWj/HCEy2Y2l10qIi/L8Z78HXlrqPkG9uhxDUxTg9j94g9OSYCSNX32o4SPrdUfZgwUPZhfAS8XUC4NZ4jFqL/O+mLTbyWU6bXzsm/GrKs8I6+w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oss.nxp.com; dmarc=pass action=none header.from=oss.nxp.com; dkim=pass header.d=oss.nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=NXP1.onmicrosoft.com; s=selector1-NXP1-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=UNq8Pzq3yWGfP2BAAYhd2CJfknyMqTKMUzRPZaiMj90=; b=xFzlBiCXOhPm13WoKjWMhDRfuTuvE0y87D2c9dV6ESe3cstE08+qXStT228y0QJLIIAaMJ6bYgj1o191MpxfwOLD04gNJZ1AvSLpiI0m+0g37bDdltRLoyh1w2WSvcIBbMs+ax2iYOY72TRFHUs8fo0DZ2k/AcIxelVsmRu4s0YW2SQT69DNL+1610vNHE38VpEYbHQ0iYZ18kWcQReBnHkQUmXPEI2baWc9bpe/Am+pzKdITQDSqQe5aPfqkIg2JOGbelsOIW/tTsWcLNM8xJEVIlTnQbIHnfd8r2RzljETRIHbhv6VZmppP6g7kyXfQhtk0P9SHSSClNpe4cpHhA== Authentication-Results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=oss.nxp.com; Received: from VE1PR04MB7216.eurprd04.prod.outlook.com (2603:10a6:800:1b0::22) by DU4PR04MB10551.eurprd04.prod.outlook.com (2603:10a6:10:588::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.688.11; Fri, 4 Dec 2026 07:10:22 +0000 Received: from VE1PR04MB7216.eurprd04.prod.outlook.com ([fe80::a9a5:cf83:dbe8:1f74]) by VE1PR04MB7216.eurprd04.prod.outlook.com ([fe80::a9a5:cf83:dbe8:1f74%6]) with mapi id 15.21.0688.009; Fri, 4 Dec 2026 07:10:22 +0000 From: wei.fang@oss.nxp.com To: xiaoning.wang@nxp.com, claudiu.manoil@nxp.com, vladimir.oltean@nxp.com, andrew@lunn.ch, olteanv@gmail.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, chleroy@kernel.org, richardcochran@gmail.com Cc: wei.fang@nxp.com, imx@lists.linux.dev, netdev@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH net-next 13/14] net: enetc: add a generic helper to add an NTMP entry by key Date: Fri, 4 Dec 2026 15:14:09 +0800 Message-Id: <20261204071410.692071-14-wei.fang@oss.nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261204071410.692071-1-wei.fang@oss.nxp.com> References: <20261204071410.692071-1-wei.fang@oss.nxp.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: SI2P153CA0025.APCP153.PROD.OUTLOOK.COM (2603:1096:4:190::12) To VE1PR04MB7216.eurprd04.prod.outlook.com (2603:10a6:800:1b0::22) X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VE1PR04MB7216:EE_|DU4PR04MB10551:EE_ X-MS-Office365-Filtering-Correlation-Id: 0b873ef6-ee14-49e3-4953-08df51d5a97b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|19092799006|7416014|376014|366016|23010399003|1800799024|11063799006|6133799003|261009223027099003|921020|18002099003|22082099003|10067099003|56012099006|3023799007|261022075727099003|261026121527099003|261021123027099003|261021121427099003|261028144727099003|261102123227099003|261102130727099003|261026140227099003|261022105027099003; X-Microsoft-Antispam-Message-Info: Bz3X80tejL+4glen70ReSd+/S4M2j+UoTvitavuw5Iv/6AhAFPq6DUKN/6o7HEpjTRsBB2rbJsIWmG2r32ReYiNCGMUiFLfQvv1Q2A1/K4XQVvA8/dRn43XfRlkXIKwcVka6XGa9SrZSAS/KSpSya8MnuQz1o+s9bhs/EdnjSFrvWdEo93eTP1rdfQ10yXaOJa2Coz+sVcToVueNhVY/VTjR/AE5G5qHiK0Bp4SGG0H+ksbTkKYD/nJattrwd4iS8IC2rvZwJ1jzd8wWTNVbUf/dTMNvWQt1YQX4s5SZU4I5QtYnmuW6NpdyVXezSdFdvEaitUo38fUy16rRuOuhzIuME8fOWP5xqpiHKqNLlLoPS7TqgEWO2AF5PPUzNmQFYj1ub+OqEvZRvHBWHH79TOvMDL3yfVhUtA2VrAjrYvrsddBa9LGmraME9bOSDiM3sbzZ66S0oGj98T5oZ3vuWQBL/YplUs02QbhyQISgwzHwUPm+tMivr2JGnESmF7lzNBju1OLLEptnQhAN1LLe8WgCCjhqK82xtIIqETGl/U0bIQw+4gPk8hKeo4dh79g4S+h7idSeqX760uM3cLhHjw49qv3yfh47PIGeRlQTS/SsN5Qoz+A8946qyJMsglTauobZ+3xNaFATmsBwVt1EH4wUUiZFV4HVoMDCD6R6vtJ0sPEiSCb37PNCczfAY4eIWT20YzsPcBu3GWFrhazXkA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VE1PR04MB7216.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(19092799006)(7416014)(376014)(366016)(23010399003)(1800799024)(11063799006)(6133799003)(261009223027099003)(921020)(18002099003)(22082099003)(10067099003)(56012099006)(3023799007)(261022075727099003)(261026121527099003)(261021123027099003)(261021121427099003)(261028144727099003)(261102123227099003)(261102130727099003)(261026140227099003)(261022105027099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?6pY1muRGqUN0WK9dsuiPgrFVTgxM1tLJPg1m6hfikvjo0AF1qRlJf8WYagLg?= =?us-ascii?Q?lkVZa+am4uFI8KQCQ1vv3QrO6aghcTW6WGjfzY2WxYdulbtO7J0MeJe1bZNc?= =?us-ascii?Q?OrI5INhn3jlCEfC49e7tTLlp8BkpnNvKL/yeipcUYvoSKGa0nQ1V+SRfyH4v?= =?us-ascii?Q?aFFPElWxjZYxXAeuz9NJv1SZxZl3CwtSGkO9CRfflh4MTg+LudBCxix1KxGR?= =?us-ascii?Q?oAJC36RdxZjvM9gvg5vVKII7b8PVTxOXFzZhQYvnyFjGY1j8+aLo20eSQjyJ?= =?us-ascii?Q?in0lYkNJGd0ngXwY5WpJ50j9T2L2q1vdyQarw3pornaNASZjh/xRcV1uhcNQ?= =?us-ascii?Q?hZLT/Kw6hta7RRxsVpUjjTqb64E0FzmR8eOjyPqENLDaZyPDAmU8jG44yuEJ?= =?us-ascii?Q?8fkmvz49BNmizUhgm0L6j9dTJ5NbsjZRnKmCZsRMSd9yfpNoG4CaoTUBJUh/?= =?us-ascii?Q?+QGAvVIhJmvN7sUZCqJPwh71PNtTWcEhU2PSHpF36ayFciFbYwHeVGYpU3zp?= =?us-ascii?Q?aC+ziUB2ibrokSUjSjnb86Qs8PUpFdeNOhudmxkOxoUEVcq4bDVn9de6n91X?= =?us-ascii?Q?mXfRvvQKD6t9GJ1vbM6IMQpACWjytWDT/WRG6Emhtj/rMz0bqlt7yiqHkZ2h?= =?us-ascii?Q?9jgK+WcV0FO+d2WtYJZSpesNdGRoEUfu/oO8/hS3Hbv8HrzGpemb6dNDJpuU?= =?us-ascii?Q?P4ixIjqjjx5jWUSQRbBoehAqk7HBqoVD0M+xmxInhF8f9lq9Hi+gKVIBzXSV?= =?us-ascii?Q?RqDhUGS/lOyaq343/EE7kQ9nPhmfWcMbAgxOphDsJREkzkZmfnK+qIAdey4O?= =?us-ascii?Q?pMt5YqRWDzxM3StKAm0lYYWuwo1HSwY41XoURLiCVB5ZNXuEb2SGVlIgBF2E?= =?us-ascii?Q?AZoghO9BmCxCT/WQge/ng1Yrx3mmHkAaGTGO4qQhAEACyQz/L4Fnp4bpEAL9?= =?us-ascii?Q?LFIntDbyXuvVwobQo5LiXKovubAoC7BXbOOai3DTzn5LJr/HusImkuCz65Qw?= =?us-ascii?Q?/M2lxPpqn91CVdbFt3Q78l29CpSH2cQ/XH9/odsB/Mvx/nlvUeghbWgKJvLm?= =?us-ascii?Q?YvJf1sgSUIPnWAkQhWLvzuoJrUjO8S3Z0u99lpxnmY6CnFNFaOZBytVnGWwC?= =?us-ascii?Q?z6PtIsnpnj7rXuNiGAyq25O4eCXEnIgzpRH6302is23eLIULH/sMBDXorf2x?= =?us-ascii?Q?xiKx0/5UdDkn7RnwQ+lYnlQ+mnrng7rHGB3KvqzNOAJQl8x00xgMCGCiZmUa?= =?us-ascii?Q?FXOx1Uaa68ziWHW5R/5YSjbtS5lqObHTXGtQmmhndbURl+mYq/lmhbz9s2Do?= =?us-ascii?Q?7gvkcbv4hw+vFirU29CtTt6z9YdAbEgGA07rR47cJOdqQ+Zpx01p660L1FHY?= =?us-ascii?Q?D6HJlXqndsgPNmGoXxUBQCCimjfeZ/pGKD7X7F8TT7m5+FIDZsT6kBT7+Uqd?= =?us-ascii?Q?0EzKylkHW9pP27EKlGCUGvvVTbR/Avi3XeGN/1EAHUxMhog/dFmb16/cA2qA?= =?us-ascii?Q?FPNeXI/4JBftVhEPB2V4MbvUkTxA5SmBv1UMwDa0inIU8ALo2onV5WrV409X?= =?us-ascii?Q?jJOG8+qyaMG0eztkkxH9XNVyvP4UZnXuv+3NaoOFFsYQOrMYM+m8tSuXadIi?= =?us-ascii?Q?qhHWOWG/5kt3GEKkMyiDpA0OZZNoPU+9aQgJDRoS+nwLfmxCbEhP2NS2Ijyj?= =?us-ascii?Q?2bWsgJSpmwD16IhUoU9G9U25ExQ7pOBdsIekaA1C/dio7T5l1uMSaQekQ1uV?= =?us-ascii?Q?c4Z7X7iYOUo90Pr0qM8gfYVpPl1esChhqr8FPIrqNlQKipZMOhmv?= X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0b873ef6-ee14-49e3-4953-08df51d5a97b X-MS-Exchange-CrossTenant-AuthSource: VE1PR04MB7216.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Dec 2026 07:10:22.4674 (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: nuLQYRiCYjyx/TPROVXAJVNKc5ys10uCj13Ag2pRdWBI8z6g6+muSEeSlWENM1Gidzq372O7JDUvsuROlZvp7va5Eo+ebkT79qPfY4jSDCM0//lwk2UiAgZDcKL/w8eA X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU4PR04MB10551 From: Wei Fang The Add operations for the IPFT, FDBT and VLAN filter tables share the same logic: pack the request, issue an "Add then Query" command so the hardware-allotted entry ID can be read back, and unpack the response. Three separate functions open-coded this identical flow. Add a generic ntmp_add_entry_by_key() helper that takes the table ID, the update-actions mask and the access method, and convert ntmp_ipft_add_entry(), ntmp_fdbt_add_entry() and ntmp_vft_add_entry() into thin wrappers around it. With the Add path moved out, ntmp_vft_set_entry() no longer needs to handle both commands. Turn it into a dedicated ntmp_vft_update_entry() that always issues NTMP_CMD_UPDATE, and drop the now-redundant command argument and its validation. Signed-off-by: Wei Fang --- drivers/net/ethernet/freescale/enetc/ntmp.c | 242 ++++++++------------ 1 file changed, 95 insertions(+), 147 deletions(-) diff --git a/drivers/net/ethernet/freescale/enetc/ntmp.c b/drivers/net/ethernet/freescale/enetc/ntmp.c index 3f8a39df78b6f..0622e7e0b5756 100644 --- a/drivers/net/ethernet/freescale/enetc/ntmp.c +++ b/drivers/net/ethernet/freescale/enetc/ntmp.c @@ -910,6 +910,73 @@ static int ntmp_query_entry_by_id(struct ntmp_user *user, int tbl_id, return err; } +/** + * ntmp_add_entry_by_key - add a new entry to a table by its key element + * @user: target ntmp_user struct + * @tbl_id: ID of the target table + * @entry: the logical entry data to be packed into the request buffer, the + * hardware-allocated entry ID is read back into it on success + * @ua: update actions applied to the entry, 0 if none + * @access_method: how the key element is matched, either NTMP_AM_EXACT_KEY + * for tables matched by an exact key or NTMP_AM_TERNARY_KEY for tables + * matched by a masked (ternary) key + * + * A generic helper for tables that add a new entry by its key element. The + * entry ID of such tables is allocated by hardware, so it packs the entry + * data and issues an "Add and Query" command over a CBDR, so that the + * hardware-allocated entry ID can be read back and unpacked into @entry. + * + * Return: 0 on success, otherwise a negative error code + */ +static int ntmp_add_entry_by_key(struct ntmp_user *user, int tbl_id, + void *entry, u16 ua, int access_method) +{ + u8 version = user->tbl_ver[tbl_id]; + const struct ntmp_tbl_ops *ops; + struct netc_swcbd swcbd; + struct netc_cbdr *cbdr; + union netc_cbd cbd; + void *buf; + u32 len; + int err; + + ops = ntmp_table_ops(tbl_id, version); + if (!ops) + return -EOPNOTSUPP; + + swcbd.size = max(ops->req_ua_len, ops->resp_query_len); + err = ntmp_alloc_data_mem(user->dev, &swcbd, &buf); + if (err) + return err; + + /* Request data */ + ntmp_fill_crd(buf, version, NTMP_QA_ENTRY_ID, ua); + ops->pack(entry, buf, access_method); + + len = NTMP_LEN(ops->req_ua_len, ops->resp_query_len); + /* The entry ID is allocated by hardware, so an "Add, followed by a + * Query" operation is required to retrieve the entry ID from the + * hardware. + */ + ntmp_fill_request_hdr(&cbd, swcbd.dma, len, tbl_id, + NTMP_CMD_AQ, access_method); + + ntmp_select_and_lock_cbdr(user, &cbdr); + err = netc_xmit_ntmp_cmd(cbdr, &cbd, &swcbd); + if (err) { + dev_err(user->dev, "Failed to add %s entry, err: %pe\n", + ntmp_table_name(tbl_id), ERR_PTR(err)); + goto unlock_cbdr; + } + + ops->unpack(buf, entry, true); + +unlock_cbdr: + ntmp_unlock_cbdr(cbdr); + + return err; +} + int ntmp_maft_add_entry(struct ntmp_user *user, struct maft_entry_data *entry) { return ntmp_add_entry_by_id(user, NTMP_MAFT_ID, entry->entry_id, @@ -1028,51 +1095,9 @@ EXPORT_SYMBOL_GPL(ntmp_rsst_query_entry); int ntmp_ipft_add_entry(struct ntmp_user *user, struct ipft_entry_data *entry) { - u8 version = user->tbl_ver[NTMP_IPFT_ID]; - const struct ntmp_tbl_ops *ops; - struct netc_swcbd swcbd; - struct netc_cbdr *cbdr; - union netc_cbd cbd; - void *buf; - u32 len; - int err; - - ops = ntmp_get_ipft_ops(version); - if (!ops) - return -EOPNOTSUPP; - - swcbd.size = max(ops->req_ua_len, ops->resp_query_len); - err = ntmp_alloc_data_mem(user->dev, &swcbd, &buf); - if (err) - return err; - - /* Note that NTMP_GEN_UA_STSEU is used to reset the statistics of - * the entry. The STSE_DATA is not present in the request data for - * 'Add' operation. - */ - ntmp_fill_crd(buf, version, NTMP_QA_ENTRY_ID, - NTMP_GEN_UA_CFGEU | NTMP_GEN_UA_STSEU); - ops->pack(entry, buf, NTMP_AM_TERNARY_KEY); - - len = NTMP_LEN(ops->req_ua_len, swcbd.size); - ntmp_fill_request_hdr(&cbd, swcbd.dma, len, NTMP_IPFT_ID, - NTMP_CMD_AQ, NTMP_AM_TERNARY_KEY); - - ntmp_select_and_lock_cbdr(user, &cbdr); - err = netc_xmit_ntmp_cmd(cbdr, &cbd, &swcbd); - if (err) { - dev_err(user->dev, "Failed to add %s entry, err: %pe\n", - ntmp_table_name(NTMP_IPFT_ID), ERR_PTR(err)); - - goto unlock_cbdr; - } - - ops->unpack(buf, entry, true); - -unlock_cbdr: - ntmp_unlock_cbdr(cbdr); - - return err; + return ntmp_add_entry_by_key(user, NTMP_IPFT_ID, (void *)entry, + NTMP_GEN_UA_CFGEU | NTMP_GEN_UA_STSEU, + NTMP_AM_TERNARY_KEY); } EXPORT_SYMBOL_GPL(ntmp_ipft_add_entry); @@ -1104,50 +1129,8 @@ EXPORT_SYMBOL_GPL(ntmp_ipft_delete_entry); int ntmp_fdbt_add_entry(struct ntmp_user *user, struct fdbt_entry_data *entry) { - u8 version = user->tbl_ver[NTMP_FDBT_ID]; - const struct ntmp_tbl_ops *ops; - struct netc_swcbd swcbd; - struct netc_cbdr *cbdr; - union netc_cbd cbd; - void *buf; - u32 len; - int err; - - ops = ntmp_get_fdbt_ops(version); - if (!ops) - return -EOPNOTSUPP; - - swcbd.size = max(ops->req_ua_len, ops->resp_query_len); - err = ntmp_alloc_data_mem(user->dev, &swcbd, &buf); - if (err) - return err; - - /* Request data */ - ntmp_fill_crd(buf, version, NTMP_QA_ENTRY_ID, NTMP_GEN_UA_CFGEU); - ops->pack(entry, buf, NTMP_AM_EXACT_KEY); - - len = NTMP_LEN(ops->req_ua_len, ops->resp_query_len); - /* The entry ID is allotted by hardware, so we need to perform - * a query action after the add action to get the entry ID from - * hardware. - */ - ntmp_fill_request_hdr(&cbd, swcbd.dma, len, NTMP_FDBT_ID, - NTMP_CMD_AQ, NTMP_AM_EXACT_KEY); - - ntmp_select_and_lock_cbdr(user, &cbdr); - err = netc_xmit_ntmp_cmd(cbdr, &cbd, &swcbd); - if (err) { - dev_err(user->dev, "Failed to add %s entry, err: %pe\n", - ntmp_table_name(NTMP_FDBT_ID), ERR_PTR(err)); - goto unlock_cbdr; - } - - ops->unpack(buf, entry, true); - -unlock_cbdr: - ntmp_unlock_cbdr(cbdr); - - return err; + return ntmp_add_entry_by_key(user, NTMP_FDBT_ID, (void *)entry, + NTMP_GEN_UA_CFGEU, NTMP_AM_EXACT_KEY); } EXPORT_SYMBOL_GPL(ntmp_fdbt_add_entry); @@ -1418,17 +1401,31 @@ int ntmp_fdbt_delete_port_dynamic_entries(struct ntmp_user *user, int port) EXPORT_SYMBOL_GPL(ntmp_fdbt_delete_port_dynamic_entries); /** - * ntmp_vft_set_entry - add an entry into the VLAN filter table or update - * the configuration element data of the specified VLAN filter entry + * ntmp_vft_add_entry - add an entry into the VLAN filter table + * @user: target ntmp_user struct + * @entry: the entry data, entry->vid is the VLAN ID and the configuration + * element data provides the values + * Return: 0 on success, otherwise a negative error code + */ +int ntmp_vft_add_entry(struct ntmp_user *user, + struct vft_entry_data *entry) +{ + return ntmp_add_entry_by_key(user, NTMP_VFT_ID, (void *)entry, + NTMP_GEN_UA_CFGEU, NTMP_AM_EXACT_KEY); +} +EXPORT_SYMBOL_GPL(ntmp_vft_add_entry); + +/** + * ntmp_vft_update_entry - update the configuration element data of the + * specified VLAN filter entry * @user: target ntmp_user struct - * @cmd: command type, NTMP_CMD_AQ or NTMP_CMD_UPDATE * @entry: the entry data, entry->vid selects the VLAN filter entry and - * the configuration element data provides the values + * the configuration element data provides the new values * * Return: 0 on success, otherwise a negative error code */ -static int ntmp_vft_set_entry(struct ntmp_user *user, int cmd, - struct vft_entry_data *entry) +int ntmp_vft_update_entry(struct ntmp_user *user, + struct vft_entry_data *entry) { u8 version = user->tbl_ver[NTMP_VFT_ID]; const struct ntmp_tbl_ops *ops; @@ -1455,67 +1452,18 @@ static int ntmp_vft_set_entry(struct ntmp_user *user, int cmd, /* Request header */ len = NTMP_LEN(ops->req_ua_len, ops->resp_query_len); ntmp_fill_request_hdr(&cbd, swcbd.dma, len, NTMP_VFT_ID, - cmd, NTMP_AM_EXACT_KEY); + NTMP_CMD_UPDATE, NTMP_AM_EXACT_KEY); ntmp_select_and_lock_cbdr(user, &cbdr); err = netc_xmit_ntmp_cmd(cbdr, &cbd, &swcbd); - if (err) - goto unlock_cbdr; - - if (cmd == NTMP_CMD_AQ) - ops->unpack(buf, (void *)entry, true); - -unlock_cbdr: - ntmp_unlock_cbdr(cbdr); - - return err; -} - -/** - * ntmp_vft_add_entry - add an entry into the VLAN filter table - * @user: target ntmp_user struct - * @entry: the entry data, entry->vid is the VLAN ID and the configuration - * element data provides the values - * - * Return: 0 on success, otherwise a negative error code - */ -int ntmp_vft_add_entry(struct ntmp_user *user, - struct vft_entry_data *entry) -{ - int err; - - err = ntmp_vft_set_entry(user, NTMP_CMD_AQ, entry); - if (err) - dev_err(user->dev, - "Failed to add %s entry, vid: %u, err: %pe\n", - ntmp_table_name(NTMP_VFT_ID), entry->vid, - ERR_PTR(err)); - - return err; -} -EXPORT_SYMBOL_GPL(ntmp_vft_add_entry); - -/** - * ntmp_vft_update_entry - update the configuration element data of the - * specified VLAN filter entry - * @user: target ntmp_user struct - * @entry: the entry data, entry->vid selects the VLAN filter entry and - * the configuration element data provides the new values - * - * Return: 0 on success, otherwise a negative error code - */ -int ntmp_vft_update_entry(struct ntmp_user *user, - struct vft_entry_data *entry) -{ - int err; - - err = ntmp_vft_set_entry(user, NTMP_CMD_UPDATE, entry); if (err) dev_err(user->dev, "Failed to update %s entry, vid: %u, err: %pe\n", ntmp_table_name(NTMP_VFT_ID), entry->vid, ERR_PTR(err)); + ntmp_unlock_cbdr(cbdr); + return err; } EXPORT_SYMBOL_GPL(ntmp_vft_update_entry); -- 2.34.1