From: Wei Fang NTMP index tables require software to allocate and manage entry IDs. Add two bitmap helper functions to facilitate this management: ntmp_lookup_free_eid(): finds the first zero bit in the given bitmap, sets it to mark the entry as in-use, and returns the corresponding entry ID. Returns NTMP_NULL_ENTRY_ID if no free entry is available. ntmp_clear_eid_bitmap(): clears the bit associated with the given entry ID in the bitmap to mark the entry as free. It is a no-op if the entry ID is NTMP_NULL_ENTRY_ID. Both functions are exported for use by other modules, such as the NETC switch driver which needs to manage group index bitmaps for the Egress Treatment Table (ETT) and Egress Count Table (ECT). Signed-off-by: Wei Fang --- drivers/net/ethernet/freescale/enetc/ntmp.c | 24 +++++++++++++++++++++ include/linux/fsl/ntmp.h | 2 ++ 2 files changed, 26 insertions(+) diff --git a/drivers/net/ethernet/freescale/enetc/ntmp.c b/drivers/net/ethernet/freescale/enetc/ntmp.c index 601435966ed1..9f38f885ebb5 100644 --- a/drivers/net/ethernet/freescale/enetc/ntmp.c +++ b/drivers/net/ethernet/freescale/enetc/ntmp.c @@ -47,6 +47,30 @@ #define RSST_STSE_DATA_SIZE(n) ((n) * 8) #define RSST_CFGE_DATA_SIZE(n) (n) +u32 ntmp_lookup_free_eid(unsigned long *bitmap, u32 size) +{ + u32 entry_id; + + entry_id = find_first_zero_bit(bitmap, size); + if (entry_id == size) + return NTMP_NULL_ENTRY_ID; + + /* Set the bit once we found it */ + set_bit(entry_id, bitmap); + + return entry_id; +} +EXPORT_SYMBOL_GPL(ntmp_lookup_free_eid); + +void ntmp_clear_eid_bitmap(unsigned long *bitmap, u32 entry_id) +{ + if (entry_id == NTMP_NULL_ENTRY_ID) + return; + + clear_bit(entry_id, bitmap); +} +EXPORT_SYMBOL_GPL(ntmp_clear_eid_bitmap); + int ntmp_init_cbdr(struct netc_cbdr *cbdr, struct device *dev, const struct netc_cbdr_regs *regs) { diff --git a/include/linux/fsl/ntmp.h b/include/linux/fsl/ntmp.h index e8b1bd802f19..4d329488763d 100644 --- a/include/linux/fsl/ntmp.h +++ b/include/linux/fsl/ntmp.h @@ -266,6 +266,8 @@ struct bpt_cfge_data { int ntmp_init_cbdr(struct netc_cbdr *cbdr, struct device *dev, const struct netc_cbdr_regs *regs); void ntmp_free_cbdr(struct netc_cbdr *cbdr); +u32 ntmp_lookup_free_eid(unsigned long *bitmap, u32 size); +void ntmp_clear_eid_bitmap(unsigned long *bitmap, u32 entry_id); /* NTMP APIs */ int ntmp_maft_add_entry(struct ntmp_user *user, u32 entry_id, -- 2.34.1