qeth_l3_sys.c 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125
  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. enum qeth_checksum_types csum_type;
  243. char *tmp;
  244. int rc;
  245. if (!card)
  246. return -EINVAL;
  247. tmp = strsep((char **) &buf, "\n");
  248. if (!strcmp(tmp, "sw_checksumming"))
  249. csum_type = SW_CHECKSUMMING;
  250. else if (!strcmp(tmp, "hw_checksumming"))
  251. csum_type = HW_CHECKSUMMING;
  252. else if (!strcmp(tmp, "no_checksumming"))
  253. csum_type = NO_CHECKSUMMING;
  254. else
  255. return -EINVAL;
  256. rc = qeth_l3_set_rx_csum(card, csum_type);
  257. if (rc)
  258. return rc;
  259. return count;
  260. }
  261. static DEVICE_ATTR(checksumming, 0644, qeth_l3_dev_checksum_show,
  262. qeth_l3_dev_checksum_store);
  263. static ssize_t qeth_l3_dev_sniffer_show(struct device *dev,
  264. struct device_attribute *attr, char *buf)
  265. {
  266. struct qeth_card *card = dev_get_drvdata(dev);
  267. if (!card)
  268. return -EINVAL;
  269. return sprintf(buf, "%i\n", card->options.sniffer ? 1 : 0);
  270. }
  271. static ssize_t qeth_l3_dev_sniffer_store(struct device *dev,
  272. struct device_attribute *attr, const char *buf, size_t count)
  273. {
  274. struct qeth_card *card = dev_get_drvdata(dev);
  275. int ret;
  276. unsigned long i;
  277. if (!card)
  278. return -EINVAL;
  279. if (card->info.type != QETH_CARD_TYPE_IQD)
  280. return -EPERM;
  281. if ((card->state != CARD_STATE_DOWN) &&
  282. (card->state != CARD_STATE_RECOVER))
  283. return -EPERM;
  284. ret = strict_strtoul(buf, 16, &i);
  285. if (ret)
  286. return -EINVAL;
  287. switch (i) {
  288. case 0:
  289. card->options.sniffer = i;
  290. break;
  291. case 1:
  292. ret = qdio_get_ssqd_desc(CARD_DDEV(card), &card->ssqd);
  293. if (card->ssqd.qdioac2 & QETH_SNIFF_AVAIL) {
  294. card->options.sniffer = i;
  295. if (card->qdio.init_pool.buf_count !=
  296. QETH_IN_BUF_COUNT_MAX)
  297. qeth_realloc_buffer_pool(card,
  298. QETH_IN_BUF_COUNT_MAX);
  299. break;
  300. } else
  301. return -EPERM;
  302. default: /* fall through */
  303. return -EINVAL;
  304. }
  305. return count;
  306. }
  307. static DEVICE_ATTR(sniffer, 0644, qeth_l3_dev_sniffer_show,
  308. qeth_l3_dev_sniffer_store);
  309. static ssize_t qeth_l3_dev_large_send_show(struct device *dev,
  310. struct device_attribute *attr, char *buf)
  311. {
  312. struct qeth_card *card = dev_get_drvdata(dev);
  313. if (!card)
  314. return -EINVAL;
  315. switch (card->options.large_send) {
  316. case QETH_LARGE_SEND_NO:
  317. return sprintf(buf, "%s\n", "no");
  318. case QETH_LARGE_SEND_TSO:
  319. return sprintf(buf, "%s\n", "TSO");
  320. default:
  321. return sprintf(buf, "%s\n", "N/A");
  322. }
  323. }
  324. static ssize_t qeth_l3_dev_large_send_store(struct device *dev,
  325. struct device_attribute *attr, const char *buf, size_t count)
  326. {
  327. struct qeth_card *card = dev_get_drvdata(dev);
  328. enum qeth_large_send_types type;
  329. int rc = 0;
  330. char *tmp;
  331. if (!card)
  332. return -EINVAL;
  333. tmp = strsep((char **) &buf, "\n");
  334. if (!strcmp(tmp, "no"))
  335. type = QETH_LARGE_SEND_NO;
  336. else if (!strcmp(tmp, "TSO"))
  337. type = QETH_LARGE_SEND_TSO;
  338. else
  339. return -EINVAL;
  340. if (card->options.large_send == type)
  341. return count;
  342. rc = qeth_l3_set_large_send(card, type);
  343. if (rc)
  344. return rc;
  345. return count;
  346. }
  347. static DEVICE_ATTR(large_send, 0644, qeth_l3_dev_large_send_show,
  348. qeth_l3_dev_large_send_store);
  349. static struct attribute *qeth_l3_device_attrs[] = {
  350. &dev_attr_route4.attr,
  351. &dev_attr_route6.attr,
  352. &dev_attr_fake_broadcast.attr,
  353. &dev_attr_broadcast_mode.attr,
  354. &dev_attr_canonical_macaddr.attr,
  355. &dev_attr_checksumming.attr,
  356. &dev_attr_sniffer.attr,
  357. &dev_attr_large_send.attr,
  358. NULL,
  359. };
  360. static struct attribute_group qeth_l3_device_attr_group = {
  361. .attrs = qeth_l3_device_attrs,
  362. };
  363. static ssize_t qeth_l3_dev_ipato_enable_show(struct device *dev,
  364. struct device_attribute *attr, char *buf)
  365. {
  366. struct qeth_card *card = dev_get_drvdata(dev);
  367. if (!card)
  368. return -EINVAL;
  369. return sprintf(buf, "%i\n", card->ipato.enabled? 1:0);
  370. }
  371. static ssize_t qeth_l3_dev_ipato_enable_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. char *tmp;
  376. if (!card)
  377. return -EINVAL;
  378. if ((card->state != CARD_STATE_DOWN) &&
  379. (card->state != CARD_STATE_RECOVER))
  380. return -EPERM;
  381. tmp = strsep((char **) &buf, "\n");
  382. if (!strcmp(tmp, "toggle")) {
  383. card->ipato.enabled = (card->ipato.enabled)? 0 : 1;
  384. } else if (!strcmp(tmp, "1")) {
  385. card->ipato.enabled = 1;
  386. } else if (!strcmp(tmp, "0")) {
  387. card->ipato.enabled = 0;
  388. } else {
  389. return -EINVAL;
  390. }
  391. return count;
  392. }
  393. static QETH_DEVICE_ATTR(ipato_enable, enable, 0644,
  394. qeth_l3_dev_ipato_enable_show,
  395. qeth_l3_dev_ipato_enable_store);
  396. static ssize_t qeth_l3_dev_ipato_invert4_show(struct device *dev,
  397. struct device_attribute *attr, char *buf)
  398. {
  399. struct qeth_card *card = dev_get_drvdata(dev);
  400. if (!card)
  401. return -EINVAL;
  402. return sprintf(buf, "%i\n", card->ipato.invert4? 1:0);
  403. }
  404. static ssize_t qeth_l3_dev_ipato_invert4_store(struct device *dev,
  405. struct device_attribute *attr,
  406. const char *buf, size_t count)
  407. {
  408. struct qeth_card *card = dev_get_drvdata(dev);
  409. char *tmp;
  410. if (!card)
  411. return -EINVAL;
  412. tmp = strsep((char **) &buf, "\n");
  413. if (!strcmp(tmp, "toggle")) {
  414. card->ipato.invert4 = (card->ipato.invert4)? 0 : 1;
  415. } else if (!strcmp(tmp, "1")) {
  416. card->ipato.invert4 = 1;
  417. } else if (!strcmp(tmp, "0")) {
  418. card->ipato.invert4 = 0;
  419. } else {
  420. return -EINVAL;
  421. }
  422. return count;
  423. }
  424. static QETH_DEVICE_ATTR(ipato_invert4, invert4, 0644,
  425. qeth_l3_dev_ipato_invert4_show,
  426. qeth_l3_dev_ipato_invert4_store);
  427. static ssize_t qeth_l3_dev_ipato_add_show(char *buf, struct qeth_card *card,
  428. enum qeth_prot_versions proto)
  429. {
  430. struct qeth_ipato_entry *ipatoe;
  431. unsigned long flags;
  432. char addr_str[40];
  433. int entry_len; /* length of 1 entry string, differs between v4 and v6 */
  434. int i = 0;
  435. entry_len = (proto == QETH_PROT_IPV4)? 12 : 40;
  436. /* add strlen for "/<mask>\n" */
  437. entry_len += (proto == QETH_PROT_IPV4)? 5 : 6;
  438. spin_lock_irqsave(&card->ip_lock, flags);
  439. list_for_each_entry(ipatoe, &card->ipato.entries, entry) {
  440. if (ipatoe->proto != proto)
  441. continue;
  442. /* String must not be longer than PAGE_SIZE. So we check if
  443. * string length gets near PAGE_SIZE. Then we can savely display
  444. * the next IPv6 address (worst case, compared to IPv4) */
  445. if ((PAGE_SIZE - i) <= entry_len)
  446. break;
  447. qeth_l3_ipaddr_to_string(proto, ipatoe->addr, addr_str);
  448. i += snprintf(buf + i, PAGE_SIZE - i,
  449. "%s/%i\n", addr_str, ipatoe->mask_bits);
  450. }
  451. spin_unlock_irqrestore(&card->ip_lock, flags);
  452. i += snprintf(buf + i, PAGE_SIZE - i, "\n");
  453. return i;
  454. }
  455. static ssize_t qeth_l3_dev_ipato_add4_show(struct device *dev,
  456. struct device_attribute *attr, char *buf)
  457. {
  458. struct qeth_card *card = dev_get_drvdata(dev);
  459. if (!card)
  460. return -EINVAL;
  461. return qeth_l3_dev_ipato_add_show(buf, card, QETH_PROT_IPV4);
  462. }
  463. static int qeth_l3_parse_ipatoe(const char *buf, enum qeth_prot_versions proto,
  464. u8 *addr, int *mask_bits)
  465. {
  466. const char *start, *end;
  467. char *tmp;
  468. char buffer[40] = {0, };
  469. start = buf;
  470. /* get address string */
  471. end = strchr(start, '/');
  472. if (!end || (end - start >= 40)) {
  473. return -EINVAL;
  474. }
  475. strncpy(buffer, start, end - start);
  476. if (qeth_l3_string_to_ipaddr(buffer, proto, addr)) {
  477. return -EINVAL;
  478. }
  479. start = end + 1;
  480. *mask_bits = simple_strtoul(start, &tmp, 10);
  481. if (!strlen(start) ||
  482. (tmp == start) ||
  483. (*mask_bits > ((proto == QETH_PROT_IPV4) ? 32 : 128))) {
  484. return -EINVAL;
  485. }
  486. return 0;
  487. }
  488. static ssize_t qeth_l3_dev_ipato_add_store(const char *buf, size_t count,
  489. struct qeth_card *card, enum qeth_prot_versions proto)
  490. {
  491. struct qeth_ipato_entry *ipatoe;
  492. u8 addr[16];
  493. int mask_bits;
  494. int rc;
  495. rc = qeth_l3_parse_ipatoe(buf, proto, addr, &mask_bits);
  496. if (rc)
  497. return rc;
  498. ipatoe = kzalloc(sizeof(struct qeth_ipato_entry), GFP_KERNEL);
  499. if (!ipatoe) {
  500. return -ENOMEM;
  501. }
  502. ipatoe->proto = proto;
  503. memcpy(ipatoe->addr, addr, (proto == QETH_PROT_IPV4)? 4:16);
  504. ipatoe->mask_bits = mask_bits;
  505. rc = qeth_l3_add_ipato_entry(card, ipatoe);
  506. if (rc) {
  507. kfree(ipatoe);
  508. return rc;
  509. }
  510. return count;
  511. }
  512. static ssize_t qeth_l3_dev_ipato_add4_store(struct device *dev,
  513. struct device_attribute *attr, const char *buf, size_t count)
  514. {
  515. struct qeth_card *card = dev_get_drvdata(dev);
  516. if (!card)
  517. return -EINVAL;
  518. return qeth_l3_dev_ipato_add_store(buf, count, card, QETH_PROT_IPV4);
  519. }
  520. static QETH_DEVICE_ATTR(ipato_add4, add4, 0644,
  521. qeth_l3_dev_ipato_add4_show,
  522. qeth_l3_dev_ipato_add4_store);
  523. static ssize_t qeth_l3_dev_ipato_del_store(const char *buf, size_t count,
  524. struct qeth_card *card, enum qeth_prot_versions proto)
  525. {
  526. u8 addr[16];
  527. int mask_bits;
  528. int rc;
  529. rc = qeth_l3_parse_ipatoe(buf, proto, addr, &mask_bits);
  530. if (rc)
  531. return rc;
  532. qeth_l3_del_ipato_entry(card, proto, addr, mask_bits);
  533. return count;
  534. }
  535. static ssize_t qeth_l3_dev_ipato_del4_store(struct device *dev,
  536. struct device_attribute *attr, const char *buf, size_t count)
  537. {
  538. struct qeth_card *card = dev_get_drvdata(dev);
  539. if (!card)
  540. return -EINVAL;
  541. return qeth_l3_dev_ipato_del_store(buf, count, card, QETH_PROT_IPV4);
  542. }
  543. static QETH_DEVICE_ATTR(ipato_del4, del4, 0200, NULL,
  544. qeth_l3_dev_ipato_del4_store);
  545. static ssize_t qeth_l3_dev_ipato_invert6_show(struct device *dev,
  546. struct device_attribute *attr, char *buf)
  547. {
  548. struct qeth_card *card = dev_get_drvdata(dev);
  549. if (!card)
  550. return -EINVAL;
  551. return sprintf(buf, "%i\n", card->ipato.invert6? 1:0);
  552. }
  553. static ssize_t qeth_l3_dev_ipato_invert6_store(struct device *dev,
  554. struct device_attribute *attr, const char *buf, size_t count)
  555. {
  556. struct qeth_card *card = dev_get_drvdata(dev);
  557. char *tmp;
  558. if (!card)
  559. return -EINVAL;
  560. tmp = strsep((char **) &buf, "\n");
  561. if (!strcmp(tmp, "toggle")) {
  562. card->ipato.invert6 = (card->ipato.invert6)? 0 : 1;
  563. } else if (!strcmp(tmp, "1")) {
  564. card->ipato.invert6 = 1;
  565. } else if (!strcmp(tmp, "0")) {
  566. card->ipato.invert6 = 0;
  567. } else {
  568. return -EINVAL;
  569. }
  570. return count;
  571. }
  572. static QETH_DEVICE_ATTR(ipato_invert6, invert6, 0644,
  573. qeth_l3_dev_ipato_invert6_show,
  574. qeth_l3_dev_ipato_invert6_store);
  575. static ssize_t qeth_l3_dev_ipato_add6_show(struct device *dev,
  576. struct device_attribute *attr, char *buf)
  577. {
  578. struct qeth_card *card = dev_get_drvdata(dev);
  579. if (!card)
  580. return -EINVAL;
  581. return qeth_l3_dev_ipato_add_show(buf, card, QETH_PROT_IPV6);
  582. }
  583. static ssize_t qeth_l3_dev_ipato_add6_store(struct device *dev,
  584. struct device_attribute *attr, const char *buf, size_t count)
  585. {
  586. struct qeth_card *card = dev_get_drvdata(dev);
  587. if (!card)
  588. return -EINVAL;
  589. return qeth_l3_dev_ipato_add_store(buf, count, card, QETH_PROT_IPV6);
  590. }
  591. static QETH_DEVICE_ATTR(ipato_add6, add6, 0644,
  592. qeth_l3_dev_ipato_add6_show,
  593. qeth_l3_dev_ipato_add6_store);
  594. static ssize_t qeth_l3_dev_ipato_del6_store(struct device *dev,
  595. struct device_attribute *attr, const char *buf, size_t count)
  596. {
  597. struct qeth_card *card = dev_get_drvdata(dev);
  598. if (!card)
  599. return -EINVAL;
  600. return qeth_l3_dev_ipato_del_store(buf, count, card, QETH_PROT_IPV6);
  601. }
  602. static QETH_DEVICE_ATTR(ipato_del6, del6, 0200, NULL,
  603. qeth_l3_dev_ipato_del6_store);
  604. static struct attribute *qeth_ipato_device_attrs[] = {
  605. &dev_attr_ipato_enable.attr,
  606. &dev_attr_ipato_invert4.attr,
  607. &dev_attr_ipato_add4.attr,
  608. &dev_attr_ipato_del4.attr,
  609. &dev_attr_ipato_invert6.attr,
  610. &dev_attr_ipato_add6.attr,
  611. &dev_attr_ipato_del6.attr,
  612. NULL,
  613. };
  614. static struct attribute_group qeth_device_ipato_group = {
  615. .name = "ipa_takeover",
  616. .attrs = qeth_ipato_device_attrs,
  617. };
  618. static ssize_t qeth_l3_dev_vipa_add_show(char *buf, struct qeth_card *card,
  619. enum qeth_prot_versions proto)
  620. {
  621. struct qeth_ipaddr *ipaddr;
  622. char addr_str[40];
  623. int entry_len; /* length of 1 entry string, differs between v4 and v6 */
  624. unsigned long flags;
  625. int i = 0;
  626. entry_len = (proto == QETH_PROT_IPV4)? 12 : 40;
  627. entry_len += 2; /* \n + terminator */
  628. spin_lock_irqsave(&card->ip_lock, flags);
  629. list_for_each_entry(ipaddr, &card->ip_list, entry) {
  630. if (ipaddr->proto != proto)
  631. continue;
  632. if (ipaddr->type != QETH_IP_TYPE_VIPA)
  633. continue;
  634. /* String must not be longer than PAGE_SIZE. So we check if
  635. * string length gets near PAGE_SIZE. Then we can savely display
  636. * the next IPv6 address (worst case, compared to IPv4) */
  637. if ((PAGE_SIZE - i) <= entry_len)
  638. break;
  639. qeth_l3_ipaddr_to_string(proto, (const u8 *)&ipaddr->u,
  640. addr_str);
  641. i += snprintf(buf + i, PAGE_SIZE - i, "%s\n", addr_str);
  642. }
  643. spin_unlock_irqrestore(&card->ip_lock, flags);
  644. i += snprintf(buf + i, PAGE_SIZE - i, "\n");
  645. return i;
  646. }
  647. static ssize_t qeth_l3_dev_vipa_add4_show(struct device *dev,
  648. struct device_attribute *attr, char *buf)
  649. {
  650. struct qeth_card *card = dev_get_drvdata(dev);
  651. if (!card)
  652. return -EINVAL;
  653. return qeth_l3_dev_vipa_add_show(buf, card, QETH_PROT_IPV4);
  654. }
  655. static int qeth_l3_parse_vipae(const char *buf, enum qeth_prot_versions proto,
  656. u8 *addr)
  657. {
  658. if (qeth_l3_string_to_ipaddr(buf, proto, addr)) {
  659. return -EINVAL;
  660. }
  661. return 0;
  662. }
  663. static ssize_t qeth_l3_dev_vipa_add_store(const char *buf, size_t count,
  664. struct qeth_card *card, enum qeth_prot_versions proto)
  665. {
  666. u8 addr[16] = {0, };
  667. int rc;
  668. rc = qeth_l3_parse_vipae(buf, proto, addr);
  669. if (rc)
  670. return rc;
  671. rc = qeth_l3_add_vipa(card, proto, addr);
  672. if (rc)
  673. return rc;
  674. return count;
  675. }
  676. static ssize_t qeth_l3_dev_vipa_add4_store(struct device *dev,
  677. struct device_attribute *attr, const char *buf, size_t count)
  678. {
  679. struct qeth_card *card = dev_get_drvdata(dev);
  680. if (!card)
  681. return -EINVAL;
  682. return qeth_l3_dev_vipa_add_store(buf, count, card, QETH_PROT_IPV4);
  683. }
  684. static QETH_DEVICE_ATTR(vipa_add4, add4, 0644,
  685. qeth_l3_dev_vipa_add4_show,
  686. qeth_l3_dev_vipa_add4_store);
  687. static ssize_t qeth_l3_dev_vipa_del_store(const char *buf, size_t count,
  688. struct qeth_card *card, enum qeth_prot_versions proto)
  689. {
  690. u8 addr[16];
  691. int rc;
  692. rc = qeth_l3_parse_vipae(buf, proto, addr);
  693. if (rc)
  694. return rc;
  695. qeth_l3_del_vipa(card, proto, addr);
  696. return count;
  697. }
  698. static ssize_t qeth_l3_dev_vipa_del4_store(struct device *dev,
  699. struct device_attribute *attr, const char *buf, size_t count)
  700. {
  701. struct qeth_card *card = dev_get_drvdata(dev);
  702. if (!card)
  703. return -EINVAL;
  704. return qeth_l3_dev_vipa_del_store(buf, count, card, QETH_PROT_IPV4);
  705. }
  706. static QETH_DEVICE_ATTR(vipa_del4, del4, 0200, NULL,
  707. qeth_l3_dev_vipa_del4_store);
  708. static ssize_t qeth_l3_dev_vipa_add6_show(struct device *dev,
  709. struct device_attribute *attr, char *buf)
  710. {
  711. struct qeth_card *card = dev_get_drvdata(dev);
  712. if (!card)
  713. return -EINVAL;
  714. return qeth_l3_dev_vipa_add_show(buf, card, QETH_PROT_IPV6);
  715. }
  716. static ssize_t qeth_l3_dev_vipa_add6_store(struct device *dev,
  717. struct device_attribute *attr, const char *buf, size_t count)
  718. {
  719. struct qeth_card *card = dev_get_drvdata(dev);
  720. if (!card)
  721. return -EINVAL;
  722. return qeth_l3_dev_vipa_add_store(buf, count, card, QETH_PROT_IPV6);
  723. }
  724. static QETH_DEVICE_ATTR(vipa_add6, add6, 0644,
  725. qeth_l3_dev_vipa_add6_show,
  726. qeth_l3_dev_vipa_add6_store);
  727. static ssize_t qeth_l3_dev_vipa_del6_store(struct device *dev,
  728. struct device_attribute *attr, const char *buf, size_t count)
  729. {
  730. struct qeth_card *card = dev_get_drvdata(dev);
  731. if (!card)
  732. return -EINVAL;
  733. return qeth_l3_dev_vipa_del_store(buf, count, card, QETH_PROT_IPV6);
  734. }
  735. static QETH_DEVICE_ATTR(vipa_del6, del6, 0200, NULL,
  736. qeth_l3_dev_vipa_del6_store);
  737. static struct attribute *qeth_vipa_device_attrs[] = {
  738. &dev_attr_vipa_add4.attr,
  739. &dev_attr_vipa_del4.attr,
  740. &dev_attr_vipa_add6.attr,
  741. &dev_attr_vipa_del6.attr,
  742. NULL,
  743. };
  744. static struct attribute_group qeth_device_vipa_group = {
  745. .name = "vipa",
  746. .attrs = qeth_vipa_device_attrs,
  747. };
  748. static ssize_t qeth_l3_dev_rxip_add_show(char *buf, struct qeth_card *card,
  749. enum qeth_prot_versions proto)
  750. {
  751. struct qeth_ipaddr *ipaddr;
  752. char addr_str[40];
  753. int entry_len; /* length of 1 entry string, differs between v4 and v6 */
  754. unsigned long flags;
  755. int i = 0;
  756. entry_len = (proto == QETH_PROT_IPV4)? 12 : 40;
  757. entry_len += 2; /* \n + terminator */
  758. spin_lock_irqsave(&card->ip_lock, flags);
  759. list_for_each_entry(ipaddr, &card->ip_list, entry) {
  760. if (ipaddr->proto != proto)
  761. continue;
  762. if (ipaddr->type != QETH_IP_TYPE_RXIP)
  763. continue;
  764. /* String must not be longer than PAGE_SIZE. So we check if
  765. * string length gets near PAGE_SIZE. Then we can savely display
  766. * the next IPv6 address (worst case, compared to IPv4) */
  767. if ((PAGE_SIZE - i) <= entry_len)
  768. break;
  769. qeth_l3_ipaddr_to_string(proto, (const u8 *)&ipaddr->u,
  770. addr_str);
  771. i += snprintf(buf + i, PAGE_SIZE - i, "%s\n", addr_str);
  772. }
  773. spin_unlock_irqrestore(&card->ip_lock, flags);
  774. i += snprintf(buf + i, PAGE_SIZE - i, "\n");
  775. return i;
  776. }
  777. static ssize_t qeth_l3_dev_rxip_add4_show(struct device *dev,
  778. struct device_attribute *attr, char *buf)
  779. {
  780. struct qeth_card *card = dev_get_drvdata(dev);
  781. if (!card)
  782. return -EINVAL;
  783. return qeth_l3_dev_rxip_add_show(buf, card, QETH_PROT_IPV4);
  784. }
  785. static int qeth_l3_parse_rxipe(const char *buf, enum qeth_prot_versions proto,
  786. u8 *addr)
  787. {
  788. if (qeth_l3_string_to_ipaddr(buf, proto, addr)) {
  789. return -EINVAL;
  790. }
  791. return 0;
  792. }
  793. static ssize_t qeth_l3_dev_rxip_add_store(const char *buf, size_t count,
  794. struct qeth_card *card, enum qeth_prot_versions proto)
  795. {
  796. u8 addr[16] = {0, };
  797. int rc;
  798. rc = qeth_l3_parse_rxipe(buf, proto, addr);
  799. if (rc)
  800. return rc;
  801. rc = qeth_l3_add_rxip(card, proto, addr);
  802. if (rc)
  803. return rc;
  804. return count;
  805. }
  806. static ssize_t qeth_l3_dev_rxip_add4_store(struct device *dev,
  807. struct device_attribute *attr, const char *buf, size_t count)
  808. {
  809. struct qeth_card *card = dev_get_drvdata(dev);
  810. if (!card)
  811. return -EINVAL;
  812. return qeth_l3_dev_rxip_add_store(buf, count, card, QETH_PROT_IPV4);
  813. }
  814. static QETH_DEVICE_ATTR(rxip_add4, add4, 0644,
  815. qeth_l3_dev_rxip_add4_show,
  816. qeth_l3_dev_rxip_add4_store);
  817. static ssize_t qeth_l3_dev_rxip_del_store(const char *buf, size_t count,
  818. struct qeth_card *card, enum qeth_prot_versions proto)
  819. {
  820. u8 addr[16];
  821. int rc;
  822. rc = qeth_l3_parse_rxipe(buf, proto, addr);
  823. if (rc)
  824. return rc;
  825. qeth_l3_del_rxip(card, proto, addr);
  826. return count;
  827. }
  828. static ssize_t qeth_l3_dev_rxip_del4_store(struct device *dev,
  829. struct device_attribute *attr, const char *buf, size_t count)
  830. {
  831. struct qeth_card *card = dev_get_drvdata(dev);
  832. if (!card)
  833. return -EINVAL;
  834. return qeth_l3_dev_rxip_del_store(buf, count, card, QETH_PROT_IPV4);
  835. }
  836. static QETH_DEVICE_ATTR(rxip_del4, del4, 0200, NULL,
  837. qeth_l3_dev_rxip_del4_store);
  838. static ssize_t qeth_l3_dev_rxip_add6_show(struct device *dev,
  839. struct device_attribute *attr, char *buf)
  840. {
  841. struct qeth_card *card = dev_get_drvdata(dev);
  842. if (!card)
  843. return -EINVAL;
  844. return qeth_l3_dev_rxip_add_show(buf, card, QETH_PROT_IPV6);
  845. }
  846. static ssize_t qeth_l3_dev_rxip_add6_store(struct device *dev,
  847. struct device_attribute *attr, const char *buf, size_t count)
  848. {
  849. struct qeth_card *card = dev_get_drvdata(dev);
  850. if (!card)
  851. return -EINVAL;
  852. return qeth_l3_dev_rxip_add_store(buf, count, card, QETH_PROT_IPV6);
  853. }
  854. static QETH_DEVICE_ATTR(rxip_add6, add6, 0644,
  855. qeth_l3_dev_rxip_add6_show,
  856. qeth_l3_dev_rxip_add6_store);
  857. static ssize_t qeth_l3_dev_rxip_del6_store(struct device *dev,
  858. struct device_attribute *attr, const char *buf, size_t count)
  859. {
  860. struct qeth_card *card = dev_get_drvdata(dev);
  861. if (!card)
  862. return -EINVAL;
  863. return qeth_l3_dev_rxip_del_store(buf, count, card, QETH_PROT_IPV6);
  864. }
  865. static QETH_DEVICE_ATTR(rxip_del6, del6, 0200, NULL,
  866. qeth_l3_dev_rxip_del6_store);
  867. static struct attribute *qeth_rxip_device_attrs[] = {
  868. &dev_attr_rxip_add4.attr,
  869. &dev_attr_rxip_del4.attr,
  870. &dev_attr_rxip_add6.attr,
  871. &dev_attr_rxip_del6.attr,
  872. NULL,
  873. };
  874. static struct attribute_group qeth_device_rxip_group = {
  875. .name = "rxip",
  876. .attrs = qeth_rxip_device_attrs,
  877. };
  878. int qeth_l3_create_device_attributes(struct device *dev)
  879. {
  880. int ret;
  881. ret = sysfs_create_group(&dev->kobj, &qeth_l3_device_attr_group);
  882. if (ret)
  883. return ret;
  884. ret = sysfs_create_group(&dev->kobj, &qeth_device_ipato_group);
  885. if (ret) {
  886. sysfs_remove_group(&dev->kobj, &qeth_l3_device_attr_group);
  887. return ret;
  888. }
  889. ret = sysfs_create_group(&dev->kobj, &qeth_device_vipa_group);
  890. if (ret) {
  891. sysfs_remove_group(&dev->kobj, &qeth_l3_device_attr_group);
  892. sysfs_remove_group(&dev->kobj, &qeth_device_ipato_group);
  893. return ret;
  894. }
  895. ret = sysfs_create_group(&dev->kobj, &qeth_device_rxip_group);
  896. if (ret) {
  897. sysfs_remove_group(&dev->kobj, &qeth_l3_device_attr_group);
  898. sysfs_remove_group(&dev->kobj, &qeth_device_ipato_group);
  899. sysfs_remove_group(&dev->kobj, &qeth_device_vipa_group);
  900. return ret;
  901. }
  902. return 0;
  903. }
  904. void qeth_l3_remove_device_attributes(struct device *dev)
  905. {
  906. sysfs_remove_group(&dev->kobj, &qeth_l3_device_attr_group);
  907. sysfs_remove_group(&dev->kobj, &qeth_device_ipato_group);
  908. sysfs_remove_group(&dev->kobj, &qeth_device_vipa_group);
  909. sysfs_remove_group(&dev->kobj, &qeth_device_rxip_group);
  910. }