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 += IGC_RSS_RDT_REG_SIZE) {
832 : 0 : union igc_rss_reta_reg reta = { .dword = 0 };
833 : : uint16_t reta_idx;
834 : :
835 : : RTE_BUILD_BUG_ON(sizeof(reta.bytes) != IGC_RSS_RDT_REG_SIZE);
836 [ # # ]: 0 : for (reta_idx = 0; reta_idx < IGC_RSS_RDT_REG_SIZE; reta_idx++) {
837 : : uint16_t q_idx;
838 : :
839 [ # # ]: 0 : q_idx = (uint8_t)((dev->data->nb_rx_queues > 1) ?
840 : 0 : (i + reta_idx) % dev->data->nb_rx_queues : 0);
841 : 0 : reta.bytes[reta_idx] = q_idx;
842 : : }
843 : 0 : E1000_WRITE_REG_LE_VALUE(hw,
844 : : E1000_RETA(i / IGC_RSS_RDT_REG_SIZE), reta.dword);
845 : : }
846 : :
847 : : /*
848 : : * Configure the RSS key and the RSS protocols used to compute
849 : : * the RSS hash of input packets.
850 : : */
851 : 0 : rss_conf = dev->data->dev_conf.rx_adv_conf.rss_conf;
852 [ # # ]: 0 : if (rss_conf.rss_key == NULL)
853 : 0 : rss_conf.rss_key = default_rss_key;
854 : 0 : igc_hw_rss_hash_set(hw, &rss_conf);
855 : 0 : }
856 : :
857 : : int
858 : 0 : igc_del_rss_filter(struct rte_eth_dev *dev)
859 : : {
860 : 0 : struct igc_rss_filter *rss_filter = IGC_DEV_PRIVATE_RSS_FILTER(dev);
861 : :
862 [ # # ]: 0 : if (rss_filter->enable) {
863 : : /* recover default RSS configuration */
864 : 0 : igc_rss_configure(dev);
865 : :
866 : : /* disable RSS logic and clear filter data */
867 : 0 : igc_rss_disable(dev);
868 : : memset(rss_filter, 0, sizeof(*rss_filter));
869 : 0 : return 0;
870 : : }
871 : 0 : PMD_DRV_LOG(ERR, "filter not exist!");
872 : 0 : return -ENOENT;
873 : : }
874 : :
875 : : /* Initiate the filter structure by the structure of rte_flow_action_rss */
876 : : void
877 : 0 : igc_rss_conf_set(struct igc_rss_filter *out,
878 : : const struct rte_flow_action_rss *rss)
879 : : {
880 : 0 : out->conf.func = rss->func;
881 : 0 : out->conf.level = rss->level;
882 : 0 : out->conf.types = rss->types;
883 : :
884 [ # # ]: 0 : if (rss->key_len == sizeof(out->key)) {
885 : 0 : memcpy(out->key, rss->key, rss->key_len);
886 : 0 : out->conf.key = out->key;
887 : 0 : out->conf.key_len = rss->key_len;
888 : : } else {
889 : 0 : out->conf.key = NULL;
890 : 0 : out->conf.key_len = 0;
891 : : }
892 : :
893 [ # # ]: 0 : if (rss->queue_num <= IGC_RSS_RDT_SIZD) {
894 : 0 : memcpy(out->queue, rss->queue,
895 : 0 : sizeof(*out->queue) * rss->queue_num);
896 : 0 : out->conf.queue = out->queue;
897 : 0 : out->conf.queue_num = rss->queue_num;
898 : : } else {
899 : 0 : out->conf.queue = NULL;
900 : 0 : out->conf.queue_num = 0;
901 : : }
902 : 0 : }
903 : :
904 : : int
905 : 0 : igc_add_rss_filter(struct rte_eth_dev *dev, struct igc_rss_filter *rss)
906 : : {
907 : 0 : struct rte_eth_rss_conf rss_conf = {
908 : 0 : .rss_key = rss->conf.key_len ?
909 [ # # ]: 0 : (void *)(uintptr_t)rss->conf.key : NULL,
910 : : .rss_key_len = rss->conf.key_len,
911 : 0 : .rss_hf = rss->conf.types,
912 : : };
913 : 0 : struct e1000_hw *hw = IGC_DEV_PRIVATE_HW(dev);
914 : 0 : struct igc_rss_filter *rss_filter = IGC_DEV_PRIVATE_RSS_FILTER(dev);
915 : : uint32_t i, j;
916 : :
917 : : /* check RSS type is valid */
918 [ # # ]: 0 : if ((rss_conf.rss_hf & IGC_RSS_OFFLOAD_ALL) == 0) {
919 : 0 : PMD_DRV_LOG(ERR,
920 : : "RSS type(0x%" PRIx64 ") error!, only 0x%" PRIx64
921 : : " been supported", rss_conf.rss_hf,
922 : : (uint64_t)IGC_RSS_OFFLOAD_ALL);
923 : 0 : return -EINVAL;
924 : : }
925 : :
926 : : /* check queue count is not zero */
927 [ # # ]: 0 : if (!rss->conf.queue_num) {
928 : 0 : PMD_DRV_LOG(ERR, "Queue number should not be 0!");
929 : 0 : return -EINVAL;
930 : : }
931 : :
932 : : /* check queue id is valid */
933 [ # # ]: 0 : for (i = 0; i < rss->conf.queue_num; i++)
934 [ # # ]: 0 : if (rss->conf.queue[i] >= dev->data->nb_rx_queues) {
935 : 0 : PMD_DRV_LOG(ERR, "Queue id %u is invalid!",
936 : : rss->conf.queue[i]);
937 : 0 : return -EINVAL;
938 : : }
939 : :
940 : : /* only support one filter */
941 [ # # ]: 0 : if (rss_filter->enable) {
942 : 0 : PMD_DRV_LOG(ERR, "Only support one RSS filter!");
943 : 0 : return -ENOTSUP;
944 : : }
945 : 0 : rss_filter->enable = 1;
946 : :
947 : 0 : igc_rss_conf_set(rss_filter, &rss->conf);
948 : :
949 : : /* Fill in redirection table. */
950 [ # # ]: 0 : for (i = 0, j = 0; i < IGC_RSS_RDT_SIZD; i += IGC_RSS_RDT_REG_SIZE) {
951 : 0 : union igc_rss_reta_reg reta = { .dword = 0 };
952 : : uint16_t reta_idx;
953 : :
954 : : RTE_BUILD_BUG_ON(sizeof(reta.bytes) != IGC_RSS_RDT_REG_SIZE);
955 [ # # ]: 0 : for (reta_idx = 0; reta_idx < IGC_RSS_RDT_REG_SIZE; reta_idx++, j++) {
956 [ # # ]: 0 : if (j == rss->conf.queue_num)
957 : : j = 0;
958 : 0 : reta.bytes[reta_idx] = rss->conf.queue[j];
959 : : }
960 : 0 : E1000_WRITE_REG_LE_VALUE(hw,
961 : : E1000_RETA(i / IGC_RSS_RDT_REG_SIZE), reta.dword);
962 : : }
963 : :
964 [ # # ]: 0 : if (rss_conf.rss_key == NULL)
965 : 0 : rss_conf.rss_key = default_rss_key;
966 : 0 : igc_hw_rss_hash_set(hw, &rss_conf);
967 : 0 : return 0;
968 : : }
969 : :
970 : : void
971 : 0 : igc_clear_rss_filter(struct rte_eth_dev *dev)
972 : : {
973 : 0 : struct igc_rss_filter *rss_filter = IGC_DEV_PRIVATE_RSS_FILTER(dev);
974 : :
975 [ # # ]: 0 : if (!rss_filter->enable)
976 : : return;
977 : :
978 : : /* recover default RSS configuration */
979 : 0 : igc_rss_configure(dev);
980 : :
981 : : /* disable RSS logic and clear filter data */
982 : 0 : igc_rss_disable(dev);
983 : : memset(rss_filter, 0, sizeof(*rss_filter));
984 : : }
985 : :
986 : : static int
987 : 0 : igc_dev_mq_rx_configure(struct rte_eth_dev *dev)
988 : : {
989 [ # # ]: 0 : if (RTE_ETH_DEV_SRIOV(dev).active) {
990 : 0 : PMD_DRV_LOG(ERR, "SRIOV unsupported!");
991 : 0 : return -EINVAL;
992 : : }
993 : :
994 : 0 : igc_rss_configure(dev);
995 [ # # ]: 0 : if (dev->data->dev_conf.rxmode.mq_mode != RTE_ETH_MQ_RX_RSS)
996 : 0 : igc_rss_disable(dev);
997 : :
998 : : return 0;
999 : : }
1000 : :
1001 : : int
1002 : 0 : igc_rx_init(struct rte_eth_dev *dev)
1003 : : {
1004 : : struct igc_rx_queue *rxq;
1005 : 0 : struct e1000_hw *hw = IGC_DEV_PRIVATE_HW(dev);
1006 : 0 : uint64_t offloads = dev->data->dev_conf.rxmode.offloads;
1007 : : uint32_t max_rx_pktlen;
1008 : : uint32_t rctl;
1009 : : uint32_t rxcsum;
1010 : : uint16_t buf_size;
1011 : : uint16_t rctl_bsize;
1012 : : uint16_t i;
1013 : : int ret;
1014 : :
1015 : 0 : dev->rx_pkt_burst = igc_recv_pkts;
1016 : :
1017 : : /*
1018 : : * Make sure receives are disabled while setting
1019 : : * up the descriptor ring.
1020 : : */
1021 : 0 : rctl = E1000_READ_REG(hw, E1000_RCTL);
1022 : 0 : E1000_WRITE_REG(hw, E1000_RCTL, rctl & ~E1000_RCTL_EN);
1023 : :
1024 : : /* Configure support of jumbo frames, if any. */
1025 [ # # ]: 0 : if (dev->data->mtu > RTE_ETHER_MTU)
1026 : 0 : rctl |= E1000_RCTL_LPE;
1027 : : else
1028 : 0 : rctl &= ~E1000_RCTL_LPE;
1029 : :
1030 : 0 : max_rx_pktlen = dev->data->mtu + IGC_ETH_OVERHEAD;
1031 : : /*
1032 : : * Set maximum packet length by default, and might be updated
1033 : : * together with enabling/disabling dual VLAN.
1034 : : */
1035 : 0 : E1000_WRITE_REG(hw, E1000_RLPML, max_rx_pktlen);
1036 : :
1037 : : /* Configure and enable each RX queue. */
1038 : : rctl_bsize = 0;
1039 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
1040 : : uint64_t bus_addr;
1041 : : uint32_t rxdctl;
1042 : : uint32_t srrctl;
1043 : :
1044 : 0 : rxq = dev->data->rx_queues[i];
1045 : 0 : rxq->flags = 0;
1046 : :
1047 [ # # ]: 0 : if (offloads & RTE_ETH_RX_OFFLOAD_TIMESTAMP)
1048 : 0 : rxq->offloads |= RTE_ETH_RX_OFFLOAD_TIMESTAMP;
1049 : :
1050 : : /* Allocate buffers for descriptor rings and set up queue */
1051 : 0 : ret = igc_alloc_rx_queue_mbufs(rxq);
1052 [ # # ]: 0 : if (ret)
1053 : 0 : return ret;
1054 : :
1055 : : /*
1056 : : * Reset crc_len in case it was changed after queue setup by a
1057 : : * call to configure
1058 : : */
1059 : 0 : rxq->crc_len = (offloads & RTE_ETH_RX_OFFLOAD_KEEP_CRC) ?
1060 : 0 : RTE_ETHER_CRC_LEN : 0;
1061 : :
1062 : 0 : bus_addr = rxq->rx_ring_phys_addr;
1063 [ # # ]: 0 : E1000_WRITE_REG(hw, E1000_RDLEN(rxq->reg_idx),
1064 : : rxq->nb_rx_desc *
1065 : : sizeof(union e1000_adv_rx_desc));
1066 [ # # ]: 0 : E1000_WRITE_REG(hw, E1000_RDBAH(rxq->reg_idx),
1067 : : (uint32_t)(bus_addr >> 32));
1068 [ # # ]: 0 : E1000_WRITE_REG(hw, E1000_RDBAL(rxq->reg_idx),
1069 : : (uint32_t)bus_addr);
1070 : :
1071 : : /* set descriptor configuration */
1072 : : srrctl = E1000_SRRCTL_DESCTYPE_ADV_ONEBUF;
1073 : :
1074 : : srrctl |= (uint32_t)(RTE_PKTMBUF_HEADROOM / 64) <<
1075 : : IGC_SRRCTL_BSIZEHEADER_SHIFT;
1076 : : /*
1077 : : * Configure RX buffer size.
1078 : : */
1079 [ # # ]: 0 : buf_size = (uint16_t)(rte_pktmbuf_data_room_size(rxq->mb_pool) -
1080 : : RTE_PKTMBUF_HEADROOM);
1081 [ # # ]: 0 : if (buf_size >= 1024) {
1082 : : /*
1083 : : * Configure the BSIZEPACKET field of the SRRCTL
1084 : : * register of the queue.
1085 : : * Value is in 1 KB resolution, from 1 KB to 16 KB.
1086 : : * If this field is equal to 0b, then RCTL.BSIZE
1087 : : * determines the RX packet buffer size.
1088 : : */
1089 : :
1090 : 0 : srrctl |= ((buf_size >> E1000_SRRCTL_BSIZEPKT_SHIFT) &
1091 : : E1000_SRRCTL_BSIZEPKT_MASK);
1092 : 0 : buf_size = (uint16_t)((srrctl &
1093 : : E1000_SRRCTL_BSIZEPKT_MASK) <<
1094 : : E1000_SRRCTL_BSIZEPKT_SHIFT);
1095 : :
1096 : : /* It adds dual VLAN length for supporting dual VLAN */
1097 [ # # ]: 0 : if (max_rx_pktlen > buf_size)
1098 : 0 : dev->data->scattered_rx = 1;
1099 : : } else {
1100 : : /*
1101 : : * Use BSIZE field of the device RCTL register.
1102 : : */
1103 [ # # ]: 0 : if (rctl_bsize == 0 || rctl_bsize > buf_size)
1104 : : rctl_bsize = buf_size;
1105 : 0 : dev->data->scattered_rx = 1;
1106 : : }
1107 : :
1108 : : /* Set if packets are dropped when no descriptors available */
1109 [ # # ]: 0 : if (rxq->drop_en)
1110 : 0 : srrctl |= E1000_SRRCTL_DROP_EN;
1111 : :
1112 [ # # ]: 0 : E1000_WRITE_REG(hw, E1000_SRRCTL(rxq->reg_idx), srrctl);
1113 : :
1114 : : /* Enable this RX queue. */
1115 : : rxdctl = E1000_RXDCTL_QUEUE_ENABLE;
1116 : 0 : rxdctl |= ((uint32_t)rxq->pthresh << IGC_RXDCTL_PTHRESH_SHIFT) &
1117 : : IGC_RXDCTL_PTHRESH_MSK;
1118 : 0 : rxdctl |= ((uint32_t)rxq->hthresh << IGC_RXDCTL_HTHRESH_SHIFT) &
1119 : : IGC_RXDCTL_HTHRESH_MSK;
1120 : 0 : rxdctl |= ((uint32_t)rxq->wthresh << IGC_RXDCTL_WTHRESH_SHIFT) &
1121 : : IGC_RXDCTL_WTHRESH_MSK;
1122 [ # # ]: 0 : E1000_WRITE_REG(hw, E1000_RXDCTL(rxq->reg_idx), rxdctl);
1123 : : }
1124 : :
1125 [ # # ]: 0 : if (offloads & RTE_ETH_RX_OFFLOAD_SCATTER)
1126 : 0 : dev->data->scattered_rx = 1;
1127 : :
1128 [ # # ]: 0 : if (dev->data->scattered_rx) {
1129 : 0 : PMD_DRV_LOG(DEBUG, "forcing scatter mode");
1130 : 0 : dev->rx_pkt_burst = igc_recv_scattered_pkts;
1131 : : }
1132 : : /*
1133 : : * Setup BSIZE field of RCTL register, if needed.
1134 : : * Buffer sizes >= 1024 are not [supposed to be] setup in the RCTL
1135 : : * register, since the code above configures the SRRCTL register of
1136 : : * the RX queue in such a case.
1137 : : * All configurable sizes are:
1138 : : * 16384: rctl |= (E1000_RCTL_SZ_16384 | E1000_RCTL_BSEX);
1139 : : * 8192: rctl |= (E1000_RCTL_SZ_8192 | E1000_RCTL_BSEX);
1140 : : * 4096: rctl |= (E1000_RCTL_SZ_4096 | E1000_RCTL_BSEX);
1141 : : * 2048: rctl |= E1000_RCTL_SZ_2048;
1142 : : * 1024: rctl |= E1000_RCTL_SZ_1024;
1143 : : * 512: rctl |= E1000_RCTL_SZ_512;
1144 : : * 256: rctl |= E1000_RCTL_SZ_256;
1145 : : */
1146 [ # # ]: 0 : if (rctl_bsize > 0) {
1147 [ # # ]: 0 : if (rctl_bsize >= 512) /* 512 <= buf_size < 1024 - use 512 */
1148 : 0 : rctl |= E1000_RCTL_SZ_512;
1149 : : else /* 256 <= buf_size < 512 - use 256 */
1150 : 0 : rctl |= E1000_RCTL_SZ_256;
1151 : : }
1152 : :
1153 : : /*
1154 : : * Configure RSS if device configured with multiple RX queues.
1155 : : */
1156 : 0 : igc_dev_mq_rx_configure(dev);
1157 : :
1158 : : /* Update the rctl since igc_dev_mq_rx_configure may change its value */
1159 : 0 : rctl |= E1000_READ_REG(hw, E1000_RCTL);
1160 : :
1161 : : /*
1162 : : * Setup the Checksum Register.
1163 : : * Receive Full-Packet Checksum Offload is mutually exclusive with RSS.
1164 : : */
1165 : 0 : rxcsum = E1000_READ_REG(hw, E1000_RXCSUM);
1166 : : rxcsum |= E1000_RXCSUM_PCSD;
1167 : :
1168 : : /* Enable both L3/L4 rx checksum offload */
1169 [ # # ]: 0 : if (offloads & RTE_ETH_RX_OFFLOAD_IPV4_CKSUM)
1170 : 0 : rxcsum |= E1000_RXCSUM_IPOFL;
1171 : : else
1172 : 0 : rxcsum &= ~E1000_RXCSUM_IPOFL;
1173 : :
1174 [ # # ]: 0 : if (offloads &
1175 : : (RTE_ETH_RX_OFFLOAD_TCP_CKSUM | RTE_ETH_RX_OFFLOAD_UDP_CKSUM)) {
1176 : 0 : rxcsum |= E1000_RXCSUM_TUOFL;
1177 : 0 : offloads |= RTE_ETH_RX_OFFLOAD_SCTP_CKSUM;
1178 : : } else {
1179 : 0 : rxcsum &= ~E1000_RXCSUM_TUOFL;
1180 : : }
1181 : :
1182 [ # # ]: 0 : if (offloads & RTE_ETH_RX_OFFLOAD_SCTP_CKSUM)
1183 : 0 : rxcsum |= E1000_RXCSUM_CRCOFL;
1184 : : else
1185 : 0 : rxcsum &= ~E1000_RXCSUM_CRCOFL;
1186 : :
1187 : 0 : E1000_WRITE_REG(hw, E1000_RXCSUM, rxcsum);
1188 : :
1189 : : /* Setup the Receive Control Register. */
1190 [ # # ]: 0 : if (offloads & RTE_ETH_RX_OFFLOAD_KEEP_CRC)
1191 : 0 : rctl &= ~E1000_RCTL_SECRC; /* Do not Strip Ethernet CRC. */
1192 : : else
1193 : 0 : rctl |= E1000_RCTL_SECRC; /* Strip Ethernet CRC. */
1194 : :
1195 : : rctl &= ~E1000_RCTL_MO_MSK;
1196 : 0 : rctl &= ~E1000_RCTL_LBM_MSK;
1197 : 0 : rctl |= E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_LBM_NO |
1198 : : E1000_RCTL_DPF |
1199 : 0 : (hw->mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
1200 : :
1201 [ # # ]: 0 : if (dev->data->dev_conf.lpbk_mode == 1)
1202 : 0 : rctl |= E1000_RCTL_LBM_MAC;
1203 : :
1204 : : rctl &= ~(E1000_RCTL_HSEL_MSK | E1000_RCTL_CFIEN | E1000_RCTL_CFI |
1205 : : E1000_RCTL_PSP | E1000_RCTL_PMCF);
1206 : :
1207 : : /* Make sure VLAN Filters are off. */
1208 : : rctl &= ~E1000_RCTL_VFE;
1209 : : /* Don't store bad packets. */
1210 : 0 : rctl &= ~E1000_RCTL_SBP;
1211 : :
1212 : : /* Enable Receives. */
1213 : 0 : E1000_WRITE_REG(hw, E1000_RCTL, rctl);
1214 : :
1215 : : /*
1216 : : * Setup the HW Rx Head and Tail Descriptor Pointers.
1217 : : * This needs to be done after enable.
1218 : : */
1219 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
1220 : : uint32_t dvmolr;
1221 : :
1222 : 0 : rxq = dev->data->rx_queues[i];
1223 [ # # ]: 0 : E1000_WRITE_REG(hw, E1000_RDH(rxq->reg_idx), 0);
1224 [ # # ]: 0 : E1000_WRITE_REG(hw, E1000_RDT(rxq->reg_idx), rxq->nb_rx_desc - 1);
1225 : :
1226 : 0 : dvmolr = E1000_READ_REG(hw, E1000_DVMOLR(rxq->reg_idx));
1227 [ # # ]: 0 : if (rxq->offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP)
1228 : 0 : dvmolr |= E1000_DVMOLR_STRVLAN;
1229 : : else
1230 : 0 : dvmolr &= ~E1000_DVMOLR_STRVLAN;
1231 : :
1232 [ # # ]: 0 : if (offloads & RTE_ETH_RX_OFFLOAD_KEEP_CRC)
1233 : 0 : dvmolr &= ~E1000_DVMOLR_STRCRC;
1234 : : else
1235 : 0 : dvmolr |= E1000_DVMOLR_STRCRC;
1236 : :
1237 : 0 : E1000_WRITE_REG(hw, E1000_DVMOLR(rxq->reg_idx), dvmolr);
1238 : 0 : dev->data->rx_queue_state[i] = RTE_ETH_QUEUE_STATE_STARTED;
1239 : : }
1240 : :
1241 : : return 0;
1242 : : }
1243 : :
1244 : : static void
1245 : : igc_reset_rx_queue(struct igc_rx_queue *rxq)
1246 : : {
1247 : : static const union e1000_adv_rx_desc zeroed_desc = { {0} };
1248 : : unsigned int i;
1249 : :
1250 : : /* Zero out HW ring memory */
1251 [ # # # # ]: 0 : for (i = 0; i < rxq->nb_rx_desc; i++)
1252 : 0 : rxq->rx_ring[i] = zeroed_desc;
1253 : :
1254 : 0 : rxq->rx_tail = 0;
1255 : 0 : rxq->pkt_first_seg = NULL;
1256 : 0 : rxq->pkt_last_seg = NULL;
1257 : : }
1258 : :
1259 : : int
1260 : 0 : eth_igc_rx_queue_setup(struct rte_eth_dev *dev,
1261 : : uint16_t queue_idx,
1262 : : uint16_t nb_desc,
1263 : : unsigned int socket_id,
1264 : : const struct rte_eth_rxconf *rx_conf,
1265 : : struct rte_mempool *mp)
1266 : : {
1267 : 0 : struct e1000_hw *hw = IGC_DEV_PRIVATE_HW(dev);
1268 : : const struct rte_memzone *rz;
1269 : : struct igc_rx_queue *rxq;
1270 : : unsigned int size;
1271 : :
1272 : : /*
1273 : : * Validate number of receive descriptors.
1274 : : * It must not exceed hardware maximum, and must be multiple
1275 : : * of IGC_RX_DESCRIPTOR_MULTIPLE.
1276 : : */
1277 [ # # ]: 0 : if (nb_desc % IGC_RX_DESCRIPTOR_MULTIPLE != 0 ||
1278 [ # # ]: 0 : nb_desc > IGC_MAX_RXD || nb_desc < IGC_MIN_RXD) {
1279 : 0 : PMD_DRV_LOG(ERR,
1280 : : "RX descriptor must be multiple of %u(cur: %u) and between %u and %u",
1281 : : IGC_RX_DESCRIPTOR_MULTIPLE, nb_desc,
1282 : : IGC_MIN_RXD, IGC_MAX_RXD);
1283 : 0 : return -EINVAL;
1284 : : }
1285 : :
1286 : : /* Free memory prior to re-allocation if needed */
1287 [ # # ]: 0 : if (dev->data->rx_queues[queue_idx] != NULL) {
1288 : 0 : igc_rx_queue_release(dev->data->rx_queues[queue_idx]);
1289 : 0 : dev->data->rx_queues[queue_idx] = NULL;
1290 : : }
1291 : :
1292 : : /* First allocate the RX queue data structure. */
1293 : 0 : rxq = rte_zmalloc("ethdev RX queue", sizeof(struct igc_rx_queue),
1294 : : RTE_CACHE_LINE_SIZE);
1295 [ # # ]: 0 : if (rxq == NULL)
1296 : : return -ENOMEM;
1297 : 0 : rxq->offloads = rx_conf->offloads;
1298 : 0 : rxq->mb_pool = mp;
1299 : 0 : rxq->nb_rx_desc = nb_desc;
1300 : 0 : rxq->pthresh = rx_conf->rx_thresh.pthresh;
1301 : 0 : rxq->hthresh = rx_conf->rx_thresh.hthresh;
1302 : 0 : rxq->wthresh = rx_conf->rx_thresh.wthresh;
1303 : 0 : rxq->drop_en = rx_conf->rx_drop_en;
1304 : 0 : rxq->rx_free_thresh = rx_conf->rx_free_thresh;
1305 : 0 : rxq->queue_id = queue_idx;
1306 : 0 : rxq->reg_idx = queue_idx;
1307 : 0 : rxq->port_id = dev->data->port_id;
1308 : :
1309 : : /*
1310 : : * Allocate RX ring hardware descriptors. A memzone large enough to
1311 : : * handle the maximum ring size is allocated in order to allow for
1312 : : * resizing in later calls to the queue setup function.
1313 : : */
1314 : : size = sizeof(union e1000_adv_rx_desc) * IGC_MAX_RXD;
1315 : 0 : rz = rte_eth_dma_zone_reserve(dev, "rx_ring", queue_idx, size,
1316 : : IGC_ALIGN, socket_id);
1317 [ # # ]: 0 : if (rz == NULL) {
1318 : 0 : igc_rx_queue_release(rxq);
1319 : 0 : return -ENOMEM;
1320 : : }
1321 [ # # ]: 0 : rxq->rdt_reg_addr = E1000_PCI_REG_ADDR(hw, E1000_RDT(rxq->reg_idx));
1322 [ # # ]: 0 : rxq->rdh_reg_addr = E1000_PCI_REG_ADDR(hw, E1000_RDH(rxq->reg_idx));
1323 : 0 : rxq->rx_ring_phys_addr = rz->iova;
1324 : 0 : rxq->rx_ring = (union e1000_adv_rx_desc *)rz->addr;
1325 : :
1326 : : /* Allocate software ring. */
1327 : 0 : rxq->sw_ring = rte_zmalloc("rxq->sw_ring",
1328 : : sizeof(struct igc_rx_entry) * nb_desc,
1329 : : RTE_CACHE_LINE_SIZE);
1330 [ # # ]: 0 : if (rxq->sw_ring == NULL) {
1331 : 0 : igc_rx_queue_release(rxq);
1332 : 0 : return -ENOMEM;
1333 : : }
1334 : :
1335 : 0 : PMD_DRV_LOG(DEBUG, "sw_ring=%p hw_ring=%p dma_addr=0x%" PRIx64,
1336 : : rxq->sw_ring, rxq->rx_ring, rxq->rx_ring_phys_addr);
1337 : :
1338 : 0 : dev->data->rx_queues[queue_idx] = rxq;
1339 : : igc_reset_rx_queue(rxq);
1340 : :
1341 : 0 : return 0;
1342 : : }
1343 : :
1344 : : /* prepare packets for transmit */
1345 : : uint16_t
1346 : 0 : eth_igc_prep_pkts(__rte_unused void *tx_queue, struct rte_mbuf **tx_pkts,
1347 : : uint16_t nb_pkts)
1348 : : {
1349 : : int i, ret;
1350 : : struct rte_mbuf *m;
1351 : :
1352 [ # # ]: 0 : for (i = 0; i < nb_pkts; i++) {
1353 : 0 : m = tx_pkts[i];
1354 : :
1355 : : /* Check some limitations for TSO in hardware */
1356 [ # # ]: 0 : if (m->ol_flags & IGC_TX_OFFLOAD_SEG)
1357 [ # # ]: 0 : if (m->tso_segsz > IGC_TSO_MAX_MSS ||
1358 [ # # ]: 0 : m->l2_len + m->l3_len + m->l4_len >
1359 : : IGC_TSO_MAX_HDRLEN) {
1360 : 0 : rte_errno = EINVAL;
1361 : 0 : return i;
1362 : : }
1363 : :
1364 [ # # ]: 0 : if (m->ol_flags & IGC_TX_OFFLOAD_NOTSUP_MASK) {
1365 : 0 : rte_errno = ENOTSUP;
1366 : 0 : return i;
1367 : : }
1368 : :
1369 : : #ifdef RTE_ETHDEV_DEBUG_TX
1370 : : ret = rte_validate_tx_offload(m);
1371 : : if (ret != 0) {
1372 : : rte_errno = -ret;
1373 : : return i;
1374 : : }
1375 : : #endif
1376 : : ret = rte_net_intel_cksum_prepare(m);
1377 [ # # ]: 0 : if (ret != 0) {
1378 : 0 : rte_errno = -ret;
1379 : 0 : return i;
1380 : : }
1381 : : }
1382 : :
1383 : 0 : return i;
1384 : : }
1385 : :
1386 : : /*
1387 : : *There're some limitations in hardware for TCP segmentation offload. We
1388 : : *should check whether the parameters are valid.
1389 : : */
1390 : : static inline uint64_t
1391 : : check_tso_para(uint64_t ol_req, union igc_tx_offload ol_para)
1392 : : {
1393 : 0 : if (!(ol_req & IGC_TX_OFFLOAD_SEG))
1394 : : return ol_req;
1395 [ # # ]: 0 : if (ol_para.tso_segsz > IGC_TSO_MAX_MSS || ol_para.l2_len +
1396 [ # # ]: 0 : ol_para.l3_len + ol_para.l4_len > IGC_TSO_MAX_HDRLEN) {
1397 : 0 : ol_req &= ~IGC_TX_OFFLOAD_SEG;
1398 : 0 : ol_req |= RTE_MBUF_F_TX_TCP_CKSUM;
1399 : : }
1400 : : return ol_req;
1401 : : }
1402 : :
1403 : : /*
1404 : : * Check which hardware context can be used. Use the existing match
1405 : : * or create a new context descriptor.
1406 : : */
1407 : : static inline uint32_t
1408 : 0 : what_advctx_update(struct igc_tx_queue *txq, uint64_t flags,
1409 : : union igc_tx_offload tx_offload)
1410 : : {
1411 : 0 : uint32_t curr = txq->ctx_curr;
1412 : :
1413 : : /* Launch time feature always need a new context descriptor */
1414 [ # # ]: 0 : if (flags & igc_tx_timestamp_dynflag)
1415 : : return IGC_CTX_NUM;
1416 : :
1417 : : /* If match with the current context */
1418 [ # # # # ]: 0 : if (likely(txq->ctx_cache[curr].flags == flags &&
1419 : : txq->ctx_cache[curr].tx_offload.data ==
1420 : : (txq->ctx_cache[curr].tx_offload_mask.data &
1421 : : tx_offload.data))) {
1422 : : return curr;
1423 : : }
1424 : :
1425 : : /* Total two context, if match with the second context */
1426 : 0 : curr ^= 1;
1427 [ # # # # ]: 0 : if (likely(txq->ctx_cache[curr].flags == flags &&
1428 : : txq->ctx_cache[curr].tx_offload.data ==
1429 : : (txq->ctx_cache[curr].tx_offload_mask.data &
1430 : : tx_offload.data))) {
1431 : 0 : txq->ctx_curr = curr;
1432 : 0 : return curr;
1433 : : }
1434 : :
1435 : : /* Mismatch, create new one */
1436 : : return IGC_CTX_NUM;
1437 : : }
1438 : :
1439 : : static uint32_t
1440 : 0 : igc_tx_launchtime(uint64_t txtime, struct igc_tx_queue *txq,
1441 : : bool *need_dummy_pkt, bool *need_frst_flag)
1442 : : {
1443 : 0 : struct rte_eth_dev *dev = &rte_eth_devices[txq->port_id];
1444 : 0 : struct igc_adapter *adapter = IGC_DEV_PRIVATE(dev);
1445 : : struct e1000_hw *hw = IGC_DEV_PRIVATE_HW(dev);
1446 : 0 : uint64_t cycle_time = adapter->cycle_time;
1447 : 0 : uint64_t base_time = adapter->base_time;
1448 : : uint64_t current_cycle_end;
1449 : : uint64_t cycles_elapsed;
1450 : : uint32_t launchtime;
1451 : : uint32_t nsec, sec;
1452 : : uint64_t systime;
1453 : :
1454 : : /*
1455 : : * Read current PTP hardware time from SYSTIM registers.
1456 : : * Reading the SYSTIML register latches the upper 32 bits to the SYSTIMH
1457 : : * shadow register for coherent access. As long as we read SYSTIML first
1458 : : * followed by SYSTIMH, we avoid race conditions where the time rolls
1459 : : * over between the two register reads.
1460 : : */
1461 : 0 : nsec = E1000_READ_REG(hw, E1000_SYSTIML);
1462 : 0 : sec = E1000_READ_REG(hw, E1000_SYSTIMH);
1463 : 0 : systime = (uint64_t)sec * NSEC_PER_SEC + (uint64_t)nsec;
1464 : :
1465 : : /* Calculate end time of current Qbv cycle */
1466 : 0 : cycles_elapsed = (systime - base_time) / cycle_time;
1467 : 0 : current_cycle_end = (cycles_elapsed + 1) * cycle_time + base_time;
1468 : :
1469 : : /* Set launchtime to 0 if txtime has expired or exceeds the horizon */
1470 [ # # # # ]: 0 : if (txtime <= systime || txtime >= current_cycle_end + cycle_time) {
1471 : 0 : txq->last_packet_cycle = current_cycle_end;
1472 : 0 : return 0;
1473 : : }
1474 : :
1475 : : /* Calculate launchtime to be inserted into Tx context descriptor */
1476 : 0 : launchtime = (txtime - base_time) % cycle_time;
1477 : :
1478 : : /* Handle txtime that fall into next Qbv cycle */
1479 [ # # ]: 0 : if (txtime >= current_cycle_end) {
1480 : : /* Only mark as first if the cycle hasn't had a first pkt yet */
1481 [ # # ]: 0 : if (txq->last_frst_flag != current_cycle_end) {
1482 : 0 : *need_frst_flag = true;
1483 : 0 : txq->last_frst_flag = current_cycle_end;
1484 : :
1485 : : /* Check if we need dummy pkt to dirty current cycle */
1486 [ # # ]: 0 : if (txq->last_packet_cycle < current_cycle_end)
1487 : 0 : *need_dummy_pkt = true;
1488 : : }
1489 : 0 : txq->last_packet_cycle = current_cycle_end + cycle_time;
1490 : : } else {
1491 : 0 : txq->last_packet_cycle = current_cycle_end;
1492 : : }
1493 : :
1494 : : return rte_cpu_to_le_32(launchtime);
1495 : : }
1496 : :
1497 : : /*
1498 : : * If the IGC_ADVTXD_TSN_CNTX_FRST flag is used to schedule a packet for the
1499 : : * next Qbv cycle while no packet was transmitted from that queue in the current
1500 : : * cycle, then the IGC_ADVTXD_TSN_CNTX_FRST flag may be valid in the current
1501 : : * cycle and the packet will be transmitted in the current cycle. To overcome
1502 : : * this issue, we transmit an IGC_DUMMY_PKT_SIZE byte "dummy" packet to "dirty"
1503 : : * the current cycle before sending the packet intended for the next cycle.
1504 : : */
1505 : : static void
1506 : 0 : igc_insert_dummy_packet(struct igc_tx_queue *txq, uint16_t *tx_id)
1507 : : {
1508 : 0 : volatile union e1000_adv_tx_desc * const txr = txq->tx_ring;
1509 : 0 : struct igc_tx_entry * const sw_ring = txq->sw_ring;
1510 : : volatile struct e1000_adv_tx_context_desc *ctx_txd;
1511 : : volatile union e1000_adv_tx_desc *txd;
1512 : : struct igc_tx_entry *txe, *txn;
1513 : :
1514 : : /* Get Tx entry (txe) for Tx context descriptor of dummy packet */
1515 : 0 : txe = &sw_ring[*tx_id];
1516 : :
1517 : : /* Prepare for next Tx entry (txn) */
1518 : 0 : txn = &sw_ring[txe->next_id];
1519 [ # # ]: 0 : RTE_MBUF_PREFETCH_TO_FREE(txn->mbuf);
1520 : :
1521 : : /* Set up Tx context descriptor for dummy packet */
1522 : 0 : ctx_txd = (volatile struct e1000_adv_tx_context_desc *)&txr[*tx_id];
1523 : 0 : ctx_txd->type_tucmd_mlhl = rte_cpu_to_le_32(E1000_ADVTXD_DTYP_CTXT |
1524 : : E1000_ADVTXD_DCMD_DEXT);
1525 : 0 : ctx_txd->mss_l4len_idx = rte_cpu_to_le_32(txq->ctx_curr <<
1526 : : E1000_ADVTXD_IDX_SHIFT);
1527 : 0 : ctx_txd->vlan_macip_lens = 0;
1528 : 0 : ctx_txd->u.launch_time = 0;
1529 : :
1530 : : /* Update tx_id and last_id */
1531 : 0 : *tx_id = txe->next_id;
1532 : 0 : txe->last_id = *tx_id;
1533 : :
1534 : : /* Get Tx entry (txe) for Tx data descriptor of dummy packet */
1535 : : txe = txn;
1536 : :
1537 : : /* Prepare for next Tx entry (txn) */
1538 : 0 : txn = &sw_ring[txe->next_id];
1539 [ # # ]: 0 : RTE_MBUF_PREFETCH_TO_FREE(txn->mbuf);
1540 : :
1541 : : /* Free previous mbuf */
1542 [ # # ]: 0 : if (txe->mbuf != NULL) {
1543 : : rte_pktmbuf_free_seg(txe->mbuf);
1544 : 0 : txe->mbuf = NULL;
1545 : : }
1546 : :
1547 : : /* Set up Tx data descriptor for dummy packet */
1548 : 0 : txd = &txr[*tx_id];
1549 : 0 : txd->read.buffer_addr = rte_cpu_to_le_64(txq->dummy_pkt_dma);
1550 : 0 : txd->read.cmd_type_len = rte_cpu_to_le_32(txq->txd_type |
1551 : : IGC_DUMMY_PKT_SIZE | E1000_ADVTXD_DCMD_IFCS |
1552 : : E1000_ADVTXD_DCMD_DEXT | E1000_TXD_CMD_EOP |
1553 : : E1000_TXD_CMD_RS);
1554 : 0 : txd->read.olinfo_status = rte_cpu_to_le_32(IGC_DUMMY_PKT_SIZE <<
1555 : : E1000_ADVTXD_PAYLEN_SHIFT);
1556 : :
1557 : : /* Update last_id and tx_id */
1558 : 0 : txe->last_id = *tx_id;
1559 : 0 : *tx_id = txe->next_id;
1560 : :
1561 : : /* Get Tx entry (txe) for Tx context descriptor of actual packet */
1562 : : txe = txn;
1563 : :
1564 : : /* Prepare for next Tx entry (txn) */
1565 : 0 : txn = &sw_ring[txe->next_id];
1566 [ # # ]: 0 : RTE_MBUF_PREFETCH_TO_FREE(txn->mbuf);
1567 : :
1568 : : /* Free previous mbuf */
1569 [ # # ]: 0 : if (txe->mbuf != NULL) {
1570 : : rte_pktmbuf_free_seg(txe->mbuf);
1571 : 0 : txe->mbuf = NULL;
1572 : : }
1573 : :
1574 : : /* Update ctx_curr */
1575 : 0 : txq->ctx_curr ^= 1;
1576 : 0 : }
1577 : :
1578 : : /*
1579 : : * This is a separate function, looking for optimization opportunity here
1580 : : * Rework required to go with the pre-defined values.
1581 : : */
1582 : : static inline void
1583 : 0 : igc_set_xmit_ctx(struct igc_tx_queue *txq, uint16_t *tx_id,
1584 : : uint64_t ol_flags, union igc_tx_offload tx_offload,
1585 : : uint64_t txtime, uint16_t tx_last)
1586 : : {
1587 : 0 : volatile union e1000_adv_tx_desc * const txr = txq->tx_ring;
1588 : 0 : struct igc_tx_entry * const sw_ring = txq->sw_ring;
1589 : : volatile struct e1000_adv_tx_context_desc *ctx_txd;
1590 : : struct igc_tx_entry *txe;
1591 : : uint32_t type_tucmd_mlhl;
1592 : : uint32_t mss_l4len_idx = 0;
1593 : : uint32_t ctx_curr;
1594 : : uint32_t vlan_macip_lens;
1595 : : union igc_tx_offload tx_offload_mask;
1596 : 0 : bool need_frst_flag = false;
1597 : 0 : bool need_dummy_pkt = false;
1598 : : uint32_t launch_time = 0;
1599 : :
1600 : : /* Use the previous context */
1601 : 0 : txq->ctx_curr ^= 1;
1602 : 0 : ctx_curr = txq->ctx_curr;
1603 : :
1604 : 0 : tx_offload_mask.data = 0;
1605 : : type_tucmd_mlhl = 0;
1606 : :
1607 [ # # ]: 0 : if (ol_flags & RTE_MBUF_F_TX_VLAN)
1608 : 0 : tx_offload_mask.vlan_tci = 0xffff;
1609 : :
1610 : : /* check if TCP segmentation required for this packet */
1611 [ # # ]: 0 : if (ol_flags & IGC_TX_OFFLOAD_SEG) {
1612 : : /* implies IP cksum in IPv4 */
1613 [ # # ]: 0 : if (ol_flags & RTE_MBUF_F_TX_IP_CKSUM)
1614 : : type_tucmd_mlhl = E1000_ADVTXD_TUCMD_IPV4 |
1615 : : E1000_ADVTXD_DTYP_CTXT | E1000_ADVTXD_DCMD_DEXT;
1616 : : else
1617 : : type_tucmd_mlhl = E1000_ADVTXD_TUCMD_IPV6 |
1618 : : E1000_ADVTXD_DTYP_CTXT | E1000_ADVTXD_DCMD_DEXT;
1619 : :
1620 [ # # ]: 0 : if (ol_flags & RTE_MBUF_F_TX_TCP_SEG)
1621 : 0 : type_tucmd_mlhl |= E1000_ADVTXD_TUCMD_L4T_TCP;
1622 : : else
1623 : : type_tucmd_mlhl |= E1000_ADVTXD_TUCMD_L4T_UDP;
1624 : :
1625 : 0 : tx_offload_mask.data |= TX_TSO_CMP_MASK;
1626 : 0 : mss_l4len_idx |= (uint32_t)tx_offload.tso_segsz <<
1627 : : E1000_ADVTXD_MSS_SHIFT;
1628 : 0 : mss_l4len_idx |= (uint32_t)tx_offload.l4_len <<
1629 : : E1000_ADVTXD_L4LEN_SHIFT;
1630 : : } else { /* no TSO, check if hardware checksum is needed */
1631 [ # # ]: 0 : if (ol_flags & (RTE_MBUF_F_TX_IP_CKSUM | RTE_MBUF_F_TX_L4_MASK))
1632 : 0 : tx_offload_mask.data |= TX_MACIP_LEN_CMP_MASK;
1633 : :
1634 [ # # ]: 0 : if (ol_flags & RTE_MBUF_F_TX_IP_CKSUM)
1635 : : type_tucmd_mlhl = E1000_ADVTXD_TUCMD_IPV4;
1636 : :
1637 [ # # # # ]: 0 : switch (ol_flags & RTE_MBUF_F_TX_L4_MASK) {
1638 : 0 : case RTE_MBUF_F_TX_TCP_CKSUM:
1639 : 0 : type_tucmd_mlhl |= E1000_ADVTXD_TUCMD_L4T_TCP |
1640 : : E1000_ADVTXD_DTYP_CTXT | E1000_ADVTXD_DCMD_DEXT;
1641 : : mss_l4len_idx |= (uint32_t)sizeof(struct rte_tcp_hdr)
1642 : : << E1000_ADVTXD_L4LEN_SHIFT;
1643 : 0 : break;
1644 : 0 : case RTE_MBUF_F_TX_UDP_CKSUM:
1645 : 0 : type_tucmd_mlhl |= E1000_ADVTXD_TUCMD_L4T_UDP |
1646 : : E1000_ADVTXD_DTYP_CTXT | E1000_ADVTXD_DCMD_DEXT;
1647 : : mss_l4len_idx |= (uint32_t)sizeof(struct rte_udp_hdr)
1648 : : << E1000_ADVTXD_L4LEN_SHIFT;
1649 : 0 : break;
1650 : 0 : case RTE_MBUF_F_TX_SCTP_CKSUM:
1651 : 0 : type_tucmd_mlhl |= E1000_ADVTXD_TUCMD_L4T_SCTP |
1652 : : E1000_ADVTXD_DTYP_CTXT | E1000_ADVTXD_DCMD_DEXT;
1653 : : mss_l4len_idx |= (uint32_t)sizeof(struct rte_sctp_hdr)
1654 : : << E1000_ADVTXD_L4LEN_SHIFT;
1655 : 0 : break;
1656 : 0 : default:
1657 : 0 : type_tucmd_mlhl |= IGC_ADVTXD_TUCMD_L4T_RSV |
1658 : : E1000_ADVTXD_DTYP_CTXT | E1000_ADVTXD_DCMD_DEXT;
1659 : 0 : break;
1660 : : }
1661 : : }
1662 : :
1663 [ # # ]: 0 : if (!txtime) {
1664 : 0 : txq->ctx_cache[ctx_curr].flags = ol_flags;
1665 : 0 : txq->ctx_cache[ctx_curr].tx_offload.data =
1666 : 0 : tx_offload_mask.data & tx_offload.data;
1667 : 0 : txq->ctx_cache[ctx_curr].tx_offload_mask = tx_offload_mask;
1668 : : } else {
1669 : 0 : launch_time = igc_tx_launchtime(txtime, txq, &need_dummy_pkt,
1670 : : &need_frst_flag);
1671 : : }
1672 : :
1673 [ # # ]: 0 : if (need_frst_flag)
1674 : 0 : mss_l4len_idx |= IGC_ADVTXD_TSN_CNTX_FRST;
1675 : :
1676 [ # # ]: 0 : if (need_dummy_pkt)
1677 : 0 : igc_insert_dummy_packet(txq, tx_id);
1678 : :
1679 : : /* Specify which HW CTX to upload. */
1680 : 0 : mss_l4len_idx |= (txq->ctx_curr << E1000_ADVTXD_IDX_SHIFT);
1681 : :
1682 : : /* Set up Tx context descriptor */
1683 : 0 : ctx_txd = (volatile struct e1000_adv_tx_context_desc *)&txr[*tx_id];
1684 : 0 : ctx_txd->type_tucmd_mlhl = rte_cpu_to_le_32(type_tucmd_mlhl);
1685 : 0 : vlan_macip_lens = (uint32_t)tx_offload.data;
1686 : 0 : ctx_txd->vlan_macip_lens = rte_cpu_to_le_32(vlan_macip_lens);
1687 : 0 : ctx_txd->mss_l4len_idx = rte_cpu_to_le_32(mss_l4len_idx);
1688 : 0 : ctx_txd->u.launch_time = launch_time;
1689 : :
1690 : : /* Update last_id and tx_id */
1691 : 0 : txe = &sw_ring[*tx_id];
1692 : 0 : txe->last_id = tx_last;
1693 : 0 : *tx_id = txe->next_id;
1694 : 0 : }
1695 : :
1696 : : static inline uint32_t
1697 : : tx_desc_vlan_flags_to_cmdtype(uint64_t ol_flags)
1698 : : {
1699 : : uint32_t cmdtype;
1700 : : static uint32_t vlan_cmd[2] = {0, E1000_ADVTXD_DCMD_VLE};
1701 : : static uint32_t tso_cmd[2] = {0, E1000_ADVTXD_DCMD_TSE};
1702 : 0 : cmdtype = vlan_cmd[(ol_flags & RTE_MBUF_F_TX_VLAN) != 0];
1703 : 0 : cmdtype |= tso_cmd[(ol_flags & IGC_TX_OFFLOAD_SEG) != 0];
1704 : : return cmdtype;
1705 : : }
1706 : :
1707 : : static inline uint32_t
1708 : : tx_desc_cksum_flags_to_olinfo(uint64_t ol_flags)
1709 : : {
1710 : : static const uint32_t l4_olinfo[2] = {0, IGC_ADVTXD_POPTS_TXSM};
1711 : : static const uint32_t l3_olinfo[2] = {0, IGC_ADVTXD_POPTS_IXSM};
1712 : : uint32_t tmp;
1713 : :
1714 : 0 : tmp = l4_olinfo[(ol_flags & RTE_MBUF_F_TX_L4_MASK) != RTE_MBUF_F_TX_L4_NO_CKSUM];
1715 : 0 : tmp |= l3_olinfo[(ol_flags & RTE_MBUF_F_TX_IP_CKSUM) != 0];
1716 : 0 : tmp |= l4_olinfo[(ol_flags & IGC_TX_OFFLOAD_SEG) != 0];
1717 : : return tmp;
1718 : : }
1719 : :
1720 : : uint16_t
1721 : 0 : igc_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
1722 : : {
1723 : : struct igc_tx_queue * const txq = tx_queue;
1724 : 0 : struct igc_tx_entry * const sw_ring = txq->sw_ring;
1725 : : struct igc_tx_entry *txe, *txn;
1726 : 0 : volatile union e1000_adv_tx_desc * const txr = txq->tx_ring;
1727 : : volatile union e1000_adv_tx_desc *txd;
1728 : : struct rte_mbuf *tx_pkt;
1729 : : struct rte_mbuf *m_seg;
1730 : : uint64_t buf_dma_addr;
1731 : : uint32_t olinfo_status;
1732 : : uint32_t cmd_type_len;
1733 : : uint32_t pkt_len;
1734 : : uint16_t slen;
1735 : : uint64_t ol_flags;
1736 : : uint16_t tx_end;
1737 : : uint16_t tx_id;
1738 : : uint16_t tx_last;
1739 : : uint16_t nb_tx;
1740 : : uint64_t tx_ol_req;
1741 : : uint32_t new_ctx = 0;
1742 : 0 : union igc_tx_offload tx_offload = {0};
1743 : : uint64_t ts = 0;
1744 : :
1745 : 0 : tx_id = txq->tx_tail;
1746 : 0 : txe = &sw_ring[tx_id];
1747 : :
1748 [ # # ]: 0 : for (nb_tx = 0; nb_tx < nb_pkts; nb_tx++) {
1749 : 0 : tx_pkt = *tx_pkts++;
1750 : 0 : pkt_len = tx_pkt->pkt_len;
1751 : :
1752 [ # # ]: 0 : RTE_MBUF_PREFETCH_TO_FREE(txe->mbuf);
1753 : :
1754 : : /*
1755 : : * The number of descriptors that must be allocated for a
1756 : : * packet is the number of segments of that packet, plus 1
1757 : : * Context Descriptor for the VLAN Tag Identifier, if any.
1758 : : * Determine the last TX descriptor to allocate in the TX ring
1759 : : * for the packet, starting from the current position (tx_id)
1760 : : * in the ring.
1761 : : */
1762 : 0 : tx_last = (uint16_t)(tx_id + tx_pkt->nb_segs - 1);
1763 : :
1764 : 0 : ol_flags = tx_pkt->ol_flags;
1765 : 0 : tx_ol_req = ol_flags & (IGC_TX_OFFLOAD_MASK |
1766 : : igc_tx_timestamp_dynflag);
1767 : :
1768 : : /* If a Context Descriptor need be built . */
1769 [ # # ]: 0 : if (tx_ol_req) {
1770 : 0 : tx_offload.l2_len = tx_pkt->l2_len;
1771 : 0 : tx_offload.l3_len = tx_pkt->l3_len;
1772 : 0 : tx_offload.l4_len = tx_pkt->l4_len;
1773 : 0 : tx_offload.vlan_tci = tx_pkt->vlan_tci;
1774 [ # # ]: 0 : tx_offload.tso_segsz = tx_pkt->tso_segsz;
1775 : : tx_ol_req = check_tso_para(tx_ol_req, tx_offload);
1776 : :
1777 : 0 : new_ctx = what_advctx_update(txq, tx_ol_req,
1778 : : tx_offload);
1779 : : /* Only allocate context descriptor if required*/
1780 : 0 : new_ctx = (new_ctx >= IGC_CTX_NUM);
1781 : 0 : tx_last = (uint16_t)(tx_last + new_ctx);
1782 : : }
1783 [ # # ]: 0 : if (tx_last >= txq->nb_tx_desc)
1784 : 0 : tx_last = (uint16_t)(tx_last - txq->nb_tx_desc);
1785 : :
1786 : : PMD_TX_LOG(DEBUG,
1787 : : "port_id=%u queue_id=%u pktlen=%u tx_first=%u tx_last=%u",
1788 : : txq->port_id, txq->queue_id, pkt_len, tx_id, tx_last);
1789 : :
1790 : : /*
1791 : : * Check if there are enough free descriptors in the TX ring
1792 : : * to transmit the next packet.
1793 : : * This operation is based on the three following rules:
1794 : : *
1795 : : * 1- Only check that the last needed TX descriptor can be
1796 : : * allocated (by construction, if that descriptor is free,
1797 : : * all intermediate ones are also free).
1798 : : *
1799 : : * For this purpose, the index of the last TX descriptor
1800 : : * used for a packet (the "last descriptor" of a packet)
1801 : : * is recorded in the TX entries (the last one included)
1802 : : * that are associated with all TX descriptors allocated
1803 : : * for that packet.
1804 : : *
1805 : : * 2- Avoid to allocate the last free TX descriptor of the
1806 : : * ring, in order to never set the TDT register with the
1807 : : * same value stored in parallel by the NIC in the TDH
1808 : : * register, which makes the TX engine of the NIC enter
1809 : : * in a deadlock situation.
1810 : : *
1811 : : * By extension, avoid to allocate a free descriptor that
1812 : : * belongs to the last set of free descriptors allocated
1813 : : * to the same packet previously transmitted.
1814 : : *
1815 : : * 3- Make sure there are two extra descriptors available in
1816 : : * the ring, in case a dummy packet is needed to dirty the
1817 : : * current Qbv cycle when using launch time feature.
1818 : : */
1819 : :
1820 : : /*
1821 : : * The "last descriptor" of the previously sent packet, if any,
1822 : : * which used the last descriptor to allocate.
1823 : : */
1824 : 0 : tx_end = (uint16_t)(tx_last + 2);
1825 [ # # ]: 0 : if (tx_end >= txq->nb_tx_desc)
1826 : 0 : tx_end = (uint16_t)(tx_end - txq->nb_tx_desc);
1827 : :
1828 : 0 : tx_end = sw_ring[tx_end].last_id;
1829 : :
1830 : : /*
1831 : : * The next descriptor following that "last descriptor" in the
1832 : : * ring.
1833 : : */
1834 : 0 : tx_end = sw_ring[tx_end].next_id;
1835 : :
1836 : : /*
1837 : : * The "last descriptor" associated with that next descriptor.
1838 : : */
1839 : 0 : tx_end = sw_ring[tx_end].last_id;
1840 : :
1841 : : /*
1842 : : * Check that this descriptor is free.
1843 : : */
1844 [ # # ]: 0 : if (!(txr[tx_end].wb.status & E1000_TXD_STAT_DD)) {
1845 [ # # ]: 0 : if (nb_tx == 0)
1846 : : return 0;
1847 : 0 : goto end_of_tx;
1848 : : }
1849 : :
1850 : : /*
1851 : : * Set common flags of all TX Data Descriptors.
1852 : : *
1853 : : * The following bits must be set in all Data Descriptors:
1854 : : * - E1000_ADVTXD_DTYP_DATA
1855 : : * - E1000_ADVTXD_DCMD_DEXT
1856 : : *
1857 : : * The following bits must be set in the first Data Descriptor
1858 : : * and are ignored in the other ones:
1859 : : * - E1000_ADVTXD_DCMD_IFCS
1860 : : * - E1000_ADVTXD_MAC_1588
1861 : : * - E1000_ADVTXD_DCMD_VLE
1862 : : *
1863 : : * The following bits must only be set in the last Data
1864 : : * Descriptor:
1865 : : * - E1000_TXD_CMD_EOP
1866 : : *
1867 : : * The following bits can be set in any Data Descriptor, but
1868 : : * are only set in the last Data Descriptor:
1869 : : * - E1000_TXD_CMD_RS
1870 : : */
1871 : 0 : cmd_type_len = txq->txd_type |
1872 : : E1000_ADVTXD_DCMD_IFCS | E1000_ADVTXD_DCMD_DEXT;
1873 [ # # ]: 0 : if (tx_ol_req & IGC_TX_OFFLOAD_SEG)
1874 : 0 : pkt_len -= (tx_pkt->l2_len + tx_pkt->l3_len +
1875 : 0 : tx_pkt->l4_len);
1876 : 0 : olinfo_status = (pkt_len << E1000_ADVTXD_PAYLEN_SHIFT);
1877 : :
1878 : : /*
1879 : : * Timer 0 should be used to for packet timestamping,
1880 : : * sample the packet timestamp to reg 0
1881 : : */
1882 [ # # ]: 0 : if (ol_flags & RTE_MBUF_F_TX_IEEE1588_TMST)
1883 : 0 : cmd_type_len |= E1000_ADVTXD_MAC_TSTAMP;
1884 : :
1885 [ # # ]: 0 : if (tx_ol_req) {
1886 : : /* Setup TX Advanced context descriptor if required */
1887 [ # # ]: 0 : if (new_ctx) {
1888 : 0 : txn = &sw_ring[txe->next_id];
1889 [ # # ]: 0 : RTE_MBUF_PREFETCH_TO_FREE(txn->mbuf);
1890 : :
1891 [ # # ]: 0 : if (txe->mbuf != NULL) {
1892 : : rte_pktmbuf_free_seg(txe->mbuf);
1893 : 0 : txe->mbuf = NULL;
1894 : : }
1895 : :
1896 [ # # ]: 0 : if (igc_tx_timestamp_dynflag > 0)
1897 : 0 : ts = *RTE_MBUF_DYNFIELD(tx_pkt,
1898 : : igc_tx_timestamp_dynfield_offset,
1899 : : uint64_t *);
1900 : :
1901 : 0 : igc_set_xmit_ctx(txq, &tx_id, tx_ol_req,
1902 : : tx_offload, ts, tx_last);
1903 : :
1904 : 0 : txe = &sw_ring[tx_id];
1905 : : }
1906 : :
1907 : : /* Setup the TX Advanced Data Descriptor */
1908 : 0 : cmd_type_len |=
1909 : : tx_desc_vlan_flags_to_cmdtype(tx_ol_req);
1910 : 0 : olinfo_status |=
1911 : : tx_desc_cksum_flags_to_olinfo(tx_ol_req);
1912 : 0 : olinfo_status |= (uint32_t)txq->ctx_curr <<
1913 : : E1000_ADVTXD_IDX_SHIFT;
1914 : : }
1915 : :
1916 : : m_seg = tx_pkt;
1917 : : do {
1918 : 0 : txn = &sw_ring[txe->next_id];
1919 [ # # ]: 0 : RTE_MBUF_PREFETCH_TO_FREE(txn->mbuf);
1920 : :
1921 : 0 : txd = &txr[tx_id];
1922 : :
1923 [ # # ]: 0 : if (txe->mbuf != NULL)
1924 : : rte_pktmbuf_free_seg(txe->mbuf);
1925 : 0 : txe->mbuf = m_seg;
1926 : :
1927 : : /* Set up transmit descriptor */
1928 [ # # ]: 0 : slen = (uint16_t)m_seg->data_len;
1929 : : buf_dma_addr = rte_mbuf_data_iova(m_seg);
1930 : 0 : txd->read.buffer_addr =
1931 : : rte_cpu_to_le_64(buf_dma_addr);
1932 : 0 : txd->read.cmd_type_len =
1933 : 0 : rte_cpu_to_le_32(cmd_type_len | slen);
1934 : 0 : txd->read.olinfo_status =
1935 : : rte_cpu_to_le_32(olinfo_status);
1936 : 0 : txe->last_id = tx_last;
1937 : 0 : tx_id = txe->next_id;
1938 : : txe = txn;
1939 : 0 : m_seg = m_seg->next;
1940 [ # # ]: 0 : } while (m_seg != NULL);
1941 : :
1942 : : /*
1943 : : * The last packet data descriptor needs End Of Packet (EOP)
1944 : : * and Report Status (RS).
1945 : : */
1946 : 0 : txd->read.cmd_type_len |=
1947 : : rte_cpu_to_le_32(E1000_TXD_CMD_EOP | E1000_TXD_CMD_RS);
1948 : : }
1949 : 0 : end_of_tx:
1950 : : rte_wmb();
1951 : :
1952 : : /*
1953 : : * Set the Transmit Descriptor Tail (TDT).
1954 : : */
1955 : 0 : E1000_PCI_REG_WRITE_RELAXED(txq->tdt_reg_addr, tx_id);
1956 : : PMD_TX_LOG(DEBUG, "port_id=%u queue_id=%u tx_tail=%u nb_tx=%u",
1957 : : txq->port_id, txq->queue_id, tx_id, nb_tx);
1958 : 0 : txq->tx_tail = tx_id;
1959 : :
1960 : 0 : return nb_tx;
1961 : : }
1962 : :
1963 : 0 : int eth_igc_tx_descriptor_status(void *tx_queue, uint16_t offset)
1964 : : {
1965 : : struct igc_tx_queue *txq = tx_queue;
1966 : : volatile uint32_t *status;
1967 : : uint32_t desc;
1968 : :
1969 [ # # # # ]: 0 : if (unlikely(!txq || offset >= txq->nb_tx_desc))
1970 : : return -EINVAL;
1971 : :
1972 : 0 : desc = txq->tx_tail + offset;
1973 [ # # ]: 0 : if (desc >= txq->nb_tx_desc)
1974 : 0 : desc -= txq->nb_tx_desc;
1975 : :
1976 : 0 : status = &txq->tx_ring[desc].wb.status;
1977 [ # # ]: 0 : if (*status & rte_cpu_to_le_32(E1000_TXD_STAT_DD))
1978 : 0 : return RTE_ETH_TX_DESC_DONE;
1979 : :
1980 : : return RTE_ETH_TX_DESC_FULL;
1981 : : }
1982 : :
1983 : : static void
1984 : 0 : igc_tx_queue_release_mbufs(struct igc_tx_queue *txq)
1985 : : {
1986 : : unsigned int i;
1987 : :
1988 [ # # ]: 0 : if (txq->sw_ring != NULL) {
1989 [ # # ]: 0 : for (i = 0; i < txq->nb_tx_desc; i++) {
1990 [ # # ]: 0 : if (txq->sw_ring[i].mbuf != NULL) {
1991 : : rte_pktmbuf_free_seg(txq->sw_ring[i].mbuf);
1992 : 0 : txq->sw_ring[i].mbuf = NULL;
1993 : : }
1994 : : }
1995 : : }
1996 : 0 : }
1997 : :
1998 : : static void
1999 : 0 : igc_tx_queue_release(struct igc_tx_queue *txq)
2000 : : {
2001 : 0 : igc_tx_queue_release_mbufs(txq);
2002 : 0 : rte_free(txq->dummy_pkt_buf);
2003 : 0 : rte_free(txq->sw_ring);
2004 : 0 : rte_free(txq);
2005 : 0 : }
2006 : :
2007 : 0 : void eth_igc_tx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
2008 : : {
2009 [ # # ]: 0 : if (dev->data->tx_queues[qid])
2010 : 0 : igc_tx_queue_release(dev->data->tx_queues[qid]);
2011 : 0 : }
2012 : :
2013 : : static void
2014 : : igc_reset_tx_queue_stat(struct igc_tx_queue *txq)
2015 : : {
2016 : 0 : txq->tx_head = 0;
2017 : 0 : txq->tx_tail = 0;
2018 : 0 : txq->ctx_curr = 0;
2019 : 0 : memset((void *)&txq->ctx_cache, 0,
2020 : : IGC_CTX_NUM * sizeof(struct igc_advctx_info));
2021 : : }
2022 : :
2023 : : static void
2024 : 0 : igc_reset_tx_queue(struct igc_tx_queue *txq)
2025 : : {
2026 : 0 : struct igc_tx_entry *txe = txq->sw_ring;
2027 : : uint16_t i, prev;
2028 : :
2029 : : /* Initialize ring entries */
2030 : 0 : prev = (uint16_t)(txq->nb_tx_desc - 1);
2031 [ # # ]: 0 : for (i = 0; i < txq->nb_tx_desc; i++) {
2032 : 0 : volatile union e1000_adv_tx_desc *txd = &txq->tx_ring[i];
2033 : :
2034 : 0 : txd->wb.status = E1000_TXD_STAT_DD;
2035 : 0 : txe[i].mbuf = NULL;
2036 : 0 : txe[i].last_id = i;
2037 : 0 : txe[prev].next_id = i;
2038 : : prev = i;
2039 : : }
2040 : :
2041 : 0 : txq->txd_type = E1000_ADVTXD_DTYP_DATA;
2042 : : igc_reset_tx_queue_stat(txq);
2043 : 0 : }
2044 : :
2045 : : /*
2046 : : * clear all rx/tx queue
2047 : : */
2048 : : void
2049 : 0 : igc_dev_clear_queues(struct rte_eth_dev *dev)
2050 : : {
2051 : : uint16_t i;
2052 : : struct igc_tx_queue *txq;
2053 : : struct igc_rx_queue *rxq;
2054 : :
2055 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
2056 : 0 : txq = dev->data->tx_queues[i];
2057 [ # # ]: 0 : if (txq != NULL) {
2058 : 0 : igc_tx_queue_release_mbufs(txq);
2059 : 0 : igc_reset_tx_queue(txq);
2060 : 0 : dev->data->tx_queue_state[i] = RTE_ETH_QUEUE_STATE_STOPPED;
2061 : : }
2062 : : }
2063 : :
2064 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
2065 : 0 : rxq = dev->data->rx_queues[i];
2066 [ # # ]: 0 : if (rxq != NULL) {
2067 : 0 : igc_rx_queue_release_mbufs(rxq);
2068 : : igc_reset_rx_queue(rxq);
2069 : 0 : dev->data->rx_queue_state[i] = RTE_ETH_QUEUE_STATE_STOPPED;
2070 : : }
2071 : : }
2072 : 0 : }
2073 : :
2074 : 0 : int eth_igc_tx_queue_setup(struct rte_eth_dev *dev, uint16_t queue_idx,
2075 : : uint16_t nb_desc, unsigned int socket_id,
2076 : : const struct rte_eth_txconf *tx_conf)
2077 : : {
2078 : : const struct rte_memzone *tz;
2079 : : struct igc_tx_queue *txq;
2080 : : struct e1000_hw *hw;
2081 : : uint32_t size;
2082 : :
2083 [ # # ]: 0 : if (nb_desc % IGC_TX_DESCRIPTOR_MULTIPLE != 0 ||
2084 [ # # ]: 0 : nb_desc > IGC_MAX_TXD || nb_desc < IGC_MIN_TXD) {
2085 : 0 : PMD_DRV_LOG(ERR,
2086 : : "TX-descriptor must be a multiple of %u and between %u and %u, cur: %u",
2087 : : IGC_TX_DESCRIPTOR_MULTIPLE,
2088 : : IGC_MAX_TXD, IGC_MIN_TXD, nb_desc);
2089 : 0 : return -EINVAL;
2090 : : }
2091 : :
2092 : 0 : hw = IGC_DEV_PRIVATE_HW(dev);
2093 : :
2094 : : /*
2095 : : * The tx_free_thresh and tx_rs_thresh values are not used in the 2.5G
2096 : : * driver.
2097 : : */
2098 [ # # ]: 0 : if (tx_conf->tx_free_thresh != 0)
2099 : 0 : PMD_DRV_LOG(INFO,
2100 : : "The tx_free_thresh parameter is not used for the 2.5G driver");
2101 [ # # ]: 0 : if (tx_conf->tx_rs_thresh != 0)
2102 : 0 : PMD_DRV_LOG(INFO,
2103 : : "The tx_rs_thresh parameter is not used for the 2.5G driver");
2104 [ # # ]: 0 : if (tx_conf->tx_thresh.wthresh == 0)
2105 : 0 : PMD_DRV_LOG(INFO,
2106 : : "To improve 2.5G driver performance, consider setting the TX WTHRESH value to 4, 8, or 16.");
2107 : :
2108 : : /* Free memory prior to re-allocation if needed */
2109 [ # # ]: 0 : if (dev->data->tx_queues[queue_idx] != NULL) {
2110 : 0 : igc_tx_queue_release(dev->data->tx_queues[queue_idx]);
2111 : 0 : dev->data->tx_queues[queue_idx] = NULL;
2112 : : }
2113 : :
2114 : : /* First allocate the tx queue data structure */
2115 : 0 : txq = rte_zmalloc("ethdev TX queue", sizeof(struct igc_tx_queue),
2116 : : RTE_CACHE_LINE_SIZE);
2117 [ # # ]: 0 : if (txq == NULL)
2118 : : return -ENOMEM;
2119 : :
2120 : : /*
2121 : : * Allocate TX ring hardware descriptors. A memzone large enough to
2122 : : * handle the maximum ring size is allocated in order to allow for
2123 : : * resizing in later calls to the queue setup function.
2124 : : */
2125 : : size = sizeof(union e1000_adv_tx_desc) * IGC_MAX_TXD;
2126 : 0 : tz = rte_eth_dma_zone_reserve(dev, "tx_ring", queue_idx, size,
2127 : : IGC_ALIGN, socket_id);
2128 [ # # ]: 0 : if (tz == NULL) {
2129 : 0 : igc_tx_queue_release(txq);
2130 : 0 : return -ENOMEM;
2131 : : }
2132 : :
2133 : 0 : txq->nb_tx_desc = nb_desc;
2134 : 0 : txq->pthresh = tx_conf->tx_thresh.pthresh;
2135 : 0 : txq->hthresh = tx_conf->tx_thresh.hthresh;
2136 : 0 : txq->wthresh = tx_conf->tx_thresh.wthresh;
2137 : :
2138 : 0 : txq->queue_id = queue_idx;
2139 : 0 : txq->reg_idx = queue_idx;
2140 : 0 : txq->port_id = dev->data->port_id;
2141 : :
2142 [ # # ]: 0 : txq->tdt_reg_addr = E1000_PCI_REG_ADDR(hw, E1000_TDT(txq->reg_idx));
2143 : 0 : txq->tx_ring_phys_addr = tz->iova;
2144 : :
2145 : 0 : txq->tx_ring = (union e1000_adv_tx_desc *)tz->addr;
2146 : : /* Allocate software ring */
2147 : 0 : txq->sw_ring = rte_zmalloc("txq->sw_ring",
2148 : : sizeof(struct igc_tx_entry) * nb_desc,
2149 : : RTE_CACHE_LINE_SIZE);
2150 [ # # ]: 0 : if (txq->sw_ring == NULL) {
2151 : 0 : igc_tx_queue_release(txq);
2152 : 0 : return -ENOMEM;
2153 : : }
2154 : 0 : PMD_DRV_LOG(DEBUG, "sw_ring=%p hw_ring=%p dma_addr=0x%" PRIx64,
2155 : : txq->sw_ring, txq->tx_ring, txq->tx_ring_phys_addr);
2156 : :
2157 : : /* Allocate dummy packet buffer */
2158 : 0 : txq->dummy_pkt_buf = rte_zmalloc("dummy_pkt", IGC_DUMMY_PKT_SIZE,
2159 : : RTE_CACHE_LINE_SIZE);
2160 [ # # ]: 0 : if (txq->dummy_pkt_buf == NULL) {
2161 : 0 : igc_tx_queue_release(txq);
2162 : 0 : return -ENOMEM;
2163 : : }
2164 : :
2165 : 0 : txq->dummy_pkt_dma = rte_mem_virt2iova(txq->dummy_pkt_buf);
2166 [ # # ]: 0 : if (txq->dummy_pkt_dma == RTE_BAD_IOVA) {
2167 : 0 : PMD_DRV_LOG(ERR, "Failed to get DMA address for dummy packet");
2168 : 0 : igc_tx_queue_release(txq);
2169 : 0 : return -ENOMEM;
2170 : : }
2171 : :
2172 : 0 : igc_reset_tx_queue(txq);
2173 : 0 : dev->tx_pkt_burst = igc_xmit_pkts;
2174 : 0 : dev->tx_pkt_prepare = ð_igc_prep_pkts;
2175 : 0 : dev->data->tx_queues[queue_idx] = txq;
2176 : 0 : txq->offloads = tx_conf->offloads;
2177 : :
2178 : 0 : return 0;
2179 : : }
2180 : :
2181 : : int
2182 : 0 : eth_igc_tx_done_cleanup(void *txqueue, uint32_t free_cnt)
2183 : : {
2184 : : struct igc_tx_queue *txq = txqueue;
2185 : : struct igc_tx_entry *sw_ring;
2186 : : volatile union e1000_adv_tx_desc *txr;
2187 : : uint16_t tx_first; /* First segment analyzed. */
2188 : : uint16_t tx_id; /* Current segment being processed. */
2189 : : uint16_t tx_last; /* Last segment in the current packet. */
2190 : : uint16_t tx_next; /* First segment of the next packet. */
2191 : : uint32_t count;
2192 : :
2193 [ # # ]: 0 : if (txq == NULL)
2194 : : return -ENODEV;
2195 : :
2196 : : count = 0;
2197 : 0 : sw_ring = txq->sw_ring;
2198 : 0 : txr = txq->tx_ring;
2199 : :
2200 : : /*
2201 : : * tx_tail is the last sent packet on the sw_ring. Goto the end
2202 : : * of that packet (the last segment in the packet chain) and
2203 : : * then the next segment will be the start of the oldest segment
2204 : : * in the sw_ring. This is the first packet that will be
2205 : : * attempted to be freed.
2206 : : */
2207 : :
2208 : : /* Get last segment in most recently added packet. */
2209 : 0 : tx_first = sw_ring[txq->tx_tail].last_id;
2210 : :
2211 : : /* Get the next segment, which is the oldest segment in ring. */
2212 : 0 : tx_first = sw_ring[tx_first].next_id;
2213 : :
2214 : : /* Set the current index to the first. */
2215 : : tx_id = tx_first;
2216 : :
2217 : : /*
2218 : : * Loop through each packet. For each packet, verify that an
2219 : : * mbuf exists and that the last segment is free. If so, free
2220 : : * it and move on.
2221 : : */
2222 : : while (1) {
2223 : 0 : tx_last = sw_ring[tx_id].last_id;
2224 : :
2225 [ # # ]: 0 : if (sw_ring[tx_last].mbuf) {
2226 [ # # ]: 0 : if (!(txr[tx_last].wb.status &
2227 : : rte_cpu_to_le_32(E1000_TXD_STAT_DD)))
2228 : : break;
2229 : :
2230 : : /* Get the start of the next packet. */
2231 : 0 : tx_next = sw_ring[tx_last].next_id;
2232 : :
2233 : : /*
2234 : : * Loop through all segments in a
2235 : : * packet.
2236 : : */
2237 : : do {
2238 [ # # ]: 0 : rte_pktmbuf_free_seg(sw_ring[tx_id].mbuf);
2239 : 0 : sw_ring[tx_id].mbuf = NULL;
2240 : 0 : sw_ring[tx_id].last_id = tx_id;
2241 : :
2242 : : /* Move to next segment. */
2243 : 0 : tx_id = sw_ring[tx_id].next_id;
2244 [ # # ]: 0 : } while (tx_id != tx_next);
2245 : :
2246 : : /*
2247 : : * Increment the number of packets
2248 : : * freed.
2249 : : */
2250 : 0 : count++;
2251 [ # # ]: 0 : if (unlikely(count == free_cnt))
2252 : : break;
2253 : : } else {
2254 : : /*
2255 : : * There are multiple reasons to be here:
2256 : : * 1) All the packets on the ring have been
2257 : : * freed - tx_id is equal to tx_first
2258 : : * and some packets have been freed.
2259 : : * - Done, exit
2260 : : * 2) Interfaces has not sent a rings worth of
2261 : : * packets yet, so the segment after tail is
2262 : : * still empty. Or a previous call to this
2263 : : * function freed some of the segments but
2264 : : * not all so there is a hole in the list.
2265 : : * Hopefully this is a rare case.
2266 : : * - Walk the list and find the next mbuf. If
2267 : : * there isn't one, then done.
2268 : : */
2269 [ # # ]: 0 : if (likely(tx_id == tx_first && count != 0))
2270 : : break;
2271 : :
2272 : : /*
2273 : : * Walk the list and find the next mbuf, if any.
2274 : : */
2275 : : do {
2276 : : /* Move to next segment. */
2277 : 0 : tx_id = sw_ring[tx_id].next_id;
2278 : :
2279 [ # # ]: 0 : if (sw_ring[tx_id].mbuf)
2280 : : break;
2281 : :
2282 [ # # ]: 0 : } while (tx_id != tx_first);
2283 : :
2284 : : /*
2285 : : * Determine why previous loop bailed. If there
2286 : : * is not an mbuf, done.
2287 : : */
2288 [ # # ]: 0 : if (sw_ring[tx_id].mbuf == NULL)
2289 : : break;
2290 : : }
2291 : : }
2292 : :
2293 : 0 : return count;
2294 : : }
2295 : :
2296 : : void
2297 : 0 : igc_tx_init(struct rte_eth_dev *dev)
2298 : : {
2299 : 0 : struct e1000_hw *hw = IGC_DEV_PRIVATE_HW(dev);
2300 : 0 : uint64_t offloads = dev->data->dev_conf.txmode.offloads;
2301 : : uint32_t tctl;
2302 : : uint32_t txdctl;
2303 : : uint16_t i;
2304 : : int err;
2305 : :
2306 : : /* Setup the Base and Length of the Tx Descriptor Rings. */
2307 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
2308 : 0 : struct igc_tx_queue *txq = dev->data->tx_queues[i];
2309 : 0 : uint64_t bus_addr = txq->tx_ring_phys_addr;
2310 : :
2311 [ # # ]: 0 : E1000_WRITE_REG(hw, E1000_TDLEN(txq->reg_idx),
2312 : : txq->nb_tx_desc *
2313 : : sizeof(union e1000_adv_tx_desc));
2314 [ # # ]: 0 : E1000_WRITE_REG(hw, E1000_TDBAH(txq->reg_idx),
2315 : : (uint32_t)(bus_addr >> 32));
2316 [ # # ]: 0 : E1000_WRITE_REG(hw, E1000_TDBAL(txq->reg_idx),
2317 : : (uint32_t)bus_addr);
2318 : :
2319 : : /* Setup the HW Tx Head and Tail descriptor pointers. */
2320 [ # # ]: 0 : E1000_WRITE_REG(hw, E1000_TDT(txq->reg_idx), 0);
2321 [ # # ]: 0 : E1000_WRITE_REG(hw, E1000_TDH(txq->reg_idx), 0);
2322 : :
2323 : : /* Setup Transmit threshold registers. */
2324 : 0 : txdctl = ((uint32_t)txq->pthresh << IGC_TXDCTL_PTHRESH_SHIFT) &
2325 : : IGC_TXDCTL_PTHRESH_MSK;
2326 : 0 : txdctl |= ((uint32_t)txq->hthresh << IGC_TXDCTL_HTHRESH_SHIFT) &
2327 : : IGC_TXDCTL_HTHRESH_MSK;
2328 : 0 : txdctl |= ((uint32_t)txq->wthresh << IGC_TXDCTL_WTHRESH_SHIFT) &
2329 : : IGC_TXDCTL_WTHRESH_MSK;
2330 : 0 : txdctl |= E1000_TXDCTL_QUEUE_ENABLE;
2331 [ # # ]: 0 : E1000_WRITE_REG(hw, E1000_TXDCTL(txq->reg_idx), txdctl);
2332 : 0 : dev->data->tx_queue_state[i] = RTE_ETH_QUEUE_STATE_STARTED;
2333 : : }
2334 : :
2335 [ # # ]: 0 : if (offloads & RTE_ETH_TX_OFFLOAD_SEND_ON_TIMESTAMP) {
2336 : 0 : err = rte_mbuf_dyn_tx_timestamp_register
2337 : : (&igc_tx_timestamp_dynfield_offset,
2338 : : &igc_tx_timestamp_dynflag);
2339 [ # # ]: 0 : if (err) {
2340 : 0 : PMD_DRV_LOG(ERR,
2341 : : "Cannot register mbuf field/flag for timestamp");
2342 : : }
2343 : : }
2344 : :
2345 : 0 : e1000_config_collision_dist(hw);
2346 : :
2347 : : /* Program the Transmit Control Register. */
2348 : 0 : tctl = E1000_READ_REG(hw, E1000_TCTL);
2349 : 0 : tctl &= ~E1000_TCTL_CT;
2350 : 0 : tctl |= (E1000_TCTL_PSP | E1000_TCTL_RTLC | E1000_TCTL_EN |
2351 : : ((uint32_t)E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT));
2352 : :
2353 : : /* This write will effectively turn on the transmit unit. */
2354 : 0 : E1000_WRITE_REG(hw, E1000_TCTL, tctl);
2355 : 0 : }
2356 : :
2357 : : void
2358 : 0 : eth_igc_rxq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
2359 : : struct rte_eth_rxq_info *qinfo)
2360 : : {
2361 : : struct igc_rx_queue *rxq;
2362 : :
2363 : 0 : rxq = dev->data->rx_queues[queue_id];
2364 : :
2365 : 0 : qinfo->mp = rxq->mb_pool;
2366 : 0 : qinfo->scattered_rx = dev->data->scattered_rx;
2367 : 0 : qinfo->nb_desc = rxq->nb_rx_desc;
2368 : :
2369 : 0 : qinfo->conf.rx_free_thresh = rxq->rx_free_thresh;
2370 : 0 : qinfo->conf.rx_drop_en = rxq->drop_en;
2371 : 0 : qinfo->conf.offloads = rxq->offloads;
2372 : 0 : qinfo->conf.rx_thresh.hthresh = rxq->hthresh;
2373 : 0 : qinfo->conf.rx_thresh.pthresh = rxq->pthresh;
2374 : 0 : qinfo->conf.rx_thresh.wthresh = rxq->wthresh;
2375 : 0 : }
2376 : :
2377 : : void
2378 : 0 : eth_igc_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
2379 : : struct rte_eth_txq_info *qinfo)
2380 : : {
2381 : : struct igc_tx_queue *txq;
2382 : :
2383 : 0 : txq = dev->data->tx_queues[queue_id];
2384 : :
2385 : 0 : qinfo->nb_desc = txq->nb_tx_desc;
2386 : :
2387 : 0 : qinfo->conf.tx_thresh.pthresh = txq->pthresh;
2388 : 0 : qinfo->conf.tx_thresh.hthresh = txq->hthresh;
2389 : 0 : qinfo->conf.tx_thresh.wthresh = txq->wthresh;
2390 : 0 : qinfo->conf.offloads = txq->offloads;
2391 : 0 : }
2392 : :
2393 : : void
2394 : 0 : eth_igc_vlan_strip_queue_set(struct rte_eth_dev *dev,
2395 : : uint16_t rx_queue_id, int on)
2396 : : {
2397 : 0 : struct e1000_hw *hw = IGC_DEV_PRIVATE_HW(dev);
2398 : 0 : struct igc_rx_queue *rxq = dev->data->rx_queues[rx_queue_id];
2399 : : uint32_t reg_val;
2400 : :
2401 [ # # ]: 0 : if (rx_queue_id >= IGC_QUEUE_PAIRS_NUM) {
2402 : 0 : PMD_DRV_LOG(ERR, "Queue index(%u) illegal, max is %u",
2403 : : rx_queue_id, IGC_QUEUE_PAIRS_NUM - 1);
2404 : 0 : return;
2405 : : }
2406 : :
2407 : 0 : reg_val = E1000_READ_REG(hw, E1000_DVMOLR(rx_queue_id));
2408 [ # # ]: 0 : if (on) {
2409 : 0 : reg_val |= E1000_DVMOLR_STRVLAN;
2410 : 0 : rxq->offloads |= RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
2411 : : } else {
2412 : 0 : reg_val &= ~(E1000_DVMOLR_STRVLAN | E1000_DVMOLR_HIDVLAN);
2413 : 0 : rxq->offloads &= ~RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
2414 : : }
2415 : :
2416 : 0 : E1000_WRITE_REG(hw, E1000_DVMOLR(rx_queue_id), reg_val);
2417 : : }
|