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>
33 static int qeth_l3_set_offline(struct ccwgroup_device
*);
34 static int qeth_l3_recover(void *);
35 static int qeth_l3_stop(struct net_device
*);
36 static void qeth_l3_set_multicast_list(struct net_device
*);
37 static int qeth_l3_neigh_setup(struct net_device
*, struct neigh_parms
*);
38 static int qeth_l3_register_addr_entry(struct qeth_card
*,
39 struct qeth_ipaddr
*);
40 static int qeth_l3_deregister_addr_entry(struct qeth_card
*,
41 struct qeth_ipaddr
*);
42 static int __qeth_l3_set_online(struct ccwgroup_device
*, int);
43 static int __qeth_l3_set_offline(struct ccwgroup_device
*, int);
45 int qeth_l3_set_large_send(struct qeth_card
*card
,
46 enum qeth_large_send_types type
)
50 card
->options
.large_send
= type
;
51 if (card
->dev
== NULL
)
54 if (card
->options
.large_send
== QETH_LARGE_SEND_TSO
) {
55 if (qeth_is_supported(card
, IPA_OUTBOUND_TSO
)) {
56 card
->dev
->features
|= NETIF_F_TSO
| NETIF_F_SG
|
59 card
->dev
->features
&= ~(NETIF_F_TSO
| NETIF_F_SG
|
61 card
->options
.large_send
= QETH_LARGE_SEND_NO
;
65 card
->dev
->features
&= ~(NETIF_F_TSO
| NETIF_F_SG
|
67 card
->options
.large_send
= QETH_LARGE_SEND_NO
;
72 static int qeth_l3_isxdigit(char *buf
)
75 if (!isxdigit(*buf
++))
81 void qeth_l3_ipaddr4_to_string(const __u8
*addr
, char *buf
)
83 sprintf(buf
, "%i.%i.%i.%i", addr
[0], addr
[1], addr
[2], addr
[3]);
86 int qeth_l3_string_to_ipaddr4(const char *buf
, __u8
*addr
)
88 int count
= 0, rc
= 0;
92 rc
= sscanf(buf
, "%u.%u.%u.%u%c",
93 &in
[0], &in
[1], &in
[2], &in
[3], &c
);
94 if (rc
!= 4 && (rc
!= 5 || c
!= '\n'))
96 for (count
= 0; count
< 4; count
++) {
99 addr
[count
] = in
[count
];
104 void qeth_l3_ipaddr6_to_string(const __u8
*addr
, char *buf
)
106 sprintf(buf
, "%02x%02x:%02x%02x:%02x%02x:%02x%02x"
107 ":%02x%02x:%02x%02x:%02x%02x:%02x%02x",
108 addr
[0], addr
[1], addr
[2], addr
[3],
109 addr
[4], addr
[5], addr
[6], addr
[7],
110 addr
[8], addr
[9], addr
[10], addr
[11],
111 addr
[12], addr
[13], addr
[14], addr
[15]);
114 int qeth_l3_string_to_ipaddr6(const char *buf
, __u8
*addr
)
116 const char *end
, *end_tmp
, *start
;
119 int num2
, cnt
, out
, found
, save_cnt
;
120 unsigned short in_tmp
[8] = {0, };
122 cnt
= out
= found
= save_cnt
= num2
= 0;
127 end
= strchr(start
, ':');
129 end
= buf
+ strlen(buf
);
130 end_tmp
= strchr(start
, '\n');
137 if ((end
- start
) > 4)
139 memcpy(num
, start
, end
- start
);
140 if (!qeth_l3_isxdigit(num
))
142 sscanf(start
, "%x", &num2
);
144 in_tmp
[save_cnt
++] = num2
;
156 if (cnt
+ save_cnt
> 8)
160 in
[cnt
--] = in_tmp
[--save_cnt
];
164 void qeth_l3_ipaddr_to_string(enum qeth_prot_versions proto
, const __u8
*addr
,
167 if (proto
== QETH_PROT_IPV4
)
168 qeth_l3_ipaddr4_to_string(addr
, buf
);
169 else if (proto
== QETH_PROT_IPV6
)
170 qeth_l3_ipaddr6_to_string(addr
, buf
);
173 int qeth_l3_string_to_ipaddr(const char *buf
, enum qeth_prot_versions proto
,
176 if (proto
== QETH_PROT_IPV4
)
177 return qeth_l3_string_to_ipaddr4(buf
, addr
);
178 else if (proto
== QETH_PROT_IPV6
)
179 return qeth_l3_string_to_ipaddr6(buf
, addr
);
184 static void qeth_l3_convert_addr_to_bits(u8
*addr
, u8
*bits
, int len
)
189 for (i
= 0; i
< len
; ++i
) {
191 for (j
= 7; j
>= 0; --j
) {
192 bits
[i
*8 + j
] = octet
& 1;
198 static int qeth_l3_is_addr_covered_by_ipato(struct qeth_card
*card
,
199 struct qeth_ipaddr
*addr
)
201 struct qeth_ipato_entry
*ipatoe
;
202 u8 addr_bits
[128] = {0, };
203 u8 ipatoe_bits
[128] = {0, };
206 if (!card
->ipato
.enabled
)
209 qeth_l3_convert_addr_to_bits((u8
*) &addr
->u
, addr_bits
,
210 (addr
->proto
== QETH_PROT_IPV4
)? 4:16);
211 list_for_each_entry(ipatoe
, &card
->ipato
.entries
, entry
) {
212 if (addr
->proto
!= ipatoe
->proto
)
214 qeth_l3_convert_addr_to_bits(ipatoe
->addr
, ipatoe_bits
,
215 (ipatoe
->proto
== QETH_PROT_IPV4
) ?
217 if (addr
->proto
== QETH_PROT_IPV4
)
218 rc
= !memcmp(addr_bits
, ipatoe_bits
,
219 min(32, ipatoe
->mask_bits
));
221 rc
= !memcmp(addr_bits
, ipatoe_bits
,
222 min(128, ipatoe
->mask_bits
));
227 if ((addr
->proto
== QETH_PROT_IPV4
) && card
->ipato
.invert4
)
229 else if ((addr
->proto
== QETH_PROT_IPV6
) && card
->ipato
.invert6
)
236 * Add IP to be added to todo list. If there is already an "add todo"
237 * in this list we just incremenent the reference count.
238 * Returns 0 if we just incremented reference count.
240 static int __qeth_l3_insert_ip_todo(struct qeth_card
*card
,
241 struct qeth_ipaddr
*addr
, int add
)
243 struct qeth_ipaddr
*tmp
, *t
;
246 if (card
->options
.sniffer
)
248 list_for_each_entry_safe(tmp
, t
, card
->ip_tbd_list
, entry
) {
249 if ((addr
->type
== QETH_IP_TYPE_DEL_ALL_MC
) &&
250 (tmp
->type
== QETH_IP_TYPE_DEL_ALL_MC
))
252 if ((tmp
->proto
== QETH_PROT_IPV4
) &&
253 (addr
->proto
== QETH_PROT_IPV4
) &&
254 (tmp
->type
== addr
->type
) &&
255 (tmp
->is_multicast
== addr
->is_multicast
) &&
256 (tmp
->u
.a4
.addr
== addr
->u
.a4
.addr
) &&
257 (tmp
->u
.a4
.mask
== addr
->u
.a4
.mask
)) {
261 if ((tmp
->proto
== QETH_PROT_IPV6
) &&
262 (addr
->proto
== QETH_PROT_IPV6
) &&
263 (tmp
->type
== addr
->type
) &&
264 (tmp
->is_multicast
== addr
->is_multicast
) &&
265 (tmp
->u
.a6
.pfxlen
== addr
->u
.a6
.pfxlen
) &&
266 (memcmp(&tmp
->u
.a6
.addr
, &addr
->u
.a6
.addr
,
267 sizeof(struct in6_addr
)) == 0)) {
273 if (addr
->users
!= 0)
274 tmp
->users
+= addr
->users
;
276 tmp
->users
+= add
? 1 : -1;
277 if (tmp
->users
== 0) {
278 list_del(&tmp
->entry
);
283 if (addr
->type
== QETH_IP_TYPE_DEL_ALL_MC
)
284 list_add(&addr
->entry
, card
->ip_tbd_list
);
286 if (addr
->users
== 0)
287 addr
->users
+= add
? 1 : -1;
288 if (add
&& (addr
->type
== QETH_IP_TYPE_NORMAL
) &&
289 qeth_l3_is_addr_covered_by_ipato(card
, addr
)) {
290 QETH_DBF_TEXT(TRACE
, 2, "tkovaddr");
291 addr
->set_flags
|= QETH_IPA_SETIP_TAKEOVER_FLAG
;
293 list_add_tail(&addr
->entry
, card
->ip_tbd_list
);
299 static int qeth_l3_delete_ip(struct qeth_card
*card
, struct qeth_ipaddr
*addr
)
304 QETH_DBF_TEXT(TRACE
, 4, "delip");
306 if (addr
->proto
== QETH_PROT_IPV4
)
307 QETH_DBF_HEX(TRACE
, 4, &addr
->u
.a4
.addr
, 4);
309 QETH_DBF_HEX(TRACE
, 4, &addr
->u
.a6
.addr
, 8);
310 QETH_DBF_HEX(TRACE
, 4, ((char *)&addr
->u
.a6
.addr
) + 8, 8);
312 spin_lock_irqsave(&card
->ip_lock
, flags
);
313 rc
= __qeth_l3_insert_ip_todo(card
, addr
, 0);
314 spin_unlock_irqrestore(&card
->ip_lock
, flags
);
318 static int qeth_l3_add_ip(struct qeth_card
*card
, struct qeth_ipaddr
*addr
)
323 QETH_DBF_TEXT(TRACE
, 4, "addip");
324 if (addr
->proto
== QETH_PROT_IPV4
)
325 QETH_DBF_HEX(TRACE
, 4, &addr
->u
.a4
.addr
, 4);
327 QETH_DBF_HEX(TRACE
, 4, &addr
->u
.a6
.addr
, 8);
328 QETH_DBF_HEX(TRACE
, 4, ((char *)&addr
->u
.a6
.addr
) + 8, 8);
330 spin_lock_irqsave(&card
->ip_lock
, flags
);
331 rc
= __qeth_l3_insert_ip_todo(card
, addr
, 1);
332 spin_unlock_irqrestore(&card
->ip_lock
, flags
);
337 static struct qeth_ipaddr
*qeth_l3_get_addr_buffer(
338 enum qeth_prot_versions prot
)
340 struct qeth_ipaddr
*addr
;
342 addr
= kzalloc(sizeof(struct qeth_ipaddr
), GFP_ATOMIC
);
346 addr
->type
= QETH_IP_TYPE_NORMAL
;
351 static void qeth_l3_delete_mc_addresses(struct qeth_card
*card
)
353 struct qeth_ipaddr
*iptodo
;
356 QETH_DBF_TEXT(TRACE
, 4, "delmc");
357 iptodo
= qeth_l3_get_addr_buffer(QETH_PROT_IPV4
);
359 QETH_DBF_TEXT(TRACE
, 2, "dmcnomem");
362 iptodo
->type
= QETH_IP_TYPE_DEL_ALL_MC
;
363 spin_lock_irqsave(&card
->ip_lock
, flags
);
364 if (!__qeth_l3_insert_ip_todo(card
, iptodo
, 0))
366 spin_unlock_irqrestore(&card
->ip_lock
, flags
);
370 * Add/remove address to/from card's ip list, i.e. try to add or remove
371 * reference to/from an IP address that is already registered on the card.
373 * 0 address was on card and its reference count has been adjusted,
374 * but is still > 0, so nothing has to be done
375 * also returns 0 if card was not on card and the todo was to delete
376 * the address -> there is also nothing to be done
377 * 1 address was not on card and the todo is to add it to the card's ip
379 * -1 address was on card and its reference count has been decremented
380 * to <= 0 by the todo -> address must be removed from card
382 static int __qeth_l3_ref_ip_on_card(struct qeth_card
*card
,
383 struct qeth_ipaddr
*todo
, struct qeth_ipaddr
**__addr
)
385 struct qeth_ipaddr
*addr
;
388 list_for_each_entry(addr
, &card
->ip_list
, entry
) {
389 if ((addr
->proto
== QETH_PROT_IPV4
) &&
390 (todo
->proto
== QETH_PROT_IPV4
) &&
391 (addr
->type
== todo
->type
) &&
392 (addr
->u
.a4
.addr
== todo
->u
.a4
.addr
) &&
393 (addr
->u
.a4
.mask
== todo
->u
.a4
.mask
)) {
397 if ((addr
->proto
== QETH_PROT_IPV6
) &&
398 (todo
->proto
== QETH_PROT_IPV6
) &&
399 (addr
->type
== todo
->type
) &&
400 (addr
->u
.a6
.pfxlen
== todo
->u
.a6
.pfxlen
) &&
401 (memcmp(&addr
->u
.a6
.addr
, &todo
->u
.a6
.addr
,
402 sizeof(struct in6_addr
)) == 0)) {
408 addr
->users
+= todo
->users
;
409 if (addr
->users
<= 0) {
413 /* for VIPA and RXIP limit refcount to 1 */
414 if (addr
->type
!= QETH_IP_TYPE_NORMAL
)
419 if (todo
->users
> 0) {
420 /* for VIPA and RXIP limit refcount to 1 */
421 if (todo
->type
!= QETH_IP_TYPE_NORMAL
)
428 static void __qeth_l3_delete_all_mc(struct qeth_card
*card
,
429 unsigned long *flags
)
431 struct list_head fail_list
;
432 struct qeth_ipaddr
*addr
, *tmp
;
435 INIT_LIST_HEAD(&fail_list
);
437 list_for_each_entry_safe(addr
, tmp
, &card
->ip_list
, entry
) {
438 if (addr
->is_multicast
) {
439 list_del(&addr
->entry
);
440 spin_unlock_irqrestore(&card
->ip_lock
, *flags
);
441 rc
= qeth_l3_deregister_addr_entry(card
, addr
);
442 spin_lock_irqsave(&card
->ip_lock
, *flags
);
443 if (!rc
|| (rc
== IPA_RC_MC_ADDR_NOT_FOUND
))
446 list_add_tail(&addr
->entry
, &fail_list
);
450 list_splice(&fail_list
, &card
->ip_list
);
453 static void qeth_l3_set_ip_addr_list(struct qeth_card
*card
)
455 struct list_head
*tbd_list
;
456 struct qeth_ipaddr
*todo
, *addr
;
460 QETH_DBF_TEXT(TRACE
, 2, "sdiplist");
461 QETH_DBF_HEX(TRACE
, 2, &card
, sizeof(void *));
463 if (card
->options
.sniffer
)
465 spin_lock_irqsave(&card
->ip_lock
, flags
);
466 tbd_list
= card
->ip_tbd_list
;
467 card
->ip_tbd_list
= kmalloc(sizeof(struct list_head
), GFP_ATOMIC
);
468 if (!card
->ip_tbd_list
) {
469 QETH_DBF_TEXT(TRACE
, 0, "silnomem");
470 card
->ip_tbd_list
= tbd_list
;
471 spin_unlock_irqrestore(&card
->ip_lock
, flags
);
474 INIT_LIST_HEAD(card
->ip_tbd_list
);
476 while (!list_empty(tbd_list
)) {
477 todo
= list_entry(tbd_list
->next
, struct qeth_ipaddr
, entry
);
478 list_del(&todo
->entry
);
479 if (todo
->type
== QETH_IP_TYPE_DEL_ALL_MC
) {
480 __qeth_l3_delete_all_mc(card
, &flags
);
484 rc
= __qeth_l3_ref_ip_on_card(card
, todo
, &addr
);
486 /* nothing to be done; only adjusted refcount */
488 } else if (rc
== 1) {
489 /* new entry to be added to on-card list */
490 spin_unlock_irqrestore(&card
->ip_lock
, flags
);
491 rc
= qeth_l3_register_addr_entry(card
, todo
);
492 spin_lock_irqsave(&card
->ip_lock
, flags
);
493 if (!rc
|| (rc
== IPA_RC_LAN_OFFLINE
))
494 list_add_tail(&todo
->entry
, &card
->ip_list
);
497 } else if (rc
== -1) {
498 /* on-card entry to be removed */
499 list_del_init(&addr
->entry
);
500 spin_unlock_irqrestore(&card
->ip_lock
, flags
);
501 rc
= qeth_l3_deregister_addr_entry(card
, addr
);
502 spin_lock_irqsave(&card
->ip_lock
, flags
);
503 if (!rc
|| (rc
== IPA_RC_IP_ADDRESS_NOT_DEFINED
))
506 list_add_tail(&addr
->entry
, &card
->ip_list
);
510 spin_unlock_irqrestore(&card
->ip_lock
, flags
);
514 static void qeth_l3_clear_ip_list(struct qeth_card
*card
, int clean
,
517 struct qeth_ipaddr
*addr
, *tmp
;
520 QETH_DBF_TEXT(TRACE
, 4, "clearip");
521 if (recover
&& card
->options
.sniffer
)
523 spin_lock_irqsave(&card
->ip_lock
, flags
);
524 /* clear todo list */
525 list_for_each_entry_safe(addr
, tmp
, card
->ip_tbd_list
, entry
) {
526 list_del(&addr
->entry
);
530 while (!list_empty(&card
->ip_list
)) {
531 addr
= list_entry(card
->ip_list
.next
,
532 struct qeth_ipaddr
, entry
);
533 list_del_init(&addr
->entry
);
535 spin_unlock_irqrestore(&card
->ip_lock
, flags
);
536 qeth_l3_deregister_addr_entry(card
, addr
);
537 spin_lock_irqsave(&card
->ip_lock
, flags
);
539 if (!recover
|| addr
->is_multicast
) {
543 list_add_tail(&addr
->entry
, card
->ip_tbd_list
);
545 spin_unlock_irqrestore(&card
->ip_lock
, flags
);
548 static int qeth_l3_address_exists_in_list(struct list_head
*list
,
549 struct qeth_ipaddr
*addr
, int same_type
)
551 struct qeth_ipaddr
*tmp
;
553 list_for_each_entry(tmp
, list
, entry
) {
554 if ((tmp
->proto
== QETH_PROT_IPV4
) &&
555 (addr
->proto
== QETH_PROT_IPV4
) &&
556 ((same_type
&& (tmp
->type
== addr
->type
)) ||
557 (!same_type
&& (tmp
->type
!= addr
->type
))) &&
558 (tmp
->u
.a4
.addr
== addr
->u
.a4
.addr
))
561 if ((tmp
->proto
== QETH_PROT_IPV6
) &&
562 (addr
->proto
== QETH_PROT_IPV6
) &&
563 ((same_type
&& (tmp
->type
== addr
->type
)) ||
564 (!same_type
&& (tmp
->type
!= addr
->type
))) &&
565 (memcmp(&tmp
->u
.a6
.addr
, &addr
->u
.a6
.addr
,
566 sizeof(struct in6_addr
)) == 0))
573 static int qeth_l3_send_setdelmc(struct qeth_card
*card
,
574 struct qeth_ipaddr
*addr
, int ipacmd
)
577 struct qeth_cmd_buffer
*iob
;
578 struct qeth_ipa_cmd
*cmd
;
580 QETH_DBF_TEXT(TRACE
, 4, "setdelmc");
582 iob
= qeth_get_ipacmd_buffer(card
, ipacmd
, addr
->proto
);
583 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
584 memcpy(&cmd
->data
.setdelipm
.mac
, addr
->mac
, OSA_ADDR_LEN
);
585 if (addr
->proto
== QETH_PROT_IPV6
)
586 memcpy(cmd
->data
.setdelipm
.ip6
, &addr
->u
.a6
.addr
,
587 sizeof(struct in6_addr
));
589 memcpy(&cmd
->data
.setdelipm
.ip4
, &addr
->u
.a4
.addr
, 4);
591 rc
= qeth_send_ipa_cmd(card
, iob
, NULL
, NULL
);
596 static void qeth_l3_fill_netmask(u8
*netmask
, unsigned int len
)
599 for (i
= 0; i
< 16; i
++) {
604 netmask
[i
] = (u8
)(0xFF00 >> j
);
610 static int qeth_l3_send_setdelip(struct qeth_card
*card
,
611 struct qeth_ipaddr
*addr
, int ipacmd
, unsigned int flags
)
614 struct qeth_cmd_buffer
*iob
;
615 struct qeth_ipa_cmd
*cmd
;
618 QETH_DBF_TEXT(TRACE
, 4, "setdelip");
619 QETH_DBF_TEXT_(TRACE
, 4, "flags%02X", flags
);
621 iob
= qeth_get_ipacmd_buffer(card
, ipacmd
, addr
->proto
);
622 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
623 if (addr
->proto
== QETH_PROT_IPV6
) {
624 memcpy(cmd
->data
.setdelip6
.ip_addr
, &addr
->u
.a6
.addr
,
625 sizeof(struct in6_addr
));
626 qeth_l3_fill_netmask(netmask
, addr
->u
.a6
.pfxlen
);
627 memcpy(cmd
->data
.setdelip6
.mask
, netmask
,
628 sizeof(struct in6_addr
));
629 cmd
->data
.setdelip6
.flags
= flags
;
631 memcpy(cmd
->data
.setdelip4
.ip_addr
, &addr
->u
.a4
.addr
, 4);
632 memcpy(cmd
->data
.setdelip4
.mask
, &addr
->u
.a4
.mask
, 4);
633 cmd
->data
.setdelip4
.flags
= flags
;
636 rc
= qeth_send_ipa_cmd(card
, iob
, NULL
, NULL
);
641 static int qeth_l3_send_setrouting(struct qeth_card
*card
,
642 enum qeth_routing_types type
, enum qeth_prot_versions prot
)
645 struct qeth_ipa_cmd
*cmd
;
646 struct qeth_cmd_buffer
*iob
;
648 QETH_DBF_TEXT(TRACE
, 4, "setroutg");
649 iob
= qeth_get_ipacmd_buffer(card
, IPA_CMD_SETRTG
, prot
);
650 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
651 cmd
->data
.setrtg
.type
= (type
);
652 rc
= qeth_send_ipa_cmd(card
, iob
, NULL
, NULL
);
657 static void qeth_l3_correct_routing_type(struct qeth_card
*card
,
658 enum qeth_routing_types
*type
, enum qeth_prot_versions prot
)
660 if (card
->info
.type
== QETH_CARD_TYPE_IQD
) {
663 case PRIMARY_CONNECTOR
:
664 case SECONDARY_CONNECTOR
:
665 case MULTICAST_ROUTER
:
674 case SECONDARY_ROUTER
:
676 case MULTICAST_ROUTER
:
677 if (qeth_is_ipafunc_supported(card
, prot
,
688 int qeth_l3_setrouting_v4(struct qeth_card
*card
)
692 QETH_DBF_TEXT(TRACE
, 3, "setrtg4");
694 qeth_l3_correct_routing_type(card
, &card
->options
.route4
.type
,
697 rc
= qeth_l3_send_setrouting(card
, card
->options
.route4
.type
,
700 card
->options
.route4
.type
= NO_ROUTER
;
701 QETH_DBF_MESSAGE(2, "Error (0x%04x) while setting routing type"
702 " on %s. Type set to 'no router'.\n", rc
,
703 QETH_CARD_IFNAME(card
));
708 int qeth_l3_setrouting_v6(struct qeth_card
*card
)
712 QETH_DBF_TEXT(TRACE
, 3, "setrtg6");
713 #ifdef CONFIG_QETH_IPV6
715 if (!qeth_is_supported(card
, IPA_IPV6
))
717 qeth_l3_correct_routing_type(card
, &card
->options
.route6
.type
,
720 rc
= qeth_l3_send_setrouting(card
, card
->options
.route6
.type
,
723 card
->options
.route6
.type
= NO_ROUTER
;
724 QETH_DBF_MESSAGE(2, "Error (0x%04x) while setting routing type"
725 " on %s. Type set to 'no router'.\n", rc
,
726 QETH_CARD_IFNAME(card
));
733 * IP address takeover related functions
735 static void qeth_l3_clear_ipato_list(struct qeth_card
*card
)
738 struct qeth_ipato_entry
*ipatoe
, *tmp
;
741 spin_lock_irqsave(&card
->ip_lock
, flags
);
742 list_for_each_entry_safe(ipatoe
, tmp
, &card
->ipato
.entries
, entry
) {
743 list_del(&ipatoe
->entry
);
746 spin_unlock_irqrestore(&card
->ip_lock
, flags
);
749 int qeth_l3_add_ipato_entry(struct qeth_card
*card
,
750 struct qeth_ipato_entry
*new)
752 struct qeth_ipato_entry
*ipatoe
;
756 QETH_DBF_TEXT(TRACE
, 2, "addipato");
757 spin_lock_irqsave(&card
->ip_lock
, flags
);
758 list_for_each_entry(ipatoe
, &card
->ipato
.entries
, entry
) {
759 if (ipatoe
->proto
!= new->proto
)
761 if (!memcmp(ipatoe
->addr
, new->addr
,
762 (ipatoe
->proto
== QETH_PROT_IPV4
)? 4:16) &&
763 (ipatoe
->mask_bits
== new->mask_bits
)) {
769 list_add_tail(&new->entry
, &card
->ipato
.entries
);
771 spin_unlock_irqrestore(&card
->ip_lock
, flags
);
775 void qeth_l3_del_ipato_entry(struct qeth_card
*card
,
776 enum qeth_prot_versions proto
, u8
*addr
, int mask_bits
)
778 struct qeth_ipato_entry
*ipatoe
, *tmp
;
781 QETH_DBF_TEXT(TRACE
, 2, "delipato");
782 spin_lock_irqsave(&card
->ip_lock
, flags
);
783 list_for_each_entry_safe(ipatoe
, tmp
, &card
->ipato
.entries
, entry
) {
784 if (ipatoe
->proto
!= proto
)
786 if (!memcmp(ipatoe
->addr
, addr
,
787 (proto
== QETH_PROT_IPV4
)? 4:16) &&
788 (ipatoe
->mask_bits
== mask_bits
)) {
789 list_del(&ipatoe
->entry
);
793 spin_unlock_irqrestore(&card
->ip_lock
, flags
);
797 * VIPA related functions
799 int qeth_l3_add_vipa(struct qeth_card
*card
, enum qeth_prot_versions proto
,
802 struct qeth_ipaddr
*ipaddr
;
806 ipaddr
= qeth_l3_get_addr_buffer(proto
);
808 if (proto
== QETH_PROT_IPV4
) {
809 QETH_DBF_TEXT(TRACE
, 2, "addvipa4");
810 memcpy(&ipaddr
->u
.a4
.addr
, addr
, 4);
811 ipaddr
->u
.a4
.mask
= 0;
812 } else if (proto
== QETH_PROT_IPV6
) {
813 QETH_DBF_TEXT(TRACE
, 2, "addvipa6");
814 memcpy(&ipaddr
->u
.a6
.addr
, addr
, 16);
815 ipaddr
->u
.a6
.pfxlen
= 0;
817 ipaddr
->type
= QETH_IP_TYPE_VIPA
;
818 ipaddr
->set_flags
= QETH_IPA_SETIP_VIPA_FLAG
;
819 ipaddr
->del_flags
= QETH_IPA_DELIP_VIPA_FLAG
;
822 spin_lock_irqsave(&card
->ip_lock
, flags
);
823 if (qeth_l3_address_exists_in_list(&card
->ip_list
, ipaddr
, 0) ||
824 qeth_l3_address_exists_in_list(card
->ip_tbd_list
, ipaddr
, 0))
826 spin_unlock_irqrestore(&card
->ip_lock
, flags
);
830 if (!qeth_l3_add_ip(card
, ipaddr
))
832 qeth_l3_set_ip_addr_list(card
);
836 void qeth_l3_del_vipa(struct qeth_card
*card
, enum qeth_prot_versions proto
,
839 struct qeth_ipaddr
*ipaddr
;
841 ipaddr
= qeth_l3_get_addr_buffer(proto
);
843 if (proto
== QETH_PROT_IPV4
) {
844 QETH_DBF_TEXT(TRACE
, 2, "delvipa4");
845 memcpy(&ipaddr
->u
.a4
.addr
, addr
, 4);
846 ipaddr
->u
.a4
.mask
= 0;
847 } else if (proto
== QETH_PROT_IPV6
) {
848 QETH_DBF_TEXT(TRACE
, 2, "delvipa6");
849 memcpy(&ipaddr
->u
.a6
.addr
, addr
, 16);
850 ipaddr
->u
.a6
.pfxlen
= 0;
852 ipaddr
->type
= QETH_IP_TYPE_VIPA
;
855 if (!qeth_l3_delete_ip(card
, ipaddr
))
857 qeth_l3_set_ip_addr_list(card
);
861 * proxy ARP related functions
863 int qeth_l3_add_rxip(struct qeth_card
*card
, enum qeth_prot_versions proto
,
866 struct qeth_ipaddr
*ipaddr
;
870 ipaddr
= qeth_l3_get_addr_buffer(proto
);
872 if (proto
== QETH_PROT_IPV4
) {
873 QETH_DBF_TEXT(TRACE
, 2, "addrxip4");
874 memcpy(&ipaddr
->u
.a4
.addr
, addr
, 4);
875 ipaddr
->u
.a4
.mask
= 0;
876 } else if (proto
== QETH_PROT_IPV6
) {
877 QETH_DBF_TEXT(TRACE
, 2, "addrxip6");
878 memcpy(&ipaddr
->u
.a6
.addr
, addr
, 16);
879 ipaddr
->u
.a6
.pfxlen
= 0;
881 ipaddr
->type
= QETH_IP_TYPE_RXIP
;
882 ipaddr
->set_flags
= QETH_IPA_SETIP_TAKEOVER_FLAG
;
883 ipaddr
->del_flags
= 0;
886 spin_lock_irqsave(&card
->ip_lock
, flags
);
887 if (qeth_l3_address_exists_in_list(&card
->ip_list
, ipaddr
, 0) ||
888 qeth_l3_address_exists_in_list(card
->ip_tbd_list
, ipaddr
, 0))
890 spin_unlock_irqrestore(&card
->ip_lock
, flags
);
894 if (!qeth_l3_add_ip(card
, ipaddr
))
896 qeth_l3_set_ip_addr_list(card
);
900 void qeth_l3_del_rxip(struct qeth_card
*card
, enum qeth_prot_versions proto
,
903 struct qeth_ipaddr
*ipaddr
;
905 ipaddr
= qeth_l3_get_addr_buffer(proto
);
907 if (proto
== QETH_PROT_IPV4
) {
908 QETH_DBF_TEXT(TRACE
, 2, "addrxip4");
909 memcpy(&ipaddr
->u
.a4
.addr
, addr
, 4);
910 ipaddr
->u
.a4
.mask
= 0;
911 } else if (proto
== QETH_PROT_IPV6
) {
912 QETH_DBF_TEXT(TRACE
, 2, "addrxip6");
913 memcpy(&ipaddr
->u
.a6
.addr
, addr
, 16);
914 ipaddr
->u
.a6
.pfxlen
= 0;
916 ipaddr
->type
= QETH_IP_TYPE_RXIP
;
919 if (!qeth_l3_delete_ip(card
, ipaddr
))
921 qeth_l3_set_ip_addr_list(card
);
924 static int qeth_l3_register_addr_entry(struct qeth_card
*card
,
925 struct qeth_ipaddr
*addr
)
931 if (addr
->proto
== QETH_PROT_IPV4
) {
932 QETH_DBF_TEXT(TRACE
, 2, "setaddr4");
933 QETH_DBF_HEX(TRACE
, 3, &addr
->u
.a4
.addr
, sizeof(int));
934 } else if (addr
->proto
== QETH_PROT_IPV6
) {
935 QETH_DBF_TEXT(TRACE
, 2, "setaddr6");
936 QETH_DBF_HEX(TRACE
, 3, &addr
->u
.a6
.addr
, 8);
937 QETH_DBF_HEX(TRACE
, 3, ((char *)&addr
->u
.a6
.addr
) + 8, 8);
939 QETH_DBF_TEXT(TRACE
, 2, "setaddr?");
940 QETH_DBF_HEX(TRACE
, 3, addr
, sizeof(struct qeth_ipaddr
));
943 if (addr
->is_multicast
)
944 rc
= qeth_l3_send_setdelmc(card
, addr
, IPA_CMD_SETIPM
);
946 rc
= qeth_l3_send_setdelip(card
, addr
, IPA_CMD_SETIP
,
949 QETH_DBF_TEXT(TRACE
, 2, "failed");
950 } while ((--cnt
> 0) && rc
);
952 QETH_DBF_TEXT(TRACE
, 2, "FAILED");
953 qeth_l3_ipaddr_to_string(addr
->proto
, (u8
*)&addr
->u
, buf
);
954 dev_warn(&card
->gdev
->dev
,
955 "Registering IP address %s failed\n", buf
);
960 static int qeth_l3_deregister_addr_entry(struct qeth_card
*card
,
961 struct qeth_ipaddr
*addr
)
965 if (addr
->proto
== QETH_PROT_IPV4
) {
966 QETH_DBF_TEXT(TRACE
, 2, "deladdr4");
967 QETH_DBF_HEX(TRACE
, 3, &addr
->u
.a4
.addr
, sizeof(int));
968 } else if (addr
->proto
== QETH_PROT_IPV6
) {
969 QETH_DBF_TEXT(TRACE
, 2, "deladdr6");
970 QETH_DBF_HEX(TRACE
, 3, &addr
->u
.a6
.addr
, 8);
971 QETH_DBF_HEX(TRACE
, 3, ((char *)&addr
->u
.a6
.addr
) + 8, 8);
973 QETH_DBF_TEXT(TRACE
, 2, "deladdr?");
974 QETH_DBF_HEX(TRACE
, 3, addr
, sizeof(struct qeth_ipaddr
));
976 if (addr
->is_multicast
)
977 rc
= qeth_l3_send_setdelmc(card
, addr
, IPA_CMD_DELIPM
);
979 rc
= qeth_l3_send_setdelip(card
, addr
, IPA_CMD_DELIP
,
982 QETH_DBF_TEXT(TRACE
, 2, "failed");
987 static inline u8
qeth_l3_get_qeth_hdr_flags4(int cast_type
)
989 if (cast_type
== RTN_MULTICAST
)
990 return QETH_CAST_MULTICAST
;
991 if (cast_type
== RTN_BROADCAST
)
992 return QETH_CAST_BROADCAST
;
993 return QETH_CAST_UNICAST
;
996 static inline u8
qeth_l3_get_qeth_hdr_flags6(int cast_type
)
998 u8 ct
= QETH_HDR_PASSTHRU
| QETH_HDR_IPV6
;
999 if (cast_type
== RTN_MULTICAST
)
1000 return ct
| QETH_CAST_MULTICAST
;
1001 if (cast_type
== RTN_ANYCAST
)
1002 return ct
| QETH_CAST_ANYCAST
;
1003 if (cast_type
== RTN_BROADCAST
)
1004 return ct
| QETH_CAST_BROADCAST
;
1005 return ct
| QETH_CAST_UNICAST
;
1008 static int qeth_l3_send_setadp_mode(struct qeth_card
*card
, __u32 command
,
1012 struct qeth_cmd_buffer
*iob
;
1013 struct qeth_ipa_cmd
*cmd
;
1015 QETH_DBF_TEXT(TRACE
, 4, "adpmode");
1017 iob
= qeth_get_adapter_cmd(card
, command
,
1018 sizeof(struct qeth_ipacmd_setadpparms
));
1019 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
1020 cmd
->data
.setadapterparms
.data
.mode
= mode
;
1021 rc
= qeth_send_ipa_cmd(card
, iob
, qeth_default_setadapterparms_cb
,
1026 static int qeth_l3_setadapter_hstr(struct qeth_card
*card
)
1030 QETH_DBF_TEXT(TRACE
, 4, "adphstr");
1032 if (qeth_adp_supported(card
, IPA_SETADP_SET_BROADCAST_MODE
)) {
1033 rc
= qeth_l3_send_setadp_mode(card
,
1034 IPA_SETADP_SET_BROADCAST_MODE
,
1035 card
->options
.broadcast_mode
);
1037 QETH_DBF_MESSAGE(2, "couldn't set broadcast mode on "
1039 CARD_BUS_ID(card
), rc
);
1040 rc
= qeth_l3_send_setadp_mode(card
,
1041 IPA_SETADP_ALTER_MAC_ADDRESS
,
1042 card
->options
.macaddr_mode
);
1044 QETH_DBF_MESSAGE(2, "couldn't set macaddr mode on "
1045 "device %s: x%x\n", CARD_BUS_ID(card
), rc
);
1048 if (card
->options
.broadcast_mode
== QETH_TR_BROADCAST_LOCAL
)
1049 QETH_DBF_MESSAGE(2, "set adapter parameters not available "
1050 "to set broadcast mode, using ALLRINGS "
1051 "on device %s:\n", CARD_BUS_ID(card
));
1052 if (card
->options
.macaddr_mode
== QETH_TR_MACADDR_CANONICAL
)
1053 QETH_DBF_MESSAGE(2, "set adapter parameters not available "
1054 "to set macaddr mode, using NONCANONICAL "
1055 "on device %s:\n", CARD_BUS_ID(card
));
1059 static int qeth_l3_setadapter_parms(struct qeth_card
*card
)
1063 QETH_DBF_TEXT(SETUP
, 2, "setadprm");
1065 if (!qeth_is_supported(card
, IPA_SETADAPTERPARMS
)) {
1066 dev_info(&card
->gdev
->dev
,
1067 "set adapter parameters not supported.\n");
1068 QETH_DBF_TEXT(SETUP
, 2, " notsupp");
1071 rc
= qeth_query_setadapterparms(card
);
1073 QETH_DBF_MESSAGE(2, "%s couldn't set adapter parameters: "
1074 "0x%x\n", dev_name(&card
->gdev
->dev
), rc
);
1077 if (qeth_adp_supported(card
, IPA_SETADP_ALTER_MAC_ADDRESS
)) {
1078 rc
= qeth_setadpparms_change_macaddr(card
);
1080 dev_warn(&card
->gdev
->dev
, "Reading the adapter MAC"
1081 " address failed\n");
1084 if ((card
->info
.link_type
== QETH_LINK_TYPE_HSTR
) ||
1085 (card
->info
.link_type
== QETH_LINK_TYPE_LANE_TR
))
1086 rc
= qeth_l3_setadapter_hstr(card
);
1091 static int qeth_l3_default_setassparms_cb(struct qeth_card
*card
,
1092 struct qeth_reply
*reply
, unsigned long data
)
1094 struct qeth_ipa_cmd
*cmd
;
1096 QETH_DBF_TEXT(TRACE
, 4, "defadpcb");
1098 cmd
= (struct qeth_ipa_cmd
*) data
;
1099 if (cmd
->hdr
.return_code
== 0) {
1100 cmd
->hdr
.return_code
= cmd
->data
.setassparms
.hdr
.return_code
;
1101 if (cmd
->hdr
.prot_version
== QETH_PROT_IPV4
)
1102 card
->options
.ipa4
.enabled_funcs
= cmd
->hdr
.ipa_enabled
;
1103 if (cmd
->hdr
.prot_version
== QETH_PROT_IPV6
)
1104 card
->options
.ipa6
.enabled_funcs
= cmd
->hdr
.ipa_enabled
;
1106 if (cmd
->data
.setassparms
.hdr
.assist_no
== IPA_INBOUND_CHECKSUM
&&
1107 cmd
->data
.setassparms
.hdr
.command_code
== IPA_CMD_ASS_START
) {
1108 card
->info
.csum_mask
= cmd
->data
.setassparms
.data
.flags_32bit
;
1109 QETH_DBF_TEXT_(TRACE
, 3, "csum:%d", card
->info
.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_DBF_TEXT(TRACE
, 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_DBF_TEXT(TRACE
, 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_DBF_TEXT(TRACE
, 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_DBF_TEXT(TRACE
, 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_DBF_TEXT(TRACE
, 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_DBF_TEXT(TRACE
, 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_DBF_TEXT(TRACE
, 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_DBF_TEXT(TRACE
, 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_DBF_TEXT(TRACE
, 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_DBF_TEXT(TRACE
, 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_DBF_TEXT(TRACE
, 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_DBF_TEXT(TRACE
, 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_DBF_TEXT(TRACE
, 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_tso(struct qeth_card
*card
)
1543 QETH_DBF_TEXT(TRACE
, 3, "sttso");
1545 if (!qeth_is_supported(card
, IPA_OUTBOUND_TSO
)) {
1546 dev_info(&card
->gdev
->dev
,
1547 "Outbound TSO not supported on %s\n",
1548 QETH_CARD_IFNAME(card
));
1551 rc
= qeth_l3_send_simple_setassparms(card
, IPA_OUTBOUND_TSO
,
1552 IPA_CMD_ASS_START
, 0);
1554 dev_warn(&card
->gdev
->dev
, "Starting outbound TCP "
1555 "segmentation offload for %s failed\n",
1556 QETH_CARD_IFNAME(card
));
1558 dev_info(&card
->gdev
->dev
,
1559 "Outbound TSO enabled\n");
1561 if (rc
&& (card
->options
.large_send
== QETH_LARGE_SEND_TSO
)) {
1562 card
->options
.large_send
= QETH_LARGE_SEND_NO
;
1563 card
->dev
->features
&= ~(NETIF_F_TSO
| NETIF_F_SG
);
1568 static int qeth_l3_start_ipassists(struct qeth_card
*card
)
1570 QETH_DBF_TEXT(TRACE
, 3, "strtipas");
1572 qeth_set_access_ctrl_online(card
); /* go on*/
1573 qeth_l3_start_ipa_arp_processing(card
); /* go on*/
1574 qeth_l3_start_ipa_ip_fragmentation(card
); /* go on*/
1575 qeth_l3_start_ipa_source_mac(card
); /* go on*/
1576 qeth_l3_start_ipa_vlan(card
); /* go on*/
1577 qeth_l3_start_ipa_multicast(card
); /* go on*/
1578 qeth_l3_start_ipa_ipv6(card
); /* go on*/
1579 qeth_l3_start_ipa_broadcast(card
); /* go on*/
1580 qeth_l3_start_ipa_checksum(card
); /* go on*/
1581 qeth_l3_start_ipa_tso(card
); /* go on*/
1585 static int qeth_l3_put_unique_id(struct qeth_card
*card
)
1589 struct qeth_cmd_buffer
*iob
;
1590 struct qeth_ipa_cmd
*cmd
;
1592 QETH_DBF_TEXT(TRACE
, 2, "puniqeid");
1594 if ((card
->info
.unique_id
& UNIQUE_ID_NOT_BY_CARD
) ==
1595 UNIQUE_ID_NOT_BY_CARD
)
1597 iob
= qeth_get_ipacmd_buffer(card
, IPA_CMD_DESTROY_ADDR
,
1599 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
1600 *((__u16
*) &cmd
->data
.create_destroy_addr
.unique_id
[6]) =
1601 card
->info
.unique_id
;
1602 memcpy(&cmd
->data
.create_destroy_addr
.unique_id
[0],
1603 card
->dev
->dev_addr
, OSA_ADDR_LEN
);
1604 rc
= qeth_send_ipa_cmd(card
, iob
, NULL
, NULL
);
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_DBF_TEXT_(TRACE
, 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_DBF_TEXT(TRACE
, 4, "addmc");
1774 for (im4
= in4_dev
->mc_list
; im4
; im4
= im4
->next
) {
1775 qeth_l3_get_mac_for_ipm(im4
->multiaddr
, buf
, in4_dev
->dev
);
1776 ipm
= qeth_l3_get_addr_buffer(QETH_PROT_IPV4
);
1779 ipm
->u
.a4
.addr
= im4
->multiaddr
;
1780 memcpy(ipm
->mac
, buf
, OSA_ADDR_LEN
);
1781 ipm
->is_multicast
= 1;
1782 if (!qeth_l3_add_ip(card
, ipm
))
1787 static void qeth_l3_add_vlan_mc(struct qeth_card
*card
)
1789 struct in_device
*in_dev
;
1790 struct vlan_group
*vg
;
1793 QETH_DBF_TEXT(TRACE
, 4, "addmcvl");
1794 if (!qeth_is_supported(card
, IPA_FULL_VLAN
) || (card
->vlangrp
== NULL
))
1798 for (i
= 0; i
< VLAN_GROUP_ARRAY_LEN
; i
++) {
1799 struct net_device
*netdev
= vlan_group_get_device(vg
, i
);
1800 if (netdev
== NULL
||
1801 !(netdev
->flags
& IFF_UP
))
1803 in_dev
= in_dev_get(netdev
);
1806 read_lock(&in_dev
->mc_list_lock
);
1807 qeth_l3_add_mc(card
, in_dev
);
1808 read_unlock(&in_dev
->mc_list_lock
);
1813 static void qeth_l3_add_multicast_ipv4(struct qeth_card
*card
)
1815 struct in_device
*in4_dev
;
1817 QETH_DBF_TEXT(TRACE
, 4, "chkmcv4");
1818 in4_dev
= in_dev_get(card
->dev
);
1819 if (in4_dev
== NULL
)
1821 read_lock(&in4_dev
->mc_list_lock
);
1822 qeth_l3_add_mc(card
, in4_dev
);
1823 qeth_l3_add_vlan_mc(card
);
1824 read_unlock(&in4_dev
->mc_list_lock
);
1825 in_dev_put(in4_dev
);
1828 #ifdef CONFIG_QETH_IPV6
1829 static void qeth_l3_add_mc6(struct qeth_card
*card
, struct inet6_dev
*in6_dev
)
1831 struct qeth_ipaddr
*ipm
;
1832 struct ifmcaddr6
*im6
;
1833 char buf
[MAX_ADDR_LEN
];
1835 QETH_DBF_TEXT(TRACE
, 4, "addmc6");
1836 for (im6
= in6_dev
->mc_list
; im6
!= NULL
; im6
= im6
->next
) {
1837 ndisc_mc_map(&im6
->mca_addr
, buf
, in6_dev
->dev
, 0);
1838 ipm
= qeth_l3_get_addr_buffer(QETH_PROT_IPV6
);
1841 ipm
->is_multicast
= 1;
1842 memcpy(ipm
->mac
, buf
, OSA_ADDR_LEN
);
1843 memcpy(&ipm
->u
.a6
.addr
, &im6
->mca_addr
.s6_addr
,
1844 sizeof(struct in6_addr
));
1845 if (!qeth_l3_add_ip(card
, ipm
))
1850 static void qeth_l3_add_vlan_mc6(struct qeth_card
*card
)
1852 struct inet6_dev
*in_dev
;
1853 struct vlan_group
*vg
;
1856 QETH_DBF_TEXT(TRACE
, 4, "admc6vl");
1857 if (!qeth_is_supported(card
, IPA_FULL_VLAN
) || (card
->vlangrp
== NULL
))
1861 for (i
= 0; i
< VLAN_GROUP_ARRAY_LEN
; i
++) {
1862 struct net_device
*netdev
= vlan_group_get_device(vg
, i
);
1863 if (netdev
== NULL
||
1864 !(netdev
->flags
& IFF_UP
))
1866 in_dev
= in6_dev_get(netdev
);
1869 read_lock_bh(&in_dev
->lock
);
1870 qeth_l3_add_mc6(card
, in_dev
);
1871 read_unlock_bh(&in_dev
->lock
);
1872 in6_dev_put(in_dev
);
1876 static void qeth_l3_add_multicast_ipv6(struct qeth_card
*card
)
1878 struct inet6_dev
*in6_dev
;
1880 QETH_DBF_TEXT(TRACE
, 4, "chkmcv6");
1881 if (!qeth_is_supported(card
, IPA_IPV6
))
1883 in6_dev
= in6_dev_get(card
->dev
);
1884 if (in6_dev
== NULL
)
1886 read_lock_bh(&in6_dev
->lock
);
1887 qeth_l3_add_mc6(card
, in6_dev
);
1888 qeth_l3_add_vlan_mc6(card
);
1889 read_unlock_bh(&in6_dev
->lock
);
1890 in6_dev_put(in6_dev
);
1892 #endif /* CONFIG_QETH_IPV6 */
1894 static void qeth_l3_free_vlan_addresses4(struct qeth_card
*card
,
1897 struct in_device
*in_dev
;
1898 struct in_ifaddr
*ifa
;
1899 struct qeth_ipaddr
*addr
;
1901 QETH_DBF_TEXT(TRACE
, 4, "frvaddr4");
1903 in_dev
= in_dev_get(vlan_group_get_device(card
->vlangrp
, vid
));
1906 for (ifa
= in_dev
->ifa_list
; ifa
; ifa
= ifa
->ifa_next
) {
1907 addr
= qeth_l3_get_addr_buffer(QETH_PROT_IPV4
);
1909 addr
->u
.a4
.addr
= ifa
->ifa_address
;
1910 addr
->u
.a4
.mask
= ifa
->ifa_mask
;
1911 addr
->type
= QETH_IP_TYPE_NORMAL
;
1912 if (!qeth_l3_delete_ip(card
, addr
))
1919 static void qeth_l3_free_vlan_addresses6(struct qeth_card
*card
,
1922 #ifdef CONFIG_QETH_IPV6
1923 struct inet6_dev
*in6_dev
;
1924 struct inet6_ifaddr
*ifa
;
1925 struct qeth_ipaddr
*addr
;
1927 QETH_DBF_TEXT(TRACE
, 4, "frvaddr6");
1929 in6_dev
= in6_dev_get(vlan_group_get_device(card
->vlangrp
, vid
));
1932 for (ifa
= in6_dev
->addr_list
; ifa
; ifa
= ifa
->lst_next
) {
1933 addr
= qeth_l3_get_addr_buffer(QETH_PROT_IPV6
);
1935 memcpy(&addr
->u
.a6
.addr
, &ifa
->addr
,
1936 sizeof(struct in6_addr
));
1937 addr
->u
.a6
.pfxlen
= ifa
->prefix_len
;
1938 addr
->type
= QETH_IP_TYPE_NORMAL
;
1939 if (!qeth_l3_delete_ip(card
, addr
))
1943 in6_dev_put(in6_dev
);
1944 #endif /* CONFIG_QETH_IPV6 */
1947 static void qeth_l3_free_vlan_addresses(struct qeth_card
*card
,
1952 qeth_l3_free_vlan_addresses4(card
, vid
);
1953 qeth_l3_free_vlan_addresses6(card
, vid
);
1956 static void qeth_l3_vlan_rx_register(struct net_device
*dev
,
1957 struct vlan_group
*grp
)
1959 struct qeth_card
*card
= dev
->ml_priv
;
1960 unsigned long flags
;
1962 QETH_DBF_TEXT(TRACE
, 4, "vlanreg");
1963 spin_lock_irqsave(&card
->vlanlock
, flags
);
1964 card
->vlangrp
= grp
;
1965 spin_unlock_irqrestore(&card
->vlanlock
, flags
);
1968 static void qeth_l3_vlan_rx_add_vid(struct net_device
*dev
, unsigned short vid
)
1973 static void qeth_l3_vlan_rx_kill_vid(struct net_device
*dev
, unsigned short vid
)
1975 struct qeth_card
*card
= dev
->ml_priv
;
1976 unsigned long flags
;
1978 QETH_DBF_TEXT_(TRACE
, 4, "kid:%d", vid
);
1979 if (qeth_wait_for_threads(card
, QETH_RECOVER_THREAD
)) {
1980 QETH_DBF_TEXT(TRACE
, 3, "kidREC");
1983 spin_lock_irqsave(&card
->vlanlock
, flags
);
1984 /* unregister IP addresses of vlan device */
1985 qeth_l3_free_vlan_addresses(card
, vid
);
1986 vlan_group_set_device(card
->vlangrp
, vid
, NULL
);
1987 spin_unlock_irqrestore(&card
->vlanlock
, flags
);
1988 qeth_l3_set_multicast_list(card
->dev
);
1991 static inline __u16
qeth_l3_rebuild_skb(struct qeth_card
*card
,
1992 struct sk_buff
*skb
, struct qeth_hdr
*hdr
)
1994 unsigned short vlan_id
= 0;
1996 struct iphdr
*ip_hdr
;
1997 unsigned char tg_addr
[MAX_ADDR_LEN
];
1999 if (!(hdr
->hdr
.l3
.flags
& QETH_HDR_PASSTHRU
)) {
2000 prot
= htons((hdr
->hdr
.l3
.flags
& QETH_HDR_IPV6
)? ETH_P_IPV6
:
2002 switch (hdr
->hdr
.l3
.flags
& QETH_HDR_CAST_MASK
) {
2003 case QETH_CAST_MULTICAST
:
2005 #ifdef CONFIG_QETH_IPV6
2006 case __constant_htons(ETH_P_IPV6
):
2007 ndisc_mc_map((struct in6_addr
*)
2009 tg_addr
, card
->dev
, 0);
2012 case __constant_htons(ETH_P_IP
):
2013 ip_hdr
= (struct iphdr
*)skb
->data
;
2014 (card
->dev
->type
== ARPHRD_IEEE802_TR
) ?
2015 ip_tr_mc_map(ip_hdr
->daddr
, tg_addr
):
2016 ip_eth_mc_map(ip_hdr
->daddr
, tg_addr
);
2019 memcpy(tg_addr
, card
->dev
->broadcast
,
2020 card
->dev
->addr_len
);
2022 card
->stats
.multicast
++;
2023 skb
->pkt_type
= PACKET_MULTICAST
;
2025 case QETH_CAST_BROADCAST
:
2026 memcpy(tg_addr
, card
->dev
->broadcast
,
2027 card
->dev
->addr_len
);
2028 card
->stats
.multicast
++;
2029 skb
->pkt_type
= PACKET_BROADCAST
;
2031 case QETH_CAST_UNICAST
:
2032 case QETH_CAST_ANYCAST
:
2033 case QETH_CAST_NOCAST
:
2035 if (card
->options
.sniffer
)
2036 skb
->pkt_type
= PACKET_OTHERHOST
;
2038 skb
->pkt_type
= PACKET_HOST
;
2039 memcpy(tg_addr
, card
->dev
->dev_addr
,
2040 card
->dev
->addr_len
);
2042 if (hdr
->hdr
.l3
.ext_flags
& QETH_HDR_EXT_SRC_MAC_ADDR
)
2043 card
->dev
->header_ops
->create(skb
, card
->dev
, prot
,
2044 tg_addr
, &hdr
->hdr
.l3
.dest_addr
[2],
2045 card
->dev
->addr_len
);
2047 card
->dev
->header_ops
->create(skb
, card
->dev
, prot
,
2048 tg_addr
, "FAKELL", card
->dev
->addr_len
);
2052 if (card
->dev
->type
== ARPHRD_IEEE802_TR
)
2053 skb
->protocol
= tr_type_trans(skb
, card
->dev
);
2056 skb
->protocol
= eth_type_trans(skb
, card
->dev
);
2058 if (hdr
->hdr
.l3
.ext_flags
&
2059 (QETH_HDR_EXT_VLAN_FRAME
| QETH_HDR_EXT_INCLUDE_VLAN_TAG
)) {
2060 vlan_id
= (hdr
->hdr
.l3
.ext_flags
& QETH_HDR_EXT_VLAN_FRAME
)?
2061 hdr
->hdr
.l3
.vlan_id
: *((u16
*)&hdr
->hdr
.l3
.dest_addr
[12]);
2064 switch (card
->options
.checksum_type
) {
2065 case SW_CHECKSUMMING
:
2066 skb
->ip_summed
= CHECKSUM_NONE
;
2068 case NO_CHECKSUMMING
:
2069 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
2071 case HW_CHECKSUMMING
:
2072 if ((hdr
->hdr
.l3
.ext_flags
&
2073 (QETH_HDR_EXT_CSUM_HDR_REQ
|
2074 QETH_HDR_EXT_CSUM_TRANSP_REQ
)) ==
2075 (QETH_HDR_EXT_CSUM_HDR_REQ
|
2076 QETH_HDR_EXT_CSUM_TRANSP_REQ
))
2077 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
2079 skb
->ip_summed
= CHECKSUM_NONE
;
2085 static void qeth_l3_process_inbound_buffer(struct qeth_card
*card
,
2086 struct qeth_qdio_buffer
*buf
, int index
)
2088 struct qdio_buffer_element
*element
;
2089 struct sk_buff
*skb
;
2090 struct qeth_hdr
*hdr
;
2094 /* get first element of current buffer */
2095 element
= (struct qdio_buffer_element
*)&buf
->buffer
->element
[0];
2097 if (card
->options
.performance_stats
)
2098 card
->perf_stats
.bufs_rec
++;
2099 while ((skb
= qeth_core_get_next_skb(card
, buf
->buffer
, &element
,
2101 skb
->dev
= card
->dev
;
2102 /* is device UP ? */
2103 if (!(card
->dev
->flags
& IFF_UP
)) {
2104 dev_kfree_skb_any(skb
);
2108 switch (hdr
->hdr
.l3
.id
) {
2109 case QETH_HEADER_TYPE_LAYER3
:
2110 vlan_tag
= qeth_l3_rebuild_skb(card
, skb
, hdr
);
2112 if (vlan_tag
&& !card
->options
.sniffer
)
2114 vlan_hwaccel_rx(skb
, card
->vlangrp
,
2117 dev_kfree_skb_any(skb
);
2123 case QETH_HEADER_TYPE_LAYER2
: /* for HiperSockets sniffer */
2124 skb
->pkt_type
= PACKET_HOST
;
2125 skb
->protocol
= eth_type_trans(skb
, skb
->dev
);
2126 if (card
->options
.checksum_type
== NO_CHECKSUMMING
)
2127 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
2129 skb
->ip_summed
= CHECKSUM_NONE
;
2131 netif_receive_skb(skb
);
2134 dev_kfree_skb_any(skb
);
2135 QETH_DBF_TEXT(TRACE
, 3, "inbunkno");
2136 QETH_DBF_HEX(CTRL
, 3, hdr
, QETH_DBF_CTRL_LEN
);
2140 card
->stats
.rx_packets
++;
2141 card
->stats
.rx_bytes
+= len
;
2145 static int qeth_l3_verify_vlan_dev(struct net_device
*dev
,
2146 struct qeth_card
*card
)
2149 struct vlan_group
*vg
;
2156 for (i
= 0; i
< VLAN_GROUP_ARRAY_LEN
; i
++) {
2157 if (vlan_group_get_device(vg
, i
) == dev
) {
2158 rc
= QETH_VLAN_CARD
;
2163 if (rc
&& !(vlan_dev_real_dev(dev
)->ml_priv
== (void *)card
))
2169 static int qeth_l3_verify_dev(struct net_device
*dev
)
2171 struct qeth_card
*card
;
2172 unsigned long flags
;
2175 read_lock_irqsave(&qeth_core_card_list
.rwlock
, flags
);
2176 list_for_each_entry(card
, &qeth_core_card_list
.list
, list
) {
2177 if (card
->dev
== dev
) {
2178 rc
= QETH_REAL_CARD
;
2181 rc
= qeth_l3_verify_vlan_dev(dev
, card
);
2185 read_unlock_irqrestore(&qeth_core_card_list
.rwlock
, flags
);
2190 static struct qeth_card
*qeth_l3_get_card_from_dev(struct net_device
*dev
)
2192 struct qeth_card
*card
= NULL
;
2195 rc
= qeth_l3_verify_dev(dev
);
2196 if (rc
== QETH_REAL_CARD
)
2197 card
= dev
->ml_priv
;
2198 else if (rc
== QETH_VLAN_CARD
)
2199 card
= vlan_dev_real_dev(dev
)->ml_priv
;
2200 if (card
&& card
->options
.layer2
)
2202 QETH_DBF_TEXT_(TRACE
, 4, "%d", rc
);
2206 static int qeth_l3_stop_card(struct qeth_card
*card
, int recovery_mode
)
2210 QETH_DBF_TEXT(SETUP
, 2, "stopcard");
2211 QETH_DBF_HEX(SETUP
, 2, &card
, sizeof(void *));
2213 qeth_set_allowed_threads(card
, 0, 1);
2214 if (card
->options
.sniffer
&&
2215 (card
->info
.promisc_mode
== SET_PROMISC_MODE_ON
))
2216 qeth_diags_trace(card
, QETH_DIAGS_CMD_TRACE_DISABLE
);
2217 if (card
->read
.state
== CH_STATE_UP
&&
2218 card
->write
.state
== CH_STATE_UP
&&
2219 (card
->state
== CARD_STATE_UP
)) {
2221 qeth_l3_stop(card
->dev
);
2224 dev_close(card
->dev
);
2227 if (!card
->use_hard_stop
) {
2228 rc
= qeth_send_stoplan(card
);
2230 QETH_DBF_TEXT_(SETUP
, 2, "1err%d", rc
);
2232 card
->state
= CARD_STATE_SOFTSETUP
;
2234 if (card
->state
== CARD_STATE_SOFTSETUP
) {
2235 qeth_l3_clear_ip_list(card
, !card
->use_hard_stop
, 1);
2236 qeth_clear_ipacmd_list(card
);
2237 card
->state
= CARD_STATE_HARDSETUP
;
2239 if (card
->state
== CARD_STATE_HARDSETUP
) {
2240 if (!card
->use_hard_stop
&&
2241 (card
->info
.type
!= QETH_CARD_TYPE_IQD
)) {
2242 rc
= qeth_l3_put_unique_id(card
);
2244 QETH_DBF_TEXT_(SETUP
, 2, "2err%d", rc
);
2246 qeth_qdio_clear_card(card
, 0);
2247 qeth_clear_qdio_buffers(card
);
2248 qeth_clear_working_pool_list(card
);
2249 card
->state
= CARD_STATE_DOWN
;
2251 if (card
->state
== CARD_STATE_DOWN
) {
2252 qeth_clear_cmd_buffers(&card
->read
);
2253 qeth_clear_cmd_buffers(&card
->write
);
2255 card
->use_hard_stop
= 0;
2260 * test for and Switch promiscuous mode (on or off)
2261 * either for guestlan or HiperSocket Sniffer
2264 qeth_l3_handle_promisc_mode(struct qeth_card
*card
)
2266 struct net_device
*dev
= card
->dev
;
2268 if (((dev
->flags
& IFF_PROMISC
) &&
2269 (card
->info
.promisc_mode
== SET_PROMISC_MODE_ON
)) ||
2270 (!(dev
->flags
& IFF_PROMISC
) &&
2271 (card
->info
.promisc_mode
== SET_PROMISC_MODE_OFF
)))
2274 if (card
->info
.guestlan
) { /* Guestlan trace */
2275 if (qeth_adp_supported(card
, IPA_SETADP_SET_PROMISC_MODE
))
2276 qeth_setadp_promisc_mode(card
);
2277 } else if (card
->options
.sniffer
&& /* HiperSockets trace */
2278 qeth_adp_supported(card
, IPA_SETADP_SET_DIAG_ASSIST
)) {
2279 if (dev
->flags
& IFF_PROMISC
) {
2280 QETH_DBF_TEXT(TRACE
, 3, "+promisc");
2281 qeth_diags_trace(card
, QETH_DIAGS_CMD_TRACE_ENABLE
);
2283 QETH_DBF_TEXT(TRACE
, 3, "-promisc");
2284 qeth_diags_trace(card
, QETH_DIAGS_CMD_TRACE_DISABLE
);
2289 static void qeth_l3_set_multicast_list(struct net_device
*dev
)
2291 struct qeth_card
*card
= dev
->ml_priv
;
2293 QETH_DBF_TEXT(TRACE
, 3, "setmulti");
2294 if (qeth_threads_running(card
, QETH_RECOVER_THREAD
) &&
2295 (card
->state
!= CARD_STATE_UP
))
2297 if (!card
->options
.sniffer
) {
2298 qeth_l3_delete_mc_addresses(card
);
2299 qeth_l3_add_multicast_ipv4(card
);
2300 #ifdef CONFIG_QETH_IPV6
2301 qeth_l3_add_multicast_ipv6(card
);
2303 qeth_l3_set_ip_addr_list(card
);
2304 if (!qeth_adp_supported(card
, IPA_SETADP_SET_PROMISC_MODE
))
2307 qeth_l3_handle_promisc_mode(card
);
2310 static const char *qeth_l3_arp_get_error_cause(int *rc
)
2313 case QETH_IPA_ARP_RC_FAILED
:
2315 return "operation failed";
2316 case QETH_IPA_ARP_RC_NOTSUPP
:
2318 return "operation not supported";
2319 case QETH_IPA_ARP_RC_OUT_OF_RANGE
:
2321 return "argument out of range";
2322 case QETH_IPA_ARP_RC_Q_NOTSUPP
:
2324 return "query operation not supported";
2325 case QETH_IPA_ARP_RC_Q_NO_DATA
:
2327 return "no query data available";
2329 return "unknown error";
2333 static int qeth_l3_arp_set_no_entries(struct qeth_card
*card
, int no_entries
)
2338 QETH_DBF_TEXT(TRACE
, 3, "arpstnoe");
2341 * currently GuestLAN only supports the ARP assist function
2342 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_SET_NO_ENTRIES;
2343 * thus we say EOPNOTSUPP for this ARP function
2345 if (card
->info
.guestlan
)
2347 if (!qeth_is_supported(card
, IPA_ARP_PROCESSING
)) {
2350 rc
= qeth_l3_send_simple_setassparms(card
, IPA_ARP_PROCESSING
,
2351 IPA_CMD_ASS_ARP_SET_NO_ENTRIES
,
2355 QETH_DBF_MESSAGE(2, "Could not set number of ARP entries on "
2356 "%s: %s (0x%x/%d)\n", QETH_CARD_IFNAME(card
),
2357 qeth_l3_arp_get_error_cause(&rc
), tmp
, tmp
);
2362 static void qeth_l3_copy_arp_entries_stripped(struct qeth_arp_query_info
*qinfo
,
2363 struct qeth_arp_query_data
*qdata
, int entry_size
,
2370 entry_ptr
= (char *)&qdata
->data
;
2371 uentry_ptr
= (char *)(qinfo
->udata
+ qinfo
->udata_offset
);
2372 for (i
= 0; i
< qdata
->no_entries
; ++i
) {
2373 /* strip off 32 bytes "media specific information" */
2374 memcpy(uentry_ptr
, (entry_ptr
+ 32), entry_size
- 32);
2375 entry_ptr
+= entry_size
;
2376 uentry_ptr
+= uentry_size
;
2380 static int qeth_l3_arp_query_cb(struct qeth_card
*card
,
2381 struct qeth_reply
*reply
, unsigned long data
)
2383 struct qeth_ipa_cmd
*cmd
;
2384 struct qeth_arp_query_data
*qdata
;
2385 struct qeth_arp_query_info
*qinfo
;
2390 QETH_DBF_TEXT(TRACE
, 4, "arpquecb");
2392 qinfo
= (struct qeth_arp_query_info
*) reply
->param
;
2393 cmd
= (struct qeth_ipa_cmd
*) data
;
2394 if (cmd
->hdr
.return_code
) {
2395 QETH_DBF_TEXT_(TRACE
, 4, "qaer1%i", cmd
->hdr
.return_code
);
2398 if (cmd
->data
.setassparms
.hdr
.return_code
) {
2399 cmd
->hdr
.return_code
= cmd
->data
.setassparms
.hdr
.return_code
;
2400 QETH_DBF_TEXT_(TRACE
, 4, "qaer2%i", cmd
->hdr
.return_code
);
2403 qdata
= &cmd
->data
.setassparms
.data
.query_arp
;
2404 switch (qdata
->reply_bits
) {
2406 uentry_size
= entry_size
= sizeof(struct qeth_arp_qi_entry5
);
2407 if (qinfo
->mask_bits
& QETH_QARP_STRIP_ENTRIES
)
2408 uentry_size
= sizeof(struct qeth_arp_qi_entry5_short
);
2411 /* fall through to default */
2413 /* tr is the same as eth -> entry7 */
2414 uentry_size
= entry_size
= sizeof(struct qeth_arp_qi_entry7
);
2415 if (qinfo
->mask_bits
& QETH_QARP_STRIP_ENTRIES
)
2416 uentry_size
= sizeof(struct qeth_arp_qi_entry7_short
);
2419 /* check if there is enough room in userspace */
2420 if ((qinfo
->udata_len
- qinfo
->udata_offset
) <
2421 qdata
->no_entries
* uentry_size
){
2422 QETH_DBF_TEXT_(TRACE
, 4, "qaer3%i", -ENOMEM
);
2423 cmd
->hdr
.return_code
= -ENOMEM
;
2426 QETH_DBF_TEXT_(TRACE
, 4, "anore%i",
2427 cmd
->data
.setassparms
.hdr
.number_of_replies
);
2428 QETH_DBF_TEXT_(TRACE
, 4, "aseqn%i", cmd
->data
.setassparms
.hdr
.seq_no
);
2429 QETH_DBF_TEXT_(TRACE
, 4, "anoen%i", qdata
->no_entries
);
2431 if (qinfo
->mask_bits
& QETH_QARP_STRIP_ENTRIES
) {
2432 /* strip off "media specific information" */
2433 qeth_l3_copy_arp_entries_stripped(qinfo
, qdata
, entry_size
,
2436 /*copy entries to user buffer*/
2437 memcpy(qinfo
->udata
+ qinfo
->udata_offset
,
2438 (char *)&qdata
->data
, qdata
->no_entries
*uentry_size
);
2440 qinfo
->no_entries
+= qdata
->no_entries
;
2441 qinfo
->udata_offset
+= (qdata
->no_entries
*uentry_size
);
2442 /* check if all replies received ... */
2443 if (cmd
->data
.setassparms
.hdr
.seq_no
<
2444 cmd
->data
.setassparms
.hdr
.number_of_replies
)
2446 memcpy(qinfo
->udata
, &qinfo
->no_entries
, 4);
2447 /* keep STRIP_ENTRIES flag so the user program can distinguish
2448 * stripped entries from normal ones */
2449 if (qinfo
->mask_bits
& QETH_QARP_STRIP_ENTRIES
)
2450 qdata
->reply_bits
|= QETH_QARP_STRIP_ENTRIES
;
2451 memcpy(qinfo
->udata
+ QETH_QARP_MASK_OFFSET
, &qdata
->reply_bits
, 2);
2455 memcpy(qinfo
->udata
, &i
, 4);
2459 static int qeth_l3_send_ipa_arp_cmd(struct qeth_card
*card
,
2460 struct qeth_cmd_buffer
*iob
, int len
,
2461 int (*reply_cb
)(struct qeth_card
*, struct qeth_reply
*,
2465 QETH_DBF_TEXT(TRACE
, 4, "sendarp");
2467 memcpy(iob
->data
, IPA_PDU_HEADER
, IPA_PDU_HEADER_SIZE
);
2468 memcpy(QETH_IPA_CMD_DEST_ADDR(iob
->data
),
2469 &card
->token
.ulp_connection_r
, QETH_MPC_TOKEN_LENGTH
);
2470 return qeth_send_control_data(card
, IPA_PDU_HEADER_SIZE
+ len
, iob
,
2471 reply_cb
, reply_param
);
2474 static int qeth_l3_arp_query(struct qeth_card
*card
, char __user
*udata
)
2476 struct qeth_cmd_buffer
*iob
;
2477 struct qeth_arp_query_info qinfo
= {0, };
2481 QETH_DBF_TEXT(TRACE
, 3, "arpquery");
2483 if (!qeth_is_supported(card
,/*IPA_QUERY_ARP_ADDR_INFO*/
2484 IPA_ARP_PROCESSING
)) {
2487 /* get size of userspace buffer and mask_bits -> 6 bytes */
2488 if (copy_from_user(&qinfo
, udata
, 6))
2490 qinfo
.udata
= kzalloc(qinfo
.udata_len
, GFP_KERNEL
);
2493 qinfo
.udata_offset
= QETH_QARP_ENTRIES_OFFSET
;
2494 iob
= qeth_l3_get_setassparms_cmd(card
, IPA_ARP_PROCESSING
,
2495 IPA_CMD_ASS_ARP_QUERY_INFO
,
2496 sizeof(int), QETH_PROT_IPV4
);
2498 rc
= qeth_l3_send_ipa_arp_cmd(card
, iob
,
2499 QETH_SETASS_BASE_LEN
+QETH_ARP_CMD_LEN
,
2500 qeth_l3_arp_query_cb
, (void *)&qinfo
);
2503 QETH_DBF_MESSAGE(2, "Error while querying ARP cache on %s: %s "
2504 "(0x%x/%d)\n", QETH_CARD_IFNAME(card
),
2505 qeth_l3_arp_get_error_cause(&rc
), tmp
, tmp
);
2506 if (copy_to_user(udata
, qinfo
.udata
, 4))
2509 if (copy_to_user(udata
, qinfo
.udata
, qinfo
.udata_len
))
2516 static int qeth_l3_arp_add_entry(struct qeth_card
*card
,
2517 struct qeth_arp_cache_entry
*entry
)
2519 struct qeth_cmd_buffer
*iob
;
2524 QETH_DBF_TEXT(TRACE
, 3, "arpadent");
2527 * currently GuestLAN only supports the ARP assist function
2528 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_ADD_ENTRY;
2529 * thus we say EOPNOTSUPP for this ARP function
2531 if (card
->info
.guestlan
)
2533 if (!qeth_is_supported(card
, IPA_ARP_PROCESSING
)) {
2537 iob
= qeth_l3_get_setassparms_cmd(card
, IPA_ARP_PROCESSING
,
2538 IPA_CMD_ASS_ARP_ADD_ENTRY
,
2539 sizeof(struct qeth_arp_cache_entry
),
2541 rc
= qeth_l3_send_setassparms(card
, iob
,
2542 sizeof(struct qeth_arp_cache_entry
),
2543 (unsigned long) entry
,
2544 qeth_l3_default_setassparms_cb
, NULL
);
2547 qeth_l3_ipaddr4_to_string((u8
*)entry
->ipaddr
, buf
);
2548 QETH_DBF_MESSAGE(2, "Could not add ARP entry for address %s "
2549 "on %s: %s (0x%x/%d)\n", buf
, QETH_CARD_IFNAME(card
),
2550 qeth_l3_arp_get_error_cause(&rc
), tmp
, tmp
);
2555 static int qeth_l3_arp_remove_entry(struct qeth_card
*card
,
2556 struct qeth_arp_cache_entry
*entry
)
2558 struct qeth_cmd_buffer
*iob
;
2559 char buf
[16] = {0, };
2563 QETH_DBF_TEXT(TRACE
, 3, "arprment");
2566 * currently GuestLAN only supports the ARP assist function
2567 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_REMOVE_ENTRY;
2568 * thus we say EOPNOTSUPP for this ARP function
2570 if (card
->info
.guestlan
)
2572 if (!qeth_is_supported(card
, IPA_ARP_PROCESSING
)) {
2575 memcpy(buf
, entry
, 12);
2576 iob
= qeth_l3_get_setassparms_cmd(card
, IPA_ARP_PROCESSING
,
2577 IPA_CMD_ASS_ARP_REMOVE_ENTRY
,
2580 rc
= qeth_l3_send_setassparms(card
, iob
,
2581 12, (unsigned long)buf
,
2582 qeth_l3_default_setassparms_cb
, NULL
);
2586 qeth_l3_ipaddr4_to_string((u8
*)entry
->ipaddr
, buf
);
2587 QETH_DBF_MESSAGE(2, "Could not delete ARP entry for address %s"
2588 " on %s: %s (0x%x/%d)\n", buf
, QETH_CARD_IFNAME(card
),
2589 qeth_l3_arp_get_error_cause(&rc
), tmp
, tmp
);
2594 static int qeth_l3_arp_flush_cache(struct qeth_card
*card
)
2599 QETH_DBF_TEXT(TRACE
, 3, "arpflush");
2602 * currently GuestLAN only supports the ARP assist function
2603 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_FLUSH_CACHE;
2604 * thus we say EOPNOTSUPP for this ARP function
2606 if (card
->info
.guestlan
|| (card
->info
.type
== QETH_CARD_TYPE_IQD
))
2608 if (!qeth_is_supported(card
, IPA_ARP_PROCESSING
)) {
2611 rc
= qeth_l3_send_simple_setassparms(card
, IPA_ARP_PROCESSING
,
2612 IPA_CMD_ASS_ARP_FLUSH_CACHE
, 0);
2615 QETH_DBF_MESSAGE(2, "Could not flush ARP cache on %s: %s "
2616 "(0x%x/%d)\n", QETH_CARD_IFNAME(card
),
2617 qeth_l3_arp_get_error_cause(&rc
), tmp
, tmp
);
2622 static int qeth_l3_do_ioctl(struct net_device
*dev
, struct ifreq
*rq
, int cmd
)
2624 struct qeth_card
*card
= dev
->ml_priv
;
2625 struct qeth_arp_cache_entry arp_entry
;
2626 struct mii_ioctl_data
*mii_data
;
2632 if ((card
->state
!= CARD_STATE_UP
) &&
2633 (card
->state
!= CARD_STATE_SOFTSETUP
))
2637 case SIOC_QETH_ARP_SET_NO_ENTRIES
:
2638 if (!capable(CAP_NET_ADMIN
)) {
2642 rc
= qeth_l3_arp_set_no_entries(card
, rq
->ifr_ifru
.ifru_ivalue
);
2644 case SIOC_QETH_ARP_QUERY_INFO
:
2645 if (!capable(CAP_NET_ADMIN
)) {
2649 rc
= qeth_l3_arp_query(card
, rq
->ifr_ifru
.ifru_data
);
2651 case SIOC_QETH_ARP_ADD_ENTRY
:
2652 if (!capable(CAP_NET_ADMIN
)) {
2656 if (copy_from_user(&arp_entry
, rq
->ifr_ifru
.ifru_data
,
2657 sizeof(struct qeth_arp_cache_entry
)))
2660 rc
= qeth_l3_arp_add_entry(card
, &arp_entry
);
2662 case SIOC_QETH_ARP_REMOVE_ENTRY
:
2663 if (!capable(CAP_NET_ADMIN
)) {
2667 if (copy_from_user(&arp_entry
, rq
->ifr_ifru
.ifru_data
,
2668 sizeof(struct qeth_arp_cache_entry
)))
2671 rc
= qeth_l3_arp_remove_entry(card
, &arp_entry
);
2673 case SIOC_QETH_ARP_FLUSH_CACHE
:
2674 if (!capable(CAP_NET_ADMIN
)) {
2678 rc
= qeth_l3_arp_flush_cache(card
);
2680 case SIOC_QETH_ADP_SET_SNMP_CONTROL
:
2681 rc
= qeth_snmp_command(card
, rq
->ifr_ifru
.ifru_data
);
2683 case SIOC_QETH_GET_CARD_TYPE
:
2684 if ((card
->info
.type
== QETH_CARD_TYPE_OSAE
) &&
2685 !card
->info
.guestlan
)
2690 mii_data
= if_mii(rq
);
2691 mii_data
->phy_id
= 0;
2694 mii_data
= if_mii(rq
);
2695 if (mii_data
->phy_id
!= 0)
2698 mii_data
->val_out
= qeth_mdio_read(dev
,
2706 QETH_DBF_TEXT_(TRACE
, 2, "ioce%d", rc
);
2710 int inline qeth_l3_get_cast_type(struct qeth_card
*card
, struct sk_buff
*skb
)
2712 int cast_type
= RTN_UNSPEC
;
2714 if (skb_dst(skb
) && skb_dst(skb
)->neighbour
) {
2715 cast_type
= skb_dst(skb
)->neighbour
->type
;
2716 if ((cast_type
== RTN_BROADCAST
) ||
2717 (cast_type
== RTN_MULTICAST
) ||
2718 (cast_type
== RTN_ANYCAST
))
2723 /* try something else */
2724 if (skb
->protocol
== ETH_P_IPV6
)
2725 return (skb_network_header(skb
)[24] == 0xff) ?
2727 else if (skb
->protocol
== ETH_P_IP
)
2728 return ((skb_network_header(skb
)[16] & 0xf0) == 0xe0) ?
2731 if (!memcmp(skb
->data
, skb
->dev
->broadcast
, 6))
2732 return RTN_BROADCAST
;
2736 hdr_mac
= *((u16
*)skb
->data
);
2738 switch (card
->info
.link_type
) {
2739 case QETH_LINK_TYPE_HSTR
:
2740 case QETH_LINK_TYPE_LANE_TR
:
2741 if ((hdr_mac
== QETH_TR_MAC_NC
) ||
2742 (hdr_mac
== QETH_TR_MAC_C
))
2743 return RTN_MULTICAST
;
2745 /* eth or so multicast? */
2747 if ((hdr_mac
== QETH_ETH_MAC_V4
) ||
2748 (hdr_mac
== QETH_ETH_MAC_V6
))
2749 return RTN_MULTICAST
;
2755 static void qeth_l3_fill_header(struct qeth_card
*card
, struct qeth_hdr
*hdr
,
2756 struct sk_buff
*skb
, int ipv
, int cast_type
)
2758 memset(hdr
, 0, sizeof(struct qeth_hdr
));
2759 hdr
->hdr
.l3
.id
= QETH_HEADER_TYPE_LAYER3
;
2760 hdr
->hdr
.l3
.ext_flags
= 0;
2763 * before we're going to overwrite this location with next hop ip.
2764 * v6 uses passthrough, v4 sets the tag in the QDIO header.
2766 if (card
->vlangrp
&& vlan_tx_tag_present(skb
)) {
2767 if ((ipv
== 4) || (card
->info
.type
== QETH_CARD_TYPE_IQD
))
2768 hdr
->hdr
.l3
.ext_flags
= QETH_HDR_EXT_VLAN_FRAME
;
2770 hdr
->hdr
.l3
.ext_flags
= QETH_HDR_EXT_INCLUDE_VLAN_TAG
;
2771 hdr
->hdr
.l3
.vlan_id
= vlan_tx_tag_get(skb
);
2774 hdr
->hdr
.l3
.length
= skb
->len
- sizeof(struct qeth_hdr
);
2777 hdr
->hdr
.l3
.flags
= qeth_l3_get_qeth_hdr_flags4(cast_type
);
2778 memset(hdr
->hdr
.l3
.dest_addr
, 0, 12);
2779 if ((skb_dst(skb
)) && (skb_dst(skb
)->neighbour
)) {
2780 *((u32
*) (&hdr
->hdr
.l3
.dest_addr
[12])) =
2781 *((u32
*) skb_dst(skb
)->neighbour
->primary_key
);
2783 /* fill in destination address used in ip header */
2784 *((u32
*) (&hdr
->hdr
.l3
.dest_addr
[12])) =
2787 } else if (ipv
== 6) {
2789 hdr
->hdr
.l3
.flags
= qeth_l3_get_qeth_hdr_flags6(cast_type
);
2790 if (card
->info
.type
== QETH_CARD_TYPE_IQD
)
2791 hdr
->hdr
.l3
.flags
&= ~QETH_HDR_PASSTHRU
;
2792 if ((skb_dst(skb
)) && (skb_dst(skb
)->neighbour
)) {
2793 memcpy(hdr
->hdr
.l3
.dest_addr
,
2794 skb_dst(skb
)->neighbour
->primary_key
, 16);
2796 /* fill in destination address used in ip header */
2797 memcpy(hdr
->hdr
.l3
.dest_addr
,
2798 &ipv6_hdr(skb
)->daddr
, 16);
2802 if ((skb
->dev
->type
== ARPHRD_IEEE802_TR
) &&
2803 !memcmp(skb
->data
+ sizeof(struct qeth_hdr
) +
2804 sizeof(__u16
), skb
->dev
->broadcast
, 6)) {
2805 hdr
->hdr
.l3
.flags
= QETH_CAST_BROADCAST
|
2807 } else if (!memcmp(skb
->data
+ sizeof(struct qeth_hdr
),
2808 skb
->dev
->broadcast
, 6)) {
2810 hdr
->hdr
.l3
.flags
= QETH_CAST_BROADCAST
|
2813 hdr
->hdr
.l3
.flags
= (cast_type
== RTN_MULTICAST
) ?
2814 QETH_CAST_MULTICAST
| QETH_HDR_PASSTHRU
:
2815 QETH_CAST_UNICAST
| QETH_HDR_PASSTHRU
;
2820 static void qeth_tso_fill_header(struct qeth_card
*card
,
2821 struct qeth_hdr
*qhdr
, struct sk_buff
*skb
)
2823 struct qeth_hdr_tso
*hdr
= (struct qeth_hdr_tso
*)qhdr
;
2824 struct tcphdr
*tcph
= tcp_hdr(skb
);
2825 struct iphdr
*iph
= ip_hdr(skb
);
2826 struct ipv6hdr
*ip6h
= ipv6_hdr(skb
);
2828 /*fix header to TSO values ...*/
2829 hdr
->hdr
.hdr
.l3
.id
= QETH_HEADER_TYPE_TSO
;
2830 /*set values which are fix for the first approach ...*/
2831 hdr
->ext
.hdr_tot_len
= (__u16
) sizeof(struct qeth_hdr_ext_tso
);
2832 hdr
->ext
.imb_hdr_no
= 1;
2833 hdr
->ext
.hdr_type
= 1;
2834 hdr
->ext
.hdr_version
= 1;
2835 hdr
->ext
.hdr_len
= 28;
2836 /*insert non-fix values */
2837 hdr
->ext
.mss
= skb_shinfo(skb
)->gso_size
;
2838 hdr
->ext
.dg_hdr_len
= (__u16
)(iph
->ihl
*4 + tcph
->doff
*4);
2839 hdr
->ext
.payload_len
= (__u16
)(skb
->len
- hdr
->ext
.dg_hdr_len
-
2840 sizeof(struct qeth_hdr_tso
));
2842 if (skb
->protocol
== ETH_P_IPV6
) {
2843 ip6h
->payload_len
= 0;
2844 tcph
->check
= ~csum_ipv6_magic(&ip6h
->saddr
, &ip6h
->daddr
,
2847 /*OSA want us to set these values ...*/
2848 tcph
->check
= ~csum_tcpudp_magic(iph
->saddr
, iph
->daddr
,
2855 static void qeth_tx_csum(struct sk_buff
*skb
)
2860 skb_set_transport_header(skb
, skb
->csum_start
- skb_headroom(skb
));
2861 offset
= skb
->csum_start
- skb_headroom(skb
);
2862 BUG_ON(offset
>= skb_headlen(skb
));
2863 csum
= skb_checksum(skb
, offset
, skb
->len
- offset
, 0);
2865 offset
+= skb
->csum_offset
;
2866 BUG_ON(offset
+ sizeof(__sum16
) > skb_headlen(skb
));
2867 *(__sum16
*)(skb
->data
+ offset
) = csum_fold(csum
);
2870 static inline int qeth_l3_tso_elements(struct sk_buff
*skb
)
2872 unsigned long tcpd
= (unsigned long)tcp_hdr(skb
) +
2873 tcp_hdr(skb
)->doff
* 4;
2874 int tcpd_len
= skb
->len
- (tcpd
- (unsigned long)skb
->data
);
2875 int elements
= PFN_UP(tcpd
+ tcpd_len
) - PFN_DOWN(tcpd
);
2876 elements
+= skb_shinfo(skb
)->nr_frags
;
2880 static inline int qeth_l3_tso_check(struct sk_buff
*skb
)
2882 int len
= ((unsigned long)tcp_hdr(skb
) + tcp_hdr(skb
)->doff
* 4) -
2883 (unsigned long)skb
->data
;
2884 return (((unsigned long)skb
->data
& PAGE_MASK
) !=
2885 (((unsigned long)skb
->data
+ len
) & PAGE_MASK
));
2888 static int qeth_l3_hard_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
2892 struct qeth_hdr
*hdr
= NULL
;
2893 int elements_needed
= 0;
2895 struct qeth_card
*card
= dev
->ml_priv
;
2896 struct sk_buff
*new_skb
= NULL
;
2897 int ipv
= qeth_get_ip_version(skb
);
2898 int cast_type
= qeth_l3_get_cast_type(card
, skb
);
2899 struct qeth_qdio_out_q
*queue
= card
->qdio
.out_qs
2900 [qeth_get_priority_queue(card
, skb
, ipv
, cast_type
)];
2901 int tx_bytes
= skb
->len
;
2902 enum qeth_large_send_types large_send
= QETH_LARGE_SEND_NO
;
2903 int data_offset
= -1;
2906 if (((card
->info
.type
== QETH_CARD_TYPE_IQD
) && (!ipv
)) ||
2907 card
->options
.sniffer
)
2910 if ((card
->state
!= CARD_STATE_UP
) || !card
->lan_online
) {
2911 card
->stats
.tx_carrier_errors
++;
2915 if ((cast_type
== RTN_BROADCAST
) &&
2916 (card
->info
.broadcast_capable
== 0))
2919 if (card
->options
.performance_stats
) {
2920 card
->perf_stats
.outbound_cnt
++;
2921 card
->perf_stats
.outbound_start_time
= qeth_get_micros();
2924 if (skb_is_gso(skb
))
2925 large_send
= card
->options
.large_send
;
2927 if (skb
->ip_summed
== CHECKSUM_PARTIAL
) {
2929 if (card
->options
.performance_stats
)
2930 card
->perf_stats
.tx_csum
++;
2933 if ((card
->info
.type
== QETH_CARD_TYPE_IQD
) && (!large_send
) &&
2934 (skb_shinfo(skb
)->nr_frags
== 0)) {
2936 data_offset
= ETH_HLEN
;
2937 hdr
= kmem_cache_alloc(qeth_core_header_cache
, GFP_ATOMIC
);
2942 /* create a clone with writeable headroom */
2943 new_skb
= skb_realloc_headroom(skb
, sizeof(struct qeth_hdr_tso
)
2949 if (card
->info
.type
== QETH_CARD_TYPE_IQD
) {
2950 if (data_offset
< 0)
2951 skb_pull(new_skb
, ETH_HLEN
);
2954 if (card
->dev
->type
== ARPHRD_IEEE802_TR
)
2955 skb_pull(new_skb
, TR_HLEN
);
2957 skb_pull(new_skb
, ETH_HLEN
);
2960 if (ipv
== 6 && card
->vlangrp
&&
2961 vlan_tx_tag_present(new_skb
)) {
2962 skb_push(new_skb
, VLAN_HLEN
);
2963 skb_copy_to_linear_data(new_skb
, new_skb
->data
+ 4, 4);
2964 skb_copy_to_linear_data_offset(new_skb
, 4,
2965 new_skb
->data
+ 8, 4);
2966 skb_copy_to_linear_data_offset(new_skb
, 8,
2967 new_skb
->data
+ 12, 4);
2968 tag
= (u16
*)(new_skb
->data
+ 12);
2969 *tag
= __constant_htons(ETH_P_8021Q
);
2970 *(tag
+ 1) = htons(vlan_tx_tag_get(new_skb
));
2971 new_skb
->vlan_tci
= 0;
2975 netif_stop_queue(dev
);
2977 /* fix hardware limitation: as long as we do not have sbal
2978 * chaining we can not send long frag lists
2980 if (large_send
== QETH_LARGE_SEND_TSO
) {
2981 if (qeth_l3_tso_elements(new_skb
) + 1 > 16) {
2982 if (skb_linearize(new_skb
))
2984 if (card
->options
.performance_stats
)
2985 card
->perf_stats
.tx_lin
++;
2989 if ((large_send
== QETH_LARGE_SEND_TSO
) &&
2990 (cast_type
== RTN_UNSPEC
)) {
2991 hdr
= (struct qeth_hdr
*)skb_push(new_skb
,
2992 sizeof(struct qeth_hdr_tso
));
2993 if (qeth_l3_tso_check(new_skb
))
2994 QETH_DBF_MESSAGE(2, "tso skb misaligned\n");
2995 memset(hdr
, 0, sizeof(struct qeth_hdr_tso
));
2996 qeth_l3_fill_header(card
, hdr
, new_skb
, ipv
, cast_type
);
2997 qeth_tso_fill_header(card
, hdr
, new_skb
);
3000 if (data_offset
< 0) {
3001 hdr
= (struct qeth_hdr
*)skb_push(new_skb
,
3002 sizeof(struct qeth_hdr
));
3003 qeth_l3_fill_header(card
, hdr
, new_skb
, ipv
,
3006 qeth_l3_fill_header(card
, hdr
, new_skb
, ipv
,
3008 hdr
->hdr
.l3
.length
= new_skb
->len
- data_offset
;
3012 elems
= qeth_get_elements_no(card
, (void *)hdr
, new_skb
,
3015 if (data_offset
>= 0)
3016 kmem_cache_free(qeth_core_header_cache
, hdr
);
3019 elements_needed
+= elems
;
3020 nr_frags
= skb_shinfo(new_skb
)->nr_frags
;
3022 if (card
->info
.type
!= QETH_CARD_TYPE_IQD
)
3023 rc
= qeth_do_send_packet(card
, queue
, new_skb
, hdr
,
3026 rc
= qeth_do_send_packet_fast(card
, queue
, new_skb
, hdr
,
3027 elements_needed
, data_offset
, 0);
3030 card
->stats
.tx_packets
++;
3031 card
->stats
.tx_bytes
+= tx_bytes
;
3033 dev_kfree_skb_any(skb
);
3034 if (card
->options
.performance_stats
) {
3035 if (large_send
!= QETH_LARGE_SEND_NO
) {
3036 card
->perf_stats
.large_send_bytes
+= tx_bytes
;
3037 card
->perf_stats
.large_send_cnt
++;
3040 card
->perf_stats
.sg_skbs_sent
++;
3041 /* nr_frags + skb->data */
3042 card
->perf_stats
.sg_frags_sent
+= nr_frags
+ 1;
3047 if (data_offset
>= 0)
3048 kmem_cache_free(qeth_core_header_cache
, hdr
);
3052 dev_kfree_skb_any(new_skb
);
3053 return NETDEV_TX_BUSY
;
3058 netif_wake_queue(dev
);
3059 if (card
->options
.performance_stats
)
3060 card
->perf_stats
.outbound_time
+= qeth_get_micros() -
3061 card
->perf_stats
.outbound_start_time
;
3065 card
->stats
.tx_dropped
++;
3066 card
->stats
.tx_errors
++;
3067 if ((new_skb
!= skb
) && new_skb
)
3068 dev_kfree_skb_any(new_skb
);
3069 dev_kfree_skb_any(skb
);
3070 netif_wake_queue(dev
);
3071 return NETDEV_TX_OK
;
3074 static int qeth_l3_open(struct net_device
*dev
)
3076 struct qeth_card
*card
= dev
->ml_priv
;
3078 QETH_DBF_TEXT(TRACE
, 4, "qethopen");
3079 if (card
->state
!= CARD_STATE_SOFTSETUP
)
3081 card
->data
.state
= CH_STATE_UP
;
3082 card
->state
= CARD_STATE_UP
;
3083 netif_start_queue(dev
);
3085 if (!card
->lan_online
&& netif_carrier_ok(dev
))
3086 netif_carrier_off(dev
);
3090 static int qeth_l3_stop(struct net_device
*dev
)
3092 struct qeth_card
*card
= dev
->ml_priv
;
3094 QETH_DBF_TEXT(TRACE
, 4, "qethstop");
3095 netif_tx_disable(dev
);
3096 if (card
->state
== CARD_STATE_UP
)
3097 card
->state
= CARD_STATE_SOFTSETUP
;
3101 static u32
qeth_l3_ethtool_get_rx_csum(struct net_device
*dev
)
3103 struct qeth_card
*card
= dev
->ml_priv
;
3105 return (card
->options
.checksum_type
== HW_CHECKSUMMING
);
3108 static int qeth_l3_ethtool_set_rx_csum(struct net_device
*dev
, u32 data
)
3110 struct qeth_card
*card
= dev
->ml_priv
;
3111 enum qeth_checksum_types csum_type
;
3114 csum_type
= HW_CHECKSUMMING
;
3116 csum_type
= SW_CHECKSUMMING
;
3118 return qeth_l3_set_rx_csum(card
, csum_type
);
3121 static int qeth_l3_ethtool_set_tso(struct net_device
*dev
, u32 data
)
3123 struct qeth_card
*card
= dev
->ml_priv
;
3127 rc
= qeth_l3_set_large_send(card
, QETH_LARGE_SEND_TSO
);
3129 dev
->features
&= ~NETIF_F_TSO
;
3130 card
->options
.large_send
= QETH_LARGE_SEND_NO
;
3135 static const struct ethtool_ops qeth_l3_ethtool_ops
= {
3136 .get_link
= ethtool_op_get_link
,
3137 .get_tx_csum
= ethtool_op_get_tx_csum
,
3138 .set_tx_csum
= ethtool_op_set_tx_hw_csum
,
3139 .get_rx_csum
= qeth_l3_ethtool_get_rx_csum
,
3140 .set_rx_csum
= qeth_l3_ethtool_set_rx_csum
,
3141 .get_sg
= ethtool_op_get_sg
,
3142 .set_sg
= ethtool_op_set_sg
,
3143 .get_tso
= ethtool_op_get_tso
,
3144 .set_tso
= qeth_l3_ethtool_set_tso
,
3145 .get_strings
= qeth_core_get_strings
,
3146 .get_ethtool_stats
= qeth_core_get_ethtool_stats
,
3147 .get_sset_count
= qeth_core_get_sset_count
,
3148 .get_drvinfo
= qeth_core_get_drvinfo
,
3149 .get_settings
= qeth_core_ethtool_get_settings
,
3153 * we need NOARP for IPv4 but we want neighbor solicitation for IPv6. Setting
3154 * NOARP on the netdevice is no option because it also turns off neighbor
3155 * solicitation. For IPv4 we install a neighbor_setup function. We don't want
3156 * arp resolution but we want the hard header (packet socket will work
3159 static int qeth_l3_neigh_setup_noarp(struct neighbour
*n
)
3161 n
->nud_state
= NUD_NOARP
;
3162 memcpy(n
->ha
, "FAKELL", 6);
3163 n
->output
= n
->ops
->connected_output
;
3168 qeth_l3_neigh_setup(struct net_device
*dev
, struct neigh_parms
*np
)
3170 if (np
->tbl
->family
== AF_INET
)
3171 np
->neigh_setup
= qeth_l3_neigh_setup_noarp
;
3176 static const struct net_device_ops qeth_l3_netdev_ops
= {
3177 .ndo_open
= qeth_l3_open
,
3178 .ndo_stop
= qeth_l3_stop
,
3179 .ndo_get_stats
= qeth_get_stats
,
3180 .ndo_start_xmit
= qeth_l3_hard_start_xmit
,
3181 .ndo_validate_addr
= eth_validate_addr
,
3182 .ndo_set_multicast_list
= qeth_l3_set_multicast_list
,
3183 .ndo_do_ioctl
= qeth_l3_do_ioctl
,
3184 .ndo_change_mtu
= qeth_change_mtu
,
3185 .ndo_vlan_rx_register
= qeth_l3_vlan_rx_register
,
3186 .ndo_vlan_rx_add_vid
= qeth_l3_vlan_rx_add_vid
,
3187 .ndo_vlan_rx_kill_vid
= qeth_l3_vlan_rx_kill_vid
,
3188 .ndo_tx_timeout
= qeth_tx_timeout
,
3191 static const struct net_device_ops qeth_l3_osa_netdev_ops
= {
3192 .ndo_open
= qeth_l3_open
,
3193 .ndo_stop
= qeth_l3_stop
,
3194 .ndo_get_stats
= qeth_get_stats
,
3195 .ndo_start_xmit
= qeth_l3_hard_start_xmit
,
3196 .ndo_validate_addr
= eth_validate_addr
,
3197 .ndo_set_multicast_list
= qeth_l3_set_multicast_list
,
3198 .ndo_do_ioctl
= qeth_l3_do_ioctl
,
3199 .ndo_change_mtu
= qeth_change_mtu
,
3200 .ndo_vlan_rx_register
= qeth_l3_vlan_rx_register
,
3201 .ndo_vlan_rx_add_vid
= qeth_l3_vlan_rx_add_vid
,
3202 .ndo_vlan_rx_kill_vid
= qeth_l3_vlan_rx_kill_vid
,
3203 .ndo_tx_timeout
= qeth_tx_timeout
,
3204 .ndo_neigh_setup
= qeth_l3_neigh_setup
,
3207 static int qeth_l3_setup_netdev(struct qeth_card
*card
)
3209 if (card
->info
.type
== QETH_CARD_TYPE_OSAE
) {
3210 if ((card
->info
.link_type
== QETH_LINK_TYPE_LANE_TR
) ||
3211 (card
->info
.link_type
== QETH_LINK_TYPE_HSTR
)) {
3213 card
->dev
= alloc_trdev(0);
3217 card
->dev
->netdev_ops
= &qeth_l3_netdev_ops
;
3219 card
->dev
= alloc_etherdev(0);
3222 card
->dev
->netdev_ops
= &qeth_l3_osa_netdev_ops
;
3224 /*IPv6 address autoconfiguration stuff*/
3225 qeth_l3_get_unique_id(card
);
3226 if (!(card
->info
.unique_id
& UNIQUE_ID_NOT_BY_CARD
))
3227 card
->dev
->dev_id
= card
->info
.unique_id
&
3230 } else if (card
->info
.type
== QETH_CARD_TYPE_IQD
) {
3231 card
->dev
= alloc_netdev(0, "hsi%d", ether_setup
);
3234 card
->dev
->flags
|= IFF_NOARP
;
3235 card
->dev
->netdev_ops
= &qeth_l3_netdev_ops
;
3236 qeth_l3_iqd_read_initial_mac(card
);
3240 card
->dev
->ml_priv
= card
;
3241 card
->dev
->watchdog_timeo
= QETH_TX_TIMEOUT
;
3242 card
->dev
->mtu
= card
->info
.initial_mtu
;
3243 SET_ETHTOOL_OPS(card
->dev
, &qeth_l3_ethtool_ops
);
3244 card
->dev
->features
|= NETIF_F_HW_VLAN_TX
|
3245 NETIF_F_HW_VLAN_RX
|
3246 NETIF_F_HW_VLAN_FILTER
;
3247 card
->dev
->priv_flags
&= ~IFF_XMIT_DST_RELEASE
;
3248 card
->dev
->gso_max_size
= 15 * PAGE_SIZE
;
3250 SET_NETDEV_DEV(card
->dev
, &card
->gdev
->dev
);
3251 return register_netdev(card
->dev
);
3254 static void qeth_l3_qdio_input_handler(struct ccw_device
*ccwdev
,
3255 unsigned int qdio_err
, unsigned int queue
, int first_element
,
3256 int count
, unsigned long card_ptr
)
3258 struct net_device
*net_dev
;
3259 struct qeth_card
*card
;
3260 struct qeth_qdio_buffer
*buffer
;
3264 card
= (struct qeth_card
*) card_ptr
;
3265 net_dev
= card
->dev
;
3266 if (card
->options
.performance_stats
) {
3267 card
->perf_stats
.inbound_cnt
++;
3268 card
->perf_stats
.inbound_start_time
= qeth_get_micros();
3270 if (qdio_err
& QDIO_ERROR_ACTIVATE_CHECK_CONDITION
) {
3271 QETH_DBF_TEXT(TRACE
, 1, "qdinchk");
3272 QETH_DBF_TEXT_(TRACE
, 1, "%s", CARD_BUS_ID(card
));
3273 QETH_DBF_TEXT_(TRACE
, 1, "%04X%04X",
3274 first_element
, count
);
3275 QETH_DBF_TEXT_(TRACE
, 1, "%04X", queue
);
3276 qeth_schedule_recovery(card
);
3279 for (i
= first_element
; i
< (first_element
+ count
); ++i
) {
3280 index
= i
% QDIO_MAX_BUFFERS_PER_Q
;
3281 buffer
= &card
->qdio
.in_q
->bufs
[index
];
3283 qeth_check_qdio_errors(card
, buffer
->buffer
,
3284 qdio_err
, "qinerr")))
3285 qeth_l3_process_inbound_buffer(card
, buffer
, index
);
3286 /* clear buffer and give back to hardware */
3287 qeth_put_buffer_pool_entry(card
, buffer
->pool_entry
);
3288 qeth_queue_input_buffer(card
, index
);
3290 if (card
->options
.performance_stats
)
3291 card
->perf_stats
.inbound_time
+= qeth_get_micros() -
3292 card
->perf_stats
.inbound_start_time
;
3295 static int qeth_l3_probe_device(struct ccwgroup_device
*gdev
)
3297 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
3299 qeth_l3_create_device_attributes(&gdev
->dev
);
3300 card
->options
.layer2
= 0;
3301 card
->discipline
.input_handler
= (qdio_handler_t
*)
3302 qeth_l3_qdio_input_handler
;
3303 card
->discipline
.output_handler
= (qdio_handler_t
*)
3304 qeth_qdio_output_handler
;
3305 card
->discipline
.recover
= qeth_l3_recover
;
3309 static void qeth_l3_remove_device(struct ccwgroup_device
*cgdev
)
3311 struct qeth_card
*card
= dev_get_drvdata(&cgdev
->dev
);
3313 qeth_set_allowed_threads(card
, 0, 1);
3314 wait_event(card
->wait_q
, qeth_threads_running(card
, 0xffffffff) == 0);
3316 if (cgdev
->state
== CCWGROUP_ONLINE
) {
3317 card
->use_hard_stop
= 1;
3318 qeth_l3_set_offline(cgdev
);
3322 unregister_netdev(card
->dev
);
3326 qeth_l3_remove_device_attributes(&cgdev
->dev
);
3327 qeth_l3_clear_ip_list(card
, 0, 0);
3328 qeth_l3_clear_ipato_list(card
);
3332 static int __qeth_l3_set_online(struct ccwgroup_device
*gdev
, int recovery_mode
)
3334 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
3336 enum qeth_card_states recover_flag
;
3339 QETH_DBF_TEXT(SETUP
, 2, "setonlin");
3340 QETH_DBF_HEX(SETUP
, 2, &card
, sizeof(void *));
3342 recover_flag
= card
->state
;
3343 rc
= qeth_core_hardsetup_card(card
);
3345 QETH_DBF_TEXT_(SETUP
, 2, "2err%d", rc
);
3350 qeth_l3_query_ipassists(card
, QETH_PROT_IPV4
);
3352 if (!card
->dev
&& qeth_l3_setup_netdev(card
)) {
3357 card
->state
= CARD_STATE_HARDSETUP
;
3358 qeth_print_status_message(card
);
3361 QETH_DBF_TEXT(SETUP
, 2, "softsetp");
3363 rc
= qeth_send_startlan(card
);
3365 QETH_DBF_TEXT_(SETUP
, 2, "1err%d", rc
);
3367 dev_warn(&card
->gdev
->dev
,
3368 "The LAN is offline\n");
3369 card
->lan_online
= 0;
3375 card
->lan_online
= 1;
3377 rc
= qeth_l3_setadapter_parms(card
);
3379 QETH_DBF_TEXT_(SETUP
, 2, "2err%d", rc
);
3380 if (!card
->options
.sniffer
) {
3381 rc
= qeth_l3_start_ipassists(card
);
3383 QETH_DBF_TEXT_(SETUP
, 2, "3err%d", rc
);
3384 qeth_l3_set_large_send(card
, card
->options
.large_send
);
3385 rc
= qeth_l3_setrouting_v4(card
);
3387 QETH_DBF_TEXT_(SETUP
, 2, "4err%d", rc
);
3388 rc
= qeth_l3_setrouting_v6(card
);
3390 QETH_DBF_TEXT_(SETUP
, 2, "5err%d", rc
);
3392 netif_tx_disable(card
->dev
);
3394 rc
= qeth_init_qdio_queues(card
);
3396 QETH_DBF_TEXT_(SETUP
, 2, "6err%d", rc
);
3400 card
->state
= CARD_STATE_SOFTSETUP
;
3401 netif_carrier_on(card
->dev
);
3403 qeth_set_allowed_threads(card
, 0xffffffff, 0);
3404 qeth_l3_set_ip_addr_list(card
);
3405 if (recover_flag
== CARD_STATE_RECOVER
) {
3407 qeth_l3_open(card
->dev
);
3410 dev_open(card
->dev
);
3413 qeth_l3_set_multicast_list(card
->dev
);
3415 /* let user_space know that device is online */
3416 kobject_uevent(&gdev
->dev
.kobj
, KOBJ_CHANGE
);
3419 card
->use_hard_stop
= 1;
3420 qeth_l3_stop_card(card
, 0);
3421 ccw_device_set_offline(CARD_DDEV(card
));
3422 ccw_device_set_offline(CARD_WDEV(card
));
3423 ccw_device_set_offline(CARD_RDEV(card
));
3424 if (recover_flag
== CARD_STATE_RECOVER
)
3425 card
->state
= CARD_STATE_RECOVER
;
3427 card
->state
= CARD_STATE_DOWN
;
3431 static int qeth_l3_set_online(struct ccwgroup_device
*gdev
)
3433 return __qeth_l3_set_online(gdev
, 0);
3436 static int __qeth_l3_set_offline(struct ccwgroup_device
*cgdev
,
3439 struct qeth_card
*card
= dev_get_drvdata(&cgdev
->dev
);
3440 int rc
= 0, rc2
= 0, rc3
= 0;
3441 enum qeth_card_states recover_flag
;
3443 QETH_DBF_TEXT(SETUP
, 3, "setoffl");
3444 QETH_DBF_HEX(SETUP
, 3, &card
, sizeof(void *));
3446 if (card
->dev
&& netif_carrier_ok(card
->dev
))
3447 netif_carrier_off(card
->dev
);
3448 recover_flag
= card
->state
;
3449 qeth_l3_stop_card(card
, recovery_mode
);
3450 rc
= ccw_device_set_offline(CARD_DDEV(card
));
3451 rc2
= ccw_device_set_offline(CARD_WDEV(card
));
3452 rc3
= ccw_device_set_offline(CARD_RDEV(card
));
3454 rc
= (rc2
) ? rc2
: rc3
;
3456 QETH_DBF_TEXT_(SETUP
, 2, "1err%d", rc
);
3457 if (recover_flag
== CARD_STATE_UP
)
3458 card
->state
= CARD_STATE_RECOVER
;
3459 /* let user_space know that device is offline */
3460 kobject_uevent(&cgdev
->dev
.kobj
, KOBJ_CHANGE
);
3464 static int qeth_l3_set_offline(struct ccwgroup_device
*cgdev
)
3466 return __qeth_l3_set_offline(cgdev
, 0);
3469 static int qeth_l3_recover(void *ptr
)
3471 struct qeth_card
*card
;
3474 card
= (struct qeth_card
*) ptr
;
3475 QETH_DBF_TEXT(TRACE
, 2, "recover1");
3476 QETH_DBF_HEX(TRACE
, 2, &card
, sizeof(void *));
3477 if (!qeth_do_run_thread(card
, QETH_RECOVER_THREAD
))
3479 QETH_DBF_TEXT(TRACE
, 2, "recover2");
3480 dev_warn(&card
->gdev
->dev
,
3481 "A recovery process has been started for the device\n");
3482 card
->use_hard_stop
= 1;
3483 __qeth_l3_set_offline(card
->gdev
, 1);
3484 rc
= __qeth_l3_set_online(card
->gdev
, 1);
3485 /* don't run another scheduled recovery */
3486 qeth_clear_thread_start_bit(card
, QETH_RECOVER_THREAD
);
3487 qeth_clear_thread_running_bit(card
, QETH_RECOVER_THREAD
);
3489 dev_info(&card
->gdev
->dev
,
3490 "Device successfully recovered!\n");
3493 dev_close(card
->dev
);
3495 dev_warn(&card
->gdev
->dev
, "The qeth device driver "
3496 "failed to recover an error on the device\n");
3501 static void qeth_l3_shutdown(struct ccwgroup_device
*gdev
)
3503 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
3504 qeth_l3_clear_ip_list(card
, 0, 0);
3505 qeth_qdio_clear_card(card
, 0);
3506 qeth_clear_qdio_buffers(card
);
3509 static int qeth_l3_pm_suspend(struct ccwgroup_device
*gdev
)
3511 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
3514 netif_device_detach(card
->dev
);
3515 qeth_set_allowed_threads(card
, 0, 1);
3516 wait_event(card
->wait_q
, qeth_threads_running(card
, 0xffffffff) == 0);
3517 if (gdev
->state
== CCWGROUP_OFFLINE
)
3519 if (card
->state
== CARD_STATE_UP
) {
3520 card
->use_hard_stop
= 1;
3521 __qeth_l3_set_offline(card
->gdev
, 1);
3523 __qeth_l3_set_offline(card
->gdev
, 0);
3527 static int qeth_l3_pm_resume(struct ccwgroup_device
*gdev
)
3529 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
3532 if (gdev
->state
== CCWGROUP_OFFLINE
)
3535 if (card
->state
== CARD_STATE_RECOVER
) {
3536 rc
= __qeth_l3_set_online(card
->gdev
, 1);
3539 dev_close(card
->dev
);
3543 rc
= __qeth_l3_set_online(card
->gdev
, 0);
3545 qeth_set_allowed_threads(card
, 0xffffffff, 0);
3547 netif_device_attach(card
->dev
);
3549 dev_warn(&card
->gdev
->dev
, "The qeth device driver "
3550 "failed to recover an error on the device\n");
3554 struct ccwgroup_driver qeth_l3_ccwgroup_driver
= {
3555 .probe
= qeth_l3_probe_device
,
3556 .remove
= qeth_l3_remove_device
,
3557 .set_online
= qeth_l3_set_online
,
3558 .set_offline
= qeth_l3_set_offline
,
3559 .shutdown
= qeth_l3_shutdown
,
3560 .freeze
= qeth_l3_pm_suspend
,
3561 .thaw
= qeth_l3_pm_resume
,
3562 .restore
= qeth_l3_pm_resume
,
3564 EXPORT_SYMBOL_GPL(qeth_l3_ccwgroup_driver
);
3566 static int qeth_l3_ip_event(struct notifier_block
*this,
3567 unsigned long event
, void *ptr
)
3569 struct in_ifaddr
*ifa
= (struct in_ifaddr
*)ptr
;
3570 struct net_device
*dev
= (struct net_device
*)ifa
->ifa_dev
->dev
;
3571 struct qeth_ipaddr
*addr
;
3572 struct qeth_card
*card
;
3574 if (dev_net(dev
) != &init_net
)
3577 QETH_DBF_TEXT(TRACE
, 3, "ipevent");
3578 card
= qeth_l3_get_card_from_dev(dev
);
3582 addr
= qeth_l3_get_addr_buffer(QETH_PROT_IPV4
);
3584 addr
->u
.a4
.addr
= ifa
->ifa_address
;
3585 addr
->u
.a4
.mask
= ifa
->ifa_mask
;
3586 addr
->type
= QETH_IP_TYPE_NORMAL
;
3592 if (!qeth_l3_add_ip(card
, addr
))
3596 if (!qeth_l3_delete_ip(card
, addr
))
3602 qeth_l3_set_ip_addr_list(card
);
3607 static struct notifier_block qeth_l3_ip_notifier
= {
3612 #ifdef CONFIG_QETH_IPV6
3614 * IPv6 event handler
3616 static int qeth_l3_ip6_event(struct notifier_block
*this,
3617 unsigned long event
, void *ptr
)
3619 struct inet6_ifaddr
*ifa
= (struct inet6_ifaddr
*)ptr
;
3620 struct net_device
*dev
= (struct net_device
*)ifa
->idev
->dev
;
3621 struct qeth_ipaddr
*addr
;
3622 struct qeth_card
*card
;
3624 QETH_DBF_TEXT(TRACE
, 3, "ip6event");
3626 card
= qeth_l3_get_card_from_dev(dev
);
3629 if (!qeth_is_supported(card
, IPA_IPV6
))
3632 addr
= qeth_l3_get_addr_buffer(QETH_PROT_IPV6
);
3634 memcpy(&addr
->u
.a6
.addr
, &ifa
->addr
, sizeof(struct in6_addr
));
3635 addr
->u
.a6
.pfxlen
= ifa
->prefix_len
;
3636 addr
->type
= QETH_IP_TYPE_NORMAL
;
3642 if (!qeth_l3_add_ip(card
, addr
))
3646 if (!qeth_l3_delete_ip(card
, addr
))
3652 qeth_l3_set_ip_addr_list(card
);
3657 static struct notifier_block qeth_l3_ip6_notifier
= {
3663 static int qeth_l3_register_notifiers(void)
3667 QETH_DBF_TEXT(TRACE
, 5, "regnotif");
3668 rc
= register_inetaddr_notifier(&qeth_l3_ip_notifier
);
3671 #ifdef CONFIG_QETH_IPV6
3672 rc
= register_inet6addr_notifier(&qeth_l3_ip6_notifier
);
3674 unregister_inetaddr_notifier(&qeth_l3_ip_notifier
);
3678 pr_warning("There is no IPv6 support for the layer 3 discipline\n");
3683 static void qeth_l3_unregister_notifiers(void)
3686 QETH_DBF_TEXT(TRACE
, 5, "unregnot");
3687 BUG_ON(unregister_inetaddr_notifier(&qeth_l3_ip_notifier
));
3688 #ifdef CONFIG_QETH_IPV6
3689 BUG_ON(unregister_inet6addr_notifier(&qeth_l3_ip6_notifier
));
3690 #endif /* QETH_IPV6 */
3693 static int __init
qeth_l3_init(void)
3697 pr_info("register layer 3 discipline\n");
3698 rc
= qeth_l3_register_notifiers();
3702 static void __exit
qeth_l3_exit(void)
3704 qeth_l3_unregister_notifiers();
3705 pr_info("unregister layer 3 discipline\n");
3708 module_init(qeth_l3_init
);
3709 module_exit(qeth_l3_exit
);
3710 MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
3711 MODULE_DESCRIPTION("qeth layer 3 discipline");
3712 MODULE_LICENSE("GPL");