From: Wei Fang 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. Signed-off-by: Wei Fang --- drivers/net/ethernet/freescale/enetc/ntmp.c | 109 +++++++++----------- 1 file changed, 46 insertions(+), 63 deletions(-) diff --git a/drivers/net/ethernet/freescale/enetc/ntmp.c b/drivers/net/ethernet/freescale/enetc/ntmp.c index 0622e7e0b5756..1c295dc6d5059 100644 --- a/drivers/net/ethernet/freescale/enetc/ntmp.c +++ b/drivers/net/ethernet/freescale/enetc/ntmp.c @@ -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); -- 2.34.1