1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(C) 2021 Marvell.
4 #ifndef _OTX_EP_COMMON_H_
5 #define _OTX_EP_COMMON_H_
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)
17 #define OTX_EP_OQ_INFOPTR_MODE (0)
18 #define OTX_EP_OQ_REFIL_THRESHOLD (16)
19 #define OTX_EP_PCI_RING_ALIGN 65536
21 #define SDP_OTX2_PKIND 57
22 #define OTX_EP_MAX_IOQS_PER_VF 8
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)
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)
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)
39 /* Input Request Header format */
40 union otx_ep_instr_irh {
46 /* PCIe port to use for response */
49 /* Scatter indicator 1=scatter */
52 /* Size of Expected result OR no. of entries in scatter list */
55 /* Desired destination port for result */
58 /* Opcode Specific parameters */
61 /* Opcode for the return packet */
66 #define otx_ep_write64(value, base_addr, reg_off) \
68 typeof(value) val = (value); \
69 typeof(reg_off) off = (reg_off); \
70 otx_ep_dbg("octeon_write_csr64: reg: 0x%08lx val: 0x%016llx\n", \
71 (unsigned long)off, (unsigned long long)val); \
72 rte_write64(val, ((base_addr) + off)); \
75 /* Instruction Header - for OCTEON-TX models */
76 typedef union otx_ep_instr_ih {
85 /** PKIND for OTX_EP */
88 /** Front Data size */
91 /** No. of entries in gather list */
94 /** Gather indicator 1=gather*/
102 /* OTX_EP IQ request list */
103 struct otx_ep_instr_list {
107 #define OTX_EP_IQREQ_LIST_SIZE (sizeof(struct otx_ep_instr_list))
109 /* Input Queue statistics. Each input queue has four stats fields. */
110 struct otx_ep_iq_stats {
111 uint64_t instr_posted; /* Instructions posted to this queue. */
112 uint64_t instr_processed; /* Instructions processed in this queue. */
113 uint64_t instr_dropped; /* Instructions that could not be processed */
118 /* Structure to define the configuration attributes for each Input queue. */
119 struct otx_ep_iq_config {
120 /* Max number of IQs available */
123 /* Command size - 32 or 64 bytes */
126 /* Pending list size, usually set to the sum of the size of all IQs */
127 uint32_t pending_list_size;
130 /** The instruction (input) queue.
131 * The input queue is used to post raw (instruction) mode data or packet data
132 * to OCTEON TX2 device from the host. Each IQ of a OTX_EP EP VF device has one
133 * such structure to represent it.
135 struct otx_ep_instr_queue {
136 struct otx_ep_device *otx_ep_dev;
139 uint32_t pkt_in_done;
141 /* Flag for 64 byte commands. */
142 uint32_t iqcmd_64B:1;
146 /* Number of descriptors in this ring. */
149 /* Input ring index, where the driver should write the next packet */
150 uint32_t host_write_index;
152 /* Input ring index, where the OCTEON TX2 should read the next packet */
153 uint32_t otx_read_index;
155 uint32_t reset_instr_cnt;
157 /** This index aids in finding the window in the queue where OCTEON TX2
158 * has read the commands.
160 uint32_t flush_index;
162 /* This keeps track of the instructions pending in this queue. */
163 uint64_t instr_pending;
165 /* Pointer to the Virtual Base addr of the input ring. */
168 /* This IQ request list */
169 struct otx_ep_instr_list *req_list;
171 /* OTX_EP doorbell register for the ring. */
174 /* OTX_EP instruction count register for this ring. */
177 /* Number of instructions pending to be posted to OCTEON TX2. */
180 /* Statistics for this input queue. */
181 struct otx_ep_iq_stats stats;
183 /* DMA mapped base address of the input descriptor ring. */
184 uint64_t base_addr_dma;
187 const struct rte_memzone *iq_mz;
190 /** Descriptor format.
191 * The descriptor ring is made of descriptors which have 2 64-bit values:
192 * -# Physical (bus) address of the data buffer.
193 * -# Physical (bus) address of a otx_ep_droq_info structure.
194 * The device DMA's incoming packets and its information at the address
195 * given by these descriptor fields.
197 struct otx_ep_droq_desc {
198 /* The buffer pointer */
201 /* The Info pointer */
204 #define OTX_EP_DROQ_DESC_SIZE (sizeof(struct otx_ep_droq_desc))
210 #define OTX_EP_RH_SIZE (sizeof(union otx_ep_rh))
212 /** Information about packet DMA'ed by OCTEON TX2.
213 * The format of the information available at Info Pointer after OCTEON TX2
214 * has posted a packet. Not all descriptors have valid information. Only
215 * the Info field of the first descriptor for a packet has information
218 struct otx_ep_droq_info {
219 /* The Length of the packet. */
222 /* The Output Receive Header. */
225 #define OTX_EP_DROQ_INFO_SIZE (sizeof(struct otx_ep_droq_info))
227 /* DROQ statistics. Each output queue has four stats fields. */
228 struct otx_ep_droq_stats {
229 /* Number of packets received in this queue. */
230 uint64_t pkts_received;
232 /* Bytes received by this queue. */
233 uint64_t bytes_received;
235 /* Num of failures of rte_pktmbuf_alloc() */
236 uint64_t rx_alloc_failure;
241 /* packets with data got ready after interrupt arrived */
242 uint64_t pkts_delayed_data;
244 /* packets dropped due to zero length */
245 uint64_t dropped_zlp;
248 /* Structure to define the configuration attributes for each Output queue. */
249 struct otx_ep_oq_config {
250 /* Max number of OQs available */
253 /* If set, the Output queue uses info-pointer mode. (Default: 1 ) */
256 /** The number of buffers that were consumed during packet processing by
257 * the driver on this Output queue before the driver attempts to
258 * replenish the descriptor ring with new buffers.
260 uint32_t refill_threshold;
263 /* The Descriptor Ring Output Queue(DROQ) structure. */
265 struct otx_ep_device *otx_ep_dev;
266 /* The 8B aligned descriptor ring starts at this address. */
267 struct otx_ep_droq_desc *desc_ring;
270 uint64_t last_pkt_count;
272 struct rte_mempool *mpool;
274 /* Driver should read the next packet at this index */
277 /* OCTEON TX2 will write the next packet at this index */
280 /* At this index, the driver will refill the descriptor's buffer */
283 /* Packets pending to be processed */
284 uint64_t pkts_pending;
286 /* Number of descriptors in this ring. */
289 /* The number of descriptors pending to refill. */
290 uint32_t refill_count;
292 uint32_t refill_threshold;
294 /* The 8B aligned info ptrs begin from this address. */
295 struct otx_ep_droq_info *info_list;
297 /* receive buffer list contains mbuf ptr list */
298 struct rte_mbuf **recv_buf_list;
300 /* The size of each buffer pointed by the buffer pointer. */
301 uint32_t buffer_size;
303 /** Pointer to the mapped packet credit register.
304 * Host writes number of info/buffer ptrs available to this register
306 void *pkts_credit_reg;
308 /** Pointer to the mapped packet sent register. OCTEON TX2 writes the
309 * number of packets DMA'ed to host memory in this register.
313 /* Statistics for this DROQ. */
314 struct otx_ep_droq_stats stats;
316 /* DMA mapped address of the DROQ descriptor ring. */
317 size_t desc_ring_dma;
319 /* Info_ptr list is allocated at this virtual address. */
320 size_t info_base_addr;
322 /* DMA mapped address of the info list */
323 size_t info_list_dma;
325 /* Allocated size of info list. */
326 uint32_t info_alloc_size;
329 const struct rte_memzone *desc_ring_mz;
331 const struct rte_memzone *info_mz;
333 #define OTX_EP_DROQ_SIZE (sizeof(struct otx_ep_droq))
336 struct otx_ep_io_enable {
342 /* Structure to define the configuration. */
343 struct otx_ep_config {
344 /* Input Queue attributes. */
345 struct otx_ep_iq_config iq;
347 /* Output Queue attributes. */
348 struct otx_ep_oq_config oq;
350 /* Num of desc for IQ rings */
351 uint32_t num_iqdef_descs;
353 /* Num of desc for OQ rings */
354 uint32_t num_oqdef_descs;
357 uint32_t oqdef_buf_size;
360 /* SRIOV information */
361 struct otx_ep_sriov_info {
362 /* Number of rings assigned to VF */
363 uint32_t rings_per_vf;
365 /* Number of VF devices enabled */
369 /* Required functions for each VF device */
370 struct otx_ep_fn_list {
371 void (*setup_iq_regs)(struct otx_ep_device *otx_ep, uint32_t q_no);
373 void (*setup_oq_regs)(struct otx_ep_device *otx_ep, uint32_t q_no);
375 void (*setup_device_regs)(struct otx_ep_device *otx_ep);
377 void (*disable_io_queues)(struct otx_ep_device *otx_ep);
380 /* OTX_EP EP VF device data structure */
381 struct otx_ep_device {
382 /* PCI device pointer */
383 struct rte_pci_device *pdev;
389 struct rte_eth_dev *eth_dev;
393 /* Memory mapped h/w address */
396 struct otx_ep_fn_list fn_list;
398 uint32_t max_tx_queues;
400 uint32_t max_rx_queues;
403 uint32_t nb_tx_queues;
405 /* The input instruction queues */
406 struct otx_ep_instr_queue *instr_queue[OTX_EP_MAX_IOQS_PER_VF];
409 uint32_t nb_rx_queues;
411 /* The DROQ output queues */
412 struct otx_ep_droq *droq[OTX_EP_MAX_IOQS_PER_VF];
415 struct otx_ep_io_enable io_qmask;
418 struct otx_ep_sriov_info sriov_info;
420 /* Device configuration */
421 const struct otx_ep_config *conf;
423 uint64_t rx_offloads;
425 uint64_t tx_offloads;
428 int otx_ep_setup_iqs(struct otx_ep_device *otx_ep, uint32_t iq_no,
429 int num_descs, unsigned int socket_id);
430 int otx_ep_delete_iqs(struct otx_ep_device *otx_ep, uint32_t iq_no);
432 int otx_ep_setup_oqs(struct otx_ep_device *otx_ep, int oq_no, int num_descs,
433 int desc_size, struct rte_mempool *mpool,
434 unsigned int socket_id);
435 int otx_ep_delete_oqs(struct otx_ep_device *otx_ep, uint32_t oq_no);
437 #define OTX_EP_MAX_PKT_SZ 64000U
438 #define OTX_EP_MAX_MAC_ADDRS 1
439 #define OTX_EP_CLEAR_ISIZE_BSIZE 0x7FFFFFULL
440 #define OTX_EP_CLEAR_OUT_INT_LVLS 0x3FFFFFFFFFFFFFULL
441 #define OTX_EP_CLEAR_IN_INT_LVLS 0xFFFFFFFF
442 #define OTX_EP_CLEAR_SDP_IN_INT_LVLS 0x3FFFFFFFFFFFFFUL
443 #define OTX_EP_DROQ_BUFSZ_MASK 0xFFFF
444 #define OTX_EP_CLEAR_SLIST_DBELL 0xFFFFFFFF
445 #define OTX_EP_CLEAR_SDP_OUT_PKT_CNT 0xFFFFFFFFF
447 extern int otx_net_ep_logtype;
448 #endif /* _OTX_EP_COMMON_H_ */