Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2019-2023 Broadcom
3 : : * All rights reserved.
4 : : */
5 : :
6 : : #include <rte_common.h>
7 : :
8 : : #include "tf_if_tbl.h"
9 : : #include "tf_common.h"
10 : : #include "tf_rm.h"
11 : : #include "tf_util.h"
12 : : #include "tf_msg.h"
13 : : #include "tfp.h"
14 : :
15 : : struct tf;
16 : :
17 : : /**
18 : : * IF Table database
19 : : */
20 : : struct tf_if_tbl_db {
21 : : struct tf_if_tbl_cfg *if_tbl_cfg_db[TF_DIR_MAX];
22 : : };
23 : :
24 : : /**
25 : : * Convert if_tbl_type to hwrm type.
26 : : *
27 : : * [in] if_tbl_type
28 : : * Interface table type
29 : : *
30 : : * [out] hwrm_type
31 : : * HWRM device data type
32 : : *
33 : : * Returns:
34 : : * 0 - Success
35 : : * -EOPNOTSUPP - Type not supported
36 : : */
37 : : static int
38 : : tf_if_tbl_get_hcapi_type(struct tf_if_tbl_get_hcapi_parms *parms)
39 : : {
40 : : struct tf_if_tbl_cfg *tbl_cfg;
41 : : enum tf_if_tbl_cfg_type cfg_type;
42 : :
43 : : tbl_cfg = (struct tf_if_tbl_cfg *)parms->tbl_db;
44 : 0 : cfg_type = tbl_cfg[parms->db_index].cfg_type;
45 : :
46 : 0 : if (cfg_type != TF_IF_TBL_CFG)
47 : : return -ENOTSUP;
48 : :
49 : 0 : *parms->hcapi_type = tbl_cfg[parms->db_index].hcapi_type;
50 : :
51 : : return 0;
52 : : }
53 : :
54 : : int
55 : 0 : tf_if_tbl_bind(struct tf *tfp,
56 : : struct tf_if_tbl_cfg_parms *parms)
57 : : {
58 : : struct tfp_calloc_parms cparms;
59 : : struct tf_if_tbl_db *if_tbl_db;
60 : :
61 [ # # ]: 0 : TF_CHECK_PARMS2(tfp, parms);
62 : :
63 : 0 : cparms.nitems = 1;
64 : 0 : cparms.size = sizeof(struct tf_if_tbl_db);
65 : 0 : cparms.alignment = 0;
66 [ # # ]: 0 : if (tfp_calloc(&cparms) != 0) {
67 : 0 : TFP_DRV_LOG(ERR, "if_tbl_rm_db alloc error %s\n",
68 : : strerror(ENOMEM));
69 : 0 : return -ENOMEM;
70 : : }
71 : :
72 : 0 : if_tbl_db = cparms.mem_va;
73 : 0 : if_tbl_db->if_tbl_cfg_db[TF_DIR_RX] = parms->cfg;
74 : 0 : if_tbl_db->if_tbl_cfg_db[TF_DIR_TX] = parms->cfg;
75 : 0 : tf_session_set_if_tbl_db(tfp, (void *)if_tbl_db);
76 : :
77 : 0 : TFP_DRV_LOG(INFO,
78 : : "Table Type - initialized\n");
79 : :
80 : 0 : return 0;
81 : : }
82 : :
83 : : int
84 : 0 : tf_if_tbl_unbind(struct tf *tfp)
85 : : {
86 : : int rc;
87 : 0 : struct tf_if_tbl_db *if_tbl_db_ptr = NULL;
88 : :
89 [ # # ]: 0 : TF_CHECK_PARMS1(tfp);
90 : :
91 : 0 : rc = tf_session_get_if_tbl_db(tfp, (void **)&if_tbl_db_ptr);
92 [ # # ]: 0 : if (rc) {
93 : 0 : TFP_DRV_LOG(INFO, "No IF Table DBs initialized\n");
94 : 0 : return 0;
95 : : }
96 : : /* Bail if nothing has been initialized */
97 [ # # ]: 0 : if (!if_tbl_db_ptr) {
98 : 0 : TFP_DRV_LOG(INFO,
99 : : "No Table DBs created\n");
100 : 0 : return 0;
101 : : }
102 : :
103 : 0 : tfp_free((void *)if_tbl_db_ptr);
104 : 0 : tf_session_set_if_tbl_db(tfp, NULL);
105 : :
106 : 0 : return 0;
107 : : }
108 : :
109 : : int
110 : 0 : tf_if_tbl_set(struct tf *tfp,
111 : : struct tf_if_tbl_set_parms *parms)
112 : : {
113 : : int rc;
114 : 0 : struct tf_if_tbl_db *if_tbl_db_ptr = NULL;
115 : : struct tf_if_tbl_get_hcapi_parms hparms;
116 : :
117 [ # # # # ]: 0 : TF_CHECK_PARMS3(tfp, parms, parms->data);
118 : :
119 : 0 : rc = tf_session_get_if_tbl_db(tfp, (void **)&if_tbl_db_ptr);
120 [ # # ]: 0 : if (rc) {
121 : 0 : TFP_DRV_LOG(INFO, "No IF Table DBs initialized\n");
122 : 0 : return 0;
123 : : }
124 : :
125 [ # # ]: 0 : if (!if_tbl_db_ptr) {
126 : 0 : TFP_DRV_LOG(ERR,
127 : : "%s: No Table DBs created\n",
128 : : tf_dir_2_str(parms->dir));
129 : 0 : return -EINVAL;
130 : : }
131 : :
132 : : /* Convert TF type to HCAPI type */
133 : 0 : hparms.tbl_db = if_tbl_db_ptr->if_tbl_cfg_db[parms->dir];
134 : 0 : hparms.db_index = parms->type;
135 [ # # ]: 0 : hparms.hcapi_type = &parms->hcapi_type;
136 : : rc = tf_if_tbl_get_hcapi_type(&hparms);
137 : : if (rc)
138 : : return rc;
139 : :
140 : 0 : rc = tf_msg_set_if_tbl_entry(tfp, parms);
141 [ # # ]: 0 : if (rc) {
142 : 0 : TFP_DRV_LOG(ERR,
143 : : "%s, If Tbl set failed, type:%d, rc:%s\n",
144 : : tf_dir_2_str(parms->dir),
145 : : parms->type,
146 : : strerror(-rc));
147 : : }
148 : :
149 : : return 0;
150 : : }
151 : :
152 : : int
153 : 0 : tf_if_tbl_get(struct tf *tfp,
154 : : struct tf_if_tbl_get_parms *parms)
155 : : {
156 : : int rc = 0;
157 : 0 : struct tf_if_tbl_db *if_tbl_db_ptr = NULL;
158 : : struct tf_if_tbl_get_hcapi_parms hparms;
159 : :
160 [ # # # # ]: 0 : TF_CHECK_PARMS3(tfp, parms, parms->data);
161 : :
162 : 0 : rc = tf_session_get_if_tbl_db(tfp, (void **)&if_tbl_db_ptr);
163 [ # # ]: 0 : if (rc) {
164 : 0 : TFP_DRV_LOG(INFO, "No IF Table DBs initialized\n");
165 : 0 : return 0;
166 : : }
167 : :
168 [ # # ]: 0 : if (!if_tbl_db_ptr) {
169 : 0 : TFP_DRV_LOG(ERR,
170 : : "%s: No Table DBs created\n",
171 : : tf_dir_2_str(parms->dir));
172 : 0 : return -EINVAL;
173 : : }
174 : :
175 : : /* Convert TF type to HCAPI type */
176 : 0 : hparms.tbl_db = if_tbl_db_ptr->if_tbl_cfg_db[parms->dir];
177 : 0 : hparms.db_index = parms->type;
178 [ # # ]: 0 : hparms.hcapi_type = &parms->hcapi_type;
179 : : rc = tf_if_tbl_get_hcapi_type(&hparms);
180 : : if (rc)
181 : : return rc;
182 : :
183 : : /* Get the entry */
184 : 0 : rc = tf_msg_get_if_tbl_entry(tfp, parms);
185 [ # # ]: 0 : if (rc) {
186 : 0 : TFP_DRV_LOG(ERR,
187 : : "%s, If Tbl get failed, type:%d, rc:%s\n",
188 : : tf_dir_2_str(parms->dir),
189 : : parms->type,
190 : : strerror(-rc));
191 : : }
192 : :
193 : : return 0;
194 : : }
|