2 * Copyright (c) 2016 Solarflare Communications Inc.
5 * This software was jointly developed between OKTET Labs (under contract
6 * for Solarflare) and Solarflare Communications, Inc.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
11 * 1. Redistributions of source code must retain the above copyright notice,
12 * this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright notice,
14 * this list of conditions and the following disclaimer in the documentation
15 * and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
19 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
21 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
24 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
27 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #include <rte_mempool.h>
35 #include "sfc_debug.h"
39 #include "sfc_tweak.h"
42 * Maximum number of Rx queue flush attempt in the case of failure or
45 #define SFC_RX_QFLUSH_ATTEMPTS (3)
48 * Time to wait between event queue polling attempts when waiting for Rx
49 * queue flush done or failed events.
51 #define SFC_RX_QFLUSH_POLL_WAIT_MS (1)
54 * Maximum number of event queue polling attempts when waiting for Rx queue
55 * flush done or failed events. It defines Rx queue flush attempt timeout
56 * together with SFC_RX_QFLUSH_POLL_WAIT_MS.
58 #define SFC_RX_QFLUSH_POLL_ATTEMPTS (2000)
61 sfc_rx_qflush_done(struct sfc_rxq *rxq)
63 rxq->state |= SFC_RXQ_FLUSHED;
64 rxq->state &= ~SFC_RXQ_FLUSHING;
68 sfc_rx_qflush_failed(struct sfc_rxq *rxq)
70 rxq->state |= SFC_RXQ_FLUSH_FAILED;
71 rxq->state &= ~SFC_RXQ_FLUSHING;
75 sfc_rx_qrefill(struct sfc_rxq *rxq)
77 unsigned int free_space;
79 void *objs[SFC_RX_REFILL_BULK];
80 efsys_dma_addr_t addr[RTE_DIM(objs)];
81 unsigned int added = rxq->added;
84 struct sfc_rx_sw_desc *rxd;
86 uint8_t port_id = rxq->port_id;
88 free_space = EFX_RXQ_LIMIT(rxq->ptr_mask + 1) -
89 (added - rxq->completed);
91 if (free_space < rxq->refill_threshold)
94 bulks = free_space / RTE_DIM(objs);
96 id = added & rxq->ptr_mask;
98 if (rte_mempool_get_bulk(rxq->refill_mb_pool, objs,
101 * It is hardly a safe way to increment counter
102 * from different contexts, but all PMDs do it.
104 rxq->evq->sa->eth_dev->data->rx_mbuf_alloc_failed +=
109 for (i = 0; i < RTE_DIM(objs);
110 ++i, id = (id + 1) & rxq->ptr_mask) {
113 rxd = &rxq->sw_desc[id];
116 rte_mbuf_refcnt_set(m, 1);
117 m->data_off = RTE_PKTMBUF_HEADROOM;
122 addr[i] = rte_pktmbuf_mtophys(m);
125 efx_rx_qpost(rxq->common, addr, rxq->buf_size,
126 RTE_DIM(objs), rxq->completed, added);
127 added += RTE_DIM(objs);
130 /* Push doorbell if something is posted */
131 if (rxq->added != added) {
133 efx_rx_qpush(rxq->common, added, &rxq->pushed);
138 sfc_rx_desc_flags_to_offload_flags(const unsigned int desc_flags)
140 uint64_t mbuf_flags = 0;
142 switch (desc_flags & (EFX_PKT_IPV4 | EFX_CKSUM_IPV4)) {
143 case (EFX_PKT_IPV4 | EFX_CKSUM_IPV4):
144 mbuf_flags |= PKT_RX_IP_CKSUM_GOOD;
147 mbuf_flags |= PKT_RX_IP_CKSUM_BAD;
150 RTE_BUILD_BUG_ON(PKT_RX_IP_CKSUM_UNKNOWN != 0);
151 SFC_ASSERT((mbuf_flags & PKT_RX_IP_CKSUM_MASK) ==
152 PKT_RX_IP_CKSUM_UNKNOWN);
156 switch ((desc_flags &
157 (EFX_PKT_TCP | EFX_PKT_UDP | EFX_CKSUM_TCPUDP))) {
158 case (EFX_PKT_TCP | EFX_CKSUM_TCPUDP):
159 case (EFX_PKT_UDP | EFX_CKSUM_TCPUDP):
160 mbuf_flags |= PKT_RX_L4_CKSUM_GOOD;
164 mbuf_flags |= PKT_RX_L4_CKSUM_BAD;
167 RTE_BUILD_BUG_ON(PKT_RX_L4_CKSUM_UNKNOWN != 0);
168 SFC_ASSERT((mbuf_flags & PKT_RX_L4_CKSUM_MASK) ==
169 PKT_RX_L4_CKSUM_UNKNOWN);
177 sfc_rx_desc_flags_to_packet_type(const unsigned int desc_flags)
179 return RTE_PTYPE_L2_ETHER |
180 ((desc_flags & EFX_PKT_IPV4) ?
181 RTE_PTYPE_L3_IPV4_EXT_UNKNOWN : 0) |
182 ((desc_flags & EFX_PKT_IPV6) ?
183 RTE_PTYPE_L3_IPV6_EXT_UNKNOWN : 0) |
184 ((desc_flags & EFX_PKT_TCP) ? RTE_PTYPE_L4_TCP : 0) |
185 ((desc_flags & EFX_PKT_UDP) ? RTE_PTYPE_L4_UDP : 0);
189 sfc_rx_set_rss_hash(struct sfc_rxq *rxq, unsigned int flags, struct rte_mbuf *m)
191 #if EFSYS_OPT_RX_SCALE
195 if ((rxq->flags & SFC_RXQ_RSS_HASH) == 0)
198 mbuf_data = rte_pktmbuf_mtod(m, uint8_t *);
200 if (flags & (EFX_PKT_IPV4 | EFX_PKT_IPV6)) {
201 m->hash.rss = efx_pseudo_hdr_hash_get(rxq->common,
202 EFX_RX_HASHALG_TOEPLITZ,
205 m->ol_flags |= PKT_RX_RSS_HASH;
211 sfc_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
213 struct sfc_rxq *rxq = rx_queue;
214 unsigned int completed;
215 unsigned int prefix_size = rxq->prefix_size;
216 unsigned int done_pkts = 0;
217 boolean_t discard_next = B_FALSE;
218 struct rte_mbuf *scatter_pkt = NULL;
220 if (unlikely((rxq->state & SFC_RXQ_RUNNING) == 0))
223 sfc_ev_qpoll(rxq->evq);
225 completed = rxq->completed;
226 while (completed != rxq->pending && done_pkts < nb_pkts) {
228 struct sfc_rx_sw_desc *rxd;
230 unsigned int seg_len;
231 unsigned int desc_flags;
233 id = completed++ & rxq->ptr_mask;
234 rxd = &rxq->sw_desc[id];
236 desc_flags = rxd->flags;
241 if (desc_flags & (EFX_ADDR_MISMATCH | EFX_DISCARD))
244 if (desc_flags & EFX_PKT_PREFIX_LEN) {
248 rc = efx_pseudo_hdr_pkt_length_get(rxq->common,
249 rte_pktmbuf_mtod(m, uint8_t *), &tmp_size);
253 seg_len = rxd->size - prefix_size;
256 rte_pktmbuf_data_len(m) = seg_len;
257 rte_pktmbuf_pkt_len(m) = seg_len;
259 if (scatter_pkt != NULL) {
260 if (rte_pktmbuf_chain(scatter_pkt, m) != 0) {
261 rte_mempool_put(rxq->refill_mb_pool,
265 /* The packet to deliver */
269 if (desc_flags & EFX_PKT_CONT) {
270 /* The packet is scattered, more fragments to come */
272 /* Futher fragments have no prefix */
277 /* Scattered packet is done */
279 /* The first fragment of the packet has prefix */
280 prefix_size = rxq->prefix_size;
282 m->ol_flags = sfc_rx_desc_flags_to_offload_flags(desc_flags);
283 m->packet_type = sfc_rx_desc_flags_to_packet_type(desc_flags);
286 * Extract RSS hash from the packet prefix and
287 * set the corresponding field (if needed and possible)
289 sfc_rx_set_rss_hash(rxq, desc_flags, m);
291 m->data_off += prefix_size;
298 discard_next = ((desc_flags & EFX_PKT_CONT) != 0);
299 rte_mempool_put(rxq->refill_mb_pool, m);
303 /* pending is only moved when entire packet is received */
304 SFC_ASSERT(scatter_pkt == NULL);
306 rxq->completed = completed;
314 sfc_rx_qdesc_npending(struct sfc_adapter *sa, unsigned int sw_index)
318 SFC_ASSERT(sw_index < sa->rxq_count);
319 rxq = sa->rxq_info[sw_index].rxq;
321 if (rxq == NULL || (rxq->state & SFC_RXQ_RUNNING) == 0)
324 sfc_ev_qpoll(rxq->evq);
326 return rxq->pending - rxq->completed;
330 sfc_rx_qdesc_done(struct sfc_rxq *rxq, unsigned int offset)
332 if ((rxq->state & SFC_RXQ_RUNNING) == 0)
335 sfc_ev_qpoll(rxq->evq);
337 return offset < (rxq->pending - rxq->completed);
341 sfc_rx_qpurge(struct sfc_rxq *rxq)
344 struct sfc_rx_sw_desc *rxd;
346 for (i = rxq->completed; i != rxq->added; ++i) {
347 rxd = &rxq->sw_desc[i & rxq->ptr_mask];
348 rte_mempool_put(rxq->refill_mb_pool, rxd->mbuf);
354 sfc_rx_qflush(struct sfc_adapter *sa, unsigned int sw_index)
357 unsigned int retry_count;
358 unsigned int wait_count;
360 rxq = sa->rxq_info[sw_index].rxq;
361 SFC_ASSERT(rxq->state & SFC_RXQ_STARTED);
364 * Retry Rx queue flushing in the case of flush failed or
365 * timeout. In the worst case it can delay for 6 seconds.
367 for (retry_count = 0;
368 ((rxq->state & SFC_RXQ_FLUSHED) == 0) &&
369 (retry_count < SFC_RX_QFLUSH_ATTEMPTS);
371 if (efx_rx_qflush(rxq->common) != 0) {
372 rxq->state |= SFC_RXQ_FLUSH_FAILED;
375 rxq->state &= ~SFC_RXQ_FLUSH_FAILED;
376 rxq->state |= SFC_RXQ_FLUSHING;
379 * Wait for Rx queue flush done or failed event at least
380 * SFC_RX_QFLUSH_POLL_WAIT_MS milliseconds and not more
381 * than 2 seconds (SFC_RX_QFLUSH_POLL_WAIT_MS multiplied
382 * by SFC_RX_QFLUSH_POLL_ATTEMPTS).
386 rte_delay_ms(SFC_RX_QFLUSH_POLL_WAIT_MS);
387 sfc_ev_qpoll(rxq->evq);
388 } while ((rxq->state & SFC_RXQ_FLUSHING) &&
389 (wait_count++ < SFC_RX_QFLUSH_POLL_ATTEMPTS));
391 if (rxq->state & SFC_RXQ_FLUSHING)
392 sfc_err(sa, "RxQ %u flush timed out", sw_index);
394 if (rxq->state & SFC_RXQ_FLUSH_FAILED)
395 sfc_err(sa, "RxQ %u flush failed", sw_index);
397 if (rxq->state & SFC_RXQ_FLUSHED)
398 sfc_info(sa, "RxQ %u flushed", sw_index);
405 sfc_rx_qstart(struct sfc_adapter *sa, unsigned int sw_index)
407 struct sfc_rxq_info *rxq_info;
412 sfc_log_init(sa, "sw_index=%u", sw_index);
414 SFC_ASSERT(sw_index < sa->rxq_count);
416 rxq_info = &sa->rxq_info[sw_index];
418 SFC_ASSERT(rxq->state == SFC_RXQ_INITIALIZED);
422 rc = sfc_ev_qstart(sa, evq->evq_index);
426 rc = efx_rx_qcreate(sa->nic, rxq->hw_index, 0, rxq_info->type,
427 &rxq->mem, rxq_info->entries,
428 0 /* not used on EF10 */, evq->common,
431 goto fail_rx_qcreate;
433 efx_rx_qenable(rxq->common);
435 rxq->pending = rxq->completed = rxq->added = rxq->pushed = 0;
437 rxq->state |= (SFC_RXQ_STARTED | SFC_RXQ_RUNNING);
442 rc = efx_mac_filter_default_rxq_set(sa->nic, rxq->common,
443 (sa->rss_channels > 1) ?
446 goto fail_mac_filter_default_rxq_set;
449 /* It seems to be used by DPDK for debug purposes only ('rte_ether') */
450 sa->eth_dev->data->rx_queue_state[sw_index] =
451 RTE_ETH_QUEUE_STATE_STARTED;
455 fail_mac_filter_default_rxq_set:
456 sfc_rx_qflush(sa, sw_index);
459 sfc_ev_qstop(sa, evq->evq_index);
466 sfc_rx_qstop(struct sfc_adapter *sa, unsigned int sw_index)
468 struct sfc_rxq_info *rxq_info;
471 sfc_log_init(sa, "sw_index=%u", sw_index);
473 SFC_ASSERT(sw_index < sa->rxq_count);
475 rxq_info = &sa->rxq_info[sw_index];
478 if (rxq->state == SFC_RXQ_INITIALIZED)
480 SFC_ASSERT(rxq->state & SFC_RXQ_STARTED);
482 /* It seems to be used by DPDK for debug purposes only ('rte_ether') */
483 sa->eth_dev->data->rx_queue_state[sw_index] =
484 RTE_ETH_QUEUE_STATE_STOPPED;
486 rxq->state &= ~SFC_RXQ_RUNNING;
489 efx_mac_filter_default_rxq_clear(sa->nic);
491 sfc_rx_qflush(sa, sw_index);
493 rxq->state = SFC_RXQ_INITIALIZED;
495 efx_rx_qdestroy(rxq->common);
497 sfc_ev_qstop(sa, rxq->evq->evq_index);
501 sfc_rx_qcheck_conf(struct sfc_adapter *sa, uint16_t nb_rx_desc,
502 const struct rte_eth_rxconf *rx_conf)
504 const uint16_t rx_free_thresh_max = EFX_RXQ_LIMIT(nb_rx_desc);
507 if (rx_conf->rx_thresh.pthresh != 0 ||
508 rx_conf->rx_thresh.hthresh != 0 ||
509 rx_conf->rx_thresh.wthresh != 0) {
511 "RxQ prefetch/host/writeback thresholds are not supported");
515 if (rx_conf->rx_free_thresh > rx_free_thresh_max) {
517 "RxQ free threshold too large: %u vs maximum %u",
518 rx_conf->rx_free_thresh, rx_free_thresh_max);
522 if (rx_conf->rx_drop_en == 0) {
523 sfc_err(sa, "RxQ drop disable is not supported");
531 sfc_rx_mbuf_data_alignment(struct rte_mempool *mb_pool)
536 /* The mbuf object itself is always cache line aligned */
537 order = rte_bsf32(RTE_CACHE_LINE_SIZE);
539 /* Data offset from mbuf object start */
540 data_off = sizeof(struct rte_mbuf) + rte_pktmbuf_priv_size(mb_pool) +
541 RTE_PKTMBUF_HEADROOM;
543 order = MIN(order, rte_bsf32(data_off));
545 return 1u << (order - 1);
549 sfc_rx_mb_pool_buf_size(struct sfc_adapter *sa, struct rte_mempool *mb_pool)
551 const efx_nic_cfg_t *encp = efx_nic_cfg_get(sa->nic);
552 const uint32_t nic_align_start = MAX(1, encp->enc_rx_buf_align_start);
553 const uint32_t nic_align_end = MAX(1, encp->enc_rx_buf_align_end);
555 unsigned int buf_aligned;
556 unsigned int start_alignment;
557 unsigned int end_padding_alignment;
559 /* Below it is assumed that both alignments are power of 2 */
560 SFC_ASSERT(rte_is_power_of_2(nic_align_start));
561 SFC_ASSERT(rte_is_power_of_2(nic_align_end));
564 * mbuf is always cache line aligned, double-check
565 * that it meets rx buffer start alignment requirements.
568 /* Start from mbuf pool data room size */
569 buf_size = rte_pktmbuf_data_room_size(mb_pool);
571 /* Remove headroom */
572 if (buf_size <= RTE_PKTMBUF_HEADROOM) {
574 "RxQ mbuf pool %s object data room size %u is smaller than headroom %u",
575 mb_pool->name, buf_size, RTE_PKTMBUF_HEADROOM);
578 buf_size -= RTE_PKTMBUF_HEADROOM;
580 /* Calculate guaranteed data start alignment */
581 buf_aligned = sfc_rx_mbuf_data_alignment(mb_pool);
583 /* Reserve space for start alignment */
584 if (buf_aligned < nic_align_start) {
585 start_alignment = nic_align_start - buf_aligned;
586 if (buf_size <= start_alignment) {
588 "RxQ mbuf pool %s object data room size %u is insufficient for headroom %u and buffer start alignment %u required by NIC",
590 rte_pktmbuf_data_room_size(mb_pool),
591 RTE_PKTMBUF_HEADROOM, start_alignment);
594 buf_aligned = nic_align_start;
595 buf_size -= start_alignment;
600 /* Make sure that end padding does not write beyond the buffer */
601 if (buf_aligned < nic_align_end) {
603 * Estimate space which can be lost. If guarnteed buffer
604 * size is odd, lost space is (nic_align_end - 1). More
605 * accurate formula is below.
607 end_padding_alignment = nic_align_end -
608 MIN(buf_aligned, 1u << (rte_bsf32(buf_size) - 1));
609 if (buf_size <= end_padding_alignment) {
611 "RxQ mbuf pool %s object data room size %u is insufficient for headroom %u, buffer start alignment %u and end padding alignment %u required by NIC",
613 rte_pktmbuf_data_room_size(mb_pool),
614 RTE_PKTMBUF_HEADROOM, start_alignment,
615 end_padding_alignment);
618 buf_size -= end_padding_alignment;
621 * Start is aligned the same or better than end,
624 buf_size = P2ALIGN(buf_size, nic_align_end);
631 sfc_rx_qinit(struct sfc_adapter *sa, unsigned int sw_index,
632 uint16_t nb_rx_desc, unsigned int socket_id,
633 const struct rte_eth_rxconf *rx_conf,
634 struct rte_mempool *mb_pool)
636 const efx_nic_cfg_t *encp = efx_nic_cfg_get(sa->nic);
639 struct sfc_rxq_info *rxq_info;
640 unsigned int evq_index;
644 rc = sfc_rx_qcheck_conf(sa, nb_rx_desc, rx_conf);
648 buf_size = sfc_rx_mb_pool_buf_size(sa, mb_pool);
650 sfc_err(sa, "RxQ %u mbuf pool object size is too small",
656 if ((buf_size < sa->port.pdu + encp->enc_rx_prefix_size) &&
657 !sa->eth_dev->data->dev_conf.rxmode.enable_scatter) {
658 sfc_err(sa, "Rx scatter is disabled and RxQ %u mbuf pool "
659 "object size is too small", sw_index);
660 sfc_err(sa, "RxQ %u calculated Rx buffer size is %u vs "
661 "PDU size %u plus Rx prefix %u bytes",
662 sw_index, buf_size, (unsigned int)sa->port.pdu,
663 encp->enc_rx_prefix_size);
668 SFC_ASSERT(sw_index < sa->rxq_count);
669 rxq_info = &sa->rxq_info[sw_index];
671 SFC_ASSERT(nb_rx_desc <= rxq_info->max_entries);
672 rxq_info->entries = nb_rx_desc;
674 sa->eth_dev->data->dev_conf.rxmode.enable_scatter ?
675 EFX_RXQ_TYPE_SCATTER : EFX_RXQ_TYPE_DEFAULT;
677 evq_index = sfc_evq_index_by_rxq_sw_index(sa, sw_index);
679 rc = sfc_ev_qinit(sa, evq_index, rxq_info->entries, socket_id);
683 evq = sa->evq_info[evq_index].evq;
686 rxq = rte_zmalloc_socket("sfc-rxq", sizeof(*rxq), RTE_CACHE_LINE_SIZE,
691 rc = sfc_dma_alloc(sa, "rxq", sw_index, EFX_RXQ_SIZE(rxq_info->entries),
692 socket_id, &rxq->mem);
697 rxq->sw_desc = rte_calloc_socket("sfc-rxq-sw_desc", rxq_info->entries,
698 sizeof(*rxq->sw_desc),
699 RTE_CACHE_LINE_SIZE, socket_id);
700 if (rxq->sw_desc == NULL)
701 goto fail_desc_alloc;
705 rxq->ptr_mask = rxq_info->entries - 1;
706 rxq->refill_threshold = rx_conf->rx_free_thresh;
707 rxq->refill_mb_pool = mb_pool;
708 rxq->buf_size = buf_size;
709 rxq->hw_index = sw_index;
710 rxq->port_id = sa->eth_dev->data->port_id;
712 /* Cache limits required on datapath in RxQ structure */
713 rxq->batch_max = encp->enc_rx_batch_max;
714 rxq->prefix_size = encp->enc_rx_prefix_size;
716 #if EFSYS_OPT_RX_SCALE
717 if (sa->hash_support == EFX_RX_HASH_AVAILABLE)
718 rxq->flags |= SFC_RXQ_RSS_HASH;
721 rxq->state = SFC_RXQ_INITIALIZED;
724 rxq_info->deferred_start = (rx_conf->rx_deferred_start != 0);
729 sfc_dma_free(sa, &rxq->mem);
735 sfc_ev_qfini(sa, evq_index);
738 rxq_info->entries = 0;
741 sfc_log_init(sa, "failed %d", rc);
746 sfc_rx_qfini(struct sfc_adapter *sa, unsigned int sw_index)
748 struct sfc_rxq_info *rxq_info;
751 SFC_ASSERT(sw_index < sa->rxq_count);
753 rxq_info = &sa->rxq_info[sw_index];
756 SFC_ASSERT(rxq->state == SFC_RXQ_INITIALIZED);
758 rxq_info->rxq = NULL;
759 rxq_info->entries = 0;
761 rte_free(rxq->sw_desc);
762 sfc_dma_free(sa, &rxq->mem);
766 #if EFSYS_OPT_RX_SCALE
768 sfc_rte_to_efx_hash_type(uint64_t rss_hf)
770 efx_rx_hash_type_t efx_hash_types = 0;
772 if ((rss_hf & (ETH_RSS_IPV4 | ETH_RSS_FRAG_IPV4 |
773 ETH_RSS_NONFRAG_IPV4_OTHER)) != 0)
774 efx_hash_types |= EFX_RX_HASH_IPV4;
776 if ((rss_hf & ETH_RSS_NONFRAG_IPV4_TCP) != 0)
777 efx_hash_types |= EFX_RX_HASH_TCPIPV4;
779 if ((rss_hf & (ETH_RSS_IPV6 | ETH_RSS_FRAG_IPV6 |
780 ETH_RSS_NONFRAG_IPV6_OTHER | ETH_RSS_IPV6_EX)) != 0)
781 efx_hash_types |= EFX_RX_HASH_IPV6;
783 if ((rss_hf & (ETH_RSS_NONFRAG_IPV6_TCP | ETH_RSS_IPV6_TCP_EX)) != 0)
784 efx_hash_types |= EFX_RX_HASH_TCPIPV6;
786 return efx_hash_types;
790 sfc_efx_to_rte_hash_type(efx_rx_hash_type_t efx_hash_types)
794 if ((efx_hash_types & EFX_RX_HASH_IPV4) != 0)
795 rss_hf |= (ETH_RSS_IPV4 | ETH_RSS_FRAG_IPV4 |
796 ETH_RSS_NONFRAG_IPV4_OTHER);
798 if ((efx_hash_types & EFX_RX_HASH_TCPIPV4) != 0)
799 rss_hf |= ETH_RSS_NONFRAG_IPV4_TCP;
801 if ((efx_hash_types & EFX_RX_HASH_IPV6) != 0)
802 rss_hf |= (ETH_RSS_IPV6 | ETH_RSS_FRAG_IPV6 |
803 ETH_RSS_NONFRAG_IPV6_OTHER | ETH_RSS_IPV6_EX);
805 if ((efx_hash_types & EFX_RX_HASH_TCPIPV6) != 0)
806 rss_hf |= (ETH_RSS_NONFRAG_IPV6_TCP | ETH_RSS_IPV6_TCP_EX);
813 sfc_rx_rss_config(struct sfc_adapter *sa)
817 #if EFSYS_OPT_RX_SCALE
818 if (sa->rss_channels > 1) {
819 rc = efx_rx_scale_mode_set(sa->nic, EFX_RX_HASHALG_TOEPLITZ,
820 sa->rss_hash_types, B_TRUE);
824 rc = efx_rx_scale_key_set(sa->nic, sa->rss_key,
825 sizeof(sa->rss_key));
829 rc = efx_rx_scale_tbl_set(sa->nic, sa->rss_tbl,
830 sizeof(sa->rss_tbl));
839 sfc_rx_start(struct sfc_adapter *sa)
841 unsigned int sw_index;
844 sfc_log_init(sa, "rxq_count=%u", sa->rxq_count);
846 rc = efx_rx_init(sa->nic);
850 rc = sfc_rx_rss_config(sa);
852 goto fail_rss_config;
854 for (sw_index = 0; sw_index < sa->rxq_count; ++sw_index) {
855 if ((!sa->rxq_info[sw_index].deferred_start ||
856 sa->rxq_info[sw_index].deferred_started)) {
857 rc = sfc_rx_qstart(sa, sw_index);
866 while (sw_index-- > 0)
867 sfc_rx_qstop(sa, sw_index);
870 efx_rx_fini(sa->nic);
873 sfc_log_init(sa, "failed %d", rc);
878 sfc_rx_stop(struct sfc_adapter *sa)
880 unsigned int sw_index;
882 sfc_log_init(sa, "rxq_count=%u", sa->rxq_count);
884 sw_index = sa->rxq_count;
885 while (sw_index-- > 0) {
886 if (sa->rxq_info[sw_index].rxq != NULL)
887 sfc_rx_qstop(sa, sw_index);
890 efx_rx_fini(sa->nic);
894 sfc_rx_qinit_info(struct sfc_adapter *sa, unsigned int sw_index)
896 struct sfc_rxq_info *rxq_info = &sa->rxq_info[sw_index];
897 unsigned int max_entries;
899 max_entries = EFX_RXQ_MAXNDESCS;
900 SFC_ASSERT(rte_is_power_of_2(max_entries));
902 rxq_info->max_entries = max_entries;
908 sfc_rx_check_mode(struct sfc_adapter *sa, struct rte_eth_rxmode *rxmode)
912 switch (rxmode->mq_mode) {
914 /* No special checks are required */
916 #if EFSYS_OPT_RX_SCALE
918 if (sa->rss_support == EFX_RX_SCALE_UNAVAILABLE) {
919 sfc_err(sa, "RSS is not available");
925 sfc_err(sa, "Rx multi-queue mode %u not supported",
930 if (rxmode->header_split) {
931 sfc_err(sa, "Header split on Rx not supported");
935 if (rxmode->hw_vlan_filter) {
936 sfc_err(sa, "HW VLAN filtering not supported");
940 if (rxmode->hw_vlan_strip) {
941 sfc_err(sa, "HW VLAN stripping not supported");
945 if (rxmode->hw_vlan_extend) {
947 "Q-in-Q HW VLAN stripping not supported");
951 if (!rxmode->hw_strip_crc) {
953 "FCS stripping control not supported - always stripped");
954 rxmode->hw_strip_crc = 1;
957 if (rxmode->enable_lro) {
958 sfc_err(sa, "LRO not supported");
966 * Initialize Rx subsystem.
968 * Called at device configuration stage when number of receive queues is
969 * specified together with other device level receive configuration.
971 * It should be used to allocate NUMA-unaware resources.
974 sfc_rx_init(struct sfc_adapter *sa)
976 struct rte_eth_conf *dev_conf = &sa->eth_dev->data->dev_conf;
977 unsigned int sw_index;
980 rc = sfc_rx_check_mode(sa, &dev_conf->rxmode);
982 goto fail_check_mode;
984 sa->rxq_count = sa->eth_dev->data->nb_rx_queues;
987 sa->rxq_info = rte_calloc_socket("sfc-rxqs", sa->rxq_count,
988 sizeof(struct sfc_rxq_info), 0,
990 if (sa->rxq_info == NULL)
991 goto fail_rxqs_alloc;
993 for (sw_index = 0; sw_index < sa->rxq_count; ++sw_index) {
994 rc = sfc_rx_qinit_info(sa, sw_index);
996 goto fail_rx_qinit_info;
999 #if EFSYS_OPT_RX_SCALE
1000 sa->rss_channels = (dev_conf->rxmode.mq_mode == ETH_MQ_RX_RSS) ?
1001 MIN(sa->rxq_count, EFX_MAXRSS) : 1;
1003 if (sa->rss_channels > 1) {
1004 for (sw_index = 0; sw_index < EFX_RSS_TBL_SIZE; ++sw_index)
1005 sa->rss_tbl[sw_index] = sw_index % sa->rss_channels;
1012 rte_free(sa->rxq_info);
1013 sa->rxq_info = NULL;
1018 sfc_log_init(sa, "failed %d", rc);
1023 * Shutdown Rx subsystem.
1025 * Called at device close stage, for example, before device
1026 * reconfiguration or shutdown.
1029 sfc_rx_fini(struct sfc_adapter *sa)
1031 unsigned int sw_index;
1033 sw_index = sa->rxq_count;
1034 while (sw_index-- > 0) {
1035 if (sa->rxq_info[sw_index].rxq != NULL)
1036 sfc_rx_qfini(sa, sw_index);
1039 rte_free(sa->rxq_info);
1040 sa->rxq_info = NULL;