From d41a6268d57a2ebfa52f86cf6f7ddbabff1f05d8 Mon Sep 17 00:00:00 2001 From: Igor Romanov Date: Tue, 13 Oct 2020 14:45:24 +0100 Subject: [PATCH] net/sfc: check for maximum number of Rx scatter buffers Update generic code to check that MTU and Rx buffer sizes do not result in more Rx scatter segments than NIC can make. Signed-off-by: Igor Romanov Signed-off-by: Andrew Rybchenko --- drivers/net/sfc/sfc_ethdev.c | 3 ++- drivers/net/sfc/sfc_rx.c | 17 ++++++++++++++--- drivers/net/sfc/sfc_rx.h | 1 + 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/drivers/net/sfc/sfc_ethdev.c b/drivers/net/sfc/sfc_ethdev.c index f41d0f5fe2..ca1b99a00f 100644 --- a/drivers/net/sfc/sfc_ethdev.c +++ b/drivers/net/sfc/sfc_ethdev.c @@ -954,7 +954,8 @@ sfc_check_scatter_on_all_rx_queues(struct sfc_adapter *sa, size_t pdu) if (!sfc_rx_check_scatter(pdu, sa->rxq_ctrl[i].buf_size, encp->enc_rx_prefix_size, - scatter_enabled, &error)) { + scatter_enabled, + encp->enc_rx_scatter_max, &error)) { sfc_err(sa, "MTU check for RxQ %u failed: %s", i, error); return EINVAL; diff --git a/drivers/net/sfc/sfc_rx.c b/drivers/net/sfc/sfc_rx.c index 3e5c8e42da..7c50fe58b8 100644 --- a/drivers/net/sfc/sfc_rx.c +++ b/drivers/net/sfc/sfc_rx.c @@ -378,10 +378,20 @@ sfc_efx_rx_qdesc_status(struct sfc_dp_rxq *dp_rxq, uint16_t offset) boolean_t sfc_rx_check_scatter(size_t pdu, size_t rx_buf_size, uint32_t rx_prefix_size, - boolean_t rx_scatter_enabled, const char **error) + boolean_t rx_scatter_enabled, uint32_t rx_scatter_max, + const char **error) { - if ((rx_buf_size < pdu + rx_prefix_size) && !rx_scatter_enabled) { - *error = "Rx scatter is disabled and RxQ mbuf pool object size is too small"; + uint32_t effective_rx_scatter_max; + uint32_t rx_scatter_bufs; + + effective_rx_scatter_max = rx_scatter_enabled ? rx_scatter_max : 1; + rx_scatter_bufs = EFX_DIV_ROUND_UP(pdu + rx_prefix_size, rx_buf_size); + + if (rx_scatter_bufs > effective_rx_scatter_max) { + if (rx_scatter_enabled) + *error = "Possible number of Rx scatter buffers exceeds maximum number"; + else + *error = "Rx scatter is disabled and RxQ mbuf pool object size is too small"; return B_FALSE; } @@ -1084,6 +1094,7 @@ sfc_rx_qinit(struct sfc_adapter *sa, unsigned int sw_index, if (!sfc_rx_check_scatter(sa->port.pdu, buf_size, encp->enc_rx_prefix_size, (offloads & DEV_RX_OFFLOAD_SCATTER), + encp->enc_rx_scatter_max, &error)) { sfc_err(sa, "RxQ %u MTU check failed: %s", sw_index, error); sfc_err(sa, "RxQ %u calculated Rx buffer size is %u vs " diff --git a/drivers/net/sfc/sfc_rx.h b/drivers/net/sfc/sfc_rx.h index b0b5327a49..d6ee9cf802 100644 --- a/drivers/net/sfc/sfc_rx.h +++ b/drivers/net/sfc/sfc_rx.h @@ -147,6 +147,7 @@ uint64_t sfc_rx_hf_efx_to_rte(struct sfc_rss *rss, efx_rx_hash_type_t efx); boolean_t sfc_rx_check_scatter(size_t pdu, size_t rx_buf_size, uint32_t rx_prefix_size, boolean_t rx_scatter_enabled, + uint32_t rx_scatter_max, const char **error); #ifdef __cplusplus -- 2.20.1