fd8a92c7b3d5334850447e5c51dc6a7cbd395a16
[vpp.git] / src / plugins / dev_octeon / octeon.h
1
2 /* SPDX-License-Identifier: Apache-2.0
3  * Copyright (c) 2023 Cisco Systems, Inc.
4  */
5 #ifndef _OCTEON_H_
6 #define _OCTEON_H_
7 #include <vppinfra/clib.h>
8 #include <vppinfra/error_bootstrap.h>
9 #include <vppinfra/format.h>
10 #include <vnet/vnet.h>
11 #include <vnet/dev/dev.h>
12 #include <vnet/flow/flow.h>
13 #include <vnet/udp/udp.h>
14 #include <vnet/ipsec/esp.h>
15 #include <base/roc_api.h>
16 #include <dev_octeon/hw_defs.h>
17
18 typedef enum
19 {
20   OCT_DEVICE_TYPE_UNKNOWN = 0,
21   OCT_DEVICE_TYPE_RVU_PF,
22   OCT_DEVICE_TYPE_RVU_VF,
23   OCT_DEVICE_TYPE_CPT_VF,
24 } __clib_packed oct_device_type_t;
25
26 typedef struct
27 {
28   oct_device_type_t type;
29   u8 nix_initialized : 1;
30   u8 status : 1;
31   u8 full_duplex : 1;
32   u32 speed;
33   struct plt_pci_device plt_pci_dev;
34   struct roc_cpt cpt;
35   struct roc_nix *nix;
36 } oct_device_t;
37
38 typedef struct
39 {
40   /* vnet flow index */
41   u32 vnet_flow_index;
42
43   u32 index;
44   /* Internal flow object */
45   struct roc_npc_flow *npc_flow;
46 } oct_flow_entry_t;
47
48 typedef struct
49 {
50   u8 lf_allocated : 1;
51   u8 tm_initialized : 1;
52   u8 npc_initialized : 1;
53   struct roc_npc npc;
54   oct_flow_entry_t *flow_entries;
55 } oct_port_t;
56
57 typedef struct
58 {
59   u8 npa_pool_initialized : 1;
60   u8 cq_initialized : 1;
61   u8 rq_initialized : 1;
62   u16 hdr_off;
63   u32 n_enq;
64   u64 aura_handle;
65   u64 aura_batch_free_ioaddr;
66   u64 lmt_base_addr;
67   CLIB_CACHE_LINE_ALIGN_MARK (data0);
68   struct roc_nix_cq cq;
69   struct roc_nix_rq rq;
70 } oct_rxq_t;
71
72 typedef struct
73 {
74   CLIB_ALIGN_MARK (cl, 128);
75   union
76   {
77     struct npa_batch_alloc_status_s status;
78     u64 iova[16];
79   };
80 } oct_npa_batch_alloc_cl128_t;
81
82 STATIC_ASSERT_SIZEOF (oct_npa_batch_alloc_cl128_t, 128);
83
84 typedef struct
85 {
86   u8 sq_initialized : 1;
87   u8 npa_pool_initialized : 1;
88   u16 hdr_off;
89   u32 n_enq;
90   u64 aura_handle;
91   u64 io_addr;
92   void *lmt_addr;
93
94   oct_npa_batch_alloc_cl128_t *ba_buffer;
95   u8 ba_first_cl;
96   u8 ba_num_cl;
97   CLIB_CACHE_LINE_ALIGN_MARK (data0);
98   struct roc_nix_sq sq;
99 } oct_txq_t;
100
101 /* format.c */
102 format_function_t format_oct_port_status;
103 format_function_t format_oct_rx_trace;
104 format_function_t format_oct_tx_trace;
105 format_function_t format_oct_port_flow;
106
107 /* port.c */
108 vnet_dev_rv_t oct_port_init (vlib_main_t *, vnet_dev_port_t *);
109 vnet_dev_rv_t oct_port_start (vlib_main_t *, vnet_dev_port_t *);
110 void oct_port_stop (vlib_main_t *, vnet_dev_port_t *);
111 void oct_port_deinit (vlib_main_t *, vnet_dev_port_t *);
112 vnet_dev_rv_t oct_port_cfg_change (vlib_main_t *, vnet_dev_port_t *,
113                                    vnet_dev_port_cfg_change_req_t *);
114 vnet_dev_rv_t oct_port_cfg_change_validate (vlib_main_t *, vnet_dev_port_t *,
115                                             vnet_dev_port_cfg_change_req_t *);
116
117 /* queue.c */
118 vnet_dev_rv_t oct_rx_queue_alloc (vlib_main_t *, vnet_dev_rx_queue_t *);
119 vnet_dev_rv_t oct_tx_queue_alloc (vlib_main_t *, vnet_dev_tx_queue_t *);
120 void oct_rx_queue_free (vlib_main_t *, vnet_dev_rx_queue_t *);
121 void oct_tx_queue_free (vlib_main_t *, vnet_dev_tx_queue_t *);
122 vnet_dev_rv_t oct_rxq_init (vlib_main_t *, vnet_dev_rx_queue_t *);
123 vnet_dev_rv_t oct_txq_init (vlib_main_t *, vnet_dev_tx_queue_t *);
124 void oct_rxq_deinit (vlib_main_t *, vnet_dev_rx_queue_t *);
125 void oct_txq_deinit (vlib_main_t *, vnet_dev_tx_queue_t *);
126 format_function_t format_oct_rxq_info;
127 format_function_t format_oct_txq_info;
128
129 /* flow.c */
130 vnet_dev_rv_t oct_flow_ops_fn (vlib_main_t *, vnet_dev_port_t *,
131                                vnet_dev_port_cfg_type_t, u32, uword *);
132 vnet_dev_rv_t oct_flow_validate_params (vlib_main_t *, vnet_dev_port_t *,
133                                         vnet_dev_port_cfg_type_t, u32,
134                                         uword *);
135 vnet_dev_rv_t oct_flow_query (vlib_main_t *, vnet_dev_port_t *, u32, uword,
136                               u64 *);
137
138 #define log_debug(dev, f, ...)                                                \
139   vlib_log (VLIB_LOG_LEVEL_DEBUG, oct_log.class, "%U: " f,                    \
140             format_vnet_dev_addr, (dev), ##__VA_ARGS__)
141 #define log_info(dev, f, ...)                                                 \
142   vlib_log (VLIB_LOG_LEVEL_INFO, oct_log.class, "%U: " f,                     \
143             format_vnet_dev_addr, (dev), ##__VA_ARGS__)
144 #define log_notice(dev, f, ...)                                               \
145   vlib_log (VLIB_LOG_LEVEL_NOTICE, oct_log.class, "%U: " f,                   \
146             format_vnet_dev_addr, (dev), ##__VA_ARGS__)
147 #define log_warn(dev, f, ...)                                                 \
148   vlib_log (VLIB_LOG_LEVEL_WARNING, oct_log.class, "%U: " f,                  \
149             format_vnet_dev_addr, (dev), ##__VA_ARGS__)
150 #define log_err(dev, f, ...)                                                  \
151   vlib_log (VLIB_LOG_LEVEL_ERR, oct_log.class, "%U: " f,                      \
152             format_vnet_dev_addr, (dev), ##__VA_ARGS__)
153
154 #define foreach_oct_tx_node_counter                                           \
155   _ (CHAIN_TOO_LONG, chain_too_long, ERROR, "drop due to buffer chain > 6")   \
156   _ (NO_FREE_SLOTS, no_free_slots, ERROR, "no free tx slots")                 \
157   _ (AURA_BATCH_ALLOC_ISSUE_FAIL, aura_batch_alloc_issue_fail, ERROR,         \
158      "aura batch alloc issue failed")                                         \
159   _ (AURA_BATCH_ALLOC_NOT_READY, aura_batch_alloc_not_ready, ERROR,           \
160      "aura batch alloc not ready")
161
162 typedef enum
163 {
164 #define _(f, n, s, d) OCT_TX_NODE_CTR_##f,
165   foreach_oct_tx_node_counter
166 #undef _
167 } oct_tx_node_counter_t;
168
169 typedef struct
170 {
171   u32 sw_if_index;
172   u32 next_index;
173   oct_nix_rx_cqe_desc_t desc;
174 } oct_rx_trace_t;
175
176 typedef struct
177 {
178   u32 sw_if_index;
179   oct_tx_desc_t desc;
180 } oct_tx_trace_t;
181 #endif /* _OCTEON_H_ */