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>
22 #include <linux/ipv6.h>
23 #include <linux/inetdevice.h>
24 #include <linux/igmp.h>
25 #include <linux/slab.h>
26 #include <linux/if_ether.h>
27 #include <linux/if_vlan.h>
28 #include <linux/skbuff.h>
32 #include <net/route.h>
34 #include <net/ip6_route.h>
35 #include <net/ip6_fib.h>
36 #include <net/ip6_checksum.h>
37 #include <net/iucv/af_iucv.h>
38 #include <linux/hashtable.h>
43 static int qeth_l3_set_offline(struct ccwgroup_device
*);
44 static int qeth_l3_stop(struct net_device
*);
45 static void qeth_l3_set_rx_mode(struct net_device
*dev
);
46 static int qeth_l3_register_addr_entry(struct qeth_card
*,
47 struct qeth_ipaddr
*);
48 static int qeth_l3_deregister_addr_entry(struct qeth_card
*,
49 struct qeth_ipaddr
*);
51 static void qeth_l3_ipaddr4_to_string(const __u8
*addr
, char *buf
)
53 sprintf(buf
, "%pI4", addr
);
56 static void qeth_l3_ipaddr6_to_string(const __u8
*addr
, char *buf
)
58 sprintf(buf
, "%pI6", addr
);
61 void qeth_l3_ipaddr_to_string(enum qeth_prot_versions proto
, const __u8
*addr
,
64 if (proto
== QETH_PROT_IPV4
)
65 qeth_l3_ipaddr4_to_string(addr
, buf
);
66 else if (proto
== QETH_PROT_IPV6
)
67 qeth_l3_ipaddr6_to_string(addr
, buf
);
70 static void qeth_l3_convert_addr_to_bits(u8
*addr
, u8
*bits
, int len
)
75 for (i
= 0; i
< len
; ++i
) {
77 for (j
= 7; j
>= 0; --j
) {
78 bits
[i
*8 + j
] = octet
& 1;
84 static bool qeth_l3_is_addr_covered_by_ipato(struct qeth_card
*card
,
85 struct qeth_ipaddr
*addr
)
87 struct qeth_ipato_entry
*ipatoe
;
88 u8 addr_bits
[128] = {0, };
89 u8 ipatoe_bits
[128] = {0, };
92 if (!card
->ipato
.enabled
)
94 if (addr
->type
!= QETH_IP_TYPE_NORMAL
)
97 qeth_l3_convert_addr_to_bits((u8
*) &addr
->u
, addr_bits
,
98 (addr
->proto
== QETH_PROT_IPV4
)? 4:16);
99 list_for_each_entry(ipatoe
, &card
->ipato
.entries
, entry
) {
100 if (addr
->proto
!= ipatoe
->proto
)
102 qeth_l3_convert_addr_to_bits(ipatoe
->addr
, ipatoe_bits
,
103 (ipatoe
->proto
== QETH_PROT_IPV4
) ?
105 if (addr
->proto
== QETH_PROT_IPV4
)
106 rc
= !memcmp(addr_bits
, ipatoe_bits
,
107 min(32, ipatoe
->mask_bits
));
109 rc
= !memcmp(addr_bits
, ipatoe_bits
,
110 min(128, ipatoe
->mask_bits
));
115 if ((addr
->proto
== QETH_PROT_IPV4
) && card
->ipato
.invert4
)
117 else if ((addr
->proto
== QETH_PROT_IPV6
) && card
->ipato
.invert6
)
124 qeth_l3_ipaddrs_is_equal(struct qeth_ipaddr
*addr1
, struct qeth_ipaddr
*addr2
)
126 return addr1
->proto
== addr2
->proto
&&
127 !memcmp(&addr1
->u
, &addr2
->u
, sizeof(addr1
->u
)) &&
128 ether_addr_equal_64bits(addr1
->mac
, addr2
->mac
);
131 static struct qeth_ipaddr
*
132 qeth_l3_ip_from_hash(struct qeth_card
*card
, struct qeth_ipaddr
*tmp_addr
)
134 struct qeth_ipaddr
*addr
;
136 if (tmp_addr
->is_multicast
) {
137 hash_for_each_possible(card
->ip_mc_htable
, addr
,
138 hnode
, qeth_l3_ipaddr_hash(tmp_addr
))
139 if (qeth_l3_ipaddrs_is_equal(tmp_addr
, addr
))
142 hash_for_each_possible(card
->ip_htable
, addr
,
143 hnode
, qeth_l3_ipaddr_hash(tmp_addr
))
144 if (qeth_l3_ipaddrs_is_equal(tmp_addr
, addr
))
151 int qeth_l3_delete_ip(struct qeth_card
*card
, struct qeth_ipaddr
*tmp_addr
)
154 struct qeth_ipaddr
*addr
;
156 QETH_CARD_TEXT(card
, 4, "delip");
158 if (tmp_addr
->proto
== QETH_PROT_IPV4
)
159 QETH_CARD_HEX(card
, 4, &tmp_addr
->u
.a4
.addr
, 4);
161 QETH_CARD_HEX(card
, 4, &tmp_addr
->u
.a6
.addr
, 8);
162 QETH_CARD_HEX(card
, 4, ((char *)&tmp_addr
->u
.a6
.addr
) + 8, 8);
165 addr
= qeth_l3_ip_from_hash(card
, tmp_addr
);
170 if (addr
->ref_counter
> 0 && (addr
->type
== QETH_IP_TYPE_NORMAL
||
171 addr
->type
== QETH_IP_TYPE_RXIP
))
173 if (addr
->in_progress
)
176 if (!qeth_card_hw_is_reachable(card
)) {
177 addr
->disp_flag
= QETH_DISP_ADDR_DELETE
;
181 rc
= qeth_l3_deregister_addr_entry(card
, addr
);
183 hash_del(&addr
->hnode
);
189 int qeth_l3_add_ip(struct qeth_card
*card
, struct qeth_ipaddr
*tmp_addr
)
192 struct qeth_ipaddr
*addr
;
194 QETH_CARD_TEXT(card
, 4, "addip");
196 if (tmp_addr
->proto
== QETH_PROT_IPV4
)
197 QETH_CARD_HEX(card
, 4, &tmp_addr
->u
.a4
.addr
, 4);
199 QETH_CARD_HEX(card
, 4, &tmp_addr
->u
.a6
.addr
, 8);
200 QETH_CARD_HEX(card
, 4, ((char *)&tmp_addr
->u
.a6
.addr
) + 8, 8);
203 addr
= qeth_l3_ip_from_hash(card
, tmp_addr
);
205 addr
= qeth_l3_get_addr_buffer(tmp_addr
->proto
);
209 memcpy(addr
, tmp_addr
, sizeof(struct qeth_ipaddr
));
210 addr
->ref_counter
= 1;
212 if (qeth_l3_is_addr_covered_by_ipato(card
, addr
)) {
213 QETH_CARD_TEXT(card
, 2, "tkovaddr");
214 addr
->set_flags
|= QETH_IPA_SETIP_TAKEOVER_FLAG
;
216 hash_add(card
->ip_htable
, &addr
->hnode
,
217 qeth_l3_ipaddr_hash(addr
));
219 if (!qeth_card_hw_is_reachable(card
)) {
220 addr
->disp_flag
= QETH_DISP_ADDR_ADD
;
224 /* qeth_l3_register_addr_entry can go to sleep
225 * if we add a IPV4 addr. It is caused by the reason
226 * that SETIP ipa cmd starts ARP staff for IPV4 addr.
227 * Thus we should unlock spinlock, and make a protection
228 * using in_progress variable to indicate that there is
229 * an hardware operation with this IPV4 address
231 if (addr
->proto
== QETH_PROT_IPV4
) {
232 addr
->in_progress
= 1;
233 spin_unlock_bh(&card
->ip_lock
);
234 rc
= qeth_l3_register_addr_entry(card
, addr
);
235 spin_lock_bh(&card
->ip_lock
);
236 addr
->in_progress
= 0;
238 rc
= qeth_l3_register_addr_entry(card
, addr
);
240 if (!rc
|| (rc
== IPA_RC_DUPLICATE_IP_ADDRESS
) ||
241 (rc
== IPA_RC_LAN_OFFLINE
)) {
242 addr
->disp_flag
= QETH_DISP_ADDR_DO_NOTHING
;
243 if (addr
->ref_counter
< 1) {
244 qeth_l3_delete_ip(card
, addr
);
248 hash_del(&addr
->hnode
);
252 if (addr
->type
== QETH_IP_TYPE_NORMAL
||
253 addr
->type
== QETH_IP_TYPE_RXIP
)
261 struct qeth_ipaddr
*qeth_l3_get_addr_buffer(
262 enum qeth_prot_versions prot
)
264 struct qeth_ipaddr
*addr
;
266 addr
= kzalloc(sizeof(struct qeth_ipaddr
), GFP_ATOMIC
);
270 addr
->type
= QETH_IP_TYPE_NORMAL
;
271 addr
->disp_flag
= QETH_DISP_ADDR_DO_NOTHING
;
277 static void qeth_l3_clear_ip_htable(struct qeth_card
*card
, int recover
)
279 struct qeth_ipaddr
*addr
;
280 struct hlist_node
*tmp
;
283 QETH_CARD_TEXT(card
, 4, "clearip");
285 if (recover
&& card
->options
.sniffer
)
288 spin_lock_bh(&card
->ip_lock
);
290 hash_for_each_safe(card
->ip_htable
, i
, tmp
, addr
, hnode
) {
292 hash_del(&addr
->hnode
);
296 addr
->disp_flag
= QETH_DISP_ADDR_ADD
;
299 spin_unlock_bh(&card
->ip_lock
);
301 spin_lock_bh(&card
->mclock
);
303 hash_for_each_safe(card
->ip_mc_htable
, i
, tmp
, addr
, hnode
) {
304 hash_del(&addr
->hnode
);
308 spin_unlock_bh(&card
->mclock
);
312 static void qeth_l3_recover_ip(struct qeth_card
*card
)
314 struct qeth_ipaddr
*addr
;
315 struct hlist_node
*tmp
;
319 QETH_CARD_TEXT(card
, 4, "recovrip");
321 spin_lock_bh(&card
->ip_lock
);
323 hash_for_each_safe(card
->ip_htable
, i
, tmp
, addr
, hnode
) {
324 if (addr
->disp_flag
== QETH_DISP_ADDR_DELETE
) {
325 qeth_l3_deregister_addr_entry(card
, addr
);
326 hash_del(&addr
->hnode
);
328 } else if (addr
->disp_flag
== QETH_DISP_ADDR_ADD
) {
329 if (addr
->proto
== QETH_PROT_IPV4
) {
330 addr
->in_progress
= 1;
331 spin_unlock_bh(&card
->ip_lock
);
332 rc
= qeth_l3_register_addr_entry(card
, addr
);
333 spin_lock_bh(&card
->ip_lock
);
334 addr
->in_progress
= 0;
336 rc
= qeth_l3_register_addr_entry(card
, addr
);
339 addr
->disp_flag
= QETH_DISP_ADDR_DO_NOTHING
;
340 if (addr
->ref_counter
< 1)
341 qeth_l3_delete_ip(card
, addr
);
343 hash_del(&addr
->hnode
);
349 spin_unlock_bh(&card
->ip_lock
);
353 static int qeth_l3_send_setdelmc(struct qeth_card
*card
,
354 struct qeth_ipaddr
*addr
, int ipacmd
)
357 struct qeth_cmd_buffer
*iob
;
358 struct qeth_ipa_cmd
*cmd
;
360 QETH_CARD_TEXT(card
, 4, "setdelmc");
362 iob
= qeth_get_ipacmd_buffer(card
, ipacmd
, addr
->proto
);
365 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
366 ether_addr_copy(cmd
->data
.setdelipm
.mac
, addr
->mac
);
367 if (addr
->proto
== QETH_PROT_IPV6
)
368 memcpy(cmd
->data
.setdelipm
.ip6
, &addr
->u
.a6
.addr
,
369 sizeof(struct in6_addr
));
371 memcpy(&cmd
->data
.setdelipm
.ip4
, &addr
->u
.a4
.addr
, 4);
373 rc
= qeth_send_ipa_cmd(card
, iob
, NULL
, NULL
);
378 static void qeth_l3_fill_netmask(u8
*netmask
, unsigned int len
)
381 for (i
= 0; i
< 16; i
++) {
386 netmask
[i
] = (u8
)(0xFF00 >> j
);
392 static int qeth_l3_send_setdelip(struct qeth_card
*card
,
393 struct qeth_ipaddr
*addr
, int ipacmd
, unsigned int flags
)
396 struct qeth_cmd_buffer
*iob
;
397 struct qeth_ipa_cmd
*cmd
;
400 QETH_CARD_TEXT(card
, 4, "setdelip");
401 QETH_CARD_TEXT_(card
, 4, "flags%02X", flags
);
403 iob
= qeth_get_ipacmd_buffer(card
, ipacmd
, addr
->proto
);
406 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
407 if (addr
->proto
== QETH_PROT_IPV6
) {
408 memcpy(cmd
->data
.setdelip6
.ip_addr
, &addr
->u
.a6
.addr
,
409 sizeof(struct in6_addr
));
410 qeth_l3_fill_netmask(netmask
, addr
->u
.a6
.pfxlen
);
411 memcpy(cmd
->data
.setdelip6
.mask
, netmask
,
412 sizeof(struct in6_addr
));
413 cmd
->data
.setdelip6
.flags
= flags
;
415 memcpy(cmd
->data
.setdelip4
.ip_addr
, &addr
->u
.a4
.addr
, 4);
416 memcpy(cmd
->data
.setdelip4
.mask
, &addr
->u
.a4
.mask
, 4);
417 cmd
->data
.setdelip4
.flags
= flags
;
420 rc
= qeth_send_ipa_cmd(card
, iob
, NULL
, NULL
);
425 static int qeth_l3_send_setrouting(struct qeth_card
*card
,
426 enum qeth_routing_types type
, enum qeth_prot_versions prot
)
429 struct qeth_ipa_cmd
*cmd
;
430 struct qeth_cmd_buffer
*iob
;
432 QETH_CARD_TEXT(card
, 4, "setroutg");
433 iob
= qeth_get_ipacmd_buffer(card
, IPA_CMD_SETRTG
, prot
);
436 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
437 cmd
->data
.setrtg
.type
= (type
);
438 rc
= qeth_send_ipa_cmd(card
, iob
, NULL
, NULL
);
443 static int qeth_l3_correct_routing_type(struct qeth_card
*card
,
444 enum qeth_routing_types
*type
, enum qeth_prot_versions prot
)
446 if (card
->info
.type
== QETH_CARD_TYPE_IQD
) {
449 case PRIMARY_CONNECTOR
:
450 case SECONDARY_CONNECTOR
:
451 case MULTICAST_ROUTER
:
460 case SECONDARY_ROUTER
:
462 case MULTICAST_ROUTER
:
463 if (qeth_is_ipafunc_supported(card
, prot
,
475 int qeth_l3_setrouting_v4(struct qeth_card
*card
)
479 QETH_CARD_TEXT(card
, 3, "setrtg4");
481 rc
= qeth_l3_correct_routing_type(card
, &card
->options
.route4
.type
,
486 rc
= qeth_l3_send_setrouting(card
, card
->options
.route4
.type
,
489 card
->options
.route4
.type
= NO_ROUTER
;
490 QETH_DBF_MESSAGE(2, "Error (0x%04x) while setting routing type"
491 " on %s. Type set to 'no router'.\n", rc
,
492 QETH_CARD_IFNAME(card
));
497 int qeth_l3_setrouting_v6(struct qeth_card
*card
)
501 QETH_CARD_TEXT(card
, 3, "setrtg6");
503 if (!qeth_is_supported(card
, IPA_IPV6
))
505 rc
= qeth_l3_correct_routing_type(card
, &card
->options
.route6
.type
,
510 rc
= qeth_l3_send_setrouting(card
, card
->options
.route6
.type
,
513 card
->options
.route6
.type
= NO_ROUTER
;
514 QETH_DBF_MESSAGE(2, "Error (0x%04x) while setting routing type"
515 " on %s. Type set to 'no router'.\n", rc
,
516 QETH_CARD_IFNAME(card
));
522 * IP address takeover related functions
526 * qeth_l3_update_ipato() - Update 'takeover' property, for all NORMAL IPs.
528 * Caller must hold ip_lock.
530 void qeth_l3_update_ipato(struct qeth_card
*card
)
532 struct qeth_ipaddr
*addr
;
535 hash_for_each(card
->ip_htable
, i
, addr
, hnode
) {
536 if (addr
->type
!= QETH_IP_TYPE_NORMAL
)
538 if (qeth_l3_is_addr_covered_by_ipato(card
, addr
))
539 addr
->set_flags
|= QETH_IPA_SETIP_TAKEOVER_FLAG
;
541 addr
->set_flags
&= ~QETH_IPA_SETIP_TAKEOVER_FLAG
;
545 static void qeth_l3_clear_ipato_list(struct qeth_card
*card
)
547 struct qeth_ipato_entry
*ipatoe
, *tmp
;
549 spin_lock_bh(&card
->ip_lock
);
551 list_for_each_entry_safe(ipatoe
, tmp
, &card
->ipato
.entries
, entry
) {
552 list_del(&ipatoe
->entry
);
556 qeth_l3_update_ipato(card
);
557 spin_unlock_bh(&card
->ip_lock
);
560 int qeth_l3_add_ipato_entry(struct qeth_card
*card
,
561 struct qeth_ipato_entry
*new)
563 struct qeth_ipato_entry
*ipatoe
;
566 QETH_CARD_TEXT(card
, 2, "addipato");
568 spin_lock_bh(&card
->ip_lock
);
570 list_for_each_entry(ipatoe
, &card
->ipato
.entries
, entry
) {
571 if (ipatoe
->proto
!= new->proto
)
573 if (!memcmp(ipatoe
->addr
, new->addr
,
574 (ipatoe
->proto
== QETH_PROT_IPV4
)? 4:16) &&
575 (ipatoe
->mask_bits
== new->mask_bits
)) {
582 list_add_tail(&new->entry
, &card
->ipato
.entries
);
583 qeth_l3_update_ipato(card
);
586 spin_unlock_bh(&card
->ip_lock
);
591 int qeth_l3_del_ipato_entry(struct qeth_card
*card
,
592 enum qeth_prot_versions proto
, u8
*addr
,
595 struct qeth_ipato_entry
*ipatoe
, *tmp
;
598 QETH_CARD_TEXT(card
, 2, "delipato");
600 spin_lock_bh(&card
->ip_lock
);
602 list_for_each_entry_safe(ipatoe
, tmp
, &card
->ipato
.entries
, entry
) {
603 if (ipatoe
->proto
!= proto
)
605 if (!memcmp(ipatoe
->addr
, addr
,
606 (proto
== QETH_PROT_IPV4
)? 4:16) &&
607 (ipatoe
->mask_bits
== mask_bits
)) {
608 list_del(&ipatoe
->entry
);
609 qeth_l3_update_ipato(card
);
615 spin_unlock_bh(&card
->ip_lock
);
620 * VIPA related functions
622 int qeth_l3_add_vipa(struct qeth_card
*card
, enum qeth_prot_versions proto
,
625 struct qeth_ipaddr
*ipaddr
;
628 ipaddr
= qeth_l3_get_addr_buffer(proto
);
630 if (proto
== QETH_PROT_IPV4
) {
631 QETH_CARD_TEXT(card
, 2, "addvipa4");
632 memcpy(&ipaddr
->u
.a4
.addr
, addr
, 4);
633 ipaddr
->u
.a4
.mask
= 0;
634 } else if (proto
== QETH_PROT_IPV6
) {
635 QETH_CARD_TEXT(card
, 2, "addvipa6");
636 memcpy(&ipaddr
->u
.a6
.addr
, addr
, 16);
637 ipaddr
->u
.a6
.pfxlen
= 0;
639 ipaddr
->type
= QETH_IP_TYPE_VIPA
;
640 ipaddr
->set_flags
= QETH_IPA_SETIP_VIPA_FLAG
;
641 ipaddr
->del_flags
= QETH_IPA_DELIP_VIPA_FLAG
;
645 spin_lock_bh(&card
->ip_lock
);
647 if (qeth_l3_ip_from_hash(card
, ipaddr
))
650 rc
= qeth_l3_add_ip(card
, ipaddr
);
652 spin_unlock_bh(&card
->ip_lock
);
659 int qeth_l3_del_vipa(struct qeth_card
*card
, enum qeth_prot_versions proto
,
662 struct qeth_ipaddr
*ipaddr
;
665 ipaddr
= qeth_l3_get_addr_buffer(proto
);
667 if (proto
== QETH_PROT_IPV4
) {
668 QETH_CARD_TEXT(card
, 2, "delvipa4");
669 memcpy(&ipaddr
->u
.a4
.addr
, addr
, 4);
670 ipaddr
->u
.a4
.mask
= 0;
671 } else if (proto
== QETH_PROT_IPV6
) {
672 QETH_CARD_TEXT(card
, 2, "delvipa6");
673 memcpy(&ipaddr
->u
.a6
.addr
, addr
, 16);
674 ipaddr
->u
.a6
.pfxlen
= 0;
676 ipaddr
->type
= QETH_IP_TYPE_VIPA
;
680 spin_lock_bh(&card
->ip_lock
);
681 rc
= qeth_l3_delete_ip(card
, ipaddr
);
682 spin_unlock_bh(&card
->ip_lock
);
689 * proxy ARP related functions
691 int qeth_l3_add_rxip(struct qeth_card
*card
, enum qeth_prot_versions proto
,
694 struct qeth_ipaddr
*ipaddr
;
697 ipaddr
= qeth_l3_get_addr_buffer(proto
);
699 if (proto
== QETH_PROT_IPV4
) {
700 QETH_CARD_TEXT(card
, 2, "addrxip4");
701 memcpy(&ipaddr
->u
.a4
.addr
, addr
, 4);
702 ipaddr
->u
.a4
.mask
= 0;
703 } else if (proto
== QETH_PROT_IPV6
) {
704 QETH_CARD_TEXT(card
, 2, "addrxip6");
705 memcpy(&ipaddr
->u
.a6
.addr
, addr
, 16);
706 ipaddr
->u
.a6
.pfxlen
= 0;
709 ipaddr
->type
= QETH_IP_TYPE_RXIP
;
710 ipaddr
->set_flags
= QETH_IPA_SETIP_TAKEOVER_FLAG
;
711 ipaddr
->del_flags
= 0;
715 spin_lock_bh(&card
->ip_lock
);
717 if (qeth_l3_ip_from_hash(card
, ipaddr
))
720 rc
= qeth_l3_add_ip(card
, ipaddr
);
722 spin_unlock_bh(&card
->ip_lock
);
729 int qeth_l3_del_rxip(struct qeth_card
*card
, enum qeth_prot_versions proto
,
732 struct qeth_ipaddr
*ipaddr
;
735 ipaddr
= qeth_l3_get_addr_buffer(proto
);
737 if (proto
== QETH_PROT_IPV4
) {
738 QETH_CARD_TEXT(card
, 2, "delrxip4");
739 memcpy(&ipaddr
->u
.a4
.addr
, addr
, 4);
740 ipaddr
->u
.a4
.mask
= 0;
741 } else if (proto
== QETH_PROT_IPV6
) {
742 QETH_CARD_TEXT(card
, 2, "delrxip6");
743 memcpy(&ipaddr
->u
.a6
.addr
, addr
, 16);
744 ipaddr
->u
.a6
.pfxlen
= 0;
746 ipaddr
->type
= QETH_IP_TYPE_RXIP
;
750 spin_lock_bh(&card
->ip_lock
);
751 rc
= qeth_l3_delete_ip(card
, ipaddr
);
752 spin_unlock_bh(&card
->ip_lock
);
758 static int qeth_l3_register_addr_entry(struct qeth_card
*card
,
759 struct qeth_ipaddr
*addr
)
766 if (addr
->proto
== QETH_PROT_IPV4
) {
767 QETH_CARD_TEXT(card
, 2, "setaddr4");
768 QETH_CARD_HEX(card
, 3, &addr
->u
.a4
.addr
, sizeof(int));
769 } else if (addr
->proto
== QETH_PROT_IPV6
) {
770 QETH_CARD_TEXT(card
, 2, "setaddr6");
771 QETH_CARD_HEX(card
, 3, &addr
->u
.a6
.addr
, 8);
772 QETH_CARD_HEX(card
, 3, ((char *)&addr
->u
.a6
.addr
) + 8, 8);
774 QETH_CARD_TEXT(card
, 2, "setaddr?");
775 QETH_CARD_HEX(card
, 3, addr
, sizeof(struct qeth_ipaddr
));
778 if (addr
->is_multicast
)
779 rc
= qeth_l3_send_setdelmc(card
, addr
, IPA_CMD_SETIPM
);
781 rc
= qeth_l3_send_setdelip(card
, addr
, IPA_CMD_SETIP
,
784 QETH_CARD_TEXT(card
, 2, "failed");
785 } while ((--cnt
> 0) && rc
);
787 QETH_CARD_TEXT(card
, 2, "FAILED");
788 qeth_l3_ipaddr_to_string(addr
->proto
, (u8
*)&addr
->u
, buf
);
789 dev_warn(&card
->gdev
->dev
,
790 "Registering IP address %s failed\n", buf
);
795 static int qeth_l3_deregister_addr_entry(struct qeth_card
*card
,
796 struct qeth_ipaddr
*addr
)
800 if (addr
->proto
== QETH_PROT_IPV4
) {
801 QETH_CARD_TEXT(card
, 2, "deladdr4");
802 QETH_CARD_HEX(card
, 3, &addr
->u
.a4
.addr
, sizeof(int));
803 } else if (addr
->proto
== QETH_PROT_IPV6
) {
804 QETH_CARD_TEXT(card
, 2, "deladdr6");
805 QETH_CARD_HEX(card
, 3, &addr
->u
.a6
.addr
, 8);
806 QETH_CARD_HEX(card
, 3, ((char *)&addr
->u
.a6
.addr
) + 8, 8);
808 QETH_CARD_TEXT(card
, 2, "deladdr?");
809 QETH_CARD_HEX(card
, 3, addr
, sizeof(struct qeth_ipaddr
));
811 if (addr
->is_multicast
)
812 rc
= qeth_l3_send_setdelmc(card
, addr
, IPA_CMD_DELIPM
);
814 rc
= qeth_l3_send_setdelip(card
, addr
, IPA_CMD_DELIP
,
817 QETH_CARD_TEXT(card
, 2, "failed");
822 static int qeth_l3_setadapter_parms(struct qeth_card
*card
)
826 QETH_DBF_TEXT(SETUP
, 2, "setadprm");
828 if (qeth_adp_supported(card
, IPA_SETADP_ALTER_MAC_ADDRESS
)) {
829 rc
= qeth_setadpparms_change_macaddr(card
);
831 dev_warn(&card
->gdev
->dev
, "Reading the adapter MAC"
832 " address failed\n");
838 static int qeth_l3_send_simple_setassparms_ipv6(struct qeth_card
*card
,
839 enum qeth_ipa_funcs ipa_func
, __u16 cmd_code
)
842 struct qeth_cmd_buffer
*iob
;
844 QETH_CARD_TEXT(card
, 4, "simassp6");
845 iob
= qeth_get_setassparms_cmd(card
, ipa_func
, cmd_code
,
849 rc
= qeth_send_setassparms(card
, iob
, 0, 0,
850 qeth_setassparms_cb
, NULL
);
854 static int qeth_l3_start_ipa_arp_processing(struct qeth_card
*card
)
858 QETH_CARD_TEXT(card
, 3, "ipaarp");
860 if (!qeth_is_supported(card
, IPA_ARP_PROCESSING
)) {
861 dev_info(&card
->gdev
->dev
,
862 "ARP processing not supported on %s!\n",
863 QETH_CARD_IFNAME(card
));
866 rc
= qeth_send_simple_setassparms(card
, IPA_ARP_PROCESSING
,
867 IPA_CMD_ASS_START
, 0);
869 dev_warn(&card
->gdev
->dev
,
870 "Starting ARP processing support for %s failed\n",
871 QETH_CARD_IFNAME(card
));
876 static int qeth_l3_start_ipa_source_mac(struct qeth_card
*card
)
880 QETH_CARD_TEXT(card
, 3, "stsrcmac");
882 if (!qeth_is_supported(card
, IPA_SOURCE_MAC
)) {
883 dev_info(&card
->gdev
->dev
,
884 "Inbound source MAC-address not supported on %s\n",
885 QETH_CARD_IFNAME(card
));
889 rc
= qeth_send_simple_setassparms(card
, IPA_SOURCE_MAC
,
890 IPA_CMD_ASS_START
, 0);
892 dev_warn(&card
->gdev
->dev
,
893 "Starting source MAC-address support for %s failed\n",
894 QETH_CARD_IFNAME(card
));
898 static int qeth_l3_start_ipa_vlan(struct qeth_card
*card
)
902 QETH_CARD_TEXT(card
, 3, "strtvlan");
904 if (!qeth_is_supported(card
, IPA_FULL_VLAN
)) {
905 dev_info(&card
->gdev
->dev
,
906 "VLAN not supported on %s\n", QETH_CARD_IFNAME(card
));
910 rc
= qeth_send_simple_setassparms(card
, IPA_VLAN_PRIO
,
911 IPA_CMD_ASS_START
, 0);
913 dev_warn(&card
->gdev
->dev
,
914 "Starting VLAN support for %s failed\n",
915 QETH_CARD_IFNAME(card
));
917 dev_info(&card
->gdev
->dev
, "VLAN enabled\n");
922 static int qeth_l3_start_ipa_multicast(struct qeth_card
*card
)
926 QETH_CARD_TEXT(card
, 3, "stmcast");
928 if (!qeth_is_supported(card
, IPA_MULTICASTING
)) {
929 dev_info(&card
->gdev
->dev
,
930 "Multicast not supported on %s\n",
931 QETH_CARD_IFNAME(card
));
935 rc
= qeth_send_simple_setassparms(card
, IPA_MULTICASTING
,
936 IPA_CMD_ASS_START
, 0);
938 dev_warn(&card
->gdev
->dev
,
939 "Starting multicast support for %s failed\n",
940 QETH_CARD_IFNAME(card
));
942 dev_info(&card
->gdev
->dev
, "Multicast enabled\n");
943 card
->dev
->flags
|= IFF_MULTICAST
;
948 static int qeth_l3_softsetup_ipv6(struct qeth_card
*card
)
952 QETH_CARD_TEXT(card
, 3, "softipv6");
954 rc
= qeth_query_ipassists(card
, QETH_PROT_IPV6
);
956 dev_err(&card
->gdev
->dev
,
957 "Activating IPv6 support for %s failed\n",
958 QETH_CARD_IFNAME(card
));
962 if (card
->info
.type
== QETH_CARD_TYPE_IQD
)
965 rc
= qeth_send_simple_setassparms(card
, IPA_IPV6
,
966 IPA_CMD_ASS_START
, 3);
968 dev_err(&card
->gdev
->dev
,
969 "Activating IPv6 support for %s failed\n",
970 QETH_CARD_IFNAME(card
));
973 rc
= qeth_l3_send_simple_setassparms_ipv6(card
, IPA_IPV6
,
976 dev_err(&card
->gdev
->dev
,
977 "Activating IPv6 support for %s failed\n",
978 QETH_CARD_IFNAME(card
));
981 rc
= qeth_l3_send_simple_setassparms_ipv6(card
, IPA_PASSTHRU
,
984 dev_warn(&card
->gdev
->dev
,
985 "Enabling the passthrough mode for %s failed\n",
986 QETH_CARD_IFNAME(card
));
990 dev_info(&card
->gdev
->dev
, "IPV6 enabled\n");
994 static int qeth_l3_start_ipa_ipv6(struct qeth_card
*card
)
996 QETH_CARD_TEXT(card
, 3, "strtipv6");
998 if (!qeth_is_supported(card
, IPA_IPV6
)) {
999 dev_info(&card
->gdev
->dev
,
1000 "IPv6 not supported on %s\n", QETH_CARD_IFNAME(card
));
1003 return qeth_l3_softsetup_ipv6(card
);
1006 static int qeth_l3_start_ipa_broadcast(struct qeth_card
*card
)
1010 QETH_CARD_TEXT(card
, 3, "stbrdcst");
1011 card
->info
.broadcast_capable
= 0;
1012 if (!qeth_is_supported(card
, IPA_FILTERING
)) {
1013 dev_info(&card
->gdev
->dev
,
1014 "Broadcast not supported on %s\n",
1015 QETH_CARD_IFNAME(card
));
1019 rc
= qeth_send_simple_setassparms(card
, IPA_FILTERING
,
1020 IPA_CMD_ASS_START
, 0);
1022 dev_warn(&card
->gdev
->dev
, "Enabling broadcast filtering for "
1023 "%s failed\n", QETH_CARD_IFNAME(card
));
1027 rc
= qeth_send_simple_setassparms(card
, IPA_FILTERING
,
1028 IPA_CMD_ASS_CONFIGURE
, 1);
1030 dev_warn(&card
->gdev
->dev
,
1031 "Setting up broadcast filtering for %s failed\n",
1032 QETH_CARD_IFNAME(card
));
1035 card
->info
.broadcast_capable
= QETH_BROADCAST_WITH_ECHO
;
1036 dev_info(&card
->gdev
->dev
, "Broadcast enabled\n");
1037 rc
= qeth_send_simple_setassparms(card
, IPA_FILTERING
,
1038 IPA_CMD_ASS_ENABLE
, 1);
1040 dev_warn(&card
->gdev
->dev
, "Setting up broadcast echo "
1041 "filtering for %s failed\n", QETH_CARD_IFNAME(card
));
1044 card
->info
.broadcast_capable
= QETH_BROADCAST_WITHOUT_ECHO
;
1046 if (card
->info
.broadcast_capable
)
1047 card
->dev
->flags
|= IFF_BROADCAST
;
1049 card
->dev
->flags
&= ~IFF_BROADCAST
;
1053 static int qeth_l3_start_ipassists(struct qeth_card
*card
)
1055 QETH_CARD_TEXT(card
, 3, "strtipas");
1057 if (qeth_set_access_ctrl_online(card
, 0))
1059 qeth_l3_start_ipa_arp_processing(card
); /* go on*/
1060 qeth_l3_start_ipa_source_mac(card
); /* go on*/
1061 qeth_l3_start_ipa_vlan(card
); /* go on*/
1062 qeth_l3_start_ipa_multicast(card
); /* go on*/
1063 qeth_l3_start_ipa_ipv6(card
); /* go on*/
1064 qeth_l3_start_ipa_broadcast(card
); /* go on*/
1068 static int qeth_l3_iqd_read_initial_mac_cb(struct qeth_card
*card
,
1069 struct qeth_reply
*reply
, unsigned long data
)
1071 struct qeth_ipa_cmd
*cmd
;
1073 cmd
= (struct qeth_ipa_cmd
*) data
;
1074 if (cmd
->hdr
.return_code
== 0)
1075 ether_addr_copy(card
->dev
->dev_addr
,
1076 cmd
->data
.create_destroy_addr
.unique_id
);
1078 eth_random_addr(card
->dev
->dev_addr
);
1083 static int qeth_l3_iqd_read_initial_mac(struct qeth_card
*card
)
1086 struct qeth_cmd_buffer
*iob
;
1087 struct qeth_ipa_cmd
*cmd
;
1089 QETH_DBF_TEXT(SETUP
, 2, "hsrmac");
1091 iob
= qeth_get_ipacmd_buffer(card
, IPA_CMD_CREATE_ADDR
,
1095 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
1096 *((__u16
*) &cmd
->data
.create_destroy_addr
.unique_id
[6]) =
1097 card
->info
.unique_id
;
1099 rc
= qeth_send_ipa_cmd(card
, iob
, qeth_l3_iqd_read_initial_mac_cb
,
1104 static int qeth_l3_get_unique_id_cb(struct qeth_card
*card
,
1105 struct qeth_reply
*reply
, unsigned long data
)
1107 struct qeth_ipa_cmd
*cmd
;
1109 cmd
= (struct qeth_ipa_cmd
*) data
;
1110 if (cmd
->hdr
.return_code
== 0)
1111 card
->info
.unique_id
= *((__u16
*)
1112 &cmd
->data
.create_destroy_addr
.unique_id
[6]);
1114 card
->info
.unique_id
= UNIQUE_ID_IF_CREATE_ADDR_FAILED
|
1115 UNIQUE_ID_NOT_BY_CARD
;
1116 dev_warn(&card
->gdev
->dev
, "The network adapter failed to "
1117 "generate a unique ID\n");
1122 static int qeth_l3_get_unique_id(struct qeth_card
*card
)
1125 struct qeth_cmd_buffer
*iob
;
1126 struct qeth_ipa_cmd
*cmd
;
1128 QETH_DBF_TEXT(SETUP
, 2, "guniqeid");
1130 if (!qeth_is_supported(card
, IPA_IPV6
)) {
1131 card
->info
.unique_id
= UNIQUE_ID_IF_CREATE_ADDR_FAILED
|
1132 UNIQUE_ID_NOT_BY_CARD
;
1136 iob
= qeth_get_ipacmd_buffer(card
, IPA_CMD_CREATE_ADDR
,
1140 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
1141 *((__u16
*) &cmd
->data
.create_destroy_addr
.unique_id
[6]) =
1142 card
->info
.unique_id
;
1144 rc
= qeth_send_ipa_cmd(card
, iob
, qeth_l3_get_unique_id_cb
, NULL
);
1149 qeth_diags_trace_cb(struct qeth_card
*card
, struct qeth_reply
*reply
,
1152 struct qeth_ipa_cmd
*cmd
;
1155 QETH_DBF_TEXT(SETUP
, 2, "diastrcb");
1157 cmd
= (struct qeth_ipa_cmd
*)data
;
1158 rc
= cmd
->hdr
.return_code
;
1160 QETH_CARD_TEXT_(card
, 2, "dxter%x", rc
);
1161 switch (cmd
->data
.diagass
.action
) {
1162 case QETH_DIAGS_CMD_TRACE_QUERY
:
1164 case QETH_DIAGS_CMD_TRACE_DISABLE
:
1167 case IPA_RC_INVALID_SUBCMD
:
1168 card
->info
.promisc_mode
= SET_PROMISC_MODE_OFF
;
1169 dev_info(&card
->gdev
->dev
, "The HiperSockets network "
1170 "traffic analyzer is deactivated\n");
1176 case QETH_DIAGS_CMD_TRACE_ENABLE
:
1179 card
->info
.promisc_mode
= SET_PROMISC_MODE_ON
;
1180 dev_info(&card
->gdev
->dev
, "The HiperSockets network "
1181 "traffic analyzer is activated\n");
1183 case IPA_RC_HARDWARE_AUTH_ERROR
:
1184 dev_warn(&card
->gdev
->dev
, "The device is not "
1185 "authorized to run as a HiperSockets network "
1186 "traffic analyzer\n");
1188 case IPA_RC_TRACE_ALREADY_ACTIVE
:
1189 dev_warn(&card
->gdev
->dev
, "A HiperSockets "
1190 "network traffic analyzer is already "
1191 "active in the HiperSockets LAN\n");
1198 QETH_DBF_MESSAGE(2, "Unknown sniffer action (0x%04x) on %s\n",
1199 cmd
->data
.diagass
.action
, QETH_CARD_IFNAME(card
));
1206 qeth_diags_trace(struct qeth_card
*card
, enum qeth_diags_trace_cmds diags_cmd
)
1208 struct qeth_cmd_buffer
*iob
;
1209 struct qeth_ipa_cmd
*cmd
;
1211 QETH_DBF_TEXT(SETUP
, 2, "diagtrac");
1213 iob
= qeth_get_ipacmd_buffer(card
, IPA_CMD_SET_DIAG_ASS
, 0);
1216 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
1217 cmd
->data
.diagass
.subcmd_len
= 16;
1218 cmd
->data
.diagass
.subcmd
= QETH_DIAGS_CMD_TRACE
;
1219 cmd
->data
.diagass
.type
= QETH_DIAGS_TYPE_HIPERSOCKET
;
1220 cmd
->data
.diagass
.action
= diags_cmd
;
1221 return qeth_send_ipa_cmd(card
, iob
, qeth_diags_trace_cb
, NULL
);
1225 qeth_l3_add_mc_to_hash(struct qeth_card
*card
, struct in_device
*in4_dev
)
1227 struct ip_mc_list
*im4
;
1228 struct qeth_ipaddr
*tmp
, *ipm
;
1230 QETH_CARD_TEXT(card
, 4, "addmc");
1232 tmp
= qeth_l3_get_addr_buffer(QETH_PROT_IPV4
);
1236 for (im4
= rcu_dereference(in4_dev
->mc_list
); im4
!= NULL
;
1237 im4
= rcu_dereference(im4
->next_rcu
)) {
1238 ip_eth_mc_map(im4
->multiaddr
, tmp
->mac
);
1239 tmp
->u
.a4
.addr
= be32_to_cpu(im4
->multiaddr
);
1240 tmp
->is_multicast
= 1;
1242 ipm
= qeth_l3_ip_from_hash(card
, tmp
);
1244 ipm
->disp_flag
= QETH_DISP_ADDR_DO_NOTHING
;
1246 ipm
= qeth_l3_get_addr_buffer(QETH_PROT_IPV4
);
1249 ether_addr_copy(ipm
->mac
, tmp
->mac
);
1250 ipm
->u
.a4
.addr
= be32_to_cpu(im4
->multiaddr
);
1251 ipm
->is_multicast
= 1;
1252 ipm
->disp_flag
= QETH_DISP_ADDR_ADD
;
1253 hash_add(card
->ip_mc_htable
,
1254 &ipm
->hnode
, qeth_l3_ipaddr_hash(ipm
));
1261 /* called with rcu_read_lock */
1262 static void qeth_l3_add_vlan_mc(struct qeth_card
*card
)
1264 struct in_device
*in_dev
;
1267 QETH_CARD_TEXT(card
, 4, "addmcvl");
1269 if (!qeth_is_supported(card
, IPA_FULL_VLAN
))
1272 for_each_set_bit(vid
, card
->active_vlans
, VLAN_N_VID
) {
1273 struct net_device
*netdev
;
1275 netdev
= __vlan_find_dev_deep_rcu(card
->dev
, htons(ETH_P_8021Q
),
1277 if (netdev
== NULL
||
1278 !(netdev
->flags
& IFF_UP
))
1280 in_dev
= __in_dev_get_rcu(netdev
);
1283 qeth_l3_add_mc_to_hash(card
, in_dev
);
1287 static void qeth_l3_add_multicast_ipv4(struct qeth_card
*card
)
1289 struct in_device
*in4_dev
;
1291 QETH_CARD_TEXT(card
, 4, "chkmcv4");
1294 in4_dev
= __in_dev_get_rcu(card
->dev
);
1295 if (in4_dev
== NULL
)
1297 qeth_l3_add_mc_to_hash(card
, in4_dev
);
1298 qeth_l3_add_vlan_mc(card
);
1303 static void qeth_l3_add_mc6_to_hash(struct qeth_card
*card
,
1304 struct inet6_dev
*in6_dev
)
1306 struct qeth_ipaddr
*ipm
;
1307 struct ifmcaddr6
*im6
;
1308 struct qeth_ipaddr
*tmp
;
1310 QETH_CARD_TEXT(card
, 4, "addmc6");
1312 tmp
= qeth_l3_get_addr_buffer(QETH_PROT_IPV6
);
1316 for (im6
= in6_dev
->mc_list
; im6
!= NULL
; im6
= im6
->next
) {
1317 ipv6_eth_mc_map(&im6
->mca_addr
, tmp
->mac
);
1318 memcpy(&tmp
->u
.a6
.addr
, &im6
->mca_addr
.s6_addr
,
1319 sizeof(struct in6_addr
));
1320 tmp
->is_multicast
= 1;
1322 ipm
= qeth_l3_ip_from_hash(card
, tmp
);
1324 ipm
->disp_flag
= QETH_DISP_ADDR_DO_NOTHING
;
1328 ipm
= qeth_l3_get_addr_buffer(QETH_PROT_IPV6
);
1332 ether_addr_copy(ipm
->mac
, tmp
->mac
);
1333 memcpy(&ipm
->u
.a6
.addr
, &im6
->mca_addr
.s6_addr
,
1334 sizeof(struct in6_addr
));
1335 ipm
->is_multicast
= 1;
1336 ipm
->disp_flag
= QETH_DISP_ADDR_ADD
;
1337 hash_add(card
->ip_mc_htable
,
1338 &ipm
->hnode
, qeth_l3_ipaddr_hash(ipm
));
1344 /* called with rcu_read_lock */
1345 static void qeth_l3_add_vlan_mc6(struct qeth_card
*card
)
1347 struct inet6_dev
*in_dev
;
1350 QETH_CARD_TEXT(card
, 4, "admc6vl");
1352 if (!qeth_is_supported(card
, IPA_FULL_VLAN
))
1355 for_each_set_bit(vid
, card
->active_vlans
, VLAN_N_VID
) {
1356 struct net_device
*netdev
;
1358 netdev
= __vlan_find_dev_deep_rcu(card
->dev
, htons(ETH_P_8021Q
),
1360 if (netdev
== NULL
||
1361 !(netdev
->flags
& IFF_UP
))
1363 in_dev
= in6_dev_get(netdev
);
1366 read_lock_bh(&in_dev
->lock
);
1367 qeth_l3_add_mc6_to_hash(card
, in_dev
);
1368 read_unlock_bh(&in_dev
->lock
);
1369 in6_dev_put(in_dev
);
1373 static void qeth_l3_add_multicast_ipv6(struct qeth_card
*card
)
1375 struct inet6_dev
*in6_dev
;
1377 QETH_CARD_TEXT(card
, 4, "chkmcv6");
1379 if (!qeth_is_supported(card
, IPA_IPV6
))
1381 in6_dev
= in6_dev_get(card
->dev
);
1386 read_lock_bh(&in6_dev
->lock
);
1387 qeth_l3_add_mc6_to_hash(card
, in6_dev
);
1388 qeth_l3_add_vlan_mc6(card
);
1389 read_unlock_bh(&in6_dev
->lock
);
1391 in6_dev_put(in6_dev
);
1394 static void qeth_l3_free_vlan_addresses4(struct qeth_card
*card
,
1397 struct in_device
*in_dev
;
1398 struct in_ifaddr
*ifa
;
1399 struct qeth_ipaddr
*addr
;
1400 struct net_device
*netdev
;
1402 QETH_CARD_TEXT(card
, 4, "frvaddr4");
1404 netdev
= __vlan_find_dev_deep_rcu(card
->dev
, htons(ETH_P_8021Q
), vid
);
1407 in_dev
= in_dev_get(netdev
);
1411 addr
= qeth_l3_get_addr_buffer(QETH_PROT_IPV4
);
1415 spin_lock_bh(&card
->ip_lock
);
1417 for (ifa
= in_dev
->ifa_list
; ifa
; ifa
= ifa
->ifa_next
) {
1418 addr
->u
.a4
.addr
= be32_to_cpu(ifa
->ifa_address
);
1419 addr
->u
.a4
.mask
= be32_to_cpu(ifa
->ifa_mask
);
1420 addr
->type
= QETH_IP_TYPE_NORMAL
;
1421 qeth_l3_delete_ip(card
, addr
);
1424 spin_unlock_bh(&card
->ip_lock
);
1431 static void qeth_l3_free_vlan_addresses6(struct qeth_card
*card
,
1434 struct inet6_dev
*in6_dev
;
1435 struct inet6_ifaddr
*ifa
;
1436 struct qeth_ipaddr
*addr
;
1437 struct net_device
*netdev
;
1439 QETH_CARD_TEXT(card
, 4, "frvaddr6");
1441 netdev
= __vlan_find_dev_deep_rcu(card
->dev
, htons(ETH_P_8021Q
), vid
);
1445 in6_dev
= in6_dev_get(netdev
);
1449 addr
= qeth_l3_get_addr_buffer(QETH_PROT_IPV6
);
1453 spin_lock_bh(&card
->ip_lock
);
1455 list_for_each_entry(ifa
, &in6_dev
->addr_list
, if_list
) {
1456 memcpy(&addr
->u
.a6
.addr
, &ifa
->addr
,
1457 sizeof(struct in6_addr
));
1458 addr
->u
.a6
.pfxlen
= ifa
->prefix_len
;
1459 addr
->type
= QETH_IP_TYPE_NORMAL
;
1460 qeth_l3_delete_ip(card
, addr
);
1463 spin_unlock_bh(&card
->ip_lock
);
1467 in6_dev_put(in6_dev
);
1470 static void qeth_l3_free_vlan_addresses(struct qeth_card
*card
,
1474 qeth_l3_free_vlan_addresses4(card
, vid
);
1475 qeth_l3_free_vlan_addresses6(card
, vid
);
1479 static int qeth_l3_vlan_rx_add_vid(struct net_device
*dev
,
1480 __be16 proto
, u16 vid
)
1482 struct qeth_card
*card
= dev
->ml_priv
;
1484 set_bit(vid
, card
->active_vlans
);
1488 static int qeth_l3_vlan_rx_kill_vid(struct net_device
*dev
,
1489 __be16 proto
, u16 vid
)
1491 struct qeth_card
*card
= dev
->ml_priv
;
1493 QETH_CARD_TEXT_(card
, 4, "kid:%d", vid
);
1495 if (qeth_wait_for_threads(card
, QETH_RECOVER_THREAD
)) {
1496 QETH_CARD_TEXT(card
, 3, "kidREC");
1499 /* unregister IP addresses of vlan device */
1500 qeth_l3_free_vlan_addresses(card
, vid
);
1501 clear_bit(vid
, card
->active_vlans
);
1502 qeth_l3_set_rx_mode(dev
);
1506 static void qeth_l3_rebuild_skb(struct qeth_card
*card
, struct sk_buff
*skb
,
1507 struct qeth_hdr
*hdr
)
1509 if (!(hdr
->hdr
.l3
.flags
& QETH_HDR_PASSTHRU
)) {
1510 u16 prot
= (hdr
->hdr
.l3
.flags
& QETH_HDR_IPV6
) ? ETH_P_IPV6
:
1512 unsigned char tg_addr
[ETH_ALEN
];
1514 skb_reset_network_header(skb
);
1515 switch (hdr
->hdr
.l3
.flags
& QETH_HDR_CAST_MASK
) {
1516 case QETH_CAST_MULTICAST
:
1517 if (prot
== ETH_P_IP
)
1518 ip_eth_mc_map(ip_hdr(skb
)->daddr
, tg_addr
);
1520 ipv6_eth_mc_map(&ipv6_hdr(skb
)->daddr
, tg_addr
);
1522 card
->stats
.multicast
++;
1523 skb
->pkt_type
= PACKET_MULTICAST
;
1525 case QETH_CAST_BROADCAST
:
1526 ether_addr_copy(tg_addr
, card
->dev
->broadcast
);
1527 card
->stats
.multicast
++;
1528 skb
->pkt_type
= PACKET_BROADCAST
;
1530 case QETH_CAST_UNICAST
:
1531 case QETH_CAST_ANYCAST
:
1532 case QETH_CAST_NOCAST
:
1534 if (card
->options
.sniffer
)
1535 skb
->pkt_type
= PACKET_OTHERHOST
;
1537 skb
->pkt_type
= PACKET_HOST
;
1538 ether_addr_copy(tg_addr
, card
->dev
->dev_addr
);
1540 if (hdr
->hdr
.l3
.ext_flags
& QETH_HDR_EXT_SRC_MAC_ADDR
)
1541 card
->dev
->header_ops
->create(skb
, card
->dev
, prot
,
1542 tg_addr
, &hdr
->hdr
.l3
.next_hop
.rx
.src_mac
,
1543 card
->dev
->addr_len
);
1545 card
->dev
->header_ops
->create(skb
, card
->dev
, prot
,
1546 tg_addr
, "FAKELL", card
->dev
->addr_len
);
1549 skb
->protocol
= eth_type_trans(skb
, card
->dev
);
1551 /* copy VLAN tag from hdr into skb */
1552 if (!card
->options
.sniffer
&&
1553 (hdr
->hdr
.l3
.ext_flags
& (QETH_HDR_EXT_VLAN_FRAME
|
1554 QETH_HDR_EXT_INCLUDE_VLAN_TAG
))) {
1555 u16 tag
= (hdr
->hdr
.l3
.ext_flags
& QETH_HDR_EXT_VLAN_FRAME
) ?
1556 hdr
->hdr
.l3
.vlan_id
:
1557 hdr
->hdr
.l3
.next_hop
.rx
.vlan_id
;
1558 __vlan_hwaccel_put_tag(skb
, htons(ETH_P_8021Q
), tag
);
1561 if (card
->dev
->features
& NETIF_F_RXCSUM
) {
1562 if ((hdr
->hdr
.l3
.ext_flags
&
1563 (QETH_HDR_EXT_CSUM_HDR_REQ
|
1564 QETH_HDR_EXT_CSUM_TRANSP_REQ
)) ==
1565 (QETH_HDR_EXT_CSUM_HDR_REQ
|
1566 QETH_HDR_EXT_CSUM_TRANSP_REQ
))
1567 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
1569 skb
->ip_summed
= CHECKSUM_NONE
;
1571 skb
->ip_summed
= CHECKSUM_NONE
;
1574 static int qeth_l3_process_inbound_buffer(struct qeth_card
*card
,
1575 int budget
, int *done
)
1578 struct sk_buff
*skb
;
1579 struct qeth_hdr
*hdr
;
1584 WARN_ON_ONCE(!budget
);
1586 skb
= qeth_core_get_next_skb(card
,
1587 &card
->qdio
.in_q
->bufs
[card
->rx
.b_index
],
1588 &card
->rx
.b_element
, &card
->rx
.e_offset
, &hdr
);
1593 skb
->dev
= card
->dev
;
1594 switch (hdr
->hdr
.l3
.id
) {
1595 case QETH_HEADER_TYPE_LAYER3
:
1596 magic
= *(__u16
*)skb
->data
;
1597 if ((card
->info
.type
== QETH_CARD_TYPE_IQD
) &&
1598 (magic
== ETH_P_AF_IUCV
)) {
1599 skb
->protocol
= cpu_to_be16(ETH_P_AF_IUCV
);
1600 skb
->pkt_type
= PACKET_HOST
;
1601 skb
->mac_header
= NET_SKB_PAD
;
1602 skb
->dev
= card
->dev
;
1604 card
->dev
->header_ops
->create(skb
, card
->dev
, 0,
1605 card
->dev
->dev_addr
, "FAKELL",
1606 card
->dev
->addr_len
);
1607 netif_receive_skb(skb
);
1609 qeth_l3_rebuild_skb(card
, skb
, hdr
);
1611 napi_gro_receive(&card
->napi
, skb
);
1614 case QETH_HEADER_TYPE_LAYER2
: /* for HiperSockets sniffer */
1615 skb
->pkt_type
= PACKET_HOST
;
1616 skb
->protocol
= eth_type_trans(skb
, skb
->dev
);
1618 netif_receive_skb(skb
);
1621 dev_kfree_skb_any(skb
);
1622 QETH_CARD_TEXT(card
, 3, "inbunkno");
1623 QETH_DBF_HEX(CTRL
, 3, hdr
, QETH_DBF_CTRL_LEN
);
1628 card
->stats
.rx_packets
++;
1629 card
->stats
.rx_bytes
+= len
;
1634 static int qeth_l3_verify_vlan_dev(struct net_device
*dev
,
1635 struct qeth_card
*card
)
1640 for_each_set_bit(vid
, card
->active_vlans
, VLAN_N_VID
) {
1641 struct net_device
*netdev
;
1644 netdev
= __vlan_find_dev_deep_rcu(card
->dev
, htons(ETH_P_8021Q
),
1647 if (netdev
== dev
) {
1648 rc
= QETH_VLAN_CARD
;
1653 if (rc
&& !(vlan_dev_real_dev(dev
)->ml_priv
== (void *)card
))
1659 static int qeth_l3_verify_dev(struct net_device
*dev
)
1661 struct qeth_card
*card
;
1663 unsigned long flags
;
1665 read_lock_irqsave(&qeth_core_card_list
.rwlock
, flags
);
1666 list_for_each_entry(card
, &qeth_core_card_list
.list
, list
) {
1667 if (card
->dev
== dev
) {
1668 rc
= QETH_REAL_CARD
;
1671 rc
= qeth_l3_verify_vlan_dev(dev
, card
);
1675 read_unlock_irqrestore(&qeth_core_card_list
.rwlock
, flags
);
1680 static struct qeth_card
*qeth_l3_get_card_from_dev(struct net_device
*dev
)
1682 struct qeth_card
*card
= NULL
;
1685 rc
= qeth_l3_verify_dev(dev
);
1686 if (rc
== QETH_REAL_CARD
)
1687 card
= dev
->ml_priv
;
1688 else if (rc
== QETH_VLAN_CARD
)
1689 card
= vlan_dev_real_dev(dev
)->ml_priv
;
1690 if (card
&& card
->options
.layer2
)
1693 QETH_CARD_TEXT_(card
, 4, "%d", rc
);
1697 static void qeth_l3_stop_card(struct qeth_card
*card
, int recovery_mode
)
1699 QETH_DBF_TEXT(SETUP
, 2, "stopcard");
1700 QETH_DBF_HEX(SETUP
, 2, &card
, sizeof(void *));
1702 qeth_set_allowed_threads(card
, 0, 1);
1703 if (card
->options
.sniffer
&&
1704 (card
->info
.promisc_mode
== SET_PROMISC_MODE_ON
))
1705 qeth_diags_trace(card
, QETH_DIAGS_CMD_TRACE_DISABLE
);
1706 if (card
->read
.state
== CH_STATE_UP
&&
1707 card
->write
.state
== CH_STATE_UP
&&
1708 (card
->state
== CARD_STATE_UP
)) {
1710 qeth_l3_stop(card
->dev
);
1713 dev_close(card
->dev
);
1716 card
->state
= CARD_STATE_SOFTSETUP
;
1718 if (card
->state
== CARD_STATE_SOFTSETUP
) {
1719 qeth_l3_clear_ip_htable(card
, 1);
1720 qeth_clear_ipacmd_list(card
);
1721 card
->state
= CARD_STATE_HARDSETUP
;
1723 if (card
->state
== CARD_STATE_HARDSETUP
) {
1724 qeth_qdio_clear_card(card
, 0);
1725 qeth_clear_qdio_buffers(card
);
1726 qeth_clear_working_pool_list(card
);
1727 card
->state
= CARD_STATE_DOWN
;
1729 if (card
->state
== CARD_STATE_DOWN
) {
1730 qeth_clear_cmd_buffers(&card
->read
);
1731 qeth_clear_cmd_buffers(&card
->write
);
1736 * test for and Switch promiscuous mode (on or off)
1737 * either for guestlan or HiperSocket Sniffer
1740 qeth_l3_handle_promisc_mode(struct qeth_card
*card
)
1742 struct net_device
*dev
= card
->dev
;
1744 if (((dev
->flags
& IFF_PROMISC
) &&
1745 (card
->info
.promisc_mode
== SET_PROMISC_MODE_ON
)) ||
1746 (!(dev
->flags
& IFF_PROMISC
) &&
1747 (card
->info
.promisc_mode
== SET_PROMISC_MODE_OFF
)))
1750 if (card
->info
.guestlan
) { /* Guestlan trace */
1751 if (qeth_adp_supported(card
, IPA_SETADP_SET_PROMISC_MODE
))
1752 qeth_setadp_promisc_mode(card
);
1753 } else if (card
->options
.sniffer
&& /* HiperSockets trace */
1754 qeth_adp_supported(card
, IPA_SETADP_SET_DIAG_ASSIST
)) {
1755 if (dev
->flags
& IFF_PROMISC
) {
1756 QETH_CARD_TEXT(card
, 3, "+promisc");
1757 qeth_diags_trace(card
, QETH_DIAGS_CMD_TRACE_ENABLE
);
1759 QETH_CARD_TEXT(card
, 3, "-promisc");
1760 qeth_diags_trace(card
, QETH_DIAGS_CMD_TRACE_DISABLE
);
1765 static void qeth_l3_set_rx_mode(struct net_device
*dev
)
1767 struct qeth_card
*card
= dev
->ml_priv
;
1768 struct qeth_ipaddr
*addr
;
1769 struct hlist_node
*tmp
;
1772 QETH_CARD_TEXT(card
, 3, "setmulti");
1773 if (qeth_threads_running(card
, QETH_RECOVER_THREAD
) &&
1774 (card
->state
!= CARD_STATE_UP
))
1776 if (!card
->options
.sniffer
) {
1777 spin_lock_bh(&card
->mclock
);
1779 qeth_l3_add_multicast_ipv4(card
);
1780 qeth_l3_add_multicast_ipv6(card
);
1782 hash_for_each_safe(card
->ip_mc_htable
, i
, tmp
, addr
, hnode
) {
1783 switch (addr
->disp_flag
) {
1784 case QETH_DISP_ADDR_DELETE
:
1785 rc
= qeth_l3_deregister_addr_entry(card
, addr
);
1786 if (!rc
|| rc
== IPA_RC_MC_ADDR_NOT_FOUND
) {
1787 hash_del(&addr
->hnode
);
1791 case QETH_DISP_ADDR_ADD
:
1792 rc
= qeth_l3_register_addr_entry(card
, addr
);
1793 if (rc
&& rc
!= IPA_RC_LAN_OFFLINE
) {
1794 hash_del(&addr
->hnode
);
1798 addr
->ref_counter
= 1;
1801 /* for next call to set_rx_mode(): */
1802 addr
->disp_flag
= QETH_DISP_ADDR_DELETE
;
1806 spin_unlock_bh(&card
->mclock
);
1808 if (!qeth_adp_supported(card
, IPA_SETADP_SET_PROMISC_MODE
))
1811 qeth_l3_handle_promisc_mode(card
);
1814 static const char *qeth_l3_arp_get_error_cause(int *rc
)
1817 case QETH_IPA_ARP_RC_FAILED
:
1819 return "operation failed";
1820 case QETH_IPA_ARP_RC_NOTSUPP
:
1822 return "operation not supported";
1823 case QETH_IPA_ARP_RC_OUT_OF_RANGE
:
1825 return "argument out of range";
1826 case QETH_IPA_ARP_RC_Q_NOTSUPP
:
1828 return "query operation not supported";
1829 case QETH_IPA_ARP_RC_Q_NO_DATA
:
1831 return "no query data available";
1833 return "unknown error";
1837 static int qeth_l3_arp_set_no_entries(struct qeth_card
*card
, int no_entries
)
1842 QETH_CARD_TEXT(card
, 3, "arpstnoe");
1845 * currently GuestLAN only supports the ARP assist function
1846 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_SET_NO_ENTRIES;
1847 * thus we say EOPNOTSUPP for this ARP function
1849 if (card
->info
.guestlan
)
1851 if (!qeth_is_supported(card
, IPA_ARP_PROCESSING
)) {
1854 rc
= qeth_send_simple_setassparms(card
, IPA_ARP_PROCESSING
,
1855 IPA_CMD_ASS_ARP_SET_NO_ENTRIES
,
1859 QETH_DBF_MESSAGE(2, "Could not set number of ARP entries on "
1860 "%s: %s (0x%x/%d)\n", QETH_CARD_IFNAME(card
),
1861 qeth_l3_arp_get_error_cause(&rc
), tmp
, tmp
);
1866 static __u32
get_arp_entry_size(struct qeth_card
*card
,
1867 struct qeth_arp_query_data
*qdata
,
1868 struct qeth_arp_entrytype
*type
, __u8 strip_entries
)
1873 is_hsi
= qdata
->reply_bits
== 5;
1874 if (type
->ip
== QETHARP_IP_ADDR_V4
) {
1875 QETH_CARD_TEXT(card
, 4, "arpev4");
1876 if (strip_entries
) {
1877 rc
= is_hsi
? sizeof(struct qeth_arp_qi_entry5_short
) :
1878 sizeof(struct qeth_arp_qi_entry7_short
);
1880 rc
= is_hsi
? sizeof(struct qeth_arp_qi_entry5
) :
1881 sizeof(struct qeth_arp_qi_entry7
);
1883 } else if (type
->ip
== QETHARP_IP_ADDR_V6
) {
1884 QETH_CARD_TEXT(card
, 4, "arpev6");
1885 if (strip_entries
) {
1887 sizeof(struct qeth_arp_qi_entry5_short_ipv6
) :
1888 sizeof(struct qeth_arp_qi_entry7_short_ipv6
);
1891 sizeof(struct qeth_arp_qi_entry5_ipv6
) :
1892 sizeof(struct qeth_arp_qi_entry7_ipv6
);
1895 QETH_CARD_TEXT(card
, 4, "arpinv");
1902 static int arpentry_matches_prot(struct qeth_arp_entrytype
*type
, __u16 prot
)
1904 return (type
->ip
== QETHARP_IP_ADDR_V4
&& prot
== QETH_PROT_IPV4
) ||
1905 (type
->ip
== QETHARP_IP_ADDR_V6
&& prot
== QETH_PROT_IPV6
);
1908 static int qeth_l3_arp_query_cb(struct qeth_card
*card
,
1909 struct qeth_reply
*reply
, unsigned long data
)
1911 struct qeth_ipa_cmd
*cmd
;
1912 struct qeth_arp_query_data
*qdata
;
1913 struct qeth_arp_query_info
*qinfo
;
1916 int entrybytes_done
;
1918 __u8 do_strip_entries
;
1920 QETH_CARD_TEXT(card
, 3, "arpquecb");
1922 qinfo
= (struct qeth_arp_query_info
*) reply
->param
;
1923 cmd
= (struct qeth_ipa_cmd
*) data
;
1924 QETH_CARD_TEXT_(card
, 4, "%i", cmd
->hdr
.prot_version
);
1925 if (cmd
->hdr
.return_code
) {
1926 QETH_CARD_TEXT(card
, 4, "arpcberr");
1927 QETH_CARD_TEXT_(card
, 4, "%i", cmd
->hdr
.return_code
);
1930 if (cmd
->data
.setassparms
.hdr
.return_code
) {
1931 cmd
->hdr
.return_code
= cmd
->data
.setassparms
.hdr
.return_code
;
1932 QETH_CARD_TEXT(card
, 4, "setaperr");
1933 QETH_CARD_TEXT_(card
, 4, "%i", cmd
->hdr
.return_code
);
1936 qdata
= &cmd
->data
.setassparms
.data
.query_arp
;
1937 QETH_CARD_TEXT_(card
, 4, "anoen%i", qdata
->no_entries
);
1939 do_strip_entries
= (qinfo
->mask_bits
& QETH_QARP_STRIP_ENTRIES
) > 0;
1940 stripped_bytes
= do_strip_entries
? QETH_QARP_MEDIASPECIFIC_BYTES
: 0;
1941 entrybytes_done
= 0;
1942 for (e
= 0; e
< qdata
->no_entries
; ++e
) {
1945 struct qeth_arp_entrytype
*etype
;
1947 cur_entry
= &qdata
->data
+ entrybytes_done
;
1948 etype
= &((struct qeth_arp_qi_entry5
*) cur_entry
)->type
;
1949 if (!arpentry_matches_prot(etype
, cmd
->hdr
.prot_version
)) {
1950 QETH_CARD_TEXT(card
, 4, "pmis");
1951 QETH_CARD_TEXT_(card
, 4, "%i", etype
->ip
);
1954 esize
= get_arp_entry_size(card
, qdata
, etype
,
1956 QETH_CARD_TEXT_(card
, 5, "esz%i", esize
);
1960 if ((qinfo
->udata_len
- qinfo
->udata_offset
) < esize
) {
1961 QETH_CARD_TEXT_(card
, 4, "qaer3%i", -ENOMEM
);
1962 cmd
->hdr
.return_code
= IPA_RC_ENOMEM
;
1966 memcpy(qinfo
->udata
+ qinfo
->udata_offset
,
1967 &qdata
->data
+ entrybytes_done
+ stripped_bytes
,
1969 entrybytes_done
+= esize
+ stripped_bytes
;
1970 qinfo
->udata_offset
+= esize
;
1971 ++qinfo
->no_entries
;
1973 /* check if all replies received ... */
1974 if (cmd
->data
.setassparms
.hdr
.seq_no
<
1975 cmd
->data
.setassparms
.hdr
.number_of_replies
)
1977 QETH_CARD_TEXT_(card
, 4, "nove%i", qinfo
->no_entries
);
1978 memcpy(qinfo
->udata
, &qinfo
->no_entries
, 4);
1979 /* keep STRIP_ENTRIES flag so the user program can distinguish
1980 * stripped entries from normal ones */
1981 if (qinfo
->mask_bits
& QETH_QARP_STRIP_ENTRIES
)
1982 qdata
->reply_bits
|= QETH_QARP_STRIP_ENTRIES
;
1983 memcpy(qinfo
->udata
+ QETH_QARP_MASK_OFFSET
, &qdata
->reply_bits
, 2);
1984 QETH_CARD_TEXT_(card
, 4, "rc%i", 0);
1988 memcpy(qinfo
->udata
, &i
, 4);
1992 static int qeth_l3_send_ipa_arp_cmd(struct qeth_card
*card
,
1993 struct qeth_cmd_buffer
*iob
, int len
,
1994 int (*reply_cb
)(struct qeth_card
*, struct qeth_reply
*,
1998 QETH_CARD_TEXT(card
, 4, "sendarp");
2000 memcpy(iob
->data
, IPA_PDU_HEADER
, IPA_PDU_HEADER_SIZE
);
2001 memcpy(QETH_IPA_CMD_DEST_ADDR(iob
->data
),
2002 &card
->token
.ulp_connection_r
, QETH_MPC_TOKEN_LENGTH
);
2003 return qeth_send_control_data(card
, IPA_PDU_HEADER_SIZE
+ len
, iob
,
2004 reply_cb
, reply_param
);
2007 static int qeth_l3_query_arp_cache_info(struct qeth_card
*card
,
2008 enum qeth_prot_versions prot
,
2009 struct qeth_arp_query_info
*qinfo
)
2011 struct qeth_cmd_buffer
*iob
;
2012 struct qeth_ipa_cmd
*cmd
;
2016 QETH_CARD_TEXT_(card
, 3, "qarpipv%i", prot
);
2018 iob
= qeth_get_setassparms_cmd(card
, IPA_ARP_PROCESSING
,
2019 IPA_CMD_ASS_ARP_QUERY_INFO
,
2020 sizeof(struct qeth_arp_query_data
)
2025 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
2026 cmd
->data
.setassparms
.data
.query_arp
.request_bits
= 0x000F;
2027 cmd
->data
.setassparms
.data
.query_arp
.reply_bits
= 0;
2028 cmd
->data
.setassparms
.data
.query_arp
.no_entries
= 0;
2029 rc
= qeth_l3_send_ipa_arp_cmd(card
, iob
,
2030 QETH_SETASS_BASE_LEN
+QETH_ARP_CMD_LEN
,
2031 qeth_l3_arp_query_cb
, (void *)qinfo
);
2035 "Error while querying ARP cache on %s: %s "
2036 "(0x%x/%d)\n", QETH_CARD_IFNAME(card
),
2037 qeth_l3_arp_get_error_cause(&rc
), tmp
, tmp
);
2043 static int qeth_l3_arp_query(struct qeth_card
*card
, char __user
*udata
)
2045 struct qeth_arp_query_info qinfo
= {0, };
2048 QETH_CARD_TEXT(card
, 3, "arpquery");
2050 if (!qeth_is_supported(card
,/*IPA_QUERY_ARP_ADDR_INFO*/
2051 IPA_ARP_PROCESSING
)) {
2052 QETH_CARD_TEXT(card
, 3, "arpqnsup");
2056 /* get size of userspace buffer and mask_bits -> 6 bytes */
2057 if (copy_from_user(&qinfo
, udata
, 6)) {
2061 qinfo
.udata
= kzalloc(qinfo
.udata_len
, GFP_KERNEL
);
2066 qinfo
.udata_offset
= QETH_QARP_ENTRIES_OFFSET
;
2067 rc
= qeth_l3_query_arp_cache_info(card
, QETH_PROT_IPV4
, &qinfo
);
2069 if (copy_to_user(udata
, qinfo
.udata
, 4))
2073 if (qinfo
.mask_bits
& QETH_QARP_WITH_IPV6
) {
2074 /* fails in case of GuestLAN QDIO mode */
2075 qeth_l3_query_arp_cache_info(card
, QETH_PROT_IPV6
, &qinfo
);
2077 if (copy_to_user(udata
, qinfo
.udata
, qinfo
.udata_len
)) {
2078 QETH_CARD_TEXT(card
, 4, "qactf");
2082 QETH_CARD_TEXT(card
, 4, "qacts");
2090 static int qeth_l3_arp_add_entry(struct qeth_card
*card
,
2091 struct qeth_arp_cache_entry
*entry
)
2093 struct qeth_cmd_buffer
*iob
;
2098 QETH_CARD_TEXT(card
, 3, "arpadent");
2101 * currently GuestLAN only supports the ARP assist function
2102 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_ADD_ENTRY;
2103 * thus we say EOPNOTSUPP for this ARP function
2105 if (card
->info
.guestlan
)
2107 if (!qeth_is_supported(card
, IPA_ARP_PROCESSING
)) {
2111 iob
= qeth_get_setassparms_cmd(card
, IPA_ARP_PROCESSING
,
2112 IPA_CMD_ASS_ARP_ADD_ENTRY
,
2113 sizeof(struct qeth_arp_cache_entry
),
2117 rc
= qeth_send_setassparms(card
, iob
,
2118 sizeof(struct qeth_arp_cache_entry
),
2119 (unsigned long) entry
,
2120 qeth_setassparms_cb
, NULL
);
2123 qeth_l3_ipaddr4_to_string((u8
*)entry
->ipaddr
, buf
);
2124 QETH_DBF_MESSAGE(2, "Could not add ARP entry for address %s "
2125 "on %s: %s (0x%x/%d)\n", buf
, QETH_CARD_IFNAME(card
),
2126 qeth_l3_arp_get_error_cause(&rc
), tmp
, tmp
);
2131 static int qeth_l3_arp_remove_entry(struct qeth_card
*card
,
2132 struct qeth_arp_cache_entry
*entry
)
2134 struct qeth_cmd_buffer
*iob
;
2135 char buf
[16] = {0, };
2139 QETH_CARD_TEXT(card
, 3, "arprment");
2142 * currently GuestLAN only supports the ARP assist function
2143 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_REMOVE_ENTRY;
2144 * thus we say EOPNOTSUPP for this ARP function
2146 if (card
->info
.guestlan
)
2148 if (!qeth_is_supported(card
, IPA_ARP_PROCESSING
)) {
2151 memcpy(buf
, entry
, 12);
2152 iob
= qeth_get_setassparms_cmd(card
, IPA_ARP_PROCESSING
,
2153 IPA_CMD_ASS_ARP_REMOVE_ENTRY
,
2158 rc
= qeth_send_setassparms(card
, iob
,
2159 12, (unsigned long)buf
,
2160 qeth_setassparms_cb
, NULL
);
2164 qeth_l3_ipaddr4_to_string((u8
*)entry
->ipaddr
, buf
);
2165 QETH_DBF_MESSAGE(2, "Could not delete ARP entry for address %s"
2166 " on %s: %s (0x%x/%d)\n", buf
, QETH_CARD_IFNAME(card
),
2167 qeth_l3_arp_get_error_cause(&rc
), tmp
, tmp
);
2172 static int qeth_l3_arp_flush_cache(struct qeth_card
*card
)
2177 QETH_CARD_TEXT(card
, 3, "arpflush");
2180 * currently GuestLAN only supports the ARP assist function
2181 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_FLUSH_CACHE;
2182 * thus we say EOPNOTSUPP for this ARP function
2184 if (card
->info
.guestlan
|| (card
->info
.type
== QETH_CARD_TYPE_IQD
))
2186 if (!qeth_is_supported(card
, IPA_ARP_PROCESSING
)) {
2189 rc
= qeth_send_simple_setassparms(card
, IPA_ARP_PROCESSING
,
2190 IPA_CMD_ASS_ARP_FLUSH_CACHE
, 0);
2193 QETH_DBF_MESSAGE(2, "Could not flush ARP cache on %s: %s "
2194 "(0x%x/%d)\n", QETH_CARD_IFNAME(card
),
2195 qeth_l3_arp_get_error_cause(&rc
), tmp
, tmp
);
2200 static int qeth_l3_do_ioctl(struct net_device
*dev
, struct ifreq
*rq
, int cmd
)
2202 struct qeth_card
*card
= dev
->ml_priv
;
2203 struct qeth_arp_cache_entry arp_entry
;
2207 case SIOC_QETH_ARP_SET_NO_ENTRIES
:
2208 if (!capable(CAP_NET_ADMIN
)) {
2212 rc
= qeth_l3_arp_set_no_entries(card
, rq
->ifr_ifru
.ifru_ivalue
);
2214 case SIOC_QETH_ARP_QUERY_INFO
:
2215 if (!capable(CAP_NET_ADMIN
)) {
2219 rc
= qeth_l3_arp_query(card
, rq
->ifr_ifru
.ifru_data
);
2221 case SIOC_QETH_ARP_ADD_ENTRY
:
2222 if (!capable(CAP_NET_ADMIN
)) {
2226 if (copy_from_user(&arp_entry
, rq
->ifr_ifru
.ifru_data
,
2227 sizeof(struct qeth_arp_cache_entry
)))
2230 rc
= qeth_l3_arp_add_entry(card
, &arp_entry
);
2232 case SIOC_QETH_ARP_REMOVE_ENTRY
:
2233 if (!capable(CAP_NET_ADMIN
)) {
2237 if (copy_from_user(&arp_entry
, rq
->ifr_ifru
.ifru_data
,
2238 sizeof(struct qeth_arp_cache_entry
)))
2241 rc
= qeth_l3_arp_remove_entry(card
, &arp_entry
);
2243 case SIOC_QETH_ARP_FLUSH_CACHE
:
2244 if (!capable(CAP_NET_ADMIN
)) {
2248 rc
= qeth_l3_arp_flush_cache(card
);
2256 static int qeth_l3_get_cast_type(struct sk_buff
*skb
)
2258 struct neighbour
*n
= NULL
;
2259 struct dst_entry
*dst
;
2264 n
= dst_neigh_lookup_skb(dst
, skb
);
2266 int cast_type
= n
->type
;
2270 if ((cast_type
== RTN_BROADCAST
) ||
2271 (cast_type
== RTN_MULTICAST
) ||
2272 (cast_type
== RTN_ANYCAST
))
2278 /* no neighbour (eg AF_PACKET), fall back to target's IP address ... */
2279 if (be16_to_cpu(skb
->protocol
) == ETH_P_IPV6
)
2280 return ipv6_addr_is_multicast(&ipv6_hdr(skb
)->daddr
) ?
2281 RTN_MULTICAST
: RTN_UNSPEC
;
2282 else if (be16_to_cpu(skb
->protocol
) == ETH_P_IP
)
2283 return ipv4_is_multicast(ip_hdr(skb
)->daddr
) ?
2284 RTN_MULTICAST
: RTN_UNSPEC
;
2286 /* ... and MAC address */
2287 if (ether_addr_equal_64bits(eth_hdr(skb
)->h_dest
, skb
->dev
->broadcast
))
2288 return RTN_BROADCAST
;
2289 if (is_multicast_ether_addr(eth_hdr(skb
)->h_dest
))
2290 return RTN_MULTICAST
;
2292 /* default to unicast */
2296 static void qeth_l3_fill_af_iucv_hdr(struct qeth_card
*card
,
2297 struct qeth_hdr
*hdr
, struct sk_buff
*skb
)
2300 struct af_iucv_trans_hdr
*iucv_hdr
;
2302 memset(hdr
, 0, sizeof(struct qeth_hdr
));
2303 hdr
->hdr
.l3
.id
= QETH_HEADER_TYPE_LAYER3
;
2304 hdr
->hdr
.l3
.ext_flags
= 0;
2305 hdr
->hdr
.l3
.length
= skb
->len
- ETH_HLEN
;
2306 hdr
->hdr
.l3
.flags
= QETH_HDR_IPV6
| QETH_CAST_UNICAST
;
2308 iucv_hdr
= (struct af_iucv_trans_hdr
*) (skb
->data
+ ETH_HLEN
);
2309 memset(daddr
, 0, sizeof(daddr
));
2312 memcpy(&daddr
[8], iucv_hdr
->destUserID
, 8);
2313 memcpy(hdr
->hdr
.l3
.next_hop
.ipv6_addr
, daddr
, 16);
2316 static u8
qeth_l3_cast_type_to_flag(int cast_type
)
2318 if (cast_type
== RTN_MULTICAST
)
2319 return QETH_CAST_MULTICAST
;
2320 if (cast_type
== RTN_ANYCAST
)
2321 return QETH_CAST_ANYCAST
;
2322 if (cast_type
== RTN_BROADCAST
)
2323 return QETH_CAST_BROADCAST
;
2324 return QETH_CAST_UNICAST
;
2327 static void qeth_l3_fill_header(struct qeth_card
*card
, struct qeth_hdr
*hdr
,
2328 struct sk_buff
*skb
, int ipv
, int cast_type
,
2329 unsigned int data_len
)
2331 memset(hdr
, 0, sizeof(struct qeth_hdr
));
2332 hdr
->hdr
.l3
.id
= QETH_HEADER_TYPE_LAYER3
;
2333 hdr
->hdr
.l3
.length
= data_len
;
2336 * before we're going to overwrite this location with next hop ip.
2337 * v6 uses passthrough, v4 sets the tag in the QDIO header.
2339 if (skb_vlan_tag_present(skb
)) {
2340 if ((ipv
== 4) || (card
->info
.type
== QETH_CARD_TYPE_IQD
))
2341 hdr
->hdr
.l3
.ext_flags
= QETH_HDR_EXT_VLAN_FRAME
;
2343 hdr
->hdr
.l3
.ext_flags
= QETH_HDR_EXT_INCLUDE_VLAN_TAG
;
2344 hdr
->hdr
.l3
.vlan_id
= skb_vlan_tag_get(skb
);
2349 hdr
->hdr
.l3
.flags
= QETH_HDR_PASSTHRU
;
2350 if (ether_addr_equal_64bits(eth_hdr(skb
)->h_dest
,
2351 skb
->dev
->broadcast
))
2352 hdr
->hdr
.l3
.flags
|= QETH_CAST_BROADCAST
;
2354 hdr
->hdr
.l3
.flags
|= (cast_type
== RTN_MULTICAST
) ?
2355 QETH_CAST_MULTICAST
: QETH_CAST_UNICAST
;
2359 hdr
->hdr
.l3
.flags
= qeth_l3_cast_type_to_flag(cast_type
);
2362 struct rtable
*rt
= skb_rtable(skb
);
2364 *((__be32
*) &hdr
->hdr
.l3
.next_hop
.ipv4
.addr
) = (rt
) ?
2365 rt_nexthop(rt
, ip_hdr(skb
)->daddr
) :
2369 const struct rt6_info
*rt
= skb_rt6_info(skb
);
2370 const struct in6_addr
*next_hop
;
2372 if (rt
&& !ipv6_addr_any(&rt
->rt6i_gateway
))
2373 next_hop
= &rt
->rt6i_gateway
;
2375 next_hop
= &ipv6_hdr(skb
)->daddr
;
2376 memcpy(hdr
->hdr
.l3
.next_hop
.ipv6_addr
, next_hop
, 16);
2378 hdr
->hdr
.l3
.flags
|= QETH_HDR_IPV6
;
2379 if (card
->info
.type
!= QETH_CARD_TYPE_IQD
)
2380 hdr
->hdr
.l3
.flags
|= QETH_HDR_PASSTHRU
;
2385 static void qeth_l3_hdr_csum(struct qeth_card
*card
, struct qeth_hdr
*hdr
,
2386 struct sk_buff
*skb
)
2388 struct iphdr
*iph
= ip_hdr(skb
);
2390 /* tcph->check contains already the pseudo hdr checksum
2391 * so just set the header flags
2393 if (iph
->protocol
== IPPROTO_UDP
)
2394 hdr
->hdr
.l3
.ext_flags
|= QETH_HDR_EXT_UDP
;
2395 hdr
->hdr
.l3
.ext_flags
|= QETH_HDR_EXT_CSUM_TRANSP_REQ
|
2396 QETH_HDR_EXT_CSUM_HDR_REQ
;
2398 if (card
->options
.performance_stats
)
2399 card
->perf_stats
.tx_csum
++;
2402 static void qeth_tso_fill_header(struct qeth_card
*card
,
2403 struct qeth_hdr
*qhdr
, struct sk_buff
*skb
)
2405 struct qeth_hdr_tso
*hdr
= (struct qeth_hdr_tso
*)qhdr
;
2406 struct tcphdr
*tcph
= tcp_hdr(skb
);
2407 struct iphdr
*iph
= ip_hdr(skb
);
2408 struct ipv6hdr
*ip6h
= ipv6_hdr(skb
);
2410 /*fix header to TSO values ...*/
2411 hdr
->hdr
.hdr
.l3
.id
= QETH_HEADER_TYPE_TSO
;
2412 /*set values which are fix for the first approach ...*/
2413 hdr
->ext
.hdr_tot_len
= (__u16
) sizeof(struct qeth_hdr_ext_tso
);
2414 hdr
->ext
.imb_hdr_no
= 1;
2415 hdr
->ext
.hdr_type
= 1;
2416 hdr
->ext
.hdr_version
= 1;
2417 hdr
->ext
.hdr_len
= 28;
2418 /*insert non-fix values */
2419 hdr
->ext
.mss
= skb_shinfo(skb
)->gso_size
;
2420 hdr
->ext
.dg_hdr_len
= (__u16
)(ip_hdrlen(skb
) + tcp_hdrlen(skb
));
2421 hdr
->ext
.payload_len
= (__u16
)(skb
->len
- hdr
->ext
.dg_hdr_len
-
2422 sizeof(struct qeth_hdr_tso
));
2424 if (be16_to_cpu(skb
->protocol
) == ETH_P_IPV6
) {
2425 ip6h
->payload_len
= 0;
2426 tcph
->check
= ~csum_ipv6_magic(&ip6h
->saddr
, &ip6h
->daddr
,
2429 /*OSA want us to set these values ...*/
2430 tcph
->check
= ~csum_tcpudp_magic(iph
->saddr
, iph
->daddr
,
2438 * qeth_l3_get_elements_no_tso() - find number of SBALEs for skb data for tso
2439 * @card: qeth card structure, to check max. elems.
2441 * @extra_elems: extra elems needed, to check against max.
2443 * Returns the number of pages, and thus QDIO buffer elements, needed to cover
2444 * skb data, including linear part and fragments, but excluding TCP header.
2445 * (Exclusion of TCP header distinguishes it from qeth_get_elements_no().)
2446 * Checks if the result plus extra_elems fits under the limit for the card.
2447 * Returns 0 if it does not.
2448 * Note: extra_elems is not included in the returned result.
2450 static int qeth_l3_get_elements_no_tso(struct qeth_card
*card
,
2451 struct sk_buff
*skb
, int extra_elems
)
2453 addr_t tcpdptr
= (addr_t
)tcp_hdr(skb
) + tcp_hdrlen(skb
);
2454 int elements
= qeth_get_elements_for_range(
2456 (addr_t
)skb
->data
+ skb_headlen(skb
)) +
2457 qeth_get_elements_for_frags(skb
);
2459 if ((elements
+ extra_elems
) > QETH_MAX_BUFFER_ELEMENTS(card
)) {
2461 "Invalid size of TSO IP packet (Number=%d / Length=%d). Discarded.\n",
2462 elements
+ extra_elems
, skb
->len
);
2468 static netdev_tx_t
qeth_l3_hard_start_xmit(struct sk_buff
*skb
,
2469 struct net_device
*dev
)
2473 struct qeth_hdr
*hdr
= NULL
;
2474 int hdr_elements
= 0;
2476 struct qeth_card
*card
= dev
->ml_priv
;
2477 struct sk_buff
*new_skb
= NULL
;
2478 int ipv
= qeth_get_ip_version(skb
);
2479 int cast_type
= qeth_l3_get_cast_type(skb
);
2480 struct qeth_qdio_out_q
*queue
=
2481 card
->qdio
.out_qs
[card
->qdio
.do_prio_queueing
2482 || (cast_type
&& card
->info
.is_multicast_different
) ?
2483 qeth_get_priority_queue(card
, skb
, ipv
, cast_type
) :
2484 card
->qdio
.default_out_queue
];
2485 int tx_bytes
= skb
->len
;
2486 unsigned int hd_len
= 0;
2488 int data_offset
= -1;
2489 unsigned int nr_frags
;
2491 if (((card
->info
.type
== QETH_CARD_TYPE_IQD
) &&
2492 (((card
->options
.cq
!= QETH_CQ_ENABLED
) && !ipv
) ||
2493 ((card
->options
.cq
== QETH_CQ_ENABLED
) &&
2494 (be16_to_cpu(skb
->protocol
) != ETH_P_AF_IUCV
)))) ||
2495 card
->options
.sniffer
)
2498 if ((card
->state
!= CARD_STATE_UP
) || !card
->lan_online
) {
2499 card
->stats
.tx_carrier_errors
++;
2503 if ((cast_type
== RTN_BROADCAST
) &&
2504 (card
->info
.broadcast_capable
== 0))
2507 if (card
->options
.performance_stats
) {
2508 card
->perf_stats
.outbound_cnt
++;
2509 card
->perf_stats
.outbound_start_time
= qeth_get_micros();
2512 /* Ignore segment size from skb_is_gso(), 1 page is always used. */
2513 use_tso
= skb_is_gso(skb
) &&
2514 (skb_shinfo(skb
)->gso_type
& SKB_GSO_TCPV4
);
2516 if (card
->info
.type
== QETH_CARD_TYPE_IQD
) {
2518 data_offset
= ETH_HLEN
;
2519 hd_len
= sizeof(*hdr
);
2520 hdr
= kmem_cache_alloc(qeth_core_header_cache
, GFP_ATOMIC
);
2525 /* create a clone with writeable headroom */
2526 new_skb
= skb_realloc_headroom(skb
, sizeof(struct qeth_hdr_tso
)
2532 skb_pull(new_skb
, ETH_HLEN
);
2535 if (ipv
!= 4 && skb_vlan_tag_present(new_skb
)) {
2536 skb_push(new_skb
, VLAN_HLEN
);
2537 skb_copy_to_linear_data(new_skb
, new_skb
->data
+ 4, 4);
2538 skb_copy_to_linear_data_offset(new_skb
, 4,
2539 new_skb
->data
+ 8, 4);
2540 skb_copy_to_linear_data_offset(new_skb
, 8,
2541 new_skb
->data
+ 12, 4);
2542 tag
= (__be16
*)(new_skb
->data
+ 12);
2543 *tag
= cpu_to_be16(ETH_P_8021Q
);
2544 *(tag
+ 1) = cpu_to_be16(skb_vlan_tag_get(new_skb
));
2548 netif_stop_queue(dev
);
2550 /* fix hardware limitation: as long as we do not have sbal
2551 * chaining we can not send long frag lists
2553 if ((card
->info
.type
!= QETH_CARD_TYPE_IQD
) &&
2554 ((use_tso
&& !qeth_l3_get_elements_no_tso(card
, new_skb
, 1)) ||
2555 (!use_tso
&& !qeth_get_elements_no(card
, new_skb
, 0, 0)))) {
2556 int lin_rc
= skb_linearize(new_skb
);
2558 if (card
->options
.performance_stats
) {
2560 card
->perf_stats
.tx_linfail
++;
2562 card
->perf_stats
.tx_lin
++;
2567 nr_frags
= skb_shinfo(new_skb
)->nr_frags
;
2570 hdr
= skb_push(new_skb
, sizeof(struct qeth_hdr_tso
));
2571 memset(hdr
, 0, sizeof(struct qeth_hdr_tso
));
2572 qeth_l3_fill_header(card
, hdr
, new_skb
, ipv
, cast_type
,
2573 new_skb
->len
- sizeof(struct qeth_hdr_tso
));
2574 qeth_tso_fill_header(card
, hdr
, new_skb
);
2577 if (data_offset
< 0) {
2578 hdr
= skb_push(new_skb
, sizeof(struct qeth_hdr
));
2579 qeth_l3_fill_header(card
, hdr
, new_skb
, ipv
, cast_type
,
2581 sizeof(struct qeth_hdr
));
2583 if (be16_to_cpu(new_skb
->protocol
) == ETH_P_AF_IUCV
)
2584 qeth_l3_fill_af_iucv_hdr(card
, hdr
, new_skb
);
2586 qeth_l3_fill_header(card
, hdr
, new_skb
, ipv
,
2588 new_skb
->len
- data_offset
);
2592 if (skb
->ip_summed
== CHECKSUM_PARTIAL
)
2593 qeth_l3_hdr_csum(card
, hdr
, new_skb
);
2596 elements
= use_tso
?
2597 qeth_l3_get_elements_no_tso(card
, new_skb
, hdr_elements
) :
2598 qeth_get_elements_no(card
, new_skb
, hdr_elements
,
2599 (data_offset
> 0) ? data_offset
: 0);
2601 if (data_offset
>= 0)
2602 kmem_cache_free(qeth_core_header_cache
, hdr
);
2605 elements
+= hdr_elements
;
2607 if (card
->info
.type
!= QETH_CARD_TYPE_IQD
) {
2610 hd_len
= sizeof(struct qeth_hdr_tso
) +
2611 ip_hdrlen(new_skb
) + tcp_hdrlen(new_skb
);
2614 len
= sizeof(struct qeth_hdr_layer3
);
2617 if (qeth_hdr_chk_and_bounce(new_skb
, &hdr
, len
))
2619 rc
= qeth_do_send_packet(card
, queue
, new_skb
, hdr
, hd_len
,
2622 rc
= qeth_do_send_packet_fast(queue
, new_skb
, hdr
, data_offset
,
2626 card
->stats
.tx_packets
++;
2627 card
->stats
.tx_bytes
+= tx_bytes
;
2629 dev_kfree_skb_any(skb
);
2630 if (card
->options
.performance_stats
) {
2632 card
->perf_stats
.large_send_bytes
+= tx_bytes
;
2633 card
->perf_stats
.large_send_cnt
++;
2636 card
->perf_stats
.sg_skbs_sent
++;
2637 /* nr_frags + skb->data */
2638 card
->perf_stats
.sg_frags_sent
+= nr_frags
+ 1;
2643 if (data_offset
>= 0)
2644 kmem_cache_free(qeth_core_header_cache
, hdr
);
2648 dev_kfree_skb_any(new_skb
);
2649 return NETDEV_TX_BUSY
;
2654 netif_wake_queue(dev
);
2655 if (card
->options
.performance_stats
)
2656 card
->perf_stats
.outbound_time
+= qeth_get_micros() -
2657 card
->perf_stats
.outbound_start_time
;
2661 card
->stats
.tx_dropped
++;
2662 card
->stats
.tx_errors
++;
2663 if ((new_skb
!= skb
) && new_skb
)
2664 dev_kfree_skb_any(new_skb
);
2665 dev_kfree_skb_any(skb
);
2666 netif_wake_queue(dev
);
2667 return NETDEV_TX_OK
;
2670 static int __qeth_l3_open(struct net_device
*dev
)
2672 struct qeth_card
*card
= dev
->ml_priv
;
2675 QETH_CARD_TEXT(card
, 4, "qethopen");
2676 if (card
->state
== CARD_STATE_UP
)
2678 if (card
->state
!= CARD_STATE_SOFTSETUP
)
2680 card
->data
.state
= CH_STATE_UP
;
2681 card
->state
= CARD_STATE_UP
;
2682 netif_start_queue(dev
);
2684 if (qdio_stop_irq(card
->data
.ccwdev
, 0) >= 0) {
2685 napi_enable(&card
->napi
);
2686 napi_schedule(&card
->napi
);
2692 static int qeth_l3_open(struct net_device
*dev
)
2694 struct qeth_card
*card
= dev
->ml_priv
;
2696 QETH_CARD_TEXT(card
, 5, "qethope_");
2697 if (qeth_wait_for_threads(card
, QETH_RECOVER_THREAD
)) {
2698 QETH_CARD_TEXT(card
, 3, "openREC");
2699 return -ERESTARTSYS
;
2701 return __qeth_l3_open(dev
);
2704 static int qeth_l3_stop(struct net_device
*dev
)
2706 struct qeth_card
*card
= dev
->ml_priv
;
2708 QETH_CARD_TEXT(card
, 4, "qethstop");
2709 netif_tx_disable(dev
);
2710 if (card
->state
== CARD_STATE_UP
) {
2711 card
->state
= CARD_STATE_SOFTSETUP
;
2712 napi_disable(&card
->napi
);
2717 static const struct ethtool_ops qeth_l3_ethtool_ops
= {
2718 .get_link
= ethtool_op_get_link
,
2719 .get_strings
= qeth_core_get_strings
,
2720 .get_ethtool_stats
= qeth_core_get_ethtool_stats
,
2721 .get_sset_count
= qeth_core_get_sset_count
,
2722 .get_drvinfo
= qeth_core_get_drvinfo
,
2723 .get_link_ksettings
= qeth_core_ethtool_get_link_ksettings
,
2727 * we need NOARP for IPv4 but we want neighbor solicitation for IPv6. Setting
2728 * NOARP on the netdevice is no option because it also turns off neighbor
2729 * solicitation. For IPv4 we install a neighbor_setup function. We don't want
2730 * arp resolution but we want the hard header (packet socket will work
2733 static int qeth_l3_neigh_setup_noarp(struct neighbour
*n
)
2735 n
->nud_state
= NUD_NOARP
;
2736 memcpy(n
->ha
, "FAKELL", 6);
2737 n
->output
= n
->ops
->connected_output
;
2742 qeth_l3_neigh_setup(struct net_device
*dev
, struct neigh_parms
*np
)
2744 if (np
->tbl
->family
== AF_INET
)
2745 np
->neigh_setup
= qeth_l3_neigh_setup_noarp
;
2750 static const struct net_device_ops qeth_l3_netdev_ops
= {
2751 .ndo_open
= qeth_l3_open
,
2752 .ndo_stop
= qeth_l3_stop
,
2753 .ndo_get_stats
= qeth_get_stats
,
2754 .ndo_start_xmit
= qeth_l3_hard_start_xmit
,
2755 .ndo_validate_addr
= eth_validate_addr
,
2756 .ndo_set_rx_mode
= qeth_l3_set_rx_mode
,
2757 .ndo_do_ioctl
= qeth_do_ioctl
,
2758 .ndo_change_mtu
= qeth_change_mtu
,
2759 .ndo_fix_features
= qeth_fix_features
,
2760 .ndo_set_features
= qeth_set_features
,
2761 .ndo_vlan_rx_add_vid
= qeth_l3_vlan_rx_add_vid
,
2762 .ndo_vlan_rx_kill_vid
= qeth_l3_vlan_rx_kill_vid
,
2763 .ndo_tx_timeout
= qeth_tx_timeout
,
2766 static const struct net_device_ops qeth_l3_osa_netdev_ops
= {
2767 .ndo_open
= qeth_l3_open
,
2768 .ndo_stop
= qeth_l3_stop
,
2769 .ndo_get_stats
= qeth_get_stats
,
2770 .ndo_start_xmit
= qeth_l3_hard_start_xmit
,
2771 .ndo_features_check
= qeth_features_check
,
2772 .ndo_validate_addr
= eth_validate_addr
,
2773 .ndo_set_rx_mode
= qeth_l3_set_rx_mode
,
2774 .ndo_do_ioctl
= qeth_do_ioctl
,
2775 .ndo_change_mtu
= qeth_change_mtu
,
2776 .ndo_fix_features
= qeth_fix_features
,
2777 .ndo_set_features
= qeth_set_features
,
2778 .ndo_vlan_rx_add_vid
= qeth_l3_vlan_rx_add_vid
,
2779 .ndo_vlan_rx_kill_vid
= qeth_l3_vlan_rx_kill_vid
,
2780 .ndo_tx_timeout
= qeth_tx_timeout
,
2781 .ndo_neigh_setup
= qeth_l3_neigh_setup
,
2784 static int qeth_l3_setup_netdev(struct qeth_card
*card
)
2788 if (card
->info
.type
== QETH_CARD_TYPE_OSD
||
2789 card
->info
.type
== QETH_CARD_TYPE_OSX
) {
2790 if ((card
->info
.link_type
== QETH_LINK_TYPE_LANE_TR
) ||
2791 (card
->info
.link_type
== QETH_LINK_TYPE_HSTR
)) {
2792 pr_info("qeth_l3: ignoring TR device\n");
2795 card
->dev
= alloc_etherdev(0);
2798 card
->dev
->netdev_ops
= &qeth_l3_osa_netdev_ops
;
2800 /*IPv6 address autoconfiguration stuff*/
2801 qeth_l3_get_unique_id(card
);
2802 if (!(card
->info
.unique_id
& UNIQUE_ID_NOT_BY_CARD
))
2803 card
->dev
->dev_id
= card
->info
.unique_id
&
2805 if (!card
->info
.guestlan
) {
2806 card
->dev
->hw_features
= NETIF_F_SG
|
2807 NETIF_F_RXCSUM
| NETIF_F_IP_CSUM
|
2809 card
->dev
->vlan_features
= NETIF_F_SG
|
2810 NETIF_F_RXCSUM
| NETIF_F_IP_CSUM
|
2812 card
->dev
->features
|= NETIF_F_SG
;
2815 } else if (card
->info
.type
== QETH_CARD_TYPE_IQD
) {
2816 card
->dev
= alloc_netdev(0, "hsi%d", NET_NAME_UNKNOWN
,
2820 card
->dev
->flags
|= IFF_NOARP
;
2821 card
->dev
->netdev_ops
= &qeth_l3_netdev_ops
;
2822 rc
= qeth_l3_iqd_read_initial_mac(card
);
2825 if (card
->options
.hsuid
[0])
2826 memcpy(card
->dev
->perm_addr
, card
->options
.hsuid
, 9);
2830 card
->dev
->ml_priv
= card
;
2831 card
->dev
->watchdog_timeo
= QETH_TX_TIMEOUT
;
2832 card
->dev
->mtu
= card
->info
.initial_mtu
;
2833 card
->dev
->min_mtu
= 64;
2834 card
->dev
->max_mtu
= ETH_MAX_MTU
;
2835 card
->dev
->ethtool_ops
= &qeth_l3_ethtool_ops
;
2836 card
->dev
->features
|= NETIF_F_HW_VLAN_CTAG_TX
|
2837 NETIF_F_HW_VLAN_CTAG_RX
|
2838 NETIF_F_HW_VLAN_CTAG_FILTER
;
2839 netif_keep_dst(card
->dev
);
2840 netif_set_gso_max_size(card
->dev
, (QETH_MAX_BUFFER_ELEMENTS(card
) - 1) *
2843 SET_NETDEV_DEV(card
->dev
, &card
->gdev
->dev
);
2844 netif_napi_add(card
->dev
, &card
->napi
, qeth_poll
, QETH_NAPI_WEIGHT
);
2845 netif_carrier_off(card
->dev
);
2846 return register_netdev(card
->dev
);
2849 static const struct device_type qeth_l3_devtype
= {
2850 .name
= "qeth_layer3",
2851 .groups
= qeth_l3_attr_groups
,
2854 static int qeth_l3_probe_device(struct ccwgroup_device
*gdev
)
2856 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
2859 if (gdev
->dev
.type
== &qeth_generic_devtype
) {
2860 rc
= qeth_l3_create_device_attributes(&gdev
->dev
);
2864 hash_init(card
->ip_htable
);
2865 hash_init(card
->ip_mc_htable
);
2866 card
->options
.layer2
= 0;
2867 card
->info
.hwtrap
= 0;
2871 static void qeth_l3_remove_device(struct ccwgroup_device
*cgdev
)
2873 struct qeth_card
*card
= dev_get_drvdata(&cgdev
->dev
);
2875 if (cgdev
->dev
.type
== &qeth_generic_devtype
)
2876 qeth_l3_remove_device_attributes(&cgdev
->dev
);
2878 qeth_set_allowed_threads(card
, 0, 1);
2879 wait_event(card
->wait_q
, qeth_threads_running(card
, 0xffffffff) == 0);
2881 if (cgdev
->state
== CCWGROUP_ONLINE
)
2882 qeth_l3_set_offline(cgdev
);
2885 netif_napi_del(&card
->napi
);
2886 unregister_netdev(card
->dev
);
2890 qeth_l3_clear_ip_htable(card
, 0);
2891 qeth_l3_clear_ipato_list(card
);
2895 static int __qeth_l3_set_online(struct ccwgroup_device
*gdev
, int recovery_mode
)
2897 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
2899 enum qeth_card_states recover_flag
;
2901 mutex_lock(&card
->discipline_mutex
);
2902 mutex_lock(&card
->conf_mutex
);
2903 QETH_DBF_TEXT(SETUP
, 2, "setonlin");
2904 QETH_DBF_HEX(SETUP
, 2, &card
, sizeof(void *));
2906 recover_flag
= card
->state
;
2907 rc
= qeth_core_hardsetup_card(card
);
2909 QETH_DBF_TEXT_(SETUP
, 2, "2err%04x", rc
);
2914 if (!card
->dev
&& qeth_l3_setup_netdev(card
)) {
2919 if (qeth_is_diagass_supported(card
, QETH_DIAGS_CMD_TRAP
)) {
2920 if (card
->info
.hwtrap
&&
2921 qeth_hw_trap(card
, QETH_DIAGS_TRAP_ARM
))
2922 card
->info
.hwtrap
= 0;
2924 card
->info
.hwtrap
= 0;
2926 card
->state
= CARD_STATE_HARDSETUP
;
2927 memset(&card
->rx
, 0, sizeof(struct qeth_rx
));
2928 qeth_print_status_message(card
);
2931 QETH_DBF_TEXT(SETUP
, 2, "softsetp");
2933 rc
= qeth_l3_setadapter_parms(card
);
2935 QETH_DBF_TEXT_(SETUP
, 2, "2err%04x", rc
);
2936 if (!card
->options
.sniffer
) {
2937 rc
= qeth_l3_start_ipassists(card
);
2939 QETH_DBF_TEXT_(SETUP
, 2, "3err%d", rc
);
2942 rc
= qeth_l3_setrouting_v4(card
);
2944 QETH_DBF_TEXT_(SETUP
, 2, "4err%04x", rc
);
2945 rc
= qeth_l3_setrouting_v6(card
);
2947 QETH_DBF_TEXT_(SETUP
, 2, "5err%04x", rc
);
2949 netif_tx_disable(card
->dev
);
2951 rc
= qeth_init_qdio_queues(card
);
2953 QETH_DBF_TEXT_(SETUP
, 2, "6err%d", rc
);
2957 card
->state
= CARD_STATE_SOFTSETUP
;
2959 qeth_set_allowed_threads(card
, 0xffffffff, 0);
2960 qeth_l3_recover_ip(card
);
2961 if (card
->lan_online
)
2962 netif_carrier_on(card
->dev
);
2964 netif_carrier_off(card
->dev
);
2965 if (recover_flag
== CARD_STATE_RECOVER
) {
2968 __qeth_l3_open(card
->dev
);
2970 dev_open(card
->dev
);
2971 qeth_l3_set_rx_mode(card
->dev
);
2972 qeth_recover_features(card
->dev
);
2975 qeth_trace_features(card
);
2976 /* let user_space know that device is online */
2977 kobject_uevent(&gdev
->dev
.kobj
, KOBJ_CHANGE
);
2978 mutex_unlock(&card
->conf_mutex
);
2979 mutex_unlock(&card
->discipline_mutex
);
2982 qeth_l3_stop_card(card
, 0);
2983 ccw_device_set_offline(CARD_DDEV(card
));
2984 ccw_device_set_offline(CARD_WDEV(card
));
2985 ccw_device_set_offline(CARD_RDEV(card
));
2986 qdio_free(CARD_DDEV(card
));
2987 if (recover_flag
== CARD_STATE_RECOVER
)
2988 card
->state
= CARD_STATE_RECOVER
;
2990 card
->state
= CARD_STATE_DOWN
;
2991 mutex_unlock(&card
->conf_mutex
);
2992 mutex_unlock(&card
->discipline_mutex
);
2996 static int qeth_l3_set_online(struct ccwgroup_device
*gdev
)
2998 return __qeth_l3_set_online(gdev
, 0);
3001 static int __qeth_l3_set_offline(struct ccwgroup_device
*cgdev
,
3004 struct qeth_card
*card
= dev_get_drvdata(&cgdev
->dev
);
3005 int rc
= 0, rc2
= 0, rc3
= 0;
3006 enum qeth_card_states recover_flag
;
3008 mutex_lock(&card
->discipline_mutex
);
3009 mutex_lock(&card
->conf_mutex
);
3010 QETH_DBF_TEXT(SETUP
, 3, "setoffl");
3011 QETH_DBF_HEX(SETUP
, 3, &card
, sizeof(void *));
3013 if (card
->dev
&& netif_carrier_ok(card
->dev
))
3014 netif_carrier_off(card
->dev
);
3015 recover_flag
= card
->state
;
3016 if ((!recovery_mode
&& card
->info
.hwtrap
) || card
->info
.hwtrap
== 2) {
3017 qeth_hw_trap(card
, QETH_DIAGS_TRAP_DISARM
);
3018 card
->info
.hwtrap
= 1;
3020 qeth_l3_stop_card(card
, recovery_mode
);
3021 if ((card
->options
.cq
== QETH_CQ_ENABLED
) && card
->dev
) {
3023 call_netdevice_notifiers(NETDEV_REBOOT
, card
->dev
);
3026 rc
= ccw_device_set_offline(CARD_DDEV(card
));
3027 rc2
= ccw_device_set_offline(CARD_WDEV(card
));
3028 rc3
= ccw_device_set_offline(CARD_RDEV(card
));
3030 rc
= (rc2
) ? rc2
: rc3
;
3032 QETH_DBF_TEXT_(SETUP
, 2, "1err%d", rc
);
3033 qdio_free(CARD_DDEV(card
));
3034 if (recover_flag
== CARD_STATE_UP
)
3035 card
->state
= CARD_STATE_RECOVER
;
3036 /* let user_space know that device is offline */
3037 kobject_uevent(&cgdev
->dev
.kobj
, KOBJ_CHANGE
);
3038 mutex_unlock(&card
->conf_mutex
);
3039 mutex_unlock(&card
->discipline_mutex
);
3043 static int qeth_l3_set_offline(struct ccwgroup_device
*cgdev
)
3045 return __qeth_l3_set_offline(cgdev
, 0);
3048 static int qeth_l3_recover(void *ptr
)
3050 struct qeth_card
*card
;
3053 card
= (struct qeth_card
*) ptr
;
3054 QETH_CARD_TEXT(card
, 2, "recover1");
3055 QETH_CARD_HEX(card
, 2, &card
, sizeof(void *));
3056 if (!qeth_do_run_thread(card
, QETH_RECOVER_THREAD
))
3058 QETH_CARD_TEXT(card
, 2, "recover2");
3059 dev_warn(&card
->gdev
->dev
,
3060 "A recovery process has been started for the device\n");
3061 qeth_set_recovery_task(card
);
3062 __qeth_l3_set_offline(card
->gdev
, 1);
3063 rc
= __qeth_l3_set_online(card
->gdev
, 1);
3065 dev_info(&card
->gdev
->dev
,
3066 "Device successfully recovered!\n");
3068 qeth_close_dev(card
);
3069 dev_warn(&card
->gdev
->dev
, "The qeth device driver "
3070 "failed to recover an error on the device\n");
3072 qeth_clear_recovery_task(card
);
3073 qeth_clear_thread_start_bit(card
, QETH_RECOVER_THREAD
);
3074 qeth_clear_thread_running_bit(card
, QETH_RECOVER_THREAD
);
3078 static int qeth_l3_pm_suspend(struct ccwgroup_device
*gdev
)
3080 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
3083 netif_device_detach(card
->dev
);
3084 qeth_set_allowed_threads(card
, 0, 1);
3085 wait_event(card
->wait_q
, qeth_threads_running(card
, 0xffffffff) == 0);
3086 if (gdev
->state
== CCWGROUP_OFFLINE
)
3088 if (card
->state
== CARD_STATE_UP
) {
3089 if (card
->info
.hwtrap
)
3090 qeth_hw_trap(card
, QETH_DIAGS_TRAP_DISARM
);
3091 __qeth_l3_set_offline(card
->gdev
, 1);
3093 __qeth_l3_set_offline(card
->gdev
, 0);
3097 static int qeth_l3_pm_resume(struct ccwgroup_device
*gdev
)
3099 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
3102 if (gdev
->state
== CCWGROUP_OFFLINE
)
3105 if (card
->state
== CARD_STATE_RECOVER
) {
3106 rc
= __qeth_l3_set_online(card
->gdev
, 1);
3109 dev_close(card
->dev
);
3113 rc
= __qeth_l3_set_online(card
->gdev
, 0);
3115 qeth_set_allowed_threads(card
, 0xffffffff, 0);
3117 netif_device_attach(card
->dev
);
3119 dev_warn(&card
->gdev
->dev
, "The qeth device driver "
3120 "failed to recover an error on the device\n");
3124 /* Returns zero if the command is successfully "consumed" */
3125 static int qeth_l3_control_event(struct qeth_card
*card
,
3126 struct qeth_ipa_cmd
*cmd
)
3131 struct qeth_discipline qeth_l3_discipline
= {
3132 .devtype
= &qeth_l3_devtype
,
3133 .start_poll
= qeth_qdio_start_poll
,
3134 .input_handler
= (qdio_handler_t
*) qeth_qdio_input_handler
,
3135 .output_handler
= (qdio_handler_t
*) qeth_qdio_output_handler
,
3136 .process_rx_buffer
= qeth_l3_process_inbound_buffer
,
3137 .recover
= qeth_l3_recover
,
3138 .setup
= qeth_l3_probe_device
,
3139 .remove
= qeth_l3_remove_device
,
3140 .set_online
= qeth_l3_set_online
,
3141 .set_offline
= qeth_l3_set_offline
,
3142 .freeze
= qeth_l3_pm_suspend
,
3143 .thaw
= qeth_l3_pm_resume
,
3144 .restore
= qeth_l3_pm_resume
,
3145 .do_ioctl
= qeth_l3_do_ioctl
,
3146 .control_event_handler
= qeth_l3_control_event
,
3148 EXPORT_SYMBOL_GPL(qeth_l3_discipline
);
3150 static int qeth_l3_ip_event(struct notifier_block
*this,
3151 unsigned long event
, void *ptr
)
3154 struct in_ifaddr
*ifa
= (struct in_ifaddr
*)ptr
;
3155 struct net_device
*dev
= (struct net_device
*)ifa
->ifa_dev
->dev
;
3156 struct qeth_ipaddr
*addr
;
3157 struct qeth_card
*card
;
3159 if (dev_net(dev
) != &init_net
)
3162 card
= qeth_l3_get_card_from_dev(dev
);
3165 QETH_CARD_TEXT(card
, 3, "ipevent");
3167 addr
= qeth_l3_get_addr_buffer(QETH_PROT_IPV4
);
3169 addr
->u
.a4
.addr
= be32_to_cpu(ifa
->ifa_address
);
3170 addr
->u
.a4
.mask
= be32_to_cpu(ifa
->ifa_mask
);
3171 addr
->type
= QETH_IP_TYPE_NORMAL
;
3177 spin_lock_bh(&card
->ip_lock
);
3178 qeth_l3_add_ip(card
, addr
);
3179 spin_unlock_bh(&card
->ip_lock
);
3182 spin_lock_bh(&card
->ip_lock
);
3183 qeth_l3_delete_ip(card
, addr
);
3184 spin_unlock_bh(&card
->ip_lock
);
3192 static struct notifier_block qeth_l3_ip_notifier
= {
3197 static int qeth_l3_ip6_event(struct notifier_block
*this,
3198 unsigned long event
, void *ptr
)
3200 struct inet6_ifaddr
*ifa
= (struct inet6_ifaddr
*)ptr
;
3201 struct net_device
*dev
= (struct net_device
*)ifa
->idev
->dev
;
3202 struct qeth_ipaddr
*addr
;
3203 struct qeth_card
*card
;
3205 card
= qeth_l3_get_card_from_dev(dev
);
3208 QETH_CARD_TEXT(card
, 3, "ip6event");
3209 if (!qeth_is_supported(card
, IPA_IPV6
))
3212 addr
= qeth_l3_get_addr_buffer(QETH_PROT_IPV6
);
3214 memcpy(&addr
->u
.a6
.addr
, &ifa
->addr
, sizeof(struct in6_addr
));
3215 addr
->u
.a6
.pfxlen
= ifa
->prefix_len
;
3216 addr
->type
= QETH_IP_TYPE_NORMAL
;
3222 spin_lock_bh(&card
->ip_lock
);
3223 qeth_l3_add_ip(card
, addr
);
3224 spin_unlock_bh(&card
->ip_lock
);
3227 spin_lock_bh(&card
->ip_lock
);
3228 qeth_l3_delete_ip(card
, addr
);
3229 spin_unlock_bh(&card
->ip_lock
);
3237 static struct notifier_block qeth_l3_ip6_notifier
= {
3242 static int qeth_l3_register_notifiers(void)
3246 QETH_DBF_TEXT(SETUP
, 5, "regnotif");
3247 rc
= register_inetaddr_notifier(&qeth_l3_ip_notifier
);
3250 rc
= register_inet6addr_notifier(&qeth_l3_ip6_notifier
);
3252 unregister_inetaddr_notifier(&qeth_l3_ip_notifier
);
3258 static void qeth_l3_unregister_notifiers(void)
3260 QETH_DBF_TEXT(SETUP
, 5, "unregnot");
3261 WARN_ON(unregister_inetaddr_notifier(&qeth_l3_ip_notifier
));
3262 WARN_ON(unregister_inet6addr_notifier(&qeth_l3_ip6_notifier
));
3265 static int __init
qeth_l3_init(void)
3267 pr_info("register layer 3 discipline\n");
3268 return qeth_l3_register_notifiers();
3271 static void __exit
qeth_l3_exit(void)
3273 qeth_l3_unregister_notifiers();
3274 pr_info("unregister layer 3 discipline\n");
3277 module_init(qeth_l3_init
);
3278 module_exit(qeth_l3_exit
);
3279 MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
3280 MODULE_DESCRIPTION("qeth layer 3 discipline");
3281 MODULE_LICENSE("GPL");