21f2dacd1d47d3f0ee0765a988e30bd6383ebbed
[deb_dpdk.git] / drivers / net / qede / qede_rxtx.h
1 /*
2  * Copyright (c) 2016 QLogic Corporation.
3  * All rights reserved.
4  * www.qlogic.com
5  *
6  * See LICENSE.qede_pmd for copyright and licensing details.
7  */
8
9
10 #ifndef _QEDE_RXTX_H_
11 #define _QEDE_RXTX_H_
12
13 #include "qede_ethdev.h"
14
15 /* Ring Descriptors */
16 #define RX_RING_SIZE_POW        16      /* 64K */
17 #define RX_RING_SIZE            (1ULL << RX_RING_SIZE_POW)
18 #define NUM_RX_BDS_MAX          (RX_RING_SIZE - 1)
19 #define NUM_RX_BDS_MIN          128
20 #define NUM_RX_BDS_DEF          NUM_RX_BDS_MAX
21 #define NUM_RX_BDS(q)           (q->nb_rx_desc - 1)
22
23 #define TX_RING_SIZE_POW        16      /* 64K */
24 #define TX_RING_SIZE            (1ULL << TX_RING_SIZE_POW)
25 #define NUM_TX_BDS_MAX          (TX_RING_SIZE - 1)
26 #define NUM_TX_BDS_MIN          128
27 #define NUM_TX_BDS_DEF          NUM_TX_BDS_MAX
28 #define NUM_TX_BDS(q)           (q->nb_tx_desc - 1)
29
30 #define TX_CONS(txq)            (txq->sw_tx_cons & NUM_TX_BDS(txq))
31 #define TX_PROD(txq)            (txq->sw_tx_prod & NUM_TX_BDS(txq))
32
33 #define QEDE_DEFAULT_TX_FREE_THRESH     32
34
35 #define QEDE_CSUM_ERROR                 (1 << 0)
36 #define QEDE_CSUM_UNNECESSARY           (1 << 1)
37 #define QEDE_TUNN_CSUM_UNNECESSARY      (1 << 2)
38
39 #define QEDE_BD_SET_ADDR_LEN(bd, maddr, len) \
40         do { \
41                 (bd)->addr.hi = rte_cpu_to_le_32(U64_HI(maddr)); \
42                 (bd)->addr.lo = rte_cpu_to_le_32(U64_LO(maddr)); \
43                 (bd)->nbytes = rte_cpu_to_le_16(len); \
44         } while (0)
45
46 #define CQE_HAS_VLAN(flags) \
47         ((flags) & (PARSING_AND_ERR_FLAGS_TAG8021QEXIST_MASK \
48                 << PARSING_AND_ERR_FLAGS_TAG8021QEXIST_SHIFT))
49
50 #define CQE_HAS_OUTER_VLAN(flags) \
51         ((flags) & (PARSING_AND_ERR_FLAGS_TUNNEL8021QTAGEXIST_MASK \
52                 << PARSING_AND_ERR_FLAGS_TUNNEL8021QTAGEXIST_SHIFT))
53
54 #define QEDE_MIN_RX_BUFF_SIZE           (1024)
55 #define QEDE_VLAN_TAG_SIZE              (4)
56 #define QEDE_LLC_SNAP_HDR_LEN           (8)
57
58 /* Max supported alignment is 256 (8 shift)
59  * minimal alignment shift 6 is optimal for 57xxx HW performance
60  */
61 #define QEDE_L1_CACHE_SHIFT     6
62 #define QEDE_RX_ALIGN_SHIFT     (RTE_MAX(6, RTE_MIN(8, QEDE_L1_CACHE_SHIFT)))
63 #define QEDE_FW_RX_ALIGN_END    (1UL << QEDE_RX_ALIGN_SHIFT)
64 #define QEDE_CEIL_TO_CACHE_LINE_SIZE(n) (((n) + (QEDE_FW_RX_ALIGN_END - 1)) & \
65                                         ~(QEDE_FW_RX_ALIGN_END - 1))
66 /* Note: QEDE_LLC_SNAP_HDR_LEN is optional */
67 #define QEDE_ETH_OVERHEAD       ((ETHER_HDR_LEN) + ((2 * QEDE_VLAN_TAG_SIZE)) \
68                                 + (QEDE_LLC_SNAP_HDR_LEN))
69
70 #define QEDE_RSS_OFFLOAD_ALL    (ETH_RSS_IPV4                   |\
71                                  ETH_RSS_NONFRAG_IPV4_TCP       |\
72                                  ETH_RSS_NONFRAG_IPV4_UDP       |\
73                                  ETH_RSS_IPV6                   |\
74                                  ETH_RSS_NONFRAG_IPV6_TCP       |\
75                                  ETH_RSS_NONFRAG_IPV6_UDP       |\
76                                  ETH_RSS_VXLAN)
77
78 #define QEDE_TXQ_FLAGS          ((uint32_t)ETH_TXQ_FLAGS_NOMULTSEGS)
79
80 #define MAX_NUM_TC              8
81
82 #define for_each_queue(i) for (i = 0; i < qdev->num_queues; i++)
83
84
85 /* Macros for non-tunnel packet types lkup table */
86 #define QEDE_PKT_TYPE_UNKNOWN                           0x0
87 #define QEDE_PKT_TYPE_MAX                               0xf
88 #define QEDE_PKT_TYPE_IPV4                              0x1
89 #define QEDE_PKT_TYPE_IPV6                              0x2
90 #define QEDE_PKT_TYPE_IPV4_TCP                          0x5
91 #define QEDE_PKT_TYPE_IPV6_TCP                          0x6
92 #define QEDE_PKT_TYPE_IPV4_UDP                          0x9
93 #define QEDE_PKT_TYPE_IPV6_UDP                          0xa
94
95 /* Macros for tunneled packets with next protocol lkup table */
96 #define QEDE_PKT_TYPE_TUNN_GENEVE                       0x1
97 #define QEDE_PKT_TYPE_TUNN_GRE                          0x2
98 #define QEDE_PKT_TYPE_TUNN_VXLAN                        0x3
99
100 /* Bit 2 is don't care bit */
101 #define QEDE_PKT_TYPE_TUNN_L2_TENID_NOEXIST_GENEVE      0x9
102 #define QEDE_PKT_TYPE_TUNN_L2_TENID_NOEXIST_GRE 0xa
103 #define QEDE_PKT_TYPE_TUNN_L2_TENID_NOEXIST_VXLAN       0xb
104
105 #define QEDE_PKT_TYPE_TUNN_L2_TENID_EXIST_GENEVE        0xd
106 #define QEDE_PKT_TYPE_TUNN_L2_TENID_EXIST_GRE           0xe
107 #define QEDE_PKT_TYPE_TUNN_L2_TENID_EXIST_VXLAN 0xf
108
109
110 #define QEDE_PKT_TYPE_TUNN_IPV4_TENID_NOEXIST_GENEVE    0x11
111 #define QEDE_PKT_TYPE_TUNN_IPV4_TENID_NOEXIST_GRE       0x12
112 #define QEDE_PKT_TYPE_TUNN_IPV4_TENID_NOEXIST_VXLAN     0x13
113
114 #define QEDE_PKT_TYPE_TUNN_IPV4_TENID_EXIST_GENEVE      0x15
115 #define QEDE_PKT_TYPE_TUNN_IPV4_TENID_EXIST_GRE 0x16
116 #define QEDE_PKT_TYPE_TUNN_IPV4_TENID_EXIST_VXLAN       0x17
117
118
119 #define QEDE_PKT_TYPE_TUNN_IPV6_TENID_NOEXIST_GENEVE    0x19
120 #define QEDE_PKT_TYPE_TUNN_IPV6_TENID_NOEXIST_GRE       0x1a
121 #define QEDE_PKT_TYPE_TUNN_IPV6_TENID_NOEXIST_VXLAN     0x1b
122
123 #define QEDE_PKT_TYPE_TUNN_IPV6_TENID_EXIST_GENEVE      0x1d
124 #define QEDE_PKT_TYPE_TUNN_IPV6_TENID_EXIST_GRE         0x1e
125 #define QEDE_PKT_TYPE_TUNN_IPV6_TENID_EXIST_VXLAN       0x1f
126
127 #define QEDE_PKT_TYPE_TUNN_MAX_TYPE                     0x20 /* 2^5 */
128
129 #define QEDE_TX_CSUM_OFFLOAD_MASK (PKT_TX_IP_CKSUM              | \
130                                    PKT_TX_TCP_CKSUM             | \
131                                    PKT_TX_UDP_CKSUM             | \
132                                    PKT_TX_OUTER_IP_CKSUM        | \
133                                    PKT_TX_TCP_SEG)
134
135 #define QEDE_TX_OFFLOAD_MASK (QEDE_TX_CSUM_OFFLOAD_MASK | \
136                               PKT_TX_QINQ_PKT           | \
137                               PKT_TX_VLAN_PKT           | \
138                               PKT_TX_TUNNEL_VXLAN)
139
140 #define QEDE_TX_OFFLOAD_NOTSUP_MASK \
141         (PKT_TX_OFFLOAD_MASK ^ QEDE_TX_OFFLOAD_MASK)
142
143 /*
144  * RX BD descriptor ring
145  */
146 struct qede_rx_entry {
147         struct rte_mbuf *mbuf;
148         uint32_t page_offset;
149         /* allows expansion .. */
150 };
151
152 /* TPA related structures */
153 struct qede_agg_info {
154         struct rte_mbuf *tpa_head; /* Pointer to first TPA segment */
155         struct rte_mbuf *tpa_tail; /* Pointer to last TPA segment */
156 };
157
158 /*
159  * Structure associated with each RX queue.
160  */
161 struct qede_rx_queue {
162         struct rte_mempool *mb_pool;
163         struct ecore_chain rx_bd_ring;
164         struct ecore_chain rx_comp_ring;
165         uint16_t *hw_cons_ptr;
166         void OSAL_IOMEM *hw_rxq_prod_addr;
167         struct qede_rx_entry *sw_rx_ring;
168         uint16_t sw_rx_cons;
169         uint16_t sw_rx_prod;
170         uint16_t nb_rx_desc;
171         uint16_t queue_id;
172         uint16_t port_id;
173         uint16_t rx_buf_size;
174         uint64_t rcv_pkts;
175         uint64_t rx_segs;
176         uint64_t rx_hw_errors;
177         uint64_t rx_alloc_errors;
178         struct qede_agg_info tpa_info[ETH_TPA_MAX_AGGS_NUM];
179         struct qede_dev *qdev;
180         void *handle;
181 };
182
183 /*
184  * TX BD descriptor ring
185  */
186 struct qede_tx_entry {
187         struct rte_mbuf *mbuf;
188         uint8_t flags;
189 };
190
191 union db_prod {
192         struct eth_db_data data;
193         uint32_t raw;
194 };
195
196 struct qede_tx_queue {
197         struct ecore_chain tx_pbl;
198         struct qede_tx_entry *sw_tx_ring;
199         uint16_t nb_tx_desc;
200         uint16_t nb_tx_avail;
201         uint16_t tx_free_thresh;
202         uint16_t queue_id;
203         uint16_t *hw_cons_ptr;
204         uint16_t sw_tx_cons;
205         uint16_t sw_tx_prod;
206         void OSAL_IOMEM *doorbell_addr;
207         volatile union db_prod tx_db;
208         uint16_t port_id;
209         uint64_t xmit_pkts;
210         bool is_legacy;
211         struct qede_dev *qdev;
212         void *handle;
213 };
214
215 struct qede_fastpath {
216         struct qede_dev *qdev;
217         u8 type;
218         uint8_t id;
219         struct ecore_sb_info *sb_info;
220         struct qede_rx_queue *rxq;
221         struct qede_tx_queue *txqs[MAX_NUM_TC];
222         char name[80];
223 };
224
225 /*
226  * RX/TX function prototypes
227  */
228 int qede_rx_queue_setup(struct rte_eth_dev *dev, uint16_t queue_idx,
229                         uint16_t nb_desc, unsigned int socket_id,
230                         const struct rte_eth_rxconf *rx_conf,
231                         struct rte_mempool *mp);
232
233 int qede_tx_queue_setup(struct rte_eth_dev *dev,
234                         uint16_t queue_idx,
235                         uint16_t nb_desc,
236                         unsigned int socket_id,
237                         const struct rte_eth_txconf *tx_conf);
238
239 void qede_rx_queue_release(void *rx_queue);
240
241 void qede_tx_queue_release(void *tx_queue);
242
243 int qede_dev_start(struct rte_eth_dev *eth_dev);
244
245 void qede_dev_stop(struct rte_eth_dev *eth_dev);
246
247 int qede_reset_fp_rings(struct qede_dev *qdev);
248
249 void qede_free_fp_arrays(struct qede_dev *qdev);
250
251 void qede_free_mem_load(struct rte_eth_dev *eth_dev);
252
253 uint16_t qede_xmit_pkts(void *p_txq, struct rte_mbuf **tx_pkts,
254                         uint16_t nb_pkts);
255
256 uint16_t qede_xmit_prep_pkts(void *p_txq, struct rte_mbuf **tx_pkts,
257                              uint16_t nb_pkts);
258
259 uint16_t qede_recv_pkts(void *p_rxq, struct rte_mbuf **rx_pkts,
260                         uint16_t nb_pkts);
261
262 uint16_t qede_rxtx_pkts_dummy(__rte_unused void *p_rxq,
263                               __rte_unused struct rte_mbuf **pkts,
264                               __rte_unused uint16_t nb_pkts);
265
266 /* Fastpath resource alloc/dealloc helpers */
267 int qede_alloc_fp_resc(struct qede_dev *qdev);
268
269 void qede_dealloc_fp_resc(struct rte_eth_dev *eth_dev);
270
271 #endif /* _QEDE_RXTX_H_ */