Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2010-2016 Intel Corporation
3 : : */
4 : :
5 : : #include <sys/queue.h>
6 : :
7 : : #include <stdio.h>
8 : : #include <stdlib.h>
9 : : #include <string.h>
10 : : #include <errno.h>
11 : : #include <stdint.h>
12 : : #include <stdarg.h>
13 : : #include <inttypes.h>
14 : :
15 : : #include <rte_interrupts.h>
16 : : #include <rte_byteorder.h>
17 : : #include <rte_common.h>
18 : : #include <rte_log.h>
19 : : #include <rte_debug.h>
20 : : #include <rte_pci.h>
21 : : #include <rte_memory.h>
22 : : #include <rte_memzone.h>
23 : : #include <rte_launch.h>
24 : : #include <rte_eal.h>
25 : : #include <rte_per_lcore.h>
26 : : #include <rte_lcore.h>
27 : : #include <rte_atomic.h>
28 : : #include <rte_branch_prediction.h>
29 : : #include <rte_mempool.h>
30 : : #include <rte_malloc.h>
31 : : #include <rte_mbuf.h>
32 : : #include <rte_ether.h>
33 : : #include <ethdev_driver.h>
34 : : #include <rte_prefetch.h>
35 : : #include <rte_udp.h>
36 : : #include <rte_tcp.h>
37 : : #include <rte_sctp.h>
38 : : #include <rte_net.h>
39 : : #include <rte_string_fns.h>
40 : :
41 : : #include "e1000_logs.h"
42 : : #include "base/e1000_api.h"
43 : : #include "e1000_ethdev.h"
44 : :
45 : : #ifdef RTE_LIBRTE_IEEE1588
46 : : #define IGB_TX_IEEE1588_TMST RTE_MBUF_F_TX_IEEE1588_TMST
47 : : #else
48 : : #define IGB_TX_IEEE1588_TMST 0
49 : : #endif
50 : : /* Bit Mask to indicate what bits required for building TX context */
51 : : #define IGB_TX_OFFLOAD_MASK (RTE_MBUF_F_TX_OUTER_IPV6 | \
52 : : RTE_MBUF_F_TX_OUTER_IPV4 | \
53 : : RTE_MBUF_F_TX_IPV6 | \
54 : : RTE_MBUF_F_TX_IPV4 | \
55 : : RTE_MBUF_F_TX_VLAN | \
56 : : RTE_MBUF_F_TX_IP_CKSUM | \
57 : : RTE_MBUF_F_TX_L4_MASK | \
58 : : RTE_MBUF_F_TX_TCP_SEG | \
59 : : IGB_TX_IEEE1588_TMST)
60 : :
61 : : #define IGB_TX_OFFLOAD_NOTSUP_MASK \
62 : : (RTE_MBUF_F_TX_OFFLOAD_MASK ^ IGB_TX_OFFLOAD_MASK)
63 : :
64 : : /**
65 : : * Structure associated with each descriptor of the RX ring of a RX queue.
66 : : */
67 : : struct igb_rx_entry {
68 : : struct rte_mbuf *mbuf; /**< mbuf associated with RX descriptor. */
69 : : };
70 : :
71 : : /**
72 : : * Structure associated with each descriptor of the TX ring of a TX queue.
73 : : */
74 : : struct igb_tx_entry {
75 : : struct rte_mbuf *mbuf; /**< mbuf associated with TX desc, if any. */
76 : : uint16_t next_id; /**< Index of next descriptor in ring. */
77 : : uint16_t last_id; /**< Index of last scattered descriptor. */
78 : : };
79 : :
80 : : /**
81 : : * rx queue flags
82 : : */
83 : : enum igb_rxq_flags {
84 : : IGB_RXQ_FLAG_LB_BSWAP_VLAN = 0x01,
85 : : };
86 : :
87 : : /**
88 : : * Structure associated with each RX queue.
89 : : */
90 : : struct igb_rx_queue {
91 : : struct rte_mempool *mb_pool; /**< mbuf pool to populate RX ring. */
92 : : volatile union e1000_adv_rx_desc *rx_ring; /**< RX ring virtual address. */
93 : : uint64_t rx_ring_phys_addr; /**< RX ring DMA address. */
94 : : volatile uint32_t *rdt_reg_addr; /**< RDT register address. */
95 : : volatile uint32_t *rdh_reg_addr; /**< RDH register address. */
96 : : struct igb_rx_entry *sw_ring; /**< address of RX software ring. */
97 : : struct rte_mbuf *pkt_first_seg; /**< First segment of current packet. */
98 : : struct rte_mbuf *pkt_last_seg; /**< Last segment of current packet. */
99 : : uint16_t nb_rx_desc; /**< number of RX descriptors. */
100 : : uint16_t rx_tail; /**< current value of RDT register. */
101 : : uint16_t nb_rx_hold; /**< number of held free RX desc. */
102 : : uint16_t rx_free_thresh; /**< max free RX desc to hold. */
103 : : uint16_t queue_id; /**< RX queue index. */
104 : : uint16_t reg_idx; /**< RX queue register index. */
105 : : uint16_t port_id; /**< Device port identifier. */
106 : : uint8_t pthresh; /**< Prefetch threshold register. */
107 : : uint8_t hthresh; /**< Host threshold register. */
108 : : uint8_t wthresh; /**< Write-back threshold register. */
109 : : uint8_t crc_len; /**< 0 if CRC stripped, 4 otherwise. */
110 : : uint8_t drop_en; /**< If not 0, set SRRCTL.Drop_En. */
111 : : uint32_t flags; /**< RX flags. */
112 : : uint64_t offloads; /**< offloads of RTE_ETH_RX_OFFLOAD_* */
113 : : const struct rte_memzone *mz;
114 : : };
115 : :
116 : : /**
117 : : * Hardware context number
118 : : */
119 : : enum igb_advctx_num {
120 : : IGB_CTX_0 = 0, /**< CTX0 */
121 : : IGB_CTX_1 = 1, /**< CTX1 */
122 : : IGB_CTX_NUM = 2, /**< CTX_NUM */
123 : : };
124 : :
125 : : /** Offload features */
126 : : union igb_tx_offload {
127 : : uint64_t data;
128 : : struct {
129 : : uint64_t l3_len:9; /**< L3 (IP) Header Length. */
130 : : uint64_t l2_len:7; /**< L2 (MAC) Header Length. */
131 : : uint64_t vlan_tci:16; /**< VLAN Tag Control Identifier(CPU order). */
132 : : uint64_t l4_len:8; /**< L4 (TCP/UDP) Header Length. */
133 : : uint64_t tso_segsz:16; /**< TCP TSO segment size. */
134 : :
135 : : /* uint64_t unused:8; */
136 : : };
137 : : };
138 : :
139 : : /*
140 : : * Compare mask for igb_tx_offload.data,
141 : : * should be in sync with igb_tx_offload layout.
142 : : * */
143 : : #define TX_MACIP_LEN_CMP_MASK 0x000000000000FFFFULL /**< L2L3 header mask. */
144 : : #define TX_VLAN_CMP_MASK 0x00000000FFFF0000ULL /**< Vlan mask. */
145 : : #define TX_TCP_LEN_CMP_MASK 0x000000FF00000000ULL /**< TCP header mask. */
146 : : #define TX_TSO_MSS_CMP_MASK 0x00FFFF0000000000ULL /**< TSO segsz mask. */
147 : : /** Mac + IP + TCP + Mss mask. */
148 : : #define TX_TSO_CMP_MASK \
149 : : (TX_MACIP_LEN_CMP_MASK | TX_TCP_LEN_CMP_MASK | TX_TSO_MSS_CMP_MASK)
150 : :
151 : : /**
152 : : * Structure to check if new context need be built
153 : : */
154 : : struct igb_advctx_info {
155 : : uint64_t flags; /**< ol_flags related to context build. */
156 : : /** tx offload: vlan, tso, l2-l3-l4 lengths. */
157 : : union igb_tx_offload tx_offload;
158 : : /** compare mask for tx offload. */
159 : : union igb_tx_offload tx_offload_mask;
160 : : };
161 : :
162 : : /**
163 : : * Structure associated with each TX queue.
164 : : */
165 : : struct igb_tx_queue {
166 : : volatile union e1000_adv_tx_desc *tx_ring; /**< TX ring address */
167 : : uint64_t tx_ring_phys_addr; /**< TX ring DMA address. */
168 : : struct igb_tx_entry *sw_ring; /**< virtual address of SW ring. */
169 : : volatile uint32_t *tdt_reg_addr; /**< Address of TDT register. */
170 : : uint32_t txd_type; /**< Device-specific TXD type */
171 : : uint16_t nb_tx_desc; /**< number of TX descriptors. */
172 : : uint16_t tx_tail; /**< Current value of TDT register. */
173 : : uint16_t tx_head;
174 : : /**< Index of first used TX descriptor. */
175 : : uint16_t queue_id; /**< TX queue index. */
176 : : uint16_t reg_idx; /**< TX queue register index. */
177 : : uint16_t port_id; /**< Device port identifier. */
178 : : uint8_t pthresh; /**< Prefetch threshold register. */
179 : : uint8_t hthresh; /**< Host threshold register. */
180 : : uint8_t wthresh; /**< Write-back threshold register. */
181 : : uint32_t ctx_curr;
182 : : /**< Current used hardware descriptor. */
183 : : uint32_t ctx_start;
184 : : /**< Start context position for transmit queue. */
185 : : struct igb_advctx_info ctx_cache[IGB_CTX_NUM];
186 : : /**< Hardware context history.*/
187 : : uint64_t offloads; /**< offloads of RTE_ETH_TX_OFFLOAD_* */
188 : : const struct rte_memzone *mz;
189 : : };
190 : :
191 : : #if 1
192 : : #define RTE_PMD_USE_PREFETCH
193 : : #endif
194 : :
195 : : #ifdef RTE_PMD_USE_PREFETCH
196 : : #define rte_igb_prefetch(p) rte_prefetch0(p)
197 : : #else
198 : : #define rte_igb_prefetch(p) do {} while(0)
199 : : #endif
200 : :
201 : : #ifdef RTE_PMD_PACKET_PREFETCH
202 : : #define rte_packet_prefetch(p) rte_prefetch1(p)
203 : : #else
204 : : #define rte_packet_prefetch(p) do {} while(0)
205 : : #endif
206 : :
207 : : /*
208 : : * Macro for VMDq feature for 1 GbE NIC.
209 : : */
210 : : #define E1000_VMOLR_SIZE (8)
211 : : #define IGB_TSO_MAX_HDRLEN (512)
212 : : #define IGB_TSO_MAX_MSS (9216)
213 : :
214 : : /*********************************************************************
215 : : *
216 : : * TX function
217 : : *
218 : : **********************************************************************/
219 : :
220 : : /*
221 : : *There're some limitations in hardware for TCP segmentation offload. We
222 : : *should check whether the parameters are valid.
223 : : */
224 : : static inline uint64_t
225 : : check_tso_para(uint64_t ol_req, union igb_tx_offload ol_para)
226 : : {
227 : 0 : if (!(ol_req & RTE_MBUF_F_TX_TCP_SEG))
228 : : return ol_req;
229 [ # # ]: 0 : if ((ol_para.tso_segsz > IGB_TSO_MAX_MSS) || (ol_para.l2_len +
230 [ # # ]: 0 : ol_para.l3_len + ol_para.l4_len > IGB_TSO_MAX_HDRLEN)) {
231 : 0 : ol_req &= ~RTE_MBUF_F_TX_TCP_SEG;
232 : 0 : ol_req |= RTE_MBUF_F_TX_TCP_CKSUM;
233 : : }
234 : : return ol_req;
235 : : }
236 : :
237 : : /*
238 : : * Advanced context descriptor are almost same between igb/ixgbe
239 : : * This is a separate function, looking for optimization opportunity here
240 : : * Rework required to go with the pre-defined values.
241 : : */
242 : :
243 : : static inline void
244 : 0 : igbe_set_xmit_ctx(struct igb_tx_queue* txq,
245 : : volatile struct e1000_adv_tx_context_desc *ctx_txd,
246 : : uint64_t ol_flags, union igb_tx_offload tx_offload, uint64_t txtime)
247 : : {
248 : : uint32_t type_tucmd_mlhl;
249 : : uint32_t mss_l4len_idx;
250 : : uint32_t ctx_idx, ctx_curr;
251 : : uint32_t vlan_macip_lens;
252 : : uint32_t launch_time;
253 : : union igb_tx_offload tx_offload_mask;
254 : :
255 : 0 : ctx_curr = txq->ctx_curr;
256 : 0 : ctx_idx = ctx_curr + txq->ctx_start;
257 : :
258 : : tx_offload_mask.data = 0;
259 : : type_tucmd_mlhl = 0;
260 : :
261 : : /* Specify which HW CTX to upload. */
262 : 0 : mss_l4len_idx = (ctx_idx << E1000_ADVTXD_IDX_SHIFT);
263 : :
264 [ # # ]: 0 : if (ol_flags & RTE_MBUF_F_TX_VLAN)
265 : : tx_offload_mask.data |= TX_VLAN_CMP_MASK;
266 : :
267 : : /* check if TCP segmentation required for this packet */
268 [ # # ]: 0 : if (ol_flags & RTE_MBUF_F_TX_TCP_SEG) {
269 : : /* implies IP cksum in IPv4 */
270 [ # # ]: 0 : if (ol_flags & RTE_MBUF_F_TX_IP_CKSUM)
271 : : type_tucmd_mlhl = E1000_ADVTXD_TUCMD_IPV4 |
272 : : E1000_ADVTXD_TUCMD_L4T_TCP |
273 : : E1000_ADVTXD_DTYP_CTXT | E1000_ADVTXD_DCMD_DEXT;
274 : : else
275 : : type_tucmd_mlhl = E1000_ADVTXD_TUCMD_IPV6 |
276 : : E1000_ADVTXD_TUCMD_L4T_TCP |
277 : : E1000_ADVTXD_DTYP_CTXT | E1000_ADVTXD_DCMD_DEXT;
278 : :
279 : 0 : tx_offload_mask.data |= TX_TSO_CMP_MASK;
280 : 0 : mss_l4len_idx |= tx_offload.tso_segsz << E1000_ADVTXD_MSS_SHIFT;
281 : 0 : mss_l4len_idx |= tx_offload.l4_len << E1000_ADVTXD_L4LEN_SHIFT;
282 : : } else { /* no TSO, check if hardware checksum is needed */
283 [ # # ]: 0 : if (ol_flags & (RTE_MBUF_F_TX_IP_CKSUM | RTE_MBUF_F_TX_L4_MASK))
284 : 0 : tx_offload_mask.data |= TX_MACIP_LEN_CMP_MASK;
285 : :
286 [ # # ]: 0 : if (ol_flags & RTE_MBUF_F_TX_IP_CKSUM)
287 : : type_tucmd_mlhl = E1000_ADVTXD_TUCMD_IPV4;
288 : :
289 [ # # # # ]: 0 : switch (ol_flags & RTE_MBUF_F_TX_L4_MASK) {
290 : 0 : case RTE_MBUF_F_TX_UDP_CKSUM:
291 : 0 : type_tucmd_mlhl |= E1000_ADVTXD_TUCMD_L4T_UDP |
292 : : E1000_ADVTXD_DTYP_CTXT | E1000_ADVTXD_DCMD_DEXT;
293 : 0 : mss_l4len_idx |= sizeof(struct rte_udp_hdr)
294 : : << E1000_ADVTXD_L4LEN_SHIFT;
295 : 0 : break;
296 : 0 : case RTE_MBUF_F_TX_TCP_CKSUM:
297 : 0 : type_tucmd_mlhl |= E1000_ADVTXD_TUCMD_L4T_TCP |
298 : : E1000_ADVTXD_DTYP_CTXT | E1000_ADVTXD_DCMD_DEXT;
299 : 0 : mss_l4len_idx |= sizeof(struct rte_tcp_hdr)
300 : : << E1000_ADVTXD_L4LEN_SHIFT;
301 : 0 : break;
302 : 0 : case RTE_MBUF_F_TX_SCTP_CKSUM:
303 : 0 : type_tucmd_mlhl |= E1000_ADVTXD_TUCMD_L4T_SCTP |
304 : : E1000_ADVTXD_DTYP_CTXT | E1000_ADVTXD_DCMD_DEXT;
305 : 0 : mss_l4len_idx |= sizeof(struct rte_sctp_hdr)
306 : : << E1000_ADVTXD_L4LEN_SHIFT;
307 : 0 : break;
308 : 0 : default:
309 : 0 : type_tucmd_mlhl |= E1000_ADVTXD_TUCMD_L4T_RSV |
310 : : E1000_ADVTXD_DTYP_CTXT | E1000_ADVTXD_DCMD_DEXT;
311 : 0 : break;
312 : : }
313 : : }
314 : :
315 [ # # ]: 0 : if (!txtime) {
316 : 0 : txq->ctx_cache[ctx_curr].flags = ol_flags;
317 : 0 : txq->ctx_cache[ctx_curr].tx_offload.data =
318 : 0 : tx_offload_mask.data & tx_offload.data;
319 : 0 : txq->ctx_cache[ctx_curr].tx_offload_mask = tx_offload_mask;
320 : : }
321 : :
322 : 0 : ctx_txd->type_tucmd_mlhl = rte_cpu_to_le_32(type_tucmd_mlhl);
323 : 0 : vlan_macip_lens = (uint32_t)tx_offload.data;
324 : 0 : ctx_txd->vlan_macip_lens = rte_cpu_to_le_32(vlan_macip_lens);
325 : 0 : ctx_txd->mss_l4len_idx = rte_cpu_to_le_32(mss_l4len_idx);
326 : 0 : ctx_txd->u.seqnum_seed = 0;
327 : :
328 [ # # ]: 0 : if (txtime) {
329 : 0 : launch_time = (txtime - IGB_I210_TX_OFFSET_BASE) % NSEC_PER_SEC;
330 : 0 : ctx_txd->u.launch_time = rte_cpu_to_le_32(launch_time / 32);
331 : : } else {
332 : 0 : ctx_txd->u.launch_time = 0;
333 : : }
334 : 0 : }
335 : :
336 : : /*
337 : : * Check which hardware context can be used. Use the existing match
338 : : * or create a new context descriptor.
339 : : */
340 : : static inline uint32_t
341 : 0 : what_advctx_update(struct igb_tx_queue *txq, uint64_t flags,
342 : : union igb_tx_offload tx_offload)
343 : : {
344 : : /* If match with the current context */
345 [ # # # # ]: 0 : if (likely((txq->ctx_cache[txq->ctx_curr].flags == flags) &&
346 : : (txq->ctx_cache[txq->ctx_curr].tx_offload.data ==
347 : : (txq->ctx_cache[txq->ctx_curr].tx_offload_mask.data & tx_offload.data)))) {
348 : : return txq->ctx_curr;
349 : : }
350 : :
351 : : /* If match with the second context */
352 : 0 : txq->ctx_curr ^= 1;
353 [ # # # # ]: 0 : if (likely((txq->ctx_cache[txq->ctx_curr].flags == flags) &&
354 : : (txq->ctx_cache[txq->ctx_curr].tx_offload.data ==
355 : : (txq->ctx_cache[txq->ctx_curr].tx_offload_mask.data & tx_offload.data)))) {
356 : 0 : return txq->ctx_curr;
357 : : }
358 : :
359 : : /* Mismatch, use the previous context */
360 : : return IGB_CTX_NUM;
361 : : }
362 : :
363 : : static inline uint32_t
364 : : tx_desc_cksum_flags_to_olinfo(uint64_t ol_flags)
365 : : {
366 : : static const uint32_t l4_olinfo[2] = {0, E1000_ADVTXD_POPTS_TXSM};
367 : : static const uint32_t l3_olinfo[2] = {0, E1000_ADVTXD_POPTS_IXSM};
368 : : uint32_t tmp;
369 : :
370 : 0 : tmp = l4_olinfo[(ol_flags & RTE_MBUF_F_TX_L4_MASK) != RTE_MBUF_F_TX_L4_NO_CKSUM];
371 : 0 : tmp |= l3_olinfo[(ol_flags & RTE_MBUF_F_TX_IP_CKSUM) != 0];
372 : 0 : tmp |= l4_olinfo[(ol_flags & RTE_MBUF_F_TX_TCP_SEG) != 0];
373 : : return tmp;
374 : : }
375 : :
376 : : static inline uint32_t
377 : : tx_desc_vlan_flags_to_cmdtype(uint64_t ol_flags)
378 : : {
379 : : uint32_t cmdtype;
380 : : static uint32_t vlan_cmd[2] = {0, E1000_ADVTXD_DCMD_VLE};
381 : : static uint32_t tso_cmd[2] = {0, E1000_ADVTXD_DCMD_TSE};
382 : 0 : cmdtype = vlan_cmd[(ol_flags & RTE_MBUF_F_TX_VLAN) != 0];
383 : 0 : cmdtype |= tso_cmd[(ol_flags & RTE_MBUF_F_TX_TCP_SEG) != 0];
384 : : return cmdtype;
385 : : }
386 : :
387 : : uint16_t
388 : 0 : eth_igb_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
389 : : uint16_t nb_pkts)
390 : : {
391 : : struct igb_tx_queue *txq;
392 : : struct igb_tx_entry *sw_ring;
393 : : struct igb_tx_entry *txe, *txn;
394 : : volatile union e1000_adv_tx_desc *txr;
395 : : volatile union e1000_adv_tx_desc *txd;
396 : : struct rte_mbuf *tx_pkt;
397 : : struct rte_mbuf *m_seg;
398 : : uint64_t buf_dma_addr;
399 : : uint32_t olinfo_status;
400 : : uint32_t cmd_type_len;
401 : : uint32_t pkt_len;
402 : : uint16_t slen;
403 : : uint64_t ol_flags;
404 : : uint16_t tx_end;
405 : : uint16_t tx_id;
406 : : uint16_t tx_last;
407 : : uint16_t nb_tx;
408 : : uint64_t tx_ol_req;
409 : : uint32_t new_ctx = 0;
410 : : uint32_t ctx = 0;
411 : 0 : union igb_tx_offload tx_offload = {0};
412 : : uint64_t ts;
413 : :
414 : : txq = tx_queue;
415 : 0 : sw_ring = txq->sw_ring;
416 : 0 : txr = txq->tx_ring;
417 : 0 : tx_id = txq->tx_tail;
418 : 0 : txe = &sw_ring[tx_id];
419 : :
420 [ # # ]: 0 : for (nb_tx = 0; nb_tx < nb_pkts; nb_tx++) {
421 : 0 : tx_pkt = *tx_pkts++;
422 : 0 : pkt_len = tx_pkt->pkt_len;
423 : :
424 [ # # ]: 0 : RTE_MBUF_PREFETCH_TO_FREE(txe->mbuf);
425 : :
426 : : /*
427 : : * The number of descriptors that must be allocated for a
428 : : * packet is the number of segments of that packet, plus 1
429 : : * Context Descriptor for the VLAN Tag Identifier, if any.
430 : : * Determine the last TX descriptor to allocate in the TX ring
431 : : * for the packet, starting from the current position (tx_id)
432 : : * in the ring.
433 : : */
434 : 0 : tx_last = (uint16_t) (tx_id + tx_pkt->nb_segs - 1);
435 : :
436 : 0 : ol_flags = tx_pkt->ol_flags;
437 : 0 : tx_ol_req = ol_flags & IGB_TX_OFFLOAD_MASK;
438 : :
439 : : /* If a Context Descriptor need be built . */
440 [ # # ]: 0 : if (tx_ol_req) {
441 : 0 : tx_offload.l2_len = tx_pkt->l2_len;
442 : 0 : tx_offload.l3_len = tx_pkt->l3_len;
443 : 0 : tx_offload.l4_len = tx_pkt->l4_len;
444 : 0 : tx_offload.vlan_tci = tx_pkt->vlan_tci;
445 [ # # ]: 0 : tx_offload.tso_segsz = tx_pkt->tso_segsz;
446 : : tx_ol_req = check_tso_para(tx_ol_req, tx_offload);
447 : :
448 : 0 : ctx = what_advctx_update(txq, tx_ol_req, tx_offload);
449 : : /* Only allocate context descriptor if required*/
450 : 0 : new_ctx = (ctx == IGB_CTX_NUM);
451 : 0 : ctx = txq->ctx_curr + txq->ctx_start;
452 : 0 : tx_last = (uint16_t) (tx_last + new_ctx);
453 : : }
454 [ # # ]: 0 : if (tx_last >= txq->nb_tx_desc)
455 : 0 : tx_last = (uint16_t) (tx_last - txq->nb_tx_desc);
456 : :
457 : : PMD_TX_LOG(DEBUG, "port_id=%u queue_id=%u pktlen=%u"
458 : : " tx_first=%u tx_last=%u",
459 : : (unsigned) txq->port_id,
460 : : (unsigned) txq->queue_id,
461 : : (unsigned) pkt_len,
462 : : (unsigned) tx_id,
463 : : (unsigned) tx_last);
464 : :
465 : : /*
466 : : * Check if there are enough free descriptors in the TX ring
467 : : * to transmit the next packet.
468 : : * This operation is based on the two following rules:
469 : : *
470 : : * 1- Only check that the last needed TX descriptor can be
471 : : * allocated (by construction, if that descriptor is free,
472 : : * all intermediate ones are also free).
473 : : *
474 : : * For this purpose, the index of the last TX descriptor
475 : : * used for a packet (the "last descriptor" of a packet)
476 : : * is recorded in the TX entries (the last one included)
477 : : * that are associated with all TX descriptors allocated
478 : : * for that packet.
479 : : *
480 : : * 2- Avoid to allocate the last free TX descriptor of the
481 : : * ring, in order to never set the TDT register with the
482 : : * same value stored in parallel by the NIC in the TDH
483 : : * register, which makes the TX engine of the NIC enter
484 : : * in a deadlock situation.
485 : : *
486 : : * By extension, avoid to allocate a free descriptor that
487 : : * belongs to the last set of free descriptors allocated
488 : : * to the same packet previously transmitted.
489 : : */
490 : :
491 : : /*
492 : : * The "last descriptor" of the previously sent packet, if any,
493 : : * which used the last descriptor to allocate.
494 : : */
495 : 0 : tx_end = sw_ring[tx_last].last_id;
496 : :
497 : : /*
498 : : * The next descriptor following that "last descriptor" in the
499 : : * ring.
500 : : */
501 : 0 : tx_end = sw_ring[tx_end].next_id;
502 : :
503 : : /*
504 : : * The "last descriptor" associated with that next descriptor.
505 : : */
506 : 0 : tx_end = sw_ring[tx_end].last_id;
507 : :
508 : : /*
509 : : * Check that this descriptor is free.
510 : : */
511 [ # # ]: 0 : if (! (txr[tx_end].wb.status & E1000_TXD_STAT_DD)) {
512 [ # # ]: 0 : if (nb_tx == 0)
513 : : return 0;
514 : 0 : goto end_of_tx;
515 : : }
516 : :
517 : : /*
518 : : * Set common flags of all TX Data Descriptors.
519 : : *
520 : : * The following bits must be set in all Data Descriptors:
521 : : * - E1000_ADVTXD_DTYP_DATA
522 : : * - E1000_ADVTXD_DCMD_DEXT
523 : : *
524 : : * The following bits must be set in the first Data Descriptor
525 : : * and are ignored in the other ones:
526 : : * - E1000_ADVTXD_DCMD_IFCS
527 : : * - E1000_ADVTXD_MAC_1588
528 : : * - E1000_ADVTXD_DCMD_VLE
529 : : *
530 : : * The following bits must only be set in the last Data
531 : : * Descriptor:
532 : : * - E1000_TXD_CMD_EOP
533 : : *
534 : : * The following bits can be set in any Data Descriptor, but
535 : : * are only set in the last Data Descriptor:
536 : : * - E1000_TXD_CMD_RS
537 : : */
538 : 0 : cmd_type_len = txq->txd_type |
539 : : E1000_ADVTXD_DCMD_IFCS | E1000_ADVTXD_DCMD_DEXT;
540 [ # # ]: 0 : if (tx_ol_req & RTE_MBUF_F_TX_TCP_SEG)
541 : 0 : pkt_len -= (tx_pkt->l2_len + tx_pkt->l3_len + tx_pkt->l4_len);
542 : 0 : olinfo_status = (pkt_len << E1000_ADVTXD_PAYLEN_SHIFT);
543 : : #if defined(RTE_LIBRTE_IEEE1588)
544 : : if (ol_flags & RTE_MBUF_F_TX_IEEE1588_TMST)
545 : : cmd_type_len |= E1000_ADVTXD_MAC_TSTAMP;
546 : : #endif
547 [ # # ]: 0 : if (tx_ol_req) {
548 : : /* Setup TX Advanced context descriptor if required */
549 [ # # ]: 0 : if (new_ctx) {
550 : : volatile struct e1000_adv_tx_context_desc *
551 : : ctx_txd;
552 : :
553 : 0 : ctx_txd = (volatile struct
554 : : e1000_adv_tx_context_desc *)
555 : 0 : &txr[tx_id];
556 : :
557 : 0 : txn = &sw_ring[txe->next_id];
558 [ # # ]: 0 : RTE_MBUF_PREFETCH_TO_FREE(txn->mbuf);
559 : :
560 [ # # ]: 0 : if (txe->mbuf != NULL) {
561 : : rte_pktmbuf_free_seg(txe->mbuf);
562 : 0 : txe->mbuf = NULL;
563 : : }
564 : :
565 [ # # ]: 0 : if (igb_tx_timestamp_dynflag > 0) {
566 : 0 : ts = *RTE_MBUF_DYNFIELD(tx_pkt,
567 : : igb_tx_timestamp_dynfield_offset, uint64_t *);
568 : 0 : igbe_set_xmit_ctx(txq, ctx_txd, tx_ol_req, tx_offload, ts);
569 : : } else {
570 : 0 : igbe_set_xmit_ctx(txq, ctx_txd, tx_ol_req, tx_offload, 0);
571 : : }
572 : :
573 : 0 : txe->last_id = tx_last;
574 : 0 : tx_id = txe->next_id;
575 : : txe = txn;
576 : : }
577 : :
578 : : /* Setup the TX Advanced Data Descriptor */
579 : 0 : cmd_type_len |= tx_desc_vlan_flags_to_cmdtype(tx_ol_req);
580 : 0 : olinfo_status |= tx_desc_cksum_flags_to_olinfo(tx_ol_req);
581 : 0 : olinfo_status |= (ctx << E1000_ADVTXD_IDX_SHIFT);
582 : : }
583 : :
584 : : m_seg = tx_pkt;
585 : : do {
586 : 0 : txn = &sw_ring[txe->next_id];
587 : 0 : txd = &txr[tx_id];
588 : :
589 [ # # ]: 0 : if (txe->mbuf != NULL)
590 : : rte_pktmbuf_free_seg(txe->mbuf);
591 : 0 : txe->mbuf = m_seg;
592 : :
593 : : /*
594 : : * Set up transmit descriptor.
595 : : */
596 [ # # ]: 0 : slen = (uint16_t) m_seg->data_len;
597 : : buf_dma_addr = rte_mbuf_data_iova(m_seg);
598 : 0 : txd->read.buffer_addr =
599 : : rte_cpu_to_le_64(buf_dma_addr);
600 : 0 : txd->read.cmd_type_len =
601 : 0 : rte_cpu_to_le_32(cmd_type_len | slen);
602 : 0 : txd->read.olinfo_status =
603 : : rte_cpu_to_le_32(olinfo_status);
604 : 0 : txe->last_id = tx_last;
605 : 0 : tx_id = txe->next_id;
606 : : txe = txn;
607 : 0 : m_seg = m_seg->next;
608 [ # # ]: 0 : } while (m_seg != NULL);
609 : :
610 : : /*
611 : : * The last packet data descriptor needs End Of Packet (EOP)
612 : : * and Report Status (RS).
613 : : */
614 : 0 : txd->read.cmd_type_len |=
615 : : rte_cpu_to_le_32(E1000_TXD_CMD_EOP | E1000_TXD_CMD_RS);
616 : : }
617 : 0 : end_of_tx:
618 : : rte_wmb();
619 : :
620 : : /*
621 : : * Set the Transmit Descriptor Tail (TDT).
622 : : */
623 : 0 : E1000_PCI_REG_WRITE_RELAXED(txq->tdt_reg_addr, tx_id);
624 : : PMD_TX_LOG(DEBUG, "port_id=%u queue_id=%u tx_tail=%u nb_tx=%u",
625 : : (unsigned) txq->port_id, (unsigned) txq->queue_id,
626 : : (unsigned) tx_id, (unsigned) nb_tx);
627 : 0 : txq->tx_tail = tx_id;
628 : :
629 : 0 : return nb_tx;
630 : : }
631 : :
632 : : /*********************************************************************
633 : : *
634 : : * TX prep functions
635 : : *
636 : : **********************************************************************/
637 : : uint16_t
638 : 0 : eth_igb_prep_pkts(__rte_unused void *tx_queue, struct rte_mbuf **tx_pkts,
639 : : uint16_t nb_pkts)
640 : : {
641 : : int i, ret;
642 : : struct rte_mbuf *m;
643 : :
644 [ # # ]: 0 : for (i = 0; i < nb_pkts; i++) {
645 : 0 : m = tx_pkts[i];
646 : :
647 : : /* Check some limitations for TSO in hardware */
648 [ # # ]: 0 : if (m->ol_flags & RTE_MBUF_F_TX_TCP_SEG)
649 [ # # ]: 0 : if ((m->tso_segsz > IGB_TSO_MAX_MSS) ||
650 [ # # ]: 0 : (m->l2_len + m->l3_len + m->l4_len >
651 : : IGB_TSO_MAX_HDRLEN)) {
652 : 0 : rte_errno = EINVAL;
653 : 0 : return i;
654 : : }
655 : :
656 [ # # ]: 0 : if (m->ol_flags & IGB_TX_OFFLOAD_NOTSUP_MASK) {
657 : 0 : rte_errno = ENOTSUP;
658 : 0 : return i;
659 : : }
660 : :
661 : : #ifdef RTE_ETHDEV_DEBUG_TX
662 : : ret = rte_validate_tx_offload(m);
663 : : if (ret != 0) {
664 : : rte_errno = -ret;
665 : : return i;
666 : : }
667 : : #endif
668 : : ret = rte_net_intel_cksum_prepare(m);
669 [ # # ]: 0 : if (ret != 0) {
670 : 0 : rte_errno = -ret;
671 : 0 : return i;
672 : : }
673 : : }
674 : :
675 : 0 : return i;
676 : : }
677 : :
678 : : /*********************************************************************
679 : : *
680 : : * RX functions
681 : : *
682 : : **********************************************************************/
683 : : #define IGB_PACKET_TYPE_IPV4 0X01
684 : : #define IGB_PACKET_TYPE_IPV4_TCP 0X11
685 : : #define IGB_PACKET_TYPE_IPV4_UDP 0X21
686 : : #define IGB_PACKET_TYPE_IPV4_SCTP 0X41
687 : : #define IGB_PACKET_TYPE_IPV4_EXT 0X03
688 : : #define IGB_PACKET_TYPE_IPV4_EXT_SCTP 0X43
689 : : #define IGB_PACKET_TYPE_IPV6 0X04
690 : : #define IGB_PACKET_TYPE_IPV6_TCP 0X14
691 : : #define IGB_PACKET_TYPE_IPV6_UDP 0X24
692 : : #define IGB_PACKET_TYPE_IPV6_EXT 0X0C
693 : : #define IGB_PACKET_TYPE_IPV6_EXT_TCP 0X1C
694 : : #define IGB_PACKET_TYPE_IPV6_EXT_UDP 0X2C
695 : : #define IGB_PACKET_TYPE_IPV4_IPV6 0X05
696 : : #define IGB_PACKET_TYPE_IPV4_IPV6_TCP 0X15
697 : : #define IGB_PACKET_TYPE_IPV4_IPV6_UDP 0X25
698 : : #define IGB_PACKET_TYPE_IPV4_IPV6_EXT 0X0D
699 : : #define IGB_PACKET_TYPE_IPV4_IPV6_EXT_TCP 0X1D
700 : : #define IGB_PACKET_TYPE_IPV4_IPV6_EXT_UDP 0X2D
701 : : #define IGB_PACKET_TYPE_MAX 0X80
702 : : #define IGB_PACKET_TYPE_MASK 0X7F
703 : : #define IGB_PACKET_TYPE_SHIFT 0X04
704 : : static inline uint32_t
705 : : igb_rxd_pkt_info_to_pkt_type(uint16_t pkt_info)
706 : : {
707 : : static const alignas(RTE_CACHE_LINE_SIZE) uint32_t
708 : : ptype_table[IGB_PACKET_TYPE_MAX] = {
709 : : [IGB_PACKET_TYPE_IPV4] = RTE_PTYPE_L2_ETHER |
710 : : RTE_PTYPE_L3_IPV4,
711 : : [IGB_PACKET_TYPE_IPV4_EXT] = RTE_PTYPE_L2_ETHER |
712 : : RTE_PTYPE_L3_IPV4_EXT,
713 : : [IGB_PACKET_TYPE_IPV6] = RTE_PTYPE_L2_ETHER |
714 : : RTE_PTYPE_L3_IPV6,
715 : : [IGB_PACKET_TYPE_IPV4_IPV6] = RTE_PTYPE_L2_ETHER |
716 : : RTE_PTYPE_L3_IPV4 | RTE_PTYPE_TUNNEL_IP |
717 : : RTE_PTYPE_INNER_L3_IPV6,
718 : : [IGB_PACKET_TYPE_IPV6_EXT] = RTE_PTYPE_L2_ETHER |
719 : : RTE_PTYPE_L3_IPV6_EXT,
720 : : [IGB_PACKET_TYPE_IPV4_IPV6_EXT] = RTE_PTYPE_L2_ETHER |
721 : : RTE_PTYPE_L3_IPV4 | RTE_PTYPE_TUNNEL_IP |
722 : : RTE_PTYPE_INNER_L3_IPV6_EXT,
723 : : [IGB_PACKET_TYPE_IPV4_TCP] = RTE_PTYPE_L2_ETHER |
724 : : RTE_PTYPE_L3_IPV4 | RTE_PTYPE_L4_TCP,
725 : : [IGB_PACKET_TYPE_IPV6_TCP] = RTE_PTYPE_L2_ETHER |
726 : : RTE_PTYPE_L3_IPV6 | RTE_PTYPE_L4_TCP,
727 : : [IGB_PACKET_TYPE_IPV4_IPV6_TCP] = RTE_PTYPE_L2_ETHER |
728 : : RTE_PTYPE_L3_IPV4 | RTE_PTYPE_TUNNEL_IP |
729 : : RTE_PTYPE_INNER_L3_IPV6 | RTE_PTYPE_INNER_L4_TCP,
730 : : [IGB_PACKET_TYPE_IPV6_EXT_TCP] = RTE_PTYPE_L2_ETHER |
731 : : RTE_PTYPE_L3_IPV6_EXT | RTE_PTYPE_L4_TCP,
732 : : [IGB_PACKET_TYPE_IPV4_IPV6_EXT_TCP] = RTE_PTYPE_L2_ETHER |
733 : : RTE_PTYPE_L3_IPV4 | RTE_PTYPE_TUNNEL_IP |
734 : : RTE_PTYPE_INNER_L3_IPV6_EXT | RTE_PTYPE_INNER_L4_TCP,
735 : : [IGB_PACKET_TYPE_IPV4_UDP] = RTE_PTYPE_L2_ETHER |
736 : : RTE_PTYPE_L3_IPV4 | RTE_PTYPE_L4_UDP,
737 : : [IGB_PACKET_TYPE_IPV6_UDP] = RTE_PTYPE_L2_ETHER |
738 : : RTE_PTYPE_L3_IPV6 | RTE_PTYPE_L4_UDP,
739 : : [IGB_PACKET_TYPE_IPV4_IPV6_UDP] = RTE_PTYPE_L2_ETHER |
740 : : RTE_PTYPE_L3_IPV4 | RTE_PTYPE_TUNNEL_IP |
741 : : RTE_PTYPE_INNER_L3_IPV6 | RTE_PTYPE_INNER_L4_UDP,
742 : : [IGB_PACKET_TYPE_IPV6_EXT_UDP] = RTE_PTYPE_L2_ETHER |
743 : : RTE_PTYPE_L3_IPV6_EXT | RTE_PTYPE_L4_UDP,
744 : : [IGB_PACKET_TYPE_IPV4_IPV6_EXT_UDP] = RTE_PTYPE_L2_ETHER |
745 : : RTE_PTYPE_L3_IPV4 | RTE_PTYPE_TUNNEL_IP |
746 : : RTE_PTYPE_INNER_L3_IPV6_EXT | RTE_PTYPE_INNER_L4_UDP,
747 : : [IGB_PACKET_TYPE_IPV4_SCTP] = RTE_PTYPE_L2_ETHER |
748 : : RTE_PTYPE_L3_IPV4 | RTE_PTYPE_L4_SCTP,
749 : : [IGB_PACKET_TYPE_IPV4_EXT_SCTP] = RTE_PTYPE_L2_ETHER |
750 : : RTE_PTYPE_L3_IPV4_EXT | RTE_PTYPE_L4_SCTP,
751 : : };
752 : 0 : if (unlikely(pkt_info & E1000_RXDADV_PKTTYPE_ETQF))
753 : : return RTE_PTYPE_UNKNOWN;
754 : :
755 : 0 : pkt_info = (pkt_info >> IGB_PACKET_TYPE_SHIFT) & IGB_PACKET_TYPE_MASK;
756 : :
757 : 0 : return ptype_table[pkt_info];
758 : : }
759 : :
760 : : static inline uint64_t
761 : : rx_desc_hlen_type_rss_to_pkt_flags(struct igb_rx_queue *rxq, uint32_t hl_tp_rs)
762 : : {
763 [ # # ]: 0 : uint64_t pkt_flags = ((hl_tp_rs & 0x0F) == 0) ? 0 : RTE_MBUF_F_RX_RSS_HASH;
764 : :
765 : : #if defined(RTE_LIBRTE_IEEE1588)
766 : : static uint32_t ip_pkt_etqf_map[8] = {
767 : : 0, 0, 0, RTE_MBUF_F_RX_IEEE1588_PTP,
768 : : 0, 0, 0, 0,
769 : : };
770 : :
771 : : struct rte_eth_dev dev = rte_eth_devices[rxq->port_id];
772 : : struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev.data->dev_private);
773 : :
774 : : /* EtherType is in bits 8:10 in Packet Type, and not in the default 0:2 */
775 : : if (hw->mac.type == e1000_i210)
776 : : pkt_flags |= ip_pkt_etqf_map[(hl_tp_rs >> 12) & 0x07];
777 : : else
778 : : pkt_flags |= ip_pkt_etqf_map[(hl_tp_rs >> 4) & 0x07];
779 : : #else
780 : : RTE_SET_USED(rxq);
781 : : #endif
782 : :
783 : : return pkt_flags;
784 : : }
785 : :
786 : : static inline uint64_t
787 : : rx_desc_status_to_pkt_flags(uint32_t rx_status)
788 : : {
789 : : uint64_t pkt_flags;
790 : :
791 : : /* Check if VLAN present */
792 : 0 : pkt_flags = ((rx_status & E1000_RXD_STAT_VP) ?
793 [ # # # # ]: 0 : RTE_MBUF_F_RX_VLAN | RTE_MBUF_F_RX_VLAN_STRIPPED : 0);
794 : :
795 : : #if defined(RTE_LIBRTE_IEEE1588)
796 : : if (rx_status & E1000_RXD_STAT_TMST)
797 : : pkt_flags = pkt_flags | RTE_MBUF_F_RX_IEEE1588_TMST;
798 : : #endif
799 : : return pkt_flags;
800 : : }
801 : :
802 : : static inline uint64_t
803 : : rx_desc_error_to_pkt_flags(uint32_t rx_status)
804 : : {
805 : : /*
806 : : * Bit 30: IPE, IPv4 checksum error
807 : : * Bit 29: L4I, L4I integrity error
808 : : */
809 : :
810 : : static uint64_t error_to_pkt_flags_map[4] = {
811 : : RTE_MBUF_F_RX_IP_CKSUM_GOOD | RTE_MBUF_F_RX_L4_CKSUM_GOOD,
812 : : RTE_MBUF_F_RX_IP_CKSUM_GOOD | RTE_MBUF_F_RX_L4_CKSUM_BAD,
813 : : RTE_MBUF_F_RX_IP_CKSUM_BAD | RTE_MBUF_F_RX_L4_CKSUM_GOOD,
814 : : RTE_MBUF_F_RX_IP_CKSUM_BAD | RTE_MBUF_F_RX_L4_CKSUM_BAD
815 : : };
816 : 0 : return error_to_pkt_flags_map[(rx_status >>
817 : 0 : E1000_RXD_ERR_CKSUM_BIT) & E1000_RXD_ERR_CKSUM_MSK];
818 : : }
819 : :
820 : : uint16_t
821 : 0 : eth_igb_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
822 : : uint16_t nb_pkts)
823 : : {
824 : : struct igb_rx_queue *rxq;
825 : : volatile union e1000_adv_rx_desc *rx_ring;
826 : : volatile union e1000_adv_rx_desc *rxdp;
827 : : struct igb_rx_entry *sw_ring;
828 : : struct igb_rx_entry *rxe;
829 : : struct rte_mbuf *rxm;
830 : : struct rte_mbuf *nmb;
831 : : union e1000_adv_rx_desc rxd;
832 : : uint64_t dma_addr;
833 : : uint32_t staterr;
834 : : uint32_t hlen_type_rss;
835 : : uint16_t pkt_len;
836 : : uint16_t rx_id;
837 : : uint16_t nb_rx;
838 : : uint16_t nb_hold;
839 : : uint64_t pkt_flags;
840 : :
841 : : nb_rx = 0;
842 : : nb_hold = 0;
843 : : rxq = rx_queue;
844 : 0 : rx_id = rxq->rx_tail;
845 : 0 : rx_ring = rxq->rx_ring;
846 : 0 : sw_ring = rxq->sw_ring;
847 [ # # ]: 0 : while (nb_rx < nb_pkts) {
848 : : /*
849 : : * The order of operations here is important as the DD status
850 : : * bit must not be read after any other descriptor fields.
851 : : * rx_ring and rxdp are pointing to volatile data so the order
852 : : * of accesses cannot be reordered by the compiler. If they were
853 : : * not volatile, they could be reordered which could lead to
854 : : * using invalid descriptor fields when read from rxd.
855 : : */
856 : 0 : rxdp = &rx_ring[rx_id];
857 : 0 : staterr = rxdp->wb.upper.status_error;
858 [ # # ]: 0 : if (! (staterr & rte_cpu_to_le_32(E1000_RXD_STAT_DD)))
859 : : break;
860 : 0 : rxd = *rxdp;
861 : :
862 : : /*
863 : : * End of packet.
864 : : *
865 : : * If the E1000_RXD_STAT_EOP flag is not set, the RX packet is
866 : : * likely to be invalid and to be dropped by the various
867 : : * validation checks performed by the network stack.
868 : : *
869 : : * Allocate a new mbuf to replenish the RX ring descriptor.
870 : : * If the allocation fails:
871 : : * - arrange for that RX descriptor to be the first one
872 : : * being parsed the next time the receive function is
873 : : * invoked [on the same queue].
874 : : *
875 : : * - Stop parsing the RX ring and return immediately.
876 : : *
877 : : * This policy do not drop the packet received in the RX
878 : : * descriptor for which the allocation of a new mbuf failed.
879 : : * Thus, it allows that packet to be later retrieved if
880 : : * mbuf have been freed in the mean time.
881 : : * As a side effect, holding RX descriptors instead of
882 : : * systematically giving them back to the NIC may lead to
883 : : * RX ring exhaustion situations.
884 : : * However, the NIC can gracefully prevent such situations
885 : : * to happen by sending specific "back-pressure" flow control
886 : : * frames to its peer(s).
887 : : */
888 : : PMD_RX_LOG(DEBUG, "port_id=%u queue_id=%u rx_id=%u "
889 : : "staterr=0x%x pkt_len=%u",
890 : : (unsigned) rxq->port_id, (unsigned) rxq->queue_id,
891 : : (unsigned) rx_id, (unsigned) staterr,
892 : : (unsigned) rte_le_to_cpu_16(rxd.wb.upper.length));
893 : :
894 : 0 : nmb = rte_mbuf_raw_alloc(rxq->mb_pool);
895 [ # # ]: 0 : if (nmb == NULL) {
896 : : PMD_RX_LOG(DEBUG, "RX mbuf alloc failed port_id=%u "
897 : : "queue_id=%u", (unsigned) rxq->port_id,
898 : : (unsigned) rxq->queue_id);
899 : 0 : rte_eth_devices[rxq->port_id].data->rx_mbuf_alloc_failed++;
900 : 0 : break;
901 : : }
902 : :
903 : 0 : nb_hold++;
904 : 0 : rxe = &sw_ring[rx_id];
905 : 0 : rx_id++;
906 [ # # ]: 0 : if (rx_id == rxq->nb_rx_desc)
907 : : rx_id = 0;
908 : :
909 : : /* Prefetch next mbuf while processing current one. */
910 : 0 : rte_igb_prefetch(sw_ring[rx_id].mbuf);
911 : :
912 : : /*
913 : : * When next RX descriptor is on a cache-line boundary,
914 : : * prefetch the next 4 RX descriptors and the next 8 pointers
915 : : * to mbufs.
916 : : */
917 [ # # ]: 0 : if ((rx_id & 0x3) == 0) {
918 : 0 : rte_igb_prefetch(&rx_ring[rx_id]);
919 : : rte_igb_prefetch(&sw_ring[rx_id]);
920 : : }
921 : :
922 : 0 : rxm = rxe->mbuf;
923 : 0 : rxe->mbuf = nmb;
924 : : dma_addr =
925 : : rte_cpu_to_le_64(rte_mbuf_data_iova_default(nmb));
926 : 0 : rxdp->read.hdr_addr = 0;
927 : 0 : rxdp->read.pkt_addr = dma_addr;
928 : :
929 : : /*
930 : : * Initialize the returned mbuf.
931 : : * 1) setup generic mbuf fields:
932 : : * - number of segments,
933 : : * - next segment,
934 : : * - packet length,
935 : : * - RX port identifier.
936 : : * 2) integrate hardware offload data, if any:
937 : : * - RSS flag & hash,
938 : : * - IP checksum flag,
939 : : * - VLAN TCI, if any,
940 : : * - error flags.
941 : : */
942 : 0 : pkt_len = (uint16_t) (rte_le_to_cpu_16(rxd.wb.upper.length) -
943 : 0 : rxq->crc_len);
944 : 0 : rxm->data_off = RTE_PKTMBUF_HEADROOM;
945 : 0 : rte_packet_prefetch((char *)rxm->buf_addr + rxm->data_off);
946 : 0 : rxm->nb_segs = 1;
947 : 0 : rxm->next = NULL;
948 : 0 : rxm->pkt_len = pkt_len;
949 : 0 : rxm->data_len = pkt_len;
950 : 0 : rxm->port = rxq->port_id;
951 : :
952 : 0 : rxm->hash.rss = rxd.wb.lower.hi_dword.rss;
953 : 0 : hlen_type_rss = rte_le_to_cpu_32(rxd.wb.lower.lo_dword.data);
954 : :
955 : : /*
956 : : * The vlan_tci field is only valid when RTE_MBUF_F_RX_VLAN is
957 : : * set in the pkt_flags field and must be in CPU byte order.
958 : : */
959 [ # # ]: 0 : if ((staterr & rte_cpu_to_le_32(E1000_RXDEXT_STATERR_LB)) &&
960 [ # # ]: 0 : (rxq->flags & IGB_RXQ_FLAG_LB_BSWAP_VLAN)) {
961 [ # # ]: 0 : rxm->vlan_tci = rte_be_to_cpu_16(rxd.wb.upper.vlan);
962 : : } else {
963 : 0 : rxm->vlan_tci = rte_le_to_cpu_16(rxd.wb.upper.vlan);
964 : : }
965 : : pkt_flags = rx_desc_hlen_type_rss_to_pkt_flags(rxq, hlen_type_rss);
966 : 0 : pkt_flags = pkt_flags | rx_desc_status_to_pkt_flags(staterr);
967 : 0 : pkt_flags = pkt_flags | rx_desc_error_to_pkt_flags(staterr);
968 : 0 : rxm->ol_flags = pkt_flags;
969 : 0 : rxm->packet_type = igb_rxd_pkt_info_to_pkt_type(rxd.wb.lower.
970 [ # # ]: 0 : lo_dword.hs_rss.pkt_info);
971 : :
972 : : /*
973 : : * Store the mbuf address into the next entry of the array
974 : : * of returned packets.
975 : : */
976 : 0 : rx_pkts[nb_rx++] = rxm;
977 : : }
978 : 0 : rxq->rx_tail = rx_id;
979 : :
980 : : /*
981 : : * If the number of free RX descriptors is greater than the RX free
982 : : * threshold of the queue, advance the Receive Descriptor Tail (RDT)
983 : : * register.
984 : : * Update the RDT with the value of the last processed RX descriptor
985 : : * minus 1, to guarantee that the RDT register is never equal to the
986 : : * RDH register, which creates a "full" ring situation from the
987 : : * hardware point of view...
988 : : */
989 : 0 : nb_hold = (uint16_t) (nb_hold + rxq->nb_rx_hold);
990 [ # # ]: 0 : if (nb_hold > rxq->rx_free_thresh) {
991 : : PMD_RX_LOG(DEBUG, "port_id=%u queue_id=%u rx_tail=%u "
992 : : "nb_hold=%u nb_rx=%u",
993 : : (unsigned) rxq->port_id, (unsigned) rxq->queue_id,
994 : : (unsigned) rx_id, (unsigned) nb_hold,
995 : : (unsigned) nb_rx);
996 [ # # ]: 0 : rx_id = (uint16_t) ((rx_id == 0) ?
997 : 0 : (rxq->nb_rx_desc - 1) : (rx_id - 1));
998 : 0 : E1000_PCI_REG_WRITE(rxq->rdt_reg_addr, rx_id);
999 : : nb_hold = 0;
1000 : : }
1001 : 0 : rxq->nb_rx_hold = nb_hold;
1002 : 0 : return nb_rx;
1003 : : }
1004 : :
1005 : : uint16_t
1006 : 0 : eth_igb_recv_scattered_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
1007 : : uint16_t nb_pkts)
1008 : : {
1009 : : struct igb_rx_queue *rxq;
1010 : : volatile union e1000_adv_rx_desc *rx_ring;
1011 : : volatile union e1000_adv_rx_desc *rxdp;
1012 : : struct igb_rx_entry *sw_ring;
1013 : : struct igb_rx_entry *rxe;
1014 : : struct rte_mbuf *first_seg;
1015 : : struct rte_mbuf *last_seg;
1016 : : struct rte_mbuf *rxm;
1017 : : struct rte_mbuf *nmb;
1018 : : union e1000_adv_rx_desc rxd;
1019 : : uint64_t dma; /* Physical address of mbuf data buffer */
1020 : : uint32_t staterr;
1021 : : uint32_t hlen_type_rss;
1022 : : uint16_t rx_id;
1023 : : uint16_t nb_rx;
1024 : : uint16_t nb_hold;
1025 : : uint16_t data_len;
1026 : : uint64_t pkt_flags;
1027 : :
1028 : : nb_rx = 0;
1029 : : nb_hold = 0;
1030 : : rxq = rx_queue;
1031 : 0 : rx_id = rxq->rx_tail;
1032 : 0 : rx_ring = rxq->rx_ring;
1033 : 0 : sw_ring = rxq->sw_ring;
1034 : :
1035 : : /*
1036 : : * Retrieve RX context of current packet, if any.
1037 : : */
1038 : 0 : first_seg = rxq->pkt_first_seg;
1039 : 0 : last_seg = rxq->pkt_last_seg;
1040 : :
1041 [ # # ]: 0 : while (nb_rx < nb_pkts) {
1042 : 0 : next_desc:
1043 : : /*
1044 : : * The order of operations here is important as the DD status
1045 : : * bit must not be read after any other descriptor fields.
1046 : : * rx_ring and rxdp are pointing to volatile data so the order
1047 : : * of accesses cannot be reordered by the compiler. If they were
1048 : : * not volatile, they could be reordered which could lead to
1049 : : * using invalid descriptor fields when read from rxd.
1050 : : */
1051 : 0 : rxdp = &rx_ring[rx_id];
1052 : 0 : staterr = rxdp->wb.upper.status_error;
1053 [ # # ]: 0 : if (! (staterr & rte_cpu_to_le_32(E1000_RXD_STAT_DD)))
1054 : : break;
1055 : 0 : rxd = *rxdp;
1056 : :
1057 : : /*
1058 : : * Descriptor done.
1059 : : *
1060 : : * Allocate a new mbuf to replenish the RX ring descriptor.
1061 : : * If the allocation fails:
1062 : : * - arrange for that RX descriptor to be the first one
1063 : : * being parsed the next time the receive function is
1064 : : * invoked [on the same queue].
1065 : : *
1066 : : * - Stop parsing the RX ring and return immediately.
1067 : : *
1068 : : * This policy does not drop the packet received in the RX
1069 : : * descriptor for which the allocation of a new mbuf failed.
1070 : : * Thus, it allows that packet to be later retrieved if
1071 : : * mbuf have been freed in the mean time.
1072 : : * As a side effect, holding RX descriptors instead of
1073 : : * systematically giving them back to the NIC may lead to
1074 : : * RX ring exhaustion situations.
1075 : : * However, the NIC can gracefully prevent such situations
1076 : : * to happen by sending specific "back-pressure" flow control
1077 : : * frames to its peer(s).
1078 : : */
1079 : : PMD_RX_LOG(DEBUG, "port_id=%u queue_id=%u rx_id=%u "
1080 : : "staterr=0x%x data_len=%u",
1081 : : (unsigned) rxq->port_id, (unsigned) rxq->queue_id,
1082 : : (unsigned) rx_id, (unsigned) staterr,
1083 : : (unsigned) rte_le_to_cpu_16(rxd.wb.upper.length));
1084 : :
1085 : 0 : nmb = rte_mbuf_raw_alloc(rxq->mb_pool);
1086 [ # # ]: 0 : if (nmb == NULL) {
1087 : : PMD_RX_LOG(DEBUG, "RX mbuf alloc failed port_id=%u "
1088 : : "queue_id=%u", (unsigned) rxq->port_id,
1089 : : (unsigned) rxq->queue_id);
1090 : 0 : rte_eth_devices[rxq->port_id].data->rx_mbuf_alloc_failed++;
1091 : 0 : break;
1092 : : }
1093 : :
1094 : 0 : nb_hold++;
1095 : 0 : rxe = &sw_ring[rx_id];
1096 : 0 : rx_id++;
1097 [ # # ]: 0 : if (rx_id == rxq->nb_rx_desc)
1098 : : rx_id = 0;
1099 : :
1100 : : /* Prefetch next mbuf while processing current one. */
1101 : 0 : rte_igb_prefetch(sw_ring[rx_id].mbuf);
1102 : :
1103 : : /*
1104 : : * When next RX descriptor is on a cache-line boundary,
1105 : : * prefetch the next 4 RX descriptors and the next 8 pointers
1106 : : * to mbufs.
1107 : : */
1108 [ # # ]: 0 : if ((rx_id & 0x3) == 0) {
1109 : 0 : rte_igb_prefetch(&rx_ring[rx_id]);
1110 : : rte_igb_prefetch(&sw_ring[rx_id]);
1111 : : }
1112 : :
1113 : : /*
1114 : : * Update RX descriptor with the physical address of the new
1115 : : * data buffer of the new allocated mbuf.
1116 : : */
1117 : 0 : rxm = rxe->mbuf;
1118 [ # # ]: 0 : rxe->mbuf = nmb;
1119 : : dma = rte_cpu_to_le_64(rte_mbuf_data_iova_default(nmb));
1120 : 0 : rxdp->read.pkt_addr = dma;
1121 : 0 : rxdp->read.hdr_addr = 0;
1122 : :
1123 : : /*
1124 : : * Set data length & data buffer address of mbuf.
1125 : : */
1126 : : data_len = rte_le_to_cpu_16(rxd.wb.upper.length);
1127 : 0 : rxm->data_len = data_len;
1128 : 0 : rxm->data_off = RTE_PKTMBUF_HEADROOM;
1129 : :
1130 : : /*
1131 : : * If this is the first buffer of the received packet,
1132 : : * set the pointer to the first mbuf of the packet and
1133 : : * initialize its context.
1134 : : * Otherwise, update the total length and the number of segments
1135 : : * of the current scattered packet, and update the pointer to
1136 : : * the last mbuf of the current packet.
1137 : : */
1138 [ # # ]: 0 : if (first_seg == NULL) {
1139 : : first_seg = rxm;
1140 : 0 : first_seg->pkt_len = data_len;
1141 : 0 : first_seg->nb_segs = 1;
1142 : : } else {
1143 : 0 : first_seg->pkt_len += data_len;
1144 : 0 : first_seg->nb_segs++;
1145 : 0 : last_seg->next = rxm;
1146 : : }
1147 : :
1148 : : /*
1149 : : * If this is not the last buffer of the received packet,
1150 : : * update the pointer to the last mbuf of the current scattered
1151 : : * packet and continue to parse the RX ring.
1152 : : */
1153 [ # # ]: 0 : if (! (staterr & E1000_RXD_STAT_EOP)) {
1154 : : last_seg = rxm;
1155 : 0 : goto next_desc;
1156 : : }
1157 : :
1158 : : /*
1159 : : * This is the last buffer of the received packet.
1160 : : * If the CRC is not stripped by the hardware:
1161 : : * - Subtract the CRC length from the total packet length.
1162 : : * - If the last buffer only contains the whole CRC or a part
1163 : : * of it, free the mbuf associated to the last buffer.
1164 : : * If part of the CRC is also contained in the previous
1165 : : * mbuf, subtract the length of that CRC part from the
1166 : : * data length of the previous mbuf.
1167 : : */
1168 : 0 : rxm->next = NULL;
1169 [ # # ]: 0 : if (unlikely(rxq->crc_len > 0)) {
1170 : 0 : first_seg->pkt_len -= RTE_ETHER_CRC_LEN;
1171 [ # # ]: 0 : if (data_len <= RTE_ETHER_CRC_LEN) {
1172 : : rte_pktmbuf_free_seg(rxm);
1173 : 0 : first_seg->nb_segs--;
1174 : 0 : last_seg->data_len = (uint16_t)
1175 : 0 : (last_seg->data_len -
1176 : : (RTE_ETHER_CRC_LEN - data_len));
1177 : 0 : last_seg->next = NULL;
1178 : : } else
1179 : 0 : rxm->data_len = (uint16_t)
1180 : : (data_len - RTE_ETHER_CRC_LEN);
1181 : : }
1182 : :
1183 : : /*
1184 : : * Initialize the first mbuf of the returned packet:
1185 : : * - RX port identifier,
1186 : : * - hardware offload data, if any:
1187 : : * - RSS flag & hash,
1188 : : * - IP checksum flag,
1189 : : * - VLAN TCI, if any,
1190 : : * - error flags.
1191 : : */
1192 : 0 : first_seg->port = rxq->port_id;
1193 : 0 : first_seg->hash.rss = rxd.wb.lower.hi_dword.rss;
1194 : :
1195 : : /*
1196 : : * The vlan_tci field is only valid when RTE_MBUF_F_RX_VLAN is
1197 : : * set in the pkt_flags field and must be in CPU byte order.
1198 : : */
1199 [ # # ]: 0 : if ((staterr & rte_cpu_to_le_32(E1000_RXDEXT_STATERR_LB)) &&
1200 [ # # ]: 0 : (rxq->flags & IGB_RXQ_FLAG_LB_BSWAP_VLAN)) {
1201 : 0 : first_seg->vlan_tci =
1202 [ # # ]: 0 : rte_be_to_cpu_16(rxd.wb.upper.vlan);
1203 : : } else {
1204 : 0 : first_seg->vlan_tci =
1205 : : rte_le_to_cpu_16(rxd.wb.upper.vlan);
1206 : : }
1207 [ # # ]: 0 : hlen_type_rss = rte_le_to_cpu_32(rxd.wb.lower.lo_dword.data);
1208 : : pkt_flags = rx_desc_hlen_type_rss_to_pkt_flags(rxq, hlen_type_rss);
1209 : 0 : pkt_flags = pkt_flags | rx_desc_status_to_pkt_flags(staterr);
1210 : 0 : pkt_flags = pkt_flags | rx_desc_error_to_pkt_flags(staterr);
1211 : 0 : first_seg->ol_flags = pkt_flags;
1212 : 0 : first_seg->packet_type = igb_rxd_pkt_info_to_pkt_type(rxd.wb.
1213 [ # # ]: 0 : lower.lo_dword.hs_rss.pkt_info);
1214 : :
1215 : : /* Prefetch data of first segment, if configured to do so. */
1216 : 0 : rte_packet_prefetch((char *)first_seg->buf_addr +
1217 : : first_seg->data_off);
1218 : :
1219 : : /*
1220 : : * Store the mbuf address into the next entry of the array
1221 : : * of returned packets.
1222 : : */
1223 : 0 : rx_pkts[nb_rx++] = first_seg;
1224 : :
1225 : : /*
1226 : : * Setup receipt context for a new packet.
1227 : : */
1228 : : first_seg = NULL;
1229 : : }
1230 : :
1231 : : /*
1232 : : * Record index of the next RX descriptor to probe.
1233 : : */
1234 : 0 : rxq->rx_tail = rx_id;
1235 : :
1236 : : /*
1237 : : * Save receive context.
1238 : : */
1239 : 0 : rxq->pkt_first_seg = first_seg;
1240 : 0 : rxq->pkt_last_seg = last_seg;
1241 : :
1242 : : /*
1243 : : * If the number of free RX descriptors is greater than the RX free
1244 : : * threshold of the queue, advance the Receive Descriptor Tail (RDT)
1245 : : * register.
1246 : : * Update the RDT with the value of the last processed RX descriptor
1247 : : * minus 1, to guarantee that the RDT register is never equal to the
1248 : : * RDH register, which creates a "full" ring situation from the
1249 : : * hardware point of view...
1250 : : */
1251 : 0 : nb_hold = (uint16_t) (nb_hold + rxq->nb_rx_hold);
1252 [ # # ]: 0 : if (nb_hold > rxq->rx_free_thresh) {
1253 : : PMD_RX_LOG(DEBUG, "port_id=%u queue_id=%u rx_tail=%u "
1254 : : "nb_hold=%u nb_rx=%u",
1255 : : (unsigned) rxq->port_id, (unsigned) rxq->queue_id,
1256 : : (unsigned) rx_id, (unsigned) nb_hold,
1257 : : (unsigned) nb_rx);
1258 [ # # ]: 0 : rx_id = (uint16_t) ((rx_id == 0) ?
1259 : 0 : (rxq->nb_rx_desc - 1) : (rx_id - 1));
1260 : 0 : E1000_PCI_REG_WRITE(rxq->rdt_reg_addr, rx_id);
1261 : : nb_hold = 0;
1262 : : }
1263 : 0 : rxq->nb_rx_hold = nb_hold;
1264 : 0 : return nb_rx;
1265 : : }
1266 : :
1267 : : /*
1268 : : * Maximum number of Ring Descriptors.
1269 : : *
1270 : : * Since RDLEN/TDLEN should be multiple of 128bytes, the number of ring
1271 : : * descriptors should meet the following condition:
1272 : : * (num_ring_desc * sizeof(struct e1000_rx/tx_desc)) % 128 == 0
1273 : : */
1274 : :
1275 : : static void
1276 : 0 : igb_tx_queue_release_mbufs(struct igb_tx_queue *txq)
1277 : : {
1278 : : unsigned i;
1279 : :
1280 [ # # ]: 0 : if (txq->sw_ring != NULL) {
1281 [ # # ]: 0 : for (i = 0; i < txq->nb_tx_desc; i++) {
1282 [ # # ]: 0 : if (txq->sw_ring[i].mbuf != NULL) {
1283 : : rte_pktmbuf_free_seg(txq->sw_ring[i].mbuf);
1284 : 0 : txq->sw_ring[i].mbuf = NULL;
1285 : : }
1286 : : }
1287 : : }
1288 : 0 : }
1289 : :
1290 : : static void
1291 : 0 : igb_tx_queue_release(struct igb_tx_queue *txq)
1292 : : {
1293 [ # # ]: 0 : if (txq != NULL) {
1294 : 0 : igb_tx_queue_release_mbufs(txq);
1295 : 0 : rte_free(txq->sw_ring);
1296 : 0 : rte_memzone_free(txq->mz);
1297 : 0 : rte_free(txq);
1298 : : }
1299 : 0 : }
1300 : :
1301 : : void
1302 : 0 : eth_igb_tx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
1303 : : {
1304 : 0 : igb_tx_queue_release(dev->data->tx_queues[qid]);
1305 : 0 : }
1306 : :
1307 : : static int
1308 : 0 : igb_tx_done_cleanup(struct igb_tx_queue *txq, uint32_t free_cnt)
1309 : : {
1310 : : struct igb_tx_entry *sw_ring;
1311 : : volatile union e1000_adv_tx_desc *txr;
1312 : : uint16_t tx_first; /* First segment analyzed. */
1313 : : uint16_t tx_id; /* Current segment being processed. */
1314 : : uint16_t tx_last; /* Last segment in the current packet. */
1315 : : uint16_t tx_next; /* First segment of the next packet. */
1316 : : int count = 0;
1317 : :
1318 [ # # ]: 0 : if (!txq)
1319 : : return -ENODEV;
1320 : :
1321 : 0 : sw_ring = txq->sw_ring;
1322 : 0 : txr = txq->tx_ring;
1323 : :
1324 : : /* tx_tail is the last sent packet on the sw_ring. Goto the end
1325 : : * of that packet (the last segment in the packet chain) and
1326 : : * then the next segment will be the start of the oldest segment
1327 : : * in the sw_ring. This is the first packet that will be
1328 : : * attempted to be freed.
1329 : : */
1330 : :
1331 : : /* Get last segment in most recently added packet. */
1332 : 0 : tx_first = sw_ring[txq->tx_tail].last_id;
1333 : :
1334 : : /* Get the next segment, which is the oldest segment in ring. */
1335 : 0 : tx_first = sw_ring[tx_first].next_id;
1336 : :
1337 : : /* Set the current index to the first. */
1338 : : tx_id = tx_first;
1339 : :
1340 : : /* Loop through each packet. For each packet, verify that an
1341 : : * mbuf exists and that the last segment is free. If so, free
1342 : : * it and move on.
1343 : : */
1344 : : while (1) {
1345 : 0 : tx_last = sw_ring[tx_id].last_id;
1346 : :
1347 [ # # ]: 0 : if (sw_ring[tx_last].mbuf) {
1348 [ # # ]: 0 : if (txr[tx_last].wb.status &
1349 : : E1000_TXD_STAT_DD) {
1350 : : /* Increment the number of packets
1351 : : * freed.
1352 : : */
1353 : 0 : count++;
1354 : :
1355 : : /* Get the start of the next packet. */
1356 : 0 : tx_next = sw_ring[tx_last].next_id;
1357 : :
1358 : : /* Loop through all segments in a
1359 : : * packet.
1360 : : */
1361 : : do {
1362 [ # # ]: 0 : if (sw_ring[tx_id].mbuf) {
1363 : : rte_pktmbuf_free_seg(
1364 : : sw_ring[tx_id].mbuf);
1365 : 0 : sw_ring[tx_id].mbuf = NULL;
1366 : 0 : sw_ring[tx_id].last_id = tx_id;
1367 : : }
1368 : :
1369 : : /* Move to next segment. */
1370 : 0 : tx_id = sw_ring[tx_id].next_id;
1371 : :
1372 [ # # ]: 0 : } while (tx_id != tx_next);
1373 : :
1374 [ # # ]: 0 : if (unlikely(count == (int)free_cnt))
1375 : : break;
1376 : : } else {
1377 : : /* mbuf still in use, nothing left to
1378 : : * free.
1379 : : */
1380 : : break;
1381 : : }
1382 : : } else {
1383 : : /* There are multiple reasons to be here:
1384 : : * 1) All the packets on the ring have been
1385 : : * freed - tx_id is equal to tx_first
1386 : : * and some packets have been freed.
1387 : : * - Done, exit
1388 : : * 2) Interfaces has not sent a rings worth of
1389 : : * packets yet, so the segment after tail is
1390 : : * still empty. Or a previous call to this
1391 : : * function freed some of the segments but
1392 : : * not all so there is a hole in the list.
1393 : : * Hopefully this is a rare case.
1394 : : * - Walk the list and find the next mbuf. If
1395 : : * there isn't one, then done.
1396 : : */
1397 [ # # ]: 0 : if (likely(tx_id == tx_first && count != 0))
1398 : : break;
1399 : :
1400 : : /* Walk the list and find the next mbuf, if any. */
1401 : : do {
1402 : : /* Move to next segment. */
1403 : 0 : tx_id = sw_ring[tx_id].next_id;
1404 : :
1405 [ # # ]: 0 : if (sw_ring[tx_id].mbuf)
1406 : : break;
1407 : :
1408 [ # # ]: 0 : } while (tx_id != tx_first);
1409 : :
1410 : : /* Determine why previous loop bailed. If there
1411 : : * is not an mbuf, done.
1412 : : */
1413 [ # # ]: 0 : if (!sw_ring[tx_id].mbuf)
1414 : : break;
1415 : : }
1416 : : }
1417 : :
1418 : : return count;
1419 : : }
1420 : :
1421 : : int
1422 : 0 : eth_igb_tx_done_cleanup(void *txq, uint32_t free_cnt)
1423 : : {
1424 : 0 : return igb_tx_done_cleanup(txq, free_cnt);
1425 : : }
1426 : :
1427 : : static void
1428 : : igb_reset_tx_queue_stat(struct igb_tx_queue *txq)
1429 : : {
1430 : 0 : txq->tx_head = 0;
1431 : 0 : txq->tx_tail = 0;
1432 : 0 : txq->ctx_curr = 0;
1433 : 0 : memset((void*)&txq->ctx_cache, 0,
1434 : : IGB_CTX_NUM * sizeof(struct igb_advctx_info));
1435 : : }
1436 : :
1437 : : static void
1438 : 0 : igb_reset_tx_queue(struct igb_tx_queue *txq, struct rte_eth_dev *dev)
1439 : : {
1440 : : static const union e1000_adv_tx_desc zeroed_desc = {{0}};
1441 : 0 : struct igb_tx_entry *txe = txq->sw_ring;
1442 : : uint16_t i, prev;
1443 : : struct e1000_hw *hw;
1444 : :
1445 : 0 : hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1446 : : /* Zero out HW ring memory */
1447 [ # # ]: 0 : for (i = 0; i < txq->nb_tx_desc; i++) {
1448 : 0 : txq->tx_ring[i] = zeroed_desc;
1449 : : }
1450 : :
1451 : : /* Initialize ring entries */
1452 : 0 : prev = (uint16_t)(txq->nb_tx_desc - 1);
1453 [ # # ]: 0 : for (i = 0; i < txq->nb_tx_desc; i++) {
1454 : 0 : volatile union e1000_adv_tx_desc *txd = &(txq->tx_ring[i]);
1455 : :
1456 : 0 : txd->wb.status = E1000_TXD_STAT_DD;
1457 : 0 : txe[i].mbuf = NULL;
1458 : 0 : txe[i].last_id = i;
1459 : 0 : txe[prev].next_id = i;
1460 : : prev = i;
1461 : : }
1462 : :
1463 : 0 : txq->txd_type = E1000_ADVTXD_DTYP_DATA;
1464 : : /* 82575 specific, each tx queue will use 2 hw contexts */
1465 [ # # ]: 0 : if (hw->mac.type == e1000_82575)
1466 : 0 : txq->ctx_start = txq->queue_id * IGB_CTX_NUM;
1467 : :
1468 : : igb_reset_tx_queue_stat(txq);
1469 : 0 : }
1470 : :
1471 : : uint64_t
1472 : 0 : igb_get_tx_port_offloads_capa(struct rte_eth_dev *dev)
1473 : : {
1474 : : uint64_t tx_offload_capa;
1475 : :
1476 : : RTE_SET_USED(dev);
1477 : : tx_offload_capa = RTE_ETH_TX_OFFLOAD_VLAN_INSERT |
1478 : : RTE_ETH_TX_OFFLOAD_IPV4_CKSUM |
1479 : : RTE_ETH_TX_OFFLOAD_UDP_CKSUM |
1480 : : RTE_ETH_TX_OFFLOAD_TCP_CKSUM |
1481 : : RTE_ETH_TX_OFFLOAD_SCTP_CKSUM |
1482 : : RTE_ETH_TX_OFFLOAD_TCP_TSO |
1483 : : RTE_ETH_TX_OFFLOAD_MULTI_SEGS |
1484 : : RTE_ETH_TX_OFFLOAD_SEND_ON_TIMESTAMP;
1485 : :
1486 : 0 : return tx_offload_capa;
1487 : : }
1488 : :
1489 : : uint64_t
1490 : 0 : igb_get_tx_queue_offloads_capa(struct rte_eth_dev *dev)
1491 : : {
1492 : : RTE_SET_USED(dev);
1493 : :
1494 : 0 : return 0;
1495 : : }
1496 : :
1497 : : int
1498 : 0 : eth_igb_tx_queue_setup(struct rte_eth_dev *dev,
1499 : : uint16_t queue_idx,
1500 : : uint16_t nb_desc,
1501 : : unsigned int socket_id,
1502 : : const struct rte_eth_txconf *tx_conf)
1503 : : {
1504 : : const struct rte_memzone *tz;
1505 : : struct igb_tx_queue *txq;
1506 : : struct e1000_hw *hw;
1507 : : uint32_t size;
1508 : : uint64_t offloads;
1509 : :
1510 : 0 : offloads = tx_conf->offloads | dev->data->dev_conf.txmode.offloads;
1511 : :
1512 : 0 : hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1513 : :
1514 : : /*
1515 : : * Validate number of transmit descriptors.
1516 : : * It must not exceed hardware maximum, and must be multiple
1517 : : * of E1000_ALIGN.
1518 : : */
1519 [ # # ]: 0 : if (nb_desc % IGB_TXD_ALIGN != 0 ||
1520 [ # # ]: 0 : (nb_desc > E1000_MAX_RING_DESC) ||
1521 : : (nb_desc < E1000_MIN_RING_DESC)) {
1522 : : return -EINVAL;
1523 : : }
1524 : :
1525 : : /*
1526 : : * The tx_free_thresh and tx_rs_thresh values are not used in the 1G
1527 : : * driver.
1528 : : */
1529 [ # # ]: 0 : if (tx_conf->tx_free_thresh != 0)
1530 : 0 : PMD_INIT_LOG(INFO, "The tx_free_thresh parameter is not "
1531 : : "used for the 1G driver.");
1532 [ # # ]: 0 : if (tx_conf->tx_rs_thresh != 0)
1533 : 0 : PMD_INIT_LOG(INFO, "The tx_rs_thresh parameter is not "
1534 : : "used for the 1G driver.");
1535 [ # # # # ]: 0 : if (tx_conf->tx_thresh.wthresh == 0 && hw->mac.type != e1000_82576)
1536 : 0 : PMD_INIT_LOG(INFO, "To improve 1G driver performance, "
1537 : : "consider setting the TX WTHRESH value to 4, 8, "
1538 : : "or 16.");
1539 : :
1540 : : /* Free memory prior to re-allocation if needed */
1541 [ # # ]: 0 : if (dev->data->tx_queues[queue_idx] != NULL) {
1542 : 0 : igb_tx_queue_release(dev->data->tx_queues[queue_idx]);
1543 : 0 : dev->data->tx_queues[queue_idx] = NULL;
1544 : : }
1545 : :
1546 : : /* First allocate the tx queue data structure */
1547 : 0 : txq = rte_zmalloc("ethdev TX queue", sizeof(struct igb_tx_queue),
1548 : : RTE_CACHE_LINE_SIZE);
1549 [ # # ]: 0 : if (txq == NULL)
1550 : : return -ENOMEM;
1551 : :
1552 : : /*
1553 : : * Allocate TX ring hardware descriptors. A memzone large enough to
1554 : : * handle the maximum ring size is allocated in order to allow for
1555 : : * resizing in later calls to the queue setup function.
1556 : : */
1557 : : size = sizeof(union e1000_adv_tx_desc) * E1000_MAX_RING_DESC;
1558 : 0 : tz = rte_eth_dma_zone_reserve(dev, "tx_ring", queue_idx, size,
1559 : : E1000_ALIGN, socket_id);
1560 [ # # ]: 0 : if (tz == NULL) {
1561 : 0 : igb_tx_queue_release(txq);
1562 : 0 : return -ENOMEM;
1563 : : }
1564 : :
1565 : 0 : txq->mz = tz;
1566 : 0 : txq->nb_tx_desc = nb_desc;
1567 : 0 : txq->pthresh = tx_conf->tx_thresh.pthresh;
1568 : 0 : txq->hthresh = tx_conf->tx_thresh.hthresh;
1569 : 0 : txq->wthresh = tx_conf->tx_thresh.wthresh;
1570 [ # # # # ]: 0 : if (txq->wthresh > 0 && hw->mac.type == e1000_82576)
1571 : 0 : txq->wthresh = 1;
1572 : 0 : txq->queue_id = queue_idx;
1573 [ # # ]: 0 : txq->reg_idx = (uint16_t)((RTE_ETH_DEV_SRIOV(dev).active == 0) ?
1574 : 0 : queue_idx : RTE_ETH_DEV_SRIOV(dev).def_pool_q_idx + queue_idx);
1575 : 0 : txq->port_id = dev->data->port_id;
1576 : :
1577 [ # # ]: 0 : txq->tdt_reg_addr = E1000_PCI_REG_ADDR(hw, E1000_TDT(txq->reg_idx));
1578 : 0 : txq->tx_ring_phys_addr = tz->iova;
1579 : :
1580 : 0 : txq->tx_ring = (union e1000_adv_tx_desc *) tz->addr;
1581 : : /* Allocate software ring */
1582 : 0 : txq->sw_ring = rte_zmalloc("txq->sw_ring",
1583 : : sizeof(struct igb_tx_entry) * nb_desc,
1584 : : RTE_CACHE_LINE_SIZE);
1585 [ # # ]: 0 : if (txq->sw_ring == NULL) {
1586 : 0 : igb_tx_queue_release(txq);
1587 : 0 : return -ENOMEM;
1588 : : }
1589 : 0 : PMD_INIT_LOG(DEBUG, "sw_ring=%p hw_ring=%p dma_addr=0x%"PRIx64,
1590 : : txq->sw_ring, txq->tx_ring, txq->tx_ring_phys_addr);
1591 : :
1592 : 0 : igb_reset_tx_queue(txq, dev);
1593 : 0 : dev->tx_pkt_burst = eth_igb_xmit_pkts;
1594 : 0 : dev->tx_pkt_prepare = ð_igb_prep_pkts;
1595 : 0 : dev->data->tx_queues[queue_idx] = txq;
1596 : 0 : txq->offloads = offloads;
1597 : :
1598 : 0 : return 0;
1599 : : }
1600 : :
1601 : : static void
1602 : 0 : igb_rx_queue_release_mbufs(struct igb_rx_queue *rxq)
1603 : : {
1604 : : unsigned i;
1605 : :
1606 [ # # ]: 0 : if (rxq->sw_ring != NULL) {
1607 [ # # ]: 0 : for (i = 0; i < rxq->nb_rx_desc; i++) {
1608 [ # # ]: 0 : if (rxq->sw_ring[i].mbuf != NULL) {
1609 : : rte_pktmbuf_free_seg(rxq->sw_ring[i].mbuf);
1610 : 0 : rxq->sw_ring[i].mbuf = NULL;
1611 : : }
1612 : : }
1613 : : }
1614 : 0 : }
1615 : :
1616 : : static void
1617 : 0 : igb_rx_queue_release(struct igb_rx_queue *rxq)
1618 : : {
1619 [ # # ]: 0 : if (rxq != NULL) {
1620 : 0 : igb_rx_queue_release_mbufs(rxq);
1621 : 0 : rte_free(rxq->sw_ring);
1622 : 0 : rte_memzone_free(rxq->mz);
1623 : 0 : rte_free(rxq);
1624 : : }
1625 : 0 : }
1626 : :
1627 : : void
1628 : 0 : eth_igb_rx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
1629 : : {
1630 : 0 : igb_rx_queue_release(dev->data->rx_queues[qid]);
1631 : 0 : }
1632 : :
1633 : : static void
1634 : : igb_reset_rx_queue(struct igb_rx_queue *rxq)
1635 : : {
1636 : : static const union e1000_adv_rx_desc zeroed_desc = {{0}};
1637 : : unsigned i;
1638 : :
1639 : : /* Zero out HW ring memory */
1640 [ # # # # ]: 0 : for (i = 0; i < rxq->nb_rx_desc; i++) {
1641 : 0 : rxq->rx_ring[i] = zeroed_desc;
1642 : : }
1643 : :
1644 : 0 : rxq->rx_tail = 0;
1645 : 0 : rxq->pkt_first_seg = NULL;
1646 : 0 : rxq->pkt_last_seg = NULL;
1647 : : }
1648 : :
1649 : : uint64_t
1650 : 0 : igb_get_rx_port_offloads_capa(struct rte_eth_dev *dev)
1651 : : {
1652 : : uint64_t rx_offload_capa;
1653 : : struct e1000_hw *hw;
1654 : :
1655 : 0 : hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1656 : :
1657 : : rx_offload_capa = RTE_ETH_RX_OFFLOAD_VLAN_STRIP |
1658 : : RTE_ETH_RX_OFFLOAD_VLAN_FILTER |
1659 : : RTE_ETH_RX_OFFLOAD_IPV4_CKSUM |
1660 : : RTE_ETH_RX_OFFLOAD_UDP_CKSUM |
1661 : : RTE_ETH_RX_OFFLOAD_TCP_CKSUM |
1662 : : RTE_ETH_RX_OFFLOAD_KEEP_CRC |
1663 : : RTE_ETH_RX_OFFLOAD_SCATTER |
1664 : : RTE_ETH_RX_OFFLOAD_RSS_HASH;
1665 : :
1666 [ # # ]: 0 : if (hw->mac.type == e1000_82576 ||
1667 [ # # ]: 0 : hw->mac.type == e1000_i350 ||
1668 [ # # ]: 0 : hw->mac.type == e1000_i210 ||
1669 : : hw->mac.type == e1000_i211)
1670 : : rx_offload_capa |= RTE_ETH_RX_OFFLOAD_VLAN_EXTEND;
1671 : :
1672 : 0 : return rx_offload_capa;
1673 : : }
1674 : :
1675 : : uint64_t
1676 : 0 : igb_get_rx_queue_offloads_capa(struct rte_eth_dev *dev)
1677 : : {
1678 : 0 : struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1679 : : uint64_t rx_queue_offload_capa;
1680 : :
1681 [ # # ]: 0 : switch (hw->mac.type) {
1682 : 0 : case e1000_vfadapt_i350:
1683 : : /*
1684 : : * As only one Rx queue can be used, let per queue offloading
1685 : : * capability be same to per port queue offloading capability
1686 : : * for better convenience.
1687 : : */
1688 : 0 : rx_queue_offload_capa = igb_get_rx_port_offloads_capa(dev);
1689 : 0 : break;
1690 : : default:
1691 : : rx_queue_offload_capa = 0;
1692 : : }
1693 : 0 : return rx_queue_offload_capa;
1694 : : }
1695 : :
1696 : : int
1697 : 0 : eth_igb_rx_queue_setup(struct rte_eth_dev *dev,
1698 : : uint16_t queue_idx,
1699 : : uint16_t nb_desc,
1700 : : unsigned int socket_id,
1701 : : const struct rte_eth_rxconf *rx_conf,
1702 : : struct rte_mempool *mp)
1703 : : {
1704 : : const struct rte_memzone *rz;
1705 : : struct igb_rx_queue *rxq;
1706 : : struct e1000_hw *hw;
1707 : : unsigned int size;
1708 : : uint64_t offloads;
1709 : :
1710 : 0 : offloads = rx_conf->offloads | dev->data->dev_conf.rxmode.offloads;
1711 : :
1712 : 0 : hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1713 : :
1714 : : /*
1715 : : * Validate number of receive descriptors.
1716 : : * It must not exceed hardware maximum, and must be multiple
1717 : : * of E1000_ALIGN.
1718 : : */
1719 [ # # ]: 0 : if (nb_desc % IGB_RXD_ALIGN != 0 ||
1720 [ # # ]: 0 : (nb_desc > E1000_MAX_RING_DESC) ||
1721 : : (nb_desc < E1000_MIN_RING_DESC)) {
1722 : : return -EINVAL;
1723 : : }
1724 : :
1725 : : /* Free memory prior to re-allocation if needed */
1726 [ # # ]: 0 : if (dev->data->rx_queues[queue_idx] != NULL) {
1727 : 0 : igb_rx_queue_release(dev->data->rx_queues[queue_idx]);
1728 : 0 : dev->data->rx_queues[queue_idx] = NULL;
1729 : : }
1730 : :
1731 : : /* First allocate the RX queue data structure. */
1732 : 0 : rxq = rte_zmalloc("ethdev RX queue", sizeof(struct igb_rx_queue),
1733 : : RTE_CACHE_LINE_SIZE);
1734 [ # # ]: 0 : if (rxq == NULL)
1735 : : return -ENOMEM;
1736 : 0 : rxq->offloads = offloads;
1737 : 0 : rxq->mb_pool = mp;
1738 : 0 : rxq->nb_rx_desc = nb_desc;
1739 : 0 : rxq->pthresh = rx_conf->rx_thresh.pthresh;
1740 : 0 : rxq->hthresh = rx_conf->rx_thresh.hthresh;
1741 : 0 : rxq->wthresh = rx_conf->rx_thresh.wthresh;
1742 [ # # ]: 0 : if (rxq->wthresh > 0 &&
1743 [ # # ]: 0 : (hw->mac.type == e1000_82576 || hw->mac.type == e1000_vfadapt_i350))
1744 : 0 : rxq->wthresh = 1;
1745 : 0 : rxq->drop_en = rx_conf->rx_drop_en;
1746 : 0 : rxq->rx_free_thresh = rx_conf->rx_free_thresh;
1747 : 0 : rxq->queue_id = queue_idx;
1748 [ # # ]: 0 : rxq->reg_idx = (uint16_t)((RTE_ETH_DEV_SRIOV(dev).active == 0) ?
1749 : 0 : queue_idx : RTE_ETH_DEV_SRIOV(dev).def_pool_q_idx + queue_idx);
1750 : 0 : rxq->port_id = dev->data->port_id;
1751 [ # # ]: 0 : if (dev->data->dev_conf.rxmode.offloads & RTE_ETH_RX_OFFLOAD_KEEP_CRC)
1752 : 0 : rxq->crc_len = RTE_ETHER_CRC_LEN;
1753 : : else
1754 : 0 : rxq->crc_len = 0;
1755 : :
1756 : : /*
1757 : : * Allocate RX ring hardware descriptors. A memzone large enough to
1758 : : * handle the maximum ring size is allocated in order to allow for
1759 : : * resizing in later calls to the queue setup function.
1760 : : */
1761 : : size = sizeof(union e1000_adv_rx_desc) * E1000_MAX_RING_DESC;
1762 : 0 : rz = rte_eth_dma_zone_reserve(dev, "rx_ring", queue_idx, size,
1763 : : E1000_ALIGN, socket_id);
1764 [ # # ]: 0 : if (rz == NULL) {
1765 : 0 : igb_rx_queue_release(rxq);
1766 : 0 : return -ENOMEM;
1767 : : }
1768 : :
1769 : 0 : rxq->mz = rz;
1770 [ # # ]: 0 : rxq->rdt_reg_addr = E1000_PCI_REG_ADDR(hw, E1000_RDT(rxq->reg_idx));
1771 [ # # ]: 0 : rxq->rdh_reg_addr = E1000_PCI_REG_ADDR(hw, E1000_RDH(rxq->reg_idx));
1772 : 0 : rxq->rx_ring_phys_addr = rz->iova;
1773 : 0 : rxq->rx_ring = (union e1000_adv_rx_desc *) rz->addr;
1774 : :
1775 : : /* Allocate software ring. */
1776 : 0 : rxq->sw_ring = rte_zmalloc("rxq->sw_ring",
1777 : : sizeof(struct igb_rx_entry) * nb_desc,
1778 : : RTE_CACHE_LINE_SIZE);
1779 [ # # ]: 0 : if (rxq->sw_ring == NULL) {
1780 : 0 : igb_rx_queue_release(rxq);
1781 : 0 : return -ENOMEM;
1782 : : }
1783 : 0 : PMD_INIT_LOG(DEBUG, "sw_ring=%p hw_ring=%p dma_addr=0x%"PRIx64,
1784 : : rxq->sw_ring, rxq->rx_ring, rxq->rx_ring_phys_addr);
1785 : :
1786 : 0 : dev->data->rx_queues[queue_idx] = rxq;
1787 : : igb_reset_rx_queue(rxq);
1788 : :
1789 : 0 : return 0;
1790 : : }
1791 : :
1792 : : int
1793 : 0 : eth_igb_rx_queue_count(void *rx_queue)
1794 : : {
1795 : : #define IGB_RXQ_SCAN_INTERVAL 4
1796 : : volatile union e1000_adv_rx_desc *rxdp;
1797 : : struct igb_rx_queue *rxq;
1798 : : uint32_t desc = 0;
1799 : :
1800 : : rxq = rx_queue;
1801 : 0 : rxdp = &(rxq->rx_ring[rxq->rx_tail]);
1802 : :
1803 [ # # ]: 0 : while ((desc < rxq->nb_rx_desc) &&
1804 [ # # ]: 0 : (rxdp->wb.upper.status_error & E1000_RXD_STAT_DD)) {
1805 : 0 : desc += IGB_RXQ_SCAN_INTERVAL;
1806 : 0 : rxdp += IGB_RXQ_SCAN_INTERVAL;
1807 [ # # ]: 0 : if (rxq->rx_tail + desc >= rxq->nb_rx_desc)
1808 : 0 : rxdp = &(rxq->rx_ring[rxq->rx_tail +
1809 : 0 : desc - rxq->nb_rx_desc]);
1810 : : }
1811 : :
1812 : 0 : return desc;
1813 : : }
1814 : :
1815 : : int
1816 : 0 : eth_igb_rx_descriptor_status(void *rx_queue, uint16_t offset)
1817 : : {
1818 : : struct igb_rx_queue *rxq = rx_queue;
1819 : : volatile uint32_t *status;
1820 : : uint32_t desc;
1821 : :
1822 [ # # ]: 0 : if (unlikely(offset >= rxq->nb_rx_desc))
1823 : : return -EINVAL;
1824 : :
1825 [ # # ]: 0 : if (offset >= rxq->nb_rx_desc - rxq->nb_rx_hold)
1826 : : return RTE_ETH_RX_DESC_UNAVAIL;
1827 : :
1828 : 0 : desc = rxq->rx_tail + offset;
1829 [ # # ]: 0 : if (desc >= rxq->nb_rx_desc)
1830 : 0 : desc -= rxq->nb_rx_desc;
1831 : :
1832 : 0 : status = &rxq->rx_ring[desc].wb.upper.status_error;
1833 [ # # ]: 0 : if (*status & rte_cpu_to_le_32(E1000_RXD_STAT_DD))
1834 : 0 : return RTE_ETH_RX_DESC_DONE;
1835 : :
1836 : : return RTE_ETH_RX_DESC_AVAIL;
1837 : : }
1838 : :
1839 : : int
1840 : 0 : eth_igb_tx_descriptor_status(void *tx_queue, uint16_t offset)
1841 : : {
1842 : : struct igb_tx_queue *txq = tx_queue;
1843 : : volatile uint32_t *status;
1844 : : uint32_t desc;
1845 : :
1846 [ # # ]: 0 : if (unlikely(offset >= txq->nb_tx_desc))
1847 : : return -EINVAL;
1848 : :
1849 : 0 : desc = txq->tx_tail + offset;
1850 [ # # ]: 0 : if (desc >= txq->nb_tx_desc)
1851 : 0 : desc -= txq->nb_tx_desc;
1852 : :
1853 : 0 : status = &txq->tx_ring[desc].wb.status;
1854 [ # # ]: 0 : if (*status & rte_cpu_to_le_32(E1000_TXD_STAT_DD))
1855 : 0 : return RTE_ETH_TX_DESC_DONE;
1856 : :
1857 : : return RTE_ETH_TX_DESC_FULL;
1858 : : }
1859 : :
1860 : : void
1861 : 0 : igb_dev_clear_queues(struct rte_eth_dev *dev)
1862 : : {
1863 : : uint16_t i;
1864 : : struct igb_tx_queue *txq;
1865 : : struct igb_rx_queue *rxq;
1866 : :
1867 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
1868 [ # # ]: 0 : __rte_assume(i < RTE_MAX_QUEUES_PER_PORT);
1869 : 0 : txq = dev->data->tx_queues[i];
1870 [ # # ]: 0 : if (txq != NULL) {
1871 : 0 : igb_tx_queue_release_mbufs(txq);
1872 : 0 : igb_reset_tx_queue(txq, dev);
1873 : 0 : dev->data->tx_queue_state[i] = RTE_ETH_QUEUE_STATE_STOPPED;
1874 : : }
1875 : : }
1876 : :
1877 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
1878 [ # # ]: 0 : __rte_assume(i < RTE_MAX_QUEUES_PER_PORT);
1879 : 0 : rxq = dev->data->rx_queues[i];
1880 [ # # ]: 0 : if (rxq != NULL) {
1881 : 0 : igb_rx_queue_release_mbufs(rxq);
1882 : : igb_reset_rx_queue(rxq);
1883 : 0 : dev->data->rx_queue_state[i] = RTE_ETH_QUEUE_STATE_STOPPED;
1884 : : }
1885 : : }
1886 : 0 : }
1887 : :
1888 : : void
1889 : 0 : igb_dev_free_queues(struct rte_eth_dev *dev)
1890 : : {
1891 : : uint16_t i;
1892 : :
1893 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
1894 : 0 : eth_igb_rx_queue_release(dev, i);
1895 : 0 : dev->data->rx_queues[i] = NULL;
1896 : : }
1897 : 0 : dev->data->nb_rx_queues = 0;
1898 : :
1899 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
1900 : 0 : eth_igb_tx_queue_release(dev, i);
1901 : 0 : dev->data->tx_queues[i] = NULL;
1902 : : }
1903 : 0 : dev->data->nb_tx_queues = 0;
1904 : 0 : }
1905 : :
1906 : : /**
1907 : : * Receive Side Scaling (RSS).
1908 : : * See section 7.1.1.7 in the following document:
1909 : : * "Intel 82576 GbE Controller Datasheet" - Revision 2.45 October 2009
1910 : : *
1911 : : * Principles:
1912 : : * The source and destination IP addresses of the IP header and the source and
1913 : : * destination ports of TCP/UDP headers, if any, of received packets are hashed
1914 : : * against a configurable random key to compute a 32-bit RSS hash result.
1915 : : * The seven (7) LSBs of the 32-bit hash result are used as an index into a
1916 : : * 128-entry redirection table (RETA). Each entry of the RETA provides a 3-bit
1917 : : * RSS output index which is used as the RX queue index where to store the
1918 : : * received packets.
1919 : : * The following output is supplied in the RX write-back descriptor:
1920 : : * - 32-bit result of the Microsoft RSS hash function,
1921 : : * - 4-bit RSS type field.
1922 : : */
1923 : :
1924 : : /*
1925 : : * RSS random key supplied in section 7.1.1.7.3 of the Intel 82576 datasheet.
1926 : : * Used as the default key.
1927 : : */
1928 : : static uint8_t rss_intel_key[40] = {
1929 : : 0x6D, 0x5A, 0x56, 0xDA, 0x25, 0x5B, 0x0E, 0xC2,
1930 : : 0x41, 0x67, 0x25, 0x3D, 0x43, 0xA3, 0x8F, 0xB0,
1931 : : 0xD0, 0xCA, 0x2B, 0xCB, 0xAE, 0x7B, 0x30, 0xB4,
1932 : : 0x77, 0xCB, 0x2D, 0xA3, 0x80, 0x30, 0xF2, 0x0C,
1933 : : 0x6A, 0x42, 0xB7, 0x3B, 0xBE, 0xAC, 0x01, 0xFA,
1934 : : };
1935 : :
1936 : : static void
1937 : : igb_rss_disable(struct rte_eth_dev *dev)
1938 : : {
1939 : : struct e1000_hw *hw;
1940 : : uint32_t mrqc;
1941 : :
1942 : 0 : hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1943 : 0 : mrqc = E1000_READ_REG(hw, E1000_MRQC);
1944 : 0 : mrqc &= ~E1000_MRQC_ENABLE_MASK;
1945 : 0 : E1000_WRITE_REG(hw, E1000_MRQC, mrqc);
1946 : 0 : }
1947 : :
1948 : : static void
1949 : 0 : igb_hw_rss_hash_set(struct e1000_hw *hw, struct rte_eth_rss_conf *rss_conf)
1950 : : {
1951 : : uint8_t *hash_key;
1952 : : uint32_t rss_key;
1953 : : uint32_t mrqc;
1954 : : uint64_t rss_hf;
1955 : : uint16_t i;
1956 : :
1957 : 0 : hash_key = rss_conf->rss_key;
1958 [ # # ]: 0 : if (hash_key != NULL) {
1959 : : /* Fill in RSS hash key */
1960 [ # # ]: 0 : for (i = 0; i < 10; i++) {
1961 : 0 : rss_key = hash_key[(i * 4)];
1962 : 0 : rss_key |= hash_key[(i * 4) + 1] << 8;
1963 : 0 : rss_key |= hash_key[(i * 4) + 2] << 16;
1964 : 0 : rss_key |= hash_key[(i * 4) + 3] << 24;
1965 : 0 : E1000_WRITE_REG_ARRAY(hw, E1000_RSSRK(0), i, rss_key);
1966 : : }
1967 : : }
1968 : :
1969 : : /* Set configured hashing protocols in MRQC register */
1970 : 0 : rss_hf = rss_conf->rss_hf;
1971 : : mrqc = E1000_MRQC_ENABLE_RSS_4Q; /* RSS enabled. */
1972 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_IPV4)
1973 : : mrqc |= E1000_MRQC_RSS_FIELD_IPV4;
1974 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_NONFRAG_IPV4_TCP)
1975 : 0 : mrqc |= E1000_MRQC_RSS_FIELD_IPV4_TCP;
1976 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_IPV6)
1977 : 0 : mrqc |= E1000_MRQC_RSS_FIELD_IPV6;
1978 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_IPV6_EX)
1979 : 0 : mrqc |= E1000_MRQC_RSS_FIELD_IPV6_EX;
1980 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_NONFRAG_IPV6_TCP)
1981 : 0 : mrqc |= E1000_MRQC_RSS_FIELD_IPV6_TCP;
1982 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_IPV6_TCP_EX)
1983 : 0 : mrqc |= E1000_MRQC_RSS_FIELD_IPV6_TCP_EX;
1984 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_NONFRAG_IPV4_UDP)
1985 : 0 : mrqc |= E1000_MRQC_RSS_FIELD_IPV4_UDP;
1986 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_NONFRAG_IPV6_UDP)
1987 : 0 : mrqc |= E1000_MRQC_RSS_FIELD_IPV6_UDP;
1988 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_IPV6_UDP_EX)
1989 : 0 : mrqc |= E1000_MRQC_RSS_FIELD_IPV6_UDP_EX;
1990 : 0 : E1000_WRITE_REG(hw, E1000_MRQC, mrqc);
1991 : 0 : }
1992 : :
1993 : : int
1994 : 0 : eth_igb_rss_hash_update(struct rte_eth_dev *dev,
1995 : : struct rte_eth_rss_conf *rss_conf)
1996 : : {
1997 : : struct e1000_hw *hw;
1998 : : uint32_t mrqc;
1999 : : uint64_t rss_hf;
2000 : :
2001 : 0 : hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2002 : :
2003 : : /*
2004 : : * Before changing anything, first check that the update RSS operation
2005 : : * does not attempt to disable RSS, if RSS was enabled at
2006 : : * initialization time, or does not attempt to enable RSS, if RSS was
2007 : : * disabled at initialization time.
2008 : : */
2009 : 0 : rss_hf = rss_conf->rss_hf & IGB_RSS_OFFLOAD_ALL;
2010 : 0 : mrqc = E1000_READ_REG(hw, E1000_MRQC);
2011 [ # # ]: 0 : if (!(mrqc & E1000_MRQC_ENABLE_MASK)) { /* RSS disabled */
2012 [ # # ]: 0 : if (rss_hf != 0) /* Enable RSS */
2013 : : return -(EINVAL);
2014 : 0 : return 0; /* Nothing to do */
2015 : : }
2016 : : /* RSS enabled */
2017 [ # # ]: 0 : if (rss_hf == 0) /* Disable RSS */
2018 : : return -(EINVAL);
2019 : 0 : igb_hw_rss_hash_set(hw, rss_conf);
2020 : 0 : return 0;
2021 : : }
2022 : :
2023 : 0 : int eth_igb_rss_hash_conf_get(struct rte_eth_dev *dev,
2024 : : struct rte_eth_rss_conf *rss_conf)
2025 : : {
2026 : : struct e1000_hw *hw;
2027 : : uint8_t *hash_key;
2028 : : uint32_t rss_key;
2029 : : uint32_t mrqc;
2030 : : uint64_t rss_hf;
2031 : : uint16_t i;
2032 : :
2033 : 0 : hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2034 : 0 : hash_key = rss_conf->rss_key;
2035 [ # # ]: 0 : if (hash_key != NULL) {
2036 : : /* Return RSS hash key */
2037 [ # # ]: 0 : for (i = 0; i < IGB_HKEY_MAX_INDEX; i++) {
2038 : 0 : rss_key = E1000_READ_REG_ARRAY(hw, E1000_RSSRK(0), i);
2039 : 0 : hash_key[(i * 4)] = rss_key & 0x000000FF;
2040 : 0 : hash_key[(i * 4) + 1] = (rss_key >> 8) & 0x000000FF;
2041 : 0 : hash_key[(i * 4) + 2] = (rss_key >> 16) & 0x000000FF;
2042 : 0 : hash_key[(i * 4) + 3] = (rss_key >> 24) & 0x000000FF;
2043 : : }
2044 : 0 : rss_conf->rss_key_len = IGB_HKEY_MAX_INDEX * sizeof(uint32_t);
2045 : : }
2046 : :
2047 : : /* Get RSS functions configured in MRQC register */
2048 : 0 : mrqc = E1000_READ_REG(hw, E1000_MRQC);
2049 [ # # ]: 0 : if ((mrqc & E1000_MRQC_ENABLE_RSS_4Q) == 0) { /* RSS is disabled */
2050 : 0 : rss_conf->rss_hf = 0;
2051 : 0 : return 0;
2052 : : }
2053 : : rss_hf = 0;
2054 [ # # ]: 0 : if (mrqc & E1000_MRQC_RSS_FIELD_IPV4)
2055 : : rss_hf |= RTE_ETH_RSS_IPV4;
2056 [ # # ]: 0 : if (mrqc & E1000_MRQC_RSS_FIELD_IPV4_TCP)
2057 : 0 : rss_hf |= RTE_ETH_RSS_NONFRAG_IPV4_TCP;
2058 [ # # ]: 0 : if (mrqc & E1000_MRQC_RSS_FIELD_IPV6)
2059 : 0 : rss_hf |= RTE_ETH_RSS_IPV6;
2060 [ # # ]: 0 : if (mrqc & E1000_MRQC_RSS_FIELD_IPV6_EX)
2061 : 0 : rss_hf |= RTE_ETH_RSS_IPV6_EX;
2062 [ # # ]: 0 : if (mrqc & E1000_MRQC_RSS_FIELD_IPV6_TCP)
2063 : 0 : rss_hf |= RTE_ETH_RSS_NONFRAG_IPV6_TCP;
2064 [ # # ]: 0 : if (mrqc & E1000_MRQC_RSS_FIELD_IPV6_TCP_EX)
2065 : 0 : rss_hf |= RTE_ETH_RSS_IPV6_TCP_EX;
2066 [ # # ]: 0 : if (mrqc & E1000_MRQC_RSS_FIELD_IPV4_UDP)
2067 : 0 : rss_hf |= RTE_ETH_RSS_NONFRAG_IPV4_UDP;
2068 [ # # ]: 0 : if (mrqc & E1000_MRQC_RSS_FIELD_IPV6_UDP)
2069 : 0 : rss_hf |= RTE_ETH_RSS_NONFRAG_IPV6_UDP;
2070 [ # # ]: 0 : if (mrqc & E1000_MRQC_RSS_FIELD_IPV6_UDP_EX)
2071 : 0 : rss_hf |= RTE_ETH_RSS_IPV6_UDP_EX;
2072 : 0 : rss_conf->rss_hf = rss_hf;
2073 : 0 : return 0;
2074 : : }
2075 : :
2076 : : static void
2077 : 0 : igb_rss_configure(struct rte_eth_dev *dev)
2078 : : {
2079 : : struct rte_eth_rss_conf rss_conf;
2080 : : struct e1000_hw *hw;
2081 : : uint32_t shift;
2082 : : uint16_t i;
2083 : :
2084 : 0 : hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2085 : :
2086 : : /* Fill in redirection table. */
2087 [ # # ]: 0 : shift = (hw->mac.type == e1000_82575) ? 6 : 0;
2088 [ # # ]: 0 : for (i = 0; i < 128; i++) {
2089 : : union e1000_reta {
2090 : : uint32_t dword;
2091 : : uint8_t bytes[4];
2092 : : } reta;
2093 : : uint8_t q_idx;
2094 : :
2095 [ # # ]: 0 : q_idx = (uint8_t) ((dev->data->nb_rx_queues > 1) ?
2096 : : i % dev->data->nb_rx_queues : 0);
2097 : 0 : reta.bytes[i & 3] = (uint8_t) (q_idx << shift);
2098 [ # # ]: 0 : if ((i & 3) == 3)
2099 : 0 : E1000_WRITE_REG(hw, E1000_RETA(i >> 2), reta.dword);
2100 : : }
2101 : :
2102 : : /*
2103 : : * Configure the RSS key and the RSS protocols used to compute
2104 : : * the RSS hash of input packets.
2105 : : */
2106 : 0 : rss_conf = dev->data->dev_conf.rx_adv_conf.rss_conf;
2107 [ # # ]: 0 : if ((rss_conf.rss_hf & IGB_RSS_OFFLOAD_ALL) == 0) {
2108 : : igb_rss_disable(dev);
2109 : 0 : return;
2110 : : }
2111 [ # # ]: 0 : if (rss_conf.rss_key == NULL)
2112 : 0 : rss_conf.rss_key = rss_intel_key; /* Default hash key */
2113 : 0 : igb_hw_rss_hash_set(hw, &rss_conf);
2114 : : }
2115 : :
2116 : : /*
2117 : : * Check if the mac type support VMDq or not.
2118 : : * Return 1 if it supports, otherwise, return 0.
2119 : : */
2120 : : static int
2121 : 0 : igb_is_vmdq_supported(const struct rte_eth_dev *dev)
2122 : : {
2123 : 0 : const struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2124 : :
2125 [ # # ]: 0 : switch (hw->mac.type) {
2126 : : case e1000_82576:
2127 : : case e1000_82580:
2128 : : case e1000_i350:
2129 : : return 1;
2130 : 0 : case e1000_82540:
2131 : : case e1000_82541:
2132 : : case e1000_82542:
2133 : : case e1000_82543:
2134 : : case e1000_82544:
2135 : : case e1000_82545:
2136 : : case e1000_82546:
2137 : : case e1000_82547:
2138 : : case e1000_82571:
2139 : : case e1000_82572:
2140 : : case e1000_82573:
2141 : : case e1000_82574:
2142 : : case e1000_82583:
2143 : : case e1000_i210:
2144 : : case e1000_i211:
2145 : : default:
2146 : 0 : PMD_INIT_LOG(ERR, "Cannot support VMDq feature");
2147 : 0 : return 0;
2148 : : }
2149 : : }
2150 : :
2151 : : static int
2152 : 0 : igb_vmdq_rx_hw_configure(struct rte_eth_dev *dev)
2153 : : {
2154 : : struct rte_eth_vmdq_rx_conf *cfg;
2155 : : struct e1000_hw *hw;
2156 : : uint32_t mrqc, vt_ctl, vmolr, rctl;
2157 : : int i;
2158 : :
2159 : 0 : PMD_INIT_FUNC_TRACE();
2160 : :
2161 : 0 : hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2162 : : cfg = &dev->data->dev_conf.rx_adv_conf.vmdq_rx_conf;
2163 : :
2164 : : /* Check if mac type can support VMDq, return value of 0 means NOT support */
2165 [ # # ]: 0 : if (igb_is_vmdq_supported(dev) == 0)
2166 : : return -1;
2167 : :
2168 : : igb_rss_disable(dev);
2169 : :
2170 : : /* RCTL: enable VLAN filter */
2171 : 0 : rctl = E1000_READ_REG(hw, E1000_RCTL);
2172 : 0 : rctl |= E1000_RCTL_VFE;
2173 : 0 : E1000_WRITE_REG(hw, E1000_RCTL, rctl);
2174 : :
2175 : : /* MRQC: enable vmdq */
2176 : 0 : mrqc = E1000_READ_REG(hw, E1000_MRQC);
2177 : 0 : mrqc |= E1000_MRQC_ENABLE_VMDQ;
2178 : 0 : E1000_WRITE_REG(hw, E1000_MRQC, mrqc);
2179 : :
2180 : : /* VTCTL: pool selection according to VLAN tag */
2181 : 0 : vt_ctl = E1000_READ_REG(hw, E1000_VT_CTL);
2182 [ # # ]: 0 : if (cfg->enable_default_pool)
2183 : 0 : vt_ctl |= (cfg->default_pool << E1000_VT_CTL_DEFAULT_POOL_SHIFT);
2184 : 0 : vt_ctl |= E1000_VT_CTL_IGNORE_MAC;
2185 : 0 : E1000_WRITE_REG(hw, E1000_VT_CTL, vt_ctl);
2186 : :
2187 [ # # ]: 0 : for (i = 0; i < E1000_VMOLR_SIZE; i++) {
2188 : 0 : vmolr = E1000_READ_REG(hw, E1000_VMOLR(i));
2189 : 0 : vmolr &= ~(E1000_VMOLR_AUPE | E1000_VMOLR_ROMPE |
2190 : : E1000_VMOLR_ROPE | E1000_VMOLR_BAM |
2191 : : E1000_VMOLR_MPME);
2192 : :
2193 [ # # ]: 0 : if (cfg->rx_mode & RTE_ETH_VMDQ_ACCEPT_UNTAG)
2194 : 0 : vmolr |= E1000_VMOLR_AUPE;
2195 [ # # ]: 0 : if (cfg->rx_mode & RTE_ETH_VMDQ_ACCEPT_HASH_MC)
2196 : 0 : vmolr |= E1000_VMOLR_ROMPE;
2197 [ # # ]: 0 : if (cfg->rx_mode & RTE_ETH_VMDQ_ACCEPT_HASH_UC)
2198 : 0 : vmolr |= E1000_VMOLR_ROPE;
2199 [ # # ]: 0 : if (cfg->rx_mode & RTE_ETH_VMDQ_ACCEPT_BROADCAST)
2200 : 0 : vmolr |= E1000_VMOLR_BAM;
2201 [ # # ]: 0 : if (cfg->rx_mode & RTE_ETH_VMDQ_ACCEPT_MULTICAST)
2202 : 0 : vmolr |= E1000_VMOLR_MPME;
2203 : :
2204 : 0 : E1000_WRITE_REG(hw, E1000_VMOLR(i), vmolr);
2205 : : }
2206 : :
2207 : : /*
2208 : : * VMOLR: set STRVLAN as 1 if IGMAC in VTCTL is set as 1
2209 : : * Both 82576 and 82580 support it
2210 : : */
2211 [ # # ]: 0 : if (hw->mac.type != e1000_i350) {
2212 [ # # ]: 0 : for (i = 0; i < E1000_VMOLR_SIZE; i++) {
2213 : 0 : vmolr = E1000_READ_REG(hw, E1000_VMOLR(i));
2214 : 0 : vmolr |= E1000_VMOLR_STRVLAN;
2215 : 0 : E1000_WRITE_REG(hw, E1000_VMOLR(i), vmolr);
2216 : : }
2217 : : }
2218 : :
2219 : : /* VFTA - enable all vlan filters */
2220 [ # # ]: 0 : for (i = 0; i < IGB_VFTA_SIZE; i++)
2221 : 0 : E1000_WRITE_REG(hw, (E1000_VFTA+(i*4)), UINT32_MAX);
2222 : :
2223 : : /* VFRE: 8 pools enabling for rx, both 82576 and i350 support it */
2224 [ # # ]: 0 : if (hw->mac.type != e1000_82580)
2225 : 0 : E1000_WRITE_REG(hw, E1000_VFRE, E1000_MBVFICR_VFREQ_MASK);
2226 : :
2227 : : /*
2228 : : * RAH/RAL - allow pools to read specific mac addresses
2229 : : * In this case, all pools should be able to read from mac addr 0
2230 : : */
2231 : 0 : E1000_WRITE_REG(hw, E1000_RAH(0), (E1000_RAH_AV | UINT16_MAX));
2232 : 0 : E1000_WRITE_REG(hw, E1000_RAL(0), UINT32_MAX);
2233 : :
2234 : : /* VLVF: set up filters for vlan tags as configured */
2235 [ # # ]: 0 : for (i = 0; i < cfg->nb_pool_maps; i++) {
2236 : : /* set vlan id in VF register and set the valid bit */
2237 : 0 : E1000_WRITE_REG(hw, E1000_VLVF(i), (E1000_VLVF_VLANID_ENABLE |
2238 : : (cfg->pool_map[i].vlan_id & RTE_ETH_VLAN_ID_MAX) |
2239 : : ((cfg->pool_map[i].pools << E1000_VLVF_POOLSEL_SHIFT) &
2240 : : E1000_VLVF_POOLSEL_MASK)));
2241 : : }
2242 : :
2243 : 0 : E1000_WRITE_FLUSH(hw);
2244 : :
2245 : 0 : return 0;
2246 : : }
2247 : :
2248 : :
2249 : : /*********************************************************************
2250 : : *
2251 : : * Enable receive unit.
2252 : : *
2253 : : **********************************************************************/
2254 : :
2255 : : static int
2256 : 0 : igb_alloc_rx_queue_mbufs(struct igb_rx_queue *rxq)
2257 : : {
2258 : 0 : struct igb_rx_entry *rxe = rxq->sw_ring;
2259 : : uint64_t dma_addr;
2260 : : unsigned i;
2261 : :
2262 : : /* Initialize software ring entries. */
2263 [ # # ]: 0 : for (i = 0; i < rxq->nb_rx_desc; i++) {
2264 : : volatile union e1000_adv_rx_desc *rxd;
2265 : 0 : struct rte_mbuf *mbuf = rte_mbuf_raw_alloc(rxq->mb_pool);
2266 : :
2267 [ # # ]: 0 : if (mbuf == NULL) {
2268 : 0 : PMD_INIT_LOG(ERR, "RX mbuf alloc failed "
2269 : : "queue_id=%hu", rxq->queue_id);
2270 : 0 : return -ENOMEM;
2271 : : }
2272 : : dma_addr =
2273 : : rte_cpu_to_le_64(rte_mbuf_data_iova_default(mbuf));
2274 : 0 : rxd = &rxq->rx_ring[i];
2275 : 0 : rxd->read.hdr_addr = 0;
2276 : 0 : rxd->read.pkt_addr = dma_addr;
2277 : 0 : rxe[i].mbuf = mbuf;
2278 : : }
2279 : :
2280 : : return 0;
2281 : : }
2282 : :
2283 : : #define E1000_MRQC_DEF_Q_SHIFT (3)
2284 : : static int
2285 : 0 : igb_dev_mq_rx_configure(struct rte_eth_dev *dev)
2286 : : {
2287 : : struct e1000_hw *hw =
2288 : 0 : E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2289 : : uint32_t mrqc;
2290 : :
2291 [ # # ]: 0 : if (RTE_ETH_DEV_SRIOV(dev).active == RTE_ETH_8_POOLS) {
2292 : : /*
2293 : : * SRIOV active scheme
2294 : : * FIXME if support RSS together with VMDq & SRIOV
2295 : : */
2296 : : mrqc = E1000_MRQC_ENABLE_VMDQ;
2297 : : /* 011b Def_Q ignore, according to VT_CTL.DEF_PL */
2298 : : mrqc |= 0x3 << E1000_MRQC_DEF_Q_SHIFT;
2299 : 0 : E1000_WRITE_REG(hw, E1000_MRQC, mrqc);
2300 [ # # ]: 0 : } else if(RTE_ETH_DEV_SRIOV(dev).active == 0) {
2301 : : /*
2302 : : * SRIOV inactive scheme
2303 : : */
2304 [ # # # ]: 0 : switch (dev->data->dev_conf.rxmode.mq_mode) {
2305 : 0 : case RTE_ETH_MQ_RX_RSS:
2306 : 0 : igb_rss_configure(dev);
2307 : 0 : break;
2308 : 0 : case RTE_ETH_MQ_RX_VMDQ_ONLY:
2309 : : /*Configure general VMDQ only RX parameters*/
2310 : 0 : igb_vmdq_rx_hw_configure(dev);
2311 : 0 : break;
2312 : : case RTE_ETH_MQ_RX_NONE:
2313 : : /* if mq_mode is none, disable rss mode.*/
2314 : : default:
2315 : : igb_rss_disable(dev);
2316 : : break;
2317 : : }
2318 : : }
2319 : :
2320 : 0 : return 0;
2321 : : }
2322 : :
2323 : : int
2324 : 0 : eth_igb_rx_init(struct rte_eth_dev *dev)
2325 : : {
2326 : : struct rte_eth_rxmode *rxmode;
2327 : : struct e1000_hw *hw;
2328 : : struct igb_rx_queue *rxq;
2329 : : uint32_t rctl;
2330 : : uint32_t rxcsum;
2331 : : uint32_t srrctl;
2332 : : uint16_t buf_size;
2333 : : uint16_t rctl_bsize;
2334 : : uint32_t max_len;
2335 : : uint16_t i;
2336 : : int ret;
2337 : :
2338 : 0 : hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2339 : : srrctl = 0;
2340 : :
2341 : : /*
2342 : : * Make sure receives are disabled while setting
2343 : : * up the descriptor ring.
2344 : : */
2345 : 0 : rctl = E1000_READ_REG(hw, E1000_RCTL);
2346 : 0 : E1000_WRITE_REG(hw, E1000_RCTL, rctl & ~E1000_RCTL_EN);
2347 : :
2348 : 0 : rxmode = &dev->data->dev_conf.rxmode;
2349 : :
2350 : : /*
2351 : : * Configure support of jumbo frames, if any.
2352 : : */
2353 : 0 : max_len = dev->data->mtu + E1000_ETH_OVERHEAD;
2354 [ # # ]: 0 : if (dev->data->mtu > RTE_ETHER_MTU) {
2355 : 0 : rctl |= E1000_RCTL_LPE;
2356 : :
2357 : : /*
2358 : : * Set maximum packet length by default, and might be updated
2359 : : * together with enabling/disabling dual VLAN.
2360 : : */
2361 [ # # ]: 0 : if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_EXTEND)
2362 : 0 : max_len += VLAN_TAG_SIZE;
2363 : :
2364 : 0 : E1000_WRITE_REG(hw, E1000_RLPML, max_len);
2365 : : } else
2366 : 0 : rctl &= ~E1000_RCTL_LPE;
2367 : :
2368 : : /* Configure and enable each RX queue. */
2369 : : rctl_bsize = 0;
2370 : 0 : dev->rx_pkt_burst = eth_igb_recv_pkts;
2371 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
2372 : : uint64_t bus_addr;
2373 : : uint32_t rxdctl;
2374 : :
2375 : 0 : rxq = dev->data->rx_queues[i];
2376 : :
2377 : 0 : rxq->flags = 0;
2378 : : /*
2379 : : * i350 and i354 vlan packets have vlan tags byte swapped.
2380 : : */
2381 [ # # ]: 0 : if (hw->mac.type == e1000_i350 || hw->mac.type == e1000_i354) {
2382 : 0 : rxq->flags |= IGB_RXQ_FLAG_LB_BSWAP_VLAN;
2383 : 0 : PMD_INIT_LOG(DEBUG, "IGB rx vlan bswap required");
2384 : : } else {
2385 : 0 : PMD_INIT_LOG(DEBUG, "IGB rx vlan bswap not required");
2386 : : }
2387 : :
2388 : : /* Allocate buffers for descriptor rings and set up queue */
2389 : 0 : ret = igb_alloc_rx_queue_mbufs(rxq);
2390 [ # # ]: 0 : if (ret)
2391 : 0 : return ret;
2392 : :
2393 : : /*
2394 : : * Reset crc_len in case it was changed after queue setup by a
2395 : : * call to configure
2396 : : */
2397 [ # # ]: 0 : if (dev->data->dev_conf.rxmode.offloads & RTE_ETH_RX_OFFLOAD_KEEP_CRC)
2398 : 0 : rxq->crc_len = RTE_ETHER_CRC_LEN;
2399 : : else
2400 : 0 : rxq->crc_len = 0;
2401 : :
2402 : 0 : bus_addr = rxq->rx_ring_phys_addr;
2403 [ # # ]: 0 : E1000_WRITE_REG(hw, E1000_RDLEN(rxq->reg_idx),
2404 : : rxq->nb_rx_desc *
2405 : : sizeof(union e1000_adv_rx_desc));
2406 [ # # ]: 0 : E1000_WRITE_REG(hw, E1000_RDBAH(rxq->reg_idx),
2407 : : (uint32_t)(bus_addr >> 32));
2408 [ # # ]: 0 : E1000_WRITE_REG(hw, E1000_RDBAL(rxq->reg_idx), (uint32_t)bus_addr);
2409 : :
2410 : : srrctl = E1000_SRRCTL_DESCTYPE_ADV_ONEBUF;
2411 : :
2412 : : /*
2413 : : * Configure RX buffer size.
2414 : : */
2415 [ # # ]: 0 : buf_size = (uint16_t)(rte_pktmbuf_data_room_size(rxq->mb_pool) -
2416 : : RTE_PKTMBUF_HEADROOM);
2417 [ # # ]: 0 : if (buf_size >= 1024) {
2418 : : /*
2419 : : * Configure the BSIZEPACKET field of the SRRCTL
2420 : : * register of the queue.
2421 : : * Value is in 1 KB resolution, from 1 KB to 127 KB.
2422 : : * If this field is equal to 0b, then RCTL.BSIZE
2423 : : * determines the RX packet buffer size.
2424 : : */
2425 : 0 : srrctl |= ((buf_size >> E1000_SRRCTL_BSIZEPKT_SHIFT) &
2426 : : E1000_SRRCTL_BSIZEPKT_MASK);
2427 : 0 : buf_size = (uint16_t) ((srrctl &
2428 : : E1000_SRRCTL_BSIZEPKT_MASK) <<
2429 : : E1000_SRRCTL_BSIZEPKT_SHIFT);
2430 : :
2431 : : /* It adds dual VLAN length for supporting dual VLAN */
2432 [ # # ]: 0 : if ((max_len + 2 * VLAN_TAG_SIZE) > buf_size) {
2433 [ # # ]: 0 : if (!dev->data->scattered_rx)
2434 : 0 : PMD_INIT_LOG(DEBUG,
2435 : : "forcing scatter mode");
2436 : 0 : dev->rx_pkt_burst = eth_igb_recv_scattered_pkts;
2437 : 0 : dev->data->scattered_rx = 1;
2438 : : }
2439 : : } else {
2440 : : /*
2441 : : * Use BSIZE field of the device RCTL register.
2442 : : */
2443 [ # # ]: 0 : if ((rctl_bsize == 0) || (rctl_bsize > buf_size))
2444 : : rctl_bsize = buf_size;
2445 [ # # ]: 0 : if (!dev->data->scattered_rx)
2446 : 0 : PMD_INIT_LOG(DEBUG, "forcing scatter mode");
2447 : 0 : dev->rx_pkt_burst = eth_igb_recv_scattered_pkts;
2448 : 0 : dev->data->scattered_rx = 1;
2449 : : }
2450 : :
2451 : : /* Set if packets are dropped when no descriptors available */
2452 [ # # ]: 0 : if (rxq->drop_en)
2453 : 0 : srrctl |= E1000_SRRCTL_DROP_EN;
2454 : :
2455 [ # # ]: 0 : E1000_WRITE_REG(hw, E1000_SRRCTL(rxq->reg_idx), srrctl);
2456 : :
2457 : : /* Enable this RX queue. */
2458 [ # # ]: 0 : rxdctl = E1000_READ_REG(hw, E1000_RXDCTL(rxq->reg_idx));
2459 : : rxdctl |= E1000_RXDCTL_QUEUE_ENABLE;
2460 : 0 : rxdctl &= 0xFFF00000;
2461 : 0 : rxdctl |= (rxq->pthresh & 0x1F);
2462 : 0 : rxdctl |= ((rxq->hthresh & 0x1F) << 8);
2463 : 0 : rxdctl |= ((rxq->wthresh & 0x1F) << 16);
2464 [ # # ]: 0 : E1000_WRITE_REG(hw, E1000_RXDCTL(rxq->reg_idx), rxdctl);
2465 : 0 : dev->data->rx_queue_state[i] = RTE_ETH_QUEUE_STATE_STARTED;
2466 : : }
2467 : :
2468 [ # # ]: 0 : if (dev->data->dev_conf.rxmode.offloads & RTE_ETH_RX_OFFLOAD_SCATTER) {
2469 [ # # ]: 0 : if (!dev->data->scattered_rx)
2470 : 0 : PMD_INIT_LOG(DEBUG, "forcing scatter mode");
2471 : 0 : dev->rx_pkt_burst = eth_igb_recv_scattered_pkts;
2472 : 0 : dev->data->scattered_rx = 1;
2473 : : }
2474 : :
2475 : : /*
2476 : : * Setup BSIZE field of RCTL register, if needed.
2477 : : * Buffer sizes >= 1024 are not [supposed to be] setup in the RCTL
2478 : : * register, since the code above configures the SRRCTL register of
2479 : : * the RX queue in such a case.
2480 : : * All configurable sizes are:
2481 : : * 16384: rctl |= (E1000_RCTL_SZ_16384 | E1000_RCTL_BSEX);
2482 : : * 8192: rctl |= (E1000_RCTL_SZ_8192 | E1000_RCTL_BSEX);
2483 : : * 4096: rctl |= (E1000_RCTL_SZ_4096 | E1000_RCTL_BSEX);
2484 : : * 2048: rctl |= E1000_RCTL_SZ_2048;
2485 : : * 1024: rctl |= E1000_RCTL_SZ_1024;
2486 : : * 512: rctl |= E1000_RCTL_SZ_512;
2487 : : * 256: rctl |= E1000_RCTL_SZ_256;
2488 : : */
2489 [ # # ]: 0 : if (rctl_bsize > 0) {
2490 [ # # ]: 0 : if (rctl_bsize >= 512) /* 512 <= buf_size < 1024 - use 512 */
2491 : 0 : rctl |= E1000_RCTL_SZ_512;
2492 : : else /* 256 <= buf_size < 512 - use 256 */
2493 : 0 : rctl |= E1000_RCTL_SZ_256;
2494 : : }
2495 : :
2496 : : /*
2497 : : * Configure RSS if device configured with multiple RX queues.
2498 : : */
2499 : 0 : igb_dev_mq_rx_configure(dev);
2500 : :
2501 : : /* Update the rctl since igb_dev_mq_rx_configure may change its value */
2502 : 0 : rctl |= E1000_READ_REG(hw, E1000_RCTL);
2503 : :
2504 : : /*
2505 : : * Setup the Checksum Register.
2506 : : * Receive Full-Packet Checksum Offload is mutually exclusive with RSS.
2507 : : */
2508 : 0 : rxcsum = E1000_READ_REG(hw, E1000_RXCSUM);
2509 : : rxcsum |= E1000_RXCSUM_PCSD;
2510 : :
2511 : : /* Enable both L3/L4 rx checksum offload */
2512 [ # # ]: 0 : if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_IPV4_CKSUM)
2513 : 0 : rxcsum |= E1000_RXCSUM_IPOFL;
2514 : : else
2515 : 0 : rxcsum &= ~E1000_RXCSUM_IPOFL;
2516 [ # # ]: 0 : if (rxmode->offloads &
2517 : : (RTE_ETH_RX_OFFLOAD_TCP_CKSUM | RTE_ETH_RX_OFFLOAD_UDP_CKSUM))
2518 : 0 : rxcsum |= E1000_RXCSUM_TUOFL;
2519 : : else
2520 : 0 : rxcsum &= ~E1000_RXCSUM_TUOFL;
2521 [ # # ]: 0 : if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_CHECKSUM)
2522 : 0 : rxcsum |= E1000_RXCSUM_CRCOFL;
2523 : : else
2524 : 0 : rxcsum &= ~E1000_RXCSUM_CRCOFL;
2525 : :
2526 : 0 : E1000_WRITE_REG(hw, E1000_RXCSUM, rxcsum);
2527 : :
2528 : : /* Setup the Receive Control Register. */
2529 [ # # ]: 0 : if (dev->data->dev_conf.rxmode.offloads & RTE_ETH_RX_OFFLOAD_KEEP_CRC) {
2530 : 0 : rctl &= ~E1000_RCTL_SECRC; /* Do not Strip Ethernet CRC. */
2531 : :
2532 : : /* clear STRCRC bit in all queues */
2533 [ # # ]: 0 : if (hw->mac.type == e1000_i350 ||
2534 [ # # ]: 0 : hw->mac.type == e1000_i210 ||
2535 [ # # ]: 0 : hw->mac.type == e1000_i211 ||
2536 : : hw->mac.type == e1000_i354) {
2537 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
2538 : 0 : rxq = dev->data->rx_queues[i];
2539 : 0 : uint32_t dvmolr = E1000_READ_REG(hw,
2540 : : E1000_DVMOLR(rxq->reg_idx));
2541 : 0 : dvmolr &= ~E1000_DVMOLR_STRCRC;
2542 : 0 : E1000_WRITE_REG(hw, E1000_DVMOLR(rxq->reg_idx), dvmolr);
2543 : : }
2544 : : }
2545 : : } else {
2546 : 0 : rctl |= E1000_RCTL_SECRC; /* Strip Ethernet CRC. */
2547 : :
2548 : : /* set STRCRC bit in all queues */
2549 [ # # ]: 0 : if (hw->mac.type == e1000_i350 ||
2550 [ # # ]: 0 : hw->mac.type == e1000_i210 ||
2551 [ # # ]: 0 : hw->mac.type == e1000_i211 ||
2552 : : hw->mac.type == e1000_i354) {
2553 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
2554 : 0 : rxq = dev->data->rx_queues[i];
2555 : 0 : uint32_t dvmolr = E1000_READ_REG(hw,
2556 : : E1000_DVMOLR(rxq->reg_idx));
2557 : 0 : dvmolr |= E1000_DVMOLR_STRCRC;
2558 : 0 : E1000_WRITE_REG(hw, E1000_DVMOLR(rxq->reg_idx), dvmolr);
2559 : : }
2560 : : }
2561 : : }
2562 : :
2563 : 0 : rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
2564 : 0 : rctl |= E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_LBM_NO |
2565 : : E1000_RCTL_RDMTS_HALF |
2566 : 0 : (hw->mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
2567 : :
2568 : : /* Make sure VLAN Filters are off. */
2569 [ # # ]: 0 : if (dev->data->dev_conf.rxmode.mq_mode != RTE_ETH_MQ_RX_VMDQ_ONLY)
2570 : 0 : rctl &= ~E1000_RCTL_VFE;
2571 : : /* Don't store bad packets. */
2572 : 0 : rctl &= ~E1000_RCTL_SBP;
2573 : :
2574 : : /* Enable Receives. */
2575 : 0 : E1000_WRITE_REG(hw, E1000_RCTL, rctl);
2576 : :
2577 : : /*
2578 : : * Setup the HW Rx Head and Tail Descriptor Pointers.
2579 : : * This needs to be done after enable.
2580 : : */
2581 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
2582 : 0 : rxq = dev->data->rx_queues[i];
2583 [ # # ]: 0 : E1000_WRITE_REG(hw, E1000_RDH(rxq->reg_idx), 0);
2584 [ # # ]: 0 : E1000_WRITE_REG(hw, E1000_RDT(rxq->reg_idx), rxq->nb_rx_desc - 1);
2585 : : }
2586 : :
2587 : : return 0;
2588 : : }
2589 : :
2590 : : /*********************************************************************
2591 : : *
2592 : : * Enable transmit unit.
2593 : : *
2594 : : **********************************************************************/
2595 : : void
2596 : 0 : eth_igb_tx_init(struct rte_eth_dev *dev)
2597 : : {
2598 : : struct e1000_hw *hw;
2599 : : struct igb_tx_queue *txq;
2600 : 0 : uint64_t offloads = dev->data->dev_conf.txmode.offloads;
2601 : : uint32_t tctl;
2602 : : uint32_t txdctl;
2603 : : uint16_t i;
2604 : : int err;
2605 : :
2606 : 0 : hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2607 : :
2608 : : /* Setup the Base and Length of the Tx Descriptor Rings. */
2609 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
2610 : : uint64_t bus_addr;
2611 : 0 : txq = dev->data->tx_queues[i];
2612 : 0 : bus_addr = txq->tx_ring_phys_addr;
2613 : :
2614 [ # # ]: 0 : E1000_WRITE_REG(hw, E1000_TDLEN(txq->reg_idx),
2615 : : txq->nb_tx_desc *
2616 : : sizeof(union e1000_adv_tx_desc));
2617 [ # # ]: 0 : E1000_WRITE_REG(hw, E1000_TDBAH(txq->reg_idx),
2618 : : (uint32_t)(bus_addr >> 32));
2619 [ # # ]: 0 : E1000_WRITE_REG(hw, E1000_TDBAL(txq->reg_idx), (uint32_t)bus_addr);
2620 : :
2621 : : /* Setup the HW Tx Head and Tail descriptor pointers. */
2622 [ # # ]: 0 : E1000_WRITE_REG(hw, E1000_TDT(txq->reg_idx), 0);
2623 [ # # ]: 0 : E1000_WRITE_REG(hw, E1000_TDH(txq->reg_idx), 0);
2624 : :
2625 : : /* Setup Transmit threshold registers. */
2626 [ # # ]: 0 : txdctl = E1000_READ_REG(hw, E1000_TXDCTL(txq->reg_idx));
2627 : 0 : txdctl |= txq->pthresh & 0x1F;
2628 : 0 : txdctl |= ((txq->hthresh & 0x1F) << 8);
2629 : 0 : txdctl |= ((txq->wthresh & 0x1F) << 16);
2630 : 0 : txdctl |= E1000_TXDCTL_QUEUE_ENABLE;
2631 [ # # ]: 0 : E1000_WRITE_REG(hw, E1000_TXDCTL(txq->reg_idx), txdctl);
2632 : 0 : dev->data->tx_queue_state[i] = RTE_ETH_QUEUE_STATE_STARTED;
2633 : : }
2634 : :
2635 [ # # ]: 0 : if (offloads & RTE_ETH_TX_OFFLOAD_SEND_ON_TIMESTAMP) {
2636 : 0 : err = rte_mbuf_dyn_tx_timestamp_register(
2637 : : &igb_tx_timestamp_dynfield_offset,
2638 : : &igb_tx_timestamp_dynflag);
2639 [ # # ]: 0 : if (err)
2640 : 0 : PMD_DRV_LOG(ERR, "Failed to register tx timestamp dynamic field");
2641 : : }
2642 : :
2643 : : /* Program the Transmit Control Register. */
2644 : 0 : tctl = E1000_READ_REG(hw, E1000_TCTL);
2645 : 0 : tctl &= ~E1000_TCTL_CT;
2646 : 0 : tctl |= (E1000_TCTL_PSP | E1000_TCTL_RTLC | E1000_TCTL_EN |
2647 : : (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT));
2648 : :
2649 : 0 : e1000_config_collision_dist(hw);
2650 : :
2651 : : /* This write will effectively turn on the transmit unit. */
2652 : 0 : E1000_WRITE_REG(hw, E1000_TCTL, tctl);
2653 : 0 : }
2654 : :
2655 : : /*********************************************************************
2656 : : *
2657 : : * Enable VF receive unit.
2658 : : *
2659 : : **********************************************************************/
2660 : : int
2661 : 0 : eth_igbvf_rx_init(struct rte_eth_dev *dev)
2662 : : {
2663 : : struct e1000_hw *hw;
2664 : : struct igb_rx_queue *rxq;
2665 : : uint32_t srrctl;
2666 : : uint16_t buf_size;
2667 : : uint16_t rctl_bsize;
2668 : : uint32_t max_len;
2669 : : uint16_t i;
2670 : : int ret;
2671 : :
2672 : 0 : hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2673 : :
2674 : : /* setup MTU */
2675 : 0 : max_len = dev->data->mtu + E1000_ETH_OVERHEAD;
2676 : 0 : e1000_rlpml_set_vf(hw, (uint16_t)(max_len + VLAN_TAG_SIZE));
2677 : :
2678 : : /* Configure and enable each RX queue. */
2679 : : rctl_bsize = 0;
2680 : 0 : dev->rx_pkt_burst = eth_igb_recv_pkts;
2681 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
2682 : : uint64_t bus_addr;
2683 : : uint32_t rxdctl;
2684 : :
2685 : 0 : rxq = dev->data->rx_queues[i];
2686 : :
2687 : 0 : rxq->flags = 0;
2688 : : /*
2689 : : * i350VF LB vlan packets have vlan tags byte swapped.
2690 : : */
2691 [ # # ]: 0 : if (hw->mac.type == e1000_vfadapt_i350) {
2692 : 0 : rxq->flags |= IGB_RXQ_FLAG_LB_BSWAP_VLAN;
2693 : 0 : PMD_INIT_LOG(DEBUG, "IGB rx vlan bswap required");
2694 : : } else {
2695 : 0 : PMD_INIT_LOG(DEBUG, "IGB rx vlan bswap not required");
2696 : : }
2697 : :
2698 : : /* Allocate buffers for descriptor rings and set up queue */
2699 : 0 : ret = igb_alloc_rx_queue_mbufs(rxq);
2700 [ # # ]: 0 : if (ret)
2701 : 0 : return ret;
2702 : :
2703 : 0 : bus_addr = rxq->rx_ring_phys_addr;
2704 [ # # ]: 0 : E1000_WRITE_REG(hw, E1000_RDLEN(i),
2705 : : rxq->nb_rx_desc *
2706 : : sizeof(union e1000_adv_rx_desc));
2707 [ # # ]: 0 : E1000_WRITE_REG(hw, E1000_RDBAH(i),
2708 : : (uint32_t)(bus_addr >> 32));
2709 [ # # ]: 0 : E1000_WRITE_REG(hw, E1000_RDBAL(i), (uint32_t)bus_addr);
2710 : :
2711 : : srrctl = E1000_SRRCTL_DESCTYPE_ADV_ONEBUF;
2712 : :
2713 : : /*
2714 : : * Configure RX buffer size.
2715 : : */
2716 [ # # ]: 0 : buf_size = (uint16_t)(rte_pktmbuf_data_room_size(rxq->mb_pool) -
2717 : : RTE_PKTMBUF_HEADROOM);
2718 [ # # ]: 0 : if (buf_size >= 1024) {
2719 : : /*
2720 : : * Configure the BSIZEPACKET field of the SRRCTL
2721 : : * register of the queue.
2722 : : * Value is in 1 KB resolution, from 1 KB to 127 KB.
2723 : : * If this field is equal to 0b, then RCTL.BSIZE
2724 : : * determines the RX packet buffer size.
2725 : : */
2726 : 0 : srrctl |= ((buf_size >> E1000_SRRCTL_BSIZEPKT_SHIFT) &
2727 : : E1000_SRRCTL_BSIZEPKT_MASK);
2728 : 0 : buf_size = (uint16_t) ((srrctl &
2729 : : E1000_SRRCTL_BSIZEPKT_MASK) <<
2730 : : E1000_SRRCTL_BSIZEPKT_SHIFT);
2731 : :
2732 : : /* It adds dual VLAN length for supporting dual VLAN */
2733 [ # # ]: 0 : if ((max_len + 2 * VLAN_TAG_SIZE) > buf_size) {
2734 [ # # ]: 0 : if (!dev->data->scattered_rx)
2735 : 0 : PMD_INIT_LOG(DEBUG,
2736 : : "forcing scatter mode");
2737 : 0 : dev->rx_pkt_burst = eth_igb_recv_scattered_pkts;
2738 : 0 : dev->data->scattered_rx = 1;
2739 : : }
2740 : : } else {
2741 : : /*
2742 : : * Use BSIZE field of the device RCTL register.
2743 : : */
2744 : : if ((rctl_bsize == 0) || (rctl_bsize > buf_size))
2745 : : rctl_bsize = buf_size;
2746 [ # # ]: 0 : if (!dev->data->scattered_rx)
2747 : 0 : PMD_INIT_LOG(DEBUG, "forcing scatter mode");
2748 : 0 : dev->rx_pkt_burst = eth_igb_recv_scattered_pkts;
2749 : 0 : dev->data->scattered_rx = 1;
2750 : : }
2751 : :
2752 : : /* Set if packets are dropped when no descriptors available */
2753 [ # # ]: 0 : if (rxq->drop_en)
2754 : 0 : srrctl |= E1000_SRRCTL_DROP_EN;
2755 : :
2756 [ # # ]: 0 : E1000_WRITE_REG(hw, E1000_SRRCTL(i), srrctl);
2757 : :
2758 : : /* Enable this RX queue. */
2759 [ # # ]: 0 : rxdctl = E1000_READ_REG(hw, E1000_RXDCTL(i));
2760 : : rxdctl |= E1000_RXDCTL_QUEUE_ENABLE;
2761 : 0 : rxdctl &= 0xFFF00000;
2762 : 0 : rxdctl |= (rxq->pthresh & 0x1F);
2763 : 0 : rxdctl |= ((rxq->hthresh & 0x1F) << 8);
2764 [ # # ]: 0 : if (hw->mac.type == e1000_vfadapt) {
2765 : : /*
2766 : : * Workaround of 82576 VF Erratum
2767 : : * force set WTHRESH to 1
2768 : : * to avoid Write-Back not triggered sometimes
2769 : : */
2770 : 0 : rxdctl |= 0x10000;
2771 : 0 : PMD_INIT_LOG(DEBUG, "Force set RX WTHRESH to 1 !");
2772 : : }
2773 : : else
2774 : 0 : rxdctl |= ((rxq->wthresh & 0x1F) << 16);
2775 : 0 : E1000_WRITE_REG(hw, E1000_RXDCTL(i), rxdctl);
2776 : :
2777 : 0 : dev->data->rx_queue_state[i] = RTE_ETH_QUEUE_STATE_STARTED;
2778 : : }
2779 : :
2780 [ # # ]: 0 : if (dev->data->dev_conf.rxmode.offloads & RTE_ETH_RX_OFFLOAD_SCATTER) {
2781 [ # # ]: 0 : if (!dev->data->scattered_rx)
2782 : 0 : PMD_INIT_LOG(DEBUG, "forcing scatter mode");
2783 : 0 : dev->rx_pkt_burst = eth_igb_recv_scattered_pkts;
2784 : 0 : dev->data->scattered_rx = 1;
2785 : : }
2786 : :
2787 : : /*
2788 : : * Setup the HW Rx Head and Tail Descriptor Pointers.
2789 : : * This needs to be done after enable.
2790 : : */
2791 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
2792 : 0 : rxq = dev->data->rx_queues[i];
2793 [ # # ]: 0 : E1000_WRITE_REG(hw, E1000_RDH(i), 0);
2794 [ # # ]: 0 : E1000_WRITE_REG(hw, E1000_RDT(i), rxq->nb_rx_desc - 1);
2795 : : }
2796 : :
2797 : : return 0;
2798 : : }
2799 : :
2800 : : /*********************************************************************
2801 : : *
2802 : : * Enable VF transmit unit.
2803 : : *
2804 : : **********************************************************************/
2805 : : void
2806 : 0 : eth_igbvf_tx_init(struct rte_eth_dev *dev)
2807 : : {
2808 : : struct e1000_hw *hw;
2809 : : struct igb_tx_queue *txq;
2810 : : uint32_t txdctl;
2811 : : uint16_t i;
2812 : :
2813 : 0 : hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2814 : :
2815 : : /* Setup the Base and Length of the Tx Descriptor Rings. */
2816 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
2817 : : uint64_t bus_addr;
2818 : :
2819 : 0 : txq = dev->data->tx_queues[i];
2820 : 0 : bus_addr = txq->tx_ring_phys_addr;
2821 [ # # ]: 0 : E1000_WRITE_REG(hw, E1000_TDLEN(i),
2822 : : txq->nb_tx_desc *
2823 : : sizeof(union e1000_adv_tx_desc));
2824 [ # # ]: 0 : E1000_WRITE_REG(hw, E1000_TDBAH(i),
2825 : : (uint32_t)(bus_addr >> 32));
2826 [ # # ]: 0 : E1000_WRITE_REG(hw, E1000_TDBAL(i), (uint32_t)bus_addr);
2827 : :
2828 : : /* Setup the HW Tx Head and Tail descriptor pointers. */
2829 [ # # ]: 0 : E1000_WRITE_REG(hw, E1000_TDT(i), 0);
2830 [ # # ]: 0 : E1000_WRITE_REG(hw, E1000_TDH(i), 0);
2831 : :
2832 : : /* Setup Transmit threshold registers. */
2833 [ # # ]: 0 : txdctl = E1000_READ_REG(hw, E1000_TXDCTL(i));
2834 : 0 : txdctl |= txq->pthresh & 0x1F;
2835 : 0 : txdctl |= ((txq->hthresh & 0x1F) << 8);
2836 [ # # ]: 0 : if (hw->mac.type == e1000_82576) {
2837 : : /*
2838 : : * Workaround of 82576 VF Erratum
2839 : : * force set WTHRESH to 1
2840 : : * to avoid Write-Back not triggered sometimes
2841 : : */
2842 : 0 : txdctl |= 0x10000;
2843 : 0 : PMD_INIT_LOG(DEBUG, "Force set TX WTHRESH to 1 !");
2844 : : }
2845 : : else
2846 : 0 : txdctl |= ((txq->wthresh & 0x1F) << 16);
2847 : 0 : txdctl |= E1000_TXDCTL_QUEUE_ENABLE;
2848 : 0 : E1000_WRITE_REG(hw, E1000_TXDCTL(i), txdctl);
2849 : :
2850 : 0 : dev->data->tx_queue_state[i] = RTE_ETH_QUEUE_STATE_STARTED;
2851 : : }
2852 : :
2853 : 0 : }
2854 : :
2855 : : void
2856 : 0 : igb_rxq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
2857 : : struct rte_eth_rxq_info *qinfo)
2858 : : {
2859 : : struct igb_rx_queue *rxq;
2860 : :
2861 : 0 : rxq = dev->data->rx_queues[queue_id];
2862 : :
2863 : 0 : qinfo->mp = rxq->mb_pool;
2864 : 0 : qinfo->scattered_rx = dev->data->scattered_rx;
2865 : 0 : qinfo->nb_desc = rxq->nb_rx_desc;
2866 : :
2867 : 0 : qinfo->conf.rx_free_thresh = rxq->rx_free_thresh;
2868 : 0 : qinfo->conf.rx_drop_en = rxq->drop_en;
2869 : 0 : qinfo->conf.offloads = rxq->offloads;
2870 : 0 : }
2871 : :
2872 : : void
2873 : 0 : igb_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
2874 : : struct rte_eth_txq_info *qinfo)
2875 : : {
2876 : : struct igb_tx_queue *txq;
2877 : :
2878 : 0 : txq = dev->data->tx_queues[queue_id];
2879 : :
2880 : 0 : qinfo->nb_desc = txq->nb_tx_desc;
2881 : :
2882 : 0 : qinfo->conf.tx_thresh.pthresh = txq->pthresh;
2883 : 0 : qinfo->conf.tx_thresh.hthresh = txq->hthresh;
2884 : 0 : qinfo->conf.tx_thresh.wthresh = txq->wthresh;
2885 : 0 : qinfo->conf.offloads = txq->offloads;
2886 : 0 : }
2887 : :
2888 : : int
2889 : 0 : igb_rss_conf_init(struct rte_eth_dev *dev,
2890 : : struct igb_rte_flow_rss_conf *out,
2891 : : const struct rte_flow_action_rss *in)
2892 : : {
2893 : 0 : struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2894 : :
2895 [ # # ]: 0 : if (in->key_len > RTE_DIM(out->key) ||
2896 [ # # ]: 0 : ((hw->mac.type == e1000_82576) &&
2897 [ # # # # ]: 0 : (in->queue_num > IGB_MAX_RX_QUEUE_NUM_82576)) ||
2898 : 0 : ((hw->mac.type != e1000_82576) &&
2899 [ # # ]: 0 : (in->queue_num > IGB_MAX_RX_QUEUE_NUM)))
2900 : : return -EINVAL;
2901 : 0 : out->conf = (struct rte_flow_action_rss){
2902 : 0 : .func = in->func,
2903 : 0 : .level = in->level,
2904 : 0 : .types = in->types,
2905 : : .key_len = in->key_len,
2906 : 0 : .queue_num = in->queue_num,
2907 : 0 : .key = memcpy(out->key, in->key, in->key_len),
2908 : 0 : .queue = memcpy(out->queue, in->queue,
2909 : 0 : sizeof(*in->queue) * in->queue_num),
2910 : : };
2911 : 0 : return 0;
2912 : : }
2913 : :
2914 : : int
2915 : 0 : igb_action_rss_same(const struct rte_flow_action_rss *comp,
2916 : : const struct rte_flow_action_rss *with)
2917 : : {
2918 : 0 : return (comp->func == with->func &&
2919 : 0 : comp->level == with->level &&
2920 [ # # ]: 0 : comp->types == with->types &&
2921 [ # # ]: 0 : comp->key_len == with->key_len &&
2922 : 0 : comp->queue_num == with->queue_num &&
2923 [ # # # # ]: 0 : !memcmp(comp->key, with->key, with->key_len) &&
2924 : 0 : !memcmp(comp->queue, with->queue,
2925 [ # # ]: 0 : sizeof(*with->queue) * with->queue_num));
2926 : : }
2927 : :
2928 : : int
2929 : 0 : igb_config_rss_filter(struct rte_eth_dev *dev,
2930 : : struct igb_rte_flow_rss_conf *conf, bool add)
2931 : : {
2932 : : uint32_t shift;
2933 : : uint16_t i, j;
2934 : 0 : struct rte_eth_rss_conf rss_conf = {
2935 : 0 : .rss_key = conf->conf.key_len ?
2936 [ # # ]: 0 : (void *)(uintptr_t)conf->conf.key : NULL,
2937 : : .rss_key_len = conf->conf.key_len,
2938 : 0 : .rss_hf = conf->conf.types,
2939 : : };
2940 : : struct e1000_filter_info *filter_info =
2941 : 0 : E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
2942 : 0 : struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2943 : :
2944 : : hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2945 : :
2946 [ # # ]: 0 : if (!add) {
2947 [ # # ]: 0 : if (igb_action_rss_same(&filter_info->rss_info.conf,
2948 : 0 : &conf->conf)) {
2949 : : igb_rss_disable(dev);
2950 : 0 : memset(&filter_info->rss_info, 0,
2951 : : sizeof(struct igb_rte_flow_rss_conf));
2952 : 0 : return 0;
2953 : : }
2954 : : return -EINVAL;
2955 : : }
2956 : :
2957 [ # # ]: 0 : if (filter_info->rss_info.conf.queue_num)
2958 : : return -EINVAL;
2959 : :
2960 : : /* Fill in redirection table. */
2961 [ # # ]: 0 : shift = (hw->mac.type == e1000_82575) ? 6 : 0;
2962 [ # # ]: 0 : for (i = 0, j = 0; i < 128; i++, j++) {
2963 : : union e1000_reta {
2964 : : uint32_t dword;
2965 : : uint8_t bytes[4];
2966 : : } reta;
2967 : : uint8_t q_idx;
2968 : :
2969 [ # # ]: 0 : if (j == conf->conf.queue_num)
2970 : : j = 0;
2971 : 0 : q_idx = conf->conf.queue[j];
2972 : 0 : reta.bytes[i & 3] = (uint8_t)(q_idx << shift);
2973 [ # # ]: 0 : if ((i & 3) == 3)
2974 : 0 : E1000_WRITE_REG(hw, E1000_RETA(i >> 2), reta.dword);
2975 : : }
2976 : :
2977 : : /* Configure the RSS key and the RSS protocols used to compute
2978 : : * the RSS hash of input packets.
2979 : : */
2980 [ # # ]: 0 : if ((rss_conf.rss_hf & IGB_RSS_OFFLOAD_ALL) == 0) {
2981 : : igb_rss_disable(dev);
2982 : 0 : return 0;
2983 : : }
2984 [ # # ]: 0 : if (rss_conf.rss_key == NULL)
2985 : 0 : rss_conf.rss_key = rss_intel_key; /* Default hash key */
2986 : 0 : igb_hw_rss_hash_set(hw, &rss_conf);
2987 : :
2988 [ # # ]: 0 : if (igb_rss_conf_init(dev, &filter_info->rss_info, &conf->conf))
2989 : 0 : return -EINVAL;
2990 : :
2991 : : return 0;
2992 : : }
|