2019-05-27 06:55:01 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2014-01-17 06:57:49 +00:00
|
|
|
/* Sysfs attributes of bond slaves
|
|
|
|
*
|
|
|
|
* Copyright (c) 2014 Scott Feldman <sfeldma@cumulusnetworks.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/capability.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/netdevice.h>
|
|
|
|
|
2014-11-10 18:27:49 +00:00
|
|
|
#include <net/bonding.h>
|
2014-01-17 06:57:49 +00:00
|
|
|
|
|
|
|
struct slave_attribute {
|
|
|
|
struct attribute attr;
|
|
|
|
ssize_t (*show)(struct slave *, char *);
|
|
|
|
};
|
|
|
|
|
2018-03-23 22:54:39 +00:00
|
|
|
#define SLAVE_ATTR_RO(_name) \
|
2022-03-06 08:28:08 +00:00
|
|
|
const struct slave_attribute slave_attr_##_name = __ATTR_RO(_name)
|
2014-01-17 06:57:49 +00:00
|
|
|
|
|
|
|
static ssize_t state_show(struct slave *slave, char *buf)
|
|
|
|
{
|
|
|
|
switch (bond_slave_state(slave)) {
|
|
|
|
case BOND_STATE_ACTIVE:
|
2022-09-28 12:30:14 +00:00
|
|
|
return sysfs_emit(buf, "active\n");
|
2014-01-17 06:57:49 +00:00
|
|
|
case BOND_STATE_BACKUP:
|
2022-09-28 12:30:14 +00:00
|
|
|
return sysfs_emit(buf, "backup\n");
|
2014-01-17 06:57:49 +00:00
|
|
|
default:
|
2022-09-28 12:30:14 +00:00
|
|
|
return sysfs_emit(buf, "UNKNOWN\n");
|
2014-01-17 06:57:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
static SLAVE_ATTR_RO(state);
|
|
|
|
|
|
|
|
static ssize_t mii_status_show(struct slave *slave, char *buf)
|
|
|
|
{
|
2022-09-28 12:30:14 +00:00
|
|
|
return sysfs_emit(buf, "%s\n", bond_slave_link_status(slave->link));
|
2014-01-17 06:57:49 +00:00
|
|
|
}
|
|
|
|
static SLAVE_ATTR_RO(mii_status);
|
|
|
|
|
|
|
|
static ssize_t link_failure_count_show(struct slave *slave, char *buf)
|
|
|
|
{
|
2022-09-28 12:30:14 +00:00
|
|
|
return sysfs_emit(buf, "%d\n", slave->link_failure_count);
|
2014-01-17 06:57:49 +00:00
|
|
|
}
|
|
|
|
static SLAVE_ATTR_RO(link_failure_count);
|
|
|
|
|
|
|
|
static ssize_t perm_hwaddr_show(struct slave *slave, char *buf)
|
|
|
|
{
|
2022-09-28 12:30:14 +00:00
|
|
|
return sysfs_emit(buf, "%*phC\n",
|
2019-03-28 10:29:21 +00:00
|
|
|
slave->dev->addr_len,
|
|
|
|
slave->perm_hwaddr);
|
2014-01-17 06:57:49 +00:00
|
|
|
}
|
|
|
|
static SLAVE_ATTR_RO(perm_hwaddr);
|
|
|
|
|
|
|
|
static ssize_t queue_id_show(struct slave *slave, char *buf)
|
|
|
|
{
|
2022-09-28 12:30:14 +00:00
|
|
|
return sysfs_emit(buf, "%d\n", slave->queue_id);
|
2014-01-17 06:57:49 +00:00
|
|
|
}
|
|
|
|
static SLAVE_ATTR_RO(queue_id);
|
|
|
|
|
|
|
|
static ssize_t ad_aggregator_id_show(struct slave *slave, char *buf)
|
|
|
|
{
|
|
|
|
const struct aggregator *agg;
|
|
|
|
|
2014-05-15 19:39:55 +00:00
|
|
|
if (BOND_MODE(slave->bond) == BOND_MODE_8023AD) {
|
2014-05-12 07:08:43 +00:00
|
|
|
agg = SLAVE_AD_INFO(slave)->port.aggregator;
|
2014-01-17 06:57:49 +00:00
|
|
|
if (agg)
|
2022-09-28 12:30:14 +00:00
|
|
|
return sysfs_emit(buf, "%d\n",
|
|
|
|
agg->aggregator_identifier);
|
2014-01-17 06:57:49 +00:00
|
|
|
}
|
|
|
|
|
2022-09-28 12:30:14 +00:00
|
|
|
return sysfs_emit(buf, "N/A\n");
|
2014-01-17 06:57:49 +00:00
|
|
|
}
|
|
|
|
static SLAVE_ATTR_RO(ad_aggregator_id);
|
|
|
|
|
2015-06-14 13:36:34 +00:00
|
|
|
static ssize_t ad_actor_oper_port_state_show(struct slave *slave, char *buf)
|
|
|
|
{
|
|
|
|
const struct port *ad_port;
|
|
|
|
|
|
|
|
if (BOND_MODE(slave->bond) == BOND_MODE_8023AD) {
|
|
|
|
ad_port = &SLAVE_AD_INFO(slave)->port;
|
|
|
|
if (ad_port->aggregator)
|
2022-09-28 12:30:14 +00:00
|
|
|
return sysfs_emit(buf, "%u\n",
|
2015-06-14 13:36:34 +00:00
|
|
|
ad_port->actor_oper_port_state);
|
|
|
|
}
|
|
|
|
|
2022-09-28 12:30:14 +00:00
|
|
|
return sysfs_emit(buf, "N/A\n");
|
2015-06-14 13:36:34 +00:00
|
|
|
}
|
|
|
|
static SLAVE_ATTR_RO(ad_actor_oper_port_state);
|
|
|
|
|
2015-06-14 13:36:35 +00:00
|
|
|
static ssize_t ad_partner_oper_port_state_show(struct slave *slave, char *buf)
|
|
|
|
{
|
|
|
|
const struct port *ad_port;
|
|
|
|
|
|
|
|
if (BOND_MODE(slave->bond) == BOND_MODE_8023AD) {
|
|
|
|
ad_port = &SLAVE_AD_INFO(slave)->port;
|
|
|
|
if (ad_port->aggregator)
|
2022-09-28 12:30:14 +00:00
|
|
|
return sysfs_emit(buf, "%u\n",
|
2015-06-14 13:36:35 +00:00
|
|
|
ad_port->partner_oper.port_state);
|
|
|
|
}
|
|
|
|
|
2022-09-28 12:30:14 +00:00
|
|
|
return sysfs_emit(buf, "N/A\n");
|
2015-06-14 13:36:35 +00:00
|
|
|
}
|
|
|
|
static SLAVE_ATTR_RO(ad_partner_oper_port_state);
|
|
|
|
|
2021-11-02 09:37:33 +00:00
|
|
|
static const struct attribute *slave_attrs[] = {
|
|
|
|
&slave_attr_state.attr,
|
|
|
|
&slave_attr_mii_status.attr,
|
|
|
|
&slave_attr_link_failure_count.attr,
|
|
|
|
&slave_attr_perm_hwaddr.attr,
|
|
|
|
&slave_attr_queue_id.attr,
|
|
|
|
&slave_attr_ad_aggregator_id.attr,
|
|
|
|
&slave_attr_ad_actor_oper_port_state.attr,
|
|
|
|
&slave_attr_ad_partner_oper_port_state.attr,
|
2014-01-17 06:57:49 +00:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
#define to_slave_attr(_at) container_of(_at, struct slave_attribute, attr)
|
|
|
|
|
|
|
|
static ssize_t slave_show(struct kobject *kobj,
|
|
|
|
struct attribute *attr, char *buf)
|
|
|
|
{
|
|
|
|
struct slave_attribute *slave_attr = to_slave_attr(attr);
|
|
|
|
struct slave *slave = to_slave(kobj);
|
|
|
|
|
|
|
|
return slave_attr->show(slave, buf);
|
|
|
|
}
|
|
|
|
|
2020-11-20 14:28:27 +00:00
|
|
|
const struct sysfs_ops slave_sysfs_ops = {
|
2014-01-17 06:57:49 +00:00
|
|
|
.show = slave_show,
|
|
|
|
};
|
|
|
|
|
|
|
|
int bond_sysfs_slave_add(struct slave *slave)
|
|
|
|
{
|
2021-11-02 09:37:33 +00:00
|
|
|
return sysfs_create_files(&slave->kobj, slave_attrs);
|
2014-01-17 06:57:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void bond_sysfs_slave_del(struct slave *slave)
|
|
|
|
{
|
2021-11-02 09:37:33 +00:00
|
|
|
sysfs_remove_files(&slave->kobj, slave_attrs);
|
2014-01-17 06:57:49 +00:00
|
|
|
}
|