qeth: delay feature trace
[linux/fpc-iii.git] / drivers / s390 / net / qeth_l3_main.c
blob4eb7ea3fc1c30bf2cb8dd55109c07fdc3ae9952d
1 /*
2 * Copyright IBM Corp. 2007, 2009
3 * Author(s): Utz Bacher <utz.bacher@de.ibm.com>,
4 * Frank Pavlic <fpavlic@de.ibm.com>,
5 * Thomas Spatzier <tspat@de.ibm.com>,
6 * Frank Blaschka <frank.blaschka@de.ibm.com>
7 */
9 #define KMSG_COMPONENT "qeth"
10 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
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>
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>
34 #include "qeth_l3.h"
37 static int qeth_l3_set_offline(struct ccwgroup_device *);
38 static int qeth_l3_recover(void *);
39 static int qeth_l3_stop(struct net_device *);
40 static void qeth_l3_set_multicast_list(struct net_device *);
41 static int qeth_l3_neigh_setup(struct net_device *, struct neigh_parms *);
42 static int qeth_l3_register_addr_entry(struct qeth_card *,
43 struct qeth_ipaddr *);
44 static int qeth_l3_deregister_addr_entry(struct qeth_card *,
45 struct qeth_ipaddr *);
46 static int __qeth_l3_set_online(struct ccwgroup_device *, int);
47 static int __qeth_l3_set_offline(struct ccwgroup_device *, int);
49 static int qeth_l3_isxdigit(char *buf)
51 while (*buf) {
52 if (!isxdigit(*buf++))
53 return 0;
55 return 1;
58 void qeth_l3_ipaddr4_to_string(const __u8 *addr, char *buf)
60 sprintf(buf, "%i.%i.%i.%i", addr[0], addr[1], addr[2], addr[3]);
63 int qeth_l3_string_to_ipaddr4(const char *buf, __u8 *addr)
65 int count = 0, rc = 0;
66 int in[4];
67 char c;
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];
78 return 0;
81 void qeth_l3_ipaddr6_to_string(const __u8 *addr, char *buf)
83 sprintf(buf, "%pI6", addr);
86 int qeth_l3_string_to_ipaddr6(const char *buf, __u8 *addr)
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, };
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;
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;
126 start = ++end;
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;
136 void qeth_l3_ipaddr_to_string(enum qeth_prot_versions proto, const __u8 *addr,
137 char *buf)
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);
145 int qeth_l3_string_to_ipaddr(const char *buf, enum qeth_prot_versions proto,
146 __u8 *addr)
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;
156 static void qeth_l3_convert_addr_to_bits(u8 *addr, u8 *bits, int len)
158 int i, j;
159 u8 octet;
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;
170 int qeth_l3_is_addr_covered_by_ipato(struct qeth_card *card,
171 struct qeth_ipaddr *addr)
173 struct qeth_ipato_entry *ipatoe;
174 u8 addr_bits[128] = {0, };
175 u8 ipatoe_bits[128] = {0, };
176 int rc = 0;
178 if (!card->ipato.enabled)
179 return 0;
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;
198 /* invert? */
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;
204 return rc;
208 * Add IP to be added to todo list. If there is already an "add todo"
209 * in this list we just incremenent the reference count.
210 * Returns 0 if we just incremented reference count.
212 static int __qeth_l3_insert_ip_todo(struct qeth_card *card,
213 struct qeth_ipaddr *addr, int add)
215 struct qeth_ipaddr *tmp, *t;
216 int found = 0;
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;
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;
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);
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;
265 list_add_tail(&addr->entry, card->ip_tbd_list);
267 return 1;
271 int qeth_l3_delete_ip(struct qeth_card *card, struct qeth_ipaddr *addr)
273 unsigned long flags;
274 int rc = 0;
276 QETH_CARD_TEXT(card, 4, "delip");
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);
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;
290 int qeth_l3_add_ip(struct qeth_card *card, struct qeth_ipaddr *addr)
292 unsigned long flags;
293 int rc = 0;
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);
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;
309 struct qeth_ipaddr *qeth_l3_get_addr_buffer(
310 enum qeth_prot_versions prot)
312 struct qeth_ipaddr *addr;
314 addr = kzalloc(sizeof(struct qeth_ipaddr), GFP_ATOMIC);
315 if (addr == NULL) {
316 return NULL;
318 addr->type = QETH_IP_TYPE_NORMAL;
319 addr->proto = prot;
320 return addr;
323 static void qeth_l3_delete_mc_addresses(struct qeth_card *card)
325 struct qeth_ipaddr *iptodo;
326 unsigned long flags;
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;
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);
342 * Add/remove address to/from card's ip list, i.e. try to add or remove
343 * reference to/from an IP address that is already registered on the card.
344 * Returns:
345 * 0 address was on card and its reference count has been adjusted,
346 * but is still > 0, so nothing has to be done
347 * also returns 0 if card was not on card and the todo was to delete
348 * the address -> there is also nothing to be done
349 * 1 address was not on card and the todo is to add it to the card's ip
350 * list
351 * -1 address was on card and its reference count has been decremented
352 * to <= 0 by the todo -> address must be removed from card
354 static int __qeth_l3_ref_ip_on_card(struct qeth_card *card,
355 struct qeth_ipaddr *todo, struct qeth_ipaddr **__addr)
357 struct qeth_ipaddr *addr;
358 int found = 0;
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;
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;
379 if (found) {
380 addr->users += todo->users;
381 if (addr->users <= 0) {
382 *__addr = addr;
383 return -1;
384 } else {
385 /* for VIPA and RXIP limit refcount to 1 */
386 if (addr->type != QETH_IP_TYPE_NORMAL)
387 addr->users = 1;
388 return 0;
391 if (todo->users > 0) {
392 /* for VIPA and RXIP limit refcount to 1 */
393 if (todo->type != QETH_IP_TYPE_NORMAL)
394 todo->users = 1;
395 return 1;
396 } else
397 return 0;
400 static void __qeth_l3_delete_all_mc(struct qeth_card *card,
401 unsigned long *flags)
403 struct list_head fail_list;
404 struct qeth_ipaddr *addr, *tmp;
405 int rc;
407 INIT_LIST_HEAD(&fail_list);
408 again:
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;
422 list_splice(&fail_list, &card->ip_list);
425 void qeth_l3_set_ip_addr_list(struct qeth_card *card)
427 struct list_head *tbd_list;
428 struct qeth_ipaddr *todo, *addr;
429 unsigned long flags;
430 int rc;
432 QETH_CARD_TEXT(card, 2, "sdiplist");
433 QETH_CARD_HEX(card, 2, &card, sizeof(void *));
435 if ((card->state != CARD_STATE_UP &&
436 card->state != CARD_STATE_SOFTSETUP) || card->options.sniffer) {
437 return;
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);
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;
459 rc = __qeth_l3_ref_ip_on_card(card, todo, &addr);
460 if (rc == 0) {
461 /* nothing to be done; only adjusted refcount */
462 kfree(todo);
463 } else if (rc == 1) {
464 /* new entry to be added to on-card list */
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 /* on-card entry to be removed */
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);
485 spin_unlock_irqrestore(&card->ip_lock, flags);
486 kfree(tbd_list);
489 static void qeth_l3_clear_ip_list(struct qeth_card *card, int recover)
491 struct qeth_ipaddr *addr, *tmp;
492 unsigned long flags;
494 QETH_CARD_TEXT(card, 4, "clearip");
495 if (recover && card->options.sniffer)
496 return;
497 spin_lock_irqsave(&card->ip_lock, flags);
498 /* clear todo list */
499 list_for_each_entry_safe(addr, tmp, card->ip_tbd_list, entry) {
500 list_del(&addr->entry);
501 kfree(addr);
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;
512 list_add_tail(&addr->entry, card->ip_tbd_list);
514 spin_unlock_irqrestore(&card->ip_lock, flags);
517 static int qeth_l3_address_exists_in_list(struct list_head *list,
518 struct qeth_ipaddr *addr, int same_type)
520 struct qeth_ipaddr *tmp;
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;
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;
539 return 0;
542 static int qeth_l3_send_setdelmc(struct qeth_card *card,
543 struct qeth_ipaddr *addr, int ipacmd)
545 int rc;
546 struct qeth_cmd_buffer *iob;
547 struct qeth_ipa_cmd *cmd;
549 QETH_CARD_TEXT(card, 4, "setdelmc");
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);
560 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
562 return rc;
565 static void qeth_l3_fill_netmask(u8 *netmask, unsigned int len)
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;
579 static int qeth_l3_send_setdelip(struct qeth_card *card,
580 struct qeth_ipaddr *addr, int ipacmd, unsigned int flags)
582 int rc;
583 struct qeth_cmd_buffer *iob;
584 struct qeth_ipa_cmd *cmd;
585 __u8 netmask[16];
587 QETH_CARD_TEXT(card, 4, "setdelip");
588 QETH_CARD_TEXT_(card, 4, "flags%02X", flags);
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;
605 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
607 return rc;
610 static int qeth_l3_send_setrouting(struct qeth_card *card,
611 enum qeth_routing_types type, enum qeth_prot_versions prot)
613 int rc;
614 struct qeth_ipa_cmd *cmd;
615 struct qeth_cmd_buffer *iob;
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);
623 return rc;
626 static void qeth_l3_correct_routing_type(struct qeth_card *card,
627 enum qeth_routing_types *type, enum qeth_prot_versions prot)
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;
636 default:
637 goto out_inval;
639 } else {
640 switch (*type) {
641 case NO_ROUTER:
642 case PRIMARY_ROUTER:
643 case SECONDARY_ROUTER:
644 return;
645 case MULTICAST_ROUTER:
646 if (qeth_is_ipafunc_supported(card, prot,
647 IPA_OSA_MC_ROUTER))
648 return;
649 default:
650 goto out_inval;
653 out_inval:
654 *type = NO_ROUTER;
657 int qeth_l3_setrouting_v4(struct qeth_card *card)
659 int rc;
661 QETH_CARD_TEXT(card, 3, "setrtg4");
663 qeth_l3_correct_routing_type(card, &card->options.route4.type,
664 QETH_PROT_IPV4);
666 rc = qeth_l3_send_setrouting(card, card->options.route4.type,
667 QETH_PROT_IPV4);
668 if (rc) {
669 card->options.route4.type = NO_ROUTER;
670 QETH_DBF_MESSAGE(2, "Error (0x%04x) while setting routing type"
671 " on %s. Type set to 'no router'.\n", rc,
672 QETH_CARD_IFNAME(card));
674 return rc;
677 int qeth_l3_setrouting_v6(struct qeth_card *card)
679 int rc = 0;
681 QETH_CARD_TEXT(card, 3, "setrtg6");
682 #ifdef CONFIG_QETH_IPV6
684 if (!qeth_is_supported(card, IPA_IPV6))
685 return 0;
686 qeth_l3_correct_routing_type(card, &card->options.route6.type,
687 QETH_PROT_IPV6);
689 rc = qeth_l3_send_setrouting(card, card->options.route6.type,
690 QETH_PROT_IPV6);
691 if (rc) {
692 card->options.route6.type = NO_ROUTER;
693 QETH_DBF_MESSAGE(2, "Error (0x%04x) while setting routing type"
694 " on %s. Type set to 'no router'.\n", rc,
695 QETH_CARD_IFNAME(card));
697 #endif
698 return rc;
702 * IP address takeover related functions
704 static void qeth_l3_clear_ipato_list(struct qeth_card *card)
707 struct qeth_ipato_entry *ipatoe, *tmp;
708 unsigned long flags;
710 spin_lock_irqsave(&card->ip_lock, flags);
711 list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry) {
712 list_del(&ipatoe->entry);
713 kfree(ipatoe);
715 spin_unlock_irqrestore(&card->ip_lock, flags);
718 int qeth_l3_add_ipato_entry(struct qeth_card *card,
719 struct qeth_ipato_entry *new)
721 struct qeth_ipato_entry *ipatoe;
722 unsigned long flags;
723 int rc = 0;
725 QETH_CARD_TEXT(card, 2, "addipato");
726 spin_lock_irqsave(&card->ip_lock, flags);
727 list_for_each_entry(ipatoe, &card->ipato.entries, entry) {
728 if (ipatoe->proto != new->proto)
729 continue;
730 if (!memcmp(ipatoe->addr, new->addr,
731 (ipatoe->proto == QETH_PROT_IPV4)? 4:16) &&
732 (ipatoe->mask_bits == new->mask_bits)) {
733 rc = -EEXIST;
734 break;
737 if (!rc)
738 list_add_tail(&new->entry, &card->ipato.entries);
740 spin_unlock_irqrestore(&card->ip_lock, flags);
741 return rc;
744 void qeth_l3_del_ipato_entry(struct qeth_card *card,
745 enum qeth_prot_versions proto, u8 *addr, int mask_bits)
747 struct qeth_ipato_entry *ipatoe, *tmp;
748 unsigned long flags;
750 QETH_CARD_TEXT(card, 2, "delipato");
751 spin_lock_irqsave(&card->ip_lock, flags);
752 list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry) {
753 if (ipatoe->proto != proto)
754 continue;
755 if (!memcmp(ipatoe->addr, addr,
756 (proto == QETH_PROT_IPV4)? 4:16) &&
757 (ipatoe->mask_bits == mask_bits)) {
758 list_del(&ipatoe->entry);
759 kfree(ipatoe);
762 spin_unlock_irqrestore(&card->ip_lock, flags);
766 * VIPA related functions
768 int qeth_l3_add_vipa(struct qeth_card *card, enum qeth_prot_versions proto,
769 const u8 *addr)
771 struct qeth_ipaddr *ipaddr;
772 unsigned long flags;
773 int rc = 0;
775 ipaddr = qeth_l3_get_addr_buffer(proto);
776 if (ipaddr) {
777 if (proto == QETH_PROT_IPV4) {
778 QETH_CARD_TEXT(card, 2, "addvipa4");
779 memcpy(&ipaddr->u.a4.addr, addr, 4);
780 ipaddr->u.a4.mask = 0;
781 } else if (proto == QETH_PROT_IPV6) {
782 QETH_CARD_TEXT(card, 2, "addvipa6");
783 memcpy(&ipaddr->u.a6.addr, addr, 16);
784 ipaddr->u.a6.pfxlen = 0;
786 ipaddr->type = QETH_IP_TYPE_VIPA;
787 ipaddr->set_flags = QETH_IPA_SETIP_VIPA_FLAG;
788 ipaddr->del_flags = QETH_IPA_DELIP_VIPA_FLAG;
789 } else
790 return -ENOMEM;
791 spin_lock_irqsave(&card->ip_lock, flags);
792 if (qeth_l3_address_exists_in_list(&card->ip_list, ipaddr, 0) ||
793 qeth_l3_address_exists_in_list(card->ip_tbd_list, ipaddr, 0))
794 rc = -EEXIST;
795 spin_unlock_irqrestore(&card->ip_lock, flags);
796 if (rc) {
797 kfree(ipaddr);
798 return rc;
800 if (!qeth_l3_add_ip(card, ipaddr))
801 kfree(ipaddr);
802 qeth_l3_set_ip_addr_list(card);
803 return rc;
806 void qeth_l3_del_vipa(struct qeth_card *card, enum qeth_prot_versions proto,
807 const u8 *addr)
809 struct qeth_ipaddr *ipaddr;
811 ipaddr = qeth_l3_get_addr_buffer(proto);
812 if (ipaddr) {
813 if (proto == QETH_PROT_IPV4) {
814 QETH_CARD_TEXT(card, 2, "delvipa4");
815 memcpy(&ipaddr->u.a4.addr, addr, 4);
816 ipaddr->u.a4.mask = 0;
817 } else if (proto == QETH_PROT_IPV6) {
818 QETH_CARD_TEXT(card, 2, "delvipa6");
819 memcpy(&ipaddr->u.a6.addr, addr, 16);
820 ipaddr->u.a6.pfxlen = 0;
822 ipaddr->type = QETH_IP_TYPE_VIPA;
823 } else
824 return;
825 if (!qeth_l3_delete_ip(card, ipaddr))
826 kfree(ipaddr);
827 qeth_l3_set_ip_addr_list(card);
831 * proxy ARP related functions
833 int qeth_l3_add_rxip(struct qeth_card *card, enum qeth_prot_versions proto,
834 const u8 *addr)
836 struct qeth_ipaddr *ipaddr;
837 unsigned long flags;
838 int rc = 0;
840 ipaddr = qeth_l3_get_addr_buffer(proto);
841 if (ipaddr) {
842 if (proto == QETH_PROT_IPV4) {
843 QETH_CARD_TEXT(card, 2, "addrxip4");
844 memcpy(&ipaddr->u.a4.addr, addr, 4);
845 ipaddr->u.a4.mask = 0;
846 } else if (proto == QETH_PROT_IPV6) {
847 QETH_CARD_TEXT(card, 2, "addrxip6");
848 memcpy(&ipaddr->u.a6.addr, addr, 16);
849 ipaddr->u.a6.pfxlen = 0;
851 ipaddr->type = QETH_IP_TYPE_RXIP;
852 ipaddr->set_flags = QETH_IPA_SETIP_TAKEOVER_FLAG;
853 ipaddr->del_flags = 0;
854 } else
855 return -ENOMEM;
856 spin_lock_irqsave(&card->ip_lock, flags);
857 if (qeth_l3_address_exists_in_list(&card->ip_list, ipaddr, 0) ||
858 qeth_l3_address_exists_in_list(card->ip_tbd_list, ipaddr, 0))
859 rc = -EEXIST;
860 spin_unlock_irqrestore(&card->ip_lock, flags);
861 if (rc) {
862 kfree(ipaddr);
863 return rc;
865 if (!qeth_l3_add_ip(card, ipaddr))
866 kfree(ipaddr);
867 qeth_l3_set_ip_addr_list(card);
868 return 0;
871 void qeth_l3_del_rxip(struct qeth_card *card, enum qeth_prot_versions proto,
872 const u8 *addr)
874 struct qeth_ipaddr *ipaddr;
876 ipaddr = qeth_l3_get_addr_buffer(proto);
877 if (ipaddr) {
878 if (proto == QETH_PROT_IPV4) {
879 QETH_CARD_TEXT(card, 2, "addrxip4");
880 memcpy(&ipaddr->u.a4.addr, addr, 4);
881 ipaddr->u.a4.mask = 0;
882 } else if (proto == QETH_PROT_IPV6) {
883 QETH_CARD_TEXT(card, 2, "addrxip6");
884 memcpy(&ipaddr->u.a6.addr, addr, 16);
885 ipaddr->u.a6.pfxlen = 0;
887 ipaddr->type = QETH_IP_TYPE_RXIP;
888 } else
889 return;
890 if (!qeth_l3_delete_ip(card, ipaddr))
891 kfree(ipaddr);
892 qeth_l3_set_ip_addr_list(card);
895 static int qeth_l3_register_addr_entry(struct qeth_card *card,
896 struct qeth_ipaddr *addr)
898 char buf[50];
899 int rc = 0;
900 int cnt = 3;
902 if (addr->proto == QETH_PROT_IPV4) {
903 QETH_CARD_TEXT(card, 2, "setaddr4");
904 QETH_CARD_HEX(card, 3, &addr->u.a4.addr, sizeof(int));
905 } else if (addr->proto == QETH_PROT_IPV6) {
906 QETH_CARD_TEXT(card, 2, "setaddr6");
907 QETH_CARD_HEX(card, 3, &addr->u.a6.addr, 8);
908 QETH_CARD_HEX(card, 3, ((char *)&addr->u.a6.addr) + 8, 8);
909 } else {
910 QETH_CARD_TEXT(card, 2, "setaddr?");
911 QETH_CARD_HEX(card, 3, addr, sizeof(struct qeth_ipaddr));
913 do {
914 if (addr->is_multicast)
915 rc = qeth_l3_send_setdelmc(card, addr, IPA_CMD_SETIPM);
916 else
917 rc = qeth_l3_send_setdelip(card, addr, IPA_CMD_SETIP,
918 addr->set_flags);
919 if (rc)
920 QETH_CARD_TEXT(card, 2, "failed");
921 } while ((--cnt > 0) && rc);
922 if (rc) {
923 QETH_CARD_TEXT(card, 2, "FAILED");
924 qeth_l3_ipaddr_to_string(addr->proto, (u8 *)&addr->u, buf);
925 dev_warn(&card->gdev->dev,
926 "Registering IP address %s failed\n", buf);
928 return rc;
931 static int qeth_l3_deregister_addr_entry(struct qeth_card *card,
932 struct qeth_ipaddr *addr)
934 int rc = 0;
936 if (addr->proto == QETH_PROT_IPV4) {
937 QETH_CARD_TEXT(card, 2, "deladdr4");
938 QETH_CARD_HEX(card, 3, &addr->u.a4.addr, sizeof(int));
939 } else if (addr->proto == QETH_PROT_IPV6) {
940 QETH_CARD_TEXT(card, 2, "deladdr6");
941 QETH_CARD_HEX(card, 3, &addr->u.a6.addr, 8);
942 QETH_CARD_HEX(card, 3, ((char *)&addr->u.a6.addr) + 8, 8);
943 } else {
944 QETH_CARD_TEXT(card, 2, "deladdr?");
945 QETH_CARD_HEX(card, 3, addr, sizeof(struct qeth_ipaddr));
947 if (addr->is_multicast)
948 rc = qeth_l3_send_setdelmc(card, addr, IPA_CMD_DELIPM);
949 else
950 rc = qeth_l3_send_setdelip(card, addr, IPA_CMD_DELIP,
951 addr->del_flags);
952 if (rc)
953 QETH_CARD_TEXT(card, 2, "failed");
955 return rc;
958 static inline u8 qeth_l3_get_qeth_hdr_flags4(int cast_type)
960 if (cast_type == RTN_MULTICAST)
961 return QETH_CAST_MULTICAST;
962 if (cast_type == RTN_BROADCAST)
963 return QETH_CAST_BROADCAST;
964 return QETH_CAST_UNICAST;
967 static inline u8 qeth_l3_get_qeth_hdr_flags6(int cast_type)
969 u8 ct = QETH_HDR_PASSTHRU | QETH_HDR_IPV6;
970 if (cast_type == RTN_MULTICAST)
971 return ct | QETH_CAST_MULTICAST;
972 if (cast_type == RTN_ANYCAST)
973 return ct | QETH_CAST_ANYCAST;
974 if (cast_type == RTN_BROADCAST)
975 return ct | QETH_CAST_BROADCAST;
976 return ct | QETH_CAST_UNICAST;
979 static int qeth_l3_setadapter_parms(struct qeth_card *card)
981 int rc;
983 QETH_DBF_TEXT(SETUP, 2, "setadprm");
985 if (!qeth_is_supported(card, IPA_SETADAPTERPARMS)) {
986 dev_info(&card->gdev->dev,
987 "set adapter parameters not supported.\n");
988 QETH_DBF_TEXT(SETUP, 2, " notsupp");
989 return 0;
991 rc = qeth_query_setadapterparms(card);
992 if (rc) {
993 QETH_DBF_MESSAGE(2, "%s couldn't set adapter parameters: "
994 "0x%x\n", dev_name(&card->gdev->dev), rc);
995 return rc;
997 if (qeth_adp_supported(card, IPA_SETADP_ALTER_MAC_ADDRESS)) {
998 rc = qeth_setadpparms_change_macaddr(card);
999 if (rc)
1000 dev_warn(&card->gdev->dev, "Reading the adapter MAC"
1001 " address failed\n");
1004 return rc;
1007 static int qeth_l3_default_setassparms_cb(struct qeth_card *card,
1008 struct qeth_reply *reply, unsigned long data)
1010 struct qeth_ipa_cmd *cmd;
1012 QETH_CARD_TEXT(card, 4, "defadpcb");
1014 cmd = (struct qeth_ipa_cmd *) data;
1015 if (cmd->hdr.return_code == 0) {
1016 cmd->hdr.return_code = cmd->data.setassparms.hdr.return_code;
1017 if (cmd->hdr.prot_version == QETH_PROT_IPV4)
1018 card->options.ipa4.enabled_funcs = cmd->hdr.ipa_enabled;
1019 if (cmd->hdr.prot_version == QETH_PROT_IPV6)
1020 card->options.ipa6.enabled_funcs = cmd->hdr.ipa_enabled;
1022 if (cmd->data.setassparms.hdr.assist_no == IPA_INBOUND_CHECKSUM &&
1023 cmd->data.setassparms.hdr.command_code == IPA_CMD_ASS_START) {
1024 card->info.csum_mask = cmd->data.setassparms.data.flags_32bit;
1025 QETH_CARD_TEXT_(card, 3, "csum:%d", card->info.csum_mask);
1027 if (cmd->data.setassparms.hdr.assist_no == IPA_OUTBOUND_CHECKSUM &&
1028 cmd->data.setassparms.hdr.command_code == IPA_CMD_ASS_START) {
1029 card->info.tx_csum_mask =
1030 cmd->data.setassparms.data.flags_32bit;
1031 QETH_CARD_TEXT_(card, 3, "tcsu:%d", card->info.tx_csum_mask);
1034 return 0;
1037 static struct qeth_cmd_buffer *qeth_l3_get_setassparms_cmd(
1038 struct qeth_card *card, enum qeth_ipa_funcs ipa_func, __u16 cmd_code,
1039 __u16 len, enum qeth_prot_versions prot)
1041 struct qeth_cmd_buffer *iob;
1042 struct qeth_ipa_cmd *cmd;
1044 QETH_CARD_TEXT(card, 4, "getasscm");
1045 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SETASSPARMS, prot);
1047 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1048 cmd->data.setassparms.hdr.assist_no = ipa_func;
1049 cmd->data.setassparms.hdr.length = 8 + len;
1050 cmd->data.setassparms.hdr.command_code = cmd_code;
1051 cmd->data.setassparms.hdr.return_code = 0;
1052 cmd->data.setassparms.hdr.seq_no = 0;
1054 return iob;
1057 static int qeth_l3_send_setassparms(struct qeth_card *card,
1058 struct qeth_cmd_buffer *iob, __u16 len, long data,
1059 int (*reply_cb)(struct qeth_card *, struct qeth_reply *,
1060 unsigned long),
1061 void *reply_param)
1063 int rc;
1064 struct qeth_ipa_cmd *cmd;
1066 QETH_CARD_TEXT(card, 4, "sendassp");
1068 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1069 if (len <= sizeof(__u32))
1070 cmd->data.setassparms.data.flags_32bit = (__u32) data;
1071 else /* (len > sizeof(__u32)) */
1072 memcpy(&cmd->data.setassparms.data, (void *) data, len);
1074 rc = qeth_send_ipa_cmd(card, iob, reply_cb, reply_param);
1075 return rc;
1078 #ifdef CONFIG_QETH_IPV6
1079 static int qeth_l3_send_simple_setassparms_ipv6(struct qeth_card *card,
1080 enum qeth_ipa_funcs ipa_func, __u16 cmd_code)
1082 int rc;
1083 struct qeth_cmd_buffer *iob;
1085 QETH_CARD_TEXT(card, 4, "simassp6");
1086 iob = qeth_l3_get_setassparms_cmd(card, ipa_func, cmd_code,
1087 0, QETH_PROT_IPV6);
1088 rc = qeth_l3_send_setassparms(card, iob, 0, 0,
1089 qeth_l3_default_setassparms_cb, NULL);
1090 return rc;
1092 #endif
1094 static int qeth_l3_send_simple_setassparms(struct qeth_card *card,
1095 enum qeth_ipa_funcs ipa_func, __u16 cmd_code, long data)
1097 int rc;
1098 int length = 0;
1099 struct qeth_cmd_buffer *iob;
1101 QETH_CARD_TEXT(card, 4, "simassp4");
1102 if (data)
1103 length = sizeof(__u32);
1104 iob = qeth_l3_get_setassparms_cmd(card, ipa_func, cmd_code,
1105 length, QETH_PROT_IPV4);
1106 rc = qeth_l3_send_setassparms(card, iob, length, data,
1107 qeth_l3_default_setassparms_cb, NULL);
1108 return rc;
1111 static int qeth_l3_start_ipa_arp_processing(struct qeth_card *card)
1113 int rc;
1115 QETH_CARD_TEXT(card, 3, "ipaarp");
1117 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
1118 dev_info(&card->gdev->dev,
1119 "ARP processing not supported on %s!\n",
1120 QETH_CARD_IFNAME(card));
1121 return 0;
1123 rc = qeth_l3_send_simple_setassparms(card, IPA_ARP_PROCESSING,
1124 IPA_CMD_ASS_START, 0);
1125 if (rc) {
1126 dev_warn(&card->gdev->dev,
1127 "Starting ARP processing support for %s failed\n",
1128 QETH_CARD_IFNAME(card));
1130 return rc;
1133 static int qeth_l3_start_ipa_ip_fragmentation(struct qeth_card *card)
1135 int rc;
1137 QETH_CARD_TEXT(card, 3, "ipaipfrg");
1139 if (!qeth_is_supported(card, IPA_IP_FRAGMENTATION)) {
1140 dev_info(&card->gdev->dev,
1141 "Hardware IP fragmentation not supported on %s\n",
1142 QETH_CARD_IFNAME(card));
1143 return -EOPNOTSUPP;
1146 rc = qeth_l3_send_simple_setassparms(card, IPA_IP_FRAGMENTATION,
1147 IPA_CMD_ASS_START, 0);
1148 if (rc) {
1149 dev_warn(&card->gdev->dev,
1150 "Starting IP fragmentation support for %s failed\n",
1151 QETH_CARD_IFNAME(card));
1152 } else
1153 dev_info(&card->gdev->dev,
1154 "Hardware IP fragmentation enabled \n");
1155 return rc;
1158 static int qeth_l3_start_ipa_source_mac(struct qeth_card *card)
1160 int rc;
1162 QETH_CARD_TEXT(card, 3, "stsrcmac");
1164 if (!qeth_is_supported(card, IPA_SOURCE_MAC)) {
1165 dev_info(&card->gdev->dev,
1166 "Inbound source MAC-address not supported on %s\n",
1167 QETH_CARD_IFNAME(card));
1168 return -EOPNOTSUPP;
1171 rc = qeth_l3_send_simple_setassparms(card, IPA_SOURCE_MAC,
1172 IPA_CMD_ASS_START, 0);
1173 if (rc)
1174 dev_warn(&card->gdev->dev,
1175 "Starting source MAC-address support for %s failed\n",
1176 QETH_CARD_IFNAME(card));
1177 return rc;
1180 static int qeth_l3_start_ipa_vlan(struct qeth_card *card)
1182 int rc = 0;
1184 QETH_CARD_TEXT(card, 3, "strtvlan");
1186 if (!qeth_is_supported(card, IPA_FULL_VLAN)) {
1187 dev_info(&card->gdev->dev,
1188 "VLAN not supported on %s\n", QETH_CARD_IFNAME(card));
1189 return -EOPNOTSUPP;
1192 rc = qeth_l3_send_simple_setassparms(card, IPA_VLAN_PRIO,
1193 IPA_CMD_ASS_START, 0);
1194 if (rc) {
1195 dev_warn(&card->gdev->dev,
1196 "Starting VLAN support for %s failed\n",
1197 QETH_CARD_IFNAME(card));
1198 } else {
1199 dev_info(&card->gdev->dev, "VLAN enabled\n");
1201 return rc;
1204 static int qeth_l3_start_ipa_multicast(struct qeth_card *card)
1206 int rc;
1208 QETH_CARD_TEXT(card, 3, "stmcast");
1210 if (!qeth_is_supported(card, IPA_MULTICASTING)) {
1211 dev_info(&card->gdev->dev,
1212 "Multicast not supported on %s\n",
1213 QETH_CARD_IFNAME(card));
1214 return -EOPNOTSUPP;
1217 rc = qeth_l3_send_simple_setassparms(card, IPA_MULTICASTING,
1218 IPA_CMD_ASS_START, 0);
1219 if (rc) {
1220 dev_warn(&card->gdev->dev,
1221 "Starting multicast support for %s failed\n",
1222 QETH_CARD_IFNAME(card));
1223 } else {
1224 dev_info(&card->gdev->dev, "Multicast enabled\n");
1225 card->dev->flags |= IFF_MULTICAST;
1227 return rc;
1230 #ifdef CONFIG_QETH_IPV6
1231 static int qeth_l3_softsetup_ipv6(struct qeth_card *card)
1233 int rc;
1235 QETH_CARD_TEXT(card, 3, "softipv6");
1237 if (card->info.type == QETH_CARD_TYPE_IQD)
1238 goto out;
1240 rc = qeth_query_ipassists(card, QETH_PROT_IPV6);
1241 if (rc) {
1242 dev_err(&card->gdev->dev,
1243 "Activating IPv6 support for %s failed\n",
1244 QETH_CARD_IFNAME(card));
1245 return rc;
1247 rc = qeth_l3_send_simple_setassparms(card, IPA_IPV6,
1248 IPA_CMD_ASS_START, 3);
1249 if (rc) {
1250 dev_err(&card->gdev->dev,
1251 "Activating IPv6 support for %s failed\n",
1252 QETH_CARD_IFNAME(card));
1253 return rc;
1255 rc = qeth_l3_send_simple_setassparms_ipv6(card, IPA_IPV6,
1256 IPA_CMD_ASS_START);
1257 if (rc) {
1258 dev_err(&card->gdev->dev,
1259 "Activating IPv6 support for %s failed\n",
1260 QETH_CARD_IFNAME(card));
1261 return rc;
1263 rc = qeth_l3_send_simple_setassparms_ipv6(card, IPA_PASSTHRU,
1264 IPA_CMD_ASS_START);
1265 if (rc) {
1266 dev_warn(&card->gdev->dev,
1267 "Enabling the passthrough mode for %s failed\n",
1268 QETH_CARD_IFNAME(card));
1269 return rc;
1271 out:
1272 dev_info(&card->gdev->dev, "IPV6 enabled\n");
1273 return 0;
1275 #endif
1277 static int qeth_l3_start_ipa_ipv6(struct qeth_card *card)
1279 int rc = 0;
1281 QETH_CARD_TEXT(card, 3, "strtipv6");
1283 if (!qeth_is_supported(card, IPA_IPV6)) {
1284 dev_info(&card->gdev->dev,
1285 "IPv6 not supported on %s\n", QETH_CARD_IFNAME(card));
1286 return 0;
1288 #ifdef CONFIG_QETH_IPV6
1289 rc = qeth_l3_softsetup_ipv6(card);
1290 #endif
1291 return rc ;
1294 static int qeth_l3_start_ipa_broadcast(struct qeth_card *card)
1296 int rc;
1298 QETH_CARD_TEXT(card, 3, "stbrdcst");
1299 card->info.broadcast_capable = 0;
1300 if (!qeth_is_supported(card, IPA_FILTERING)) {
1301 dev_info(&card->gdev->dev,
1302 "Broadcast not supported on %s\n",
1303 QETH_CARD_IFNAME(card));
1304 rc = -EOPNOTSUPP;
1305 goto out;
1307 rc = qeth_l3_send_simple_setassparms(card, IPA_FILTERING,
1308 IPA_CMD_ASS_START, 0);
1309 if (rc) {
1310 dev_warn(&card->gdev->dev, "Enabling broadcast filtering for "
1311 "%s failed\n", QETH_CARD_IFNAME(card));
1312 goto out;
1315 rc = qeth_l3_send_simple_setassparms(card, IPA_FILTERING,
1316 IPA_CMD_ASS_CONFIGURE, 1);
1317 if (rc) {
1318 dev_warn(&card->gdev->dev,
1319 "Setting up broadcast filtering for %s failed\n",
1320 QETH_CARD_IFNAME(card));
1321 goto out;
1323 card->info.broadcast_capable = QETH_BROADCAST_WITH_ECHO;
1324 dev_info(&card->gdev->dev, "Broadcast enabled\n");
1325 rc = qeth_l3_send_simple_setassparms(card, IPA_FILTERING,
1326 IPA_CMD_ASS_ENABLE, 1);
1327 if (rc) {
1328 dev_warn(&card->gdev->dev, "Setting up broadcast echo "
1329 "filtering for %s failed\n", QETH_CARD_IFNAME(card));
1330 goto out;
1332 card->info.broadcast_capable = QETH_BROADCAST_WITHOUT_ECHO;
1333 out:
1334 if (card->info.broadcast_capable)
1335 card->dev->flags |= IFF_BROADCAST;
1336 else
1337 card->dev->flags &= ~IFF_BROADCAST;
1338 return rc;
1341 static int qeth_l3_send_checksum_command(struct qeth_card *card)
1343 int rc;
1345 rc = qeth_l3_send_simple_setassparms(card, IPA_INBOUND_CHECKSUM,
1346 IPA_CMD_ASS_START, 0);
1347 if (rc) {
1348 dev_warn(&card->gdev->dev, "Starting HW checksumming for %s "
1349 "failed, using SW checksumming\n",
1350 QETH_CARD_IFNAME(card));
1351 return rc;
1353 rc = qeth_l3_send_simple_setassparms(card, IPA_INBOUND_CHECKSUM,
1354 IPA_CMD_ASS_ENABLE,
1355 card->info.csum_mask);
1356 if (rc) {
1357 dev_warn(&card->gdev->dev, "Enabling HW checksumming for %s "
1358 "failed, using SW checksumming\n",
1359 QETH_CARD_IFNAME(card));
1360 return rc;
1362 return 0;
1365 static int qeth_l3_set_rx_csum(struct qeth_card *card, int on)
1367 int rc = 0;
1369 if (on) {
1370 rc = qeth_l3_send_checksum_command(card);
1371 if (rc)
1372 return -EIO;
1373 dev_info(&card->gdev->dev,
1374 "HW Checksumming (inbound) enabled\n");
1375 } else {
1376 rc = qeth_l3_send_simple_setassparms(card,
1377 IPA_INBOUND_CHECKSUM, IPA_CMD_ASS_STOP, 0);
1378 if (rc)
1379 return -EIO;
1382 return 0;
1385 static int qeth_l3_start_ipa_checksum(struct qeth_card *card)
1387 QETH_CARD_TEXT(card, 3, "strtcsum");
1389 if (card->dev->features & NETIF_F_RXCSUM) {
1390 rtnl_lock();
1391 /* force set_features call */
1392 card->dev->features &= ~NETIF_F_RXCSUM;
1393 netdev_update_features(card->dev);
1394 rtnl_unlock();
1396 return 0;
1399 static int qeth_l3_start_ipa_tx_checksum(struct qeth_card *card)
1401 int rc = 0;
1403 if (!qeth_is_supported(card, IPA_OUTBOUND_CHECKSUM))
1404 return rc;
1405 rc = qeth_l3_send_simple_setassparms(card, IPA_OUTBOUND_CHECKSUM,
1406 IPA_CMD_ASS_START, 0);
1407 if (rc)
1408 goto err_out;
1409 rc = qeth_l3_send_simple_setassparms(card, IPA_OUTBOUND_CHECKSUM,
1410 IPA_CMD_ASS_ENABLE, card->info.tx_csum_mask);
1411 if (rc)
1412 goto err_out;
1413 dev_info(&card->gdev->dev, "HW TX Checksumming enabled\n");
1414 return rc;
1415 err_out:
1416 dev_warn(&card->gdev->dev, "Enabling HW TX checksumming for %s "
1417 "failed, using SW TX checksumming\n", QETH_CARD_IFNAME(card));
1418 return rc;
1421 static int qeth_l3_start_ipa_tso(struct qeth_card *card)
1423 int rc;
1425 QETH_CARD_TEXT(card, 3, "sttso");
1427 if (!qeth_is_supported(card, IPA_OUTBOUND_TSO)) {
1428 dev_info(&card->gdev->dev,
1429 "Outbound TSO not supported on %s\n",
1430 QETH_CARD_IFNAME(card));
1431 rc = -EOPNOTSUPP;
1432 } else {
1433 rc = qeth_l3_send_simple_setassparms(card, IPA_OUTBOUND_TSO,
1434 IPA_CMD_ASS_START, 0);
1435 if (rc)
1436 dev_warn(&card->gdev->dev, "Starting outbound TCP "
1437 "segmentation offload for %s failed\n",
1438 QETH_CARD_IFNAME(card));
1439 else
1440 dev_info(&card->gdev->dev,
1441 "Outbound TSO enabled\n");
1443 if (rc)
1444 card->dev->features &= ~NETIF_F_TSO;
1445 return rc;
1448 static int qeth_l3_start_ipassists(struct qeth_card *card)
1450 QETH_CARD_TEXT(card, 3, "strtipas");
1452 if (qeth_set_access_ctrl_online(card, 0))
1453 return -EIO;
1454 qeth_l3_start_ipa_arp_processing(card); /* go on*/
1455 qeth_l3_start_ipa_ip_fragmentation(card); /* go on*/
1456 qeth_l3_start_ipa_source_mac(card); /* go on*/
1457 qeth_l3_start_ipa_vlan(card); /* go on*/
1458 qeth_l3_start_ipa_multicast(card); /* go on*/
1459 qeth_l3_start_ipa_ipv6(card); /* go on*/
1460 qeth_l3_start_ipa_broadcast(card); /* go on*/
1461 qeth_l3_start_ipa_checksum(card); /* go on*/
1462 qeth_l3_start_ipa_tx_checksum(card);
1463 qeth_l3_start_ipa_tso(card); /* go on*/
1464 return 0;
1467 static int qeth_l3_iqd_read_initial_mac_cb(struct qeth_card *card,
1468 struct qeth_reply *reply, unsigned long data)
1470 struct qeth_ipa_cmd *cmd;
1472 cmd = (struct qeth_ipa_cmd *) data;
1473 if (cmd->hdr.return_code == 0)
1474 memcpy(card->dev->dev_addr,
1475 cmd->data.create_destroy_addr.unique_id, ETH_ALEN);
1476 else
1477 eth_random_addr(card->dev->dev_addr);
1479 return 0;
1482 static int qeth_l3_iqd_read_initial_mac(struct qeth_card *card)
1484 int rc = 0;
1485 struct qeth_cmd_buffer *iob;
1486 struct qeth_ipa_cmd *cmd;
1488 QETH_DBF_TEXT(SETUP, 2, "hsrmac");
1490 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_CREATE_ADDR,
1491 QETH_PROT_IPV6);
1492 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1493 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
1494 card->info.unique_id;
1496 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_iqd_read_initial_mac_cb,
1497 NULL);
1498 return rc;
1501 static int qeth_l3_get_unique_id_cb(struct qeth_card *card,
1502 struct qeth_reply *reply, unsigned long data)
1504 struct qeth_ipa_cmd *cmd;
1506 cmd = (struct qeth_ipa_cmd *) data;
1507 if (cmd->hdr.return_code == 0)
1508 card->info.unique_id = *((__u16 *)
1509 &cmd->data.create_destroy_addr.unique_id[6]);
1510 else {
1511 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
1512 UNIQUE_ID_NOT_BY_CARD;
1513 dev_warn(&card->gdev->dev, "The network adapter failed to "
1514 "generate a unique ID\n");
1516 return 0;
1519 static int qeth_l3_get_unique_id(struct qeth_card *card)
1521 int rc = 0;
1522 struct qeth_cmd_buffer *iob;
1523 struct qeth_ipa_cmd *cmd;
1525 QETH_DBF_TEXT(SETUP, 2, "guniqeid");
1527 if (!qeth_is_supported(card, IPA_IPV6)) {
1528 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
1529 UNIQUE_ID_NOT_BY_CARD;
1530 return 0;
1533 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_CREATE_ADDR,
1534 QETH_PROT_IPV6);
1535 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1536 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
1537 card->info.unique_id;
1539 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_get_unique_id_cb, NULL);
1540 return rc;
1543 static int
1544 qeth_diags_trace_cb(struct qeth_card *card, struct qeth_reply *reply,
1545 unsigned long data)
1547 struct qeth_ipa_cmd *cmd;
1548 __u16 rc;
1550 QETH_DBF_TEXT(SETUP, 2, "diastrcb");
1552 cmd = (struct qeth_ipa_cmd *)data;
1553 rc = cmd->hdr.return_code;
1554 if (rc)
1555 QETH_CARD_TEXT_(card, 2, "dxter%x", rc);
1556 switch (cmd->data.diagass.action) {
1557 case QETH_DIAGS_CMD_TRACE_QUERY:
1558 break;
1559 case QETH_DIAGS_CMD_TRACE_DISABLE:
1560 switch (rc) {
1561 case 0:
1562 case IPA_RC_INVALID_SUBCMD:
1563 card->info.promisc_mode = SET_PROMISC_MODE_OFF;
1564 dev_info(&card->gdev->dev, "The HiperSockets network "
1565 "traffic analyzer is deactivated\n");
1566 break;
1567 default:
1568 break;
1570 break;
1571 case QETH_DIAGS_CMD_TRACE_ENABLE:
1572 switch (rc) {
1573 case 0:
1574 card->info.promisc_mode = SET_PROMISC_MODE_ON;
1575 dev_info(&card->gdev->dev, "The HiperSockets network "
1576 "traffic analyzer is activated\n");
1577 break;
1578 case IPA_RC_HARDWARE_AUTH_ERROR:
1579 dev_warn(&card->gdev->dev, "The device is not "
1580 "authorized to run as a HiperSockets network "
1581 "traffic analyzer\n");
1582 break;
1583 case IPA_RC_TRACE_ALREADY_ACTIVE:
1584 dev_warn(&card->gdev->dev, "A HiperSockets "
1585 "network traffic analyzer is already "
1586 "active in the HiperSockets LAN\n");
1587 break;
1588 default:
1589 break;
1591 break;
1592 default:
1593 QETH_DBF_MESSAGE(2, "Unknown sniffer action (0x%04x) on %s\n",
1594 cmd->data.diagass.action, QETH_CARD_IFNAME(card));
1597 return 0;
1600 static int
1601 qeth_diags_trace(struct qeth_card *card, enum qeth_diags_trace_cmds diags_cmd)
1603 struct qeth_cmd_buffer *iob;
1604 struct qeth_ipa_cmd *cmd;
1606 QETH_DBF_TEXT(SETUP, 2, "diagtrac");
1608 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SET_DIAG_ASS, 0);
1609 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1610 cmd->data.diagass.subcmd_len = 16;
1611 cmd->data.diagass.subcmd = QETH_DIAGS_CMD_TRACE;
1612 cmd->data.diagass.type = QETH_DIAGS_TYPE_HIPERSOCKET;
1613 cmd->data.diagass.action = diags_cmd;
1614 return qeth_send_ipa_cmd(card, iob, qeth_diags_trace_cb, NULL);
1617 static void qeth_l3_get_mac_for_ipm(__u32 ipm, char *mac,
1618 struct net_device *dev)
1620 ip_eth_mc_map(ipm, mac);
1623 static void qeth_l3_add_mc(struct qeth_card *card, struct in_device *in4_dev)
1625 struct qeth_ipaddr *ipm;
1626 struct ip_mc_list *im4;
1627 char buf[MAX_ADDR_LEN];
1629 QETH_CARD_TEXT(card, 4, "addmc");
1630 for (im4 = rcu_dereference(in4_dev->mc_list); im4 != NULL;
1631 im4 = rcu_dereference(im4->next_rcu)) {
1632 qeth_l3_get_mac_for_ipm(im4->multiaddr, buf, in4_dev->dev);
1633 ipm = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
1634 if (!ipm)
1635 continue;
1636 ipm->u.a4.addr = im4->multiaddr;
1637 memcpy(ipm->mac, buf, OSA_ADDR_LEN);
1638 ipm->is_multicast = 1;
1639 if (!qeth_l3_add_ip(card, ipm))
1640 kfree(ipm);
1644 /* called with rcu_read_lock */
1645 static void qeth_l3_add_vlan_mc(struct qeth_card *card)
1647 struct in_device *in_dev;
1648 u16 vid;
1650 QETH_CARD_TEXT(card, 4, "addmcvl");
1651 if (!qeth_is_supported(card, IPA_FULL_VLAN))
1652 return;
1654 for_each_set_bit(vid, card->active_vlans, VLAN_N_VID) {
1655 struct net_device *netdev;
1657 netdev = __vlan_find_dev_deep(card->dev, vid);
1658 if (netdev == NULL ||
1659 !(netdev->flags & IFF_UP))
1660 continue;
1661 in_dev = __in_dev_get_rcu(netdev);
1662 if (!in_dev)
1663 continue;
1664 qeth_l3_add_mc(card, in_dev);
1668 static void qeth_l3_add_multicast_ipv4(struct qeth_card *card)
1670 struct in_device *in4_dev;
1672 QETH_CARD_TEXT(card, 4, "chkmcv4");
1673 rcu_read_lock();
1674 in4_dev = __in_dev_get_rcu(card->dev);
1675 if (in4_dev == NULL)
1676 goto unlock;
1677 qeth_l3_add_mc(card, in4_dev);
1678 qeth_l3_add_vlan_mc(card);
1679 unlock:
1680 rcu_read_unlock();
1683 #ifdef CONFIG_QETH_IPV6
1684 static void qeth_l3_add_mc6(struct qeth_card *card, struct inet6_dev *in6_dev)
1686 struct qeth_ipaddr *ipm;
1687 struct ifmcaddr6 *im6;
1688 char buf[MAX_ADDR_LEN];
1690 QETH_CARD_TEXT(card, 4, "addmc6");
1691 for (im6 = in6_dev->mc_list; im6 != NULL; im6 = im6->next) {
1692 ndisc_mc_map(&im6->mca_addr, buf, in6_dev->dev, 0);
1693 ipm = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
1694 if (!ipm)
1695 continue;
1696 ipm->is_multicast = 1;
1697 memcpy(ipm->mac, buf, OSA_ADDR_LEN);
1698 memcpy(&ipm->u.a6.addr, &im6->mca_addr.s6_addr,
1699 sizeof(struct in6_addr));
1700 if (!qeth_l3_add_ip(card, ipm))
1701 kfree(ipm);
1705 /* called with rcu_read_lock */
1706 static void qeth_l3_add_vlan_mc6(struct qeth_card *card)
1708 struct inet6_dev *in_dev;
1709 u16 vid;
1711 QETH_CARD_TEXT(card, 4, "admc6vl");
1712 if (!qeth_is_supported(card, IPA_FULL_VLAN))
1713 return;
1715 for_each_set_bit(vid, card->active_vlans, VLAN_N_VID) {
1716 struct net_device *netdev;
1718 netdev = __vlan_find_dev_deep(card->dev, vid);
1719 if (netdev == NULL ||
1720 !(netdev->flags & IFF_UP))
1721 continue;
1722 in_dev = in6_dev_get(netdev);
1723 if (!in_dev)
1724 continue;
1725 read_lock_bh(&in_dev->lock);
1726 qeth_l3_add_mc6(card, in_dev);
1727 read_unlock_bh(&in_dev->lock);
1728 in6_dev_put(in_dev);
1732 static void qeth_l3_add_multicast_ipv6(struct qeth_card *card)
1734 struct inet6_dev *in6_dev;
1736 QETH_CARD_TEXT(card, 4, "chkmcv6");
1737 if (!qeth_is_supported(card, IPA_IPV6))
1738 return ;
1739 in6_dev = in6_dev_get(card->dev);
1740 if (in6_dev == NULL)
1741 return;
1742 rcu_read_lock();
1743 read_lock_bh(&in6_dev->lock);
1744 qeth_l3_add_mc6(card, in6_dev);
1745 qeth_l3_add_vlan_mc6(card);
1746 read_unlock_bh(&in6_dev->lock);
1747 rcu_read_unlock();
1748 in6_dev_put(in6_dev);
1750 #endif /* CONFIG_QETH_IPV6 */
1752 static void qeth_l3_free_vlan_addresses4(struct qeth_card *card,
1753 unsigned short vid)
1755 struct in_device *in_dev;
1756 struct in_ifaddr *ifa;
1757 struct qeth_ipaddr *addr;
1758 struct net_device *netdev;
1760 QETH_CARD_TEXT(card, 4, "frvaddr4");
1762 netdev = __vlan_find_dev_deep(card->dev, vid);
1763 if (!netdev)
1764 return;
1765 in_dev = in_dev_get(netdev);
1766 if (!in_dev)
1767 return;
1768 for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
1769 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
1770 if (addr) {
1771 addr->u.a4.addr = ifa->ifa_address;
1772 addr->u.a4.mask = ifa->ifa_mask;
1773 addr->type = QETH_IP_TYPE_NORMAL;
1774 if (!qeth_l3_delete_ip(card, addr))
1775 kfree(addr);
1778 in_dev_put(in_dev);
1781 static void qeth_l3_free_vlan_addresses6(struct qeth_card *card,
1782 unsigned short vid)
1784 #ifdef CONFIG_QETH_IPV6
1785 struct inet6_dev *in6_dev;
1786 struct inet6_ifaddr *ifa;
1787 struct qeth_ipaddr *addr;
1788 struct net_device *netdev;
1790 QETH_CARD_TEXT(card, 4, "frvaddr6");
1792 netdev = __vlan_find_dev_deep(card->dev, vid);
1793 if (!netdev)
1794 return;
1795 in6_dev = in6_dev_get(netdev);
1796 if (!in6_dev)
1797 return;
1798 list_for_each_entry(ifa, &in6_dev->addr_list, if_list) {
1799 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
1800 if (addr) {
1801 memcpy(&addr->u.a6.addr, &ifa->addr,
1802 sizeof(struct in6_addr));
1803 addr->u.a6.pfxlen = ifa->prefix_len;
1804 addr->type = QETH_IP_TYPE_NORMAL;
1805 if (!qeth_l3_delete_ip(card, addr))
1806 kfree(addr);
1809 in6_dev_put(in6_dev);
1810 #endif /* CONFIG_QETH_IPV6 */
1813 static void qeth_l3_free_vlan_addresses(struct qeth_card *card,
1814 unsigned short vid)
1816 rcu_read_lock();
1817 qeth_l3_free_vlan_addresses4(card, vid);
1818 qeth_l3_free_vlan_addresses6(card, vid);
1819 rcu_read_unlock();
1822 static int qeth_l3_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
1824 struct qeth_card *card = dev->ml_priv;
1826 set_bit(vid, card->active_vlans);
1827 return 0;
1830 static int qeth_l3_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
1832 struct qeth_card *card = dev->ml_priv;
1833 unsigned long flags;
1835 QETH_CARD_TEXT_(card, 4, "kid:%d", vid);
1836 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
1837 QETH_CARD_TEXT(card, 3, "kidREC");
1838 return 0;
1840 spin_lock_irqsave(&card->vlanlock, flags);
1841 /* unregister IP addresses of vlan device */
1842 qeth_l3_free_vlan_addresses(card, vid);
1843 clear_bit(vid, card->active_vlans);
1844 spin_unlock_irqrestore(&card->vlanlock, flags);
1845 qeth_l3_set_multicast_list(card->dev);
1846 return 0;
1849 static inline int qeth_l3_rebuild_skb(struct qeth_card *card,
1850 struct sk_buff *skb, struct qeth_hdr *hdr,
1851 unsigned short *vlan_id)
1853 __be16 prot;
1854 struct iphdr *ip_hdr;
1855 unsigned char tg_addr[MAX_ADDR_LEN];
1856 int is_vlan = 0;
1858 if (!(hdr->hdr.l3.flags & QETH_HDR_PASSTHRU)) {
1859 prot = htons((hdr->hdr.l3.flags & QETH_HDR_IPV6)? ETH_P_IPV6 :
1860 ETH_P_IP);
1861 switch (hdr->hdr.l3.flags & QETH_HDR_CAST_MASK) {
1862 case QETH_CAST_MULTICAST:
1863 switch (prot) {
1864 #ifdef CONFIG_QETH_IPV6
1865 case __constant_htons(ETH_P_IPV6):
1866 ndisc_mc_map((struct in6_addr *)
1867 skb->data + 24,
1868 tg_addr, card->dev, 0);
1869 break;
1870 #endif
1871 case __constant_htons(ETH_P_IP):
1872 ip_hdr = (struct iphdr *)skb->data;
1873 ip_eth_mc_map(ip_hdr->daddr, tg_addr);
1874 break;
1875 default:
1876 memcpy(tg_addr, card->dev->broadcast,
1877 card->dev->addr_len);
1879 card->stats.multicast++;
1880 skb->pkt_type = PACKET_MULTICAST;
1881 break;
1882 case QETH_CAST_BROADCAST:
1883 memcpy(tg_addr, card->dev->broadcast,
1884 card->dev->addr_len);
1885 card->stats.multicast++;
1886 skb->pkt_type = PACKET_BROADCAST;
1887 break;
1888 case QETH_CAST_UNICAST:
1889 case QETH_CAST_ANYCAST:
1890 case QETH_CAST_NOCAST:
1891 default:
1892 if (card->options.sniffer)
1893 skb->pkt_type = PACKET_OTHERHOST;
1894 else
1895 skb->pkt_type = PACKET_HOST;
1896 memcpy(tg_addr, card->dev->dev_addr,
1897 card->dev->addr_len);
1899 if (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_SRC_MAC_ADDR)
1900 card->dev->header_ops->create(skb, card->dev, prot,
1901 tg_addr, &hdr->hdr.l3.dest_addr[2],
1902 card->dev->addr_len);
1903 else
1904 card->dev->header_ops->create(skb, card->dev, prot,
1905 tg_addr, "FAKELL", card->dev->addr_len);
1908 skb->protocol = eth_type_trans(skb, card->dev);
1910 if (hdr->hdr.l3.ext_flags &
1911 (QETH_HDR_EXT_VLAN_FRAME | QETH_HDR_EXT_INCLUDE_VLAN_TAG)) {
1912 *vlan_id = (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_VLAN_FRAME) ?
1913 hdr->hdr.l3.vlan_id : *((u16 *)&hdr->hdr.l3.dest_addr[12]);
1914 is_vlan = 1;
1917 if (card->dev->features & NETIF_F_RXCSUM) {
1918 if ((hdr->hdr.l3.ext_flags &
1919 (QETH_HDR_EXT_CSUM_HDR_REQ |
1920 QETH_HDR_EXT_CSUM_TRANSP_REQ)) ==
1921 (QETH_HDR_EXT_CSUM_HDR_REQ |
1922 QETH_HDR_EXT_CSUM_TRANSP_REQ))
1923 skb->ip_summed = CHECKSUM_UNNECESSARY;
1924 else
1925 skb->ip_summed = CHECKSUM_NONE;
1926 } else
1927 skb->ip_summed = CHECKSUM_NONE;
1929 return is_vlan;
1932 static int qeth_l3_process_inbound_buffer(struct qeth_card *card,
1933 int budget, int *done)
1935 int work_done = 0;
1936 struct sk_buff *skb;
1937 struct qeth_hdr *hdr;
1938 __u16 vlan_tag = 0;
1939 int is_vlan;
1940 unsigned int len;
1941 __u16 magic;
1943 *done = 0;
1944 WARN_ON_ONCE(!budget);
1945 while (budget) {
1946 skb = qeth_core_get_next_skb(card,
1947 &card->qdio.in_q->bufs[card->rx.b_index],
1948 &card->rx.b_element, &card->rx.e_offset, &hdr);
1949 if (!skb) {
1950 *done = 1;
1951 break;
1953 skb->dev = card->dev;
1954 switch (hdr->hdr.l3.id) {
1955 case QETH_HEADER_TYPE_LAYER3:
1956 magic = *(__u16 *)skb->data;
1957 if ((card->info.type == QETH_CARD_TYPE_IQD) &&
1958 (magic == ETH_P_AF_IUCV)) {
1959 skb->protocol = ETH_P_AF_IUCV;
1960 skb->pkt_type = PACKET_HOST;
1961 skb->mac_header = NET_SKB_PAD;
1962 skb->dev = card->dev;
1963 len = skb->len;
1964 card->dev->header_ops->create(skb, card->dev, 0,
1965 card->dev->dev_addr, "FAKELL",
1966 card->dev->addr_len);
1967 netif_receive_skb(skb);
1968 } else {
1969 is_vlan = qeth_l3_rebuild_skb(card, skb, hdr,
1970 &vlan_tag);
1971 len = skb->len;
1972 if (is_vlan && !card->options.sniffer)
1973 __vlan_hwaccel_put_tag(skb, vlan_tag);
1974 napi_gro_receive(&card->napi, skb);
1976 break;
1977 case QETH_HEADER_TYPE_LAYER2: /* for HiperSockets sniffer */
1978 skb->pkt_type = PACKET_HOST;
1979 skb->protocol = eth_type_trans(skb, skb->dev);
1980 len = skb->len;
1981 netif_receive_skb(skb);
1982 break;
1983 default:
1984 dev_kfree_skb_any(skb);
1985 QETH_CARD_TEXT(card, 3, "inbunkno");
1986 QETH_DBF_HEX(CTRL, 3, hdr, QETH_DBF_CTRL_LEN);
1987 continue;
1989 work_done++;
1990 budget--;
1991 card->stats.rx_packets++;
1992 card->stats.rx_bytes += len;
1994 return work_done;
1997 static int qeth_l3_poll(struct napi_struct *napi, int budget)
1999 struct qeth_card *card = container_of(napi, struct qeth_card, napi);
2000 int work_done = 0;
2001 struct qeth_qdio_buffer *buffer;
2002 int done;
2003 int new_budget = budget;
2005 if (card->options.performance_stats) {
2006 card->perf_stats.inbound_cnt++;
2007 card->perf_stats.inbound_start_time = qeth_get_micros();
2010 while (1) {
2011 if (!card->rx.b_count) {
2012 card->rx.qdio_err = 0;
2013 card->rx.b_count = qdio_get_next_buffers(
2014 card->data.ccwdev, 0, &card->rx.b_index,
2015 &card->rx.qdio_err);
2016 if (card->rx.b_count <= 0) {
2017 card->rx.b_count = 0;
2018 break;
2020 card->rx.b_element =
2021 &card->qdio.in_q->bufs[card->rx.b_index]
2022 .buffer->element[0];
2023 card->rx.e_offset = 0;
2026 while (card->rx.b_count) {
2027 buffer = &card->qdio.in_q->bufs[card->rx.b_index];
2028 if (!(card->rx.qdio_err &&
2029 qeth_check_qdio_errors(card, buffer->buffer,
2030 card->rx.qdio_err, "qinerr")))
2031 work_done += qeth_l3_process_inbound_buffer(
2032 card, new_budget, &done);
2033 else
2034 done = 1;
2036 if (done) {
2037 if (card->options.performance_stats)
2038 card->perf_stats.bufs_rec++;
2039 qeth_put_buffer_pool_entry(card,
2040 buffer->pool_entry);
2041 qeth_queue_input_buffer(card, card->rx.b_index);
2042 card->rx.b_count--;
2043 if (card->rx.b_count) {
2044 card->rx.b_index =
2045 (card->rx.b_index + 1) %
2046 QDIO_MAX_BUFFERS_PER_Q;
2047 card->rx.b_element =
2048 &card->qdio.in_q
2049 ->bufs[card->rx.b_index]
2050 .buffer->element[0];
2051 card->rx.e_offset = 0;
2055 if (work_done >= budget)
2056 goto out;
2057 else
2058 new_budget = budget - work_done;
2062 napi_complete(napi);
2063 if (qdio_start_irq(card->data.ccwdev, 0))
2064 napi_schedule(&card->napi);
2065 out:
2066 if (card->options.performance_stats)
2067 card->perf_stats.inbound_time += qeth_get_micros() -
2068 card->perf_stats.inbound_start_time;
2069 return work_done;
2072 static int qeth_l3_verify_vlan_dev(struct net_device *dev,
2073 struct qeth_card *card)
2075 int rc = 0;
2076 u16 vid;
2078 for_each_set_bit(vid, card->active_vlans, VLAN_N_VID) {
2079 struct net_device *netdev;
2081 rcu_read_lock();
2082 netdev = __vlan_find_dev_deep(card->dev, vid);
2083 rcu_read_unlock();
2084 if (netdev == dev) {
2085 rc = QETH_VLAN_CARD;
2086 break;
2090 if (rc && !(vlan_dev_real_dev(dev)->ml_priv == (void *)card))
2091 return 0;
2093 return rc;
2096 static int qeth_l3_verify_dev(struct net_device *dev)
2098 struct qeth_card *card;
2099 unsigned long flags;
2100 int rc = 0;
2102 read_lock_irqsave(&qeth_core_card_list.rwlock, flags);
2103 list_for_each_entry(card, &qeth_core_card_list.list, list) {
2104 if (card->dev == dev) {
2105 rc = QETH_REAL_CARD;
2106 break;
2108 rc = qeth_l3_verify_vlan_dev(dev, card);
2109 if (rc)
2110 break;
2112 read_unlock_irqrestore(&qeth_core_card_list.rwlock, flags);
2114 return rc;
2117 static struct qeth_card *qeth_l3_get_card_from_dev(struct net_device *dev)
2119 struct qeth_card *card = NULL;
2120 int rc;
2122 rc = qeth_l3_verify_dev(dev);
2123 if (rc == QETH_REAL_CARD)
2124 card = dev->ml_priv;
2125 else if (rc == QETH_VLAN_CARD)
2126 card = vlan_dev_real_dev(dev)->ml_priv;
2127 if (card && card->options.layer2)
2128 card = NULL;
2129 if (card)
2130 QETH_CARD_TEXT_(card, 4, "%d", rc);
2131 return card ;
2134 static int qeth_l3_stop_card(struct qeth_card *card, int recovery_mode)
2136 int rc = 0;
2138 QETH_DBF_TEXT(SETUP, 2, "stopcard");
2139 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
2141 qeth_set_allowed_threads(card, 0, 1);
2142 if (card->options.sniffer &&
2143 (card->info.promisc_mode == SET_PROMISC_MODE_ON))
2144 qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_DISABLE);
2145 if (card->read.state == CH_STATE_UP &&
2146 card->write.state == CH_STATE_UP &&
2147 (card->state == CARD_STATE_UP)) {
2148 if (recovery_mode)
2149 qeth_l3_stop(card->dev);
2150 else {
2151 rtnl_lock();
2152 dev_close(card->dev);
2153 rtnl_unlock();
2155 card->state = CARD_STATE_SOFTSETUP;
2157 if (card->state == CARD_STATE_SOFTSETUP) {
2158 qeth_l3_clear_ip_list(card, 1);
2159 qeth_clear_ipacmd_list(card);
2160 card->state = CARD_STATE_HARDSETUP;
2162 if (card->state == CARD_STATE_HARDSETUP) {
2163 qeth_qdio_clear_card(card, 0);
2164 qeth_clear_qdio_buffers(card);
2165 qeth_clear_working_pool_list(card);
2166 card->state = CARD_STATE_DOWN;
2168 if (card->state == CARD_STATE_DOWN) {
2169 qeth_clear_cmd_buffers(&card->read);
2170 qeth_clear_cmd_buffers(&card->write);
2172 return rc;
2176 * test for and Switch promiscuous mode (on or off)
2177 * either for guestlan or HiperSocket Sniffer
2179 static void
2180 qeth_l3_handle_promisc_mode(struct qeth_card *card)
2182 struct net_device *dev = card->dev;
2184 if (((dev->flags & IFF_PROMISC) &&
2185 (card->info.promisc_mode == SET_PROMISC_MODE_ON)) ||
2186 (!(dev->flags & IFF_PROMISC) &&
2187 (card->info.promisc_mode == SET_PROMISC_MODE_OFF)))
2188 return;
2190 if (card->info.guestlan) { /* Guestlan trace */
2191 if (qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
2192 qeth_setadp_promisc_mode(card);
2193 } else if (card->options.sniffer && /* HiperSockets trace */
2194 qeth_adp_supported(card, IPA_SETADP_SET_DIAG_ASSIST)) {
2195 if (dev->flags & IFF_PROMISC) {
2196 QETH_CARD_TEXT(card, 3, "+promisc");
2197 qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_ENABLE);
2198 } else {
2199 QETH_CARD_TEXT(card, 3, "-promisc");
2200 qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_DISABLE);
2205 static void qeth_l3_set_multicast_list(struct net_device *dev)
2207 struct qeth_card *card = dev->ml_priv;
2209 QETH_CARD_TEXT(card, 3, "setmulti");
2210 if (qeth_threads_running(card, QETH_RECOVER_THREAD) &&
2211 (card->state != CARD_STATE_UP))
2212 return;
2213 if (!card->options.sniffer) {
2214 qeth_l3_delete_mc_addresses(card);
2215 qeth_l3_add_multicast_ipv4(card);
2216 #ifdef CONFIG_QETH_IPV6
2217 qeth_l3_add_multicast_ipv6(card);
2218 #endif
2219 qeth_l3_set_ip_addr_list(card);
2220 if (!qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
2221 return;
2223 qeth_l3_handle_promisc_mode(card);
2226 static const char *qeth_l3_arp_get_error_cause(int *rc)
2228 switch (*rc) {
2229 case QETH_IPA_ARP_RC_FAILED:
2230 *rc = -EIO;
2231 return "operation failed";
2232 case QETH_IPA_ARP_RC_NOTSUPP:
2233 *rc = -EOPNOTSUPP;
2234 return "operation not supported";
2235 case QETH_IPA_ARP_RC_OUT_OF_RANGE:
2236 *rc = -EINVAL;
2237 return "argument out of range";
2238 case QETH_IPA_ARP_RC_Q_NOTSUPP:
2239 *rc = -EOPNOTSUPP;
2240 return "query operation not supported";
2241 case QETH_IPA_ARP_RC_Q_NO_DATA:
2242 *rc = -ENOENT;
2243 return "no query data available";
2244 default:
2245 return "unknown error";
2249 static int qeth_l3_arp_set_no_entries(struct qeth_card *card, int no_entries)
2251 int tmp;
2252 int rc;
2254 QETH_CARD_TEXT(card, 3, "arpstnoe");
2257 * currently GuestLAN only supports the ARP assist function
2258 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_SET_NO_ENTRIES;
2259 * thus we say EOPNOTSUPP for this ARP function
2261 if (card->info.guestlan)
2262 return -EOPNOTSUPP;
2263 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
2264 return -EOPNOTSUPP;
2266 rc = qeth_l3_send_simple_setassparms(card, IPA_ARP_PROCESSING,
2267 IPA_CMD_ASS_ARP_SET_NO_ENTRIES,
2268 no_entries);
2269 if (rc) {
2270 tmp = rc;
2271 QETH_DBF_MESSAGE(2, "Could not set number of ARP entries on "
2272 "%s: %s (0x%x/%d)\n", QETH_CARD_IFNAME(card),
2273 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
2275 return rc;
2278 static __u32 get_arp_entry_size(struct qeth_card *card,
2279 struct qeth_arp_query_data *qdata,
2280 struct qeth_arp_entrytype *type, __u8 strip_entries)
2282 __u32 rc;
2283 __u8 is_hsi;
2285 is_hsi = qdata->reply_bits == 5;
2286 if (type->ip == QETHARP_IP_ADDR_V4) {
2287 QETH_CARD_TEXT(card, 4, "arpev4");
2288 if (strip_entries) {
2289 rc = is_hsi ? sizeof(struct qeth_arp_qi_entry5_short) :
2290 sizeof(struct qeth_arp_qi_entry7_short);
2291 } else {
2292 rc = is_hsi ? sizeof(struct qeth_arp_qi_entry5) :
2293 sizeof(struct qeth_arp_qi_entry7);
2295 } else if (type->ip == QETHARP_IP_ADDR_V6) {
2296 QETH_CARD_TEXT(card, 4, "arpev6");
2297 if (strip_entries) {
2298 rc = is_hsi ?
2299 sizeof(struct qeth_arp_qi_entry5_short_ipv6) :
2300 sizeof(struct qeth_arp_qi_entry7_short_ipv6);
2301 } else {
2302 rc = is_hsi ?
2303 sizeof(struct qeth_arp_qi_entry5_ipv6) :
2304 sizeof(struct qeth_arp_qi_entry7_ipv6);
2306 } else {
2307 QETH_CARD_TEXT(card, 4, "arpinv");
2308 rc = 0;
2311 return rc;
2314 static int arpentry_matches_prot(struct qeth_arp_entrytype *type, __u16 prot)
2316 return (type->ip == QETHARP_IP_ADDR_V4 && prot == QETH_PROT_IPV4) ||
2317 (type->ip == QETHARP_IP_ADDR_V6 && prot == QETH_PROT_IPV6);
2320 static int qeth_l3_arp_query_cb(struct qeth_card *card,
2321 struct qeth_reply *reply, unsigned long data)
2323 struct qeth_ipa_cmd *cmd;
2324 struct qeth_arp_query_data *qdata;
2325 struct qeth_arp_query_info *qinfo;
2326 int i;
2327 int e;
2328 int entrybytes_done;
2329 int stripped_bytes;
2330 __u8 do_strip_entries;
2332 QETH_CARD_TEXT(card, 3, "arpquecb");
2334 qinfo = (struct qeth_arp_query_info *) reply->param;
2335 cmd = (struct qeth_ipa_cmd *) data;
2336 QETH_CARD_TEXT_(card, 4, "%i", cmd->hdr.prot_version);
2337 if (cmd->hdr.return_code) {
2338 QETH_CARD_TEXT(card, 4, "arpcberr");
2339 QETH_CARD_TEXT_(card, 4, "%i", cmd->hdr.return_code);
2340 return 0;
2342 if (cmd->data.setassparms.hdr.return_code) {
2343 cmd->hdr.return_code = cmd->data.setassparms.hdr.return_code;
2344 QETH_CARD_TEXT(card, 4, "setaperr");
2345 QETH_CARD_TEXT_(card, 4, "%i", cmd->hdr.return_code);
2346 return 0;
2348 qdata = &cmd->data.setassparms.data.query_arp;
2349 QETH_CARD_TEXT_(card, 4, "anoen%i", qdata->no_entries);
2351 do_strip_entries = (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES) > 0;
2352 stripped_bytes = do_strip_entries ? QETH_QARP_MEDIASPECIFIC_BYTES : 0;
2353 entrybytes_done = 0;
2354 for (e = 0; e < qdata->no_entries; ++e) {
2355 char *cur_entry;
2356 __u32 esize;
2357 struct qeth_arp_entrytype *etype;
2359 cur_entry = &qdata->data + entrybytes_done;
2360 etype = &((struct qeth_arp_qi_entry5 *) cur_entry)->type;
2361 if (!arpentry_matches_prot(etype, cmd->hdr.prot_version)) {
2362 QETH_CARD_TEXT(card, 4, "pmis");
2363 QETH_CARD_TEXT_(card, 4, "%i", etype->ip);
2364 break;
2366 esize = get_arp_entry_size(card, qdata, etype,
2367 do_strip_entries);
2368 QETH_CARD_TEXT_(card, 5, "esz%i", esize);
2369 if (!esize)
2370 break;
2372 if ((qinfo->udata_len - qinfo->udata_offset) < esize) {
2373 QETH_CARD_TEXT_(card, 4, "qaer3%i", -ENOMEM);
2374 cmd->hdr.return_code = IPA_RC_ENOMEM;
2375 goto out_error;
2378 memcpy(qinfo->udata + qinfo->udata_offset,
2379 &qdata->data + entrybytes_done + stripped_bytes,
2380 esize);
2381 entrybytes_done += esize + stripped_bytes;
2382 qinfo->udata_offset += esize;
2383 ++qinfo->no_entries;
2385 /* check if all replies received ... */
2386 if (cmd->data.setassparms.hdr.seq_no <
2387 cmd->data.setassparms.hdr.number_of_replies)
2388 return 1;
2389 QETH_CARD_TEXT_(card, 4, "nove%i", qinfo->no_entries);
2390 memcpy(qinfo->udata, &qinfo->no_entries, 4);
2391 /* keep STRIP_ENTRIES flag so the user program can distinguish
2392 * stripped entries from normal ones */
2393 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES)
2394 qdata->reply_bits |= QETH_QARP_STRIP_ENTRIES;
2395 memcpy(qinfo->udata + QETH_QARP_MASK_OFFSET, &qdata->reply_bits, 2);
2396 QETH_CARD_TEXT_(card, 4, "rc%i", 0);
2397 return 0;
2398 out_error:
2399 i = 0;
2400 memcpy(qinfo->udata, &i, 4);
2401 return 0;
2404 static int qeth_l3_send_ipa_arp_cmd(struct qeth_card *card,
2405 struct qeth_cmd_buffer *iob, int len,
2406 int (*reply_cb)(struct qeth_card *, struct qeth_reply *,
2407 unsigned long),
2408 void *reply_param)
2410 QETH_CARD_TEXT(card, 4, "sendarp");
2412 memcpy(iob->data, IPA_PDU_HEADER, IPA_PDU_HEADER_SIZE);
2413 memcpy(QETH_IPA_CMD_DEST_ADDR(iob->data),
2414 &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
2415 return qeth_send_control_data(card, IPA_PDU_HEADER_SIZE + len, iob,
2416 reply_cb, reply_param);
2419 static int qeth_l3_query_arp_cache_info(struct qeth_card *card,
2420 enum qeth_prot_versions prot,
2421 struct qeth_arp_query_info *qinfo)
2423 struct qeth_cmd_buffer *iob;
2424 struct qeth_ipa_cmd *cmd;
2425 int tmp;
2426 int rc;
2428 QETH_CARD_TEXT_(card, 3, "qarpipv%i", prot);
2430 iob = qeth_l3_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
2431 IPA_CMD_ASS_ARP_QUERY_INFO,
2432 sizeof(struct qeth_arp_query_data) - sizeof(char),
2433 prot);
2434 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
2435 cmd->data.setassparms.data.query_arp.request_bits = 0x000F;
2436 cmd->data.setassparms.data.query_arp.reply_bits = 0;
2437 cmd->data.setassparms.data.query_arp.no_entries = 0;
2438 rc = qeth_l3_send_ipa_arp_cmd(card, iob,
2439 QETH_SETASS_BASE_LEN+QETH_ARP_CMD_LEN,
2440 qeth_l3_arp_query_cb, (void *)qinfo);
2441 if (rc) {
2442 tmp = rc;
2443 QETH_DBF_MESSAGE(2,
2444 "Error while querying ARP cache on %s: %s "
2445 "(0x%x/%d)\n", QETH_CARD_IFNAME(card),
2446 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
2449 return rc;
2452 static int qeth_l3_arp_query(struct qeth_card *card, char __user *udata)
2454 struct qeth_arp_query_info qinfo = {0, };
2455 int rc;
2457 QETH_CARD_TEXT(card, 3, "arpquery");
2459 if (!qeth_is_supported(card,/*IPA_QUERY_ARP_ADDR_INFO*/
2460 IPA_ARP_PROCESSING)) {
2461 QETH_CARD_TEXT(card, 3, "arpqnsup");
2462 rc = -EOPNOTSUPP;
2463 goto out;
2465 /* get size of userspace buffer and mask_bits -> 6 bytes */
2466 if (copy_from_user(&qinfo, udata, 6)) {
2467 rc = -EFAULT;
2468 goto out;
2470 qinfo.udata = kzalloc(qinfo.udata_len, GFP_KERNEL);
2471 if (!qinfo.udata) {
2472 rc = -ENOMEM;
2473 goto out;
2475 qinfo.udata_offset = QETH_QARP_ENTRIES_OFFSET;
2476 rc = qeth_l3_query_arp_cache_info(card, QETH_PROT_IPV4, &qinfo);
2477 if (rc) {
2478 if (copy_to_user(udata, qinfo.udata, 4))
2479 rc = -EFAULT;
2480 goto free_and_out;
2481 } else {
2482 #ifdef CONFIG_QETH_IPV6
2483 if (qinfo.mask_bits & QETH_QARP_WITH_IPV6) {
2484 /* fails in case of GuestLAN QDIO mode */
2485 qeth_l3_query_arp_cache_info(card, QETH_PROT_IPV6,
2486 &qinfo);
2488 #endif
2489 if (copy_to_user(udata, qinfo.udata, qinfo.udata_len)) {
2490 QETH_CARD_TEXT(card, 4, "qactf");
2491 rc = -EFAULT;
2492 goto free_and_out;
2494 QETH_CARD_TEXT_(card, 4, "qacts");
2496 free_and_out:
2497 kfree(qinfo.udata);
2498 out:
2499 return rc;
2502 static int qeth_l3_arp_add_entry(struct qeth_card *card,
2503 struct qeth_arp_cache_entry *entry)
2505 struct qeth_cmd_buffer *iob;
2506 char buf[16];
2507 int tmp;
2508 int rc;
2510 QETH_CARD_TEXT(card, 3, "arpadent");
2513 * currently GuestLAN only supports the ARP assist function
2514 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_ADD_ENTRY;
2515 * thus we say EOPNOTSUPP for this ARP function
2517 if (card->info.guestlan)
2518 return -EOPNOTSUPP;
2519 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
2520 return -EOPNOTSUPP;
2523 iob = qeth_l3_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
2524 IPA_CMD_ASS_ARP_ADD_ENTRY,
2525 sizeof(struct qeth_arp_cache_entry),
2526 QETH_PROT_IPV4);
2527 rc = qeth_l3_send_setassparms(card, iob,
2528 sizeof(struct qeth_arp_cache_entry),
2529 (unsigned long) entry,
2530 qeth_l3_default_setassparms_cb, NULL);
2531 if (rc) {
2532 tmp = rc;
2533 qeth_l3_ipaddr4_to_string((u8 *)entry->ipaddr, buf);
2534 QETH_DBF_MESSAGE(2, "Could not add ARP entry for address %s "
2535 "on %s: %s (0x%x/%d)\n", buf, QETH_CARD_IFNAME(card),
2536 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
2538 return rc;
2541 static int qeth_l3_arp_remove_entry(struct qeth_card *card,
2542 struct qeth_arp_cache_entry *entry)
2544 struct qeth_cmd_buffer *iob;
2545 char buf[16] = {0, };
2546 int tmp;
2547 int rc;
2549 QETH_CARD_TEXT(card, 3, "arprment");
2552 * currently GuestLAN only supports the ARP assist function
2553 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_REMOVE_ENTRY;
2554 * thus we say EOPNOTSUPP for this ARP function
2556 if (card->info.guestlan)
2557 return -EOPNOTSUPP;
2558 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
2559 return -EOPNOTSUPP;
2561 memcpy(buf, entry, 12);
2562 iob = qeth_l3_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
2563 IPA_CMD_ASS_ARP_REMOVE_ENTRY,
2565 QETH_PROT_IPV4);
2566 rc = qeth_l3_send_setassparms(card, iob,
2567 12, (unsigned long)buf,
2568 qeth_l3_default_setassparms_cb, NULL);
2569 if (rc) {
2570 tmp = rc;
2571 memset(buf, 0, 16);
2572 qeth_l3_ipaddr4_to_string((u8 *)entry->ipaddr, buf);
2573 QETH_DBF_MESSAGE(2, "Could not delete ARP entry for address %s"
2574 " on %s: %s (0x%x/%d)\n", buf, QETH_CARD_IFNAME(card),
2575 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
2577 return rc;
2580 static int qeth_l3_arp_flush_cache(struct qeth_card *card)
2582 int rc;
2583 int tmp;
2585 QETH_CARD_TEXT(card, 3, "arpflush");
2588 * currently GuestLAN only supports the ARP assist function
2589 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_FLUSH_CACHE;
2590 * thus we say EOPNOTSUPP for this ARP function
2592 if (card->info.guestlan || (card->info.type == QETH_CARD_TYPE_IQD))
2593 return -EOPNOTSUPP;
2594 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
2595 return -EOPNOTSUPP;
2597 rc = qeth_l3_send_simple_setassparms(card, IPA_ARP_PROCESSING,
2598 IPA_CMD_ASS_ARP_FLUSH_CACHE, 0);
2599 if (rc) {
2600 tmp = rc;
2601 QETH_DBF_MESSAGE(2, "Could not flush ARP cache on %s: %s "
2602 "(0x%x/%d)\n", QETH_CARD_IFNAME(card),
2603 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
2605 return rc;
2608 static int qeth_l3_do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
2610 struct qeth_card *card = dev->ml_priv;
2611 struct qeth_arp_cache_entry arp_entry;
2612 struct mii_ioctl_data *mii_data;
2613 int rc = 0;
2615 if (!card)
2616 return -ENODEV;
2618 if ((card->state != CARD_STATE_UP) &&
2619 (card->state != CARD_STATE_SOFTSETUP))
2620 return -ENODEV;
2622 switch (cmd) {
2623 case SIOC_QETH_ARP_SET_NO_ENTRIES:
2624 if (!capable(CAP_NET_ADMIN)) {
2625 rc = -EPERM;
2626 break;
2628 rc = qeth_l3_arp_set_no_entries(card, rq->ifr_ifru.ifru_ivalue);
2629 break;
2630 case SIOC_QETH_ARP_QUERY_INFO:
2631 if (!capable(CAP_NET_ADMIN)) {
2632 rc = -EPERM;
2633 break;
2635 rc = qeth_l3_arp_query(card, rq->ifr_ifru.ifru_data);
2636 break;
2637 case SIOC_QETH_ARP_ADD_ENTRY:
2638 if (!capable(CAP_NET_ADMIN)) {
2639 rc = -EPERM;
2640 break;
2642 if (copy_from_user(&arp_entry, rq->ifr_ifru.ifru_data,
2643 sizeof(struct qeth_arp_cache_entry)))
2644 rc = -EFAULT;
2645 else
2646 rc = qeth_l3_arp_add_entry(card, &arp_entry);
2647 break;
2648 case SIOC_QETH_ARP_REMOVE_ENTRY:
2649 if (!capable(CAP_NET_ADMIN)) {
2650 rc = -EPERM;
2651 break;
2653 if (copy_from_user(&arp_entry, rq->ifr_ifru.ifru_data,
2654 sizeof(struct qeth_arp_cache_entry)))
2655 rc = -EFAULT;
2656 else
2657 rc = qeth_l3_arp_remove_entry(card, &arp_entry);
2658 break;
2659 case SIOC_QETH_ARP_FLUSH_CACHE:
2660 if (!capable(CAP_NET_ADMIN)) {
2661 rc = -EPERM;
2662 break;
2664 rc = qeth_l3_arp_flush_cache(card);
2665 break;
2666 case SIOC_QETH_ADP_SET_SNMP_CONTROL:
2667 rc = qeth_snmp_command(card, rq->ifr_ifru.ifru_data);
2668 break;
2669 case SIOC_QETH_GET_CARD_TYPE:
2670 if ((card->info.type == QETH_CARD_TYPE_OSD ||
2671 card->info.type == QETH_CARD_TYPE_OSX) &&
2672 !card->info.guestlan)
2673 return 1;
2674 return 0;
2675 break;
2676 case SIOCGMIIPHY:
2677 mii_data = if_mii(rq);
2678 mii_data->phy_id = 0;
2679 break;
2680 case SIOCGMIIREG:
2681 mii_data = if_mii(rq);
2682 if (mii_data->phy_id != 0)
2683 rc = -EINVAL;
2684 else
2685 mii_data->val_out = qeth_mdio_read(dev,
2686 mii_data->phy_id,
2687 mii_data->reg_num);
2688 break;
2689 case SIOC_QETH_QUERY_OAT:
2690 rc = qeth_query_oat_command(card, rq->ifr_ifru.ifru_data);
2691 break;
2692 default:
2693 rc = -EOPNOTSUPP;
2695 if (rc)
2696 QETH_CARD_TEXT_(card, 2, "ioce%d", rc);
2697 return rc;
2700 int inline qeth_l3_get_cast_type(struct qeth_card *card, struct sk_buff *skb)
2702 int cast_type = RTN_UNSPEC;
2703 struct neighbour *n = NULL;
2704 struct dst_entry *dst;
2706 rcu_read_lock();
2707 dst = skb_dst(skb);
2708 if (dst)
2709 n = dst_neigh_lookup_skb(dst, skb);
2710 if (n) {
2711 cast_type = n->type;
2712 rcu_read_unlock();
2713 neigh_release(n);
2714 if ((cast_type == RTN_BROADCAST) ||
2715 (cast_type == RTN_MULTICAST) ||
2716 (cast_type == RTN_ANYCAST))
2717 return cast_type;
2718 else
2719 return RTN_UNSPEC;
2721 rcu_read_unlock();
2723 /* try something else */
2724 if (skb->protocol == ETH_P_IPV6)
2725 return (skb_network_header(skb)[24] == 0xff) ?
2726 RTN_MULTICAST : 0;
2727 else if (skb->protocol == ETH_P_IP)
2728 return ((skb_network_header(skb)[16] & 0xf0) == 0xe0) ?
2729 RTN_MULTICAST : 0;
2730 /* ... */
2731 if (!memcmp(skb->data, skb->dev->broadcast, 6))
2732 return RTN_BROADCAST;
2733 else {
2734 u16 hdr_mac;
2736 hdr_mac = *((u16 *)skb->data);
2737 /* tr multicast? */
2738 switch (card->info.link_type) {
2739 case QETH_LINK_TYPE_HSTR:
2740 case QETH_LINK_TYPE_LANE_TR:
2741 if ((hdr_mac == QETH_TR_MAC_NC) ||
2742 (hdr_mac == QETH_TR_MAC_C))
2743 return RTN_MULTICAST;
2744 break;
2745 /* eth or so multicast? */
2746 default:
2747 if ((hdr_mac == QETH_ETH_MAC_V4) ||
2748 (hdr_mac == QETH_ETH_MAC_V6))
2749 return RTN_MULTICAST;
2752 return cast_type;
2755 static void qeth_l3_fill_af_iucv_hdr(struct qeth_card *card,
2756 struct qeth_hdr *hdr, struct sk_buff *skb)
2758 char daddr[16];
2759 struct af_iucv_trans_hdr *iucv_hdr;
2761 skb_pull(skb, 14);
2762 card->dev->header_ops->create(skb, card->dev, 0,
2763 card->dev->dev_addr, card->dev->dev_addr,
2764 card->dev->addr_len);
2765 skb_pull(skb, 14);
2766 iucv_hdr = (struct af_iucv_trans_hdr *)skb->data;
2767 memset(hdr, 0, sizeof(struct qeth_hdr));
2768 hdr->hdr.l3.id = QETH_HEADER_TYPE_LAYER3;
2769 hdr->hdr.l3.ext_flags = 0;
2770 hdr->hdr.l3.length = skb->len;
2771 hdr->hdr.l3.flags = QETH_HDR_IPV6 | QETH_CAST_UNICAST;
2772 memset(daddr, 0, sizeof(daddr));
2773 daddr[0] = 0xfe;
2774 daddr[1] = 0x80;
2775 memcpy(&daddr[8], iucv_hdr->destUserID, 8);
2776 memcpy(hdr->hdr.l3.dest_addr, daddr, 16);
2779 static void qeth_l3_fill_header(struct qeth_card *card, struct qeth_hdr *hdr,
2780 struct sk_buff *skb, int ipv, int cast_type)
2782 struct dst_entry *dst;
2784 memset(hdr, 0, sizeof(struct qeth_hdr));
2785 hdr->hdr.l3.id = QETH_HEADER_TYPE_LAYER3;
2786 hdr->hdr.l3.ext_flags = 0;
2789 * before we're going to overwrite this location with next hop ip.
2790 * v6 uses passthrough, v4 sets the tag in the QDIO header.
2792 if (vlan_tx_tag_present(skb)) {
2793 if ((ipv == 4) || (card->info.type == QETH_CARD_TYPE_IQD))
2794 hdr->hdr.l3.ext_flags = QETH_HDR_EXT_VLAN_FRAME;
2795 else
2796 hdr->hdr.l3.ext_flags = QETH_HDR_EXT_INCLUDE_VLAN_TAG;
2797 hdr->hdr.l3.vlan_id = vlan_tx_tag_get(skb);
2800 hdr->hdr.l3.length = skb->len - sizeof(struct qeth_hdr);
2802 rcu_read_lock();
2803 dst = skb_dst(skb);
2804 if (ipv == 4) {
2805 struct rtable *rt = (struct rtable *) dst;
2806 __be32 *pkey = &ip_hdr(skb)->daddr;
2808 if (rt->rt_gateway)
2809 pkey = &rt->rt_gateway;
2811 /* IPv4 */
2812 hdr->hdr.l3.flags = qeth_l3_get_qeth_hdr_flags4(cast_type);
2813 memset(hdr->hdr.l3.dest_addr, 0, 12);
2814 *((__be32 *) (&hdr->hdr.l3.dest_addr[12])) = *pkey;
2815 } else if (ipv == 6) {
2816 struct rt6_info *rt = (struct rt6_info *) dst;
2817 struct in6_addr *pkey = &ipv6_hdr(skb)->daddr;
2819 if (!ipv6_addr_any(&rt->rt6i_gateway))
2820 pkey = &rt->rt6i_gateway;
2822 /* IPv6 */
2823 hdr->hdr.l3.flags = qeth_l3_get_qeth_hdr_flags6(cast_type);
2824 if (card->info.type == QETH_CARD_TYPE_IQD)
2825 hdr->hdr.l3.flags &= ~QETH_HDR_PASSTHRU;
2826 memcpy(hdr->hdr.l3.dest_addr, pkey, 16);
2827 } else {
2828 if (!memcmp(skb->data + sizeof(struct qeth_hdr),
2829 skb->dev->broadcast, 6)) {
2830 /* broadcast? */
2831 hdr->hdr.l3.flags = QETH_CAST_BROADCAST |
2832 QETH_HDR_PASSTHRU;
2833 } else {
2834 hdr->hdr.l3.flags = (cast_type == RTN_MULTICAST) ?
2835 QETH_CAST_MULTICAST | QETH_HDR_PASSTHRU :
2836 QETH_CAST_UNICAST | QETH_HDR_PASSTHRU;
2839 rcu_read_unlock();
2842 static inline void qeth_l3_hdr_csum(struct qeth_card *card,
2843 struct qeth_hdr *hdr, struct sk_buff *skb)
2845 struct iphdr *iph = ip_hdr(skb);
2847 /* tcph->check contains already the pseudo hdr checksum
2848 * so just set the header flags
2850 if (iph->protocol == IPPROTO_UDP)
2851 hdr->hdr.l3.ext_flags |= QETH_HDR_EXT_UDP;
2852 hdr->hdr.l3.ext_flags |= QETH_HDR_EXT_CSUM_TRANSP_REQ |
2853 QETH_HDR_EXT_CSUM_HDR_REQ;
2854 iph->check = 0;
2855 if (card->options.performance_stats)
2856 card->perf_stats.tx_csum++;
2859 static void qeth_tso_fill_header(struct qeth_card *card,
2860 struct qeth_hdr *qhdr, struct sk_buff *skb)
2862 struct qeth_hdr_tso *hdr = (struct qeth_hdr_tso *)qhdr;
2863 struct tcphdr *tcph = tcp_hdr(skb);
2864 struct iphdr *iph = ip_hdr(skb);
2865 struct ipv6hdr *ip6h = ipv6_hdr(skb);
2867 /*fix header to TSO values ...*/
2868 hdr->hdr.hdr.l3.id = QETH_HEADER_TYPE_TSO;
2869 hdr->hdr.hdr.l3.length = skb->len - sizeof(struct qeth_hdr_tso);
2870 /*set values which are fix for the first approach ...*/
2871 hdr->ext.hdr_tot_len = (__u16) sizeof(struct qeth_hdr_ext_tso);
2872 hdr->ext.imb_hdr_no = 1;
2873 hdr->ext.hdr_type = 1;
2874 hdr->ext.hdr_version = 1;
2875 hdr->ext.hdr_len = 28;
2876 /*insert non-fix values */
2877 hdr->ext.mss = skb_shinfo(skb)->gso_size;
2878 hdr->ext.dg_hdr_len = (__u16)(iph->ihl*4 + tcph->doff*4);
2879 hdr->ext.payload_len = (__u16)(skb->len - hdr->ext.dg_hdr_len -
2880 sizeof(struct qeth_hdr_tso));
2881 tcph->check = 0;
2882 if (skb->protocol == ETH_P_IPV6) {
2883 ip6h->payload_len = 0;
2884 tcph->check = ~csum_ipv6_magic(&ip6h->saddr, &ip6h->daddr,
2885 0, IPPROTO_TCP, 0);
2886 } else {
2887 /*OSA want us to set these values ...*/
2888 tcph->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr,
2889 0, IPPROTO_TCP, 0);
2890 iph->tot_len = 0;
2891 iph->check = 0;
2895 static inline int qeth_l3_tso_elements(struct sk_buff *skb)
2897 unsigned long tcpd = (unsigned long)tcp_hdr(skb) +
2898 tcp_hdr(skb)->doff * 4;
2899 int tcpd_len = skb->len - (tcpd - (unsigned long)skb->data);
2900 int elements = PFN_UP(tcpd + tcpd_len - 1) - PFN_DOWN(tcpd);
2901 elements += skb_shinfo(skb)->nr_frags;
2902 return elements;
2905 static int qeth_l3_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
2907 int rc;
2908 u16 *tag;
2909 struct qeth_hdr *hdr = NULL;
2910 int elements_needed = 0;
2911 int elems;
2912 struct qeth_card *card = dev->ml_priv;
2913 struct sk_buff *new_skb = NULL;
2914 int ipv = qeth_get_ip_version(skb);
2915 int cast_type = qeth_l3_get_cast_type(card, skb);
2916 struct qeth_qdio_out_q *queue = card->qdio.out_qs
2917 [qeth_get_priority_queue(card, skb, ipv, cast_type)];
2918 int tx_bytes = skb->len;
2919 bool large_send;
2920 int data_offset = -1;
2921 int nr_frags;
2923 if (((card->info.type == QETH_CARD_TYPE_IQD) &&
2924 (((card->options.cq != QETH_CQ_ENABLED) && !ipv) ||
2925 ((card->options.cq == QETH_CQ_ENABLED) &&
2926 (skb->protocol != ETH_P_AF_IUCV)))) ||
2927 card->options.sniffer)
2928 goto tx_drop;
2930 if ((card->state != CARD_STATE_UP) || !card->lan_online) {
2931 card->stats.tx_carrier_errors++;
2932 goto tx_drop;
2935 if ((cast_type == RTN_BROADCAST) &&
2936 (card->info.broadcast_capable == 0))
2937 goto tx_drop;
2939 if (card->options.performance_stats) {
2940 card->perf_stats.outbound_cnt++;
2941 card->perf_stats.outbound_start_time = qeth_get_micros();
2944 large_send = skb_is_gso(skb);
2946 if ((card->info.type == QETH_CARD_TYPE_IQD) && (!large_send) &&
2947 (skb_shinfo(skb)->nr_frags == 0)) {
2948 new_skb = skb;
2949 if (new_skb->protocol == ETH_P_AF_IUCV)
2950 data_offset = 0;
2951 else
2952 data_offset = ETH_HLEN;
2953 hdr = kmem_cache_alloc(qeth_core_header_cache, GFP_ATOMIC);
2954 if (!hdr)
2955 goto tx_drop;
2956 elements_needed++;
2957 } else {
2958 /* create a clone with writeable headroom */
2959 new_skb = skb_realloc_headroom(skb, sizeof(struct qeth_hdr_tso)
2960 + VLAN_HLEN);
2961 if (!new_skb)
2962 goto tx_drop;
2965 if (card->info.type == QETH_CARD_TYPE_IQD) {
2966 if (data_offset < 0)
2967 skb_pull(new_skb, ETH_HLEN);
2968 } else {
2969 if (ipv == 4) {
2970 skb_pull(new_skb, ETH_HLEN);
2973 if (ipv != 4 && vlan_tx_tag_present(new_skb)) {
2974 skb_push(new_skb, VLAN_HLEN);
2975 skb_copy_to_linear_data(new_skb, new_skb->data + 4, 4);
2976 skb_copy_to_linear_data_offset(new_skb, 4,
2977 new_skb->data + 8, 4);
2978 skb_copy_to_linear_data_offset(new_skb, 8,
2979 new_skb->data + 12, 4);
2980 tag = (u16 *)(new_skb->data + 12);
2981 *tag = __constant_htons(ETH_P_8021Q);
2982 *(tag + 1) = htons(vlan_tx_tag_get(new_skb));
2986 netif_stop_queue(dev);
2988 /* fix hardware limitation: as long as we do not have sbal
2989 * chaining we can not send long frag lists
2991 if (large_send) {
2992 if (qeth_l3_tso_elements(new_skb) + 1 > 16) {
2993 if (skb_linearize(new_skb))
2994 goto tx_drop;
2995 if (card->options.performance_stats)
2996 card->perf_stats.tx_lin++;
3000 if (large_send && (cast_type == RTN_UNSPEC)) {
3001 hdr = (struct qeth_hdr *)skb_push(new_skb,
3002 sizeof(struct qeth_hdr_tso));
3003 memset(hdr, 0, sizeof(struct qeth_hdr_tso));
3004 qeth_l3_fill_header(card, hdr, new_skb, ipv, cast_type);
3005 qeth_tso_fill_header(card, hdr, new_skb);
3006 elements_needed++;
3007 } else {
3008 if (data_offset < 0) {
3009 hdr = (struct qeth_hdr *)skb_push(new_skb,
3010 sizeof(struct qeth_hdr));
3011 qeth_l3_fill_header(card, hdr, new_skb, ipv,
3012 cast_type);
3013 } else {
3014 if (new_skb->protocol == ETH_P_AF_IUCV)
3015 qeth_l3_fill_af_iucv_hdr(card, hdr, new_skb);
3016 else {
3017 qeth_l3_fill_header(card, hdr, new_skb, ipv,
3018 cast_type);
3019 hdr->hdr.l3.length = new_skb->len - data_offset;
3023 if (skb->ip_summed == CHECKSUM_PARTIAL)
3024 qeth_l3_hdr_csum(card, hdr, new_skb);
3027 elems = qeth_get_elements_no(card, (void *)hdr, new_skb,
3028 elements_needed);
3029 if (!elems) {
3030 if (data_offset >= 0)
3031 kmem_cache_free(qeth_core_header_cache, hdr);
3032 goto tx_drop;
3034 elements_needed += elems;
3035 nr_frags = skb_shinfo(new_skb)->nr_frags;
3037 if (card->info.type != QETH_CARD_TYPE_IQD) {
3038 int len;
3039 if (large_send)
3040 len = ((unsigned long)tcp_hdr(new_skb) +
3041 tcp_hdr(new_skb)->doff * 4) -
3042 (unsigned long)new_skb->data;
3043 else
3044 len = sizeof(struct qeth_hdr_layer3);
3046 if (qeth_hdr_chk_and_bounce(new_skb, len))
3047 goto tx_drop;
3048 rc = qeth_do_send_packet(card, queue, new_skb, hdr,
3049 elements_needed);
3050 } else
3051 rc = qeth_do_send_packet_fast(card, queue, new_skb, hdr,
3052 elements_needed, data_offset, 0);
3054 if (!rc) {
3055 card->stats.tx_packets++;
3056 card->stats.tx_bytes += tx_bytes;
3057 if (new_skb != skb)
3058 dev_kfree_skb_any(skb);
3059 if (card->options.performance_stats) {
3060 if (large_send) {
3061 card->perf_stats.large_send_bytes += tx_bytes;
3062 card->perf_stats.large_send_cnt++;
3064 if (nr_frags) {
3065 card->perf_stats.sg_skbs_sent++;
3066 /* nr_frags + skb->data */
3067 card->perf_stats.sg_frags_sent += nr_frags + 1;
3070 rc = NETDEV_TX_OK;
3071 } else {
3072 if (data_offset >= 0)
3073 kmem_cache_free(qeth_core_header_cache, hdr);
3075 if (rc == -EBUSY) {
3076 if (new_skb != skb)
3077 dev_kfree_skb_any(new_skb);
3078 return NETDEV_TX_BUSY;
3079 } else
3080 goto tx_drop;
3083 netif_wake_queue(dev);
3084 if (card->options.performance_stats)
3085 card->perf_stats.outbound_time += qeth_get_micros() -
3086 card->perf_stats.outbound_start_time;
3087 return rc;
3089 tx_drop:
3090 card->stats.tx_dropped++;
3091 card->stats.tx_errors++;
3092 if ((new_skb != skb) && new_skb)
3093 dev_kfree_skb_any(new_skb);
3094 dev_kfree_skb_any(skb);
3095 netif_wake_queue(dev);
3096 return NETDEV_TX_OK;
3099 static int __qeth_l3_open(struct net_device *dev)
3101 struct qeth_card *card = dev->ml_priv;
3102 int rc = 0;
3104 QETH_CARD_TEXT(card, 4, "qethopen");
3105 if (card->state == CARD_STATE_UP)
3106 return rc;
3107 if (card->state != CARD_STATE_SOFTSETUP)
3108 return -ENODEV;
3109 card->data.state = CH_STATE_UP;
3110 card->state = CARD_STATE_UP;
3111 netif_start_queue(dev);
3113 if (qdio_stop_irq(card->data.ccwdev, 0) >= 0) {
3114 napi_enable(&card->napi);
3115 napi_schedule(&card->napi);
3116 } else
3117 rc = -EIO;
3118 return rc;
3121 static int qeth_l3_open(struct net_device *dev)
3123 struct qeth_card *card = dev->ml_priv;
3125 QETH_CARD_TEXT(card, 5, "qethope_");
3126 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
3127 QETH_CARD_TEXT(card, 3, "openREC");
3128 return -ERESTARTSYS;
3130 return __qeth_l3_open(dev);
3133 static int qeth_l3_stop(struct net_device *dev)
3135 struct qeth_card *card = dev->ml_priv;
3137 QETH_CARD_TEXT(card, 4, "qethstop");
3138 netif_tx_disable(dev);
3139 if (card->state == CARD_STATE_UP) {
3140 card->state = CARD_STATE_SOFTSETUP;
3141 napi_disable(&card->napi);
3143 return 0;
3146 static netdev_features_t qeth_l3_fix_features(struct net_device *dev,
3147 netdev_features_t features)
3149 struct qeth_card *card = dev->ml_priv;
3151 if (!qeth_is_supported(card, IPA_OUTBOUND_CHECKSUM))
3152 features &= ~NETIF_F_IP_CSUM;
3153 if (!qeth_is_supported(card, IPA_OUTBOUND_TSO))
3154 features &= ~NETIF_F_TSO;
3155 if (!qeth_is_supported(card, IPA_INBOUND_CHECKSUM))
3156 features &= ~NETIF_F_RXCSUM;
3158 return features;
3161 static int qeth_l3_set_features(struct net_device *dev,
3162 netdev_features_t features)
3164 struct qeth_card *card = dev->ml_priv;
3165 u32 changed = dev->features ^ features;
3166 int err;
3168 if (!(changed & NETIF_F_RXCSUM))
3169 return 0;
3171 if (card->state == CARD_STATE_DOWN ||
3172 card->state == CARD_STATE_RECOVER)
3173 return 0;
3175 err = qeth_l3_set_rx_csum(card, features & NETIF_F_RXCSUM);
3176 if (err)
3177 dev->features = features ^ NETIF_F_RXCSUM;
3179 return err;
3182 static const struct ethtool_ops qeth_l3_ethtool_ops = {
3183 .get_link = ethtool_op_get_link,
3184 .get_strings = qeth_core_get_strings,
3185 .get_ethtool_stats = qeth_core_get_ethtool_stats,
3186 .get_sset_count = qeth_core_get_sset_count,
3187 .get_drvinfo = qeth_core_get_drvinfo,
3188 .get_settings = qeth_core_ethtool_get_settings,
3192 * we need NOARP for IPv4 but we want neighbor solicitation for IPv6. Setting
3193 * NOARP on the netdevice is no option because it also turns off neighbor
3194 * solicitation. For IPv4 we install a neighbor_setup function. We don't want
3195 * arp resolution but we want the hard header (packet socket will work
3196 * e.g. tcpdump)
3198 static int qeth_l3_neigh_setup_noarp(struct neighbour *n)
3200 n->nud_state = NUD_NOARP;
3201 memcpy(n->ha, "FAKELL", 6);
3202 n->output = n->ops->connected_output;
3203 return 0;
3206 static int
3207 qeth_l3_neigh_setup(struct net_device *dev, struct neigh_parms *np)
3209 if (np->tbl->family == AF_INET)
3210 np->neigh_setup = qeth_l3_neigh_setup_noarp;
3212 return 0;
3215 static const struct net_device_ops qeth_l3_netdev_ops = {
3216 .ndo_open = qeth_l3_open,
3217 .ndo_stop = qeth_l3_stop,
3218 .ndo_get_stats = qeth_get_stats,
3219 .ndo_start_xmit = qeth_l3_hard_start_xmit,
3220 .ndo_validate_addr = eth_validate_addr,
3221 .ndo_set_rx_mode = qeth_l3_set_multicast_list,
3222 .ndo_do_ioctl = qeth_l3_do_ioctl,
3223 .ndo_change_mtu = qeth_change_mtu,
3224 .ndo_fix_features = qeth_l3_fix_features,
3225 .ndo_set_features = qeth_l3_set_features,
3226 .ndo_vlan_rx_add_vid = qeth_l3_vlan_rx_add_vid,
3227 .ndo_vlan_rx_kill_vid = qeth_l3_vlan_rx_kill_vid,
3228 .ndo_tx_timeout = qeth_tx_timeout,
3231 static const struct net_device_ops qeth_l3_osa_netdev_ops = {
3232 .ndo_open = qeth_l3_open,
3233 .ndo_stop = qeth_l3_stop,
3234 .ndo_get_stats = qeth_get_stats,
3235 .ndo_start_xmit = qeth_l3_hard_start_xmit,
3236 .ndo_validate_addr = eth_validate_addr,
3237 .ndo_set_rx_mode = qeth_l3_set_multicast_list,
3238 .ndo_do_ioctl = qeth_l3_do_ioctl,
3239 .ndo_change_mtu = qeth_change_mtu,
3240 .ndo_fix_features = qeth_l3_fix_features,
3241 .ndo_set_features = qeth_l3_set_features,
3242 .ndo_vlan_rx_add_vid = qeth_l3_vlan_rx_add_vid,
3243 .ndo_vlan_rx_kill_vid = qeth_l3_vlan_rx_kill_vid,
3244 .ndo_tx_timeout = qeth_tx_timeout,
3245 .ndo_neigh_setup = qeth_l3_neigh_setup,
3248 static int qeth_l3_setup_netdev(struct qeth_card *card)
3250 if (card->info.type == QETH_CARD_TYPE_OSD ||
3251 card->info.type == QETH_CARD_TYPE_OSX) {
3252 if ((card->info.link_type == QETH_LINK_TYPE_LANE_TR) ||
3253 (card->info.link_type == QETH_LINK_TYPE_HSTR)) {
3254 pr_info("qeth_l3: ignoring TR device\n");
3255 return -ENODEV;
3256 } else {
3257 card->dev = alloc_etherdev(0);
3258 if (!card->dev)
3259 return -ENODEV;
3260 card->dev->netdev_ops = &qeth_l3_osa_netdev_ops;
3262 /*IPv6 address autoconfiguration stuff*/
3263 qeth_l3_get_unique_id(card);
3264 if (!(card->info.unique_id & UNIQUE_ID_NOT_BY_CARD))
3265 card->dev->dev_id = card->info.unique_id &
3266 0xffff;
3267 if (!card->info.guestlan) {
3268 card->dev->hw_features = NETIF_F_SG |
3269 NETIF_F_RXCSUM | NETIF_F_IP_CSUM |
3270 NETIF_F_TSO;
3271 card->dev->features = NETIF_F_RXCSUM;
3274 } else if (card->info.type == QETH_CARD_TYPE_IQD) {
3275 card->dev = alloc_netdev(0, "hsi%d", ether_setup);
3276 if (!card->dev)
3277 return -ENODEV;
3278 card->dev->flags |= IFF_NOARP;
3279 card->dev->netdev_ops = &qeth_l3_netdev_ops;
3280 qeth_l3_iqd_read_initial_mac(card);
3281 if (card->options.hsuid[0])
3282 memcpy(card->dev->perm_addr, card->options.hsuid, 9);
3283 } else
3284 return -ENODEV;
3286 card->dev->ml_priv = card;
3287 card->dev->watchdog_timeo = QETH_TX_TIMEOUT;
3288 card->dev->mtu = card->info.initial_mtu;
3289 SET_ETHTOOL_OPS(card->dev, &qeth_l3_ethtool_ops);
3290 card->dev->features |= NETIF_F_HW_VLAN_TX |
3291 NETIF_F_HW_VLAN_RX |
3292 NETIF_F_HW_VLAN_FILTER;
3293 card->dev->priv_flags &= ~IFF_XMIT_DST_RELEASE;
3294 card->dev->gso_max_size = 15 * PAGE_SIZE;
3296 SET_NETDEV_DEV(card->dev, &card->gdev->dev);
3297 netif_napi_add(card->dev, &card->napi, qeth_l3_poll, QETH_NAPI_WEIGHT);
3298 return register_netdev(card->dev);
3301 static int qeth_l3_probe_device(struct ccwgroup_device *gdev)
3303 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3305 qeth_l3_create_device_attributes(&gdev->dev);
3306 card->options.layer2 = 0;
3307 card->info.hwtrap = 0;
3308 return 0;
3311 static void qeth_l3_remove_device(struct ccwgroup_device *cgdev)
3313 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
3315 qeth_l3_remove_device_attributes(&cgdev->dev);
3317 qeth_set_allowed_threads(card, 0, 1);
3318 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
3320 if (cgdev->state == CCWGROUP_ONLINE)
3321 qeth_l3_set_offline(cgdev);
3323 if (card->dev) {
3324 unregister_netdev(card->dev);
3325 card->dev = NULL;
3328 qeth_l3_clear_ip_list(card, 0);
3329 qeth_l3_clear_ipato_list(card);
3330 return;
3333 static int __qeth_l3_set_online(struct ccwgroup_device *gdev, int recovery_mode)
3335 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3336 int rc = 0;
3337 enum qeth_card_states recover_flag;
3339 mutex_lock(&card->discipline_mutex);
3340 mutex_lock(&card->conf_mutex);
3341 QETH_DBF_TEXT(SETUP, 2, "setonlin");
3342 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
3344 recover_flag = card->state;
3345 rc = qeth_core_hardsetup_card(card);
3346 if (rc) {
3347 QETH_DBF_TEXT_(SETUP, 2, "2err%d", rc);
3348 rc = -ENODEV;
3349 goto out_remove;
3352 if (!card->dev && qeth_l3_setup_netdev(card)) {
3353 rc = -ENODEV;
3354 goto out_remove;
3357 if (qeth_is_diagass_supported(card, QETH_DIAGS_CMD_TRAP)) {
3358 if (card->info.hwtrap &&
3359 qeth_hw_trap(card, QETH_DIAGS_TRAP_ARM))
3360 card->info.hwtrap = 0;
3361 } else
3362 card->info.hwtrap = 0;
3364 card->state = CARD_STATE_HARDSETUP;
3365 memset(&card->rx, 0, sizeof(struct qeth_rx));
3366 qeth_print_status_message(card);
3368 /* softsetup */
3369 QETH_DBF_TEXT(SETUP, 2, "softsetp");
3371 rc = qeth_send_startlan(card);
3372 if (rc) {
3373 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
3374 if (rc == 0xe080) {
3375 dev_warn(&card->gdev->dev,
3376 "The LAN is offline\n");
3377 card->lan_online = 0;
3378 goto contin;
3380 rc = -ENODEV;
3381 goto out_remove;
3382 } else
3383 card->lan_online = 1;
3385 contin:
3386 rc = qeth_l3_setadapter_parms(card);
3387 if (rc)
3388 QETH_DBF_TEXT_(SETUP, 2, "2err%d", rc);
3389 if (!card->options.sniffer) {
3390 rc = qeth_l3_start_ipassists(card);
3391 if (rc) {
3392 QETH_DBF_TEXT_(SETUP, 2, "3err%d", rc);
3393 goto out_remove;
3395 rc = qeth_l3_setrouting_v4(card);
3396 if (rc)
3397 QETH_DBF_TEXT_(SETUP, 2, "4err%d", rc);
3398 rc = qeth_l3_setrouting_v6(card);
3399 if (rc)
3400 QETH_DBF_TEXT_(SETUP, 2, "5err%d", rc);
3402 netif_tx_disable(card->dev);
3404 rc = qeth_init_qdio_queues(card);
3405 if (rc) {
3406 QETH_DBF_TEXT_(SETUP, 2, "6err%d", rc);
3407 rc = -ENODEV;
3408 goto out_remove;
3410 card->state = CARD_STATE_SOFTSETUP;
3412 qeth_set_allowed_threads(card, 0xffffffff, 0);
3413 qeth_l3_set_ip_addr_list(card);
3414 if (card->lan_online)
3415 netif_carrier_on(card->dev);
3416 else
3417 netif_carrier_off(card->dev);
3418 if (recover_flag == CARD_STATE_RECOVER) {
3419 rtnl_lock();
3420 if (recovery_mode)
3421 __qeth_l3_open(card->dev);
3422 else
3423 dev_open(card->dev);
3424 qeth_l3_set_multicast_list(card->dev);
3425 rtnl_unlock();
3427 qeth_trace_features(card);
3428 /* let user_space know that device is online */
3429 kobject_uevent(&gdev->dev.kobj, KOBJ_CHANGE);
3430 mutex_unlock(&card->conf_mutex);
3431 mutex_unlock(&card->discipline_mutex);
3432 return 0;
3433 out_remove:
3434 qeth_l3_stop_card(card, 0);
3435 ccw_device_set_offline(CARD_DDEV(card));
3436 ccw_device_set_offline(CARD_WDEV(card));
3437 ccw_device_set_offline(CARD_RDEV(card));
3438 if (recover_flag == CARD_STATE_RECOVER)
3439 card->state = CARD_STATE_RECOVER;
3440 else
3441 card->state = CARD_STATE_DOWN;
3442 mutex_unlock(&card->conf_mutex);
3443 mutex_unlock(&card->discipline_mutex);
3444 return rc;
3447 static int qeth_l3_set_online(struct ccwgroup_device *gdev)
3449 return __qeth_l3_set_online(gdev, 0);
3452 static int __qeth_l3_set_offline(struct ccwgroup_device *cgdev,
3453 int recovery_mode)
3455 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
3456 int rc = 0, rc2 = 0, rc3 = 0;
3457 enum qeth_card_states recover_flag;
3459 mutex_lock(&card->discipline_mutex);
3460 mutex_lock(&card->conf_mutex);
3461 QETH_DBF_TEXT(SETUP, 3, "setoffl");
3462 QETH_DBF_HEX(SETUP, 3, &card, sizeof(void *));
3464 if (card->dev && netif_carrier_ok(card->dev))
3465 netif_carrier_off(card->dev);
3466 recover_flag = card->state;
3467 if ((!recovery_mode && card->info.hwtrap) || card->info.hwtrap == 2) {
3468 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
3469 card->info.hwtrap = 1;
3471 qeth_l3_stop_card(card, recovery_mode);
3472 if ((card->options.cq == QETH_CQ_ENABLED) && card->dev) {
3473 rtnl_lock();
3474 call_netdevice_notifiers(NETDEV_REBOOT, card->dev);
3475 rtnl_unlock();
3477 rc = ccw_device_set_offline(CARD_DDEV(card));
3478 rc2 = ccw_device_set_offline(CARD_WDEV(card));
3479 rc3 = ccw_device_set_offline(CARD_RDEV(card));
3480 if (!rc)
3481 rc = (rc2) ? rc2 : rc3;
3482 if (rc)
3483 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
3484 if (recover_flag == CARD_STATE_UP)
3485 card->state = CARD_STATE_RECOVER;
3486 /* let user_space know that device is offline */
3487 kobject_uevent(&cgdev->dev.kobj, KOBJ_CHANGE);
3488 mutex_unlock(&card->conf_mutex);
3489 mutex_unlock(&card->discipline_mutex);
3490 return 0;
3493 static int qeth_l3_set_offline(struct ccwgroup_device *cgdev)
3495 return __qeth_l3_set_offline(cgdev, 0);
3498 static int qeth_l3_recover(void *ptr)
3500 struct qeth_card *card;
3501 int rc = 0;
3503 card = (struct qeth_card *) ptr;
3504 QETH_CARD_TEXT(card, 2, "recover1");
3505 QETH_CARD_HEX(card, 2, &card, sizeof(void *));
3506 if (!qeth_do_run_thread(card, QETH_RECOVER_THREAD))
3507 return 0;
3508 QETH_CARD_TEXT(card, 2, "recover2");
3509 dev_warn(&card->gdev->dev,
3510 "A recovery process has been started for the device\n");
3511 __qeth_l3_set_offline(card->gdev, 1);
3512 rc = __qeth_l3_set_online(card->gdev, 1);
3513 if (!rc)
3514 dev_info(&card->gdev->dev,
3515 "Device successfully recovered!\n");
3516 else {
3517 qeth_close_dev(card);
3518 dev_warn(&card->gdev->dev, "The qeth device driver "
3519 "failed to recover an error on the device\n");
3521 qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD);
3522 qeth_clear_thread_running_bit(card, QETH_RECOVER_THREAD);
3523 return 0;
3526 static void qeth_l3_shutdown(struct ccwgroup_device *gdev)
3528 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3529 qeth_set_allowed_threads(card, 0, 1);
3530 if ((gdev->state == CCWGROUP_ONLINE) && card->info.hwtrap)
3531 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
3532 qeth_qdio_clear_card(card, 0);
3533 qeth_clear_qdio_buffers(card);
3536 static int qeth_l3_pm_suspend(struct ccwgroup_device *gdev)
3538 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3540 if (card->dev)
3541 netif_device_detach(card->dev);
3542 qeth_set_allowed_threads(card, 0, 1);
3543 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
3544 if (gdev->state == CCWGROUP_OFFLINE)
3545 return 0;
3546 if (card->state == CARD_STATE_UP) {
3547 if (card->info.hwtrap)
3548 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
3549 __qeth_l3_set_offline(card->gdev, 1);
3550 } else
3551 __qeth_l3_set_offline(card->gdev, 0);
3552 return 0;
3555 static int qeth_l3_pm_resume(struct ccwgroup_device *gdev)
3557 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3558 int rc = 0;
3560 if (gdev->state == CCWGROUP_OFFLINE)
3561 goto out;
3563 if (card->state == CARD_STATE_RECOVER) {
3564 rc = __qeth_l3_set_online(card->gdev, 1);
3565 if (rc) {
3566 rtnl_lock();
3567 dev_close(card->dev);
3568 rtnl_unlock();
3570 } else
3571 rc = __qeth_l3_set_online(card->gdev, 0);
3572 out:
3573 qeth_set_allowed_threads(card, 0xffffffff, 0);
3574 if (card->dev)
3575 netif_device_attach(card->dev);
3576 if (rc)
3577 dev_warn(&card->gdev->dev, "The qeth device driver "
3578 "failed to recover an error on the device\n");
3579 return rc;
3582 struct qeth_discipline qeth_l3_discipline = {
3583 .start_poll = qeth_qdio_start_poll,
3584 .input_handler = (qdio_handler_t *) qeth_qdio_input_handler,
3585 .output_handler = (qdio_handler_t *) qeth_qdio_output_handler,
3586 .recover = qeth_l3_recover,
3587 .setup = qeth_l3_probe_device,
3588 .remove = qeth_l3_remove_device,
3589 .set_online = qeth_l3_set_online,
3590 .set_offline = qeth_l3_set_offline,
3591 .shutdown = qeth_l3_shutdown,
3592 .freeze = qeth_l3_pm_suspend,
3593 .thaw = qeth_l3_pm_resume,
3594 .restore = qeth_l3_pm_resume,
3596 EXPORT_SYMBOL_GPL(qeth_l3_discipline);
3598 static int qeth_l3_ip_event(struct notifier_block *this,
3599 unsigned long event, void *ptr)
3601 struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;
3602 struct net_device *dev = (struct net_device *)ifa->ifa_dev->dev;
3603 struct qeth_ipaddr *addr;
3604 struct qeth_card *card;
3606 if (dev_net(dev) != &init_net)
3607 return NOTIFY_DONE;
3609 card = qeth_l3_get_card_from_dev(dev);
3610 if (!card)
3611 return NOTIFY_DONE;
3612 QETH_CARD_TEXT(card, 3, "ipevent");
3614 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
3615 if (addr != NULL) {
3616 addr->u.a4.addr = ifa->ifa_address;
3617 addr->u.a4.mask = ifa->ifa_mask;
3618 addr->type = QETH_IP_TYPE_NORMAL;
3619 } else
3620 goto out;
3622 switch (event) {
3623 case NETDEV_UP:
3624 if (!qeth_l3_add_ip(card, addr))
3625 kfree(addr);
3626 break;
3627 case NETDEV_DOWN:
3628 if (!qeth_l3_delete_ip(card, addr))
3629 kfree(addr);
3630 break;
3631 default:
3632 break;
3634 qeth_l3_set_ip_addr_list(card);
3635 out:
3636 return NOTIFY_DONE;
3639 static struct notifier_block qeth_l3_ip_notifier = {
3640 qeth_l3_ip_event,
3641 NULL,
3644 #ifdef CONFIG_QETH_IPV6
3646 * IPv6 event handler
3648 static int qeth_l3_ip6_event(struct notifier_block *this,
3649 unsigned long event, void *ptr)
3651 struct inet6_ifaddr *ifa = (struct inet6_ifaddr *)ptr;
3652 struct net_device *dev = (struct net_device *)ifa->idev->dev;
3653 struct qeth_ipaddr *addr;
3654 struct qeth_card *card;
3656 card = qeth_l3_get_card_from_dev(dev);
3657 if (!card)
3658 return NOTIFY_DONE;
3659 QETH_CARD_TEXT(card, 3, "ip6event");
3660 if (!qeth_is_supported(card, IPA_IPV6))
3661 return NOTIFY_DONE;
3663 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
3664 if (addr != NULL) {
3665 memcpy(&addr->u.a6.addr, &ifa->addr, sizeof(struct in6_addr));
3666 addr->u.a6.pfxlen = ifa->prefix_len;
3667 addr->type = QETH_IP_TYPE_NORMAL;
3668 } else
3669 goto out;
3671 switch (event) {
3672 case NETDEV_UP:
3673 if (!qeth_l3_add_ip(card, addr))
3674 kfree(addr);
3675 break;
3676 case NETDEV_DOWN:
3677 if (!qeth_l3_delete_ip(card, addr))
3678 kfree(addr);
3679 break;
3680 default:
3681 break;
3683 qeth_l3_set_ip_addr_list(card);
3684 out:
3685 return NOTIFY_DONE;
3688 static struct notifier_block qeth_l3_ip6_notifier = {
3689 qeth_l3_ip6_event,
3690 NULL,
3692 #endif
3694 static int qeth_l3_register_notifiers(void)
3696 int rc;
3698 QETH_DBF_TEXT(SETUP, 5, "regnotif");
3699 rc = register_inetaddr_notifier(&qeth_l3_ip_notifier);
3700 if (rc)
3701 return rc;
3702 #ifdef CONFIG_QETH_IPV6
3703 rc = register_inet6addr_notifier(&qeth_l3_ip6_notifier);
3704 if (rc) {
3705 unregister_inetaddr_notifier(&qeth_l3_ip_notifier);
3706 return rc;
3708 #else
3709 pr_warning("There is no IPv6 support for the layer 3 discipline\n");
3710 #endif
3711 return 0;
3714 static void qeth_l3_unregister_notifiers(void)
3717 QETH_DBF_TEXT(SETUP, 5, "unregnot");
3718 WARN_ON(unregister_inetaddr_notifier(&qeth_l3_ip_notifier));
3719 #ifdef CONFIG_QETH_IPV6
3720 WARN_ON(unregister_inet6addr_notifier(&qeth_l3_ip6_notifier));
3721 #endif /* QETH_IPV6 */
3724 static int __init qeth_l3_init(void)
3726 int rc = 0;
3728 pr_info("register layer 3 discipline\n");
3729 rc = qeth_l3_register_notifiers();
3730 return rc;
3733 static void __exit qeth_l3_exit(void)
3735 qeth_l3_unregister_notifiers();
3736 pr_info("unregister layer 3 discipline\n");
3739 module_init(qeth_l3_init);
3740 module_exit(qeth_l3_exit);
3741 MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
3742 MODULE_DESCRIPTION("qeth layer 3 discipline");
3743 MODULE_LICENSE("GPL");