2 * Copyright IBM Corp. 2007, 2009
3 * Author(s): Utz Bacher <utz.bacher@de.ibm.com>,
4 * Frank Pavlic <fpavlic@de.ibm.com>,
5 * Thomas Spatzier <tspat@de.ibm.com>,
6 * Frank Blaschka <frank.blaschka@de.ibm.com>
9 #define KMSG_COMPONENT "qeth"
10 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
12 #include <linux/module.h>
13 #include <linux/moduleparam.h>
14 #include <linux/bitops.h>
15 #include <linux/string.h>
16 #include <linux/errno.h>
17 #include <linux/kernel.h>
18 #include <linux/etherdevice.h>
19 #include <linux/mii.h>
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_recover(void *);
40 static int qeth_l3_stop(struct net_device
*);
41 static void qeth_l3_set_multicast_list(struct net_device
*);
42 static int qeth_l3_neigh_setup(struct net_device
*, struct neigh_parms
*);
43 static int qeth_l3_register_addr_entry(struct qeth_card
*,
44 struct qeth_ipaddr
*);
45 static int qeth_l3_deregister_addr_entry(struct qeth_card
*,
46 struct qeth_ipaddr
*);
47 static int __qeth_l3_set_online(struct ccwgroup_device
*, int);
48 static int __qeth_l3_set_offline(struct ccwgroup_device
*, int);
50 static int qeth_l3_isxdigit(char *buf
)
53 if (!isxdigit(*buf
++))
59 static void qeth_l3_ipaddr4_to_string(const __u8
*addr
, char *buf
)
61 sprintf(buf
, "%pI4", addr
);
64 static int qeth_l3_string_to_ipaddr4(const char *buf
, __u8
*addr
)
66 int count
= 0, rc
= 0;
70 rc
= sscanf(buf
, "%u.%u.%u.%u%c",
71 &in
[0], &in
[1], &in
[2], &in
[3], &c
);
72 if (rc
!= 4 && (rc
!= 5 || c
!= '\n'))
74 for (count
= 0; count
< 4; count
++) {
77 addr
[count
] = in
[count
];
82 static void qeth_l3_ipaddr6_to_string(const __u8
*addr
, char *buf
)
84 sprintf(buf
, "%pI6", addr
);
87 static int qeth_l3_string_to_ipaddr6(const char *buf
, __u8
*addr
)
89 const char *end
, *end_tmp
, *start
;
92 int num2
, cnt
, out
, found
, save_cnt
;
93 unsigned short in_tmp
[8] = {0, };
95 cnt
= out
= found
= save_cnt
= num2
= 0;
100 end
= strchr(start
, ':');
102 end
= buf
+ strlen(buf
);
103 end_tmp
= strchr(start
, '\n');
110 if ((end
- start
) > 4)
112 memcpy(num
, start
, end
- start
);
113 if (!qeth_l3_isxdigit(num
))
115 sscanf(start
, "%x", &num2
);
117 in_tmp
[save_cnt
++] = num2
;
129 if (cnt
+ save_cnt
> 8)
133 in
[cnt
--] = in_tmp
[--save_cnt
];
137 void qeth_l3_ipaddr_to_string(enum qeth_prot_versions proto
, const __u8
*addr
,
140 if (proto
== QETH_PROT_IPV4
)
141 qeth_l3_ipaddr4_to_string(addr
, buf
);
142 else if (proto
== QETH_PROT_IPV6
)
143 qeth_l3_ipaddr6_to_string(addr
, buf
);
146 int qeth_l3_string_to_ipaddr(const char *buf
, enum qeth_prot_versions proto
,
149 if (proto
== QETH_PROT_IPV4
)
150 return qeth_l3_string_to_ipaddr4(buf
, addr
);
151 else if (proto
== QETH_PROT_IPV6
)
152 return qeth_l3_string_to_ipaddr6(buf
, addr
);
157 static void qeth_l3_convert_addr_to_bits(u8
*addr
, u8
*bits
, int len
)
162 for (i
= 0; i
< len
; ++i
) {
164 for (j
= 7; j
>= 0; --j
) {
165 bits
[i
*8 + j
] = octet
& 1;
171 int qeth_l3_is_addr_covered_by_ipato(struct qeth_card
*card
,
172 struct qeth_ipaddr
*addr
)
174 struct qeth_ipato_entry
*ipatoe
;
175 u8 addr_bits
[128] = {0, };
176 u8 ipatoe_bits
[128] = {0, };
179 if (!card
->ipato
.enabled
)
182 qeth_l3_convert_addr_to_bits((u8
*) &addr
->u
, addr_bits
,
183 (addr
->proto
== QETH_PROT_IPV4
)? 4:16);
184 list_for_each_entry(ipatoe
, &card
->ipato
.entries
, entry
) {
185 if (addr
->proto
!= ipatoe
->proto
)
187 qeth_l3_convert_addr_to_bits(ipatoe
->addr
, ipatoe_bits
,
188 (ipatoe
->proto
== QETH_PROT_IPV4
) ?
190 if (addr
->proto
== QETH_PROT_IPV4
)
191 rc
= !memcmp(addr_bits
, ipatoe_bits
,
192 min(32, ipatoe
->mask_bits
));
194 rc
= !memcmp(addr_bits
, ipatoe_bits
,
195 min(128, ipatoe
->mask_bits
));
200 if ((addr
->proto
== QETH_PROT_IPV4
) && card
->ipato
.invert4
)
202 else if ((addr
->proto
== QETH_PROT_IPV6
) && card
->ipato
.invert6
)
209 qeth_l3_ipaddrs_is_equal(struct qeth_ipaddr
*addr1
, struct qeth_ipaddr
*addr2
)
211 return addr1
->proto
== addr2
->proto
&&
212 !memcmp(&addr1
->u
, &addr2
->u
, sizeof(addr1
->u
)) &&
213 !memcmp(&addr1
->mac
, &addr2
->mac
, sizeof(addr1
->mac
));
216 static struct qeth_ipaddr
*
217 qeth_l3_ip_from_hash(struct qeth_card
*card
, struct qeth_ipaddr
*tmp_addr
)
219 struct qeth_ipaddr
*addr
;
221 if (tmp_addr
->is_multicast
) {
222 hash_for_each_possible(card
->ip_mc_htable
, addr
,
223 hnode
, qeth_l3_ipaddr_hash(tmp_addr
))
224 if (qeth_l3_ipaddrs_is_equal(tmp_addr
, addr
))
227 hash_for_each_possible(card
->ip_htable
, addr
,
228 hnode
, qeth_l3_ipaddr_hash(tmp_addr
))
229 if (qeth_l3_ipaddrs_is_equal(tmp_addr
, addr
))
236 int qeth_l3_delete_ip(struct qeth_card
*card
, struct qeth_ipaddr
*tmp_addr
)
239 struct qeth_ipaddr
*addr
;
241 QETH_CARD_TEXT(card
, 4, "delip");
243 if (tmp_addr
->proto
== QETH_PROT_IPV4
)
244 QETH_CARD_HEX(card
, 4, &tmp_addr
->u
.a4
.addr
, 4);
246 QETH_CARD_HEX(card
, 4, &tmp_addr
->u
.a6
.addr
, 8);
247 QETH_CARD_HEX(card
, 4, ((char *)&tmp_addr
->u
.a6
.addr
) + 8, 8);
250 addr
= qeth_l3_ip_from_hash(card
, tmp_addr
);
255 if (addr
->type
== QETH_IP_TYPE_NORMAL
&& addr
->ref_counter
> 0)
257 if (addr
->in_progress
)
260 if (!qeth_card_hw_is_reachable(card
)) {
261 addr
->disp_flag
= QETH_DISP_ADDR_DELETE
;
265 rc
= qeth_l3_deregister_addr_entry(card
, addr
);
267 hash_del(&addr
->hnode
);
273 int qeth_l3_add_ip(struct qeth_card
*card
, struct qeth_ipaddr
*tmp_addr
)
276 struct qeth_ipaddr
*addr
;
278 QETH_CARD_TEXT(card
, 4, "addip");
280 if (tmp_addr
->proto
== QETH_PROT_IPV4
)
281 QETH_CARD_HEX(card
, 4, &tmp_addr
->u
.a4
.addr
, 4);
283 QETH_CARD_HEX(card
, 4, &tmp_addr
->u
.a6
.addr
, 8);
284 QETH_CARD_HEX(card
, 4, ((char *)&tmp_addr
->u
.a6
.addr
) + 8, 8);
287 addr
= qeth_l3_ip_from_hash(card
, tmp_addr
);
289 addr
= qeth_l3_get_addr_buffer(tmp_addr
->proto
);
293 memcpy(addr
, tmp_addr
, sizeof(struct qeth_ipaddr
));
294 addr
->ref_counter
= 1;
296 if (addr
->type
== QETH_IP_TYPE_NORMAL
&&
297 qeth_l3_is_addr_covered_by_ipato(card
, addr
)) {
298 QETH_CARD_TEXT(card
, 2, "tkovaddr");
299 addr
->set_flags
|= QETH_IPA_SETIP_TAKEOVER_FLAG
;
301 hash_add(card
->ip_htable
, &addr
->hnode
,
302 qeth_l3_ipaddr_hash(addr
));
304 if (!qeth_card_hw_is_reachable(card
)) {
305 addr
->disp_flag
= QETH_DISP_ADDR_ADD
;
309 /* qeth_l3_register_addr_entry can go to sleep
310 * if we add a IPV4 addr. It is caused by the reason
311 * that SETIP ipa cmd starts ARP staff for IPV4 addr.
312 * Thus we should unlock spinlock, and make a protection
313 * using in_progress variable to indicate that there is
314 * an hardware operation with this IPV4 address
316 if (addr
->proto
== QETH_PROT_IPV4
) {
317 addr
->in_progress
= 1;
318 spin_unlock_bh(&card
->ip_lock
);
319 rc
= qeth_l3_register_addr_entry(card
, addr
);
320 spin_lock_bh(&card
->ip_lock
);
321 addr
->in_progress
= 0;
323 rc
= qeth_l3_register_addr_entry(card
, addr
);
325 if (!rc
|| (rc
== IPA_RC_DUPLICATE_IP_ADDRESS
) ||
326 (rc
== IPA_RC_LAN_OFFLINE
)) {
327 addr
->disp_flag
= QETH_DISP_ADDR_DO_NOTHING
;
328 if (addr
->ref_counter
< 1) {
329 qeth_l3_delete_ip(card
, addr
);
333 hash_del(&addr
->hnode
);
337 if (addr
->type
== QETH_IP_TYPE_NORMAL
)
345 struct qeth_ipaddr
*qeth_l3_get_addr_buffer(
346 enum qeth_prot_versions prot
)
348 struct qeth_ipaddr
*addr
;
350 addr
= kzalloc(sizeof(struct qeth_ipaddr
), GFP_ATOMIC
);
354 addr
->type
= QETH_IP_TYPE_NORMAL
;
355 addr
->disp_flag
= QETH_DISP_ADDR_DO_NOTHING
;
361 static void qeth_l3_clear_ip_htable(struct qeth_card
*card
, int recover
)
363 struct qeth_ipaddr
*addr
;
364 struct hlist_node
*tmp
;
367 QETH_CARD_TEXT(card
, 4, "clearip");
369 if (recover
&& card
->options
.sniffer
)
372 spin_lock_bh(&card
->ip_lock
);
374 hash_for_each_safe(card
->ip_htable
, i
, tmp
, addr
, hnode
) {
376 hash_del(&addr
->hnode
);
380 addr
->disp_flag
= QETH_DISP_ADDR_ADD
;
383 spin_unlock_bh(&card
->ip_lock
);
385 spin_lock_bh(&card
->mclock
);
387 hash_for_each_safe(card
->ip_mc_htable
, i
, tmp
, addr
, hnode
) {
388 hash_del(&addr
->hnode
);
392 spin_unlock_bh(&card
->mclock
);
396 static void qeth_l3_recover_ip(struct qeth_card
*card
)
398 struct qeth_ipaddr
*addr
;
399 struct hlist_node
*tmp
;
403 QETH_CARD_TEXT(card
, 4, "recovrip");
405 spin_lock_bh(&card
->ip_lock
);
407 hash_for_each_safe(card
->ip_htable
, i
, tmp
, addr
, hnode
) {
408 if (addr
->disp_flag
== QETH_DISP_ADDR_DELETE
) {
409 qeth_l3_deregister_addr_entry(card
, addr
);
410 hash_del(&addr
->hnode
);
412 } else if (addr
->disp_flag
== QETH_DISP_ADDR_ADD
) {
413 if (addr
->proto
== QETH_PROT_IPV4
) {
414 addr
->in_progress
= 1;
415 spin_unlock_bh(&card
->ip_lock
);
416 rc
= qeth_l3_register_addr_entry(card
, addr
);
417 spin_lock_bh(&card
->ip_lock
);
418 addr
->in_progress
= 0;
420 rc
= qeth_l3_register_addr_entry(card
, addr
);
423 addr
->disp_flag
= QETH_DISP_ADDR_DO_NOTHING
;
424 if (addr
->ref_counter
< 1)
425 qeth_l3_delete_ip(card
, addr
);
427 hash_del(&addr
->hnode
);
433 spin_unlock_bh(&card
->ip_lock
);
437 static int qeth_l3_send_setdelmc(struct qeth_card
*card
,
438 struct qeth_ipaddr
*addr
, int ipacmd
)
441 struct qeth_cmd_buffer
*iob
;
442 struct qeth_ipa_cmd
*cmd
;
444 QETH_CARD_TEXT(card
, 4, "setdelmc");
446 iob
= qeth_get_ipacmd_buffer(card
, ipacmd
, addr
->proto
);
449 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
450 memcpy(&cmd
->data
.setdelipm
.mac
, addr
->mac
, OSA_ADDR_LEN
);
451 if (addr
->proto
== QETH_PROT_IPV6
)
452 memcpy(cmd
->data
.setdelipm
.ip6
, &addr
->u
.a6
.addr
,
453 sizeof(struct in6_addr
));
455 memcpy(&cmd
->data
.setdelipm
.ip4
, &addr
->u
.a4
.addr
, 4);
457 rc
= qeth_send_ipa_cmd(card
, iob
, NULL
, NULL
);
462 static void qeth_l3_fill_netmask(u8
*netmask
, unsigned int len
)
465 for (i
= 0; i
< 16; i
++) {
470 netmask
[i
] = (u8
)(0xFF00 >> j
);
476 static int qeth_l3_send_setdelip(struct qeth_card
*card
,
477 struct qeth_ipaddr
*addr
, int ipacmd
, unsigned int flags
)
480 struct qeth_cmd_buffer
*iob
;
481 struct qeth_ipa_cmd
*cmd
;
484 QETH_CARD_TEXT(card
, 4, "setdelip");
485 QETH_CARD_TEXT_(card
, 4, "flags%02X", flags
);
487 iob
= qeth_get_ipacmd_buffer(card
, ipacmd
, addr
->proto
);
490 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
491 if (addr
->proto
== QETH_PROT_IPV6
) {
492 memcpy(cmd
->data
.setdelip6
.ip_addr
, &addr
->u
.a6
.addr
,
493 sizeof(struct in6_addr
));
494 qeth_l3_fill_netmask(netmask
, addr
->u
.a6
.pfxlen
);
495 memcpy(cmd
->data
.setdelip6
.mask
, netmask
,
496 sizeof(struct in6_addr
));
497 cmd
->data
.setdelip6
.flags
= flags
;
499 memcpy(cmd
->data
.setdelip4
.ip_addr
, &addr
->u
.a4
.addr
, 4);
500 memcpy(cmd
->data
.setdelip4
.mask
, &addr
->u
.a4
.mask
, 4);
501 cmd
->data
.setdelip4
.flags
= flags
;
504 rc
= qeth_send_ipa_cmd(card
, iob
, NULL
, NULL
);
509 static int qeth_l3_send_setrouting(struct qeth_card
*card
,
510 enum qeth_routing_types type
, enum qeth_prot_versions prot
)
513 struct qeth_ipa_cmd
*cmd
;
514 struct qeth_cmd_buffer
*iob
;
516 QETH_CARD_TEXT(card
, 4, "setroutg");
517 iob
= qeth_get_ipacmd_buffer(card
, IPA_CMD_SETRTG
, prot
);
520 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
521 cmd
->data
.setrtg
.type
= (type
);
522 rc
= qeth_send_ipa_cmd(card
, iob
, NULL
, NULL
);
527 static int qeth_l3_correct_routing_type(struct qeth_card
*card
,
528 enum qeth_routing_types
*type
, enum qeth_prot_versions prot
)
530 if (card
->info
.type
== QETH_CARD_TYPE_IQD
) {
533 case PRIMARY_CONNECTOR
:
534 case SECONDARY_CONNECTOR
:
535 case MULTICAST_ROUTER
:
544 case SECONDARY_ROUTER
:
546 case MULTICAST_ROUTER
:
547 if (qeth_is_ipafunc_supported(card
, prot
,
559 int qeth_l3_setrouting_v4(struct qeth_card
*card
)
563 QETH_CARD_TEXT(card
, 3, "setrtg4");
565 rc
= qeth_l3_correct_routing_type(card
, &card
->options
.route4
.type
,
570 rc
= qeth_l3_send_setrouting(card
, card
->options
.route4
.type
,
573 card
->options
.route4
.type
= NO_ROUTER
;
574 QETH_DBF_MESSAGE(2, "Error (0x%04x) while setting routing type"
575 " on %s. Type set to 'no router'.\n", rc
,
576 QETH_CARD_IFNAME(card
));
581 int qeth_l3_setrouting_v6(struct qeth_card
*card
)
585 QETH_CARD_TEXT(card
, 3, "setrtg6");
586 #ifdef CONFIG_QETH_IPV6
588 if (!qeth_is_supported(card
, IPA_IPV6
))
590 rc
= qeth_l3_correct_routing_type(card
, &card
->options
.route6
.type
,
595 rc
= qeth_l3_send_setrouting(card
, card
->options
.route6
.type
,
598 card
->options
.route6
.type
= NO_ROUTER
;
599 QETH_DBF_MESSAGE(2, "Error (0x%04x) while setting routing type"
600 " on %s. Type set to 'no router'.\n", rc
,
601 QETH_CARD_IFNAME(card
));
608 * IP address takeover related functions
610 static void qeth_l3_clear_ipato_list(struct qeth_card
*card
)
612 struct qeth_ipato_entry
*ipatoe
, *tmp
;
614 spin_lock_bh(&card
->ip_lock
);
616 list_for_each_entry_safe(ipatoe
, tmp
, &card
->ipato
.entries
, entry
) {
617 list_del(&ipatoe
->entry
);
621 spin_unlock_bh(&card
->ip_lock
);
624 int qeth_l3_add_ipato_entry(struct qeth_card
*card
,
625 struct qeth_ipato_entry
*new)
627 struct qeth_ipato_entry
*ipatoe
;
630 QETH_CARD_TEXT(card
, 2, "addipato");
632 spin_lock_bh(&card
->ip_lock
);
634 list_for_each_entry(ipatoe
, &card
->ipato
.entries
, entry
) {
635 if (ipatoe
->proto
!= new->proto
)
637 if (!memcmp(ipatoe
->addr
, new->addr
,
638 (ipatoe
->proto
== QETH_PROT_IPV4
)? 4:16) &&
639 (ipatoe
->mask_bits
== new->mask_bits
)) {
646 list_add_tail(&new->entry
, &card
->ipato
.entries
);
648 spin_unlock_bh(&card
->ip_lock
);
653 void qeth_l3_del_ipato_entry(struct qeth_card
*card
,
654 enum qeth_prot_versions proto
, u8
*addr
, int mask_bits
)
656 struct qeth_ipato_entry
*ipatoe
, *tmp
;
658 QETH_CARD_TEXT(card
, 2, "delipato");
660 spin_lock_bh(&card
->ip_lock
);
662 list_for_each_entry_safe(ipatoe
, tmp
, &card
->ipato
.entries
, entry
) {
663 if (ipatoe
->proto
!= proto
)
665 if (!memcmp(ipatoe
->addr
, addr
,
666 (proto
== QETH_PROT_IPV4
)? 4:16) &&
667 (ipatoe
->mask_bits
== mask_bits
)) {
668 list_del(&ipatoe
->entry
);
673 spin_unlock_bh(&card
->ip_lock
);
677 * VIPA related functions
679 int qeth_l3_add_vipa(struct qeth_card
*card
, enum qeth_prot_versions proto
,
682 struct qeth_ipaddr
*ipaddr
;
685 ipaddr
= qeth_l3_get_addr_buffer(proto
);
687 if (proto
== QETH_PROT_IPV4
) {
688 QETH_CARD_TEXT(card
, 2, "addvipa4");
689 memcpy(&ipaddr
->u
.a4
.addr
, addr
, 4);
690 ipaddr
->u
.a4
.mask
= 0;
691 } else if (proto
== QETH_PROT_IPV6
) {
692 QETH_CARD_TEXT(card
, 2, "addvipa6");
693 memcpy(&ipaddr
->u
.a6
.addr
, addr
, 16);
694 ipaddr
->u
.a6
.pfxlen
= 0;
696 ipaddr
->type
= QETH_IP_TYPE_VIPA
;
697 ipaddr
->set_flags
= QETH_IPA_SETIP_VIPA_FLAG
;
698 ipaddr
->del_flags
= QETH_IPA_DELIP_VIPA_FLAG
;
702 spin_lock_bh(&card
->ip_lock
);
704 if (qeth_l3_ip_from_hash(card
, ipaddr
))
707 qeth_l3_add_ip(card
, ipaddr
);
709 spin_unlock_bh(&card
->ip_lock
);
716 void qeth_l3_del_vipa(struct qeth_card
*card
, enum qeth_prot_versions proto
,
719 struct qeth_ipaddr
*ipaddr
;
721 ipaddr
= qeth_l3_get_addr_buffer(proto
);
723 if (proto
== QETH_PROT_IPV4
) {
724 QETH_CARD_TEXT(card
, 2, "delvipa4");
725 memcpy(&ipaddr
->u
.a4
.addr
, addr
, 4);
726 ipaddr
->u
.a4
.mask
= 0;
727 } else if (proto
== QETH_PROT_IPV6
) {
728 QETH_CARD_TEXT(card
, 2, "delvipa6");
729 memcpy(&ipaddr
->u
.a6
.addr
, addr
, 16);
730 ipaddr
->u
.a6
.pfxlen
= 0;
732 ipaddr
->type
= QETH_IP_TYPE_VIPA
;
736 spin_lock_bh(&card
->ip_lock
);
737 qeth_l3_delete_ip(card
, ipaddr
);
738 spin_unlock_bh(&card
->ip_lock
);
744 * proxy ARP related functions
746 int qeth_l3_add_rxip(struct qeth_card
*card
, enum qeth_prot_versions proto
,
749 struct qeth_ipaddr
*ipaddr
;
752 ipaddr
= qeth_l3_get_addr_buffer(proto
);
754 if (proto
== QETH_PROT_IPV4
) {
755 QETH_CARD_TEXT(card
, 2, "addrxip4");
756 memcpy(&ipaddr
->u
.a4
.addr
, addr
, 4);
757 ipaddr
->u
.a4
.mask
= 0;
758 } else if (proto
== QETH_PROT_IPV6
) {
759 QETH_CARD_TEXT(card
, 2, "addrxip6");
760 memcpy(&ipaddr
->u
.a6
.addr
, addr
, 16);
761 ipaddr
->u
.a6
.pfxlen
= 0;
764 ipaddr
->type
= QETH_IP_TYPE_RXIP
;
765 ipaddr
->set_flags
= QETH_IPA_SETIP_TAKEOVER_FLAG
;
766 ipaddr
->del_flags
= 0;
770 spin_lock_bh(&card
->ip_lock
);
772 if (qeth_l3_ip_from_hash(card
, ipaddr
))
775 qeth_l3_add_ip(card
, ipaddr
);
777 spin_unlock_bh(&card
->ip_lock
);
784 void qeth_l3_del_rxip(struct qeth_card
*card
, enum qeth_prot_versions proto
,
787 struct qeth_ipaddr
*ipaddr
;
789 ipaddr
= qeth_l3_get_addr_buffer(proto
);
791 if (proto
== QETH_PROT_IPV4
) {
792 QETH_CARD_TEXT(card
, 2, "addrxip4");
793 memcpy(&ipaddr
->u
.a4
.addr
, addr
, 4);
794 ipaddr
->u
.a4
.mask
= 0;
795 } else if (proto
== QETH_PROT_IPV6
) {
796 QETH_CARD_TEXT(card
, 2, "addrxip6");
797 memcpy(&ipaddr
->u
.a6
.addr
, addr
, 16);
798 ipaddr
->u
.a6
.pfxlen
= 0;
800 ipaddr
->type
= QETH_IP_TYPE_RXIP
;
804 spin_lock_bh(&card
->ip_lock
);
805 qeth_l3_delete_ip(card
, ipaddr
);
806 spin_unlock_bh(&card
->ip_lock
);
811 static int qeth_l3_register_addr_entry(struct qeth_card
*card
,
812 struct qeth_ipaddr
*addr
)
819 if (addr
->proto
== QETH_PROT_IPV4
) {
820 QETH_CARD_TEXT(card
, 2, "setaddr4");
821 QETH_CARD_HEX(card
, 3, &addr
->u
.a4
.addr
, sizeof(int));
822 } else if (addr
->proto
== QETH_PROT_IPV6
) {
823 QETH_CARD_TEXT(card
, 2, "setaddr6");
824 QETH_CARD_HEX(card
, 3, &addr
->u
.a6
.addr
, 8);
825 QETH_CARD_HEX(card
, 3, ((char *)&addr
->u
.a6
.addr
) + 8, 8);
827 QETH_CARD_TEXT(card
, 2, "setaddr?");
828 QETH_CARD_HEX(card
, 3, addr
, sizeof(struct qeth_ipaddr
));
831 if (addr
->is_multicast
)
832 rc
= qeth_l3_send_setdelmc(card
, addr
, IPA_CMD_SETIPM
);
834 rc
= qeth_l3_send_setdelip(card
, addr
, IPA_CMD_SETIP
,
837 QETH_CARD_TEXT(card
, 2, "failed");
838 } while ((--cnt
> 0) && rc
);
840 QETH_CARD_TEXT(card
, 2, "FAILED");
841 qeth_l3_ipaddr_to_string(addr
->proto
, (u8
*)&addr
->u
, buf
);
842 dev_warn(&card
->gdev
->dev
,
843 "Registering IP address %s failed\n", buf
);
848 static int qeth_l3_deregister_addr_entry(struct qeth_card
*card
,
849 struct qeth_ipaddr
*addr
)
853 if (addr
->proto
== QETH_PROT_IPV4
) {
854 QETH_CARD_TEXT(card
, 2, "deladdr4");
855 QETH_CARD_HEX(card
, 3, &addr
->u
.a4
.addr
, sizeof(int));
856 } else if (addr
->proto
== QETH_PROT_IPV6
) {
857 QETH_CARD_TEXT(card
, 2, "deladdr6");
858 QETH_CARD_HEX(card
, 3, &addr
->u
.a6
.addr
, 8);
859 QETH_CARD_HEX(card
, 3, ((char *)&addr
->u
.a6
.addr
) + 8, 8);
861 QETH_CARD_TEXT(card
, 2, "deladdr?");
862 QETH_CARD_HEX(card
, 3, addr
, sizeof(struct qeth_ipaddr
));
864 if (addr
->is_multicast
)
865 rc
= qeth_l3_send_setdelmc(card
, addr
, IPA_CMD_DELIPM
);
867 rc
= qeth_l3_send_setdelip(card
, addr
, IPA_CMD_DELIP
,
870 QETH_CARD_TEXT(card
, 2, "failed");
875 static inline u8
qeth_l3_get_qeth_hdr_flags4(int cast_type
)
877 if (cast_type
== RTN_MULTICAST
)
878 return QETH_CAST_MULTICAST
;
879 if (cast_type
== RTN_BROADCAST
)
880 return QETH_CAST_BROADCAST
;
881 return QETH_CAST_UNICAST
;
884 static inline u8
qeth_l3_get_qeth_hdr_flags6(int cast_type
)
886 u8 ct
= QETH_HDR_PASSTHRU
| QETH_HDR_IPV6
;
887 if (cast_type
== RTN_MULTICAST
)
888 return ct
| QETH_CAST_MULTICAST
;
889 if (cast_type
== RTN_ANYCAST
)
890 return ct
| QETH_CAST_ANYCAST
;
891 if (cast_type
== RTN_BROADCAST
)
892 return ct
| QETH_CAST_BROADCAST
;
893 return ct
| QETH_CAST_UNICAST
;
896 static int qeth_l3_setadapter_parms(struct qeth_card
*card
)
900 QETH_DBF_TEXT(SETUP
, 2, "setadprm");
902 if (!qeth_is_supported(card
, IPA_SETADAPTERPARMS
)) {
903 dev_info(&card
->gdev
->dev
,
904 "set adapter parameters not supported.\n");
905 QETH_DBF_TEXT(SETUP
, 2, " notsupp");
908 rc
= qeth_query_setadapterparms(card
);
910 QETH_DBF_MESSAGE(2, "%s couldn't set adapter parameters: "
911 "0x%x\n", dev_name(&card
->gdev
->dev
), rc
);
914 if (qeth_adp_supported(card
, IPA_SETADP_ALTER_MAC_ADDRESS
)) {
915 rc
= qeth_setadpparms_change_macaddr(card
);
917 dev_warn(&card
->gdev
->dev
, "Reading the adapter MAC"
918 " address failed\n");
924 #ifdef CONFIG_QETH_IPV6
925 static int qeth_l3_send_simple_setassparms_ipv6(struct qeth_card
*card
,
926 enum qeth_ipa_funcs ipa_func
, __u16 cmd_code
)
929 struct qeth_cmd_buffer
*iob
;
931 QETH_CARD_TEXT(card
, 4, "simassp6");
932 iob
= qeth_get_setassparms_cmd(card
, ipa_func
, cmd_code
,
936 rc
= qeth_send_setassparms(card
, iob
, 0, 0,
937 qeth_setassparms_cb
, NULL
);
942 static int qeth_l3_start_ipa_arp_processing(struct qeth_card
*card
)
946 QETH_CARD_TEXT(card
, 3, "ipaarp");
948 if (!qeth_is_supported(card
, IPA_ARP_PROCESSING
)) {
949 dev_info(&card
->gdev
->dev
,
950 "ARP processing not supported on %s!\n",
951 QETH_CARD_IFNAME(card
));
954 rc
= qeth_send_simple_setassparms(card
, IPA_ARP_PROCESSING
,
955 IPA_CMD_ASS_START
, 0);
957 dev_warn(&card
->gdev
->dev
,
958 "Starting ARP processing support for %s failed\n",
959 QETH_CARD_IFNAME(card
));
964 static int qeth_l3_start_ipa_ip_fragmentation(struct qeth_card
*card
)
968 QETH_CARD_TEXT(card
, 3, "ipaipfrg");
970 if (!qeth_is_supported(card
, IPA_IP_FRAGMENTATION
)) {
971 dev_info(&card
->gdev
->dev
,
972 "Hardware IP fragmentation not supported on %s\n",
973 QETH_CARD_IFNAME(card
));
977 rc
= qeth_send_simple_setassparms(card
, IPA_IP_FRAGMENTATION
,
978 IPA_CMD_ASS_START
, 0);
980 dev_warn(&card
->gdev
->dev
,
981 "Starting IP fragmentation support for %s failed\n",
982 QETH_CARD_IFNAME(card
));
984 dev_info(&card
->gdev
->dev
,
985 "Hardware IP fragmentation enabled \n");
989 static int qeth_l3_start_ipa_source_mac(struct qeth_card
*card
)
993 QETH_CARD_TEXT(card
, 3, "stsrcmac");
995 if (!qeth_is_supported(card
, IPA_SOURCE_MAC
)) {
996 dev_info(&card
->gdev
->dev
,
997 "Inbound source MAC-address not supported on %s\n",
998 QETH_CARD_IFNAME(card
));
1002 rc
= qeth_send_simple_setassparms(card
, IPA_SOURCE_MAC
,
1003 IPA_CMD_ASS_START
, 0);
1005 dev_warn(&card
->gdev
->dev
,
1006 "Starting source MAC-address support for %s failed\n",
1007 QETH_CARD_IFNAME(card
));
1011 static int qeth_l3_start_ipa_vlan(struct qeth_card
*card
)
1015 QETH_CARD_TEXT(card
, 3, "strtvlan");
1017 if (!qeth_is_supported(card
, IPA_FULL_VLAN
)) {
1018 dev_info(&card
->gdev
->dev
,
1019 "VLAN not supported on %s\n", QETH_CARD_IFNAME(card
));
1023 rc
= qeth_send_simple_setassparms(card
, IPA_VLAN_PRIO
,
1024 IPA_CMD_ASS_START
, 0);
1026 dev_warn(&card
->gdev
->dev
,
1027 "Starting VLAN support for %s failed\n",
1028 QETH_CARD_IFNAME(card
));
1030 dev_info(&card
->gdev
->dev
, "VLAN enabled\n");
1035 static int qeth_l3_start_ipa_multicast(struct qeth_card
*card
)
1039 QETH_CARD_TEXT(card
, 3, "stmcast");
1041 if (!qeth_is_supported(card
, IPA_MULTICASTING
)) {
1042 dev_info(&card
->gdev
->dev
,
1043 "Multicast not supported on %s\n",
1044 QETH_CARD_IFNAME(card
));
1048 rc
= qeth_send_simple_setassparms(card
, IPA_MULTICASTING
,
1049 IPA_CMD_ASS_START
, 0);
1051 dev_warn(&card
->gdev
->dev
,
1052 "Starting multicast support for %s failed\n",
1053 QETH_CARD_IFNAME(card
));
1055 dev_info(&card
->gdev
->dev
, "Multicast enabled\n");
1056 card
->dev
->flags
|= IFF_MULTICAST
;
1061 #ifdef CONFIG_QETH_IPV6
1062 static int qeth_l3_softsetup_ipv6(struct qeth_card
*card
)
1066 QETH_CARD_TEXT(card
, 3, "softipv6");
1068 if (card
->info
.type
== QETH_CARD_TYPE_IQD
)
1071 rc
= qeth_query_ipassists(card
, QETH_PROT_IPV6
);
1073 dev_err(&card
->gdev
->dev
,
1074 "Activating IPv6 support for %s failed\n",
1075 QETH_CARD_IFNAME(card
));
1078 rc
= qeth_send_simple_setassparms(card
, IPA_IPV6
,
1079 IPA_CMD_ASS_START
, 3);
1081 dev_err(&card
->gdev
->dev
,
1082 "Activating IPv6 support for %s failed\n",
1083 QETH_CARD_IFNAME(card
));
1086 rc
= qeth_l3_send_simple_setassparms_ipv6(card
, IPA_IPV6
,
1089 dev_err(&card
->gdev
->dev
,
1090 "Activating IPv6 support for %s failed\n",
1091 QETH_CARD_IFNAME(card
));
1094 rc
= qeth_l3_send_simple_setassparms_ipv6(card
, IPA_PASSTHRU
,
1097 dev_warn(&card
->gdev
->dev
,
1098 "Enabling the passthrough mode for %s failed\n",
1099 QETH_CARD_IFNAME(card
));
1103 dev_info(&card
->gdev
->dev
, "IPV6 enabled\n");
1108 static int qeth_l3_start_ipa_ipv6(struct qeth_card
*card
)
1112 QETH_CARD_TEXT(card
, 3, "strtipv6");
1114 if (!qeth_is_supported(card
, IPA_IPV6
)) {
1115 dev_info(&card
->gdev
->dev
,
1116 "IPv6 not supported on %s\n", QETH_CARD_IFNAME(card
));
1119 #ifdef CONFIG_QETH_IPV6
1120 rc
= qeth_l3_softsetup_ipv6(card
);
1125 static int qeth_l3_start_ipa_broadcast(struct qeth_card
*card
)
1129 QETH_CARD_TEXT(card
, 3, "stbrdcst");
1130 card
->info
.broadcast_capable
= 0;
1131 if (!qeth_is_supported(card
, IPA_FILTERING
)) {
1132 dev_info(&card
->gdev
->dev
,
1133 "Broadcast not supported on %s\n",
1134 QETH_CARD_IFNAME(card
));
1138 rc
= qeth_send_simple_setassparms(card
, IPA_FILTERING
,
1139 IPA_CMD_ASS_START
, 0);
1141 dev_warn(&card
->gdev
->dev
, "Enabling broadcast filtering for "
1142 "%s failed\n", QETH_CARD_IFNAME(card
));
1146 rc
= qeth_send_simple_setassparms(card
, IPA_FILTERING
,
1147 IPA_CMD_ASS_CONFIGURE
, 1);
1149 dev_warn(&card
->gdev
->dev
,
1150 "Setting up broadcast filtering for %s failed\n",
1151 QETH_CARD_IFNAME(card
));
1154 card
->info
.broadcast_capable
= QETH_BROADCAST_WITH_ECHO
;
1155 dev_info(&card
->gdev
->dev
, "Broadcast enabled\n");
1156 rc
= qeth_send_simple_setassparms(card
, IPA_FILTERING
,
1157 IPA_CMD_ASS_ENABLE
, 1);
1159 dev_warn(&card
->gdev
->dev
, "Setting up broadcast echo "
1160 "filtering for %s failed\n", QETH_CARD_IFNAME(card
));
1163 card
->info
.broadcast_capable
= QETH_BROADCAST_WITHOUT_ECHO
;
1165 if (card
->info
.broadcast_capable
)
1166 card
->dev
->flags
|= IFF_BROADCAST
;
1168 card
->dev
->flags
&= ~IFF_BROADCAST
;
1172 static int qeth_l3_start_ipassists(struct qeth_card
*card
)
1174 QETH_CARD_TEXT(card
, 3, "strtipas");
1176 if (qeth_set_access_ctrl_online(card
, 0))
1178 qeth_l3_start_ipa_arp_processing(card
); /* go on*/
1179 qeth_l3_start_ipa_ip_fragmentation(card
); /* go on*/
1180 qeth_l3_start_ipa_source_mac(card
); /* go on*/
1181 qeth_l3_start_ipa_vlan(card
); /* go on*/
1182 qeth_l3_start_ipa_multicast(card
); /* go on*/
1183 qeth_l3_start_ipa_ipv6(card
); /* go on*/
1184 qeth_l3_start_ipa_broadcast(card
); /* go on*/
1188 static int qeth_l3_iqd_read_initial_mac_cb(struct qeth_card
*card
,
1189 struct qeth_reply
*reply
, unsigned long data
)
1191 struct qeth_ipa_cmd
*cmd
;
1193 cmd
= (struct qeth_ipa_cmd
*) data
;
1194 if (cmd
->hdr
.return_code
== 0)
1195 memcpy(card
->dev
->dev_addr
,
1196 cmd
->data
.create_destroy_addr
.unique_id
, ETH_ALEN
);
1198 eth_random_addr(card
->dev
->dev_addr
);
1203 static int qeth_l3_iqd_read_initial_mac(struct qeth_card
*card
)
1206 struct qeth_cmd_buffer
*iob
;
1207 struct qeth_ipa_cmd
*cmd
;
1209 QETH_DBF_TEXT(SETUP
, 2, "hsrmac");
1211 iob
= qeth_get_ipacmd_buffer(card
, IPA_CMD_CREATE_ADDR
,
1215 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
1216 *((__u16
*) &cmd
->data
.create_destroy_addr
.unique_id
[6]) =
1217 card
->info
.unique_id
;
1219 rc
= qeth_send_ipa_cmd(card
, iob
, qeth_l3_iqd_read_initial_mac_cb
,
1224 static int qeth_l3_get_unique_id_cb(struct qeth_card
*card
,
1225 struct qeth_reply
*reply
, unsigned long data
)
1227 struct qeth_ipa_cmd
*cmd
;
1229 cmd
= (struct qeth_ipa_cmd
*) data
;
1230 if (cmd
->hdr
.return_code
== 0)
1231 card
->info
.unique_id
= *((__u16
*)
1232 &cmd
->data
.create_destroy_addr
.unique_id
[6]);
1234 card
->info
.unique_id
= UNIQUE_ID_IF_CREATE_ADDR_FAILED
|
1235 UNIQUE_ID_NOT_BY_CARD
;
1236 dev_warn(&card
->gdev
->dev
, "The network adapter failed to "
1237 "generate a unique ID\n");
1242 static int qeth_l3_get_unique_id(struct qeth_card
*card
)
1245 struct qeth_cmd_buffer
*iob
;
1246 struct qeth_ipa_cmd
*cmd
;
1248 QETH_DBF_TEXT(SETUP
, 2, "guniqeid");
1250 if (!qeth_is_supported(card
, IPA_IPV6
)) {
1251 card
->info
.unique_id
= UNIQUE_ID_IF_CREATE_ADDR_FAILED
|
1252 UNIQUE_ID_NOT_BY_CARD
;
1256 iob
= qeth_get_ipacmd_buffer(card
, IPA_CMD_CREATE_ADDR
,
1260 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
1261 *((__u16
*) &cmd
->data
.create_destroy_addr
.unique_id
[6]) =
1262 card
->info
.unique_id
;
1264 rc
= qeth_send_ipa_cmd(card
, iob
, qeth_l3_get_unique_id_cb
, NULL
);
1269 qeth_diags_trace_cb(struct qeth_card
*card
, struct qeth_reply
*reply
,
1272 struct qeth_ipa_cmd
*cmd
;
1275 QETH_DBF_TEXT(SETUP
, 2, "diastrcb");
1277 cmd
= (struct qeth_ipa_cmd
*)data
;
1278 rc
= cmd
->hdr
.return_code
;
1280 QETH_CARD_TEXT_(card
, 2, "dxter%x", rc
);
1281 switch (cmd
->data
.diagass
.action
) {
1282 case QETH_DIAGS_CMD_TRACE_QUERY
:
1284 case QETH_DIAGS_CMD_TRACE_DISABLE
:
1287 case IPA_RC_INVALID_SUBCMD
:
1288 card
->info
.promisc_mode
= SET_PROMISC_MODE_OFF
;
1289 dev_info(&card
->gdev
->dev
, "The HiperSockets network "
1290 "traffic analyzer is deactivated\n");
1296 case QETH_DIAGS_CMD_TRACE_ENABLE
:
1299 card
->info
.promisc_mode
= SET_PROMISC_MODE_ON
;
1300 dev_info(&card
->gdev
->dev
, "The HiperSockets network "
1301 "traffic analyzer is activated\n");
1303 case IPA_RC_HARDWARE_AUTH_ERROR
:
1304 dev_warn(&card
->gdev
->dev
, "The device is not "
1305 "authorized to run as a HiperSockets network "
1306 "traffic analyzer\n");
1308 case IPA_RC_TRACE_ALREADY_ACTIVE
:
1309 dev_warn(&card
->gdev
->dev
, "A HiperSockets "
1310 "network traffic analyzer is already "
1311 "active in the HiperSockets LAN\n");
1318 QETH_DBF_MESSAGE(2, "Unknown sniffer action (0x%04x) on %s\n",
1319 cmd
->data
.diagass
.action
, QETH_CARD_IFNAME(card
));
1326 qeth_diags_trace(struct qeth_card
*card
, enum qeth_diags_trace_cmds diags_cmd
)
1328 struct qeth_cmd_buffer
*iob
;
1329 struct qeth_ipa_cmd
*cmd
;
1331 QETH_DBF_TEXT(SETUP
, 2, "diagtrac");
1333 iob
= qeth_get_ipacmd_buffer(card
, IPA_CMD_SET_DIAG_ASS
, 0);
1336 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
1337 cmd
->data
.diagass
.subcmd_len
= 16;
1338 cmd
->data
.diagass
.subcmd
= QETH_DIAGS_CMD_TRACE
;
1339 cmd
->data
.diagass
.type
= QETH_DIAGS_TYPE_HIPERSOCKET
;
1340 cmd
->data
.diagass
.action
= diags_cmd
;
1341 return qeth_send_ipa_cmd(card
, iob
, qeth_diags_trace_cb
, NULL
);
1344 static void qeth_l3_get_mac_for_ipm(__u32 ipm
, char *mac
)
1346 ip_eth_mc_map(ipm
, mac
);
1349 static void qeth_l3_mark_all_mc_to_be_deleted(struct qeth_card
*card
)
1351 struct qeth_ipaddr
*addr
;
1354 hash_for_each(card
->ip_mc_htable
, i
, addr
, hnode
)
1355 addr
->disp_flag
= QETH_DISP_ADDR_DELETE
;
1359 static void qeth_l3_add_all_new_mc(struct qeth_card
*card
)
1361 struct qeth_ipaddr
*addr
;
1362 struct hlist_node
*tmp
;
1366 hash_for_each_safe(card
->ip_mc_htable
, i
, tmp
, addr
, hnode
) {
1367 if (addr
->disp_flag
== QETH_DISP_ADDR_ADD
) {
1368 rc
= qeth_l3_register_addr_entry(card
, addr
);
1369 if (!rc
|| (rc
== IPA_RC_LAN_OFFLINE
))
1370 addr
->ref_counter
= 1;
1372 hash_del(&addr
->hnode
);
1380 static void qeth_l3_delete_nonused_mc(struct qeth_card
*card
)
1382 struct qeth_ipaddr
*addr
;
1383 struct hlist_node
*tmp
;
1387 hash_for_each_safe(card
->ip_mc_htable
, i
, tmp
, addr
, hnode
) {
1388 if (addr
->disp_flag
== QETH_DISP_ADDR_DELETE
) {
1389 rc
= qeth_l3_deregister_addr_entry(card
, addr
);
1390 if (!rc
|| (rc
== IPA_RC_MC_ADDR_NOT_FOUND
)) {
1391 hash_del(&addr
->hnode
);
1401 qeth_l3_add_mc_to_hash(struct qeth_card
*card
, struct in_device
*in4_dev
)
1403 struct ip_mc_list
*im4
;
1404 struct qeth_ipaddr
*tmp
, *ipm
;
1405 char buf
[MAX_ADDR_LEN
];
1407 QETH_CARD_TEXT(card
, 4, "addmc");
1409 tmp
= qeth_l3_get_addr_buffer(QETH_PROT_IPV4
);
1413 for (im4
= rcu_dereference(in4_dev
->mc_list
); im4
!= NULL
;
1414 im4
= rcu_dereference(im4
->next_rcu
)) {
1415 qeth_l3_get_mac_for_ipm(im4
->multiaddr
, buf
);
1417 tmp
->u
.a4
.addr
= im4
->multiaddr
;
1418 memcpy(tmp
->mac
, buf
, sizeof(tmp
->mac
));
1420 ipm
= qeth_l3_ip_from_hash(card
, tmp
);
1422 ipm
->disp_flag
= QETH_DISP_ADDR_DO_NOTHING
;
1424 ipm
= qeth_l3_get_addr_buffer(QETH_PROT_IPV4
);
1427 memcpy(ipm
->mac
, buf
, sizeof(tmp
->mac
));
1428 ipm
->u
.a4
.addr
= im4
->multiaddr
;
1429 ipm
->is_multicast
= 1;
1430 ipm
->disp_flag
= QETH_DISP_ADDR_ADD
;
1431 hash_add(card
->ip_mc_htable
,
1432 &ipm
->hnode
, qeth_l3_ipaddr_hash(ipm
));
1439 /* called with rcu_read_lock */
1440 static void qeth_l3_add_vlan_mc(struct qeth_card
*card
)
1442 struct in_device
*in_dev
;
1445 QETH_CARD_TEXT(card
, 4, "addmcvl");
1447 if (!qeth_is_supported(card
, IPA_FULL_VLAN
))
1450 for_each_set_bit(vid
, card
->active_vlans
, VLAN_N_VID
) {
1451 struct net_device
*netdev
;
1453 netdev
= __vlan_find_dev_deep_rcu(card
->dev
, htons(ETH_P_8021Q
),
1455 if (netdev
== NULL
||
1456 !(netdev
->flags
& IFF_UP
))
1458 in_dev
= __in_dev_get_rcu(netdev
);
1461 qeth_l3_add_mc_to_hash(card
, in_dev
);
1465 static void qeth_l3_add_multicast_ipv4(struct qeth_card
*card
)
1467 struct in_device
*in4_dev
;
1469 QETH_CARD_TEXT(card
, 4, "chkmcv4");
1472 in4_dev
= __in_dev_get_rcu(card
->dev
);
1473 if (in4_dev
== NULL
)
1475 qeth_l3_add_mc_to_hash(card
, in4_dev
);
1476 qeth_l3_add_vlan_mc(card
);
1481 #ifdef CONFIG_QETH_IPV6
1483 qeth_l3_add_mc6_to_hash(struct qeth_card
*card
, struct inet6_dev
*in6_dev
)
1485 struct qeth_ipaddr
*ipm
;
1486 struct ifmcaddr6
*im6
;
1487 struct qeth_ipaddr
*tmp
;
1488 char buf
[MAX_ADDR_LEN
];
1490 QETH_CARD_TEXT(card
, 4, "addmc6");
1492 tmp
= qeth_l3_get_addr_buffer(QETH_PROT_IPV6
);
1496 for (im6
= in6_dev
->mc_list
; im6
!= NULL
; im6
= im6
->next
) {
1497 ndisc_mc_map(&im6
->mca_addr
, buf
, in6_dev
->dev
, 0);
1499 memcpy(tmp
->mac
, buf
, sizeof(tmp
->mac
));
1500 memcpy(&tmp
->u
.a6
.addr
, &im6
->mca_addr
.s6_addr
,
1501 sizeof(struct in6_addr
));
1502 tmp
->is_multicast
= 1;
1504 ipm
= qeth_l3_ip_from_hash(card
, tmp
);
1506 ipm
->disp_flag
= QETH_DISP_ADDR_DO_NOTHING
;
1510 ipm
= qeth_l3_get_addr_buffer(QETH_PROT_IPV6
);
1514 memcpy(ipm
->mac
, buf
, OSA_ADDR_LEN
);
1515 memcpy(&ipm
->u
.a6
.addr
, &im6
->mca_addr
.s6_addr
,
1516 sizeof(struct in6_addr
));
1517 ipm
->is_multicast
= 1;
1518 ipm
->disp_flag
= QETH_DISP_ADDR_ADD
;
1519 hash_add(card
->ip_mc_htable
,
1520 &ipm
->hnode
, qeth_l3_ipaddr_hash(ipm
));
1526 /* called with rcu_read_lock */
1527 static void qeth_l3_add_vlan_mc6(struct qeth_card
*card
)
1529 struct inet6_dev
*in_dev
;
1532 QETH_CARD_TEXT(card
, 4, "admc6vl");
1534 if (!qeth_is_supported(card
, IPA_FULL_VLAN
))
1537 for_each_set_bit(vid
, card
->active_vlans
, VLAN_N_VID
) {
1538 struct net_device
*netdev
;
1540 netdev
= __vlan_find_dev_deep_rcu(card
->dev
, htons(ETH_P_8021Q
),
1542 if (netdev
== NULL
||
1543 !(netdev
->flags
& IFF_UP
))
1545 in_dev
= in6_dev_get(netdev
);
1548 read_lock_bh(&in_dev
->lock
);
1549 qeth_l3_add_mc6_to_hash(card
, in_dev
);
1550 read_unlock_bh(&in_dev
->lock
);
1551 in6_dev_put(in_dev
);
1555 static void qeth_l3_add_multicast_ipv6(struct qeth_card
*card
)
1557 struct inet6_dev
*in6_dev
;
1559 QETH_CARD_TEXT(card
, 4, "chkmcv6");
1561 if (!qeth_is_supported(card
, IPA_IPV6
))
1563 in6_dev
= in6_dev_get(card
->dev
);
1568 read_lock_bh(&in6_dev
->lock
);
1569 qeth_l3_add_mc6_to_hash(card
, in6_dev
);
1570 qeth_l3_add_vlan_mc6(card
);
1571 read_unlock_bh(&in6_dev
->lock
);
1573 in6_dev_put(in6_dev
);
1575 #endif /* CONFIG_QETH_IPV6 */
1577 static void qeth_l3_free_vlan_addresses4(struct qeth_card
*card
,
1580 struct in_device
*in_dev
;
1581 struct in_ifaddr
*ifa
;
1582 struct qeth_ipaddr
*addr
;
1583 struct net_device
*netdev
;
1585 QETH_CARD_TEXT(card
, 4, "frvaddr4");
1587 netdev
= __vlan_find_dev_deep_rcu(card
->dev
, htons(ETH_P_8021Q
), vid
);
1590 in_dev
= in_dev_get(netdev
);
1594 addr
= qeth_l3_get_addr_buffer(QETH_PROT_IPV4
);
1598 spin_lock_bh(&card
->ip_lock
);
1600 for (ifa
= in_dev
->ifa_list
; ifa
; ifa
= ifa
->ifa_next
) {
1601 addr
->u
.a4
.addr
= ifa
->ifa_address
;
1602 addr
->u
.a4
.mask
= ifa
->ifa_mask
;
1603 addr
->type
= QETH_IP_TYPE_NORMAL
;
1604 qeth_l3_delete_ip(card
, addr
);
1607 spin_unlock_bh(&card
->ip_lock
);
1613 static void qeth_l3_free_vlan_addresses6(struct qeth_card
*card
,
1616 #ifdef CONFIG_QETH_IPV6
1617 struct inet6_dev
*in6_dev
;
1618 struct inet6_ifaddr
*ifa
;
1619 struct qeth_ipaddr
*addr
;
1620 struct net_device
*netdev
;
1622 QETH_CARD_TEXT(card
, 4, "frvaddr6");
1624 netdev
= __vlan_find_dev_deep_rcu(card
->dev
, htons(ETH_P_8021Q
), vid
);
1628 in6_dev
= in6_dev_get(netdev
);
1632 addr
= qeth_l3_get_addr_buffer(QETH_PROT_IPV6
);
1636 spin_lock_bh(&card
->ip_lock
);
1638 list_for_each_entry(ifa
, &in6_dev
->addr_list
, if_list
) {
1639 memcpy(&addr
->u
.a6
.addr
, &ifa
->addr
,
1640 sizeof(struct in6_addr
));
1641 addr
->u
.a6
.pfxlen
= ifa
->prefix_len
;
1642 addr
->type
= QETH_IP_TYPE_NORMAL
;
1643 qeth_l3_delete_ip(card
, addr
);
1646 spin_unlock_bh(&card
->ip_lock
);
1649 in6_dev_put(in6_dev
);
1650 #endif /* CONFIG_QETH_IPV6 */
1653 static void qeth_l3_free_vlan_addresses(struct qeth_card
*card
,
1657 qeth_l3_free_vlan_addresses4(card
, vid
);
1658 qeth_l3_free_vlan_addresses6(card
, vid
);
1662 static int qeth_l3_vlan_rx_add_vid(struct net_device
*dev
,
1663 __be16 proto
, u16 vid
)
1665 struct qeth_card
*card
= dev
->ml_priv
;
1667 set_bit(vid
, card
->active_vlans
);
1671 static int qeth_l3_vlan_rx_kill_vid(struct net_device
*dev
,
1672 __be16 proto
, u16 vid
)
1674 struct qeth_card
*card
= dev
->ml_priv
;
1676 QETH_CARD_TEXT_(card
, 4, "kid:%d", vid
);
1678 if (qeth_wait_for_threads(card
, QETH_RECOVER_THREAD
)) {
1679 QETH_CARD_TEXT(card
, 3, "kidREC");
1682 /* unregister IP addresses of vlan device */
1683 qeth_l3_free_vlan_addresses(card
, vid
);
1684 clear_bit(vid
, card
->active_vlans
);
1685 qeth_l3_set_multicast_list(card
->dev
);
1689 static inline int qeth_l3_rebuild_skb(struct qeth_card
*card
,
1690 struct sk_buff
*skb
, struct qeth_hdr
*hdr
,
1691 unsigned short *vlan_id
)
1694 struct iphdr
*ip_hdr
;
1695 unsigned char tg_addr
[MAX_ADDR_LEN
];
1698 if (!(hdr
->hdr
.l3
.flags
& QETH_HDR_PASSTHRU
)) {
1699 prot
= htons((hdr
->hdr
.l3
.flags
& QETH_HDR_IPV6
)? ETH_P_IPV6
:
1701 switch (hdr
->hdr
.l3
.flags
& QETH_HDR_CAST_MASK
) {
1702 case QETH_CAST_MULTICAST
:
1704 #ifdef CONFIG_QETH_IPV6
1705 case __constant_htons(ETH_P_IPV6
):
1706 ndisc_mc_map((struct in6_addr
*)
1708 tg_addr
, card
->dev
, 0);
1711 case __constant_htons(ETH_P_IP
):
1712 ip_hdr
= (struct iphdr
*)skb
->data
;
1713 ip_eth_mc_map(ip_hdr
->daddr
, tg_addr
);
1716 memcpy(tg_addr
, card
->dev
->broadcast
,
1717 card
->dev
->addr_len
);
1719 card
->stats
.multicast
++;
1720 skb
->pkt_type
= PACKET_MULTICAST
;
1722 case QETH_CAST_BROADCAST
:
1723 memcpy(tg_addr
, card
->dev
->broadcast
,
1724 card
->dev
->addr_len
);
1725 card
->stats
.multicast
++;
1726 skb
->pkt_type
= PACKET_BROADCAST
;
1728 case QETH_CAST_UNICAST
:
1729 case QETH_CAST_ANYCAST
:
1730 case QETH_CAST_NOCAST
:
1732 if (card
->options
.sniffer
)
1733 skb
->pkt_type
= PACKET_OTHERHOST
;
1735 skb
->pkt_type
= PACKET_HOST
;
1736 memcpy(tg_addr
, card
->dev
->dev_addr
,
1737 card
->dev
->addr_len
);
1739 if (hdr
->hdr
.l3
.ext_flags
& QETH_HDR_EXT_SRC_MAC_ADDR
)
1740 card
->dev
->header_ops
->create(skb
, card
->dev
, prot
,
1741 tg_addr
, &hdr
->hdr
.l3
.dest_addr
[2],
1742 card
->dev
->addr_len
);
1744 card
->dev
->header_ops
->create(skb
, card
->dev
, prot
,
1745 tg_addr
, "FAKELL", card
->dev
->addr_len
);
1748 skb
->protocol
= eth_type_trans(skb
, card
->dev
);
1750 if (hdr
->hdr
.l3
.ext_flags
&
1751 (QETH_HDR_EXT_VLAN_FRAME
| QETH_HDR_EXT_INCLUDE_VLAN_TAG
)) {
1752 *vlan_id
= (hdr
->hdr
.l3
.ext_flags
& QETH_HDR_EXT_VLAN_FRAME
) ?
1753 hdr
->hdr
.l3
.vlan_id
: *((u16
*)&hdr
->hdr
.l3
.dest_addr
[12]);
1757 if (card
->dev
->features
& NETIF_F_RXCSUM
) {
1758 if ((hdr
->hdr
.l3
.ext_flags
&
1759 (QETH_HDR_EXT_CSUM_HDR_REQ
|
1760 QETH_HDR_EXT_CSUM_TRANSP_REQ
)) ==
1761 (QETH_HDR_EXT_CSUM_HDR_REQ
|
1762 QETH_HDR_EXT_CSUM_TRANSP_REQ
))
1763 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
1765 skb
->ip_summed
= CHECKSUM_NONE
;
1767 skb
->ip_summed
= CHECKSUM_NONE
;
1771 static int qeth_l3_process_inbound_buffer(struct qeth_card
*card
,
1772 int budget
, int *done
)
1775 struct sk_buff
*skb
;
1776 struct qeth_hdr
*hdr
;
1783 WARN_ON_ONCE(!budget
);
1785 skb
= qeth_core_get_next_skb(card
,
1786 &card
->qdio
.in_q
->bufs
[card
->rx
.b_index
],
1787 &card
->rx
.b_element
, &card
->rx
.e_offset
, &hdr
);
1792 skb
->dev
= card
->dev
;
1793 switch (hdr
->hdr
.l3
.id
) {
1794 case QETH_HEADER_TYPE_LAYER3
:
1795 magic
= *(__u16
*)skb
->data
;
1796 if ((card
->info
.type
== QETH_CARD_TYPE_IQD
) &&
1797 (magic
== ETH_P_AF_IUCV
)) {
1798 skb
->protocol
= ETH_P_AF_IUCV
;
1799 skb
->pkt_type
= PACKET_HOST
;
1800 skb
->mac_header
= NET_SKB_PAD
;
1801 skb
->dev
= card
->dev
;
1803 card
->dev
->header_ops
->create(skb
, card
->dev
, 0,
1804 card
->dev
->dev_addr
, "FAKELL",
1805 card
->dev
->addr_len
);
1806 netif_receive_skb(skb
);
1808 is_vlan
= qeth_l3_rebuild_skb(card
, skb
, hdr
,
1811 if (is_vlan
&& !card
->options
.sniffer
)
1812 __vlan_hwaccel_put_tag(skb
,
1813 htons(ETH_P_8021Q
), vlan_tag
);
1814 napi_gro_receive(&card
->napi
, skb
);
1817 case QETH_HEADER_TYPE_LAYER2
: /* for HiperSockets sniffer */
1818 skb
->pkt_type
= PACKET_HOST
;
1819 skb
->protocol
= eth_type_trans(skb
, skb
->dev
);
1821 netif_receive_skb(skb
);
1824 dev_kfree_skb_any(skb
);
1825 QETH_CARD_TEXT(card
, 3, "inbunkno");
1826 QETH_DBF_HEX(CTRL
, 3, hdr
, QETH_DBF_CTRL_LEN
);
1831 card
->stats
.rx_packets
++;
1832 card
->stats
.rx_bytes
+= len
;
1837 static int qeth_l3_poll(struct napi_struct
*napi
, int budget
)
1839 struct qeth_card
*card
= container_of(napi
, struct qeth_card
, napi
);
1841 struct qeth_qdio_buffer
*buffer
;
1843 int new_budget
= budget
;
1845 if (card
->options
.performance_stats
) {
1846 card
->perf_stats
.inbound_cnt
++;
1847 card
->perf_stats
.inbound_start_time
= qeth_get_micros();
1851 if (!card
->rx
.b_count
) {
1852 card
->rx
.qdio_err
= 0;
1853 card
->rx
.b_count
= qdio_get_next_buffers(
1854 card
->data
.ccwdev
, 0, &card
->rx
.b_index
,
1855 &card
->rx
.qdio_err
);
1856 if (card
->rx
.b_count
<= 0) {
1857 card
->rx
.b_count
= 0;
1860 card
->rx
.b_element
=
1861 &card
->qdio
.in_q
->bufs
[card
->rx
.b_index
]
1862 .buffer
->element
[0];
1863 card
->rx
.e_offset
= 0;
1866 while (card
->rx
.b_count
) {
1867 buffer
= &card
->qdio
.in_q
->bufs
[card
->rx
.b_index
];
1868 if (!(card
->rx
.qdio_err
&&
1869 qeth_check_qdio_errors(card
, buffer
->buffer
,
1870 card
->rx
.qdio_err
, "qinerr")))
1871 work_done
+= qeth_l3_process_inbound_buffer(
1872 card
, new_budget
, &done
);
1877 if (card
->options
.performance_stats
)
1878 card
->perf_stats
.bufs_rec
++;
1879 qeth_put_buffer_pool_entry(card
,
1880 buffer
->pool_entry
);
1881 qeth_queue_input_buffer(card
, card
->rx
.b_index
);
1883 if (card
->rx
.b_count
) {
1885 (card
->rx
.b_index
+ 1) %
1886 QDIO_MAX_BUFFERS_PER_Q
;
1887 card
->rx
.b_element
=
1889 ->bufs
[card
->rx
.b_index
]
1890 .buffer
->element
[0];
1891 card
->rx
.e_offset
= 0;
1895 if (work_done
>= budget
)
1898 new_budget
= budget
- work_done
;
1902 napi_complete(napi
);
1903 if (qdio_start_irq(card
->data
.ccwdev
, 0))
1904 napi_schedule(&card
->napi
);
1906 if (card
->options
.performance_stats
)
1907 card
->perf_stats
.inbound_time
+= qeth_get_micros() -
1908 card
->perf_stats
.inbound_start_time
;
1912 static int qeth_l3_verify_vlan_dev(struct net_device
*dev
,
1913 struct qeth_card
*card
)
1918 for_each_set_bit(vid
, card
->active_vlans
, VLAN_N_VID
) {
1919 struct net_device
*netdev
;
1922 netdev
= __vlan_find_dev_deep_rcu(card
->dev
, htons(ETH_P_8021Q
),
1925 if (netdev
== dev
) {
1926 rc
= QETH_VLAN_CARD
;
1931 if (rc
&& !(vlan_dev_real_dev(dev
)->ml_priv
== (void *)card
))
1937 static int qeth_l3_verify_dev(struct net_device
*dev
)
1939 struct qeth_card
*card
;
1941 unsigned long flags
;
1943 read_lock_irqsave(&qeth_core_card_list
.rwlock
, flags
);
1944 list_for_each_entry(card
, &qeth_core_card_list
.list
, list
) {
1945 if (card
->dev
== dev
) {
1946 rc
= QETH_REAL_CARD
;
1949 rc
= qeth_l3_verify_vlan_dev(dev
, card
);
1953 read_unlock_irqrestore(&qeth_core_card_list
.rwlock
, flags
);
1958 static struct qeth_card
*qeth_l3_get_card_from_dev(struct net_device
*dev
)
1960 struct qeth_card
*card
= NULL
;
1963 rc
= qeth_l3_verify_dev(dev
);
1964 if (rc
== QETH_REAL_CARD
)
1965 card
= dev
->ml_priv
;
1966 else if (rc
== QETH_VLAN_CARD
)
1967 card
= vlan_dev_real_dev(dev
)->ml_priv
;
1968 if (card
&& card
->options
.layer2
)
1971 QETH_CARD_TEXT_(card
, 4, "%d", rc
);
1975 static void qeth_l3_stop_card(struct qeth_card
*card
, int recovery_mode
)
1977 QETH_DBF_TEXT(SETUP
, 2, "stopcard");
1978 QETH_DBF_HEX(SETUP
, 2, &card
, sizeof(void *));
1980 qeth_set_allowed_threads(card
, 0, 1);
1981 if (card
->options
.sniffer
&&
1982 (card
->info
.promisc_mode
== SET_PROMISC_MODE_ON
))
1983 qeth_diags_trace(card
, QETH_DIAGS_CMD_TRACE_DISABLE
);
1984 if (card
->read
.state
== CH_STATE_UP
&&
1985 card
->write
.state
== CH_STATE_UP
&&
1986 (card
->state
== CARD_STATE_UP
)) {
1988 qeth_l3_stop(card
->dev
);
1991 dev_close(card
->dev
);
1994 card
->state
= CARD_STATE_SOFTSETUP
;
1996 if (card
->state
== CARD_STATE_SOFTSETUP
) {
1997 qeth_l3_clear_ip_htable(card
, 1);
1998 qeth_clear_ipacmd_list(card
);
1999 card
->state
= CARD_STATE_HARDSETUP
;
2001 if (card
->state
== CARD_STATE_HARDSETUP
) {
2002 qeth_qdio_clear_card(card
, 0);
2003 qeth_clear_qdio_buffers(card
);
2004 qeth_clear_working_pool_list(card
);
2005 card
->state
= CARD_STATE_DOWN
;
2007 if (card
->state
== CARD_STATE_DOWN
) {
2008 qeth_clear_cmd_buffers(&card
->read
);
2009 qeth_clear_cmd_buffers(&card
->write
);
2014 * test for and Switch promiscuous mode (on or off)
2015 * either for guestlan or HiperSocket Sniffer
2018 qeth_l3_handle_promisc_mode(struct qeth_card
*card
)
2020 struct net_device
*dev
= card
->dev
;
2022 if (((dev
->flags
& IFF_PROMISC
) &&
2023 (card
->info
.promisc_mode
== SET_PROMISC_MODE_ON
)) ||
2024 (!(dev
->flags
& IFF_PROMISC
) &&
2025 (card
->info
.promisc_mode
== SET_PROMISC_MODE_OFF
)))
2028 if (card
->info
.guestlan
) { /* Guestlan trace */
2029 if (qeth_adp_supported(card
, IPA_SETADP_SET_PROMISC_MODE
))
2030 qeth_setadp_promisc_mode(card
);
2031 } else if (card
->options
.sniffer
&& /* HiperSockets trace */
2032 qeth_adp_supported(card
, IPA_SETADP_SET_DIAG_ASSIST
)) {
2033 if (dev
->flags
& IFF_PROMISC
) {
2034 QETH_CARD_TEXT(card
, 3, "+promisc");
2035 qeth_diags_trace(card
, QETH_DIAGS_CMD_TRACE_ENABLE
);
2037 QETH_CARD_TEXT(card
, 3, "-promisc");
2038 qeth_diags_trace(card
, QETH_DIAGS_CMD_TRACE_DISABLE
);
2043 static void qeth_l3_set_multicast_list(struct net_device
*dev
)
2045 struct qeth_card
*card
= dev
->ml_priv
;
2047 QETH_CARD_TEXT(card
, 3, "setmulti");
2048 if (qeth_threads_running(card
, QETH_RECOVER_THREAD
) &&
2049 (card
->state
!= CARD_STATE_UP
))
2051 if (!card
->options
.sniffer
) {
2053 spin_lock_bh(&card
->mclock
);
2055 qeth_l3_mark_all_mc_to_be_deleted(card
);
2057 qeth_l3_add_multicast_ipv4(card
);
2058 #ifdef CONFIG_QETH_IPV6
2059 qeth_l3_add_multicast_ipv6(card
);
2061 qeth_l3_delete_nonused_mc(card
);
2062 qeth_l3_add_all_new_mc(card
);
2064 spin_unlock_bh(&card
->mclock
);
2066 if (!qeth_adp_supported(card
, IPA_SETADP_SET_PROMISC_MODE
))
2069 qeth_l3_handle_promisc_mode(card
);
2072 static const char *qeth_l3_arp_get_error_cause(int *rc
)
2075 case QETH_IPA_ARP_RC_FAILED
:
2077 return "operation failed";
2078 case QETH_IPA_ARP_RC_NOTSUPP
:
2080 return "operation not supported";
2081 case QETH_IPA_ARP_RC_OUT_OF_RANGE
:
2083 return "argument out of range";
2084 case QETH_IPA_ARP_RC_Q_NOTSUPP
:
2086 return "query operation not supported";
2087 case QETH_IPA_ARP_RC_Q_NO_DATA
:
2089 return "no query data available";
2091 return "unknown error";
2095 static int qeth_l3_arp_set_no_entries(struct qeth_card
*card
, int no_entries
)
2100 QETH_CARD_TEXT(card
, 3, "arpstnoe");
2103 * currently GuestLAN only supports the ARP assist function
2104 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_SET_NO_ENTRIES;
2105 * thus we say EOPNOTSUPP for this ARP function
2107 if (card
->info
.guestlan
)
2109 if (!qeth_is_supported(card
, IPA_ARP_PROCESSING
)) {
2112 rc
= qeth_send_simple_setassparms(card
, IPA_ARP_PROCESSING
,
2113 IPA_CMD_ASS_ARP_SET_NO_ENTRIES
,
2117 QETH_DBF_MESSAGE(2, "Could not set number of ARP entries on "
2118 "%s: %s (0x%x/%d)\n", QETH_CARD_IFNAME(card
),
2119 qeth_l3_arp_get_error_cause(&rc
), tmp
, tmp
);
2124 static __u32
get_arp_entry_size(struct qeth_card
*card
,
2125 struct qeth_arp_query_data
*qdata
,
2126 struct qeth_arp_entrytype
*type
, __u8 strip_entries
)
2131 is_hsi
= qdata
->reply_bits
== 5;
2132 if (type
->ip
== QETHARP_IP_ADDR_V4
) {
2133 QETH_CARD_TEXT(card
, 4, "arpev4");
2134 if (strip_entries
) {
2135 rc
= is_hsi
? sizeof(struct qeth_arp_qi_entry5_short
) :
2136 sizeof(struct qeth_arp_qi_entry7_short
);
2138 rc
= is_hsi
? sizeof(struct qeth_arp_qi_entry5
) :
2139 sizeof(struct qeth_arp_qi_entry7
);
2141 } else if (type
->ip
== QETHARP_IP_ADDR_V6
) {
2142 QETH_CARD_TEXT(card
, 4, "arpev6");
2143 if (strip_entries
) {
2145 sizeof(struct qeth_arp_qi_entry5_short_ipv6
) :
2146 sizeof(struct qeth_arp_qi_entry7_short_ipv6
);
2149 sizeof(struct qeth_arp_qi_entry5_ipv6
) :
2150 sizeof(struct qeth_arp_qi_entry7_ipv6
);
2153 QETH_CARD_TEXT(card
, 4, "arpinv");
2160 static int arpentry_matches_prot(struct qeth_arp_entrytype
*type
, __u16 prot
)
2162 return (type
->ip
== QETHARP_IP_ADDR_V4
&& prot
== QETH_PROT_IPV4
) ||
2163 (type
->ip
== QETHARP_IP_ADDR_V6
&& prot
== QETH_PROT_IPV6
);
2166 static int qeth_l3_arp_query_cb(struct qeth_card
*card
,
2167 struct qeth_reply
*reply
, unsigned long data
)
2169 struct qeth_ipa_cmd
*cmd
;
2170 struct qeth_arp_query_data
*qdata
;
2171 struct qeth_arp_query_info
*qinfo
;
2174 int entrybytes_done
;
2176 __u8 do_strip_entries
;
2178 QETH_CARD_TEXT(card
, 3, "arpquecb");
2180 qinfo
= (struct qeth_arp_query_info
*) reply
->param
;
2181 cmd
= (struct qeth_ipa_cmd
*) data
;
2182 QETH_CARD_TEXT_(card
, 4, "%i", cmd
->hdr
.prot_version
);
2183 if (cmd
->hdr
.return_code
) {
2184 QETH_CARD_TEXT(card
, 4, "arpcberr");
2185 QETH_CARD_TEXT_(card
, 4, "%i", cmd
->hdr
.return_code
);
2188 if (cmd
->data
.setassparms
.hdr
.return_code
) {
2189 cmd
->hdr
.return_code
= cmd
->data
.setassparms
.hdr
.return_code
;
2190 QETH_CARD_TEXT(card
, 4, "setaperr");
2191 QETH_CARD_TEXT_(card
, 4, "%i", cmd
->hdr
.return_code
);
2194 qdata
= &cmd
->data
.setassparms
.data
.query_arp
;
2195 QETH_CARD_TEXT_(card
, 4, "anoen%i", qdata
->no_entries
);
2197 do_strip_entries
= (qinfo
->mask_bits
& QETH_QARP_STRIP_ENTRIES
) > 0;
2198 stripped_bytes
= do_strip_entries
? QETH_QARP_MEDIASPECIFIC_BYTES
: 0;
2199 entrybytes_done
= 0;
2200 for (e
= 0; e
< qdata
->no_entries
; ++e
) {
2203 struct qeth_arp_entrytype
*etype
;
2205 cur_entry
= &qdata
->data
+ entrybytes_done
;
2206 etype
= &((struct qeth_arp_qi_entry5
*) cur_entry
)->type
;
2207 if (!arpentry_matches_prot(etype
, cmd
->hdr
.prot_version
)) {
2208 QETH_CARD_TEXT(card
, 4, "pmis");
2209 QETH_CARD_TEXT_(card
, 4, "%i", etype
->ip
);
2212 esize
= get_arp_entry_size(card
, qdata
, etype
,
2214 QETH_CARD_TEXT_(card
, 5, "esz%i", esize
);
2218 if ((qinfo
->udata_len
- qinfo
->udata_offset
) < esize
) {
2219 QETH_CARD_TEXT_(card
, 4, "qaer3%i", -ENOMEM
);
2220 cmd
->hdr
.return_code
= IPA_RC_ENOMEM
;
2224 memcpy(qinfo
->udata
+ qinfo
->udata_offset
,
2225 &qdata
->data
+ entrybytes_done
+ stripped_bytes
,
2227 entrybytes_done
+= esize
+ stripped_bytes
;
2228 qinfo
->udata_offset
+= esize
;
2229 ++qinfo
->no_entries
;
2231 /* check if all replies received ... */
2232 if (cmd
->data
.setassparms
.hdr
.seq_no
<
2233 cmd
->data
.setassparms
.hdr
.number_of_replies
)
2235 QETH_CARD_TEXT_(card
, 4, "nove%i", qinfo
->no_entries
);
2236 memcpy(qinfo
->udata
, &qinfo
->no_entries
, 4);
2237 /* keep STRIP_ENTRIES flag so the user program can distinguish
2238 * stripped entries from normal ones */
2239 if (qinfo
->mask_bits
& QETH_QARP_STRIP_ENTRIES
)
2240 qdata
->reply_bits
|= QETH_QARP_STRIP_ENTRIES
;
2241 memcpy(qinfo
->udata
+ QETH_QARP_MASK_OFFSET
, &qdata
->reply_bits
, 2);
2242 QETH_CARD_TEXT_(card
, 4, "rc%i", 0);
2246 memcpy(qinfo
->udata
, &i
, 4);
2250 static int qeth_l3_send_ipa_arp_cmd(struct qeth_card
*card
,
2251 struct qeth_cmd_buffer
*iob
, int len
,
2252 int (*reply_cb
)(struct qeth_card
*, struct qeth_reply
*,
2256 QETH_CARD_TEXT(card
, 4, "sendarp");
2258 memcpy(iob
->data
, IPA_PDU_HEADER
, IPA_PDU_HEADER_SIZE
);
2259 memcpy(QETH_IPA_CMD_DEST_ADDR(iob
->data
),
2260 &card
->token
.ulp_connection_r
, QETH_MPC_TOKEN_LENGTH
);
2261 return qeth_send_control_data(card
, IPA_PDU_HEADER_SIZE
+ len
, iob
,
2262 reply_cb
, reply_param
);
2265 static int qeth_l3_query_arp_cache_info(struct qeth_card
*card
,
2266 enum qeth_prot_versions prot
,
2267 struct qeth_arp_query_info
*qinfo
)
2269 struct qeth_cmd_buffer
*iob
;
2270 struct qeth_ipa_cmd
*cmd
;
2274 QETH_CARD_TEXT_(card
, 3, "qarpipv%i", prot
);
2276 iob
= qeth_get_setassparms_cmd(card
, IPA_ARP_PROCESSING
,
2277 IPA_CMD_ASS_ARP_QUERY_INFO
,
2278 sizeof(struct qeth_arp_query_data
)
2283 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
2284 cmd
->data
.setassparms
.data
.query_arp
.request_bits
= 0x000F;
2285 cmd
->data
.setassparms
.data
.query_arp
.reply_bits
= 0;
2286 cmd
->data
.setassparms
.data
.query_arp
.no_entries
= 0;
2287 rc
= qeth_l3_send_ipa_arp_cmd(card
, iob
,
2288 QETH_SETASS_BASE_LEN
+QETH_ARP_CMD_LEN
,
2289 qeth_l3_arp_query_cb
, (void *)qinfo
);
2293 "Error while querying ARP cache on %s: %s "
2294 "(0x%x/%d)\n", QETH_CARD_IFNAME(card
),
2295 qeth_l3_arp_get_error_cause(&rc
), tmp
, tmp
);
2301 static int qeth_l3_arp_query(struct qeth_card
*card
, char __user
*udata
)
2303 struct qeth_arp_query_info qinfo
= {0, };
2306 QETH_CARD_TEXT(card
, 3, "arpquery");
2308 if (!qeth_is_supported(card
,/*IPA_QUERY_ARP_ADDR_INFO*/
2309 IPA_ARP_PROCESSING
)) {
2310 QETH_CARD_TEXT(card
, 3, "arpqnsup");
2314 /* get size of userspace buffer and mask_bits -> 6 bytes */
2315 if (copy_from_user(&qinfo
, udata
, 6)) {
2319 qinfo
.udata
= kzalloc(qinfo
.udata_len
, GFP_KERNEL
);
2324 qinfo
.udata_offset
= QETH_QARP_ENTRIES_OFFSET
;
2325 rc
= qeth_l3_query_arp_cache_info(card
, QETH_PROT_IPV4
, &qinfo
);
2327 if (copy_to_user(udata
, qinfo
.udata
, 4))
2331 #ifdef CONFIG_QETH_IPV6
2332 if (qinfo
.mask_bits
& QETH_QARP_WITH_IPV6
) {
2333 /* fails in case of GuestLAN QDIO mode */
2334 qeth_l3_query_arp_cache_info(card
, QETH_PROT_IPV6
, &qinfo
);
2337 if (copy_to_user(udata
, qinfo
.udata
, qinfo
.udata_len
)) {
2338 QETH_CARD_TEXT(card
, 4, "qactf");
2342 QETH_CARD_TEXT(card
, 4, "qacts");
2350 static int qeth_l3_arp_add_entry(struct qeth_card
*card
,
2351 struct qeth_arp_cache_entry
*entry
)
2353 struct qeth_cmd_buffer
*iob
;
2358 QETH_CARD_TEXT(card
, 3, "arpadent");
2361 * currently GuestLAN only supports the ARP assist function
2362 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_ADD_ENTRY;
2363 * thus we say EOPNOTSUPP for this ARP function
2365 if (card
->info
.guestlan
)
2367 if (!qeth_is_supported(card
, IPA_ARP_PROCESSING
)) {
2371 iob
= qeth_get_setassparms_cmd(card
, IPA_ARP_PROCESSING
,
2372 IPA_CMD_ASS_ARP_ADD_ENTRY
,
2373 sizeof(struct qeth_arp_cache_entry
),
2377 rc
= qeth_send_setassparms(card
, iob
,
2378 sizeof(struct qeth_arp_cache_entry
),
2379 (unsigned long) entry
,
2380 qeth_setassparms_cb
, NULL
);
2383 qeth_l3_ipaddr4_to_string((u8
*)entry
->ipaddr
, buf
);
2384 QETH_DBF_MESSAGE(2, "Could not add ARP entry for address %s "
2385 "on %s: %s (0x%x/%d)\n", buf
, QETH_CARD_IFNAME(card
),
2386 qeth_l3_arp_get_error_cause(&rc
), tmp
, tmp
);
2391 static int qeth_l3_arp_remove_entry(struct qeth_card
*card
,
2392 struct qeth_arp_cache_entry
*entry
)
2394 struct qeth_cmd_buffer
*iob
;
2395 char buf
[16] = {0, };
2399 QETH_CARD_TEXT(card
, 3, "arprment");
2402 * currently GuestLAN only supports the ARP assist function
2403 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_REMOVE_ENTRY;
2404 * thus we say EOPNOTSUPP for this ARP function
2406 if (card
->info
.guestlan
)
2408 if (!qeth_is_supported(card
, IPA_ARP_PROCESSING
)) {
2411 memcpy(buf
, entry
, 12);
2412 iob
= qeth_get_setassparms_cmd(card
, IPA_ARP_PROCESSING
,
2413 IPA_CMD_ASS_ARP_REMOVE_ENTRY
,
2418 rc
= qeth_send_setassparms(card
, iob
,
2419 12, (unsigned long)buf
,
2420 qeth_setassparms_cb
, NULL
);
2424 qeth_l3_ipaddr4_to_string((u8
*)entry
->ipaddr
, buf
);
2425 QETH_DBF_MESSAGE(2, "Could not delete ARP entry for address %s"
2426 " on %s: %s (0x%x/%d)\n", buf
, QETH_CARD_IFNAME(card
),
2427 qeth_l3_arp_get_error_cause(&rc
), tmp
, tmp
);
2432 static int qeth_l3_arp_flush_cache(struct qeth_card
*card
)
2437 QETH_CARD_TEXT(card
, 3, "arpflush");
2440 * currently GuestLAN only supports the ARP assist function
2441 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_FLUSH_CACHE;
2442 * thus we say EOPNOTSUPP for this ARP function
2444 if (card
->info
.guestlan
|| (card
->info
.type
== QETH_CARD_TYPE_IQD
))
2446 if (!qeth_is_supported(card
, IPA_ARP_PROCESSING
)) {
2449 rc
= qeth_send_simple_setassparms(card
, IPA_ARP_PROCESSING
,
2450 IPA_CMD_ASS_ARP_FLUSH_CACHE
, 0);
2453 QETH_DBF_MESSAGE(2, "Could not flush ARP cache on %s: %s "
2454 "(0x%x/%d)\n", QETH_CARD_IFNAME(card
),
2455 qeth_l3_arp_get_error_cause(&rc
), tmp
, tmp
);
2460 static int qeth_l3_do_ioctl(struct net_device
*dev
, struct ifreq
*rq
, int cmd
)
2462 struct qeth_card
*card
= dev
->ml_priv
;
2463 struct qeth_arp_cache_entry arp_entry
;
2464 struct mii_ioctl_data
*mii_data
;
2470 if (!qeth_card_hw_is_reachable(card
))
2474 case SIOC_QETH_ARP_SET_NO_ENTRIES
:
2475 if (!capable(CAP_NET_ADMIN
)) {
2479 rc
= qeth_l3_arp_set_no_entries(card
, rq
->ifr_ifru
.ifru_ivalue
);
2481 case SIOC_QETH_ARP_QUERY_INFO
:
2482 if (!capable(CAP_NET_ADMIN
)) {
2486 rc
= qeth_l3_arp_query(card
, rq
->ifr_ifru
.ifru_data
);
2488 case SIOC_QETH_ARP_ADD_ENTRY
:
2489 if (!capable(CAP_NET_ADMIN
)) {
2493 if (copy_from_user(&arp_entry
, rq
->ifr_ifru
.ifru_data
,
2494 sizeof(struct qeth_arp_cache_entry
)))
2497 rc
= qeth_l3_arp_add_entry(card
, &arp_entry
);
2499 case SIOC_QETH_ARP_REMOVE_ENTRY
:
2500 if (!capable(CAP_NET_ADMIN
)) {
2504 if (copy_from_user(&arp_entry
, rq
->ifr_ifru
.ifru_data
,
2505 sizeof(struct qeth_arp_cache_entry
)))
2508 rc
= qeth_l3_arp_remove_entry(card
, &arp_entry
);
2510 case SIOC_QETH_ARP_FLUSH_CACHE
:
2511 if (!capable(CAP_NET_ADMIN
)) {
2515 rc
= qeth_l3_arp_flush_cache(card
);
2517 case SIOC_QETH_ADP_SET_SNMP_CONTROL
:
2518 rc
= qeth_snmp_command(card
, rq
->ifr_ifru
.ifru_data
);
2520 case SIOC_QETH_GET_CARD_TYPE
:
2521 if ((card
->info
.type
== QETH_CARD_TYPE_OSD
||
2522 card
->info
.type
== QETH_CARD_TYPE_OSX
) &&
2523 !card
->info
.guestlan
)
2528 mii_data
= if_mii(rq
);
2529 mii_data
->phy_id
= 0;
2532 mii_data
= if_mii(rq
);
2533 if (mii_data
->phy_id
!= 0)
2536 mii_data
->val_out
= qeth_mdio_read(dev
,
2540 case SIOC_QETH_QUERY_OAT
:
2541 rc
= qeth_query_oat_command(card
, rq
->ifr_ifru
.ifru_data
);
2547 QETH_CARD_TEXT_(card
, 2, "ioce%d", rc
);
2551 int inline qeth_l3_get_cast_type(struct qeth_card
*card
, struct sk_buff
*skb
)
2553 int cast_type
= RTN_UNSPEC
;
2554 struct neighbour
*n
= NULL
;
2555 struct dst_entry
*dst
;
2560 n
= dst_neigh_lookup_skb(dst
, skb
);
2562 cast_type
= n
->type
;
2565 if ((cast_type
== RTN_BROADCAST
) ||
2566 (cast_type
== RTN_MULTICAST
) ||
2567 (cast_type
== RTN_ANYCAST
))
2574 /* try something else */
2575 if (skb
->protocol
== ETH_P_IPV6
)
2576 return (skb_network_header(skb
)[24] == 0xff) ?
2578 else if (skb
->protocol
== ETH_P_IP
)
2579 return ((skb_network_header(skb
)[16] & 0xf0) == 0xe0) ?
2582 if (!memcmp(skb
->data
, skb
->dev
->broadcast
, 6))
2583 return RTN_BROADCAST
;
2587 hdr_mac
= *((u16
*)skb
->data
);
2589 switch (card
->info
.link_type
) {
2590 case QETH_LINK_TYPE_HSTR
:
2591 case QETH_LINK_TYPE_LANE_TR
:
2592 if ((hdr_mac
== QETH_TR_MAC_NC
) ||
2593 (hdr_mac
== QETH_TR_MAC_C
))
2594 return RTN_MULTICAST
;
2596 /* eth or so multicast? */
2598 if ((hdr_mac
== QETH_ETH_MAC_V4
) ||
2599 (hdr_mac
== QETH_ETH_MAC_V6
))
2600 return RTN_MULTICAST
;
2606 static void qeth_l3_fill_af_iucv_hdr(struct qeth_card
*card
,
2607 struct qeth_hdr
*hdr
, struct sk_buff
*skb
)
2610 struct af_iucv_trans_hdr
*iucv_hdr
;
2613 card
->dev
->header_ops
->create(skb
, card
->dev
, 0,
2614 card
->dev
->dev_addr
, card
->dev
->dev_addr
,
2615 card
->dev
->addr_len
);
2617 iucv_hdr
= (struct af_iucv_trans_hdr
*)skb
->data
;
2618 memset(hdr
, 0, sizeof(struct qeth_hdr
));
2619 hdr
->hdr
.l3
.id
= QETH_HEADER_TYPE_LAYER3
;
2620 hdr
->hdr
.l3
.ext_flags
= 0;
2621 hdr
->hdr
.l3
.length
= skb
->len
;
2622 hdr
->hdr
.l3
.flags
= QETH_HDR_IPV6
| QETH_CAST_UNICAST
;
2623 memset(daddr
, 0, sizeof(daddr
));
2626 memcpy(&daddr
[8], iucv_hdr
->destUserID
, 8);
2627 memcpy(hdr
->hdr
.l3
.dest_addr
, daddr
, 16);
2630 static void qeth_l3_fill_header(struct qeth_card
*card
, struct qeth_hdr
*hdr
,
2631 struct sk_buff
*skb
, int ipv
, int cast_type
)
2633 struct dst_entry
*dst
;
2635 memset(hdr
, 0, sizeof(struct qeth_hdr
));
2636 hdr
->hdr
.l3
.id
= QETH_HEADER_TYPE_LAYER3
;
2637 hdr
->hdr
.l3
.ext_flags
= 0;
2640 * before we're going to overwrite this location with next hop ip.
2641 * v6 uses passthrough, v4 sets the tag in the QDIO header.
2643 if (skb_vlan_tag_present(skb
)) {
2644 if ((ipv
== 4) || (card
->info
.type
== QETH_CARD_TYPE_IQD
))
2645 hdr
->hdr
.l3
.ext_flags
= QETH_HDR_EXT_VLAN_FRAME
;
2647 hdr
->hdr
.l3
.ext_flags
= QETH_HDR_EXT_INCLUDE_VLAN_TAG
;
2648 hdr
->hdr
.l3
.vlan_id
= skb_vlan_tag_get(skb
);
2651 hdr
->hdr
.l3
.length
= skb
->len
- sizeof(struct qeth_hdr
);
2656 struct rtable
*rt
= (struct rtable
*) dst
;
2657 __be32
*pkey
= &ip_hdr(skb
)->daddr
;
2660 pkey
= &rt
->rt_gateway
;
2663 hdr
->hdr
.l3
.flags
= qeth_l3_get_qeth_hdr_flags4(cast_type
);
2664 memset(hdr
->hdr
.l3
.dest_addr
, 0, 12);
2665 *((__be32
*) (&hdr
->hdr
.l3
.dest_addr
[12])) = *pkey
;
2666 } else if (ipv
== 6) {
2667 struct rt6_info
*rt
= (struct rt6_info
*) dst
;
2668 struct in6_addr
*pkey
= &ipv6_hdr(skb
)->daddr
;
2670 if (!ipv6_addr_any(&rt
->rt6i_gateway
))
2671 pkey
= &rt
->rt6i_gateway
;
2674 hdr
->hdr
.l3
.flags
= qeth_l3_get_qeth_hdr_flags6(cast_type
);
2675 if (card
->info
.type
== QETH_CARD_TYPE_IQD
)
2676 hdr
->hdr
.l3
.flags
&= ~QETH_HDR_PASSTHRU
;
2677 memcpy(hdr
->hdr
.l3
.dest_addr
, pkey
, 16);
2679 if (!memcmp(skb
->data
+ sizeof(struct qeth_hdr
),
2680 skb
->dev
->broadcast
, 6)) {
2682 hdr
->hdr
.l3
.flags
= QETH_CAST_BROADCAST
|
2685 hdr
->hdr
.l3
.flags
= (cast_type
== RTN_MULTICAST
) ?
2686 QETH_CAST_MULTICAST
| QETH_HDR_PASSTHRU
:
2687 QETH_CAST_UNICAST
| QETH_HDR_PASSTHRU
;
2693 static inline void qeth_l3_hdr_csum(struct qeth_card
*card
,
2694 struct qeth_hdr
*hdr
, struct sk_buff
*skb
)
2696 struct iphdr
*iph
= ip_hdr(skb
);
2698 /* tcph->check contains already the pseudo hdr checksum
2699 * so just set the header flags
2701 if (iph
->protocol
== IPPROTO_UDP
)
2702 hdr
->hdr
.l3
.ext_flags
|= QETH_HDR_EXT_UDP
;
2703 hdr
->hdr
.l3
.ext_flags
|= QETH_HDR_EXT_CSUM_TRANSP_REQ
|
2704 QETH_HDR_EXT_CSUM_HDR_REQ
;
2706 if (card
->options
.performance_stats
)
2707 card
->perf_stats
.tx_csum
++;
2710 static void qeth_tso_fill_header(struct qeth_card
*card
,
2711 struct qeth_hdr
*qhdr
, struct sk_buff
*skb
)
2713 struct qeth_hdr_tso
*hdr
= (struct qeth_hdr_tso
*)qhdr
;
2714 struct tcphdr
*tcph
= tcp_hdr(skb
);
2715 struct iphdr
*iph
= ip_hdr(skb
);
2716 struct ipv6hdr
*ip6h
= ipv6_hdr(skb
);
2718 /*fix header to TSO values ...*/
2719 hdr
->hdr
.hdr
.l3
.id
= QETH_HEADER_TYPE_TSO
;
2720 hdr
->hdr
.hdr
.l3
.length
= skb
->len
- sizeof(struct qeth_hdr_tso
);
2721 /*set values which are fix for the first approach ...*/
2722 hdr
->ext
.hdr_tot_len
= (__u16
) sizeof(struct qeth_hdr_ext_tso
);
2723 hdr
->ext
.imb_hdr_no
= 1;
2724 hdr
->ext
.hdr_type
= 1;
2725 hdr
->ext
.hdr_version
= 1;
2726 hdr
->ext
.hdr_len
= 28;
2727 /*insert non-fix values */
2728 hdr
->ext
.mss
= skb_shinfo(skb
)->gso_size
;
2729 hdr
->ext
.dg_hdr_len
= (__u16
)(iph
->ihl
*4 + tcph
->doff
*4);
2730 hdr
->ext
.payload_len
= (__u16
)(skb
->len
- hdr
->ext
.dg_hdr_len
-
2731 sizeof(struct qeth_hdr_tso
));
2733 if (skb
->protocol
== ETH_P_IPV6
) {
2734 ip6h
->payload_len
= 0;
2735 tcph
->check
= ~csum_ipv6_magic(&ip6h
->saddr
, &ip6h
->daddr
,
2738 /*OSA want us to set these values ...*/
2739 tcph
->check
= ~csum_tcpudp_magic(iph
->saddr
, iph
->daddr
,
2747 * qeth_l3_get_elements_no_tso() - find number of SBALEs for skb data for tso
2748 * @card: qeth card structure, to check max. elems.
2750 * @extra_elems: extra elems needed, to check against max.
2752 * Returns the number of pages, and thus QDIO buffer elements, needed to cover
2753 * skb data, including linear part and fragments, but excluding TCP header.
2754 * (Exclusion of TCP header distinguishes it from qeth_get_elements_no().)
2755 * Checks if the result plus extra_elems fits under the limit for the card.
2756 * Returns 0 if it does not.
2757 * Note: extra_elems is not included in the returned result.
2759 static int qeth_l3_get_elements_no_tso(struct qeth_card
*card
,
2760 struct sk_buff
*skb
, int extra_elems
)
2762 addr_t tcpdptr
= (addr_t
)tcp_hdr(skb
) + tcp_hdrlen(skb
);
2763 int elements
= qeth_get_elements_for_range(
2765 (addr_t
)skb
->data
+ skb_headlen(skb
)) +
2766 qeth_get_elements_for_frags(skb
);
2768 if ((elements
+ extra_elems
) > QETH_MAX_BUFFER_ELEMENTS(card
)) {
2770 "Invalid size of TSO IP packet (Number=%d / Length=%d). Discarded.\n",
2771 elements
+ extra_elems
, skb
->len
);
2777 static int qeth_l3_hard_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
2781 struct qeth_hdr
*hdr
= NULL
;
2782 int hdr_elements
= 0;
2784 struct qeth_card
*card
= dev
->ml_priv
;
2785 struct sk_buff
*new_skb
= NULL
;
2786 int ipv
= qeth_get_ip_version(skb
);
2787 int cast_type
= qeth_l3_get_cast_type(card
, skb
);
2788 struct qeth_qdio_out_q
*queue
=
2789 card
->qdio
.out_qs
[card
->qdio
.do_prio_queueing
2790 || (cast_type
&& card
->info
.is_multicast_different
) ?
2791 qeth_get_priority_queue(card
, skb
, ipv
, cast_type
) :
2792 card
->qdio
.default_out_queue
];
2793 int tx_bytes
= skb
->len
;
2795 int data_offset
= -1;
2798 if (((card
->info
.type
== QETH_CARD_TYPE_IQD
) &&
2799 (((card
->options
.cq
!= QETH_CQ_ENABLED
) && !ipv
) ||
2800 ((card
->options
.cq
== QETH_CQ_ENABLED
) &&
2801 (skb
->protocol
!= ETH_P_AF_IUCV
)))) ||
2802 card
->options
.sniffer
)
2805 if ((card
->state
!= CARD_STATE_UP
) || !card
->lan_online
) {
2806 card
->stats
.tx_carrier_errors
++;
2810 if ((cast_type
== RTN_BROADCAST
) &&
2811 (card
->info
.broadcast_capable
== 0))
2814 if (card
->options
.performance_stats
) {
2815 card
->perf_stats
.outbound_cnt
++;
2816 card
->perf_stats
.outbound_start_time
= qeth_get_micros();
2819 /* Ignore segment size from skb_is_gso(), 1 page is always used. */
2820 use_tso
= skb_is_gso(skb
) &&
2821 (qeth_get_ip_protocol(skb
) == IPPROTO_TCP
) && (ipv
== 4);
2823 if ((card
->info
.type
== QETH_CARD_TYPE_IQD
) &&
2824 !skb_is_nonlinear(skb
)) {
2826 if (new_skb
->protocol
== ETH_P_AF_IUCV
)
2829 data_offset
= ETH_HLEN
;
2830 hdr
= kmem_cache_alloc(qeth_core_header_cache
, GFP_ATOMIC
);
2835 /* create a clone with writeable headroom */
2836 new_skb
= skb_realloc_headroom(skb
, sizeof(struct qeth_hdr_tso
)
2842 if (card
->info
.type
== QETH_CARD_TYPE_IQD
) {
2843 if (data_offset
< 0)
2844 skb_pull(new_skb
, ETH_HLEN
);
2847 skb_pull(new_skb
, ETH_HLEN
);
2850 if (ipv
!= 4 && skb_vlan_tag_present(new_skb
)) {
2851 skb_push(new_skb
, VLAN_HLEN
);
2852 skb_copy_to_linear_data(new_skb
, new_skb
->data
+ 4, 4);
2853 skb_copy_to_linear_data_offset(new_skb
, 4,
2854 new_skb
->data
+ 8, 4);
2855 skb_copy_to_linear_data_offset(new_skb
, 8,
2856 new_skb
->data
+ 12, 4);
2857 tag
= (u16
*)(new_skb
->data
+ 12);
2858 *tag
= __constant_htons(ETH_P_8021Q
);
2859 *(tag
+ 1) = htons(skb_vlan_tag_get(new_skb
));
2863 netif_stop_queue(dev
);
2865 /* fix hardware limitation: as long as we do not have sbal
2866 * chaining we can not send long frag lists
2868 if ((card
->info
.type
!= QETH_CARD_TYPE_IQD
) &&
2869 ((use_tso
&& !qeth_l3_get_elements_no_tso(card
, new_skb
, 1)) ||
2870 (!use_tso
&& !qeth_get_elements_no(card
, new_skb
, 0)))) {
2871 int lin_rc
= skb_linearize(new_skb
);
2873 if (card
->options
.performance_stats
) {
2875 card
->perf_stats
.tx_linfail
++;
2877 card
->perf_stats
.tx_lin
++;
2884 hdr
= (struct qeth_hdr
*)skb_push(new_skb
,
2885 sizeof(struct qeth_hdr_tso
));
2886 memset(hdr
, 0, sizeof(struct qeth_hdr_tso
));
2887 qeth_l3_fill_header(card
, hdr
, new_skb
, ipv
, cast_type
);
2888 qeth_tso_fill_header(card
, hdr
, new_skb
);
2891 if (data_offset
< 0) {
2892 hdr
= (struct qeth_hdr
*)skb_push(new_skb
,
2893 sizeof(struct qeth_hdr
));
2894 qeth_l3_fill_header(card
, hdr
, new_skb
, ipv
,
2897 if (new_skb
->protocol
== ETH_P_AF_IUCV
)
2898 qeth_l3_fill_af_iucv_hdr(card
, hdr
, new_skb
);
2900 qeth_l3_fill_header(card
, hdr
, new_skb
, ipv
,
2902 hdr
->hdr
.l3
.length
= new_skb
->len
- data_offset
;
2906 if (skb
->ip_summed
== CHECKSUM_PARTIAL
)
2907 qeth_l3_hdr_csum(card
, hdr
, new_skb
);
2910 elements
= use_tso
?
2911 qeth_l3_get_elements_no_tso(card
, new_skb
, hdr_elements
) :
2912 qeth_get_elements_no(card
, new_skb
, hdr_elements
);
2914 if (data_offset
>= 0)
2915 kmem_cache_free(qeth_core_header_cache
, hdr
);
2918 elements
+= hdr_elements
;
2920 if (card
->info
.type
!= QETH_CARD_TYPE_IQD
) {
2923 len
= ((unsigned long)tcp_hdr(new_skb
) +
2924 tcp_hdrlen(new_skb
)) -
2925 (unsigned long)new_skb
->data
;
2927 len
= sizeof(struct qeth_hdr_layer3
);
2929 if (qeth_hdr_chk_and_bounce(new_skb
, &hdr
, len
))
2931 rc
= qeth_do_send_packet(card
, queue
, new_skb
, hdr
, elements
);
2933 rc
= qeth_do_send_packet_fast(card
, queue
, new_skb
, hdr
,
2934 elements
, data_offset
, 0);
2937 card
->stats
.tx_packets
++;
2938 card
->stats
.tx_bytes
+= tx_bytes
;
2940 dev_kfree_skb_any(skb
);
2941 if (card
->options
.performance_stats
) {
2942 nr_frags
= skb_shinfo(new_skb
)->nr_frags
;
2944 card
->perf_stats
.large_send_bytes
+= tx_bytes
;
2945 card
->perf_stats
.large_send_cnt
++;
2948 card
->perf_stats
.sg_skbs_sent
++;
2949 /* nr_frags + skb->data */
2950 card
->perf_stats
.sg_frags_sent
+= nr_frags
+ 1;
2955 if (data_offset
>= 0)
2956 kmem_cache_free(qeth_core_header_cache
, hdr
);
2960 dev_kfree_skb_any(new_skb
);
2961 return NETDEV_TX_BUSY
;
2966 netif_wake_queue(dev
);
2967 if (card
->options
.performance_stats
)
2968 card
->perf_stats
.outbound_time
+= qeth_get_micros() -
2969 card
->perf_stats
.outbound_start_time
;
2973 card
->stats
.tx_dropped
++;
2974 card
->stats
.tx_errors
++;
2975 if ((new_skb
!= skb
) && new_skb
)
2976 dev_kfree_skb_any(new_skb
);
2977 dev_kfree_skb_any(skb
);
2978 netif_wake_queue(dev
);
2979 return NETDEV_TX_OK
;
2982 static int __qeth_l3_open(struct net_device
*dev
)
2984 struct qeth_card
*card
= dev
->ml_priv
;
2987 QETH_CARD_TEXT(card
, 4, "qethopen");
2988 if (card
->state
== CARD_STATE_UP
)
2990 if (card
->state
!= CARD_STATE_SOFTSETUP
)
2992 card
->data
.state
= CH_STATE_UP
;
2993 card
->state
= CARD_STATE_UP
;
2994 netif_start_queue(dev
);
2996 if (qdio_stop_irq(card
->data
.ccwdev
, 0) >= 0) {
2997 napi_enable(&card
->napi
);
2998 napi_schedule(&card
->napi
);
3004 static int qeth_l3_open(struct net_device
*dev
)
3006 struct qeth_card
*card
= dev
->ml_priv
;
3008 QETH_CARD_TEXT(card
, 5, "qethope_");
3009 if (qeth_wait_for_threads(card
, QETH_RECOVER_THREAD
)) {
3010 QETH_CARD_TEXT(card
, 3, "openREC");
3011 return -ERESTARTSYS
;
3013 return __qeth_l3_open(dev
);
3016 static int qeth_l3_stop(struct net_device
*dev
)
3018 struct qeth_card
*card
= dev
->ml_priv
;
3020 QETH_CARD_TEXT(card
, 4, "qethstop");
3021 netif_tx_disable(dev
);
3022 if (card
->state
== CARD_STATE_UP
) {
3023 card
->state
= CARD_STATE_SOFTSETUP
;
3024 napi_disable(&card
->napi
);
3029 static const struct ethtool_ops qeth_l3_ethtool_ops
= {
3030 .get_link
= ethtool_op_get_link
,
3031 .get_strings
= qeth_core_get_strings
,
3032 .get_ethtool_stats
= qeth_core_get_ethtool_stats
,
3033 .get_sset_count
= qeth_core_get_sset_count
,
3034 .get_drvinfo
= qeth_core_get_drvinfo
,
3035 .get_settings
= qeth_core_ethtool_get_settings
,
3039 * we need NOARP for IPv4 but we want neighbor solicitation for IPv6. Setting
3040 * NOARP on the netdevice is no option because it also turns off neighbor
3041 * solicitation. For IPv4 we install a neighbor_setup function. We don't want
3042 * arp resolution but we want the hard header (packet socket will work
3045 static int qeth_l3_neigh_setup_noarp(struct neighbour
*n
)
3047 n
->nud_state
= NUD_NOARP
;
3048 memcpy(n
->ha
, "FAKELL", 6);
3049 n
->output
= n
->ops
->connected_output
;
3054 qeth_l3_neigh_setup(struct net_device
*dev
, struct neigh_parms
*np
)
3056 if (np
->tbl
->family
== AF_INET
)
3057 np
->neigh_setup
= qeth_l3_neigh_setup_noarp
;
3062 static const struct net_device_ops qeth_l3_netdev_ops
= {
3063 .ndo_open
= qeth_l3_open
,
3064 .ndo_stop
= qeth_l3_stop
,
3065 .ndo_get_stats
= qeth_get_stats
,
3066 .ndo_start_xmit
= qeth_l3_hard_start_xmit
,
3067 .ndo_validate_addr
= eth_validate_addr
,
3068 .ndo_set_rx_mode
= qeth_l3_set_multicast_list
,
3069 .ndo_do_ioctl
= qeth_l3_do_ioctl
,
3070 .ndo_change_mtu
= qeth_change_mtu
,
3071 .ndo_fix_features
= qeth_fix_features
,
3072 .ndo_set_features
= qeth_set_features
,
3073 .ndo_vlan_rx_add_vid
= qeth_l3_vlan_rx_add_vid
,
3074 .ndo_vlan_rx_kill_vid
= qeth_l3_vlan_rx_kill_vid
,
3075 .ndo_tx_timeout
= qeth_tx_timeout
,
3078 static const struct net_device_ops qeth_l3_osa_netdev_ops
= {
3079 .ndo_open
= qeth_l3_open
,
3080 .ndo_stop
= qeth_l3_stop
,
3081 .ndo_get_stats
= qeth_get_stats
,
3082 .ndo_start_xmit
= qeth_l3_hard_start_xmit
,
3083 .ndo_validate_addr
= eth_validate_addr
,
3084 .ndo_set_rx_mode
= qeth_l3_set_multicast_list
,
3085 .ndo_do_ioctl
= qeth_l3_do_ioctl
,
3086 .ndo_change_mtu
= qeth_change_mtu
,
3087 .ndo_fix_features
= qeth_fix_features
,
3088 .ndo_set_features
= qeth_set_features
,
3089 .ndo_vlan_rx_add_vid
= qeth_l3_vlan_rx_add_vid
,
3090 .ndo_vlan_rx_kill_vid
= qeth_l3_vlan_rx_kill_vid
,
3091 .ndo_tx_timeout
= qeth_tx_timeout
,
3092 .ndo_neigh_setup
= qeth_l3_neigh_setup
,
3095 static int qeth_l3_setup_netdev(struct qeth_card
*card
)
3099 if (card
->info
.type
== QETH_CARD_TYPE_OSD
||
3100 card
->info
.type
== QETH_CARD_TYPE_OSX
) {
3101 if ((card
->info
.link_type
== QETH_LINK_TYPE_LANE_TR
) ||
3102 (card
->info
.link_type
== QETH_LINK_TYPE_HSTR
)) {
3103 pr_info("qeth_l3: ignoring TR device\n");
3106 card
->dev
= alloc_etherdev(0);
3109 card
->dev
->netdev_ops
= &qeth_l3_osa_netdev_ops
;
3111 /*IPv6 address autoconfiguration stuff*/
3112 qeth_l3_get_unique_id(card
);
3113 if (!(card
->info
.unique_id
& UNIQUE_ID_NOT_BY_CARD
))
3114 card
->dev
->dev_id
= card
->info
.unique_id
&
3116 if (!card
->info
.guestlan
) {
3117 card
->dev
->hw_features
= NETIF_F_SG
|
3118 NETIF_F_RXCSUM
| NETIF_F_IP_CSUM
|
3120 card
->dev
->vlan_features
= NETIF_F_SG
|
3121 NETIF_F_RXCSUM
| NETIF_F_IP_CSUM
|
3125 } else if (card
->info
.type
== QETH_CARD_TYPE_IQD
) {
3126 card
->dev
= alloc_netdev(0, "hsi%d", NET_NAME_UNKNOWN
,
3130 card
->dev
->flags
|= IFF_NOARP
;
3131 card
->dev
->netdev_ops
= &qeth_l3_netdev_ops
;
3132 rc
= qeth_l3_iqd_read_initial_mac(card
);
3135 if (card
->options
.hsuid
[0])
3136 memcpy(card
->dev
->perm_addr
, card
->options
.hsuid
, 9);
3140 card
->dev
->ml_priv
= card
;
3141 card
->dev
->watchdog_timeo
= QETH_TX_TIMEOUT
;
3142 card
->dev
->mtu
= card
->info
.initial_mtu
;
3143 card
->dev
->min_mtu
= 64;
3144 card
->dev
->max_mtu
= ETH_MAX_MTU
;
3145 card
->dev
->ethtool_ops
= &qeth_l3_ethtool_ops
;
3146 card
->dev
->features
|= NETIF_F_HW_VLAN_CTAG_TX
|
3147 NETIF_F_HW_VLAN_CTAG_RX
|
3148 NETIF_F_HW_VLAN_CTAG_FILTER
;
3149 netif_keep_dst(card
->dev
);
3150 card
->dev
->gso_max_size
= (QETH_MAX_BUFFER_ELEMENTS(card
) - 1) *
3153 SET_NETDEV_DEV(card
->dev
, &card
->gdev
->dev
);
3154 netif_napi_add(card
->dev
, &card
->napi
, qeth_l3_poll
, QETH_NAPI_WEIGHT
);
3155 netif_carrier_off(card
->dev
);
3156 return register_netdev(card
->dev
);
3159 static int qeth_l3_probe_device(struct ccwgroup_device
*gdev
)
3161 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
3163 qeth_l3_create_device_attributes(&gdev
->dev
);
3164 card
->options
.layer2
= 0;
3165 card
->info
.hwtrap
= 0;
3169 static void qeth_l3_remove_device(struct ccwgroup_device
*cgdev
)
3171 struct qeth_card
*card
= dev_get_drvdata(&cgdev
->dev
);
3173 qeth_l3_remove_device_attributes(&cgdev
->dev
);
3175 qeth_set_allowed_threads(card
, 0, 1);
3176 wait_event(card
->wait_q
, qeth_threads_running(card
, 0xffffffff) == 0);
3178 if (cgdev
->state
== CCWGROUP_ONLINE
)
3179 qeth_l3_set_offline(cgdev
);
3182 netif_napi_del(&card
->napi
);
3183 unregister_netdev(card
->dev
);
3187 qeth_l3_clear_ip_htable(card
, 0);
3188 qeth_l3_clear_ipato_list(card
);
3192 static int __qeth_l3_set_online(struct ccwgroup_device
*gdev
, int recovery_mode
)
3194 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
3196 enum qeth_card_states recover_flag
;
3198 mutex_lock(&card
->discipline_mutex
);
3199 mutex_lock(&card
->conf_mutex
);
3200 QETH_DBF_TEXT(SETUP
, 2, "setonlin");
3201 QETH_DBF_HEX(SETUP
, 2, &card
, sizeof(void *));
3203 recover_flag
= card
->state
;
3204 rc
= qeth_core_hardsetup_card(card
);
3206 QETH_DBF_TEXT_(SETUP
, 2, "2err%04x", rc
);
3211 if (!card
->dev
&& qeth_l3_setup_netdev(card
)) {
3216 if (qeth_is_diagass_supported(card
, QETH_DIAGS_CMD_TRAP
)) {
3217 if (card
->info
.hwtrap
&&
3218 qeth_hw_trap(card
, QETH_DIAGS_TRAP_ARM
))
3219 card
->info
.hwtrap
= 0;
3221 card
->info
.hwtrap
= 0;
3223 card
->state
= CARD_STATE_HARDSETUP
;
3224 memset(&card
->rx
, 0, sizeof(struct qeth_rx
));
3225 qeth_print_status_message(card
);
3228 QETH_DBF_TEXT(SETUP
, 2, "softsetp");
3230 rc
= qeth_send_startlan(card
);
3232 QETH_DBF_TEXT_(SETUP
, 2, "1err%d", rc
);
3234 dev_warn(&card
->gdev
->dev
,
3235 "The LAN is offline\n");
3236 card
->lan_online
= 0;
3242 card
->lan_online
= 1;
3245 rc
= qeth_l3_setadapter_parms(card
);
3247 QETH_DBF_TEXT_(SETUP
, 2, "2err%04x", rc
);
3248 if (!card
->options
.sniffer
) {
3249 rc
= qeth_l3_start_ipassists(card
);
3251 QETH_DBF_TEXT_(SETUP
, 2, "3err%d", rc
);
3254 rc
= qeth_l3_setrouting_v4(card
);
3256 QETH_DBF_TEXT_(SETUP
, 2, "4err%04x", rc
);
3257 rc
= qeth_l3_setrouting_v6(card
);
3259 QETH_DBF_TEXT_(SETUP
, 2, "5err%04x", rc
);
3261 netif_tx_disable(card
->dev
);
3263 rc
= qeth_init_qdio_queues(card
);
3265 QETH_DBF_TEXT_(SETUP
, 2, "6err%d", rc
);
3269 card
->state
= CARD_STATE_SOFTSETUP
;
3271 qeth_set_allowed_threads(card
, 0xffffffff, 0);
3272 qeth_l3_recover_ip(card
);
3273 if (card
->lan_online
)
3274 netif_carrier_on(card
->dev
);
3276 netif_carrier_off(card
->dev
);
3277 if (recover_flag
== CARD_STATE_RECOVER
) {
3280 __qeth_l3_open(card
->dev
);
3282 dev_open(card
->dev
);
3283 qeth_l3_set_multicast_list(card
->dev
);
3284 qeth_recover_features(card
->dev
);
3287 qeth_trace_features(card
);
3288 /* let user_space know that device is online */
3289 kobject_uevent(&gdev
->dev
.kobj
, KOBJ_CHANGE
);
3290 mutex_unlock(&card
->conf_mutex
);
3291 mutex_unlock(&card
->discipline_mutex
);
3294 qeth_l3_stop_card(card
, 0);
3295 ccw_device_set_offline(CARD_DDEV(card
));
3296 ccw_device_set_offline(CARD_WDEV(card
));
3297 ccw_device_set_offline(CARD_RDEV(card
));
3298 qdio_free(CARD_DDEV(card
));
3299 if (recover_flag
== CARD_STATE_RECOVER
)
3300 card
->state
= CARD_STATE_RECOVER
;
3302 card
->state
= CARD_STATE_DOWN
;
3303 mutex_unlock(&card
->conf_mutex
);
3304 mutex_unlock(&card
->discipline_mutex
);
3308 static int qeth_l3_set_online(struct ccwgroup_device
*gdev
)
3310 return __qeth_l3_set_online(gdev
, 0);
3313 static int __qeth_l3_set_offline(struct ccwgroup_device
*cgdev
,
3316 struct qeth_card
*card
= dev_get_drvdata(&cgdev
->dev
);
3317 int rc
= 0, rc2
= 0, rc3
= 0;
3318 enum qeth_card_states recover_flag
;
3320 mutex_lock(&card
->discipline_mutex
);
3321 mutex_lock(&card
->conf_mutex
);
3322 QETH_DBF_TEXT(SETUP
, 3, "setoffl");
3323 QETH_DBF_HEX(SETUP
, 3, &card
, sizeof(void *));
3325 if (card
->dev
&& netif_carrier_ok(card
->dev
))
3326 netif_carrier_off(card
->dev
);
3327 recover_flag
= card
->state
;
3328 if ((!recovery_mode
&& card
->info
.hwtrap
) || card
->info
.hwtrap
== 2) {
3329 qeth_hw_trap(card
, QETH_DIAGS_TRAP_DISARM
);
3330 card
->info
.hwtrap
= 1;
3332 qeth_l3_stop_card(card
, recovery_mode
);
3333 if ((card
->options
.cq
== QETH_CQ_ENABLED
) && card
->dev
) {
3335 call_netdevice_notifiers(NETDEV_REBOOT
, card
->dev
);
3338 rc
= ccw_device_set_offline(CARD_DDEV(card
));
3339 rc2
= ccw_device_set_offline(CARD_WDEV(card
));
3340 rc3
= ccw_device_set_offline(CARD_RDEV(card
));
3342 rc
= (rc2
) ? rc2
: rc3
;
3344 QETH_DBF_TEXT_(SETUP
, 2, "1err%d", rc
);
3345 qdio_free(CARD_DDEV(card
));
3346 if (recover_flag
== CARD_STATE_UP
)
3347 card
->state
= CARD_STATE_RECOVER
;
3348 /* let user_space know that device is offline */
3349 kobject_uevent(&cgdev
->dev
.kobj
, KOBJ_CHANGE
);
3350 mutex_unlock(&card
->conf_mutex
);
3351 mutex_unlock(&card
->discipline_mutex
);
3355 static int qeth_l3_set_offline(struct ccwgroup_device
*cgdev
)
3357 return __qeth_l3_set_offline(cgdev
, 0);
3360 static int qeth_l3_recover(void *ptr
)
3362 struct qeth_card
*card
;
3365 card
= (struct qeth_card
*) ptr
;
3366 QETH_CARD_TEXT(card
, 2, "recover1");
3367 QETH_CARD_HEX(card
, 2, &card
, sizeof(void *));
3368 if (!qeth_do_run_thread(card
, QETH_RECOVER_THREAD
))
3370 QETH_CARD_TEXT(card
, 2, "recover2");
3371 dev_warn(&card
->gdev
->dev
,
3372 "A recovery process has been started for the device\n");
3373 qeth_set_recovery_task(card
);
3374 __qeth_l3_set_offline(card
->gdev
, 1);
3375 rc
= __qeth_l3_set_online(card
->gdev
, 1);
3377 dev_info(&card
->gdev
->dev
,
3378 "Device successfully recovered!\n");
3380 qeth_close_dev(card
);
3381 dev_warn(&card
->gdev
->dev
, "The qeth device driver "
3382 "failed to recover an error on the device\n");
3384 qeth_clear_recovery_task(card
);
3385 qeth_clear_thread_start_bit(card
, QETH_RECOVER_THREAD
);
3386 qeth_clear_thread_running_bit(card
, QETH_RECOVER_THREAD
);
3390 static void qeth_l3_shutdown(struct ccwgroup_device
*gdev
)
3392 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
3393 qeth_set_allowed_threads(card
, 0, 1);
3394 if ((gdev
->state
== CCWGROUP_ONLINE
) && card
->info
.hwtrap
)
3395 qeth_hw_trap(card
, QETH_DIAGS_TRAP_DISARM
);
3396 qeth_qdio_clear_card(card
, 0);
3397 qeth_clear_qdio_buffers(card
);
3398 qdio_free(CARD_DDEV(card
));
3401 static int qeth_l3_pm_suspend(struct ccwgroup_device
*gdev
)
3403 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
3406 netif_device_detach(card
->dev
);
3407 qeth_set_allowed_threads(card
, 0, 1);
3408 wait_event(card
->wait_q
, qeth_threads_running(card
, 0xffffffff) == 0);
3409 if (gdev
->state
== CCWGROUP_OFFLINE
)
3411 if (card
->state
== CARD_STATE_UP
) {
3412 if (card
->info
.hwtrap
)
3413 qeth_hw_trap(card
, QETH_DIAGS_TRAP_DISARM
);
3414 __qeth_l3_set_offline(card
->gdev
, 1);
3416 __qeth_l3_set_offline(card
->gdev
, 0);
3420 static int qeth_l3_pm_resume(struct ccwgroup_device
*gdev
)
3422 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
3425 if (gdev
->state
== CCWGROUP_OFFLINE
)
3428 if (card
->state
== CARD_STATE_RECOVER
) {
3429 rc
= __qeth_l3_set_online(card
->gdev
, 1);
3432 dev_close(card
->dev
);
3436 rc
= __qeth_l3_set_online(card
->gdev
, 0);
3438 qeth_set_allowed_threads(card
, 0xffffffff, 0);
3440 netif_device_attach(card
->dev
);
3442 dev_warn(&card
->gdev
->dev
, "The qeth device driver "
3443 "failed to recover an error on the device\n");
3447 /* Returns zero if the command is successfully "consumed" */
3448 static int qeth_l3_control_event(struct qeth_card
*card
,
3449 struct qeth_ipa_cmd
*cmd
)
3454 struct qeth_discipline qeth_l3_discipline
= {
3455 .start_poll
= qeth_qdio_start_poll
,
3456 .input_handler
= (qdio_handler_t
*) qeth_qdio_input_handler
,
3457 .output_handler
= (qdio_handler_t
*) qeth_qdio_output_handler
,
3458 .recover
= qeth_l3_recover
,
3459 .setup
= qeth_l3_probe_device
,
3460 .remove
= qeth_l3_remove_device
,
3461 .set_online
= qeth_l3_set_online
,
3462 .set_offline
= qeth_l3_set_offline
,
3463 .shutdown
= qeth_l3_shutdown
,
3464 .freeze
= qeth_l3_pm_suspend
,
3465 .thaw
= qeth_l3_pm_resume
,
3466 .restore
= qeth_l3_pm_resume
,
3467 .control_event_handler
= qeth_l3_control_event
,
3469 EXPORT_SYMBOL_GPL(qeth_l3_discipline
);
3471 static int qeth_l3_ip_event(struct notifier_block
*this,
3472 unsigned long event
, void *ptr
)
3475 struct in_ifaddr
*ifa
= (struct in_ifaddr
*)ptr
;
3476 struct net_device
*dev
= (struct net_device
*)ifa
->ifa_dev
->dev
;
3477 struct qeth_ipaddr
*addr
;
3478 struct qeth_card
*card
;
3480 if (dev_net(dev
) != &init_net
)
3483 card
= qeth_l3_get_card_from_dev(dev
);
3486 QETH_CARD_TEXT(card
, 3, "ipevent");
3488 addr
= qeth_l3_get_addr_buffer(QETH_PROT_IPV4
);
3490 addr
->u
.a4
.addr
= ifa
->ifa_address
;
3491 addr
->u
.a4
.mask
= ifa
->ifa_mask
;
3492 addr
->type
= QETH_IP_TYPE_NORMAL
;
3498 spin_lock_bh(&card
->ip_lock
);
3499 qeth_l3_add_ip(card
, addr
);
3500 spin_unlock_bh(&card
->ip_lock
);
3503 spin_lock_bh(&card
->ip_lock
);
3504 qeth_l3_delete_ip(card
, addr
);
3505 spin_unlock_bh(&card
->ip_lock
);
3513 static struct notifier_block qeth_l3_ip_notifier
= {
3518 #ifdef CONFIG_QETH_IPV6
3520 * IPv6 event handler
3522 static int qeth_l3_ip6_event(struct notifier_block
*this,
3523 unsigned long event
, void *ptr
)
3525 struct inet6_ifaddr
*ifa
= (struct inet6_ifaddr
*)ptr
;
3526 struct net_device
*dev
= (struct net_device
*)ifa
->idev
->dev
;
3527 struct qeth_ipaddr
*addr
;
3528 struct qeth_card
*card
;
3530 card
= qeth_l3_get_card_from_dev(dev
);
3533 QETH_CARD_TEXT(card
, 3, "ip6event");
3534 if (!qeth_is_supported(card
, IPA_IPV6
))
3537 addr
= qeth_l3_get_addr_buffer(QETH_PROT_IPV6
);
3539 memcpy(&addr
->u
.a6
.addr
, &ifa
->addr
, sizeof(struct in6_addr
));
3540 addr
->u
.a6
.pfxlen
= ifa
->prefix_len
;
3541 addr
->type
= QETH_IP_TYPE_NORMAL
;
3547 spin_lock_bh(&card
->ip_lock
);
3548 qeth_l3_add_ip(card
, addr
);
3549 spin_unlock_bh(&card
->ip_lock
);
3552 spin_lock_bh(&card
->ip_lock
);
3553 qeth_l3_delete_ip(card
, addr
);
3554 spin_unlock_bh(&card
->ip_lock
);
3562 static struct notifier_block qeth_l3_ip6_notifier
= {
3568 static int qeth_l3_register_notifiers(void)
3572 QETH_DBF_TEXT(SETUP
, 5, "regnotif");
3573 rc
= register_inetaddr_notifier(&qeth_l3_ip_notifier
);
3576 #ifdef CONFIG_QETH_IPV6
3577 rc
= register_inet6addr_notifier(&qeth_l3_ip6_notifier
);
3579 unregister_inetaddr_notifier(&qeth_l3_ip_notifier
);
3583 pr_warn("There is no IPv6 support for the layer 3 discipline\n");
3588 static void qeth_l3_unregister_notifiers(void)
3591 QETH_DBF_TEXT(SETUP
, 5, "unregnot");
3592 WARN_ON(unregister_inetaddr_notifier(&qeth_l3_ip_notifier
));
3593 #ifdef CONFIG_QETH_IPV6
3594 WARN_ON(unregister_inet6addr_notifier(&qeth_l3_ip6_notifier
));
3595 #endif /* QETH_IPV6 */
3598 static int __init
qeth_l3_init(void)
3602 pr_info("register layer 3 discipline\n");
3603 rc
= qeth_l3_register_notifiers();
3607 static void __exit
qeth_l3_exit(void)
3609 qeth_l3_unregister_notifiers();
3610 pr_info("unregister layer 3 discipline\n");
3613 module_init(qeth_l3_init
);
3614 module_exit(qeth_l3_exit
);
3615 MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
3616 MODULE_DESCRIPTION("qeth layer 3 discipline");
3617 MODULE_LICENSE("GPL");