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_memcpy.h>
23 : : #include <rte_memzone.h>
24 : : #include <rte_launch.h>
25 : : #include <rte_eal.h>
26 : : #include <rte_per_lcore.h>
27 : : #include <rte_lcore.h>
28 : : #include <rte_atomic.h>
29 : : #include <rte_branch_prediction.h>
30 : : #include <rte_mempool.h>
31 : : #include <rte_malloc.h>
32 : : #include <rte_mbuf.h>
33 : : #include <rte_ether.h>
34 : : #include <ethdev_driver.h>
35 : : #include <rte_prefetch.h>
36 : : #include <rte_udp.h>
37 : : #include <rte_tcp.h>
38 : : #include <rte_sctp.h>
39 : : #include <rte_net.h>
40 : : #include <rte_string_fns.h>
41 : :
42 : : #include "e1000_logs.h"
43 : : #include "base/e1000_api.h"
44 : : #include "e1000_ethdev.h"
45 : :
46 : : #ifdef RTE_LIBRTE_IEEE1588
47 : : #define IGB_TX_IEEE1588_TMST RTE_MBUF_F_TX_IEEE1588_TMST
48 : : #else
49 : : #define IGB_TX_IEEE1588_TMST 0
50 : : #endif
51 : : /* Bit Mask to indicate what bits required for building TX context */
52 : : #define IGB_TX_OFFLOAD_MASK (RTE_MBUF_F_TX_OUTER_IPV6 | \
53 : : RTE_MBUF_F_TX_OUTER_IPV4 | \
54 : : RTE_MBUF_F_TX_IPV6 | \
55 : : RTE_MBUF_F_TX_IPV4 | \
56 : : RTE_MBUF_F_TX_VLAN | \
57 : : RTE_MBUF_F_TX_IP_CKSUM | \
58 : : RTE_MBUF_F_TX_L4_MASK | \
59 : : RTE_MBUF_F_TX_TCP_SEG | \
60 : : IGB_TX_IEEE1588_TMST)
61 : :
62 : : #define IGB_TX_OFFLOAD_NOTSUP_MASK \
63 : : (RTE_MBUF_F_TX_OFFLOAD_MASK ^ IGB_TX_OFFLOAD_MASK)
64 : :
65 : : /**
66 : : * Structure associated with each descriptor of the RX ring of a RX queue.
67 : : */
68 : : struct igb_rx_entry {
69 : : struct rte_mbuf *mbuf; /**< mbuf associated with RX descriptor. */
70 : : };
71 : :
72 : : /**
73 : : * Structure associated with each descriptor of the TX ring of a TX queue.
74 : : */
75 : : struct igb_tx_entry {
76 : : struct rte_mbuf *mbuf; /**< mbuf associated with TX desc, if any. */
77 : : uint16_t next_id; /**< Index of next descriptor in ring. */
78 : : uint16_t last_id; /**< Index of last scattered descriptor. */
79 : : };
80 : :
81 : : /**
82 : : * rx queue flags
83 : : */
84 : : enum igb_rxq_flags {
85 : : IGB_RXQ_FLAG_LB_BSWAP_VLAN = 0x01,
86 : : };
87 : :
88 : : /**
89 : : * Structure associated with each RX queue.
90 : : */
91 : : struct igb_rx_queue {
92 : : struct rte_mempool *mb_pool; /**< mbuf pool to populate RX ring. */
93 : : volatile union e1000_adv_rx_desc *rx_ring; /**< RX ring virtual address. */
94 : : uint64_t rx_ring_phys_addr; /**< RX ring DMA address. */
95 : : volatile uint32_t *rdt_reg_addr; /**< RDT register address. */
96 : : volatile uint32_t *rdh_reg_addr; /**< RDH register address. */
97 : : struct igb_rx_entry *sw_ring; /**< address of RX software ring. */
98 : : struct rte_mbuf *pkt_first_seg; /**< First segment of current packet. */
99 : : struct rte_mbuf *pkt_last_seg; /**< Last segment of current packet. */
100 : : uint16_t nb_rx_desc; /**< number of RX descriptors. */
101 : : uint16_t rx_tail; /**< current value of RDT register. */
102 : : uint16_t nb_rx_hold; /**< number of held free RX desc. */
103 : : uint16_t rx_free_thresh; /**< max free RX desc to hold. */
104 : : uint16_t queue_id; /**< RX queue index. */
105 : : uint16_t reg_idx; /**< RX queue register index. */
106 : : uint16_t port_id; /**< Device port identifier. */
107 : : uint8_t pthresh; /**< Prefetch threshold register. */
108 : : uint8_t hthresh; /**< Host threshold register. */
109 : : uint8_t wthresh; /**< Write-back threshold register. */
110 : : uint8_t crc_len; /**< 0 if CRC stripped, 4 otherwise. */
111 : : uint8_t drop_en; /**< If not 0, set SRRCTL.Drop_En. */
112 : : uint32_t flags; /**< RX flags. */
113 : : uint64_t offloads; /**< offloads of RTE_ETH_RX_OFFLOAD_* */
114 : : const struct rte_memzone *mz;
115 : : };
116 : :
117 : : /**
118 : : * Hardware context number
119 : : */
120 : : enum igb_advctx_num {
121 : : IGB_CTX_0 = 0, /**< CTX0 */
122 : : IGB_CTX_1 = 1, /**< CTX1 */
123 : : IGB_CTX_NUM = 2, /**< CTX_NUM */
124 : : };
125 : :
126 : : /** Offload features */
127 : : union igb_tx_offload {
128 : : uint64_t data;
129 : : struct {
130 : : uint64_t l3_len:9; /**< L3 (IP) Header Length. */
131 : : uint64_t l2_len:7; /**< L2 (MAC) Header Length. */
132 : : uint64_t vlan_tci:16; /**< VLAN Tag Control Identifier(CPU order). */
133 : : uint64_t l4_len:8; /**< L4 (TCP/UDP) Header Length. */
134 : : uint64_t tso_segsz:16; /**< TCP TSO segment size. */
135 : :
136 : : /* uint64_t unused:8; */
137 : : };
138 : : };
139 : :
140 : : /*
141 : : * Compare mask for igb_tx_offload.data,
142 : : * should be in sync with igb_tx_offload layout.
143 : : * */
144 : : #define TX_MACIP_LEN_CMP_MASK 0x000000000000FFFFULL /**< L2L3 header mask. */
145 : : #define TX_VLAN_CMP_MASK 0x00000000FFFF0000ULL /**< Vlan mask. */
146 : : #define TX_TCP_LEN_CMP_MASK 0x000000FF00000000ULL /**< TCP header mask. */
147 : : #define TX_TSO_MSS_CMP_MASK 0x00FFFF0000000000ULL /**< TSO segsz mask. */
148 : : /** Mac + IP + TCP + Mss mask. */
149 : : #define TX_TSO_CMP_MASK \
150 : : (TX_MACIP_LEN_CMP_MASK | TX_TCP_LEN_CMP_MASK | TX_TSO_MSS_CMP_MASK)
151 : :
152 : : /**
153 : : * Structure to check if new context need be built
154 : : */
155 : : struct igb_advctx_info {
156 : : uint64_t flags; /**< ol_flags related to context build. */
157 : : /** tx offload: vlan, tso, l2-l3-l4 lengths. */
158 : : union igb_tx_offload tx_offload;
159 : : /** compare mask for tx offload. */
160 : : union igb_tx_offload tx_offload_mask;
161 : : };
162 : :
163 : : /**
164 : : * Structure associated with each TX queue.
165 : : */
166 : : struct igb_tx_queue {
167 : : volatile union e1000_adv_tx_desc *tx_ring; /**< TX ring address */
168 : : uint64_t tx_ring_phys_addr; /**< TX ring DMA address. */
169 : : struct igb_tx_entry *sw_ring; /**< virtual address of SW ring. */
170 : : volatile uint32_t *tdt_reg_addr; /**< Address of TDT register. */
171 : : uint32_t txd_type; /**< Device-specific TXD type */
172 : : uint16_t nb_tx_desc; /**< number of TX descriptors. */
173 : : uint16_t tx_tail; /**< Current value of TDT register. */
174 : : uint16_t tx_head;
175 : : /**< Index of first used TX descriptor. */
176 : : uint16_t queue_id; /**< TX queue index. */
177 : : uint16_t reg_idx; /**< TX queue register index. */
178 : : uint16_t port_id; /**< Device port identifier. */
179 : : uint8_t pthresh; /**< Prefetch threshold register. */
180 : : uint8_t hthresh; /**< Host threshold register. */
181 : : uint8_t wthresh; /**< Write-back threshold register. */
182 : : uint32_t ctx_curr;
183 : : /**< Current used hardware descriptor. */
184 : : uint32_t ctx_start;
185 : : /**< Start context position for transmit queue. */
186 : : struct igb_advctx_info ctx_cache[IGB_CTX_NUM];
187 : : /**< Hardware context history.*/
188 : : uint64_t offloads; /**< offloads of RTE_ETH_TX_OFFLOAD_* */
189 : : const struct rte_memzone *mz;
190 : : };
191 : :
192 : : #if 1
193 : : #define RTE_PMD_USE_PREFETCH
194 : : #endif
195 : :
196 : : #ifdef RTE_PMD_USE_PREFETCH
197 : : #define rte_igb_prefetch(p) rte_prefetch0(p)
198 : : #else
199 : : #define rte_igb_prefetch(p) do {} while(0)
200 : : #endif
201 : :
202 : : #ifdef RTE_PMD_PACKET_PREFETCH
203 : : #define rte_packet_prefetch(p) rte_prefetch1(p)
204 : : #else
205 : : #define rte_packet_prefetch(p) do {} while(0)
206 : : #endif
207 : :
208 : : /*
209 : : * Macro for VMDq feature for 1 GbE NIC.
210 : : */
211 : : #define E1000_VMOLR_SIZE (8)
212 : : #define IGB_TSO_MAX_HDRLEN (512)
213 : : #define IGB_TSO_MAX_MSS (9216)
214 : :
215 : : /*********************************************************************
216 : : *
217 : : * TX function
218 : : *
219 : : **********************************************************************/
220 : :
221 : : /*
222 : : *There're some limitations in hardware for TCP segmentation offload. We
223 : : *should check whether the parameters are valid.
224 : : */
225 : : static inline uint64_t
226 : : check_tso_para(uint64_t ol_req, union igb_tx_offload ol_para)
227 : : {
228 : 0 : if (!(ol_req & RTE_MBUF_F_TX_TCP_SEG))
229 : : return ol_req;
230 [ # # ]: 0 : if ((ol_para.tso_segsz > IGB_TSO_MAX_MSS) || (ol_para.l2_len +
231 [ # # ]: 0 : ol_para.l3_len + ol_para.l4_len > IGB_TSO_MAX_HDRLEN)) {
232 : 0 : ol_req &= ~RTE_MBUF_F_TX_TCP_SEG;
233 : 0 : ol_req |= RTE_MBUF_F_TX_TCP_CKSUM;
234 : : }
235 : : return ol_req;
236 : : }
237 : :
238 : : /*
239 : : * Advanced context descriptor are almost same between igb/ixgbe
240 : : * This is a separate function, looking for optimization opportunity here
241 : : * Rework required to go with the pre-defined values.
242 : : */
243 : :
244 : : static inline void
245 : 0 : igbe_set_xmit_ctx(struct igb_tx_queue* txq,
246 : : volatile struct e1000_adv_tx_context_desc *ctx_txd,
247 : : uint64_t ol_flags, union igb_tx_offload tx_offload, uint64_t txtime)
248 : : {
249 : : uint32_t type_tucmd_mlhl;
250 : : uint32_t mss_l4len_idx;
251 : : uint32_t ctx_idx, ctx_curr;
252 : : uint32_t vlan_macip_lens;
253 : : uint32_t launch_time;
254 : : union igb_tx_offload tx_offload_mask;
255 : :
256 : 0 : ctx_curr = txq->ctx_curr;
257 : 0 : ctx_idx = ctx_curr + txq->ctx_start;
258 : :
259 : : tx_offload_mask.data = 0;
260 : : type_tucmd_mlhl = 0;
261 : :
262 : : /* Specify which HW CTX to upload. */
263 : 0 : mss_l4len_idx = (ctx_idx << E1000_ADVTXD_IDX_SHIFT);
264 : :
265 [ # # ]: 0 : if (ol_flags & RTE_MBUF_F_TX_VLAN)
266 : : tx_offload_mask.data |= TX_VLAN_CMP_MASK;
267 : :
268 : : /* check if TCP segmentation required for this packet */
269 [ # # ]: 0 : if (ol_flags & RTE_MBUF_F_TX_TCP_SEG) {
270 : : /* implies IP cksum in IPv4 */
271 [ # # ]: 0 : if (ol_flags & RTE_MBUF_F_TX_IP_CKSUM)
272 : : type_tucmd_mlhl = E1000_ADVTXD_TUCMD_IPV4 |
273 : : E1000_ADVTXD_TUCMD_L4T_TCP |
274 : : E1000_ADVTXD_DTYP_CTXT | E1000_ADVTXD_DCMD_DEXT;
275 : : else
276 : : type_tucmd_mlhl = E1000_ADVTXD_TUCMD_IPV6 |
277 : : E1000_ADVTXD_TUCMD_L4T_TCP |
278 : : E1000_ADVTXD_DTYP_CTXT | E1000_ADVTXD_DCMD_DEXT;
279 : :
280 : 0 : tx_offload_mask.data |= TX_TSO_CMP_MASK;
281 : 0 : mss_l4len_idx |= tx_offload.tso_segsz << E1000_ADVTXD_MSS_SHIFT;
282 : 0 : mss_l4len_idx |= tx_offload.l4_len << E1000_ADVTXD_L4LEN_SHIFT;
283 : : } else { /* no TSO, check if hardware checksum is needed */
284 [ # # ]: 0 : if (ol_flags & (RTE_MBUF_F_TX_IP_CKSUM | RTE_MBUF_F_TX_L4_MASK))
285 : 0 : tx_offload_mask.data |= TX_MACIP_LEN_CMP_MASK;
286 : :
287 [ # # ]: 0 : if (ol_flags & RTE_MBUF_F_TX_IP_CKSUM)
288 : : type_tucmd_mlhl = E1000_ADVTXD_TUCMD_IPV4;
289 : :
290 [ # # # # ]: 0 : switch (ol_flags & RTE_MBUF_F_TX_L4_MASK) {
291 : 0 : case RTE_MBUF_F_TX_UDP_CKSUM:
292 : 0 : type_tucmd_mlhl |= E1000_ADVTXD_TUCMD_L4T_UDP |
293 : : E1000_ADVTXD_DTYP_CTXT | E1000_ADVTXD_DCMD_DEXT;
294 : 0 : mss_l4len_idx |= sizeof(struct rte_udp_hdr)
295 : : << E1000_ADVTXD_L4LEN_SHIFT;
296 : 0 : break;
297 : 0 : case RTE_MBUF_F_TX_TCP_CKSUM:
298 : 0 : type_tucmd_mlhl |= E1000_ADVTXD_TUCMD_L4T_TCP |
299 : : E1000_ADVTXD_DTYP_CTXT | E1000_ADVTXD_DCMD_DEXT;
300 : 0 : mss_l4len_idx |= sizeof(struct rte_tcp_hdr)
301 : : << E1000_ADVTXD_L4LEN_SHIFT;
302 : 0 : break;
303 : 0 : case RTE_MBUF_F_TX_SCTP_CKSUM:
304 : 0 : type_tucmd_mlhl |= E1000_ADVTXD_TUCMD_L4T_SCTP |
305 : : E1000_ADVTXD_DTYP_CTXT | E1000_ADVTXD_DCMD_DEXT;
306 : 0 : mss_l4len_idx |= sizeof(struct rte_sctp_hdr)
307 : : << E1000_ADVTXD_L4LEN_SHIFT;
308 : 0 : break;
309 : 0 : default:
310 : 0 : type_tucmd_mlhl |= E1000_ADVTXD_TUCMD_L4T_RSV |
311 : : E1000_ADVTXD_DTYP_CTXT | E1000_ADVTXD_DCMD_DEXT;
312 : 0 : break;
313 : : }
314 : : }
315 : :
316 [ # # ]: 0 : if (!txtime) {
317 : 0 : txq->ctx_cache[ctx_curr].flags = ol_flags;
318 : 0 : txq->ctx_cache[ctx_curr].tx_offload.data =
319 : 0 : tx_offload_mask.data & tx_offload.data;
320 : 0 : txq->ctx_cache[ctx_curr].tx_offload_mask = tx_offload_mask;
321 : : }
322 : :
323 : 0 : ctx_txd->type_tucmd_mlhl = rte_cpu_to_le_32(type_tucmd_mlhl);
324 : 0 : vlan_macip_lens = (uint32_t)tx_offload.data;
325 : 0 : ctx_txd->vlan_macip_lens = rte_cpu_to_le_32(vlan_macip_lens);
326 : 0 : ctx_txd->mss_l4len_idx = rte_cpu_to_le_32(mss_l4len_idx);
327 : 0 : ctx_txd->u.seqnum_seed = 0;
328 : :
329 [ # # ]: 0 : if (txtime) {
330 : 0 : launch_time = (txtime - IGB_I210_TX_OFFSET_BASE) % NSEC_PER_SEC;
331 : 0 : ctx_txd->u.launch_time = rte_cpu_to_le_32(launch_time / 32);
332 : : } else {
333 : 0 : ctx_txd->u.launch_time = 0;
334 : : }
335 : 0 : }
336 : :
337 : : /*
338 : : * Check which hardware context can be used. Use the existing match
339 : : * or create a new context descriptor.
340 : : */
341 : : static inline uint32_t
342 : 0 : what_advctx_update(struct igb_tx_queue *txq, uint64_t flags,
343 : : union igb_tx_offload tx_offload)
344 : : {
345 : : /* If match with the current context */
346 [ # # # # ]: 0 : if (likely((txq->ctx_cache[txq->ctx_curr].flags == flags) &&
347 : : (txq->ctx_cache[txq->ctx_curr].tx_offload.data ==
348 : : (txq->ctx_cache[txq->ctx_curr].tx_offload_mask.data & tx_offload.data)))) {
349 : : return txq->ctx_curr;
350 : : }
351 : :
352 : : /* If match with the second context */
353 : 0 : txq->ctx_curr ^= 1;
354 [ # # # # ]: 0 : if (likely((txq->ctx_cache[txq->ctx_curr].flags == flags) &&
355 : : (txq->ctx_cache[txq->ctx_curr].tx_offload.data ==
356 : : (txq->ctx_cache[txq->ctx_curr].tx_offload_mask.data & tx_offload.data)))) {
357 : 0 : return txq->ctx_curr;
358 : : }
359 : :
360 : : /* Mismatch, use the previous context */
361 : : return IGB_CTX_NUM;
362 : : }
363 : :
364 : : static inline uint32_t
365 : : tx_desc_cksum_flags_to_olinfo(uint64_t ol_flags)
366 : : {
367 : : static const uint32_t l4_olinfo[2] = {0, E1000_ADVTXD_POPTS_TXSM};
368 : : static const uint32_t l3_olinfo[2] = {0, E1000_ADVTXD_POPTS_IXSM};
369 : : uint32_t tmp;
370 : :
371 : 0 : tmp = l4_olinfo[(ol_flags & RTE_MBUF_F_TX_L4_MASK) != RTE_MBUF_F_TX_L4_NO_CKSUM];
372 : 0 : tmp |= l3_olinfo[(ol_flags & RTE_MBUF_F_TX_IP_CKSUM) != 0];
373 : 0 : tmp |= l4_olinfo[(ol_flags & RTE_MBUF_F_TX_TCP_SEG) != 0];
374 : : return tmp;
375 : : }
376 : :
377 : : static inline uint32_t
378 : : tx_desc_vlan_flags_to_cmdtype(uint64_t ol_flags)
379 : : {
380 : : uint32_t cmdtype;
381 : : static uint32_t vlan_cmd[2] = {0, E1000_ADVTXD_DCMD_VLE};
382 : : static uint32_t tso_cmd[2] = {0, E1000_ADVTXD_DCMD_TSE};
383 : 0 : cmdtype = vlan_cmd[(ol_flags & RTE_MBUF_F_TX_VLAN) != 0];
384 : 0 : cmdtype |= tso_cmd[(ol_flags & RTE_MBUF_F_TX_TCP_SEG) != 0];
385 : : return cmdtype;
386 : : }
387 : :
388 : : uint16_t
389 : 0 : eth_igb_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
390 : : uint16_t nb_pkts)
391 : : {
392 : : struct igb_tx_queue *txq;
393 : : struct igb_tx_entry *sw_ring;
394 : : struct igb_tx_entry *txe, *txn;
395 : : volatile union e1000_adv_tx_desc *txr;
396 : : volatile union e1000_adv_tx_desc *txd;
397 : : struct rte_mbuf *tx_pkt;
398 : : struct rte_mbuf *m_seg;
399 : : uint64_t buf_dma_addr;
400 : : uint32_t olinfo_status;
401 : : uint32_t cmd_type_len;
402 : : uint32_t pkt_len;
403 : : uint16_t slen;
404 : : uint64_t ol_flags;
405 : : uint16_t tx_end;
406 : : uint16_t tx_id;
407 : : uint16_t tx_last;
408 : : uint16_t nb_tx;
409 : : uint64_t tx_ol_req;
410 : : uint32_t new_ctx = 0;
411 : : uint32_t ctx = 0;
412 : 0 : union igb_tx_offload tx_offload = {0};
413 : : uint64_t ts;
414 : :
415 : : txq = tx_queue;
416 : 0 : sw_ring = txq->sw_ring;
417 : 0 : txr = txq->tx_ring;
418 : 0 : tx_id = txq->tx_tail;
419 : 0 : txe = &sw_ring[tx_id];
420 : :
421 [ # # ]: 0 : for (nb_tx = 0; nb_tx < nb_pkts; nb_tx++) {
422 : 0 : tx_pkt = *tx_pkts++;
423 : 0 : pkt_len = tx_pkt->pkt_len;
424 : :
425 [ # # ]: 0 : RTE_MBUF_PREFETCH_TO_FREE(txe->mbuf);
426 : :
427 : : /*
428 : : * The number of descriptors that must be allocated for a
429 : : * packet is the number of segments of that packet, plus 1
430 : : * Context Descriptor for the VLAN Tag Identifier, if any.
431 : : * Determine the last TX descriptor to allocate in the TX ring
432 : : * for the packet, starting from the current position (tx_id)
433 : : * in the ring.
434 : : */
435 : 0 : tx_last = (uint16_t) (tx_id + tx_pkt->nb_segs - 1);
436 : :
437 : 0 : ol_flags = tx_pkt->ol_flags;
438 : 0 : tx_ol_req = ol_flags & IGB_TX_OFFLOAD_MASK;
439 : :
440 : : /* If a Context Descriptor need be built . */
441 [ # # ]: 0 : if (tx_ol_req) {
442 : 0 : tx_offload.l2_len = tx_pkt->l2_len;
443 : 0 : tx_offload.l3_len = tx_pkt->l3_len;
444 : 0 : tx_offload.l4_len = tx_pkt->l4_len;
445 : 0 : tx_offload.vlan_tci = tx_pkt->vlan_tci;
446 [ # # ]: 0 : tx_offload.tso_segsz = tx_pkt->tso_segsz;
447 : : tx_ol_req = check_tso_para(tx_ol_req, tx_offload);
448 : :
449 : 0 : ctx = what_advctx_update(txq, tx_ol_req, tx_offload);
450 : : /* Only allocate context descriptor if required*/
451 : 0 : new_ctx = (ctx == IGB_CTX_NUM);
452 : 0 : ctx = txq->ctx_curr + txq->ctx_start;
453 : 0 : tx_last = (uint16_t) (tx_last + new_ctx);
454 : : }
455 [ # # ]: 0 : if (tx_last >= txq->nb_tx_desc)
456 : 0 : tx_last = (uint16_t) (tx_last - txq->nb_tx_desc);
457 : :
458 : : PMD_TX_LOG(DEBUG, "port_id=%u queue_id=%u pktlen=%u"
459 : : " tx_first=%u tx_last=%u",
460 : : (unsigned) txq->port_id,
461 : : (unsigned) txq->queue_id,
462 : : (unsigned) pkt_len,
463 : : (unsigned) tx_id,
464 : : (unsigned) tx_last);
465 : :
466 : : /*
467 : : * Check if there are enough free descriptors in the TX ring
468 : : * to transmit the next packet.
469 : : * This operation is based on the two following rules:
470 : : *
471 : : * 1- Only check that the last needed TX descriptor can be
472 : : * allocated (by construction, if that descriptor is free,
473 : : * all intermediate ones are also free).
474 : : *
475 : : * For this purpose, the index of the last TX descriptor
476 : : * used for a packet (the "last descriptor" of a packet)
477 : : * is recorded in the TX entries (the last one included)
478 : : * that are associated with all TX descriptors allocated
479 : : * for that packet.
480 : : *
481 : : * 2- Avoid to allocate the last free TX descriptor of the
482 : : * ring, in order to never set the TDT register with the
483 : : * same value stored in parallel by the NIC in the TDH
484 : : * register, which makes the TX engine of the NIC enter
485 : : * in a deadlock situation.
486 : : *
487 : : * By extension, avoid to allocate a free descriptor that
488 : : * belongs to the last set of free descriptors allocated
489 : : * to the same packet previously transmitted.
490 : : */
491 : :
492 : : /*
493 : : * The "last descriptor" of the previously sent packet, if any,
494 : : * which used the last descriptor to allocate.
495 : : */
496 : 0 : tx_end = sw_ring[tx_last].last_id;
497 : :
498 : : /*
499 : : * The next descriptor following that "last descriptor" in the
500 : : * ring.
501 : : */
502 : 0 : tx_end = sw_ring[tx_end].next_id;
503 : :
504 : : /*
505 : : * The "last descriptor" associated with that next descriptor.
506 : : */
507 : 0 : tx_end = sw_ring[tx_end].last_id;
508 : :
509 : : /*
510 : : * Check that this descriptor is free.
511 : : */
512 [ # # ]: 0 : if (! (txr[tx_end].wb.status & E1000_TXD_STAT_DD)) {
513 [ # # ]: 0 : if (nb_tx == 0)
514 : : return 0;
515 : 0 : goto end_of_tx;
516 : : }
517 : :
518 : : /*
519 : : * Set common flags of all TX Data Descriptors.
520 : : *
521 : : * The following bits must be set in all Data Descriptors:
522 : : * - E1000_ADVTXD_DTYP_DATA
523 : : * - E1000_ADVTXD_DCMD_DEXT
524 : : *
525 : : * The following bits must be set in the first Data Descriptor
526 : : * and are ignored in the other ones:
527 : : * - E1000_ADVTXD_DCMD_IFCS
528 : : * - E1000_ADVTXD_MAC_1588
529 : : * - E1000_ADVTXD_DCMD_VLE
530 : : *
531 : : * The following bits must only be set in the last Data
532 : : * Descriptor:
533 : : * - E1000_TXD_CMD_EOP
534 : : *
535 : : * The following bits can be set in any Data Descriptor, but
536 : : * are only set in the last Data Descriptor:
537 : : * - E1000_TXD_CMD_RS
538 : : */
539 : 0 : cmd_type_len = txq->txd_type |
540 : : E1000_ADVTXD_DCMD_IFCS | E1000_ADVTXD_DCMD_DEXT;
541 [ # # ]: 0 : if (tx_ol_req & RTE_MBUF_F_TX_TCP_SEG)
542 : 0 : pkt_len -= (tx_pkt->l2_len + tx_pkt->l3_len + tx_pkt->l4_len);
543 : 0 : olinfo_status = (pkt_len << E1000_ADVTXD_PAYLEN_SHIFT);
544 : : #if defined(RTE_LIBRTE_IEEE1588)
545 : : if (ol_flags & RTE_MBUF_F_TX_IEEE1588_TMST)
546 : : cmd_type_len |= E1000_ADVTXD_MAC_TSTAMP;
547 : : #endif
548 [ # # ]: 0 : if (tx_ol_req) {
549 : : /* Setup TX Advanced context descriptor if required */
550 [ # # ]: 0 : if (new_ctx) {
551 : : volatile struct e1000_adv_tx_context_desc *
552 : : ctx_txd;
553 : :
554 : 0 : ctx_txd = (volatile struct
555 : : e1000_adv_tx_context_desc *)
556 : 0 : &txr[tx_id];
557 : :
558 : 0 : txn = &sw_ring[txe->next_id];
559 [ # # ]: 0 : RTE_MBUF_PREFETCH_TO_FREE(txn->mbuf);
560 : :
561 [ # # ]: 0 : if (txe->mbuf != NULL) {
562 : : rte_pktmbuf_free_seg(txe->mbuf);
563 : 0 : txe->mbuf = NULL;
564 : : }
565 : :
566 [ # # ]: 0 : if (igb_tx_timestamp_dynflag > 0) {
567 : 0 : ts = *RTE_MBUF_DYNFIELD(tx_pkt,
568 : : igb_tx_timestamp_dynfield_offset, uint64_t *);
569 : 0 : igbe_set_xmit_ctx(txq, ctx_txd, tx_ol_req, tx_offload, ts);
570 : : } else {
571 : 0 : igbe_set_xmit_ctx(txq, ctx_txd, tx_ol_req, tx_offload, 0);
572 : : }
573 : :
574 : 0 : txe->last_id = tx_last;
575 : 0 : tx_id = txe->next_id;
576 : : txe = txn;
577 : : }
578 : :
579 : : /* Setup the TX Advanced Data Descriptor */
580 : 0 : cmd_type_len |= tx_desc_vlan_flags_to_cmdtype(tx_ol_req);
581 : 0 : olinfo_status |= tx_desc_cksum_flags_to_olinfo(tx_ol_req);
582 : 0 : olinfo_status |= (ctx << E1000_ADVTXD_IDX_SHIFT);
583 : : }
584 : :
585 : : m_seg = tx_pkt;
586 : : do {
587 : 0 : txn = &sw_ring[txe->next_id];
588 : 0 : txd = &txr[tx_id];
589 : :
590 [ # # ]: 0 : if (txe->mbuf != NULL)
591 : : rte_pktmbuf_free_seg(txe->mbuf);
592 : 0 : txe->mbuf = m_seg;
593 : :
594 : : /*
595 : : * Set up transmit descriptor.
596 : : */
597 [ # # ]: 0 : slen = (uint16_t) m_seg->data_len;
598 : : buf_dma_addr = rte_mbuf_data_iova(m_seg);
599 : 0 : txd->read.buffer_addr =
600 : : rte_cpu_to_le_64(buf_dma_addr);
601 : 0 : txd->read.cmd_type_len =
602 : 0 : rte_cpu_to_le_32(cmd_type_len | slen);
603 : 0 : txd->read.olinfo_status =
604 : : rte_cpu_to_le_32(olinfo_status);
605 : 0 : txe->last_id = tx_last;
606 : 0 : tx_id = txe->next_id;
607 : : txe = txn;
608 : 0 : m_seg = m_seg->next;
609 [ # # ]: 0 : } while (m_seg != NULL);
610 : :
611 : : /*
612 : : * The last packet data descriptor needs End Of Packet (EOP)
613 : : * and Report Status (RS).
614 : : */
615 : 0 : txd->read.cmd_type_len |=
616 : : rte_cpu_to_le_32(E1000_TXD_CMD_EOP | E1000_TXD_CMD_RS);
617 : : }
618 : 0 : end_of_tx:
619 : : rte_wmb();
620 : :
621 : : /*
622 : : * Set the Transmit Descriptor Tail (TDT).
623 : : */
624 : 0 : E1000_PCI_REG_WRITE_RELAXED(txq->tdt_reg_addr, tx_id);
625 : : PMD_TX_LOG(DEBUG, "port_id=%u queue_id=%u tx_tail=%u nb_tx=%u",
626 : : (unsigned) txq->port_id, (unsigned) txq->queue_id,
627 : : (unsigned) tx_id, (unsigned) nb_tx);
628 : 0 : txq->tx_tail = tx_id;
629 : :
630 : 0 : return nb_tx;
631 : : }
632 : :
633 : : /*********************************************************************
634 : : *
635 : : * TX prep functions
636 : : *
637 : : **********************************************************************/
638 : : uint16_t
639 : 0 : eth_igb_prep_pkts(__rte_unused void *tx_queue, struct rte_mbuf **tx_pkts,
640 : : uint16_t nb_pkts)
641 : : {
642 : : int i, ret;
643 : : struct rte_mbuf *m;
644 : :
645 [ # # ]: 0 : for (i = 0; i < nb_pkts; i++) {
646 : 0 : m = tx_pkts[i];
647 : :
648 : : /* Check some limitations for TSO in hardware */
649 [ # # ]: 0 : if (m->ol_flags & RTE_MBUF_F_TX_TCP_SEG)
650 [ # # ]: 0 : if ((m->tso_segsz > IGB_TSO_MAX_MSS) ||
651 [ # # ]: 0 : (m->l2_len + m->l3_len + m->l4_len >
652 : : IGB_TSO_MAX_HDRLEN)) {
653 : 0 : rte_errno = EINVAL;
654 : 0 : return i;
655 : : }
656 : :
657 [ # # ]: 0 : if (m->ol_flags & IGB_TX_OFFLOAD_NOTSUP_MASK) {
658 : 0 : rte_errno = ENOTSUP;
659 : 0 : return i;
660 : : }
661 : :
662 : : #ifdef RTE_ETHDEV_DEBUG_TX
663 : : ret = rte_validate_tx_offload(m);
664 : : if (ret != 0) {
665 : : rte_errno = -ret;
666 : : return i;
667 : : }
668 : : #endif
669 : : ret = rte_net_intel_cksum_prepare(m);
670 [ # # ]: 0 : if (ret != 0) {
671 : 0 : rte_errno = -ret;
672 : 0 : return i;
673 : : }
674 : : }
675 : :
676 : 0 : return i;
677 : : }
678 : :
679 : : /*********************************************************************
680 : : *
681 : : * RX functions
682 : : *
683 : : **********************************************************************/
684 : : #define IGB_PACKET_TYPE_IPV4 0X01
685 : : #define IGB_PACKET_TYPE_IPV4_TCP 0X11
686 : : #define IGB_PACKET_TYPE_IPV4_UDP 0X21
687 : : #define IGB_PACKET_TYPE_IPV4_SCTP 0X41
688 : : #define IGB_PACKET_TYPE_IPV4_EXT 0X03
689 : : #define IGB_PACKET_TYPE_IPV4_EXT_SCTP 0X43
690 : : #define IGB_PACKET_TYPE_IPV6 0X04
691 : : #define IGB_PACKET_TYPE_IPV6_TCP 0X14
692 : : #define IGB_PACKET_TYPE_IPV6_UDP 0X24
693 : : #define IGB_PACKET_TYPE_IPV6_EXT 0X0C
694 : : #define IGB_PACKET_TYPE_IPV6_EXT_TCP 0X1C
695 : : #define IGB_PACKET_TYPE_IPV6_EXT_UDP 0X2C
696 : : #define IGB_PACKET_TYPE_IPV4_IPV6 0X05
697 : : #define IGB_PACKET_TYPE_IPV4_IPV6_TCP 0X15
698 : : #define IGB_PACKET_TYPE_IPV4_IPV6_UDP 0X25
699 : : #define IGB_PACKET_TYPE_IPV4_IPV6_EXT 0X0D
700 : : #define IGB_PACKET_TYPE_IPV4_IPV6_EXT_TCP 0X1D
701 : : #define IGB_PACKET_TYPE_IPV4_IPV6_EXT_UDP 0X2D
702 : : #define IGB_PACKET_TYPE_MAX 0X80
703 : : #define IGB_PACKET_TYPE_MASK 0X7F
704 : : #define IGB_PACKET_TYPE_SHIFT 0X04
705 : : static inline uint32_t
706 : : igb_rxd_pkt_info_to_pkt_type(uint16_t pkt_info)
707 : : {
708 : : static const alignas(RTE_CACHE_LINE_SIZE) uint32_t
709 : : ptype_table[IGB_PACKET_TYPE_MAX] = {
710 : : [IGB_PACKET_TYPE_IPV4] = RTE_PTYPE_L2_ETHER |
711 : : RTE_PTYPE_L3_IPV4,
712 : : [IGB_PACKET_TYPE_IPV4_EXT] = RTE_PTYPE_L2_ETHER |
713 : : RTE_PTYPE_L3_IPV4_EXT,
714 : : [IGB_PACKET_TYPE_IPV6] = RTE_PTYPE_L2_ETHER |
715 : : RTE_PTYPE_L3_IPV6,
716 : : [IGB_PACKET_TYPE_IPV4_IPV6] = RTE_PTYPE_L2_ETHER |
717 : : RTE_PTYPE_L3_IPV4 | RTE_PTYPE_TUNNEL_IP |
718 : : RTE_PTYPE_INNER_L3_IPV6,
719 : : [IGB_PACKET_TYPE_IPV6_EXT] = RTE_PTYPE_L2_ETHER |
720 : : RTE_PTYPE_L3_IPV6_EXT,
721 : : [IGB_PACKET_TYPE_IPV4_IPV6_EXT] = RTE_PTYPE_L2_ETHER |
722 : : RTE_PTYPE_L3_IPV4 | RTE_PTYPE_TUNNEL_IP |
723 : : RTE_PTYPE_INNER_L3_IPV6_EXT,
724 : : [IGB_PACKET_TYPE_IPV4_TCP] = RTE_PTYPE_L2_ETHER |
725 : : RTE_PTYPE_L3_IPV4 | RTE_PTYPE_L4_TCP,
726 : : [IGB_PACKET_TYPE_IPV6_TCP] = RTE_PTYPE_L2_ETHER |
727 : : RTE_PTYPE_L3_IPV6 | RTE_PTYPE_L4_TCP,
728 : : [IGB_PACKET_TYPE_IPV4_IPV6_TCP] = RTE_PTYPE_L2_ETHER |
729 : : RTE_PTYPE_L3_IPV4 | RTE_PTYPE_TUNNEL_IP |
730 : : RTE_PTYPE_INNER_L3_IPV6 | RTE_PTYPE_INNER_L4_TCP,
731 : : [IGB_PACKET_TYPE_IPV6_EXT_TCP] = RTE_PTYPE_L2_ETHER |
732 : : RTE_PTYPE_L3_IPV6_EXT | RTE_PTYPE_L4_TCP,
733 : : [IGB_PACKET_TYPE_IPV4_IPV6_EXT_TCP] = RTE_PTYPE_L2_ETHER |
734 : : RTE_PTYPE_L3_IPV4 | RTE_PTYPE_TUNNEL_IP |
735 : : RTE_PTYPE_INNER_L3_IPV6_EXT | RTE_PTYPE_INNER_L4_TCP,
736 : : [IGB_PACKET_TYPE_IPV4_UDP] = RTE_PTYPE_L2_ETHER |
737 : : RTE_PTYPE_L3_IPV4 | RTE_PTYPE_L4_UDP,
738 : : [IGB_PACKET_TYPE_IPV6_UDP] = RTE_PTYPE_L2_ETHER |
739 : : RTE_PTYPE_L3_IPV6 | RTE_PTYPE_L4_UDP,
740 : : [IGB_PACKET_TYPE_IPV4_IPV6_UDP] = RTE_PTYPE_L2_ETHER |
741 : : RTE_PTYPE_L3_IPV4 | RTE_PTYPE_TUNNEL_IP |
742 : : RTE_PTYPE_INNER_L3_IPV6 | RTE_PTYPE_INNER_L4_UDP,
743 : : [IGB_PACKET_TYPE_IPV6_EXT_UDP] = RTE_PTYPE_L2_ETHER |
744 : : RTE_PTYPE_L3_IPV6_EXT | RTE_PTYPE_L4_UDP,
745 : : [IGB_PACKET_TYPE_IPV4_IPV6_EXT_UDP] = RTE_PTYPE_L2_ETHER |
746 : : RTE_PTYPE_L3_IPV4 | RTE_PTYPE_TUNNEL_IP |
747 : : RTE_PTYPE_INNER_L3_IPV6_EXT | RTE_PTYPE_INNER_L4_UDP,
748 : : [IGB_PACKET_TYPE_IPV4_SCTP] = RTE_PTYPE_L2_ETHER |
749 : : RTE_PTYPE_L3_IPV4 | RTE_PTYPE_L4_SCTP,
750 : : [IGB_PACKET_TYPE_IPV4_EXT_SCTP] = RTE_PTYPE_L2_ETHER |
751 : : RTE_PTYPE_L3_IPV4_EXT | RTE_PTYPE_L4_SCTP,
752 : : };
753 : 0 : if (unlikely(pkt_info & E1000_RXDADV_PKTTYPE_ETQF))
754 : : return RTE_PTYPE_UNKNOWN;
755 : :
756 : 0 : pkt_info = (pkt_info >> IGB_PACKET_TYPE_SHIFT) & IGB_PACKET_TYPE_MASK;
757 : :
758 : 0 : return ptype_table[pkt_info];
759 : : }
760 : :
761 : : static inline uint64_t
762 : : rx_desc_hlen_type_rss_to_pkt_flags(struct igb_rx_queue *rxq, uint32_t hl_tp_rs)
763 : : {
764 [ # # ]: 0 : uint64_t pkt_flags = ((hl_tp_rs & 0x0F) == 0) ? 0 : RTE_MBUF_F_RX_RSS_HASH;
765 : :
766 : : #if defined(RTE_LIBRTE_IEEE1588)
767 : : static uint32_t ip_pkt_etqf_map[8] = {
768 : : 0, 0, 0, RTE_MBUF_F_RX_IEEE1588_PTP,
769 : : 0, 0, 0, 0,
770 : : };
771 : :
772 : : struct rte_eth_dev dev = rte_eth_devices[rxq->port_id];
773 : : struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev.data->dev_private);
774 : :
775 : : /* EtherType is in bits 8:10 in Packet Type, and not in the default 0:2 */
776 : : if (hw->mac.type == e1000_i210)
777 : : pkt_flags |= ip_pkt_etqf_map[(hl_tp_rs >> 12) & 0x07];
778 : : else
779 : : pkt_flags |= ip_pkt_etqf_map[(hl_tp_rs >> 4) & 0x07];
780 : : #else
781 : : RTE_SET_USED(rxq);
782 : : #endif
783 : :
784 : : return pkt_flags;
785 : : }
786 : :
787 : : static inline uint64_t
788 : : rx_desc_status_to_pkt_flags(uint32_t rx_status)
789 : : {
790 : : uint64_t pkt_flags;
791 : :
792 : : /* Check if VLAN present */
793 : 0 : pkt_flags = ((rx_status & E1000_RXD_STAT_VP) ?
794 [ # # # # ]: 0 : RTE_MBUF_F_RX_VLAN | RTE_MBUF_F_RX_VLAN_STRIPPED : 0);
795 : :
796 : : #if defined(RTE_LIBRTE_IEEE1588)
797 : : if (rx_status & E1000_RXD_STAT_TMST)
798 : : pkt_flags = pkt_flags | RTE_MBUF_F_RX_IEEE1588_TMST;
799 : : #endif
800 : : return pkt_flags;
801 : : }
802 : :
803 : : static inline uint64_t
804 : : rx_desc_error_to_pkt_flags(uint32_t rx_status)
805 : : {
806 : : /*
807 : : * Bit 30: IPE, IPv4 checksum error
808 : : * Bit 29: L4I, L4I integrity error
809 : : */
810 : :
811 : : static uint64_t error_to_pkt_flags_map[4] = {
812 : : RTE_MBUF_F_RX_IP_CKSUM_GOOD | RTE_MBUF_F_RX_L4_CKSUM_GOOD,
813 : : RTE_MBUF_F_RX_IP_CKSUM_GOOD | RTE_MBUF_F_RX_L4_CKSUM_BAD,
814 : : RTE_MBUF_F_RX_IP_CKSUM_BAD | RTE_MBUF_F_RX_L4_CKSUM_GOOD,
815 : : RTE_MBUF_F_RX_IP_CKSUM_BAD | RTE_MBUF_F_RX_L4_CKSUM_BAD
816 : : };
817 : 0 : return error_to_pkt_flags_map[(rx_status >>
818 : 0 : E1000_RXD_ERR_CKSUM_BIT) & E1000_RXD_ERR_CKSUM_MSK];
819 : : }
820 : :
821 : : uint16_t
822 : 0 : eth_igb_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
823 : : uint16_t nb_pkts)
824 : : {
825 : : struct igb_rx_queue *rxq;
826 : : volatile union e1000_adv_rx_desc *rx_ring;
827 : : volatile union e1000_adv_rx_desc *rxdp;
828 : : struct igb_rx_entry *sw_ring;
829 : : struct igb_rx_entry *rxe;
830 : : struct rte_mbuf *rxm;
831 : : struct rte_mbuf *nmb;
832 : : union e1000_adv_rx_desc rxd;
833 : : uint64_t dma_addr;
834 : : uint32_t staterr;
835 : : uint32_t hlen_type_rss;
836 : : uint16_t pkt_len;
837 : : uint16_t rx_id;
838 : : uint16_t nb_rx;
839 : : uint16_t nb_hold;
840 : : uint64_t pkt_flags;
841 : :
842 : : nb_rx = 0;
843 : : nb_hold = 0;
844 : : rxq = rx_queue;
845 : 0 : rx_id = rxq->rx_tail;
846 : 0 : rx_ring = rxq->rx_ring;
847 : 0 : sw_ring = rxq->sw_ring;
848 [ # # ]: 0 : while (nb_rx < nb_pkts) {
849 : : /*
850 : : * The order of operations here is important as the DD status
851 : : * bit must not be read after any other descriptor fields.
852 : : * rx_ring and rxdp are pointing to volatile data so the order
853 : : * of accesses cannot be reordered by the compiler. If they were
854 : : * not volatile, they could be reordered which could lead to
855 : : * using invalid descriptor fields when read from rxd.
856 : : */
857 : 0 : rxdp = &rx_ring[rx_id];
858 : 0 : staterr = rxdp->wb.upper.status_error;
859 [ # # ]: 0 : if (! (staterr & rte_cpu_to_le_32(E1000_RXD_STAT_DD)))
860 : : break;
861 : 0 : rxd = *rxdp;
862 : :
863 : : /*
864 : : * End of packet.
865 : : *
866 : : * If the E1000_RXD_STAT_EOP flag is not set, the RX packet is
867 : : * likely to be invalid and to be dropped by the various
868 : : * validation checks performed by the network stack.
869 : : *
870 : : * Allocate a new mbuf to replenish the RX ring descriptor.
871 : : * If the allocation fails:
872 : : * - arrange for that RX descriptor to be the first one
873 : : * being parsed the next time the receive function is
874 : : * invoked [on the same queue].
875 : : *
876 : : * - Stop parsing the RX ring and return immediately.
877 : : *
878 : : * This policy do not drop the packet received in the RX
879 : : * descriptor for which the allocation of a new mbuf failed.
880 : : * Thus, it allows that packet to be later retrieved if
881 : : * mbuf have been freed in the mean time.
882 : : * As a side effect, holding RX descriptors instead of
883 : : * systematically giving them back to the NIC may lead to
884 : : * RX ring exhaustion situations.
885 : : * However, the NIC can gracefully prevent such situations
886 : : * to happen by sending specific "back-pressure" flow control
887 : : * frames to its peer(s).
888 : : */
889 : : PMD_RX_LOG(DEBUG, "port_id=%u queue_id=%u rx_id=%u "
890 : : "staterr=0x%x pkt_len=%u",
891 : : (unsigned) rxq->port_id, (unsigned) rxq->queue_id,
892 : : (unsigned) rx_id, (unsigned) staterr,
893 : : (unsigned) rte_le_to_cpu_16(rxd.wb.upper.length));
894 : :
895 : 0 : nmb = rte_mbuf_raw_alloc(rxq->mb_pool);
896 [ # # ]: 0 : if (nmb == NULL) {
897 : : PMD_RX_LOG(DEBUG, "RX mbuf alloc failed port_id=%u "
898 : : "queue_id=%u", (unsigned) rxq->port_id,
899 : : (unsigned) rxq->queue_id);
900 : 0 : rte_eth_devices[rxq->port_id].data->rx_mbuf_alloc_failed++;
901 : 0 : break;
902 : : }
903 : :
904 : 0 : nb_hold++;
905 : 0 : rxe = &sw_ring[rx_id];
906 : 0 : rx_id++;
907 [ # # ]: 0 : if (rx_id == rxq->nb_rx_desc)
908 : : rx_id = 0;
909 : :
910 : : /* Prefetch next mbuf while processing current one. */
911 : 0 : rte_igb_prefetch(sw_ring[rx_id].mbuf);
912 : :
913 : : /*
914 : : * When next RX descriptor is on a cache-line boundary,
915 : : * prefetch the next 4 RX descriptors and the next 8 pointers
916 : : * to mbufs.
917 : : */
918 [ # # ]: 0 : if ((rx_id & 0x3) == 0) {
919 : 0 : rte_igb_prefetch(&rx_ring[rx_id]);
920 : : rte_igb_prefetch(&sw_ring[rx_id]);
921 : : }
922 : :
923 : 0 : rxm = rxe->mbuf;
924 : 0 : rxe->mbuf = nmb;
925 : : dma_addr =
926 : : rte_cpu_to_le_64(rte_mbuf_data_iova_default(nmb));
927 : 0 : rxdp->read.hdr_addr = 0;
928 : 0 : rxdp->read.pkt_addr = dma_addr;
929 : :
930 : : /*
931 : : * Initialize the returned mbuf.
932 : : * 1) setup generic mbuf fields:
933 : : * - number of segments,
934 : : * - next segment,
935 : : * - packet length,
936 : : * - RX port identifier.
937 : : * 2) integrate hardware offload data, if any:
938 : : * - RSS flag & hash,
939 : : * - IP checksum flag,
940 : : * - VLAN TCI, if any,
941 : : * - error flags.
942 : : */
943 : 0 : pkt_len = (uint16_t) (rte_le_to_cpu_16(rxd.wb.upper.length) -
944 : 0 : rxq->crc_len);
945 : 0 : rxm->data_off = RTE_PKTMBUF_HEADROOM;
946 : 0 : rte_packet_prefetch((char *)rxm->buf_addr + rxm->data_off);
947 : 0 : rxm->nb_segs = 1;
948 : 0 : rxm->next = NULL;
949 : 0 : rxm->pkt_len = pkt_len;
950 : 0 : rxm->data_len = pkt_len;
951 : 0 : rxm->port = rxq->port_id;
952 : :
953 : 0 : rxm->hash.rss = rxd.wb.lower.hi_dword.rss;
954 : 0 : hlen_type_rss = rte_le_to_cpu_32(rxd.wb.lower.lo_dword.data);
955 : :
956 : : /*
957 : : * The vlan_tci field is only valid when RTE_MBUF_F_RX_VLAN is
958 : : * set in the pkt_flags field and must be in CPU byte order.
959 : : */
960 [ # # ]: 0 : if ((staterr & rte_cpu_to_le_32(E1000_RXDEXT_STATERR_LB)) &&
961 [ # # ]: 0 : (rxq->flags & IGB_RXQ_FLAG_LB_BSWAP_VLAN)) {
962 [ # # ]: 0 : rxm->vlan_tci = rte_be_to_cpu_16(rxd.wb.upper.vlan);
963 : : } else {
964 : 0 : rxm->vlan_tci = rte_le_to_cpu_16(rxd.wb.upper.vlan);
965 : : }
966 : : pkt_flags = rx_desc_hlen_type_rss_to_pkt_flags(rxq, hlen_type_rss);
967 : 0 : pkt_flags = pkt_flags | rx_desc_status_to_pkt_flags(staterr);
968 : 0 : pkt_flags = pkt_flags | rx_desc_error_to_pkt_flags(staterr);
969 : 0 : rxm->ol_flags = pkt_flags;
970 : 0 : rxm->packet_type = igb_rxd_pkt_info_to_pkt_type(rxd.wb.lower.
971 [ # # ]: 0 : lo_dword.hs_rss.pkt_info);
972 : :
973 : : /*
974 : : * Store the mbuf address into the next entry of the array
975 : : * of returned packets.
976 : : */
977 : 0 : rx_pkts[nb_rx++] = rxm;
978 : : }
979 : 0 : rxq->rx_tail = rx_id;
980 : :
981 : : /*
982 : : * If the number of free RX descriptors is greater than the RX free
983 : : * threshold of the queue, advance the Receive Descriptor Tail (RDT)
984 : : * register.
985 : : * Update the RDT with the value of the last processed RX descriptor
986 : : * minus 1, to guarantee that the RDT register is never equal to the
987 : : * RDH register, which creates a "full" ring situation from the
988 : : * hardware point of view...
989 : : */
990 : 0 : nb_hold = (uint16_t) (nb_hold + rxq->nb_rx_hold);
991 [ # # ]: 0 : if (nb_hold > rxq->rx_free_thresh) {
992 : : PMD_RX_LOG(DEBUG, "port_id=%u queue_id=%u rx_tail=%u "
993 : : "nb_hold=%u nb_rx=%u",
994 : : (unsigned) rxq->port_id, (unsigned) rxq->queue_id,
995 : : (unsigned) rx_id, (unsigned) nb_hold,
996 : : (unsigned) nb_rx);
997 [ # # ]: 0 : rx_id = (uint16_t) ((rx_id == 0) ?
998 : 0 : (rxq->nb_rx_desc - 1) : (rx_id - 1));
999 : 0 : E1000_PCI_REG_WRITE(rxq->rdt_reg_addr, rx_id);
1000 : : nb_hold = 0;
1001 : : }
1002 : 0 : rxq->nb_rx_hold = nb_hold;
1003 : 0 : return nb_rx;
1004 : : }
1005 : :
1006 : : uint16_t
1007 : 0 : eth_igb_recv_scattered_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
1008 : : uint16_t nb_pkts)
1009 : : {
1010 : : struct igb_rx_queue *rxq;
1011 : : volatile union e1000_adv_rx_desc *rx_ring;
1012 : : volatile union e1000_adv_rx_desc *rxdp;
1013 : : struct igb_rx_entry *sw_ring;
1014 : : struct igb_rx_entry *rxe;
1015 : : struct rte_mbuf *first_seg;
1016 : : struct rte_mbuf *last_seg;
1017 : : struct rte_mbuf *rxm;
1018 : : struct rte_mbuf *nmb;
1019 : : union e1000_adv_rx_desc rxd;
1020 : : uint64_t dma; /* Physical address of mbuf data buffer */
1021 : : uint32_t staterr;
1022 : : uint32_t hlen_type_rss;
1023 : : uint16_t rx_id;
1024 : : uint16_t nb_rx;
1025 : : uint16_t nb_hold;
1026 : : uint16_t data_len;
1027 : : uint64_t pkt_flags;
1028 : :
1029 : : nb_rx = 0;
1030 : : nb_hold = 0;
1031 : : rxq = rx_queue;
1032 : 0 : rx_id = rxq->rx_tail;
1033 : 0 : rx_ring = rxq->rx_ring;
1034 : 0 : sw_ring = rxq->sw_ring;
1035 : :
1036 : : /*
1037 : : * Retrieve RX context of current packet, if any.
1038 : : */
1039 : 0 : first_seg = rxq->pkt_first_seg;
1040 : 0 : last_seg = rxq->pkt_last_seg;
1041 : :
1042 [ # # ]: 0 : while (nb_rx < nb_pkts) {
1043 : 0 : next_desc:
1044 : : /*
1045 : : * The order of operations here is important as the DD status
1046 : : * bit must not be read after any other descriptor fields.
1047 : : * rx_ring and rxdp are pointing to volatile data so the order
1048 : : * of accesses cannot be reordered by the compiler. If they were
1049 : : * not volatile, they could be reordered which could lead to
1050 : : * using invalid descriptor fields when read from rxd.
1051 : : */
1052 : 0 : rxdp = &rx_ring[rx_id];
1053 : 0 : staterr = rxdp->wb.upper.status_error;
1054 [ # # ]: 0 : if (! (staterr & rte_cpu_to_le_32(E1000_RXD_STAT_DD)))
1055 : : break;
1056 : 0 : rxd = *rxdp;
1057 : :
1058 : : /*
1059 : : * Descriptor done.
1060 : : *
1061 : : * Allocate a new mbuf to replenish the RX ring descriptor.
1062 : : * If the allocation fails:
1063 : : * - arrange for that RX descriptor to be the first one
1064 : : * being parsed the next time the receive function is
1065 : : * invoked [on the same queue].
1066 : : *
1067 : : * - Stop parsing the RX ring and return immediately.
1068 : : *
1069 : : * This policy does not drop the packet received in the RX
1070 : : * descriptor for which the allocation of a new mbuf failed.
1071 : : * Thus, it allows that packet to be later retrieved if
1072 : : * mbuf have been freed in the mean time.
1073 : : * As a side effect, holding RX descriptors instead of
1074 : : * systematically giving them back to the NIC may lead to
1075 : : * RX ring exhaustion situations.
1076 : : * However, the NIC can gracefully prevent such situations
1077 : : * to happen by sending specific "back-pressure" flow control
1078 : : * frames to its peer(s).
1079 : : */
1080 : : PMD_RX_LOG(DEBUG, "port_id=%u queue_id=%u rx_id=%u "
1081 : : "staterr=0x%x data_len=%u",
1082 : : (unsigned) rxq->port_id, (unsigned) rxq->queue_id,
1083 : : (unsigned) rx_id, (unsigned) staterr,
1084 : : (unsigned) rte_le_to_cpu_16(rxd.wb.upper.length));
1085 : :
1086 : 0 : nmb = rte_mbuf_raw_alloc(rxq->mb_pool);
1087 [ # # ]: 0 : if (nmb == NULL) {
1088 : : PMD_RX_LOG(DEBUG, "RX mbuf alloc failed port_id=%u "
1089 : : "queue_id=%u", (unsigned) rxq->port_id,
1090 : : (unsigned) rxq->queue_id);
1091 : 0 : rte_eth_devices[rxq->port_id].data->rx_mbuf_alloc_failed++;
1092 : 0 : break;
1093 : : }
1094 : :
1095 : 0 : nb_hold++;
1096 : 0 : rxe = &sw_ring[rx_id];
1097 : 0 : rx_id++;
1098 [ # # ]: 0 : if (rx_id == rxq->nb_rx_desc)
1099 : : rx_id = 0;
1100 : :
1101 : : /* Prefetch next mbuf while processing current one. */
1102 : 0 : rte_igb_prefetch(sw_ring[rx_id].mbuf);
1103 : :
1104 : : /*
1105 : : * When next RX descriptor is on a cache-line boundary,
1106 : : * prefetch the next 4 RX descriptors and the next 8 pointers
1107 : : * to mbufs.
1108 : : */
1109 [ # # ]: 0 : if ((rx_id & 0x3) == 0) {
1110 : 0 : rte_igb_prefetch(&rx_ring[rx_id]);
1111 : : rte_igb_prefetch(&sw_ring[rx_id]);
1112 : : }
1113 : :
1114 : : /*
1115 : : * Update RX descriptor with the physical address of the new
1116 : : * data buffer of the new allocated mbuf.
1117 : : */
1118 : 0 : rxm = rxe->mbuf;
1119 [ # # ]: 0 : rxe->mbuf = nmb;
1120 : : dma = rte_cpu_to_le_64(rte_mbuf_data_iova_default(nmb));
1121 : 0 : rxdp->read.pkt_addr = dma;
1122 : 0 : rxdp->read.hdr_addr = 0;
1123 : :
1124 : : /*
1125 : : * Set data length & data buffer address of mbuf.
1126 : : */
1127 : : data_len = rte_le_to_cpu_16(rxd.wb.upper.length);
1128 : 0 : rxm->data_len = data_len;
1129 : 0 : rxm->data_off = RTE_PKTMBUF_HEADROOM;
1130 : :
1131 : : /*
1132 : : * If this is the first buffer of the received packet,
1133 : : * set the pointer to the first mbuf of the packet and
1134 : : * initialize its context.
1135 : : * Otherwise, update the total length and the number of segments
1136 : : * of the current scattered packet, and update the pointer to
1137 : : * the last mbuf of the current packet.
1138 : : */
1139 [ # # ]: 0 : if (first_seg == NULL) {
1140 : : first_seg = rxm;
1141 : 0 : first_seg->pkt_len = data_len;
1142 : 0 : first_seg->nb_segs = 1;
1143 : : } else {
1144 : 0 : first_seg->pkt_len += data_len;
1145 : 0 : first_seg->nb_segs++;
1146 : 0 : last_seg->next = rxm;
1147 : : }
1148 : :
1149 : : /*
1150 : : * If this is not the last buffer of the received packet,
1151 : : * update the pointer to the last mbuf of the current scattered
1152 : : * packet and continue to parse the RX ring.
1153 : : */
1154 [ # # ]: 0 : if (! (staterr & E1000_RXD_STAT_EOP)) {
1155 : : last_seg = rxm;
1156 : 0 : goto next_desc;
1157 : : }
1158 : :
1159 : : /*
1160 : : * This is the last buffer of the received packet.
1161 : : * If the CRC is not stripped by the hardware:
1162 : : * - Subtract the CRC length from the total packet length.
1163 : : * - If the last buffer only contains the whole CRC or a part
1164 : : * of it, free the mbuf associated to the last buffer.
1165 : : * If part of the CRC is also contained in the previous
1166 : : * mbuf, subtract the length of that CRC part from the
1167 : : * data length of the previous mbuf.
1168 : : */
1169 : 0 : rxm->next = NULL;
1170 [ # # ]: 0 : if (unlikely(rxq->crc_len > 0)) {
1171 : 0 : first_seg->pkt_len -= RTE_ETHER_CRC_LEN;
1172 [ # # ]: 0 : if (data_len <= RTE_ETHER_CRC_LEN) {
1173 : : rte_pktmbuf_free_seg(rxm);
1174 : 0 : first_seg->nb_segs--;
1175 : 0 : last_seg->data_len = (uint16_t)
1176 : 0 : (last_seg->data_len -
1177 : : (RTE_ETHER_CRC_LEN - data_len));
1178 : 0 : last_seg->next = NULL;
1179 : : } else
1180 : 0 : rxm->data_len = (uint16_t)
1181 : : (data_len - RTE_ETHER_CRC_LEN);
1182 : : }
1183 : :
1184 : : /*
1185 : : * Initialize the first mbuf of the returned packet:
1186 : : * - RX port identifier,
1187 : : * - hardware offload data, if any:
1188 : : * - RSS flag & hash,
1189 : : * - IP checksum flag,
1190 : : * - VLAN TCI, if any,
1191 : : * - error flags.
1192 : : */
1193 : 0 : first_seg->port = rxq->port_id;
1194 : 0 : first_seg->hash.rss = rxd.wb.lower.hi_dword.rss;
1195 : :
1196 : : /*
1197 : : * The vlan_tci field is only valid when RTE_MBUF_F_RX_VLAN is
1198 : : * set in the pkt_flags field and must be in CPU byte order.
1199 : : */
1200 [ # # ]: 0 : if ((staterr & rte_cpu_to_le_32(E1000_RXDEXT_STATERR_LB)) &&
1201 [ # # ]: 0 : (rxq->flags & IGB_RXQ_FLAG_LB_BSWAP_VLAN)) {
1202 : 0 : first_seg->vlan_tci =
1203 [ # # ]: 0 : rte_be_to_cpu_16(rxd.wb.upper.vlan);
1204 : : } else {
1205 : 0 : first_seg->vlan_tci =
1206 : : rte_le_to_cpu_16(rxd.wb.upper.vlan);
1207 : : }
1208 [ # # ]: 0 : hlen_type_rss = rte_le_to_cpu_32(rxd.wb.lower.lo_dword.data);
1209 : : pkt_flags = rx_desc_hlen_type_rss_to_pkt_flags(rxq, hlen_type_rss);
1210 : 0 : pkt_flags = pkt_flags | rx_desc_status_to_pkt_flags(staterr);
1211 : 0 : pkt_flags = pkt_flags | rx_desc_error_to_pkt_flags(staterr);
1212 : 0 : first_seg->ol_flags = pkt_flags;
1213 : 0 : first_seg->packet_type = igb_rxd_pkt_info_to_pkt_type(rxd.wb.
1214 [ # # ]: 0 : lower.lo_dword.hs_rss.pkt_info);
1215 : :
1216 : : /* Prefetch data of first segment, if configured to do so. */
1217 : 0 : rte_packet_prefetch((char *)first_seg->buf_addr +
1218 : : first_seg->data_off);
1219 : :
1220 : : /*
1221 : : * Store the mbuf address into the next entry of the array
1222 : : * of returned packets.
1223 : : */
1224 : 0 : rx_pkts[nb_rx++] = first_seg;
1225 : :
1226 : : /*
1227 : : * Setup receipt context for a new packet.
1228 : : */
1229 : : first_seg = NULL;
1230 : : }
1231 : :
1232 : : /*
1233 : : * Record index of the next RX descriptor to probe.
1234 : : */
1235 : 0 : rxq->rx_tail = rx_id;
1236 : :
1237 : : /*
1238 : : * Save receive context.
1239 : : */
1240 : 0 : rxq->pkt_first_seg = first_seg;
1241 : 0 : rxq->pkt_last_seg = last_seg;
1242 : :
1243 : : /*
1244 : : * If the number of free RX descriptors is greater than the RX free
1245 : : * threshold of the queue, advance the Receive Descriptor Tail (RDT)
1246 : : * register.
1247 : : * Update the RDT with the value of the last processed RX descriptor
1248 : : * minus 1, to guarantee that the RDT register is never equal to the
1249 : : * RDH register, which creates a "full" ring situation from the
1250 : : * hardware point of view...
1251 : : */
1252 : 0 : nb_hold = (uint16_t) (nb_hold + rxq->nb_rx_hold);
1253 [ # # ]: 0 : if (nb_hold > rxq->rx_free_thresh) {
1254 : : PMD_RX_LOG(DEBUG, "port_id=%u queue_id=%u rx_tail=%u "
1255 : : "nb_hold=%u nb_rx=%u",
1256 : : (unsigned) rxq->port_id, (unsigned) rxq->queue_id,
1257 : : (unsigned) rx_id, (unsigned) nb_hold,
1258 : : (unsigned) nb_rx);
1259 [ # # ]: 0 : rx_id = (uint16_t) ((rx_id == 0) ?
1260 : 0 : (rxq->nb_rx_desc - 1) : (rx_id - 1));
1261 : 0 : E1000_PCI_REG_WRITE(rxq->rdt_reg_addr, rx_id);
1262 : : nb_hold = 0;
1263 : : }
1264 : 0 : rxq->nb_rx_hold = nb_hold;
1265 : 0 : return nb_rx;
1266 : : }
1267 : :
1268 : : /*
1269 : : * Maximum number of Ring Descriptors.
1270 : : *
1271 : : * Since RDLEN/TDLEN should be multiple of 128bytes, the number of ring
1272 : : * descriptors should meet the following condition:
1273 : : * (num_ring_desc * sizeof(struct e1000_rx/tx_desc)) % 128 == 0
1274 : : */
1275 : :
1276 : : static void
1277 : 0 : igb_tx_queue_release_mbufs(struct igb_tx_queue *txq)
1278 : : {
1279 : : unsigned i;
1280 : :
1281 [ # # ]: 0 : if (txq->sw_ring != NULL) {
1282 [ # # ]: 0 : for (i = 0; i < txq->nb_tx_desc; i++) {
1283 [ # # ]: 0 : if (txq->sw_ring[i].mbuf != NULL) {
1284 : : rte_pktmbuf_free_seg(txq->sw_ring[i].mbuf);
1285 : 0 : txq->sw_ring[i].mbuf = NULL;
1286 : : }
1287 : : }
1288 : : }
1289 : 0 : }
1290 : :
1291 : : static void
1292 : 0 : igb_tx_queue_release(struct igb_tx_queue *txq)
1293 : : {
1294 [ # # ]: 0 : if (txq != NULL) {
1295 : 0 : igb_tx_queue_release_mbufs(txq);
1296 : 0 : rte_free(txq->sw_ring);
1297 : 0 : rte_memzone_free(txq->mz);
1298 : 0 : rte_free(txq);
1299 : : }
1300 : 0 : }
1301 : :
1302 : : void
1303 : 0 : eth_igb_tx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
1304 : : {
1305 : 0 : igb_tx_queue_release(dev->data->tx_queues[qid]);
1306 : 0 : }
1307 : :
1308 : : static int
1309 : 0 : igb_tx_done_cleanup(struct igb_tx_queue *txq, uint32_t free_cnt)
1310 : : {
1311 : : struct igb_tx_entry *sw_ring;
1312 : : volatile union e1000_adv_tx_desc *txr;
1313 : : uint16_t tx_first; /* First segment analyzed. */
1314 : : uint16_t tx_id; /* Current segment being processed. */
1315 : : uint16_t tx_last; /* Last segment in the current packet. */
1316 : : uint16_t tx_next; /* First segment of the next packet. */
1317 : : int count = 0;
1318 : :
1319 [ # # ]: 0 : if (!txq)
1320 : : return -ENODEV;
1321 : :
1322 : 0 : sw_ring = txq->sw_ring;
1323 : 0 : txr = txq->tx_ring;
1324 : :
1325 : : /* tx_tail is the last sent packet on the sw_ring. Goto the end
1326 : : * of that packet (the last segment in the packet chain) and
1327 : : * then the next segment will be the start of the oldest segment
1328 : : * in the sw_ring. This is the first packet that will be
1329 : : * attempted to be freed.
1330 : : */
1331 : :
1332 : : /* Get last segment in most recently added packet. */
1333 : 0 : tx_first = sw_ring[txq->tx_tail].last_id;
1334 : :
1335 : : /* Get the next segment, which is the oldest segment in ring. */
1336 : 0 : tx_first = sw_ring[tx_first].next_id;
1337 : :
1338 : : /* Set the current index to the first. */
1339 : : tx_id = tx_first;
1340 : :
1341 : : /* Loop through each packet. For each packet, verify that an
1342 : : * mbuf exists and that the last segment is free. If so, free
1343 : : * it and move on.
1344 : : */
1345 : : while (1) {
1346 : 0 : tx_last = sw_ring[tx_id].last_id;
1347 : :
1348 [ # # ]: 0 : if (sw_ring[tx_last].mbuf) {
1349 [ # # ]: 0 : if (txr[tx_last].wb.status &
1350 : : E1000_TXD_STAT_DD) {
1351 : : /* Increment the number of packets
1352 : : * freed.
1353 : : */
1354 : 0 : count++;
1355 : :
1356 : : /* Get the start of the next packet. */
1357 : 0 : tx_next = sw_ring[tx_last].next_id;
1358 : :
1359 : : /* Loop through all segments in a
1360 : : * packet.
1361 : : */
1362 : : do {
1363 [ # # ]: 0 : if (sw_ring[tx_id].mbuf) {
1364 : : rte_pktmbuf_free_seg(
1365 : : sw_ring[tx_id].mbuf);
1366 : 0 : sw_ring[tx_id].mbuf = NULL;
1367 : 0 : sw_ring[tx_id].last_id = tx_id;
1368 : : }
1369 : :
1370 : : /* Move to next segment. */
1371 : 0 : tx_id = sw_ring[tx_id].next_id;
1372 : :
1373 [ # # ]: 0 : } while (tx_id != tx_next);
1374 : :
1375 [ # # ]: 0 : if (unlikely(count == (int)free_cnt))
1376 : : break;
1377 : : } else {
1378 : : /* mbuf still in use, nothing left to
1379 : : * free.
1380 : : */
1381 : : break;
1382 : : }
1383 : : } else {
1384 : : /* There are multiple reasons to be here:
1385 : : * 1) All the packets on the ring have been
1386 : : * freed - tx_id is equal to tx_first
1387 : : * and some packets have been freed.
1388 : : * - Done, exit
1389 : : * 2) Interfaces has not sent a rings worth of
1390 : : * packets yet, so the segment after tail is
1391 : : * still empty. Or a previous call to this
1392 : : * function freed some of the segments but
1393 : : * not all so there is a hole in the list.
1394 : : * Hopefully this is a rare case.
1395 : : * - Walk the list and find the next mbuf. If
1396 : : * there isn't one, then done.
1397 : : */
1398 [ # # ]: 0 : if (likely(tx_id == tx_first && count != 0))
1399 : : break;
1400 : :
1401 : : /* Walk the list and find the next mbuf, if any. */
1402 : : do {
1403 : : /* Move to next segment. */
1404 : 0 : tx_id = sw_ring[tx_id].next_id;
1405 : :
1406 [ # # ]: 0 : if (sw_ring[tx_id].mbuf)
1407 : : break;
1408 : :
1409 [ # # ]: 0 : } while (tx_id != tx_first);
1410 : :
1411 : : /* Determine why previous loop bailed. If there
1412 : : * is not an mbuf, done.
1413 : : */
1414 [ # # ]: 0 : if (!sw_ring[tx_id].mbuf)
1415 : : break;
1416 : : }
1417 : : }
1418 : :
1419 : : return count;
1420 : : }
1421 : :
1422 : : int
1423 : 0 : eth_igb_tx_done_cleanup(void *txq, uint32_t free_cnt)
1424 : : {
1425 : 0 : return igb_tx_done_cleanup(txq, free_cnt);
1426 : : }
1427 : :
1428 : : static void
1429 : : igb_reset_tx_queue_stat(struct igb_tx_queue *txq)
1430 : : {
1431 : 0 : txq->tx_head = 0;
1432 : 0 : txq->tx_tail = 0;
1433 : 0 : txq->ctx_curr = 0;
1434 : 0 : memset((void*)&txq->ctx_cache, 0,
1435 : : IGB_CTX_NUM * sizeof(struct igb_advctx_info));
1436 : : }
1437 : :
1438 : : static void
1439 : 0 : igb_reset_tx_queue(struct igb_tx_queue *txq, struct rte_eth_dev *dev)
1440 : : {
1441 : : static const union e1000_adv_tx_desc zeroed_desc = {{0}};
1442 : 0 : struct igb_tx_entry *txe = txq->sw_ring;
1443 : : uint16_t i, prev;
1444 : : struct e1000_hw *hw;
1445 : :
1446 : 0 : hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1447 : : /* Zero out HW ring memory */
1448 [ # # ]: 0 : for (i = 0; i < txq->nb_tx_desc; i++) {
1449 : 0 : txq->tx_ring[i] = zeroed_desc;
1450 : : }
1451 : :
1452 : : /* Initialize ring entries */
1453 : 0 : prev = (uint16_t)(txq->nb_tx_desc - 1);
1454 [ # # ]: 0 : for (i = 0; i < txq->nb_tx_desc; i++) {
1455 : 0 : volatile union e1000_adv_tx_desc *txd = &(txq->tx_ring[i]);
1456 : :
1457 : 0 : txd->wb.status = E1000_TXD_STAT_DD;
1458 : 0 : txe[i].mbuf = NULL;
1459 : 0 : txe[i].last_id = i;
1460 : 0 : txe[prev].next_id = i;
1461 : : prev = i;
1462 : : }
1463 : :
1464 : 0 : txq->txd_type = E1000_ADVTXD_DTYP_DATA;
1465 : : /* 82575 specific, each tx queue will use 2 hw contexts */
1466 [ # # ]: 0 : if (hw->mac.type == e1000_82575)
1467 : 0 : txq->ctx_start = txq->queue_id * IGB_CTX_NUM;
1468 : :
1469 : : igb_reset_tx_queue_stat(txq);
1470 : 0 : }
1471 : :
1472 : : uint64_t
1473 : 0 : igb_get_tx_port_offloads_capa(struct rte_eth_dev *dev)
1474 : : {
1475 : : uint64_t tx_offload_capa;
1476 : :
1477 : : RTE_SET_USED(dev);
1478 : : tx_offload_capa = RTE_ETH_TX_OFFLOAD_VLAN_INSERT |
1479 : : RTE_ETH_TX_OFFLOAD_IPV4_CKSUM |
1480 : : RTE_ETH_TX_OFFLOAD_UDP_CKSUM |
1481 : : RTE_ETH_TX_OFFLOAD_TCP_CKSUM |
1482 : : RTE_ETH_TX_OFFLOAD_SCTP_CKSUM |
1483 : : RTE_ETH_TX_OFFLOAD_TCP_TSO |
1484 : : RTE_ETH_TX_OFFLOAD_MULTI_SEGS |
1485 : : RTE_ETH_TX_OFFLOAD_SEND_ON_TIMESTAMP;
1486 : :
1487 : 0 : return tx_offload_capa;
1488 : : }
1489 : :
1490 : : uint64_t
1491 : 0 : igb_get_tx_queue_offloads_capa(struct rte_eth_dev *dev)
1492 : : {
1493 : : RTE_SET_USED(dev);
1494 : :
1495 : 0 : return 0;
1496 : : }
1497 : :
1498 : : int
1499 : 0 : eth_igb_tx_queue_setup(struct rte_eth_dev *dev,
1500 : : uint16_t queue_idx,
1501 : : uint16_t nb_desc,
1502 : : unsigned int socket_id,
1503 : : const struct rte_eth_txconf *tx_conf)
1504 : : {
1505 : : const struct rte_memzone *tz;
1506 : : struct igb_tx_queue *txq;
1507 : : struct e1000_hw *hw;
1508 : : uint32_t size;
1509 : : uint64_t offloads;
1510 : :
1511 : 0 : offloads = tx_conf->offloads | dev->data->dev_conf.txmode.offloads;
1512 : :
1513 : 0 : hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1514 : :
1515 : : /*
1516 : : * Validate number of transmit descriptors.
1517 : : * It must not exceed hardware maximum, and must be multiple
1518 : : * of E1000_ALIGN.
1519 : : */
1520 [ # # ]: 0 : if (nb_desc % IGB_TXD_ALIGN != 0 ||
1521 [ # # ]: 0 : (nb_desc > E1000_MAX_RING_DESC) ||
1522 : : (nb_desc < E1000_MIN_RING_DESC)) {
1523 : : return -EINVAL;
1524 : : }
1525 : :
1526 : : /*
1527 : : * The tx_free_thresh and tx_rs_thresh values are not used in the 1G
1528 : : * driver.
1529 : : */
1530 [ # # ]: 0 : if (tx_conf->tx_free_thresh != 0)
1531 : 0 : PMD_INIT_LOG(INFO, "The tx_free_thresh parameter is not "
1532 : : "used for the 1G driver.");
1533 [ # # ]: 0 : if (tx_conf->tx_rs_thresh != 0)
1534 : 0 : PMD_INIT_LOG(INFO, "The tx_rs_thresh parameter is not "
1535 : : "used for the 1G driver.");
1536 [ # # # # ]: 0 : if (tx_conf->tx_thresh.wthresh == 0 && hw->mac.type != e1000_82576)
1537 : 0 : PMD_INIT_LOG(INFO, "To improve 1G driver performance, "
1538 : : "consider setting the TX WTHRESH value to 4, 8, "
1539 : : "or 16.");
1540 : :
1541 : : /* Free memory prior to re-allocation if needed */
1542 [ # # ]: 0 : if (dev->data->tx_queues[queue_idx] != NULL) {
1543 : 0 : igb_tx_queue_release(dev->data->tx_queues[queue_idx]);
1544 : 0 : dev->data->tx_queues[queue_idx] = NULL;
1545 : : }
1546 : :
1547 : : /* First allocate the tx queue data structure */
1548 : 0 : txq = rte_zmalloc("ethdev TX queue", sizeof(struct igb_tx_queue),
1549 : : RTE_CACHE_LINE_SIZE);
1550 [ # # ]: 0 : if (txq == NULL)
1551 : : return -ENOMEM;
1552 : :
1553 : : /*
1554 : : * Allocate TX ring hardware descriptors. A memzone large enough to
1555 : : * handle the maximum ring size is allocated in order to allow for
1556 : : * resizing in later calls to the queue setup function.
1557 : : */
1558 : : size = sizeof(union e1000_adv_tx_desc) * E1000_MAX_RING_DESC;
1559 : 0 : tz = rte_eth_dma_zone_reserve(dev, "tx_ring", queue_idx, size,
1560 : : E1000_ALIGN, socket_id);
1561 [ # # ]: 0 : if (tz == NULL) {
1562 : 0 : igb_tx_queue_release(txq);
1563 : 0 : return -ENOMEM;
1564 : : }
1565 : :
1566 : 0 : txq->mz = tz;
1567 : 0 : txq->nb_tx_desc = nb_desc;
1568 : 0 : txq->pthresh = tx_conf->tx_thresh.pthresh;
1569 : 0 : txq->hthresh = tx_conf->tx_thresh.hthresh;
1570 : 0 : txq->wthresh = tx_conf->tx_thresh.wthresh;
1571 [ # # # # ]: 0 : if (txq->wthresh > 0 && hw->mac.type == e1000_82576)
1572 : 0 : txq->wthresh = 1;
1573 : 0 : txq->queue_id = queue_idx;
1574 [ # # ]: 0 : txq->reg_idx = (uint16_t)((RTE_ETH_DEV_SRIOV(dev).active == 0) ?
1575 : 0 : queue_idx : RTE_ETH_DEV_SRIOV(dev).def_pool_q_idx + queue_idx);
1576 : 0 : txq->port_id = dev->data->port_id;
1577 : :
1578 [ # # ]: 0 : txq->tdt_reg_addr = E1000_PCI_REG_ADDR(hw, E1000_TDT(txq->reg_idx));
1579 : 0 : txq->tx_ring_phys_addr = tz->iova;
1580 : :
1581 : 0 : txq->tx_ring = (union e1000_adv_tx_desc *) tz->addr;
1582 : : /* Allocate software ring */
1583 : 0 : txq->sw_ring = rte_zmalloc("txq->sw_ring",
1584 : : sizeof(struct igb_tx_entry) * nb_desc,
1585 : : RTE_CACHE_LINE_SIZE);
1586 [ # # ]: 0 : if (txq->sw_ring == NULL) {
1587 : 0 : igb_tx_queue_release(txq);
1588 : 0 : return -ENOMEM;
1589 : : }
1590 : 0 : PMD_INIT_LOG(DEBUG, "sw_ring=%p hw_ring=%p dma_addr=0x%"PRIx64,
1591 : : txq->sw_ring, txq->tx_ring, txq->tx_ring_phys_addr);
1592 : :
1593 : 0 : igb_reset_tx_queue(txq, dev);
1594 : 0 : dev->tx_pkt_burst = eth_igb_xmit_pkts;
1595 : 0 : dev->tx_pkt_prepare = ð_igb_prep_pkts;
1596 : 0 : dev->data->tx_queues[queue_idx] = txq;
1597 : 0 : txq->offloads = offloads;
1598 : :
1599 : 0 : return 0;
1600 : : }
1601 : :
1602 : : static void
1603 : 0 : igb_rx_queue_release_mbufs(struct igb_rx_queue *rxq)
1604 : : {
1605 : : unsigned i;
1606 : :
1607 [ # # ]: 0 : if (rxq->sw_ring != NULL) {
1608 [ # # ]: 0 : for (i = 0; i < rxq->nb_rx_desc; i++) {
1609 [ # # ]: 0 : if (rxq->sw_ring[i].mbuf != NULL) {
1610 : : rte_pktmbuf_free_seg(rxq->sw_ring[i].mbuf);
1611 : 0 : rxq->sw_ring[i].mbuf = NULL;
1612 : : }
1613 : : }
1614 : : }
1615 : 0 : }
1616 : :
1617 : : static void
1618 : 0 : igb_rx_queue_release(struct igb_rx_queue *rxq)
1619 : : {
1620 [ # # ]: 0 : if (rxq != NULL) {
1621 : 0 : igb_rx_queue_release_mbufs(rxq);
1622 : 0 : rte_free(rxq->sw_ring);
1623 : 0 : rte_memzone_free(rxq->mz);
1624 : 0 : rte_free(rxq);
1625 : : }
1626 : 0 : }
1627 : :
1628 : : void
1629 : 0 : eth_igb_rx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
1630 : : {
1631 : 0 : igb_rx_queue_release(dev->data->rx_queues[qid]);
1632 : 0 : }
1633 : :
1634 : : static void
1635 : : igb_reset_rx_queue(struct igb_rx_queue *rxq)
1636 : : {
1637 : : static const union e1000_adv_rx_desc zeroed_desc = {{0}};
1638 : : unsigned i;
1639 : :
1640 : : /* Zero out HW ring memory */
1641 [ # # # # ]: 0 : for (i = 0; i < rxq->nb_rx_desc; i++) {
1642 : 0 : rxq->rx_ring[i] = zeroed_desc;
1643 : : }
1644 : :
1645 : 0 : rxq->rx_tail = 0;
1646 : 0 : rxq->pkt_first_seg = NULL;
1647 : 0 : rxq->pkt_last_seg = NULL;
1648 : : }
1649 : :
1650 : : uint64_t
1651 : 0 : igb_get_rx_port_offloads_capa(struct rte_eth_dev *dev)
1652 : : {
1653 : : uint64_t rx_offload_capa;
1654 : : struct e1000_hw *hw;
1655 : :
1656 : 0 : hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1657 : :
1658 : : rx_offload_capa = RTE_ETH_RX_OFFLOAD_VLAN_STRIP |
1659 : : RTE_ETH_RX_OFFLOAD_VLAN_FILTER |
1660 : : RTE_ETH_RX_OFFLOAD_IPV4_CKSUM |
1661 : : RTE_ETH_RX_OFFLOAD_UDP_CKSUM |
1662 : : RTE_ETH_RX_OFFLOAD_TCP_CKSUM |
1663 : : RTE_ETH_RX_OFFLOAD_KEEP_CRC |
1664 : : RTE_ETH_RX_OFFLOAD_SCATTER |
1665 : : RTE_ETH_RX_OFFLOAD_RSS_HASH;
1666 : :
1667 [ # # ]: 0 : if (hw->mac.type == e1000_82576 ||
1668 [ # # ]: 0 : hw->mac.type == e1000_i350 ||
1669 [ # # ]: 0 : hw->mac.type == e1000_i210 ||
1670 : : hw->mac.type == e1000_i211)
1671 : : rx_offload_capa |= RTE_ETH_RX_OFFLOAD_VLAN_EXTEND;
1672 : :
1673 : 0 : return rx_offload_capa;
1674 : : }
1675 : :
1676 : : uint64_t
1677 : 0 : igb_get_rx_queue_offloads_capa(struct rte_eth_dev *dev)
1678 : : {
1679 : 0 : struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1680 : : uint64_t rx_queue_offload_capa;
1681 : :
1682 [ # # ]: 0 : switch (hw->mac.type) {
1683 : 0 : case e1000_vfadapt_i350:
1684 : : /*
1685 : : * As only one Rx queue can be used, let per queue offloading
1686 : : * capability be same to per port queue offloading capability
1687 : : * for better convenience.
1688 : : */
1689 : 0 : rx_queue_offload_capa = igb_get_rx_port_offloads_capa(dev);
1690 : 0 : break;
1691 : : default:
1692 : : rx_queue_offload_capa = 0;
1693 : : }
1694 : 0 : return rx_queue_offload_capa;
1695 : : }
1696 : :
1697 : : int
1698 : 0 : eth_igb_rx_queue_setup(struct rte_eth_dev *dev,
1699 : : uint16_t queue_idx,
1700 : : uint16_t nb_desc,
1701 : : unsigned int socket_id,
1702 : : const struct rte_eth_rxconf *rx_conf,
1703 : : struct rte_mempool *mp)
1704 : : {
1705 : : const struct rte_memzone *rz;
1706 : : struct igb_rx_queue *rxq;
1707 : : struct e1000_hw *hw;
1708 : : unsigned int size;
1709 : : uint64_t offloads;
1710 : :
1711 : 0 : offloads = rx_conf->offloads | dev->data->dev_conf.rxmode.offloads;
1712 : :
1713 : 0 : hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1714 : :
1715 : : /*
1716 : : * Validate number of receive descriptors.
1717 : : * It must not exceed hardware maximum, and must be multiple
1718 : : * of E1000_ALIGN.
1719 : : */
1720 [ # # ]: 0 : if (nb_desc % IGB_RXD_ALIGN != 0 ||
1721 [ # # ]: 0 : (nb_desc > E1000_MAX_RING_DESC) ||
1722 : : (nb_desc < E1000_MIN_RING_DESC)) {
1723 : : return -EINVAL;
1724 : : }
1725 : :
1726 : : /* Free memory prior to re-allocation if needed */
1727 [ # # ]: 0 : if (dev->data->rx_queues[queue_idx] != NULL) {
1728 : 0 : igb_rx_queue_release(dev->data->rx_queues[queue_idx]);
1729 : 0 : dev->data->rx_queues[queue_idx] = NULL;
1730 : : }
1731 : :
1732 : : /* First allocate the RX queue data structure. */
1733 : 0 : rxq = rte_zmalloc("ethdev RX queue", sizeof(struct igb_rx_queue),
1734 : : RTE_CACHE_LINE_SIZE);
1735 [ # # ]: 0 : if (rxq == NULL)
1736 : : return -ENOMEM;
1737 : 0 : rxq->offloads = offloads;
1738 : 0 : rxq->mb_pool = mp;
1739 : 0 : rxq->nb_rx_desc = nb_desc;
1740 : 0 : rxq->pthresh = rx_conf->rx_thresh.pthresh;
1741 : 0 : rxq->hthresh = rx_conf->rx_thresh.hthresh;
1742 : 0 : rxq->wthresh = rx_conf->rx_thresh.wthresh;
1743 [ # # ]: 0 : if (rxq->wthresh > 0 &&
1744 [ # # ]: 0 : (hw->mac.type == e1000_82576 || hw->mac.type == e1000_vfadapt_i350))
1745 : 0 : rxq->wthresh = 1;
1746 : 0 : rxq->drop_en = rx_conf->rx_drop_en;
1747 : 0 : rxq->rx_free_thresh = rx_conf->rx_free_thresh;
1748 : 0 : rxq->queue_id = queue_idx;
1749 [ # # ]: 0 : rxq->reg_idx = (uint16_t)((RTE_ETH_DEV_SRIOV(dev).active == 0) ?
1750 : 0 : queue_idx : RTE_ETH_DEV_SRIOV(dev).def_pool_q_idx + queue_idx);
1751 : 0 : rxq->port_id = dev->data->port_id;
1752 [ # # ]: 0 : if (dev->data->dev_conf.rxmode.offloads & RTE_ETH_RX_OFFLOAD_KEEP_CRC)
1753 : 0 : rxq->crc_len = RTE_ETHER_CRC_LEN;
1754 : : else
1755 : 0 : rxq->crc_len = 0;
1756 : :
1757 : : /*
1758 : : * Allocate RX ring hardware descriptors. A memzone large enough to
1759 : : * handle the maximum ring size is allocated in order to allow for
1760 : : * resizing in later calls to the queue setup function.
1761 : : */
1762 : : size = sizeof(union e1000_adv_rx_desc) * E1000_MAX_RING_DESC;
1763 : 0 : rz = rte_eth_dma_zone_reserve(dev, "rx_ring", queue_idx, size,
1764 : : E1000_ALIGN, socket_id);
1765 [ # # ]: 0 : if (rz == NULL) {
1766 : 0 : igb_rx_queue_release(rxq);
1767 : 0 : return -ENOMEM;
1768 : : }
1769 : :
1770 : 0 : rxq->mz = rz;
1771 [ # # ]: 0 : rxq->rdt_reg_addr = E1000_PCI_REG_ADDR(hw, E1000_RDT(rxq->reg_idx));
1772 [ # # ]: 0 : rxq->rdh_reg_addr = E1000_PCI_REG_ADDR(hw, E1000_RDH(rxq->reg_idx));
1773 : 0 : rxq->rx_ring_phys_addr = rz->iova;
1774 : 0 : rxq->rx_ring = (union e1000_adv_rx_desc *) rz->addr;
1775 : :
1776 : : /* Allocate software ring. */
1777 : 0 : rxq->sw_ring = rte_zmalloc("rxq->sw_ring",
1778 : : sizeof(struct igb_rx_entry) * nb_desc,
1779 : : RTE_CACHE_LINE_SIZE);
1780 [ # # ]: 0 : if (rxq->sw_ring == NULL) {
1781 : 0 : igb_rx_queue_release(rxq);
1782 : 0 : return -ENOMEM;
1783 : : }
1784 : 0 : PMD_INIT_LOG(DEBUG, "sw_ring=%p hw_ring=%p dma_addr=0x%"PRIx64,
1785 : : rxq->sw_ring, rxq->rx_ring, rxq->rx_ring_phys_addr);
1786 : :
1787 : 0 : dev->data->rx_queues[queue_idx] = rxq;
1788 : : igb_reset_rx_queue(rxq);
1789 : :
1790 : 0 : return 0;
1791 : : }
1792 : :
1793 : : uint32_t
1794 : 0 : eth_igb_rx_queue_count(void *rx_queue)
1795 : : {
1796 : : #define IGB_RXQ_SCAN_INTERVAL 4
1797 : : volatile union e1000_adv_rx_desc *rxdp;
1798 : : struct igb_rx_queue *rxq;
1799 : : uint32_t desc = 0;
1800 : :
1801 : : rxq = rx_queue;
1802 : 0 : rxdp = &(rxq->rx_ring[rxq->rx_tail]);
1803 : :
1804 [ # # ]: 0 : while ((desc < rxq->nb_rx_desc) &&
1805 [ # # ]: 0 : (rxdp->wb.upper.status_error & E1000_RXD_STAT_DD)) {
1806 : 0 : desc += IGB_RXQ_SCAN_INTERVAL;
1807 : 0 : rxdp += IGB_RXQ_SCAN_INTERVAL;
1808 [ # # ]: 0 : if (rxq->rx_tail + desc >= rxq->nb_rx_desc)
1809 : 0 : rxdp = &(rxq->rx_ring[rxq->rx_tail +
1810 : 0 : desc - rxq->nb_rx_desc]);
1811 : : }
1812 : :
1813 : 0 : return desc;
1814 : : }
1815 : :
1816 : : int
1817 : 0 : eth_igb_rx_descriptor_status(void *rx_queue, uint16_t offset)
1818 : : {
1819 : : struct igb_rx_queue *rxq = rx_queue;
1820 : : volatile uint32_t *status;
1821 : : uint32_t desc;
1822 : :
1823 [ # # ]: 0 : if (unlikely(offset >= rxq->nb_rx_desc))
1824 : : return -EINVAL;
1825 : :
1826 [ # # ]: 0 : if (offset >= rxq->nb_rx_desc - rxq->nb_rx_hold)
1827 : : return RTE_ETH_RX_DESC_UNAVAIL;
1828 : :
1829 : 0 : desc = rxq->rx_tail + offset;
1830 [ # # ]: 0 : if (desc >= rxq->nb_rx_desc)
1831 : 0 : desc -= rxq->nb_rx_desc;
1832 : :
1833 : 0 : status = &rxq->rx_ring[desc].wb.upper.status_error;
1834 [ # # ]: 0 : if (*status & rte_cpu_to_le_32(E1000_RXD_STAT_DD))
1835 : 0 : return RTE_ETH_RX_DESC_DONE;
1836 : :
1837 : : return RTE_ETH_RX_DESC_AVAIL;
1838 : : }
1839 : :
1840 : : int
1841 : 0 : eth_igb_tx_descriptor_status(void *tx_queue, uint16_t offset)
1842 : : {
1843 : : struct igb_tx_queue *txq = tx_queue;
1844 : : volatile uint32_t *status;
1845 : : uint32_t desc;
1846 : :
1847 [ # # ]: 0 : if (unlikely(offset >= txq->nb_tx_desc))
1848 : : return -EINVAL;
1849 : :
1850 : 0 : desc = txq->tx_tail + offset;
1851 [ # # ]: 0 : if (desc >= txq->nb_tx_desc)
1852 : 0 : desc -= txq->nb_tx_desc;
1853 : :
1854 : 0 : status = &txq->tx_ring[desc].wb.status;
1855 [ # # ]: 0 : if (*status & rte_cpu_to_le_32(E1000_TXD_STAT_DD))
1856 : 0 : return RTE_ETH_TX_DESC_DONE;
1857 : :
1858 : : return RTE_ETH_TX_DESC_FULL;
1859 : : }
1860 : :
1861 : : void
1862 : 0 : igb_dev_clear_queues(struct rte_eth_dev *dev)
1863 : : {
1864 : : uint16_t i;
1865 : : struct igb_tx_queue *txq;
1866 : : struct igb_rx_queue *rxq;
1867 : :
1868 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
1869 [ # # ]: 0 : __rte_assume(i < RTE_MAX_QUEUES_PER_PORT);
1870 : 0 : txq = dev->data->tx_queues[i];
1871 [ # # ]: 0 : if (txq != NULL) {
1872 : 0 : igb_tx_queue_release_mbufs(txq);
1873 : 0 : igb_reset_tx_queue(txq, dev);
1874 : 0 : dev->data->tx_queue_state[i] = RTE_ETH_QUEUE_STATE_STOPPED;
1875 : : }
1876 : : }
1877 : :
1878 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
1879 [ # # ]: 0 : __rte_assume(i < RTE_MAX_QUEUES_PER_PORT);
1880 : 0 : rxq = dev->data->rx_queues[i];
1881 [ # # ]: 0 : if (rxq != NULL) {
1882 : 0 : igb_rx_queue_release_mbufs(rxq);
1883 : : igb_reset_rx_queue(rxq);
1884 : 0 : dev->data->rx_queue_state[i] = RTE_ETH_QUEUE_STATE_STOPPED;
1885 : : }
1886 : : }
1887 : 0 : }
1888 : :
1889 : : void
1890 : 0 : igb_dev_free_queues(struct rte_eth_dev *dev)
1891 : : {
1892 : : uint16_t i;
1893 : :
1894 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
1895 : 0 : eth_igb_rx_queue_release(dev, i);
1896 : 0 : dev->data->rx_queues[i] = NULL;
1897 : : }
1898 : 0 : dev->data->nb_rx_queues = 0;
1899 : :
1900 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
1901 : 0 : eth_igb_tx_queue_release(dev, i);
1902 : 0 : dev->data->tx_queues[i] = NULL;
1903 : : }
1904 : 0 : dev->data->nb_tx_queues = 0;
1905 : 0 : }
1906 : :
1907 : : /**
1908 : : * Receive Side Scaling (RSS).
1909 : : * See section 7.1.1.7 in the following document:
1910 : : * "Intel 82576 GbE Controller Datasheet" - Revision 2.45 October 2009
1911 : : *
1912 : : * Principles:
1913 : : * The source and destination IP addresses of the IP header and the source and
1914 : : * destination ports of TCP/UDP headers, if any, of received packets are hashed
1915 : : * against a configurable random key to compute a 32-bit RSS hash result.
1916 : : * The seven (7) LSBs of the 32-bit hash result are used as an index into a
1917 : : * 128-entry redirection table (RETA). Each entry of the RETA provides a 3-bit
1918 : : * RSS output index which is used as the RX queue index where to store the
1919 : : * received packets.
1920 : : * The following output is supplied in the RX write-back descriptor:
1921 : : * - 32-bit result of the Microsoft RSS hash function,
1922 : : * - 4-bit RSS type field.
1923 : : */
1924 : :
1925 : : /*
1926 : : * RSS random key supplied in section 7.1.1.7.3 of the Intel 82576 datasheet.
1927 : : * Used as the default key.
1928 : : */
1929 : : static uint8_t rss_intel_key[40] = {
1930 : : 0x6D, 0x5A, 0x56, 0xDA, 0x25, 0x5B, 0x0E, 0xC2,
1931 : : 0x41, 0x67, 0x25, 0x3D, 0x43, 0xA3, 0x8F, 0xB0,
1932 : : 0xD0, 0xCA, 0x2B, 0xCB, 0xAE, 0x7B, 0x30, 0xB4,
1933 : : 0x77, 0xCB, 0x2D, 0xA3, 0x80, 0x30, 0xF2, 0x0C,
1934 : : 0x6A, 0x42, 0xB7, 0x3B, 0xBE, 0xAC, 0x01, 0xFA,
1935 : : };
1936 : :
1937 : : static void
1938 : : igb_rss_disable(struct rte_eth_dev *dev)
1939 : : {
1940 : : struct e1000_hw *hw;
1941 : : uint32_t mrqc;
1942 : :
1943 : 0 : hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1944 : 0 : mrqc = E1000_READ_REG(hw, E1000_MRQC);
1945 : 0 : mrqc &= ~E1000_MRQC_ENABLE_MASK;
1946 : 0 : E1000_WRITE_REG(hw, E1000_MRQC, mrqc);
1947 : 0 : }
1948 : :
1949 : : static void
1950 : 0 : igb_hw_rss_hash_set(struct e1000_hw *hw, struct rte_eth_rss_conf *rss_conf)
1951 : : {
1952 : : uint8_t *hash_key;
1953 : : uint32_t rss_key;
1954 : : uint32_t mrqc;
1955 : : uint64_t rss_hf;
1956 : : uint16_t i;
1957 : :
1958 : 0 : hash_key = rss_conf->rss_key;
1959 [ # # ]: 0 : if (hash_key != NULL) {
1960 : : /* Fill in RSS hash key */
1961 [ # # ]: 0 : for (i = 0; i < 10; i++) {
1962 : 0 : rss_key = hash_key[(i * 4)];
1963 : 0 : rss_key |= hash_key[(i * 4) + 1] << 8;
1964 : 0 : rss_key |= hash_key[(i * 4) + 2] << 16;
1965 : 0 : rss_key |= hash_key[(i * 4) + 3] << 24;
1966 : 0 : E1000_WRITE_REG_ARRAY(hw, E1000_RSSRK(0), i, rss_key);
1967 : : }
1968 : : }
1969 : :
1970 : : /* Set configured hashing protocols in MRQC register */
1971 : 0 : rss_hf = rss_conf->rss_hf;
1972 : : mrqc = E1000_MRQC_ENABLE_RSS_4Q; /* RSS enabled. */
1973 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_IPV4)
1974 : : mrqc |= E1000_MRQC_RSS_FIELD_IPV4;
1975 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_NONFRAG_IPV4_TCP)
1976 : 0 : mrqc |= E1000_MRQC_RSS_FIELD_IPV4_TCP;
1977 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_IPV6)
1978 : 0 : mrqc |= E1000_MRQC_RSS_FIELD_IPV6;
1979 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_IPV6_EX)
1980 : 0 : mrqc |= E1000_MRQC_RSS_FIELD_IPV6_EX;
1981 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_NONFRAG_IPV6_TCP)
1982 : 0 : mrqc |= E1000_MRQC_RSS_FIELD_IPV6_TCP;
1983 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_IPV6_TCP_EX)
1984 : 0 : mrqc |= E1000_MRQC_RSS_FIELD_IPV6_TCP_EX;
1985 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_NONFRAG_IPV4_UDP)
1986 : 0 : mrqc |= E1000_MRQC_RSS_FIELD_IPV4_UDP;
1987 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_NONFRAG_IPV6_UDP)
1988 : 0 : mrqc |= E1000_MRQC_RSS_FIELD_IPV6_UDP;
1989 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_IPV6_UDP_EX)
1990 : 0 : mrqc |= E1000_MRQC_RSS_FIELD_IPV6_UDP_EX;
1991 : 0 : E1000_WRITE_REG(hw, E1000_MRQC, mrqc);
1992 : 0 : }
1993 : :
1994 : : int
1995 : 0 : eth_igb_rss_hash_update(struct rte_eth_dev *dev,
1996 : : struct rte_eth_rss_conf *rss_conf)
1997 : : {
1998 : : struct e1000_hw *hw;
1999 : : uint32_t mrqc;
2000 : : uint64_t rss_hf;
2001 : :
2002 : 0 : hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2003 : :
2004 : : /*
2005 : : * Before changing anything, first check that the update RSS operation
2006 : : * does not attempt to disable RSS, if RSS was enabled at
2007 : : * initialization time, or does not attempt to enable RSS, if RSS was
2008 : : * disabled at initialization time.
2009 : : */
2010 : 0 : rss_hf = rss_conf->rss_hf & IGB_RSS_OFFLOAD_ALL;
2011 : 0 : mrqc = E1000_READ_REG(hw, E1000_MRQC);
2012 [ # # ]: 0 : if (!(mrqc & E1000_MRQC_ENABLE_MASK)) { /* RSS disabled */
2013 [ # # ]: 0 : if (rss_hf != 0) /* Enable RSS */
2014 : : return -(EINVAL);
2015 : 0 : return 0; /* Nothing to do */
2016 : : }
2017 : : /* RSS enabled */
2018 [ # # ]: 0 : if (rss_hf == 0) /* Disable RSS */
2019 : : return -(EINVAL);
2020 : 0 : igb_hw_rss_hash_set(hw, rss_conf);
2021 : 0 : return 0;
2022 : : }
2023 : :
2024 : 0 : int eth_igb_rss_hash_conf_get(struct rte_eth_dev *dev,
2025 : : struct rte_eth_rss_conf *rss_conf)
2026 : : {
2027 : : struct e1000_hw *hw;
2028 : : uint8_t *hash_key;
2029 : : uint32_t rss_key;
2030 : : uint32_t mrqc;
2031 : : uint64_t rss_hf;
2032 : : uint16_t i;
2033 : :
2034 : 0 : hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2035 : 0 : hash_key = rss_conf->rss_key;
2036 [ # # ]: 0 : if (hash_key != NULL) {
2037 : : /* Return RSS hash key */
2038 [ # # ]: 0 : for (i = 0; i < 10; i++) {
2039 : 0 : rss_key = E1000_READ_REG_ARRAY(hw, E1000_RSSRK(0), i);
2040 : 0 : hash_key[(i * 4)] = rss_key & 0x000000FF;
2041 : 0 : hash_key[(i * 4) + 1] = (rss_key >> 8) & 0x000000FF;
2042 : 0 : hash_key[(i * 4) + 2] = (rss_key >> 16) & 0x000000FF;
2043 : 0 : hash_key[(i * 4) + 3] = (rss_key >> 24) & 0x000000FF;
2044 : : }
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 : : }
|