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/iucv/af_iucv.h>
36 #include <linux/hashtable.h>
41 static int qeth_l3_set_offline(struct ccwgroup_device
*);
42 static int qeth_l3_register_addr_entry(struct qeth_card
*,
43 struct qeth_ipaddr
*);
44 static int qeth_l3_deregister_addr_entry(struct qeth_card
*,
45 struct qeth_ipaddr
*);
47 static void qeth_l3_ipaddr4_to_string(const __u8
*addr
, char *buf
)
49 sprintf(buf
, "%pI4", addr
);
52 static void qeth_l3_ipaddr6_to_string(const __u8
*addr
, char *buf
)
54 sprintf(buf
, "%pI6", addr
);
57 void qeth_l3_ipaddr_to_string(enum qeth_prot_versions proto
, const __u8
*addr
,
60 if (proto
== QETH_PROT_IPV4
)
61 qeth_l3_ipaddr4_to_string(addr
, buf
);
62 else if (proto
== QETH_PROT_IPV6
)
63 qeth_l3_ipaddr6_to_string(addr
, buf
);
66 static struct qeth_ipaddr
*qeth_l3_find_addr_by_ip(struct qeth_card
*card
,
67 struct qeth_ipaddr
*query
)
69 u32 key
= qeth_l3_ipaddr_hash(query
);
70 struct qeth_ipaddr
*addr
;
72 if (query
->is_multicast
) {
73 hash_for_each_possible(card
->ip_mc_htable
, addr
, hnode
, key
)
74 if (qeth_l3_addr_match_ip(addr
, query
))
77 hash_for_each_possible(card
->ip_htable
, addr
, hnode
, key
)
78 if (qeth_l3_addr_match_ip(addr
, query
))
84 static void qeth_l3_convert_addr_to_bits(u8
*addr
, u8
*bits
, int len
)
89 for (i
= 0; i
< len
; ++i
) {
91 for (j
= 7; j
>= 0; --j
) {
92 bits
[i
*8 + j
] = octet
& 1;
98 static bool qeth_l3_is_addr_covered_by_ipato(struct qeth_card
*card
,
99 struct qeth_ipaddr
*addr
)
101 struct qeth_ipato_entry
*ipatoe
;
102 u8 addr_bits
[128] = {0, };
103 u8 ipatoe_bits
[128] = {0, };
106 if (!card
->ipato
.enabled
)
108 if (addr
->type
!= QETH_IP_TYPE_NORMAL
)
111 qeth_l3_convert_addr_to_bits((u8
*) &addr
->u
, addr_bits
,
112 (addr
->proto
== QETH_PROT_IPV4
)? 4:16);
113 list_for_each_entry(ipatoe
, &card
->ipato
.entries
, entry
) {
114 if (addr
->proto
!= ipatoe
->proto
)
116 qeth_l3_convert_addr_to_bits(ipatoe
->addr
, ipatoe_bits
,
117 (ipatoe
->proto
== QETH_PROT_IPV4
) ?
119 if (addr
->proto
== QETH_PROT_IPV4
)
120 rc
= !memcmp(addr_bits
, ipatoe_bits
,
121 min(32, ipatoe
->mask_bits
));
123 rc
= !memcmp(addr_bits
, ipatoe_bits
,
124 min(128, ipatoe
->mask_bits
));
129 if ((addr
->proto
== QETH_PROT_IPV4
) && card
->ipato
.invert4
)
131 else if ((addr
->proto
== QETH_PROT_IPV6
) && card
->ipato
.invert6
)
137 static int qeth_l3_delete_ip(struct qeth_card
*card
,
138 struct qeth_ipaddr
*tmp_addr
)
141 struct qeth_ipaddr
*addr
;
143 if (tmp_addr
->type
== QETH_IP_TYPE_RXIP
)
144 QETH_CARD_TEXT(card
, 2, "delrxip");
145 else if (tmp_addr
->type
== QETH_IP_TYPE_VIPA
)
146 QETH_CARD_TEXT(card
, 2, "delvipa");
148 QETH_CARD_TEXT(card
, 2, "delip");
150 if (tmp_addr
->proto
== QETH_PROT_IPV4
)
151 QETH_CARD_HEX(card
, 4, &tmp_addr
->u
.a4
.addr
, 4);
153 QETH_CARD_HEX(card
, 4, &tmp_addr
->u
.a6
.addr
, 8);
154 QETH_CARD_HEX(card
, 4, ((char *)&tmp_addr
->u
.a6
.addr
) + 8, 8);
157 addr
= qeth_l3_find_addr_by_ip(card
, tmp_addr
);
158 if (!addr
|| !qeth_l3_addr_match_all(addr
, tmp_addr
))
162 if (addr
->type
== QETH_IP_TYPE_NORMAL
&& addr
->ref_counter
> 0)
164 if (addr
->in_progress
)
167 if (qeth_card_hw_is_reachable(card
))
168 rc
= qeth_l3_deregister_addr_entry(card
, addr
);
170 hash_del(&addr
->hnode
);
176 static int qeth_l3_add_ip(struct qeth_card
*card
, struct qeth_ipaddr
*tmp_addr
)
179 struct qeth_ipaddr
*addr
;
182 if (tmp_addr
->type
== QETH_IP_TYPE_RXIP
)
183 QETH_CARD_TEXT(card
, 2, "addrxip");
184 else if (tmp_addr
->type
== QETH_IP_TYPE_VIPA
)
185 QETH_CARD_TEXT(card
, 2, "addvipa");
187 QETH_CARD_TEXT(card
, 2, "addip");
189 if (tmp_addr
->proto
== QETH_PROT_IPV4
)
190 QETH_CARD_HEX(card
, 4, &tmp_addr
->u
.a4
.addr
, 4);
192 QETH_CARD_HEX(card
, 4, &tmp_addr
->u
.a6
.addr
, 8);
193 QETH_CARD_HEX(card
, 4, ((char *)&tmp_addr
->u
.a6
.addr
) + 8, 8);
196 addr
= qeth_l3_find_addr_by_ip(card
, tmp_addr
);
198 if (tmp_addr
->type
!= QETH_IP_TYPE_NORMAL
)
200 if (qeth_l3_addr_match_all(addr
, tmp_addr
)) {
204 qeth_l3_ipaddr_to_string(tmp_addr
->proto
, (u8
*)&tmp_addr
->u
,
206 dev_warn(&card
->gdev
->dev
,
207 "Registering IP address %s failed\n", buf
);
210 addr
= kmemdup(tmp_addr
, sizeof(*tmp_addr
), GFP_KERNEL
);
214 if (qeth_l3_is_addr_covered_by_ipato(card
, addr
)) {
215 QETH_CARD_TEXT(card
, 2, "tkovaddr");
218 hash_add(card
->ip_htable
, &addr
->hnode
,
219 qeth_l3_ipaddr_hash(addr
));
221 if (!qeth_card_hw_is_reachable(card
)) {
222 addr
->disp_flag
= QETH_DISP_ADDR_ADD
;
226 /* qeth_l3_register_addr_entry can go to sleep
227 * if we add a IPV4 addr. It is caused by the reason
228 * that SETIP ipa cmd starts ARP staff for IPV4 addr.
229 * Thus we should unlock spinlock, and make a protection
230 * using in_progress variable to indicate that there is
231 * an hardware operation with this IPV4 address
233 if (addr
->proto
== QETH_PROT_IPV4
) {
234 addr
->in_progress
= 1;
235 mutex_unlock(&card
->ip_lock
);
236 rc
= qeth_l3_register_addr_entry(card
, addr
);
237 mutex_lock(&card
->ip_lock
);
238 addr
->in_progress
= 0;
240 rc
= qeth_l3_register_addr_entry(card
, addr
);
242 if (!rc
|| rc
== -EADDRINUSE
|| rc
== -ENETDOWN
) {
243 addr
->disp_flag
= QETH_DISP_ADDR_DO_NOTHING
;
244 if (addr
->ref_counter
< 1) {
245 qeth_l3_deregister_addr_entry(card
, addr
);
246 hash_del(&addr
->hnode
);
250 hash_del(&addr
->hnode
);
257 static int qeth_l3_modify_ip(struct qeth_card
*card
, struct qeth_ipaddr
*addr
,
262 mutex_lock(&card
->ip_lock
);
263 rc
= add
? qeth_l3_add_ip(card
, addr
) : qeth_l3_delete_ip(card
, addr
);
264 mutex_unlock(&card
->ip_lock
);
269 static void qeth_l3_drain_rx_mode_cache(struct qeth_card
*card
)
271 struct qeth_ipaddr
*addr
;
272 struct hlist_node
*tmp
;
275 hash_for_each_safe(card
->ip_mc_htable
, i
, tmp
, addr
, hnode
) {
276 hash_del(&addr
->hnode
);
281 static void qeth_l3_clear_ip_htable(struct qeth_card
*card
, int recover
)
283 struct qeth_ipaddr
*addr
;
284 struct hlist_node
*tmp
;
287 QETH_CARD_TEXT(card
, 4, "clearip");
289 mutex_lock(&card
->ip_lock
);
291 hash_for_each_safe(card
->ip_htable
, i
, tmp
, addr
, hnode
) {
293 hash_del(&addr
->hnode
);
297 addr
->disp_flag
= QETH_DISP_ADDR_ADD
;
300 mutex_unlock(&card
->ip_lock
);
303 static void qeth_l3_recover_ip(struct qeth_card
*card
)
305 struct qeth_ipaddr
*addr
;
306 struct hlist_node
*tmp
;
310 QETH_CARD_TEXT(card
, 4, "recovrip");
312 mutex_lock(&card
->ip_lock
);
314 hash_for_each_safe(card
->ip_htable
, i
, tmp
, addr
, hnode
) {
315 if (addr
->disp_flag
== QETH_DISP_ADDR_ADD
) {
316 if (addr
->proto
== QETH_PROT_IPV4
) {
317 addr
->in_progress
= 1;
318 mutex_unlock(&card
->ip_lock
);
319 rc
= qeth_l3_register_addr_entry(card
, addr
);
320 mutex_lock(&card
->ip_lock
);
321 addr
->in_progress
= 0;
323 rc
= qeth_l3_register_addr_entry(card
, addr
);
326 addr
->disp_flag
= QETH_DISP_ADDR_DO_NOTHING
;
327 if (addr
->ref_counter
< 1)
328 qeth_l3_delete_ip(card
, addr
);
330 hash_del(&addr
->hnode
);
336 mutex_unlock(&card
->ip_lock
);
339 static int qeth_l3_setdelip_cb(struct qeth_card
*card
, struct qeth_reply
*reply
,
342 struct qeth_ipa_cmd
*cmd
= (struct qeth_ipa_cmd
*) data
;
344 switch (cmd
->hdr
.return_code
) {
347 case IPA_RC_DUPLICATE_IP_ADDRESS
:
349 case IPA_RC_MC_ADDR_NOT_FOUND
:
351 case IPA_RC_LAN_OFFLINE
:
358 static int qeth_l3_send_setdelmc(struct qeth_card
*card
,
359 struct qeth_ipaddr
*addr
, int ipacmd
)
361 struct qeth_cmd_buffer
*iob
;
362 struct qeth_ipa_cmd
*cmd
;
364 QETH_CARD_TEXT(card
, 4, "setdelmc");
366 iob
= qeth_ipa_alloc_cmd(card
, ipacmd
, addr
->proto
,
367 IPA_DATA_SIZEOF(setdelipm
));
370 cmd
= __ipa_cmd(iob
);
371 if (addr
->proto
== QETH_PROT_IPV6
) {
372 cmd
->data
.setdelipm
.ip
= addr
->u
.a6
.addr
;
373 ipv6_eth_mc_map(&addr
->u
.a6
.addr
, cmd
->data
.setdelipm
.mac
);
375 cmd
->data
.setdelipm
.ip
.s6_addr32
[3] = addr
->u
.a4
.addr
;
376 ip_eth_mc_map(addr
->u
.a4
.addr
, cmd
->data
.setdelipm
.mac
);
379 return qeth_send_ipa_cmd(card
, iob
, qeth_l3_setdelip_cb
, NULL
);
382 static void qeth_l3_fill_netmask(u8
*netmask
, unsigned int len
)
385 for (i
= 0; i
< 16; i
++) {
390 netmask
[i
] = (u8
)(0xFF00 >> j
);
396 static u32
qeth_l3_get_setdelip_flags(struct qeth_ipaddr
*addr
, bool set
)
398 switch (addr
->type
) {
399 case QETH_IP_TYPE_RXIP
:
400 return (set
) ? QETH_IPA_SETIP_TAKEOVER_FLAG
: 0;
401 case QETH_IP_TYPE_VIPA
:
402 return (set
) ? QETH_IPA_SETIP_VIPA_FLAG
:
403 QETH_IPA_DELIP_VIPA_FLAG
;
405 return (set
&& addr
->ipato
) ? QETH_IPA_SETIP_TAKEOVER_FLAG
: 0;
409 static int qeth_l3_send_setdelip(struct qeth_card
*card
,
410 struct qeth_ipaddr
*addr
,
411 enum qeth_ipa_cmds ipacmd
)
413 struct qeth_cmd_buffer
*iob
;
414 struct qeth_ipa_cmd
*cmd
;
418 QETH_CARD_TEXT(card
, 4, "setdelip");
420 iob
= qeth_ipa_alloc_cmd(card
, ipacmd
, addr
->proto
,
421 IPA_DATA_SIZEOF(setdelip6
));
424 cmd
= __ipa_cmd(iob
);
426 flags
= qeth_l3_get_setdelip_flags(addr
, ipacmd
== IPA_CMD_SETIP
);
427 QETH_CARD_TEXT_(card
, 4, "flags%02X", flags
);
429 if (addr
->proto
== QETH_PROT_IPV6
) {
430 memcpy(cmd
->data
.setdelip6
.ip_addr
, &addr
->u
.a6
.addr
,
431 sizeof(struct in6_addr
));
432 qeth_l3_fill_netmask(netmask
, addr
->u
.a6
.pfxlen
);
433 memcpy(cmd
->data
.setdelip6
.mask
, netmask
,
434 sizeof(struct in6_addr
));
435 cmd
->data
.setdelip6
.flags
= flags
;
437 memcpy(cmd
->data
.setdelip4
.ip_addr
, &addr
->u
.a4
.addr
, 4);
438 memcpy(cmd
->data
.setdelip4
.mask
, &addr
->u
.a4
.mask
, 4);
439 cmd
->data
.setdelip4
.flags
= flags
;
442 return qeth_send_ipa_cmd(card
, iob
, qeth_l3_setdelip_cb
, NULL
);
445 static int qeth_l3_send_setrouting(struct qeth_card
*card
,
446 enum qeth_routing_types type
, enum qeth_prot_versions prot
)
449 struct qeth_ipa_cmd
*cmd
;
450 struct qeth_cmd_buffer
*iob
;
452 QETH_CARD_TEXT(card
, 4, "setroutg");
453 iob
= qeth_ipa_alloc_cmd(card
, IPA_CMD_SETRTG
, prot
,
454 IPA_DATA_SIZEOF(setrtg
));
457 cmd
= __ipa_cmd(iob
);
458 cmd
->data
.setrtg
.type
= (type
);
459 rc
= qeth_send_ipa_cmd(card
, iob
, NULL
, NULL
);
464 static int qeth_l3_correct_routing_type(struct qeth_card
*card
,
465 enum qeth_routing_types
*type
, enum qeth_prot_versions prot
)
470 case PRIMARY_CONNECTOR
:
471 case SECONDARY_CONNECTOR
:
472 case MULTICAST_ROUTER
:
481 case SECONDARY_ROUTER
:
483 case MULTICAST_ROUTER
:
484 if (qeth_is_ipafunc_supported(card
, prot
,
496 int qeth_l3_setrouting_v4(struct qeth_card
*card
)
500 QETH_CARD_TEXT(card
, 3, "setrtg4");
502 rc
= qeth_l3_correct_routing_type(card
, &card
->options
.route4
.type
,
507 rc
= qeth_l3_send_setrouting(card
, card
->options
.route4
.type
,
510 card
->options
.route4
.type
= NO_ROUTER
;
511 QETH_DBF_MESSAGE(2, "Error (%#06x) while setting routing type on device %x. Type set to 'no router'.\n",
512 rc
, CARD_DEVID(card
));
517 int qeth_l3_setrouting_v6(struct qeth_card
*card
)
521 QETH_CARD_TEXT(card
, 3, "setrtg6");
523 if (!qeth_is_supported(card
, IPA_IPV6
))
525 rc
= qeth_l3_correct_routing_type(card
, &card
->options
.route6
.type
,
530 rc
= qeth_l3_send_setrouting(card
, card
->options
.route6
.type
,
533 card
->options
.route6
.type
= NO_ROUTER
;
534 QETH_DBF_MESSAGE(2, "Error (%#06x) while setting routing type on device %x. Type set to 'no router'.\n",
535 rc
, CARD_DEVID(card
));
541 * IP address takeover related functions
545 * qeth_l3_update_ipato() - Update 'takeover' property, for all NORMAL IPs.
547 * Caller must hold ip_lock.
549 void qeth_l3_update_ipato(struct qeth_card
*card
)
551 struct qeth_ipaddr
*addr
;
554 hash_for_each(card
->ip_htable
, i
, addr
, hnode
) {
555 if (addr
->type
!= QETH_IP_TYPE_NORMAL
)
557 addr
->ipato
= qeth_l3_is_addr_covered_by_ipato(card
, addr
);
561 static void qeth_l3_clear_ipato_list(struct qeth_card
*card
)
563 struct qeth_ipato_entry
*ipatoe
, *tmp
;
565 mutex_lock(&card
->ip_lock
);
567 list_for_each_entry_safe(ipatoe
, tmp
, &card
->ipato
.entries
, entry
) {
568 list_del(&ipatoe
->entry
);
572 qeth_l3_update_ipato(card
);
573 mutex_unlock(&card
->ip_lock
);
576 int qeth_l3_add_ipato_entry(struct qeth_card
*card
,
577 struct qeth_ipato_entry
*new)
579 struct qeth_ipato_entry
*ipatoe
;
582 QETH_CARD_TEXT(card
, 2, "addipato");
584 mutex_lock(&card
->ip_lock
);
586 list_for_each_entry(ipatoe
, &card
->ipato
.entries
, entry
) {
587 if (ipatoe
->proto
!= new->proto
)
589 if (!memcmp(ipatoe
->addr
, new->addr
,
590 (ipatoe
->proto
== QETH_PROT_IPV4
)? 4:16) &&
591 (ipatoe
->mask_bits
== new->mask_bits
)) {
598 list_add_tail(&new->entry
, &card
->ipato
.entries
);
599 qeth_l3_update_ipato(card
);
602 mutex_unlock(&card
->ip_lock
);
607 int qeth_l3_del_ipato_entry(struct qeth_card
*card
,
608 enum qeth_prot_versions proto
, u8
*addr
,
611 struct qeth_ipato_entry
*ipatoe
, *tmp
;
614 QETH_CARD_TEXT(card
, 2, "delipato");
616 mutex_lock(&card
->ip_lock
);
618 list_for_each_entry_safe(ipatoe
, tmp
, &card
->ipato
.entries
, entry
) {
619 if (ipatoe
->proto
!= proto
)
621 if (!memcmp(ipatoe
->addr
, addr
,
622 (proto
== QETH_PROT_IPV4
)? 4:16) &&
623 (ipatoe
->mask_bits
== mask_bits
)) {
624 list_del(&ipatoe
->entry
);
625 qeth_l3_update_ipato(card
);
631 mutex_unlock(&card
->ip_lock
);
635 int qeth_l3_modify_rxip_vipa(struct qeth_card
*card
, bool add
, const u8
*ip
,
636 enum qeth_ip_types type
,
637 enum qeth_prot_versions proto
)
639 struct qeth_ipaddr addr
;
641 qeth_l3_init_ipaddr(&addr
, type
, proto
);
642 if (proto
== QETH_PROT_IPV4
)
643 memcpy(&addr
.u
.a4
.addr
, ip
, 4);
645 memcpy(&addr
.u
.a6
.addr
, ip
, 16);
647 return qeth_l3_modify_ip(card
, &addr
, add
);
650 int qeth_l3_modify_hsuid(struct qeth_card
*card
, bool add
)
652 struct qeth_ipaddr addr
;
655 qeth_l3_init_ipaddr(&addr
, QETH_IP_TYPE_NORMAL
, QETH_PROT_IPV6
);
656 addr
.u
.a6
.addr
.s6_addr
[0] = 0xfe;
657 addr
.u
.a6
.addr
.s6_addr
[1] = 0x80;
658 for (i
= 0; i
< 8; i
++)
659 addr
.u
.a6
.addr
.s6_addr
[8+i
] = card
->options
.hsuid
[i
];
661 return qeth_l3_modify_ip(card
, &addr
, add
);
664 static int qeth_l3_register_addr_entry(struct qeth_card
*card
,
665 struct qeth_ipaddr
*addr
)
671 if (card
->options
.sniffer
)
674 if (addr
->proto
== QETH_PROT_IPV4
) {
675 QETH_CARD_TEXT(card
, 2, "setaddr4");
676 QETH_CARD_HEX(card
, 3, &addr
->u
.a4
.addr
, sizeof(int));
677 } else if (addr
->proto
== QETH_PROT_IPV6
) {
678 QETH_CARD_TEXT(card
, 2, "setaddr6");
679 QETH_CARD_HEX(card
, 3, &addr
->u
.a6
.addr
, 8);
680 QETH_CARD_HEX(card
, 3, ((char *)&addr
->u
.a6
.addr
) + 8, 8);
682 QETH_CARD_TEXT(card
, 2, "setaddr?");
683 QETH_CARD_HEX(card
, 3, addr
, sizeof(struct qeth_ipaddr
));
686 if (addr
->is_multicast
)
687 rc
= qeth_l3_send_setdelmc(card
, addr
, IPA_CMD_SETIPM
);
689 rc
= qeth_l3_send_setdelip(card
, addr
, IPA_CMD_SETIP
);
691 QETH_CARD_TEXT(card
, 2, "failed");
692 } while ((--cnt
> 0) && rc
);
694 QETH_CARD_TEXT(card
, 2, "FAILED");
695 qeth_l3_ipaddr_to_string(addr
->proto
, (u8
*)&addr
->u
, buf
);
696 dev_warn(&card
->gdev
->dev
,
697 "Registering IP address %s failed\n", buf
);
702 static int qeth_l3_deregister_addr_entry(struct qeth_card
*card
,
703 struct qeth_ipaddr
*addr
)
707 if (card
->options
.sniffer
)
710 if (addr
->proto
== QETH_PROT_IPV4
) {
711 QETH_CARD_TEXT(card
, 2, "deladdr4");
712 QETH_CARD_HEX(card
, 3, &addr
->u
.a4
.addr
, sizeof(int));
713 } else if (addr
->proto
== QETH_PROT_IPV6
) {
714 QETH_CARD_TEXT(card
, 2, "deladdr6");
715 QETH_CARD_HEX(card
, 3, &addr
->u
.a6
.addr
, 8);
716 QETH_CARD_HEX(card
, 3, ((char *)&addr
->u
.a6
.addr
) + 8, 8);
718 QETH_CARD_TEXT(card
, 2, "deladdr?");
719 QETH_CARD_HEX(card
, 3, addr
, sizeof(struct qeth_ipaddr
));
721 if (addr
->is_multicast
)
722 rc
= qeth_l3_send_setdelmc(card
, addr
, IPA_CMD_DELIPM
);
724 rc
= qeth_l3_send_setdelip(card
, addr
, IPA_CMD_DELIP
);
726 QETH_CARD_TEXT(card
, 2, "failed");
731 static int qeth_l3_setadapter_parms(struct qeth_card
*card
)
735 QETH_CARD_TEXT(card
, 2, "setadprm");
737 if (qeth_adp_supported(card
, IPA_SETADP_ALTER_MAC_ADDRESS
)) {
738 rc
= qeth_setadpparms_change_macaddr(card
);
740 dev_warn(&card
->gdev
->dev
, "Reading the adapter MAC"
741 " address failed\n");
747 static int qeth_l3_start_ipa_arp_processing(struct qeth_card
*card
)
751 QETH_CARD_TEXT(card
, 3, "ipaarp");
753 if (!qeth_is_supported(card
, IPA_ARP_PROCESSING
)) {
754 dev_info(&card
->gdev
->dev
,
755 "ARP processing not supported on %s!\n",
756 QETH_CARD_IFNAME(card
));
759 rc
= qeth_send_simple_setassparms(card
, IPA_ARP_PROCESSING
,
760 IPA_CMD_ASS_START
, NULL
);
762 dev_warn(&card
->gdev
->dev
,
763 "Starting ARP processing support for %s failed\n",
764 QETH_CARD_IFNAME(card
));
769 static int qeth_l3_start_ipa_source_mac(struct qeth_card
*card
)
773 QETH_CARD_TEXT(card
, 3, "stsrcmac");
775 if (!qeth_is_supported(card
, IPA_SOURCE_MAC
)) {
776 dev_info(&card
->gdev
->dev
,
777 "Inbound source MAC-address not supported on %s\n",
778 QETH_CARD_IFNAME(card
));
782 rc
= qeth_send_simple_setassparms(card
, IPA_SOURCE_MAC
,
783 IPA_CMD_ASS_START
, NULL
);
785 dev_warn(&card
->gdev
->dev
,
786 "Starting source MAC-address support for %s failed\n",
787 QETH_CARD_IFNAME(card
));
791 static int qeth_l3_start_ipa_vlan(struct qeth_card
*card
)
795 QETH_CARD_TEXT(card
, 3, "strtvlan");
797 if (!qeth_is_supported(card
, IPA_FULL_VLAN
)) {
798 dev_info(&card
->gdev
->dev
,
799 "VLAN not supported on %s\n", QETH_CARD_IFNAME(card
));
803 rc
= qeth_send_simple_setassparms(card
, IPA_VLAN_PRIO
,
804 IPA_CMD_ASS_START
, NULL
);
806 dev_warn(&card
->gdev
->dev
,
807 "Starting VLAN support for %s failed\n",
808 QETH_CARD_IFNAME(card
));
810 dev_info(&card
->gdev
->dev
, "VLAN enabled\n");
815 static int qeth_l3_start_ipa_multicast(struct qeth_card
*card
)
819 QETH_CARD_TEXT(card
, 3, "stmcast");
821 if (!qeth_is_supported(card
, IPA_MULTICASTING
)) {
822 dev_info(&card
->gdev
->dev
,
823 "Multicast not supported on %s\n",
824 QETH_CARD_IFNAME(card
));
828 rc
= qeth_send_simple_setassparms(card
, IPA_MULTICASTING
,
829 IPA_CMD_ASS_START
, NULL
);
831 dev_warn(&card
->gdev
->dev
,
832 "Starting multicast support for %s failed\n",
833 QETH_CARD_IFNAME(card
));
835 dev_info(&card
->gdev
->dev
, "Multicast enabled\n");
836 card
->dev
->flags
|= IFF_MULTICAST
;
841 static int qeth_l3_softsetup_ipv6(struct qeth_card
*card
)
846 QETH_CARD_TEXT(card
, 3, "softipv6");
851 rc
= qeth_send_simple_setassparms(card
, IPA_IPV6
, IPA_CMD_ASS_START
,
854 dev_err(&card
->gdev
->dev
,
855 "Activating IPv6 support for %s failed\n",
856 QETH_CARD_IFNAME(card
));
859 rc
= qeth_send_simple_setassparms_v6(card
, IPA_IPV6
, IPA_CMD_ASS_START
,
862 dev_err(&card
->gdev
->dev
,
863 "Activating IPv6 support for %s failed\n",
864 QETH_CARD_IFNAME(card
));
867 rc
= qeth_send_simple_setassparms_v6(card
, IPA_PASSTHRU
,
868 IPA_CMD_ASS_START
, NULL
);
870 dev_warn(&card
->gdev
->dev
,
871 "Enabling the passthrough mode for %s failed\n",
872 QETH_CARD_IFNAME(card
));
876 dev_info(&card
->gdev
->dev
, "IPV6 enabled\n");
880 static int qeth_l3_start_ipa_ipv6(struct qeth_card
*card
)
882 QETH_CARD_TEXT(card
, 3, "strtipv6");
884 if (!qeth_is_supported(card
, IPA_IPV6
)) {
885 dev_info(&card
->gdev
->dev
,
886 "IPv6 not supported on %s\n", QETH_CARD_IFNAME(card
));
889 return qeth_l3_softsetup_ipv6(card
);
892 static int qeth_l3_start_ipa_broadcast(struct qeth_card
*card
)
897 QETH_CARD_TEXT(card
, 3, "stbrdcst");
898 card
->info
.broadcast_capable
= 0;
899 if (!qeth_is_supported(card
, IPA_FILTERING
)) {
900 dev_info(&card
->gdev
->dev
,
901 "Broadcast not supported on %s\n",
902 QETH_CARD_IFNAME(card
));
906 rc
= qeth_send_simple_setassparms(card
, IPA_FILTERING
,
907 IPA_CMD_ASS_START
, NULL
);
909 dev_warn(&card
->gdev
->dev
, "Enabling broadcast filtering for "
910 "%s failed\n", QETH_CARD_IFNAME(card
));
914 rc
= qeth_send_simple_setassparms(card
, IPA_FILTERING
,
915 IPA_CMD_ASS_CONFIGURE
, &filter_data
);
917 dev_warn(&card
->gdev
->dev
,
918 "Setting up broadcast filtering for %s failed\n",
919 QETH_CARD_IFNAME(card
));
922 card
->info
.broadcast_capable
= QETH_BROADCAST_WITH_ECHO
;
923 dev_info(&card
->gdev
->dev
, "Broadcast enabled\n");
924 rc
= qeth_send_simple_setassparms(card
, IPA_FILTERING
,
925 IPA_CMD_ASS_ENABLE
, &filter_data
);
927 dev_warn(&card
->gdev
->dev
, "Setting up broadcast echo "
928 "filtering for %s failed\n", QETH_CARD_IFNAME(card
));
931 card
->info
.broadcast_capable
= QETH_BROADCAST_WITHOUT_ECHO
;
933 if (card
->info
.broadcast_capable
)
934 card
->dev
->flags
|= IFF_BROADCAST
;
936 card
->dev
->flags
&= ~IFF_BROADCAST
;
940 static int qeth_l3_start_ipassists(struct qeth_card
*card
)
942 QETH_CARD_TEXT(card
, 3, "strtipas");
944 qeth_l3_start_ipa_arp_processing(card
); /* go on*/
945 qeth_l3_start_ipa_source_mac(card
); /* go on*/
946 qeth_l3_start_ipa_vlan(card
); /* go on*/
947 qeth_l3_start_ipa_multicast(card
); /* go on*/
948 qeth_l3_start_ipa_ipv6(card
); /* go on*/
949 qeth_l3_start_ipa_broadcast(card
); /* go on*/
953 static int qeth_l3_iqd_read_initial_mac_cb(struct qeth_card
*card
,
954 struct qeth_reply
*reply
, unsigned long data
)
956 struct qeth_ipa_cmd
*cmd
= (struct qeth_ipa_cmd
*) data
;
958 if (cmd
->hdr
.return_code
)
961 ether_addr_copy(card
->dev
->dev_addr
,
962 cmd
->data
.create_destroy_addr
.unique_id
);
966 static int qeth_l3_iqd_read_initial_mac(struct qeth_card
*card
)
969 struct qeth_cmd_buffer
*iob
;
970 struct qeth_ipa_cmd
*cmd
;
972 QETH_CARD_TEXT(card
, 2, "hsrmac");
974 iob
= qeth_ipa_alloc_cmd(card
, IPA_CMD_CREATE_ADDR
, QETH_PROT_IPV6
,
975 IPA_DATA_SIZEOF(create_destroy_addr
));
978 cmd
= __ipa_cmd(iob
);
979 *((__u16
*) &cmd
->data
.create_destroy_addr
.unique_id
[6]) =
980 card
->info
.unique_id
;
982 rc
= qeth_send_ipa_cmd(card
, iob
, qeth_l3_iqd_read_initial_mac_cb
,
987 static int qeth_l3_get_unique_id_cb(struct qeth_card
*card
,
988 struct qeth_reply
*reply
, unsigned long data
)
990 struct qeth_ipa_cmd
*cmd
= (struct qeth_ipa_cmd
*) data
;
992 if (cmd
->hdr
.return_code
== 0) {
993 card
->info
.unique_id
= *((__u16
*)
994 &cmd
->data
.create_destroy_addr
.unique_id
[6]);
998 card
->info
.unique_id
= UNIQUE_ID_IF_CREATE_ADDR_FAILED
|
999 UNIQUE_ID_NOT_BY_CARD
;
1000 dev_warn(&card
->gdev
->dev
, "The network adapter failed to generate a unique ID\n");
1004 static int qeth_l3_get_unique_id(struct qeth_card
*card
)
1007 struct qeth_cmd_buffer
*iob
;
1008 struct qeth_ipa_cmd
*cmd
;
1010 QETH_CARD_TEXT(card
, 2, "guniqeid");
1012 if (!qeth_is_supported(card
, IPA_IPV6
)) {
1013 card
->info
.unique_id
= UNIQUE_ID_IF_CREATE_ADDR_FAILED
|
1014 UNIQUE_ID_NOT_BY_CARD
;
1018 iob
= qeth_ipa_alloc_cmd(card
, IPA_CMD_CREATE_ADDR
, QETH_PROT_IPV6
,
1019 IPA_DATA_SIZEOF(create_destroy_addr
));
1022 cmd
= __ipa_cmd(iob
);
1023 *((__u16
*) &cmd
->data
.create_destroy_addr
.unique_id
[6]) =
1024 card
->info
.unique_id
;
1026 rc
= qeth_send_ipa_cmd(card
, iob
, qeth_l3_get_unique_id_cb
, NULL
);
1031 qeth_diags_trace_cb(struct qeth_card
*card
, struct qeth_reply
*reply
,
1034 struct qeth_ipa_cmd
*cmd
;
1037 QETH_CARD_TEXT(card
, 2, "diastrcb");
1039 cmd
= (struct qeth_ipa_cmd
*)data
;
1040 rc
= cmd
->hdr
.return_code
;
1042 QETH_CARD_TEXT_(card
, 2, "dxter%x", rc
);
1043 switch (cmd
->data
.diagass
.action
) {
1044 case QETH_DIAGS_CMD_TRACE_QUERY
:
1046 case QETH_DIAGS_CMD_TRACE_DISABLE
:
1049 case IPA_RC_INVALID_SUBCMD
:
1050 card
->info
.promisc_mode
= SET_PROMISC_MODE_OFF
;
1051 dev_info(&card
->gdev
->dev
, "The HiperSockets network "
1052 "traffic analyzer is deactivated\n");
1058 case QETH_DIAGS_CMD_TRACE_ENABLE
:
1061 card
->info
.promisc_mode
= SET_PROMISC_MODE_ON
;
1062 dev_info(&card
->gdev
->dev
, "The HiperSockets network "
1063 "traffic analyzer is activated\n");
1065 case IPA_RC_HARDWARE_AUTH_ERROR
:
1066 dev_warn(&card
->gdev
->dev
, "The device is not "
1067 "authorized to run as a HiperSockets network "
1068 "traffic analyzer\n");
1070 case IPA_RC_TRACE_ALREADY_ACTIVE
:
1071 dev_warn(&card
->gdev
->dev
, "A HiperSockets "
1072 "network traffic analyzer is already "
1073 "active in the HiperSockets LAN\n");
1080 QETH_DBF_MESSAGE(2, "Unknown sniffer action (%#06x) on device %x\n",
1081 cmd
->data
.diagass
.action
, CARD_DEVID(card
));
1084 return rc
? -EIO
: 0;
1088 qeth_diags_trace(struct qeth_card
*card
, enum qeth_diags_trace_cmds diags_cmd
)
1090 struct qeth_cmd_buffer
*iob
;
1091 struct qeth_ipa_cmd
*cmd
;
1093 QETH_CARD_TEXT(card
, 2, "diagtrac");
1095 iob
= qeth_get_diag_cmd(card
, QETH_DIAGS_CMD_TRACE
, 0);
1098 cmd
= __ipa_cmd(iob
);
1099 cmd
->data
.diagass
.type
= QETH_DIAGS_TYPE_HIPERSOCKET
;
1100 cmd
->data
.diagass
.action
= diags_cmd
;
1101 return qeth_send_ipa_cmd(card
, iob
, qeth_diags_trace_cb
, NULL
);
1104 static int qeth_l3_add_mcast_rtnl(struct net_device
*dev
, int vid
, void *arg
)
1106 struct qeth_card
*card
= arg
;
1107 struct inet6_dev
*in6_dev
;
1108 struct in_device
*in4_dev
;
1109 struct qeth_ipaddr
*ipm
;
1110 struct qeth_ipaddr tmp
;
1111 struct ip_mc_list
*im4
;
1112 struct ifmcaddr6
*im6
;
1114 QETH_CARD_TEXT(card
, 4, "addmc");
1116 if (!dev
|| !(dev
->flags
& IFF_UP
))
1119 in4_dev
= __in_dev_get_rtnl(dev
);
1123 qeth_l3_init_ipaddr(&tmp
, QETH_IP_TYPE_NORMAL
, QETH_PROT_IPV4
);
1124 tmp
.disp_flag
= QETH_DISP_ADDR_ADD
;
1125 tmp
.is_multicast
= 1;
1127 for (im4
= rtnl_dereference(in4_dev
->mc_list
); im4
!= NULL
;
1128 im4
= rtnl_dereference(im4
->next_rcu
)) {
1129 tmp
.u
.a4
.addr
= im4
->multiaddr
;
1131 ipm
= qeth_l3_find_addr_by_ip(card
, &tmp
);
1133 /* for mcast, by-IP match means full match */
1134 ipm
->disp_flag
= QETH_DISP_ADDR_DO_NOTHING
;
1138 ipm
= kmemdup(&tmp
, sizeof(tmp
), GFP_KERNEL
);
1142 hash_add(card
->ip_mc_htable
, &ipm
->hnode
,
1143 qeth_l3_ipaddr_hash(ipm
));
1147 if (!qeth_is_supported(card
, IPA_IPV6
))
1150 in6_dev
= __in6_dev_get(dev
);
1154 qeth_l3_init_ipaddr(&tmp
, QETH_IP_TYPE_NORMAL
, QETH_PROT_IPV6
);
1155 tmp
.disp_flag
= QETH_DISP_ADDR_ADD
;
1156 tmp
.is_multicast
= 1;
1158 read_lock_bh(&in6_dev
->lock
);
1159 for (im6
= in6_dev
->mc_list
; im6
!= NULL
; im6
= im6
->next
) {
1160 tmp
.u
.a6
.addr
= im6
->mca_addr
;
1162 ipm
= qeth_l3_find_addr_by_ip(card
, &tmp
);
1164 /* for mcast, by-IP match means full match */
1165 ipm
->disp_flag
= QETH_DISP_ADDR_DO_NOTHING
;
1169 ipm
= kmemdup(&tmp
, sizeof(tmp
), GFP_ATOMIC
);
1173 hash_add(card
->ip_mc_htable
,
1174 &ipm
->hnode
, qeth_l3_ipaddr_hash(ipm
));
1177 read_unlock_bh(&in6_dev
->lock
);
1183 static int qeth_l3_vlan_rx_add_vid(struct net_device
*dev
,
1184 __be16 proto
, u16 vid
)
1186 struct qeth_card
*card
= dev
->ml_priv
;
1188 QETH_CARD_TEXT_(card
, 4, "aid:%d", vid
);
1192 static int qeth_l3_vlan_rx_kill_vid(struct net_device
*dev
,
1193 __be16 proto
, u16 vid
)
1195 struct qeth_card
*card
= dev
->ml_priv
;
1197 QETH_CARD_TEXT_(card
, 4, "kid:%d", vid
);
1201 static void qeth_l3_rebuild_skb(struct qeth_card
*card
, struct sk_buff
*skb
,
1202 struct qeth_hdr
*hdr
)
1204 struct af_iucv_trans_hdr
*iucv
= (struct af_iucv_trans_hdr
*) skb
->data
;
1205 struct net_device
*dev
= skb
->dev
;
1207 if (IS_IQD(card
) && iucv
->magic
== ETH_P_AF_IUCV
) {
1208 dev_hard_header(skb
, dev
, ETH_P_AF_IUCV
, dev
->dev_addr
,
1209 "FAKELL", skb
->len
);
1213 if (!(hdr
->hdr
.l3
.flags
& QETH_HDR_PASSTHRU
)) {
1214 u16 prot
= (hdr
->hdr
.l3
.flags
& QETH_HDR_IPV6
) ? ETH_P_IPV6
:
1216 unsigned char tg_addr
[ETH_ALEN
];
1218 skb_reset_network_header(skb
);
1219 switch (hdr
->hdr
.l3
.flags
& QETH_HDR_CAST_MASK
) {
1220 case QETH_CAST_MULTICAST
:
1221 if (prot
== ETH_P_IP
)
1222 ip_eth_mc_map(ip_hdr(skb
)->daddr
, tg_addr
);
1224 ipv6_eth_mc_map(&ipv6_hdr(skb
)->daddr
, tg_addr
);
1225 QETH_CARD_STAT_INC(card
, rx_multicast
);
1227 case QETH_CAST_BROADCAST
:
1228 ether_addr_copy(tg_addr
, card
->dev
->broadcast
);
1229 QETH_CARD_STAT_INC(card
, rx_multicast
);
1232 if (card
->options
.sniffer
)
1233 skb
->pkt_type
= PACKET_OTHERHOST
;
1234 ether_addr_copy(tg_addr
, card
->dev
->dev_addr
);
1237 if (hdr
->hdr
.l3
.ext_flags
& QETH_HDR_EXT_SRC_MAC_ADDR
)
1238 card
->dev
->header_ops
->create(skb
, card
->dev
, prot
,
1239 tg_addr
, &hdr
->hdr
.l3
.next_hop
.rx
.src_mac
,
1242 card
->dev
->header_ops
->create(skb
, card
->dev
, prot
,
1243 tg_addr
, "FAKELL", skb
->len
);
1246 /* copy VLAN tag from hdr into skb */
1247 if (!card
->options
.sniffer
&&
1248 (hdr
->hdr
.l3
.ext_flags
& (QETH_HDR_EXT_VLAN_FRAME
|
1249 QETH_HDR_EXT_INCLUDE_VLAN_TAG
))) {
1250 u16 tag
= (hdr
->hdr
.l3
.ext_flags
& QETH_HDR_EXT_VLAN_FRAME
) ?
1251 hdr
->hdr
.l3
.vlan_id
:
1252 hdr
->hdr
.l3
.next_hop
.rx
.vlan_id
;
1253 __vlan_hwaccel_put_tag(skb
, htons(ETH_P_8021Q
), tag
);
1256 qeth_rx_csum(card
, skb
, hdr
->hdr
.l3
.ext_flags
);
1259 static int qeth_l3_process_inbound_buffer(struct qeth_card
*card
,
1260 int budget
, int *done
)
1263 struct sk_buff
*skb
;
1264 struct qeth_hdr
*hdr
;
1267 WARN_ON_ONCE(!budget
);
1269 skb
= qeth_core_get_next_skb(card
,
1270 &card
->qdio
.in_q
->bufs
[card
->rx
.b_index
],
1271 &card
->rx
.b_element
, &card
->rx
.e_offset
, &hdr
);
1277 if (hdr
->hdr
.l3
.id
== QETH_HEADER_TYPE_LAYER3
)
1278 qeth_l3_rebuild_skb(card
, skb
, hdr
);
1280 skb
->protocol
= eth_type_trans(skb
, skb
->dev
);
1281 QETH_CARD_STAT_INC(card
, rx_packets
);
1282 QETH_CARD_STAT_ADD(card
, rx_bytes
, skb
->len
);
1284 napi_gro_receive(&card
->napi
, skb
);
1291 static void qeth_l3_stop_card(struct qeth_card
*card
)
1293 QETH_CARD_TEXT(card
, 2, "stopcard");
1295 qeth_set_allowed_threads(card
, 0, 1);
1297 cancel_work_sync(&card
->rx_mode_work
);
1298 qeth_l3_drain_rx_mode_cache(card
);
1300 if (card
->options
.sniffer
&&
1301 (card
->info
.promisc_mode
== SET_PROMISC_MODE_ON
))
1302 qeth_diags_trace(card
, QETH_DIAGS_CMD_TRACE_DISABLE
);
1304 if (card
->state
== CARD_STATE_SOFTSETUP
) {
1305 qeth_l3_clear_ip_htable(card
, 1);
1306 qeth_clear_ipacmd_list(card
);
1307 card
->state
= CARD_STATE_HARDSETUP
;
1309 if (card
->state
== CARD_STATE_HARDSETUP
) {
1310 qeth_drain_output_queues(card
);
1311 qeth_clear_working_pool_list(card
);
1312 card
->state
= CARD_STATE_DOWN
;
1315 qeth_qdio_clear_card(card
, 0);
1316 flush_workqueue(card
->event_wq
);
1317 card
->info
.promisc_mode
= 0;
1320 static void qeth_l3_set_promisc_mode(struct qeth_card
*card
)
1322 bool enable
= card
->dev
->flags
& IFF_PROMISC
;
1324 if (card
->info
.promisc_mode
== enable
)
1327 if (IS_VM_NIC(card
)) { /* Guestlan trace */
1328 if (qeth_adp_supported(card
, IPA_SETADP_SET_PROMISC_MODE
))
1329 qeth_setadp_promisc_mode(card
, enable
);
1330 } else if (card
->options
.sniffer
&& /* HiperSockets trace */
1331 qeth_adp_supported(card
, IPA_SETADP_SET_DIAG_ASSIST
)) {
1333 QETH_CARD_TEXT(card
, 3, "+promisc");
1334 qeth_diags_trace(card
, QETH_DIAGS_CMD_TRACE_ENABLE
);
1336 QETH_CARD_TEXT(card
, 3, "-promisc");
1337 qeth_diags_trace(card
, QETH_DIAGS_CMD_TRACE_DISABLE
);
1342 static void qeth_l3_rx_mode_work(struct work_struct
*work
)
1344 struct qeth_card
*card
= container_of(work
, struct qeth_card
,
1346 struct qeth_ipaddr
*addr
;
1347 struct hlist_node
*tmp
;
1350 QETH_CARD_TEXT(card
, 3, "setmulti");
1352 if (!card
->options
.sniffer
) {
1354 qeth_l3_add_mcast_rtnl(card
->dev
, 0, card
);
1355 if (qeth_is_supported(card
, IPA_FULL_VLAN
))
1356 vlan_for_each(card
->dev
, qeth_l3_add_mcast_rtnl
, card
);
1359 hash_for_each_safe(card
->ip_mc_htable
, i
, tmp
, addr
, hnode
) {
1360 switch (addr
->disp_flag
) {
1361 case QETH_DISP_ADDR_DELETE
:
1362 rc
= qeth_l3_deregister_addr_entry(card
, addr
);
1363 if (!rc
|| rc
== -ENOENT
) {
1364 hash_del(&addr
->hnode
);
1368 case QETH_DISP_ADDR_ADD
:
1369 rc
= qeth_l3_register_addr_entry(card
, addr
);
1370 if (rc
&& rc
!= -ENETDOWN
) {
1371 hash_del(&addr
->hnode
);
1375 addr
->ref_counter
= 1;
1378 /* for next call to set_rx_mode(): */
1379 addr
->disp_flag
= QETH_DISP_ADDR_DELETE
;
1384 qeth_l3_set_promisc_mode(card
);
1387 static int qeth_l3_arp_makerc(u16 rc
)
1390 case IPA_RC_SUCCESS
:
1392 case QETH_IPA_ARP_RC_NOTSUPP
:
1393 case QETH_IPA_ARP_RC_Q_NOTSUPP
:
1395 case QETH_IPA_ARP_RC_OUT_OF_RANGE
:
1397 case QETH_IPA_ARP_RC_Q_NO_DATA
:
1404 static int qeth_l3_arp_cmd_cb(struct qeth_card
*card
, struct qeth_reply
*reply
,
1407 struct qeth_ipa_cmd
*cmd
= (struct qeth_ipa_cmd
*) data
;
1409 qeth_setassparms_cb(card
, reply
, data
);
1410 return qeth_l3_arp_makerc(cmd
->hdr
.return_code
);
1413 static int qeth_l3_arp_set_no_entries(struct qeth_card
*card
, int no_entries
)
1415 struct qeth_cmd_buffer
*iob
;
1418 QETH_CARD_TEXT(card
, 3, "arpstnoe");
1421 * currently GuestLAN only supports the ARP assist function
1422 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_SET_NO_ENTRIES;
1423 * thus we say EOPNOTSUPP for this ARP function
1425 if (IS_VM_NIC(card
))
1427 if (!qeth_is_supported(card
, IPA_ARP_PROCESSING
)) {
1431 iob
= qeth_get_setassparms_cmd(card
, IPA_ARP_PROCESSING
,
1432 IPA_CMD_ASS_ARP_SET_NO_ENTRIES
,
1433 SETASS_DATA_SIZEOF(flags_32bit
),
1438 __ipa_cmd(iob
)->data
.setassparms
.data
.flags_32bit
= (u32
) no_entries
;
1439 rc
= qeth_send_ipa_cmd(card
, iob
, qeth_l3_arp_cmd_cb
, NULL
);
1441 QETH_DBF_MESSAGE(2, "Could not set number of ARP entries on device %x: %#x\n",
1442 CARD_DEVID(card
), rc
);
1446 static __u32
get_arp_entry_size(struct qeth_card
*card
,
1447 struct qeth_arp_query_data
*qdata
,
1448 struct qeth_arp_entrytype
*type
, __u8 strip_entries
)
1453 is_hsi
= qdata
->reply_bits
== 5;
1454 if (type
->ip
== QETHARP_IP_ADDR_V4
) {
1455 QETH_CARD_TEXT(card
, 4, "arpev4");
1456 if (strip_entries
) {
1457 rc
= is_hsi
? sizeof(struct qeth_arp_qi_entry5_short
) :
1458 sizeof(struct qeth_arp_qi_entry7_short
);
1460 rc
= is_hsi
? sizeof(struct qeth_arp_qi_entry5
) :
1461 sizeof(struct qeth_arp_qi_entry7
);
1463 } else if (type
->ip
== QETHARP_IP_ADDR_V6
) {
1464 QETH_CARD_TEXT(card
, 4, "arpev6");
1465 if (strip_entries
) {
1467 sizeof(struct qeth_arp_qi_entry5_short_ipv6
) :
1468 sizeof(struct qeth_arp_qi_entry7_short_ipv6
);
1471 sizeof(struct qeth_arp_qi_entry5_ipv6
) :
1472 sizeof(struct qeth_arp_qi_entry7_ipv6
);
1475 QETH_CARD_TEXT(card
, 4, "arpinv");
1482 static int arpentry_matches_prot(struct qeth_arp_entrytype
*type
, __u16 prot
)
1484 return (type
->ip
== QETHARP_IP_ADDR_V4
&& prot
== QETH_PROT_IPV4
) ||
1485 (type
->ip
== QETHARP_IP_ADDR_V6
&& prot
== QETH_PROT_IPV6
);
1488 static int qeth_l3_arp_query_cb(struct qeth_card
*card
,
1489 struct qeth_reply
*reply
, unsigned long data
)
1491 struct qeth_ipa_cmd
*cmd
;
1492 struct qeth_arp_query_data
*qdata
;
1493 struct qeth_arp_query_info
*qinfo
;
1495 int entrybytes_done
;
1497 __u8 do_strip_entries
;
1499 QETH_CARD_TEXT(card
, 3, "arpquecb");
1501 qinfo
= (struct qeth_arp_query_info
*) reply
->param
;
1502 cmd
= (struct qeth_ipa_cmd
*) data
;
1503 QETH_CARD_TEXT_(card
, 4, "%i", cmd
->hdr
.prot_version
);
1504 if (cmd
->hdr
.return_code
) {
1505 QETH_CARD_TEXT(card
, 4, "arpcberr");
1506 QETH_CARD_TEXT_(card
, 4, "%i", cmd
->hdr
.return_code
);
1507 return qeth_l3_arp_makerc(cmd
->hdr
.return_code
);
1509 if (cmd
->data
.setassparms
.hdr
.return_code
) {
1510 cmd
->hdr
.return_code
= cmd
->data
.setassparms
.hdr
.return_code
;
1511 QETH_CARD_TEXT(card
, 4, "setaperr");
1512 QETH_CARD_TEXT_(card
, 4, "%i", cmd
->hdr
.return_code
);
1513 return qeth_l3_arp_makerc(cmd
->hdr
.return_code
);
1515 qdata
= &cmd
->data
.setassparms
.data
.query_arp
;
1516 QETH_CARD_TEXT_(card
, 4, "anoen%i", qdata
->no_entries
);
1518 do_strip_entries
= (qinfo
->mask_bits
& QETH_QARP_STRIP_ENTRIES
) > 0;
1519 stripped_bytes
= do_strip_entries
? QETH_QARP_MEDIASPECIFIC_BYTES
: 0;
1520 entrybytes_done
= 0;
1521 for (e
= 0; e
< qdata
->no_entries
; ++e
) {
1524 struct qeth_arp_entrytype
*etype
;
1526 cur_entry
= &qdata
->data
+ entrybytes_done
;
1527 etype
= &((struct qeth_arp_qi_entry5
*) cur_entry
)->type
;
1528 if (!arpentry_matches_prot(etype
, cmd
->hdr
.prot_version
)) {
1529 QETH_CARD_TEXT(card
, 4, "pmis");
1530 QETH_CARD_TEXT_(card
, 4, "%i", etype
->ip
);
1533 esize
= get_arp_entry_size(card
, qdata
, etype
,
1535 QETH_CARD_TEXT_(card
, 5, "esz%i", esize
);
1539 if ((qinfo
->udata_len
- qinfo
->udata_offset
) < esize
) {
1540 QETH_CARD_TEXT_(card
, 4, "qaer3%i", -ENOSPC
);
1541 memset(qinfo
->udata
, 0, 4);
1545 memcpy(qinfo
->udata
+ qinfo
->udata_offset
,
1546 &qdata
->data
+ entrybytes_done
+ stripped_bytes
,
1548 entrybytes_done
+= esize
+ stripped_bytes
;
1549 qinfo
->udata_offset
+= esize
;
1550 ++qinfo
->no_entries
;
1552 /* check if all replies received ... */
1553 if (cmd
->data
.setassparms
.hdr
.seq_no
<
1554 cmd
->data
.setassparms
.hdr
.number_of_replies
)
1556 QETH_CARD_TEXT_(card
, 4, "nove%i", qinfo
->no_entries
);
1557 memcpy(qinfo
->udata
, &qinfo
->no_entries
, 4);
1558 /* keep STRIP_ENTRIES flag so the user program can distinguish
1559 * stripped entries from normal ones */
1560 if (qinfo
->mask_bits
& QETH_QARP_STRIP_ENTRIES
)
1561 qdata
->reply_bits
|= QETH_QARP_STRIP_ENTRIES
;
1562 memcpy(qinfo
->udata
+ QETH_QARP_MASK_OFFSET
, &qdata
->reply_bits
, 2);
1563 QETH_CARD_TEXT_(card
, 4, "rc%i", 0);
1567 static int qeth_l3_query_arp_cache_info(struct qeth_card
*card
,
1568 enum qeth_prot_versions prot
,
1569 struct qeth_arp_query_info
*qinfo
)
1571 struct qeth_cmd_buffer
*iob
;
1572 struct qeth_ipa_cmd
*cmd
;
1575 QETH_CARD_TEXT_(card
, 3, "qarpipv%i", prot
);
1577 iob
= qeth_get_setassparms_cmd(card
, IPA_ARP_PROCESSING
,
1578 IPA_CMD_ASS_ARP_QUERY_INFO
,
1579 SETASS_DATA_SIZEOF(query_arp
), prot
);
1582 cmd
= __ipa_cmd(iob
);
1583 cmd
->data
.setassparms
.data
.query_arp
.request_bits
= 0x000F;
1584 rc
= qeth_send_ipa_cmd(card
, iob
, qeth_l3_arp_query_cb
, qinfo
);
1586 QETH_DBF_MESSAGE(2, "Error while querying ARP cache on device %x: %#x\n",
1587 CARD_DEVID(card
), rc
);
1591 static int qeth_l3_arp_query(struct qeth_card
*card
, char __user
*udata
)
1593 struct qeth_arp_query_info qinfo
= {0, };
1596 QETH_CARD_TEXT(card
, 3, "arpquery");
1598 if (!qeth_is_supported(card
,/*IPA_QUERY_ARP_ADDR_INFO*/
1599 IPA_ARP_PROCESSING
)) {
1600 QETH_CARD_TEXT(card
, 3, "arpqnsup");
1604 /* get size of userspace buffer and mask_bits -> 6 bytes */
1605 if (copy_from_user(&qinfo
, udata
, 6)) {
1609 qinfo
.udata
= kzalloc(qinfo
.udata_len
, GFP_KERNEL
);
1614 qinfo
.udata_offset
= QETH_QARP_ENTRIES_OFFSET
;
1615 rc
= qeth_l3_query_arp_cache_info(card
, QETH_PROT_IPV4
, &qinfo
);
1617 if (copy_to_user(udata
, qinfo
.udata
, 4))
1621 if (qinfo
.mask_bits
& QETH_QARP_WITH_IPV6
) {
1622 /* fails in case of GuestLAN QDIO mode */
1623 qeth_l3_query_arp_cache_info(card
, QETH_PROT_IPV6
, &qinfo
);
1625 if (copy_to_user(udata
, qinfo
.udata
, qinfo
.udata_len
)) {
1626 QETH_CARD_TEXT(card
, 4, "qactf");
1630 QETH_CARD_TEXT(card
, 4, "qacts");
1638 static int qeth_l3_arp_modify_entry(struct qeth_card
*card
,
1639 struct qeth_arp_cache_entry
*entry
,
1640 enum qeth_arp_process_subcmds arp_cmd
)
1642 struct qeth_arp_cache_entry
*cmd_entry
;
1643 struct qeth_cmd_buffer
*iob
;
1646 if (arp_cmd
== IPA_CMD_ASS_ARP_ADD_ENTRY
)
1647 QETH_CARD_TEXT(card
, 3, "arpadd");
1649 QETH_CARD_TEXT(card
, 3, "arpdel");
1652 * currently GuestLAN only supports the ARP assist function
1653 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_ADD_ENTRY;
1654 * thus we say EOPNOTSUPP for this ARP function
1656 if (IS_VM_NIC(card
))
1658 if (!qeth_is_supported(card
, IPA_ARP_PROCESSING
)) {
1662 iob
= qeth_get_setassparms_cmd(card
, IPA_ARP_PROCESSING
, arp_cmd
,
1663 SETASS_DATA_SIZEOF(arp_entry
),
1668 cmd_entry
= &__ipa_cmd(iob
)->data
.setassparms
.data
.arp_entry
;
1669 ether_addr_copy(cmd_entry
->macaddr
, entry
->macaddr
);
1670 memcpy(cmd_entry
->ipaddr
, entry
->ipaddr
, 4);
1671 rc
= qeth_send_ipa_cmd(card
, iob
, qeth_l3_arp_cmd_cb
, NULL
);
1673 QETH_DBF_MESSAGE(2, "Could not modify (cmd: %#x) ARP entry on device %x: %#x\n",
1674 arp_cmd
, CARD_DEVID(card
), rc
);
1678 static int qeth_l3_arp_flush_cache(struct qeth_card
*card
)
1680 struct qeth_cmd_buffer
*iob
;
1683 QETH_CARD_TEXT(card
, 3, "arpflush");
1686 * currently GuestLAN only supports the ARP assist function
1687 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_FLUSH_CACHE;
1688 * thus we say EOPNOTSUPP for this ARP function
1690 if (IS_VM_NIC(card
) || IS_IQD(card
))
1692 if (!qeth_is_supported(card
, IPA_ARP_PROCESSING
)) {
1696 iob
= qeth_get_setassparms_cmd(card
, IPA_ARP_PROCESSING
,
1697 IPA_CMD_ASS_ARP_FLUSH_CACHE
, 0,
1702 rc
= qeth_send_ipa_cmd(card
, iob
, qeth_l3_arp_cmd_cb
, NULL
);
1704 QETH_DBF_MESSAGE(2, "Could not flush ARP cache on device %x: %#x\n",
1705 CARD_DEVID(card
), rc
);
1709 static int qeth_l3_do_ioctl(struct net_device
*dev
, struct ifreq
*rq
, int cmd
)
1711 struct qeth_card
*card
= dev
->ml_priv
;
1712 struct qeth_arp_cache_entry arp_entry
;
1713 enum qeth_arp_process_subcmds arp_cmd
;
1717 case SIOC_QETH_ARP_SET_NO_ENTRIES
:
1718 if (!capable(CAP_NET_ADMIN
)) {
1722 rc
= qeth_l3_arp_set_no_entries(card
, rq
->ifr_ifru
.ifru_ivalue
);
1724 case SIOC_QETH_ARP_QUERY_INFO
:
1725 if (!capable(CAP_NET_ADMIN
)) {
1729 rc
= qeth_l3_arp_query(card
, rq
->ifr_ifru
.ifru_data
);
1731 case SIOC_QETH_ARP_ADD_ENTRY
:
1732 case SIOC_QETH_ARP_REMOVE_ENTRY
:
1733 if (!capable(CAP_NET_ADMIN
))
1735 if (copy_from_user(&arp_entry
, rq
->ifr_data
, sizeof(arp_entry
)))
1738 arp_cmd
= (cmd
== SIOC_QETH_ARP_ADD_ENTRY
) ?
1739 IPA_CMD_ASS_ARP_ADD_ENTRY
:
1740 IPA_CMD_ASS_ARP_REMOVE_ENTRY
;
1741 return qeth_l3_arp_modify_entry(card
, &arp_entry
, arp_cmd
);
1742 case SIOC_QETH_ARP_FLUSH_CACHE
:
1743 if (!capable(CAP_NET_ADMIN
)) {
1747 rc
= qeth_l3_arp_flush_cache(card
);
1755 static int qeth_l3_get_cast_type_rcu(struct sk_buff
*skb
, struct dst_entry
*dst
,
1758 struct neighbour
*n
= NULL
;
1761 n
= dst_neigh_lookup_skb(dst
, skb
);
1764 int cast_type
= n
->type
;
1767 if ((cast_type
== RTN_BROADCAST
) ||
1768 (cast_type
== RTN_MULTICAST
) ||
1769 (cast_type
== RTN_ANYCAST
))
1774 /* no neighbour (eg AF_PACKET), fall back to target's IP address ... */
1777 if (ipv4_is_lbcast(ip_hdr(skb
)->daddr
))
1778 return RTN_BROADCAST
;
1779 return ipv4_is_multicast(ip_hdr(skb
)->daddr
) ?
1780 RTN_MULTICAST
: RTN_UNICAST
;
1782 return ipv6_addr_is_multicast(&ipv6_hdr(skb
)->daddr
) ?
1783 RTN_MULTICAST
: RTN_UNICAST
;
1785 /* ... and MAC address */
1786 return qeth_get_ether_cast_type(skb
);
1790 static int qeth_l3_get_cast_type(struct sk_buff
*skb
)
1792 int ipv
= qeth_get_ip_version(skb
);
1793 struct dst_entry
*dst
;
1797 dst
= qeth_dst_check_rcu(skb
, ipv
);
1798 cast_type
= qeth_l3_get_cast_type_rcu(skb
, dst
, ipv
);
1804 static u8
qeth_l3_cast_type_to_flag(int cast_type
)
1806 if (cast_type
== RTN_MULTICAST
)
1807 return QETH_CAST_MULTICAST
;
1808 if (cast_type
== RTN_ANYCAST
)
1809 return QETH_CAST_ANYCAST
;
1810 if (cast_type
== RTN_BROADCAST
)
1811 return QETH_CAST_BROADCAST
;
1812 return QETH_CAST_UNICAST
;
1815 static void qeth_l3_fill_header(struct qeth_qdio_out_q
*queue
,
1816 struct qeth_hdr
*hdr
, struct sk_buff
*skb
,
1817 int ipv
, unsigned int data_len
)
1819 struct qeth_hdr_layer3
*l3_hdr
= &hdr
->hdr
.l3
;
1820 struct vlan_ethhdr
*veth
= vlan_eth_hdr(skb
);
1821 struct qeth_card
*card
= queue
->card
;
1822 struct dst_entry
*dst
;
1825 hdr
->hdr
.l3
.length
= data_len
;
1827 if (skb_is_gso(skb
)) {
1828 hdr
->hdr
.l3
.id
= QETH_HEADER_TYPE_L3_TSO
;
1830 hdr
->hdr
.l3
.id
= QETH_HEADER_TYPE_LAYER3
;
1832 if (skb
->protocol
== htons(ETH_P_AF_IUCV
)) {
1833 l3_hdr
->flags
= QETH_HDR_IPV6
| QETH_CAST_UNICAST
;
1834 l3_hdr
->next_hop
.ipv6_addr
.s6_addr16
[0] = htons(0xfe80);
1835 memcpy(&l3_hdr
->next_hop
.ipv6_addr
.s6_addr32
[2],
1836 iucv_trans_hdr(skb
)->destUserID
, 8);
1840 if (skb
->ip_summed
== CHECKSUM_PARTIAL
) {
1841 qeth_tx_csum(skb
, &hdr
->hdr
.l3
.ext_flags
, ipv
);
1842 /* some HW requires combined L3+L4 csum offload: */
1844 hdr
->hdr
.l3
.ext_flags
|= QETH_HDR_EXT_CSUM_HDR_REQ
;
1848 if (ipv
== 4 || IS_IQD(card
)) {
1849 /* NETIF_F_HW_VLAN_CTAG_TX */
1850 if (skb_vlan_tag_present(skb
)) {
1851 hdr
->hdr
.l3
.ext_flags
|= QETH_HDR_EXT_VLAN_FRAME
;
1852 hdr
->hdr
.l3
.vlan_id
= skb_vlan_tag_get(skb
);
1854 } else if (veth
->h_vlan_proto
== htons(ETH_P_8021Q
)) {
1855 hdr
->hdr
.l3
.ext_flags
|= QETH_HDR_EXT_INCLUDE_VLAN_TAG
;
1856 hdr
->hdr
.l3
.vlan_id
= ntohs(veth
->h_vlan_TCI
);
1860 dst
= qeth_dst_check_rcu(skb
, ipv
);
1862 if (IS_IQD(card
) && skb_get_queue_mapping(skb
) != QETH_IQD_MCAST_TXQ
)
1863 cast_type
= RTN_UNICAST
;
1865 cast_type
= qeth_l3_get_cast_type_rcu(skb
, dst
, ipv
);
1866 l3_hdr
->flags
|= qeth_l3_cast_type_to_flag(cast_type
);
1869 struct rtable
*rt
= (struct rtable
*) dst
;
1871 *((__be32
*) &hdr
->hdr
.l3
.next_hop
.ipv4
.addr
) = (rt
) ?
1872 rt_nexthop(rt
, ip_hdr(skb
)->daddr
) :
1874 } else if (ipv
== 6) {
1875 struct rt6_info
*rt
= (struct rt6_info
*) dst
;
1877 if (rt
&& !ipv6_addr_any(&rt
->rt6i_gateway
))
1878 l3_hdr
->next_hop
.ipv6_addr
= rt
->rt6i_gateway
;
1880 l3_hdr
->next_hop
.ipv6_addr
= ipv6_hdr(skb
)->daddr
;
1882 hdr
->hdr
.l3
.flags
|= QETH_HDR_IPV6
;
1884 hdr
->hdr
.l3
.flags
|= QETH_HDR_PASSTHRU
;
1887 l3_hdr
->flags
|= QETH_HDR_PASSTHRU
;
1892 static void qeth_l3_fixup_headers(struct sk_buff
*skb
)
1894 struct iphdr
*iph
= ip_hdr(skb
);
1896 /* this is safe, IPv6 traffic takes a different path */
1897 if (skb
->ip_summed
== CHECKSUM_PARTIAL
)
1899 if (skb_is_gso(skb
)) {
1901 tcp_hdr(skb
)->check
= ~tcp_v4_check(0, iph
->saddr
,
1906 static int qeth_l3_xmit(struct qeth_card
*card
, struct sk_buff
*skb
,
1907 struct qeth_qdio_out_q
*queue
, int ipv
)
1909 unsigned int hw_hdr_len
;
1912 /* re-use the L2 header area for the HW header: */
1913 hw_hdr_len
= skb_is_gso(skb
) ? sizeof(struct qeth_hdr_tso
) :
1914 sizeof(struct qeth_hdr
);
1915 rc
= skb_cow_head(skb
, hw_hdr_len
- ETH_HLEN
);
1918 skb_pull(skb
, ETH_HLEN
);
1920 qeth_l3_fixup_headers(skb
);
1921 return qeth_xmit(card
, skb
, queue
, ipv
, qeth_l3_fill_header
);
1924 static netdev_tx_t
qeth_l3_hard_start_xmit(struct sk_buff
*skb
,
1925 struct net_device
*dev
)
1927 struct qeth_card
*card
= dev
->ml_priv
;
1928 u16 txq
= skb_get_queue_mapping(skb
);
1929 int ipv
= qeth_get_ip_version(skb
);
1930 struct qeth_qdio_out_q
*queue
;
1933 if (!skb_is_gso(skb
))
1934 qdisc_skb_cb(skb
)->pkt_len
= skb
->len
;
1936 queue
= card
->qdio
.out_qs
[qeth_iqd_translate_txq(dev
, txq
)];
1938 if (card
->options
.sniffer
)
1940 if ((card
->options
.cq
!= QETH_CQ_ENABLED
&& !ipv
) ||
1941 (card
->options
.cq
== QETH_CQ_ENABLED
&&
1942 skb
->protocol
!= htons(ETH_P_AF_IUCV
)))
1945 queue
= card
->qdio
.out_qs
[txq
];
1948 if (!(dev
->flags
& IFF_BROADCAST
) &&
1949 qeth_l3_get_cast_type(skb
) == RTN_BROADCAST
)
1952 if (ipv
== 4 || IS_IQD(card
))
1953 rc
= qeth_l3_xmit(card
, skb
, queue
, ipv
);
1955 rc
= qeth_xmit(card
, skb
, queue
, ipv
, qeth_l3_fill_header
);
1958 return NETDEV_TX_OK
;
1961 QETH_TXQ_STAT_INC(queue
, tx_dropped
);
1963 return NETDEV_TX_OK
;
1966 static void qeth_l3_set_rx_mode(struct net_device
*dev
)
1968 struct qeth_card
*card
= dev
->ml_priv
;
1970 schedule_work(&card
->rx_mode_work
);
1974 * we need NOARP for IPv4 but we want neighbor solicitation for IPv6. Setting
1975 * NOARP on the netdevice is no option because it also turns off neighbor
1976 * solicitation. For IPv4 we install a neighbor_setup function. We don't want
1977 * arp resolution but we want the hard header (packet socket will work
1980 static int qeth_l3_neigh_setup_noarp(struct neighbour
*n
)
1982 n
->nud_state
= NUD_NOARP
;
1983 memcpy(n
->ha
, "FAKELL", 6);
1984 n
->output
= n
->ops
->connected_output
;
1989 qeth_l3_neigh_setup(struct net_device
*dev
, struct neigh_parms
*np
)
1991 if (np
->tbl
->family
== AF_INET
)
1992 np
->neigh_setup
= qeth_l3_neigh_setup_noarp
;
1997 static netdev_features_t
qeth_l3_osa_features_check(struct sk_buff
*skb
,
1998 struct net_device
*dev
,
1999 netdev_features_t features
)
2001 if (qeth_get_ip_version(skb
) != 4)
2002 features
&= ~NETIF_F_HW_VLAN_CTAG_TX
;
2003 return qeth_features_check(skb
, dev
, features
);
2006 static u16
qeth_l3_iqd_select_queue(struct net_device
*dev
, struct sk_buff
*skb
,
2007 struct net_device
*sb_dev
)
2009 return qeth_iqd_select_queue(dev
, skb
, qeth_l3_get_cast_type(skb
),
2013 static u16
qeth_l3_osa_select_queue(struct net_device
*dev
, struct sk_buff
*skb
,
2014 struct net_device
*sb_dev
)
2016 struct qeth_card
*card
= dev
->ml_priv
;
2018 return qeth_get_priority_queue(card
, skb
);
2021 static const struct net_device_ops qeth_l3_netdev_ops
= {
2022 .ndo_open
= qeth_open
,
2023 .ndo_stop
= qeth_stop
,
2024 .ndo_get_stats64
= qeth_get_stats64
,
2025 .ndo_start_xmit
= qeth_l3_hard_start_xmit
,
2026 .ndo_select_queue
= qeth_l3_iqd_select_queue
,
2027 .ndo_validate_addr
= eth_validate_addr
,
2028 .ndo_set_rx_mode
= qeth_l3_set_rx_mode
,
2029 .ndo_do_ioctl
= qeth_do_ioctl
,
2030 .ndo_fix_features
= qeth_fix_features
,
2031 .ndo_set_features
= qeth_set_features
,
2032 .ndo_vlan_rx_add_vid
= qeth_l3_vlan_rx_add_vid
,
2033 .ndo_vlan_rx_kill_vid
= qeth_l3_vlan_rx_kill_vid
,
2034 .ndo_tx_timeout
= qeth_tx_timeout
,
2037 static const struct net_device_ops qeth_l3_osa_netdev_ops
= {
2038 .ndo_open
= qeth_open
,
2039 .ndo_stop
= qeth_stop
,
2040 .ndo_get_stats64
= qeth_get_stats64
,
2041 .ndo_start_xmit
= qeth_l3_hard_start_xmit
,
2042 .ndo_features_check
= qeth_l3_osa_features_check
,
2043 .ndo_select_queue
= qeth_l3_osa_select_queue
,
2044 .ndo_validate_addr
= eth_validate_addr
,
2045 .ndo_set_rx_mode
= qeth_l3_set_rx_mode
,
2046 .ndo_do_ioctl
= qeth_do_ioctl
,
2047 .ndo_fix_features
= qeth_fix_features
,
2048 .ndo_set_features
= qeth_set_features
,
2049 .ndo_vlan_rx_add_vid
= qeth_l3_vlan_rx_add_vid
,
2050 .ndo_vlan_rx_kill_vid
= qeth_l3_vlan_rx_kill_vid
,
2051 .ndo_tx_timeout
= qeth_tx_timeout
,
2052 .ndo_neigh_setup
= qeth_l3_neigh_setup
,
2055 static int qeth_l3_setup_netdev(struct qeth_card
*card
, bool carrier_ok
)
2057 unsigned int headroom
;
2060 if (IS_OSD(card
) || IS_OSX(card
)) {
2061 if ((card
->info
.link_type
== QETH_LINK_TYPE_LANE_TR
) ||
2062 (card
->info
.link_type
== QETH_LINK_TYPE_HSTR
)) {
2063 pr_info("qeth_l3: ignoring TR device\n");
2067 card
->dev
->netdev_ops
= &qeth_l3_osa_netdev_ops
;
2069 /*IPv6 address autoconfiguration stuff*/
2070 qeth_l3_get_unique_id(card
);
2071 if (!(card
->info
.unique_id
& UNIQUE_ID_NOT_BY_CARD
))
2072 card
->dev
->dev_id
= card
->info
.unique_id
& 0xffff;
2074 if (!IS_VM_NIC(card
)) {
2075 card
->dev
->features
|= NETIF_F_SG
;
2076 card
->dev
->hw_features
|= NETIF_F_TSO
|
2077 NETIF_F_RXCSUM
| NETIF_F_IP_CSUM
;
2078 card
->dev
->vlan_features
|= NETIF_F_TSO
|
2079 NETIF_F_RXCSUM
| NETIF_F_IP_CSUM
;
2082 if (qeth_is_supported6(card
, IPA_OUTBOUND_CHECKSUM_V6
)) {
2083 card
->dev
->hw_features
|= NETIF_F_IPV6_CSUM
;
2084 card
->dev
->vlan_features
|= NETIF_F_IPV6_CSUM
;
2086 if (qeth_is_supported6(card
, IPA_OUTBOUND_TSO
)) {
2087 card
->dev
->hw_features
|= NETIF_F_TSO6
;
2088 card
->dev
->vlan_features
|= NETIF_F_TSO6
;
2091 /* allow for de-acceleration of NETIF_F_HW_VLAN_CTAG_TX: */
2092 if (card
->dev
->hw_features
& NETIF_F_TSO6
)
2093 headroom
= sizeof(struct qeth_hdr_tso
) + VLAN_HLEN
;
2094 else if (card
->dev
->hw_features
& NETIF_F_TSO
)
2095 headroom
= sizeof(struct qeth_hdr_tso
);
2097 headroom
= sizeof(struct qeth_hdr
) + VLAN_HLEN
;
2098 } else if (IS_IQD(card
)) {
2099 card
->dev
->flags
|= IFF_NOARP
;
2100 card
->dev
->netdev_ops
= &qeth_l3_netdev_ops
;
2101 headroom
= sizeof(struct qeth_hdr
) - ETH_HLEN
;
2103 rc
= qeth_l3_iqd_read_initial_mac(card
);
2109 card
->dev
->needed_headroom
= headroom
;
2110 card
->dev
->features
|= NETIF_F_HW_VLAN_CTAG_TX
|
2111 NETIF_F_HW_VLAN_CTAG_RX
|
2112 NETIF_F_HW_VLAN_CTAG_FILTER
;
2114 netif_keep_dst(card
->dev
);
2115 if (card
->dev
->hw_features
& (NETIF_F_TSO
| NETIF_F_TSO6
))
2116 netif_set_gso_max_size(card
->dev
,
2117 PAGE_SIZE
* (QETH_MAX_BUFFER_ELEMENTS(card
) - 1));
2119 netif_napi_add(card
->dev
, &card
->napi
, qeth_poll
, QETH_NAPI_WEIGHT
);
2120 rc
= register_netdev(card
->dev
);
2121 if (!rc
&& carrier_ok
)
2122 netif_carrier_on(card
->dev
);
2126 card
->dev
->netdev_ops
= NULL
;
2130 static const struct device_type qeth_l3_devtype
= {
2131 .name
= "qeth_layer3",
2132 .groups
= qeth_l3_attr_groups
,
2135 static int qeth_l3_probe_device(struct ccwgroup_device
*gdev
)
2137 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
2140 hash_init(card
->ip_htable
);
2141 mutex_init(&card
->ip_lock
);
2142 card
->cmd_wq
= alloc_ordered_workqueue("%s_cmd", 0,
2143 dev_name(&gdev
->dev
));
2147 if (gdev
->dev
.type
== &qeth_generic_devtype
) {
2148 rc
= qeth_l3_create_device_attributes(&gdev
->dev
);
2150 destroy_workqueue(card
->cmd_wq
);
2155 hash_init(card
->ip_mc_htable
);
2156 INIT_WORK(&card
->rx_mode_work
, qeth_l3_rx_mode_work
);
2160 static void qeth_l3_remove_device(struct ccwgroup_device
*cgdev
)
2162 struct qeth_card
*card
= dev_get_drvdata(&cgdev
->dev
);
2164 if (cgdev
->dev
.type
== &qeth_generic_devtype
)
2165 qeth_l3_remove_device_attributes(&cgdev
->dev
);
2167 qeth_set_allowed_threads(card
, 0, 1);
2168 wait_event(card
->wait_q
, qeth_threads_running(card
, 0xffffffff) == 0);
2170 if (cgdev
->state
== CCWGROUP_ONLINE
)
2171 qeth_l3_set_offline(cgdev
);
2173 cancel_work_sync(&card
->close_dev_work
);
2174 if (qeth_netdev_is_registered(card
->dev
))
2175 unregister_netdev(card
->dev
);
2177 flush_workqueue(card
->cmd_wq
);
2178 destroy_workqueue(card
->cmd_wq
);
2179 qeth_l3_clear_ip_htable(card
, 0);
2180 qeth_l3_clear_ipato_list(card
);
2183 static int qeth_l3_set_online(struct ccwgroup_device
*gdev
)
2185 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
2186 struct net_device
*dev
= card
->dev
;
2190 mutex_lock(&card
->discipline_mutex
);
2191 mutex_lock(&card
->conf_mutex
);
2192 QETH_CARD_TEXT(card
, 2, "setonlin");
2194 rc
= qeth_core_hardsetup_card(card
, &carrier_ok
);
2196 QETH_CARD_TEXT_(card
, 2, "2err%04x", rc
);
2201 card
->state
= CARD_STATE_HARDSETUP
;
2202 qeth_print_status_message(card
);
2205 QETH_CARD_TEXT(card
, 2, "softsetp");
2207 rc
= qeth_l3_setadapter_parms(card
);
2209 QETH_CARD_TEXT_(card
, 2, "2err%04x", rc
);
2210 if (!card
->options
.sniffer
) {
2211 rc
= qeth_l3_start_ipassists(card
);
2213 QETH_CARD_TEXT_(card
, 2, "3err%d", rc
);
2216 rc
= qeth_l3_setrouting_v4(card
);
2218 QETH_CARD_TEXT_(card
, 2, "4err%04x", rc
);
2219 rc
= qeth_l3_setrouting_v6(card
);
2221 QETH_CARD_TEXT_(card
, 2, "5err%04x", rc
);
2224 rc
= qeth_init_qdio_queues(card
);
2226 QETH_CARD_TEXT_(card
, 2, "6err%d", rc
);
2230 card
->state
= CARD_STATE_SOFTSETUP
;
2232 qeth_set_allowed_threads(card
, 0xffffffff, 0);
2233 qeth_l3_recover_ip(card
);
2235 if (!qeth_netdev_is_registered(dev
)) {
2236 rc
= qeth_l3_setup_netdev(card
, carrier_ok
);
2242 netif_carrier_on(dev
);
2244 netif_carrier_off(dev
);
2246 netif_device_attach(dev
);
2247 qeth_enable_hw_features(dev
);
2249 if (card
->info
.open_when_online
) {
2250 card
->info
.open_when_online
= 0;
2251 dev_open(dev
, NULL
);
2255 qeth_trace_features(card
);
2256 /* let user_space know that device is online */
2257 kobject_uevent(&gdev
->dev
.kobj
, KOBJ_CHANGE
);
2258 mutex_unlock(&card
->conf_mutex
);
2259 mutex_unlock(&card
->discipline_mutex
);
2262 qeth_l3_stop_card(card
);
2263 qeth_stop_channel(&card
->data
);
2264 qeth_stop_channel(&card
->write
);
2265 qeth_stop_channel(&card
->read
);
2266 qdio_free(CARD_DDEV(card
));
2268 mutex_unlock(&card
->conf_mutex
);
2269 mutex_unlock(&card
->discipline_mutex
);
2273 static int __qeth_l3_set_offline(struct ccwgroup_device
*cgdev
,
2276 struct qeth_card
*card
= dev_get_drvdata(&cgdev
->dev
);
2277 int rc
= 0, rc2
= 0, rc3
= 0;
2279 mutex_lock(&card
->discipline_mutex
);
2280 mutex_lock(&card
->conf_mutex
);
2281 QETH_CARD_TEXT(card
, 3, "setoffl");
2283 if ((!recovery_mode
&& card
->info
.hwtrap
) || card
->info
.hwtrap
== 2) {
2284 qeth_hw_trap(card
, QETH_DIAGS_TRAP_DISARM
);
2285 card
->info
.hwtrap
= 1;
2289 card
->info
.open_when_online
= card
->dev
->flags
& IFF_UP
;
2290 dev_close(card
->dev
);
2291 netif_device_detach(card
->dev
);
2292 netif_carrier_off(card
->dev
);
2295 qeth_l3_stop_card(card
);
2296 if (card
->options
.cq
== QETH_CQ_ENABLED
) {
2298 call_netdevice_notifiers(NETDEV_REBOOT
, card
->dev
);
2302 rc
= qeth_stop_channel(&card
->data
);
2303 rc2
= qeth_stop_channel(&card
->write
);
2304 rc3
= qeth_stop_channel(&card
->read
);
2306 rc
= (rc2
) ? rc2
: rc3
;
2308 QETH_CARD_TEXT_(card
, 2, "1err%d", rc
);
2309 qdio_free(CARD_DDEV(card
));
2311 /* let user_space know that device is offline */
2312 kobject_uevent(&cgdev
->dev
.kobj
, KOBJ_CHANGE
);
2313 mutex_unlock(&card
->conf_mutex
);
2314 mutex_unlock(&card
->discipline_mutex
);
2318 static int qeth_l3_set_offline(struct ccwgroup_device
*cgdev
)
2320 return __qeth_l3_set_offline(cgdev
, 0);
2323 static int qeth_l3_recover(void *ptr
)
2325 struct qeth_card
*card
;
2328 card
= (struct qeth_card
*) ptr
;
2329 QETH_CARD_TEXT(card
, 2, "recover1");
2330 QETH_CARD_HEX(card
, 2, &card
, sizeof(void *));
2331 if (!qeth_do_run_thread(card
, QETH_RECOVER_THREAD
))
2333 QETH_CARD_TEXT(card
, 2, "recover2");
2334 dev_warn(&card
->gdev
->dev
,
2335 "A recovery process has been started for the device\n");
2336 __qeth_l3_set_offline(card
->gdev
, 1);
2337 rc
= qeth_l3_set_online(card
->gdev
);
2339 dev_info(&card
->gdev
->dev
,
2340 "Device successfully recovered!\n");
2342 ccwgroup_set_offline(card
->gdev
);
2343 dev_warn(&card
->gdev
->dev
, "The qeth device driver "
2344 "failed to recover an error on the device\n");
2346 qeth_clear_thread_start_bit(card
, QETH_RECOVER_THREAD
);
2347 qeth_clear_thread_running_bit(card
, QETH_RECOVER_THREAD
);
2351 /* Returns zero if the command is successfully "consumed" */
2352 static int qeth_l3_control_event(struct qeth_card
*card
,
2353 struct qeth_ipa_cmd
*cmd
)
2358 struct qeth_discipline qeth_l3_discipline
= {
2359 .devtype
= &qeth_l3_devtype
,
2360 .process_rx_buffer
= qeth_l3_process_inbound_buffer
,
2361 .recover
= qeth_l3_recover
,
2362 .setup
= qeth_l3_probe_device
,
2363 .remove
= qeth_l3_remove_device
,
2364 .set_online
= qeth_l3_set_online
,
2365 .set_offline
= qeth_l3_set_offline
,
2366 .do_ioctl
= qeth_l3_do_ioctl
,
2367 .control_event_handler
= qeth_l3_control_event
,
2369 EXPORT_SYMBOL_GPL(qeth_l3_discipline
);
2371 static int qeth_l3_handle_ip_event(struct qeth_card
*card
,
2372 struct qeth_ipaddr
*addr
,
2373 unsigned long event
)
2377 qeth_l3_modify_ip(card
, addr
, true);
2380 qeth_l3_modify_ip(card
, addr
, false);
2387 struct qeth_l3_ip_event_work
{
2388 struct work_struct work
;
2389 struct qeth_card
*card
;
2390 struct qeth_ipaddr addr
;
2393 #define to_ip_work(w) container_of((w), struct qeth_l3_ip_event_work, work)
2395 static void qeth_l3_add_ip_worker(struct work_struct
*work
)
2397 struct qeth_l3_ip_event_work
*ip_work
= to_ip_work(work
);
2399 qeth_l3_modify_ip(ip_work
->card
, &ip_work
->addr
, true);
2403 static void qeth_l3_delete_ip_worker(struct work_struct
*work
)
2405 struct qeth_l3_ip_event_work
*ip_work
= to_ip_work(work
);
2407 qeth_l3_modify_ip(ip_work
->card
, &ip_work
->addr
, false);
2411 static struct qeth_card
*qeth_l3_get_card_from_dev(struct net_device
*dev
)
2413 if (is_vlan_dev(dev
))
2414 dev
= vlan_dev_real_dev(dev
);
2415 if (dev
->netdev_ops
== &qeth_l3_osa_netdev_ops
||
2416 dev
->netdev_ops
== &qeth_l3_netdev_ops
)
2417 return (struct qeth_card
*) dev
->ml_priv
;
2421 static int qeth_l3_ip_event(struct notifier_block
*this,
2422 unsigned long event
, void *ptr
)
2425 struct in_ifaddr
*ifa
= (struct in_ifaddr
*)ptr
;
2426 struct net_device
*dev
= ifa
->ifa_dev
->dev
;
2427 struct qeth_ipaddr addr
;
2428 struct qeth_card
*card
;
2430 if (dev_net(dev
) != &init_net
)
2433 card
= qeth_l3_get_card_from_dev(dev
);
2436 QETH_CARD_TEXT(card
, 3, "ipevent");
2438 qeth_l3_init_ipaddr(&addr
, QETH_IP_TYPE_NORMAL
, QETH_PROT_IPV4
);
2439 addr
.u
.a4
.addr
= ifa
->ifa_address
;
2440 addr
.u
.a4
.mask
= be32_to_cpu(ifa
->ifa_mask
);
2442 return qeth_l3_handle_ip_event(card
, &addr
, event
);
2445 static struct notifier_block qeth_l3_ip_notifier
= {
2450 static int qeth_l3_ip6_event(struct notifier_block
*this,
2451 unsigned long event
, void *ptr
)
2453 struct inet6_ifaddr
*ifa
= (struct inet6_ifaddr
*)ptr
;
2454 struct net_device
*dev
= ifa
->idev
->dev
;
2455 struct qeth_l3_ip_event_work
*ip_work
;
2456 struct qeth_card
*card
;
2458 if (event
!= NETDEV_UP
&& event
!= NETDEV_DOWN
)
2461 card
= qeth_l3_get_card_from_dev(dev
);
2464 QETH_CARD_TEXT(card
, 3, "ip6event");
2465 if (!qeth_is_supported(card
, IPA_IPV6
))
2468 ip_work
= kmalloc(sizeof(*ip_work
), GFP_ATOMIC
);
2472 if (event
== NETDEV_UP
)
2473 INIT_WORK(&ip_work
->work
, qeth_l3_add_ip_worker
);
2475 INIT_WORK(&ip_work
->work
, qeth_l3_delete_ip_worker
);
2477 ip_work
->card
= card
;
2478 qeth_l3_init_ipaddr(&ip_work
->addr
, QETH_IP_TYPE_NORMAL
,
2480 ip_work
->addr
.u
.a6
.addr
= ifa
->addr
;
2481 ip_work
->addr
.u
.a6
.pfxlen
= ifa
->prefix_len
;
2483 queue_work(card
->cmd_wq
, &ip_work
->work
);
2487 static struct notifier_block qeth_l3_ip6_notifier
= {
2492 static int qeth_l3_register_notifiers(void)
2496 QETH_DBF_TEXT(SETUP
, 5, "regnotif");
2497 rc
= register_inetaddr_notifier(&qeth_l3_ip_notifier
);
2500 rc
= register_inet6addr_notifier(&qeth_l3_ip6_notifier
);
2502 unregister_inetaddr_notifier(&qeth_l3_ip_notifier
);
2508 static void qeth_l3_unregister_notifiers(void)
2510 QETH_DBF_TEXT(SETUP
, 5, "unregnot");
2511 WARN_ON(unregister_inetaddr_notifier(&qeth_l3_ip_notifier
));
2512 WARN_ON(unregister_inet6addr_notifier(&qeth_l3_ip6_notifier
));
2515 static int __init
qeth_l3_init(void)
2517 pr_info("register layer 3 discipline\n");
2518 return qeth_l3_register_notifiers();
2521 static void __exit
qeth_l3_exit(void)
2523 qeth_l3_unregister_notifiers();
2524 pr_info("unregister layer 3 discipline\n");
2527 module_init(qeth_l3_init
);
2528 module_exit(qeth_l3_exit
);
2529 MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
2530 MODULE_DESCRIPTION("qeth layer 3 discipline");
2531 MODULE_LICENSE("GPL");