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 #define otx_ep_write64(value, base_addr, reg_off) \
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)); \
50 /* Structure to define the configuration attributes for each Input queue. */
51 struct otx_ep_iq_config {
52 /* Max number of IQs available */
55 /* Command size - 32 or 64 bytes */
58 /* Pending list size, usually set to the sum of the size of all IQs */
59 uint32_t pending_list_size;
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.
69 struct otx_ep_droq_desc {
70 /* The buffer pointer */
73 /* The Info pointer */
76 #define OTX_EP_DROQ_DESC_SIZE (sizeof(struct otx_ep_droq_desc))
82 #define OTX_EP_RH_SIZE (sizeof(union otx_ep_rh))
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
90 struct otx_ep_droq_info {
91 /* The Length of the packet. */
94 /* The Output Receive Header. */
97 #define OTX_EP_DROQ_INFO_SIZE (sizeof(struct otx_ep_droq_info))
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;
104 /* Bytes received by this queue. */
105 uint64_t bytes_received;
107 /* Num of failures of rte_pktmbuf_alloc() */
108 uint64_t rx_alloc_failure;
113 /* packets with data got ready after interrupt arrived */
114 uint64_t pkts_delayed_data;
116 /* packets dropped due to zero length */
117 uint64_t dropped_zlp;
120 /* Structure to define the configuration attributes for each Output queue. */
121 struct otx_ep_oq_config {
122 /* Max number of OQs available */
125 /* If set, the Output queue uses info-pointer mode. (Default: 1 ) */
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.
132 uint32_t refill_threshold;
135 /* The Descriptor Ring Output Queue(DROQ) structure. */
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;
142 uint64_t last_pkt_count;
144 struct rte_mempool *mpool;
146 /* Driver should read the next packet at this index */
149 /* OCTEON TX2 will write the next packet at this index */
152 /* At this index, the driver will refill the descriptor's buffer */
155 /* Packets pending to be processed */
156 uint64_t pkts_pending;
158 /* Number of descriptors in this ring. */
161 /* The number of descriptors pending to refill. */
162 uint32_t refill_count;
164 uint32_t refill_threshold;
166 /* The 8B aligned info ptrs begin from this address. */
167 struct otx_ep_droq_info *info_list;
169 /* receive buffer list contains mbuf ptr list */
170 struct rte_mbuf **recv_buf_list;
172 /* The size of each buffer pointed by the buffer pointer. */
173 uint32_t buffer_size;
175 /* Statistics for this DROQ. */
176 struct otx_ep_droq_stats stats;
178 /* DMA mapped address of the DROQ descriptor ring. */
179 size_t desc_ring_dma;
181 /* Info_ptr list is allocated at this virtual address. */
182 size_t info_base_addr;
184 /* DMA mapped address of the info list */
185 size_t info_list_dma;
187 /* Allocated size of info list. */
188 uint32_t info_alloc_size;
191 const struct rte_memzone *desc_ring_mz;
192 const struct rte_memzone *info_mz;
194 #define OTX_EP_DROQ_SIZE (sizeof(struct otx_ep_droq))
197 struct otx_ep_io_enable {
203 /* Structure to define the configuration. */
204 struct otx_ep_config {
205 /* Input Queue attributes. */
206 struct otx_ep_iq_config iq;
208 /* Output Queue attributes. */
209 struct otx_ep_oq_config oq;
211 /* Num of desc for IQ rings */
212 uint32_t num_iqdef_descs;
214 /* Num of desc for OQ rings */
215 uint32_t num_oqdef_descs;
218 uint32_t oqdef_buf_size;
221 /* SRIOV information */
222 struct otx_ep_sriov_info {
223 /* Number of rings assigned to VF */
224 uint32_t rings_per_vf;
226 /* Number of VF devices enabled */
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);
234 void (*setup_device_regs)(struct otx_ep_device *otx_ep);
236 void (*disable_io_queues)(struct otx_ep_device *otx_ep);
239 /* OTX_EP EP VF device data structure */
240 struct otx_ep_device {
241 /* PCI device pointer */
242 struct rte_pci_device *pdev;
248 struct rte_eth_dev *eth_dev;
252 /* Memory mapped h/w address */
255 struct otx_ep_fn_list fn_list;
257 uint32_t max_tx_queues;
259 uint32_t max_rx_queues;
262 uint32_t nb_rx_queues;
264 /* The DROQ output queues */
265 struct otx_ep_droq *droq[OTX_EP_MAX_IOQS_PER_VF];
268 struct otx_ep_io_enable io_qmask;
271 struct otx_ep_sriov_info sriov_info;
273 /* Device configuration */
274 const struct otx_ep_config *conf;
276 uint64_t rx_offloads;
278 uint64_t tx_offloads;
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);
286 #define OTX_EP_MAX_PKT_SZ 64000U
287 #define OTX_EP_MAX_MAC_ADDRS 1
289 extern int otx_net_ep_logtype;
290 #endif /* _OTX_EP_COMMON_H_ */