qeth_l3_sys.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020
  1. /*
  2. * drivers/s390/net/qeth_l3_sys.c
  3. *
  4. * Copyright IBM Corp. 2007
  5. * Author(s): Utz Bacher <utz.bacher@de.ibm.com>,
  6. * Frank Pavlic <fpavlic@de.ibm.com>,
  7. * Thomas Spatzier <tspat@de.ibm.com>,
  8. * Frank Blaschka <frank.blaschka@de.ibm.com>
  9. */
  10. #include "qeth_l3.h"
  11. #define QETH_DEVICE_ATTR(_id, _name, _mode, _show, _store) \
  12. struct device_attribute dev_attr_##_id = __ATTR(_name, _mode, _show, _store)
  13. static const char *qeth_l3_get_checksum_str(struct qeth_card *card)
  14. {
  15. if (card->options.checksum_type == SW_CHECKSUMMING)
  16. return "sw";
  17. else if (card->options.checksum_type == HW_CHECKSUMMING)
  18. return "hw";
  19. else
  20. return "no";
  21. }
  22. static ssize_t qeth_l3_dev_route_show(struct qeth_card *card,
  23. struct qeth_routing_info *route, char *buf)
  24. {
  25. switch (route->type) {
  26. case PRIMARY_ROUTER:
  27. return sprintf(buf, "%s\n", "primary router");
  28. case SECONDARY_ROUTER:
  29. return sprintf(buf, "%s\n", "secondary router");
  30. case MULTICAST_ROUTER:
  31. if (card->info.broadcast_capable == QETH_BROADCAST_WITHOUT_ECHO)
  32. return sprintf(buf, "%s\n", "multicast router+");
  33. else
  34. return sprintf(buf, "%s\n", "multicast router");
  35. case PRIMARY_CONNECTOR:
  36. if (card->info.broadcast_capable == QETH_BROADCAST_WITHOUT_ECHO)
  37. return sprintf(buf, "%s\n", "primary connector+");
  38. else
  39. return sprintf(buf, "%s\n", "primary connector");
  40. case SECONDARY_CONNECTOR:
  41. if (card->info.broadcast_capable == QETH_BROADCAST_WITHOUT_ECHO)
  42. return sprintf(buf, "%s\n", "secondary connector+");
  43. else
  44. return sprintf(buf, "%s\n", "secondary connector");
  45. default:
  46. return sprintf(buf, "%s\n", "no");
  47. }
  48. }
  49. static ssize_t qeth_l3_dev_route4_show(struct device *dev,
  50. struct device_attribute *attr, char *buf)
  51. {
  52. struct qeth_card *card = dev_get_drvdata(dev);
  53. if (!card)
  54. return -EINVAL;
  55. return qeth_l3_dev_route_show(card, &card->options.route4, buf);
  56. }
  57. static ssize_t qeth_l3_dev_route_store(struct qeth_card *card,
  58. struct qeth_routing_info *route, enum qeth_prot_versions prot,
  59. const char *buf, size_t count)
  60. {
  61. enum qeth_routing_types old_route_type = route->type;
  62. char *tmp;
  63. int rc;
  64. tmp = strsep((char **) &buf, "\n");
  65. if (!strcmp(tmp, "no_router")) {
  66. route->type = NO_ROUTER;
  67. } else if (!strcmp(tmp, "primary_connector")) {
  68. route->type = PRIMARY_CONNECTOR;
  69. } else if (!strcmp(tmp, "secondary_connector")) {
  70. route->type = SECONDARY_CONNECTOR;
  71. } else if (!strcmp(tmp, "primary_router")) {
  72. route->type = PRIMARY_ROUTER;
  73. } else if (!strcmp(tmp, "secondary_router")) {
  74. route->type = SECONDARY_ROUTER;
  75. } else if (!strcmp(tmp, "multicast_router")) {
  76. route->type = MULTICAST_ROUTER;
  77. } else {
  78. return -EINVAL;
  79. }
  80. if (((card->state == CARD_STATE_SOFTSETUP) ||
  81. (card->state == CARD_STATE_UP)) &&
  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. return count;
  89. }
  90. static ssize_t qeth_l3_dev_route4_store(struct device *dev,
  91. struct device_attribute *attr, const char *buf, size_t count)
  92. {
  93. struct qeth_card *card = dev_get_drvdata(dev);
  94. if (!card)
  95. return -EINVAL;
  96. return qeth_l3_dev_route_store(card, &card->options.route4,
  97. QETH_PROT_IPV4, buf, count);
  98. }
  99. static DEVICE_ATTR(route4, 0644, qeth_l3_dev_route4_show,
  100. qeth_l3_dev_route4_store);
  101. static ssize_t qeth_l3_dev_route6_show(struct device *dev,
  102. struct device_attribute *attr, char *buf)
  103. {
  104. struct qeth_card *card = dev_get_drvdata(dev);
  105. if (!card)
  106. return -EINVAL;
  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. if (!card)
  114. return -EINVAL;
  115. return qeth_l3_dev_route_store(card, &card->options.route6,
  116. QETH_PROT_IPV6, buf, count);
  117. }
  118. static DEVICE_ATTR(route6, 0644, qeth_l3_dev_route6_show,
  119. qeth_l3_dev_route6_store);
  120. static ssize_t qeth_l3_dev_fake_broadcast_show(struct device *dev,
  121. struct device_attribute *attr, char *buf)
  122. {
  123. struct qeth_card *card = dev_get_drvdata(dev);
  124. if (!card)
  125. return -EINVAL;
  126. return sprintf(buf, "%i\n", card->options.fake_broadcast? 1:0);
  127. }
  128. static ssize_t qeth_l3_dev_fake_broadcast_store(struct device *dev,
  129. struct device_attribute *attr, const char *buf, size_t count)
  130. {
  131. struct qeth_card *card = dev_get_drvdata(dev);
  132. char *tmp;
  133. int i;
  134. if (!card)
  135. return -EINVAL;
  136. if ((card->state != CARD_STATE_DOWN) &&
  137. (card->state != CARD_STATE_RECOVER))
  138. return -EPERM;
  139. i = simple_strtoul(buf, &tmp, 16);
  140. if ((i == 0) || (i == 1))
  141. card->options.fake_broadcast = i;
  142. else {
  143. return -EINVAL;
  144. }
  145. return count;
  146. }
  147. static DEVICE_ATTR(fake_broadcast, 0644, qeth_l3_dev_fake_broadcast_show,
  148. qeth_l3_dev_fake_broadcast_store);
  149. static ssize_t qeth_l3_dev_broadcast_mode_show(struct device *dev,
  150. struct device_attribute *attr, char *buf)
  151. {
  152. struct qeth_card *card = dev_get_drvdata(dev);
  153. if (!card)
  154. return -EINVAL;
  155. if (!((card->info.link_type == QETH_LINK_TYPE_HSTR) ||
  156. (card->info.link_type == QETH_LINK_TYPE_LANE_TR)))
  157. return sprintf(buf, "n/a\n");
  158. return sprintf(buf, "%s\n", (card->options.broadcast_mode ==
  159. QETH_TR_BROADCAST_ALLRINGS)?
  160. "all rings":"local");
  161. }
  162. static ssize_t qeth_l3_dev_broadcast_mode_store(struct device *dev,
  163. struct device_attribute *attr, const char *buf, size_t count)
  164. {
  165. struct qeth_card *card = dev_get_drvdata(dev);
  166. char *tmp;
  167. if (!card)
  168. return -EINVAL;
  169. if ((card->state != CARD_STATE_DOWN) &&
  170. (card->state != CARD_STATE_RECOVER))
  171. return -EPERM;
  172. if (!((card->info.link_type == QETH_LINK_TYPE_HSTR) ||
  173. (card->info.link_type == QETH_LINK_TYPE_LANE_TR))) {
  174. return -EINVAL;
  175. }
  176. tmp = strsep((char **) &buf, "\n");
  177. if (!strcmp(tmp, "local")) {
  178. card->options.broadcast_mode = QETH_TR_BROADCAST_LOCAL;
  179. return count;
  180. } else if (!strcmp(tmp, "all_rings")) {
  181. card->options.broadcast_mode = QETH_TR_BROADCAST_ALLRINGS;
  182. return count;
  183. } else {
  184. return -EINVAL;
  185. }
  186. return count;
  187. }
  188. static DEVICE_ATTR(broadcast_mode, 0644, qeth_l3_dev_broadcast_mode_show,
  189. qeth_l3_dev_broadcast_mode_store);
  190. static ssize_t qeth_l3_dev_canonical_macaddr_show(struct device *dev,
  191. struct device_attribute *attr, char *buf)
  192. {
  193. struct qeth_card *card = dev_get_drvdata(dev);
  194. if (!card)
  195. return -EINVAL;
  196. if (!((card->info.link_type == QETH_LINK_TYPE_HSTR) ||
  197. (card->info.link_type == QETH_LINK_TYPE_LANE_TR)))
  198. return sprintf(buf, "n/a\n");
  199. return sprintf(buf, "%i\n", (card->options.macaddr_mode ==
  200. QETH_TR_MACADDR_CANONICAL)? 1:0);
  201. }
  202. static ssize_t qeth_l3_dev_canonical_macaddr_store(struct device *dev,
  203. struct device_attribute *attr, const char *buf, size_t count)
  204. {
  205. struct qeth_card *card = dev_get_drvdata(dev);
  206. char *tmp;
  207. int i;
  208. if (!card)
  209. return -EINVAL;
  210. if ((card->state != CARD_STATE_DOWN) &&
  211. (card->state != CARD_STATE_RECOVER))
  212. return -EPERM;
  213. if (!((card->info.link_type == QETH_LINK_TYPE_HSTR) ||
  214. (card->info.link_type == QETH_LINK_TYPE_LANE_TR))) {
  215. return -EINVAL;
  216. }
  217. i = simple_strtoul(buf, &tmp, 16);
  218. if ((i == 0) || (i == 1))
  219. card->options.macaddr_mode = i?
  220. QETH_TR_MACADDR_CANONICAL :
  221. QETH_TR_MACADDR_NONCANONICAL;
  222. else {
  223. return -EINVAL;
  224. }
  225. return count;
  226. }
  227. static DEVICE_ATTR(canonical_macaddr, 0644, qeth_l3_dev_canonical_macaddr_show,
  228. qeth_l3_dev_canonical_macaddr_store);
  229. static ssize_t qeth_l3_dev_checksum_show(struct device *dev,
  230. struct device_attribute *attr, char *buf)
  231. {
  232. struct qeth_card *card = dev_get_drvdata(dev);
  233. if (!card)
  234. return -EINVAL;
  235. return sprintf(buf, "%s checksumming\n",
  236. qeth_l3_get_checksum_str(card));
  237. }
  238. static ssize_t qeth_l3_dev_checksum_store(struct device *dev,
  239. struct device_attribute *attr, const char *buf, size_t count)
  240. {
  241. struct qeth_card *card = dev_get_drvdata(dev);
  242. char *tmp;
  243. if (!card)
  244. return -EINVAL;
  245. if ((card->state != CARD_STATE_DOWN) &&
  246. (card->state != CARD_STATE_RECOVER))
  247. return -EPERM;
  248. tmp = strsep((char **) &buf, "\n");
  249. if (!strcmp(tmp, "sw_checksumming"))
  250. card->options.checksum_type = SW_CHECKSUMMING;
  251. else if (!strcmp(tmp, "hw_checksumming"))
  252. card->options.checksum_type = HW_CHECKSUMMING;
  253. else if (!strcmp(tmp, "no_checksumming"))
  254. card->options.checksum_type = NO_CHECKSUMMING;
  255. else {
  256. return -EINVAL;
  257. }
  258. return count;
  259. }
  260. static DEVICE_ATTR(checksumming, 0644, qeth_l3_dev_checksum_show,
  261. qeth_l3_dev_checksum_store);
  262. static struct attribute *qeth_l3_device_attrs[] = {
  263. &dev_attr_route4.attr,
  264. &dev_attr_route6.attr,
  265. &dev_attr_fake_broadcast.attr,
  266. &dev_attr_broadcast_mode.attr,
  267. &dev_attr_canonical_macaddr.attr,
  268. &dev_attr_checksumming.attr,
  269. NULL,
  270. };
  271. static struct attribute_group qeth_l3_device_attr_group = {
  272. .attrs = qeth_l3_device_attrs,
  273. };
  274. static ssize_t qeth_l3_dev_ipato_enable_show(struct device *dev,
  275. struct device_attribute *attr, char *buf)
  276. {
  277. struct qeth_card *card = dev_get_drvdata(dev);
  278. if (!card)
  279. return -EINVAL;
  280. return sprintf(buf, "%i\n", card->ipato.enabled? 1:0);
  281. }
  282. static ssize_t qeth_l3_dev_ipato_enable_store(struct device *dev,
  283. struct device_attribute *attr, const char *buf, size_t count)
  284. {
  285. struct qeth_card *card = dev_get_drvdata(dev);
  286. char *tmp;
  287. if (!card)
  288. return -EINVAL;
  289. if ((card->state != CARD_STATE_DOWN) &&
  290. (card->state != CARD_STATE_RECOVER))
  291. return -EPERM;
  292. tmp = strsep((char **) &buf, "\n");
  293. if (!strcmp(tmp, "toggle")) {
  294. card->ipato.enabled = (card->ipato.enabled)? 0 : 1;
  295. } else if (!strcmp(tmp, "1")) {
  296. card->ipato.enabled = 1;
  297. } else if (!strcmp(tmp, "0")) {
  298. card->ipato.enabled = 0;
  299. } else {
  300. return -EINVAL;
  301. }
  302. return count;
  303. }
  304. static QETH_DEVICE_ATTR(ipato_enable, enable, 0644,
  305. qeth_l3_dev_ipato_enable_show,
  306. qeth_l3_dev_ipato_enable_store);
  307. static ssize_t qeth_l3_dev_ipato_invert4_show(struct device *dev,
  308. struct device_attribute *attr, char *buf)
  309. {
  310. struct qeth_card *card = dev_get_drvdata(dev);
  311. if (!card)
  312. return -EINVAL;
  313. return sprintf(buf, "%i\n", card->ipato.invert4? 1:0);
  314. }
  315. static ssize_t qeth_l3_dev_ipato_invert4_store(struct device *dev,
  316. struct device_attribute *attr,
  317. const char *buf, size_t count)
  318. {
  319. struct qeth_card *card = dev_get_drvdata(dev);
  320. char *tmp;
  321. if (!card)
  322. return -EINVAL;
  323. tmp = strsep((char **) &buf, "\n");
  324. if (!strcmp(tmp, "toggle")) {
  325. card->ipato.invert4 = (card->ipato.invert4)? 0 : 1;
  326. } else if (!strcmp(tmp, "1")) {
  327. card->ipato.invert4 = 1;
  328. } else if (!strcmp(tmp, "0")) {
  329. card->ipato.invert4 = 0;
  330. } else {
  331. return -EINVAL;
  332. }
  333. return count;
  334. }
  335. static QETH_DEVICE_ATTR(ipato_invert4, invert4, 0644,
  336. qeth_l3_dev_ipato_invert4_show,
  337. qeth_l3_dev_ipato_invert4_store);
  338. static ssize_t qeth_l3_dev_ipato_add_show(char *buf, struct qeth_card *card,
  339. enum qeth_prot_versions proto)
  340. {
  341. struct qeth_ipato_entry *ipatoe;
  342. unsigned long flags;
  343. char addr_str[40];
  344. int entry_len; /* length of 1 entry string, differs between v4 and v6 */
  345. int i = 0;
  346. entry_len = (proto == QETH_PROT_IPV4)? 12 : 40;
  347. /* add strlen for "/<mask>\n" */
  348. entry_len += (proto == QETH_PROT_IPV4)? 5 : 6;
  349. spin_lock_irqsave(&card->ip_lock, flags);
  350. list_for_each_entry(ipatoe, &card->ipato.entries, entry) {
  351. if (ipatoe->proto != proto)
  352. continue;
  353. /* String must not be longer than PAGE_SIZE. So we check if
  354. * string length gets near PAGE_SIZE. Then we can savely display
  355. * the next IPv6 address (worst case, compared to IPv4) */
  356. if ((PAGE_SIZE - i) <= entry_len)
  357. break;
  358. qeth_l3_ipaddr_to_string(proto, ipatoe->addr, addr_str);
  359. i += snprintf(buf + i, PAGE_SIZE - i,
  360. "%s/%i\n", addr_str, ipatoe->mask_bits);
  361. }
  362. spin_unlock_irqrestore(&card->ip_lock, flags);
  363. i += snprintf(buf + i, PAGE_SIZE - i, "\n");
  364. return i;
  365. }
  366. static ssize_t qeth_l3_dev_ipato_add4_show(struct device *dev,
  367. struct device_attribute *attr, char *buf)
  368. {
  369. struct qeth_card *card = dev_get_drvdata(dev);
  370. if (!card)
  371. return -EINVAL;
  372. return qeth_l3_dev_ipato_add_show(buf, card, QETH_PROT_IPV4);
  373. }
  374. static int qeth_l3_parse_ipatoe(const char *buf, enum qeth_prot_versions proto,
  375. u8 *addr, int *mask_bits)
  376. {
  377. const char *start, *end;
  378. char *tmp;
  379. char buffer[40] = {0, };
  380. start = buf;
  381. /* get address string */
  382. end = strchr(start, '/');
  383. if (!end || (end - start >= 40)) {
  384. return -EINVAL;
  385. }
  386. strncpy(buffer, start, end - start);
  387. if (qeth_l3_string_to_ipaddr(buffer, proto, addr)) {
  388. return -EINVAL;
  389. }
  390. start = end + 1;
  391. *mask_bits = simple_strtoul(start, &tmp, 10);
  392. if (!strlen(start) ||
  393. (tmp == start) ||
  394. (*mask_bits > ((proto == QETH_PROT_IPV4) ? 32 : 128))) {
  395. return -EINVAL;
  396. }
  397. return 0;
  398. }
  399. static ssize_t qeth_l3_dev_ipato_add_store(const char *buf, size_t count,
  400. struct qeth_card *card, enum qeth_prot_versions proto)
  401. {
  402. struct qeth_ipato_entry *ipatoe;
  403. u8 addr[16];
  404. int mask_bits;
  405. int rc;
  406. rc = qeth_l3_parse_ipatoe(buf, proto, addr, &mask_bits);
  407. if (rc)
  408. return rc;
  409. ipatoe = kzalloc(sizeof(struct qeth_ipato_entry), GFP_KERNEL);
  410. if (!ipatoe) {
  411. return -ENOMEM;
  412. }
  413. ipatoe->proto = proto;
  414. memcpy(ipatoe->addr, addr, (proto == QETH_PROT_IPV4)? 4:16);
  415. ipatoe->mask_bits = mask_bits;
  416. rc = qeth_l3_add_ipato_entry(card, ipatoe);
  417. if (rc) {
  418. kfree(ipatoe);
  419. return rc;
  420. }
  421. return count;
  422. }
  423. static ssize_t qeth_l3_dev_ipato_add4_store(struct device *dev,
  424. struct device_attribute *attr, const char *buf, size_t count)
  425. {
  426. struct qeth_card *card = dev_get_drvdata(dev);
  427. if (!card)
  428. return -EINVAL;
  429. return qeth_l3_dev_ipato_add_store(buf, count, card, QETH_PROT_IPV4);
  430. }
  431. static QETH_DEVICE_ATTR(ipato_add4, add4, 0644,
  432. qeth_l3_dev_ipato_add4_show,
  433. qeth_l3_dev_ipato_add4_store);
  434. static ssize_t qeth_l3_dev_ipato_del_store(const char *buf, size_t count,
  435. struct qeth_card *card, enum qeth_prot_versions proto)
  436. {
  437. u8 addr[16];
  438. int mask_bits;
  439. int rc;
  440. rc = qeth_l3_parse_ipatoe(buf, proto, addr, &mask_bits);
  441. if (rc)
  442. return rc;
  443. qeth_l3_del_ipato_entry(card, proto, addr, mask_bits);
  444. return count;
  445. }
  446. static ssize_t qeth_l3_dev_ipato_del4_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. if (!card)
  451. return -EINVAL;
  452. return qeth_l3_dev_ipato_del_store(buf, count, card, QETH_PROT_IPV4);
  453. }
  454. static QETH_DEVICE_ATTR(ipato_del4, del4, 0200, NULL,
  455. qeth_l3_dev_ipato_del4_store);
  456. static ssize_t qeth_l3_dev_ipato_invert6_show(struct device *dev,
  457. struct device_attribute *attr, char *buf)
  458. {
  459. struct qeth_card *card = dev_get_drvdata(dev);
  460. if (!card)
  461. return -EINVAL;
  462. return sprintf(buf, "%i\n", card->ipato.invert6? 1:0);
  463. }
  464. static ssize_t qeth_l3_dev_ipato_invert6_store(struct device *dev,
  465. struct device_attribute *attr, const char *buf, size_t count)
  466. {
  467. struct qeth_card *card = dev_get_drvdata(dev);
  468. char *tmp;
  469. if (!card)
  470. return -EINVAL;
  471. tmp = strsep((char **) &buf, "\n");
  472. if (!strcmp(tmp, "toggle")) {
  473. card->ipato.invert6 = (card->ipato.invert6)? 0 : 1;
  474. } else if (!strcmp(tmp, "1")) {
  475. card->ipato.invert6 = 1;
  476. } else if (!strcmp(tmp, "0")) {
  477. card->ipato.invert6 = 0;
  478. } else {
  479. return -EINVAL;
  480. }
  481. return count;
  482. }
  483. static QETH_DEVICE_ATTR(ipato_invert6, invert6, 0644,
  484. qeth_l3_dev_ipato_invert6_show,
  485. qeth_l3_dev_ipato_invert6_store);
  486. static ssize_t qeth_l3_dev_ipato_add6_show(struct device *dev,
  487. struct device_attribute *attr, char *buf)
  488. {
  489. struct qeth_card *card = dev_get_drvdata(dev);
  490. if (!card)
  491. return -EINVAL;
  492. return qeth_l3_dev_ipato_add_show(buf, card, QETH_PROT_IPV6);
  493. }
  494. static ssize_t qeth_l3_dev_ipato_add6_store(struct device *dev,
  495. struct device_attribute *attr, const char *buf, size_t count)
  496. {
  497. struct qeth_card *card = dev_get_drvdata(dev);
  498. if (!card)
  499. return -EINVAL;
  500. return qeth_l3_dev_ipato_add_store(buf, count, card, QETH_PROT_IPV6);
  501. }
  502. static QETH_DEVICE_ATTR(ipato_add6, add6, 0644,
  503. qeth_l3_dev_ipato_add6_show,
  504. qeth_l3_dev_ipato_add6_store);
  505. static ssize_t qeth_l3_dev_ipato_del6_store(struct device *dev,
  506. struct device_attribute *attr, const char *buf, size_t count)
  507. {
  508. struct qeth_card *card = dev_get_drvdata(dev);
  509. if (!card)
  510. return -EINVAL;
  511. return qeth_l3_dev_ipato_del_store(buf, count, card, QETH_PROT_IPV6);
  512. }
  513. static QETH_DEVICE_ATTR(ipato_del6, del6, 0200, NULL,
  514. qeth_l3_dev_ipato_del6_store);
  515. static struct attribute *qeth_ipato_device_attrs[] = {
  516. &dev_attr_ipato_enable.attr,
  517. &dev_attr_ipato_invert4.attr,
  518. &dev_attr_ipato_add4.attr,
  519. &dev_attr_ipato_del4.attr,
  520. &dev_attr_ipato_invert6.attr,
  521. &dev_attr_ipato_add6.attr,
  522. &dev_attr_ipato_del6.attr,
  523. NULL,
  524. };
  525. static struct attribute_group qeth_device_ipato_group = {
  526. .name = "ipa_takeover",
  527. .attrs = qeth_ipato_device_attrs,
  528. };
  529. static ssize_t qeth_l3_dev_vipa_add_show(char *buf, struct qeth_card *card,
  530. enum qeth_prot_versions proto)
  531. {
  532. struct qeth_ipaddr *ipaddr;
  533. char addr_str[40];
  534. int entry_len; /* length of 1 entry string, differs between v4 and v6 */
  535. unsigned long flags;
  536. int i = 0;
  537. entry_len = (proto == QETH_PROT_IPV4)? 12 : 40;
  538. entry_len += 2; /* \n + terminator */
  539. spin_lock_irqsave(&card->ip_lock, flags);
  540. list_for_each_entry(ipaddr, &card->ip_list, entry) {
  541. if (ipaddr->proto != proto)
  542. continue;
  543. if (ipaddr->type != QETH_IP_TYPE_VIPA)
  544. continue;
  545. /* String must not be longer than PAGE_SIZE. So we check if
  546. * string length gets near PAGE_SIZE. Then we can savely display
  547. * the next IPv6 address (worst case, compared to IPv4) */
  548. if ((PAGE_SIZE - i) <= entry_len)
  549. break;
  550. qeth_l3_ipaddr_to_string(proto, (const u8 *)&ipaddr->u,
  551. addr_str);
  552. i += snprintf(buf + i, PAGE_SIZE - i, "%s\n", addr_str);
  553. }
  554. spin_unlock_irqrestore(&card->ip_lock, flags);
  555. i += snprintf(buf + i, PAGE_SIZE - i, "\n");
  556. return i;
  557. }
  558. static ssize_t qeth_l3_dev_vipa_add4_show(struct device *dev,
  559. struct device_attribute *attr, char *buf)
  560. {
  561. struct qeth_card *card = dev_get_drvdata(dev);
  562. if (!card)
  563. return -EINVAL;
  564. return qeth_l3_dev_vipa_add_show(buf, card, QETH_PROT_IPV4);
  565. }
  566. static int qeth_l3_parse_vipae(const char *buf, enum qeth_prot_versions proto,
  567. u8 *addr)
  568. {
  569. if (qeth_l3_string_to_ipaddr(buf, proto, addr)) {
  570. return -EINVAL;
  571. }
  572. return 0;
  573. }
  574. static ssize_t qeth_l3_dev_vipa_add_store(const char *buf, size_t count,
  575. struct qeth_card *card, enum qeth_prot_versions proto)
  576. {
  577. u8 addr[16] = {0, };
  578. int rc;
  579. rc = qeth_l3_parse_vipae(buf, proto, addr);
  580. if (rc)
  581. return rc;
  582. rc = qeth_l3_add_vipa(card, proto, addr);
  583. if (rc)
  584. return rc;
  585. return count;
  586. }
  587. static ssize_t qeth_l3_dev_vipa_add4_store(struct device *dev,
  588. struct device_attribute *attr, const char *buf, size_t count)
  589. {
  590. struct qeth_card *card = dev_get_drvdata(dev);
  591. if (!card)
  592. return -EINVAL;
  593. return qeth_l3_dev_vipa_add_store(buf, count, card, QETH_PROT_IPV4);
  594. }
  595. static QETH_DEVICE_ATTR(vipa_add4, add4, 0644,
  596. qeth_l3_dev_vipa_add4_show,
  597. qeth_l3_dev_vipa_add4_store);
  598. static ssize_t qeth_l3_dev_vipa_del_store(const char *buf, size_t count,
  599. struct qeth_card *card, enum qeth_prot_versions proto)
  600. {
  601. u8 addr[16];
  602. int rc;
  603. rc = qeth_l3_parse_vipae(buf, proto, addr);
  604. if (rc)
  605. return rc;
  606. qeth_l3_del_vipa(card, proto, addr);
  607. return count;
  608. }
  609. static ssize_t qeth_l3_dev_vipa_del4_store(struct device *dev,
  610. struct device_attribute *attr, const char *buf, size_t count)
  611. {
  612. struct qeth_card *card = dev_get_drvdata(dev);
  613. if (!card)
  614. return -EINVAL;
  615. return qeth_l3_dev_vipa_del_store(buf, count, card, QETH_PROT_IPV4);
  616. }
  617. static QETH_DEVICE_ATTR(vipa_del4, del4, 0200, NULL,
  618. qeth_l3_dev_vipa_del4_store);
  619. static ssize_t qeth_l3_dev_vipa_add6_show(struct device *dev,
  620. struct device_attribute *attr, char *buf)
  621. {
  622. struct qeth_card *card = dev_get_drvdata(dev);
  623. if (!card)
  624. return -EINVAL;
  625. return qeth_l3_dev_vipa_add_show(buf, card, QETH_PROT_IPV6);
  626. }
  627. static ssize_t qeth_l3_dev_vipa_add6_store(struct device *dev,
  628. struct device_attribute *attr, const char *buf, size_t count)
  629. {
  630. struct qeth_card *card = dev_get_drvdata(dev);
  631. if (!card)
  632. return -EINVAL;
  633. return qeth_l3_dev_vipa_add_store(buf, count, card, QETH_PROT_IPV6);
  634. }
  635. static QETH_DEVICE_ATTR(vipa_add6, add6, 0644,
  636. qeth_l3_dev_vipa_add6_show,
  637. qeth_l3_dev_vipa_add6_store);
  638. static ssize_t qeth_l3_dev_vipa_del6_store(struct device *dev,
  639. struct device_attribute *attr, const char *buf, size_t count)
  640. {
  641. struct qeth_card *card = dev_get_drvdata(dev);
  642. if (!card)
  643. return -EINVAL;
  644. return qeth_l3_dev_vipa_del_store(buf, count, card, QETH_PROT_IPV6);
  645. }
  646. static QETH_DEVICE_ATTR(vipa_del6, del6, 0200, NULL,
  647. qeth_l3_dev_vipa_del6_store);
  648. static struct attribute *qeth_vipa_device_attrs[] = {
  649. &dev_attr_vipa_add4.attr,
  650. &dev_attr_vipa_del4.attr,
  651. &dev_attr_vipa_add6.attr,
  652. &dev_attr_vipa_del6.attr,
  653. NULL,
  654. };
  655. static struct attribute_group qeth_device_vipa_group = {
  656. .name = "vipa",
  657. .attrs = qeth_vipa_device_attrs,
  658. };
  659. static ssize_t qeth_l3_dev_rxip_add_show(char *buf, struct qeth_card *card,
  660. enum qeth_prot_versions proto)
  661. {
  662. struct qeth_ipaddr *ipaddr;
  663. char addr_str[40];
  664. int entry_len; /* length of 1 entry string, differs between v4 and v6 */
  665. unsigned long flags;
  666. int i = 0;
  667. entry_len = (proto == QETH_PROT_IPV4)? 12 : 40;
  668. entry_len += 2; /* \n + terminator */
  669. spin_lock_irqsave(&card->ip_lock, flags);
  670. list_for_each_entry(ipaddr, &card->ip_list, entry) {
  671. if (ipaddr->proto != proto)
  672. continue;
  673. if (ipaddr->type != QETH_IP_TYPE_RXIP)
  674. continue;
  675. /* String must not be longer than PAGE_SIZE. So we check if
  676. * string length gets near PAGE_SIZE. Then we can savely display
  677. * the next IPv6 address (worst case, compared to IPv4) */
  678. if ((PAGE_SIZE - i) <= entry_len)
  679. break;
  680. qeth_l3_ipaddr_to_string(proto, (const u8 *)&ipaddr->u,
  681. addr_str);
  682. i += snprintf(buf + i, PAGE_SIZE - i, "%s\n", addr_str);
  683. }
  684. spin_unlock_irqrestore(&card->ip_lock, flags);
  685. i += snprintf(buf + i, PAGE_SIZE - i, "\n");
  686. return i;
  687. }
  688. static ssize_t qeth_l3_dev_rxip_add4_show(struct device *dev,
  689. struct device_attribute *attr, char *buf)
  690. {
  691. struct qeth_card *card = dev_get_drvdata(dev);
  692. if (!card)
  693. return -EINVAL;
  694. return qeth_l3_dev_rxip_add_show(buf, card, QETH_PROT_IPV4);
  695. }
  696. static int qeth_l3_parse_rxipe(const char *buf, enum qeth_prot_versions proto,
  697. u8 *addr)
  698. {
  699. if (qeth_l3_string_to_ipaddr(buf, proto, addr)) {
  700. return -EINVAL;
  701. }
  702. return 0;
  703. }
  704. static ssize_t qeth_l3_dev_rxip_add_store(const char *buf, size_t count,
  705. struct qeth_card *card, enum qeth_prot_versions proto)
  706. {
  707. u8 addr[16] = {0, };
  708. int rc;
  709. rc = qeth_l3_parse_rxipe(buf, proto, addr);
  710. if (rc)
  711. return rc;
  712. rc = qeth_l3_add_rxip(card, proto, addr);
  713. if (rc)
  714. return rc;
  715. return count;
  716. }
  717. static ssize_t qeth_l3_dev_rxip_add4_store(struct device *dev,
  718. struct device_attribute *attr, const char *buf, size_t count)
  719. {
  720. struct qeth_card *card = dev_get_drvdata(dev);
  721. if (!card)
  722. return -EINVAL;
  723. return qeth_l3_dev_rxip_add_store(buf, count, card, QETH_PROT_IPV4);
  724. }
  725. static QETH_DEVICE_ATTR(rxip_add4, add4, 0644,
  726. qeth_l3_dev_rxip_add4_show,
  727. qeth_l3_dev_rxip_add4_store);
  728. static ssize_t qeth_l3_dev_rxip_del_store(const char *buf, size_t count,
  729. struct qeth_card *card, enum qeth_prot_versions proto)
  730. {
  731. u8 addr[16];
  732. int rc;
  733. rc = qeth_l3_parse_rxipe(buf, proto, addr);
  734. if (rc)
  735. return rc;
  736. qeth_l3_del_rxip(card, proto, addr);
  737. return count;
  738. }
  739. static ssize_t qeth_l3_dev_rxip_del4_store(struct device *dev,
  740. struct device_attribute *attr, const char *buf, size_t count)
  741. {
  742. struct qeth_card *card = dev_get_drvdata(dev);
  743. if (!card)
  744. return -EINVAL;
  745. return qeth_l3_dev_rxip_del_store(buf, count, card, QETH_PROT_IPV4);
  746. }
  747. static QETH_DEVICE_ATTR(rxip_del4, del4, 0200, NULL,
  748. qeth_l3_dev_rxip_del4_store);
  749. static ssize_t qeth_l3_dev_rxip_add6_show(struct device *dev,
  750. struct device_attribute *attr, char *buf)
  751. {
  752. struct qeth_card *card = dev_get_drvdata(dev);
  753. if (!card)
  754. return -EINVAL;
  755. return qeth_l3_dev_rxip_add_show(buf, card, QETH_PROT_IPV6);
  756. }
  757. static ssize_t qeth_l3_dev_rxip_add6_store(struct device *dev,
  758. struct device_attribute *attr, const char *buf, size_t count)
  759. {
  760. struct qeth_card *card = dev_get_drvdata(dev);
  761. if (!card)
  762. return -EINVAL;
  763. return qeth_l3_dev_rxip_add_store(buf, count, card, QETH_PROT_IPV6);
  764. }
  765. static QETH_DEVICE_ATTR(rxip_add6, add6, 0644,
  766. qeth_l3_dev_rxip_add6_show,
  767. qeth_l3_dev_rxip_add6_store);
  768. static ssize_t qeth_l3_dev_rxip_del6_store(struct device *dev,
  769. struct device_attribute *attr, const char *buf, size_t count)
  770. {
  771. struct qeth_card *card = dev_get_drvdata(dev);
  772. if (!card)
  773. return -EINVAL;
  774. return qeth_l3_dev_rxip_del_store(buf, count, card, QETH_PROT_IPV6);
  775. }
  776. static QETH_DEVICE_ATTR(rxip_del6, del6, 0200, NULL,
  777. qeth_l3_dev_rxip_del6_store);
  778. static struct attribute *qeth_rxip_device_attrs[] = {
  779. &dev_attr_rxip_add4.attr,
  780. &dev_attr_rxip_del4.attr,
  781. &dev_attr_rxip_add6.attr,
  782. &dev_attr_rxip_del6.attr,
  783. NULL,
  784. };
  785. static struct attribute_group qeth_device_rxip_group = {
  786. .name = "rxip",
  787. .attrs = qeth_rxip_device_attrs,
  788. };
  789. int qeth_l3_create_device_attributes(struct device *dev)
  790. {
  791. int ret;
  792. ret = sysfs_create_group(&dev->kobj, &qeth_l3_device_attr_group);
  793. if (ret)
  794. return ret;
  795. ret = sysfs_create_group(&dev->kobj, &qeth_device_ipato_group);
  796. if (ret) {
  797. sysfs_remove_group(&dev->kobj, &qeth_l3_device_attr_group);
  798. return ret;
  799. }
  800. ret = sysfs_create_group(&dev->kobj, &qeth_device_vipa_group);
  801. if (ret) {
  802. sysfs_remove_group(&dev->kobj, &qeth_l3_device_attr_group);
  803. sysfs_remove_group(&dev->kobj, &qeth_device_ipato_group);
  804. return ret;
  805. }
  806. ret = sysfs_create_group(&dev->kobj, &qeth_device_rxip_group);
  807. if (ret) {
  808. sysfs_remove_group(&dev->kobj, &qeth_l3_device_attr_group);
  809. sysfs_remove_group(&dev->kobj, &qeth_device_ipato_group);
  810. sysfs_remove_group(&dev->kobj, &qeth_device_vipa_group);
  811. return ret;
  812. }
  813. return 0;
  814. }
  815. void qeth_l3_remove_device_attributes(struct device *dev)
  816. {
  817. sysfs_remove_group(&dev->kobj, &qeth_l3_device_attr_group);
  818. sysfs_remove_group(&dev->kobj, &qeth_device_ipato_group);
  819. sysfs_remove_group(&dev->kobj, &qeth_device_vipa_group);
  820. sysfs_remove_group(&dev->kobj, &qeth_device_rxip_group);
  821. }