78b4928760758e606c94b82b59d2c49e193a8b79
[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 "ice_ethdev.h"
9
10 #define ICE_ALIGN_RING_DESC  32
11 #define ICE_MIN_RING_DESC    64
12 #define ICE_MAX_RING_DESC    4096
13 #define ICE_DMA_MEM_ALIGN    4096
14 #define ICE_RING_BASE_ALIGN  128
15
16 #define ICE_RX_MAX_BURST 32
17 #define ICE_TX_MAX_BURST 32
18
19 #define ICE_CHK_Q_ENA_COUNT        100
20 #define ICE_CHK_Q_ENA_INTERVAL_US  100
21
22 #ifdef RTE_LIBRTE_ICE_16BYTE_RX_DESC
23 #define ice_rx_desc ice_16byte_rx_desc
24 #else
25 #define ice_rx_desc ice_32byte_rx_desc
26 #endif
27
28 #define ICE_SUPPORT_CHAIN_NUM 5
29
30 typedef void (*ice_rx_release_mbufs_t)(struct ice_rx_queue *rxq);
31 typedef void (*ice_tx_release_mbufs_t)(struct ice_tx_queue *txq);
32
33 struct ice_rx_entry {
34         struct rte_mbuf *mbuf;
35 };
36
37 struct ice_rx_queue {
38         struct rte_mempool *mp; /* mbuf pool to populate RX ring */
39         volatile union ice_rx_desc *rx_ring;/* RX ring virtual address */
40         uint64_t rx_ring_phys_addr; /* RX ring DMA address */
41         struct ice_rx_entry *sw_ring; /* address of RX soft ring */
42         uint16_t nb_rx_desc; /* number of RX descriptors */
43         uint16_t rx_free_thresh; /* max free RX desc to hold */
44         uint16_t rx_tail; /* current value of tail */
45         uint16_t nb_rx_hold; /* number of held free RX desc */
46         struct rte_mbuf *pkt_first_seg; /**< first segment of current packet */
47         struct rte_mbuf *pkt_last_seg; /**< last segment of current packet */
48 #ifdef RTE_LIBRTE_ICE_RX_ALLOW_BULK_ALLOC
49         uint16_t rx_nb_avail; /**< number of staged packets ready */
50         uint16_t rx_next_avail; /**< index of next staged packets */
51         uint16_t rx_free_trigger; /**< triggers rx buffer allocation */
52         struct rte_mbuf fake_mbuf; /**< dummy mbuf */
53         struct rte_mbuf *rx_stage[ICE_RX_MAX_BURST * 2];
54 #endif
55         uint8_t port_id; /* device port ID */
56         uint8_t crc_len; /* 0 if CRC stripped, 4 otherwise */
57         uint16_t queue_id; /* RX queue index */
58         uint16_t reg_idx; /* RX queue register index */
59         uint8_t drop_en; /* if not 0, set register bit */
60         volatile uint8_t *qrx_tail; /* register address of tail */
61         struct ice_vsi *vsi; /* the VSI this queue belongs to */
62         uint16_t rx_buf_len; /* The packet buffer size */
63         uint16_t rx_hdr_len; /* The header buffer size */
64         uint16_t max_pkt_len; /* Maximum packet length */
65         bool q_set; /* indicate if rx queue has been configured */
66         bool rx_deferred_start; /* don't start this queue in dev start */
67         ice_rx_release_mbufs_t rx_rel_mbufs;
68 };
69
70 struct ice_tx_entry {
71         struct rte_mbuf *mbuf;
72         uint16_t next_id;
73         uint16_t last_id;
74 };
75
76 struct ice_tx_queue {
77         uint16_t nb_tx_desc; /* number of TX descriptors */
78         uint64_t tx_ring_phys_addr; /* TX ring DMA address */
79         volatile struct ice_tx_desc *tx_ring; /* TX ring virtual address */
80         struct ice_tx_entry *sw_ring; /* virtual address of SW ring */
81         uint16_t tx_tail; /* current value of tail register */
82         volatile uint8_t *qtx_tail; /* register address of tail */
83         uint16_t nb_tx_used; /* number of TX desc used since RS bit set */
84         /* index to last TX descriptor to have been cleaned */
85         uint16_t last_desc_cleaned;
86         /* Total number of TX descriptors ready to be allocated. */
87         uint16_t nb_tx_free;
88         /* Start freeing TX buffers if there are less free descriptors than
89          * this value.
90          */
91         uint16_t tx_free_thresh;
92         /* Number of TX descriptors to use before RS bit is set. */
93         uint16_t tx_rs_thresh;
94         uint8_t pthresh; /**< Prefetch threshold register. */
95         uint8_t hthresh; /**< Host threshold register. */
96         uint8_t wthresh; /**< Write-back threshold reg. */
97         uint8_t port_id; /* Device port identifier. */
98         uint16_t queue_id; /* TX queue index. */
99         uint32_t q_teid; /* TX schedule node id. */
100         uint16_t reg_idx;
101         uint64_t offloads;
102         struct ice_vsi *vsi; /* the VSI this queue belongs to */
103         uint16_t tx_next_dd;
104         uint16_t tx_next_rs;
105         bool tx_deferred_start; /* don't start this queue in dev start */
106         bool q_set; /* indicate if tx queue has been configured */
107         ice_tx_release_mbufs_t tx_rel_mbufs;
108 };
109
110 /* Offload features */
111 union ice_tx_offload {
112         uint64_t data;
113         struct {
114                 uint64_t l2_len:7; /* L2 (MAC) Header Length. */
115                 uint64_t l3_len:9; /* L3 (IP) Header Length. */
116                 uint64_t l4_len:8; /* L4 Header Length. */
117                 uint64_t tso_segsz:16; /* TCP TSO segment size */
118                 uint64_t outer_l2_len:8; /* outer L2 Header Length */
119                 uint64_t outer_l3_len:16; /* outer L3 Header Length */
120         };
121 };
122
123 int ice_rx_queue_setup(struct rte_eth_dev *dev,
124                        uint16_t queue_idx,
125                        uint16_t nb_desc,
126                        unsigned int socket_id,
127                        const struct rte_eth_rxconf *rx_conf,
128                        struct rte_mempool *mp);
129 int ice_tx_queue_setup(struct rte_eth_dev *dev,
130                        uint16_t queue_idx,
131                        uint16_t nb_desc,
132                        unsigned int socket_id,
133                        const struct rte_eth_txconf *tx_conf);
134 int ice_rx_queue_start(struct rte_eth_dev *dev, uint16_t rx_queue_id);
135 int ice_rx_queue_stop(struct rte_eth_dev *dev, uint16_t rx_queue_id);
136 int ice_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id);
137 int ice_tx_queue_stop(struct rte_eth_dev *dev, uint16_t tx_queue_id);
138 void ice_rx_queue_release(void *rxq);
139 void ice_tx_queue_release(void *txq);
140 void ice_clear_queues(struct rte_eth_dev *dev);
141 void ice_free_queues(struct rte_eth_dev *dev);
142 uint16_t ice_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
143                        uint16_t nb_pkts);
144 uint16_t ice_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
145                        uint16_t nb_pkts);
146 void ice_set_rx_function(struct rte_eth_dev *dev);
147 uint16_t ice_prep_pkts(__rte_unused void *tx_queue, struct rte_mbuf **tx_pkts,
148                        uint16_t nb_pkts);
149 void ice_set_tx_function(struct rte_eth_dev *dev);
150 uint32_t ice_rx_queue_count(struct rte_eth_dev *dev, uint16_t rx_queue_id);
151 void ice_rxq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
152                       struct rte_eth_rxq_info *qinfo);
153 void ice_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
154                       struct rte_eth_txq_info *qinfo);
155 int ice_rx_descriptor_status(void *rx_queue, uint16_t offset);
156 int ice_tx_descriptor_status(void *tx_queue, uint16_t offset);
157 void ice_set_default_ptype_table(struct rte_eth_dev *dev);
158 const uint32_t *ice_dev_supported_ptypes_get(struct rte_eth_dev *dev);
159 #endif /* _ICE_RXTX_H_ */