net/qede: add fastpath support for VXLAN tunneling
[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                 /* FW 8.10.x specific change */  \
45                 (bd)->data.bitfields = ((len) & \
46                                          ETH_TX_DATA_1ST_BD_PKT_LEN_MASK) \
47                                         << ETH_TX_DATA_1ST_BD_PKT_LEN_SHIFT; \
48         } while (0)
49
50 #define CQE_HAS_VLAN(flags) \
51         ((flags) & (PARSING_AND_ERR_FLAGS_TAG8021QEXIST_MASK \
52                 << PARSING_AND_ERR_FLAGS_TAG8021QEXIST_SHIFT))
53
54 #define CQE_HAS_OUTER_VLAN(flags) \
55         ((flags) & (PARSING_AND_ERR_FLAGS_TUNNEL8021QTAGEXIST_MASK \
56                 << PARSING_AND_ERR_FLAGS_TUNNEL8021QTAGEXIST_SHIFT))
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
65 #define QEDE_ETH_OVERHEAD       (ETHER_HDR_LEN + 8 + 8 + QEDE_FW_RX_ALIGN_END)
66
67 /* TBD: Excluding IPV6 */
68 #define QEDE_RSS_OFFLOAD_ALL    (ETH_RSS_IPV4 | ETH_RSS_NONFRAG_IPV4_TCP | \
69                                  ETH_RSS_NONFRAG_IPV4_UDP | ETH_RSS_VXLAN)
70
71 #define QEDE_TXQ_FLAGS          ((uint32_t)ETH_TXQ_FLAGS_NOMULTSEGS)
72
73 #define MAX_NUM_TC              8
74
75 #define for_each_queue(i) for (i = 0; i < qdev->num_queues; i++)
76
77
78 /* Macros for non-tunnel packet types lkup table */
79 #define QEDE_PKT_TYPE_UNKNOWN                           0x0
80 #define QEDE_PKT_TYPE_MAX                               0xf
81 #define QEDE_PKT_TYPE_IPV4                              0x1
82 #define QEDE_PKT_TYPE_IPV6                              0x2
83 #define QEDE_PKT_TYPE_IPV4_TCP                          0x5
84 #define QEDE_PKT_TYPE_IPV6_TCP                          0x6
85 #define QEDE_PKT_TYPE_IPV4_UDP                          0x9
86 #define QEDE_PKT_TYPE_IPV6_UDP                          0xa
87
88 /* Macros for tunneled packets with next protocol lkup table */
89 #define QEDE_PKT_TYPE_TUNN_GENEVE                       0x1
90 #define QEDE_PKT_TYPE_TUNN_GRE                          0x2
91 #define QEDE_PKT_TYPE_TUNN_VXLAN                        0x3
92
93 /* Bit 2 is don't care bit */
94 #define QEDE_PKT_TYPE_TUNN_L2_TENID_NOEXIST_GENEVE      0x9
95 #define QEDE_PKT_TYPE_TUNN_L2_TENID_NOEXIST_GRE 0xa
96 #define QEDE_PKT_TYPE_TUNN_L2_TENID_NOEXIST_VXLAN       0xb
97
98 #define QEDE_PKT_TYPE_TUNN_L2_TENID_EXIST_GENEVE        0xd
99 #define QEDE_PKT_TYPE_TUNN_L2_TENID_EXIST_GRE           0xe
100 #define QEDE_PKT_TYPE_TUNN_L2_TENID_EXIST_VXLAN 0xf
101
102
103 #define QEDE_PKT_TYPE_TUNN_IPV4_TENID_NOEXIST_GENEVE    0x11
104 #define QEDE_PKT_TYPE_TUNN_IPV4_TENID_NOEXIST_GRE       0x12
105 #define QEDE_PKT_TYPE_TUNN_IPV4_TENID_NOEXIST_VXLAN     0x13
106
107 #define QEDE_PKT_TYPE_TUNN_IPV4_TENID_EXIST_GENEVE      0x15
108 #define QEDE_PKT_TYPE_TUNN_IPV4_TENID_EXIST_GRE 0x16
109 #define QEDE_PKT_TYPE_TUNN_IPV4_TENID_EXIST_VXLAN       0x17
110
111
112 #define QEDE_PKT_TYPE_TUNN_IPV6_TENID_NOEXIST_GENEVE    0x19
113 #define QEDE_PKT_TYPE_TUNN_IPV6_TENID_NOEXIST_GRE       0x1a
114 #define QEDE_PKT_TYPE_TUNN_IPV6_TENID_NOEXIST_VXLAN     0x1b
115
116 #define QEDE_PKT_TYPE_TUNN_IPV6_TENID_EXIST_GENEVE      0x1d
117 #define QEDE_PKT_TYPE_TUNN_IPV6_TENID_EXIST_GRE         0x1e
118 #define QEDE_PKT_TYPE_TUNN_IPV6_TENID_EXIST_VXLAN       0x1f
119
120 #define QEDE_PKT_TYPE_TUNN_MAX_TYPE                     0x20 /* 2^5 */
121
122 /*
123  * RX BD descriptor ring
124  */
125 struct qede_rx_entry {
126         struct rte_mbuf *mbuf;
127         uint32_t page_offset;
128         /* allows expansion .. */
129 };
130
131 /*
132  * Structure associated with each RX queue.
133  */
134 struct qede_rx_queue {
135         struct rte_mempool *mb_pool;
136         struct ecore_chain rx_bd_ring;
137         struct ecore_chain rx_comp_ring;
138         uint16_t *hw_cons_ptr;
139         void OSAL_IOMEM *hw_rxq_prod_addr;
140         struct qede_rx_entry *sw_rx_ring;
141         uint16_t sw_rx_cons;
142         uint16_t sw_rx_prod;
143         uint16_t nb_rx_desc;
144         uint16_t queue_id;
145         uint16_t port_id;
146         uint16_t rx_buf_size;
147         uint64_t rcv_pkts;
148         uint64_t rx_segs;
149         uint64_t rx_hw_errors;
150         uint64_t rx_alloc_errors;
151         struct qede_dev *qdev;
152 };
153
154 /*
155  * TX BD descriptor ring
156  */
157 struct qede_tx_entry {
158         struct rte_mbuf *mbuf;
159         uint8_t flags;
160 };
161
162 union db_prod {
163         struct eth_db_data data;
164         uint32_t raw;
165 };
166
167 struct qede_tx_queue {
168         struct ecore_chain tx_pbl;
169         struct qede_tx_entry *sw_tx_ring;
170         uint16_t nb_tx_desc;
171         uint16_t nb_tx_avail;
172         uint16_t tx_free_thresh;
173         uint16_t queue_id;
174         uint16_t *hw_cons_ptr;
175         uint16_t sw_tx_cons;
176         uint16_t sw_tx_prod;
177         void OSAL_IOMEM *doorbell_addr;
178         volatile union db_prod tx_db;
179         uint16_t port_id;
180         uint64_t xmit_pkts;
181         bool is_legacy;
182         struct qede_dev *qdev;
183 };
184
185 struct qede_fastpath {
186         struct qede_dev *qdev;
187         u8 type;
188         uint8_t id;
189         struct ecore_sb_info *sb_info;
190         struct qede_rx_queue *rxq;
191         struct qede_tx_queue *txqs[MAX_NUM_TC];
192         char name[80];
193 };
194
195 /*
196  * RX/TX function prototypes
197  */
198 int qede_rx_queue_setup(struct rte_eth_dev *dev, uint16_t queue_idx,
199                         uint16_t nb_desc, unsigned int socket_id,
200                         const struct rte_eth_rxconf *rx_conf,
201                         struct rte_mempool *mp);
202
203 int qede_tx_queue_setup(struct rte_eth_dev *dev,
204                         uint16_t queue_idx,
205                         uint16_t nb_desc,
206                         unsigned int socket_id,
207                         const struct rte_eth_txconf *tx_conf);
208
209 void qede_rx_queue_release(void *rx_queue);
210
211 void qede_tx_queue_release(void *tx_queue);
212
213 int qede_dev_start(struct rte_eth_dev *eth_dev);
214
215 void qede_dev_stop(struct rte_eth_dev *eth_dev);
216
217 int qede_reset_fp_rings(struct qede_dev *qdev);
218
219 void qede_free_fp_arrays(struct qede_dev *qdev);
220
221 void qede_free_mem_load(struct rte_eth_dev *eth_dev);
222
223 uint16_t qede_xmit_pkts(void *p_txq, struct rte_mbuf **tx_pkts,
224                         uint16_t nb_pkts);
225
226 uint16_t qede_recv_pkts(void *p_rxq, struct rte_mbuf **rx_pkts,
227                         uint16_t nb_pkts);
228
229 /* Fastpath resource alloc/dealloc helpers */
230 int qede_alloc_fp_resc(struct qede_dev *qdev);
231
232 void qede_dealloc_fp_resc(struct rte_eth_dev *eth_dev);
233
234 #endif /* _QEDE_RXTX_H_ */