net/octeontx_ep: add Rx queue setup and release
[dpdk.git] / drivers / net / octeontx_ep / otx_ep_common.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(C) 2021 Marvell.
3  */
4 #ifndef _OTX_EP_COMMON_H_
5 #define _OTX_EP_COMMON_H_
6
7 #define OTX_EP_MAX_RINGS_PER_VF        (8)
8 #define OTX_EP_CFG_IO_QUEUES        OTX_EP_MAX_RINGS_PER_VF
9 #define OTX_EP_64BYTE_INSTR         (64)
10 #define OTX_EP_MIN_IQ_DESCRIPTORS   (128)
11 #define OTX_EP_MIN_OQ_DESCRIPTORS   (128)
12 #define OTX_EP_MAX_IQ_DESCRIPTORS   (8192)
13 #define OTX_EP_MAX_OQ_DESCRIPTORS   (8192)
14 #define OTX_EP_OQ_BUF_SIZE          (2048)
15 #define OTX_EP_MIN_RX_BUF_SIZE      (64)
16
17 #define OTX_EP_OQ_INFOPTR_MODE      (0)
18 #define OTX_EP_OQ_REFIL_THRESHOLD   (16)
19 #define OTX_EP_PCI_RING_ALIGN   65536
20 #define SDP_PKIND 40
21 #define SDP_OTX2_PKIND 57
22 #define OTX_EP_MAX_IOQS_PER_VF 8
23
24 #define otx_ep_info(fmt, args...)                               \
25         rte_log(RTE_LOG_INFO, otx_net_ep_logtype,               \
26                 "%s():%u " fmt "\n",                            \
27                 __func__, __LINE__, ##args)
28
29 #define otx_ep_err(fmt, args...)                                \
30         rte_log(RTE_LOG_ERR, otx_net_ep_logtype,                \
31                 "%s():%u " fmt "\n",                            \
32                 __func__, __LINE__, ##args)
33
34 #define otx_ep_dbg(fmt, args...)                                \
35         rte_log(RTE_LOG_DEBUG, otx_net_ep_logtype,              \
36                 "%s():%u " fmt "\n",                            \
37                 __func__, __LINE__, ##args)
38
39 #define otx_ep_write64(value, base_addr, reg_off) \
40         {\
41         typeof(value) val = (value); \
42         typeof(reg_off) off = (reg_off); \
43         otx_ep_dbg("octeon_write_csr64: reg: 0x%08lx val: 0x%016llx\n", \
44                    (unsigned long)off, (unsigned long long)val); \
45         rte_write64(val, ((base_addr) + off)); \
46         }
47
48 struct otx_ep_device;
49
50 /* Structure to define the configuration attributes for each Input queue. */
51 struct otx_ep_iq_config {
52         /* Max number of IQs available */
53         uint16_t max_iqs;
54
55         /* Command size - 32 or 64 bytes */
56         uint16_t instr_type;
57
58         /* Pending list size, usually set to the sum of the size of all IQs */
59         uint32_t pending_list_size;
60 };
61
62 /** Descriptor format.
63  *  The descriptor ring is made of descriptors which have 2 64-bit values:
64  *  -# Physical (bus) address of the data buffer.
65  *  -# Physical (bus) address of a otx_ep_droq_info structure.
66  *  The device DMA's incoming packets and its information at the address
67  *  given by these descriptor fields.
68  */
69 struct otx_ep_droq_desc {
70         /* The buffer pointer */
71         uint64_t buffer_ptr;
72
73         /* The Info pointer */
74         uint64_t info_ptr;
75 };
76 #define OTX_EP_DROQ_DESC_SIZE   (sizeof(struct otx_ep_droq_desc))
77
78 /* Receive Header */
79 union otx_ep_rh {
80         uint64_t rh64;
81 };
82 #define OTX_EP_RH_SIZE (sizeof(union otx_ep_rh))
83
84 /** Information about packet DMA'ed by OCTEON TX2.
85  *  The format of the information available at Info Pointer after OCTEON TX2
86  *  has posted a packet. Not all descriptors have valid information. Only
87  *  the Info field of the first descriptor for a packet has information
88  *  about the packet.
89  */
90 struct otx_ep_droq_info {
91         /* The Length of the packet. */
92         uint64_t length;
93
94         /* The Output Receive Header. */
95         union otx_ep_rh rh;
96 };
97 #define OTX_EP_DROQ_INFO_SIZE   (sizeof(struct otx_ep_droq_info))
98
99 /* DROQ statistics. Each output queue has four stats fields. */
100 struct otx_ep_droq_stats {
101         /* Number of packets received in this queue. */
102         uint64_t pkts_received;
103
104         /* Bytes received by this queue. */
105         uint64_t bytes_received;
106
107         /* Num of failures of rte_pktmbuf_alloc() */
108         uint64_t rx_alloc_failure;
109
110         /* Rx error */
111         uint64_t rx_err;
112
113         /* packets with data got ready after interrupt arrived */
114         uint64_t pkts_delayed_data;
115
116         /* packets dropped due to zero length */
117         uint64_t dropped_zlp;
118 };
119
120 /* Structure to define the configuration attributes for each Output queue. */
121 struct otx_ep_oq_config {
122         /* Max number of OQs available */
123         uint16_t max_oqs;
124
125         /* If set, the Output queue uses info-pointer mode. (Default: 1 ) */
126         uint16_t info_ptr;
127
128         /** The number of buffers that were consumed during packet processing by
129          *  the driver on this Output queue before the driver attempts to
130          *  replenish the descriptor ring with new buffers.
131          */
132         uint32_t refill_threshold;
133 };
134
135 /* The Descriptor Ring Output Queue(DROQ) structure. */
136 struct otx_ep_droq {
137         struct otx_ep_device *otx_ep_dev;
138         /* The 8B aligned descriptor ring starts at this address. */
139         struct otx_ep_droq_desc *desc_ring;
140
141         uint32_t q_no;
142         uint64_t last_pkt_count;
143
144         struct rte_mempool *mpool;
145
146         /* Driver should read the next packet at this index */
147         uint32_t read_idx;
148
149         /* OCTEON TX2 will write the next packet at this index */
150         uint32_t write_idx;
151
152         /* At this index, the driver will refill the descriptor's buffer */
153         uint32_t refill_idx;
154
155         /* Packets pending to be processed */
156         uint64_t pkts_pending;
157
158         /* Number of descriptors in this ring. */
159         uint32_t nb_desc;
160
161         /* The number of descriptors pending to refill. */
162         uint32_t refill_count;
163
164         uint32_t refill_threshold;
165
166         /* The 8B aligned info ptrs begin from this address. */
167         struct otx_ep_droq_info *info_list;
168
169         /* receive buffer list contains mbuf ptr list */
170         struct rte_mbuf **recv_buf_list;
171
172         /* The size of each buffer pointed by the buffer pointer. */
173         uint32_t buffer_size;
174
175         /* Statistics for this DROQ. */
176         struct otx_ep_droq_stats stats;
177
178         /* DMA mapped address of the DROQ descriptor ring. */
179         size_t desc_ring_dma;
180
181         /* Info_ptr list is allocated at this virtual address. */
182         size_t info_base_addr;
183
184         /* DMA mapped address of the info list */
185         size_t info_list_dma;
186
187         /* Allocated size of info list. */
188         uint32_t info_alloc_size;
189
190         /* Memory zone **/
191         const struct rte_memzone *desc_ring_mz;
192         const struct rte_memzone *info_mz;
193 };
194 #define OTX_EP_DROQ_SIZE                (sizeof(struct otx_ep_droq))
195
196 /* IQ/OQ mask */
197 struct otx_ep_io_enable {
198         uint64_t iq;
199         uint64_t oq;
200         uint64_t iq64B;
201 };
202
203 /* Structure to define the configuration. */
204 struct otx_ep_config {
205         /* Input Queue attributes. */
206         struct otx_ep_iq_config iq;
207
208         /* Output Queue attributes. */
209         struct otx_ep_oq_config oq;
210
211         /* Num of desc for IQ rings */
212         uint32_t num_iqdef_descs;
213
214         /* Num of desc for OQ rings */
215         uint32_t num_oqdef_descs;
216
217         /* OQ buffer size */
218         uint32_t oqdef_buf_size;
219 };
220
221 /* SRIOV information */
222 struct otx_ep_sriov_info {
223         /* Number of rings assigned to VF */
224         uint32_t rings_per_vf;
225
226         /* Number of VF devices enabled */
227         uint32_t num_vfs;
228 };
229
230 /* Required functions for each VF device */
231 struct otx_ep_fn_list {
232         void (*setup_oq_regs)(struct otx_ep_device *otx_ep, uint32_t q_no);
233
234         void (*setup_device_regs)(struct otx_ep_device *otx_ep);
235
236         void (*disable_io_queues)(struct otx_ep_device *otx_ep);
237 };
238
239 /* OTX_EP EP VF device data structure */
240 struct otx_ep_device {
241         /* PCI device pointer */
242         struct rte_pci_device *pdev;
243
244         uint16_t chip_id;
245
246         uint32_t pkind;
247
248         struct rte_eth_dev *eth_dev;
249
250         int port_id;
251
252         /* Memory mapped h/w address */
253         uint8_t *hw_addr;
254
255         struct otx_ep_fn_list fn_list;
256
257         uint32_t max_tx_queues;
258
259         uint32_t max_rx_queues;
260
261         /* Num OQs */
262         uint32_t nb_rx_queues;
263
264         /* The DROQ output queues  */
265         struct otx_ep_droq *droq[OTX_EP_MAX_IOQS_PER_VF];
266
267         /* IOQ mask */
268         struct otx_ep_io_enable io_qmask;
269
270         /* SR-IOV info */
271         struct otx_ep_sriov_info sriov_info;
272
273         /* Device configuration */
274         const struct otx_ep_config *conf;
275
276         uint64_t rx_offloads;
277
278         uint64_t tx_offloads;
279 };
280
281 int otx_ep_setup_oqs(struct otx_ep_device *otx_ep, int oq_no, int num_descs,
282                      int desc_size, struct rte_mempool *mpool,
283                      unsigned int socket_id);
284 int otx_ep_delete_oqs(struct otx_ep_device *otx_ep, uint32_t oq_no);
285
286 #define OTX_EP_MAX_PKT_SZ 64000U
287 #define OTX_EP_MAX_MAC_ADDRS 1
288
289 extern int otx_net_ep_logtype;
290 #endif  /* _OTX_EP_COMMON_H_ */