qeth_l3_sys.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright IBM Corp. 2007
  4. * Author(s): Utz Bacher <utz.bacher@de.ibm.com>,
  5. * Frank Pavlic <fpavlic@de.ibm.com>,
  6. * Thomas Spatzier <tspat@de.ibm.com>,
  7. * Frank Blaschka <frank.blaschka@de.ibm.com>
  8. */
  9. #include <linux/slab.h>
  10. #include <asm/ebcdic.h>
  11. #include <linux/hashtable.h>
  12. #include <linux/inet.h>
  13. #include "qeth_l3.h"
  14. #define QETH_DEVICE_ATTR(_id, _name, _mode, _show, _store) \
  15. struct device_attribute dev_attr_##_id = __ATTR(_name, _mode, _show, _store)
  16. static int qeth_l3_string_to_ipaddr(const char *buf,
  17. enum qeth_prot_versions proto, u8 *addr)
  18. {
  19. const char *end;
  20. if ((proto == QETH_PROT_IPV4 && !in4_pton(buf, -1, addr, -1, &end)) ||
  21. (proto == QETH_PROT_IPV6 && !in6_pton(buf, -1, addr, -1, &end)))
  22. return -EINVAL;
  23. return 0;
  24. }
  25. static ssize_t qeth_l3_dev_route_show(struct qeth_card *card,
  26. struct qeth_routing_info *route, char *buf)
  27. {
  28. switch (route->type) {
  29. case PRIMARY_ROUTER:
  30. return sysfs_emit(buf, "%s\n", "primary router");
  31. case SECONDARY_ROUTER:
  32. return sysfs_emit(buf, "%s\n", "secondary router");
  33. case MULTICAST_ROUTER:
  34. if (card->info.broadcast_capable == QETH_BROADCAST_WITHOUT_ECHO)
  35. return sysfs_emit(buf, "%s\n", "multicast router+");
  36. else
  37. return sysfs_emit(buf, "%s\n", "multicast router");
  38. case PRIMARY_CONNECTOR:
  39. if (card->info.broadcast_capable == QETH_BROADCAST_WITHOUT_ECHO)
  40. return sysfs_emit(buf, "%s\n", "primary connector+");
  41. else
  42. return sysfs_emit(buf, "%s\n", "primary connector");
  43. case SECONDARY_CONNECTOR:
  44. if (card->info.broadcast_capable == QETH_BROADCAST_WITHOUT_ECHO)
  45. return sysfs_emit(buf, "%s\n", "secondary connector+");
  46. else
  47. return sysfs_emit(buf, "%s\n", "secondary connector");
  48. default:
  49. return sysfs_emit(buf, "%s\n", "no");
  50. }
  51. }
  52. static ssize_t qeth_l3_dev_route4_show(struct device *dev,
  53. struct device_attribute *attr, char *buf)
  54. {
  55. struct qeth_card *card = dev_get_drvdata(dev);
  56. return qeth_l3_dev_route_show(card, &card->options.route4, buf);
  57. }
  58. static ssize_t qeth_l3_dev_route_store(struct qeth_card *card,
  59. struct qeth_routing_info *route, enum qeth_prot_versions prot,
  60. const char *buf, size_t count)
  61. {
  62. enum qeth_routing_types old_route_type = route->type;
  63. int rc = 0;
  64. mutex_lock(&card->conf_mutex);
  65. if (sysfs_streq(buf, "no_router")) {
  66. route->type = NO_ROUTER;
  67. } else if (sysfs_streq(buf, "primary_connector")) {
  68. route->type = PRIMARY_CONNECTOR;
  69. } else if (sysfs_streq(buf, "secondary_connector")) {
  70. route->type = SECONDARY_CONNECTOR;
  71. } else if (sysfs_streq(buf, "primary_router")) {
  72. route->type = PRIMARY_ROUTER;
  73. } else if (sysfs_streq(buf, "secondary_router")) {
  74. route->type = SECONDARY_ROUTER;
  75. } else if (sysfs_streq(buf, "multicast_router")) {
  76. route->type = MULTICAST_ROUTER;
  77. } else {
  78. rc = -EINVAL;
  79. goto out;
  80. }
  81. if (qeth_card_hw_is_reachable(card) &&
  82. (old_route_type != route->type)) {
  83. if (prot == QETH_PROT_IPV4)
  84. rc = qeth_l3_setrouting_v4(card);
  85. else if (prot == QETH_PROT_IPV6)
  86. rc = qeth_l3_setrouting_v6(card);
  87. }
  88. out:
  89. if (rc)
  90. route->type = old_route_type;
  91. mutex_unlock(&card->conf_mutex);
  92. return rc ? rc : count;
  93. }
  94. static ssize_t qeth_l3_dev_route4_store(struct device *dev,
  95. struct device_attribute *attr, const char *buf, size_t count)
  96. {
  97. struct qeth_card *card = dev_get_drvdata(dev);
  98. return qeth_l3_dev_route_store(card, &card->options.route4,
  99. QETH_PROT_IPV4, buf, count);
  100. }
  101. static DEVICE_ATTR(route4, 0644, qeth_l3_dev_route4_show,
  102. qeth_l3_dev_route4_store);
  103. static ssize_t qeth_l3_dev_route6_show(struct device *dev,
  104. struct device_attribute *attr, char *buf)
  105. {
  106. struct qeth_card *card = dev_get_drvdata(dev);
  107. return qeth_l3_dev_route_show(card, &card->options.route6, buf);
  108. }
  109. static ssize_t qeth_l3_dev_route6_store(struct device *dev,
  110. struct device_attribute *attr, const char *buf, size_t count)
  111. {
  112. struct qeth_card *card = dev_get_drvdata(dev);
  113. return qeth_l3_dev_route_store(card, &card->options.route6,
  114. QETH_PROT_IPV6, buf, count);
  115. }
  116. static DEVICE_ATTR(route6, 0644, qeth_l3_dev_route6_show,
  117. qeth_l3_dev_route6_store);
  118. static ssize_t qeth_l3_dev_sniffer_show(struct device *dev,
  119. struct device_attribute *attr, char *buf)
  120. {
  121. struct qeth_card *card = dev_get_drvdata(dev);
  122. return sysfs_emit(buf, "%i\n", card->options.sniffer ? 1 : 0);
  123. }
  124. static ssize_t qeth_l3_dev_sniffer_store(struct device *dev,
  125. struct device_attribute *attr, const char *buf, size_t count)
  126. {
  127. struct qeth_card *card = dev_get_drvdata(dev);
  128. int rc = 0;
  129. unsigned long i;
  130. if (!IS_IQD(card))
  131. return -EPERM;
  132. if (card->options.cq == QETH_CQ_ENABLED)
  133. return -EPERM;
  134. mutex_lock(&card->conf_mutex);
  135. if (card->state != CARD_STATE_DOWN) {
  136. rc = -EPERM;
  137. goto out;
  138. }
  139. rc = kstrtoul(buf, 16, &i);
  140. if (rc) {
  141. rc = -EINVAL;
  142. goto out;
  143. }
  144. switch (i) {
  145. case 0:
  146. card->options.sniffer = i;
  147. break;
  148. case 1:
  149. qdio_get_ssqd_desc(CARD_DDEV(card), &card->ssqd);
  150. if (card->ssqd.qdioac2 & CHSC_AC2_SNIFFER_AVAILABLE) {
  151. card->options.sniffer = i;
  152. qeth_resize_buffer_pool(card, QETH_IN_BUF_COUNT_MAX);
  153. } else {
  154. rc = -EPERM;
  155. }
  156. break;
  157. default:
  158. rc = -EINVAL;
  159. }
  160. out:
  161. mutex_unlock(&card->conf_mutex);
  162. return rc ? rc : count;
  163. }
  164. static DEVICE_ATTR(sniffer, 0644, qeth_l3_dev_sniffer_show,
  165. qeth_l3_dev_sniffer_store);
  166. static ssize_t qeth_l3_dev_hsuid_show(struct device *dev,
  167. struct device_attribute *attr, char *buf)
  168. {
  169. struct qeth_card *card = dev_get_drvdata(dev);
  170. char tmp_hsuid[9];
  171. if (!IS_IQD(card))
  172. return -EPERM;
  173. memcpy(tmp_hsuid, card->options.hsuid, sizeof(tmp_hsuid));
  174. EBCASC(tmp_hsuid, 8);
  175. return sysfs_emit(buf, "%s\n", tmp_hsuid);
  176. }
  177. static ssize_t qeth_l3_dev_hsuid_store(struct device *dev,
  178. struct device_attribute *attr, const char *buf, size_t count)
  179. {
  180. struct qeth_card *card = dev_get_drvdata(dev);
  181. int rc = 0;
  182. char *tmp;
  183. if (!IS_IQD(card))
  184. return -EPERM;
  185. mutex_lock(&card->conf_mutex);
  186. if (card->state != CARD_STATE_DOWN) {
  187. rc = -EPERM;
  188. goto out;
  189. }
  190. if (card->options.sniffer) {
  191. rc = -EPERM;
  192. goto out;
  193. }
  194. if (card->options.cq == QETH_CQ_NOTAVAILABLE) {
  195. rc = -EPERM;
  196. goto out;
  197. }
  198. tmp = strsep((char **)&buf, "\n");
  199. if (strlen(tmp) > 8) {
  200. rc = -EINVAL;
  201. goto out;
  202. }
  203. if (card->options.hsuid[0])
  204. /* delete old ip address */
  205. qeth_l3_modify_hsuid(card, false);
  206. if (strlen(tmp) == 0) {
  207. /* delete ip address only */
  208. card->options.hsuid[0] = '\0';
  209. memcpy(card->dev->perm_addr, card->options.hsuid, 9);
  210. qeth_configure_cq(card, QETH_CQ_DISABLED);
  211. goto out;
  212. }
  213. if (qeth_configure_cq(card, QETH_CQ_ENABLED)) {
  214. rc = -EPERM;
  215. goto out;
  216. }
  217. scnprintf(card->options.hsuid, sizeof(card->options.hsuid),
  218. "%-8s", tmp);
  219. ASCEBC(card->options.hsuid, 8);
  220. memcpy(card->dev->perm_addr, card->options.hsuid, 9);
  221. rc = qeth_l3_modify_hsuid(card, true);
  222. out:
  223. mutex_unlock(&card->conf_mutex);
  224. return rc ? rc : count;
  225. }
  226. static DEVICE_ATTR(hsuid, 0644, qeth_l3_dev_hsuid_show,
  227. qeth_l3_dev_hsuid_store);
  228. static struct attribute *qeth_l3_device_attrs[] = {
  229. &dev_attr_route4.attr,
  230. &dev_attr_route6.attr,
  231. &dev_attr_sniffer.attr,
  232. &dev_attr_hsuid.attr,
  233. NULL,
  234. };
  235. static const struct attribute_group qeth_l3_device_attr_group = {
  236. .attrs = qeth_l3_device_attrs,
  237. };
  238. static ssize_t qeth_l3_dev_ipato_enable_show(struct device *dev,
  239. struct device_attribute *attr, char *buf)
  240. {
  241. struct qeth_card *card = dev_get_drvdata(dev);
  242. return sysfs_emit(buf, "%u\n", card->ipato.enabled ? 1 : 0);
  243. }
  244. static ssize_t qeth_l3_dev_ipato_enable_store(struct device *dev,
  245. struct device_attribute *attr, const char *buf, size_t count)
  246. {
  247. struct qeth_card *card = dev_get_drvdata(dev);
  248. bool enable;
  249. int rc = 0;
  250. mutex_lock(&card->conf_mutex);
  251. if (card->state != CARD_STATE_DOWN) {
  252. rc = -EPERM;
  253. goto out;
  254. }
  255. mutex_lock(&card->ip_lock);
  256. if (sysfs_streq(buf, "toggle")) {
  257. enable = !card->ipato.enabled;
  258. } else if (kstrtobool(buf, &enable)) {
  259. rc = -EINVAL;
  260. goto unlock_ip;
  261. }
  262. if (card->ipato.enabled != enable) {
  263. card->ipato.enabled = enable;
  264. qeth_l3_update_ipato(card);
  265. }
  266. unlock_ip:
  267. mutex_unlock(&card->ip_lock);
  268. out:
  269. mutex_unlock(&card->conf_mutex);
  270. return rc ? rc : count;
  271. }
  272. static QETH_DEVICE_ATTR(ipato_enable, enable, 0644,
  273. qeth_l3_dev_ipato_enable_show,
  274. qeth_l3_dev_ipato_enable_store);
  275. static ssize_t qeth_l3_dev_ipato_invert4_show(struct device *dev,
  276. struct device_attribute *attr, char *buf)
  277. {
  278. struct qeth_card *card = dev_get_drvdata(dev);
  279. return sysfs_emit(buf, "%u\n", card->ipato.invert4 ? 1 : 0);
  280. }
  281. static ssize_t qeth_l3_dev_ipato_invert4_store(struct device *dev,
  282. struct device_attribute *attr,
  283. const char *buf, size_t count)
  284. {
  285. struct qeth_card *card = dev_get_drvdata(dev);
  286. bool invert;
  287. int rc = 0;
  288. mutex_lock(&card->ip_lock);
  289. if (sysfs_streq(buf, "toggle")) {
  290. invert = !card->ipato.invert4;
  291. } else if (kstrtobool(buf, &invert)) {
  292. rc = -EINVAL;
  293. goto out;
  294. }
  295. if (card->ipato.invert4 != invert) {
  296. card->ipato.invert4 = invert;
  297. qeth_l3_update_ipato(card);
  298. }
  299. out:
  300. mutex_unlock(&card->ip_lock);
  301. return rc ? rc : count;
  302. }
  303. static QETH_DEVICE_ATTR(ipato_invert4, invert4, 0644,
  304. qeth_l3_dev_ipato_invert4_show,
  305. qeth_l3_dev_ipato_invert4_store);
  306. static ssize_t qeth_l3_dev_ipato_add_show(char *buf, struct qeth_card *card,
  307. enum qeth_prot_versions proto)
  308. {
  309. struct qeth_ipato_entry *ipatoe;
  310. char addr_str[INET6_ADDRSTRLEN];
  311. int offset = 0;
  312. mutex_lock(&card->ip_lock);
  313. list_for_each_entry(ipatoe, &card->ipato.entries, entry) {
  314. if (ipatoe->proto != proto)
  315. continue;
  316. qeth_l3_ipaddr_to_string(proto, ipatoe->addr, addr_str);
  317. offset += sysfs_emit_at(buf, offset, "%s/%i\n",
  318. addr_str, ipatoe->mask_bits);
  319. }
  320. mutex_unlock(&card->ip_lock);
  321. return offset ? offset : sysfs_emit(buf, "\n");
  322. }
  323. static ssize_t qeth_l3_dev_ipato_add4_show(struct device *dev,
  324. struct device_attribute *attr, char *buf)
  325. {
  326. struct qeth_card *card = dev_get_drvdata(dev);
  327. return qeth_l3_dev_ipato_add_show(buf, card, QETH_PROT_IPV4);
  328. }
  329. static int qeth_l3_parse_ipatoe(const char *buf, enum qeth_prot_versions proto,
  330. u8 *addr, unsigned int *mask_bits)
  331. {
  332. char *sep;
  333. int rc;
  334. /* Expected input pattern: %addr/%mask */
  335. sep = strnchr(buf, INET6_ADDRSTRLEN, '/');
  336. if (!sep)
  337. return -EINVAL;
  338. /* Terminate the %addr sub-string, and parse it: */
  339. *sep = '\0';
  340. rc = qeth_l3_string_to_ipaddr(buf, proto, addr);
  341. if (rc)
  342. return rc;
  343. rc = kstrtouint(sep + 1, 10, mask_bits);
  344. if (rc)
  345. return rc;
  346. if (*mask_bits > ((proto == QETH_PROT_IPV4) ? 32 : 128))
  347. return -EINVAL;
  348. return 0;
  349. }
  350. static ssize_t qeth_l3_dev_ipato_add_store(const char *buf, size_t count,
  351. struct qeth_card *card, enum qeth_prot_versions proto)
  352. {
  353. struct qeth_ipato_entry *ipatoe;
  354. unsigned int mask_bits;
  355. u8 addr[16];
  356. int rc = 0;
  357. rc = qeth_l3_parse_ipatoe(buf, proto, addr, &mask_bits);
  358. if (rc)
  359. return rc;
  360. ipatoe = kzalloc(sizeof(struct qeth_ipato_entry), GFP_KERNEL);
  361. if (!ipatoe)
  362. return -ENOMEM;
  363. ipatoe->proto = proto;
  364. memcpy(ipatoe->addr, addr, (proto == QETH_PROT_IPV4) ? 4 : 16);
  365. ipatoe->mask_bits = mask_bits;
  366. rc = qeth_l3_add_ipato_entry(card, ipatoe);
  367. if (rc)
  368. kfree(ipatoe);
  369. return rc ? rc : count;
  370. }
  371. static ssize_t qeth_l3_dev_ipato_add4_store(struct device *dev,
  372. struct device_attribute *attr, const char *buf, size_t count)
  373. {
  374. struct qeth_card *card = dev_get_drvdata(dev);
  375. return qeth_l3_dev_ipato_add_store(buf, count, card, QETH_PROT_IPV4);
  376. }
  377. static QETH_DEVICE_ATTR(ipato_add4, add4, 0644,
  378. qeth_l3_dev_ipato_add4_show,
  379. qeth_l3_dev_ipato_add4_store);
  380. static ssize_t qeth_l3_dev_ipato_del_store(const char *buf, size_t count,
  381. struct qeth_card *card, enum qeth_prot_versions proto)
  382. {
  383. unsigned int mask_bits;
  384. u8 addr[16];
  385. int rc = 0;
  386. rc = qeth_l3_parse_ipatoe(buf, proto, addr, &mask_bits);
  387. if (!rc)
  388. rc = qeth_l3_del_ipato_entry(card, proto, addr, mask_bits);
  389. return rc ? rc : count;
  390. }
  391. static ssize_t qeth_l3_dev_ipato_del4_store(struct device *dev,
  392. struct device_attribute *attr, const char *buf, size_t count)
  393. {
  394. struct qeth_card *card = dev_get_drvdata(dev);
  395. return qeth_l3_dev_ipato_del_store(buf, count, card, QETH_PROT_IPV4);
  396. }
  397. static QETH_DEVICE_ATTR(ipato_del4, del4, 0200, NULL,
  398. qeth_l3_dev_ipato_del4_store);
  399. static ssize_t qeth_l3_dev_ipato_invert6_show(struct device *dev,
  400. struct device_attribute *attr, char *buf)
  401. {
  402. struct qeth_card *card = dev_get_drvdata(dev);
  403. return sysfs_emit(buf, "%u\n", card->ipato.invert6 ? 1 : 0);
  404. }
  405. static ssize_t qeth_l3_dev_ipato_invert6_store(struct device *dev,
  406. struct device_attribute *attr, const char *buf, size_t count)
  407. {
  408. struct qeth_card *card = dev_get_drvdata(dev);
  409. bool invert;
  410. int rc = 0;
  411. mutex_lock(&card->ip_lock);
  412. if (sysfs_streq(buf, "toggle")) {
  413. invert = !card->ipato.invert6;
  414. } else if (kstrtobool(buf, &invert)) {
  415. rc = -EINVAL;
  416. goto out;
  417. }
  418. if (card->ipato.invert6 != invert) {
  419. card->ipato.invert6 = invert;
  420. qeth_l3_update_ipato(card);
  421. }
  422. out:
  423. mutex_unlock(&card->ip_lock);
  424. return rc ? rc : count;
  425. }
  426. static QETH_DEVICE_ATTR(ipato_invert6, invert6, 0644,
  427. qeth_l3_dev_ipato_invert6_show,
  428. qeth_l3_dev_ipato_invert6_store);
  429. static ssize_t qeth_l3_dev_ipato_add6_show(struct device *dev,
  430. struct device_attribute *attr, char *buf)
  431. {
  432. struct qeth_card *card = dev_get_drvdata(dev);
  433. return qeth_l3_dev_ipato_add_show(buf, card, QETH_PROT_IPV6);
  434. }
  435. static ssize_t qeth_l3_dev_ipato_add6_store(struct device *dev,
  436. struct device_attribute *attr, const char *buf, size_t count)
  437. {
  438. struct qeth_card *card = dev_get_drvdata(dev);
  439. return qeth_l3_dev_ipato_add_store(buf, count, card, QETH_PROT_IPV6);
  440. }
  441. static QETH_DEVICE_ATTR(ipato_add6, add6, 0644,
  442. qeth_l3_dev_ipato_add6_show,
  443. qeth_l3_dev_ipato_add6_store);
  444. static ssize_t qeth_l3_dev_ipato_del6_store(struct device *dev,
  445. struct device_attribute *attr, const char *buf, size_t count)
  446. {
  447. struct qeth_card *card = dev_get_drvdata(dev);
  448. return qeth_l3_dev_ipato_del_store(buf, count, card, QETH_PROT_IPV6);
  449. }
  450. static QETH_DEVICE_ATTR(ipato_del6, del6, 0200, NULL,
  451. qeth_l3_dev_ipato_del6_store);
  452. static struct attribute *qeth_ipato_device_attrs[] = {
  453. &dev_attr_ipato_enable.attr,
  454. &dev_attr_ipato_invert4.attr,
  455. &dev_attr_ipato_add4.attr,
  456. &dev_attr_ipato_del4.attr,
  457. &dev_attr_ipato_invert6.attr,
  458. &dev_attr_ipato_add6.attr,
  459. &dev_attr_ipato_del6.attr,
  460. NULL,
  461. };
  462. static const struct attribute_group qeth_device_ipato_group = {
  463. .name = "ipa_takeover",
  464. .attrs = qeth_ipato_device_attrs,
  465. };
  466. static ssize_t qeth_l3_dev_ip_add_show(struct device *dev, char *buf,
  467. enum qeth_prot_versions proto,
  468. enum qeth_ip_types type)
  469. {
  470. struct qeth_card *card = dev_get_drvdata(dev);
  471. char addr_str[INET6_ADDRSTRLEN];
  472. struct qeth_ipaddr *ipaddr;
  473. int offset = 0;
  474. int i;
  475. mutex_lock(&card->ip_lock);
  476. hash_for_each(card->ip_htable, i, ipaddr, hnode) {
  477. if (ipaddr->proto != proto || ipaddr->type != type)
  478. continue;
  479. qeth_l3_ipaddr_to_string(proto, (u8 *)&ipaddr->u, addr_str);
  480. offset += sysfs_emit_at(buf, offset, "%s\n", addr_str);
  481. }
  482. mutex_unlock(&card->ip_lock);
  483. return offset ? offset : sysfs_emit(buf, "\n");
  484. }
  485. static ssize_t qeth_l3_dev_vipa_add4_show(struct device *dev,
  486. struct device_attribute *attr,
  487. char *buf)
  488. {
  489. return qeth_l3_dev_ip_add_show(dev, buf, QETH_PROT_IPV4,
  490. QETH_IP_TYPE_VIPA);
  491. }
  492. static ssize_t qeth_l3_vipa_store(struct device *dev, const char *buf, bool add,
  493. size_t count, enum qeth_prot_versions proto)
  494. {
  495. struct qeth_card *card = dev_get_drvdata(dev);
  496. u8 addr[16] = {0, };
  497. int rc;
  498. rc = qeth_l3_string_to_ipaddr(buf, proto, addr);
  499. if (!rc)
  500. rc = qeth_l3_modify_rxip_vipa(card, add, addr,
  501. QETH_IP_TYPE_VIPA, proto);
  502. return rc ? rc : count;
  503. }
  504. static ssize_t qeth_l3_dev_vipa_add4_store(struct device *dev,
  505. struct device_attribute *attr, const char *buf, size_t count)
  506. {
  507. return qeth_l3_vipa_store(dev, buf, true, count, QETH_PROT_IPV4);
  508. }
  509. static QETH_DEVICE_ATTR(vipa_add4, add4, 0644,
  510. qeth_l3_dev_vipa_add4_show,
  511. qeth_l3_dev_vipa_add4_store);
  512. static ssize_t qeth_l3_dev_vipa_del4_store(struct device *dev,
  513. struct device_attribute *attr, const char *buf, size_t count)
  514. {
  515. return qeth_l3_vipa_store(dev, buf, false, count, QETH_PROT_IPV4);
  516. }
  517. static QETH_DEVICE_ATTR(vipa_del4, del4, 0200, NULL,
  518. qeth_l3_dev_vipa_del4_store);
  519. static ssize_t qeth_l3_dev_vipa_add6_show(struct device *dev,
  520. struct device_attribute *attr,
  521. char *buf)
  522. {
  523. return qeth_l3_dev_ip_add_show(dev, buf, QETH_PROT_IPV6,
  524. QETH_IP_TYPE_VIPA);
  525. }
  526. static ssize_t qeth_l3_dev_vipa_add6_store(struct device *dev,
  527. struct device_attribute *attr, const char *buf, size_t count)
  528. {
  529. return qeth_l3_vipa_store(dev, buf, true, count, QETH_PROT_IPV6);
  530. }
  531. static QETH_DEVICE_ATTR(vipa_add6, add6, 0644,
  532. qeth_l3_dev_vipa_add6_show,
  533. qeth_l3_dev_vipa_add6_store);
  534. static ssize_t qeth_l3_dev_vipa_del6_store(struct device *dev,
  535. struct device_attribute *attr, const char *buf, size_t count)
  536. {
  537. return qeth_l3_vipa_store(dev, buf, false, count, QETH_PROT_IPV6);
  538. }
  539. static QETH_DEVICE_ATTR(vipa_del6, del6, 0200, NULL,
  540. qeth_l3_dev_vipa_del6_store);
  541. static struct attribute *qeth_vipa_device_attrs[] = {
  542. &dev_attr_vipa_add4.attr,
  543. &dev_attr_vipa_del4.attr,
  544. &dev_attr_vipa_add6.attr,
  545. &dev_attr_vipa_del6.attr,
  546. NULL,
  547. };
  548. static const struct attribute_group qeth_device_vipa_group = {
  549. .name = "vipa",
  550. .attrs = qeth_vipa_device_attrs,
  551. };
  552. static ssize_t qeth_l3_dev_rxip_add4_show(struct device *dev,
  553. struct device_attribute *attr,
  554. char *buf)
  555. {
  556. return qeth_l3_dev_ip_add_show(dev, buf, QETH_PROT_IPV4,
  557. QETH_IP_TYPE_RXIP);
  558. }
  559. static int qeth_l3_parse_rxipe(const char *buf, enum qeth_prot_versions proto,
  560. u8 *addr)
  561. {
  562. __be32 ipv4_addr;
  563. struct in6_addr ipv6_addr;
  564. if (qeth_l3_string_to_ipaddr(buf, proto, addr)) {
  565. return -EINVAL;
  566. }
  567. if (proto == QETH_PROT_IPV4) {
  568. memcpy(&ipv4_addr, addr, sizeof(ipv4_addr));
  569. if (ipv4_is_multicast(ipv4_addr)) {
  570. QETH_DBF_MESSAGE(2, "multicast rxip not supported.\n");
  571. return -EINVAL;
  572. }
  573. } else if (proto == QETH_PROT_IPV6) {
  574. memcpy(&ipv6_addr, addr, sizeof(ipv6_addr));
  575. if (ipv6_addr_is_multicast(&ipv6_addr)) {
  576. QETH_DBF_MESSAGE(2, "multicast rxip not supported.\n");
  577. return -EINVAL;
  578. }
  579. }
  580. return 0;
  581. }
  582. static ssize_t qeth_l3_rxip_store(struct device *dev, const char *buf, bool add,
  583. size_t count, enum qeth_prot_versions proto)
  584. {
  585. struct qeth_card *card = dev_get_drvdata(dev);
  586. u8 addr[16] = {0, };
  587. int rc;
  588. rc = qeth_l3_parse_rxipe(buf, proto, addr);
  589. if (!rc)
  590. rc = qeth_l3_modify_rxip_vipa(card, add, addr,
  591. QETH_IP_TYPE_RXIP, proto);
  592. return rc ? rc : count;
  593. }
  594. static ssize_t qeth_l3_dev_rxip_add4_store(struct device *dev,
  595. struct device_attribute *attr, const char *buf, size_t count)
  596. {
  597. return qeth_l3_rxip_store(dev, buf, true, count, QETH_PROT_IPV4);
  598. }
  599. static QETH_DEVICE_ATTR(rxip_add4, add4, 0644,
  600. qeth_l3_dev_rxip_add4_show,
  601. qeth_l3_dev_rxip_add4_store);
  602. static ssize_t qeth_l3_dev_rxip_del4_store(struct device *dev,
  603. struct device_attribute *attr, const char *buf, size_t count)
  604. {
  605. return qeth_l3_rxip_store(dev, buf, false, count, QETH_PROT_IPV4);
  606. }
  607. static QETH_DEVICE_ATTR(rxip_del4, del4, 0200, NULL,
  608. qeth_l3_dev_rxip_del4_store);
  609. static ssize_t qeth_l3_dev_rxip_add6_show(struct device *dev,
  610. struct device_attribute *attr,
  611. char *buf)
  612. {
  613. return qeth_l3_dev_ip_add_show(dev, buf, QETH_PROT_IPV6,
  614. QETH_IP_TYPE_RXIP);
  615. }
  616. static ssize_t qeth_l3_dev_rxip_add6_store(struct device *dev,
  617. struct device_attribute *attr, const char *buf, size_t count)
  618. {
  619. return qeth_l3_rxip_store(dev, buf, true, count, QETH_PROT_IPV6);
  620. }
  621. static QETH_DEVICE_ATTR(rxip_add6, add6, 0644,
  622. qeth_l3_dev_rxip_add6_show,
  623. qeth_l3_dev_rxip_add6_store);
  624. static ssize_t qeth_l3_dev_rxip_del6_store(struct device *dev,
  625. struct device_attribute *attr, const char *buf, size_t count)
  626. {
  627. return qeth_l3_rxip_store(dev, buf, false, count, QETH_PROT_IPV6);
  628. }
  629. static QETH_DEVICE_ATTR(rxip_del6, del6, 0200, NULL,
  630. qeth_l3_dev_rxip_del6_store);
  631. static struct attribute *qeth_rxip_device_attrs[] = {
  632. &dev_attr_rxip_add4.attr,
  633. &dev_attr_rxip_del4.attr,
  634. &dev_attr_rxip_add6.attr,
  635. &dev_attr_rxip_del6.attr,
  636. NULL,
  637. };
  638. static const struct attribute_group qeth_device_rxip_group = {
  639. .name = "rxip",
  640. .attrs = qeth_rxip_device_attrs,
  641. };
  642. const struct attribute_group *qeth_l3_attr_groups[] = {
  643. &qeth_l3_device_attr_group,
  644. &qeth_device_ipato_group,
  645. &qeth_device_vipa_group,
  646. &qeth_device_rxip_group,
  647. NULL,
  648. };