1eaf182126d7dda944c3eb384364583ed05d84d8
[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
15 /**
16  * Device specific function that retrieves the MAX number of HCAPI
17  * types the device supports.
18  *
19  * [in] tfp
20  *   Pointer to TF handle
21  *
22  * [out] max_types
23  *   Pointer to the MAX number of HCAPI types supported
24  *
25  * Returns
26  *   - (0) if successful.
27  *   - (-EINVAL) on failure.
28  */
29 static int
30 tf_dev_p4_get_max_types(struct tf *tfp __rte_unused,
31                         uint16_t *max_types)
32 {
33         if (max_types == NULL)
34                 return -EINVAL;
35
36         *max_types = CFA_RESOURCE_TYPE_P4_LAST + 1;
37
38         return 0;
39 }
40
41 /**
42  * Device specific function that retrieves the WC TCAM slices the
43  * device supports.
44  *
45  * [in] tfp
46  *   Pointer to TF handle
47  *
48  * [out] slice_size
49  *   Pointer to the WC TCAM slice size
50  *
51  * [out] num_slices_per_row
52  *   Pointer to the WC TCAM row slice configuration
53  *
54  * Returns
55  *   - (0) if successful.
56  *   - (-EINVAL) on failure.
57  */
58 static int
59 tf_dev_p4_get_tcam_slice_info(struct tf *tfp __rte_unused,
60                               enum tf_tcam_tbl_type type,
61                               uint16_t key_sz,
62                               uint16_t *num_slices_per_row)
63 {
64 #define CFA_P4_WC_TCAM_SLICES_PER_ROW 2
65 #define CFA_P4_WC_TCAM_SLICE_SIZE     12
66
67         if (type == TF_TCAM_TBL_TYPE_WC_TCAM) {
68                 *num_slices_per_row = CFA_P4_WC_TCAM_SLICES_PER_ROW;
69                 if (key_sz > *num_slices_per_row * CFA_P4_WC_TCAM_SLICE_SIZE)
70                         return -ENOTSUP;
71
72                 *num_slices_per_row = 1;
73         } else { /* for other type of tcam */
74                 *num_slices_per_row = 1;
75         }
76
77         return 0;
78 }
79
80 /**
81  * Truflow P4 device specific functions
82  */
83 const struct tf_dev_ops tf_dev_ops_p4_init = {
84         .tf_dev_get_max_types = tf_dev_p4_get_max_types,
85         .tf_dev_get_tcam_slice_info = tf_dev_p4_get_tcam_slice_info,
86         .tf_dev_alloc_ident = NULL,
87         .tf_dev_free_ident = NULL,
88         .tf_dev_alloc_tbl = NULL,
89         .tf_dev_free_tbl = NULL,
90         .tf_dev_alloc_search_tbl = NULL,
91         .tf_dev_set_tbl = NULL,
92         .tf_dev_get_tbl = NULL,
93         .tf_dev_get_bulk_tbl = NULL,
94         .tf_dev_alloc_tcam = NULL,
95         .tf_dev_free_tcam = NULL,
96         .tf_dev_alloc_search_tcam = NULL,
97         .tf_dev_set_tcam = NULL,
98         .tf_dev_get_tcam = NULL,
99         .tf_dev_insert_int_em_entry = NULL,
100         .tf_dev_delete_int_em_entry = NULL,
101         .tf_dev_insert_ext_em_entry = NULL,
102         .tf_dev_delete_ext_em_entry = NULL,
103         .tf_dev_alloc_tbl_scope = NULL,
104         .tf_dev_free_tbl_scope = NULL,
105 };
106
107 /**
108  * Truflow P4 device specific functions
109  */
110 const struct tf_dev_ops tf_dev_ops_p4 = {
111         .tf_dev_get_max_types = tf_dev_p4_get_max_types,
112         .tf_dev_get_tcam_slice_info = tf_dev_p4_get_tcam_slice_info,
113         .tf_dev_alloc_ident = tf_ident_alloc,
114         .tf_dev_free_ident = tf_ident_free,
115         .tf_dev_alloc_tbl = tf_tbl_alloc,
116         .tf_dev_free_tbl = tf_tbl_free,
117         .tf_dev_alloc_search_tbl = NULL,
118         .tf_dev_set_tbl = tf_tbl_set,
119         .tf_dev_get_tbl = tf_tbl_get,
120         .tf_dev_get_bulk_tbl = tf_tbl_bulk_get,
121         .tf_dev_alloc_tcam = tf_tcam_alloc,
122         .tf_dev_free_tcam = tf_tcam_free,
123         .tf_dev_alloc_search_tcam = NULL,
124         .tf_dev_set_tcam = tf_tcam_set,
125         .tf_dev_get_tcam = NULL,
126         .tf_dev_insert_int_em_entry = tf_em_insert_int_entry,
127         .tf_dev_delete_int_em_entry = tf_em_delete_int_entry,
128         .tf_dev_insert_ext_em_entry = tf_em_insert_ext_entry,
129         .tf_dev_delete_ext_em_entry = tf_em_delete_ext_entry,
130         .tf_dev_alloc_tbl_scope = tf_em_ext_common_alloc,
131         .tf_dev_free_tbl_scope = tf_em_ext_common_free,
132 };