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