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