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
25 #define otx_ep_info(fmt, args...) \
26 rte_log(RTE_LOG_INFO, otx_net_ep_logtype, \
27 "%s():%u " fmt "\n", \
28 __func__, __LINE__, ##args)
30 #define otx_ep_err(fmt, args...) \
31 rte_log(RTE_LOG_ERR, otx_net_ep_logtype, \
32 "%s():%u " fmt "\n", \
33 __func__, __LINE__, ##args)
35 #define otx_ep_dbg(fmt, args...) \
36 rte_log(RTE_LOG_DEBUG, otx_net_ep_logtype, \
37 "%s():%u " fmt "\n", \
38 __func__, __LINE__, ##args)
40 /* Input Request Header format */
41 union otx_ep_instr_irh {
47 /* PCIe port to use for response */
50 /* Scatter indicator 1=scatter */
53 /* Size of Expected result OR no. of entries in scatter list */
56 /* Desired destination port for result */
59 /* Opcode Specific parameters */
62 /* Opcode for the return packet */
67 #define otx_ep_write64(value, base_addr, reg_off) \
69 typeof(value) val = (value); \
70 typeof(reg_off) off = (reg_off); \
71 otx_ep_dbg("octeon_write_csr64: reg: 0x%08lx val: 0x%016llx\n", \
72 (unsigned long)off, (unsigned long long)val); \
73 rte_write64(val, ((base_addr) + off)); \
76 /* Instruction Header - for OCTEON-TX models */
77 typedef union otx_ep_instr_ih {
86 /** PKIND for OTX_EP */
89 /** Front Data size */
92 /** No. of entries in gather list */
95 /** Gather indicator 1=gather*/
103 /* OTX_EP IQ request list */
104 struct otx_ep_instr_list {
108 #define OTX_EP_IQREQ_LIST_SIZE (sizeof(struct otx_ep_instr_list))
110 /* Input Queue statistics. Each input queue has four stats fields. */
111 struct otx_ep_iq_stats {
112 uint64_t instr_posted; /* Instructions posted to this queue. */
113 uint64_t instr_processed; /* Instructions processed in this queue. */
114 uint64_t instr_dropped; /* Instructions that could not be processed */
119 /* Structure to define the configuration attributes for each Input queue. */
120 struct otx_ep_iq_config {
121 /* Max number of IQs available */
124 /* Command size - 32 or 64 bytes */
127 /* Pending list size, usually set to the sum of the size of all IQs */
128 uint32_t pending_list_size;
131 /** The instruction (input) queue.
132 * The input queue is used to post raw (instruction) mode data or packet data
133 * to OCTEON TX2 device from the host. Each IQ of a OTX_EP EP VF device has one
134 * such structure to represent it.
136 struct otx_ep_instr_queue {
137 struct otx_ep_device *otx_ep_dev;
140 uint32_t pkt_in_done;
142 /* Flag for 64 byte commands. */
143 uint32_t iqcmd_64B:1;
147 /* Number of descriptors in this ring. */
150 /* Input ring index, where the driver should write the next packet */
151 uint32_t host_write_index;
153 /* Input ring index, where the OCTEON TX2 should read the next packet */
154 uint32_t otx_read_index;
156 uint32_t reset_instr_cnt;
158 /** This index aids in finding the window in the queue where OCTEON TX2
159 * has read the commands.
161 uint32_t flush_index;
163 /* This keeps track of the instructions pending in this queue. */
164 uint64_t instr_pending;
166 /* Pointer to the Virtual Base addr of the input ring. */
169 /* This IQ request list */
170 struct otx_ep_instr_list *req_list;
172 /* OTX_EP doorbell register for the ring. */
175 /* OTX_EP instruction count register for this ring. */
178 /* Number of instructions pending to be posted to OCTEON TX2. */
181 /* Statistics for this input queue. */
182 struct otx_ep_iq_stats stats;
184 /* DMA mapped base address of the input descriptor ring. */
185 uint64_t base_addr_dma;
188 const struct rte_memzone *iq_mz;
191 /** Descriptor format.
192 * The descriptor ring is made of descriptors which have 2 64-bit values:
193 * -# Physical (bus) address of the data buffer.
194 * -# Physical (bus) address of a otx_ep_droq_info structure.
195 * The device DMA's incoming packets and its information at the address
196 * given by these descriptor fields.
198 struct otx_ep_droq_desc {
199 /* The buffer pointer */
202 /* The Info pointer */
205 #define OTX_EP_DROQ_DESC_SIZE (sizeof(struct otx_ep_droq_desc))
211 #define OTX_EP_RH_SIZE (sizeof(union otx_ep_rh))
213 /** Information about packet DMA'ed by OCTEON TX2.
214 * The format of the information available at Info Pointer after OCTEON TX2
215 * has posted a packet. Not all descriptors have valid information. Only
216 * the Info field of the first descriptor for a packet has information
219 struct otx_ep_droq_info {
220 /* The Length of the packet. */
223 /* The Output Receive Header. */
226 #define OTX_EP_DROQ_INFO_SIZE (sizeof(struct otx_ep_droq_info))
228 /* DROQ statistics. Each output queue has four stats fields. */
229 struct otx_ep_droq_stats {
230 /* Number of packets received in this queue. */
231 uint64_t pkts_received;
233 /* Bytes received by this queue. */
234 uint64_t bytes_received;
236 /* Num of failures of rte_pktmbuf_alloc() */
237 uint64_t rx_alloc_failure;
242 /* packets with data got ready after interrupt arrived */
243 uint64_t pkts_delayed_data;
245 /* packets dropped due to zero length */
246 uint64_t dropped_zlp;
249 /* Structure to define the configuration attributes for each Output queue. */
250 struct otx_ep_oq_config {
251 /* Max number of OQs available */
254 /* If set, the Output queue uses info-pointer mode. (Default: 1 ) */
257 /** The number of buffers that were consumed during packet processing by
258 * the driver on this Output queue before the driver attempts to
259 * replenish the descriptor ring with new buffers.
261 uint32_t refill_threshold;
264 /* The Descriptor Ring Output Queue(DROQ) structure. */
266 struct otx_ep_device *otx_ep_dev;
267 /* The 8B aligned descriptor ring starts at this address. */
268 struct otx_ep_droq_desc *desc_ring;
271 uint64_t last_pkt_count;
273 struct rte_mempool *mpool;
275 /* Driver should read the next packet at this index */
278 /* OCTEON TX2 will write the next packet at this index */
281 /* At this index, the driver will refill the descriptor's buffer */
284 /* Packets pending to be processed */
285 uint64_t pkts_pending;
287 /* Number of descriptors in this ring. */
290 /* The number of descriptors pending to refill. */
291 uint32_t refill_count;
293 uint32_t refill_threshold;
295 /* The 8B aligned info ptrs begin from this address. */
296 struct otx_ep_droq_info *info_list;
298 /* receive buffer list contains mbuf ptr list */
299 struct rte_mbuf **recv_buf_list;
301 /* The size of each buffer pointed by the buffer pointer. */
302 uint32_t buffer_size;
304 /** Pointer to the mapped packet credit register.
305 * Host writes number of info/buffer ptrs available to this register
307 void *pkts_credit_reg;
309 /** Pointer to the mapped packet sent register. OCTEON TX2 writes the
310 * number of packets DMA'ed to host memory in this register.
314 /* Statistics for this DROQ. */
315 struct otx_ep_droq_stats stats;
317 /* DMA mapped address of the DROQ descriptor ring. */
318 size_t desc_ring_dma;
320 /* Info_ptr list is allocated at this virtual address. */
321 size_t info_base_addr;
323 /* DMA mapped address of the info list */
324 size_t info_list_dma;
326 /* Allocated size of info list. */
327 uint32_t info_alloc_size;
330 const struct rte_memzone *desc_ring_mz;
332 const struct rte_memzone *info_mz;
334 #define OTX_EP_DROQ_SIZE (sizeof(struct otx_ep_droq))
337 struct otx_ep_io_enable {
343 /* Structure to define the configuration. */
344 struct otx_ep_config {
345 /* Input Queue attributes. */
346 struct otx_ep_iq_config iq;
348 /* Output Queue attributes. */
349 struct otx_ep_oq_config oq;
351 /* Num of desc for IQ rings */
352 uint32_t num_iqdef_descs;
354 /* Num of desc for OQ rings */
355 uint32_t num_oqdef_descs;
358 uint32_t oqdef_buf_size;
361 /* SRIOV information */
362 struct otx_ep_sriov_info {
363 /* Number of rings assigned to VF */
364 uint32_t rings_per_vf;
366 /* Number of VF devices enabled */
370 /* Required functions for each VF device */
371 struct otx_ep_fn_list {
372 void (*setup_iq_regs)(struct otx_ep_device *otx_ep, uint32_t q_no);
374 void (*setup_oq_regs)(struct otx_ep_device *otx_ep, uint32_t q_no);
376 void (*setup_device_regs)(struct otx_ep_device *otx_ep);
378 int (*enable_io_queues)(struct otx_ep_device *otx_ep);
379 void (*disable_io_queues)(struct otx_ep_device *otx_ep);
381 int (*enable_iq)(struct otx_ep_device *otx_ep, uint32_t q_no);
382 void (*disable_iq)(struct otx_ep_device *otx_ep, uint32_t q_no);
384 int (*enable_oq)(struct otx_ep_device *otx_ep, uint32_t q_no);
385 void (*disable_oq)(struct otx_ep_device *otx_ep, uint32_t q_no);
388 /* OTX_EP EP VF device data structure */
389 struct otx_ep_device {
390 /* PCI device pointer */
391 struct rte_pci_device *pdev;
397 struct rte_eth_dev *eth_dev;
401 /* Memory mapped h/w address */
404 struct otx_ep_fn_list fn_list;
406 uint32_t max_tx_queues;
408 uint32_t max_rx_queues;
411 uint32_t nb_tx_queues;
413 /* The input instruction queues */
414 struct otx_ep_instr_queue *instr_queue[OTX_EP_MAX_IOQS_PER_VF];
417 uint32_t nb_rx_queues;
419 /* The DROQ output queues */
420 struct otx_ep_droq *droq[OTX_EP_MAX_IOQS_PER_VF];
423 struct otx_ep_io_enable io_qmask;
426 struct otx_ep_sriov_info sriov_info;
428 /* Device configuration */
429 const struct otx_ep_config *conf;
431 uint64_t rx_offloads;
433 uint64_t tx_offloads;
436 int otx_ep_setup_iqs(struct otx_ep_device *otx_ep, uint32_t iq_no,
437 int num_descs, unsigned int socket_id);
438 int otx_ep_delete_iqs(struct otx_ep_device *otx_ep, uint32_t iq_no);
440 int otx_ep_setup_oqs(struct otx_ep_device *otx_ep, int oq_no, int num_descs,
441 int desc_size, struct rte_mempool *mpool,
442 unsigned int socket_id);
443 int otx_ep_delete_oqs(struct otx_ep_device *otx_ep, uint32_t oq_no);
445 #define OTX_EP_MAX_PKT_SZ 64000U
446 #define OTX_EP_MAX_MAC_ADDRS 1
447 #define OTX_EP_CLEAR_ISIZE_BSIZE 0x7FFFFFULL
448 #define OTX_EP_CLEAR_OUT_INT_LVLS 0x3FFFFFFFFFFFFFULL
449 #define OTX_EP_CLEAR_IN_INT_LVLS 0xFFFFFFFF
450 #define OTX_EP_CLEAR_SDP_IN_INT_LVLS 0x3FFFFFFFFFFFFFUL
451 #define OTX_EP_DROQ_BUFSZ_MASK 0xFFFF
452 #define OTX_EP_CLEAR_SLIST_DBELL 0xFFFFFFFF
453 #define OTX_EP_CLEAR_SDP_OUT_PKT_CNT 0xFFFFFFFFF
455 extern int otx_net_ep_logtype;
456 #endif /* _OTX_EP_COMMON_H_ */