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 * Resource Reservation Check function
22 * Pointer to TF handle
25 * Pointer to rm element config
28 * Pointer to resource reservation array
31 * - (n) number of tables that have non-zero reservation count.
34 tf_dev_reservation_check(struct tf *tfp __rte_unused,
36 struct tf_rm_element_cfg *cfg,
37 uint16_t *reservations)
43 for (i = 0; i < TF_DIR_MAX; i++) {
44 rm_num = (uint16_t *)reservations + i * count;
45 for (j = 0; j < count; j++) {
46 if ((cfg[j].cfg_type == TF_RM_ELEM_CFG_HCAPI ||
47 cfg[j].cfg_type == TF_RM_ELEM_CFG_HCAPI_BA) &&
57 * Device specific bind function, WH+
60 * Pointer to TF handle
63 * Flag controlling shadow copy DB creation
66 * Pointer to resource allocation information
72 * - (0) if successful.
73 * - (-EINVAL) on parameter or internal failure.
76 tf_dev_bind_p4(struct tf *tfp,
78 struct tf_session_resources *resources,
79 struct tf_dev_info *dev_handle)
84 bool no_rsv_flag = true;
85 struct tf_ident_cfg_parms ident_cfg;
86 struct tf_tbl_cfg_parms tbl_cfg;
87 struct tf_tcam_cfg_parms tcam_cfg;
88 struct tf_em_cfg_parms em_cfg;
89 struct tf_if_tbl_cfg_parms if_tbl_cfg;
90 struct tf_global_cfg_cfg_parms global_cfg;
92 /* Initial function initialization */
93 dev_handle->ops = &tf_dev_ops_p4_init;
95 /* Initialize the modules */
97 rsv_cnt = tf_dev_reservation_check(tfp,
100 (uint16_t *)resources->ident_cnt);
102 ident_cfg.num_elements = TF_IDENT_TYPE_MAX;
103 ident_cfg.cfg = tf_ident_p4;
104 ident_cfg.shadow_copy = shadow_copy;
105 ident_cfg.resources = resources;
106 rc = tf_ident_bind(tfp, &ident_cfg);
109 "Identifier initialization failure\n");
116 rsv_cnt = tf_dev_reservation_check(tfp,
119 (uint16_t *)resources->tbl_cnt);
121 tbl_cfg.num_elements = TF_TBL_TYPE_MAX;
122 tbl_cfg.cfg = tf_tbl_p4;
123 tbl_cfg.shadow_copy = shadow_copy;
124 tbl_cfg.resources = resources;
125 rc = tf_tbl_bind(tfp, &tbl_cfg);
128 "Table initialization failure\n");
135 rsv_cnt = tf_dev_reservation_check(tfp,
136 TF_TCAM_TBL_TYPE_MAX,
138 (uint16_t *)resources->tcam_cnt);
140 tcam_cfg.num_elements = TF_TCAM_TBL_TYPE_MAX;
141 tcam_cfg.cfg = tf_tcam_p4;
142 tcam_cfg.shadow_copy = shadow_copy;
143 tcam_cfg.resources = resources;
144 rc = tf_tcam_bind(tfp, &tcam_cfg);
147 "TCAM initialization failure\n");
157 em_cfg.cfg = tf_em_ext_p4;
158 rsv_cnt = tf_dev_reservation_check(tfp,
161 (uint16_t *)resources->em_cnt);
163 em_cfg.num_elements = TF_EM_TBL_TYPE_MAX;
164 em_cfg.resources = resources;
165 em_cfg.mem_type = TF_EEM_MEM_TYPE_HOST;
166 rc = tf_em_ext_common_bind(tfp, &em_cfg);
169 "EEM initialization failure\n");
178 rsv_cnt = tf_dev_reservation_check(tfp,
181 (uint16_t *)resources->em_cnt);
183 em_cfg.num_elements = TF_EM_TBL_TYPE_MAX;
184 em_cfg.cfg = tf_em_int_p4;
185 em_cfg.resources = resources;
186 em_cfg.mem_type = 0; /* Not used by EM */
188 rc = tf_em_int_bind(tfp, &em_cfg);
191 "EM initialization failure\n");
198 * There is no rm reserved for any tables
203 "No rm reserved for any tables\n");
210 if_tbl_cfg.num_elements = TF_IF_TBL_TYPE_MAX;
211 if_tbl_cfg.cfg = tf_if_tbl_p4;
212 if_tbl_cfg.shadow_copy = shadow_copy;
213 rc = tf_if_tbl_bind(tfp, &if_tbl_cfg);
216 "IF Table initialization failure\n");
223 global_cfg.num_elements = TF_GLOBAL_CFG_TYPE_MAX;
224 global_cfg.cfg = tf_global_cfg_p4;
225 rc = tf_global_cfg_bind(tfp, &global_cfg);
228 "Global Cfg initialization failure\n");
232 /* Final function initialization */
233 dev_handle->ops = &tf_dev_ops_p4;
238 /* Cleanup of already created modules */
239 frc = tf_dev_unbind_p4(tfp);
247 * Device specific unbind function, WH+
250 * Pointer to TF handle
253 * - (0) if successful.
254 * - (-EINVAL) on failure.
257 tf_dev_unbind_p4(struct tf *tfp)
262 /* Unbind all the support modules. As this is only done on
263 * close we only report errors as everything has to be cleaned
266 * In case of residuals TCAMs are cleaned up first as to
267 * invalidate the pipeline in a clean manner.
269 rc = tf_tcam_unbind(tfp);
272 "Device unbind failed, TCAM\n");
276 rc = tf_ident_unbind(tfp);
279 "Device unbind failed, Identifier\n");
283 rc = tf_tbl_unbind(tfp);
286 "Device unbind failed, Table Type\n");
290 rc = tf_em_ext_common_unbind(tfp);
293 "Device unbind failed, EEM\n");
297 rc = tf_em_int_unbind(tfp);
300 "Device unbind failed, EM\n");
304 rc = tf_if_tbl_unbind(tfp);
307 "Device unbind failed, IF Table Type\n");
311 rc = tf_global_cfg_unbind(tfp);
314 "Device unbind failed, Global Cfg Type\n");
325 * Device specific bind function, THOR
328 * Pointer to TF handle
331 * Flag controlling shadow copy DB creation
334 * Pointer to resource allocation information
340 * - (0) if successful.
341 * - (-EINVAL) on parameter or internal failure.
344 tf_dev_bind_p58(struct tf *tfp,
346 struct tf_session_resources *resources,
347 struct tf_dev_info *dev_handle)
352 bool no_rsv_flag = true;
353 struct tf_ident_cfg_parms ident_cfg;
354 struct tf_tbl_cfg_parms tbl_cfg;
355 struct tf_tcam_cfg_parms tcam_cfg;
356 struct tf_em_cfg_parms em_cfg;
357 struct tf_if_tbl_cfg_parms if_tbl_cfg;
358 struct tf_global_cfg_cfg_parms global_cfg;
360 /* Initial function initialization */
361 dev_handle->ops = &tf_dev_ops_p58_init;
363 /* Initialize the modules */
365 rsv_cnt = tf_dev_reservation_check(tfp,
368 (uint16_t *)resources->ident_cnt);
370 ident_cfg.num_elements = TF_IDENT_TYPE_MAX;
371 ident_cfg.cfg = tf_ident_p58;
372 ident_cfg.shadow_copy = shadow_copy;
373 ident_cfg.resources = resources;
374 rc = tf_ident_bind(tfp, &ident_cfg);
377 "Identifier initialization failure\n");
383 rsv_cnt = tf_dev_reservation_check(tfp,
386 (uint16_t *)resources->tbl_cnt);
388 tbl_cfg.num_elements = TF_TBL_TYPE_MAX;
389 tbl_cfg.cfg = tf_tbl_p58;
390 tbl_cfg.shadow_copy = shadow_copy;
391 tbl_cfg.resources = resources;
392 rc = tf_tbl_bind(tfp, &tbl_cfg);
395 "Table initialization failure\n");
401 rsv_cnt = tf_dev_reservation_check(tfp,
402 TF_TCAM_TBL_TYPE_MAX,
404 (uint16_t *)resources->tcam_cnt);
406 tcam_cfg.num_elements = TF_TCAM_TBL_TYPE_MAX;
407 tcam_cfg.cfg = tf_tcam_p58;
408 tcam_cfg.shadow_copy = shadow_copy;
409 tcam_cfg.resources = resources;
410 rc = tf_tcam_bind(tfp, &tcam_cfg);
413 "TCAM initialization failure\n");
422 rsv_cnt = tf_dev_reservation_check(tfp,
425 (uint16_t *)resources->em_cnt);
427 em_cfg.num_elements = TF_EM_TBL_TYPE_MAX;
428 em_cfg.cfg = tf_em_int_p58;
429 em_cfg.resources = resources;
430 em_cfg.mem_type = 0; /* Not used by EM */
432 rc = tf_em_int_bind(tfp, &em_cfg);
435 "EM initialization failure\n");
442 * There is no rm reserved for any tables
447 "No rm reserved for any tables\n");
454 if_tbl_cfg.num_elements = TF_IF_TBL_TYPE_MAX;
455 if_tbl_cfg.cfg = tf_if_tbl_p58;
456 if_tbl_cfg.shadow_copy = shadow_copy;
457 rc = tf_if_tbl_bind(tfp, &if_tbl_cfg);
460 "IF Table initialization failure\n");
467 global_cfg.num_elements = TF_GLOBAL_CFG_TYPE_MAX;
468 global_cfg.cfg = tf_global_cfg_p58;
469 rc = tf_global_cfg_bind(tfp, &global_cfg);
472 "Global Cfg initialization failure\n");
476 /* Final function initialization */
477 dev_handle->ops = &tf_dev_ops_p58;
482 /* Cleanup of already created modules */
483 frc = tf_dev_unbind_p58(tfp);
491 * Device specific unbind function, THOR
494 * Pointer to TF handle
497 * - (0) if successful.
498 * - (-EINVAL) on failure.
501 tf_dev_unbind_p58(struct tf *tfp)
506 /* Unbind all the support modules. As this is only done on
507 * close we only report errors as everything has to be cleaned
510 * In case of residuals TCAMs are cleaned up first as to
511 * invalidate the pipeline in a clean manner.
513 rc = tf_tcam_unbind(tfp);
516 "Device unbind failed, TCAM\n");
520 rc = tf_ident_unbind(tfp);
523 "Device unbind failed, Identifier\n");
527 rc = tf_tbl_unbind(tfp);
530 "Device unbind failed, Table Type\n");
534 rc = tf_em_int_unbind(tfp);
537 "Device unbind failed, EM\n");
541 rc = tf_if_tbl_unbind(tfp);
544 "Device unbind failed, IF Table Type\n");
548 rc = tf_global_cfg_unbind(tfp);
551 "Device unbind failed, Global Cfg Type\n");
562 tf_dev_bind(struct tf *tfp __rte_unused,
563 enum tf_device_type type,
565 struct tf_session_resources *resources,
566 struct tf_dev_info *dev_handle)
569 case TF_DEVICE_TYPE_WH:
570 case TF_DEVICE_TYPE_SR:
571 dev_handle->type = type;
572 return tf_dev_bind_p4(tfp,
576 case TF_DEVICE_TYPE_THOR:
577 dev_handle->type = type;
578 return tf_dev_bind_p58(tfp,
590 tf_dev_bind_ops(enum tf_device_type type,
591 struct tf_dev_info *dev_handle)
594 case TF_DEVICE_TYPE_WH:
595 case TF_DEVICE_TYPE_SR:
596 dev_handle->ops = &tf_dev_ops_p4;
598 case TF_DEVICE_TYPE_THOR:
599 dev_handle->ops = &tf_dev_ops_p58;
611 tf_dev_unbind(struct tf *tfp,
612 struct tf_dev_info *dev_handle)
614 switch (dev_handle->type) {
615 case TF_DEVICE_TYPE_WH:
616 case TF_DEVICE_TYPE_SR:
617 return tf_dev_unbind_p4(tfp);
618 case TF_DEVICE_TYPE_THOR:
619 return tf_dev_unbind_p58(tfp);