1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2020 Intel Corporation
5 #include <rte_config.h>
7 #include <rte_malloc.h>
8 #include <ethdev_driver.h>
14 #ifdef RTE_PMD_USE_PREFETCH
15 #define rte_igc_prefetch(p) rte_prefetch0(p)
17 #define rte_igc_prefetch(p) do {} while (0)
20 #ifdef RTE_PMD_PACKET_PREFETCH
21 #define rte_packet_prefetch(p) rte_prefetch1(p)
23 #define rte_packet_prefetch(p) do {} while (0)
26 /* Multicast / Unicast table offset mask. */
27 #define IGC_RCTL_MO_MSK (3u << IGC_RCTL_MO_SHIFT)
30 #define IGC_RCTL_LBM_SHIFT 6
31 #define IGC_RCTL_LBM_MSK (3u << IGC_RCTL_LBM_SHIFT)
33 /* Hash select for MTA */
34 #define IGC_RCTL_HSEL_SHIFT 8
35 #define IGC_RCTL_HSEL_MSK (3u << IGC_RCTL_HSEL_SHIFT)
36 #define IGC_RCTL_PSP (1u << 21)
38 /* Receive buffer size for header buffer */
39 #define IGC_SRRCTL_BSIZEHEADER_SHIFT 8
41 /* RX descriptor status and error flags */
42 #define IGC_RXD_STAT_L4CS (1u << 5)
43 #define IGC_RXD_STAT_VEXT (1u << 9)
44 #define IGC_RXD_STAT_LLINT (1u << 11)
45 #define IGC_RXD_STAT_SCRC (1u << 12)
46 #define IGC_RXD_STAT_SMDT_MASK (3u << 13)
47 #define IGC_RXD_STAT_MC (1u << 19)
48 #define IGC_RXD_EXT_ERR_L4E (1u << 29)
49 #define IGC_RXD_EXT_ERR_IPE (1u << 30)
50 #define IGC_RXD_EXT_ERR_RXE (1u << 31)
51 #define IGC_RXD_RSS_TYPE_MASK 0xfu
52 #define IGC_RXD_PCTYPE_MASK (0x7fu << 4)
53 #define IGC_RXD_ETQF_SHIFT 12
54 #define IGC_RXD_ETQF_MSK (0xfu << IGC_RXD_ETQF_SHIFT)
55 #define IGC_RXD_VPKT (1u << 16)
57 /* TXD control bits */
58 #define IGC_TXDCTL_PTHRESH_SHIFT 0
59 #define IGC_TXDCTL_HTHRESH_SHIFT 8
60 #define IGC_TXDCTL_WTHRESH_SHIFT 16
61 #define IGC_TXDCTL_PTHRESH_MSK (0x1fu << IGC_TXDCTL_PTHRESH_SHIFT)
62 #define IGC_TXDCTL_HTHRESH_MSK (0x1fu << IGC_TXDCTL_HTHRESH_SHIFT)
63 #define IGC_TXDCTL_WTHRESH_MSK (0x1fu << IGC_TXDCTL_WTHRESH_SHIFT)
65 /* RXD control bits */
66 #define IGC_RXDCTL_PTHRESH_SHIFT 0
67 #define IGC_RXDCTL_HTHRESH_SHIFT 8
68 #define IGC_RXDCTL_WTHRESH_SHIFT 16
69 #define IGC_RXDCTL_PTHRESH_MSK (0x1fu << IGC_RXDCTL_PTHRESH_SHIFT)
70 #define IGC_RXDCTL_HTHRESH_MSK (0x1fu << IGC_RXDCTL_HTHRESH_SHIFT)
71 #define IGC_RXDCTL_WTHRESH_MSK (0x1fu << IGC_RXDCTL_WTHRESH_SHIFT)
73 #define IGC_TSO_MAX_HDRLEN 512
74 #define IGC_TSO_MAX_MSS 9216
76 /* Bit Mask to indicate what bits required for building TX context */
77 #define IGC_TX_OFFLOAD_MASK (RTE_MBUF_F_TX_OUTER_IPV4 | \
78 RTE_MBUF_F_TX_IPV6 | \
79 RTE_MBUF_F_TX_IPV4 | \
80 RTE_MBUF_F_TX_VLAN | \
81 RTE_MBUF_F_TX_IP_CKSUM | \
82 RTE_MBUF_F_TX_L4_MASK | \
83 RTE_MBUF_F_TX_TCP_SEG | \
84 RTE_MBUF_F_TX_UDP_SEG)
86 #define IGC_TX_OFFLOAD_SEG (RTE_MBUF_F_TX_TCP_SEG | RTE_MBUF_F_TX_UDP_SEG)
88 #define IGC_ADVTXD_POPTS_TXSM 0x00000200 /* L4 Checksum offload request */
89 #define IGC_ADVTXD_POPTS_IXSM 0x00000100 /* IP Checksum offload request */
91 /* L4 Packet TYPE of Reserved */
92 #define IGC_ADVTXD_TUCMD_L4T_RSV 0x00001800
94 #define IGC_TX_OFFLOAD_NOTSUP_MASK (RTE_MBUF_F_TX_OFFLOAD_MASK ^ IGC_TX_OFFLOAD_MASK)
97 * Structure associated with each descriptor of the RX ring of a RX queue.
100 struct rte_mbuf *mbuf; /**< mbuf associated with RX descriptor. */
104 * Structure associated with each RX queue.
106 struct igc_rx_queue {
107 struct rte_mempool *mb_pool; /**< mbuf pool to populate RX ring. */
108 volatile union igc_adv_rx_desc *rx_ring;
109 /**< RX ring virtual address. */
110 uint64_t rx_ring_phys_addr; /**< RX ring DMA address. */
111 volatile uint32_t *rdt_reg_addr; /**< RDT register address. */
112 volatile uint32_t *rdh_reg_addr; /**< RDH register address. */
113 struct igc_rx_entry *sw_ring; /**< address of RX software ring. */
114 struct rte_mbuf *pkt_first_seg; /**< First segment of current packet. */
115 struct rte_mbuf *pkt_last_seg; /**< Last segment of current packet. */
116 uint16_t nb_rx_desc; /**< number of RX descriptors. */
117 uint16_t rx_tail; /**< current value of RDT register. */
118 uint16_t nb_rx_hold; /**< number of held free RX desc. */
119 uint16_t rx_free_thresh; /**< max free RX desc to hold. */
120 uint16_t queue_id; /**< RX queue index. */
121 uint16_t reg_idx; /**< RX queue register index. */
122 uint16_t port_id; /**< Device port identifier. */
123 uint8_t pthresh; /**< Prefetch threshold register. */
124 uint8_t hthresh; /**< Host threshold register. */
125 uint8_t wthresh; /**< Write-back threshold register. */
126 uint8_t crc_len; /**< 0 if CRC stripped, 4 otherwise. */
127 uint8_t drop_en; /**< If not 0, set SRRCTL.Drop_En. */
128 uint32_t flags; /**< RX flags. */
129 uint64_t offloads; /**< offloads of RTE_ETH_RX_OFFLOAD_* */
132 /** Offload features */
133 union igc_tx_offload {
136 uint64_t l3_len:9; /**< L3 (IP) Header Length. */
137 uint64_t l2_len:7; /**< L2 (MAC) Header Length. */
138 uint64_t vlan_tci:16;
139 /**< VLAN Tag Control Identifier(CPU order). */
140 uint64_t l4_len:8; /**< L4 (TCP/UDP) Header Length. */
141 uint64_t tso_segsz:16; /**< TCP TSO segment size. */
142 /* uint64_t unused:8; */
147 * Compare mask for igc_tx_offload.data,
148 * should be in sync with igc_tx_offload layout.
150 #define TX_MACIP_LEN_CMP_MASK 0x000000000000FFFFULL /**< L2L3 header mask. */
151 #define TX_VLAN_CMP_MASK 0x00000000FFFF0000ULL /**< Vlan mask. */
152 #define TX_TCP_LEN_CMP_MASK 0x000000FF00000000ULL /**< TCP header mask. */
153 #define TX_TSO_MSS_CMP_MASK 0x00FFFF0000000000ULL /**< TSO segsz mask. */
154 /** Mac + IP + TCP + Mss mask. */
155 #define TX_TSO_CMP_MASK \
156 (TX_MACIP_LEN_CMP_MASK | TX_TCP_LEN_CMP_MASK | TX_TSO_MSS_CMP_MASK)
159 * Structure to check if new context need be built
161 struct igc_advctx_info {
162 uint64_t flags; /**< ol_flags related to context build. */
163 /** tx offload: vlan, tso, l2-l3-l4 lengths. */
164 union igc_tx_offload tx_offload;
165 /** compare mask for tx offload. */
166 union igc_tx_offload tx_offload_mask;
170 * Hardware context number
173 IGC_CTX_0 = 0, /**< CTX0 */
174 IGC_CTX_1 = 1, /**< CTX1 */
175 IGC_CTX_NUM = 2, /**< CTX_NUM */
179 * Structure associated with each descriptor of the TX ring of a TX queue.
181 struct igc_tx_entry {
182 struct rte_mbuf *mbuf; /**< mbuf associated with TX desc, if any. */
183 uint16_t next_id; /**< Index of next descriptor in ring. */
184 uint16_t last_id; /**< Index of last scattered descriptor. */
188 * Structure associated with each TX queue.
190 struct igc_tx_queue {
191 volatile union igc_adv_tx_desc *tx_ring; /**< TX ring address */
192 uint64_t tx_ring_phys_addr; /**< TX ring DMA address. */
193 struct igc_tx_entry *sw_ring; /**< virtual address of SW ring. */
194 volatile uint32_t *tdt_reg_addr; /**< Address of TDT register. */
195 uint32_t txd_type; /**< Device-specific TXD type */
196 uint16_t nb_tx_desc; /**< number of TX descriptors. */
197 uint16_t tx_tail; /**< Current value of TDT register. */
199 /**< Index of first used TX descriptor. */
200 uint16_t queue_id; /**< TX queue index. */
201 uint16_t reg_idx; /**< TX queue register index. */
202 uint16_t port_id; /**< Device port identifier. */
203 uint8_t pthresh; /**< Prefetch threshold register. */
204 uint8_t hthresh; /**< Host threshold register. */
205 uint8_t wthresh; /**< Write-back threshold register. */
208 /**< Start context position for transmit queue. */
209 struct igc_advctx_info ctx_cache[IGC_CTX_NUM];
210 /**< Hardware context history.*/
211 uint64_t offloads; /**< offloads of RTE_ETH_TX_OFFLOAD_* */
214 static inline uint64_t
215 rx_desc_statuserr_to_pkt_flags(uint32_t statuserr)
217 static uint64_t l4_chksum_flags[] = {0, 0,
218 RTE_MBUF_F_RX_L4_CKSUM_GOOD,
219 RTE_MBUF_F_RX_L4_CKSUM_BAD};
221 static uint64_t l3_chksum_flags[] = {0, 0,
222 RTE_MBUF_F_RX_IP_CKSUM_GOOD,
223 RTE_MBUF_F_RX_IP_CKSUM_BAD};
224 uint64_t pkt_flags = 0;
227 if (statuserr & IGC_RXD_STAT_VP)
228 pkt_flags |= RTE_MBUF_F_RX_VLAN_STRIPPED;
230 tmp = !!(statuserr & (IGC_RXD_STAT_L4CS | IGC_RXD_STAT_UDPCS));
231 tmp = (tmp << 1) | (uint32_t)!!(statuserr & IGC_RXD_EXT_ERR_L4E);
232 pkt_flags |= l4_chksum_flags[tmp];
234 tmp = !!(statuserr & IGC_RXD_STAT_IPCS);
235 tmp = (tmp << 1) | (uint32_t)!!(statuserr & IGC_RXD_EXT_ERR_IPE);
236 pkt_flags |= l3_chksum_flags[tmp];
241 #define IGC_PACKET_TYPE_IPV4 0X01
242 #define IGC_PACKET_TYPE_IPV4_TCP 0X11
243 #define IGC_PACKET_TYPE_IPV4_UDP 0X21
244 #define IGC_PACKET_TYPE_IPV4_SCTP 0X41
245 #define IGC_PACKET_TYPE_IPV4_EXT 0X03
246 #define IGC_PACKET_TYPE_IPV4_EXT_SCTP 0X43
247 #define IGC_PACKET_TYPE_IPV6 0X04
248 #define IGC_PACKET_TYPE_IPV6_TCP 0X14
249 #define IGC_PACKET_TYPE_IPV6_UDP 0X24
250 #define IGC_PACKET_TYPE_IPV6_EXT 0X0C
251 #define IGC_PACKET_TYPE_IPV6_EXT_TCP 0X1C
252 #define IGC_PACKET_TYPE_IPV6_EXT_UDP 0X2C
253 #define IGC_PACKET_TYPE_IPV4_IPV6 0X05
254 #define IGC_PACKET_TYPE_IPV4_IPV6_TCP 0X15
255 #define IGC_PACKET_TYPE_IPV4_IPV6_UDP 0X25
256 #define IGC_PACKET_TYPE_IPV4_IPV6_EXT 0X0D
257 #define IGC_PACKET_TYPE_IPV4_IPV6_EXT_TCP 0X1D
258 #define IGC_PACKET_TYPE_IPV4_IPV6_EXT_UDP 0X2D
259 #define IGC_PACKET_TYPE_MAX 0X80
260 #define IGC_PACKET_TYPE_MASK 0X7F
261 #define IGC_PACKET_TYPE_SHIFT 0X04
263 static inline uint32_t
264 rx_desc_pkt_info_to_pkt_type(uint32_t pkt_info)
266 static const uint32_t
267 ptype_table[IGC_PACKET_TYPE_MAX] __rte_cache_aligned = {
268 [IGC_PACKET_TYPE_IPV4] = RTE_PTYPE_L2_ETHER |
270 [IGC_PACKET_TYPE_IPV4_EXT] = RTE_PTYPE_L2_ETHER |
271 RTE_PTYPE_L3_IPV4_EXT,
272 [IGC_PACKET_TYPE_IPV6] = RTE_PTYPE_L2_ETHER |
274 [IGC_PACKET_TYPE_IPV4_IPV6] = RTE_PTYPE_L2_ETHER |
275 RTE_PTYPE_L3_IPV4 | RTE_PTYPE_TUNNEL_IP |
276 RTE_PTYPE_INNER_L3_IPV6,
277 [IGC_PACKET_TYPE_IPV6_EXT] = RTE_PTYPE_L2_ETHER |
278 RTE_PTYPE_L3_IPV6_EXT,
279 [IGC_PACKET_TYPE_IPV4_IPV6_EXT] = RTE_PTYPE_L2_ETHER |
280 RTE_PTYPE_L3_IPV4 | RTE_PTYPE_TUNNEL_IP |
281 RTE_PTYPE_INNER_L3_IPV6_EXT,
282 [IGC_PACKET_TYPE_IPV4_TCP] = RTE_PTYPE_L2_ETHER |
283 RTE_PTYPE_L3_IPV4 | RTE_PTYPE_L4_TCP,
284 [IGC_PACKET_TYPE_IPV6_TCP] = RTE_PTYPE_L2_ETHER |
285 RTE_PTYPE_L3_IPV6 | RTE_PTYPE_L4_TCP,
286 [IGC_PACKET_TYPE_IPV4_IPV6_TCP] = RTE_PTYPE_L2_ETHER |
287 RTE_PTYPE_L3_IPV4 | RTE_PTYPE_TUNNEL_IP |
288 RTE_PTYPE_INNER_L3_IPV6 | RTE_PTYPE_INNER_L4_TCP,
289 [IGC_PACKET_TYPE_IPV6_EXT_TCP] = RTE_PTYPE_L2_ETHER |
290 RTE_PTYPE_L3_IPV6_EXT | RTE_PTYPE_L4_TCP,
291 [IGC_PACKET_TYPE_IPV4_IPV6_EXT_TCP] = RTE_PTYPE_L2_ETHER |
292 RTE_PTYPE_L3_IPV4 | RTE_PTYPE_TUNNEL_IP |
293 RTE_PTYPE_INNER_L3_IPV6_EXT | RTE_PTYPE_INNER_L4_TCP,
294 [IGC_PACKET_TYPE_IPV4_UDP] = RTE_PTYPE_L2_ETHER |
295 RTE_PTYPE_L3_IPV4 | RTE_PTYPE_L4_UDP,
296 [IGC_PACKET_TYPE_IPV6_UDP] = RTE_PTYPE_L2_ETHER |
297 RTE_PTYPE_L3_IPV6 | RTE_PTYPE_L4_UDP,
298 [IGC_PACKET_TYPE_IPV4_IPV6_UDP] = RTE_PTYPE_L2_ETHER |
299 RTE_PTYPE_L3_IPV4 | RTE_PTYPE_TUNNEL_IP |
300 RTE_PTYPE_INNER_L3_IPV6 | RTE_PTYPE_INNER_L4_UDP,
301 [IGC_PACKET_TYPE_IPV6_EXT_UDP] = RTE_PTYPE_L2_ETHER |
302 RTE_PTYPE_L3_IPV6_EXT | RTE_PTYPE_L4_UDP,
303 [IGC_PACKET_TYPE_IPV4_IPV6_EXT_UDP] = RTE_PTYPE_L2_ETHER |
304 RTE_PTYPE_L3_IPV4 | RTE_PTYPE_TUNNEL_IP |
305 RTE_PTYPE_INNER_L3_IPV6_EXT | RTE_PTYPE_INNER_L4_UDP,
306 [IGC_PACKET_TYPE_IPV4_SCTP] = RTE_PTYPE_L2_ETHER |
307 RTE_PTYPE_L3_IPV4 | RTE_PTYPE_L4_SCTP,
308 [IGC_PACKET_TYPE_IPV4_EXT_SCTP] = RTE_PTYPE_L2_ETHER |
309 RTE_PTYPE_L3_IPV4_EXT | RTE_PTYPE_L4_SCTP,
311 if (unlikely(pkt_info & IGC_RXDADV_PKTTYPE_ETQF))
312 return RTE_PTYPE_UNKNOWN;
314 pkt_info = (pkt_info >> IGC_PACKET_TYPE_SHIFT) & IGC_PACKET_TYPE_MASK;
316 return ptype_table[pkt_info];
320 rx_desc_get_pkt_info(struct igc_rx_queue *rxq, struct rte_mbuf *rxm,
321 union igc_adv_rx_desc *rxd, uint32_t staterr)
324 uint32_t hlen_type_rss;
327 /* Prefetch data of first segment, if configured to do so. */
328 rte_packet_prefetch((char *)rxm->buf_addr + rxm->data_off);
330 rxm->port = rxq->port_id;
331 hlen_type_rss = rte_le_to_cpu_32(rxd->wb.lower.lo_dword.data);
332 rxm->hash.rss = rte_le_to_cpu_32(rxd->wb.lower.hi_dword.rss);
333 rxm->vlan_tci = rte_le_to_cpu_16(rxd->wb.upper.vlan);
335 pkt_flags = (hlen_type_rss & IGC_RXD_RSS_TYPE_MASK) ?
336 RTE_MBUF_F_RX_RSS_HASH : 0;
338 if (hlen_type_rss & IGC_RXD_VPKT)
339 pkt_flags |= RTE_MBUF_F_RX_VLAN;
341 pkt_flags |= rx_desc_statuserr_to_pkt_flags(staterr);
343 rxm->ol_flags = pkt_flags;
344 pkt_info = rte_le_to_cpu_16(rxd->wb.lower.lo_dword.hs_rss.pkt_info);
345 rxm->packet_type = rx_desc_pkt_info_to_pkt_type(pkt_info);
349 igc_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
351 struct igc_rx_queue * const rxq = rx_queue;
352 volatile union igc_adv_rx_desc * const rx_ring = rxq->rx_ring;
353 struct igc_rx_entry * const sw_ring = rxq->sw_ring;
354 uint16_t rx_id = rxq->rx_tail;
356 uint16_t nb_hold = 0;
358 while (nb_rx < nb_pkts) {
359 volatile union igc_adv_rx_desc *rxdp;
360 struct igc_rx_entry *rxe;
361 struct rte_mbuf *rxm;
362 struct rte_mbuf *nmb;
363 union igc_adv_rx_desc rxd;
368 * The order of operations here is important as the DD status
369 * bit must not be read after any other descriptor fields.
370 * rx_ring and rxdp are pointing to volatile data so the order
371 * of accesses cannot be reordered by the compiler. If they were
372 * not volatile, they could be reordered which could lead to
373 * using invalid descriptor fields when read from rxd.
375 rxdp = &rx_ring[rx_id];
376 staterr = rte_cpu_to_le_32(rxdp->wb.upper.status_error);
377 if (!(staterr & IGC_RXD_STAT_DD))
384 * If the IGC_RXD_STAT_EOP flag is not set, the RX packet is
385 * likely to be invalid and to be dropped by the various
386 * validation checks performed by the network stack.
388 * Allocate a new mbuf to replenish the RX ring descriptor.
389 * If the allocation fails:
390 * - arrange for that RX descriptor to be the first one
391 * being parsed the next time the receive function is
392 * invoked [on the same queue].
394 * - Stop parsing the RX ring and return immediately.
396 * This policy does not drop the packet received in the RX
397 * descriptor for which the allocation of a new mbuf failed.
398 * Thus, it allows that packet to be later retrieved if
399 * mbuf have been freed in the mean time.
400 * As a side effect, holding RX descriptors instead of
401 * systematically giving them back to the NIC may lead to
402 * RX ring exhaustion situations.
403 * However, the NIC can gracefully prevent such situations
404 * to happen by sending specific "back-pressure" flow control
405 * frames to its peer(s).
408 "port_id=%u queue_id=%u rx_id=%u staterr=0x%x data_len=%u",
409 rxq->port_id, rxq->queue_id, rx_id, staterr,
410 rte_le_to_cpu_16(rxd.wb.upper.length));
412 nmb = rte_mbuf_raw_alloc(rxq->mb_pool);
416 "RX mbuf alloc failed, port_id=%u queue_id=%u",
417 rxq->port_id, rxq->queue_id);
419 rte_eth_devices[id].data->rx_mbuf_alloc_failed++;
424 rxe = &sw_ring[rx_id];
426 if (rx_id >= rxq->nb_rx_desc)
429 /* Prefetch next mbuf while processing current one. */
430 rte_igc_prefetch(sw_ring[rx_id].mbuf);
433 * When next RX descriptor is on a cache-line boundary,
434 * prefetch the next 4 RX descriptors and the next 8 pointers
437 if ((rx_id & 0x3) == 0) {
438 rte_igc_prefetch(&rx_ring[rx_id]);
439 rte_igc_prefetch(&sw_ring[rx_id]);
443 * Update RX descriptor with the physical address of the new
444 * data buffer of the new allocated mbuf.
448 rxdp->read.hdr_addr = 0;
449 rxdp->read.pkt_addr =
450 rte_cpu_to_le_64(rte_mbuf_data_iova_default(nmb));
453 rxm->data_off = RTE_PKTMBUF_HEADROOM;
454 data_len = rte_le_to_cpu_16(rxd.wb.upper.length) - rxq->crc_len;
455 rxm->data_len = data_len;
456 rxm->pkt_len = data_len;
459 rx_desc_get_pkt_info(rxq, rxm, &rxd, staterr);
462 * Store the mbuf address into the next entry of the array
463 * of returned packets.
465 rx_pkts[nb_rx++] = rxm;
467 rxq->rx_tail = rx_id;
470 * If the number of free RX descriptors is greater than the RX free
471 * threshold of the queue, advance the Receive Descriptor Tail (RDT)
473 * Update the RDT with the value of the last processed RX descriptor
474 * minus 1, to guarantee that the RDT register is never equal to the
475 * RDH register, which creates a "full" ring situation from the
476 * hardware point of view...
478 nb_hold = nb_hold + rxq->nb_rx_hold;
479 if (nb_hold > rxq->rx_free_thresh) {
481 "port_id=%u queue_id=%u rx_tail=%u nb_hold=%u nb_rx=%u",
482 rxq->port_id, rxq->queue_id, rx_id, nb_hold, nb_rx);
483 rx_id = (rx_id == 0) ? (rxq->nb_rx_desc - 1) : (rx_id - 1);
484 IGC_PCI_REG_WRITE(rxq->rdt_reg_addr, rx_id);
487 rxq->nb_rx_hold = nb_hold;
492 igc_recv_scattered_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
495 struct igc_rx_queue * const rxq = rx_queue;
496 volatile union igc_adv_rx_desc * const rx_ring = rxq->rx_ring;
497 struct igc_rx_entry * const sw_ring = rxq->sw_ring;
498 struct rte_mbuf *first_seg = rxq->pkt_first_seg;
499 struct rte_mbuf *last_seg = rxq->pkt_last_seg;
501 uint16_t rx_id = rxq->rx_tail;
503 uint16_t nb_hold = 0;
505 while (nb_rx < nb_pkts) {
506 volatile union igc_adv_rx_desc *rxdp;
507 struct igc_rx_entry *rxe;
508 struct rte_mbuf *rxm;
509 struct rte_mbuf *nmb;
510 union igc_adv_rx_desc rxd;
516 * The order of operations here is important as the DD status
517 * bit must not be read after any other descriptor fields.
518 * rx_ring and rxdp are pointing to volatile data so the order
519 * of accesses cannot be reordered by the compiler. If they were
520 * not volatile, they could be reordered which could lead to
521 * using invalid descriptor fields when read from rxd.
523 rxdp = &rx_ring[rx_id];
524 staterr = rte_cpu_to_le_32(rxdp->wb.upper.status_error);
525 if (!(staterr & IGC_RXD_STAT_DD))
532 * Allocate a new mbuf to replenish the RX ring descriptor.
533 * If the allocation fails:
534 * - arrange for that RX descriptor to be the first one
535 * being parsed the next time the receive function is
536 * invoked [on the same queue].
538 * - Stop parsing the RX ring and return immediately.
540 * This policy does not drop the packet received in the RX
541 * descriptor for which the allocation of a new mbuf failed.
542 * Thus, it allows that packet to be later retrieved if
543 * mbuf have been freed in the mean time.
544 * As a side effect, holding RX descriptors instead of
545 * systematically giving them back to the NIC may lead to
546 * RX ring exhaustion situations.
547 * However, the NIC can gracefully prevent such situations
548 * to happen by sending specific "back-pressure" flow control
549 * frames to its peer(s).
552 "port_id=%u queue_id=%u rx_id=%u staterr=0x%x data_len=%u",
553 rxq->port_id, rxq->queue_id, rx_id, staterr,
554 rte_le_to_cpu_16(rxd.wb.upper.length));
556 nmb = rte_mbuf_raw_alloc(rxq->mb_pool);
560 "RX mbuf alloc failed, port_id=%u queue_id=%u",
561 rxq->port_id, rxq->queue_id);
563 rte_eth_devices[id].data->rx_mbuf_alloc_failed++;
568 rxe = &sw_ring[rx_id];
570 if (rx_id >= rxq->nb_rx_desc)
573 /* Prefetch next mbuf while processing current one. */
574 rte_igc_prefetch(sw_ring[rx_id].mbuf);
577 * When next RX descriptor is on a cache-line boundary,
578 * prefetch the next 4 RX descriptors and the next 8 pointers
581 if ((rx_id & 0x3) == 0) {
582 rte_igc_prefetch(&rx_ring[rx_id]);
583 rte_igc_prefetch(&sw_ring[rx_id]);
587 * Update RX descriptor with the physical address of the new
588 * data buffer of the new allocated mbuf.
592 rxdp->read.hdr_addr = 0;
593 rxdp->read.pkt_addr =
594 rte_cpu_to_le_64(rte_mbuf_data_iova_default(nmb));
598 * Set data length & data buffer address of mbuf.
600 rxm->data_off = RTE_PKTMBUF_HEADROOM;
601 data_len = rte_le_to_cpu_16(rxd.wb.upper.length);
602 rxm->data_len = data_len;
605 * If this is the first buffer of the received packet,
606 * set the pointer to the first mbuf of the packet and
607 * initialize its context.
608 * Otherwise, update the total length and the number of segments
609 * of the current scattered packet, and update the pointer to
610 * the last mbuf of the current packet.
612 if (first_seg == NULL) {
614 first_seg->pkt_len = data_len;
615 first_seg->nb_segs = 1;
617 first_seg->pkt_len += data_len;
618 first_seg->nb_segs++;
619 last_seg->next = rxm;
623 * If this is not the last buffer of the received packet,
624 * update the pointer to the last mbuf of the current scattered
625 * packet and continue to parse the RX ring.
627 if (!(staterr & IGC_RXD_STAT_EOP)) {
633 * This is the last buffer of the received packet.
634 * If the CRC is not stripped by the hardware:
635 * - Subtract the CRC length from the total packet length.
636 * - If the last buffer only contains the whole CRC or a part
637 * of it, free the mbuf associated to the last buffer.
638 * If part of the CRC is also contained in the previous
639 * mbuf, subtract the length of that CRC part from the
640 * data length of the previous mbuf.
642 if (unlikely(rxq->crc_len > 0)) {
643 first_seg->pkt_len -= RTE_ETHER_CRC_LEN;
644 if (data_len <= RTE_ETHER_CRC_LEN) {
645 rte_pktmbuf_free_seg(rxm);
646 first_seg->nb_segs--;
647 last_seg->data_len = last_seg->data_len -
648 (RTE_ETHER_CRC_LEN - data_len);
649 last_seg->next = NULL;
651 rxm->data_len = (uint16_t)
652 (data_len - RTE_ETHER_CRC_LEN);
656 rx_desc_get_pkt_info(rxq, first_seg, &rxd, staterr);
659 * Store the mbuf address into the next entry of the array
660 * of returned packets.
662 rx_pkts[nb_rx++] = first_seg;
664 /* Setup receipt context for a new packet. */
667 rxq->rx_tail = rx_id;
670 * Save receive context.
672 rxq->pkt_first_seg = first_seg;
673 rxq->pkt_last_seg = last_seg;
676 * If the number of free RX descriptors is greater than the RX free
677 * threshold of the queue, advance the Receive Descriptor Tail (RDT)
679 * Update the RDT with the value of the last processed RX descriptor
680 * minus 1, to guarantee that the RDT register is never equal to the
681 * RDH register, which creates a "full" ring situation from the
682 * hardware point of view...
684 nb_hold = nb_hold + rxq->nb_rx_hold;
685 if (nb_hold > rxq->rx_free_thresh) {
687 "port_id=%u queue_id=%u rx_tail=%u nb_hold=%u nb_rx=%u",
688 rxq->port_id, rxq->queue_id, rx_id, nb_hold, nb_rx);
689 rx_id = (rx_id == 0) ? (rxq->nb_rx_desc - 1) : (rx_id - 1);
690 IGC_PCI_REG_WRITE(rxq->rdt_reg_addr, rx_id);
693 rxq->nb_rx_hold = nb_hold;
698 igc_rx_queue_release_mbufs(struct igc_rx_queue *rxq)
702 if (rxq->sw_ring != NULL) {
703 for (i = 0; i < rxq->nb_rx_desc; i++) {
704 if (rxq->sw_ring[i].mbuf != NULL) {
705 rte_pktmbuf_free_seg(rxq->sw_ring[i].mbuf);
706 rxq->sw_ring[i].mbuf = NULL;
713 igc_rx_queue_release(struct igc_rx_queue *rxq)
715 igc_rx_queue_release_mbufs(rxq);
716 rte_free(rxq->sw_ring);
720 void eth_igc_rx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
722 if (dev->data->rx_queues[qid])
723 igc_rx_queue_release(dev->data->rx_queues[qid]);
726 uint32_t eth_igc_rx_queue_count(void *rx_queue)
729 * Check the DD bit of a rx descriptor of each 4 in a group,
730 * to avoid checking too frequently and downgrading performance
733 #define IGC_RXQ_SCAN_INTERVAL 4
735 volatile union igc_adv_rx_desc *rxdp;
736 struct igc_rx_queue *rxq;
740 rxdp = &rxq->rx_ring[rxq->rx_tail];
742 while (desc < rxq->nb_rx_desc - rxq->rx_tail) {
743 if (unlikely(!(rxdp->wb.upper.status_error &
746 desc += IGC_RXQ_SCAN_INTERVAL;
747 rxdp += IGC_RXQ_SCAN_INTERVAL;
749 rxdp = &rxq->rx_ring[rxq->rx_tail + desc - rxq->nb_rx_desc];
751 while (desc < rxq->nb_rx_desc &&
752 (rxdp->wb.upper.status_error & IGC_RXD_STAT_DD)) {
753 desc += IGC_RXQ_SCAN_INTERVAL;
754 rxdp += IGC_RXQ_SCAN_INTERVAL;
760 int eth_igc_rx_descriptor_status(void *rx_queue, uint16_t offset)
762 struct igc_rx_queue *rxq = rx_queue;
763 volatile uint32_t *status;
766 if (unlikely(!rxq || offset >= rxq->nb_rx_desc))
769 if (offset >= rxq->nb_rx_desc - rxq->nb_rx_hold)
770 return RTE_ETH_RX_DESC_UNAVAIL;
772 desc = rxq->rx_tail + offset;
773 if (desc >= rxq->nb_rx_desc)
774 desc -= rxq->nb_rx_desc;
776 status = &rxq->rx_ring[desc].wb.upper.status_error;
777 if (*status & rte_cpu_to_le_32(IGC_RXD_STAT_DD))
778 return RTE_ETH_RX_DESC_DONE;
780 return RTE_ETH_RX_DESC_AVAIL;
784 igc_alloc_rx_queue_mbufs(struct igc_rx_queue *rxq)
786 struct igc_rx_entry *rxe = rxq->sw_ring;
790 /* Initialize software ring entries. */
791 for (i = 0; i < rxq->nb_rx_desc; i++) {
792 volatile union igc_adv_rx_desc *rxd;
793 struct rte_mbuf *mbuf = rte_mbuf_raw_alloc(rxq->mb_pool);
796 PMD_DRV_LOG(ERR, "RX mbuf alloc failed, queue_id=%hu",
800 dma_addr = rte_cpu_to_le_64(rte_mbuf_data_iova_default(mbuf));
801 rxd = &rxq->rx_ring[i];
802 rxd->read.hdr_addr = 0;
803 rxd->read.pkt_addr = dma_addr;
811 * RSS random key supplied in section 7.1.2.9.3 of the Intel I225 datasheet.
812 * Used as the default key.
814 static uint8_t default_rss_key[40] = {
815 0x6D, 0x5A, 0x56, 0xDA, 0x25, 0x5B, 0x0E, 0xC2,
816 0x41, 0x67, 0x25, 0x3D, 0x43, 0xA3, 0x8F, 0xB0,
817 0xD0, 0xCA, 0x2B, 0xCB, 0xAE, 0x7B, 0x30, 0xB4,
818 0x77, 0xCB, 0x2D, 0xA3, 0x80, 0x30, 0xF2, 0x0C,
819 0x6A, 0x42, 0xB7, 0x3B, 0xBE, 0xAC, 0x01, 0xFA,
823 igc_rss_disable(struct rte_eth_dev *dev)
825 struct igc_hw *hw = IGC_DEV_PRIVATE_HW(dev);
828 mrqc = IGC_READ_REG(hw, IGC_MRQC);
829 mrqc &= ~IGC_MRQC_ENABLE_MASK;
830 IGC_WRITE_REG(hw, IGC_MRQC, mrqc);
834 igc_hw_rss_hash_set(struct igc_hw *hw, struct rte_eth_rss_conf *rss_conf)
836 uint32_t *hash_key = (uint32_t *)rss_conf->rss_key;
840 if (hash_key != NULL) {
843 /* Fill in RSS hash key */
844 for (i = 0; i < IGC_HKEY_MAX_INDEX; i++)
845 IGC_WRITE_REG_LE_VALUE(hw, IGC_RSSRK(i), hash_key[i]);
848 /* Set configured hashing protocols in MRQC register */
849 rss_hf = rss_conf->rss_hf;
850 mrqc = IGC_MRQC_ENABLE_RSS_4Q; /* RSS enabled. */
851 if (rss_hf & RTE_ETH_RSS_IPV4)
852 mrqc |= IGC_MRQC_RSS_FIELD_IPV4;
853 if (rss_hf & RTE_ETH_RSS_NONFRAG_IPV4_TCP)
854 mrqc |= IGC_MRQC_RSS_FIELD_IPV4_TCP;
855 if (rss_hf & RTE_ETH_RSS_IPV6)
856 mrqc |= IGC_MRQC_RSS_FIELD_IPV6;
857 if (rss_hf & RTE_ETH_RSS_IPV6_EX)
858 mrqc |= IGC_MRQC_RSS_FIELD_IPV6_EX;
859 if (rss_hf & RTE_ETH_RSS_NONFRAG_IPV6_TCP)
860 mrqc |= IGC_MRQC_RSS_FIELD_IPV6_TCP;
861 if (rss_hf & RTE_ETH_RSS_IPV6_TCP_EX)
862 mrqc |= IGC_MRQC_RSS_FIELD_IPV6_TCP_EX;
863 if (rss_hf & RTE_ETH_RSS_NONFRAG_IPV4_UDP)
864 mrqc |= IGC_MRQC_RSS_FIELD_IPV4_UDP;
865 if (rss_hf & RTE_ETH_RSS_NONFRAG_IPV6_UDP)
866 mrqc |= IGC_MRQC_RSS_FIELD_IPV6_UDP;
867 if (rss_hf & RTE_ETH_RSS_IPV6_UDP_EX)
868 mrqc |= IGC_MRQC_RSS_FIELD_IPV6_UDP_EX;
869 IGC_WRITE_REG(hw, IGC_MRQC, mrqc);
873 igc_rss_configure(struct rte_eth_dev *dev)
875 struct rte_eth_rss_conf rss_conf;
876 struct igc_hw *hw = IGC_DEV_PRIVATE_HW(dev);
879 /* Fill in redirection table. */
880 for (i = 0; i < IGC_RSS_RDT_SIZD; i++) {
881 union igc_rss_reta_reg reta;
882 uint16_t q_idx, reta_idx;
884 q_idx = (uint8_t)((dev->data->nb_rx_queues > 1) ?
885 i % dev->data->nb_rx_queues : 0);
886 reta_idx = i % sizeof(reta);
887 reta.bytes[reta_idx] = q_idx;
888 if (reta_idx == sizeof(reta) - 1)
889 IGC_WRITE_REG_LE_VALUE(hw,
890 IGC_RETA(i / sizeof(reta)), reta.dword);
894 * Configure the RSS key and the RSS protocols used to compute
895 * the RSS hash of input packets.
897 rss_conf = dev->data->dev_conf.rx_adv_conf.rss_conf;
898 if (rss_conf.rss_key == NULL)
899 rss_conf.rss_key = default_rss_key;
900 igc_hw_rss_hash_set(hw, &rss_conf);
904 igc_del_rss_filter(struct rte_eth_dev *dev)
906 struct igc_rss_filter *rss_filter = IGC_DEV_PRIVATE_RSS_FILTER(dev);
908 if (rss_filter->enable) {
909 /* recover default RSS configuration */
910 igc_rss_configure(dev);
912 /* disable RSS logic and clear filter data */
913 igc_rss_disable(dev);
914 memset(rss_filter, 0, sizeof(*rss_filter));
917 PMD_DRV_LOG(ERR, "filter not exist!");
921 /* Initiate the filter structure by the structure of rte_flow_action_rss */
923 igc_rss_conf_set(struct igc_rss_filter *out,
924 const struct rte_flow_action_rss *rss)
926 out->conf.func = rss->func;
927 out->conf.level = rss->level;
928 out->conf.types = rss->types;
930 if (rss->key_len == sizeof(out->key)) {
931 memcpy(out->key, rss->key, rss->key_len);
932 out->conf.key = out->key;
933 out->conf.key_len = rss->key_len;
935 out->conf.key = NULL;
936 out->conf.key_len = 0;
939 if (rss->queue_num <= IGC_RSS_RDT_SIZD) {
940 memcpy(out->queue, rss->queue,
941 sizeof(*out->queue) * rss->queue_num);
942 out->conf.queue = out->queue;
943 out->conf.queue_num = rss->queue_num;
945 out->conf.queue = NULL;
946 out->conf.queue_num = 0;
951 igc_add_rss_filter(struct rte_eth_dev *dev, struct igc_rss_filter *rss)
953 struct rte_eth_rss_conf rss_conf = {
954 .rss_key = rss->conf.key_len ?
955 (void *)(uintptr_t)rss->conf.key : NULL,
956 .rss_key_len = rss->conf.key_len,
957 .rss_hf = rss->conf.types,
959 struct igc_hw *hw = IGC_DEV_PRIVATE_HW(dev);
960 struct igc_rss_filter *rss_filter = IGC_DEV_PRIVATE_RSS_FILTER(dev);
963 /* check RSS type is valid */
964 if ((rss_conf.rss_hf & IGC_RSS_OFFLOAD_ALL) == 0) {
966 "RSS type(0x%" PRIx64 ") error!, only 0x%" PRIx64
967 " been supported", rss_conf.rss_hf,
968 (uint64_t)IGC_RSS_OFFLOAD_ALL);
972 /* check queue count is not zero */
973 if (!rss->conf.queue_num) {
974 PMD_DRV_LOG(ERR, "Queue number should not be 0!");
978 /* check queue id is valid */
979 for (i = 0; i < rss->conf.queue_num; i++)
980 if (rss->conf.queue[i] >= dev->data->nb_rx_queues) {
981 PMD_DRV_LOG(ERR, "Queue id %u is invalid!",
986 /* only support one filter */
987 if (rss_filter->enable) {
988 PMD_DRV_LOG(ERR, "Only support one RSS filter!");
991 rss_filter->enable = 1;
993 igc_rss_conf_set(rss_filter, &rss->conf);
995 /* Fill in redirection table. */
996 for (i = 0, j = 0; i < IGC_RSS_RDT_SIZD; i++, j++) {
997 union igc_rss_reta_reg reta;
998 uint16_t q_idx, reta_idx;
1000 if (j == rss->conf.queue_num)
1002 q_idx = rss->conf.queue[j];
1003 reta_idx = i % sizeof(reta);
1004 reta.bytes[reta_idx] = q_idx;
1005 if (reta_idx == sizeof(reta) - 1)
1006 IGC_WRITE_REG_LE_VALUE(hw,
1007 IGC_RETA(i / sizeof(reta)), reta.dword);
1010 if (rss_conf.rss_key == NULL)
1011 rss_conf.rss_key = default_rss_key;
1012 igc_hw_rss_hash_set(hw, &rss_conf);
1017 igc_clear_rss_filter(struct rte_eth_dev *dev)
1019 struct igc_rss_filter *rss_filter = IGC_DEV_PRIVATE_RSS_FILTER(dev);
1021 if (!rss_filter->enable)
1024 /* recover default RSS configuration */
1025 igc_rss_configure(dev);
1027 /* disable RSS logic and clear filter data */
1028 igc_rss_disable(dev);
1029 memset(rss_filter, 0, sizeof(*rss_filter));
1033 igc_dev_mq_rx_configure(struct rte_eth_dev *dev)
1035 if (RTE_ETH_DEV_SRIOV(dev).active) {
1036 PMD_DRV_LOG(ERR, "SRIOV unsupported!");
1040 switch (dev->data->dev_conf.rxmode.mq_mode) {
1041 case RTE_ETH_MQ_RX_RSS:
1042 igc_rss_configure(dev);
1044 case RTE_ETH_MQ_RX_NONE:
1046 * configure RSS register for following,
1047 * then disable the RSS logic
1049 igc_rss_configure(dev);
1050 igc_rss_disable(dev);
1053 PMD_DRV_LOG(ERR, "rx mode(%d) not supported!",
1054 dev->data->dev_conf.rxmode.mq_mode);
1061 igc_rx_init(struct rte_eth_dev *dev)
1063 struct igc_rx_queue *rxq;
1064 struct igc_hw *hw = IGC_DEV_PRIVATE_HW(dev);
1065 uint64_t offloads = dev->data->dev_conf.rxmode.offloads;
1066 uint32_t max_rx_pktlen;
1070 uint16_t rctl_bsize;
1074 dev->rx_pkt_burst = igc_recv_pkts;
1077 * Make sure receives are disabled while setting
1078 * up the descriptor ring.
1080 rctl = IGC_READ_REG(hw, IGC_RCTL);
1081 IGC_WRITE_REG(hw, IGC_RCTL, rctl & ~IGC_RCTL_EN);
1083 /* Configure support of jumbo frames, if any. */
1084 if (dev->data->mtu > RTE_ETHER_MTU)
1085 rctl |= IGC_RCTL_LPE;
1087 rctl &= ~IGC_RCTL_LPE;
1089 max_rx_pktlen = dev->data->mtu + IGC_ETH_OVERHEAD;
1091 * Set maximum packet length by default, and might be updated
1092 * together with enabling/disabling dual VLAN.
1094 IGC_WRITE_REG(hw, IGC_RLPML, max_rx_pktlen);
1096 /* Configure and enable each RX queue. */
1098 for (i = 0; i < dev->data->nb_rx_queues; i++) {
1103 rxq = dev->data->rx_queues[i];
1106 /* Allocate buffers for descriptor rings and set up queue */
1107 ret = igc_alloc_rx_queue_mbufs(rxq);
1112 * Reset crc_len in case it was changed after queue setup by a
1115 rxq->crc_len = (offloads & RTE_ETH_RX_OFFLOAD_KEEP_CRC) ?
1116 RTE_ETHER_CRC_LEN : 0;
1118 bus_addr = rxq->rx_ring_phys_addr;
1119 IGC_WRITE_REG(hw, IGC_RDLEN(rxq->reg_idx),
1121 sizeof(union igc_adv_rx_desc));
1122 IGC_WRITE_REG(hw, IGC_RDBAH(rxq->reg_idx),
1123 (uint32_t)(bus_addr >> 32));
1124 IGC_WRITE_REG(hw, IGC_RDBAL(rxq->reg_idx),
1125 (uint32_t)bus_addr);
1127 /* set descriptor configuration */
1128 srrctl = IGC_SRRCTL_DESCTYPE_ADV_ONEBUF;
1130 srrctl |= (uint32_t)(RTE_PKTMBUF_HEADROOM / 64) <<
1131 IGC_SRRCTL_BSIZEHEADER_SHIFT;
1133 * Configure RX buffer size.
1135 buf_size = (uint16_t)(rte_pktmbuf_data_room_size(rxq->mb_pool) -
1136 RTE_PKTMBUF_HEADROOM);
1137 if (buf_size >= 1024) {
1139 * Configure the BSIZEPACKET field of the SRRCTL
1140 * register of the queue.
1141 * Value is in 1 KB resolution, from 1 KB to 16 KB.
1142 * If this field is equal to 0b, then RCTL.BSIZE
1143 * determines the RX packet buffer size.
1146 srrctl |= ((buf_size >> IGC_SRRCTL_BSIZEPKT_SHIFT) &
1147 IGC_SRRCTL_BSIZEPKT_MASK);
1148 buf_size = (uint16_t)((srrctl &
1149 IGC_SRRCTL_BSIZEPKT_MASK) <<
1150 IGC_SRRCTL_BSIZEPKT_SHIFT);
1152 /* It adds dual VLAN length for supporting dual VLAN */
1153 if (max_rx_pktlen > buf_size)
1154 dev->data->scattered_rx = 1;
1157 * Use BSIZE field of the device RCTL register.
1159 if (rctl_bsize == 0 || rctl_bsize > buf_size)
1160 rctl_bsize = buf_size;
1161 dev->data->scattered_rx = 1;
1164 /* Set if packets are dropped when no descriptors available */
1166 srrctl |= IGC_SRRCTL_DROP_EN;
1168 IGC_WRITE_REG(hw, IGC_SRRCTL(rxq->reg_idx), srrctl);
1170 /* Enable this RX queue. */
1171 rxdctl = IGC_RXDCTL_QUEUE_ENABLE;
1172 rxdctl |= ((uint32_t)rxq->pthresh << IGC_RXDCTL_PTHRESH_SHIFT) &
1173 IGC_RXDCTL_PTHRESH_MSK;
1174 rxdctl |= ((uint32_t)rxq->hthresh << IGC_RXDCTL_HTHRESH_SHIFT) &
1175 IGC_RXDCTL_HTHRESH_MSK;
1176 rxdctl |= ((uint32_t)rxq->wthresh << IGC_RXDCTL_WTHRESH_SHIFT) &
1177 IGC_RXDCTL_WTHRESH_MSK;
1178 IGC_WRITE_REG(hw, IGC_RXDCTL(rxq->reg_idx), rxdctl);
1181 if (offloads & RTE_ETH_RX_OFFLOAD_SCATTER)
1182 dev->data->scattered_rx = 1;
1184 if (dev->data->scattered_rx) {
1185 PMD_DRV_LOG(DEBUG, "forcing scatter mode");
1186 dev->rx_pkt_burst = igc_recv_scattered_pkts;
1189 * Setup BSIZE field of RCTL register, if needed.
1190 * Buffer sizes >= 1024 are not [supposed to be] setup in the RCTL
1191 * register, since the code above configures the SRRCTL register of
1192 * the RX queue in such a case.
1193 * All configurable sizes are:
1194 * 16384: rctl |= (IGC_RCTL_SZ_16384 | IGC_RCTL_BSEX);
1195 * 8192: rctl |= (IGC_RCTL_SZ_8192 | IGC_RCTL_BSEX);
1196 * 4096: rctl |= (IGC_RCTL_SZ_4096 | IGC_RCTL_BSEX);
1197 * 2048: rctl |= IGC_RCTL_SZ_2048;
1198 * 1024: rctl |= IGC_RCTL_SZ_1024;
1199 * 512: rctl |= IGC_RCTL_SZ_512;
1200 * 256: rctl |= IGC_RCTL_SZ_256;
1202 if (rctl_bsize > 0) {
1203 if (rctl_bsize >= 512) /* 512 <= buf_size < 1024 - use 512 */
1204 rctl |= IGC_RCTL_SZ_512;
1205 else /* 256 <= buf_size < 512 - use 256 */
1206 rctl |= IGC_RCTL_SZ_256;
1210 * Configure RSS if device configured with multiple RX queues.
1212 igc_dev_mq_rx_configure(dev);
1214 /* Update the rctl since igc_dev_mq_rx_configure may change its value */
1215 rctl |= IGC_READ_REG(hw, IGC_RCTL);
1218 * Setup the Checksum Register.
1219 * Receive Full-Packet Checksum Offload is mutually exclusive with RSS.
1221 rxcsum = IGC_READ_REG(hw, IGC_RXCSUM);
1222 rxcsum |= IGC_RXCSUM_PCSD;
1224 /* Enable both L3/L4 rx checksum offload */
1225 if (offloads & RTE_ETH_RX_OFFLOAD_IPV4_CKSUM)
1226 rxcsum |= IGC_RXCSUM_IPOFL;
1228 rxcsum &= ~IGC_RXCSUM_IPOFL;
1231 (RTE_ETH_RX_OFFLOAD_TCP_CKSUM | RTE_ETH_RX_OFFLOAD_UDP_CKSUM)) {
1232 rxcsum |= IGC_RXCSUM_TUOFL;
1233 offloads |= RTE_ETH_RX_OFFLOAD_SCTP_CKSUM;
1235 rxcsum &= ~IGC_RXCSUM_TUOFL;
1238 if (offloads & RTE_ETH_RX_OFFLOAD_SCTP_CKSUM)
1239 rxcsum |= IGC_RXCSUM_CRCOFL;
1241 rxcsum &= ~IGC_RXCSUM_CRCOFL;
1243 IGC_WRITE_REG(hw, IGC_RXCSUM, rxcsum);
1245 /* Setup the Receive Control Register. */
1246 if (offloads & RTE_ETH_RX_OFFLOAD_KEEP_CRC)
1247 rctl &= ~IGC_RCTL_SECRC; /* Do not Strip Ethernet CRC. */
1249 rctl |= IGC_RCTL_SECRC; /* Strip Ethernet CRC. */
1251 rctl &= ~IGC_RCTL_MO_MSK;
1252 rctl &= ~IGC_RCTL_LBM_MSK;
1253 rctl |= IGC_RCTL_EN | IGC_RCTL_BAM | IGC_RCTL_LBM_NO |
1255 (hw->mac.mc_filter_type << IGC_RCTL_MO_SHIFT);
1257 if (dev->data->dev_conf.lpbk_mode == 1)
1258 rctl |= IGC_RCTL_LBM_MAC;
1260 rctl &= ~(IGC_RCTL_HSEL_MSK | IGC_RCTL_CFIEN | IGC_RCTL_CFI |
1261 IGC_RCTL_PSP | IGC_RCTL_PMCF);
1263 /* Make sure VLAN Filters are off. */
1264 rctl &= ~IGC_RCTL_VFE;
1265 /* Don't store bad packets. */
1266 rctl &= ~IGC_RCTL_SBP;
1268 /* Enable Receives. */
1269 IGC_WRITE_REG(hw, IGC_RCTL, rctl);
1272 * Setup the HW Rx Head and Tail Descriptor Pointers.
1273 * This needs to be done after enable.
1275 for (i = 0; i < dev->data->nb_rx_queues; i++) {
1278 rxq = dev->data->rx_queues[i];
1279 IGC_WRITE_REG(hw, IGC_RDH(rxq->reg_idx), 0);
1280 IGC_WRITE_REG(hw, IGC_RDT(rxq->reg_idx), rxq->nb_rx_desc - 1);
1282 dvmolr = IGC_READ_REG(hw, IGC_DVMOLR(rxq->reg_idx));
1283 if (rxq->offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP)
1284 dvmolr |= IGC_DVMOLR_STRVLAN;
1286 dvmolr &= ~IGC_DVMOLR_STRVLAN;
1288 if (offloads & RTE_ETH_RX_OFFLOAD_KEEP_CRC)
1289 dvmolr &= ~IGC_DVMOLR_STRCRC;
1291 dvmolr |= IGC_DVMOLR_STRCRC;
1293 IGC_WRITE_REG(hw, IGC_DVMOLR(rxq->reg_idx), dvmolr);
1300 igc_reset_rx_queue(struct igc_rx_queue *rxq)
1302 static const union igc_adv_rx_desc zeroed_desc = { {0} };
1305 /* Zero out HW ring memory */
1306 for (i = 0; i < rxq->nb_rx_desc; i++)
1307 rxq->rx_ring[i] = zeroed_desc;
1310 rxq->pkt_first_seg = NULL;
1311 rxq->pkt_last_seg = NULL;
1315 eth_igc_rx_queue_setup(struct rte_eth_dev *dev,
1318 unsigned int socket_id,
1319 const struct rte_eth_rxconf *rx_conf,
1320 struct rte_mempool *mp)
1322 struct igc_hw *hw = IGC_DEV_PRIVATE_HW(dev);
1323 const struct rte_memzone *rz;
1324 struct igc_rx_queue *rxq;
1328 * Validate number of receive descriptors.
1329 * It must not exceed hardware maximum, and must be multiple
1330 * of IGC_RX_DESCRIPTOR_MULTIPLE.
1332 if (nb_desc % IGC_RX_DESCRIPTOR_MULTIPLE != 0 ||
1333 nb_desc > IGC_MAX_RXD || nb_desc < IGC_MIN_RXD) {
1335 "RX descriptor must be multiple of %u(cur: %u) and between %u and %u",
1336 IGC_RX_DESCRIPTOR_MULTIPLE, nb_desc,
1337 IGC_MIN_RXD, IGC_MAX_RXD);
1341 /* Free memory prior to re-allocation if needed */
1342 if (dev->data->rx_queues[queue_idx] != NULL) {
1343 igc_rx_queue_release(dev->data->rx_queues[queue_idx]);
1344 dev->data->rx_queues[queue_idx] = NULL;
1347 /* First allocate the RX queue data structure. */
1348 rxq = rte_zmalloc("ethdev RX queue", sizeof(struct igc_rx_queue),
1349 RTE_CACHE_LINE_SIZE);
1352 rxq->offloads = rx_conf->offloads;
1354 rxq->nb_rx_desc = nb_desc;
1355 rxq->pthresh = rx_conf->rx_thresh.pthresh;
1356 rxq->hthresh = rx_conf->rx_thresh.hthresh;
1357 rxq->wthresh = rx_conf->rx_thresh.wthresh;
1358 rxq->drop_en = rx_conf->rx_drop_en;
1359 rxq->rx_free_thresh = rx_conf->rx_free_thresh;
1360 rxq->queue_id = queue_idx;
1361 rxq->reg_idx = queue_idx;
1362 rxq->port_id = dev->data->port_id;
1365 * Allocate RX ring hardware descriptors. A memzone large enough to
1366 * handle the maximum ring size is allocated in order to allow for
1367 * resizing in later calls to the queue setup function.
1369 size = sizeof(union igc_adv_rx_desc) * IGC_MAX_RXD;
1370 rz = rte_eth_dma_zone_reserve(dev, "rx_ring", queue_idx, size,
1371 IGC_ALIGN, socket_id);
1373 igc_rx_queue_release(rxq);
1376 rxq->rdt_reg_addr = IGC_PCI_REG_ADDR(hw, IGC_RDT(rxq->reg_idx));
1377 rxq->rdh_reg_addr = IGC_PCI_REG_ADDR(hw, IGC_RDH(rxq->reg_idx));
1378 rxq->rx_ring_phys_addr = rz->iova;
1379 rxq->rx_ring = (union igc_adv_rx_desc *)rz->addr;
1381 /* Allocate software ring. */
1382 rxq->sw_ring = rte_zmalloc("rxq->sw_ring",
1383 sizeof(struct igc_rx_entry) * nb_desc,
1384 RTE_CACHE_LINE_SIZE);
1385 if (rxq->sw_ring == NULL) {
1386 igc_rx_queue_release(rxq);
1390 PMD_DRV_LOG(DEBUG, "sw_ring=%p hw_ring=%p dma_addr=0x%" PRIx64,
1391 rxq->sw_ring, rxq->rx_ring, rxq->rx_ring_phys_addr);
1393 dev->data->rx_queues[queue_idx] = rxq;
1394 igc_reset_rx_queue(rxq);
1399 /* prepare packets for transmit */
1401 eth_igc_prep_pkts(__rte_unused void *tx_queue, struct rte_mbuf **tx_pkts,
1407 for (i = 0; i < nb_pkts; i++) {
1410 /* Check some limitations for TSO in hardware */
1411 if (m->ol_flags & IGC_TX_OFFLOAD_SEG)
1412 if (m->tso_segsz > IGC_TSO_MAX_MSS ||
1413 m->l2_len + m->l3_len + m->l4_len >
1414 IGC_TSO_MAX_HDRLEN) {
1419 if (m->ol_flags & IGC_TX_OFFLOAD_NOTSUP_MASK) {
1420 rte_errno = ENOTSUP;
1424 #ifdef RTE_ETHDEV_DEBUG_TX
1425 ret = rte_validate_tx_offload(m);
1431 ret = rte_net_intel_cksum_prepare(m);
1442 *There're some limitations in hardware for TCP segmentation offload. We
1443 *should check whether the parameters are valid.
1445 static inline uint64_t
1446 check_tso_para(uint64_t ol_req, union igc_tx_offload ol_para)
1448 if (!(ol_req & IGC_TX_OFFLOAD_SEG))
1450 if (ol_para.tso_segsz > IGC_TSO_MAX_MSS || ol_para.l2_len +
1451 ol_para.l3_len + ol_para.l4_len > IGC_TSO_MAX_HDRLEN) {
1452 ol_req &= ~IGC_TX_OFFLOAD_SEG;
1453 ol_req |= RTE_MBUF_F_TX_TCP_CKSUM;
1459 * Check which hardware context can be used. Use the existing match
1460 * or create a new context descriptor.
1462 static inline uint32_t
1463 what_advctx_update(struct igc_tx_queue *txq, uint64_t flags,
1464 union igc_tx_offload tx_offload)
1466 uint32_t curr = txq->ctx_curr;
1468 /* If match with the current context */
1469 if (likely(txq->ctx_cache[curr].flags == flags &&
1470 txq->ctx_cache[curr].tx_offload.data ==
1471 (txq->ctx_cache[curr].tx_offload_mask.data &
1472 tx_offload.data))) {
1476 /* Total two context, if match with the second context */
1478 if (likely(txq->ctx_cache[curr].flags == flags &&
1479 txq->ctx_cache[curr].tx_offload.data ==
1480 (txq->ctx_cache[curr].tx_offload_mask.data &
1481 tx_offload.data))) {
1482 txq->ctx_curr = curr;
1486 /* Mismatch, create new one */
1491 * This is a separate function, looking for optimization opportunity here
1492 * Rework required to go with the pre-defined values.
1495 igc_set_xmit_ctx(struct igc_tx_queue *txq,
1496 volatile struct igc_adv_tx_context_desc *ctx_txd,
1497 uint64_t ol_flags, union igc_tx_offload tx_offload)
1499 uint32_t type_tucmd_mlhl;
1500 uint32_t mss_l4len_idx;
1502 uint32_t vlan_macip_lens;
1503 union igc_tx_offload tx_offload_mask;
1505 /* Use the previous context */
1507 ctx_curr = txq->ctx_curr;
1509 tx_offload_mask.data = 0;
1510 type_tucmd_mlhl = 0;
1512 /* Specify which HW CTX to upload. */
1513 mss_l4len_idx = (ctx_curr << IGC_ADVTXD_IDX_SHIFT);
1515 if (ol_flags & RTE_MBUF_F_TX_VLAN)
1516 tx_offload_mask.vlan_tci = 0xffff;
1518 /* check if TCP segmentation required for this packet */
1519 if (ol_flags & IGC_TX_OFFLOAD_SEG) {
1520 /* implies IP cksum in IPv4 */
1521 if (ol_flags & RTE_MBUF_F_TX_IP_CKSUM)
1522 type_tucmd_mlhl = IGC_ADVTXD_TUCMD_IPV4 |
1523 IGC_ADVTXD_DTYP_CTXT | IGC_ADVTXD_DCMD_DEXT;
1525 type_tucmd_mlhl = IGC_ADVTXD_TUCMD_IPV6 |
1526 IGC_ADVTXD_DTYP_CTXT | IGC_ADVTXD_DCMD_DEXT;
1528 if (ol_flags & RTE_MBUF_F_TX_TCP_SEG)
1529 type_tucmd_mlhl |= IGC_ADVTXD_TUCMD_L4T_TCP;
1531 type_tucmd_mlhl |= IGC_ADVTXD_TUCMD_L4T_UDP;
1533 tx_offload_mask.data |= TX_TSO_CMP_MASK;
1534 mss_l4len_idx |= (uint32_t)tx_offload.tso_segsz <<
1535 IGC_ADVTXD_MSS_SHIFT;
1536 mss_l4len_idx |= (uint32_t)tx_offload.l4_len <<
1537 IGC_ADVTXD_L4LEN_SHIFT;
1538 } else { /* no TSO, check if hardware checksum is needed */
1539 if (ol_flags & (RTE_MBUF_F_TX_IP_CKSUM | RTE_MBUF_F_TX_L4_MASK))
1540 tx_offload_mask.data |= TX_MACIP_LEN_CMP_MASK;
1542 if (ol_flags & RTE_MBUF_F_TX_IP_CKSUM)
1543 type_tucmd_mlhl = IGC_ADVTXD_TUCMD_IPV4;
1545 switch (ol_flags & RTE_MBUF_F_TX_L4_MASK) {
1546 case RTE_MBUF_F_TX_TCP_CKSUM:
1547 type_tucmd_mlhl |= IGC_ADVTXD_TUCMD_L4T_TCP |
1548 IGC_ADVTXD_DTYP_CTXT | IGC_ADVTXD_DCMD_DEXT;
1549 mss_l4len_idx |= (uint32_t)sizeof(struct rte_tcp_hdr)
1550 << IGC_ADVTXD_L4LEN_SHIFT;
1552 case RTE_MBUF_F_TX_UDP_CKSUM:
1553 type_tucmd_mlhl |= IGC_ADVTXD_TUCMD_L4T_UDP |
1554 IGC_ADVTXD_DTYP_CTXT | IGC_ADVTXD_DCMD_DEXT;
1555 mss_l4len_idx |= (uint32_t)sizeof(struct rte_udp_hdr)
1556 << IGC_ADVTXD_L4LEN_SHIFT;
1558 case RTE_MBUF_F_TX_SCTP_CKSUM:
1559 type_tucmd_mlhl |= IGC_ADVTXD_TUCMD_L4T_SCTP |
1560 IGC_ADVTXD_DTYP_CTXT | IGC_ADVTXD_DCMD_DEXT;
1561 mss_l4len_idx |= (uint32_t)sizeof(struct rte_sctp_hdr)
1562 << IGC_ADVTXD_L4LEN_SHIFT;
1565 type_tucmd_mlhl |= IGC_ADVTXD_TUCMD_L4T_RSV |
1566 IGC_ADVTXD_DTYP_CTXT | IGC_ADVTXD_DCMD_DEXT;
1571 txq->ctx_cache[ctx_curr].flags = ol_flags;
1572 txq->ctx_cache[ctx_curr].tx_offload.data =
1573 tx_offload_mask.data & tx_offload.data;
1574 txq->ctx_cache[ctx_curr].tx_offload_mask = tx_offload_mask;
1576 ctx_txd->type_tucmd_mlhl = rte_cpu_to_le_32(type_tucmd_mlhl);
1577 vlan_macip_lens = (uint32_t)tx_offload.data;
1578 ctx_txd->vlan_macip_lens = rte_cpu_to_le_32(vlan_macip_lens);
1579 ctx_txd->mss_l4len_idx = rte_cpu_to_le_32(mss_l4len_idx);
1580 ctx_txd->u.launch_time = 0;
1583 static inline uint32_t
1584 tx_desc_vlan_flags_to_cmdtype(uint64_t ol_flags)
1587 static uint32_t vlan_cmd[2] = {0, IGC_ADVTXD_DCMD_VLE};
1588 static uint32_t tso_cmd[2] = {0, IGC_ADVTXD_DCMD_TSE};
1589 cmdtype = vlan_cmd[(ol_flags & RTE_MBUF_F_TX_VLAN) != 0];
1590 cmdtype |= tso_cmd[(ol_flags & IGC_TX_OFFLOAD_SEG) != 0];
1594 static inline uint32_t
1595 tx_desc_cksum_flags_to_olinfo(uint64_t ol_flags)
1597 static const uint32_t l4_olinfo[2] = {0, IGC_ADVTXD_POPTS_TXSM};
1598 static const uint32_t l3_olinfo[2] = {0, IGC_ADVTXD_POPTS_IXSM};
1601 tmp = l4_olinfo[(ol_flags & RTE_MBUF_F_TX_L4_MASK) != RTE_MBUF_F_TX_L4_NO_CKSUM];
1602 tmp |= l3_olinfo[(ol_flags & RTE_MBUF_F_TX_IP_CKSUM) != 0];
1603 tmp |= l4_olinfo[(ol_flags & IGC_TX_OFFLOAD_SEG) != 0];
1608 igc_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
1610 struct igc_tx_queue * const txq = tx_queue;
1611 struct igc_tx_entry * const sw_ring = txq->sw_ring;
1612 struct igc_tx_entry *txe, *txn;
1613 volatile union igc_adv_tx_desc * const txr = txq->tx_ring;
1614 volatile union igc_adv_tx_desc *txd;
1615 struct rte_mbuf *tx_pkt;
1616 struct rte_mbuf *m_seg;
1617 uint64_t buf_dma_addr;
1618 uint32_t olinfo_status;
1619 uint32_t cmd_type_len;
1628 uint32_t new_ctx = 0;
1629 union igc_tx_offload tx_offload = {0};
1631 tx_id = txq->tx_tail;
1632 txe = &sw_ring[tx_id];
1634 for (nb_tx = 0; nb_tx < nb_pkts; nb_tx++) {
1635 tx_pkt = *tx_pkts++;
1636 pkt_len = tx_pkt->pkt_len;
1638 RTE_MBUF_PREFETCH_TO_FREE(txe->mbuf);
1641 * The number of descriptors that must be allocated for a
1642 * packet is the number of segments of that packet, plus 1
1643 * Context Descriptor for the VLAN Tag Identifier, if any.
1644 * Determine the last TX descriptor to allocate in the TX ring
1645 * for the packet, starting from the current position (tx_id)
1648 tx_last = (uint16_t)(tx_id + tx_pkt->nb_segs - 1);
1650 ol_flags = tx_pkt->ol_flags;
1651 tx_ol_req = ol_flags & IGC_TX_OFFLOAD_MASK;
1653 /* If a Context Descriptor need be built . */
1655 tx_offload.l2_len = tx_pkt->l2_len;
1656 tx_offload.l3_len = tx_pkt->l3_len;
1657 tx_offload.l4_len = tx_pkt->l4_len;
1658 tx_offload.vlan_tci = tx_pkt->vlan_tci;
1659 tx_offload.tso_segsz = tx_pkt->tso_segsz;
1660 tx_ol_req = check_tso_para(tx_ol_req, tx_offload);
1662 new_ctx = what_advctx_update(txq, tx_ol_req,
1664 /* Only allocate context descriptor if required*/
1665 new_ctx = (new_ctx >= IGC_CTX_NUM);
1666 tx_last = (uint16_t)(tx_last + new_ctx);
1668 if (tx_last >= txq->nb_tx_desc)
1669 tx_last = (uint16_t)(tx_last - txq->nb_tx_desc);
1672 "port_id=%u queue_id=%u pktlen=%u tx_first=%u tx_last=%u",
1673 txq->port_id, txq->queue_id, pkt_len, tx_id, tx_last);
1676 * Check if there are enough free descriptors in the TX ring
1677 * to transmit the next packet.
1678 * This operation is based on the two following rules:
1680 * 1- Only check that the last needed TX descriptor can be
1681 * allocated (by construction, if that descriptor is free,
1682 * all intermediate ones are also free).
1684 * For this purpose, the index of the last TX descriptor
1685 * used for a packet (the "last descriptor" of a packet)
1686 * is recorded in the TX entries (the last one included)
1687 * that are associated with all TX descriptors allocated
1690 * 2- Avoid to allocate the last free TX descriptor of the
1691 * ring, in order to never set the TDT register with the
1692 * same value stored in parallel by the NIC in the TDH
1693 * register, which makes the TX engine of the NIC enter
1694 * in a deadlock situation.
1696 * By extension, avoid to allocate a free descriptor that
1697 * belongs to the last set of free descriptors allocated
1698 * to the same packet previously transmitted.
1702 * The "last descriptor" of the previously sent packet, if any,
1703 * which used the last descriptor to allocate.
1705 tx_end = sw_ring[tx_last].last_id;
1708 * The next descriptor following that "last descriptor" in the
1711 tx_end = sw_ring[tx_end].next_id;
1714 * The "last descriptor" associated with that next descriptor.
1716 tx_end = sw_ring[tx_end].last_id;
1719 * Check that this descriptor is free.
1721 if (!(txr[tx_end].wb.status & IGC_TXD_STAT_DD)) {
1728 * Set common flags of all TX Data Descriptors.
1730 * The following bits must be set in all Data Descriptors:
1731 * - IGC_ADVTXD_DTYP_DATA
1732 * - IGC_ADVTXD_DCMD_DEXT
1734 * The following bits must be set in the first Data Descriptor
1735 * and are ignored in the other ones:
1736 * - IGC_ADVTXD_DCMD_IFCS
1737 * - IGC_ADVTXD_MAC_1588
1738 * - IGC_ADVTXD_DCMD_VLE
1740 * The following bits must only be set in the last Data
1744 * The following bits can be set in any Data Descriptor, but
1745 * are only set in the last Data Descriptor:
1748 cmd_type_len = txq->txd_type |
1749 IGC_ADVTXD_DCMD_IFCS | IGC_ADVTXD_DCMD_DEXT;
1750 if (tx_ol_req & IGC_TX_OFFLOAD_SEG)
1751 pkt_len -= (tx_pkt->l2_len + tx_pkt->l3_len +
1753 olinfo_status = (pkt_len << IGC_ADVTXD_PAYLEN_SHIFT);
1756 * Timer 0 should be used to for packet timestamping,
1757 * sample the packet timestamp to reg 0
1759 if (ol_flags & RTE_MBUF_F_TX_IEEE1588_TMST)
1760 cmd_type_len |= IGC_ADVTXD_MAC_TSTAMP;
1763 /* Setup TX Advanced context descriptor if required */
1765 volatile struct igc_adv_tx_context_desc *
1766 ctx_txd = (volatile struct
1767 igc_adv_tx_context_desc *)&txr[tx_id];
1769 txn = &sw_ring[txe->next_id];
1770 RTE_MBUF_PREFETCH_TO_FREE(txn->mbuf);
1772 if (txe->mbuf != NULL) {
1773 rte_pktmbuf_free_seg(txe->mbuf);
1777 igc_set_xmit_ctx(txq, ctx_txd, tx_ol_req,
1780 txe->last_id = tx_last;
1781 tx_id = txe->next_id;
1785 /* Setup the TX Advanced Data Descriptor */
1787 tx_desc_vlan_flags_to_cmdtype(tx_ol_req);
1789 tx_desc_cksum_flags_to_olinfo(tx_ol_req);
1790 olinfo_status |= (uint32_t)txq->ctx_curr <<
1791 IGC_ADVTXD_IDX_SHIFT;
1796 txn = &sw_ring[txe->next_id];
1797 RTE_MBUF_PREFETCH_TO_FREE(txn->mbuf);
1801 if (txe->mbuf != NULL)
1802 rte_pktmbuf_free_seg(txe->mbuf);
1805 /* Set up transmit descriptor */
1806 slen = (uint16_t)m_seg->data_len;
1807 buf_dma_addr = rte_mbuf_data_iova(m_seg);
1808 txd->read.buffer_addr =
1809 rte_cpu_to_le_64(buf_dma_addr);
1810 txd->read.cmd_type_len =
1811 rte_cpu_to_le_32(cmd_type_len | slen);
1812 txd->read.olinfo_status =
1813 rte_cpu_to_le_32(olinfo_status);
1814 txe->last_id = tx_last;
1815 tx_id = txe->next_id;
1817 m_seg = m_seg->next;
1818 } while (m_seg != NULL);
1821 * The last packet data descriptor needs End Of Packet (EOP)
1822 * and Report Status (RS).
1824 txd->read.cmd_type_len |=
1825 rte_cpu_to_le_32(IGC_TXD_CMD_EOP | IGC_TXD_CMD_RS);
1831 * Set the Transmit Descriptor Tail (TDT).
1833 IGC_PCI_REG_WRITE_RELAXED(txq->tdt_reg_addr, tx_id);
1834 PMD_TX_LOG(DEBUG, "port_id=%u queue_id=%u tx_tail=%u nb_tx=%u",
1835 txq->port_id, txq->queue_id, tx_id, nb_tx);
1836 txq->tx_tail = tx_id;
1841 int eth_igc_tx_descriptor_status(void *tx_queue, uint16_t offset)
1843 struct igc_tx_queue *txq = tx_queue;
1844 volatile uint32_t *status;
1847 if (unlikely(!txq || offset >= txq->nb_tx_desc))
1850 desc = txq->tx_tail + offset;
1851 if (desc >= txq->nb_tx_desc)
1852 desc -= txq->nb_tx_desc;
1854 status = &txq->tx_ring[desc].wb.status;
1855 if (*status & rte_cpu_to_le_32(IGC_TXD_STAT_DD))
1856 return RTE_ETH_TX_DESC_DONE;
1858 return RTE_ETH_TX_DESC_FULL;
1862 igc_tx_queue_release_mbufs(struct igc_tx_queue *txq)
1866 if (txq->sw_ring != NULL) {
1867 for (i = 0; i < txq->nb_tx_desc; i++) {
1868 if (txq->sw_ring[i].mbuf != NULL) {
1869 rte_pktmbuf_free_seg(txq->sw_ring[i].mbuf);
1870 txq->sw_ring[i].mbuf = NULL;
1877 igc_tx_queue_release(struct igc_tx_queue *txq)
1879 igc_tx_queue_release_mbufs(txq);
1880 rte_free(txq->sw_ring);
1884 void eth_igc_tx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
1886 if (dev->data->tx_queues[qid])
1887 igc_tx_queue_release(dev->data->tx_queues[qid]);
1891 igc_reset_tx_queue_stat(struct igc_tx_queue *txq)
1896 memset((void *)&txq->ctx_cache, 0,
1897 IGC_CTX_NUM * sizeof(struct igc_advctx_info));
1901 igc_reset_tx_queue(struct igc_tx_queue *txq)
1903 struct igc_tx_entry *txe = txq->sw_ring;
1906 /* Initialize ring entries */
1907 prev = (uint16_t)(txq->nb_tx_desc - 1);
1908 for (i = 0; i < txq->nb_tx_desc; i++) {
1909 volatile union igc_adv_tx_desc *txd = &txq->tx_ring[i];
1911 txd->wb.status = IGC_TXD_STAT_DD;
1914 txe[prev].next_id = i;
1918 txq->txd_type = IGC_ADVTXD_DTYP_DATA;
1919 igc_reset_tx_queue_stat(txq);
1923 * clear all rx/tx queue
1926 igc_dev_clear_queues(struct rte_eth_dev *dev)
1929 struct igc_tx_queue *txq;
1930 struct igc_rx_queue *rxq;
1932 for (i = 0; i < dev->data->nb_tx_queues; i++) {
1933 txq = dev->data->tx_queues[i];
1935 igc_tx_queue_release_mbufs(txq);
1936 igc_reset_tx_queue(txq);
1940 for (i = 0; i < dev->data->nb_rx_queues; i++) {
1941 rxq = dev->data->rx_queues[i];
1943 igc_rx_queue_release_mbufs(rxq);
1944 igc_reset_rx_queue(rxq);
1949 int eth_igc_tx_queue_setup(struct rte_eth_dev *dev, uint16_t queue_idx,
1950 uint16_t nb_desc, unsigned int socket_id,
1951 const struct rte_eth_txconf *tx_conf)
1953 const struct rte_memzone *tz;
1954 struct igc_tx_queue *txq;
1958 if (nb_desc % IGC_TX_DESCRIPTOR_MULTIPLE != 0 ||
1959 nb_desc > IGC_MAX_TXD || nb_desc < IGC_MIN_TXD) {
1961 "TX-descriptor must be a multiple of %u and between %u and %u, cur: %u",
1962 IGC_TX_DESCRIPTOR_MULTIPLE,
1963 IGC_MAX_TXD, IGC_MIN_TXD, nb_desc);
1967 hw = IGC_DEV_PRIVATE_HW(dev);
1970 * The tx_free_thresh and tx_rs_thresh values are not used in the 2.5G
1973 if (tx_conf->tx_free_thresh != 0)
1975 "The tx_free_thresh parameter is not used for the 2.5G driver");
1976 if (tx_conf->tx_rs_thresh != 0)
1978 "The tx_rs_thresh parameter is not used for the 2.5G driver");
1979 if (tx_conf->tx_thresh.wthresh == 0)
1981 "To improve 2.5G driver performance, consider setting the TX WTHRESH value to 4, 8, or 16.");
1983 /* Free memory prior to re-allocation if needed */
1984 if (dev->data->tx_queues[queue_idx] != NULL) {
1985 igc_tx_queue_release(dev->data->tx_queues[queue_idx]);
1986 dev->data->tx_queues[queue_idx] = NULL;
1989 /* First allocate the tx queue data structure */
1990 txq = rte_zmalloc("ethdev TX queue", sizeof(struct igc_tx_queue),
1991 RTE_CACHE_LINE_SIZE);
1996 * Allocate TX ring hardware descriptors. A memzone large enough to
1997 * handle the maximum ring size is allocated in order to allow for
1998 * resizing in later calls to the queue setup function.
2000 size = sizeof(union igc_adv_tx_desc) * IGC_MAX_TXD;
2001 tz = rte_eth_dma_zone_reserve(dev, "tx_ring", queue_idx, size,
2002 IGC_ALIGN, socket_id);
2004 igc_tx_queue_release(txq);
2008 txq->nb_tx_desc = nb_desc;
2009 txq->pthresh = tx_conf->tx_thresh.pthresh;
2010 txq->hthresh = tx_conf->tx_thresh.hthresh;
2011 txq->wthresh = tx_conf->tx_thresh.wthresh;
2013 txq->queue_id = queue_idx;
2014 txq->reg_idx = queue_idx;
2015 txq->port_id = dev->data->port_id;
2017 txq->tdt_reg_addr = IGC_PCI_REG_ADDR(hw, IGC_TDT(txq->reg_idx));
2018 txq->tx_ring_phys_addr = tz->iova;
2020 txq->tx_ring = (union igc_adv_tx_desc *)tz->addr;
2021 /* Allocate software ring */
2022 txq->sw_ring = rte_zmalloc("txq->sw_ring",
2023 sizeof(struct igc_tx_entry) * nb_desc,
2024 RTE_CACHE_LINE_SIZE);
2025 if (txq->sw_ring == NULL) {
2026 igc_tx_queue_release(txq);
2029 PMD_DRV_LOG(DEBUG, "sw_ring=%p hw_ring=%p dma_addr=0x%" PRIx64,
2030 txq->sw_ring, txq->tx_ring, txq->tx_ring_phys_addr);
2032 igc_reset_tx_queue(txq);
2033 dev->tx_pkt_burst = igc_xmit_pkts;
2034 dev->tx_pkt_prepare = ð_igc_prep_pkts;
2035 dev->data->tx_queues[queue_idx] = txq;
2036 txq->offloads = tx_conf->offloads;
2042 eth_igc_tx_done_cleanup(void *txqueue, uint32_t free_cnt)
2044 struct igc_tx_queue *txq = txqueue;
2045 struct igc_tx_entry *sw_ring;
2046 volatile union igc_adv_tx_desc *txr;
2047 uint16_t tx_first; /* First segment analyzed. */
2048 uint16_t tx_id; /* Current segment being processed. */
2049 uint16_t tx_last; /* Last segment in the current packet. */
2050 uint16_t tx_next; /* First segment of the next packet. */
2057 sw_ring = txq->sw_ring;
2061 * tx_tail is the last sent packet on the sw_ring. Goto the end
2062 * of that packet (the last segment in the packet chain) and
2063 * then the next segment will be the start of the oldest segment
2064 * in the sw_ring. This is the first packet that will be
2065 * attempted to be freed.
2068 /* Get last segment in most recently added packet. */
2069 tx_first = sw_ring[txq->tx_tail].last_id;
2071 /* Get the next segment, which is the oldest segment in ring. */
2072 tx_first = sw_ring[tx_first].next_id;
2074 /* Set the current index to the first. */
2078 * Loop through each packet. For each packet, verify that an
2079 * mbuf exists and that the last segment is free. If so, free
2083 tx_last = sw_ring[tx_id].last_id;
2085 if (sw_ring[tx_last].mbuf) {
2086 if (!(txr[tx_last].wb.status &
2087 rte_cpu_to_le_32(IGC_TXD_STAT_DD)))
2090 /* Get the start of the next packet. */
2091 tx_next = sw_ring[tx_last].next_id;
2094 * Loop through all segments in a
2098 rte_pktmbuf_free_seg(sw_ring[tx_id].mbuf);
2099 sw_ring[tx_id].mbuf = NULL;
2100 sw_ring[tx_id].last_id = tx_id;
2102 /* Move to next segment. */
2103 tx_id = sw_ring[tx_id].next_id;
2104 } while (tx_id != tx_next);
2107 * Increment the number of packets
2111 if (unlikely(count == free_cnt))
2115 * There are multiple reasons to be here:
2116 * 1) All the packets on the ring have been
2117 * freed - tx_id is equal to tx_first
2118 * and some packets have been freed.
2120 * 2) Interfaces has not sent a rings worth of
2121 * packets yet, so the segment after tail is
2122 * still empty. Or a previous call to this
2123 * function freed some of the segments but
2124 * not all so there is a hole in the list.
2125 * Hopefully this is a rare case.
2126 * - Walk the list and find the next mbuf. If
2127 * there isn't one, then done.
2129 if (likely(tx_id == tx_first && count != 0))
2133 * Walk the list and find the next mbuf, if any.
2136 /* Move to next segment. */
2137 tx_id = sw_ring[tx_id].next_id;
2139 if (sw_ring[tx_id].mbuf)
2142 } while (tx_id != tx_first);
2145 * Determine why previous loop bailed. If there
2146 * is not an mbuf, done.
2148 if (sw_ring[tx_id].mbuf == NULL)
2157 igc_tx_init(struct rte_eth_dev *dev)
2159 struct igc_hw *hw = IGC_DEV_PRIVATE_HW(dev);
2164 /* Setup the Base and Length of the Tx Descriptor Rings. */
2165 for (i = 0; i < dev->data->nb_tx_queues; i++) {
2166 struct igc_tx_queue *txq = dev->data->tx_queues[i];
2167 uint64_t bus_addr = txq->tx_ring_phys_addr;
2169 IGC_WRITE_REG(hw, IGC_TDLEN(txq->reg_idx),
2171 sizeof(union igc_adv_tx_desc));
2172 IGC_WRITE_REG(hw, IGC_TDBAH(txq->reg_idx),
2173 (uint32_t)(bus_addr >> 32));
2174 IGC_WRITE_REG(hw, IGC_TDBAL(txq->reg_idx),
2175 (uint32_t)bus_addr);
2177 /* Setup the HW Tx Head and Tail descriptor pointers. */
2178 IGC_WRITE_REG(hw, IGC_TDT(txq->reg_idx), 0);
2179 IGC_WRITE_REG(hw, IGC_TDH(txq->reg_idx), 0);
2181 /* Setup Transmit threshold registers. */
2182 txdctl = ((uint32_t)txq->pthresh << IGC_TXDCTL_PTHRESH_SHIFT) &
2183 IGC_TXDCTL_PTHRESH_MSK;
2184 txdctl |= ((uint32_t)txq->hthresh << IGC_TXDCTL_HTHRESH_SHIFT) &
2185 IGC_TXDCTL_HTHRESH_MSK;
2186 txdctl |= ((uint32_t)txq->wthresh << IGC_TXDCTL_WTHRESH_SHIFT) &
2187 IGC_TXDCTL_WTHRESH_MSK;
2188 txdctl |= IGC_TXDCTL_QUEUE_ENABLE;
2189 IGC_WRITE_REG(hw, IGC_TXDCTL(txq->reg_idx), txdctl);
2192 igc_config_collision_dist(hw);
2194 /* Program the Transmit Control Register. */
2195 tctl = IGC_READ_REG(hw, IGC_TCTL);
2196 tctl &= ~IGC_TCTL_CT;
2197 tctl |= (IGC_TCTL_PSP | IGC_TCTL_RTLC | IGC_TCTL_EN |
2198 ((uint32_t)IGC_COLLISION_THRESHOLD << IGC_CT_SHIFT));
2200 /* This write will effectively turn on the transmit unit. */
2201 IGC_WRITE_REG(hw, IGC_TCTL, tctl);
2205 eth_igc_rxq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
2206 struct rte_eth_rxq_info *qinfo)
2208 struct igc_rx_queue *rxq;
2210 rxq = dev->data->rx_queues[queue_id];
2212 qinfo->mp = rxq->mb_pool;
2213 qinfo->scattered_rx = dev->data->scattered_rx;
2214 qinfo->nb_desc = rxq->nb_rx_desc;
2216 qinfo->conf.rx_free_thresh = rxq->rx_free_thresh;
2217 qinfo->conf.rx_drop_en = rxq->drop_en;
2218 qinfo->conf.offloads = rxq->offloads;
2219 qinfo->conf.rx_thresh.hthresh = rxq->hthresh;
2220 qinfo->conf.rx_thresh.pthresh = rxq->pthresh;
2221 qinfo->conf.rx_thresh.wthresh = rxq->wthresh;
2225 eth_igc_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
2226 struct rte_eth_txq_info *qinfo)
2228 struct igc_tx_queue *txq;
2230 txq = dev->data->tx_queues[queue_id];
2232 qinfo->nb_desc = txq->nb_tx_desc;
2234 qinfo->conf.tx_thresh.pthresh = txq->pthresh;
2235 qinfo->conf.tx_thresh.hthresh = txq->hthresh;
2236 qinfo->conf.tx_thresh.wthresh = txq->wthresh;
2237 qinfo->conf.offloads = txq->offloads;
2241 eth_igc_vlan_strip_queue_set(struct rte_eth_dev *dev,
2242 uint16_t rx_queue_id, int on)
2244 struct igc_hw *hw = IGC_DEV_PRIVATE_HW(dev);
2245 struct igc_rx_queue *rxq = dev->data->rx_queues[rx_queue_id];
2248 if (rx_queue_id >= IGC_QUEUE_PAIRS_NUM) {
2249 PMD_DRV_LOG(ERR, "Queue index(%u) illegal, max is %u",
2250 rx_queue_id, IGC_QUEUE_PAIRS_NUM - 1);
2254 reg_val = IGC_READ_REG(hw, IGC_DVMOLR(rx_queue_id));
2256 reg_val |= IGC_DVMOLR_STRVLAN;
2257 rxq->offloads |= RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
2259 reg_val &= ~(IGC_DVMOLR_STRVLAN | IGC_DVMOLR_HIDVLAN);
2260 rxq->offloads &= ~RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
2263 IGC_WRITE_REG(hw, IGC_DVMOLR(rx_queue_id), reg_val);