net/bnxt: add shadow table capability with search
[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 __rte_unused,
32                         uint16_t *max_types)
33 {
34         if (max_types == NULL)
35                 return -EINVAL;
36
37         *max_types = CFA_RESOURCE_TYPE_P4_LAST + 1;
38
39         return 0;
40 }
41
42 /**
43  * Device specific function that retrieves the WC TCAM slices the
44  * device supports.
45  *
46  * [in] tfp
47  *   Pointer to TF handle
48  *
49  * [out] slice_size
50  *   Pointer to the WC TCAM slice size
51  *
52  * [out] num_slices_per_row
53  *   Pointer to the WC TCAM row slice configuration
54  *
55  * Returns
56  *   - (0) if successful.
57  *   - (-EINVAL) on failure.
58  */
59 static int
60 tf_dev_p4_get_tcam_slice_info(struct tf *tfp __rte_unused,
61                               enum tf_tcam_tbl_type type,
62                               uint16_t key_sz,
63                               uint16_t *num_slices_per_row)
64 {
65 #define CFA_P4_WC_TCAM_SLICES_PER_ROW 2
66 #define CFA_P4_WC_TCAM_SLICE_SIZE     12
67
68         if (type == TF_TCAM_TBL_TYPE_WC_TCAM) {
69                 *num_slices_per_row = CFA_P4_WC_TCAM_SLICES_PER_ROW;
70                 if (key_sz > *num_slices_per_row * CFA_P4_WC_TCAM_SLICE_SIZE)
71                         return -ENOTSUP;
72
73                 *num_slices_per_row = 1;
74         } else { /* for other type of tcam */
75                 *num_slices_per_row = 1;
76         }
77
78         return 0;
79 }
80
81 /**
82  * Truflow P4 device specific functions
83  */
84 const struct tf_dev_ops tf_dev_ops_p4_init = {
85         .tf_dev_get_max_types = tf_dev_p4_get_max_types,
86         .tf_dev_get_tcam_slice_info = tf_dev_p4_get_tcam_slice_info,
87         .tf_dev_alloc_ident = NULL,
88         .tf_dev_free_ident = NULL,
89         .tf_dev_search_ident = NULL,
90         .tf_dev_alloc_ext_tbl = NULL,
91         .tf_dev_alloc_tbl = NULL,
92         .tf_dev_free_ext_tbl = NULL,
93         .tf_dev_free_tbl = NULL,
94         .tf_dev_alloc_search_tbl = NULL,
95         .tf_dev_set_tbl = NULL,
96         .tf_dev_set_ext_tbl = NULL,
97         .tf_dev_get_tbl = NULL,
98         .tf_dev_get_bulk_tbl = NULL,
99         .tf_dev_alloc_tcam = NULL,
100         .tf_dev_free_tcam = NULL,
101         .tf_dev_alloc_search_tcam = NULL,
102         .tf_dev_set_tcam = NULL,
103         .tf_dev_get_tcam = NULL,
104         .tf_dev_insert_int_em_entry = NULL,
105         .tf_dev_delete_int_em_entry = NULL,
106         .tf_dev_insert_ext_em_entry = NULL,
107         .tf_dev_delete_ext_em_entry = NULL,
108         .tf_dev_alloc_tbl_scope = NULL,
109         .tf_dev_free_tbl_scope = NULL,
110         .tf_dev_set_if_tbl = NULL,
111         .tf_dev_get_if_tbl = NULL,
112         .tf_dev_set_global_cfg = NULL,
113         .tf_dev_get_global_cfg = NULL,
114 };
115
116 /**
117  * Truflow P4 device specific functions
118  */
119 const struct tf_dev_ops tf_dev_ops_p4 = {
120         .tf_dev_get_max_types = tf_dev_p4_get_max_types,
121         .tf_dev_get_tcam_slice_info = tf_dev_p4_get_tcam_slice_info,
122         .tf_dev_alloc_ident = tf_ident_alloc,
123         .tf_dev_free_ident = tf_ident_free,
124         .tf_dev_search_ident = tf_ident_search,
125         .tf_dev_alloc_tbl = tf_tbl_alloc,
126         .tf_dev_alloc_ext_tbl = tf_tbl_ext_alloc,
127         .tf_dev_free_tbl = tf_tbl_free,
128         .tf_dev_free_ext_tbl = tf_tbl_ext_free,
129         .tf_dev_alloc_search_tbl = tf_tbl_alloc_search,
130         .tf_dev_set_tbl = tf_tbl_set,
131         .tf_dev_set_ext_tbl = tf_tbl_ext_common_set,
132         .tf_dev_get_tbl = tf_tbl_get,
133         .tf_dev_get_bulk_tbl = tf_tbl_bulk_get,
134         .tf_dev_alloc_tcam = tf_tcam_alloc,
135         .tf_dev_free_tcam = tf_tcam_free,
136         .tf_dev_alloc_search_tcam = tf_tcam_alloc_search,
137         .tf_dev_set_tcam = tf_tcam_set,
138         .tf_dev_get_tcam = NULL,
139         .tf_dev_insert_int_em_entry = tf_em_insert_int_entry,
140         .tf_dev_delete_int_em_entry = tf_em_delete_int_entry,
141         .tf_dev_insert_ext_em_entry = tf_em_insert_ext_entry,
142         .tf_dev_delete_ext_em_entry = tf_em_delete_ext_entry,
143         .tf_dev_alloc_tbl_scope = tf_em_ext_common_alloc,
144         .tf_dev_free_tbl_scope = tf_em_ext_common_free,
145         .tf_dev_set_if_tbl = tf_if_tbl_set,
146         .tf_dev_get_if_tbl = tf_if_tbl_get,
147         .tf_dev_set_global_cfg = tf_global_cfg_set,
148         .tf_dev_get_global_cfg = tf_global_cfg_get,
149 };