qeth_l2_sys.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. /*
  2. * Copyright IBM Corp. 2013
  3. * Author(s): Eugene Crosser <eugene.crosser@ru.ibm.com>
  4. */
  5. #include <linux/slab.h>
  6. #include <asm/ebcdic.h>
  7. #include "qeth_core.h"
  8. #include "qeth_l2.h"
  9. #define QETH_DEVICE_ATTR(_id, _name, _mode, _show, _store) \
  10. struct device_attribute dev_attr_##_id = __ATTR(_name, _mode, _show, _store)
  11. static ssize_t qeth_bridge_port_role_state_show(struct device *dev,
  12. struct device_attribute *attr, char *buf,
  13. int show_state)
  14. {
  15. struct qeth_card *card = dev_get_drvdata(dev);
  16. enum qeth_sbp_states state = QETH_SBP_STATE_INACTIVE;
  17. int rc = 0;
  18. char *word;
  19. if (!card)
  20. return -EINVAL;
  21. if (qeth_card_hw_is_reachable(card) &&
  22. card->options.sbp.supported_funcs)
  23. rc = qeth_bridgeport_query_ports(card,
  24. &card->options.sbp.role, &state);
  25. if (!rc) {
  26. if (show_state)
  27. switch (state) {
  28. case QETH_SBP_STATE_INACTIVE:
  29. word = "inactive"; break;
  30. case QETH_SBP_STATE_STANDBY:
  31. word = "standby"; break;
  32. case QETH_SBP_STATE_ACTIVE:
  33. word = "active"; break;
  34. default:
  35. rc = -EIO;
  36. }
  37. else
  38. switch (card->options.sbp.role) {
  39. case QETH_SBP_ROLE_NONE:
  40. word = "none"; break;
  41. case QETH_SBP_ROLE_PRIMARY:
  42. word = "primary"; break;
  43. case QETH_SBP_ROLE_SECONDARY:
  44. word = "secondary"; break;
  45. default:
  46. rc = -EIO;
  47. }
  48. if (rc)
  49. QETH_CARD_TEXT_(card, 2, "SBP%02x:%02x",
  50. card->options.sbp.role, state);
  51. else
  52. rc = sprintf(buf, "%s\n", word);
  53. }
  54. return rc;
  55. }
  56. static ssize_t qeth_bridge_port_role_show(struct device *dev,
  57. struct device_attribute *attr, char *buf)
  58. {
  59. return qeth_bridge_port_role_state_show(dev, attr, buf, 0);
  60. }
  61. static ssize_t qeth_bridge_port_role_store(struct device *dev,
  62. struct device_attribute *attr, const char *buf, size_t count)
  63. {
  64. struct qeth_card *card = dev_get_drvdata(dev);
  65. int rc = 0;
  66. enum qeth_sbp_roles role;
  67. if (!card)
  68. return -EINVAL;
  69. if (sysfs_streq(buf, "primary"))
  70. role = QETH_SBP_ROLE_PRIMARY;
  71. else if (sysfs_streq(buf, "secondary"))
  72. role = QETH_SBP_ROLE_SECONDARY;
  73. else if (sysfs_streq(buf, "none"))
  74. role = QETH_SBP_ROLE_NONE;
  75. else
  76. return -EINVAL;
  77. mutex_lock(&card->conf_mutex);
  78. if (card->options.sbp.reflect_promisc) /* Forbid direct manipulation */
  79. rc = -EPERM;
  80. else if (qeth_card_hw_is_reachable(card)) {
  81. rc = qeth_bridgeport_setrole(card, role);
  82. if (!rc)
  83. card->options.sbp.role = role;
  84. } else
  85. card->options.sbp.role = role;
  86. mutex_unlock(&card->conf_mutex);
  87. return rc ? rc : count;
  88. }
  89. static DEVICE_ATTR(bridge_role, 0644, qeth_bridge_port_role_show,
  90. qeth_bridge_port_role_store);
  91. static ssize_t qeth_bridge_port_state_show(struct device *dev,
  92. struct device_attribute *attr, char *buf)
  93. {
  94. return qeth_bridge_port_role_state_show(dev, attr, buf, 1);
  95. }
  96. static DEVICE_ATTR(bridge_state, 0444, qeth_bridge_port_state_show,
  97. NULL);
  98. static ssize_t qeth_bridgeport_hostnotification_show(struct device *dev,
  99. struct device_attribute *attr, char *buf)
  100. {
  101. struct qeth_card *card = dev_get_drvdata(dev);
  102. int enabled;
  103. if (!card)
  104. return -EINVAL;
  105. enabled = card->options.sbp.hostnotification;
  106. return sprintf(buf, "%d\n", enabled);
  107. }
  108. static ssize_t qeth_bridgeport_hostnotification_store(struct device *dev,
  109. struct device_attribute *attr, const char *buf, size_t count)
  110. {
  111. struct qeth_card *card = dev_get_drvdata(dev);
  112. int rc = 0;
  113. int enable;
  114. if (!card)
  115. return -EINVAL;
  116. if (sysfs_streq(buf, "0"))
  117. enable = 0;
  118. else if (sysfs_streq(buf, "1"))
  119. enable = 1;
  120. else
  121. return -EINVAL;
  122. mutex_lock(&card->conf_mutex);
  123. if (qeth_card_hw_is_reachable(card)) {
  124. rc = qeth_bridgeport_an_set(card, enable);
  125. if (!rc)
  126. card->options.sbp.hostnotification = enable;
  127. } else
  128. card->options.sbp.hostnotification = enable;
  129. mutex_unlock(&card->conf_mutex);
  130. return rc ? rc : count;
  131. }
  132. static DEVICE_ATTR(bridge_hostnotify, 0644,
  133. qeth_bridgeport_hostnotification_show,
  134. qeth_bridgeport_hostnotification_store);
  135. static ssize_t qeth_bridgeport_reflect_show(struct device *dev,
  136. struct device_attribute *attr, char *buf)
  137. {
  138. struct qeth_card *card = dev_get_drvdata(dev);
  139. char *state;
  140. if (!card)
  141. return -EINVAL;
  142. if (card->options.sbp.reflect_promisc) {
  143. if (card->options.sbp.reflect_promisc_primary)
  144. state = "primary";
  145. else
  146. state = "secondary";
  147. } else
  148. state = "none";
  149. return sprintf(buf, "%s\n", state);
  150. }
  151. static ssize_t qeth_bridgeport_reflect_store(struct device *dev,
  152. struct device_attribute *attr, const char *buf, size_t count)
  153. {
  154. struct qeth_card *card = dev_get_drvdata(dev);
  155. int enable, primary;
  156. int rc = 0;
  157. if (!card)
  158. return -EINVAL;
  159. if (sysfs_streq(buf, "none")) {
  160. enable = 0;
  161. primary = 0;
  162. } else if (sysfs_streq(buf, "primary")) {
  163. enable = 1;
  164. primary = 1;
  165. } else if (sysfs_streq(buf, "secondary")) {
  166. enable = 1;
  167. primary = 0;
  168. } else
  169. return -EINVAL;
  170. mutex_lock(&card->conf_mutex);
  171. if (card->options.sbp.role != QETH_SBP_ROLE_NONE)
  172. rc = -EPERM;
  173. else {
  174. card->options.sbp.reflect_promisc = enable;
  175. card->options.sbp.reflect_promisc_primary = primary;
  176. rc = 0;
  177. }
  178. mutex_unlock(&card->conf_mutex);
  179. return rc ? rc : count;
  180. }
  181. static DEVICE_ATTR(bridge_reflect_promisc, 0644,
  182. qeth_bridgeport_reflect_show,
  183. qeth_bridgeport_reflect_store);
  184. static struct attribute *qeth_l2_bridgeport_attrs[] = {
  185. &dev_attr_bridge_role.attr,
  186. &dev_attr_bridge_state.attr,
  187. &dev_attr_bridge_hostnotify.attr,
  188. &dev_attr_bridge_reflect_promisc.attr,
  189. NULL,
  190. };
  191. static struct attribute_group qeth_l2_bridgeport_attr_group = {
  192. .attrs = qeth_l2_bridgeport_attrs,
  193. };
  194. int qeth_l2_create_device_attributes(struct device *dev)
  195. {
  196. return sysfs_create_group(&dev->kobj, &qeth_l2_bridgeport_attr_group);
  197. }
  198. void qeth_l2_remove_device_attributes(struct device *dev)
  199. {
  200. sysfs_remove_group(&dev->kobj, &qeth_l2_bridgeport_attr_group);
  201. }
  202. /**
  203. * qeth_l2_setup_bridgeport_attrs() - set/restore attrs when turning online.
  204. * @card: qeth_card structure pointer
  205. *
  206. * Note: this function is called with conf_mutex held by the caller
  207. */
  208. void qeth_l2_setup_bridgeport_attrs(struct qeth_card *card)
  209. {
  210. int rc;
  211. if (!card)
  212. return;
  213. if (!card->options.sbp.supported_funcs)
  214. return;
  215. if (card->options.sbp.role != QETH_SBP_ROLE_NONE) {
  216. /* Conditional to avoid spurious error messages */
  217. qeth_bridgeport_setrole(card, card->options.sbp.role);
  218. /* Let the callback function refresh the stored role value. */
  219. qeth_bridgeport_query_ports(card,
  220. &card->options.sbp.role, NULL);
  221. }
  222. if (card->options.sbp.hostnotification) {
  223. rc = qeth_bridgeport_an_set(card, 1);
  224. if (rc)
  225. card->options.sbp.hostnotification = 0;
  226. } else
  227. qeth_bridgeport_an_set(card, 0);
  228. }
  229. const struct attribute_group *qeth_l2_attr_groups[] = {
  230. &qeth_device_attr_group,
  231. &qeth_device_blkt_group,
  232. /* l2 specific, see l2_{create,remove}_device_attributes(): */
  233. &qeth_l2_bridgeport_attr_group,
  234. NULL,
  235. };