Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2010-2016 Intel Corporation
3 : : */
4 : :
5 : : #include <sys/queue.h>
6 : :
7 : : #include <stdio.h>
8 : : #include <stdlib.h>
9 : : #include <string.h>
10 : : #include <errno.h>
11 : : #include <stdint.h>
12 : : #include <stdarg.h>
13 : : #include <inttypes.h>
14 : :
15 : : #include <rte_interrupts.h>
16 : : #include <rte_byteorder.h>
17 : : #include <rte_common.h>
18 : : #include <rte_log.h>
19 : : #include <rte_debug.h>
20 : : #include <rte_pci.h>
21 : : #include <bus_pci_driver.h>
22 : : #include <rte_memory.h>
23 : : #include <rte_memzone.h>
24 : : #include <rte_launch.h>
25 : : #include <rte_eal.h>
26 : : #include <rte_per_lcore.h>
27 : : #include <rte_lcore.h>
28 : : #include <rte_atomic.h>
29 : : #include <rte_branch_prediction.h>
30 : : #include <rte_mempool.h>
31 : : #include <rte_malloc.h>
32 : : #include <rte_mbuf.h>
33 : : #include <rte_ether.h>
34 : : #include <ethdev_driver.h>
35 : : #include <rte_prefetch.h>
36 : : #include <rte_ip.h>
37 : : #include <rte_udp.h>
38 : : #include <rte_tcp.h>
39 : : #include <rte_sctp.h>
40 : : #include <rte_net.h>
41 : : #include <rte_string_fns.h>
42 : :
43 : : #include "e1000_logs.h"
44 : : #include "base/e1000_api.h"
45 : : #include "e1000_ethdev.h"
46 : : #include "base/e1000_osdep.h"
47 : :
48 : : #define E1000_TXD_VLAN_SHIFT 16
49 : :
50 : : #define E1000_RXDCTL_GRAN 0x01000000 /* RXDCTL Granularity */
51 : :
52 : : #define E1000_TX_OFFLOAD_MASK (RTE_MBUF_F_TX_IPV6 | \
53 : : RTE_MBUF_F_TX_IPV4 | \
54 : : RTE_MBUF_F_TX_IP_CKSUM | \
55 : : RTE_MBUF_F_TX_L4_MASK | \
56 : : RTE_MBUF_F_TX_VLAN)
57 : :
58 : : #define E1000_TX_OFFLOAD_NOTSUP_MASK \
59 : : (RTE_MBUF_F_TX_OFFLOAD_MASK ^ E1000_TX_OFFLOAD_MASK)
60 : :
61 : : /**
62 : : * Structure associated with each descriptor of the RX ring of a RX queue.
63 : : */
64 : : struct em_rx_entry {
65 : : struct rte_mbuf *mbuf; /**< mbuf associated with RX descriptor. */
66 : : };
67 : :
68 : : /**
69 : : * Structure associated with each descriptor of the TX ring of a TX queue.
70 : : */
71 : : struct em_tx_entry {
72 : : struct rte_mbuf *mbuf; /**< mbuf associated with TX desc, if any. */
73 : : uint16_t next_id; /**< Index of next descriptor in ring. */
74 : : uint16_t last_id; /**< Index of last scattered descriptor. */
75 : : };
76 : :
77 : : /**
78 : : * Structure associated with each RX queue.
79 : : */
80 : : struct em_rx_queue {
81 : : struct rte_mempool *mb_pool; /**< mbuf pool to populate RX ring. */
82 : : volatile struct e1000_rx_desc *rx_ring; /**< RX ring virtual address. */
83 : : uint64_t rx_ring_phys_addr; /**< RX ring DMA address. */
84 : : volatile uint32_t *rdt_reg_addr; /**< RDT register address. */
85 : : volatile uint32_t *rdh_reg_addr; /**< RDH register address. */
86 : : struct em_rx_entry *sw_ring; /**< address of RX software ring. */
87 : : struct rte_mbuf *pkt_first_seg; /**< First segment of current packet. */
88 : : struct rte_mbuf *pkt_last_seg; /**< Last segment of current packet. */
89 : : uint64_t offloads; /**< Offloads of RTE_ETH_RX_OFFLOAD_* */
90 : : uint16_t nb_rx_desc; /**< number of RX descriptors. */
91 : : uint16_t rx_tail; /**< current value of RDT register. */
92 : : uint16_t nb_rx_hold; /**< number of held free RX desc. */
93 : : uint16_t rx_free_thresh; /**< max free RX desc to hold. */
94 : : uint16_t queue_id; /**< RX queue index. */
95 : : uint16_t port_id; /**< Device port identifier. */
96 : : uint8_t pthresh; /**< Prefetch threshold register. */
97 : : uint8_t hthresh; /**< Host threshold register. */
98 : : uint8_t wthresh; /**< Write-back threshold register. */
99 : : uint8_t crc_len; /**< 0 if CRC stripped, 4 otherwise. */
100 : : const struct rte_memzone *mz;
101 : : };
102 : :
103 : : /**
104 : : * Hardware context number
105 : : */
106 : : enum {
107 : : EM_CTX_0 = 0, /**< CTX0 */
108 : : EM_CTX_NUM = 1, /**< CTX NUM */
109 : : };
110 : :
111 : : /** Offload features */
112 : : union em_vlan_macip {
113 : : uint32_t data;
114 : : struct {
115 : : uint16_t l3_len:9; /**< L3 (IP) Header Length. */
116 : : uint16_t l2_len:7; /**< L2 (MAC) Header Length. */
117 : : uint16_t vlan_tci;
118 : : /**< VLAN Tag Control Identifier (CPU order). */
119 : : } f;
120 : : };
121 : :
122 : : /*
123 : : * Compare mask for vlan_macip_len.data,
124 : : * should be in sync with em_vlan_macip.f layout.
125 : : * */
126 : : #define TX_VLAN_CMP_MASK 0xFFFF0000 /**< VLAN length - 16-bits. */
127 : : #define TX_MAC_LEN_CMP_MASK 0x0000FE00 /**< MAC length - 7-bits. */
128 : : #define TX_IP_LEN_CMP_MASK 0x000001FF /**< IP length - 9-bits. */
129 : : /** MAC+IP length. */
130 : : #define TX_MACIP_LEN_CMP_MASK (TX_MAC_LEN_CMP_MASK | TX_IP_LEN_CMP_MASK)
131 : :
132 : : /**
133 : : * Structure to check if new context need be built
134 : : */
135 : : struct em_ctx_info {
136 : : uint64_t flags; /**< ol_flags related to context build. */
137 : : uint32_t cmp_mask; /**< compare mask */
138 : : union em_vlan_macip hdrlen; /**< L2 and L3 header lengths */
139 : : };
140 : :
141 : : /**
142 : : * Structure associated with each TX queue.
143 : : */
144 : : struct em_tx_queue {
145 : : volatile struct e1000_data_desc *tx_ring; /**< TX ring address */
146 : : uint64_t tx_ring_phys_addr; /**< TX ring DMA address. */
147 : : struct em_tx_entry *sw_ring; /**< virtual address of SW ring. */
148 : : volatile uint32_t *tdt_reg_addr; /**< Address of TDT register. */
149 : : uint16_t nb_tx_desc; /**< number of TX descriptors. */
150 : : uint16_t tx_tail; /**< Current value of TDT register. */
151 : : /**< Start freeing TX buffers if there are less free descriptors than
152 : : this value. */
153 : : uint16_t tx_free_thresh;
154 : : /**< Number of TX descriptors to use before RS bit is set. */
155 : : uint16_t tx_rs_thresh;
156 : : /** Number of TX descriptors used since RS bit was set. */
157 : : uint16_t nb_tx_used;
158 : : /** Index to last TX descriptor to have been cleaned. */
159 : : uint16_t last_desc_cleaned;
160 : : /** Total number of TX descriptors ready to be allocated. */
161 : : uint16_t nb_tx_free;
162 : : uint16_t queue_id; /**< TX queue index. */
163 : : uint16_t port_id; /**< Device port identifier. */
164 : : uint8_t pthresh; /**< Prefetch threshold register. */
165 : : uint8_t hthresh; /**< Host threshold register. */
166 : : uint8_t wthresh; /**< Write-back threshold register. */
167 : : struct em_ctx_info ctx_cache;
168 : : /**< Hardware context history.*/
169 : : uint64_t offloads; /**< offloads of RTE_ETH_TX_OFFLOAD_* */
170 : : const struct rte_memzone *mz;
171 : : };
172 : :
173 : : #if 1
174 : : #define RTE_PMD_USE_PREFETCH
175 : : #endif
176 : :
177 : : #ifdef RTE_PMD_USE_PREFETCH
178 : : #define rte_em_prefetch(p) rte_prefetch0(p)
179 : : #else
180 : : #define rte_em_prefetch(p) do {} while(0)
181 : : #endif
182 : :
183 : : #ifdef RTE_PMD_PACKET_PREFETCH
184 : : #define rte_packet_prefetch(p) rte_prefetch1(p)
185 : : #else
186 : : #define rte_packet_prefetch(p) do {} while(0)
187 : : #endif
188 : :
189 : : #ifndef DEFAULT_TX_FREE_THRESH
190 : : #define DEFAULT_TX_FREE_THRESH 32
191 : : #endif /* DEFAULT_TX_FREE_THRESH */
192 : :
193 : : #ifndef DEFAULT_TX_RS_THRESH
194 : : #define DEFAULT_TX_RS_THRESH 32
195 : : #endif /* DEFAULT_TX_RS_THRESH */
196 : :
197 : :
198 : : /*********************************************************************
199 : : *
200 : : * TX function
201 : : *
202 : : **********************************************************************/
203 : :
204 : : /*
205 : : * Populates TX context descriptor.
206 : : */
207 : : static inline void
208 : 0 : em_set_xmit_ctx(struct em_tx_queue* txq,
209 : : volatile struct e1000_context_desc *ctx_txd,
210 : : uint64_t flags,
211 : : union em_vlan_macip hdrlen)
212 : : {
213 : : uint32_t cmp_mask, cmd_len;
214 : : uint16_t ipcse, l2len;
215 : : struct e1000_context_desc ctx;
216 : :
217 : : cmp_mask = 0;
218 : : cmd_len = E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_C;
219 : :
220 : 0 : l2len = hdrlen.f.l2_len;
221 : 0 : ipcse = (uint16_t)(l2len + hdrlen.f.l3_len);
222 : :
223 : : /* setup IPCS* fields */
224 : 0 : ctx.lower_setup.ip_fields.ipcss = (uint8_t)l2len;
225 : 0 : ctx.lower_setup.ip_fields.ipcso = (uint8_t)(l2len +
226 : : offsetof(struct rte_ipv4_hdr, hdr_checksum));
227 : :
228 : : /*
229 : : * When doing checksum or TCP segmentation with IPv6 headers,
230 : : * IPCSE field should be set t0 0.
231 : : */
232 [ # # ]: 0 : if (flags & RTE_MBUF_F_TX_IP_CKSUM) {
233 : : ctx.lower_setup.ip_fields.ipcse =
234 : 0 : (uint16_t)rte_cpu_to_le_16(ipcse - 1);
235 : : cmd_len |= E1000_TXD_CMD_IP;
236 : : cmp_mask |= TX_MACIP_LEN_CMP_MASK;
237 : : } else {
238 : : ctx.lower_setup.ip_fields.ipcse = 0;
239 : : }
240 : :
241 : : /* setup TUCS* fields */
242 : 0 : ctx.upper_setup.tcp_fields.tucss = (uint8_t)ipcse;
243 : : ctx.upper_setup.tcp_fields.tucse = 0;
244 : :
245 [ # # # ]: 0 : switch (flags & RTE_MBUF_F_TX_L4_MASK) {
246 : 0 : case RTE_MBUF_F_TX_UDP_CKSUM:
247 : 0 : ctx.upper_setup.tcp_fields.tucso = (uint8_t)(ipcse +
248 : : offsetof(struct rte_udp_hdr, dgram_cksum));
249 : : cmp_mask |= TX_MACIP_LEN_CMP_MASK;
250 : 0 : break;
251 : 0 : case RTE_MBUF_F_TX_TCP_CKSUM:
252 : 0 : ctx.upper_setup.tcp_fields.tucso = (uint8_t)(ipcse +
253 : : offsetof(struct rte_tcp_hdr, cksum));
254 : 0 : cmd_len |= E1000_TXD_CMD_TCP;
255 : : cmp_mask |= TX_MACIP_LEN_CMP_MASK;
256 : 0 : break;
257 : : default:
258 : : ctx.upper_setup.tcp_fields.tucso = 0;
259 : : }
260 : :
261 : : ctx.cmd_and_length = rte_cpu_to_le_32(cmd_len);
262 : : ctx.tcp_seg_setup.data = 0;
263 : :
264 : 0 : *ctx_txd = ctx;
265 : :
266 : 0 : txq->ctx_cache.flags = flags;
267 : 0 : txq->ctx_cache.cmp_mask = cmp_mask;
268 : 0 : txq->ctx_cache.hdrlen = hdrlen;
269 : 0 : }
270 : :
271 : : /*
272 : : * Check which hardware context can be used. Use the existing match
273 : : * or create a new context descriptor.
274 : : */
275 : : static inline uint32_t
276 : : what_ctx_update(struct em_tx_queue *txq, uint64_t flags,
277 : : union em_vlan_macip hdrlen)
278 : : {
279 : : /* If match with the current context */
280 [ # # ]: 0 : if (likely (txq->ctx_cache.flags == flags &&
281 : : ((txq->ctx_cache.hdrlen.data ^ hdrlen.data) &
282 : : txq->ctx_cache.cmp_mask) == 0))
283 : 0 : return EM_CTX_0;
284 : :
285 : : /* Mismatch */
286 : : return EM_CTX_NUM;
287 : : }
288 : :
289 : : /* Reset transmit descriptors after they have been used */
290 : : static inline int
291 : 0 : em_xmit_cleanup(struct em_tx_queue *txq)
292 : : {
293 : 0 : struct em_tx_entry *sw_ring = txq->sw_ring;
294 : 0 : volatile struct e1000_data_desc *txr = txq->tx_ring;
295 : 0 : uint16_t last_desc_cleaned = txq->last_desc_cleaned;
296 : 0 : uint16_t nb_tx_desc = txq->nb_tx_desc;
297 : : uint16_t desc_to_clean_to;
298 : : uint16_t nb_tx_to_clean;
299 : :
300 : : /* Determine the last descriptor needing to be cleaned */
301 : 0 : desc_to_clean_to = (uint16_t)(last_desc_cleaned + txq->tx_rs_thresh);
302 [ # # ]: 0 : if (desc_to_clean_to >= nb_tx_desc)
303 : 0 : desc_to_clean_to = (uint16_t)(desc_to_clean_to - nb_tx_desc);
304 : :
305 : : /* Check to make sure the last descriptor to clean is done */
306 : 0 : desc_to_clean_to = sw_ring[desc_to_clean_to].last_id;
307 [ # # ]: 0 : if (! (txr[desc_to_clean_to].upper.fields.status & E1000_TXD_STAT_DD))
308 : : {
309 : : PMD_TX_LOG(DEBUG,
310 : : "TX descriptor %4u is not done"
311 : : "(port=%d queue=%d)", desc_to_clean_to,
312 : : txq->port_id, txq->queue_id);
313 : : /* Failed to clean any descriptors, better luck next time */
314 : : return -(1);
315 : : }
316 : :
317 : : /* Figure out how many descriptors will be cleaned */
318 [ # # ]: 0 : if (last_desc_cleaned > desc_to_clean_to)
319 : 0 : nb_tx_to_clean = (uint16_t)((nb_tx_desc - last_desc_cleaned) +
320 : : desc_to_clean_to);
321 : : else
322 : 0 : nb_tx_to_clean = (uint16_t)(desc_to_clean_to -
323 : : last_desc_cleaned);
324 : :
325 : : PMD_TX_LOG(DEBUG,
326 : : "Cleaning %4u TX descriptors: %4u to %4u "
327 : : "(port=%d queue=%d)", nb_tx_to_clean,
328 : : last_desc_cleaned, desc_to_clean_to, txq->port_id,
329 : : txq->queue_id);
330 : :
331 : : /*
332 : : * The last descriptor to clean is done, so that means all the
333 : : * descriptors from the last descriptor that was cleaned
334 : : * up to the last descriptor with the RS bit set
335 : : * are done. Only reset the threshold descriptor.
336 : : */
337 : 0 : txr[desc_to_clean_to].upper.fields.status = 0;
338 : :
339 : : /* Update the txq to reflect the last descriptor that was cleaned */
340 : 0 : txq->last_desc_cleaned = desc_to_clean_to;
341 : 0 : txq->nb_tx_free = (uint16_t)(txq->nb_tx_free + nb_tx_to_clean);
342 : :
343 : : /* No Error */
344 : 0 : return 0;
345 : : }
346 : :
347 : : static inline uint32_t
348 : : tx_desc_cksum_flags_to_upper(uint64_t ol_flags)
349 : : {
350 : : static const uint32_t l4_olinfo[2] = {0, E1000_TXD_POPTS_TXSM << 8};
351 : : static const uint32_t l3_olinfo[2] = {0, E1000_TXD_POPTS_IXSM << 8};
352 : : uint32_t tmp;
353 : :
354 : 0 : tmp = l4_olinfo[(ol_flags & RTE_MBUF_F_TX_L4_MASK) != RTE_MBUF_F_TX_L4_NO_CKSUM];
355 : 0 : tmp |= l3_olinfo[(ol_flags & RTE_MBUF_F_TX_IP_CKSUM) != 0];
356 : : return tmp;
357 : : }
358 : :
359 : : uint16_t
360 : 0 : eth_em_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
361 : : uint16_t nb_pkts)
362 : : {
363 : : struct em_tx_queue *txq;
364 : : struct em_tx_entry *sw_ring;
365 : : struct em_tx_entry *txe, *txn;
366 : : volatile struct e1000_data_desc *txr;
367 : : volatile struct e1000_data_desc *txd;
368 : : struct rte_mbuf *tx_pkt;
369 : : struct rte_mbuf *m_seg;
370 : : uint64_t buf_dma_addr;
371 : : uint32_t popts_spec;
372 : : uint32_t cmd_type_len;
373 : : uint16_t slen;
374 : : uint64_t ol_flags;
375 : : uint16_t tx_id;
376 : : uint16_t tx_last;
377 : : uint16_t nb_tx;
378 : : uint16_t nb_used;
379 : : uint64_t tx_ol_req;
380 : : uint32_t ctx;
381 : : uint32_t new_ctx;
382 : : union em_vlan_macip hdrlen;
383 : :
384 : : txq = tx_queue;
385 : 0 : sw_ring = txq->sw_ring;
386 : 0 : txr = txq->tx_ring;
387 : 0 : tx_id = txq->tx_tail;
388 : 0 : txe = &sw_ring[tx_id];
389 : :
390 : : /* Determine if the descriptor ring needs to be cleaned. */
391 [ # # ]: 0 : if (txq->nb_tx_free < txq->tx_free_thresh)
392 : 0 : em_xmit_cleanup(txq);
393 : :
394 : : /* TX loop */
395 [ # # ]: 0 : for (nb_tx = 0; nb_tx < nb_pkts; nb_tx++) {
396 : : new_ctx = 0;
397 : 0 : tx_pkt = *tx_pkts++;
398 : :
399 [ # # ]: 0 : RTE_MBUF_PREFETCH_TO_FREE(txe->mbuf);
400 : :
401 : : /*
402 : : * Determine how many (if any) context descriptors
403 : : * are needed for offload functionality.
404 : : */
405 : 0 : ol_flags = tx_pkt->ol_flags;
406 : :
407 : : /* If hardware offload required */
408 : 0 : tx_ol_req = (ol_flags & (RTE_MBUF_F_TX_IP_CKSUM | RTE_MBUF_F_TX_L4_MASK));
409 [ # # ]: 0 : if (tx_ol_req) {
410 : 0 : hdrlen.f.vlan_tci = tx_pkt->vlan_tci;
411 : 0 : hdrlen.f.l2_len = tx_pkt->l2_len;
412 [ # # ]: 0 : hdrlen.f.l3_len = tx_pkt->l3_len;
413 : : /* If new context to be built or reuse the exist ctx. */
414 : : ctx = what_ctx_update(txq, tx_ol_req, hdrlen);
415 : :
416 : : /* Only allocate context descriptor if required*/
417 : 0 : new_ctx = (ctx == EM_CTX_NUM);
418 : : }
419 : :
420 : : /*
421 : : * Keep track of how many descriptors are used this loop
422 : : * This will always be the number of segments + the number of
423 : : * Context descriptors required to transmit the packet
424 : : */
425 : 0 : nb_used = (uint16_t)(tx_pkt->nb_segs + new_ctx);
426 : :
427 : : /*
428 : : * The number of descriptors that must be allocated for a
429 : : * packet is the number of segments of that packet, plus 1
430 : : * Context Descriptor for the hardware offload, if any.
431 : : * Determine the last TX descriptor to allocate in the TX ring
432 : : * for the packet, starting from the current position (tx_id)
433 : : * in the ring.
434 : : */
435 : 0 : tx_last = (uint16_t) (tx_id + nb_used - 1);
436 : :
437 : : /* Circular ring */
438 [ # # ]: 0 : if (tx_last >= txq->nb_tx_desc)
439 : 0 : tx_last = (uint16_t) (tx_last - txq->nb_tx_desc);
440 : :
441 : : PMD_TX_LOG(DEBUG, "port_id=%u queue_id=%u pktlen=%u"
442 : : " tx_first=%u tx_last=%u",
443 : : (unsigned) txq->port_id,
444 : : (unsigned) txq->queue_id,
445 : : (unsigned) tx_pkt->pkt_len,
446 : : (unsigned) tx_id,
447 : : (unsigned) tx_last);
448 : :
449 : : /*
450 : : * Make sure there are enough TX descriptors available to
451 : : * transmit the entire packet.
452 : : * nb_used better be less than or equal to txq->tx_rs_thresh
453 : : */
454 [ # # ]: 0 : while (unlikely (nb_used > txq->nb_tx_free)) {
455 : : PMD_TX_LOG(DEBUG, "Not enough free TX descriptors "
456 : : "nb_used=%4u nb_free=%4u "
457 : : "(port=%d queue=%d)",
458 : : nb_used, txq->nb_tx_free,
459 : : txq->port_id, txq->queue_id);
460 : :
461 [ # # ]: 0 : if (em_xmit_cleanup(txq) != 0) {
462 : : /* Could not clean any descriptors */
463 [ # # ]: 0 : if (nb_tx == 0)
464 : : return 0;
465 : 0 : goto end_of_tx;
466 : : }
467 : : }
468 : :
469 : : /*
470 : : * By now there are enough free TX descriptors to transmit
471 : : * the packet.
472 : : */
473 : :
474 : : /*
475 : : * Set common flags of all TX Data Descriptors.
476 : : *
477 : : * The following bits must be set in all Data Descriptors:
478 : : * - E1000_TXD_DTYP_DATA
479 : : * - E1000_TXD_DTYP_DEXT
480 : : *
481 : : * The following bits must be set in the first Data Descriptor
482 : : * and are ignored in the other ones:
483 : : * - E1000_TXD_POPTS_IXSM
484 : : * - E1000_TXD_POPTS_TXSM
485 : : *
486 : : * The following bits must be set in the last Data Descriptor
487 : : * and are ignored in the other ones:
488 : : * - E1000_TXD_CMD_VLE
489 : : * - E1000_TXD_CMD_IFCS
490 : : *
491 : : * The following bits must only be set in the last Data
492 : : * Descriptor:
493 : : * - E1000_TXD_CMD_EOP
494 : : *
495 : : * The following bits can be set in any Data Descriptor, but
496 : : * are only set in the last Data Descriptor:
497 : : * - E1000_TXD_CMD_RS
498 : : */
499 : : cmd_type_len = E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
500 : : E1000_TXD_CMD_IFCS;
501 : : popts_spec = 0;
502 : :
503 : : /* Set VLAN Tag offload fields. */
504 [ # # ]: 0 : if (ol_flags & RTE_MBUF_F_TX_VLAN) {
505 : : cmd_type_len |= E1000_TXD_CMD_VLE;
506 : 0 : popts_spec = tx_pkt->vlan_tci << E1000_TXD_VLAN_SHIFT;
507 : : }
508 : :
509 [ # # ]: 0 : if (tx_ol_req) {
510 : : /*
511 : : * Setup the TX Context Descriptor if required
512 : : */
513 [ # # ]: 0 : if (new_ctx) {
514 : : volatile struct e1000_context_desc *ctx_txd;
515 : :
516 : 0 : ctx_txd = (volatile struct e1000_context_desc *)
517 : 0 : &txr[tx_id];
518 : :
519 : 0 : txn = &sw_ring[txe->next_id];
520 [ # # ]: 0 : RTE_MBUF_PREFETCH_TO_FREE(txn->mbuf);
521 : :
522 [ # # ]: 0 : if (txe->mbuf != NULL) {
523 : : rte_pktmbuf_free_seg(txe->mbuf);
524 : 0 : txe->mbuf = NULL;
525 : : }
526 : :
527 : 0 : em_set_xmit_ctx(txq, ctx_txd, tx_ol_req,
528 : : hdrlen);
529 : :
530 : 0 : txe->last_id = tx_last;
531 : 0 : tx_id = txe->next_id;
532 : : txe = txn;
533 : : }
534 : :
535 : : /*
536 : : * Setup the TX Data Descriptor,
537 : : * This path will go through
538 : : * whatever new/reuse the context descriptor
539 : : */
540 : 0 : popts_spec |= tx_desc_cksum_flags_to_upper(ol_flags);
541 : : }
542 : :
543 : : m_seg = tx_pkt;
544 : : do {
545 : 0 : txd = &txr[tx_id];
546 : 0 : txn = &sw_ring[txe->next_id];
547 : :
548 [ # # ]: 0 : if (txe->mbuf != NULL)
549 : : rte_pktmbuf_free_seg(txe->mbuf);
550 : 0 : txe->mbuf = m_seg;
551 : :
552 : : /*
553 : : * Set up Transmit Data Descriptor.
554 : : */
555 [ # # ]: 0 : slen = m_seg->data_len;
556 : : buf_dma_addr = rte_mbuf_data_iova(m_seg);
557 : :
558 : 0 : txd->buffer_addr = rte_cpu_to_le_64(buf_dma_addr);
559 : 0 : txd->lower.data = rte_cpu_to_le_32(cmd_type_len | slen);
560 : 0 : txd->upper.data = rte_cpu_to_le_32(popts_spec);
561 : :
562 : 0 : txe->last_id = tx_last;
563 : 0 : tx_id = txe->next_id;
564 : : txe = txn;
565 : 0 : m_seg = m_seg->next;
566 [ # # ]: 0 : } while (m_seg != NULL);
567 : :
568 : : /*
569 : : * The last packet data descriptor needs End Of Packet (EOP)
570 : : */
571 : 0 : cmd_type_len |= E1000_TXD_CMD_EOP;
572 : 0 : txq->nb_tx_used = (uint16_t)(txq->nb_tx_used + nb_used);
573 : 0 : txq->nb_tx_free = (uint16_t)(txq->nb_tx_free - nb_used);
574 : :
575 : : /* Set RS bit only on threshold packets' last descriptor */
576 [ # # ]: 0 : if (txq->nb_tx_used >= txq->tx_rs_thresh) {
577 : : PMD_TX_LOG(DEBUG,
578 : : "Setting RS bit on TXD id=%4u "
579 : : "(port=%d queue=%d)",
580 : : tx_last, txq->port_id, txq->queue_id);
581 : :
582 : 0 : cmd_type_len |= E1000_TXD_CMD_RS;
583 : :
584 : : /* Update txq RS bit counters */
585 : 0 : txq->nb_tx_used = 0;
586 : : }
587 : 0 : txd->lower.data |= rte_cpu_to_le_32(cmd_type_len);
588 : : }
589 : 0 : end_of_tx:
590 : : rte_wmb();
591 : :
592 : : /*
593 : : * Set the Transmit Descriptor Tail (TDT)
594 : : */
595 : : PMD_TX_LOG(DEBUG, "port_id=%u queue_id=%u tx_tail=%u nb_tx=%u",
596 : : (unsigned) txq->port_id, (unsigned) txq->queue_id,
597 : : (unsigned) tx_id, (unsigned) nb_tx);
598 : 0 : E1000_PCI_REG_WRITE_RELAXED(txq->tdt_reg_addr, tx_id);
599 : 0 : txq->tx_tail = tx_id;
600 : :
601 : 0 : return nb_tx;
602 : : }
603 : :
604 : : /*********************************************************************
605 : : *
606 : : * TX prep functions
607 : : *
608 : : **********************************************************************/
609 : : uint16_t
610 : 0 : eth_em_prep_pkts(__rte_unused void *tx_queue, struct rte_mbuf **tx_pkts,
611 : : uint16_t nb_pkts)
612 : : {
613 : : int i, ret;
614 : : struct rte_mbuf *m;
615 : :
616 [ # # ]: 0 : for (i = 0; i < nb_pkts; i++) {
617 : 0 : m = tx_pkts[i];
618 : :
619 [ # # ]: 0 : if (m->ol_flags & E1000_TX_OFFLOAD_NOTSUP_MASK) {
620 : 0 : rte_errno = ENOTSUP;
621 : 0 : return i;
622 : : }
623 : :
624 : : #ifdef RTE_ETHDEV_DEBUG_TX
625 : : ret = rte_validate_tx_offload(m);
626 : : if (ret != 0) {
627 : : rte_errno = -ret;
628 : : return i;
629 : : }
630 : : #endif
631 : : ret = rte_net_intel_cksum_prepare(m);
632 [ # # ]: 0 : if (ret != 0) {
633 : 0 : rte_errno = -ret;
634 : 0 : return i;
635 : : }
636 : : }
637 : :
638 : 0 : return i;
639 : : }
640 : :
641 : : /*********************************************************************
642 : : *
643 : : * RX functions
644 : : *
645 : : **********************************************************************/
646 : :
647 : : static inline uint64_t
648 : : rx_desc_status_to_pkt_flags(uint32_t rx_status)
649 : : {
650 : : uint64_t pkt_flags;
651 : :
652 : : /* Check if VLAN present */
653 : : pkt_flags = ((rx_status & E1000_RXD_STAT_VP) ?
654 : 0 : RTE_MBUF_F_RX_VLAN | RTE_MBUF_F_RX_VLAN_STRIPPED : 0);
655 : :
656 : : return pkt_flags;
657 : : }
658 : :
659 : : static inline uint64_t
660 : : rx_desc_error_to_pkt_flags(uint32_t rx_error)
661 : : {
662 : : uint64_t pkt_flags = 0;
663 : :
664 [ # # # # ]: 0 : if (rx_error & E1000_RXD_ERR_IPE)
665 : : pkt_flags |= RTE_MBUF_F_RX_IP_CKSUM_BAD;
666 [ # # # # ]: 0 : if (rx_error & E1000_RXD_ERR_TCPE)
667 : 0 : pkt_flags |= RTE_MBUF_F_RX_L4_CKSUM_BAD;
668 : : return pkt_flags;
669 : : }
670 : :
671 : : uint16_t
672 : 0 : eth_em_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
673 : : uint16_t nb_pkts)
674 : : {
675 : : volatile struct e1000_rx_desc *rx_ring;
676 : : volatile struct e1000_rx_desc *rxdp;
677 : : struct em_rx_queue *rxq;
678 : : struct em_rx_entry *sw_ring;
679 : : struct em_rx_entry *rxe;
680 : : struct rte_mbuf *rxm;
681 : : struct rte_mbuf *nmb;
682 : : struct e1000_rx_desc rxd;
683 : : uint64_t dma_addr;
684 : : uint16_t pkt_len;
685 : : uint16_t rx_id;
686 : : uint16_t nb_rx;
687 : : uint16_t nb_hold;
688 : : uint8_t status;
689 : :
690 : : rxq = rx_queue;
691 : :
692 : : nb_rx = 0;
693 : : nb_hold = 0;
694 : 0 : rx_id = rxq->rx_tail;
695 : 0 : rx_ring = rxq->rx_ring;
696 : 0 : sw_ring = rxq->sw_ring;
697 [ # # ]: 0 : while (nb_rx < nb_pkts) {
698 : : /*
699 : : * The order of operations here is important as the DD status
700 : : * bit must not be read after any other descriptor fields.
701 : : * rx_ring and rxdp are pointing to volatile data so the order
702 : : * of accesses cannot be reordered by the compiler. If they were
703 : : * not volatile, they could be reordered which could lead to
704 : : * using invalid descriptor fields when read from rxd.
705 : : */
706 : 0 : rxdp = &rx_ring[rx_id];
707 : 0 : status = rxdp->status;
708 [ # # ]: 0 : if (! (status & E1000_RXD_STAT_DD))
709 : : break;
710 : 0 : rxd = *rxdp;
711 : :
712 : : /*
713 : : * End of packet.
714 : : *
715 : : * If the E1000_RXD_STAT_EOP flag is not set, the RX packet is
716 : : * likely to be invalid and to be dropped by the various
717 : : * validation checks performed by the network stack.
718 : : *
719 : : * Allocate a new mbuf to replenish the RX ring descriptor.
720 : : * If the allocation fails:
721 : : * - arrange for that RX descriptor to be the first one
722 : : * being parsed the next time the receive function is
723 : : * invoked [on the same queue].
724 : : *
725 : : * - Stop parsing the RX ring and return immediately.
726 : : *
727 : : * This policy do not drop the packet received in the RX
728 : : * descriptor for which the allocation of a new mbuf failed.
729 : : * Thus, it allows that packet to be later retrieved if
730 : : * mbuf have been freed in the mean time.
731 : : * As a side effect, holding RX descriptors instead of
732 : : * systematically giving them back to the NIC may lead to
733 : : * RX ring exhaustion situations.
734 : : * However, the NIC can gracefully prevent such situations
735 : : * to happen by sending specific "back-pressure" flow control
736 : : * frames to its peer(s).
737 : : */
738 : : PMD_RX_LOG(DEBUG, "port_id=%u queue_id=%u rx_id=%u "
739 : : "status=0x%x pkt_len=%u",
740 : : (unsigned) rxq->port_id, (unsigned) rxq->queue_id,
741 : : (unsigned) rx_id, (unsigned) status,
742 : : (unsigned) rte_le_to_cpu_16(rxd.length));
743 : :
744 : 0 : nmb = rte_mbuf_raw_alloc(rxq->mb_pool);
745 [ # # ]: 0 : if (nmb == NULL) {
746 : : PMD_RX_LOG(DEBUG, "RX mbuf alloc failed port_id=%u "
747 : : "queue_id=%u",
748 : : (unsigned) rxq->port_id,
749 : : (unsigned) rxq->queue_id);
750 : 0 : rte_eth_devices[rxq->port_id].data->rx_mbuf_alloc_failed++;
751 : 0 : break;
752 : : }
753 : :
754 : 0 : nb_hold++;
755 : 0 : rxe = &sw_ring[rx_id];
756 : 0 : rx_id++;
757 [ # # ]: 0 : if (rx_id == rxq->nb_rx_desc)
758 : : rx_id = 0;
759 : :
760 : : /* Prefetch next mbuf while processing current one. */
761 : 0 : rte_em_prefetch(sw_ring[rx_id].mbuf);
762 : :
763 : : /*
764 : : * When next RX descriptor is on a cache-line boundary,
765 : : * prefetch the next 4 RX descriptors and the next 8 pointers
766 : : * to mbufs.
767 : : */
768 [ # # ]: 0 : if ((rx_id & 0x3) == 0) {
769 : 0 : rte_em_prefetch(&rx_ring[rx_id]);
770 : : rte_em_prefetch(&sw_ring[rx_id]);
771 : : }
772 : :
773 : : /* Rearm RXD: attach new mbuf and reset status to zero. */
774 : :
775 : 0 : rxm = rxe->mbuf;
776 : 0 : rxe->mbuf = nmb;
777 : : dma_addr =
778 : : rte_cpu_to_le_64(rte_mbuf_data_iova_default(nmb));
779 : 0 : rxdp->buffer_addr = dma_addr;
780 : 0 : rxdp->status = 0;
781 : :
782 : : /*
783 : : * Initialize the returned mbuf.
784 : : * 1) setup generic mbuf fields:
785 : : * - number of segments,
786 : : * - next segment,
787 : : * - packet length,
788 : : * - RX port identifier.
789 : : * 2) integrate hardware offload data, if any:
790 : : * - RSS flag & hash,
791 : : * - IP checksum flag,
792 : : * - VLAN TCI, if any,
793 : : * - error flags.
794 : : */
795 : 0 : pkt_len = (uint16_t) (rte_le_to_cpu_16(rxd.length) -
796 : 0 : rxq->crc_len);
797 : 0 : rxm->data_off = RTE_PKTMBUF_HEADROOM;
798 : 0 : rte_packet_prefetch((char *)rxm->buf_addr + rxm->data_off);
799 : 0 : rxm->nb_segs = 1;
800 : 0 : rxm->next = NULL;
801 : 0 : rxm->pkt_len = pkt_len;
802 : 0 : rxm->data_len = pkt_len;
803 [ # # ]: 0 : rxm->port = rxq->port_id;
804 : :
805 : : rxm->ol_flags = rx_desc_status_to_pkt_flags(status);
806 : 0 : rxm->ol_flags = rxm->ol_flags |
807 : : rx_desc_error_to_pkt_flags(rxd.errors);
808 : :
809 : : /* Only valid if RTE_MBUF_F_RX_VLAN set in pkt_flags */
810 : 0 : rxm->vlan_tci = rte_le_to_cpu_16(rxd.special);
811 : :
812 : : /*
813 : : * Store the mbuf address into the next entry of the array
814 : : * of returned packets.
815 : : */
816 : 0 : rx_pkts[nb_rx++] = rxm;
817 : : }
818 : 0 : rxq->rx_tail = rx_id;
819 : :
820 : : /*
821 : : * If the number of free RX descriptors is greater than the RX free
822 : : * threshold of the queue, advance the Receive Descriptor Tail (RDT)
823 : : * register.
824 : : * Update the RDT with the value of the last processed RX descriptor
825 : : * minus 1, to guarantee that the RDT register is never equal to the
826 : : * RDH register, which creates a "full" ring situation from the
827 : : * hardware point of view...
828 : : */
829 : 0 : nb_hold = (uint16_t) (nb_hold + rxq->nb_rx_hold);
830 [ # # ]: 0 : if (nb_hold > rxq->rx_free_thresh) {
831 : : PMD_RX_LOG(DEBUG, "port_id=%u queue_id=%u rx_tail=%u "
832 : : "nb_hold=%u nb_rx=%u",
833 : : (unsigned) rxq->port_id, (unsigned) rxq->queue_id,
834 : : (unsigned) rx_id, (unsigned) nb_hold,
835 : : (unsigned) nb_rx);
836 [ # # ]: 0 : rx_id = (uint16_t) ((rx_id == 0) ?
837 : 0 : (rxq->nb_rx_desc - 1) : (rx_id - 1));
838 : 0 : E1000_PCI_REG_WRITE(rxq->rdt_reg_addr, rx_id);
839 : : nb_hold = 0;
840 : : }
841 : 0 : rxq->nb_rx_hold = nb_hold;
842 : 0 : return nb_rx;
843 : : }
844 : :
845 : : uint16_t
846 : 0 : eth_em_recv_scattered_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
847 : : uint16_t nb_pkts)
848 : : {
849 : : struct em_rx_queue *rxq;
850 : : volatile struct e1000_rx_desc *rx_ring;
851 : : volatile struct e1000_rx_desc *rxdp;
852 : : struct em_rx_entry *sw_ring;
853 : : struct em_rx_entry *rxe;
854 : : struct rte_mbuf *first_seg;
855 : : struct rte_mbuf *last_seg;
856 : : struct rte_mbuf *rxm;
857 : : struct rte_mbuf *nmb;
858 : : struct e1000_rx_desc rxd;
859 : : uint64_t dma; /* Physical address of mbuf data buffer */
860 : : uint16_t rx_id;
861 : : uint16_t nb_rx;
862 : : uint16_t nb_hold;
863 : : uint16_t data_len;
864 : : uint8_t status;
865 : :
866 : : rxq = rx_queue;
867 : :
868 : : nb_rx = 0;
869 : : nb_hold = 0;
870 : 0 : rx_id = rxq->rx_tail;
871 : 0 : rx_ring = rxq->rx_ring;
872 : 0 : sw_ring = rxq->sw_ring;
873 : :
874 : : /*
875 : : * Retrieve RX context of current packet, if any.
876 : : */
877 : 0 : first_seg = rxq->pkt_first_seg;
878 : 0 : last_seg = rxq->pkt_last_seg;
879 : :
880 [ # # ]: 0 : while (nb_rx < nb_pkts) {
881 : 0 : next_desc:
882 : : /*
883 : : * The order of operations here is important as the DD status
884 : : * bit must not be read after any other descriptor fields.
885 : : * rx_ring and rxdp are pointing to volatile data so the order
886 : : * of accesses cannot be reordered by the compiler. If they were
887 : : * not volatile, they could be reordered which could lead to
888 : : * using invalid descriptor fields when read from rxd.
889 : : */
890 : 0 : rxdp = &rx_ring[rx_id];
891 : 0 : status = rxdp->status;
892 [ # # ]: 0 : if (! (status & E1000_RXD_STAT_DD))
893 : : break;
894 : 0 : rxd = *rxdp;
895 : :
896 : : /*
897 : : * Descriptor done.
898 : : *
899 : : * Allocate a new mbuf to replenish the RX ring descriptor.
900 : : * If the allocation fails:
901 : : * - arrange for that RX descriptor to be the first one
902 : : * being parsed the next time the receive function is
903 : : * invoked [on the same queue].
904 : : *
905 : : * - Stop parsing the RX ring and return immediately.
906 : : *
907 : : * This policy does not drop the packet received in the RX
908 : : * descriptor for which the allocation of a new mbuf failed.
909 : : * Thus, it allows that packet to be later retrieved if
910 : : * mbuf have been freed in the mean time.
911 : : * As a side effect, holding RX descriptors instead of
912 : : * systematically giving them back to the NIC may lead to
913 : : * RX ring exhaustion situations.
914 : : * However, the NIC can gracefully prevent such situations
915 : : * to happen by sending specific "back-pressure" flow control
916 : : * frames to its peer(s).
917 : : */
918 : : PMD_RX_LOG(DEBUG, "port_id=%u queue_id=%u rx_id=%u "
919 : : "status=0x%x data_len=%u",
920 : : (unsigned) rxq->port_id, (unsigned) rxq->queue_id,
921 : : (unsigned) rx_id, (unsigned) status,
922 : : (unsigned) rte_le_to_cpu_16(rxd.length));
923 : :
924 : 0 : nmb = rte_mbuf_raw_alloc(rxq->mb_pool);
925 [ # # ]: 0 : if (nmb == NULL) {
926 : : PMD_RX_LOG(DEBUG, "RX mbuf alloc failed port_id=%u "
927 : : "queue_id=%u", (unsigned) rxq->port_id,
928 : : (unsigned) rxq->queue_id);
929 : 0 : rte_eth_devices[rxq->port_id].data->rx_mbuf_alloc_failed++;
930 : 0 : break;
931 : : }
932 : :
933 : 0 : nb_hold++;
934 : 0 : rxe = &sw_ring[rx_id];
935 : 0 : rx_id++;
936 [ # # ]: 0 : if (rx_id == rxq->nb_rx_desc)
937 : : rx_id = 0;
938 : :
939 : : /* Prefetch next mbuf while processing current one. */
940 : 0 : rte_em_prefetch(sw_ring[rx_id].mbuf);
941 : :
942 : : /*
943 : : * When next RX descriptor is on a cache-line boundary,
944 : : * prefetch the next 4 RX descriptors and the next 8 pointers
945 : : * to mbufs.
946 : : */
947 [ # # ]: 0 : if ((rx_id & 0x3) == 0) {
948 : 0 : rte_em_prefetch(&rx_ring[rx_id]);
949 : : rte_em_prefetch(&sw_ring[rx_id]);
950 : : }
951 : :
952 : : /*
953 : : * Update RX descriptor with the physical address of the new
954 : : * data buffer of the new allocated mbuf.
955 : : */
956 : 0 : rxm = rxe->mbuf;
957 [ # # ]: 0 : rxe->mbuf = nmb;
958 : : dma = rte_cpu_to_le_64(rte_mbuf_data_iova_default(nmb));
959 : 0 : rxdp->buffer_addr = dma;
960 : 0 : rxdp->status = 0;
961 : :
962 : : /*
963 : : * Set data length & data buffer address of mbuf.
964 : : */
965 : : data_len = rte_le_to_cpu_16(rxd.length);
966 : 0 : rxm->data_len = data_len;
967 : 0 : rxm->data_off = RTE_PKTMBUF_HEADROOM;
968 : :
969 : : /*
970 : : * If this is the first buffer of the received packet,
971 : : * set the pointer to the first mbuf of the packet and
972 : : * initialize its context.
973 : : * Otherwise, update the total length and the number of segments
974 : : * of the current scattered packet, and update the pointer to
975 : : * the last mbuf of the current packet.
976 : : */
977 [ # # ]: 0 : if (first_seg == NULL) {
978 : : first_seg = rxm;
979 : 0 : first_seg->pkt_len = data_len;
980 : 0 : first_seg->nb_segs = 1;
981 : : } else {
982 : 0 : first_seg->pkt_len += data_len;
983 : 0 : first_seg->nb_segs++;
984 : 0 : last_seg->next = rxm;
985 : : }
986 : :
987 : : /*
988 : : * If this is not the last buffer of the received packet,
989 : : * update the pointer to the last mbuf of the current scattered
990 : : * packet and continue to parse the RX ring.
991 : : */
992 [ # # ]: 0 : if (! (status & E1000_RXD_STAT_EOP)) {
993 : : last_seg = rxm;
994 : 0 : goto next_desc;
995 : : }
996 : :
997 : : /*
998 : : * This is the last buffer of the received packet.
999 : : * If the CRC is not stripped by the hardware:
1000 : : * - Subtract the CRC length from the total packet length.
1001 : : * - If the last buffer only contains the whole CRC or a part
1002 : : * of it, free the mbuf associated to the last buffer.
1003 : : * If part of the CRC is also contained in the previous
1004 : : * mbuf, subtract the length of that CRC part from the
1005 : : * data length of the previous mbuf.
1006 : : */
1007 : 0 : rxm->next = NULL;
1008 [ # # ]: 0 : if (unlikely(rxq->crc_len > 0)) {
1009 : 0 : first_seg->pkt_len -= RTE_ETHER_CRC_LEN;
1010 [ # # ]: 0 : if (data_len <= RTE_ETHER_CRC_LEN) {
1011 : : rte_pktmbuf_free_seg(rxm);
1012 : 0 : first_seg->nb_segs--;
1013 : 0 : last_seg->data_len = (uint16_t)
1014 : 0 : (last_seg->data_len -
1015 : : (RTE_ETHER_CRC_LEN - data_len));
1016 : 0 : last_seg->next = NULL;
1017 : : } else
1018 : 0 : rxm->data_len = (uint16_t)
1019 : : (data_len - RTE_ETHER_CRC_LEN);
1020 : : }
1021 : :
1022 : : /*
1023 : : * Initialize the first mbuf of the returned packet:
1024 : : * - RX port identifier,
1025 : : * - hardware offload data, if any:
1026 : : * - IP checksum flag,
1027 : : * - VLAN TCI, if any,
1028 : : * - error flags.
1029 : : */
1030 [ # # ]: 0 : first_seg->port = rxq->port_id;
1031 : :
1032 : : first_seg->ol_flags = rx_desc_status_to_pkt_flags(status);
1033 : 0 : first_seg->ol_flags = first_seg->ol_flags |
1034 : : rx_desc_error_to_pkt_flags(rxd.errors);
1035 : :
1036 : : /* Only valid if RTE_MBUF_F_RX_VLAN set in pkt_flags */
1037 : 0 : first_seg->vlan_tci = rte_le_to_cpu_16(rxd.special);
1038 : :
1039 : : /* Prefetch data of first segment, if configured to do so. */
1040 : 0 : rte_packet_prefetch((char *)first_seg->buf_addr +
1041 : : first_seg->data_off);
1042 : :
1043 : : /*
1044 : : * Store the mbuf address into the next entry of the array
1045 : : * of returned packets.
1046 : : */
1047 : 0 : rx_pkts[nb_rx++] = first_seg;
1048 : :
1049 : : /*
1050 : : * Setup receipt context for a new packet.
1051 : : */
1052 : : first_seg = NULL;
1053 : : }
1054 : :
1055 : : /*
1056 : : * Record index of the next RX descriptor to probe.
1057 : : */
1058 : 0 : rxq->rx_tail = rx_id;
1059 : :
1060 : : /*
1061 : : * Save receive context.
1062 : : */
1063 : 0 : rxq->pkt_first_seg = first_seg;
1064 : 0 : rxq->pkt_last_seg = last_seg;
1065 : :
1066 : : /*
1067 : : * If the number of free RX descriptors is greater than the RX free
1068 : : * threshold of the queue, advance the Receive Descriptor Tail (RDT)
1069 : : * register.
1070 : : * Update the RDT with the value of the last processed RX descriptor
1071 : : * minus 1, to guarantee that the RDT register is never equal to the
1072 : : * RDH register, which creates a "full" ring situation from the
1073 : : * hardware point of view...
1074 : : */
1075 : 0 : nb_hold = (uint16_t) (nb_hold + rxq->nb_rx_hold);
1076 [ # # ]: 0 : if (nb_hold > rxq->rx_free_thresh) {
1077 : : PMD_RX_LOG(DEBUG, "port_id=%u queue_id=%u rx_tail=%u "
1078 : : "nb_hold=%u nb_rx=%u",
1079 : : (unsigned) rxq->port_id, (unsigned) rxq->queue_id,
1080 : : (unsigned) rx_id, (unsigned) nb_hold,
1081 : : (unsigned) nb_rx);
1082 [ # # ]: 0 : rx_id = (uint16_t) ((rx_id == 0) ?
1083 : 0 : (rxq->nb_rx_desc - 1) : (rx_id - 1));
1084 : 0 : E1000_PCI_REG_WRITE(rxq->rdt_reg_addr, rx_id);
1085 : : nb_hold = 0;
1086 : : }
1087 : 0 : rxq->nb_rx_hold = nb_hold;
1088 : 0 : return nb_rx;
1089 : : }
1090 : :
1091 : : #define EM_MAX_BUF_SIZE 16384
1092 : : #define EM_RCTL_FLXBUF_STEP 1024
1093 : :
1094 : : static void
1095 : 0 : em_tx_queue_release_mbufs(struct em_tx_queue *txq)
1096 : : {
1097 : : unsigned i;
1098 : :
1099 [ # # ]: 0 : if (txq->sw_ring != NULL) {
1100 [ # # ]: 0 : for (i = 0; i != txq->nb_tx_desc; i++) {
1101 [ # # ]: 0 : if (txq->sw_ring[i].mbuf != NULL) {
1102 : : rte_pktmbuf_free_seg(txq->sw_ring[i].mbuf);
1103 : 0 : txq->sw_ring[i].mbuf = NULL;
1104 : : }
1105 : : }
1106 : : }
1107 : 0 : }
1108 : :
1109 : : static void
1110 : 0 : em_tx_queue_release(struct em_tx_queue *txq)
1111 : : {
1112 [ # # ]: 0 : if (txq != NULL) {
1113 : 0 : em_tx_queue_release_mbufs(txq);
1114 : 0 : rte_free(txq->sw_ring);
1115 : 0 : rte_memzone_free(txq->mz);
1116 : 0 : rte_free(txq);
1117 : : }
1118 : 0 : }
1119 : :
1120 : : void
1121 : 0 : eth_em_tx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
1122 : : {
1123 : 0 : em_tx_queue_release(dev->data->tx_queues[qid]);
1124 : 0 : }
1125 : :
1126 : : /* (Re)set dynamic em_tx_queue fields to defaults */
1127 : : static void
1128 : 0 : em_reset_tx_queue(struct em_tx_queue *txq)
1129 : : {
1130 : : uint16_t i, nb_desc, prev;
1131 : : static const struct e1000_data_desc txd_init = {
1132 : : .upper.fields = {.status = E1000_TXD_STAT_DD},
1133 : : };
1134 : :
1135 : 0 : nb_desc = txq->nb_tx_desc;
1136 : :
1137 : : /* Initialize ring entries */
1138 : :
1139 : 0 : prev = (uint16_t) (nb_desc - 1);
1140 : :
1141 [ # # ]: 0 : for (i = 0; i < nb_desc; i++) {
1142 : 0 : txq->tx_ring[i] = txd_init;
1143 : 0 : txq->sw_ring[i].mbuf = NULL;
1144 : 0 : txq->sw_ring[i].last_id = i;
1145 : 0 : txq->sw_ring[prev].next_id = i;
1146 : : prev = i;
1147 : : }
1148 : :
1149 : : /*
1150 : : * Always allow 1 descriptor to be un-allocated to avoid
1151 : : * a H/W race condition
1152 : : */
1153 : 0 : txq->nb_tx_free = (uint16_t)(nb_desc - 1);
1154 : 0 : txq->last_desc_cleaned = (uint16_t)(nb_desc - 1);
1155 : 0 : txq->nb_tx_used = 0;
1156 : 0 : txq->tx_tail = 0;
1157 : :
1158 : 0 : memset((void*)&txq->ctx_cache, 0, sizeof (txq->ctx_cache));
1159 : 0 : }
1160 : :
1161 : : uint64_t
1162 : 0 : em_get_tx_port_offloads_capa(struct rte_eth_dev *dev)
1163 : : {
1164 : : uint64_t tx_offload_capa;
1165 : :
1166 : : RTE_SET_USED(dev);
1167 : : tx_offload_capa =
1168 : : RTE_ETH_TX_OFFLOAD_MULTI_SEGS |
1169 : : RTE_ETH_TX_OFFLOAD_VLAN_INSERT |
1170 : : RTE_ETH_TX_OFFLOAD_IPV4_CKSUM |
1171 : : RTE_ETH_TX_OFFLOAD_UDP_CKSUM |
1172 : : RTE_ETH_TX_OFFLOAD_TCP_CKSUM;
1173 : :
1174 : 0 : return tx_offload_capa;
1175 : : }
1176 : :
1177 : : uint64_t
1178 : 0 : em_get_tx_queue_offloads_capa(struct rte_eth_dev *dev)
1179 : : {
1180 : : uint64_t tx_queue_offload_capa;
1181 : :
1182 : : /*
1183 : : * As only one Tx queue can be used, let per queue offloading
1184 : : * capability be same to per port queue offloading capability
1185 : : * for better convenience.
1186 : : */
1187 : 0 : tx_queue_offload_capa = em_get_tx_port_offloads_capa(dev);
1188 : :
1189 : 0 : return tx_queue_offload_capa;
1190 : : }
1191 : :
1192 : : int
1193 : 0 : eth_em_tx_queue_setup(struct rte_eth_dev *dev,
1194 : : uint16_t queue_idx,
1195 : : uint16_t nb_desc,
1196 : : unsigned int socket_id,
1197 : : const struct rte_eth_txconf *tx_conf)
1198 : : {
1199 : : const struct rte_memzone *tz;
1200 : : struct em_tx_queue *txq;
1201 : : struct e1000_hw *hw;
1202 : : uint32_t tsize;
1203 : : uint16_t tx_rs_thresh, tx_free_thresh;
1204 : : uint64_t offloads;
1205 : :
1206 : 0 : hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1207 : :
1208 : 0 : offloads = tx_conf->offloads | dev->data->dev_conf.txmode.offloads;
1209 : :
1210 : : /*
1211 : : * Validate number of transmit descriptors.
1212 : : * It must not exceed hardware maximum, and must be multiple
1213 : : * of E1000_ALIGN.
1214 : : */
1215 [ # # ]: 0 : if (nb_desc % EM_TXD_ALIGN != 0 ||
1216 [ # # ]: 0 : (nb_desc > E1000_MAX_RING_DESC) ||
1217 : : (nb_desc < E1000_MIN_RING_DESC)) {
1218 : : return -(EINVAL);
1219 : : }
1220 : :
1221 : 0 : tx_free_thresh = tx_conf->tx_free_thresh;
1222 [ # # ]: 0 : if (tx_free_thresh == 0)
1223 : 0 : tx_free_thresh = (uint16_t)RTE_MIN(nb_desc / 4,
1224 : : DEFAULT_TX_FREE_THRESH);
1225 : :
1226 : 0 : tx_rs_thresh = tx_conf->tx_rs_thresh;
1227 [ # # ]: 0 : if (tx_rs_thresh == 0)
1228 : 0 : tx_rs_thresh = (uint16_t)RTE_MIN(tx_free_thresh,
1229 : : DEFAULT_TX_RS_THRESH);
1230 : :
1231 [ # # ]: 0 : if (tx_free_thresh >= (nb_desc - 3)) {
1232 : 0 : PMD_INIT_LOG(ERR, "tx_free_thresh must be less than the "
1233 : : "number of TX descriptors minus 3. "
1234 : : "(tx_free_thresh=%u port=%d queue=%d)",
1235 : : (unsigned int)tx_free_thresh,
1236 : : (int)dev->data->port_id, (int)queue_idx);
1237 : 0 : return -(EINVAL);
1238 : : }
1239 [ # # ]: 0 : if (tx_rs_thresh > tx_free_thresh) {
1240 : 0 : PMD_INIT_LOG(ERR, "tx_rs_thresh must be less than or equal to "
1241 : : "tx_free_thresh. (tx_free_thresh=%u "
1242 : : "tx_rs_thresh=%u port=%d queue=%d)",
1243 : : (unsigned int)tx_free_thresh,
1244 : : (unsigned int)tx_rs_thresh,
1245 : : (int)dev->data->port_id,
1246 : : (int)queue_idx);
1247 : 0 : return -(EINVAL);
1248 : : }
1249 : :
1250 : : /*
1251 : : * If rs_bit_thresh is greater than 1, then TX WTHRESH should be
1252 : : * set to 0. If WTHRESH is greater than zero, the RS bit is ignored
1253 : : * by the NIC and all descriptors are written back after the NIC
1254 : : * accumulates WTHRESH descriptors.
1255 : : */
1256 [ # # # # ]: 0 : if (tx_conf->tx_thresh.wthresh != 0 && tx_rs_thresh != 1) {
1257 : 0 : PMD_INIT_LOG(ERR, "TX WTHRESH must be set to 0 if "
1258 : : "tx_rs_thresh is greater than 1. (tx_rs_thresh=%u "
1259 : : "port=%d queue=%d)", (unsigned int)tx_rs_thresh,
1260 : : (int)dev->data->port_id, (int)queue_idx);
1261 : 0 : return -(EINVAL);
1262 : : }
1263 : :
1264 : : /* Free memory prior to re-allocation if needed... */
1265 [ # # ]: 0 : if (dev->data->tx_queues[queue_idx] != NULL) {
1266 : 0 : em_tx_queue_release(dev->data->tx_queues[queue_idx]);
1267 : 0 : dev->data->tx_queues[queue_idx] = NULL;
1268 : : }
1269 : :
1270 : : /*
1271 : : * Allocate TX ring hardware descriptors. A memzone large enough to
1272 : : * handle the maximum ring size is allocated in order to allow for
1273 : : * resizing in later calls to the queue setup function.
1274 : : */
1275 : : tsize = sizeof(txq->tx_ring[0]) * E1000_MAX_RING_DESC;
1276 : 0 : tz = rte_eth_dma_zone_reserve(dev, "tx_ring", queue_idx, tsize,
1277 : : RTE_CACHE_LINE_SIZE, socket_id);
1278 [ # # ]: 0 : if (tz == NULL)
1279 : : return -ENOMEM;
1280 : :
1281 : : /* Allocate the tx queue data structure. */
1282 [ # # ]: 0 : if ((txq = rte_zmalloc("ethdev TX queue", sizeof(*txq),
1283 : : RTE_CACHE_LINE_SIZE)) == NULL)
1284 : : return -ENOMEM;
1285 : :
1286 : 0 : txq->mz = tz;
1287 : : /* Allocate software ring */
1288 [ # # ]: 0 : if ((txq->sw_ring = rte_zmalloc("txq->sw_ring",
1289 : : sizeof(txq->sw_ring[0]) * nb_desc,
1290 : : RTE_CACHE_LINE_SIZE)) == NULL) {
1291 : 0 : em_tx_queue_release(txq);
1292 : 0 : return -ENOMEM;
1293 : : }
1294 : :
1295 : 0 : txq->nb_tx_desc = nb_desc;
1296 : 0 : txq->tx_free_thresh = tx_free_thresh;
1297 : 0 : txq->tx_rs_thresh = tx_rs_thresh;
1298 : 0 : txq->pthresh = tx_conf->tx_thresh.pthresh;
1299 : 0 : txq->hthresh = tx_conf->tx_thresh.hthresh;
1300 : 0 : txq->wthresh = tx_conf->tx_thresh.wthresh;
1301 : 0 : txq->queue_id = queue_idx;
1302 : 0 : txq->port_id = dev->data->port_id;
1303 : :
1304 [ # # ]: 0 : txq->tdt_reg_addr = E1000_PCI_REG_ADDR(hw, E1000_TDT(queue_idx));
1305 : 0 : txq->tx_ring_phys_addr = tz->iova;
1306 : 0 : txq->tx_ring = (struct e1000_data_desc *) tz->addr;
1307 : :
1308 : 0 : PMD_INIT_LOG(DEBUG, "sw_ring=%p hw_ring=%p dma_addr=0x%"PRIx64,
1309 : : txq->sw_ring, txq->tx_ring, txq->tx_ring_phys_addr);
1310 : :
1311 : 0 : em_reset_tx_queue(txq);
1312 : :
1313 : 0 : dev->data->tx_queues[queue_idx] = txq;
1314 : 0 : txq->offloads = offloads;
1315 : 0 : return 0;
1316 : : }
1317 : :
1318 : : static void
1319 : 0 : em_rx_queue_release_mbufs(struct em_rx_queue *rxq)
1320 : : {
1321 : : unsigned i;
1322 : :
1323 [ # # ]: 0 : if (rxq->sw_ring != NULL) {
1324 [ # # ]: 0 : for (i = 0; i != rxq->nb_rx_desc; i++) {
1325 [ # # ]: 0 : if (rxq->sw_ring[i].mbuf != NULL) {
1326 : : rte_pktmbuf_free_seg(rxq->sw_ring[i].mbuf);
1327 : 0 : rxq->sw_ring[i].mbuf = NULL;
1328 : : }
1329 : : }
1330 : : }
1331 : 0 : }
1332 : :
1333 : : static void
1334 : 0 : em_rx_queue_release(struct em_rx_queue *rxq)
1335 : : {
1336 [ # # ]: 0 : if (rxq != NULL) {
1337 : 0 : em_rx_queue_release_mbufs(rxq);
1338 : 0 : rte_free(rxq->sw_ring);
1339 : 0 : rte_memzone_free(rxq->mz);
1340 : 0 : rte_free(rxq);
1341 : : }
1342 : 0 : }
1343 : :
1344 : : void
1345 : 0 : eth_em_rx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
1346 : : {
1347 : 0 : em_rx_queue_release(dev->data->rx_queues[qid]);
1348 : 0 : }
1349 : :
1350 : : /* Reset dynamic em_rx_queue fields back to defaults */
1351 : : static void
1352 : : em_reset_rx_queue(struct em_rx_queue *rxq)
1353 : : {
1354 : 0 : rxq->rx_tail = 0;
1355 : 0 : rxq->nb_rx_hold = 0;
1356 : 0 : rxq->pkt_first_seg = NULL;
1357 : 0 : rxq->pkt_last_seg = NULL;
1358 : 0 : }
1359 : :
1360 : : uint64_t
1361 : 0 : em_get_rx_port_offloads_capa(void)
1362 : : {
1363 : : uint64_t rx_offload_capa;
1364 : :
1365 : : rx_offload_capa =
1366 : : RTE_ETH_RX_OFFLOAD_VLAN_STRIP |
1367 : : RTE_ETH_RX_OFFLOAD_VLAN_FILTER |
1368 : : RTE_ETH_RX_OFFLOAD_IPV4_CKSUM |
1369 : : RTE_ETH_RX_OFFLOAD_UDP_CKSUM |
1370 : : RTE_ETH_RX_OFFLOAD_TCP_CKSUM |
1371 : : RTE_ETH_RX_OFFLOAD_KEEP_CRC |
1372 : : RTE_ETH_RX_OFFLOAD_SCATTER;
1373 : :
1374 : 0 : return rx_offload_capa;
1375 : : }
1376 : :
1377 : : uint64_t
1378 : 0 : em_get_rx_queue_offloads_capa(void)
1379 : : {
1380 : : uint64_t rx_queue_offload_capa;
1381 : :
1382 : : /*
1383 : : * As only one Rx queue can be used, let per queue offloading
1384 : : * capability be same to per port queue offloading capability
1385 : : * for better convenience.
1386 : : */
1387 : 0 : rx_queue_offload_capa = em_get_rx_port_offloads_capa();
1388 : :
1389 : 0 : return rx_queue_offload_capa;
1390 : : }
1391 : :
1392 : : int
1393 : 0 : eth_em_rx_queue_setup(struct rte_eth_dev *dev,
1394 : : uint16_t queue_idx,
1395 : : uint16_t nb_desc,
1396 : : unsigned int socket_id,
1397 : : const struct rte_eth_rxconf *rx_conf,
1398 : : struct rte_mempool *mp)
1399 : : {
1400 : : const struct rte_memzone *rz;
1401 : : struct em_rx_queue *rxq;
1402 : : struct e1000_hw *hw;
1403 : : uint32_t rsize;
1404 : : uint64_t offloads;
1405 : :
1406 : 0 : hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1407 : :
1408 : 0 : offloads = rx_conf->offloads | dev->data->dev_conf.rxmode.offloads;
1409 : :
1410 : : /*
1411 : : * Validate number of receive descriptors.
1412 : : * It must not exceed hardware maximum, and must be multiple
1413 : : * of E1000_ALIGN.
1414 : : */
1415 [ # # ]: 0 : if (nb_desc % EM_RXD_ALIGN != 0 ||
1416 [ # # ]: 0 : (nb_desc > E1000_MAX_RING_DESC) ||
1417 : : (nb_desc < E1000_MIN_RING_DESC)) {
1418 : : return -EINVAL;
1419 : : }
1420 : :
1421 : : /*
1422 : : * EM devices don't support drop_en functionality.
1423 : : * It's an optimization that does nothing on single-queue devices,
1424 : : * so just log the issue and carry on.
1425 : : */
1426 [ # # ]: 0 : if (rx_conf->rx_drop_en) {
1427 : 0 : PMD_INIT_LOG(NOTICE, "drop_en functionality not supported by "
1428 : : "device");
1429 : : }
1430 : :
1431 : : /* Free memory prior to re-allocation if needed. */
1432 [ # # ]: 0 : if (dev->data->rx_queues[queue_idx] != NULL) {
1433 : 0 : em_rx_queue_release(dev->data->rx_queues[queue_idx]);
1434 : 0 : dev->data->rx_queues[queue_idx] = NULL;
1435 : : }
1436 : :
1437 : : /* Allocate RX ring for max possible mumber of hardware descriptors. */
1438 : : rsize = sizeof(rxq->rx_ring[0]) * E1000_MAX_RING_DESC;
1439 : 0 : rz = rte_eth_dma_zone_reserve(dev, "rx_ring", queue_idx, rsize,
1440 : : RTE_CACHE_LINE_SIZE, socket_id);
1441 [ # # ]: 0 : if (rz == NULL)
1442 : : return -ENOMEM;
1443 : :
1444 : : /* Allocate the RX queue data structure. */
1445 [ # # ]: 0 : if ((rxq = rte_zmalloc("ethdev RX queue", sizeof(*rxq),
1446 : : RTE_CACHE_LINE_SIZE)) == NULL)
1447 : : return -ENOMEM;
1448 : :
1449 : 0 : rxq->mz = rz;
1450 : : /* Allocate software ring. */
1451 [ # # ]: 0 : if ((rxq->sw_ring = rte_zmalloc("rxq->sw_ring",
1452 : : sizeof (rxq->sw_ring[0]) * nb_desc,
1453 : : RTE_CACHE_LINE_SIZE)) == NULL) {
1454 : 0 : em_rx_queue_release(rxq);
1455 : 0 : return -ENOMEM;
1456 : : }
1457 : :
1458 : 0 : rxq->mb_pool = mp;
1459 : 0 : rxq->nb_rx_desc = nb_desc;
1460 : 0 : rxq->pthresh = rx_conf->rx_thresh.pthresh;
1461 : 0 : rxq->hthresh = rx_conf->rx_thresh.hthresh;
1462 : 0 : rxq->wthresh = rx_conf->rx_thresh.wthresh;
1463 : 0 : rxq->rx_free_thresh = rx_conf->rx_free_thresh;
1464 : 0 : rxq->queue_id = queue_idx;
1465 : 0 : rxq->port_id = dev->data->port_id;
1466 [ # # ]: 0 : if (dev->data->dev_conf.rxmode.offloads & RTE_ETH_RX_OFFLOAD_KEEP_CRC)
1467 : 0 : rxq->crc_len = RTE_ETHER_CRC_LEN;
1468 : : else
1469 : 0 : rxq->crc_len = 0;
1470 : :
1471 [ # # ]: 0 : rxq->rdt_reg_addr = E1000_PCI_REG_ADDR(hw, E1000_RDT(queue_idx));
1472 [ # # ]: 0 : rxq->rdh_reg_addr = E1000_PCI_REG_ADDR(hw, E1000_RDH(queue_idx));
1473 : 0 : rxq->rx_ring_phys_addr = rz->iova;
1474 : 0 : rxq->rx_ring = (struct e1000_rx_desc *) rz->addr;
1475 : :
1476 : 0 : PMD_INIT_LOG(DEBUG, "sw_ring=%p hw_ring=%p dma_addr=0x%"PRIx64,
1477 : : rxq->sw_ring, rxq->rx_ring, rxq->rx_ring_phys_addr);
1478 : :
1479 : 0 : dev->data->rx_queues[queue_idx] = rxq;
1480 : : em_reset_rx_queue(rxq);
1481 : 0 : rxq->offloads = offloads;
1482 : :
1483 : 0 : return 0;
1484 : : }
1485 : :
1486 : : int
1487 : 0 : eth_em_rx_queue_count(void *rx_queue)
1488 : : {
1489 : : #define EM_RXQ_SCAN_INTERVAL 4
1490 : : volatile struct e1000_rx_desc *rxdp;
1491 : : struct em_rx_queue *rxq;
1492 : : uint32_t desc = 0;
1493 : :
1494 : : rxq = rx_queue;
1495 : 0 : rxdp = &(rxq->rx_ring[rxq->rx_tail]);
1496 : :
1497 [ # # ]: 0 : while ((desc < rxq->nb_rx_desc) &&
1498 [ # # ]: 0 : (rxdp->status & E1000_RXD_STAT_DD)) {
1499 : 0 : desc += EM_RXQ_SCAN_INTERVAL;
1500 : 0 : rxdp += EM_RXQ_SCAN_INTERVAL;
1501 [ # # ]: 0 : if (rxq->rx_tail + desc >= rxq->nb_rx_desc)
1502 : 0 : rxdp = &(rxq->rx_ring[rxq->rx_tail +
1503 : 0 : desc - rxq->nb_rx_desc]);
1504 : : }
1505 : :
1506 : 0 : return desc;
1507 : : }
1508 : :
1509 : : int
1510 : 0 : eth_em_rx_descriptor_status(void *rx_queue, uint16_t offset)
1511 : : {
1512 : : struct em_rx_queue *rxq = rx_queue;
1513 : : volatile uint8_t *status;
1514 : : uint32_t desc;
1515 : :
1516 [ # # ]: 0 : if (unlikely(offset >= rxq->nb_rx_desc))
1517 : : return -EINVAL;
1518 : :
1519 [ # # ]: 0 : if (offset >= rxq->nb_rx_desc - rxq->nb_rx_hold)
1520 : : return RTE_ETH_RX_DESC_UNAVAIL;
1521 : :
1522 : 0 : desc = rxq->rx_tail + offset;
1523 [ # # ]: 0 : if (desc >= rxq->nb_rx_desc)
1524 : 0 : desc -= rxq->nb_rx_desc;
1525 : :
1526 : 0 : status = &rxq->rx_ring[desc].status;
1527 [ # # ]: 0 : if (*status & E1000_RXD_STAT_DD)
1528 : 0 : return RTE_ETH_RX_DESC_DONE;
1529 : :
1530 : : return RTE_ETH_RX_DESC_AVAIL;
1531 : : }
1532 : :
1533 : : int
1534 : 0 : eth_em_tx_descriptor_status(void *tx_queue, uint16_t offset)
1535 : : {
1536 : : struct em_tx_queue *txq = tx_queue;
1537 : : volatile uint8_t *status;
1538 : : uint32_t desc;
1539 : :
1540 [ # # ]: 0 : if (unlikely(offset >= txq->nb_tx_desc))
1541 : : return -EINVAL;
1542 : :
1543 : 0 : desc = txq->tx_tail + offset;
1544 : : /* go to next desc that has the RS bit */
1545 : 0 : desc = ((desc + txq->tx_rs_thresh - 1) / txq->tx_rs_thresh) *
1546 : : txq->tx_rs_thresh;
1547 [ # # ]: 0 : if (desc >= txq->nb_tx_desc) {
1548 : 0 : desc -= txq->nb_tx_desc;
1549 [ # # ]: 0 : if (desc >= txq->nb_tx_desc)
1550 : 0 : desc -= txq->nb_tx_desc;
1551 : : }
1552 : :
1553 : 0 : status = &txq->tx_ring[desc].upper.fields.status;
1554 [ # # ]: 0 : if (*status & E1000_TXD_STAT_DD)
1555 : 0 : return RTE_ETH_TX_DESC_DONE;
1556 : :
1557 : : return RTE_ETH_TX_DESC_FULL;
1558 : : }
1559 : :
1560 : : void
1561 : 0 : em_dev_clear_queues(struct rte_eth_dev *dev)
1562 : : {
1563 : : uint16_t i;
1564 : : struct em_tx_queue *txq;
1565 : : struct em_rx_queue *rxq;
1566 : :
1567 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
1568 : 0 : txq = dev->data->tx_queues[i];
1569 [ # # ]: 0 : if (txq != NULL) {
1570 : 0 : em_tx_queue_release_mbufs(txq);
1571 : 0 : em_reset_tx_queue(txq);
1572 : : }
1573 : :
1574 : 0 : dev->data->tx_queue_state[i] = RTE_ETH_QUEUE_STATE_STOPPED;
1575 : : }
1576 : :
1577 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
1578 : 0 : rxq = dev->data->rx_queues[i];
1579 [ # # ]: 0 : if (rxq != NULL) {
1580 : 0 : em_rx_queue_release_mbufs(rxq);
1581 : : em_reset_rx_queue(rxq);
1582 : : }
1583 : :
1584 : 0 : dev->data->rx_queue_state[i] = RTE_ETH_QUEUE_STATE_STOPPED;
1585 : : }
1586 : 0 : }
1587 : :
1588 : : void
1589 : 0 : em_dev_free_queues(struct rte_eth_dev *dev)
1590 : : {
1591 : : uint16_t i;
1592 : :
1593 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
1594 : 0 : eth_em_rx_queue_release(dev, i);
1595 : 0 : dev->data->rx_queues[i] = NULL;
1596 : : }
1597 : 0 : dev->data->nb_rx_queues = 0;
1598 : :
1599 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
1600 : 0 : eth_em_tx_queue_release(dev, i);
1601 : 0 : dev->data->tx_queues[i] = NULL;
1602 : : }
1603 : 0 : dev->data->nb_tx_queues = 0;
1604 : 0 : }
1605 : :
1606 : : /*
1607 : : * Takes as input/output parameter RX buffer size.
1608 : : * Returns (BSIZE | BSEX | FLXBUF) fields of RCTL register.
1609 : : */
1610 : : static uint32_t
1611 : : em_rctl_bsize(__rte_unused enum e1000_mac_type hwtyp, uint32_t *bufsz)
1612 : : {
1613 : : /*
1614 : : * For BSIZE & BSEX all configurable sizes are:
1615 : : * 16384: rctl |= (E1000_RCTL_SZ_16384 | E1000_RCTL_BSEX);
1616 : : * 8192: rctl |= (E1000_RCTL_SZ_8192 | E1000_RCTL_BSEX);
1617 : : * 4096: rctl |= (E1000_RCTL_SZ_4096 | E1000_RCTL_BSEX);
1618 : : * 2048: rctl |= E1000_RCTL_SZ_2048;
1619 : : * 1024: rctl |= E1000_RCTL_SZ_1024;
1620 : : * 512: rctl |= E1000_RCTL_SZ_512;
1621 : : * 256: rctl |= E1000_RCTL_SZ_256;
1622 : : */
1623 : : static const struct {
1624 : : uint32_t bufsz;
1625 : : uint32_t rctl;
1626 : : } bufsz_to_rctl[] = {
1627 : : {16384, (E1000_RCTL_SZ_16384 | E1000_RCTL_BSEX)},
1628 : : {8192, (E1000_RCTL_SZ_8192 | E1000_RCTL_BSEX)},
1629 : : {4096, (E1000_RCTL_SZ_4096 | E1000_RCTL_BSEX)},
1630 : : {2048, E1000_RCTL_SZ_2048},
1631 : : {1024, E1000_RCTL_SZ_1024},
1632 : : {512, E1000_RCTL_SZ_512},
1633 : : {256, E1000_RCTL_SZ_256},
1634 : : };
1635 : :
1636 : : int i;
1637 : : uint32_t rctl_bsize;
1638 : :
1639 : : rctl_bsize = *bufsz;
1640 : :
1641 : : /*
1642 : : * Starting from 82571 it is possible to specify RX buffer size
1643 : : * by RCTL.FLXBUF. When this field is different from zero, the
1644 : : * RX buffer size = RCTL.FLXBUF * 1K
1645 : : * (e.g. t is possible to specify RX buffer size 1,2,...,15KB).
1646 : : * It is working ok on real HW, but by some reason doesn't work
1647 : : * on VMware emulated 82574L.
1648 : : * So for now, always use BSIZE/BSEX to setup RX buffer size.
1649 : : * If you don't plan to use it on VMware emulated 82574L and
1650 : : * would like to specify RX buffer size in 1K granularity,
1651 : : * uncomment the following lines:
1652 : : * ***************************************************************
1653 : : * if (hwtyp >= e1000_82571 && hwtyp <= e1000_82574 &&
1654 : : * rctl_bsize >= EM_RCTL_FLXBUF_STEP) {
1655 : : * rctl_bsize /= EM_RCTL_FLXBUF_STEP;
1656 : : * *bufsz = rctl_bsize;
1657 : : * return (rctl_bsize << E1000_RCTL_FLXBUF_SHIFT &
1658 : : * E1000_RCTL_FLXBUF_MASK);
1659 : : * }
1660 : : * ***************************************************************
1661 : : */
1662 : :
1663 [ # # ]: 0 : for (i = 0; i != sizeof(bufsz_to_rctl) / sizeof(bufsz_to_rctl[0]);
1664 : 0 : i++) {
1665 [ # # ]: 0 : if (rctl_bsize >= bufsz_to_rctl[i].bufsz) {
1666 : : *bufsz = bufsz_to_rctl[i].bufsz;
1667 : 0 : return bufsz_to_rctl[i].rctl;
1668 : : }
1669 : : }
1670 : :
1671 : : /* Should never happen. */
1672 : : return -EINVAL;
1673 : : }
1674 : :
1675 : : static int
1676 : 0 : em_alloc_rx_queue_mbufs(struct em_rx_queue *rxq)
1677 : : {
1678 : 0 : struct em_rx_entry *rxe = rxq->sw_ring;
1679 : : uint64_t dma_addr;
1680 : : unsigned i;
1681 : : static const struct e1000_rx_desc rxd_init = {
1682 : : .buffer_addr = 0,
1683 : : };
1684 : :
1685 : : /* Initialize software ring entries */
1686 [ # # ]: 0 : for (i = 0; i < rxq->nb_rx_desc; i++) {
1687 : : volatile struct e1000_rx_desc *rxd;
1688 : 0 : struct rte_mbuf *mbuf = rte_mbuf_raw_alloc(rxq->mb_pool);
1689 : :
1690 [ # # ]: 0 : if (mbuf == NULL) {
1691 : 0 : PMD_INIT_LOG(ERR, "RX mbuf alloc failed "
1692 : : "queue_id=%hu", rxq->queue_id);
1693 : 0 : return -ENOMEM;
1694 : : }
1695 : :
1696 : : dma_addr =
1697 : : rte_cpu_to_le_64(rte_mbuf_data_iova_default(mbuf));
1698 : :
1699 : : /* Clear HW ring memory */
1700 : 0 : rxq->rx_ring[i] = rxd_init;
1701 : :
1702 : : rxd = &rxq->rx_ring[i];
1703 : 0 : rxd->buffer_addr = dma_addr;
1704 : 0 : rxe[i].mbuf = mbuf;
1705 : : }
1706 : :
1707 : : return 0;
1708 : : }
1709 : :
1710 : : /*********************************************************************
1711 : : *
1712 : : * Enable receive unit.
1713 : : *
1714 : : **********************************************************************/
1715 : : int
1716 : 0 : eth_em_rx_init(struct rte_eth_dev *dev)
1717 : : {
1718 : : struct e1000_hw *hw;
1719 : : struct em_rx_queue *rxq;
1720 : : struct rte_eth_rxmode *rxmode;
1721 : : uint32_t rctl;
1722 : : uint32_t rfctl;
1723 : : uint32_t rxcsum;
1724 : : uint32_t rctl_bsize;
1725 : : uint16_t i;
1726 : : int ret;
1727 : :
1728 : 0 : hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1729 : : rxmode = &dev->data->dev_conf.rxmode;
1730 : :
1731 : : /*
1732 : : * Make sure receives are disabled while setting
1733 : : * up the descriptor ring.
1734 : : */
1735 : 0 : rctl = E1000_READ_REG(hw, E1000_RCTL);
1736 : 0 : E1000_WRITE_REG(hw, E1000_RCTL, rctl & ~E1000_RCTL_EN);
1737 : :
1738 : 0 : rfctl = E1000_READ_REG(hw, E1000_RFCTL);
1739 : :
1740 : : /* Disable extended descriptor type. */
1741 : 0 : rfctl &= ~E1000_RFCTL_EXTEN;
1742 : : /* Disable accelerated acknowledge */
1743 [ # # ]: 0 : if (hw->mac.type == e1000_82574)
1744 : 0 : rfctl |= E1000_RFCTL_ACK_DIS;
1745 : :
1746 : 0 : E1000_WRITE_REG(hw, E1000_RFCTL, rfctl);
1747 : :
1748 : : /*
1749 : : * XXX TEMPORARY WORKAROUND: on some systems with 82573
1750 : : * long latencies are observed, like Lenovo X60. This
1751 : : * change eliminates the problem, but since having positive
1752 : : * values in RDTR is a known source of problems on other
1753 : : * platforms another solution is being sought.
1754 : : */
1755 [ # # ]: 0 : if (hw->mac.type == e1000_82573)
1756 : 0 : E1000_WRITE_REG(hw, E1000_RDTR, 0x20);
1757 : :
1758 : 0 : dev->rx_pkt_burst = (eth_rx_burst_t)eth_em_recv_pkts;
1759 : :
1760 : : /* Determine RX bufsize. */
1761 : : rctl_bsize = EM_MAX_BUF_SIZE;
1762 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
1763 : : uint32_t buf_size;
1764 : :
1765 : 0 : rxq = dev->data->rx_queues[i];
1766 [ # # ]: 0 : buf_size = rte_pktmbuf_data_room_size(rxq->mb_pool) -
1767 : : RTE_PKTMBUF_HEADROOM;
1768 : 0 : rctl_bsize = RTE_MIN(rctl_bsize, buf_size);
1769 : : }
1770 : :
1771 : 0 : rctl |= em_rctl_bsize(hw->mac.type, &rctl_bsize);
1772 : :
1773 : : /* Configure and enable each RX queue. */
1774 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
1775 : : uint64_t bus_addr;
1776 : : uint32_t rxdctl;
1777 : :
1778 : 0 : rxq = dev->data->rx_queues[i];
1779 : :
1780 : : /* Allocate buffers for descriptor rings and setup queue */
1781 : 0 : ret = em_alloc_rx_queue_mbufs(rxq);
1782 [ # # ]: 0 : if (ret)
1783 : 0 : return ret;
1784 : :
1785 : : /*
1786 : : * Reset crc_len in case it was changed after queue setup by a
1787 : : * call to configure
1788 : : */
1789 [ # # ]: 0 : if (dev->data->dev_conf.rxmode.offloads & RTE_ETH_RX_OFFLOAD_KEEP_CRC)
1790 : 0 : rxq->crc_len = RTE_ETHER_CRC_LEN;
1791 : : else
1792 : 0 : rxq->crc_len = 0;
1793 : :
1794 : 0 : bus_addr = rxq->rx_ring_phys_addr;
1795 [ # # ]: 0 : E1000_WRITE_REG(hw, E1000_RDLEN(i),
1796 : : rxq->nb_rx_desc *
1797 : : sizeof(*rxq->rx_ring));
1798 [ # # ]: 0 : E1000_WRITE_REG(hw, E1000_RDBAH(i),
1799 : : (uint32_t)(bus_addr >> 32));
1800 [ # # ]: 0 : E1000_WRITE_REG(hw, E1000_RDBAL(i), (uint32_t)bus_addr);
1801 : :
1802 [ # # ]: 0 : E1000_WRITE_REG(hw, E1000_RDH(i), 0);
1803 [ # # ]: 0 : E1000_WRITE_REG(hw, E1000_RDT(i), rxq->nb_rx_desc - 1);
1804 : :
1805 : 0 : rxdctl = E1000_READ_REG(hw, E1000_RXDCTL(0));
1806 : 0 : rxdctl &= 0xFE000000;
1807 : 0 : rxdctl |= rxq->pthresh & 0x3F;
1808 : 0 : rxdctl |= (rxq->hthresh & 0x3F) << 8;
1809 : 0 : rxdctl |= (rxq->wthresh & 0x3F) << 16;
1810 : 0 : rxdctl |= E1000_RXDCTL_GRAN;
1811 [ # # ]: 0 : E1000_WRITE_REG(hw, E1000_RXDCTL(i), rxdctl);
1812 : :
1813 : 0 : dev->data->rx_queue_state[i] = RTE_ETH_QUEUE_STATE_STARTED;
1814 : :
1815 : : /*
1816 : : * Due to EM devices not having any sort of hardware
1817 : : * limit for packet length, jumbo frame of any size
1818 : : * can be accepted, thus we have to enable scattered
1819 : : * rx if jumbo frames are enabled (or if buffer size
1820 : : * is too small to accommodate non-jumbo packets)
1821 : : * to avoid splitting packets that don't fit into
1822 : : * one buffer.
1823 : : */
1824 [ # # # # ]: 0 : if (dev->data->mtu > RTE_ETHER_MTU ||
1825 : : rctl_bsize < RTE_ETHER_MAX_LEN) {
1826 [ # # ]: 0 : if (!dev->data->scattered_rx)
1827 : 0 : PMD_INIT_LOG(DEBUG, "forcing scatter mode");
1828 : 0 : dev->rx_pkt_burst =
1829 : : (eth_rx_burst_t)eth_em_recv_scattered_pkts;
1830 : 0 : dev->data->scattered_rx = 1;
1831 : : }
1832 : : }
1833 : :
1834 [ # # ]: 0 : if (dev->data->dev_conf.rxmode.offloads & RTE_ETH_RX_OFFLOAD_SCATTER) {
1835 [ # # ]: 0 : if (!dev->data->scattered_rx)
1836 : 0 : PMD_INIT_LOG(DEBUG, "forcing scatter mode");
1837 : 0 : dev->rx_pkt_burst = eth_em_recv_scattered_pkts;
1838 : 0 : dev->data->scattered_rx = 1;
1839 : : }
1840 : :
1841 : : /*
1842 : : * Setup the Checksum Register.
1843 : : * Receive Full-Packet Checksum Offload is mutually exclusive with RSS.
1844 : : */
1845 : 0 : rxcsum = E1000_READ_REG(hw, E1000_RXCSUM);
1846 : :
1847 [ # # ]: 0 : if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_CHECKSUM)
1848 : 0 : rxcsum |= E1000_RXCSUM_IPOFL;
1849 : : else
1850 : 0 : rxcsum &= ~E1000_RXCSUM_IPOFL;
1851 : 0 : E1000_WRITE_REG(hw, E1000_RXCSUM, rxcsum);
1852 : :
1853 : : /* No MRQ or RSS support for now */
1854 : :
1855 : : /* Set early receive threshold on appropriate hw */
1856 [ # # ]: 0 : if ((hw->mac.type == e1000_ich9lan ||
1857 [ # # ]: 0 : hw->mac.type == e1000_pch2lan ||
1858 : 0 : hw->mac.type == e1000_ich10lan) &&
1859 [ # # ]: 0 : dev->data->mtu > RTE_ETHER_MTU) {
1860 : 0 : u32 rxdctl = E1000_READ_REG(hw, E1000_RXDCTL(0));
1861 : 0 : E1000_WRITE_REG(hw, E1000_RXDCTL(0), rxdctl | 3);
1862 : 0 : E1000_WRITE_REG(hw, E1000_ERT, 0x100 | (1 << 13));
1863 : : }
1864 : :
1865 [ # # ]: 0 : if (hw->mac.type == e1000_pch2lan) {
1866 [ # # ]: 0 : if (dev->data->mtu > RTE_ETHER_MTU)
1867 : 0 : e1000_lv_jumbo_workaround_ich8lan(hw, TRUE);
1868 : : else
1869 : 0 : e1000_lv_jumbo_workaround_ich8lan(hw, FALSE);
1870 : : }
1871 : :
1872 : : /* Setup the Receive Control Register. */
1873 [ # # ]: 0 : if (dev->data->dev_conf.rxmode.offloads & RTE_ETH_RX_OFFLOAD_KEEP_CRC)
1874 : 0 : rctl &= ~E1000_RCTL_SECRC; /* Do not Strip Ethernet CRC. */
1875 : : else
1876 : 0 : rctl |= E1000_RCTL_SECRC; /* Strip Ethernet CRC. */
1877 : :
1878 : 0 : rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
1879 : 0 : rctl |= E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_LBM_NO |
1880 : : E1000_RCTL_RDMTS_HALF |
1881 : 0 : (hw->mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
1882 : :
1883 : : /* Make sure VLAN Filters are off. */
1884 : : rctl &= ~E1000_RCTL_VFE;
1885 : : /* Don't store bad packets. */
1886 : : rctl &= ~E1000_RCTL_SBP;
1887 : : /* Legacy descriptor type. */
1888 : : rctl &= ~E1000_RCTL_DTYP_MASK;
1889 : :
1890 : : /*
1891 : : * Configure support of jumbo frames, if any.
1892 : : */
1893 [ # # ]: 0 : if (dev->data->mtu > RTE_ETHER_MTU)
1894 : 0 : rctl |= E1000_RCTL_LPE;
1895 : : else
1896 : 0 : rctl &= ~E1000_RCTL_LPE;
1897 : :
1898 : : /* Enable Receives. */
1899 : 0 : E1000_WRITE_REG(hw, E1000_RCTL, rctl);
1900 : :
1901 : 0 : return 0;
1902 : : }
1903 : :
1904 : : /*********************************************************************
1905 : : *
1906 : : * Enable transmit unit.
1907 : : *
1908 : : **********************************************************************/
1909 : : void
1910 : 0 : eth_em_tx_init(struct rte_eth_dev *dev)
1911 : : {
1912 : : struct e1000_hw *hw;
1913 : : struct em_tx_queue *txq;
1914 : : uint32_t tctl;
1915 : : uint32_t txdctl;
1916 : : uint16_t i;
1917 : :
1918 : 0 : hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1919 : :
1920 : : /* Setup the Base and Length of the Tx Descriptor Rings. */
1921 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
1922 : : uint64_t bus_addr;
1923 : :
1924 : 0 : txq = dev->data->tx_queues[i];
1925 : 0 : bus_addr = txq->tx_ring_phys_addr;
1926 [ # # ]: 0 : E1000_WRITE_REG(hw, E1000_TDLEN(i),
1927 : : txq->nb_tx_desc *
1928 : : sizeof(*txq->tx_ring));
1929 [ # # ]: 0 : E1000_WRITE_REG(hw, E1000_TDBAH(i),
1930 : : (uint32_t)(bus_addr >> 32));
1931 [ # # ]: 0 : E1000_WRITE_REG(hw, E1000_TDBAL(i), (uint32_t)bus_addr);
1932 : :
1933 : : /* Setup the HW Tx Head and Tail descriptor pointers. */
1934 [ # # ]: 0 : E1000_WRITE_REG(hw, E1000_TDT(i), 0);
1935 [ # # ]: 0 : E1000_WRITE_REG(hw, E1000_TDH(i), 0);
1936 : :
1937 : : /* Setup Transmit threshold registers. */
1938 [ # # ]: 0 : txdctl = E1000_READ_REG(hw, E1000_TXDCTL(i));
1939 : : /*
1940 : : * bit 22 is reserved, on some models should always be 0,
1941 : : * on others - always 1.
1942 : : */
1943 : 0 : txdctl &= E1000_TXDCTL_COUNT_DESC;
1944 : 0 : txdctl |= txq->pthresh & 0x3F;
1945 : 0 : txdctl |= (txq->hthresh & 0x3F) << 8;
1946 : 0 : txdctl |= (txq->wthresh & 0x3F) << 16;
1947 : 0 : txdctl |= E1000_TXDCTL_GRAN;
1948 : 0 : E1000_WRITE_REG(hw, E1000_TXDCTL(i), txdctl);
1949 : :
1950 : 0 : dev->data->tx_queue_state[i] = RTE_ETH_QUEUE_STATE_STARTED;
1951 : : }
1952 : :
1953 : : /* Program the Transmit Control Register. */
1954 : 0 : tctl = E1000_READ_REG(hw, E1000_TCTL);
1955 : 0 : tctl &= ~E1000_TCTL_CT;
1956 : 0 : tctl |= (E1000_TCTL_PSP | E1000_TCTL_RTLC | E1000_TCTL_EN |
1957 : : (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT));
1958 : :
1959 : : /* SPT and CNP Si errata workaround to avoid data corruption */
1960 [ # # ]: 0 : if (hw->mac.type == e1000_pch_spt) {
1961 : : uint32_t reg_val;
1962 : 0 : reg_val = E1000_READ_REG(hw, E1000_IOSFPC);
1963 : 0 : reg_val |= E1000_RCTL_RDMTS_HEX;
1964 : 0 : E1000_WRITE_REG(hw, E1000_IOSFPC, reg_val);
1965 : :
1966 : : /* Dropping the number of outstanding requests from
1967 : : * 3 to 2 in order to avoid a buffer overrun.
1968 : : */
1969 : 0 : reg_val = E1000_READ_REG(hw, E1000_TARC(0));
1970 : 0 : reg_val &= ~E1000_TARC0_CB_MULTIQ_3_REQ;
1971 : 0 : reg_val |= E1000_TARC0_CB_MULTIQ_2_REQ;
1972 : 0 : E1000_WRITE_REG(hw, E1000_TARC(0), reg_val);
1973 : : }
1974 : :
1975 : : /* This write will effectively turn on the transmit unit. */
1976 : 0 : E1000_WRITE_REG(hw, E1000_TCTL, tctl);
1977 : 0 : }
1978 : :
1979 : : void
1980 : 0 : em_rxq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
1981 : : struct rte_eth_rxq_info *qinfo)
1982 : : {
1983 : : struct em_rx_queue *rxq;
1984 : :
1985 : 0 : rxq = dev->data->rx_queues[queue_id];
1986 : :
1987 : 0 : qinfo->mp = rxq->mb_pool;
1988 : 0 : qinfo->scattered_rx = dev->data->scattered_rx;
1989 : 0 : qinfo->nb_desc = rxq->nb_rx_desc;
1990 : 0 : qinfo->conf.rx_free_thresh = rxq->rx_free_thresh;
1991 : 0 : qinfo->conf.offloads = rxq->offloads;
1992 : 0 : }
1993 : :
1994 : : void
1995 : 0 : em_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
1996 : : struct rte_eth_txq_info *qinfo)
1997 : : {
1998 : : struct em_tx_queue *txq;
1999 : :
2000 : 0 : txq = dev->data->tx_queues[queue_id];
2001 : :
2002 : 0 : qinfo->nb_desc = txq->nb_tx_desc;
2003 : :
2004 : 0 : qinfo->conf.tx_thresh.pthresh = txq->pthresh;
2005 : 0 : qinfo->conf.tx_thresh.hthresh = txq->hthresh;
2006 : 0 : qinfo->conf.tx_thresh.wthresh = txq->wthresh;
2007 : 0 : qinfo->conf.tx_free_thresh = txq->tx_free_thresh;
2008 : 0 : qinfo->conf.tx_rs_thresh = txq->tx_rs_thresh;
2009 : 0 : qinfo->conf.offloads = txq->offloads;
2010 : 0 : }
2011 : :
2012 : : static void
2013 : 0 : e1000_flush_tx_ring(struct rte_eth_dev *dev)
2014 : : {
2015 : 0 : struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2016 : : volatile struct e1000_data_desc *tx_desc;
2017 : : volatile uint32_t *tdt_reg_addr;
2018 : : uint32_t tdt, tctl, txd_lower = E1000_TXD_CMD_IFCS;
2019 : : uint16_t size = 512;
2020 : : struct em_tx_queue *txq;
2021 : : int i;
2022 : :
2023 [ # # ]: 0 : if (dev->data->tx_queues == NULL)
2024 : : return;
2025 : 0 : tctl = E1000_READ_REG(hw, E1000_TCTL);
2026 : 0 : E1000_WRITE_REG(hw, E1000_TCTL, tctl | E1000_TCTL_EN);
2027 [ # # # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues &&
2028 : 0 : i < E1000_I219_MAX_TX_QUEUE_NUM; i++) {
2029 : 0 : txq = dev->data->tx_queues[i];
2030 : 0 : tdt = E1000_READ_REG(hw, E1000_TDT(i));
2031 [ # # ]: 0 : if (tdt != txq->tx_tail)
2032 : : return;
2033 : 0 : tx_desc = &txq->tx_ring[txq->tx_tail];
2034 : 0 : tx_desc->buffer_addr = rte_cpu_to_le_64(txq->tx_ring_phys_addr);
2035 : 0 : tx_desc->lower.data = rte_cpu_to_le_32(txd_lower | size);
2036 : 0 : tx_desc->upper.data = 0;
2037 : :
2038 : 0 : rte_io_wmb();
2039 : 0 : txq->tx_tail++;
2040 [ # # ]: 0 : if (txq->tx_tail == txq->nb_tx_desc)
2041 : 0 : txq->tx_tail = 0;
2042 : 0 : tdt_reg_addr = E1000_PCI_REG_ADDR(hw, E1000_TDT(i));
2043 : 0 : E1000_PCI_REG_WRITE(tdt_reg_addr, txq->tx_tail);
2044 : 0 : usec_delay(250);
2045 : : }
2046 : : }
2047 : :
2048 : : static void
2049 : 0 : e1000_flush_rx_ring(struct rte_eth_dev *dev)
2050 : : {
2051 : : uint32_t rctl, rxdctl;
2052 : 0 : struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2053 : : int i;
2054 : :
2055 : 0 : rctl = E1000_READ_REG(hw, E1000_RCTL);
2056 : 0 : E1000_WRITE_REG(hw, E1000_RCTL, rctl & ~E1000_RCTL_EN);
2057 : 0 : E1000_WRITE_FLUSH(hw);
2058 : 0 : usec_delay(150);
2059 : :
2060 [ # # # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues &&
2061 : 0 : i < E1000_I219_MAX_RX_QUEUE_NUM; i++) {
2062 : 0 : rxdctl = E1000_READ_REG(hw, E1000_RXDCTL(i));
2063 : : /* zero the lower 14 bits (prefetch and host thresholds) */
2064 : 0 : rxdctl &= 0xffffc000;
2065 : :
2066 : : /* update thresholds: prefetch threshold to 31,
2067 : : * host threshold to 1 and make sure the granularity
2068 : : * is "descriptors" and not "cache lines"
2069 : : */
2070 : 0 : rxdctl |= (0x1F | (1UL << 8) | E1000_RXDCTL_THRESH_UNIT_DESC);
2071 : :
2072 : 0 : E1000_WRITE_REG(hw, E1000_RXDCTL(i), rxdctl);
2073 : : }
2074 : : /* momentarily enable the RX ring for the changes to take effect */
2075 : 0 : E1000_WRITE_REG(hw, E1000_RCTL, rctl | E1000_RCTL_EN);
2076 : 0 : E1000_WRITE_FLUSH(hw);
2077 : 0 : usec_delay(150);
2078 : 0 : E1000_WRITE_REG(hw, E1000_RCTL, rctl & ~E1000_RCTL_EN);
2079 : 0 : }
2080 : :
2081 : : /**
2082 : : * em_flush_desc_rings - remove all descriptors from the descriptor rings
2083 : : *
2084 : : * In i219, the descriptor rings must be emptied before resetting/closing the
2085 : : * HW. Failure to do this will cause the HW to enter a unit hang state which
2086 : : * can only be released by PCI reset on the device
2087 : : *
2088 : : */
2089 : :
2090 : : void
2091 : 0 : em_flush_desc_rings(struct rte_eth_dev *dev)
2092 : : {
2093 : : uint32_t fextnvm11, tdlen;
2094 : 0 : struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2095 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
2096 : 0 : uint16_t pci_cfg_status = 0;
2097 : : int ret;
2098 : :
2099 : 0 : fextnvm11 = E1000_READ_REG(hw, E1000_FEXTNVM11);
2100 : 0 : E1000_WRITE_REG(hw, E1000_FEXTNVM11,
2101 : : fextnvm11 | E1000_FEXTNVM11_DISABLE_MULR_FIX);
2102 : 0 : tdlen = E1000_READ_REG(hw, E1000_TDLEN(0));
2103 : 0 : ret = rte_pci_read_config(pci_dev, &pci_cfg_status,
2104 : : sizeof(pci_cfg_status), RTE_PCI_STATUS);
2105 [ # # ]: 0 : if (ret < 0) {
2106 : 0 : PMD_DRV_LOG(ERR, "Failed to read PCI offset 0x%x",
2107 : : RTE_PCI_STATUS);
2108 : 0 : return;
2109 : : }
2110 : :
2111 : : /* do nothing if we're not in faulty state, or if the queue is empty */
2112 [ # # # # ]: 0 : if ((pci_cfg_status & RTE_PCI_STATUS_PARITY) && tdlen) {
2113 : : /* flush desc ring */
2114 : 0 : e1000_flush_tx_ring(dev);
2115 : 0 : ret = rte_pci_read_config(pci_dev, &pci_cfg_status,
2116 : : sizeof(pci_cfg_status), RTE_PCI_STATUS);
2117 [ # # ]: 0 : if (ret < 0) {
2118 : 0 : PMD_DRV_LOG(ERR, "Failed to read PCI offset 0x%x",
2119 : : RTE_PCI_STATUS);
2120 : 0 : return;
2121 : : }
2122 : :
2123 [ # # ]: 0 : if (pci_cfg_status & RTE_PCI_STATUS_PARITY)
2124 : 0 : e1000_flush_rx_ring(dev);
2125 : : }
2126 : : }
|