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 #include "tf_tbl_sram.h"
15 #endif /* TF_TCAM_SHARED */
19 /* Number of slices per row for WC TCAM */
20 uint16_t g_wc_num_slices_per_row = TF_WC_TCAM_1_SLICE_PER_ROW;
22 /* Forward declarations */
23 static int tf_dev_unbind_p4(struct tf *tfp);
24 static int tf_dev_unbind_p58(struct tf *tfp);
27 * Resource Reservation Check function
30 * Number of module subtypes
33 * Pointer to rm element config
36 * Pointer to resource reservation array
39 * - (n) number of tables in module that have non-zero reservation count.
42 tf_dev_reservation_check(uint16_t count,
43 struct tf_rm_element_cfg *cfg,
44 uint16_t *reservations)
50 for (i = 0; i < TF_DIR_MAX; i++) {
51 rm_num = (uint16_t *)reservations + i * count;
52 for (j = 0; j < count; j++) {
53 if ((cfg[j].cfg_type == TF_RM_ELEM_CFG_HCAPI ||
54 cfg[j].cfg_type == TF_RM_ELEM_CFG_HCAPI_BA ||
56 TF_RM_ELEM_CFG_HCAPI_BA_PARENT ||
58 TF_RM_ELEM_CFG_HCAPI_BA_CHILD) &&
68 * Device specific bind function, WH+
71 * Pointer to TF handle
74 * Flag controlling shadow copy DB creation
77 * Pointer to resource allocation information
83 * - (0) if successful.
84 * - (-EINVAL) on parameter or internal failure.
87 tf_dev_bind_p4(struct tf *tfp,
89 struct tf_session_resources *resources,
90 struct tf_dev_info *dev_handle,
91 enum tf_wc_num_slice wc_num_slices)
96 bool no_rsv_flag = true;
97 struct tf_ident_cfg_parms ident_cfg;
98 struct tf_tbl_cfg_parms tbl_cfg;
99 struct tf_tcam_cfg_parms tcam_cfg;
100 struct tf_em_cfg_parms em_cfg;
101 struct tf_if_tbl_cfg_parms if_tbl_cfg;
102 struct tf_global_cfg_cfg_parms global_cfg;
103 struct tf_session *tfs;
105 /* Retrieve the session information */
106 rc = tf_session_get_session_internal(tfp, &tfs);
110 /* Initial function initialization */
111 dev_handle->ops = &tf_dev_ops_p4_init;
113 /* Initialize the modules */
115 rsv_cnt = tf_dev_reservation_check(TF_IDENT_TYPE_MAX,
117 (uint16_t *)resources->ident_cnt);
119 ident_cfg.num_elements = TF_IDENT_TYPE_MAX;
120 ident_cfg.cfg = tf_ident_p4;
121 ident_cfg.shadow_copy = shadow_copy;
122 ident_cfg.resources = resources;
123 rc = tf_ident_bind(tfp, &ident_cfg);
126 "Identifier initialization failure\n");
133 rsv_cnt = tf_dev_reservation_check(TF_TBL_TYPE_MAX,
135 (uint16_t *)resources->tbl_cnt);
137 tbl_cfg.num_elements = TF_TBL_TYPE_MAX;
138 tbl_cfg.cfg = tf_tbl_p4;
139 tbl_cfg.resources = resources;
140 rc = tf_tbl_bind(tfp, &tbl_cfg);
143 "Table initialization failure\n");
150 rsv_cnt = tf_dev_reservation_check(TF_TCAM_TBL_TYPE_MAX,
152 (uint16_t *)resources->tcam_cnt);
154 tcam_cfg.num_elements = TF_TCAM_TBL_TYPE_MAX;
155 tcam_cfg.cfg = tf_tcam_p4;
156 tcam_cfg.shadow_copy = shadow_copy;
157 tcam_cfg.resources = resources;
158 tcam_cfg.wc_num_slices = wc_num_slices;
159 #ifdef TF_TCAM_SHARED
160 rc = tf_tcam_shared_bind(tfp, &tcam_cfg);
161 #else /* !TF_TCAM_SHARED */
162 rc = tf_tcam_bind(tfp, &tcam_cfg);
166 "TCAM initialization failure\n");
176 em_cfg.cfg = tf_em_ext_p4;
177 rsv_cnt = tf_dev_reservation_check(TF_EM_TBL_TYPE_MAX,
179 (uint16_t *)resources->em_cnt);
181 em_cfg.num_elements = TF_EM_TBL_TYPE_MAX;
182 em_cfg.resources = resources;
183 em_cfg.mem_type = TF_EEM_MEM_TYPE_HOST;
184 rc = tf_em_ext_common_bind(tfp, &em_cfg);
187 "EEM initialization failure\n");
196 rsv_cnt = tf_dev_reservation_check(TF_EM_TBL_TYPE_MAX,
198 (uint16_t *)resources->em_cnt);
200 em_cfg.num_elements = TF_EM_TBL_TYPE_MAX;
201 em_cfg.cfg = tf_em_int_p4;
202 em_cfg.resources = resources;
203 em_cfg.mem_type = 0; /* Not used by EM */
205 rc = tf_em_int_bind(tfp, &em_cfg);
208 "EM initialization failure\n");
215 * There is no rm reserved for any tables
220 "No rm reserved for any tables\n");
227 if_tbl_cfg.num_elements = TF_IF_TBL_TYPE_MAX;
228 if_tbl_cfg.cfg = tf_if_tbl_p4;
229 if_tbl_cfg.shadow_copy = shadow_copy;
230 rc = tf_if_tbl_bind(tfp, &if_tbl_cfg);
233 "IF Table initialization failure\n");
237 if (!tf_session_is_shared_session(tfs)) {
241 global_cfg.num_elements = TF_GLOBAL_CFG_TYPE_MAX;
242 global_cfg.cfg = tf_global_cfg_p4;
243 rc = tf_global_cfg_bind(tfp, &global_cfg);
246 "Global Cfg initialization failure\n");
250 /* Final function initialization */
251 dev_handle->ops = &tf_dev_ops_p4;
256 /* Cleanup of already created modules */
257 frc = tf_dev_unbind_p4(tfp);
265 * Device specific unbind function, WH+
268 * Pointer to TF handle
271 * - (0) if successful.
272 * - (-EINVAL) on failure.
275 tf_dev_unbind_p4(struct tf *tfp)
279 struct tf_session *tfs;
281 /* Retrieve the session information */
282 rc = tf_session_get_session_internal(tfp, &tfs);
286 /* Unbind all the support modules. As this is only done on
287 * close we only report errors as everything has to be cleaned
290 * In case of residuals TCAMs are cleaned up first as to
291 * invalidate the pipeline in a clean manner.
293 #ifdef TF_TCAM_SHARED
294 rc = tf_tcam_shared_unbind(tfp);
295 #else /* !TF_TCAM_SHARED */
296 rc = tf_tcam_unbind(tfp);
297 #endif /* TF_TCAM_SHARED */
300 "Device unbind failed, TCAM\n");
304 rc = tf_ident_unbind(tfp);
307 "Device unbind failed, Identifier\n");
311 rc = tf_tbl_unbind(tfp);
314 "Device unbind failed, Table Type\n");
318 rc = tf_em_ext_common_unbind(tfp);
321 "Device unbind failed, EEM\n");
325 rc = tf_em_int_unbind(tfp);
328 "Device unbind failed, EM\n");
332 if (!tf_session_is_shared_session(tfs)) {
333 rc = tf_if_tbl_unbind(tfp);
336 "Device unbind failed, IF Table Type\n");
340 rc = tf_global_cfg_unbind(tfp);
343 "Device unbind failed, Global Cfg Type\n");
355 * Device specific bind function, THOR
358 * Pointer to TF handle
361 * Flag controlling shadow copy DB creation
364 * Pointer to resource allocation information
370 * - (0) if successful.
371 * - (-EINVAL) on parameter or internal failure.
374 tf_dev_bind_p58(struct tf *tfp,
376 struct tf_session_resources *resources,
377 struct tf_dev_info *dev_handle,
378 enum tf_wc_num_slice wc_num_slices)
383 bool no_rsv_flag = true;
384 struct tf_ident_cfg_parms ident_cfg;
385 struct tf_tbl_cfg_parms tbl_cfg;
386 struct tf_tcam_cfg_parms tcam_cfg;
387 struct tf_em_cfg_parms em_cfg;
388 struct tf_if_tbl_cfg_parms if_tbl_cfg;
389 struct tf_global_cfg_cfg_parms global_cfg;
390 struct tf_session *tfs;
392 /* Initial function initialization */
393 dev_handle->ops = &tf_dev_ops_p58_init;
395 /* Retrieve the session information */
396 rc = tf_session_get_session_internal(tfp, &tfs);
400 rsv_cnt = tf_dev_reservation_check(TF_IDENT_TYPE_MAX,
402 (uint16_t *)resources->ident_cnt);
404 ident_cfg.num_elements = TF_IDENT_TYPE_MAX;
405 ident_cfg.cfg = tf_ident_p58;
406 ident_cfg.shadow_copy = shadow_copy;
407 ident_cfg.resources = resources;
408 rc = tf_ident_bind(tfp, &ident_cfg);
411 "Identifier initialization failure\n");
417 rsv_cnt = tf_dev_reservation_check(TF_TBL_TYPE_MAX,
419 (uint16_t *)resources->tbl_cnt);
421 tbl_cfg.num_elements = TF_TBL_TYPE_MAX;
422 tbl_cfg.cfg = tf_tbl_p58;
423 tbl_cfg.resources = resources;
424 rc = tf_tbl_bind(tfp, &tbl_cfg);
427 "Table initialization failure\n");
432 rc = tf_tbl_sram_bind(tfp);
435 "SRAM table initialization failure\n");
440 rsv_cnt = tf_dev_reservation_check(TF_TCAM_TBL_TYPE_MAX,
442 (uint16_t *)resources->tcam_cnt);
444 tcam_cfg.num_elements = TF_TCAM_TBL_TYPE_MAX;
445 tcam_cfg.cfg = tf_tcam_p58;
446 tcam_cfg.shadow_copy = shadow_copy;
447 tcam_cfg.resources = resources;
448 tcam_cfg.wc_num_slices = wc_num_slices;
449 #ifdef TF_TCAM_SHARED
450 rc = tf_tcam_shared_bind(tfp, &tcam_cfg);
451 #else /* !TF_TCAM_SHARED */
452 rc = tf_tcam_bind(tfp, &tcam_cfg);
456 "TCAM initialization failure\n");
465 rsv_cnt = tf_dev_reservation_check(TF_EM_TBL_TYPE_MAX,
467 (uint16_t *)resources->em_cnt);
469 em_cfg.num_elements = TF_EM_TBL_TYPE_MAX;
470 em_cfg.cfg = tf_em_int_p58;
471 em_cfg.resources = resources;
472 em_cfg.mem_type = 0; /* Not used by EM */
474 rc = tf_em_int_bind(tfp, &em_cfg);
477 "EM initialization failure\n");
484 * There is no rm reserved for any tables
489 "No rm reserved for any tables\n");
496 if_tbl_cfg.num_elements = TF_IF_TBL_TYPE_MAX;
497 if_tbl_cfg.cfg = tf_if_tbl_p58;
498 if_tbl_cfg.shadow_copy = shadow_copy;
499 rc = tf_if_tbl_bind(tfp, &if_tbl_cfg);
502 "IF Table initialization failure\n");
506 if (!tf_session_is_shared_session(tfs)) {
510 global_cfg.num_elements = TF_GLOBAL_CFG_TYPE_MAX;
511 global_cfg.cfg = tf_global_cfg_p58;
512 rc = tf_global_cfg_bind(tfp, &global_cfg);
515 "Global Cfg initialization failure\n");
520 /* Final function initialization */
521 dev_handle->ops = &tf_dev_ops_p58;
526 /* Cleanup of already created modules */
527 frc = tf_dev_unbind_p58(tfp);
535 * Device specific unbind function, THOR
538 * Pointer to TF handle
541 * - (0) if successful.
542 * - (-EINVAL) on failure.
545 tf_dev_unbind_p58(struct tf *tfp)
549 struct tf_session *tfs;
551 /* Retrieve the session information */
552 rc = tf_session_get_session_internal(tfp, &tfs);
556 /* Unbind all the support modules. As this is only done on
557 * close we only report errors as everything has to be cleaned
560 * In case of residuals TCAMs are cleaned up first as to
561 * invalidate the pipeline in a clean manner.
563 #ifdef TF_TCAM_SHARED
564 rc = tf_tcam_shared_unbind(tfp);
565 #else /* !TF_TCAM_SHARED */
566 rc = tf_tcam_unbind(tfp);
567 #endif /* TF_TCAM_SHARED */
570 "Device unbind failed, TCAM\n");
574 rc = tf_ident_unbind(tfp);
577 "Device unbind failed, Identifier\n");
581 /* Unbind the SRAM table prior to table as the table manager
582 * owns and frees the table DB while the SRAM table manager owns
583 * and manages it's internal data structures. SRAM table manager
584 * relies on the table rm_db to exist.
586 rc = tf_tbl_sram_unbind(tfp);
589 "Device unbind failed, SRAM table\n");
593 rc = tf_tbl_unbind(tfp);
596 "Device unbind failed, Table Type\n");
600 rc = tf_em_int_unbind(tfp);
603 "Device unbind failed, EM\n");
607 rc = tf_if_tbl_unbind(tfp);
610 "Device unbind failed, IF Table Type\n");
614 if (!tf_session_is_shared_session(tfs)) {
615 rc = tf_global_cfg_unbind(tfp);
618 "Device unbind failed, Global Cfg Type\n");
630 tf_dev_bind(struct tf *tfp __rte_unused,
631 enum tf_device_type type,
633 struct tf_session_resources *resources,
634 uint16_t wc_num_slices,
635 struct tf_dev_info *dev_handle)
638 case TF_DEVICE_TYPE_WH:
639 case TF_DEVICE_TYPE_SR:
640 dev_handle->type = type;
641 return tf_dev_bind_p4(tfp,
646 case TF_DEVICE_TYPE_THOR:
647 dev_handle->type = type;
648 return tf_dev_bind_p58(tfp,
661 tf_dev_bind_ops(enum tf_device_type type,
662 struct tf_dev_info *dev_handle)
665 case TF_DEVICE_TYPE_WH:
666 case TF_DEVICE_TYPE_SR:
667 dev_handle->ops = &tf_dev_ops_p4_init;
669 case TF_DEVICE_TYPE_THOR:
670 dev_handle->ops = &tf_dev_ops_p58_init;
682 tf_dev_unbind(struct tf *tfp,
683 struct tf_dev_info *dev_handle)
685 switch (dev_handle->type) {
686 case TF_DEVICE_TYPE_WH:
687 case TF_DEVICE_TYPE_SR:
688 return tf_dev_unbind_p4(tfp);
689 case TF_DEVICE_TYPE_THOR:
690 return tf_dev_unbind_p58(tfp);