Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2020 Intel Corporation
3 : : */
4 : :
5 : : #include <rte_config.h>
6 : : #include <rte_flow.h>
7 : : #include <rte_malloc.h>
8 : : #include <ethdev_driver.h>
9 : : #include <rte_net.h>
10 : :
11 : : #include "igc_logs.h"
12 : : #include "igc_txrx.h"
13 : :
14 : : #ifdef RTE_PMD_USE_PREFETCH
15 : : #define rte_igc_prefetch(p) rte_prefetch0(p)
16 : : #else
17 : : #define rte_igc_prefetch(p) do {} while (0)
18 : : #endif
19 : :
20 : : #ifdef RTE_PMD_PACKET_PREFETCH
21 : : #define rte_packet_prefetch(p) rte_prefetch1(p)
22 : : #else
23 : : #define rte_packet_prefetch(p) do {} while (0)
24 : : #endif
25 : :
26 : : /* Multicast / Unicast table offset mask. */
27 : : #define IGC_RCTL_MO_MSK (3u << IGC_RCTL_MO_SHIFT)
28 : :
29 : : /* Loopback mode. */
30 : : #define IGC_RCTL_LBM_SHIFT 6
31 : : #define IGC_RCTL_LBM_MSK (3u << IGC_RCTL_LBM_SHIFT)
32 : :
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)
37 : :
38 : : /* Receive buffer size for header buffer */
39 : : #define IGC_SRRCTL_BSIZEHEADER_SHIFT 8
40 : :
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)
56 : :
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)
64 : :
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)
72 : :
73 : : #define IGC_TSO_MAX_HDRLEN 512
74 : : #define IGC_TSO_MAX_MSS 9216
75 : :
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 | \
85 : : RTE_MBUF_F_TX_IEEE1588_TMST)
86 : :
87 : : #define IGC_TX_OFFLOAD_SEG (RTE_MBUF_F_TX_TCP_SEG | RTE_MBUF_F_TX_UDP_SEG)
88 : :
89 : : #define IGC_ADVTXD_POPTS_TXSM 0x00000200 /* L4 Checksum offload request */
90 : : #define IGC_ADVTXD_POPTS_IXSM 0x00000100 /* IP Checksum offload request */
91 : :
92 : : /* L4 Packet TYPE of Reserved */
93 : : #define IGC_ADVTXD_TUCMD_L4T_RSV 0x00001800
94 : :
95 : : #define IGC_TX_OFFLOAD_NOTSUP_MASK (RTE_MBUF_F_TX_OFFLOAD_MASK ^ IGC_TX_OFFLOAD_MASK)
96 : :
97 : : #define IGC_TS_HDR_LEN 16
98 : :
99 : : static inline uint64_t
100 : 0 : rx_desc_statuserr_to_pkt_flags(uint32_t statuserr)
101 : : {
102 : : static uint64_t l4_chksum_flags[] = {0, 0,
103 : : RTE_MBUF_F_RX_L4_CKSUM_GOOD,
104 : : RTE_MBUF_F_RX_L4_CKSUM_BAD};
105 : :
106 : : static uint64_t l3_chksum_flags[] = {0, 0,
107 : : RTE_MBUF_F_RX_IP_CKSUM_GOOD,
108 : : RTE_MBUF_F_RX_IP_CKSUM_BAD};
109 : : uint64_t pkt_flags = 0;
110 : : uint32_t tmp;
111 : :
112 [ # # ]: 0 : if (statuserr & IGC_RXD_STAT_VP)
113 : : pkt_flags |= RTE_MBUF_F_RX_VLAN_STRIPPED;
114 : :
115 : 0 : tmp = !!(statuserr & (IGC_RXD_STAT_L4CS | IGC_RXD_STAT_UDPCS));
116 : 0 : tmp = (tmp << 1) | (uint32_t)!!(statuserr & IGC_RXD_EXT_ERR_L4E);
117 : 0 : pkt_flags |= l4_chksum_flags[tmp];
118 : :
119 : 0 : tmp = !!(statuserr & IGC_RXD_STAT_IPCS);
120 : 0 : tmp = (tmp << 1) | (uint32_t)!!(statuserr & IGC_RXD_EXT_ERR_IPE);
121 : 0 : pkt_flags |= l3_chksum_flags[tmp];
122 : :
123 : 0 : return pkt_flags;
124 : : }
125 : :
126 : : #define IGC_PACKET_TYPE_IPV4 0X01
127 : : #define IGC_PACKET_TYPE_IPV4_TCP 0X11
128 : : #define IGC_PACKET_TYPE_IPV4_UDP 0X21
129 : : #define IGC_PACKET_TYPE_IPV4_SCTP 0X41
130 : : #define IGC_PACKET_TYPE_IPV4_EXT 0X03
131 : : #define IGC_PACKET_TYPE_IPV4_EXT_SCTP 0X43
132 : : #define IGC_PACKET_TYPE_IPV6 0X04
133 : : #define IGC_PACKET_TYPE_IPV6_TCP 0X14
134 : : #define IGC_PACKET_TYPE_IPV6_UDP 0X24
135 : : #define IGC_PACKET_TYPE_IPV6_EXT 0X0C
136 : : #define IGC_PACKET_TYPE_IPV6_EXT_TCP 0X1C
137 : : #define IGC_PACKET_TYPE_IPV6_EXT_UDP 0X2C
138 : : #define IGC_PACKET_TYPE_IPV4_IPV6 0X05
139 : : #define IGC_PACKET_TYPE_IPV4_IPV6_TCP 0X15
140 : : #define IGC_PACKET_TYPE_IPV4_IPV6_UDP 0X25
141 : : #define IGC_PACKET_TYPE_IPV4_IPV6_EXT 0X0D
142 : : #define IGC_PACKET_TYPE_IPV4_IPV6_EXT_TCP 0X1D
143 : : #define IGC_PACKET_TYPE_IPV4_IPV6_EXT_UDP 0X2D
144 : : #define IGC_PACKET_TYPE_MAX 0X80
145 : : #define IGC_PACKET_TYPE_MASK 0X7F
146 : : #define IGC_PACKET_TYPE_SHIFT 0X04
147 : :
148 : : static inline uint32_t
149 : : rx_desc_pkt_info_to_pkt_type(uint32_t pkt_info)
150 : : {
151 : : static const uint32_t
152 : : ptype_table[IGC_PACKET_TYPE_MAX] __rte_cache_aligned = {
153 : : [IGC_PACKET_TYPE_IPV4] = RTE_PTYPE_L2_ETHER |
154 : : RTE_PTYPE_L3_IPV4,
155 : : [IGC_PACKET_TYPE_IPV4_EXT] = RTE_PTYPE_L2_ETHER |
156 : : RTE_PTYPE_L3_IPV4_EXT,
157 : : [IGC_PACKET_TYPE_IPV6] = RTE_PTYPE_L2_ETHER |
158 : : RTE_PTYPE_L3_IPV6,
159 : : [IGC_PACKET_TYPE_IPV4_IPV6] = RTE_PTYPE_L2_ETHER |
160 : : RTE_PTYPE_L3_IPV4 | RTE_PTYPE_TUNNEL_IP |
161 : : RTE_PTYPE_INNER_L3_IPV6,
162 : : [IGC_PACKET_TYPE_IPV6_EXT] = RTE_PTYPE_L2_ETHER |
163 : : RTE_PTYPE_L3_IPV6_EXT,
164 : : [IGC_PACKET_TYPE_IPV4_IPV6_EXT] = RTE_PTYPE_L2_ETHER |
165 : : RTE_PTYPE_L3_IPV4 | RTE_PTYPE_TUNNEL_IP |
166 : : RTE_PTYPE_INNER_L3_IPV6_EXT,
167 : : [IGC_PACKET_TYPE_IPV4_TCP] = RTE_PTYPE_L2_ETHER |
168 : : RTE_PTYPE_L3_IPV4 | RTE_PTYPE_L4_TCP,
169 : : [IGC_PACKET_TYPE_IPV6_TCP] = RTE_PTYPE_L2_ETHER |
170 : : RTE_PTYPE_L3_IPV6 | RTE_PTYPE_L4_TCP,
171 : : [IGC_PACKET_TYPE_IPV4_IPV6_TCP] = RTE_PTYPE_L2_ETHER |
172 : : RTE_PTYPE_L3_IPV4 | RTE_PTYPE_TUNNEL_IP |
173 : : RTE_PTYPE_INNER_L3_IPV6 | RTE_PTYPE_INNER_L4_TCP,
174 : : [IGC_PACKET_TYPE_IPV6_EXT_TCP] = RTE_PTYPE_L2_ETHER |
175 : : RTE_PTYPE_L3_IPV6_EXT | RTE_PTYPE_L4_TCP,
176 : : [IGC_PACKET_TYPE_IPV4_IPV6_EXT_TCP] = RTE_PTYPE_L2_ETHER |
177 : : RTE_PTYPE_L3_IPV4 | RTE_PTYPE_TUNNEL_IP |
178 : : RTE_PTYPE_INNER_L3_IPV6_EXT | RTE_PTYPE_INNER_L4_TCP,
179 : : [IGC_PACKET_TYPE_IPV4_UDP] = RTE_PTYPE_L2_ETHER |
180 : : RTE_PTYPE_L3_IPV4 | RTE_PTYPE_L4_UDP,
181 : : [IGC_PACKET_TYPE_IPV6_UDP] = RTE_PTYPE_L2_ETHER |
182 : : RTE_PTYPE_L3_IPV6 | RTE_PTYPE_L4_UDP,
183 : : [IGC_PACKET_TYPE_IPV4_IPV6_UDP] = RTE_PTYPE_L2_ETHER |
184 : : RTE_PTYPE_L3_IPV4 | RTE_PTYPE_TUNNEL_IP |
185 : : RTE_PTYPE_INNER_L3_IPV6 | RTE_PTYPE_INNER_L4_UDP,
186 : : [IGC_PACKET_TYPE_IPV6_EXT_UDP] = RTE_PTYPE_L2_ETHER |
187 : : RTE_PTYPE_L3_IPV6_EXT | RTE_PTYPE_L4_UDP,
188 : : [IGC_PACKET_TYPE_IPV4_IPV6_EXT_UDP] = RTE_PTYPE_L2_ETHER |
189 : : RTE_PTYPE_L3_IPV4 | RTE_PTYPE_TUNNEL_IP |
190 : : RTE_PTYPE_INNER_L3_IPV6_EXT | RTE_PTYPE_INNER_L4_UDP,
191 : : [IGC_PACKET_TYPE_IPV4_SCTP] = RTE_PTYPE_L2_ETHER |
192 : : RTE_PTYPE_L3_IPV4 | RTE_PTYPE_L4_SCTP,
193 : : [IGC_PACKET_TYPE_IPV4_EXT_SCTP] = RTE_PTYPE_L2_ETHER |
194 : : RTE_PTYPE_L3_IPV4_EXT | RTE_PTYPE_L4_SCTP,
195 : : };
196 : 0 : if (unlikely(pkt_info & IGC_RXDADV_PKTTYPE_ETQF))
197 : : return RTE_PTYPE_UNKNOWN;
198 : :
199 : 0 : pkt_info = (pkt_info >> IGC_PACKET_TYPE_SHIFT) & IGC_PACKET_TYPE_MASK;
200 : :
201 : 0 : return ptype_table[pkt_info];
202 : : }
203 : :
204 : : static inline void
205 : 0 : rx_desc_get_pkt_info(struct igc_rx_queue *rxq, struct rte_mbuf *rxm,
206 : : union igc_adv_rx_desc *rxd, uint32_t staterr)
207 : : {
208 : : uint64_t pkt_flags;
209 : : uint32_t hlen_type_rss;
210 : : uint16_t pkt_info;
211 : :
212 : : /* Prefetch data of first segment, if configured to do so. */
213 : 0 : rte_packet_prefetch((char *)rxm->buf_addr + rxm->data_off);
214 : :
215 : 0 : rxm->port = rxq->port_id;
216 : 0 : hlen_type_rss = rte_le_to_cpu_32(rxd->wb.lower.lo_dword.data);
217 : 0 : rxm->hash.rss = rte_le_to_cpu_32(rxd->wb.lower.hi_dword.rss);
218 : 0 : rxm->vlan_tci = rte_le_to_cpu_16(rxd->wb.upper.vlan);
219 : :
220 : 0 : pkt_flags = (hlen_type_rss & IGC_RXD_RSS_TYPE_MASK) ?
221 [ # # ]: 0 : RTE_MBUF_F_RX_RSS_HASH : 0;
222 : :
223 [ # # ]: 0 : if (hlen_type_rss & IGC_RXD_VPKT)
224 : 0 : pkt_flags |= RTE_MBUF_F_RX_VLAN;
225 : :
226 : 0 : pkt_flags |= rx_desc_statuserr_to_pkt_flags(staterr);
227 : :
228 [ # # ]: 0 : if (rxq->offloads & RTE_ETH_RX_OFFLOAD_TIMESTAMP)
229 : 0 : pkt_flags |= RTE_MBUF_F_RX_IEEE1588_PTP;
230 : :
231 : 0 : rxm->ol_flags = pkt_flags;
232 : 0 : pkt_info = rte_le_to_cpu_16(rxd->wb.lower.lo_dword.hs_rss.pkt_info);
233 [ # # ]: 0 : rxm->packet_type = rx_desc_pkt_info_to_pkt_type(pkt_info);
234 : 0 : }
235 : :
236 : : uint16_t
237 : 0 : igc_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
238 : : {
239 : : struct igc_rx_queue * const rxq = rx_queue;
240 : 0 : volatile union igc_adv_rx_desc * const rx_ring = rxq->rx_ring;
241 : 0 : struct igc_rx_entry * const sw_ring = rxq->sw_ring;
242 : 0 : uint16_t rx_id = rxq->rx_tail;
243 : : uint16_t nb_rx = 0;
244 : : uint16_t nb_hold = 0;
245 : :
246 [ # # ]: 0 : while (nb_rx < nb_pkts) {
247 : : volatile union igc_adv_rx_desc *rxdp;
248 : : struct igc_rx_entry *rxe;
249 : : struct rte_mbuf *rxm;
250 : : struct rte_mbuf *nmb;
251 : : union igc_adv_rx_desc rxd;
252 : : uint32_t staterr;
253 : : uint16_t data_len;
254 : :
255 : : /*
256 : : * The order of operations here is important as the DD status
257 : : * bit must not be read after any other descriptor fields.
258 : : * rx_ring and rxdp are pointing to volatile data so the order
259 : : * of accesses cannot be reordered by the compiler. If they were
260 : : * not volatile, they could be reordered which could lead to
261 : : * using invalid descriptor fields when read from rxd.
262 : : */
263 : 0 : rxdp = &rx_ring[rx_id];
264 : 0 : staterr = rte_cpu_to_le_32(rxdp->wb.upper.status_error);
265 [ # # ]: 0 : if (!(staterr & IGC_RXD_STAT_DD))
266 : : break;
267 : 0 : rxd = *rxdp;
268 : :
269 : : /*
270 : : * End of packet.
271 : : *
272 : : * If the IGC_RXD_STAT_EOP flag is not set, the RX packet is
273 : : * likely to be invalid and to be dropped by the various
274 : : * validation checks performed by the network stack.
275 : : *
276 : : * Allocate a new mbuf to replenish the RX ring descriptor.
277 : : * If the allocation fails:
278 : : * - arrange for that RX descriptor to be the first one
279 : : * being parsed the next time the receive function is
280 : : * invoked [on the same queue].
281 : : *
282 : : * - Stop parsing the RX ring and return immediately.
283 : : *
284 : : * This policy does not drop the packet received in the RX
285 : : * descriptor for which the allocation of a new mbuf failed.
286 : : * Thus, it allows that packet to be later retrieved if
287 : : * mbuf have been freed in the mean time.
288 : : * As a side effect, holding RX descriptors instead of
289 : : * systematically giving them back to the NIC may lead to
290 : : * RX ring exhaustion situations.
291 : : * However, the NIC can gracefully prevent such situations
292 : : * to happen by sending specific "back-pressure" flow control
293 : : * frames to its peer(s).
294 : : */
295 : : PMD_RX_LOG(DEBUG,
296 : : "port_id=%u queue_id=%u rx_id=%u staterr=0x%x data_len=%u",
297 : : rxq->port_id, rxq->queue_id, rx_id, staterr,
298 : : rte_le_to_cpu_16(rxd.wb.upper.length));
299 : :
300 : 0 : nmb = rte_mbuf_raw_alloc(rxq->mb_pool);
301 [ # # ]: 0 : if (nmb == NULL) {
302 : : unsigned int id;
303 : : PMD_RX_LOG(DEBUG,
304 : : "RX mbuf alloc failed, port_id=%u queue_id=%u",
305 : : rxq->port_id, rxq->queue_id);
306 : 0 : id = rxq->port_id;
307 : 0 : rte_eth_devices[id].data->rx_mbuf_alloc_failed++;
308 : 0 : break;
309 : : }
310 : :
311 : 0 : nb_hold++;
312 : 0 : rxe = &sw_ring[rx_id];
313 : 0 : rx_id++;
314 [ # # ]: 0 : if (rx_id >= rxq->nb_rx_desc)
315 : : rx_id = 0;
316 : :
317 : : /* Prefetch next mbuf while processing current one. */
318 : : rte_igc_prefetch(sw_ring[rx_id].mbuf);
319 : :
320 : : /*
321 : : * When next RX descriptor is on a cache-line boundary,
322 : : * prefetch the next 4 RX descriptors and the next 8 pointers
323 : : * to mbufs.
324 : : */
325 : : if ((rx_id & 0x3) == 0) {
326 : : rte_igc_prefetch(&rx_ring[rx_id]);
327 : : rte_igc_prefetch(&sw_ring[rx_id]);
328 : : }
329 : :
330 : : /*
331 : : * Update RX descriptor with the physical address of the new
332 : : * data buffer of the new allocated mbuf.
333 : : */
334 : 0 : rxm = rxe->mbuf;
335 : 0 : rxe->mbuf = nmb;
336 : 0 : rxdp->read.hdr_addr = 0;
337 : :
338 [ # # ]: 0 : if (rxq->offloads & RTE_ETH_RX_OFFLOAD_TIMESTAMP)
339 : 0 : rxdp->read.pkt_addr =
340 : 0 : rte_cpu_to_le_64(rte_mbuf_data_iova_default(nmb)) -
341 : : IGC_TS_HDR_LEN;
342 : : else
343 : 0 : rxdp->read.pkt_addr =
344 : : rte_cpu_to_le_64(rte_mbuf_data_iova_default(nmb));
345 : :
346 : 0 : rxm->next = NULL;
347 : :
348 : 0 : rxm->data_off = RTE_PKTMBUF_HEADROOM;
349 : 0 : data_len = rte_le_to_cpu_16(rxd.wb.upper.length) - rxq->crc_len;
350 : 0 : rxm->data_len = data_len;
351 : 0 : rxm->pkt_len = data_len;
352 : 0 : rxm->nb_segs = 1;
353 : :
354 : 0 : rx_desc_get_pkt_info(rxq, rxm, &rxd, staterr);
355 : :
356 [ # # ]: 0 : if (rxq->offloads & RTE_ETH_RX_OFFLOAD_TIMESTAMP) {
357 : 0 : uint32_t *ts = rte_pktmbuf_mtod_offset(rxm,
358 : : uint32_t *, -IGC_TS_HDR_LEN);
359 : 0 : rxq->rx_timestamp = (uint64_t)ts[3] * NSEC_PER_SEC +
360 : 0 : ts[2];
361 : 0 : rxm->timesync = rxq->queue_id;
362 : : }
363 : :
364 : : /*
365 : : * Store the mbuf address into the next entry of the array
366 : : * of returned packets.
367 : : */
368 : 0 : rx_pkts[nb_rx++] = rxm;
369 : : }
370 : 0 : rxq->rx_tail = rx_id;
371 : :
372 : : /*
373 : : * If the number of free RX descriptors is greater than the RX free
374 : : * threshold of the queue, advance the Receive Descriptor Tail (RDT)
375 : : * register.
376 : : * Update the RDT with the value of the last processed RX descriptor
377 : : * minus 1, to guarantee that the RDT register is never equal to the
378 : : * RDH register, which creates a "full" ring situation from the
379 : : * hardware point of view...
380 : : */
381 : 0 : nb_hold = nb_hold + rxq->nb_rx_hold;
382 [ # # ]: 0 : if (nb_hold > rxq->rx_free_thresh) {
383 : : PMD_RX_LOG(DEBUG,
384 : : "port_id=%u queue_id=%u rx_tail=%u nb_hold=%u nb_rx=%u",
385 : : rxq->port_id, rxq->queue_id, rx_id, nb_hold, nb_rx);
386 [ # # ]: 0 : rx_id = (rx_id == 0) ? (rxq->nb_rx_desc - 1) : (rx_id - 1);
387 : 0 : IGC_PCI_REG_WRITE(rxq->rdt_reg_addr, rx_id);
388 : : nb_hold = 0;
389 : : }
390 : 0 : rxq->nb_rx_hold = nb_hold;
391 : 0 : return nb_rx;
392 : : }
393 : :
394 : : uint16_t
395 : 0 : igc_recv_scattered_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
396 : : uint16_t nb_pkts)
397 : : {
398 : : struct igc_rx_queue * const rxq = rx_queue;
399 : 0 : volatile union igc_adv_rx_desc * const rx_ring = rxq->rx_ring;
400 : 0 : struct igc_rx_entry * const sw_ring = rxq->sw_ring;
401 : 0 : struct rte_mbuf *first_seg = rxq->pkt_first_seg;
402 : 0 : struct rte_mbuf *last_seg = rxq->pkt_last_seg;
403 : :
404 : 0 : uint16_t rx_id = rxq->rx_tail;
405 : : uint16_t nb_rx = 0;
406 : : uint16_t nb_hold = 0;
407 : :
408 [ # # ]: 0 : while (nb_rx < nb_pkts) {
409 : : volatile union igc_adv_rx_desc *rxdp;
410 : : struct igc_rx_entry *rxe;
411 : : struct rte_mbuf *rxm;
412 : : struct rte_mbuf *nmb;
413 : : union igc_adv_rx_desc rxd;
414 : : uint32_t staterr;
415 : : uint16_t data_len;
416 : :
417 : 0 : next_desc:
418 : : /*
419 : : * The order of operations here is important as the DD status
420 : : * bit must not be read after any other descriptor fields.
421 : : * rx_ring and rxdp are pointing to volatile data so the order
422 : : * of accesses cannot be reordered by the compiler. If they were
423 : : * not volatile, they could be reordered which could lead to
424 : : * using invalid descriptor fields when read from rxd.
425 : : */
426 : 0 : rxdp = &rx_ring[rx_id];
427 : 0 : staterr = rte_cpu_to_le_32(rxdp->wb.upper.status_error);
428 [ # # ]: 0 : if (!(staterr & IGC_RXD_STAT_DD))
429 : : break;
430 : 0 : rxd = *rxdp;
431 : :
432 : : /*
433 : : * Descriptor done.
434 : : *
435 : : * Allocate a new mbuf to replenish the RX ring descriptor.
436 : : * If the allocation fails:
437 : : * - arrange for that RX descriptor to be the first one
438 : : * being parsed the next time the receive function is
439 : : * invoked [on the same queue].
440 : : *
441 : : * - Stop parsing the RX ring and return immediately.
442 : : *
443 : : * This policy does not drop the packet received in the RX
444 : : * descriptor for which the allocation of a new mbuf failed.
445 : : * Thus, it allows that packet to be later retrieved if
446 : : * mbuf have been freed in the mean time.
447 : : * As a side effect, holding RX descriptors instead of
448 : : * systematically giving them back to the NIC may lead to
449 : : * RX ring exhaustion situations.
450 : : * However, the NIC can gracefully prevent such situations
451 : : * to happen by sending specific "back-pressure" flow control
452 : : * frames to its peer(s).
453 : : */
454 : : PMD_RX_LOG(DEBUG,
455 : : "port_id=%u queue_id=%u rx_id=%u staterr=0x%x data_len=%u",
456 : : rxq->port_id, rxq->queue_id, rx_id, staterr,
457 : : rte_le_to_cpu_16(rxd.wb.upper.length));
458 : :
459 : 0 : nmb = rte_mbuf_raw_alloc(rxq->mb_pool);
460 [ # # ]: 0 : if (nmb == NULL) {
461 : : unsigned int id;
462 : : PMD_RX_LOG(DEBUG,
463 : : "RX mbuf alloc failed, port_id=%u queue_id=%u",
464 : : rxq->port_id, rxq->queue_id);
465 : 0 : id = rxq->port_id;
466 : 0 : rte_eth_devices[id].data->rx_mbuf_alloc_failed++;
467 : 0 : break;
468 : : }
469 : :
470 : 0 : nb_hold++;
471 : 0 : rxe = &sw_ring[rx_id];
472 : 0 : rx_id++;
473 [ # # ]: 0 : if (rx_id >= rxq->nb_rx_desc)
474 : : rx_id = 0;
475 : :
476 : : /* Prefetch next mbuf while processing current one. */
477 : : rte_igc_prefetch(sw_ring[rx_id].mbuf);
478 : :
479 : : /*
480 : : * When next RX descriptor is on a cache-line boundary,
481 : : * prefetch the next 4 RX descriptors and the next 8 pointers
482 : : * to mbufs.
483 : : */
484 : : if ((rx_id & 0x3) == 0) {
485 : : rte_igc_prefetch(&rx_ring[rx_id]);
486 : : rte_igc_prefetch(&sw_ring[rx_id]);
487 : : }
488 : :
489 : : /*
490 : : * Update RX descriptor with the physical address of the new
491 : : * data buffer of the new allocated mbuf.
492 : : */
493 : 0 : rxm = rxe->mbuf;
494 : 0 : rxe->mbuf = nmb;
495 : 0 : rxdp->read.hdr_addr = 0;
496 : :
497 [ # # ]: 0 : if (rxq->offloads & RTE_ETH_RX_OFFLOAD_TIMESTAMP)
498 : 0 : rxdp->read.pkt_addr =
499 : 0 : rte_cpu_to_le_64(rte_mbuf_data_iova_default(nmb)) -
500 : : IGC_TS_HDR_LEN;
501 : : else
502 : 0 : rxdp->read.pkt_addr =
503 : : rte_cpu_to_le_64(rte_mbuf_data_iova_default(nmb));
504 : :
505 : 0 : rxm->next = NULL;
506 : :
507 : : /*
508 : : * Set data length & data buffer address of mbuf.
509 : : */
510 : 0 : rxm->data_off = RTE_PKTMBUF_HEADROOM;
511 : 0 : data_len = rte_le_to_cpu_16(rxd.wb.upper.length);
512 : 0 : rxm->data_len = data_len;
513 : :
514 : : /*
515 : : * If this is the first buffer of the received packet,
516 : : * set the pointer to the first mbuf of the packet and
517 : : * initialize its context.
518 : : * Otherwise, update the total length and the number of segments
519 : : * of the current scattered packet, and update the pointer to
520 : : * the last mbuf of the current packet.
521 : : */
522 [ # # ]: 0 : if (first_seg == NULL) {
523 : : first_seg = rxm;
524 : 0 : first_seg->pkt_len = data_len;
525 : 0 : first_seg->nb_segs = 1;
526 : : } else {
527 : 0 : first_seg->pkt_len += data_len;
528 : 0 : first_seg->nb_segs++;
529 : 0 : last_seg->next = rxm;
530 : : }
531 : :
532 : : /*
533 : : * If this is not the last buffer of the received packet,
534 : : * update the pointer to the last mbuf of the current scattered
535 : : * packet and continue to parse the RX ring.
536 : : */
537 [ # # ]: 0 : if (!(staterr & IGC_RXD_STAT_EOP)) {
538 : : last_seg = rxm;
539 : 0 : goto next_desc;
540 : : }
541 : :
542 : : /*
543 : : * This is the last buffer of the received packet.
544 : : * If the CRC is not stripped by the hardware:
545 : : * - Subtract the CRC length from the total packet length.
546 : : * - If the last buffer only contains the whole CRC or a part
547 : : * of it, free the mbuf associated to the last buffer.
548 : : * If part of the CRC is also contained in the previous
549 : : * mbuf, subtract the length of that CRC part from the
550 : : * data length of the previous mbuf.
551 : : */
552 [ # # ]: 0 : if (unlikely(rxq->crc_len > 0)) {
553 : 0 : first_seg->pkt_len -= RTE_ETHER_CRC_LEN;
554 [ # # ]: 0 : if (data_len <= RTE_ETHER_CRC_LEN) {
555 : : rte_pktmbuf_free_seg(rxm);
556 : 0 : first_seg->nb_segs--;
557 : 0 : last_seg->data_len = last_seg->data_len -
558 : : (RTE_ETHER_CRC_LEN - data_len);
559 : 0 : last_seg->next = NULL;
560 : : } else {
561 : 0 : rxm->data_len = (uint16_t)
562 : : (data_len - RTE_ETHER_CRC_LEN);
563 : : }
564 : : }
565 : :
566 : 0 : rx_desc_get_pkt_info(rxq, first_seg, &rxd, staterr);
567 : :
568 [ # # ]: 0 : if (rxq->offloads & RTE_ETH_RX_OFFLOAD_TIMESTAMP) {
569 : 0 : uint32_t *ts = rte_pktmbuf_mtod_offset(first_seg,
570 : : uint32_t *, -IGC_TS_HDR_LEN);
571 : 0 : rxq->rx_timestamp = (uint64_t)ts[3] * NSEC_PER_SEC +
572 : 0 : ts[2];
573 : 0 : rxm->timesync = rxq->queue_id;
574 : : }
575 : :
576 : : /*
577 : : * Store the mbuf address into the next entry of the array
578 : : * of returned packets.
579 : : */
580 : 0 : rx_pkts[nb_rx++] = first_seg;
581 : :
582 : : /* Setup receipt context for a new packet. */
583 : : first_seg = NULL;
584 : : }
585 : 0 : rxq->rx_tail = rx_id;
586 : :
587 : : /*
588 : : * Save receive context.
589 : : */
590 : 0 : rxq->pkt_first_seg = first_seg;
591 : 0 : rxq->pkt_last_seg = last_seg;
592 : :
593 : : /*
594 : : * If the number of free RX descriptors is greater than the RX free
595 : : * threshold of the queue, advance the Receive Descriptor Tail (RDT)
596 : : * register.
597 : : * Update the RDT with the value of the last processed RX descriptor
598 : : * minus 1, to guarantee that the RDT register is never equal to the
599 : : * RDH register, which creates a "full" ring situation from the
600 : : * hardware point of view...
601 : : */
602 : 0 : nb_hold = nb_hold + rxq->nb_rx_hold;
603 [ # # ]: 0 : if (nb_hold > rxq->rx_free_thresh) {
604 : : PMD_RX_LOG(DEBUG,
605 : : "port_id=%u queue_id=%u rx_tail=%u nb_hold=%u nb_rx=%u",
606 : : rxq->port_id, rxq->queue_id, rx_id, nb_hold, nb_rx);
607 [ # # ]: 0 : rx_id = (rx_id == 0) ? (rxq->nb_rx_desc - 1) : (rx_id - 1);
608 : 0 : IGC_PCI_REG_WRITE(rxq->rdt_reg_addr, rx_id);
609 : : nb_hold = 0;
610 : : }
611 : 0 : rxq->nb_rx_hold = nb_hold;
612 : 0 : return nb_rx;
613 : : }
614 : :
615 : : static void
616 : 0 : igc_rx_queue_release_mbufs(struct igc_rx_queue *rxq)
617 : : {
618 : : unsigned int i;
619 : :
620 [ # # ]: 0 : if (rxq->sw_ring != NULL) {
621 [ # # ]: 0 : for (i = 0; i < rxq->nb_rx_desc; i++) {
622 [ # # ]: 0 : if (rxq->sw_ring[i].mbuf != NULL) {
623 : : rte_pktmbuf_free_seg(rxq->sw_ring[i].mbuf);
624 : 0 : rxq->sw_ring[i].mbuf = NULL;
625 : : }
626 : : }
627 : : }
628 : 0 : }
629 : :
630 : : static void
631 : 0 : igc_rx_queue_release(struct igc_rx_queue *rxq)
632 : : {
633 : 0 : igc_rx_queue_release_mbufs(rxq);
634 : 0 : rte_free(rxq->sw_ring);
635 : 0 : rte_free(rxq);
636 : 0 : }
637 : :
638 : 0 : void eth_igc_rx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
639 : : {
640 [ # # ]: 0 : if (dev->data->rx_queues[qid])
641 : 0 : igc_rx_queue_release(dev->data->rx_queues[qid]);
642 : 0 : }
643 : :
644 : 0 : uint32_t eth_igc_rx_queue_count(void *rx_queue)
645 : : {
646 : : /**
647 : : * Check the DD bit of a rx descriptor of each 4 in a group,
648 : : * to avoid checking too frequently and downgrading performance
649 : : * too much.
650 : : */
651 : : #define IGC_RXQ_SCAN_INTERVAL 4
652 : :
653 : : volatile union igc_adv_rx_desc *rxdp;
654 : : struct igc_rx_queue *rxq;
655 : : uint16_t desc = 0;
656 : :
657 : : rxq = rx_queue;
658 : 0 : rxdp = &rxq->rx_ring[rxq->rx_tail];
659 : :
660 [ # # ]: 0 : while (desc < rxq->nb_rx_desc - rxq->rx_tail) {
661 [ # # ]: 0 : if (unlikely(!(rxdp->wb.upper.status_error &
662 : : IGC_RXD_STAT_DD)))
663 : 0 : return desc;
664 : 0 : desc += IGC_RXQ_SCAN_INTERVAL;
665 : 0 : rxdp += IGC_RXQ_SCAN_INTERVAL;
666 : : }
667 : 0 : rxdp = &rxq->rx_ring[rxq->rx_tail + desc - rxq->nb_rx_desc];
668 : :
669 [ # # ]: 0 : while (desc < rxq->nb_rx_desc &&
670 [ # # ]: 0 : (rxdp->wb.upper.status_error & IGC_RXD_STAT_DD)) {
671 : 0 : desc += IGC_RXQ_SCAN_INTERVAL;
672 : 0 : rxdp += IGC_RXQ_SCAN_INTERVAL;
673 : : }
674 : :
675 : 0 : return desc;
676 : : }
677 : :
678 : 0 : int eth_igc_rx_descriptor_status(void *rx_queue, uint16_t offset)
679 : : {
680 : : struct igc_rx_queue *rxq = rx_queue;
681 : : volatile uint32_t *status;
682 : : uint32_t desc;
683 : :
684 [ # # # # ]: 0 : if (unlikely(!rxq || offset >= rxq->nb_rx_desc))
685 : : return -EINVAL;
686 : :
687 [ # # ]: 0 : if (offset >= rxq->nb_rx_desc - rxq->nb_rx_hold)
688 : : return RTE_ETH_RX_DESC_UNAVAIL;
689 : :
690 : 0 : desc = rxq->rx_tail + offset;
691 [ # # ]: 0 : if (desc >= rxq->nb_rx_desc)
692 : 0 : desc -= rxq->nb_rx_desc;
693 : :
694 : 0 : status = &rxq->rx_ring[desc].wb.upper.status_error;
695 [ # # ]: 0 : if (*status & rte_cpu_to_le_32(IGC_RXD_STAT_DD))
696 : 0 : return RTE_ETH_RX_DESC_DONE;
697 : :
698 : : return RTE_ETH_RX_DESC_AVAIL;
699 : : }
700 : :
701 : : static int
702 : 0 : igc_alloc_rx_queue_mbufs(struct igc_rx_queue *rxq)
703 : : {
704 : 0 : struct igc_rx_entry *rxe = rxq->sw_ring;
705 : : uint64_t dma_addr;
706 : : unsigned int i;
707 : :
708 : : /* Initialize software ring entries. */
709 [ # # ]: 0 : for (i = 0; i < rxq->nb_rx_desc; i++) {
710 : : volatile union igc_adv_rx_desc *rxd;
711 : 0 : struct rte_mbuf *mbuf = rte_mbuf_raw_alloc(rxq->mb_pool);
712 : :
713 [ # # ]: 0 : if (mbuf == NULL) {
714 : 0 : PMD_DRV_LOG(ERR, "RX mbuf alloc failed, queue_id=%hu",
715 : : rxq->queue_id);
716 : 0 : return -ENOMEM;
717 : : }
718 : : dma_addr = rte_cpu_to_le_64(rte_mbuf_data_iova_default(mbuf));
719 : 0 : rxd = &rxq->rx_ring[i];
720 : 0 : rxd->read.hdr_addr = 0;
721 [ # # ]: 0 : if (rxq->offloads & RTE_ETH_RX_OFFLOAD_TIMESTAMP)
722 : 0 : rxd->read.pkt_addr = dma_addr - IGC_TS_HDR_LEN;
723 : : else
724 : 0 : rxd->read.pkt_addr = dma_addr;
725 : 0 : rxe[i].mbuf = mbuf;
726 : : }
727 : :
728 : : return 0;
729 : : }
730 : :
731 : : /*
732 : : * RSS random key supplied in section 7.1.2.9.3 of the Intel I225 datasheet.
733 : : * Used as the default key.
734 : : */
735 : : static uint8_t default_rss_key[40] = {
736 : : 0x6D, 0x5A, 0x56, 0xDA, 0x25, 0x5B, 0x0E, 0xC2,
737 : : 0x41, 0x67, 0x25, 0x3D, 0x43, 0xA3, 0x8F, 0xB0,
738 : : 0xD0, 0xCA, 0x2B, 0xCB, 0xAE, 0x7B, 0x30, 0xB4,
739 : : 0x77, 0xCB, 0x2D, 0xA3, 0x80, 0x30, 0xF2, 0x0C,
740 : : 0x6A, 0x42, 0xB7, 0x3B, 0xBE, 0xAC, 0x01, 0xFA,
741 : : };
742 : :
743 : : void
744 : 0 : igc_rss_disable(struct rte_eth_dev *dev)
745 : : {
746 : 0 : struct igc_hw *hw = IGC_DEV_PRIVATE_HW(dev);
747 : : uint32_t mrqc;
748 : :
749 : 0 : mrqc = IGC_READ_REG(hw, IGC_MRQC);
750 : 0 : mrqc &= ~IGC_MRQC_ENABLE_MASK;
751 : 0 : IGC_WRITE_REG(hw, IGC_MRQC, mrqc);
752 : 0 : }
753 : :
754 : : void
755 : 0 : igc_hw_rss_hash_set(struct igc_hw *hw, struct rte_eth_rss_conf *rss_conf)
756 : : {
757 : 0 : uint32_t *hash_key = (uint32_t *)rss_conf->rss_key;
758 : : uint32_t mrqc;
759 : : uint64_t rss_hf;
760 : :
761 [ # # ]: 0 : if (hash_key != NULL) {
762 : : uint8_t i;
763 : :
764 : : /* Fill in RSS hash key */
765 [ # # ]: 0 : for (i = 0; i < IGC_HKEY_MAX_INDEX; i++)
766 : 0 : IGC_WRITE_REG_LE_VALUE(hw, IGC_RSSRK(i), hash_key[i]);
767 : : }
768 : :
769 : : /* Set configured hashing protocols in MRQC register */
770 : 0 : rss_hf = rss_conf->rss_hf;
771 : : mrqc = IGC_MRQC_ENABLE_RSS_4Q; /* RSS enabled. */
772 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_IPV4)
773 : : mrqc |= IGC_MRQC_RSS_FIELD_IPV4;
774 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_NONFRAG_IPV4_TCP)
775 : 0 : mrqc |= IGC_MRQC_RSS_FIELD_IPV4_TCP;
776 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_IPV6)
777 : 0 : mrqc |= IGC_MRQC_RSS_FIELD_IPV6;
778 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_IPV6_EX)
779 : 0 : mrqc |= IGC_MRQC_RSS_FIELD_IPV6_EX;
780 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_NONFRAG_IPV6_TCP)
781 : 0 : mrqc |= IGC_MRQC_RSS_FIELD_IPV6_TCP;
782 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_IPV6_TCP_EX)
783 : 0 : mrqc |= IGC_MRQC_RSS_FIELD_IPV6_TCP_EX;
784 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_NONFRAG_IPV4_UDP)
785 : 0 : mrqc |= IGC_MRQC_RSS_FIELD_IPV4_UDP;
786 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_NONFRAG_IPV6_UDP)
787 : 0 : mrqc |= IGC_MRQC_RSS_FIELD_IPV6_UDP;
788 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_IPV6_UDP_EX)
789 : 0 : mrqc |= IGC_MRQC_RSS_FIELD_IPV6_UDP_EX;
790 : 0 : IGC_WRITE_REG(hw, IGC_MRQC, mrqc);
791 : 0 : }
792 : :
793 : : static void
794 : 0 : igc_rss_configure(struct rte_eth_dev *dev)
795 : : {
796 : : struct rte_eth_rss_conf rss_conf;
797 : 0 : struct igc_hw *hw = IGC_DEV_PRIVATE_HW(dev);
798 : : uint16_t i;
799 : :
800 : : /* Fill in redirection table. */
801 [ # # ]: 0 : for (i = 0; i < IGC_RSS_RDT_SIZD; i++) {
802 : : union igc_rss_reta_reg reta;
803 : : uint16_t q_idx, reta_idx;
804 : :
805 [ # # ]: 0 : q_idx = (uint8_t)((dev->data->nb_rx_queues > 1) ?
806 : : i % dev->data->nb_rx_queues : 0);
807 : 0 : reta_idx = i % sizeof(reta);
808 : 0 : reta.bytes[reta_idx] = q_idx;
809 [ # # ]: 0 : if (reta_idx == sizeof(reta) - 1)
810 : 0 : IGC_WRITE_REG_LE_VALUE(hw,
811 : : IGC_RETA(i / sizeof(reta)), reta.dword);
812 : : }
813 : :
814 : : /*
815 : : * Configure the RSS key and the RSS protocols used to compute
816 : : * the RSS hash of input packets.
817 : : */
818 : 0 : rss_conf = dev->data->dev_conf.rx_adv_conf.rss_conf;
819 [ # # ]: 0 : if (rss_conf.rss_key == NULL)
820 : 0 : rss_conf.rss_key = default_rss_key;
821 : 0 : igc_hw_rss_hash_set(hw, &rss_conf);
822 : 0 : }
823 : :
824 : : int
825 : 0 : igc_del_rss_filter(struct rte_eth_dev *dev)
826 : : {
827 : 0 : struct igc_rss_filter *rss_filter = IGC_DEV_PRIVATE_RSS_FILTER(dev);
828 : :
829 [ # # ]: 0 : if (rss_filter->enable) {
830 : : /* recover default RSS configuration */
831 : 0 : igc_rss_configure(dev);
832 : :
833 : : /* disable RSS logic and clear filter data */
834 : 0 : igc_rss_disable(dev);
835 : : memset(rss_filter, 0, sizeof(*rss_filter));
836 : 0 : return 0;
837 : : }
838 : 0 : PMD_DRV_LOG(ERR, "filter not exist!");
839 : 0 : return -ENOENT;
840 : : }
841 : :
842 : : /* Initiate the filter structure by the structure of rte_flow_action_rss */
843 : : void
844 : 0 : igc_rss_conf_set(struct igc_rss_filter *out,
845 : : const struct rte_flow_action_rss *rss)
846 : : {
847 : 0 : out->conf.func = rss->func;
848 : 0 : out->conf.level = rss->level;
849 : 0 : out->conf.types = rss->types;
850 : :
851 [ # # ]: 0 : if (rss->key_len == sizeof(out->key)) {
852 : 0 : memcpy(out->key, rss->key, rss->key_len);
853 : 0 : out->conf.key = out->key;
854 : 0 : out->conf.key_len = rss->key_len;
855 : : } else {
856 : 0 : out->conf.key = NULL;
857 : 0 : out->conf.key_len = 0;
858 : : }
859 : :
860 [ # # ]: 0 : if (rss->queue_num <= IGC_RSS_RDT_SIZD) {
861 : 0 : memcpy(out->queue, rss->queue,
862 : 0 : sizeof(*out->queue) * rss->queue_num);
863 : 0 : out->conf.queue = out->queue;
864 : 0 : out->conf.queue_num = rss->queue_num;
865 : : } else {
866 : 0 : out->conf.queue = NULL;
867 : 0 : out->conf.queue_num = 0;
868 : : }
869 : 0 : }
870 : :
871 : : int
872 : 0 : igc_add_rss_filter(struct rte_eth_dev *dev, struct igc_rss_filter *rss)
873 : : {
874 : 0 : struct rte_eth_rss_conf rss_conf = {
875 : 0 : .rss_key = rss->conf.key_len ?
876 [ # # ]: 0 : (void *)(uintptr_t)rss->conf.key : NULL,
877 : : .rss_key_len = rss->conf.key_len,
878 : 0 : .rss_hf = rss->conf.types,
879 : : };
880 : 0 : struct igc_hw *hw = IGC_DEV_PRIVATE_HW(dev);
881 : 0 : struct igc_rss_filter *rss_filter = IGC_DEV_PRIVATE_RSS_FILTER(dev);
882 : : uint32_t i, j;
883 : :
884 : : /* check RSS type is valid */
885 [ # # ]: 0 : if ((rss_conf.rss_hf & IGC_RSS_OFFLOAD_ALL) == 0) {
886 : 0 : PMD_DRV_LOG(ERR,
887 : : "RSS type(0x%" PRIx64 ") error!, only 0x%" PRIx64
888 : : " been supported", rss_conf.rss_hf,
889 : : (uint64_t)IGC_RSS_OFFLOAD_ALL);
890 : 0 : return -EINVAL;
891 : : }
892 : :
893 : : /* check queue count is not zero */
894 [ # # ]: 0 : if (!rss->conf.queue_num) {
895 : 0 : PMD_DRV_LOG(ERR, "Queue number should not be 0!");
896 : 0 : return -EINVAL;
897 : : }
898 : :
899 : : /* check queue id is valid */
900 [ # # ]: 0 : for (i = 0; i < rss->conf.queue_num; i++)
901 [ # # ]: 0 : if (rss->conf.queue[i] >= dev->data->nb_rx_queues) {
902 : 0 : PMD_DRV_LOG(ERR, "Queue id %u is invalid!",
903 : : rss->conf.queue[i]);
904 : 0 : return -EINVAL;
905 : : }
906 : :
907 : : /* only support one filter */
908 [ # # ]: 0 : if (rss_filter->enable) {
909 : 0 : PMD_DRV_LOG(ERR, "Only support one RSS filter!");
910 : 0 : return -ENOTSUP;
911 : : }
912 : 0 : rss_filter->enable = 1;
913 : :
914 : 0 : igc_rss_conf_set(rss_filter, &rss->conf);
915 : :
916 : : /* Fill in redirection table. */
917 [ # # ]: 0 : for (i = 0, j = 0; i < IGC_RSS_RDT_SIZD; i++, j++) {
918 : : union igc_rss_reta_reg reta;
919 : : uint16_t q_idx, reta_idx;
920 : :
921 [ # # ]: 0 : if (j == rss->conf.queue_num)
922 : : j = 0;
923 : 0 : q_idx = rss->conf.queue[j];
924 : 0 : reta_idx = i % sizeof(reta);
925 : 0 : reta.bytes[reta_idx] = q_idx;
926 [ # # ]: 0 : if (reta_idx == sizeof(reta) - 1)
927 : 0 : IGC_WRITE_REG_LE_VALUE(hw,
928 : : IGC_RETA(i / sizeof(reta)), reta.dword);
929 : : }
930 : :
931 [ # # ]: 0 : if (rss_conf.rss_key == NULL)
932 : 0 : rss_conf.rss_key = default_rss_key;
933 : 0 : igc_hw_rss_hash_set(hw, &rss_conf);
934 : 0 : return 0;
935 : : }
936 : :
937 : : void
938 : 0 : igc_clear_rss_filter(struct rte_eth_dev *dev)
939 : : {
940 : 0 : struct igc_rss_filter *rss_filter = IGC_DEV_PRIVATE_RSS_FILTER(dev);
941 : :
942 [ # # ]: 0 : if (!rss_filter->enable)
943 : : return;
944 : :
945 : : /* recover default RSS configuration */
946 : 0 : igc_rss_configure(dev);
947 : :
948 : : /* disable RSS logic and clear filter data */
949 : 0 : igc_rss_disable(dev);
950 : : memset(rss_filter, 0, sizeof(*rss_filter));
951 : : }
952 : :
953 : : static int
954 : 0 : igc_dev_mq_rx_configure(struct rte_eth_dev *dev)
955 : : {
956 [ # # ]: 0 : if (RTE_ETH_DEV_SRIOV(dev).active) {
957 : 0 : PMD_DRV_LOG(ERR, "SRIOV unsupported!");
958 : 0 : return -EINVAL;
959 : : }
960 : :
961 [ # # # ]: 0 : switch (dev->data->dev_conf.rxmode.mq_mode) {
962 : 0 : case RTE_ETH_MQ_RX_RSS:
963 : 0 : igc_rss_configure(dev);
964 : 0 : break;
965 : 0 : case RTE_ETH_MQ_RX_NONE:
966 : : /*
967 : : * configure RSS register for following,
968 : : * then disable the RSS logic
969 : : */
970 : 0 : igc_rss_configure(dev);
971 : 0 : igc_rss_disable(dev);
972 : 0 : break;
973 : 0 : default:
974 : 0 : PMD_DRV_LOG(ERR, "rx mode(%d) not supported!",
975 : : dev->data->dev_conf.rxmode.mq_mode);
976 : 0 : return -EINVAL;
977 : : }
978 : : return 0;
979 : : }
980 : :
981 : : int
982 : 0 : igc_rx_init(struct rte_eth_dev *dev)
983 : : {
984 : : struct igc_rx_queue *rxq;
985 : 0 : struct igc_hw *hw = IGC_DEV_PRIVATE_HW(dev);
986 : 0 : uint64_t offloads = dev->data->dev_conf.rxmode.offloads;
987 : : uint32_t max_rx_pktlen;
988 : : uint32_t rctl;
989 : : uint32_t rxcsum;
990 : : uint16_t buf_size;
991 : : uint16_t rctl_bsize;
992 : : uint16_t i;
993 : : int ret;
994 : :
995 : 0 : dev->rx_pkt_burst = igc_recv_pkts;
996 : :
997 : : /*
998 : : * Make sure receives are disabled while setting
999 : : * up the descriptor ring.
1000 : : */
1001 : 0 : rctl = IGC_READ_REG(hw, IGC_RCTL);
1002 : 0 : IGC_WRITE_REG(hw, IGC_RCTL, rctl & ~IGC_RCTL_EN);
1003 : :
1004 : : /* Configure support of jumbo frames, if any. */
1005 [ # # ]: 0 : if (dev->data->mtu > RTE_ETHER_MTU)
1006 : 0 : rctl |= IGC_RCTL_LPE;
1007 : : else
1008 : 0 : rctl &= ~IGC_RCTL_LPE;
1009 : :
1010 : 0 : max_rx_pktlen = dev->data->mtu + IGC_ETH_OVERHEAD;
1011 : : /*
1012 : : * Set maximum packet length by default, and might be updated
1013 : : * together with enabling/disabling dual VLAN.
1014 : : */
1015 : 0 : IGC_WRITE_REG(hw, IGC_RLPML, max_rx_pktlen);
1016 : :
1017 : : /* Configure and enable each RX queue. */
1018 : : rctl_bsize = 0;
1019 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
1020 : : uint64_t bus_addr;
1021 : : uint32_t rxdctl;
1022 : : uint32_t srrctl;
1023 : :
1024 : 0 : rxq = dev->data->rx_queues[i];
1025 : 0 : rxq->flags = 0;
1026 : :
1027 [ # # ]: 0 : if (offloads & RTE_ETH_RX_OFFLOAD_TIMESTAMP)
1028 : 0 : rxq->offloads |= RTE_ETH_RX_OFFLOAD_TIMESTAMP;
1029 : :
1030 : : /* Allocate buffers for descriptor rings and set up queue */
1031 : 0 : ret = igc_alloc_rx_queue_mbufs(rxq);
1032 [ # # ]: 0 : if (ret)
1033 : 0 : return ret;
1034 : :
1035 : : /*
1036 : : * Reset crc_len in case it was changed after queue setup by a
1037 : : * call to configure
1038 : : */
1039 : 0 : rxq->crc_len = (offloads & RTE_ETH_RX_OFFLOAD_KEEP_CRC) ?
1040 : 0 : RTE_ETHER_CRC_LEN : 0;
1041 : :
1042 : 0 : bus_addr = rxq->rx_ring_phys_addr;
1043 [ # # ]: 0 : IGC_WRITE_REG(hw, IGC_RDLEN(rxq->reg_idx),
1044 : : rxq->nb_rx_desc *
1045 : : sizeof(union igc_adv_rx_desc));
1046 [ # # ]: 0 : IGC_WRITE_REG(hw, IGC_RDBAH(rxq->reg_idx),
1047 : : (uint32_t)(bus_addr >> 32));
1048 [ # # ]: 0 : IGC_WRITE_REG(hw, IGC_RDBAL(rxq->reg_idx),
1049 : : (uint32_t)bus_addr);
1050 : :
1051 : : /* set descriptor configuration */
1052 : : srrctl = IGC_SRRCTL_DESCTYPE_ADV_ONEBUF;
1053 : :
1054 : : srrctl |= (uint32_t)(RTE_PKTMBUF_HEADROOM / 64) <<
1055 : : IGC_SRRCTL_BSIZEHEADER_SHIFT;
1056 : : /*
1057 : : * Configure RX buffer size.
1058 : : */
1059 [ # # ]: 0 : buf_size = (uint16_t)(rte_pktmbuf_data_room_size(rxq->mb_pool) -
1060 : : RTE_PKTMBUF_HEADROOM);
1061 [ # # ]: 0 : if (buf_size >= 1024) {
1062 : : /*
1063 : : * Configure the BSIZEPACKET field of the SRRCTL
1064 : : * register of the queue.
1065 : : * Value is in 1 KB resolution, from 1 KB to 16 KB.
1066 : : * If this field is equal to 0b, then RCTL.BSIZE
1067 : : * determines the RX packet buffer size.
1068 : : */
1069 : :
1070 : 0 : srrctl |= ((buf_size >> IGC_SRRCTL_BSIZEPKT_SHIFT) &
1071 : : IGC_SRRCTL_BSIZEPKT_MASK);
1072 : 0 : buf_size = (uint16_t)((srrctl &
1073 : : IGC_SRRCTL_BSIZEPKT_MASK) <<
1074 : : IGC_SRRCTL_BSIZEPKT_SHIFT);
1075 : :
1076 : : /* It adds dual VLAN length for supporting dual VLAN */
1077 [ # # ]: 0 : if (max_rx_pktlen > buf_size)
1078 : 0 : dev->data->scattered_rx = 1;
1079 : : } else {
1080 : : /*
1081 : : * Use BSIZE field of the device RCTL register.
1082 : : */
1083 [ # # ]: 0 : if (rctl_bsize == 0 || rctl_bsize > buf_size)
1084 : : rctl_bsize = buf_size;
1085 : 0 : dev->data->scattered_rx = 1;
1086 : : }
1087 : :
1088 : : /* Set if packets are dropped when no descriptors available */
1089 [ # # ]: 0 : if (rxq->drop_en)
1090 : 0 : srrctl |= IGC_SRRCTL_DROP_EN;
1091 : :
1092 [ # # ]: 0 : IGC_WRITE_REG(hw, IGC_SRRCTL(rxq->reg_idx), srrctl);
1093 : :
1094 : : /* Enable this RX queue. */
1095 : : rxdctl = IGC_RXDCTL_QUEUE_ENABLE;
1096 : 0 : rxdctl |= ((uint32_t)rxq->pthresh << IGC_RXDCTL_PTHRESH_SHIFT) &
1097 : : IGC_RXDCTL_PTHRESH_MSK;
1098 : 0 : rxdctl |= ((uint32_t)rxq->hthresh << IGC_RXDCTL_HTHRESH_SHIFT) &
1099 : : IGC_RXDCTL_HTHRESH_MSK;
1100 : 0 : rxdctl |= ((uint32_t)rxq->wthresh << IGC_RXDCTL_WTHRESH_SHIFT) &
1101 : : IGC_RXDCTL_WTHRESH_MSK;
1102 [ # # ]: 0 : IGC_WRITE_REG(hw, IGC_RXDCTL(rxq->reg_idx), rxdctl);
1103 : : }
1104 : :
1105 [ # # ]: 0 : if (offloads & RTE_ETH_RX_OFFLOAD_SCATTER)
1106 : 0 : dev->data->scattered_rx = 1;
1107 : :
1108 [ # # ]: 0 : if (dev->data->scattered_rx) {
1109 : 0 : PMD_DRV_LOG(DEBUG, "forcing scatter mode");
1110 : 0 : dev->rx_pkt_burst = igc_recv_scattered_pkts;
1111 : : }
1112 : : /*
1113 : : * Setup BSIZE field of RCTL register, if needed.
1114 : : * Buffer sizes >= 1024 are not [supposed to be] setup in the RCTL
1115 : : * register, since the code above configures the SRRCTL register of
1116 : : * the RX queue in such a case.
1117 : : * All configurable sizes are:
1118 : : * 16384: rctl |= (IGC_RCTL_SZ_16384 | IGC_RCTL_BSEX);
1119 : : * 8192: rctl |= (IGC_RCTL_SZ_8192 | IGC_RCTL_BSEX);
1120 : : * 4096: rctl |= (IGC_RCTL_SZ_4096 | IGC_RCTL_BSEX);
1121 : : * 2048: rctl |= IGC_RCTL_SZ_2048;
1122 : : * 1024: rctl |= IGC_RCTL_SZ_1024;
1123 : : * 512: rctl |= IGC_RCTL_SZ_512;
1124 : : * 256: rctl |= IGC_RCTL_SZ_256;
1125 : : */
1126 [ # # ]: 0 : if (rctl_bsize > 0) {
1127 [ # # ]: 0 : if (rctl_bsize >= 512) /* 512 <= buf_size < 1024 - use 512 */
1128 : 0 : rctl |= IGC_RCTL_SZ_512;
1129 : : else /* 256 <= buf_size < 512 - use 256 */
1130 : 0 : rctl |= IGC_RCTL_SZ_256;
1131 : : }
1132 : :
1133 : : /*
1134 : : * Configure RSS if device configured with multiple RX queues.
1135 : : */
1136 : 0 : igc_dev_mq_rx_configure(dev);
1137 : :
1138 : : /* Update the rctl since igc_dev_mq_rx_configure may change its value */
1139 : 0 : rctl |= IGC_READ_REG(hw, IGC_RCTL);
1140 : :
1141 : : /*
1142 : : * Setup the Checksum Register.
1143 : : * Receive Full-Packet Checksum Offload is mutually exclusive with RSS.
1144 : : */
1145 : 0 : rxcsum = IGC_READ_REG(hw, IGC_RXCSUM);
1146 : : rxcsum |= IGC_RXCSUM_PCSD;
1147 : :
1148 : : /* Enable both L3/L4 rx checksum offload */
1149 [ # # ]: 0 : if (offloads & RTE_ETH_RX_OFFLOAD_IPV4_CKSUM)
1150 : 0 : rxcsum |= IGC_RXCSUM_IPOFL;
1151 : : else
1152 : 0 : rxcsum &= ~IGC_RXCSUM_IPOFL;
1153 : :
1154 [ # # ]: 0 : if (offloads &
1155 : : (RTE_ETH_RX_OFFLOAD_TCP_CKSUM | RTE_ETH_RX_OFFLOAD_UDP_CKSUM)) {
1156 : 0 : rxcsum |= IGC_RXCSUM_TUOFL;
1157 : 0 : offloads |= RTE_ETH_RX_OFFLOAD_SCTP_CKSUM;
1158 : : } else {
1159 : 0 : rxcsum &= ~IGC_RXCSUM_TUOFL;
1160 : : }
1161 : :
1162 [ # # ]: 0 : if (offloads & RTE_ETH_RX_OFFLOAD_SCTP_CKSUM)
1163 : 0 : rxcsum |= IGC_RXCSUM_CRCOFL;
1164 : : else
1165 : 0 : rxcsum &= ~IGC_RXCSUM_CRCOFL;
1166 : :
1167 : 0 : IGC_WRITE_REG(hw, IGC_RXCSUM, rxcsum);
1168 : :
1169 : : /* Setup the Receive Control Register. */
1170 [ # # ]: 0 : if (offloads & RTE_ETH_RX_OFFLOAD_KEEP_CRC)
1171 : 0 : rctl &= ~IGC_RCTL_SECRC; /* Do not Strip Ethernet CRC. */
1172 : : else
1173 : 0 : rctl |= IGC_RCTL_SECRC; /* Strip Ethernet CRC. */
1174 : :
1175 : : rctl &= ~IGC_RCTL_MO_MSK;
1176 : 0 : rctl &= ~IGC_RCTL_LBM_MSK;
1177 : 0 : rctl |= IGC_RCTL_EN | IGC_RCTL_BAM | IGC_RCTL_LBM_NO |
1178 : : IGC_RCTL_DPF |
1179 : 0 : (hw->mac.mc_filter_type << IGC_RCTL_MO_SHIFT);
1180 : :
1181 [ # # ]: 0 : if (dev->data->dev_conf.lpbk_mode == 1)
1182 : 0 : rctl |= IGC_RCTL_LBM_MAC;
1183 : :
1184 : : rctl &= ~(IGC_RCTL_HSEL_MSK | IGC_RCTL_CFIEN | IGC_RCTL_CFI |
1185 : : IGC_RCTL_PSP | IGC_RCTL_PMCF);
1186 : :
1187 : : /* Make sure VLAN Filters are off. */
1188 : : rctl &= ~IGC_RCTL_VFE;
1189 : : /* Don't store bad packets. */
1190 : 0 : rctl &= ~IGC_RCTL_SBP;
1191 : :
1192 : : /* Enable Receives. */
1193 : 0 : IGC_WRITE_REG(hw, IGC_RCTL, rctl);
1194 : :
1195 : : /*
1196 : : * Setup the HW Rx Head and Tail Descriptor Pointers.
1197 : : * This needs to be done after enable.
1198 : : */
1199 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
1200 : : uint32_t dvmolr;
1201 : :
1202 : 0 : rxq = dev->data->rx_queues[i];
1203 [ # # ]: 0 : IGC_WRITE_REG(hw, IGC_RDH(rxq->reg_idx), 0);
1204 [ # # ]: 0 : IGC_WRITE_REG(hw, IGC_RDT(rxq->reg_idx), rxq->nb_rx_desc - 1);
1205 : :
1206 : 0 : dvmolr = IGC_READ_REG(hw, IGC_DVMOLR(rxq->reg_idx));
1207 [ # # ]: 0 : if (rxq->offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP)
1208 : 0 : dvmolr |= IGC_DVMOLR_STRVLAN;
1209 : : else
1210 : 0 : dvmolr &= ~IGC_DVMOLR_STRVLAN;
1211 : :
1212 [ # # ]: 0 : if (offloads & RTE_ETH_RX_OFFLOAD_KEEP_CRC)
1213 : 0 : dvmolr &= ~IGC_DVMOLR_STRCRC;
1214 : : else
1215 : 0 : dvmolr |= IGC_DVMOLR_STRCRC;
1216 : :
1217 : 0 : IGC_WRITE_REG(hw, IGC_DVMOLR(rxq->reg_idx), dvmolr);
1218 : 0 : dev->data->rx_queue_state[i] = RTE_ETH_QUEUE_STATE_STARTED;
1219 : : }
1220 : :
1221 : : return 0;
1222 : : }
1223 : :
1224 : : static void
1225 : : igc_reset_rx_queue(struct igc_rx_queue *rxq)
1226 : : {
1227 : : static const union igc_adv_rx_desc zeroed_desc = { {0} };
1228 : : unsigned int i;
1229 : :
1230 : : /* Zero out HW ring memory */
1231 [ # # # # ]: 0 : for (i = 0; i < rxq->nb_rx_desc; i++)
1232 : 0 : rxq->rx_ring[i] = zeroed_desc;
1233 : :
1234 : 0 : rxq->rx_tail = 0;
1235 : 0 : rxq->pkt_first_seg = NULL;
1236 : 0 : rxq->pkt_last_seg = NULL;
1237 : : }
1238 : :
1239 : : int
1240 : 0 : eth_igc_rx_queue_setup(struct rte_eth_dev *dev,
1241 : : uint16_t queue_idx,
1242 : : uint16_t nb_desc,
1243 : : unsigned int socket_id,
1244 : : const struct rte_eth_rxconf *rx_conf,
1245 : : struct rte_mempool *mp)
1246 : : {
1247 : 0 : struct igc_hw *hw = IGC_DEV_PRIVATE_HW(dev);
1248 : : const struct rte_memzone *rz;
1249 : : struct igc_rx_queue *rxq;
1250 : : unsigned int size;
1251 : :
1252 : : /*
1253 : : * Validate number of receive descriptors.
1254 : : * It must not exceed hardware maximum, and must be multiple
1255 : : * of IGC_RX_DESCRIPTOR_MULTIPLE.
1256 : : */
1257 [ # # ]: 0 : if (nb_desc % IGC_RX_DESCRIPTOR_MULTIPLE != 0 ||
1258 [ # # ]: 0 : nb_desc > IGC_MAX_RXD || nb_desc < IGC_MIN_RXD) {
1259 : 0 : PMD_DRV_LOG(ERR,
1260 : : "RX descriptor must be multiple of %u(cur: %u) and between %u and %u",
1261 : : IGC_RX_DESCRIPTOR_MULTIPLE, nb_desc,
1262 : : IGC_MIN_RXD, IGC_MAX_RXD);
1263 : 0 : return -EINVAL;
1264 : : }
1265 : :
1266 : : /* Free memory prior to re-allocation if needed */
1267 [ # # ]: 0 : if (dev->data->rx_queues[queue_idx] != NULL) {
1268 : 0 : igc_rx_queue_release(dev->data->rx_queues[queue_idx]);
1269 : 0 : dev->data->rx_queues[queue_idx] = NULL;
1270 : : }
1271 : :
1272 : : /* First allocate the RX queue data structure. */
1273 : 0 : rxq = rte_zmalloc("ethdev RX queue", sizeof(struct igc_rx_queue),
1274 : : RTE_CACHE_LINE_SIZE);
1275 [ # # ]: 0 : if (rxq == NULL)
1276 : : return -ENOMEM;
1277 : 0 : rxq->offloads = rx_conf->offloads;
1278 : 0 : rxq->mb_pool = mp;
1279 : 0 : rxq->nb_rx_desc = nb_desc;
1280 : 0 : rxq->pthresh = rx_conf->rx_thresh.pthresh;
1281 : 0 : rxq->hthresh = rx_conf->rx_thresh.hthresh;
1282 : 0 : rxq->wthresh = rx_conf->rx_thresh.wthresh;
1283 : 0 : rxq->drop_en = rx_conf->rx_drop_en;
1284 : 0 : rxq->rx_free_thresh = rx_conf->rx_free_thresh;
1285 : 0 : rxq->queue_id = queue_idx;
1286 : 0 : rxq->reg_idx = queue_idx;
1287 : 0 : rxq->port_id = dev->data->port_id;
1288 : :
1289 : : /*
1290 : : * Allocate RX ring hardware descriptors. A memzone large enough to
1291 : : * handle the maximum ring size is allocated in order to allow for
1292 : : * resizing in later calls to the queue setup function.
1293 : : */
1294 : : size = sizeof(union igc_adv_rx_desc) * IGC_MAX_RXD;
1295 : 0 : rz = rte_eth_dma_zone_reserve(dev, "rx_ring", queue_idx, size,
1296 : : IGC_ALIGN, socket_id);
1297 [ # # ]: 0 : if (rz == NULL) {
1298 : 0 : igc_rx_queue_release(rxq);
1299 : 0 : return -ENOMEM;
1300 : : }
1301 [ # # ]: 0 : rxq->rdt_reg_addr = IGC_PCI_REG_ADDR(hw, IGC_RDT(rxq->reg_idx));
1302 [ # # ]: 0 : rxq->rdh_reg_addr = IGC_PCI_REG_ADDR(hw, IGC_RDH(rxq->reg_idx));
1303 : 0 : rxq->rx_ring_phys_addr = rz->iova;
1304 : 0 : rxq->rx_ring = (union igc_adv_rx_desc *)rz->addr;
1305 : :
1306 : : /* Allocate software ring. */
1307 : 0 : rxq->sw_ring = rte_zmalloc("rxq->sw_ring",
1308 : : sizeof(struct igc_rx_entry) * nb_desc,
1309 : : RTE_CACHE_LINE_SIZE);
1310 [ # # ]: 0 : if (rxq->sw_ring == NULL) {
1311 : 0 : igc_rx_queue_release(rxq);
1312 : 0 : return -ENOMEM;
1313 : : }
1314 : :
1315 : 0 : PMD_DRV_LOG(DEBUG, "sw_ring=%p hw_ring=%p dma_addr=0x%" PRIx64,
1316 : : rxq->sw_ring, rxq->rx_ring, rxq->rx_ring_phys_addr);
1317 : :
1318 : 0 : dev->data->rx_queues[queue_idx] = rxq;
1319 : : igc_reset_rx_queue(rxq);
1320 : :
1321 : 0 : return 0;
1322 : : }
1323 : :
1324 : : /* prepare packets for transmit */
1325 : : uint16_t
1326 : 0 : eth_igc_prep_pkts(__rte_unused void *tx_queue, struct rte_mbuf **tx_pkts,
1327 : : uint16_t nb_pkts)
1328 : : {
1329 : : int i, ret;
1330 : : struct rte_mbuf *m;
1331 : :
1332 [ # # ]: 0 : for (i = 0; i < nb_pkts; i++) {
1333 : 0 : m = tx_pkts[i];
1334 : :
1335 : : /* Check some limitations for TSO in hardware */
1336 [ # # ]: 0 : if (m->ol_flags & IGC_TX_OFFLOAD_SEG)
1337 [ # # ]: 0 : if (m->tso_segsz > IGC_TSO_MAX_MSS ||
1338 [ # # ]: 0 : m->l2_len + m->l3_len + m->l4_len >
1339 : : IGC_TSO_MAX_HDRLEN) {
1340 : 0 : rte_errno = EINVAL;
1341 : 0 : return i;
1342 : : }
1343 : :
1344 [ # # ]: 0 : if (m->ol_flags & IGC_TX_OFFLOAD_NOTSUP_MASK) {
1345 : 0 : rte_errno = ENOTSUP;
1346 : 0 : return i;
1347 : : }
1348 : :
1349 : : #ifdef RTE_ETHDEV_DEBUG_TX
1350 : : ret = rte_validate_tx_offload(m);
1351 : : if (ret != 0) {
1352 : : rte_errno = -ret;
1353 : : return i;
1354 : : }
1355 : : #endif
1356 : : ret = rte_net_intel_cksum_prepare(m);
1357 [ # # ]: 0 : if (ret != 0) {
1358 : 0 : rte_errno = -ret;
1359 : 0 : return i;
1360 : : }
1361 : : }
1362 : :
1363 : 0 : return i;
1364 : : }
1365 : :
1366 : : /*
1367 : : *There're some limitations in hardware for TCP segmentation offload. We
1368 : : *should check whether the parameters are valid.
1369 : : */
1370 : : static inline uint64_t
1371 : : check_tso_para(uint64_t ol_req, union igc_tx_offload ol_para)
1372 : : {
1373 : 0 : if (!(ol_req & IGC_TX_OFFLOAD_SEG))
1374 : : return ol_req;
1375 [ # # ]: 0 : if (ol_para.tso_segsz > IGC_TSO_MAX_MSS || ol_para.l2_len +
1376 [ # # ]: 0 : ol_para.l3_len + ol_para.l4_len > IGC_TSO_MAX_HDRLEN) {
1377 : 0 : ol_req &= ~IGC_TX_OFFLOAD_SEG;
1378 : 0 : ol_req |= RTE_MBUF_F_TX_TCP_CKSUM;
1379 : : }
1380 : : return ol_req;
1381 : : }
1382 : :
1383 : : /*
1384 : : * Check which hardware context can be used. Use the existing match
1385 : : * or create a new context descriptor.
1386 : : */
1387 : : static inline uint32_t
1388 : 0 : what_advctx_update(struct igc_tx_queue *txq, uint64_t flags,
1389 : : union igc_tx_offload tx_offload)
1390 : : {
1391 : 0 : uint32_t curr = txq->ctx_curr;
1392 : :
1393 : : /* If match with the current context */
1394 [ # # # # ]: 0 : if (likely(txq->ctx_cache[curr].flags == flags &&
1395 : : txq->ctx_cache[curr].tx_offload.data ==
1396 : : (txq->ctx_cache[curr].tx_offload_mask.data &
1397 : : tx_offload.data))) {
1398 : : return curr;
1399 : : }
1400 : :
1401 : : /* Total two context, if match with the second context */
1402 : 0 : curr ^= 1;
1403 [ # # # # ]: 0 : if (likely(txq->ctx_cache[curr].flags == flags &&
1404 : : txq->ctx_cache[curr].tx_offload.data ==
1405 : : (txq->ctx_cache[curr].tx_offload_mask.data &
1406 : : tx_offload.data))) {
1407 : 0 : txq->ctx_curr = curr;
1408 : 0 : return curr;
1409 : : }
1410 : :
1411 : : /* Mismatch, create new one */
1412 : : return IGC_CTX_NUM;
1413 : : }
1414 : :
1415 : : static uint32_t igc_tx_launchtime(uint64_t txtime, uint16_t port_id)
1416 : : {
1417 : : struct rte_eth_dev *dev = &rte_eth_devices[port_id];
1418 : 0 : struct igc_adapter *adapter = IGC_DEV_PRIVATE(dev);
1419 : 0 : uint64_t base_time = adapter->base_time;
1420 : 0 : uint64_t cycle_time = adapter->cycle_time;
1421 : : uint32_t launchtime;
1422 : :
1423 : 0 : launchtime = (txtime - base_time) % cycle_time;
1424 : :
1425 : : return rte_cpu_to_le_32(launchtime);
1426 : : }
1427 : :
1428 : : /*
1429 : : * This is a separate function, looking for optimization opportunity here
1430 : : * Rework required to go with the pre-defined values.
1431 : : */
1432 : : static inline void
1433 : 0 : igc_set_xmit_ctx(struct igc_tx_queue *txq,
1434 : : volatile struct igc_adv_tx_context_desc *ctx_txd,
1435 : : uint64_t ol_flags, union igc_tx_offload tx_offload,
1436 : : uint64_t txtime)
1437 : : {
1438 : : uint32_t type_tucmd_mlhl;
1439 : : uint32_t mss_l4len_idx;
1440 : : uint32_t ctx_curr;
1441 : : uint32_t vlan_macip_lens;
1442 : : union igc_tx_offload tx_offload_mask;
1443 : :
1444 : : /* Use the previous context */
1445 : 0 : txq->ctx_curr ^= 1;
1446 : 0 : ctx_curr = txq->ctx_curr;
1447 : :
1448 : 0 : tx_offload_mask.data = 0;
1449 : : type_tucmd_mlhl = 0;
1450 : :
1451 : : /* Specify which HW CTX to upload. */
1452 : 0 : mss_l4len_idx = (ctx_curr << IGC_ADVTXD_IDX_SHIFT);
1453 : :
1454 [ # # ]: 0 : if (ol_flags & RTE_MBUF_F_TX_VLAN)
1455 : 0 : tx_offload_mask.vlan_tci = 0xffff;
1456 : :
1457 : : /* check if TCP segmentation required for this packet */
1458 [ # # ]: 0 : if (ol_flags & IGC_TX_OFFLOAD_SEG) {
1459 : : /* implies IP cksum in IPv4 */
1460 [ # # ]: 0 : if (ol_flags & RTE_MBUF_F_TX_IP_CKSUM)
1461 : : type_tucmd_mlhl = IGC_ADVTXD_TUCMD_IPV4 |
1462 : : IGC_ADVTXD_DTYP_CTXT | IGC_ADVTXD_DCMD_DEXT;
1463 : : else
1464 : : type_tucmd_mlhl = IGC_ADVTXD_TUCMD_IPV6 |
1465 : : IGC_ADVTXD_DTYP_CTXT | IGC_ADVTXD_DCMD_DEXT;
1466 : :
1467 [ # # ]: 0 : if (ol_flags & RTE_MBUF_F_TX_TCP_SEG)
1468 : 0 : type_tucmd_mlhl |= IGC_ADVTXD_TUCMD_L4T_TCP;
1469 : : else
1470 : : type_tucmd_mlhl |= IGC_ADVTXD_TUCMD_L4T_UDP;
1471 : :
1472 : 0 : tx_offload_mask.data |= TX_TSO_CMP_MASK;
1473 : 0 : mss_l4len_idx |= (uint32_t)tx_offload.tso_segsz <<
1474 : : IGC_ADVTXD_MSS_SHIFT;
1475 : 0 : mss_l4len_idx |= (uint32_t)tx_offload.l4_len <<
1476 : : IGC_ADVTXD_L4LEN_SHIFT;
1477 : : } else { /* no TSO, check if hardware checksum is needed */
1478 [ # # ]: 0 : if (ol_flags & (RTE_MBUF_F_TX_IP_CKSUM | RTE_MBUF_F_TX_L4_MASK))
1479 : 0 : tx_offload_mask.data |= TX_MACIP_LEN_CMP_MASK;
1480 : :
1481 [ # # ]: 0 : if (ol_flags & RTE_MBUF_F_TX_IP_CKSUM)
1482 : : type_tucmd_mlhl = IGC_ADVTXD_TUCMD_IPV4;
1483 : :
1484 [ # # # # ]: 0 : switch (ol_flags & RTE_MBUF_F_TX_L4_MASK) {
1485 : 0 : case RTE_MBUF_F_TX_TCP_CKSUM:
1486 : 0 : type_tucmd_mlhl |= IGC_ADVTXD_TUCMD_L4T_TCP |
1487 : : IGC_ADVTXD_DTYP_CTXT | IGC_ADVTXD_DCMD_DEXT;
1488 : 0 : mss_l4len_idx |= (uint32_t)sizeof(struct rte_tcp_hdr)
1489 : : << IGC_ADVTXD_L4LEN_SHIFT;
1490 : 0 : break;
1491 : 0 : case RTE_MBUF_F_TX_UDP_CKSUM:
1492 : 0 : type_tucmd_mlhl |= IGC_ADVTXD_TUCMD_L4T_UDP |
1493 : : IGC_ADVTXD_DTYP_CTXT | IGC_ADVTXD_DCMD_DEXT;
1494 : 0 : mss_l4len_idx |= (uint32_t)sizeof(struct rte_udp_hdr)
1495 : : << IGC_ADVTXD_L4LEN_SHIFT;
1496 : 0 : break;
1497 : 0 : case RTE_MBUF_F_TX_SCTP_CKSUM:
1498 : 0 : type_tucmd_mlhl |= IGC_ADVTXD_TUCMD_L4T_SCTP |
1499 : : IGC_ADVTXD_DTYP_CTXT | IGC_ADVTXD_DCMD_DEXT;
1500 : 0 : mss_l4len_idx |= (uint32_t)sizeof(struct rte_sctp_hdr)
1501 : : << IGC_ADVTXD_L4LEN_SHIFT;
1502 : 0 : break;
1503 : 0 : default:
1504 : 0 : type_tucmd_mlhl |= IGC_ADVTXD_TUCMD_L4T_RSV |
1505 : : IGC_ADVTXD_DTYP_CTXT | IGC_ADVTXD_DCMD_DEXT;
1506 : 0 : break;
1507 : : }
1508 : : }
1509 : :
1510 [ # # ]: 0 : if (!txtime) {
1511 : 0 : txq->ctx_cache[ctx_curr].flags = ol_flags;
1512 : 0 : txq->ctx_cache[ctx_curr].tx_offload.data =
1513 : 0 : tx_offload_mask.data & tx_offload.data;
1514 : 0 : txq->ctx_cache[ctx_curr].tx_offload_mask = tx_offload_mask;
1515 : : }
1516 : :
1517 : 0 : ctx_txd->type_tucmd_mlhl = rte_cpu_to_le_32(type_tucmd_mlhl);
1518 : 0 : vlan_macip_lens = (uint32_t)tx_offload.data;
1519 : 0 : ctx_txd->vlan_macip_lens = rte_cpu_to_le_32(vlan_macip_lens);
1520 : 0 : ctx_txd->mss_l4len_idx = rte_cpu_to_le_32(mss_l4len_idx);
1521 : :
1522 [ # # ]: 0 : if (txtime)
1523 : 0 : ctx_txd->u.launch_time = igc_tx_launchtime(txtime,
1524 : 0 : txq->port_id);
1525 : : else
1526 : 0 : ctx_txd->u.launch_time = 0;
1527 : 0 : }
1528 : :
1529 : : static inline uint32_t
1530 : : tx_desc_vlan_flags_to_cmdtype(uint64_t ol_flags)
1531 : : {
1532 : : uint32_t cmdtype;
1533 : : static uint32_t vlan_cmd[2] = {0, IGC_ADVTXD_DCMD_VLE};
1534 : : static uint32_t tso_cmd[2] = {0, IGC_ADVTXD_DCMD_TSE};
1535 : 0 : cmdtype = vlan_cmd[(ol_flags & RTE_MBUF_F_TX_VLAN) != 0];
1536 : 0 : cmdtype |= tso_cmd[(ol_flags & IGC_TX_OFFLOAD_SEG) != 0];
1537 : : return cmdtype;
1538 : : }
1539 : :
1540 : : static inline uint32_t
1541 : : tx_desc_cksum_flags_to_olinfo(uint64_t ol_flags)
1542 : : {
1543 : : static const uint32_t l4_olinfo[2] = {0, IGC_ADVTXD_POPTS_TXSM};
1544 : : static const uint32_t l3_olinfo[2] = {0, IGC_ADVTXD_POPTS_IXSM};
1545 : : uint32_t tmp;
1546 : :
1547 : 0 : tmp = l4_olinfo[(ol_flags & RTE_MBUF_F_TX_L4_MASK) != RTE_MBUF_F_TX_L4_NO_CKSUM];
1548 : 0 : tmp |= l3_olinfo[(ol_flags & RTE_MBUF_F_TX_IP_CKSUM) != 0];
1549 : 0 : tmp |= l4_olinfo[(ol_flags & IGC_TX_OFFLOAD_SEG) != 0];
1550 : : return tmp;
1551 : : }
1552 : :
1553 : : uint16_t
1554 : 0 : igc_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
1555 : : {
1556 : : struct igc_tx_queue * const txq = tx_queue;
1557 : 0 : struct igc_tx_entry * const sw_ring = txq->sw_ring;
1558 : : struct igc_tx_entry *txe, *txn;
1559 : 0 : volatile union igc_adv_tx_desc * const txr = txq->tx_ring;
1560 : : volatile union igc_adv_tx_desc *txd;
1561 : : struct rte_mbuf *tx_pkt;
1562 : : struct rte_mbuf *m_seg;
1563 : : uint64_t buf_dma_addr;
1564 : : uint32_t olinfo_status;
1565 : : uint32_t cmd_type_len;
1566 : : uint32_t pkt_len;
1567 : : uint16_t slen;
1568 : : uint64_t ol_flags;
1569 : : uint16_t tx_end;
1570 : : uint16_t tx_id;
1571 : : uint16_t tx_last;
1572 : : uint16_t nb_tx;
1573 : : uint64_t tx_ol_req;
1574 : : uint32_t new_ctx = 0;
1575 : 0 : union igc_tx_offload tx_offload = {0};
1576 : : uint64_t ts;
1577 : :
1578 : 0 : tx_id = txq->tx_tail;
1579 : 0 : txe = &sw_ring[tx_id];
1580 : :
1581 [ # # ]: 0 : for (nb_tx = 0; nb_tx < nb_pkts; nb_tx++) {
1582 : 0 : tx_pkt = *tx_pkts++;
1583 : 0 : pkt_len = tx_pkt->pkt_len;
1584 : :
1585 [ # # ]: 0 : RTE_MBUF_PREFETCH_TO_FREE(txe->mbuf);
1586 : :
1587 : : /*
1588 : : * The number of descriptors that must be allocated for a
1589 : : * packet is the number of segments of that packet, plus 1
1590 : : * Context Descriptor for the VLAN Tag Identifier, if any.
1591 : : * Determine the last TX descriptor to allocate in the TX ring
1592 : : * for the packet, starting from the current position (tx_id)
1593 : : * in the ring.
1594 : : */
1595 : 0 : tx_last = (uint16_t)(tx_id + tx_pkt->nb_segs - 1);
1596 : :
1597 : 0 : ol_flags = tx_pkt->ol_flags;
1598 : 0 : tx_ol_req = ol_flags & IGC_TX_OFFLOAD_MASK;
1599 : :
1600 : : /* If a Context Descriptor need be built . */
1601 [ # # ]: 0 : if (tx_ol_req) {
1602 : 0 : tx_offload.l2_len = tx_pkt->l2_len;
1603 : 0 : tx_offload.l3_len = tx_pkt->l3_len;
1604 : 0 : tx_offload.l4_len = tx_pkt->l4_len;
1605 : 0 : tx_offload.vlan_tci = tx_pkt->vlan_tci;
1606 [ # # ]: 0 : tx_offload.tso_segsz = tx_pkt->tso_segsz;
1607 : : tx_ol_req = check_tso_para(tx_ol_req, tx_offload);
1608 : :
1609 : 0 : new_ctx = what_advctx_update(txq, tx_ol_req,
1610 : : tx_offload);
1611 : : /* Only allocate context descriptor if required*/
1612 : 0 : new_ctx = (new_ctx >= IGC_CTX_NUM);
1613 : 0 : tx_last = (uint16_t)(tx_last + new_ctx);
1614 : : }
1615 [ # # ]: 0 : if (tx_last >= txq->nb_tx_desc)
1616 : 0 : tx_last = (uint16_t)(tx_last - txq->nb_tx_desc);
1617 : :
1618 : : PMD_TX_LOG(DEBUG,
1619 : : "port_id=%u queue_id=%u pktlen=%u tx_first=%u tx_last=%u",
1620 : : txq->port_id, txq->queue_id, pkt_len, tx_id, tx_last);
1621 : :
1622 : : /*
1623 : : * Check if there are enough free descriptors in the TX ring
1624 : : * to transmit the next packet.
1625 : : * This operation is based on the two following rules:
1626 : : *
1627 : : * 1- Only check that the last needed TX descriptor can be
1628 : : * allocated (by construction, if that descriptor is free,
1629 : : * all intermediate ones are also free).
1630 : : *
1631 : : * For this purpose, the index of the last TX descriptor
1632 : : * used for a packet (the "last descriptor" of a packet)
1633 : : * is recorded in the TX entries (the last one included)
1634 : : * that are associated with all TX descriptors allocated
1635 : : * for that packet.
1636 : : *
1637 : : * 2- Avoid to allocate the last free TX descriptor of the
1638 : : * ring, in order to never set the TDT register with the
1639 : : * same value stored in parallel by the NIC in the TDH
1640 : : * register, which makes the TX engine of the NIC enter
1641 : : * in a deadlock situation.
1642 : : *
1643 : : * By extension, avoid to allocate a free descriptor that
1644 : : * belongs to the last set of free descriptors allocated
1645 : : * to the same packet previously transmitted.
1646 : : */
1647 : :
1648 : : /*
1649 : : * The "last descriptor" of the previously sent packet, if any,
1650 : : * which used the last descriptor to allocate.
1651 : : */
1652 : 0 : tx_end = sw_ring[tx_last].last_id;
1653 : :
1654 : : /*
1655 : : * The next descriptor following that "last descriptor" in the
1656 : : * ring.
1657 : : */
1658 : 0 : tx_end = sw_ring[tx_end].next_id;
1659 : :
1660 : : /*
1661 : : * The "last descriptor" associated with that next descriptor.
1662 : : */
1663 : 0 : tx_end = sw_ring[tx_end].last_id;
1664 : :
1665 : : /*
1666 : : * Check that this descriptor is free.
1667 : : */
1668 [ # # ]: 0 : if (!(txr[tx_end].wb.status & IGC_TXD_STAT_DD)) {
1669 [ # # ]: 0 : if (nb_tx == 0)
1670 : : return 0;
1671 : 0 : goto end_of_tx;
1672 : : }
1673 : :
1674 : : /*
1675 : : * Set common flags of all TX Data Descriptors.
1676 : : *
1677 : : * The following bits must be set in all Data Descriptors:
1678 : : * - IGC_ADVTXD_DTYP_DATA
1679 : : * - IGC_ADVTXD_DCMD_DEXT
1680 : : *
1681 : : * The following bits must be set in the first Data Descriptor
1682 : : * and are ignored in the other ones:
1683 : : * - IGC_ADVTXD_DCMD_IFCS
1684 : : * - IGC_ADVTXD_MAC_1588
1685 : : * - IGC_ADVTXD_DCMD_VLE
1686 : : *
1687 : : * The following bits must only be set in the last Data
1688 : : * Descriptor:
1689 : : * - IGC_TXD_CMD_EOP
1690 : : *
1691 : : * The following bits can be set in any Data Descriptor, but
1692 : : * are only set in the last Data Descriptor:
1693 : : * - IGC_TXD_CMD_RS
1694 : : */
1695 : 0 : cmd_type_len = txq->txd_type |
1696 : : IGC_ADVTXD_DCMD_IFCS | IGC_ADVTXD_DCMD_DEXT;
1697 [ # # ]: 0 : if (tx_ol_req & IGC_TX_OFFLOAD_SEG)
1698 : 0 : pkt_len -= (tx_pkt->l2_len + tx_pkt->l3_len +
1699 : 0 : tx_pkt->l4_len);
1700 : 0 : olinfo_status = (pkt_len << IGC_ADVTXD_PAYLEN_SHIFT);
1701 : :
1702 : : /*
1703 : : * Timer 0 should be used to for packet timestamping,
1704 : : * sample the packet timestamp to reg 0
1705 : : */
1706 [ # # ]: 0 : if (ol_flags & RTE_MBUF_F_TX_IEEE1588_TMST)
1707 : 0 : cmd_type_len |= IGC_ADVTXD_MAC_TSTAMP;
1708 : :
1709 [ # # ]: 0 : if (tx_ol_req) {
1710 : : /* Setup TX Advanced context descriptor if required */
1711 [ # # ]: 0 : if (new_ctx) {
1712 : : volatile struct igc_adv_tx_context_desc *
1713 : 0 : ctx_txd = (volatile struct
1714 : 0 : igc_adv_tx_context_desc *)&txr[tx_id];
1715 : :
1716 : 0 : txn = &sw_ring[txe->next_id];
1717 [ # # ]: 0 : RTE_MBUF_PREFETCH_TO_FREE(txn->mbuf);
1718 : :
1719 [ # # ]: 0 : if (txe->mbuf != NULL) {
1720 : : rte_pktmbuf_free_seg(txe->mbuf);
1721 : 0 : txe->mbuf = NULL;
1722 : : }
1723 : :
1724 [ # # ]: 0 : if (igc_tx_timestamp_dynflag > 0) {
1725 : 0 : ts = *RTE_MBUF_DYNFIELD(tx_pkt,
1726 : : igc_tx_timestamp_dynfield_offset,
1727 : : uint64_t *);
1728 : 0 : igc_set_xmit_ctx(txq, ctx_txd,
1729 : : tx_ol_req, tx_offload, ts);
1730 : : } else {
1731 : 0 : igc_set_xmit_ctx(txq, ctx_txd,
1732 : : tx_ol_req, tx_offload, 0);
1733 : : }
1734 : :
1735 : 0 : txe->last_id = tx_last;
1736 : 0 : tx_id = txe->next_id;
1737 : : txe = txn;
1738 : : }
1739 : :
1740 : : /* Setup the TX Advanced Data Descriptor */
1741 : 0 : cmd_type_len |=
1742 : : tx_desc_vlan_flags_to_cmdtype(tx_ol_req);
1743 : 0 : olinfo_status |=
1744 : : tx_desc_cksum_flags_to_olinfo(tx_ol_req);
1745 : 0 : olinfo_status |= (uint32_t)txq->ctx_curr <<
1746 : : IGC_ADVTXD_IDX_SHIFT;
1747 : : }
1748 : :
1749 : : m_seg = tx_pkt;
1750 : : do {
1751 : 0 : txn = &sw_ring[txe->next_id];
1752 [ # # ]: 0 : RTE_MBUF_PREFETCH_TO_FREE(txn->mbuf);
1753 : :
1754 : 0 : txd = &txr[tx_id];
1755 : :
1756 [ # # ]: 0 : if (txe->mbuf != NULL)
1757 : : rte_pktmbuf_free_seg(txe->mbuf);
1758 : 0 : txe->mbuf = m_seg;
1759 : :
1760 : : /* Set up transmit descriptor */
1761 [ # # ]: 0 : slen = (uint16_t)m_seg->data_len;
1762 : : buf_dma_addr = rte_mbuf_data_iova(m_seg);
1763 : 0 : txd->read.buffer_addr =
1764 : : rte_cpu_to_le_64(buf_dma_addr);
1765 : 0 : txd->read.cmd_type_len =
1766 : 0 : rte_cpu_to_le_32(cmd_type_len | slen);
1767 : 0 : txd->read.olinfo_status =
1768 : : rte_cpu_to_le_32(olinfo_status);
1769 : 0 : txe->last_id = tx_last;
1770 : 0 : tx_id = txe->next_id;
1771 : : txe = txn;
1772 : 0 : m_seg = m_seg->next;
1773 [ # # ]: 0 : } while (m_seg != NULL);
1774 : :
1775 : : /*
1776 : : * The last packet data descriptor needs End Of Packet (EOP)
1777 : : * and Report Status (RS).
1778 : : */
1779 : 0 : txd->read.cmd_type_len |=
1780 : : rte_cpu_to_le_32(IGC_TXD_CMD_EOP | IGC_TXD_CMD_RS);
1781 : : }
1782 : 0 : end_of_tx:
1783 : : rte_wmb();
1784 : :
1785 : : /*
1786 : : * Set the Transmit Descriptor Tail (TDT).
1787 : : */
1788 : 0 : IGC_PCI_REG_WRITE_RELAXED(txq->tdt_reg_addr, tx_id);
1789 : : PMD_TX_LOG(DEBUG, "port_id=%u queue_id=%u tx_tail=%u nb_tx=%u",
1790 : : txq->port_id, txq->queue_id, tx_id, nb_tx);
1791 : 0 : txq->tx_tail = tx_id;
1792 : :
1793 : 0 : return nb_tx;
1794 : : }
1795 : :
1796 : 0 : int eth_igc_tx_descriptor_status(void *tx_queue, uint16_t offset)
1797 : : {
1798 : : struct igc_tx_queue *txq = tx_queue;
1799 : : volatile uint32_t *status;
1800 : : uint32_t desc;
1801 : :
1802 [ # # # # ]: 0 : if (unlikely(!txq || offset >= txq->nb_tx_desc))
1803 : : return -EINVAL;
1804 : :
1805 : 0 : desc = txq->tx_tail + offset;
1806 [ # # ]: 0 : if (desc >= txq->nb_tx_desc)
1807 : 0 : desc -= txq->nb_tx_desc;
1808 : :
1809 : 0 : status = &txq->tx_ring[desc].wb.status;
1810 [ # # ]: 0 : if (*status & rte_cpu_to_le_32(IGC_TXD_STAT_DD))
1811 : 0 : return RTE_ETH_TX_DESC_DONE;
1812 : :
1813 : : return RTE_ETH_TX_DESC_FULL;
1814 : : }
1815 : :
1816 : : static void
1817 : 0 : igc_tx_queue_release_mbufs(struct igc_tx_queue *txq)
1818 : : {
1819 : : unsigned int i;
1820 : :
1821 [ # # ]: 0 : if (txq->sw_ring != NULL) {
1822 [ # # ]: 0 : for (i = 0; i < txq->nb_tx_desc; i++) {
1823 [ # # ]: 0 : if (txq->sw_ring[i].mbuf != NULL) {
1824 : : rte_pktmbuf_free_seg(txq->sw_ring[i].mbuf);
1825 : 0 : txq->sw_ring[i].mbuf = NULL;
1826 : : }
1827 : : }
1828 : : }
1829 : 0 : }
1830 : :
1831 : : static void
1832 : 0 : igc_tx_queue_release(struct igc_tx_queue *txq)
1833 : : {
1834 : 0 : igc_tx_queue_release_mbufs(txq);
1835 : 0 : rte_free(txq->sw_ring);
1836 : 0 : rte_free(txq);
1837 : 0 : }
1838 : :
1839 : 0 : void eth_igc_tx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
1840 : : {
1841 [ # # ]: 0 : if (dev->data->tx_queues[qid])
1842 : 0 : igc_tx_queue_release(dev->data->tx_queues[qid]);
1843 : 0 : }
1844 : :
1845 : : static void
1846 : : igc_reset_tx_queue_stat(struct igc_tx_queue *txq)
1847 : : {
1848 : 0 : txq->tx_head = 0;
1849 : 0 : txq->tx_tail = 0;
1850 : 0 : txq->ctx_curr = 0;
1851 : 0 : memset((void *)&txq->ctx_cache, 0,
1852 : : IGC_CTX_NUM * sizeof(struct igc_advctx_info));
1853 : : }
1854 : :
1855 : : static void
1856 : 0 : igc_reset_tx_queue(struct igc_tx_queue *txq)
1857 : : {
1858 : 0 : struct igc_tx_entry *txe = txq->sw_ring;
1859 : : uint16_t i, prev;
1860 : :
1861 : : /* Initialize ring entries */
1862 : 0 : prev = (uint16_t)(txq->nb_tx_desc - 1);
1863 [ # # ]: 0 : for (i = 0; i < txq->nb_tx_desc; i++) {
1864 : 0 : volatile union igc_adv_tx_desc *txd = &txq->tx_ring[i];
1865 : :
1866 : 0 : txd->wb.status = IGC_TXD_STAT_DD;
1867 : 0 : txe[i].mbuf = NULL;
1868 : 0 : txe[i].last_id = i;
1869 : 0 : txe[prev].next_id = i;
1870 : : prev = i;
1871 : : }
1872 : :
1873 : 0 : txq->txd_type = IGC_ADVTXD_DTYP_DATA;
1874 : : igc_reset_tx_queue_stat(txq);
1875 : 0 : }
1876 : :
1877 : : /*
1878 : : * clear all rx/tx queue
1879 : : */
1880 : : void
1881 : 0 : igc_dev_clear_queues(struct rte_eth_dev *dev)
1882 : : {
1883 : : uint16_t i;
1884 : : struct igc_tx_queue *txq;
1885 : : struct igc_rx_queue *rxq;
1886 : :
1887 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
1888 : 0 : txq = dev->data->tx_queues[i];
1889 [ # # ]: 0 : if (txq != NULL) {
1890 : 0 : igc_tx_queue_release_mbufs(txq);
1891 : 0 : igc_reset_tx_queue(txq);
1892 : 0 : dev->data->tx_queue_state[i] = RTE_ETH_QUEUE_STATE_STOPPED;
1893 : : }
1894 : : }
1895 : :
1896 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
1897 : 0 : rxq = dev->data->rx_queues[i];
1898 [ # # ]: 0 : if (rxq != NULL) {
1899 : 0 : igc_rx_queue_release_mbufs(rxq);
1900 : : igc_reset_rx_queue(rxq);
1901 : 0 : dev->data->rx_queue_state[i] = RTE_ETH_QUEUE_STATE_STOPPED;
1902 : : }
1903 : : }
1904 : 0 : }
1905 : :
1906 : 0 : int eth_igc_tx_queue_setup(struct rte_eth_dev *dev, uint16_t queue_idx,
1907 : : uint16_t nb_desc, unsigned int socket_id,
1908 : : const struct rte_eth_txconf *tx_conf)
1909 : : {
1910 : : const struct rte_memzone *tz;
1911 : : struct igc_tx_queue *txq;
1912 : : struct igc_hw *hw;
1913 : : uint32_t size;
1914 : :
1915 [ # # ]: 0 : if (nb_desc % IGC_TX_DESCRIPTOR_MULTIPLE != 0 ||
1916 [ # # ]: 0 : nb_desc > IGC_MAX_TXD || nb_desc < IGC_MIN_TXD) {
1917 : 0 : PMD_DRV_LOG(ERR,
1918 : : "TX-descriptor must be a multiple of %u and between %u and %u, cur: %u",
1919 : : IGC_TX_DESCRIPTOR_MULTIPLE,
1920 : : IGC_MAX_TXD, IGC_MIN_TXD, nb_desc);
1921 : 0 : return -EINVAL;
1922 : : }
1923 : :
1924 : 0 : hw = IGC_DEV_PRIVATE_HW(dev);
1925 : :
1926 : : /*
1927 : : * The tx_free_thresh and tx_rs_thresh values are not used in the 2.5G
1928 : : * driver.
1929 : : */
1930 [ # # ]: 0 : if (tx_conf->tx_free_thresh != 0)
1931 : 0 : PMD_DRV_LOG(INFO,
1932 : : "The tx_free_thresh parameter is not used for the 2.5G driver");
1933 [ # # ]: 0 : if (tx_conf->tx_rs_thresh != 0)
1934 : 0 : PMD_DRV_LOG(INFO,
1935 : : "The tx_rs_thresh parameter is not used for the 2.5G driver");
1936 [ # # ]: 0 : if (tx_conf->tx_thresh.wthresh == 0)
1937 : 0 : PMD_DRV_LOG(INFO,
1938 : : "To improve 2.5G driver performance, consider setting the TX WTHRESH value to 4, 8, or 16.");
1939 : :
1940 : : /* Free memory prior to re-allocation if needed */
1941 [ # # ]: 0 : if (dev->data->tx_queues[queue_idx] != NULL) {
1942 : 0 : igc_tx_queue_release(dev->data->tx_queues[queue_idx]);
1943 : 0 : dev->data->tx_queues[queue_idx] = NULL;
1944 : : }
1945 : :
1946 : : /* First allocate the tx queue data structure */
1947 : 0 : txq = rte_zmalloc("ethdev TX queue", sizeof(struct igc_tx_queue),
1948 : : RTE_CACHE_LINE_SIZE);
1949 [ # # ]: 0 : if (txq == NULL)
1950 : : return -ENOMEM;
1951 : :
1952 : : /*
1953 : : * Allocate TX ring hardware descriptors. A memzone large enough to
1954 : : * handle the maximum ring size is allocated in order to allow for
1955 : : * resizing in later calls to the queue setup function.
1956 : : */
1957 : : size = sizeof(union igc_adv_tx_desc) * IGC_MAX_TXD;
1958 : 0 : tz = rte_eth_dma_zone_reserve(dev, "tx_ring", queue_idx, size,
1959 : : IGC_ALIGN, socket_id);
1960 [ # # ]: 0 : if (tz == NULL) {
1961 : 0 : igc_tx_queue_release(txq);
1962 : 0 : return -ENOMEM;
1963 : : }
1964 : :
1965 : 0 : txq->nb_tx_desc = nb_desc;
1966 : 0 : txq->pthresh = tx_conf->tx_thresh.pthresh;
1967 : 0 : txq->hthresh = tx_conf->tx_thresh.hthresh;
1968 : 0 : txq->wthresh = tx_conf->tx_thresh.wthresh;
1969 : :
1970 : 0 : txq->queue_id = queue_idx;
1971 : 0 : txq->reg_idx = queue_idx;
1972 : 0 : txq->port_id = dev->data->port_id;
1973 : :
1974 [ # # ]: 0 : txq->tdt_reg_addr = IGC_PCI_REG_ADDR(hw, IGC_TDT(txq->reg_idx));
1975 : 0 : txq->tx_ring_phys_addr = tz->iova;
1976 : :
1977 : 0 : txq->tx_ring = (union igc_adv_tx_desc *)tz->addr;
1978 : : /* Allocate software ring */
1979 : 0 : txq->sw_ring = rte_zmalloc("txq->sw_ring",
1980 : : sizeof(struct igc_tx_entry) * nb_desc,
1981 : : RTE_CACHE_LINE_SIZE);
1982 [ # # ]: 0 : if (txq->sw_ring == NULL) {
1983 : 0 : igc_tx_queue_release(txq);
1984 : 0 : return -ENOMEM;
1985 : : }
1986 : 0 : PMD_DRV_LOG(DEBUG, "sw_ring=%p hw_ring=%p dma_addr=0x%" PRIx64,
1987 : : txq->sw_ring, txq->tx_ring, txq->tx_ring_phys_addr);
1988 : :
1989 : 0 : igc_reset_tx_queue(txq);
1990 : 0 : dev->tx_pkt_burst = igc_xmit_pkts;
1991 : 0 : dev->tx_pkt_prepare = ð_igc_prep_pkts;
1992 : 0 : dev->data->tx_queues[queue_idx] = txq;
1993 : 0 : txq->offloads = tx_conf->offloads;
1994 : :
1995 : 0 : return 0;
1996 : : }
1997 : :
1998 : : int
1999 : 0 : eth_igc_tx_done_cleanup(void *txqueue, uint32_t free_cnt)
2000 : : {
2001 : : struct igc_tx_queue *txq = txqueue;
2002 : : struct igc_tx_entry *sw_ring;
2003 : : volatile union igc_adv_tx_desc *txr;
2004 : : uint16_t tx_first; /* First segment analyzed. */
2005 : : uint16_t tx_id; /* Current segment being processed. */
2006 : : uint16_t tx_last; /* Last segment in the current packet. */
2007 : : uint16_t tx_next; /* First segment of the next packet. */
2008 : : uint32_t count;
2009 : :
2010 [ # # ]: 0 : if (txq == NULL)
2011 : : return -ENODEV;
2012 : :
2013 : : count = 0;
2014 : 0 : sw_ring = txq->sw_ring;
2015 : 0 : txr = txq->tx_ring;
2016 : :
2017 : : /*
2018 : : * tx_tail is the last sent packet on the sw_ring. Goto the end
2019 : : * of that packet (the last segment in the packet chain) and
2020 : : * then the next segment will be the start of the oldest segment
2021 : : * in the sw_ring. This is the first packet that will be
2022 : : * attempted to be freed.
2023 : : */
2024 : :
2025 : : /* Get last segment in most recently added packet. */
2026 : 0 : tx_first = sw_ring[txq->tx_tail].last_id;
2027 : :
2028 : : /* Get the next segment, which is the oldest segment in ring. */
2029 : 0 : tx_first = sw_ring[tx_first].next_id;
2030 : :
2031 : : /* Set the current index to the first. */
2032 : : tx_id = tx_first;
2033 : :
2034 : : /*
2035 : : * Loop through each packet. For each packet, verify that an
2036 : : * mbuf exists and that the last segment is free. If so, free
2037 : : * it and move on.
2038 : : */
2039 : : while (1) {
2040 : 0 : tx_last = sw_ring[tx_id].last_id;
2041 : :
2042 [ # # ]: 0 : if (sw_ring[tx_last].mbuf) {
2043 [ # # ]: 0 : if (!(txr[tx_last].wb.status &
2044 : : rte_cpu_to_le_32(IGC_TXD_STAT_DD)))
2045 : : break;
2046 : :
2047 : : /* Get the start of the next packet. */
2048 : 0 : tx_next = sw_ring[tx_last].next_id;
2049 : :
2050 : : /*
2051 : : * Loop through all segments in a
2052 : : * packet.
2053 : : */
2054 : : do {
2055 [ # # ]: 0 : rte_pktmbuf_free_seg(sw_ring[tx_id].mbuf);
2056 : 0 : sw_ring[tx_id].mbuf = NULL;
2057 : 0 : sw_ring[tx_id].last_id = tx_id;
2058 : :
2059 : : /* Move to next segment. */
2060 : 0 : tx_id = sw_ring[tx_id].next_id;
2061 [ # # ]: 0 : } while (tx_id != tx_next);
2062 : :
2063 : : /*
2064 : : * Increment the number of packets
2065 : : * freed.
2066 : : */
2067 : 0 : count++;
2068 [ # # ]: 0 : if (unlikely(count == free_cnt))
2069 : : break;
2070 : : } else {
2071 : : /*
2072 : : * There are multiple reasons to be here:
2073 : : * 1) All the packets on the ring have been
2074 : : * freed - tx_id is equal to tx_first
2075 : : * and some packets have been freed.
2076 : : * - Done, exit
2077 : : * 2) Interfaces has not sent a rings worth of
2078 : : * packets yet, so the segment after tail is
2079 : : * still empty. Or a previous call to this
2080 : : * function freed some of the segments but
2081 : : * not all so there is a hole in the list.
2082 : : * Hopefully this is a rare case.
2083 : : * - Walk the list and find the next mbuf. If
2084 : : * there isn't one, then done.
2085 : : */
2086 [ # # ]: 0 : if (likely(tx_id == tx_first && count != 0))
2087 : : break;
2088 : :
2089 : : /*
2090 : : * Walk the list and find the next mbuf, if any.
2091 : : */
2092 : : do {
2093 : : /* Move to next segment. */
2094 : 0 : tx_id = sw_ring[tx_id].next_id;
2095 : :
2096 [ # # ]: 0 : if (sw_ring[tx_id].mbuf)
2097 : : break;
2098 : :
2099 [ # # ]: 0 : } while (tx_id != tx_first);
2100 : :
2101 : : /*
2102 : : * Determine why previous loop bailed. If there
2103 : : * is not an mbuf, done.
2104 : : */
2105 [ # # ]: 0 : if (sw_ring[tx_id].mbuf == NULL)
2106 : : break;
2107 : : }
2108 : : }
2109 : :
2110 : 0 : return count;
2111 : : }
2112 : :
2113 : : void
2114 : 0 : igc_tx_init(struct rte_eth_dev *dev)
2115 : : {
2116 : 0 : struct igc_hw *hw = IGC_DEV_PRIVATE_HW(dev);
2117 : 0 : uint64_t offloads = dev->data->dev_conf.txmode.offloads;
2118 : : uint32_t tctl;
2119 : : uint32_t txdctl;
2120 : : uint16_t i;
2121 : : int err;
2122 : :
2123 : : /* Setup the Base and Length of the Tx Descriptor Rings. */
2124 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
2125 : 0 : struct igc_tx_queue *txq = dev->data->tx_queues[i];
2126 : 0 : uint64_t bus_addr = txq->tx_ring_phys_addr;
2127 : :
2128 [ # # ]: 0 : IGC_WRITE_REG(hw, IGC_TDLEN(txq->reg_idx),
2129 : : txq->nb_tx_desc *
2130 : : sizeof(union igc_adv_tx_desc));
2131 [ # # ]: 0 : IGC_WRITE_REG(hw, IGC_TDBAH(txq->reg_idx),
2132 : : (uint32_t)(bus_addr >> 32));
2133 [ # # ]: 0 : IGC_WRITE_REG(hw, IGC_TDBAL(txq->reg_idx),
2134 : : (uint32_t)bus_addr);
2135 : :
2136 : : /* Setup the HW Tx Head and Tail descriptor pointers. */
2137 [ # # ]: 0 : IGC_WRITE_REG(hw, IGC_TDT(txq->reg_idx), 0);
2138 [ # # ]: 0 : IGC_WRITE_REG(hw, IGC_TDH(txq->reg_idx), 0);
2139 : :
2140 : : /* Setup Transmit threshold registers. */
2141 : 0 : txdctl = ((uint32_t)txq->pthresh << IGC_TXDCTL_PTHRESH_SHIFT) &
2142 : : IGC_TXDCTL_PTHRESH_MSK;
2143 : 0 : txdctl |= ((uint32_t)txq->hthresh << IGC_TXDCTL_HTHRESH_SHIFT) &
2144 : : IGC_TXDCTL_HTHRESH_MSK;
2145 : 0 : txdctl |= ((uint32_t)txq->wthresh << IGC_TXDCTL_WTHRESH_SHIFT) &
2146 : : IGC_TXDCTL_WTHRESH_MSK;
2147 : 0 : txdctl |= IGC_TXDCTL_QUEUE_ENABLE;
2148 [ # # ]: 0 : IGC_WRITE_REG(hw, IGC_TXDCTL(txq->reg_idx), txdctl);
2149 : 0 : dev->data->tx_queue_state[i] = RTE_ETH_QUEUE_STATE_STARTED;
2150 : : }
2151 : :
2152 [ # # ]: 0 : if (offloads & RTE_ETH_TX_OFFLOAD_SEND_ON_TIMESTAMP) {
2153 : 0 : err = rte_mbuf_dyn_tx_timestamp_register
2154 : : (&igc_tx_timestamp_dynfield_offset,
2155 : : &igc_tx_timestamp_dynflag);
2156 [ # # ]: 0 : if (err) {
2157 : 0 : PMD_DRV_LOG(ERR,
2158 : : "Cannot register mbuf field/flag for timestamp");
2159 : : }
2160 : : }
2161 : :
2162 : 0 : igc_config_collision_dist(hw);
2163 : :
2164 : : /* Program the Transmit Control Register. */
2165 : 0 : tctl = IGC_READ_REG(hw, IGC_TCTL);
2166 : 0 : tctl &= ~IGC_TCTL_CT;
2167 : 0 : tctl |= (IGC_TCTL_PSP | IGC_TCTL_RTLC | IGC_TCTL_EN |
2168 : : ((uint32_t)IGC_COLLISION_THRESHOLD << IGC_CT_SHIFT));
2169 : :
2170 : : /* This write will effectively turn on the transmit unit. */
2171 : 0 : IGC_WRITE_REG(hw, IGC_TCTL, tctl);
2172 : 0 : }
2173 : :
2174 : : void
2175 : 0 : eth_igc_rxq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
2176 : : struct rte_eth_rxq_info *qinfo)
2177 : : {
2178 : : struct igc_rx_queue *rxq;
2179 : :
2180 : 0 : rxq = dev->data->rx_queues[queue_id];
2181 : :
2182 : 0 : qinfo->mp = rxq->mb_pool;
2183 : 0 : qinfo->scattered_rx = dev->data->scattered_rx;
2184 : 0 : qinfo->nb_desc = rxq->nb_rx_desc;
2185 : :
2186 : 0 : qinfo->conf.rx_free_thresh = rxq->rx_free_thresh;
2187 : 0 : qinfo->conf.rx_drop_en = rxq->drop_en;
2188 : 0 : qinfo->conf.offloads = rxq->offloads;
2189 : 0 : qinfo->conf.rx_thresh.hthresh = rxq->hthresh;
2190 : 0 : qinfo->conf.rx_thresh.pthresh = rxq->pthresh;
2191 : 0 : qinfo->conf.rx_thresh.wthresh = rxq->wthresh;
2192 : 0 : }
2193 : :
2194 : : void
2195 : 0 : eth_igc_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
2196 : : struct rte_eth_txq_info *qinfo)
2197 : : {
2198 : : struct igc_tx_queue *txq;
2199 : :
2200 : 0 : txq = dev->data->tx_queues[queue_id];
2201 : :
2202 : 0 : qinfo->nb_desc = txq->nb_tx_desc;
2203 : :
2204 : 0 : qinfo->conf.tx_thresh.pthresh = txq->pthresh;
2205 : 0 : qinfo->conf.tx_thresh.hthresh = txq->hthresh;
2206 : 0 : qinfo->conf.tx_thresh.wthresh = txq->wthresh;
2207 : 0 : qinfo->conf.offloads = txq->offloads;
2208 : 0 : }
2209 : :
2210 : : void
2211 : 0 : eth_igc_vlan_strip_queue_set(struct rte_eth_dev *dev,
2212 : : uint16_t rx_queue_id, int on)
2213 : : {
2214 : 0 : struct igc_hw *hw = IGC_DEV_PRIVATE_HW(dev);
2215 : 0 : struct igc_rx_queue *rxq = dev->data->rx_queues[rx_queue_id];
2216 : : uint32_t reg_val;
2217 : :
2218 [ # # ]: 0 : if (rx_queue_id >= IGC_QUEUE_PAIRS_NUM) {
2219 : 0 : PMD_DRV_LOG(ERR, "Queue index(%u) illegal, max is %u",
2220 : : rx_queue_id, IGC_QUEUE_PAIRS_NUM - 1);
2221 : 0 : return;
2222 : : }
2223 : :
2224 : 0 : reg_val = IGC_READ_REG(hw, IGC_DVMOLR(rx_queue_id));
2225 [ # # ]: 0 : if (on) {
2226 : 0 : reg_val |= IGC_DVMOLR_STRVLAN;
2227 : 0 : rxq->offloads |= RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
2228 : : } else {
2229 : 0 : reg_val &= ~(IGC_DVMOLR_STRVLAN | IGC_DVMOLR_HIDVLAN);
2230 : 0 : rxq->offloads &= ~RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
2231 : : }
2232 : :
2233 : 0 : IGC_WRITE_REG(hw, IGC_DVMOLR(rx_queue_id), reg_val);
2234 : : }
|