From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5AA63C43381 for ; Tue, 26 Mar 2019 20:36:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 23EBD20823 for ; Tue, 26 Mar 2019 20:36:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=netronome-com.20150623.gappssmtp.com header.i=@netronome-com.20150623.gappssmtp.com header.b="ddA+O7uR" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732727AbfCZUgF (ORCPT ); Tue, 26 Mar 2019 16:36:05 -0400 Received: from mail-qt1-f196.google.com ([209.85.160.196]:46411 "EHLO mail-qt1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726207AbfCZUgF (ORCPT ); Tue, 26 Mar 2019 16:36:05 -0400 Received: by mail-qt1-f196.google.com with SMTP id z17so16246163qts.13 for ; Tue, 26 Mar 2019 13:36:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=netronome-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:in-reply-to:references :organization:mime-version:content-transfer-encoding; bh=IqqE6H9V6hknWJnViu+KQqYDd+D5l6jPegDlfoz8+Fo=; b=ddA+O7uRFVX1K854igEKivDLtkOvQKvSwlhrEWFtLO54z+3w9Y/pEs4xCkT1PwQoss Re0y93fhFiUI/1IsGE8ZgDmD9/mMKj7M7a960PvfjBPvChnzjRWv/K5tLG/kfx/GbKlo C6KswKINxTAKKG9EFsnQVymN5cY3wJIs4lesQdyVO4HH1e+PU0geeWiNiT/0eXZegqT5 646SPxpnPlycKSpOrrd0WDZZlQZlKGA7Z9pOSZiDm16l2iI6Bx7BVacTMnsDUP2f8/DM 2/sDvkO3EgRQJ8RbzKK3ZHs27derNX4f2h+U+R3yS5phw0HD5oIuyXnVdmc9CKxJbNhd 5u+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to :references:organization:mime-version:content-transfer-encoding; bh=IqqE6H9V6hknWJnViu+KQqYDd+D5l6jPegDlfoz8+Fo=; b=EaQSAiziPlyAOJV1Ex935zQHKp3+YzTtp+QwJRs3vOQ1QRH66otn5uIrNHUquWMouV S6Fd35Zp5H/rqoCE3CMW7qCV1zcdwC/j/7VGaoRLmDKtaEIoxw2fXxSC7qmojft4ydD/ xvXztJcbAnrDg753GLcShSDIX8/8+odXEWtntdHMAGHTpvzorIpb1QQtMmLgNCiyLfBY lH6+2WE0FsuNha2fT5tEidtPVunDnyamiyIrtGaBk+pBgJnl4K6Kl4RP7QhlrAosFvjJ YYZkwJhxuykCOCYrG/C2ZpSTc/y/nSfFLAPkneGG805BRF2629Wmo+RGhIGqK0qkh7fT /e1w== X-Gm-Message-State: APjAAAXRpW2Gw61vDOn//tf5635Cp6GYZS92tuwd+I4JJHhPDTuEeHYM QYCzq8X7FViR6crpvv5C37ufbNoel4Y= X-Google-Smtp-Source: APXvYqxVtRHxDvB8OiJfI0RBp44Lz9yNhVmyMghrfmCSilbL80JbGgpVwyp5NKm5rScHT5Vpjn8V7g== X-Received: by 2002:a0c:b581:: with SMTP id g1mr11351078qve.97.1553632564138; Tue, 26 Mar 2019 13:36:04 -0700 (PDT) Received: from cakuba.netronome.com ([66.60.152.14]) by smtp.gmail.com with ESMTPSA id i11sm9391891qkg.33.2019.03.26.13.36.02 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 26 Mar 2019 13:36:04 -0700 (PDT) Date: Tue, 26 Mar 2019 13:35:58 -0700 From: Jakub Kicinski To: Jiri Pirko Cc: netdev@vger.kernel.org, davem@davemloft.net, mlxsw@mellanox.com, idosch@mellanox.com, f.fainelli@gmail.com, andrew@lunn.ch, vivien.didelot@gmail.com, michael.chan@broadcom.com Subject: Re: [patch net-next v2 11/12] net: devlink: expose phys port name Message-ID: <20190326133558.40d5ff0e@cakuba.netronome.com> In-Reply-To: <20190326120307.2953-12-jiri@resnulli.us> References: <20190326120307.2953-1-jiri@resnulli.us> <20190326120307.2953-12-jiri@resnulli.us> Organization: Netronome Systems, Ltd. MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On Tue, 26 Mar 2019 13:03:06 +0100, Jiri Pirko wrote: > From: Jiri Pirko > > Currently, it is exposed via rtnetlink. But it is relevant to devlink > ports, so expose it here too. > > Signed-off-by: Jiri Pirko Why? User space has access to all the components which are used to generate the name in a typed, structured form. That's strictly superior to the string netdev string. Do you have some use in mind for the new attribute? > diff --git a/include/uapi/linux/devlink.h b/include/uapi/linux/devlink.h > index 5bb4ea67d84f..2d0365e45141 100644 > --- a/include/uapi/linux/devlink.h > +++ b/include/uapi/linux/devlink.h > @@ -332,6 +332,8 @@ enum devlink_attr { > DEVLINK_ATTR_FLASH_UPDATE_FILE_NAME, /* string */ > DEVLINK_ATTR_FLASH_UPDATE_COMPONENT, /* string */ > > + DEVLINK_ATTR_PORT_PHYS_NAME, /* string */ > + > /* add new attributes above here, update the policy in devlink.c */ > > __DEVLINK_ATTR_MAX, > diff --git a/net/core/devlink.c b/net/core/devlink.c > index 6bbd07e3861e..356d7ee7c404 100644 > --- a/net/core/devlink.c > +++ b/net/core/devlink.c > @@ -508,6 +508,57 @@ static void devlink_notify(struct devlink *devlink, enum devlink_command cmd) > msg, 0, DEVLINK_MCGRP_CONFIG, GFP_KERNEL); > } > > +static int __devlink_port_phys_port_name_get(struct devlink_port *devlink_port, > + char *name, size_t len) > +{ > + struct devlink_port_attrs *attrs = &devlink_port->attrs; > + int n = 0; > + > + if (!attrs->set) > + return -EOPNOTSUPP; > + > + switch (attrs->flavour) { > + case DEVLINK_PORT_FLAVOUR_PHYSICAL: > + if (!attrs->split) > + n = snprintf(name, len, "p%u", attrs->port_number); > + else > + n = snprintf(name, len, "p%us%u", attrs->port_number, > + attrs->split_subport_number); > + break; > + case DEVLINK_PORT_FLAVOUR_CPU: > + case DEVLINK_PORT_FLAVOUR_DSA: > + /* As CPU and DSA ports do not have a netdevice associated > + * case should not ever happen. > + */ > + WARN_ON(1); > + return -EINVAL; > + } > + > + if (n >= len) > + return -EINVAL; > + > + return 0; > +} > + > +static int devlink_nl_port_phys_port_name_put(struct sk_buff *msg, > + struct devlink_port *devlink_port) > +{ > + struct devlink_port_attrs *attrs = &devlink_port->attrs; > + char phys_name[IFNAMSIZ]; > + int err; > + > + if (attrs->flavour != DEVLINK_PORT_FLAVOUR_PHYSICAL) > + return 0; > + > + err = __devlink_port_phys_port_name_get(devlink_port, > + phys_name, sizeof(phys_name)); > + if (err) > + return err; > + if (nla_put_string(msg, DEVLINK_ATTR_PORT_PHYS_NAME, phys_name)) > + return -EMSGSIZE; > + return 0; > +} > + > static int devlink_nl_port_attrs_put(struct sk_buff *msg, > struct devlink_port *devlink_port) > { > @@ -526,6 +577,9 @@ static int devlink_nl_port_attrs_put(struct sk_buff *msg, > if (nla_put_u32(msg, DEVLINK_ATTR_PORT_SPLIT_SUBPORT_NUMBER, > attrs->split_subport_number)) > return -EMSGSIZE; > + if (devlink_nl_port_phys_port_name_put(msg, devlink_port)) > + return -EMSGSIZE; > + > return 0; > } > > @@ -5414,38 +5468,6 @@ void devlink_port_attrs_set(struct devlink_port *devlink_port, > } > EXPORT_SYMBOL_GPL(devlink_port_attrs_set); > > -static int __devlink_port_phys_port_name_get(struct devlink_port *devlink_port, > - char *name, size_t len) > -{ > - struct devlink_port_attrs *attrs = &devlink_port->attrs; > - int n = 0; > - > - if (!attrs->set) > - return -EOPNOTSUPP; > - > - switch (attrs->flavour) { > - case DEVLINK_PORT_FLAVOUR_PHYSICAL: > - if (!attrs->split) > - n = snprintf(name, len, "p%u", attrs->port_number); > - else > - n = snprintf(name, len, "p%us%u", attrs->port_number, > - attrs->split_subport_number); > - break; > - case DEVLINK_PORT_FLAVOUR_CPU: > - case DEVLINK_PORT_FLAVOUR_DSA: > - /* As CPU and DSA ports do not have a netdevice associated > - * case should not ever happen. > - */ > - WARN_ON(1); > - return -EINVAL; > - } > - > - if (n >= len) > - return -EINVAL; > - > - return 0; > -} > - > int devlink_sb_register(struct devlink *devlink, unsigned int sb_index, > u32 size, u16 ingress_pools_count, > u16 egress_pools_count, u16 ingress_tc_count,