net/mlx5: Include linux/pci.h for pci_msix_can_alloc_dyn()
[linux-block.git] / drivers / net / bonding / bond_sysfs_slave.c
CommitLineData
2874c5fd 1// SPDX-License-Identifier: GPL-2.0-or-later
07699f9a 2/* Sysfs attributes of bond slaves
3 *
4 * Copyright (c) 2014 Scott Feldman <sfeldma@cumulusnetworks.com>
07699f9a 5 */
6
7#include <linux/capability.h>
8#include <linux/kernel.h>
9#include <linux/netdevice.h>
10
1ef8019b 11#include <net/bonding.h>
07699f9a 12
13struct slave_attribute {
14 struct attribute attr;
15 ssize_t (*show)(struct slave *, char *);
16};
17
d61e4038 18#define SLAVE_ATTR_RO(_name) \
669b258a 19const struct slave_attribute slave_attr_##_name = __ATTR_RO(_name)
07699f9a 20
21static ssize_t state_show(struct slave *slave, char *buf)
22{
23 switch (bond_slave_state(slave)) {
24 case BOND_STATE_ACTIVE:
96e07181 25 return sysfs_emit(buf, "active\n");
07699f9a 26 case BOND_STATE_BACKUP:
96e07181 27 return sysfs_emit(buf, "backup\n");
07699f9a 28 default:
96e07181 29 return sysfs_emit(buf, "UNKNOWN\n");
07699f9a 30 }
31}
32static SLAVE_ATTR_RO(state);
33
34static ssize_t mii_status_show(struct slave *slave, char *buf)
35{
96e07181 36 return sysfs_emit(buf, "%s\n", bond_slave_link_status(slave->link));
07699f9a 37}
38static SLAVE_ATTR_RO(mii_status);
39
40static ssize_t link_failure_count_show(struct slave *slave, char *buf)
41{
96e07181 42 return sysfs_emit(buf, "%d\n", slave->link_failure_count);
07699f9a 43}
44static SLAVE_ATTR_RO(link_failure_count);
45
46static ssize_t perm_hwaddr_show(struct slave *slave, char *buf)
47{
96e07181 48 return sysfs_emit(buf, "%*phC\n",
18bebc6d
KK
49 slave->dev->addr_len,
50 slave->perm_hwaddr);
07699f9a 51}
52static SLAVE_ATTR_RO(perm_hwaddr);
53
54static ssize_t queue_id_show(struct slave *slave, char *buf)
55{
96e07181 56 return sysfs_emit(buf, "%d\n", slave->queue_id);
07699f9a 57}
58static SLAVE_ATTR_RO(queue_id);
59
60static ssize_t ad_aggregator_id_show(struct slave *slave, char *buf)
61{
62 const struct aggregator *agg;
63
01844098 64 if (BOND_MODE(slave->bond) == BOND_MODE_8023AD) {
3fdddd85 65 agg = SLAVE_AD_INFO(slave)->port.aggregator;
07699f9a 66 if (agg)
96e07181
WY
67 return sysfs_emit(buf, "%d\n",
68 agg->aggregator_identifier);
07699f9a 69 }
70
96e07181 71 return sysfs_emit(buf, "N/A\n");
07699f9a 72}
73static SLAVE_ATTR_RO(ad_aggregator_id);
74
254cb6db
NA
75static ssize_t ad_actor_oper_port_state_show(struct slave *slave, char *buf)
76{
77 const struct port *ad_port;
78
79 if (BOND_MODE(slave->bond) == BOND_MODE_8023AD) {
80 ad_port = &SLAVE_AD_INFO(slave)->port;
81 if (ad_port->aggregator)
96e07181 82 return sysfs_emit(buf, "%u\n",
254cb6db
NA
83 ad_port->actor_oper_port_state);
84 }
85
96e07181 86 return sysfs_emit(buf, "N/A\n");
254cb6db
NA
87}
88static SLAVE_ATTR_RO(ad_actor_oper_port_state);
89
46ea297e
NA
90static ssize_t ad_partner_oper_port_state_show(struct slave *slave, char *buf)
91{
92 const struct port *ad_port;
93
94 if (BOND_MODE(slave->bond) == BOND_MODE_8023AD) {
95 ad_port = &SLAVE_AD_INFO(slave)->port;
96 if (ad_port->aggregator)
96e07181 97 return sysfs_emit(buf, "%u\n",
46ea297e
NA
98 ad_port->partner_oper.port_state);
99 }
100
96e07181 101 return sysfs_emit(buf, "N/A\n");
46ea297e
NA
102}
103static SLAVE_ATTR_RO(ad_partner_oper_port_state);
104
b93c6a91
HG
105static const struct attribute *slave_attrs[] = {
106 &slave_attr_state.attr,
107 &slave_attr_mii_status.attr,
108 &slave_attr_link_failure_count.attr,
109 &slave_attr_perm_hwaddr.attr,
110 &slave_attr_queue_id.attr,
111 &slave_attr_ad_aggregator_id.attr,
112 &slave_attr_ad_actor_oper_port_state.attr,
113 &slave_attr_ad_partner_oper_port_state.attr,
07699f9a 114 NULL
115};
116
117#define to_slave_attr(_at) container_of(_at, struct slave_attribute, attr)
07699f9a 118
119static ssize_t slave_show(struct kobject *kobj,
120 struct attribute *attr, char *buf)
121{
122 struct slave_attribute *slave_attr = to_slave_attr(attr);
123 struct slave *slave = to_slave(kobj);
124
125 return slave_attr->show(slave, buf);
126}
127
b9ad3e9f 128const struct sysfs_ops slave_sysfs_ops = {
07699f9a 129 .show = slave_show,
130};
131
07699f9a 132int bond_sysfs_slave_add(struct slave *slave)
133{
b93c6a91 134 return sysfs_create_files(&slave->kobj, slave_attrs);
07699f9a 135}
136
137void bond_sysfs_slave_del(struct slave *slave)
138{
b93c6a91 139 sysfs_remove_files(&slave->kobj, slave_attrs);
07699f9a 140}