0344565d72ca3451ea4df326bd00b6e4f181e979
[dpdk.git] / drivers / net / bnxt / tf_core / tf_device_p4.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2019-2020 Broadcom
3  * All rights reserved.
4  */
5
6 #include <rte_common.h>
7 #include <cfa_resource_types.h>
8
9 #include "tf_device.h"
10 #include "tf_identifier.h"
11 #include "tf_tbl.h"
12 #include "tf_tcam.h"
13 #include "tf_em.h"
14 #include "tf_if_tbl.h"
15
16 /**
17  * Device specific function that retrieves the MAX number of HCAPI
18  * types the device supports.
19  *
20  * [in] tfp
21  *   Pointer to TF handle
22  *
23  * [out] max_types
24  *   Pointer to the MAX number of HCAPI types supported
25  *
26  * Returns
27  *   - (0) if successful.
28  *   - (-EINVAL) on failure.
29  */
30 static int
31 tf_dev_p4_get_max_types(struct tf *tfp,
32                         uint16_t *max_types)
33 {
34         struct tf_session *tfs;
35         struct tf_dev_info *dev;
36         int rc;
37
38         if (max_types == NULL || tfp == NULL)
39                 return -EINVAL;
40
41         /* Retrieve the session information */
42         rc = tf_session_get_session(tfp, &tfs);
43         if (rc)
44                 return rc;
45
46         /* Retrieve the device information */
47         rc = tf_session_get_device(tfs, &dev);
48         if (rc)
49                 return rc;
50
51         if (dev->type == TF_DEVICE_TYPE_WH)
52                 *max_types = CFA_RESOURCE_TYPE_P4_LAST + 1;
53         else if (dev->type == TF_DEVICE_TYPE_SR)
54                 *max_types = CFA_RESOURCE_TYPE_P45_LAST + 1;
55         else
56                 return -ENODEV;
57
58         return 0;
59 }
60
61 /**
62  * Device specific function that retrieves the WC TCAM slices the
63  * device supports.
64  *
65  * [in] tfp
66  *   Pointer to TF handle
67  *
68  * [out] slice_size
69  *   Pointer to the WC TCAM slice size
70  *
71  * [out] num_slices_per_row
72  *   Pointer to the WC TCAM row slice configuration
73  *
74  * Returns
75  *   - (0) if successful.
76  *   - (-EINVAL) on failure.
77  */
78 static int
79 tf_dev_p4_get_tcam_slice_info(struct tf *tfp __rte_unused,
80                               enum tf_tcam_tbl_type type,
81                               uint16_t key_sz,
82                               uint16_t *num_slices_per_row)
83 {
84 #define CFA_P4_WC_TCAM_SLICES_PER_ROW 2
85 #define CFA_P4_WC_TCAM_SLICE_SIZE     12
86
87         if (type == TF_TCAM_TBL_TYPE_WC_TCAM) {
88                 *num_slices_per_row = CFA_P4_WC_TCAM_SLICES_PER_ROW;
89                 if (key_sz > *num_slices_per_row * CFA_P4_WC_TCAM_SLICE_SIZE)
90                         return -ENOTSUP;
91
92                 *num_slices_per_row = 1;
93         } else { /* for other type of tcam */
94                 *num_slices_per_row = 1;
95         }
96
97         return 0;
98 }
99
100 /**
101  * Truflow P4 device specific functions
102  */
103 const struct tf_dev_ops tf_dev_ops_p4_init = {
104         .tf_dev_get_max_types = tf_dev_p4_get_max_types,
105         .tf_dev_get_tcam_slice_info = tf_dev_p4_get_tcam_slice_info,
106         .tf_dev_alloc_ident = NULL,
107         .tf_dev_free_ident = NULL,
108         .tf_dev_search_ident = NULL,
109         .tf_dev_alloc_ext_tbl = NULL,
110         .tf_dev_alloc_tbl = NULL,
111         .tf_dev_free_ext_tbl = NULL,
112         .tf_dev_free_tbl = NULL,
113         .tf_dev_alloc_search_tbl = NULL,
114         .tf_dev_set_tbl = NULL,
115         .tf_dev_set_ext_tbl = NULL,
116         .tf_dev_get_tbl = NULL,
117         .tf_dev_get_bulk_tbl = NULL,
118         .tf_dev_alloc_tcam = NULL,
119         .tf_dev_free_tcam = NULL,
120         .tf_dev_alloc_search_tcam = NULL,
121         .tf_dev_set_tcam = NULL,
122         .tf_dev_get_tcam = NULL,
123         .tf_dev_insert_int_em_entry = NULL,
124         .tf_dev_delete_int_em_entry = NULL,
125         .tf_dev_insert_ext_em_entry = NULL,
126         .tf_dev_delete_ext_em_entry = NULL,
127         .tf_dev_alloc_tbl_scope = NULL,
128         .tf_dev_free_tbl_scope = NULL,
129         .tf_dev_set_if_tbl = NULL,
130         .tf_dev_get_if_tbl = NULL,
131         .tf_dev_set_global_cfg = NULL,
132         .tf_dev_get_global_cfg = NULL,
133 };
134
135 /**
136  * Truflow P4 device specific functions
137  */
138 const struct tf_dev_ops tf_dev_ops_p4 = {
139         .tf_dev_get_max_types = tf_dev_p4_get_max_types,
140         .tf_dev_get_tcam_slice_info = tf_dev_p4_get_tcam_slice_info,
141         .tf_dev_alloc_ident = tf_ident_alloc,
142         .tf_dev_free_ident = tf_ident_free,
143         .tf_dev_search_ident = tf_ident_search,
144         .tf_dev_alloc_tbl = tf_tbl_alloc,
145         .tf_dev_alloc_ext_tbl = tf_tbl_ext_alloc,
146         .tf_dev_free_tbl = tf_tbl_free,
147         .tf_dev_free_ext_tbl = tf_tbl_ext_free,
148         .tf_dev_alloc_search_tbl = tf_tbl_alloc_search,
149         .tf_dev_set_tbl = tf_tbl_set,
150         .tf_dev_set_ext_tbl = tf_tbl_ext_common_set,
151         .tf_dev_get_tbl = tf_tbl_get,
152         .tf_dev_get_bulk_tbl = tf_tbl_bulk_get,
153         .tf_dev_alloc_tcam = tf_tcam_alloc,
154         .tf_dev_free_tcam = tf_tcam_free,
155         .tf_dev_alloc_search_tcam = tf_tcam_alloc_search,
156         .tf_dev_set_tcam = tf_tcam_set,
157         .tf_dev_get_tcam = NULL,
158         .tf_dev_insert_int_em_entry = tf_em_insert_int_entry,
159         .tf_dev_delete_int_em_entry = tf_em_delete_int_entry,
160         .tf_dev_insert_ext_em_entry = tf_em_insert_ext_entry,
161         .tf_dev_delete_ext_em_entry = tf_em_delete_ext_entry,
162         .tf_dev_alloc_tbl_scope = tf_em_ext_common_alloc,
163         .tf_dev_free_tbl_scope = tf_em_ext_common_free,
164         .tf_dev_set_if_tbl = tf_if_tbl_set,
165         .tf_dev_get_if_tbl = tf_if_tbl_get,
166         .tf_dev_set_global_cfg = tf_global_cfg_set,
167         .tf_dev_get_global_cfg = tf_global_cfg_get,
168 };