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 ||
49 TF_RM_ELEM_CFG_HCAPI_BA_PARENT ||
51 TF_RM_ELEM_CFG_HCAPI_BA_CHILD) &&
61 * Device specific bind function, WH+
64 * Pointer to TF handle
67 * Flag controlling shadow copy DB creation
70 * Pointer to resource allocation information
76 * - (0) if successful.
77 * - (-EINVAL) on parameter or internal failure.
80 tf_dev_bind_p4(struct tf *tfp,
82 struct tf_session_resources *resources,
83 struct tf_dev_info *dev_handle)
88 bool no_rsv_flag = true;
89 struct tf_ident_cfg_parms ident_cfg;
90 struct tf_tbl_cfg_parms tbl_cfg;
91 struct tf_tcam_cfg_parms tcam_cfg;
92 struct tf_em_cfg_parms em_cfg;
93 struct tf_if_tbl_cfg_parms if_tbl_cfg;
94 struct tf_global_cfg_cfg_parms global_cfg;
96 /* Initial function initialization */
97 dev_handle->ops = &tf_dev_ops_p4_init;
99 /* Initialize the modules */
101 rsv_cnt = tf_dev_reservation_check(TF_IDENT_TYPE_MAX,
103 (uint16_t *)resources->ident_cnt);
105 ident_cfg.num_elements = TF_IDENT_TYPE_MAX;
106 ident_cfg.cfg = tf_ident_p4;
107 ident_cfg.shadow_copy = shadow_copy;
108 ident_cfg.resources = resources;
109 rc = tf_ident_bind(tfp, &ident_cfg);
112 "Identifier initialization failure\n");
119 rsv_cnt = tf_dev_reservation_check(TF_TBL_TYPE_MAX,
121 (uint16_t *)resources->tbl_cnt);
123 tbl_cfg.num_elements = TF_TBL_TYPE_MAX;
124 tbl_cfg.cfg = tf_tbl_p4;
125 tbl_cfg.shadow_copy = shadow_copy;
126 tbl_cfg.resources = resources;
127 rc = tf_tbl_bind(tfp, &tbl_cfg);
130 "Table initialization failure\n");
137 rsv_cnt = tf_dev_reservation_check(TF_TCAM_TBL_TYPE_MAX,
139 (uint16_t *)resources->tcam_cnt);
141 tcam_cfg.num_elements = TF_TCAM_TBL_TYPE_MAX;
142 tcam_cfg.cfg = tf_tcam_p4;
143 tcam_cfg.shadow_copy = shadow_copy;
144 tcam_cfg.resources = resources;
145 rc = tf_tcam_bind(tfp, &tcam_cfg);
148 "TCAM initialization failure\n");
158 em_cfg.cfg = tf_em_ext_p4;
159 rsv_cnt = tf_dev_reservation_check(TF_EM_TBL_TYPE_MAX,
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(TF_EM_TBL_TYPE_MAX,
180 (uint16_t *)resources->em_cnt);
182 em_cfg.num_elements = TF_EM_TBL_TYPE_MAX;
183 em_cfg.cfg = tf_em_int_p4;
184 em_cfg.resources = resources;
185 em_cfg.mem_type = 0; /* Not used by EM */
187 rc = tf_em_int_bind(tfp, &em_cfg);
190 "EM initialization failure\n");
197 * There is no rm reserved for any tables
202 "No rm reserved for any tables\n");
209 if_tbl_cfg.num_elements = TF_IF_TBL_TYPE_MAX;
210 if_tbl_cfg.cfg = tf_if_tbl_p4;
211 if_tbl_cfg.shadow_copy = shadow_copy;
212 rc = tf_if_tbl_bind(tfp, &if_tbl_cfg);
215 "IF Table initialization failure\n");
222 global_cfg.num_elements = TF_GLOBAL_CFG_TYPE_MAX;
223 global_cfg.cfg = tf_global_cfg_p4;
224 rc = tf_global_cfg_bind(tfp, &global_cfg);
227 "Global Cfg initialization failure\n");
231 /* Final function initialization */
232 dev_handle->ops = &tf_dev_ops_p4;
237 /* Cleanup of already created modules */
238 frc = tf_dev_unbind_p4(tfp);
246 * Device specific unbind function, WH+
249 * Pointer to TF handle
252 * - (0) if successful.
253 * - (-EINVAL) on failure.
256 tf_dev_unbind_p4(struct tf *tfp)
261 /* Unbind all the support modules. As this is only done on
262 * close we only report errors as everything has to be cleaned
265 * In case of residuals TCAMs are cleaned up first as to
266 * invalidate the pipeline in a clean manner.
268 rc = tf_tcam_unbind(tfp);
271 "Device unbind failed, TCAM\n");
275 rc = tf_ident_unbind(tfp);
278 "Device unbind failed, Identifier\n");
282 rc = tf_tbl_unbind(tfp);
285 "Device unbind failed, Table Type\n");
289 rc = tf_em_ext_common_unbind(tfp);
292 "Device unbind failed, EEM\n");
296 rc = tf_em_int_unbind(tfp);
299 "Device unbind failed, EM\n");
303 rc = tf_if_tbl_unbind(tfp);
306 "Device unbind failed, IF Table Type\n");
310 rc = tf_global_cfg_unbind(tfp);
313 "Device unbind failed, Global Cfg Type\n");
324 * Device specific bind function, THOR
327 * Pointer to TF handle
330 * Flag controlling shadow copy DB creation
333 * Pointer to resource allocation information
339 * - (0) if successful.
340 * - (-EINVAL) on parameter or internal failure.
343 tf_dev_bind_p58(struct tf *tfp,
345 struct tf_session_resources *resources,
346 struct tf_dev_info *dev_handle)
351 bool no_rsv_flag = true;
352 struct tf_ident_cfg_parms ident_cfg;
353 struct tf_tbl_cfg_parms tbl_cfg;
354 struct tf_tcam_cfg_parms tcam_cfg;
355 struct tf_em_cfg_parms em_cfg;
356 struct tf_if_tbl_cfg_parms if_tbl_cfg;
357 struct tf_global_cfg_cfg_parms global_cfg;
358 struct tf_session *tfs;
360 /* Initial function initialization */
361 dev_handle->ops = &tf_dev_ops_p58_init;
363 /* Retrieve the session information */
364 rc = tf_session_get_session_internal(tfp, &tfs);
368 rsv_cnt = tf_dev_reservation_check(TF_IDENT_TYPE_MAX,
370 (uint16_t *)resources->ident_cnt);
372 ident_cfg.num_elements = TF_IDENT_TYPE_MAX;
373 ident_cfg.cfg = tf_ident_p58;
374 ident_cfg.shadow_copy = shadow_copy;
375 ident_cfg.resources = resources;
376 rc = tf_ident_bind(tfp, &ident_cfg);
379 "Identifier initialization failure\n");
385 rsv_cnt = tf_dev_reservation_check(TF_TBL_TYPE_MAX,
387 (uint16_t *)resources->tbl_cnt);
389 tbl_cfg.num_elements = TF_TBL_TYPE_MAX;
390 tbl_cfg.cfg = tf_tbl_p58;
391 tbl_cfg.shadow_copy = shadow_copy;
392 tbl_cfg.resources = resources;
393 rc = tf_tbl_bind(tfp, &tbl_cfg);
396 "Table initialization failure\n");
402 rsv_cnt = tf_dev_reservation_check(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(TF_EM_TBL_TYPE_MAX,
424 (uint16_t *)resources->em_cnt);
426 em_cfg.num_elements = TF_EM_TBL_TYPE_MAX;
427 em_cfg.cfg = tf_em_int_p58;
428 em_cfg.resources = resources;
429 em_cfg.mem_type = 0; /* Not used by EM */
431 rc = tf_em_int_bind(tfp, &em_cfg);
434 "EM initialization failure\n");
441 * There is no rm reserved for any tables
446 "No rm reserved for any tables\n");
453 if (!tf_session_is_shared_session(tfs)) {
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");
477 /* Final function initialization */
478 dev_handle->ops = &tf_dev_ops_p58;
483 /* Cleanup of already created modules */
484 frc = tf_dev_unbind_p58(tfp);
492 * Device specific unbind function, THOR
495 * Pointer to TF handle
498 * - (0) if successful.
499 * - (-EINVAL) on failure.
502 tf_dev_unbind_p58(struct tf *tfp)
506 struct tf_session *tfs;
508 /* Retrieve the session information */
509 rc = tf_session_get_session_internal(tfp, &tfs);
513 /* Unbind all the support modules. As this is only done on
514 * close we only report errors as everything has to be cleaned
517 * In case of residuals TCAMs are cleaned up first as to
518 * invalidate the pipeline in a clean manner.
520 rc = tf_tcam_unbind(tfp);
523 "Device unbind failed, TCAM\n");
527 rc = tf_ident_unbind(tfp);
530 "Device unbind failed, Identifier\n");
534 rc = tf_tbl_unbind(tfp);
537 "Device unbind failed, Table Type\n");
541 rc = tf_em_int_unbind(tfp);
544 "Device unbind failed, EM\n");
548 if (!tf_session_is_shared_session(tfs)) {
549 rc = tf_if_tbl_unbind(tfp);
552 "Device unbind failed, IF Table Type\n");
556 rc = tf_global_cfg_unbind(tfp);
559 "Device unbind failed, Global Cfg Type\n");
571 tf_dev_bind(struct tf *tfp __rte_unused,
572 enum tf_device_type type,
574 struct tf_session_resources *resources,
575 struct tf_dev_info *dev_handle)
578 case TF_DEVICE_TYPE_WH:
579 case TF_DEVICE_TYPE_SR:
580 dev_handle->type = type;
581 return tf_dev_bind_p4(tfp,
585 case TF_DEVICE_TYPE_THOR:
586 dev_handle->type = type;
587 return tf_dev_bind_p58(tfp,
599 tf_dev_bind_ops(enum tf_device_type type,
600 struct tf_dev_info *dev_handle)
603 case TF_DEVICE_TYPE_WH:
604 case TF_DEVICE_TYPE_SR:
605 dev_handle->ops = &tf_dev_ops_p4_init;
607 case TF_DEVICE_TYPE_THOR:
608 dev_handle->ops = &tf_dev_ops_p58_init;
620 tf_dev_unbind(struct tf *tfp,
621 struct tf_dev_info *dev_handle)
623 switch (dev_handle->type) {
624 case TF_DEVICE_TYPE_WH:
625 case TF_DEVICE_TYPE_SR:
626 return tf_dev_unbind_p4(tfp);
627 case TF_DEVICE_TYPE_THOR:
628 return tf_dev_unbind_p58(tfp);