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