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=52.101.83.47 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796368164; b=ODeWGf047TnEnEYS1YtFmUmgC4sIyA01ANk3dvTsh5k1MBESOrR8e2oU85HLFrMOyTqv mjB+g5cRa1ODu0UWqs+lJq2Fxgp5GTtHtn6QbmA+uUhnlbpny0hBdwjoLg9AGvjRBL82/ KpzOqoC9izTTeld9blyjzLW5eq8JWzohb45IW0fVFKxKELAR9tVALWHTGF04j8wK9GjNT vOvcWe178G/sFArRogfHMNa0xVL+1moucyYTIuIErt2CjHPigK2SeGkYZ9s3e16M5rred 4LZr3sQz5PG6OLkYkTYReaUw5g4zmG9PIobEB+KJWD70W0MPKFh9PAwb6yu+ZqQkxBQ== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796368164; 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=Lyb2TTg7HOQ+jnPq1TSX3IgUmhI8SW6EzfXQI3V11Ec=; b=N1r5tyR725kpvEjHXVmwL9UCHZaJuLrMAZzgqbF/cRdgmsVKY7SnqQZLV8/bfV8g8y8V bsKFF2/fz6H5f7xBa4Y7SvjLvJIiV6rAvsNSWFphik8Xf40feSUqLHbKUZ5YUmuSkttfs Ma4H085exxH1WoRDptSicmIOzxb1BPD8PxKMjXjXU7fjgibRiXiGUGLTCheZ7x5wMr10D dUXWEw7g9uXdAaVvVM16q8ZFcg067BZk0T0NuRDUMHU6NhYIauG16AO4mKUswxRpmAjjI PViGw1ubtBcB7LJtHY52SShFl1XDt70WQOHLg5+WMARxW+u/84lLZOyWm/WjWJSNpgw== 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=SCM85K6W; arc=pass header.oldest-pass=0 smtp.remote-ip=52.101.83.47 Received: from GVXPR05CU001.outbound.protection.outlook.com (mail-swedencentralazon11013047.outbound.protection.outlook.com [52.101.83.47]) (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 D0ED9606A32C for ; Fri, 4 Dec 2026 07:09:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D0ED9606A32C 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=SCM85K6W ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=HEGAeajIL8M2BG3kUW5rGmZCn7eaeQXaCgQlOa/1RK008Wir0Z6XEX9tBpUQ4Uv5WNij6bnydFwemRNQ1GqyviVjVIqHb+qie7Vh9AfdI+Jgi7yZPwGlltFEKAiqLDwYDWvJ0LE50xEQsicoMnuU8qDrpu5h0/tKae9YQGnb0Z7+Bkr4k/06hZidh9r2b+4dPSeg/N0+u5YZwwdY4qRK8+22wOBxjpKiHXT7H9z8goL8asYL5GIYsDSMbCc+tJ/+q4dQTU/TUG3c5yyXvJ4GKnHOL6/tGiaFRWrsT0VTU/gvCpVe2PD98F5ECgaoqQVdwXtix5FRQMm5KjN7n2+jgg== 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=Lyb2TTg7HOQ+jnPq1TSX3IgUmhI8SW6EzfXQI3V11Ec=; b=sUTMuQAVFG/Sdx0DMBlbVm47YMj1jb2cGhhZ1D4IJDpmHgY24N+t69SrSXDc/ut1BN3QsHYh6w36FLnqdafpB1pIwcNF/n288QouYW8WjHWY5sXBnkqeENndAaaclxbM+qv+EP/XgRY7ugmO33Nwdvnz3PFCcrZGEZ5c+lxE5bd6Bjagt0qNFUWGVl1oCn8qjX3DAl/2qL7RiPGhPM/Kpy6QoZhJ0+QcU1VyUfGvIljAQmzrZR8qrtY8H6LHM8j2WoKHM9PC7JWXflhbLyFRx4rkoO1qeBHKg6jfqjas1/84XEzyxEeHo+/DyHsXGA9UvxKG3phLFSvP2+dv5cLh1A== 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=Lyb2TTg7HOQ+jnPq1TSX3IgUmhI8SW6EzfXQI3V11Ec=; b=SCM85K6WxBiDWf7HNou7xbz0DU78MzkiaqoKav98zvy5f5waLA8/WXAqif5i5CZ5VLOyjpYlBvIZqqsItRxDb0B0EEw8F6ptiyKKfz8+qsiSJXG0YCVUmvZFuzY4p7JeJD/XbUpdR2WWRD2bKpu7W8nX4VEr66JK/28sZe48SgeN+cT92xuTH9nbjT68ydQDAXlNOOEdmCqXRg1G0uP0zdylGQoj6VSpohrXJW2PqADKq2jrkflQi0qBL8n5MFHwgMMJWZ1bCghsUtLlfJ081cd7Ydr6rGNnMDtEPVsLyU2jPB1H6NdVJheMmXkzl+wDR2U8U6RtvDXKK53NETT4iA== 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:21 +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:21 +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 03/14] net: enetc: decouple IPFT logical config from hardware wire format Date: Fri, 4 Dec 2026 15:13:59 +0800 Message-Id: <20261204071410.692071-4-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: SGAP274CA0022.SGPP274.PROD.OUTLOOK.COM (2603:1096:4:b6::34) 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: 865cd655-fbee-4df1-17e9-08df51d584f1 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|3023799007; X-Microsoft-Antispam-Message-Info: lHxAAamPmnbR4NC1BUeIhK+seMVHh3GSzrPgRF2BnrIbu0WUUDiqmG2nExW6NFT/YZHcNqQNH0tlqmr0n0MjVXAbPODuqJ/9Ch4jQrKu6lm8wy6/d6yb0tJqh3+/BGWzxdegG8vvHVRpoOhtow4MVfPx4j3QapxCiu7pxv1GacHMVpIXCtJ+i8etQ6U1tvTxqvOfMpg5OGPnbaSJQ4N3gyyqRGckMw5Qnq72gamSgDWzWcJ49lWSir/IBIe30cCRDxAn1p1YFMX0anQCYyZxgn+NQr0SN+RgJZCoQ7o2b1ndHp7PNveRCAScQ/jB9IyHNDik7PYNMKENrUDEx8PrzEI7kfUC7A9ZU/bXN0hkeXGj8br/d1T9o0hE77H5ERZkdU+HCkBbondSX2XU3Akok8/w6/3uQxD9bV2feN3iqS27eeNAM0+8d5i79MYD470YjhfN/oSGIr6C5reOoeIN6fPqi2i10MwO+J0BpKIS9Gelr4+J77i8mmSV4qVcHVi2KU3GOdL+n5LIQ+96S8GazS38O8mesvE+k8kp2Z6rTg8VDMx6/8bDQk0NARhmLgyyaD8dmBQYMhy7nutu4PQSkF6vWSVIFCnMJ5CitvauqJkVUG3oZpgP9OHc/MU3GLg3OdGKAEzbF7s0VJKGmoeI0dYnkfJpChRaUoVZLmiYYnTHyBQKpQzMwvbs8os+fHHhzRKQTmYlH6OLFhbCQ8j90w== 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)(3023799007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?Ln+CzXy9KSPLKUOG6HCW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G0+Ul0/q6gtM?= X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 865cd655-fbee-4df1-17e9-08df51d584f1 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:21.1584 (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: SwO5nX19a+7CARygZxSenKos7VPWA7D9zVYdpJNYg8Blwb7KZCcJlC5JYNYIUxqxTdslM3J8q9ukZmUzmSiCGLKHkI40DLdrvmKjH79rLj7ZhjudrCyFrKxiCOjIxY/W X-MS-Exchange-Transport-CrossTenantHeadersStamped: AMBPR04MB11763 From: Wei Fang Current SoCs only implement IPFT version 0, but future versions may extend the table with a different buffer layout and size. Today struct ipft_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 ipft_entry_data into a version-agnostic logical config, and move the wire structures into ntmp_private.h to keep them internal to the NTMP layer. The packet header fields (VLAN TCI, EtherType, IP addresses and L4 ports) use network byte order to match the kernel structures the caller copies them from; the remaining control fields use native CPU types. Add a MAFT-style struct ntmp_tbl_ops instance holding the buffer sizes and pack()/unpack() callbacks, and select it via ntmp_get_ipft_ops(). ntmp_ipft_add_entry() now marshals through the ops, so the caller works with the logical config and no longer touches the wire format. A future version can then be added within the NTMP layer by providing its wire structure, pack/unpack helpers and ops instance. Signed-off-by: Wei Fang --- drivers/net/dsa/netc/netc_main.c | 18 +-- drivers/net/dsa/netc/netc_ptp.c | 28 ++-- drivers/net/ethernet/freescale/enetc/ntmp.c | 148 ++++++++++++++++-- .../ethernet/freescale/enetc/ntmp_private.h | 42 +++++ include/linux/fsl/ntmp.h | 36 ++--- 5 files changed, 210 insertions(+), 62 deletions(-) diff --git a/drivers/net/dsa/netc/netc_main.c b/drivers/net/dsa/netc/netc_main.c index b071c0c1e46a5..9529eb66571c2 100644 --- a/drivers/net/dsa/netc/netc_main.c +++ b/drivers/net/dsa/netc/netc_main.c @@ -1883,10 +1883,7 @@ static int netc_port_add_host_flood_rule(struct netc_port *np, const u8 dmac_mask[ETH_ALEN] = {0x1, 0, 0, 0, 0, 0}; struct netc_switch *priv = np->switch_priv; struct ipft_entry_data *host_flood; - struct ipft_keye_data *keye; - struct ipft_cfge_data *cfge; - u16 src_port; - u32 cfg; + struct ipft_entry_keye *keye; int err; if (!uc && !mc) @@ -1897,11 +1894,10 @@ static int netc_port_add_host_flood_rule(struct netc_port *np, return -ENOMEM; keye = &host_flood->keye; - cfge = &host_flood->cfge; - - src_port = FIELD_PREP(IPFT_SRC_PORT, np->dp->index); - src_port |= IPFT_SRC_PORT_MASK; - keye->src_port = cpu_to_le16(src_port); + keye->src_port = FIELD_PREP(IPFT_SRC_PORT, np->dp->index) | + IPFT_SRC_PORT_MASK; + host_flood->cfg = FIELD_PREP(IPFT_FLTFA, IPFT_FLTFA_REDIRECT) | + FIELD_PREP(IPFT_HR, NETC_HR_HOST_FLOOD); /* If either only unicast or only multicast need to be flooded * to the host, we always set the mask that tests the first MAC @@ -1918,10 +1914,6 @@ static int netc_port_add_host_flood_rule(struct netc_port *np, ether_addr_copy(keye->dmac_mask, dmac_mask); } - cfg = FIELD_PREP(IPFT_FLTFA, IPFT_FLTFA_REDIRECT); - cfg |= FIELD_PREP(IPFT_HR, NETC_HR_HOST_FLOOD); - cfge->cfg = cpu_to_le32(cfg); - err = ntmp_ipft_add_entry(&priv->ntmp, host_flood); if (err) goto free_host_flood; diff --git a/drivers/net/dsa/netc/netc_ptp.c b/drivers/net/dsa/netc/netc_ptp.c index 46aa3b7ba2d2e..b27674486c8d3 100644 --- a/drivers/net/dsa/netc/netc_ptp.c +++ b/drivers/net/dsa/netc/netc_ptp.c @@ -454,15 +454,15 @@ static int netc_port_del_ptp_filter(struct netc_port *np) return ret; } -static int netc_build_ptp_ipft_keye(struct ipft_keye_data *keye, int port, +static int netc_build_ptp_ipft_keye(struct ipft_entry_data *entry, int port, enum netc_ptp_type type) { - u16 src_port, frm_attr_flags; + struct ipft_entry_keye *keye = &entry->keye; + u16 frm_attr_flags; - keye->precedence = cpu_to_le16(NETC_IPFT_PTP_PRECEDENCE); - src_port = FIELD_PREP(IPFT_SRC_PORT, port); - src_port |= IPFT_SRC_PORT_MASK; - keye->src_port = cpu_to_le16(src_port); + keye->precedence = NETC_IPFT_PTP_PRECEDENCE; + keye->src_port = FIELD_PREP(IPFT_SRC_PORT, port) | + IPFT_SRC_PORT_MASK; switch (type) { case NETC_PTP_L2: @@ -479,11 +479,11 @@ static int netc_build_ptp_ipft_keye(struct ipft_keye_data *keye, int port, type == NETC_PTP_L4_IPV6_GENERAL) frm_attr_flags |= IPFT_FAF_IP_VER6; - keye->frm_attr_flags = cpu_to_le16(frm_attr_flags); + keye->frm_attr_flags = frm_attr_flags; /* Update frm_attr_flags to reuse it as the mask */ frm_attr_flags |= IPFT_FAF_IP_VER6 | IPFT_FAF_L4_CODE; - keye->frm_attr_flags_mask = cpu_to_le16(frm_attr_flags); + keye->frm_attr_flags_mask = frm_attr_flags; keye->ip_protocol = IPPROTO_UDP; keye->ip_protocol_mask = 0xff; @@ -507,23 +507,19 @@ static int netc_port_add_ipft_ptp_entry(struct netc_port *np, { struct netc_switch *priv = np->switch_priv; struct ipft_entry_data *entry; - struct ipft_keye_data *keye; - u32 cfg; int err; entry = kzalloc_obj(*entry); if (!entry) return -ENOMEM; - keye = &entry->keye; - err = netc_build_ptp_ipft_keye(keye, np->dp->index, type); + err = netc_build_ptp_ipft_keye(entry, np->dp->index, type); if (err) goto free_entry; - cfg = FIELD_PREP(IPFT_FLTFA, IPFT_FLTFA_REDIRECT); - cfg |= FIELD_PREP(IPFT_HR, NETC_HR_PTP_TRAP); - cfg |= IPFT_TIMECAPE | IPFT_RRT; - entry->cfge.cfg = cpu_to_le32(cfg); + entry->cfg = FIELD_PREP(IPFT_FLTFA, IPFT_FLTFA_REDIRECT) | + FIELD_PREP(IPFT_HR, NETC_HR_PTP_TRAP) | + IPFT_TIMECAPE | IPFT_RRT; err = ntmp_ipft_add_entry(&priv->ntmp, entry); if (err) diff --git a/drivers/net/ethernet/freescale/enetc/ntmp.c b/drivers/net/ethernet/freescale/enetc/ntmp.c index 21174bf2320a6..6143e8b5c6b1f 100644 --- a/drivers/net/ethernet/freescale/enetc/ntmp.c +++ b/drivers/net/ethernet/freescale/enetc/ntmp.c @@ -347,6 +347,127 @@ static const struct ntmp_tbl_ops *ntmp_get_maft_ops(u8 version) } } +static void ntmp_ipft_pack_v0(const void *entry, void *buf, int access_method) +{ + const struct ipft_entry_data *e = entry; + struct ipft_req_ua *req = buf; + struct ipft_cfge_data *cfge; + + if (access_method == NTMP_AM_TERNARY_KEY) { + struct ipft_keye_data *keye = &req->ak.keye; + const struct ipft_entry_keye *k = &e->keye; + + keye->precedence = cpu_to_le16(k->precedence); + keye->frm_attr_flags = cpu_to_le16(k->frm_attr_flags); + keye->frm_attr_flags_mask = cpu_to_le16(k->frm_attr_flags_mask); + keye->dscp = cpu_to_le16(k->dscp); + keye->src_port = cpu_to_le16(k->src_port); + keye->outer_vlan_tci = k->outer_vlan_tci; + keye->outer_vlan_tci_mask = k->outer_vlan_tci_mask; + + memcpy(keye->dmac, k->dmac, ETH_ALEN); + memcpy(keye->dmac_mask, k->dmac_mask, ETH_ALEN); + memcpy(keye->smac, k->smac, ETH_ALEN); + memcpy(keye->smac_mask, k->smac_mask, ETH_ALEN); + + keye->inner_vlan_tci = k->inner_vlan_tci; + keye->inner_vlan_tci_mask = k->inner_vlan_tci_mask; + keye->ethertype = k->ethertype; + keye->ethertype_mask = k->ethertype_mask; + keye->ip_protocol = k->ip_protocol; + keye->ip_protocol_mask = k->ip_protocol_mask; + + for (int i = 0; i < 4; i++) { + keye->ip_src[i] = k->ip_src[i]; + keye->ip_src_mask[i] = k->ip_src_mask[i]; + keye->ip_dst[i] = k->ip_dst[i]; + keye->ip_dst_mask[i] = k->ip_dst_mask[i]; + } + + keye->l4_src_port = k->l4_src_port; + keye->l4_src_port_mask = k->l4_src_port_mask; + keye->l4_dst_port = k->l4_dst_port; + keye->l4_dst_port_mask = k->l4_dst_port_mask; + memcpy(keye->byte, k->byte, sizeof(keye->byte)); + } else { /* NTMP_AM_ENTRY_ID */ + req->ak.eid.entry_id = cpu_to_le32(e->entry_id); + } + + cfge = &req->cfge; + cfge->cfg = cpu_to_le32(e->cfg); + cfge->flta_tgt = cpu_to_le32(e->flta_tgt); +} + +static void ntmp_ipft_unpack_v0(const void *buf, void *entry, bool only_eid) +{ + const struct ipft_resp_query *resp = buf; + const struct ipft_cfge_data *cfge; + const struct ipft_keye_data *keye; + struct ipft_entry_data *e = entry; + struct ipft_entry_keye *k; + int i; + + e->entry_id = le32_to_cpu(resp->entry_id); + if (only_eid) + return; + + keye = &resp->keye; + k = &e->keye; + k->precedence = le16_to_cpu(keye->precedence); + k->frm_attr_flags = le16_to_cpu(keye->frm_attr_flags); + k->frm_attr_flags_mask = le16_to_cpu(keye->frm_attr_flags_mask); + k->dscp = le16_to_cpu(keye->dscp); + k->src_port = le16_to_cpu(keye->src_port); + k->outer_vlan_tci = keye->outer_vlan_tci; + k->outer_vlan_tci_mask = keye->outer_vlan_tci_mask; + + memcpy(k->dmac, keye->dmac, ETH_ALEN); + memcpy(k->dmac_mask, keye->dmac_mask, ETH_ALEN); + memcpy(k->smac, keye->smac, ETH_ALEN); + memcpy(k->smac_mask, keye->smac_mask, ETH_ALEN); + + k->inner_vlan_tci = keye->inner_vlan_tci; + k->inner_vlan_tci_mask = keye->inner_vlan_tci_mask; + k->ethertype = keye->ethertype; + k->ethertype_mask = keye->ethertype_mask; + k->ip_protocol = keye->ip_protocol; + k->ip_protocol_mask = keye->ip_protocol_mask; + + for (i = 0; i < 4; i++) { + k->ip_src[i] = keye->ip_src[i]; + k->ip_src_mask[i] = keye->ip_src_mask[i]; + k->ip_dst[i] = keye->ip_dst[i]; + k->ip_dst_mask[i] = keye->ip_dst_mask[i]; + } + + k->l4_src_port = keye->l4_src_port; + k->l4_src_port_mask = keye->l4_src_port_mask; + k->l4_dst_port = keye->l4_dst_port; + k->l4_dst_port_mask = keye->l4_dst_port_mask; + memcpy(k->byte, keye->byte, sizeof(k->byte)); + + cfge = &resp->cfge; + e->cfg = le32_to_cpu(cfge->cfg); + e->flta_tgt = le32_to_cpu(cfge->flta_tgt); +} + +static const struct ntmp_tbl_ops ipft_ops_v0 = { + .req_ua_len = sizeof(struct ipft_req_ua), + .resp_query_len = sizeof(struct ipft_resp_query), + .pack = ntmp_ipft_pack_v0, + .unpack = ntmp_ipft_unpack_v0, +}; + +static const struct ntmp_tbl_ops *ntmp_get_ipft_ops(u8 version) +{ + switch (version) { + case NTMP_TBL_V(0): + return &ipft_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) { @@ -586,8 +707,8 @@ EXPORT_SYMBOL_GPL(ntmp_rsst_query_entry); /** * ntmp_ipft_add_entry - add an entry into the ingress port filter table * @user: target ntmp_user struct - * @entry: the entry data, entry->cfge (configuration element data) and - * entry->keye (key element data) are used as input. Since the entry ID + * @entry: the entry data, the configuration element data (CFGE_DATA) and + * the key element data (KEYE_DATA) are used as input. Since the entry ID * is assigned by the hardware, so entry->entry_id is a returned value * for the driver to use, the driver can update/delete/query the entry * based on the entry_id. @@ -597,16 +718,21 @@ EXPORT_SYMBOL_GPL(ntmp_rsst_query_entry); int ntmp_ipft_add_entry(struct ntmp_user *user, struct ipft_entry_data *entry) { - struct ipft_resp_query *resp; - struct ipft_req_ua *req; + 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; - swcbd.size = sizeof(*resp); - err = ntmp_alloc_data_mem(user->dev, &swcbd, (void **)&req); + 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; @@ -614,12 +740,11 @@ int ntmp_ipft_add_entry(struct ntmp_user *user, * the entry. The STSE_DATA is not present in the request data for * 'Add' operation. */ - ntmp_fill_crd(&req->crd, user->tbl_ver[NTMP_IPFT_ID], NTMP_QA_ENTRY_ID, + ntmp_fill_crd(buf, version, NTMP_QA_ENTRY_ID, NTMP_GEN_UA_CFGEU | NTMP_GEN_UA_STSEU); - req->ak.keye = entry->keye; - req->cfge = entry->cfge; + ops->pack(entry, buf, NTMP_AM_TERNARY_KEY); - len = NTMP_LEN(sizeof(*req), swcbd.size); + 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); @@ -632,8 +757,7 @@ int ntmp_ipft_add_entry(struct ntmp_user *user, goto unlock_cbdr; } - resp = (struct ipft_resp_query *)req; - entry->entry_id = le32_to_cpu(resp->entry_id); + ops->unpack(buf, entry, true); 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 4d372dcc6ca31..5dcfc98b51066 100644 --- a/drivers/net/ethernet/freescale/enetc/ntmp_private.h +++ b/drivers/net/ethernet/freescale/enetc/ntmp_private.h @@ -141,6 +141,48 @@ struct rsst_req_update { u8 groups[]; }; +/* Ingress Port Filter Table Key Element Data */ +struct ipft_keye_data { + __le16 precedence; + __le16 resv0[3]; + __le16 frm_attr_flags; + __le16 frm_attr_flags_mask; + __le16 dscp; + __le16 src_port; /* This field is reserved for ENETC */ + __be16 outer_vlan_tci; + __be16 outer_vlan_tci_mask; + u8 dmac[ETH_ALEN]; + u8 dmac_mask[ETH_ALEN]; + u8 smac[ETH_ALEN]; + u8 smac_mask[ETH_ALEN]; + __be16 inner_vlan_tci; + __be16 inner_vlan_tci_mask; + __be16 ethertype; + __be16 ethertype_mask; + u8 ip_protocol; + u8 ip_protocol_mask; + __le16 resv1[7]; + __be32 ip_src[4]; + __le32 resv2[2]; + __be32 ip_src_mask[4]; + __be16 l4_src_port; + __be16 l4_src_port_mask; + __le32 resv3; + __be32 ip_dst[4]; + __le32 resv4[2]; + __be32 ip_dst_mask[4]; + __be16 l4_dst_port; + __be16 l4_dst_port_mask; + __le32 resv5; + struct ipft_pld_byte byte[IPFT_MAX_PLD_LEN]; +}; + +/* Ingress Port Filter Table Configuration Element Data */ +struct ipft_cfge_data { + __le32 cfg; + __le32 flta_tgt; +}; + /* Ingress Port Filter Table Response Data Buffer Format of Query action */ struct ipft_resp_query { __le32 status; diff --git a/include/linux/fsl/ntmp.h b/include/linux/fsl/ntmp.h index 558577c052e77..226c672c845af 100644 --- a/include/linux/fsl/ntmp.h +++ b/include/linux/fsl/ntmp.h @@ -92,10 +92,9 @@ struct ipft_pld_byte { u8 mask; }; -struct ipft_keye_data { - __le16 precedence; - __le16 resv0[3]; - __le16 frm_attr_flags; +struct ipft_entry_keye { + u16 precedence; + u16 frm_attr_flags; #define IPFT_FAF_OVLAN BIT(2) #define IPFT_FAF_IVLAN BIT(3) #define IPFT_FAF_IP_HDR BIT(7) @@ -105,12 +104,12 @@ struct ipft_keye_data { #define IPFT_FAF_UDP_HDR 2 #define IPFT_FAF_SCTP_HDR 3 #define IPFT_FAF_WOL_MAGIC BIT(12) - __le16 frm_attr_flags_mask; - __le16 dscp; + u16 frm_attr_flags_mask; + u16 dscp; #define IPFT_DSCP GENMASK(5, 0) #define IPFT_DSCP_MASK GENMASK(11, 6) #define IPFT_DSCP_MASK_ALL 0x3f - __le16 src_port; /* This field is reserved for ENETC */ + u16 src_port; /* This field is reserved for ENETC */ #define IPFT_SRC_PORT GENMASK(4, 0) #define IPFT_SRC_PORT_MASK GENMASK(9, 5) #define IPFT_SRC_PORT_MASK_ALL 0x1f @@ -126,24 +125,25 @@ struct ipft_keye_data { __be16 ethertype_mask; u8 ip_protocol; u8 ip_protocol_mask; - __le16 resv1[7]; __be32 ip_src[4]; - __le32 resv2[2]; __be32 ip_src_mask[4]; __be16 l4_src_port; __be16 l4_src_port_mask; - __le32 resv3; __be32 ip_dst[4]; - __le32 resv4[2]; __be32 ip_dst_mask[4]; __be16 l4_dst_port; __be16 l4_dst_port_mask; - __le32 resv5; struct ipft_pld_byte byte[IPFT_MAX_PLD_LEN]; }; -struct ipft_cfge_data { - __le32 cfg; +struct ipft_entry_data { + u32 entry_id; /* hardware assigns entry ID */ + + /* KEYE_DATA */ + struct ipft_entry_keye keye; + + /* CFGE_DATA */ + u32 cfg; #define IPFT_IPV GENMASK(3, 0) #define IPFT_OIPV BIT(4) #define IPFT_DR GENMASK(6, 5) @@ -166,13 +166,7 @@ struct ipft_cfge_data { #define IPFT_RRT BIT(23) #define IPFT_BL2F BIT(24) #define IPFT_EVMEID GENMASK(31, 28) - __le32 flta_tgt; -}; - -struct ipft_entry_data { - u32 entry_id; /* hardware assigns entry ID */ - struct ipft_keye_data keye; - struct ipft_cfge_data cfge; + u32 flta_tgt; }; struct fdbt_keye_data { -- 2.34.1