net: enetc: refactor NTMP table handling and add generic helpers
Subsystems (7)
cover net: enetc: refactor NTMP table handling and add generic helpers
From: Wei Fang <[email protected]>
This series refactors the NTMP infrastructure to improve maintainability and future-proof the driver.
1. Introduce a public enum ntmp_tbl_id and an indexed tbl_ver array, removing per-table version fields and redundant arguments.
2. Add generic ntmp_add_entry_by_id() and ntmp_update_entry_by_id() helpers that encapsulate common add/update boilerplate.
3. Provide ntmp_add_entry_by_key() for tables that allocate IDs in hardware, reducing duplicated logic across IPFT, FDBT and VFT.
4. Implement ntmp_query_entry_by_id() as a unified query path, eliminating per-table query duplication.
5. Convert specific table update functions (ECT, FDBT, ETT, BPT) to use the generic update helper.
6. Decouple logical configuration structs from hardware wire format for MAFT, IPFT, FDBT, VFT, ETT and BPT tables. New version-agnostic *_entry_data structs use native CPU types; wire structures are moved to ntmp_private.h and accessed via ntmp_tbl_ops callbacks.
7. Add kernel-doc for ntmp_delete_entry_by_id() to keep documentation consistent.
8. Register table specific ops in ntmp_table_ops() and expose helper getters (ntmp_get_*_ops()).
9. Update callers throughout the driver to work with the logical config structs and generic helpers, simplifying code paths and reducing boilerplate.
These changes make NTMP table code easier to extend for future hardware revisions, improve code reuse, and provide clearer documentation.
Wei Fang (14):
net: enetc: use an ID-indexed array to track NTMP table versions
net: enetc: decouple MAFT logical config from hardware wire format
net: enetc: decouple IPFT logical config from hardware wire format
net: enetc: decouple FDBT logical config from hardware wire format
net: enetc: decouple VFT logical config from hardware wire format
net: enetc: decouple ETT logical config from hardware wire format
net: enetc: decouple BPT logical config from hardware wire format
net: enetc: add generic ntmp_add_entry_by_id() helper
net: enetc: simplify callers of ntmp_query_entry_by_id()
net: enetc: add kernel-doc for ntmp_delete_entry_by_id()
net: enetc: add a generic helper to update an NTMP entry by entry ID
net: enetc: convert ntmp_ect_update_entry() to the generic update
helper
net: enetc: add a generic helper to add an NTMP entry by key
net: enetc: convert the RSST to the generic NTMP entry helpers
drivers/net/dsa/netc/netc_main.c | 231 ++- drivers/net/dsa/netc/netc_ptp.c | 28 +- drivers/net/dsa/netc/netc_switch.h | 9 +- .../ethernet/freescale/enetc/enetc4_debugfs.c | 10 +- .../net/ethernet/freescale/enetc/enetc4_pf.c | 19 +- drivers/net/ethernet/freescale/enetc/ntmp.c | 1247 ++++++++++------- .../ethernet/freescale/enetc/ntmp_private.h | 149 +- include/linux/fsl/ntmp.h | 219 ++- 8 files changed, 1129 insertions(+), 783 deletions(-)
Signature · 1 line
2.34.1
PATCH 1/14 net: enetc: use an ID-indexed array to track NTMP table versions
From: Wei Fang <[email protected]>
The NTMP table versions are kept in struct netc_tbl_vers, one named u8 field per table, while the table IDs are duplicated as private macros in ntmp.c. Callers must pick the right field by hand, and the version has to be passed around even though the table ID is known.
Move the table IDs into a public enum ntmp_tbl_id with an NTMP_TBL_MAX_ID sentinel, and replace the per-table fields with a single u8 tbl_ver[NTMP_TBL_MAX_ID] indexed by table ID. Update the call sites accordingly and drop the redundant tbl_ver argument from ntmp_delete_entry_by_id().
--- drivers/net/dsa/netc/netc_main.c | 2 +- .../net/ethernet/freescale/enetc/enetc4_pf.c | 2 +- drivers/net/ethernet/freescale/enetc/ntmp.c | 67 ++++++++----------- include/linux/fsl/ntmp.h | 23 ++++--- 4 files changed, 43 insertions(+), 51 deletions(-)
drivers/net/dsa/netc/netc_main.c +1 -1
@@ -397,7 +397,7 @@ static void netc_init_ntmp_tbl_versions(struct netc_switch *priv)struct ntmp_user *ntmp = &priv->ntmp;/* All tables default to version 0 */ -memset (&ntmp->tbl,0 ,sizeof (ntmp->tbl)); +memset (ntmp->tbl_ver,0 ,sizeof (ntmp->tbl_ver)); }static int netc_init_all_cbdrs (struct netc_switch *priv)
drivers/net/ethernet/freescale/enetc/enetc4_pf.c +1 -1
@@ -470,7 +470,7 @@ static int enetc4_init_ntmp_user(struct enetc_si *si)int err;/* For ENETC 4.1, all table versions are 0 */ -memset (&user->tbl,0 ,sizeof (user->tbl)); +memset (user->tbl_ver,0 ,sizeof (user->tbl_ver)); err =enetc4_setup_cbdr (si);if (err)
drivers/net/ethernet/freescale/enetc/ntmp.c +28 -39
205 lines not on this page · raw message
include/linux/fsl/ntmp.h +13 -10
@@ -30,15 +30,18 @@ struct netc_cbdr_regs {void __iomem *lenr; }; -struct netc_tbl_vers { -u8 maft_ver; -u8 rsst_ver; -u8 fdbt_ver; -u8 vft_ver; -u8 bpt_ver; -u8 ipft_ver; -u8 ett_ver; -u8 ect_ver; +enum ntmp_tbl_id { +NTMP_MAFT_ID =1 , +NTMP_RSST_ID =3 , +NTMP_IPFT_ID =13 , +NTMP_FDBT_ID =15 , +NTMP_VFT_ID =18 , +NTMP_ETT_ID =33 , +NTMP_ECT_ID =39 , +NTMP_BPT_ID =41 , + +/* Add new table ID above here */ +NTMP_TBL_MAX_ID , };struct netc_swcbd {
@@ -70,7 +73,7 @@ struct ntmp_user {int cbdr_num;/* number of control BD ring */ struct device *dev;struct netc_cbdr *ring; -struct netc_tbl_vers tbl; +u8 tbl_ver[NTMP_TBL_MAX_ID ];/* NTMP table bitmaps for resource management */ u32 ett_bitmap_size;
Signature · 1 line
2.34.1
PATCH 2/14 net: enetc: decouple MAFT logical config from hardware wire format
In reply to [email protected]From: Wei Fang <[email protected]>
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.
--- .../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(-)
drivers/net/ethernet/freescale/enetc/enetc4_debugfs.c +5 -5
@@ -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:
drivers/net/ethernet/freescale/enetc/enetc4_pf.c +8 -9
@@ -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; } }
drivers/net/ethernet/freescale/enetc/ntmp.c +66 -26
137 lines not on this page · raw message
drivers/net/ethernet/freescale/enetc/ntmp_private.h +42 -0
48 lines not on this page · raw message
include/linux/fsl/ntmp.h +12 -32
68 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH 3/14 net: enetc: decouple IPFT logical config from hardware wire format
In reply to [email protected]From: Wei Fang <[email protected]>
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.
--- 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(-)
drivers/net/dsa/netc/netc_main.c +5 -13
@@ -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;
drivers/net/dsa/netc/netc_ptp.c +12 -16
@@ -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)
drivers/net/ethernet/freescale/enetc/ntmp.c +136 -12
186 lines not on this page · raw message
drivers/net/ethernet/freescale/enetc/ntmp_private.h +42 -0
48 lines not on this page · raw message
include/linux/fsl/ntmp.h +15 -21
@@ -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 {
Signature · 1 line
2.34.1
PATCH 4/14 net: enetc: decouple FDBT logical config from hardware wire format
In reply to [email protected]From: Wei Fang <[email protected]>
Current SoCs only implement FDBT version 0, but future versions may extend the table with a different buffer layout and size. Today struct fdbt_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 fdbt_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 struct ntmp_tbl_ops instance holding the buffer sizes and pack()/unpack() callbacks, and select it via ntmp_get_fdbt_ops(), following the MAFT and IPFT tables.
Reshape the FDBT interface around the logical config. ntmp_fdbt_add_entry() and ntmp_fdbt_update_entry() now take a struct fdbt_entry_data pointer instead of separate keye/cfge pointers and an entry ID. Add a status field to the logical config to carry the RESUME_ENTRY_ID of a search, so ntmp_fdbt_search_port_entry() no longer needs a separate resume_entry_id argument and its caller resumes from entry->status.
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.
--- drivers/net/dsa/netc/netc_main.c | 71 ++++---- drivers/net/dsa/netc/netc_switch.h | 4 +- drivers/net/ethernet/freescale/enetc/ntmp.c | 155 ++++++++++++------ .../ethernet/freescale/enetc/ntmp_private.h | 15 ++ include/linux/fsl/ntmp.h | 35 ++-- 5 files changed, 167 insertions(+), 113 deletions(-)
drivers/net/dsa/netc/netc_main.c +29 -42
@@ -21,8 +21,8 @@ netc_lookup_fdb_entry(struct netc_switch *priv,struct netc_fdb_entry *entry;hlist_for_each_entry (entry, &priv->fdb_list, node) -if (ether_addr_equal (entry->keye.mac_addr, addr) && -le16_to_cpu (entry->keye.fid) == vid) +if (ether_addr_equal (entry->data.mac_addr, addr) && + entry->data.fid == vid)return entry;return NULL ;
@@ -739,26 +739,19 @@ static int netc_port_add_fdb_entry(struct netc_port *np, {struct netc_switch *priv = np->switch_priv;struct netc_fdb_entry *entry; -struct fdbt_keye_data *keye; -struct fdbt_cfge_data *cfge;int port = np->dp->index; -u32 cfg =0 ;int err; entry =kzalloc_obj (*entry);if (!entry)return -ENOMEM ; - keye = &entry->keye; - cfge = &entry->cfge; -ether_addr_copy (keye->mac_addr, addr); - keye->fid =cpu_to_le16 (vid); - - cfge->port_bitmap =cpu_to_le32 (BIT (port)); - cfge->cfg =cpu_to_le32 (cfg); - cfge->et_eid =cpu_to_le32 (NTMP_NULL_ENTRY_ID ); +ether_addr_copy (entry->data.mac_addr, addr); + entry->data.fid = vid; + entry->data.port_bitmap =BIT (port); + entry->data.et_eid =NTMP_NULL_ENTRY_ID ; - err =ntmp_fdbt_add_entry (&priv->ntmp, &entry->entry_id, keye, cfge); + err =ntmp_fdbt_add_entry (&priv->ntmp, &entry->data);if (err) {kfree (entry);
@@ -775,9 +768,8 @@ static int netc_port_set_fdb_entry(struct netc_port *np, {struct netc_switch *priv = np->switch_priv;struct netc_fdb_entry *entry; -struct fdbt_cfge_data *cfge;int port = np->dp->index; -__le32 old_port_bitmap; +u32 old_port_bitmap;int err =0 ;mutex_lock (&priv->fdbt_lock);
@@ -793,24 +785,23 @@ static int netc_port_set_fdb_entry(struct netc_port *np, goto unlock_fdbt; } - cfge = &entry->cfge;/* If the entry already exists on the port, return 0 directly */ -if (unlikely (cfge->port_bitmap &cpu_to_le32 (BIT (port)))) +if (unlikely (entry->data.port_bitmap &BIT (port))) goto unlock_fdbt;/* If the entry already exists, but not on this port, we need to * update the port bitmap. In general, it should only be valid * for multicast or broadcast address. */ - old_port_bitmap = cfge->port_bitmap; + old_port_bitmap = entry->data.port_bitmap;if (is_multicast_ether_addr (addr)) - cfge->port_bitmap |=cpu_to_le32 (BIT (port)); + entry->data.port_bitmap |=BIT (port);else - cfge->port_bitmap =cpu_to_le32 (BIT (port)); + entry->data.port_bitmap =BIT (port); - err =ntmp_fdbt_update_entry (&priv->ntmp, entry->entry_id, cfge); + err =ntmp_fdbt_update_entry (&priv->ntmp, &entry->data);if (err) { - cfge->port_bitmap = old_port_bitmap; + entry->data.port_bitmap = old_port_bitmap;dev_err (priv->dev,"Failed to set FDB entry on port %d\n" , port); }
@@ -827,7 +818,6 @@ static int netc_port_del_fdb_entry(struct netc_port *np,struct netc_switch *priv = np->switch_priv;struct ntmp_user *ntmp = &priv->ntmp;struct netc_fdb_entry *entry; -struct fdbt_cfge_data *cfge;int port = np->dp->index;int err =0 ;
@@ -848,25 +838,24 @@ static int netc_port_del_fdb_entry(struct netc_port *np,*/ goto unlock_fdbt; - cfge = &entry->cfge; -if (unlikely (!(cfge->port_bitmap &cpu_to_le32 (BIT (port))))) +if (unlikely (!(entry->data.port_bitmap &BIT (port)))) goto unlock_fdbt; -if (cfge->port_bitmap !=cpu_to_le32 (BIT (port))) { +if (entry->data.port_bitmap !=BIT (port)) {/* If the entry also exists on other ports, we need to * update the entry in the FDB table. */ - cfge->port_bitmap &=cpu_to_le32 (~BIT (port)); - err =ntmp_fdbt_update_entry (ntmp, entry->entry_id, cfge); + entry->data.port_bitmap &= ~BIT (port); + err =ntmp_fdbt_update_entry (ntmp, &entry->data);if (err) { - cfge->port_bitmap |=cpu_to_le32 (BIT (port)); + entry->data.port_bitmap |=BIT (port); goto unlock_fdbt; } }else {/* If the entry only exists on this port, just delete * it from the FDB table. */ - err =ntmp_fdbt_delete_entry (ntmp, entry->entry_id); + err =ntmp_fdbt_delete_entry (ntmp, entry->data.entry_id);if (err) goto unlock_fdbt;
@@ -1818,10 +1807,8 @@ static int netc_port_fdb_dump(struct dsa_switch *ds, int port,struct netc_switch *priv = ds->priv;u32 resume_eid =NTMP_NULL_ENTRY_ID ;struct fdbt_entry_data *entry; -struct fdbt_keye_data *keye; -struct fdbt_cfge_data *cfge; -u32 cfg, cnt =0 ;bool is_static; +u32 cnt =0 ;int err;u16 vid;
@@ -1829,24 +1816,22 @@ static int netc_port_fdb_dump(struct dsa_switch *ds, int port,if (!entry)return -ENOMEM ; - keye = &entry->keye; - cfge = &entry->cfge;mutex_lock (&priv->fdbt_lock); do { memset(entry, 0, sizeof(*entry)); - err = ntmp_fdbt_search_port_entry(&priv->ntmp, port, - &resume_eid, entry); + entry->status = resume_eid; + + err = ntmp_fdbt_search_port_entry(&priv->ntmp, port, entry); if (err || entry->entry_id == NTMP_NULL_ENTRY_ID) break; - cfg = le32_to_cpu(cfge->cfg); - is_static = (cfg & FDBT_DYNAMIC) ? false : true; - vid = le16_to_cpu(keye->fid); + is_static = (entry->cfg & FDBT_DYNAMIC) ? false : true; + vid = entry->fid; if (vid >= NETC_VLAN_UNAWARE_PVID(ds->max_num_bridges)) vid = 0; - err = cb(keye->mac_addr, vid, is_static, data); + err = cb(entry->mac_addr, vid, is_static, data); if (err) break;
@@ -1855,6 +1840,8 @@ static int netc_port_fdb_dump(struct dsa_switch *ds, int port,*/ if (++cnt >= priv->htmcapr_num_words)break ; + + resume_eid = entry->status; }while (resume_eid !=NTMP_NULL_ENTRY_ID );mutex_unlock (&priv->fdbt_lock);
drivers/net/dsa/netc/netc_switch.h +1 -3
@@ -136,9 +136,7 @@ struct netc_switch_regs { };struct netc_fdb_entry { -u32 entry_id; -struct fdbt_cfge_data cfge; -struct fdbt_keye_data keye; +struct fdbt_entry_data data;struct hlist_node node; };
drivers/net/ethernet/freescale/enetc/ntmp.c +107 -48
247 lines not on this page · raw message
drivers/net/ethernet/freescale/enetc/ntmp_private.h +15 -0
@@ -219,6 +219,21 @@ struct ipft_req_qd {__le32 resv[52 ]; }; +/* FDB Table Key Element Data */ +struct fdbt_keye_data { +u8 mac_addr[ETH_ALEN ];/* big-endian */ +__le16 resv0; +__le16 fid; +__le16 resv1; +}; + +/* FDB Table Configuration Element Data */ +struct fdbt_cfge_data { +__le32 port_bitmap; +__le32 cfg; +__le32 et_eid; +}; +/* Access Key Format of FDB Table */ struct fdbt_ak_eid {__le32 entry_id;
include/linux/fsl/ntmp.h +15 -20
@@ -169,31 +169,28 @@ struct ipft_entry_data {u32 flta_tgt; }; -struct fdbt_keye_data { +struct fdbt_entry_data { +u32 entry_id; +u32 status;/* RESUME_ENTRY_ID returned by a search operation */ + +/* KEYE_DATA */ u8 mac_addr[ETH_ALEN ];/* big-endian */ -__le16 resv0; -__le16 fid; +u16 fid;#define FDBT_FID GENMASK(11, 0) -__le16 resv1; -}; -struct fdbt_cfge_data { -__le32 port_bitmap; +/* CFGE_DATA */ +u32 port_bitmap;#define FDBT_PORT_BITMAP GENMASK(23, 0) -__le32 cfg; +u32 cfg;#define FDBT_OETEID GENMASK(1, 0)#define FDBT_EPORT GENMASK(6, 2)#define FDBT_IMIRE BIT(7)#define FDBT_CTD GENMASK(10, 9)#define FDBT_DYNAMIC BIT(11)#define FDBT_TIMECAPE BIT(12) -__le32 et_eid; -}; +u32 et_eid; -struct fdbt_entry_data { -u32 entry_id; -struct fdbt_keye_data keye; -struct fdbt_cfge_data cfge; +/* ACTE_DATA */ u8 acte;#define FDBT_ACT_CNT GENMASK(6, 0)#define FDBT_ACT_FLAG BIT(7)
@@ -293,14 +290,12 @@ int ntmp_rsst_query_entry(struct ntmp_user *user,int ntmp_ipft_add_entry (struct ntmp_user *user,struct ipft_entry_data *entry);int ntmp_ipft_delete_entry (struct ntmp_user *user,u32 entry_id); -int ntmp_fdbt_add_entry (struct ntmp_user *user,u32 *entry_id, -const struct fdbt_keye_data *keye, -const struct fdbt_cfge_data *cfge); -int ntmp_fdbt_update_entry (struct ntmp_user *user,u32 entry_id, -const struct fdbt_cfge_data *cfge); +int ntmp_fdbt_add_entry (struct ntmp_user *user, +struct fdbt_entry_data *entry); +int ntmp_fdbt_update_entry (struct ntmp_user *user, +const struct fdbt_entry_data *entry);int ntmp_fdbt_delete_entry (struct ntmp_user *user,u32 entry_id);int ntmp_fdbt_search_port_entry (struct ntmp_user *user,int port, -u32 *resume_entry_id,struct fdbt_entry_data *entry);int ntmp_fdbt_update_activity_element (struct ntmp_user *user);int ntmp_fdbt_delete_ageing_entries (struct ntmp_user *user,u8 act_cnt);
Signature · 1 line
2.34.1
PATCH 5/14 net: enetc: decouple VFT logical config from hardware wire format
In reply to [email protected]From: Wei Fang <[email protected]>
Current SoCs only implement VFT version 0, but future versions may extend the table with a different buffer layout and size. Today struct vft_cfge_data is the hardware CFGE structure, 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.
Add a version-agnostic struct vft_entry_data that uses native CPU types and also carries the VLAN ID, and move the wire structure into ntmp_private.h to keep it internal to the NTMP layer. Add a struct ntmp_tbl_ops instance holding the buffer size and a pack() callback, and select it via ntmp_get_vft_ops(), following the MAFT, IPFT and FDBT tables.
Reshape the VFT interface around the logical config. ntmp_vft_add_entry() and ntmp_vft_update_entry() now take a struct vft_entry_data pointer instead of a VLAN ID and a separate cfge pointer. Note that the command in ntmp_vft_add_entry() has been changed NTMP_CMD_AQ. This allows the NETC switch driver to track the ID of each entry and access thoes entries using the entry ID match method.
A future version can then be added within the NTMP layer by providing its wire structure, pack helper and ops instance. Callers may still need small adjustments, but they no longer deal with the wire format or endianness.
--- drivers/net/dsa/netc/netc_main.c | 83 +++++------- drivers/net/dsa/netc/netc_switch.h | 3 +- drivers/net/ethernet/freescale/enetc/ntmp.c | 120 ++++++++++++++---- .../ethernet/freescale/enetc/ntmp_private.h | 17 +++ include/linux/fsl/ntmp.h | 25 ++-- 5 files changed, 161 insertions(+), 87 deletions(-)
drivers/net/dsa/netc/netc_main.c +35 -48
@@ -43,7 +43,7 @@ netc_lookup_vlan_entry(struct netc_switch *priv, u16 vid)struct netc_vlan_entry *entry;hlist_for_each_entry (entry, &priv->vlan_list, node) -if (entry->vid == vid) +if (entry->data.vid == vid)return entry;return NULL ;
@@ -699,18 +699,17 @@ static u32 netc_available_port_bitmap(struct netc_switch *priv)static int netc_add_standalone_vlan_entry (struct netc_switch *priv) { -u32 bitmap_stg =VFT_STG_ID (0 ) |netc_available_port_bitmap (priv); -struct vft_cfge_data *cfge; -u16 cfg; +struct vft_entry_data *entry;int err; - cfge =kzalloc_obj (*cfge); -if (!cfge) + entry =kzalloc_obj (*entry); +if (!entry)return -ENOMEM ; - cfge->bitmap_stg =cpu_to_le32 (bitmap_stg); - cfge->et_eid =cpu_to_le32 (NTMP_NULL_ENTRY_ID ); - cfge->fid =cpu_to_le16 (NETC_STANDALONE_PVID ); + entry->vid =NETC_STANDALONE_PVID ; + entry->bitmap_stg =VFT_STG_ID (0 ) |netc_available_port_bitmap (priv); + entry->et_eid =NTMP_NULL_ENTRY_ID ; + entry->fid =NETC_STANDALONE_PVID ;/* For standalone ports, MAC learning needs to be disabled, so frames * from other user ports will not be forwarded to the standalone ports,
@@ -720,16 +719,15 @@ static int netc_add_standalone_vlan_entry(struct netc_switch *priv)* MFO_NO_MATCH_DISCARD, so the frames will be discarded rather than * flooding to other ports. */ - cfg =FIELD_PREP (VFT_MLO ,MLO_DISABLE ) | -FIELD_PREP (VFT_MFO ,MFO_NO_MATCH_DISCARD ); - cfge->cfg =cpu_to_le16 (cfg); + entry->cfg =FIELD_PREP (VFT_MLO ,MLO_DISABLE ) | +FIELD_PREP (VFT_MFO ,MFO_NO_MATCH_DISCARD ); - err =ntmp_vft_add_entry (&priv->ntmp,NETC_STANDALONE_PVID , cfge); + err =ntmp_vft_add_entry (&priv->ntmp, entry);if (err)dev_err (priv->dev,"Failed to add standalone VLAN entry\n" ); -kfree (cfge); +kfree (entry);return err; }
@@ -1385,7 +1383,7 @@ static int netc_add_vlan_egress_rule(struct netc_switch *priv,if (err) goto clear_ett_gid; - entry->cfge.et_eid =cpu_to_le32 (ett_eid); + entry->data.et_eid = ett_eid; entry->ect_gid = ect_gid;return 0 ;
@@ -1407,7 +1405,7 @@ static void netc_delete_vlan_egress_rule(struct netc_switch *priv,struct ntmp_user *ntmp = &priv->ntmp;u32 ett_eid, ett_gid; - ett_eid =le32_to_cpu (entry->cfge.et_eid); + ett_eid = entry->data.et_eid;if (ett_eid ==NTMP_NULL_ENTRY_ID )return ;
@@ -1427,8 +1425,8 @@ static int netc_port_update_vlan_egress_rule(struct netc_port *np, {bool untagged = !!(entry->untagged_port_bitmap &BIT (np->dp->index));u32 num_ports =netc_num_available_ports (np->switch_priv); -u32 ett_eid =le32_to_cpu (entry->cfge.et_eid);struct netc_switch *priv = np->switch_priv; +u32 ett_eid = entry->data.et_eid;u32 ect_eid =NTMP_NULL_ENTRY_ID ;int err;
@@ -1447,7 +1445,7 @@ static int netc_port_update_vlan_egress_rule(struct netc_port *np,if (err) {dev_err (priv->dev,"Failed to update VLAN %u egress rule on port %d\n" , - entry->vid, np->dp->index); + entry->data.vid, np->dp->index);return err; }
@@ -1462,20 +1460,15 @@ static int netc_port_add_vlan_entry(struct netc_port *np, u16 vid, {struct netc_switch *priv = np->switch_priv;struct netc_vlan_entry *entry; -struct vft_cfge_data *cfge;u32 index = np->dp->index; -u32 bitmap_stg;int err; -u16 cfg; entry =kzalloc_obj (*entry);if (!entry)return -ENOMEM ; - entry->vid = vid; entry->ect_gid =NTMP_NULL_ENTRY_ID ; - - bitmap_stg =BIT (index) |VFT_STG_ID (0 ); + entry->data.bitmap_stg =BIT (index) |VFT_STG_ID (0 );/* If the VID is a VLAN-unaware PVID, the CPU port needs to be * a member of this VLAN. */
@@ -1483,18 +1476,15 @@ static int netc_port_add_vlan_entry(struct netc_port *np, u16 vid, vid >= NETC_VLAN_UNAWARE_PVID(priv->ds->max_num_bridges)) {struct dsa_port *cpu_dp = np->dp->cpu_dp; - bitmap_stg |=BIT (cpu_dp->index); + entry->data.bitmap_stg |=BIT (cpu_dp->index); } - cfg =FIELD_PREP (VFT_MLO ,MLO_HW ) | -FIELD_PREP (VFT_MFO ,MFO_NO_MATCH_FLOOD ); - - cfge = &entry->cfge; - cfge->et_eid =cpu_to_le32 (NTMP_NULL_ENTRY_ID ); - cfge->bitmap_stg =cpu_to_le32 (bitmap_stg); - cfge->fid =cpu_to_le16 (vid); - cfge->cfg =cpu_to_le16 (cfg); - cfge->eta_port_bitmap =cpu_to_le32 (priv->port_bitmap); + entry->data.vid = vid; + entry->data.et_eid =NTMP_NULL_ENTRY_ID ; + entry->data.fid = vid; + entry->data.cfg =FIELD_PREP (VFT_MLO ,MLO_HW ) | +FIELD_PREP (VFT_MFO ,MFO_NO_MATCH_FLOOD ); + entry->data.eta_port_bitmap = priv->port_bitmap;if (untagged) entry->untagged_port_bitmap =BIT (index);
@@ -1503,7 +1493,7 @@ static int netc_port_add_vlan_entry(struct netc_port *np, u16 vid,if (err) goto free_vlan_entry; - err =ntmp_vft_add_entry (&priv->ntmp, vid, cfge); + err =ntmp_vft_add_entry (&priv->ntmp, &entry->data);if (err) { dev_err(priv->dev, "Failed to add VLAN %u entry on port %d\n",
@@ -1528,9 +1518,10 @@ static bool netc_port_vlan_egress_rule_changed(struct netc_switch *priv, int port, bool untagged) { bool old_untagged = !!(entry->untagged_port_bitmap & BIT(port)); +u16 vid = entry->data.vid;/* VLAN-unaware VIDs have no egress rules, so return 'false' */ -if (entry->vid >=NETC_VLAN_UNAWARE_PVID (priv->ds->max_num_bridges)) +if (vid >=NETC_VLAN_UNAWARE_PVID (priv->ds->max_num_bridges))return false;return old_untagged != untagged;
@@ -1541,7 +1532,6 @@ static int netc_port_set_vlan_entry(struct netc_port *np, u16 vid, {struct netc_switch *priv = np->switch_priv;struct netc_vlan_entry *entry; -struct vft_cfge_data *cfge;int port = np->dp->index;bool changed;int err =0 ;
@@ -1566,12 +1556,11 @@ static int netc_port_set_vlan_entry(struct netc_port *np, u16 vid, } } - cfge = &entry->cfge; -if (cfge->bitmap_stg &cpu_to_le32 (BIT (port))) +if (entry->data.bitmap_stg &BIT (port)) goto unlock_vft; - cfge->bitmap_stg |=cpu_to_le32 (BIT (port)); - err =ntmp_vft_update_entry (&priv->ntmp, vid, cfge); + entry->data.bitmap_stg |=BIT (port); + err =ntmp_vft_update_entry (&priv->ntmp, &entry->data);if (err) { dev_err(priv->dev, "Failed to update VLAN %u entry on port %d\n",
@@ -1585,7 +1574,7 @@ static int netc_port_set_vlan_entry(struct netc_port *np, u16 vid,return 0 ; restore_bitmap_stg: - cfge->bitmap_stg &=cpu_to_le32 (~BIT (port)); + entry->data.bitmap_stg &= ~BIT (port);if (changed) { entry->untagged_port_bitmap ^=BIT (port);/* Recover the corresponding ETT entry. It doesn't matter
@@ -1606,7 +1595,6 @@ static int netc_port_del_vlan_entry(struct netc_port *np, u16 vid) {struct netc_switch *priv = np->switch_priv;struct netc_vlan_entry *entry; -struct vft_cfge_data *cfge;int port = np->dp->index;u32 vlan_port_bitmap;int err =0 ;
@@ -1617,9 +1605,8 @@ static int netc_port_del_vlan_entry(struct netc_port *np, u16 vid)if (!entry) goto unlock_vft; - cfge = &entry->cfge; vlan_port_bitmap =FIELD_GET (VFT_PORT_MEMBERSHIP , -le32_to_cpu (cfge->bitmap_stg)); + entry->data.bitmap_stg);/* If the VID is a VLAN-unaware PVID, we need to clear the CPU * port bit of vlan_port_bitmap, so that the VLAN entry can be * deleted if no user ports use this VLAN.
@@ -1646,10 +1633,10 @@ static int netc_port_del_vlan_entry(struct netc_port *np, u16 vid)if (!(vlan_port_bitmap &BIT (port))) goto unlock_vft; - cfge->bitmap_stg &=cpu_to_le32 (~BIT (port)); - err =ntmp_vft_update_entry (&priv->ntmp, vid, cfge); + entry->data.bitmap_stg &= ~BIT (port); + err =ntmp_vft_update_entry (&priv->ntmp, &entry->data);if (err) { - cfge->bitmap_stg |=cpu_to_le32 (BIT (port)); + entry->data.bitmap_stg |=BIT (port); goto unlock_vft; }
drivers/net/dsa/netc/netc_switch.h +1 -2
@@ -141,10 +141,9 @@ struct netc_fdb_entry { };struct netc_vlan_entry { -u16 vid;u32 ect_gid;u32 untagged_port_bitmap; -struct vft_cfge_data cfge; +struct vft_entry_data data;struct hlist_node node; };
drivers/net/ethernet/freescale/enetc/ntmp.c +93 -27
184 lines not on this page · raw message
drivers/net/ethernet/freescale/enetc/ntmp_private.h +17 -0
@@ -291,6 +291,15 @@ struct fdbt_resp_query {u8 resv[3 ]; }; +/* VLAN Filter Table Configuration Element Data */ +struct vft_cfge_data { +__le32 bitmap_stg; +__le16 fid; +__le16 cfg; +__le32 eta_port_bitmap; +__le32 et_eid; +}; +/* Access Key Format of VLAN Filter Table */ struct vft_ak_exact {__le16 vid;/* bit0~11: VLAN ID, other bits are reserved */
@@ -316,6 +325,14 @@ struct vft_req_qd {union vft_access_key ak; }; +struct vft_resp_query { +__le32 status; +__le32 entry_id; +__le16 vid;/* KEYE_DATA */ +__le16 resv; +struct vft_cfge_data cfge; +}; +/* Egress Treatment Table Request Data Buffer Format of Update and Add * actions */
include/linux/fsl/ntmp.h +15 -10
@@ -196,14 +196,19 @@ struct fdbt_entry_data {#define FDBT_ACT_FLAG BIT(7) }; -struct vft_cfge_data { -__le32 bitmap_stg; +struct vft_entry_data { +u16 vid; +u32 status;/* resume entry ID */ +u32 entry_id;/* hardware assigns entry ID */ + +/* CFGE_DATA */ +u32 bitmap_stg;#define VFT_PORT_MEMBERSHIP GENMASK(23, 0)#define VFT_STG_ID_MASK GENMASK(27, 24)#define VFT_STG_ID (g) FIELD_PREP(VFT_STG_ID_MASK, (g)) -__le16 fid; +u16 fid;#define VFT_FID GENMASK(11, 0) -__le16 cfg; +u16 cfg;#define VFT_MLO GENMASK(2, 0)#define VFT_MFO GENMASK(4, 3)#define VFT_IPMFE BIT(6)
@@ -212,9 +217,9 @@ struct vft_cfge_data {#define VFT_SFDA BIT(10)#define VFT_OSFDA BIT(11)#define VFT_FDBAFSS BIT(12) -__le32 eta_port_bitmap; +u32 eta_port_bitmap;#define VFT_ETA_PORT_BITMAP GENMASK(23, 0) -__le32 et_eid; +u32 et_eid; };struct ett_cfge_data {
@@ -300,10 +305,10 @@ int ntmp_fdbt_search_port_entry(struct ntmp_user *user, int port,int ntmp_fdbt_update_activity_element (struct ntmp_user *user);int ntmp_fdbt_delete_ageing_entries (struct ntmp_user *user,u8 act_cnt);int ntmp_fdbt_delete_port_dynamic_entries (struct ntmp_user *user,int port); -int ntmp_vft_add_entry (struct ntmp_user *user,u16 vid, -const struct vft_cfge_data *cfge); -int ntmp_vft_update_entry (struct ntmp_user *user,u16 vid, -const struct vft_cfge_data *cfge); +int ntmp_vft_add_entry (struct ntmp_user *user, +struct vft_entry_data *entry); +int ntmp_vft_update_entry (struct ntmp_user *user, +struct vft_entry_data *entry);int ntmp_vft_delete_entry (struct ntmp_user *user,u16 vid);int ntmp_ett_add_entry (struct ntmp_user *user,u32 entry_id,const struct ett_cfge_data *cfge);
Signature · 1 line
2.34.1
PATCH 6/14 net: enetc: decouple ETT logical config from hardware wire format
In reply to [email protected]From: Wei Fang <[email protected]>
Current SoCs only implement ETT version 0, but future versions may extend the table with a different buffer layout and size. Today struct ett_cfge_data is the hardware CFGE structure, 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.
Add a version-agnostic struct ett_entry_data that uses native CPU types and also carries the entry ID, and move the wire structure into ntmp_private.h to keep it internal to the NTMP layer. Add a struct ntmp_tbl_ops instance holding the buffer size and a pack() callback, and select it via ntmp_get_ett_ops(), following the MAFT, IPFT, FDBT and VFT tables.
Reshape the ETT interface around the logical config. ntmp_ett_add_entry() and ntmp_ett_update_entry() now take a struct ett_entry_data pointer instead of an entry ID and a separate cfge pointer.
A future version can then be added within the NTMP layer by providing its wire structure, pack helper and ops instance. Callers may still need small adjustments, but they no longer deal with the wire format or endianness.
--- drivers/net/dsa/netc/netc_main.c | 23 +++--- drivers/net/ethernet/freescale/enetc/ntmp.c | 80 ++++++++++++++----- .../ethernet/freescale/enetc/ntmp_private.h | 9 +++ include/linux/fsl/ntmp.h | 23 +++--- 4 files changed, 92 insertions(+), 43 deletions(-)
drivers/net/dsa/netc/netc_main.c +12 -11
@@ -1251,16 +1251,17 @@ static void netc_switch_get_ip_revision(struct netc_switch *priv) priv->revision =FIELD_GET (IPBRR0_IP_REV , val); } -static void netc_init_ett_cfge (struct ett_cfge_data *cfge, -bool untagged,u32 ect_eid) +static void netc_init_ett_entry (struct ett_entry_data *entry,bool untagged, +u32 ett_eid,u32 ect_eid) {u32 vuda_sqta =FMTEID_VUDA_SQTA ;u16 efm_cfg =0 ; + entry->entry_id = ett_eid;if (ect_eid !=NTMP_NULL_ENTRY_ID ) {/* Increase egress frame counter */ efm_cfg |=FIELD_PREP (ETT_ECA ,ETT_ECA_INC ); - cfge->ec_eid =cpu_to_le32 (ect_eid); + entry->ec_eid = ect_eid; }/* If egress rule is VLAN untagged */
@@ -1272,30 +1273,30 @@ static void netc_init_ett_cfge(struct ett_cfge_data *cfge, ETT_FRM_LEN_DEL_VLAN); } - cfge->efm_eid =cpu_to_le32 (vuda_sqta); - cfge->efm_cfg =cpu_to_le16 (efm_cfg); + entry->efm_eid = vuda_sqta; + entry->efm_cfg = efm_cfg; }static int netc_add_ett_entry (struct netc_switch *priv,bool untagged,u32 ett_eid,u32 ect_eid) {struct ntmp_user *ntmp = &priv->ntmp; -struct ett_cfge_data cfge = {}; +struct ett_entry_data entry = {}; -netc_init_ett_cfge (&cfge, untagged, ect_eid); +netc_init_ett_entry (&entry, untagged, ett_eid, ect_eid); -return ntmp_ett_add_entry (ntmp, ett_eid, &cfge); +return ntmp_ett_add_entry (ntmp, &entry); }static int netc_update_ett_entry (struct netc_switch *priv,bool untagged,u32 ett_eid,u32 ect_eid) {struct ntmp_user *ntmp = &priv->ntmp; -struct ett_cfge_data cfge = {}; +struct ett_entry_data entry = {}; -netc_init_ett_cfge (&cfge, untagged, ect_eid); +netc_init_ett_entry (&entry, untagged, ett_eid, ect_eid); -return ntmp_ett_update_entry (ntmp, ett_eid, &cfge); +return ntmp_ett_update_entry (ntmp, &entry); } static int netc_add_ett_group_entries(struct netc_switch *priv,
drivers/net/ethernet/freescale/enetc/ntmp.c +58 -22
138 lines not on this page · raw message
drivers/net/ethernet/freescale/enetc/ntmp_private.h +9 -0
@@ -333,6 +333,15 @@ struct vft_resp_query {struct vft_cfge_data cfge; }; +/* Egress Treatment Table Configuration Element Data */ +struct ett_cfge_data { +__le16 efm_cfg; +__le16 efm_data_len; +__le32 efm_eid; +__le32 ec_eid; +__le32 esqa_tgt_eid; +}; +/* Egress Treatment Table Request Data Buffer Format of Update and Add * actions */
include/linux/fsl/ntmp.h +13 -10
@@ -222,8 +222,11 @@ struct vft_entry_data {u32 et_eid; }; -struct ett_cfge_data { -__le16 efm_cfg; +struct ett_entry_data { +u32 entry_id; + +/* CFGE_DATA */ +u16 efm_cfg;#define ETT_EFM_MODE GENMASK(1, 0)#define ETT_ESQA GENMASK(5, 4)#define ETT_ECA GENMASK(8, 6)
@@ -232,11 +235,11 @@ struct ett_cfge_data {#define ETT_FRM_LEN_DEL_VLAN 0x7c#define ETT_FRM_LEN_DEL_RTAG 0x7a#define ETT_FRM_LEN_DEL_VLAN_RTAG 0x76 -__le16 efm_data_len; +u16 efm_data_len;#define ETT_EFM_DATA_LEN GENMASK(10, 0) -__le32 efm_eid; -__le32 ec_eid; -__le32 esqa_tgt_eid; +u32 efm_eid; +u32 ec_eid; +u32 esqa_tgt_eid; };struct bpt_bpse_data {
@@ -310,10 +313,10 @@ int ntmp_vft_add_entry(struct ntmp_user *user,int ntmp_vft_update_entry (struct ntmp_user *user,struct vft_entry_data *entry);int ntmp_vft_delete_entry (struct ntmp_user *user,u16 vid); -int ntmp_ett_add_entry (struct ntmp_user *user,u32 entry_id, -const struct ett_cfge_data *cfge); -int ntmp_ett_update_entry (struct ntmp_user *user,u32 entry_id, -const struct ett_cfge_data *cfge); +int ntmp_ett_add_entry (struct ntmp_user *user, +const struct ett_entry_data *entry); +int ntmp_ett_update_entry (struct ntmp_user *user, +const struct ett_entry_data *entry);int ntmp_ett_delete_entry (struct ntmp_user *user,u32 entry_id);int ntmp_ect_update_entry (struct ntmp_user *user,u32 entry_id); int ntmp_bpt_update_entry(struct ntmp_user *user, u32 entry_id,
Signature · 1 line
2.34.1
PATCH 7/14 net: enetc: decouple BPT logical config from hardware wire format
In reply to [email protected]From: Wei Fang <[email protected]>
Current SoCs only implement BPT version 0, but future versions may extend the table with a different buffer layout and size. Today struct bpt_cfge_data and struct bpt_bpse_data are the hardware CFGE and BPSE structures, 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.
Add a version-agnostic struct bpt_entry_data that uses native CPU types and also carries the entry ID, and move the wire structures into ntmp_private.h to keep them internal to the NTMP layer. Add a struct ntmp_tbl_ops instance holding the buffer size and a pack() callback, and select it via ntmp_get_bpt_ops(), following the other NTMP tables.
Reshape the BPT interface around the logical config. ntmp_bpt_update_entry() now takes a struct bpt_entry_data pointer instead of an entry ID and a separate cfge pointer, and the driver caches struct bpt_entry_data.
A future version can then be added within the NTMP layer by providing its wire structures, pack helper and ops instance. Callers may still need small adjustments, but they no longer deal with the wire format or endianness.
--- drivers/net/dsa/netc/netc_main.c | 34 ++++++----- drivers/net/dsa/netc/netc_switch.h | 2 +- drivers/net/ethernet/freescale/enetc/ntmp.c | 59 +++++++++++++++---- .../ethernet/freescale/enetc/ntmp_private.h | 20 +++++++ include/linux/fsl/ntmp.h | 35 +++++------ 5 files changed, 106 insertions(+), 44 deletions(-)
drivers/net/dsa/netc/netc_main.c +18 -16
@@ -958,10 +958,11 @@ static int netc_switch_bpt_default_config(struct netc_switch *priv)/* Initialize the maximum threshold of each buffer pool entry */ for (int i =0 ; i < priv->num_bp; i++) { -struct bpt_cfge_data *cfge = &priv->bpt_list[i]; +struct bpt_entry_data *entry = &priv->bpt_list[i]; - cfge->max_thresh =cpu_to_le16 (NETC_BP_THRESH ); - err =ntmp_bpt_update_entry (&priv->ntmp, i, cfge); + entry->entry_id = i; + entry->max_thresh =NETC_BP_THRESH ; + err =ntmp_bpt_update_entry (&priv->ntmp, entry);if (err) goto free_bpt_list; }
@@ -2395,24 +2396,25 @@ static void netc_port_set_tx_pause(struct netc_port *np, bool tx_pause) num_bp = priv->num_bp / priv->info->num_ports;for (i =0 , j = port * num_bp; i < num_bp; i++, j++) { -struct bpt_cfge_data *cfge = &priv->bpt_list[j]; -struct bpt_cfge_data old_cfge = *cfge; +struct bpt_entry_data *entry = &priv->bpt_list[j]; +struct bpt_entry_data old_entry = *entry;if (tx_pause) { - cfge->fc_on_thresh =cpu_to_le16 (NETC_FC_THRESH_ON ); - cfge->fc_off_thresh =cpu_to_le16 (NETC_FC_THRESH_OFF ); - cfge->fccfg_sbpen =FIELD_PREP (BPT_FC_CFG , -BPT_FC_CFG_EN_BPFC ); - cfge->fc_ports =cpu_to_le32 (BIT (port)); + entry->fc_on_thresh =NETC_FC_THRESH_ON ; + entry->fc_off_thresh =NETC_FC_THRESH_OFF ; + entry->fccfg_sbpen =FIELD_PREP (BPT_FC_CFG , +BPT_FC_CFG_EN_BPFC ); + entry->fc_ports =BIT (port); }else { - cfge->fc_on_thresh =cpu_to_le16 (0 ); - cfge->fc_off_thresh =cpu_to_le16 (0 ); - cfge->fccfg_sbpen =0 ; - cfge->fc_ports =cpu_to_le32 (0 ); + entry->fc_on_thresh =0 ; + entry->fc_off_thresh =0 ; + entry->fccfg_sbpen =0 ; + entry->fc_ports =0 ; } -if (ntmp_bpt_update_entry (&priv->ntmp, j, cfge)) { - *cfge = old_cfge; + entry->entry_id = j; +if (ntmp_bpt_update_entry (&priv->ntmp, entry)) { + *entry = old_entry;dev_warn (priv->dev,"Failed to %s TX pause of buffer pool %d (swp%d)\n" , tx_pause ?"enable" :"disable" , j, port);
drivers/net/dsa/netc/netc_switch.h +1 -1
@@ -178,7 +178,7 @@ struct netc_switch {u32 htmcapr_num_words;u32 num_bp; -struct bpt_cfge_data *bpt_list; +struct bpt_entry_data *bpt_list;struct pci_dev *tmr_dev;/* The PTP Timer PCI device */ };
drivers/net/ethernet/freescale/enetc/ntmp.c +49 -10
89 lines not on this page · raw message
drivers/net/ethernet/freescale/enetc/ntmp_private.h +20 -0
@@ -350,6 +350,26 @@ struct ett_req_ua {struct ett_cfge_data cfge; }; +/* Buffer Pool Table Statistics Element Data */ +struct bpt_bpse_data { +__le32 amount_used; +__le32 amount_used_hwm; +u8 bpd_fc_state; +} __packed; + +/* Buffer Pool Table Configuration Element Data */ +struct bpt_cfge_data { +u8 fccfg_sbpen; +u8 pfc_vector; +__le16 max_thresh; +__le16 fc_on_thresh; +__le16 fc_off_thresh; +__le16 sbp_thresh; +__le16 resv; +__le32 sbp_eid; +__le32 fc_ports; +}; +/* Buffer Pool Table Request Data Buffer Format of Update action */ struct bpt_req_update {struct ntmp_req_by_eid rbe;
include/linux/fsl/ntmp.h +18 -17
@@ -242,26 +242,27 @@ struct ett_entry_data {u32 esqa_tgt_eid; }; -struct bpt_bpse_data { -__le32 amount_used; -__le32 amount_used_hwm; -u8 bpd_fc_state; -#define BPT_FC_STATE BIT(0) -#define BPT_BPD BIT(1) -} __packed; +struct bpt_entry_data { +u32 entry_id; -struct bpt_cfge_data { +/* CFGE_DATA */ u8 fccfg_sbpen;#define BPT_FC_CFG GENMASK(2, 1)#define BPT_FC_CFG_EN_BPFC 1u8 pfc_vector; -__le16 max_thresh; -__le16 fc_on_thresh; -__le16 fc_off_thresh; -__le16 sbp_thresh; -__le16 resv; -__le32 sbp_eid; -__le32 fc_ports; +u16 max_thresh; +u16 fc_on_thresh; +u16 fc_off_thresh; +u16 sbp_thresh; +u32 sbp_eid; +u32 fc_ports; + +/* BPSE_DATA */ +u32 amount_used; +u32 amount_used_hwm; +u8 bpd_fc_state; +#define BPT_FC_STATE BIT(0) +#define BPT_BPD BIT(1) };union ntmp_fmt_eid {
@@ -319,8 +320,8 @@ int ntmp_ett_update_entry(struct ntmp_user *user, const struct ett_entry_data *entry);int ntmp_ett_delete_entry (struct ntmp_user *user,u32 entry_id);int ntmp_ect_update_entry (struct ntmp_user *user,u32 entry_id); -int ntmp_bpt_update_entry (struct ntmp_user *user,u32 entry_id, -const struct bpt_cfge_data *cfge); +int ntmp_bpt_update_entry (struct ntmp_user *user, +struct bpt_entry_data *entry);#else static inline int ntmp_init_cbdr (struct netc_cbdr *cbdr,struct device *dev,const struct netc_cbdr_regs *regs)
Signature · 1 line
2.34.1
PATCH 8/14 net: enetc: add generic ntmp_add_entry_by_id() helper
In reply to [email protected]From: Wei Fang <[email protected]>
Some NTMP tables have their entry IDs allocated by software, and adding a new entry to them follows the same logic: look up the table ops, allocate the request buffer, fill the common request data and header, then issue the add command over a CBDR. Adding such a table today means duplicating this boilerplate.
Introduce ntmp_add_entry_by_id() to factor out this common logic, along with ntmp_table_ops() to select the table ops by table ID. The update actions are passed in so callers can request the needed element updates.
Convert the MAFT and ETT add paths to use the new helper. More tables will reuse it later.
--- drivers/net/ethernet/freescale/enetc/ntmp.c | 182 +++++++++++--------- 1 file changed, 96 insertions(+), 86 deletions(-)
drivers/net/ethernet/freescale/enetc/ntmp.c +96 -86
@@ -640,6 +640,76 @@ static const struct ntmp_tbl_ops *ntmp_get_bpt_ops(u8 version) } } +static const struct ntmp_tbl_ops *ntmp_table_ops (int tbl_id,u8 version) +{ +switch (tbl_id) { +case NTMP_MAFT_ID : +return ntmp_get_maft_ops (version); +case NTMP_IPFT_ID : +return ntmp_get_ipft_ops (version); +case NTMP_FDBT_ID : +return ntmp_get_fdbt_ops (version); +case NTMP_VFT_ID : +return ntmp_get_vft_ops (version); +case NTMP_ETT_ID : +return ntmp_get_ett_ops (version); +case NTMP_BPT_ID : +return ntmp_get_bpt_ops (version); +default : +return NULL ; + } +} + +/** +* ntmp_add_entry_by_id - add a new entry to a table whose entry ID is +* allocated by software +* @user: target ntmp_user struct +* @tbl_id: ID of the target table +* @entry_id: the software-allocated entry ID +* @entry: the logical entry data to be packed into the request buffer +* @ua: update actions applied to the entry, 0 if none +* +* A generic helper for tables that add a new entry with a software-allocated +* entry ID. It looks up the table ops for the current version, allocates the +* request buffer, packs the entry data and issues the add command over a CBDR. +* +* Return: 0 on success, otherwise a negative error code +*/ +static int ntmp_add_entry_by_id (struct ntmp_user *user,int tbl_id, +u32 entry_id,void *entry,u16 ua) +{ +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; +int err; + + ops =ntmp_table_ops (tbl_id, version); +if (!ops) +return -EOPNOTSUPP ; + + swcbd.size = ops->req_ua_len; + err =ntmp_alloc_data_mem (user->dev, &swcbd, &buf); +if (err) +return err; + +ntmp_fill_crd_eid (buf, version,0 , ua, entry_id); + ops->pack (entry, buf,NTMP_AM_ENTRY_ID ); +ntmp_fill_request_hdr (&cbd, swcbd.dma,NTMP_LEN (ops->req_ua_len,0 ), + tbl_id,NTMP_CMD_ADD ,NTMP_AM_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 %s entry 0x%x, err: %pe\n" , +ntmp_table_name (tbl_id), entry_id,ERR_PTR (err)); +ntmp_unlock_cbdr (cbdr); + +return err; +} +static int ntmp_delete_entry_by_id (struct ntmp_user *user,int tbl_id,u32 entry_id,u32 req_len,u32 resp_len) {
@@ -716,39 +786,8 @@ static int ntmp_query_entry_by_id(struct netc_cbdr *cbdr, int tbl_id,int ntmp_maft_add_entry (struct ntmp_user *user,struct maft_entry_data *entry) { -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; - - 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 (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 ); - -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 0x%x, err: %pe\n" , -ntmp_table_name (NTMP_MAFT_ID ), entry->entry_id, -ERR_PTR (err)); -ntmp_unlock_cbdr (cbdr); - -return err; +return ntmp_add_entry_by_id (user,NTMP_MAFT_ID , entry->entry_id, + (void *)entry,0 ); }EXPORT_SYMBOL_GPL (ntmp_maft_add_entry);
@@ -1460,17 +1499,32 @@ int ntmp_vft_delete_entry(struct ntmp_user *user, u16 vid)EXPORT_SYMBOL_GPL (ntmp_vft_delete_entry);/** -* ntmp_ett_set_entry - add a new entry to the egress treatment table or -* update the configuration element data of the specified entry +* ntmp_ett_add_entry - add a new entry to the egress treatment table * @user: target ntmp_user struct -* @cmd: command type, NTMP_CMD_ADD or NTMP_CMD_UPDATE -* @entry: the entry data, entry->entry_id selects the entry and the +* @entry: the entry data, entry->entry_id is the entry ID and the * configuration element data provides the values * * Return: 0 on success, otherwise a negative error code */ -static int ntmp_ett_set_entry (struct ntmp_user *user,int cmd, -const struct ett_entry_data *entry) +int ntmp_ett_add_entry (struct ntmp_user *user, +const struct ett_entry_data *entry) +{ +return ntmp_add_entry_by_id (user,NTMP_ETT_ID , entry->entry_id, + (void *)entry,NTMP_GEN_UA_CFGEU ); +} +EXPORT_SYMBOL_GPL (ntmp_ett_add_entry); + +/** +* ntmp_ett_update_entry - update the configuration element data of the +* specified entry +* @user: target ntmp_user struct +* @entry: the entry data, entry->entry_id selects the entry and the +* configuration element data provides the new values +* +* Return: 0 on success, otherwise a negative error code +*/ +int ntmp_ett_update_entry (struct ntmp_user *user, +const struct ett_entry_data *entry) {u8 version = user->tbl_ver[NTMP_ETT_ID ];const struct ntmp_tbl_ops *ops;
@@ -1480,9 +1534,6 @@ static int ntmp_ett_set_entry(struct ntmp_user *user, int cmd,void *buf;int err; -if (cmd !=NTMP_CMD_ADD && cmd !=NTMP_CMD_UPDATE ) -return -EINVAL ; - ops =ntmp_get_ett_ops (version);if (!ops)return -EOPNOTSUPP ;
@@ -1499,59 +1550,18 @@ static int ntmp_ett_set_entry(struct ntmp_user *user, int cmd,/* Request header */ ntmp_fill_request_hdr (&cbd, swcbd.dma,NTMP_LEN (swcbd.size,0 ), -NTMP_ETT_ID , cmd,NTMP_AM_ENTRY_ID ); +NTMP_ETT_ID ,NTMP_CMD_UPDATE ,NTMP_AM_ENTRY_ID );ntmp_select_and_lock_cbdr (user, &cbdr); err =netc_xmit_ntmp_cmd (cbdr, &cbd, &swcbd); -ntmp_unlock_cbdr (cbdr); - -return err; -} - -/** -* ntmp_ett_add_entry - add a new entry to the egress treatment table -* @user: target ntmp_user struct -* @entry: the entry data, entry->entry_id is the entry ID and the -* configuration element data provides the values -* -* Return: 0 on success, otherwise a negative error code -*/ -int ntmp_ett_add_entry (struct ntmp_user *user, -const struct ett_entry_data *entry) -{ -int err; - - err =ntmp_ett_set_entry (user,NTMP_CMD_ADD , entry); -if (err) -dev_err (user->dev,"Failed to add %s entry 0x%x, err: %pe\n" , -ntmp_table_name (NTMP_ETT_ID ), entry->entry_id, -ERR_PTR (err)); - -return err; -} -EXPORT_SYMBOL_GPL (ntmp_ett_add_entry); - -/** -* ntmp_ett_update_entry - update the configuration element data of the -* specified entry -* @user: target ntmp_user struct -* @entry: the entry data, entry->entry_id selects the entry and the -* configuration element data provides the new values -* -* Return: 0 on success, otherwise a negative error code -*/ -int ntmp_ett_update_entry (struct ntmp_user *user, -const struct ett_entry_data *entry) -{ -int err; - - err =ntmp_ett_set_entry (user,NTMP_CMD_UPDATE , entry);if (err)dev_err (user->dev,"Failed to update %s entry 0x%x, err: %pe\n" ,ntmp_table_name (NTMP_ETT_ID ), entry->entry_id,ERR_PTR (err)); +ntmp_unlock_cbdr (cbdr); +return err; }EXPORT_SYMBOL_GPL (ntmp_ett_update_entry);
Signature · 1 line
2.34.1
PATCH 9/14 net: enetc: simplify callers of ntmp_query_entry_by_id()
In reply to [email protected]From: Wei Fang <[email protected]>
Most NTMP tables can query an entry by its entry ID, and they follow the same logic. The current ntmp_query_entry_by_id() still leaves the table ops lookup, buffer allocation, request filling, CBDR locking and response unpacking to each caller, so every query wrapper duplicates that boilerplate.
Move this common handling into ntmp_query_entry_by_id() and take the user, table ID, entry ID and entry data directly, so a caller only needs a single call. The response entry ID is now read from the first field of the response buffer, which lets the one-field struct ntmp_cmn_resp_query be dropped.
Convert the MAFT query path to the reworked helper. More tables will reuse it later.
--- drivers/net/ethernet/freescale/enetc/ntmp.c | 105 ++++++++++-------- .../ethernet/freescale/enetc/ntmp_private.h | 4 - 2 files changed, 56 insertions(+), 53 deletions(-)
drivers/net/ethernet/freescale/enetc/ntmp.c +56 -49
@@ -740,48 +740,82 @@ static int ntmp_delete_entry_by_id(struct ntmp_user *user, int tbl_id,return err; } -static int ntmp_query_entry_by_id (struct netc_cbdr *cbdr,int tbl_id, -struct ntmp_req_by_eid *req, -struct netc_swcbd *swcbd, +/** +* ntmp_query_entry_by_id - query an entry of a table by its entry ID +* @user: target ntmp_user struct +* @tbl_id: ID of the target table +* @entry_id: the entry ID to query +* @entry: used to store the queried entry data +* @ua: update actions, some tables support resetting the statistics +* after the query, in which case the caller passes the update actions, +* otherwise 0 +* @compare_eid: whether to compare the queried entry ID against the +* entry ID returned by the hardware. Only a table whose response data +* starts with the entry_id field can set this. +* +* Return: 0 on success, otherwise a negative error code +*/ +static int ntmp_query_entry_by_id (struct ntmp_user *user,int tbl_id, +u32 entry_id,void *entry,u16 ua,bool compare_eid) { -u32 len =NTMP_LEN (sizeof (*req), swcbd->size); -struct ntmp_cmn_resp_query *resp; -int cmd =NTMP_CMD_QUERY ; +u32 req_len =sizeof (struct ntmp_req_by_eid ); +int cmd = ua ?NTMP_CMD_QU :NTMP_CMD_QUERY ; +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; -u32 entry_id; +__le32 *resp_eid; +void *buf; +u32 len;int err; - entry_id =le32_to_cpu (req->entry_id); -if (le16_to_cpu (req->crd.update_act)) - cmd =NTMP_CMD_QU ; + ops =ntmp_table_ops (tbl_id, version); +if (!ops) +return -EOPNOTSUPP ; + + swcbd.size =max (req_len, ops->resp_query_len); + err =ntmp_alloc_data_mem (user->dev, &swcbd, &buf); +if (err) +return err; -/* Request header */ -ntmp_fill_request_hdr (&cbd, swcbd->dma, len, tbl_id, cmd, + len =NTMP_LEN (req_len, ops->resp_query_len); +ntmp_fill_crd_eid (buf, version,0 , ua, entry_id); +ntmp_fill_request_hdr (&cbd, swcbd.dma, len, tbl_id, cmd,NTMP_AM_ENTRY_ID ); - err =netc_xmit_ntmp_cmd (cbdr, &cbd, swcbd); + +ntmp_select_and_lock_cbdr (user, &cbdr); + err =netc_xmit_ntmp_cmd (cbdr, &cbd, &swcbd);if (err) {dev_err (cbdr->dev,"Failed to query entry 0x%x of %s, err: %pe\n" , entry_id,ntmp_table_name (tbl_id),ERR_PTR (err)); -return err; + goto unlock_cbdr; }/* For a few tables, the first field of their response data is not * entry_id, so directly return success. */ if (!compare_eid) -return 0 ; + goto unpack_resp_data; - resp = (struct ntmp_cmn_resp_query *)req; -if (unlikely (le32_to_cpu (resp->entry_id) != entry_id)) { + resp_eid = buf; +if (unlikely (le32_to_cpu (*resp_eid) != entry_id)) {dev_err (cbdr->dev,"%s: query EID 0x%x doesn't match response EID 0x%x\n" , -ntmp_table_name (tbl_id), entry_id,le32_to_cpu (resp->entry_id)); -return -EIO ; +ntmp_table_name (tbl_id), entry_id, +le32_to_cpu (*resp_eid)); + err = -EIO ; + goto unlock_cbdr; } -return 0 ; +unpack_resp_data: + ops->unpack (buf, entry, false); +unlock_cbdr: +ntmp_unlock_cbdr (cbdr); + +return err; }int ntmp_maft_add_entry (struct ntmp_user *user,struct maft_entry_data *entry)
@@ -794,35 +828,8 @@ EXPORT_SYMBOL_GPL(ntmp_maft_add_entry);int ntmp_maft_query_entry (struct ntmp_user *user,struct maft_entry_data *entry) { -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; - - 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 (buf, version,0 ,0 , entry->entry_id); - -ntmp_select_and_lock_cbdr (user, &cbdr); - err =ntmp_query_entry_by_id (cbdr,NTMP_MAFT_ID , buf, &swcbd, true); -if (err) - goto unlock_cbdr; - - ops->unpack (buf, entry, false); - -unlock_cbdr: -ntmp_unlock_cbdr (cbdr); - -return err; +return ntmp_query_entry_by_id (user,NTMP_MAFT_ID , entry->entry_id, + (void *)entry,0 , true); }EXPORT_SYMBOL_GPL (ntmp_maft_query_entry);
drivers/net/ethernet/freescale/enetc/ntmp_private.h +0 -4
@@ -69,10 +69,6 @@ struct ntmp_cmn_req_data { ((a) & NTMP_QUERY_ACT)) }; -struct ntmp_cmn_resp_query { -__le32 entry_id; -}; -/* Generic structure for request data by entry ID */ struct ntmp_req_by_eid {struct ntmp_cmn_req_data crd;
Signature · 1 line
2.34.1
PATCH 10/14 net: enetc: add kernel-doc for ntmp_delete_entry_by_id()
In reply to [email protected]From: Wei Fang <[email protected]>
The other generic by-ID helpers already have kernel-doc, while ntmp_delete_entry_by_id() does not. Add its kernel-doc to keep the documentation of these helpers consistent.
--- drivers/net/ethernet/freescale/enetc/ntmp.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
drivers/net/ethernet/freescale/enetc/ntmp.c +10 -0
@@ -710,6 +710,16 @@ static int ntmp_add_entry_by_id(struct ntmp_user *user, int tbl_id,return err; } +/** +* ntmp_delete_entry_by_id - delete an entry of a table by its entry ID +* @user: target ntmp_user struct +* @tbl_id: ID of the target table +* @entry_id: the entry ID to delete +* @req_len: length of the request data buffer +* @resp_len: length of the response data buffer +* +* Return: 0 on success, otherwise a negative error code +*/ static int ntmp_delete_entry_by_id (struct ntmp_user *user,int tbl_id,u32 entry_id,u32 req_len,u32 resp_len) {
Signature · 1 line
2.34.1
PATCH 11/14 net: enetc: add a generic helper to update an NTMP entry by entry ID
In reply to [email protected]From: Wei Fang <[email protected]>
Several NTMP tables implement their own update-by-entry-ID routine, and ntmp_fdbt_update_entry(), ntmp_ett_update_entry() and ntmp_bpt_update_entry() all repeat the same sequence: look up the table ops, allocate the request buffer, fill the CRD and entry ID, pack the config, build the request header and issue the command.
Add a generic ntmp_update_entry_by_id() helper that carries this common flow and takes the per-table specifics, entry ID, update actions and response length, as arguments. Convert the FDBT, ETT and BPT update functions to call it. This removes the duplicated boilerplate and keeps future table update paths consistent.
--- drivers/net/ethernet/freescale/enetc/ntmp.c | 174 +++++++------------- 1 file changed, 63 insertions(+), 111 deletions(-)
drivers/net/ethernet/freescale/enetc/ntmp.c +63 -111
@@ -710,6 +710,61 @@ static int ntmp_add_entry_by_id(struct ntmp_user *user, int tbl_id,return err; } +/** +* ntmp_update_entry_by_id - update an entry of a table by its entry ID +* @user: target ntmp_user struct +* @tbl_id: ID of the target table +* @entry_id: the entry ID to update +* @entry: the logical entry data to be packed into the request buffer +* @ua: update actions applied to the entry, 0 if none +* @resp_len: length of the response data buffer, 0 if none +* +* A generic helper for tables that update an entry by its entry ID. It looks +* up the table ops for the current version, allocates the request buffer, +* packs the entry data and issues the update command over a CBDR. +* +* Return: 0 on success, otherwise a negative error code +*/ +static int ntmp_update_entry_by_id (struct ntmp_user *user,int tbl_id, +u32 entry_id,void *entry,u16 ua, +u32 resp_len) +{ +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, resp_len); + err =ntmp_alloc_data_mem (user->dev, &swcbd, &buf); +if (err) +return err; + +ntmp_fill_crd_eid (buf, version,0 , ua, entry_id); + ops->pack (entry, buf,NTMP_AM_ENTRY_ID ); + + len =NTMP_LEN (ops->req_ua_len, resp_len); +ntmp_fill_request_hdr (&cbd, swcbd.dma, len, tbl_id, +NTMP_CMD_UPDATE ,NTMP_AM_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 update %s entry 0x%x, err: %pe\n" , +ntmp_table_name (tbl_id), entry_id,ERR_PTR (err)); +ntmp_unlock_cbdr (cbdr); + +return err; +} +/** * ntmp_delete_entry_by_id - delete an entry of a table by its entry ID * @user: target ntmp_user struct
@@ -1081,42 +1136,9 @@ EXPORT_SYMBOL_GPL(ntmp_fdbt_add_entry);int ntmp_fdbt_update_entry (struct ntmp_user *user,const 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 = ops->req_ua_len; - err =ntmp_alloc_data_mem (user->dev, &swcbd, &buf); -if (err) -return err; - -/* Request data */ -ntmp_fill_crd (buf, version,0 ,NTMP_GEN_UA_CFGEU ); - ops->pack (entry, buf,NTMP_AM_ENTRY_ID ); - -/* Request header */ - len =NTMP_LEN (ops->req_ua_len,NTMP_STATUS_RESP_LEN ); -ntmp_fill_request_hdr (&cbd, swcbd.dma, len,NTMP_FDBT_ID , -NTMP_CMD_UPDATE ,NTMP_AM_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 update %s entry, err: %pe\n" , -ntmp_table_name (NTMP_FDBT_ID ),ERR_PTR (err)); - -ntmp_unlock_cbdr (cbdr); - -return err; +return ntmp_update_entry_by_id (user,NTMP_FDBT_ID , entry->entry_id, + (void *)entry,NTMP_GEN_UA_CFGEU , +NTMP_STATUS_RESP_LEN ); }EXPORT_SYMBOL_GPL (ntmp_fdbt_update_entry);
@@ -1543,43 +1565,8 @@ EXPORT_SYMBOL_GPL(ntmp_ett_add_entry);int ntmp_ett_update_entry (struct ntmp_user *user,const struct ett_entry_data *entry) { -u8 version = user->tbl_ver[NTMP_ETT_ID ]; -const struct ntmp_tbl_ops *ops; -struct netc_swcbd swcbd; -struct netc_cbdr *cbdr; -union netc_cbd cbd; -void *buf; -int err; - - ops =ntmp_get_ett_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; - -/* Request data */ -ntmp_fill_crd_eid (buf, version,0 ,NTMP_GEN_UA_CFGEU , - entry->entry_id); - ops->pack (entry, buf,0 ); - -/* Request header */ -ntmp_fill_request_hdr (&cbd, swcbd.dma,NTMP_LEN (swcbd.size,0 ), -NTMP_ETT_ID ,NTMP_CMD_UPDATE ,NTMP_AM_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 update %s entry 0x%x, err: %pe\n" , -ntmp_table_name (NTMP_ETT_ID ), entry->entry_id, -ERR_PTR (err)); - -ntmp_unlock_cbdr (cbdr); - -return err; +return ntmp_update_entry_by_id (user,NTMP_ETT_ID , entry->entry_id, + (void *)entry,NTMP_GEN_UA_CFGEU ,0 ); }EXPORT_SYMBOL_GPL (ntmp_ett_update_entry);
@@ -1642,44 +1629,9 @@ EXPORT_SYMBOL_GPL(ntmp_ect_update_entry);int ntmp_bpt_update_entry (struct ntmp_user *user,struct bpt_entry_data *entry) { -u8 version = user->tbl_ver[NTMP_BPT_ID ]; -const struct ntmp_tbl_ops *ops; -struct netc_swcbd swcbd; -struct netc_cbdr *cbdr; -union netc_cbd cbd; -void *buf; -int err; - - ops =ntmp_get_bpt_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; - -/* Note that BPT_UA_BPSEU is used to update the BPSE_DATA of the entry, -* which is maintained by the hardware. The BPSE_DATA is not present in -* the request data for 'Update' operation. -*/ -ntmp_fill_crd_eid (buf, version,0 ,NTMP_GEN_UA_CFGEU |BPT_UA_BPSEU , - entry->entry_id); - ops->pack (entry, buf,0 ); -ntmp_fill_request_hdr (&cbd, swcbd.dma,NTMP_LEN (ops->req_ua_len,0 ), -NTMP_BPT_ID ,NTMP_CMD_UPDATE ,NTMP_AM_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 update %s entry 0x%x, err: %pe\n" , -ntmp_table_name (NTMP_BPT_ID ), entry->entry_id, -ERR_PTR (err)); - -ntmp_unlock_cbdr (cbdr); - -return err; +return ntmp_update_entry_by_id (user,NTMP_BPT_ID , entry->entry_id, + (void *)entry,NTMP_GEN_UA_CFGEU | +BPT_UA_BPSEU ,0 ); }EXPORT_SYMBOL_GPL (ntmp_bpt_update_entry);
Signature · 1 line
2.34.1
PATCH 12/14 net: enetc: convert ntmp_ect_update_entry() to the generic update helper
In reply to [email protected]From: Wei Fang <[email protected]>
ntmp_ect_update_entry() still open-codes the update sequence while the other tables now route through ntmp_update_entry_by_id(). To let the Egress Count Table (ECT) reuse the generic helper, it needs a table ops instance.
Add ect_ops_v0 and register it in ntmp_table_ops(). The ECT is a static bounded-index table whose entries are always present, so it has no "Add" operation, and its "Update" only resets the counter with no CFGE_DATA to carry, hence its pack() callback is empty. Convert ntmp_ect_update_entry() to call ntmp_update_entry_by_id(), which removes the duplicated boilerplate.
--- drivers/net/ethernet/freescale/enetc/ntmp.c | 58 ++++++++++----------- 1 file changed, 29 insertions(+), 29 deletions(-)
drivers/net/ethernet/freescale/enetc/ntmp.c +29 -29
@@ -608,6 +608,31 @@ static const struct ntmp_tbl_ops *ntmp_get_ett_ops(u8 version) } } +static void ntmp_ect_pack_v0 (const void *entry,void *buf,int access_method) +{ +/* Egress Count table is a static bounded index table, its entries +* are always present, so it does not support "Add" operation. The +* "Update" operation only resets the counter, so there is no +* CFGE_DATA to be updated. Therefore, there's no need to pack any +* data here. +*/ +} + +static const struct ntmp_tbl_ops ect_ops_v0 = { + .req_ua_len =sizeof (struct ntmp_req_by_eid ), + .pack = ntmp_ect_pack_v0, +}; + +static const struct ntmp_tbl_ops *ntmp_get_ect_ops (u8 version) +{ +switch (version) { +case NTMP_TBL_V (0 ): +return &ect_ops_v0; +default : +return NULL ; + } +} +static void ntmp_bpt_pack_v0 (const void *entry,void *buf,int access_method) {const struct bpt_entry_data *_entry = entry;
@@ -653,6 +678,8 @@ static const struct ntmp_tbl_ops *ntmp_table_ops(int tbl_id, u8 version)return ntmp_get_vft_ops (version);case NTMP_ETT_ID :return ntmp_get_ett_ops (version); +case NTMP_ECT_ID : +return ntmp_get_ect_ops (version);case NTMP_BPT_ID :return ntmp_get_bpt_ops (version);default :
@@ -1594,35 +1621,8 @@ EXPORT_SYMBOL_GPL(ntmp_ett_delete_entry);*/ int ntmp_ect_update_entry (struct ntmp_user *user,u32 entry_id) { -struct ntmp_req_by_eid *req; -struct netc_swcbd swcbd; -struct netc_cbdr *cbdr; -union netc_cbd cbd; -int err; - - swcbd.size =sizeof (*req); - err =ntmp_alloc_data_mem (user->dev, &swcbd, (void **)&req); -if (err) -return err; - -/* Request data */ -ntmp_fill_crd_eid (req, user->tbl_ver[NTMP_ECT_ID ],0 , -ECT_UA_STSEU , entry_id); - -/* Request header */ -ntmp_fill_request_hdr (&cbd, swcbd.dma,NTMP_LEN (swcbd.size,0 ), -NTMP_ECT_ID ,NTMP_CMD_UPDATE ,NTMP_AM_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 update %s entry 0x%x, err: %pe\n" , -ntmp_table_name (NTMP_ECT_ID ), entry_id,ERR_PTR (err)); - -ntmp_unlock_cbdr (cbdr); - -return err; +return ntmp_update_entry_by_id (user,NTMP_ECT_ID , entry_id,NULL , +ECT_UA_STSEU ,0 ); }EXPORT_SYMBOL_GPL (ntmp_ect_update_entry);
Signature · 1 line
2.34.1
PATCH 13/14 net: enetc: add a generic helper to add an NTMP entry by key
In reply to [email protected]From: Wei Fang <[email protected]>
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.
--- drivers/net/ethernet/freescale/enetc/ntmp.c | 242 ++++++++------------ 1 file changed, 95 insertions(+), 147 deletions(-)
drivers/net/ethernet/freescale/enetc/ntmp.c +95 -147
@@ -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);
Signature · 1 line
2.34.1
PATCH 14/14 net: enetc: convert the RSST to the generic NTMP entry helpers
In reply to [email protected]From: Wei Fang <[email protected]>
The RSS table (RSST) still open-codes its own CBDR sequences for the update and query operations, duplicating the logic that is now provided by the generic ntmp_update_entry_by_id() and ntmp_query_entry_by_id() helpers.
Add a set of table ops for the RSST, moving the packing of the group values into the request buffer and the unpacking of the queried groups into ntmp_rsst_pack_v0() and ntmp_rsst_unpack_v0(), and register them in ntmp_table_ops(). With the ops in place, convert ntmp_rsst_update_entry() and ntmp_rsst_query_entry() into thin wrappers around the generic helpers.
--- drivers/net/ethernet/freescale/enetc/ntmp.c | 109 +++++++++----------- 1 file changed, 46 insertions(+), 63 deletions(-)
drivers/net/ethernet/freescale/enetc/ntmp.c +46 -63
@@ -347,6 +347,45 @@ static const struct ntmp_tbl_ops *ntmp_get_maft_ops(u8 version) } } +static void ntmp_rsst_pack_v0 (const void *entry,void *buf,int access_method) +{ +struct rsst_req_update *req = buf; +const u32 *table = entry; + +for (int i =0 ; i <RSST_ENTRY_NUM ; i++) + req->groups[i] = (u8)(table[i]); +} + +static void ntmp_rsst_unpack_v0 (const void *buf,void *entry,bool only_eid) +{ +const u8 *group = buf; +u32 *table = entry; + + group +=NTMP_ENTRY_ID_SIZE +RSST_STSE_DATA_SIZE (RSST_ENTRY_NUM ); +for (int i =0 ; i <RSST_ENTRY_NUM ; i++) + table[i] = group[i]; +} + +static const struct ntmp_tbl_ops rsst_ops_v0 = { + .req_ua_len =sizeof (struct ntmp_req_by_eid ) + +RSST_CFGE_DATA_SIZE (RSST_ENTRY_NUM ), + .resp_query_len =NTMP_ENTRY_ID_SIZE + +RSST_CFGE_DATA_SIZE (RSST_ENTRY_NUM ) + +RSST_STSE_DATA_SIZE (RSST_ENTRY_NUM ), + .pack = ntmp_rsst_pack_v0, + .unpack = ntmp_rsst_unpack_v0, +}; + +static const struct ntmp_tbl_ops *ntmp_get_rsst_ops (u8 version) +{ +switch (version) { +case NTMP_TBL_V (0 ): +return &rsst_ops_v0; +default : +return NULL ; + } +} +static void ntmp_ipft_pack_v0 (const void *entry,void *buf,int access_method) {const struct ipft_entry_data *e = entry;
@@ -670,6 +709,8 @@ static const struct ntmp_tbl_ops *ntmp_table_ops(int tbl_id, u8 version)switch (tbl_id) {case NTMP_MAFT_ID :return ntmp_get_maft_ops (version); +case NTMP_RSST_ID : +return ntmp_get_rsst_ops (version);case NTMP_IPFT_ID :return ntmp_get_ipft_ops (version);case NTMP_FDBT_ID :
@@ -1002,82 +1043,24 @@ EXPORT_SYMBOL_GPL(ntmp_maft_delete_entry);int ntmp_rsst_update_entry (struct ntmp_user *user,const u32 *table,int count) { -struct rsst_req_update *req; -struct netc_swcbd swcbd; -struct netc_cbdr *cbdr; -union netc_cbd cbd; -int err, i; -if (count !=RSST_ENTRY_NUM )/* HW only takes in a full 64 entry table */ return -EINVAL ; - swcbd.size =struct_size (req, groups, count); - err =ntmp_alloc_data_mem (user->dev, &swcbd, (void **)&req); -if (err) -return err; - -/* Set the request data buffer */ -ntmp_fill_crd_eid (&req->rbe, user->tbl_ver[NTMP_RSST_ID ],0 , -NTMP_GEN_UA_CFGEU |NTMP_GEN_UA_STSEU ,0 ); -for (i =0 ; i < count; i++) - req->groups[i] = (u8)(table[i]); - -ntmp_fill_request_hdr (&cbd, swcbd.dma,NTMP_LEN (swcbd.size,0 ), -NTMP_RSST_ID ,NTMP_CMD_UPDATE ,NTMP_AM_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 update RSST entry, err: %pe\n" , -ERR_PTR (err)); -ntmp_unlock_cbdr (cbdr); - -return err; +return ntmp_update_entry_by_id (user,NTMP_RSST_ID ,0 , (void *)table, +NTMP_GEN_UA_CFGEU |NTMP_GEN_UA_STSEU , +0 ); }EXPORT_SYMBOL_GPL (ntmp_rsst_update_entry);int ntmp_rsst_query_entry (struct ntmp_user *user,u32 *table,int count) { -struct ntmp_req_by_eid *req; -struct netc_swcbd swcbd; -struct netc_cbdr *cbdr; -union netc_cbd cbd; -int err, i; -u8 *group; -if (count !=RSST_ENTRY_NUM )/* HW only takes in a full 64 entry table */ return -EINVAL ; - swcbd.size =NTMP_ENTRY_ID_SIZE +RSST_STSE_DATA_SIZE (count) + -RSST_CFGE_DATA_SIZE (count); - err =ntmp_alloc_data_mem (user->dev, &swcbd, (void **)&req); -if (err) -return err; - -/* Set the request data buffer */ -ntmp_fill_crd_eid (req, user->tbl_ver[NTMP_RSST_ID ],0 ,0 ,0 ); -ntmp_fill_request_hdr (&cbd, swcbd.dma,NTMP_LEN (sizeof (*req), swcbd.size), -NTMP_RSST_ID ,NTMP_CMD_QUERY ,NTMP_AM_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 query RSST entry, err: %pe\n" , -ERR_PTR (err)); - goto unlock_cbdr; - } - - group = (u8 *)req; - group +=NTMP_ENTRY_ID_SIZE +RSST_STSE_DATA_SIZE (count); -for (i =0 ; i < count; i++) - table[i] = group[i]; - -unlock_cbdr: -ntmp_unlock_cbdr (cbdr); - -return err; +return ntmp_query_entry_by_id (user,NTMP_RSST_ID ,0 , (void *)table, +0 , false); }EXPORT_SYMBOL_GPL (ntmp_rsst_query_entry);
Signature · 1 line
2.34.1