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_BUSY_LOOP_COUNT (10000)
23 #define OTX_EP_MAX_IOQS_PER_VF 8
24 #define OTX_CUST_DATA_LEN 0
26 #define otx_ep_info(fmt, args...) \
27 rte_log(RTE_LOG_INFO, otx_net_ep_logtype, \
28 "%s():%u " fmt "\n", \
29 __func__, __LINE__, ##args)
31 #define otx_ep_err(fmt, args...) \
32 rte_log(RTE_LOG_ERR, otx_net_ep_logtype, \
33 "%s():%u " fmt "\n", \
34 __func__, __LINE__, ##args)
36 #define otx_ep_dbg(fmt, args...) \
37 rte_log(RTE_LOG_DEBUG, otx_net_ep_logtype, \
38 "%s():%u " fmt "\n", \
39 __func__, __LINE__, ##args)
41 /* Input Request Header format */
42 union otx_ep_instr_irh {
48 /* PCIe port to use for response */
51 /* Scatter indicator 1=scatter */
54 /* Size of Expected result OR no. of entries in scatter list */
57 /* Desired destination port for result */
60 /* Opcode Specific parameters */
63 /* Opcode for the return packet */
68 #define otx_ep_write64(value, base_addr, reg_off) \
70 typeof(value) val = (value); \
71 typeof(reg_off) off = (reg_off); \
72 otx_ep_dbg("octeon_write_csr64: reg: 0x%08lx val: 0x%016llx\n", \
73 (unsigned long)off, (unsigned long long)val); \
74 rte_write64(val, ((base_addr) + off)); \
77 /* Instruction Header - for OCTEON-TX models */
78 typedef union otx_ep_instr_ih {
87 /** PKIND for OTX_EP */
90 /** Front Data size */
93 /** No. of entries in gather list */
96 /** Gather indicator 1=gather*/
100 uint64_t reserved3:1;
104 /* OTX_EP IQ request list */
105 struct otx_ep_instr_list {
109 #define OTX_EP_IQREQ_LIST_SIZE (sizeof(struct otx_ep_instr_list))
111 /* Input Queue statistics. Each input queue has four stats fields. */
112 struct otx_ep_iq_stats {
113 uint64_t instr_posted; /* Instructions posted to this queue. */
114 uint64_t instr_processed; /* Instructions processed in this queue. */
115 uint64_t instr_dropped; /* Instructions that could not be processed */
120 /* Structure to define the configuration attributes for each Input queue. */
121 struct otx_ep_iq_config {
122 /* Max number of IQs available */
125 /* Command size - 32 or 64 bytes */
128 /* Pending list size, usually set to the sum of the size of all IQs */
129 uint32_t pending_list_size;
132 /** The instruction (input) queue.
133 * The input queue is used to post raw (instruction) mode data or packet data
134 * to OCTEON TX2 device from the host. Each IQ of a OTX_EP EP VF device has one
135 * such structure to represent it.
137 struct otx_ep_instr_queue {
138 struct otx_ep_device *otx_ep_dev;
141 uint32_t pkt_in_done;
143 /* Flag for 64 byte commands. */
144 uint32_t iqcmd_64B:1;
148 /* Number of descriptors in this ring. */
151 /* Input ring index, where the driver should write the next packet */
152 uint32_t host_write_index;
154 /* Input ring index, where the OCTEON TX2 should read the next packet */
155 uint32_t otx_read_index;
157 uint32_t reset_instr_cnt;
159 /** This index aids in finding the window in the queue where OCTEON TX2
160 * has read the commands.
162 uint32_t flush_index;
164 /* This keeps track of the instructions pending in this queue. */
165 uint64_t instr_pending;
167 /* Pointer to the Virtual Base addr of the input ring. */
170 /* This IQ request list */
171 struct otx_ep_instr_list *req_list;
173 /* OTX_EP doorbell register for the ring. */
176 /* OTX_EP instruction count register for this ring. */
179 /* Number of instructions pending to be posted to OCTEON TX2. */
182 /* Statistics for this input queue. */
183 struct otx_ep_iq_stats stats;
185 /* DMA mapped base address of the input descriptor ring. */
186 uint64_t base_addr_dma;
189 const struct rte_memzone *iq_mz;
192 /** Descriptor format.
193 * The descriptor ring is made of descriptors which have 2 64-bit values:
194 * -# Physical (bus) address of the data buffer.
195 * -# Physical (bus) address of a otx_ep_droq_info structure.
196 * The device DMA's incoming packets and its information at the address
197 * given by these descriptor fields.
199 struct otx_ep_droq_desc {
200 /* The buffer pointer */
203 /* The Info pointer */
206 #define OTX_EP_DROQ_DESC_SIZE (sizeof(struct otx_ep_droq_desc))
212 #define OTX_EP_RH_SIZE (sizeof(union otx_ep_rh))
214 /** Information about packet DMA'ed by OCTEON TX2.
215 * The format of the information available at Info Pointer after OCTEON TX2
216 * has posted a packet. Not all descriptors have valid information. Only
217 * the Info field of the first descriptor for a packet has information
220 struct otx_ep_droq_info {
221 /* The Length of the packet. */
224 /* The Output Receive Header. */
227 #define OTX_EP_DROQ_INFO_SIZE (sizeof(struct otx_ep_droq_info))
229 /* DROQ statistics. Each output queue has four stats fields. */
230 struct otx_ep_droq_stats {
231 /* Number of packets received in this queue. */
232 uint64_t pkts_received;
234 /* Bytes received by this queue. */
235 uint64_t bytes_received;
237 /* Num of failures of rte_pktmbuf_alloc() */
238 uint64_t rx_alloc_failure;
243 /* packets with data got ready after interrupt arrived */
244 uint64_t pkts_delayed_data;
246 /* packets dropped due to zero length */
247 uint64_t dropped_zlp;
250 /* Structure to define the configuration attributes for each Output queue. */
251 struct otx_ep_oq_config {
252 /* Max number of OQs available */
255 /* If set, the Output queue uses info-pointer mode. (Default: 1 ) */
258 /** The number of buffers that were consumed during packet processing by
259 * the driver on this Output queue before the driver attempts to
260 * replenish the descriptor ring with new buffers.
262 uint32_t refill_threshold;
265 /* The Descriptor Ring Output Queue(DROQ) structure. */
267 struct otx_ep_device *otx_ep_dev;
268 /* The 8B aligned descriptor ring starts at this address. */
269 struct otx_ep_droq_desc *desc_ring;
272 uint64_t last_pkt_count;
274 struct rte_mempool *mpool;
276 /* Driver should read the next packet at this index */
279 /* OCTEON TX2 will write the next packet at this index */
282 /* At this index, the driver will refill the descriptor's buffer */
285 /* Packets pending to be processed */
286 uint64_t pkts_pending;
288 /* Number of descriptors in this ring. */
291 /* The number of descriptors pending to refill. */
292 uint32_t refill_count;
294 uint32_t refill_threshold;
296 /* The 8B aligned info ptrs begin from this address. */
297 struct otx_ep_droq_info *info_list;
299 /* receive buffer list contains mbuf ptr list */
300 struct rte_mbuf **recv_buf_list;
302 /* The size of each buffer pointed by the buffer pointer. */
303 uint32_t buffer_size;
305 /** Pointer to the mapped packet credit register.
306 * Host writes number of info/buffer ptrs available to this register
308 void *pkts_credit_reg;
310 /** Pointer to the mapped packet sent register. OCTEON TX2 writes the
311 * number of packets DMA'ed to host memory in this register.
315 /* Statistics for this DROQ. */
316 struct otx_ep_droq_stats stats;
318 /* DMA mapped address of the DROQ descriptor ring. */
319 size_t desc_ring_dma;
321 /* Info_ptr list is allocated at this virtual address. */
322 size_t info_base_addr;
324 /* DMA mapped address of the info list */
325 size_t info_list_dma;
327 /* Allocated size of info list. */
328 uint32_t info_alloc_size;
331 const struct rte_memzone *desc_ring_mz;
333 const struct rte_memzone *info_mz;
335 #define OTX_EP_DROQ_SIZE (sizeof(struct otx_ep_droq))
338 struct otx_ep_io_enable {
344 /* Structure to define the configuration. */
345 struct otx_ep_config {
346 /* Input Queue attributes. */
347 struct otx_ep_iq_config iq;
349 /* Output Queue attributes. */
350 struct otx_ep_oq_config oq;
352 /* Num of desc for IQ rings */
353 uint32_t num_iqdef_descs;
355 /* Num of desc for OQ rings */
356 uint32_t num_oqdef_descs;
359 uint32_t oqdef_buf_size;
362 /* SRIOV information */
363 struct otx_ep_sriov_info {
364 /* Number of rings assigned to VF */
365 uint32_t rings_per_vf;
367 /* Number of VF devices enabled */
371 /* Required functions for each VF device */
372 struct otx_ep_fn_list {
373 void (*setup_iq_regs)(struct otx_ep_device *otx_ep, uint32_t q_no);
375 void (*setup_oq_regs)(struct otx_ep_device *otx_ep, uint32_t q_no);
377 void (*setup_device_regs)(struct otx_ep_device *otx_ep);
379 int (*enable_io_queues)(struct otx_ep_device *otx_ep);
380 void (*disable_io_queues)(struct otx_ep_device *otx_ep);
382 int (*enable_iq)(struct otx_ep_device *otx_ep, uint32_t q_no);
383 void (*disable_iq)(struct otx_ep_device *otx_ep, uint32_t q_no);
385 int (*enable_oq)(struct otx_ep_device *otx_ep, uint32_t q_no);
386 void (*disable_oq)(struct otx_ep_device *otx_ep, uint32_t q_no);
389 /* OTX_EP EP VF device data structure */
390 struct otx_ep_device {
391 /* PCI device pointer */
392 struct rte_pci_device *pdev;
398 struct rte_eth_dev *eth_dev;
402 /* Memory mapped h/w address */
405 struct otx_ep_fn_list fn_list;
407 uint32_t max_tx_queues;
409 uint32_t max_rx_queues;
412 uint32_t nb_tx_queues;
414 /* The input instruction queues */
415 struct otx_ep_instr_queue *instr_queue[OTX_EP_MAX_IOQS_PER_VF];
418 uint32_t nb_rx_queues;
420 /* The DROQ output queues */
421 struct otx_ep_droq *droq[OTX_EP_MAX_IOQS_PER_VF];
424 struct otx_ep_io_enable io_qmask;
427 struct otx_ep_sriov_info sriov_info;
429 /* Device configuration */
430 const struct otx_ep_config *conf;
432 uint64_t rx_offloads;
434 uint64_t tx_offloads;
437 int otx_ep_setup_iqs(struct otx_ep_device *otx_ep, uint32_t iq_no,
438 int num_descs, unsigned int socket_id);
439 int otx_ep_delete_iqs(struct otx_ep_device *otx_ep, uint32_t iq_no);
441 int otx_ep_setup_oqs(struct otx_ep_device *otx_ep, int oq_no, int num_descs,
442 int desc_size, struct rte_mempool *mpool,
443 unsigned int socket_id);
444 int otx_ep_delete_oqs(struct otx_ep_device *otx_ep, uint32_t oq_no);
446 #define OTX_EP_MAX_PKT_SZ 64000U
447 #define OTX_EP_MAX_MAC_ADDRS 1
448 #define OTX_EP_CLEAR_ISIZE_BSIZE 0x7FFFFFULL
449 #define OTX_EP_CLEAR_OUT_INT_LVLS 0x3FFFFFFFFFFFFFULL
450 #define OTX_EP_CLEAR_IN_INT_LVLS 0xFFFFFFFF
451 #define OTX_EP_CLEAR_SDP_IN_INT_LVLS 0x3FFFFFFFFFFFFFUL
452 #define OTX_EP_DROQ_BUFSZ_MASK 0xFFFF
453 #define OTX_EP_CLEAR_SLIST_DBELL 0xFFFFFFFF
454 #define OTX_EP_CLEAR_SDP_OUT_PKT_CNT 0xFFFFFFFFF
456 extern int otx_net_ep_logtype;
457 #endif /* _OTX_EP_COMMON_H_ */