net/ice: enable flow director engine
[dpdk.git] / drivers / net / ice / ice_rxtx.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2018 Intel Corporation
3  */
4
5 #ifndef _ICE_RXTX_H_
6 #define _ICE_RXTX_H_
7
8 #include "rte_pmd_ice.h"
9 #include "ice_ethdev.h"
10
11 #define ICE_ALIGN_RING_DESC  32
12 #define ICE_MIN_RING_DESC    64
13 #define ICE_MAX_RING_DESC    4096
14 #define ICE_DMA_MEM_ALIGN    4096
15 #define ICE_RING_BASE_ALIGN  128
16
17 #define ICE_RX_MAX_BURST 32
18 #define ICE_TX_MAX_BURST 32
19
20 #define ICE_CHK_Q_ENA_COUNT        100
21 #define ICE_CHK_Q_ENA_INTERVAL_US  100
22
23 #ifdef RTE_LIBRTE_ICE_16BYTE_RX_DESC
24 #define ice_rx_flex_desc ice_16b_rx_flex_desc
25 #else
26 #define ice_rx_flex_desc ice_32b_rx_flex_desc
27 #endif
28
29 #define ICE_SUPPORT_CHAIN_NUM 5
30
31 #define ICE_TD_CMD                      ICE_TX_DESC_CMD_EOP
32
33 #define ICE_VPMD_RX_BURST           32
34 #define ICE_VPMD_TX_BURST           32
35 #define ICE_RXQ_REARM_THRESH        32
36 #define ICE_MAX_RX_BURST            ICE_RXQ_REARM_THRESH
37 #define ICE_TX_MAX_FREE_BUF_SZ      64
38 #define ICE_DESCS_PER_LOOP          4
39
40 #define ICE_FDIR_PKT_LEN        512
41
42 typedef void (*ice_rx_release_mbufs_t)(struct ice_rx_queue *rxq);
43 typedef void (*ice_tx_release_mbufs_t)(struct ice_tx_queue *txq);
44
45 struct ice_rx_entry {
46         struct rte_mbuf *mbuf;
47 };
48
49 struct ice_rx_queue {
50         struct rte_mempool *mp; /* mbuf pool to populate RX ring */
51         volatile union ice_rx_flex_desc *rx_ring;/* RX ring virtual address */
52         rte_iova_t rx_ring_dma; /* RX ring DMA address */
53         struct ice_rx_entry *sw_ring; /* address of RX soft ring */
54         uint16_t nb_rx_desc; /* number of RX descriptors */
55         uint16_t rx_free_thresh; /* max free RX desc to hold */
56         uint16_t rx_tail; /* current value of tail */
57         uint16_t nb_rx_hold; /* number of held free RX desc */
58         struct rte_mbuf *pkt_first_seg; /**< first segment of current packet */
59         struct rte_mbuf *pkt_last_seg; /**< last segment of current packet */
60         uint16_t rx_nb_avail; /**< number of staged packets ready */
61         uint16_t rx_next_avail; /**< index of next staged packets */
62         uint16_t rx_free_trigger; /**< triggers rx buffer allocation */
63         struct rte_mbuf fake_mbuf; /**< dummy mbuf */
64         struct rte_mbuf *rx_stage[ICE_RX_MAX_BURST * 2];
65
66         uint16_t rxrearm_nb;    /**< number of remaining to be re-armed */
67         uint16_t rxrearm_start; /**< the idx we start the re-arming from */
68         uint64_t mbuf_initializer; /**< value to init mbufs */
69
70         uint8_t port_id; /* device port ID */
71         uint8_t crc_len; /* 0 if CRC stripped, 4 otherwise */
72         uint16_t queue_id; /* RX queue index */
73         uint16_t reg_idx; /* RX queue register index */
74         uint8_t drop_en; /* if not 0, set register bit */
75         volatile uint8_t *qrx_tail; /* register address of tail */
76         struct ice_vsi *vsi; /* the VSI this queue belongs to */
77         uint16_t rx_buf_len; /* The packet buffer size */
78         uint16_t rx_hdr_len; /* The header buffer size */
79         uint16_t max_pkt_len; /* Maximum packet length */
80         bool q_set; /* indicate if rx queue has been configured */
81         bool rx_deferred_start; /* don't start this queue in dev start */
82         uint8_t proto_xtr; /* Protocol extraction from flexible descriptor */
83         ice_rx_release_mbufs_t rx_rel_mbufs;
84 };
85
86 struct ice_tx_entry {
87         struct rte_mbuf *mbuf;
88         uint16_t next_id;
89         uint16_t last_id;
90 };
91
92 struct ice_tx_queue {
93         uint16_t nb_tx_desc; /* number of TX descriptors */
94         rte_iova_t tx_ring_dma; /* TX ring DMA address */
95         volatile struct ice_tx_desc *tx_ring; /* TX ring virtual address */
96         struct ice_tx_entry *sw_ring; /* virtual address of SW ring */
97         uint16_t tx_tail; /* current value of tail register */
98         volatile uint8_t *qtx_tail; /* register address of tail */
99         uint16_t nb_tx_used; /* number of TX desc used since RS bit set */
100         /* index to last TX descriptor to have been cleaned */
101         uint16_t last_desc_cleaned;
102         /* Total number of TX descriptors ready to be allocated. */
103         uint16_t nb_tx_free;
104         /* Start freeing TX buffers if there are less free descriptors than
105          * this value.
106          */
107         uint16_t tx_free_thresh;
108         /* Number of TX descriptors to use before RS bit is set. */
109         uint16_t tx_rs_thresh;
110         uint8_t pthresh; /**< Prefetch threshold register. */
111         uint8_t hthresh; /**< Host threshold register. */
112         uint8_t wthresh; /**< Write-back threshold reg. */
113         uint8_t port_id; /* Device port identifier. */
114         uint16_t queue_id; /* TX queue index. */
115         uint32_t q_teid; /* TX schedule node id. */
116         uint16_t reg_idx;
117         uint64_t offloads;
118         struct ice_vsi *vsi; /* the VSI this queue belongs to */
119         uint16_t tx_next_dd;
120         uint16_t tx_next_rs;
121         bool tx_deferred_start; /* don't start this queue in dev start */
122         bool q_set; /* indicate if tx queue has been configured */
123         ice_tx_release_mbufs_t tx_rel_mbufs;
124 };
125
126 /* Offload features */
127 union ice_tx_offload {
128         uint64_t data;
129         struct {
130                 uint64_t l2_len:7; /* L2 (MAC) Header Length. */
131                 uint64_t l3_len:9; /* L3 (IP) Header Length. */
132                 uint64_t l4_len:8; /* L4 Header Length. */
133                 uint64_t tso_segsz:16; /* TCP TSO segment size */
134                 uint64_t outer_l2_len:8; /* outer L2 Header Length */
135                 uint64_t outer_l3_len:16; /* outer L3 Header Length */
136         };
137 };
138
139 int ice_rx_queue_setup(struct rte_eth_dev *dev,
140                        uint16_t queue_idx,
141                        uint16_t nb_desc,
142                        unsigned int socket_id,
143                        const struct rte_eth_rxconf *rx_conf,
144                        struct rte_mempool *mp);
145 int ice_tx_queue_setup(struct rte_eth_dev *dev,
146                        uint16_t queue_idx,
147                        uint16_t nb_desc,
148                        unsigned int socket_id,
149                        const struct rte_eth_txconf *tx_conf);
150 int ice_rx_queue_start(struct rte_eth_dev *dev, uint16_t rx_queue_id);
151 int ice_rx_queue_stop(struct rte_eth_dev *dev, uint16_t rx_queue_id);
152 int ice_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id);
153 int ice_tx_queue_stop(struct rte_eth_dev *dev, uint16_t tx_queue_id);
154 int ice_fdir_rx_queue_start(struct rte_eth_dev *dev, uint16_t rx_queue_id);
155 int ice_fdir_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id);
156 int ice_fdir_rx_queue_stop(struct rte_eth_dev *dev, uint16_t rx_queue_id);
157 int ice_fdir_tx_queue_stop(struct rte_eth_dev *dev, uint16_t tx_queue_id);
158 void ice_rx_queue_release(void *rxq);
159 void ice_tx_queue_release(void *txq);
160 void ice_clear_queues(struct rte_eth_dev *dev);
161 void ice_free_queues(struct rte_eth_dev *dev);
162 int ice_fdir_setup_tx_resources(struct ice_pf *pf);
163 int ice_fdir_setup_rx_resources(struct ice_pf *pf);
164 uint16_t ice_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
165                        uint16_t nb_pkts);
166 uint16_t ice_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
167                        uint16_t nb_pkts);
168 void ice_set_rx_function(struct rte_eth_dev *dev);
169 uint16_t ice_prep_pkts(__rte_unused void *tx_queue, struct rte_mbuf **tx_pkts,
170                        uint16_t nb_pkts);
171 void ice_set_tx_function_flag(struct rte_eth_dev *dev,
172                               struct ice_tx_queue *txq);
173 void ice_set_tx_function(struct rte_eth_dev *dev);
174 uint32_t ice_rx_queue_count(struct rte_eth_dev *dev, uint16_t rx_queue_id);
175 void ice_rxq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
176                       struct rte_eth_rxq_info *qinfo);
177 void ice_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
178                       struct rte_eth_txq_info *qinfo);
179 int ice_rx_burst_mode_get(struct rte_eth_dev *dev, uint16_t queue_id,
180                           struct rte_eth_burst_mode *mode);
181 int ice_tx_burst_mode_get(struct rte_eth_dev *dev, uint16_t queue_id,
182                           struct rte_eth_burst_mode *mode);
183 int ice_rx_descriptor_status(void *rx_queue, uint16_t offset);
184 int ice_tx_descriptor_status(void *tx_queue, uint16_t offset);
185 void ice_set_default_ptype_table(struct rte_eth_dev *dev);
186 const uint32_t *ice_dev_supported_ptypes_get(struct rte_eth_dev *dev);
187
188 int ice_rx_vec_dev_check(struct rte_eth_dev *dev);
189 int ice_tx_vec_dev_check(struct rte_eth_dev *dev);
190 int ice_rxq_vec_setup(struct ice_rx_queue *rxq);
191 int ice_txq_vec_setup(struct ice_tx_queue *txq);
192 uint16_t ice_recv_pkts_vec(void *rx_queue, struct rte_mbuf **rx_pkts,
193                            uint16_t nb_pkts);
194 uint16_t ice_recv_scattered_pkts_vec(void *rx_queue, struct rte_mbuf **rx_pkts,
195                                      uint16_t nb_pkts);
196 uint16_t ice_xmit_pkts_vec(void *tx_queue, struct rte_mbuf **tx_pkts,
197                            uint16_t nb_pkts);
198 uint16_t ice_recv_pkts_vec_avx2(void *rx_queue, struct rte_mbuf **rx_pkts,
199                                 uint16_t nb_pkts);
200 uint16_t ice_recv_scattered_pkts_vec_avx2(void *rx_queue,
201                                           struct rte_mbuf **rx_pkts,
202                                           uint16_t nb_pkts);
203 uint16_t ice_xmit_pkts_vec_avx2(void *tx_queue, struct rte_mbuf **tx_pkts,
204                                 uint16_t nb_pkts);
205 int ice_fdir_programming(struct ice_pf *pf, struct ice_fltr_desc *fdir_desc);
206 #endif /* _ICE_RXTX_H_ */