From patchwork Thu Jul 21 09:32:52 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuval Shaia X-Patchwork-Id: 9241315 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2F76B60756 for ; Thu, 21 Jul 2016 09:33:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1E58727BFC for ; Thu, 21 Jul 2016 09:33:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 12DC427C0F; Thu, 21 Jul 2016 09:33:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 724C827BFC for ; Thu, 21 Jul 2016 09:33:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751346AbcGUJdG (ORCPT ); Thu, 21 Jul 2016 05:33:06 -0400 Received: from userp1040.oracle.com ([156.151.31.81]:51275 "EHLO userp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751777AbcGUJdF (ORCPT ); Thu, 21 Jul 2016 05:33:05 -0400 Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id u6L9Wv5b006673 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 21 Jul 2016 09:32:58 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserv0021.oracle.com (8.13.8/8.13.8) with ESMTP id u6L9WvfJ020302 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 21 Jul 2016 09:32:57 GMT Received: from abhmp0011.oracle.com (abhmp0011.oracle.com [141.146.116.17]) by aserv0122.oracle.com (8.13.8/8.13.8) with ESMTP id u6L9Wsss032067; Thu, 21 Jul 2016 09:32:56 GMT Received: from yuval-net-srv-ca.us.oracle.com (/10.211.3.71) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 21 Jul 2016 02:32:53 -0700 From: Yuval Shaia To: linux-rdma@vger.kernel.org, dledford@redhat.com, sean.hefty@intel.com, hal.rosenstock@gmail.com Subject: [RFC] IB/mlx4: Add sysfs entry for VF node_guid Date: Thu, 21 Jul 2016 02:32:52 -0700 Message-Id: <1469093572-6793-1-git-send-email-yuval.shaia@oracle.com> X-Mailer: git-send-email 1.7.1 X-Source-IP: aserv0021.oracle.com [141.146.126.233] Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Adding sysfs entries to read/write VF's Node GUID. This abbility will enable sys-admin to configure node GUID for VFs the same way it is done for VF's port GUIDs. Signed-off-by: Yuval Shaia --- drivers/infiniband/hw/mlx4/sysfs.c | 72 ++++++++++++++++++++++++++++++++++++ 1 files changed, 72 insertions(+), 0 deletions(-) diff --git a/drivers/infiniband/hw/mlx4/sysfs.c b/drivers/infiniband/hw/mlx4/sysfs.c index 69fb5ba..6fc4366 100644 --- a/drivers/infiniband/hw/mlx4/sysfs.c +++ b/drivers/infiniband/hw/mlx4/sysfs.c @@ -371,6 +371,7 @@ struct mlx4_port { struct attribute_group gid_group; struct device_attribute enable_smi_admin; struct device_attribute smi_enabled; + struct device_attribute node_guid; int slave; u8 port_num; }; @@ -620,6 +621,7 @@ static int add_vf_smi_entries(struct mlx4_port *p) sysfs_remove_file(&p->kobj, &p->smi_enabled.attr); return ret; } + return 0; } @@ -635,6 +637,69 @@ static void remove_vf_smi_entries(struct mlx4_port *p) sysfs_remove_file(&p->kobj, &p->enable_smi_admin.attr); } +static ssize_t sysfs_show_node_guid(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct mlx4_port *p = container_of(attr, struct mlx4_port, node_guid); + ssize_t len = 0; + __be64 guid = mlx4_get_slave_node_guid(p->dev->dev, p->slave); + + len = sprintf(buf, "slave %d 0x%llx\n", p->slave, be64_to_cpu(guid)); + + return len; +} + +static ssize_t sysfs_store_node_guid(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct mlx4_port *p = container_of(attr, struct mlx4_port, node_guid); + __be64 guid; + + if (sscanf(buf, "0x%llx", &guid) != 1) + return -EINVAL; + + mlx4_put_slave_node_guid(p->dev->dev, p->slave, cpu_to_be64(guid)); + + return count; +} + +static int add_vf_admin_guid_entry(struct mlx4_port *p) +{ + int is_eth = rdma_port_get_link_layer(&p->dev->ib_dev, p->port_num) == + IB_LINK_LAYER_ETHERNET; + int ret; + + /* do not display entries if eth transport, or if master */ + if (is_eth || p->slave == mlx4_master_func_num(p->dev->dev)) + return 0; + + sysfs_attr_init(&p->node_guid.attr); + p->node_guid.show = sysfs_show_node_guid; + p->node_guid.store = sysfs_store_node_guid; + p->node_guid.attr.name = "node_guid"; + p->node_guid.attr.mode = 0644; + ret = sysfs_create_file(&p->kobj, &p->node_guid.attr); + if (ret) { + pr_err("failed to create sysfs entry for node_guid\n"); + return ret; + } + + return 0; +} + +static void remove_vf_node_guid_entry(struct mlx4_port *p) +{ + int is_eth = rdma_port_get_link_layer(&p->dev->ib_dev, p->port_num) == + IB_LINK_LAYER_ETHERNET; + + if (is_eth || p->slave == mlx4_master_func_num(p->dev->dev)) + return; + + sysfs_remove_file(&p->kobj, &p->node_guid.attr); +} + static int add_port(struct mlx4_ib_dev *dev, int port_num, int slave) { struct mlx4_port *p; @@ -686,6 +751,10 @@ static int add_port(struct mlx4_ib_dev *dev, int port_num, int slave) if (ret) goto err_free_gid; + ret = add_vf_admin_guid_entry(p); + if (ret) + goto err_free_gid; + list_add_tail(&p->kobj.entry, &dev->pkeys.pkey_port_list[slave]); return 0; @@ -743,6 +812,7 @@ static int register_one_pkey_tree(struct mlx4_ib_dev *dev, int slave) if (err) goto err_add; } + return 0; err_add: @@ -754,6 +824,7 @@ err_add: sysfs_remove_group(p, &mport->pkey_group); sysfs_remove_group(p, &mport->gid_group); remove_vf_smi_entries(mport); + remove_vf_node_guid_entry(mport); kobject_put(p); } kobject_put(dev->dev_ports_parent[slave]); @@ -799,6 +870,7 @@ static void unregister_pkey_tree(struct mlx4_ib_dev *device) sysfs_remove_group(p, &port->pkey_group); sysfs_remove_group(p, &port->gid_group); remove_vf_smi_entries(port); + remove_vf_node_guid_entry(port); kobject_put(p); kobject_put(device->dev_ports_parent[slave]); }