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");
156 if (dev_handle->type == TF_DEVICE_TYPE_WH)
157 em_cfg.cfg = tf_em_ext_p4;
159 em_cfg.cfg = tf_em_ext_p45;
161 rsv_cnt = tf_dev_reservation_check(tfp,
164 (uint16_t *)resources->em_cnt);
166 em_cfg.num_elements = TF_EM_TBL_TYPE_MAX;
167 em_cfg.resources = resources;
168 em_cfg.mem_type = TF_EEM_MEM_TYPE_HOST;
169 rc = tf_em_ext_common_bind(tfp, &em_cfg);
172 "EEM initialization failure\n");
181 rsv_cnt = tf_dev_reservation_check(tfp,
184 (uint16_t *)resources->em_cnt);
186 em_cfg.num_elements = TF_EM_TBL_TYPE_MAX;
187 em_cfg.cfg = tf_em_int_p4;
188 em_cfg.resources = resources;
189 em_cfg.mem_type = 0; /* Not used by EM */
191 rc = tf_em_int_bind(tfp, &em_cfg);
194 "EM initialization failure\n");
201 * There is no rm reserved for any tables
206 "No rm reserved for any tables\n");
213 if_tbl_cfg.num_elements = TF_IF_TBL_TYPE_MAX;
214 if_tbl_cfg.cfg = tf_if_tbl_p4;
215 if_tbl_cfg.shadow_copy = shadow_copy;
216 rc = tf_if_tbl_bind(tfp, &if_tbl_cfg);
219 "IF Table initialization failure\n");
226 global_cfg.num_elements = TF_GLOBAL_CFG_TYPE_MAX;
227 global_cfg.cfg = tf_global_cfg_p4;
228 rc = tf_global_cfg_bind(tfp, &global_cfg);
231 "Global Cfg initialization failure\n");
235 /* Final function initialization */
236 dev_handle->ops = &tf_dev_ops_p4;
241 /* Cleanup of already created modules */
242 frc = tf_dev_unbind_p4(tfp);
250 * Device specific unbind function, WH+
253 * Pointer to TF handle
256 * - (0) if successful.
257 * - (-EINVAL) on failure.
260 tf_dev_unbind_p4(struct tf *tfp)
265 /* Unbind all the support modules. As this is only done on
266 * close we only report errors as everything has to be cleaned
269 * In case of residuals TCAMs are cleaned up first as to
270 * invalidate the pipeline in a clean manner.
272 rc = tf_tcam_unbind(tfp);
275 "Device unbind failed, TCAM\n");
279 rc = tf_ident_unbind(tfp);
282 "Device unbind failed, Identifier\n");
286 rc = tf_tbl_unbind(tfp);
289 "Device unbind failed, Table Type\n");
293 rc = tf_em_ext_common_unbind(tfp);
296 "Device unbind failed, EEM\n");
300 rc = tf_em_int_unbind(tfp);
303 "Device unbind failed, EM\n");
307 rc = tf_if_tbl_unbind(tfp);
310 "Device unbind failed, IF Table Type\n");
314 rc = tf_global_cfg_unbind(tfp);
317 "Device unbind failed, Global Cfg Type\n");
328 * Device specific bind function, THOR
331 * Pointer to TF handle
334 * Flag controlling shadow copy DB creation
337 * Pointer to resource allocation information
343 * - (0) if successful.
344 * - (-EINVAL) on parameter or internal failure.
347 tf_dev_bind_p58(struct tf *tfp,
349 struct tf_session_resources *resources,
350 struct tf_dev_info *dev_handle)
355 bool no_rsv_flag = true;
356 struct tf_ident_cfg_parms ident_cfg;
357 struct tf_tbl_cfg_parms tbl_cfg;
358 struct tf_tcam_cfg_parms tcam_cfg;
359 struct tf_em_cfg_parms em_cfg;
360 struct tf_if_tbl_cfg_parms if_tbl_cfg;
361 struct tf_global_cfg_cfg_parms global_cfg;
363 /* Initial function initialization */
364 dev_handle->ops = &tf_dev_ops_p58_init;
366 /* Initialize the modules */
368 rsv_cnt = tf_dev_reservation_check(tfp,
371 (uint16_t *)resources->ident_cnt);
373 ident_cfg.num_elements = TF_IDENT_TYPE_MAX;
374 ident_cfg.cfg = tf_ident_p58;
375 ident_cfg.shadow_copy = shadow_copy;
376 ident_cfg.resources = resources;
377 rc = tf_ident_bind(tfp, &ident_cfg);
380 "Identifier initialization failure\n");
386 rsv_cnt = tf_dev_reservation_check(tfp,
389 (uint16_t *)resources->tbl_cnt);
391 tbl_cfg.num_elements = TF_TBL_TYPE_MAX;
392 tbl_cfg.cfg = tf_tbl_p58;
393 tbl_cfg.shadow_copy = shadow_copy;
394 tbl_cfg.resources = resources;
395 rc = tf_tbl_bind(tfp, &tbl_cfg);
398 "Table initialization failure\n");
404 rsv_cnt = tf_dev_reservation_check(tfp,
405 TF_TCAM_TBL_TYPE_MAX,
407 (uint16_t *)resources->tcam_cnt);
409 tcam_cfg.num_elements = TF_TCAM_TBL_TYPE_MAX;
410 tcam_cfg.cfg = tf_tcam_p58;
411 tcam_cfg.shadow_copy = shadow_copy;
412 tcam_cfg.resources = resources;
413 rc = tf_tcam_bind(tfp, &tcam_cfg);
416 "TCAM initialization failure\n");
425 rsv_cnt = tf_dev_reservation_check(tfp,
428 (uint16_t *)resources->em_cnt);
430 em_cfg.num_elements = TF_EM_TBL_TYPE_MAX;
431 em_cfg.cfg = tf_em_int_p58;
432 em_cfg.resources = resources;
433 em_cfg.mem_type = 0; /* Not used by EM */
435 rc = tf_em_int_bind(tfp, &em_cfg);
438 "EM initialization failure\n");
445 * There is no rm reserved for any tables
450 "No rm reserved for any tables\n");
457 if_tbl_cfg.num_elements = TF_IF_TBL_TYPE_MAX;
458 if_tbl_cfg.cfg = tf_if_tbl_p58;
459 if_tbl_cfg.shadow_copy = shadow_copy;
460 rc = tf_if_tbl_bind(tfp, &if_tbl_cfg);
463 "IF Table initialization failure\n");
470 global_cfg.num_elements = TF_GLOBAL_CFG_TYPE_MAX;
471 global_cfg.cfg = tf_global_cfg_p58;
472 rc = tf_global_cfg_bind(tfp, &global_cfg);
475 "Global Cfg initialization failure\n");
479 /* Final function initialization */
480 dev_handle->ops = &tf_dev_ops_p58;
485 /* Cleanup of already created modules */
486 frc = tf_dev_unbind_p58(tfp);
494 * Device specific unbind function, THOR
497 * Pointer to TF handle
500 * - (0) if successful.
501 * - (-EINVAL) on failure.
504 tf_dev_unbind_p58(struct tf *tfp)
509 /* Unbind all the support modules. As this is only done on
510 * close we only report errors as everything has to be cleaned
513 * In case of residuals TCAMs are cleaned up first as to
514 * invalidate the pipeline in a clean manner.
516 rc = tf_tcam_unbind(tfp);
519 "Device unbind failed, TCAM\n");
523 rc = tf_ident_unbind(tfp);
526 "Device unbind failed, Identifier\n");
530 rc = tf_tbl_unbind(tfp);
533 "Device unbind failed, Table Type\n");
537 rc = tf_em_int_unbind(tfp);
540 "Device unbind failed, EM\n");
544 rc = tf_if_tbl_unbind(tfp);
547 "Device unbind failed, IF Table Type\n");
551 rc = tf_global_cfg_unbind(tfp);
554 "Device unbind failed, Global Cfg Type\n");
565 tf_dev_bind(struct tf *tfp __rte_unused,
566 enum tf_device_type type,
568 struct tf_session_resources *resources,
569 struct tf_dev_info *dev_handle)
572 case TF_DEVICE_TYPE_WH:
573 case TF_DEVICE_TYPE_SR:
574 dev_handle->type = type;
575 return tf_dev_bind_p4(tfp,
579 case TF_DEVICE_TYPE_THOR:
580 dev_handle->type = type;
581 return tf_dev_bind_p58(tfp,
593 tf_dev_bind_ops(enum tf_device_type type,
594 struct tf_dev_info *dev_handle)
597 case TF_DEVICE_TYPE_WH:
598 case TF_DEVICE_TYPE_SR:
599 dev_handle->ops = &tf_dev_ops_p4;
601 case TF_DEVICE_TYPE_THOR:
602 dev_handle->ops = &tf_dev_ops_p58;
614 tf_dev_unbind(struct tf *tfp,
615 struct tf_dev_info *dev_handle)
617 switch (dev_handle->type) {
618 case TF_DEVICE_TYPE_WH:
619 case TF_DEVICE_TYPE_SR:
620 return tf_dev_unbind_p4(tfp);
621 case TF_DEVICE_TYPE_THOR:
622 return tf_dev_unbind_p58(tfp);