octeon: native driver for Marvell Octeon SoC
[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 <base/roc_api.h>
13 #include <dev_octeon/hw_defs.h>
14
15 typedef enum
16 {
17   OCT_DEVICE_TYPE_UNKNOWN = 0,
18   OCT_DEVICE_TYPE_RVU_PF,
19   OCT_DEVICE_TYPE_CPT_VF,
20 } __clib_packed oct_device_type_t;
21
22 typedef struct
23 {
24   oct_device_type_t type;
25   u8 nix_initialized : 1;
26   u8 status : 1;
27   u8 full_duplex : 1;
28   u32 speed;
29   struct plt_pci_device plt_pci_dev;
30   struct roc_cpt cpt;
31   struct roc_nix *nix;
32 } oct_device_t;
33
34 typedef struct
35 {
36   u8 lf_allocated : 1;
37   u8 tm_initialized : 1;
38   u8 npc_initialized : 1;
39   struct roc_npc npc;
40 } oct_port_t;
41
42 typedef struct
43 {
44   u8 npa_pool_initialized : 1;
45   u8 cq_initialized : 1;
46   u8 rq_initialized : 1;
47   u16 hdr_off;
48   u32 n_enq;
49   u64 aura_handle;
50   u64 aura_batch_free_ioaddr;
51   u64 lmt_base_addr;
52   CLIB_CACHE_LINE_ALIGN_MARK (data0);
53   struct roc_nix_cq cq;
54   struct roc_nix_rq rq;
55 } oct_rxq_t;
56
57 typedef struct
58 {
59   CLIB_ALIGN_MARK (cl, 128);
60   union
61   {
62     struct npa_batch_alloc_status_s status;
63     u64 iova[16];
64   };
65 } oct_npa_batch_alloc_cl128_t;
66
67 STATIC_ASSERT_SIZEOF (oct_npa_batch_alloc_cl128_t, 128);
68
69 typedef struct
70 {
71   u8 sq_initialized : 1;
72   u8 npa_pool_initialized : 1;
73   u16 hdr_off;
74   u32 n_enq;
75   u64 aura_handle;
76   u64 io_addr;
77   void *lmt_addr;
78
79   oct_npa_batch_alloc_cl128_t *ba_buffer;
80   u8 ba_first_cl;
81   u8 ba_num_cl;
82   CLIB_CACHE_LINE_ALIGN_MARK (data0);
83   struct roc_nix_sq sq;
84 } oct_txq_t;
85
86 /* format.c */
87 format_function_t format_oct_port_status;
88 format_function_t format_oct_rx_trace;
89 format_function_t format_oct_tx_trace;
90
91 /* port.c */
92 vnet_dev_rv_t oct_port_init (vlib_main_t *, vnet_dev_port_t *);
93 vnet_dev_rv_t oct_port_start (vlib_main_t *, vnet_dev_port_t *);
94 void oct_port_stop (vlib_main_t *, vnet_dev_port_t *);
95 void oct_port_deinit (vlib_main_t *, vnet_dev_port_t *);
96 vnet_dev_rv_t oct_port_cfg_change (vlib_main_t *, vnet_dev_port_t *,
97                                    vnet_dev_port_cfg_change_req_t *);
98
99 /* queue.c */
100 vnet_dev_rv_t oct_rx_queue_alloc (vlib_main_t *, vnet_dev_rx_queue_t *);
101 vnet_dev_rv_t oct_tx_queue_alloc (vlib_main_t *, vnet_dev_tx_queue_t *);
102 void oct_rx_queue_free (vlib_main_t *, vnet_dev_rx_queue_t *);
103 void oct_tx_queue_free (vlib_main_t *, vnet_dev_tx_queue_t *);
104 vnet_dev_rv_t oct_rxq_init (vlib_main_t *, vnet_dev_rx_queue_t *);
105 vnet_dev_rv_t oct_txq_init (vlib_main_t *, vnet_dev_tx_queue_t *);
106 void oct_rxq_deinit (vlib_main_t *, vnet_dev_rx_queue_t *);
107 void oct_txq_deinit (vlib_main_t *, vnet_dev_tx_queue_t *);
108 format_function_t format_oct_rxq_info;
109 format_function_t format_oct_txq_info;
110
111 #define log_debug(dev, f, ...)                                                \
112   vlib_log (VLIB_LOG_LEVEL_DEBUG, oct_log.class, "%U: " f,                    \
113             format_vnet_dev_addr, (dev), ##__VA_ARGS__)
114 #define log_info(dev, f, ...)                                                 \
115   vlib_log (VLIB_LOG_LEVEL_INFO, oct_log.class, "%U: " f,                     \
116             format_vnet_dev_addr, (dev), ##__VA_ARGS__)
117 #define log_notice(dev, f, ...)                                               \
118   vlib_log (VLIB_LOG_LEVEL_NOTICE, oct_log.class, "%U: " f,                   \
119             format_vnet_dev_addr, (dev), ##__VA_ARGS__)
120 #define log_warn(dev, f, ...)                                                 \
121   vlib_log (VLIB_LOG_LEVEL_WARNING, oct_log.class, "%U: " f,                  \
122             format_vnet_dev_addr, (dev), ##__VA_ARGS__)
123 #define log_err(dev, f, ...)                                                  \
124   vlib_log (VLIB_LOG_LEVEL_ERR, oct_log.class, "%U: " f,                      \
125             format_vnet_dev_addr, (dev), ##__VA_ARGS__)
126
127 #define foreach_oct_tx_node_counter                                           \
128   _ (CHAIN_TOO_LONG, chain_too_long, ERROR, "drop due to buffer chain > 6")   \
129   _ (NO_FREE_SLOTS, no_free_slots, ERROR, "no free tx slots")                 \
130   _ (AURA_BATCH_ALLOC_ISSUE_FAIL, aura_batch_alloc_issue_fail, ERROR,         \
131      "aura batch alloc issue failed")                                         \
132   _ (AURA_BATCH_ALLOC_NOT_READY, aura_batch_alloc_not_ready, ERROR,           \
133      "aura batch alloc not ready")
134
135 typedef enum
136 {
137 #define _(f, n, s, d) OCT_TX_NODE_CTR_##f,
138   foreach_oct_tx_node_counter
139 #undef _
140 } oct_tx_node_counter_t;
141
142 typedef struct
143 {
144   u32 sw_if_index;
145   u32 next_index;
146   oct_nix_rx_cqe_desc_t desc;
147 } oct_rx_trace_t;
148
149 typedef struct
150 {
151   u32 sw_if_index;
152   oct_tx_desc_t desc;
153 } oct_tx_trace_t;
154 #endif /* _OCTEON_H_ */