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/inet.h>
23 #include <linux/ipv6.h>
24 #include <linux/inetdevice.h>
25 #include <linux/igmp.h>
26 #include <linux/slab.h>
27 #include <linux/if_ether.h>
28 #include <linux/if_vlan.h>
29 #include <linux/skbuff.h>
33 #include <net/route.h>
35 #include <net/ip6_route.h>
36 #include <net/iucv/af_iucv.h>
37 #include <linux/hashtable.h>
41 static int qeth_l3_register_addr_entry(struct qeth_card
*,
42 struct qeth_ipaddr
*);
43 static int qeth_l3_deregister_addr_entry(struct qeth_card
*,
44 struct qeth_ipaddr
*);
46 int qeth_l3_ipaddr_to_string(enum qeth_prot_versions proto
, const u8
*addr
,
49 if (proto
== QETH_PROT_IPV4
)
50 return scnprintf(buf
, INET_ADDRSTRLEN
, "%pI4", addr
);
52 return scnprintf(buf
, INET6_ADDRSTRLEN
, "%pI6", addr
);
55 static struct qeth_ipaddr
*qeth_l3_find_addr_by_ip(struct qeth_card
*card
,
56 struct qeth_ipaddr
*query
)
58 u32 key
= qeth_l3_ipaddr_hash(query
);
59 struct qeth_ipaddr
*addr
;
61 if (query
->is_multicast
) {
62 hash_for_each_possible(card
->rx_mode_addrs
, addr
, hnode
, key
)
63 if (qeth_l3_addr_match_ip(addr
, query
))
66 hash_for_each_possible(card
->ip_htable
, addr
, hnode
, key
)
67 if (qeth_l3_addr_match_ip(addr
, query
))
73 static void qeth_l3_convert_addr_to_bits(u8
*addr
, u8
*bits
, int len
)
78 for (i
= 0; i
< len
; ++i
) {
80 for (j
= 7; j
>= 0; --j
) {
81 bits
[i
*8 + j
] = octet
& 1;
87 static bool qeth_l3_is_addr_covered_by_ipato(struct qeth_card
*card
,
88 struct qeth_ipaddr
*addr
)
90 struct qeth_ipato_entry
*ipatoe
;
91 u8 addr_bits
[128] = {0, };
92 u8 ipatoe_bits
[128] = {0, };
95 if (!card
->ipato
.enabled
)
97 if (addr
->type
!= QETH_IP_TYPE_NORMAL
)
100 qeth_l3_convert_addr_to_bits((u8
*) &addr
->u
, addr_bits
,
101 (addr
->proto
== QETH_PROT_IPV4
) ? 4 : 16);
102 list_for_each_entry(ipatoe
, &card
->ipato
.entries
, entry
) {
103 if (addr
->proto
!= ipatoe
->proto
)
105 qeth_l3_convert_addr_to_bits(ipatoe
->addr
, ipatoe_bits
,
106 (ipatoe
->proto
== QETH_PROT_IPV4
) ?
108 rc
= !memcmp(addr_bits
, ipatoe_bits
, ipatoe
->mask_bits
);
113 if ((addr
->proto
== QETH_PROT_IPV4
) && card
->ipato
.invert4
)
115 else if ((addr
->proto
== QETH_PROT_IPV6
) && card
->ipato
.invert6
)
121 static int qeth_l3_delete_ip(struct qeth_card
*card
,
122 struct qeth_ipaddr
*tmp_addr
)
125 struct qeth_ipaddr
*addr
;
127 if (tmp_addr
->type
== QETH_IP_TYPE_RXIP
)
128 QETH_CARD_TEXT(card
, 2, "delrxip");
129 else if (tmp_addr
->type
== QETH_IP_TYPE_VIPA
)
130 QETH_CARD_TEXT(card
, 2, "delvipa");
132 QETH_CARD_TEXT(card
, 2, "delip");
134 if (tmp_addr
->proto
== QETH_PROT_IPV4
)
135 QETH_CARD_HEX(card
, 4, &tmp_addr
->u
.a4
.addr
, 4);
137 QETH_CARD_HEX(card
, 4, &tmp_addr
->u
.a6
.addr
, 8);
138 QETH_CARD_HEX(card
, 4, ((char *)&tmp_addr
->u
.a6
.addr
) + 8, 8);
141 addr
= qeth_l3_find_addr_by_ip(card
, tmp_addr
);
142 if (!addr
|| !qeth_l3_addr_match_all(addr
, tmp_addr
))
146 if (addr
->type
== QETH_IP_TYPE_NORMAL
&& addr
->ref_counter
> 0)
149 if (qeth_card_hw_is_reachable(card
))
150 rc
= qeth_l3_deregister_addr_entry(card
, addr
);
152 hash_del(&addr
->hnode
);
158 static int qeth_l3_add_ip(struct qeth_card
*card
, struct qeth_ipaddr
*tmp_addr
)
161 struct qeth_ipaddr
*addr
;
162 char buf
[INET6_ADDRSTRLEN
];
164 if (tmp_addr
->type
== QETH_IP_TYPE_RXIP
)
165 QETH_CARD_TEXT(card
, 2, "addrxip");
166 else if (tmp_addr
->type
== QETH_IP_TYPE_VIPA
)
167 QETH_CARD_TEXT(card
, 2, "addvipa");
169 QETH_CARD_TEXT(card
, 2, "addip");
171 if (tmp_addr
->proto
== QETH_PROT_IPV4
)
172 QETH_CARD_HEX(card
, 4, &tmp_addr
->u
.a4
.addr
, 4);
174 QETH_CARD_HEX(card
, 4, &tmp_addr
->u
.a6
.addr
, 8);
175 QETH_CARD_HEX(card
, 4, ((char *)&tmp_addr
->u
.a6
.addr
) + 8, 8);
178 addr
= qeth_l3_find_addr_by_ip(card
, tmp_addr
);
180 if (tmp_addr
->type
!= QETH_IP_TYPE_NORMAL
)
182 if (qeth_l3_addr_match_all(addr
, tmp_addr
)) {
186 qeth_l3_ipaddr_to_string(tmp_addr
->proto
, (u8
*)&tmp_addr
->u
,
188 dev_warn(&card
->gdev
->dev
,
189 "Registering IP address %s failed\n", buf
);
192 addr
= kmemdup(tmp_addr
, sizeof(*tmp_addr
), GFP_KERNEL
);
196 if (qeth_l3_is_addr_covered_by_ipato(card
, addr
)) {
197 QETH_CARD_TEXT(card
, 2, "tkovaddr");
200 hash_add(card
->ip_htable
, &addr
->hnode
,
201 qeth_l3_ipaddr_hash(addr
));
203 if (!qeth_card_hw_is_reachable(card
)) {
204 addr
->disp_flag
= QETH_DISP_ADDR_ADD
;
208 rc
= qeth_l3_register_addr_entry(card
, addr
);
210 if (!rc
|| rc
== -EADDRINUSE
|| rc
== -ENETDOWN
) {
211 addr
->disp_flag
= QETH_DISP_ADDR_DO_NOTHING
;
213 hash_del(&addr
->hnode
);
220 static int qeth_l3_modify_ip(struct qeth_card
*card
, struct qeth_ipaddr
*addr
,
225 mutex_lock(&card
->ip_lock
);
226 rc
= add
? qeth_l3_add_ip(card
, addr
) : qeth_l3_delete_ip(card
, addr
);
227 mutex_unlock(&card
->ip_lock
);
232 static void qeth_l3_drain_rx_mode_cache(struct qeth_card
*card
)
234 struct qeth_ipaddr
*addr
;
235 struct hlist_node
*tmp
;
238 hash_for_each_safe(card
->rx_mode_addrs
, i
, tmp
, addr
, hnode
) {
239 hash_del(&addr
->hnode
);
244 static void qeth_l3_clear_ip_htable(struct qeth_card
*card
, int recover
)
246 struct qeth_ipaddr
*addr
;
247 struct hlist_node
*tmp
;
250 QETH_CARD_TEXT(card
, 4, "clearip");
252 mutex_lock(&card
->ip_lock
);
254 hash_for_each_safe(card
->ip_htable
, i
, tmp
, addr
, hnode
) {
256 hash_del(&addr
->hnode
);
259 /* prepare for recovery */
260 addr
->disp_flag
= QETH_DISP_ADDR_ADD
;
264 mutex_unlock(&card
->ip_lock
);
267 static void qeth_l3_recover_ip(struct qeth_card
*card
)
269 struct qeth_ipaddr
*addr
;
270 struct hlist_node
*tmp
;
274 QETH_CARD_TEXT(card
, 4, "recovrip");
276 mutex_lock(&card
->ip_lock
);
278 hash_for_each_safe(card
->ip_htable
, i
, tmp
, addr
, hnode
) {
279 if (addr
->disp_flag
== QETH_DISP_ADDR_ADD
) {
280 rc
= qeth_l3_register_addr_entry(card
, addr
);
282 if (!rc
|| rc
== -EADDRINUSE
|| rc
== -ENETDOWN
) {
283 /* keep it in the records */
284 addr
->disp_flag
= QETH_DISP_ADDR_DO_NOTHING
;
287 hash_del(&addr
->hnode
);
293 mutex_unlock(&card
->ip_lock
);
296 static int qeth_l3_setdelip_cb(struct qeth_card
*card
, struct qeth_reply
*reply
,
299 struct qeth_ipa_cmd
*cmd
= (struct qeth_ipa_cmd
*) data
;
301 switch (cmd
->hdr
.return_code
) {
304 case IPA_RC_DUPLICATE_IP_ADDRESS
:
306 case IPA_RC_MC_ADDR_NOT_FOUND
:
308 case IPA_RC_LAN_OFFLINE
:
315 static int qeth_l3_send_setdelmc(struct qeth_card
*card
,
316 struct qeth_ipaddr
*addr
,
317 enum qeth_ipa_cmds ipacmd
)
319 struct qeth_cmd_buffer
*iob
;
320 struct qeth_ipa_cmd
*cmd
;
322 QETH_CARD_TEXT(card
, 4, "setdelmc");
324 iob
= qeth_ipa_alloc_cmd(card
, ipacmd
, addr
->proto
,
325 IPA_DATA_SIZEOF(setdelipm
));
328 cmd
= __ipa_cmd(iob
);
329 if (addr
->proto
== QETH_PROT_IPV6
) {
330 cmd
->data
.setdelipm
.ip
= addr
->u
.a6
.addr
;
331 ipv6_eth_mc_map(&addr
->u
.a6
.addr
, cmd
->data
.setdelipm
.mac
);
333 cmd
->data
.setdelipm
.ip
.s6_addr32
[3] = addr
->u
.a4
.addr
;
334 ip_eth_mc_map(addr
->u
.a4
.addr
, cmd
->data
.setdelipm
.mac
);
337 return qeth_send_ipa_cmd(card
, iob
, qeth_l3_setdelip_cb
, NULL
);
340 static void qeth_l3_set_ipv6_prefix(struct in6_addr
*prefix
, unsigned int len
)
344 while (len
&& i
< 4) {
345 int mask_len
= min_t(int, len
, 32);
347 prefix
->s6_addr32
[i
] = inet_make_mask(mask_len
);
353 static u32
qeth_l3_get_setdelip_flags(struct qeth_ipaddr
*addr
, bool set
)
355 switch (addr
->type
) {
356 case QETH_IP_TYPE_RXIP
:
357 return (set
) ? QETH_IPA_SETIP_TAKEOVER_FLAG
: 0;
358 case QETH_IP_TYPE_VIPA
:
359 return (set
) ? QETH_IPA_SETIP_VIPA_FLAG
:
360 QETH_IPA_DELIP_VIPA_FLAG
;
362 return (set
&& addr
->ipato
) ? QETH_IPA_SETIP_TAKEOVER_FLAG
: 0;
366 static int qeth_l3_send_setdelip(struct qeth_card
*card
,
367 struct qeth_ipaddr
*addr
,
368 enum qeth_ipa_cmds ipacmd
)
370 struct qeth_cmd_buffer
*iob
;
371 struct qeth_ipa_cmd
*cmd
;
374 QETH_CARD_TEXT(card
, 4, "setdelip");
376 iob
= qeth_ipa_alloc_cmd(card
, ipacmd
, addr
->proto
,
377 IPA_DATA_SIZEOF(setdelip6
));
380 cmd
= __ipa_cmd(iob
);
382 flags
= qeth_l3_get_setdelip_flags(addr
, ipacmd
== IPA_CMD_SETIP
);
383 QETH_CARD_TEXT_(card
, 4, "flags%02X", flags
);
385 if (addr
->proto
== QETH_PROT_IPV6
) {
386 cmd
->data
.setdelip6
.addr
= addr
->u
.a6
.addr
;
387 qeth_l3_set_ipv6_prefix(&cmd
->data
.setdelip6
.prefix
,
389 cmd
->data
.setdelip6
.flags
= flags
;
391 cmd
->data
.setdelip4
.addr
= addr
->u
.a4
.addr
;
392 cmd
->data
.setdelip4
.mask
= addr
->u
.a4
.mask
;
393 cmd
->data
.setdelip4
.flags
= flags
;
396 return qeth_send_ipa_cmd(card
, iob
, qeth_l3_setdelip_cb
, NULL
);
399 static int qeth_l3_send_setrouting(struct qeth_card
*card
,
400 enum qeth_routing_types type
, enum qeth_prot_versions prot
)
403 struct qeth_ipa_cmd
*cmd
;
404 struct qeth_cmd_buffer
*iob
;
406 QETH_CARD_TEXT(card
, 4, "setroutg");
407 iob
= qeth_ipa_alloc_cmd(card
, IPA_CMD_SETRTG
, prot
,
408 IPA_DATA_SIZEOF(setrtg
));
411 cmd
= __ipa_cmd(iob
);
412 cmd
->data
.setrtg
.type
= (type
);
413 rc
= qeth_send_ipa_cmd(card
, iob
, NULL
, NULL
);
418 static int qeth_l3_correct_routing_type(struct qeth_card
*card
,
419 enum qeth_routing_types
*type
, enum qeth_prot_versions prot
)
424 case PRIMARY_CONNECTOR
:
425 case SECONDARY_CONNECTOR
:
426 case MULTICAST_ROUTER
:
435 case SECONDARY_ROUTER
:
437 case MULTICAST_ROUTER
:
438 if (qeth_is_ipafunc_supported(card
, prot
,
451 int qeth_l3_setrouting_v4(struct qeth_card
*card
)
455 QETH_CARD_TEXT(card
, 3, "setrtg4");
457 rc
= qeth_l3_correct_routing_type(card
, &card
->options
.route4
.type
,
462 rc
= qeth_l3_send_setrouting(card
, card
->options
.route4
.type
,
465 card
->options
.route4
.type
= NO_ROUTER
;
466 QETH_DBF_MESSAGE(2, "Error (%#06x) while setting routing type on device %x. Type set to 'no router'.\n",
467 rc
, CARD_DEVID(card
));
472 int qeth_l3_setrouting_v6(struct qeth_card
*card
)
476 QETH_CARD_TEXT(card
, 3, "setrtg6");
478 if (!qeth_is_supported(card
, IPA_IPV6
))
480 rc
= qeth_l3_correct_routing_type(card
, &card
->options
.route6
.type
,
485 rc
= qeth_l3_send_setrouting(card
, card
->options
.route6
.type
,
488 card
->options
.route6
.type
= NO_ROUTER
;
489 QETH_DBF_MESSAGE(2, "Error (%#06x) while setting routing type on device %x. Type set to 'no router'.\n",
490 rc
, CARD_DEVID(card
));
496 * IP address takeover related functions
500 * qeth_l3_update_ipato() - Update 'takeover' property, for all NORMAL IPs.
502 * Caller must hold ip_lock.
504 void qeth_l3_update_ipato(struct qeth_card
*card
)
506 struct qeth_ipaddr
*addr
;
509 hash_for_each(card
->ip_htable
, i
, addr
, hnode
) {
510 if (addr
->type
!= QETH_IP_TYPE_NORMAL
)
512 addr
->ipato
= qeth_l3_is_addr_covered_by_ipato(card
, addr
);
516 static void qeth_l3_clear_ipato_list(struct qeth_card
*card
)
518 struct qeth_ipato_entry
*ipatoe
, *tmp
;
520 mutex_lock(&card
->ip_lock
);
522 list_for_each_entry_safe(ipatoe
, tmp
, &card
->ipato
.entries
, entry
) {
523 list_del(&ipatoe
->entry
);
527 qeth_l3_update_ipato(card
);
528 mutex_unlock(&card
->ip_lock
);
531 int qeth_l3_add_ipato_entry(struct qeth_card
*card
,
532 struct qeth_ipato_entry
*new)
534 struct qeth_ipato_entry
*ipatoe
;
537 QETH_CARD_TEXT(card
, 2, "addipato");
539 mutex_lock(&card
->ip_lock
);
541 list_for_each_entry(ipatoe
, &card
->ipato
.entries
, entry
) {
542 if (ipatoe
->proto
!= new->proto
)
544 if (!memcmp(ipatoe
->addr
, new->addr
,
545 (ipatoe
->proto
== QETH_PROT_IPV4
) ? 4 : 16) &&
546 (ipatoe
->mask_bits
== new->mask_bits
)) {
553 list_add_tail(&new->entry
, &card
->ipato
.entries
);
554 qeth_l3_update_ipato(card
);
557 mutex_unlock(&card
->ip_lock
);
562 int qeth_l3_del_ipato_entry(struct qeth_card
*card
,
563 enum qeth_prot_versions proto
, u8
*addr
,
564 unsigned int mask_bits
)
566 struct qeth_ipato_entry
*ipatoe
, *tmp
;
569 QETH_CARD_TEXT(card
, 2, "delipato");
571 mutex_lock(&card
->ip_lock
);
573 list_for_each_entry_safe(ipatoe
, tmp
, &card
->ipato
.entries
, entry
) {
574 if (ipatoe
->proto
!= proto
)
576 if (!memcmp(ipatoe
->addr
, addr
,
577 (proto
== QETH_PROT_IPV4
) ? 4 : 16) &&
578 (ipatoe
->mask_bits
== mask_bits
)) {
579 list_del(&ipatoe
->entry
);
580 qeth_l3_update_ipato(card
);
586 mutex_unlock(&card
->ip_lock
);
591 int qeth_l3_modify_rxip_vipa(struct qeth_card
*card
, bool add
, const u8
*ip
,
592 enum qeth_ip_types type
,
593 enum qeth_prot_versions proto
)
595 struct qeth_ipaddr addr
;
597 qeth_l3_init_ipaddr(&addr
, type
, proto
);
598 if (proto
== QETH_PROT_IPV4
)
599 memcpy(&addr
.u
.a4
.addr
, ip
, 4);
601 memcpy(&addr
.u
.a6
.addr
, ip
, 16);
603 return qeth_l3_modify_ip(card
, &addr
, add
);
606 int qeth_l3_modify_hsuid(struct qeth_card
*card
, bool add
)
608 struct qeth_ipaddr addr
;
611 qeth_l3_init_ipaddr(&addr
, QETH_IP_TYPE_NORMAL
, QETH_PROT_IPV6
);
612 addr
.u
.a6
.addr
.s6_addr
[0] = 0xfe;
613 addr
.u
.a6
.addr
.s6_addr
[1] = 0x80;
614 for (i
= 0; i
< 8; i
++)
615 addr
.u
.a6
.addr
.s6_addr
[8+i
] = card
->options
.hsuid
[i
];
617 return qeth_l3_modify_ip(card
, &addr
, add
);
620 static int qeth_l3_register_addr_entry(struct qeth_card
*card
,
621 struct qeth_ipaddr
*addr
)
627 if (card
->options
.sniffer
)
630 if (addr
->proto
== QETH_PROT_IPV4
) {
631 QETH_CARD_TEXT(card
, 2, "setaddr4");
632 QETH_CARD_HEX(card
, 3, &addr
->u
.a4
.addr
, sizeof(int));
633 } else if (addr
->proto
== QETH_PROT_IPV6
) {
634 QETH_CARD_TEXT(card
, 2, "setaddr6");
635 QETH_CARD_HEX(card
, 3, &addr
->u
.a6
.addr
, 8);
636 QETH_CARD_HEX(card
, 3, ((char *)&addr
->u
.a6
.addr
) + 8, 8);
638 QETH_CARD_TEXT(card
, 2, "setaddr?");
639 QETH_CARD_HEX(card
, 3, addr
, sizeof(struct qeth_ipaddr
));
642 if (addr
->is_multicast
)
643 rc
= qeth_l3_send_setdelmc(card
, addr
, IPA_CMD_SETIPM
);
645 rc
= qeth_l3_send_setdelip(card
, addr
, IPA_CMD_SETIP
);
647 QETH_CARD_TEXT(card
, 2, "failed");
648 } while ((--cnt
> 0) && rc
);
650 QETH_CARD_TEXT(card
, 2, "FAILED");
651 qeth_l3_ipaddr_to_string(addr
->proto
, (u8
*)&addr
->u
, buf
);
652 dev_warn(&card
->gdev
->dev
,
653 "Registering IP address %s failed\n", buf
);
658 static int qeth_l3_deregister_addr_entry(struct qeth_card
*card
,
659 struct qeth_ipaddr
*addr
)
663 if (card
->options
.sniffer
)
666 if (addr
->proto
== QETH_PROT_IPV4
) {
667 QETH_CARD_TEXT(card
, 2, "deladdr4");
668 QETH_CARD_HEX(card
, 3, &addr
->u
.a4
.addr
, sizeof(int));
669 } else if (addr
->proto
== QETH_PROT_IPV6
) {
670 QETH_CARD_TEXT(card
, 2, "deladdr6");
671 QETH_CARD_HEX(card
, 3, &addr
->u
.a6
.addr
, 8);
672 QETH_CARD_HEX(card
, 3, ((char *)&addr
->u
.a6
.addr
) + 8, 8);
674 QETH_CARD_TEXT(card
, 2, "deladdr?");
675 QETH_CARD_HEX(card
, 3, addr
, sizeof(struct qeth_ipaddr
));
677 if (addr
->is_multicast
)
678 rc
= qeth_l3_send_setdelmc(card
, addr
, IPA_CMD_DELIPM
);
680 rc
= qeth_l3_send_setdelip(card
, addr
, IPA_CMD_DELIP
);
682 QETH_CARD_TEXT(card
, 2, "failed");
687 static int qeth_l3_setadapter_parms(struct qeth_card
*card
)
691 QETH_CARD_TEXT(card
, 2, "setadprm");
693 if (qeth_adp_supported(card
, IPA_SETADP_ALTER_MAC_ADDRESS
)) {
694 rc
= qeth_setadpparms_change_macaddr(card
);
696 dev_warn(&card
->gdev
->dev
, "Reading the adapter MAC"
697 " address failed\n");
703 static int qeth_l3_start_ipa_arp_processing(struct qeth_card
*card
)
707 QETH_CARD_TEXT(card
, 3, "ipaarp");
709 if (!qeth_is_supported(card
, IPA_ARP_PROCESSING
)) {
710 dev_info(&card
->gdev
->dev
,
711 "ARP processing not supported on %s!\n",
712 netdev_name(card
->dev
));
715 rc
= qeth_send_simple_setassparms(card
, IPA_ARP_PROCESSING
,
716 IPA_CMD_ASS_START
, NULL
);
718 dev_warn(&card
->gdev
->dev
,
719 "Starting ARP processing support for %s failed\n",
720 netdev_name(card
->dev
));
725 static int qeth_l3_start_ipa_source_mac(struct qeth_card
*card
)
729 QETH_CARD_TEXT(card
, 3, "stsrcmac");
731 if (!qeth_is_supported(card
, IPA_SOURCE_MAC
)) {
732 dev_info(&card
->gdev
->dev
,
733 "Inbound source MAC-address not supported on %s\n",
734 netdev_name(card
->dev
));
738 rc
= qeth_send_simple_setassparms(card
, IPA_SOURCE_MAC
,
739 IPA_CMD_ASS_START
, NULL
);
741 dev_warn(&card
->gdev
->dev
,
742 "Starting source MAC-address support for %s failed\n",
743 netdev_name(card
->dev
));
747 static int qeth_l3_start_ipa_vlan(struct qeth_card
*card
)
751 QETH_CARD_TEXT(card
, 3, "strtvlan");
753 if (!qeth_is_supported(card
, IPA_FULL_VLAN
)) {
754 dev_info(&card
->gdev
->dev
,
755 "VLAN not supported on %s\n", netdev_name(card
->dev
));
759 rc
= qeth_send_simple_setassparms(card
, IPA_VLAN_PRIO
,
760 IPA_CMD_ASS_START
, NULL
);
762 dev_warn(&card
->gdev
->dev
,
763 "Starting VLAN support for %s failed\n",
764 netdev_name(card
->dev
));
766 dev_info(&card
->gdev
->dev
, "VLAN enabled\n");
771 static int qeth_l3_start_ipa_multicast(struct qeth_card
*card
)
775 QETH_CARD_TEXT(card
, 3, "stmcast");
777 if (!qeth_is_supported(card
, IPA_MULTICASTING
)) {
778 dev_info(&card
->gdev
->dev
,
779 "Multicast not supported on %s\n",
780 netdev_name(card
->dev
));
784 rc
= qeth_send_simple_setassparms(card
, IPA_MULTICASTING
,
785 IPA_CMD_ASS_START
, NULL
);
787 dev_warn(&card
->gdev
->dev
,
788 "Starting multicast support for %s failed\n",
789 netdev_name(card
->dev
));
791 dev_info(&card
->gdev
->dev
, "Multicast enabled\n");
792 card
->dev
->flags
|= IFF_MULTICAST
;
797 static int qeth_l3_softsetup_ipv6(struct qeth_card
*card
)
802 QETH_CARD_TEXT(card
, 3, "softipv6");
807 rc
= qeth_send_simple_setassparms(card
, IPA_IPV6
, IPA_CMD_ASS_START
,
810 dev_err(&card
->gdev
->dev
,
811 "Activating IPv6 support for %s failed\n",
812 netdev_name(card
->dev
));
815 rc
= qeth_send_simple_setassparms_v6(card
, IPA_IPV6
, IPA_CMD_ASS_START
,
818 dev_err(&card
->gdev
->dev
,
819 "Activating IPv6 support for %s failed\n",
820 netdev_name(card
->dev
));
823 rc
= qeth_send_simple_setassparms_v6(card
, IPA_PASSTHRU
,
824 IPA_CMD_ASS_START
, NULL
);
826 dev_warn(&card
->gdev
->dev
,
827 "Enabling the passthrough mode for %s failed\n",
828 netdev_name(card
->dev
));
832 dev_info(&card
->gdev
->dev
, "IPV6 enabled\n");
836 static int qeth_l3_start_ipa_ipv6(struct qeth_card
*card
)
838 QETH_CARD_TEXT(card
, 3, "strtipv6");
840 if (!qeth_is_supported(card
, IPA_IPV6
)) {
841 dev_info(&card
->gdev
->dev
,
842 "IPv6 not supported on %s\n", netdev_name(card
->dev
));
845 return qeth_l3_softsetup_ipv6(card
);
848 static int qeth_l3_start_ipa_broadcast(struct qeth_card
*card
)
853 QETH_CARD_TEXT(card
, 3, "stbrdcst");
854 card
->info
.broadcast_capable
= 0;
855 if (!qeth_is_supported(card
, IPA_FILTERING
)) {
856 dev_info(&card
->gdev
->dev
,
857 "Broadcast not supported on %s\n",
858 netdev_name(card
->dev
));
862 rc
= qeth_send_simple_setassparms(card
, IPA_FILTERING
,
863 IPA_CMD_ASS_START
, NULL
);
865 dev_warn(&card
->gdev
->dev
,
866 "Enabling broadcast filtering for %s failed\n",
867 netdev_name(card
->dev
));
871 rc
= qeth_send_simple_setassparms(card
, IPA_FILTERING
,
872 IPA_CMD_ASS_CONFIGURE
, &filter_data
);
874 dev_warn(&card
->gdev
->dev
,
875 "Setting up broadcast filtering for %s failed\n",
876 netdev_name(card
->dev
));
879 card
->info
.broadcast_capable
= QETH_BROADCAST_WITH_ECHO
;
880 dev_info(&card
->gdev
->dev
, "Broadcast enabled\n");
881 rc
= qeth_send_simple_setassparms(card
, IPA_FILTERING
,
882 IPA_CMD_ASS_ENABLE
, &filter_data
);
884 dev_warn(&card
->gdev
->dev
,
885 "Setting up broadcast echo filtering for %s failed\n",
886 netdev_name(card
->dev
));
889 card
->info
.broadcast_capable
= QETH_BROADCAST_WITHOUT_ECHO
;
891 if (card
->info
.broadcast_capable
)
892 card
->dev
->flags
|= IFF_BROADCAST
;
894 card
->dev
->flags
&= ~IFF_BROADCAST
;
898 static void qeth_l3_start_ipassists(struct qeth_card
*card
)
900 QETH_CARD_TEXT(card
, 3, "strtipas");
902 qeth_l3_start_ipa_arp_processing(card
); /* go on*/
903 qeth_l3_start_ipa_source_mac(card
); /* go on*/
904 qeth_l3_start_ipa_vlan(card
); /* go on*/
905 qeth_l3_start_ipa_multicast(card
); /* go on*/
906 qeth_l3_start_ipa_ipv6(card
); /* go on*/
907 qeth_l3_start_ipa_broadcast(card
); /* go on*/
910 static int qeth_l3_iqd_read_initial_mac_cb(struct qeth_card
*card
,
911 struct qeth_reply
*reply
, unsigned long data
)
913 struct qeth_ipa_cmd
*cmd
= (struct qeth_ipa_cmd
*) data
;
915 if (cmd
->hdr
.return_code
)
917 if (!is_valid_ether_addr(cmd
->data
.create_destroy_addr
.mac_addr
))
918 return -EADDRNOTAVAIL
;
920 eth_hw_addr_set(card
->dev
, cmd
->data
.create_destroy_addr
.mac_addr
);
924 static int qeth_l3_iqd_read_initial_mac(struct qeth_card
*card
)
927 struct qeth_cmd_buffer
*iob
;
929 QETH_CARD_TEXT(card
, 2, "hsrmac");
931 iob
= qeth_ipa_alloc_cmd(card
, IPA_CMD_CREATE_ADDR
, QETH_PROT_IPV6
,
932 IPA_DATA_SIZEOF(create_destroy_addr
));
936 rc
= qeth_send_ipa_cmd(card
, iob
, qeth_l3_iqd_read_initial_mac_cb
,
941 static int qeth_l3_get_unique_id_cb(struct qeth_card
*card
,
942 struct qeth_reply
*reply
, unsigned long data
)
944 struct qeth_ipa_cmd
*cmd
= (struct qeth_ipa_cmd
*) data
;
945 u16
*uid
= reply
->param
;
947 if (cmd
->hdr
.return_code
== 0) {
948 *uid
= cmd
->data
.create_destroy_addr
.uid
;
952 dev_warn(&card
->gdev
->dev
, "The network adapter failed to generate a unique ID\n");
956 static u16
qeth_l3_get_unique_id(struct qeth_card
*card
, u16 uid
)
958 struct qeth_cmd_buffer
*iob
;
960 QETH_CARD_TEXT(card
, 2, "guniqeid");
962 if (!qeth_is_supported(card
, IPA_IPV6
))
965 iob
= qeth_ipa_alloc_cmd(card
, IPA_CMD_CREATE_ADDR
, QETH_PROT_IPV6
,
966 IPA_DATA_SIZEOF(create_destroy_addr
));
970 __ipa_cmd(iob
)->data
.create_destroy_addr
.uid
= uid
;
971 qeth_send_ipa_cmd(card
, iob
, qeth_l3_get_unique_id_cb
, &uid
);
978 qeth_diags_trace_cb(struct qeth_card
*card
, struct qeth_reply
*reply
,
981 struct qeth_ipa_cmd
*cmd
;
984 QETH_CARD_TEXT(card
, 2, "diastrcb");
986 cmd
= (struct qeth_ipa_cmd
*)data
;
987 rc
= cmd
->hdr
.return_code
;
989 QETH_CARD_TEXT_(card
, 2, "dxter%x", rc
);
990 switch (cmd
->data
.diagass
.action
) {
991 case QETH_DIAGS_CMD_TRACE_QUERY
:
993 case QETH_DIAGS_CMD_TRACE_DISABLE
:
996 case IPA_RC_INVALID_SUBCMD
:
997 card
->info
.promisc_mode
= SET_PROMISC_MODE_OFF
;
998 dev_info(&card
->gdev
->dev
, "The HiperSockets network "
999 "traffic analyzer is deactivated\n");
1005 case QETH_DIAGS_CMD_TRACE_ENABLE
:
1008 card
->info
.promisc_mode
= SET_PROMISC_MODE_ON
;
1009 dev_info(&card
->gdev
->dev
, "The HiperSockets network "
1010 "traffic analyzer is activated\n");
1012 case IPA_RC_HARDWARE_AUTH_ERROR
:
1013 dev_warn(&card
->gdev
->dev
, "The device is not "
1014 "authorized to run as a HiperSockets network "
1015 "traffic analyzer\n");
1017 case IPA_RC_TRACE_ALREADY_ACTIVE
:
1018 dev_warn(&card
->gdev
->dev
, "A HiperSockets "
1019 "network traffic analyzer is already "
1020 "active in the HiperSockets LAN\n");
1027 QETH_DBF_MESSAGE(2, "Unknown sniffer action (%#06x) on device %x\n",
1028 cmd
->data
.diagass
.action
, CARD_DEVID(card
));
1031 return rc
? -EIO
: 0;
1035 qeth_diags_trace(struct qeth_card
*card
, enum qeth_diags_trace_cmds diags_cmd
)
1037 struct qeth_cmd_buffer
*iob
;
1038 struct qeth_ipa_cmd
*cmd
;
1040 QETH_CARD_TEXT(card
, 2, "diagtrac");
1042 iob
= qeth_get_diag_cmd(card
, QETH_DIAGS_CMD_TRACE
, 0);
1045 cmd
= __ipa_cmd(iob
);
1046 cmd
->data
.diagass
.type
= QETH_DIAGS_TYPE_HIPERSOCKET
;
1047 cmd
->data
.diagass
.action
= diags_cmd
;
1048 return qeth_send_ipa_cmd(card
, iob
, qeth_diags_trace_cb
, NULL
);
1051 static int qeth_l3_add_mcast_rtnl(struct net_device
*dev
, int vid
, void *arg
)
1053 struct qeth_card
*card
= arg
;
1054 struct inet6_dev
*in6_dev
;
1055 struct in_device
*in4_dev
;
1056 struct qeth_ipaddr
*ipm
;
1057 struct qeth_ipaddr tmp
;
1058 struct ip_mc_list
*im4
;
1059 struct ifmcaddr6
*im6
;
1061 QETH_CARD_TEXT(card
, 4, "addmc");
1063 if (!dev
|| !(dev
->flags
& IFF_UP
))
1066 in4_dev
= __in_dev_get_rtnl(dev
);
1070 qeth_l3_init_ipaddr(&tmp
, QETH_IP_TYPE_NORMAL
, QETH_PROT_IPV4
);
1071 tmp
.disp_flag
= QETH_DISP_ADDR_ADD
;
1072 tmp
.is_multicast
= 1;
1074 for (im4
= rtnl_dereference(in4_dev
->mc_list
); im4
!= NULL
;
1075 im4
= rtnl_dereference(im4
->next_rcu
)) {
1076 tmp
.u
.a4
.addr
= im4
->multiaddr
;
1078 ipm
= qeth_l3_find_addr_by_ip(card
, &tmp
);
1080 /* for mcast, by-IP match means full match */
1081 ipm
->disp_flag
= QETH_DISP_ADDR_DO_NOTHING
;
1085 ipm
= kmemdup(&tmp
, sizeof(tmp
), GFP_KERNEL
);
1089 hash_add(card
->rx_mode_addrs
, &ipm
->hnode
,
1090 qeth_l3_ipaddr_hash(ipm
));
1094 if (!qeth_is_supported(card
, IPA_IPV6
))
1097 in6_dev
= __in6_dev_get(dev
);
1101 qeth_l3_init_ipaddr(&tmp
, QETH_IP_TYPE_NORMAL
, QETH_PROT_IPV6
);
1102 tmp
.disp_flag
= QETH_DISP_ADDR_ADD
;
1103 tmp
.is_multicast
= 1;
1105 for (im6
= rtnl_dereference(in6_dev
->mc_list
);
1107 im6
= rtnl_dereference(im6
->next
)) {
1108 tmp
.u
.a6
.addr
= im6
->mca_addr
;
1110 ipm
= qeth_l3_find_addr_by_ip(card
, &tmp
);
1112 /* for mcast, by-IP match means full match */
1113 ipm
->disp_flag
= QETH_DISP_ADDR_DO_NOTHING
;
1117 ipm
= kmemdup(&tmp
, sizeof(tmp
), GFP_ATOMIC
);
1121 hash_add(card
->rx_mode_addrs
, &ipm
->hnode
,
1122 qeth_l3_ipaddr_hash(ipm
));
1130 static void qeth_l3_set_promisc_mode(struct qeth_card
*card
)
1132 bool enable
= card
->dev
->flags
& IFF_PROMISC
;
1134 if (card
->info
.promisc_mode
== enable
)
1137 if (IS_VM_NIC(card
)) { /* Guestlan trace */
1138 if (qeth_adp_supported(card
, IPA_SETADP_SET_PROMISC_MODE
))
1139 qeth_setadp_promisc_mode(card
, enable
);
1140 } else if (card
->options
.sniffer
&& /* HiperSockets trace */
1141 qeth_adp_supported(card
, IPA_SETADP_SET_DIAG_ASSIST
)) {
1143 QETH_CARD_TEXT(card
, 3, "+promisc");
1144 qeth_diags_trace(card
, QETH_DIAGS_CMD_TRACE_ENABLE
);
1146 QETH_CARD_TEXT(card
, 3, "-promisc");
1147 qeth_diags_trace(card
, QETH_DIAGS_CMD_TRACE_DISABLE
);
1152 static void qeth_l3_rx_mode_work(struct work_struct
*work
)
1154 struct qeth_card
*card
= container_of(work
, struct qeth_card
,
1156 struct qeth_ipaddr
*addr
;
1157 struct hlist_node
*tmp
;
1160 QETH_CARD_TEXT(card
, 3, "setmulti");
1162 if (!card
->options
.sniffer
) {
1164 qeth_l3_add_mcast_rtnl(card
->dev
, 0, card
);
1165 if (qeth_is_supported(card
, IPA_FULL_VLAN
))
1166 vlan_for_each(card
->dev
, qeth_l3_add_mcast_rtnl
, card
);
1169 hash_for_each_safe(card
->rx_mode_addrs
, i
, tmp
, addr
, hnode
) {
1170 switch (addr
->disp_flag
) {
1171 case QETH_DISP_ADDR_DELETE
:
1172 rc
= qeth_l3_deregister_addr_entry(card
, addr
);
1173 if (!rc
|| rc
== -ENOENT
) {
1174 hash_del(&addr
->hnode
);
1178 case QETH_DISP_ADDR_ADD
:
1179 rc
= qeth_l3_register_addr_entry(card
, addr
);
1180 if (rc
&& rc
!= -ENETDOWN
) {
1181 hash_del(&addr
->hnode
);
1187 /* for next call to set_rx_mode(): */
1188 addr
->disp_flag
= QETH_DISP_ADDR_DELETE
;
1193 qeth_l3_set_promisc_mode(card
);
1196 static int qeth_l3_arp_makerc(u16 rc
)
1199 case IPA_RC_SUCCESS
:
1201 case QETH_IPA_ARP_RC_NOTSUPP
:
1202 case QETH_IPA_ARP_RC_Q_NOTSUPP
:
1204 case QETH_IPA_ARP_RC_OUT_OF_RANGE
:
1206 case QETH_IPA_ARP_RC_Q_NO_DATA
:
1213 static int qeth_l3_arp_cmd_cb(struct qeth_card
*card
, struct qeth_reply
*reply
,
1216 struct qeth_ipa_cmd
*cmd
= (struct qeth_ipa_cmd
*) data
;
1218 qeth_setassparms_cb(card
, reply
, data
);
1219 return qeth_l3_arp_makerc(cmd
->hdr
.return_code
);
1222 static int qeth_l3_arp_set_no_entries(struct qeth_card
*card
, int no_entries
)
1224 struct qeth_cmd_buffer
*iob
;
1227 QETH_CARD_TEXT(card
, 3, "arpstnoe");
1230 * currently GuestLAN only supports the ARP assist function
1231 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_SET_NO_ENTRIES;
1232 * thus we say EOPNOTSUPP for this ARP function
1234 if (IS_VM_NIC(card
))
1236 if (!qeth_is_supported(card
, IPA_ARP_PROCESSING
)) {
1240 iob
= qeth_get_setassparms_cmd(card
, IPA_ARP_PROCESSING
,
1241 IPA_CMD_ASS_ARP_SET_NO_ENTRIES
,
1242 SETASS_DATA_SIZEOF(flags_32bit
),
1247 __ipa_cmd(iob
)->data
.setassparms
.data
.flags_32bit
= (u32
) no_entries
;
1248 rc
= qeth_send_ipa_cmd(card
, iob
, qeth_l3_arp_cmd_cb
, NULL
);
1250 QETH_DBF_MESSAGE(2, "Could not set number of ARP entries on device %x: %#x\n",
1251 CARD_DEVID(card
), rc
);
1255 static __u32
get_arp_entry_size(struct qeth_card
*card
,
1256 struct qeth_arp_query_data
*qdata
,
1257 struct qeth_arp_entrytype
*type
, __u8 strip_entries
)
1262 is_hsi
= qdata
->reply_bits
== 5;
1263 if (type
->ip
== QETHARP_IP_ADDR_V4
) {
1264 QETH_CARD_TEXT(card
, 4, "arpev4");
1265 if (strip_entries
) {
1266 rc
= is_hsi
? sizeof(struct qeth_arp_qi_entry5_short
) :
1267 sizeof(struct qeth_arp_qi_entry7_short
);
1269 rc
= is_hsi
? sizeof(struct qeth_arp_qi_entry5
) :
1270 sizeof(struct qeth_arp_qi_entry7
);
1272 } else if (type
->ip
== QETHARP_IP_ADDR_V6
) {
1273 QETH_CARD_TEXT(card
, 4, "arpev6");
1274 if (strip_entries
) {
1276 sizeof(struct qeth_arp_qi_entry5_short_ipv6
) :
1277 sizeof(struct qeth_arp_qi_entry7_short_ipv6
);
1280 sizeof(struct qeth_arp_qi_entry5_ipv6
) :
1281 sizeof(struct qeth_arp_qi_entry7_ipv6
);
1284 QETH_CARD_TEXT(card
, 4, "arpinv");
1291 static int arpentry_matches_prot(struct qeth_arp_entrytype
*type
, __u16 prot
)
1293 return (type
->ip
== QETHARP_IP_ADDR_V4
&& prot
== QETH_PROT_IPV4
) ||
1294 (type
->ip
== QETHARP_IP_ADDR_V6
&& prot
== QETH_PROT_IPV6
);
1297 static int qeth_l3_arp_query_cb(struct qeth_card
*card
,
1298 struct qeth_reply
*reply
, unsigned long data
)
1300 struct qeth_ipa_cmd
*cmd
;
1301 struct qeth_arp_query_data
*qdata
;
1302 struct qeth_arp_query_info
*qinfo
;
1304 int entrybytes_done
;
1306 __u8 do_strip_entries
;
1308 QETH_CARD_TEXT(card
, 3, "arpquecb");
1310 qinfo
= (struct qeth_arp_query_info
*) reply
->param
;
1311 cmd
= (struct qeth_ipa_cmd
*) data
;
1312 QETH_CARD_TEXT_(card
, 4, "%i", cmd
->hdr
.prot_version
);
1313 if (cmd
->hdr
.return_code
) {
1314 QETH_CARD_TEXT(card
, 4, "arpcberr");
1315 QETH_CARD_TEXT_(card
, 4, "%i", cmd
->hdr
.return_code
);
1316 return qeth_l3_arp_makerc(cmd
->hdr
.return_code
);
1318 if (cmd
->data
.setassparms
.hdr
.return_code
) {
1319 cmd
->hdr
.return_code
= cmd
->data
.setassparms
.hdr
.return_code
;
1320 QETH_CARD_TEXT(card
, 4, "setaperr");
1321 QETH_CARD_TEXT_(card
, 4, "%i", cmd
->hdr
.return_code
);
1322 return qeth_l3_arp_makerc(cmd
->hdr
.return_code
);
1324 qdata
= &cmd
->data
.setassparms
.data
.query_arp
;
1325 QETH_CARD_TEXT_(card
, 4, "anoen%i", qdata
->no_entries
);
1327 do_strip_entries
= (qinfo
->mask_bits
& QETH_QARP_STRIP_ENTRIES
) > 0;
1328 stripped_bytes
= do_strip_entries
? QETH_QARP_MEDIASPECIFIC_BYTES
: 0;
1329 entrybytes_done
= 0;
1330 for (e
= 0; e
< qdata
->no_entries
; ++e
) {
1333 struct qeth_arp_entrytype
*etype
;
1335 cur_entry
= &qdata
->data
+ entrybytes_done
;
1336 etype
= &((struct qeth_arp_qi_entry5
*) cur_entry
)->type
;
1337 if (!arpentry_matches_prot(etype
, cmd
->hdr
.prot_version
)) {
1338 QETH_CARD_TEXT(card
, 4, "pmis");
1339 QETH_CARD_TEXT_(card
, 4, "%i", etype
->ip
);
1342 esize
= get_arp_entry_size(card
, qdata
, etype
,
1344 QETH_CARD_TEXT_(card
, 5, "esz%i", esize
);
1348 if ((qinfo
->udata_len
- qinfo
->udata_offset
) < esize
) {
1349 QETH_CARD_TEXT_(card
, 4, "qaer3%i", -ENOSPC
);
1350 memset(qinfo
->udata
, 0, 4);
1354 memcpy(qinfo
->udata
+ qinfo
->udata_offset
,
1355 &qdata
->data
+ entrybytes_done
+ stripped_bytes
,
1357 entrybytes_done
+= esize
+ stripped_bytes
;
1358 qinfo
->udata_offset
+= esize
;
1359 ++qinfo
->no_entries
;
1361 /* check if all replies received ... */
1362 if (cmd
->data
.setassparms
.hdr
.seq_no
<
1363 cmd
->data
.setassparms
.hdr
.number_of_replies
)
1365 QETH_CARD_TEXT_(card
, 4, "nove%i", qinfo
->no_entries
);
1366 memcpy(qinfo
->udata
, &qinfo
->no_entries
, 4);
1367 /* keep STRIP_ENTRIES flag so the user program can distinguish
1368 * stripped entries from normal ones */
1369 if (qinfo
->mask_bits
& QETH_QARP_STRIP_ENTRIES
)
1370 qdata
->reply_bits
|= QETH_QARP_STRIP_ENTRIES
;
1371 memcpy(qinfo
->udata
+ QETH_QARP_MASK_OFFSET
, &qdata
->reply_bits
, 2);
1372 QETH_CARD_TEXT_(card
, 4, "rc%i", 0);
1376 static int qeth_l3_query_arp_cache_info(struct qeth_card
*card
,
1377 enum qeth_prot_versions prot
,
1378 struct qeth_arp_query_info
*qinfo
)
1380 struct qeth_cmd_buffer
*iob
;
1381 struct qeth_ipa_cmd
*cmd
;
1384 QETH_CARD_TEXT_(card
, 3, "qarpipv%i", prot
);
1386 iob
= qeth_get_setassparms_cmd(card
, IPA_ARP_PROCESSING
,
1387 IPA_CMD_ASS_ARP_QUERY_INFO
,
1388 SETASS_DATA_SIZEOF(query_arp
), prot
);
1391 cmd
= __ipa_cmd(iob
);
1392 cmd
->data
.setassparms
.data
.query_arp
.request_bits
= 0x000F;
1393 rc
= qeth_send_ipa_cmd(card
, iob
, qeth_l3_arp_query_cb
, qinfo
);
1395 QETH_DBF_MESSAGE(2, "Error while querying ARP cache on device %x: %#x\n",
1396 CARD_DEVID(card
), rc
);
1400 static int qeth_l3_arp_query(struct qeth_card
*card
, char __user
*udata
)
1402 struct qeth_arp_query_info qinfo
= {0, };
1405 QETH_CARD_TEXT(card
, 3, "arpquery");
1407 if (!qeth_is_supported(card
,/*IPA_QUERY_ARP_ADDR_INFO*/
1408 IPA_ARP_PROCESSING
)) {
1409 QETH_CARD_TEXT(card
, 3, "arpqnsup");
1413 /* get size of userspace buffer and mask_bits -> 6 bytes */
1414 if (copy_from_user(&qinfo
, udata
, 6)) {
1418 qinfo
.udata
= kzalloc(qinfo
.udata_len
, GFP_KERNEL
);
1423 qinfo
.udata_offset
= QETH_QARP_ENTRIES_OFFSET
;
1424 rc
= qeth_l3_query_arp_cache_info(card
, QETH_PROT_IPV4
, &qinfo
);
1426 if (copy_to_user(udata
, qinfo
.udata
, 4))
1430 if (qinfo
.mask_bits
& QETH_QARP_WITH_IPV6
) {
1431 /* fails in case of GuestLAN QDIO mode */
1432 qeth_l3_query_arp_cache_info(card
, QETH_PROT_IPV6
, &qinfo
);
1434 if (copy_to_user(udata
, qinfo
.udata
, qinfo
.udata_len
)) {
1435 QETH_CARD_TEXT(card
, 4, "qactf");
1439 QETH_CARD_TEXT(card
, 4, "qacts");
1447 static int qeth_l3_arp_modify_entry(struct qeth_card
*card
,
1448 struct qeth_arp_cache_entry
*entry
,
1449 enum qeth_arp_process_subcmds arp_cmd
)
1451 struct qeth_arp_cache_entry
*cmd_entry
;
1452 struct qeth_cmd_buffer
*iob
;
1455 if (arp_cmd
== IPA_CMD_ASS_ARP_ADD_ENTRY
)
1456 QETH_CARD_TEXT(card
, 3, "arpadd");
1458 QETH_CARD_TEXT(card
, 3, "arpdel");
1461 * currently GuestLAN only supports the ARP assist function
1462 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_ADD_ENTRY;
1463 * thus we say EOPNOTSUPP for this ARP function
1465 if (IS_VM_NIC(card
))
1467 if (!qeth_is_supported(card
, IPA_ARP_PROCESSING
)) {
1471 iob
= qeth_get_setassparms_cmd(card
, IPA_ARP_PROCESSING
, arp_cmd
,
1472 SETASS_DATA_SIZEOF(arp_entry
),
1477 cmd_entry
= &__ipa_cmd(iob
)->data
.setassparms
.data
.arp_entry
;
1478 ether_addr_copy(cmd_entry
->macaddr
, entry
->macaddr
);
1479 memcpy(cmd_entry
->ipaddr
, entry
->ipaddr
, 4);
1480 rc
= qeth_send_ipa_cmd(card
, iob
, qeth_l3_arp_cmd_cb
, NULL
);
1482 QETH_DBF_MESSAGE(2, "Could not modify (cmd: %#x) ARP entry on device %x: %#x\n",
1483 arp_cmd
, CARD_DEVID(card
), rc
);
1487 static int qeth_l3_arp_flush_cache(struct qeth_card
*card
)
1489 struct qeth_cmd_buffer
*iob
;
1492 QETH_CARD_TEXT(card
, 3, "arpflush");
1495 * currently GuestLAN only supports the ARP assist function
1496 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_FLUSH_CACHE;
1497 * thus we say EOPNOTSUPP for this ARP function
1499 if (IS_VM_NIC(card
) || IS_IQD(card
))
1501 if (!qeth_is_supported(card
, IPA_ARP_PROCESSING
)) {
1505 iob
= qeth_get_setassparms_cmd(card
, IPA_ARP_PROCESSING
,
1506 IPA_CMD_ASS_ARP_FLUSH_CACHE
, 0,
1511 rc
= qeth_send_ipa_cmd(card
, iob
, qeth_l3_arp_cmd_cb
, NULL
);
1513 QETH_DBF_MESSAGE(2, "Could not flush ARP cache on device %x: %#x\n",
1514 CARD_DEVID(card
), rc
);
1518 static int qeth_l3_ndo_siocdevprivate(struct net_device
*dev
, struct ifreq
*rq
,
1519 void __user
*data
, int cmd
)
1521 struct qeth_card
*card
= dev
->ml_priv
;
1522 struct qeth_arp_cache_entry arp_entry
;
1523 enum qeth_arp_process_subcmds arp_cmd
;
1527 case SIOC_QETH_ARP_SET_NO_ENTRIES
:
1528 if (!capable(CAP_NET_ADMIN
)) {
1532 rc
= qeth_l3_arp_set_no_entries(card
, rq
->ifr_ifru
.ifru_ivalue
);
1534 case SIOC_QETH_ARP_QUERY_INFO
:
1535 if (!capable(CAP_NET_ADMIN
)) {
1539 rc
= qeth_l3_arp_query(card
, data
);
1541 case SIOC_QETH_ARP_ADD_ENTRY
:
1542 case SIOC_QETH_ARP_REMOVE_ENTRY
:
1543 if (!capable(CAP_NET_ADMIN
))
1545 if (copy_from_user(&arp_entry
, data
, sizeof(arp_entry
)))
1548 arp_cmd
= (cmd
== SIOC_QETH_ARP_ADD_ENTRY
) ?
1549 IPA_CMD_ASS_ARP_ADD_ENTRY
:
1550 IPA_CMD_ASS_ARP_REMOVE_ENTRY
;
1551 return qeth_l3_arp_modify_entry(card
, &arp_entry
, arp_cmd
);
1552 case SIOC_QETH_ARP_FLUSH_CACHE
:
1553 if (!capable(CAP_NET_ADMIN
)) {
1557 rc
= qeth_l3_arp_flush_cache(card
);
1560 rc
= qeth_siocdevprivate(dev
, rq
, data
, cmd
);
1565 static int qeth_l3_get_cast_type_rcu(struct sk_buff
*skb
, struct dst_entry
*dst
,
1568 struct neighbour
*n
= NULL
;
1571 n
= dst_neigh_lookup_skb(dst
, skb
);
1574 int cast_type
= n
->type
;
1577 if ((cast_type
== RTN_BROADCAST
) ||
1578 (cast_type
== RTN_MULTICAST
) ||
1579 (cast_type
== RTN_ANYCAST
))
1584 /* no neighbour (eg AF_PACKET), fall back to target's IP address ... */
1586 case htons(ETH_P_IP
):
1587 if (ipv4_is_lbcast(ip_hdr(skb
)->daddr
))
1588 return RTN_BROADCAST
;
1589 return ipv4_is_multicast(ip_hdr(skb
)->daddr
) ?
1590 RTN_MULTICAST
: RTN_UNICAST
;
1591 case htons(ETH_P_IPV6
):
1592 return ipv6_addr_is_multicast(&ipv6_hdr(skb
)->daddr
) ?
1593 RTN_MULTICAST
: RTN_UNICAST
;
1594 case htons(ETH_P_AF_IUCV
):
1597 /* OSA only: ... and MAC address */
1598 return qeth_get_ether_cast_type(skb
);
1602 static int qeth_l3_get_cast_type(struct sk_buff
*skb
, __be16 proto
)
1604 struct dst_entry
*dst
;
1608 dst
= qeth_dst_check_rcu(skb
, proto
);
1609 cast_type
= qeth_l3_get_cast_type_rcu(skb
, dst
, proto
);
1615 static u8
qeth_l3_cast_type_to_flag(int cast_type
)
1617 if (cast_type
== RTN_MULTICAST
)
1618 return QETH_CAST_MULTICAST
;
1619 if (cast_type
== RTN_ANYCAST
)
1620 return QETH_CAST_ANYCAST
;
1621 if (cast_type
== RTN_BROADCAST
)
1622 return QETH_CAST_BROADCAST
;
1623 return QETH_CAST_UNICAST
;
1626 static void qeth_l3_fill_header(struct qeth_qdio_out_q
*queue
,
1627 struct qeth_hdr
*hdr
, struct sk_buff
*skb
,
1628 __be16 proto
, unsigned int data_len
)
1630 struct qeth_hdr_layer3
*l3_hdr
= &hdr
->hdr
.l3
;
1631 struct vlan_ethhdr
*veth
= vlan_eth_hdr(skb
);
1632 struct qeth_card
*card
= queue
->card
;
1633 struct dst_entry
*dst
;
1636 hdr
->hdr
.l3
.length
= data_len
;
1638 if (skb_is_gso(skb
)) {
1639 hdr
->hdr
.l3
.id
= QETH_HEADER_TYPE_L3_TSO
;
1641 hdr
->hdr
.l3
.id
= QETH_HEADER_TYPE_LAYER3
;
1643 if (skb
->ip_summed
== CHECKSUM_PARTIAL
) {
1644 qeth_tx_csum(skb
, &hdr
->hdr
.l3
.ext_flags
, proto
);
1645 /* some HW requires combined L3+L4 csum offload: */
1646 if (proto
== htons(ETH_P_IP
))
1647 hdr
->hdr
.l3
.ext_flags
|= QETH_HDR_EXT_CSUM_HDR_REQ
;
1651 if (proto
== htons(ETH_P_IP
) || IS_IQD(card
)) {
1652 /* NETIF_F_HW_VLAN_CTAG_TX */
1653 if (skb_vlan_tag_present(skb
)) {
1654 hdr
->hdr
.l3
.ext_flags
|= QETH_HDR_EXT_VLAN_FRAME
;
1655 hdr
->hdr
.l3
.vlan_id
= skb_vlan_tag_get(skb
);
1657 } else if (veth
->h_vlan_proto
== htons(ETH_P_8021Q
)) {
1658 hdr
->hdr
.l3
.ext_flags
|= QETH_HDR_EXT_INCLUDE_VLAN_TAG
;
1659 hdr
->hdr
.l3
.vlan_id
= ntohs(veth
->h_vlan_TCI
);
1663 dst
= qeth_dst_check_rcu(skb
, proto
);
1665 if (IS_IQD(card
) && skb_get_queue_mapping(skb
) != QETH_IQD_MCAST_TXQ
)
1666 cast_type
= RTN_UNICAST
;
1668 cast_type
= qeth_l3_get_cast_type_rcu(skb
, dst
, proto
);
1669 l3_hdr
->flags
|= qeth_l3_cast_type_to_flag(cast_type
);
1672 case htons(ETH_P_IP
):
1673 l3_hdr
->next_hop
.addr
.s6_addr32
[3] =
1674 qeth_next_hop_v4_rcu(skb
, dst
);
1676 case htons(ETH_P_IPV6
):
1677 l3_hdr
->next_hop
.addr
= *qeth_next_hop_v6_rcu(skb
, dst
);
1679 hdr
->hdr
.l3
.flags
|= QETH_HDR_IPV6
;
1681 hdr
->hdr
.l3
.flags
|= QETH_HDR_PASSTHRU
;
1683 case htons(ETH_P_AF_IUCV
):
1684 l3_hdr
->next_hop
.addr
.s6_addr16
[0] = htons(0xfe80);
1685 memcpy(&l3_hdr
->next_hop
.addr
.s6_addr32
[2],
1686 iucv_trans_hdr(skb
)->destUserID
, 8);
1687 l3_hdr
->flags
|= QETH_HDR_IPV6
;
1691 l3_hdr
->flags
|= QETH_HDR_PASSTHRU
;
1696 static void qeth_l3_fixup_headers(struct sk_buff
*skb
)
1698 struct iphdr
*iph
= ip_hdr(skb
);
1700 /* this is safe, IPv6 traffic takes a different path */
1701 if (skb
->ip_summed
== CHECKSUM_PARTIAL
)
1703 if (skb_is_gso(skb
)) {
1705 tcp_hdr(skb
)->check
= ~tcp_v4_check(0, iph
->saddr
,
1710 static int qeth_l3_xmit(struct qeth_card
*card
, struct sk_buff
*skb
,
1711 struct qeth_qdio_out_q
*queue
, __be16 proto
)
1713 unsigned int hw_hdr_len
;
1716 /* re-use the L2 header area for the HW header: */
1717 hw_hdr_len
= skb_is_gso(skb
) ? sizeof(struct qeth_hdr_tso
) :
1718 sizeof(struct qeth_hdr
);
1719 rc
= skb_cow_head(skb
, hw_hdr_len
- ETH_HLEN
);
1722 skb_pull(skb
, ETH_HLEN
);
1724 qeth_l3_fixup_headers(skb
);
1725 return qeth_xmit(card
, skb
, queue
, proto
, qeth_l3_fill_header
);
1728 static netdev_tx_t
qeth_l3_hard_start_xmit(struct sk_buff
*skb
,
1729 struct net_device
*dev
)
1731 struct qeth_card
*card
= dev
->ml_priv
;
1732 __be16 proto
= vlan_get_protocol(skb
);
1733 u16 txq
= skb_get_queue_mapping(skb
);
1734 struct qeth_qdio_out_q
*queue
;
1737 if (!skb_is_gso(skb
))
1738 qdisc_skb_cb(skb
)->pkt_len
= skb
->len
;
1740 queue
= card
->qdio
.out_qs
[qeth_iqd_translate_txq(dev
, txq
)];
1742 if (card
->options
.sniffer
)
1746 case htons(ETH_P_AF_IUCV
):
1747 if (card
->options
.cq
!= QETH_CQ_ENABLED
)
1750 case htons(ETH_P_IP
):
1751 case htons(ETH_P_IPV6
):
1752 if (card
->options
.cq
== QETH_CQ_ENABLED
)
1759 queue
= card
->qdio
.out_qs
[txq
];
1762 if (!(dev
->flags
& IFF_BROADCAST
) &&
1763 qeth_l3_get_cast_type(skb
, proto
) == RTN_BROADCAST
)
1766 if (proto
== htons(ETH_P_IP
) || IS_IQD(card
))
1767 rc
= qeth_l3_xmit(card
, skb
, queue
, proto
);
1769 rc
= qeth_xmit(card
, skb
, queue
, proto
, qeth_l3_fill_header
);
1772 return NETDEV_TX_OK
;
1775 QETH_TXQ_STAT_INC(queue
, tx_dropped
);
1777 return NETDEV_TX_OK
;
1780 static void qeth_l3_set_rx_mode(struct net_device
*dev
)
1782 struct qeth_card
*card
= dev
->ml_priv
;
1784 schedule_work(&card
->rx_mode_work
);
1788 * we need NOARP for IPv4 but we want neighbor solicitation for IPv6. Setting
1789 * NOARP on the netdevice is no option because it also turns off neighbor
1790 * solicitation. For IPv4 we install a neighbor_setup function. We don't want
1791 * arp resolution but we want the hard header (packet socket will work
1794 static int qeth_l3_neigh_setup_noarp(struct neighbour
*n
)
1796 n
->nud_state
= NUD_NOARP
;
1797 memcpy(n
->ha
, "FAKELL", 6);
1798 n
->output
= n
->ops
->connected_output
;
1803 qeth_l3_neigh_setup(struct net_device
*dev
, struct neigh_parms
*np
)
1805 if (np
->tbl
->family
== AF_INET
)
1806 np
->neigh_setup
= qeth_l3_neigh_setup_noarp
;
1811 static netdev_features_t
qeth_l3_osa_features_check(struct sk_buff
*skb
,
1812 struct net_device
*dev
,
1813 netdev_features_t features
)
1815 if (vlan_get_protocol(skb
) != htons(ETH_P_IP
))
1816 features
&= ~NETIF_F_HW_VLAN_CTAG_TX
;
1817 return qeth_features_check(skb
, dev
, features
);
1820 static u16
qeth_l3_iqd_select_queue(struct net_device
*dev
, struct sk_buff
*skb
,
1821 struct net_device
*sb_dev
)
1823 __be16 proto
= vlan_get_protocol(skb
);
1825 return qeth_iqd_select_queue(dev
, skb
,
1826 qeth_l3_get_cast_type(skb
, proto
), sb_dev
);
1829 static const struct net_device_ops qeth_l3_netdev_ops
= {
1830 .ndo_open
= qeth_open
,
1831 .ndo_stop
= qeth_stop
,
1832 .ndo_get_stats64
= qeth_get_stats64
,
1833 .ndo_start_xmit
= qeth_l3_hard_start_xmit
,
1834 .ndo_select_queue
= qeth_l3_iqd_select_queue
,
1835 .ndo_validate_addr
= eth_validate_addr
,
1836 .ndo_set_rx_mode
= qeth_l3_set_rx_mode
,
1837 .ndo_eth_ioctl
= qeth_do_ioctl
,
1838 .ndo_siocdevprivate
= qeth_l3_ndo_siocdevprivate
,
1839 .ndo_fix_features
= qeth_fix_features
,
1840 .ndo_set_features
= qeth_set_features
,
1841 .ndo_tx_timeout
= qeth_tx_timeout
,
1844 static const struct net_device_ops qeth_l3_osa_netdev_ops
= {
1845 .ndo_open
= qeth_open
,
1846 .ndo_stop
= qeth_stop
,
1847 .ndo_get_stats64
= qeth_get_stats64
,
1848 .ndo_start_xmit
= qeth_l3_hard_start_xmit
,
1849 .ndo_features_check
= qeth_l3_osa_features_check
,
1850 .ndo_select_queue
= qeth_osa_select_queue
,
1851 .ndo_validate_addr
= eth_validate_addr
,
1852 .ndo_set_rx_mode
= qeth_l3_set_rx_mode
,
1853 .ndo_eth_ioctl
= qeth_do_ioctl
,
1854 .ndo_siocdevprivate
= qeth_l3_ndo_siocdevprivate
,
1855 .ndo_fix_features
= qeth_fix_features
,
1856 .ndo_set_features
= qeth_set_features
,
1857 .ndo_tx_timeout
= qeth_tx_timeout
,
1858 .ndo_neigh_setup
= qeth_l3_neigh_setup
,
1861 static int qeth_l3_setup_netdev(struct qeth_card
*card
)
1863 struct net_device
*dev
= card
->dev
;
1864 unsigned int headroom
;
1867 if (IS_OSD(card
) || IS_OSX(card
)) {
1868 card
->dev
->netdev_ops
= &qeth_l3_osa_netdev_ops
;
1870 /*IPv6 address autoconfiguration stuff*/
1871 dev
->dev_id
= qeth_l3_get_unique_id(card
, dev
->dev_id
);
1873 if (!IS_VM_NIC(card
)) {
1874 card
->dev
->features
|= NETIF_F_SG
;
1875 card
->dev
->hw_features
|= NETIF_F_TSO
|
1876 NETIF_F_RXCSUM
| NETIF_F_IP_CSUM
;
1877 card
->dev
->vlan_features
|= NETIF_F_TSO
|
1878 NETIF_F_RXCSUM
| NETIF_F_IP_CSUM
;
1881 if (qeth_is_supported6(card
, IPA_OUTBOUND_CHECKSUM_V6
)) {
1882 card
->dev
->hw_features
|= NETIF_F_IPV6_CSUM
;
1883 card
->dev
->vlan_features
|= NETIF_F_IPV6_CSUM
;
1885 if (qeth_is_supported6(card
, IPA_OUTBOUND_TSO
)) {
1886 card
->dev
->hw_features
|= NETIF_F_TSO6
;
1887 card
->dev
->vlan_features
|= NETIF_F_TSO6
;
1890 /* allow for de-acceleration of NETIF_F_HW_VLAN_CTAG_TX: */
1891 if (card
->dev
->hw_features
& NETIF_F_TSO6
)
1892 headroom
= sizeof(struct qeth_hdr_tso
) + VLAN_HLEN
;
1893 else if (card
->dev
->hw_features
& NETIF_F_TSO
)
1894 headroom
= sizeof(struct qeth_hdr_tso
);
1896 headroom
= sizeof(struct qeth_hdr
) + VLAN_HLEN
;
1897 } else if (IS_IQD(card
)) {
1898 card
->dev
->flags
|= IFF_NOARP
;
1899 card
->dev
->netdev_ops
= &qeth_l3_netdev_ops
;
1900 headroom
= sizeof(struct qeth_hdr
) - ETH_HLEN
;
1902 rc
= qeth_l3_iqd_read_initial_mac(card
);
1908 card
->dev
->needed_headroom
= headroom
;
1909 card
->dev
->features
|= NETIF_F_HW_VLAN_CTAG_TX
|
1910 NETIF_F_HW_VLAN_CTAG_RX
;
1912 netif_keep_dst(card
->dev
);
1913 if (card
->dev
->hw_features
& (NETIF_F_TSO
| NETIF_F_TSO6
))
1914 netif_set_tso_max_size(card
->dev
,
1915 PAGE_SIZE
* (QETH_MAX_BUFFER_ELEMENTS(card
) - 1));
1917 netif_napi_add(card
->dev
, &card
->napi
, qeth_poll
);
1918 return register_netdev(card
->dev
);
1921 static const struct device_type qeth_l3_devtype
= {
1922 .name
= "qeth_layer3",
1923 .groups
= qeth_l3_attr_groups
,
1926 static int qeth_l3_probe_device(struct ccwgroup_device
*gdev
)
1928 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
1931 hash_init(card
->ip_htable
);
1932 mutex_init(&card
->ip_lock
);
1933 card
->cmd_wq
= alloc_ordered_workqueue("%s_cmd", 0,
1934 dev_name(&gdev
->dev
));
1938 if (gdev
->dev
.type
) {
1939 rc
= device_add_groups(&gdev
->dev
, qeth_l3_attr_groups
);
1941 destroy_workqueue(card
->cmd_wq
);
1945 gdev
->dev
.type
= &qeth_l3_devtype
;
1948 INIT_WORK(&card
->rx_mode_work
, qeth_l3_rx_mode_work
);
1952 static void qeth_l3_remove_device(struct ccwgroup_device
*cgdev
)
1954 struct qeth_card
*card
= dev_get_drvdata(&cgdev
->dev
);
1956 if (cgdev
->dev
.type
!= &qeth_l3_devtype
)
1957 device_remove_groups(&cgdev
->dev
, qeth_l3_attr_groups
);
1959 qeth_set_allowed_threads(card
, 0, 1);
1960 wait_event(card
->wait_q
, qeth_threads_running(card
, 0xffffffff) == 0);
1962 if (cgdev
->state
== CCWGROUP_ONLINE
)
1963 qeth_set_offline(card
, card
->discipline
, false);
1965 if (card
->dev
->reg_state
== NETREG_REGISTERED
)
1966 unregister_netdev(card
->dev
);
1968 destroy_workqueue(card
->cmd_wq
);
1969 qeth_l3_clear_ip_htable(card
, 0);
1970 qeth_l3_clear_ipato_list(card
);
1973 static int qeth_l3_set_online(struct qeth_card
*card
, bool carrier_ok
)
1975 struct net_device
*dev
= card
->dev
;
1979 QETH_CARD_TEXT(card
, 2, "softsetp");
1981 rc
= qeth_l3_setadapter_parms(card
);
1983 QETH_CARD_TEXT_(card
, 2, "2err%04x", rc
);
1984 if (!card
->options
.sniffer
) {
1985 qeth_l3_start_ipassists(card
);
1987 rc
= qeth_l3_setrouting_v4(card
);
1989 QETH_CARD_TEXT_(card
, 2, "4err%04x", rc
);
1990 rc
= qeth_l3_setrouting_v6(card
);
1992 QETH_CARD_TEXT_(card
, 2, "5err%04x", rc
);
1995 card
->state
= CARD_STATE_SOFTSETUP
;
1997 qeth_set_allowed_threads(card
, 0xffffffff, 0);
1998 qeth_l3_recover_ip(card
);
2000 if (dev
->reg_state
!= NETREG_REGISTERED
) {
2001 rc
= qeth_l3_setup_netdev(card
);
2006 netif_carrier_on(dev
);
2009 rc
= qeth_set_real_num_tx_queues(card
,
2010 qeth_tx_actual_queues(card
));
2013 goto err_set_queues
;
2017 netif_carrier_on(dev
);
2019 netif_carrier_off(dev
);
2021 netif_device_attach(dev
);
2022 qeth_enable_hw_features(dev
);
2024 if (netif_running(dev
)) {
2026 napi_schedule(&card
->napi
);
2027 /* kick-start the NAPI softirq: */
2036 qeth_set_allowed_threads(card
, 0, 1);
2037 card
->state
= CARD_STATE_DOWN
;
2038 qeth_l3_clear_ip_htable(card
, 1);
2042 static void qeth_l3_set_offline(struct qeth_card
*card
)
2044 qeth_set_allowed_threads(card
, 0, 1);
2045 qeth_l3_drain_rx_mode_cache(card
);
2047 if (card
->options
.sniffer
&&
2048 (card
->info
.promisc_mode
== SET_PROMISC_MODE_ON
))
2049 qeth_diags_trace(card
, QETH_DIAGS_CMD_TRACE_DISABLE
);
2051 if (card
->state
== CARD_STATE_SOFTSETUP
) {
2052 card
->state
= CARD_STATE_DOWN
;
2053 qeth_l3_clear_ip_htable(card
, 1);
2057 /* Returns zero if the command is successfully "consumed" */
2058 static int qeth_l3_control_event(struct qeth_card
*card
,
2059 struct qeth_ipa_cmd
*cmd
)
2064 const struct qeth_discipline qeth_l3_discipline
= {
2065 .setup
= qeth_l3_probe_device
,
2066 .remove
= qeth_l3_remove_device
,
2067 .set_online
= qeth_l3_set_online
,
2068 .set_offline
= qeth_l3_set_offline
,
2069 .control_event_handler
= qeth_l3_control_event
,
2071 EXPORT_SYMBOL_GPL(qeth_l3_discipline
);
2073 static int qeth_l3_handle_ip_event(struct qeth_card
*card
,
2074 struct qeth_ipaddr
*addr
,
2075 unsigned long event
)
2079 qeth_l3_modify_ip(card
, addr
, true);
2082 qeth_l3_modify_ip(card
, addr
, false);
2089 struct qeth_l3_ip_event_work
{
2090 struct work_struct work
;
2091 struct qeth_card
*card
;
2092 struct qeth_ipaddr addr
;
2095 #define to_ip_work(w) container_of((w), struct qeth_l3_ip_event_work, work)
2097 static void qeth_l3_add_ip_worker(struct work_struct
*work
)
2099 struct qeth_l3_ip_event_work
*ip_work
= to_ip_work(work
);
2101 qeth_l3_modify_ip(ip_work
->card
, &ip_work
->addr
, true);
2105 static void qeth_l3_delete_ip_worker(struct work_struct
*work
)
2107 struct qeth_l3_ip_event_work
*ip_work
= to_ip_work(work
);
2109 qeth_l3_modify_ip(ip_work
->card
, &ip_work
->addr
, false);
2113 static struct qeth_card
*qeth_l3_get_card_from_dev(struct net_device
*dev
)
2115 if (is_vlan_dev(dev
))
2116 dev
= vlan_dev_real_dev(dev
);
2117 if (dev
->netdev_ops
== &qeth_l3_osa_netdev_ops
||
2118 dev
->netdev_ops
== &qeth_l3_netdev_ops
)
2119 return (struct qeth_card
*) dev
->ml_priv
;
2123 static int qeth_l3_ip_event(struct notifier_block
*this,
2124 unsigned long event
, void *ptr
)
2126 struct in_ifaddr
*ifa
= (struct in_ifaddr
*)ptr
;
2127 struct net_device
*dev
= ifa
->ifa_dev
->dev
;
2128 struct qeth_ipaddr addr
;
2129 struct qeth_card
*card
;
2131 card
= qeth_l3_get_card_from_dev(dev
);
2134 QETH_CARD_TEXT(card
, 3, "ipevent");
2136 qeth_l3_init_ipaddr(&addr
, QETH_IP_TYPE_NORMAL
, QETH_PROT_IPV4
);
2137 addr
.u
.a4
.addr
= ifa
->ifa_address
;
2138 addr
.u
.a4
.mask
= ifa
->ifa_mask
;
2140 return qeth_l3_handle_ip_event(card
, &addr
, event
);
2143 static struct notifier_block qeth_l3_ip_notifier
= {
2148 static int qeth_l3_ip6_event(struct notifier_block
*this,
2149 unsigned long event
, void *ptr
)
2151 struct inet6_ifaddr
*ifa
= (struct inet6_ifaddr
*)ptr
;
2152 struct net_device
*dev
= ifa
->idev
->dev
;
2153 struct qeth_l3_ip_event_work
*ip_work
;
2154 struct qeth_card
*card
;
2156 if (event
!= NETDEV_UP
&& event
!= NETDEV_DOWN
)
2159 card
= qeth_l3_get_card_from_dev(dev
);
2162 QETH_CARD_TEXT(card
, 3, "ip6event");
2163 if (!qeth_is_supported(card
, IPA_IPV6
))
2166 ip_work
= kmalloc(sizeof(*ip_work
), GFP_ATOMIC
);
2170 if (event
== NETDEV_UP
)
2171 INIT_WORK(&ip_work
->work
, qeth_l3_add_ip_worker
);
2173 INIT_WORK(&ip_work
->work
, qeth_l3_delete_ip_worker
);
2175 ip_work
->card
= card
;
2176 qeth_l3_init_ipaddr(&ip_work
->addr
, QETH_IP_TYPE_NORMAL
,
2178 ip_work
->addr
.u
.a6
.addr
= ifa
->addr
;
2179 ip_work
->addr
.u
.a6
.pfxlen
= ifa
->prefix_len
;
2181 queue_work(card
->cmd_wq
, &ip_work
->work
);
2185 static struct notifier_block qeth_l3_ip6_notifier
= {
2190 static int qeth_l3_register_notifiers(void)
2194 QETH_DBF_TEXT(SETUP
, 5, "regnotif");
2195 rc
= register_inetaddr_notifier(&qeth_l3_ip_notifier
);
2198 rc
= register_inet6addr_notifier(&qeth_l3_ip6_notifier
);
2200 unregister_inetaddr_notifier(&qeth_l3_ip_notifier
);
2206 static void qeth_l3_unregister_notifiers(void)
2208 QETH_DBF_TEXT(SETUP
, 5, "unregnot");
2209 WARN_ON(unregister_inetaddr_notifier(&qeth_l3_ip_notifier
));
2210 WARN_ON(unregister_inet6addr_notifier(&qeth_l3_ip6_notifier
));
2213 static int __init
qeth_l3_init(void)
2215 pr_info("register layer 3 discipline\n");
2216 return qeth_l3_register_notifiers();
2219 static void __exit
qeth_l3_exit(void)
2221 qeth_l3_unregister_notifiers();
2222 pr_info("unregister layer 3 discipline\n");
2225 module_init(qeth_l3_init
);
2226 module_exit(qeth_l3_exit
);
2227 MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
2228 MODULE_DESCRIPTION("qeth layer 3 discipline");
2229 MODULE_LICENSE("GPL");