qeth_l3_sys.c 28 KB

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