net/avf: enable SSE Rx Tx
[dpdk.git] / drivers / net / avf / avf_rxtx.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2017 Intel Corporation
3  */
4
5 #ifndef _AVF_RXTX_H_
6 #define _AVF_RXTX_H_
7
8 /* In QLEN must be whole number of 32 descriptors. */
9 #define AVF_ALIGN_RING_DESC      32
10 #define AVF_MIN_RING_DESC        64
11 #define AVF_MAX_RING_DESC        4096
12 #define AVF_DMA_MEM_ALIGN        4096
13 /* Base address of the HW descriptor ring should be 128B aligned. */
14 #define AVF_RING_BASE_ALIGN      128
15
16 /* used for Rx Bulk Allocate */
17 #define AVF_RX_MAX_BURST         32
18
19 /* used for Vector PMD */
20 #define AVF_VPMD_RX_MAX_BURST    32
21 #define AVF_VPMD_TX_MAX_BURST    32
22 #define AVF_VPMD_DESCS_PER_LOOP  4
23 #define AVF_VPMD_TX_MAX_FREE_BUF 64
24
25 #define AVF_SIMPLE_FLAGS ((uint32_t)ETH_TXQ_FLAGS_NOMULTSEGS | \
26                           ETH_TXQ_FLAGS_NOOFFLOADS)
27
28 #define DEFAULT_TX_RS_THRESH     32
29 #define DEFAULT_TX_FREE_THRESH   32
30
31 #define AVF_MIN_TSO_MSS          256
32 #define AVF_MAX_TSO_MSS          9668
33 #define AVF_TSO_MAX_SEG          UINT8_MAX
34 #define AVF_TX_MAX_MTU_SEG       8
35
36 #define AVF_TX_CKSUM_OFFLOAD_MASK (              \
37                 PKT_TX_IP_CKSUM |                \
38                 PKT_TX_L4_MASK |                 \
39                 PKT_TX_TCP_SEG)
40
41 #define AVF_TX_OFFLOAD_MASK (  \
42                 PKT_TX_VLAN_PKT |                \
43                 PKT_TX_IP_CKSUM |                \
44                 PKT_TX_L4_MASK |                 \
45                 PKT_TX_TCP_SEG)
46
47 #define AVF_TX_OFFLOAD_NOTSUP_MASK \
48                 (PKT_TX_OFFLOAD_MASK ^ AVF_TX_OFFLOAD_MASK)
49
50 /* HW desc structure, both 16-byte and 32-byte types are supported */
51 #ifdef RTE_LIBRTE_AVF_16BYTE_RX_DESC
52 #define avf_rx_desc avf_16byte_rx_desc
53 #else
54 #define avf_rx_desc avf_32byte_rx_desc
55 #endif
56
57 struct avf_rxq_ops {
58         void (*release_mbufs)(struct avf_rx_queue *rxq);
59 };
60
61 struct avf_txq_ops {
62         void (*release_mbufs)(struct avf_tx_queue *txq);
63 };
64
65 /* Structure associated with each Rx queue. */
66 struct avf_rx_queue {
67         struct rte_mempool *mp;       /* mbuf pool to populate Rx ring */
68         const struct rte_memzone *mz; /* memzone for Rx ring */
69         volatile union avf_rx_desc *rx_ring; /* Rx ring virtual address */
70         uint64_t rx_ring_phys_addr;   /* Rx ring DMA address */
71         struct rte_mbuf **sw_ring;     /* address of SW ring */
72         uint16_t nb_rx_desc;          /* ring length */
73         uint16_t rx_tail;             /* current value of tail */
74         volatile uint8_t *qrx_tail;   /* register address of tail */
75         uint16_t rx_free_thresh;      /* max free RX desc to hold */
76         uint16_t nb_rx_hold;          /* number of held free RX desc */
77         struct rte_mbuf *pkt_first_seg; /* first segment of current packet */
78         struct rte_mbuf *pkt_last_seg;  /* last segment of current packet */
79         struct rte_mbuf fake_mbuf;      /* dummy mbuf */
80
81         /* used for VPMD */
82         uint16_t rxrearm_nb;       /* number of remaining to be re-armed */
83         uint16_t rxrearm_start;    /* the idx we start the re-arming from */
84         uint64_t mbuf_initializer; /* value to init mbufs */
85
86         uint16_t port_id;        /* device port ID */
87         uint8_t crc_len;        /* 0 if CRC stripped, 4 otherwise */
88         uint16_t queue_id;      /* Rx queue index */
89         uint16_t rx_buf_len;    /* The packet buffer size */
90         uint16_t rx_hdr_len;    /* The header buffer size */
91         uint16_t max_pkt_len;   /* Maximum packet length */
92
93         bool q_set;             /* if rx queue has been configured */
94         bool rx_deferred_start; /* don't start this queue in dev start */
95         const struct avf_rxq_ops *ops;
96 };
97
98 struct avf_tx_entry {
99         struct rte_mbuf *mbuf;
100         uint16_t next_id;
101         uint16_t last_id;
102 };
103
104 /* Structure associated with each TX queue. */
105 struct avf_tx_queue {
106         const struct rte_memzone *mz;  /* memzone for Tx ring */
107         volatile struct avf_tx_desc *tx_ring; /* Tx ring virtual address */
108         uint64_t tx_ring_phys_addr;    /* Tx ring DMA address */
109         struct avf_tx_entry *sw_ring;  /* address array of SW ring */
110         uint16_t nb_tx_desc;           /* ring length */
111         uint16_t tx_tail;              /* current value of tail */
112         volatile uint8_t *qtx_tail;    /* register address of tail */
113         /* number of used desc since RS bit set */
114         uint16_t nb_used;
115         uint16_t nb_free;
116         uint16_t last_desc_cleaned;    /* last desc have been cleaned*/
117         uint16_t free_thresh;
118         uint16_t rs_thresh;
119
120         uint16_t port_id;
121         uint16_t queue_id;
122         uint32_t txq_flags;
123         uint16_t next_dd;              /* next to set RS, for VPMD */
124         uint16_t next_rs;              /* next to check DD,  for VPMD */
125
126         bool q_set;                    /* if rx queue has been configured */
127         bool tx_deferred_start;        /* don't start this queue in dev start */
128         const struct avf_txq_ops *ops;
129 };
130
131 /* Offload features */
132 union avf_tx_offload {
133         uint64_t data;
134         struct {
135                 uint64_t l2_len:7; /* L2 (MAC) Header Length. */
136                 uint64_t l3_len:9; /* L3 (IP) Header Length. */
137                 uint64_t l4_len:8; /* L4 Header Length. */
138                 uint64_t tso_segsz:16; /* TCP TSO segment size */
139                 /* uint64_t unused : 24; */
140         };
141 };
142
143 int avf_dev_rx_queue_setup(struct rte_eth_dev *dev,
144                            uint16_t queue_idx,
145                            uint16_t nb_desc,
146                            unsigned int socket_id,
147                            const struct rte_eth_rxconf *rx_conf,
148                            struct rte_mempool *mp);
149
150 int avf_dev_rx_queue_start(struct rte_eth_dev *dev, uint16_t rx_queue_id);
151 int avf_dev_rx_queue_stop(struct rte_eth_dev *dev, uint16_t rx_queue_id);
152 void avf_dev_rx_queue_release(void *rxq);
153
154 int avf_dev_tx_queue_setup(struct rte_eth_dev *dev,
155                            uint16_t queue_idx,
156                            uint16_t nb_desc,
157                            unsigned int socket_id,
158                            const struct rte_eth_txconf *tx_conf);
159 int avf_dev_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id);
160 int avf_dev_tx_queue_stop(struct rte_eth_dev *dev, uint16_t tx_queue_id);
161 void avf_dev_tx_queue_release(void *txq);
162 void avf_stop_queues(struct rte_eth_dev *dev);
163 uint16_t avf_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
164                        uint16_t nb_pkts);
165 uint16_t avf_recv_scattered_pkts(void *rx_queue,
166                                  struct rte_mbuf **rx_pkts,
167                                  uint16_t nb_pkts);
168 uint16_t avf_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
169                        uint16_t nb_pkts);
170 uint16_t avf_prep_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
171                        uint16_t nb_pkts);
172 void avf_set_rx_function(struct rte_eth_dev *dev);
173 void avf_set_tx_function(struct rte_eth_dev *dev);
174 void avf_dev_rxq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
175                           struct rte_eth_rxq_info *qinfo);
176 void avf_dev_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
177                           struct rte_eth_txq_info *qinfo);
178 uint32_t avf_dev_rxq_count(struct rte_eth_dev *dev, uint16_t queue_id);
179 int avf_dev_rx_desc_status(void *rx_queue, uint16_t offset);
180 int avf_dev_tx_desc_status(void *tx_queue, uint16_t offset);
181
182 uint16_t avf_recv_pkts_vec(void *rx_queue, struct rte_mbuf **rx_pkts,
183                            uint16_t nb_pkts);
184 uint16_t avf_recv_scattered_pkts_vec(void *rx_queue,
185                                      struct rte_mbuf **rx_pkts,
186                                      uint16_t nb_pkts);
187 uint16_t avf_xmit_fixed_burst_vec(void *tx_queue, struct rte_mbuf **tx_pkts,
188                                   uint16_t nb_pkts);
189 int avf_rxq_vec_setup(struct avf_rx_queue *rxq);
190 int avf_txq_vec_setup(struct avf_tx_queue *txq);
191
192 static inline
193 void avf_dump_rx_descriptor(struct avf_rx_queue *rxq,
194                             const void *desc,
195                             uint16_t rx_id)
196 {
197 #ifdef RTE_LIBRTE_AVF_16BYTE_RX_DESC
198         const union avf_16byte_rx_desc *rx_desc = desc;
199
200         printf("Queue %d Rx_desc %d: QW0: 0x%016"PRIx64" QW1: 0x%016"PRIx64"\n",
201                rxq->queue_id, rx_id, rx_desc->read.pkt_addr,
202                rx_desc->read.hdr_addr);
203 #else
204         const union avf_32byte_rx_desc *rx_desc = desc;
205
206         printf("Queue %d Rx_desc %d: QW0: 0x%016"PRIx64" QW1: 0x%016"PRIx64
207                " QW2: 0x%016"PRIx64" QW3: 0x%016"PRIx64"\n", rxq->queue_id,
208                rx_id, rx_desc->read.pkt_addr, rx_desc->read.hdr_addr,
209                rx_desc->read.rsvd1, rx_desc->read.rsvd2);
210 #endif
211 }
212
213 /* All the descriptors are 16 bytes, so just use one of them
214  * to print the qwords
215  */
216 static inline
217 void avf_dump_tx_descriptor(const struct avf_tx_queue *txq,
218                             const void *desc, uint16_t tx_id)
219 {
220         char *name;
221         const struct avf_tx_desc *tx_desc = desc;
222         enum avf_tx_desc_dtype_value type;
223
224         type = (enum avf_tx_desc_dtype_value)rte_le_to_cpu_64(
225                 tx_desc->cmd_type_offset_bsz &
226                 rte_cpu_to_le_64(AVF_TXD_QW1_DTYPE_MASK));
227         switch (type) {
228         case AVF_TX_DESC_DTYPE_DATA:
229                 name = "Tx_data_desc";
230                 break;
231         case AVF_TX_DESC_DTYPE_CONTEXT:
232                 name = "Tx_context_desc";
233                 break;
234         default:
235                 name = "unknown_desc";
236                 break;
237         }
238
239         printf("Queue %d %s %d: QW0: 0x%016"PRIx64" QW1: 0x%016"PRIx64"\n",
240                txq->queue_id, name, tx_id, tx_desc->buffer_addr,
241                tx_desc->cmd_type_offset_bsz);
242 }
243
244 #ifdef DEBUG_DUMP_DESC
245 #define AVF_DUMP_RX_DESC(rxq, desc, rx_id) \
246         avf_dump_rx_descriptor(rxq, desc, rx_id)
247 #define AVF_DUMP_TX_DESC(txq, desc, tx_id) \
248         avf_dump_tx_descriptor(txq, desc, tx_id)
249 #else
250 #define AVF_DUMP_RX_DESC(rxq, desc, rx_id) do { } while (0)
251 #define AVF_DUMP_TX_DESC(txq, desc, tx_id) do { } while (0)
252 #endif
253
254 #endif /* _AVF_RXTX_H_ */