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");
222 if_tbl_cfg.num_elements = TF_IF_TBL_TYPE_MAX;
223 if_tbl_cfg.cfg = tf_if_tbl_p4;
224 if_tbl_cfg.shadow_copy = shadow_copy;
225 rc = tf_if_tbl_bind(tfp, &if_tbl_cfg);
228 "IF Table initialization failure\n");
232 if (!tf_session_is_shared_session(tfs)) {
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)
274 struct tf_session *tfs;
276 /* Retrieve the session information */
277 rc = tf_session_get_session_internal(tfp, &tfs);
281 /* Unbind all the support modules. As this is only done on
282 * close we only report errors as everything has to be cleaned
285 * In case of residuals TCAMs are cleaned up first as to
286 * invalidate the pipeline in a clean manner.
288 #ifdef TF_TCAM_SHARED
289 rc = tf_tcam_shared_unbind(tfp);
290 #else /* !TF_TCAM_SHARED */
291 rc = tf_tcam_unbind(tfp);
292 #endif /* TF_TCAM_SHARED */
295 "Device unbind failed, TCAM\n");
299 rc = tf_ident_unbind(tfp);
302 "Device unbind failed, Identifier\n");
306 rc = tf_tbl_unbind(tfp);
309 "Device unbind failed, Table Type\n");
313 rc = tf_em_ext_common_unbind(tfp);
316 "Device unbind failed, EEM\n");
320 rc = tf_em_int_unbind(tfp);
323 "Device unbind failed, EM\n");
327 if (!tf_session_is_shared_session(tfs)) {
328 rc = tf_if_tbl_unbind(tfp);
331 "Device unbind failed, IF Table Type\n");
335 rc = tf_global_cfg_unbind(tfp);
338 "Device unbind failed, Global Cfg Type\n");
350 * Device specific bind function, THOR
353 * Pointer to TF handle
356 * Flag controlling shadow copy DB creation
359 * Pointer to resource allocation information
365 * - (0) if successful.
366 * - (-EINVAL) on parameter or internal failure.
369 tf_dev_bind_p58(struct tf *tfp,
371 struct tf_session_resources *resources,
372 struct tf_dev_info *dev_handle)
377 bool no_rsv_flag = true;
378 struct tf_ident_cfg_parms ident_cfg;
379 struct tf_tbl_cfg_parms tbl_cfg;
380 struct tf_tcam_cfg_parms tcam_cfg;
381 struct tf_em_cfg_parms em_cfg;
382 struct tf_if_tbl_cfg_parms if_tbl_cfg;
383 struct tf_global_cfg_cfg_parms global_cfg;
384 struct tf_session *tfs;
386 /* Initial function initialization */
387 dev_handle->ops = &tf_dev_ops_p58_init;
389 /* Retrieve the session information */
390 rc = tf_session_get_session_internal(tfp, &tfs);
394 rsv_cnt = tf_dev_reservation_check(TF_IDENT_TYPE_MAX,
396 (uint16_t *)resources->ident_cnt);
398 ident_cfg.num_elements = TF_IDENT_TYPE_MAX;
399 ident_cfg.cfg = tf_ident_p58;
400 ident_cfg.shadow_copy = shadow_copy;
401 ident_cfg.resources = resources;
402 rc = tf_ident_bind(tfp, &ident_cfg);
405 "Identifier initialization failure\n");
411 rsv_cnt = tf_dev_reservation_check(TF_TBL_TYPE_MAX,
413 (uint16_t *)resources->tbl_cnt);
415 tbl_cfg.num_elements = TF_TBL_TYPE_MAX;
416 tbl_cfg.cfg = tf_tbl_p58;
417 tbl_cfg.shadow_copy = shadow_copy;
418 tbl_cfg.resources = resources;
419 rc = tf_tbl_bind(tfp, &tbl_cfg);
422 "Table initialization failure\n");
428 rsv_cnt = tf_dev_reservation_check(TF_TCAM_TBL_TYPE_MAX,
430 (uint16_t *)resources->tcam_cnt);
432 tcam_cfg.num_elements = TF_TCAM_TBL_TYPE_MAX;
433 tcam_cfg.cfg = tf_tcam_p58;
434 tcam_cfg.shadow_copy = shadow_copy;
435 tcam_cfg.resources = resources;
436 #ifdef TF_TCAM_SHARED
437 rc = tf_tcam_shared_bind(tfp, &tcam_cfg);
438 #else /* !TF_TCAM_SHARED */
439 rc = tf_tcam_bind(tfp, &tcam_cfg);
443 "TCAM initialization failure\n");
452 rsv_cnt = tf_dev_reservation_check(TF_EM_TBL_TYPE_MAX,
454 (uint16_t *)resources->em_cnt);
456 em_cfg.num_elements = TF_EM_TBL_TYPE_MAX;
457 em_cfg.cfg = tf_em_int_p58;
458 em_cfg.resources = resources;
459 em_cfg.mem_type = 0; /* Not used by EM */
461 rc = tf_em_int_bind(tfp, &em_cfg);
464 "EM initialization failure\n");
471 * There is no rm reserved for any tables
476 "No rm reserved for any tables\n");
483 if_tbl_cfg.num_elements = TF_IF_TBL_TYPE_MAX;
484 if_tbl_cfg.cfg = tf_if_tbl_p58;
485 if_tbl_cfg.shadow_copy = shadow_copy;
486 rc = tf_if_tbl_bind(tfp, &if_tbl_cfg);
489 "IF Table initialization failure\n");
493 if (!tf_session_is_shared_session(tfs)) {
497 global_cfg.num_elements = TF_GLOBAL_CFG_TYPE_MAX;
498 global_cfg.cfg = tf_global_cfg_p58;
499 rc = tf_global_cfg_bind(tfp, &global_cfg);
502 "Global Cfg initialization failure\n");
507 /* Final function initialization */
508 dev_handle->ops = &tf_dev_ops_p58;
513 /* Cleanup of already created modules */
514 frc = tf_dev_unbind_p58(tfp);
522 * Device specific unbind function, THOR
525 * Pointer to TF handle
528 * - (0) if successful.
529 * - (-EINVAL) on failure.
532 tf_dev_unbind_p58(struct tf *tfp)
536 struct tf_session *tfs;
538 /* Retrieve the session information */
539 rc = tf_session_get_session_internal(tfp, &tfs);
543 /* Unbind all the support modules. As this is only done on
544 * close we only report errors as everything has to be cleaned
547 * In case of residuals TCAMs are cleaned up first as to
548 * invalidate the pipeline in a clean manner.
550 #ifdef TF_TCAM_SHARED
551 rc = tf_tcam_shared_unbind(tfp);
552 #else /* !TF_TCAM_SHARED */
553 rc = tf_tcam_unbind(tfp);
554 #endif /* TF_TCAM_SHARED */
557 "Device unbind failed, TCAM\n");
561 rc = tf_ident_unbind(tfp);
564 "Device unbind failed, Identifier\n");
568 rc = tf_tbl_unbind(tfp);
571 "Device unbind failed, Table Type\n");
575 rc = tf_em_int_unbind(tfp);
578 "Device unbind failed, EM\n");
582 rc = tf_if_tbl_unbind(tfp);
585 "Device unbind failed, IF Table Type\n");
589 if (!tf_session_is_shared_session(tfs)) {
590 rc = tf_global_cfg_unbind(tfp);
593 "Device unbind failed, Global Cfg Type\n");
605 tf_dev_bind(struct tf *tfp __rte_unused,
606 enum tf_device_type type,
608 struct tf_session_resources *resources,
609 struct tf_dev_info *dev_handle)
612 case TF_DEVICE_TYPE_WH:
613 case TF_DEVICE_TYPE_SR:
614 dev_handle->type = type;
615 return tf_dev_bind_p4(tfp,
619 case TF_DEVICE_TYPE_THOR:
620 dev_handle->type = type;
621 return tf_dev_bind_p58(tfp,
633 tf_dev_bind_ops(enum tf_device_type type,
634 struct tf_dev_info *dev_handle)
637 case TF_DEVICE_TYPE_WH:
638 case TF_DEVICE_TYPE_SR:
639 dev_handle->ops = &tf_dev_ops_p4_init;
641 case TF_DEVICE_TYPE_THOR:
642 dev_handle->ops = &tf_dev_ops_p58_init;
654 tf_dev_unbind(struct tf *tfp,
655 struct tf_dev_info *dev_handle)
657 switch (dev_handle->type) {
658 case TF_DEVICE_TYPE_WH:
659 case TF_DEVICE_TYPE_SR:
660 return tf_dev_unbind_p4(tfp);
661 case TF_DEVICE_TYPE_THOR:
662 return tf_dev_unbind_p58(tfp);