Date: Thu, 9 Nov 2017 13:35:07 +0000 (UTC) From: Marcin Wojtas <mw@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r325591 - head/sys/dev/ena Message-ID: <201711091335.vA9DZ7YP093059@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: mw Date: Thu Nov 9 13:35:07 2017 New Revision: 325591 URL: https://svnweb.freebsd.org/changeset/base/325591 Log: Read max MTU from the ENA device The device now provides driver with max available MTU value it can handle. The function setting MTU for the interface was simplified and reworked to follow up this changes. Submitted by: Michal Krawczyk <mk@semihalf.com> Reviewed by: byenduri_gmail.com Obtained from: Semihalf Sponsored by: Amazon, Inc. Differential Revision: https://reviews.freebsd.org/D12870 Modified: head/sys/dev/ena/ena.c head/sys/dev/ena/ena.h Modified: head/sys/dev/ena/ena.c ============================================================================== --- head/sys/dev/ena/ena.c Thu Nov 9 13:33:02 2017 (r325590) +++ head/sys/dev/ena/ena.c Thu Nov 9 13:35:07 2017 (r325591) @@ -351,39 +351,25 @@ static int ena_change_mtu(if_t ifp, int new_mtu) { struct ena_adapter *adapter = if_getsoftc(ifp); - struct ena_com_dev_get_features_ctx get_feat_ctx; - int rc, old_mtu, max_frame; + int rc; - rc = ena_com_get_dev_attr_feat(adapter->ena_dev, &get_feat_ctx); - if (unlikely(rc != 0)) { - device_printf(adapter->pdev, - "Cannot get attribute for ena device\n"); - return (ENXIO); - } - - /* Save old MTU in case of fail */ - old_mtu = if_getmtu(ifp); - - /* Change MTU and calculate max frame */ - if_setmtu(ifp, new_mtu); - max_frame = ETHER_MAX_FRAME(ifp, ETHERTYPE_VLAN, 1); - - if (unlikely((new_mtu < ENA_MIN_FRAME_LEN) || - (new_mtu > get_feat_ctx.dev_attr.max_mtu) || - (max_frame > ENA_MAX_FRAME_LEN))) { + if ((new_mtu > adapter->max_mtu) || (new_mtu < ENA_MIN_MTU)) { device_printf(adapter->pdev, "Invalid MTU setting. " - "new_mtu: %d\n", new_mtu); - goto error; + "new_mtu: %d max mtu: %d min mtu: %d\n", + new_mtu, adapter->max_mtu, ENA_MIN_MTU); + return (EINVAL); } rc = ena_com_set_dev_mtu(adapter->ena_dev, new_mtu); - if (rc != 0) - goto error; + if (likely(rc == 0)) { + ena_trace(ENA_DBG, "set MTU to %d\n", new_mtu); + if_setmtu(ifp, new_mtu); + } else { + device_printf(adapter->pdev, "Failed to set MTU to %d\n", + new_mtu); + } - return (0); -error: - if_setmtu(ifp, old_mtu); - return (EINVAL); + return (rc); } static inline void @@ -3703,6 +3689,8 @@ ena_attach(device_t pdev) ENA_ASSERT(io_queue_num > 0, "Invalid queue number: %d\n", io_queue_num); adapter->num_queues = io_queue_num; + + adapter->max_mtu = get_feat_ctx.dev_attr.max_mtu; /* calculatre ring sizes */ queue_size = ena_calc_queue_size(adapter,&tx_sgl_size, Modified: head/sys/dev/ena/ena.h ============================================================================== --- head/sys/dev/ena/ena.h Thu Nov 9 13:33:02 2017 (r325590) +++ head/sys/dev/ena/ena.h Thu Nov 9 13:35:07 2017 (r325591) @@ -103,6 +103,8 @@ #define RX_IRQ_INTERVAL 20 #define TX_IRQ_INTERVAL 50 +#define ENA_MIN_MTU 128 + #define ENA_TSO_MAXSIZE 65536 #define ENA_MMIO_DISABLE_REG_READ BIT(0) @@ -325,6 +327,8 @@ struct ena_adapter { bus_dma_tag_t tx_buf_tag; bus_dma_tag_t rx_buf_tag; int dma_width; + + uint32_t max_mtu; uint16_t max_tx_sgl_size; uint16_t max_rx_sgl_size;
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201711091335.vA9DZ7YP093059>