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