qeth_l3_sys.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright IBM Corp. 2007
  4. * Author(s): Utz Bacher <[email protected]>,
  5. * Frank Pavlic <[email protected]>,
  6. * Thomas Spatzier <[email protected]>,
  7. * Frank Blaschka <[email protected]>
  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 sprintf(buf, "%s\n", "primary router");
  31. case SECONDARY_ROUTER:
  32. return sprintf(buf, "%s\n", "secondary router");
  33. case MULTICAST_ROUTER:
  34. if (card->info.broadcast_capable == QETH_BROADCAST_WITHOUT_ECHO)
  35. return sprintf(buf, "%s\n", "multicast router+");
  36. else
  37. return sprintf(buf, "%s\n", "multicast router");
  38. case PRIMARY_CONNECTOR:
  39. if (card->info.broadcast_capable == QETH_BROADCAST_WITHOUT_ECHO)
  40. return sprintf(buf, "%s\n", "primary connector+");
  41. else
  42. return sprintf(buf, "%s\n", "primary connector");
  43. case SECONDARY_CONNECTOR:
  44. if (card->info.broadcast_capable == QETH_BROADCAST_WITHOUT_ECHO)
  45. return sprintf(buf, "%s\n", "secondary connector+");
  46. else
  47. return sprintf(buf, "%s\n", "secondary connector");
  48. default:
  49. return sprintf(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 sprintf(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 sprintf(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. snprintf(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 sprintf(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 sprintf(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. int str_len = 0;
  311. mutex_lock(&card->ip_lock);
  312. list_for_each_entry(ipatoe, &card->ipato.entries, entry) {
  313. char addr_str[40];
  314. int entry_len;
  315. if (ipatoe->proto != proto)
  316. continue;
  317. entry_len = qeth_l3_ipaddr_to_string(proto, ipatoe->addr,
  318. addr_str);
  319. if (entry_len < 0)
  320. continue;
  321. /* Append /%mask to the entry: */
  322. entry_len += 1 + ((proto == QETH_PROT_IPV4) ? 2 : 3);
  323. /* Enough room to format %entry\n into null terminated page? */
  324. if (entry_len + 1 > PAGE_SIZE - str_len - 1)
  325. break;
  326. entry_len = scnprintf(buf, PAGE_SIZE - str_len,
  327. "%s/%i\n", addr_str, ipatoe->mask_bits);
  328. str_len += entry_len;
  329. buf += entry_len;
  330. }
  331. mutex_unlock(&card->ip_lock);
  332. return str_len ? str_len : scnprintf(buf, PAGE_SIZE, "\n");
  333. }
  334. static ssize_t qeth_l3_dev_ipato_add4_show(struct device *dev,
  335. struct device_attribute *attr, char *buf)
  336. {
  337. struct qeth_card *card = dev_get_drvdata(dev);
  338. return qeth_l3_dev_ipato_add_show(buf, card, QETH_PROT_IPV4);
  339. }
  340. static int qeth_l3_parse_ipatoe(const char *buf, enum qeth_prot_versions proto,
  341. u8 *addr, unsigned int *mask_bits)
  342. {
  343. char *sep;
  344. int rc;
  345. /* Expected input pattern: %addr/%mask */
  346. sep = strnchr(buf, 40, '/');
  347. if (!sep)
  348. return -EINVAL;
  349. /* Terminate the %addr sub-string, and parse it: */
  350. *sep = '\0';
  351. rc = qeth_l3_string_to_ipaddr(buf, proto, addr);
  352. if (rc)
  353. return rc;
  354. rc = kstrtouint(sep + 1, 10, mask_bits);
  355. if (rc)
  356. return rc;
  357. if (*mask_bits > ((proto == QETH_PROT_IPV4) ? 32 : 128))
  358. return -EINVAL;
  359. return 0;
  360. }
  361. static ssize_t qeth_l3_dev_ipato_add_store(const char *buf, size_t count,
  362. struct qeth_card *card, enum qeth_prot_versions proto)
  363. {
  364. struct qeth_ipato_entry *ipatoe;
  365. unsigned int mask_bits;
  366. u8 addr[16];
  367. int rc = 0;
  368. rc = qeth_l3_parse_ipatoe(buf, proto, addr, &mask_bits);
  369. if (rc)
  370. return rc;
  371. ipatoe = kzalloc(sizeof(struct qeth_ipato_entry), GFP_KERNEL);
  372. if (!ipatoe)
  373. return -ENOMEM;
  374. ipatoe->proto = proto;
  375. memcpy(ipatoe->addr, addr, (proto == QETH_PROT_IPV4) ? 4 : 16);
  376. ipatoe->mask_bits = mask_bits;
  377. rc = qeth_l3_add_ipato_entry(card, ipatoe);
  378. if (rc)
  379. kfree(ipatoe);
  380. return rc ? rc : count;
  381. }
  382. static ssize_t qeth_l3_dev_ipato_add4_store(struct device *dev,
  383. struct device_attribute *attr, const char *buf, size_t count)
  384. {
  385. struct qeth_card *card = dev_get_drvdata(dev);
  386. return qeth_l3_dev_ipato_add_store(buf, count, card, QETH_PROT_IPV4);
  387. }
  388. static QETH_DEVICE_ATTR(ipato_add4, add4, 0644,
  389. qeth_l3_dev_ipato_add4_show,
  390. qeth_l3_dev_ipato_add4_store);
  391. static ssize_t qeth_l3_dev_ipato_del_store(const char *buf, size_t count,
  392. struct qeth_card *card, enum qeth_prot_versions proto)
  393. {
  394. unsigned int mask_bits;
  395. u8 addr[16];
  396. int rc = 0;
  397. rc = qeth_l3_parse_ipatoe(buf, proto, addr, &mask_bits);
  398. if (!rc)
  399. rc = qeth_l3_del_ipato_entry(card, proto, addr, mask_bits);
  400. return rc ? rc : count;
  401. }
  402. static ssize_t qeth_l3_dev_ipato_del4_store(struct device *dev,
  403. struct device_attribute *attr, const char *buf, size_t count)
  404. {
  405. struct qeth_card *card = dev_get_drvdata(dev);
  406. return qeth_l3_dev_ipato_del_store(buf, count, card, QETH_PROT_IPV4);
  407. }
  408. static QETH_DEVICE_ATTR(ipato_del4, del4, 0200, NULL,
  409. qeth_l3_dev_ipato_del4_store);
  410. static ssize_t qeth_l3_dev_ipato_invert6_show(struct device *dev,
  411. struct device_attribute *attr, char *buf)
  412. {
  413. struct qeth_card *card = dev_get_drvdata(dev);
  414. return sprintf(buf, "%u\n", card->ipato.invert6 ? 1 : 0);
  415. }
  416. static ssize_t qeth_l3_dev_ipato_invert6_store(struct device *dev,
  417. struct device_attribute *attr, const char *buf, size_t count)
  418. {
  419. struct qeth_card *card = dev_get_drvdata(dev);
  420. bool invert;
  421. int rc = 0;
  422. mutex_lock(&card->ip_lock);
  423. if (sysfs_streq(buf, "toggle")) {
  424. invert = !card->ipato.invert6;
  425. } else if (kstrtobool(buf, &invert)) {
  426. rc = -EINVAL;
  427. goto out;
  428. }
  429. if (card->ipato.invert6 != invert) {
  430. card->ipato.invert6 = invert;
  431. qeth_l3_update_ipato(card);
  432. }
  433. out:
  434. mutex_unlock(&card->ip_lock);
  435. return rc ? rc : count;
  436. }
  437. static QETH_DEVICE_ATTR(ipato_invert6, invert6, 0644,
  438. qeth_l3_dev_ipato_invert6_show,
  439. qeth_l3_dev_ipato_invert6_store);
  440. static ssize_t qeth_l3_dev_ipato_add6_show(struct device *dev,
  441. struct device_attribute *attr, char *buf)
  442. {
  443. struct qeth_card *card = dev_get_drvdata(dev);
  444. return qeth_l3_dev_ipato_add_show(buf, card, QETH_PROT_IPV6);
  445. }
  446. static ssize_t qeth_l3_dev_ipato_add6_store(struct device *dev,
  447. struct device_attribute *attr, const char *buf, size_t count)
  448. {
  449. struct qeth_card *card = dev_get_drvdata(dev);
  450. return qeth_l3_dev_ipato_add_store(buf, count, card, QETH_PROT_IPV6);
  451. }
  452. static QETH_DEVICE_ATTR(ipato_add6, add6, 0644,
  453. qeth_l3_dev_ipato_add6_show,
  454. qeth_l3_dev_ipato_add6_store);
  455. static ssize_t qeth_l3_dev_ipato_del6_store(struct device *dev,
  456. struct device_attribute *attr, const char *buf, size_t count)
  457. {
  458. struct qeth_card *card = dev_get_drvdata(dev);
  459. return qeth_l3_dev_ipato_del_store(buf, count, card, QETH_PROT_IPV6);
  460. }
  461. static QETH_DEVICE_ATTR(ipato_del6, del6, 0200, NULL,
  462. qeth_l3_dev_ipato_del6_store);
  463. static struct attribute *qeth_ipato_device_attrs[] = {
  464. &dev_attr_ipato_enable.attr,
  465. &dev_attr_ipato_invert4.attr,
  466. &dev_attr_ipato_add4.attr,
  467. &dev_attr_ipato_del4.attr,
  468. &dev_attr_ipato_invert6.attr,
  469. &dev_attr_ipato_add6.attr,
  470. &dev_attr_ipato_del6.attr,
  471. NULL,
  472. };
  473. static const struct attribute_group qeth_device_ipato_group = {
  474. .name = "ipa_takeover",
  475. .attrs = qeth_ipato_device_attrs,
  476. };
  477. static ssize_t qeth_l3_dev_ip_add_show(struct device *dev, char *buf,
  478. enum qeth_prot_versions proto,
  479. enum qeth_ip_types type)
  480. {
  481. struct qeth_card *card = dev_get_drvdata(dev);
  482. struct qeth_ipaddr *ipaddr;
  483. int str_len = 0;
  484. int i;
  485. mutex_lock(&card->ip_lock);
  486. hash_for_each(card->ip_htable, i, ipaddr, hnode) {
  487. char addr_str[40];
  488. int entry_len;
  489. if (ipaddr->proto != proto || ipaddr->type != type)
  490. continue;
  491. entry_len = qeth_l3_ipaddr_to_string(proto, (u8 *)&ipaddr->u,
  492. addr_str);
  493. if (entry_len < 0)
  494. continue;
  495. /* Enough room to format %addr\n into null terminated page? */
  496. if (entry_len + 1 > PAGE_SIZE - str_len - 1)
  497. break;
  498. entry_len = scnprintf(buf, PAGE_SIZE - str_len, "%s\n",
  499. addr_str);
  500. str_len += entry_len;
  501. buf += entry_len;
  502. }
  503. mutex_unlock(&card->ip_lock);
  504. return str_len ? str_len : scnprintf(buf, PAGE_SIZE, "\n");
  505. }
  506. static ssize_t qeth_l3_dev_vipa_add4_show(struct device *dev,
  507. struct device_attribute *attr,
  508. char *buf)
  509. {
  510. return qeth_l3_dev_ip_add_show(dev, buf, QETH_PROT_IPV4,
  511. QETH_IP_TYPE_VIPA);
  512. }
  513. static ssize_t qeth_l3_vipa_store(struct device *dev, const char *buf, bool add,
  514. size_t count, enum qeth_prot_versions proto)
  515. {
  516. struct qeth_card *card = dev_get_drvdata(dev);
  517. u8 addr[16] = {0, };
  518. int rc;
  519. rc = qeth_l3_string_to_ipaddr(buf, proto, addr);
  520. if (!rc)
  521. rc = qeth_l3_modify_rxip_vipa(card, add, addr,
  522. QETH_IP_TYPE_VIPA, proto);
  523. return rc ? rc : count;
  524. }
  525. static ssize_t qeth_l3_dev_vipa_add4_store(struct device *dev,
  526. struct device_attribute *attr, const char *buf, size_t count)
  527. {
  528. return qeth_l3_vipa_store(dev, buf, true, count, QETH_PROT_IPV4);
  529. }
  530. static QETH_DEVICE_ATTR(vipa_add4, add4, 0644,
  531. qeth_l3_dev_vipa_add4_show,
  532. qeth_l3_dev_vipa_add4_store);
  533. static ssize_t qeth_l3_dev_vipa_del4_store(struct device *dev,
  534. struct device_attribute *attr, const char *buf, size_t count)
  535. {
  536. return qeth_l3_vipa_store(dev, buf, false, count, QETH_PROT_IPV4);
  537. }
  538. static QETH_DEVICE_ATTR(vipa_del4, del4, 0200, NULL,
  539. qeth_l3_dev_vipa_del4_store);
  540. static ssize_t qeth_l3_dev_vipa_add6_show(struct device *dev,
  541. struct device_attribute *attr,
  542. char *buf)
  543. {
  544. return qeth_l3_dev_ip_add_show(dev, buf, QETH_PROT_IPV6,
  545. QETH_IP_TYPE_VIPA);
  546. }
  547. static ssize_t qeth_l3_dev_vipa_add6_store(struct device *dev,
  548. struct device_attribute *attr, const char *buf, size_t count)
  549. {
  550. return qeth_l3_vipa_store(dev, buf, true, count, QETH_PROT_IPV6);
  551. }
  552. static QETH_DEVICE_ATTR(vipa_add6, add6, 0644,
  553. qeth_l3_dev_vipa_add6_show,
  554. qeth_l3_dev_vipa_add6_store);
  555. static ssize_t qeth_l3_dev_vipa_del6_store(struct device *dev,
  556. struct device_attribute *attr, const char *buf, size_t count)
  557. {
  558. return qeth_l3_vipa_store(dev, buf, false, count, QETH_PROT_IPV6);
  559. }
  560. static QETH_DEVICE_ATTR(vipa_del6, del6, 0200, NULL,
  561. qeth_l3_dev_vipa_del6_store);
  562. static struct attribute *qeth_vipa_device_attrs[] = {
  563. &dev_attr_vipa_add4.attr,
  564. &dev_attr_vipa_del4.attr,
  565. &dev_attr_vipa_add6.attr,
  566. &dev_attr_vipa_del6.attr,
  567. NULL,
  568. };
  569. static const struct attribute_group qeth_device_vipa_group = {
  570. .name = "vipa",
  571. .attrs = qeth_vipa_device_attrs,
  572. };
  573. static ssize_t qeth_l3_dev_rxip_add4_show(struct device *dev,
  574. struct device_attribute *attr,
  575. char *buf)
  576. {
  577. return qeth_l3_dev_ip_add_show(dev, buf, QETH_PROT_IPV4,
  578. QETH_IP_TYPE_RXIP);
  579. }
  580. static int qeth_l3_parse_rxipe(const char *buf, enum qeth_prot_versions proto,
  581. u8 *addr)
  582. {
  583. __be32 ipv4_addr;
  584. struct in6_addr ipv6_addr;
  585. if (qeth_l3_string_to_ipaddr(buf, proto, addr)) {
  586. return -EINVAL;
  587. }
  588. if (proto == QETH_PROT_IPV4) {
  589. memcpy(&ipv4_addr, addr, sizeof(ipv4_addr));
  590. if (ipv4_is_multicast(ipv4_addr)) {
  591. QETH_DBF_MESSAGE(2, "multicast rxip not supported.\n");
  592. return -EINVAL;
  593. }
  594. } else if (proto == QETH_PROT_IPV6) {
  595. memcpy(&ipv6_addr, addr, sizeof(ipv6_addr));
  596. if (ipv6_addr_is_multicast(&ipv6_addr)) {
  597. QETH_DBF_MESSAGE(2, "multicast rxip not supported.\n");
  598. return -EINVAL;
  599. }
  600. }
  601. return 0;
  602. }
  603. static ssize_t qeth_l3_rxip_store(struct device *dev, const char *buf, bool add,
  604. size_t count, enum qeth_prot_versions proto)
  605. {
  606. struct qeth_card *card = dev_get_drvdata(dev);
  607. u8 addr[16] = {0, };
  608. int rc;
  609. rc = qeth_l3_parse_rxipe(buf, proto, addr);
  610. if (!rc)
  611. rc = qeth_l3_modify_rxip_vipa(card, add, addr,
  612. QETH_IP_TYPE_RXIP, proto);
  613. return rc ? rc : count;
  614. }
  615. static ssize_t qeth_l3_dev_rxip_add4_store(struct device *dev,
  616. struct device_attribute *attr, const char *buf, size_t count)
  617. {
  618. return qeth_l3_rxip_store(dev, buf, true, count, QETH_PROT_IPV4);
  619. }
  620. static QETH_DEVICE_ATTR(rxip_add4, add4, 0644,
  621. qeth_l3_dev_rxip_add4_show,
  622. qeth_l3_dev_rxip_add4_store);
  623. static ssize_t qeth_l3_dev_rxip_del4_store(struct device *dev,
  624. struct device_attribute *attr, const char *buf, size_t count)
  625. {
  626. return qeth_l3_rxip_store(dev, buf, false, count, QETH_PROT_IPV4);
  627. }
  628. static QETH_DEVICE_ATTR(rxip_del4, del4, 0200, NULL,
  629. qeth_l3_dev_rxip_del4_store);
  630. static ssize_t qeth_l3_dev_rxip_add6_show(struct device *dev,
  631. struct device_attribute *attr,
  632. char *buf)
  633. {
  634. return qeth_l3_dev_ip_add_show(dev, buf, QETH_PROT_IPV6,
  635. QETH_IP_TYPE_RXIP);
  636. }
  637. static ssize_t qeth_l3_dev_rxip_add6_store(struct device *dev,
  638. struct device_attribute *attr, const char *buf, size_t count)
  639. {
  640. return qeth_l3_rxip_store(dev, buf, true, count, QETH_PROT_IPV6);
  641. }
  642. static QETH_DEVICE_ATTR(rxip_add6, add6, 0644,
  643. qeth_l3_dev_rxip_add6_show,
  644. qeth_l3_dev_rxip_add6_store);
  645. static ssize_t qeth_l3_dev_rxip_del6_store(struct device *dev,
  646. struct device_attribute *attr, const char *buf, size_t count)
  647. {
  648. return qeth_l3_rxip_store(dev, buf, false, count, QETH_PROT_IPV6);
  649. }
  650. static QETH_DEVICE_ATTR(rxip_del6, del6, 0200, NULL,
  651. qeth_l3_dev_rxip_del6_store);
  652. static struct attribute *qeth_rxip_device_attrs[] = {
  653. &dev_attr_rxip_add4.attr,
  654. &dev_attr_rxip_del4.attr,
  655. &dev_attr_rxip_add6.attr,
  656. &dev_attr_rxip_del6.attr,
  657. NULL,
  658. };
  659. static const struct attribute_group qeth_device_rxip_group = {
  660. .name = "rxip",
  661. .attrs = qeth_rxip_device_attrs,
  662. };
  663. const struct attribute_group *qeth_l3_attr_groups[] = {
  664. &qeth_l3_device_attr_group,
  665. &qeth_device_ipato_group,
  666. &qeth_device_vipa_group,
  667. &qeth_device_rxip_group,
  668. NULL,
  669. };