From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 0D0ABA0C41; Wed, 17 Nov 2021 18:51:40 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id DEE4F41168; Wed, 17 Nov 2021 18:51:39 +0100 (CET) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mails.dpdk.org (Postfix) with ESMTP id 06E9D41141 for ; Wed, 17 Nov 2021 18:51:38 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1637171498; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=XDpGun6Bxkp3m7TVPkTk4JCB2vQguBFIXuj/BnpJzd0=; b=TUCzOtW0uq3z29N0VtCg7buJJT4NBgjWxSv5jvvtLDAbnrQvg1FuVMPhydPqjz9MBUPl4L 39pZ+62WzNbSP+KLy2a03NzVVgIe84WHjOYTOwxxxL2/GYVgiZrFMXWcb2/NsE7QaoZVAV 3IZ1VVLwaD7eW3+l8oaYpNlPYXQrxKU= Received: from mail-lf1-f72.google.com (mail-lf1-f72.google.com [209.85.167.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-342--bQM_dVROumVZDdG0LLmNg-1; Wed, 17 Nov 2021 12:51:37 -0500 X-MC-Unique: -bQM_dVROumVZDdG0LLmNg-1 Received: by mail-lf1-f72.google.com with SMTP id w2-20020a0565120b0200b004036bc9597eso2048564lfu.14 for ; Wed, 17 Nov 2021 09:51:37 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=XDpGun6Bxkp3m7TVPkTk4JCB2vQguBFIXuj/BnpJzd0=; b=ZcjEf8Azl1kQn5v18DEEnziTYG++jS7oTIT+KztkHytiFfO4k5cW4szC8ognk4Ym0+ f/wemWEFAgJzVLfz1CvqyiSAAakAdAca6BkJT6HdlkWI1CdEPYvtRdSpk5jR6ABBrDcx yxSf5rPSco0ODtDl7ADmQIbJtqMj+ciTuy5RLAt2qtnCz+1fTlweVwmf1RGaolVBpN3C VUAVf/Fte5kFy5hRQ0m/MwTJmwwn2CyiDcrIkMV/7iDh8CEzvCFVLs8gxAwdxxUVSloD LO8Z6uhzuODZMMSF/KjzelW9JyH5JDgqWrJau+pvQYFdtJg3n+vQimq0HK4tLecbBLKt 4C9w== X-Gm-Message-State: AOAM531cBxt68/j4lwkKugsCiR4ud00phxFBaK8HZkDrau9HsHCpf+PS l5SWNnqK+BOmX0YErXkB4jGn6j7vZvgX6+ox6dulaHt/w6f+ax91ZbMs39wqQ6MTgvuHj1Zo2C3 5AJbtzPB4By6mGXmXKlE= X-Received: by 2002:a2e:760d:: with SMTP id r13mr9281561ljc.159.1637171495777; Wed, 17 Nov 2021 09:51:35 -0800 (PST) X-Google-Smtp-Source: ABdhPJx5S6T7Sh26EAd6OXg4zpqegePDqsMJJ4+9TGJHGVpo36/MYfOhsM937BngkQ4QP3f1lI7nK1n4Ems9GUPMc38= X-Received: by 2002:a2e:760d:: with SMTP id r13mr9281523ljc.159.1637171495513; Wed, 17 Nov 2021 09:51:35 -0800 (PST) MIME-Version: 1.0 References: <1619693609-28244-1-git-send-email-humin29@huawei.com> <1619693609-28244-3-git-send-email-humin29@huawei.com> In-Reply-To: <1619693609-28244-3-git-send-email-humin29@huawei.com> From: David Marchand Date: Wed, 17 Nov 2021 18:51:24 +0100 Message-ID: Subject: Re: [dpdk-dev] [PATCH V1 2/2] examples/ethtool: support the query of MTU To: "Min Hu (Connor)" Cc: dev , "Yigit, Ferruh" Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dmarchan@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org On Thu, Apr 29, 2021 at 12:53 PM Min Hu (Connor) wrote: > > From: Huisong Li > > This patch supports the query of MTU. > > Signed-off-by: Huisong Li > --- > examples/ethtool/ethtool-app/ethapp.c | 48 +++++++++++++++++++++++++---------- > examples/ethtool/lib/rte_ethtool.c | 7 +++++ > examples/ethtool/lib/rte_ethtool.h | 14 ++++++++++ > 3 files changed, 56 insertions(+), 13 deletions(-) > > diff --git a/examples/ethtool/ethtool-app/ethapp.c b/examples/ethtool/ethtool-app/ethapp.c > index fc743ce..aed4bc5 100644 > --- a/examples/ethtool/ethtool-app/ethapp.c > +++ b/examples/ethtool/ethtool-app/ethapp.c > @@ -517,31 +517,41 @@ pcmd_macaddr_callback(void *ptr_params, > static void > pcmd_mtu_callback(void *ptr_params, > __rte_unused struct cmdline *ctx, > - __rte_unused void *ptr_data) > + void *ptr_data) > { > struct pcmd_intstr_params *params = ptr_params; > int stat; > uint16_t new_mtu; > char *ptr_parse_end; > > - new_mtu = strtoul(params->opt, &ptr_parse_end, 10); > - if (*ptr_parse_end != '\0' || > - new_mtu < RTE_ETHER_MIN_MTU || > - new_mtu > RTE_ETHER_MAX_JUMBO_FRAME_LEN) { > - printf("Port %i: Invalid MTU value\n", params->port); > + if (ptr_data == NULL) { > + new_mtu = strtoul(params->opt, &ptr_parse_end, 10); > + if (*ptr_parse_end != '\0' || > + new_mtu < RTE_ETHER_MIN_MTU || > + new_mtu > RTE_ETHER_MAX_JUMBO_FRAME_LEN) { > + printf("Port %i: Invalid MTU value\n", params->port); > + return; > + } > + stat = rte_ethtool_net_change_mtu(params->port, new_mtu); > + if (stat == 0) > + printf("Port %i: MTU set to %i\n", params->port, > + new_mtu); > + else if (stat == -ENOTSUP) > + printf("Port %i: Operation not supported\n", > + params->port); > + else > + printf("Port %i: Error setting MTU\n", params->port); > + > return; > } > - stat = rte_ethtool_net_change_mtu(params->port, new_mtu); > - if (stat == 0) > - printf("Port %i: MTU set to %i\n", params->port, new_mtu); > - else if (stat == -ENOTSUP) > + > + stat = rte_ethtool_net_get_mtu(params->port, &new_mtu); > + if (stat) > printf("Port %i: Operation not supported\n", params->port); > else > - printf("Port %i: Error setting MTU\n", params->port); > + printf("Port %i: Current MTU: %i\n", params->port, new_mtu); > } Please separate as two helpers, there is no code shared between set and get, afaics. > > - > - > static void pcmd_portstats_callback(__rte_unused void *ptr_params, > __rte_unused struct cmdline *ctx, > __rte_unused void *ptr_data) > @@ -799,6 +809,17 @@ cmdline_parse_inst_t pcmd_macaddr = { > NULL > }, > }; > +cmdline_parse_inst_t pcmd_mtu_get = { > + .f = pcmd_mtu_callback, > + .data = (void *)0x01, > + .help_str = "mtu \n" > + " Get MTU", > + .tokens = { > + (void *)&pcmd_mtu_token_cmd, > + (void *)&pcmd_intstr_token_port, > + NULL > + }, > +}; > cmdline_parse_inst_t pcmd_mtu = { > .f = pcmd_mtu_callback, > .data = NULL, > @@ -879,6 +900,7 @@ cmdline_parse_ctx_t list_prompt_commands[] = { > (cmdline_parse_inst_t *)&pcmd_link, > (cmdline_parse_inst_t *)&pcmd_macaddr_get, > (cmdline_parse_inst_t *)&pcmd_macaddr, > + (cmdline_parse_inst_t *)&pcmd_mtu_get, > (cmdline_parse_inst_t *)&pcmd_mtu, > (cmdline_parse_inst_t *)&pcmd_open, > (cmdline_parse_inst_t *)&pcmd_pause_noopt, > diff --git a/examples/ethtool/lib/rte_ethtool.c b/examples/ethtool/lib/rte_ethtool.c > index 73193ed..e69b2c1 100644 > --- a/examples/ethtool/lib/rte_ethtool.c > +++ b/examples/ethtool/lib/rte_ethtool.c > @@ -345,6 +345,13 @@ rte_ethtool_net_validate_addr(uint16_t port_id __rte_unused, > return rte_is_valid_assigned_ether_addr(addr); > } > > +int > +rte_ethtool_net_get_mtu(uint16_t port_id, uint16_t *mtu) > +{ > + RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); > + > + return rte_eth_dev_get_mtu(port_id, mtu); > +} > > int > rte_ethtool_net_change_mtu(uint16_t port_id, uint16_t mtu) > diff --git a/examples/ethtool/lib/rte_ethtool.h b/examples/ethtool/lib/rte_ethtool.h > index fe3250e..434ad1d 100644 > --- a/examples/ethtool/lib/rte_ethtool.h > +++ b/examples/ethtool/lib/rte_ethtool.h > @@ -23,6 +23,7 @@ > * rte_ethtool_net_stop: net_device_ops::ndo_stop > * rte_ethtool_net_set_mac_addr: net_device_ops::ndo_set_mac_address > * rte_ethtool_net_validate_addr: net_device_ops::ndo_validate_addr > + * rte_ethtool_net_get_mtu: net_device_ops::ndo_get_mtu > * rte_ethtool_net_change_mtu: net_device_ops::ndo_change_mtu > * rte_ethtool_net_get_stats64: net_device_ops::ndo_get_stats64 > * rte_ethtool_net_vlan_rx_add_vid net_device_ops::ndo_vlan_rx_add_vid > @@ -296,6 +297,19 @@ int rte_ethtool_net_validate_addr(uint16_t port_id, > struct rte_ether_addr *addr); > > /** > + * Retrieve the MTU of an Ethernet device. > + * > + * @param port_id > + * The port identifier of the Ethernet device. > + * @param mtu > + * A pointer to a uint16_t where the retrieved MTU is to be stored. > + * @return > + * - (0) if successful. > + * - (-ENODEV) if *port_id* invalid. > + */ > +int rte_ethtool_net_get_mtu(uint16_t port_id, uint16_t *mtu); > + > +/** > * Setting the Ethernet device maximum Tx unit. > * > * @param port_id > -- > 2.8.1 > -- David Marchand