xref: /dpdk/drivers/net/bnxt/tf_core/tf_tcam_shared.c (revision 97435d7906d7706e39e5c3dfefa5e09d7de7f733)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2019-2023 Broadcom
3  * All rights reserved.
4  */
5 
6 #include <string.h>
7 #include <rte_common.h>
8 
9 #include "tf_core.h"
10 
11 #include "tf_tcam_shared.h"
12 #include "tf_tcam.h"
13 #include "tf_common.h"
14 #include "tf_util.h"
15 #include "tf_rm.h"
16 #include "tf_device.h"
17 #include "tfp.h"
18 #include "tf_session.h"
19 #include "tf_msg.h"
20 #include "bitalloc.h"
21 #include "tf_tcam_mgr_msg.h"
22 
23 /**
24  * tf_tcam_shared_bind
25  */
26 int
tf_tcam_shared_bind(struct tf * tfp,struct tf_tcam_cfg_parms * parms)27 tf_tcam_shared_bind(struct tf *tfp,
28 		    struct tf_tcam_cfg_parms *parms)
29 {
30 	int rc;
31 
32 	TF_CHECK_PARMS2(tfp, parms);
33 
34 	/* Perform normal bind
35 	 */
36 	rc = tf_tcam_bind(tfp, parms);
37 	return rc;
38 
39 }
40 /**
41  * tf_tcam_shared_unbind
42  */
43 int
tf_tcam_shared_unbind(struct tf * tfp)44 tf_tcam_shared_unbind(struct tf *tfp)
45 {
46 	int rc;
47 
48 	TF_CHECK_PARMS1(tfp);
49 
50 	rc = tf_tcam_unbind(tfp);
51 	return rc;
52 }
53 
54 /**
55  * tf_tcam_shared_alloc
56  */
57 int
tf_tcam_shared_alloc(struct tf * tfp,struct tf_tcam_alloc_parms * parms)58 tf_tcam_shared_alloc(struct tf *tfp,
59 		     struct tf_tcam_alloc_parms *parms)
60 {
61 	int rc;
62 
63 	TF_CHECK_PARMS2(tfp, parms);
64 
65 	rc = tf_tcam_alloc(tfp, parms);
66 	return rc;
67 }
68 
69 int
tf_tcam_shared_free(struct tf * tfp,struct tf_tcam_free_parms * parms)70 tf_tcam_shared_free(struct tf *tfp,
71 		    struct tf_tcam_free_parms *parms)
72 {
73 	int rc;
74 
75 	TF_CHECK_PARMS2(tfp, parms);
76 
77 	rc = tf_tcam_free(tfp, parms);
78 	return rc;
79 }
80 
81 int
tf_tcam_shared_set(struct tf * tfp __rte_unused,struct tf_tcam_set_parms * parms __rte_unused)82 tf_tcam_shared_set(struct tf *tfp __rte_unused,
83 		   struct tf_tcam_set_parms *parms __rte_unused)
84 {
85 	int rc;
86 
87 	TF_CHECK_PARMS2(tfp, parms);
88 
89 	rc = tf_tcam_set(tfp, parms);
90 	return rc;
91 }
92 
93 int
tf_tcam_shared_get(struct tf * tfp __rte_unused,struct tf_tcam_get_parms * parms)94 tf_tcam_shared_get(struct tf *tfp __rte_unused,
95 		   struct tf_tcam_get_parms *parms)
96 {
97 	int rc;
98 
99 	TF_CHECK_PARMS2(tfp, parms);
100 
101 	rc = tf_tcam_get(tfp, parms);
102 	return rc;
103 }
104 
105 /** Move all shared WC TCAM entries from the high pool into the low pool
106  *  and clear out the high pool entries.
107  */
108 static
tf_tcam_shared_move(struct tf * tfp,struct tf_move_tcam_shared_entries_parms * parms)109 int tf_tcam_shared_move(struct tf *tfp,
110 			struct tf_move_tcam_shared_entries_parms *parms)
111 {
112 	struct tf_session *tfs;
113 	int rc;
114 
115 	TF_CHECK_PARMS2(tfp, parms);
116 
117 	/* Retrieve the session information */
118 	rc = tf_session_get_session_internal(tfp, &tfs);
119 	if (rc)
120 		return rc;
121 
122 	/* If we aren't the shared session or one of our
123 	 * special types
124 	 */
125 	if (!tf_session_is_shared_session(tfs) ||
126 	    (parms->tcam_tbl_type != TF_TCAM_TBL_TYPE_WC_TCAM_HIGH &&
127 	     parms->tcam_tbl_type != TF_TCAM_TBL_TYPE_WC_TCAM_LOW)) {
128 		TFP_DRV_LOG(ERR,
129 			    "%s: Session must be shared with HI/LO type\n",
130 			    tf_dir_2_str(parms->dir));
131 		return -EOPNOTSUPP;
132 	}
133 
134 	rc = tf_tcam_mgr_shared_move_msg(tfp, parms);
135 	return rc;
136 }
137 
138 int
tf_tcam_shared_move_p4(struct tf * tfp,struct tf_move_tcam_shared_entries_parms * parms)139 tf_tcam_shared_move_p4(struct tf *tfp,
140 		       struct tf_move_tcam_shared_entries_parms *parms)
141 {
142 	int rc = 0;
143 	rc = tf_tcam_shared_move(tfp,
144 				 parms);
145 	return rc;
146 }
147 
148 int
tf_tcam_shared_move_p58(struct tf * tfp,struct tf_move_tcam_shared_entries_parms * parms)149 tf_tcam_shared_move_p58(struct tf *tfp,
150 			struct tf_move_tcam_shared_entries_parms *parms)
151 {
152 	int rc = 0;
153 	rc = tf_tcam_shared_move(tfp,
154 				 parms);
155 	return rc;
156 }
157 
158 int
tf_tcam_shared_clear(struct tf * tfp,struct tf_clear_tcam_shared_entries_parms * parms)159 tf_tcam_shared_clear(struct tf *tfp,
160 		     struct tf_clear_tcam_shared_entries_parms *parms)
161 {
162 	int rc = 0;
163 	struct tf_session *tfs;
164 
165 	TF_CHECK_PARMS2(tfp, parms);
166 
167 	/* Retrieve the session information */
168 	rc = tf_session_get_session_internal(tfp, &tfs);
169 	if (rc)
170 		return rc;
171 
172 	if (!tf_session_is_shared_session(tfs) ||
173 	    (parms->tcam_tbl_type != TF_TCAM_TBL_TYPE_WC_TCAM_HIGH &&
174 	     parms->tcam_tbl_type != TF_TCAM_TBL_TYPE_WC_TCAM_LOW))
175 		return -EOPNOTSUPP;
176 
177 	rc = tf_tcam_mgr_shared_clear_msg(tfp, parms);
178 	return rc;
179 }
180