From patchwork Fri Nov 28 13:34:19 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 415877 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 47EB9140119 for ; Sat, 29 Nov 2014 00:36:30 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751789AbaK1NgO (ORCPT ); Fri, 28 Nov 2014 08:36:14 -0500 Received: from mail-wi0-f169.google.com ([209.85.212.169]:53648 "EHLO mail-wi0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751552AbaK1Nen (ORCPT ); Fri, 28 Nov 2014 08:34:43 -0500 Received: by mail-wi0-f169.google.com with SMTP id r20so21166228wiv.0 for ; Fri, 28 Nov 2014 05:34:42 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=vqAeNtMqTSp8bZTnC4KfV/GBG0xBb/kssHeLlovadnc=; b=imJGFmn/dhbKYKEA1EMPWc/czRtlkWRHxTRL++4uaiWOLAbCJW9WEmx6GyvCOUJREi tIdh9HMvVpbqlr2AthxfyGHnlyU/Zhhxpmvus04JG06hVyLl98zkDDoCrJzTdPNAxdzQ RxXsZ93PwABqSaz8y2Us3W80vn1bucOYVQOM3QHyfrMyy3SFK/617uJ0jsBlCUXXhzeq 4Td7rqftqpfZYmfBMG5kS6zWUQhgxn+UXvT5S4pVCj1DPJzgSx0jgwTjGm29pT96w7FA rR5yUzmMbexIv1rlr5JRRFxHgUdrjhYE81Px52TLuhugMzWeJ4G3juUXYqxNUjgGM0+y r2Vw== X-Gm-Message-State: ALoCoQkeL99pxSR09IC9yH8aD2+AQf/i5RYxrJmqKb/ebzTQCJsqe7OEVfYtCw71zBh0EuHZSpaR X-Received: by 10.180.77.170 with SMTP id t10mr62081130wiw.57.1417181682591; Fri, 28 Nov 2014 05:34:42 -0800 (PST) Received: from localhost (ip-94-113-123-0.net.upcbroadband.cz. [94.113.123.0]) by mx.google.com with ESMTPSA id ce1sm15068462wjc.2.2014.11.28.05.34.42 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 28 Nov 2014 05:34:42 -0800 (PST) From: Jiri Pirko To: netdev@vger.kernel.org Cc: davem@davemloft.net, nhorman@tuxdriver.com, andy@greyhouse.net, tgraf@suug.ch, dborkman@redhat.com, ogerlitz@mellanox.com, jesse@nicira.com, pshelar@nicira.com, azhou@nicira.com, ben@decadent.org.uk, stephen@networkplumber.org, jeffrey.t.kirsher@intel.com, vyasevic@redhat.com, xiyou.wangcong@gmail.com, john.r.fastabend@intel.com, edumazet@google.com, jhs@mojatatu.com, sfeldma@gmail.com, f.fainelli@gmail.com, roopa@cumulusnetworks.com, linville@tuxdriver.com, jasowang@redhat.com, ebiederm@xmission.com, nicolas.dichtel@6wind.com, ryazanov.s.a@gmail.com, buytenh@wantstofly.org, aviadr@mellanox.com, nbd@openwrt.org, alexei.starovoitov@gmail.com, Neil.Jerram@metaswitch.com, ronye@mellanox.com, simon.horman@netronome.com, alexander.h.duyck@redhat.com, john.ronciak@intel.com, mleitner@redhat.com, shrijeet@gmail.com, gospo@cumulusnetworks.com, bcrl@kvack.org, hemal@broadcom.com Subject: [patch net-next v5 08/21] net-sysfs: expose physical switch id for particular device Date: Fri, 28 Nov 2014 14:34:19 +0100 Message-Id: <1417181672-11531-9-git-send-email-jiri@resnulli.us> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1417181672-11531-1-git-send-email-jiri@resnulli.us> References: <1417181672-11531-1-git-send-email-jiri@resnulli.us> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Signed-off-by: Jiri Pirko Reviewed-by: Thomas Graf Acked-by: John Fastabend Acked-by: Andy Gospodarek Acked-by: Florian Fainelli --- v4->v5: -no change v3->v4: -added entry to Documentation/ABI/testing/sysfs-class-net as suggested by Florian v2->v3: -changed "sw" string to "switch" to avoid confusion v1->v2: -no change --- Documentation/ABI/testing/sysfs-class-net | 8 ++++++++ net/core/net-sysfs.c | 24 ++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-class-net b/Documentation/ABI/testing/sysfs-class-net index e1b2e78..beb8ec4 100644 --- a/Documentation/ABI/testing/sysfs-class-net +++ b/Documentation/ABI/testing/sysfs-class-net @@ -216,3 +216,11 @@ Contact: netdev@vger.kernel.org Description: Indicates the interface protocol type as a decimal value. See include/uapi/linux/if_arp.h for all possible values. + +What: /sys/class/net//phys_switch_id +Date: November 2014 +KernelVersion: 3.19 +Contact: netdev@vger.kernel.org +Description: + Indicates the unique physical switch identifier of a switch this + port belongs to, as a string. diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c index 26c46f4..9993412 100644 --- a/net/core/net-sysfs.c +++ b/net/core/net-sysfs.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -416,6 +417,28 @@ static ssize_t phys_port_id_show(struct device *dev, } static DEVICE_ATTR_RO(phys_port_id); +static ssize_t phys_switch_id_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct net_device *netdev = to_net_dev(dev); + ssize_t ret = -EINVAL; + + if (!rtnl_trylock()) + return restart_syscall(); + + if (dev_isalive(netdev)) { + struct netdev_phys_item_id ppid; + + ret = netdev_switch_parent_id_get(netdev, &ppid); + if (!ret) + ret = sprintf(buf, "%*phN\n", ppid.id_len, ppid.id); + } + rtnl_unlock(); + + return ret; +} +static DEVICE_ATTR_RO(phys_switch_id); + static struct attribute *net_class_attrs[] = { &dev_attr_netdev_group.attr, &dev_attr_type.attr, @@ -441,6 +464,7 @@ static struct attribute *net_class_attrs[] = { &dev_attr_tx_queue_len.attr, &dev_attr_gro_flush_timeout.attr, &dev_attr_phys_port_id.attr, + &dev_attr_phys_switch_id.attr, NULL, }; ATTRIBUTE_GROUPS(net_class);