qeth_l3_sys.c 27 KB

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