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.162.50 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796368158; b=qrRP1oyGgn1OqSy1St++BVIDK14Rnt8wSD2DVkdrEBNAYGcZOWdtAVAK4Q1WaPfLShf2 53ikqcIcWP1ojEctQgqOYv/BwcR4deN3oprXQOisHTAYnPdVufeNApl32CO0aP7MGMd3T RioydDtHCjXyLM37D+YWBQqPh+8CAc8YrCjz5sJO6mvHE+kdk/T8WRmbR3Y+G22tkSzua qPpz9eH5jpm2w6TwSqI7yzIcR4bbvSZza7rM3BcUxqey9w1lFMN5AqbVsmQNzQNNLS4EJ F3QpmLfKen7wkzDwsJdX0ZqUYF0wOJKFWH4lDIIEdyDgQd0/PzNwt8B+2bR/Oz4GSJA== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796368158; 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=obltR0vqlo5G5315xNeyGdvdN5i1WPmjiEW7KpVXkrQ=; b=uQqMlTcC2plmkMJaVKMhz+Hlu1UKbJ2ZwmIoi+r/IqybKek/Bkh/sLtTYoliK+ur/wml J22+7iXKpdCn2RgIcfDd/y9bft7C1Low7CNnpysUslaZHTPt3jRfG9eiSDTKNHSw46gq9 vpV53HiIkfNKeuFythxC4eQBqGLd0uD+gVXhmiIOWbkmTSrYNycUxigk0UUQdVXpznwHO XRX+6kHkExkjw0yZb9m468WFJkdwC2dvXFsUzDpGdiE5fjSCB57eDWEs6eusyH0YYI8qI GkXC31oNuE70pAIeb/SHoDAslmd9kX8V3XYm0HUDXGa7/YIbccO9MmrlkAEOTGCupdw== 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=vJwZZr8g; arc=pass header.oldest-pass=0 smtp.remote-ip=40.107.162.50 Received: from PA4PR04CU001.outbound.protection.outlook.com (mail-francecentralazon11013050.outbound.protection.outlook.com [40.107.162.50]) (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 60B58606A32D for ; Fri, 4 Dec 2026 07:09:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 60B58606A32D 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=vJwZZr8g ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=PVHfczY/wWVIzcO0n1PTrjaf7m0RZi2BPUsTNE/8VpbcM1sATCvYYjAGav5lc9Or7uIZGpWFat4OLyceVEsKxolRnuPfeH99xDwVNYDqCOGeWEG90mk5z9sPEulC67MX5MYOZ+OgLKWkCniwoDzfntHRWZZBmGIio95eolKMWpKigSpmNU2BA0MFYX6aCjGy1KVnlMztvwGnMDhEwJk+2jT1n3+ISkXjNfM7j5PRCssWbOGIdQ4eCFYHlSOj8DG06bpPLvKM1rmJaKRozbauBh/obGiYbJEzB+ngvmyETtKMoxLvZ3LjxhVNfP2K12/bafka4NEeYE28llbeSaiQRw== 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=obltR0vqlo5G5315xNeyGdvdN5i1WPmjiEW7KpVXkrQ=; b=QDXNNELi8pJNPzX1VHJIUZlI7PuSThgjIMZa2ruRbNcKDMvGM3rT67BRwYffAIg520lrv9lUWTPJAJ20ei9DRvyfHyXHhMjNYXlytv/GdlmRRMaURz8VJDTMt9eqjGOPEyXsvDY4Cji0iwImKEqa+PhqqDzOT2uU18vokIlPtwgTps7xiMlknEBoDsO9b915UZHry2tP46xZQ06TuHToqiVLFDPzXO6TYlCEj6P0OKHmK+qAgD1qGtykKQ4Uwtt/Bq3ihEycPLXDJov6KMAXdbFy2oOwsczra8/Xvs+Gh+YevCeMFFv2AxQquqErwSZBeZasSxRJjDPCo7PkKOH8lA== 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=obltR0vqlo5G5315xNeyGdvdN5i1WPmjiEW7KpVXkrQ=; b=vJwZZr8gCxbxgQZTas/oCQr22j/8fd9KFY0A4Aj8yOQzWid7c6e1dQOwXFw/ZQBfzpcP+XeXo/ec/IS2Lz79i/Ok4mXhUriRz1C9AhKWYwmt6dRe2ajNo3q6ljZs7zNp2/l8sbWrcv1cwtzAfdkfmQ2n7jsoTj8MwMiObCuKrJ1j2LWtPP1ttN35BShVBGyllHFpkS0z7tUbHpIwabpoHOZSVAEd1KpckXwjlzzH/l9fPWOyIpQNKVJhG5wNCTJCpX6Y31uBwJHtANeMDTgWa1xac5HmsFR2Q8VlVJj9XJC2cdx3ORj4s4UQW5qZ+pTW8TY8eHfbEuO1YFnV83aTXQ== 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 AMBPR04MB11763.eurprd04.prod.outlook.com (2603:10a6:20b:6f2::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.688.13; Fri, 4 Dec 2026 07:09:14 +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:09:14 +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 02/14] net: enetc: decouple MAFT logical config from hardware wire format Date: Fri, 4 Dec 2026 15:13:58 +0800 Message-Id: <20261204071410.692071-3-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: SI3PR01CA0005.apcprd01.prod.exchangelabs.com (2603:1096:4:296::13) 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_|AMBPR04MB11763:EE_ X-MS-Office365-Filtering-Correlation-Id: d8e9c0cc-c5bb-400e-76e8-08df51d58127 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|1800799024|376014|7416014|23010399003|19092799006|22082099003|18002099003|921020|10067099003|56012099006|261026135527099003|261026130827099003|261022115727099003|261026140227099003|261022105027099003|261022075727099003|261028144727099003|261022113327099003|261026121527099003|261021130227099003|261021133027099003|261021123027099003|261021121427099003|261021135927099003|261102123227099003|261102130727099003|261009223027099003|11063799006|6133799003; X-Microsoft-Antispam-Message-Info: ynC4TDDhc7vBCAltmWVPNA5fs2Trk4edw/5jgmCAqw6WCYBuDUtB0iXTVExMolezuedcOmjLts0l4SnkliQkOt0r4MGwvEc78ayYVWlzRCTz/BsVf4a5KGxWIiYBnxxjXQwCg59HOg1vV0rM9QG3qSacbfPFMNFfjfxFR/P/mdjQC0u3ealJzaAFHrF9fagXrDJRg01ax3OFf4ABkiCV1qWLqHYUC8lavQT1IHo74ioKBJU7zhHKjTdLAqIN6vi9WSzW5DrBPkYJwYziyosGRiQ0Jf3dVsS0NObMr2xJhMBiV3utBTOmdr+fjOm3RjOdOP4+UUGrm+AVn8YOHJ0YqAeNP5aMTl6yKMKqAXXmSAnqzNo5mPUkiq+/4bR3GVXiac5swrkK75Wd89GRYi0HBXryUj2Jyc09EqRZkT+cthePQOjf4fG+ud1e9cOcETMJnTGmcss7kQ0pgTYGUB2WnoPWcro5T4GEt9nnP6t6iqlPdWUPgg+gA0A/mYcjZ2EcMCN/56dnVUAxtTUl3LbZsBsE/uTNkS15E4YuF+JXrmXvl/RTmR4iEuzbUOp9xXE46SAXrx4JsFb/CR1nnIlLEF5MGOh4cG8afJ0UfmAkxgK2Xws5aqpt0PC2nECqrbY5J4phy7+PFAAzX7DNxQibrpBko5lsQ1kr7mYFdZOSVWxiF4Tfy4N6z5wTPmJbgx2DJUSf6F0D7hRfNICG3Prkqg== 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)(366016)(1800799024)(376014)(7416014)(23010399003)(19092799006)(22082099003)(18002099003)(921020)(10067099003)(56012099006)(261026135527099003)(261026130827099003)(261022115727099003)(261026140227099003)(261022105027099003)(261022075727099003)(261028144727099003)(261022113327099003)(261026121527099003)(261021130227099003)(261021133027099003)(261021123027099003)(261021121427099003)(261021135927099003)(261102123227099003)(261102130727099003)(261009223027099003)(11063799006)(6133799003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?UQp8ESK4Fr4ZiIDDWEa8CO8cKb5YnrNduLZAXjUqf4y6So9xRVqzciI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atorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: d8e9c0cc-c5bb-400e-76e8-08df51d58127 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:09:14.8104 (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: giXQ+ctHti+W3tMC794SUXQyG2HAwRilCVWy1O7eDn9jVBBrSNvHWUmyOm0FDQBkZAtv5NiXPZ5rjFLhCzNf6GyTXZUJarAYWDoV1LmLjVYYHxeZedQRbsMkppF9sEF/ X-MS-Exchange-Transport-CrossTenantHeadersStamped: AMBPR04MB11763 From: Wei Fang Current SoCs only implement MAFT version 0, but future versions may extend the table with a different buffer layout and size. Today struct maft_entry_data embeds the version 0 hardware KEYE/CFGE structures directly, so callers must know the wire format and open-code endianness conversions. This interface is hard to extend: once a new version changes the buffer layout or size, updating the callers becomes cumbersome. Turn struct maft_entry_data into a version-agnostic config using native CPU types, and move the wire structures into ntmp_private.h to keep them internal to the NTMP layer. Add a generic struct ntmp_tbl_ops holding the buffer sizes and pack()/unpack() callbacks, and select the MAFT version instance via ntmp_get_maft_ops(). ntmp_maft_add_entry() and ntmp_maft_query_entry() now marshal through the ops, so callers work with the logical config and no longer touch the hardware format. A future version can then be added within the NTMP layer by providing its wire structure, pack/unpack helpers and ops instance. Callers may still need small adjustments, but they no longer deal with the wire format or endianness. It's worth noting that some inline functions were removed from ntmp.h because these functions are only used in the nxp-enetc4 driver, which selects NXP_NTMP and FSL_ENETC_CORE, so ultimately NXP_NETC_LIB will also be selected. Therefore, these inline functions have no purpose. Signed-off-by: Wei Fang --- .../ethernet/freescale/enetc/enetc4_debugfs.c | 10 +- .../net/ethernet/freescale/enetc/enetc4_pf.c | 17 ++-- drivers/net/ethernet/freescale/enetc/ntmp.c | 92 +++++++++++++------ .../ethernet/freescale/enetc/ntmp_private.h | 42 +++++++++ include/linux/fsl/ntmp.h | 44 +++------ 5 files changed, 133 insertions(+), 72 deletions(-) diff --git a/drivers/net/ethernet/freescale/enetc/enetc4_debugfs.c b/drivers/net/ethernet/freescale/enetc/enetc4_debugfs.c index c73722e2285f5..dd8689ad1696d 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc4_debugfs.c +++ b/drivers/net/ethernet/freescale/enetc/enetc4_debugfs.c @@ -55,7 +55,7 @@ static int enetc_mac_filter_show(struct seq_file *s, void *data) struct enetc_pf *pf = enetc_si_priv(s->private); struct enetc_hw *hw = &pf->si->hw; int num_si = pf->total_vfs + 1; - struct maft_entry_data maft; + struct maft_entry_data entry; struct ntmp_user *user; u32 val, entry_id; int err = 0; @@ -86,14 +86,14 @@ static int enetc_mac_filter_show(struct seq_file *s, void *data) seq_puts(s, "MAC address filter table\n"); for_each_set_bit(entry_id, user->maft_eid_bitmap, user->maft_num_entries) { - memset(&maft, 0, sizeof(maft)); - err = ntmp_maft_query_entry(user, entry_id, &maft); + memset(&entry, 0, sizeof(entry)); + entry.entry_id = entry_id; + err = ntmp_maft_query_entry(user, &entry); if (err) goto unlock_rtnl; seq_printf(s, "Entry %d, MAC: %pM, SI bitmap: 0x%04x\n", - entry_id, maft.keye.mac_addr, - le16_to_cpu(maft.cfge.si_bitmap)); + entry_id, entry.mac_addr, entry.si_bitmap); } unlock_rtnl: diff --git a/drivers/net/ethernet/freescale/enetc/enetc4_pf.c b/drivers/net/ethernet/freescale/enetc/enetc4_pf.c index 3074b8aac556f..756ead4719ae3 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc4_pf.c +++ b/drivers/net/ethernet/freescale/enetc/enetc4_pf.c @@ -96,11 +96,9 @@ static int enetc4_pf_add_maft_entries(struct enetc_pf *pf, { struct ntmp_user *user = &pf->si->ntmp_user; int mac_cnt = netdev_hw_addr_list_count(uc); - struct maft_entry_data maft = {}; + struct maft_entry_data entry = {}; struct netdev_hw_addr *ha; u32 available_entries; - u16 si_bit = BIT(0); - u32 entry_id; int err; available_entries = user->maft_num_entries - @@ -110,14 +108,15 @@ static int enetc4_pf_add_maft_entries(struct enetc_pf *pf, if (mac_cnt > available_entries) return -ENOSPC; - maft.cfge.si_bitmap = cpu_to_le16(si_bit); + entry.si_bitmap = BIT(0); netdev_hw_addr_list_for_each(ha, uc) { - entry_id = ntmp_lookup_free_eid(user->maft_eid_bitmap, - user->maft_num_entries); - ether_addr_copy(maft.keye.mac_addr, ha->addr); - err = ntmp_maft_add_entry(user, entry_id, &maft); + entry.entry_id = ntmp_lookup_free_eid(user->maft_eid_bitmap, + user->maft_num_entries); + ether_addr_copy(entry.mac_addr, ha->addr); + err = ntmp_maft_add_entry(user, &entry); if (unlikely(err)) { - ntmp_clear_eid_bitmap(user->maft_eid_bitmap, entry_id); + ntmp_clear_eid_bitmap(user->maft_eid_bitmap, + entry.entry_id); goto clear_maft_entries; } } diff --git a/drivers/net/ethernet/freescale/enetc/ntmp.c b/drivers/net/ethernet/freescale/enetc/ntmp.c index 1fb7aa7a6e62e..21174bf2320a6 100644 --- a/drivers/net/ethernet/freescale/enetc/ntmp.c +++ b/drivers/net/ethernet/freescale/enetc/ntmp.c @@ -312,6 +312,41 @@ static const char *ntmp_table_name(int tbl_id) } } +static void ntmp_maft_pack_v0(const void *entry, void *buf, int access_method) +{ + const struct maft_entry_data *e = entry; + struct maft_req_add *req = buf; + + memcpy(req->keye.mac_addr, e->mac_addr, ETH_ALEN); + req->cfge.si_bitmap = cpu_to_le16(e->si_bitmap); +} + +static void ntmp_maft_unpack_v0(const void *buf, void *entry, bool only_eid) +{ + const struct maft_resp_query *resp = buf; + struct maft_entry_data *e = entry; + + memcpy(e->mac_addr, resp->keye.mac_addr, ETH_ALEN); + e->si_bitmap = le16_to_cpu(resp->cfge.si_bitmap); +} + +static const struct ntmp_tbl_ops maft_ops_v0 = { + .req_ua_len = sizeof(struct maft_req_add), + .resp_query_len = sizeof(struct maft_resp_query), + .pack = ntmp_maft_pack_v0, + .unpack = ntmp_maft_unpack_v0, +}; + +static const struct ntmp_tbl_ops *ntmp_get_maft_ops(u8 version) +{ + switch (version) { + case NTMP_TBL_V(0): + return &maft_ops_v0; + default: + return NULL; + } +} + static int ntmp_delete_entry_by_id(struct ntmp_user *user, int tbl_id, u32 entry_id, u32 req_len, u32 resp_len) { @@ -386,26 +421,28 @@ static int ntmp_query_entry_by_id(struct netc_cbdr *cbdr, int tbl_id, return 0; } -int ntmp_maft_add_entry(struct ntmp_user *user, u32 entry_id, - struct maft_entry_data *maft) +int ntmp_maft_add_entry(struct ntmp_user *user, struct maft_entry_data *entry) { - struct netc_swcbd swcbd = { - .size = sizeof(struct maft_req_add), - }; - struct maft_req_add *req; + u8 version = user->tbl_ver[NTMP_MAFT_ID]; + const struct ntmp_tbl_ops *ops; + struct netc_swcbd swcbd; struct netc_cbdr *cbdr; union netc_cbd cbd; + void *buf; int err; - err = ntmp_alloc_data_mem(user->dev, &swcbd, (void **)&req); + ops = ntmp_get_maft_ops(version); + if (!ops) + return -EOPNOTSUPP; + + swcbd.size = ops->req_ua_len; + err = ntmp_alloc_data_mem(user->dev, &swcbd, &buf); if (err) return err; /* Set mac address filter table request data buffer */ - ntmp_fill_crd_eid(&req->rbe, user->tbl_ver[NTMP_MAFT_ID], 0, 0, - entry_id); - req->keye = maft->keye; - req->cfge = maft->cfge; + ntmp_fill_crd_eid(buf, version, 0, 0, entry->entry_id); + ops->pack(entry, buf, 0); ntmp_fill_request_hdr(&cbd, swcbd.dma, NTMP_LEN(swcbd.size, 0), NTMP_MAFT_ID, NTMP_CMD_ADD, NTMP_AM_ENTRY_ID); @@ -413,39 +450,42 @@ int ntmp_maft_add_entry(struct ntmp_user *user, u32 entry_id, ntmp_select_and_lock_cbdr(user, &cbdr); err = netc_xmit_ntmp_cmd(cbdr, &cbd, &swcbd); if (err) - dev_err(user->dev, "Failed to add MAFT entry 0x%x, err: %pe\n", - entry_id, ERR_PTR(err)); + dev_err(user->dev, "Failed to add %s entry 0x%x, err: %pe\n", + ntmp_table_name(NTMP_MAFT_ID), entry->entry_id, + ERR_PTR(err)); ntmp_unlock_cbdr(cbdr); return err; } EXPORT_SYMBOL_GPL(ntmp_maft_add_entry); -int ntmp_maft_query_entry(struct ntmp_user *user, u32 entry_id, - struct maft_entry_data *maft) +int ntmp_maft_query_entry(struct ntmp_user *user, + struct maft_entry_data *entry) { - struct netc_swcbd swcbd = { - .size = sizeof(struct maft_resp_query), - }; - struct maft_resp_query *resp; - struct ntmp_req_by_eid *req; + u8 version = user->tbl_ver[NTMP_MAFT_ID]; + const struct ntmp_tbl_ops *ops; + struct netc_swcbd swcbd; struct netc_cbdr *cbdr; + void *buf; int err; - err = ntmp_alloc_data_mem(user->dev, &swcbd, (void **)&req); + ops = ntmp_get_maft_ops(version); + if (!ops) + return -EOPNOTSUPP; + + swcbd.size = ops->resp_query_len; + err = ntmp_alloc_data_mem(user->dev, &swcbd, &buf); if (err) return err; - ntmp_fill_crd_eid(req, user->tbl_ver[NTMP_MAFT_ID], 0, 0, entry_id); + ntmp_fill_crd_eid(buf, version, 0, 0, entry->entry_id); ntmp_select_and_lock_cbdr(user, &cbdr); - err = ntmp_query_entry_by_id(cbdr, NTMP_MAFT_ID, req, &swcbd, true); + err = ntmp_query_entry_by_id(cbdr, NTMP_MAFT_ID, buf, &swcbd, true); if (err) goto unlock_cbdr; - resp = (struct maft_resp_query *)req; - maft->keye = resp->keye; - maft->cfge = resp->cfge; + ops->unpack(buf, entry, false); unlock_cbdr: ntmp_unlock_cbdr(cbdr); diff --git a/drivers/net/ethernet/freescale/enetc/ntmp_private.h b/drivers/net/ethernet/freescale/enetc/ntmp_private.h index 531ea7ddd1452..4d372dcc6ca31 100644 --- a/drivers/net/ethernet/freescale/enetc/ntmp_private.h +++ b/drivers/net/ethernet/freescale/enetc/ntmp_private.h @@ -79,6 +79,48 @@ struct ntmp_req_by_eid { __le32 entry_id; }; +/** + * struct ntmp_tbl_ops - Generic per-table buffer pack/unpack operations + * @req_ua_len: The request data buffer length of add or update operation + * @resp_query_len: The response data buffer length of query operation + * @pack: Pack a logical *_entry_data into the hardware request data buffer. + * Used by the add or update operation. access_method selects how the + * entry is accessed. Besides entry_id, some tables also support other + * access methods such as Exact key or Ternary key, and the format of + * the ACCESS_KEY field in the request data differs per method. It has + * no effect for tables that only support entry_id access. + * @unpack: Unpack the hardware response data buffer into a logical + * *_entry_data. Used by the query operation. Note that some tables have + * entry IDs assigned by the hardware, the "Add followed by a Query" + * command is usually used to get the hardware-generated entry ID. So + * only_eid means only unpacking the entry_id responded by the hardware. + * It has no effect for tables whose entry IDs are assigned by software. + * + * This is a generic structure that most NTMP tables can reuse. The buffer + * layout of a table may differ between hardware versions, so each table + * provides one instance of these operations per supported version. @pack + * and @unpack take void pointers because the generic NTMP helpers are + * table-agnostic; type safety is enforced by each table's own wrappers, + * which cast to the concrete *_entry_data and *_req_add / *_req_ua / + * *_resp_query types. + */ +struct ntmp_tbl_ops { + u32 req_ua_len; + u32 resp_query_len; + void (*pack)(const void *entry, void *buf, int access_method); + void (*unpack)(const void *buf, void *entry, bool only_eid); +}; + +struct maft_keye_data { + u8 mac_addr[ETH_ALEN]; + __le16 resv; +}; + +struct maft_cfge_data { + __le16 si_bitmap; + __le16 resv; +}; + /* MAC Address Filter Table Request Data Buffer Format of Add action */ struct maft_req_add { struct ntmp_req_by_eid rbe; diff --git a/include/linux/fsl/ntmp.h b/include/linux/fsl/ntmp.h index d21218ad33395..558577c052e77 100644 --- a/include/linux/fsl/ntmp.h +++ b/include/linux/fsl/ntmp.h @@ -10,15 +10,8 @@ #define NTMP_NULL_ENTRY_ID 0xffffffffU #define IPFT_MAX_PLD_LEN 24 -struct maft_keye_data { - u8 mac_addr[ETH_ALEN]; - __le16 resv; -}; - -struct maft_cfge_data { - __le16 si_bitmap; - __le16 resv; -}; +/* NTMP table version */ +#define NTMP_TBL_V(x) (x) struct netc_cbdr_regs { void __iomem *pir; @@ -85,8 +78,13 @@ struct ntmp_user { }; struct maft_entry_data { - struct maft_keye_data keye; - struct maft_cfge_data cfge; + u32 entry_id; + + /* KEYE_DATA */ + u8 mac_addr[ETH_ALEN]; + + /* CFGE_DATA */ + u16 si_bitmap; }; struct ipft_pld_byte { @@ -290,10 +288,9 @@ u32 ntmp_lookup_free_eid(unsigned long *bitmap, u32 size); void ntmp_clear_eid_bitmap(unsigned long *bitmap, u32 entry_id); /* NTMP APIs */ -int ntmp_maft_add_entry(struct ntmp_user *user, u32 entry_id, - struct maft_entry_data *maft); -int ntmp_maft_query_entry(struct ntmp_user *user, u32 entry_id, - struct maft_entry_data *maft); +int ntmp_maft_add_entry(struct ntmp_user *user, struct maft_entry_data *entry); +int ntmp_maft_query_entry(struct ntmp_user *user, + struct maft_entry_data *entry); int ntmp_maft_delete_entry(struct ntmp_user *user, u32 entry_id); int ntmp_rsst_update_entry(struct ntmp_user *user, const u32 *table, int count); @@ -338,23 +335,6 @@ static inline void ntmp_free_cbdr(struct netc_cbdr *cbdr) { } -static inline int ntmp_maft_add_entry(struct ntmp_user *user, u32 entry_id, - struct maft_entry_data *maft) -{ - return 0; -} - -static inline int ntmp_maft_query_entry(struct ntmp_user *user, u32 entry_id, - struct maft_entry_data *maft) -{ - return 0; -} - -static inline int ntmp_maft_delete_entry(struct ntmp_user *user, u32 entry_id) -{ - return 0; -} - static inline int ntmp_rsst_update_entry(struct ntmp_user *user, const u32 *table, int count) { -- 2.34.1