From: Denis Pryazhennikov <denis.pryazhenni...@arknetworks.am> API allows to insert data to any supported HW table.
Signed-off-by: Denis Pryazhennikov <denis.pryazhenni...@arknetworks.am> Reviewed-by: Ivan Malov <ivan.ma...@arknetworks.am> Reviewed-by: Viacheslav Galaktionov <viacheslav.galaktio...@arknetworks.am> Reviewed-by: Andy Moreton <amore...@xilinx.com> --- drivers/common/sfc_efx/base/efx.h | 16 +++++ drivers/common/sfc_efx/base/efx_table.c | 79 +++++++++++++++++++++++++ drivers/common/sfc_efx/version.map | 1 + 3 files changed, 96 insertions(+) diff --git a/drivers/common/sfc_efx/base/efx.h b/drivers/common/sfc_efx/base/efx.h index e7988e3657..90d86c70dd 100644 --- a/drivers/common/sfc_efx/base/efx.h +++ b/drivers/common/sfc_efx/base/efx.h @@ -5152,6 +5152,22 @@ efx_table_describe( __in unsigned int n_field_descs, __out_opt unsigned int *n_field_descs_writtenp); +/* Maximum possible size of data for manipulation of the tables */ +#define EFX_TABLE_ENTRY_LENGTH_MAX 1008 + +LIBEFX_API +extern __checkReturn efx_rc_t +efx_table_entry_insert( + __in efx_nic_t *enp, + __in efx_table_id_t table_id, + __in uint16_t priority, + __in uint16_t mask_id, + __in uint16_t key_width, + __in uint16_t mask_width, + __in uint16_t resp_width, + __in_bcount(data_size) uint8_t *entry_datap, + __in unsigned int data_size); + #ifdef __cplusplus } #endif diff --git a/drivers/common/sfc_efx/base/efx_table.c b/drivers/common/sfc_efx/base/efx_table.c index c5657ddff7..6ebb92e83b 100644 --- a/drivers/common/sfc_efx/base/efx_table.c +++ b/drivers/common/sfc_efx/base/efx_table.c @@ -338,6 +338,85 @@ efx_table_describe( EFSYS_PROBE(fail6); fail5: EFSYS_PROBE(fail5); +fail4: + EFSYS_PROBE(fail4); +fail3: + EFSYS_PROBE(fail3); +fail2: + EFSYS_PROBE(fail2); +fail1: + EFSYS_PROBE1(fail1, efx_rc_t, rc); + return (rc); +} + + __checkReturn efx_rc_t +efx_table_entry_insert( + __in efx_nic_t *enp, + __in efx_table_id_t table_id, + __in uint16_t priority, + __in uint16_t mask_id, + __in uint16_t key_width, + __in uint16_t mask_width, + __in uint16_t resp_width, + __in_bcount(data_size) uint8_t *entry_datap, + __in unsigned int data_size) +{ + const efx_nic_cfg_t *encp = efx_nic_cfg_get(enp); + unsigned int n_dwords; + efx_mcdi_req_t req; + efx_rc_t rc; + EFX_MCDI_DECLARE_BUF(payload, + MC_CMD_TABLE_INSERT_IN_LENMAX_MCDI2, + MC_CMD_TABLE_INSERT_OUT_LEN); + + /* + * Ensure MCDI number of 32bit units matches EFX maximum possible + * data in bytes. + */ + EFX_STATIC_ASSERT((MC_CMD_TABLE_INSERT_IN_LENMAX * sizeof(uint32_t)) == + EFX_TABLE_ENTRY_LENGTH_MAX); + + if (encp->enc_table_api_supported == B_FALSE) { + rc = ENOTSUP; + goto fail1; + } + + if ((data_size % sizeof(uint32_t)) != 0) { + rc = EINVAL; + goto fail2; + } + + if ((data_size == 0) || (data_size > EFX_TABLE_ENTRY_LENGTH_MAX)) { + rc = EINVAL; + goto fail3; + } + + n_dwords = data_size / sizeof(uint32_t); + + req.emr_cmd = MC_CMD_TABLE_INSERT; + req.emr_in_buf = payload; + req.emr_in_length = MC_CMD_TABLE_INSERT_IN_LEN(n_dwords); + req.emr_out_buf = payload; + req.emr_out_length = MC_CMD_TABLE_INSERT_OUT_LEN; + + MCDI_IN_SET_DWORD(req, TABLE_INSERT_IN_TABLE_ID, (uint32_t)table_id); + MCDI_IN_SET_WORD(req, TABLE_INSERT_IN_PRIORITY, priority); + MCDI_IN_SET_WORD(req, TABLE_INSERT_IN_MASK_ID, mask_id); + MCDI_IN_SET_WORD(req, TABLE_INSERT_IN_KEY_WIDTH, key_width); + MCDI_IN_SET_WORD(req, TABLE_INSERT_IN_MASK_WIDTH, mask_width); + MCDI_IN_SET_WORD(req, TABLE_INSERT_IN_RESP_WIDTH, resp_width); + + memcpy(MCDI_IN2(req, uint8_t, TABLE_INSERT_IN_DATA), entry_datap, data_size); + + efx_mcdi_execute(enp, &req); + + if (req.emr_rc != 0) { + rc = req.emr_rc; + goto fail4; + } + + return (0); + fail4: EFSYS_PROBE(fail4); fail3: diff --git a/drivers/common/sfc_efx/version.map b/drivers/common/sfc_efx/version.map index a87cb1bba5..2be519e0e1 100644 --- a/drivers/common/sfc_efx/version.map +++ b/drivers/common/sfc_efx/version.map @@ -233,6 +233,7 @@ INTERNAL { efx_sram_buf_tbl_set; efx_table_describe; + efx_table_entry_insert; efx_table_is_supported; efx_table_list; efx_table_supported_num_get; -- 2.30.2