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"
15 /* Forward declarations */
16 static int tf_dev_unbind_p4(struct tf *tfp);
17 static int tf_dev_unbind_p58(struct tf *tfp);
20 * Resource Reservation Check function
23 * Number of module subtypes
26 * Pointer to rm element config
29 * Pointer to resource reservation array
32 * - (n) number of tables in module that have non-zero reservation count.
35 tf_dev_reservation_check(uint16_t count,
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(TF_IDENT_TYPE_MAX,
99 (uint16_t *)resources->ident_cnt);
101 ident_cfg.num_elements = TF_IDENT_TYPE_MAX;
102 ident_cfg.cfg = tf_ident_p4;
103 ident_cfg.shadow_copy = shadow_copy;
104 ident_cfg.resources = resources;
105 rc = tf_ident_bind(tfp, &ident_cfg);
108 "Identifier initialization failure\n");
115 rsv_cnt = tf_dev_reservation_check(TF_TBL_TYPE_MAX,
117 (uint16_t *)resources->tbl_cnt);
119 tbl_cfg.num_elements = TF_TBL_TYPE_MAX;
120 tbl_cfg.cfg = tf_tbl_p4;
121 tbl_cfg.shadow_copy = shadow_copy;
122 tbl_cfg.resources = resources;
123 rc = tf_tbl_bind(tfp, &tbl_cfg);
126 "Table initialization failure\n");
133 rsv_cnt = tf_dev_reservation_check(TF_TCAM_TBL_TYPE_MAX,
135 (uint16_t *)resources->tcam_cnt);
137 tcam_cfg.num_elements = TF_TCAM_TBL_TYPE_MAX;
138 tcam_cfg.cfg = tf_tcam_p4;
139 tcam_cfg.shadow_copy = shadow_copy;
140 tcam_cfg.resources = resources;
141 rc = tf_tcam_bind(tfp, &tcam_cfg);
144 "TCAM initialization failure\n");
154 em_cfg.cfg = tf_em_ext_p4;
155 rsv_cnt = tf_dev_reservation_check(TF_EM_TBL_TYPE_MAX,
157 (uint16_t *)resources->em_cnt);
159 em_cfg.num_elements = TF_EM_TBL_TYPE_MAX;
160 em_cfg.resources = resources;
161 em_cfg.mem_type = TF_EEM_MEM_TYPE_HOST;
162 rc = tf_em_ext_common_bind(tfp, &em_cfg);
165 "EEM initialization failure\n");
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.cfg = tf_em_int_p4;
180 em_cfg.resources = resources;
181 em_cfg.mem_type = 0; /* Not used by EM */
183 rc = tf_em_int_bind(tfp, &em_cfg);
186 "EM initialization failure\n");
193 * There is no rm reserved for any tables
198 "No rm reserved for any tables\n");
205 if_tbl_cfg.num_elements = TF_IF_TBL_TYPE_MAX;
206 if_tbl_cfg.cfg = tf_if_tbl_p4;
207 if_tbl_cfg.shadow_copy = shadow_copy;
208 rc = tf_if_tbl_bind(tfp, &if_tbl_cfg);
211 "IF Table initialization failure\n");
218 global_cfg.num_elements = TF_GLOBAL_CFG_TYPE_MAX;
219 global_cfg.cfg = tf_global_cfg_p4;
220 rc = tf_global_cfg_bind(tfp, &global_cfg);
223 "Global Cfg initialization failure\n");
227 /* Final function initialization */
228 dev_handle->ops = &tf_dev_ops_p4;
233 /* Cleanup of already created modules */
234 frc = tf_dev_unbind_p4(tfp);
242 * Device specific unbind function, WH+
245 * Pointer to TF handle
248 * - (0) if successful.
249 * - (-EINVAL) on failure.
252 tf_dev_unbind_p4(struct tf *tfp)
257 /* Unbind all the support modules. As this is only done on
258 * close we only report errors as everything has to be cleaned
261 * In case of residuals TCAMs are cleaned up first as to
262 * invalidate the pipeline in a clean manner.
264 rc = tf_tcam_unbind(tfp);
267 "Device unbind failed, TCAM\n");
271 rc = tf_ident_unbind(tfp);
274 "Device unbind failed, Identifier\n");
278 rc = tf_tbl_unbind(tfp);
281 "Device unbind failed, Table Type\n");
285 rc = tf_em_ext_common_unbind(tfp);
288 "Device unbind failed, EEM\n");
292 rc = tf_em_int_unbind(tfp);
295 "Device unbind failed, EM\n");
299 rc = tf_if_tbl_unbind(tfp);
302 "Device unbind failed, IF Table Type\n");
306 rc = tf_global_cfg_unbind(tfp);
309 "Device unbind failed, Global Cfg Type\n");
320 * Device specific bind function, THOR
323 * Pointer to TF handle
326 * Flag controlling shadow copy DB creation
329 * Pointer to resource allocation information
335 * - (0) if successful.
336 * - (-EINVAL) on parameter or internal failure.
339 tf_dev_bind_p58(struct tf *tfp,
341 struct tf_session_resources *resources,
342 struct tf_dev_info *dev_handle)
347 bool no_rsv_flag = true;
348 struct tf_ident_cfg_parms ident_cfg;
349 struct tf_tbl_cfg_parms tbl_cfg;
350 struct tf_tcam_cfg_parms tcam_cfg;
351 struct tf_em_cfg_parms em_cfg;
352 struct tf_if_tbl_cfg_parms if_tbl_cfg;
353 struct tf_global_cfg_cfg_parms global_cfg;
355 /* Initial function initialization */
356 dev_handle->ops = &tf_dev_ops_p58_init;
358 rsv_cnt = tf_dev_reservation_check(TF_IDENT_TYPE_MAX,
360 (uint16_t *)resources->ident_cnt);
362 ident_cfg.num_elements = TF_IDENT_TYPE_MAX;
363 ident_cfg.cfg = tf_ident_p58;
364 ident_cfg.shadow_copy = shadow_copy;
365 ident_cfg.resources = resources;
366 rc = tf_ident_bind(tfp, &ident_cfg);
369 "Identifier initialization failure\n");
375 rsv_cnt = tf_dev_reservation_check(TF_TBL_TYPE_MAX,
377 (uint16_t *)resources->tbl_cnt);
379 tbl_cfg.num_elements = TF_TBL_TYPE_MAX;
380 tbl_cfg.cfg = tf_tbl_p58;
381 tbl_cfg.shadow_copy = shadow_copy;
382 tbl_cfg.resources = resources;
383 rc = tf_tbl_bind(tfp, &tbl_cfg);
386 "Table initialization failure\n");
392 rsv_cnt = tf_dev_reservation_check(TF_TCAM_TBL_TYPE_MAX,
394 (uint16_t *)resources->tcam_cnt);
396 tcam_cfg.num_elements = TF_TCAM_TBL_TYPE_MAX;
397 tcam_cfg.cfg = tf_tcam_p58;
398 tcam_cfg.shadow_copy = shadow_copy;
399 tcam_cfg.resources = resources;
400 rc = tf_tcam_bind(tfp, &tcam_cfg);
403 "TCAM initialization failure\n");
412 rsv_cnt = tf_dev_reservation_check(TF_EM_TBL_TYPE_MAX,
414 (uint16_t *)resources->em_cnt);
416 em_cfg.num_elements = TF_EM_TBL_TYPE_MAX;
417 em_cfg.cfg = tf_em_int_p58;
418 em_cfg.resources = resources;
419 em_cfg.mem_type = 0; /* Not used by EM */
421 rc = tf_em_int_bind(tfp, &em_cfg);
424 "EM initialization failure\n");
431 * There is no rm reserved for any tables
436 "No rm reserved for any tables\n");
443 if_tbl_cfg.num_elements = TF_IF_TBL_TYPE_MAX;
444 if_tbl_cfg.cfg = tf_if_tbl_p58;
445 if_tbl_cfg.shadow_copy = shadow_copy;
446 rc = tf_if_tbl_bind(tfp, &if_tbl_cfg);
449 "IF Table initialization failure\n");
456 global_cfg.num_elements = TF_GLOBAL_CFG_TYPE_MAX;
457 global_cfg.cfg = tf_global_cfg_p58;
458 rc = tf_global_cfg_bind(tfp, &global_cfg);
461 "Global Cfg initialization failure\n");
465 /* Final function initialization */
466 dev_handle->ops = &tf_dev_ops_p58;
471 /* Cleanup of already created modules */
472 frc = tf_dev_unbind_p58(tfp);
480 * Device specific unbind function, THOR
483 * Pointer to TF handle
486 * - (0) if successful.
487 * - (-EINVAL) on failure.
490 tf_dev_unbind_p58(struct tf *tfp)
495 /* Unbind all the support modules. As this is only done on
496 * close we only report errors as everything has to be cleaned
499 * In case of residuals TCAMs are cleaned up first as to
500 * invalidate the pipeline in a clean manner.
502 rc = tf_tcam_unbind(tfp);
505 "Device unbind failed, TCAM\n");
509 rc = tf_ident_unbind(tfp);
512 "Device unbind failed, Identifier\n");
516 rc = tf_tbl_unbind(tfp);
519 "Device unbind failed, Table Type\n");
523 rc = tf_em_int_unbind(tfp);
526 "Device unbind failed, EM\n");
530 rc = tf_if_tbl_unbind(tfp);
533 "Device unbind failed, IF Table Type\n");
537 rc = tf_global_cfg_unbind(tfp);
540 "Device unbind failed, Global Cfg Type\n");
551 tf_dev_bind(struct tf *tfp __rte_unused,
552 enum tf_device_type type,
554 struct tf_session_resources *resources,
555 struct tf_dev_info *dev_handle)
558 case TF_DEVICE_TYPE_WH:
559 case TF_DEVICE_TYPE_SR:
560 dev_handle->type = type;
561 return tf_dev_bind_p4(tfp,
565 case TF_DEVICE_TYPE_THOR:
566 dev_handle->type = type;
567 return tf_dev_bind_p58(tfp,
579 tf_dev_bind_ops(enum tf_device_type type,
580 struct tf_dev_info *dev_handle)
583 case TF_DEVICE_TYPE_WH:
584 case TF_DEVICE_TYPE_SR:
585 dev_handle->ops = &tf_dev_ops_p4_init;
587 case TF_DEVICE_TYPE_THOR:
588 dev_handle->ops = &tf_dev_ops_p58_init;
600 tf_dev_unbind(struct tf *tfp,
601 struct tf_dev_info *dev_handle)
603 switch (dev_handle->type) {
604 case TF_DEVICE_TYPE_WH:
605 case TF_DEVICE_TYPE_SR:
606 return tf_dev_unbind_p4(tfp);
607 case TF_DEVICE_TYPE_THOR:
608 return tf_dev_unbind_p58(tfp);