qeth_l2_sys.c 6.5 KB

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