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 int qeth_l3_set_large_send(struct qeth_card
*card
,
47 enum qeth_large_send_types type
)
51 card
->options
.large_send
= type
;
52 if (card
->dev
== NULL
)
55 if (card
->options
.large_send
== QETH_LARGE_SEND_TSO
) {
56 if (qeth_is_supported(card
, IPA_OUTBOUND_TSO
)) {
57 card
->dev
->features
|= NETIF_F_TSO
| NETIF_F_SG
|
60 card
->dev
->features
&= ~(NETIF_F_TSO
| NETIF_F_SG
|
62 card
->options
.large_send
= QETH_LARGE_SEND_NO
;
66 card
->dev
->features
&= ~(NETIF_F_TSO
| NETIF_F_SG
|
68 card
->options
.large_send
= QETH_LARGE_SEND_NO
;
73 static int qeth_l3_isxdigit(char *buf
)
76 if (!isxdigit(*buf
++))
82 void qeth_l3_ipaddr4_to_string(const __u8
*addr
, char *buf
)
84 sprintf(buf
, "%i.%i.%i.%i", addr
[0], addr
[1], addr
[2], addr
[3]);
87 int qeth_l3_string_to_ipaddr4(const char *buf
, __u8
*addr
)
89 int count
= 0, rc
= 0;
93 rc
= sscanf(buf
, "%u.%u.%u.%u%c",
94 &in
[0], &in
[1], &in
[2], &in
[3], &c
);
95 if (rc
!= 4 && (rc
!= 5 || c
!= '\n'))
97 for (count
= 0; count
< 4; count
++) {
100 addr
[count
] = in
[count
];
105 void qeth_l3_ipaddr6_to_string(const __u8
*addr
, char *buf
)
107 sprintf(buf
, "%pI6", addr
);
110 int qeth_l3_string_to_ipaddr6(const char *buf
, __u8
*addr
)
112 const char *end
, *end_tmp
, *start
;
115 int num2
, cnt
, out
, found
, save_cnt
;
116 unsigned short in_tmp
[8] = {0, };
118 cnt
= out
= found
= save_cnt
= num2
= 0;
123 end
= strchr(start
, ':');
125 end
= buf
+ strlen(buf
);
126 end_tmp
= strchr(start
, '\n');
133 if ((end
- start
) > 4)
135 memcpy(num
, start
, end
- start
);
136 if (!qeth_l3_isxdigit(num
))
138 sscanf(start
, "%x", &num2
);
140 in_tmp
[save_cnt
++] = num2
;
152 if (cnt
+ save_cnt
> 8)
156 in
[cnt
--] = in_tmp
[--save_cnt
];
160 void qeth_l3_ipaddr_to_string(enum qeth_prot_versions proto
, const __u8
*addr
,
163 if (proto
== QETH_PROT_IPV4
)
164 qeth_l3_ipaddr4_to_string(addr
, buf
);
165 else if (proto
== QETH_PROT_IPV6
)
166 qeth_l3_ipaddr6_to_string(addr
, buf
);
169 int qeth_l3_string_to_ipaddr(const char *buf
, enum qeth_prot_versions proto
,
172 if (proto
== QETH_PROT_IPV4
)
173 return qeth_l3_string_to_ipaddr4(buf
, addr
);
174 else if (proto
== QETH_PROT_IPV6
)
175 return qeth_l3_string_to_ipaddr6(buf
, addr
);
180 static void qeth_l3_convert_addr_to_bits(u8
*addr
, u8
*bits
, int len
)
185 for (i
= 0; i
< len
; ++i
) {
187 for (j
= 7; j
>= 0; --j
) {
188 bits
[i
*8 + j
] = octet
& 1;
194 int qeth_l3_is_addr_covered_by_ipato(struct qeth_card
*card
,
195 struct qeth_ipaddr
*addr
)
197 struct qeth_ipato_entry
*ipatoe
;
198 u8 addr_bits
[128] = {0, };
199 u8 ipatoe_bits
[128] = {0, };
202 if (!card
->ipato
.enabled
)
205 qeth_l3_convert_addr_to_bits((u8
*) &addr
->u
, addr_bits
,
206 (addr
->proto
== QETH_PROT_IPV4
)? 4:16);
207 list_for_each_entry(ipatoe
, &card
->ipato
.entries
, entry
) {
208 if (addr
->proto
!= ipatoe
->proto
)
210 qeth_l3_convert_addr_to_bits(ipatoe
->addr
, ipatoe_bits
,
211 (ipatoe
->proto
== QETH_PROT_IPV4
) ?
213 if (addr
->proto
== QETH_PROT_IPV4
)
214 rc
= !memcmp(addr_bits
, ipatoe_bits
,
215 min(32, ipatoe
->mask_bits
));
217 rc
= !memcmp(addr_bits
, ipatoe_bits
,
218 min(128, ipatoe
->mask_bits
));
223 if ((addr
->proto
== QETH_PROT_IPV4
) && card
->ipato
.invert4
)
225 else if ((addr
->proto
== QETH_PROT_IPV6
) && card
->ipato
.invert6
)
232 * Add IP to be added to todo list. If there is already an "add todo"
233 * in this list we just incremenent the reference count.
234 * Returns 0 if we just incremented reference count.
236 static int __qeth_l3_insert_ip_todo(struct qeth_card
*card
,
237 struct qeth_ipaddr
*addr
, int add
)
239 struct qeth_ipaddr
*tmp
, *t
;
242 if (card
->options
.sniffer
)
244 list_for_each_entry_safe(tmp
, t
, card
->ip_tbd_list
, entry
) {
245 if ((addr
->type
== QETH_IP_TYPE_DEL_ALL_MC
) &&
246 (tmp
->type
== QETH_IP_TYPE_DEL_ALL_MC
))
248 if ((tmp
->proto
== QETH_PROT_IPV4
) &&
249 (addr
->proto
== QETH_PROT_IPV4
) &&
250 (tmp
->type
== addr
->type
) &&
251 (tmp
->is_multicast
== addr
->is_multicast
) &&
252 (tmp
->u
.a4
.addr
== addr
->u
.a4
.addr
) &&
253 (tmp
->u
.a4
.mask
== addr
->u
.a4
.mask
)) {
257 if ((tmp
->proto
== QETH_PROT_IPV6
) &&
258 (addr
->proto
== QETH_PROT_IPV6
) &&
259 (tmp
->type
== addr
->type
) &&
260 (tmp
->is_multicast
== addr
->is_multicast
) &&
261 (tmp
->u
.a6
.pfxlen
== addr
->u
.a6
.pfxlen
) &&
262 (memcmp(&tmp
->u
.a6
.addr
, &addr
->u
.a6
.addr
,
263 sizeof(struct in6_addr
)) == 0)) {
269 if (addr
->users
!= 0)
270 tmp
->users
+= addr
->users
;
272 tmp
->users
+= add
? 1 : -1;
273 if (tmp
->users
== 0) {
274 list_del(&tmp
->entry
);
279 if (addr
->type
== QETH_IP_TYPE_DEL_ALL_MC
)
280 list_add(&addr
->entry
, card
->ip_tbd_list
);
282 if (addr
->users
== 0)
283 addr
->users
+= add
? 1 : -1;
284 if (add
&& (addr
->type
== QETH_IP_TYPE_NORMAL
) &&
285 qeth_l3_is_addr_covered_by_ipato(card
, addr
)) {
286 QETH_CARD_TEXT(card
, 2, "tkovaddr");
287 addr
->set_flags
|= QETH_IPA_SETIP_TAKEOVER_FLAG
;
289 list_add_tail(&addr
->entry
, card
->ip_tbd_list
);
295 static int qeth_l3_delete_ip(struct qeth_card
*card
, struct qeth_ipaddr
*addr
)
300 QETH_CARD_TEXT(card
, 4, "delip");
302 if (addr
->proto
== QETH_PROT_IPV4
)
303 QETH_CARD_HEX(card
, 4, &addr
->u
.a4
.addr
, 4);
305 QETH_CARD_HEX(card
, 4, &addr
->u
.a6
.addr
, 8);
306 QETH_CARD_HEX(card
, 4, ((char *)&addr
->u
.a6
.addr
) + 8, 8);
308 spin_lock_irqsave(&card
->ip_lock
, flags
);
309 rc
= __qeth_l3_insert_ip_todo(card
, addr
, 0);
310 spin_unlock_irqrestore(&card
->ip_lock
, flags
);
314 static int qeth_l3_add_ip(struct qeth_card
*card
, struct qeth_ipaddr
*addr
)
319 QETH_CARD_TEXT(card
, 4, "addip");
320 if (addr
->proto
== QETH_PROT_IPV4
)
321 QETH_CARD_HEX(card
, 4, &addr
->u
.a4
.addr
, 4);
323 QETH_CARD_HEX(card
, 4, &addr
->u
.a6
.addr
, 8);
324 QETH_CARD_HEX(card
, 4, ((char *)&addr
->u
.a6
.addr
) + 8, 8);
326 spin_lock_irqsave(&card
->ip_lock
, flags
);
327 rc
= __qeth_l3_insert_ip_todo(card
, addr
, 1);
328 spin_unlock_irqrestore(&card
->ip_lock
, flags
);
333 static struct qeth_ipaddr
*qeth_l3_get_addr_buffer(
334 enum qeth_prot_versions prot
)
336 struct qeth_ipaddr
*addr
;
338 addr
= kzalloc(sizeof(struct qeth_ipaddr
), GFP_ATOMIC
);
342 addr
->type
= QETH_IP_TYPE_NORMAL
;
347 static void qeth_l3_delete_mc_addresses(struct qeth_card
*card
)
349 struct qeth_ipaddr
*iptodo
;
352 QETH_CARD_TEXT(card
, 4, "delmc");
353 iptodo
= qeth_l3_get_addr_buffer(QETH_PROT_IPV4
);
355 QETH_CARD_TEXT(card
, 2, "dmcnomem");
358 iptodo
->type
= QETH_IP_TYPE_DEL_ALL_MC
;
359 spin_lock_irqsave(&card
->ip_lock
, flags
);
360 if (!__qeth_l3_insert_ip_todo(card
, iptodo
, 0))
362 spin_unlock_irqrestore(&card
->ip_lock
, flags
);
366 * Add/remove address to/from card's ip list, i.e. try to add or remove
367 * reference to/from an IP address that is already registered on the card.
369 * 0 address was on card and its reference count has been adjusted,
370 * but is still > 0, so nothing has to be done
371 * also returns 0 if card was not on card and the todo was to delete
372 * the address -> there is also nothing to be done
373 * 1 address was not on card and the todo is to add it to the card's ip
375 * -1 address was on card and its reference count has been decremented
376 * to <= 0 by the todo -> address must be removed from card
378 static int __qeth_l3_ref_ip_on_card(struct qeth_card
*card
,
379 struct qeth_ipaddr
*todo
, struct qeth_ipaddr
**__addr
)
381 struct qeth_ipaddr
*addr
;
384 list_for_each_entry(addr
, &card
->ip_list
, entry
) {
385 if ((addr
->proto
== QETH_PROT_IPV4
) &&
386 (todo
->proto
== QETH_PROT_IPV4
) &&
387 (addr
->type
== todo
->type
) &&
388 (addr
->u
.a4
.addr
== todo
->u
.a4
.addr
) &&
389 (addr
->u
.a4
.mask
== todo
->u
.a4
.mask
)) {
393 if ((addr
->proto
== QETH_PROT_IPV6
) &&
394 (todo
->proto
== QETH_PROT_IPV6
) &&
395 (addr
->type
== todo
->type
) &&
396 (addr
->u
.a6
.pfxlen
== todo
->u
.a6
.pfxlen
) &&
397 (memcmp(&addr
->u
.a6
.addr
, &todo
->u
.a6
.addr
,
398 sizeof(struct in6_addr
)) == 0)) {
404 addr
->users
+= todo
->users
;
405 if (addr
->users
<= 0) {
409 /* for VIPA and RXIP limit refcount to 1 */
410 if (addr
->type
!= QETH_IP_TYPE_NORMAL
)
415 if (todo
->users
> 0) {
416 /* for VIPA and RXIP limit refcount to 1 */
417 if (todo
->type
!= QETH_IP_TYPE_NORMAL
)
424 static void __qeth_l3_delete_all_mc(struct qeth_card
*card
,
425 unsigned long *flags
)
427 struct list_head fail_list
;
428 struct qeth_ipaddr
*addr
, *tmp
;
431 INIT_LIST_HEAD(&fail_list
);
433 list_for_each_entry_safe(addr
, tmp
, &card
->ip_list
, entry
) {
434 if (addr
->is_multicast
) {
435 list_del(&addr
->entry
);
436 spin_unlock_irqrestore(&card
->ip_lock
, *flags
);
437 rc
= qeth_l3_deregister_addr_entry(card
, addr
);
438 spin_lock_irqsave(&card
->ip_lock
, *flags
);
439 if (!rc
|| (rc
== IPA_RC_MC_ADDR_NOT_FOUND
))
442 list_add_tail(&addr
->entry
, &fail_list
);
446 list_splice(&fail_list
, &card
->ip_list
);
449 static void qeth_l3_set_ip_addr_list(struct qeth_card
*card
)
451 struct list_head
*tbd_list
;
452 struct qeth_ipaddr
*todo
, *addr
;
456 QETH_CARD_TEXT(card
, 2, "sdiplist");
457 QETH_CARD_HEX(card
, 2, &card
, sizeof(void *));
459 if ((card
->state
!= CARD_STATE_UP
&&
460 card
->state
!= CARD_STATE_SOFTSETUP
) || card
->options
.sniffer
) {
464 spin_lock_irqsave(&card
->ip_lock
, flags
);
465 tbd_list
= card
->ip_tbd_list
;
466 card
->ip_tbd_list
= kmalloc(sizeof(struct list_head
), GFP_ATOMIC
);
467 if (!card
->ip_tbd_list
) {
468 QETH_CARD_TEXT(card
, 0, "silnomem");
469 card
->ip_tbd_list
= tbd_list
;
470 spin_unlock_irqrestore(&card
->ip_lock
, flags
);
473 INIT_LIST_HEAD(card
->ip_tbd_list
);
475 while (!list_empty(tbd_list
)) {
476 todo
= list_entry(tbd_list
->next
, struct qeth_ipaddr
, entry
);
477 list_del(&todo
->entry
);
478 if (todo
->type
== QETH_IP_TYPE_DEL_ALL_MC
) {
479 __qeth_l3_delete_all_mc(card
, &flags
);
483 rc
= __qeth_l3_ref_ip_on_card(card
, todo
, &addr
);
485 /* nothing to be done; only adjusted refcount */
487 } else if (rc
== 1) {
488 /* new entry to be added to on-card list */
489 spin_unlock_irqrestore(&card
->ip_lock
, flags
);
490 rc
= qeth_l3_register_addr_entry(card
, todo
);
491 spin_lock_irqsave(&card
->ip_lock
, flags
);
492 if (!rc
|| (rc
== IPA_RC_LAN_OFFLINE
))
493 list_add_tail(&todo
->entry
, &card
->ip_list
);
496 } else if (rc
== -1) {
497 /* on-card entry to be removed */
498 list_del_init(&addr
->entry
);
499 spin_unlock_irqrestore(&card
->ip_lock
, flags
);
500 rc
= qeth_l3_deregister_addr_entry(card
, addr
);
501 spin_lock_irqsave(&card
->ip_lock
, flags
);
502 if (!rc
|| (rc
== IPA_RC_IP_ADDRESS_NOT_DEFINED
))
505 list_add_tail(&addr
->entry
, &card
->ip_list
);
509 spin_unlock_irqrestore(&card
->ip_lock
, flags
);
513 static void qeth_l3_clear_ip_list(struct qeth_card
*card
, int recover
)
515 struct qeth_ipaddr
*addr
, *tmp
;
518 QETH_CARD_TEXT(card
, 4, "clearip");
519 if (recover
&& card
->options
.sniffer
)
521 spin_lock_irqsave(&card
->ip_lock
, flags
);
522 /* clear todo list */
523 list_for_each_entry_safe(addr
, tmp
, card
->ip_tbd_list
, entry
) {
524 list_del(&addr
->entry
);
528 while (!list_empty(&card
->ip_list
)) {
529 addr
= list_entry(card
->ip_list
.next
,
530 struct qeth_ipaddr
, entry
);
531 list_del_init(&addr
->entry
);
532 if (!recover
|| addr
->is_multicast
) {
536 list_add_tail(&addr
->entry
, card
->ip_tbd_list
);
538 spin_unlock_irqrestore(&card
->ip_lock
, flags
);
541 static int qeth_l3_address_exists_in_list(struct list_head
*list
,
542 struct qeth_ipaddr
*addr
, int same_type
)
544 struct qeth_ipaddr
*tmp
;
546 list_for_each_entry(tmp
, list
, entry
) {
547 if ((tmp
->proto
== QETH_PROT_IPV4
) &&
548 (addr
->proto
== QETH_PROT_IPV4
) &&
549 ((same_type
&& (tmp
->type
== addr
->type
)) ||
550 (!same_type
&& (tmp
->type
!= addr
->type
))) &&
551 (tmp
->u
.a4
.addr
== addr
->u
.a4
.addr
))
554 if ((tmp
->proto
== QETH_PROT_IPV6
) &&
555 (addr
->proto
== QETH_PROT_IPV6
) &&
556 ((same_type
&& (tmp
->type
== addr
->type
)) ||
557 (!same_type
&& (tmp
->type
!= addr
->type
))) &&
558 (memcmp(&tmp
->u
.a6
.addr
, &addr
->u
.a6
.addr
,
559 sizeof(struct in6_addr
)) == 0))
566 static int qeth_l3_send_setdelmc(struct qeth_card
*card
,
567 struct qeth_ipaddr
*addr
, int ipacmd
)
570 struct qeth_cmd_buffer
*iob
;
571 struct qeth_ipa_cmd
*cmd
;
573 QETH_CARD_TEXT(card
, 4, "setdelmc");
575 iob
= qeth_get_ipacmd_buffer(card
, ipacmd
, addr
->proto
);
576 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
577 memcpy(&cmd
->data
.setdelipm
.mac
, addr
->mac
, OSA_ADDR_LEN
);
578 if (addr
->proto
== QETH_PROT_IPV6
)
579 memcpy(cmd
->data
.setdelipm
.ip6
, &addr
->u
.a6
.addr
,
580 sizeof(struct in6_addr
));
582 memcpy(&cmd
->data
.setdelipm
.ip4
, &addr
->u
.a4
.addr
, 4);
584 rc
= qeth_send_ipa_cmd(card
, iob
, NULL
, NULL
);
589 static void qeth_l3_fill_netmask(u8
*netmask
, unsigned int len
)
592 for (i
= 0; i
< 16; i
++) {
597 netmask
[i
] = (u8
)(0xFF00 >> j
);
603 static int qeth_l3_send_setdelip(struct qeth_card
*card
,
604 struct qeth_ipaddr
*addr
, int ipacmd
, unsigned int flags
)
607 struct qeth_cmd_buffer
*iob
;
608 struct qeth_ipa_cmd
*cmd
;
611 QETH_CARD_TEXT(card
, 4, "setdelip");
612 QETH_CARD_TEXT_(card
, 4, "flags%02X", flags
);
614 iob
= qeth_get_ipacmd_buffer(card
, ipacmd
, addr
->proto
);
615 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
616 if (addr
->proto
== QETH_PROT_IPV6
) {
617 memcpy(cmd
->data
.setdelip6
.ip_addr
, &addr
->u
.a6
.addr
,
618 sizeof(struct in6_addr
));
619 qeth_l3_fill_netmask(netmask
, addr
->u
.a6
.pfxlen
);
620 memcpy(cmd
->data
.setdelip6
.mask
, netmask
,
621 sizeof(struct in6_addr
));
622 cmd
->data
.setdelip6
.flags
= flags
;
624 memcpy(cmd
->data
.setdelip4
.ip_addr
, &addr
->u
.a4
.addr
, 4);
625 memcpy(cmd
->data
.setdelip4
.mask
, &addr
->u
.a4
.mask
, 4);
626 cmd
->data
.setdelip4
.flags
= flags
;
629 rc
= qeth_send_ipa_cmd(card
, iob
, NULL
, NULL
);
634 static int qeth_l3_send_setrouting(struct qeth_card
*card
,
635 enum qeth_routing_types type
, enum qeth_prot_versions prot
)
638 struct qeth_ipa_cmd
*cmd
;
639 struct qeth_cmd_buffer
*iob
;
641 QETH_CARD_TEXT(card
, 4, "setroutg");
642 iob
= qeth_get_ipacmd_buffer(card
, IPA_CMD_SETRTG
, prot
);
643 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
644 cmd
->data
.setrtg
.type
= (type
);
645 rc
= qeth_send_ipa_cmd(card
, iob
, NULL
, NULL
);
650 static void qeth_l3_correct_routing_type(struct qeth_card
*card
,
651 enum qeth_routing_types
*type
, enum qeth_prot_versions prot
)
653 if (card
->info
.type
== QETH_CARD_TYPE_IQD
) {
656 case PRIMARY_CONNECTOR
:
657 case SECONDARY_CONNECTOR
:
658 case MULTICAST_ROUTER
:
667 case SECONDARY_ROUTER
:
669 case MULTICAST_ROUTER
:
670 if (qeth_is_ipafunc_supported(card
, prot
,
681 int qeth_l3_setrouting_v4(struct qeth_card
*card
)
685 QETH_CARD_TEXT(card
, 3, "setrtg4");
687 qeth_l3_correct_routing_type(card
, &card
->options
.route4
.type
,
690 rc
= qeth_l3_send_setrouting(card
, card
->options
.route4
.type
,
693 card
->options
.route4
.type
= NO_ROUTER
;
694 QETH_DBF_MESSAGE(2, "Error (0x%04x) while setting routing type"
695 " on %s. Type set to 'no router'.\n", rc
,
696 QETH_CARD_IFNAME(card
));
701 int qeth_l3_setrouting_v6(struct qeth_card
*card
)
705 QETH_CARD_TEXT(card
, 3, "setrtg6");
706 #ifdef CONFIG_QETH_IPV6
708 if (!qeth_is_supported(card
, IPA_IPV6
))
710 qeth_l3_correct_routing_type(card
, &card
->options
.route6
.type
,
713 rc
= qeth_l3_send_setrouting(card
, card
->options
.route6
.type
,
716 card
->options
.route6
.type
= NO_ROUTER
;
717 QETH_DBF_MESSAGE(2, "Error (0x%04x) while setting routing type"
718 " on %s. Type set to 'no router'.\n", rc
,
719 QETH_CARD_IFNAME(card
));
726 * IP address takeover related functions
728 static void qeth_l3_clear_ipato_list(struct qeth_card
*card
)
731 struct qeth_ipato_entry
*ipatoe
, *tmp
;
734 spin_lock_irqsave(&card
->ip_lock
, flags
);
735 list_for_each_entry_safe(ipatoe
, tmp
, &card
->ipato
.entries
, entry
) {
736 list_del(&ipatoe
->entry
);
739 spin_unlock_irqrestore(&card
->ip_lock
, flags
);
742 int qeth_l3_add_ipato_entry(struct qeth_card
*card
,
743 struct qeth_ipato_entry
*new)
745 struct qeth_ipato_entry
*ipatoe
;
749 QETH_CARD_TEXT(card
, 2, "addipato");
750 spin_lock_irqsave(&card
->ip_lock
, flags
);
751 list_for_each_entry(ipatoe
, &card
->ipato
.entries
, entry
) {
752 if (ipatoe
->proto
!= new->proto
)
754 if (!memcmp(ipatoe
->addr
, new->addr
,
755 (ipatoe
->proto
== QETH_PROT_IPV4
)? 4:16) &&
756 (ipatoe
->mask_bits
== new->mask_bits
)) {
762 list_add_tail(&new->entry
, &card
->ipato
.entries
);
764 spin_unlock_irqrestore(&card
->ip_lock
, flags
);
768 void qeth_l3_del_ipato_entry(struct qeth_card
*card
,
769 enum qeth_prot_versions proto
, u8
*addr
, int mask_bits
)
771 struct qeth_ipato_entry
*ipatoe
, *tmp
;
774 QETH_CARD_TEXT(card
, 2, "delipato");
775 spin_lock_irqsave(&card
->ip_lock
, flags
);
776 list_for_each_entry_safe(ipatoe
, tmp
, &card
->ipato
.entries
, entry
) {
777 if (ipatoe
->proto
!= proto
)
779 if (!memcmp(ipatoe
->addr
, addr
,
780 (proto
== QETH_PROT_IPV4
)? 4:16) &&
781 (ipatoe
->mask_bits
== mask_bits
)) {
782 list_del(&ipatoe
->entry
);
786 spin_unlock_irqrestore(&card
->ip_lock
, flags
);
790 * VIPA related functions
792 int qeth_l3_add_vipa(struct qeth_card
*card
, enum qeth_prot_versions proto
,
795 struct qeth_ipaddr
*ipaddr
;
799 ipaddr
= qeth_l3_get_addr_buffer(proto
);
801 if (proto
== QETH_PROT_IPV4
) {
802 QETH_CARD_TEXT(card
, 2, "addvipa4");
803 memcpy(&ipaddr
->u
.a4
.addr
, addr
, 4);
804 ipaddr
->u
.a4
.mask
= 0;
805 } else if (proto
== QETH_PROT_IPV6
) {
806 QETH_CARD_TEXT(card
, 2, "addvipa6");
807 memcpy(&ipaddr
->u
.a6
.addr
, addr
, 16);
808 ipaddr
->u
.a6
.pfxlen
= 0;
810 ipaddr
->type
= QETH_IP_TYPE_VIPA
;
811 ipaddr
->set_flags
= QETH_IPA_SETIP_VIPA_FLAG
;
812 ipaddr
->del_flags
= QETH_IPA_DELIP_VIPA_FLAG
;
815 spin_lock_irqsave(&card
->ip_lock
, flags
);
816 if (qeth_l3_address_exists_in_list(&card
->ip_list
, ipaddr
, 0) ||
817 qeth_l3_address_exists_in_list(card
->ip_tbd_list
, ipaddr
, 0))
819 spin_unlock_irqrestore(&card
->ip_lock
, flags
);
823 if (!qeth_l3_add_ip(card
, ipaddr
))
825 qeth_l3_set_ip_addr_list(card
);
829 void qeth_l3_del_vipa(struct qeth_card
*card
, enum qeth_prot_versions proto
,
832 struct qeth_ipaddr
*ipaddr
;
834 ipaddr
= qeth_l3_get_addr_buffer(proto
);
836 if (proto
== QETH_PROT_IPV4
) {
837 QETH_CARD_TEXT(card
, 2, "delvipa4");
838 memcpy(&ipaddr
->u
.a4
.addr
, addr
, 4);
839 ipaddr
->u
.a4
.mask
= 0;
840 } else if (proto
== QETH_PROT_IPV6
) {
841 QETH_CARD_TEXT(card
, 2, "delvipa6");
842 memcpy(&ipaddr
->u
.a6
.addr
, addr
, 16);
843 ipaddr
->u
.a6
.pfxlen
= 0;
845 ipaddr
->type
= QETH_IP_TYPE_VIPA
;
848 if (!qeth_l3_delete_ip(card
, ipaddr
))
850 qeth_l3_set_ip_addr_list(card
);
854 * proxy ARP related functions
856 int qeth_l3_add_rxip(struct qeth_card
*card
, enum qeth_prot_versions proto
,
859 struct qeth_ipaddr
*ipaddr
;
863 ipaddr
= qeth_l3_get_addr_buffer(proto
);
865 if (proto
== QETH_PROT_IPV4
) {
866 QETH_CARD_TEXT(card
, 2, "addrxip4");
867 memcpy(&ipaddr
->u
.a4
.addr
, addr
, 4);
868 ipaddr
->u
.a4
.mask
= 0;
869 } else if (proto
== QETH_PROT_IPV6
) {
870 QETH_CARD_TEXT(card
, 2, "addrxip6");
871 memcpy(&ipaddr
->u
.a6
.addr
, addr
, 16);
872 ipaddr
->u
.a6
.pfxlen
= 0;
874 ipaddr
->type
= QETH_IP_TYPE_RXIP
;
875 ipaddr
->set_flags
= QETH_IPA_SETIP_TAKEOVER_FLAG
;
876 ipaddr
->del_flags
= 0;
879 spin_lock_irqsave(&card
->ip_lock
, flags
);
880 if (qeth_l3_address_exists_in_list(&card
->ip_list
, ipaddr
, 0) ||
881 qeth_l3_address_exists_in_list(card
->ip_tbd_list
, ipaddr
, 0))
883 spin_unlock_irqrestore(&card
->ip_lock
, flags
);
887 if (!qeth_l3_add_ip(card
, ipaddr
))
889 qeth_l3_set_ip_addr_list(card
);
893 void qeth_l3_del_rxip(struct qeth_card
*card
, enum qeth_prot_versions proto
,
896 struct qeth_ipaddr
*ipaddr
;
898 ipaddr
= qeth_l3_get_addr_buffer(proto
);
900 if (proto
== QETH_PROT_IPV4
) {
901 QETH_CARD_TEXT(card
, 2, "addrxip4");
902 memcpy(&ipaddr
->u
.a4
.addr
, addr
, 4);
903 ipaddr
->u
.a4
.mask
= 0;
904 } else if (proto
== QETH_PROT_IPV6
) {
905 QETH_CARD_TEXT(card
, 2, "addrxip6");
906 memcpy(&ipaddr
->u
.a6
.addr
, addr
, 16);
907 ipaddr
->u
.a6
.pfxlen
= 0;
909 ipaddr
->type
= QETH_IP_TYPE_RXIP
;
912 if (!qeth_l3_delete_ip(card
, ipaddr
))
914 qeth_l3_set_ip_addr_list(card
);
917 static int qeth_l3_register_addr_entry(struct qeth_card
*card
,
918 struct qeth_ipaddr
*addr
)
924 if (addr
->proto
== QETH_PROT_IPV4
) {
925 QETH_CARD_TEXT(card
, 2, "setaddr4");
926 QETH_CARD_HEX(card
, 3, &addr
->u
.a4
.addr
, sizeof(int));
927 } else if (addr
->proto
== QETH_PROT_IPV6
) {
928 QETH_CARD_TEXT(card
, 2, "setaddr6");
929 QETH_CARD_HEX(card
, 3, &addr
->u
.a6
.addr
, 8);
930 QETH_CARD_HEX(card
, 3, ((char *)&addr
->u
.a6
.addr
) + 8, 8);
932 QETH_CARD_TEXT(card
, 2, "setaddr?");
933 QETH_CARD_HEX(card
, 3, addr
, sizeof(struct qeth_ipaddr
));
936 if (addr
->is_multicast
)
937 rc
= qeth_l3_send_setdelmc(card
, addr
, IPA_CMD_SETIPM
);
939 rc
= qeth_l3_send_setdelip(card
, addr
, IPA_CMD_SETIP
,
942 QETH_CARD_TEXT(card
, 2, "failed");
943 } while ((--cnt
> 0) && rc
);
945 QETH_CARD_TEXT(card
, 2, "FAILED");
946 qeth_l3_ipaddr_to_string(addr
->proto
, (u8
*)&addr
->u
, buf
);
947 dev_warn(&card
->gdev
->dev
,
948 "Registering IP address %s failed\n", buf
);
953 static int qeth_l3_deregister_addr_entry(struct qeth_card
*card
,
954 struct qeth_ipaddr
*addr
)
958 if (addr
->proto
== QETH_PROT_IPV4
) {
959 QETH_CARD_TEXT(card
, 2, "deladdr4");
960 QETH_CARD_HEX(card
, 3, &addr
->u
.a4
.addr
, sizeof(int));
961 } else if (addr
->proto
== QETH_PROT_IPV6
) {
962 QETH_CARD_TEXT(card
, 2, "deladdr6");
963 QETH_CARD_HEX(card
, 3, &addr
->u
.a6
.addr
, 8);
964 QETH_CARD_HEX(card
, 3, ((char *)&addr
->u
.a6
.addr
) + 8, 8);
966 QETH_CARD_TEXT(card
, 2, "deladdr?");
967 QETH_CARD_HEX(card
, 3, addr
, sizeof(struct qeth_ipaddr
));
969 if (addr
->is_multicast
)
970 rc
= qeth_l3_send_setdelmc(card
, addr
, IPA_CMD_DELIPM
);
972 rc
= qeth_l3_send_setdelip(card
, addr
, IPA_CMD_DELIP
,
975 QETH_CARD_TEXT(card
, 2, "failed");
980 static inline u8
qeth_l3_get_qeth_hdr_flags4(int cast_type
)
982 if (cast_type
== RTN_MULTICAST
)
983 return QETH_CAST_MULTICAST
;
984 if (cast_type
== RTN_BROADCAST
)
985 return QETH_CAST_BROADCAST
;
986 return QETH_CAST_UNICAST
;
989 static inline u8
qeth_l3_get_qeth_hdr_flags6(int cast_type
)
991 u8 ct
= QETH_HDR_PASSTHRU
| QETH_HDR_IPV6
;
992 if (cast_type
== RTN_MULTICAST
)
993 return ct
| QETH_CAST_MULTICAST
;
994 if (cast_type
== RTN_ANYCAST
)
995 return ct
| QETH_CAST_ANYCAST
;
996 if (cast_type
== RTN_BROADCAST
)
997 return ct
| QETH_CAST_BROADCAST
;
998 return ct
| QETH_CAST_UNICAST
;
1001 static int qeth_l3_send_setadp_mode(struct qeth_card
*card
, __u32 command
,
1005 struct qeth_cmd_buffer
*iob
;
1006 struct qeth_ipa_cmd
*cmd
;
1008 QETH_CARD_TEXT(card
, 4, "adpmode");
1010 iob
= qeth_get_adapter_cmd(card
, command
,
1011 sizeof(struct qeth_ipacmd_setadpparms
));
1012 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
1013 cmd
->data
.setadapterparms
.data
.mode
= mode
;
1014 rc
= qeth_send_ipa_cmd(card
, iob
, qeth_default_setadapterparms_cb
,
1019 static int qeth_l3_setadapter_hstr(struct qeth_card
*card
)
1023 QETH_CARD_TEXT(card
, 4, "adphstr");
1025 if (qeth_adp_supported(card
, IPA_SETADP_SET_BROADCAST_MODE
)) {
1026 rc
= qeth_l3_send_setadp_mode(card
,
1027 IPA_SETADP_SET_BROADCAST_MODE
,
1028 card
->options
.broadcast_mode
);
1030 QETH_DBF_MESSAGE(2, "couldn't set broadcast mode on "
1032 CARD_BUS_ID(card
), rc
);
1033 rc
= qeth_l3_send_setadp_mode(card
,
1034 IPA_SETADP_ALTER_MAC_ADDRESS
,
1035 card
->options
.macaddr_mode
);
1037 QETH_DBF_MESSAGE(2, "couldn't set macaddr mode on "
1038 "device %s: x%x\n", CARD_BUS_ID(card
), rc
);
1041 if (card
->options
.broadcast_mode
== QETH_TR_BROADCAST_LOCAL
)
1042 QETH_DBF_MESSAGE(2, "set adapter parameters not available "
1043 "to set broadcast mode, using ALLRINGS "
1044 "on device %s:\n", CARD_BUS_ID(card
));
1045 if (card
->options
.macaddr_mode
== QETH_TR_MACADDR_CANONICAL
)
1046 QETH_DBF_MESSAGE(2, "set adapter parameters not available "
1047 "to set macaddr mode, using NONCANONICAL "
1048 "on device %s:\n", CARD_BUS_ID(card
));
1052 static int qeth_l3_setadapter_parms(struct qeth_card
*card
)
1056 QETH_DBF_TEXT(SETUP
, 2, "setadprm");
1058 if (!qeth_is_supported(card
, IPA_SETADAPTERPARMS
)) {
1059 dev_info(&card
->gdev
->dev
,
1060 "set adapter parameters not supported.\n");
1061 QETH_DBF_TEXT(SETUP
, 2, " notsupp");
1064 rc
= qeth_query_setadapterparms(card
);
1066 QETH_DBF_MESSAGE(2, "%s couldn't set adapter parameters: "
1067 "0x%x\n", dev_name(&card
->gdev
->dev
), rc
);
1070 if (qeth_adp_supported(card
, IPA_SETADP_ALTER_MAC_ADDRESS
)) {
1071 rc
= qeth_setadpparms_change_macaddr(card
);
1073 dev_warn(&card
->gdev
->dev
, "Reading the adapter MAC"
1074 " address failed\n");
1077 if ((card
->info
.link_type
== QETH_LINK_TYPE_HSTR
) ||
1078 (card
->info
.link_type
== QETH_LINK_TYPE_LANE_TR
))
1079 rc
= qeth_l3_setadapter_hstr(card
);
1084 static int qeth_l3_default_setassparms_cb(struct qeth_card
*card
,
1085 struct qeth_reply
*reply
, unsigned long data
)
1087 struct qeth_ipa_cmd
*cmd
;
1089 QETH_CARD_TEXT(card
, 4, "defadpcb");
1091 cmd
= (struct qeth_ipa_cmd
*) data
;
1092 if (cmd
->hdr
.return_code
== 0) {
1093 cmd
->hdr
.return_code
= cmd
->data
.setassparms
.hdr
.return_code
;
1094 if (cmd
->hdr
.prot_version
== QETH_PROT_IPV4
)
1095 card
->options
.ipa4
.enabled_funcs
= cmd
->hdr
.ipa_enabled
;
1096 if (cmd
->hdr
.prot_version
== QETH_PROT_IPV6
)
1097 card
->options
.ipa6
.enabled_funcs
= cmd
->hdr
.ipa_enabled
;
1099 if (cmd
->data
.setassparms
.hdr
.assist_no
== IPA_INBOUND_CHECKSUM
&&
1100 cmd
->data
.setassparms
.hdr
.command_code
== IPA_CMD_ASS_START
) {
1101 card
->info
.csum_mask
= cmd
->data
.setassparms
.data
.flags_32bit
;
1102 QETH_CARD_TEXT_(card
, 3, "csum:%d", card
->info
.csum_mask
);
1104 if (cmd
->data
.setassparms
.hdr
.assist_no
== IPA_OUTBOUND_CHECKSUM
&&
1105 cmd
->data
.setassparms
.hdr
.command_code
== IPA_CMD_ASS_START
) {
1106 card
->info
.tx_csum_mask
=
1107 cmd
->data
.setassparms
.data
.flags_32bit
;
1108 QETH_CARD_TEXT_(card
, 3, "tcsu:%d", card
->info
.tx_csum_mask
);
1114 static struct qeth_cmd_buffer
*qeth_l3_get_setassparms_cmd(
1115 struct qeth_card
*card
, enum qeth_ipa_funcs ipa_func
, __u16 cmd_code
,
1116 __u16 len
, enum qeth_prot_versions prot
)
1118 struct qeth_cmd_buffer
*iob
;
1119 struct qeth_ipa_cmd
*cmd
;
1121 QETH_CARD_TEXT(card
, 4, "getasscm");
1122 iob
= qeth_get_ipacmd_buffer(card
, IPA_CMD_SETASSPARMS
, prot
);
1124 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
1125 cmd
->data
.setassparms
.hdr
.assist_no
= ipa_func
;
1126 cmd
->data
.setassparms
.hdr
.length
= 8 + len
;
1127 cmd
->data
.setassparms
.hdr
.command_code
= cmd_code
;
1128 cmd
->data
.setassparms
.hdr
.return_code
= 0;
1129 cmd
->data
.setassparms
.hdr
.seq_no
= 0;
1134 static int qeth_l3_send_setassparms(struct qeth_card
*card
,
1135 struct qeth_cmd_buffer
*iob
, __u16 len
, long data
,
1136 int (*reply_cb
)(struct qeth_card
*, struct qeth_reply
*,
1141 struct qeth_ipa_cmd
*cmd
;
1143 QETH_CARD_TEXT(card
, 4, "sendassp");
1145 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
1146 if (len
<= sizeof(__u32
))
1147 cmd
->data
.setassparms
.data
.flags_32bit
= (__u32
) data
;
1148 else /* (len > sizeof(__u32)) */
1149 memcpy(&cmd
->data
.setassparms
.data
, (void *) data
, len
);
1151 rc
= qeth_send_ipa_cmd(card
, iob
, reply_cb
, reply_param
);
1155 #ifdef CONFIG_QETH_IPV6
1156 static int qeth_l3_send_simple_setassparms_ipv6(struct qeth_card
*card
,
1157 enum qeth_ipa_funcs ipa_func
, __u16 cmd_code
)
1160 struct qeth_cmd_buffer
*iob
;
1162 QETH_CARD_TEXT(card
, 4, "simassp6");
1163 iob
= qeth_l3_get_setassparms_cmd(card
, ipa_func
, cmd_code
,
1165 rc
= qeth_l3_send_setassparms(card
, iob
, 0, 0,
1166 qeth_l3_default_setassparms_cb
, NULL
);
1171 static int qeth_l3_send_simple_setassparms(struct qeth_card
*card
,
1172 enum qeth_ipa_funcs ipa_func
, __u16 cmd_code
, long data
)
1176 struct qeth_cmd_buffer
*iob
;
1178 QETH_CARD_TEXT(card
, 4, "simassp4");
1180 length
= sizeof(__u32
);
1181 iob
= qeth_l3_get_setassparms_cmd(card
, ipa_func
, cmd_code
,
1182 length
, QETH_PROT_IPV4
);
1183 rc
= qeth_l3_send_setassparms(card
, iob
, length
, data
,
1184 qeth_l3_default_setassparms_cb
, NULL
);
1188 static int qeth_l3_start_ipa_arp_processing(struct qeth_card
*card
)
1192 QETH_CARD_TEXT(card
, 3, "ipaarp");
1194 if (!qeth_is_supported(card
, IPA_ARP_PROCESSING
)) {
1195 dev_info(&card
->gdev
->dev
,
1196 "ARP processing not supported on %s!\n",
1197 QETH_CARD_IFNAME(card
));
1200 rc
= qeth_l3_send_simple_setassparms(card
, IPA_ARP_PROCESSING
,
1201 IPA_CMD_ASS_START
, 0);
1203 dev_warn(&card
->gdev
->dev
,
1204 "Starting ARP processing support for %s failed\n",
1205 QETH_CARD_IFNAME(card
));
1210 static int qeth_l3_start_ipa_ip_fragmentation(struct qeth_card
*card
)
1214 QETH_CARD_TEXT(card
, 3, "ipaipfrg");
1216 if (!qeth_is_supported(card
, IPA_IP_FRAGMENTATION
)) {
1217 dev_info(&card
->gdev
->dev
,
1218 "Hardware IP fragmentation not supported on %s\n",
1219 QETH_CARD_IFNAME(card
));
1223 rc
= qeth_l3_send_simple_setassparms(card
, IPA_IP_FRAGMENTATION
,
1224 IPA_CMD_ASS_START
, 0);
1226 dev_warn(&card
->gdev
->dev
,
1227 "Starting IP fragmentation support for %s failed\n",
1228 QETH_CARD_IFNAME(card
));
1230 dev_info(&card
->gdev
->dev
,
1231 "Hardware IP fragmentation enabled \n");
1235 static int qeth_l3_start_ipa_source_mac(struct qeth_card
*card
)
1239 QETH_CARD_TEXT(card
, 3, "stsrcmac");
1241 if (!qeth_is_supported(card
, IPA_SOURCE_MAC
)) {
1242 dev_info(&card
->gdev
->dev
,
1243 "Inbound source MAC-address not supported on %s\n",
1244 QETH_CARD_IFNAME(card
));
1248 rc
= qeth_l3_send_simple_setassparms(card
, IPA_SOURCE_MAC
,
1249 IPA_CMD_ASS_START
, 0);
1251 dev_warn(&card
->gdev
->dev
,
1252 "Starting source MAC-address support for %s failed\n",
1253 QETH_CARD_IFNAME(card
));
1257 static int qeth_l3_start_ipa_vlan(struct qeth_card
*card
)
1261 QETH_CARD_TEXT(card
, 3, "strtvlan");
1263 if (!qeth_is_supported(card
, IPA_FULL_VLAN
)) {
1264 dev_info(&card
->gdev
->dev
,
1265 "VLAN not supported on %s\n", QETH_CARD_IFNAME(card
));
1269 rc
= qeth_l3_send_simple_setassparms(card
, IPA_VLAN_PRIO
,
1270 IPA_CMD_ASS_START
, 0);
1272 dev_warn(&card
->gdev
->dev
,
1273 "Starting VLAN support for %s failed\n",
1274 QETH_CARD_IFNAME(card
));
1276 dev_info(&card
->gdev
->dev
, "VLAN enabled\n");
1281 static int qeth_l3_start_ipa_multicast(struct qeth_card
*card
)
1285 QETH_CARD_TEXT(card
, 3, "stmcast");
1287 if (!qeth_is_supported(card
, IPA_MULTICASTING
)) {
1288 dev_info(&card
->gdev
->dev
,
1289 "Multicast not supported on %s\n",
1290 QETH_CARD_IFNAME(card
));
1294 rc
= qeth_l3_send_simple_setassparms(card
, IPA_MULTICASTING
,
1295 IPA_CMD_ASS_START
, 0);
1297 dev_warn(&card
->gdev
->dev
,
1298 "Starting multicast support for %s failed\n",
1299 QETH_CARD_IFNAME(card
));
1301 dev_info(&card
->gdev
->dev
, "Multicast enabled\n");
1302 card
->dev
->flags
|= IFF_MULTICAST
;
1307 static int qeth_l3_query_ipassists_cb(struct qeth_card
*card
,
1308 struct qeth_reply
*reply
, unsigned long data
)
1310 struct qeth_ipa_cmd
*cmd
;
1312 QETH_DBF_TEXT(SETUP
, 2, "qipasscb");
1314 cmd
= (struct qeth_ipa_cmd
*) data
;
1315 if (cmd
->hdr
.prot_version
== QETH_PROT_IPV4
) {
1316 card
->options
.ipa4
.supported_funcs
= cmd
->hdr
.ipa_supported
;
1317 card
->options
.ipa4
.enabled_funcs
= cmd
->hdr
.ipa_enabled
;
1319 card
->options
.ipa6
.supported_funcs
= cmd
->hdr
.ipa_supported
;
1320 card
->options
.ipa6
.enabled_funcs
= cmd
->hdr
.ipa_enabled
;
1322 QETH_DBF_TEXT(SETUP
, 2, "suppenbl");
1323 QETH_DBF_TEXT_(SETUP
, 2, "%x", cmd
->hdr
.ipa_supported
);
1324 QETH_DBF_TEXT_(SETUP
, 2, "%x", cmd
->hdr
.ipa_enabled
);
1328 static int qeth_l3_query_ipassists(struct qeth_card
*card
,
1329 enum qeth_prot_versions prot
)
1332 struct qeth_cmd_buffer
*iob
;
1334 QETH_DBF_TEXT_(SETUP
, 2, "qipassi%i", prot
);
1335 iob
= qeth_get_ipacmd_buffer(card
, IPA_CMD_QIPASSIST
, prot
);
1336 rc
= qeth_send_ipa_cmd(card
, iob
, qeth_l3_query_ipassists_cb
, NULL
);
1340 #ifdef CONFIG_QETH_IPV6
1341 static int qeth_l3_softsetup_ipv6(struct qeth_card
*card
)
1345 QETH_CARD_TEXT(card
, 3, "softipv6");
1347 if (card
->info
.type
== QETH_CARD_TYPE_IQD
)
1350 rc
= qeth_l3_query_ipassists(card
, QETH_PROT_IPV6
);
1352 dev_err(&card
->gdev
->dev
,
1353 "Activating IPv6 support for %s failed\n",
1354 QETH_CARD_IFNAME(card
));
1357 rc
= qeth_l3_send_simple_setassparms(card
, IPA_IPV6
,
1358 IPA_CMD_ASS_START
, 3);
1360 dev_err(&card
->gdev
->dev
,
1361 "Activating IPv6 support for %s failed\n",
1362 QETH_CARD_IFNAME(card
));
1365 rc
= qeth_l3_send_simple_setassparms_ipv6(card
, IPA_IPV6
,
1368 dev_err(&card
->gdev
->dev
,
1369 "Activating IPv6 support for %s failed\n",
1370 QETH_CARD_IFNAME(card
));
1373 rc
= qeth_l3_send_simple_setassparms_ipv6(card
, IPA_PASSTHRU
,
1376 dev_warn(&card
->gdev
->dev
,
1377 "Enabling the passthrough mode for %s failed\n",
1378 QETH_CARD_IFNAME(card
));
1382 dev_info(&card
->gdev
->dev
, "IPV6 enabled\n");
1387 static int qeth_l3_start_ipa_ipv6(struct qeth_card
*card
)
1391 QETH_CARD_TEXT(card
, 3, "strtipv6");
1393 if (!qeth_is_supported(card
, IPA_IPV6
)) {
1394 dev_info(&card
->gdev
->dev
,
1395 "IPv6 not supported on %s\n", QETH_CARD_IFNAME(card
));
1398 #ifdef CONFIG_QETH_IPV6
1399 rc
= qeth_l3_softsetup_ipv6(card
);
1404 static int qeth_l3_start_ipa_broadcast(struct qeth_card
*card
)
1408 QETH_CARD_TEXT(card
, 3, "stbrdcst");
1409 card
->info
.broadcast_capable
= 0;
1410 if (!qeth_is_supported(card
, IPA_FILTERING
)) {
1411 dev_info(&card
->gdev
->dev
,
1412 "Broadcast not supported on %s\n",
1413 QETH_CARD_IFNAME(card
));
1417 rc
= qeth_l3_send_simple_setassparms(card
, IPA_FILTERING
,
1418 IPA_CMD_ASS_START
, 0);
1420 dev_warn(&card
->gdev
->dev
, "Enabling broadcast filtering for "
1421 "%s failed\n", QETH_CARD_IFNAME(card
));
1425 rc
= qeth_l3_send_simple_setassparms(card
, IPA_FILTERING
,
1426 IPA_CMD_ASS_CONFIGURE
, 1);
1428 dev_warn(&card
->gdev
->dev
,
1429 "Setting up broadcast filtering for %s failed\n",
1430 QETH_CARD_IFNAME(card
));
1433 card
->info
.broadcast_capable
= QETH_BROADCAST_WITH_ECHO
;
1434 dev_info(&card
->gdev
->dev
, "Broadcast enabled\n");
1435 rc
= qeth_l3_send_simple_setassparms(card
, IPA_FILTERING
,
1436 IPA_CMD_ASS_ENABLE
, 1);
1438 dev_warn(&card
->gdev
->dev
, "Setting up broadcast echo "
1439 "filtering for %s failed\n", QETH_CARD_IFNAME(card
));
1442 card
->info
.broadcast_capable
= QETH_BROADCAST_WITHOUT_ECHO
;
1444 if (card
->info
.broadcast_capable
)
1445 card
->dev
->flags
|= IFF_BROADCAST
;
1447 card
->dev
->flags
&= ~IFF_BROADCAST
;
1451 static int qeth_l3_send_checksum_command(struct qeth_card
*card
)
1455 rc
= qeth_l3_send_simple_setassparms(card
, IPA_INBOUND_CHECKSUM
,
1456 IPA_CMD_ASS_START
, 0);
1458 dev_warn(&card
->gdev
->dev
, "Starting HW checksumming for %s "
1459 "failed, using SW checksumming\n",
1460 QETH_CARD_IFNAME(card
));
1463 rc
= qeth_l3_send_simple_setassparms(card
, IPA_INBOUND_CHECKSUM
,
1465 card
->info
.csum_mask
);
1467 dev_warn(&card
->gdev
->dev
, "Enabling HW checksumming for %s "
1468 "failed, using SW checksumming\n",
1469 QETH_CARD_IFNAME(card
));
1475 int qeth_l3_set_rx_csum(struct qeth_card
*card
,
1476 enum qeth_checksum_types csum_type
)
1480 if (card
->options
.checksum_type
== HW_CHECKSUMMING
) {
1481 if ((csum_type
!= HW_CHECKSUMMING
) &&
1482 (card
->state
!= CARD_STATE_DOWN
)) {
1483 rc
= qeth_l3_send_simple_setassparms(card
,
1484 IPA_INBOUND_CHECKSUM
, IPA_CMD_ASS_STOP
, 0);
1489 if (csum_type
== HW_CHECKSUMMING
) {
1490 if (card
->state
!= CARD_STATE_DOWN
) {
1491 if (!qeth_is_supported(card
,
1492 IPA_INBOUND_CHECKSUM
))
1494 rc
= qeth_l3_send_checksum_command(card
);
1500 card
->options
.checksum_type
= csum_type
;
1504 static int qeth_l3_start_ipa_checksum(struct qeth_card
*card
)
1508 QETH_CARD_TEXT(card
, 3, "strtcsum");
1510 if (card
->options
.checksum_type
== NO_CHECKSUMMING
) {
1511 dev_info(&card
->gdev
->dev
,
1512 "Using no checksumming on %s.\n",
1513 QETH_CARD_IFNAME(card
));
1516 if (card
->options
.checksum_type
== SW_CHECKSUMMING
) {
1517 dev_info(&card
->gdev
->dev
,
1518 "Using SW checksumming on %s.\n",
1519 QETH_CARD_IFNAME(card
));
1522 if (!qeth_is_supported(card
, IPA_INBOUND_CHECKSUM
)) {
1523 dev_info(&card
->gdev
->dev
,
1524 "Inbound HW Checksumming not "
1525 "supported on %s,\ncontinuing "
1526 "using Inbound SW Checksumming\n",
1527 QETH_CARD_IFNAME(card
));
1528 card
->options
.checksum_type
= SW_CHECKSUMMING
;
1531 rc
= qeth_l3_send_checksum_command(card
);
1533 dev_info(&card
->gdev
->dev
,
1534 "HW Checksumming (inbound) enabled\n");
1539 static int qeth_l3_start_ipa_tx_checksum(struct qeth_card
*card
)
1543 if (!qeth_is_supported(card
, IPA_OUTBOUND_CHECKSUM
))
1545 rc
= qeth_l3_send_simple_setassparms(card
, IPA_OUTBOUND_CHECKSUM
,
1546 IPA_CMD_ASS_START
, 0);
1549 rc
= qeth_l3_send_simple_setassparms(card
, IPA_OUTBOUND_CHECKSUM
,
1550 IPA_CMD_ASS_ENABLE
, card
->info
.tx_csum_mask
);
1553 dev_info(&card
->gdev
->dev
, "HW TX Checksumming enabled\n");
1556 dev_warn(&card
->gdev
->dev
, "Enabling HW TX checksumming for %s "
1557 "failed, using SW TX checksumming\n", QETH_CARD_IFNAME(card
));
1561 static int qeth_l3_start_ipa_tso(struct qeth_card
*card
)
1565 QETH_CARD_TEXT(card
, 3, "sttso");
1567 if (!qeth_is_supported(card
, IPA_OUTBOUND_TSO
)) {
1568 dev_info(&card
->gdev
->dev
,
1569 "Outbound TSO not supported on %s\n",
1570 QETH_CARD_IFNAME(card
));
1573 rc
= qeth_l3_send_simple_setassparms(card
, IPA_OUTBOUND_TSO
,
1574 IPA_CMD_ASS_START
, 0);
1576 dev_warn(&card
->gdev
->dev
, "Starting outbound TCP "
1577 "segmentation offload for %s failed\n",
1578 QETH_CARD_IFNAME(card
));
1580 dev_info(&card
->gdev
->dev
,
1581 "Outbound TSO enabled\n");
1583 if (rc
&& (card
->options
.large_send
== QETH_LARGE_SEND_TSO
)) {
1584 card
->options
.large_send
= QETH_LARGE_SEND_NO
;
1585 card
->dev
->features
&= ~(NETIF_F_TSO
| NETIF_F_SG
);
1590 static int qeth_l3_start_ipassists(struct qeth_card
*card
)
1592 QETH_CARD_TEXT(card
, 3, "strtipas");
1594 qeth_set_access_ctrl_online(card
); /* go on*/
1595 qeth_l3_start_ipa_arp_processing(card
); /* go on*/
1596 qeth_l3_start_ipa_ip_fragmentation(card
); /* go on*/
1597 qeth_l3_start_ipa_source_mac(card
); /* go on*/
1598 qeth_l3_start_ipa_vlan(card
); /* go on*/
1599 qeth_l3_start_ipa_multicast(card
); /* go on*/
1600 qeth_l3_start_ipa_ipv6(card
); /* go on*/
1601 qeth_l3_start_ipa_broadcast(card
); /* go on*/
1602 qeth_l3_start_ipa_checksum(card
); /* go on*/
1603 qeth_l3_start_ipa_tx_checksum(card
);
1604 qeth_l3_start_ipa_tso(card
); /* go on*/
1608 static int qeth_l3_iqd_read_initial_mac_cb(struct qeth_card
*card
,
1609 struct qeth_reply
*reply
, unsigned long data
)
1611 struct qeth_ipa_cmd
*cmd
;
1613 cmd
= (struct qeth_ipa_cmd
*) data
;
1614 if (cmd
->hdr
.return_code
== 0)
1615 memcpy(card
->dev
->dev_addr
,
1616 cmd
->data
.create_destroy_addr
.unique_id
, ETH_ALEN
);
1618 random_ether_addr(card
->dev
->dev_addr
);
1623 static int qeth_l3_iqd_read_initial_mac(struct qeth_card
*card
)
1626 struct qeth_cmd_buffer
*iob
;
1627 struct qeth_ipa_cmd
*cmd
;
1629 QETH_DBF_TEXT(SETUP
, 2, "hsrmac");
1631 iob
= qeth_get_ipacmd_buffer(card
, IPA_CMD_CREATE_ADDR
,
1633 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
1634 *((__u16
*) &cmd
->data
.create_destroy_addr
.unique_id
[6]) =
1635 card
->info
.unique_id
;
1637 rc
= qeth_send_ipa_cmd(card
, iob
, qeth_l3_iqd_read_initial_mac_cb
,
1642 static int qeth_l3_get_unique_id_cb(struct qeth_card
*card
,
1643 struct qeth_reply
*reply
, unsigned long data
)
1645 struct qeth_ipa_cmd
*cmd
;
1647 cmd
= (struct qeth_ipa_cmd
*) data
;
1648 if (cmd
->hdr
.return_code
== 0)
1649 card
->info
.unique_id
= *((__u16
*)
1650 &cmd
->data
.create_destroy_addr
.unique_id
[6]);
1652 card
->info
.unique_id
= UNIQUE_ID_IF_CREATE_ADDR_FAILED
|
1653 UNIQUE_ID_NOT_BY_CARD
;
1654 dev_warn(&card
->gdev
->dev
, "The network adapter failed to "
1655 "generate a unique ID\n");
1660 static int qeth_l3_get_unique_id(struct qeth_card
*card
)
1663 struct qeth_cmd_buffer
*iob
;
1664 struct qeth_ipa_cmd
*cmd
;
1666 QETH_DBF_TEXT(SETUP
, 2, "guniqeid");
1668 if (!qeth_is_supported(card
, IPA_IPV6
)) {
1669 card
->info
.unique_id
= UNIQUE_ID_IF_CREATE_ADDR_FAILED
|
1670 UNIQUE_ID_NOT_BY_CARD
;
1674 iob
= qeth_get_ipacmd_buffer(card
, IPA_CMD_CREATE_ADDR
,
1676 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
1677 *((__u16
*) &cmd
->data
.create_destroy_addr
.unique_id
[6]) =
1678 card
->info
.unique_id
;
1680 rc
= qeth_send_ipa_cmd(card
, iob
, qeth_l3_get_unique_id_cb
, NULL
);
1685 qeth_diags_trace_cb(struct qeth_card
*card
, struct qeth_reply
*reply
,
1688 struct qeth_ipa_cmd
*cmd
;
1691 QETH_DBF_TEXT(SETUP
, 2, "diastrcb");
1693 cmd
= (struct qeth_ipa_cmd
*)data
;
1694 rc
= cmd
->hdr
.return_code
;
1696 QETH_CARD_TEXT_(card
, 2, "dxter%x", rc
);
1697 switch (cmd
->data
.diagass
.action
) {
1698 case QETH_DIAGS_CMD_TRACE_QUERY
:
1700 case QETH_DIAGS_CMD_TRACE_DISABLE
:
1703 case IPA_RC_INVALID_SUBCMD
:
1704 card
->info
.promisc_mode
= SET_PROMISC_MODE_OFF
;
1705 dev_info(&card
->gdev
->dev
, "The HiperSockets network "
1706 "traffic analyzer is deactivated\n");
1712 case QETH_DIAGS_CMD_TRACE_ENABLE
:
1715 card
->info
.promisc_mode
= SET_PROMISC_MODE_ON
;
1716 dev_info(&card
->gdev
->dev
, "The HiperSockets network "
1717 "traffic analyzer is activated\n");
1719 case IPA_RC_HARDWARE_AUTH_ERROR
:
1720 dev_warn(&card
->gdev
->dev
, "The device is not "
1721 "authorized to run as a HiperSockets network "
1722 "traffic analyzer\n");
1724 case IPA_RC_TRACE_ALREADY_ACTIVE
:
1725 dev_warn(&card
->gdev
->dev
, "A HiperSockets "
1726 "network traffic analyzer is already "
1727 "active in the HiperSockets LAN\n");
1734 QETH_DBF_MESSAGE(2, "Unknown sniffer action (0x%04x) on %s\n",
1735 cmd
->data
.diagass
.action
, QETH_CARD_IFNAME(card
));
1742 qeth_diags_trace(struct qeth_card
*card
, enum qeth_diags_trace_cmds diags_cmd
)
1744 struct qeth_cmd_buffer
*iob
;
1745 struct qeth_ipa_cmd
*cmd
;
1747 QETH_DBF_TEXT(SETUP
, 2, "diagtrac");
1749 iob
= qeth_get_ipacmd_buffer(card
, IPA_CMD_SET_DIAG_ASS
, 0);
1750 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
1751 cmd
->data
.diagass
.subcmd_len
= 16;
1752 cmd
->data
.diagass
.subcmd
= QETH_DIAGS_CMD_TRACE
;
1753 cmd
->data
.diagass
.type
= QETH_DIAGS_TYPE_HIPERSOCKET
;
1754 cmd
->data
.diagass
.action
= diags_cmd
;
1755 return qeth_send_ipa_cmd(card
, iob
, qeth_diags_trace_cb
, NULL
);
1758 static void qeth_l3_get_mac_for_ipm(__u32 ipm
, char *mac
,
1759 struct net_device
*dev
)
1761 if (dev
->type
== ARPHRD_IEEE802_TR
)
1762 ip_tr_mc_map(ipm
, mac
);
1764 ip_eth_mc_map(ipm
, mac
);
1767 static void qeth_l3_add_mc(struct qeth_card
*card
, struct in_device
*in4_dev
)
1769 struct qeth_ipaddr
*ipm
;
1770 struct ip_mc_list
*im4
;
1771 char buf
[MAX_ADDR_LEN
];
1773 QETH_CARD_TEXT(card
, 4, "addmc");
1774 for (im4
= rcu_dereference(in4_dev
->mc_list
); im4
!= NULL
;
1775 im4
= rcu_dereference(im4
->next_rcu
)) {
1776 qeth_l3_get_mac_for_ipm(im4
->multiaddr
, buf
, in4_dev
->dev
);
1777 ipm
= qeth_l3_get_addr_buffer(QETH_PROT_IPV4
);
1780 ipm
->u
.a4
.addr
= im4
->multiaddr
;
1781 memcpy(ipm
->mac
, buf
, OSA_ADDR_LEN
);
1782 ipm
->is_multicast
= 1;
1783 if (!qeth_l3_add_ip(card
, ipm
))
1788 static void qeth_l3_add_vlan_mc(struct qeth_card
*card
)
1790 struct in_device
*in_dev
;
1791 struct vlan_group
*vg
;
1794 QETH_CARD_TEXT(card
, 4, "addmcvl");
1795 if (!qeth_is_supported(card
, IPA_FULL_VLAN
) || (card
->vlangrp
== NULL
))
1799 for (i
= 0; i
< VLAN_N_VID
; i
++) {
1800 struct net_device
*netdev
= vlan_group_get_device(vg
, i
);
1801 if (netdev
== NULL
||
1802 !(netdev
->flags
& IFF_UP
))
1804 in_dev
= in_dev_get(netdev
);
1808 qeth_l3_add_mc(card
, in_dev
);
1814 static void qeth_l3_add_multicast_ipv4(struct qeth_card
*card
)
1816 struct in_device
*in4_dev
;
1818 QETH_CARD_TEXT(card
, 4, "chkmcv4");
1819 in4_dev
= in_dev_get(card
->dev
);
1820 if (in4_dev
== NULL
)
1823 qeth_l3_add_mc(card
, in4_dev
);
1824 qeth_l3_add_vlan_mc(card
);
1826 in_dev_put(in4_dev
);
1829 #ifdef CONFIG_QETH_IPV6
1830 static void qeth_l3_add_mc6(struct qeth_card
*card
, struct inet6_dev
*in6_dev
)
1832 struct qeth_ipaddr
*ipm
;
1833 struct ifmcaddr6
*im6
;
1834 char buf
[MAX_ADDR_LEN
];
1836 QETH_CARD_TEXT(card
, 4, "addmc6");
1837 for (im6
= in6_dev
->mc_list
; im6
!= NULL
; im6
= im6
->next
) {
1838 ndisc_mc_map(&im6
->mca_addr
, buf
, in6_dev
->dev
, 0);
1839 ipm
= qeth_l3_get_addr_buffer(QETH_PROT_IPV6
);
1842 ipm
->is_multicast
= 1;
1843 memcpy(ipm
->mac
, buf
, OSA_ADDR_LEN
);
1844 memcpy(&ipm
->u
.a6
.addr
, &im6
->mca_addr
.s6_addr
,
1845 sizeof(struct in6_addr
));
1846 if (!qeth_l3_add_ip(card
, ipm
))
1851 static void qeth_l3_add_vlan_mc6(struct qeth_card
*card
)
1853 struct inet6_dev
*in_dev
;
1854 struct vlan_group
*vg
;
1857 QETH_CARD_TEXT(card
, 4, "admc6vl");
1858 if (!qeth_is_supported(card
, IPA_FULL_VLAN
) || (card
->vlangrp
== NULL
))
1862 for (i
= 0; i
< VLAN_N_VID
; i
++) {
1863 struct net_device
*netdev
= vlan_group_get_device(vg
, i
);
1864 if (netdev
== NULL
||
1865 !(netdev
->flags
& IFF_UP
))
1867 in_dev
= in6_dev_get(netdev
);
1870 read_lock_bh(&in_dev
->lock
);
1871 qeth_l3_add_mc6(card
, in_dev
);
1872 read_unlock_bh(&in_dev
->lock
);
1873 in6_dev_put(in_dev
);
1877 static void qeth_l3_add_multicast_ipv6(struct qeth_card
*card
)
1879 struct inet6_dev
*in6_dev
;
1881 QETH_CARD_TEXT(card
, 4, "chkmcv6");
1882 if (!qeth_is_supported(card
, IPA_IPV6
))
1884 in6_dev
= in6_dev_get(card
->dev
);
1885 if (in6_dev
== NULL
)
1887 read_lock_bh(&in6_dev
->lock
);
1888 qeth_l3_add_mc6(card
, in6_dev
);
1889 qeth_l3_add_vlan_mc6(card
);
1890 read_unlock_bh(&in6_dev
->lock
);
1891 in6_dev_put(in6_dev
);
1893 #endif /* CONFIG_QETH_IPV6 */
1895 static void qeth_l3_free_vlan_addresses4(struct qeth_card
*card
,
1898 struct in_device
*in_dev
;
1899 struct in_ifaddr
*ifa
;
1900 struct qeth_ipaddr
*addr
;
1902 QETH_CARD_TEXT(card
, 4, "frvaddr4");
1904 in_dev
= in_dev_get(vlan_group_get_device(card
->vlangrp
, vid
));
1907 for (ifa
= in_dev
->ifa_list
; ifa
; ifa
= ifa
->ifa_next
) {
1908 addr
= qeth_l3_get_addr_buffer(QETH_PROT_IPV4
);
1910 addr
->u
.a4
.addr
= ifa
->ifa_address
;
1911 addr
->u
.a4
.mask
= ifa
->ifa_mask
;
1912 addr
->type
= QETH_IP_TYPE_NORMAL
;
1913 if (!qeth_l3_delete_ip(card
, addr
))
1920 static void qeth_l3_free_vlan_addresses6(struct qeth_card
*card
,
1923 #ifdef CONFIG_QETH_IPV6
1924 struct inet6_dev
*in6_dev
;
1925 struct inet6_ifaddr
*ifa
;
1926 struct qeth_ipaddr
*addr
;
1928 QETH_CARD_TEXT(card
, 4, "frvaddr6");
1930 in6_dev
= in6_dev_get(vlan_group_get_device(card
->vlangrp
, vid
));
1933 list_for_each_entry(ifa
, &in6_dev
->addr_list
, if_list
) {
1934 addr
= qeth_l3_get_addr_buffer(QETH_PROT_IPV6
);
1936 memcpy(&addr
->u
.a6
.addr
, &ifa
->addr
,
1937 sizeof(struct in6_addr
));
1938 addr
->u
.a6
.pfxlen
= ifa
->prefix_len
;
1939 addr
->type
= QETH_IP_TYPE_NORMAL
;
1940 if (!qeth_l3_delete_ip(card
, addr
))
1944 in6_dev_put(in6_dev
);
1945 #endif /* CONFIG_QETH_IPV6 */
1948 static void qeth_l3_free_vlan_addresses(struct qeth_card
*card
,
1953 qeth_l3_free_vlan_addresses4(card
, vid
);
1954 qeth_l3_free_vlan_addresses6(card
, vid
);
1957 static void qeth_l3_vlan_rx_register(struct net_device
*dev
,
1958 struct vlan_group
*grp
)
1960 struct qeth_card
*card
= dev
->ml_priv
;
1961 unsigned long flags
;
1963 QETH_CARD_TEXT(card
, 4, "vlanreg");
1964 spin_lock_irqsave(&card
->vlanlock
, flags
);
1965 card
->vlangrp
= grp
;
1966 spin_unlock_irqrestore(&card
->vlanlock
, flags
);
1969 static void qeth_l3_vlan_rx_add_vid(struct net_device
*dev
, unsigned short vid
)
1974 static void qeth_l3_vlan_rx_kill_vid(struct net_device
*dev
, unsigned short vid
)
1976 struct qeth_card
*card
= dev
->ml_priv
;
1977 unsigned long flags
;
1979 QETH_CARD_TEXT_(card
, 4, "kid:%d", vid
);
1980 if (qeth_wait_for_threads(card
, QETH_RECOVER_THREAD
)) {
1981 QETH_CARD_TEXT(card
, 3, "kidREC");
1984 spin_lock_irqsave(&card
->vlanlock
, flags
);
1985 /* unregister IP addresses of vlan device */
1986 qeth_l3_free_vlan_addresses(card
, vid
);
1987 vlan_group_set_device(card
->vlangrp
, vid
, NULL
);
1988 spin_unlock_irqrestore(&card
->vlanlock
, flags
);
1989 qeth_l3_set_multicast_list(card
->dev
);
1992 static inline int qeth_l3_rebuild_skb(struct qeth_card
*card
,
1993 struct sk_buff
*skb
, struct qeth_hdr
*hdr
,
1994 unsigned short *vlan_id
)
1997 struct iphdr
*ip_hdr
;
1998 unsigned char tg_addr
[MAX_ADDR_LEN
];
2001 if (!(hdr
->hdr
.l3
.flags
& QETH_HDR_PASSTHRU
)) {
2002 prot
= htons((hdr
->hdr
.l3
.flags
& QETH_HDR_IPV6
)? ETH_P_IPV6
:
2004 switch (hdr
->hdr
.l3
.flags
& QETH_HDR_CAST_MASK
) {
2005 case QETH_CAST_MULTICAST
:
2007 #ifdef CONFIG_QETH_IPV6
2008 case __constant_htons(ETH_P_IPV6
):
2009 ndisc_mc_map((struct in6_addr
*)
2011 tg_addr
, card
->dev
, 0);
2014 case __constant_htons(ETH_P_IP
):
2015 ip_hdr
= (struct iphdr
*)skb
->data
;
2016 (card
->dev
->type
== ARPHRD_IEEE802_TR
) ?
2017 ip_tr_mc_map(ip_hdr
->daddr
, tg_addr
):
2018 ip_eth_mc_map(ip_hdr
->daddr
, tg_addr
);
2021 memcpy(tg_addr
, card
->dev
->broadcast
,
2022 card
->dev
->addr_len
);
2024 card
->stats
.multicast
++;
2025 skb
->pkt_type
= PACKET_MULTICAST
;
2027 case QETH_CAST_BROADCAST
:
2028 memcpy(tg_addr
, card
->dev
->broadcast
,
2029 card
->dev
->addr_len
);
2030 card
->stats
.multicast
++;
2031 skb
->pkt_type
= PACKET_BROADCAST
;
2033 case QETH_CAST_UNICAST
:
2034 case QETH_CAST_ANYCAST
:
2035 case QETH_CAST_NOCAST
:
2037 if (card
->options
.sniffer
)
2038 skb
->pkt_type
= PACKET_OTHERHOST
;
2040 skb
->pkt_type
= PACKET_HOST
;
2041 memcpy(tg_addr
, card
->dev
->dev_addr
,
2042 card
->dev
->addr_len
);
2044 if (hdr
->hdr
.l3
.ext_flags
& QETH_HDR_EXT_SRC_MAC_ADDR
)
2045 card
->dev
->header_ops
->create(skb
, card
->dev
, prot
,
2046 tg_addr
, &hdr
->hdr
.l3
.dest_addr
[2],
2047 card
->dev
->addr_len
);
2049 card
->dev
->header_ops
->create(skb
, card
->dev
, prot
,
2050 tg_addr
, "FAKELL", card
->dev
->addr_len
);
2054 if (card
->dev
->type
== ARPHRD_IEEE802_TR
)
2055 skb
->protocol
= tr_type_trans(skb
, card
->dev
);
2058 skb
->protocol
= eth_type_trans(skb
, card
->dev
);
2060 if (hdr
->hdr
.l3
.ext_flags
&
2061 (QETH_HDR_EXT_VLAN_FRAME
| QETH_HDR_EXT_INCLUDE_VLAN_TAG
)) {
2062 *vlan_id
= (hdr
->hdr
.l3
.ext_flags
& QETH_HDR_EXT_VLAN_FRAME
) ?
2063 hdr
->hdr
.l3
.vlan_id
: *((u16
*)&hdr
->hdr
.l3
.dest_addr
[12]);
2067 switch (card
->options
.checksum_type
) {
2068 case SW_CHECKSUMMING
:
2069 skb
->ip_summed
= CHECKSUM_NONE
;
2071 case NO_CHECKSUMMING
:
2072 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
2074 case HW_CHECKSUMMING
:
2075 if ((hdr
->hdr
.l3
.ext_flags
&
2076 (QETH_HDR_EXT_CSUM_HDR_REQ
|
2077 QETH_HDR_EXT_CSUM_TRANSP_REQ
)) ==
2078 (QETH_HDR_EXT_CSUM_HDR_REQ
|
2079 QETH_HDR_EXT_CSUM_TRANSP_REQ
))
2080 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
2082 skb
->ip_summed
= CHECKSUM_NONE
;
2088 static int qeth_l3_process_inbound_buffer(struct qeth_card
*card
,
2089 int budget
, int *done
)
2092 struct sk_buff
*skb
;
2093 struct qeth_hdr
*hdr
;
2101 skb
= qeth_core_get_next_skb(card
,
2102 card
->qdio
.in_q
->bufs
[card
->rx
.b_index
].buffer
,
2103 &card
->rx
.b_element
, &card
->rx
.e_offset
, &hdr
);
2108 skb
->dev
= card
->dev
;
2109 switch (hdr
->hdr
.l3
.id
) {
2110 case QETH_HEADER_TYPE_LAYER3
:
2111 is_vlan
= qeth_l3_rebuild_skb(card
, skb
, hdr
,
2114 if (is_vlan
&& !card
->options
.sniffer
)
2115 vlan_gro_receive(&card
->napi
, card
->vlangrp
,
2118 napi_gro_receive(&card
->napi
, skb
);
2120 case QETH_HEADER_TYPE_LAYER2
: /* for HiperSockets sniffer */
2121 skb
->pkt_type
= PACKET_HOST
;
2122 skb
->protocol
= eth_type_trans(skb
, skb
->dev
);
2124 netif_receive_skb(skb
);
2127 dev_kfree_skb_any(skb
);
2128 QETH_CARD_TEXT(card
, 3, "inbunkno");
2129 QETH_DBF_HEX(CTRL
, 3, hdr
, QETH_DBF_CTRL_LEN
);
2134 card
->stats
.rx_packets
++;
2135 card
->stats
.rx_bytes
+= len
;
2140 static int qeth_l3_poll(struct napi_struct
*napi
, int budget
)
2142 struct qeth_card
*card
= container_of(napi
, struct qeth_card
, napi
);
2144 struct qeth_qdio_buffer
*buffer
;
2146 int new_budget
= budget
;
2148 if (card
->options
.performance_stats
) {
2149 card
->perf_stats
.inbound_cnt
++;
2150 card
->perf_stats
.inbound_start_time
= qeth_get_micros();
2154 if (!card
->rx
.b_count
) {
2155 card
->rx
.qdio_err
= 0;
2156 card
->rx
.b_count
= qdio_get_next_buffers(
2157 card
->data
.ccwdev
, 0, &card
->rx
.b_index
,
2158 &card
->rx
.qdio_err
);
2159 if (card
->rx
.b_count
<= 0) {
2160 card
->rx
.b_count
= 0;
2163 card
->rx
.b_element
=
2164 &card
->qdio
.in_q
->bufs
[card
->rx
.b_index
]
2165 .buffer
->element
[0];
2166 card
->rx
.e_offset
= 0;
2169 while (card
->rx
.b_count
) {
2170 buffer
= &card
->qdio
.in_q
->bufs
[card
->rx
.b_index
];
2171 if (!(card
->rx
.qdio_err
&&
2172 qeth_check_qdio_errors(card
, buffer
->buffer
,
2173 card
->rx
.qdio_err
, "qinerr")))
2174 work_done
+= qeth_l3_process_inbound_buffer(
2175 card
, new_budget
, &done
);
2180 if (card
->options
.performance_stats
)
2181 card
->perf_stats
.bufs_rec
++;
2182 qeth_put_buffer_pool_entry(card
,
2183 buffer
->pool_entry
);
2184 qeth_queue_input_buffer(card
, card
->rx
.b_index
);
2186 if (card
->rx
.b_count
) {
2188 (card
->rx
.b_index
+ 1) %
2189 QDIO_MAX_BUFFERS_PER_Q
;
2190 card
->rx
.b_element
=
2192 ->bufs
[card
->rx
.b_index
]
2193 .buffer
->element
[0];
2194 card
->rx
.e_offset
= 0;
2198 if (work_done
>= budget
)
2201 new_budget
= budget
- work_done
;
2205 napi_complete(napi
);
2206 if (qdio_start_irq(card
->data
.ccwdev
, 0))
2207 napi_schedule(&card
->napi
);
2209 if (card
->options
.performance_stats
)
2210 card
->perf_stats
.inbound_time
+= qeth_get_micros() -
2211 card
->perf_stats
.inbound_start_time
;
2215 static int qeth_l3_verify_vlan_dev(struct net_device
*dev
,
2216 struct qeth_card
*card
)
2219 struct vlan_group
*vg
;
2226 for (i
= 0; i
< VLAN_N_VID
; i
++) {
2227 if (vlan_group_get_device(vg
, i
) == dev
) {
2228 rc
= QETH_VLAN_CARD
;
2233 if (rc
&& !(vlan_dev_real_dev(dev
)->ml_priv
== (void *)card
))
2239 static int qeth_l3_verify_dev(struct net_device
*dev
)
2241 struct qeth_card
*card
;
2242 unsigned long flags
;
2245 read_lock_irqsave(&qeth_core_card_list
.rwlock
, flags
);
2246 list_for_each_entry(card
, &qeth_core_card_list
.list
, list
) {
2247 if (card
->dev
== dev
) {
2248 rc
= QETH_REAL_CARD
;
2251 rc
= qeth_l3_verify_vlan_dev(dev
, card
);
2255 read_unlock_irqrestore(&qeth_core_card_list
.rwlock
, flags
);
2260 static struct qeth_card
*qeth_l3_get_card_from_dev(struct net_device
*dev
)
2262 struct qeth_card
*card
= NULL
;
2265 rc
= qeth_l3_verify_dev(dev
);
2266 if (rc
== QETH_REAL_CARD
)
2267 card
= dev
->ml_priv
;
2268 else if (rc
== QETH_VLAN_CARD
)
2269 card
= vlan_dev_real_dev(dev
)->ml_priv
;
2270 if (card
&& card
->options
.layer2
)
2273 QETH_CARD_TEXT_(card
, 4, "%d", rc
);
2277 static int qeth_l3_stop_card(struct qeth_card
*card
, int recovery_mode
)
2281 QETH_DBF_TEXT(SETUP
, 2, "stopcard");
2282 QETH_DBF_HEX(SETUP
, 2, &card
, sizeof(void *));
2284 qeth_set_allowed_threads(card
, 0, 1);
2285 if (card
->options
.sniffer
&&
2286 (card
->info
.promisc_mode
== SET_PROMISC_MODE_ON
))
2287 qeth_diags_trace(card
, QETH_DIAGS_CMD_TRACE_DISABLE
);
2288 if (card
->read
.state
== CH_STATE_UP
&&
2289 card
->write
.state
== CH_STATE_UP
&&
2290 (card
->state
== CARD_STATE_UP
)) {
2292 qeth_l3_stop(card
->dev
);
2295 dev_close(card
->dev
);
2298 card
->state
= CARD_STATE_SOFTSETUP
;
2300 if (card
->state
== CARD_STATE_SOFTSETUP
) {
2301 qeth_l3_clear_ip_list(card
, 1);
2302 qeth_clear_ipacmd_list(card
);
2303 card
->state
= CARD_STATE_HARDSETUP
;
2305 if (card
->state
== CARD_STATE_HARDSETUP
) {
2306 qeth_qdio_clear_card(card
, 0);
2307 qeth_clear_qdio_buffers(card
);
2308 qeth_clear_working_pool_list(card
);
2309 card
->state
= CARD_STATE_DOWN
;
2311 if (card
->state
== CARD_STATE_DOWN
) {
2312 qeth_clear_cmd_buffers(&card
->read
);
2313 qeth_clear_cmd_buffers(&card
->write
);
2319 * test for and Switch promiscuous mode (on or off)
2320 * either for guestlan or HiperSocket Sniffer
2323 qeth_l3_handle_promisc_mode(struct qeth_card
*card
)
2325 struct net_device
*dev
= card
->dev
;
2327 if (((dev
->flags
& IFF_PROMISC
) &&
2328 (card
->info
.promisc_mode
== SET_PROMISC_MODE_ON
)) ||
2329 (!(dev
->flags
& IFF_PROMISC
) &&
2330 (card
->info
.promisc_mode
== SET_PROMISC_MODE_OFF
)))
2333 if (card
->info
.guestlan
) { /* Guestlan trace */
2334 if (qeth_adp_supported(card
, IPA_SETADP_SET_PROMISC_MODE
))
2335 qeth_setadp_promisc_mode(card
);
2336 } else if (card
->options
.sniffer
&& /* HiperSockets trace */
2337 qeth_adp_supported(card
, IPA_SETADP_SET_DIAG_ASSIST
)) {
2338 if (dev
->flags
& IFF_PROMISC
) {
2339 QETH_CARD_TEXT(card
, 3, "+promisc");
2340 qeth_diags_trace(card
, QETH_DIAGS_CMD_TRACE_ENABLE
);
2342 QETH_CARD_TEXT(card
, 3, "-promisc");
2343 qeth_diags_trace(card
, QETH_DIAGS_CMD_TRACE_DISABLE
);
2348 static void qeth_l3_set_multicast_list(struct net_device
*dev
)
2350 struct qeth_card
*card
= dev
->ml_priv
;
2352 QETH_CARD_TEXT(card
, 3, "setmulti");
2353 if (qeth_threads_running(card
, QETH_RECOVER_THREAD
) &&
2354 (card
->state
!= CARD_STATE_UP
))
2356 if (!card
->options
.sniffer
) {
2357 qeth_l3_delete_mc_addresses(card
);
2358 qeth_l3_add_multicast_ipv4(card
);
2359 #ifdef CONFIG_QETH_IPV6
2360 qeth_l3_add_multicast_ipv6(card
);
2362 qeth_l3_set_ip_addr_list(card
);
2363 if (!qeth_adp_supported(card
, IPA_SETADP_SET_PROMISC_MODE
))
2366 qeth_l3_handle_promisc_mode(card
);
2369 static const char *qeth_l3_arp_get_error_cause(int *rc
)
2372 case QETH_IPA_ARP_RC_FAILED
:
2374 return "operation failed";
2375 case QETH_IPA_ARP_RC_NOTSUPP
:
2377 return "operation not supported";
2378 case QETH_IPA_ARP_RC_OUT_OF_RANGE
:
2380 return "argument out of range";
2381 case QETH_IPA_ARP_RC_Q_NOTSUPP
:
2383 return "query operation not supported";
2384 case QETH_IPA_ARP_RC_Q_NO_DATA
:
2386 return "no query data available";
2388 return "unknown error";
2392 static int qeth_l3_arp_set_no_entries(struct qeth_card
*card
, int no_entries
)
2397 QETH_CARD_TEXT(card
, 3, "arpstnoe");
2400 * currently GuestLAN only supports the ARP assist function
2401 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_SET_NO_ENTRIES;
2402 * thus we say EOPNOTSUPP for this ARP function
2404 if (card
->info
.guestlan
)
2406 if (!qeth_is_supported(card
, IPA_ARP_PROCESSING
)) {
2409 rc
= qeth_l3_send_simple_setassparms(card
, IPA_ARP_PROCESSING
,
2410 IPA_CMD_ASS_ARP_SET_NO_ENTRIES
,
2414 QETH_DBF_MESSAGE(2, "Could not set number of ARP entries on "
2415 "%s: %s (0x%x/%d)\n", QETH_CARD_IFNAME(card
),
2416 qeth_l3_arp_get_error_cause(&rc
), tmp
, tmp
);
2421 static __u32
get_arp_entry_size(struct qeth_card
*card
,
2422 struct qeth_arp_query_data
*qdata
,
2423 struct qeth_arp_entrytype
*type
, __u8 strip_entries
)
2428 is_hsi
= qdata
->reply_bits
== 5;
2429 if (type
->ip
== QETHARP_IP_ADDR_V4
) {
2430 QETH_CARD_TEXT(card
, 4, "arpev4");
2431 if (strip_entries
) {
2432 rc
= is_hsi
? sizeof(struct qeth_arp_qi_entry5_short
) :
2433 sizeof(struct qeth_arp_qi_entry7_short
);
2435 rc
= is_hsi
? sizeof(struct qeth_arp_qi_entry5
) :
2436 sizeof(struct qeth_arp_qi_entry7
);
2438 } else if (type
->ip
== QETHARP_IP_ADDR_V6
) {
2439 QETH_CARD_TEXT(card
, 4, "arpev6");
2440 if (strip_entries
) {
2442 sizeof(struct qeth_arp_qi_entry5_short_ipv6
) :
2443 sizeof(struct qeth_arp_qi_entry7_short_ipv6
);
2446 sizeof(struct qeth_arp_qi_entry5_ipv6
) :
2447 sizeof(struct qeth_arp_qi_entry7_ipv6
);
2450 QETH_CARD_TEXT(card
, 4, "arpinv");
2457 static int arpentry_matches_prot(struct qeth_arp_entrytype
*type
, __u16 prot
)
2459 return (type
->ip
== QETHARP_IP_ADDR_V4
&& prot
== QETH_PROT_IPV4
) ||
2460 (type
->ip
== QETHARP_IP_ADDR_V6
&& prot
== QETH_PROT_IPV6
);
2463 static int qeth_l3_arp_query_cb(struct qeth_card
*card
,
2464 struct qeth_reply
*reply
, unsigned long data
)
2466 struct qeth_ipa_cmd
*cmd
;
2467 struct qeth_arp_query_data
*qdata
;
2468 struct qeth_arp_query_info
*qinfo
;
2471 int entrybytes_done
;
2473 __u8 do_strip_entries
;
2475 QETH_CARD_TEXT(card
, 3, "arpquecb");
2477 qinfo
= (struct qeth_arp_query_info
*) reply
->param
;
2478 cmd
= (struct qeth_ipa_cmd
*) data
;
2479 QETH_CARD_TEXT_(card
, 4, "%i", cmd
->hdr
.prot_version
);
2480 if (cmd
->hdr
.return_code
) {
2481 QETH_CARD_TEXT(card
, 4, "arpcberr");
2482 QETH_CARD_TEXT_(card
, 4, "%i", cmd
->hdr
.return_code
);
2485 if (cmd
->data
.setassparms
.hdr
.return_code
) {
2486 cmd
->hdr
.return_code
= cmd
->data
.setassparms
.hdr
.return_code
;
2487 QETH_CARD_TEXT(card
, 4, "setaperr");
2488 QETH_CARD_TEXT_(card
, 4, "%i", cmd
->hdr
.return_code
);
2491 qdata
= &cmd
->data
.setassparms
.data
.query_arp
;
2492 QETH_CARD_TEXT_(card
, 4, "anoen%i", qdata
->no_entries
);
2494 do_strip_entries
= (qinfo
->mask_bits
& QETH_QARP_STRIP_ENTRIES
) > 0;
2495 stripped_bytes
= do_strip_entries
? QETH_QARP_MEDIASPECIFIC_BYTES
: 0;
2496 entrybytes_done
= 0;
2497 for (e
= 0; e
< qdata
->no_entries
; ++e
) {
2500 struct qeth_arp_entrytype
*etype
;
2502 cur_entry
= &qdata
->data
+ entrybytes_done
;
2503 etype
= &((struct qeth_arp_qi_entry5
*) cur_entry
)->type
;
2504 if (!arpentry_matches_prot(etype
, cmd
->hdr
.prot_version
)) {
2505 QETH_CARD_TEXT(card
, 4, "pmis");
2506 QETH_CARD_TEXT_(card
, 4, "%i", etype
->ip
);
2509 esize
= get_arp_entry_size(card
, qdata
, etype
,
2511 QETH_CARD_TEXT_(card
, 5, "esz%i", esize
);
2515 if ((qinfo
->udata_len
- qinfo
->udata_offset
) < esize
) {
2516 QETH_CARD_TEXT_(card
, 4, "qaer3%i", -ENOMEM
);
2517 cmd
->hdr
.return_code
= -ENOMEM
;
2521 memcpy(qinfo
->udata
+ qinfo
->udata_offset
,
2522 &qdata
->data
+ entrybytes_done
+ stripped_bytes
,
2524 entrybytes_done
+= esize
+ stripped_bytes
;
2525 qinfo
->udata_offset
+= esize
;
2526 ++qinfo
->no_entries
;
2528 /* check if all replies received ... */
2529 if (cmd
->data
.setassparms
.hdr
.seq_no
<
2530 cmd
->data
.setassparms
.hdr
.number_of_replies
)
2532 QETH_CARD_TEXT_(card
, 4, "nove%i", qinfo
->no_entries
);
2533 memcpy(qinfo
->udata
, &qinfo
->no_entries
, 4);
2534 /* keep STRIP_ENTRIES flag so the user program can distinguish
2535 * stripped entries from normal ones */
2536 if (qinfo
->mask_bits
& QETH_QARP_STRIP_ENTRIES
)
2537 qdata
->reply_bits
|= QETH_QARP_STRIP_ENTRIES
;
2538 memcpy(qinfo
->udata
+ QETH_QARP_MASK_OFFSET
, &qdata
->reply_bits
, 2);
2539 QETH_CARD_TEXT_(card
, 4, "rc%i", 0);
2543 memcpy(qinfo
->udata
, &i
, 4);
2547 static int qeth_l3_send_ipa_arp_cmd(struct qeth_card
*card
,
2548 struct qeth_cmd_buffer
*iob
, int len
,
2549 int (*reply_cb
)(struct qeth_card
*, struct qeth_reply
*,
2553 QETH_CARD_TEXT(card
, 4, "sendarp");
2555 memcpy(iob
->data
, IPA_PDU_HEADER
, IPA_PDU_HEADER_SIZE
);
2556 memcpy(QETH_IPA_CMD_DEST_ADDR(iob
->data
),
2557 &card
->token
.ulp_connection_r
, QETH_MPC_TOKEN_LENGTH
);
2558 return qeth_send_control_data(card
, IPA_PDU_HEADER_SIZE
+ len
, iob
,
2559 reply_cb
, reply_param
);
2562 static int qeth_l3_query_arp_cache_info(struct qeth_card
*card
,
2563 enum qeth_prot_versions prot
,
2564 struct qeth_arp_query_info
*qinfo
)
2566 struct qeth_cmd_buffer
*iob
;
2567 struct qeth_ipa_cmd
*cmd
;
2571 QETH_CARD_TEXT_(card
, 3, "qarpipv%i", prot
);
2573 iob
= qeth_l3_get_setassparms_cmd(card
, IPA_ARP_PROCESSING
,
2574 IPA_CMD_ASS_ARP_QUERY_INFO
,
2575 sizeof(struct qeth_arp_query_data
) - sizeof(char),
2577 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
2578 cmd
->data
.setassparms
.data
.query_arp
.request_bits
= 0x000F;
2579 cmd
->data
.setassparms
.data
.query_arp
.reply_bits
= 0;
2580 cmd
->data
.setassparms
.data
.query_arp
.no_entries
= 0;
2581 rc
= qeth_l3_send_ipa_arp_cmd(card
, iob
,
2582 QETH_SETASS_BASE_LEN
+QETH_ARP_CMD_LEN
,
2583 qeth_l3_arp_query_cb
, (void *)qinfo
);
2587 "Error while querying ARP cache on %s: %s "
2588 "(0x%x/%d)\n", QETH_CARD_IFNAME(card
),
2589 qeth_l3_arp_get_error_cause(&rc
), tmp
, tmp
);
2595 static int qeth_l3_arp_query(struct qeth_card
*card
, char __user
*udata
)
2597 struct qeth_arp_query_info qinfo
= {0, };
2600 QETH_CARD_TEXT(card
, 3, "arpquery");
2602 if (!qeth_is_supported(card
,/*IPA_QUERY_ARP_ADDR_INFO*/
2603 IPA_ARP_PROCESSING
)) {
2604 QETH_CARD_TEXT(card
, 3, "arpqnsup");
2608 /* get size of userspace buffer and mask_bits -> 6 bytes */
2609 if (copy_from_user(&qinfo
, udata
, 6)) {
2613 qinfo
.udata
= kzalloc(qinfo
.udata_len
, GFP_KERNEL
);
2618 qinfo
.udata_offset
= QETH_QARP_ENTRIES_OFFSET
;
2619 rc
= qeth_l3_query_arp_cache_info(card
, QETH_PROT_IPV4
, &qinfo
);
2621 if (copy_to_user(udata
, qinfo
.udata
, 4))
2625 #ifdef CONFIG_QETH_IPV6
2626 if (qinfo
.mask_bits
& QETH_QARP_WITH_IPV6
) {
2627 /* fails in case of GuestLAN QDIO mode */
2628 qeth_l3_query_arp_cache_info(card
, QETH_PROT_IPV6
,
2632 if (copy_to_user(udata
, qinfo
.udata
, qinfo
.udata_len
)) {
2633 QETH_CARD_TEXT(card
, 4, "qactf");
2637 QETH_CARD_TEXT_(card
, 4, "qacts");
2645 static int qeth_l3_arp_add_entry(struct qeth_card
*card
,
2646 struct qeth_arp_cache_entry
*entry
)
2648 struct qeth_cmd_buffer
*iob
;
2653 QETH_CARD_TEXT(card
, 3, "arpadent");
2656 * currently GuestLAN only supports the ARP assist function
2657 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_ADD_ENTRY;
2658 * thus we say EOPNOTSUPP for this ARP function
2660 if (card
->info
.guestlan
)
2662 if (!qeth_is_supported(card
, IPA_ARP_PROCESSING
)) {
2666 iob
= qeth_l3_get_setassparms_cmd(card
, IPA_ARP_PROCESSING
,
2667 IPA_CMD_ASS_ARP_ADD_ENTRY
,
2668 sizeof(struct qeth_arp_cache_entry
),
2670 rc
= qeth_l3_send_setassparms(card
, iob
,
2671 sizeof(struct qeth_arp_cache_entry
),
2672 (unsigned long) entry
,
2673 qeth_l3_default_setassparms_cb
, NULL
);
2676 qeth_l3_ipaddr4_to_string((u8
*)entry
->ipaddr
, buf
);
2677 QETH_DBF_MESSAGE(2, "Could not add ARP entry for address %s "
2678 "on %s: %s (0x%x/%d)\n", buf
, QETH_CARD_IFNAME(card
),
2679 qeth_l3_arp_get_error_cause(&rc
), tmp
, tmp
);
2684 static int qeth_l3_arp_remove_entry(struct qeth_card
*card
,
2685 struct qeth_arp_cache_entry
*entry
)
2687 struct qeth_cmd_buffer
*iob
;
2688 char buf
[16] = {0, };
2692 QETH_CARD_TEXT(card
, 3, "arprment");
2695 * currently GuestLAN only supports the ARP assist function
2696 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_REMOVE_ENTRY;
2697 * thus we say EOPNOTSUPP for this ARP function
2699 if (card
->info
.guestlan
)
2701 if (!qeth_is_supported(card
, IPA_ARP_PROCESSING
)) {
2704 memcpy(buf
, entry
, 12);
2705 iob
= qeth_l3_get_setassparms_cmd(card
, IPA_ARP_PROCESSING
,
2706 IPA_CMD_ASS_ARP_REMOVE_ENTRY
,
2709 rc
= qeth_l3_send_setassparms(card
, iob
,
2710 12, (unsigned long)buf
,
2711 qeth_l3_default_setassparms_cb
, NULL
);
2715 qeth_l3_ipaddr4_to_string((u8
*)entry
->ipaddr
, buf
);
2716 QETH_DBF_MESSAGE(2, "Could not delete ARP entry for address %s"
2717 " on %s: %s (0x%x/%d)\n", buf
, QETH_CARD_IFNAME(card
),
2718 qeth_l3_arp_get_error_cause(&rc
), tmp
, tmp
);
2723 static int qeth_l3_arp_flush_cache(struct qeth_card
*card
)
2728 QETH_CARD_TEXT(card
, 3, "arpflush");
2731 * currently GuestLAN only supports the ARP assist function
2732 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_FLUSH_CACHE;
2733 * thus we say EOPNOTSUPP for this ARP function
2735 if (card
->info
.guestlan
|| (card
->info
.type
== QETH_CARD_TYPE_IQD
))
2737 if (!qeth_is_supported(card
, IPA_ARP_PROCESSING
)) {
2740 rc
= qeth_l3_send_simple_setassparms(card
, IPA_ARP_PROCESSING
,
2741 IPA_CMD_ASS_ARP_FLUSH_CACHE
, 0);
2744 QETH_DBF_MESSAGE(2, "Could not flush ARP cache on %s: %s "
2745 "(0x%x/%d)\n", QETH_CARD_IFNAME(card
),
2746 qeth_l3_arp_get_error_cause(&rc
), tmp
, tmp
);
2751 static int qeth_l3_do_ioctl(struct net_device
*dev
, struct ifreq
*rq
, int cmd
)
2753 struct qeth_card
*card
= dev
->ml_priv
;
2754 struct qeth_arp_cache_entry arp_entry
;
2755 struct mii_ioctl_data
*mii_data
;
2761 if ((card
->state
!= CARD_STATE_UP
) &&
2762 (card
->state
!= CARD_STATE_SOFTSETUP
))
2766 case SIOC_QETH_ARP_SET_NO_ENTRIES
:
2767 if (!capable(CAP_NET_ADMIN
)) {
2771 rc
= qeth_l3_arp_set_no_entries(card
, rq
->ifr_ifru
.ifru_ivalue
);
2773 case SIOC_QETH_ARP_QUERY_INFO
:
2774 if (!capable(CAP_NET_ADMIN
)) {
2778 rc
= qeth_l3_arp_query(card
, rq
->ifr_ifru
.ifru_data
);
2780 case SIOC_QETH_ARP_ADD_ENTRY
:
2781 if (!capable(CAP_NET_ADMIN
)) {
2785 if (copy_from_user(&arp_entry
, rq
->ifr_ifru
.ifru_data
,
2786 sizeof(struct qeth_arp_cache_entry
)))
2789 rc
= qeth_l3_arp_add_entry(card
, &arp_entry
);
2791 case SIOC_QETH_ARP_REMOVE_ENTRY
:
2792 if (!capable(CAP_NET_ADMIN
)) {
2796 if (copy_from_user(&arp_entry
, rq
->ifr_ifru
.ifru_data
,
2797 sizeof(struct qeth_arp_cache_entry
)))
2800 rc
= qeth_l3_arp_remove_entry(card
, &arp_entry
);
2802 case SIOC_QETH_ARP_FLUSH_CACHE
:
2803 if (!capable(CAP_NET_ADMIN
)) {
2807 rc
= qeth_l3_arp_flush_cache(card
);
2809 case SIOC_QETH_ADP_SET_SNMP_CONTROL
:
2810 rc
= qeth_snmp_command(card
, rq
->ifr_ifru
.ifru_data
);
2812 case SIOC_QETH_GET_CARD_TYPE
:
2813 if ((card
->info
.type
== QETH_CARD_TYPE_OSD
||
2814 card
->info
.type
== QETH_CARD_TYPE_OSX
) &&
2815 !card
->info
.guestlan
)
2820 mii_data
= if_mii(rq
);
2821 mii_data
->phy_id
= 0;
2824 mii_data
= if_mii(rq
);
2825 if (mii_data
->phy_id
!= 0)
2828 mii_data
->val_out
= qeth_mdio_read(dev
,
2836 QETH_CARD_TEXT_(card
, 2, "ioce%d", rc
);
2840 int inline qeth_l3_get_cast_type(struct qeth_card
*card
, struct sk_buff
*skb
)
2842 int cast_type
= RTN_UNSPEC
;
2844 if (skb_dst(skb
) && skb_dst(skb
)->neighbour
) {
2845 cast_type
= skb_dst(skb
)->neighbour
->type
;
2846 if ((cast_type
== RTN_BROADCAST
) ||
2847 (cast_type
== RTN_MULTICAST
) ||
2848 (cast_type
== RTN_ANYCAST
))
2853 /* try something else */
2854 if (skb
->protocol
== ETH_P_IPV6
)
2855 return (skb_network_header(skb
)[24] == 0xff) ?
2857 else if (skb
->protocol
== ETH_P_IP
)
2858 return ((skb_network_header(skb
)[16] & 0xf0) == 0xe0) ?
2861 if (!memcmp(skb
->data
, skb
->dev
->broadcast
, 6))
2862 return RTN_BROADCAST
;
2866 hdr_mac
= *((u16
*)skb
->data
);
2868 switch (card
->info
.link_type
) {
2869 case QETH_LINK_TYPE_HSTR
:
2870 case QETH_LINK_TYPE_LANE_TR
:
2871 if ((hdr_mac
== QETH_TR_MAC_NC
) ||
2872 (hdr_mac
== QETH_TR_MAC_C
))
2873 return RTN_MULTICAST
;
2875 /* eth or so multicast? */
2877 if ((hdr_mac
== QETH_ETH_MAC_V4
) ||
2878 (hdr_mac
== QETH_ETH_MAC_V6
))
2879 return RTN_MULTICAST
;
2885 static void qeth_l3_fill_header(struct qeth_card
*card
, struct qeth_hdr
*hdr
,
2886 struct sk_buff
*skb
, int ipv
, int cast_type
)
2888 memset(hdr
, 0, sizeof(struct qeth_hdr
));
2889 hdr
->hdr
.l3
.id
= QETH_HEADER_TYPE_LAYER3
;
2890 hdr
->hdr
.l3
.ext_flags
= 0;
2893 * before we're going to overwrite this location with next hop ip.
2894 * v6 uses passthrough, v4 sets the tag in the QDIO header.
2896 if (card
->vlangrp
&& vlan_tx_tag_present(skb
)) {
2897 if ((ipv
== 4) || (card
->info
.type
== QETH_CARD_TYPE_IQD
))
2898 hdr
->hdr
.l3
.ext_flags
= QETH_HDR_EXT_VLAN_FRAME
;
2900 hdr
->hdr
.l3
.ext_flags
= QETH_HDR_EXT_INCLUDE_VLAN_TAG
;
2901 hdr
->hdr
.l3
.vlan_id
= vlan_tx_tag_get(skb
);
2904 hdr
->hdr
.l3
.length
= skb
->len
- sizeof(struct qeth_hdr
);
2907 hdr
->hdr
.l3
.flags
= qeth_l3_get_qeth_hdr_flags4(cast_type
);
2908 memset(hdr
->hdr
.l3
.dest_addr
, 0, 12);
2909 if ((skb_dst(skb
)) && (skb_dst(skb
)->neighbour
)) {
2910 *((u32
*) (&hdr
->hdr
.l3
.dest_addr
[12])) =
2911 *((u32
*) skb_dst(skb
)->neighbour
->primary_key
);
2913 /* fill in destination address used in ip header */
2914 *((u32
*) (&hdr
->hdr
.l3
.dest_addr
[12])) =
2917 } else if (ipv
== 6) {
2919 hdr
->hdr
.l3
.flags
= qeth_l3_get_qeth_hdr_flags6(cast_type
);
2920 if (card
->info
.type
== QETH_CARD_TYPE_IQD
)
2921 hdr
->hdr
.l3
.flags
&= ~QETH_HDR_PASSTHRU
;
2922 if ((skb_dst(skb
)) && (skb_dst(skb
)->neighbour
)) {
2923 memcpy(hdr
->hdr
.l3
.dest_addr
,
2924 skb_dst(skb
)->neighbour
->primary_key
, 16);
2926 /* fill in destination address used in ip header */
2927 memcpy(hdr
->hdr
.l3
.dest_addr
,
2928 &ipv6_hdr(skb
)->daddr
, 16);
2932 if ((skb
->dev
->type
== ARPHRD_IEEE802_TR
) &&
2933 !memcmp(skb
->data
+ sizeof(struct qeth_hdr
) +
2934 sizeof(__u16
), skb
->dev
->broadcast
, 6)) {
2935 hdr
->hdr
.l3
.flags
= QETH_CAST_BROADCAST
|
2937 } else if (!memcmp(skb
->data
+ sizeof(struct qeth_hdr
),
2938 skb
->dev
->broadcast
, 6)) {
2940 hdr
->hdr
.l3
.flags
= QETH_CAST_BROADCAST
|
2943 hdr
->hdr
.l3
.flags
= (cast_type
== RTN_MULTICAST
) ?
2944 QETH_CAST_MULTICAST
| QETH_HDR_PASSTHRU
:
2945 QETH_CAST_UNICAST
| QETH_HDR_PASSTHRU
;
2950 static inline void qeth_l3_hdr_csum(struct qeth_card
*card
,
2951 struct qeth_hdr
*hdr
, struct sk_buff
*skb
)
2953 struct iphdr
*iph
= ip_hdr(skb
);
2955 /* tcph->check contains already the pseudo hdr checksum
2956 * so just set the header flags
2958 if (iph
->protocol
== IPPROTO_UDP
)
2959 hdr
->hdr
.l3
.ext_flags
|= QETH_HDR_EXT_UDP
;
2960 hdr
->hdr
.l3
.ext_flags
|= QETH_HDR_EXT_CSUM_TRANSP_REQ
|
2961 QETH_HDR_EXT_CSUM_HDR_REQ
;
2963 if (card
->options
.performance_stats
)
2964 card
->perf_stats
.tx_csum
++;
2967 static void qeth_tso_fill_header(struct qeth_card
*card
,
2968 struct qeth_hdr
*qhdr
, struct sk_buff
*skb
)
2970 struct qeth_hdr_tso
*hdr
= (struct qeth_hdr_tso
*)qhdr
;
2971 struct tcphdr
*tcph
= tcp_hdr(skb
);
2972 struct iphdr
*iph
= ip_hdr(skb
);
2973 struct ipv6hdr
*ip6h
= ipv6_hdr(skb
);
2975 /*fix header to TSO values ...*/
2976 hdr
->hdr
.hdr
.l3
.id
= QETH_HEADER_TYPE_TSO
;
2977 hdr
->hdr
.hdr
.l3
.length
= skb
->len
- sizeof(struct qeth_hdr_tso
);
2978 /*set values which are fix for the first approach ...*/
2979 hdr
->ext
.hdr_tot_len
= (__u16
) sizeof(struct qeth_hdr_ext_tso
);
2980 hdr
->ext
.imb_hdr_no
= 1;
2981 hdr
->ext
.hdr_type
= 1;
2982 hdr
->ext
.hdr_version
= 1;
2983 hdr
->ext
.hdr_len
= 28;
2984 /*insert non-fix values */
2985 hdr
->ext
.mss
= skb_shinfo(skb
)->gso_size
;
2986 hdr
->ext
.dg_hdr_len
= (__u16
)(iph
->ihl
*4 + tcph
->doff
*4);
2987 hdr
->ext
.payload_len
= (__u16
)(skb
->len
- hdr
->ext
.dg_hdr_len
-
2988 sizeof(struct qeth_hdr_tso
));
2990 if (skb
->protocol
== ETH_P_IPV6
) {
2991 ip6h
->payload_len
= 0;
2992 tcph
->check
= ~csum_ipv6_magic(&ip6h
->saddr
, &ip6h
->daddr
,
2995 /*OSA want us to set these values ...*/
2996 tcph
->check
= ~csum_tcpudp_magic(iph
->saddr
, iph
->daddr
,
3003 static inline int qeth_l3_tso_elements(struct sk_buff
*skb
)
3005 unsigned long tcpd
= (unsigned long)tcp_hdr(skb
) +
3006 tcp_hdr(skb
)->doff
* 4;
3007 int tcpd_len
= skb
->len
- (tcpd
- (unsigned long)skb
->data
);
3008 int elements
= PFN_UP(tcpd
+ tcpd_len
- 1) - PFN_DOWN(tcpd
);
3009 elements
+= skb_shinfo(skb
)->nr_frags
;
3013 static int qeth_l3_hard_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
3017 struct qeth_hdr
*hdr
= NULL
;
3018 int elements_needed
= 0;
3020 struct qeth_card
*card
= dev
->ml_priv
;
3021 struct sk_buff
*new_skb
= NULL
;
3022 int ipv
= qeth_get_ip_version(skb
);
3023 int cast_type
= qeth_l3_get_cast_type(card
, skb
);
3024 struct qeth_qdio_out_q
*queue
= card
->qdio
.out_qs
3025 [qeth_get_priority_queue(card
, skb
, ipv
, cast_type
)];
3026 int tx_bytes
= skb
->len
;
3027 enum qeth_large_send_types large_send
= QETH_LARGE_SEND_NO
;
3028 int data_offset
= -1;
3031 if (((card
->info
.type
== QETH_CARD_TYPE_IQD
) && (!ipv
)) ||
3032 card
->options
.sniffer
)
3035 if ((card
->state
!= CARD_STATE_UP
) || !card
->lan_online
) {
3036 card
->stats
.tx_carrier_errors
++;
3040 if ((cast_type
== RTN_BROADCAST
) &&
3041 (card
->info
.broadcast_capable
== 0))
3044 if (card
->options
.performance_stats
) {
3045 card
->perf_stats
.outbound_cnt
++;
3046 card
->perf_stats
.outbound_start_time
= qeth_get_micros();
3049 if (skb_is_gso(skb
))
3050 large_send
= card
->options
.large_send
;
3052 if ((card
->info
.type
== QETH_CARD_TYPE_IQD
) && (!large_send
) &&
3053 (skb_shinfo(skb
)->nr_frags
== 0)) {
3055 data_offset
= ETH_HLEN
;
3056 hdr
= kmem_cache_alloc(qeth_core_header_cache
, GFP_ATOMIC
);
3061 /* create a clone with writeable headroom */
3062 new_skb
= skb_realloc_headroom(skb
, sizeof(struct qeth_hdr_tso
)
3068 if (card
->info
.type
== QETH_CARD_TYPE_IQD
) {
3069 if (data_offset
< 0)
3070 skb_pull(new_skb
, ETH_HLEN
);
3073 if (card
->dev
->type
== ARPHRD_IEEE802_TR
)
3074 skb_pull(new_skb
, TR_HLEN
);
3076 skb_pull(new_skb
, ETH_HLEN
);
3079 if (ipv
!= 4 && card
->vlangrp
&&
3080 vlan_tx_tag_present(new_skb
)) {
3081 skb_push(new_skb
, VLAN_HLEN
);
3082 skb_copy_to_linear_data(new_skb
, new_skb
->data
+ 4, 4);
3083 skb_copy_to_linear_data_offset(new_skb
, 4,
3084 new_skb
->data
+ 8, 4);
3085 skb_copy_to_linear_data_offset(new_skb
, 8,
3086 new_skb
->data
+ 12, 4);
3087 tag
= (u16
*)(new_skb
->data
+ 12);
3088 *tag
= __constant_htons(ETH_P_8021Q
);
3089 *(tag
+ 1) = htons(vlan_tx_tag_get(new_skb
));
3090 new_skb
->vlan_tci
= 0;
3094 netif_stop_queue(dev
);
3096 /* fix hardware limitation: as long as we do not have sbal
3097 * chaining we can not send long frag lists
3099 if (large_send
== QETH_LARGE_SEND_TSO
) {
3100 if (qeth_l3_tso_elements(new_skb
) + 1 > 16) {
3101 if (skb_linearize(new_skb
))
3103 if (card
->options
.performance_stats
)
3104 card
->perf_stats
.tx_lin
++;
3108 if ((large_send
== QETH_LARGE_SEND_TSO
) &&
3109 (cast_type
== RTN_UNSPEC
)) {
3110 hdr
= (struct qeth_hdr
*)skb_push(new_skb
,
3111 sizeof(struct qeth_hdr_tso
));
3112 memset(hdr
, 0, sizeof(struct qeth_hdr_tso
));
3113 qeth_l3_fill_header(card
, hdr
, new_skb
, ipv
, cast_type
);
3114 qeth_tso_fill_header(card
, hdr
, new_skb
);
3117 if (data_offset
< 0) {
3118 hdr
= (struct qeth_hdr
*)skb_push(new_skb
,
3119 sizeof(struct qeth_hdr
));
3120 qeth_l3_fill_header(card
, hdr
, new_skb
, ipv
,
3123 qeth_l3_fill_header(card
, hdr
, new_skb
, ipv
,
3125 hdr
->hdr
.l3
.length
= new_skb
->len
- data_offset
;
3128 if (skb
->ip_summed
== CHECKSUM_PARTIAL
)
3129 qeth_l3_hdr_csum(card
, hdr
, new_skb
);
3132 elems
= qeth_get_elements_no(card
, (void *)hdr
, new_skb
,
3135 if (data_offset
>= 0)
3136 kmem_cache_free(qeth_core_header_cache
, hdr
);
3139 elements_needed
+= elems
;
3140 nr_frags
= skb_shinfo(new_skb
)->nr_frags
;
3142 if (card
->info
.type
!= QETH_CARD_TYPE_IQD
) {
3144 if (large_send
== QETH_LARGE_SEND_TSO
)
3145 len
= ((unsigned long)tcp_hdr(new_skb
) +
3146 tcp_hdr(new_skb
)->doff
* 4) -
3147 (unsigned long)new_skb
->data
;
3149 len
= sizeof(struct qeth_hdr_layer3
);
3151 if (qeth_hdr_chk_and_bounce(new_skb
, len
))
3153 rc
= qeth_do_send_packet(card
, queue
, new_skb
, hdr
,
3156 rc
= qeth_do_send_packet_fast(card
, queue
, new_skb
, hdr
,
3157 elements_needed
, data_offset
, 0);
3160 card
->stats
.tx_packets
++;
3161 card
->stats
.tx_bytes
+= tx_bytes
;
3163 dev_kfree_skb_any(skb
);
3164 if (card
->options
.performance_stats
) {
3165 if (large_send
!= QETH_LARGE_SEND_NO
) {
3166 card
->perf_stats
.large_send_bytes
+= tx_bytes
;
3167 card
->perf_stats
.large_send_cnt
++;
3170 card
->perf_stats
.sg_skbs_sent
++;
3171 /* nr_frags + skb->data */
3172 card
->perf_stats
.sg_frags_sent
+= nr_frags
+ 1;
3177 if (data_offset
>= 0)
3178 kmem_cache_free(qeth_core_header_cache
, hdr
);
3182 dev_kfree_skb_any(new_skb
);
3183 return NETDEV_TX_BUSY
;
3188 netif_wake_queue(dev
);
3189 if (card
->options
.performance_stats
)
3190 card
->perf_stats
.outbound_time
+= qeth_get_micros() -
3191 card
->perf_stats
.outbound_start_time
;
3195 card
->stats
.tx_dropped
++;
3196 card
->stats
.tx_errors
++;
3197 if ((new_skb
!= skb
) && new_skb
)
3198 dev_kfree_skb_any(new_skb
);
3199 dev_kfree_skb_any(skb
);
3200 netif_wake_queue(dev
);
3201 return NETDEV_TX_OK
;
3204 static int __qeth_l3_open(struct net_device
*dev
)
3206 struct qeth_card
*card
= dev
->ml_priv
;
3209 QETH_CARD_TEXT(card
, 4, "qethopen");
3210 if (card
->state
== CARD_STATE_UP
)
3212 if (card
->state
!= CARD_STATE_SOFTSETUP
)
3214 card
->data
.state
= CH_STATE_UP
;
3215 card
->state
= CARD_STATE_UP
;
3216 netif_start_queue(dev
);
3218 if (qdio_stop_irq(card
->data
.ccwdev
, 0) >= 0) {
3219 napi_enable(&card
->napi
);
3220 napi_schedule(&card
->napi
);
3226 static int qeth_l3_open(struct net_device
*dev
)
3228 struct qeth_card
*card
= dev
->ml_priv
;
3230 QETH_CARD_TEXT(card
, 5, "qethope_");
3231 if (qeth_wait_for_threads(card
, QETH_RECOVER_THREAD
)) {
3232 QETH_CARD_TEXT(card
, 3, "openREC");
3233 return -ERESTARTSYS
;
3235 return __qeth_l3_open(dev
);
3238 static int qeth_l3_stop(struct net_device
*dev
)
3240 struct qeth_card
*card
= dev
->ml_priv
;
3242 QETH_CARD_TEXT(card
, 4, "qethstop");
3243 netif_tx_disable(dev
);
3244 if (card
->state
== CARD_STATE_UP
) {
3245 card
->state
= CARD_STATE_SOFTSETUP
;
3246 napi_disable(&card
->napi
);
3251 static u32
qeth_l3_ethtool_get_rx_csum(struct net_device
*dev
)
3253 struct qeth_card
*card
= dev
->ml_priv
;
3255 return (card
->options
.checksum_type
== HW_CHECKSUMMING
);
3258 static int qeth_l3_ethtool_set_rx_csum(struct net_device
*dev
, u32 data
)
3260 struct qeth_card
*card
= dev
->ml_priv
;
3261 enum qeth_checksum_types csum_type
;
3264 csum_type
= HW_CHECKSUMMING
;
3266 csum_type
= SW_CHECKSUMMING
;
3268 return qeth_l3_set_rx_csum(card
, csum_type
);
3271 static int qeth_l3_ethtool_set_tso(struct net_device
*dev
, u32 data
)
3273 struct qeth_card
*card
= dev
->ml_priv
;
3277 rc
= qeth_l3_set_large_send(card
, QETH_LARGE_SEND_TSO
);
3279 dev
->features
&= ~NETIF_F_TSO
;
3280 card
->options
.large_send
= QETH_LARGE_SEND_NO
;
3285 static int qeth_l3_ethtool_set_tx_csum(struct net_device
*dev
, u32 data
)
3287 struct qeth_card
*card
= dev
->ml_priv
;
3290 if (qeth_is_supported(card
, IPA_OUTBOUND_CHECKSUM
))
3291 dev
->features
|= NETIF_F_IP_CSUM
;
3295 dev
->features
&= ~NETIF_F_IP_CSUM
;
3300 static const struct ethtool_ops qeth_l3_ethtool_ops
= {
3301 .get_link
= ethtool_op_get_link
,
3302 .get_tx_csum
= ethtool_op_get_tx_csum
,
3303 .set_tx_csum
= qeth_l3_ethtool_set_tx_csum
,
3304 .get_rx_csum
= qeth_l3_ethtool_get_rx_csum
,
3305 .set_rx_csum
= qeth_l3_ethtool_set_rx_csum
,
3306 .get_sg
= ethtool_op_get_sg
,
3307 .set_sg
= ethtool_op_set_sg
,
3308 .get_tso
= ethtool_op_get_tso
,
3309 .set_tso
= qeth_l3_ethtool_set_tso
,
3310 .get_strings
= qeth_core_get_strings
,
3311 .get_ethtool_stats
= qeth_core_get_ethtool_stats
,
3312 .get_sset_count
= qeth_core_get_sset_count
,
3313 .get_drvinfo
= qeth_core_get_drvinfo
,
3314 .get_settings
= qeth_core_ethtool_get_settings
,
3318 * we need NOARP for IPv4 but we want neighbor solicitation for IPv6. Setting
3319 * NOARP on the netdevice is no option because it also turns off neighbor
3320 * solicitation. For IPv4 we install a neighbor_setup function. We don't want
3321 * arp resolution but we want the hard header (packet socket will work
3324 static int qeth_l3_neigh_setup_noarp(struct neighbour
*n
)
3326 n
->nud_state
= NUD_NOARP
;
3327 memcpy(n
->ha
, "FAKELL", 6);
3328 n
->output
= n
->ops
->connected_output
;
3333 qeth_l3_neigh_setup(struct net_device
*dev
, struct neigh_parms
*np
)
3335 if (np
->tbl
->family
== AF_INET
)
3336 np
->neigh_setup
= qeth_l3_neigh_setup_noarp
;
3341 static const struct net_device_ops qeth_l3_netdev_ops
= {
3342 .ndo_open
= qeth_l3_open
,
3343 .ndo_stop
= qeth_l3_stop
,
3344 .ndo_get_stats
= qeth_get_stats
,
3345 .ndo_start_xmit
= qeth_l3_hard_start_xmit
,
3346 .ndo_validate_addr
= eth_validate_addr
,
3347 .ndo_set_multicast_list
= qeth_l3_set_multicast_list
,
3348 .ndo_do_ioctl
= qeth_l3_do_ioctl
,
3349 .ndo_change_mtu
= qeth_change_mtu
,
3350 .ndo_vlan_rx_register
= qeth_l3_vlan_rx_register
,
3351 .ndo_vlan_rx_add_vid
= qeth_l3_vlan_rx_add_vid
,
3352 .ndo_vlan_rx_kill_vid
= qeth_l3_vlan_rx_kill_vid
,
3353 .ndo_tx_timeout
= qeth_tx_timeout
,
3356 static const struct net_device_ops qeth_l3_osa_netdev_ops
= {
3357 .ndo_open
= qeth_l3_open
,
3358 .ndo_stop
= qeth_l3_stop
,
3359 .ndo_get_stats
= qeth_get_stats
,
3360 .ndo_start_xmit
= qeth_l3_hard_start_xmit
,
3361 .ndo_validate_addr
= eth_validate_addr
,
3362 .ndo_set_multicast_list
= qeth_l3_set_multicast_list
,
3363 .ndo_do_ioctl
= qeth_l3_do_ioctl
,
3364 .ndo_change_mtu
= qeth_change_mtu
,
3365 .ndo_vlan_rx_register
= qeth_l3_vlan_rx_register
,
3366 .ndo_vlan_rx_add_vid
= qeth_l3_vlan_rx_add_vid
,
3367 .ndo_vlan_rx_kill_vid
= qeth_l3_vlan_rx_kill_vid
,
3368 .ndo_tx_timeout
= qeth_tx_timeout
,
3369 .ndo_neigh_setup
= qeth_l3_neigh_setup
,
3372 static int qeth_l3_setup_netdev(struct qeth_card
*card
)
3374 if (card
->info
.type
== QETH_CARD_TYPE_OSD
||
3375 card
->info
.type
== QETH_CARD_TYPE_OSX
) {
3376 if ((card
->info
.link_type
== QETH_LINK_TYPE_LANE_TR
) ||
3377 (card
->info
.link_type
== QETH_LINK_TYPE_HSTR
)) {
3379 card
->dev
= alloc_trdev(0);
3383 card
->dev
->netdev_ops
= &qeth_l3_netdev_ops
;
3385 card
->dev
= alloc_etherdev(0);
3388 card
->dev
->netdev_ops
= &qeth_l3_osa_netdev_ops
;
3390 /*IPv6 address autoconfiguration stuff*/
3391 qeth_l3_get_unique_id(card
);
3392 if (!(card
->info
.unique_id
& UNIQUE_ID_NOT_BY_CARD
))
3393 card
->dev
->dev_id
= card
->info
.unique_id
&
3395 if (!card
->info
.guestlan
)
3396 card
->dev
->features
|= NETIF_F_GRO
;
3398 } else if (card
->info
.type
== QETH_CARD_TYPE_IQD
) {
3399 card
->dev
= alloc_netdev(0, "hsi%d", ether_setup
);
3402 card
->dev
->flags
|= IFF_NOARP
;
3403 card
->dev
->netdev_ops
= &qeth_l3_netdev_ops
;
3404 qeth_l3_iqd_read_initial_mac(card
);
3408 card
->dev
->ml_priv
= card
;
3409 card
->dev
->watchdog_timeo
= QETH_TX_TIMEOUT
;
3410 card
->dev
->mtu
= card
->info
.initial_mtu
;
3411 SET_ETHTOOL_OPS(card
->dev
, &qeth_l3_ethtool_ops
);
3412 card
->dev
->features
|= NETIF_F_HW_VLAN_TX
|
3413 NETIF_F_HW_VLAN_RX
|
3414 NETIF_F_HW_VLAN_FILTER
;
3415 card
->dev
->priv_flags
&= ~IFF_XMIT_DST_RELEASE
;
3416 card
->dev
->gso_max_size
= 15 * PAGE_SIZE
;
3418 SET_NETDEV_DEV(card
->dev
, &card
->gdev
->dev
);
3419 netif_napi_add(card
->dev
, &card
->napi
, qeth_l3_poll
, QETH_NAPI_WEIGHT
);
3420 return register_netdev(card
->dev
);
3423 static int qeth_l3_probe_device(struct ccwgroup_device
*gdev
)
3425 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
3427 qeth_l3_create_device_attributes(&gdev
->dev
);
3428 card
->options
.layer2
= 0;
3429 card
->discipline
.start_poll
= qeth_qdio_start_poll
;
3430 card
->discipline
.input_handler
= (qdio_handler_t
*)
3431 qeth_qdio_input_handler
;
3432 card
->discipline
.output_handler
= (qdio_handler_t
*)
3433 qeth_qdio_output_handler
;
3434 card
->discipline
.recover
= qeth_l3_recover
;
3435 if ((card
->info
.type
== QETH_CARD_TYPE_OSD
) ||
3436 (card
->info
.type
== QETH_CARD_TYPE_OSX
))
3437 card
->options
.checksum_type
= HW_CHECKSUMMING
;
3441 static void qeth_l3_remove_device(struct ccwgroup_device
*cgdev
)
3443 struct qeth_card
*card
= dev_get_drvdata(&cgdev
->dev
);
3445 qeth_l3_remove_device_attributes(&cgdev
->dev
);
3447 qeth_set_allowed_threads(card
, 0, 1);
3448 wait_event(card
->wait_q
, qeth_threads_running(card
, 0xffffffff) == 0);
3450 if (cgdev
->state
== CCWGROUP_ONLINE
)
3451 qeth_l3_set_offline(cgdev
);
3454 unregister_netdev(card
->dev
);
3458 qeth_l3_clear_ip_list(card
, 0);
3459 qeth_l3_clear_ipato_list(card
);
3463 static int __qeth_l3_set_online(struct ccwgroup_device
*gdev
, int recovery_mode
)
3465 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
3467 enum qeth_card_states recover_flag
;
3470 mutex_lock(&card
->discipline_mutex
);
3471 mutex_lock(&card
->conf_mutex
);
3472 QETH_DBF_TEXT(SETUP
, 2, "setonlin");
3473 QETH_DBF_HEX(SETUP
, 2, &card
, sizeof(void *));
3475 recover_flag
= card
->state
;
3476 rc
= qeth_core_hardsetup_card(card
);
3478 QETH_DBF_TEXT_(SETUP
, 2, "2err%d", rc
);
3483 qeth_l3_query_ipassists(card
, QETH_PROT_IPV4
);
3485 if (!card
->dev
&& qeth_l3_setup_netdev(card
)) {
3490 card
->state
= CARD_STATE_HARDSETUP
;
3491 memset(&card
->rx
, 0, sizeof(struct qeth_rx
));
3492 qeth_print_status_message(card
);
3495 QETH_DBF_TEXT(SETUP
, 2, "softsetp");
3497 rc
= qeth_send_startlan(card
);
3499 QETH_DBF_TEXT_(SETUP
, 2, "1err%d", rc
);
3501 dev_warn(&card
->gdev
->dev
,
3502 "The LAN is offline\n");
3503 card
->lan_online
= 0;
3509 card
->lan_online
= 1;
3512 rc
= qeth_l3_setadapter_parms(card
);
3514 QETH_DBF_TEXT_(SETUP
, 2, "2err%d", rc
);
3515 if (!card
->options
.sniffer
) {
3516 rc
= qeth_l3_start_ipassists(card
);
3518 QETH_DBF_TEXT_(SETUP
, 2, "3err%d", rc
);
3519 qeth_l3_set_large_send(card
, card
->options
.large_send
);
3520 rc
= qeth_l3_setrouting_v4(card
);
3522 QETH_DBF_TEXT_(SETUP
, 2, "4err%d", rc
);
3523 rc
= qeth_l3_setrouting_v6(card
);
3525 QETH_DBF_TEXT_(SETUP
, 2, "5err%d", rc
);
3527 netif_tx_disable(card
->dev
);
3529 rc
= qeth_init_qdio_queues(card
);
3531 QETH_DBF_TEXT_(SETUP
, 2, "6err%d", rc
);
3535 card
->state
= CARD_STATE_SOFTSETUP
;
3537 qeth_set_allowed_threads(card
, 0xffffffff, 0);
3538 qeth_l3_set_ip_addr_list(card
);
3539 if (card
->lan_online
)
3540 netif_carrier_on(card
->dev
);
3542 netif_carrier_off(card
->dev
);
3543 if (recover_flag
== CARD_STATE_RECOVER
) {
3545 __qeth_l3_open(card
->dev
);
3548 dev_open(card
->dev
);
3551 qeth_l3_set_multicast_list(card
->dev
);
3553 /* let user_space know that device is online */
3554 kobject_uevent(&gdev
->dev
.kobj
, KOBJ_CHANGE
);
3555 mutex_unlock(&card
->conf_mutex
);
3556 mutex_unlock(&card
->discipline_mutex
);
3559 qeth_l3_stop_card(card
, 0);
3560 ccw_device_set_offline(CARD_DDEV(card
));
3561 ccw_device_set_offline(CARD_WDEV(card
));
3562 ccw_device_set_offline(CARD_RDEV(card
));
3563 if (recover_flag
== CARD_STATE_RECOVER
)
3564 card
->state
= CARD_STATE_RECOVER
;
3566 card
->state
= CARD_STATE_DOWN
;
3567 mutex_unlock(&card
->conf_mutex
);
3568 mutex_unlock(&card
->discipline_mutex
);
3572 static int qeth_l3_set_online(struct ccwgroup_device
*gdev
)
3574 return __qeth_l3_set_online(gdev
, 0);
3577 static int __qeth_l3_set_offline(struct ccwgroup_device
*cgdev
,
3580 struct qeth_card
*card
= dev_get_drvdata(&cgdev
->dev
);
3581 int rc
= 0, rc2
= 0, rc3
= 0;
3582 enum qeth_card_states recover_flag
;
3584 mutex_lock(&card
->discipline_mutex
);
3585 mutex_lock(&card
->conf_mutex
);
3586 QETH_DBF_TEXT(SETUP
, 3, "setoffl");
3587 QETH_DBF_HEX(SETUP
, 3, &card
, sizeof(void *));
3589 if (card
->dev
&& netif_carrier_ok(card
->dev
))
3590 netif_carrier_off(card
->dev
);
3591 recover_flag
= card
->state
;
3592 qeth_l3_stop_card(card
, recovery_mode
);
3593 rc
= ccw_device_set_offline(CARD_DDEV(card
));
3594 rc2
= ccw_device_set_offline(CARD_WDEV(card
));
3595 rc3
= ccw_device_set_offline(CARD_RDEV(card
));
3597 rc
= (rc2
) ? rc2
: rc3
;
3599 QETH_DBF_TEXT_(SETUP
, 2, "1err%d", rc
);
3600 if (recover_flag
== CARD_STATE_UP
)
3601 card
->state
= CARD_STATE_RECOVER
;
3602 /* let user_space know that device is offline */
3603 kobject_uevent(&cgdev
->dev
.kobj
, KOBJ_CHANGE
);
3604 mutex_unlock(&card
->conf_mutex
);
3605 mutex_unlock(&card
->discipline_mutex
);
3609 static int qeth_l3_set_offline(struct ccwgroup_device
*cgdev
)
3611 return __qeth_l3_set_offline(cgdev
, 0);
3614 static int qeth_l3_recover(void *ptr
)
3616 struct qeth_card
*card
;
3619 card
= (struct qeth_card
*) ptr
;
3620 QETH_CARD_TEXT(card
, 2, "recover1");
3621 QETH_CARD_HEX(card
, 2, &card
, sizeof(void *));
3622 if (!qeth_do_run_thread(card
, QETH_RECOVER_THREAD
))
3624 QETH_CARD_TEXT(card
, 2, "recover2");
3625 dev_warn(&card
->gdev
->dev
,
3626 "A recovery process has been started for the device\n");
3627 __qeth_l3_set_offline(card
->gdev
, 1);
3628 rc
= __qeth_l3_set_online(card
->gdev
, 1);
3630 dev_info(&card
->gdev
->dev
,
3631 "Device successfully recovered!\n");
3634 dev_close(card
->dev
);
3636 dev_warn(&card
->gdev
->dev
, "The qeth device driver "
3637 "failed to recover an error on the device\n");
3639 qeth_clear_thread_start_bit(card
, QETH_RECOVER_THREAD
);
3640 qeth_clear_thread_running_bit(card
, QETH_RECOVER_THREAD
);
3644 static void qeth_l3_shutdown(struct ccwgroup_device
*gdev
)
3646 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
3647 qeth_qdio_clear_card(card
, 0);
3648 qeth_clear_qdio_buffers(card
);
3651 static int qeth_l3_pm_suspend(struct ccwgroup_device
*gdev
)
3653 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
3656 netif_device_detach(card
->dev
);
3657 qeth_set_allowed_threads(card
, 0, 1);
3658 wait_event(card
->wait_q
, qeth_threads_running(card
, 0xffffffff) == 0);
3659 if (gdev
->state
== CCWGROUP_OFFLINE
)
3661 if (card
->state
== CARD_STATE_UP
) {
3662 __qeth_l3_set_offline(card
->gdev
, 1);
3664 __qeth_l3_set_offline(card
->gdev
, 0);
3668 static int qeth_l3_pm_resume(struct ccwgroup_device
*gdev
)
3670 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
3673 if (gdev
->state
== CCWGROUP_OFFLINE
)
3676 if (card
->state
== CARD_STATE_RECOVER
) {
3677 rc
= __qeth_l3_set_online(card
->gdev
, 1);
3680 dev_close(card
->dev
);
3684 rc
= __qeth_l3_set_online(card
->gdev
, 0);
3686 qeth_set_allowed_threads(card
, 0xffffffff, 0);
3688 netif_device_attach(card
->dev
);
3690 dev_warn(&card
->gdev
->dev
, "The qeth device driver "
3691 "failed to recover an error on the device\n");
3695 struct ccwgroup_driver qeth_l3_ccwgroup_driver
= {
3696 .probe
= qeth_l3_probe_device
,
3697 .remove
= qeth_l3_remove_device
,
3698 .set_online
= qeth_l3_set_online
,
3699 .set_offline
= qeth_l3_set_offline
,
3700 .shutdown
= qeth_l3_shutdown
,
3701 .freeze
= qeth_l3_pm_suspend
,
3702 .thaw
= qeth_l3_pm_resume
,
3703 .restore
= qeth_l3_pm_resume
,
3705 EXPORT_SYMBOL_GPL(qeth_l3_ccwgroup_driver
);
3707 static int qeth_l3_ip_event(struct notifier_block
*this,
3708 unsigned long event
, void *ptr
)
3710 struct in_ifaddr
*ifa
= (struct in_ifaddr
*)ptr
;
3711 struct net_device
*dev
= (struct net_device
*)ifa
->ifa_dev
->dev
;
3712 struct qeth_ipaddr
*addr
;
3713 struct qeth_card
*card
;
3715 if (dev_net(dev
) != &init_net
)
3718 card
= qeth_l3_get_card_from_dev(dev
);
3719 QETH_CARD_TEXT(card
, 3, "ipevent");
3723 addr
= qeth_l3_get_addr_buffer(QETH_PROT_IPV4
);
3725 addr
->u
.a4
.addr
= ifa
->ifa_address
;
3726 addr
->u
.a4
.mask
= ifa
->ifa_mask
;
3727 addr
->type
= QETH_IP_TYPE_NORMAL
;
3733 if (!qeth_l3_add_ip(card
, addr
))
3737 if (!qeth_l3_delete_ip(card
, addr
))
3743 qeth_l3_set_ip_addr_list(card
);
3748 static struct notifier_block qeth_l3_ip_notifier
= {
3753 #ifdef CONFIG_QETH_IPV6
3755 * IPv6 event handler
3757 static int qeth_l3_ip6_event(struct notifier_block
*this,
3758 unsigned long event
, void *ptr
)
3760 struct inet6_ifaddr
*ifa
= (struct inet6_ifaddr
*)ptr
;
3761 struct net_device
*dev
= (struct net_device
*)ifa
->idev
->dev
;
3762 struct qeth_ipaddr
*addr
;
3763 struct qeth_card
*card
;
3766 card
= qeth_l3_get_card_from_dev(dev
);
3769 QETH_CARD_TEXT(card
, 3, "ip6event");
3770 if (!qeth_is_supported(card
, IPA_IPV6
))
3773 addr
= qeth_l3_get_addr_buffer(QETH_PROT_IPV6
);
3775 memcpy(&addr
->u
.a6
.addr
, &ifa
->addr
, sizeof(struct in6_addr
));
3776 addr
->u
.a6
.pfxlen
= ifa
->prefix_len
;
3777 addr
->type
= QETH_IP_TYPE_NORMAL
;
3783 if (!qeth_l3_add_ip(card
, addr
))
3787 if (!qeth_l3_delete_ip(card
, addr
))
3793 qeth_l3_set_ip_addr_list(card
);
3798 static struct notifier_block qeth_l3_ip6_notifier
= {
3804 static int qeth_l3_register_notifiers(void)
3808 QETH_DBF_TEXT(SETUP
, 5, "regnotif");
3809 rc
= register_inetaddr_notifier(&qeth_l3_ip_notifier
);
3812 #ifdef CONFIG_QETH_IPV6
3813 rc
= register_inet6addr_notifier(&qeth_l3_ip6_notifier
);
3815 unregister_inetaddr_notifier(&qeth_l3_ip_notifier
);
3819 pr_warning("There is no IPv6 support for the layer 3 discipline\n");
3824 static void qeth_l3_unregister_notifiers(void)
3827 QETH_DBF_TEXT(SETUP
, 5, "unregnot");
3828 BUG_ON(unregister_inetaddr_notifier(&qeth_l3_ip_notifier
));
3829 #ifdef CONFIG_QETH_IPV6
3830 BUG_ON(unregister_inet6addr_notifier(&qeth_l3_ip6_notifier
));
3831 #endif /* QETH_IPV6 */
3834 static int __init
qeth_l3_init(void)
3838 pr_info("register layer 3 discipline\n");
3839 rc
= qeth_l3_register_notifiers();
3843 static void __exit
qeth_l3_exit(void)
3845 qeth_l3_unregister_notifiers();
3846 pr_info("unregister layer 3 discipline\n");
3849 module_init(qeth_l3_init
);
3850 module_exit(qeth_l3_exit
);
3851 MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
3852 MODULE_DESCRIPTION("qeth layer 3 discipline");
3853 MODULE_LICENSE("GPL");