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"
13 #include "tf_tcam_shared.h"
14 #endif /* TF_TCAM_SHARED */
18 /* Forward declarations */
19 static int tf_dev_unbind_p4(struct tf *tfp);
20 static int tf_dev_unbind_p58(struct tf *tfp);
23 * Resource Reservation Check function
26 * Number of module subtypes
29 * Pointer to rm element config
32 * Pointer to resource reservation array
35 * - (n) number of tables in module that have non-zero reservation count.
38 tf_dev_reservation_check(uint16_t count,
39 struct tf_rm_element_cfg *cfg,
40 uint16_t *reservations)
46 for (i = 0; i < TF_DIR_MAX; i++) {
47 rm_num = (uint16_t *)reservations + i * count;
48 for (j = 0; j < count; j++) {
49 if ((cfg[j].cfg_type == TF_RM_ELEM_CFG_HCAPI ||
50 cfg[j].cfg_type == TF_RM_ELEM_CFG_HCAPI_BA ||
52 TF_RM_ELEM_CFG_HCAPI_BA_PARENT ||
54 TF_RM_ELEM_CFG_HCAPI_BA_CHILD) &&
64 * Device specific bind function, WH+
67 * Pointer to TF handle
70 * Flag controlling shadow copy DB creation
73 * Pointer to resource allocation information
79 * - (0) if successful.
80 * - (-EINVAL) on parameter or internal failure.
83 tf_dev_bind_p4(struct tf *tfp,
85 struct tf_session_resources *resources,
86 struct tf_dev_info *dev_handle)
91 bool no_rsv_flag = true;
92 struct tf_ident_cfg_parms ident_cfg;
93 struct tf_tbl_cfg_parms tbl_cfg;
94 struct tf_tcam_cfg_parms tcam_cfg;
95 struct tf_em_cfg_parms em_cfg;
96 struct tf_if_tbl_cfg_parms if_tbl_cfg;
97 struct tf_global_cfg_cfg_parms global_cfg;
98 struct tf_session *tfs;
100 /* Retrieve the session information */
101 rc = tf_session_get_session_internal(tfp, &tfs);
105 /* Initial function initialization */
106 dev_handle->ops = &tf_dev_ops_p4_init;
108 /* Initialize the modules */
110 rsv_cnt = tf_dev_reservation_check(TF_IDENT_TYPE_MAX,
112 (uint16_t *)resources->ident_cnt);
114 ident_cfg.num_elements = TF_IDENT_TYPE_MAX;
115 ident_cfg.cfg = tf_ident_p4;
116 ident_cfg.shadow_copy = shadow_copy;
117 ident_cfg.resources = resources;
118 rc = tf_ident_bind(tfp, &ident_cfg);
121 "Identifier initialization failure\n");
128 rsv_cnt = tf_dev_reservation_check(TF_TBL_TYPE_MAX,
130 (uint16_t *)resources->tbl_cnt);
132 tbl_cfg.num_elements = TF_TBL_TYPE_MAX;
133 tbl_cfg.cfg = tf_tbl_p4;
134 tbl_cfg.shadow_copy = shadow_copy;
135 tbl_cfg.resources = resources;
136 rc = tf_tbl_bind(tfp, &tbl_cfg);
139 "Table initialization failure\n");
146 rsv_cnt = tf_dev_reservation_check(TF_TCAM_TBL_TYPE_MAX,
148 (uint16_t *)resources->tcam_cnt);
150 tcam_cfg.num_elements = TF_TCAM_TBL_TYPE_MAX;
151 tcam_cfg.cfg = tf_tcam_p4;
152 tcam_cfg.shadow_copy = shadow_copy;
153 tcam_cfg.resources = resources;
154 #ifdef TF_TCAM_SHARED
155 rc = tf_tcam_shared_bind(tfp, &tcam_cfg);
156 #else /* !TF_TCAM_SHARED */
157 rc = tf_tcam_bind(tfp, &tcam_cfg);
161 "TCAM initialization failure\n");
171 em_cfg.cfg = tf_em_ext_p4;
172 rsv_cnt = tf_dev_reservation_check(TF_EM_TBL_TYPE_MAX,
174 (uint16_t *)resources->em_cnt);
176 em_cfg.num_elements = TF_EM_TBL_TYPE_MAX;
177 em_cfg.resources = resources;
178 em_cfg.mem_type = TF_EEM_MEM_TYPE_HOST;
179 rc = tf_em_ext_common_bind(tfp, &em_cfg);
182 "EEM initialization failure\n");
191 rsv_cnt = tf_dev_reservation_check(TF_EM_TBL_TYPE_MAX,
193 (uint16_t *)resources->em_cnt);
195 em_cfg.num_elements = TF_EM_TBL_TYPE_MAX;
196 em_cfg.cfg = tf_em_int_p4;
197 em_cfg.resources = resources;
198 em_cfg.mem_type = 0; /* Not used by EM */
200 rc = tf_em_int_bind(tfp, &em_cfg);
203 "EM initialization failure\n");
210 * There is no rm reserved for any tables
215 "No rm reserved for any tables\n");
219 if (!tf_session_is_shared_session(tfs)) {
223 if_tbl_cfg.num_elements = TF_IF_TBL_TYPE_MAX;
224 if_tbl_cfg.cfg = tf_if_tbl_p4;
225 if_tbl_cfg.shadow_copy = shadow_copy;
226 rc = tf_if_tbl_bind(tfp, &if_tbl_cfg);
229 "IF Table initialization failure\n");
236 global_cfg.num_elements = TF_GLOBAL_CFG_TYPE_MAX;
237 global_cfg.cfg = tf_global_cfg_p4;
238 rc = tf_global_cfg_bind(tfp, &global_cfg);
241 "Global Cfg initialization failure\n");
245 /* Final function initialization */
246 dev_handle->ops = &tf_dev_ops_p4;
251 /* Cleanup of already created modules */
252 frc = tf_dev_unbind_p4(tfp);
260 * Device specific unbind function, WH+
263 * Pointer to TF handle
266 * - (0) if successful.
267 * - (-EINVAL) on failure.
270 tf_dev_unbind_p4(struct tf *tfp)
275 /* Unbind all the support modules. As this is only done on
276 * close we only report errors as everything has to be cleaned
279 * In case of residuals TCAMs are cleaned up first as to
280 * invalidate the pipeline in a clean manner.
282 #ifdef TF_TCAM_SHARED
283 rc = tf_tcam_shared_unbind(tfp);
284 #else /* !TF_TCAM_SHARED */
285 rc = tf_tcam_unbind(tfp);
286 #endif /* TF_TCAM_SHARED */
289 "Device unbind failed, TCAM\n");
293 rc = tf_ident_unbind(tfp);
296 "Device unbind failed, Identifier\n");
300 rc = tf_tbl_unbind(tfp);
303 "Device unbind failed, Table Type\n");
307 rc = tf_em_ext_common_unbind(tfp);
310 "Device unbind failed, EEM\n");
314 rc = tf_em_int_unbind(tfp);
317 "Device unbind failed, EM\n");
321 rc = tf_if_tbl_unbind(tfp);
324 "Device unbind failed, IF Table Type\n");
328 rc = tf_global_cfg_unbind(tfp);
331 "Device unbind failed, Global Cfg Type\n");
342 * Device specific bind function, THOR
345 * Pointer to TF handle
348 * Flag controlling shadow copy DB creation
351 * Pointer to resource allocation information
357 * - (0) if successful.
358 * - (-EINVAL) on parameter or internal failure.
361 tf_dev_bind_p58(struct tf *tfp,
363 struct tf_session_resources *resources,
364 struct tf_dev_info *dev_handle)
369 bool no_rsv_flag = true;
370 struct tf_ident_cfg_parms ident_cfg;
371 struct tf_tbl_cfg_parms tbl_cfg;
372 struct tf_tcam_cfg_parms tcam_cfg;
373 struct tf_em_cfg_parms em_cfg;
374 struct tf_if_tbl_cfg_parms if_tbl_cfg;
375 struct tf_global_cfg_cfg_parms global_cfg;
376 struct tf_session *tfs;
378 /* Initial function initialization */
379 dev_handle->ops = &tf_dev_ops_p58_init;
381 /* Retrieve the session information */
382 rc = tf_session_get_session_internal(tfp, &tfs);
386 rsv_cnt = tf_dev_reservation_check(TF_IDENT_TYPE_MAX,
388 (uint16_t *)resources->ident_cnt);
390 ident_cfg.num_elements = TF_IDENT_TYPE_MAX;
391 ident_cfg.cfg = tf_ident_p58;
392 ident_cfg.shadow_copy = shadow_copy;
393 ident_cfg.resources = resources;
394 rc = tf_ident_bind(tfp, &ident_cfg);
397 "Identifier initialization failure\n");
403 rsv_cnt = tf_dev_reservation_check(TF_TBL_TYPE_MAX,
405 (uint16_t *)resources->tbl_cnt);
407 tbl_cfg.num_elements = TF_TBL_TYPE_MAX;
408 tbl_cfg.cfg = tf_tbl_p58;
409 tbl_cfg.shadow_copy = shadow_copy;
410 tbl_cfg.resources = resources;
411 rc = tf_tbl_bind(tfp, &tbl_cfg);
414 "Table initialization failure\n");
420 rsv_cnt = tf_dev_reservation_check(TF_TCAM_TBL_TYPE_MAX,
422 (uint16_t *)resources->tcam_cnt);
424 tcam_cfg.num_elements = TF_TCAM_TBL_TYPE_MAX;
425 tcam_cfg.cfg = tf_tcam_p58;
426 tcam_cfg.shadow_copy = shadow_copy;
427 tcam_cfg.resources = resources;
428 #ifdef TF_TCAM_SHARED
429 rc = tf_tcam_shared_bind(tfp, &tcam_cfg);
430 #else /* !TF_TCAM_SHARED */
431 rc = tf_tcam_bind(tfp, &tcam_cfg);
435 "TCAM initialization failure\n");
444 rsv_cnt = tf_dev_reservation_check(TF_EM_TBL_TYPE_MAX,
446 (uint16_t *)resources->em_cnt);
448 em_cfg.num_elements = TF_EM_TBL_TYPE_MAX;
449 em_cfg.cfg = tf_em_int_p58;
450 em_cfg.resources = resources;
451 em_cfg.mem_type = 0; /* Not used by EM */
453 rc = tf_em_int_bind(tfp, &em_cfg);
456 "EM initialization failure\n");
463 * There is no rm reserved for any tables
468 "No rm reserved for any tables\n");
475 if (!tf_session_is_shared_session(tfs)) {
476 if_tbl_cfg.num_elements = TF_IF_TBL_TYPE_MAX;
477 if_tbl_cfg.cfg = tf_if_tbl_p58;
478 if_tbl_cfg.shadow_copy = shadow_copy;
479 rc = tf_if_tbl_bind(tfp, &if_tbl_cfg);
482 "IF Table initialization failure\n");
489 global_cfg.num_elements = TF_GLOBAL_CFG_TYPE_MAX;
490 global_cfg.cfg = tf_global_cfg_p58;
491 rc = tf_global_cfg_bind(tfp, &global_cfg);
494 "Global Cfg initialization failure\n");
499 /* Final function initialization */
500 dev_handle->ops = &tf_dev_ops_p58;
505 /* Cleanup of already created modules */
506 frc = tf_dev_unbind_p58(tfp);
514 * Device specific unbind function, THOR
517 * Pointer to TF handle
520 * - (0) if successful.
521 * - (-EINVAL) on failure.
524 tf_dev_unbind_p58(struct tf *tfp)
528 struct tf_session *tfs;
530 /* Retrieve the session information */
531 rc = tf_session_get_session_internal(tfp, &tfs);
535 /* Unbind all the support modules. As this is only done on
536 * close we only report errors as everything has to be cleaned
539 * In case of residuals TCAMs are cleaned up first as to
540 * invalidate the pipeline in a clean manner.
542 #ifdef TF_TCAM_SHARED
543 rc = tf_tcam_shared_unbind(tfp);
544 #else /* !TF_TCAM_SHARED */
545 rc = tf_tcam_unbind(tfp);
546 #endif /* TF_TCAM_SHARED */
549 "Device unbind failed, TCAM\n");
553 rc = tf_ident_unbind(tfp);
556 "Device unbind failed, Identifier\n");
560 rc = tf_tbl_unbind(tfp);
563 "Device unbind failed, Table Type\n");
567 rc = tf_em_int_unbind(tfp);
570 "Device unbind failed, EM\n");
574 if (!tf_session_is_shared_session(tfs)) {
575 rc = tf_if_tbl_unbind(tfp);
578 "Device unbind failed, IF Table Type\n");
582 rc = tf_global_cfg_unbind(tfp);
585 "Device unbind failed, Global Cfg Type\n");
597 tf_dev_bind(struct tf *tfp __rte_unused,
598 enum tf_device_type type,
600 struct tf_session_resources *resources,
601 struct tf_dev_info *dev_handle)
604 case TF_DEVICE_TYPE_WH:
605 case TF_DEVICE_TYPE_SR:
606 dev_handle->type = type;
607 return tf_dev_bind_p4(tfp,
611 case TF_DEVICE_TYPE_THOR:
612 dev_handle->type = type;
613 return tf_dev_bind_p58(tfp,
625 tf_dev_bind_ops(enum tf_device_type type,
626 struct tf_dev_info *dev_handle)
629 case TF_DEVICE_TYPE_WH:
630 case TF_DEVICE_TYPE_SR:
631 dev_handle->ops = &tf_dev_ops_p4_init;
633 case TF_DEVICE_TYPE_THOR:
634 dev_handle->ops = &tf_dev_ops_p58_init;
646 tf_dev_unbind(struct tf *tfp,
647 struct tf_dev_info *dev_handle)
649 switch (dev_handle->type) {
650 case TF_DEVICE_TYPE_WH:
651 case TF_DEVICE_TYPE_SR:
652 return tf_dev_unbind_p4(tfp);
653 case TF_DEVICE_TYPE_THOR:
654 return tf_dev_unbind_p58(tfp);