Signed-off-by: Andrew Rybchenko <arybche...@solarflare.com>
Reviewed-by: Andrew Lee <a...@solarflare.com>
Reviewed-by: Robert Stonehouse <rstoneho...@solarflare.com>
---
 doc/guides/nics/features/sfc_efx.ini |  2 ++
 doc/guides/nics/sfc_efx.rst          |  4 +++
 drivers/net/sfc/sfc_ethdev.c         | 67 ++++++++++++++++++++++++++++++++++++
 3 files changed, 73 insertions(+)

diff --git a/doc/guides/nics/features/sfc_efx.ini 
b/doc/guides/nics/features/sfc_efx.ini
index 693d35e..a845bfc 100644
--- a/doc/guides/nics/features/sfc_efx.ini
+++ b/doc/guides/nics/features/sfc_efx.ini
@@ -6,6 +6,8 @@
 [Features]
 Link status          = Y
 Link status event    = Y
+MTU update           = Y
+Jumbo frame          = Y
 Flow control         = Y
 L3 checksum offload  = P
 L4 checksum offload  = P
diff --git a/doc/guides/nics/sfc_efx.rst b/doc/guides/nics/sfc_efx.rst
index 58f8242..c482d77 100644
--- a/doc/guides/nics/sfc_efx.rst
+++ b/doc/guides/nics/sfc_efx.rst
@@ -55,6 +55,10 @@ SFC EFX PMD has support for:
 
 - Basic flow control
 
+- MTU update
+
+- Jumbo frames up to 9K
+
 
 Non-supported Features
 ----------------------
diff --git a/drivers/net/sfc/sfc_ethdev.c b/drivers/net/sfc/sfc_ethdev.c
index 8c46500..6690755 100644
--- a/drivers/net/sfc/sfc_ethdev.c
+++ b/drivers/net/sfc/sfc_ethdev.c
@@ -549,6 +549,72 @@ sfc_flow_ctrl_set(struct rte_eth_dev *dev, struct 
rte_eth_fc_conf *fc_conf)
        return -rc;
 }
 
+static int
+sfc_dev_set_mtu(struct rte_eth_dev *dev, uint16_t mtu)
+{
+       struct sfc_adapter *sa = dev->data->dev_private;
+       size_t pdu = EFX_MAC_PDU(mtu);
+       size_t old_pdu;
+       int rc;
+
+       sfc_log_init(sa, "mtu=%u", mtu);
+
+       rc = EINVAL;
+       if (pdu < EFX_MAC_PDU_MIN) {
+               sfc_err(sa, "too small MTU %u (PDU size %u less than min %u)",
+                       (unsigned int)mtu, (unsigned int)pdu,
+                       EFX_MAC_PDU_MIN);
+               goto fail_inval;
+       }
+       if (pdu > EFX_MAC_PDU_MAX) {
+               sfc_err(sa, "too big MTU %u (PDU size %u greater than max %u)",
+                       (unsigned int)mtu, (unsigned int)pdu,
+                       EFX_MAC_PDU_MAX);
+               goto fail_inval;
+       }
+
+       sfc_adapter_lock(sa);
+
+       if (pdu != sa->port.pdu) {
+               if (sa->state == SFC_ADAPTER_STARTED) {
+                       sfc_stop(sa);
+
+                       old_pdu = sa->port.pdu;
+                       sa->port.pdu = pdu;
+                       rc = sfc_start(sa);
+                       if (rc != 0)
+                               goto fail_start;
+               } else {
+                       sa->port.pdu = pdu;
+               }
+       }
+
+       /*
+        * The driver does not use it, but other PMDs update jumbo_frame
+        * flag and max_rx_pkt_len when MTU is set.
+        */
+       dev->data->dev_conf.rxmode.jumbo_frame = (mtu > ETHER_MAX_LEN);
+       dev->data->dev_conf.rxmode.max_rx_pkt_len = sa->port.pdu;
+
+       sfc_adapter_unlock(sa);
+
+       sfc_log_init(sa, "done");
+       return 0;
+
+fail_start:
+       sa->port.pdu = old_pdu;
+       if (sfc_start(sa) != 0)
+               sfc_err(sa, "cannot start with neither new (%u) nor old (%u) "
+                       "PDU max size - port is stopped",
+                       (unsigned int)pdu, (unsigned int)old_pdu);
+       sfc_adapter_unlock(sa);
+
+fail_inval:
+       sfc_log_init(sa, "failed %d", rc);
+       SFC_ASSERT(rc > 0);
+       return -rc;
+}
+
 static const struct eth_dev_ops sfc_eth_dev_ops = {
        .dev_configure                  = sfc_dev_configure,
        .dev_start                      = sfc_dev_start,
@@ -559,6 +625,7 @@ static const struct eth_dev_ops sfc_eth_dev_ops = {
        .xstats_get                     = sfc_xstats_get,
        .xstats_get_names               = sfc_xstats_get_names,
        .dev_infos_get                  = sfc_dev_infos_get,
+       .mtu_set                        = sfc_dev_set_mtu,
        .rx_queue_setup                 = sfc_rx_queue_setup,
        .rx_queue_release               = sfc_rx_queue_release,
        .tx_queue_setup                 = sfc_tx_queue_setup,
-- 
2.5.5

Reply via email to