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 /* Forward declarations */
20 static int tf_dev_unbind_p4(struct tf *tfp);
21 static int tf_dev_unbind_p58(struct tf *tfp);
24 * Resource Reservation Check function
27 * Number of module subtypes
30 * Pointer to rm element config
33 * Pointer to resource reservation array
36 * - (n) number of tables in module that have non-zero reservation count.
39 tf_dev_reservation_check(uint16_t count,
40 struct tf_rm_element_cfg *cfg,
41 uint16_t *reservations)
47 for (i = 0; i < TF_DIR_MAX; i++) {
48 rm_num = (uint16_t *)reservations + i * count;
49 for (j = 0; j < count; j++) {
50 if ((cfg[j].cfg_type == TF_RM_ELEM_CFG_HCAPI ||
51 cfg[j].cfg_type == TF_RM_ELEM_CFG_HCAPI_BA ||
53 TF_RM_ELEM_CFG_HCAPI_BA_PARENT ||
55 TF_RM_ELEM_CFG_HCAPI_BA_CHILD) &&
65 * Device specific bind function, WH+
68 * Pointer to TF handle
71 * Flag controlling shadow copy DB creation
74 * Pointer to resource allocation information
80 * - (0) if successful.
81 * - (-EINVAL) on parameter or internal failure.
84 tf_dev_bind_p4(struct tf *tfp,
86 struct tf_session_resources *resources,
87 struct tf_dev_info *dev_handle,
88 enum tf_wc_num_slice wc_num_slices)
93 bool no_rsv_flag = true;
94 struct tf_ident_cfg_parms ident_cfg;
95 struct tf_tbl_cfg_parms tbl_cfg;
96 struct tf_tcam_cfg_parms tcam_cfg;
97 struct tf_em_cfg_parms em_cfg;
98 struct tf_if_tbl_cfg_parms if_tbl_cfg;
99 struct tf_global_cfg_cfg_parms global_cfg;
100 struct tf_session *tfs;
102 /* Retrieve the session information */
103 rc = tf_session_get_session_internal(tfp, &tfs);
107 /* Initial function initialization */
108 dev_handle->ops = &tf_dev_ops_p4_init;
110 /* Initialize the modules */
112 rsv_cnt = tf_dev_reservation_check(TF_IDENT_TYPE_MAX,
114 (uint16_t *)resources->ident_cnt);
116 ident_cfg.num_elements = TF_IDENT_TYPE_MAX;
117 ident_cfg.cfg = tf_ident_p4;
118 ident_cfg.shadow_copy = shadow_copy;
119 ident_cfg.resources = resources;
120 rc = tf_ident_bind(tfp, &ident_cfg);
123 "Identifier initialization failure\n");
130 rsv_cnt = tf_dev_reservation_check(TF_TBL_TYPE_MAX,
131 tf_tbl_p4[TF_DIR_RX],
132 (uint16_t *)resources->tbl_cnt);
134 tbl_cfg.num_elements = TF_TBL_TYPE_MAX;
135 tbl_cfg.cfg = tf_tbl_p4[TF_DIR_RX];
136 tbl_cfg.resources = resources;
137 rc = tf_tbl_bind(tfp, &tbl_cfg);
140 "Table initialization failure\n");
147 rsv_cnt = tf_dev_reservation_check(TF_TCAM_TBL_TYPE_MAX,
149 (uint16_t *)resources->tcam_cnt);
151 tcam_cfg.num_elements = TF_TCAM_TBL_TYPE_MAX;
152 tcam_cfg.cfg = tf_tcam_p4;
153 tcam_cfg.shadow_copy = shadow_copy;
154 tcam_cfg.resources = resources;
155 tcam_cfg.wc_num_slices = wc_num_slices;
156 #ifdef TF_TCAM_SHARED
157 rc = tf_tcam_shared_bind(tfp, &tcam_cfg);
158 #else /* !TF_TCAM_SHARED */
159 rc = tf_tcam_bind(tfp, &tcam_cfg);
163 "TCAM initialization failure\n");
173 em_cfg.cfg = tf_em_ext_p4;
174 rsv_cnt = tf_dev_reservation_check(TF_EM_TBL_TYPE_MAX,
176 (uint16_t *)resources->em_cnt);
178 em_cfg.num_elements = TF_EM_TBL_TYPE_MAX;
179 em_cfg.resources = resources;
180 em_cfg.mem_type = TF_EEM_MEM_TYPE_HOST;
181 rc = tf_em_ext_common_bind(tfp, &em_cfg);
184 "EEM initialization failure\n");
193 rsv_cnt = tf_dev_reservation_check(TF_EM_TBL_TYPE_MAX,
195 (uint16_t *)resources->em_cnt);
197 em_cfg.num_elements = TF_EM_TBL_TYPE_MAX;
198 em_cfg.cfg = tf_em_int_p4;
199 em_cfg.resources = resources;
200 em_cfg.mem_type = 0; /* Not used by EM */
202 rc = tf_em_int_bind(tfp, &em_cfg);
205 "EM initialization failure\n");
212 * There is no rm reserved for any tables
217 "No rm reserved for any tables\n");
224 if_tbl_cfg.num_elements = TF_IF_TBL_TYPE_MAX;
225 if_tbl_cfg.cfg = tf_if_tbl_p4;
226 if_tbl_cfg.shadow_copy = shadow_copy;
227 rc = tf_if_tbl_bind(tfp, &if_tbl_cfg);
230 "IF Table initialization failure\n");
234 if (!tf_session_is_shared_session(tfs)) {
238 global_cfg.num_elements = TF_GLOBAL_CFG_TYPE_MAX;
239 global_cfg.cfg = tf_global_cfg_p4;
240 rc = tf_global_cfg_bind(tfp, &global_cfg);
243 "Global Cfg initialization failure\n");
247 /* Final function initialization */
248 dev_handle->ops = &tf_dev_ops_p4;
253 /* Cleanup of already created modules */
254 frc = tf_dev_unbind_p4(tfp);
262 * Device specific unbind function, WH+
265 * Pointer to TF handle
268 * - (0) if successful.
269 * - (-EINVAL) on failure.
272 tf_dev_unbind_p4(struct tf *tfp)
276 struct tf_session *tfs;
278 /* Retrieve the session information */
279 rc = tf_session_get_session_internal(tfp, &tfs);
283 /* Unbind all the support modules. As this is only done on
284 * close we only report errors as everything has to be cleaned
287 * In case of residuals TCAMs are cleaned up first as to
288 * invalidate the pipeline in a clean manner.
290 #ifdef TF_TCAM_SHARED
291 rc = tf_tcam_shared_unbind(tfp);
292 #else /* !TF_TCAM_SHARED */
293 rc = tf_tcam_unbind(tfp);
294 #endif /* TF_TCAM_SHARED */
297 "Device unbind failed, TCAM\n");
301 rc = tf_ident_unbind(tfp);
304 "Device unbind failed, Identifier\n");
308 rc = tf_tbl_unbind(tfp);
311 "Device unbind failed, Table Type\n");
315 rc = tf_em_ext_common_unbind(tfp);
318 "Device unbind failed, EEM\n");
322 rc = tf_em_int_unbind(tfp);
325 "Device unbind failed, EM\n");
329 if (!tf_session_is_shared_session(tfs)) {
330 rc = tf_if_tbl_unbind(tfp);
333 "Device unbind failed, IF Table Type\n");
337 rc = tf_global_cfg_unbind(tfp);
340 "Device unbind failed, Global Cfg Type\n");
352 * Device specific bind function, THOR
355 * Pointer to TF handle
358 * Flag controlling shadow copy DB creation
361 * Pointer to resource allocation information
367 * - (0) if successful.
368 * - (-EINVAL) on parameter or internal failure.
371 tf_dev_bind_p58(struct tf *tfp,
373 struct tf_session_resources *resources,
374 struct tf_dev_info *dev_handle,
375 enum tf_wc_num_slice wc_num_slices)
380 bool no_rsv_flag = true;
381 struct tf_ident_cfg_parms ident_cfg;
382 struct tf_tbl_cfg_parms tbl_cfg;
383 struct tf_tcam_cfg_parms tcam_cfg;
384 struct tf_em_cfg_parms em_cfg;
385 struct tf_if_tbl_cfg_parms if_tbl_cfg;
386 struct tf_global_cfg_cfg_parms global_cfg;
387 struct tf_session *tfs;
389 /* Initial function initialization */
390 dev_handle->ops = &tf_dev_ops_p58_init;
392 /* Retrieve the session information */
393 rc = tf_session_get_session_internal(tfp, &tfs);
397 rsv_cnt = tf_dev_reservation_check(TF_IDENT_TYPE_MAX,
399 (uint16_t *)resources->ident_cnt);
401 ident_cfg.num_elements = TF_IDENT_TYPE_MAX;
402 ident_cfg.cfg = tf_ident_p58;
403 ident_cfg.shadow_copy = shadow_copy;
404 ident_cfg.resources = resources;
405 rc = tf_ident_bind(tfp, &ident_cfg);
408 "Identifier initialization failure\n");
414 rsv_cnt = tf_dev_reservation_check(TF_TBL_TYPE_MAX,
415 tf_tbl_p58[TF_DIR_RX],
416 (uint16_t *)resources->tbl_cnt);
417 rsv_cnt += tf_dev_reservation_check(TF_TBL_TYPE_MAX,
418 tf_tbl_p58[TF_DIR_TX],
419 (uint16_t *)resources->tbl_cnt);
421 tbl_cfg.num_elements = TF_TBL_TYPE_MAX;
422 tbl_cfg.cfg = tf_tbl_p58[TF_DIR_RX];
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);