1 /* SPDX-License-Identifier: BSD-3-Clause 2 * 3 * Copyright (c) 2023 Advanced Micro Devices, Inc. 4 */ 5 6 #include "sfc.h" 7 #include "sfc_tbl_meta.h" 8 #include "sfc_tbl_meta_cache.h" 9 10 const struct sfc_tbl_meta * sfc_tbl_meta_lookup(struct sfc_adapter * sa,efx_table_id_t table_id)11sfc_tbl_meta_lookup(struct sfc_adapter *sa, efx_table_id_t table_id) 12 { 13 struct sfc_tbl_meta *meta; 14 struct sfc_tbls *tables = &sa->hw_tables; 15 int rc; 16 17 SFC_ASSERT(sfc_adapter_is_locked(sa)); 18 19 if (tables->status != SFC_TBLS_STATUS_SUPPORTED) 20 return NULL; 21 22 rc = rte_hash_lookup_data(tables->meta.cache, (const void *)&table_id, 23 (void **)&meta); 24 if (rc < 0) 25 return NULL; 26 27 SFC_ASSERT(meta != NULL); 28 SFC_ASSERT(meta->table_id == table_id); 29 30 return meta; 31 } 32 33 int sfc_tbl_meta_init(struct sfc_adapter * sa)34sfc_tbl_meta_init(struct sfc_adapter *sa) 35 { 36 struct sfc_tbls *tables = &sa->hw_tables; 37 struct sfc_tbl_meta_cache *meta = &tables->meta; 38 int rc; 39 40 SFC_ASSERT(sfc_adapter_is_locked(sa)); 41 42 if (tables->status != SFC_TBLS_STATUS_SUPPORTED) 43 return 0; 44 45 rc = sfc_tbl_meta_cache_ctor(&meta->cache); 46 if (rc != 0) 47 return rc; 48 49 rc = sfc_tbl_meta_cache_update(meta->cache, sa->nic); 50 if (rc != 0) { 51 sfc_tbl_meta_cache_dtor(&meta->cache); 52 return rc; 53 } 54 55 return 0; 56 } 57 58 void sfc_tbl_meta_fini(struct sfc_adapter * sa)59sfc_tbl_meta_fini(struct sfc_adapter *sa) 60 { 61 struct sfc_tbls *tables = &sa->hw_tables; 62 struct sfc_tbl_meta_cache *meta = &tables->meta; 63 64 if (meta->cache == NULL) 65 return; 66 67 SFC_ASSERT(sfc_adapter_is_locked(sa)); 68 SFC_ASSERT(tables->status == SFC_TBLS_STATUS_SUPPORTED); 69 70 sfc_tbl_meta_cache_dtor(&meta->cache); 71 } 72