2 * Copyright IBM Corp. 2007, 2009
3 * Author(s): Utz Bacher <utz.bacher@de.ibm.com>,
4 * Frank Pavlic <fpavlic@de.ibm.com>,
5 * Thomas Spatzier <tspat@de.ibm.com>,
6 * Frank Blaschka <frank.blaschka@de.ibm.com>
9 #define KMSG_COMPONENT "qeth"
10 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
12 #include <linux/module.h>
13 #include <linux/moduleparam.h>
14 #include <linux/bitops.h>
15 #include <linux/string.h>
16 #include <linux/errno.h>
17 #include <linux/kernel.h>
18 #include <linux/etherdevice.h>
19 #include <linux/mii.h>
21 #include <linux/ipv6.h>
22 #include <linux/inetdevice.h>
23 #include <linux/igmp.h>
24 #include <linux/slab.h>
25 #include <linux/if_vlan.h>
29 #include <net/route.h>
30 #include <net/ip6_fib.h>
31 #include <net/ip6_checksum.h>
32 #include <net/iucv/af_iucv.h>
37 static int qeth_l3_set_offline(struct ccwgroup_device
*);
38 static int qeth_l3_recover(void *);
39 static int qeth_l3_stop(struct net_device
*);
40 static void qeth_l3_set_multicast_list(struct net_device
*);
41 static int qeth_l3_neigh_setup(struct net_device
*, struct neigh_parms
*);
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
*);
46 static int __qeth_l3_set_online(struct ccwgroup_device
*, int);
47 static int __qeth_l3_set_offline(struct ccwgroup_device
*, int);
49 static int qeth_l3_isxdigit(char *buf
)
52 if (!isxdigit(*buf
++))
58 void qeth_l3_ipaddr4_to_string(const __u8
*addr
, char *buf
)
60 sprintf(buf
, "%i.%i.%i.%i", addr
[0], addr
[1], addr
[2], addr
[3]);
63 int qeth_l3_string_to_ipaddr4(const char *buf
, __u8
*addr
)
65 int count
= 0, rc
= 0;
69 rc
= sscanf(buf
, "%u.%u.%u.%u%c",
70 &in
[0], &in
[1], &in
[2], &in
[3], &c
);
71 if (rc
!= 4 && (rc
!= 5 || c
!= '\n'))
73 for (count
= 0; count
< 4; count
++) {
76 addr
[count
] = in
[count
];
81 void qeth_l3_ipaddr6_to_string(const __u8
*addr
, char *buf
)
83 sprintf(buf
, "%pI6", addr
);
86 int qeth_l3_string_to_ipaddr6(const char *buf
, __u8
*addr
)
88 const char *end
, *end_tmp
, *start
;
91 int num2
, cnt
, out
, found
, save_cnt
;
92 unsigned short in_tmp
[8] = {0, };
94 cnt
= out
= found
= save_cnt
= num2
= 0;
99 end
= strchr(start
, ':');
101 end
= buf
+ strlen(buf
);
102 end_tmp
= strchr(start
, '\n');
109 if ((end
- start
) > 4)
111 memcpy(num
, start
, end
- start
);
112 if (!qeth_l3_isxdigit(num
))
114 sscanf(start
, "%x", &num2
);
116 in_tmp
[save_cnt
++] = num2
;
128 if (cnt
+ save_cnt
> 8)
132 in
[cnt
--] = in_tmp
[--save_cnt
];
136 void qeth_l3_ipaddr_to_string(enum qeth_prot_versions proto
, const __u8
*addr
,
139 if (proto
== QETH_PROT_IPV4
)
140 qeth_l3_ipaddr4_to_string(addr
, buf
);
141 else if (proto
== QETH_PROT_IPV6
)
142 qeth_l3_ipaddr6_to_string(addr
, buf
);
145 int qeth_l3_string_to_ipaddr(const char *buf
, enum qeth_prot_versions proto
,
148 if (proto
== QETH_PROT_IPV4
)
149 return qeth_l3_string_to_ipaddr4(buf
, addr
);
150 else if (proto
== QETH_PROT_IPV6
)
151 return qeth_l3_string_to_ipaddr6(buf
, addr
);
156 static void qeth_l3_convert_addr_to_bits(u8
*addr
, u8
*bits
, int len
)
161 for (i
= 0; i
< len
; ++i
) {
163 for (j
= 7; j
>= 0; --j
) {
164 bits
[i
*8 + j
] = octet
& 1;
170 int qeth_l3_is_addr_covered_by_ipato(struct qeth_card
*card
,
171 struct qeth_ipaddr
*addr
)
173 struct qeth_ipato_entry
*ipatoe
;
174 u8 addr_bits
[128] = {0, };
175 u8 ipatoe_bits
[128] = {0, };
178 if (!card
->ipato
.enabled
)
181 qeth_l3_convert_addr_to_bits((u8
*) &addr
->u
, addr_bits
,
182 (addr
->proto
== QETH_PROT_IPV4
)? 4:16);
183 list_for_each_entry(ipatoe
, &card
->ipato
.entries
, entry
) {
184 if (addr
->proto
!= ipatoe
->proto
)
186 qeth_l3_convert_addr_to_bits(ipatoe
->addr
, ipatoe_bits
,
187 (ipatoe
->proto
== QETH_PROT_IPV4
) ?
189 if (addr
->proto
== QETH_PROT_IPV4
)
190 rc
= !memcmp(addr_bits
, ipatoe_bits
,
191 min(32, ipatoe
->mask_bits
));
193 rc
= !memcmp(addr_bits
, ipatoe_bits
,
194 min(128, ipatoe
->mask_bits
));
199 if ((addr
->proto
== QETH_PROT_IPV4
) && card
->ipato
.invert4
)
201 else if ((addr
->proto
== QETH_PROT_IPV6
) && card
->ipato
.invert6
)
208 * Add IP to be added to todo list. If there is already an "add todo"
209 * in this list we just incremenent the reference count.
210 * Returns 0 if we just incremented reference count.
212 static int __qeth_l3_insert_ip_todo(struct qeth_card
*card
,
213 struct qeth_ipaddr
*addr
, int add
)
215 struct qeth_ipaddr
*tmp
, *t
;
218 if (card
->options
.sniffer
)
220 list_for_each_entry_safe(tmp
, t
, card
->ip_tbd_list
, entry
) {
221 if ((addr
->type
== QETH_IP_TYPE_DEL_ALL_MC
) &&
222 (tmp
->type
== QETH_IP_TYPE_DEL_ALL_MC
))
224 if ((tmp
->proto
== QETH_PROT_IPV4
) &&
225 (addr
->proto
== QETH_PROT_IPV4
) &&
226 (tmp
->type
== addr
->type
) &&
227 (tmp
->is_multicast
== addr
->is_multicast
) &&
228 (tmp
->u
.a4
.addr
== addr
->u
.a4
.addr
) &&
229 (tmp
->u
.a4
.mask
== addr
->u
.a4
.mask
)) {
233 if ((tmp
->proto
== QETH_PROT_IPV6
) &&
234 (addr
->proto
== QETH_PROT_IPV6
) &&
235 (tmp
->type
== addr
->type
) &&
236 (tmp
->is_multicast
== addr
->is_multicast
) &&
237 (tmp
->u
.a6
.pfxlen
== addr
->u
.a6
.pfxlen
) &&
238 (memcmp(&tmp
->u
.a6
.addr
, &addr
->u
.a6
.addr
,
239 sizeof(struct in6_addr
)) == 0)) {
245 if (addr
->users
!= 0)
246 tmp
->users
+= addr
->users
;
248 tmp
->users
+= add
? 1 : -1;
249 if (tmp
->users
== 0) {
250 list_del(&tmp
->entry
);
255 if (addr
->type
== QETH_IP_TYPE_DEL_ALL_MC
)
256 list_add(&addr
->entry
, card
->ip_tbd_list
);
258 if (addr
->users
== 0)
259 addr
->users
+= add
? 1 : -1;
260 if (add
&& (addr
->type
== QETH_IP_TYPE_NORMAL
) &&
261 qeth_l3_is_addr_covered_by_ipato(card
, addr
)) {
262 QETH_CARD_TEXT(card
, 2, "tkovaddr");
263 addr
->set_flags
|= QETH_IPA_SETIP_TAKEOVER_FLAG
;
265 list_add_tail(&addr
->entry
, card
->ip_tbd_list
);
271 int qeth_l3_delete_ip(struct qeth_card
*card
, struct qeth_ipaddr
*addr
)
276 QETH_CARD_TEXT(card
, 4, "delip");
278 if (addr
->proto
== QETH_PROT_IPV4
)
279 QETH_CARD_HEX(card
, 4, &addr
->u
.a4
.addr
, 4);
281 QETH_CARD_HEX(card
, 4, &addr
->u
.a6
.addr
, 8);
282 QETH_CARD_HEX(card
, 4, ((char *)&addr
->u
.a6
.addr
) + 8, 8);
284 spin_lock_irqsave(&card
->ip_lock
, flags
);
285 rc
= __qeth_l3_insert_ip_todo(card
, addr
, 0);
286 spin_unlock_irqrestore(&card
->ip_lock
, flags
);
290 int qeth_l3_add_ip(struct qeth_card
*card
, struct qeth_ipaddr
*addr
)
295 QETH_CARD_TEXT(card
, 4, "addip");
296 if (addr
->proto
== QETH_PROT_IPV4
)
297 QETH_CARD_HEX(card
, 4, &addr
->u
.a4
.addr
, 4);
299 QETH_CARD_HEX(card
, 4, &addr
->u
.a6
.addr
, 8);
300 QETH_CARD_HEX(card
, 4, ((char *)&addr
->u
.a6
.addr
) + 8, 8);
302 spin_lock_irqsave(&card
->ip_lock
, flags
);
303 rc
= __qeth_l3_insert_ip_todo(card
, addr
, 1);
304 spin_unlock_irqrestore(&card
->ip_lock
, flags
);
309 struct qeth_ipaddr
*qeth_l3_get_addr_buffer(
310 enum qeth_prot_versions prot
)
312 struct qeth_ipaddr
*addr
;
314 addr
= kzalloc(sizeof(struct qeth_ipaddr
), GFP_ATOMIC
);
318 addr
->type
= QETH_IP_TYPE_NORMAL
;
323 static void qeth_l3_delete_mc_addresses(struct qeth_card
*card
)
325 struct qeth_ipaddr
*iptodo
;
328 QETH_CARD_TEXT(card
, 4, "delmc");
329 iptodo
= qeth_l3_get_addr_buffer(QETH_PROT_IPV4
);
331 QETH_CARD_TEXT(card
, 2, "dmcnomem");
334 iptodo
->type
= QETH_IP_TYPE_DEL_ALL_MC
;
335 spin_lock_irqsave(&card
->ip_lock
, flags
);
336 if (!__qeth_l3_insert_ip_todo(card
, iptodo
, 0))
338 spin_unlock_irqrestore(&card
->ip_lock
, flags
);
342 * Add/remove address to/from card's ip list, i.e. try to add or remove
343 * reference to/from an IP address that is already registered on the card.
345 * 0 address was on card and its reference count has been adjusted,
346 * but is still > 0, so nothing has to be done
347 * also returns 0 if card was not on card and the todo was to delete
348 * the address -> there is also nothing to be done
349 * 1 address was not on card and the todo is to add it to the card's ip
351 * -1 address was on card and its reference count has been decremented
352 * to <= 0 by the todo -> address must be removed from card
354 static int __qeth_l3_ref_ip_on_card(struct qeth_card
*card
,
355 struct qeth_ipaddr
*todo
, struct qeth_ipaddr
**__addr
)
357 struct qeth_ipaddr
*addr
;
360 list_for_each_entry(addr
, &card
->ip_list
, entry
) {
361 if ((addr
->proto
== QETH_PROT_IPV4
) &&
362 (todo
->proto
== QETH_PROT_IPV4
) &&
363 (addr
->type
== todo
->type
) &&
364 (addr
->u
.a4
.addr
== todo
->u
.a4
.addr
) &&
365 (addr
->u
.a4
.mask
== todo
->u
.a4
.mask
)) {
369 if ((addr
->proto
== QETH_PROT_IPV6
) &&
370 (todo
->proto
== QETH_PROT_IPV6
) &&
371 (addr
->type
== todo
->type
) &&
372 (addr
->u
.a6
.pfxlen
== todo
->u
.a6
.pfxlen
) &&
373 (memcmp(&addr
->u
.a6
.addr
, &todo
->u
.a6
.addr
,
374 sizeof(struct in6_addr
)) == 0)) {
380 addr
->users
+= todo
->users
;
381 if (addr
->users
<= 0) {
385 /* for VIPA and RXIP limit refcount to 1 */
386 if (addr
->type
!= QETH_IP_TYPE_NORMAL
)
391 if (todo
->users
> 0) {
392 /* for VIPA and RXIP limit refcount to 1 */
393 if (todo
->type
!= QETH_IP_TYPE_NORMAL
)
400 static void __qeth_l3_delete_all_mc(struct qeth_card
*card
,
401 unsigned long *flags
)
403 struct list_head fail_list
;
404 struct qeth_ipaddr
*addr
, *tmp
;
407 INIT_LIST_HEAD(&fail_list
);
409 list_for_each_entry_safe(addr
, tmp
, &card
->ip_list
, entry
) {
410 if (addr
->is_multicast
) {
411 list_del(&addr
->entry
);
412 spin_unlock_irqrestore(&card
->ip_lock
, *flags
);
413 rc
= qeth_l3_deregister_addr_entry(card
, addr
);
414 spin_lock_irqsave(&card
->ip_lock
, *flags
);
415 if (!rc
|| (rc
== IPA_RC_MC_ADDR_NOT_FOUND
))
418 list_add_tail(&addr
->entry
, &fail_list
);
422 list_splice(&fail_list
, &card
->ip_list
);
425 void qeth_l3_set_ip_addr_list(struct qeth_card
*card
)
427 struct list_head
*tbd_list
;
428 struct qeth_ipaddr
*todo
, *addr
;
432 QETH_CARD_TEXT(card
, 2, "sdiplist");
433 QETH_CARD_HEX(card
, 2, &card
, sizeof(void *));
435 if ((card
->state
!= CARD_STATE_UP
&&
436 card
->state
!= CARD_STATE_SOFTSETUP
) || card
->options
.sniffer
) {
440 spin_lock_irqsave(&card
->ip_lock
, flags
);
441 tbd_list
= card
->ip_tbd_list
;
442 card
->ip_tbd_list
= kzalloc(sizeof(struct list_head
), GFP_ATOMIC
);
443 if (!card
->ip_tbd_list
) {
444 QETH_CARD_TEXT(card
, 0, "silnomem");
445 card
->ip_tbd_list
= tbd_list
;
446 spin_unlock_irqrestore(&card
->ip_lock
, flags
);
449 INIT_LIST_HEAD(card
->ip_tbd_list
);
451 while (!list_empty(tbd_list
)) {
452 todo
= list_entry(tbd_list
->next
, struct qeth_ipaddr
, entry
);
453 list_del(&todo
->entry
);
454 if (todo
->type
== QETH_IP_TYPE_DEL_ALL_MC
) {
455 __qeth_l3_delete_all_mc(card
, &flags
);
459 rc
= __qeth_l3_ref_ip_on_card(card
, todo
, &addr
);
461 /* nothing to be done; only adjusted refcount */
463 } else if (rc
== 1) {
464 /* new entry to be added to on-card list */
465 spin_unlock_irqrestore(&card
->ip_lock
, flags
);
466 rc
= qeth_l3_register_addr_entry(card
, todo
);
467 spin_lock_irqsave(&card
->ip_lock
, flags
);
468 if (!rc
|| (rc
== IPA_RC_LAN_OFFLINE
))
469 list_add_tail(&todo
->entry
, &card
->ip_list
);
472 } else if (rc
== -1) {
473 /* on-card entry to be removed */
474 list_del_init(&addr
->entry
);
475 spin_unlock_irqrestore(&card
->ip_lock
, flags
);
476 rc
= qeth_l3_deregister_addr_entry(card
, addr
);
477 spin_lock_irqsave(&card
->ip_lock
, flags
);
478 if (!rc
|| (rc
== IPA_RC_IP_ADDRESS_NOT_DEFINED
))
481 list_add_tail(&addr
->entry
, &card
->ip_list
);
485 spin_unlock_irqrestore(&card
->ip_lock
, flags
);
489 static void qeth_l3_clear_ip_list(struct qeth_card
*card
, int recover
)
491 struct qeth_ipaddr
*addr
, *tmp
;
494 QETH_CARD_TEXT(card
, 4, "clearip");
495 if (recover
&& card
->options
.sniffer
)
497 spin_lock_irqsave(&card
->ip_lock
, flags
);
498 /* clear todo list */
499 list_for_each_entry_safe(addr
, tmp
, card
->ip_tbd_list
, entry
) {
500 list_del(&addr
->entry
);
504 while (!list_empty(&card
->ip_list
)) {
505 addr
= list_entry(card
->ip_list
.next
,
506 struct qeth_ipaddr
, entry
);
507 list_del_init(&addr
->entry
);
508 if (!recover
|| addr
->is_multicast
) {
512 list_add_tail(&addr
->entry
, card
->ip_tbd_list
);
514 spin_unlock_irqrestore(&card
->ip_lock
, flags
);
517 static int qeth_l3_address_exists_in_list(struct list_head
*list
,
518 struct qeth_ipaddr
*addr
, int same_type
)
520 struct qeth_ipaddr
*tmp
;
522 list_for_each_entry(tmp
, list
, entry
) {
523 if ((tmp
->proto
== QETH_PROT_IPV4
) &&
524 (addr
->proto
== QETH_PROT_IPV4
) &&
525 ((same_type
&& (tmp
->type
== addr
->type
)) ||
526 (!same_type
&& (tmp
->type
!= addr
->type
))) &&
527 (tmp
->u
.a4
.addr
== addr
->u
.a4
.addr
))
530 if ((tmp
->proto
== QETH_PROT_IPV6
) &&
531 (addr
->proto
== QETH_PROT_IPV6
) &&
532 ((same_type
&& (tmp
->type
== addr
->type
)) ||
533 (!same_type
&& (tmp
->type
!= addr
->type
))) &&
534 (memcmp(&tmp
->u
.a6
.addr
, &addr
->u
.a6
.addr
,
535 sizeof(struct in6_addr
)) == 0))
542 static int qeth_l3_send_setdelmc(struct qeth_card
*card
,
543 struct qeth_ipaddr
*addr
, int ipacmd
)
546 struct qeth_cmd_buffer
*iob
;
547 struct qeth_ipa_cmd
*cmd
;
549 QETH_CARD_TEXT(card
, 4, "setdelmc");
551 iob
= qeth_get_ipacmd_buffer(card
, ipacmd
, addr
->proto
);
552 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
553 memcpy(&cmd
->data
.setdelipm
.mac
, addr
->mac
, OSA_ADDR_LEN
);
554 if (addr
->proto
== QETH_PROT_IPV6
)
555 memcpy(cmd
->data
.setdelipm
.ip6
, &addr
->u
.a6
.addr
,
556 sizeof(struct in6_addr
));
558 memcpy(&cmd
->data
.setdelipm
.ip4
, &addr
->u
.a4
.addr
, 4);
560 rc
= qeth_send_ipa_cmd(card
, iob
, NULL
, NULL
);
565 static void qeth_l3_fill_netmask(u8
*netmask
, unsigned int len
)
568 for (i
= 0; i
< 16; i
++) {
573 netmask
[i
] = (u8
)(0xFF00 >> j
);
579 static int qeth_l3_send_setdelip(struct qeth_card
*card
,
580 struct qeth_ipaddr
*addr
, int ipacmd
, unsigned int flags
)
583 struct qeth_cmd_buffer
*iob
;
584 struct qeth_ipa_cmd
*cmd
;
587 QETH_CARD_TEXT(card
, 4, "setdelip");
588 QETH_CARD_TEXT_(card
, 4, "flags%02X", flags
);
590 iob
= qeth_get_ipacmd_buffer(card
, ipacmd
, addr
->proto
);
591 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
592 if (addr
->proto
== QETH_PROT_IPV6
) {
593 memcpy(cmd
->data
.setdelip6
.ip_addr
, &addr
->u
.a6
.addr
,
594 sizeof(struct in6_addr
));
595 qeth_l3_fill_netmask(netmask
, addr
->u
.a6
.pfxlen
);
596 memcpy(cmd
->data
.setdelip6
.mask
, netmask
,
597 sizeof(struct in6_addr
));
598 cmd
->data
.setdelip6
.flags
= flags
;
600 memcpy(cmd
->data
.setdelip4
.ip_addr
, &addr
->u
.a4
.addr
, 4);
601 memcpy(cmd
->data
.setdelip4
.mask
, &addr
->u
.a4
.mask
, 4);
602 cmd
->data
.setdelip4
.flags
= flags
;
605 rc
= qeth_send_ipa_cmd(card
, iob
, NULL
, NULL
);
610 static int qeth_l3_send_setrouting(struct qeth_card
*card
,
611 enum qeth_routing_types type
, enum qeth_prot_versions prot
)
614 struct qeth_ipa_cmd
*cmd
;
615 struct qeth_cmd_buffer
*iob
;
617 QETH_CARD_TEXT(card
, 4, "setroutg");
618 iob
= qeth_get_ipacmd_buffer(card
, IPA_CMD_SETRTG
, prot
);
619 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
620 cmd
->data
.setrtg
.type
= (type
);
621 rc
= qeth_send_ipa_cmd(card
, iob
, NULL
, NULL
);
626 static int qeth_l3_correct_routing_type(struct qeth_card
*card
,
627 enum qeth_routing_types
*type
, enum qeth_prot_versions prot
)
629 if (card
->info
.type
== QETH_CARD_TYPE_IQD
) {
632 case PRIMARY_CONNECTOR
:
633 case SECONDARY_CONNECTOR
:
634 case MULTICAST_ROUTER
:
643 case SECONDARY_ROUTER
:
645 case MULTICAST_ROUTER
:
646 if (qeth_is_ipafunc_supported(card
, prot
,
658 int qeth_l3_setrouting_v4(struct qeth_card
*card
)
662 QETH_CARD_TEXT(card
, 3, "setrtg4");
664 rc
= qeth_l3_correct_routing_type(card
, &card
->options
.route4
.type
,
669 rc
= qeth_l3_send_setrouting(card
, card
->options
.route4
.type
,
672 card
->options
.route4
.type
= NO_ROUTER
;
673 QETH_DBF_MESSAGE(2, "Error (0x%04x) while setting routing type"
674 " on %s. Type set to 'no router'.\n", rc
,
675 QETH_CARD_IFNAME(card
));
680 int qeth_l3_setrouting_v6(struct qeth_card
*card
)
684 QETH_CARD_TEXT(card
, 3, "setrtg6");
685 #ifdef CONFIG_QETH_IPV6
687 if (!qeth_is_supported(card
, IPA_IPV6
))
689 rc
= qeth_l3_correct_routing_type(card
, &card
->options
.route6
.type
,
694 rc
= qeth_l3_send_setrouting(card
, card
->options
.route6
.type
,
697 card
->options
.route6
.type
= NO_ROUTER
;
698 QETH_DBF_MESSAGE(2, "Error (0x%04x) while setting routing type"
699 " on %s. Type set to 'no router'.\n", rc
,
700 QETH_CARD_IFNAME(card
));
707 * IP address takeover related functions
709 static void qeth_l3_clear_ipato_list(struct qeth_card
*card
)
712 struct qeth_ipato_entry
*ipatoe
, *tmp
;
715 spin_lock_irqsave(&card
->ip_lock
, flags
);
716 list_for_each_entry_safe(ipatoe
, tmp
, &card
->ipato
.entries
, entry
) {
717 list_del(&ipatoe
->entry
);
720 spin_unlock_irqrestore(&card
->ip_lock
, flags
);
723 int qeth_l3_add_ipato_entry(struct qeth_card
*card
,
724 struct qeth_ipato_entry
*new)
726 struct qeth_ipato_entry
*ipatoe
;
730 QETH_CARD_TEXT(card
, 2, "addipato");
731 spin_lock_irqsave(&card
->ip_lock
, flags
);
732 list_for_each_entry(ipatoe
, &card
->ipato
.entries
, entry
) {
733 if (ipatoe
->proto
!= new->proto
)
735 if (!memcmp(ipatoe
->addr
, new->addr
,
736 (ipatoe
->proto
== QETH_PROT_IPV4
)? 4:16) &&
737 (ipatoe
->mask_bits
== new->mask_bits
)) {
743 list_add_tail(&new->entry
, &card
->ipato
.entries
);
745 spin_unlock_irqrestore(&card
->ip_lock
, flags
);
749 void qeth_l3_del_ipato_entry(struct qeth_card
*card
,
750 enum qeth_prot_versions proto
, u8
*addr
, int mask_bits
)
752 struct qeth_ipato_entry
*ipatoe
, *tmp
;
755 QETH_CARD_TEXT(card
, 2, "delipato");
756 spin_lock_irqsave(&card
->ip_lock
, flags
);
757 list_for_each_entry_safe(ipatoe
, tmp
, &card
->ipato
.entries
, entry
) {
758 if (ipatoe
->proto
!= proto
)
760 if (!memcmp(ipatoe
->addr
, addr
,
761 (proto
== QETH_PROT_IPV4
)? 4:16) &&
762 (ipatoe
->mask_bits
== mask_bits
)) {
763 list_del(&ipatoe
->entry
);
767 spin_unlock_irqrestore(&card
->ip_lock
, flags
);
771 * VIPA related functions
773 int qeth_l3_add_vipa(struct qeth_card
*card
, enum qeth_prot_versions proto
,
776 struct qeth_ipaddr
*ipaddr
;
780 ipaddr
= qeth_l3_get_addr_buffer(proto
);
782 if (proto
== QETH_PROT_IPV4
) {
783 QETH_CARD_TEXT(card
, 2, "addvipa4");
784 memcpy(&ipaddr
->u
.a4
.addr
, addr
, 4);
785 ipaddr
->u
.a4
.mask
= 0;
786 } else if (proto
== QETH_PROT_IPV6
) {
787 QETH_CARD_TEXT(card
, 2, "addvipa6");
788 memcpy(&ipaddr
->u
.a6
.addr
, addr
, 16);
789 ipaddr
->u
.a6
.pfxlen
= 0;
791 ipaddr
->type
= QETH_IP_TYPE_VIPA
;
792 ipaddr
->set_flags
= QETH_IPA_SETIP_VIPA_FLAG
;
793 ipaddr
->del_flags
= QETH_IPA_DELIP_VIPA_FLAG
;
796 spin_lock_irqsave(&card
->ip_lock
, flags
);
797 if (qeth_l3_address_exists_in_list(&card
->ip_list
, ipaddr
, 0) ||
798 qeth_l3_address_exists_in_list(card
->ip_tbd_list
, ipaddr
, 0))
800 spin_unlock_irqrestore(&card
->ip_lock
, flags
);
805 if (!qeth_l3_add_ip(card
, ipaddr
))
807 qeth_l3_set_ip_addr_list(card
);
811 void qeth_l3_del_vipa(struct qeth_card
*card
, enum qeth_prot_versions proto
,
814 struct qeth_ipaddr
*ipaddr
;
816 ipaddr
= qeth_l3_get_addr_buffer(proto
);
818 if (proto
== QETH_PROT_IPV4
) {
819 QETH_CARD_TEXT(card
, 2, "delvipa4");
820 memcpy(&ipaddr
->u
.a4
.addr
, addr
, 4);
821 ipaddr
->u
.a4
.mask
= 0;
822 } else if (proto
== QETH_PROT_IPV6
) {
823 QETH_CARD_TEXT(card
, 2, "delvipa6");
824 memcpy(&ipaddr
->u
.a6
.addr
, addr
, 16);
825 ipaddr
->u
.a6
.pfxlen
= 0;
827 ipaddr
->type
= QETH_IP_TYPE_VIPA
;
830 if (!qeth_l3_delete_ip(card
, ipaddr
))
832 qeth_l3_set_ip_addr_list(card
);
836 * proxy ARP related functions
838 int qeth_l3_add_rxip(struct qeth_card
*card
, enum qeth_prot_versions proto
,
841 struct qeth_ipaddr
*ipaddr
;
845 ipaddr
= qeth_l3_get_addr_buffer(proto
);
847 if (proto
== QETH_PROT_IPV4
) {
848 QETH_CARD_TEXT(card
, 2, "addrxip4");
849 memcpy(&ipaddr
->u
.a4
.addr
, addr
, 4);
850 ipaddr
->u
.a4
.mask
= 0;
851 } else if (proto
== QETH_PROT_IPV6
) {
852 QETH_CARD_TEXT(card
, 2, "addrxip6");
853 memcpy(&ipaddr
->u
.a6
.addr
, addr
, 16);
854 ipaddr
->u
.a6
.pfxlen
= 0;
856 ipaddr
->type
= QETH_IP_TYPE_RXIP
;
857 ipaddr
->set_flags
= QETH_IPA_SETIP_TAKEOVER_FLAG
;
858 ipaddr
->del_flags
= 0;
861 spin_lock_irqsave(&card
->ip_lock
, flags
);
862 if (qeth_l3_address_exists_in_list(&card
->ip_list
, ipaddr
, 0) ||
863 qeth_l3_address_exists_in_list(card
->ip_tbd_list
, ipaddr
, 0))
865 spin_unlock_irqrestore(&card
->ip_lock
, flags
);
870 if (!qeth_l3_add_ip(card
, ipaddr
))
872 qeth_l3_set_ip_addr_list(card
);
876 void qeth_l3_del_rxip(struct qeth_card
*card
, enum qeth_prot_versions proto
,
879 struct qeth_ipaddr
*ipaddr
;
881 ipaddr
= qeth_l3_get_addr_buffer(proto
);
883 if (proto
== QETH_PROT_IPV4
) {
884 QETH_CARD_TEXT(card
, 2, "addrxip4");
885 memcpy(&ipaddr
->u
.a4
.addr
, addr
, 4);
886 ipaddr
->u
.a4
.mask
= 0;
887 } else if (proto
== QETH_PROT_IPV6
) {
888 QETH_CARD_TEXT(card
, 2, "addrxip6");
889 memcpy(&ipaddr
->u
.a6
.addr
, addr
, 16);
890 ipaddr
->u
.a6
.pfxlen
= 0;
892 ipaddr
->type
= QETH_IP_TYPE_RXIP
;
895 if (!qeth_l3_delete_ip(card
, ipaddr
))
897 qeth_l3_set_ip_addr_list(card
);
900 static int qeth_l3_register_addr_entry(struct qeth_card
*card
,
901 struct qeth_ipaddr
*addr
)
907 if (addr
->proto
== QETH_PROT_IPV4
) {
908 QETH_CARD_TEXT(card
, 2, "setaddr4");
909 QETH_CARD_HEX(card
, 3, &addr
->u
.a4
.addr
, sizeof(int));
910 } else if (addr
->proto
== QETH_PROT_IPV6
) {
911 QETH_CARD_TEXT(card
, 2, "setaddr6");
912 QETH_CARD_HEX(card
, 3, &addr
->u
.a6
.addr
, 8);
913 QETH_CARD_HEX(card
, 3, ((char *)&addr
->u
.a6
.addr
) + 8, 8);
915 QETH_CARD_TEXT(card
, 2, "setaddr?");
916 QETH_CARD_HEX(card
, 3, addr
, sizeof(struct qeth_ipaddr
));
919 if (addr
->is_multicast
)
920 rc
= qeth_l3_send_setdelmc(card
, addr
, IPA_CMD_SETIPM
);
922 rc
= qeth_l3_send_setdelip(card
, addr
, IPA_CMD_SETIP
,
925 QETH_CARD_TEXT(card
, 2, "failed");
926 } while ((--cnt
> 0) && rc
);
928 QETH_CARD_TEXT(card
, 2, "FAILED");
929 qeth_l3_ipaddr_to_string(addr
->proto
, (u8
*)&addr
->u
, buf
);
930 dev_warn(&card
->gdev
->dev
,
931 "Registering IP address %s failed\n", buf
);
936 static int qeth_l3_deregister_addr_entry(struct qeth_card
*card
,
937 struct qeth_ipaddr
*addr
)
941 if (addr
->proto
== QETH_PROT_IPV4
) {
942 QETH_CARD_TEXT(card
, 2, "deladdr4");
943 QETH_CARD_HEX(card
, 3, &addr
->u
.a4
.addr
, sizeof(int));
944 } else if (addr
->proto
== QETH_PROT_IPV6
) {
945 QETH_CARD_TEXT(card
, 2, "deladdr6");
946 QETH_CARD_HEX(card
, 3, &addr
->u
.a6
.addr
, 8);
947 QETH_CARD_HEX(card
, 3, ((char *)&addr
->u
.a6
.addr
) + 8, 8);
949 QETH_CARD_TEXT(card
, 2, "deladdr?");
950 QETH_CARD_HEX(card
, 3, addr
, sizeof(struct qeth_ipaddr
));
952 if (addr
->is_multicast
)
953 rc
= qeth_l3_send_setdelmc(card
, addr
, IPA_CMD_DELIPM
);
955 rc
= qeth_l3_send_setdelip(card
, addr
, IPA_CMD_DELIP
,
958 QETH_CARD_TEXT(card
, 2, "failed");
963 static inline u8
qeth_l3_get_qeth_hdr_flags4(int cast_type
)
965 if (cast_type
== RTN_MULTICAST
)
966 return QETH_CAST_MULTICAST
;
967 if (cast_type
== RTN_BROADCAST
)
968 return QETH_CAST_BROADCAST
;
969 return QETH_CAST_UNICAST
;
972 static inline u8
qeth_l3_get_qeth_hdr_flags6(int cast_type
)
974 u8 ct
= QETH_HDR_PASSTHRU
| QETH_HDR_IPV6
;
975 if (cast_type
== RTN_MULTICAST
)
976 return ct
| QETH_CAST_MULTICAST
;
977 if (cast_type
== RTN_ANYCAST
)
978 return ct
| QETH_CAST_ANYCAST
;
979 if (cast_type
== RTN_BROADCAST
)
980 return ct
| QETH_CAST_BROADCAST
;
981 return ct
| QETH_CAST_UNICAST
;
984 static int qeth_l3_setadapter_parms(struct qeth_card
*card
)
988 QETH_DBF_TEXT(SETUP
, 2, "setadprm");
990 if (!qeth_is_supported(card
, IPA_SETADAPTERPARMS
)) {
991 dev_info(&card
->gdev
->dev
,
992 "set adapter parameters not supported.\n");
993 QETH_DBF_TEXT(SETUP
, 2, " notsupp");
996 rc
= qeth_query_setadapterparms(card
);
998 QETH_DBF_MESSAGE(2, "%s couldn't set adapter parameters: "
999 "0x%x\n", dev_name(&card
->gdev
->dev
), rc
);
1002 if (qeth_adp_supported(card
, IPA_SETADP_ALTER_MAC_ADDRESS
)) {
1003 rc
= qeth_setadpparms_change_macaddr(card
);
1005 dev_warn(&card
->gdev
->dev
, "Reading the adapter MAC"
1006 " address failed\n");
1012 static int qeth_l3_default_setassparms_cb(struct qeth_card
*card
,
1013 struct qeth_reply
*reply
, unsigned long data
)
1015 struct qeth_ipa_cmd
*cmd
;
1017 QETH_CARD_TEXT(card
, 4, "defadpcb");
1019 cmd
= (struct qeth_ipa_cmd
*) data
;
1020 if (cmd
->hdr
.return_code
== 0) {
1021 cmd
->hdr
.return_code
= cmd
->data
.setassparms
.hdr
.return_code
;
1022 if (cmd
->hdr
.prot_version
== QETH_PROT_IPV4
)
1023 card
->options
.ipa4
.enabled_funcs
= cmd
->hdr
.ipa_enabled
;
1024 if (cmd
->hdr
.prot_version
== QETH_PROT_IPV6
)
1025 card
->options
.ipa6
.enabled_funcs
= cmd
->hdr
.ipa_enabled
;
1027 if (cmd
->data
.setassparms
.hdr
.assist_no
== IPA_INBOUND_CHECKSUM
&&
1028 cmd
->data
.setassparms
.hdr
.command_code
== IPA_CMD_ASS_START
) {
1029 card
->info
.csum_mask
= cmd
->data
.setassparms
.data
.flags_32bit
;
1030 QETH_CARD_TEXT_(card
, 3, "csum:%d", card
->info
.csum_mask
);
1032 if (cmd
->data
.setassparms
.hdr
.assist_no
== IPA_OUTBOUND_CHECKSUM
&&
1033 cmd
->data
.setassparms
.hdr
.command_code
== IPA_CMD_ASS_START
) {
1034 card
->info
.tx_csum_mask
=
1035 cmd
->data
.setassparms
.data
.flags_32bit
;
1036 QETH_CARD_TEXT_(card
, 3, "tcsu:%d", card
->info
.tx_csum_mask
);
1042 static struct qeth_cmd_buffer
*qeth_l3_get_setassparms_cmd(
1043 struct qeth_card
*card
, enum qeth_ipa_funcs ipa_func
, __u16 cmd_code
,
1044 __u16 len
, enum qeth_prot_versions prot
)
1046 struct qeth_cmd_buffer
*iob
;
1047 struct qeth_ipa_cmd
*cmd
;
1049 QETH_CARD_TEXT(card
, 4, "getasscm");
1050 iob
= qeth_get_ipacmd_buffer(card
, IPA_CMD_SETASSPARMS
, prot
);
1052 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
1053 cmd
->data
.setassparms
.hdr
.assist_no
= ipa_func
;
1054 cmd
->data
.setassparms
.hdr
.length
= 8 + len
;
1055 cmd
->data
.setassparms
.hdr
.command_code
= cmd_code
;
1056 cmd
->data
.setassparms
.hdr
.return_code
= 0;
1057 cmd
->data
.setassparms
.hdr
.seq_no
= 0;
1062 static int qeth_l3_send_setassparms(struct qeth_card
*card
,
1063 struct qeth_cmd_buffer
*iob
, __u16 len
, long data
,
1064 int (*reply_cb
)(struct qeth_card
*, struct qeth_reply
*,
1069 struct qeth_ipa_cmd
*cmd
;
1071 QETH_CARD_TEXT(card
, 4, "sendassp");
1073 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
1074 if (len
<= sizeof(__u32
))
1075 cmd
->data
.setassparms
.data
.flags_32bit
= (__u32
) data
;
1076 else /* (len > sizeof(__u32)) */
1077 memcpy(&cmd
->data
.setassparms
.data
, (void *) data
, len
);
1079 rc
= qeth_send_ipa_cmd(card
, iob
, reply_cb
, reply_param
);
1083 #ifdef CONFIG_QETH_IPV6
1084 static int qeth_l3_send_simple_setassparms_ipv6(struct qeth_card
*card
,
1085 enum qeth_ipa_funcs ipa_func
, __u16 cmd_code
)
1088 struct qeth_cmd_buffer
*iob
;
1090 QETH_CARD_TEXT(card
, 4, "simassp6");
1091 iob
= qeth_l3_get_setassparms_cmd(card
, ipa_func
, cmd_code
,
1093 rc
= qeth_l3_send_setassparms(card
, iob
, 0, 0,
1094 qeth_l3_default_setassparms_cb
, NULL
);
1099 static int qeth_l3_send_simple_setassparms(struct qeth_card
*card
,
1100 enum qeth_ipa_funcs ipa_func
, __u16 cmd_code
, long data
)
1104 struct qeth_cmd_buffer
*iob
;
1106 QETH_CARD_TEXT(card
, 4, "simassp4");
1108 length
= sizeof(__u32
);
1109 iob
= qeth_l3_get_setassparms_cmd(card
, ipa_func
, cmd_code
,
1110 length
, QETH_PROT_IPV4
);
1111 rc
= qeth_l3_send_setassparms(card
, iob
, length
, data
,
1112 qeth_l3_default_setassparms_cb
, NULL
);
1116 static int qeth_l3_start_ipa_arp_processing(struct qeth_card
*card
)
1120 QETH_CARD_TEXT(card
, 3, "ipaarp");
1122 if (!qeth_is_supported(card
, IPA_ARP_PROCESSING
)) {
1123 dev_info(&card
->gdev
->dev
,
1124 "ARP processing not supported on %s!\n",
1125 QETH_CARD_IFNAME(card
));
1128 rc
= qeth_l3_send_simple_setassparms(card
, IPA_ARP_PROCESSING
,
1129 IPA_CMD_ASS_START
, 0);
1131 dev_warn(&card
->gdev
->dev
,
1132 "Starting ARP processing support for %s failed\n",
1133 QETH_CARD_IFNAME(card
));
1138 static int qeth_l3_start_ipa_ip_fragmentation(struct qeth_card
*card
)
1142 QETH_CARD_TEXT(card
, 3, "ipaipfrg");
1144 if (!qeth_is_supported(card
, IPA_IP_FRAGMENTATION
)) {
1145 dev_info(&card
->gdev
->dev
,
1146 "Hardware IP fragmentation not supported on %s\n",
1147 QETH_CARD_IFNAME(card
));
1151 rc
= qeth_l3_send_simple_setassparms(card
, IPA_IP_FRAGMENTATION
,
1152 IPA_CMD_ASS_START
, 0);
1154 dev_warn(&card
->gdev
->dev
,
1155 "Starting IP fragmentation support for %s failed\n",
1156 QETH_CARD_IFNAME(card
));
1158 dev_info(&card
->gdev
->dev
,
1159 "Hardware IP fragmentation enabled \n");
1163 static int qeth_l3_start_ipa_source_mac(struct qeth_card
*card
)
1167 QETH_CARD_TEXT(card
, 3, "stsrcmac");
1169 if (!qeth_is_supported(card
, IPA_SOURCE_MAC
)) {
1170 dev_info(&card
->gdev
->dev
,
1171 "Inbound source MAC-address not supported on %s\n",
1172 QETH_CARD_IFNAME(card
));
1176 rc
= qeth_l3_send_simple_setassparms(card
, IPA_SOURCE_MAC
,
1177 IPA_CMD_ASS_START
, 0);
1179 dev_warn(&card
->gdev
->dev
,
1180 "Starting source MAC-address support for %s failed\n",
1181 QETH_CARD_IFNAME(card
));
1185 static int qeth_l3_start_ipa_vlan(struct qeth_card
*card
)
1189 QETH_CARD_TEXT(card
, 3, "strtvlan");
1191 if (!qeth_is_supported(card
, IPA_FULL_VLAN
)) {
1192 dev_info(&card
->gdev
->dev
,
1193 "VLAN not supported on %s\n", QETH_CARD_IFNAME(card
));
1197 rc
= qeth_l3_send_simple_setassparms(card
, IPA_VLAN_PRIO
,
1198 IPA_CMD_ASS_START
, 0);
1200 dev_warn(&card
->gdev
->dev
,
1201 "Starting VLAN support for %s failed\n",
1202 QETH_CARD_IFNAME(card
));
1204 dev_info(&card
->gdev
->dev
, "VLAN enabled\n");
1209 static int qeth_l3_start_ipa_multicast(struct qeth_card
*card
)
1213 QETH_CARD_TEXT(card
, 3, "stmcast");
1215 if (!qeth_is_supported(card
, IPA_MULTICASTING
)) {
1216 dev_info(&card
->gdev
->dev
,
1217 "Multicast not supported on %s\n",
1218 QETH_CARD_IFNAME(card
));
1222 rc
= qeth_l3_send_simple_setassparms(card
, IPA_MULTICASTING
,
1223 IPA_CMD_ASS_START
, 0);
1225 dev_warn(&card
->gdev
->dev
,
1226 "Starting multicast support for %s failed\n",
1227 QETH_CARD_IFNAME(card
));
1229 dev_info(&card
->gdev
->dev
, "Multicast enabled\n");
1230 card
->dev
->flags
|= IFF_MULTICAST
;
1235 #ifdef CONFIG_QETH_IPV6
1236 static int qeth_l3_softsetup_ipv6(struct qeth_card
*card
)
1240 QETH_CARD_TEXT(card
, 3, "softipv6");
1242 if (card
->info
.type
== QETH_CARD_TYPE_IQD
)
1245 rc
= qeth_query_ipassists(card
, QETH_PROT_IPV6
);
1247 dev_err(&card
->gdev
->dev
,
1248 "Activating IPv6 support for %s failed\n",
1249 QETH_CARD_IFNAME(card
));
1252 rc
= qeth_l3_send_simple_setassparms(card
, IPA_IPV6
,
1253 IPA_CMD_ASS_START
, 3);
1255 dev_err(&card
->gdev
->dev
,
1256 "Activating IPv6 support for %s failed\n",
1257 QETH_CARD_IFNAME(card
));
1260 rc
= qeth_l3_send_simple_setassparms_ipv6(card
, IPA_IPV6
,
1263 dev_err(&card
->gdev
->dev
,
1264 "Activating IPv6 support for %s failed\n",
1265 QETH_CARD_IFNAME(card
));
1268 rc
= qeth_l3_send_simple_setassparms_ipv6(card
, IPA_PASSTHRU
,
1271 dev_warn(&card
->gdev
->dev
,
1272 "Enabling the passthrough mode for %s failed\n",
1273 QETH_CARD_IFNAME(card
));
1277 dev_info(&card
->gdev
->dev
, "IPV6 enabled\n");
1282 static int qeth_l3_start_ipa_ipv6(struct qeth_card
*card
)
1286 QETH_CARD_TEXT(card
, 3, "strtipv6");
1288 if (!qeth_is_supported(card
, IPA_IPV6
)) {
1289 dev_info(&card
->gdev
->dev
,
1290 "IPv6 not supported on %s\n", QETH_CARD_IFNAME(card
));
1293 #ifdef CONFIG_QETH_IPV6
1294 rc
= qeth_l3_softsetup_ipv6(card
);
1299 static int qeth_l3_start_ipa_broadcast(struct qeth_card
*card
)
1303 QETH_CARD_TEXT(card
, 3, "stbrdcst");
1304 card
->info
.broadcast_capable
= 0;
1305 if (!qeth_is_supported(card
, IPA_FILTERING
)) {
1306 dev_info(&card
->gdev
->dev
,
1307 "Broadcast not supported on %s\n",
1308 QETH_CARD_IFNAME(card
));
1312 rc
= qeth_l3_send_simple_setassparms(card
, IPA_FILTERING
,
1313 IPA_CMD_ASS_START
, 0);
1315 dev_warn(&card
->gdev
->dev
, "Enabling broadcast filtering for "
1316 "%s failed\n", QETH_CARD_IFNAME(card
));
1320 rc
= qeth_l3_send_simple_setassparms(card
, IPA_FILTERING
,
1321 IPA_CMD_ASS_CONFIGURE
, 1);
1323 dev_warn(&card
->gdev
->dev
,
1324 "Setting up broadcast filtering for %s failed\n",
1325 QETH_CARD_IFNAME(card
));
1328 card
->info
.broadcast_capable
= QETH_BROADCAST_WITH_ECHO
;
1329 dev_info(&card
->gdev
->dev
, "Broadcast enabled\n");
1330 rc
= qeth_l3_send_simple_setassparms(card
, IPA_FILTERING
,
1331 IPA_CMD_ASS_ENABLE
, 1);
1333 dev_warn(&card
->gdev
->dev
, "Setting up broadcast echo "
1334 "filtering for %s failed\n", QETH_CARD_IFNAME(card
));
1337 card
->info
.broadcast_capable
= QETH_BROADCAST_WITHOUT_ECHO
;
1339 if (card
->info
.broadcast_capable
)
1340 card
->dev
->flags
|= IFF_BROADCAST
;
1342 card
->dev
->flags
&= ~IFF_BROADCAST
;
1346 static int qeth_l3_send_checksum_command(struct qeth_card
*card
)
1350 rc
= qeth_l3_send_simple_setassparms(card
, IPA_INBOUND_CHECKSUM
,
1351 IPA_CMD_ASS_START
, 0);
1353 dev_warn(&card
->gdev
->dev
, "Starting HW checksumming for %s "
1354 "failed, using SW checksumming\n",
1355 QETH_CARD_IFNAME(card
));
1358 rc
= qeth_l3_send_simple_setassparms(card
, IPA_INBOUND_CHECKSUM
,
1360 card
->info
.csum_mask
);
1362 dev_warn(&card
->gdev
->dev
, "Enabling HW checksumming for %s "
1363 "failed, using SW checksumming\n",
1364 QETH_CARD_IFNAME(card
));
1370 static int qeth_l3_set_rx_csum(struct qeth_card
*card
, int on
)
1375 rc
= qeth_l3_send_checksum_command(card
);
1378 dev_info(&card
->gdev
->dev
,
1379 "HW Checksumming (inbound) enabled\n");
1381 rc
= qeth_l3_send_simple_setassparms(card
,
1382 IPA_INBOUND_CHECKSUM
, IPA_CMD_ASS_STOP
, 0);
1390 static int qeth_l3_start_ipa_checksum(struct qeth_card
*card
)
1392 QETH_CARD_TEXT(card
, 3, "strtcsum");
1394 if (card
->dev
->features
& NETIF_F_RXCSUM
) {
1396 /* force set_features call */
1397 card
->dev
->features
&= ~NETIF_F_RXCSUM
;
1398 netdev_update_features(card
->dev
);
1404 static int qeth_l3_start_ipa_tx_checksum(struct qeth_card
*card
)
1408 if (!qeth_is_supported(card
, IPA_OUTBOUND_CHECKSUM
))
1410 rc
= qeth_l3_send_simple_setassparms(card
, IPA_OUTBOUND_CHECKSUM
,
1411 IPA_CMD_ASS_START
, 0);
1414 rc
= qeth_l3_send_simple_setassparms(card
, IPA_OUTBOUND_CHECKSUM
,
1415 IPA_CMD_ASS_ENABLE
, card
->info
.tx_csum_mask
);
1418 dev_info(&card
->gdev
->dev
, "HW TX Checksumming enabled\n");
1421 dev_warn(&card
->gdev
->dev
, "Enabling HW TX checksumming for %s "
1422 "failed, using SW TX checksumming\n", QETH_CARD_IFNAME(card
));
1426 static int qeth_l3_start_ipa_tso(struct qeth_card
*card
)
1430 QETH_CARD_TEXT(card
, 3, "sttso");
1432 if (!qeth_is_supported(card
, IPA_OUTBOUND_TSO
)) {
1433 dev_info(&card
->gdev
->dev
,
1434 "Outbound TSO not supported on %s\n",
1435 QETH_CARD_IFNAME(card
));
1438 rc
= qeth_l3_send_simple_setassparms(card
, IPA_OUTBOUND_TSO
,
1439 IPA_CMD_ASS_START
, 0);
1441 dev_warn(&card
->gdev
->dev
, "Starting outbound TCP "
1442 "segmentation offload for %s failed\n",
1443 QETH_CARD_IFNAME(card
));
1445 dev_info(&card
->gdev
->dev
,
1446 "Outbound TSO enabled\n");
1449 card
->dev
->features
&= ~NETIF_F_TSO
;
1453 static int qeth_l3_start_ipassists(struct qeth_card
*card
)
1455 QETH_CARD_TEXT(card
, 3, "strtipas");
1457 if (qeth_set_access_ctrl_online(card
, 0))
1459 qeth_l3_start_ipa_arp_processing(card
); /* go on*/
1460 qeth_l3_start_ipa_ip_fragmentation(card
); /* go on*/
1461 qeth_l3_start_ipa_source_mac(card
); /* go on*/
1462 qeth_l3_start_ipa_vlan(card
); /* go on*/
1463 qeth_l3_start_ipa_multicast(card
); /* go on*/
1464 qeth_l3_start_ipa_ipv6(card
); /* go on*/
1465 qeth_l3_start_ipa_broadcast(card
); /* go on*/
1466 qeth_l3_start_ipa_checksum(card
); /* go on*/
1467 qeth_l3_start_ipa_tx_checksum(card
);
1468 qeth_l3_start_ipa_tso(card
); /* go on*/
1472 static int qeth_l3_iqd_read_initial_mac_cb(struct qeth_card
*card
,
1473 struct qeth_reply
*reply
, unsigned long data
)
1475 struct qeth_ipa_cmd
*cmd
;
1477 cmd
= (struct qeth_ipa_cmd
*) data
;
1478 if (cmd
->hdr
.return_code
== 0)
1479 memcpy(card
->dev
->dev_addr
,
1480 cmd
->data
.create_destroy_addr
.unique_id
, ETH_ALEN
);
1482 eth_random_addr(card
->dev
->dev_addr
);
1487 static int qeth_l3_iqd_read_initial_mac(struct qeth_card
*card
)
1490 struct qeth_cmd_buffer
*iob
;
1491 struct qeth_ipa_cmd
*cmd
;
1493 QETH_DBF_TEXT(SETUP
, 2, "hsrmac");
1495 iob
= qeth_get_ipacmd_buffer(card
, IPA_CMD_CREATE_ADDR
,
1497 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
1498 *((__u16
*) &cmd
->data
.create_destroy_addr
.unique_id
[6]) =
1499 card
->info
.unique_id
;
1501 rc
= qeth_send_ipa_cmd(card
, iob
, qeth_l3_iqd_read_initial_mac_cb
,
1506 static int qeth_l3_get_unique_id_cb(struct qeth_card
*card
,
1507 struct qeth_reply
*reply
, unsigned long data
)
1509 struct qeth_ipa_cmd
*cmd
;
1511 cmd
= (struct qeth_ipa_cmd
*) data
;
1512 if (cmd
->hdr
.return_code
== 0)
1513 card
->info
.unique_id
= *((__u16
*)
1514 &cmd
->data
.create_destroy_addr
.unique_id
[6]);
1516 card
->info
.unique_id
= UNIQUE_ID_IF_CREATE_ADDR_FAILED
|
1517 UNIQUE_ID_NOT_BY_CARD
;
1518 dev_warn(&card
->gdev
->dev
, "The network adapter failed to "
1519 "generate a unique ID\n");
1524 static int qeth_l3_get_unique_id(struct qeth_card
*card
)
1527 struct qeth_cmd_buffer
*iob
;
1528 struct qeth_ipa_cmd
*cmd
;
1530 QETH_DBF_TEXT(SETUP
, 2, "guniqeid");
1532 if (!qeth_is_supported(card
, IPA_IPV6
)) {
1533 card
->info
.unique_id
= UNIQUE_ID_IF_CREATE_ADDR_FAILED
|
1534 UNIQUE_ID_NOT_BY_CARD
;
1538 iob
= qeth_get_ipacmd_buffer(card
, IPA_CMD_CREATE_ADDR
,
1540 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
1541 *((__u16
*) &cmd
->data
.create_destroy_addr
.unique_id
[6]) =
1542 card
->info
.unique_id
;
1544 rc
= qeth_send_ipa_cmd(card
, iob
, qeth_l3_get_unique_id_cb
, NULL
);
1549 qeth_diags_trace_cb(struct qeth_card
*card
, struct qeth_reply
*reply
,
1552 struct qeth_ipa_cmd
*cmd
;
1555 QETH_DBF_TEXT(SETUP
, 2, "diastrcb");
1557 cmd
= (struct qeth_ipa_cmd
*)data
;
1558 rc
= cmd
->hdr
.return_code
;
1560 QETH_CARD_TEXT_(card
, 2, "dxter%x", rc
);
1561 switch (cmd
->data
.diagass
.action
) {
1562 case QETH_DIAGS_CMD_TRACE_QUERY
:
1564 case QETH_DIAGS_CMD_TRACE_DISABLE
:
1567 case IPA_RC_INVALID_SUBCMD
:
1568 card
->info
.promisc_mode
= SET_PROMISC_MODE_OFF
;
1569 dev_info(&card
->gdev
->dev
, "The HiperSockets network "
1570 "traffic analyzer is deactivated\n");
1576 case QETH_DIAGS_CMD_TRACE_ENABLE
:
1579 card
->info
.promisc_mode
= SET_PROMISC_MODE_ON
;
1580 dev_info(&card
->gdev
->dev
, "The HiperSockets network "
1581 "traffic analyzer is activated\n");
1583 case IPA_RC_HARDWARE_AUTH_ERROR
:
1584 dev_warn(&card
->gdev
->dev
, "The device is not "
1585 "authorized to run as a HiperSockets network "
1586 "traffic analyzer\n");
1588 case IPA_RC_TRACE_ALREADY_ACTIVE
:
1589 dev_warn(&card
->gdev
->dev
, "A HiperSockets "
1590 "network traffic analyzer is already "
1591 "active in the HiperSockets LAN\n");
1598 QETH_DBF_MESSAGE(2, "Unknown sniffer action (0x%04x) on %s\n",
1599 cmd
->data
.diagass
.action
, QETH_CARD_IFNAME(card
));
1606 qeth_diags_trace(struct qeth_card
*card
, enum qeth_diags_trace_cmds diags_cmd
)
1608 struct qeth_cmd_buffer
*iob
;
1609 struct qeth_ipa_cmd
*cmd
;
1611 QETH_DBF_TEXT(SETUP
, 2, "diagtrac");
1613 iob
= qeth_get_ipacmd_buffer(card
, IPA_CMD_SET_DIAG_ASS
, 0);
1614 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
1615 cmd
->data
.diagass
.subcmd_len
= 16;
1616 cmd
->data
.diagass
.subcmd
= QETH_DIAGS_CMD_TRACE
;
1617 cmd
->data
.diagass
.type
= QETH_DIAGS_TYPE_HIPERSOCKET
;
1618 cmd
->data
.diagass
.action
= diags_cmd
;
1619 return qeth_send_ipa_cmd(card
, iob
, qeth_diags_trace_cb
, NULL
);
1622 static void qeth_l3_get_mac_for_ipm(__u32 ipm
, char *mac
,
1623 struct net_device
*dev
)
1625 ip_eth_mc_map(ipm
, mac
);
1628 static void qeth_l3_add_mc(struct qeth_card
*card
, struct in_device
*in4_dev
)
1630 struct qeth_ipaddr
*ipm
;
1631 struct ip_mc_list
*im4
;
1632 char buf
[MAX_ADDR_LEN
];
1634 QETH_CARD_TEXT(card
, 4, "addmc");
1635 for (im4
= rcu_dereference(in4_dev
->mc_list
); im4
!= NULL
;
1636 im4
= rcu_dereference(im4
->next_rcu
)) {
1637 qeth_l3_get_mac_for_ipm(im4
->multiaddr
, buf
, in4_dev
->dev
);
1638 ipm
= qeth_l3_get_addr_buffer(QETH_PROT_IPV4
);
1641 ipm
->u
.a4
.addr
= im4
->multiaddr
;
1642 memcpy(ipm
->mac
, buf
, OSA_ADDR_LEN
);
1643 ipm
->is_multicast
= 1;
1644 if (!qeth_l3_add_ip(card
, ipm
))
1649 /* called with rcu_read_lock */
1650 static void qeth_l3_add_vlan_mc(struct qeth_card
*card
)
1652 struct in_device
*in_dev
;
1655 QETH_CARD_TEXT(card
, 4, "addmcvl");
1656 if (!qeth_is_supported(card
, IPA_FULL_VLAN
))
1659 for_each_set_bit(vid
, card
->active_vlans
, VLAN_N_VID
) {
1660 struct net_device
*netdev
;
1662 netdev
= __vlan_find_dev_deep_rcu(card
->dev
, htons(ETH_P_8021Q
),
1664 if (netdev
== NULL
||
1665 !(netdev
->flags
& IFF_UP
))
1667 in_dev
= __in_dev_get_rcu(netdev
);
1670 qeth_l3_add_mc(card
, in_dev
);
1674 static void qeth_l3_add_multicast_ipv4(struct qeth_card
*card
)
1676 struct in_device
*in4_dev
;
1678 QETH_CARD_TEXT(card
, 4, "chkmcv4");
1680 in4_dev
= __in_dev_get_rcu(card
->dev
);
1681 if (in4_dev
== NULL
)
1683 qeth_l3_add_mc(card
, in4_dev
);
1684 qeth_l3_add_vlan_mc(card
);
1689 #ifdef CONFIG_QETH_IPV6
1690 static void qeth_l3_add_mc6(struct qeth_card
*card
, struct inet6_dev
*in6_dev
)
1692 struct qeth_ipaddr
*ipm
;
1693 struct ifmcaddr6
*im6
;
1694 char buf
[MAX_ADDR_LEN
];
1696 QETH_CARD_TEXT(card
, 4, "addmc6");
1697 for (im6
= in6_dev
->mc_list
; im6
!= NULL
; im6
= im6
->next
) {
1698 ndisc_mc_map(&im6
->mca_addr
, buf
, in6_dev
->dev
, 0);
1699 ipm
= qeth_l3_get_addr_buffer(QETH_PROT_IPV6
);
1702 ipm
->is_multicast
= 1;
1703 memcpy(ipm
->mac
, buf
, OSA_ADDR_LEN
);
1704 memcpy(&ipm
->u
.a6
.addr
, &im6
->mca_addr
.s6_addr
,
1705 sizeof(struct in6_addr
));
1706 if (!qeth_l3_add_ip(card
, ipm
))
1711 /* called with rcu_read_lock */
1712 static void qeth_l3_add_vlan_mc6(struct qeth_card
*card
)
1714 struct inet6_dev
*in_dev
;
1717 QETH_CARD_TEXT(card
, 4, "admc6vl");
1718 if (!qeth_is_supported(card
, IPA_FULL_VLAN
))
1721 for_each_set_bit(vid
, card
->active_vlans
, VLAN_N_VID
) {
1722 struct net_device
*netdev
;
1724 netdev
= __vlan_find_dev_deep_rcu(card
->dev
, htons(ETH_P_8021Q
),
1726 if (netdev
== NULL
||
1727 !(netdev
->flags
& IFF_UP
))
1729 in_dev
= in6_dev_get(netdev
);
1732 read_lock_bh(&in_dev
->lock
);
1733 qeth_l3_add_mc6(card
, in_dev
);
1734 read_unlock_bh(&in_dev
->lock
);
1735 in6_dev_put(in_dev
);
1739 static void qeth_l3_add_multicast_ipv6(struct qeth_card
*card
)
1741 struct inet6_dev
*in6_dev
;
1743 QETH_CARD_TEXT(card
, 4, "chkmcv6");
1744 if (!qeth_is_supported(card
, IPA_IPV6
))
1746 in6_dev
= in6_dev_get(card
->dev
);
1747 if (in6_dev
== NULL
)
1750 read_lock_bh(&in6_dev
->lock
);
1751 qeth_l3_add_mc6(card
, in6_dev
);
1752 qeth_l3_add_vlan_mc6(card
);
1753 read_unlock_bh(&in6_dev
->lock
);
1755 in6_dev_put(in6_dev
);
1757 #endif /* CONFIG_QETH_IPV6 */
1759 static void qeth_l3_free_vlan_addresses4(struct qeth_card
*card
,
1762 struct in_device
*in_dev
;
1763 struct in_ifaddr
*ifa
;
1764 struct qeth_ipaddr
*addr
;
1765 struct net_device
*netdev
;
1767 QETH_CARD_TEXT(card
, 4, "frvaddr4");
1769 netdev
= __vlan_find_dev_deep_rcu(card
->dev
, htons(ETH_P_8021Q
), vid
);
1772 in_dev
= in_dev_get(netdev
);
1775 for (ifa
= in_dev
->ifa_list
; ifa
; ifa
= ifa
->ifa_next
) {
1776 addr
= qeth_l3_get_addr_buffer(QETH_PROT_IPV4
);
1778 addr
->u
.a4
.addr
= ifa
->ifa_address
;
1779 addr
->u
.a4
.mask
= ifa
->ifa_mask
;
1780 addr
->type
= QETH_IP_TYPE_NORMAL
;
1781 if (!qeth_l3_delete_ip(card
, addr
))
1788 static void qeth_l3_free_vlan_addresses6(struct qeth_card
*card
,
1791 #ifdef CONFIG_QETH_IPV6
1792 struct inet6_dev
*in6_dev
;
1793 struct inet6_ifaddr
*ifa
;
1794 struct qeth_ipaddr
*addr
;
1795 struct net_device
*netdev
;
1797 QETH_CARD_TEXT(card
, 4, "frvaddr6");
1799 netdev
= __vlan_find_dev_deep_rcu(card
->dev
, htons(ETH_P_8021Q
), vid
);
1802 in6_dev
= in6_dev_get(netdev
);
1805 list_for_each_entry(ifa
, &in6_dev
->addr_list
, if_list
) {
1806 addr
= qeth_l3_get_addr_buffer(QETH_PROT_IPV6
);
1808 memcpy(&addr
->u
.a6
.addr
, &ifa
->addr
,
1809 sizeof(struct in6_addr
));
1810 addr
->u
.a6
.pfxlen
= ifa
->prefix_len
;
1811 addr
->type
= QETH_IP_TYPE_NORMAL
;
1812 if (!qeth_l3_delete_ip(card
, addr
))
1816 in6_dev_put(in6_dev
);
1817 #endif /* CONFIG_QETH_IPV6 */
1820 static void qeth_l3_free_vlan_addresses(struct qeth_card
*card
,
1824 qeth_l3_free_vlan_addresses4(card
, vid
);
1825 qeth_l3_free_vlan_addresses6(card
, vid
);
1829 static int qeth_l3_vlan_rx_add_vid(struct net_device
*dev
,
1830 __be16 proto
, u16 vid
)
1832 struct qeth_card
*card
= dev
->ml_priv
;
1834 set_bit(vid
, card
->active_vlans
);
1838 static int qeth_l3_vlan_rx_kill_vid(struct net_device
*dev
,
1839 __be16 proto
, u16 vid
)
1841 struct qeth_card
*card
= dev
->ml_priv
;
1842 unsigned long flags
;
1844 QETH_CARD_TEXT_(card
, 4, "kid:%d", vid
);
1845 if (qeth_wait_for_threads(card
, QETH_RECOVER_THREAD
)) {
1846 QETH_CARD_TEXT(card
, 3, "kidREC");
1849 spin_lock_irqsave(&card
->vlanlock
, flags
);
1850 /* unregister IP addresses of vlan device */
1851 qeth_l3_free_vlan_addresses(card
, vid
);
1852 clear_bit(vid
, card
->active_vlans
);
1853 spin_unlock_irqrestore(&card
->vlanlock
, flags
);
1854 qeth_l3_set_multicast_list(card
->dev
);
1858 static inline int qeth_l3_rebuild_skb(struct qeth_card
*card
,
1859 struct sk_buff
*skb
, struct qeth_hdr
*hdr
,
1860 unsigned short *vlan_id
)
1863 struct iphdr
*ip_hdr
;
1864 unsigned char tg_addr
[MAX_ADDR_LEN
];
1867 if (!(hdr
->hdr
.l3
.flags
& QETH_HDR_PASSTHRU
)) {
1868 prot
= htons((hdr
->hdr
.l3
.flags
& QETH_HDR_IPV6
)? ETH_P_IPV6
:
1870 switch (hdr
->hdr
.l3
.flags
& QETH_HDR_CAST_MASK
) {
1871 case QETH_CAST_MULTICAST
:
1873 #ifdef CONFIG_QETH_IPV6
1874 case __constant_htons(ETH_P_IPV6
):
1875 ndisc_mc_map((struct in6_addr
*)
1877 tg_addr
, card
->dev
, 0);
1880 case __constant_htons(ETH_P_IP
):
1881 ip_hdr
= (struct iphdr
*)skb
->data
;
1882 ip_eth_mc_map(ip_hdr
->daddr
, tg_addr
);
1885 memcpy(tg_addr
, card
->dev
->broadcast
,
1886 card
->dev
->addr_len
);
1888 card
->stats
.multicast
++;
1889 skb
->pkt_type
= PACKET_MULTICAST
;
1891 case QETH_CAST_BROADCAST
:
1892 memcpy(tg_addr
, card
->dev
->broadcast
,
1893 card
->dev
->addr_len
);
1894 card
->stats
.multicast
++;
1895 skb
->pkt_type
= PACKET_BROADCAST
;
1897 case QETH_CAST_UNICAST
:
1898 case QETH_CAST_ANYCAST
:
1899 case QETH_CAST_NOCAST
:
1901 if (card
->options
.sniffer
)
1902 skb
->pkt_type
= PACKET_OTHERHOST
;
1904 skb
->pkt_type
= PACKET_HOST
;
1905 memcpy(tg_addr
, card
->dev
->dev_addr
,
1906 card
->dev
->addr_len
);
1908 if (hdr
->hdr
.l3
.ext_flags
& QETH_HDR_EXT_SRC_MAC_ADDR
)
1909 card
->dev
->header_ops
->create(skb
, card
->dev
, prot
,
1910 tg_addr
, &hdr
->hdr
.l3
.dest_addr
[2],
1911 card
->dev
->addr_len
);
1913 card
->dev
->header_ops
->create(skb
, card
->dev
, prot
,
1914 tg_addr
, "FAKELL", card
->dev
->addr_len
);
1917 skb
->protocol
= eth_type_trans(skb
, card
->dev
);
1919 if (hdr
->hdr
.l3
.ext_flags
&
1920 (QETH_HDR_EXT_VLAN_FRAME
| QETH_HDR_EXT_INCLUDE_VLAN_TAG
)) {
1921 *vlan_id
= (hdr
->hdr
.l3
.ext_flags
& QETH_HDR_EXT_VLAN_FRAME
) ?
1922 hdr
->hdr
.l3
.vlan_id
: *((u16
*)&hdr
->hdr
.l3
.dest_addr
[12]);
1926 if (card
->dev
->features
& NETIF_F_RXCSUM
) {
1927 if ((hdr
->hdr
.l3
.ext_flags
&
1928 (QETH_HDR_EXT_CSUM_HDR_REQ
|
1929 QETH_HDR_EXT_CSUM_TRANSP_REQ
)) ==
1930 (QETH_HDR_EXT_CSUM_HDR_REQ
|
1931 QETH_HDR_EXT_CSUM_TRANSP_REQ
))
1932 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
1934 skb
->ip_summed
= CHECKSUM_NONE
;
1936 skb
->ip_summed
= CHECKSUM_NONE
;
1941 static int qeth_l3_process_inbound_buffer(struct qeth_card
*card
,
1942 int budget
, int *done
)
1945 struct sk_buff
*skb
;
1946 struct qeth_hdr
*hdr
;
1953 WARN_ON_ONCE(!budget
);
1955 skb
= qeth_core_get_next_skb(card
,
1956 &card
->qdio
.in_q
->bufs
[card
->rx
.b_index
],
1957 &card
->rx
.b_element
, &card
->rx
.e_offset
, &hdr
);
1962 skb
->dev
= card
->dev
;
1963 switch (hdr
->hdr
.l3
.id
) {
1964 case QETH_HEADER_TYPE_LAYER3
:
1965 magic
= *(__u16
*)skb
->data
;
1966 if ((card
->info
.type
== QETH_CARD_TYPE_IQD
) &&
1967 (magic
== ETH_P_AF_IUCV
)) {
1968 skb
->protocol
= ETH_P_AF_IUCV
;
1969 skb
->pkt_type
= PACKET_HOST
;
1970 skb
->mac_header
= NET_SKB_PAD
;
1971 skb
->dev
= card
->dev
;
1973 card
->dev
->header_ops
->create(skb
, card
->dev
, 0,
1974 card
->dev
->dev_addr
, "FAKELL",
1975 card
->dev
->addr_len
);
1976 netif_receive_skb(skb
);
1978 is_vlan
= qeth_l3_rebuild_skb(card
, skb
, hdr
,
1981 if (is_vlan
&& !card
->options
.sniffer
)
1982 __vlan_hwaccel_put_tag(skb
,
1983 htons(ETH_P_8021Q
), vlan_tag
);
1984 napi_gro_receive(&card
->napi
, skb
);
1987 case QETH_HEADER_TYPE_LAYER2
: /* for HiperSockets sniffer */
1988 skb
->pkt_type
= PACKET_HOST
;
1989 skb
->protocol
= eth_type_trans(skb
, skb
->dev
);
1991 netif_receive_skb(skb
);
1994 dev_kfree_skb_any(skb
);
1995 QETH_CARD_TEXT(card
, 3, "inbunkno");
1996 QETH_DBF_HEX(CTRL
, 3, hdr
, QETH_DBF_CTRL_LEN
);
2001 card
->stats
.rx_packets
++;
2002 card
->stats
.rx_bytes
+= len
;
2007 static int qeth_l3_poll(struct napi_struct
*napi
, int budget
)
2009 struct qeth_card
*card
= container_of(napi
, struct qeth_card
, napi
);
2011 struct qeth_qdio_buffer
*buffer
;
2013 int new_budget
= budget
;
2015 if (card
->options
.performance_stats
) {
2016 card
->perf_stats
.inbound_cnt
++;
2017 card
->perf_stats
.inbound_start_time
= qeth_get_micros();
2021 if (!card
->rx
.b_count
) {
2022 card
->rx
.qdio_err
= 0;
2023 card
->rx
.b_count
= qdio_get_next_buffers(
2024 card
->data
.ccwdev
, 0, &card
->rx
.b_index
,
2025 &card
->rx
.qdio_err
);
2026 if (card
->rx
.b_count
<= 0) {
2027 card
->rx
.b_count
= 0;
2030 card
->rx
.b_element
=
2031 &card
->qdio
.in_q
->bufs
[card
->rx
.b_index
]
2032 .buffer
->element
[0];
2033 card
->rx
.e_offset
= 0;
2036 while (card
->rx
.b_count
) {
2037 buffer
= &card
->qdio
.in_q
->bufs
[card
->rx
.b_index
];
2038 if (!(card
->rx
.qdio_err
&&
2039 qeth_check_qdio_errors(card
, buffer
->buffer
,
2040 card
->rx
.qdio_err
, "qinerr")))
2041 work_done
+= qeth_l3_process_inbound_buffer(
2042 card
, new_budget
, &done
);
2047 if (card
->options
.performance_stats
)
2048 card
->perf_stats
.bufs_rec
++;
2049 qeth_put_buffer_pool_entry(card
,
2050 buffer
->pool_entry
);
2051 qeth_queue_input_buffer(card
, card
->rx
.b_index
);
2053 if (card
->rx
.b_count
) {
2055 (card
->rx
.b_index
+ 1) %
2056 QDIO_MAX_BUFFERS_PER_Q
;
2057 card
->rx
.b_element
=
2059 ->bufs
[card
->rx
.b_index
]
2060 .buffer
->element
[0];
2061 card
->rx
.e_offset
= 0;
2065 if (work_done
>= budget
)
2068 new_budget
= budget
- work_done
;
2072 napi_complete(napi
);
2073 if (qdio_start_irq(card
->data
.ccwdev
, 0))
2074 napi_schedule(&card
->napi
);
2076 if (card
->options
.performance_stats
)
2077 card
->perf_stats
.inbound_time
+= qeth_get_micros() -
2078 card
->perf_stats
.inbound_start_time
;
2082 static int qeth_l3_verify_vlan_dev(struct net_device
*dev
,
2083 struct qeth_card
*card
)
2088 for_each_set_bit(vid
, card
->active_vlans
, VLAN_N_VID
) {
2089 struct net_device
*netdev
;
2092 netdev
= __vlan_find_dev_deep_rcu(card
->dev
, htons(ETH_P_8021Q
),
2095 if (netdev
== dev
) {
2096 rc
= QETH_VLAN_CARD
;
2101 if (rc
&& !(vlan_dev_real_dev(dev
)->ml_priv
== (void *)card
))
2107 static int qeth_l3_verify_dev(struct net_device
*dev
)
2109 struct qeth_card
*card
;
2110 unsigned long flags
;
2113 read_lock_irqsave(&qeth_core_card_list
.rwlock
, flags
);
2114 list_for_each_entry(card
, &qeth_core_card_list
.list
, list
) {
2115 if (card
->dev
== dev
) {
2116 rc
= QETH_REAL_CARD
;
2119 rc
= qeth_l3_verify_vlan_dev(dev
, card
);
2123 read_unlock_irqrestore(&qeth_core_card_list
.rwlock
, flags
);
2128 static struct qeth_card
*qeth_l3_get_card_from_dev(struct net_device
*dev
)
2130 struct qeth_card
*card
= NULL
;
2133 rc
= qeth_l3_verify_dev(dev
);
2134 if (rc
== QETH_REAL_CARD
)
2135 card
= dev
->ml_priv
;
2136 else if (rc
== QETH_VLAN_CARD
)
2137 card
= vlan_dev_real_dev(dev
)->ml_priv
;
2138 if (card
&& card
->options
.layer2
)
2141 QETH_CARD_TEXT_(card
, 4, "%d", rc
);
2145 static int qeth_l3_stop_card(struct qeth_card
*card
, int recovery_mode
)
2149 QETH_DBF_TEXT(SETUP
, 2, "stopcard");
2150 QETH_DBF_HEX(SETUP
, 2, &card
, sizeof(void *));
2152 qeth_set_allowed_threads(card
, 0, 1);
2153 if (card
->options
.sniffer
&&
2154 (card
->info
.promisc_mode
== SET_PROMISC_MODE_ON
))
2155 qeth_diags_trace(card
, QETH_DIAGS_CMD_TRACE_DISABLE
);
2156 if (card
->read
.state
== CH_STATE_UP
&&
2157 card
->write
.state
== CH_STATE_UP
&&
2158 (card
->state
== CARD_STATE_UP
)) {
2160 qeth_l3_stop(card
->dev
);
2163 dev_close(card
->dev
);
2166 card
->state
= CARD_STATE_SOFTSETUP
;
2168 if (card
->state
== CARD_STATE_SOFTSETUP
) {
2169 qeth_l3_clear_ip_list(card
, 1);
2170 qeth_clear_ipacmd_list(card
);
2171 card
->state
= CARD_STATE_HARDSETUP
;
2173 if (card
->state
== CARD_STATE_HARDSETUP
) {
2174 qeth_qdio_clear_card(card
, 0);
2175 qeth_clear_qdio_buffers(card
);
2176 qeth_clear_working_pool_list(card
);
2177 card
->state
= CARD_STATE_DOWN
;
2179 if (card
->state
== CARD_STATE_DOWN
) {
2180 qeth_clear_cmd_buffers(&card
->read
);
2181 qeth_clear_cmd_buffers(&card
->write
);
2187 * test for and Switch promiscuous mode (on or off)
2188 * either for guestlan or HiperSocket Sniffer
2191 qeth_l3_handle_promisc_mode(struct qeth_card
*card
)
2193 struct net_device
*dev
= card
->dev
;
2195 if (((dev
->flags
& IFF_PROMISC
) &&
2196 (card
->info
.promisc_mode
== SET_PROMISC_MODE_ON
)) ||
2197 (!(dev
->flags
& IFF_PROMISC
) &&
2198 (card
->info
.promisc_mode
== SET_PROMISC_MODE_OFF
)))
2201 if (card
->info
.guestlan
) { /* Guestlan trace */
2202 if (qeth_adp_supported(card
, IPA_SETADP_SET_PROMISC_MODE
))
2203 qeth_setadp_promisc_mode(card
);
2204 } else if (card
->options
.sniffer
&& /* HiperSockets trace */
2205 qeth_adp_supported(card
, IPA_SETADP_SET_DIAG_ASSIST
)) {
2206 if (dev
->flags
& IFF_PROMISC
) {
2207 QETH_CARD_TEXT(card
, 3, "+promisc");
2208 qeth_diags_trace(card
, QETH_DIAGS_CMD_TRACE_ENABLE
);
2210 QETH_CARD_TEXT(card
, 3, "-promisc");
2211 qeth_diags_trace(card
, QETH_DIAGS_CMD_TRACE_DISABLE
);
2216 static void qeth_l3_set_multicast_list(struct net_device
*dev
)
2218 struct qeth_card
*card
= dev
->ml_priv
;
2220 QETH_CARD_TEXT(card
, 3, "setmulti");
2221 if (qeth_threads_running(card
, QETH_RECOVER_THREAD
) &&
2222 (card
->state
!= CARD_STATE_UP
))
2224 if (!card
->options
.sniffer
) {
2225 qeth_l3_delete_mc_addresses(card
);
2226 qeth_l3_add_multicast_ipv4(card
);
2227 #ifdef CONFIG_QETH_IPV6
2228 qeth_l3_add_multicast_ipv6(card
);
2230 qeth_l3_set_ip_addr_list(card
);
2231 if (!qeth_adp_supported(card
, IPA_SETADP_SET_PROMISC_MODE
))
2234 qeth_l3_handle_promisc_mode(card
);
2237 static const char *qeth_l3_arp_get_error_cause(int *rc
)
2240 case QETH_IPA_ARP_RC_FAILED
:
2242 return "operation failed";
2243 case QETH_IPA_ARP_RC_NOTSUPP
:
2245 return "operation not supported";
2246 case QETH_IPA_ARP_RC_OUT_OF_RANGE
:
2248 return "argument out of range";
2249 case QETH_IPA_ARP_RC_Q_NOTSUPP
:
2251 return "query operation not supported";
2252 case QETH_IPA_ARP_RC_Q_NO_DATA
:
2254 return "no query data available";
2256 return "unknown error";
2260 static int qeth_l3_arp_set_no_entries(struct qeth_card
*card
, int no_entries
)
2265 QETH_CARD_TEXT(card
, 3, "arpstnoe");
2268 * currently GuestLAN only supports the ARP assist function
2269 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_SET_NO_ENTRIES;
2270 * thus we say EOPNOTSUPP for this ARP function
2272 if (card
->info
.guestlan
)
2274 if (!qeth_is_supported(card
, IPA_ARP_PROCESSING
)) {
2277 rc
= qeth_l3_send_simple_setassparms(card
, IPA_ARP_PROCESSING
,
2278 IPA_CMD_ASS_ARP_SET_NO_ENTRIES
,
2282 QETH_DBF_MESSAGE(2, "Could not set number of ARP entries on "
2283 "%s: %s (0x%x/%d)\n", QETH_CARD_IFNAME(card
),
2284 qeth_l3_arp_get_error_cause(&rc
), tmp
, tmp
);
2289 static __u32
get_arp_entry_size(struct qeth_card
*card
,
2290 struct qeth_arp_query_data
*qdata
,
2291 struct qeth_arp_entrytype
*type
, __u8 strip_entries
)
2296 is_hsi
= qdata
->reply_bits
== 5;
2297 if (type
->ip
== QETHARP_IP_ADDR_V4
) {
2298 QETH_CARD_TEXT(card
, 4, "arpev4");
2299 if (strip_entries
) {
2300 rc
= is_hsi
? sizeof(struct qeth_arp_qi_entry5_short
) :
2301 sizeof(struct qeth_arp_qi_entry7_short
);
2303 rc
= is_hsi
? sizeof(struct qeth_arp_qi_entry5
) :
2304 sizeof(struct qeth_arp_qi_entry7
);
2306 } else if (type
->ip
== QETHARP_IP_ADDR_V6
) {
2307 QETH_CARD_TEXT(card
, 4, "arpev6");
2308 if (strip_entries
) {
2310 sizeof(struct qeth_arp_qi_entry5_short_ipv6
) :
2311 sizeof(struct qeth_arp_qi_entry7_short_ipv6
);
2314 sizeof(struct qeth_arp_qi_entry5_ipv6
) :
2315 sizeof(struct qeth_arp_qi_entry7_ipv6
);
2318 QETH_CARD_TEXT(card
, 4, "arpinv");
2325 static int arpentry_matches_prot(struct qeth_arp_entrytype
*type
, __u16 prot
)
2327 return (type
->ip
== QETHARP_IP_ADDR_V4
&& prot
== QETH_PROT_IPV4
) ||
2328 (type
->ip
== QETHARP_IP_ADDR_V6
&& prot
== QETH_PROT_IPV6
);
2331 static int qeth_l3_arp_query_cb(struct qeth_card
*card
,
2332 struct qeth_reply
*reply
, unsigned long data
)
2334 struct qeth_ipa_cmd
*cmd
;
2335 struct qeth_arp_query_data
*qdata
;
2336 struct qeth_arp_query_info
*qinfo
;
2339 int entrybytes_done
;
2341 __u8 do_strip_entries
;
2343 QETH_CARD_TEXT(card
, 3, "arpquecb");
2345 qinfo
= (struct qeth_arp_query_info
*) reply
->param
;
2346 cmd
= (struct qeth_ipa_cmd
*) data
;
2347 QETH_CARD_TEXT_(card
, 4, "%i", cmd
->hdr
.prot_version
);
2348 if (cmd
->hdr
.return_code
) {
2349 QETH_CARD_TEXT(card
, 4, "arpcberr");
2350 QETH_CARD_TEXT_(card
, 4, "%i", cmd
->hdr
.return_code
);
2353 if (cmd
->data
.setassparms
.hdr
.return_code
) {
2354 cmd
->hdr
.return_code
= cmd
->data
.setassparms
.hdr
.return_code
;
2355 QETH_CARD_TEXT(card
, 4, "setaperr");
2356 QETH_CARD_TEXT_(card
, 4, "%i", cmd
->hdr
.return_code
);
2359 qdata
= &cmd
->data
.setassparms
.data
.query_arp
;
2360 QETH_CARD_TEXT_(card
, 4, "anoen%i", qdata
->no_entries
);
2362 do_strip_entries
= (qinfo
->mask_bits
& QETH_QARP_STRIP_ENTRIES
) > 0;
2363 stripped_bytes
= do_strip_entries
? QETH_QARP_MEDIASPECIFIC_BYTES
: 0;
2364 entrybytes_done
= 0;
2365 for (e
= 0; e
< qdata
->no_entries
; ++e
) {
2368 struct qeth_arp_entrytype
*etype
;
2370 cur_entry
= &qdata
->data
+ entrybytes_done
;
2371 etype
= &((struct qeth_arp_qi_entry5
*) cur_entry
)->type
;
2372 if (!arpentry_matches_prot(etype
, cmd
->hdr
.prot_version
)) {
2373 QETH_CARD_TEXT(card
, 4, "pmis");
2374 QETH_CARD_TEXT_(card
, 4, "%i", etype
->ip
);
2377 esize
= get_arp_entry_size(card
, qdata
, etype
,
2379 QETH_CARD_TEXT_(card
, 5, "esz%i", esize
);
2383 if ((qinfo
->udata_len
- qinfo
->udata_offset
) < esize
) {
2384 QETH_CARD_TEXT_(card
, 4, "qaer3%i", -ENOMEM
);
2385 cmd
->hdr
.return_code
= IPA_RC_ENOMEM
;
2389 memcpy(qinfo
->udata
+ qinfo
->udata_offset
,
2390 &qdata
->data
+ entrybytes_done
+ stripped_bytes
,
2392 entrybytes_done
+= esize
+ stripped_bytes
;
2393 qinfo
->udata_offset
+= esize
;
2394 ++qinfo
->no_entries
;
2396 /* check if all replies received ... */
2397 if (cmd
->data
.setassparms
.hdr
.seq_no
<
2398 cmd
->data
.setassparms
.hdr
.number_of_replies
)
2400 QETH_CARD_TEXT_(card
, 4, "nove%i", qinfo
->no_entries
);
2401 memcpy(qinfo
->udata
, &qinfo
->no_entries
, 4);
2402 /* keep STRIP_ENTRIES flag so the user program can distinguish
2403 * stripped entries from normal ones */
2404 if (qinfo
->mask_bits
& QETH_QARP_STRIP_ENTRIES
)
2405 qdata
->reply_bits
|= QETH_QARP_STRIP_ENTRIES
;
2406 memcpy(qinfo
->udata
+ QETH_QARP_MASK_OFFSET
, &qdata
->reply_bits
, 2);
2407 QETH_CARD_TEXT_(card
, 4, "rc%i", 0);
2411 memcpy(qinfo
->udata
, &i
, 4);
2415 static int qeth_l3_send_ipa_arp_cmd(struct qeth_card
*card
,
2416 struct qeth_cmd_buffer
*iob
, int len
,
2417 int (*reply_cb
)(struct qeth_card
*, struct qeth_reply
*,
2421 QETH_CARD_TEXT(card
, 4, "sendarp");
2423 memcpy(iob
->data
, IPA_PDU_HEADER
, IPA_PDU_HEADER_SIZE
);
2424 memcpy(QETH_IPA_CMD_DEST_ADDR(iob
->data
),
2425 &card
->token
.ulp_connection_r
, QETH_MPC_TOKEN_LENGTH
);
2426 return qeth_send_control_data(card
, IPA_PDU_HEADER_SIZE
+ len
, iob
,
2427 reply_cb
, reply_param
);
2430 static int qeth_l3_query_arp_cache_info(struct qeth_card
*card
,
2431 enum qeth_prot_versions prot
,
2432 struct qeth_arp_query_info
*qinfo
)
2434 struct qeth_cmd_buffer
*iob
;
2435 struct qeth_ipa_cmd
*cmd
;
2439 QETH_CARD_TEXT_(card
, 3, "qarpipv%i", prot
);
2441 iob
= qeth_l3_get_setassparms_cmd(card
, IPA_ARP_PROCESSING
,
2442 IPA_CMD_ASS_ARP_QUERY_INFO
,
2443 sizeof(struct qeth_arp_query_data
) - sizeof(char),
2445 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
2446 cmd
->data
.setassparms
.data
.query_arp
.request_bits
= 0x000F;
2447 cmd
->data
.setassparms
.data
.query_arp
.reply_bits
= 0;
2448 cmd
->data
.setassparms
.data
.query_arp
.no_entries
= 0;
2449 rc
= qeth_l3_send_ipa_arp_cmd(card
, iob
,
2450 QETH_SETASS_BASE_LEN
+QETH_ARP_CMD_LEN
,
2451 qeth_l3_arp_query_cb
, (void *)qinfo
);
2455 "Error while querying ARP cache on %s: %s "
2456 "(0x%x/%d)\n", QETH_CARD_IFNAME(card
),
2457 qeth_l3_arp_get_error_cause(&rc
), tmp
, tmp
);
2463 static int qeth_l3_arp_query(struct qeth_card
*card
, char __user
*udata
)
2465 struct qeth_arp_query_info qinfo
= {0, };
2468 QETH_CARD_TEXT(card
, 3, "arpquery");
2470 if (!qeth_is_supported(card
,/*IPA_QUERY_ARP_ADDR_INFO*/
2471 IPA_ARP_PROCESSING
)) {
2472 QETH_CARD_TEXT(card
, 3, "arpqnsup");
2476 /* get size of userspace buffer and mask_bits -> 6 bytes */
2477 if (copy_from_user(&qinfo
, udata
, 6)) {
2481 qinfo
.udata
= kzalloc(qinfo
.udata_len
, GFP_KERNEL
);
2486 qinfo
.udata_offset
= QETH_QARP_ENTRIES_OFFSET
;
2487 rc
= qeth_l3_query_arp_cache_info(card
, QETH_PROT_IPV4
, &qinfo
);
2489 if (copy_to_user(udata
, qinfo
.udata
, 4))
2493 #ifdef CONFIG_QETH_IPV6
2494 if (qinfo
.mask_bits
& QETH_QARP_WITH_IPV6
) {
2495 /* fails in case of GuestLAN QDIO mode */
2496 qeth_l3_query_arp_cache_info(card
, QETH_PROT_IPV6
,
2500 if (copy_to_user(udata
, qinfo
.udata
, qinfo
.udata_len
)) {
2501 QETH_CARD_TEXT(card
, 4, "qactf");
2505 QETH_CARD_TEXT_(card
, 4, "qacts");
2513 static int qeth_l3_arp_add_entry(struct qeth_card
*card
,
2514 struct qeth_arp_cache_entry
*entry
)
2516 struct qeth_cmd_buffer
*iob
;
2521 QETH_CARD_TEXT(card
, 3, "arpadent");
2524 * currently GuestLAN only supports the ARP assist function
2525 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_ADD_ENTRY;
2526 * thus we say EOPNOTSUPP for this ARP function
2528 if (card
->info
.guestlan
)
2530 if (!qeth_is_supported(card
, IPA_ARP_PROCESSING
)) {
2534 iob
= qeth_l3_get_setassparms_cmd(card
, IPA_ARP_PROCESSING
,
2535 IPA_CMD_ASS_ARP_ADD_ENTRY
,
2536 sizeof(struct qeth_arp_cache_entry
),
2538 rc
= qeth_l3_send_setassparms(card
, iob
,
2539 sizeof(struct qeth_arp_cache_entry
),
2540 (unsigned long) entry
,
2541 qeth_l3_default_setassparms_cb
, NULL
);
2544 qeth_l3_ipaddr4_to_string((u8
*)entry
->ipaddr
, buf
);
2545 QETH_DBF_MESSAGE(2, "Could not add ARP entry for address %s "
2546 "on %s: %s (0x%x/%d)\n", buf
, QETH_CARD_IFNAME(card
),
2547 qeth_l3_arp_get_error_cause(&rc
), tmp
, tmp
);
2552 static int qeth_l3_arp_remove_entry(struct qeth_card
*card
,
2553 struct qeth_arp_cache_entry
*entry
)
2555 struct qeth_cmd_buffer
*iob
;
2556 char buf
[16] = {0, };
2560 QETH_CARD_TEXT(card
, 3, "arprment");
2563 * currently GuestLAN only supports the ARP assist function
2564 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_REMOVE_ENTRY;
2565 * thus we say EOPNOTSUPP for this ARP function
2567 if (card
->info
.guestlan
)
2569 if (!qeth_is_supported(card
, IPA_ARP_PROCESSING
)) {
2572 memcpy(buf
, entry
, 12);
2573 iob
= qeth_l3_get_setassparms_cmd(card
, IPA_ARP_PROCESSING
,
2574 IPA_CMD_ASS_ARP_REMOVE_ENTRY
,
2577 rc
= qeth_l3_send_setassparms(card
, iob
,
2578 12, (unsigned long)buf
,
2579 qeth_l3_default_setassparms_cb
, NULL
);
2583 qeth_l3_ipaddr4_to_string((u8
*)entry
->ipaddr
, buf
);
2584 QETH_DBF_MESSAGE(2, "Could not delete ARP entry for address %s"
2585 " on %s: %s (0x%x/%d)\n", buf
, QETH_CARD_IFNAME(card
),
2586 qeth_l3_arp_get_error_cause(&rc
), tmp
, tmp
);
2591 static int qeth_l3_arp_flush_cache(struct qeth_card
*card
)
2596 QETH_CARD_TEXT(card
, 3, "arpflush");
2599 * currently GuestLAN only supports the ARP assist function
2600 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_FLUSH_CACHE;
2601 * thus we say EOPNOTSUPP for this ARP function
2603 if (card
->info
.guestlan
|| (card
->info
.type
== QETH_CARD_TYPE_IQD
))
2605 if (!qeth_is_supported(card
, IPA_ARP_PROCESSING
)) {
2608 rc
= qeth_l3_send_simple_setassparms(card
, IPA_ARP_PROCESSING
,
2609 IPA_CMD_ASS_ARP_FLUSH_CACHE
, 0);
2612 QETH_DBF_MESSAGE(2, "Could not flush ARP cache on %s: %s "
2613 "(0x%x/%d)\n", QETH_CARD_IFNAME(card
),
2614 qeth_l3_arp_get_error_cause(&rc
), tmp
, tmp
);
2619 static int qeth_l3_do_ioctl(struct net_device
*dev
, struct ifreq
*rq
, int cmd
)
2621 struct qeth_card
*card
= dev
->ml_priv
;
2622 struct qeth_arp_cache_entry arp_entry
;
2623 struct mii_ioctl_data
*mii_data
;
2629 if ((card
->state
!= CARD_STATE_UP
) &&
2630 (card
->state
!= CARD_STATE_SOFTSETUP
))
2634 case SIOC_QETH_ARP_SET_NO_ENTRIES
:
2635 if (!capable(CAP_NET_ADMIN
)) {
2639 rc
= qeth_l3_arp_set_no_entries(card
, rq
->ifr_ifru
.ifru_ivalue
);
2641 case SIOC_QETH_ARP_QUERY_INFO
:
2642 if (!capable(CAP_NET_ADMIN
)) {
2646 rc
= qeth_l3_arp_query(card
, rq
->ifr_ifru
.ifru_data
);
2648 case SIOC_QETH_ARP_ADD_ENTRY
:
2649 if (!capable(CAP_NET_ADMIN
)) {
2653 if (copy_from_user(&arp_entry
, rq
->ifr_ifru
.ifru_data
,
2654 sizeof(struct qeth_arp_cache_entry
)))
2657 rc
= qeth_l3_arp_add_entry(card
, &arp_entry
);
2659 case SIOC_QETH_ARP_REMOVE_ENTRY
:
2660 if (!capable(CAP_NET_ADMIN
)) {
2664 if (copy_from_user(&arp_entry
, rq
->ifr_ifru
.ifru_data
,
2665 sizeof(struct qeth_arp_cache_entry
)))
2668 rc
= qeth_l3_arp_remove_entry(card
, &arp_entry
);
2670 case SIOC_QETH_ARP_FLUSH_CACHE
:
2671 if (!capable(CAP_NET_ADMIN
)) {
2675 rc
= qeth_l3_arp_flush_cache(card
);
2677 case SIOC_QETH_ADP_SET_SNMP_CONTROL
:
2678 rc
= qeth_snmp_command(card
, rq
->ifr_ifru
.ifru_data
);
2680 case SIOC_QETH_GET_CARD_TYPE
:
2681 if ((card
->info
.type
== QETH_CARD_TYPE_OSD
||
2682 card
->info
.type
== QETH_CARD_TYPE_OSX
) &&
2683 !card
->info
.guestlan
)
2688 mii_data
= if_mii(rq
);
2689 mii_data
->phy_id
= 0;
2692 mii_data
= if_mii(rq
);
2693 if (mii_data
->phy_id
!= 0)
2696 mii_data
->val_out
= qeth_mdio_read(dev
,
2700 case SIOC_QETH_QUERY_OAT
:
2701 rc
= qeth_query_oat_command(card
, rq
->ifr_ifru
.ifru_data
);
2707 QETH_CARD_TEXT_(card
, 2, "ioce%d", rc
);
2711 int inline qeth_l3_get_cast_type(struct qeth_card
*card
, struct sk_buff
*skb
)
2713 int cast_type
= RTN_UNSPEC
;
2714 struct neighbour
*n
= NULL
;
2715 struct dst_entry
*dst
;
2720 n
= dst_neigh_lookup_skb(dst
, skb
);
2722 cast_type
= n
->type
;
2725 if ((cast_type
== RTN_BROADCAST
) ||
2726 (cast_type
== RTN_MULTICAST
) ||
2727 (cast_type
== RTN_ANYCAST
))
2734 /* try something else */
2735 if (skb
->protocol
== ETH_P_IPV6
)
2736 return (skb_network_header(skb
)[24] == 0xff) ?
2738 else if (skb
->protocol
== ETH_P_IP
)
2739 return ((skb_network_header(skb
)[16] & 0xf0) == 0xe0) ?
2742 if (!memcmp(skb
->data
, skb
->dev
->broadcast
, 6))
2743 return RTN_BROADCAST
;
2747 hdr_mac
= *((u16
*)skb
->data
);
2749 switch (card
->info
.link_type
) {
2750 case QETH_LINK_TYPE_HSTR
:
2751 case QETH_LINK_TYPE_LANE_TR
:
2752 if ((hdr_mac
== QETH_TR_MAC_NC
) ||
2753 (hdr_mac
== QETH_TR_MAC_C
))
2754 return RTN_MULTICAST
;
2756 /* eth or so multicast? */
2758 if ((hdr_mac
== QETH_ETH_MAC_V4
) ||
2759 (hdr_mac
== QETH_ETH_MAC_V6
))
2760 return RTN_MULTICAST
;
2766 static void qeth_l3_fill_af_iucv_hdr(struct qeth_card
*card
,
2767 struct qeth_hdr
*hdr
, struct sk_buff
*skb
)
2770 struct af_iucv_trans_hdr
*iucv_hdr
;
2772 memset(hdr
, 0, sizeof(struct qeth_hdr
));
2773 hdr
->hdr
.l3
.id
= QETH_HEADER_TYPE_LAYER3
;
2774 hdr
->hdr
.l3
.ext_flags
= 0;
2775 hdr
->hdr
.l3
.length
= skb
->len
- ETH_HLEN
;
2776 hdr
->hdr
.l3
.flags
= QETH_HDR_IPV6
| QETH_CAST_UNICAST
;
2778 iucv_hdr
= (struct af_iucv_trans_hdr
*) (skb
->data
+ ETH_HLEN
);
2779 memset(daddr
, 0, sizeof(daddr
));
2782 memcpy(&daddr
[8], iucv_hdr
->destUserID
, 8);
2783 memcpy(hdr
->hdr
.l3
.dest_addr
, daddr
, 16);
2786 static void qeth_l3_fill_header(struct qeth_card
*card
, struct qeth_hdr
*hdr
,
2787 struct sk_buff
*skb
, int ipv
, int cast_type
)
2789 struct dst_entry
*dst
;
2791 memset(hdr
, 0, sizeof(struct qeth_hdr
));
2792 hdr
->hdr
.l3
.id
= QETH_HEADER_TYPE_LAYER3
;
2793 hdr
->hdr
.l3
.ext_flags
= 0;
2796 * before we're going to overwrite this location with next hop ip.
2797 * v6 uses passthrough, v4 sets the tag in the QDIO header.
2799 if (vlan_tx_tag_present(skb
)) {
2800 if ((ipv
== 4) || (card
->info
.type
== QETH_CARD_TYPE_IQD
))
2801 hdr
->hdr
.l3
.ext_flags
= QETH_HDR_EXT_VLAN_FRAME
;
2803 hdr
->hdr
.l3
.ext_flags
= QETH_HDR_EXT_INCLUDE_VLAN_TAG
;
2804 hdr
->hdr
.l3
.vlan_id
= vlan_tx_tag_get(skb
);
2807 hdr
->hdr
.l3
.length
= skb
->len
- sizeof(struct qeth_hdr
);
2812 struct rtable
*rt
= (struct rtable
*) dst
;
2813 __be32
*pkey
= &ip_hdr(skb
)->daddr
;
2816 pkey
= &rt
->rt_gateway
;
2819 hdr
->hdr
.l3
.flags
= qeth_l3_get_qeth_hdr_flags4(cast_type
);
2820 memset(hdr
->hdr
.l3
.dest_addr
, 0, 12);
2821 *((__be32
*) (&hdr
->hdr
.l3
.dest_addr
[12])) = *pkey
;
2822 } else if (ipv
== 6) {
2823 struct rt6_info
*rt
= (struct rt6_info
*) dst
;
2824 struct in6_addr
*pkey
= &ipv6_hdr(skb
)->daddr
;
2826 if (!ipv6_addr_any(&rt
->rt6i_gateway
))
2827 pkey
= &rt
->rt6i_gateway
;
2830 hdr
->hdr
.l3
.flags
= qeth_l3_get_qeth_hdr_flags6(cast_type
);
2831 if (card
->info
.type
== QETH_CARD_TYPE_IQD
)
2832 hdr
->hdr
.l3
.flags
&= ~QETH_HDR_PASSTHRU
;
2833 memcpy(hdr
->hdr
.l3
.dest_addr
, pkey
, 16);
2835 if (!memcmp(skb
->data
+ sizeof(struct qeth_hdr
),
2836 skb
->dev
->broadcast
, 6)) {
2838 hdr
->hdr
.l3
.flags
= QETH_CAST_BROADCAST
|
2841 hdr
->hdr
.l3
.flags
= (cast_type
== RTN_MULTICAST
) ?
2842 QETH_CAST_MULTICAST
| QETH_HDR_PASSTHRU
:
2843 QETH_CAST_UNICAST
| QETH_HDR_PASSTHRU
;
2849 static inline void qeth_l3_hdr_csum(struct qeth_card
*card
,
2850 struct qeth_hdr
*hdr
, struct sk_buff
*skb
)
2852 struct iphdr
*iph
= ip_hdr(skb
);
2854 /* tcph->check contains already the pseudo hdr checksum
2855 * so just set the header flags
2857 if (iph
->protocol
== IPPROTO_UDP
)
2858 hdr
->hdr
.l3
.ext_flags
|= QETH_HDR_EXT_UDP
;
2859 hdr
->hdr
.l3
.ext_flags
|= QETH_HDR_EXT_CSUM_TRANSP_REQ
|
2860 QETH_HDR_EXT_CSUM_HDR_REQ
;
2862 if (card
->options
.performance_stats
)
2863 card
->perf_stats
.tx_csum
++;
2866 static void qeth_tso_fill_header(struct qeth_card
*card
,
2867 struct qeth_hdr
*qhdr
, struct sk_buff
*skb
)
2869 struct qeth_hdr_tso
*hdr
= (struct qeth_hdr_tso
*)qhdr
;
2870 struct tcphdr
*tcph
= tcp_hdr(skb
);
2871 struct iphdr
*iph
= ip_hdr(skb
);
2872 struct ipv6hdr
*ip6h
= ipv6_hdr(skb
);
2874 /*fix header to TSO values ...*/
2875 hdr
->hdr
.hdr
.l3
.id
= QETH_HEADER_TYPE_TSO
;
2876 hdr
->hdr
.hdr
.l3
.length
= skb
->len
- sizeof(struct qeth_hdr_tso
);
2877 /*set values which are fix for the first approach ...*/
2878 hdr
->ext
.hdr_tot_len
= (__u16
) sizeof(struct qeth_hdr_ext_tso
);
2879 hdr
->ext
.imb_hdr_no
= 1;
2880 hdr
->ext
.hdr_type
= 1;
2881 hdr
->ext
.hdr_version
= 1;
2882 hdr
->ext
.hdr_len
= 28;
2883 /*insert non-fix values */
2884 hdr
->ext
.mss
= skb_shinfo(skb
)->gso_size
;
2885 hdr
->ext
.dg_hdr_len
= (__u16
)(iph
->ihl
*4 + tcph
->doff
*4);
2886 hdr
->ext
.payload_len
= (__u16
)(skb
->len
- hdr
->ext
.dg_hdr_len
-
2887 sizeof(struct qeth_hdr_tso
));
2889 if (skb
->protocol
== ETH_P_IPV6
) {
2890 ip6h
->payload_len
= 0;
2891 tcph
->check
= ~csum_ipv6_magic(&ip6h
->saddr
, &ip6h
->daddr
,
2894 /*OSA want us to set these values ...*/
2895 tcph
->check
= ~csum_tcpudp_magic(iph
->saddr
, iph
->daddr
,
2902 static inline int qeth_l3_tso_elements(struct sk_buff
*skb
)
2904 unsigned long tcpd
= (unsigned long)tcp_hdr(skb
) +
2905 tcp_hdr(skb
)->doff
* 4;
2906 int tcpd_len
= skb
->len
- (tcpd
- (unsigned long)skb
->data
);
2907 int elements
= PFN_UP(tcpd
+ tcpd_len
- 1) - PFN_DOWN(tcpd
);
2909 elements
+= qeth_get_elements_for_frags(skb
);
2914 static int qeth_l3_hard_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
2918 struct qeth_hdr
*hdr
= NULL
;
2919 int elements_needed
= 0;
2921 struct qeth_card
*card
= dev
->ml_priv
;
2922 struct sk_buff
*new_skb
= NULL
;
2923 int ipv
= qeth_get_ip_version(skb
);
2924 int cast_type
= qeth_l3_get_cast_type(card
, skb
);
2925 struct qeth_qdio_out_q
*queue
=
2926 card
->qdio
.out_qs
[card
->qdio
.do_prio_queueing
2927 || (cast_type
&& card
->info
.is_multicast_different
) ?
2928 qeth_get_priority_queue(card
, skb
, ipv
, cast_type
) :
2929 card
->qdio
.default_out_queue
];
2930 int tx_bytes
= skb
->len
;
2932 int data_offset
= -1;
2935 if (((card
->info
.type
== QETH_CARD_TYPE_IQD
) &&
2936 (((card
->options
.cq
!= QETH_CQ_ENABLED
) && !ipv
) ||
2937 ((card
->options
.cq
== QETH_CQ_ENABLED
) &&
2938 (skb
->protocol
!= ETH_P_AF_IUCV
)))) ||
2939 card
->options
.sniffer
)
2942 if ((card
->state
!= CARD_STATE_UP
) || !card
->lan_online
) {
2943 card
->stats
.tx_carrier_errors
++;
2947 if ((cast_type
== RTN_BROADCAST
) &&
2948 (card
->info
.broadcast_capable
== 0))
2951 if (card
->options
.performance_stats
) {
2952 card
->perf_stats
.outbound_cnt
++;
2953 card
->perf_stats
.outbound_start_time
= qeth_get_micros();
2956 large_send
= skb_is_gso(skb
);
2958 if ((card
->info
.type
== QETH_CARD_TYPE_IQD
) && (!large_send
) &&
2959 (skb_shinfo(skb
)->nr_frags
== 0)) {
2961 data_offset
= ETH_HLEN
;
2962 hdr
= kmem_cache_alloc(qeth_core_header_cache
, GFP_ATOMIC
);
2967 /* create a clone with writeable headroom */
2968 new_skb
= skb_realloc_headroom(skb
, sizeof(struct qeth_hdr_tso
)
2974 if (card
->info
.type
== QETH_CARD_TYPE_IQD
) {
2975 if (data_offset
< 0)
2976 skb_pull(new_skb
, ETH_HLEN
);
2979 skb_pull(new_skb
, ETH_HLEN
);
2982 if (ipv
!= 4 && vlan_tx_tag_present(new_skb
)) {
2983 skb_push(new_skb
, VLAN_HLEN
);
2984 skb_copy_to_linear_data(new_skb
, new_skb
->data
+ 4, 4);
2985 skb_copy_to_linear_data_offset(new_skb
, 4,
2986 new_skb
->data
+ 8, 4);
2987 skb_copy_to_linear_data_offset(new_skb
, 8,
2988 new_skb
->data
+ 12, 4);
2989 tag
= (u16
*)(new_skb
->data
+ 12);
2990 *tag
= __constant_htons(ETH_P_8021Q
);
2991 *(tag
+ 1) = htons(vlan_tx_tag_get(new_skb
));
2995 netif_stop_queue(dev
);
2997 /* fix hardware limitation: as long as we do not have sbal
2998 * chaining we can not send long frag lists
3001 if (qeth_l3_tso_elements(new_skb
) + 1 > 16) {
3002 if (skb_linearize(new_skb
))
3004 if (card
->options
.performance_stats
)
3005 card
->perf_stats
.tx_lin
++;
3009 if (large_send
&& (cast_type
== RTN_UNSPEC
)) {
3010 hdr
= (struct qeth_hdr
*)skb_push(new_skb
,
3011 sizeof(struct qeth_hdr_tso
));
3012 memset(hdr
, 0, sizeof(struct qeth_hdr_tso
));
3013 qeth_l3_fill_header(card
, hdr
, new_skb
, ipv
, cast_type
);
3014 qeth_tso_fill_header(card
, hdr
, new_skb
);
3017 if (data_offset
< 0) {
3018 hdr
= (struct qeth_hdr
*)skb_push(new_skb
,
3019 sizeof(struct qeth_hdr
));
3020 qeth_l3_fill_header(card
, hdr
, new_skb
, ipv
,
3023 if (new_skb
->protocol
== ETH_P_AF_IUCV
)
3024 qeth_l3_fill_af_iucv_hdr(card
, hdr
, new_skb
);
3026 qeth_l3_fill_header(card
, hdr
, new_skb
, ipv
,
3028 hdr
->hdr
.l3
.length
= new_skb
->len
- data_offset
;
3032 if (skb
->ip_summed
== CHECKSUM_PARTIAL
)
3033 qeth_l3_hdr_csum(card
, hdr
, new_skb
);
3036 elems
= qeth_get_elements_no(card
, new_skb
, elements_needed
);
3038 if (data_offset
>= 0)
3039 kmem_cache_free(qeth_core_header_cache
, hdr
);
3042 elements_needed
+= elems
;
3043 nr_frags
= skb_shinfo(new_skb
)->nr_frags
;
3045 if (card
->info
.type
!= QETH_CARD_TYPE_IQD
) {
3048 len
= ((unsigned long)tcp_hdr(new_skb
) +
3049 tcp_hdr(new_skb
)->doff
* 4) -
3050 (unsigned long)new_skb
->data
;
3052 len
= sizeof(struct qeth_hdr_layer3
);
3054 if (qeth_hdr_chk_and_bounce(new_skb
, &hdr
, len
))
3056 rc
= qeth_do_send_packet(card
, queue
, new_skb
, hdr
,
3059 rc
= qeth_do_send_packet_fast(card
, queue
, new_skb
, hdr
,
3060 elements_needed
, data_offset
, 0);
3063 card
->stats
.tx_packets
++;
3064 card
->stats
.tx_bytes
+= tx_bytes
;
3066 dev_kfree_skb_any(skb
);
3067 if (card
->options
.performance_stats
) {
3069 card
->perf_stats
.large_send_bytes
+= tx_bytes
;
3070 card
->perf_stats
.large_send_cnt
++;
3073 card
->perf_stats
.sg_skbs_sent
++;
3074 /* nr_frags + skb->data */
3075 card
->perf_stats
.sg_frags_sent
+= nr_frags
+ 1;
3080 if (data_offset
>= 0)
3081 kmem_cache_free(qeth_core_header_cache
, hdr
);
3085 dev_kfree_skb_any(new_skb
);
3086 return NETDEV_TX_BUSY
;
3091 netif_wake_queue(dev
);
3092 if (card
->options
.performance_stats
)
3093 card
->perf_stats
.outbound_time
+= qeth_get_micros() -
3094 card
->perf_stats
.outbound_start_time
;
3098 card
->stats
.tx_dropped
++;
3099 card
->stats
.tx_errors
++;
3100 if ((new_skb
!= skb
) && new_skb
)
3101 dev_kfree_skb_any(new_skb
);
3102 dev_kfree_skb_any(skb
);
3103 netif_wake_queue(dev
);
3104 return NETDEV_TX_OK
;
3107 static int __qeth_l3_open(struct net_device
*dev
)
3109 struct qeth_card
*card
= dev
->ml_priv
;
3112 QETH_CARD_TEXT(card
, 4, "qethopen");
3113 if (card
->state
== CARD_STATE_UP
)
3115 if (card
->state
!= CARD_STATE_SOFTSETUP
)
3117 card
->data
.state
= CH_STATE_UP
;
3118 card
->state
= CARD_STATE_UP
;
3119 netif_start_queue(dev
);
3121 if (qdio_stop_irq(card
->data
.ccwdev
, 0) >= 0) {
3122 napi_enable(&card
->napi
);
3123 napi_schedule(&card
->napi
);
3129 static int qeth_l3_open(struct net_device
*dev
)
3131 struct qeth_card
*card
= dev
->ml_priv
;
3133 QETH_CARD_TEXT(card
, 5, "qethope_");
3134 if (qeth_wait_for_threads(card
, QETH_RECOVER_THREAD
)) {
3135 QETH_CARD_TEXT(card
, 3, "openREC");
3136 return -ERESTARTSYS
;
3138 return __qeth_l3_open(dev
);
3141 static int qeth_l3_stop(struct net_device
*dev
)
3143 struct qeth_card
*card
= dev
->ml_priv
;
3145 QETH_CARD_TEXT(card
, 4, "qethstop");
3146 netif_tx_disable(dev
);
3147 if (card
->state
== CARD_STATE_UP
) {
3148 card
->state
= CARD_STATE_SOFTSETUP
;
3149 napi_disable(&card
->napi
);
3154 static netdev_features_t
qeth_l3_fix_features(struct net_device
*dev
,
3155 netdev_features_t features
)
3157 struct qeth_card
*card
= dev
->ml_priv
;
3159 if (!qeth_is_supported(card
, IPA_OUTBOUND_CHECKSUM
))
3160 features
&= ~NETIF_F_IP_CSUM
;
3161 if (!qeth_is_supported(card
, IPA_OUTBOUND_TSO
))
3162 features
&= ~NETIF_F_TSO
;
3163 if (!qeth_is_supported(card
, IPA_INBOUND_CHECKSUM
))
3164 features
&= ~NETIF_F_RXCSUM
;
3169 static int qeth_l3_set_features(struct net_device
*dev
,
3170 netdev_features_t features
)
3172 struct qeth_card
*card
= dev
->ml_priv
;
3173 u32 changed
= dev
->features
^ features
;
3176 if (!(changed
& NETIF_F_RXCSUM
))
3179 if (card
->state
== CARD_STATE_DOWN
||
3180 card
->state
== CARD_STATE_RECOVER
)
3183 err
= qeth_l3_set_rx_csum(card
, features
& NETIF_F_RXCSUM
);
3185 dev
->features
= features
^ NETIF_F_RXCSUM
;
3190 static const struct ethtool_ops qeth_l3_ethtool_ops
= {
3191 .get_link
= ethtool_op_get_link
,
3192 .get_strings
= qeth_core_get_strings
,
3193 .get_ethtool_stats
= qeth_core_get_ethtool_stats
,
3194 .get_sset_count
= qeth_core_get_sset_count
,
3195 .get_drvinfo
= qeth_core_get_drvinfo
,
3196 .get_settings
= qeth_core_ethtool_get_settings
,
3200 * we need NOARP for IPv4 but we want neighbor solicitation for IPv6. Setting
3201 * NOARP on the netdevice is no option because it also turns off neighbor
3202 * solicitation. For IPv4 we install a neighbor_setup function. We don't want
3203 * arp resolution but we want the hard header (packet socket will work
3206 static int qeth_l3_neigh_setup_noarp(struct neighbour
*n
)
3208 n
->nud_state
= NUD_NOARP
;
3209 memcpy(n
->ha
, "FAKELL", 6);
3210 n
->output
= n
->ops
->connected_output
;
3215 qeth_l3_neigh_setup(struct net_device
*dev
, struct neigh_parms
*np
)
3217 if (np
->tbl
->family
== AF_INET
)
3218 np
->neigh_setup
= qeth_l3_neigh_setup_noarp
;
3223 static const struct net_device_ops qeth_l3_netdev_ops
= {
3224 .ndo_open
= qeth_l3_open
,
3225 .ndo_stop
= qeth_l3_stop
,
3226 .ndo_get_stats
= qeth_get_stats
,
3227 .ndo_start_xmit
= qeth_l3_hard_start_xmit
,
3228 .ndo_validate_addr
= eth_validate_addr
,
3229 .ndo_set_rx_mode
= qeth_l3_set_multicast_list
,
3230 .ndo_do_ioctl
= qeth_l3_do_ioctl
,
3231 .ndo_change_mtu
= qeth_change_mtu
,
3232 .ndo_fix_features
= qeth_l3_fix_features
,
3233 .ndo_set_features
= qeth_l3_set_features
,
3234 .ndo_vlan_rx_add_vid
= qeth_l3_vlan_rx_add_vid
,
3235 .ndo_vlan_rx_kill_vid
= qeth_l3_vlan_rx_kill_vid
,
3236 .ndo_tx_timeout
= qeth_tx_timeout
,
3239 static const struct net_device_ops qeth_l3_osa_netdev_ops
= {
3240 .ndo_open
= qeth_l3_open
,
3241 .ndo_stop
= qeth_l3_stop
,
3242 .ndo_get_stats
= qeth_get_stats
,
3243 .ndo_start_xmit
= qeth_l3_hard_start_xmit
,
3244 .ndo_validate_addr
= eth_validate_addr
,
3245 .ndo_set_rx_mode
= qeth_l3_set_multicast_list
,
3246 .ndo_do_ioctl
= qeth_l3_do_ioctl
,
3247 .ndo_change_mtu
= qeth_change_mtu
,
3248 .ndo_fix_features
= qeth_l3_fix_features
,
3249 .ndo_set_features
= qeth_l3_set_features
,
3250 .ndo_vlan_rx_add_vid
= qeth_l3_vlan_rx_add_vid
,
3251 .ndo_vlan_rx_kill_vid
= qeth_l3_vlan_rx_kill_vid
,
3252 .ndo_tx_timeout
= qeth_tx_timeout
,
3253 .ndo_neigh_setup
= qeth_l3_neigh_setup
,
3256 static int qeth_l3_setup_netdev(struct qeth_card
*card
)
3258 if (card
->info
.type
== QETH_CARD_TYPE_OSD
||
3259 card
->info
.type
== QETH_CARD_TYPE_OSX
) {
3260 if ((card
->info
.link_type
== QETH_LINK_TYPE_LANE_TR
) ||
3261 (card
->info
.link_type
== QETH_LINK_TYPE_HSTR
)) {
3262 pr_info("qeth_l3: ignoring TR device\n");
3265 card
->dev
= alloc_etherdev(0);
3268 card
->dev
->netdev_ops
= &qeth_l3_osa_netdev_ops
;
3270 /*IPv6 address autoconfiguration stuff*/
3271 qeth_l3_get_unique_id(card
);
3272 if (!(card
->info
.unique_id
& UNIQUE_ID_NOT_BY_CARD
))
3273 card
->dev
->dev_id
= card
->info
.unique_id
&
3275 if (!card
->info
.guestlan
) {
3276 card
->dev
->hw_features
= NETIF_F_SG
|
3277 NETIF_F_RXCSUM
| NETIF_F_IP_CSUM
|
3279 card
->dev
->features
= NETIF_F_RXCSUM
;
3282 } else if (card
->info
.type
== QETH_CARD_TYPE_IQD
) {
3283 card
->dev
= alloc_netdev(0, "hsi%d", NET_NAME_UNKNOWN
,
3287 card
->dev
->flags
|= IFF_NOARP
;
3288 card
->dev
->netdev_ops
= &qeth_l3_netdev_ops
;
3289 qeth_l3_iqd_read_initial_mac(card
);
3290 if (card
->options
.hsuid
[0])
3291 memcpy(card
->dev
->perm_addr
, card
->options
.hsuid
, 9);
3295 card
->dev
->ml_priv
= card
;
3296 card
->dev
->watchdog_timeo
= QETH_TX_TIMEOUT
;
3297 card
->dev
->mtu
= card
->info
.initial_mtu
;
3298 card
->dev
->ethtool_ops
= &qeth_l3_ethtool_ops
;
3299 card
->dev
->features
|= NETIF_F_HW_VLAN_CTAG_TX
|
3300 NETIF_F_HW_VLAN_CTAG_RX
|
3301 NETIF_F_HW_VLAN_CTAG_FILTER
;
3302 netif_keep_dst(card
->dev
);
3303 card
->dev
->gso_max_size
= 15 * PAGE_SIZE
;
3305 SET_NETDEV_DEV(card
->dev
, &card
->gdev
->dev
);
3306 netif_napi_add(card
->dev
, &card
->napi
, qeth_l3_poll
, QETH_NAPI_WEIGHT
);
3307 return register_netdev(card
->dev
);
3310 static int qeth_l3_probe_device(struct ccwgroup_device
*gdev
)
3312 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
3315 rc
= qeth_l3_create_device_attributes(&gdev
->dev
);
3318 card
->options
.layer2
= 0;
3319 card
->info
.hwtrap
= 0;
3323 static void qeth_l3_remove_device(struct ccwgroup_device
*cgdev
)
3325 struct qeth_card
*card
= dev_get_drvdata(&cgdev
->dev
);
3327 qeth_l3_remove_device_attributes(&cgdev
->dev
);
3329 qeth_set_allowed_threads(card
, 0, 1);
3330 wait_event(card
->wait_q
, qeth_threads_running(card
, 0xffffffff) == 0);
3332 if (cgdev
->state
== CCWGROUP_ONLINE
)
3333 qeth_l3_set_offline(cgdev
);
3336 unregister_netdev(card
->dev
);
3337 free_netdev(card
->dev
);
3341 qeth_l3_clear_ip_list(card
, 0);
3342 qeth_l3_clear_ipato_list(card
);
3346 static int __qeth_l3_set_online(struct ccwgroup_device
*gdev
, int recovery_mode
)
3348 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
3350 enum qeth_card_states recover_flag
;
3352 mutex_lock(&card
->discipline_mutex
);
3353 mutex_lock(&card
->conf_mutex
);
3354 QETH_DBF_TEXT(SETUP
, 2, "setonlin");
3355 QETH_DBF_HEX(SETUP
, 2, &card
, sizeof(void *));
3357 recover_flag
= card
->state
;
3358 rc
= qeth_core_hardsetup_card(card
);
3360 QETH_DBF_TEXT_(SETUP
, 2, "2err%d", rc
);
3365 if (!card
->dev
&& qeth_l3_setup_netdev(card
)) {
3370 if (qeth_is_diagass_supported(card
, QETH_DIAGS_CMD_TRAP
)) {
3371 if (card
->info
.hwtrap
&&
3372 qeth_hw_trap(card
, QETH_DIAGS_TRAP_ARM
))
3373 card
->info
.hwtrap
= 0;
3375 card
->info
.hwtrap
= 0;
3377 card
->state
= CARD_STATE_HARDSETUP
;
3378 memset(&card
->rx
, 0, sizeof(struct qeth_rx
));
3379 qeth_print_status_message(card
);
3382 QETH_DBF_TEXT(SETUP
, 2, "softsetp");
3384 rc
= qeth_send_startlan(card
);
3386 QETH_DBF_TEXT_(SETUP
, 2, "1err%d", rc
);
3388 dev_warn(&card
->gdev
->dev
,
3389 "The LAN is offline\n");
3390 card
->lan_online
= 0;
3396 card
->lan_online
= 1;
3399 rc
= qeth_l3_setadapter_parms(card
);
3401 QETH_DBF_TEXT_(SETUP
, 2, "2err%d", rc
);
3402 if (!card
->options
.sniffer
) {
3403 rc
= qeth_l3_start_ipassists(card
);
3405 QETH_DBF_TEXT_(SETUP
, 2, "3err%d", rc
);
3408 rc
= qeth_l3_setrouting_v4(card
);
3410 QETH_DBF_TEXT_(SETUP
, 2, "4err%d", rc
);
3411 rc
= qeth_l3_setrouting_v6(card
);
3413 QETH_DBF_TEXT_(SETUP
, 2, "5err%d", rc
);
3415 netif_tx_disable(card
->dev
);
3417 rc
= qeth_init_qdio_queues(card
);
3419 QETH_DBF_TEXT_(SETUP
, 2, "6err%d", rc
);
3423 card
->state
= CARD_STATE_SOFTSETUP
;
3425 qeth_set_allowed_threads(card
, 0xffffffff, 0);
3426 qeth_l3_set_ip_addr_list(card
);
3427 if (card
->lan_online
)
3428 netif_carrier_on(card
->dev
);
3430 netif_carrier_off(card
->dev
);
3431 if (recover_flag
== CARD_STATE_RECOVER
) {
3434 __qeth_l3_open(card
->dev
);
3436 dev_open(card
->dev
);
3437 qeth_l3_set_multicast_list(card
->dev
);
3440 qeth_trace_features(card
);
3441 /* let user_space know that device is online */
3442 kobject_uevent(&gdev
->dev
.kobj
, KOBJ_CHANGE
);
3443 mutex_unlock(&card
->conf_mutex
);
3444 mutex_unlock(&card
->discipline_mutex
);
3447 qeth_l3_stop_card(card
, 0);
3448 ccw_device_set_offline(CARD_DDEV(card
));
3449 ccw_device_set_offline(CARD_WDEV(card
));
3450 ccw_device_set_offline(CARD_RDEV(card
));
3451 qdio_free(CARD_DDEV(card
));
3452 if (recover_flag
== CARD_STATE_RECOVER
)
3453 card
->state
= CARD_STATE_RECOVER
;
3455 card
->state
= CARD_STATE_DOWN
;
3456 mutex_unlock(&card
->conf_mutex
);
3457 mutex_unlock(&card
->discipline_mutex
);
3461 static int qeth_l3_set_online(struct ccwgroup_device
*gdev
)
3463 return __qeth_l3_set_online(gdev
, 0);
3466 static int __qeth_l3_set_offline(struct ccwgroup_device
*cgdev
,
3469 struct qeth_card
*card
= dev_get_drvdata(&cgdev
->dev
);
3470 int rc
= 0, rc2
= 0, rc3
= 0;
3471 enum qeth_card_states recover_flag
;
3473 mutex_lock(&card
->discipline_mutex
);
3474 mutex_lock(&card
->conf_mutex
);
3475 QETH_DBF_TEXT(SETUP
, 3, "setoffl");
3476 QETH_DBF_HEX(SETUP
, 3, &card
, sizeof(void *));
3478 if (card
->dev
&& netif_carrier_ok(card
->dev
))
3479 netif_carrier_off(card
->dev
);
3480 recover_flag
= card
->state
;
3481 if ((!recovery_mode
&& card
->info
.hwtrap
) || card
->info
.hwtrap
== 2) {
3482 qeth_hw_trap(card
, QETH_DIAGS_TRAP_DISARM
);
3483 card
->info
.hwtrap
= 1;
3485 qeth_l3_stop_card(card
, recovery_mode
);
3486 if ((card
->options
.cq
== QETH_CQ_ENABLED
) && card
->dev
) {
3488 call_netdevice_notifiers(NETDEV_REBOOT
, card
->dev
);
3491 rc
= ccw_device_set_offline(CARD_DDEV(card
));
3492 rc2
= ccw_device_set_offline(CARD_WDEV(card
));
3493 rc3
= ccw_device_set_offline(CARD_RDEV(card
));
3495 rc
= (rc2
) ? rc2
: rc3
;
3497 QETH_DBF_TEXT_(SETUP
, 2, "1err%d", rc
);
3498 qdio_free(CARD_DDEV(card
));
3499 if (recover_flag
== CARD_STATE_UP
)
3500 card
->state
= CARD_STATE_RECOVER
;
3501 /* let user_space know that device is offline */
3502 kobject_uevent(&cgdev
->dev
.kobj
, KOBJ_CHANGE
);
3503 mutex_unlock(&card
->conf_mutex
);
3504 mutex_unlock(&card
->discipline_mutex
);
3508 static int qeth_l3_set_offline(struct ccwgroup_device
*cgdev
)
3510 return __qeth_l3_set_offline(cgdev
, 0);
3513 static int qeth_l3_recover(void *ptr
)
3515 struct qeth_card
*card
;
3518 card
= (struct qeth_card
*) ptr
;
3519 QETH_CARD_TEXT(card
, 2, "recover1");
3520 QETH_CARD_HEX(card
, 2, &card
, sizeof(void *));
3521 if (!qeth_do_run_thread(card
, QETH_RECOVER_THREAD
))
3523 QETH_CARD_TEXT(card
, 2, "recover2");
3524 dev_warn(&card
->gdev
->dev
,
3525 "A recovery process has been started for the device\n");
3526 qeth_set_recovery_task(card
);
3527 __qeth_l3_set_offline(card
->gdev
, 1);
3528 rc
= __qeth_l3_set_online(card
->gdev
, 1);
3530 dev_info(&card
->gdev
->dev
,
3531 "Device successfully recovered!\n");
3533 qeth_close_dev(card
);
3534 dev_warn(&card
->gdev
->dev
, "The qeth device driver "
3535 "failed to recover an error on the device\n");
3537 qeth_clear_recovery_task(card
);
3538 qeth_clear_thread_start_bit(card
, QETH_RECOVER_THREAD
);
3539 qeth_clear_thread_running_bit(card
, QETH_RECOVER_THREAD
);
3543 static void qeth_l3_shutdown(struct ccwgroup_device
*gdev
)
3545 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
3546 qeth_set_allowed_threads(card
, 0, 1);
3547 if ((gdev
->state
== CCWGROUP_ONLINE
) && card
->info
.hwtrap
)
3548 qeth_hw_trap(card
, QETH_DIAGS_TRAP_DISARM
);
3549 qeth_qdio_clear_card(card
, 0);
3550 qeth_clear_qdio_buffers(card
);
3551 qdio_free(CARD_DDEV(card
));
3554 static int qeth_l3_pm_suspend(struct ccwgroup_device
*gdev
)
3556 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
3559 netif_device_detach(card
->dev
);
3560 qeth_set_allowed_threads(card
, 0, 1);
3561 wait_event(card
->wait_q
, qeth_threads_running(card
, 0xffffffff) == 0);
3562 if (gdev
->state
== CCWGROUP_OFFLINE
)
3564 if (card
->state
== CARD_STATE_UP
) {
3565 if (card
->info
.hwtrap
)
3566 qeth_hw_trap(card
, QETH_DIAGS_TRAP_DISARM
);
3567 __qeth_l3_set_offline(card
->gdev
, 1);
3569 __qeth_l3_set_offline(card
->gdev
, 0);
3573 static int qeth_l3_pm_resume(struct ccwgroup_device
*gdev
)
3575 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
3578 if (gdev
->state
== CCWGROUP_OFFLINE
)
3581 if (card
->state
== CARD_STATE_RECOVER
) {
3582 rc
= __qeth_l3_set_online(card
->gdev
, 1);
3585 dev_close(card
->dev
);
3589 rc
= __qeth_l3_set_online(card
->gdev
, 0);
3591 qeth_set_allowed_threads(card
, 0xffffffff, 0);
3593 netif_device_attach(card
->dev
);
3595 dev_warn(&card
->gdev
->dev
, "The qeth device driver "
3596 "failed to recover an error on the device\n");
3600 /* Returns zero if the command is successfully "consumed" */
3601 static int qeth_l3_control_event(struct qeth_card
*card
,
3602 struct qeth_ipa_cmd
*cmd
)
3607 struct qeth_discipline qeth_l3_discipline
= {
3608 .devtype
= &qeth_generic_devtype
,
3609 .start_poll
= qeth_qdio_start_poll
,
3610 .input_handler
= (qdio_handler_t
*) qeth_qdio_input_handler
,
3611 .output_handler
= (qdio_handler_t
*) qeth_qdio_output_handler
,
3612 .recover
= qeth_l3_recover
,
3613 .setup
= qeth_l3_probe_device
,
3614 .remove
= qeth_l3_remove_device
,
3615 .set_online
= qeth_l3_set_online
,
3616 .set_offline
= qeth_l3_set_offline
,
3617 .shutdown
= qeth_l3_shutdown
,
3618 .freeze
= qeth_l3_pm_suspend
,
3619 .thaw
= qeth_l3_pm_resume
,
3620 .restore
= qeth_l3_pm_resume
,
3621 .control_event_handler
= qeth_l3_control_event
,
3623 EXPORT_SYMBOL_GPL(qeth_l3_discipline
);
3625 static int qeth_l3_ip_event(struct notifier_block
*this,
3626 unsigned long event
, void *ptr
)
3628 struct in_ifaddr
*ifa
= (struct in_ifaddr
*)ptr
;
3629 struct net_device
*dev
= (struct net_device
*)ifa
->ifa_dev
->dev
;
3630 struct qeth_ipaddr
*addr
;
3631 struct qeth_card
*card
;
3633 if (dev_net(dev
) != &init_net
)
3636 card
= qeth_l3_get_card_from_dev(dev
);
3639 QETH_CARD_TEXT(card
, 3, "ipevent");
3641 addr
= qeth_l3_get_addr_buffer(QETH_PROT_IPV4
);
3643 addr
->u
.a4
.addr
= ifa
->ifa_address
;
3644 addr
->u
.a4
.mask
= ifa
->ifa_mask
;
3645 addr
->type
= QETH_IP_TYPE_NORMAL
;
3651 if (!qeth_l3_add_ip(card
, addr
))
3655 if (!qeth_l3_delete_ip(card
, addr
))
3661 qeth_l3_set_ip_addr_list(card
);
3666 static struct notifier_block qeth_l3_ip_notifier
= {
3671 #ifdef CONFIG_QETH_IPV6
3673 * IPv6 event handler
3675 static int qeth_l3_ip6_event(struct notifier_block
*this,
3676 unsigned long event
, void *ptr
)
3678 struct inet6_ifaddr
*ifa
= (struct inet6_ifaddr
*)ptr
;
3679 struct net_device
*dev
= (struct net_device
*)ifa
->idev
->dev
;
3680 struct qeth_ipaddr
*addr
;
3681 struct qeth_card
*card
;
3683 card
= qeth_l3_get_card_from_dev(dev
);
3686 QETH_CARD_TEXT(card
, 3, "ip6event");
3687 if (!qeth_is_supported(card
, IPA_IPV6
))
3690 addr
= qeth_l3_get_addr_buffer(QETH_PROT_IPV6
);
3692 memcpy(&addr
->u
.a6
.addr
, &ifa
->addr
, sizeof(struct in6_addr
));
3693 addr
->u
.a6
.pfxlen
= ifa
->prefix_len
;
3694 addr
->type
= QETH_IP_TYPE_NORMAL
;
3700 if (!qeth_l3_add_ip(card
, addr
))
3704 if (!qeth_l3_delete_ip(card
, addr
))
3710 qeth_l3_set_ip_addr_list(card
);
3715 static struct notifier_block qeth_l3_ip6_notifier
= {
3721 static int qeth_l3_register_notifiers(void)
3725 QETH_DBF_TEXT(SETUP
, 5, "regnotif");
3726 rc
= register_inetaddr_notifier(&qeth_l3_ip_notifier
);
3729 #ifdef CONFIG_QETH_IPV6
3730 rc
= register_inet6addr_notifier(&qeth_l3_ip6_notifier
);
3732 unregister_inetaddr_notifier(&qeth_l3_ip_notifier
);
3736 pr_warning("There is no IPv6 support for the layer 3 discipline\n");
3741 static void qeth_l3_unregister_notifiers(void)
3744 QETH_DBF_TEXT(SETUP
, 5, "unregnot");
3745 WARN_ON(unregister_inetaddr_notifier(&qeth_l3_ip_notifier
));
3746 #ifdef CONFIG_QETH_IPV6
3747 WARN_ON(unregister_inet6addr_notifier(&qeth_l3_ip6_notifier
));
3748 #endif /* QETH_IPV6 */
3751 static int __init
qeth_l3_init(void)
3755 pr_info("register layer 3 discipline\n");
3756 rc
= qeth_l3_register_notifiers();
3760 static void __exit
qeth_l3_exit(void)
3762 qeth_l3_unregister_notifiers();
3763 pr_info("unregister layer 3 discipline\n");
3766 module_init(qeth_l3_init
);
3767 module_exit(qeth_l3_exit
);
3768 MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
3769 MODULE_DESCRIPTION("qeth layer 3 discipline");
3770 MODULE_LICENSE("GPL");