From owner-svn-src-head@freebsd.org Thu Nov 9 13:35:08 2017 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id EDE65E50621; Thu, 9 Nov 2017 13:35:08 +0000 (UTC) (envelope-from mw@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id C7A96662FF; Thu, 9 Nov 2017 13:35:08 +0000 (UTC) (envelope-from mw@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id vA9DZ7BC093061; Thu, 9 Nov 2017 13:35:07 GMT (envelope-from mw@FreeBSD.org) Received: (from mw@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id vA9DZ7YP093059; Thu, 9 Nov 2017 13:35:07 GMT (envelope-from mw@FreeBSD.org) Message-Id: <201711091335.vA9DZ7YP093059@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mw set sender to mw@FreeBSD.org using -f From: Marcin Wojtas Date: Thu, 9 Nov 2017 13:35:07 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r325591 - head/sys/dev/ena X-SVN-Group: head X-SVN-Commit-Author: mw X-SVN-Commit-Paths: head/sys/dev/ena X-SVN-Commit-Revision: 325591 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 09 Nov 2017 13:35:09 -0000 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 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;