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 struct qeth_ipaddr
*qeth_l3_get_addr_buffer(enum qeth_prot_versions prot
)
72 struct qeth_ipaddr
*addr
= kmalloc(sizeof(*addr
), GFP_ATOMIC
);
75 qeth_l3_init_ipaddr(addr
, QETH_IP_TYPE_NORMAL
, prot
);
79 static struct qeth_ipaddr
*qeth_l3_find_addr_by_ip(struct qeth_card
*card
,
80 struct qeth_ipaddr
*query
)
82 u64 key
= qeth_l3_ipaddr_hash(query
);
83 struct qeth_ipaddr
*addr
;
85 if (query
->is_multicast
) {
86 hash_for_each_possible(card
->ip_mc_htable
, addr
, hnode
, key
)
87 if (qeth_l3_addr_match_ip(addr
, query
))
90 hash_for_each_possible(card
->ip_htable
, addr
, hnode
, key
)
91 if (qeth_l3_addr_match_ip(addr
, query
))
97 static void qeth_l3_convert_addr_to_bits(u8
*addr
, u8
*bits
, int len
)
102 for (i
= 0; i
< len
; ++i
) {
104 for (j
= 7; j
>= 0; --j
) {
105 bits
[i
*8 + j
] = octet
& 1;
111 static bool qeth_l3_is_addr_covered_by_ipato(struct qeth_card
*card
,
112 struct qeth_ipaddr
*addr
)
114 struct qeth_ipato_entry
*ipatoe
;
115 u8 addr_bits
[128] = {0, };
116 u8 ipatoe_bits
[128] = {0, };
119 if (!card
->ipato
.enabled
)
121 if (addr
->type
!= QETH_IP_TYPE_NORMAL
)
124 qeth_l3_convert_addr_to_bits((u8
*) &addr
->u
, addr_bits
,
125 (addr
->proto
== QETH_PROT_IPV4
)? 4:16);
126 list_for_each_entry(ipatoe
, &card
->ipato
.entries
, entry
) {
127 if (addr
->proto
!= ipatoe
->proto
)
129 qeth_l3_convert_addr_to_bits(ipatoe
->addr
, ipatoe_bits
,
130 (ipatoe
->proto
== QETH_PROT_IPV4
) ?
132 if (addr
->proto
== QETH_PROT_IPV4
)
133 rc
= !memcmp(addr_bits
, ipatoe_bits
,
134 min(32, ipatoe
->mask_bits
));
136 rc
= !memcmp(addr_bits
, ipatoe_bits
,
137 min(128, ipatoe
->mask_bits
));
142 if ((addr
->proto
== QETH_PROT_IPV4
) && card
->ipato
.invert4
)
144 else if ((addr
->proto
== QETH_PROT_IPV6
) && card
->ipato
.invert6
)
150 static int qeth_l3_delete_ip(struct qeth_card
*card
,
151 struct qeth_ipaddr
*tmp_addr
)
154 struct qeth_ipaddr
*addr
;
156 if (tmp_addr
->type
== QETH_IP_TYPE_RXIP
)
157 QETH_CARD_TEXT(card
, 2, "delrxip");
158 else if (tmp_addr
->type
== QETH_IP_TYPE_VIPA
)
159 QETH_CARD_TEXT(card
, 2, "delvipa");
161 QETH_CARD_TEXT(card
, 2, "delip");
163 if (tmp_addr
->proto
== QETH_PROT_IPV4
)
164 QETH_CARD_HEX(card
, 4, &tmp_addr
->u
.a4
.addr
, 4);
166 QETH_CARD_HEX(card
, 4, &tmp_addr
->u
.a6
.addr
, 8);
167 QETH_CARD_HEX(card
, 4, ((char *)&tmp_addr
->u
.a6
.addr
) + 8, 8);
170 addr
= qeth_l3_find_addr_by_ip(card
, tmp_addr
);
171 if (!addr
|| !qeth_l3_addr_match_all(addr
, tmp_addr
))
175 if (addr
->type
== QETH_IP_TYPE_NORMAL
&& addr
->ref_counter
> 0)
177 if (addr
->in_progress
)
180 if (qeth_card_hw_is_reachable(card
))
181 rc
= qeth_l3_deregister_addr_entry(card
, addr
);
183 hash_del(&addr
->hnode
);
189 static int qeth_l3_add_ip(struct qeth_card
*card
, struct qeth_ipaddr
*tmp_addr
)
192 struct qeth_ipaddr
*addr
;
195 if (tmp_addr
->type
== QETH_IP_TYPE_RXIP
)
196 QETH_CARD_TEXT(card
, 2, "addrxip");
197 else if (tmp_addr
->type
== QETH_IP_TYPE_VIPA
)
198 QETH_CARD_TEXT(card
, 2, "addvipa");
200 QETH_CARD_TEXT(card
, 2, "addip");
202 if (tmp_addr
->proto
== QETH_PROT_IPV4
)
203 QETH_CARD_HEX(card
, 4, &tmp_addr
->u
.a4
.addr
, 4);
205 QETH_CARD_HEX(card
, 4, &tmp_addr
->u
.a6
.addr
, 8);
206 QETH_CARD_HEX(card
, 4, ((char *)&tmp_addr
->u
.a6
.addr
) + 8, 8);
209 addr
= qeth_l3_find_addr_by_ip(card
, tmp_addr
);
211 if (tmp_addr
->type
!= QETH_IP_TYPE_NORMAL
)
213 if (qeth_l3_addr_match_all(addr
, tmp_addr
)) {
217 qeth_l3_ipaddr_to_string(tmp_addr
->proto
, (u8
*)&tmp_addr
->u
,
219 dev_warn(&card
->gdev
->dev
,
220 "Registering IP address %s failed\n", buf
);
223 addr
= qeth_l3_get_addr_buffer(tmp_addr
->proto
);
227 memcpy(addr
, tmp_addr
, sizeof(struct qeth_ipaddr
));
228 addr
->ref_counter
= 1;
230 if (qeth_l3_is_addr_covered_by_ipato(card
, addr
)) {
231 QETH_CARD_TEXT(card
, 2, "tkovaddr");
234 hash_add(card
->ip_htable
, &addr
->hnode
,
235 qeth_l3_ipaddr_hash(addr
));
237 if (!qeth_card_hw_is_reachable(card
)) {
238 addr
->disp_flag
= QETH_DISP_ADDR_ADD
;
242 /* qeth_l3_register_addr_entry can go to sleep
243 * if we add a IPV4 addr. It is caused by the reason
244 * that SETIP ipa cmd starts ARP staff for IPV4 addr.
245 * Thus we should unlock spinlock, and make a protection
246 * using in_progress variable to indicate that there is
247 * an hardware operation with this IPV4 address
249 if (addr
->proto
== QETH_PROT_IPV4
) {
250 addr
->in_progress
= 1;
251 spin_unlock_bh(&card
->ip_lock
);
252 rc
= qeth_l3_register_addr_entry(card
, addr
);
253 spin_lock_bh(&card
->ip_lock
);
254 addr
->in_progress
= 0;
256 rc
= qeth_l3_register_addr_entry(card
, addr
);
258 if (!rc
|| (rc
== IPA_RC_DUPLICATE_IP_ADDRESS
) ||
259 (rc
== IPA_RC_LAN_OFFLINE
)) {
260 addr
->disp_flag
= QETH_DISP_ADDR_DO_NOTHING
;
261 if (addr
->ref_counter
< 1) {
262 qeth_l3_deregister_addr_entry(card
, addr
);
263 hash_del(&addr
->hnode
);
267 hash_del(&addr
->hnode
);
274 static void qeth_l3_clear_ip_htable(struct qeth_card
*card
, int recover
)
276 struct qeth_ipaddr
*addr
;
277 struct hlist_node
*tmp
;
280 QETH_CARD_TEXT(card
, 4, "clearip");
282 if (recover
&& card
->options
.sniffer
)
285 spin_lock_bh(&card
->ip_lock
);
287 hash_for_each_safe(card
->ip_htable
, i
, tmp
, addr
, hnode
) {
289 hash_del(&addr
->hnode
);
293 addr
->disp_flag
= QETH_DISP_ADDR_ADD
;
296 spin_unlock_bh(&card
->ip_lock
);
298 spin_lock_bh(&card
->mclock
);
300 hash_for_each_safe(card
->ip_mc_htable
, i
, tmp
, addr
, hnode
) {
301 hash_del(&addr
->hnode
);
305 spin_unlock_bh(&card
->mclock
);
309 static void qeth_l3_recover_ip(struct qeth_card
*card
)
311 struct qeth_ipaddr
*addr
;
312 struct hlist_node
*tmp
;
316 QETH_CARD_TEXT(card
, 4, "recovrip");
318 spin_lock_bh(&card
->ip_lock
);
320 hash_for_each_safe(card
->ip_htable
, i
, tmp
, addr
, hnode
) {
321 if (addr
->disp_flag
== QETH_DISP_ADDR_ADD
) {
322 if (addr
->proto
== QETH_PROT_IPV4
) {
323 addr
->in_progress
= 1;
324 spin_unlock_bh(&card
->ip_lock
);
325 rc
= qeth_l3_register_addr_entry(card
, addr
);
326 spin_lock_bh(&card
->ip_lock
);
327 addr
->in_progress
= 0;
329 rc
= qeth_l3_register_addr_entry(card
, addr
);
332 addr
->disp_flag
= QETH_DISP_ADDR_DO_NOTHING
;
333 if (addr
->ref_counter
< 1)
334 qeth_l3_delete_ip(card
, addr
);
336 hash_del(&addr
->hnode
);
342 spin_unlock_bh(&card
->ip_lock
);
346 static int qeth_l3_send_setdelmc(struct qeth_card
*card
,
347 struct qeth_ipaddr
*addr
, int ipacmd
)
350 struct qeth_cmd_buffer
*iob
;
351 struct qeth_ipa_cmd
*cmd
;
353 QETH_CARD_TEXT(card
, 4, "setdelmc");
355 iob
= qeth_get_ipacmd_buffer(card
, ipacmd
, addr
->proto
);
358 cmd
= __ipa_cmd(iob
);
359 ether_addr_copy(cmd
->data
.setdelipm
.mac
, addr
->mac
);
360 if (addr
->proto
== QETH_PROT_IPV6
)
361 memcpy(cmd
->data
.setdelipm
.ip6
, &addr
->u
.a6
.addr
,
362 sizeof(struct in6_addr
));
364 memcpy(&cmd
->data
.setdelipm
.ip4
, &addr
->u
.a4
.addr
, 4);
366 rc
= qeth_send_ipa_cmd(card
, iob
, NULL
, NULL
);
371 static void qeth_l3_fill_netmask(u8
*netmask
, unsigned int len
)
374 for (i
= 0; i
< 16; i
++) {
379 netmask
[i
] = (u8
)(0xFF00 >> j
);
385 static u32
qeth_l3_get_setdelip_flags(struct qeth_ipaddr
*addr
, bool set
)
387 switch (addr
->type
) {
388 case QETH_IP_TYPE_RXIP
:
389 return (set
) ? QETH_IPA_SETIP_TAKEOVER_FLAG
: 0;
390 case QETH_IP_TYPE_VIPA
:
391 return (set
) ? QETH_IPA_SETIP_VIPA_FLAG
:
392 QETH_IPA_DELIP_VIPA_FLAG
;
394 return (set
&& addr
->ipato
) ? QETH_IPA_SETIP_TAKEOVER_FLAG
: 0;
398 static int qeth_l3_send_setdelip(struct qeth_card
*card
,
399 struct qeth_ipaddr
*addr
,
400 enum qeth_ipa_cmds ipacmd
)
402 struct qeth_cmd_buffer
*iob
;
403 struct qeth_ipa_cmd
*cmd
;
407 QETH_CARD_TEXT(card
, 4, "setdelip");
409 iob
= qeth_get_ipacmd_buffer(card
, ipacmd
, addr
->proto
);
412 cmd
= __ipa_cmd(iob
);
414 flags
= qeth_l3_get_setdelip_flags(addr
, ipacmd
== IPA_CMD_SETIP
);
415 QETH_CARD_TEXT_(card
, 4, "flags%02X", flags
);
417 if (addr
->proto
== QETH_PROT_IPV6
) {
418 memcpy(cmd
->data
.setdelip6
.ip_addr
, &addr
->u
.a6
.addr
,
419 sizeof(struct in6_addr
));
420 qeth_l3_fill_netmask(netmask
, addr
->u
.a6
.pfxlen
);
421 memcpy(cmd
->data
.setdelip6
.mask
, netmask
,
422 sizeof(struct in6_addr
));
423 cmd
->data
.setdelip6
.flags
= flags
;
425 memcpy(cmd
->data
.setdelip4
.ip_addr
, &addr
->u
.a4
.addr
, 4);
426 memcpy(cmd
->data
.setdelip4
.mask
, &addr
->u
.a4
.mask
, 4);
427 cmd
->data
.setdelip4
.flags
= flags
;
430 return qeth_send_ipa_cmd(card
, iob
, NULL
, NULL
);
433 static int qeth_l3_send_setrouting(struct qeth_card
*card
,
434 enum qeth_routing_types type
, enum qeth_prot_versions prot
)
437 struct qeth_ipa_cmd
*cmd
;
438 struct qeth_cmd_buffer
*iob
;
440 QETH_CARD_TEXT(card
, 4, "setroutg");
441 iob
= qeth_get_ipacmd_buffer(card
, IPA_CMD_SETRTG
, prot
);
444 cmd
= __ipa_cmd(iob
);
445 cmd
->data
.setrtg
.type
= (type
);
446 rc
= qeth_send_ipa_cmd(card
, iob
, NULL
, NULL
);
451 static int qeth_l3_correct_routing_type(struct qeth_card
*card
,
452 enum qeth_routing_types
*type
, enum qeth_prot_versions prot
)
454 if (card
->info
.type
== QETH_CARD_TYPE_IQD
) {
457 case PRIMARY_CONNECTOR
:
458 case SECONDARY_CONNECTOR
:
459 case MULTICAST_ROUTER
:
468 case SECONDARY_ROUTER
:
470 case MULTICAST_ROUTER
:
471 if (qeth_is_ipafunc_supported(card
, prot
,
483 int qeth_l3_setrouting_v4(struct qeth_card
*card
)
487 QETH_CARD_TEXT(card
, 3, "setrtg4");
489 rc
= qeth_l3_correct_routing_type(card
, &card
->options
.route4
.type
,
494 rc
= qeth_l3_send_setrouting(card
, card
->options
.route4
.type
,
497 card
->options
.route4
.type
= NO_ROUTER
;
498 QETH_DBF_MESSAGE(2, "Error (0x%04x) while setting routing type"
499 " on %s. Type set to 'no router'.\n", rc
,
500 QETH_CARD_IFNAME(card
));
505 int qeth_l3_setrouting_v6(struct qeth_card
*card
)
509 QETH_CARD_TEXT(card
, 3, "setrtg6");
511 if (!qeth_is_supported(card
, IPA_IPV6
))
513 rc
= qeth_l3_correct_routing_type(card
, &card
->options
.route6
.type
,
518 rc
= qeth_l3_send_setrouting(card
, card
->options
.route6
.type
,
521 card
->options
.route6
.type
= NO_ROUTER
;
522 QETH_DBF_MESSAGE(2, "Error (0x%04x) while setting routing type"
523 " on %s. Type set to 'no router'.\n", rc
,
524 QETH_CARD_IFNAME(card
));
530 * IP address takeover related functions
534 * qeth_l3_update_ipato() - Update 'takeover' property, for all NORMAL IPs.
536 * Caller must hold ip_lock.
538 void qeth_l3_update_ipato(struct qeth_card
*card
)
540 struct qeth_ipaddr
*addr
;
543 hash_for_each(card
->ip_htable
, i
, addr
, hnode
) {
544 if (addr
->type
!= QETH_IP_TYPE_NORMAL
)
546 addr
->ipato
= qeth_l3_is_addr_covered_by_ipato(card
, addr
);
550 static void qeth_l3_clear_ipato_list(struct qeth_card
*card
)
552 struct qeth_ipato_entry
*ipatoe
, *tmp
;
554 spin_lock_bh(&card
->ip_lock
);
556 list_for_each_entry_safe(ipatoe
, tmp
, &card
->ipato
.entries
, entry
) {
557 list_del(&ipatoe
->entry
);
561 qeth_l3_update_ipato(card
);
562 spin_unlock_bh(&card
->ip_lock
);
565 int qeth_l3_add_ipato_entry(struct qeth_card
*card
,
566 struct qeth_ipato_entry
*new)
568 struct qeth_ipato_entry
*ipatoe
;
571 QETH_CARD_TEXT(card
, 2, "addipato");
573 spin_lock_bh(&card
->ip_lock
);
575 list_for_each_entry(ipatoe
, &card
->ipato
.entries
, entry
) {
576 if (ipatoe
->proto
!= new->proto
)
578 if (!memcmp(ipatoe
->addr
, new->addr
,
579 (ipatoe
->proto
== QETH_PROT_IPV4
)? 4:16) &&
580 (ipatoe
->mask_bits
== new->mask_bits
)) {
587 list_add_tail(&new->entry
, &card
->ipato
.entries
);
588 qeth_l3_update_ipato(card
);
591 spin_unlock_bh(&card
->ip_lock
);
596 int qeth_l3_del_ipato_entry(struct qeth_card
*card
,
597 enum qeth_prot_versions proto
, u8
*addr
,
600 struct qeth_ipato_entry
*ipatoe
, *tmp
;
603 QETH_CARD_TEXT(card
, 2, "delipato");
605 spin_lock_bh(&card
->ip_lock
);
607 list_for_each_entry_safe(ipatoe
, tmp
, &card
->ipato
.entries
, entry
) {
608 if (ipatoe
->proto
!= proto
)
610 if (!memcmp(ipatoe
->addr
, addr
,
611 (proto
== QETH_PROT_IPV4
)? 4:16) &&
612 (ipatoe
->mask_bits
== mask_bits
)) {
613 list_del(&ipatoe
->entry
);
614 qeth_l3_update_ipato(card
);
620 spin_unlock_bh(&card
->ip_lock
);
624 int qeth_l3_modify_rxip_vipa(struct qeth_card
*card
, bool add
, const u8
*ip
,
625 enum qeth_ip_types type
,
626 enum qeth_prot_versions proto
)
628 struct qeth_ipaddr addr
;
631 qeth_l3_init_ipaddr(&addr
, type
, proto
);
632 if (proto
== QETH_PROT_IPV4
)
633 memcpy(&addr
.u
.a4
.addr
, ip
, 4);
635 memcpy(&addr
.u
.a6
.addr
, ip
, 16);
637 spin_lock_bh(&card
->ip_lock
);
638 rc
= add
? qeth_l3_add_ip(card
, &addr
) : qeth_l3_delete_ip(card
, &addr
);
639 spin_unlock_bh(&card
->ip_lock
);
643 int qeth_l3_modify_hsuid(struct qeth_card
*card
, bool add
)
645 struct qeth_ipaddr addr
;
648 qeth_l3_init_ipaddr(&addr
, QETH_IP_TYPE_NORMAL
, QETH_PROT_IPV6
);
649 addr
.u
.a6
.addr
.s6_addr
[0] = 0xfe;
650 addr
.u
.a6
.addr
.s6_addr
[1] = 0x80;
651 for (i
= 0; i
< 8; i
++)
652 addr
.u
.a6
.addr
.s6_addr
[8+i
] = card
->options
.hsuid
[i
];
654 spin_lock_bh(&card
->ip_lock
);
655 rc
= add
? qeth_l3_add_ip(card
, &addr
) : qeth_l3_delete_ip(card
, &addr
);
656 spin_unlock_bh(&card
->ip_lock
);
660 static int qeth_l3_register_addr_entry(struct qeth_card
*card
,
661 struct qeth_ipaddr
*addr
)
668 if (addr
->proto
== QETH_PROT_IPV4
) {
669 QETH_CARD_TEXT(card
, 2, "setaddr4");
670 QETH_CARD_HEX(card
, 3, &addr
->u
.a4
.addr
, sizeof(int));
671 } else if (addr
->proto
== QETH_PROT_IPV6
) {
672 QETH_CARD_TEXT(card
, 2, "setaddr6");
673 QETH_CARD_HEX(card
, 3, &addr
->u
.a6
.addr
, 8);
674 QETH_CARD_HEX(card
, 3, ((char *)&addr
->u
.a6
.addr
) + 8, 8);
676 QETH_CARD_TEXT(card
, 2, "setaddr?");
677 QETH_CARD_HEX(card
, 3, addr
, sizeof(struct qeth_ipaddr
));
680 if (addr
->is_multicast
)
681 rc
= qeth_l3_send_setdelmc(card
, addr
, IPA_CMD_SETIPM
);
683 rc
= qeth_l3_send_setdelip(card
, addr
, IPA_CMD_SETIP
);
685 QETH_CARD_TEXT(card
, 2, "failed");
686 } while ((--cnt
> 0) && rc
);
688 QETH_CARD_TEXT(card
, 2, "FAILED");
689 qeth_l3_ipaddr_to_string(addr
->proto
, (u8
*)&addr
->u
, buf
);
690 dev_warn(&card
->gdev
->dev
,
691 "Registering IP address %s failed\n", buf
);
696 static int qeth_l3_deregister_addr_entry(struct qeth_card
*card
,
697 struct qeth_ipaddr
*addr
)
701 if (addr
->proto
== QETH_PROT_IPV4
) {
702 QETH_CARD_TEXT(card
, 2, "deladdr4");
703 QETH_CARD_HEX(card
, 3, &addr
->u
.a4
.addr
, sizeof(int));
704 } else if (addr
->proto
== QETH_PROT_IPV6
) {
705 QETH_CARD_TEXT(card
, 2, "deladdr6");
706 QETH_CARD_HEX(card
, 3, &addr
->u
.a6
.addr
, 8);
707 QETH_CARD_HEX(card
, 3, ((char *)&addr
->u
.a6
.addr
) + 8, 8);
709 QETH_CARD_TEXT(card
, 2, "deladdr?");
710 QETH_CARD_HEX(card
, 3, addr
, sizeof(struct qeth_ipaddr
));
712 if (addr
->is_multicast
)
713 rc
= qeth_l3_send_setdelmc(card
, addr
, IPA_CMD_DELIPM
);
715 rc
= qeth_l3_send_setdelip(card
, addr
, IPA_CMD_DELIP
);
717 QETH_CARD_TEXT(card
, 2, "failed");
722 static int qeth_l3_setadapter_parms(struct qeth_card
*card
)
726 QETH_DBF_TEXT(SETUP
, 2, "setadprm");
728 if (qeth_adp_supported(card
, IPA_SETADP_ALTER_MAC_ADDRESS
)) {
729 rc
= qeth_setadpparms_change_macaddr(card
);
731 dev_warn(&card
->gdev
->dev
, "Reading the adapter MAC"
732 " address failed\n");
738 static int qeth_l3_start_ipa_arp_processing(struct qeth_card
*card
)
742 QETH_CARD_TEXT(card
, 3, "ipaarp");
744 if (!qeth_is_supported(card
, IPA_ARP_PROCESSING
)) {
745 dev_info(&card
->gdev
->dev
,
746 "ARP processing not supported on %s!\n",
747 QETH_CARD_IFNAME(card
));
750 rc
= qeth_send_simple_setassparms(card
, IPA_ARP_PROCESSING
,
751 IPA_CMD_ASS_START
, 0);
753 dev_warn(&card
->gdev
->dev
,
754 "Starting ARP processing support for %s failed\n",
755 QETH_CARD_IFNAME(card
));
760 static int qeth_l3_start_ipa_source_mac(struct qeth_card
*card
)
764 QETH_CARD_TEXT(card
, 3, "stsrcmac");
766 if (!qeth_is_supported(card
, IPA_SOURCE_MAC
)) {
767 dev_info(&card
->gdev
->dev
,
768 "Inbound source MAC-address not supported on %s\n",
769 QETH_CARD_IFNAME(card
));
773 rc
= qeth_send_simple_setassparms(card
, IPA_SOURCE_MAC
,
774 IPA_CMD_ASS_START
, 0);
776 dev_warn(&card
->gdev
->dev
,
777 "Starting source MAC-address support for %s failed\n",
778 QETH_CARD_IFNAME(card
));
782 static int qeth_l3_start_ipa_vlan(struct qeth_card
*card
)
786 QETH_CARD_TEXT(card
, 3, "strtvlan");
788 if (!qeth_is_supported(card
, IPA_FULL_VLAN
)) {
789 dev_info(&card
->gdev
->dev
,
790 "VLAN not supported on %s\n", QETH_CARD_IFNAME(card
));
794 rc
= qeth_send_simple_setassparms(card
, IPA_VLAN_PRIO
,
795 IPA_CMD_ASS_START
, 0);
797 dev_warn(&card
->gdev
->dev
,
798 "Starting VLAN support for %s failed\n",
799 QETH_CARD_IFNAME(card
));
801 dev_info(&card
->gdev
->dev
, "VLAN enabled\n");
806 static int qeth_l3_start_ipa_multicast(struct qeth_card
*card
)
810 QETH_CARD_TEXT(card
, 3, "stmcast");
812 if (!qeth_is_supported(card
, IPA_MULTICASTING
)) {
813 dev_info(&card
->gdev
->dev
,
814 "Multicast not supported on %s\n",
815 QETH_CARD_IFNAME(card
));
819 rc
= qeth_send_simple_setassparms(card
, IPA_MULTICASTING
,
820 IPA_CMD_ASS_START
, 0);
822 dev_warn(&card
->gdev
->dev
,
823 "Starting multicast support for %s failed\n",
824 QETH_CARD_IFNAME(card
));
826 dev_info(&card
->gdev
->dev
, "Multicast enabled\n");
827 card
->dev
->flags
|= IFF_MULTICAST
;
832 static int qeth_l3_softsetup_ipv6(struct qeth_card
*card
)
836 QETH_CARD_TEXT(card
, 3, "softipv6");
838 if (card
->info
.type
== QETH_CARD_TYPE_IQD
)
841 rc
= qeth_send_simple_setassparms(card
, IPA_IPV6
,
842 IPA_CMD_ASS_START
, 3);
844 dev_err(&card
->gdev
->dev
,
845 "Activating IPv6 support for %s failed\n",
846 QETH_CARD_IFNAME(card
));
849 rc
= qeth_send_simple_setassparms_v6(card
, IPA_IPV6
,
850 IPA_CMD_ASS_START
, 0);
852 dev_err(&card
->gdev
->dev
,
853 "Activating IPv6 support for %s failed\n",
854 QETH_CARD_IFNAME(card
));
857 rc
= qeth_send_simple_setassparms_v6(card
, IPA_PASSTHRU
,
858 IPA_CMD_ASS_START
, 0);
860 dev_warn(&card
->gdev
->dev
,
861 "Enabling the passthrough mode for %s failed\n",
862 QETH_CARD_IFNAME(card
));
866 dev_info(&card
->gdev
->dev
, "IPV6 enabled\n");
870 static int qeth_l3_start_ipa_ipv6(struct qeth_card
*card
)
872 QETH_CARD_TEXT(card
, 3, "strtipv6");
874 if (!qeth_is_supported(card
, IPA_IPV6
)) {
875 dev_info(&card
->gdev
->dev
,
876 "IPv6 not supported on %s\n", QETH_CARD_IFNAME(card
));
879 return qeth_l3_softsetup_ipv6(card
);
882 static int qeth_l3_start_ipa_broadcast(struct qeth_card
*card
)
886 QETH_CARD_TEXT(card
, 3, "stbrdcst");
887 card
->info
.broadcast_capable
= 0;
888 if (!qeth_is_supported(card
, IPA_FILTERING
)) {
889 dev_info(&card
->gdev
->dev
,
890 "Broadcast not supported on %s\n",
891 QETH_CARD_IFNAME(card
));
895 rc
= qeth_send_simple_setassparms(card
, IPA_FILTERING
,
896 IPA_CMD_ASS_START
, 0);
898 dev_warn(&card
->gdev
->dev
, "Enabling broadcast filtering for "
899 "%s failed\n", QETH_CARD_IFNAME(card
));
903 rc
= qeth_send_simple_setassparms(card
, IPA_FILTERING
,
904 IPA_CMD_ASS_CONFIGURE
, 1);
906 dev_warn(&card
->gdev
->dev
,
907 "Setting up broadcast filtering for %s failed\n",
908 QETH_CARD_IFNAME(card
));
911 card
->info
.broadcast_capable
= QETH_BROADCAST_WITH_ECHO
;
912 dev_info(&card
->gdev
->dev
, "Broadcast enabled\n");
913 rc
= qeth_send_simple_setassparms(card
, IPA_FILTERING
,
914 IPA_CMD_ASS_ENABLE
, 1);
916 dev_warn(&card
->gdev
->dev
, "Setting up broadcast echo "
917 "filtering for %s failed\n", QETH_CARD_IFNAME(card
));
920 card
->info
.broadcast_capable
= QETH_BROADCAST_WITHOUT_ECHO
;
922 if (card
->info
.broadcast_capable
)
923 card
->dev
->flags
|= IFF_BROADCAST
;
925 card
->dev
->flags
&= ~IFF_BROADCAST
;
929 static int qeth_l3_start_ipassists(struct qeth_card
*card
)
931 QETH_CARD_TEXT(card
, 3, "strtipas");
933 if (qeth_set_access_ctrl_online(card
, 0))
935 qeth_l3_start_ipa_arp_processing(card
); /* go on*/
936 qeth_l3_start_ipa_source_mac(card
); /* go on*/
937 qeth_l3_start_ipa_vlan(card
); /* go on*/
938 qeth_l3_start_ipa_multicast(card
); /* go on*/
939 qeth_l3_start_ipa_ipv6(card
); /* go on*/
940 qeth_l3_start_ipa_broadcast(card
); /* go on*/
944 static int qeth_l3_iqd_read_initial_mac_cb(struct qeth_card
*card
,
945 struct qeth_reply
*reply
, unsigned long data
)
947 struct qeth_ipa_cmd
*cmd
;
949 cmd
= (struct qeth_ipa_cmd
*) data
;
950 if (cmd
->hdr
.return_code
== 0)
951 ether_addr_copy(card
->dev
->dev_addr
,
952 cmd
->data
.create_destroy_addr
.unique_id
);
954 eth_random_addr(card
->dev
->dev_addr
);
959 static int qeth_l3_iqd_read_initial_mac(struct qeth_card
*card
)
962 struct qeth_cmd_buffer
*iob
;
963 struct qeth_ipa_cmd
*cmd
;
965 QETH_DBF_TEXT(SETUP
, 2, "hsrmac");
967 iob
= qeth_get_ipacmd_buffer(card
, IPA_CMD_CREATE_ADDR
,
971 cmd
= __ipa_cmd(iob
);
972 *((__u16
*) &cmd
->data
.create_destroy_addr
.unique_id
[6]) =
973 card
->info
.unique_id
;
975 rc
= qeth_send_ipa_cmd(card
, iob
, qeth_l3_iqd_read_initial_mac_cb
,
980 static int qeth_l3_get_unique_id_cb(struct qeth_card
*card
,
981 struct qeth_reply
*reply
, unsigned long data
)
983 struct qeth_ipa_cmd
*cmd
;
985 cmd
= (struct qeth_ipa_cmd
*) data
;
986 if (cmd
->hdr
.return_code
== 0)
987 card
->info
.unique_id
= *((__u16
*)
988 &cmd
->data
.create_destroy_addr
.unique_id
[6]);
990 card
->info
.unique_id
= UNIQUE_ID_IF_CREATE_ADDR_FAILED
|
991 UNIQUE_ID_NOT_BY_CARD
;
992 dev_warn(&card
->gdev
->dev
, "The network adapter failed to "
993 "generate a unique ID\n");
998 static int qeth_l3_get_unique_id(struct qeth_card
*card
)
1001 struct qeth_cmd_buffer
*iob
;
1002 struct qeth_ipa_cmd
*cmd
;
1004 QETH_DBF_TEXT(SETUP
, 2, "guniqeid");
1006 if (!qeth_is_supported(card
, IPA_IPV6
)) {
1007 card
->info
.unique_id
= UNIQUE_ID_IF_CREATE_ADDR_FAILED
|
1008 UNIQUE_ID_NOT_BY_CARD
;
1012 iob
= qeth_get_ipacmd_buffer(card
, IPA_CMD_CREATE_ADDR
,
1016 cmd
= __ipa_cmd(iob
);
1017 *((__u16
*) &cmd
->data
.create_destroy_addr
.unique_id
[6]) =
1018 card
->info
.unique_id
;
1020 rc
= qeth_send_ipa_cmd(card
, iob
, qeth_l3_get_unique_id_cb
, NULL
);
1025 qeth_diags_trace_cb(struct qeth_card
*card
, struct qeth_reply
*reply
,
1028 struct qeth_ipa_cmd
*cmd
;
1031 QETH_DBF_TEXT(SETUP
, 2, "diastrcb");
1033 cmd
= (struct qeth_ipa_cmd
*)data
;
1034 rc
= cmd
->hdr
.return_code
;
1036 QETH_CARD_TEXT_(card
, 2, "dxter%x", rc
);
1037 switch (cmd
->data
.diagass
.action
) {
1038 case QETH_DIAGS_CMD_TRACE_QUERY
:
1040 case QETH_DIAGS_CMD_TRACE_DISABLE
:
1043 case IPA_RC_INVALID_SUBCMD
:
1044 card
->info
.promisc_mode
= SET_PROMISC_MODE_OFF
;
1045 dev_info(&card
->gdev
->dev
, "The HiperSockets network "
1046 "traffic analyzer is deactivated\n");
1052 case QETH_DIAGS_CMD_TRACE_ENABLE
:
1055 card
->info
.promisc_mode
= SET_PROMISC_MODE_ON
;
1056 dev_info(&card
->gdev
->dev
, "The HiperSockets network "
1057 "traffic analyzer is activated\n");
1059 case IPA_RC_HARDWARE_AUTH_ERROR
:
1060 dev_warn(&card
->gdev
->dev
, "The device is not "
1061 "authorized to run as a HiperSockets network "
1062 "traffic analyzer\n");
1064 case IPA_RC_TRACE_ALREADY_ACTIVE
:
1065 dev_warn(&card
->gdev
->dev
, "A HiperSockets "
1066 "network traffic analyzer is already "
1067 "active in the HiperSockets LAN\n");
1074 QETH_DBF_MESSAGE(2, "Unknown sniffer action (0x%04x) on %s\n",
1075 cmd
->data
.diagass
.action
, QETH_CARD_IFNAME(card
));
1082 qeth_diags_trace(struct qeth_card
*card
, enum qeth_diags_trace_cmds diags_cmd
)
1084 struct qeth_cmd_buffer
*iob
;
1085 struct qeth_ipa_cmd
*cmd
;
1087 QETH_DBF_TEXT(SETUP
, 2, "diagtrac");
1089 iob
= qeth_get_ipacmd_buffer(card
, IPA_CMD_SET_DIAG_ASS
, 0);
1092 cmd
= __ipa_cmd(iob
);
1093 cmd
->data
.diagass
.subcmd_len
= 16;
1094 cmd
->data
.diagass
.subcmd
= QETH_DIAGS_CMD_TRACE
;
1095 cmd
->data
.diagass
.type
= QETH_DIAGS_TYPE_HIPERSOCKET
;
1096 cmd
->data
.diagass
.action
= diags_cmd
;
1097 return qeth_send_ipa_cmd(card
, iob
, qeth_diags_trace_cb
, NULL
);
1101 qeth_l3_add_mc_to_hash(struct qeth_card
*card
, struct in_device
*in4_dev
)
1103 struct ip_mc_list
*im4
;
1104 struct qeth_ipaddr
*tmp
, *ipm
;
1106 QETH_CARD_TEXT(card
, 4, "addmc");
1108 tmp
= qeth_l3_get_addr_buffer(QETH_PROT_IPV4
);
1112 for (im4
= rcu_dereference(in4_dev
->mc_list
); im4
!= NULL
;
1113 im4
= rcu_dereference(im4
->next_rcu
)) {
1114 ip_eth_mc_map(im4
->multiaddr
, tmp
->mac
);
1115 tmp
->u
.a4
.addr
= be32_to_cpu(im4
->multiaddr
);
1116 tmp
->is_multicast
= 1;
1118 ipm
= qeth_l3_find_addr_by_ip(card
, tmp
);
1120 /* for mcast, by-IP match means full match */
1121 ipm
->disp_flag
= QETH_DISP_ADDR_DO_NOTHING
;
1123 ipm
= qeth_l3_get_addr_buffer(QETH_PROT_IPV4
);
1126 ether_addr_copy(ipm
->mac
, tmp
->mac
);
1127 ipm
->u
.a4
.addr
= be32_to_cpu(im4
->multiaddr
);
1128 ipm
->is_multicast
= 1;
1129 ipm
->disp_flag
= QETH_DISP_ADDR_ADD
;
1130 hash_add(card
->ip_mc_htable
,
1131 &ipm
->hnode
, qeth_l3_ipaddr_hash(ipm
));
1138 /* called with rcu_read_lock */
1139 static void qeth_l3_add_vlan_mc(struct qeth_card
*card
)
1141 struct in_device
*in_dev
;
1144 QETH_CARD_TEXT(card
, 4, "addmcvl");
1146 if (!qeth_is_supported(card
, IPA_FULL_VLAN
))
1149 for_each_set_bit(vid
, card
->active_vlans
, VLAN_N_VID
) {
1150 struct net_device
*netdev
;
1152 netdev
= __vlan_find_dev_deep_rcu(card
->dev
, htons(ETH_P_8021Q
),
1154 if (netdev
== NULL
||
1155 !(netdev
->flags
& IFF_UP
))
1157 in_dev
= __in_dev_get_rcu(netdev
);
1160 qeth_l3_add_mc_to_hash(card
, in_dev
);
1164 static void qeth_l3_add_multicast_ipv4(struct qeth_card
*card
)
1166 struct in_device
*in4_dev
;
1168 QETH_CARD_TEXT(card
, 4, "chkmcv4");
1171 in4_dev
= __in_dev_get_rcu(card
->dev
);
1172 if (in4_dev
== NULL
)
1174 qeth_l3_add_mc_to_hash(card
, in4_dev
);
1175 qeth_l3_add_vlan_mc(card
);
1180 static void qeth_l3_add_mc6_to_hash(struct qeth_card
*card
,
1181 struct inet6_dev
*in6_dev
)
1183 struct qeth_ipaddr
*ipm
;
1184 struct ifmcaddr6
*im6
;
1185 struct qeth_ipaddr
*tmp
;
1187 QETH_CARD_TEXT(card
, 4, "addmc6");
1189 tmp
= qeth_l3_get_addr_buffer(QETH_PROT_IPV6
);
1193 for (im6
= in6_dev
->mc_list
; im6
!= NULL
; im6
= im6
->next
) {
1194 ipv6_eth_mc_map(&im6
->mca_addr
, tmp
->mac
);
1195 memcpy(&tmp
->u
.a6
.addr
, &im6
->mca_addr
.s6_addr
,
1196 sizeof(struct in6_addr
));
1197 tmp
->is_multicast
= 1;
1199 ipm
= qeth_l3_find_addr_by_ip(card
, tmp
);
1201 /* for mcast, by-IP match means full match */
1202 ipm
->disp_flag
= QETH_DISP_ADDR_DO_NOTHING
;
1206 ipm
= qeth_l3_get_addr_buffer(QETH_PROT_IPV6
);
1210 ether_addr_copy(ipm
->mac
, tmp
->mac
);
1211 memcpy(&ipm
->u
.a6
.addr
, &im6
->mca_addr
.s6_addr
,
1212 sizeof(struct in6_addr
));
1213 ipm
->is_multicast
= 1;
1214 ipm
->disp_flag
= QETH_DISP_ADDR_ADD
;
1215 hash_add(card
->ip_mc_htable
,
1216 &ipm
->hnode
, qeth_l3_ipaddr_hash(ipm
));
1222 /* called with rcu_read_lock */
1223 static void qeth_l3_add_vlan_mc6(struct qeth_card
*card
)
1225 struct inet6_dev
*in_dev
;
1228 QETH_CARD_TEXT(card
, 4, "admc6vl");
1230 if (!qeth_is_supported(card
, IPA_FULL_VLAN
))
1233 for_each_set_bit(vid
, card
->active_vlans
, VLAN_N_VID
) {
1234 struct net_device
*netdev
;
1236 netdev
= __vlan_find_dev_deep_rcu(card
->dev
, htons(ETH_P_8021Q
),
1238 if (netdev
== NULL
||
1239 !(netdev
->flags
& IFF_UP
))
1241 in_dev
= in6_dev_get(netdev
);
1244 read_lock_bh(&in_dev
->lock
);
1245 qeth_l3_add_mc6_to_hash(card
, in_dev
);
1246 read_unlock_bh(&in_dev
->lock
);
1247 in6_dev_put(in_dev
);
1251 static void qeth_l3_add_multicast_ipv6(struct qeth_card
*card
)
1253 struct inet6_dev
*in6_dev
;
1255 QETH_CARD_TEXT(card
, 4, "chkmcv6");
1257 if (!qeth_is_supported(card
, IPA_IPV6
))
1259 in6_dev
= in6_dev_get(card
->dev
);
1264 read_lock_bh(&in6_dev
->lock
);
1265 qeth_l3_add_mc6_to_hash(card
, in6_dev
);
1266 qeth_l3_add_vlan_mc6(card
);
1267 read_unlock_bh(&in6_dev
->lock
);
1269 in6_dev_put(in6_dev
);
1272 static int qeth_l3_vlan_rx_add_vid(struct net_device
*dev
,
1273 __be16 proto
, u16 vid
)
1275 struct qeth_card
*card
= dev
->ml_priv
;
1277 set_bit(vid
, card
->active_vlans
);
1281 static int qeth_l3_vlan_rx_kill_vid(struct net_device
*dev
,
1282 __be16 proto
, u16 vid
)
1284 struct qeth_card
*card
= dev
->ml_priv
;
1286 QETH_CARD_TEXT_(card
, 4, "kid:%d", vid
);
1288 if (qeth_wait_for_threads(card
, QETH_RECOVER_THREAD
)) {
1289 QETH_CARD_TEXT(card
, 3, "kidREC");
1292 clear_bit(vid
, card
->active_vlans
);
1293 qeth_l3_set_rx_mode(dev
);
1297 static void qeth_l3_rebuild_skb(struct qeth_card
*card
, struct sk_buff
*skb
,
1298 struct qeth_hdr
*hdr
)
1300 if (!(hdr
->hdr
.l3
.flags
& QETH_HDR_PASSTHRU
)) {
1301 u16 prot
= (hdr
->hdr
.l3
.flags
& QETH_HDR_IPV6
) ? ETH_P_IPV6
:
1303 unsigned char tg_addr
[ETH_ALEN
];
1305 skb_reset_network_header(skb
);
1306 switch (hdr
->hdr
.l3
.flags
& QETH_HDR_CAST_MASK
) {
1307 case QETH_CAST_MULTICAST
:
1308 if (prot
== ETH_P_IP
)
1309 ip_eth_mc_map(ip_hdr(skb
)->daddr
, tg_addr
);
1311 ipv6_eth_mc_map(&ipv6_hdr(skb
)->daddr
, tg_addr
);
1313 card
->stats
.multicast
++;
1315 case QETH_CAST_BROADCAST
:
1316 ether_addr_copy(tg_addr
, card
->dev
->broadcast
);
1317 card
->stats
.multicast
++;
1320 if (card
->options
.sniffer
)
1321 skb
->pkt_type
= PACKET_OTHERHOST
;
1322 ether_addr_copy(tg_addr
, card
->dev
->dev_addr
);
1325 if (hdr
->hdr
.l3
.ext_flags
& QETH_HDR_EXT_SRC_MAC_ADDR
)
1326 card
->dev
->header_ops
->create(skb
, card
->dev
, prot
,
1327 tg_addr
, &hdr
->hdr
.l3
.next_hop
.rx
.src_mac
,
1330 card
->dev
->header_ops
->create(skb
, card
->dev
, prot
,
1331 tg_addr
, "FAKELL", skb
->len
);
1334 skb
->protocol
= eth_type_trans(skb
, card
->dev
);
1336 /* copy VLAN tag from hdr into skb */
1337 if (!card
->options
.sniffer
&&
1338 (hdr
->hdr
.l3
.ext_flags
& (QETH_HDR_EXT_VLAN_FRAME
|
1339 QETH_HDR_EXT_INCLUDE_VLAN_TAG
))) {
1340 u16 tag
= (hdr
->hdr
.l3
.ext_flags
& QETH_HDR_EXT_VLAN_FRAME
) ?
1341 hdr
->hdr
.l3
.vlan_id
:
1342 hdr
->hdr
.l3
.next_hop
.rx
.vlan_id
;
1343 __vlan_hwaccel_put_tag(skb
, htons(ETH_P_8021Q
), tag
);
1346 qeth_rx_csum(card
, skb
, hdr
->hdr
.l3
.ext_flags
);
1349 static int qeth_l3_process_inbound_buffer(struct qeth_card
*card
,
1350 int budget
, int *done
)
1353 struct sk_buff
*skb
;
1354 struct qeth_hdr
*hdr
;
1359 WARN_ON_ONCE(!budget
);
1361 skb
= qeth_core_get_next_skb(card
,
1362 &card
->qdio
.in_q
->bufs
[card
->rx
.b_index
],
1363 &card
->rx
.b_element
, &card
->rx
.e_offset
, &hdr
);
1368 switch (hdr
->hdr
.l3
.id
) {
1369 case QETH_HEADER_TYPE_LAYER3
:
1370 magic
= *(__u16
*)skb
->data
;
1371 if ((card
->info
.type
== QETH_CARD_TYPE_IQD
) &&
1372 (magic
== ETH_P_AF_IUCV
)) {
1373 skb
->protocol
= cpu_to_be16(ETH_P_AF_IUCV
);
1375 card
->dev
->header_ops
->create(skb
, card
->dev
, 0,
1376 card
->dev
->dev_addr
, "FAKELL", len
);
1377 skb_reset_mac_header(skb
);
1378 netif_receive_skb(skb
);
1380 qeth_l3_rebuild_skb(card
, skb
, hdr
);
1382 napi_gro_receive(&card
->napi
, skb
);
1385 case QETH_HEADER_TYPE_LAYER2
: /* for HiperSockets sniffer */
1386 skb
->protocol
= eth_type_trans(skb
, skb
->dev
);
1388 netif_receive_skb(skb
);
1391 dev_kfree_skb_any(skb
);
1392 QETH_CARD_TEXT(card
, 3, "inbunkno");
1393 QETH_DBF_HEX(CTRL
, 3, hdr
, QETH_DBF_CTRL_LEN
);
1398 card
->stats
.rx_packets
++;
1399 card
->stats
.rx_bytes
+= len
;
1404 static void qeth_l3_stop_card(struct qeth_card
*card
, int recovery_mode
)
1406 QETH_DBF_TEXT(SETUP
, 2, "stopcard");
1407 QETH_DBF_HEX(SETUP
, 2, &card
, sizeof(void *));
1409 qeth_set_allowed_threads(card
, 0, 1);
1410 if (card
->options
.sniffer
&&
1411 (card
->info
.promisc_mode
== SET_PROMISC_MODE_ON
))
1412 qeth_diags_trace(card
, QETH_DIAGS_CMD_TRACE_DISABLE
);
1413 if (card
->read
.state
== CH_STATE_UP
&&
1414 card
->write
.state
== CH_STATE_UP
&&
1415 (card
->state
== CARD_STATE_UP
)) {
1417 qeth_l3_stop(card
->dev
);
1420 dev_close(card
->dev
);
1423 card
->state
= CARD_STATE_SOFTSETUP
;
1425 if (card
->state
== CARD_STATE_SOFTSETUP
) {
1426 qeth_l3_clear_ip_htable(card
, 1);
1427 qeth_clear_ipacmd_list(card
);
1428 card
->state
= CARD_STATE_HARDSETUP
;
1430 if (card
->state
== CARD_STATE_HARDSETUP
) {
1431 qeth_qdio_clear_card(card
, 0);
1432 qeth_clear_qdio_buffers(card
);
1433 qeth_clear_working_pool_list(card
);
1434 card
->state
= CARD_STATE_DOWN
;
1436 if (card
->state
== CARD_STATE_DOWN
) {
1437 qeth_clear_cmd_buffers(&card
->read
);
1438 qeth_clear_cmd_buffers(&card
->write
);
1443 * test for and Switch promiscuous mode (on or off)
1444 * either for guestlan or HiperSocket Sniffer
1447 qeth_l3_handle_promisc_mode(struct qeth_card
*card
)
1449 struct net_device
*dev
= card
->dev
;
1451 if (((dev
->flags
& IFF_PROMISC
) &&
1452 (card
->info
.promisc_mode
== SET_PROMISC_MODE_ON
)) ||
1453 (!(dev
->flags
& IFF_PROMISC
) &&
1454 (card
->info
.promisc_mode
== SET_PROMISC_MODE_OFF
)))
1457 if (card
->info
.guestlan
) { /* Guestlan trace */
1458 if (qeth_adp_supported(card
, IPA_SETADP_SET_PROMISC_MODE
))
1459 qeth_setadp_promisc_mode(card
);
1460 } else if (card
->options
.sniffer
&& /* HiperSockets trace */
1461 qeth_adp_supported(card
, IPA_SETADP_SET_DIAG_ASSIST
)) {
1462 if (dev
->flags
& IFF_PROMISC
) {
1463 QETH_CARD_TEXT(card
, 3, "+promisc");
1464 qeth_diags_trace(card
, QETH_DIAGS_CMD_TRACE_ENABLE
);
1466 QETH_CARD_TEXT(card
, 3, "-promisc");
1467 qeth_diags_trace(card
, QETH_DIAGS_CMD_TRACE_DISABLE
);
1472 static void qeth_l3_set_rx_mode(struct net_device
*dev
)
1474 struct qeth_card
*card
= dev
->ml_priv
;
1475 struct qeth_ipaddr
*addr
;
1476 struct hlist_node
*tmp
;
1479 QETH_CARD_TEXT(card
, 3, "setmulti");
1480 if (qeth_threads_running(card
, QETH_RECOVER_THREAD
) &&
1481 (card
->state
!= CARD_STATE_UP
))
1483 if (!card
->options
.sniffer
) {
1484 spin_lock_bh(&card
->mclock
);
1486 qeth_l3_add_multicast_ipv4(card
);
1487 qeth_l3_add_multicast_ipv6(card
);
1489 hash_for_each_safe(card
->ip_mc_htable
, i
, tmp
, addr
, hnode
) {
1490 switch (addr
->disp_flag
) {
1491 case QETH_DISP_ADDR_DELETE
:
1492 rc
= qeth_l3_deregister_addr_entry(card
, addr
);
1493 if (!rc
|| rc
== IPA_RC_MC_ADDR_NOT_FOUND
) {
1494 hash_del(&addr
->hnode
);
1498 case QETH_DISP_ADDR_ADD
:
1499 rc
= qeth_l3_register_addr_entry(card
, addr
);
1500 if (rc
&& rc
!= IPA_RC_LAN_OFFLINE
) {
1501 hash_del(&addr
->hnode
);
1505 addr
->ref_counter
= 1;
1508 /* for next call to set_rx_mode(): */
1509 addr
->disp_flag
= QETH_DISP_ADDR_DELETE
;
1513 spin_unlock_bh(&card
->mclock
);
1515 if (!qeth_adp_supported(card
, IPA_SETADP_SET_PROMISC_MODE
))
1518 qeth_l3_handle_promisc_mode(card
);
1521 static const char *qeth_l3_arp_get_error_cause(int *rc
)
1524 case QETH_IPA_ARP_RC_FAILED
:
1526 return "operation failed";
1527 case QETH_IPA_ARP_RC_NOTSUPP
:
1529 return "operation not supported";
1530 case QETH_IPA_ARP_RC_OUT_OF_RANGE
:
1532 return "argument out of range";
1533 case QETH_IPA_ARP_RC_Q_NOTSUPP
:
1535 return "query operation not supported";
1536 case QETH_IPA_ARP_RC_Q_NO_DATA
:
1538 return "no query data available";
1540 return "unknown error";
1544 static int qeth_l3_arp_set_no_entries(struct qeth_card
*card
, int no_entries
)
1549 QETH_CARD_TEXT(card
, 3, "arpstnoe");
1552 * currently GuestLAN only supports the ARP assist function
1553 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_SET_NO_ENTRIES;
1554 * thus we say EOPNOTSUPP for this ARP function
1556 if (card
->info
.guestlan
)
1558 if (!qeth_is_supported(card
, IPA_ARP_PROCESSING
)) {
1561 rc
= qeth_send_simple_setassparms(card
, IPA_ARP_PROCESSING
,
1562 IPA_CMD_ASS_ARP_SET_NO_ENTRIES
,
1566 QETH_DBF_MESSAGE(2, "Could not set number of ARP entries on "
1567 "%s: %s (0x%x/%d)\n", QETH_CARD_IFNAME(card
),
1568 qeth_l3_arp_get_error_cause(&rc
), tmp
, tmp
);
1573 static __u32
get_arp_entry_size(struct qeth_card
*card
,
1574 struct qeth_arp_query_data
*qdata
,
1575 struct qeth_arp_entrytype
*type
, __u8 strip_entries
)
1580 is_hsi
= qdata
->reply_bits
== 5;
1581 if (type
->ip
== QETHARP_IP_ADDR_V4
) {
1582 QETH_CARD_TEXT(card
, 4, "arpev4");
1583 if (strip_entries
) {
1584 rc
= is_hsi
? sizeof(struct qeth_arp_qi_entry5_short
) :
1585 sizeof(struct qeth_arp_qi_entry7_short
);
1587 rc
= is_hsi
? sizeof(struct qeth_arp_qi_entry5
) :
1588 sizeof(struct qeth_arp_qi_entry7
);
1590 } else if (type
->ip
== QETHARP_IP_ADDR_V6
) {
1591 QETH_CARD_TEXT(card
, 4, "arpev6");
1592 if (strip_entries
) {
1594 sizeof(struct qeth_arp_qi_entry5_short_ipv6
) :
1595 sizeof(struct qeth_arp_qi_entry7_short_ipv6
);
1598 sizeof(struct qeth_arp_qi_entry5_ipv6
) :
1599 sizeof(struct qeth_arp_qi_entry7_ipv6
);
1602 QETH_CARD_TEXT(card
, 4, "arpinv");
1609 static int arpentry_matches_prot(struct qeth_arp_entrytype
*type
, __u16 prot
)
1611 return (type
->ip
== QETHARP_IP_ADDR_V4
&& prot
== QETH_PROT_IPV4
) ||
1612 (type
->ip
== QETHARP_IP_ADDR_V6
&& prot
== QETH_PROT_IPV6
);
1615 static int qeth_l3_arp_query_cb(struct qeth_card
*card
,
1616 struct qeth_reply
*reply
, unsigned long data
)
1618 struct qeth_ipa_cmd
*cmd
;
1619 struct qeth_arp_query_data
*qdata
;
1620 struct qeth_arp_query_info
*qinfo
;
1623 int entrybytes_done
;
1625 __u8 do_strip_entries
;
1627 QETH_CARD_TEXT(card
, 3, "arpquecb");
1629 qinfo
= (struct qeth_arp_query_info
*) reply
->param
;
1630 cmd
= (struct qeth_ipa_cmd
*) data
;
1631 QETH_CARD_TEXT_(card
, 4, "%i", cmd
->hdr
.prot_version
);
1632 if (cmd
->hdr
.return_code
) {
1633 QETH_CARD_TEXT(card
, 4, "arpcberr");
1634 QETH_CARD_TEXT_(card
, 4, "%i", cmd
->hdr
.return_code
);
1637 if (cmd
->data
.setassparms
.hdr
.return_code
) {
1638 cmd
->hdr
.return_code
= cmd
->data
.setassparms
.hdr
.return_code
;
1639 QETH_CARD_TEXT(card
, 4, "setaperr");
1640 QETH_CARD_TEXT_(card
, 4, "%i", cmd
->hdr
.return_code
);
1643 qdata
= &cmd
->data
.setassparms
.data
.query_arp
;
1644 QETH_CARD_TEXT_(card
, 4, "anoen%i", qdata
->no_entries
);
1646 do_strip_entries
= (qinfo
->mask_bits
& QETH_QARP_STRIP_ENTRIES
) > 0;
1647 stripped_bytes
= do_strip_entries
? QETH_QARP_MEDIASPECIFIC_BYTES
: 0;
1648 entrybytes_done
= 0;
1649 for (e
= 0; e
< qdata
->no_entries
; ++e
) {
1652 struct qeth_arp_entrytype
*etype
;
1654 cur_entry
= &qdata
->data
+ entrybytes_done
;
1655 etype
= &((struct qeth_arp_qi_entry5
*) cur_entry
)->type
;
1656 if (!arpentry_matches_prot(etype
, cmd
->hdr
.prot_version
)) {
1657 QETH_CARD_TEXT(card
, 4, "pmis");
1658 QETH_CARD_TEXT_(card
, 4, "%i", etype
->ip
);
1661 esize
= get_arp_entry_size(card
, qdata
, etype
,
1663 QETH_CARD_TEXT_(card
, 5, "esz%i", esize
);
1667 if ((qinfo
->udata_len
- qinfo
->udata_offset
) < esize
) {
1668 QETH_CARD_TEXT_(card
, 4, "qaer3%i", -ENOMEM
);
1669 cmd
->hdr
.return_code
= IPA_RC_ENOMEM
;
1673 memcpy(qinfo
->udata
+ qinfo
->udata_offset
,
1674 &qdata
->data
+ entrybytes_done
+ stripped_bytes
,
1676 entrybytes_done
+= esize
+ stripped_bytes
;
1677 qinfo
->udata_offset
+= esize
;
1678 ++qinfo
->no_entries
;
1680 /* check if all replies received ... */
1681 if (cmd
->data
.setassparms
.hdr
.seq_no
<
1682 cmd
->data
.setassparms
.hdr
.number_of_replies
)
1684 QETH_CARD_TEXT_(card
, 4, "nove%i", qinfo
->no_entries
);
1685 memcpy(qinfo
->udata
, &qinfo
->no_entries
, 4);
1686 /* keep STRIP_ENTRIES flag so the user program can distinguish
1687 * stripped entries from normal ones */
1688 if (qinfo
->mask_bits
& QETH_QARP_STRIP_ENTRIES
)
1689 qdata
->reply_bits
|= QETH_QARP_STRIP_ENTRIES
;
1690 memcpy(qinfo
->udata
+ QETH_QARP_MASK_OFFSET
, &qdata
->reply_bits
, 2);
1691 QETH_CARD_TEXT_(card
, 4, "rc%i", 0);
1695 memcpy(qinfo
->udata
, &i
, 4);
1699 static int qeth_l3_send_ipa_arp_cmd(struct qeth_card
*card
,
1700 struct qeth_cmd_buffer
*iob
, int len
,
1701 int (*reply_cb
)(struct qeth_card
*, struct qeth_reply
*,
1705 QETH_CARD_TEXT(card
, 4, "sendarp");
1707 memcpy(iob
->data
, IPA_PDU_HEADER
, IPA_PDU_HEADER_SIZE
);
1708 memcpy(QETH_IPA_CMD_DEST_ADDR(iob
->data
),
1709 &card
->token
.ulp_connection_r
, QETH_MPC_TOKEN_LENGTH
);
1710 return qeth_send_control_data(card
, IPA_PDU_HEADER_SIZE
+ len
, iob
,
1711 reply_cb
, reply_param
);
1714 static int qeth_l3_query_arp_cache_info(struct qeth_card
*card
,
1715 enum qeth_prot_versions prot
,
1716 struct qeth_arp_query_info
*qinfo
)
1718 struct qeth_cmd_buffer
*iob
;
1719 struct qeth_ipa_cmd
*cmd
;
1723 QETH_CARD_TEXT_(card
, 3, "qarpipv%i", prot
);
1725 iob
= qeth_get_setassparms_cmd(card
, IPA_ARP_PROCESSING
,
1726 IPA_CMD_ASS_ARP_QUERY_INFO
,
1727 sizeof(struct qeth_arp_query_data
)
1732 cmd
= __ipa_cmd(iob
);
1733 cmd
->data
.setassparms
.data
.query_arp
.request_bits
= 0x000F;
1734 cmd
->data
.setassparms
.data
.query_arp
.reply_bits
= 0;
1735 cmd
->data
.setassparms
.data
.query_arp
.no_entries
= 0;
1736 rc
= qeth_l3_send_ipa_arp_cmd(card
, iob
,
1737 QETH_SETASS_BASE_LEN
+QETH_ARP_CMD_LEN
,
1738 qeth_l3_arp_query_cb
, (void *)qinfo
);
1742 "Error while querying ARP cache on %s: %s "
1743 "(0x%x/%d)\n", QETH_CARD_IFNAME(card
),
1744 qeth_l3_arp_get_error_cause(&rc
), tmp
, tmp
);
1750 static int qeth_l3_arp_query(struct qeth_card
*card
, char __user
*udata
)
1752 struct qeth_arp_query_info qinfo
= {0, };
1755 QETH_CARD_TEXT(card
, 3, "arpquery");
1757 if (!qeth_is_supported(card
,/*IPA_QUERY_ARP_ADDR_INFO*/
1758 IPA_ARP_PROCESSING
)) {
1759 QETH_CARD_TEXT(card
, 3, "arpqnsup");
1763 /* get size of userspace buffer and mask_bits -> 6 bytes */
1764 if (copy_from_user(&qinfo
, udata
, 6)) {
1768 qinfo
.udata
= kzalloc(qinfo
.udata_len
, GFP_KERNEL
);
1773 qinfo
.udata_offset
= QETH_QARP_ENTRIES_OFFSET
;
1774 rc
= qeth_l3_query_arp_cache_info(card
, QETH_PROT_IPV4
, &qinfo
);
1776 if (copy_to_user(udata
, qinfo
.udata
, 4))
1780 if (qinfo
.mask_bits
& QETH_QARP_WITH_IPV6
) {
1781 /* fails in case of GuestLAN QDIO mode */
1782 qeth_l3_query_arp_cache_info(card
, QETH_PROT_IPV6
, &qinfo
);
1784 if (copy_to_user(udata
, qinfo
.udata
, qinfo
.udata_len
)) {
1785 QETH_CARD_TEXT(card
, 4, "qactf");
1789 QETH_CARD_TEXT(card
, 4, "qacts");
1797 static int qeth_l3_arp_add_entry(struct qeth_card
*card
,
1798 struct qeth_arp_cache_entry
*entry
)
1800 struct qeth_cmd_buffer
*iob
;
1805 QETH_CARD_TEXT(card
, 3, "arpadent");
1808 * currently GuestLAN only supports the ARP assist function
1809 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_ADD_ENTRY;
1810 * thus we say EOPNOTSUPP for this ARP function
1812 if (card
->info
.guestlan
)
1814 if (!qeth_is_supported(card
, IPA_ARP_PROCESSING
)) {
1818 iob
= qeth_get_setassparms_cmd(card
, IPA_ARP_PROCESSING
,
1819 IPA_CMD_ASS_ARP_ADD_ENTRY
,
1820 sizeof(struct qeth_arp_cache_entry
),
1824 rc
= qeth_send_setassparms(card
, iob
,
1825 sizeof(struct qeth_arp_cache_entry
),
1826 (unsigned long) entry
,
1827 qeth_setassparms_cb
, NULL
);
1830 qeth_l3_ipaddr4_to_string((u8
*)entry
->ipaddr
, buf
);
1831 QETH_DBF_MESSAGE(2, "Could not add ARP entry for address %s "
1832 "on %s: %s (0x%x/%d)\n", buf
, QETH_CARD_IFNAME(card
),
1833 qeth_l3_arp_get_error_cause(&rc
), tmp
, tmp
);
1838 static int qeth_l3_arp_remove_entry(struct qeth_card
*card
,
1839 struct qeth_arp_cache_entry
*entry
)
1841 struct qeth_cmd_buffer
*iob
;
1842 char buf
[16] = {0, };
1846 QETH_CARD_TEXT(card
, 3, "arprment");
1849 * currently GuestLAN only supports the ARP assist function
1850 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_REMOVE_ENTRY;
1851 * thus we say EOPNOTSUPP for this ARP function
1853 if (card
->info
.guestlan
)
1855 if (!qeth_is_supported(card
, IPA_ARP_PROCESSING
)) {
1858 memcpy(buf
, entry
, 12);
1859 iob
= qeth_get_setassparms_cmd(card
, IPA_ARP_PROCESSING
,
1860 IPA_CMD_ASS_ARP_REMOVE_ENTRY
,
1865 rc
= qeth_send_setassparms(card
, iob
,
1866 12, (unsigned long)buf
,
1867 qeth_setassparms_cb
, NULL
);
1871 qeth_l3_ipaddr4_to_string((u8
*)entry
->ipaddr
, buf
);
1872 QETH_DBF_MESSAGE(2, "Could not delete ARP entry for address %s"
1873 " on %s: %s (0x%x/%d)\n", buf
, QETH_CARD_IFNAME(card
),
1874 qeth_l3_arp_get_error_cause(&rc
), tmp
, tmp
);
1879 static int qeth_l3_arp_flush_cache(struct qeth_card
*card
)
1884 QETH_CARD_TEXT(card
, 3, "arpflush");
1887 * currently GuestLAN only supports the ARP assist function
1888 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_FLUSH_CACHE;
1889 * thus we say EOPNOTSUPP for this ARP function
1891 if (card
->info
.guestlan
|| (card
->info
.type
== QETH_CARD_TYPE_IQD
))
1893 if (!qeth_is_supported(card
, IPA_ARP_PROCESSING
)) {
1896 rc
= qeth_send_simple_setassparms(card
, IPA_ARP_PROCESSING
,
1897 IPA_CMD_ASS_ARP_FLUSH_CACHE
, 0);
1900 QETH_DBF_MESSAGE(2, "Could not flush ARP cache on %s: %s "
1901 "(0x%x/%d)\n", QETH_CARD_IFNAME(card
),
1902 qeth_l3_arp_get_error_cause(&rc
), tmp
, tmp
);
1907 static int qeth_l3_do_ioctl(struct net_device
*dev
, struct ifreq
*rq
, int cmd
)
1909 struct qeth_card
*card
= dev
->ml_priv
;
1910 struct qeth_arp_cache_entry arp_entry
;
1914 case SIOC_QETH_ARP_SET_NO_ENTRIES
:
1915 if (!capable(CAP_NET_ADMIN
)) {
1919 rc
= qeth_l3_arp_set_no_entries(card
, rq
->ifr_ifru
.ifru_ivalue
);
1921 case SIOC_QETH_ARP_QUERY_INFO
:
1922 if (!capable(CAP_NET_ADMIN
)) {
1926 rc
= qeth_l3_arp_query(card
, rq
->ifr_ifru
.ifru_data
);
1928 case SIOC_QETH_ARP_ADD_ENTRY
:
1929 if (!capable(CAP_NET_ADMIN
)) {
1933 if (copy_from_user(&arp_entry
, rq
->ifr_ifru
.ifru_data
,
1934 sizeof(struct qeth_arp_cache_entry
)))
1937 rc
= qeth_l3_arp_add_entry(card
, &arp_entry
);
1939 case SIOC_QETH_ARP_REMOVE_ENTRY
:
1940 if (!capable(CAP_NET_ADMIN
)) {
1944 if (copy_from_user(&arp_entry
, rq
->ifr_ifru
.ifru_data
,
1945 sizeof(struct qeth_arp_cache_entry
)))
1948 rc
= qeth_l3_arp_remove_entry(card
, &arp_entry
);
1950 case SIOC_QETH_ARP_FLUSH_CACHE
:
1951 if (!capable(CAP_NET_ADMIN
)) {
1955 rc
= qeth_l3_arp_flush_cache(card
);
1963 static int qeth_l3_get_cast_type(struct sk_buff
*skb
)
1965 struct neighbour
*n
= NULL
;
1966 struct dst_entry
*dst
;
1971 n
= dst_neigh_lookup_skb(dst
, skb
);
1973 int cast_type
= n
->type
;
1977 if ((cast_type
== RTN_BROADCAST
) ||
1978 (cast_type
== RTN_MULTICAST
) ||
1979 (cast_type
== RTN_ANYCAST
))
1985 /* no neighbour (eg AF_PACKET), fall back to target's IP address ... */
1986 if (be16_to_cpu(skb
->protocol
) == ETH_P_IPV6
)
1987 return ipv6_addr_is_multicast(&ipv6_hdr(skb
)->daddr
) ?
1988 RTN_MULTICAST
: RTN_UNSPEC
;
1989 else if (be16_to_cpu(skb
->protocol
) == ETH_P_IP
)
1990 return ipv4_is_multicast(ip_hdr(skb
)->daddr
) ?
1991 RTN_MULTICAST
: RTN_UNSPEC
;
1993 /* ... and MAC address */
1994 if (ether_addr_equal_64bits(eth_hdr(skb
)->h_dest
, skb
->dev
->broadcast
))
1995 return RTN_BROADCAST
;
1996 if (is_multicast_ether_addr(eth_hdr(skb
)->h_dest
))
1997 return RTN_MULTICAST
;
1999 /* default to unicast */
2003 static void qeth_l3_fill_af_iucv_hdr(struct qeth_card
*card
,
2004 struct qeth_hdr
*hdr
, struct sk_buff
*skb
)
2007 struct af_iucv_trans_hdr
*iucv_hdr
;
2009 memset(hdr
, 0, sizeof(struct qeth_hdr
));
2010 hdr
->hdr
.l3
.id
= QETH_HEADER_TYPE_LAYER3
;
2011 hdr
->hdr
.l3
.ext_flags
= 0;
2012 hdr
->hdr
.l3
.length
= skb
->len
- ETH_HLEN
;
2013 hdr
->hdr
.l3
.flags
= QETH_HDR_IPV6
| QETH_CAST_UNICAST
;
2015 iucv_hdr
= (struct af_iucv_trans_hdr
*) (skb
->data
+ ETH_HLEN
);
2016 memset(daddr
, 0, sizeof(daddr
));
2019 memcpy(&daddr
[8], iucv_hdr
->destUserID
, 8);
2020 memcpy(hdr
->hdr
.l3
.next_hop
.ipv6_addr
, daddr
, 16);
2023 static u8
qeth_l3_cast_type_to_flag(int cast_type
)
2025 if (cast_type
== RTN_MULTICAST
)
2026 return QETH_CAST_MULTICAST
;
2027 if (cast_type
== RTN_ANYCAST
)
2028 return QETH_CAST_ANYCAST
;
2029 if (cast_type
== RTN_BROADCAST
)
2030 return QETH_CAST_BROADCAST
;
2031 return QETH_CAST_UNICAST
;
2034 static void qeth_l3_fill_header(struct qeth_card
*card
, struct qeth_hdr
*hdr
,
2035 struct sk_buff
*skb
, int ipv
, int cast_type
,
2036 unsigned int data_len
)
2038 memset(hdr
, 0, sizeof(struct qeth_hdr
));
2039 hdr
->hdr
.l3
.id
= QETH_HEADER_TYPE_LAYER3
;
2040 hdr
->hdr
.l3
.length
= data_len
;
2043 * before we're going to overwrite this location with next hop ip.
2044 * v6 uses passthrough, v4 sets the tag in the QDIO header.
2046 if (skb_vlan_tag_present(skb
)) {
2047 if ((ipv
== 4) || (card
->info
.type
== QETH_CARD_TYPE_IQD
))
2048 hdr
->hdr
.l3
.ext_flags
= QETH_HDR_EXT_VLAN_FRAME
;
2050 hdr
->hdr
.l3
.ext_flags
= QETH_HDR_EXT_INCLUDE_VLAN_TAG
;
2051 hdr
->hdr
.l3
.vlan_id
= skb_vlan_tag_get(skb
);
2056 hdr
->hdr
.l3
.flags
= QETH_HDR_PASSTHRU
;
2057 if (ether_addr_equal_64bits(eth_hdr(skb
)->h_dest
,
2058 skb
->dev
->broadcast
))
2059 hdr
->hdr
.l3
.flags
|= QETH_CAST_BROADCAST
;
2061 hdr
->hdr
.l3
.flags
|= (cast_type
== RTN_MULTICAST
) ?
2062 QETH_CAST_MULTICAST
: QETH_CAST_UNICAST
;
2066 hdr
->hdr
.l3
.flags
= qeth_l3_cast_type_to_flag(cast_type
);
2069 struct rtable
*rt
= skb_rtable(skb
);
2071 *((__be32
*) &hdr
->hdr
.l3
.next_hop
.ipv4
.addr
) = (rt
) ?
2072 rt_nexthop(rt
, ip_hdr(skb
)->daddr
) :
2076 const struct rt6_info
*rt
= skb_rt6_info(skb
);
2077 const struct in6_addr
*next_hop
;
2079 if (rt
&& !ipv6_addr_any(&rt
->rt6i_gateway
))
2080 next_hop
= &rt
->rt6i_gateway
;
2082 next_hop
= &ipv6_hdr(skb
)->daddr
;
2083 memcpy(hdr
->hdr
.l3
.next_hop
.ipv6_addr
, next_hop
, 16);
2085 hdr
->hdr
.l3
.flags
|= QETH_HDR_IPV6
;
2086 if (card
->info
.type
!= QETH_CARD_TYPE_IQD
)
2087 hdr
->hdr
.l3
.flags
|= QETH_HDR_PASSTHRU
;
2092 static void qeth_tso_fill_header(struct qeth_card
*card
,
2093 struct qeth_hdr
*qhdr
, struct sk_buff
*skb
)
2095 struct qeth_hdr_tso
*hdr
= (struct qeth_hdr_tso
*)qhdr
;
2096 struct tcphdr
*tcph
= tcp_hdr(skb
);
2097 struct iphdr
*iph
= ip_hdr(skb
);
2098 struct ipv6hdr
*ip6h
= ipv6_hdr(skb
);
2100 /*fix header to TSO values ...*/
2101 hdr
->hdr
.hdr
.l3
.id
= QETH_HEADER_TYPE_TSO
;
2102 /*set values which are fix for the first approach ...*/
2103 hdr
->ext
.hdr_tot_len
= (__u16
) sizeof(struct qeth_hdr_ext_tso
);
2104 hdr
->ext
.imb_hdr_no
= 1;
2105 hdr
->ext
.hdr_type
= 1;
2106 hdr
->ext
.hdr_version
= 1;
2107 hdr
->ext
.hdr_len
= 28;
2108 /*insert non-fix values */
2109 hdr
->ext
.mss
= skb_shinfo(skb
)->gso_size
;
2110 hdr
->ext
.dg_hdr_len
= (__u16
)(ip_hdrlen(skb
) + tcp_hdrlen(skb
));
2111 hdr
->ext
.payload_len
= (__u16
)(skb
->len
- hdr
->ext
.dg_hdr_len
-
2112 sizeof(struct qeth_hdr_tso
));
2114 if (be16_to_cpu(skb
->protocol
) == ETH_P_IPV6
) {
2115 ip6h
->payload_len
= 0;
2116 tcph
->check
= ~csum_ipv6_magic(&ip6h
->saddr
, &ip6h
->daddr
,
2119 /*OSA want us to set these values ...*/
2120 tcph
->check
= ~csum_tcpudp_magic(iph
->saddr
, iph
->daddr
,
2128 * qeth_l3_get_elements_no_tso() - find number of SBALEs for skb data for tso
2129 * @card: qeth card structure, to check max. elems.
2131 * @extra_elems: extra elems needed, to check against max.
2133 * Returns the number of pages, and thus QDIO buffer elements, needed to cover
2134 * skb data, including linear part and fragments, but excluding TCP header.
2135 * (Exclusion of TCP header distinguishes it from qeth_get_elements_no().)
2136 * Checks if the result plus extra_elems fits under the limit for the card.
2137 * Returns 0 if it does not.
2138 * Note: extra_elems is not included in the returned result.
2140 static int qeth_l3_get_elements_no_tso(struct qeth_card
*card
,
2141 struct sk_buff
*skb
, int extra_elems
)
2143 addr_t start
= (addr_t
)tcp_hdr(skb
) + tcp_hdrlen(skb
);
2144 addr_t end
= (addr_t
)skb
->data
+ skb_headlen(skb
);
2145 int elements
= qeth_get_elements_for_frags(skb
);
2148 elements
+= qeth_get_elements_for_range(start
, end
);
2150 if ((elements
+ extra_elems
) > QETH_MAX_BUFFER_ELEMENTS(card
)) {
2152 "Invalid size of TSO IP packet (Number=%d / Length=%d). Discarded.\n",
2153 elements
+ extra_elems
, skb
->len
);
2159 static netdev_tx_t
qeth_l3_hard_start_xmit(struct sk_buff
*skb
,
2160 struct net_device
*dev
)
2164 struct qeth_hdr
*hdr
= NULL
;
2165 int hdr_elements
= 0;
2167 struct qeth_card
*card
= dev
->ml_priv
;
2168 struct sk_buff
*new_skb
= NULL
;
2169 int ipv
= qeth_get_ip_version(skb
);
2170 int cast_type
= qeth_l3_get_cast_type(skb
);
2171 struct qeth_qdio_out_q
*queue
=
2172 card
->qdio
.out_qs
[card
->qdio
.do_prio_queueing
2173 || (cast_type
&& card
->info
.is_multicast_different
) ?
2174 qeth_get_priority_queue(card
, skb
, ipv
, cast_type
) :
2175 card
->qdio
.default_out_queue
];
2176 int tx_bytes
= skb
->len
;
2177 unsigned int hd_len
= 0;
2179 int data_offset
= -1;
2180 unsigned int nr_frags
;
2182 if (((card
->info
.type
== QETH_CARD_TYPE_IQD
) &&
2183 (((card
->options
.cq
!= QETH_CQ_ENABLED
) && !ipv
) ||
2184 ((card
->options
.cq
== QETH_CQ_ENABLED
) &&
2185 (be16_to_cpu(skb
->protocol
) != ETH_P_AF_IUCV
)))) ||
2186 card
->options
.sniffer
)
2189 if ((card
->state
!= CARD_STATE_UP
) || !card
->lan_online
) {
2190 card
->stats
.tx_carrier_errors
++;
2194 if ((cast_type
== RTN_BROADCAST
) &&
2195 (card
->info
.broadcast_capable
== 0))
2198 if (card
->options
.performance_stats
) {
2199 card
->perf_stats
.outbound_cnt
++;
2200 card
->perf_stats
.outbound_start_time
= qeth_get_micros();
2203 /* Ignore segment size from skb_is_gso(), 1 page is always used. */
2204 use_tso
= skb_is_gso(skb
) &&
2205 (skb_shinfo(skb
)->gso_type
& SKB_GSO_TCPV4
);
2207 if (card
->info
.type
== QETH_CARD_TYPE_IQD
) {
2209 data_offset
= ETH_HLEN
;
2210 hd_len
= sizeof(*hdr
);
2211 hdr
= kmem_cache_alloc(qeth_core_header_cache
, GFP_ATOMIC
);
2216 /* create a clone with writeable headroom */
2217 new_skb
= skb_realloc_headroom(skb
, sizeof(struct qeth_hdr_tso
)
2223 skb_pull(new_skb
, ETH_HLEN
);
2226 if (ipv
!= 4 && skb_vlan_tag_present(new_skb
)) {
2227 skb_push(new_skb
, VLAN_HLEN
);
2228 skb_copy_to_linear_data(new_skb
, new_skb
->data
+ 4, 4);
2229 skb_copy_to_linear_data_offset(new_skb
, 4,
2230 new_skb
->data
+ 8, 4);
2231 skb_copy_to_linear_data_offset(new_skb
, 8,
2232 new_skb
->data
+ 12, 4);
2233 tag
= (__be16
*)(new_skb
->data
+ 12);
2234 *tag
= cpu_to_be16(ETH_P_8021Q
);
2235 *(tag
+ 1) = cpu_to_be16(skb_vlan_tag_get(new_skb
));
2239 netif_stop_queue(dev
);
2241 /* fix hardware limitation: as long as we do not have sbal
2242 * chaining we can not send long frag lists
2244 if ((card
->info
.type
!= QETH_CARD_TYPE_IQD
) &&
2245 ((use_tso
&& !qeth_l3_get_elements_no_tso(card
, new_skb
, 1)) ||
2246 (!use_tso
&& !qeth_get_elements_no(card
, new_skb
, 0, 0)))) {
2247 int lin_rc
= skb_linearize(new_skb
);
2249 if (card
->options
.performance_stats
) {
2251 card
->perf_stats
.tx_linfail
++;
2253 card
->perf_stats
.tx_lin
++;
2258 nr_frags
= skb_shinfo(new_skb
)->nr_frags
;
2261 hdr
= skb_push(new_skb
, sizeof(struct qeth_hdr_tso
));
2262 memset(hdr
, 0, sizeof(struct qeth_hdr_tso
));
2263 qeth_l3_fill_header(card
, hdr
, new_skb
, ipv
, cast_type
,
2264 new_skb
->len
- sizeof(struct qeth_hdr_tso
));
2265 qeth_tso_fill_header(card
, hdr
, new_skb
);
2268 if (data_offset
< 0) {
2269 hdr
= skb_push(new_skb
, sizeof(struct qeth_hdr
));
2270 qeth_l3_fill_header(card
, hdr
, new_skb
, ipv
, cast_type
,
2272 sizeof(struct qeth_hdr
));
2274 if (be16_to_cpu(new_skb
->protocol
) == ETH_P_AF_IUCV
)
2275 qeth_l3_fill_af_iucv_hdr(card
, hdr
, new_skb
);
2277 qeth_l3_fill_header(card
, hdr
, new_skb
, ipv
,
2279 new_skb
->len
- data_offset
);
2283 if (new_skb
->ip_summed
== CHECKSUM_PARTIAL
) {
2284 qeth_tx_csum(new_skb
, &hdr
->hdr
.l3
.ext_flags
, ipv
);
2285 if (card
->options
.performance_stats
)
2286 card
->perf_stats
.tx_csum
++;
2290 elements
= use_tso
?
2291 qeth_l3_get_elements_no_tso(card
, new_skb
, hdr_elements
) :
2292 qeth_get_elements_no(card
, new_skb
, hdr_elements
,
2293 (data_offset
> 0) ? data_offset
: 0);
2295 if (data_offset
>= 0)
2296 kmem_cache_free(qeth_core_header_cache
, hdr
);
2299 elements
+= hdr_elements
;
2301 if (card
->info
.type
!= QETH_CARD_TYPE_IQD
) {
2304 hd_len
= sizeof(struct qeth_hdr_tso
) +
2305 ip_hdrlen(new_skb
) + tcp_hdrlen(new_skb
);
2308 len
= sizeof(struct qeth_hdr_layer3
);
2311 if (qeth_hdr_chk_and_bounce(new_skb
, &hdr
, len
))
2313 rc
= qeth_do_send_packet(card
, queue
, new_skb
, hdr
, hd_len
,
2316 rc
= qeth_do_send_packet_fast(queue
, new_skb
, hdr
, data_offset
,
2320 card
->stats
.tx_packets
++;
2321 card
->stats
.tx_bytes
+= tx_bytes
;
2323 dev_kfree_skb_any(skb
);
2324 if (card
->options
.performance_stats
) {
2326 card
->perf_stats
.large_send_bytes
+= tx_bytes
;
2327 card
->perf_stats
.large_send_cnt
++;
2330 card
->perf_stats
.sg_skbs_sent
++;
2331 /* nr_frags + skb->data */
2332 card
->perf_stats
.sg_frags_sent
+= nr_frags
+ 1;
2337 if (data_offset
>= 0)
2338 kmem_cache_free(qeth_core_header_cache
, hdr
);
2342 dev_kfree_skb_any(new_skb
);
2343 return NETDEV_TX_BUSY
;
2348 netif_wake_queue(dev
);
2349 if (card
->options
.performance_stats
)
2350 card
->perf_stats
.outbound_time
+= qeth_get_micros() -
2351 card
->perf_stats
.outbound_start_time
;
2355 card
->stats
.tx_dropped
++;
2356 card
->stats
.tx_errors
++;
2357 if ((new_skb
!= skb
) && new_skb
)
2358 dev_kfree_skb_any(new_skb
);
2359 dev_kfree_skb_any(skb
);
2360 netif_wake_queue(dev
);
2361 return NETDEV_TX_OK
;
2364 static int __qeth_l3_open(struct net_device
*dev
)
2366 struct qeth_card
*card
= dev
->ml_priv
;
2369 QETH_CARD_TEXT(card
, 4, "qethopen");
2370 if (card
->state
== CARD_STATE_UP
)
2372 if (card
->state
!= CARD_STATE_SOFTSETUP
)
2374 card
->data
.state
= CH_STATE_UP
;
2375 card
->state
= CARD_STATE_UP
;
2376 netif_start_queue(dev
);
2378 if (qdio_stop_irq(card
->data
.ccwdev
, 0) >= 0) {
2379 napi_enable(&card
->napi
);
2380 napi_schedule(&card
->napi
);
2386 static int qeth_l3_open(struct net_device
*dev
)
2388 struct qeth_card
*card
= dev
->ml_priv
;
2390 QETH_CARD_TEXT(card
, 5, "qethope_");
2391 if (qeth_wait_for_threads(card
, QETH_RECOVER_THREAD
)) {
2392 QETH_CARD_TEXT(card
, 3, "openREC");
2393 return -ERESTARTSYS
;
2395 return __qeth_l3_open(dev
);
2398 static int qeth_l3_stop(struct net_device
*dev
)
2400 struct qeth_card
*card
= dev
->ml_priv
;
2402 QETH_CARD_TEXT(card
, 4, "qethstop");
2403 netif_tx_disable(dev
);
2404 if (card
->state
== CARD_STATE_UP
) {
2405 card
->state
= CARD_STATE_SOFTSETUP
;
2406 napi_disable(&card
->napi
);
2411 static const struct ethtool_ops qeth_l3_ethtool_ops
= {
2412 .get_link
= ethtool_op_get_link
,
2413 .get_strings
= qeth_core_get_strings
,
2414 .get_ethtool_stats
= qeth_core_get_ethtool_stats
,
2415 .get_sset_count
= qeth_core_get_sset_count
,
2416 .get_drvinfo
= qeth_core_get_drvinfo
,
2417 .get_link_ksettings
= qeth_core_ethtool_get_link_ksettings
,
2421 * we need NOARP for IPv4 but we want neighbor solicitation for IPv6. Setting
2422 * NOARP on the netdevice is no option because it also turns off neighbor
2423 * solicitation. For IPv4 we install a neighbor_setup function. We don't want
2424 * arp resolution but we want the hard header (packet socket will work
2427 static int qeth_l3_neigh_setup_noarp(struct neighbour
*n
)
2429 n
->nud_state
= NUD_NOARP
;
2430 memcpy(n
->ha
, "FAKELL", 6);
2431 n
->output
= n
->ops
->connected_output
;
2436 qeth_l3_neigh_setup(struct net_device
*dev
, struct neigh_parms
*np
)
2438 if (np
->tbl
->family
== AF_INET
)
2439 np
->neigh_setup
= qeth_l3_neigh_setup_noarp
;
2444 static const struct net_device_ops qeth_l3_netdev_ops
= {
2445 .ndo_open
= qeth_l3_open
,
2446 .ndo_stop
= qeth_l3_stop
,
2447 .ndo_get_stats
= qeth_get_stats
,
2448 .ndo_start_xmit
= qeth_l3_hard_start_xmit
,
2449 .ndo_validate_addr
= eth_validate_addr
,
2450 .ndo_set_rx_mode
= qeth_l3_set_rx_mode
,
2451 .ndo_do_ioctl
= qeth_do_ioctl
,
2452 .ndo_change_mtu
= qeth_change_mtu
,
2453 .ndo_fix_features
= qeth_fix_features
,
2454 .ndo_set_features
= qeth_set_features
,
2455 .ndo_vlan_rx_add_vid
= qeth_l3_vlan_rx_add_vid
,
2456 .ndo_vlan_rx_kill_vid
= qeth_l3_vlan_rx_kill_vid
,
2457 .ndo_tx_timeout
= qeth_tx_timeout
,
2460 static const struct net_device_ops qeth_l3_osa_netdev_ops
= {
2461 .ndo_open
= qeth_l3_open
,
2462 .ndo_stop
= qeth_l3_stop
,
2463 .ndo_get_stats
= qeth_get_stats
,
2464 .ndo_start_xmit
= qeth_l3_hard_start_xmit
,
2465 .ndo_features_check
= qeth_features_check
,
2466 .ndo_validate_addr
= eth_validate_addr
,
2467 .ndo_set_rx_mode
= qeth_l3_set_rx_mode
,
2468 .ndo_do_ioctl
= qeth_do_ioctl
,
2469 .ndo_change_mtu
= qeth_change_mtu
,
2470 .ndo_fix_features
= qeth_fix_features
,
2471 .ndo_set_features
= qeth_set_features
,
2472 .ndo_vlan_rx_add_vid
= qeth_l3_vlan_rx_add_vid
,
2473 .ndo_vlan_rx_kill_vid
= qeth_l3_vlan_rx_kill_vid
,
2474 .ndo_tx_timeout
= qeth_tx_timeout
,
2475 .ndo_neigh_setup
= qeth_l3_neigh_setup
,
2478 static int qeth_l3_setup_netdev(struct qeth_card
*card
)
2482 if (card
->info
.type
== QETH_CARD_TYPE_OSD
||
2483 card
->info
.type
== QETH_CARD_TYPE_OSX
) {
2484 if ((card
->info
.link_type
== QETH_LINK_TYPE_LANE_TR
) ||
2485 (card
->info
.link_type
== QETH_LINK_TYPE_HSTR
)) {
2486 pr_info("qeth_l3: ignoring TR device\n");
2490 card
->dev
= alloc_etherdev(0);
2493 card
->dev
->netdev_ops
= &qeth_l3_osa_netdev_ops
;
2495 /*IPv6 address autoconfiguration stuff*/
2496 qeth_l3_get_unique_id(card
);
2497 if (!(card
->info
.unique_id
& UNIQUE_ID_NOT_BY_CARD
))
2498 card
->dev
->dev_id
= card
->info
.unique_id
& 0xffff;
2500 card
->dev
->hw_features
|= NETIF_F_SG
;
2501 card
->dev
->vlan_features
|= NETIF_F_SG
;
2503 if (!card
->info
.guestlan
) {
2504 card
->dev
->features
|= NETIF_F_SG
;
2505 card
->dev
->hw_features
|= NETIF_F_TSO
|
2506 NETIF_F_RXCSUM
| NETIF_F_IP_CSUM
;
2507 card
->dev
->vlan_features
|= NETIF_F_TSO
|
2508 NETIF_F_RXCSUM
| NETIF_F_IP_CSUM
;
2511 if (qeth_is_supported6(card
, IPA_OUTBOUND_CHECKSUM_V6
)) {
2512 card
->dev
->hw_features
|= NETIF_F_IPV6_CSUM
;
2513 card
->dev
->vlan_features
|= NETIF_F_IPV6_CSUM
;
2515 } else if (card
->info
.type
== QETH_CARD_TYPE_IQD
) {
2516 card
->dev
= alloc_netdev(0, "hsi%d", NET_NAME_UNKNOWN
,
2520 card
->dev
->flags
|= IFF_NOARP
;
2521 card
->dev
->netdev_ops
= &qeth_l3_netdev_ops
;
2522 rc
= qeth_l3_iqd_read_initial_mac(card
);
2525 if (card
->options
.hsuid
[0])
2526 memcpy(card
->dev
->perm_addr
, card
->options
.hsuid
, 9);
2530 card
->dev
->ml_priv
= card
;
2531 card
->dev
->watchdog_timeo
= QETH_TX_TIMEOUT
;
2532 card
->dev
->mtu
= card
->info
.initial_mtu
;
2533 card
->dev
->min_mtu
= 64;
2534 card
->dev
->max_mtu
= ETH_MAX_MTU
;
2535 card
->dev
->dev_port
= card
->info
.portno
;
2536 card
->dev
->ethtool_ops
= &qeth_l3_ethtool_ops
;
2537 card
->dev
->features
|= NETIF_F_HW_VLAN_CTAG_TX
|
2538 NETIF_F_HW_VLAN_CTAG_RX
|
2539 NETIF_F_HW_VLAN_CTAG_FILTER
;
2540 netif_keep_dst(card
->dev
);
2541 netif_set_gso_max_size(card
->dev
, (QETH_MAX_BUFFER_ELEMENTS(card
) - 1) *
2544 SET_NETDEV_DEV(card
->dev
, &card
->gdev
->dev
);
2545 netif_napi_add(card
->dev
, &card
->napi
, qeth_poll
, QETH_NAPI_WEIGHT
);
2546 netif_carrier_off(card
->dev
);
2547 return register_netdev(card
->dev
);
2550 static const struct device_type qeth_l3_devtype
= {
2551 .name
= "qeth_layer3",
2552 .groups
= qeth_l3_attr_groups
,
2555 static int qeth_l3_probe_device(struct ccwgroup_device
*gdev
)
2557 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
2560 if (gdev
->dev
.type
== &qeth_generic_devtype
) {
2561 rc
= qeth_l3_create_device_attributes(&gdev
->dev
);
2565 hash_init(card
->ip_htable
);
2566 hash_init(card
->ip_mc_htable
);
2567 card
->options
.layer2
= 0;
2568 card
->info
.hwtrap
= 0;
2572 static void qeth_l3_remove_device(struct ccwgroup_device
*cgdev
)
2574 struct qeth_card
*card
= dev_get_drvdata(&cgdev
->dev
);
2576 if (cgdev
->dev
.type
== &qeth_generic_devtype
)
2577 qeth_l3_remove_device_attributes(&cgdev
->dev
);
2579 qeth_set_allowed_threads(card
, 0, 1);
2580 wait_event(card
->wait_q
, qeth_threads_running(card
, 0xffffffff) == 0);
2582 if (cgdev
->state
== CCWGROUP_ONLINE
)
2583 qeth_l3_set_offline(cgdev
);
2586 unregister_netdev(card
->dev
);
2587 free_netdev(card
->dev
);
2591 qeth_l3_clear_ip_htable(card
, 0);
2592 qeth_l3_clear_ipato_list(card
);
2596 static int __qeth_l3_set_online(struct ccwgroup_device
*gdev
, int recovery_mode
)
2598 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
2600 enum qeth_card_states recover_flag
;
2602 mutex_lock(&card
->discipline_mutex
);
2603 mutex_lock(&card
->conf_mutex
);
2604 QETH_DBF_TEXT(SETUP
, 2, "setonlin");
2605 QETH_DBF_HEX(SETUP
, 2, &card
, sizeof(void *));
2607 recover_flag
= card
->state
;
2608 rc
= qeth_core_hardsetup_card(card
);
2610 QETH_DBF_TEXT_(SETUP
, 2, "2err%04x", rc
);
2615 if (!card
->dev
&& qeth_l3_setup_netdev(card
)) {
2620 if (qeth_is_diagass_supported(card
, QETH_DIAGS_CMD_TRAP
)) {
2621 if (card
->info
.hwtrap
&&
2622 qeth_hw_trap(card
, QETH_DIAGS_TRAP_ARM
))
2623 card
->info
.hwtrap
= 0;
2625 card
->info
.hwtrap
= 0;
2627 card
->state
= CARD_STATE_HARDSETUP
;
2628 qeth_print_status_message(card
);
2631 QETH_DBF_TEXT(SETUP
, 2, "softsetp");
2633 rc
= qeth_l3_setadapter_parms(card
);
2635 QETH_DBF_TEXT_(SETUP
, 2, "2err%04x", rc
);
2636 if (!card
->options
.sniffer
) {
2637 rc
= qeth_l3_start_ipassists(card
);
2639 QETH_DBF_TEXT_(SETUP
, 2, "3err%d", rc
);
2642 rc
= qeth_l3_setrouting_v4(card
);
2644 QETH_DBF_TEXT_(SETUP
, 2, "4err%04x", rc
);
2645 rc
= qeth_l3_setrouting_v6(card
);
2647 QETH_DBF_TEXT_(SETUP
, 2, "5err%04x", rc
);
2649 netif_tx_disable(card
->dev
);
2651 rc
= qeth_init_qdio_queues(card
);
2653 QETH_DBF_TEXT_(SETUP
, 2, "6err%d", rc
);
2657 card
->state
= CARD_STATE_SOFTSETUP
;
2659 qeth_set_allowed_threads(card
, 0xffffffff, 0);
2660 qeth_l3_recover_ip(card
);
2661 if (card
->lan_online
)
2662 netif_carrier_on(card
->dev
);
2664 netif_carrier_off(card
->dev
);
2666 qeth_enable_hw_features(card
->dev
);
2667 if (recover_flag
== CARD_STATE_RECOVER
) {
2670 __qeth_l3_open(card
->dev
);
2672 dev_open(card
->dev
);
2673 qeth_l3_set_rx_mode(card
->dev
);
2676 qeth_trace_features(card
);
2677 /* let user_space know that device is online */
2678 kobject_uevent(&gdev
->dev
.kobj
, KOBJ_CHANGE
);
2679 mutex_unlock(&card
->conf_mutex
);
2680 mutex_unlock(&card
->discipline_mutex
);
2683 qeth_l3_stop_card(card
, 0);
2684 ccw_device_set_offline(CARD_DDEV(card
));
2685 ccw_device_set_offline(CARD_WDEV(card
));
2686 ccw_device_set_offline(CARD_RDEV(card
));
2687 qdio_free(CARD_DDEV(card
));
2688 if (recover_flag
== CARD_STATE_RECOVER
)
2689 card
->state
= CARD_STATE_RECOVER
;
2691 card
->state
= CARD_STATE_DOWN
;
2692 mutex_unlock(&card
->conf_mutex
);
2693 mutex_unlock(&card
->discipline_mutex
);
2697 static int qeth_l3_set_online(struct ccwgroup_device
*gdev
)
2699 return __qeth_l3_set_online(gdev
, 0);
2702 static int __qeth_l3_set_offline(struct ccwgroup_device
*cgdev
,
2705 struct qeth_card
*card
= dev_get_drvdata(&cgdev
->dev
);
2706 int rc
= 0, rc2
= 0, rc3
= 0;
2707 enum qeth_card_states recover_flag
;
2709 mutex_lock(&card
->discipline_mutex
);
2710 mutex_lock(&card
->conf_mutex
);
2711 QETH_DBF_TEXT(SETUP
, 3, "setoffl");
2712 QETH_DBF_HEX(SETUP
, 3, &card
, sizeof(void *));
2714 if (card
->dev
&& netif_carrier_ok(card
->dev
))
2715 netif_carrier_off(card
->dev
);
2716 recover_flag
= card
->state
;
2717 if ((!recovery_mode
&& card
->info
.hwtrap
) || card
->info
.hwtrap
== 2) {
2718 qeth_hw_trap(card
, QETH_DIAGS_TRAP_DISARM
);
2719 card
->info
.hwtrap
= 1;
2721 qeth_l3_stop_card(card
, recovery_mode
);
2722 if ((card
->options
.cq
== QETH_CQ_ENABLED
) && card
->dev
) {
2724 call_netdevice_notifiers(NETDEV_REBOOT
, card
->dev
);
2727 rc
= ccw_device_set_offline(CARD_DDEV(card
));
2728 rc2
= ccw_device_set_offline(CARD_WDEV(card
));
2729 rc3
= ccw_device_set_offline(CARD_RDEV(card
));
2731 rc
= (rc2
) ? rc2
: rc3
;
2733 QETH_DBF_TEXT_(SETUP
, 2, "1err%d", rc
);
2734 qdio_free(CARD_DDEV(card
));
2735 if (recover_flag
== CARD_STATE_UP
)
2736 card
->state
= CARD_STATE_RECOVER
;
2737 /* let user_space know that device is offline */
2738 kobject_uevent(&cgdev
->dev
.kobj
, KOBJ_CHANGE
);
2739 mutex_unlock(&card
->conf_mutex
);
2740 mutex_unlock(&card
->discipline_mutex
);
2744 static int qeth_l3_set_offline(struct ccwgroup_device
*cgdev
)
2746 return __qeth_l3_set_offline(cgdev
, 0);
2749 static int qeth_l3_recover(void *ptr
)
2751 struct qeth_card
*card
;
2754 card
= (struct qeth_card
*) ptr
;
2755 QETH_CARD_TEXT(card
, 2, "recover1");
2756 QETH_CARD_HEX(card
, 2, &card
, sizeof(void *));
2757 if (!qeth_do_run_thread(card
, QETH_RECOVER_THREAD
))
2759 QETH_CARD_TEXT(card
, 2, "recover2");
2760 dev_warn(&card
->gdev
->dev
,
2761 "A recovery process has been started for the device\n");
2762 qeth_set_recovery_task(card
);
2763 __qeth_l3_set_offline(card
->gdev
, 1);
2764 rc
= __qeth_l3_set_online(card
->gdev
, 1);
2766 dev_info(&card
->gdev
->dev
,
2767 "Device successfully recovered!\n");
2769 qeth_close_dev(card
);
2770 dev_warn(&card
->gdev
->dev
, "The qeth device driver "
2771 "failed to recover an error on the device\n");
2773 qeth_clear_recovery_task(card
);
2774 qeth_clear_thread_start_bit(card
, QETH_RECOVER_THREAD
);
2775 qeth_clear_thread_running_bit(card
, QETH_RECOVER_THREAD
);
2779 static int qeth_l3_pm_suspend(struct ccwgroup_device
*gdev
)
2781 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
2784 netif_device_detach(card
->dev
);
2785 qeth_set_allowed_threads(card
, 0, 1);
2786 wait_event(card
->wait_q
, qeth_threads_running(card
, 0xffffffff) == 0);
2787 if (gdev
->state
== CCWGROUP_OFFLINE
)
2789 if (card
->state
== CARD_STATE_UP
) {
2790 if (card
->info
.hwtrap
)
2791 qeth_hw_trap(card
, QETH_DIAGS_TRAP_DISARM
);
2792 __qeth_l3_set_offline(card
->gdev
, 1);
2794 __qeth_l3_set_offline(card
->gdev
, 0);
2798 static int qeth_l3_pm_resume(struct ccwgroup_device
*gdev
)
2800 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
2803 if (gdev
->state
== CCWGROUP_OFFLINE
)
2806 if (card
->state
== CARD_STATE_RECOVER
) {
2807 rc
= __qeth_l3_set_online(card
->gdev
, 1);
2810 dev_close(card
->dev
);
2814 rc
= __qeth_l3_set_online(card
->gdev
, 0);
2816 qeth_set_allowed_threads(card
, 0xffffffff, 0);
2818 netif_device_attach(card
->dev
);
2820 dev_warn(&card
->gdev
->dev
, "The qeth device driver "
2821 "failed to recover an error on the device\n");
2825 /* Returns zero if the command is successfully "consumed" */
2826 static int qeth_l3_control_event(struct qeth_card
*card
,
2827 struct qeth_ipa_cmd
*cmd
)
2832 struct qeth_discipline qeth_l3_discipline
= {
2833 .devtype
= &qeth_l3_devtype
,
2834 .process_rx_buffer
= qeth_l3_process_inbound_buffer
,
2835 .recover
= qeth_l3_recover
,
2836 .setup
= qeth_l3_probe_device
,
2837 .remove
= qeth_l3_remove_device
,
2838 .set_online
= qeth_l3_set_online
,
2839 .set_offline
= qeth_l3_set_offline
,
2840 .freeze
= qeth_l3_pm_suspend
,
2841 .thaw
= qeth_l3_pm_resume
,
2842 .restore
= qeth_l3_pm_resume
,
2843 .do_ioctl
= qeth_l3_do_ioctl
,
2844 .control_event_handler
= qeth_l3_control_event
,
2846 EXPORT_SYMBOL_GPL(qeth_l3_discipline
);
2848 static int qeth_l3_handle_ip_event(struct qeth_card
*card
,
2849 struct qeth_ipaddr
*addr
,
2850 unsigned long event
)
2854 spin_lock_bh(&card
->ip_lock
);
2855 qeth_l3_add_ip(card
, addr
);
2856 spin_unlock_bh(&card
->ip_lock
);
2859 spin_lock_bh(&card
->ip_lock
);
2860 qeth_l3_delete_ip(card
, addr
);
2861 spin_unlock_bh(&card
->ip_lock
);
2868 static struct qeth_card
*qeth_l3_get_card_from_dev(struct net_device
*dev
)
2870 if (is_vlan_dev(dev
))
2871 dev
= vlan_dev_real_dev(dev
);
2872 if (dev
->netdev_ops
== &qeth_l3_osa_netdev_ops
||
2873 dev
->netdev_ops
== &qeth_l3_netdev_ops
)
2874 return (struct qeth_card
*) dev
->ml_priv
;
2878 static int qeth_l3_ip_event(struct notifier_block
*this,
2879 unsigned long event
, void *ptr
)
2882 struct in_ifaddr
*ifa
= (struct in_ifaddr
*)ptr
;
2883 struct net_device
*dev
= ifa
->ifa_dev
->dev
;
2884 struct qeth_ipaddr addr
;
2885 struct qeth_card
*card
;
2887 if (dev_net(dev
) != &init_net
)
2890 card
= qeth_l3_get_card_from_dev(dev
);
2893 QETH_CARD_TEXT(card
, 3, "ipevent");
2895 qeth_l3_init_ipaddr(&addr
, QETH_IP_TYPE_NORMAL
, QETH_PROT_IPV4
);
2896 addr
.u
.a4
.addr
= be32_to_cpu(ifa
->ifa_address
);
2897 addr
.u
.a4
.mask
= be32_to_cpu(ifa
->ifa_mask
);
2899 return qeth_l3_handle_ip_event(card
, &addr
, event
);
2902 static struct notifier_block qeth_l3_ip_notifier
= {
2907 static int qeth_l3_ip6_event(struct notifier_block
*this,
2908 unsigned long event
, void *ptr
)
2910 struct inet6_ifaddr
*ifa
= (struct inet6_ifaddr
*)ptr
;
2911 struct net_device
*dev
= ifa
->idev
->dev
;
2912 struct qeth_ipaddr addr
;
2913 struct qeth_card
*card
;
2915 card
= qeth_l3_get_card_from_dev(dev
);
2918 QETH_CARD_TEXT(card
, 3, "ip6event");
2919 if (!qeth_is_supported(card
, IPA_IPV6
))
2922 qeth_l3_init_ipaddr(&addr
, QETH_IP_TYPE_NORMAL
, QETH_PROT_IPV6
);
2923 addr
.u
.a6
.addr
= ifa
->addr
;
2924 addr
.u
.a6
.pfxlen
= ifa
->prefix_len
;
2926 return qeth_l3_handle_ip_event(card
, &addr
, event
);
2929 static struct notifier_block qeth_l3_ip6_notifier
= {
2934 static int qeth_l3_register_notifiers(void)
2938 QETH_DBF_TEXT(SETUP
, 5, "regnotif");
2939 rc
= register_inetaddr_notifier(&qeth_l3_ip_notifier
);
2942 rc
= register_inet6addr_notifier(&qeth_l3_ip6_notifier
);
2944 unregister_inetaddr_notifier(&qeth_l3_ip_notifier
);
2950 static void qeth_l3_unregister_notifiers(void)
2952 QETH_DBF_TEXT(SETUP
, 5, "unregnot");
2953 WARN_ON(unregister_inetaddr_notifier(&qeth_l3_ip_notifier
));
2954 WARN_ON(unregister_inet6addr_notifier(&qeth_l3_ip6_notifier
));
2957 static int __init
qeth_l3_init(void)
2959 pr_info("register layer 3 discipline\n");
2960 return qeth_l3_register_notifiers();
2963 static void __exit
qeth_l3_exit(void)
2965 qeth_l3_unregister_notifiers();
2966 pr_info("unregister layer 3 discipline\n");
2969 module_init(qeth_l3_init
);
2970 module_exit(qeth_l3_exit
);
2971 MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
2972 MODULE_DESCRIPTION("qeth layer 3 discipline");
2973 MODULE_LICENSE("GPL");