1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2019-2020 Broadcom
7 #include "tf_device_p4.h"
12 /* Forward declarations */
13 static int dev_unbind_p4(struct tf *tfp);
16 * Device specific bind function, WH+
19 * Pointer to TF handle
22 * Flag controlling shadow copy DB creation
25 * Pointer to resource allocation information
31 * - (0) if successful.
32 * - (-EINVAL) on parameter or internal failure.
35 dev_bind_p4(struct tf *tfp,
37 struct tf_session_resources *resources,
38 struct tf_dev_info *dev_handle)
42 struct tf_ident_cfg_parms ident_cfg;
43 struct tf_tbl_cfg_parms tbl_cfg;
44 struct tf_tcam_cfg_parms tcam_cfg;
46 /* Initialize the modules */
48 ident_cfg.num_elements = TF_IDENT_TYPE_MAX;
49 ident_cfg.cfg = tf_ident_p4;
50 ident_cfg.shadow_copy = shadow_copy;
51 ident_cfg.resources = resources;
52 rc = tf_ident_bind(tfp, &ident_cfg);
55 "Identifier initialization failure\n");
59 tbl_cfg.num_elements = TF_TBL_TYPE_MAX;
60 tbl_cfg.cfg = tf_tbl_p4;
61 tbl_cfg.shadow_copy = shadow_copy;
62 tbl_cfg.resources = resources;
63 rc = tf_tbl_bind(tfp, &tbl_cfg);
66 "Table initialization failure\n");
70 tcam_cfg.num_elements = TF_TCAM_TBL_TYPE_MAX;
71 tcam_cfg.cfg = tf_tcam_p4;
72 tcam_cfg.shadow_copy = shadow_copy;
73 tcam_cfg.resources = resources;
74 rc = tf_tcam_bind(tfp, &tcam_cfg);
77 "TCAM initialization failure\n");
81 dev_handle->type = TF_DEVICE_TYPE_WH;
82 dev_handle->ops = &tf_dev_ops_p4;
87 /* Cleanup of already created modules */
88 frc = dev_unbind_p4(tfp);
96 * Device specific unbind function, WH+
99 * Pointer to TF handle
102 * - (0) if successful.
103 * - (-EINVAL) on failure.
106 dev_unbind_p4(struct tf *tfp)
111 /* Unbind all the support modules. As this is only done on
112 * close we only report errors as everything has to be cleaned
115 rc = tf_ident_unbind(tfp);
118 "Device unbind failed, Identifier\n");
122 rc = tf_tbl_unbind(tfp);
125 "Device unbind failed, Table Type\n");
129 rc = tf_tcam_unbind(tfp);
132 "Device unbind failed, TCAM\n");
143 dev_bind(struct tf *tfp __rte_unused,
144 enum tf_device_type type,
146 struct tf_session_resources *resources,
147 struct tf_dev_info *dev_handle)
150 case TF_DEVICE_TYPE_WH:
151 return dev_bind_p4(tfp,
163 dev_unbind(struct tf *tfp,
164 struct tf_dev_info *dev_handle)
166 switch (dev_handle->type) {
167 case TF_DEVICE_TYPE_WH:
168 return dev_unbind_p4(tfp);