1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright IBM Corp. 2007, 2009
4 * Author(s): Utz Bacher <utz.bacher@de.ibm.com>,
5 * Frank Pavlic <fpavlic@de.ibm.com>,
6 * Thomas Spatzier <tspat@de.ibm.com>,
7 * Frank Blaschka <frank.blaschka@de.ibm.com>
10 #define KMSG_COMPONENT "qeth"
11 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
13 #include <linux/module.h>
14 #include <linux/moduleparam.h>
15 #include <linux/bitops.h>
16 #include <linux/string.h>
17 #include <linux/errno.h>
18 #include <linux/kernel.h>
19 #include <linux/etherdevice.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>
29 #include <net/route.h>
30 #include <net/ip6_fib.h>
31 #include <net/ip6_checksum.h>
32 #include <net/iucv/af_iucv.h>
33 #include <linux/hashtable.h>
38 static int qeth_l3_set_offline(struct ccwgroup_device
*);
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_register_addr_entry(struct qeth_card
*,
42 struct qeth_ipaddr
*);
43 static int qeth_l3_deregister_addr_entry(struct qeth_card
*,
44 struct qeth_ipaddr
*);
46 static int qeth_l3_isxdigit(char *buf
)
49 if (!isxdigit(*buf
++))
55 static void qeth_l3_ipaddr4_to_string(const __u8
*addr
, char *buf
)
57 sprintf(buf
, "%pI4", addr
);
60 static int qeth_l3_string_to_ipaddr4(const char *buf
, __u8
*addr
)
62 int count
= 0, rc
= 0;
66 rc
= sscanf(buf
, "%u.%u.%u.%u%c",
67 &in
[0], &in
[1], &in
[2], &in
[3], &c
);
68 if (rc
!= 4 && (rc
!= 5 || c
!= '\n'))
70 for (count
= 0; count
< 4; count
++) {
73 addr
[count
] = in
[count
];
78 static void qeth_l3_ipaddr6_to_string(const __u8
*addr
, char *buf
)
80 sprintf(buf
, "%pI6", addr
);
83 static int qeth_l3_string_to_ipaddr6(const char *buf
, __u8
*addr
)
85 const char *end
, *end_tmp
, *start
;
88 int num2
, cnt
, out
, found
, save_cnt
;
89 unsigned short in_tmp
[8] = {0, };
91 cnt
= out
= found
= save_cnt
= num2
= 0;
96 end
= strchr(start
, ':');
98 end
= buf
+ strlen(buf
);
99 end_tmp
= strchr(start
, '\n');
106 if ((end
- start
) > 4)
108 memcpy(num
, start
, end
- start
);
109 if (!qeth_l3_isxdigit(num
))
111 sscanf(start
, "%x", &num2
);
113 in_tmp
[save_cnt
++] = num2
;
125 if (cnt
+ save_cnt
> 8)
129 in
[cnt
--] = in_tmp
[--save_cnt
];
133 void qeth_l3_ipaddr_to_string(enum qeth_prot_versions proto
, const __u8
*addr
,
136 if (proto
== QETH_PROT_IPV4
)
137 qeth_l3_ipaddr4_to_string(addr
, buf
);
138 else if (proto
== QETH_PROT_IPV6
)
139 qeth_l3_ipaddr6_to_string(addr
, buf
);
142 int qeth_l3_string_to_ipaddr(const char *buf
, enum qeth_prot_versions proto
,
145 if (proto
== QETH_PROT_IPV4
)
146 return qeth_l3_string_to_ipaddr4(buf
, addr
);
147 else if (proto
== QETH_PROT_IPV6
)
148 return qeth_l3_string_to_ipaddr6(buf
, addr
);
153 static void qeth_l3_convert_addr_to_bits(u8
*addr
, u8
*bits
, int len
)
158 for (i
= 0; i
< len
; ++i
) {
160 for (j
= 7; j
>= 0; --j
) {
161 bits
[i
*8 + j
] = octet
& 1;
167 static bool qeth_l3_is_addr_covered_by_ipato(struct qeth_card
*card
,
168 struct qeth_ipaddr
*addr
)
170 struct qeth_ipato_entry
*ipatoe
;
171 u8 addr_bits
[128] = {0, };
172 u8 ipatoe_bits
[128] = {0, };
175 if (!card
->ipato
.enabled
)
177 if (addr
->type
!= QETH_IP_TYPE_NORMAL
)
180 qeth_l3_convert_addr_to_bits((u8
*) &addr
->u
, addr_bits
,
181 (addr
->proto
== QETH_PROT_IPV4
)? 4:16);
182 list_for_each_entry(ipatoe
, &card
->ipato
.entries
, entry
) {
183 if (addr
->proto
!= ipatoe
->proto
)
185 qeth_l3_convert_addr_to_bits(ipatoe
->addr
, ipatoe_bits
,
186 (ipatoe
->proto
== QETH_PROT_IPV4
) ?
188 if (addr
->proto
== QETH_PROT_IPV4
)
189 rc
= !memcmp(addr_bits
, ipatoe_bits
,
190 min(32, ipatoe
->mask_bits
));
192 rc
= !memcmp(addr_bits
, ipatoe_bits
,
193 min(128, ipatoe
->mask_bits
));
198 if ((addr
->proto
== QETH_PROT_IPV4
) && card
->ipato
.invert4
)
200 else if ((addr
->proto
== QETH_PROT_IPV6
) && card
->ipato
.invert6
)
207 qeth_l3_ipaddrs_is_equal(struct qeth_ipaddr
*addr1
, struct qeth_ipaddr
*addr2
)
209 return addr1
->proto
== addr2
->proto
&&
210 !memcmp(&addr1
->u
, &addr2
->u
, sizeof(addr1
->u
)) &&
211 !memcmp(&addr1
->mac
, &addr2
->mac
, sizeof(addr1
->mac
));
214 static struct qeth_ipaddr
*
215 qeth_l3_ip_from_hash(struct qeth_card
*card
, struct qeth_ipaddr
*tmp_addr
)
217 struct qeth_ipaddr
*addr
;
219 if (tmp_addr
->is_multicast
) {
220 hash_for_each_possible(card
->ip_mc_htable
, addr
,
221 hnode
, qeth_l3_ipaddr_hash(tmp_addr
))
222 if (qeth_l3_ipaddrs_is_equal(tmp_addr
, addr
))
225 hash_for_each_possible(card
->ip_htable
, addr
,
226 hnode
, qeth_l3_ipaddr_hash(tmp_addr
))
227 if (qeth_l3_ipaddrs_is_equal(tmp_addr
, addr
))
234 int qeth_l3_delete_ip(struct qeth_card
*card
, struct qeth_ipaddr
*tmp_addr
)
237 struct qeth_ipaddr
*addr
;
239 QETH_CARD_TEXT(card
, 4, "delip");
241 if (tmp_addr
->proto
== QETH_PROT_IPV4
)
242 QETH_CARD_HEX(card
, 4, &tmp_addr
->u
.a4
.addr
, 4);
244 QETH_CARD_HEX(card
, 4, &tmp_addr
->u
.a6
.addr
, 8);
245 QETH_CARD_HEX(card
, 4, ((char *)&tmp_addr
->u
.a6
.addr
) + 8, 8);
248 addr
= qeth_l3_ip_from_hash(card
, tmp_addr
);
253 if (addr
->ref_counter
> 0 && (addr
->type
== QETH_IP_TYPE_NORMAL
||
254 addr
->type
== QETH_IP_TYPE_RXIP
))
256 if (addr
->in_progress
)
259 if (!qeth_card_hw_is_reachable(card
)) {
260 addr
->disp_flag
= QETH_DISP_ADDR_DELETE
;
264 rc
= qeth_l3_deregister_addr_entry(card
, addr
);
266 hash_del(&addr
->hnode
);
272 int qeth_l3_add_ip(struct qeth_card
*card
, struct qeth_ipaddr
*tmp_addr
)
275 struct qeth_ipaddr
*addr
;
277 QETH_CARD_TEXT(card
, 4, "addip");
279 if (tmp_addr
->proto
== QETH_PROT_IPV4
)
280 QETH_CARD_HEX(card
, 4, &tmp_addr
->u
.a4
.addr
, 4);
282 QETH_CARD_HEX(card
, 4, &tmp_addr
->u
.a6
.addr
, 8);
283 QETH_CARD_HEX(card
, 4, ((char *)&tmp_addr
->u
.a6
.addr
) + 8, 8);
286 addr
= qeth_l3_ip_from_hash(card
, tmp_addr
);
288 addr
= qeth_l3_get_addr_buffer(tmp_addr
->proto
);
292 memcpy(addr
, tmp_addr
, sizeof(struct qeth_ipaddr
));
293 addr
->ref_counter
= 1;
295 if (qeth_l3_is_addr_covered_by_ipato(card
, addr
)) {
296 QETH_CARD_TEXT(card
, 2, "tkovaddr");
297 addr
->set_flags
|= QETH_IPA_SETIP_TAKEOVER_FLAG
;
299 hash_add(card
->ip_htable
, &addr
->hnode
,
300 qeth_l3_ipaddr_hash(addr
));
302 if (!qeth_card_hw_is_reachable(card
)) {
303 addr
->disp_flag
= QETH_DISP_ADDR_ADD
;
307 /* qeth_l3_register_addr_entry can go to sleep
308 * if we add a IPV4 addr. It is caused by the reason
309 * that SETIP ipa cmd starts ARP staff for IPV4 addr.
310 * Thus we should unlock spinlock, and make a protection
311 * using in_progress variable to indicate that there is
312 * an hardware operation with this IPV4 address
314 if (addr
->proto
== QETH_PROT_IPV4
) {
315 addr
->in_progress
= 1;
316 spin_unlock_bh(&card
->ip_lock
);
317 rc
= qeth_l3_register_addr_entry(card
, addr
);
318 spin_lock_bh(&card
->ip_lock
);
319 addr
->in_progress
= 0;
321 rc
= qeth_l3_register_addr_entry(card
, addr
);
323 if (!rc
|| (rc
== IPA_RC_DUPLICATE_IP_ADDRESS
) ||
324 (rc
== IPA_RC_LAN_OFFLINE
)) {
325 addr
->disp_flag
= QETH_DISP_ADDR_DO_NOTHING
;
326 if (addr
->ref_counter
< 1) {
327 qeth_l3_delete_ip(card
, addr
);
331 hash_del(&addr
->hnode
);
335 if (addr
->type
== QETH_IP_TYPE_NORMAL
||
336 addr
->type
== QETH_IP_TYPE_RXIP
)
344 struct qeth_ipaddr
*qeth_l3_get_addr_buffer(
345 enum qeth_prot_versions prot
)
347 struct qeth_ipaddr
*addr
;
349 addr
= kzalloc(sizeof(struct qeth_ipaddr
), GFP_ATOMIC
);
353 addr
->type
= QETH_IP_TYPE_NORMAL
;
354 addr
->disp_flag
= QETH_DISP_ADDR_DO_NOTHING
;
360 static void qeth_l3_clear_ip_htable(struct qeth_card
*card
, int recover
)
362 struct qeth_ipaddr
*addr
;
363 struct hlist_node
*tmp
;
366 QETH_CARD_TEXT(card
, 4, "clearip");
368 if (recover
&& card
->options
.sniffer
)
371 spin_lock_bh(&card
->ip_lock
);
373 hash_for_each_safe(card
->ip_htable
, i
, tmp
, addr
, hnode
) {
375 hash_del(&addr
->hnode
);
379 addr
->disp_flag
= QETH_DISP_ADDR_ADD
;
382 spin_unlock_bh(&card
->ip_lock
);
384 spin_lock_bh(&card
->mclock
);
386 hash_for_each_safe(card
->ip_mc_htable
, i
, tmp
, addr
, hnode
) {
387 hash_del(&addr
->hnode
);
391 spin_unlock_bh(&card
->mclock
);
395 static void qeth_l3_recover_ip(struct qeth_card
*card
)
397 struct qeth_ipaddr
*addr
;
398 struct hlist_node
*tmp
;
402 QETH_CARD_TEXT(card
, 4, "recovrip");
404 spin_lock_bh(&card
->ip_lock
);
406 hash_for_each_safe(card
->ip_htable
, i
, tmp
, addr
, hnode
) {
407 if (addr
->disp_flag
== QETH_DISP_ADDR_DELETE
) {
408 qeth_l3_deregister_addr_entry(card
, addr
);
409 hash_del(&addr
->hnode
);
411 } else if (addr
->disp_flag
== QETH_DISP_ADDR_ADD
) {
412 if (addr
->proto
== QETH_PROT_IPV4
) {
413 addr
->in_progress
= 1;
414 spin_unlock_bh(&card
->ip_lock
);
415 rc
= qeth_l3_register_addr_entry(card
, addr
);
416 spin_lock_bh(&card
->ip_lock
);
417 addr
->in_progress
= 0;
419 rc
= qeth_l3_register_addr_entry(card
, addr
);
422 addr
->disp_flag
= QETH_DISP_ADDR_DO_NOTHING
;
423 if (addr
->ref_counter
< 1)
424 qeth_l3_delete_ip(card
, addr
);
426 hash_del(&addr
->hnode
);
432 spin_unlock_bh(&card
->ip_lock
);
436 static int qeth_l3_send_setdelmc(struct qeth_card
*card
,
437 struct qeth_ipaddr
*addr
, int ipacmd
)
440 struct qeth_cmd_buffer
*iob
;
441 struct qeth_ipa_cmd
*cmd
;
443 QETH_CARD_TEXT(card
, 4, "setdelmc");
445 iob
= qeth_get_ipacmd_buffer(card
, ipacmd
, addr
->proto
);
448 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
449 memcpy(&cmd
->data
.setdelipm
.mac
, addr
->mac
, OSA_ADDR_LEN
);
450 if (addr
->proto
== QETH_PROT_IPV6
)
451 memcpy(cmd
->data
.setdelipm
.ip6
, &addr
->u
.a6
.addr
,
452 sizeof(struct in6_addr
));
454 memcpy(&cmd
->data
.setdelipm
.ip4
, &addr
->u
.a4
.addr
, 4);
456 rc
= qeth_send_ipa_cmd(card
, iob
, NULL
, NULL
);
461 static void qeth_l3_fill_netmask(u8
*netmask
, unsigned int len
)
464 for (i
= 0; i
< 16; i
++) {
469 netmask
[i
] = (u8
)(0xFF00 >> j
);
475 static int qeth_l3_send_setdelip(struct qeth_card
*card
,
476 struct qeth_ipaddr
*addr
, int ipacmd
, unsigned int flags
)
479 struct qeth_cmd_buffer
*iob
;
480 struct qeth_ipa_cmd
*cmd
;
483 QETH_CARD_TEXT(card
, 4, "setdelip");
484 QETH_CARD_TEXT_(card
, 4, "flags%02X", flags
);
486 iob
= qeth_get_ipacmd_buffer(card
, ipacmd
, addr
->proto
);
489 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
490 if (addr
->proto
== QETH_PROT_IPV6
) {
491 memcpy(cmd
->data
.setdelip6
.ip_addr
, &addr
->u
.a6
.addr
,
492 sizeof(struct in6_addr
));
493 qeth_l3_fill_netmask(netmask
, addr
->u
.a6
.pfxlen
);
494 memcpy(cmd
->data
.setdelip6
.mask
, netmask
,
495 sizeof(struct in6_addr
));
496 cmd
->data
.setdelip6
.flags
= flags
;
498 memcpy(cmd
->data
.setdelip4
.ip_addr
, &addr
->u
.a4
.addr
, 4);
499 memcpy(cmd
->data
.setdelip4
.mask
, &addr
->u
.a4
.mask
, 4);
500 cmd
->data
.setdelip4
.flags
= flags
;
503 rc
= qeth_send_ipa_cmd(card
, iob
, NULL
, NULL
);
508 static int qeth_l3_send_setrouting(struct qeth_card
*card
,
509 enum qeth_routing_types type
, enum qeth_prot_versions prot
)
512 struct qeth_ipa_cmd
*cmd
;
513 struct qeth_cmd_buffer
*iob
;
515 QETH_CARD_TEXT(card
, 4, "setroutg");
516 iob
= qeth_get_ipacmd_buffer(card
, IPA_CMD_SETRTG
, prot
);
519 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
520 cmd
->data
.setrtg
.type
= (type
);
521 rc
= qeth_send_ipa_cmd(card
, iob
, NULL
, NULL
);
526 static int qeth_l3_correct_routing_type(struct qeth_card
*card
,
527 enum qeth_routing_types
*type
, enum qeth_prot_versions prot
)
529 if (card
->info
.type
== QETH_CARD_TYPE_IQD
) {
532 case PRIMARY_CONNECTOR
:
533 case SECONDARY_CONNECTOR
:
534 case MULTICAST_ROUTER
:
543 case SECONDARY_ROUTER
:
545 case MULTICAST_ROUTER
:
546 if (qeth_is_ipafunc_supported(card
, prot
,
558 int qeth_l3_setrouting_v4(struct qeth_card
*card
)
562 QETH_CARD_TEXT(card
, 3, "setrtg4");
564 rc
= qeth_l3_correct_routing_type(card
, &card
->options
.route4
.type
,
569 rc
= qeth_l3_send_setrouting(card
, card
->options
.route4
.type
,
572 card
->options
.route4
.type
= NO_ROUTER
;
573 QETH_DBF_MESSAGE(2, "Error (0x%04x) while setting routing type"
574 " on %s. Type set to 'no router'.\n", rc
,
575 QETH_CARD_IFNAME(card
));
580 int qeth_l3_setrouting_v6(struct qeth_card
*card
)
584 QETH_CARD_TEXT(card
, 3, "setrtg6");
585 #ifdef CONFIG_QETH_IPV6
587 if (!qeth_is_supported(card
, IPA_IPV6
))
589 rc
= qeth_l3_correct_routing_type(card
, &card
->options
.route6
.type
,
594 rc
= qeth_l3_send_setrouting(card
, card
->options
.route6
.type
,
597 card
->options
.route6
.type
= NO_ROUTER
;
598 QETH_DBF_MESSAGE(2, "Error (0x%04x) while setting routing type"
599 " on %s. Type set to 'no router'.\n", rc
,
600 QETH_CARD_IFNAME(card
));
607 * IP address takeover related functions
611 * qeth_l3_update_ipato() - Update 'takeover' property, for all NORMAL IPs.
613 * Caller must hold ip_lock.
615 void qeth_l3_update_ipato(struct qeth_card
*card
)
617 struct qeth_ipaddr
*addr
;
620 hash_for_each(card
->ip_htable
, i
, addr
, hnode
) {
621 if (addr
->type
!= QETH_IP_TYPE_NORMAL
)
623 if (qeth_l3_is_addr_covered_by_ipato(card
, addr
))
624 addr
->set_flags
|= QETH_IPA_SETIP_TAKEOVER_FLAG
;
626 addr
->set_flags
&= ~QETH_IPA_SETIP_TAKEOVER_FLAG
;
630 static void qeth_l3_clear_ipato_list(struct qeth_card
*card
)
632 struct qeth_ipato_entry
*ipatoe
, *tmp
;
634 spin_lock_bh(&card
->ip_lock
);
636 list_for_each_entry_safe(ipatoe
, tmp
, &card
->ipato
.entries
, entry
) {
637 list_del(&ipatoe
->entry
);
641 qeth_l3_update_ipato(card
);
642 spin_unlock_bh(&card
->ip_lock
);
645 int qeth_l3_add_ipato_entry(struct qeth_card
*card
,
646 struct qeth_ipato_entry
*new)
648 struct qeth_ipato_entry
*ipatoe
;
651 QETH_CARD_TEXT(card
, 2, "addipato");
653 spin_lock_bh(&card
->ip_lock
);
655 list_for_each_entry(ipatoe
, &card
->ipato
.entries
, entry
) {
656 if (ipatoe
->proto
!= new->proto
)
658 if (!memcmp(ipatoe
->addr
, new->addr
,
659 (ipatoe
->proto
== QETH_PROT_IPV4
)? 4:16) &&
660 (ipatoe
->mask_bits
== new->mask_bits
)) {
667 list_add_tail(&new->entry
, &card
->ipato
.entries
);
668 qeth_l3_update_ipato(card
);
671 spin_unlock_bh(&card
->ip_lock
);
676 void qeth_l3_del_ipato_entry(struct qeth_card
*card
,
677 enum qeth_prot_versions proto
, u8
*addr
, int mask_bits
)
679 struct qeth_ipato_entry
*ipatoe
, *tmp
;
681 QETH_CARD_TEXT(card
, 2, "delipato");
683 spin_lock_bh(&card
->ip_lock
);
685 list_for_each_entry_safe(ipatoe
, tmp
, &card
->ipato
.entries
, entry
) {
686 if (ipatoe
->proto
!= proto
)
688 if (!memcmp(ipatoe
->addr
, addr
,
689 (proto
== QETH_PROT_IPV4
)? 4:16) &&
690 (ipatoe
->mask_bits
== mask_bits
)) {
691 list_del(&ipatoe
->entry
);
692 qeth_l3_update_ipato(card
);
697 spin_unlock_bh(&card
->ip_lock
);
701 * VIPA related functions
703 int qeth_l3_add_vipa(struct qeth_card
*card
, enum qeth_prot_versions proto
,
706 struct qeth_ipaddr
*ipaddr
;
709 ipaddr
= qeth_l3_get_addr_buffer(proto
);
711 if (proto
== QETH_PROT_IPV4
) {
712 QETH_CARD_TEXT(card
, 2, "addvipa4");
713 memcpy(&ipaddr
->u
.a4
.addr
, addr
, 4);
714 ipaddr
->u
.a4
.mask
= 0;
715 } else if (proto
== QETH_PROT_IPV6
) {
716 QETH_CARD_TEXT(card
, 2, "addvipa6");
717 memcpy(&ipaddr
->u
.a6
.addr
, addr
, 16);
718 ipaddr
->u
.a6
.pfxlen
= 0;
720 ipaddr
->type
= QETH_IP_TYPE_VIPA
;
721 ipaddr
->set_flags
= QETH_IPA_SETIP_VIPA_FLAG
;
722 ipaddr
->del_flags
= QETH_IPA_DELIP_VIPA_FLAG
;
726 spin_lock_bh(&card
->ip_lock
);
728 if (qeth_l3_ip_from_hash(card
, ipaddr
))
731 qeth_l3_add_ip(card
, ipaddr
);
733 spin_unlock_bh(&card
->ip_lock
);
740 void qeth_l3_del_vipa(struct qeth_card
*card
, enum qeth_prot_versions proto
,
743 struct qeth_ipaddr
*ipaddr
;
745 ipaddr
= qeth_l3_get_addr_buffer(proto
);
747 if (proto
== QETH_PROT_IPV4
) {
748 QETH_CARD_TEXT(card
, 2, "delvipa4");
749 memcpy(&ipaddr
->u
.a4
.addr
, addr
, 4);
750 ipaddr
->u
.a4
.mask
= 0;
751 } else if (proto
== QETH_PROT_IPV6
) {
752 QETH_CARD_TEXT(card
, 2, "delvipa6");
753 memcpy(&ipaddr
->u
.a6
.addr
, addr
, 16);
754 ipaddr
->u
.a6
.pfxlen
= 0;
756 ipaddr
->type
= QETH_IP_TYPE_VIPA
;
760 spin_lock_bh(&card
->ip_lock
);
761 qeth_l3_delete_ip(card
, ipaddr
);
762 spin_unlock_bh(&card
->ip_lock
);
768 * proxy ARP related functions
770 int qeth_l3_add_rxip(struct qeth_card
*card
, enum qeth_prot_versions proto
,
773 struct qeth_ipaddr
*ipaddr
;
776 ipaddr
= qeth_l3_get_addr_buffer(proto
);
778 if (proto
== QETH_PROT_IPV4
) {
779 QETH_CARD_TEXT(card
, 2, "addrxip4");
780 memcpy(&ipaddr
->u
.a4
.addr
, addr
, 4);
781 ipaddr
->u
.a4
.mask
= 0;
782 } else if (proto
== QETH_PROT_IPV6
) {
783 QETH_CARD_TEXT(card
, 2, "addrxip6");
784 memcpy(&ipaddr
->u
.a6
.addr
, addr
, 16);
785 ipaddr
->u
.a6
.pfxlen
= 0;
788 ipaddr
->type
= QETH_IP_TYPE_RXIP
;
789 ipaddr
->set_flags
= QETH_IPA_SETIP_TAKEOVER_FLAG
;
790 ipaddr
->del_flags
= 0;
794 spin_lock_bh(&card
->ip_lock
);
796 if (qeth_l3_ip_from_hash(card
, ipaddr
))
799 qeth_l3_add_ip(card
, ipaddr
);
801 spin_unlock_bh(&card
->ip_lock
);
808 void qeth_l3_del_rxip(struct qeth_card
*card
, enum qeth_prot_versions proto
,
811 struct qeth_ipaddr
*ipaddr
;
813 ipaddr
= qeth_l3_get_addr_buffer(proto
);
815 if (proto
== QETH_PROT_IPV4
) {
816 QETH_CARD_TEXT(card
, 2, "delrxip4");
817 memcpy(&ipaddr
->u
.a4
.addr
, addr
, 4);
818 ipaddr
->u
.a4
.mask
= 0;
819 } else if (proto
== QETH_PROT_IPV6
) {
820 QETH_CARD_TEXT(card
, 2, "delrxip6");
821 memcpy(&ipaddr
->u
.a6
.addr
, addr
, 16);
822 ipaddr
->u
.a6
.pfxlen
= 0;
824 ipaddr
->type
= QETH_IP_TYPE_RXIP
;
828 spin_lock_bh(&card
->ip_lock
);
829 qeth_l3_delete_ip(card
, ipaddr
);
830 spin_unlock_bh(&card
->ip_lock
);
835 static int qeth_l3_register_addr_entry(struct qeth_card
*card
,
836 struct qeth_ipaddr
*addr
)
843 if (addr
->proto
== QETH_PROT_IPV4
) {
844 QETH_CARD_TEXT(card
, 2, "setaddr4");
845 QETH_CARD_HEX(card
, 3, &addr
->u
.a4
.addr
, sizeof(int));
846 } else if (addr
->proto
== QETH_PROT_IPV6
) {
847 QETH_CARD_TEXT(card
, 2, "setaddr6");
848 QETH_CARD_HEX(card
, 3, &addr
->u
.a6
.addr
, 8);
849 QETH_CARD_HEX(card
, 3, ((char *)&addr
->u
.a6
.addr
) + 8, 8);
851 QETH_CARD_TEXT(card
, 2, "setaddr?");
852 QETH_CARD_HEX(card
, 3, addr
, sizeof(struct qeth_ipaddr
));
855 if (addr
->is_multicast
)
856 rc
= qeth_l3_send_setdelmc(card
, addr
, IPA_CMD_SETIPM
);
858 rc
= qeth_l3_send_setdelip(card
, addr
, IPA_CMD_SETIP
,
861 QETH_CARD_TEXT(card
, 2, "failed");
862 } while ((--cnt
> 0) && rc
);
864 QETH_CARD_TEXT(card
, 2, "FAILED");
865 qeth_l3_ipaddr_to_string(addr
->proto
, (u8
*)&addr
->u
, buf
);
866 dev_warn(&card
->gdev
->dev
,
867 "Registering IP address %s failed\n", buf
);
872 static int qeth_l3_deregister_addr_entry(struct qeth_card
*card
,
873 struct qeth_ipaddr
*addr
)
877 if (addr
->proto
== QETH_PROT_IPV4
) {
878 QETH_CARD_TEXT(card
, 2, "deladdr4");
879 QETH_CARD_HEX(card
, 3, &addr
->u
.a4
.addr
, sizeof(int));
880 } else if (addr
->proto
== QETH_PROT_IPV6
) {
881 QETH_CARD_TEXT(card
, 2, "deladdr6");
882 QETH_CARD_HEX(card
, 3, &addr
->u
.a6
.addr
, 8);
883 QETH_CARD_HEX(card
, 3, ((char *)&addr
->u
.a6
.addr
) + 8, 8);
885 QETH_CARD_TEXT(card
, 2, "deladdr?");
886 QETH_CARD_HEX(card
, 3, addr
, sizeof(struct qeth_ipaddr
));
888 if (addr
->is_multicast
)
889 rc
= qeth_l3_send_setdelmc(card
, addr
, IPA_CMD_DELIPM
);
891 rc
= qeth_l3_send_setdelip(card
, addr
, IPA_CMD_DELIP
,
894 QETH_CARD_TEXT(card
, 2, "failed");
899 static u8
qeth_l3_get_qeth_hdr_flags4(int cast_type
)
901 if (cast_type
== RTN_MULTICAST
)
902 return QETH_CAST_MULTICAST
;
903 if (cast_type
== RTN_BROADCAST
)
904 return QETH_CAST_BROADCAST
;
905 return QETH_CAST_UNICAST
;
908 static u8
qeth_l3_get_qeth_hdr_flags6(int cast_type
)
910 u8 ct
= QETH_HDR_PASSTHRU
| QETH_HDR_IPV6
;
911 if (cast_type
== RTN_MULTICAST
)
912 return ct
| QETH_CAST_MULTICAST
;
913 if (cast_type
== RTN_ANYCAST
)
914 return ct
| QETH_CAST_ANYCAST
;
915 if (cast_type
== RTN_BROADCAST
)
916 return ct
| QETH_CAST_BROADCAST
;
917 return ct
| QETH_CAST_UNICAST
;
920 static int qeth_l3_setadapter_parms(struct qeth_card
*card
)
924 QETH_DBF_TEXT(SETUP
, 2, "setadprm");
926 if (qeth_adp_supported(card
, IPA_SETADP_ALTER_MAC_ADDRESS
)) {
927 rc
= qeth_setadpparms_change_macaddr(card
);
929 dev_warn(&card
->gdev
->dev
, "Reading the adapter MAC"
930 " address failed\n");
936 #ifdef CONFIG_QETH_IPV6
937 static int qeth_l3_send_simple_setassparms_ipv6(struct qeth_card
*card
,
938 enum qeth_ipa_funcs ipa_func
, __u16 cmd_code
)
941 struct qeth_cmd_buffer
*iob
;
943 QETH_CARD_TEXT(card
, 4, "simassp6");
944 iob
= qeth_get_setassparms_cmd(card
, ipa_func
, cmd_code
,
948 rc
= qeth_send_setassparms(card
, iob
, 0, 0,
949 qeth_setassparms_cb
, NULL
);
954 static int qeth_l3_start_ipa_arp_processing(struct qeth_card
*card
)
958 QETH_CARD_TEXT(card
, 3, "ipaarp");
960 if (!qeth_is_supported(card
, IPA_ARP_PROCESSING
)) {
961 dev_info(&card
->gdev
->dev
,
962 "ARP processing not supported on %s!\n",
963 QETH_CARD_IFNAME(card
));
966 rc
= qeth_send_simple_setassparms(card
, IPA_ARP_PROCESSING
,
967 IPA_CMD_ASS_START
, 0);
969 dev_warn(&card
->gdev
->dev
,
970 "Starting ARP processing support for %s failed\n",
971 QETH_CARD_IFNAME(card
));
976 static int qeth_l3_start_ipa_source_mac(struct qeth_card
*card
)
980 QETH_CARD_TEXT(card
, 3, "stsrcmac");
982 if (!qeth_is_supported(card
, IPA_SOURCE_MAC
)) {
983 dev_info(&card
->gdev
->dev
,
984 "Inbound source MAC-address not supported on %s\n",
985 QETH_CARD_IFNAME(card
));
989 rc
= qeth_send_simple_setassparms(card
, IPA_SOURCE_MAC
,
990 IPA_CMD_ASS_START
, 0);
992 dev_warn(&card
->gdev
->dev
,
993 "Starting source MAC-address support for %s failed\n",
994 QETH_CARD_IFNAME(card
));
998 static int qeth_l3_start_ipa_vlan(struct qeth_card
*card
)
1002 QETH_CARD_TEXT(card
, 3, "strtvlan");
1004 if (!qeth_is_supported(card
, IPA_FULL_VLAN
)) {
1005 dev_info(&card
->gdev
->dev
,
1006 "VLAN not supported on %s\n", QETH_CARD_IFNAME(card
));
1010 rc
= qeth_send_simple_setassparms(card
, IPA_VLAN_PRIO
,
1011 IPA_CMD_ASS_START
, 0);
1013 dev_warn(&card
->gdev
->dev
,
1014 "Starting VLAN support for %s failed\n",
1015 QETH_CARD_IFNAME(card
));
1017 dev_info(&card
->gdev
->dev
, "VLAN enabled\n");
1022 static int qeth_l3_start_ipa_multicast(struct qeth_card
*card
)
1026 QETH_CARD_TEXT(card
, 3, "stmcast");
1028 if (!qeth_is_supported(card
, IPA_MULTICASTING
)) {
1029 dev_info(&card
->gdev
->dev
,
1030 "Multicast not supported on %s\n",
1031 QETH_CARD_IFNAME(card
));
1035 rc
= qeth_send_simple_setassparms(card
, IPA_MULTICASTING
,
1036 IPA_CMD_ASS_START
, 0);
1038 dev_warn(&card
->gdev
->dev
,
1039 "Starting multicast support for %s failed\n",
1040 QETH_CARD_IFNAME(card
));
1042 dev_info(&card
->gdev
->dev
, "Multicast enabled\n");
1043 card
->dev
->flags
|= IFF_MULTICAST
;
1048 #ifdef CONFIG_QETH_IPV6
1049 static int qeth_l3_softsetup_ipv6(struct qeth_card
*card
)
1053 QETH_CARD_TEXT(card
, 3, "softipv6");
1055 rc
= qeth_query_ipassists(card
, QETH_PROT_IPV6
);
1057 dev_err(&card
->gdev
->dev
,
1058 "Activating IPv6 support for %s failed\n",
1059 QETH_CARD_IFNAME(card
));
1063 if (card
->info
.type
== QETH_CARD_TYPE_IQD
)
1066 rc
= qeth_send_simple_setassparms(card
, IPA_IPV6
,
1067 IPA_CMD_ASS_START
, 3);
1069 dev_err(&card
->gdev
->dev
,
1070 "Activating IPv6 support for %s failed\n",
1071 QETH_CARD_IFNAME(card
));
1074 rc
= qeth_l3_send_simple_setassparms_ipv6(card
, IPA_IPV6
,
1077 dev_err(&card
->gdev
->dev
,
1078 "Activating IPv6 support for %s failed\n",
1079 QETH_CARD_IFNAME(card
));
1082 rc
= qeth_l3_send_simple_setassparms_ipv6(card
, IPA_PASSTHRU
,
1085 dev_warn(&card
->gdev
->dev
,
1086 "Enabling the passthrough mode for %s failed\n",
1087 QETH_CARD_IFNAME(card
));
1091 dev_info(&card
->gdev
->dev
, "IPV6 enabled\n");
1096 static int qeth_l3_start_ipa_ipv6(struct qeth_card
*card
)
1100 QETH_CARD_TEXT(card
, 3, "strtipv6");
1102 if (!qeth_is_supported(card
, IPA_IPV6
)) {
1103 dev_info(&card
->gdev
->dev
,
1104 "IPv6 not supported on %s\n", QETH_CARD_IFNAME(card
));
1107 #ifdef CONFIG_QETH_IPV6
1108 rc
= qeth_l3_softsetup_ipv6(card
);
1113 static int qeth_l3_start_ipa_broadcast(struct qeth_card
*card
)
1117 QETH_CARD_TEXT(card
, 3, "stbrdcst");
1118 card
->info
.broadcast_capable
= 0;
1119 if (!qeth_is_supported(card
, IPA_FILTERING
)) {
1120 dev_info(&card
->gdev
->dev
,
1121 "Broadcast not supported on %s\n",
1122 QETH_CARD_IFNAME(card
));
1126 rc
= qeth_send_simple_setassparms(card
, IPA_FILTERING
,
1127 IPA_CMD_ASS_START
, 0);
1129 dev_warn(&card
->gdev
->dev
, "Enabling broadcast filtering for "
1130 "%s failed\n", QETH_CARD_IFNAME(card
));
1134 rc
= qeth_send_simple_setassparms(card
, IPA_FILTERING
,
1135 IPA_CMD_ASS_CONFIGURE
, 1);
1137 dev_warn(&card
->gdev
->dev
,
1138 "Setting up broadcast filtering for %s failed\n",
1139 QETH_CARD_IFNAME(card
));
1142 card
->info
.broadcast_capable
= QETH_BROADCAST_WITH_ECHO
;
1143 dev_info(&card
->gdev
->dev
, "Broadcast enabled\n");
1144 rc
= qeth_send_simple_setassparms(card
, IPA_FILTERING
,
1145 IPA_CMD_ASS_ENABLE
, 1);
1147 dev_warn(&card
->gdev
->dev
, "Setting up broadcast echo "
1148 "filtering for %s failed\n", QETH_CARD_IFNAME(card
));
1151 card
->info
.broadcast_capable
= QETH_BROADCAST_WITHOUT_ECHO
;
1153 if (card
->info
.broadcast_capable
)
1154 card
->dev
->flags
|= IFF_BROADCAST
;
1156 card
->dev
->flags
&= ~IFF_BROADCAST
;
1160 static int qeth_l3_start_ipassists(struct qeth_card
*card
)
1162 QETH_CARD_TEXT(card
, 3, "strtipas");
1164 if (qeth_set_access_ctrl_online(card
, 0))
1166 qeth_l3_start_ipa_arp_processing(card
); /* go on*/
1167 qeth_l3_start_ipa_source_mac(card
); /* go on*/
1168 qeth_l3_start_ipa_vlan(card
); /* go on*/
1169 qeth_l3_start_ipa_multicast(card
); /* go on*/
1170 qeth_l3_start_ipa_ipv6(card
); /* go on*/
1171 qeth_l3_start_ipa_broadcast(card
); /* go on*/
1175 static int qeth_l3_iqd_read_initial_mac_cb(struct qeth_card
*card
,
1176 struct qeth_reply
*reply
, unsigned long data
)
1178 struct qeth_ipa_cmd
*cmd
;
1180 cmd
= (struct qeth_ipa_cmd
*) data
;
1181 if (cmd
->hdr
.return_code
== 0)
1182 memcpy(card
->dev
->dev_addr
,
1183 cmd
->data
.create_destroy_addr
.unique_id
, ETH_ALEN
);
1185 eth_random_addr(card
->dev
->dev_addr
);
1190 static int qeth_l3_iqd_read_initial_mac(struct qeth_card
*card
)
1193 struct qeth_cmd_buffer
*iob
;
1194 struct qeth_ipa_cmd
*cmd
;
1196 QETH_DBF_TEXT(SETUP
, 2, "hsrmac");
1198 iob
= qeth_get_ipacmd_buffer(card
, IPA_CMD_CREATE_ADDR
,
1202 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
1203 *((__u16
*) &cmd
->data
.create_destroy_addr
.unique_id
[6]) =
1204 card
->info
.unique_id
;
1206 rc
= qeth_send_ipa_cmd(card
, iob
, qeth_l3_iqd_read_initial_mac_cb
,
1211 static int qeth_l3_get_unique_id_cb(struct qeth_card
*card
,
1212 struct qeth_reply
*reply
, unsigned long data
)
1214 struct qeth_ipa_cmd
*cmd
;
1216 cmd
= (struct qeth_ipa_cmd
*) data
;
1217 if (cmd
->hdr
.return_code
== 0)
1218 card
->info
.unique_id
= *((__u16
*)
1219 &cmd
->data
.create_destroy_addr
.unique_id
[6]);
1221 card
->info
.unique_id
= UNIQUE_ID_IF_CREATE_ADDR_FAILED
|
1222 UNIQUE_ID_NOT_BY_CARD
;
1223 dev_warn(&card
->gdev
->dev
, "The network adapter failed to "
1224 "generate a unique ID\n");
1229 static int qeth_l3_get_unique_id(struct qeth_card
*card
)
1232 struct qeth_cmd_buffer
*iob
;
1233 struct qeth_ipa_cmd
*cmd
;
1235 QETH_DBF_TEXT(SETUP
, 2, "guniqeid");
1237 if (!qeth_is_supported(card
, IPA_IPV6
)) {
1238 card
->info
.unique_id
= UNIQUE_ID_IF_CREATE_ADDR_FAILED
|
1239 UNIQUE_ID_NOT_BY_CARD
;
1243 iob
= qeth_get_ipacmd_buffer(card
, IPA_CMD_CREATE_ADDR
,
1247 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
1248 *((__u16
*) &cmd
->data
.create_destroy_addr
.unique_id
[6]) =
1249 card
->info
.unique_id
;
1251 rc
= qeth_send_ipa_cmd(card
, iob
, qeth_l3_get_unique_id_cb
, NULL
);
1256 qeth_diags_trace_cb(struct qeth_card
*card
, struct qeth_reply
*reply
,
1259 struct qeth_ipa_cmd
*cmd
;
1262 QETH_DBF_TEXT(SETUP
, 2, "diastrcb");
1264 cmd
= (struct qeth_ipa_cmd
*)data
;
1265 rc
= cmd
->hdr
.return_code
;
1267 QETH_CARD_TEXT_(card
, 2, "dxter%x", rc
);
1268 switch (cmd
->data
.diagass
.action
) {
1269 case QETH_DIAGS_CMD_TRACE_QUERY
:
1271 case QETH_DIAGS_CMD_TRACE_DISABLE
:
1274 case IPA_RC_INVALID_SUBCMD
:
1275 card
->info
.promisc_mode
= SET_PROMISC_MODE_OFF
;
1276 dev_info(&card
->gdev
->dev
, "The HiperSockets network "
1277 "traffic analyzer is deactivated\n");
1283 case QETH_DIAGS_CMD_TRACE_ENABLE
:
1286 card
->info
.promisc_mode
= SET_PROMISC_MODE_ON
;
1287 dev_info(&card
->gdev
->dev
, "The HiperSockets network "
1288 "traffic analyzer is activated\n");
1290 case IPA_RC_HARDWARE_AUTH_ERROR
:
1291 dev_warn(&card
->gdev
->dev
, "The device is not "
1292 "authorized to run as a HiperSockets network "
1293 "traffic analyzer\n");
1295 case IPA_RC_TRACE_ALREADY_ACTIVE
:
1296 dev_warn(&card
->gdev
->dev
, "A HiperSockets "
1297 "network traffic analyzer is already "
1298 "active in the HiperSockets LAN\n");
1305 QETH_DBF_MESSAGE(2, "Unknown sniffer action (0x%04x) on %s\n",
1306 cmd
->data
.diagass
.action
, QETH_CARD_IFNAME(card
));
1313 qeth_diags_trace(struct qeth_card
*card
, enum qeth_diags_trace_cmds diags_cmd
)
1315 struct qeth_cmd_buffer
*iob
;
1316 struct qeth_ipa_cmd
*cmd
;
1318 QETH_DBF_TEXT(SETUP
, 2, "diagtrac");
1320 iob
= qeth_get_ipacmd_buffer(card
, IPA_CMD_SET_DIAG_ASS
, 0);
1323 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
1324 cmd
->data
.diagass
.subcmd_len
= 16;
1325 cmd
->data
.diagass
.subcmd
= QETH_DIAGS_CMD_TRACE
;
1326 cmd
->data
.diagass
.type
= QETH_DIAGS_TYPE_HIPERSOCKET
;
1327 cmd
->data
.diagass
.action
= diags_cmd
;
1328 return qeth_send_ipa_cmd(card
, iob
, qeth_diags_trace_cb
, NULL
);
1331 static void qeth_l3_get_mac_for_ipm(__be32 ipm
, char *mac
)
1333 ip_eth_mc_map(ipm
, mac
);
1336 static void qeth_l3_mark_all_mc_to_be_deleted(struct qeth_card
*card
)
1338 struct qeth_ipaddr
*addr
;
1341 hash_for_each(card
->ip_mc_htable
, i
, addr
, hnode
)
1342 addr
->disp_flag
= QETH_DISP_ADDR_DELETE
;
1346 static void qeth_l3_add_all_new_mc(struct qeth_card
*card
)
1348 struct qeth_ipaddr
*addr
;
1349 struct hlist_node
*tmp
;
1353 hash_for_each_safe(card
->ip_mc_htable
, i
, tmp
, addr
, hnode
) {
1354 if (addr
->disp_flag
== QETH_DISP_ADDR_ADD
) {
1355 rc
= qeth_l3_register_addr_entry(card
, addr
);
1356 if (!rc
|| (rc
== IPA_RC_LAN_OFFLINE
))
1357 addr
->ref_counter
= 1;
1359 hash_del(&addr
->hnode
);
1367 static void qeth_l3_delete_nonused_mc(struct qeth_card
*card
)
1369 struct qeth_ipaddr
*addr
;
1370 struct hlist_node
*tmp
;
1374 hash_for_each_safe(card
->ip_mc_htable
, i
, tmp
, addr
, hnode
) {
1375 if (addr
->disp_flag
== QETH_DISP_ADDR_DELETE
) {
1376 rc
= qeth_l3_deregister_addr_entry(card
, addr
);
1377 if (!rc
|| (rc
== IPA_RC_MC_ADDR_NOT_FOUND
)) {
1378 hash_del(&addr
->hnode
);
1388 qeth_l3_add_mc_to_hash(struct qeth_card
*card
, struct in_device
*in4_dev
)
1390 struct ip_mc_list
*im4
;
1391 struct qeth_ipaddr
*tmp
, *ipm
;
1392 char buf
[MAX_ADDR_LEN
];
1394 QETH_CARD_TEXT(card
, 4, "addmc");
1396 tmp
= qeth_l3_get_addr_buffer(QETH_PROT_IPV4
);
1400 for (im4
= rcu_dereference(in4_dev
->mc_list
); im4
!= NULL
;
1401 im4
= rcu_dereference(im4
->next_rcu
)) {
1402 qeth_l3_get_mac_for_ipm(im4
->multiaddr
, buf
);
1404 tmp
->u
.a4
.addr
= be32_to_cpu(im4
->multiaddr
);
1405 memcpy(tmp
->mac
, buf
, sizeof(tmp
->mac
));
1406 tmp
->is_multicast
= 1;
1408 ipm
= qeth_l3_ip_from_hash(card
, tmp
);
1410 ipm
->disp_flag
= QETH_DISP_ADDR_DO_NOTHING
;
1412 ipm
= qeth_l3_get_addr_buffer(QETH_PROT_IPV4
);
1415 memcpy(ipm
->mac
, buf
, sizeof(tmp
->mac
));
1416 ipm
->u
.a4
.addr
= be32_to_cpu(im4
->multiaddr
);
1417 ipm
->is_multicast
= 1;
1418 ipm
->disp_flag
= QETH_DISP_ADDR_ADD
;
1419 hash_add(card
->ip_mc_htable
,
1420 &ipm
->hnode
, qeth_l3_ipaddr_hash(ipm
));
1427 /* called with rcu_read_lock */
1428 static void qeth_l3_add_vlan_mc(struct qeth_card
*card
)
1430 struct in_device
*in_dev
;
1433 QETH_CARD_TEXT(card
, 4, "addmcvl");
1435 if (!qeth_is_supported(card
, IPA_FULL_VLAN
))
1438 for_each_set_bit(vid
, card
->active_vlans
, VLAN_N_VID
) {
1439 struct net_device
*netdev
;
1441 netdev
= __vlan_find_dev_deep_rcu(card
->dev
, htons(ETH_P_8021Q
),
1443 if (netdev
== NULL
||
1444 !(netdev
->flags
& IFF_UP
))
1446 in_dev
= __in_dev_get_rcu(netdev
);
1449 qeth_l3_add_mc_to_hash(card
, in_dev
);
1453 static void qeth_l3_add_multicast_ipv4(struct qeth_card
*card
)
1455 struct in_device
*in4_dev
;
1457 QETH_CARD_TEXT(card
, 4, "chkmcv4");
1460 in4_dev
= __in_dev_get_rcu(card
->dev
);
1461 if (in4_dev
== NULL
)
1463 qeth_l3_add_mc_to_hash(card
, in4_dev
);
1464 qeth_l3_add_vlan_mc(card
);
1469 #ifdef CONFIG_QETH_IPV6
1471 qeth_l3_add_mc6_to_hash(struct qeth_card
*card
, struct inet6_dev
*in6_dev
)
1473 struct qeth_ipaddr
*ipm
;
1474 struct ifmcaddr6
*im6
;
1475 struct qeth_ipaddr
*tmp
;
1476 char buf
[MAX_ADDR_LEN
];
1478 QETH_CARD_TEXT(card
, 4, "addmc6");
1480 tmp
= qeth_l3_get_addr_buffer(QETH_PROT_IPV6
);
1484 for (im6
= in6_dev
->mc_list
; im6
!= NULL
; im6
= im6
->next
) {
1485 ndisc_mc_map(&im6
->mca_addr
, buf
, in6_dev
->dev
, 0);
1487 memcpy(tmp
->mac
, buf
, sizeof(tmp
->mac
));
1488 memcpy(&tmp
->u
.a6
.addr
, &im6
->mca_addr
.s6_addr
,
1489 sizeof(struct in6_addr
));
1490 tmp
->is_multicast
= 1;
1492 ipm
= qeth_l3_ip_from_hash(card
, tmp
);
1494 ipm
->disp_flag
= QETH_DISP_ADDR_DO_NOTHING
;
1498 ipm
= qeth_l3_get_addr_buffer(QETH_PROT_IPV6
);
1502 memcpy(ipm
->mac
, buf
, OSA_ADDR_LEN
);
1503 memcpy(&ipm
->u
.a6
.addr
, &im6
->mca_addr
.s6_addr
,
1504 sizeof(struct in6_addr
));
1505 ipm
->is_multicast
= 1;
1506 ipm
->disp_flag
= QETH_DISP_ADDR_ADD
;
1507 hash_add(card
->ip_mc_htable
,
1508 &ipm
->hnode
, qeth_l3_ipaddr_hash(ipm
));
1514 /* called with rcu_read_lock */
1515 static void qeth_l3_add_vlan_mc6(struct qeth_card
*card
)
1517 struct inet6_dev
*in_dev
;
1520 QETH_CARD_TEXT(card
, 4, "admc6vl");
1522 if (!qeth_is_supported(card
, IPA_FULL_VLAN
))
1525 for_each_set_bit(vid
, card
->active_vlans
, VLAN_N_VID
) {
1526 struct net_device
*netdev
;
1528 netdev
= __vlan_find_dev_deep_rcu(card
->dev
, htons(ETH_P_8021Q
),
1530 if (netdev
== NULL
||
1531 !(netdev
->flags
& IFF_UP
))
1533 in_dev
= in6_dev_get(netdev
);
1536 read_lock_bh(&in_dev
->lock
);
1537 qeth_l3_add_mc6_to_hash(card
, in_dev
);
1538 read_unlock_bh(&in_dev
->lock
);
1539 in6_dev_put(in_dev
);
1543 static void qeth_l3_add_multicast_ipv6(struct qeth_card
*card
)
1545 struct inet6_dev
*in6_dev
;
1547 QETH_CARD_TEXT(card
, 4, "chkmcv6");
1549 if (!qeth_is_supported(card
, IPA_IPV6
))
1551 in6_dev
= in6_dev_get(card
->dev
);
1556 read_lock_bh(&in6_dev
->lock
);
1557 qeth_l3_add_mc6_to_hash(card
, in6_dev
);
1558 qeth_l3_add_vlan_mc6(card
);
1559 read_unlock_bh(&in6_dev
->lock
);
1561 in6_dev_put(in6_dev
);
1563 #endif /* CONFIG_QETH_IPV6 */
1565 static void qeth_l3_free_vlan_addresses4(struct qeth_card
*card
,
1568 struct in_device
*in_dev
;
1569 struct in_ifaddr
*ifa
;
1570 struct qeth_ipaddr
*addr
;
1571 struct net_device
*netdev
;
1573 QETH_CARD_TEXT(card
, 4, "frvaddr4");
1575 netdev
= __vlan_find_dev_deep_rcu(card
->dev
, htons(ETH_P_8021Q
), vid
);
1578 in_dev
= in_dev_get(netdev
);
1582 addr
= qeth_l3_get_addr_buffer(QETH_PROT_IPV4
);
1586 spin_lock_bh(&card
->ip_lock
);
1588 for (ifa
= in_dev
->ifa_list
; ifa
; ifa
= ifa
->ifa_next
) {
1589 addr
->u
.a4
.addr
= be32_to_cpu(ifa
->ifa_address
);
1590 addr
->u
.a4
.mask
= be32_to_cpu(ifa
->ifa_mask
);
1591 addr
->type
= QETH_IP_TYPE_NORMAL
;
1592 qeth_l3_delete_ip(card
, addr
);
1595 spin_unlock_bh(&card
->ip_lock
);
1602 static void qeth_l3_free_vlan_addresses6(struct qeth_card
*card
,
1605 #ifdef CONFIG_QETH_IPV6
1606 struct inet6_dev
*in6_dev
;
1607 struct inet6_ifaddr
*ifa
;
1608 struct qeth_ipaddr
*addr
;
1609 struct net_device
*netdev
;
1611 QETH_CARD_TEXT(card
, 4, "frvaddr6");
1613 netdev
= __vlan_find_dev_deep_rcu(card
->dev
, htons(ETH_P_8021Q
), vid
);
1617 in6_dev
= in6_dev_get(netdev
);
1621 addr
= qeth_l3_get_addr_buffer(QETH_PROT_IPV6
);
1625 spin_lock_bh(&card
->ip_lock
);
1627 list_for_each_entry(ifa
, &in6_dev
->addr_list
, if_list
) {
1628 memcpy(&addr
->u
.a6
.addr
, &ifa
->addr
,
1629 sizeof(struct in6_addr
));
1630 addr
->u
.a6
.pfxlen
= ifa
->prefix_len
;
1631 addr
->type
= QETH_IP_TYPE_NORMAL
;
1632 qeth_l3_delete_ip(card
, addr
);
1635 spin_unlock_bh(&card
->ip_lock
);
1639 in6_dev_put(in6_dev
);
1640 #endif /* CONFIG_QETH_IPV6 */
1643 static void qeth_l3_free_vlan_addresses(struct qeth_card
*card
,
1647 qeth_l3_free_vlan_addresses4(card
, vid
);
1648 qeth_l3_free_vlan_addresses6(card
, vid
);
1652 static int qeth_l3_vlan_rx_add_vid(struct net_device
*dev
,
1653 __be16 proto
, u16 vid
)
1655 struct qeth_card
*card
= dev
->ml_priv
;
1657 set_bit(vid
, card
->active_vlans
);
1661 static int qeth_l3_vlan_rx_kill_vid(struct net_device
*dev
,
1662 __be16 proto
, u16 vid
)
1664 struct qeth_card
*card
= dev
->ml_priv
;
1666 QETH_CARD_TEXT_(card
, 4, "kid:%d", vid
);
1668 if (qeth_wait_for_threads(card
, QETH_RECOVER_THREAD
)) {
1669 QETH_CARD_TEXT(card
, 3, "kidREC");
1672 /* unregister IP addresses of vlan device */
1673 qeth_l3_free_vlan_addresses(card
, vid
);
1674 clear_bit(vid
, card
->active_vlans
);
1675 qeth_l3_set_multicast_list(card
->dev
);
1679 static void qeth_l3_rebuild_skb(struct qeth_card
*card
, struct sk_buff
*skb
,
1680 struct qeth_hdr
*hdr
)
1683 struct iphdr
*ip_hdr
;
1684 unsigned char tg_addr
[MAX_ADDR_LEN
];
1686 if (!(hdr
->hdr
.l3
.flags
& QETH_HDR_PASSTHRU
)) {
1687 prot
= (hdr
->hdr
.l3
.flags
& QETH_HDR_IPV6
) ? ETH_P_IPV6
:
1689 switch (hdr
->hdr
.l3
.flags
& QETH_HDR_CAST_MASK
) {
1690 case QETH_CAST_MULTICAST
:
1692 #ifdef CONFIG_QETH_IPV6
1694 ndisc_mc_map((struct in6_addr
*)
1696 tg_addr
, card
->dev
, 0);
1700 ip_hdr
= (struct iphdr
*)skb
->data
;
1701 ip_eth_mc_map(ip_hdr
->daddr
, tg_addr
);
1704 memcpy(tg_addr
, card
->dev
->broadcast
,
1705 card
->dev
->addr_len
);
1707 card
->stats
.multicast
++;
1708 skb
->pkt_type
= PACKET_MULTICAST
;
1710 case QETH_CAST_BROADCAST
:
1711 memcpy(tg_addr
, card
->dev
->broadcast
,
1712 card
->dev
->addr_len
);
1713 card
->stats
.multicast
++;
1714 skb
->pkt_type
= PACKET_BROADCAST
;
1716 case QETH_CAST_UNICAST
:
1717 case QETH_CAST_ANYCAST
:
1718 case QETH_CAST_NOCAST
:
1720 if (card
->options
.sniffer
)
1721 skb
->pkt_type
= PACKET_OTHERHOST
;
1723 skb
->pkt_type
= PACKET_HOST
;
1724 memcpy(tg_addr
, card
->dev
->dev_addr
,
1725 card
->dev
->addr_len
);
1727 if (hdr
->hdr
.l3
.ext_flags
& QETH_HDR_EXT_SRC_MAC_ADDR
)
1728 card
->dev
->header_ops
->create(skb
, card
->dev
, prot
,
1729 tg_addr
, &hdr
->hdr
.l3
.dest_addr
[2],
1730 card
->dev
->addr_len
);
1732 card
->dev
->header_ops
->create(skb
, card
->dev
, prot
,
1733 tg_addr
, "FAKELL", card
->dev
->addr_len
);
1736 skb
->protocol
= eth_type_trans(skb
, card
->dev
);
1738 /* copy VLAN tag from hdr into skb */
1739 if (!card
->options
.sniffer
&&
1740 (hdr
->hdr
.l3
.ext_flags
& (QETH_HDR_EXT_VLAN_FRAME
|
1741 QETH_HDR_EXT_INCLUDE_VLAN_TAG
))) {
1742 u16 tag
= (hdr
->hdr
.l3
.ext_flags
& QETH_HDR_EXT_VLAN_FRAME
) ?
1743 hdr
->hdr
.l3
.vlan_id
:
1744 *((u16
*)&hdr
->hdr
.l3
.dest_addr
[12]);
1745 __vlan_hwaccel_put_tag(skb
, htons(ETH_P_8021Q
), tag
);
1748 if (card
->dev
->features
& NETIF_F_RXCSUM
) {
1749 if ((hdr
->hdr
.l3
.ext_flags
&
1750 (QETH_HDR_EXT_CSUM_HDR_REQ
|
1751 QETH_HDR_EXT_CSUM_TRANSP_REQ
)) ==
1752 (QETH_HDR_EXT_CSUM_HDR_REQ
|
1753 QETH_HDR_EXT_CSUM_TRANSP_REQ
))
1754 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
1756 skb
->ip_summed
= CHECKSUM_NONE
;
1758 skb
->ip_summed
= CHECKSUM_NONE
;
1761 static int qeth_l3_process_inbound_buffer(struct qeth_card
*card
,
1762 int budget
, int *done
)
1765 struct sk_buff
*skb
;
1766 struct qeth_hdr
*hdr
;
1771 WARN_ON_ONCE(!budget
);
1773 skb
= qeth_core_get_next_skb(card
,
1774 &card
->qdio
.in_q
->bufs
[card
->rx
.b_index
],
1775 &card
->rx
.b_element
, &card
->rx
.e_offset
, &hdr
);
1780 skb
->dev
= card
->dev
;
1781 switch (hdr
->hdr
.l3
.id
) {
1782 case QETH_HEADER_TYPE_LAYER3
:
1783 magic
= *(__u16
*)skb
->data
;
1784 if ((card
->info
.type
== QETH_CARD_TYPE_IQD
) &&
1785 (magic
== ETH_P_AF_IUCV
)) {
1786 skb
->protocol
= cpu_to_be16(ETH_P_AF_IUCV
);
1787 skb
->pkt_type
= PACKET_HOST
;
1788 skb
->mac_header
= NET_SKB_PAD
;
1789 skb
->dev
= card
->dev
;
1791 card
->dev
->header_ops
->create(skb
, card
->dev
, 0,
1792 card
->dev
->dev_addr
, "FAKELL",
1793 card
->dev
->addr_len
);
1794 netif_receive_skb(skb
);
1796 qeth_l3_rebuild_skb(card
, skb
, hdr
);
1798 napi_gro_receive(&card
->napi
, skb
);
1801 case QETH_HEADER_TYPE_LAYER2
: /* for HiperSockets sniffer */
1802 skb
->pkt_type
= PACKET_HOST
;
1803 skb
->protocol
= eth_type_trans(skb
, skb
->dev
);
1805 netif_receive_skb(skb
);
1808 dev_kfree_skb_any(skb
);
1809 QETH_CARD_TEXT(card
, 3, "inbunkno");
1810 QETH_DBF_HEX(CTRL
, 3, hdr
, QETH_DBF_CTRL_LEN
);
1815 card
->stats
.rx_packets
++;
1816 card
->stats
.rx_bytes
+= len
;
1821 static int qeth_l3_verify_vlan_dev(struct net_device
*dev
,
1822 struct qeth_card
*card
)
1827 for_each_set_bit(vid
, card
->active_vlans
, VLAN_N_VID
) {
1828 struct net_device
*netdev
;
1831 netdev
= __vlan_find_dev_deep_rcu(card
->dev
, htons(ETH_P_8021Q
),
1834 if (netdev
== dev
) {
1835 rc
= QETH_VLAN_CARD
;
1840 if (rc
&& !(vlan_dev_real_dev(dev
)->ml_priv
== (void *)card
))
1846 static int qeth_l3_verify_dev(struct net_device
*dev
)
1848 struct qeth_card
*card
;
1850 unsigned long flags
;
1852 read_lock_irqsave(&qeth_core_card_list
.rwlock
, flags
);
1853 list_for_each_entry(card
, &qeth_core_card_list
.list
, list
) {
1854 if (card
->dev
== dev
) {
1855 rc
= QETH_REAL_CARD
;
1858 rc
= qeth_l3_verify_vlan_dev(dev
, card
);
1862 read_unlock_irqrestore(&qeth_core_card_list
.rwlock
, flags
);
1867 static struct qeth_card
*qeth_l3_get_card_from_dev(struct net_device
*dev
)
1869 struct qeth_card
*card
= NULL
;
1872 rc
= qeth_l3_verify_dev(dev
);
1873 if (rc
== QETH_REAL_CARD
)
1874 card
= dev
->ml_priv
;
1875 else if (rc
== QETH_VLAN_CARD
)
1876 card
= vlan_dev_real_dev(dev
)->ml_priv
;
1877 if (card
&& card
->options
.layer2
)
1880 QETH_CARD_TEXT_(card
, 4, "%d", rc
);
1884 static void qeth_l3_stop_card(struct qeth_card
*card
, int recovery_mode
)
1886 QETH_DBF_TEXT(SETUP
, 2, "stopcard");
1887 QETH_DBF_HEX(SETUP
, 2, &card
, sizeof(void *));
1889 qeth_set_allowed_threads(card
, 0, 1);
1890 if (card
->options
.sniffer
&&
1891 (card
->info
.promisc_mode
== SET_PROMISC_MODE_ON
))
1892 qeth_diags_trace(card
, QETH_DIAGS_CMD_TRACE_DISABLE
);
1893 if (card
->read
.state
== CH_STATE_UP
&&
1894 card
->write
.state
== CH_STATE_UP
&&
1895 (card
->state
== CARD_STATE_UP
)) {
1897 qeth_l3_stop(card
->dev
);
1900 dev_close(card
->dev
);
1903 card
->state
= CARD_STATE_SOFTSETUP
;
1905 if (card
->state
== CARD_STATE_SOFTSETUP
) {
1906 qeth_l3_clear_ip_htable(card
, 1);
1907 qeth_clear_ipacmd_list(card
);
1908 card
->state
= CARD_STATE_HARDSETUP
;
1910 if (card
->state
== CARD_STATE_HARDSETUP
) {
1911 qeth_qdio_clear_card(card
, 0);
1912 qeth_clear_qdio_buffers(card
);
1913 qeth_clear_working_pool_list(card
);
1914 card
->state
= CARD_STATE_DOWN
;
1916 if (card
->state
== CARD_STATE_DOWN
) {
1917 qeth_clear_cmd_buffers(&card
->read
);
1918 qeth_clear_cmd_buffers(&card
->write
);
1923 * test for and Switch promiscuous mode (on or off)
1924 * either for guestlan or HiperSocket Sniffer
1927 qeth_l3_handle_promisc_mode(struct qeth_card
*card
)
1929 struct net_device
*dev
= card
->dev
;
1931 if (((dev
->flags
& IFF_PROMISC
) &&
1932 (card
->info
.promisc_mode
== SET_PROMISC_MODE_ON
)) ||
1933 (!(dev
->flags
& IFF_PROMISC
) &&
1934 (card
->info
.promisc_mode
== SET_PROMISC_MODE_OFF
)))
1937 if (card
->info
.guestlan
) { /* Guestlan trace */
1938 if (qeth_adp_supported(card
, IPA_SETADP_SET_PROMISC_MODE
))
1939 qeth_setadp_promisc_mode(card
);
1940 } else if (card
->options
.sniffer
&& /* HiperSockets trace */
1941 qeth_adp_supported(card
, IPA_SETADP_SET_DIAG_ASSIST
)) {
1942 if (dev
->flags
& IFF_PROMISC
) {
1943 QETH_CARD_TEXT(card
, 3, "+promisc");
1944 qeth_diags_trace(card
, QETH_DIAGS_CMD_TRACE_ENABLE
);
1946 QETH_CARD_TEXT(card
, 3, "-promisc");
1947 qeth_diags_trace(card
, QETH_DIAGS_CMD_TRACE_DISABLE
);
1952 static void qeth_l3_set_multicast_list(struct net_device
*dev
)
1954 struct qeth_card
*card
= dev
->ml_priv
;
1956 QETH_CARD_TEXT(card
, 3, "setmulti");
1957 if (qeth_threads_running(card
, QETH_RECOVER_THREAD
) &&
1958 (card
->state
!= CARD_STATE_UP
))
1960 if (!card
->options
.sniffer
) {
1962 spin_lock_bh(&card
->mclock
);
1964 qeth_l3_mark_all_mc_to_be_deleted(card
);
1966 qeth_l3_add_multicast_ipv4(card
);
1967 #ifdef CONFIG_QETH_IPV6
1968 qeth_l3_add_multicast_ipv6(card
);
1970 qeth_l3_delete_nonused_mc(card
);
1971 qeth_l3_add_all_new_mc(card
);
1973 spin_unlock_bh(&card
->mclock
);
1975 if (!qeth_adp_supported(card
, IPA_SETADP_SET_PROMISC_MODE
))
1978 qeth_l3_handle_promisc_mode(card
);
1981 static const char *qeth_l3_arp_get_error_cause(int *rc
)
1984 case QETH_IPA_ARP_RC_FAILED
:
1986 return "operation failed";
1987 case QETH_IPA_ARP_RC_NOTSUPP
:
1989 return "operation not supported";
1990 case QETH_IPA_ARP_RC_OUT_OF_RANGE
:
1992 return "argument out of range";
1993 case QETH_IPA_ARP_RC_Q_NOTSUPP
:
1995 return "query operation not supported";
1996 case QETH_IPA_ARP_RC_Q_NO_DATA
:
1998 return "no query data available";
2000 return "unknown error";
2004 static int qeth_l3_arp_set_no_entries(struct qeth_card
*card
, int no_entries
)
2009 QETH_CARD_TEXT(card
, 3, "arpstnoe");
2012 * currently GuestLAN only supports the ARP assist function
2013 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_SET_NO_ENTRIES;
2014 * thus we say EOPNOTSUPP for this ARP function
2016 if (card
->info
.guestlan
)
2018 if (!qeth_is_supported(card
, IPA_ARP_PROCESSING
)) {
2021 rc
= qeth_send_simple_setassparms(card
, IPA_ARP_PROCESSING
,
2022 IPA_CMD_ASS_ARP_SET_NO_ENTRIES
,
2026 QETH_DBF_MESSAGE(2, "Could not set number of ARP entries on "
2027 "%s: %s (0x%x/%d)\n", QETH_CARD_IFNAME(card
),
2028 qeth_l3_arp_get_error_cause(&rc
), tmp
, tmp
);
2033 static __u32
get_arp_entry_size(struct qeth_card
*card
,
2034 struct qeth_arp_query_data
*qdata
,
2035 struct qeth_arp_entrytype
*type
, __u8 strip_entries
)
2040 is_hsi
= qdata
->reply_bits
== 5;
2041 if (type
->ip
== QETHARP_IP_ADDR_V4
) {
2042 QETH_CARD_TEXT(card
, 4, "arpev4");
2043 if (strip_entries
) {
2044 rc
= is_hsi
? sizeof(struct qeth_arp_qi_entry5_short
) :
2045 sizeof(struct qeth_arp_qi_entry7_short
);
2047 rc
= is_hsi
? sizeof(struct qeth_arp_qi_entry5
) :
2048 sizeof(struct qeth_arp_qi_entry7
);
2050 } else if (type
->ip
== QETHARP_IP_ADDR_V6
) {
2051 QETH_CARD_TEXT(card
, 4, "arpev6");
2052 if (strip_entries
) {
2054 sizeof(struct qeth_arp_qi_entry5_short_ipv6
) :
2055 sizeof(struct qeth_arp_qi_entry7_short_ipv6
);
2058 sizeof(struct qeth_arp_qi_entry5_ipv6
) :
2059 sizeof(struct qeth_arp_qi_entry7_ipv6
);
2062 QETH_CARD_TEXT(card
, 4, "arpinv");
2069 static int arpentry_matches_prot(struct qeth_arp_entrytype
*type
, __u16 prot
)
2071 return (type
->ip
== QETHARP_IP_ADDR_V4
&& prot
== QETH_PROT_IPV4
) ||
2072 (type
->ip
== QETHARP_IP_ADDR_V6
&& prot
== QETH_PROT_IPV6
);
2075 static int qeth_l3_arp_query_cb(struct qeth_card
*card
,
2076 struct qeth_reply
*reply
, unsigned long data
)
2078 struct qeth_ipa_cmd
*cmd
;
2079 struct qeth_arp_query_data
*qdata
;
2080 struct qeth_arp_query_info
*qinfo
;
2083 int entrybytes_done
;
2085 __u8 do_strip_entries
;
2087 QETH_CARD_TEXT(card
, 3, "arpquecb");
2089 qinfo
= (struct qeth_arp_query_info
*) reply
->param
;
2090 cmd
= (struct qeth_ipa_cmd
*) data
;
2091 QETH_CARD_TEXT_(card
, 4, "%i", cmd
->hdr
.prot_version
);
2092 if (cmd
->hdr
.return_code
) {
2093 QETH_CARD_TEXT(card
, 4, "arpcberr");
2094 QETH_CARD_TEXT_(card
, 4, "%i", cmd
->hdr
.return_code
);
2097 if (cmd
->data
.setassparms
.hdr
.return_code
) {
2098 cmd
->hdr
.return_code
= cmd
->data
.setassparms
.hdr
.return_code
;
2099 QETH_CARD_TEXT(card
, 4, "setaperr");
2100 QETH_CARD_TEXT_(card
, 4, "%i", cmd
->hdr
.return_code
);
2103 qdata
= &cmd
->data
.setassparms
.data
.query_arp
;
2104 QETH_CARD_TEXT_(card
, 4, "anoen%i", qdata
->no_entries
);
2106 do_strip_entries
= (qinfo
->mask_bits
& QETH_QARP_STRIP_ENTRIES
) > 0;
2107 stripped_bytes
= do_strip_entries
? QETH_QARP_MEDIASPECIFIC_BYTES
: 0;
2108 entrybytes_done
= 0;
2109 for (e
= 0; e
< qdata
->no_entries
; ++e
) {
2112 struct qeth_arp_entrytype
*etype
;
2114 cur_entry
= &qdata
->data
+ entrybytes_done
;
2115 etype
= &((struct qeth_arp_qi_entry5
*) cur_entry
)->type
;
2116 if (!arpentry_matches_prot(etype
, cmd
->hdr
.prot_version
)) {
2117 QETH_CARD_TEXT(card
, 4, "pmis");
2118 QETH_CARD_TEXT_(card
, 4, "%i", etype
->ip
);
2121 esize
= get_arp_entry_size(card
, qdata
, etype
,
2123 QETH_CARD_TEXT_(card
, 5, "esz%i", esize
);
2127 if ((qinfo
->udata_len
- qinfo
->udata_offset
) < esize
) {
2128 QETH_CARD_TEXT_(card
, 4, "qaer3%i", -ENOMEM
);
2129 cmd
->hdr
.return_code
= IPA_RC_ENOMEM
;
2133 memcpy(qinfo
->udata
+ qinfo
->udata_offset
,
2134 &qdata
->data
+ entrybytes_done
+ stripped_bytes
,
2136 entrybytes_done
+= esize
+ stripped_bytes
;
2137 qinfo
->udata_offset
+= esize
;
2138 ++qinfo
->no_entries
;
2140 /* check if all replies received ... */
2141 if (cmd
->data
.setassparms
.hdr
.seq_no
<
2142 cmd
->data
.setassparms
.hdr
.number_of_replies
)
2144 QETH_CARD_TEXT_(card
, 4, "nove%i", qinfo
->no_entries
);
2145 memcpy(qinfo
->udata
, &qinfo
->no_entries
, 4);
2146 /* keep STRIP_ENTRIES flag so the user program can distinguish
2147 * stripped entries from normal ones */
2148 if (qinfo
->mask_bits
& QETH_QARP_STRIP_ENTRIES
)
2149 qdata
->reply_bits
|= QETH_QARP_STRIP_ENTRIES
;
2150 memcpy(qinfo
->udata
+ QETH_QARP_MASK_OFFSET
, &qdata
->reply_bits
, 2);
2151 QETH_CARD_TEXT_(card
, 4, "rc%i", 0);
2155 memcpy(qinfo
->udata
, &i
, 4);
2159 static int qeth_l3_send_ipa_arp_cmd(struct qeth_card
*card
,
2160 struct qeth_cmd_buffer
*iob
, int len
,
2161 int (*reply_cb
)(struct qeth_card
*, struct qeth_reply
*,
2165 QETH_CARD_TEXT(card
, 4, "sendarp");
2167 memcpy(iob
->data
, IPA_PDU_HEADER
, IPA_PDU_HEADER_SIZE
);
2168 memcpy(QETH_IPA_CMD_DEST_ADDR(iob
->data
),
2169 &card
->token
.ulp_connection_r
, QETH_MPC_TOKEN_LENGTH
);
2170 return qeth_send_control_data(card
, IPA_PDU_HEADER_SIZE
+ len
, iob
,
2171 reply_cb
, reply_param
);
2174 static int qeth_l3_query_arp_cache_info(struct qeth_card
*card
,
2175 enum qeth_prot_versions prot
,
2176 struct qeth_arp_query_info
*qinfo
)
2178 struct qeth_cmd_buffer
*iob
;
2179 struct qeth_ipa_cmd
*cmd
;
2183 QETH_CARD_TEXT_(card
, 3, "qarpipv%i", prot
);
2185 iob
= qeth_get_setassparms_cmd(card
, IPA_ARP_PROCESSING
,
2186 IPA_CMD_ASS_ARP_QUERY_INFO
,
2187 sizeof(struct qeth_arp_query_data
)
2192 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
2193 cmd
->data
.setassparms
.data
.query_arp
.request_bits
= 0x000F;
2194 cmd
->data
.setassparms
.data
.query_arp
.reply_bits
= 0;
2195 cmd
->data
.setassparms
.data
.query_arp
.no_entries
= 0;
2196 rc
= qeth_l3_send_ipa_arp_cmd(card
, iob
,
2197 QETH_SETASS_BASE_LEN
+QETH_ARP_CMD_LEN
,
2198 qeth_l3_arp_query_cb
, (void *)qinfo
);
2202 "Error while querying ARP cache on %s: %s "
2203 "(0x%x/%d)\n", QETH_CARD_IFNAME(card
),
2204 qeth_l3_arp_get_error_cause(&rc
), tmp
, tmp
);
2210 static int qeth_l3_arp_query(struct qeth_card
*card
, char __user
*udata
)
2212 struct qeth_arp_query_info qinfo
= {0, };
2215 QETH_CARD_TEXT(card
, 3, "arpquery");
2217 if (!qeth_is_supported(card
,/*IPA_QUERY_ARP_ADDR_INFO*/
2218 IPA_ARP_PROCESSING
)) {
2219 QETH_CARD_TEXT(card
, 3, "arpqnsup");
2223 /* get size of userspace buffer and mask_bits -> 6 bytes */
2224 if (copy_from_user(&qinfo
, udata
, 6)) {
2228 qinfo
.udata
= kzalloc(qinfo
.udata_len
, GFP_KERNEL
);
2233 qinfo
.udata_offset
= QETH_QARP_ENTRIES_OFFSET
;
2234 rc
= qeth_l3_query_arp_cache_info(card
, QETH_PROT_IPV4
, &qinfo
);
2236 if (copy_to_user(udata
, qinfo
.udata
, 4))
2240 #ifdef CONFIG_QETH_IPV6
2241 if (qinfo
.mask_bits
& QETH_QARP_WITH_IPV6
) {
2242 /* fails in case of GuestLAN QDIO mode */
2243 qeth_l3_query_arp_cache_info(card
, QETH_PROT_IPV6
, &qinfo
);
2246 if (copy_to_user(udata
, qinfo
.udata
, qinfo
.udata_len
)) {
2247 QETH_CARD_TEXT(card
, 4, "qactf");
2251 QETH_CARD_TEXT(card
, 4, "qacts");
2259 static int qeth_l3_arp_add_entry(struct qeth_card
*card
,
2260 struct qeth_arp_cache_entry
*entry
)
2262 struct qeth_cmd_buffer
*iob
;
2267 QETH_CARD_TEXT(card
, 3, "arpadent");
2270 * currently GuestLAN only supports the ARP assist function
2271 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_ADD_ENTRY;
2272 * thus we say EOPNOTSUPP for this ARP function
2274 if (card
->info
.guestlan
)
2276 if (!qeth_is_supported(card
, IPA_ARP_PROCESSING
)) {
2280 iob
= qeth_get_setassparms_cmd(card
, IPA_ARP_PROCESSING
,
2281 IPA_CMD_ASS_ARP_ADD_ENTRY
,
2282 sizeof(struct qeth_arp_cache_entry
),
2286 rc
= qeth_send_setassparms(card
, iob
,
2287 sizeof(struct qeth_arp_cache_entry
),
2288 (unsigned long) entry
,
2289 qeth_setassparms_cb
, NULL
);
2292 qeth_l3_ipaddr4_to_string((u8
*)entry
->ipaddr
, buf
);
2293 QETH_DBF_MESSAGE(2, "Could not add ARP entry for address %s "
2294 "on %s: %s (0x%x/%d)\n", buf
, QETH_CARD_IFNAME(card
),
2295 qeth_l3_arp_get_error_cause(&rc
), tmp
, tmp
);
2300 static int qeth_l3_arp_remove_entry(struct qeth_card
*card
,
2301 struct qeth_arp_cache_entry
*entry
)
2303 struct qeth_cmd_buffer
*iob
;
2304 char buf
[16] = {0, };
2308 QETH_CARD_TEXT(card
, 3, "arprment");
2311 * currently GuestLAN only supports the ARP assist function
2312 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_REMOVE_ENTRY;
2313 * thus we say EOPNOTSUPP for this ARP function
2315 if (card
->info
.guestlan
)
2317 if (!qeth_is_supported(card
, IPA_ARP_PROCESSING
)) {
2320 memcpy(buf
, entry
, 12);
2321 iob
= qeth_get_setassparms_cmd(card
, IPA_ARP_PROCESSING
,
2322 IPA_CMD_ASS_ARP_REMOVE_ENTRY
,
2327 rc
= qeth_send_setassparms(card
, iob
,
2328 12, (unsigned long)buf
,
2329 qeth_setassparms_cb
, NULL
);
2333 qeth_l3_ipaddr4_to_string((u8
*)entry
->ipaddr
, buf
);
2334 QETH_DBF_MESSAGE(2, "Could not delete ARP entry for address %s"
2335 " on %s: %s (0x%x/%d)\n", buf
, QETH_CARD_IFNAME(card
),
2336 qeth_l3_arp_get_error_cause(&rc
), tmp
, tmp
);
2341 static int qeth_l3_arp_flush_cache(struct qeth_card
*card
)
2346 QETH_CARD_TEXT(card
, 3, "arpflush");
2349 * currently GuestLAN only supports the ARP assist function
2350 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_FLUSH_CACHE;
2351 * thus we say EOPNOTSUPP for this ARP function
2353 if (card
->info
.guestlan
|| (card
->info
.type
== QETH_CARD_TYPE_IQD
))
2355 if (!qeth_is_supported(card
, IPA_ARP_PROCESSING
)) {
2358 rc
= qeth_send_simple_setassparms(card
, IPA_ARP_PROCESSING
,
2359 IPA_CMD_ASS_ARP_FLUSH_CACHE
, 0);
2362 QETH_DBF_MESSAGE(2, "Could not flush ARP cache on %s: %s "
2363 "(0x%x/%d)\n", QETH_CARD_IFNAME(card
),
2364 qeth_l3_arp_get_error_cause(&rc
), tmp
, tmp
);
2369 static int qeth_l3_do_ioctl(struct net_device
*dev
, struct ifreq
*rq
, int cmd
)
2371 struct qeth_card
*card
= dev
->ml_priv
;
2372 struct qeth_arp_cache_entry arp_entry
;
2376 case SIOC_QETH_ARP_SET_NO_ENTRIES
:
2377 if (!capable(CAP_NET_ADMIN
)) {
2381 rc
= qeth_l3_arp_set_no_entries(card
, rq
->ifr_ifru
.ifru_ivalue
);
2383 case SIOC_QETH_ARP_QUERY_INFO
:
2384 if (!capable(CAP_NET_ADMIN
)) {
2388 rc
= qeth_l3_arp_query(card
, rq
->ifr_ifru
.ifru_data
);
2390 case SIOC_QETH_ARP_ADD_ENTRY
:
2391 if (!capable(CAP_NET_ADMIN
)) {
2395 if (copy_from_user(&arp_entry
, rq
->ifr_ifru
.ifru_data
,
2396 sizeof(struct qeth_arp_cache_entry
)))
2399 rc
= qeth_l3_arp_add_entry(card
, &arp_entry
);
2401 case SIOC_QETH_ARP_REMOVE_ENTRY
:
2402 if (!capable(CAP_NET_ADMIN
)) {
2406 if (copy_from_user(&arp_entry
, rq
->ifr_ifru
.ifru_data
,
2407 sizeof(struct qeth_arp_cache_entry
)))
2410 rc
= qeth_l3_arp_remove_entry(card
, &arp_entry
);
2412 case SIOC_QETH_ARP_FLUSH_CACHE
:
2413 if (!capable(CAP_NET_ADMIN
)) {
2417 rc
= qeth_l3_arp_flush_cache(card
);
2425 static int qeth_l3_get_cast_type(struct qeth_card
*card
, struct sk_buff
*skb
)
2427 int cast_type
= RTN_UNSPEC
;
2428 struct neighbour
*n
= NULL
;
2429 struct dst_entry
*dst
;
2434 n
= dst_neigh_lookup_skb(dst
, skb
);
2436 cast_type
= n
->type
;
2439 if ((cast_type
== RTN_BROADCAST
) ||
2440 (cast_type
== RTN_MULTICAST
) ||
2441 (cast_type
== RTN_ANYCAST
))
2448 /* try something else */
2449 if (be16_to_cpu(skb
->protocol
) == ETH_P_IPV6
)
2450 return (skb_network_header(skb
)[24] == 0xff) ?
2452 else if (be16_to_cpu(skb
->protocol
) == ETH_P_IP
)
2453 return ((skb_network_header(skb
)[16] & 0xf0) == 0xe0) ?
2456 if (!memcmp(skb
->data
, skb
->dev
->broadcast
, 6))
2457 return RTN_BROADCAST
;
2461 hdr_mac
= *((u16
*)skb
->data
);
2463 switch (card
->info
.link_type
) {
2464 case QETH_LINK_TYPE_HSTR
:
2465 case QETH_LINK_TYPE_LANE_TR
:
2466 if ((hdr_mac
== QETH_TR_MAC_NC
) ||
2467 (hdr_mac
== QETH_TR_MAC_C
))
2468 return RTN_MULTICAST
;
2470 /* eth or so multicast? */
2472 if ((hdr_mac
== QETH_ETH_MAC_V4
) ||
2473 (hdr_mac
== QETH_ETH_MAC_V6
))
2474 return RTN_MULTICAST
;
2480 static void qeth_l3_fill_af_iucv_hdr(struct qeth_card
*card
,
2481 struct qeth_hdr
*hdr
, struct sk_buff
*skb
)
2484 struct af_iucv_trans_hdr
*iucv_hdr
;
2486 memset(hdr
, 0, sizeof(struct qeth_hdr
));
2487 hdr
->hdr
.l3
.id
= QETH_HEADER_TYPE_LAYER3
;
2488 hdr
->hdr
.l3
.ext_flags
= 0;
2489 hdr
->hdr
.l3
.length
= skb
->len
- ETH_HLEN
;
2490 hdr
->hdr
.l3
.flags
= QETH_HDR_IPV6
| QETH_CAST_UNICAST
;
2492 iucv_hdr
= (struct af_iucv_trans_hdr
*) (skb
->data
+ ETH_HLEN
);
2493 memset(daddr
, 0, sizeof(daddr
));
2496 memcpy(&daddr
[8], iucv_hdr
->destUserID
, 8);
2497 memcpy(hdr
->hdr
.l3
.dest_addr
, daddr
, 16);
2500 static void qeth_l3_fill_header(struct qeth_card
*card
, struct qeth_hdr
*hdr
,
2501 struct sk_buff
*skb
, int ipv
, int cast_type
)
2503 struct dst_entry
*dst
;
2505 memset(hdr
, 0, sizeof(struct qeth_hdr
));
2506 hdr
->hdr
.l3
.id
= QETH_HEADER_TYPE_LAYER3
;
2507 hdr
->hdr
.l3
.ext_flags
= 0;
2510 * before we're going to overwrite this location with next hop ip.
2511 * v6 uses passthrough, v4 sets the tag in the QDIO header.
2513 if (skb_vlan_tag_present(skb
)) {
2514 if ((ipv
== 4) || (card
->info
.type
== QETH_CARD_TYPE_IQD
))
2515 hdr
->hdr
.l3
.ext_flags
= QETH_HDR_EXT_VLAN_FRAME
;
2517 hdr
->hdr
.l3
.ext_flags
= QETH_HDR_EXT_INCLUDE_VLAN_TAG
;
2518 hdr
->hdr
.l3
.vlan_id
= skb_vlan_tag_get(skb
);
2521 hdr
->hdr
.l3
.length
= skb
->len
- sizeof(struct qeth_hdr
);
2526 struct rtable
*rt
= (struct rtable
*) dst
;
2527 __be32
*pkey
= &ip_hdr(skb
)->daddr
;
2529 if (rt
&& rt
->rt_gateway
)
2530 pkey
= &rt
->rt_gateway
;
2533 hdr
->hdr
.l3
.flags
= qeth_l3_get_qeth_hdr_flags4(cast_type
);
2534 memset(hdr
->hdr
.l3
.dest_addr
, 0, 12);
2535 *((__be32
*) (&hdr
->hdr
.l3
.dest_addr
[12])) = *pkey
;
2536 } else if (ipv
== 6) {
2537 struct rt6_info
*rt
= (struct rt6_info
*) dst
;
2538 struct in6_addr
*pkey
= &ipv6_hdr(skb
)->daddr
;
2540 if (rt
&& !ipv6_addr_any(&rt
->rt6i_gateway
))
2541 pkey
= &rt
->rt6i_gateway
;
2544 hdr
->hdr
.l3
.flags
= qeth_l3_get_qeth_hdr_flags6(cast_type
);
2545 if (card
->info
.type
== QETH_CARD_TYPE_IQD
)
2546 hdr
->hdr
.l3
.flags
&= ~QETH_HDR_PASSTHRU
;
2547 memcpy(hdr
->hdr
.l3
.dest_addr
, pkey
, 16);
2549 if (!memcmp(skb
->data
+ sizeof(struct qeth_hdr
),
2550 skb
->dev
->broadcast
, 6)) {
2552 hdr
->hdr
.l3
.flags
= QETH_CAST_BROADCAST
|
2555 hdr
->hdr
.l3
.flags
= (cast_type
== RTN_MULTICAST
) ?
2556 QETH_CAST_MULTICAST
| QETH_HDR_PASSTHRU
:
2557 QETH_CAST_UNICAST
| QETH_HDR_PASSTHRU
;
2563 static void qeth_l3_hdr_csum(struct qeth_card
*card
, struct qeth_hdr
*hdr
,
2564 struct sk_buff
*skb
)
2566 struct iphdr
*iph
= ip_hdr(skb
);
2568 /* tcph->check contains already the pseudo hdr checksum
2569 * so just set the header flags
2571 if (iph
->protocol
== IPPROTO_UDP
)
2572 hdr
->hdr
.l3
.ext_flags
|= QETH_HDR_EXT_UDP
;
2573 hdr
->hdr
.l3
.ext_flags
|= QETH_HDR_EXT_CSUM_TRANSP_REQ
|
2574 QETH_HDR_EXT_CSUM_HDR_REQ
;
2576 if (card
->options
.performance_stats
)
2577 card
->perf_stats
.tx_csum
++;
2580 static void qeth_tso_fill_header(struct qeth_card
*card
,
2581 struct qeth_hdr
*qhdr
, struct sk_buff
*skb
)
2583 struct qeth_hdr_tso
*hdr
= (struct qeth_hdr_tso
*)qhdr
;
2584 struct tcphdr
*tcph
= tcp_hdr(skb
);
2585 struct iphdr
*iph
= ip_hdr(skb
);
2586 struct ipv6hdr
*ip6h
= ipv6_hdr(skb
);
2588 /*fix header to TSO values ...*/
2589 hdr
->hdr
.hdr
.l3
.id
= QETH_HEADER_TYPE_TSO
;
2590 hdr
->hdr
.hdr
.l3
.length
= skb
->len
- sizeof(struct qeth_hdr_tso
);
2591 /*set values which are fix for the first approach ...*/
2592 hdr
->ext
.hdr_tot_len
= (__u16
) sizeof(struct qeth_hdr_ext_tso
);
2593 hdr
->ext
.imb_hdr_no
= 1;
2594 hdr
->ext
.hdr_type
= 1;
2595 hdr
->ext
.hdr_version
= 1;
2596 hdr
->ext
.hdr_len
= 28;
2597 /*insert non-fix values */
2598 hdr
->ext
.mss
= skb_shinfo(skb
)->gso_size
;
2599 hdr
->ext
.dg_hdr_len
= (__u16
)(ip_hdrlen(skb
) + tcp_hdrlen(skb
));
2600 hdr
->ext
.payload_len
= (__u16
)(skb
->len
- hdr
->ext
.dg_hdr_len
-
2601 sizeof(struct qeth_hdr_tso
));
2603 if (be16_to_cpu(skb
->protocol
) == ETH_P_IPV6
) {
2604 ip6h
->payload_len
= 0;
2605 tcph
->check
= ~csum_ipv6_magic(&ip6h
->saddr
, &ip6h
->daddr
,
2608 /*OSA want us to set these values ...*/
2609 tcph
->check
= ~csum_tcpudp_magic(iph
->saddr
, iph
->daddr
,
2617 * qeth_l3_get_elements_no_tso() - find number of SBALEs for skb data for tso
2618 * @card: qeth card structure, to check max. elems.
2620 * @extra_elems: extra elems needed, to check against max.
2622 * Returns the number of pages, and thus QDIO buffer elements, needed to cover
2623 * skb data, including linear part and fragments, but excluding TCP header.
2624 * (Exclusion of TCP header distinguishes it from qeth_get_elements_no().)
2625 * Checks if the result plus extra_elems fits under the limit for the card.
2626 * Returns 0 if it does not.
2627 * Note: extra_elems is not included in the returned result.
2629 static int qeth_l3_get_elements_no_tso(struct qeth_card
*card
,
2630 struct sk_buff
*skb
, int extra_elems
)
2632 addr_t tcpdptr
= (addr_t
)tcp_hdr(skb
) + tcp_hdrlen(skb
);
2633 int elements
= qeth_get_elements_for_range(
2635 (addr_t
)skb
->data
+ skb_headlen(skb
)) +
2636 qeth_get_elements_for_frags(skb
);
2638 if ((elements
+ extra_elems
) > QETH_MAX_BUFFER_ELEMENTS(card
)) {
2640 "Invalid size of TSO IP packet (Number=%d / Length=%d). Discarded.\n",
2641 elements
+ extra_elems
, skb
->len
);
2647 static netdev_tx_t
qeth_l3_hard_start_xmit(struct sk_buff
*skb
,
2648 struct net_device
*dev
)
2652 struct qeth_hdr
*hdr
= NULL
;
2653 int hdr_elements
= 0;
2655 struct qeth_card
*card
= dev
->ml_priv
;
2656 struct sk_buff
*new_skb
= NULL
;
2657 int ipv
= qeth_get_ip_version(skb
);
2658 int cast_type
= qeth_l3_get_cast_type(card
, skb
);
2659 struct qeth_qdio_out_q
*queue
=
2660 card
->qdio
.out_qs
[card
->qdio
.do_prio_queueing
2661 || (cast_type
&& card
->info
.is_multicast_different
) ?
2662 qeth_get_priority_queue(card
, skb
, ipv
, cast_type
) :
2663 card
->qdio
.default_out_queue
];
2664 int tx_bytes
= skb
->len
;
2665 unsigned int hd_len
= 0;
2667 int data_offset
= -1;
2668 unsigned int nr_frags
;
2670 if (((card
->info
.type
== QETH_CARD_TYPE_IQD
) &&
2671 (((card
->options
.cq
!= QETH_CQ_ENABLED
) && !ipv
) ||
2672 ((card
->options
.cq
== QETH_CQ_ENABLED
) &&
2673 (be16_to_cpu(skb
->protocol
) != ETH_P_AF_IUCV
)))) ||
2674 card
->options
.sniffer
)
2677 if ((card
->state
!= CARD_STATE_UP
) || !card
->lan_online
) {
2678 card
->stats
.tx_carrier_errors
++;
2682 if ((cast_type
== RTN_BROADCAST
) &&
2683 (card
->info
.broadcast_capable
== 0))
2686 if (card
->options
.performance_stats
) {
2687 card
->perf_stats
.outbound_cnt
++;
2688 card
->perf_stats
.outbound_start_time
= qeth_get_micros();
2691 /* Ignore segment size from skb_is_gso(), 1 page is always used. */
2692 use_tso
= skb_is_gso(skb
) &&
2693 (skb_shinfo(skb
)->gso_type
& SKB_GSO_TCPV4
);
2695 if (card
->info
.type
== QETH_CARD_TYPE_IQD
) {
2697 data_offset
= ETH_HLEN
;
2698 hd_len
= sizeof(*hdr
);
2699 hdr
= kmem_cache_alloc(qeth_core_header_cache
, GFP_ATOMIC
);
2704 /* create a clone with writeable headroom */
2705 new_skb
= skb_realloc_headroom(skb
, sizeof(struct qeth_hdr_tso
)
2711 skb_pull(new_skb
, ETH_HLEN
);
2714 if (ipv
!= 4 && skb_vlan_tag_present(new_skb
)) {
2715 skb_push(new_skb
, VLAN_HLEN
);
2716 skb_copy_to_linear_data(new_skb
, new_skb
->data
+ 4, 4);
2717 skb_copy_to_linear_data_offset(new_skb
, 4,
2718 new_skb
->data
+ 8, 4);
2719 skb_copy_to_linear_data_offset(new_skb
, 8,
2720 new_skb
->data
+ 12, 4);
2721 tag
= (__be16
*)(new_skb
->data
+ 12);
2722 *tag
= cpu_to_be16(ETH_P_8021Q
);
2723 *(tag
+ 1) = cpu_to_be16(skb_vlan_tag_get(new_skb
));
2727 netif_stop_queue(dev
);
2729 /* fix hardware limitation: as long as we do not have sbal
2730 * chaining we can not send long frag lists
2732 if ((card
->info
.type
!= QETH_CARD_TYPE_IQD
) &&
2733 ((use_tso
&& !qeth_l3_get_elements_no_tso(card
, new_skb
, 1)) ||
2734 (!use_tso
&& !qeth_get_elements_no(card
, new_skb
, 0, 0)))) {
2735 int lin_rc
= skb_linearize(new_skb
);
2737 if (card
->options
.performance_stats
) {
2739 card
->perf_stats
.tx_linfail
++;
2741 card
->perf_stats
.tx_lin
++;
2746 nr_frags
= skb_shinfo(new_skb
)->nr_frags
;
2749 hdr
= skb_push(new_skb
, sizeof(struct qeth_hdr_tso
));
2750 memset(hdr
, 0, sizeof(struct qeth_hdr_tso
));
2751 qeth_l3_fill_header(card
, hdr
, new_skb
, ipv
, cast_type
);
2752 qeth_tso_fill_header(card
, hdr
, new_skb
);
2755 if (data_offset
< 0) {
2756 hdr
= skb_push(new_skb
, sizeof(struct qeth_hdr
));
2757 qeth_l3_fill_header(card
, hdr
, new_skb
, ipv
,
2760 if (be16_to_cpu(new_skb
->protocol
) == ETH_P_AF_IUCV
)
2761 qeth_l3_fill_af_iucv_hdr(card
, hdr
, new_skb
);
2763 qeth_l3_fill_header(card
, hdr
, new_skb
, ipv
,
2765 hdr
->hdr
.l3
.length
= new_skb
->len
- data_offset
;
2769 if (skb
->ip_summed
== CHECKSUM_PARTIAL
)
2770 qeth_l3_hdr_csum(card
, hdr
, new_skb
);
2773 elements
= use_tso
?
2774 qeth_l3_get_elements_no_tso(card
, new_skb
, hdr_elements
) :
2775 qeth_get_elements_no(card
, new_skb
, hdr_elements
,
2776 (data_offset
> 0) ? data_offset
: 0);
2778 if (data_offset
>= 0)
2779 kmem_cache_free(qeth_core_header_cache
, hdr
);
2782 elements
+= hdr_elements
;
2784 if (card
->info
.type
!= QETH_CARD_TYPE_IQD
) {
2787 hd_len
= sizeof(struct qeth_hdr_tso
) +
2788 ip_hdrlen(new_skb
) + tcp_hdrlen(new_skb
);
2791 len
= sizeof(struct qeth_hdr_layer3
);
2794 if (qeth_hdr_chk_and_bounce(new_skb
, &hdr
, len
))
2796 rc
= qeth_do_send_packet(card
, queue
, new_skb
, hdr
, hd_len
,
2799 rc
= qeth_do_send_packet_fast(queue
, new_skb
, hdr
, data_offset
,
2803 card
->stats
.tx_packets
++;
2804 card
->stats
.tx_bytes
+= tx_bytes
;
2806 dev_kfree_skb_any(skb
);
2807 if (card
->options
.performance_stats
) {
2809 card
->perf_stats
.large_send_bytes
+= tx_bytes
;
2810 card
->perf_stats
.large_send_cnt
++;
2813 card
->perf_stats
.sg_skbs_sent
++;
2814 /* nr_frags + skb->data */
2815 card
->perf_stats
.sg_frags_sent
+= nr_frags
+ 1;
2820 if (data_offset
>= 0)
2821 kmem_cache_free(qeth_core_header_cache
, hdr
);
2825 dev_kfree_skb_any(new_skb
);
2826 return NETDEV_TX_BUSY
;
2831 netif_wake_queue(dev
);
2832 if (card
->options
.performance_stats
)
2833 card
->perf_stats
.outbound_time
+= qeth_get_micros() -
2834 card
->perf_stats
.outbound_start_time
;
2838 card
->stats
.tx_dropped
++;
2839 card
->stats
.tx_errors
++;
2840 if ((new_skb
!= skb
) && new_skb
)
2841 dev_kfree_skb_any(new_skb
);
2842 dev_kfree_skb_any(skb
);
2843 netif_wake_queue(dev
);
2844 return NETDEV_TX_OK
;
2847 static int __qeth_l3_open(struct net_device
*dev
)
2849 struct qeth_card
*card
= dev
->ml_priv
;
2852 QETH_CARD_TEXT(card
, 4, "qethopen");
2853 if (card
->state
== CARD_STATE_UP
)
2855 if (card
->state
!= CARD_STATE_SOFTSETUP
)
2857 card
->data
.state
= CH_STATE_UP
;
2858 card
->state
= CARD_STATE_UP
;
2859 netif_start_queue(dev
);
2861 if (qdio_stop_irq(card
->data
.ccwdev
, 0) >= 0) {
2862 napi_enable(&card
->napi
);
2863 napi_schedule(&card
->napi
);
2869 static int qeth_l3_open(struct net_device
*dev
)
2871 struct qeth_card
*card
= dev
->ml_priv
;
2873 QETH_CARD_TEXT(card
, 5, "qethope_");
2874 if (qeth_wait_for_threads(card
, QETH_RECOVER_THREAD
)) {
2875 QETH_CARD_TEXT(card
, 3, "openREC");
2876 return -ERESTARTSYS
;
2878 return __qeth_l3_open(dev
);
2881 static int qeth_l3_stop(struct net_device
*dev
)
2883 struct qeth_card
*card
= dev
->ml_priv
;
2885 QETH_CARD_TEXT(card
, 4, "qethstop");
2886 netif_tx_disable(dev
);
2887 if (card
->state
== CARD_STATE_UP
) {
2888 card
->state
= CARD_STATE_SOFTSETUP
;
2889 napi_disable(&card
->napi
);
2894 static const struct ethtool_ops qeth_l3_ethtool_ops
= {
2895 .get_link
= ethtool_op_get_link
,
2896 .get_strings
= qeth_core_get_strings
,
2897 .get_ethtool_stats
= qeth_core_get_ethtool_stats
,
2898 .get_sset_count
= qeth_core_get_sset_count
,
2899 .get_drvinfo
= qeth_core_get_drvinfo
,
2900 .get_link_ksettings
= qeth_core_ethtool_get_link_ksettings
,
2904 * we need NOARP for IPv4 but we want neighbor solicitation for IPv6. Setting
2905 * NOARP on the netdevice is no option because it also turns off neighbor
2906 * solicitation. For IPv4 we install a neighbor_setup function. We don't want
2907 * arp resolution but we want the hard header (packet socket will work
2910 static int qeth_l3_neigh_setup_noarp(struct neighbour
*n
)
2912 n
->nud_state
= NUD_NOARP
;
2913 memcpy(n
->ha
, "FAKELL", 6);
2914 n
->output
= n
->ops
->connected_output
;
2919 qeth_l3_neigh_setup(struct net_device
*dev
, struct neigh_parms
*np
)
2921 if (np
->tbl
->family
== AF_INET
)
2922 np
->neigh_setup
= qeth_l3_neigh_setup_noarp
;
2927 static const struct net_device_ops qeth_l3_netdev_ops
= {
2928 .ndo_open
= qeth_l3_open
,
2929 .ndo_stop
= qeth_l3_stop
,
2930 .ndo_get_stats
= qeth_get_stats
,
2931 .ndo_start_xmit
= qeth_l3_hard_start_xmit
,
2932 .ndo_validate_addr
= eth_validate_addr
,
2933 .ndo_set_rx_mode
= qeth_l3_set_multicast_list
,
2934 .ndo_do_ioctl
= qeth_do_ioctl
,
2935 .ndo_change_mtu
= qeth_change_mtu
,
2936 .ndo_fix_features
= qeth_fix_features
,
2937 .ndo_set_features
= qeth_set_features
,
2938 .ndo_vlan_rx_add_vid
= qeth_l3_vlan_rx_add_vid
,
2939 .ndo_vlan_rx_kill_vid
= qeth_l3_vlan_rx_kill_vid
,
2940 .ndo_tx_timeout
= qeth_tx_timeout
,
2943 static const struct net_device_ops qeth_l3_osa_netdev_ops
= {
2944 .ndo_open
= qeth_l3_open
,
2945 .ndo_stop
= qeth_l3_stop
,
2946 .ndo_get_stats
= qeth_get_stats
,
2947 .ndo_start_xmit
= qeth_l3_hard_start_xmit
,
2948 .ndo_features_check
= qeth_features_check
,
2949 .ndo_validate_addr
= eth_validate_addr
,
2950 .ndo_set_rx_mode
= qeth_l3_set_multicast_list
,
2951 .ndo_do_ioctl
= qeth_do_ioctl
,
2952 .ndo_change_mtu
= qeth_change_mtu
,
2953 .ndo_fix_features
= qeth_fix_features
,
2954 .ndo_set_features
= qeth_set_features
,
2955 .ndo_vlan_rx_add_vid
= qeth_l3_vlan_rx_add_vid
,
2956 .ndo_vlan_rx_kill_vid
= qeth_l3_vlan_rx_kill_vid
,
2957 .ndo_tx_timeout
= qeth_tx_timeout
,
2958 .ndo_neigh_setup
= qeth_l3_neigh_setup
,
2961 static int qeth_l3_setup_netdev(struct qeth_card
*card
)
2965 if (card
->info
.type
== QETH_CARD_TYPE_OSD
||
2966 card
->info
.type
== QETH_CARD_TYPE_OSX
) {
2967 if ((card
->info
.link_type
== QETH_LINK_TYPE_LANE_TR
) ||
2968 (card
->info
.link_type
== QETH_LINK_TYPE_HSTR
)) {
2969 pr_info("qeth_l3: ignoring TR device\n");
2972 card
->dev
= alloc_etherdev(0);
2975 card
->dev
->netdev_ops
= &qeth_l3_osa_netdev_ops
;
2977 /*IPv6 address autoconfiguration stuff*/
2978 qeth_l3_get_unique_id(card
);
2979 if (!(card
->info
.unique_id
& UNIQUE_ID_NOT_BY_CARD
))
2980 card
->dev
->dev_id
= card
->info
.unique_id
&
2982 if (!card
->info
.guestlan
) {
2983 card
->dev
->hw_features
= NETIF_F_SG
|
2984 NETIF_F_RXCSUM
| NETIF_F_IP_CSUM
|
2986 card
->dev
->vlan_features
= NETIF_F_SG
|
2987 NETIF_F_RXCSUM
| NETIF_F_IP_CSUM
|
2989 card
->dev
->features
|= NETIF_F_SG
;
2992 } else if (card
->info
.type
== QETH_CARD_TYPE_IQD
) {
2993 card
->dev
= alloc_netdev(0, "hsi%d", NET_NAME_UNKNOWN
,
2997 card
->dev
->flags
|= IFF_NOARP
;
2998 card
->dev
->netdev_ops
= &qeth_l3_netdev_ops
;
2999 rc
= qeth_l3_iqd_read_initial_mac(card
);
3002 if (card
->options
.hsuid
[0])
3003 memcpy(card
->dev
->perm_addr
, card
->options
.hsuid
, 9);
3007 card
->dev
->ml_priv
= card
;
3008 card
->dev
->watchdog_timeo
= QETH_TX_TIMEOUT
;
3009 card
->dev
->mtu
= card
->info
.initial_mtu
;
3010 card
->dev
->min_mtu
= 64;
3011 card
->dev
->max_mtu
= ETH_MAX_MTU
;
3012 card
->dev
->ethtool_ops
= &qeth_l3_ethtool_ops
;
3013 card
->dev
->features
|= NETIF_F_HW_VLAN_CTAG_TX
|
3014 NETIF_F_HW_VLAN_CTAG_RX
|
3015 NETIF_F_HW_VLAN_CTAG_FILTER
;
3016 netif_keep_dst(card
->dev
);
3017 netif_set_gso_max_size(card
->dev
, (QETH_MAX_BUFFER_ELEMENTS(card
) - 1) *
3020 SET_NETDEV_DEV(card
->dev
, &card
->gdev
->dev
);
3021 netif_napi_add(card
->dev
, &card
->napi
, qeth_poll
, QETH_NAPI_WEIGHT
);
3022 netif_carrier_off(card
->dev
);
3023 return register_netdev(card
->dev
);
3026 static const struct device_type qeth_l3_devtype
= {
3027 .name
= "qeth_layer3",
3028 .groups
= qeth_l3_attr_groups
,
3031 static int qeth_l3_probe_device(struct ccwgroup_device
*gdev
)
3033 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
3036 if (gdev
->dev
.type
== &qeth_generic_devtype
) {
3037 rc
= qeth_l3_create_device_attributes(&gdev
->dev
);
3041 hash_init(card
->ip_htable
);
3042 hash_init(card
->ip_mc_htable
);
3043 card
->options
.layer2
= 0;
3044 card
->info
.hwtrap
= 0;
3048 static void qeth_l3_remove_device(struct ccwgroup_device
*cgdev
)
3050 struct qeth_card
*card
= dev_get_drvdata(&cgdev
->dev
);
3052 if (cgdev
->dev
.type
== &qeth_generic_devtype
)
3053 qeth_l3_remove_device_attributes(&cgdev
->dev
);
3055 qeth_set_allowed_threads(card
, 0, 1);
3056 wait_event(card
->wait_q
, qeth_threads_running(card
, 0xffffffff) == 0);
3058 if (cgdev
->state
== CCWGROUP_ONLINE
)
3059 qeth_l3_set_offline(cgdev
);
3062 netif_napi_del(&card
->napi
);
3063 unregister_netdev(card
->dev
);
3067 qeth_l3_clear_ip_htable(card
, 0);
3068 qeth_l3_clear_ipato_list(card
);
3072 static int __qeth_l3_set_online(struct ccwgroup_device
*gdev
, int recovery_mode
)
3074 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
3076 enum qeth_card_states recover_flag
;
3078 mutex_lock(&card
->discipline_mutex
);
3079 mutex_lock(&card
->conf_mutex
);
3080 QETH_DBF_TEXT(SETUP
, 2, "setonlin");
3081 QETH_DBF_HEX(SETUP
, 2, &card
, sizeof(void *));
3083 recover_flag
= card
->state
;
3084 rc
= qeth_core_hardsetup_card(card
);
3086 QETH_DBF_TEXT_(SETUP
, 2, "2err%04x", rc
);
3091 if (!card
->dev
&& qeth_l3_setup_netdev(card
)) {
3096 if (qeth_is_diagass_supported(card
, QETH_DIAGS_CMD_TRAP
)) {
3097 if (card
->info
.hwtrap
&&
3098 qeth_hw_trap(card
, QETH_DIAGS_TRAP_ARM
))
3099 card
->info
.hwtrap
= 0;
3101 card
->info
.hwtrap
= 0;
3103 card
->state
= CARD_STATE_HARDSETUP
;
3104 memset(&card
->rx
, 0, sizeof(struct qeth_rx
));
3105 qeth_print_status_message(card
);
3108 QETH_DBF_TEXT(SETUP
, 2, "softsetp");
3110 rc
= qeth_l3_setadapter_parms(card
);
3112 QETH_DBF_TEXT_(SETUP
, 2, "2err%04x", rc
);
3113 if (!card
->options
.sniffer
) {
3114 rc
= qeth_l3_start_ipassists(card
);
3116 QETH_DBF_TEXT_(SETUP
, 2, "3err%d", rc
);
3119 rc
= qeth_l3_setrouting_v4(card
);
3121 QETH_DBF_TEXT_(SETUP
, 2, "4err%04x", rc
);
3122 rc
= qeth_l3_setrouting_v6(card
);
3124 QETH_DBF_TEXT_(SETUP
, 2, "5err%04x", rc
);
3126 netif_tx_disable(card
->dev
);
3128 rc
= qeth_init_qdio_queues(card
);
3130 QETH_DBF_TEXT_(SETUP
, 2, "6err%d", rc
);
3134 card
->state
= CARD_STATE_SOFTSETUP
;
3136 qeth_set_allowed_threads(card
, 0xffffffff, 0);
3137 qeth_l3_recover_ip(card
);
3138 if (card
->lan_online
)
3139 netif_carrier_on(card
->dev
);
3141 netif_carrier_off(card
->dev
);
3142 if (recover_flag
== CARD_STATE_RECOVER
) {
3145 __qeth_l3_open(card
->dev
);
3147 dev_open(card
->dev
);
3148 qeth_l3_set_multicast_list(card
->dev
);
3149 qeth_recover_features(card
->dev
);
3152 qeth_trace_features(card
);
3153 /* let user_space know that device is online */
3154 kobject_uevent(&gdev
->dev
.kobj
, KOBJ_CHANGE
);
3155 mutex_unlock(&card
->conf_mutex
);
3156 mutex_unlock(&card
->discipline_mutex
);
3159 qeth_l3_stop_card(card
, 0);
3160 ccw_device_set_offline(CARD_DDEV(card
));
3161 ccw_device_set_offline(CARD_WDEV(card
));
3162 ccw_device_set_offline(CARD_RDEV(card
));
3163 qdio_free(CARD_DDEV(card
));
3164 if (recover_flag
== CARD_STATE_RECOVER
)
3165 card
->state
= CARD_STATE_RECOVER
;
3167 card
->state
= CARD_STATE_DOWN
;
3168 mutex_unlock(&card
->conf_mutex
);
3169 mutex_unlock(&card
->discipline_mutex
);
3173 static int qeth_l3_set_online(struct ccwgroup_device
*gdev
)
3175 return __qeth_l3_set_online(gdev
, 0);
3178 static int __qeth_l3_set_offline(struct ccwgroup_device
*cgdev
,
3181 struct qeth_card
*card
= dev_get_drvdata(&cgdev
->dev
);
3182 int rc
= 0, rc2
= 0, rc3
= 0;
3183 enum qeth_card_states recover_flag
;
3185 mutex_lock(&card
->discipline_mutex
);
3186 mutex_lock(&card
->conf_mutex
);
3187 QETH_DBF_TEXT(SETUP
, 3, "setoffl");
3188 QETH_DBF_HEX(SETUP
, 3, &card
, sizeof(void *));
3190 if (card
->dev
&& netif_carrier_ok(card
->dev
))
3191 netif_carrier_off(card
->dev
);
3192 recover_flag
= card
->state
;
3193 if ((!recovery_mode
&& card
->info
.hwtrap
) || card
->info
.hwtrap
== 2) {
3194 qeth_hw_trap(card
, QETH_DIAGS_TRAP_DISARM
);
3195 card
->info
.hwtrap
= 1;
3197 qeth_l3_stop_card(card
, recovery_mode
);
3198 if ((card
->options
.cq
== QETH_CQ_ENABLED
) && card
->dev
) {
3200 call_netdevice_notifiers(NETDEV_REBOOT
, card
->dev
);
3203 rc
= ccw_device_set_offline(CARD_DDEV(card
));
3204 rc2
= ccw_device_set_offline(CARD_WDEV(card
));
3205 rc3
= ccw_device_set_offline(CARD_RDEV(card
));
3207 rc
= (rc2
) ? rc2
: rc3
;
3209 QETH_DBF_TEXT_(SETUP
, 2, "1err%d", rc
);
3210 qdio_free(CARD_DDEV(card
));
3211 if (recover_flag
== CARD_STATE_UP
)
3212 card
->state
= CARD_STATE_RECOVER
;
3213 /* let user_space know that device is offline */
3214 kobject_uevent(&cgdev
->dev
.kobj
, KOBJ_CHANGE
);
3215 mutex_unlock(&card
->conf_mutex
);
3216 mutex_unlock(&card
->discipline_mutex
);
3220 static int qeth_l3_set_offline(struct ccwgroup_device
*cgdev
)
3222 return __qeth_l3_set_offline(cgdev
, 0);
3225 static int qeth_l3_recover(void *ptr
)
3227 struct qeth_card
*card
;
3230 card
= (struct qeth_card
*) ptr
;
3231 QETH_CARD_TEXT(card
, 2, "recover1");
3232 QETH_CARD_HEX(card
, 2, &card
, sizeof(void *));
3233 if (!qeth_do_run_thread(card
, QETH_RECOVER_THREAD
))
3235 QETH_CARD_TEXT(card
, 2, "recover2");
3236 dev_warn(&card
->gdev
->dev
,
3237 "A recovery process has been started for the device\n");
3238 qeth_set_recovery_task(card
);
3239 __qeth_l3_set_offline(card
->gdev
, 1);
3240 rc
= __qeth_l3_set_online(card
->gdev
, 1);
3242 dev_info(&card
->gdev
->dev
,
3243 "Device successfully recovered!\n");
3245 qeth_close_dev(card
);
3246 dev_warn(&card
->gdev
->dev
, "The qeth device driver "
3247 "failed to recover an error on the device\n");
3249 qeth_clear_recovery_task(card
);
3250 qeth_clear_thread_start_bit(card
, QETH_RECOVER_THREAD
);
3251 qeth_clear_thread_running_bit(card
, QETH_RECOVER_THREAD
);
3255 static int qeth_l3_pm_suspend(struct ccwgroup_device
*gdev
)
3257 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
3260 netif_device_detach(card
->dev
);
3261 qeth_set_allowed_threads(card
, 0, 1);
3262 wait_event(card
->wait_q
, qeth_threads_running(card
, 0xffffffff) == 0);
3263 if (gdev
->state
== CCWGROUP_OFFLINE
)
3265 if (card
->state
== CARD_STATE_UP
) {
3266 if (card
->info
.hwtrap
)
3267 qeth_hw_trap(card
, QETH_DIAGS_TRAP_DISARM
);
3268 __qeth_l3_set_offline(card
->gdev
, 1);
3270 __qeth_l3_set_offline(card
->gdev
, 0);
3274 static int qeth_l3_pm_resume(struct ccwgroup_device
*gdev
)
3276 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
3279 if (gdev
->state
== CCWGROUP_OFFLINE
)
3282 if (card
->state
== CARD_STATE_RECOVER
) {
3283 rc
= __qeth_l3_set_online(card
->gdev
, 1);
3286 dev_close(card
->dev
);
3290 rc
= __qeth_l3_set_online(card
->gdev
, 0);
3292 qeth_set_allowed_threads(card
, 0xffffffff, 0);
3294 netif_device_attach(card
->dev
);
3296 dev_warn(&card
->gdev
->dev
, "The qeth device driver "
3297 "failed to recover an error on the device\n");
3301 /* Returns zero if the command is successfully "consumed" */
3302 static int qeth_l3_control_event(struct qeth_card
*card
,
3303 struct qeth_ipa_cmd
*cmd
)
3308 struct qeth_discipline qeth_l3_discipline
= {
3309 .devtype
= &qeth_l3_devtype
,
3310 .start_poll
= qeth_qdio_start_poll
,
3311 .input_handler
= (qdio_handler_t
*) qeth_qdio_input_handler
,
3312 .output_handler
= (qdio_handler_t
*) qeth_qdio_output_handler
,
3313 .process_rx_buffer
= qeth_l3_process_inbound_buffer
,
3314 .recover
= qeth_l3_recover
,
3315 .setup
= qeth_l3_probe_device
,
3316 .remove
= qeth_l3_remove_device
,
3317 .set_online
= qeth_l3_set_online
,
3318 .set_offline
= qeth_l3_set_offline
,
3319 .freeze
= qeth_l3_pm_suspend
,
3320 .thaw
= qeth_l3_pm_resume
,
3321 .restore
= qeth_l3_pm_resume
,
3322 .do_ioctl
= qeth_l3_do_ioctl
,
3323 .control_event_handler
= qeth_l3_control_event
,
3325 EXPORT_SYMBOL_GPL(qeth_l3_discipline
);
3327 static int qeth_l3_ip_event(struct notifier_block
*this,
3328 unsigned long event
, void *ptr
)
3331 struct in_ifaddr
*ifa
= (struct in_ifaddr
*)ptr
;
3332 struct net_device
*dev
= (struct net_device
*)ifa
->ifa_dev
->dev
;
3333 struct qeth_ipaddr
*addr
;
3334 struct qeth_card
*card
;
3336 if (dev_net(dev
) != &init_net
)
3339 card
= qeth_l3_get_card_from_dev(dev
);
3342 QETH_CARD_TEXT(card
, 3, "ipevent");
3344 addr
= qeth_l3_get_addr_buffer(QETH_PROT_IPV4
);
3346 addr
->u
.a4
.addr
= be32_to_cpu(ifa
->ifa_address
);
3347 addr
->u
.a4
.mask
= be32_to_cpu(ifa
->ifa_mask
);
3348 addr
->type
= QETH_IP_TYPE_NORMAL
;
3354 spin_lock_bh(&card
->ip_lock
);
3355 qeth_l3_add_ip(card
, addr
);
3356 spin_unlock_bh(&card
->ip_lock
);
3359 spin_lock_bh(&card
->ip_lock
);
3360 qeth_l3_delete_ip(card
, addr
);
3361 spin_unlock_bh(&card
->ip_lock
);
3369 static struct notifier_block qeth_l3_ip_notifier
= {
3374 #ifdef CONFIG_QETH_IPV6
3376 * IPv6 event handler
3378 static int qeth_l3_ip6_event(struct notifier_block
*this,
3379 unsigned long event
, void *ptr
)
3381 struct inet6_ifaddr
*ifa
= (struct inet6_ifaddr
*)ptr
;
3382 struct net_device
*dev
= (struct net_device
*)ifa
->idev
->dev
;
3383 struct qeth_ipaddr
*addr
;
3384 struct qeth_card
*card
;
3386 card
= qeth_l3_get_card_from_dev(dev
);
3389 QETH_CARD_TEXT(card
, 3, "ip6event");
3390 if (!qeth_is_supported(card
, IPA_IPV6
))
3393 addr
= qeth_l3_get_addr_buffer(QETH_PROT_IPV6
);
3395 memcpy(&addr
->u
.a6
.addr
, &ifa
->addr
, sizeof(struct in6_addr
));
3396 addr
->u
.a6
.pfxlen
= ifa
->prefix_len
;
3397 addr
->type
= QETH_IP_TYPE_NORMAL
;
3403 spin_lock_bh(&card
->ip_lock
);
3404 qeth_l3_add_ip(card
, addr
);
3405 spin_unlock_bh(&card
->ip_lock
);
3408 spin_lock_bh(&card
->ip_lock
);
3409 qeth_l3_delete_ip(card
, addr
);
3410 spin_unlock_bh(&card
->ip_lock
);
3418 static struct notifier_block qeth_l3_ip6_notifier
= {
3424 static int qeth_l3_register_notifiers(void)
3428 QETH_DBF_TEXT(SETUP
, 5, "regnotif");
3429 rc
= register_inetaddr_notifier(&qeth_l3_ip_notifier
);
3432 #ifdef CONFIG_QETH_IPV6
3433 rc
= register_inet6addr_notifier(&qeth_l3_ip6_notifier
);
3435 unregister_inetaddr_notifier(&qeth_l3_ip_notifier
);
3439 pr_warn("There is no IPv6 support for the layer 3 discipline\n");
3444 static void qeth_l3_unregister_notifiers(void)
3447 QETH_DBF_TEXT(SETUP
, 5, "unregnot");
3448 WARN_ON(unregister_inetaddr_notifier(&qeth_l3_ip_notifier
));
3449 #ifdef CONFIG_QETH_IPV6
3450 WARN_ON(unregister_inet6addr_notifier(&qeth_l3_ip6_notifier
));
3451 #endif /* QETH_IPV6 */
3454 static int __init
qeth_l3_init(void)
3458 pr_info("register layer 3 discipline\n");
3459 rc
= qeth_l3_register_notifiers();
3463 static void __exit
qeth_l3_exit(void)
3465 qeth_l3_unregister_notifiers();
3466 pr_info("unregister layer 3 discipline\n");
3469 module_init(qeth_l3_init
);
3470 module_exit(qeth_l3_exit
);
3471 MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
3472 MODULE_DESCRIPTION("qeth layer 3 discipline");
3473 MODULE_LICENSE("GPL");