2 * drivers/s390/net/qeth_l3_main.c
4 * Copyright IBM Corp. 2007, 2009
5 * Author(s): Utz Bacher <utz.bacher@de.ibm.com>,
6 * Frank Pavlic <fpavlic@de.ibm.com>,
7 * Thomas Spatzier <tspat@de.ibm.com>,
8 * Frank Blaschka <frank.blaschka@de.ibm.com>
11 #define KMSG_COMPONENT "qeth"
12 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
14 #include <linux/module.h>
15 #include <linux/moduleparam.h>
16 #include <linux/string.h>
17 #include <linux/errno.h>
18 #include <linux/kernel.h>
19 #include <linux/etherdevice.h>
20 #include <linux/mii.h>
22 #include <linux/ipv6.h>
23 #include <linux/inetdevice.h>
24 #include <linux/igmp.h>
25 #include <linux/slab.h>
29 #include <net/ip6_checksum.h>
34 static int qeth_l3_set_offline(struct ccwgroup_device
*);
35 static int qeth_l3_recover(void *);
36 static int qeth_l3_stop(struct net_device
*);
37 static void qeth_l3_set_multicast_list(struct net_device
*);
38 static int qeth_l3_neigh_setup(struct net_device
*, struct neigh_parms
*);
39 static int qeth_l3_register_addr_entry(struct qeth_card
*,
40 struct qeth_ipaddr
*);
41 static int qeth_l3_deregister_addr_entry(struct qeth_card
*,
42 struct qeth_ipaddr
*);
43 static int __qeth_l3_set_online(struct ccwgroup_device
*, int);
44 static int __qeth_l3_set_offline(struct ccwgroup_device
*, int);
46 static int qeth_l3_isxdigit(char *buf
)
49 if (!isxdigit(*buf
++))
55 void qeth_l3_ipaddr4_to_string(const __u8
*addr
, char *buf
)
57 sprintf(buf
, "%i.%i.%i.%i", addr
[0], addr
[1], addr
[2], addr
[3]);
60 int qeth_l3_string_to_ipaddr4(const char *buf
, __u8
*addr
)
62 int count
= 0, rc
= 0;
66 rc
= sscanf(buf
, "%u.%u.%u.%u%c",
67 &in
[0], &in
[1], &in
[2], &in
[3], &c
);
68 if (rc
!= 4 && (rc
!= 5 || c
!= '\n'))
70 for (count
= 0; count
< 4; count
++) {
73 addr
[count
] = in
[count
];
78 void qeth_l3_ipaddr6_to_string(const __u8
*addr
, char *buf
)
80 sprintf(buf
, "%pI6", addr
);
83 int qeth_l3_string_to_ipaddr6(const char *buf
, __u8
*addr
)
85 const char *end
, *end_tmp
, *start
;
88 int num2
, cnt
, out
, found
, save_cnt
;
89 unsigned short in_tmp
[8] = {0, };
91 cnt
= out
= found
= save_cnt
= num2
= 0;
96 end
= strchr(start
, ':');
98 end
= buf
+ strlen(buf
);
99 end_tmp
= strchr(start
, '\n');
106 if ((end
- start
) > 4)
108 memcpy(num
, start
, end
- start
);
109 if (!qeth_l3_isxdigit(num
))
111 sscanf(start
, "%x", &num2
);
113 in_tmp
[save_cnt
++] = num2
;
125 if (cnt
+ save_cnt
> 8)
129 in
[cnt
--] = in_tmp
[--save_cnt
];
133 void qeth_l3_ipaddr_to_string(enum qeth_prot_versions proto
, const __u8
*addr
,
136 if (proto
== QETH_PROT_IPV4
)
137 qeth_l3_ipaddr4_to_string(addr
, buf
);
138 else if (proto
== QETH_PROT_IPV6
)
139 qeth_l3_ipaddr6_to_string(addr
, buf
);
142 int qeth_l3_string_to_ipaddr(const char *buf
, enum qeth_prot_versions proto
,
145 if (proto
== QETH_PROT_IPV4
)
146 return qeth_l3_string_to_ipaddr4(buf
, addr
);
147 else if (proto
== QETH_PROT_IPV6
)
148 return qeth_l3_string_to_ipaddr6(buf
, addr
);
153 static void qeth_l3_convert_addr_to_bits(u8
*addr
, u8
*bits
, int len
)
158 for (i
= 0; i
< len
; ++i
) {
160 for (j
= 7; j
>= 0; --j
) {
161 bits
[i
*8 + j
] = octet
& 1;
167 int qeth_l3_is_addr_covered_by_ipato(struct qeth_card
*card
,
168 struct qeth_ipaddr
*addr
)
170 struct qeth_ipato_entry
*ipatoe
;
171 u8 addr_bits
[128] = {0, };
172 u8 ipatoe_bits
[128] = {0, };
175 if (!card
->ipato
.enabled
)
178 qeth_l3_convert_addr_to_bits((u8
*) &addr
->u
, addr_bits
,
179 (addr
->proto
== QETH_PROT_IPV4
)? 4:16);
180 list_for_each_entry(ipatoe
, &card
->ipato
.entries
, entry
) {
181 if (addr
->proto
!= ipatoe
->proto
)
183 qeth_l3_convert_addr_to_bits(ipatoe
->addr
, ipatoe_bits
,
184 (ipatoe
->proto
== QETH_PROT_IPV4
) ?
186 if (addr
->proto
== QETH_PROT_IPV4
)
187 rc
= !memcmp(addr_bits
, ipatoe_bits
,
188 min(32, ipatoe
->mask_bits
));
190 rc
= !memcmp(addr_bits
, ipatoe_bits
,
191 min(128, ipatoe
->mask_bits
));
196 if ((addr
->proto
== QETH_PROT_IPV4
) && card
->ipato
.invert4
)
198 else if ((addr
->proto
== QETH_PROT_IPV6
) && card
->ipato
.invert6
)
205 * Add IP to be added to todo list. If there is already an "add todo"
206 * in this list we just incremenent the reference count.
207 * Returns 0 if we just incremented reference count.
209 static int __qeth_l3_insert_ip_todo(struct qeth_card
*card
,
210 struct qeth_ipaddr
*addr
, int add
)
212 struct qeth_ipaddr
*tmp
, *t
;
215 if (card
->options
.sniffer
)
217 list_for_each_entry_safe(tmp
, t
, card
->ip_tbd_list
, entry
) {
218 if ((addr
->type
== QETH_IP_TYPE_DEL_ALL_MC
) &&
219 (tmp
->type
== QETH_IP_TYPE_DEL_ALL_MC
))
221 if ((tmp
->proto
== QETH_PROT_IPV4
) &&
222 (addr
->proto
== QETH_PROT_IPV4
) &&
223 (tmp
->type
== addr
->type
) &&
224 (tmp
->is_multicast
== addr
->is_multicast
) &&
225 (tmp
->u
.a4
.addr
== addr
->u
.a4
.addr
) &&
226 (tmp
->u
.a4
.mask
== addr
->u
.a4
.mask
)) {
230 if ((tmp
->proto
== QETH_PROT_IPV6
) &&
231 (addr
->proto
== QETH_PROT_IPV6
) &&
232 (tmp
->type
== addr
->type
) &&
233 (tmp
->is_multicast
== addr
->is_multicast
) &&
234 (tmp
->u
.a6
.pfxlen
== addr
->u
.a6
.pfxlen
) &&
235 (memcmp(&tmp
->u
.a6
.addr
, &addr
->u
.a6
.addr
,
236 sizeof(struct in6_addr
)) == 0)) {
242 if (addr
->users
!= 0)
243 tmp
->users
+= addr
->users
;
245 tmp
->users
+= add
? 1 : -1;
246 if (tmp
->users
== 0) {
247 list_del(&tmp
->entry
);
252 if (addr
->type
== QETH_IP_TYPE_DEL_ALL_MC
)
253 list_add(&addr
->entry
, card
->ip_tbd_list
);
255 if (addr
->users
== 0)
256 addr
->users
+= add
? 1 : -1;
257 if (add
&& (addr
->type
== QETH_IP_TYPE_NORMAL
) &&
258 qeth_l3_is_addr_covered_by_ipato(card
, addr
)) {
259 QETH_CARD_TEXT(card
, 2, "tkovaddr");
260 addr
->set_flags
|= QETH_IPA_SETIP_TAKEOVER_FLAG
;
262 list_add_tail(&addr
->entry
, card
->ip_tbd_list
);
268 static int qeth_l3_delete_ip(struct qeth_card
*card
, struct qeth_ipaddr
*addr
)
273 QETH_CARD_TEXT(card
, 4, "delip");
275 if (addr
->proto
== QETH_PROT_IPV4
)
276 QETH_CARD_HEX(card
, 4, &addr
->u
.a4
.addr
, 4);
278 QETH_CARD_HEX(card
, 4, &addr
->u
.a6
.addr
, 8);
279 QETH_CARD_HEX(card
, 4, ((char *)&addr
->u
.a6
.addr
) + 8, 8);
281 spin_lock_irqsave(&card
->ip_lock
, flags
);
282 rc
= __qeth_l3_insert_ip_todo(card
, addr
, 0);
283 spin_unlock_irqrestore(&card
->ip_lock
, flags
);
287 static int qeth_l3_add_ip(struct qeth_card
*card
, struct qeth_ipaddr
*addr
)
292 QETH_CARD_TEXT(card
, 4, "addip");
293 if (addr
->proto
== QETH_PROT_IPV4
)
294 QETH_CARD_HEX(card
, 4, &addr
->u
.a4
.addr
, 4);
296 QETH_CARD_HEX(card
, 4, &addr
->u
.a6
.addr
, 8);
297 QETH_CARD_HEX(card
, 4, ((char *)&addr
->u
.a6
.addr
) + 8, 8);
299 spin_lock_irqsave(&card
->ip_lock
, flags
);
300 rc
= __qeth_l3_insert_ip_todo(card
, addr
, 1);
301 spin_unlock_irqrestore(&card
->ip_lock
, flags
);
306 static struct qeth_ipaddr
*qeth_l3_get_addr_buffer(
307 enum qeth_prot_versions prot
)
309 struct qeth_ipaddr
*addr
;
311 addr
= kzalloc(sizeof(struct qeth_ipaddr
), GFP_ATOMIC
);
315 addr
->type
= QETH_IP_TYPE_NORMAL
;
320 static void qeth_l3_delete_mc_addresses(struct qeth_card
*card
)
322 struct qeth_ipaddr
*iptodo
;
325 QETH_CARD_TEXT(card
, 4, "delmc");
326 iptodo
= qeth_l3_get_addr_buffer(QETH_PROT_IPV4
);
328 QETH_CARD_TEXT(card
, 2, "dmcnomem");
331 iptodo
->type
= QETH_IP_TYPE_DEL_ALL_MC
;
332 spin_lock_irqsave(&card
->ip_lock
, flags
);
333 if (!__qeth_l3_insert_ip_todo(card
, iptodo
, 0))
335 spin_unlock_irqrestore(&card
->ip_lock
, flags
);
339 * Add/remove address to/from card's ip list, i.e. try to add or remove
340 * reference to/from an IP address that is already registered on the card.
342 * 0 address was on card and its reference count has been adjusted,
343 * but is still > 0, so nothing has to be done
344 * also returns 0 if card was not on card and the todo was to delete
345 * the address -> there is also nothing to be done
346 * 1 address was not on card and the todo is to add it to the card's ip
348 * -1 address was on card and its reference count has been decremented
349 * to <= 0 by the todo -> address must be removed from card
351 static int __qeth_l3_ref_ip_on_card(struct qeth_card
*card
,
352 struct qeth_ipaddr
*todo
, struct qeth_ipaddr
**__addr
)
354 struct qeth_ipaddr
*addr
;
357 list_for_each_entry(addr
, &card
->ip_list
, entry
) {
358 if ((addr
->proto
== QETH_PROT_IPV4
) &&
359 (todo
->proto
== QETH_PROT_IPV4
) &&
360 (addr
->type
== todo
->type
) &&
361 (addr
->u
.a4
.addr
== todo
->u
.a4
.addr
) &&
362 (addr
->u
.a4
.mask
== todo
->u
.a4
.mask
)) {
366 if ((addr
->proto
== QETH_PROT_IPV6
) &&
367 (todo
->proto
== QETH_PROT_IPV6
) &&
368 (addr
->type
== todo
->type
) &&
369 (addr
->u
.a6
.pfxlen
== todo
->u
.a6
.pfxlen
) &&
370 (memcmp(&addr
->u
.a6
.addr
, &todo
->u
.a6
.addr
,
371 sizeof(struct in6_addr
)) == 0)) {
377 addr
->users
+= todo
->users
;
378 if (addr
->users
<= 0) {
382 /* for VIPA and RXIP limit refcount to 1 */
383 if (addr
->type
!= QETH_IP_TYPE_NORMAL
)
388 if (todo
->users
> 0) {
389 /* for VIPA and RXIP limit refcount to 1 */
390 if (todo
->type
!= QETH_IP_TYPE_NORMAL
)
397 static void __qeth_l3_delete_all_mc(struct qeth_card
*card
,
398 unsigned long *flags
)
400 struct list_head fail_list
;
401 struct qeth_ipaddr
*addr
, *tmp
;
404 INIT_LIST_HEAD(&fail_list
);
406 list_for_each_entry_safe(addr
, tmp
, &card
->ip_list
, entry
) {
407 if (addr
->is_multicast
) {
408 list_del(&addr
->entry
);
409 spin_unlock_irqrestore(&card
->ip_lock
, *flags
);
410 rc
= qeth_l3_deregister_addr_entry(card
, addr
);
411 spin_lock_irqsave(&card
->ip_lock
, *flags
);
412 if (!rc
|| (rc
== IPA_RC_MC_ADDR_NOT_FOUND
))
415 list_add_tail(&addr
->entry
, &fail_list
);
419 list_splice(&fail_list
, &card
->ip_list
);
422 static void qeth_l3_set_ip_addr_list(struct qeth_card
*card
)
424 struct list_head
*tbd_list
;
425 struct qeth_ipaddr
*todo
, *addr
;
429 QETH_CARD_TEXT(card
, 2, "sdiplist");
430 QETH_CARD_HEX(card
, 2, &card
, sizeof(void *));
432 if ((card
->state
!= CARD_STATE_UP
&&
433 card
->state
!= CARD_STATE_SOFTSETUP
) || card
->options
.sniffer
) {
437 spin_lock_irqsave(&card
->ip_lock
, flags
);
438 tbd_list
= card
->ip_tbd_list
;
439 card
->ip_tbd_list
= kmalloc(sizeof(struct list_head
), GFP_ATOMIC
);
440 if (!card
->ip_tbd_list
) {
441 QETH_CARD_TEXT(card
, 0, "silnomem");
442 card
->ip_tbd_list
= tbd_list
;
443 spin_unlock_irqrestore(&card
->ip_lock
, flags
);
446 INIT_LIST_HEAD(card
->ip_tbd_list
);
448 while (!list_empty(tbd_list
)) {
449 todo
= list_entry(tbd_list
->next
, struct qeth_ipaddr
, entry
);
450 list_del(&todo
->entry
);
451 if (todo
->type
== QETH_IP_TYPE_DEL_ALL_MC
) {
452 __qeth_l3_delete_all_mc(card
, &flags
);
456 rc
= __qeth_l3_ref_ip_on_card(card
, todo
, &addr
);
458 /* nothing to be done; only adjusted refcount */
460 } else if (rc
== 1) {
461 /* new entry to be added to on-card list */
462 spin_unlock_irqrestore(&card
->ip_lock
, flags
);
463 rc
= qeth_l3_register_addr_entry(card
, todo
);
464 spin_lock_irqsave(&card
->ip_lock
, flags
);
465 if (!rc
|| (rc
== IPA_RC_LAN_OFFLINE
))
466 list_add_tail(&todo
->entry
, &card
->ip_list
);
469 } else if (rc
== -1) {
470 /* on-card entry to be removed */
471 list_del_init(&addr
->entry
);
472 spin_unlock_irqrestore(&card
->ip_lock
, flags
);
473 rc
= qeth_l3_deregister_addr_entry(card
, addr
);
474 spin_lock_irqsave(&card
->ip_lock
, flags
);
475 if (!rc
|| (rc
== IPA_RC_IP_ADDRESS_NOT_DEFINED
))
478 list_add_tail(&addr
->entry
, &card
->ip_list
);
482 spin_unlock_irqrestore(&card
->ip_lock
, flags
);
486 static void qeth_l3_clear_ip_list(struct qeth_card
*card
, int recover
)
488 struct qeth_ipaddr
*addr
, *tmp
;
491 QETH_CARD_TEXT(card
, 4, "clearip");
492 if (recover
&& card
->options
.sniffer
)
494 spin_lock_irqsave(&card
->ip_lock
, flags
);
495 /* clear todo list */
496 list_for_each_entry_safe(addr
, tmp
, card
->ip_tbd_list
, entry
) {
497 list_del(&addr
->entry
);
501 while (!list_empty(&card
->ip_list
)) {
502 addr
= list_entry(card
->ip_list
.next
,
503 struct qeth_ipaddr
, entry
);
504 list_del_init(&addr
->entry
);
505 if (!recover
|| addr
->is_multicast
) {
509 list_add_tail(&addr
->entry
, card
->ip_tbd_list
);
511 spin_unlock_irqrestore(&card
->ip_lock
, flags
);
514 static int qeth_l3_address_exists_in_list(struct list_head
*list
,
515 struct qeth_ipaddr
*addr
, int same_type
)
517 struct qeth_ipaddr
*tmp
;
519 list_for_each_entry(tmp
, list
, entry
) {
520 if ((tmp
->proto
== QETH_PROT_IPV4
) &&
521 (addr
->proto
== QETH_PROT_IPV4
) &&
522 ((same_type
&& (tmp
->type
== addr
->type
)) ||
523 (!same_type
&& (tmp
->type
!= addr
->type
))) &&
524 (tmp
->u
.a4
.addr
== addr
->u
.a4
.addr
))
527 if ((tmp
->proto
== QETH_PROT_IPV6
) &&
528 (addr
->proto
== QETH_PROT_IPV6
) &&
529 ((same_type
&& (tmp
->type
== addr
->type
)) ||
530 (!same_type
&& (tmp
->type
!= addr
->type
))) &&
531 (memcmp(&tmp
->u
.a6
.addr
, &addr
->u
.a6
.addr
,
532 sizeof(struct in6_addr
)) == 0))
539 static int qeth_l3_send_setdelmc(struct qeth_card
*card
,
540 struct qeth_ipaddr
*addr
, int ipacmd
)
543 struct qeth_cmd_buffer
*iob
;
544 struct qeth_ipa_cmd
*cmd
;
546 QETH_CARD_TEXT(card
, 4, "setdelmc");
548 iob
= qeth_get_ipacmd_buffer(card
, ipacmd
, addr
->proto
);
549 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
550 memcpy(&cmd
->data
.setdelipm
.mac
, addr
->mac
, OSA_ADDR_LEN
);
551 if (addr
->proto
== QETH_PROT_IPV6
)
552 memcpy(cmd
->data
.setdelipm
.ip6
, &addr
->u
.a6
.addr
,
553 sizeof(struct in6_addr
));
555 memcpy(&cmd
->data
.setdelipm
.ip4
, &addr
->u
.a4
.addr
, 4);
557 rc
= qeth_send_ipa_cmd(card
, iob
, NULL
, NULL
);
562 static void qeth_l3_fill_netmask(u8
*netmask
, unsigned int len
)
565 for (i
= 0; i
< 16; i
++) {
570 netmask
[i
] = (u8
)(0xFF00 >> j
);
576 static int qeth_l3_send_setdelip(struct qeth_card
*card
,
577 struct qeth_ipaddr
*addr
, int ipacmd
, unsigned int flags
)
580 struct qeth_cmd_buffer
*iob
;
581 struct qeth_ipa_cmd
*cmd
;
584 QETH_CARD_TEXT(card
, 4, "setdelip");
585 QETH_CARD_TEXT_(card
, 4, "flags%02X", flags
);
587 iob
= qeth_get_ipacmd_buffer(card
, ipacmd
, addr
->proto
);
588 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
589 if (addr
->proto
== QETH_PROT_IPV6
) {
590 memcpy(cmd
->data
.setdelip6
.ip_addr
, &addr
->u
.a6
.addr
,
591 sizeof(struct in6_addr
));
592 qeth_l3_fill_netmask(netmask
, addr
->u
.a6
.pfxlen
);
593 memcpy(cmd
->data
.setdelip6
.mask
, netmask
,
594 sizeof(struct in6_addr
));
595 cmd
->data
.setdelip6
.flags
= flags
;
597 memcpy(cmd
->data
.setdelip4
.ip_addr
, &addr
->u
.a4
.addr
, 4);
598 memcpy(cmd
->data
.setdelip4
.mask
, &addr
->u
.a4
.mask
, 4);
599 cmd
->data
.setdelip4
.flags
= flags
;
602 rc
= qeth_send_ipa_cmd(card
, iob
, NULL
, NULL
);
607 static int qeth_l3_send_setrouting(struct qeth_card
*card
,
608 enum qeth_routing_types type
, enum qeth_prot_versions prot
)
611 struct qeth_ipa_cmd
*cmd
;
612 struct qeth_cmd_buffer
*iob
;
614 QETH_CARD_TEXT(card
, 4, "setroutg");
615 iob
= qeth_get_ipacmd_buffer(card
, IPA_CMD_SETRTG
, prot
);
616 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
617 cmd
->data
.setrtg
.type
= (type
);
618 rc
= qeth_send_ipa_cmd(card
, iob
, NULL
, NULL
);
623 static void qeth_l3_correct_routing_type(struct qeth_card
*card
,
624 enum qeth_routing_types
*type
, enum qeth_prot_versions prot
)
626 if (card
->info
.type
== QETH_CARD_TYPE_IQD
) {
629 case PRIMARY_CONNECTOR
:
630 case SECONDARY_CONNECTOR
:
631 case MULTICAST_ROUTER
:
640 case SECONDARY_ROUTER
:
642 case MULTICAST_ROUTER
:
643 if (qeth_is_ipafunc_supported(card
, prot
,
654 int qeth_l3_setrouting_v4(struct qeth_card
*card
)
658 QETH_CARD_TEXT(card
, 3, "setrtg4");
660 qeth_l3_correct_routing_type(card
, &card
->options
.route4
.type
,
663 rc
= qeth_l3_send_setrouting(card
, card
->options
.route4
.type
,
666 card
->options
.route4
.type
= NO_ROUTER
;
667 QETH_DBF_MESSAGE(2, "Error (0x%04x) while setting routing type"
668 " on %s. Type set to 'no router'.\n", rc
,
669 QETH_CARD_IFNAME(card
));
674 int qeth_l3_setrouting_v6(struct qeth_card
*card
)
678 QETH_CARD_TEXT(card
, 3, "setrtg6");
679 #ifdef CONFIG_QETH_IPV6
681 if (!qeth_is_supported(card
, IPA_IPV6
))
683 qeth_l3_correct_routing_type(card
, &card
->options
.route6
.type
,
686 rc
= qeth_l3_send_setrouting(card
, card
->options
.route6
.type
,
689 card
->options
.route6
.type
= NO_ROUTER
;
690 QETH_DBF_MESSAGE(2, "Error (0x%04x) while setting routing type"
691 " on %s. Type set to 'no router'.\n", rc
,
692 QETH_CARD_IFNAME(card
));
699 * IP address takeover related functions
701 static void qeth_l3_clear_ipato_list(struct qeth_card
*card
)
704 struct qeth_ipato_entry
*ipatoe
, *tmp
;
707 spin_lock_irqsave(&card
->ip_lock
, flags
);
708 list_for_each_entry_safe(ipatoe
, tmp
, &card
->ipato
.entries
, entry
) {
709 list_del(&ipatoe
->entry
);
712 spin_unlock_irqrestore(&card
->ip_lock
, flags
);
715 int qeth_l3_add_ipato_entry(struct qeth_card
*card
,
716 struct qeth_ipato_entry
*new)
718 struct qeth_ipato_entry
*ipatoe
;
722 QETH_CARD_TEXT(card
, 2, "addipato");
723 spin_lock_irqsave(&card
->ip_lock
, flags
);
724 list_for_each_entry(ipatoe
, &card
->ipato
.entries
, entry
) {
725 if (ipatoe
->proto
!= new->proto
)
727 if (!memcmp(ipatoe
->addr
, new->addr
,
728 (ipatoe
->proto
== QETH_PROT_IPV4
)? 4:16) &&
729 (ipatoe
->mask_bits
== new->mask_bits
)) {
735 list_add_tail(&new->entry
, &card
->ipato
.entries
);
737 spin_unlock_irqrestore(&card
->ip_lock
, flags
);
741 void qeth_l3_del_ipato_entry(struct qeth_card
*card
,
742 enum qeth_prot_versions proto
, u8
*addr
, int mask_bits
)
744 struct qeth_ipato_entry
*ipatoe
, *tmp
;
747 QETH_CARD_TEXT(card
, 2, "delipato");
748 spin_lock_irqsave(&card
->ip_lock
, flags
);
749 list_for_each_entry_safe(ipatoe
, tmp
, &card
->ipato
.entries
, entry
) {
750 if (ipatoe
->proto
!= proto
)
752 if (!memcmp(ipatoe
->addr
, addr
,
753 (proto
== QETH_PROT_IPV4
)? 4:16) &&
754 (ipatoe
->mask_bits
== mask_bits
)) {
755 list_del(&ipatoe
->entry
);
759 spin_unlock_irqrestore(&card
->ip_lock
, flags
);
763 * VIPA related functions
765 int qeth_l3_add_vipa(struct qeth_card
*card
, enum qeth_prot_versions proto
,
768 struct qeth_ipaddr
*ipaddr
;
772 ipaddr
= qeth_l3_get_addr_buffer(proto
);
774 if (proto
== QETH_PROT_IPV4
) {
775 QETH_CARD_TEXT(card
, 2, "addvipa4");
776 memcpy(&ipaddr
->u
.a4
.addr
, addr
, 4);
777 ipaddr
->u
.a4
.mask
= 0;
778 } else if (proto
== QETH_PROT_IPV6
) {
779 QETH_CARD_TEXT(card
, 2, "addvipa6");
780 memcpy(&ipaddr
->u
.a6
.addr
, addr
, 16);
781 ipaddr
->u
.a6
.pfxlen
= 0;
783 ipaddr
->type
= QETH_IP_TYPE_VIPA
;
784 ipaddr
->set_flags
= QETH_IPA_SETIP_VIPA_FLAG
;
785 ipaddr
->del_flags
= QETH_IPA_DELIP_VIPA_FLAG
;
788 spin_lock_irqsave(&card
->ip_lock
, flags
);
789 if (qeth_l3_address_exists_in_list(&card
->ip_list
, ipaddr
, 0) ||
790 qeth_l3_address_exists_in_list(card
->ip_tbd_list
, ipaddr
, 0))
792 spin_unlock_irqrestore(&card
->ip_lock
, flags
);
796 if (!qeth_l3_add_ip(card
, ipaddr
))
798 qeth_l3_set_ip_addr_list(card
);
802 void qeth_l3_del_vipa(struct qeth_card
*card
, enum qeth_prot_versions proto
,
805 struct qeth_ipaddr
*ipaddr
;
807 ipaddr
= qeth_l3_get_addr_buffer(proto
);
809 if (proto
== QETH_PROT_IPV4
) {
810 QETH_CARD_TEXT(card
, 2, "delvipa4");
811 memcpy(&ipaddr
->u
.a4
.addr
, addr
, 4);
812 ipaddr
->u
.a4
.mask
= 0;
813 } else if (proto
== QETH_PROT_IPV6
) {
814 QETH_CARD_TEXT(card
, 2, "delvipa6");
815 memcpy(&ipaddr
->u
.a6
.addr
, addr
, 16);
816 ipaddr
->u
.a6
.pfxlen
= 0;
818 ipaddr
->type
= QETH_IP_TYPE_VIPA
;
821 if (!qeth_l3_delete_ip(card
, ipaddr
))
823 qeth_l3_set_ip_addr_list(card
);
827 * proxy ARP related functions
829 int qeth_l3_add_rxip(struct qeth_card
*card
, enum qeth_prot_versions proto
,
832 struct qeth_ipaddr
*ipaddr
;
836 ipaddr
= qeth_l3_get_addr_buffer(proto
);
838 if (proto
== QETH_PROT_IPV4
) {
839 QETH_CARD_TEXT(card
, 2, "addrxip4");
840 memcpy(&ipaddr
->u
.a4
.addr
, addr
, 4);
841 ipaddr
->u
.a4
.mask
= 0;
842 } else if (proto
== QETH_PROT_IPV6
) {
843 QETH_CARD_TEXT(card
, 2, "addrxip6");
844 memcpy(&ipaddr
->u
.a6
.addr
, addr
, 16);
845 ipaddr
->u
.a6
.pfxlen
= 0;
847 ipaddr
->type
= QETH_IP_TYPE_RXIP
;
848 ipaddr
->set_flags
= QETH_IPA_SETIP_TAKEOVER_FLAG
;
849 ipaddr
->del_flags
= 0;
852 spin_lock_irqsave(&card
->ip_lock
, flags
);
853 if (qeth_l3_address_exists_in_list(&card
->ip_list
, ipaddr
, 0) ||
854 qeth_l3_address_exists_in_list(card
->ip_tbd_list
, ipaddr
, 0))
856 spin_unlock_irqrestore(&card
->ip_lock
, flags
);
860 if (!qeth_l3_add_ip(card
, ipaddr
))
862 qeth_l3_set_ip_addr_list(card
);
866 void qeth_l3_del_rxip(struct qeth_card
*card
, enum qeth_prot_versions proto
,
869 struct qeth_ipaddr
*ipaddr
;
871 ipaddr
= qeth_l3_get_addr_buffer(proto
);
873 if (proto
== QETH_PROT_IPV4
) {
874 QETH_CARD_TEXT(card
, 2, "addrxip4");
875 memcpy(&ipaddr
->u
.a4
.addr
, addr
, 4);
876 ipaddr
->u
.a4
.mask
= 0;
877 } else if (proto
== QETH_PROT_IPV6
) {
878 QETH_CARD_TEXT(card
, 2, "addrxip6");
879 memcpy(&ipaddr
->u
.a6
.addr
, addr
, 16);
880 ipaddr
->u
.a6
.pfxlen
= 0;
882 ipaddr
->type
= QETH_IP_TYPE_RXIP
;
885 if (!qeth_l3_delete_ip(card
, ipaddr
))
887 qeth_l3_set_ip_addr_list(card
);
890 static int qeth_l3_register_addr_entry(struct qeth_card
*card
,
891 struct qeth_ipaddr
*addr
)
897 if (addr
->proto
== QETH_PROT_IPV4
) {
898 QETH_CARD_TEXT(card
, 2, "setaddr4");
899 QETH_CARD_HEX(card
, 3, &addr
->u
.a4
.addr
, sizeof(int));
900 } else if (addr
->proto
== QETH_PROT_IPV6
) {
901 QETH_CARD_TEXT(card
, 2, "setaddr6");
902 QETH_CARD_HEX(card
, 3, &addr
->u
.a6
.addr
, 8);
903 QETH_CARD_HEX(card
, 3, ((char *)&addr
->u
.a6
.addr
) + 8, 8);
905 QETH_CARD_TEXT(card
, 2, "setaddr?");
906 QETH_CARD_HEX(card
, 3, addr
, sizeof(struct qeth_ipaddr
));
909 if (addr
->is_multicast
)
910 rc
= qeth_l3_send_setdelmc(card
, addr
, IPA_CMD_SETIPM
);
912 rc
= qeth_l3_send_setdelip(card
, addr
, IPA_CMD_SETIP
,
915 QETH_CARD_TEXT(card
, 2, "failed");
916 } while ((--cnt
> 0) && rc
);
918 QETH_CARD_TEXT(card
, 2, "FAILED");
919 qeth_l3_ipaddr_to_string(addr
->proto
, (u8
*)&addr
->u
, buf
);
920 dev_warn(&card
->gdev
->dev
,
921 "Registering IP address %s failed\n", buf
);
926 static int qeth_l3_deregister_addr_entry(struct qeth_card
*card
,
927 struct qeth_ipaddr
*addr
)
931 if (addr
->proto
== QETH_PROT_IPV4
) {
932 QETH_CARD_TEXT(card
, 2, "deladdr4");
933 QETH_CARD_HEX(card
, 3, &addr
->u
.a4
.addr
, sizeof(int));
934 } else if (addr
->proto
== QETH_PROT_IPV6
) {
935 QETH_CARD_TEXT(card
, 2, "deladdr6");
936 QETH_CARD_HEX(card
, 3, &addr
->u
.a6
.addr
, 8);
937 QETH_CARD_HEX(card
, 3, ((char *)&addr
->u
.a6
.addr
) + 8, 8);
939 QETH_CARD_TEXT(card
, 2, "deladdr?");
940 QETH_CARD_HEX(card
, 3, addr
, sizeof(struct qeth_ipaddr
));
942 if (addr
->is_multicast
)
943 rc
= qeth_l3_send_setdelmc(card
, addr
, IPA_CMD_DELIPM
);
945 rc
= qeth_l3_send_setdelip(card
, addr
, IPA_CMD_DELIP
,
948 QETH_CARD_TEXT(card
, 2, "failed");
953 static inline u8
qeth_l3_get_qeth_hdr_flags4(int cast_type
)
955 if (cast_type
== RTN_MULTICAST
)
956 return QETH_CAST_MULTICAST
;
957 if (cast_type
== RTN_BROADCAST
)
958 return QETH_CAST_BROADCAST
;
959 return QETH_CAST_UNICAST
;
962 static inline u8
qeth_l3_get_qeth_hdr_flags6(int cast_type
)
964 u8 ct
= QETH_HDR_PASSTHRU
| QETH_HDR_IPV6
;
965 if (cast_type
== RTN_MULTICAST
)
966 return ct
| QETH_CAST_MULTICAST
;
967 if (cast_type
== RTN_ANYCAST
)
968 return ct
| QETH_CAST_ANYCAST
;
969 if (cast_type
== RTN_BROADCAST
)
970 return ct
| QETH_CAST_BROADCAST
;
971 return ct
| QETH_CAST_UNICAST
;
974 static int qeth_l3_send_setadp_mode(struct qeth_card
*card
, __u32 command
,
978 struct qeth_cmd_buffer
*iob
;
979 struct qeth_ipa_cmd
*cmd
;
981 QETH_CARD_TEXT(card
, 4, "adpmode");
983 iob
= qeth_get_adapter_cmd(card
, command
,
984 sizeof(struct qeth_ipacmd_setadpparms
));
985 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
986 cmd
->data
.setadapterparms
.data
.mode
= mode
;
987 rc
= qeth_send_ipa_cmd(card
, iob
, qeth_default_setadapterparms_cb
,
992 static int qeth_l3_setadapter_hstr(struct qeth_card
*card
)
996 QETH_CARD_TEXT(card
, 4, "adphstr");
998 if (qeth_adp_supported(card
, IPA_SETADP_SET_BROADCAST_MODE
)) {
999 rc
= qeth_l3_send_setadp_mode(card
,
1000 IPA_SETADP_SET_BROADCAST_MODE
,
1001 card
->options
.broadcast_mode
);
1003 QETH_DBF_MESSAGE(2, "couldn't set broadcast mode on "
1005 CARD_BUS_ID(card
), rc
);
1006 rc
= qeth_l3_send_setadp_mode(card
,
1007 IPA_SETADP_ALTER_MAC_ADDRESS
,
1008 card
->options
.macaddr_mode
);
1010 QETH_DBF_MESSAGE(2, "couldn't set macaddr mode on "
1011 "device %s: x%x\n", CARD_BUS_ID(card
), rc
);
1014 if (card
->options
.broadcast_mode
== QETH_TR_BROADCAST_LOCAL
)
1015 QETH_DBF_MESSAGE(2, "set adapter parameters not available "
1016 "to set broadcast mode, using ALLRINGS "
1017 "on device %s:\n", CARD_BUS_ID(card
));
1018 if (card
->options
.macaddr_mode
== QETH_TR_MACADDR_CANONICAL
)
1019 QETH_DBF_MESSAGE(2, "set adapter parameters not available "
1020 "to set macaddr mode, using NONCANONICAL "
1021 "on device %s:\n", CARD_BUS_ID(card
));
1025 static int qeth_l3_setadapter_parms(struct qeth_card
*card
)
1029 QETH_DBF_TEXT(SETUP
, 2, "setadprm");
1031 if (!qeth_is_supported(card
, IPA_SETADAPTERPARMS
)) {
1032 dev_info(&card
->gdev
->dev
,
1033 "set adapter parameters not supported.\n");
1034 QETH_DBF_TEXT(SETUP
, 2, " notsupp");
1037 rc
= qeth_query_setadapterparms(card
);
1039 QETH_DBF_MESSAGE(2, "%s couldn't set adapter parameters: "
1040 "0x%x\n", dev_name(&card
->gdev
->dev
), rc
);
1043 if (qeth_adp_supported(card
, IPA_SETADP_ALTER_MAC_ADDRESS
)) {
1044 rc
= qeth_setadpparms_change_macaddr(card
);
1046 dev_warn(&card
->gdev
->dev
, "Reading the adapter MAC"
1047 " address failed\n");
1050 if ((card
->info
.link_type
== QETH_LINK_TYPE_HSTR
) ||
1051 (card
->info
.link_type
== QETH_LINK_TYPE_LANE_TR
))
1052 rc
= qeth_l3_setadapter_hstr(card
);
1057 static int qeth_l3_default_setassparms_cb(struct qeth_card
*card
,
1058 struct qeth_reply
*reply
, unsigned long data
)
1060 struct qeth_ipa_cmd
*cmd
;
1062 QETH_CARD_TEXT(card
, 4, "defadpcb");
1064 cmd
= (struct qeth_ipa_cmd
*) data
;
1065 if (cmd
->hdr
.return_code
== 0) {
1066 cmd
->hdr
.return_code
= cmd
->data
.setassparms
.hdr
.return_code
;
1067 if (cmd
->hdr
.prot_version
== QETH_PROT_IPV4
)
1068 card
->options
.ipa4
.enabled_funcs
= cmd
->hdr
.ipa_enabled
;
1069 if (cmd
->hdr
.prot_version
== QETH_PROT_IPV6
)
1070 card
->options
.ipa6
.enabled_funcs
= cmd
->hdr
.ipa_enabled
;
1072 if (cmd
->data
.setassparms
.hdr
.assist_no
== IPA_INBOUND_CHECKSUM
&&
1073 cmd
->data
.setassparms
.hdr
.command_code
== IPA_CMD_ASS_START
) {
1074 card
->info
.csum_mask
= cmd
->data
.setassparms
.data
.flags_32bit
;
1075 QETH_CARD_TEXT_(card
, 3, "csum:%d", card
->info
.csum_mask
);
1077 if (cmd
->data
.setassparms
.hdr
.assist_no
== IPA_OUTBOUND_CHECKSUM
&&
1078 cmd
->data
.setassparms
.hdr
.command_code
== IPA_CMD_ASS_START
) {
1079 card
->info
.tx_csum_mask
=
1080 cmd
->data
.setassparms
.data
.flags_32bit
;
1081 QETH_CARD_TEXT_(card
, 3, "tcsu:%d", card
->info
.tx_csum_mask
);
1087 static struct qeth_cmd_buffer
*qeth_l3_get_setassparms_cmd(
1088 struct qeth_card
*card
, enum qeth_ipa_funcs ipa_func
, __u16 cmd_code
,
1089 __u16 len
, enum qeth_prot_versions prot
)
1091 struct qeth_cmd_buffer
*iob
;
1092 struct qeth_ipa_cmd
*cmd
;
1094 QETH_CARD_TEXT(card
, 4, "getasscm");
1095 iob
= qeth_get_ipacmd_buffer(card
, IPA_CMD_SETASSPARMS
, prot
);
1097 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
1098 cmd
->data
.setassparms
.hdr
.assist_no
= ipa_func
;
1099 cmd
->data
.setassparms
.hdr
.length
= 8 + len
;
1100 cmd
->data
.setassparms
.hdr
.command_code
= cmd_code
;
1101 cmd
->data
.setassparms
.hdr
.return_code
= 0;
1102 cmd
->data
.setassparms
.hdr
.seq_no
= 0;
1107 static int qeth_l3_send_setassparms(struct qeth_card
*card
,
1108 struct qeth_cmd_buffer
*iob
, __u16 len
, long data
,
1109 int (*reply_cb
)(struct qeth_card
*, struct qeth_reply
*,
1114 struct qeth_ipa_cmd
*cmd
;
1116 QETH_CARD_TEXT(card
, 4, "sendassp");
1118 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
1119 if (len
<= sizeof(__u32
))
1120 cmd
->data
.setassparms
.data
.flags_32bit
= (__u32
) data
;
1121 else /* (len > sizeof(__u32)) */
1122 memcpy(&cmd
->data
.setassparms
.data
, (void *) data
, len
);
1124 rc
= qeth_send_ipa_cmd(card
, iob
, reply_cb
, reply_param
);
1128 #ifdef CONFIG_QETH_IPV6
1129 static int qeth_l3_send_simple_setassparms_ipv6(struct qeth_card
*card
,
1130 enum qeth_ipa_funcs ipa_func
, __u16 cmd_code
)
1133 struct qeth_cmd_buffer
*iob
;
1135 QETH_CARD_TEXT(card
, 4, "simassp6");
1136 iob
= qeth_l3_get_setassparms_cmd(card
, ipa_func
, cmd_code
,
1138 rc
= qeth_l3_send_setassparms(card
, iob
, 0, 0,
1139 qeth_l3_default_setassparms_cb
, NULL
);
1144 static int qeth_l3_send_simple_setassparms(struct qeth_card
*card
,
1145 enum qeth_ipa_funcs ipa_func
, __u16 cmd_code
, long data
)
1149 struct qeth_cmd_buffer
*iob
;
1151 QETH_CARD_TEXT(card
, 4, "simassp4");
1153 length
= sizeof(__u32
);
1154 iob
= qeth_l3_get_setassparms_cmd(card
, ipa_func
, cmd_code
,
1155 length
, QETH_PROT_IPV4
);
1156 rc
= qeth_l3_send_setassparms(card
, iob
, length
, data
,
1157 qeth_l3_default_setassparms_cb
, NULL
);
1161 static int qeth_l3_start_ipa_arp_processing(struct qeth_card
*card
)
1165 QETH_CARD_TEXT(card
, 3, "ipaarp");
1167 if (!qeth_is_supported(card
, IPA_ARP_PROCESSING
)) {
1168 dev_info(&card
->gdev
->dev
,
1169 "ARP processing not supported on %s!\n",
1170 QETH_CARD_IFNAME(card
));
1173 rc
= qeth_l3_send_simple_setassparms(card
, IPA_ARP_PROCESSING
,
1174 IPA_CMD_ASS_START
, 0);
1176 dev_warn(&card
->gdev
->dev
,
1177 "Starting ARP processing support for %s failed\n",
1178 QETH_CARD_IFNAME(card
));
1183 static int qeth_l3_start_ipa_ip_fragmentation(struct qeth_card
*card
)
1187 QETH_CARD_TEXT(card
, 3, "ipaipfrg");
1189 if (!qeth_is_supported(card
, IPA_IP_FRAGMENTATION
)) {
1190 dev_info(&card
->gdev
->dev
,
1191 "Hardware IP fragmentation not supported on %s\n",
1192 QETH_CARD_IFNAME(card
));
1196 rc
= qeth_l3_send_simple_setassparms(card
, IPA_IP_FRAGMENTATION
,
1197 IPA_CMD_ASS_START
, 0);
1199 dev_warn(&card
->gdev
->dev
,
1200 "Starting IP fragmentation support for %s failed\n",
1201 QETH_CARD_IFNAME(card
));
1203 dev_info(&card
->gdev
->dev
,
1204 "Hardware IP fragmentation enabled \n");
1208 static int qeth_l3_start_ipa_source_mac(struct qeth_card
*card
)
1212 QETH_CARD_TEXT(card
, 3, "stsrcmac");
1214 if (!qeth_is_supported(card
, IPA_SOURCE_MAC
)) {
1215 dev_info(&card
->gdev
->dev
,
1216 "Inbound source MAC-address not supported on %s\n",
1217 QETH_CARD_IFNAME(card
));
1221 rc
= qeth_l3_send_simple_setassparms(card
, IPA_SOURCE_MAC
,
1222 IPA_CMD_ASS_START
, 0);
1224 dev_warn(&card
->gdev
->dev
,
1225 "Starting source MAC-address support for %s failed\n",
1226 QETH_CARD_IFNAME(card
));
1230 static int qeth_l3_start_ipa_vlan(struct qeth_card
*card
)
1234 QETH_CARD_TEXT(card
, 3, "strtvlan");
1236 if (!qeth_is_supported(card
, IPA_FULL_VLAN
)) {
1237 dev_info(&card
->gdev
->dev
,
1238 "VLAN not supported on %s\n", QETH_CARD_IFNAME(card
));
1242 rc
= qeth_l3_send_simple_setassparms(card
, IPA_VLAN_PRIO
,
1243 IPA_CMD_ASS_START
, 0);
1245 dev_warn(&card
->gdev
->dev
,
1246 "Starting VLAN support for %s failed\n",
1247 QETH_CARD_IFNAME(card
));
1249 dev_info(&card
->gdev
->dev
, "VLAN enabled\n");
1254 static int qeth_l3_start_ipa_multicast(struct qeth_card
*card
)
1258 QETH_CARD_TEXT(card
, 3, "stmcast");
1260 if (!qeth_is_supported(card
, IPA_MULTICASTING
)) {
1261 dev_info(&card
->gdev
->dev
,
1262 "Multicast not supported on %s\n",
1263 QETH_CARD_IFNAME(card
));
1267 rc
= qeth_l3_send_simple_setassparms(card
, IPA_MULTICASTING
,
1268 IPA_CMD_ASS_START
, 0);
1270 dev_warn(&card
->gdev
->dev
,
1271 "Starting multicast support for %s failed\n",
1272 QETH_CARD_IFNAME(card
));
1274 dev_info(&card
->gdev
->dev
, "Multicast enabled\n");
1275 card
->dev
->flags
|= IFF_MULTICAST
;
1280 #ifdef CONFIG_QETH_IPV6
1281 static int qeth_l3_softsetup_ipv6(struct qeth_card
*card
)
1285 QETH_CARD_TEXT(card
, 3, "softipv6");
1287 if (card
->info
.type
== QETH_CARD_TYPE_IQD
)
1290 rc
= qeth_query_ipassists(card
, QETH_PROT_IPV6
);
1292 dev_err(&card
->gdev
->dev
,
1293 "Activating IPv6 support for %s failed\n",
1294 QETH_CARD_IFNAME(card
));
1297 rc
= qeth_l3_send_simple_setassparms(card
, IPA_IPV6
,
1298 IPA_CMD_ASS_START
, 3);
1300 dev_err(&card
->gdev
->dev
,
1301 "Activating IPv6 support for %s failed\n",
1302 QETH_CARD_IFNAME(card
));
1305 rc
= qeth_l3_send_simple_setassparms_ipv6(card
, IPA_IPV6
,
1308 dev_err(&card
->gdev
->dev
,
1309 "Activating IPv6 support for %s failed\n",
1310 QETH_CARD_IFNAME(card
));
1313 rc
= qeth_l3_send_simple_setassparms_ipv6(card
, IPA_PASSTHRU
,
1316 dev_warn(&card
->gdev
->dev
,
1317 "Enabling the passthrough mode for %s failed\n",
1318 QETH_CARD_IFNAME(card
));
1322 dev_info(&card
->gdev
->dev
, "IPV6 enabled\n");
1327 static int qeth_l3_start_ipa_ipv6(struct qeth_card
*card
)
1331 QETH_CARD_TEXT(card
, 3, "strtipv6");
1333 if (!qeth_is_supported(card
, IPA_IPV6
)) {
1334 dev_info(&card
->gdev
->dev
,
1335 "IPv6 not supported on %s\n", QETH_CARD_IFNAME(card
));
1338 #ifdef CONFIG_QETH_IPV6
1339 rc
= qeth_l3_softsetup_ipv6(card
);
1344 static int qeth_l3_start_ipa_broadcast(struct qeth_card
*card
)
1348 QETH_CARD_TEXT(card
, 3, "stbrdcst");
1349 card
->info
.broadcast_capable
= 0;
1350 if (!qeth_is_supported(card
, IPA_FILTERING
)) {
1351 dev_info(&card
->gdev
->dev
,
1352 "Broadcast not supported on %s\n",
1353 QETH_CARD_IFNAME(card
));
1357 rc
= qeth_l3_send_simple_setassparms(card
, IPA_FILTERING
,
1358 IPA_CMD_ASS_START
, 0);
1360 dev_warn(&card
->gdev
->dev
, "Enabling broadcast filtering for "
1361 "%s failed\n", QETH_CARD_IFNAME(card
));
1365 rc
= qeth_l3_send_simple_setassparms(card
, IPA_FILTERING
,
1366 IPA_CMD_ASS_CONFIGURE
, 1);
1368 dev_warn(&card
->gdev
->dev
,
1369 "Setting up broadcast filtering for %s failed\n",
1370 QETH_CARD_IFNAME(card
));
1373 card
->info
.broadcast_capable
= QETH_BROADCAST_WITH_ECHO
;
1374 dev_info(&card
->gdev
->dev
, "Broadcast enabled\n");
1375 rc
= qeth_l3_send_simple_setassparms(card
, IPA_FILTERING
,
1376 IPA_CMD_ASS_ENABLE
, 1);
1378 dev_warn(&card
->gdev
->dev
, "Setting up broadcast echo "
1379 "filtering for %s failed\n", QETH_CARD_IFNAME(card
));
1382 card
->info
.broadcast_capable
= QETH_BROADCAST_WITHOUT_ECHO
;
1384 if (card
->info
.broadcast_capable
)
1385 card
->dev
->flags
|= IFF_BROADCAST
;
1387 card
->dev
->flags
&= ~IFF_BROADCAST
;
1391 static int qeth_l3_send_checksum_command(struct qeth_card
*card
)
1395 rc
= qeth_l3_send_simple_setassparms(card
, IPA_INBOUND_CHECKSUM
,
1396 IPA_CMD_ASS_START
, 0);
1398 dev_warn(&card
->gdev
->dev
, "Starting HW checksumming for %s "
1399 "failed, using SW checksumming\n",
1400 QETH_CARD_IFNAME(card
));
1403 rc
= qeth_l3_send_simple_setassparms(card
, IPA_INBOUND_CHECKSUM
,
1405 card
->info
.csum_mask
);
1407 dev_warn(&card
->gdev
->dev
, "Enabling HW checksumming for %s "
1408 "failed, using SW checksumming\n",
1409 QETH_CARD_IFNAME(card
));
1415 int qeth_l3_set_rx_csum(struct qeth_card
*card
, int on
)
1420 rc
= qeth_l3_send_checksum_command(card
);
1423 dev_info(&card
->gdev
->dev
,
1424 "HW Checksumming (inbound) enabled\n");
1426 rc
= qeth_l3_send_simple_setassparms(card
,
1427 IPA_INBOUND_CHECKSUM
, IPA_CMD_ASS_STOP
, 0);
1435 static int qeth_l3_start_ipa_checksum(struct qeth_card
*card
)
1437 QETH_CARD_TEXT(card
, 3, "strtcsum");
1439 if (card
->dev
->features
& NETIF_F_RXCSUM
) {
1441 /* force set_features call */
1442 card
->dev
->features
&= ~NETIF_F_RXCSUM
;
1443 netdev_update_features(card
->dev
);
1449 static int qeth_l3_start_ipa_tx_checksum(struct qeth_card
*card
)
1453 if (!qeth_is_supported(card
, IPA_OUTBOUND_CHECKSUM
))
1455 rc
= qeth_l3_send_simple_setassparms(card
, IPA_OUTBOUND_CHECKSUM
,
1456 IPA_CMD_ASS_START
, 0);
1459 rc
= qeth_l3_send_simple_setassparms(card
, IPA_OUTBOUND_CHECKSUM
,
1460 IPA_CMD_ASS_ENABLE
, card
->info
.tx_csum_mask
);
1463 dev_info(&card
->gdev
->dev
, "HW TX Checksumming enabled\n");
1466 dev_warn(&card
->gdev
->dev
, "Enabling HW TX checksumming for %s "
1467 "failed, using SW TX checksumming\n", QETH_CARD_IFNAME(card
));
1471 static int qeth_l3_start_ipa_tso(struct qeth_card
*card
)
1475 QETH_CARD_TEXT(card
, 3, "sttso");
1477 if (!qeth_is_supported(card
, IPA_OUTBOUND_TSO
)) {
1478 dev_info(&card
->gdev
->dev
,
1479 "Outbound TSO not supported on %s\n",
1480 QETH_CARD_IFNAME(card
));
1483 rc
= qeth_l3_send_simple_setassparms(card
, IPA_OUTBOUND_TSO
,
1484 IPA_CMD_ASS_START
, 0);
1486 dev_warn(&card
->gdev
->dev
, "Starting outbound TCP "
1487 "segmentation offload for %s failed\n",
1488 QETH_CARD_IFNAME(card
));
1490 dev_info(&card
->gdev
->dev
,
1491 "Outbound TSO enabled\n");
1494 card
->dev
->features
&= ~NETIF_F_TSO
;
1498 static int qeth_l3_start_ipassists(struct qeth_card
*card
)
1500 QETH_CARD_TEXT(card
, 3, "strtipas");
1502 qeth_set_access_ctrl_online(card
); /* go on*/
1503 qeth_l3_start_ipa_arp_processing(card
); /* go on*/
1504 qeth_l3_start_ipa_ip_fragmentation(card
); /* go on*/
1505 qeth_l3_start_ipa_source_mac(card
); /* go on*/
1506 qeth_l3_start_ipa_vlan(card
); /* go on*/
1507 qeth_l3_start_ipa_multicast(card
); /* go on*/
1508 qeth_l3_start_ipa_ipv6(card
); /* go on*/
1509 qeth_l3_start_ipa_broadcast(card
); /* go on*/
1510 qeth_l3_start_ipa_checksum(card
); /* go on*/
1511 qeth_l3_start_ipa_tx_checksum(card
);
1512 qeth_l3_start_ipa_tso(card
); /* go on*/
1516 static int qeth_l3_iqd_read_initial_mac_cb(struct qeth_card
*card
,
1517 struct qeth_reply
*reply
, unsigned long data
)
1519 struct qeth_ipa_cmd
*cmd
;
1521 cmd
= (struct qeth_ipa_cmd
*) data
;
1522 if (cmd
->hdr
.return_code
== 0)
1523 memcpy(card
->dev
->dev_addr
,
1524 cmd
->data
.create_destroy_addr
.unique_id
, ETH_ALEN
);
1526 random_ether_addr(card
->dev
->dev_addr
);
1531 static int qeth_l3_iqd_read_initial_mac(struct qeth_card
*card
)
1534 struct qeth_cmd_buffer
*iob
;
1535 struct qeth_ipa_cmd
*cmd
;
1537 QETH_DBF_TEXT(SETUP
, 2, "hsrmac");
1539 iob
= qeth_get_ipacmd_buffer(card
, IPA_CMD_CREATE_ADDR
,
1541 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
1542 *((__u16
*) &cmd
->data
.create_destroy_addr
.unique_id
[6]) =
1543 card
->info
.unique_id
;
1545 rc
= qeth_send_ipa_cmd(card
, iob
, qeth_l3_iqd_read_initial_mac_cb
,
1550 static int qeth_l3_get_unique_id_cb(struct qeth_card
*card
,
1551 struct qeth_reply
*reply
, unsigned long data
)
1553 struct qeth_ipa_cmd
*cmd
;
1555 cmd
= (struct qeth_ipa_cmd
*) data
;
1556 if (cmd
->hdr
.return_code
== 0)
1557 card
->info
.unique_id
= *((__u16
*)
1558 &cmd
->data
.create_destroy_addr
.unique_id
[6]);
1560 card
->info
.unique_id
= UNIQUE_ID_IF_CREATE_ADDR_FAILED
|
1561 UNIQUE_ID_NOT_BY_CARD
;
1562 dev_warn(&card
->gdev
->dev
, "The network adapter failed to "
1563 "generate a unique ID\n");
1568 static int qeth_l3_get_unique_id(struct qeth_card
*card
)
1571 struct qeth_cmd_buffer
*iob
;
1572 struct qeth_ipa_cmd
*cmd
;
1574 QETH_DBF_TEXT(SETUP
, 2, "guniqeid");
1576 if (!qeth_is_supported(card
, IPA_IPV6
)) {
1577 card
->info
.unique_id
= UNIQUE_ID_IF_CREATE_ADDR_FAILED
|
1578 UNIQUE_ID_NOT_BY_CARD
;
1582 iob
= qeth_get_ipacmd_buffer(card
, IPA_CMD_CREATE_ADDR
,
1584 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
1585 *((__u16
*) &cmd
->data
.create_destroy_addr
.unique_id
[6]) =
1586 card
->info
.unique_id
;
1588 rc
= qeth_send_ipa_cmd(card
, iob
, qeth_l3_get_unique_id_cb
, NULL
);
1593 qeth_diags_trace_cb(struct qeth_card
*card
, struct qeth_reply
*reply
,
1596 struct qeth_ipa_cmd
*cmd
;
1599 QETH_DBF_TEXT(SETUP
, 2, "diastrcb");
1601 cmd
= (struct qeth_ipa_cmd
*)data
;
1602 rc
= cmd
->hdr
.return_code
;
1604 QETH_CARD_TEXT_(card
, 2, "dxter%x", rc
);
1605 switch (cmd
->data
.diagass
.action
) {
1606 case QETH_DIAGS_CMD_TRACE_QUERY
:
1608 case QETH_DIAGS_CMD_TRACE_DISABLE
:
1611 case IPA_RC_INVALID_SUBCMD
:
1612 card
->info
.promisc_mode
= SET_PROMISC_MODE_OFF
;
1613 dev_info(&card
->gdev
->dev
, "The HiperSockets network "
1614 "traffic analyzer is deactivated\n");
1620 case QETH_DIAGS_CMD_TRACE_ENABLE
:
1623 card
->info
.promisc_mode
= SET_PROMISC_MODE_ON
;
1624 dev_info(&card
->gdev
->dev
, "The HiperSockets network "
1625 "traffic analyzer is activated\n");
1627 case IPA_RC_HARDWARE_AUTH_ERROR
:
1628 dev_warn(&card
->gdev
->dev
, "The device is not "
1629 "authorized to run as a HiperSockets network "
1630 "traffic analyzer\n");
1632 case IPA_RC_TRACE_ALREADY_ACTIVE
:
1633 dev_warn(&card
->gdev
->dev
, "A HiperSockets "
1634 "network traffic analyzer is already "
1635 "active in the HiperSockets LAN\n");
1642 QETH_DBF_MESSAGE(2, "Unknown sniffer action (0x%04x) on %s\n",
1643 cmd
->data
.diagass
.action
, QETH_CARD_IFNAME(card
));
1650 qeth_diags_trace(struct qeth_card
*card
, enum qeth_diags_trace_cmds diags_cmd
)
1652 struct qeth_cmd_buffer
*iob
;
1653 struct qeth_ipa_cmd
*cmd
;
1655 QETH_DBF_TEXT(SETUP
, 2, "diagtrac");
1657 iob
= qeth_get_ipacmd_buffer(card
, IPA_CMD_SET_DIAG_ASS
, 0);
1658 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
1659 cmd
->data
.diagass
.subcmd_len
= 16;
1660 cmd
->data
.diagass
.subcmd
= QETH_DIAGS_CMD_TRACE
;
1661 cmd
->data
.diagass
.type
= QETH_DIAGS_TYPE_HIPERSOCKET
;
1662 cmd
->data
.diagass
.action
= diags_cmd
;
1663 return qeth_send_ipa_cmd(card
, iob
, qeth_diags_trace_cb
, NULL
);
1666 static void qeth_l3_get_mac_for_ipm(__u32 ipm
, char *mac
,
1667 struct net_device
*dev
)
1669 if (dev
->type
== ARPHRD_IEEE802_TR
)
1670 ip_tr_mc_map(ipm
, mac
);
1672 ip_eth_mc_map(ipm
, mac
);
1675 static void qeth_l3_add_mc(struct qeth_card
*card
, struct in_device
*in4_dev
)
1677 struct qeth_ipaddr
*ipm
;
1678 struct ip_mc_list
*im4
;
1679 char buf
[MAX_ADDR_LEN
];
1681 QETH_CARD_TEXT(card
, 4, "addmc");
1682 for (im4
= rcu_dereference(in4_dev
->mc_list
); im4
!= NULL
;
1683 im4
= rcu_dereference(im4
->next_rcu
)) {
1684 qeth_l3_get_mac_for_ipm(im4
->multiaddr
, buf
, in4_dev
->dev
);
1685 ipm
= qeth_l3_get_addr_buffer(QETH_PROT_IPV4
);
1688 ipm
->u
.a4
.addr
= im4
->multiaddr
;
1689 memcpy(ipm
->mac
, buf
, OSA_ADDR_LEN
);
1690 ipm
->is_multicast
= 1;
1691 if (!qeth_l3_add_ip(card
, ipm
))
1696 static void qeth_l3_add_vlan_mc(struct qeth_card
*card
)
1698 struct in_device
*in_dev
;
1699 struct vlan_group
*vg
;
1702 QETH_CARD_TEXT(card
, 4, "addmcvl");
1703 if (!qeth_is_supported(card
, IPA_FULL_VLAN
) || (card
->vlangrp
== NULL
))
1707 for (i
= 0; i
< VLAN_N_VID
; i
++) {
1708 struct net_device
*netdev
= vlan_group_get_device(vg
, i
);
1709 if (netdev
== NULL
||
1710 !(netdev
->flags
& IFF_UP
))
1712 in_dev
= in_dev_get(netdev
);
1716 qeth_l3_add_mc(card
, in_dev
);
1722 static void qeth_l3_add_multicast_ipv4(struct qeth_card
*card
)
1724 struct in_device
*in4_dev
;
1726 QETH_CARD_TEXT(card
, 4, "chkmcv4");
1727 in4_dev
= in_dev_get(card
->dev
);
1728 if (in4_dev
== NULL
)
1731 qeth_l3_add_mc(card
, in4_dev
);
1732 qeth_l3_add_vlan_mc(card
);
1734 in_dev_put(in4_dev
);
1737 #ifdef CONFIG_QETH_IPV6
1738 static void qeth_l3_add_mc6(struct qeth_card
*card
, struct inet6_dev
*in6_dev
)
1740 struct qeth_ipaddr
*ipm
;
1741 struct ifmcaddr6
*im6
;
1742 char buf
[MAX_ADDR_LEN
];
1744 QETH_CARD_TEXT(card
, 4, "addmc6");
1745 for (im6
= in6_dev
->mc_list
; im6
!= NULL
; im6
= im6
->next
) {
1746 ndisc_mc_map(&im6
->mca_addr
, buf
, in6_dev
->dev
, 0);
1747 ipm
= qeth_l3_get_addr_buffer(QETH_PROT_IPV6
);
1750 ipm
->is_multicast
= 1;
1751 memcpy(ipm
->mac
, buf
, OSA_ADDR_LEN
);
1752 memcpy(&ipm
->u
.a6
.addr
, &im6
->mca_addr
.s6_addr
,
1753 sizeof(struct in6_addr
));
1754 if (!qeth_l3_add_ip(card
, ipm
))
1759 static void qeth_l3_add_vlan_mc6(struct qeth_card
*card
)
1761 struct inet6_dev
*in_dev
;
1762 struct vlan_group
*vg
;
1765 QETH_CARD_TEXT(card
, 4, "admc6vl");
1766 if (!qeth_is_supported(card
, IPA_FULL_VLAN
) || (card
->vlangrp
== NULL
))
1770 for (i
= 0; i
< VLAN_N_VID
; i
++) {
1771 struct net_device
*netdev
= vlan_group_get_device(vg
, i
);
1772 if (netdev
== NULL
||
1773 !(netdev
->flags
& IFF_UP
))
1775 in_dev
= in6_dev_get(netdev
);
1778 read_lock_bh(&in_dev
->lock
);
1779 qeth_l3_add_mc6(card
, in_dev
);
1780 read_unlock_bh(&in_dev
->lock
);
1781 in6_dev_put(in_dev
);
1785 static void qeth_l3_add_multicast_ipv6(struct qeth_card
*card
)
1787 struct inet6_dev
*in6_dev
;
1789 QETH_CARD_TEXT(card
, 4, "chkmcv6");
1790 if (!qeth_is_supported(card
, IPA_IPV6
))
1792 in6_dev
= in6_dev_get(card
->dev
);
1793 if (in6_dev
== NULL
)
1795 read_lock_bh(&in6_dev
->lock
);
1796 qeth_l3_add_mc6(card
, in6_dev
);
1797 qeth_l3_add_vlan_mc6(card
);
1798 read_unlock_bh(&in6_dev
->lock
);
1799 in6_dev_put(in6_dev
);
1801 #endif /* CONFIG_QETH_IPV6 */
1803 static void qeth_l3_free_vlan_addresses4(struct qeth_card
*card
,
1806 struct in_device
*in_dev
;
1807 struct in_ifaddr
*ifa
;
1808 struct qeth_ipaddr
*addr
;
1810 QETH_CARD_TEXT(card
, 4, "frvaddr4");
1812 in_dev
= in_dev_get(vlan_group_get_device(card
->vlangrp
, vid
));
1815 for (ifa
= in_dev
->ifa_list
; ifa
; ifa
= ifa
->ifa_next
) {
1816 addr
= qeth_l3_get_addr_buffer(QETH_PROT_IPV4
);
1818 addr
->u
.a4
.addr
= ifa
->ifa_address
;
1819 addr
->u
.a4
.mask
= ifa
->ifa_mask
;
1820 addr
->type
= QETH_IP_TYPE_NORMAL
;
1821 if (!qeth_l3_delete_ip(card
, addr
))
1828 static void qeth_l3_free_vlan_addresses6(struct qeth_card
*card
,
1831 #ifdef CONFIG_QETH_IPV6
1832 struct inet6_dev
*in6_dev
;
1833 struct inet6_ifaddr
*ifa
;
1834 struct qeth_ipaddr
*addr
;
1836 QETH_CARD_TEXT(card
, 4, "frvaddr6");
1838 in6_dev
= in6_dev_get(vlan_group_get_device(card
->vlangrp
, vid
));
1841 list_for_each_entry(ifa
, &in6_dev
->addr_list
, if_list
) {
1842 addr
= qeth_l3_get_addr_buffer(QETH_PROT_IPV6
);
1844 memcpy(&addr
->u
.a6
.addr
, &ifa
->addr
,
1845 sizeof(struct in6_addr
));
1846 addr
->u
.a6
.pfxlen
= ifa
->prefix_len
;
1847 addr
->type
= QETH_IP_TYPE_NORMAL
;
1848 if (!qeth_l3_delete_ip(card
, addr
))
1852 in6_dev_put(in6_dev
);
1853 #endif /* CONFIG_QETH_IPV6 */
1856 static void qeth_l3_free_vlan_addresses(struct qeth_card
*card
,
1861 qeth_l3_free_vlan_addresses4(card
, vid
);
1862 qeth_l3_free_vlan_addresses6(card
, vid
);
1865 static void qeth_l3_vlan_rx_register(struct net_device
*dev
,
1866 struct vlan_group
*grp
)
1868 struct qeth_card
*card
= dev
->ml_priv
;
1869 unsigned long flags
;
1871 QETH_CARD_TEXT(card
, 4, "vlanreg");
1872 spin_lock_irqsave(&card
->vlanlock
, flags
);
1873 card
->vlangrp
= grp
;
1874 spin_unlock_irqrestore(&card
->vlanlock
, flags
);
1877 static void qeth_l3_vlan_rx_add_vid(struct net_device
*dev
, unsigned short vid
)
1882 static void qeth_l3_vlan_rx_kill_vid(struct net_device
*dev
, unsigned short vid
)
1884 struct qeth_card
*card
= dev
->ml_priv
;
1885 unsigned long flags
;
1887 QETH_CARD_TEXT_(card
, 4, "kid:%d", vid
);
1888 if (qeth_wait_for_threads(card
, QETH_RECOVER_THREAD
)) {
1889 QETH_CARD_TEXT(card
, 3, "kidREC");
1892 spin_lock_irqsave(&card
->vlanlock
, flags
);
1893 /* unregister IP addresses of vlan device */
1894 qeth_l3_free_vlan_addresses(card
, vid
);
1895 vlan_group_set_device(card
->vlangrp
, vid
, NULL
);
1896 spin_unlock_irqrestore(&card
->vlanlock
, flags
);
1897 qeth_l3_set_multicast_list(card
->dev
);
1900 static inline int qeth_l3_rebuild_skb(struct qeth_card
*card
,
1901 struct sk_buff
*skb
, struct qeth_hdr
*hdr
,
1902 unsigned short *vlan_id
)
1905 struct iphdr
*ip_hdr
;
1906 unsigned char tg_addr
[MAX_ADDR_LEN
];
1909 if (!(hdr
->hdr
.l3
.flags
& QETH_HDR_PASSTHRU
)) {
1910 prot
= htons((hdr
->hdr
.l3
.flags
& QETH_HDR_IPV6
)? ETH_P_IPV6
:
1912 switch (hdr
->hdr
.l3
.flags
& QETH_HDR_CAST_MASK
) {
1913 case QETH_CAST_MULTICAST
:
1915 #ifdef CONFIG_QETH_IPV6
1916 case __constant_htons(ETH_P_IPV6
):
1917 ndisc_mc_map((struct in6_addr
*)
1919 tg_addr
, card
->dev
, 0);
1922 case __constant_htons(ETH_P_IP
):
1923 ip_hdr
= (struct iphdr
*)skb
->data
;
1924 (card
->dev
->type
== ARPHRD_IEEE802_TR
) ?
1925 ip_tr_mc_map(ip_hdr
->daddr
, tg_addr
):
1926 ip_eth_mc_map(ip_hdr
->daddr
, tg_addr
);
1929 memcpy(tg_addr
, card
->dev
->broadcast
,
1930 card
->dev
->addr_len
);
1932 card
->stats
.multicast
++;
1933 skb
->pkt_type
= PACKET_MULTICAST
;
1935 case QETH_CAST_BROADCAST
:
1936 memcpy(tg_addr
, card
->dev
->broadcast
,
1937 card
->dev
->addr_len
);
1938 card
->stats
.multicast
++;
1939 skb
->pkt_type
= PACKET_BROADCAST
;
1941 case QETH_CAST_UNICAST
:
1942 case QETH_CAST_ANYCAST
:
1943 case QETH_CAST_NOCAST
:
1945 if (card
->options
.sniffer
)
1946 skb
->pkt_type
= PACKET_OTHERHOST
;
1948 skb
->pkt_type
= PACKET_HOST
;
1949 memcpy(tg_addr
, card
->dev
->dev_addr
,
1950 card
->dev
->addr_len
);
1952 if (hdr
->hdr
.l3
.ext_flags
& QETH_HDR_EXT_SRC_MAC_ADDR
)
1953 card
->dev
->header_ops
->create(skb
, card
->dev
, prot
,
1954 tg_addr
, &hdr
->hdr
.l3
.dest_addr
[2],
1955 card
->dev
->addr_len
);
1957 card
->dev
->header_ops
->create(skb
, card
->dev
, prot
,
1958 tg_addr
, "FAKELL", card
->dev
->addr_len
);
1962 if (card
->dev
->type
== ARPHRD_IEEE802_TR
)
1963 skb
->protocol
= tr_type_trans(skb
, card
->dev
);
1966 skb
->protocol
= eth_type_trans(skb
, card
->dev
);
1968 if (hdr
->hdr
.l3
.ext_flags
&
1969 (QETH_HDR_EXT_VLAN_FRAME
| QETH_HDR_EXT_INCLUDE_VLAN_TAG
)) {
1970 *vlan_id
= (hdr
->hdr
.l3
.ext_flags
& QETH_HDR_EXT_VLAN_FRAME
) ?
1971 hdr
->hdr
.l3
.vlan_id
: *((u16
*)&hdr
->hdr
.l3
.dest_addr
[12]);
1975 if (card
->dev
->features
& NETIF_F_RXCSUM
) {
1976 if ((hdr
->hdr
.l3
.ext_flags
&
1977 (QETH_HDR_EXT_CSUM_HDR_REQ
|
1978 QETH_HDR_EXT_CSUM_TRANSP_REQ
)) ==
1979 (QETH_HDR_EXT_CSUM_HDR_REQ
|
1980 QETH_HDR_EXT_CSUM_TRANSP_REQ
))
1981 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
1983 skb
->ip_summed
= CHECKSUM_NONE
;
1985 skb
->ip_summed
= CHECKSUM_NONE
;
1990 static int qeth_l3_process_inbound_buffer(struct qeth_card
*card
,
1991 int budget
, int *done
)
1994 struct sk_buff
*skb
;
1995 struct qeth_hdr
*hdr
;
2003 skb
= qeth_core_get_next_skb(card
,
2004 card
->qdio
.in_q
->bufs
[card
->rx
.b_index
].buffer
,
2005 &card
->rx
.b_element
, &card
->rx
.e_offset
, &hdr
);
2010 skb
->dev
= card
->dev
;
2011 switch (hdr
->hdr
.l3
.id
) {
2012 case QETH_HEADER_TYPE_LAYER3
:
2013 is_vlan
= qeth_l3_rebuild_skb(card
, skb
, hdr
,
2016 if (is_vlan
&& !card
->options
.sniffer
)
2017 vlan_gro_receive(&card
->napi
, card
->vlangrp
,
2020 napi_gro_receive(&card
->napi
, skb
);
2022 case QETH_HEADER_TYPE_LAYER2
: /* for HiperSockets sniffer */
2023 skb
->pkt_type
= PACKET_HOST
;
2024 skb
->protocol
= eth_type_trans(skb
, skb
->dev
);
2026 netif_receive_skb(skb
);
2029 dev_kfree_skb_any(skb
);
2030 QETH_CARD_TEXT(card
, 3, "inbunkno");
2031 QETH_DBF_HEX(CTRL
, 3, hdr
, QETH_DBF_CTRL_LEN
);
2036 card
->stats
.rx_packets
++;
2037 card
->stats
.rx_bytes
+= len
;
2042 static int qeth_l3_poll(struct napi_struct
*napi
, int budget
)
2044 struct qeth_card
*card
= container_of(napi
, struct qeth_card
, napi
);
2046 struct qeth_qdio_buffer
*buffer
;
2048 int new_budget
= budget
;
2050 if (card
->options
.performance_stats
) {
2051 card
->perf_stats
.inbound_cnt
++;
2052 card
->perf_stats
.inbound_start_time
= qeth_get_micros();
2056 if (!card
->rx
.b_count
) {
2057 card
->rx
.qdio_err
= 0;
2058 card
->rx
.b_count
= qdio_get_next_buffers(
2059 card
->data
.ccwdev
, 0, &card
->rx
.b_index
,
2060 &card
->rx
.qdio_err
);
2061 if (card
->rx
.b_count
<= 0) {
2062 card
->rx
.b_count
= 0;
2065 card
->rx
.b_element
=
2066 &card
->qdio
.in_q
->bufs
[card
->rx
.b_index
]
2067 .buffer
->element
[0];
2068 card
->rx
.e_offset
= 0;
2071 while (card
->rx
.b_count
) {
2072 buffer
= &card
->qdio
.in_q
->bufs
[card
->rx
.b_index
];
2073 if (!(card
->rx
.qdio_err
&&
2074 qeth_check_qdio_errors(card
, buffer
->buffer
,
2075 card
->rx
.qdio_err
, "qinerr")))
2076 work_done
+= qeth_l3_process_inbound_buffer(
2077 card
, new_budget
, &done
);
2082 if (card
->options
.performance_stats
)
2083 card
->perf_stats
.bufs_rec
++;
2084 qeth_put_buffer_pool_entry(card
,
2085 buffer
->pool_entry
);
2086 qeth_queue_input_buffer(card
, card
->rx
.b_index
);
2088 if (card
->rx
.b_count
) {
2090 (card
->rx
.b_index
+ 1) %
2091 QDIO_MAX_BUFFERS_PER_Q
;
2092 card
->rx
.b_element
=
2094 ->bufs
[card
->rx
.b_index
]
2095 .buffer
->element
[0];
2096 card
->rx
.e_offset
= 0;
2100 if (work_done
>= budget
)
2103 new_budget
= budget
- work_done
;
2107 napi_complete(napi
);
2108 if (qdio_start_irq(card
->data
.ccwdev
, 0))
2109 napi_schedule(&card
->napi
);
2111 if (card
->options
.performance_stats
)
2112 card
->perf_stats
.inbound_time
+= qeth_get_micros() -
2113 card
->perf_stats
.inbound_start_time
;
2117 static int qeth_l3_verify_vlan_dev(struct net_device
*dev
,
2118 struct qeth_card
*card
)
2121 struct vlan_group
*vg
;
2128 for (i
= 0; i
< VLAN_N_VID
; i
++) {
2129 if (vlan_group_get_device(vg
, i
) == dev
) {
2130 rc
= QETH_VLAN_CARD
;
2135 if (rc
&& !(vlan_dev_real_dev(dev
)->ml_priv
== (void *)card
))
2141 static int qeth_l3_verify_dev(struct net_device
*dev
)
2143 struct qeth_card
*card
;
2144 unsigned long flags
;
2147 read_lock_irqsave(&qeth_core_card_list
.rwlock
, flags
);
2148 list_for_each_entry(card
, &qeth_core_card_list
.list
, list
) {
2149 if (card
->dev
== dev
) {
2150 rc
= QETH_REAL_CARD
;
2153 rc
= qeth_l3_verify_vlan_dev(dev
, card
);
2157 read_unlock_irqrestore(&qeth_core_card_list
.rwlock
, flags
);
2162 static struct qeth_card
*qeth_l3_get_card_from_dev(struct net_device
*dev
)
2164 struct qeth_card
*card
= NULL
;
2167 rc
= qeth_l3_verify_dev(dev
);
2168 if (rc
== QETH_REAL_CARD
)
2169 card
= dev
->ml_priv
;
2170 else if (rc
== QETH_VLAN_CARD
)
2171 card
= vlan_dev_real_dev(dev
)->ml_priv
;
2172 if (card
&& card
->options
.layer2
)
2175 QETH_CARD_TEXT_(card
, 4, "%d", rc
);
2179 static int qeth_l3_stop_card(struct qeth_card
*card
, int recovery_mode
)
2183 QETH_DBF_TEXT(SETUP
, 2, "stopcard");
2184 QETH_DBF_HEX(SETUP
, 2, &card
, sizeof(void *));
2186 qeth_set_allowed_threads(card
, 0, 1);
2187 if (card
->options
.sniffer
&&
2188 (card
->info
.promisc_mode
== SET_PROMISC_MODE_ON
))
2189 qeth_diags_trace(card
, QETH_DIAGS_CMD_TRACE_DISABLE
);
2190 if (card
->read
.state
== CH_STATE_UP
&&
2191 card
->write
.state
== CH_STATE_UP
&&
2192 (card
->state
== CARD_STATE_UP
)) {
2194 qeth_l3_stop(card
->dev
);
2197 dev_close(card
->dev
);
2200 card
->state
= CARD_STATE_SOFTSETUP
;
2202 if (card
->state
== CARD_STATE_SOFTSETUP
) {
2203 qeth_l3_clear_ip_list(card
, 1);
2204 qeth_clear_ipacmd_list(card
);
2205 card
->state
= CARD_STATE_HARDSETUP
;
2207 if (card
->state
== CARD_STATE_HARDSETUP
) {
2208 qeth_qdio_clear_card(card
, 0);
2209 qeth_clear_qdio_buffers(card
);
2210 qeth_clear_working_pool_list(card
);
2211 card
->state
= CARD_STATE_DOWN
;
2213 if (card
->state
== CARD_STATE_DOWN
) {
2214 qeth_clear_cmd_buffers(&card
->read
);
2215 qeth_clear_cmd_buffers(&card
->write
);
2221 * test for and Switch promiscuous mode (on or off)
2222 * either for guestlan or HiperSocket Sniffer
2225 qeth_l3_handle_promisc_mode(struct qeth_card
*card
)
2227 struct net_device
*dev
= card
->dev
;
2229 if (((dev
->flags
& IFF_PROMISC
) &&
2230 (card
->info
.promisc_mode
== SET_PROMISC_MODE_ON
)) ||
2231 (!(dev
->flags
& IFF_PROMISC
) &&
2232 (card
->info
.promisc_mode
== SET_PROMISC_MODE_OFF
)))
2235 if (card
->info
.guestlan
) { /* Guestlan trace */
2236 if (qeth_adp_supported(card
, IPA_SETADP_SET_PROMISC_MODE
))
2237 qeth_setadp_promisc_mode(card
);
2238 } else if (card
->options
.sniffer
&& /* HiperSockets trace */
2239 qeth_adp_supported(card
, IPA_SETADP_SET_DIAG_ASSIST
)) {
2240 if (dev
->flags
& IFF_PROMISC
) {
2241 QETH_CARD_TEXT(card
, 3, "+promisc");
2242 qeth_diags_trace(card
, QETH_DIAGS_CMD_TRACE_ENABLE
);
2244 QETH_CARD_TEXT(card
, 3, "-promisc");
2245 qeth_diags_trace(card
, QETH_DIAGS_CMD_TRACE_DISABLE
);
2250 static void qeth_l3_set_multicast_list(struct net_device
*dev
)
2252 struct qeth_card
*card
= dev
->ml_priv
;
2254 QETH_CARD_TEXT(card
, 3, "setmulti");
2255 if (qeth_threads_running(card
, QETH_RECOVER_THREAD
) &&
2256 (card
->state
!= CARD_STATE_UP
))
2258 if (!card
->options
.sniffer
) {
2259 qeth_l3_delete_mc_addresses(card
);
2260 qeth_l3_add_multicast_ipv4(card
);
2261 #ifdef CONFIG_QETH_IPV6
2262 qeth_l3_add_multicast_ipv6(card
);
2264 qeth_l3_set_ip_addr_list(card
);
2265 if (!qeth_adp_supported(card
, IPA_SETADP_SET_PROMISC_MODE
))
2268 qeth_l3_handle_promisc_mode(card
);
2271 static const char *qeth_l3_arp_get_error_cause(int *rc
)
2274 case QETH_IPA_ARP_RC_FAILED
:
2276 return "operation failed";
2277 case QETH_IPA_ARP_RC_NOTSUPP
:
2279 return "operation not supported";
2280 case QETH_IPA_ARP_RC_OUT_OF_RANGE
:
2282 return "argument out of range";
2283 case QETH_IPA_ARP_RC_Q_NOTSUPP
:
2285 return "query operation not supported";
2286 case QETH_IPA_ARP_RC_Q_NO_DATA
:
2288 return "no query data available";
2290 return "unknown error";
2294 static int qeth_l3_arp_set_no_entries(struct qeth_card
*card
, int no_entries
)
2299 QETH_CARD_TEXT(card
, 3, "arpstnoe");
2302 * currently GuestLAN only supports the ARP assist function
2303 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_SET_NO_ENTRIES;
2304 * thus we say EOPNOTSUPP for this ARP function
2306 if (card
->info
.guestlan
)
2308 if (!qeth_is_supported(card
, IPA_ARP_PROCESSING
)) {
2311 rc
= qeth_l3_send_simple_setassparms(card
, IPA_ARP_PROCESSING
,
2312 IPA_CMD_ASS_ARP_SET_NO_ENTRIES
,
2316 QETH_DBF_MESSAGE(2, "Could not set number of ARP entries on "
2317 "%s: %s (0x%x/%d)\n", QETH_CARD_IFNAME(card
),
2318 qeth_l3_arp_get_error_cause(&rc
), tmp
, tmp
);
2323 static __u32
get_arp_entry_size(struct qeth_card
*card
,
2324 struct qeth_arp_query_data
*qdata
,
2325 struct qeth_arp_entrytype
*type
, __u8 strip_entries
)
2330 is_hsi
= qdata
->reply_bits
== 5;
2331 if (type
->ip
== QETHARP_IP_ADDR_V4
) {
2332 QETH_CARD_TEXT(card
, 4, "arpev4");
2333 if (strip_entries
) {
2334 rc
= is_hsi
? sizeof(struct qeth_arp_qi_entry5_short
) :
2335 sizeof(struct qeth_arp_qi_entry7_short
);
2337 rc
= is_hsi
? sizeof(struct qeth_arp_qi_entry5
) :
2338 sizeof(struct qeth_arp_qi_entry7
);
2340 } else if (type
->ip
== QETHARP_IP_ADDR_V6
) {
2341 QETH_CARD_TEXT(card
, 4, "arpev6");
2342 if (strip_entries
) {
2344 sizeof(struct qeth_arp_qi_entry5_short_ipv6
) :
2345 sizeof(struct qeth_arp_qi_entry7_short_ipv6
);
2348 sizeof(struct qeth_arp_qi_entry5_ipv6
) :
2349 sizeof(struct qeth_arp_qi_entry7_ipv6
);
2352 QETH_CARD_TEXT(card
, 4, "arpinv");
2359 static int arpentry_matches_prot(struct qeth_arp_entrytype
*type
, __u16 prot
)
2361 return (type
->ip
== QETHARP_IP_ADDR_V4
&& prot
== QETH_PROT_IPV4
) ||
2362 (type
->ip
== QETHARP_IP_ADDR_V6
&& prot
== QETH_PROT_IPV6
);
2365 static int qeth_l3_arp_query_cb(struct qeth_card
*card
,
2366 struct qeth_reply
*reply
, unsigned long data
)
2368 struct qeth_ipa_cmd
*cmd
;
2369 struct qeth_arp_query_data
*qdata
;
2370 struct qeth_arp_query_info
*qinfo
;
2373 int entrybytes_done
;
2375 __u8 do_strip_entries
;
2377 QETH_CARD_TEXT(card
, 3, "arpquecb");
2379 qinfo
= (struct qeth_arp_query_info
*) reply
->param
;
2380 cmd
= (struct qeth_ipa_cmd
*) data
;
2381 QETH_CARD_TEXT_(card
, 4, "%i", cmd
->hdr
.prot_version
);
2382 if (cmd
->hdr
.return_code
) {
2383 QETH_CARD_TEXT(card
, 4, "arpcberr");
2384 QETH_CARD_TEXT_(card
, 4, "%i", cmd
->hdr
.return_code
);
2387 if (cmd
->data
.setassparms
.hdr
.return_code
) {
2388 cmd
->hdr
.return_code
= cmd
->data
.setassparms
.hdr
.return_code
;
2389 QETH_CARD_TEXT(card
, 4, "setaperr");
2390 QETH_CARD_TEXT_(card
, 4, "%i", cmd
->hdr
.return_code
);
2393 qdata
= &cmd
->data
.setassparms
.data
.query_arp
;
2394 QETH_CARD_TEXT_(card
, 4, "anoen%i", qdata
->no_entries
);
2396 do_strip_entries
= (qinfo
->mask_bits
& QETH_QARP_STRIP_ENTRIES
) > 0;
2397 stripped_bytes
= do_strip_entries
? QETH_QARP_MEDIASPECIFIC_BYTES
: 0;
2398 entrybytes_done
= 0;
2399 for (e
= 0; e
< qdata
->no_entries
; ++e
) {
2402 struct qeth_arp_entrytype
*etype
;
2404 cur_entry
= &qdata
->data
+ entrybytes_done
;
2405 etype
= &((struct qeth_arp_qi_entry5
*) cur_entry
)->type
;
2406 if (!arpentry_matches_prot(etype
, cmd
->hdr
.prot_version
)) {
2407 QETH_CARD_TEXT(card
, 4, "pmis");
2408 QETH_CARD_TEXT_(card
, 4, "%i", etype
->ip
);
2411 esize
= get_arp_entry_size(card
, qdata
, etype
,
2413 QETH_CARD_TEXT_(card
, 5, "esz%i", esize
);
2417 if ((qinfo
->udata_len
- qinfo
->udata_offset
) < esize
) {
2418 QETH_CARD_TEXT_(card
, 4, "qaer3%i", -ENOMEM
);
2419 cmd
->hdr
.return_code
= -ENOMEM
;
2423 memcpy(qinfo
->udata
+ qinfo
->udata_offset
,
2424 &qdata
->data
+ entrybytes_done
+ stripped_bytes
,
2426 entrybytes_done
+= esize
+ stripped_bytes
;
2427 qinfo
->udata_offset
+= esize
;
2428 ++qinfo
->no_entries
;
2430 /* check if all replies received ... */
2431 if (cmd
->data
.setassparms
.hdr
.seq_no
<
2432 cmd
->data
.setassparms
.hdr
.number_of_replies
)
2434 QETH_CARD_TEXT_(card
, 4, "nove%i", qinfo
->no_entries
);
2435 memcpy(qinfo
->udata
, &qinfo
->no_entries
, 4);
2436 /* keep STRIP_ENTRIES flag so the user program can distinguish
2437 * stripped entries from normal ones */
2438 if (qinfo
->mask_bits
& QETH_QARP_STRIP_ENTRIES
)
2439 qdata
->reply_bits
|= QETH_QARP_STRIP_ENTRIES
;
2440 memcpy(qinfo
->udata
+ QETH_QARP_MASK_OFFSET
, &qdata
->reply_bits
, 2);
2441 QETH_CARD_TEXT_(card
, 4, "rc%i", 0);
2445 memcpy(qinfo
->udata
, &i
, 4);
2449 static int qeth_l3_send_ipa_arp_cmd(struct qeth_card
*card
,
2450 struct qeth_cmd_buffer
*iob
, int len
,
2451 int (*reply_cb
)(struct qeth_card
*, struct qeth_reply
*,
2455 QETH_CARD_TEXT(card
, 4, "sendarp");
2457 memcpy(iob
->data
, IPA_PDU_HEADER
, IPA_PDU_HEADER_SIZE
);
2458 memcpy(QETH_IPA_CMD_DEST_ADDR(iob
->data
),
2459 &card
->token
.ulp_connection_r
, QETH_MPC_TOKEN_LENGTH
);
2460 return qeth_send_control_data(card
, IPA_PDU_HEADER_SIZE
+ len
, iob
,
2461 reply_cb
, reply_param
);
2464 static int qeth_l3_query_arp_cache_info(struct qeth_card
*card
,
2465 enum qeth_prot_versions prot
,
2466 struct qeth_arp_query_info
*qinfo
)
2468 struct qeth_cmd_buffer
*iob
;
2469 struct qeth_ipa_cmd
*cmd
;
2473 QETH_CARD_TEXT_(card
, 3, "qarpipv%i", prot
);
2475 iob
= qeth_l3_get_setassparms_cmd(card
, IPA_ARP_PROCESSING
,
2476 IPA_CMD_ASS_ARP_QUERY_INFO
,
2477 sizeof(struct qeth_arp_query_data
) - sizeof(char),
2479 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
2480 cmd
->data
.setassparms
.data
.query_arp
.request_bits
= 0x000F;
2481 cmd
->data
.setassparms
.data
.query_arp
.reply_bits
= 0;
2482 cmd
->data
.setassparms
.data
.query_arp
.no_entries
= 0;
2483 rc
= qeth_l3_send_ipa_arp_cmd(card
, iob
,
2484 QETH_SETASS_BASE_LEN
+QETH_ARP_CMD_LEN
,
2485 qeth_l3_arp_query_cb
, (void *)qinfo
);
2489 "Error while querying ARP cache on %s: %s "
2490 "(0x%x/%d)\n", QETH_CARD_IFNAME(card
),
2491 qeth_l3_arp_get_error_cause(&rc
), tmp
, tmp
);
2497 static int qeth_l3_arp_query(struct qeth_card
*card
, char __user
*udata
)
2499 struct qeth_arp_query_info qinfo
= {0, };
2502 QETH_CARD_TEXT(card
, 3, "arpquery");
2504 if (!qeth_is_supported(card
,/*IPA_QUERY_ARP_ADDR_INFO*/
2505 IPA_ARP_PROCESSING
)) {
2506 QETH_CARD_TEXT(card
, 3, "arpqnsup");
2510 /* get size of userspace buffer and mask_bits -> 6 bytes */
2511 if (copy_from_user(&qinfo
, udata
, 6)) {
2515 qinfo
.udata
= kzalloc(qinfo
.udata_len
, GFP_KERNEL
);
2520 qinfo
.udata_offset
= QETH_QARP_ENTRIES_OFFSET
;
2521 rc
= qeth_l3_query_arp_cache_info(card
, QETH_PROT_IPV4
, &qinfo
);
2523 if (copy_to_user(udata
, qinfo
.udata
, 4))
2527 #ifdef CONFIG_QETH_IPV6
2528 if (qinfo
.mask_bits
& QETH_QARP_WITH_IPV6
) {
2529 /* fails in case of GuestLAN QDIO mode */
2530 qeth_l3_query_arp_cache_info(card
, QETH_PROT_IPV6
,
2534 if (copy_to_user(udata
, qinfo
.udata
, qinfo
.udata_len
)) {
2535 QETH_CARD_TEXT(card
, 4, "qactf");
2539 QETH_CARD_TEXT_(card
, 4, "qacts");
2547 static int qeth_l3_arp_add_entry(struct qeth_card
*card
,
2548 struct qeth_arp_cache_entry
*entry
)
2550 struct qeth_cmd_buffer
*iob
;
2555 QETH_CARD_TEXT(card
, 3, "arpadent");
2558 * currently GuestLAN only supports the ARP assist function
2559 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_ADD_ENTRY;
2560 * thus we say EOPNOTSUPP for this ARP function
2562 if (card
->info
.guestlan
)
2564 if (!qeth_is_supported(card
, IPA_ARP_PROCESSING
)) {
2568 iob
= qeth_l3_get_setassparms_cmd(card
, IPA_ARP_PROCESSING
,
2569 IPA_CMD_ASS_ARP_ADD_ENTRY
,
2570 sizeof(struct qeth_arp_cache_entry
),
2572 rc
= qeth_l3_send_setassparms(card
, iob
,
2573 sizeof(struct qeth_arp_cache_entry
),
2574 (unsigned long) entry
,
2575 qeth_l3_default_setassparms_cb
, NULL
);
2578 qeth_l3_ipaddr4_to_string((u8
*)entry
->ipaddr
, buf
);
2579 QETH_DBF_MESSAGE(2, "Could not add ARP entry for address %s "
2580 "on %s: %s (0x%x/%d)\n", buf
, QETH_CARD_IFNAME(card
),
2581 qeth_l3_arp_get_error_cause(&rc
), tmp
, tmp
);
2586 static int qeth_l3_arp_remove_entry(struct qeth_card
*card
,
2587 struct qeth_arp_cache_entry
*entry
)
2589 struct qeth_cmd_buffer
*iob
;
2590 char buf
[16] = {0, };
2594 QETH_CARD_TEXT(card
, 3, "arprment");
2597 * currently GuestLAN only supports the ARP assist function
2598 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_REMOVE_ENTRY;
2599 * thus we say EOPNOTSUPP for this ARP function
2601 if (card
->info
.guestlan
)
2603 if (!qeth_is_supported(card
, IPA_ARP_PROCESSING
)) {
2606 memcpy(buf
, entry
, 12);
2607 iob
= qeth_l3_get_setassparms_cmd(card
, IPA_ARP_PROCESSING
,
2608 IPA_CMD_ASS_ARP_REMOVE_ENTRY
,
2611 rc
= qeth_l3_send_setassparms(card
, iob
,
2612 12, (unsigned long)buf
,
2613 qeth_l3_default_setassparms_cb
, NULL
);
2617 qeth_l3_ipaddr4_to_string((u8
*)entry
->ipaddr
, buf
);
2618 QETH_DBF_MESSAGE(2, "Could not delete ARP entry for address %s"
2619 " on %s: %s (0x%x/%d)\n", buf
, QETH_CARD_IFNAME(card
),
2620 qeth_l3_arp_get_error_cause(&rc
), tmp
, tmp
);
2625 static int qeth_l3_arp_flush_cache(struct qeth_card
*card
)
2630 QETH_CARD_TEXT(card
, 3, "arpflush");
2633 * currently GuestLAN only supports the ARP assist function
2634 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_FLUSH_CACHE;
2635 * thus we say EOPNOTSUPP for this ARP function
2637 if (card
->info
.guestlan
|| (card
->info
.type
== QETH_CARD_TYPE_IQD
))
2639 if (!qeth_is_supported(card
, IPA_ARP_PROCESSING
)) {
2642 rc
= qeth_l3_send_simple_setassparms(card
, IPA_ARP_PROCESSING
,
2643 IPA_CMD_ASS_ARP_FLUSH_CACHE
, 0);
2646 QETH_DBF_MESSAGE(2, "Could not flush ARP cache on %s: %s "
2647 "(0x%x/%d)\n", QETH_CARD_IFNAME(card
),
2648 qeth_l3_arp_get_error_cause(&rc
), tmp
, tmp
);
2653 static int qeth_l3_do_ioctl(struct net_device
*dev
, struct ifreq
*rq
, int cmd
)
2655 struct qeth_card
*card
= dev
->ml_priv
;
2656 struct qeth_arp_cache_entry arp_entry
;
2657 struct mii_ioctl_data
*mii_data
;
2663 if ((card
->state
!= CARD_STATE_UP
) &&
2664 (card
->state
!= CARD_STATE_SOFTSETUP
))
2668 case SIOC_QETH_ARP_SET_NO_ENTRIES
:
2669 if (!capable(CAP_NET_ADMIN
)) {
2673 rc
= qeth_l3_arp_set_no_entries(card
, rq
->ifr_ifru
.ifru_ivalue
);
2675 case SIOC_QETH_ARP_QUERY_INFO
:
2676 if (!capable(CAP_NET_ADMIN
)) {
2680 rc
= qeth_l3_arp_query(card
, rq
->ifr_ifru
.ifru_data
);
2682 case SIOC_QETH_ARP_ADD_ENTRY
:
2683 if (!capable(CAP_NET_ADMIN
)) {
2687 if (copy_from_user(&arp_entry
, rq
->ifr_ifru
.ifru_data
,
2688 sizeof(struct qeth_arp_cache_entry
)))
2691 rc
= qeth_l3_arp_add_entry(card
, &arp_entry
);
2693 case SIOC_QETH_ARP_REMOVE_ENTRY
:
2694 if (!capable(CAP_NET_ADMIN
)) {
2698 if (copy_from_user(&arp_entry
, rq
->ifr_ifru
.ifru_data
,
2699 sizeof(struct qeth_arp_cache_entry
)))
2702 rc
= qeth_l3_arp_remove_entry(card
, &arp_entry
);
2704 case SIOC_QETH_ARP_FLUSH_CACHE
:
2705 if (!capable(CAP_NET_ADMIN
)) {
2709 rc
= qeth_l3_arp_flush_cache(card
);
2711 case SIOC_QETH_ADP_SET_SNMP_CONTROL
:
2712 rc
= qeth_snmp_command(card
, rq
->ifr_ifru
.ifru_data
);
2714 case SIOC_QETH_GET_CARD_TYPE
:
2715 if ((card
->info
.type
== QETH_CARD_TYPE_OSD
||
2716 card
->info
.type
== QETH_CARD_TYPE_OSX
) &&
2717 !card
->info
.guestlan
)
2722 mii_data
= if_mii(rq
);
2723 mii_data
->phy_id
= 0;
2726 mii_data
= if_mii(rq
);
2727 if (mii_data
->phy_id
!= 0)
2730 mii_data
->val_out
= qeth_mdio_read(dev
,
2738 QETH_CARD_TEXT_(card
, 2, "ioce%d", rc
);
2742 int inline qeth_l3_get_cast_type(struct qeth_card
*card
, struct sk_buff
*skb
)
2744 int cast_type
= RTN_UNSPEC
;
2745 struct neighbour
*n
= NULL
;
2746 struct dst_entry
*dst
;
2750 n
= dst_get_neighbour(dst
);
2752 cast_type
= n
->type
;
2753 if ((cast_type
== RTN_BROADCAST
) ||
2754 (cast_type
== RTN_MULTICAST
) ||
2755 (cast_type
== RTN_ANYCAST
))
2760 /* try something else */
2761 if (skb
->protocol
== ETH_P_IPV6
)
2762 return (skb_network_header(skb
)[24] == 0xff) ?
2764 else if (skb
->protocol
== ETH_P_IP
)
2765 return ((skb_network_header(skb
)[16] & 0xf0) == 0xe0) ?
2768 if (!memcmp(skb
->data
, skb
->dev
->broadcast
, 6))
2769 return RTN_BROADCAST
;
2773 hdr_mac
= *((u16
*)skb
->data
);
2775 switch (card
->info
.link_type
) {
2776 case QETH_LINK_TYPE_HSTR
:
2777 case QETH_LINK_TYPE_LANE_TR
:
2778 if ((hdr_mac
== QETH_TR_MAC_NC
) ||
2779 (hdr_mac
== QETH_TR_MAC_C
))
2780 return RTN_MULTICAST
;
2782 /* eth or so multicast? */
2784 if ((hdr_mac
== QETH_ETH_MAC_V4
) ||
2785 (hdr_mac
== QETH_ETH_MAC_V6
))
2786 return RTN_MULTICAST
;
2792 static void qeth_l3_fill_header(struct qeth_card
*card
, struct qeth_hdr
*hdr
,
2793 struct sk_buff
*skb
, int ipv
, int cast_type
)
2795 struct neighbour
*n
= NULL
;
2796 struct dst_entry
*dst
;
2798 memset(hdr
, 0, sizeof(struct qeth_hdr
));
2799 hdr
->hdr
.l3
.id
= QETH_HEADER_TYPE_LAYER3
;
2800 hdr
->hdr
.l3
.ext_flags
= 0;
2803 * before we're going to overwrite this location with next hop ip.
2804 * v6 uses passthrough, v4 sets the tag in the QDIO header.
2806 if (card
->vlangrp
&& vlan_tx_tag_present(skb
)) {
2807 if ((ipv
== 4) || (card
->info
.type
== QETH_CARD_TYPE_IQD
))
2808 hdr
->hdr
.l3
.ext_flags
= QETH_HDR_EXT_VLAN_FRAME
;
2810 hdr
->hdr
.l3
.ext_flags
= QETH_HDR_EXT_INCLUDE_VLAN_TAG
;
2811 hdr
->hdr
.l3
.vlan_id
= vlan_tx_tag_get(skb
);
2814 hdr
->hdr
.l3
.length
= skb
->len
- sizeof(struct qeth_hdr
);
2817 n
= dst_get_neighbour(dst
);
2820 hdr
->hdr
.l3
.flags
= qeth_l3_get_qeth_hdr_flags4(cast_type
);
2821 memset(hdr
->hdr
.l3
.dest_addr
, 0, 12);
2823 *((u32
*) (&hdr
->hdr
.l3
.dest_addr
[12])) =
2824 *((u32
*) n
->primary_key
);
2826 /* fill in destination address used in ip header */
2827 *((u32
*) (&hdr
->hdr
.l3
.dest_addr
[12])) =
2830 } else if (ipv
== 6) {
2832 hdr
->hdr
.l3
.flags
= qeth_l3_get_qeth_hdr_flags6(cast_type
);
2833 if (card
->info
.type
== QETH_CARD_TYPE_IQD
)
2834 hdr
->hdr
.l3
.flags
&= ~QETH_HDR_PASSTHRU
;
2836 memcpy(hdr
->hdr
.l3
.dest_addr
,
2837 n
->primary_key
, 16);
2839 /* fill in destination address used in ip header */
2840 memcpy(hdr
->hdr
.l3
.dest_addr
,
2841 &ipv6_hdr(skb
)->daddr
, 16);
2845 if ((skb
->dev
->type
== ARPHRD_IEEE802_TR
) &&
2846 !memcmp(skb
->data
+ sizeof(struct qeth_hdr
) +
2847 sizeof(__u16
), skb
->dev
->broadcast
, 6)) {
2848 hdr
->hdr
.l3
.flags
= QETH_CAST_BROADCAST
|
2850 } else if (!memcmp(skb
->data
+ sizeof(struct qeth_hdr
),
2851 skb
->dev
->broadcast
, 6)) {
2853 hdr
->hdr
.l3
.flags
= QETH_CAST_BROADCAST
|
2856 hdr
->hdr
.l3
.flags
= (cast_type
== RTN_MULTICAST
) ?
2857 QETH_CAST_MULTICAST
| QETH_HDR_PASSTHRU
:
2858 QETH_CAST_UNICAST
| QETH_HDR_PASSTHRU
;
2863 static inline void qeth_l3_hdr_csum(struct qeth_card
*card
,
2864 struct qeth_hdr
*hdr
, struct sk_buff
*skb
)
2866 struct iphdr
*iph
= ip_hdr(skb
);
2868 /* tcph->check contains already the pseudo hdr checksum
2869 * so just set the header flags
2871 if (iph
->protocol
== IPPROTO_UDP
)
2872 hdr
->hdr
.l3
.ext_flags
|= QETH_HDR_EXT_UDP
;
2873 hdr
->hdr
.l3
.ext_flags
|= QETH_HDR_EXT_CSUM_TRANSP_REQ
|
2874 QETH_HDR_EXT_CSUM_HDR_REQ
;
2876 if (card
->options
.performance_stats
)
2877 card
->perf_stats
.tx_csum
++;
2880 static void qeth_tso_fill_header(struct qeth_card
*card
,
2881 struct qeth_hdr
*qhdr
, struct sk_buff
*skb
)
2883 struct qeth_hdr_tso
*hdr
= (struct qeth_hdr_tso
*)qhdr
;
2884 struct tcphdr
*tcph
= tcp_hdr(skb
);
2885 struct iphdr
*iph
= ip_hdr(skb
);
2886 struct ipv6hdr
*ip6h
= ipv6_hdr(skb
);
2888 /*fix header to TSO values ...*/
2889 hdr
->hdr
.hdr
.l3
.id
= QETH_HEADER_TYPE_TSO
;
2890 hdr
->hdr
.hdr
.l3
.length
= skb
->len
- sizeof(struct qeth_hdr_tso
);
2891 /*set values which are fix for the first approach ...*/
2892 hdr
->ext
.hdr_tot_len
= (__u16
) sizeof(struct qeth_hdr_ext_tso
);
2893 hdr
->ext
.imb_hdr_no
= 1;
2894 hdr
->ext
.hdr_type
= 1;
2895 hdr
->ext
.hdr_version
= 1;
2896 hdr
->ext
.hdr_len
= 28;
2897 /*insert non-fix values */
2898 hdr
->ext
.mss
= skb_shinfo(skb
)->gso_size
;
2899 hdr
->ext
.dg_hdr_len
= (__u16
)(iph
->ihl
*4 + tcph
->doff
*4);
2900 hdr
->ext
.payload_len
= (__u16
)(skb
->len
- hdr
->ext
.dg_hdr_len
-
2901 sizeof(struct qeth_hdr_tso
));
2903 if (skb
->protocol
== ETH_P_IPV6
) {
2904 ip6h
->payload_len
= 0;
2905 tcph
->check
= ~csum_ipv6_magic(&ip6h
->saddr
, &ip6h
->daddr
,
2908 /*OSA want us to set these values ...*/
2909 tcph
->check
= ~csum_tcpudp_magic(iph
->saddr
, iph
->daddr
,
2916 static inline int qeth_l3_tso_elements(struct sk_buff
*skb
)
2918 unsigned long tcpd
= (unsigned long)tcp_hdr(skb
) +
2919 tcp_hdr(skb
)->doff
* 4;
2920 int tcpd_len
= skb
->len
- (tcpd
- (unsigned long)skb
->data
);
2921 int elements
= PFN_UP(tcpd
+ tcpd_len
- 1) - PFN_DOWN(tcpd
);
2922 elements
+= skb_shinfo(skb
)->nr_frags
;
2926 static int qeth_l3_hard_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
2930 struct qeth_hdr
*hdr
= NULL
;
2931 int elements_needed
= 0;
2933 struct qeth_card
*card
= dev
->ml_priv
;
2934 struct sk_buff
*new_skb
= NULL
;
2935 int ipv
= qeth_get_ip_version(skb
);
2936 int cast_type
= qeth_l3_get_cast_type(card
, skb
);
2937 struct qeth_qdio_out_q
*queue
= card
->qdio
.out_qs
2938 [qeth_get_priority_queue(card
, skb
, ipv
, cast_type
)];
2939 int tx_bytes
= skb
->len
;
2941 int data_offset
= -1;
2944 if (((card
->info
.type
== QETH_CARD_TYPE_IQD
) && (!ipv
)) ||
2945 card
->options
.sniffer
)
2948 if ((card
->state
!= CARD_STATE_UP
) || !card
->lan_online
) {
2949 card
->stats
.tx_carrier_errors
++;
2953 if ((cast_type
== RTN_BROADCAST
) &&
2954 (card
->info
.broadcast_capable
== 0))
2957 if (card
->options
.performance_stats
) {
2958 card
->perf_stats
.outbound_cnt
++;
2959 card
->perf_stats
.outbound_start_time
= qeth_get_micros();
2962 large_send
= skb_is_gso(skb
);
2964 if ((card
->info
.type
== QETH_CARD_TYPE_IQD
) && (!large_send
) &&
2965 (skb_shinfo(skb
)->nr_frags
== 0)) {
2967 data_offset
= ETH_HLEN
;
2968 hdr
= kmem_cache_alloc(qeth_core_header_cache
, GFP_ATOMIC
);
2973 /* create a clone with writeable headroom */
2974 new_skb
= skb_realloc_headroom(skb
, sizeof(struct qeth_hdr_tso
)
2980 if (card
->info
.type
== QETH_CARD_TYPE_IQD
) {
2981 if (data_offset
< 0)
2982 skb_pull(new_skb
, ETH_HLEN
);
2985 if (card
->dev
->type
== ARPHRD_IEEE802_TR
)
2986 skb_pull(new_skb
, TR_HLEN
);
2988 skb_pull(new_skb
, ETH_HLEN
);
2991 if (ipv
!= 4 && card
->vlangrp
&&
2992 vlan_tx_tag_present(new_skb
)) {
2993 skb_push(new_skb
, VLAN_HLEN
);
2994 skb_copy_to_linear_data(new_skb
, new_skb
->data
+ 4, 4);
2995 skb_copy_to_linear_data_offset(new_skb
, 4,
2996 new_skb
->data
+ 8, 4);
2997 skb_copy_to_linear_data_offset(new_skb
, 8,
2998 new_skb
->data
+ 12, 4);
2999 tag
= (u16
*)(new_skb
->data
+ 12);
3000 *tag
= __constant_htons(ETH_P_8021Q
);
3001 *(tag
+ 1) = htons(vlan_tx_tag_get(new_skb
));
3002 new_skb
->vlan_tci
= 0;
3006 netif_stop_queue(dev
);
3008 /* fix hardware limitation: as long as we do not have sbal
3009 * chaining we can not send long frag lists
3012 if (qeth_l3_tso_elements(new_skb
) + 1 > 16) {
3013 if (skb_linearize(new_skb
))
3015 if (card
->options
.performance_stats
)
3016 card
->perf_stats
.tx_lin
++;
3020 if (large_send
&& (cast_type
== RTN_UNSPEC
)) {
3021 hdr
= (struct qeth_hdr
*)skb_push(new_skb
,
3022 sizeof(struct qeth_hdr_tso
));
3023 memset(hdr
, 0, sizeof(struct qeth_hdr_tso
));
3024 qeth_l3_fill_header(card
, hdr
, new_skb
, ipv
, cast_type
);
3025 qeth_tso_fill_header(card
, hdr
, new_skb
);
3028 if (data_offset
< 0) {
3029 hdr
= (struct qeth_hdr
*)skb_push(new_skb
,
3030 sizeof(struct qeth_hdr
));
3031 qeth_l3_fill_header(card
, hdr
, new_skb
, ipv
,
3034 qeth_l3_fill_header(card
, hdr
, new_skb
, ipv
,
3036 hdr
->hdr
.l3
.length
= new_skb
->len
- data_offset
;
3039 if (skb
->ip_summed
== CHECKSUM_PARTIAL
)
3040 qeth_l3_hdr_csum(card
, hdr
, new_skb
);
3043 elems
= qeth_get_elements_no(card
, (void *)hdr
, new_skb
,
3046 if (data_offset
>= 0)
3047 kmem_cache_free(qeth_core_header_cache
, hdr
);
3050 elements_needed
+= elems
;
3051 nr_frags
= skb_shinfo(new_skb
)->nr_frags
;
3053 if (card
->info
.type
!= QETH_CARD_TYPE_IQD
) {
3056 len
= ((unsigned long)tcp_hdr(new_skb
) +
3057 tcp_hdr(new_skb
)->doff
* 4) -
3058 (unsigned long)new_skb
->data
;
3060 len
= sizeof(struct qeth_hdr_layer3
);
3062 if (qeth_hdr_chk_and_bounce(new_skb
, len
))
3064 rc
= qeth_do_send_packet(card
, queue
, new_skb
, hdr
,
3067 rc
= qeth_do_send_packet_fast(card
, queue
, new_skb
, hdr
,
3068 elements_needed
, data_offset
, 0);
3071 card
->stats
.tx_packets
++;
3072 card
->stats
.tx_bytes
+= tx_bytes
;
3074 dev_kfree_skb_any(skb
);
3075 if (card
->options
.performance_stats
) {
3077 card
->perf_stats
.large_send_bytes
+= tx_bytes
;
3078 card
->perf_stats
.large_send_cnt
++;
3081 card
->perf_stats
.sg_skbs_sent
++;
3082 /* nr_frags + skb->data */
3083 card
->perf_stats
.sg_frags_sent
+= nr_frags
+ 1;
3088 if (data_offset
>= 0)
3089 kmem_cache_free(qeth_core_header_cache
, hdr
);
3093 dev_kfree_skb_any(new_skb
);
3094 return NETDEV_TX_BUSY
;
3099 netif_wake_queue(dev
);
3100 if (card
->options
.performance_stats
)
3101 card
->perf_stats
.outbound_time
+= qeth_get_micros() -
3102 card
->perf_stats
.outbound_start_time
;
3106 card
->stats
.tx_dropped
++;
3107 card
->stats
.tx_errors
++;
3108 if ((new_skb
!= skb
) && new_skb
)
3109 dev_kfree_skb_any(new_skb
);
3110 dev_kfree_skb_any(skb
);
3111 netif_wake_queue(dev
);
3112 return NETDEV_TX_OK
;
3115 static int __qeth_l3_open(struct net_device
*dev
)
3117 struct qeth_card
*card
= dev
->ml_priv
;
3120 QETH_CARD_TEXT(card
, 4, "qethopen");
3121 if (card
->state
== CARD_STATE_UP
)
3123 if (card
->state
!= CARD_STATE_SOFTSETUP
)
3125 card
->data
.state
= CH_STATE_UP
;
3126 card
->state
= CARD_STATE_UP
;
3127 netif_start_queue(dev
);
3129 if (qdio_stop_irq(card
->data
.ccwdev
, 0) >= 0) {
3130 napi_enable(&card
->napi
);
3131 napi_schedule(&card
->napi
);
3137 static int qeth_l3_open(struct net_device
*dev
)
3139 struct qeth_card
*card
= dev
->ml_priv
;
3141 QETH_CARD_TEXT(card
, 5, "qethope_");
3142 if (qeth_wait_for_threads(card
, QETH_RECOVER_THREAD
)) {
3143 QETH_CARD_TEXT(card
, 3, "openREC");
3144 return -ERESTARTSYS
;
3146 return __qeth_l3_open(dev
);
3149 static int qeth_l3_stop(struct net_device
*dev
)
3151 struct qeth_card
*card
= dev
->ml_priv
;
3153 QETH_CARD_TEXT(card
, 4, "qethstop");
3154 netif_tx_disable(dev
);
3155 if (card
->state
== CARD_STATE_UP
) {
3156 card
->state
= CARD_STATE_SOFTSETUP
;
3157 napi_disable(&card
->napi
);
3162 static u32
qeth_l3_fix_features(struct net_device
*dev
, u32 features
)
3164 struct qeth_card
*card
= dev
->ml_priv
;
3166 if (!qeth_is_supported(card
, IPA_OUTBOUND_CHECKSUM
))
3167 features
&= ~NETIF_F_IP_CSUM
;
3168 if (!qeth_is_supported(card
, IPA_OUTBOUND_TSO
))
3169 features
&= ~NETIF_F_TSO
;
3170 if (!qeth_is_supported(card
, IPA_INBOUND_CHECKSUM
))
3171 features
&= ~NETIF_F_RXCSUM
;
3176 static int qeth_l3_set_features(struct net_device
*dev
, u32 features
)
3178 struct qeth_card
*card
= dev
->ml_priv
;
3179 u32 changed
= dev
->features
^ features
;
3182 if (!(changed
& NETIF_F_RXCSUM
))
3185 if (card
->state
== CARD_STATE_DOWN
||
3186 card
->state
== CARD_STATE_RECOVER
)
3189 err
= qeth_l3_set_rx_csum(card
, features
& NETIF_F_RXCSUM
);
3191 dev
->features
= features
^ NETIF_F_RXCSUM
;
3196 static const struct ethtool_ops qeth_l3_ethtool_ops
= {
3197 .get_link
= ethtool_op_get_link
,
3198 .get_strings
= qeth_core_get_strings
,
3199 .get_ethtool_stats
= qeth_core_get_ethtool_stats
,
3200 .get_sset_count
= qeth_core_get_sset_count
,
3201 .get_drvinfo
= qeth_core_get_drvinfo
,
3202 .get_settings
= qeth_core_ethtool_get_settings
,
3206 * we need NOARP for IPv4 but we want neighbor solicitation for IPv6. Setting
3207 * NOARP on the netdevice is no option because it also turns off neighbor
3208 * solicitation. For IPv4 we install a neighbor_setup function. We don't want
3209 * arp resolution but we want the hard header (packet socket will work
3212 static int qeth_l3_neigh_setup_noarp(struct neighbour
*n
)
3214 n
->nud_state
= NUD_NOARP
;
3215 memcpy(n
->ha
, "FAKELL", 6);
3216 n
->output
= n
->ops
->connected_output
;
3221 qeth_l3_neigh_setup(struct net_device
*dev
, struct neigh_parms
*np
)
3223 if (np
->tbl
->family
== AF_INET
)
3224 np
->neigh_setup
= qeth_l3_neigh_setup_noarp
;
3229 static const struct net_device_ops qeth_l3_netdev_ops
= {
3230 .ndo_open
= qeth_l3_open
,
3231 .ndo_stop
= qeth_l3_stop
,
3232 .ndo_get_stats
= qeth_get_stats
,
3233 .ndo_start_xmit
= qeth_l3_hard_start_xmit
,
3234 .ndo_validate_addr
= eth_validate_addr
,
3235 .ndo_set_multicast_list
= qeth_l3_set_multicast_list
,
3236 .ndo_do_ioctl
= qeth_l3_do_ioctl
,
3237 .ndo_change_mtu
= qeth_change_mtu
,
3238 .ndo_fix_features
= qeth_l3_fix_features
,
3239 .ndo_set_features
= qeth_l3_set_features
,
3240 .ndo_vlan_rx_register
= qeth_l3_vlan_rx_register
,
3241 .ndo_vlan_rx_add_vid
= qeth_l3_vlan_rx_add_vid
,
3242 .ndo_vlan_rx_kill_vid
= qeth_l3_vlan_rx_kill_vid
,
3243 .ndo_tx_timeout
= qeth_tx_timeout
,
3246 static const struct net_device_ops qeth_l3_osa_netdev_ops
= {
3247 .ndo_open
= qeth_l3_open
,
3248 .ndo_stop
= qeth_l3_stop
,
3249 .ndo_get_stats
= qeth_get_stats
,
3250 .ndo_start_xmit
= qeth_l3_hard_start_xmit
,
3251 .ndo_validate_addr
= eth_validate_addr
,
3252 .ndo_set_multicast_list
= qeth_l3_set_multicast_list
,
3253 .ndo_do_ioctl
= qeth_l3_do_ioctl
,
3254 .ndo_change_mtu
= qeth_change_mtu
,
3255 .ndo_fix_features
= qeth_l3_fix_features
,
3256 .ndo_set_features
= qeth_l3_set_features
,
3257 .ndo_vlan_rx_register
= qeth_l3_vlan_rx_register
,
3258 .ndo_vlan_rx_add_vid
= qeth_l3_vlan_rx_add_vid
,
3259 .ndo_vlan_rx_kill_vid
= qeth_l3_vlan_rx_kill_vid
,
3260 .ndo_tx_timeout
= qeth_tx_timeout
,
3261 .ndo_neigh_setup
= qeth_l3_neigh_setup
,
3264 static int qeth_l3_setup_netdev(struct qeth_card
*card
)
3266 if (card
->info
.type
== QETH_CARD_TYPE_OSD
||
3267 card
->info
.type
== QETH_CARD_TYPE_OSX
) {
3268 if ((card
->info
.link_type
== QETH_LINK_TYPE_LANE_TR
) ||
3269 (card
->info
.link_type
== QETH_LINK_TYPE_HSTR
)) {
3271 card
->dev
= alloc_trdev(0);
3275 card
->dev
->netdev_ops
= &qeth_l3_netdev_ops
;
3277 card
->dev
= alloc_etherdev(0);
3280 card
->dev
->netdev_ops
= &qeth_l3_osa_netdev_ops
;
3282 /*IPv6 address autoconfiguration stuff*/
3283 qeth_l3_get_unique_id(card
);
3284 if (!(card
->info
.unique_id
& UNIQUE_ID_NOT_BY_CARD
))
3285 card
->dev
->dev_id
= card
->info
.unique_id
&
3287 if (!card
->info
.guestlan
) {
3288 card
->dev
->hw_features
= NETIF_F_SG
|
3289 NETIF_F_RXCSUM
| NETIF_F_IP_CSUM
|
3291 card
->dev
->features
= NETIF_F_RXCSUM
;
3294 } else if (card
->info
.type
== QETH_CARD_TYPE_IQD
) {
3295 card
->dev
= alloc_netdev(0, "hsi%d", ether_setup
);
3298 card
->dev
->flags
|= IFF_NOARP
;
3299 card
->dev
->netdev_ops
= &qeth_l3_netdev_ops
;
3300 qeth_l3_iqd_read_initial_mac(card
);
3304 card
->dev
->ml_priv
= card
;
3305 card
->dev
->watchdog_timeo
= QETH_TX_TIMEOUT
;
3306 card
->dev
->mtu
= card
->info
.initial_mtu
;
3307 SET_ETHTOOL_OPS(card
->dev
, &qeth_l3_ethtool_ops
);
3308 card
->dev
->features
|= NETIF_F_HW_VLAN_TX
|
3309 NETIF_F_HW_VLAN_RX
|
3310 NETIF_F_HW_VLAN_FILTER
;
3311 card
->dev
->priv_flags
&= ~IFF_XMIT_DST_RELEASE
;
3312 card
->dev
->gso_max_size
= 15 * PAGE_SIZE
;
3314 SET_NETDEV_DEV(card
->dev
, &card
->gdev
->dev
);
3315 netif_napi_add(card
->dev
, &card
->napi
, qeth_l3_poll
, QETH_NAPI_WEIGHT
);
3316 return register_netdev(card
->dev
);
3319 static int qeth_l3_probe_device(struct ccwgroup_device
*gdev
)
3321 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
3323 qeth_l3_create_device_attributes(&gdev
->dev
);
3324 card
->options
.layer2
= 0;
3325 card
->info
.hwtrap
= 0;
3326 card
->discipline
.start_poll
= qeth_qdio_start_poll
;
3327 card
->discipline
.input_handler
= (qdio_handler_t
*)
3328 qeth_qdio_input_handler
;
3329 card
->discipline
.output_handler
= (qdio_handler_t
*)
3330 qeth_qdio_output_handler
;
3331 card
->discipline
.recover
= qeth_l3_recover
;
3335 static void qeth_l3_remove_device(struct ccwgroup_device
*cgdev
)
3337 struct qeth_card
*card
= dev_get_drvdata(&cgdev
->dev
);
3339 qeth_l3_remove_device_attributes(&cgdev
->dev
);
3341 qeth_set_allowed_threads(card
, 0, 1);
3342 wait_event(card
->wait_q
, qeth_threads_running(card
, 0xffffffff) == 0);
3344 if (cgdev
->state
== CCWGROUP_ONLINE
)
3345 qeth_l3_set_offline(cgdev
);
3348 unregister_netdev(card
->dev
);
3352 qeth_l3_clear_ip_list(card
, 0);
3353 qeth_l3_clear_ipato_list(card
);
3357 static int __qeth_l3_set_online(struct ccwgroup_device
*gdev
, int recovery_mode
)
3359 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
3361 enum qeth_card_states recover_flag
;
3364 mutex_lock(&card
->discipline_mutex
);
3365 mutex_lock(&card
->conf_mutex
);
3366 QETH_DBF_TEXT(SETUP
, 2, "setonlin");
3367 QETH_DBF_HEX(SETUP
, 2, &card
, sizeof(void *));
3369 recover_flag
= card
->state
;
3370 rc
= qeth_core_hardsetup_card(card
);
3372 QETH_DBF_TEXT_(SETUP
, 2, "2err%d", rc
);
3377 if (!card
->dev
&& qeth_l3_setup_netdev(card
)) {
3382 if (qeth_is_diagass_supported(card
, QETH_DIAGS_CMD_TRAP
)) {
3383 if (card
->info
.hwtrap
&&
3384 qeth_hw_trap(card
, QETH_DIAGS_TRAP_ARM
))
3385 card
->info
.hwtrap
= 0;
3387 card
->info
.hwtrap
= 0;
3389 card
->state
= CARD_STATE_HARDSETUP
;
3390 memset(&card
->rx
, 0, sizeof(struct qeth_rx
));
3391 qeth_print_status_message(card
);
3394 QETH_DBF_TEXT(SETUP
, 2, "softsetp");
3396 rc
= qeth_send_startlan(card
);
3398 QETH_DBF_TEXT_(SETUP
, 2, "1err%d", rc
);
3400 dev_warn(&card
->gdev
->dev
,
3401 "The LAN is offline\n");
3402 card
->lan_online
= 0;
3408 card
->lan_online
= 1;
3411 rc
= qeth_l3_setadapter_parms(card
);
3413 QETH_DBF_TEXT_(SETUP
, 2, "2err%d", rc
);
3414 if (!card
->options
.sniffer
) {
3415 rc
= qeth_l3_start_ipassists(card
);
3417 QETH_DBF_TEXT_(SETUP
, 2, "3err%d", rc
);
3418 rc
= qeth_l3_setrouting_v4(card
);
3420 QETH_DBF_TEXT_(SETUP
, 2, "4err%d", rc
);
3421 rc
= qeth_l3_setrouting_v6(card
);
3423 QETH_DBF_TEXT_(SETUP
, 2, "5err%d", rc
);
3425 netif_tx_disable(card
->dev
);
3427 rc
= qeth_init_qdio_queues(card
);
3429 QETH_DBF_TEXT_(SETUP
, 2, "6err%d", rc
);
3433 card
->state
= CARD_STATE_SOFTSETUP
;
3435 qeth_set_allowed_threads(card
, 0xffffffff, 0);
3436 qeth_l3_set_ip_addr_list(card
);
3437 if (card
->lan_online
)
3438 netif_carrier_on(card
->dev
);
3440 netif_carrier_off(card
->dev
);
3441 if (recover_flag
== CARD_STATE_RECOVER
) {
3443 __qeth_l3_open(card
->dev
);
3446 dev_open(card
->dev
);
3449 qeth_l3_set_multicast_list(card
->dev
);
3451 /* let user_space know that device is online */
3452 kobject_uevent(&gdev
->dev
.kobj
, KOBJ_CHANGE
);
3453 mutex_unlock(&card
->conf_mutex
);
3454 mutex_unlock(&card
->discipline_mutex
);
3457 qeth_l3_stop_card(card
, 0);
3458 ccw_device_set_offline(CARD_DDEV(card
));
3459 ccw_device_set_offline(CARD_WDEV(card
));
3460 ccw_device_set_offline(CARD_RDEV(card
));
3461 if (recover_flag
== CARD_STATE_RECOVER
)
3462 card
->state
= CARD_STATE_RECOVER
;
3464 card
->state
= CARD_STATE_DOWN
;
3465 mutex_unlock(&card
->conf_mutex
);
3466 mutex_unlock(&card
->discipline_mutex
);
3470 static int qeth_l3_set_online(struct ccwgroup_device
*gdev
)
3472 return __qeth_l3_set_online(gdev
, 0);
3475 static int __qeth_l3_set_offline(struct ccwgroup_device
*cgdev
,
3478 struct qeth_card
*card
= dev_get_drvdata(&cgdev
->dev
);
3479 int rc
= 0, rc2
= 0, rc3
= 0;
3480 enum qeth_card_states recover_flag
;
3482 mutex_lock(&card
->discipline_mutex
);
3483 mutex_lock(&card
->conf_mutex
);
3484 QETH_DBF_TEXT(SETUP
, 3, "setoffl");
3485 QETH_DBF_HEX(SETUP
, 3, &card
, sizeof(void *));
3487 if (card
->dev
&& netif_carrier_ok(card
->dev
))
3488 netif_carrier_off(card
->dev
);
3489 recover_flag
= card
->state
;
3490 if ((!recovery_mode
&& card
->info
.hwtrap
) || card
->info
.hwtrap
== 2) {
3491 qeth_hw_trap(card
, QETH_DIAGS_TRAP_DISARM
);
3492 card
->info
.hwtrap
= 1;
3494 qeth_l3_stop_card(card
, recovery_mode
);
3495 rc
= ccw_device_set_offline(CARD_DDEV(card
));
3496 rc2
= ccw_device_set_offline(CARD_WDEV(card
));
3497 rc3
= ccw_device_set_offline(CARD_RDEV(card
));
3499 rc
= (rc2
) ? rc2
: rc3
;
3501 QETH_DBF_TEXT_(SETUP
, 2, "1err%d", rc
);
3502 if (recover_flag
== CARD_STATE_UP
)
3503 card
->state
= CARD_STATE_RECOVER
;
3504 /* let user_space know that device is offline */
3505 kobject_uevent(&cgdev
->dev
.kobj
, KOBJ_CHANGE
);
3506 mutex_unlock(&card
->conf_mutex
);
3507 mutex_unlock(&card
->discipline_mutex
);
3511 static int qeth_l3_set_offline(struct ccwgroup_device
*cgdev
)
3513 return __qeth_l3_set_offline(cgdev
, 0);
3516 static int qeth_l3_recover(void *ptr
)
3518 struct qeth_card
*card
;
3521 card
= (struct qeth_card
*) ptr
;
3522 QETH_CARD_TEXT(card
, 2, "recover1");
3523 QETH_CARD_HEX(card
, 2, &card
, sizeof(void *));
3524 if (!qeth_do_run_thread(card
, QETH_RECOVER_THREAD
))
3526 QETH_CARD_TEXT(card
, 2, "recover2");
3527 dev_warn(&card
->gdev
->dev
,
3528 "A recovery process has been started for the device\n");
3529 __qeth_l3_set_offline(card
->gdev
, 1);
3530 rc
= __qeth_l3_set_online(card
->gdev
, 1);
3532 dev_info(&card
->gdev
->dev
,
3533 "Device successfully recovered!\n");
3536 dev_close(card
->dev
);
3538 dev_warn(&card
->gdev
->dev
, "The qeth device driver "
3539 "failed to recover an error on the device\n");
3541 qeth_clear_thread_start_bit(card
, QETH_RECOVER_THREAD
);
3542 qeth_clear_thread_running_bit(card
, QETH_RECOVER_THREAD
);
3546 static void qeth_l3_shutdown(struct ccwgroup_device
*gdev
)
3548 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
3549 if ((gdev
->state
== CCWGROUP_ONLINE
) && card
->info
.hwtrap
)
3550 qeth_hw_trap(card
, QETH_DIAGS_TRAP_DISARM
);
3551 qeth_qdio_clear_card(card
, 0);
3552 qeth_clear_qdio_buffers(card
);
3555 static int qeth_l3_pm_suspend(struct ccwgroup_device
*gdev
)
3557 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
3560 netif_device_detach(card
->dev
);
3561 qeth_set_allowed_threads(card
, 0, 1);
3562 wait_event(card
->wait_q
, qeth_threads_running(card
, 0xffffffff) == 0);
3563 if (gdev
->state
== CCWGROUP_OFFLINE
)
3565 if (card
->state
== CARD_STATE_UP
) {
3566 if (card
->info
.hwtrap
)
3567 qeth_hw_trap(card
, QETH_DIAGS_TRAP_DISARM
);
3568 __qeth_l3_set_offline(card
->gdev
, 1);
3570 __qeth_l3_set_offline(card
->gdev
, 0);
3574 static int qeth_l3_pm_resume(struct ccwgroup_device
*gdev
)
3576 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
3579 if (gdev
->state
== CCWGROUP_OFFLINE
)
3582 if (card
->state
== CARD_STATE_RECOVER
) {
3583 rc
= __qeth_l3_set_online(card
->gdev
, 1);
3586 dev_close(card
->dev
);
3590 rc
= __qeth_l3_set_online(card
->gdev
, 0);
3592 qeth_set_allowed_threads(card
, 0xffffffff, 0);
3594 netif_device_attach(card
->dev
);
3596 dev_warn(&card
->gdev
->dev
, "The qeth device driver "
3597 "failed to recover an error on the device\n");
3601 struct ccwgroup_driver qeth_l3_ccwgroup_driver
= {
3602 .probe
= qeth_l3_probe_device
,
3603 .remove
= qeth_l3_remove_device
,
3604 .set_online
= qeth_l3_set_online
,
3605 .set_offline
= qeth_l3_set_offline
,
3606 .shutdown
= qeth_l3_shutdown
,
3607 .freeze
= qeth_l3_pm_suspend
,
3608 .thaw
= qeth_l3_pm_resume
,
3609 .restore
= qeth_l3_pm_resume
,
3611 EXPORT_SYMBOL_GPL(qeth_l3_ccwgroup_driver
);
3613 static int qeth_l3_ip_event(struct notifier_block
*this,
3614 unsigned long event
, void *ptr
)
3616 struct in_ifaddr
*ifa
= (struct in_ifaddr
*)ptr
;
3617 struct net_device
*dev
= (struct net_device
*)ifa
->ifa_dev
->dev
;
3618 struct qeth_ipaddr
*addr
;
3619 struct qeth_card
*card
;
3621 if (dev_net(dev
) != &init_net
)
3624 card
= qeth_l3_get_card_from_dev(dev
);
3625 QETH_CARD_TEXT(card
, 3, "ipevent");
3629 addr
= qeth_l3_get_addr_buffer(QETH_PROT_IPV4
);
3631 addr
->u
.a4
.addr
= ifa
->ifa_address
;
3632 addr
->u
.a4
.mask
= ifa
->ifa_mask
;
3633 addr
->type
= QETH_IP_TYPE_NORMAL
;
3639 if (!qeth_l3_add_ip(card
, addr
))
3643 if (!qeth_l3_delete_ip(card
, addr
))
3649 qeth_l3_set_ip_addr_list(card
);
3654 static struct notifier_block qeth_l3_ip_notifier
= {
3659 #ifdef CONFIG_QETH_IPV6
3661 * IPv6 event handler
3663 static int qeth_l3_ip6_event(struct notifier_block
*this,
3664 unsigned long event
, void *ptr
)
3666 struct inet6_ifaddr
*ifa
= (struct inet6_ifaddr
*)ptr
;
3667 struct net_device
*dev
= (struct net_device
*)ifa
->idev
->dev
;
3668 struct qeth_ipaddr
*addr
;
3669 struct qeth_card
*card
;
3672 card
= qeth_l3_get_card_from_dev(dev
);
3675 QETH_CARD_TEXT(card
, 3, "ip6event");
3676 if (!qeth_is_supported(card
, IPA_IPV6
))
3679 addr
= qeth_l3_get_addr_buffer(QETH_PROT_IPV6
);
3681 memcpy(&addr
->u
.a6
.addr
, &ifa
->addr
, sizeof(struct in6_addr
));
3682 addr
->u
.a6
.pfxlen
= ifa
->prefix_len
;
3683 addr
->type
= QETH_IP_TYPE_NORMAL
;
3689 if (!qeth_l3_add_ip(card
, addr
))
3693 if (!qeth_l3_delete_ip(card
, addr
))
3699 qeth_l3_set_ip_addr_list(card
);
3704 static struct notifier_block qeth_l3_ip6_notifier
= {
3710 static int qeth_l3_register_notifiers(void)
3714 QETH_DBF_TEXT(SETUP
, 5, "regnotif");
3715 rc
= register_inetaddr_notifier(&qeth_l3_ip_notifier
);
3718 #ifdef CONFIG_QETH_IPV6
3719 rc
= register_inet6addr_notifier(&qeth_l3_ip6_notifier
);
3721 unregister_inetaddr_notifier(&qeth_l3_ip_notifier
);
3725 pr_warning("There is no IPv6 support for the layer 3 discipline\n");
3730 static void qeth_l3_unregister_notifiers(void)
3733 QETH_DBF_TEXT(SETUP
, 5, "unregnot");
3734 BUG_ON(unregister_inetaddr_notifier(&qeth_l3_ip_notifier
));
3735 #ifdef CONFIG_QETH_IPV6
3736 BUG_ON(unregister_inet6addr_notifier(&qeth_l3_ip6_notifier
));
3737 #endif /* QETH_IPV6 */
3740 static int __init
qeth_l3_init(void)
3744 pr_info("register layer 3 discipline\n");
3745 rc
= qeth_l3_register_notifiers();
3749 static void __exit
qeth_l3_exit(void)
3751 qeth_l3_unregister_notifiers();
3752 pr_info("unregister layer 3 discipline\n");
3755 module_init(qeth_l3_init
);
3756 module_exit(qeth_l3_exit
);
3757 MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
3758 MODULE_DESCRIPTION("qeth layer 3 discipline");
3759 MODULE_LICENSE("GPL");