PageRenderTime 3860ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 1ms

/drivers/s390/net/qeth_l3_main.c

https://bitbucket.org/slukk/jb-tsm-kernel-4.2
C | 3759 lines | 3251 code | 394 blank | 114 comment | 725 complexity | 0ac3595442969ea8ec7f05d360378290 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.0, AGPL-1.0
  1. /*
  2. * drivers/s390/net/qeth_l3_main.c
  3. *
  4. * Copyright IBM Corp. 2007, 2009
  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. #define KMSG_COMPONENT "qeth"
  11. #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
  12. #include <linux/module.h>
  13. #include <linux/moduleparam.h>
  14. #include <linux/string.h>
  15. #include <linux/errno.h>
  16. #include <linux/kernel.h>
  17. #include <linux/etherdevice.h>
  18. #include <linux/mii.h>
  19. #include <linux/ip.h>
  20. #include <linux/ipv6.h>
  21. #include <linux/inetdevice.h>
  22. #include <linux/igmp.h>
  23. #include <linux/slab.h>
  24. #include <net/ip.h>
  25. #include <net/arp.h>
  26. #include <net/ip6_checksum.h>
  27. #include "qeth_l3.h"
  28. static int qeth_l3_set_offline(struct ccwgroup_device *);
  29. static int qeth_l3_recover(void *);
  30. static int qeth_l3_stop(struct net_device *);
  31. static void qeth_l3_set_multicast_list(struct net_device *);
  32. static int qeth_l3_neigh_setup(struct net_device *, struct neigh_parms *);
  33. static int qeth_l3_register_addr_entry(struct qeth_card *,
  34. struct qeth_ipaddr *);
  35. static int qeth_l3_deregister_addr_entry(struct qeth_card *,
  36. struct qeth_ipaddr *);
  37. static int __qeth_l3_set_online(struct ccwgroup_device *, int);
  38. static int __qeth_l3_set_offline(struct ccwgroup_device *, int);
  39. static int qeth_l3_isxdigit(char *buf)
  40. {
  41. while (*buf) {
  42. if (!isxdigit(*buf++))
  43. return 0;
  44. }
  45. return 1;
  46. }
  47. void qeth_l3_ipaddr4_to_string(const __u8 *addr, char *buf)
  48. {
  49. sprintf(buf, "%i.%i.%i.%i", addr[0], addr[1], addr[2], addr[3]);
  50. }
  51. int qeth_l3_string_to_ipaddr4(const char *buf, __u8 *addr)
  52. {
  53. int count = 0, rc = 0;
  54. int in[4];
  55. char c;
  56. rc = sscanf(buf, "%u.%u.%u.%u%c",
  57. &in[0], &in[1], &in[2], &in[3], &c);
  58. if (rc != 4 && (rc != 5 || c != '\n'))
  59. return -EINVAL;
  60. for (count = 0; count < 4; count++) {
  61. if (in[count] > 255)
  62. return -EINVAL;
  63. addr[count] = in[count];
  64. }
  65. return 0;
  66. }
  67. void qeth_l3_ipaddr6_to_string(const __u8 *addr, char *buf)
  68. {
  69. sprintf(buf, "%pI6", addr);
  70. }
  71. int qeth_l3_string_to_ipaddr6(const char *buf, __u8 *addr)
  72. {
  73. const char *end, *end_tmp, *start;
  74. __u16 *in;
  75. char num[5];
  76. int num2, cnt, out, found, save_cnt;
  77. unsigned short in_tmp[8] = {0, };
  78. cnt = out = found = save_cnt = num2 = 0;
  79. end = start = buf;
  80. in = (__u16 *) addr;
  81. memset(in, 0, 16);
  82. while (*end) {
  83. end = strchr(start, ':');
  84. if (end == NULL) {
  85. end = buf + strlen(buf);
  86. end_tmp = strchr(start, '\n');
  87. if (end_tmp != NULL)
  88. end = end_tmp;
  89. out = 1;
  90. }
  91. if ((end - start)) {
  92. memset(num, 0, 5);
  93. if ((end - start) > 4)
  94. return -EINVAL;
  95. memcpy(num, start, end - start);
  96. if (!qeth_l3_isxdigit(num))
  97. return -EINVAL;
  98. sscanf(start, "%x", &num2);
  99. if (found)
  100. in_tmp[save_cnt++] = num2;
  101. else
  102. in[cnt++] = num2;
  103. if (out)
  104. break;
  105. } else {
  106. if (found)
  107. return -EINVAL;
  108. found = 1;
  109. }
  110. start = ++end;
  111. }
  112. if (cnt + save_cnt > 8)
  113. return -EINVAL;
  114. cnt = 7;
  115. while (save_cnt)
  116. in[cnt--] = in_tmp[--save_cnt];
  117. return 0;
  118. }
  119. void qeth_l3_ipaddr_to_string(enum qeth_prot_versions proto, const __u8 *addr,
  120. char *buf)
  121. {
  122. if (proto == QETH_PROT_IPV4)
  123. qeth_l3_ipaddr4_to_string(addr, buf);
  124. else if (proto == QETH_PROT_IPV6)
  125. qeth_l3_ipaddr6_to_string(addr, buf);
  126. }
  127. int qeth_l3_string_to_ipaddr(const char *buf, enum qeth_prot_versions proto,
  128. __u8 *addr)
  129. {
  130. if (proto == QETH_PROT_IPV4)
  131. return qeth_l3_string_to_ipaddr4(buf, addr);
  132. else if (proto == QETH_PROT_IPV6)
  133. return qeth_l3_string_to_ipaddr6(buf, addr);
  134. else
  135. return -EINVAL;
  136. }
  137. static void qeth_l3_convert_addr_to_bits(u8 *addr, u8 *bits, int len)
  138. {
  139. int i, j;
  140. u8 octet;
  141. for (i = 0; i < len; ++i) {
  142. octet = addr[i];
  143. for (j = 7; j >= 0; --j) {
  144. bits[i*8 + j] = octet & 1;
  145. octet >>= 1;
  146. }
  147. }
  148. }
  149. int qeth_l3_is_addr_covered_by_ipato(struct qeth_card *card,
  150. struct qeth_ipaddr *addr)
  151. {
  152. struct qeth_ipato_entry *ipatoe;
  153. u8 addr_bits[128] = {0, };
  154. u8 ipatoe_bits[128] = {0, };
  155. int rc = 0;
  156. if (!card->ipato.enabled)
  157. return 0;
  158. qeth_l3_convert_addr_to_bits((u8 *) &addr->u, addr_bits,
  159. (addr->proto == QETH_PROT_IPV4)? 4:16);
  160. list_for_each_entry(ipatoe, &card->ipato.entries, entry) {
  161. if (addr->proto != ipatoe->proto)
  162. continue;
  163. qeth_l3_convert_addr_to_bits(ipatoe->addr, ipatoe_bits,
  164. (ipatoe->proto == QETH_PROT_IPV4) ?
  165. 4 : 16);
  166. if (addr->proto == QETH_PROT_IPV4)
  167. rc = !memcmp(addr_bits, ipatoe_bits,
  168. min(32, ipatoe->mask_bits));
  169. else
  170. rc = !memcmp(addr_bits, ipatoe_bits,
  171. min(128, ipatoe->mask_bits));
  172. if (rc)
  173. break;
  174. }
  175. /* invert? */
  176. if ((addr->proto == QETH_PROT_IPV4) && card->ipato.invert4)
  177. rc = !rc;
  178. else if ((addr->proto == QETH_PROT_IPV6) && card->ipato.invert6)
  179. rc = !rc;
  180. return rc;
  181. }
  182. /*
  183. * Add IP to be added to todo list. If there is already an "add todo"
  184. * in this list we just incremenent the reference count.
  185. * Returns 0 if we just incremented reference count.
  186. */
  187. static int __qeth_l3_insert_ip_todo(struct qeth_card *card,
  188. struct qeth_ipaddr *addr, int add)
  189. {
  190. struct qeth_ipaddr *tmp, *t;
  191. int found = 0;
  192. if (card->options.sniffer)
  193. return 0;
  194. list_for_each_entry_safe(tmp, t, card->ip_tbd_list, entry) {
  195. if ((addr->type == QETH_IP_TYPE_DEL_ALL_MC) &&
  196. (tmp->type == QETH_IP_TYPE_DEL_ALL_MC))
  197. return 0;
  198. if ((tmp->proto == QETH_PROT_IPV4) &&
  199. (addr->proto == QETH_PROT_IPV4) &&
  200. (tmp->type == addr->type) &&
  201. (tmp->is_multicast == addr->is_multicast) &&
  202. (tmp->u.a4.addr == addr->u.a4.addr) &&
  203. (tmp->u.a4.mask == addr->u.a4.mask)) {
  204. found = 1;
  205. break;
  206. }
  207. if ((tmp->proto == QETH_PROT_IPV6) &&
  208. (addr->proto == QETH_PROT_IPV6) &&
  209. (tmp->type == addr->type) &&
  210. (tmp->is_multicast == addr->is_multicast) &&
  211. (tmp->u.a6.pfxlen == addr->u.a6.pfxlen) &&
  212. (memcmp(&tmp->u.a6.addr, &addr->u.a6.addr,
  213. sizeof(struct in6_addr)) == 0)) {
  214. found = 1;
  215. break;
  216. }
  217. }
  218. if (found) {
  219. if (addr->users != 0)
  220. tmp->users += addr->users;
  221. else
  222. tmp->users += add ? 1 : -1;
  223. if (tmp->users == 0) {
  224. list_del(&tmp->entry);
  225. kfree(tmp);
  226. }
  227. return 0;
  228. } else {
  229. if (addr->type == QETH_IP_TYPE_DEL_ALL_MC)
  230. list_add(&addr->entry, card->ip_tbd_list);
  231. else {
  232. if (addr->users == 0)
  233. addr->users += add ? 1 : -1;
  234. if (add && (addr->type == QETH_IP_TYPE_NORMAL) &&
  235. qeth_l3_is_addr_covered_by_ipato(card, addr)) {
  236. QETH_CARD_TEXT(card, 2, "tkovaddr");
  237. addr->set_flags |= QETH_IPA_SETIP_TAKEOVER_FLAG;
  238. }
  239. list_add_tail(&addr->entry, card->ip_tbd_list);
  240. }
  241. return 1;
  242. }
  243. }
  244. static int qeth_l3_delete_ip(struct qeth_card *card, struct qeth_ipaddr *addr)
  245. {
  246. unsigned long flags;
  247. int rc = 0;
  248. QETH_CARD_TEXT(card, 4, "delip");
  249. if (addr->proto == QETH_PROT_IPV4)
  250. QETH_CARD_HEX(card, 4, &addr->u.a4.addr, 4);
  251. else {
  252. QETH_CARD_HEX(card, 4, &addr->u.a6.addr, 8);
  253. QETH_CARD_HEX(card, 4, ((char *)&addr->u.a6.addr) + 8, 8);
  254. }
  255. spin_lock_irqsave(&card->ip_lock, flags);
  256. rc = __qeth_l3_insert_ip_todo(card, addr, 0);
  257. spin_unlock_irqrestore(&card->ip_lock, flags);
  258. return rc;
  259. }
  260. static int qeth_l3_add_ip(struct qeth_card *card, struct qeth_ipaddr *addr)
  261. {
  262. unsigned long flags;
  263. int rc = 0;
  264. QETH_CARD_TEXT(card, 4, "addip");
  265. if (addr->proto == QETH_PROT_IPV4)
  266. QETH_CARD_HEX(card, 4, &addr->u.a4.addr, 4);
  267. else {
  268. QETH_CARD_HEX(card, 4, &addr->u.a6.addr, 8);
  269. QETH_CARD_HEX(card, 4, ((char *)&addr->u.a6.addr) + 8, 8);
  270. }
  271. spin_lock_irqsave(&card->ip_lock, flags);
  272. rc = __qeth_l3_insert_ip_todo(card, addr, 1);
  273. spin_unlock_irqrestore(&card->ip_lock, flags);
  274. return rc;
  275. }
  276. static struct qeth_ipaddr *qeth_l3_get_addr_buffer(
  277. enum qeth_prot_versions prot)
  278. {
  279. struct qeth_ipaddr *addr;
  280. addr = kzalloc(sizeof(struct qeth_ipaddr), GFP_ATOMIC);
  281. if (addr == NULL) {
  282. return NULL;
  283. }
  284. addr->type = QETH_IP_TYPE_NORMAL;
  285. addr->proto = prot;
  286. return addr;
  287. }
  288. static void qeth_l3_delete_mc_addresses(struct qeth_card *card)
  289. {
  290. struct qeth_ipaddr *iptodo;
  291. unsigned long flags;
  292. QETH_CARD_TEXT(card, 4, "delmc");
  293. iptodo = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
  294. if (!iptodo) {
  295. QETH_CARD_TEXT(card, 2, "dmcnomem");
  296. return;
  297. }
  298. iptodo->type = QETH_IP_TYPE_DEL_ALL_MC;
  299. spin_lock_irqsave(&card->ip_lock, flags);
  300. if (!__qeth_l3_insert_ip_todo(card, iptodo, 0))
  301. kfree(iptodo);
  302. spin_unlock_irqrestore(&card->ip_lock, flags);
  303. }
  304. /*
  305. * Add/remove address to/from card's ip list, i.e. try to add or remove
  306. * reference to/from an IP address that is already registered on the card.
  307. * Returns:
  308. * 0 address was on card and its reference count has been adjusted,
  309. * but is still > 0, so nothing has to be done
  310. * also returns 0 if card was not on card and the todo was to delete
  311. * the address -> there is also nothing to be done
  312. * 1 address was not on card and the todo is to add it to the card's ip
  313. * list
  314. * -1 address was on card and its reference count has been decremented
  315. * to <= 0 by the todo -> address must be removed from card
  316. */
  317. static int __qeth_l3_ref_ip_on_card(struct qeth_card *card,
  318. struct qeth_ipaddr *todo, struct qeth_ipaddr **__addr)
  319. {
  320. struct qeth_ipaddr *addr;
  321. int found = 0;
  322. list_for_each_entry(addr, &card->ip_list, entry) {
  323. if ((addr->proto == QETH_PROT_IPV4) &&
  324. (todo->proto == QETH_PROT_IPV4) &&
  325. (addr->type == todo->type) &&
  326. (addr->u.a4.addr == todo->u.a4.addr) &&
  327. (addr->u.a4.mask == todo->u.a4.mask)) {
  328. found = 1;
  329. break;
  330. }
  331. if ((addr->proto == QETH_PROT_IPV6) &&
  332. (todo->proto == QETH_PROT_IPV6) &&
  333. (addr->type == todo->type) &&
  334. (addr->u.a6.pfxlen == todo->u.a6.pfxlen) &&
  335. (memcmp(&addr->u.a6.addr, &todo->u.a6.addr,
  336. sizeof(struct in6_addr)) == 0)) {
  337. found = 1;
  338. break;
  339. }
  340. }
  341. if (found) {
  342. addr->users += todo->users;
  343. if (addr->users <= 0) {
  344. *__addr = addr;
  345. return -1;
  346. } else {
  347. /* for VIPA and RXIP limit refcount to 1 */
  348. if (addr->type != QETH_IP_TYPE_NORMAL)
  349. addr->users = 1;
  350. return 0;
  351. }
  352. }
  353. if (todo->users > 0) {
  354. /* for VIPA and RXIP limit refcount to 1 */
  355. if (todo->type != QETH_IP_TYPE_NORMAL)
  356. todo->users = 1;
  357. return 1;
  358. } else
  359. return 0;
  360. }
  361. static void __qeth_l3_delete_all_mc(struct qeth_card *card,
  362. unsigned long *flags)
  363. {
  364. struct list_head fail_list;
  365. struct qeth_ipaddr *addr, *tmp;
  366. int rc;
  367. INIT_LIST_HEAD(&fail_list);
  368. again:
  369. list_for_each_entry_safe(addr, tmp, &card->ip_list, entry) {
  370. if (addr->is_multicast) {
  371. list_del(&addr->entry);
  372. spin_unlock_irqrestore(&card->ip_lock, *flags);
  373. rc = qeth_l3_deregister_addr_entry(card, addr);
  374. spin_lock_irqsave(&card->ip_lock, *flags);
  375. if (!rc || (rc == IPA_RC_MC_ADDR_NOT_FOUND))
  376. kfree(addr);
  377. else
  378. list_add_tail(&addr->entry, &fail_list);
  379. goto again;
  380. }
  381. }
  382. list_splice(&fail_list, &card->ip_list);
  383. }
  384. static void qeth_l3_set_ip_addr_list(struct qeth_card *card)
  385. {
  386. struct list_head *tbd_list;
  387. struct qeth_ipaddr *todo, *addr;
  388. unsigned long flags;
  389. int rc;
  390. QETH_CARD_TEXT(card, 2, "sdiplist");
  391. QETH_CARD_HEX(card, 2, &card, sizeof(void *));
  392. if ((card->state != CARD_STATE_UP &&
  393. card->state != CARD_STATE_SOFTSETUP) || card->options.sniffer) {
  394. return;
  395. }
  396. spin_lock_irqsave(&card->ip_lock, flags);
  397. tbd_list = card->ip_tbd_list;
  398. card->ip_tbd_list = kmalloc(sizeof(struct list_head), GFP_ATOMIC);
  399. if (!card->ip_tbd_list) {
  400. QETH_CARD_TEXT(card, 0, "silnomem");
  401. card->ip_tbd_list = tbd_list;
  402. spin_unlock_irqrestore(&card->ip_lock, flags);
  403. return;
  404. } else
  405. INIT_LIST_HEAD(card->ip_tbd_list);
  406. while (!list_empty(tbd_list)) {
  407. todo = list_entry(tbd_list->next, struct qeth_ipaddr, entry);
  408. list_del(&todo->entry);
  409. if (todo->type == QETH_IP_TYPE_DEL_ALL_MC) {
  410. __qeth_l3_delete_all_mc(card, &flags);
  411. kfree(todo);
  412. continue;
  413. }
  414. rc = __qeth_l3_ref_ip_on_card(card, todo, &addr);
  415. if (rc == 0) {
  416. /* nothing to be done; only adjusted refcount */
  417. kfree(todo);
  418. } else if (rc == 1) {
  419. /* new entry to be added to on-card list */
  420. spin_unlock_irqrestore(&card->ip_lock, flags);
  421. rc = qeth_l3_register_addr_entry(card, todo);
  422. spin_lock_irqsave(&card->ip_lock, flags);
  423. if (!rc || (rc == IPA_RC_LAN_OFFLINE))
  424. list_add_tail(&todo->entry, &card->ip_list);
  425. else
  426. kfree(todo);
  427. } else if (rc == -1) {
  428. /* on-card entry to be removed */
  429. list_del_init(&addr->entry);
  430. spin_unlock_irqrestore(&card->ip_lock, flags);
  431. rc = qeth_l3_deregister_addr_entry(card, addr);
  432. spin_lock_irqsave(&card->ip_lock, flags);
  433. if (!rc || (rc == IPA_RC_IP_ADDRESS_NOT_DEFINED))
  434. kfree(addr);
  435. else
  436. list_add_tail(&addr->entry, &card->ip_list);
  437. kfree(todo);
  438. }
  439. }
  440. spin_unlock_irqrestore(&card->ip_lock, flags);
  441. kfree(tbd_list);
  442. }
  443. static void qeth_l3_clear_ip_list(struct qeth_card *card, int recover)
  444. {
  445. struct qeth_ipaddr *addr, *tmp;
  446. unsigned long flags;
  447. QETH_CARD_TEXT(card, 4, "clearip");
  448. if (recover && card->options.sniffer)
  449. return;
  450. spin_lock_irqsave(&card->ip_lock, flags);
  451. /* clear todo list */
  452. list_for_each_entry_safe(addr, tmp, card->ip_tbd_list, entry) {
  453. list_del(&addr->entry);
  454. kfree(addr);
  455. }
  456. while (!list_empty(&card->ip_list)) {
  457. addr = list_entry(card->ip_list.next,
  458. struct qeth_ipaddr, entry);
  459. list_del_init(&addr->entry);
  460. if (!recover || addr->is_multicast) {
  461. kfree(addr);
  462. continue;
  463. }
  464. list_add_tail(&addr->entry, card->ip_tbd_list);
  465. }
  466. spin_unlock_irqrestore(&card->ip_lock, flags);
  467. }
  468. static int qeth_l3_address_exists_in_list(struct list_head *list,
  469. struct qeth_ipaddr *addr, int same_type)
  470. {
  471. struct qeth_ipaddr *tmp;
  472. list_for_each_entry(tmp, list, entry) {
  473. if ((tmp->proto == QETH_PROT_IPV4) &&
  474. (addr->proto == QETH_PROT_IPV4) &&
  475. ((same_type && (tmp->type == addr->type)) ||
  476. (!same_type && (tmp->type != addr->type))) &&
  477. (tmp->u.a4.addr == addr->u.a4.addr))
  478. return 1;
  479. if ((tmp->proto == QETH_PROT_IPV6) &&
  480. (addr->proto == QETH_PROT_IPV6) &&
  481. ((same_type && (tmp->type == addr->type)) ||
  482. (!same_type && (tmp->type != addr->type))) &&
  483. (memcmp(&tmp->u.a6.addr, &addr->u.a6.addr,
  484. sizeof(struct in6_addr)) == 0))
  485. return 1;
  486. }
  487. return 0;
  488. }
  489. static int qeth_l3_send_setdelmc(struct qeth_card *card,
  490. struct qeth_ipaddr *addr, int ipacmd)
  491. {
  492. int rc;
  493. struct qeth_cmd_buffer *iob;
  494. struct qeth_ipa_cmd *cmd;
  495. QETH_CARD_TEXT(card, 4, "setdelmc");
  496. iob = qeth_get_ipacmd_buffer(card, ipacmd, addr->proto);
  497. cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
  498. memcpy(&cmd->data.setdelipm.mac, addr->mac, OSA_ADDR_LEN);
  499. if (addr->proto == QETH_PROT_IPV6)
  500. memcpy(cmd->data.setdelipm.ip6, &addr->u.a6.addr,
  501. sizeof(struct in6_addr));
  502. else
  503. memcpy(&cmd->data.setdelipm.ip4, &addr->u.a4.addr, 4);
  504. rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
  505. return rc;
  506. }
  507. static void qeth_l3_fill_netmask(u8 *netmask, unsigned int len)
  508. {
  509. int i, j;
  510. for (i = 0; i < 16; i++) {
  511. j = (len) - (i * 8);
  512. if (j >= 8)
  513. netmask[i] = 0xff;
  514. else if (j > 0)
  515. netmask[i] = (u8)(0xFF00 >> j);
  516. else
  517. netmask[i] = 0;
  518. }
  519. }
  520. static int qeth_l3_send_setdelip(struct qeth_card *card,
  521. struct qeth_ipaddr *addr, int ipacmd, unsigned int flags)
  522. {
  523. int rc;
  524. struct qeth_cmd_buffer *iob;
  525. struct qeth_ipa_cmd *cmd;
  526. __u8 netmask[16];
  527. QETH_CARD_TEXT(card, 4, "setdelip");
  528. QETH_CARD_TEXT_(card, 4, "flags%02X", flags);
  529. iob = qeth_get_ipacmd_buffer(card, ipacmd, addr->proto);
  530. cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
  531. if (addr->proto == QETH_PROT_IPV6) {
  532. memcpy(cmd->data.setdelip6.ip_addr, &addr->u.a6.addr,
  533. sizeof(struct in6_addr));
  534. qeth_l3_fill_netmask(netmask, addr->u.a6.pfxlen);
  535. memcpy(cmd->data.setdelip6.mask, netmask,
  536. sizeof(struct in6_addr));
  537. cmd->data.setdelip6.flags = flags;
  538. } else {
  539. memcpy(cmd->data.setdelip4.ip_addr, &addr->u.a4.addr, 4);
  540. memcpy(cmd->data.setdelip4.mask, &addr->u.a4.mask, 4);
  541. cmd->data.setdelip4.flags = flags;
  542. }
  543. rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
  544. return rc;
  545. }
  546. static int qeth_l3_send_setrouting(struct qeth_card *card,
  547. enum qeth_routing_types type, enum qeth_prot_versions prot)
  548. {
  549. int rc;
  550. struct qeth_ipa_cmd *cmd;
  551. struct qeth_cmd_buffer *iob;
  552. QETH_CARD_TEXT(card, 4, "setroutg");
  553. iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SETRTG, prot);
  554. cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
  555. cmd->data.setrtg.type = (type);
  556. rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
  557. return rc;
  558. }
  559. static void qeth_l3_correct_routing_type(struct qeth_card *card,
  560. enum qeth_routing_types *type, enum qeth_prot_versions prot)
  561. {
  562. if (card->info.type == QETH_CARD_TYPE_IQD) {
  563. switch (*type) {
  564. case NO_ROUTER:
  565. case PRIMARY_CONNECTOR:
  566. case SECONDARY_CONNECTOR:
  567. case MULTICAST_ROUTER:
  568. return;
  569. default:
  570. goto out_inval;
  571. }
  572. } else {
  573. switch (*type) {
  574. case NO_ROUTER:
  575. case PRIMARY_ROUTER:
  576. case SECONDARY_ROUTER:
  577. return;
  578. case MULTICAST_ROUTER:
  579. if (qeth_is_ipafunc_supported(card, prot,
  580. IPA_OSA_MC_ROUTER))
  581. return;
  582. default:
  583. goto out_inval;
  584. }
  585. }
  586. out_inval:
  587. *type = NO_ROUTER;
  588. }
  589. int qeth_l3_setrouting_v4(struct qeth_card *card)
  590. {
  591. int rc;
  592. QETH_CARD_TEXT(card, 3, "setrtg4");
  593. qeth_l3_correct_routing_type(card, &card->options.route4.type,
  594. QETH_PROT_IPV4);
  595. rc = qeth_l3_send_setrouting(card, card->options.route4.type,
  596. QETH_PROT_IPV4);
  597. if (rc) {
  598. card->options.route4.type = NO_ROUTER;
  599. QETH_DBF_MESSAGE(2, "Error (0x%04x) while setting routing type"
  600. " on %s. Type set to 'no router'.\n", rc,
  601. QETH_CARD_IFNAME(card));
  602. }
  603. return rc;
  604. }
  605. int qeth_l3_setrouting_v6(struct qeth_card *card)
  606. {
  607. int rc = 0;
  608. QETH_CARD_TEXT(card, 3, "setrtg6");
  609. #ifdef CONFIG_QETH_IPV6
  610. if (!qeth_is_supported(card, IPA_IPV6))
  611. return 0;
  612. qeth_l3_correct_routing_type(card, &card->options.route6.type,
  613. QETH_PROT_IPV6);
  614. rc = qeth_l3_send_setrouting(card, card->options.route6.type,
  615. QETH_PROT_IPV6);
  616. if (rc) {
  617. card->options.route6.type = NO_ROUTER;
  618. QETH_DBF_MESSAGE(2, "Error (0x%04x) while setting routing type"
  619. " on %s. Type set to 'no router'.\n", rc,
  620. QETH_CARD_IFNAME(card));
  621. }
  622. #endif
  623. return rc;
  624. }
  625. /*
  626. * IP address takeover related functions
  627. */
  628. static void qeth_l3_clear_ipato_list(struct qeth_card *card)
  629. {
  630. struct qeth_ipato_entry *ipatoe, *tmp;
  631. unsigned long flags;
  632. spin_lock_irqsave(&card->ip_lock, flags);
  633. list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry) {
  634. list_del(&ipatoe->entry);
  635. kfree(ipatoe);
  636. }
  637. spin_unlock_irqrestore(&card->ip_lock, flags);
  638. }
  639. int qeth_l3_add_ipato_entry(struct qeth_card *card,
  640. struct qeth_ipato_entry *new)
  641. {
  642. struct qeth_ipato_entry *ipatoe;
  643. unsigned long flags;
  644. int rc = 0;
  645. QETH_CARD_TEXT(card, 2, "addipato");
  646. spin_lock_irqsave(&card->ip_lock, flags);
  647. list_for_each_entry(ipatoe, &card->ipato.entries, entry) {
  648. if (ipatoe->proto != new->proto)
  649. continue;
  650. if (!memcmp(ipatoe->addr, new->addr,
  651. (ipatoe->proto == QETH_PROT_IPV4)? 4:16) &&
  652. (ipatoe->mask_bits == new->mask_bits)) {
  653. rc = -EEXIST;
  654. break;
  655. }
  656. }
  657. if (!rc)
  658. list_add_tail(&new->entry, &card->ipato.entries);
  659. spin_unlock_irqrestore(&card->ip_lock, flags);
  660. return rc;
  661. }
  662. void qeth_l3_del_ipato_entry(struct qeth_card *card,
  663. enum qeth_prot_versions proto, u8 *addr, int mask_bits)
  664. {
  665. struct qeth_ipato_entry *ipatoe, *tmp;
  666. unsigned long flags;
  667. QETH_CARD_TEXT(card, 2, "delipato");
  668. spin_lock_irqsave(&card->ip_lock, flags);
  669. list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry) {
  670. if (ipatoe->proto != proto)
  671. continue;
  672. if (!memcmp(ipatoe->addr, addr,
  673. (proto == QETH_PROT_IPV4)? 4:16) &&
  674. (ipatoe->mask_bits == mask_bits)) {
  675. list_del(&ipatoe->entry);
  676. kfree(ipatoe);
  677. }
  678. }
  679. spin_unlock_irqrestore(&card->ip_lock, flags);
  680. }
  681. /*
  682. * VIPA related functions
  683. */
  684. int qeth_l3_add_vipa(struct qeth_card *card, enum qeth_prot_versions proto,
  685. const u8 *addr)
  686. {
  687. struct qeth_ipaddr *ipaddr;
  688. unsigned long flags;
  689. int rc = 0;
  690. ipaddr = qeth_l3_get_addr_buffer(proto);
  691. if (ipaddr) {
  692. if (proto == QETH_PROT_IPV4) {
  693. QETH_CARD_TEXT(card, 2, "addvipa4");
  694. memcpy(&ipaddr->u.a4.addr, addr, 4);
  695. ipaddr->u.a4.mask = 0;
  696. } else if (proto == QETH_PROT_IPV6) {
  697. QETH_CARD_TEXT(card, 2, "addvipa6");
  698. memcpy(&ipaddr->u.a6.addr, addr, 16);
  699. ipaddr->u.a6.pfxlen = 0;
  700. }
  701. ipaddr->type = QETH_IP_TYPE_VIPA;
  702. ipaddr->set_flags = QETH_IPA_SETIP_VIPA_FLAG;
  703. ipaddr->del_flags = QETH_IPA_DELIP_VIPA_FLAG;
  704. } else
  705. return -ENOMEM;
  706. spin_lock_irqsave(&card->ip_lock, flags);
  707. if (qeth_l3_address_exists_in_list(&card->ip_list, ipaddr, 0) ||
  708. qeth_l3_address_exists_in_list(card->ip_tbd_list, ipaddr, 0))
  709. rc = -EEXIST;
  710. spin_unlock_irqrestore(&card->ip_lock, flags);
  711. if (rc) {
  712. return rc;
  713. }
  714. if (!qeth_l3_add_ip(card, ipaddr))
  715. kfree(ipaddr);
  716. qeth_l3_set_ip_addr_list(card);
  717. return rc;
  718. }
  719. void qeth_l3_del_vipa(struct qeth_card *card, enum qeth_prot_versions proto,
  720. const u8 *addr)
  721. {
  722. struct qeth_ipaddr *ipaddr;
  723. ipaddr = qeth_l3_get_addr_buffer(proto);
  724. if (ipaddr) {
  725. if (proto == QETH_PROT_IPV4) {
  726. QETH_CARD_TEXT(card, 2, "delvipa4");
  727. memcpy(&ipaddr->u.a4.addr, addr, 4);
  728. ipaddr->u.a4.mask = 0;
  729. } else if (proto == QETH_PROT_IPV6) {
  730. QETH_CARD_TEXT(card, 2, "delvipa6");
  731. memcpy(&ipaddr->u.a6.addr, addr, 16);
  732. ipaddr->u.a6.pfxlen = 0;
  733. }
  734. ipaddr->type = QETH_IP_TYPE_VIPA;
  735. } else
  736. return;
  737. if (!qeth_l3_delete_ip(card, ipaddr))
  738. kfree(ipaddr);
  739. qeth_l3_set_ip_addr_list(card);
  740. }
  741. /*
  742. * proxy ARP related functions
  743. */
  744. int qeth_l3_add_rxip(struct qeth_card *card, enum qeth_prot_versions proto,
  745. const u8 *addr)
  746. {
  747. struct qeth_ipaddr *ipaddr;
  748. unsigned long flags;
  749. int rc = 0;
  750. ipaddr = qeth_l3_get_addr_buffer(proto);
  751. if (ipaddr) {
  752. if (proto == QETH_PROT_IPV4) {
  753. QETH_CARD_TEXT(card, 2, "addrxip4");
  754. memcpy(&ipaddr->u.a4.addr, addr, 4);
  755. ipaddr->u.a4.mask = 0;
  756. } else if (proto == QETH_PROT_IPV6) {
  757. QETH_CARD_TEXT(card, 2, "addrxip6");
  758. memcpy(&ipaddr->u.a6.addr, addr, 16);
  759. ipaddr->u.a6.pfxlen = 0;
  760. }
  761. ipaddr->type = QETH_IP_TYPE_RXIP;
  762. ipaddr->set_flags = QETH_IPA_SETIP_TAKEOVER_FLAG;
  763. ipaddr->del_flags = 0;
  764. } else
  765. return -ENOMEM;
  766. spin_lock_irqsave(&card->ip_lock, flags);
  767. if (qeth_l3_address_exists_in_list(&card->ip_list, ipaddr, 0) ||
  768. qeth_l3_address_exists_in_list(card->ip_tbd_list, ipaddr, 0))
  769. rc = -EEXIST;
  770. spin_unlock_irqrestore(&card->ip_lock, flags);
  771. if (rc) {
  772. return rc;
  773. }
  774. if (!qeth_l3_add_ip(card, ipaddr))
  775. kfree(ipaddr);
  776. qeth_l3_set_ip_addr_list(card);
  777. return 0;
  778. }
  779. void qeth_l3_del_rxip(struct qeth_card *card, enum qeth_prot_versions proto,
  780. const u8 *addr)
  781. {
  782. struct qeth_ipaddr *ipaddr;
  783. ipaddr = qeth_l3_get_addr_buffer(proto);
  784. if (ipaddr) {
  785. if (proto == QETH_PROT_IPV4) {
  786. QETH_CARD_TEXT(card, 2, "addrxip4");
  787. memcpy(&ipaddr->u.a4.addr, addr, 4);
  788. ipaddr->u.a4.mask = 0;
  789. } else if (proto == QETH_PROT_IPV6) {
  790. QETH_CARD_TEXT(card, 2, "addrxip6");
  791. memcpy(&ipaddr->u.a6.addr, addr, 16);
  792. ipaddr->u.a6.pfxlen = 0;
  793. }
  794. ipaddr->type = QETH_IP_TYPE_RXIP;
  795. } else
  796. return;
  797. if (!qeth_l3_delete_ip(card, ipaddr))
  798. kfree(ipaddr);
  799. qeth_l3_set_ip_addr_list(card);
  800. }
  801. static int qeth_l3_register_addr_entry(struct qeth_card *card,
  802. struct qeth_ipaddr *addr)
  803. {
  804. char buf[50];
  805. int rc = 0;
  806. int cnt = 3;
  807. if (addr->proto == QETH_PROT_IPV4) {
  808. QETH_CARD_TEXT(card, 2, "setaddr4");
  809. QETH_CARD_HEX(card, 3, &addr->u.a4.addr, sizeof(int));
  810. } else if (addr->proto == QETH_PROT_IPV6) {
  811. QETH_CARD_TEXT(card, 2, "setaddr6");
  812. QETH_CARD_HEX(card, 3, &addr->u.a6.addr, 8);
  813. QETH_CARD_HEX(card, 3, ((char *)&addr->u.a6.addr) + 8, 8);
  814. } else {
  815. QETH_CARD_TEXT(card, 2, "setaddr?");
  816. QETH_CARD_HEX(card, 3, addr, sizeof(struct qeth_ipaddr));
  817. }
  818. do {
  819. if (addr->is_multicast)
  820. rc = qeth_l3_send_setdelmc(card, addr, IPA_CMD_SETIPM);
  821. else
  822. rc = qeth_l3_send_setdelip(card, addr, IPA_CMD_SETIP,
  823. addr->set_flags);
  824. if (rc)
  825. QETH_CARD_TEXT(card, 2, "failed");
  826. } while ((--cnt > 0) && rc);
  827. if (rc) {
  828. QETH_CARD_TEXT(card, 2, "FAILED");
  829. qeth_l3_ipaddr_to_string(addr->proto, (u8 *)&addr->u, buf);
  830. dev_warn(&card->gdev->dev,
  831. "Registering IP address %s failed\n", buf);
  832. }
  833. return rc;
  834. }
  835. static int qeth_l3_deregister_addr_entry(struct qeth_card *card,
  836. struct qeth_ipaddr *addr)
  837. {
  838. int rc = 0;
  839. if (addr->proto == QETH_PROT_IPV4) {
  840. QETH_CARD_TEXT(card, 2, "deladdr4");
  841. QETH_CARD_HEX(card, 3, &addr->u.a4.addr, sizeof(int));
  842. } else if (addr->proto == QETH_PROT_IPV6) {
  843. QETH_CARD_TEXT(card, 2, "deladdr6");
  844. QETH_CARD_HEX(card, 3, &addr->u.a6.addr, 8);
  845. QETH_CARD_HEX(card, 3, ((char *)&addr->u.a6.addr) + 8, 8);
  846. } else {
  847. QETH_CARD_TEXT(card, 2, "deladdr?");
  848. QETH_CARD_HEX(card, 3, addr, sizeof(struct qeth_ipaddr));
  849. }
  850. if (addr->is_multicast)
  851. rc = qeth_l3_send_setdelmc(card, addr, IPA_CMD_DELIPM);
  852. else
  853. rc = qeth_l3_send_setdelip(card, addr, IPA_CMD_DELIP,
  854. addr->del_flags);
  855. if (rc)
  856. QETH_CARD_TEXT(card, 2, "failed");
  857. return rc;
  858. }
  859. static inline u8 qeth_l3_get_qeth_hdr_flags4(int cast_type)
  860. {
  861. if (cast_type == RTN_MULTICAST)
  862. return QETH_CAST_MULTICAST;
  863. if (cast_type == RTN_BROADCAST)
  864. return QETH_CAST_BROADCAST;
  865. return QETH_CAST_UNICAST;
  866. }
  867. static inline u8 qeth_l3_get_qeth_hdr_flags6(int cast_type)
  868. {
  869. u8 ct = QETH_HDR_PASSTHRU | QETH_HDR_IPV6;
  870. if (cast_type == RTN_MULTICAST)
  871. return ct | QETH_CAST_MULTICAST;
  872. if (cast_type == RTN_ANYCAST)
  873. return ct | QETH_CAST_ANYCAST;
  874. if (cast_type == RTN_BROADCAST)
  875. return ct | QETH_CAST_BROADCAST;
  876. return ct | QETH_CAST_UNICAST;
  877. }
  878. static int qeth_l3_send_setadp_mode(struct qeth_card *card, __u32 command,
  879. __u32 mode)
  880. {
  881. int rc;
  882. struct qeth_cmd_buffer *iob;
  883. struct qeth_ipa_cmd *cmd;
  884. QETH_CARD_TEXT(card, 4, "adpmode");
  885. iob = qeth_get_adapter_cmd(card, command,
  886. sizeof(struct qeth_ipacmd_setadpparms));
  887. cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
  888. cmd->data.setadapterparms.data.mode = mode;
  889. rc = qeth_send_ipa_cmd(card, iob, qeth_default_setadapterparms_cb,
  890. NULL);
  891. return rc;
  892. }
  893. static int qeth_l3_setadapter_hstr(struct qeth_card *card)
  894. {
  895. int rc;
  896. QETH_CARD_TEXT(card, 4, "adphstr");
  897. if (qeth_adp_supported(card, IPA_SETADP_SET_BROADCAST_MODE)) {
  898. rc = qeth_l3_send_setadp_mode(card,
  899. IPA_SETADP_SET_BROADCAST_MODE,
  900. card->options.broadcast_mode);
  901. if (rc)
  902. QETH_DBF_MESSAGE(2, "couldn't set broadcast mode on "
  903. "device %s: x%x\n",
  904. CARD_BUS_ID(card), rc);
  905. rc = qeth_l3_send_setadp_mode(card,
  906. IPA_SETADP_ALTER_MAC_ADDRESS,
  907. card->options.macaddr_mode);
  908. if (rc)
  909. QETH_DBF_MESSAGE(2, "couldn't set macaddr mode on "
  910. "device %s: x%x\n", CARD_BUS_ID(card), rc);
  911. return rc;
  912. }
  913. if (card->options.broadcast_mode == QETH_TR_BROADCAST_LOCAL)
  914. QETH_DBF_MESSAGE(2, "set adapter parameters not available "
  915. "to set broadcast mode, using ALLRINGS "
  916. "on device %s:\n", CARD_BUS_ID(card));
  917. if (card->options.macaddr_mode == QETH_TR_MACADDR_CANONICAL)
  918. QETH_DBF_MESSAGE(2, "set adapter parameters not available "
  919. "to set macaddr mode, using NONCANONICAL "
  920. "on device %s:\n", CARD_BUS_ID(card));
  921. return 0;
  922. }
  923. static int qeth_l3_setadapter_parms(struct qeth_card *card)
  924. {
  925. int rc;
  926. QETH_DBF_TEXT(SETUP, 2, "setadprm");
  927. if (!qeth_is_supported(card, IPA_SETADAPTERPARMS)) {
  928. dev_info(&card->gdev->dev,
  929. "set adapter parameters not supported.\n");
  930. QETH_DBF_TEXT(SETUP, 2, " notsupp");
  931. return 0;
  932. }
  933. rc = qeth_query_setadapterparms(card);
  934. if (rc) {
  935. QETH_DBF_MESSAGE(2, "%s couldn't set adapter parameters: "
  936. "0x%x\n", dev_name(&card->gdev->dev), rc);
  937. return rc;
  938. }
  939. if (qeth_adp_supported(card, IPA_SETADP_ALTER_MAC_ADDRESS)) {
  940. rc = qeth_setadpparms_change_macaddr(card);
  941. if (rc)
  942. dev_warn(&card->gdev->dev, "Reading the adapter MAC"
  943. " address failed\n");
  944. }
  945. if ((card->info.link_type == QETH_LINK_TYPE_HSTR) ||
  946. (card->info.link_type == QETH_LINK_TYPE_LANE_TR))
  947. rc = qeth_l3_setadapter_hstr(card);
  948. return rc;
  949. }
  950. static int qeth_l3_default_setassparms_cb(struct qeth_card *card,
  951. struct qeth_reply *reply, unsigned long data)
  952. {
  953. struct qeth_ipa_cmd *cmd;
  954. QETH_CARD_TEXT(card, 4, "defadpcb");
  955. cmd = (struct qeth_ipa_cmd *) data;
  956. if (cmd->hdr.return_code == 0) {
  957. cmd->hdr.return_code = cmd->data.setassparms.hdr.return_code;
  958. if (cmd->hdr.prot_version == QETH_PROT_IPV4)
  959. card->options.ipa4.enabled_funcs = cmd->hdr.ipa_enabled;
  960. if (cmd->hdr.prot_version == QETH_PROT_IPV6)
  961. card->options.ipa6.enabled_funcs = cmd->hdr.ipa_enabled;
  962. }
  963. if (cmd->data.setassparms.hdr.assist_no == IPA_INBOUND_CHECKSUM &&
  964. cmd->data.setassparms.hdr.command_code == IPA_CMD_ASS_START) {
  965. card->info.csum_mask = cmd->data.setassparms.data.flags_32bit;
  966. QETH_CARD_TEXT_(card, 3, "csum:%d", card->info.csum_mask);
  967. }
  968. if (cmd->data.setassparms.hdr.assist_no == IPA_OUTBOUND_CHECKSUM &&
  969. cmd->data.setassparms.hdr.command_code == IPA_CMD_ASS_START) {
  970. card->info.tx_csum_mask =
  971. cmd->data.setassparms.data.flags_32bit;
  972. QETH_CARD_TEXT_(card, 3, "tcsu:%d", card->info.tx_csum_mask);
  973. }
  974. return 0;
  975. }
  976. static struct qeth_cmd_buffer *qeth_l3_get_setassparms_cmd(
  977. struct qeth_card *card, enum qeth_ipa_funcs ipa_func, __u16 cmd_code,
  978. __u16 len, enum qeth_prot_versions prot)
  979. {
  980. struct qeth_cmd_buffer *iob;
  981. struct qeth_ipa_cmd *cmd;
  982. QETH_CARD_TEXT(card, 4, "getasscm");
  983. iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SETASSPARMS, prot);
  984. cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
  985. cmd->data.setassparms.hdr.assist_no = ipa_func;
  986. cmd->data.setassparms.hdr.length = 8 + len;
  987. cmd->data.setassparms.hdr.command_code = cmd_code;
  988. cmd->data.setassparms.hdr.return_code = 0;
  989. cmd->data.setassparms.hdr.seq_no = 0;
  990. return iob;
  991. }
  992. static int qeth_l3_send_setassparms(struct qeth_card *card,
  993. struct qeth_cmd_buffer *iob, __u16 len, long data,
  994. int (*reply_cb)(struct qeth_card *, struct qeth_reply *,
  995. unsigned long),
  996. void *reply_param)
  997. {
  998. int rc;
  999. struct qeth_ipa_cmd *cmd;
  1000. QETH_CARD_TEXT(card, 4, "sendassp");
  1001. cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
  1002. if (len <= sizeof(__u32))
  1003. cmd->data.setassparms.data.flags_32bit = (__u32) data;
  1004. else /* (len > sizeof(__u32)) */
  1005. memcpy(&cmd->data.setassparms.data, (void *) data, len);
  1006. rc = qeth_send_ipa_cmd(card, iob, reply_cb, reply_param);
  1007. return rc;
  1008. }
  1009. #ifdef CONFIG_QETH_IPV6
  1010. static int qeth_l3_send_simple_setassparms_ipv6(struct qeth_card *card,
  1011. enum qeth_ipa_funcs ipa_func, __u16 cmd_code)
  1012. {
  1013. int rc;
  1014. struct qeth_cmd_buffer *iob;
  1015. QETH_CARD_TEXT(card, 4, "simassp6");
  1016. iob = qeth_l3_get_setassparms_cmd(card, ipa_func, cmd_code,
  1017. 0, QETH_PROT_IPV6);
  1018. rc = qeth_l3_send_setassparms(card, iob, 0, 0,
  1019. qeth_l3_default_setassparms_cb, NULL);
  1020. return rc;
  1021. }
  1022. #endif
  1023. static int qeth_l3_send_simple_setassparms(struct qeth_card *card,
  1024. enum qeth_ipa_funcs ipa_func, __u16 cmd_code, long data)
  1025. {
  1026. int rc;
  1027. int length = 0;
  1028. struct qeth_cmd_buffer *iob;
  1029. QETH_CARD_TEXT(card, 4, "simassp4");
  1030. if (data)
  1031. length = sizeof(__u32);
  1032. iob = qeth_l3_get_setassparms_cmd(card, ipa_func, cmd_code,
  1033. length, QETH_PROT_IPV4);
  1034. rc = qeth_l3_send_setassparms(card, iob, length, data,
  1035. qeth_l3_default_setassparms_cb, NULL);
  1036. return rc;
  1037. }
  1038. static int qeth_l3_start_ipa_arp_processing(struct qeth_card *card)
  1039. {
  1040. int rc;
  1041. QETH_CARD_TEXT(card, 3, "ipaarp");
  1042. if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
  1043. dev_info(&card->gdev->dev,
  1044. "ARP processing not supported on %s!\n",
  1045. QETH_CARD_IFNAME(card));
  1046. return 0;
  1047. }
  1048. rc = qeth_l3_send_simple_setassparms(card, IPA_ARP_PROCESSING,
  1049. IPA_CMD_ASS_START, 0);
  1050. if (rc) {
  1051. dev_warn(&card->gdev->dev,
  1052. "Starting ARP processing support for %s failed\n",
  1053. QETH_CARD_IFNAME(card));
  1054. }
  1055. return rc;
  1056. }
  1057. static int qeth_l3_start_ipa_ip_fragmentation(struct qeth_card *card)
  1058. {
  1059. int rc;
  1060. QETH_CARD_TEXT(card, 3, "ipaipfrg");
  1061. if (!qeth_is_supported(card, IPA_IP_FRAGMENTATION)) {
  1062. dev_info(&card->gdev->dev,
  1063. "Hardware IP fragmentation not supported on %s\n",
  1064. QETH_CARD_IFNAME(card));
  1065. return -EOPNOTSUPP;
  1066. }
  1067. rc = qeth_l3_send_simple_setassparms(card, IPA_IP_FRAGMENTATION,
  1068. IPA_CMD_ASS_START, 0);
  1069. if (rc) {
  1070. dev_warn(&card->gdev->dev,
  1071. "Starting IP fragmentation support for %s failed\n",
  1072. QETH_CARD_IFNAME(card));
  1073. } else
  1074. dev_info(&card->gdev->dev,
  1075. "Hardware IP fragmentation enabled \n");
  1076. return rc;
  1077. }
  1078. static int qeth_l3_start_ipa_source_mac(struct qeth_card *card)
  1079. {
  1080. int rc;
  1081. QETH_CARD_TEXT(card, 3, "stsrcmac");
  1082. if (!qeth_is_supported(card, IPA_SOURCE_MAC)) {
  1083. dev_info(&card->gdev->dev,
  1084. "Inbound source MAC-address not supported on %s\n",
  1085. QETH_CARD_IFNAME(card));
  1086. return -EOPNOTSUPP;
  1087. }
  1088. rc = qeth_l3_send_simple_setassparms(card, IPA_SOURCE_MAC,
  1089. IPA_CMD_ASS_START, 0);
  1090. if (rc)
  1091. dev_warn(&card->gdev->dev,
  1092. "Starting source MAC-address support for %s failed\n",
  1093. QETH_CARD_IFNAME(card));
  1094. return rc;
  1095. }
  1096. static int qeth_l3_start_ipa_vlan(struct qeth_card *card)
  1097. {
  1098. int rc = 0;
  1099. QETH_CARD_TEXT(card, 3, "strtvlan");
  1100. if (!qeth_is_supported(card, IPA_FULL_VLAN)) {
  1101. dev_info(&card->gdev->dev,
  1102. "VLAN not supported on %s\n", QETH_CARD_IFNAME(card));
  1103. return -EOPNOTSUPP;
  1104. }
  1105. rc = qeth_l3_send_simple_setassparms(card, IPA_VLAN_PRIO,
  1106. IPA_CMD_ASS_START, 0);
  1107. if (rc) {
  1108. dev_warn(&card->gdev->dev,
  1109. "Starting VLAN support for %s failed\n",
  1110. QETH_CARD_IFNAME(card));
  1111. } else {
  1112. dev_info(&card->gdev->dev, "VLAN enabled\n");
  1113. }
  1114. return rc;
  1115. }
  1116. static int qeth_l3_start_ipa_multicast(struct qeth_card *card)
  1117. {
  1118. int rc;
  1119. QETH_CARD_TEXT(card, 3, "stmcast");
  1120. if (!qeth_is_supported(card, IPA_MULTICASTING)) {
  1121. dev_info(&card->gdev->dev,
  1122. "Multicast not supported on %s\n",
  1123. QETH_CARD_IFNAME(card));
  1124. return -EOPNOTSUPP;
  1125. }
  1126. rc = qeth_l3_send_simple_setassparms(card, IPA_MULTICASTING,
  1127. IPA_CMD_ASS_START, 0);
  1128. if (rc) {
  1129. dev_warn(&card->gdev->dev,
  1130. "Starting multicast support for %s failed\n",
  1131. QETH_CARD_IFNAME(card));
  1132. } else {
  1133. dev_info(&card->gdev->dev, "Multicast enabled\n");
  1134. card->dev->flags |= IFF_MULTICAST;
  1135. }
  1136. return rc;
  1137. }
  1138. #ifdef CONFIG_QETH_IPV6
  1139. static int qeth_l3_softsetup_ipv6(struct qeth_card *card)
  1140. {
  1141. int rc;
  1142. QETH_CARD_TEXT(card, 3, "softipv6");
  1143. if (card->info.type == QETH_CARD_TYPE_IQD)
  1144. goto out;
  1145. rc = qeth_query_ipassists(card, QETH_PROT_IPV6);
  1146. if (rc) {
  1147. dev_err(&card->gdev->dev,
  1148. "Activating IPv6 support for %s failed\n",
  1149. QETH_CARD_IFNAME(card));
  1150. return rc;
  1151. }
  1152. rc = qeth_l3_send_simple_setassparms(card, IPA_IPV6,
  1153. IPA_CMD_ASS_START, 3);
  1154. if (rc) {
  1155. dev_err(&card->gdev->dev,
  1156. "Activating IPv6 support for %s failed\n",
  1157. QETH_CARD_IFNAME(card));
  1158. return rc;
  1159. }
  1160. rc = qeth_l3_send_simple_setassparms_ipv6(card, IPA_IPV6,
  1161. IPA_CMD_ASS_START);
  1162. if (rc) {
  1163. dev_err(&card->gdev->dev,
  1164. "Activating IPv6 support for %s failed\n",
  1165. QETH_CARD_IFNAME(card));
  1166. return rc;
  1167. }
  1168. rc = qeth_l3_send_simple_setassparms_ipv6(card, IPA_PASSTHRU,
  1169. IPA_CMD_ASS_START);
  1170. if (rc) {
  1171. dev_warn(&card->gdev->dev,
  1172. "Enabling the passthrough mode for %s failed\n",
  1173. QETH_CARD_IFNAME(card));
  1174. return rc;
  1175. }
  1176. out:
  1177. dev_info(&card->gdev->dev, "IPV6 enabled\n");
  1178. return 0;
  1179. }
  1180. #endif
  1181. static int qeth_l3_start_ipa_ipv6(struct qeth_card *card)
  1182. {
  1183. int rc = 0;
  1184. QETH_CARD_TEXT(card, 3, "strtipv6");
  1185. if (!qeth_is_supported(card, IPA_IPV6)) {
  1186. dev_info(&card->gdev->dev,
  1187. "IPv6 not supported on %s\n", QETH_CARD_IFNAME(card));
  1188. return 0;
  1189. }
  1190. #ifdef CONFIG_QETH_IPV6
  1191. rc = qeth_l3_softsetup_ipv6(card);
  1192. #endif
  1193. return rc ;
  1194. }
  1195. static int qeth_l3_start_ipa_broadcast(struct qeth_card *card)
  1196. {
  1197. int rc;
  1198. QETH_CARD_TEXT(card, 3, "stbrdcst");
  1199. card->info.broadcast_capable = 0;
  1200. if (!qeth_is_supported(card, IPA_FILTERING)) {
  1201. dev_info(&card->gdev->dev,
  1202. "Broadcast not supported on %s\n",
  1203. QETH_CARD_IFNAME(card));
  1204. rc = -EOPNOTSUPP;
  1205. goto out;
  1206. }
  1207. rc = qeth_l3_send_simple_setassparms(card, IPA_FILTERING,
  1208. IPA_CMD_ASS_START, 0);
  1209. if (rc) {
  1210. dev_warn(&card->gdev->dev, "Enabling broadcast filtering for "
  1211. "%s failed\n", QETH_CARD_IFNAME(card));
  1212. goto out;
  1213. }
  1214. rc = qeth_l3_send_simple_setassparms(card, IPA_FILTERING,
  1215. IPA_CMD_ASS_CONFIGURE, 1);
  1216. if (rc) {
  1217. dev_warn(&card->gdev->dev,
  1218. "Setting up broadcast filtering for %s failed\n",
  1219. QETH_CARD_IFNAME(card));
  1220. goto out;
  1221. }
  1222. card->info.broadcast_capable = QETH_BROADCAST_WITH_ECHO;
  1223. dev_info(&card->gdev->dev, "Broadcast enabled\n");
  1224. rc = qeth_l3_send_simple_setassparms(card, IPA_FILTERING,
  1225. IPA_CMD_ASS_ENABLE, 1);
  1226. if (rc) {
  1227. dev_warn(&card->gdev->dev, "Setting up broadcast echo "
  1228. "filtering for %s failed\n", QETH_CARD_IFNAME(card));
  1229. goto out;
  1230. }
  1231. card->info.broadcast_capable = QETH_BROADCAST_WITHOUT_ECHO;
  1232. out:
  1233. if (card->info.broadcast_capable)
  1234. card->dev->flags |= IFF_BROADCAST;
  1235. else
  1236. card->dev->flags &= ~IFF_BROADCAST;
  1237. return rc;
  1238. }
  1239. static int qeth_l3_send_checksum_command(struct qeth_card *card)
  1240. {
  1241. int rc;
  1242. rc = qeth_l3_send_simple_setassparms(card, IPA_INBOUND_CHECKSUM,
  1243. IPA_CMD_ASS_START, 0);
  1244. if (rc) {
  1245. dev_warn(&card->gdev->dev, "Starting HW checksumming for %s "
  1246. "failed, using SW checksumming\n",
  1247. QETH_CARD_IFNAME(card));
  1248. return rc;
  1249. }
  1250. rc = qeth_l3_send_simple_setassparms(card, IPA_INBOUND_CHECKSUM,
  1251. IPA_CMD_ASS_ENABLE,
  1252. card->info.csum_mask);
  1253. if (rc) {
  1254. dev_warn(&card->gdev->dev, "Enabling HW checksumming for %s "
  1255. "failed, using SW checksumming\n",
  1256. QETH_CARD_IFNAME(card));
  1257. return rc;
  1258. }
  1259. return 0;
  1260. }
  1261. int qeth_l3_set_rx_csum(struct qeth_card *card, int on)
  1262. {
  1263. int rc = 0;
  1264. if (on) {
  1265. rc = qeth_l3_send_checksum_command(card);
  1266. if (rc)
  1267. return -EIO;
  1268. dev_info(&card->gdev->dev,
  1269. "HW Checksumming (inbound) enabled\n");
  1270. } else {
  1271. rc = qeth_l3_send_simple_setassparms(card,
  1272. IPA_INBOUND_CHECKSUM, IPA_CMD_ASS_STOP, 0);
  1273. if (rc)
  1274. return -EIO;
  1275. }
  1276. return 0;
  1277. }
  1278. static int qeth_l3_start_ipa_checksum(struct qeth_card *card)
  1279. {
  1280. QETH_CARD_TEXT(card, 3, "strtcsum");
  1281. if (card->dev->features & NETIF_F_RXCSUM) {
  1282. rtnl_lock();
  1283. /* force set_features call */
  1284. card->dev->features &= ~NETIF_F_RXCSUM;
  1285. netdev_update_features(card->dev);
  1286. rtnl_unlock();
  1287. }
  1288. return 0;
  1289. }
  1290. static int qeth_l3_start_ipa_tx_checksum(struct qeth_card *card)
  1291. {
  1292. int rc = 0;
  1293. if (!qeth_is_supported(card, IPA_OUTBOUND_CHECKSUM))
  1294. return rc;
  1295. rc = qeth_l3_send_simple_setassparms(card, IPA_OUTBOUND_CHECKSUM,
  1296. IPA_CMD_ASS_START, 0);
  1297. if (rc)
  1298. goto err_out;
  1299. rc = qeth_l3_send_simple_setassparms(card, IPA_OUTBOUND_CHECKSUM,
  1300. IPA_CMD_ASS_ENABLE, card->info.tx_csum_mask);
  1301. if (rc)
  1302. goto err_out;
  1303. dev_info(&card->gdev->dev, "HW TX Checksumming enabled\n");
  1304. return rc;
  1305. err_out:
  1306. dev_warn(&card->gdev->dev, "Enabling HW TX checksumming for %s "
  1307. "failed, using SW TX checksumming\n", QETH_CARD_IFNAME(card));
  1308. return rc;
  1309. }
  1310. static int qeth_l3_start_ipa_tso(struct qeth_card *card)
  1311. {
  1312. int rc;
  1313. QETH_CARD_TEXT(card, 3, "sttso");
  1314. if (!qeth_is_supported(card, IPA_OUTBOUND_TSO)) {
  1315. dev_info(&card->gdev->dev,
  1316. "Outbound TSO not supported on %s\n",
  1317. QETH_CARD_IFNAME(card));
  1318. rc = -EOPNOTSUPP;
  1319. } else {
  1320. rc = qeth_l3_send_simple_setassparms(card, IPA_OUTBOUND_TSO,
  1321. IPA_CMD_ASS_START, 0);
  1322. if (rc)
  1323. dev_warn(&card->gdev->dev, "Starting outbound TCP "
  1324. "segmentation offload for %s failed\n",
  1325. QETH_CARD_IFNAME(card));
  1326. else
  1327. dev_info(&card->gdev->dev,
  1328. "Outbound TSO enabled\n");
  1329. }
  1330. if (rc)
  1331. card->dev->features &= ~NETIF_F_TSO;
  1332. return rc;
  1333. }
  1334. static int qeth_l3_start_ipassists(struct qeth_card *card)
  1335. {
  1336. QETH_CARD_TEXT(card, 3, "strtipas");
  1337. qeth_set_access_ctrl_online(card); /* go on*/
  1338. qeth_l3_start_ipa_arp_processing(card); /* go on*/
  1339. qeth_l3_start_ipa_ip_fragmentation(card); /* go on*/
  1340. qeth_l3_start_ipa_source_mac(card); /* go on*/
  1341. qeth_l3_start_ipa_vlan(card); /* go on*/
  1342. qeth_l3_start_ipa_multicast(card); /* go on*/
  1343. qeth_l3_start_ipa_ipv6(card); /* go on*/
  1344. qeth_l3_start_ipa_broadcast(card); /* go on*/
  1345. qeth_l3_start_ipa_checksum(card); /* go on*/
  1346. qeth_l3_start_ipa_tx_checksum(card);
  1347. qeth_l3_start_ipa_tso(card); /* go on*/
  1348. return 0;
  1349. }
  1350. static int qeth_l3_iqd_read_initial_mac_cb(struct qeth_card *card,
  1351. struct qeth_reply *reply, unsigned long data)
  1352. {
  1353. struct qeth_ipa_cmd *cmd;
  1354. cmd = (struct qeth_ipa_cmd *) data;
  1355. if (cmd->hdr.return_code == 0)
  1356. memcpy(card->dev->dev_addr,
  1357. cmd->data.create_destroy_addr.unique_id, ETH_ALEN);
  1358. else
  1359. random_ether_addr(card->dev->dev_addr);
  1360. return 0;
  1361. }
  1362. static int qeth_l3_iqd_read_initial_mac(struct qeth_card *card)
  1363. {
  1364. int rc = 0;
  1365. struct qeth_cmd_buffer *iob;
  1366. struct qeth_ipa_cmd *cmd;
  1367. QETH_DBF_TEXT(SETUP, 2, "hsrmac");
  1368. iob = qeth_get_ipacmd_buffer(card, IPA_CMD_CREATE_ADDR,
  1369. QETH_PROT_IPV6);
  1370. cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
  1371. *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
  1372. card->info.unique_id;
  1373. rc = qeth_send_ipa_cmd(card, iob, qeth_l3_iqd_read_initial_mac_cb,
  1374. NULL);
  1375. return rc;
  1376. }
  1377. static int qeth_l3_get_unique_id_cb(struct qeth_card *card,
  1378. struct qeth_reply *reply, unsigned long data)
  1379. {
  1380. struct qeth_ipa_cmd *cmd;
  1381. cmd = (struct qeth_ipa_cmd *) data;
  1382. if (cmd->hdr.return_code == 0)
  1383. card->info.unique_id = *((__u16 *)
  1384. &cmd->data.create_destroy_addr.unique_id[6]);
  1385. else {
  1386. card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
  1387. UNIQUE_ID_NOT_BY_CARD;
  1388. dev_warn(&card->gdev->dev, "The network adapter failed to "
  1389. "generate a unique ID\n");
  1390. }
  1391. return 0;
  1392. }
  1393. static int qeth_l3_get_unique_id(struct qeth_card *card)
  1394. {
  1395. int rc = 0;
  1396. struct qeth_cmd_buffer *iob;
  1397. struct qeth_ipa_cmd *cmd;
  1398. QETH_DBF_TEXT(SETUP, 2, "guniqeid");
  1399. if (!qeth_is_supported(card, IPA_IPV6)) {
  1400. card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
  1401. UNIQUE_ID_NOT_BY_CARD;
  1402. return 0;
  1403. }
  1404. iob = qeth_get_ipacmd_buffer(card, IPA_CMD_CREATE_ADDR,
  1405. QETH_PROT_IPV6);
  1406. cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
  1407. *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
  1408. card->info.unique_id;
  1409. rc = qeth_send_ipa_cmd(card, iob, qeth_l3_get_unique_id_cb, NULL);
  1410. return rc;
  1411. }
  1412. static int
  1413. qeth_diags_trace_cb(struct qeth_card *card, struct qeth_reply *reply,
  1414. unsigned long data)
  1415. {
  1416. struct qeth_ipa_cmd *cmd;
  1417. __u16 rc;
  1418. QETH_DBF_TEXT(SETUP, 2, "diastrcb");
  1419. cmd = (struct qeth_ipa_cmd *)data;
  1420. rc = cmd->hdr.return_code;
  1421. if (rc)
  1422. QETH_CARD_TEXT_(card, 2, "dxter%x", rc);
  1423. switch (cmd->data.diagass.action) {
  1424. case QETH_DIAGS_CMD_TRACE_QUERY:
  1425. break;
  1426. case QETH_DIAGS_CMD_TRACE_DISABLE:
  1427. switch (rc) {
  1428. case 0:
  1429. case IPA_RC_INVALID_SUBCMD:
  1430. card->info.promisc_mode = SET_PROMISC_MODE_OFF;
  1431. dev_info(&card->gdev->dev, "The HiperSockets network "
  1432. "traffic analyzer is deactivated\n");
  1433. break;
  1434. default:
  1435. break;
  1436. }
  1437. break;
  1438. case QETH_DIAGS_CMD_TRACE_ENABLE:
  1439. switch (rc) {
  1440. case 0:
  1441. card->info.promisc_mode = SET_PROMISC_MODE_ON;
  1442. dev_info(&card->gdev->dev, "The HiperSockets network "
  1443. "traffic analyzer is activated\n");
  1444. break;
  1445. case IPA_RC_HARDWARE_AUTH_ERROR:
  1446. dev_warn(&card->gdev->dev, "The device is not "
  1447. "authorized to run as a HiperSockets network "
  1448. "traffic analyzer\n");
  1449. break;
  1450. case IPA_RC_TRACE_ALREADY_ACTIVE:
  1451. dev_warn(&card->gdev->dev, "A HiperSockets "
  1452. "network traffic analyzer is already "
  1453. "active in the HiperSockets LAN\n");
  1454. break;
  1455. default:
  1456. break;
  1457. }
  1458. break;
  1459. default:
  1460. QETH_DBF_MESSAGE(2, "Unknown sniffer action (0x%04x) on %s\n",
  1461. cmd->data.diagass.action, QETH_CARD_IFNAME(card));
  1462. }
  1463. return 0;
  1464. }
  1465. static int
  1466. qeth_diags_trace(struct qeth_card *card, enum qeth_diags_trace_cmds diags_cmd)
  1467. {
  1468. struct qeth_cmd_buffer *iob;
  1469. struct qeth_ipa_cmd *cmd;
  1470. QETH_DBF_TEXT(SETUP, 2, "diagtrac");
  1471. iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SET_DIAG_ASS, 0);
  1472. cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
  1473. cmd->data.diagass.subcmd_len = 16;
  1474. cmd->data.diagass.subcmd = QETH_DIAGS_CMD_TRACE;
  1475. cmd->data.diagass.type = QETH_DIAGS_TYPE_HIPERSOCKET;
  1476. cmd->data.diagass.action = diags_cmd;
  1477. return qeth_send_ipa_cmd(card, iob, qeth_diags_trace_cb, NULL);
  1478. }
  1479. static void qeth_l3_get_mac_for_ipm(__u32 ipm, char *mac,
  1480. struct net_device *dev)
  1481. {
  1482. if (dev->type == ARPHRD_IEEE802_TR)
  1483. ip_tr_mc_map(ipm, mac);
  1484. else
  1485. ip_eth_mc_map(ipm, mac);
  1486. }
  1487. static void qeth_l3_add_mc(struct qeth_card *card, struct in_device *in4_dev)
  1488. {
  1489. struct qeth_ipaddr *ipm;
  1490. struct ip_mc_list *im4;
  1491. char buf[MAX_ADDR_LEN];
  1492. QETH_CARD_TEXT(card, 4, "addmc");
  1493. for (im4 = rcu_dereference(in4_dev->mc_list); im4 != NULL;
  1494. im4 = rcu_dereference(im4->next_rcu)) {
  1495. qeth_l3_get_mac_for_ipm(im4->multiaddr, buf, in4_dev->dev);
  1496. ipm = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
  1497. if (!ipm)
  1498. continue;
  1499. ipm->u.a4.addr = im4->multiaddr;
  1500. memcpy(ipm->mac, buf, OSA_ADDR_LEN);
  1501. ipm->is_multicast = 1;
  1502. if (!qeth_l3_add_ip(card, ipm))
  1503. kfree(ipm);
  1504. }
  1505. }
  1506. static void qeth_l3_add_vlan_mc(struct qeth_card *card)
  1507. {
  1508. struct in_device *in_dev;
  1509. struct vlan_group *vg;
  1510. int i;
  1511. QETH_CARD_TEXT(card, 4, "addmcvl");
  1512. if (!qeth_is_supported(card, IPA_FULL_VLAN) || (card->vlangrp == NULL))
  1513. return;
  1514. vg = card->vlangrp;
  1515. for (i = 0; i < VLAN_N_VID; i++) {
  1516. struct net_device *netdev = vlan_group_get_device(vg, i);
  1517. if (netdev == NULL ||
  1518. !(netdev->flags & IFF_UP))
  1519. continue;
  1520. in_dev = in_dev_get(netdev);
  1521. if (!in_dev)
  1522. continue;
  1523. rcu_read_lock();
  1524. qeth_l3_add_mc(card, in_dev);
  1525. rcu_read_unlock();
  1526. in_dev_put(in_dev);
  1527. }
  1528. }
  1529. static void qeth_l3_add_multicast_ipv4(struct qeth_card *card)
  1530. {
  1531. struct in_device *in4_dev;
  1532. QETH_CARD_TEXT(card, 4, "chkmcv4");
  1533. in4_dev = in_dev_get(card->dev);
  1534. if (in4_dev == NULL)
  1535. return;
  1536. rcu_read_lock();
  1537. qeth_l3_add_mc(card, in4_dev);
  1538. qeth_l3_add_vlan_mc(card);
  1539. rcu_read_unlock();
  1540. in_dev_put(in4_dev);
  1541. }
  1542. #ifdef CONFIG_QETH_IPV6
  1543. static void qeth_l3_add_mc6(struct qeth_card *card, struct inet6_dev *in6_dev)
  1544. {
  1545. struct qeth_ipaddr *ipm;
  1546. struct ifmcaddr6 *im6;
  1547. char buf[MAX_ADDR_LEN];
  1548. QETH_CARD_TEXT(card, 4, "addmc6");
  1549. for (im6 = in6_dev->mc_list; im6 != NULL; im6 = im6->next) {
  1550. ndisc_mc_map(&im6->mca_addr, buf, in6_dev->dev, 0);
  1551. ipm = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
  1552. if (!ipm)
  1553. continue;
  1554. ipm->is_multicast = 1;
  1555. memcpy(ipm->mac, buf, OSA_ADDR_LEN);
  1556. memcpy(&ipm->u.a6.addr, &im6->mca_addr.s6_addr,
  1557. sizeof(struct in6_addr));
  1558. if (!qeth_l3_add_ip(card, ipm))
  1559. kfree(ipm);
  1560. }
  1561. }
  1562. static void qeth_l3_add_vlan_mc6(struct qeth_card *card)
  1563. {
  1564. struct inet6_dev *in_dev;
  1565. struct vlan_group *vg;
  1566. int i;
  1567. QETH_CARD_TEXT(card, 4, "admc6vl");
  1568. if (!qeth_is_supported(card, IPA_FULL_VLAN) || (card->vlangrp == NULL))
  1569. return;
  1570. vg = card->vlangrp;
  1571. for (i = 0; i < VLAN_N_VID; i++) {
  1572. struct net_device *netdev = vlan_group_get_device(vg, i);
  1573. if (netdev == NULL ||
  1574. !(netdev->flags & IFF_UP))
  1575. continue;
  1576. in_dev = in6_dev_get(netdev);
  1577. if (!in_dev)
  1578. continue;
  1579. read_lock_bh(&in_dev->lock);
  1580. qeth_l3_add_mc6(card, in_dev);
  1581. read_unlock_bh(&in_dev->lock);
  1582. in6_dev_put(in_dev);
  1583. }
  1584. }
  1585. static void qeth_l3_add_multicast_ipv6(struct qeth_card *card)
  1586. {
  1587. struct inet6_dev *in6_dev;
  1588. QETH_CARD_TEXT(card, 4, "chkmcv6");
  1589. if (!qeth_is_supported(card, IPA_IPV6))
  1590. return ;
  1591. in6_dev = in6_dev_get(card->dev);
  1592. if (in6_dev == NULL)
  1593. return;
  1594. read_lock_bh(&in6_dev->lock);
  1595. qeth_l3_add_mc6(card, in6_dev);
  1596. qeth_l3_add_vlan_mc6(card);
  1597. read_unlock_bh(&in6_dev->lock);
  1598. in6_dev_put(in6_dev);
  1599. }
  1600. #endif /* CONFIG_QETH_IPV6 */
  1601. static void qeth_l3_free_vlan_addresses4(struct qeth_card *card,
  1602. unsigned short vid)
  1603. {
  1604. struct in_device *in_dev;
  1605. struct in_ifaddr *ifa;
  1606. struct qeth_ipaddr *addr;
  1607. QETH_CARD_TEXT(card, 4, "frvaddr4");
  1608. in_dev = in_dev_get(vlan_group_get_device(card->vlangrp, vid));
  1609. if (!in_dev)
  1610. return;
  1611. for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
  1612. addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
  1613. if (addr) {
  1614. addr->u.a4.addr = ifa->ifa_address;
  1615. addr->u.a4.mask = ifa->ifa_mask;
  1616. addr->type = QETH_IP_TYPE_NORMAL;
  1617. if (!qeth_l3_delete_ip(card, addr))
  1618. kfree(addr);
  1619. }
  1620. }
  1621. in_dev_put(in_dev);
  1622. }
  1623. static void qeth_l3_free_vlan_addresses6(struct qeth_card *card,
  1624. unsigned short vid)
  1625. {
  1626. #ifdef CONFIG_QETH_IPV6
  1627. struct inet6_dev *in6_dev;
  1628. struct inet6_ifaddr *ifa;
  1629. struct qeth_ipaddr *addr;
  1630. QETH_CARD_TEXT(card, 4, "frvaddr6");
  1631. in6_dev = in6_dev_get(vlan_group_get_device(card->vlangrp, vid));
  1632. if (!in6_dev)
  1633. return;
  1634. list_for_each_entry(ifa, &in6_dev->addr_list, if_list) {
  1635. addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
  1636. if (addr) {
  1637. memcpy(&addr->u.a6.addr, &ifa->addr,
  1638. sizeof(struct in6_addr));
  1639. addr->u.a6.pfxlen = ifa->prefix_len;
  1640. addr->type = QETH_IP_TYPE_NORMAL;
  1641. if (!qeth_l3_delete_ip(card, addr))
  1642. kfree(addr);
  1643. }
  1644. }
  1645. in6_dev_put(in6_dev);
  1646. #endif /* CONFIG_QETH_IPV6 */
  1647. }
  1648. static void qeth_l3_free_vlan_addresses(struct qeth_card *card,
  1649. unsigned short vid)
  1650. {
  1651. if (!card->vlangrp)
  1652. return;
  1653. qeth_l3_free_vlan_addresses4(card, vid);
  1654. qeth_l3_free_vlan_addresses6(card, vid);
  1655. }
  1656. static void qeth_l3_vlan_rx_register(struct net_device *dev,
  1657. struct vlan_group *grp)
  1658. {
  1659. struct qeth_card *card = dev->ml_priv;
  1660. unsigned long flags;
  1661. QETH_CARD_TEXT(card, 4, "vlanreg");
  1662. spin_lock_irqsave(&card->vlanlock, flags);
  1663. card->vlangrp = grp;
  1664. spin_unlock_irqrestore(&card->vlanlock, flags);
  1665. }
  1666. static void qeth_l3_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
  1667. {
  1668. return;
  1669. }
  1670. static void qeth_l3_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
  1671. {
  1672. struct qeth_card *card = dev->ml_priv;
  1673. unsigned long flags;
  1674. QETH_CARD_TEXT_(card, 4, "kid:%d", vid);
  1675. if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
  1676. QETH_CARD_TEXT(card, 3, "kidREC");
  1677. return;
  1678. }
  1679. spin_lock_irqsave(&card->vlanlock, flags);
  1680. /* unregister IP addresses of vlan device */
  1681. qeth_l3_free_vlan_addresses(card, vid);
  1682. vlan_group_set_device(card->vlangrp, vid, NULL);
  1683. spin_unlock_irqrestore(&card->vlanlock, flags);
  1684. qeth_l3_set_multicast_list(card->dev);
  1685. }
  1686. static inline int qeth_l3_rebuild_skb(struct qeth_card *card,
  1687. struct sk_buff *skb, struct qeth_hdr *hdr,
  1688. unsigned short *vlan_id)
  1689. {
  1690. __be16 prot;
  1691. struct iphdr *ip_hdr;
  1692. unsigned char tg_addr[MAX_ADDR_LEN];
  1693. int is_vlan = 0;
  1694. if (!(hdr->hdr.l3.flags & QETH_HDR_PASSTHRU)) {
  1695. prot = htons((hdr->hdr.l3.flags & QETH_HDR_IPV6)? ETH_P_IPV6 :
  1696. ETH_P_IP);
  1697. switch (hdr->hdr.l3.flags & QETH_HDR_CAST_MASK) {
  1698. case QETH_CAST_MULTICAST:
  1699. switch (prot) {
  1700. #ifdef CONFIG_QETH_IPV6
  1701. case __constant_htons(ETH_P_IPV6):
  1702. ndisc_mc_map((struct in6_addr *)
  1703. skb->data + 24,
  1704. tg_addr, card->dev, 0);
  1705. break;
  1706. #endif
  1707. case __constant_htons(ETH_P_IP):
  1708. ip_hdr = (struct iphdr *)skb->data;
  1709. (card->dev->type == ARPHRD_IEEE802_TR) ?
  1710. ip_tr_mc_map(ip_hdr->daddr, tg_addr):
  1711. ip_eth_mc_map(ip_hdr->daddr, tg_addr);
  1712. break;
  1713. default:
  1714. memcpy(tg_addr, card->dev->broadcast,
  1715. card->dev->addr_len);
  1716. }
  1717. card->stats.multicast++;
  1718. skb->pkt_type = PACKET_MULTICAST;
  1719. break;
  1720. case QETH_CAST_BROADCAST:
  1721. memcpy(tg_addr, card->dev->broadcast,
  1722. card->dev->addr_len);
  1723. card->stats.multicast++;
  1724. skb->pkt_type = PACKET_BROADCAST;
  1725. break;
  1726. case QETH_CAST_UNICAST:
  1727. case QETH_CAST_ANYCAST:
  1728. case QETH_CAST_NOCAST:
  1729. default:
  1730. if (card->options.sniffer)
  1731. skb->pkt_type = PACKET_OTHERHOST;
  1732. else
  1733. skb->pkt_type = PACKET_HOST;
  1734. memcpy(tg_addr, card->dev->dev_addr,
  1735. card->dev->addr_len);
  1736. }
  1737. if (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_SRC_MAC_ADDR)
  1738. card->dev->header_ops->create(skb, card->dev, prot,
  1739. tg_addr, &hdr->hdr.l3.dest_addr[2],
  1740. card->dev->addr_len);
  1741. else
  1742. card->dev->header_ops->create(skb, card->dev, prot,
  1743. tg_addr, "FAKELL", card->dev->addr_len);
  1744. }
  1745. #ifdef CONFIG_TR
  1746. if (card->dev->type == ARPHRD_IEEE802_TR)
  1747. skb->protocol = tr_type_trans(skb, card->dev);
  1748. else
  1749. #endif
  1750. skb->protocol = eth_type_trans(skb, card->dev);
  1751. if (hdr->hdr.l3.ext_flags &
  1752. (QETH_HDR_EXT_VLAN_FRAME | QETH_HDR_EXT_INCLUDE_VLAN_TAG)) {
  1753. *vlan_id = (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_VLAN_FRAME) ?
  1754. hdr->hdr.l3.vlan_id : *((u16 *)&hdr->hdr.l3.dest_addr[12]);
  1755. is_vlan = 1;
  1756. }
  1757. if (card->dev->features & NETIF_F_RXCSUM) {
  1758. if ((hdr->hdr.l3.ext_flags &
  1759. (QETH_HDR_EXT_CSUM_HDR_REQ |
  1760. QETH_HDR_EXT_CSUM_TRANSP_REQ)) ==
  1761. (QETH_HDR_EXT_CSUM_HDR_REQ |
  1762. QETH_HDR_EXT_CSUM_TRANSP_REQ))
  1763. skb->ip_summed = CHECKSUM_UNNECESSARY;
  1764. else
  1765. skb->ip_summed = CHECKSUM_NONE;
  1766. } else
  1767. skb->ip_summed = CHECKSUM_NONE;
  1768. return is_vlan;
  1769. }
  1770. static int qeth_l3_process_inbound_buffer(struct qeth_card *card,
  1771. int budget, int *done)
  1772. {
  1773. int work_done = 0;
  1774. struct sk_buff *skb;
  1775. struct qeth_hdr *hdr;
  1776. __u16 vlan_tag = 0;
  1777. int is_vlan;
  1778. unsigned int len;
  1779. *done = 0;
  1780. BUG_ON(!budget);
  1781. while (budget) {
  1782. skb = qeth_core_get_next_skb(card,
  1783. card->qdio.in_q->bufs[card->rx.b_index].buffer,
  1784. &card->rx.b_element, &card->rx.e_offset, &hdr);
  1785. if (!skb) {
  1786. *done = 1;
  1787. break;
  1788. }
  1789. skb->dev = card->dev;
  1790. switch (hdr->hdr.l3.id) {
  1791. case QETH_HEADER_TYPE_LAYER3:
  1792. is_vlan = qeth_l3_rebuild_skb(card, skb, hdr,
  1793. &vlan_tag);
  1794. len = skb->len;
  1795. if (is_vlan && !card->options.sniffer)
  1796. vlan_gro_receive(&card->napi, card->vlangrp,
  1797. vlan_tag, skb);
  1798. else
  1799. napi_gro_receive(&card->napi, skb);
  1800. break;
  1801. case QETH_HEADER_TYPE_LAYER2: /* for HiperSockets sniffer */
  1802. skb->pkt_type = PACKET_HOST;
  1803. skb->protocol = eth_type_trans(skb, skb->dev);
  1804. len = skb->len;
  1805. netif_receive_skb(skb);
  1806. break;
  1807. default:
  1808. dev_kfree_skb_any(skb);
  1809. QETH_CARD_TEXT(card, 3, "inbunkno");
  1810. QETH_DBF_HEX(CTRL, 3, hdr, QETH_DBF_CTRL_LEN);
  1811. continue;
  1812. }
  1813. work_done++;
  1814. budget--;
  1815. card->stats.rx_packets++;
  1816. card->stats.rx_bytes += len;
  1817. }
  1818. return work_done;
  1819. }
  1820. static int qeth_l3_poll(struct napi_struct *napi, int budget)
  1821. {
  1822. struct qeth_card *card = container_of(napi, struct qeth_card, napi);
  1823. int work_done = 0;
  1824. struct qeth_qdio_buffer *buffer;
  1825. int done;
  1826. int new_budget = budget;
  1827. if (card->options.performance_stats) {
  1828. card->perf_stats.inbound_cnt++;
  1829. card->perf_stats.inbound_start_time = qeth_get_micros();
  1830. }
  1831. while (1) {
  1832. if (!card->rx.b_count) {
  1833. card->rx.qdio_err = 0;
  1834. card->rx.b_count = qdio_get_next_buffers(
  1835. card->data.ccwdev, 0, &card->rx.b_index,
  1836. &card->rx.qdio_err);
  1837. if (card->rx.b_count <= 0) {
  1838. card->rx.b_count = 0;
  1839. break;
  1840. }
  1841. card->rx.b_element =
  1842. &card->qdio.in_q->bufs[card->rx.b_index]
  1843. .buffer->element[0];
  1844. card->rx.e_offset = 0;
  1845. }
  1846. while (card->rx.b_count) {
  1847. buffer = &card->qdio.in_q->bufs[card->rx.b_index];
  1848. if (!(card->rx.qdio_err &&
  1849. qeth_check_qdio_errors(card, buffer->buffer,
  1850. card->rx.qdio_err, "qinerr")))
  1851. work_done += qeth_l3_process_inbound_buffer(
  1852. card, new_budget, &done);
  1853. else
  1854. done = 1;
  1855. if (done) {
  1856. if (card->options.performance_stats)
  1857. card->perf_stats.bufs_rec++;
  1858. qeth_put_buffer_pool_entry(card,
  1859. buffer->pool_entry);
  1860. qeth_queue_input_buffer(card, card->rx.b_index);
  1861. card->rx.b_count--;
  1862. if (card->rx.b_count) {
  1863. card->rx.b_index =
  1864. (card->rx.b_index + 1) %
  1865. QDIO_MAX_BUFFERS_PER_Q;
  1866. card->rx.b_element =
  1867. &card->qdio.in_q
  1868. ->bufs[card->rx.b_index]
  1869. .buffer->element[0];
  1870. card->rx.e_offset = 0;
  1871. }
  1872. }
  1873. if (work_done >= budget)
  1874. goto out;
  1875. else
  1876. new_budget = budget - work_done;
  1877. }
  1878. }
  1879. napi_complete(napi);
  1880. if (qdio_start_irq(card->data.ccwdev, 0))
  1881. napi_schedule(&card->napi);
  1882. out:
  1883. if (card->options.performance_stats)
  1884. card->perf_stats.inbound_time += qeth_get_micros() -
  1885. card->perf_stats.inbound_start_time;
  1886. return work_done;
  1887. }
  1888. static int qeth_l3_verify_vlan_dev(struct net_device *dev,
  1889. struct qeth_card *card)
  1890. {
  1891. int rc = 0;
  1892. struct vlan_group *vg;
  1893. int i;
  1894. vg = card->vlangrp;
  1895. if (!vg)
  1896. return rc;
  1897. for (i = 0; i < VLAN_N_VID; i++) {
  1898. if (vlan_group_get_device(vg, i) == dev) {
  1899. rc = QETH_VLAN_CARD;
  1900. break;
  1901. }
  1902. }
  1903. if (rc && !(vlan_dev_real_dev(dev)->ml_priv == (void *)card))
  1904. return 0;
  1905. return rc;
  1906. }
  1907. static int qeth_l3_verify_dev(struct net_device *dev)
  1908. {
  1909. struct qeth_card *card;
  1910. unsigned long flags;
  1911. int rc = 0;
  1912. read_lock_irqsave(&qeth_core_card_list.rwlock, flags);
  1913. list_for_each_entry(card, &qeth_core_card_list.list, list) {
  1914. if (card->dev == dev) {
  1915. rc = QETH_REAL_CARD;
  1916. break;
  1917. }
  1918. rc = qeth_l3_verify_vlan_dev(dev, card);
  1919. if (rc)
  1920. break;
  1921. }
  1922. read_unlock_irqrestore(&qeth_core_card_list.rwlock, flags);
  1923. return rc;
  1924. }
  1925. static struct qeth_card *qeth_l3_get_card_from_dev(struct net_device *dev)
  1926. {
  1927. struct qeth_card *card = NULL;
  1928. int rc;
  1929. rc = qeth_l3_verify_dev(dev);
  1930. if (rc == QETH_REAL_CARD)
  1931. card = dev->ml_priv;
  1932. else if (rc == QETH_VLAN_CARD)
  1933. card = vlan_dev_real_dev(dev)->ml_priv;
  1934. if (card && card->options.layer2)
  1935. card = NULL;
  1936. if (card)
  1937. QETH_CARD_TEXT_(card, 4, "%d", rc);
  1938. return card ;
  1939. }
  1940. static int qeth_l3_stop_card(struct qeth_card *card, int recovery_mode)
  1941. {
  1942. int rc = 0;
  1943. QETH_DBF_TEXT(SETUP, 2, "stopcard");
  1944. QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
  1945. qeth_set_allowed_threads(card, 0, 1);
  1946. if (card->options.sniffer &&
  1947. (card->info.promisc_mode == SET_PROMISC_MODE_ON))
  1948. qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_DISABLE);
  1949. if (card->read.state == CH_STATE_UP &&
  1950. card->write.state == CH_STATE_UP &&
  1951. (card->state == CARD_STATE_UP)) {
  1952. if (recovery_mode)
  1953. qeth_l3_stop(card->dev);
  1954. else {
  1955. rtnl_lock();
  1956. dev_close(card->dev);
  1957. rtnl_unlock();
  1958. }
  1959. card->state = CARD_STATE_SOFTSETUP;
  1960. }
  1961. if (card->state == CARD_STATE_SOFTSETUP) {
  1962. qeth_l3_clear_ip_list(card, 1);
  1963. qeth_clear_ipacmd_list(card);
  1964. card->state = CARD_STATE_HARDSETUP;
  1965. }
  1966. if (card->state == CARD_STATE_HARDSETUP) {
  1967. qeth_qdio_clear_card(card, 0);
  1968. qeth_clear_qdio_buffers(card);
  1969. qeth_clear_working_pool_list(card);
  1970. card->state = CARD_STATE_DOWN;
  1971. }
  1972. if (card->state == CARD_STATE_DOWN) {
  1973. qeth_clear_cmd_buffers(&card->read);
  1974. qeth_clear_cmd_buffers(&card->write);
  1975. }
  1976. return rc;
  1977. }
  1978. /*
  1979. * test for and Switch promiscuous mode (on or off)
  1980. * either for guestlan or HiperSocket Sniffer
  1981. */
  1982. static void
  1983. qeth_l3_handle_promisc_mode(struct qeth_card *card)
  1984. {
  1985. struct net_device *dev = card->dev;
  1986. if (((dev->flags & IFF_PROMISC) &&
  1987. (card->info.promisc_mode == SET_PROMISC_MODE_ON)) ||
  1988. (!(dev->flags & IFF_PROMISC) &&
  1989. (card->info.promisc_mode == SET_PROMISC_MODE_OFF)))
  1990. return;
  1991. if (card->info.guestlan) { /* Guestlan trace */
  1992. if (qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
  1993. qeth_setadp_promisc_mode(card);
  1994. } else if (card->options.sniffer && /* HiperSockets trace */
  1995. qeth_adp_supported(card, IPA_SETADP_SET_DIAG_ASSIST)) {
  1996. if (dev->flags & IFF_PROMISC) {
  1997. QETH_CARD_TEXT(card, 3, "+promisc");
  1998. qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_ENABLE);
  1999. } else {
  2000. QETH_CARD_TEXT(card, 3, "-promisc");
  2001. qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_DISABLE);
  2002. }
  2003. }
  2004. }
  2005. static void qeth_l3_set_multicast_list(struct net_device *dev)
  2006. {
  2007. struct qeth_card *card = dev->ml_priv;
  2008. QETH_CARD_TEXT(card, 3, "setmulti");
  2009. if (qeth_threads_running(card, QETH_RECOVER_THREAD) &&
  2010. (card->state != CARD_STATE_UP))
  2011. return;
  2012. if (!card->options.sniffer) {
  2013. qeth_l3_delete_mc_addresses(card);
  2014. qeth_l3_add_multicast_ipv4(card);
  2015. #ifdef CONFIG_QETH_IPV6
  2016. qeth_l3_add_multicast_ipv6(card);
  2017. #endif
  2018. qeth_l3_set_ip_addr_list(card);
  2019. if (!qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
  2020. return;
  2021. }
  2022. qeth_l3_handle_promisc_mode(card);
  2023. }
  2024. static const char *qeth_l3_arp_get_error_cause(int *rc)
  2025. {
  2026. switch (*rc) {
  2027. case QETH_IPA_ARP_RC_FAILED:
  2028. *rc = -EIO;
  2029. return "operation failed";
  2030. case QETH_IPA_ARP_RC_NOTSUPP:
  2031. *rc = -EOPNOTSUPP;
  2032. return "operation not supported";
  2033. case QETH_IPA_ARP_RC_OUT_OF_RANGE:
  2034. *rc = -EINVAL;
  2035. return "argument out of range";
  2036. case QETH_IPA_ARP_RC_Q_NOTSUPP:
  2037. *rc = -EOPNOTSUPP;
  2038. return "query operation not supported";
  2039. case QETH_IPA_ARP_RC_Q_NO_DATA:
  2040. *rc = -ENOENT;
  2041. return "no query data available";
  2042. default:
  2043. return "unknown error";
  2044. }
  2045. }
  2046. static int qeth_l3_arp_set_no_entries(struct qeth_card *card, int no_entries)
  2047. {
  2048. int tmp;
  2049. int rc;
  2050. QETH_CARD_TEXT(card, 3, "arpstnoe");
  2051. /*
  2052. * currently GuestLAN only supports the ARP assist function
  2053. * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_SET_NO_ENTRIES;
  2054. * thus we say EOPNOTSUPP for this ARP function
  2055. */
  2056. if (card->info.guestlan)
  2057. return -EOPNOTSUPP;
  2058. if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
  2059. return -EOPNOTSUPP;
  2060. }
  2061. rc = qeth_l3_send_simple_setassparms(card, IPA_ARP_PROCESSING,
  2062. IPA_CMD_ASS_ARP_SET_NO_ENTRIES,
  2063. no_entries);
  2064. if (rc) {
  2065. tmp = rc;
  2066. QETH_DBF_MESSAGE(2, "Could not set number of ARP entries on "
  2067. "%s: %s (0x%x/%d)\n", QETH_CARD_IFNAME(card),
  2068. qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
  2069. }
  2070. return rc;
  2071. }
  2072. static __u32 get_arp_entry_size(struct qeth_card *card,
  2073. struct qeth_arp_query_data *qdata,
  2074. struct qeth_arp_entrytype *type, __u8 strip_entries)
  2075. {
  2076. __u32 rc;
  2077. __u8 is_hsi;
  2078. is_hsi = qdata->reply_bits == 5;
  2079. if (type->ip == QETHARP_IP_ADDR_V4) {
  2080. QETH_CARD_TEXT(card, 4, "arpev4");
  2081. if (strip_entries) {
  2082. rc = is_hsi ? sizeof(struct qeth_arp_qi_entry5_short) :
  2083. sizeof(struct qeth_arp_qi_entry7_short);
  2084. } else {
  2085. rc = is_hsi ? sizeof(struct qeth_arp_qi_entry5) :
  2086. sizeof(struct qeth_arp_qi_entry7);
  2087. }
  2088. } else if (type->ip == QETHARP_IP_ADDR_V6) {
  2089. QETH_CARD_TEXT(card, 4, "arpev6");
  2090. if (strip_entries) {
  2091. rc = is_hsi ?
  2092. sizeof(struct qeth_arp_qi_entry5_short_ipv6) :
  2093. sizeof(struct qeth_arp_qi_entry7_short_ipv6);
  2094. } else {
  2095. rc = is_hsi ?
  2096. sizeof(struct qeth_arp_qi_entry5_ipv6) :
  2097. sizeof(struct qeth_arp_qi_entry7_ipv6);
  2098. }
  2099. } else {
  2100. QETH_CARD_TEXT(card, 4, "arpinv");
  2101. rc = 0;
  2102. }
  2103. return rc;
  2104. }
  2105. static int arpentry_matches_prot(struct qeth_arp_entrytype *type, __u16 prot)
  2106. {
  2107. return (type->ip == QETHARP_IP_ADDR_V4 && prot == QETH_PROT_IPV4) ||
  2108. (type->ip == QETHARP_IP_ADDR_V6 && prot == QETH_PROT_IPV6);
  2109. }
  2110. static int qeth_l3_arp_query_cb(struct qeth_card *card,
  2111. struct qeth_reply *reply, unsigned long data)
  2112. {
  2113. struct qeth_ipa_cmd *cmd;
  2114. struct qeth_arp_query_data *qdata;
  2115. struct qeth_arp_query_info *qinfo;
  2116. int i;
  2117. int e;
  2118. int entrybytes_done;
  2119. int stripped_bytes;
  2120. __u8 do_strip_entries;
  2121. QETH_CARD_TEXT(card, 3, "arpquecb");
  2122. qinfo = (struct qeth_arp_query_info *) reply->param;
  2123. cmd = (struct qeth_ipa_cmd *) data;
  2124. QETH_CARD_TEXT_(card, 4, "%i", cmd->hdr.prot_version);
  2125. if (cmd->hdr.return_code) {
  2126. QETH_CARD_TEXT(card, 4, "arpcberr");
  2127. QETH_CARD_TEXT_(card, 4, "%i", cmd->hdr.return_code);
  2128. return 0;
  2129. }
  2130. if (cmd->data.setassparms.hdr.return_code) {
  2131. cmd->hdr.return_code = cmd->data.setassparms.hdr.return_code;
  2132. QETH_CARD_TEXT(card, 4, "setaperr");
  2133. QETH_CARD_TEXT_(card, 4, "%i", cmd->hdr.return_code);
  2134. return 0;
  2135. }
  2136. qdata = &cmd->data.setassparms.data.query_arp;
  2137. QETH_CARD_TEXT_(card, 4, "anoen%i", qdata->no_entries);
  2138. do_strip_entries = (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES) > 0;
  2139. stripped_bytes = do_strip_entries ? QETH_QARP_MEDIASPECIFIC_BYTES : 0;
  2140. entrybytes_done = 0;
  2141. for (e = 0; e < qdata->no_entries; ++e) {
  2142. char *cur_entry;
  2143. __u32 esize;
  2144. struct qeth_arp_entrytype *etype;
  2145. cur_entry = &qdata->data + entrybytes_done;
  2146. etype = &((struct qeth_arp_qi_entry5 *) cur_entry)->type;
  2147. if (!arpentry_matches_prot(etype, cmd->hdr.prot_version)) {
  2148. QETH_CARD_TEXT(card, 4, "pmis");
  2149. QETH_CARD_TEXT_(card, 4, "%i", etype->ip);
  2150. break;
  2151. }
  2152. esize = get_arp_entry_size(card, qdata, etype,
  2153. do_strip_entries);
  2154. QETH_CARD_TEXT_(card, 5, "esz%i", esize);
  2155. if (!esize)
  2156. break;
  2157. if ((qinfo->udata_len - qinfo->udata_offset) < esize) {
  2158. QETH_CARD_TEXT_(card, 4, "qaer3%i", -ENOMEM);
  2159. cmd->hdr.return_code = -ENOMEM;
  2160. goto out_error;
  2161. }
  2162. memcpy(qinfo->udata + qinfo->udata_offset,
  2163. &qdata->data + entrybytes_done + stripped_bytes,
  2164. esize);
  2165. entrybytes_done += esize + stripped_bytes;
  2166. qinfo->udata_offset += esize;
  2167. ++qinfo->no_entries;
  2168. }
  2169. /* check if all replies received ... */
  2170. if (cmd->data.setassparms.hdr.seq_no <
  2171. cmd->data.setassparms.hdr.number_of_replies)
  2172. return 1;
  2173. QETH_CARD_TEXT_(card, 4, "nove%i", qinfo->no_entries);
  2174. memcpy(qinfo->udata, &qinfo->no_entries, 4);
  2175. /* keep STRIP_ENTRIES flag so the user program can distinguish
  2176. * stripped entries from normal ones */
  2177. if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES)
  2178. qdata->reply_bits |= QETH_QARP_STRIP_ENTRIES;
  2179. memcpy(qinfo->udata + QETH_QARP_MASK_OFFSET, &qdata->reply_bits, 2);
  2180. QETH_CARD_TEXT_(card, 4, "rc%i", 0);
  2181. return 0;
  2182. out_error:
  2183. i = 0;
  2184. memcpy(qinfo->udata, &i, 4);
  2185. return 0;
  2186. }
  2187. static int qeth_l3_send_ipa_arp_cmd(struct qeth_card *card,
  2188. struct qeth_cmd_buffer *iob, int len,
  2189. int (*reply_cb)(struct qeth_card *, struct qeth_reply *,
  2190. unsigned long),
  2191. void *reply_param)
  2192. {
  2193. QETH_CARD_TEXT(card, 4, "sendarp");
  2194. memcpy(iob->data, IPA_PDU_HEADER, IPA_PDU_HEADER_SIZE);
  2195. memcpy(QETH_IPA_CMD_DEST_ADDR(iob->data),
  2196. &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
  2197. return qeth_send_control_data(card, IPA_PDU_HEADER_SIZE + len, iob,
  2198. reply_cb, reply_param);
  2199. }
  2200. static int qeth_l3_query_arp_cache_info(struct qeth_card *card,
  2201. enum qeth_prot_versions prot,
  2202. struct qeth_arp_query_info *qinfo)
  2203. {
  2204. struct qeth_cmd_buffer *iob;
  2205. struct qeth_ipa_cmd *cmd;
  2206. int tmp;
  2207. int rc;
  2208. QETH_CARD_TEXT_(card, 3, "qarpipv%i", prot);
  2209. iob = qeth_l3_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
  2210. IPA_CMD_ASS_ARP_QUERY_INFO,
  2211. sizeof(struct qeth_arp_query_data) - sizeof(char),
  2212. prot);
  2213. cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
  2214. cmd->data.setassparms.data.query_arp.request_bits = 0x000F;
  2215. cmd->data.setassparms.data.query_arp.reply_bits = 0;
  2216. cmd->data.setassparms.data.query_arp.no_entries = 0;
  2217. rc = qeth_l3_send_ipa_arp_cmd(card, iob,
  2218. QETH_SETASS_BASE_LEN+QETH_ARP_CMD_LEN,
  2219. qeth_l3_arp_query_cb, (void *)qinfo);
  2220. if (rc) {
  2221. tmp = rc;
  2222. QETH_DBF_MESSAGE(2,
  2223. "Error while querying ARP cache on %s: %s "
  2224. "(0x%x/%d)\n", QETH_CARD_IFNAME(card),
  2225. qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
  2226. }
  2227. return rc;
  2228. }
  2229. static int qeth_l3_arp_query(struct qeth_card *card, char __user *udata)
  2230. {
  2231. struct qeth_arp_query_info qinfo = {0, };
  2232. int rc;
  2233. QETH_CARD_TEXT(card, 3, "arpquery");
  2234. if (!qeth_is_supported(card,/*IPA_QUERY_ARP_ADDR_INFO*/
  2235. IPA_ARP_PROCESSING)) {
  2236. QETH_CARD_TEXT(card, 3, "arpqnsup");
  2237. rc = -EOPNOTSUPP;
  2238. goto out;
  2239. }
  2240. /* get size of userspace buffer and mask_bits -> 6 bytes */
  2241. if (copy_from_user(&qinfo, udata, 6)) {
  2242. rc = -EFAULT;
  2243. goto out;
  2244. }
  2245. qinfo.udata = kzalloc(qinfo.udata_len, GFP_KERNEL);
  2246. if (!qinfo.udata) {
  2247. rc = -ENOMEM;
  2248. goto out;
  2249. }
  2250. qinfo.udata_offset = QETH_QARP_ENTRIES_OFFSET;
  2251. rc = qeth_l3_query_arp_cache_info(card, QETH_PROT_IPV4, &qinfo);
  2252. if (rc) {
  2253. if (copy_to_user(udata, qinfo.udata, 4))
  2254. rc = -EFAULT;
  2255. goto free_and_out;
  2256. } else {
  2257. #ifdef CONFIG_QETH_IPV6
  2258. if (qinfo.mask_bits & QETH_QARP_WITH_IPV6) {
  2259. /* fails in case of GuestLAN QDIO mode */
  2260. qeth_l3_query_arp_cache_info(card, QETH_PROT_IPV6,
  2261. &qinfo);
  2262. }
  2263. #endif
  2264. if (copy_to_user(udata, qinfo.udata, qinfo.udata_len)) {
  2265. QETH_CARD_TEXT(card, 4, "qactf");
  2266. rc = -EFAULT;
  2267. goto free_and_out;
  2268. }
  2269. QETH_CARD_TEXT_(card, 4, "qacts");
  2270. }
  2271. free_and_out:
  2272. kfree(qinfo.udata);
  2273. out:
  2274. return rc;
  2275. }
  2276. static int qeth_l3_arp_add_entry(struct qeth_card *card,
  2277. struct qeth_arp_cache_entry *entry)
  2278. {
  2279. struct qeth_cmd_buffer *iob;
  2280. char buf[16];
  2281. int tmp;
  2282. int rc;
  2283. QETH_CARD_TEXT(card, 3, "arpadent");
  2284. /*
  2285. * currently GuestLAN only supports the ARP assist function
  2286. * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_ADD_ENTRY;
  2287. * thus we say EOPNOTSUPP for this ARP function
  2288. */
  2289. if (card->info.guestlan)
  2290. return -EOPNOTSUPP;
  2291. if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
  2292. return -EOPNOTSUPP;
  2293. }
  2294. iob = qeth_l3_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
  2295. IPA_CMD_ASS_ARP_ADD_ENTRY,
  2296. sizeof(struct qeth_arp_cache_entry),
  2297. QETH_PROT_IPV4);
  2298. rc = qeth_l3_send_setassparms(card, iob,
  2299. sizeof(struct qeth_arp_cache_entry),
  2300. (unsigned long) entry,
  2301. qeth_l3_default_setassparms_cb, NULL);
  2302. if (rc) {
  2303. tmp = rc;
  2304. qeth_l3_ipaddr4_to_string((u8 *)entry->ipaddr, buf);
  2305. QETH_DBF_MESSAGE(2, "Could not add ARP entry for address %s "
  2306. "on %s: %s (0x%x/%d)\n", buf, QETH_CARD_IFNAME(card),
  2307. qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
  2308. }
  2309. return rc;
  2310. }
  2311. static int qeth_l3_arp_remove_entry(struct qeth_card *card,
  2312. struct qeth_arp_cache_entry *entry)
  2313. {
  2314. struct qeth_cmd_buffer *iob;
  2315. char buf[16] = {0, };
  2316. int tmp;
  2317. int rc;
  2318. QETH_CARD_TEXT(card, 3, "arprment");
  2319. /*
  2320. * currently GuestLAN only supports the ARP assist function
  2321. * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_REMOVE_ENTRY;
  2322. * thus we say EOPNOTSUPP for this ARP function
  2323. */
  2324. if (card->info.guestlan)
  2325. return -EOPNOTSUPP;
  2326. if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
  2327. return -EOPNOTSUPP;
  2328. }
  2329. memcpy(buf, entry, 12);
  2330. iob = qeth_l3_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
  2331. IPA_CMD_ASS_ARP_REMOVE_ENTRY,
  2332. 12,
  2333. QETH_PROT_IPV4);
  2334. rc = qeth_l3_send_setassparms(card, iob,
  2335. 12, (unsigned long)buf,
  2336. qeth_l3_default_setassparms_cb, NULL);
  2337. if (rc) {
  2338. tmp = rc;
  2339. memset(buf, 0, 16);
  2340. qeth_l3_ipaddr4_to_string((u8 *)entry->ipaddr, buf);
  2341. QETH_DBF_MESSAGE(2, "Could not delete ARP entry for address %s"
  2342. " on %s: %s (0x%x/%d)\n", buf, QETH_CARD_IFNAME(card),
  2343. qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
  2344. }
  2345. return rc;
  2346. }
  2347. static int qeth_l3_arp_flush_cache(struct qeth_card *card)
  2348. {
  2349. int rc;
  2350. int tmp;
  2351. QETH_CARD_TEXT(card, 3, "arpflush");
  2352. /*
  2353. * currently GuestLAN only supports the ARP assist function
  2354. * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_FLUSH_CACHE;
  2355. * thus we say EOPNOTSUPP for this ARP function
  2356. */
  2357. if (card->info.guestlan || (card->info.type == QETH_CARD_TYPE_IQD))
  2358. return -EOPNOTSUPP;
  2359. if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
  2360. return -EOPNOTSUPP;
  2361. }
  2362. rc = qeth_l3_send_simple_setassparms(card, IPA_ARP_PROCESSING,
  2363. IPA_CMD_ASS_ARP_FLUSH_CACHE, 0);
  2364. if (rc) {
  2365. tmp = rc;
  2366. QETH_DBF_MESSAGE(2, "Could not flush ARP cache on %s: %s "
  2367. "(0x%x/%d)\n", QETH_CARD_IFNAME(card),
  2368. qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
  2369. }
  2370. return rc;
  2371. }
  2372. static int qeth_l3_do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
  2373. {
  2374. struct qeth_card *card = dev->ml_priv;
  2375. struct qeth_arp_cache_entry arp_entry;
  2376. struct mii_ioctl_data *mii_data;
  2377. int rc = 0;
  2378. if (!card)
  2379. return -ENODEV;
  2380. if ((card->state != CARD_STATE_UP) &&
  2381. (card->state != CARD_STATE_SOFTSETUP))
  2382. return -ENODEV;
  2383. switch (cmd) {
  2384. case SIOC_QETH_ARP_SET_NO_ENTRIES:
  2385. if (!capable(CAP_NET_ADMIN)) {
  2386. rc = -EPERM;
  2387. break;
  2388. }
  2389. rc = qeth_l3_arp_set_no_entries(card, rq->ifr_ifru.ifru_ivalue);
  2390. break;
  2391. case SIOC_QETH_ARP_QUERY_INFO:
  2392. if (!capable(CAP_NET_ADMIN)) {
  2393. rc = -EPERM;
  2394. break;
  2395. }
  2396. rc = qeth_l3_arp_query(card, rq->ifr_ifru.ifru_data);
  2397. break;
  2398. case SIOC_QETH_ARP_ADD_ENTRY:
  2399. if (!capable(CAP_NET_ADMIN)) {
  2400. rc = -EPERM;
  2401. break;
  2402. }
  2403. if (copy_from_user(&arp_entry, rq->ifr_ifru.ifru_data,
  2404. sizeof(struct qeth_arp_cache_entry)))
  2405. rc = -EFAULT;
  2406. else
  2407. rc = qeth_l3_arp_add_entry(card, &arp_entry);
  2408. break;
  2409. case SIOC_QETH_ARP_REMOVE_ENTRY:
  2410. if (!capable(CAP_NET_ADMIN)) {
  2411. rc = -EPERM;
  2412. break;
  2413. }
  2414. if (copy_from_user(&arp_entry, rq->ifr_ifru.ifru_data,
  2415. sizeof(struct qeth_arp_cache_entry)))
  2416. rc = -EFAULT;
  2417. else
  2418. rc = qeth_l3_arp_remove_entry(card, &arp_entry);
  2419. break;
  2420. case SIOC_QETH_ARP_FLUSH_CACHE:
  2421. if (!capable(CAP_NET_ADMIN)) {
  2422. rc = -EPERM;
  2423. break;
  2424. }
  2425. rc = qeth_l3_arp_flush_cache(card);
  2426. break;
  2427. case SIOC_QETH_ADP_SET_SNMP_CONTROL:
  2428. rc = qeth_snmp_command(card, rq->ifr_ifru.ifru_data);
  2429. break;
  2430. case SIOC_QETH_GET_CARD_TYPE:
  2431. if ((card->info.type == QETH_CARD_TYPE_OSD ||
  2432. card->info.type == QETH_CARD_TYPE_OSX) &&
  2433. !card->info.guestlan)
  2434. return 1;
  2435. return 0;
  2436. break;
  2437. case SIOCGMIIPHY:
  2438. mii_data = if_mii(rq);
  2439. mii_data->phy_id = 0;
  2440. break;
  2441. case SIOCGMIIREG:
  2442. mii_data = if_mii(rq);
  2443. if (mii_data->phy_id != 0)
  2444. rc = -EINVAL;
  2445. else
  2446. mii_data->val_out = qeth_mdio_read(dev,
  2447. mii_data->phy_id,
  2448. mii_data->reg_num);
  2449. break;
  2450. default:
  2451. rc = -EOPNOTSUPP;
  2452. }
  2453. if (rc)
  2454. QETH_CARD_TEXT_(card, 2, "ioce%d", rc);
  2455. return rc;
  2456. }
  2457. int inline qeth_l3_get_cast_type(struct qeth_card *card, struct sk_buff *skb)
  2458. {
  2459. int cast_type = RTN_UNSPEC;
  2460. struct neighbour *n = NULL;
  2461. struct dst_entry *dst;
  2462. dst = skb_dst(skb);
  2463. if (dst)
  2464. n = dst_get_neighbour(dst);
  2465. if (n) {
  2466. cast_type = n->type;
  2467. if ((cast_type == RTN_BROADCAST) ||
  2468. (cast_type == RTN_MULTICAST) ||
  2469. (cast_type == RTN_ANYCAST))
  2470. return cast_type;
  2471. else
  2472. return RTN_UNSPEC;
  2473. }
  2474. /* try something else */
  2475. if (skb->protocol == ETH_P_IPV6)
  2476. return (skb_network_header(skb)[24] == 0xff) ?
  2477. RTN_MULTICAST : 0;
  2478. else if (skb->protocol == ETH_P_IP)
  2479. return ((skb_network_header(skb)[16] & 0xf0) == 0xe0) ?
  2480. RTN_MULTICAST : 0;
  2481. /* ... */
  2482. if (!memcmp(skb->data, skb->dev->broadcast, 6))
  2483. return RTN_BROADCAST;
  2484. else {
  2485. u16 hdr_mac;
  2486. hdr_mac = *((u16 *)skb->data);
  2487. /* tr multicast? */
  2488. switch (card->info.link_type) {
  2489. case QETH_LINK_TYPE_HSTR:
  2490. case QETH_LINK_TYPE_LANE_TR:
  2491. if ((hdr_mac == QETH_TR_MAC_NC) ||
  2492. (hdr_mac == QETH_TR_MAC_C))
  2493. return RTN_MULTICAST;
  2494. break;
  2495. /* eth or so multicast? */
  2496. default:
  2497. if ((hdr_mac == QETH_ETH_MAC_V4) ||
  2498. (hdr_mac == QETH_ETH_MAC_V6))
  2499. return RTN_MULTICAST;
  2500. }
  2501. }
  2502. return cast_type;
  2503. }
  2504. static void qeth_l3_fill_header(struct qeth_card *card, struct qeth_hdr *hdr,
  2505. struct sk_buff *skb, int ipv, int cast_type)
  2506. {
  2507. struct neighbour *n = NULL;
  2508. struct dst_entry *dst;
  2509. memset(hdr, 0, sizeof(struct qeth_hdr));
  2510. hdr->hdr.l3.id = QETH_HEADER_TYPE_LAYER3;
  2511. hdr->hdr.l3.ext_flags = 0;
  2512. /*
  2513. * before we're going to overwrite this location with next hop ip.
  2514. * v6 uses passthrough, v4 sets the tag in the QDIO header.
  2515. */
  2516. if (card->vlangrp && vlan_tx_tag_present(skb)) {
  2517. if ((ipv == 4) || (card->info.type == QETH_CARD_TYPE_IQD))
  2518. hdr->hdr.l3.ext_flags = QETH_HDR_EXT_VLAN_FRAME;
  2519. else
  2520. hdr->hdr.l3.ext_flags = QETH_HDR_EXT_INCLUDE_VLAN_TAG;
  2521. hdr->hdr.l3.vlan_id = vlan_tx_tag_get(skb);
  2522. }
  2523. hdr->hdr.l3.length = skb->len - sizeof(struct qeth_hdr);
  2524. dst = skb_dst(skb);
  2525. if (dst)
  2526. n = dst_get_neighbour(dst);
  2527. if (ipv == 4) {
  2528. /* IPv4 */
  2529. hdr->hdr.l3.flags = qeth_l3_get_qeth_hdr_flags4(cast_type);
  2530. memset(hdr->hdr.l3.dest_addr, 0, 12);
  2531. if (n) {
  2532. *((u32 *) (&hdr->hdr.l3.dest_addr[12])) =
  2533. *((u32 *) n->primary_key);
  2534. } else {
  2535. /* fill in destination address used in ip header */
  2536. *((u32 *) (&hdr->hdr.l3.dest_addr[12])) =
  2537. ip_hdr(skb)->daddr;
  2538. }
  2539. } else if (ipv == 6) {
  2540. /* IPv6 */
  2541. hdr->hdr.l3.flags = qeth_l3_get_qeth_hdr_flags6(cast_type);
  2542. if (card->info.type == QETH_CARD_TYPE_IQD)
  2543. hdr->hdr.l3.flags &= ~QETH_HDR_PASSTHRU;
  2544. if (n) {
  2545. memcpy(hdr->hdr.l3.dest_addr,
  2546. n->primary_key, 16);
  2547. } else {
  2548. /* fill in destination address used in ip header */
  2549. memcpy(hdr->hdr.l3.dest_addr,
  2550. &ipv6_hdr(skb)->daddr, 16);
  2551. }
  2552. } else {
  2553. /* passthrough */
  2554. if ((skb->dev->type == ARPHRD_IEEE802_TR) &&
  2555. !memcmp(skb->data + sizeof(struct qeth_hdr) +
  2556. sizeof(__u16), skb->dev->broadcast, 6)) {
  2557. hdr->hdr.l3.flags = QETH_CAST_BROADCAST |
  2558. QETH_HDR_PASSTHRU;
  2559. } else if (!memcmp(skb->data + sizeof(struct qeth_hdr),
  2560. skb->dev->broadcast, 6)) {
  2561. /* broadcast? */
  2562. hdr->hdr.l3.flags = QETH_CAST_BROADCAST |
  2563. QETH_HDR_PASSTHRU;
  2564. } else {
  2565. hdr->hdr.l3.flags = (cast_type == RTN_MULTICAST) ?
  2566. QETH_CAST_MULTICAST | QETH_HDR_PASSTHRU :
  2567. QETH_CAST_UNICAST | QETH_HDR_PASSTHRU;
  2568. }
  2569. }
  2570. }
  2571. static inline void qeth_l3_hdr_csum(struct qeth_card *card,
  2572. struct qeth_hdr *hdr, struct sk_buff *skb)
  2573. {
  2574. struct iphdr *iph = ip_hdr(skb);
  2575. /* tcph->check contains already the pseudo hdr checksum
  2576. * so just set the header flags
  2577. */
  2578. if (iph->protocol == IPPROTO_UDP)
  2579. hdr->hdr.l3.ext_flags |= QETH_HDR_EXT_UDP;
  2580. hdr->hdr.l3.ext_flags |= QETH_HDR_EXT_CSUM_TRANSP_REQ |
  2581. QETH_HDR_EXT_CSUM_HDR_REQ;
  2582. iph->check = 0;
  2583. if (card->options.performance_stats)
  2584. card->perf_stats.tx_csum++;
  2585. }
  2586. static void qeth_tso_fill_header(struct qeth_card *card,
  2587. struct qeth_hdr *qhdr, struct sk_buff *skb)
  2588. {
  2589. struct qeth_hdr_tso *hdr = (struct qeth_hdr_tso *)qhdr;
  2590. struct tcphdr *tcph = tcp_hdr(skb);
  2591. struct iphdr *iph = ip_hdr(skb);
  2592. struct ipv6hdr *ip6h = ipv6_hdr(skb);
  2593. /*fix header to TSO values ...*/
  2594. hdr->hdr.hdr.l3.id = QETH_HEADER_TYPE_TSO;
  2595. hdr->hdr.hdr.l3.length = skb->len - sizeof(struct qeth_hdr_tso);
  2596. /*set values which are fix for the first approach ...*/
  2597. hdr->ext.hdr_tot_len = (__u16) sizeof(struct qeth_hdr_ext_tso);
  2598. hdr->ext.imb_hdr_no = 1;
  2599. hdr->ext.hdr_type = 1;
  2600. hdr->ext.hdr_version = 1;
  2601. hdr->ext.hdr_len = 28;
  2602. /*insert non-fix values */
  2603. hdr->ext.mss = skb_shinfo(skb)->gso_size;
  2604. hdr->ext.dg_hdr_len = (__u16)(iph->ihl*4 + tcph->doff*4);
  2605. hdr->ext.payload_len = (__u16)(skb->len - hdr->ext.dg_hdr_len -
  2606. sizeof(struct qeth_hdr_tso));
  2607. tcph->check = 0;
  2608. if (skb->protocol == ETH_P_IPV6) {
  2609. ip6h->payload_len = 0;
  2610. tcph->check = ~csum_ipv6_magic(&ip6h->saddr, &ip6h->daddr,
  2611. 0, IPPROTO_TCP, 0);
  2612. } else {
  2613. /*OSA want us to set these values ...*/
  2614. tcph->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr,
  2615. 0, IPPROTO_TCP, 0);
  2616. iph->tot_len = 0;
  2617. iph->check = 0;
  2618. }
  2619. }
  2620. static inline int qeth_l3_tso_elements(struct sk_buff *skb)
  2621. {
  2622. unsigned long tcpd = (unsigned long)tcp_hdr(skb) +
  2623. tcp_hdr(skb)->doff * 4;
  2624. int tcpd_len = skb->len - (tcpd - (unsigned long)skb->data);
  2625. int elements = PFN_UP(tcpd + tcpd_len - 1) - PFN_DOWN(tcpd);
  2626. elements += skb_shinfo(skb)->nr_frags;
  2627. return elements;
  2628. }
  2629. static int qeth_l3_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
  2630. {
  2631. int rc;
  2632. u16 *tag;
  2633. struct qeth_hdr *hdr = NULL;
  2634. int elements_needed = 0;
  2635. int elems;
  2636. struct qeth_card *card = dev->ml_priv;
  2637. struct sk_buff *new_skb = NULL;
  2638. int ipv = qeth_get_ip_version(skb);
  2639. int cast_type = qeth_l3_get_cast_type(card, skb);
  2640. struct qeth_qdio_out_q *queue = card->qdio.out_qs
  2641. [qeth_get_priority_queue(card, skb, ipv, cast_type)];
  2642. int tx_bytes = skb->len;
  2643. bool large_send;
  2644. int data_offset = -1;
  2645. int nr_frags;
  2646. if (((card->info.type == QETH_CARD_TYPE_IQD) && (!ipv)) ||
  2647. card->options.sniffer)
  2648. goto tx_drop;
  2649. if ((card->state != CARD_STATE_UP) || !card->lan_online) {
  2650. card->stats.tx_carrier_errors++;
  2651. goto tx_drop;
  2652. }
  2653. if ((cast_type == RTN_BROADCAST) &&
  2654. (card->info.broadcast_capable == 0))
  2655. goto tx_drop;
  2656. if (card->options.performance_stats) {
  2657. card->perf_stats.outbound_cnt++;
  2658. card->perf_stats.outbound_start_time = qeth_get_micros();
  2659. }
  2660. large_send = skb_is_gso(skb);
  2661. if ((card->info.type == QETH_CARD_TYPE_IQD) && (!large_send) &&
  2662. (skb_shinfo(skb)->nr_frags == 0)) {
  2663. new_skb = skb;
  2664. data_offset = ETH_HLEN;
  2665. hdr = kmem_cache_alloc(qeth_core_header_cache, GFP_ATOMIC);
  2666. if (!hdr)
  2667. goto tx_drop;
  2668. elements_needed++;
  2669. } else {
  2670. /* create a clone with writeable headroom */
  2671. new_skb = skb_realloc_headroom(skb, sizeof(struct qeth_hdr_tso)
  2672. + VLAN_HLEN);
  2673. if (!new_skb)
  2674. goto tx_drop;
  2675. }
  2676. if (card->info.type == QETH_CARD_TYPE_IQD) {
  2677. if (data_offset < 0)
  2678. skb_pull(new_skb, ETH_HLEN);
  2679. } else {
  2680. if (ipv == 4) {
  2681. if (card->dev->type == ARPHRD_IEEE802_TR)
  2682. skb_pull(new_skb, TR_HLEN);
  2683. else
  2684. skb_pull(new_skb, ETH_HLEN);
  2685. }
  2686. if (ipv != 4 && card->vlangrp &&
  2687. vlan_tx_tag_present(new_skb)) {
  2688. skb_push(new_skb, VLAN_HLEN);
  2689. skb_copy_to_linear_data(new_skb, new_skb->data + 4, 4);
  2690. skb_copy_to_linear_data_offset(new_skb, 4,
  2691. new_skb->data + 8, 4);
  2692. skb_copy_to_linear_data_offset(new_skb, 8,
  2693. new_skb->data + 12, 4);
  2694. tag = (u16 *)(new_skb->data + 12);
  2695. *tag = __constant_htons(ETH_P_8021Q);
  2696. *(tag + 1) = htons(vlan_tx_tag_get(new_skb));
  2697. new_skb->vlan_tci = 0;
  2698. }
  2699. }
  2700. netif_stop_queue(dev);
  2701. /* fix hardware limitation: as long as we do not have sbal
  2702. * chaining we can not send long frag lists
  2703. */
  2704. if (large_send) {
  2705. if (qeth_l3_tso_elements(new_skb) + 1 > 16) {
  2706. if (skb_linearize(new_skb))
  2707. goto tx_drop;
  2708. if (card->options.performance_stats)
  2709. card->perf_stats.tx_lin++;
  2710. }
  2711. }
  2712. if (large_send && (cast_type == RTN_UNSPEC)) {
  2713. hdr = (struct qeth_hdr *)skb_push(new_skb,
  2714. sizeof(struct qeth_hdr_tso));
  2715. memset(hdr, 0, sizeof(struct qeth_hdr_tso));
  2716. qeth_l3_fill_header(card, hdr, new_skb, ipv, cast_type);
  2717. qeth_tso_fill_header(card, hdr, new_skb);
  2718. elements_needed++;
  2719. } else {
  2720. if (data_offset < 0) {
  2721. hdr = (struct qeth_hdr *)skb_push(new_skb,
  2722. sizeof(struct qeth_hdr));
  2723. qeth_l3_fill_header(card, hdr, new_skb, ipv,
  2724. cast_type);
  2725. } else {
  2726. qeth_l3_fill_header(card, hdr, new_skb, ipv,
  2727. cast_type);
  2728. hdr->hdr.l3.length = new_skb->len - data_offset;
  2729. }
  2730. if (skb->ip_summed == CHECKSUM_PARTIAL)
  2731. qeth_l3_hdr_csum(card, hdr, new_skb);
  2732. }
  2733. elems = qeth_get_elements_no(card, (void *)hdr, new_skb,
  2734. elements_needed);
  2735. if (!elems) {
  2736. if (data_offset >= 0)
  2737. kmem_cache_free(qeth_core_header_cache, hdr);
  2738. goto tx_drop;
  2739. }
  2740. elements_needed += elems;
  2741. nr_frags = skb_shinfo(new_skb)->nr_frags;
  2742. if (card->info.type != QETH_CARD_TYPE_IQD) {
  2743. int len;
  2744. if (large_send)
  2745. len = ((unsigned long)tcp_hdr(new_skb) +
  2746. tcp_hdr(new_skb)->doff * 4) -
  2747. (unsigned long)new_skb->data;
  2748. else
  2749. len = sizeof(struct qeth_hdr_layer3);
  2750. if (qeth_hdr_chk_and_bounce(new_skb, len))
  2751. goto tx_drop;
  2752. rc = qeth_do_send_packet(card, queue, new_skb, hdr,
  2753. elements_needed);
  2754. } else
  2755. rc = qeth_do_send_packet_fast(card, queue, new_skb, hdr,
  2756. elements_needed, data_offset, 0);
  2757. if (!rc) {
  2758. card->stats.tx_packets++;
  2759. card->stats.tx_bytes += tx_bytes;
  2760. if (new_skb != skb)
  2761. dev_kfree_skb_any(skb);
  2762. if (card->options.performance_stats) {
  2763. if (large_send) {
  2764. card->perf_stats.large_send_bytes += tx_bytes;
  2765. card->perf_stats.large_send_cnt++;
  2766. }
  2767. if (nr_frags) {
  2768. card->perf_stats.sg_skbs_sent++;
  2769. /* nr_frags + skb->data */
  2770. card->perf_stats.sg_frags_sent += nr_frags + 1;
  2771. }
  2772. }
  2773. rc = NETDEV_TX_OK;
  2774. } else {
  2775. if (data_offset >= 0)
  2776. kmem_cache_free(qeth_core_header_cache, hdr);
  2777. if (rc == -EBUSY) {
  2778. if (new_skb != skb)
  2779. dev_kfree_skb_any(new_skb);
  2780. return NETDEV_TX_BUSY;
  2781. } else
  2782. goto tx_drop;
  2783. }
  2784. netif_wake_queue(dev);
  2785. if (card->options.performance_stats)
  2786. card->perf_stats.outbound_time += qeth_get_micros() -
  2787. card->perf_stats.outbound_start_time;
  2788. return rc;
  2789. tx_drop:
  2790. card->stats.tx_dropped++;
  2791. card->stats.tx_errors++;
  2792. if ((new_skb != skb) && new_skb)
  2793. dev_kfree_skb_any(new_skb);
  2794. dev_kfree_skb_any(skb);
  2795. netif_wake_queue(dev);
  2796. return NETDEV_TX_OK;
  2797. }
  2798. static int __qeth_l3_open(struct net_device *dev)
  2799. {
  2800. struct qeth_card *card = dev->ml_priv;
  2801. int rc = 0;
  2802. QETH_CARD_TEXT(card, 4, "qethopen");
  2803. if (card->state == CARD_STATE_UP)
  2804. return rc;
  2805. if (card->state != CARD_STATE_SOFTSETUP)
  2806. return -ENODEV;
  2807. card->data.state = CH_STATE_UP;
  2808. card->state = CARD_STATE_UP;
  2809. netif_start_queue(dev);
  2810. if (qdio_stop_irq(card->data.ccwdev, 0) >= 0) {
  2811. napi_enable(&card->napi);
  2812. napi_schedule(&card->napi);
  2813. } else
  2814. rc = -EIO;
  2815. return rc;
  2816. }
  2817. static int qeth_l3_open(struct net_device *dev)
  2818. {
  2819. struct qeth_card *card = dev->ml_priv;
  2820. QETH_CARD_TEXT(card, 5, "qethope_");
  2821. if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
  2822. QETH_CARD_TEXT(card, 3, "openREC");
  2823. return -ERESTARTSYS;
  2824. }
  2825. return __qeth_l3_open(dev);
  2826. }
  2827. static int qeth_l3_stop(struct net_device *dev)
  2828. {
  2829. struct qeth_card *card = dev->ml_priv;
  2830. QETH_CARD_TEXT(card, 4, "qethstop");
  2831. netif_tx_disable(dev);
  2832. if (card->state == CARD_STATE_UP) {
  2833. card->state = CARD_STATE_SOFTSETUP;
  2834. napi_disable(&card->napi);
  2835. }
  2836. return 0;
  2837. }
  2838. static u32 qeth_l3_fix_features(struct net_device *dev, u32 features)
  2839. {
  2840. struct qeth_card *card = dev->ml_priv;
  2841. if (!qeth_is_supported(card, IPA_OUTBOUND_CHECKSUM))
  2842. features &= ~NETIF_F_IP_CSUM;
  2843. if (!qeth_is_supported(card, IPA_OUTBOUND_TSO))
  2844. features &= ~NETIF_F_TSO;
  2845. if (!qeth_is_supported(card, IPA_INBOUND_CHECKSUM))
  2846. features &= ~NETIF_F_RXCSUM;
  2847. return features;
  2848. }
  2849. static int qeth_l3_set_features(struct net_device *dev, u32 features)
  2850. {
  2851. struct qeth_card *card = dev->ml_priv;
  2852. u32 changed = dev->features ^ features;
  2853. int err;
  2854. if (!(changed & NETIF_F_RXCSUM))
  2855. return 0;
  2856. if (card->state == CARD_STATE_DOWN ||
  2857. card->state == CARD_STATE_RECOVER)
  2858. return 0;
  2859. err = qeth_l3_set_rx_csum(card, features & NETIF_F_RXCSUM);
  2860. if (err)
  2861. dev->features = features ^ NETIF_F_RXCSUM;
  2862. return err;
  2863. }
  2864. static const struct ethtool_ops qeth_l3_ethtool_ops = {
  2865. .get_link = ethtool_op_get_link,
  2866. .get_strings = qeth_core_get_strings,
  2867. .get_ethtool_stats = qeth_core_get_ethtool_stats,
  2868. .get_sset_count = qeth_core_get_sset_count,
  2869. .get_drvinfo = qeth_core_get_drvinfo,
  2870. .get_settings = qeth_core_ethtool_get_settings,
  2871. };
  2872. /*
  2873. * we need NOARP for IPv4 but we want neighbor solicitation for IPv6. Setting
  2874. * NOARP on the netdevice is no option because it also turns off neighbor
  2875. * solicitation. For IPv4 we install a neighbor_setup function. We don't want
  2876. * arp resolution but we want the hard header (packet socket will work
  2877. * e.g. tcpdump)
  2878. */
  2879. static int qeth_l3_neigh_setup_noarp(struct neighbour *n)
  2880. {
  2881. n->nud_state = NUD_NOARP;
  2882. memcpy(n->ha, "FAKELL", 6);
  2883. n->output = n->ops->connected_output;
  2884. return 0;
  2885. }
  2886. static int
  2887. qeth_l3_neigh_setup(struct net_device *dev, struct neigh_parms *np)
  2888. {
  2889. if (np->tbl->family == AF_INET)
  2890. np->neigh_setup = qeth_l3_neigh_setup_noarp;
  2891. return 0;
  2892. }
  2893. static const struct net_device_ops qeth_l3_netdev_ops = {
  2894. .ndo_open = qeth_l3_open,
  2895. .ndo_stop = qeth_l3_stop,
  2896. .ndo_get_stats = qeth_get_stats,
  2897. .ndo_start_xmit = qeth_l3_hard_start_xmit,
  2898. .ndo_validate_addr = eth_validate_addr,
  2899. .ndo_set_multicast_list = qeth_l3_set_multicast_list,
  2900. .ndo_do_ioctl = qeth_l3_do_ioctl,
  2901. .ndo_change_mtu = qeth_change_mtu,
  2902. .ndo_fix_features = qeth_l3_fix_features,
  2903. .ndo_set_features = qeth_l3_set_features,
  2904. .ndo_vlan_rx_register = qeth_l3_vlan_rx_register,
  2905. .ndo_vlan_rx_add_vid = qeth_l3_vlan_rx_add_vid,
  2906. .ndo_vlan_rx_kill_vid = qeth_l3_vlan_rx_kill_vid,
  2907. .ndo_tx_timeout = qeth_tx_timeout,
  2908. };
  2909. static const struct net_device_ops qeth_l3_osa_netdev_ops = {
  2910. .ndo_open = qeth_l3_open,
  2911. .ndo_stop = qeth_l3_stop,
  2912. .ndo_get_stats = qeth_get_stats,
  2913. .ndo_start_xmit = qeth_l3_hard_start_xmit,
  2914. .ndo_validate_addr = eth_validate_addr,
  2915. .ndo_set_multicast_list = qeth_l3_set_multicast_list,
  2916. .ndo_do_ioctl = qeth_l3_do_ioctl,
  2917. .ndo_change_mtu = qeth_change_mtu,
  2918. .ndo_fix_features = qeth_l3_fix_features,
  2919. .ndo_set_features = qeth_l3_set_features,
  2920. .ndo_vlan_rx_register = qeth_l3_vlan_rx_register,
  2921. .ndo_vlan_rx_add_vid = qeth_l3_vlan_rx_add_vid,
  2922. .ndo_vlan_rx_kill_vid = qeth_l3_vlan_rx_kill_vid,
  2923. .ndo_tx_timeout = qeth_tx_timeout,
  2924. .ndo_neigh_setup = qeth_l3_neigh_setup,
  2925. };
  2926. static int qeth_l3_setup_netdev(struct qeth_card *card)
  2927. {
  2928. if (card->info.type == QETH_CARD_TYPE_OSD ||
  2929. card->info.type == QETH_CARD_TYPE_OSX) {
  2930. if ((card->info.link_type == QETH_LINK_TYPE_LANE_TR) ||
  2931. (card->info.link_type == QETH_LINK_TYPE_HSTR)) {
  2932. #ifdef CONFIG_TR
  2933. card->dev = alloc_trdev(0);
  2934. #endif
  2935. if (!card->dev)
  2936. return -ENODEV;
  2937. card->dev->netdev_ops = &qeth_l3_netdev_ops;
  2938. } else {
  2939. card->dev = alloc_etherdev(0);
  2940. if (!card->dev)
  2941. return -ENODEV;
  2942. card->dev->netdev_ops = &qeth_l3_osa_netdev_ops;
  2943. /*IPv6 address autoconfiguration stuff*/
  2944. qeth_l3_get_unique_id(card);
  2945. if (!(card->info.unique_id & UNIQUE_ID_NOT_BY_CARD))
  2946. card->dev->dev_id = card->info.unique_id &
  2947. 0xffff;
  2948. if (!card->info.guestlan) {
  2949. card->dev->hw_features = NETIF_F_SG |
  2950. NETIF_F_RXCSUM | NETIF_F_IP_CSUM |
  2951. NETIF_F_TSO;
  2952. card->dev->features = NETIF_F_RXCSUM;
  2953. }
  2954. }
  2955. } else if (card->info.type == QETH_CARD_TYPE_IQD) {
  2956. card->dev = alloc_netdev(0, "hsi%d", ether_setup);
  2957. if (!card->dev)
  2958. return -ENODEV;
  2959. card->dev->flags |= IFF_NOARP;
  2960. card->dev->netdev_ops = &qeth_l3_netdev_ops;
  2961. qeth_l3_iqd_read_initial_mac(card);
  2962. } else
  2963. return -ENODEV;
  2964. card->dev->ml_priv = card;
  2965. card->dev->watchdog_timeo = QETH_TX_TIMEOUT;
  2966. card->dev->mtu = card->info.initial_mtu;
  2967. SET_ETHTOOL_OPS(card->dev, &qeth_l3_ethtool_ops);
  2968. card->dev->features |= NETIF_F_HW_VLAN_TX |
  2969. NETIF_F_HW_VLAN_RX |
  2970. NETIF_F_HW_VLAN_FILTER;
  2971. card->dev->priv_flags &= ~IFF_XMIT_DST_RELEASE;
  2972. card->dev->gso_max_size = 15 * PAGE_SIZE;
  2973. SET_NETDEV_DEV(card->dev, &card->gdev->dev);
  2974. netif_napi_add(card->dev, &card->napi, qeth_l3_poll, QETH_NAPI_WEIGHT);
  2975. return register_netdev(card->dev);
  2976. }
  2977. static int qeth_l3_probe_device(struct ccwgroup_device *gdev)
  2978. {
  2979. struct qeth_card *card = dev_get_drvdata(&gdev->dev);
  2980. qeth_l3_create_device_attributes(&gdev->dev);
  2981. card->options.layer2 = 0;
  2982. card->info.hwtrap = 0;
  2983. card->discipline.start_poll = qeth_qdio_start_poll;
  2984. card->discipline.input_handler = (qdio_handler_t *)
  2985. qeth_qdio_input_handler;
  2986. card->discipline.output_handler = (qdio_handler_t *)
  2987. qeth_qdio_output_handler;
  2988. card->discipline.recover = qeth_l3_recover;
  2989. return 0;
  2990. }
  2991. static void qeth_l3_remove_device(struct ccwgroup_device *cgdev)
  2992. {
  2993. struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
  2994. qeth_l3_remove_device_attributes(&cgdev->dev);
  2995. qeth_set_allowed_threads(card, 0, 1);
  2996. wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
  2997. if (cgdev->state == CCWGROUP_ONLINE)
  2998. qeth_l3_set_offline(cgdev);
  2999. if (card->dev) {
  3000. unregister_netdev(card->dev);
  3001. card->dev = NULL;
  3002. }
  3003. qeth_l3_clear_ip_list(card, 0);
  3004. qeth_l3_clear_ipato_list(card);
  3005. return;
  3006. }
  3007. static int __qeth_l3_set_online(struct ccwgroup_device *gdev, int recovery_mode)
  3008. {
  3009. struct qeth_card *card = dev_get_drvdata(&gdev->dev);
  3010. int rc = 0;
  3011. enum qeth_card_states recover_flag;
  3012. BUG_ON(!card);
  3013. mutex_lock(&card->discipline_mutex);
  3014. mutex_lock(&card->conf_mutex);
  3015. QETH_DBF_TEXT(SETUP, 2, "setonlin");
  3016. QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
  3017. recover_flag = card->state;
  3018. rc = qeth_core_hardsetup_card(card);
  3019. if (rc) {
  3020. QETH_DBF_TEXT_(SETUP, 2, "2err%d", rc);
  3021. rc = -ENODEV;
  3022. goto out_remove;
  3023. }
  3024. if (!card->dev && qeth_l3_setup_netdev(card)) {
  3025. rc = -ENODEV;
  3026. goto out_remove;
  3027. }
  3028. if (qeth_is_diagass_supported(card, QETH_DIAGS_CMD_TRAP)) {
  3029. if (card->info.hwtrap &&
  3030. qeth_hw_trap(card, QETH_DIAGS_TRAP_ARM))
  3031. card->info.hwtrap = 0;
  3032. } else
  3033. card->info.hwtrap = 0;
  3034. card->state = CARD_STATE_HARDSETUP;
  3035. memset(&card->rx, 0, sizeof(struct qeth_rx));
  3036. qeth_print_status_message(card);
  3037. /* softsetup */
  3038. QETH_DBF_TEXT(SETUP, 2, "softsetp");
  3039. rc = qeth_send_startlan(card);
  3040. if (rc) {
  3041. QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
  3042. if (rc == 0xe080) {
  3043. dev_warn(&card->gdev->dev,
  3044. "The LAN is offline\n");
  3045. card->lan_online = 0;
  3046. goto contin;
  3047. }
  3048. rc = -ENODEV;
  3049. goto out_remove;
  3050. } else
  3051. card->lan_online = 1;
  3052. contin:
  3053. rc = qeth_l3_setadapter_parms(card);
  3054. if (rc)
  3055. QETH_DBF_TEXT_(SETUP, 2, "2err%d", rc);
  3056. if (!card->options.sniffer) {
  3057. rc = qeth_l3_start_ipassists(card);
  3058. if (rc)
  3059. QETH_DBF_TEXT_(SETUP, 2, "3err%d", rc);
  3060. rc = qeth_l3_setrouting_v4(card);
  3061. if (rc)
  3062. QETH_DBF_TEXT_(SETUP, 2, "4err%d", rc);
  3063. rc = qeth_l3_setrouting_v6(card);
  3064. if (rc)
  3065. QETH_DBF_TEXT_(SETUP, 2, "5err%d", rc);
  3066. }
  3067. netif_tx_disable(card->dev);
  3068. rc = qeth_init_qdio_queues(card);
  3069. if (rc) {
  3070. QETH_DBF_TEXT_(SETUP, 2, "6err%d", rc);
  3071. rc = -ENODEV;
  3072. goto out_remove;
  3073. }
  3074. card->state = CARD_STATE_SOFTSETUP;
  3075. qeth_set_allowed_threads(card, 0xffffffff, 0);
  3076. qeth_l3_set_ip_addr_list(card);
  3077. if (card->lan_online)
  3078. netif_carrier_on(card->dev);
  3079. else
  3080. netif_carrier_off(card->dev);
  3081. if (recover_flag == CARD_STATE_RECOVER) {
  3082. if (recovery_mode)
  3083. __qeth_l3_open(card->dev);
  3084. else {
  3085. rtnl_lock();
  3086. dev_open(card->dev);
  3087. rtnl_unlock();
  3088. }
  3089. qeth_l3_set_multicast_list(card->dev);
  3090. }
  3091. /* let user_space know that device is online */
  3092. kobject_uevent(&gdev->dev.kobj, KOBJ_CHANGE);
  3093. mutex_unlock(&card->conf_mutex);
  3094. mutex_unlock(&card->discipline_mutex);
  3095. return 0;
  3096. out_remove:
  3097. qeth_l3_stop_card(card, 0);
  3098. ccw_device_set_offline(CARD_DDEV(card));
  3099. ccw_device_set_offline(CARD_WDEV(card));
  3100. ccw_device_set_offline(CARD_RDEV(card));
  3101. if (recover_flag == CARD_STATE_RECOVER)
  3102. card->state = CARD_STATE_RECOVER;
  3103. else
  3104. card->state = CARD_STATE_DOWN;
  3105. mutex_unlock(&card->conf_mutex);
  3106. mutex_unlock(&card->discipline_mutex);
  3107. return rc;
  3108. }
  3109. static int qeth_l3_set_online(struct ccwgroup_device *gdev)
  3110. {
  3111. return __qeth_l3_set_online(gdev, 0);
  3112. }
  3113. static int __qeth_l3_set_offline(struct ccwgroup_device *cgdev,
  3114. int recovery_mode)
  3115. {
  3116. struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
  3117. int rc = 0, rc2 = 0, rc3 = 0;
  3118. enum qeth_card_states recover_flag;
  3119. mutex_lock(&card->discipline_mutex);
  3120. mutex_lock(&card->conf_mutex);
  3121. QETH_DBF_TEXT(SETUP, 3, "setoffl");
  3122. QETH_DBF_HEX(SETUP, 3, &card, sizeof(void *));
  3123. if (card->dev && netif_carrier_ok(card->dev))
  3124. netif_carrier_off(card->dev);
  3125. recover_flag = card->state;
  3126. if ((!recovery_mode && card->info.hwtrap) || card->info.hwtrap == 2) {
  3127. qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
  3128. card->info.hwtrap = 1;
  3129. }
  3130. qeth_l3_stop_card(card, recovery_mode);
  3131. rc = ccw_device_set_offline(CARD_DDEV(card));
  3132. rc2 = ccw_device_set_offline(CARD_WDEV(card));
  3133. rc3 = ccw_device_set_offline(CARD_RDEV(card));
  3134. if (!rc)
  3135. rc = (rc2) ? rc2 : rc3;
  3136. if (rc)
  3137. QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
  3138. if (recover_flag == CARD_STATE_UP)
  3139. card->state = CARD_STATE_RECOVER;
  3140. /* let user_space know that device is offline */
  3141. kobject_uevent(&cgdev->dev.kobj, KOBJ_CHANGE);
  3142. mutex_unlock(&card->conf_mutex);
  3143. mutex_unlock(&card->discipline_mutex);
  3144. return 0;
  3145. }
  3146. static int qeth_l3_set_offline(struct ccwgroup_device *cgdev)
  3147. {
  3148. return __qeth_l3_set_offline(cgdev, 0);
  3149. }
  3150. static int qeth_l3_recover(void *ptr)
  3151. {
  3152. struct qeth_card *card;
  3153. int rc = 0;
  3154. card = (struct qeth_card *) ptr;
  3155. QETH_CARD_TEXT(card, 2, "recover1");
  3156. QETH_CARD_HEX(card, 2, &card, sizeof(void *));
  3157. if (!qeth_do_run_thread(card, QETH_RECOVER_THREAD))
  3158. return 0;
  3159. QETH_CARD_TEXT(card, 2, "recover2");
  3160. dev_warn(&card->gdev->dev,
  3161. "A recovery process has been started for the device\n");
  3162. __qeth_l3_set_offline(card->gdev, 1);
  3163. rc = __qeth_l3_set_online(card->gdev, 1);
  3164. if (!rc)
  3165. dev_info(&card->gdev->dev,
  3166. "Device successfully recovered!\n");
  3167. else {
  3168. rtnl_lock();
  3169. dev_close(card->dev);
  3170. rtnl_unlock();
  3171. dev_warn(&card->gdev->dev, "The qeth device driver "
  3172. "failed to recover an error on the device\n");
  3173. }
  3174. qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD);
  3175. qeth_clear_thread_running_bit(card, QETH_RECOVER_THREAD);
  3176. return 0;
  3177. }
  3178. static void qeth_l3_shutdown(struct ccwgroup_device *gdev)
  3179. {
  3180. struct qeth_card *card = dev_get_drvdata(&gdev->dev);
  3181. if ((gdev->state == CCWGROUP_ONLINE) && card->info.hwtrap)
  3182. qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
  3183. qeth_qdio_clear_card(card, 0);
  3184. qeth_clear_qdio_buffers(card);
  3185. }
  3186. static int qeth_l3_pm_suspend(struct ccwgroup_device *gdev)
  3187. {
  3188. struct qeth_card *card = dev_get_drvdata(&gdev->dev);
  3189. if (card->dev)
  3190. netif_device_detach(card->dev);
  3191. qeth_set_allowed_threads(card, 0, 1);
  3192. wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
  3193. if (gdev->state == CCWGROUP_OFFLINE)
  3194. return 0;
  3195. if (card->state == CARD_STATE_UP) {
  3196. if (card->info.hwtrap)
  3197. qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
  3198. __qeth_l3_set_offline(card->gdev, 1);
  3199. } else
  3200. __qeth_l3_set_offline(card->gdev, 0);
  3201. return 0;
  3202. }
  3203. static int qeth_l3_pm_resume(struct ccwgroup_device *gdev)
  3204. {
  3205. struct qeth_card *card = dev_get_drvdata(&gdev->dev);
  3206. int rc = 0;
  3207. if (gdev->state == CCWGROUP_OFFLINE)
  3208. goto out;
  3209. if (card->state == CARD_STATE_RECOVER) {
  3210. rc = __qeth_l3_set_online(card->gdev, 1);
  3211. if (rc) {
  3212. rtnl_lock();
  3213. dev_close(card->dev);
  3214. rtnl_unlock();
  3215. }
  3216. } else
  3217. rc = __qeth_l3_set_online(card->gdev, 0);
  3218. out:
  3219. qeth_set_allowed_threads(card, 0xffffffff, 0);
  3220. if (card->dev)
  3221. netif_device_attach(card->dev);
  3222. if (rc)
  3223. dev_warn(&card->gdev->dev, "The qeth device driver "
  3224. "failed to recover an error on the device\n");
  3225. return rc;
  3226. }
  3227. struct ccwgroup_driver qeth_l3_ccwgroup_driver = {
  3228. .probe = qeth_l3_probe_device,
  3229. .remove = qeth_l3_remove_device,
  3230. .set_online = qeth_l3_set_online,
  3231. .set_offline = qeth_l3_set_offline,
  3232. .shutdown = qeth_l3_shutdown,
  3233. .freeze = qeth_l3_pm_suspend,
  3234. .thaw = qeth_l3_pm_resume,
  3235. .restore = qeth_l3_pm_resume,
  3236. };
  3237. EXPORT_SYMBOL_GPL(qeth_l3_ccwgroup_driver);
  3238. static int qeth_l3_ip_event(struct notifier_block *this,
  3239. unsigned long event, void *ptr)
  3240. {
  3241. struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;
  3242. struct net_device *dev = (struct net_device *)ifa->ifa_dev->dev;
  3243. struct qeth_ipaddr *addr;
  3244. struct qeth_card *card;
  3245. if (dev_net(dev) != &init_net)
  3246. return NOTIFY_DONE;
  3247. card = qeth_l3_get_card_from_dev(dev);
  3248. QETH_CARD_TEXT(card, 3, "ipevent");
  3249. if (!card)
  3250. return NOTIFY_DONE;
  3251. addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
  3252. if (addr != NULL) {
  3253. addr->u.a4.addr = ifa->ifa_address;
  3254. addr->u.a4.mask = ifa->ifa_mask;
  3255. addr->type = QETH_IP_TYPE_NORMAL;
  3256. } else
  3257. goto out;
  3258. switch (event) {
  3259. case NETDEV_UP:
  3260. if (!qeth_l3_add_ip(card, addr))
  3261. kfree(addr);
  3262. break;
  3263. case NETDEV_DOWN:
  3264. if (!qeth_l3_delete_ip(card, addr))
  3265. kfree(addr);
  3266. break;
  3267. default:
  3268. break;
  3269. }
  3270. qeth_l3_set_ip_addr_list(card);
  3271. out:
  3272. return NOTIFY_DONE;
  3273. }
  3274. static struct notifier_block qeth_l3_ip_notifier = {
  3275. qeth_l3_ip_event,
  3276. NULL,
  3277. };
  3278. #ifdef CONFIG_QETH_IPV6
  3279. /**
  3280. * IPv6 event handler
  3281. */
  3282. static int qeth_l3_ip6_event(struct notifier_block *this,
  3283. unsigned long event, void *ptr)
  3284. {
  3285. struct inet6_ifaddr *ifa = (struct inet6_ifaddr *)ptr;
  3286. struct net_device *dev = (struct net_device *)ifa->idev->dev;
  3287. struct qeth_ipaddr *addr;
  3288. struct qeth_card *card;
  3289. card = qeth_l3_get_card_from_dev(dev);
  3290. if (!card)
  3291. return NOTIFY_DONE;
  3292. QETH_CARD_TEXT(card, 3, "ip6event");
  3293. if (!qeth_is_supported(card, IPA_IPV6))
  3294. return NOTIFY_DONE;
  3295. addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
  3296. if (addr != NULL) {
  3297. memcpy(&addr->u.a6.addr, &ifa->addr, sizeof(struct in6_addr));
  3298. addr->u.a6.pfxlen = ifa->prefix_len;
  3299. addr->type = QETH_IP_TYPE_NORMAL;
  3300. } else
  3301. goto out;
  3302. switch (event) {
  3303. case NETDEV_UP:
  3304. if (!qeth_l3_add_ip(card, addr))
  3305. kfree(addr);
  3306. break;
  3307. case NETDEV_DOWN:
  3308. if (!qeth_l3_delete_ip(card, addr))
  3309. kfree(addr);
  3310. break;
  3311. default:
  3312. break;
  3313. }
  3314. qeth_l3_set_ip_addr_list(card);
  3315. out:
  3316. return NOTIFY_DONE;
  3317. }
  3318. static struct notifier_block qeth_l3_ip6_notifier = {
  3319. qeth_l3_ip6_event,
  3320. NULL,
  3321. };
  3322. #endif
  3323. static int qeth_l3_register_notifiers(void)
  3324. {
  3325. int rc;
  3326. QETH_DBF_TEXT(SETUP, 5, "regnotif");
  3327. rc = register_inetaddr_notifier(&qeth_l3_ip_notifier);
  3328. if (rc)
  3329. return rc;
  3330. #ifdef CONFIG_QETH_IPV6
  3331. rc = register_inet6addr_notifier(&qeth_l3_ip6_notifier);
  3332. if (rc) {
  3333. unregister_inetaddr_notifier(&qeth_l3_ip_notifier);
  3334. return rc;
  3335. }
  3336. #else
  3337. pr_warning("There is no IPv6 support for the layer 3 discipline\n");
  3338. #endif
  3339. return 0;
  3340. }
  3341. static void qeth_l3_unregister_notifiers(void)
  3342. {
  3343. QETH_DBF_TEXT(SETUP, 5, "unregnot");
  3344. BUG_ON(unregister_inetaddr_notifier(&qeth_l3_ip_notifier));
  3345. #ifdef CONFIG_QETH_IPV6
  3346. BUG_ON(unregister_inet6addr_notifier(&qeth_l3_ip6_notifier));
  3347. #endif /* QETH_IPV6 */
  3348. }
  3349. static int __init qeth_l3_init(void)
  3350. {
  3351. int rc = 0;
  3352. pr_info("register layer 3 discipline\n");
  3353. rc = qeth_l3_register_notifiers();
  3354. return rc;
  3355. }
  3356. static void __exit qeth_l3_exit(void)
  3357. {
  3358. qeth_l3_unregister_notifiers();
  3359. pr_info("unregister layer 3 discipline\n");
  3360. }
  3361. module_init(qeth_l3_init);
  3362. module_exit(qeth_l3_exit);
  3363. MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
  3364. MODULE_DESCRIPTION("qeth layer 3 discipline");
  3365. MODULE_LICENSE("GPL");