[PATCH net-next 03/14] net: enetc: decouple IPFT logical config from hardware wire format
wei.fang at oss.nxp.com
wei.fang at oss.nxp.com
Thu Dec 3 23:13:59 PST 2026
From: Wei Fang <wei.fang at nxp.com>
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 <wei.fang at nxp.com>
---
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
More information about the linux-arm-kernel
mailing list