From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lf1-f66.google.com (mail-lf1-f66.google.com [209.85.167.66]) by dpdk.org (Postfix) with ESMTP id 624D95911 for ; Fri, 31 Aug 2018 14:26:20 +0200 (CEST) Received: by mail-lf1-f66.google.com with SMTP id x26-v6so9830899lfi.7 for ; Fri, 31 Aug 2018 05:26:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=a+Cta85EWUKpT64PU8UyNVUyMG8cM3zlt4ooWDcXcnY=; b=OVmdDB6EWcD/w9D5ZYJqGYghs4IzYEqh1nGrzy6vv6AGtj8ReLZC7jMe0gwJHUKcmA bpZdYeylf1OhAdeqNfgV4No7QxgcJ4XkntetoZQiPvmjA6QWJHu1UMetEHnMltiq/c1X FKKj4mIcaTTP4Vk7SD8zfVnJUoV494/tPX3fnq7iNRJkhlXMKxCvmyCag21Eoasq7m2i eJ78DVLAAj6IAbu9R3NOQzfXMQWRTwSvPB0v66F9xufHzX1So1VFArTjbzl1IEpazD90 e1Ejclptg0CcigxAEwEj7byXzzFnRbz7bPkenogmN6mAHWu4NQWwJutrscmdeO2iCJoL AEOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=a+Cta85EWUKpT64PU8UyNVUyMG8cM3zlt4ooWDcXcnY=; b=iTfEvrJtjFRGnFtfVxP96A9onBED1dHh1x+xgGuFHwmYJvWOml+nppMzEMBBdpgPoD 9WCQ3dAT4IvCFXYPsSfmA4qgqldSK6/5t8jmMx4x0X/uNYArdYZukR8sg9b3bH1E50hr 3bd+U7mfPHa3XKytdjLHBGMb0qUONHfzB2vnHqIPi0ezOeX430OSofmICZ0ndd3OcNcO mpDYbmd6wmDo7cRowStz+fs+c4gczVdQ/OYqnJO81rxJ2/54fX5bdOeZJYIXqiCnvju5 JP2LVQOGTOXcvdbsipfA91gc8EjzpKNbYjlN1C5TtxUWbziGmv5iGqFi2+NZ4s7SVx2L zFhQ== X-Gm-Message-State: APzg51C/jbsMXdEg92b/WW02cz6O9PoJX/DkWRFjyr8Jx7rWGaXiDgO8 qxIfJku4uqN22iGrcE4DbMGCAUntavc= X-Google-Smtp-Source: ANB0VdZD+01m+cS3D0WaAb5hSQeTS71IfedDcL8oBRlfEE5vrrAFo2Fy6H7IoPMdKoOUzRN4hbAMSQ== X-Received: by 2002:ac2:428f:: with SMTP id m15-v6mr10017377lfh.52.1535718379895; Fri, 31 Aug 2018 05:26:19 -0700 (PDT) Received: from amok.semihalf.local (31-172-191-173.noc.fibertech.net.pl. [31.172.191.173]) by smtp.googlemail.com with ESMTPSA id t4-v6sm1825422lfd.13.2018.08.31.05.26.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 31 Aug 2018 05:26:19 -0700 (PDT) From: Andrzej Ostruszka To: dev@dpdk.org Cc: mw@semihalf.com, zr@semihalf.com, tdu@semihalf.com, nsamsono@marvell.com Date: Fri, 31 Aug 2018 14:26:04 +0200 Message-Id: <1535718368-15803-9-git-send-email-amo@semihalf.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1535718368-15803-1-git-send-email-amo@semihalf.com> References: <1535469030-18647-1-git-send-email-amo@semihalf.com> <1535718368-15803-1-git-send-email-amo@semihalf.com> Subject: [dpdk-dev] [PATCH v2 4/8] net/mvneta: support for setting of MTU X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 31 Aug 2018 12:26:21 -0000 From: Zyta Szpak Add callback for setting of MTU. Signed-off-by: Natalie Samsonov Signed-off-by: Zyta Szpak --- drivers/net/mvneta/mvneta_ethdev.c | 149 +++++++++++++++++++++++++++++++++++++ 1 file changed, 149 insertions(+) diff --git a/drivers/net/mvneta/mvneta_ethdev.c b/drivers/net/mvneta/mvneta_ethdev.c index 968f920..a7e79ea 100644 --- a/drivers/net/mvneta/mvneta_ethdev.c +++ b/drivers/net/mvneta/mvneta_ethdev.c @@ -1025,6 +1025,77 @@ static void mvneta_txq_info_get(struct rte_eth_dev *dev, uint16_t tx_queue_id, } /** + * DPDK callback to change the MTU. + * + * Setting the MTU affects hardware MRU (packets larger than the MRU + * will be dropped). + * + * @param dev + * Pointer to Ethernet device structure. + * @param mtu + * New MTU. + * + * @return + * 0 on success, negative error value otherwise. + */ +static int +mvneta_mtu_set(struct rte_eth_dev *dev, uint16_t mtu) +{ + struct mvneta_priv *priv = dev->data->dev_private; + uint16_t mbuf_data_size = 0; /* SW buffer size */ + uint16_t mru; + int ret; + + mru = MRVL_NETA_MTU_TO_MRU(mtu); + /* + * min_rx_buf_size is equal to mbuf data size + * if pmd didn't set it differently + */ + mbuf_data_size = dev->data->min_rx_buf_size - RTE_PKTMBUF_HEADROOM; + /* Prevent PMD from: + * - setting mru greater than the mbuf size resulting in + * hw and sw buffer size mismatch + * - setting mtu that requires the support of scattered packets + * when this feature has not been enabled/supported so far. + */ + if (!dev->data->scattered_rx && + (mru + MRVL_NETA_PKT_OFFS > mbuf_data_size)) { + mru = mbuf_data_size - MRVL_NETA_PKT_OFFS; + mtu = MRVL_NETA_MRU_TO_MTU(mru); + MVNETA_LOG(WARNING, "MTU too big, max MTU possible limitted by" + " current mbuf size: %u. Set MTU to %u, MRU to %u", + mbuf_data_size, mtu, mru); + } + + if (mtu < ETHER_MIN_MTU || mru > MVNETA_PKT_SIZE_MAX) { + MVNETA_LOG(ERR, "Invalid MTU [%u] or MRU [%u]", mtu, mru); + return -EINVAL; + } + + dev->data->mtu = mtu; + dev->data->dev_conf.rxmode.max_rx_pkt_len = mru - MV_MH_SIZE; + + if (!priv->ppio) + /* It is OK. New MTU will be set later on mvneta_dev_start */ + return 0; + + ret = neta_ppio_set_mru(priv->ppio, mru); + if (ret) { + MVNETA_LOG(ERR, "Failed to change MRU"); + return ret; + } + + ret = neta_ppio_set_mtu(priv->ppio, mtu); + if (ret) { + MVNETA_LOG(ERR, "Failed to change MTU"); + return ret; + } + MVNETA_LOG(INFO, "MTU changed to %u, MRU = %u", mtu, mru); + + return 0; +} + +/** * DPDK callback to bring the link up. * * @param dev @@ -1298,6 +1369,12 @@ mvneta_dev_start(struct rte_eth_dev *dev) } } + ret = mvneta_mtu_set(dev, dev->data->mtu); + if (ret) { + MVNETA_LOG(ERR, "Failed to set MTU %d", dev->data->mtu); + goto out; + } + ret = mvneta_dev_set_link_up(dev); if (ret) { MVNETA_LOG(ERR, "Failed to set link up"); @@ -1380,6 +1457,76 @@ mvneta_dev_close(struct rte_eth_dev *dev) } /** + * DPDK callback to retrieve physical link information. + * + * @param dev + * Pointer to Ethernet device structure. + * @param wait_to_complete + * Wait for request completion (ignored). + * + * @return + * 0 on success, negative error value otherwise. + */ +static int +mvneta_link_update(struct rte_eth_dev *dev, int wait_to_complete __rte_unused) +{ + /* + * TODO + * once MUSDK provides necessary API use it here + */ + struct mvneta_priv *priv = dev->data->dev_private; + struct ethtool_cmd edata; + struct ifreq req; + int ret, fd, link_up; + + if (!priv->ppio) + return -EPERM; + + edata.cmd = ETHTOOL_GSET; + + strcpy(req.ifr_name, dev->data->name); + req.ifr_data = (void *)&edata; + + fd = socket(AF_INET, SOCK_DGRAM, 0); + if (fd == -1) + return -EFAULT; + ret = ioctl(fd, SIOCETHTOOL, &req); + if (ret == -1) { + close(fd); + return -EFAULT; + } + + close(fd); + + switch (ethtool_cmd_speed(&edata)) { + case SPEED_10: + dev->data->dev_link.link_speed = ETH_SPEED_NUM_10M; + break; + case SPEED_100: + dev->data->dev_link.link_speed = ETH_SPEED_NUM_100M; + break; + case SPEED_1000: + dev->data->dev_link.link_speed = ETH_SPEED_NUM_1G; + break; + case SPEED_2500: + dev->data->dev_link.link_speed = ETH_SPEED_NUM_2_5G; + break; + default: + dev->data->dev_link.link_speed = ETH_SPEED_NUM_NONE; + } + + dev->data->dev_link.link_duplex = edata.duplex ? ETH_LINK_FULL_DUPLEX : + ETH_LINK_HALF_DUPLEX; + dev->data->dev_link.link_autoneg = edata.autoneg ? ETH_LINK_AUTONEG : + ETH_LINK_FIXED; + + neta_ppio_get_link_state(priv->ppio, &link_up); + dev->data->dev_link.link_status = link_up ? ETH_LINK_UP : ETH_LINK_DOWN; + + return 0; +} + +/** * DPDK callback to set the primary MAC address. * * @param dev @@ -1412,7 +1559,9 @@ static const struct eth_dev_ops mvneta_ops = { .dev_set_link_up = mvneta_dev_set_link_up, .dev_set_link_down = mvneta_dev_set_link_down, .dev_close = mvneta_dev_close, + .link_update = mvneta_link_update, .mac_addr_set = mvneta_mac_addr_set, + .mtu_set = mvneta_mtu_set, .dev_infos_get = mvneta_dev_infos_get, .dev_supported_ptypes_get = mvneta_dev_supported_ptypes_get, .rxq_info_get = mvneta_rxq_info_get, -- 2.7.4