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 tf_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 tf_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 dev_handle->type = TF_DEVICE_TYPE_WH;
47 /* Initial function initialization */
48 dev_handle->ops = &tf_dev_ops_p4_init;
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");
89 /* Final function initialization */
90 dev_handle->ops = &tf_dev_ops_p4;
95 /* Cleanup of already created modules */
96 frc = tf_dev_unbind_p4(tfp);
104 * Device specific unbind function, WH+
107 * Pointer to TF handle
110 * - (0) if successful.
111 * - (-EINVAL) on failure.
114 tf_dev_unbind_p4(struct tf *tfp)
119 /* Unbind all the support modules. As this is only done on
120 * close we only report errors as everything has to be cleaned
123 * In case of residuals TCAMs are cleaned up first as to
124 * invalidate the pipeline in a clean manner.
126 rc = tf_tcam_unbind(tfp);
129 "Device unbind failed, TCAM\n");
133 rc = tf_ident_unbind(tfp);
136 "Device unbind failed, Identifier\n");
140 rc = tf_tbl_unbind(tfp);
143 "Device unbind failed, Table Type\n");
154 tf_dev_bind(struct tf *tfp __rte_unused,
155 enum tf_device_type type,
157 struct tf_session_resources *resources,
158 struct tf_dev_info *dev_handle)
161 case TF_DEVICE_TYPE_WH:
162 return tf_dev_bind_p4(tfp,
174 tf_dev_unbind(struct tf *tfp,
175 struct tf_dev_info *dev_handle)
177 switch (dev_handle->type) {
178 case TF_DEVICE_TYPE_WH:
179 return tf_dev_unbind_p4(tfp);