2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.
|
2005-08-11 14:03:10 +08:00
|
|
|
* Copyright (c) 2005 Mellanox Technologies Ltd. All rights reserved.
|
|
|
|
* Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
|
|
|
* This software is available to you under a choice of one of two
|
|
|
|
* licenses. You may choose to be licensed under the terms of the GNU
|
|
|
|
* General Public License (GPL) Version 2, available from the file
|
|
|
|
* COPYING in the main directory of this source tree, or the
|
|
|
|
* OpenIB.org BSD license below:
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or
|
|
|
|
* without modification, are permitted provided that the following
|
|
|
|
* conditions are met:
|
|
|
|
*
|
|
|
|
* - Redistributions of source code must retain the above
|
|
|
|
* copyright notice, this list of conditions and the following
|
|
|
|
* disclaimer.
|
|
|
|
*
|
|
|
|
* - Redistributions in binary form must reproduce the above
|
|
|
|
* copyright notice, this list of conditions and the following
|
|
|
|
* disclaimer in the documentation and/or other materials
|
|
|
|
* provided with the distribution.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
|
|
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
* SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "core_priv.h"
|
|
|
|
|
2005-11-07 16:59:43 +08:00
|
|
|
#include <linux/slab.h>
|
2011-05-28 01:27:45 +08:00
|
|
|
#include <linux/stat.h>
|
2005-11-07 16:59:43 +08:00
|
|
|
#include <linux/string.h>
|
2015-12-23 20:56:49 +08:00
|
|
|
#include <linux/netdevice.h>
|
2016-06-15 14:22:07 +08:00
|
|
|
#include <linux/ethtool.h>
|
2005-11-07 16:59:43 +08:00
|
|
|
|
2005-08-26 04:40:04 +08:00
|
|
|
#include <rdma/ib_mad.h>
|
2015-12-21 22:20:28 +08:00
|
|
|
#include <rdma/ib_pma.h>
|
2018-06-05 13:40:18 +08:00
|
|
|
#include <rdma/ib_cache.h>
|
2019-07-02 18:02:42 +08:00
|
|
|
#include <rdma/rdma_counter.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2015-12-23 20:56:49 +08:00
|
|
|
struct ib_port;
|
|
|
|
|
|
|
|
struct gid_attr_group {
|
|
|
|
struct ib_port *port;
|
|
|
|
struct kobject kobj;
|
|
|
|
struct attribute_group ndev;
|
|
|
|
struct attribute_group type;
|
|
|
|
};
|
2005-04-17 06:20:36 +08:00
|
|
|
struct ib_port {
|
|
|
|
struct kobject kobj;
|
|
|
|
struct ib_device *ibdev;
|
2015-12-23 20:56:49 +08:00
|
|
|
struct gid_attr_group *gid_attr_group;
|
2005-04-17 06:20:36 +08:00
|
|
|
struct attribute_group gid_group;
|
2020-07-15 02:34:08 +08:00
|
|
|
struct attribute_group *pkey_group;
|
2020-10-01 06:40:03 +08:00
|
|
|
const struct attribute_group *pma_table;
|
IB/core: Make device counter infrastructure dynamic
In practice, each RDMA device has a unique set of counters that the
hardware implements. Having a central set of counters that they must
all adhere to is limiting and causes many useful counters to not be
available.
Therefore we create a dynamic counter registration infrastructure.
The driver must implement a stats structure allocation routine, in
which the driver must place the directory name it wants, a list of
names for all of the counters, an array of u64 counters themselves,
plus a few generic configuration options.
We then implement a core routine to create a sysfs file for each
of the named stats elements, and a core routine to retrieve the
stats when any of the sysfs attribute files are read.
To avoid excessive beating on the stats generation routine in the
drivers, the core code also caches the stats for a short period of
time so that someone attempting to read all of the stats in a
given device's directory will not result in a stats generation
call per file read.
Future work will attempt to standardize just the shared stats
elements, and possibly add a method to get the stats via netlink
in addition to sysfs.
Signed-off-by: Christoph Lameter <cl@linux.com>
Signed-off-by: Mark Bloch <markb@mellanox.com>
Reviewed-by: Steve Wise <swise@opengridcomputing.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
[ Add caching, make structure names more informative, add i40iw support,
other significant rewrites from the original patch ]
2016-05-17 01:49:33 +08:00
|
|
|
struct attribute_group *hw_stats_ag;
|
|
|
|
struct rdma_hw_stats *hw_stats;
|
|
|
|
u8 port_num;
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct port_attribute {
|
|
|
|
struct attribute attr;
|
|
|
|
ssize_t (*show)(struct ib_port *, struct port_attribute *, char *buf);
|
|
|
|
ssize_t (*store)(struct ib_port *, struct port_attribute *,
|
|
|
|
const char *buf, size_t count);
|
|
|
|
};
|
|
|
|
|
|
|
|
#define PORT_ATTR(_name, _mode, _show, _store) \
|
|
|
|
struct port_attribute port_attr_##_name = __ATTR(_name, _mode, _show, _store)
|
|
|
|
|
|
|
|
#define PORT_ATTR_RO(_name) \
|
|
|
|
struct port_attribute port_attr_##_name = __ATTR_RO(_name)
|
|
|
|
|
|
|
|
struct port_table_attribute {
|
2005-04-29 13:58:46 +08:00
|
|
|
struct port_attribute attr;
|
|
|
|
char name[8];
|
|
|
|
int index;
|
2016-01-04 11:44:25 +08:00
|
|
|
__be16 attr_id;
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
IB/core: Make device counter infrastructure dynamic
In practice, each RDMA device has a unique set of counters that the
hardware implements. Having a central set of counters that they must
all adhere to is limiting and causes many useful counters to not be
available.
Therefore we create a dynamic counter registration infrastructure.
The driver must implement a stats structure allocation routine, in
which the driver must place the directory name it wants, a list of
names for all of the counters, an array of u64 counters themselves,
plus a few generic configuration options.
We then implement a core routine to create a sysfs file for each
of the named stats elements, and a core routine to retrieve the
stats when any of the sysfs attribute files are read.
To avoid excessive beating on the stats generation routine in the
drivers, the core code also caches the stats for a short period of
time so that someone attempting to read all of the stats in a
given device's directory will not result in a stats generation
call per file read.
Future work will attempt to standardize just the shared stats
elements, and possibly add a method to get the stats via netlink
in addition to sysfs.
Signed-off-by: Christoph Lameter <cl@linux.com>
Signed-off-by: Mark Bloch <markb@mellanox.com>
Reviewed-by: Steve Wise <swise@opengridcomputing.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
[ Add caching, make structure names more informative, add i40iw support,
other significant rewrites from the original patch ]
2016-05-17 01:49:33 +08:00
|
|
|
struct hw_stats_attribute {
|
|
|
|
struct attribute attr;
|
|
|
|
ssize_t (*show)(struct kobject *kobj,
|
|
|
|
struct attribute *attr, char *buf);
|
|
|
|
ssize_t (*store)(struct kobject *kobj,
|
|
|
|
struct attribute *attr,
|
|
|
|
const char *buf,
|
|
|
|
size_t count);
|
|
|
|
int index;
|
|
|
|
u8 port_num;
|
|
|
|
};
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
static ssize_t port_attr_show(struct kobject *kobj,
|
|
|
|
struct attribute *attr, char *buf)
|
|
|
|
{
|
|
|
|
struct port_attribute *port_attr =
|
|
|
|
container_of(attr, struct port_attribute, attr);
|
|
|
|
struct ib_port *p = container_of(kobj, struct ib_port, kobj);
|
|
|
|
|
|
|
|
if (!port_attr->show)
|
2005-04-29 14:27:34 +08:00
|
|
|
return -EIO;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
return port_attr->show(p, port_attr, buf);
|
|
|
|
}
|
|
|
|
|
2017-10-16 13:45:14 +08:00
|
|
|
static ssize_t port_attr_store(struct kobject *kobj,
|
|
|
|
struct attribute *attr,
|
|
|
|
const char *buf, size_t count)
|
|
|
|
{
|
|
|
|
struct port_attribute *port_attr =
|
|
|
|
container_of(attr, struct port_attribute, attr);
|
|
|
|
struct ib_port *p = container_of(kobj, struct ib_port, kobj);
|
|
|
|
|
|
|
|
if (!port_attr->store)
|
|
|
|
return -EIO;
|
|
|
|
return port_attr->store(p, port_attr, buf, count);
|
|
|
|
}
|
|
|
|
|
2010-01-19 09:58:23 +08:00
|
|
|
static const struct sysfs_ops port_sysfs_ops = {
|
2017-10-16 13:45:14 +08:00
|
|
|
.show = port_attr_show,
|
|
|
|
.store = port_attr_store
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
2015-12-23 20:56:49 +08:00
|
|
|
static ssize_t gid_attr_show(struct kobject *kobj,
|
|
|
|
struct attribute *attr, char *buf)
|
|
|
|
{
|
|
|
|
struct port_attribute *port_attr =
|
|
|
|
container_of(attr, struct port_attribute, attr);
|
|
|
|
struct ib_port *p = container_of(kobj, struct gid_attr_group,
|
|
|
|
kobj)->port;
|
|
|
|
|
|
|
|
if (!port_attr->show)
|
|
|
|
return -EIO;
|
|
|
|
|
|
|
|
return port_attr->show(p, port_attr, buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct sysfs_ops gid_attr_sysfs_ops = {
|
|
|
|
.show = gid_attr_show
|
|
|
|
};
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
static ssize_t state_show(struct ib_port *p, struct port_attribute *unused,
|
|
|
|
char *buf)
|
|
|
|
{
|
|
|
|
struct ib_port_attr attr;
|
|
|
|
ssize_t ret;
|
|
|
|
|
|
|
|
static const char *state_name[] = {
|
|
|
|
[IB_PORT_NOP] = "NOP",
|
|
|
|
[IB_PORT_DOWN] = "DOWN",
|
|
|
|
[IB_PORT_INIT] = "INIT",
|
|
|
|
[IB_PORT_ARMED] = "ARMED",
|
|
|
|
[IB_PORT_ACTIVE] = "ACTIVE",
|
|
|
|
[IB_PORT_ACTIVE_DEFER] = "ACTIVE_DEFER"
|
|
|
|
};
|
|
|
|
|
|
|
|
ret = ib_query_port(p->ibdev, p->port_num, &attr);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2020-10-08 10:36:27 +08:00
|
|
|
return sysfs_emit(buf, "%d: %s\n", attr.state,
|
|
|
|
attr.state >= 0 &&
|
|
|
|
attr.state < ARRAY_SIZE(state_name) ?
|
|
|
|
state_name[attr.state] :
|
|
|
|
"UNKNOWN");
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t lid_show(struct ib_port *p, struct port_attribute *unused,
|
|
|
|
char *buf)
|
|
|
|
{
|
|
|
|
struct ib_port_attr attr;
|
|
|
|
ssize_t ret;
|
|
|
|
|
|
|
|
ret = ib_query_port(p->ibdev, p->port_num, &attr);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2020-10-08 10:36:27 +08:00
|
|
|
return sysfs_emit(buf, "0x%x\n", attr.lid);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t lid_mask_count_show(struct ib_port *p,
|
|
|
|
struct port_attribute *unused,
|
|
|
|
char *buf)
|
|
|
|
{
|
|
|
|
struct ib_port_attr attr;
|
|
|
|
ssize_t ret;
|
|
|
|
|
|
|
|
ret = ib_query_port(p->ibdev, p->port_num, &attr);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2020-10-08 10:36:27 +08:00
|
|
|
return sysfs_emit(buf, "%d\n", attr.lmc);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t sm_lid_show(struct ib_port *p, struct port_attribute *unused,
|
|
|
|
char *buf)
|
|
|
|
{
|
|
|
|
struct ib_port_attr attr;
|
|
|
|
ssize_t ret;
|
|
|
|
|
|
|
|
ret = ib_query_port(p->ibdev, p->port_num, &attr);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2020-10-08 10:36:27 +08:00
|
|
|
return sysfs_emit(buf, "0x%x\n", attr.sm_lid);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t sm_sl_show(struct ib_port *p, struct port_attribute *unused,
|
|
|
|
char *buf)
|
|
|
|
{
|
|
|
|
struct ib_port_attr attr;
|
|
|
|
ssize_t ret;
|
|
|
|
|
|
|
|
ret = ib_query_port(p->ibdev, p->port_num, &attr);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2020-10-08 10:36:27 +08:00
|
|
|
return sysfs_emit(buf, "%d\n", attr.sm_sl);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t cap_mask_show(struct ib_port *p, struct port_attribute *unused,
|
|
|
|
char *buf)
|
|
|
|
{
|
|
|
|
struct ib_port_attr attr;
|
|
|
|
ssize_t ret;
|
|
|
|
|
|
|
|
ret = ib_query_port(p->ibdev, p->port_num, &attr);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2020-10-08 10:36:27 +08:00
|
|
|
return sysfs_emit(buf, "0x%08x\n", attr.port_cap_flags);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t rate_show(struct ib_port *p, struct port_attribute *unused,
|
|
|
|
char *buf)
|
|
|
|
{
|
|
|
|
struct ib_port_attr attr;
|
|
|
|
char *speed = "";
|
2012-04-03 01:57:31 +08:00
|
|
|
int rate; /* in deci-Gb/sec */
|
2005-04-17 06:20:36 +08:00
|
|
|
ssize_t ret;
|
|
|
|
|
|
|
|
ret = ib_query_port(p->ibdev, p->port_num, &attr);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
switch (attr.active_speed) {
|
2012-02-29 00:49:50 +08:00
|
|
|
case IB_SPEED_DDR:
|
2011-10-05 19:21:47 +08:00
|
|
|
speed = " DDR";
|
2012-02-28 01:15:08 +08:00
|
|
|
rate = 50;
|
2011-10-05 19:21:47 +08:00
|
|
|
break;
|
2012-02-29 00:49:50 +08:00
|
|
|
case IB_SPEED_QDR:
|
2011-10-05 19:21:47 +08:00
|
|
|
speed = " QDR";
|
2012-02-28 01:15:08 +08:00
|
|
|
rate = 100;
|
2011-10-05 19:21:47 +08:00
|
|
|
break;
|
2012-02-29 00:49:50 +08:00
|
|
|
case IB_SPEED_FDR10:
|
2011-10-05 19:21:47 +08:00
|
|
|
speed = " FDR10";
|
2012-02-28 01:15:08 +08:00
|
|
|
rate = 100;
|
2011-10-05 19:21:47 +08:00
|
|
|
break;
|
2012-02-29 00:49:50 +08:00
|
|
|
case IB_SPEED_FDR:
|
2011-10-05 19:21:47 +08:00
|
|
|
speed = " FDR";
|
2012-02-28 01:15:08 +08:00
|
|
|
rate = 140;
|
2011-10-05 19:21:47 +08:00
|
|
|
break;
|
2012-02-29 00:49:50 +08:00
|
|
|
case IB_SPEED_EDR:
|
2011-10-05 19:21:47 +08:00
|
|
|
speed = " EDR";
|
2012-02-28 01:15:08 +08:00
|
|
|
rate = 250;
|
2011-10-05 19:21:47 +08:00
|
|
|
break;
|
2017-04-21 01:53:31 +08:00
|
|
|
case IB_SPEED_HDR:
|
|
|
|
speed = " HDR";
|
|
|
|
rate = 500;
|
|
|
|
break;
|
2020-10-26 21:37:37 +08:00
|
|
|
case IB_SPEED_NDR:
|
|
|
|
speed = " NDR";
|
|
|
|
rate = 1000;
|
|
|
|
break;
|
2012-04-03 01:57:31 +08:00
|
|
|
case IB_SPEED_SDR:
|
|
|
|
default: /* default to SDR for invalid rates */
|
2018-03-15 17:02:13 +08:00
|
|
|
speed = " SDR";
|
2012-04-03 01:57:31 +08:00
|
|
|
rate = 25;
|
|
|
|
break;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2011-10-05 19:21:47 +08:00
|
|
|
rate *= ib_width_enum_to_int(attr.active_width);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (rate < 0)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2020-10-08 10:36:27 +08:00
|
|
|
return sysfs_emit(buf, "%d%s Gb/sec (%dX%s)\n", rate / 10,
|
|
|
|
rate % 10 ? ".5" : "",
|
|
|
|
ib_width_enum_to_int(attr.active_width), speed);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2019-08-07 18:31:35 +08:00
|
|
|
static const char *phys_state_to_str(enum ib_port_phys_state phys_state)
|
|
|
|
{
|
|
|
|
static const char * phys_state_str[] = {
|
|
|
|
"<unknown>",
|
|
|
|
"Sleep",
|
|
|
|
"Polling",
|
|
|
|
"Disabled",
|
|
|
|
"PortConfigurationTraining",
|
|
|
|
"LinkUp",
|
|
|
|
"LinkErrorRecovery",
|
|
|
|
"Phy Test",
|
|
|
|
};
|
|
|
|
|
|
|
|
if (phys_state < ARRAY_SIZE(phys_state_str))
|
|
|
|
return phys_state_str[phys_state];
|
|
|
|
return "<unknown>";
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
static ssize_t phys_state_show(struct ib_port *p, struct port_attribute *unused,
|
|
|
|
char *buf)
|
|
|
|
{
|
|
|
|
struct ib_port_attr attr;
|
|
|
|
|
|
|
|
ssize_t ret;
|
|
|
|
|
|
|
|
ret = ib_query_port(p->ibdev, p->port_num, &attr);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2020-10-08 10:36:27 +08:00
|
|
|
return sysfs_emit(buf, "%d: %s\n", attr.phys_state,
|
|
|
|
phys_state_to_str(attr.phys_state));
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2010-10-22 20:32:05 +08:00
|
|
|
static ssize_t link_layer_show(struct ib_port *p, struct port_attribute *unused,
|
|
|
|
char *buf)
|
|
|
|
{
|
2020-10-08 10:36:27 +08:00
|
|
|
const char *output;
|
|
|
|
|
2010-10-22 20:32:05 +08:00
|
|
|
switch (rdma_port_get_link_layer(p->ibdev, p->port_num)) {
|
|
|
|
case IB_LINK_LAYER_INFINIBAND:
|
2020-10-08 10:36:27 +08:00
|
|
|
output = "InfiniBand";
|
|
|
|
break;
|
2010-10-22 20:32:05 +08:00
|
|
|
case IB_LINK_LAYER_ETHERNET:
|
2020-10-08 10:36:27 +08:00
|
|
|
output = "Ethernet";
|
|
|
|
break;
|
2010-10-22 20:32:05 +08:00
|
|
|
default:
|
2020-10-08 10:36:27 +08:00
|
|
|
output = "Unknown";
|
|
|
|
break;
|
2010-10-22 20:32:05 +08:00
|
|
|
}
|
2020-10-08 10:36:27 +08:00
|
|
|
|
|
|
|
return sysfs_emit(buf, "%s\n", output);
|
2010-10-22 20:32:05 +08:00
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
static PORT_ATTR_RO(state);
|
|
|
|
static PORT_ATTR_RO(lid);
|
|
|
|
static PORT_ATTR_RO(lid_mask_count);
|
|
|
|
static PORT_ATTR_RO(sm_lid);
|
|
|
|
static PORT_ATTR_RO(sm_sl);
|
|
|
|
static PORT_ATTR_RO(cap_mask);
|
|
|
|
static PORT_ATTR_RO(rate);
|
|
|
|
static PORT_ATTR_RO(phys_state);
|
2010-10-22 20:32:05 +08:00
|
|
|
static PORT_ATTR_RO(link_layer);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
static struct attribute *port_default_attrs[] = {
|
|
|
|
&port_attr_state.attr,
|
|
|
|
&port_attr_lid.attr,
|
|
|
|
&port_attr_lid_mask_count.attr,
|
|
|
|
&port_attr_sm_lid.attr,
|
|
|
|
&port_attr_sm_sl.attr,
|
|
|
|
&port_attr_cap_mask.attr,
|
|
|
|
&port_attr_rate.attr,
|
|
|
|
&port_attr_phys_state.attr,
|
2010-10-22 20:32:05 +08:00
|
|
|
&port_attr_link_layer.attr,
|
2005-04-17 06:20:36 +08:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2020-10-08 10:36:27 +08:00
|
|
|
static ssize_t print_ndev(const struct ib_gid_attr *gid_attr, char *buf)
|
2015-12-23 20:56:49 +08:00
|
|
|
{
|
2019-05-02 15:48:07 +08:00
|
|
|
struct net_device *ndev;
|
2020-10-08 10:36:27 +08:00
|
|
|
int ret = -EINVAL;
|
2019-05-02 15:48:07 +08:00
|
|
|
|
|
|
|
rcu_read_lock();
|
|
|
|
ndev = rcu_dereference(gid_attr->ndev);
|
|
|
|
if (ndev)
|
2020-10-08 10:36:27 +08:00
|
|
|
ret = sysfs_emit(buf, "%s\n", ndev->name);
|
2019-05-02 15:48:07 +08:00
|
|
|
rcu_read_unlock();
|
|
|
|
return ret;
|
2015-12-23 20:56:49 +08:00
|
|
|
}
|
|
|
|
|
2020-10-08 10:36:27 +08:00
|
|
|
static ssize_t print_gid_type(const struct ib_gid_attr *gid_attr, char *buf)
|
2015-12-23 20:56:49 +08:00
|
|
|
{
|
2020-10-08 10:36:27 +08:00
|
|
|
return sysfs_emit(buf, "%s\n",
|
|
|
|
ib_cache_gid_type_str(gid_attr->gid_type));
|
2015-12-23 20:56:49 +08:00
|
|
|
}
|
|
|
|
|
2018-06-05 13:40:18 +08:00
|
|
|
static ssize_t _show_port_gid_attr(
|
|
|
|
struct ib_port *p, struct port_attribute *attr, char *buf,
|
2020-10-08 10:36:27 +08:00
|
|
|
ssize_t (*print)(const struct ib_gid_attr *gid_attr, char *buf))
|
2015-12-23 20:56:49 +08:00
|
|
|
{
|
|
|
|
struct port_table_attribute *tab_attr =
|
|
|
|
container_of(attr, struct port_table_attribute, attr);
|
2018-06-05 13:40:18 +08:00
|
|
|
const struct ib_gid_attr *gid_attr;
|
2015-12-23 20:56:49 +08:00
|
|
|
ssize_t ret;
|
|
|
|
|
2018-06-05 13:40:18 +08:00
|
|
|
gid_attr = rdma_get_gid_attr(p->ibdev, p->port_num, tab_attr->index);
|
|
|
|
if (IS_ERR(gid_attr))
|
2020-09-24 00:50:12 +08:00
|
|
|
/* -EINVAL is returned for user space compatibility reasons. */
|
|
|
|
return -EINVAL;
|
2015-12-23 20:56:49 +08:00
|
|
|
|
2018-06-05 13:40:18 +08:00
|
|
|
ret = print(gid_attr, buf);
|
|
|
|
rdma_put_gid_attr(gid_attr);
|
2015-12-23 20:56:49 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
static ssize_t show_port_gid(struct ib_port *p, struct port_attribute *attr,
|
|
|
|
char *buf)
|
|
|
|
{
|
|
|
|
struct port_table_attribute *tab_attr =
|
|
|
|
container_of(attr, struct port_table_attribute, attr);
|
2018-06-05 13:40:18 +08:00
|
|
|
const struct ib_gid_attr *gid_attr;
|
2020-10-08 10:36:27 +08:00
|
|
|
int len;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2018-06-05 13:40:18 +08:00
|
|
|
gid_attr = rdma_get_gid_attr(p->ibdev, p->port_num, tab_attr->index);
|
|
|
|
if (IS_ERR(gid_attr)) {
|
|
|
|
const union ib_gid zgid = {};
|
|
|
|
|
|
|
|
/* If reading GID fails, it is likely due to GID entry being
|
|
|
|
* empty (invalid) or reserved GID in the table. User space
|
|
|
|
* expects to read GID table entries as long as it given index
|
|
|
|
* is within GID table size. Administrative/debugging tool
|
|
|
|
* fails to query rest of the GID entries if it hits error
|
|
|
|
* while querying a GID of the given index. To avoid user
|
|
|
|
* space throwing such error on fail to read gid, return zero
|
|
|
|
* GID as before. This maintains backward compatibility.
|
|
|
|
*/
|
2020-10-08 10:36:27 +08:00
|
|
|
return sysfs_emit(buf, "%pI6\n", zgid.raw);
|
2018-06-05 13:40:18 +08:00
|
|
|
}
|
|
|
|
|
2020-10-08 10:36:27 +08:00
|
|
|
len = sysfs_emit(buf, "%pI6\n", gid_attr->gid.raw);
|
2018-06-05 13:40:18 +08:00
|
|
|
rdma_put_gid_attr(gid_attr);
|
2020-10-08 10:36:27 +08:00
|
|
|
return len;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2015-12-23 20:56:49 +08:00
|
|
|
static ssize_t show_port_gid_attr_ndev(struct ib_port *p,
|
|
|
|
struct port_attribute *attr, char *buf)
|
|
|
|
{
|
|
|
|
return _show_port_gid_attr(p, attr, buf, print_ndev);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t show_port_gid_attr_gid_type(struct ib_port *p,
|
|
|
|
struct port_attribute *attr,
|
|
|
|
char *buf)
|
|
|
|
{
|
|
|
|
return _show_port_gid_attr(p, attr, buf, print_gid_type);
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
static ssize_t show_port_pkey(struct ib_port *p, struct port_attribute *attr,
|
|
|
|
char *buf)
|
|
|
|
{
|
|
|
|
struct port_table_attribute *tab_attr =
|
|
|
|
container_of(attr, struct port_table_attribute, attr);
|
|
|
|
u16 pkey;
|
2020-10-08 10:36:27 +08:00
|
|
|
int ret;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
ret = ib_query_pkey(p->ibdev, p->port_num, tab_attr->index, &pkey);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2020-10-08 10:36:27 +08:00
|
|
|
return sysfs_emit(buf, "0x%04x\n", pkey);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#define PORT_PMA_ATTR(_name, _counter, _width, _offset) \
|
|
|
|
struct port_table_attribute port_pma_attr_##_name = { \
|
|
|
|
.attr = __ATTR(_name, S_IRUGO, show_pma_counter, NULL), \
|
2015-12-21 22:20:28 +08:00
|
|
|
.index = (_offset) | ((_width) << 16) | ((_counter) << 24), \
|
|
|
|
.attr_id = IB_PMA_PORT_COUNTERS , \
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2015-12-21 22:20:29 +08:00
|
|
|
#define PORT_PMA_ATTR_EXT(_name, _width, _offset) \
|
|
|
|
struct port_table_attribute port_pma_attr_ext_##_name = { \
|
|
|
|
.attr = __ATTR(_name, S_IRUGO, show_pma_counter, NULL), \
|
|
|
|
.index = (_offset) | ((_width) << 16), \
|
|
|
|
.attr_id = IB_PMA_PORT_COUNTERS_EXT , \
|
|
|
|
}
|
|
|
|
|
2015-12-21 22:20:27 +08:00
|
|
|
/*
|
|
|
|
* Get a Perfmgmt MAD block of data.
|
|
|
|
* Returns error code or the number of bytes retrieved.
|
|
|
|
*/
|
2016-01-04 11:44:25 +08:00
|
|
|
static int get_perf_mad(struct ib_device *dev, int port_num, __be16 attr,
|
2015-12-21 22:20:27 +08:00
|
|
|
void *data, int offset, size_t size)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2015-12-21 22:20:27 +08:00
|
|
|
struct ib_mad *in_mad;
|
|
|
|
struct ib_mad *out_mad;
|
2015-06-07 02:38:31 +08:00
|
|
|
size_t mad_size = sizeof(*out_mad);
|
|
|
|
u16 out_mad_pkey_index = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
ssize_t ret;
|
|
|
|
|
2018-12-11 03:09:48 +08:00
|
|
|
if (!dev->ops.process_mad)
|
2015-12-21 22:20:27 +08:00
|
|
|
return -ENOSYS;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2019-10-29 14:27:31 +08:00
|
|
|
in_mad = kzalloc(sizeof(*in_mad), GFP_KERNEL);
|
|
|
|
out_mad = kzalloc(sizeof(*out_mad), GFP_KERNEL);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!in_mad || !out_mad) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
in_mad->mad_hdr.base_version = 1;
|
|
|
|
in_mad->mad_hdr.mgmt_class = IB_MGMT_CLASS_PERF_MGMT;
|
|
|
|
in_mad->mad_hdr.class_version = 1;
|
|
|
|
in_mad->mad_hdr.method = IB_MGMT_METHOD_GET;
|
2015-12-21 22:20:27 +08:00
|
|
|
in_mad->mad_hdr.attr_id = attr;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2015-12-29 18:43:43 +08:00
|
|
|
if (attr != IB_PMA_CLASS_PORT_INFO)
|
|
|
|
in_mad->data[41] = port_num; /* PortSelect field */
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2019-10-29 14:27:45 +08:00
|
|
|
if ((dev->ops.process_mad(dev, IB_MAD_IGNORE_MKEY, port_num, NULL, NULL,
|
|
|
|
in_mad, out_mad, &mad_size,
|
2018-12-11 03:09:48 +08:00
|
|
|
&out_mad_pkey_index) &
|
2005-04-17 06:20:36 +08:00
|
|
|
(IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_REPLY)) !=
|
|
|
|
(IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_REPLY)) {
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
2015-12-21 22:20:27 +08:00
|
|
|
memcpy(data, out_mad->data + offset, size);
|
|
|
|
ret = size;
|
|
|
|
out:
|
|
|
|
kfree(in_mad);
|
|
|
|
kfree(out_mad);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t show_pma_counter(struct ib_port *p, struct port_attribute *attr,
|
|
|
|
char *buf)
|
|
|
|
{
|
|
|
|
struct port_table_attribute *tab_attr =
|
|
|
|
container_of(attr, struct port_table_attribute, attr);
|
|
|
|
int offset = tab_attr->index & 0xffff;
|
|
|
|
int width = (tab_attr->index >> 16) & 0xff;
|
2020-10-08 10:36:27 +08:00
|
|
|
int ret;
|
2015-12-21 22:20:27 +08:00
|
|
|
u8 data[8];
|
2020-10-08 10:36:27 +08:00
|
|
|
int len;
|
2015-12-21 22:20:27 +08:00
|
|
|
|
2015-12-21 22:20:28 +08:00
|
|
|
ret = get_perf_mad(p->ibdev, p->port_num, tab_attr->attr_id, &data,
|
2015-12-21 22:20:27 +08:00
|
|
|
40 + offset / 8, sizeof(data));
|
|
|
|
if (ret < 0)
|
2018-10-07 17:12:40 +08:00
|
|
|
return ret;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
switch (width) {
|
|
|
|
case 4:
|
2020-10-08 10:36:27 +08:00
|
|
|
len = sysfs_emit(buf, "%u\n",
|
|
|
|
(*data >> (4 - (offset % 8))) & 0xf);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
case 8:
|
2020-10-08 10:36:27 +08:00
|
|
|
len = sysfs_emit(buf, "%u\n", *data);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
case 16:
|
2020-10-08 10:36:27 +08:00
|
|
|
len = sysfs_emit(buf, "%u\n", be16_to_cpup((__be16 *)data));
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
case 32:
|
2020-10-08 10:36:27 +08:00
|
|
|
len = sysfs_emit(buf, "%u\n", be32_to_cpup((__be32 *)data));
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
2015-12-21 22:20:29 +08:00
|
|
|
case 64:
|
2020-10-08 10:36:27 +08:00
|
|
|
len = sysfs_emit(buf, "%llu\n", be64_to_cpup((__be64 *)data));
|
2015-12-21 22:20:29 +08:00
|
|
|
break;
|
2005-04-17 06:20:36 +08:00
|
|
|
default:
|
2020-10-08 10:36:27 +08:00
|
|
|
len = 0;
|
|
|
|
break;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2020-10-08 10:36:27 +08:00
|
|
|
return len;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static PORT_PMA_ATTR(symbol_error , 0, 16, 32);
|
|
|
|
static PORT_PMA_ATTR(link_error_recovery , 1, 8, 48);
|
|
|
|
static PORT_PMA_ATTR(link_downed , 2, 8, 56);
|
|
|
|
static PORT_PMA_ATTR(port_rcv_errors , 3, 16, 64);
|
|
|
|
static PORT_PMA_ATTR(port_rcv_remote_physical_errors, 4, 16, 80);
|
|
|
|
static PORT_PMA_ATTR(port_rcv_switch_relay_errors , 5, 16, 96);
|
|
|
|
static PORT_PMA_ATTR(port_xmit_discards , 6, 16, 112);
|
|
|
|
static PORT_PMA_ATTR(port_xmit_constraint_errors , 7, 8, 128);
|
|
|
|
static PORT_PMA_ATTR(port_rcv_constraint_errors , 8, 8, 136);
|
|
|
|
static PORT_PMA_ATTR(local_link_integrity_errors , 9, 4, 152);
|
|
|
|
static PORT_PMA_ATTR(excessive_buffer_overrun_errors, 10, 4, 156);
|
|
|
|
static PORT_PMA_ATTR(VL15_dropped , 11, 16, 176);
|
|
|
|
static PORT_PMA_ATTR(port_xmit_data , 12, 32, 192);
|
|
|
|
static PORT_PMA_ATTR(port_rcv_data , 13, 32, 224);
|
|
|
|
static PORT_PMA_ATTR(port_xmit_packets , 14, 32, 256);
|
|
|
|
static PORT_PMA_ATTR(port_rcv_packets , 15, 32, 288);
|
2016-07-08 23:27:42 +08:00
|
|
|
static PORT_PMA_ATTR(port_xmit_wait , 0, 32, 320);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2015-12-21 22:20:29 +08:00
|
|
|
/*
|
|
|
|
* Counters added by extended set
|
|
|
|
*/
|
|
|
|
static PORT_PMA_ATTR_EXT(port_xmit_data , 64, 64);
|
|
|
|
static PORT_PMA_ATTR_EXT(port_rcv_data , 64, 128);
|
|
|
|
static PORT_PMA_ATTR_EXT(port_xmit_packets , 64, 192);
|
|
|
|
static PORT_PMA_ATTR_EXT(port_rcv_packets , 64, 256);
|
|
|
|
static PORT_PMA_ATTR_EXT(unicast_xmit_packets , 64, 320);
|
|
|
|
static PORT_PMA_ATTR_EXT(unicast_rcv_packets , 64, 384);
|
|
|
|
static PORT_PMA_ATTR_EXT(multicast_xmit_packets , 64, 448);
|
|
|
|
static PORT_PMA_ATTR_EXT(multicast_rcv_packets , 64, 512);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
static struct attribute *pma_attrs[] = {
|
|
|
|
&port_pma_attr_symbol_error.attr.attr,
|
|
|
|
&port_pma_attr_link_error_recovery.attr.attr,
|
|
|
|
&port_pma_attr_link_downed.attr.attr,
|
|
|
|
&port_pma_attr_port_rcv_errors.attr.attr,
|
|
|
|
&port_pma_attr_port_rcv_remote_physical_errors.attr.attr,
|
|
|
|
&port_pma_attr_port_rcv_switch_relay_errors.attr.attr,
|
|
|
|
&port_pma_attr_port_xmit_discards.attr.attr,
|
|
|
|
&port_pma_attr_port_xmit_constraint_errors.attr.attr,
|
|
|
|
&port_pma_attr_port_rcv_constraint_errors.attr.attr,
|
|
|
|
&port_pma_attr_local_link_integrity_errors.attr.attr,
|
|
|
|
&port_pma_attr_excessive_buffer_overrun_errors.attr.attr,
|
|
|
|
&port_pma_attr_VL15_dropped.attr.attr,
|
|
|
|
&port_pma_attr_port_xmit_data.attr.attr,
|
|
|
|
&port_pma_attr_port_rcv_data.attr.attr,
|
|
|
|
&port_pma_attr_port_xmit_packets.attr.attr,
|
|
|
|
&port_pma_attr_port_rcv_packets.attr.attr,
|
2016-07-08 23:27:42 +08:00
|
|
|
&port_pma_attr_port_xmit_wait.attr.attr,
|
2005-04-17 06:20:36 +08:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2015-12-21 22:20:29 +08:00
|
|
|
static struct attribute *pma_attrs_ext[] = {
|
|
|
|
&port_pma_attr_symbol_error.attr.attr,
|
|
|
|
&port_pma_attr_link_error_recovery.attr.attr,
|
|
|
|
&port_pma_attr_link_downed.attr.attr,
|
|
|
|
&port_pma_attr_port_rcv_errors.attr.attr,
|
|
|
|
&port_pma_attr_port_rcv_remote_physical_errors.attr.attr,
|
|
|
|
&port_pma_attr_port_rcv_switch_relay_errors.attr.attr,
|
|
|
|
&port_pma_attr_port_xmit_discards.attr.attr,
|
|
|
|
&port_pma_attr_port_xmit_constraint_errors.attr.attr,
|
|
|
|
&port_pma_attr_port_rcv_constraint_errors.attr.attr,
|
|
|
|
&port_pma_attr_local_link_integrity_errors.attr.attr,
|
|
|
|
&port_pma_attr_excessive_buffer_overrun_errors.attr.attr,
|
|
|
|
&port_pma_attr_VL15_dropped.attr.attr,
|
|
|
|
&port_pma_attr_ext_port_xmit_data.attr.attr,
|
|
|
|
&port_pma_attr_ext_port_rcv_data.attr.attr,
|
|
|
|
&port_pma_attr_ext_port_xmit_packets.attr.attr,
|
2016-07-08 23:27:42 +08:00
|
|
|
&port_pma_attr_port_xmit_wait.attr.attr,
|
2015-12-21 22:20:29 +08:00
|
|
|
&port_pma_attr_ext_port_rcv_packets.attr.attr,
|
|
|
|
&port_pma_attr_ext_unicast_rcv_packets.attr.attr,
|
|
|
|
&port_pma_attr_ext_unicast_xmit_packets.attr.attr,
|
|
|
|
&port_pma_attr_ext_multicast_rcv_packets.attr.attr,
|
|
|
|
&port_pma_attr_ext_multicast_xmit_packets.attr.attr,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct attribute *pma_attrs_noietf[] = {
|
|
|
|
&port_pma_attr_symbol_error.attr.attr,
|
|
|
|
&port_pma_attr_link_error_recovery.attr.attr,
|
|
|
|
&port_pma_attr_link_downed.attr.attr,
|
|
|
|
&port_pma_attr_port_rcv_errors.attr.attr,
|
|
|
|
&port_pma_attr_port_rcv_remote_physical_errors.attr.attr,
|
|
|
|
&port_pma_attr_port_rcv_switch_relay_errors.attr.attr,
|
|
|
|
&port_pma_attr_port_xmit_discards.attr.attr,
|
|
|
|
&port_pma_attr_port_xmit_constraint_errors.attr.attr,
|
|
|
|
&port_pma_attr_port_rcv_constraint_errors.attr.attr,
|
|
|
|
&port_pma_attr_local_link_integrity_errors.attr.attr,
|
|
|
|
&port_pma_attr_excessive_buffer_overrun_errors.attr.attr,
|
|
|
|
&port_pma_attr_VL15_dropped.attr.attr,
|
|
|
|
&port_pma_attr_ext_port_xmit_data.attr.attr,
|
|
|
|
&port_pma_attr_ext_port_rcv_data.attr.attr,
|
|
|
|
&port_pma_attr_ext_port_xmit_packets.attr.attr,
|
|
|
|
&port_pma_attr_ext_port_rcv_packets.attr.attr,
|
2016-07-08 23:27:42 +08:00
|
|
|
&port_pma_attr_port_xmit_wait.attr.attr,
|
2015-12-21 22:20:29 +08:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2020-10-01 06:40:03 +08:00
|
|
|
static const struct attribute_group pma_group = {
|
2005-04-17 06:20:36 +08:00
|
|
|
.name = "counters",
|
|
|
|
.attrs = pma_attrs
|
|
|
|
};
|
|
|
|
|
2020-10-01 06:40:03 +08:00
|
|
|
static const struct attribute_group pma_group_ext = {
|
2015-12-21 22:20:29 +08:00
|
|
|
.name = "counters",
|
|
|
|
.attrs = pma_attrs_ext
|
|
|
|
};
|
|
|
|
|
2020-10-01 06:40:03 +08:00
|
|
|
static const struct attribute_group pma_group_noietf = {
|
2015-12-21 22:20:29 +08:00
|
|
|
.name = "counters",
|
|
|
|
.attrs = pma_attrs_noietf
|
|
|
|
};
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
static void ib_port_release(struct kobject *kobj)
|
|
|
|
{
|
|
|
|
struct ib_port *p = container_of(kobj, struct ib_port, kobj);
|
|
|
|
struct attribute *a;
|
|
|
|
int i;
|
|
|
|
|
2014-05-18 16:12:25 +08:00
|
|
|
if (p->gid_group.attrs) {
|
|
|
|
for (i = 0; (a = p->gid_group.attrs[i]); ++i)
|
|
|
|
kfree(a);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2014-05-18 16:12:25 +08:00
|
|
|
kfree(p->gid_group.attrs);
|
|
|
|
}
|
2005-04-29 13:58:46 +08:00
|
|
|
|
2020-07-15 02:34:08 +08:00
|
|
|
if (p->pkey_group) {
|
|
|
|
if (p->pkey_group->attrs) {
|
|
|
|
for (i = 0; (a = p->pkey_group->attrs[i]); ++i)
|
|
|
|
kfree(a);
|
|
|
|
|
|
|
|
kfree(p->pkey_group->attrs);
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2020-07-15 02:34:08 +08:00
|
|
|
kfree(p->pkey_group);
|
|
|
|
p->pkey_group = NULL;
|
2014-05-18 16:12:25 +08:00
|
|
|
}
|
2005-04-29 13:58:46 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
kfree(p);
|
|
|
|
}
|
|
|
|
|
2015-12-23 20:56:49 +08:00
|
|
|
static void ib_port_gid_attr_release(struct kobject *kobj)
|
|
|
|
{
|
|
|
|
struct gid_attr_group *g = container_of(kobj, struct gid_attr_group,
|
|
|
|
kobj);
|
|
|
|
struct attribute *a;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (g->ndev.attrs) {
|
|
|
|
for (i = 0; (a = g->ndev.attrs[i]); ++i)
|
|
|
|
kfree(a);
|
|
|
|
|
|
|
|
kfree(g->ndev.attrs);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g->type.attrs) {
|
|
|
|
for (i = 0; (a = g->type.attrs[i]); ++i)
|
|
|
|
kfree(a);
|
|
|
|
|
|
|
|
kfree(g->type.attrs);
|
|
|
|
}
|
|
|
|
|
|
|
|
kfree(g);
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
static struct kobj_type port_type = {
|
|
|
|
.release = ib_port_release,
|
|
|
|
.sysfs_ops = &port_sysfs_ops,
|
|
|
|
.default_attrs = port_default_attrs
|
|
|
|
};
|
|
|
|
|
2015-12-23 20:56:49 +08:00
|
|
|
static struct kobj_type gid_attr_type = {
|
|
|
|
.sysfs_ops = &gid_attr_sysfs_ops,
|
|
|
|
.release = ib_port_gid_attr_release
|
|
|
|
};
|
|
|
|
|
2005-04-29 13:58:46 +08:00
|
|
|
static struct attribute **
|
|
|
|
alloc_group_attrs(ssize_t (*show)(struct ib_port *,
|
|
|
|
struct port_attribute *, char *buf),
|
|
|
|
int len)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-04-29 13:58:46 +08:00
|
|
|
struct attribute **tab_attr;
|
|
|
|
struct port_table_attribute *element;
|
2005-04-17 06:20:36 +08:00
|
|
|
int i;
|
|
|
|
|
2005-04-29 13:58:46 +08:00
|
|
|
tab_attr = kcalloc(1 + len, sizeof(struct attribute *), GFP_KERNEL);
|
|
|
|
if (!tab_attr)
|
|
|
|
return NULL;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-04-29 13:58:46 +08:00
|
|
|
for (i = 0; i < len; i++) {
|
2005-09-07 06:18:35 +08:00
|
|
|
element = kzalloc(sizeof(struct port_table_attribute),
|
2005-04-29 13:58:46 +08:00
|
|
|
GFP_KERNEL);
|
|
|
|
if (!element)
|
2005-04-17 06:20:36 +08:00
|
|
|
goto err;
|
|
|
|
|
2005-04-29 13:58:46 +08:00
|
|
|
if (snprintf(element->name, sizeof(element->name),
|
2006-03-21 02:08:25 +08:00
|
|
|
"%d", i) >= sizeof(element->name)) {
|
|
|
|
kfree(element);
|
2005-04-17 06:20:36 +08:00
|
|
|
goto err;
|
2006-03-21 02:08:25 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-04-29 13:58:46 +08:00
|
|
|
element->attr.attr.name = element->name;
|
|
|
|
element->attr.attr.mode = S_IRUGO;
|
|
|
|
element->attr.show = show;
|
|
|
|
element->index = i;
|
2010-03-16 05:01:25 +08:00
|
|
|
sysfs_attr_init(&element->attr.attr);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-04-29 13:58:46 +08:00
|
|
|
tab_attr[i] = &element->attr.attr;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2005-04-29 13:58:46 +08:00
|
|
|
return tab_attr;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-04-29 13:58:46 +08:00
|
|
|
err:
|
|
|
|
while (--i >= 0)
|
|
|
|
kfree(tab_attr[i]);
|
|
|
|
kfree(tab_attr);
|
|
|
|
return NULL;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2015-12-21 22:20:29 +08:00
|
|
|
/*
|
|
|
|
* Figure out which counter table to use depending on
|
|
|
|
* the device capabilities.
|
|
|
|
*/
|
2020-10-01 06:40:03 +08:00
|
|
|
static const struct attribute_group *get_counter_table(struct ib_device *dev,
|
|
|
|
int port_num)
|
2015-12-21 22:20:29 +08:00
|
|
|
{
|
|
|
|
struct ib_class_port_info cpi;
|
|
|
|
|
2015-12-29 18:43:43 +08:00
|
|
|
if (get_perf_mad(dev, port_num, IB_PMA_CLASS_PORT_INFO,
|
2015-12-21 22:20:29 +08:00
|
|
|
&cpi, 40, sizeof(cpi)) >= 0) {
|
2016-02-11 16:24:42 +08:00
|
|
|
if (cpi.capability_mask & IB_PMA_CLASS_CAP_EXT_WIDTH)
|
2015-12-21 22:20:29 +08:00
|
|
|
/* We have extended counters */
|
|
|
|
return &pma_group_ext;
|
|
|
|
|
2016-02-11 16:24:42 +08:00
|
|
|
if (cpi.capability_mask & IB_PMA_CLASS_CAP_EXT_WIDTH_NOIETF)
|
2015-12-21 22:20:29 +08:00
|
|
|
/* But not the IETF ones */
|
|
|
|
return &pma_group_noietf;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Fall back to normal counters */
|
|
|
|
return &pma_group;
|
|
|
|
}
|
|
|
|
|
IB/core: Make device counter infrastructure dynamic
In practice, each RDMA device has a unique set of counters that the
hardware implements. Having a central set of counters that they must
all adhere to is limiting and causes many useful counters to not be
available.
Therefore we create a dynamic counter registration infrastructure.
The driver must implement a stats structure allocation routine, in
which the driver must place the directory name it wants, a list of
names for all of the counters, an array of u64 counters themselves,
plus a few generic configuration options.
We then implement a core routine to create a sysfs file for each
of the named stats elements, and a core routine to retrieve the
stats when any of the sysfs attribute files are read.
To avoid excessive beating on the stats generation routine in the
drivers, the core code also caches the stats for a short period of
time so that someone attempting to read all of the stats in a
given device's directory will not result in a stats generation
call per file read.
Future work will attempt to standardize just the shared stats
elements, and possibly add a method to get the stats via netlink
in addition to sysfs.
Signed-off-by: Christoph Lameter <cl@linux.com>
Signed-off-by: Mark Bloch <markb@mellanox.com>
Reviewed-by: Steve Wise <swise@opengridcomputing.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
[ Add caching, make structure names more informative, add i40iw support,
other significant rewrites from the original patch ]
2016-05-17 01:49:33 +08:00
|
|
|
static int update_hw_stats(struct ib_device *dev, struct rdma_hw_stats *stats,
|
|
|
|
u8 port_num, int index)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (time_is_after_eq_jiffies(stats->timestamp + stats->lifespan))
|
|
|
|
return 0;
|
2018-12-11 03:09:48 +08:00
|
|
|
ret = dev->ops.get_hw_stats(dev, stats, port_num, index);
|
IB/core: Make device counter infrastructure dynamic
In practice, each RDMA device has a unique set of counters that the
hardware implements. Having a central set of counters that they must
all adhere to is limiting and causes many useful counters to not be
available.
Therefore we create a dynamic counter registration infrastructure.
The driver must implement a stats structure allocation routine, in
which the driver must place the directory name it wants, a list of
names for all of the counters, an array of u64 counters themselves,
plus a few generic configuration options.
We then implement a core routine to create a sysfs file for each
of the named stats elements, and a core routine to retrieve the
stats when any of the sysfs attribute files are read.
To avoid excessive beating on the stats generation routine in the
drivers, the core code also caches the stats for a short period of
time so that someone attempting to read all of the stats in a
given device's directory will not result in a stats generation
call per file read.
Future work will attempt to standardize just the shared stats
elements, and possibly add a method to get the stats via netlink
in addition to sysfs.
Signed-off-by: Christoph Lameter <cl@linux.com>
Signed-off-by: Mark Bloch <markb@mellanox.com>
Reviewed-by: Steve Wise <swise@opengridcomputing.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
[ Add caching, make structure names more informative, add i40iw support,
other significant rewrites from the original patch ]
2016-05-17 01:49:33 +08:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
if (ret == stats->num_counters)
|
|
|
|
stats->timestamp = jiffies;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-10-08 10:36:27 +08:00
|
|
|
static int print_hw_stat(struct ib_device *dev, int port_num,
|
|
|
|
struct rdma_hw_stats *stats, int index, char *buf)
|
IB/core: Make device counter infrastructure dynamic
In practice, each RDMA device has a unique set of counters that the
hardware implements. Having a central set of counters that they must
all adhere to is limiting and causes many useful counters to not be
available.
Therefore we create a dynamic counter registration infrastructure.
The driver must implement a stats structure allocation routine, in
which the driver must place the directory name it wants, a list of
names for all of the counters, an array of u64 counters themselves,
plus a few generic configuration options.
We then implement a core routine to create a sysfs file for each
of the named stats elements, and a core routine to retrieve the
stats when any of the sysfs attribute files are read.
To avoid excessive beating on the stats generation routine in the
drivers, the core code also caches the stats for a short period of
time so that someone attempting to read all of the stats in a
given device's directory will not result in a stats generation
call per file read.
Future work will attempt to standardize just the shared stats
elements, and possibly add a method to get the stats via netlink
in addition to sysfs.
Signed-off-by: Christoph Lameter <cl@linux.com>
Signed-off-by: Mark Bloch <markb@mellanox.com>
Reviewed-by: Steve Wise <swise@opengridcomputing.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
[ Add caching, make structure names more informative, add i40iw support,
other significant rewrites from the original patch ]
2016-05-17 01:49:33 +08:00
|
|
|
{
|
2019-07-02 18:02:42 +08:00
|
|
|
u64 v = rdma_counter_get_hwstat_value(dev, port_num, index);
|
|
|
|
|
2020-10-08 10:36:27 +08:00
|
|
|
return sysfs_emit(buf, "%llu\n", stats->value[index] + v);
|
IB/core: Make device counter infrastructure dynamic
In practice, each RDMA device has a unique set of counters that the
hardware implements. Having a central set of counters that they must
all adhere to is limiting and causes many useful counters to not be
available.
Therefore we create a dynamic counter registration infrastructure.
The driver must implement a stats structure allocation routine, in
which the driver must place the directory name it wants, a list of
names for all of the counters, an array of u64 counters themselves,
plus a few generic configuration options.
We then implement a core routine to create a sysfs file for each
of the named stats elements, and a core routine to retrieve the
stats when any of the sysfs attribute files are read.
To avoid excessive beating on the stats generation routine in the
drivers, the core code also caches the stats for a short period of
time so that someone attempting to read all of the stats in a
given device's directory will not result in a stats generation
call per file read.
Future work will attempt to standardize just the shared stats
elements, and possibly add a method to get the stats via netlink
in addition to sysfs.
Signed-off-by: Christoph Lameter <cl@linux.com>
Signed-off-by: Mark Bloch <markb@mellanox.com>
Reviewed-by: Steve Wise <swise@opengridcomputing.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
[ Add caching, make structure names more informative, add i40iw support,
other significant rewrites from the original patch ]
2016-05-17 01:49:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t show_hw_stats(struct kobject *kobj, struct attribute *attr,
|
|
|
|
char *buf)
|
|
|
|
{
|
|
|
|
struct ib_device *dev;
|
|
|
|
struct ib_port *port;
|
|
|
|
struct hw_stats_attribute *hsa;
|
|
|
|
struct rdma_hw_stats *stats;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
hsa = container_of(attr, struct hw_stats_attribute, attr);
|
|
|
|
if (!hsa->port_num) {
|
|
|
|
dev = container_of((struct device *)kobj,
|
|
|
|
struct ib_device, dev);
|
|
|
|
stats = dev->hw_stats;
|
|
|
|
} else {
|
|
|
|
port = container_of(kobj, struct ib_port, kobj);
|
|
|
|
dev = port->ibdev;
|
|
|
|
stats = port->hw_stats;
|
|
|
|
}
|
2018-03-27 20:51:05 +08:00
|
|
|
mutex_lock(&stats->lock);
|
IB/core: Make device counter infrastructure dynamic
In practice, each RDMA device has a unique set of counters that the
hardware implements. Having a central set of counters that they must
all adhere to is limiting and causes many useful counters to not be
available.
Therefore we create a dynamic counter registration infrastructure.
The driver must implement a stats structure allocation routine, in
which the driver must place the directory name it wants, a list of
names for all of the counters, an array of u64 counters themselves,
plus a few generic configuration options.
We then implement a core routine to create a sysfs file for each
of the named stats elements, and a core routine to retrieve the
stats when any of the sysfs attribute files are read.
To avoid excessive beating on the stats generation routine in the
drivers, the core code also caches the stats for a short period of
time so that someone attempting to read all of the stats in a
given device's directory will not result in a stats generation
call per file read.
Future work will attempt to standardize just the shared stats
elements, and possibly add a method to get the stats via netlink
in addition to sysfs.
Signed-off-by: Christoph Lameter <cl@linux.com>
Signed-off-by: Mark Bloch <markb@mellanox.com>
Reviewed-by: Steve Wise <swise@opengridcomputing.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
[ Add caching, make structure names more informative, add i40iw support,
other significant rewrites from the original patch ]
2016-05-17 01:49:33 +08:00
|
|
|
ret = update_hw_stats(dev, stats, hsa->port_num, hsa->index);
|
|
|
|
if (ret)
|
2018-03-27 20:51:05 +08:00
|
|
|
goto unlock;
|
2019-07-02 18:02:42 +08:00
|
|
|
ret = print_hw_stat(dev, hsa->port_num, stats, hsa->index, buf);
|
2018-03-27 20:51:05 +08:00
|
|
|
unlock:
|
|
|
|
mutex_unlock(&stats->lock);
|
|
|
|
|
|
|
|
return ret;
|
IB/core: Make device counter infrastructure dynamic
In practice, each RDMA device has a unique set of counters that the
hardware implements. Having a central set of counters that they must
all adhere to is limiting and causes many useful counters to not be
available.
Therefore we create a dynamic counter registration infrastructure.
The driver must implement a stats structure allocation routine, in
which the driver must place the directory name it wants, a list of
names for all of the counters, an array of u64 counters themselves,
plus a few generic configuration options.
We then implement a core routine to create a sysfs file for each
of the named stats elements, and a core routine to retrieve the
stats when any of the sysfs attribute files are read.
To avoid excessive beating on the stats generation routine in the
drivers, the core code also caches the stats for a short period of
time so that someone attempting to read all of the stats in a
given device's directory will not result in a stats generation
call per file read.
Future work will attempt to standardize just the shared stats
elements, and possibly add a method to get the stats via netlink
in addition to sysfs.
Signed-off-by: Christoph Lameter <cl@linux.com>
Signed-off-by: Mark Bloch <markb@mellanox.com>
Reviewed-by: Steve Wise <swise@opengridcomputing.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
[ Add caching, make structure names more informative, add i40iw support,
other significant rewrites from the original patch ]
2016-05-17 01:49:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t show_stats_lifespan(struct kobject *kobj,
|
|
|
|
struct attribute *attr,
|
|
|
|
char *buf)
|
|
|
|
{
|
|
|
|
struct hw_stats_attribute *hsa;
|
2018-03-27 20:51:05 +08:00
|
|
|
struct rdma_hw_stats *stats;
|
IB/core: Make device counter infrastructure dynamic
In practice, each RDMA device has a unique set of counters that the
hardware implements. Having a central set of counters that they must
all adhere to is limiting and causes many useful counters to not be
available.
Therefore we create a dynamic counter registration infrastructure.
The driver must implement a stats structure allocation routine, in
which the driver must place the directory name it wants, a list of
names for all of the counters, an array of u64 counters themselves,
plus a few generic configuration options.
We then implement a core routine to create a sysfs file for each
of the named stats elements, and a core routine to retrieve the
stats when any of the sysfs attribute files are read.
To avoid excessive beating on the stats generation routine in the
drivers, the core code also caches the stats for a short period of
time so that someone attempting to read all of the stats in a
given device's directory will not result in a stats generation
call per file read.
Future work will attempt to standardize just the shared stats
elements, and possibly add a method to get the stats via netlink
in addition to sysfs.
Signed-off-by: Christoph Lameter <cl@linux.com>
Signed-off-by: Mark Bloch <markb@mellanox.com>
Reviewed-by: Steve Wise <swise@opengridcomputing.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
[ Add caching, make structure names more informative, add i40iw support,
other significant rewrites from the original patch ]
2016-05-17 01:49:33 +08:00
|
|
|
int msecs;
|
|
|
|
|
|
|
|
hsa = container_of(attr, struct hw_stats_attribute, attr);
|
|
|
|
if (!hsa->port_num) {
|
|
|
|
struct ib_device *dev = container_of((struct device *)kobj,
|
|
|
|
struct ib_device, dev);
|
2018-03-27 20:51:05 +08:00
|
|
|
|
|
|
|
stats = dev->hw_stats;
|
IB/core: Make device counter infrastructure dynamic
In practice, each RDMA device has a unique set of counters that the
hardware implements. Having a central set of counters that they must
all adhere to is limiting and causes many useful counters to not be
available.
Therefore we create a dynamic counter registration infrastructure.
The driver must implement a stats structure allocation routine, in
which the driver must place the directory name it wants, a list of
names for all of the counters, an array of u64 counters themselves,
plus a few generic configuration options.
We then implement a core routine to create a sysfs file for each
of the named stats elements, and a core routine to retrieve the
stats when any of the sysfs attribute files are read.
To avoid excessive beating on the stats generation routine in the
drivers, the core code also caches the stats for a short period of
time so that someone attempting to read all of the stats in a
given device's directory will not result in a stats generation
call per file read.
Future work will attempt to standardize just the shared stats
elements, and possibly add a method to get the stats via netlink
in addition to sysfs.
Signed-off-by: Christoph Lameter <cl@linux.com>
Signed-off-by: Mark Bloch <markb@mellanox.com>
Reviewed-by: Steve Wise <swise@opengridcomputing.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
[ Add caching, make structure names more informative, add i40iw support,
other significant rewrites from the original patch ]
2016-05-17 01:49:33 +08:00
|
|
|
} else {
|
|
|
|
struct ib_port *p = container_of(kobj, struct ib_port, kobj);
|
2018-03-27 20:51:05 +08:00
|
|
|
|
|
|
|
stats = p->hw_stats;
|
IB/core: Make device counter infrastructure dynamic
In practice, each RDMA device has a unique set of counters that the
hardware implements. Having a central set of counters that they must
all adhere to is limiting and causes many useful counters to not be
available.
Therefore we create a dynamic counter registration infrastructure.
The driver must implement a stats structure allocation routine, in
which the driver must place the directory name it wants, a list of
names for all of the counters, an array of u64 counters themselves,
plus a few generic configuration options.
We then implement a core routine to create a sysfs file for each
of the named stats elements, and a core routine to retrieve the
stats when any of the sysfs attribute files are read.
To avoid excessive beating on the stats generation routine in the
drivers, the core code also caches the stats for a short period of
time so that someone attempting to read all of the stats in a
given device's directory will not result in a stats generation
call per file read.
Future work will attempt to standardize just the shared stats
elements, and possibly add a method to get the stats via netlink
in addition to sysfs.
Signed-off-by: Christoph Lameter <cl@linux.com>
Signed-off-by: Mark Bloch <markb@mellanox.com>
Reviewed-by: Steve Wise <swise@opengridcomputing.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
[ Add caching, make structure names more informative, add i40iw support,
other significant rewrites from the original patch ]
2016-05-17 01:49:33 +08:00
|
|
|
}
|
2018-03-27 20:51:05 +08:00
|
|
|
|
|
|
|
mutex_lock(&stats->lock);
|
|
|
|
msecs = jiffies_to_msecs(stats->lifespan);
|
|
|
|
mutex_unlock(&stats->lock);
|
|
|
|
|
2020-10-08 10:36:27 +08:00
|
|
|
return sysfs_emit(buf, "%d\n", msecs);
|
IB/core: Make device counter infrastructure dynamic
In practice, each RDMA device has a unique set of counters that the
hardware implements. Having a central set of counters that they must
all adhere to is limiting and causes many useful counters to not be
available.
Therefore we create a dynamic counter registration infrastructure.
The driver must implement a stats structure allocation routine, in
which the driver must place the directory name it wants, a list of
names for all of the counters, an array of u64 counters themselves,
plus a few generic configuration options.
We then implement a core routine to create a sysfs file for each
of the named stats elements, and a core routine to retrieve the
stats when any of the sysfs attribute files are read.
To avoid excessive beating on the stats generation routine in the
drivers, the core code also caches the stats for a short period of
time so that someone attempting to read all of the stats in a
given device's directory will not result in a stats generation
call per file read.
Future work will attempt to standardize just the shared stats
elements, and possibly add a method to get the stats via netlink
in addition to sysfs.
Signed-off-by: Christoph Lameter <cl@linux.com>
Signed-off-by: Mark Bloch <markb@mellanox.com>
Reviewed-by: Steve Wise <swise@opengridcomputing.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
[ Add caching, make structure names more informative, add i40iw support,
other significant rewrites from the original patch ]
2016-05-17 01:49:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t set_stats_lifespan(struct kobject *kobj,
|
|
|
|
struct attribute *attr,
|
|
|
|
const char *buf, size_t count)
|
|
|
|
{
|
|
|
|
struct hw_stats_attribute *hsa;
|
2018-03-27 20:51:05 +08:00
|
|
|
struct rdma_hw_stats *stats;
|
IB/core: Make device counter infrastructure dynamic
In practice, each RDMA device has a unique set of counters that the
hardware implements. Having a central set of counters that they must
all adhere to is limiting and causes many useful counters to not be
available.
Therefore we create a dynamic counter registration infrastructure.
The driver must implement a stats structure allocation routine, in
which the driver must place the directory name it wants, a list of
names for all of the counters, an array of u64 counters themselves,
plus a few generic configuration options.
We then implement a core routine to create a sysfs file for each
of the named stats elements, and a core routine to retrieve the
stats when any of the sysfs attribute files are read.
To avoid excessive beating on the stats generation routine in the
drivers, the core code also caches the stats for a short period of
time so that someone attempting to read all of the stats in a
given device's directory will not result in a stats generation
call per file read.
Future work will attempt to standardize just the shared stats
elements, and possibly add a method to get the stats via netlink
in addition to sysfs.
Signed-off-by: Christoph Lameter <cl@linux.com>
Signed-off-by: Mark Bloch <markb@mellanox.com>
Reviewed-by: Steve Wise <swise@opengridcomputing.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
[ Add caching, make structure names more informative, add i40iw support,
other significant rewrites from the original patch ]
2016-05-17 01:49:33 +08:00
|
|
|
int msecs;
|
|
|
|
int jiffies;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = kstrtoint(buf, 10, &msecs);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
if (msecs < 0 || msecs > 10000)
|
|
|
|
return -EINVAL;
|
|
|
|
jiffies = msecs_to_jiffies(msecs);
|
|
|
|
hsa = container_of(attr, struct hw_stats_attribute, attr);
|
|
|
|
if (!hsa->port_num) {
|
|
|
|
struct ib_device *dev = container_of((struct device *)kobj,
|
|
|
|
struct ib_device, dev);
|
2018-03-27 20:51:05 +08:00
|
|
|
|
|
|
|
stats = dev->hw_stats;
|
IB/core: Make device counter infrastructure dynamic
In practice, each RDMA device has a unique set of counters that the
hardware implements. Having a central set of counters that they must
all adhere to is limiting and causes many useful counters to not be
available.
Therefore we create a dynamic counter registration infrastructure.
The driver must implement a stats structure allocation routine, in
which the driver must place the directory name it wants, a list of
names for all of the counters, an array of u64 counters themselves,
plus a few generic configuration options.
We then implement a core routine to create a sysfs file for each
of the named stats elements, and a core routine to retrieve the
stats when any of the sysfs attribute files are read.
To avoid excessive beating on the stats generation routine in the
drivers, the core code also caches the stats for a short period of
time so that someone attempting to read all of the stats in a
given device's directory will not result in a stats generation
call per file read.
Future work will attempt to standardize just the shared stats
elements, and possibly add a method to get the stats via netlink
in addition to sysfs.
Signed-off-by: Christoph Lameter <cl@linux.com>
Signed-off-by: Mark Bloch <markb@mellanox.com>
Reviewed-by: Steve Wise <swise@opengridcomputing.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
[ Add caching, make structure names more informative, add i40iw support,
other significant rewrites from the original patch ]
2016-05-17 01:49:33 +08:00
|
|
|
} else {
|
|
|
|
struct ib_port *p = container_of(kobj, struct ib_port, kobj);
|
2018-03-27 20:51:05 +08:00
|
|
|
|
|
|
|
stats = p->hw_stats;
|
IB/core: Make device counter infrastructure dynamic
In practice, each RDMA device has a unique set of counters that the
hardware implements. Having a central set of counters that they must
all adhere to is limiting and causes many useful counters to not be
available.
Therefore we create a dynamic counter registration infrastructure.
The driver must implement a stats structure allocation routine, in
which the driver must place the directory name it wants, a list of
names for all of the counters, an array of u64 counters themselves,
plus a few generic configuration options.
We then implement a core routine to create a sysfs file for each
of the named stats elements, and a core routine to retrieve the
stats when any of the sysfs attribute files are read.
To avoid excessive beating on the stats generation routine in the
drivers, the core code also caches the stats for a short period of
time so that someone attempting to read all of the stats in a
given device's directory will not result in a stats generation
call per file read.
Future work will attempt to standardize just the shared stats
elements, and possibly add a method to get the stats via netlink
in addition to sysfs.
Signed-off-by: Christoph Lameter <cl@linux.com>
Signed-off-by: Mark Bloch <markb@mellanox.com>
Reviewed-by: Steve Wise <swise@opengridcomputing.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
[ Add caching, make structure names more informative, add i40iw support,
other significant rewrites from the original patch ]
2016-05-17 01:49:33 +08:00
|
|
|
}
|
2018-03-27 20:51:05 +08:00
|
|
|
|
|
|
|
mutex_lock(&stats->lock);
|
|
|
|
stats->lifespan = jiffies;
|
|
|
|
mutex_unlock(&stats->lock);
|
|
|
|
|
IB/core: Make device counter infrastructure dynamic
In practice, each RDMA device has a unique set of counters that the
hardware implements. Having a central set of counters that they must
all adhere to is limiting and causes many useful counters to not be
available.
Therefore we create a dynamic counter registration infrastructure.
The driver must implement a stats structure allocation routine, in
which the driver must place the directory name it wants, a list of
names for all of the counters, an array of u64 counters themselves,
plus a few generic configuration options.
We then implement a core routine to create a sysfs file for each
of the named stats elements, and a core routine to retrieve the
stats when any of the sysfs attribute files are read.
To avoid excessive beating on the stats generation routine in the
drivers, the core code also caches the stats for a short period of
time so that someone attempting to read all of the stats in a
given device's directory will not result in a stats generation
call per file read.
Future work will attempt to standardize just the shared stats
elements, and possibly add a method to get the stats via netlink
in addition to sysfs.
Signed-off-by: Christoph Lameter <cl@linux.com>
Signed-off-by: Mark Bloch <markb@mellanox.com>
Reviewed-by: Steve Wise <swise@opengridcomputing.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
[ Add caching, make structure names more informative, add i40iw support,
other significant rewrites from the original patch ]
2016-05-17 01:49:33 +08:00
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void free_hsag(struct kobject *kobj, struct attribute_group *attr_group)
|
|
|
|
{
|
|
|
|
struct attribute **attr;
|
|
|
|
|
|
|
|
sysfs_remove_group(kobj, attr_group);
|
|
|
|
|
|
|
|
for (attr = attr_group->attrs; *attr; attr++)
|
|
|
|
kfree(*attr);
|
|
|
|
kfree(attr_group);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct attribute *alloc_hsa(int index, u8 port_num, const char *name)
|
|
|
|
{
|
|
|
|
struct hw_stats_attribute *hsa;
|
|
|
|
|
|
|
|
hsa = kmalloc(sizeof(*hsa), GFP_KERNEL);
|
|
|
|
if (!hsa)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
hsa->attr.name = (char *)name;
|
|
|
|
hsa->attr.mode = S_IRUGO;
|
|
|
|
hsa->show = show_hw_stats;
|
|
|
|
hsa->store = NULL;
|
|
|
|
hsa->index = index;
|
|
|
|
hsa->port_num = port_num;
|
|
|
|
|
|
|
|
return &hsa->attr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct attribute *alloc_hsa_lifespan(char *name, u8 port_num)
|
|
|
|
{
|
|
|
|
struct hw_stats_attribute *hsa;
|
|
|
|
|
|
|
|
hsa = kmalloc(sizeof(*hsa), GFP_KERNEL);
|
|
|
|
if (!hsa)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
hsa->attr.name = name;
|
|
|
|
hsa->attr.mode = S_IWUSR | S_IRUGO;
|
|
|
|
hsa->show = show_stats_lifespan;
|
|
|
|
hsa->store = set_stats_lifespan;
|
|
|
|
hsa->index = 0;
|
|
|
|
hsa->port_num = port_num;
|
|
|
|
|
|
|
|
return &hsa->attr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void setup_hw_stats(struct ib_device *device, struct ib_port *port,
|
|
|
|
u8 port_num)
|
|
|
|
{
|
2016-06-07 19:43:46 +08:00
|
|
|
struct attribute_group *hsag;
|
IB/core: Make device counter infrastructure dynamic
In practice, each RDMA device has a unique set of counters that the
hardware implements. Having a central set of counters that they must
all adhere to is limiting and causes many useful counters to not be
available.
Therefore we create a dynamic counter registration infrastructure.
The driver must implement a stats structure allocation routine, in
which the driver must place the directory name it wants, a list of
names for all of the counters, an array of u64 counters themselves,
plus a few generic configuration options.
We then implement a core routine to create a sysfs file for each
of the named stats elements, and a core routine to retrieve the
stats when any of the sysfs attribute files are read.
To avoid excessive beating on the stats generation routine in the
drivers, the core code also caches the stats for a short period of
time so that someone attempting to read all of the stats in a
given device's directory will not result in a stats generation
call per file read.
Future work will attempt to standardize just the shared stats
elements, and possibly add a method to get the stats via netlink
in addition to sysfs.
Signed-off-by: Christoph Lameter <cl@linux.com>
Signed-off-by: Mark Bloch <markb@mellanox.com>
Reviewed-by: Steve Wise <swise@opengridcomputing.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
[ Add caching, make structure names more informative, add i40iw support,
other significant rewrites from the original patch ]
2016-05-17 01:49:33 +08:00
|
|
|
struct rdma_hw_stats *stats;
|
2016-06-07 19:43:46 +08:00
|
|
|
int i, ret;
|
IB/core: Make device counter infrastructure dynamic
In practice, each RDMA device has a unique set of counters that the
hardware implements. Having a central set of counters that they must
all adhere to is limiting and causes many useful counters to not be
available.
Therefore we create a dynamic counter registration infrastructure.
The driver must implement a stats structure allocation routine, in
which the driver must place the directory name it wants, a list of
names for all of the counters, an array of u64 counters themselves,
plus a few generic configuration options.
We then implement a core routine to create a sysfs file for each
of the named stats elements, and a core routine to retrieve the
stats when any of the sysfs attribute files are read.
To avoid excessive beating on the stats generation routine in the
drivers, the core code also caches the stats for a short period of
time so that someone attempting to read all of the stats in a
given device's directory will not result in a stats generation
call per file read.
Future work will attempt to standardize just the shared stats
elements, and possibly add a method to get the stats via netlink
in addition to sysfs.
Signed-off-by: Christoph Lameter <cl@linux.com>
Signed-off-by: Mark Bloch <markb@mellanox.com>
Reviewed-by: Steve Wise <swise@opengridcomputing.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
[ Add caching, make structure names more informative, add i40iw support,
other significant rewrites from the original patch ]
2016-05-17 01:49:33 +08:00
|
|
|
|
2018-12-11 03:09:48 +08:00
|
|
|
stats = device->ops.alloc_hw_stats(device, port_num);
|
IB/core: Make device counter infrastructure dynamic
In practice, each RDMA device has a unique set of counters that the
hardware implements. Having a central set of counters that they must
all adhere to is limiting and causes many useful counters to not be
available.
Therefore we create a dynamic counter registration infrastructure.
The driver must implement a stats structure allocation routine, in
which the driver must place the directory name it wants, a list of
names for all of the counters, an array of u64 counters themselves,
plus a few generic configuration options.
We then implement a core routine to create a sysfs file for each
of the named stats elements, and a core routine to retrieve the
stats when any of the sysfs attribute files are read.
To avoid excessive beating on the stats generation routine in the
drivers, the core code also caches the stats for a short period of
time so that someone attempting to read all of the stats in a
given device's directory will not result in a stats generation
call per file read.
Future work will attempt to standardize just the shared stats
elements, and possibly add a method to get the stats via netlink
in addition to sysfs.
Signed-off-by: Christoph Lameter <cl@linux.com>
Signed-off-by: Mark Bloch <markb@mellanox.com>
Reviewed-by: Steve Wise <swise@opengridcomputing.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
[ Add caching, make structure names more informative, add i40iw support,
other significant rewrites from the original patch ]
2016-05-17 01:49:33 +08:00
|
|
|
|
|
|
|
if (!stats)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!stats->names || stats->num_counters <= 0)
|
2016-06-02 02:06:36 +08:00
|
|
|
goto err_free_stats;
|
IB/core: Make device counter infrastructure dynamic
In practice, each RDMA device has a unique set of counters that the
hardware implements. Having a central set of counters that they must
all adhere to is limiting and causes many useful counters to not be
available.
Therefore we create a dynamic counter registration infrastructure.
The driver must implement a stats structure allocation routine, in
which the driver must place the directory name it wants, a list of
names for all of the counters, an array of u64 counters themselves,
plus a few generic configuration options.
We then implement a core routine to create a sysfs file for each
of the named stats elements, and a core routine to retrieve the
stats when any of the sysfs attribute files are read.
To avoid excessive beating on the stats generation routine in the
drivers, the core code also caches the stats for a short period of
time so that someone attempting to read all of the stats in a
given device's directory will not result in a stats generation
call per file read.
Future work will attempt to standardize just the shared stats
elements, and possibly add a method to get the stats via netlink
in addition to sysfs.
Signed-off-by: Christoph Lameter <cl@linux.com>
Signed-off-by: Mark Bloch <markb@mellanox.com>
Reviewed-by: Steve Wise <swise@opengridcomputing.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
[ Add caching, make structure names more informative, add i40iw support,
other significant rewrites from the original patch ]
2016-05-17 01:49:33 +08:00
|
|
|
|
2016-06-07 07:52:55 +08:00
|
|
|
/*
|
|
|
|
* Two extra attribue elements here, one for the lifespan entry and
|
|
|
|
* one to NULL terminate the list for the sysfs core code
|
|
|
|
*/
|
IB/core: Make device counter infrastructure dynamic
In practice, each RDMA device has a unique set of counters that the
hardware implements. Having a central set of counters that they must
all adhere to is limiting and causes many useful counters to not be
available.
Therefore we create a dynamic counter registration infrastructure.
The driver must implement a stats structure allocation routine, in
which the driver must place the directory name it wants, a list of
names for all of the counters, an array of u64 counters themselves,
plus a few generic configuration options.
We then implement a core routine to create a sysfs file for each
of the named stats elements, and a core routine to retrieve the
stats when any of the sysfs attribute files are read.
To avoid excessive beating on the stats generation routine in the
drivers, the core code also caches the stats for a short period of
time so that someone attempting to read all of the stats in a
given device's directory will not result in a stats generation
call per file read.
Future work will attempt to standardize just the shared stats
elements, and possibly add a method to get the stats via netlink
in addition to sysfs.
Signed-off-by: Christoph Lameter <cl@linux.com>
Signed-off-by: Mark Bloch <markb@mellanox.com>
Reviewed-by: Steve Wise <swise@opengridcomputing.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
[ Add caching, make structure names more informative, add i40iw support,
other significant rewrites from the original patch ]
2016-05-17 01:49:33 +08:00
|
|
|
hsag = kzalloc(sizeof(*hsag) +
|
2016-06-07 07:52:55 +08:00
|
|
|
sizeof(void *) * (stats->num_counters + 2),
|
IB/core: Make device counter infrastructure dynamic
In practice, each RDMA device has a unique set of counters that the
hardware implements. Having a central set of counters that they must
all adhere to is limiting and causes many useful counters to not be
available.
Therefore we create a dynamic counter registration infrastructure.
The driver must implement a stats structure allocation routine, in
which the driver must place the directory name it wants, a list of
names for all of the counters, an array of u64 counters themselves,
plus a few generic configuration options.
We then implement a core routine to create a sysfs file for each
of the named stats elements, and a core routine to retrieve the
stats when any of the sysfs attribute files are read.
To avoid excessive beating on the stats generation routine in the
drivers, the core code also caches the stats for a short period of
time so that someone attempting to read all of the stats in a
given device's directory will not result in a stats generation
call per file read.
Future work will attempt to standardize just the shared stats
elements, and possibly add a method to get the stats via netlink
in addition to sysfs.
Signed-off-by: Christoph Lameter <cl@linux.com>
Signed-off-by: Mark Bloch <markb@mellanox.com>
Reviewed-by: Steve Wise <swise@opengridcomputing.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
[ Add caching, make structure names more informative, add i40iw support,
other significant rewrites from the original patch ]
2016-05-17 01:49:33 +08:00
|
|
|
GFP_KERNEL);
|
|
|
|
if (!hsag)
|
2016-06-02 02:06:36 +08:00
|
|
|
goto err_free_stats;
|
IB/core: Make device counter infrastructure dynamic
In practice, each RDMA device has a unique set of counters that the
hardware implements. Having a central set of counters that they must
all adhere to is limiting and causes many useful counters to not be
available.
Therefore we create a dynamic counter registration infrastructure.
The driver must implement a stats structure allocation routine, in
which the driver must place the directory name it wants, a list of
names for all of the counters, an array of u64 counters themselves,
plus a few generic configuration options.
We then implement a core routine to create a sysfs file for each
of the named stats elements, and a core routine to retrieve the
stats when any of the sysfs attribute files are read.
To avoid excessive beating on the stats generation routine in the
drivers, the core code also caches the stats for a short period of
time so that someone attempting to read all of the stats in a
given device's directory will not result in a stats generation
call per file read.
Future work will attempt to standardize just the shared stats
elements, and possibly add a method to get the stats via netlink
in addition to sysfs.
Signed-off-by: Christoph Lameter <cl@linux.com>
Signed-off-by: Mark Bloch <markb@mellanox.com>
Reviewed-by: Steve Wise <swise@opengridcomputing.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
[ Add caching, make structure names more informative, add i40iw support,
other significant rewrites from the original patch ]
2016-05-17 01:49:33 +08:00
|
|
|
|
2018-12-11 03:09:48 +08:00
|
|
|
ret = device->ops.get_hw_stats(device, stats, port_num,
|
|
|
|
stats->num_counters);
|
IB/core: Make device counter infrastructure dynamic
In practice, each RDMA device has a unique set of counters that the
hardware implements. Having a central set of counters that they must
all adhere to is limiting and causes many useful counters to not be
available.
Therefore we create a dynamic counter registration infrastructure.
The driver must implement a stats structure allocation routine, in
which the driver must place the directory name it wants, a list of
names for all of the counters, an array of u64 counters themselves,
plus a few generic configuration options.
We then implement a core routine to create a sysfs file for each
of the named stats elements, and a core routine to retrieve the
stats when any of the sysfs attribute files are read.
To avoid excessive beating on the stats generation routine in the
drivers, the core code also caches the stats for a short period of
time so that someone attempting to read all of the stats in a
given device's directory will not result in a stats generation
call per file read.
Future work will attempt to standardize just the shared stats
elements, and possibly add a method to get the stats via netlink
in addition to sysfs.
Signed-off-by: Christoph Lameter <cl@linux.com>
Signed-off-by: Mark Bloch <markb@mellanox.com>
Reviewed-by: Steve Wise <swise@opengridcomputing.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
[ Add caching, make structure names more informative, add i40iw support,
other significant rewrites from the original patch ]
2016-05-17 01:49:33 +08:00
|
|
|
if (ret != stats->num_counters)
|
2016-06-07 19:43:46 +08:00
|
|
|
goto err_free_hsag;
|
IB/core: Make device counter infrastructure dynamic
In practice, each RDMA device has a unique set of counters that the
hardware implements. Having a central set of counters that they must
all adhere to is limiting and causes many useful counters to not be
available.
Therefore we create a dynamic counter registration infrastructure.
The driver must implement a stats structure allocation routine, in
which the driver must place the directory name it wants, a list of
names for all of the counters, an array of u64 counters themselves,
plus a few generic configuration options.
We then implement a core routine to create a sysfs file for each
of the named stats elements, and a core routine to retrieve the
stats when any of the sysfs attribute files are read.
To avoid excessive beating on the stats generation routine in the
drivers, the core code also caches the stats for a short period of
time so that someone attempting to read all of the stats in a
given device's directory will not result in a stats generation
call per file read.
Future work will attempt to standardize just the shared stats
elements, and possibly add a method to get the stats via netlink
in addition to sysfs.
Signed-off-by: Christoph Lameter <cl@linux.com>
Signed-off-by: Mark Bloch <markb@mellanox.com>
Reviewed-by: Steve Wise <swise@opengridcomputing.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
[ Add caching, make structure names more informative, add i40iw support,
other significant rewrites from the original patch ]
2016-05-17 01:49:33 +08:00
|
|
|
|
|
|
|
stats->timestamp = jiffies;
|
|
|
|
|
|
|
|
hsag->name = "hw_counters";
|
|
|
|
hsag->attrs = (void *)hsag + sizeof(*hsag);
|
|
|
|
|
|
|
|
for (i = 0; i < stats->num_counters; i++) {
|
|
|
|
hsag->attrs[i] = alloc_hsa(i, port_num, stats->names[i]);
|
|
|
|
if (!hsag->attrs[i])
|
|
|
|
goto err;
|
2016-06-04 20:15:24 +08:00
|
|
|
sysfs_attr_init(hsag->attrs[i]);
|
IB/core: Make device counter infrastructure dynamic
In practice, each RDMA device has a unique set of counters that the
hardware implements. Having a central set of counters that they must
all adhere to is limiting and causes many useful counters to not be
available.
Therefore we create a dynamic counter registration infrastructure.
The driver must implement a stats structure allocation routine, in
which the driver must place the directory name it wants, a list of
names for all of the counters, an array of u64 counters themselves,
plus a few generic configuration options.
We then implement a core routine to create a sysfs file for each
of the named stats elements, and a core routine to retrieve the
stats when any of the sysfs attribute files are read.
To avoid excessive beating on the stats generation routine in the
drivers, the core code also caches the stats for a short period of
time so that someone attempting to read all of the stats in a
given device's directory will not result in a stats generation
call per file read.
Future work will attempt to standardize just the shared stats
elements, and possibly add a method to get the stats via netlink
in addition to sysfs.
Signed-off-by: Christoph Lameter <cl@linux.com>
Signed-off-by: Mark Bloch <markb@mellanox.com>
Reviewed-by: Steve Wise <swise@opengridcomputing.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
[ Add caching, make structure names more informative, add i40iw support,
other significant rewrites from the original patch ]
2016-05-17 01:49:33 +08:00
|
|
|
}
|
|
|
|
|
2018-03-27 20:51:05 +08:00
|
|
|
mutex_init(&stats->lock);
|
IB/core: Make device counter infrastructure dynamic
In practice, each RDMA device has a unique set of counters that the
hardware implements. Having a central set of counters that they must
all adhere to is limiting and causes many useful counters to not be
available.
Therefore we create a dynamic counter registration infrastructure.
The driver must implement a stats structure allocation routine, in
which the driver must place the directory name it wants, a list of
names for all of the counters, an array of u64 counters themselves,
plus a few generic configuration options.
We then implement a core routine to create a sysfs file for each
of the named stats elements, and a core routine to retrieve the
stats when any of the sysfs attribute files are read.
To avoid excessive beating on the stats generation routine in the
drivers, the core code also caches the stats for a short period of
time so that someone attempting to read all of the stats in a
given device's directory will not result in a stats generation
call per file read.
Future work will attempt to standardize just the shared stats
elements, and possibly add a method to get the stats via netlink
in addition to sysfs.
Signed-off-by: Christoph Lameter <cl@linux.com>
Signed-off-by: Mark Bloch <markb@mellanox.com>
Reviewed-by: Steve Wise <swise@opengridcomputing.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
[ Add caching, make structure names more informative, add i40iw support,
other significant rewrites from the original patch ]
2016-05-17 01:49:33 +08:00
|
|
|
/* treat an error here as non-fatal */
|
|
|
|
hsag->attrs[i] = alloc_hsa_lifespan("lifespan", port_num);
|
2016-06-04 20:15:24 +08:00
|
|
|
if (hsag->attrs[i])
|
|
|
|
sysfs_attr_init(hsag->attrs[i]);
|
IB/core: Make device counter infrastructure dynamic
In practice, each RDMA device has a unique set of counters that the
hardware implements. Having a central set of counters that they must
all adhere to is limiting and causes many useful counters to not be
available.
Therefore we create a dynamic counter registration infrastructure.
The driver must implement a stats structure allocation routine, in
which the driver must place the directory name it wants, a list of
names for all of the counters, an array of u64 counters themselves,
plus a few generic configuration options.
We then implement a core routine to create a sysfs file for each
of the named stats elements, and a core routine to retrieve the
stats when any of the sysfs attribute files are read.
To avoid excessive beating on the stats generation routine in the
drivers, the core code also caches the stats for a short period of
time so that someone attempting to read all of the stats in a
given device's directory will not result in a stats generation
call per file read.
Future work will attempt to standardize just the shared stats
elements, and possibly add a method to get the stats via netlink
in addition to sysfs.
Signed-off-by: Christoph Lameter <cl@linux.com>
Signed-off-by: Mark Bloch <markb@mellanox.com>
Reviewed-by: Steve Wise <swise@opengridcomputing.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
[ Add caching, make structure names more informative, add i40iw support,
other significant rewrites from the original patch ]
2016-05-17 01:49:33 +08:00
|
|
|
|
|
|
|
if (port) {
|
|
|
|
struct kobject *kobj = &port->kobj;
|
|
|
|
ret = sysfs_create_group(kobj, hsag);
|
|
|
|
if (ret)
|
|
|
|
goto err;
|
|
|
|
port->hw_stats_ag = hsag;
|
|
|
|
port->hw_stats = stats;
|
2019-07-02 18:02:46 +08:00
|
|
|
if (device->port_data)
|
|
|
|
device->port_data[port_num].hw_stats = stats;
|
IB/core: Make device counter infrastructure dynamic
In practice, each RDMA device has a unique set of counters that the
hardware implements. Having a central set of counters that they must
all adhere to is limiting and causes many useful counters to not be
available.
Therefore we create a dynamic counter registration infrastructure.
The driver must implement a stats structure allocation routine, in
which the driver must place the directory name it wants, a list of
names for all of the counters, an array of u64 counters themselves,
plus a few generic configuration options.
We then implement a core routine to create a sysfs file for each
of the named stats elements, and a core routine to retrieve the
stats when any of the sysfs attribute files are read.
To avoid excessive beating on the stats generation routine in the
drivers, the core code also caches the stats for a short period of
time so that someone attempting to read all of the stats in a
given device's directory will not result in a stats generation
call per file read.
Future work will attempt to standardize just the shared stats
elements, and possibly add a method to get the stats via netlink
in addition to sysfs.
Signed-off-by: Christoph Lameter <cl@linux.com>
Signed-off-by: Mark Bloch <markb@mellanox.com>
Reviewed-by: Steve Wise <swise@opengridcomputing.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
[ Add caching, make structure names more informative, add i40iw support,
other significant rewrites from the original patch ]
2016-05-17 01:49:33 +08:00
|
|
|
} else {
|
|
|
|
struct kobject *kobj = &device->dev.kobj;
|
|
|
|
ret = sysfs_create_group(kobj, hsag);
|
|
|
|
if (ret)
|
|
|
|
goto err;
|
|
|
|
device->hw_stats_ag = hsag;
|
|
|
|
device->hw_stats = stats;
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
err:
|
|
|
|
for (; i >= 0; i--)
|
|
|
|
kfree(hsag->attrs[i]);
|
2016-06-07 19:43:46 +08:00
|
|
|
err_free_hsag:
|
IB/core: Make device counter infrastructure dynamic
In practice, each RDMA device has a unique set of counters that the
hardware implements. Having a central set of counters that they must
all adhere to is limiting and causes many useful counters to not be
available.
Therefore we create a dynamic counter registration infrastructure.
The driver must implement a stats structure allocation routine, in
which the driver must place the directory name it wants, a list of
names for all of the counters, an array of u64 counters themselves,
plus a few generic configuration options.
We then implement a core routine to create a sysfs file for each
of the named stats elements, and a core routine to retrieve the
stats when any of the sysfs attribute files are read.
To avoid excessive beating on the stats generation routine in the
drivers, the core code also caches the stats for a short period of
time so that someone attempting to read all of the stats in a
given device's directory will not result in a stats generation
call per file read.
Future work will attempt to standardize just the shared stats
elements, and possibly add a method to get the stats via netlink
in addition to sysfs.
Signed-off-by: Christoph Lameter <cl@linux.com>
Signed-off-by: Mark Bloch <markb@mellanox.com>
Reviewed-by: Steve Wise <swise@opengridcomputing.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
[ Add caching, make structure names more informative, add i40iw support,
other significant rewrites from the original patch ]
2016-05-17 01:49:33 +08:00
|
|
|
kfree(hsag);
|
2016-06-02 02:06:36 +08:00
|
|
|
err_free_stats:
|
|
|
|
kfree(stats);
|
IB/core: Make device counter infrastructure dynamic
In practice, each RDMA device has a unique set of counters that the
hardware implements. Having a central set of counters that they must
all adhere to is limiting and causes many useful counters to not be
available.
Therefore we create a dynamic counter registration infrastructure.
The driver must implement a stats structure allocation routine, in
which the driver must place the directory name it wants, a list of
names for all of the counters, an array of u64 counters themselves,
plus a few generic configuration options.
We then implement a core routine to create a sysfs file for each
of the named stats elements, and a core routine to retrieve the
stats when any of the sysfs attribute files are read.
To avoid excessive beating on the stats generation routine in the
drivers, the core code also caches the stats for a short period of
time so that someone attempting to read all of the stats in a
given device's directory will not result in a stats generation
call per file read.
Future work will attempt to standardize just the shared stats
elements, and possibly add a method to get the stats via netlink
in addition to sysfs.
Signed-off-by: Christoph Lameter <cl@linux.com>
Signed-off-by: Mark Bloch <markb@mellanox.com>
Reviewed-by: Steve Wise <swise@opengridcomputing.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
[ Add caching, make structure names more informative, add i40iw support,
other significant rewrites from the original patch ]
2016-05-17 01:49:33 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-05-01 13:46:55 +08:00
|
|
|
static int add_port(struct ib_core_device *coredev, int port_num)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2019-02-26 19:56:11 +08:00
|
|
|
struct ib_device *device = rdma_device_to_ibdev(&coredev->dev);
|
2019-05-01 13:46:55 +08:00
|
|
|
bool is_full_dev = &device->coredev == coredev;
|
2005-04-17 06:20:36 +08:00
|
|
|
struct ib_port *p;
|
|
|
|
struct ib_port_attr attr;
|
|
|
|
int i;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = ib_query_port(device, port_num, &attr);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2005-11-02 23:23:14 +08:00
|
|
|
p = kzalloc(sizeof *p, GFP_KERNEL);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!p)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
p->ibdev = device;
|
|
|
|
p->port_num = port_num;
|
|
|
|
|
2007-12-18 03:54:39 +08:00
|
|
|
ret = kobject_init_and_add(&p->kobj, &port_type,
|
2019-02-26 19:56:11 +08:00
|
|
|
coredev->ports_kobj,
|
2007-12-18 03:54:39 +08:00
|
|
|
"%d", port_num);
|
2014-05-18 16:12:25 +08:00
|
|
|
if (ret) {
|
2020-05-28 11:02:30 +08:00
|
|
|
goto err_put;
|
2014-05-18 16:12:25 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2015-12-23 20:56:49 +08:00
|
|
|
p->gid_attr_group = kzalloc(sizeof(*p->gid_attr_group), GFP_KERNEL);
|
|
|
|
if (!p->gid_attr_group) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto err_put;
|
|
|
|
}
|
|
|
|
|
|
|
|
p->gid_attr_group->port = p;
|
|
|
|
ret = kobject_init_and_add(&p->gid_attr_group->kobj, &gid_attr_type,
|
|
|
|
&p->kobj, "gid_attrs");
|
|
|
|
if (ret) {
|
2020-05-28 11:02:30 +08:00
|
|
|
goto err_put_gid_attrs;
|
2015-12-23 20:56:49 +08:00
|
|
|
}
|
|
|
|
|
2019-05-01 13:46:55 +08:00
|
|
|
if (device->ops.process_mad && is_full_dev) {
|
2018-10-07 17:12:40 +08:00
|
|
|
p->pma_table = get_counter_table(device, port_num);
|
|
|
|
ret = sysfs_create_group(&p->kobj, p->pma_table);
|
|
|
|
if (ret)
|
|
|
|
goto err_put_gid_attrs;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
p->gid_group.name = "gids";
|
2005-04-29 13:58:46 +08:00
|
|
|
p->gid_group.attrs = alloc_group_attrs(show_port_gid, attr.gid_tbl_len);
|
2013-06-21 11:24:27 +08:00
|
|
|
if (!p->gid_group.attrs) {
|
|
|
|
ret = -ENOMEM;
|
2005-04-29 13:58:46 +08:00
|
|
|
goto err_remove_pma;
|
2013-06-21 11:24:27 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
ret = sysfs_create_group(&p->kobj, &p->gid_group);
|
|
|
|
if (ret)
|
|
|
|
goto err_free_gid;
|
|
|
|
|
2015-12-23 20:56:49 +08:00
|
|
|
p->gid_attr_group->ndev.name = "ndevs";
|
|
|
|
p->gid_attr_group->ndev.attrs = alloc_group_attrs(show_port_gid_attr_ndev,
|
|
|
|
attr.gid_tbl_len);
|
|
|
|
if (!p->gid_attr_group->ndev.attrs) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto err_remove_gid;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = sysfs_create_group(&p->gid_attr_group->kobj,
|
|
|
|
&p->gid_attr_group->ndev);
|
|
|
|
if (ret)
|
|
|
|
goto err_free_gid_ndev;
|
|
|
|
|
|
|
|
p->gid_attr_group->type.name = "types";
|
|
|
|
p->gid_attr_group->type.attrs = alloc_group_attrs(show_port_gid_attr_gid_type,
|
|
|
|
attr.gid_tbl_len);
|
|
|
|
if (!p->gid_attr_group->type.attrs) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto err_remove_gid_ndev;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = sysfs_create_group(&p->gid_attr_group->kobj,
|
|
|
|
&p->gid_attr_group->type);
|
|
|
|
if (ret)
|
|
|
|
goto err_free_gid_type;
|
|
|
|
|
2020-07-15 02:34:08 +08:00
|
|
|
if (attr.pkey_tbl_len) {
|
|
|
|
p->pkey_group = kzalloc(sizeof(*p->pkey_group), GFP_KERNEL);
|
|
|
|
if (!p->pkey_group) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto err_remove_gid_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
p->pkey_group->name = "pkeys";
|
|
|
|
p->pkey_group->attrs = alloc_group_attrs(show_port_pkey,
|
|
|
|
attr.pkey_tbl_len);
|
|
|
|
if (!p->pkey_group->attrs) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto err_free_pkey_group;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = sysfs_create_group(&p->kobj, p->pkey_group);
|
|
|
|
if (ret)
|
|
|
|
goto err_free_pkey;
|
2013-06-21 11:24:27 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
|
2019-05-01 13:46:55 +08:00
|
|
|
if (device->ops.init_port && is_full_dev) {
|
2018-12-18 20:28:30 +08:00
|
|
|
ret = device->ops.init_port(device, port_num, &p->kobj);
|
2010-05-07 08:03:25 +08:00
|
|
|
if (ret)
|
|
|
|
goto err_remove_pkey;
|
|
|
|
}
|
|
|
|
|
IB/core: Make device counter infrastructure dynamic
In practice, each RDMA device has a unique set of counters that the
hardware implements. Having a central set of counters that they must
all adhere to is limiting and causes many useful counters to not be
available.
Therefore we create a dynamic counter registration infrastructure.
The driver must implement a stats structure allocation routine, in
which the driver must place the directory name it wants, a list of
names for all of the counters, an array of u64 counters themselves,
plus a few generic configuration options.
We then implement a core routine to create a sysfs file for each
of the named stats elements, and a core routine to retrieve the
stats when any of the sysfs attribute files are read.
To avoid excessive beating on the stats generation routine in the
drivers, the core code also caches the stats for a short period of
time so that someone attempting to read all of the stats in a
given device's directory will not result in a stats generation
call per file read.
Future work will attempt to standardize just the shared stats
elements, and possibly add a method to get the stats via netlink
in addition to sysfs.
Signed-off-by: Christoph Lameter <cl@linux.com>
Signed-off-by: Mark Bloch <markb@mellanox.com>
Reviewed-by: Steve Wise <swise@opengridcomputing.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
[ Add caching, make structure names more informative, add i40iw support,
other significant rewrites from the original patch ]
2016-05-17 01:49:33 +08:00
|
|
|
/*
|
2018-10-17 18:21:08 +08:00
|
|
|
* If port == 0, it means hw_counters are per device and not per
|
|
|
|
* port, so holder should be device. Therefore skip per port conunter
|
|
|
|
* initialization.
|
IB/core: Make device counter infrastructure dynamic
In practice, each RDMA device has a unique set of counters that the
hardware implements. Having a central set of counters that they must
all adhere to is limiting and causes many useful counters to not be
available.
Therefore we create a dynamic counter registration infrastructure.
The driver must implement a stats structure allocation routine, in
which the driver must place the directory name it wants, a list of
names for all of the counters, an array of u64 counters themselves,
plus a few generic configuration options.
We then implement a core routine to create a sysfs file for each
of the named stats elements, and a core routine to retrieve the
stats when any of the sysfs attribute files are read.
To avoid excessive beating on the stats generation routine in the
drivers, the core code also caches the stats for a short period of
time so that someone attempting to read all of the stats in a
given device's directory will not result in a stats generation
call per file read.
Future work will attempt to standardize just the shared stats
elements, and possibly add a method to get the stats via netlink
in addition to sysfs.
Signed-off-by: Christoph Lameter <cl@linux.com>
Signed-off-by: Mark Bloch <markb@mellanox.com>
Reviewed-by: Steve Wise <swise@opengridcomputing.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
[ Add caching, make structure names more informative, add i40iw support,
other significant rewrites from the original patch ]
2016-05-17 01:49:33 +08:00
|
|
|
*/
|
2019-05-01 13:46:55 +08:00
|
|
|
if (device->ops.alloc_hw_stats && port_num && is_full_dev)
|
IB/core: Make device counter infrastructure dynamic
In practice, each RDMA device has a unique set of counters that the
hardware implements. Having a central set of counters that they must
all adhere to is limiting and causes many useful counters to not be
available.
Therefore we create a dynamic counter registration infrastructure.
The driver must implement a stats structure allocation routine, in
which the driver must place the directory name it wants, a list of
names for all of the counters, an array of u64 counters themselves,
plus a few generic configuration options.
We then implement a core routine to create a sysfs file for each
of the named stats elements, and a core routine to retrieve the
stats when any of the sysfs attribute files are read.
To avoid excessive beating on the stats generation routine in the
drivers, the core code also caches the stats for a short period of
time so that someone attempting to read all of the stats in a
given device's directory will not result in a stats generation
call per file read.
Future work will attempt to standardize just the shared stats
elements, and possibly add a method to get the stats via netlink
in addition to sysfs.
Signed-off-by: Christoph Lameter <cl@linux.com>
Signed-off-by: Mark Bloch <markb@mellanox.com>
Reviewed-by: Steve Wise <swise@opengridcomputing.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
[ Add caching, make structure names more informative, add i40iw support,
other significant rewrites from the original patch ]
2016-05-17 01:49:33 +08:00
|
|
|
setup_hw_stats(device, p, port_num);
|
|
|
|
|
2019-02-26 19:56:11 +08:00
|
|
|
list_add_tail(&p->kobj.entry, &coredev->port_list);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-12-18 03:54:39 +08:00
|
|
|
kobject_uevent(&p->kobj, KOBJ_ADD);
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
|
2010-05-07 08:03:25 +08:00
|
|
|
err_remove_pkey:
|
2020-07-15 02:34:08 +08:00
|
|
|
if (p->pkey_group)
|
|
|
|
sysfs_remove_group(&p->kobj, p->pkey_group);
|
2010-05-07 08:03:25 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
err_free_pkey:
|
2020-07-15 02:34:08 +08:00
|
|
|
if (p->pkey_group) {
|
|
|
|
for (i = 0; i < attr.pkey_tbl_len; ++i)
|
|
|
|
kfree(p->pkey_group->attrs[i]);
|
|
|
|
|
|
|
|
kfree(p->pkey_group->attrs);
|
|
|
|
p->pkey_group->attrs = NULL;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2020-07-15 02:34:08 +08:00
|
|
|
err_free_pkey_group:
|
|
|
|
kfree(p->pkey_group);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2015-12-23 20:56:49 +08:00
|
|
|
err_remove_gid_type:
|
|
|
|
sysfs_remove_group(&p->gid_attr_group->kobj,
|
|
|
|
&p->gid_attr_group->type);
|
|
|
|
|
|
|
|
err_free_gid_type:
|
|
|
|
for (i = 0; i < attr.gid_tbl_len; ++i)
|
|
|
|
kfree(p->gid_attr_group->type.attrs[i]);
|
|
|
|
|
|
|
|
kfree(p->gid_attr_group->type.attrs);
|
|
|
|
p->gid_attr_group->type.attrs = NULL;
|
|
|
|
|
|
|
|
err_remove_gid_ndev:
|
|
|
|
sysfs_remove_group(&p->gid_attr_group->kobj,
|
|
|
|
&p->gid_attr_group->ndev);
|
|
|
|
|
|
|
|
err_free_gid_ndev:
|
|
|
|
for (i = 0; i < attr.gid_tbl_len; ++i)
|
|
|
|
kfree(p->gid_attr_group->ndev.attrs[i]);
|
|
|
|
|
|
|
|
kfree(p->gid_attr_group->ndev.attrs);
|
|
|
|
p->gid_attr_group->ndev.attrs = NULL;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
err_remove_gid:
|
|
|
|
sysfs_remove_group(&p->kobj, &p->gid_group);
|
|
|
|
|
|
|
|
err_free_gid:
|
2005-04-29 13:58:46 +08:00
|
|
|
for (i = 0; i < attr.gid_tbl_len; ++i)
|
|
|
|
kfree(p->gid_group.attrs[i]);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-04-29 13:58:46 +08:00
|
|
|
kfree(p->gid_group.attrs);
|
2014-05-18 16:12:25 +08:00
|
|
|
p->gid_group.attrs = NULL;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
err_remove_pma:
|
2018-10-07 17:12:40 +08:00
|
|
|
if (p->pma_table)
|
|
|
|
sysfs_remove_group(&p->kobj, p->pma_table);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2015-12-23 20:56:49 +08:00
|
|
|
err_put_gid_attrs:
|
|
|
|
kobject_put(&p->gid_attr_group->kobj);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
err_put:
|
2014-05-18 16:12:25 +08:00
|
|
|
kobject_put(&p->kobj);
|
2005-04-17 06:20:36 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-10-08 10:36:26 +08:00
|
|
|
static const char *node_type_string(int node_type)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2020-10-08 10:36:26 +08:00
|
|
|
switch (node_type) {
|
RDMA: Convert sysfs device * show functions to use sysfs_emit()
Done with cocci script:
@@
identifier d_show;
identifier dev, attr, buf;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
return
- sprintf(buf,
+ sysfs_emit(buf,
...);
...>
}
@@
identifier d_show;
identifier dev, attr, buf;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
return
- snprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
}
@@
identifier d_show;
identifier dev, attr, buf;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
return
- scnprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
}
@@
identifier d_show;
identifier dev, attr, buf;
expression chr;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
return
- strcpy(buf, chr);
+ sysfs_emit(buf, chr);
...>
}
@@
identifier d_show;
identifier dev, attr, buf;
identifier len;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
len =
- sprintf(buf,
+ sysfs_emit(buf,
...);
...>
return len;
}
@@
identifier d_show;
identifier dev, attr, buf;
identifier len;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
len =
- snprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
return len;
}
@@
identifier d_show;
identifier dev, attr, buf;
identifier len;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
len =
- scnprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
return len;
}
@@
identifier d_show;
identifier dev, attr, buf;
identifier len;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
- len += scnprintf(buf + len, PAGE_SIZE - len,
+ len += sysfs_emit_at(buf, len,
...);
...>
return len;
}
@@
identifier d_show;
identifier dev, attr, buf;
expression chr;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
...
- strcpy(buf, chr);
- return strlen(buf);
+ return sysfs_emit(buf, chr);
}
Link: https://lore.kernel.org/r/7f406fa8e3aa2552c022bec680f621e38d1fe414.1602122879.git.joe@perches.com
Signed-off-by: Joe Perches <joe@perches.com>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
2020-10-08 10:36:24 +08:00
|
|
|
case RDMA_NODE_IB_CA:
|
2020-10-08 10:36:26 +08:00
|
|
|
return "CA";
|
|
|
|
case RDMA_NODE_IB_SWITCH:
|
|
|
|
return "switch";
|
|
|
|
case RDMA_NODE_IB_ROUTER:
|
|
|
|
return "router";
|
RDMA: Convert sysfs device * show functions to use sysfs_emit()
Done with cocci script:
@@
identifier d_show;
identifier dev, attr, buf;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
return
- sprintf(buf,
+ sysfs_emit(buf,
...);
...>
}
@@
identifier d_show;
identifier dev, attr, buf;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
return
- snprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
}
@@
identifier d_show;
identifier dev, attr, buf;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
return
- scnprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
}
@@
identifier d_show;
identifier dev, attr, buf;
expression chr;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
return
- strcpy(buf, chr);
+ sysfs_emit(buf, chr);
...>
}
@@
identifier d_show;
identifier dev, attr, buf;
identifier len;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
len =
- sprintf(buf,
+ sysfs_emit(buf,
...);
...>
return len;
}
@@
identifier d_show;
identifier dev, attr, buf;
identifier len;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
len =
- snprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
return len;
}
@@
identifier d_show;
identifier dev, attr, buf;
identifier len;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
len =
- scnprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
return len;
}
@@
identifier d_show;
identifier dev, attr, buf;
identifier len;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
- len += scnprintf(buf + len, PAGE_SIZE - len,
+ len += sysfs_emit_at(buf, len,
...);
...>
return len;
}
@@
identifier d_show;
identifier dev, attr, buf;
expression chr;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
...
- strcpy(buf, chr);
- return strlen(buf);
+ return sysfs_emit(buf, chr);
}
Link: https://lore.kernel.org/r/7f406fa8e3aa2552c022bec680f621e38d1fe414.1602122879.git.joe@perches.com
Signed-off-by: Joe Perches <joe@perches.com>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
2020-10-08 10:36:24 +08:00
|
|
|
case RDMA_NODE_RNIC:
|
2020-10-08 10:36:26 +08:00
|
|
|
return "RNIC";
|
RDMA: Convert sysfs device * show functions to use sysfs_emit()
Done with cocci script:
@@
identifier d_show;
identifier dev, attr, buf;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
return
- sprintf(buf,
+ sysfs_emit(buf,
...);
...>
}
@@
identifier d_show;
identifier dev, attr, buf;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
return
- snprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
}
@@
identifier d_show;
identifier dev, attr, buf;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
return
- scnprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
}
@@
identifier d_show;
identifier dev, attr, buf;
expression chr;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
return
- strcpy(buf, chr);
+ sysfs_emit(buf, chr);
...>
}
@@
identifier d_show;
identifier dev, attr, buf;
identifier len;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
len =
- sprintf(buf,
+ sysfs_emit(buf,
...);
...>
return len;
}
@@
identifier d_show;
identifier dev, attr, buf;
identifier len;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
len =
- snprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
return len;
}
@@
identifier d_show;
identifier dev, attr, buf;
identifier len;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
len =
- scnprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
return len;
}
@@
identifier d_show;
identifier dev, attr, buf;
identifier len;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
- len += scnprintf(buf + len, PAGE_SIZE - len,
+ len += sysfs_emit_at(buf, len,
...);
...>
return len;
}
@@
identifier d_show;
identifier dev, attr, buf;
expression chr;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
...
- strcpy(buf, chr);
- return strlen(buf);
+ return sysfs_emit(buf, chr);
}
Link: https://lore.kernel.org/r/7f406fa8e3aa2552c022bec680f621e38d1fe414.1602122879.git.joe@perches.com
Signed-off-by: Joe Perches <joe@perches.com>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
2020-10-08 10:36:24 +08:00
|
|
|
case RDMA_NODE_USNIC:
|
2020-10-08 10:36:26 +08:00
|
|
|
return "usNIC";
|
RDMA: Convert sysfs device * show functions to use sysfs_emit()
Done with cocci script:
@@
identifier d_show;
identifier dev, attr, buf;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
return
- sprintf(buf,
+ sysfs_emit(buf,
...);
...>
}
@@
identifier d_show;
identifier dev, attr, buf;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
return
- snprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
}
@@
identifier d_show;
identifier dev, attr, buf;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
return
- scnprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
}
@@
identifier d_show;
identifier dev, attr, buf;
expression chr;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
return
- strcpy(buf, chr);
+ sysfs_emit(buf, chr);
...>
}
@@
identifier d_show;
identifier dev, attr, buf;
identifier len;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
len =
- sprintf(buf,
+ sysfs_emit(buf,
...);
...>
return len;
}
@@
identifier d_show;
identifier dev, attr, buf;
identifier len;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
len =
- snprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
return len;
}
@@
identifier d_show;
identifier dev, attr, buf;
identifier len;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
len =
- scnprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
return len;
}
@@
identifier d_show;
identifier dev, attr, buf;
identifier len;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
- len += scnprintf(buf + len, PAGE_SIZE - len,
+ len += sysfs_emit_at(buf, len,
...);
...>
return len;
}
@@
identifier d_show;
identifier dev, attr, buf;
expression chr;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
...
- strcpy(buf, chr);
- return strlen(buf);
+ return sysfs_emit(buf, chr);
}
Link: https://lore.kernel.org/r/7f406fa8e3aa2552c022bec680f621e38d1fe414.1602122879.git.joe@perches.com
Signed-off-by: Joe Perches <joe@perches.com>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
2020-10-08 10:36:24 +08:00
|
|
|
case RDMA_NODE_USNIC_UDP:
|
2020-10-08 10:36:26 +08:00
|
|
|
return "usNIC UDP";
|
RDMA: Convert sysfs device * show functions to use sysfs_emit()
Done with cocci script:
@@
identifier d_show;
identifier dev, attr, buf;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
return
- sprintf(buf,
+ sysfs_emit(buf,
...);
...>
}
@@
identifier d_show;
identifier dev, attr, buf;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
return
- snprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
}
@@
identifier d_show;
identifier dev, attr, buf;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
return
- scnprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
}
@@
identifier d_show;
identifier dev, attr, buf;
expression chr;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
return
- strcpy(buf, chr);
+ sysfs_emit(buf, chr);
...>
}
@@
identifier d_show;
identifier dev, attr, buf;
identifier len;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
len =
- sprintf(buf,
+ sysfs_emit(buf,
...);
...>
return len;
}
@@
identifier d_show;
identifier dev, attr, buf;
identifier len;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
len =
- snprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
return len;
}
@@
identifier d_show;
identifier dev, attr, buf;
identifier len;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
len =
- scnprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
return len;
}
@@
identifier d_show;
identifier dev, attr, buf;
identifier len;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
- len += scnprintf(buf + len, PAGE_SIZE - len,
+ len += sysfs_emit_at(buf, len,
...);
...>
return len;
}
@@
identifier d_show;
identifier dev, attr, buf;
expression chr;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
...
- strcpy(buf, chr);
- return strlen(buf);
+ return sysfs_emit(buf, chr);
}
Link: https://lore.kernel.org/r/7f406fa8e3aa2552c022bec680f621e38d1fe414.1602122879.git.joe@perches.com
Signed-off-by: Joe Perches <joe@perches.com>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
2020-10-08 10:36:24 +08:00
|
|
|
case RDMA_NODE_UNSPECIFIED:
|
2020-10-08 10:36:26 +08:00
|
|
|
return "unspecified";
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2020-10-08 10:36:26 +08:00
|
|
|
return "<unknown>";
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t node_type_show(struct device *device,
|
|
|
|
struct device_attribute *attr, char *buf)
|
|
|
|
{
|
|
|
|
struct ib_device *dev = rdma_device_to_ibdev(device);
|
|
|
|
|
|
|
|
return sysfs_emit(buf, "%d: %s\n", dev->node_type,
|
|
|
|
node_type_string(dev->node_type));
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2018-09-05 14:47:58 +08:00
|
|
|
static DEVICE_ATTR_RO(node_type);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2018-09-05 14:47:58 +08:00
|
|
|
static ssize_t sys_image_guid_show(struct device *device,
|
2008-02-22 07:13:36 +08:00
|
|
|
struct device_attribute *dev_attr, char *buf)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2018-12-18 20:15:56 +08:00
|
|
|
struct ib_device *dev = rdma_device_to_ibdev(device);
|
2020-10-08 10:36:26 +08:00
|
|
|
__be16 *guid = (__be16 *)&dev->attrs.sys_image_guid;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2020-10-08 10:36:26 +08:00
|
|
|
return sysfs_emit(buf, "%04x:%04x:%04x:%04x\n",
|
|
|
|
be16_to_cpu(guid[0]),
|
|
|
|
be16_to_cpu(guid[1]),
|
|
|
|
be16_to_cpu(guid[2]),
|
|
|
|
be16_to_cpu(guid[3]));
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2018-09-05 14:47:58 +08:00
|
|
|
static DEVICE_ATTR_RO(sys_image_guid);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2018-09-05 14:47:58 +08:00
|
|
|
static ssize_t node_guid_show(struct device *device,
|
2008-02-22 07:13:36 +08:00
|
|
|
struct device_attribute *attr, char *buf)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2018-12-18 20:15:56 +08:00
|
|
|
struct ib_device *dev = rdma_device_to_ibdev(device);
|
2020-10-08 10:36:26 +08:00
|
|
|
__be16 *node_guid = (__be16 *)&dev->node_guid;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
RDMA: Convert sysfs device * show functions to use sysfs_emit()
Done with cocci script:
@@
identifier d_show;
identifier dev, attr, buf;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
return
- sprintf(buf,
+ sysfs_emit(buf,
...);
...>
}
@@
identifier d_show;
identifier dev, attr, buf;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
return
- snprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
}
@@
identifier d_show;
identifier dev, attr, buf;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
return
- scnprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
}
@@
identifier d_show;
identifier dev, attr, buf;
expression chr;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
return
- strcpy(buf, chr);
+ sysfs_emit(buf, chr);
...>
}
@@
identifier d_show;
identifier dev, attr, buf;
identifier len;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
len =
- sprintf(buf,
+ sysfs_emit(buf,
...);
...>
return len;
}
@@
identifier d_show;
identifier dev, attr, buf;
identifier len;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
len =
- snprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
return len;
}
@@
identifier d_show;
identifier dev, attr, buf;
identifier len;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
len =
- scnprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
return len;
}
@@
identifier d_show;
identifier dev, attr, buf;
identifier len;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
- len += scnprintf(buf + len, PAGE_SIZE - len,
+ len += sysfs_emit_at(buf, len,
...);
...>
return len;
}
@@
identifier d_show;
identifier dev, attr, buf;
expression chr;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
...
- strcpy(buf, chr);
- return strlen(buf);
+ return sysfs_emit(buf, chr);
}
Link: https://lore.kernel.org/r/7f406fa8e3aa2552c022bec680f621e38d1fe414.1602122879.git.joe@perches.com
Signed-off-by: Joe Perches <joe@perches.com>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
2020-10-08 10:36:24 +08:00
|
|
|
return sysfs_emit(buf, "%04x:%04x:%04x:%04x\n",
|
2020-10-08 10:36:26 +08:00
|
|
|
be16_to_cpu(node_guid[0]),
|
|
|
|
be16_to_cpu(node_guid[1]),
|
|
|
|
be16_to_cpu(node_guid[2]),
|
|
|
|
be16_to_cpu(node_guid[3]));
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2018-09-05 14:47:58 +08:00
|
|
|
static DEVICE_ATTR_RO(node_guid);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2018-09-05 14:47:58 +08:00
|
|
|
static ssize_t node_desc_show(struct device *device,
|
2008-02-22 07:13:36 +08:00
|
|
|
struct device_attribute *attr, char *buf)
|
2006-02-03 01:47:14 +08:00
|
|
|
{
|
2018-12-18 20:15:56 +08:00
|
|
|
struct ib_device *dev = rdma_device_to_ibdev(device);
|
2006-02-03 01:47:14 +08:00
|
|
|
|
RDMA: Convert sysfs device * show functions to use sysfs_emit()
Done with cocci script:
@@
identifier d_show;
identifier dev, attr, buf;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
return
- sprintf(buf,
+ sysfs_emit(buf,
...);
...>
}
@@
identifier d_show;
identifier dev, attr, buf;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
return
- snprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
}
@@
identifier d_show;
identifier dev, attr, buf;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
return
- scnprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
}
@@
identifier d_show;
identifier dev, attr, buf;
expression chr;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
return
- strcpy(buf, chr);
+ sysfs_emit(buf, chr);
...>
}
@@
identifier d_show;
identifier dev, attr, buf;
identifier len;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
len =
- sprintf(buf,
+ sysfs_emit(buf,
...);
...>
return len;
}
@@
identifier d_show;
identifier dev, attr, buf;
identifier len;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
len =
- snprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
return len;
}
@@
identifier d_show;
identifier dev, attr, buf;
identifier len;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
len =
- scnprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
return len;
}
@@
identifier d_show;
identifier dev, attr, buf;
identifier len;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
- len += scnprintf(buf + len, PAGE_SIZE - len,
+ len += sysfs_emit_at(buf, len,
...);
...>
return len;
}
@@
identifier d_show;
identifier dev, attr, buf;
expression chr;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
...
- strcpy(buf, chr);
- return strlen(buf);
+ return sysfs_emit(buf, chr);
}
Link: https://lore.kernel.org/r/7f406fa8e3aa2552c022bec680f621e38d1fe414.1602122879.git.joe@perches.com
Signed-off-by: Joe Perches <joe@perches.com>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
2020-10-08 10:36:24 +08:00
|
|
|
return sysfs_emit(buf, "%.64s\n", dev->node_desc);
|
2006-02-03 01:47:14 +08:00
|
|
|
}
|
|
|
|
|
2018-09-05 14:47:58 +08:00
|
|
|
static ssize_t node_desc_store(struct device *device,
|
|
|
|
struct device_attribute *attr,
|
|
|
|
const char *buf, size_t count)
|
2006-02-03 01:47:14 +08:00
|
|
|
{
|
2018-12-18 20:15:56 +08:00
|
|
|
struct ib_device *dev = rdma_device_to_ibdev(device);
|
2006-02-03 01:47:14 +08:00
|
|
|
struct ib_device_modify desc = {};
|
|
|
|
int ret;
|
|
|
|
|
2018-12-11 03:09:48 +08:00
|
|
|
if (!dev->ops.modify_device)
|
2019-09-23 18:41:56 +08:00
|
|
|
return -EOPNOTSUPP;
|
2006-02-03 01:47:14 +08:00
|
|
|
|
2016-08-26 01:57:07 +08:00
|
|
|
memcpy(desc.node_desc, buf, min_t(int, count, IB_DEVICE_NODE_DESC_MAX));
|
2006-02-03 01:47:14 +08:00
|
|
|
ret = ib_modify_device(dev, IB_DEVICE_MODIFY_NODE_DESC, &desc);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
2018-09-05 14:47:58 +08:00
|
|
|
static DEVICE_ATTR_RW(node_desc);
|
2006-02-03 01:47:14 +08:00
|
|
|
|
2018-09-05 14:47:58 +08:00
|
|
|
static ssize_t fw_ver_show(struct device *device, struct device_attribute *attr,
|
2016-06-15 14:22:07 +08:00
|
|
|
char *buf)
|
|
|
|
{
|
2018-12-18 20:15:56 +08:00
|
|
|
struct ib_device *dev = rdma_device_to_ibdev(device);
|
2020-10-08 10:36:26 +08:00
|
|
|
char version[IB_FW_VERSION_NAME_MAX] = {};
|
|
|
|
|
|
|
|
ib_get_device_fw_str(dev, version);
|
2016-06-15 14:22:07 +08:00
|
|
|
|
2020-10-08 10:36:26 +08:00
|
|
|
return sysfs_emit(buf, "%s\n", version);
|
2016-06-15 14:22:07 +08:00
|
|
|
}
|
2018-09-05 14:47:58 +08:00
|
|
|
static DEVICE_ATTR_RO(fw_ver);
|
|
|
|
|
|
|
|
static struct attribute *ib_dev_attrs[] = {
|
|
|
|
&dev_attr_node_type.attr,
|
|
|
|
&dev_attr_node_guid.attr,
|
|
|
|
&dev_attr_sys_image_guid.attr,
|
|
|
|
&dev_attr_fw_ver.attr,
|
|
|
|
&dev_attr_node_desc.attr,
|
|
|
|
NULL,
|
|
|
|
};
|
2016-06-15 14:22:07 +08:00
|
|
|
|
2019-02-14 01:23:06 +08:00
|
|
|
const struct attribute_group ib_dev_attr_group = {
|
2018-09-05 14:47:58 +08:00
|
|
|
.attrs = ib_dev_attrs,
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
2019-02-26 19:56:15 +08:00
|
|
|
void ib_free_port_attrs(struct ib_core_device *coredev)
|
2014-05-18 16:12:26 +08:00
|
|
|
{
|
2019-07-02 18:02:46 +08:00
|
|
|
struct ib_device *device = rdma_device_to_ibdev(&coredev->dev);
|
|
|
|
bool is_full_dev = &device->coredev == coredev;
|
2014-05-18 16:12:26 +08:00
|
|
|
struct kobject *p, *t;
|
|
|
|
|
2019-02-26 19:56:11 +08:00
|
|
|
list_for_each_entry_safe(p, t, &coredev->port_list, entry) {
|
2014-05-18 16:12:26 +08:00
|
|
|
struct ib_port *port = container_of(p, struct ib_port, kobj);
|
2019-02-14 01:23:04 +08:00
|
|
|
|
2014-05-18 16:12:26 +08:00
|
|
|
list_del(&p->entry);
|
2019-02-14 01:23:04 +08:00
|
|
|
if (port->hw_stats_ag)
|
IB/core: Make device counter infrastructure dynamic
In practice, each RDMA device has a unique set of counters that the
hardware implements. Having a central set of counters that they must
all adhere to is limiting and causes many useful counters to not be
available.
Therefore we create a dynamic counter registration infrastructure.
The driver must implement a stats structure allocation routine, in
which the driver must place the directory name it wants, a list of
names for all of the counters, an array of u64 counters themselves,
plus a few generic configuration options.
We then implement a core routine to create a sysfs file for each
of the named stats elements, and a core routine to retrieve the
stats when any of the sysfs attribute files are read.
To avoid excessive beating on the stats generation routine in the
drivers, the core code also caches the stats for a short period of
time so that someone attempting to read all of the stats in a
given device's directory will not result in a stats generation
call per file read.
Future work will attempt to standardize just the shared stats
elements, and possibly add a method to get the stats via netlink
in addition to sysfs.
Signed-off-by: Christoph Lameter <cl@linux.com>
Signed-off-by: Mark Bloch <markb@mellanox.com>
Reviewed-by: Steve Wise <swise@opengridcomputing.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
[ Add caching, make structure names more informative, add i40iw support,
other significant rewrites from the original patch ]
2016-05-17 01:49:33 +08:00
|
|
|
free_hsag(&port->kobj, port->hw_stats_ag);
|
2019-02-14 01:23:04 +08:00
|
|
|
kfree(port->hw_stats);
|
2019-07-02 18:02:46 +08:00
|
|
|
if (device->port_data && is_full_dev)
|
|
|
|
device->port_data[port->port_num].hw_stats = NULL;
|
2018-10-07 17:12:40 +08:00
|
|
|
|
|
|
|
if (port->pma_table)
|
|
|
|
sysfs_remove_group(p, port->pma_table);
|
2020-07-15 02:34:08 +08:00
|
|
|
if (port->pkey_group)
|
|
|
|
sysfs_remove_group(p, port->pkey_group);
|
2014-05-18 16:12:26 +08:00
|
|
|
sysfs_remove_group(p, &port->gid_group);
|
2015-12-23 20:56:49 +08:00
|
|
|
sysfs_remove_group(&port->gid_attr_group->kobj,
|
|
|
|
&port->gid_attr_group->ndev);
|
|
|
|
sysfs_remove_group(&port->gid_attr_group->kobj,
|
|
|
|
&port->gid_attr_group->type);
|
|
|
|
kobject_put(&port->gid_attr_group->kobj);
|
2014-05-18 16:12:26 +08:00
|
|
|
kobject_put(p);
|
|
|
|
}
|
|
|
|
|
2019-02-26 19:56:11 +08:00
|
|
|
kobject_put(coredev->ports_kobj);
|
2014-05-18 16:12:26 +08:00
|
|
|
}
|
|
|
|
|
2019-05-01 13:46:55 +08:00
|
|
|
int ib_setup_port_attrs(struct ib_core_device *coredev)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2019-02-26 19:56:11 +08:00
|
|
|
struct ib_device *device = rdma_device_to_ibdev(&coredev->dev);
|
2019-02-13 12:12:47 +08:00
|
|
|
unsigned int port;
|
2005-04-17 06:20:36 +08:00
|
|
|
int ret;
|
|
|
|
|
2019-02-26 19:56:11 +08:00
|
|
|
coredev->ports_kobj = kobject_create_and_add("ports",
|
|
|
|
&coredev->dev.kobj);
|
|
|
|
if (!coredev->ports_kobj)
|
2019-02-14 01:23:04 +08:00
|
|
|
return -ENOMEM;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2019-02-13 12:12:47 +08:00
|
|
|
rdma_for_each_port (device, port) {
|
2019-05-01 13:46:55 +08:00
|
|
|
ret = add_port(coredev, port);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (ret)
|
|
|
|
goto err_put;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_put:
|
2019-02-26 19:56:11 +08:00
|
|
|
ib_free_port_attrs(coredev);
|
2005-04-17 06:20:36 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-02-14 01:23:04 +08:00
|
|
|
int ib_device_register_sysfs(struct ib_device *device)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2019-02-14 01:23:04 +08:00
|
|
|
int ret;
|
2014-05-18 16:12:26 +08:00
|
|
|
|
2019-05-01 13:46:55 +08:00
|
|
|
ret = ib_setup_port_attrs(&device->coredev);
|
2019-02-14 01:23:04 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
if (device->ops.alloc_hw_stats)
|
|
|
|
setup_hw_stats(device, NULL, 0);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ib_device_unregister_sysfs(struct ib_device *device)
|
|
|
|
{
|
|
|
|
if (device->hw_stats_ag)
|
|
|
|
free_hsag(&device->dev.kobj, device->hw_stats_ag);
|
|
|
|
kfree(device->hw_stats);
|
|
|
|
|
2019-02-26 19:56:11 +08:00
|
|
|
ib_free_port_attrs(&device->coredev);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2019-03-11 20:40:31 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* ib_port_register_module_stat - add module counters under relevant port
|
|
|
|
* of IB device.
|
|
|
|
*
|
|
|
|
* @device: IB device to add counters
|
|
|
|
* @port_num: valid port number
|
|
|
|
* @kobj: pointer to the kobject to initialize
|
|
|
|
* @ktype: pointer to the ktype for this kobject.
|
|
|
|
* @name: the name of the kobject
|
|
|
|
*/
|
|
|
|
int ib_port_register_module_stat(struct ib_device *device, u8 port_num,
|
|
|
|
struct kobject *kobj, struct kobj_type *ktype,
|
|
|
|
const char *name)
|
|
|
|
{
|
|
|
|
struct kobject *p, *t;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
list_for_each_entry_safe(p, t, &device->coredev.port_list, entry) {
|
|
|
|
struct ib_port *port = container_of(p, struct ib_port, kobj);
|
|
|
|
|
|
|
|
if (port->port_num != port_num)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
ret = kobject_init_and_add(kobj, ktype, &port->kobj, "%s",
|
|
|
|
name);
|
2020-05-28 11:02:30 +08:00
|
|
|
if (ret) {
|
|
|
|
kobject_put(kobj);
|
2019-03-11 20:40:31 +08:00
|
|
|
return ret;
|
2020-05-28 11:02:30 +08:00
|
|
|
}
|
2019-03-11 20:40:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ib_port_register_module_stat);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ib_port_unregister_module_stat - release module counters
|
|
|
|
* @kobj: pointer to the kobject to release
|
|
|
|
*/
|
|
|
|
void ib_port_unregister_module_stat(struct kobject *kobj)
|
|
|
|
{
|
|
|
|
kobject_put(kobj);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ib_port_unregister_module_stat);
|