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