1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2019-2021 Broadcom
7 #include "tf_device_p4.h"
8 #include "tf_device_p58.h"
14 /* Forward declarations */
15 static int tf_dev_unbind_p4(struct tf *tfp);
16 static int tf_dev_unbind_p58(struct tf *tfp);
19 * Device specific bind function, WH+
22 * Pointer to TF handle
25 * Flag controlling shadow copy DB creation
28 * Pointer to resource allocation information
34 * - (0) if successful.
35 * - (-EINVAL) on parameter or internal failure.
38 tf_dev_bind_p4(struct tf *tfp,
40 struct tf_session_resources *resources,
41 struct tf_dev_info *dev_handle)
45 struct tf_ident_cfg_parms ident_cfg;
46 struct tf_tbl_cfg_parms tbl_cfg;
47 struct tf_tcam_cfg_parms tcam_cfg;
48 struct tf_em_cfg_parms em_cfg;
49 struct tf_if_tbl_cfg_parms if_tbl_cfg;
50 struct tf_global_cfg_cfg_parms global_cfg;
52 /* Initial function initialization */
53 dev_handle->ops = &tf_dev_ops_p4_init;
55 /* Initialize the modules */
57 ident_cfg.num_elements = TF_IDENT_TYPE_MAX;
58 ident_cfg.cfg = tf_ident_p4;
59 ident_cfg.shadow_copy = shadow_copy;
60 ident_cfg.resources = resources;
61 rc = tf_ident_bind(tfp, &ident_cfg);
64 "Identifier initialization failure\n");
68 tbl_cfg.num_elements = TF_TBL_TYPE_MAX;
69 tbl_cfg.cfg = tf_tbl_p4;
70 tbl_cfg.shadow_copy = shadow_copy;
71 tbl_cfg.resources = resources;
72 rc = tf_tbl_bind(tfp, &tbl_cfg);
75 "Table initialization failure\n");
79 tcam_cfg.num_elements = TF_TCAM_TBL_TYPE_MAX;
80 tcam_cfg.cfg = tf_tcam_p4;
81 tcam_cfg.shadow_copy = shadow_copy;
82 tcam_cfg.resources = resources;
83 rc = tf_tcam_bind(tfp, &tcam_cfg);
86 "TCAM initialization failure\n");
93 em_cfg.num_elements = TF_EM_TBL_TYPE_MAX;
94 if (dev_handle->type == TF_DEVICE_TYPE_WH)
95 em_cfg.cfg = tf_em_ext_p4;
97 em_cfg.cfg = tf_em_ext_p45;
98 em_cfg.resources = resources;
99 em_cfg.mem_type = TF_EEM_MEM_TYPE_HOST;
100 rc = tf_em_ext_common_bind(tfp, &em_cfg);
103 "EEM initialization failure\n");
110 em_cfg.num_elements = TF_EM_TBL_TYPE_MAX;
111 em_cfg.cfg = tf_em_int_p4;
112 em_cfg.resources = resources;
113 em_cfg.mem_type = 0; /* Not used by EM */
115 rc = tf_em_int_bind(tfp, &em_cfg);
118 "EM initialization failure\n");
125 if_tbl_cfg.num_elements = TF_IF_TBL_TYPE_MAX;
126 if_tbl_cfg.cfg = tf_if_tbl_p4;
127 if_tbl_cfg.shadow_copy = shadow_copy;
128 rc = tf_if_tbl_bind(tfp, &if_tbl_cfg);
131 "IF Table initialization failure\n");
138 global_cfg.num_elements = TF_GLOBAL_CFG_TYPE_MAX;
139 global_cfg.cfg = tf_global_cfg_p4;
140 rc = tf_global_cfg_bind(tfp, &global_cfg);
143 "Global Cfg initialization failure\n");
147 /* Final function initialization */
148 dev_handle->ops = &tf_dev_ops_p4;
153 /* Cleanup of already created modules */
154 frc = tf_dev_unbind_p4(tfp);
162 * Device specific unbind function, WH+
165 * Pointer to TF handle
168 * - (0) if successful.
169 * - (-EINVAL) on failure.
172 tf_dev_unbind_p4(struct tf *tfp)
177 /* Unbind all the support modules. As this is only done on
178 * close we only report errors as everything has to be cleaned
181 * In case of residuals TCAMs are cleaned up first as to
182 * invalidate the pipeline in a clean manner.
184 rc = tf_tcam_unbind(tfp);
187 "Device unbind failed, TCAM\n");
191 rc = tf_ident_unbind(tfp);
194 "Device unbind failed, Identifier\n");
198 rc = tf_tbl_unbind(tfp);
201 "Device unbind failed, Table Type\n");
205 rc = tf_em_ext_common_unbind(tfp);
208 "Device unbind failed, EEM\n");
212 rc = tf_em_int_unbind(tfp);
215 "Device unbind failed, EM\n");
219 rc = tf_if_tbl_unbind(tfp);
222 "Device unbind failed, IF Table Type\n");
226 rc = tf_global_cfg_unbind(tfp);
229 "Device unbind failed, Global Cfg Type\n");
240 * Device specific bind function, THOR
243 * Pointer to TF handle
246 * Flag controlling shadow copy DB creation
249 * Pointer to resource allocation information
255 * - (0) if successful.
256 * - (-EINVAL) on parameter or internal failure.
259 tf_dev_bind_p58(struct tf *tfp,
261 struct tf_session_resources *resources,
262 struct tf_dev_info *dev_handle)
266 struct tf_ident_cfg_parms ident_cfg;
267 struct tf_tbl_cfg_parms tbl_cfg;
268 struct tf_tcam_cfg_parms tcam_cfg;
269 struct tf_em_cfg_parms em_cfg;
270 struct tf_if_tbl_cfg_parms if_tbl_cfg;
271 struct tf_global_cfg_cfg_parms global_cfg;
273 /* Initial function initialization */
274 dev_handle->ops = &tf_dev_ops_p58_init;
276 /* Initialize the modules */
278 ident_cfg.num_elements = TF_IDENT_TYPE_MAX;
279 ident_cfg.cfg = tf_ident_p58;
280 ident_cfg.shadow_copy = shadow_copy;
281 ident_cfg.resources = resources;
282 rc = tf_ident_bind(tfp, &ident_cfg);
285 "Identifier initialization failure\n");
289 tbl_cfg.num_elements = TF_TBL_TYPE_MAX;
290 tbl_cfg.cfg = tf_tbl_p58;
291 tbl_cfg.shadow_copy = shadow_copy;
292 tbl_cfg.resources = resources;
293 rc = tf_tbl_bind(tfp, &tbl_cfg);
296 "Table initialization failure\n");
300 tcam_cfg.num_elements = TF_TCAM_TBL_TYPE_MAX;
301 tcam_cfg.cfg = tf_tcam_p58;
302 tcam_cfg.shadow_copy = shadow_copy;
303 tcam_cfg.resources = resources;
304 rc = tf_tcam_bind(tfp, &tcam_cfg);
307 "TCAM initialization failure\n");
314 em_cfg.num_elements = TF_EM_TBL_TYPE_MAX;
315 em_cfg.cfg = tf_em_int_p58;
316 em_cfg.resources = resources;
317 em_cfg.mem_type = 0; /* Not used by EM */
319 rc = tf_em_int_bind(tfp, &em_cfg);
322 "EM initialization failure\n");
329 if_tbl_cfg.num_elements = TF_IF_TBL_TYPE_MAX;
330 if_tbl_cfg.cfg = tf_if_tbl_p58;
331 if_tbl_cfg.shadow_copy = shadow_copy;
332 rc = tf_if_tbl_bind(tfp, &if_tbl_cfg);
335 "IF Table initialization failure\n");
342 global_cfg.num_elements = TF_GLOBAL_CFG_TYPE_MAX;
343 global_cfg.cfg = tf_global_cfg_p58;
344 rc = tf_global_cfg_bind(tfp, &global_cfg);
347 "Global Cfg initialization failure\n");
351 /* Final function initialization */
352 dev_handle->ops = &tf_dev_ops_p58;
357 /* Cleanup of already created modules */
358 frc = tf_dev_unbind_p58(tfp);
366 * Device specific unbind function, THOR
369 * Pointer to TF handle
372 * - (0) if successful.
373 * - (-EINVAL) on failure.
376 tf_dev_unbind_p58(struct tf *tfp)
381 /* Unbind all the support modules. As this is only done on
382 * close we only report errors as everything has to be cleaned
385 * In case of residuals TCAMs are cleaned up first as to
386 * invalidate the pipeline in a clean manner.
388 rc = tf_tcam_unbind(tfp);
391 "Device unbind failed, TCAM\n");
395 rc = tf_ident_unbind(tfp);
398 "Device unbind failed, Identifier\n");
402 rc = tf_tbl_unbind(tfp);
405 "Device unbind failed, Table Type\n");
409 rc = tf_em_int_unbind(tfp);
412 "Device unbind failed, EM\n");
416 rc = tf_if_tbl_unbind(tfp);
419 "Device unbind failed, IF Table Type\n");
423 rc = tf_global_cfg_unbind(tfp);
426 "Device unbind failed, Global Cfg Type\n");
437 tf_dev_bind(struct tf *tfp __rte_unused,
438 enum tf_device_type type,
440 struct tf_session_resources *resources,
441 struct tf_dev_info *dev_handle)
444 case TF_DEVICE_TYPE_WH:
445 case TF_DEVICE_TYPE_SR:
446 dev_handle->type = type;
447 return tf_dev_bind_p4(tfp,
451 case TF_DEVICE_TYPE_THOR:
452 dev_handle->type = type;
453 return tf_dev_bind_p58(tfp,
465 tf_dev_unbind(struct tf *tfp,
466 struct tf_dev_info *dev_handle)
468 switch (dev_handle->type) {
469 case TF_DEVICE_TYPE_WH:
470 case TF_DEVICE_TYPE_SR:
471 return tf_dev_unbind_p4(tfp);
472 case TF_DEVICE_TYPE_THOR:
473 return tf_dev_unbind_p58(tfp);