Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause 2 : : * Copyright(C) 2022 Marvell. 3 : : */ 4 : : 5 : : #include "roc_api.h" 6 : : #include "roc_priv.h" 7 : : 8 : : int 9 : 0 : roc_npa_buf_type_update(uint64_t aura_handle, enum roc_npa_buf_type type, int count) 10 : : { 11 : : uint64_t aura_id = roc_npa_aura_handle_to_aura(aura_handle); 12 : : struct npa_lf *lf; 13 : : 14 : 0 : lf = idev_npa_obj_get(); 15 [ # # # # ]: 0 : if (lf == NULL || aura_id >= lf->nr_pools) 16 : : return NPA_ERR_PARAM; 17 : : 18 [ # # ]: 0 : if (plt_bitmap_get(lf->npa_bmp, aura_id)) { 19 : 0 : plt_err("Cannot set buf type on unused aura"); 20 : 0 : return NPA_ERR_PARAM; 21 : : } 22 : : 23 [ # # # # ]: 0 : if (type >= ROC_NPA_BUF_TYPE_END || (lf->aura_attr[aura_id].buf_type[type] + count < 0)) { 24 : 0 : plt_err("Pool buf type invalid"); 25 : 0 : return NPA_ERR_PARAM; 26 : : } 27 : : 28 : 0 : lf->aura_attr[aura_id].buf_type[type] += count; 29 : : plt_wmb(); 30 : 0 : return 0; 31 : : } 32 : : 33 : : uint64_t 34 : 0 : roc_npa_buf_type_mask(uint64_t aura_handle) 35 : : { 36 : : uint64_t aura_id = roc_npa_aura_handle_to_aura(aura_handle); 37 : : uint64_t type_mask = 0; 38 : : struct npa_lf *lf; 39 : : int type; 40 : : 41 : 0 : lf = idev_npa_obj_get(); 42 [ # # # # ]: 0 : if (lf == NULL || aura_id >= lf->nr_pools) { 43 : 0 : plt_err("Invalid aura id or lf"); 44 : 0 : return 0; 45 : : } 46 : : 47 [ # # ]: 0 : if (plt_bitmap_get(lf->npa_bmp, aura_id)) { 48 : 0 : plt_err("Cannot get buf_type on unused aura"); 49 : 0 : return 0; 50 : : } 51 : : 52 [ # # ]: 0 : for (type = 0; type < ROC_NPA_BUF_TYPE_END; type++) { 53 [ # # ]: 0 : if (lf->aura_attr[aura_id].buf_type[type]) 54 : 0 : type_mask |= BIT_ULL(type); 55 : : } 56 : : 57 : : return type_mask; 58 : : } 59 : : 60 : : uint64_t 61 : 0 : roc_npa_buf_type_limit_get(uint64_t type_mask) 62 : : { 63 : : uint64_t wdata, reg; 64 : : uint64_t limit = 0; 65 : : struct npa_lf *lf; 66 : : uint64_t aura_id; 67 : : int64_t *addr; 68 : : uint64_t val; 69 : : int type; 70 : : 71 : 0 : lf = idev_npa_obj_get(); 72 [ # # ]: 0 : if (lf == NULL) 73 : : return NPA_ERR_PARAM; 74 : : 75 [ # # ]: 0 : for (aura_id = 0; aura_id < lf->nr_pools; aura_id++) { 76 : : if (plt_bitmap_get(lf->npa_bmp, aura_id)) 77 : : continue; 78 : : 79 : : /* Find aura's matching the buf_types requested */ 80 : : if (type_mask != 0) { 81 : : val = 0; 82 : : for (type = 0; type < ROC_NPA_BUF_TYPE_END; type++) { 83 : : if (lf->aura_attr[aura_id].buf_type[type] != 0) 84 : : val |= BIT_ULL(type); 85 : : } 86 : : if ((val & type_mask) == 0) 87 : : continue; 88 : : } 89 : : 90 : : wdata = aura_id << 44; 91 : : addr = (int64_t *)(lf->base + NPA_LF_AURA_OP_LIMIT); 92 : : reg = roc_atomic64_add_nosync(wdata, addr); 93 : : 94 : : if (!(reg & BIT_ULL(42))) 95 : : limit += (reg & ROC_AURA_OP_LIMIT_MASK); 96 : : } 97 : : 98 : : return limit; 99 : : }