2 * Copyright IBM Corp. 2013
3 * Author(s): Eugene Crosser <eugene.crosser@ru.ibm.com>
6 #include <linux/slab.h>
7 #include <asm/ebcdic.h>
10 #define QETH_DEVICE_ATTR(_id, _name, _mode, _show, _store) \
11 struct device_attribute dev_attr_##_id = __ATTR(_name, _mode, _show, _store)
13 static int qeth_card_hw_is_reachable(struct qeth_card *card)
15 return (card->state == CARD_STATE_SOFTSETUP) ||
16 (card->state == CARD_STATE_UP);
19 static ssize_t qeth_bridge_port_role_state_show(struct device *dev,
20 struct device_attribute *attr, char *buf,
23 struct qeth_card *card = dev_get_drvdata(dev);
24 enum qeth_sbp_states state = QETH_SBP_STATE_INACTIVE;
31 mutex_lock(&card->conf_mutex);
33 if (qeth_card_hw_is_reachable(card) &&
34 card->options.sbp.supported_funcs)
35 rc = qeth_bridgeport_query_ports(card,
36 &card->options.sbp.role, &state);
40 case QETH_SBP_STATE_INACTIVE:
41 word = "inactive"; break;
42 case QETH_SBP_STATE_STANDBY:
43 word = "standby"; break;
44 case QETH_SBP_STATE_ACTIVE:
45 word = "active"; break;
50 switch (card->options.sbp.role) {
51 case QETH_SBP_ROLE_NONE:
53 case QETH_SBP_ROLE_PRIMARY:
54 word = "primary"; break;
55 case QETH_SBP_ROLE_SECONDARY:
56 word = "secondary"; break;
61 QETH_CARD_TEXT_(card, 2, "SBP%02x:%02x",
62 card->options.sbp.role, state);
64 rc = sprintf(buf, "%s\n", word);
67 mutex_unlock(&card->conf_mutex);
72 static ssize_t qeth_bridge_port_role_show(struct device *dev,
73 struct device_attribute *attr, char *buf)
75 return qeth_bridge_port_role_state_show(dev, attr, buf, 0);
78 static ssize_t qeth_bridge_port_role_store(struct device *dev,
79 struct device_attribute *attr, const char *buf, size_t count)
81 struct qeth_card *card = dev_get_drvdata(dev);
83 enum qeth_sbp_roles role;
87 if (sysfs_streq(buf, "primary"))
88 role = QETH_SBP_ROLE_PRIMARY;
89 else if (sysfs_streq(buf, "secondary"))
90 role = QETH_SBP_ROLE_SECONDARY;
91 else if (sysfs_streq(buf, "none"))
92 role = QETH_SBP_ROLE_NONE;
96 mutex_lock(&card->conf_mutex);
98 if (qeth_card_hw_is_reachable(card)) {
99 rc = qeth_bridgeport_setrole(card, role);
101 card->options.sbp.role = role;
103 card->options.sbp.role = role;
105 mutex_unlock(&card->conf_mutex);
107 return rc ? rc : count;
110 static DEVICE_ATTR(bridge_role, 0644, qeth_bridge_port_role_show,
111 qeth_bridge_port_role_store);
113 static ssize_t qeth_bridge_port_state_show(struct device *dev,
114 struct device_attribute *attr, char *buf)
116 return qeth_bridge_port_role_state_show(dev, attr, buf, 1);
119 static DEVICE_ATTR(bridge_state, 0644, qeth_bridge_port_state_show,
122 static ssize_t qeth_bridgeport_hostnotification_show(struct device *dev,
123 struct device_attribute *attr, char *buf)
125 struct qeth_card *card = dev_get_drvdata(dev);
131 mutex_lock(&card->conf_mutex);
133 enabled = card->options.sbp.hostnotification;
135 mutex_unlock(&card->conf_mutex);
137 return sprintf(buf, "%d\n", enabled);
140 static ssize_t qeth_bridgeport_hostnotification_store(struct device *dev,
141 struct device_attribute *attr, const char *buf, size_t count)
143 struct qeth_card *card = dev_get_drvdata(dev);
150 if (sysfs_streq(buf, "0"))
152 else if (sysfs_streq(buf, "1"))
157 mutex_lock(&card->conf_mutex);
159 if (qeth_card_hw_is_reachable(card)) {
160 rc = qeth_bridgeport_an_set(card, enable);
162 card->options.sbp.hostnotification = enable;
164 card->options.sbp.hostnotification = enable;
166 mutex_unlock(&card->conf_mutex);
168 return rc ? rc : count;
171 static DEVICE_ATTR(bridge_hostnotify, 0644,
172 qeth_bridgeport_hostnotification_show,
173 qeth_bridgeport_hostnotification_store);
175 static struct attribute *qeth_l2_bridgeport_attrs[] = {
176 &dev_attr_bridge_role.attr,
177 &dev_attr_bridge_state.attr,
178 &dev_attr_bridge_hostnotify.attr,
182 static struct attribute_group qeth_l2_bridgeport_attr_group = {
183 .attrs = qeth_l2_bridgeport_attrs,
186 int qeth_l2_create_device_attributes(struct device *dev)
188 return sysfs_create_group(&dev->kobj, &qeth_l2_bridgeport_attr_group);
191 void qeth_l2_remove_device_attributes(struct device *dev)
193 sysfs_remove_group(&dev->kobj, &qeth_l2_bridgeport_attr_group);
197 * qeth_l2_setup_bridgeport_attrs() - set/restore attrs when turning online.
198 * @card: qeth_card structure pointer
200 * Note: this function is called with conf_mutex held by the caller
202 void qeth_l2_setup_bridgeport_attrs(struct qeth_card *card)
208 if (!card->options.sbp.supported_funcs)
210 if (card->options.sbp.role != QETH_SBP_ROLE_NONE) {
211 /* Conditional to avoid spurious error messages */
212 qeth_bridgeport_setrole(card, card->options.sbp.role);
213 /* Let the callback function refresh the stored role value. */
214 qeth_bridgeport_query_ports(card,
215 &card->options.sbp.role, NULL);
217 if (card->options.sbp.hostnotification) {
218 rc = qeth_bridgeport_an_set(card, 1);
220 card->options.sbp.hostnotification = 0;
222 qeth_bridgeport_an_set(card, 0);