1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2019-2020 Broadcom
7 #include "tf_device_p4.h"
13 /* Forward declarations */
14 static int tf_dev_unbind_p4(struct tf *tfp);
17 * Device specific bind function, WH+
20 * Pointer to TF handle
23 * Flag controlling shadow copy DB creation
26 * Pointer to resource allocation information
32 * - (0) if successful.
33 * - (-EINVAL) on parameter or internal failure.
36 tf_dev_bind_p4(struct tf *tfp,
38 struct tf_session_resources *resources,
39 struct tf_dev_info *dev_handle)
43 struct tf_ident_cfg_parms ident_cfg;
44 struct tf_tbl_cfg_parms tbl_cfg;
45 struct tf_tcam_cfg_parms tcam_cfg;
46 struct tf_em_cfg_parms em_cfg;
47 struct tf_if_tbl_cfg_parms if_tbl_cfg;
48 struct tf_global_cfg_cfg_parms global_cfg;
50 dev_handle->type = TF_DEVICE_TYPE_WH;
51 /* Initial function initialization */
52 dev_handle->ops = &tf_dev_ops_p4_init;
54 /* Initialize the modules */
56 ident_cfg.num_elements = TF_IDENT_TYPE_MAX;
57 ident_cfg.cfg = tf_ident_p4;
58 ident_cfg.shadow_copy = shadow_copy;
59 ident_cfg.resources = resources;
60 rc = tf_ident_bind(tfp, &ident_cfg);
63 "Identifier initialization failure\n");
67 tbl_cfg.num_elements = TF_TBL_TYPE_MAX;
68 tbl_cfg.cfg = tf_tbl_p4;
69 tbl_cfg.shadow_copy = shadow_copy;
70 tbl_cfg.resources = resources;
71 rc = tf_tbl_bind(tfp, &tbl_cfg);
74 "Table initialization failure\n");
78 tcam_cfg.num_elements = TF_TCAM_TBL_TYPE_MAX;
79 tcam_cfg.cfg = tf_tcam_p4;
80 tcam_cfg.shadow_copy = shadow_copy;
81 tcam_cfg.resources = resources;
82 rc = tf_tcam_bind(tfp, &tcam_cfg);
85 "TCAM initialization failure\n");
92 em_cfg.num_elements = TF_EM_TBL_TYPE_MAX;
93 em_cfg.cfg = tf_em_ext_p4;
94 em_cfg.resources = resources;
95 em_cfg.mem_type = TF_EEM_MEM_TYPE_HOST;
97 rc = tf_em_ext_common_bind(tfp, &em_cfg);
100 "EEM initialization failure\n");
107 em_cfg.num_elements = TF_EM_TBL_TYPE_MAX;
108 em_cfg.cfg = tf_em_int_p4;
109 em_cfg.resources = resources;
110 em_cfg.mem_type = 0; /* Not used by EM */
112 rc = tf_em_int_bind(tfp, &em_cfg);
115 "EM initialization failure\n");
122 if_tbl_cfg.num_elements = TF_IF_TBL_TYPE_MAX;
123 if_tbl_cfg.cfg = tf_if_tbl_p4;
124 if_tbl_cfg.shadow_copy = shadow_copy;
125 rc = tf_if_tbl_bind(tfp, &if_tbl_cfg);
128 "IF Table initialization failure\n");
135 global_cfg.num_elements = TF_GLOBAL_CFG_TYPE_MAX;
136 global_cfg.cfg = tf_global_cfg_p4;
137 rc = tf_global_cfg_bind(tfp, &global_cfg);
140 "Global Cfg initialization failure\n");
144 /* Final function initialization */
145 dev_handle->ops = &tf_dev_ops_p4;
150 /* Cleanup of already created modules */
151 frc = tf_dev_unbind_p4(tfp);
159 * Device specific unbind function, WH+
162 * Pointer to TF handle
165 * - (0) if successful.
166 * - (-EINVAL) on failure.
169 tf_dev_unbind_p4(struct tf *tfp)
174 /* Unbind all the support modules. As this is only done on
175 * close we only report errors as everything has to be cleaned
178 * In case of residuals TCAMs are cleaned up first as to
179 * invalidate the pipeline in a clean manner.
181 rc = tf_tcam_unbind(tfp);
184 "Device unbind failed, TCAM\n");
188 rc = tf_ident_unbind(tfp);
191 "Device unbind failed, Identifier\n");
195 rc = tf_tbl_unbind(tfp);
198 "Device unbind failed, Table Type\n");
202 rc = tf_em_ext_common_unbind(tfp);
205 "Device unbind failed, EEM\n");
209 rc = tf_em_int_unbind(tfp);
212 "Device unbind failed, EM\n");
216 rc = tf_if_tbl_unbind(tfp);
219 "Device unbind failed, IF Table Type\n");
223 rc = tf_global_cfg_unbind(tfp);
226 "Device unbind failed, Global Cfg Type\n");
237 tf_dev_bind(struct tf *tfp __rte_unused,
238 enum tf_device_type type,
240 struct tf_session_resources *resources,
241 struct tf_dev_info *dev_handle)
244 case TF_DEVICE_TYPE_WH:
245 return tf_dev_bind_p4(tfp,
257 tf_dev_unbind(struct tf *tfp,
258 struct tf_dev_info *dev_handle)
260 switch (dev_handle->type) {
261 case TF_DEVICE_TYPE_WH:
262 return tf_dev_unbind_p4(tfp);