762dac0473b91694aadb618beaba4910c3bb2c85
[dpdk.git] / drivers / net / bnxt / tf_core / tf_if_tbl.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2019-2021 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 DBs.
19  * TODO: Store this data in session db
20  */
21 static void *if_tbl_db[TF_DIR_MAX];
22
23 /**
24  * Init flag, set on bind and cleared on unbind
25  * TODO: Store this data in session db
26  */
27 static uint8_t init;
28
29 /**
30  * Convert if_tbl_type to hwrm type.
31  *
32  * [in] if_tbl_type
33  *   Interface table type
34  *
35  * [out] hwrm_type
36  *   HWRM device data type
37  *
38  * Returns:
39  *    0          - Success
40  *   -EOPNOTSUPP - Type not supported
41  */
42 static int
43 tf_if_tbl_get_hcapi_type(struct tf_if_tbl_get_hcapi_parms *parms)
44 {
45         struct tf_if_tbl_cfg *tbl_cfg;
46         enum tf_if_tbl_cfg_type cfg_type;
47
48         tbl_cfg = (struct tf_if_tbl_cfg *)parms->tbl_db;
49         cfg_type = tbl_cfg[parms->db_index].cfg_type;
50
51         if (cfg_type != TF_IF_TBL_CFG)
52                 return -ENOTSUP;
53
54         *parms->hcapi_type = tbl_cfg[parms->db_index].hcapi_type;
55
56         return 0;
57 }
58
59 int
60 tf_if_tbl_bind(struct tf *tfp __rte_unused,
61                struct tf_if_tbl_cfg_parms *parms)
62 {
63         TF_CHECK_PARMS2(tfp, parms);
64
65         if_tbl_db[TF_DIR_RX] = parms->cfg;
66         if_tbl_db[TF_DIR_TX] = parms->cfg;
67
68         init = 1;
69
70         TFP_DRV_LOG(INFO,
71                     "Table Type - initialized\n");
72
73         return 0;
74 }
75
76 int
77 tf_if_tbl_unbind(struct tf *tfp __rte_unused)
78 {
79         /* Bail if nothing has been initialized */
80         if (!init) {
81                 TFP_DRV_LOG(INFO,
82                             "No Table DBs created\n");
83                 return 0;
84         }
85
86         if_tbl_db[TF_DIR_RX] = NULL;
87         if_tbl_db[TF_DIR_TX] = NULL;
88         init = 0;
89
90         return 0;
91 }
92
93 int
94 tf_if_tbl_set(struct tf *tfp,
95               struct tf_if_tbl_set_parms *parms)
96 {
97         int rc;
98         struct tf_if_tbl_get_hcapi_parms hparms;
99
100         TF_CHECK_PARMS3(tfp, parms, parms->data);
101
102         if (!init) {
103                 TFP_DRV_LOG(ERR,
104                             "%s: No Table DBs created\n",
105                             tf_dir_2_str(parms->dir));
106                 return -EINVAL;
107         }
108
109         /* Convert TF type to HCAPI type */
110         hparms.tbl_db = if_tbl_db[parms->dir];
111         hparms.db_index = parms->type;
112         hparms.hcapi_type = &parms->hcapi_type;
113         rc = tf_if_tbl_get_hcapi_type(&hparms);
114         if (rc)
115                 return rc;
116
117         rc = tf_msg_set_if_tbl_entry(tfp, parms);
118         if (rc) {
119                 TFP_DRV_LOG(ERR,
120                             "%s, If Tbl set failed, type:%d, rc:%s\n",
121                             tf_dir_2_str(parms->dir),
122                             parms->type,
123                             strerror(-rc));
124         }
125
126         return 0;
127 }
128
129 int
130 tf_if_tbl_get(struct tf *tfp,
131               struct tf_if_tbl_get_parms *parms)
132 {
133         int rc = 0;
134         struct tf_if_tbl_get_hcapi_parms hparms;
135
136         TF_CHECK_PARMS3(tfp, parms, parms->data);
137
138         if (!init) {
139                 TFP_DRV_LOG(ERR,
140                             "%s: No Table DBs created\n",
141                             tf_dir_2_str(parms->dir));
142                 return -EINVAL;
143         }
144
145         /* Convert TF type to HCAPI type */
146         hparms.tbl_db = if_tbl_db[parms->dir];
147         hparms.db_index = parms->type;
148         hparms.hcapi_type = &parms->hcapi_type;
149         rc = tf_if_tbl_get_hcapi_type(&hparms);
150         if (rc)
151                 return rc;
152
153         /* Get the entry */
154         rc = tf_msg_get_if_tbl_entry(tfp, parms);
155         if (rc) {
156                 TFP_DRV_LOG(ERR,
157                             "%s, If Tbl get failed, type:%d, rc:%s\n",
158                             tf_dir_2_str(parms->dir),
159                             parms->type,
160                             strerror(-rc));
161         }
162
163         return 0;
164 }