2018-01-08 13:35:35 +00:00
|
|
|
/* SPDX-License-Identifier: BSD-3-Clause
|
2017-03-16 12:41:08 +00:00
|
|
|
*
|
2018-01-08 13:35:35 +00:00
|
|
|
* Copyright (c) 2016-2018 Solarflare Communications Inc.
|
2016-11-29 16:19:15 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This software was jointly developed between OKTET Labs (under contract
|
|
|
|
* for Solarflare) and Solarflare Communications, Inc.
|
|
|
|
*/
|
|
|
|
|
2016-11-29 16:19:20 +00:00
|
|
|
#include <rte_mempool.h>
|
|
|
|
|
2016-11-29 16:19:15 +00:00
|
|
|
#include "efx.h"
|
|
|
|
|
|
|
|
#include "sfc.h"
|
2016-11-29 16:19:21 +00:00
|
|
|
#include "sfc_debug.h"
|
2016-11-29 16:19:15 +00:00
|
|
|
#include "sfc_log.h"
|
2016-11-29 16:19:17 +00:00
|
|
|
#include "sfc_ev.h"
|
2016-11-29 16:19:15 +00:00
|
|
|
#include "sfc_rx.h"
|
2017-03-20 10:15:10 +00:00
|
|
|
#include "sfc_kvargs.h"
|
2016-11-29 16:19:20 +00:00
|
|
|
#include "sfc_tweak.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Maximum number of Rx queue flush attempt in the case of failure or
|
|
|
|
* flush timeout
|
|
|
|
*/
|
|
|
|
#define SFC_RX_QFLUSH_ATTEMPTS (3)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Time to wait between event queue polling attempts when waiting for Rx
|
|
|
|
* queue flush done or failed events.
|
|
|
|
*/
|
|
|
|
#define SFC_RX_QFLUSH_POLL_WAIT_MS (1)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Maximum number of event queue polling attempts when waiting for Rx queue
|
|
|
|
* flush done or failed events. It defines Rx queue flush attempt timeout
|
|
|
|
* together with SFC_RX_QFLUSH_POLL_WAIT_MS.
|
|
|
|
*/
|
|
|
|
#define SFC_RX_QFLUSH_POLL_ATTEMPTS (2000)
|
|
|
|
|
|
|
|
void
|
|
|
|
sfc_rx_qflush_done(struct sfc_rxq *rxq)
|
|
|
|
{
|
|
|
|
rxq->state |= SFC_RXQ_FLUSHED;
|
|
|
|
rxq->state &= ~SFC_RXQ_FLUSHING;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
sfc_rx_qflush_failed(struct sfc_rxq *rxq)
|
|
|
|
{
|
|
|
|
rxq->state |= SFC_RXQ_FLUSH_FAILED;
|
|
|
|
rxq->state &= ~SFC_RXQ_FLUSHING;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-03-20 10:15:10 +00:00
|
|
|
sfc_efx_rx_qrefill(struct sfc_efx_rxq *rxq)
|
2016-11-29 16:19:20 +00:00
|
|
|
{
|
|
|
|
unsigned int free_space;
|
|
|
|
unsigned int bulks;
|
|
|
|
void *objs[SFC_RX_REFILL_BULK];
|
|
|
|
efsys_dma_addr_t addr[RTE_DIM(objs)];
|
|
|
|
unsigned int added = rxq->added;
|
|
|
|
unsigned int id;
|
|
|
|
unsigned int i;
|
2017-03-20 10:15:10 +00:00
|
|
|
struct sfc_efx_rx_sw_desc *rxd;
|
2016-11-29 16:19:20 +00:00
|
|
|
struct rte_mbuf *m;
|
2017-03-20 10:15:10 +00:00
|
|
|
uint16_t port_id = rxq->dp.dpq.port_id;
|
2016-11-29 16:19:20 +00:00
|
|
|
|
2018-01-09 20:24:52 +00:00
|
|
|
free_space = rxq->max_fill_level - (added - rxq->completed);
|
2016-12-15 12:51:07 +00:00
|
|
|
|
|
|
|
if (free_space < rxq->refill_threshold)
|
|
|
|
return;
|
|
|
|
|
2016-11-29 16:19:20 +00:00
|
|
|
bulks = free_space / RTE_DIM(objs);
|
2017-03-20 10:15:12 +00:00
|
|
|
/* refill_threshold guarantees that bulks is positive */
|
|
|
|
SFC_ASSERT(bulks > 0);
|
2016-11-29 16:19:20 +00:00
|
|
|
|
|
|
|
id = added & rxq->ptr_mask;
|
2017-03-20 10:15:12 +00:00
|
|
|
do {
|
|
|
|
if (unlikely(rte_mempool_get_bulk(rxq->refill_mb_pool, objs,
|
|
|
|
RTE_DIM(objs)) < 0)) {
|
2016-11-29 16:19:20 +00:00
|
|
|
/*
|
|
|
|
* It is hardly a safe way to increment counter
|
|
|
|
* from different contexts, but all PMDs do it.
|
|
|
|
*/
|
|
|
|
rxq->evq->sa->eth_dev->data->rx_mbuf_alloc_failed +=
|
|
|
|
RTE_DIM(objs);
|
2017-03-20 10:15:12 +00:00
|
|
|
/* Return if we have posted nothing yet */
|
|
|
|
if (added == rxq->added)
|
|
|
|
return;
|
|
|
|
/* Push posted */
|
2016-11-29 16:19:20 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < RTE_DIM(objs);
|
|
|
|
++i, id = (id + 1) & rxq->ptr_mask) {
|
|
|
|
m = objs[i];
|
|
|
|
|
|
|
|
rxd = &rxq->sw_desc[id];
|
|
|
|
rxd->mbuf = m;
|
|
|
|
|
2017-04-04 11:57:36 +00:00
|
|
|
SFC_ASSERT(rte_mbuf_refcnt_read(m) == 1);
|
2016-11-29 16:19:20 +00:00
|
|
|
m->data_off = RTE_PKTMBUF_HEADROOM;
|
2017-04-04 11:57:36 +00:00
|
|
|
SFC_ASSERT(m->next == NULL);
|
|
|
|
SFC_ASSERT(m->nb_segs == 1);
|
2016-11-29 16:19:20 +00:00
|
|
|
m->port = port_id;
|
|
|
|
|
2017-11-05 23:22:55 +00:00
|
|
|
addr[i] = rte_pktmbuf_iova(m);
|
2016-11-29 16:19:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
efx_rx_qpost(rxq->common, addr, rxq->buf_size,
|
|
|
|
RTE_DIM(objs), rxq->completed, added);
|
|
|
|
added += RTE_DIM(objs);
|
2017-03-20 10:15:12 +00:00
|
|
|
} while (--bulks > 0);
|
2016-11-29 16:19:20 +00:00
|
|
|
|
2017-03-20 10:15:12 +00:00
|
|
|
SFC_ASSERT(added != rxq->added);
|
|
|
|
rxq->added = added;
|
|
|
|
efx_rx_qpush(rxq->common, added, &rxq->pushed);
|
2016-11-29 16:19:20 +00:00
|
|
|
}
|
|
|
|
|
2016-12-15 12:51:04 +00:00
|
|
|
static uint64_t
|
2017-03-20 10:15:10 +00:00
|
|
|
sfc_efx_rx_desc_flags_to_offload_flags(const unsigned int desc_flags)
|
2016-12-15 12:51:04 +00:00
|
|
|
{
|
|
|
|
uint64_t mbuf_flags = 0;
|
|
|
|
|
|
|
|
switch (desc_flags & (EFX_PKT_IPV4 | EFX_CKSUM_IPV4)) {
|
|
|
|
case (EFX_PKT_IPV4 | EFX_CKSUM_IPV4):
|
|
|
|
mbuf_flags |= PKT_RX_IP_CKSUM_GOOD;
|
|
|
|
break;
|
|
|
|
case EFX_PKT_IPV4:
|
|
|
|
mbuf_flags |= PKT_RX_IP_CKSUM_BAD;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
RTE_BUILD_BUG_ON(PKT_RX_IP_CKSUM_UNKNOWN != 0);
|
|
|
|
SFC_ASSERT((mbuf_flags & PKT_RX_IP_CKSUM_MASK) ==
|
|
|
|
PKT_RX_IP_CKSUM_UNKNOWN);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch ((desc_flags &
|
|
|
|
(EFX_PKT_TCP | EFX_PKT_UDP | EFX_CKSUM_TCPUDP))) {
|
|
|
|
case (EFX_PKT_TCP | EFX_CKSUM_TCPUDP):
|
|
|
|
case (EFX_PKT_UDP | EFX_CKSUM_TCPUDP):
|
|
|
|
mbuf_flags |= PKT_RX_L4_CKSUM_GOOD;
|
|
|
|
break;
|
|
|
|
case EFX_PKT_TCP:
|
|
|
|
case EFX_PKT_UDP:
|
|
|
|
mbuf_flags |= PKT_RX_L4_CKSUM_BAD;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
RTE_BUILD_BUG_ON(PKT_RX_L4_CKSUM_UNKNOWN != 0);
|
|
|
|
SFC_ASSERT((mbuf_flags & PKT_RX_L4_CKSUM_MASK) ==
|
|
|
|
PKT_RX_L4_CKSUM_UNKNOWN);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mbuf_flags;
|
|
|
|
}
|
|
|
|
|
2016-12-15 12:51:05 +00:00
|
|
|
static uint32_t
|
2017-03-20 10:15:10 +00:00
|
|
|
sfc_efx_rx_desc_flags_to_packet_type(const unsigned int desc_flags)
|
2016-12-15 12:51:05 +00:00
|
|
|
{
|
|
|
|
return RTE_PTYPE_L2_ETHER |
|
|
|
|
((desc_flags & EFX_PKT_IPV4) ?
|
|
|
|
RTE_PTYPE_L3_IPV4_EXT_UNKNOWN : 0) |
|
|
|
|
((desc_flags & EFX_PKT_IPV6) ?
|
|
|
|
RTE_PTYPE_L3_IPV6_EXT_UNKNOWN : 0) |
|
|
|
|
((desc_flags & EFX_PKT_TCP) ? RTE_PTYPE_L4_TCP : 0) |
|
|
|
|
((desc_flags & EFX_PKT_UDP) ? RTE_PTYPE_L4_UDP : 0);
|
|
|
|
}
|
|
|
|
|
2017-03-20 10:15:10 +00:00
|
|
|
static const uint32_t *
|
2017-12-24 10:46:41 +00:00
|
|
|
sfc_efx_supported_ptypes_get(__rte_unused uint32_t tunnel_encaps)
|
2017-03-20 10:15:10 +00:00
|
|
|
{
|
|
|
|
static const uint32_t ptypes[] = {
|
|
|
|
RTE_PTYPE_L2_ETHER,
|
|
|
|
RTE_PTYPE_L3_IPV4_EXT_UNKNOWN,
|
|
|
|
RTE_PTYPE_L3_IPV6_EXT_UNKNOWN,
|
|
|
|
RTE_PTYPE_L4_TCP,
|
|
|
|
RTE_PTYPE_L4_UDP,
|
|
|
|
RTE_PTYPE_UNKNOWN
|
|
|
|
};
|
|
|
|
|
|
|
|
return ptypes;
|
|
|
|
}
|
|
|
|
|
2017-08-30 18:17:31 +00:00
|
|
|
#if EFSYS_OPT_RX_SCALE
|
2016-12-15 12:51:18 +00:00
|
|
|
static void
|
2017-03-20 10:15:10 +00:00
|
|
|
sfc_efx_rx_set_rss_hash(struct sfc_efx_rxq *rxq, unsigned int flags,
|
|
|
|
struct rte_mbuf *m)
|
2016-12-15 12:51:18 +00:00
|
|
|
{
|
|
|
|
uint8_t *mbuf_data;
|
|
|
|
|
|
|
|
|
2017-03-20 10:15:10 +00:00
|
|
|
if ((rxq->flags & SFC_EFX_RXQ_FLAG_RSS_HASH) == 0)
|
2016-12-15 12:51:18 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
mbuf_data = rte_pktmbuf_mtod(m, uint8_t *);
|
|
|
|
|
|
|
|
if (flags & (EFX_PKT_IPV4 | EFX_PKT_IPV6)) {
|
|
|
|
m->hash.rss = efx_pseudo_hdr_hash_get(rxq->common,
|
|
|
|
EFX_RX_HASHALG_TOEPLITZ,
|
|
|
|
mbuf_data);
|
|
|
|
|
|
|
|
m->ol_flags |= PKT_RX_RSS_HASH;
|
|
|
|
}
|
|
|
|
}
|
2017-08-30 18:17:31 +00:00
|
|
|
#else
|
|
|
|
static void
|
|
|
|
sfc_efx_rx_set_rss_hash(__rte_unused struct sfc_efx_rxq *rxq,
|
|
|
|
__rte_unused unsigned int flags,
|
|
|
|
__rte_unused struct rte_mbuf *m)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
#endif
|
2016-12-15 12:51:18 +00:00
|
|
|
|
2017-03-20 10:15:10 +00:00
|
|
|
static uint16_t
|
|
|
|
sfc_efx_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
|
2016-11-29 16:19:21 +00:00
|
|
|
{
|
2017-03-20 10:15:10 +00:00
|
|
|
struct sfc_dp_rxq *dp_rxq = rx_queue;
|
|
|
|
struct sfc_efx_rxq *rxq = sfc_efx_rxq_by_dp_rxq(dp_rxq);
|
2016-11-29 16:19:21 +00:00
|
|
|
unsigned int completed;
|
|
|
|
unsigned int prefix_size = rxq->prefix_size;
|
|
|
|
unsigned int done_pkts = 0;
|
2016-11-29 16:19:22 +00:00
|
|
|
boolean_t discard_next = B_FALSE;
|
2016-12-15 12:51:10 +00:00
|
|
|
struct rte_mbuf *scatter_pkt = NULL;
|
2016-11-29 16:19:21 +00:00
|
|
|
|
2017-03-20 10:15:10 +00:00
|
|
|
if (unlikely((rxq->flags & SFC_EFX_RXQ_FLAG_RUNNING) == 0))
|
2016-11-29 16:19:21 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
sfc_ev_qpoll(rxq->evq);
|
|
|
|
|
|
|
|
completed = rxq->completed;
|
|
|
|
while (completed != rxq->pending && done_pkts < nb_pkts) {
|
|
|
|
unsigned int id;
|
2017-03-20 10:15:10 +00:00
|
|
|
struct sfc_efx_rx_sw_desc *rxd;
|
2016-11-29 16:19:21 +00:00
|
|
|
struct rte_mbuf *m;
|
|
|
|
unsigned int seg_len;
|
|
|
|
unsigned int desc_flags;
|
|
|
|
|
|
|
|
id = completed++ & rxq->ptr_mask;
|
|
|
|
rxd = &rxq->sw_desc[id];
|
|
|
|
m = rxd->mbuf;
|
|
|
|
desc_flags = rxd->flags;
|
|
|
|
|
2016-11-29 16:19:22 +00:00
|
|
|
if (discard_next)
|
|
|
|
goto discard;
|
|
|
|
|
2016-11-29 16:19:21 +00:00
|
|
|
if (desc_flags & (EFX_ADDR_MISMATCH | EFX_DISCARD))
|
|
|
|
goto discard;
|
|
|
|
|
|
|
|
if (desc_flags & EFX_PKT_PREFIX_LEN) {
|
|
|
|
uint16_t tmp_size;
|
|
|
|
int rc __rte_unused;
|
|
|
|
|
|
|
|
rc = efx_pseudo_hdr_pkt_length_get(rxq->common,
|
|
|
|
rte_pktmbuf_mtod(m, uint8_t *), &tmp_size);
|
|
|
|
SFC_ASSERT(rc == 0);
|
|
|
|
seg_len = tmp_size;
|
|
|
|
} else {
|
|
|
|
seg_len = rxd->size - prefix_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
rte_pktmbuf_data_len(m) = seg_len;
|
|
|
|
rte_pktmbuf_pkt_len(m) = seg_len;
|
|
|
|
|
2016-12-15 12:51:10 +00:00
|
|
|
if (scatter_pkt != NULL) {
|
|
|
|
if (rte_pktmbuf_chain(scatter_pkt, m) != 0) {
|
2017-03-30 15:16:15 +00:00
|
|
|
rte_pktmbuf_free(scatter_pkt);
|
2016-12-15 12:51:10 +00:00
|
|
|
goto discard;
|
|
|
|
}
|
|
|
|
/* The packet to deliver */
|
|
|
|
m = scatter_pkt;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (desc_flags & EFX_PKT_CONT) {
|
|
|
|
/* The packet is scattered, more fragments to come */
|
|
|
|
scatter_pkt = m;
|
2017-06-07 05:05:06 +00:00
|
|
|
/* Further fragments have no prefix */
|
2016-12-15 12:51:10 +00:00
|
|
|
prefix_size = 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Scattered packet is done */
|
|
|
|
scatter_pkt = NULL;
|
|
|
|
/* The first fragment of the packet has prefix */
|
|
|
|
prefix_size = rxq->prefix_size;
|
|
|
|
|
2017-03-20 10:15:10 +00:00
|
|
|
m->ol_flags =
|
|
|
|
sfc_efx_rx_desc_flags_to_offload_flags(desc_flags);
|
|
|
|
m->packet_type =
|
|
|
|
sfc_efx_rx_desc_flags_to_packet_type(desc_flags);
|
2016-11-29 16:19:21 +00:00
|
|
|
|
2016-12-15 12:51:18 +00:00
|
|
|
/*
|
|
|
|
* Extract RSS hash from the packet prefix and
|
|
|
|
* set the corresponding field (if needed and possible)
|
|
|
|
*/
|
2017-03-20 10:15:10 +00:00
|
|
|
sfc_efx_rx_set_rss_hash(rxq, desc_flags, m);
|
2016-12-15 12:51:18 +00:00
|
|
|
|
|
|
|
m->data_off += prefix_size;
|
|
|
|
|
2016-11-29 16:19:21 +00:00
|
|
|
*rx_pkts++ = m;
|
|
|
|
done_pkts++;
|
|
|
|
continue;
|
|
|
|
|
|
|
|
discard:
|
2016-11-29 16:19:22 +00:00
|
|
|
discard_next = ((desc_flags & EFX_PKT_CONT) != 0);
|
2016-11-29 16:19:21 +00:00
|
|
|
rte_mempool_put(rxq->refill_mb_pool, m);
|
|
|
|
rxd->mbuf = NULL;
|
|
|
|
}
|
|
|
|
|
2016-12-15 12:51:10 +00:00
|
|
|
/* pending is only moved when entire packet is received */
|
|
|
|
SFC_ASSERT(scatter_pkt == NULL);
|
|
|
|
|
2016-11-29 16:19:21 +00:00
|
|
|
rxq->completed = completed;
|
|
|
|
|
2017-03-20 10:15:10 +00:00
|
|
|
sfc_efx_rx_qrefill(rxq);
|
2016-11-29 16:19:21 +00:00
|
|
|
|
|
|
|
return done_pkts;
|
|
|
|
}
|
|
|
|
|
2017-03-20 10:15:10 +00:00
|
|
|
static sfc_dp_rx_qdesc_npending_t sfc_efx_rx_qdesc_npending;
|
|
|
|
static unsigned int
|
|
|
|
sfc_efx_rx_qdesc_npending(struct sfc_dp_rxq *dp_rxq)
|
2016-12-15 12:51:08 +00:00
|
|
|
{
|
2017-03-20 10:15:10 +00:00
|
|
|
struct sfc_efx_rxq *rxq = sfc_efx_rxq_by_dp_rxq(dp_rxq);
|
2016-12-15 12:51:08 +00:00
|
|
|
|
2017-03-20 10:15:10 +00:00
|
|
|
if ((rxq->flags & SFC_EFX_RXQ_FLAG_RUNNING) == 0)
|
2016-12-15 12:51:08 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
sfc_ev_qpoll(rxq->evq);
|
|
|
|
|
|
|
|
return rxq->pending - rxq->completed;
|
|
|
|
}
|
|
|
|
|
2017-08-30 09:08:46 +00:00
|
|
|
static sfc_dp_rx_qdesc_status_t sfc_efx_rx_qdesc_status;
|
|
|
|
static int
|
|
|
|
sfc_efx_rx_qdesc_status(struct sfc_dp_rxq *dp_rxq, uint16_t offset)
|
|
|
|
{
|
|
|
|
struct sfc_efx_rxq *rxq = sfc_efx_rxq_by_dp_rxq(dp_rxq);
|
|
|
|
|
|
|
|
if (unlikely(offset > rxq->ptr_mask))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Poll EvQ to derive up-to-date 'rxq->pending' figure;
|
|
|
|
* it is required for the queue to be running, but the
|
|
|
|
* check is omitted because API design assumes that it
|
|
|
|
* is the duty of the caller to satisfy all conditions
|
|
|
|
*/
|
|
|
|
SFC_ASSERT((rxq->flags & SFC_EFX_RXQ_FLAG_RUNNING) ==
|
|
|
|
SFC_EFX_RXQ_FLAG_RUNNING);
|
|
|
|
sfc_ev_qpoll(rxq->evq);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* There is a handful of reserved entries in the ring,
|
|
|
|
* but an explicit check whether the offset points to
|
|
|
|
* a reserved entry is neglected since the two checks
|
|
|
|
* below rely on the figures which take the HW limits
|
|
|
|
* into account and thus if an entry is reserved, the
|
|
|
|
* checks will fail and UNAVAIL code will be returned
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (offset < (rxq->pending - rxq->completed))
|
|
|
|
return RTE_ETH_RX_DESC_DONE;
|
|
|
|
|
|
|
|
if (offset < (rxq->added - rxq->completed))
|
|
|
|
return RTE_ETH_RX_DESC_AVAIL;
|
|
|
|
|
|
|
|
return RTE_ETH_RX_DESC_UNAVAIL;
|
|
|
|
}
|
|
|
|
|
2017-03-20 10:15:10 +00:00
|
|
|
struct sfc_rxq *
|
|
|
|
sfc_rxq_by_dp_rxq(const struct sfc_dp_rxq *dp_rxq)
|
2016-12-15 12:51:09 +00:00
|
|
|
{
|
2017-03-20 10:15:10 +00:00
|
|
|
const struct sfc_dp_queue *dpq = &dp_rxq->dpq;
|
|
|
|
struct rte_eth_dev *eth_dev;
|
|
|
|
struct sfc_adapter *sa;
|
|
|
|
struct sfc_rxq *rxq;
|
2016-12-15 12:51:09 +00:00
|
|
|
|
2017-03-20 10:15:10 +00:00
|
|
|
SFC_ASSERT(rte_eth_dev_is_valid_port(dpq->port_id));
|
|
|
|
eth_dev = &rte_eth_devices[dpq->port_id];
|
2016-12-15 12:51:09 +00:00
|
|
|
|
2017-03-20 10:15:10 +00:00
|
|
|
sa = eth_dev->data->dev_private;
|
|
|
|
|
|
|
|
SFC_ASSERT(dpq->queue_id < sa->rxq_count);
|
|
|
|
rxq = sa->rxq_info[dpq->queue_id].rxq;
|
|
|
|
|
|
|
|
SFC_ASSERT(rxq != NULL);
|
|
|
|
return rxq;
|
|
|
|
}
|
|
|
|
|
2018-01-09 20:24:50 +00:00
|
|
|
static sfc_dp_rx_qsize_up_rings_t sfc_efx_rx_qsize_up_rings;
|
|
|
|
static int
|
|
|
|
sfc_efx_rx_qsize_up_rings(uint16_t nb_rx_desc,
|
|
|
|
unsigned int *rxq_entries,
|
|
|
|
unsigned int *evq_entries,
|
|
|
|
unsigned int *rxq_max_fill_level)
|
|
|
|
{
|
|
|
|
*rxq_entries = nb_rx_desc;
|
|
|
|
*evq_entries = nb_rx_desc;
|
|
|
|
*rxq_max_fill_level = EFX_RXQ_LIMIT(*rxq_entries);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-03-20 10:15:10 +00:00
|
|
|
static sfc_dp_rx_qcreate_t sfc_efx_rx_qcreate;
|
|
|
|
static int
|
|
|
|
sfc_efx_rx_qcreate(uint16_t port_id, uint16_t queue_id,
|
|
|
|
const struct rte_pci_addr *pci_addr, int socket_id,
|
|
|
|
const struct sfc_dp_rx_qcreate_info *info,
|
|
|
|
struct sfc_dp_rxq **dp_rxqp)
|
|
|
|
{
|
|
|
|
struct sfc_efx_rxq *rxq;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
rc = ENOMEM;
|
|
|
|
rxq = rte_zmalloc_socket("sfc-efx-rxq", sizeof(*rxq),
|
|
|
|
RTE_CACHE_LINE_SIZE, socket_id);
|
|
|
|
if (rxq == NULL)
|
|
|
|
goto fail_rxq_alloc;
|
|
|
|
|
|
|
|
sfc_dp_queue_init(&rxq->dp.dpq, port_id, queue_id, pci_addr);
|
|
|
|
|
|
|
|
rc = ENOMEM;
|
|
|
|
rxq->sw_desc = rte_calloc_socket("sfc-efx-rxq-sw_desc",
|
|
|
|
info->rxq_entries,
|
|
|
|
sizeof(*rxq->sw_desc),
|
|
|
|
RTE_CACHE_LINE_SIZE, socket_id);
|
|
|
|
if (rxq->sw_desc == NULL)
|
|
|
|
goto fail_desc_alloc;
|
|
|
|
|
|
|
|
/* efx datapath is bound to efx control path */
|
|
|
|
rxq->evq = sfc_rxq_by_dp_rxq(&rxq->dp)->evq;
|
|
|
|
if (info->flags & SFC_RXQ_FLAG_RSS_HASH)
|
|
|
|
rxq->flags |= SFC_EFX_RXQ_FLAG_RSS_HASH;
|
|
|
|
rxq->ptr_mask = info->rxq_entries - 1;
|
|
|
|
rxq->batch_max = info->batch_max;
|
|
|
|
rxq->prefix_size = info->prefix_size;
|
2018-01-09 20:24:52 +00:00
|
|
|
rxq->max_fill_level = info->max_fill_level;
|
2017-03-20 10:15:10 +00:00
|
|
|
rxq->refill_threshold = info->refill_threshold;
|
|
|
|
rxq->buf_size = info->buf_size;
|
|
|
|
rxq->refill_mb_pool = info->refill_mb_pool;
|
|
|
|
|
|
|
|
*dp_rxqp = &rxq->dp;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
fail_desc_alloc:
|
|
|
|
rte_free(rxq);
|
|
|
|
|
|
|
|
fail_rxq_alloc:
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static sfc_dp_rx_qdestroy_t sfc_efx_rx_qdestroy;
|
|
|
|
static void
|
|
|
|
sfc_efx_rx_qdestroy(struct sfc_dp_rxq *dp_rxq)
|
|
|
|
{
|
|
|
|
struct sfc_efx_rxq *rxq = sfc_efx_rxq_by_dp_rxq(dp_rxq);
|
|
|
|
|
|
|
|
rte_free(rxq->sw_desc);
|
|
|
|
rte_free(rxq);
|
|
|
|
}
|
|
|
|
|
|
|
|
static sfc_dp_rx_qstart_t sfc_efx_rx_qstart;
|
|
|
|
static int
|
|
|
|
sfc_efx_rx_qstart(struct sfc_dp_rxq *dp_rxq,
|
|
|
|
__rte_unused unsigned int evq_read_ptr)
|
|
|
|
{
|
|
|
|
/* libefx-based datapath is specific to libefx-based PMD */
|
|
|
|
struct sfc_efx_rxq *rxq = sfc_efx_rxq_by_dp_rxq(dp_rxq);
|
|
|
|
struct sfc_rxq *crxq = sfc_rxq_by_dp_rxq(dp_rxq);
|
|
|
|
|
|
|
|
rxq->common = crxq->common;
|
|
|
|
|
|
|
|
rxq->pending = rxq->completed = rxq->added = rxq->pushed = 0;
|
|
|
|
|
|
|
|
sfc_efx_rx_qrefill(rxq);
|
|
|
|
|
|
|
|
rxq->flags |= (SFC_EFX_RXQ_FLAG_STARTED | SFC_EFX_RXQ_FLAG_RUNNING);
|
|
|
|
|
|
|
|
return 0;
|
2016-12-15 12:51:09 +00:00
|
|
|
}
|
|
|
|
|
2017-03-20 10:15:10 +00:00
|
|
|
static sfc_dp_rx_qstop_t sfc_efx_rx_qstop;
|
2016-11-29 16:19:20 +00:00
|
|
|
static void
|
2017-03-20 10:15:10 +00:00
|
|
|
sfc_efx_rx_qstop(struct sfc_dp_rxq *dp_rxq,
|
|
|
|
__rte_unused unsigned int *evq_read_ptr)
|
2016-11-29 16:19:20 +00:00
|
|
|
{
|
2017-03-20 10:15:10 +00:00
|
|
|
struct sfc_efx_rxq *rxq = sfc_efx_rxq_by_dp_rxq(dp_rxq);
|
|
|
|
|
|
|
|
rxq->flags &= ~SFC_EFX_RXQ_FLAG_RUNNING;
|
|
|
|
|
|
|
|
/* libefx-based datapath is bound to libefx-based PMD and uses
|
|
|
|
* event queue structure directly. So, there is no necessity to
|
|
|
|
* return EvQ read pointer.
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
static sfc_dp_rx_qpurge_t sfc_efx_rx_qpurge;
|
|
|
|
static void
|
|
|
|
sfc_efx_rx_qpurge(struct sfc_dp_rxq *dp_rxq)
|
|
|
|
{
|
|
|
|
struct sfc_efx_rxq *rxq = sfc_efx_rxq_by_dp_rxq(dp_rxq);
|
2016-11-29 16:19:20 +00:00
|
|
|
unsigned int i;
|
2017-03-20 10:15:10 +00:00
|
|
|
struct sfc_efx_rx_sw_desc *rxd;
|
2016-11-29 16:19:20 +00:00
|
|
|
|
|
|
|
for (i = rxq->completed; i != rxq->added; ++i) {
|
|
|
|
rxd = &rxq->sw_desc[i & rxq->ptr_mask];
|
|
|
|
rte_mempool_put(rxq->refill_mb_pool, rxd->mbuf);
|
|
|
|
rxd->mbuf = NULL;
|
2017-03-20 10:15:10 +00:00
|
|
|
/* Packed stream relies on 0 in inactive SW desc.
|
|
|
|
* Rx queue stop is not performance critical, so
|
|
|
|
* there is no harm to do it always.
|
|
|
|
*/
|
|
|
|
rxd->flags = 0;
|
|
|
|
rxd->size = 0;
|
2016-11-29 16:19:20 +00:00
|
|
|
}
|
2017-03-20 10:15:10 +00:00
|
|
|
|
|
|
|
rxq->flags &= ~SFC_EFX_RXQ_FLAG_STARTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct sfc_dp_rx sfc_efx_rx = {
|
|
|
|
.dp = {
|
|
|
|
.name = SFC_KVARG_DATAPATH_EFX,
|
|
|
|
.type = SFC_DP_RX,
|
|
|
|
.hw_fw_caps = 0,
|
|
|
|
},
|
2017-03-20 10:15:11 +00:00
|
|
|
.features = SFC_DP_RX_FEAT_SCATTER,
|
2018-01-09 20:24:50 +00:00
|
|
|
.qsize_up_rings = sfc_efx_rx_qsize_up_rings,
|
2017-03-20 10:15:10 +00:00
|
|
|
.qcreate = sfc_efx_rx_qcreate,
|
|
|
|
.qdestroy = sfc_efx_rx_qdestroy,
|
|
|
|
.qstart = sfc_efx_rx_qstart,
|
|
|
|
.qstop = sfc_efx_rx_qstop,
|
|
|
|
.qpurge = sfc_efx_rx_qpurge,
|
|
|
|
.supported_ptypes_get = sfc_efx_supported_ptypes_get,
|
|
|
|
.qdesc_npending = sfc_efx_rx_qdesc_npending,
|
2017-08-30 09:08:46 +00:00
|
|
|
.qdesc_status = sfc_efx_rx_qdesc_status,
|
2017-03-20 10:15:10 +00:00
|
|
|
.pkt_burst = sfc_efx_recv_pkts,
|
|
|
|
};
|
|
|
|
|
|
|
|
unsigned int
|
|
|
|
sfc_rx_qdesc_npending(struct sfc_adapter *sa, unsigned int sw_index)
|
|
|
|
{
|
|
|
|
struct sfc_rxq *rxq;
|
|
|
|
|
|
|
|
SFC_ASSERT(sw_index < sa->rxq_count);
|
|
|
|
rxq = sa->rxq_info[sw_index].rxq;
|
|
|
|
|
|
|
|
if (rxq == NULL || (rxq->state & SFC_RXQ_STARTED) == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return sa->dp_rx->qdesc_npending(rxq->dp);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
sfc_rx_qdesc_done(struct sfc_dp_rxq *dp_rxq, unsigned int offset)
|
|
|
|
{
|
|
|
|
struct sfc_rxq *rxq = sfc_rxq_by_dp_rxq(dp_rxq);
|
|
|
|
|
|
|
|
return offset < rxq->evq->sa->dp_rx->qdesc_npending(dp_rxq);
|
2016-11-29 16:19:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
sfc_rx_qflush(struct sfc_adapter *sa, unsigned int sw_index)
|
|
|
|
{
|
|
|
|
struct sfc_rxq *rxq;
|
|
|
|
unsigned int retry_count;
|
|
|
|
unsigned int wait_count;
|
2017-05-27 07:55:32 +00:00
|
|
|
int rc;
|
2016-11-29 16:19:20 +00:00
|
|
|
|
|
|
|
rxq = sa->rxq_info[sw_index].rxq;
|
|
|
|
SFC_ASSERT(rxq->state & SFC_RXQ_STARTED);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Retry Rx queue flushing in the case of flush failed or
|
|
|
|
* timeout. In the worst case it can delay for 6 seconds.
|
|
|
|
*/
|
|
|
|
for (retry_count = 0;
|
|
|
|
((rxq->state & SFC_RXQ_FLUSHED) == 0) &&
|
|
|
|
(retry_count < SFC_RX_QFLUSH_ATTEMPTS);
|
|
|
|
++retry_count) {
|
2017-05-27 07:55:32 +00:00
|
|
|
rc = efx_rx_qflush(rxq->common);
|
|
|
|
if (rc != 0) {
|
|
|
|
rxq->state |= (rc == EALREADY) ?
|
|
|
|
SFC_RXQ_FLUSHED : SFC_RXQ_FLUSH_FAILED;
|
2016-11-29 16:19:20 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
rxq->state &= ~SFC_RXQ_FLUSH_FAILED;
|
|
|
|
rxq->state |= SFC_RXQ_FLUSHING;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Wait for Rx queue flush done or failed event at least
|
|
|
|
* SFC_RX_QFLUSH_POLL_WAIT_MS milliseconds and not more
|
|
|
|
* than 2 seconds (SFC_RX_QFLUSH_POLL_WAIT_MS multiplied
|
|
|
|
* by SFC_RX_QFLUSH_POLL_ATTEMPTS).
|
|
|
|
*/
|
|
|
|
wait_count = 0;
|
|
|
|
do {
|
|
|
|
rte_delay_ms(SFC_RX_QFLUSH_POLL_WAIT_MS);
|
|
|
|
sfc_ev_qpoll(rxq->evq);
|
|
|
|
} while ((rxq->state & SFC_RXQ_FLUSHING) &&
|
|
|
|
(wait_count++ < SFC_RX_QFLUSH_POLL_ATTEMPTS));
|
|
|
|
|
|
|
|
if (rxq->state & SFC_RXQ_FLUSHING)
|
|
|
|
sfc_err(sa, "RxQ %u flush timed out", sw_index);
|
|
|
|
|
|
|
|
if (rxq->state & SFC_RXQ_FLUSH_FAILED)
|
|
|
|
sfc_err(sa, "RxQ %u flush failed", sw_index);
|
|
|
|
|
|
|
|
if (rxq->state & SFC_RXQ_FLUSHED)
|
|
|
|
sfc_info(sa, "RxQ %u flushed", sw_index);
|
|
|
|
}
|
|
|
|
|
2017-03-20 10:15:10 +00:00
|
|
|
sa->dp_rx->qpurge(rxq->dp);
|
2016-11-29 16:19:20 +00:00
|
|
|
}
|
|
|
|
|
2017-03-09 17:23:01 +00:00
|
|
|
static int
|
|
|
|
sfc_rx_default_rxq_set_filter(struct sfc_adapter *sa, struct sfc_rxq *rxq)
|
|
|
|
{
|
2017-04-18 13:03:07 +00:00
|
|
|
boolean_t rss = (sa->rss_channels > 0) ? B_TRUE : B_FALSE;
|
2017-03-09 17:23:01 +00:00
|
|
|
struct sfc_port *port = &sa->port;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If promiscuous or all-multicast mode has been requested, setting
|
|
|
|
* filter for the default Rx queue might fail, in particular, while
|
|
|
|
* running over PCI function which is not a member of corresponding
|
|
|
|
* privilege groups; if this occurs, few iterations will be made to
|
|
|
|
* repeat this step without promiscuous and all-multicast flags set
|
|
|
|
*/
|
|
|
|
retry:
|
|
|
|
rc = efx_mac_filter_default_rxq_set(sa->nic, rxq->common, rss);
|
|
|
|
if (rc == 0)
|
|
|
|
return 0;
|
|
|
|
else if (rc != EOPNOTSUPP)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
if (port->promisc) {
|
|
|
|
sfc_warn(sa, "promiscuous mode has been requested, "
|
|
|
|
"but the HW rejects it");
|
|
|
|
sfc_warn(sa, "promiscuous mode will be disabled");
|
|
|
|
|
|
|
|
port->promisc = B_FALSE;
|
|
|
|
rc = sfc_set_rx_mode(sa);
|
|
|
|
if (rc != 0)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
goto retry;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (port->allmulti) {
|
|
|
|
sfc_warn(sa, "all-multicast mode has been requested, "
|
|
|
|
"but the HW rejects it");
|
|
|
|
sfc_warn(sa, "all-multicast mode will be disabled");
|
|
|
|
|
|
|
|
port->allmulti = B_FALSE;
|
|
|
|
rc = sfc_set_rx_mode(sa);
|
|
|
|
if (rc != 0)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
goto retry;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2016-11-29 16:19:20 +00:00
|
|
|
int
|
|
|
|
sfc_rx_qstart(struct sfc_adapter *sa, unsigned int sw_index)
|
|
|
|
{
|
2017-06-20 16:37:09 +00:00
|
|
|
struct sfc_port *port = &sa->port;
|
2016-11-29 16:19:20 +00:00
|
|
|
struct sfc_rxq_info *rxq_info;
|
|
|
|
struct sfc_rxq *rxq;
|
|
|
|
struct sfc_evq *evq;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
sfc_log_init(sa, "sw_index=%u", sw_index);
|
|
|
|
|
|
|
|
SFC_ASSERT(sw_index < sa->rxq_count);
|
|
|
|
|
|
|
|
rxq_info = &sa->rxq_info[sw_index];
|
|
|
|
rxq = rxq_info->rxq;
|
|
|
|
SFC_ASSERT(rxq->state == SFC_RXQ_INITIALIZED);
|
|
|
|
|
|
|
|
evq = rxq->evq;
|
|
|
|
|
2017-03-31 10:22:16 +00:00
|
|
|
rc = sfc_ev_qstart(evq, sfc_evq_index_by_rxq_sw_index(sa, sw_index));
|
2016-11-29 16:19:20 +00:00
|
|
|
if (rc != 0)
|
|
|
|
goto fail_ev_qstart;
|
|
|
|
|
|
|
|
rc = efx_rx_qcreate(sa->nic, rxq->hw_index, 0, rxq_info->type,
|
|
|
|
&rxq->mem, rxq_info->entries,
|
2017-12-24 10:46:35 +00:00
|
|
|
0 /* not used on EF10 */, rxq_info->type_flags,
|
|
|
|
evq->common, &rxq->common);
|
2016-11-29 16:19:20 +00:00
|
|
|
if (rc != 0)
|
|
|
|
goto fail_rx_qcreate;
|
|
|
|
|
|
|
|
efx_rx_qenable(rxq->common);
|
|
|
|
|
2017-03-20 10:15:10 +00:00
|
|
|
rc = sa->dp_rx->qstart(rxq->dp, evq->read_ptr);
|
|
|
|
if (rc != 0)
|
|
|
|
goto fail_dp_qstart;
|
2016-11-29 16:19:20 +00:00
|
|
|
|
2017-03-20 10:15:09 +00:00
|
|
|
rxq->state |= SFC_RXQ_STARTED;
|
2016-11-29 16:19:20 +00:00
|
|
|
|
2017-06-20 16:37:09 +00:00
|
|
|
if ((sw_index == 0) && !port->isolated) {
|
2017-03-09 17:23:01 +00:00
|
|
|
rc = sfc_rx_default_rxq_set_filter(sa, rxq);
|
2016-11-29 16:19:20 +00:00
|
|
|
if (rc != 0)
|
|
|
|
goto fail_mac_filter_default_rxq_set;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* It seems to be used by DPDK for debug purposes only ('rte_ether') */
|
|
|
|
sa->eth_dev->data->rx_queue_state[sw_index] =
|
|
|
|
RTE_ETH_QUEUE_STATE_STARTED;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
fail_mac_filter_default_rxq_set:
|
2017-03-20 10:15:10 +00:00
|
|
|
sa->dp_rx->qstop(rxq->dp, &rxq->evq->read_ptr);
|
|
|
|
|
|
|
|
fail_dp_qstart:
|
2016-11-29 16:19:20 +00:00
|
|
|
sfc_rx_qflush(sa, sw_index);
|
|
|
|
|
|
|
|
fail_rx_qcreate:
|
2017-03-31 10:22:16 +00:00
|
|
|
sfc_ev_qstop(evq);
|
2016-11-29 16:19:20 +00:00
|
|
|
|
|
|
|
fail_ev_qstart:
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
sfc_rx_qstop(struct sfc_adapter *sa, unsigned int sw_index)
|
|
|
|
{
|
|
|
|
struct sfc_rxq_info *rxq_info;
|
|
|
|
struct sfc_rxq *rxq;
|
|
|
|
|
|
|
|
sfc_log_init(sa, "sw_index=%u", sw_index);
|
|
|
|
|
|
|
|
SFC_ASSERT(sw_index < sa->rxq_count);
|
|
|
|
|
|
|
|
rxq_info = &sa->rxq_info[sw_index];
|
|
|
|
rxq = rxq_info->rxq;
|
2016-12-15 12:51:11 +00:00
|
|
|
|
|
|
|
if (rxq->state == SFC_RXQ_INITIALIZED)
|
|
|
|
return;
|
2016-11-29 16:19:20 +00:00
|
|
|
SFC_ASSERT(rxq->state & SFC_RXQ_STARTED);
|
|
|
|
|
|
|
|
/* It seems to be used by DPDK for debug purposes only ('rte_ether') */
|
|
|
|
sa->eth_dev->data->rx_queue_state[sw_index] =
|
|
|
|
RTE_ETH_QUEUE_STATE_STOPPED;
|
|
|
|
|
2017-03-20 10:15:10 +00:00
|
|
|
sa->dp_rx->qstop(rxq->dp, &rxq->evq->read_ptr);
|
2016-11-29 16:19:21 +00:00
|
|
|
|
2016-11-29 16:19:20 +00:00
|
|
|
if (sw_index == 0)
|
|
|
|
efx_mac_filter_default_rxq_clear(sa->nic);
|
|
|
|
|
|
|
|
sfc_rx_qflush(sa, sw_index);
|
|
|
|
|
|
|
|
rxq->state = SFC_RXQ_INITIALIZED;
|
|
|
|
|
|
|
|
efx_rx_qdestroy(rxq->common);
|
|
|
|
|
2017-03-31 10:22:16 +00:00
|
|
|
sfc_ev_qstop(rxq->evq);
|
2016-11-29 16:19:20 +00:00
|
|
|
}
|
2016-11-29 16:19:15 +00:00
|
|
|
|
2016-11-29 16:19:17 +00:00
|
|
|
static int
|
2018-01-09 20:24:50 +00:00
|
|
|
sfc_rx_qcheck_conf(struct sfc_adapter *sa, unsigned int rxq_max_fill_level,
|
2016-11-29 16:19:17 +00:00
|
|
|
const struct rte_eth_rxconf *rx_conf)
|
|
|
|
{
|
|
|
|
int rc = 0;
|
|
|
|
|
|
|
|
if (rx_conf->rx_thresh.pthresh != 0 ||
|
|
|
|
rx_conf->rx_thresh.hthresh != 0 ||
|
|
|
|
rx_conf->rx_thresh.wthresh != 0) {
|
2017-11-14 11:32:34 +00:00
|
|
|
sfc_warn(sa,
|
2016-11-29 16:19:17 +00:00
|
|
|
"RxQ prefetch/host/writeback thresholds are not supported");
|
|
|
|
}
|
|
|
|
|
2018-01-09 20:24:50 +00:00
|
|
|
if (rx_conf->rx_free_thresh > rxq_max_fill_level) {
|
2016-12-15 12:51:07 +00:00
|
|
|
sfc_err(sa,
|
|
|
|
"RxQ free threshold too large: %u vs maximum %u",
|
2018-01-09 20:24:50 +00:00
|
|
|
rx_conf->rx_free_thresh, rxq_max_fill_level);
|
2016-11-29 16:19:17 +00:00
|
|
|
rc = EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rx_conf->rx_drop_en == 0) {
|
|
|
|
sfc_err(sa, "RxQ drop disable is not supported");
|
|
|
|
rc = EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2016-11-29 16:19:18 +00:00
|
|
|
static unsigned int
|
|
|
|
sfc_rx_mbuf_data_alignment(struct rte_mempool *mb_pool)
|
|
|
|
{
|
|
|
|
uint32_t data_off;
|
|
|
|
uint32_t order;
|
|
|
|
|
|
|
|
/* The mbuf object itself is always cache line aligned */
|
|
|
|
order = rte_bsf32(RTE_CACHE_LINE_SIZE);
|
|
|
|
|
|
|
|
/* Data offset from mbuf object start */
|
|
|
|
data_off = sizeof(struct rte_mbuf) + rte_pktmbuf_priv_size(mb_pool) +
|
|
|
|
RTE_PKTMBUF_HEADROOM;
|
|
|
|
|
|
|
|
order = MIN(order, rte_bsf32(data_off));
|
|
|
|
|
|
|
|
return 1u << (order - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint16_t
|
|
|
|
sfc_rx_mb_pool_buf_size(struct sfc_adapter *sa, struct rte_mempool *mb_pool)
|
|
|
|
{
|
|
|
|
const efx_nic_cfg_t *encp = efx_nic_cfg_get(sa->nic);
|
|
|
|
const uint32_t nic_align_start = MAX(1, encp->enc_rx_buf_align_start);
|
|
|
|
const uint32_t nic_align_end = MAX(1, encp->enc_rx_buf_align_end);
|
|
|
|
uint16_t buf_size;
|
|
|
|
unsigned int buf_aligned;
|
|
|
|
unsigned int start_alignment;
|
|
|
|
unsigned int end_padding_alignment;
|
|
|
|
|
|
|
|
/* Below it is assumed that both alignments are power of 2 */
|
|
|
|
SFC_ASSERT(rte_is_power_of_2(nic_align_start));
|
|
|
|
SFC_ASSERT(rte_is_power_of_2(nic_align_end));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* mbuf is always cache line aligned, double-check
|
|
|
|
* that it meets rx buffer start alignment requirements.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Start from mbuf pool data room size */
|
|
|
|
buf_size = rte_pktmbuf_data_room_size(mb_pool);
|
|
|
|
|
|
|
|
/* Remove headroom */
|
|
|
|
if (buf_size <= RTE_PKTMBUF_HEADROOM) {
|
|
|
|
sfc_err(sa,
|
|
|
|
"RxQ mbuf pool %s object data room size %u is smaller than headroom %u",
|
|
|
|
mb_pool->name, buf_size, RTE_PKTMBUF_HEADROOM);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
buf_size -= RTE_PKTMBUF_HEADROOM;
|
|
|
|
|
|
|
|
/* Calculate guaranteed data start alignment */
|
|
|
|
buf_aligned = sfc_rx_mbuf_data_alignment(mb_pool);
|
|
|
|
|
|
|
|
/* Reserve space for start alignment */
|
|
|
|
if (buf_aligned < nic_align_start) {
|
|
|
|
start_alignment = nic_align_start - buf_aligned;
|
|
|
|
if (buf_size <= start_alignment) {
|
|
|
|
sfc_err(sa,
|
|
|
|
"RxQ mbuf pool %s object data room size %u is insufficient for headroom %u and buffer start alignment %u required by NIC",
|
|
|
|
mb_pool->name,
|
|
|
|
rte_pktmbuf_data_room_size(mb_pool),
|
|
|
|
RTE_PKTMBUF_HEADROOM, start_alignment);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
buf_aligned = nic_align_start;
|
|
|
|
buf_size -= start_alignment;
|
|
|
|
} else {
|
|
|
|
start_alignment = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Make sure that end padding does not write beyond the buffer */
|
|
|
|
if (buf_aligned < nic_align_end) {
|
|
|
|
/*
|
|
|
|
* Estimate space which can be lost. If guarnteed buffer
|
|
|
|
* size is odd, lost space is (nic_align_end - 1). More
|
|
|
|
* accurate formula is below.
|
|
|
|
*/
|
|
|
|
end_padding_alignment = nic_align_end -
|
|
|
|
MIN(buf_aligned, 1u << (rte_bsf32(buf_size) - 1));
|
|
|
|
if (buf_size <= end_padding_alignment) {
|
|
|
|
sfc_err(sa,
|
|
|
|
"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",
|
|
|
|
mb_pool->name,
|
|
|
|
rte_pktmbuf_data_room_size(mb_pool),
|
|
|
|
RTE_PKTMBUF_HEADROOM, start_alignment,
|
|
|
|
end_padding_alignment);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
buf_size -= end_padding_alignment;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Start is aligned the same or better than end,
|
|
|
|
* just align length.
|
|
|
|
*/
|
|
|
|
buf_size = P2ALIGN(buf_size, nic_align_end);
|
|
|
|
}
|
|
|
|
|
|
|
|
return buf_size;
|
|
|
|
}
|
|
|
|
|
2016-11-29 16:19:17 +00:00
|
|
|
int
|
|
|
|
sfc_rx_qinit(struct sfc_adapter *sa, unsigned int sw_index,
|
|
|
|
uint16_t nb_rx_desc, unsigned int socket_id,
|
|
|
|
const struct rte_eth_rxconf *rx_conf,
|
|
|
|
struct rte_mempool *mb_pool)
|
|
|
|
{
|
2016-11-29 16:19:19 +00:00
|
|
|
const efx_nic_cfg_t *encp = efx_nic_cfg_get(sa->nic);
|
2016-11-29 16:19:17 +00:00
|
|
|
int rc;
|
2018-01-09 20:24:50 +00:00
|
|
|
unsigned int rxq_entries;
|
|
|
|
unsigned int evq_entries;
|
|
|
|
unsigned int rxq_max_fill_level;
|
2016-11-29 16:19:18 +00:00
|
|
|
uint16_t buf_size;
|
2016-11-29 16:19:17 +00:00
|
|
|
struct sfc_rxq_info *rxq_info;
|
|
|
|
struct sfc_evq *evq;
|
|
|
|
struct sfc_rxq *rxq;
|
2017-03-20 10:15:10 +00:00
|
|
|
struct sfc_dp_rx_qcreate_info info;
|
2016-11-29 16:19:17 +00:00
|
|
|
|
2018-01-09 20:24:50 +00:00
|
|
|
rc = sa->dp_rx->qsize_up_rings(nb_rx_desc, &rxq_entries, &evq_entries,
|
|
|
|
&rxq_max_fill_level);
|
|
|
|
if (rc != 0)
|
|
|
|
goto fail_size_up_rings;
|
2018-01-09 20:24:54 +00:00
|
|
|
SFC_ASSERT(rxq_entries >= EFX_RXQ_MINNDESCS);
|
|
|
|
SFC_ASSERT(rxq_entries <= EFX_RXQ_MAXNDESCS);
|
|
|
|
SFC_ASSERT(rxq_entries >= nb_rx_desc);
|
|
|
|
SFC_ASSERT(rxq_max_fill_level <= nb_rx_desc);
|
2018-01-09 20:24:50 +00:00
|
|
|
|
|
|
|
rc = sfc_rx_qcheck_conf(sa, rxq_max_fill_level, rx_conf);
|
2016-11-29 16:19:17 +00:00
|
|
|
if (rc != 0)
|
|
|
|
goto fail_bad_conf;
|
|
|
|
|
2016-11-29 16:19:18 +00:00
|
|
|
buf_size = sfc_rx_mb_pool_buf_size(sa, mb_pool);
|
|
|
|
if (buf_size == 0) {
|
|
|
|
sfc_err(sa, "RxQ %u mbuf pool object size is too small",
|
|
|
|
sw_index);
|
2016-11-29 16:19:19 +00:00
|
|
|
rc = EINVAL;
|
|
|
|
goto fail_bad_conf;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((buf_size < sa->port.pdu + encp->enc_rx_prefix_size) &&
|
|
|
|
!sa->eth_dev->data->dev_conf.rxmode.enable_scatter) {
|
|
|
|
sfc_err(sa, "Rx scatter is disabled and RxQ %u mbuf pool "
|
|
|
|
"object size is too small", sw_index);
|
|
|
|
sfc_err(sa, "RxQ %u calculated Rx buffer size is %u vs "
|
|
|
|
"PDU size %u plus Rx prefix %u bytes",
|
|
|
|
sw_index, buf_size, (unsigned int)sa->port.pdu,
|
|
|
|
encp->enc_rx_prefix_size);
|
|
|
|
rc = EINVAL;
|
2016-11-29 16:19:17 +00:00
|
|
|
goto fail_bad_conf;
|
|
|
|
}
|
|
|
|
|
|
|
|
SFC_ASSERT(sw_index < sa->rxq_count);
|
|
|
|
rxq_info = &sa->rxq_info[sw_index];
|
|
|
|
|
2018-01-09 20:24:50 +00:00
|
|
|
SFC_ASSERT(rxq_entries <= rxq_info->max_entries);
|
|
|
|
rxq_info->entries = rxq_entries;
|
2017-12-24 10:46:35 +00:00
|
|
|
rxq_info->type = EFX_RXQ_TYPE_DEFAULT;
|
|
|
|
rxq_info->type_flags =
|
2016-12-15 12:51:10 +00:00
|
|
|
sa->eth_dev->data->dev_conf.rxmode.enable_scatter ?
|
2017-12-24 10:46:35 +00:00
|
|
|
EFX_RXQ_FLAG_SCATTER : EFX_RXQ_FLAG_NONE;
|
2016-11-29 16:19:17 +00:00
|
|
|
|
2017-12-24 10:46:41 +00:00
|
|
|
if ((encp->enc_tunnel_encapsulations_supported != 0) &&
|
|
|
|
(sa->dp_rx->features & SFC_DP_RX_FEAT_TUNNELS))
|
|
|
|
rxq_info->type_flags |= EFX_RXQ_FLAG_INNER_CLASSES;
|
|
|
|
|
2017-03-31 10:22:16 +00:00
|
|
|
rc = sfc_ev_qinit(sa, SFC_EVQ_TYPE_RX, sw_index,
|
2018-01-09 20:24:50 +00:00
|
|
|
evq_entries, socket_id, &evq);
|
2016-11-29 16:19:17 +00:00
|
|
|
if (rc != 0)
|
|
|
|
goto fail_ev_qinit;
|
|
|
|
|
|
|
|
rc = ENOMEM;
|
|
|
|
rxq = rte_zmalloc_socket("sfc-rxq", sizeof(*rxq), RTE_CACHE_LINE_SIZE,
|
|
|
|
socket_id);
|
|
|
|
if (rxq == NULL)
|
|
|
|
goto fail_rxq_alloc;
|
|
|
|
|
2017-03-20 10:15:10 +00:00
|
|
|
rxq_info->rxq = rxq;
|
2016-11-29 16:19:17 +00:00
|
|
|
|
|
|
|
rxq->evq = evq;
|
2017-03-20 10:15:10 +00:00
|
|
|
rxq->hw_index = sw_index;
|
2017-03-20 10:15:12 +00:00
|
|
|
rxq->refill_threshold =
|
|
|
|
RTE_MAX(rx_conf->rx_free_thresh, SFC_RX_REFILL_BULK);
|
2016-11-29 16:19:17 +00:00
|
|
|
rxq->refill_mb_pool = mb_pool;
|
|
|
|
|
2017-03-20 10:15:10 +00:00
|
|
|
rc = sfc_dma_alloc(sa, "rxq", sw_index, EFX_RXQ_SIZE(rxq_info->entries),
|
|
|
|
socket_id, &rxq->mem);
|
|
|
|
if (rc != 0)
|
|
|
|
goto fail_dma_alloc;
|
|
|
|
|
|
|
|
memset(&info, 0, sizeof(info));
|
|
|
|
info.refill_mb_pool = rxq->refill_mb_pool;
|
2018-01-09 20:24:52 +00:00
|
|
|
info.max_fill_level = rxq_max_fill_level;
|
2017-03-20 10:15:10 +00:00
|
|
|
info.refill_threshold = rxq->refill_threshold;
|
|
|
|
info.buf_size = buf_size;
|
|
|
|
info.batch_max = encp->enc_rx_batch_max;
|
|
|
|
info.prefix_size = encp->enc_rx_prefix_size;
|
2016-11-29 16:19:21 +00:00
|
|
|
|
2016-12-15 12:51:17 +00:00
|
|
|
#if EFSYS_OPT_RX_SCALE
|
2017-04-18 13:03:08 +00:00
|
|
|
if (sa->hash_support == EFX_RX_HASH_AVAILABLE && sa->rss_channels > 0)
|
2017-03-20 10:15:10 +00:00
|
|
|
info.flags |= SFC_RXQ_FLAG_RSS_HASH;
|
2016-12-15 12:51:17 +00:00
|
|
|
#endif
|
|
|
|
|
2017-03-20 10:15:10 +00:00
|
|
|
info.rxq_entries = rxq_info->entries;
|
2017-03-20 10:15:13 +00:00
|
|
|
info.rxq_hw_ring = rxq->mem.esm_base;
|
2018-01-09 20:24:50 +00:00
|
|
|
info.evq_entries = evq_entries;
|
2017-03-20 10:15:13 +00:00
|
|
|
info.evq_hw_ring = evq->mem.esm_base;
|
|
|
|
info.hw_index = rxq->hw_index;
|
|
|
|
info.mem_bar = sa->mem_bar.esb_base;
|
2017-03-20 10:15:10 +00:00
|
|
|
|
|
|
|
rc = sa->dp_rx->qcreate(sa->eth_dev->data->port_id, sw_index,
|
2017-05-15 10:24:03 +00:00
|
|
|
&RTE_ETH_DEV_TO_PCI(sa->eth_dev)->addr,
|
2017-03-20 10:15:10 +00:00
|
|
|
socket_id, &info, &rxq->dp);
|
|
|
|
if (rc != 0)
|
|
|
|
goto fail_dp_rx_qcreate;
|
|
|
|
|
|
|
|
evq->dp_rxq = rxq->dp;
|
|
|
|
|
2016-11-29 16:19:17 +00:00
|
|
|
rxq->state = SFC_RXQ_INITIALIZED;
|
|
|
|
|
2016-12-15 12:51:11 +00:00
|
|
|
rxq_info->deferred_start = (rx_conf->rx_deferred_start != 0);
|
2016-11-29 16:19:17 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
2017-03-20 10:15:10 +00:00
|
|
|
fail_dp_rx_qcreate:
|
2016-11-29 16:19:17 +00:00
|
|
|
sfc_dma_free(sa, &rxq->mem);
|
|
|
|
|
|
|
|
fail_dma_alloc:
|
2017-03-20 10:15:10 +00:00
|
|
|
rxq_info->rxq = NULL;
|
2016-11-29 16:19:17 +00:00
|
|
|
rte_free(rxq);
|
|
|
|
|
|
|
|
fail_rxq_alloc:
|
2017-03-31 10:22:16 +00:00
|
|
|
sfc_ev_qfini(evq);
|
2016-11-29 16:19:17 +00:00
|
|
|
|
|
|
|
fail_ev_qinit:
|
|
|
|
rxq_info->entries = 0;
|
|
|
|
|
|
|
|
fail_bad_conf:
|
2018-01-09 20:24:50 +00:00
|
|
|
fail_size_up_rings:
|
2016-11-29 16:19:17 +00:00
|
|
|
sfc_log_init(sa, "failed %d", rc);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
sfc_rx_qfini(struct sfc_adapter *sa, unsigned int sw_index)
|
|
|
|
{
|
|
|
|
struct sfc_rxq_info *rxq_info;
|
|
|
|
struct sfc_rxq *rxq;
|
|
|
|
|
|
|
|
SFC_ASSERT(sw_index < sa->rxq_count);
|
|
|
|
|
|
|
|
rxq_info = &sa->rxq_info[sw_index];
|
|
|
|
|
|
|
|
rxq = rxq_info->rxq;
|
|
|
|
SFC_ASSERT(rxq->state == SFC_RXQ_INITIALIZED);
|
|
|
|
|
2017-03-20 10:15:10 +00:00
|
|
|
sa->dp_rx->qdestroy(rxq->dp);
|
|
|
|
rxq->dp = NULL;
|
|
|
|
|
2016-11-29 16:19:17 +00:00
|
|
|
rxq_info->rxq = NULL;
|
|
|
|
rxq_info->entries = 0;
|
|
|
|
|
|
|
|
sfc_dma_free(sa, &rxq->mem);
|
2017-03-29 08:25:40 +00:00
|
|
|
|
2017-03-31 10:22:16 +00:00
|
|
|
sfc_ev_qfini(rxq->evq);
|
|
|
|
rxq->evq = NULL;
|
|
|
|
|
|
|
|
rte_free(rxq);
|
2016-11-29 16:19:17 +00:00
|
|
|
}
|
|
|
|
|
2016-12-15 12:51:17 +00:00
|
|
|
#if EFSYS_OPT_RX_SCALE
|
|
|
|
efx_rx_hash_type_t
|
|
|
|
sfc_rte_to_efx_hash_type(uint64_t rss_hf)
|
|
|
|
{
|
|
|
|
efx_rx_hash_type_t efx_hash_types = 0;
|
|
|
|
|
|
|
|
if ((rss_hf & (ETH_RSS_IPV4 | ETH_RSS_FRAG_IPV4 |
|
|
|
|
ETH_RSS_NONFRAG_IPV4_OTHER)) != 0)
|
|
|
|
efx_hash_types |= EFX_RX_HASH_IPV4;
|
|
|
|
|
|
|
|
if ((rss_hf & ETH_RSS_NONFRAG_IPV4_TCP) != 0)
|
|
|
|
efx_hash_types |= EFX_RX_HASH_TCPIPV4;
|
|
|
|
|
|
|
|
if ((rss_hf & (ETH_RSS_IPV6 | ETH_RSS_FRAG_IPV6 |
|
|
|
|
ETH_RSS_NONFRAG_IPV6_OTHER | ETH_RSS_IPV6_EX)) != 0)
|
|
|
|
efx_hash_types |= EFX_RX_HASH_IPV6;
|
|
|
|
|
|
|
|
if ((rss_hf & (ETH_RSS_NONFRAG_IPV6_TCP | ETH_RSS_IPV6_TCP_EX)) != 0)
|
|
|
|
efx_hash_types |= EFX_RX_HASH_TCPIPV6;
|
|
|
|
|
|
|
|
return efx_hash_types;
|
|
|
|
}
|
2016-12-15 12:51:19 +00:00
|
|
|
|
|
|
|
uint64_t
|
|
|
|
sfc_efx_to_rte_hash_type(efx_rx_hash_type_t efx_hash_types)
|
|
|
|
{
|
|
|
|
uint64_t rss_hf = 0;
|
|
|
|
|
|
|
|
if ((efx_hash_types & EFX_RX_HASH_IPV4) != 0)
|
|
|
|
rss_hf |= (ETH_RSS_IPV4 | ETH_RSS_FRAG_IPV4 |
|
|
|
|
ETH_RSS_NONFRAG_IPV4_OTHER);
|
|
|
|
|
|
|
|
if ((efx_hash_types & EFX_RX_HASH_TCPIPV4) != 0)
|
|
|
|
rss_hf |= ETH_RSS_NONFRAG_IPV4_TCP;
|
|
|
|
|
|
|
|
if ((efx_hash_types & EFX_RX_HASH_IPV6) != 0)
|
|
|
|
rss_hf |= (ETH_RSS_IPV6 | ETH_RSS_FRAG_IPV6 |
|
|
|
|
ETH_RSS_NONFRAG_IPV6_OTHER | ETH_RSS_IPV6_EX);
|
|
|
|
|
|
|
|
if ((efx_hash_types & EFX_RX_HASH_TCPIPV6) != 0)
|
|
|
|
rss_hf |= (ETH_RSS_NONFRAG_IPV6_TCP | ETH_RSS_IPV6_TCP_EX);
|
|
|
|
|
|
|
|
return rss_hf;
|
|
|
|
}
|
2016-12-15 12:51:17 +00:00
|
|
|
#endif
|
|
|
|
|
2017-08-30 18:17:31 +00:00
|
|
|
#if EFSYS_OPT_RX_SCALE
|
2016-12-15 12:51:17 +00:00
|
|
|
static int
|
|
|
|
sfc_rx_rss_config(struct sfc_adapter *sa)
|
|
|
|
{
|
|
|
|
int rc = 0;
|
|
|
|
|
2017-04-18 13:03:07 +00:00
|
|
|
if (sa->rss_channels > 0) {
|
2017-08-30 18:17:37 +00:00
|
|
|
rc = efx_rx_scale_mode_set(sa->nic, EFX_RSS_CONTEXT_DEFAULT,
|
|
|
|
EFX_RX_HASHALG_TOEPLITZ,
|
2016-12-15 12:51:17 +00:00
|
|
|
sa->rss_hash_types, B_TRUE);
|
|
|
|
if (rc != 0)
|
|
|
|
goto finish;
|
|
|
|
|
2017-08-30 18:17:37 +00:00
|
|
|
rc = efx_rx_scale_key_set(sa->nic, EFX_RSS_CONTEXT_DEFAULT,
|
|
|
|
sa->rss_key,
|
2016-12-15 12:51:17 +00:00
|
|
|
sizeof(sa->rss_key));
|
|
|
|
if (rc != 0)
|
|
|
|
goto finish;
|
|
|
|
|
2017-08-30 18:17:37 +00:00
|
|
|
rc = efx_rx_scale_tbl_set(sa->nic, EFX_RSS_CONTEXT_DEFAULT,
|
|
|
|
sa->rss_tbl, RTE_DIM(sa->rss_tbl));
|
2016-12-15 12:51:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
finish:
|
|
|
|
return rc;
|
|
|
|
}
|
2017-08-30 18:17:31 +00:00
|
|
|
#else
|
|
|
|
static int
|
|
|
|
sfc_rx_rss_config(__rte_unused struct sfc_adapter *sa)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
2016-12-15 12:51:17 +00:00
|
|
|
|
2016-11-29 16:19:20 +00:00
|
|
|
int
|
|
|
|
sfc_rx_start(struct sfc_adapter *sa)
|
|
|
|
{
|
|
|
|
unsigned int sw_index;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
sfc_log_init(sa, "rxq_count=%u", sa->rxq_count);
|
|
|
|
|
|
|
|
rc = efx_rx_init(sa->nic);
|
|
|
|
if (rc != 0)
|
|
|
|
goto fail_rx_init;
|
|
|
|
|
2016-12-15 12:51:17 +00:00
|
|
|
rc = sfc_rx_rss_config(sa);
|
|
|
|
if (rc != 0)
|
|
|
|
goto fail_rss_config;
|
|
|
|
|
2016-11-29 16:19:20 +00:00
|
|
|
for (sw_index = 0; sw_index < sa->rxq_count; ++sw_index) {
|
2016-12-15 12:51:11 +00:00
|
|
|
if ((!sa->rxq_info[sw_index].deferred_start ||
|
|
|
|
sa->rxq_info[sw_index].deferred_started)) {
|
|
|
|
rc = sfc_rx_qstart(sa, sw_index);
|
|
|
|
if (rc != 0)
|
|
|
|
goto fail_rx_qstart;
|
|
|
|
}
|
2016-11-29 16:19:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
fail_rx_qstart:
|
|
|
|
while (sw_index-- > 0)
|
|
|
|
sfc_rx_qstop(sa, sw_index);
|
|
|
|
|
2016-12-15 12:51:17 +00:00
|
|
|
fail_rss_config:
|
2016-11-29 16:19:20 +00:00
|
|
|
efx_rx_fini(sa->nic);
|
|
|
|
|
|
|
|
fail_rx_init:
|
|
|
|
sfc_log_init(sa, "failed %d", rc);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
sfc_rx_stop(struct sfc_adapter *sa)
|
|
|
|
{
|
|
|
|
unsigned int sw_index;
|
|
|
|
|
|
|
|
sfc_log_init(sa, "rxq_count=%u", sa->rxq_count);
|
|
|
|
|
|
|
|
sw_index = sa->rxq_count;
|
|
|
|
while (sw_index-- > 0) {
|
|
|
|
if (sa->rxq_info[sw_index].rxq != NULL)
|
|
|
|
sfc_rx_qstop(sa, sw_index);
|
|
|
|
}
|
|
|
|
|
|
|
|
efx_rx_fini(sa->nic);
|
|
|
|
}
|
|
|
|
|
2016-11-29 16:19:15 +00:00
|
|
|
static int
|
|
|
|
sfc_rx_qinit_info(struct sfc_adapter *sa, unsigned int sw_index)
|
|
|
|
{
|
|
|
|
struct sfc_rxq_info *rxq_info = &sa->rxq_info[sw_index];
|
|
|
|
unsigned int max_entries;
|
|
|
|
|
|
|
|
max_entries = EFX_RXQ_MAXNDESCS;
|
|
|
|
SFC_ASSERT(rte_is_power_of_2(max_entries));
|
|
|
|
|
|
|
|
rxq_info->max_entries = max_entries;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-11-29 16:19:16 +00:00
|
|
|
static int
|
|
|
|
sfc_rx_check_mode(struct sfc_adapter *sa, struct rte_eth_rxmode *rxmode)
|
|
|
|
{
|
|
|
|
int rc = 0;
|
|
|
|
|
|
|
|
switch (rxmode->mq_mode) {
|
|
|
|
case ETH_MQ_RX_NONE:
|
|
|
|
/* No special checks are required */
|
|
|
|
break;
|
2016-12-15 12:51:17 +00:00
|
|
|
#if EFSYS_OPT_RX_SCALE
|
|
|
|
case ETH_MQ_RX_RSS:
|
|
|
|
if (sa->rss_support == EFX_RX_SCALE_UNAVAILABLE) {
|
|
|
|
sfc_err(sa, "RSS is not available");
|
|
|
|
rc = EINVAL;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
#endif
|
2016-11-29 16:19:16 +00:00
|
|
|
default:
|
|
|
|
sfc_err(sa, "Rx multi-queue mode %u not supported",
|
|
|
|
rxmode->mq_mode);
|
|
|
|
rc = EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rxmode->header_split) {
|
|
|
|
sfc_err(sa, "Header split on Rx not supported");
|
|
|
|
rc = EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rxmode->hw_vlan_filter) {
|
|
|
|
sfc_err(sa, "HW VLAN filtering not supported");
|
|
|
|
rc = EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rxmode->hw_vlan_strip) {
|
|
|
|
sfc_err(sa, "HW VLAN stripping not supported");
|
|
|
|
rc = EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rxmode->hw_vlan_extend) {
|
|
|
|
sfc_err(sa,
|
|
|
|
"Q-in-Q HW VLAN stripping not supported");
|
|
|
|
rc = EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!rxmode->hw_strip_crc) {
|
|
|
|
sfc_warn(sa,
|
|
|
|
"FCS stripping control not supported - always stripped");
|
|
|
|
rxmode->hw_strip_crc = 1;
|
|
|
|
}
|
|
|
|
|
2017-03-20 10:15:11 +00:00
|
|
|
if (rxmode->enable_scatter &&
|
|
|
|
(~sa->dp_rx->features & SFC_DP_RX_FEAT_SCATTER)) {
|
|
|
|
sfc_err(sa, "Rx scatter not supported by %s datapath",
|
|
|
|
sa->dp_rx->dp.name);
|
|
|
|
rc = EINVAL;
|
|
|
|
}
|
|
|
|
|
2016-11-29 16:19:16 +00:00
|
|
|
if (rxmode->enable_lro) {
|
|
|
|
sfc_err(sa, "LRO not supported");
|
|
|
|
rc = EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2017-03-31 10:22:21 +00:00
|
|
|
/**
|
|
|
|
* Destroy excess queues that are no longer needed after reconfiguration
|
|
|
|
* or complete close.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
sfc_rx_fini_queues(struct sfc_adapter *sa, unsigned int nb_rx_queues)
|
|
|
|
{
|
|
|
|
int sw_index;
|
|
|
|
|
|
|
|
SFC_ASSERT(nb_rx_queues <= sa->rxq_count);
|
|
|
|
|
|
|
|
sw_index = sa->rxq_count;
|
|
|
|
while (--sw_index >= (int)nb_rx_queues) {
|
|
|
|
if (sa->rxq_info[sw_index].rxq != NULL)
|
|
|
|
sfc_rx_qfini(sa, sw_index);
|
|
|
|
}
|
|
|
|
|
|
|
|
sa->rxq_count = nb_rx_queues;
|
|
|
|
}
|
|
|
|
|
2016-11-29 16:19:15 +00:00
|
|
|
/**
|
|
|
|
* Initialize Rx subsystem.
|
|
|
|
*
|
2017-03-31 10:22:21 +00:00
|
|
|
* Called at device (re)configuration stage when number of receive queues is
|
2016-11-29 16:19:15 +00:00
|
|
|
* specified together with other device level receive configuration.
|
|
|
|
*
|
|
|
|
* It should be used to allocate NUMA-unaware resources.
|
|
|
|
*/
|
|
|
|
int
|
2017-03-31 10:22:19 +00:00
|
|
|
sfc_rx_configure(struct sfc_adapter *sa)
|
2016-11-29 16:19:15 +00:00
|
|
|
{
|
2016-11-29 16:19:16 +00:00
|
|
|
struct rte_eth_conf *dev_conf = &sa->eth_dev->data->dev_conf;
|
2017-03-31 10:22:21 +00:00
|
|
|
const unsigned int nb_rx_queues = sa->eth_dev->data->nb_rx_queues;
|
2016-11-29 16:19:15 +00:00
|
|
|
int rc;
|
|
|
|
|
2017-03-31 10:22:21 +00:00
|
|
|
sfc_log_init(sa, "nb_rx_queues=%u (old %u)",
|
|
|
|
nb_rx_queues, sa->rxq_count);
|
|
|
|
|
2016-11-29 16:19:16 +00:00
|
|
|
rc = sfc_rx_check_mode(sa, &dev_conf->rxmode);
|
|
|
|
if (rc != 0)
|
|
|
|
goto fail_check_mode;
|
|
|
|
|
2017-03-31 10:22:21 +00:00
|
|
|
if (nb_rx_queues == sa->rxq_count)
|
|
|
|
goto done;
|
2016-11-29 16:19:15 +00:00
|
|
|
|
2017-03-31 10:22:21 +00:00
|
|
|
if (sa->rxq_info == NULL) {
|
|
|
|
rc = ENOMEM;
|
|
|
|
sa->rxq_info = rte_calloc_socket("sfc-rxqs", nb_rx_queues,
|
|
|
|
sizeof(sa->rxq_info[0]), 0,
|
|
|
|
sa->socket_id);
|
|
|
|
if (sa->rxq_info == NULL)
|
|
|
|
goto fail_rxqs_alloc;
|
|
|
|
} else {
|
|
|
|
struct sfc_rxq_info *new_rxq_info;
|
|
|
|
|
|
|
|
if (nb_rx_queues < sa->rxq_count)
|
|
|
|
sfc_rx_fini_queues(sa, nb_rx_queues);
|
|
|
|
|
|
|
|
rc = ENOMEM;
|
|
|
|
new_rxq_info =
|
|
|
|
rte_realloc(sa->rxq_info,
|
|
|
|
nb_rx_queues * sizeof(sa->rxq_info[0]), 0);
|
|
|
|
if (new_rxq_info == NULL && nb_rx_queues > 0)
|
|
|
|
goto fail_rxqs_realloc;
|
|
|
|
|
|
|
|
sa->rxq_info = new_rxq_info;
|
|
|
|
if (nb_rx_queues > sa->rxq_count)
|
|
|
|
memset(&sa->rxq_info[sa->rxq_count], 0,
|
|
|
|
(nb_rx_queues - sa->rxq_count) *
|
|
|
|
sizeof(sa->rxq_info[0]));
|
|
|
|
}
|
2016-11-29 16:19:15 +00:00
|
|
|
|
2017-03-31 10:22:21 +00:00
|
|
|
while (sa->rxq_count < nb_rx_queues) {
|
|
|
|
rc = sfc_rx_qinit_info(sa, sa->rxq_count);
|
2016-11-29 16:19:15 +00:00
|
|
|
if (rc != 0)
|
|
|
|
goto fail_rx_qinit_info;
|
2017-03-31 10:22:21 +00:00
|
|
|
|
|
|
|
sa->rxq_count++;
|
2016-11-29 16:19:15 +00:00
|
|
|
}
|
|
|
|
|
2016-12-15 12:51:17 +00:00
|
|
|
#if EFSYS_OPT_RX_SCALE
|
|
|
|
sa->rss_channels = (dev_conf->rxmode.mq_mode == ETH_MQ_RX_RSS) ?
|
2017-04-18 13:03:07 +00:00
|
|
|
MIN(sa->rxq_count, EFX_MAXRSS) : 0;
|
2016-12-15 12:51:17 +00:00
|
|
|
|
2017-04-18 13:03:07 +00:00
|
|
|
if (sa->rss_channels > 0) {
|
2017-08-30 18:17:31 +00:00
|
|
|
unsigned int sw_index;
|
|
|
|
|
2016-12-15 12:51:17 +00:00
|
|
|
for (sw_index = 0; sw_index < EFX_RSS_TBL_SIZE; ++sw_index)
|
|
|
|
sa->rss_tbl[sw_index] = sw_index % sa->rss_channels;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-03-31 10:22:21 +00:00
|
|
|
done:
|
2016-11-29 16:19:15 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
fail_rx_qinit_info:
|
2017-03-31 10:22:21 +00:00
|
|
|
fail_rxqs_realloc:
|
2016-11-29 16:19:15 +00:00
|
|
|
fail_rxqs_alloc:
|
2017-03-31 10:22:21 +00:00
|
|
|
sfc_rx_close(sa);
|
|
|
|
|
2016-11-29 16:19:16 +00:00
|
|
|
fail_check_mode:
|
2016-11-29 16:19:15 +00:00
|
|
|
sfc_log_init(sa, "failed %d", rc);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shutdown Rx subsystem.
|
|
|
|
*
|
2017-03-31 10:22:21 +00:00
|
|
|
* Called at device close stage, for example, before device shutdown.
|
2016-11-29 16:19:15 +00:00
|
|
|
*/
|
|
|
|
void
|
2017-03-31 10:22:19 +00:00
|
|
|
sfc_rx_close(struct sfc_adapter *sa)
|
2016-11-29 16:19:15 +00:00
|
|
|
{
|
2017-03-31 10:22:21 +00:00
|
|
|
sfc_rx_fini_queues(sa, 0);
|
2016-11-29 16:19:17 +00:00
|
|
|
|
2017-04-18 13:03:06 +00:00
|
|
|
sa->rss_channels = 0;
|
|
|
|
|
2016-11-29 16:19:15 +00:00
|
|
|
rte_free(sa->rxq_info);
|
|
|
|
sa->rxq_info = NULL;
|
|
|
|
}
|