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>
28 #include <net/ip6_checksum.h>
32 static int qeth_l3_set_offline(struct ccwgroup_device
*);
33 static int qeth_l3_recover(void *);
34 static int qeth_l3_stop(struct net_device
*);
35 static void qeth_l3_set_multicast_list(struct net_device
*);
36 static int qeth_l3_neigh_setup(struct net_device
*, struct neigh_parms
*);
37 static int qeth_l3_register_addr_entry(struct qeth_card
*,
38 struct qeth_ipaddr
*);
39 static int qeth_l3_deregister_addr_entry(struct qeth_card
*,
40 struct qeth_ipaddr
*);
41 static int __qeth_l3_set_online(struct ccwgroup_device
*, int);
42 static int __qeth_l3_set_offline(struct ccwgroup_device
*, int);
44 int qeth_l3_set_large_send(struct qeth_card
*card
,
45 enum qeth_large_send_types type
)
49 card
->options
.large_send
= type
;
50 if (card
->dev
== NULL
)
53 if (card
->options
.large_send
== QETH_LARGE_SEND_TSO
) {
54 if (qeth_is_supported(card
, IPA_OUTBOUND_TSO
)) {
55 card
->dev
->features
|= NETIF_F_TSO
| NETIF_F_SG
|
58 card
->dev
->features
&= ~(NETIF_F_TSO
| NETIF_F_SG
|
60 card
->options
.large_send
= QETH_LARGE_SEND_NO
;
64 card
->dev
->features
&= ~(NETIF_F_TSO
| NETIF_F_SG
|
66 card
->options
.large_send
= QETH_LARGE_SEND_NO
;
71 static int qeth_l3_isxdigit(char *buf
)
74 if (!isxdigit(*buf
++))
80 void qeth_l3_ipaddr4_to_string(const __u8
*addr
, char *buf
)
82 sprintf(buf
, "%i.%i.%i.%i", addr
[0], addr
[1], addr
[2], addr
[3]);
85 int qeth_l3_string_to_ipaddr4(const char *buf
, __u8
*addr
)
87 int count
= 0, rc
= 0;
91 rc
= sscanf(buf
, "%u.%u.%u.%u%c",
92 &in
[0], &in
[1], &in
[2], &in
[3], &c
);
93 if (rc
!= 4 && (rc
!= 5 || c
!= '\n'))
95 for (count
= 0; count
< 4; count
++) {
98 addr
[count
] = in
[count
];
103 void qeth_l3_ipaddr6_to_string(const __u8
*addr
, char *buf
)
105 sprintf(buf
, "%02x%02x:%02x%02x:%02x%02x:%02x%02x"
106 ":%02x%02x:%02x%02x:%02x%02x:%02x%02x",
107 addr
[0], addr
[1], addr
[2], addr
[3],
108 addr
[4], addr
[5], addr
[6], addr
[7],
109 addr
[8], addr
[9], addr
[10], addr
[11],
110 addr
[12], addr
[13], addr
[14], addr
[15]);
113 int qeth_l3_string_to_ipaddr6(const char *buf
, __u8
*addr
)
115 const char *end
, *end_tmp
, *start
;
118 int num2
, cnt
, out
, found
, save_cnt
;
119 unsigned short in_tmp
[8] = {0, };
121 cnt
= out
= found
= save_cnt
= num2
= 0;
126 end
= strchr(start
, ':');
128 end
= buf
+ strlen(buf
);
129 end_tmp
= strchr(start
, '\n');
136 if ((end
- start
) > 4)
138 memcpy(num
, start
, end
- start
);
139 if (!qeth_l3_isxdigit(num
))
141 sscanf(start
, "%x", &num2
);
143 in_tmp
[save_cnt
++] = num2
;
155 if (cnt
+ save_cnt
> 8)
159 in
[cnt
--] = in_tmp
[--save_cnt
];
163 void qeth_l3_ipaddr_to_string(enum qeth_prot_versions proto
, const __u8
*addr
,
166 if (proto
== QETH_PROT_IPV4
)
167 qeth_l3_ipaddr4_to_string(addr
, buf
);
168 else if (proto
== QETH_PROT_IPV6
)
169 qeth_l3_ipaddr6_to_string(addr
, buf
);
172 int qeth_l3_string_to_ipaddr(const char *buf
, enum qeth_prot_versions proto
,
175 if (proto
== QETH_PROT_IPV4
)
176 return qeth_l3_string_to_ipaddr4(buf
, addr
);
177 else if (proto
== QETH_PROT_IPV6
)
178 return qeth_l3_string_to_ipaddr6(buf
, addr
);
183 static void qeth_l3_convert_addr_to_bits(u8
*addr
, u8
*bits
, int len
)
188 for (i
= 0; i
< len
; ++i
) {
190 for (j
= 7; j
>= 0; --j
) {
191 bits
[i
*8 + j
] = octet
& 1;
197 static int qeth_l3_is_addr_covered_by_ipato(struct qeth_card
*card
,
198 struct qeth_ipaddr
*addr
)
200 struct qeth_ipato_entry
*ipatoe
;
201 u8 addr_bits
[128] = {0, };
202 u8 ipatoe_bits
[128] = {0, };
205 if (!card
->ipato
.enabled
)
208 qeth_l3_convert_addr_to_bits((u8
*) &addr
->u
, addr_bits
,
209 (addr
->proto
== QETH_PROT_IPV4
)? 4:16);
210 list_for_each_entry(ipatoe
, &card
->ipato
.entries
, entry
) {
211 if (addr
->proto
!= ipatoe
->proto
)
213 qeth_l3_convert_addr_to_bits(ipatoe
->addr
, ipatoe_bits
,
214 (ipatoe
->proto
== QETH_PROT_IPV4
) ?
216 if (addr
->proto
== QETH_PROT_IPV4
)
217 rc
= !memcmp(addr_bits
, ipatoe_bits
,
218 min(32, ipatoe
->mask_bits
));
220 rc
= !memcmp(addr_bits
, ipatoe_bits
,
221 min(128, ipatoe
->mask_bits
));
226 if ((addr
->proto
== QETH_PROT_IPV4
) && card
->ipato
.invert4
)
228 else if ((addr
->proto
== QETH_PROT_IPV6
) && card
->ipato
.invert6
)
235 * Add IP to be added to todo list. If there is already an "add todo"
236 * in this list we just incremenent the reference count.
237 * Returns 0 if we just incremented reference count.
239 static int __qeth_l3_insert_ip_todo(struct qeth_card
*card
,
240 struct qeth_ipaddr
*addr
, int add
)
242 struct qeth_ipaddr
*tmp
, *t
;
245 if (card
->options
.sniffer
)
247 list_for_each_entry_safe(tmp
, t
, card
->ip_tbd_list
, entry
) {
248 if ((addr
->type
== QETH_IP_TYPE_DEL_ALL_MC
) &&
249 (tmp
->type
== QETH_IP_TYPE_DEL_ALL_MC
))
251 if ((tmp
->proto
== QETH_PROT_IPV4
) &&
252 (addr
->proto
== QETH_PROT_IPV4
) &&
253 (tmp
->type
== addr
->type
) &&
254 (tmp
->is_multicast
== addr
->is_multicast
) &&
255 (tmp
->u
.a4
.addr
== addr
->u
.a4
.addr
) &&
256 (tmp
->u
.a4
.mask
== addr
->u
.a4
.mask
)) {
260 if ((tmp
->proto
== QETH_PROT_IPV6
) &&
261 (addr
->proto
== QETH_PROT_IPV6
) &&
262 (tmp
->type
== addr
->type
) &&
263 (tmp
->is_multicast
== addr
->is_multicast
) &&
264 (tmp
->u
.a6
.pfxlen
== addr
->u
.a6
.pfxlen
) &&
265 (memcmp(&tmp
->u
.a6
.addr
, &addr
->u
.a6
.addr
,
266 sizeof(struct in6_addr
)) == 0)) {
272 if (addr
->users
!= 0)
273 tmp
->users
+= addr
->users
;
275 tmp
->users
+= add
? 1 : -1;
276 if (tmp
->users
== 0) {
277 list_del(&tmp
->entry
);
282 if (addr
->type
== QETH_IP_TYPE_DEL_ALL_MC
)
283 list_add(&addr
->entry
, card
->ip_tbd_list
);
285 if (addr
->users
== 0)
286 addr
->users
+= add
? 1 : -1;
287 if (add
&& (addr
->type
== QETH_IP_TYPE_NORMAL
) &&
288 qeth_l3_is_addr_covered_by_ipato(card
, addr
)) {
289 QETH_DBF_TEXT(TRACE
, 2, "tkovaddr");
290 addr
->set_flags
|= QETH_IPA_SETIP_TAKEOVER_FLAG
;
292 list_add_tail(&addr
->entry
, card
->ip_tbd_list
);
298 static int qeth_l3_delete_ip(struct qeth_card
*card
, struct qeth_ipaddr
*addr
)
303 QETH_DBF_TEXT(TRACE
, 4, "delip");
305 if (addr
->proto
== QETH_PROT_IPV4
)
306 QETH_DBF_HEX(TRACE
, 4, &addr
->u
.a4
.addr
, 4);
308 QETH_DBF_HEX(TRACE
, 4, &addr
->u
.a6
.addr
, 8);
309 QETH_DBF_HEX(TRACE
, 4, ((char *)&addr
->u
.a6
.addr
) + 8, 8);
311 spin_lock_irqsave(&card
->ip_lock
, flags
);
312 rc
= __qeth_l3_insert_ip_todo(card
, addr
, 0);
313 spin_unlock_irqrestore(&card
->ip_lock
, flags
);
317 static int qeth_l3_add_ip(struct qeth_card
*card
, struct qeth_ipaddr
*addr
)
322 QETH_DBF_TEXT(TRACE
, 4, "addip");
323 if (addr
->proto
== QETH_PROT_IPV4
)
324 QETH_DBF_HEX(TRACE
, 4, &addr
->u
.a4
.addr
, 4);
326 QETH_DBF_HEX(TRACE
, 4, &addr
->u
.a6
.addr
, 8);
327 QETH_DBF_HEX(TRACE
, 4, ((char *)&addr
->u
.a6
.addr
) + 8, 8);
329 spin_lock_irqsave(&card
->ip_lock
, flags
);
330 rc
= __qeth_l3_insert_ip_todo(card
, addr
, 1);
331 spin_unlock_irqrestore(&card
->ip_lock
, flags
);
336 static struct qeth_ipaddr
*qeth_l3_get_addr_buffer(
337 enum qeth_prot_versions prot
)
339 struct qeth_ipaddr
*addr
;
341 addr
= kzalloc(sizeof(struct qeth_ipaddr
), GFP_ATOMIC
);
345 addr
->type
= QETH_IP_TYPE_NORMAL
;
350 static void qeth_l3_delete_mc_addresses(struct qeth_card
*card
)
352 struct qeth_ipaddr
*iptodo
;
355 QETH_DBF_TEXT(TRACE
, 4, "delmc");
356 iptodo
= qeth_l3_get_addr_buffer(QETH_PROT_IPV4
);
358 QETH_DBF_TEXT(TRACE
, 2, "dmcnomem");
361 iptodo
->type
= QETH_IP_TYPE_DEL_ALL_MC
;
362 spin_lock_irqsave(&card
->ip_lock
, flags
);
363 if (!__qeth_l3_insert_ip_todo(card
, iptodo
, 0))
365 spin_unlock_irqrestore(&card
->ip_lock
, flags
);
369 * Add/remove address to/from card's ip list, i.e. try to add or remove
370 * reference to/from an IP address that is already registered on the card.
372 * 0 address was on card and its reference count has been adjusted,
373 * but is still > 0, so nothing has to be done
374 * also returns 0 if card was not on card and the todo was to delete
375 * the address -> there is also nothing to be done
376 * 1 address was not on card and the todo is to add it to the card's ip
378 * -1 address was on card and its reference count has been decremented
379 * to <= 0 by the todo -> address must be removed from card
381 static int __qeth_l3_ref_ip_on_card(struct qeth_card
*card
,
382 struct qeth_ipaddr
*todo
, struct qeth_ipaddr
**__addr
)
384 struct qeth_ipaddr
*addr
;
387 list_for_each_entry(addr
, &card
->ip_list
, entry
) {
388 if ((addr
->proto
== QETH_PROT_IPV4
) &&
389 (todo
->proto
== QETH_PROT_IPV4
) &&
390 (addr
->type
== todo
->type
) &&
391 (addr
->u
.a4
.addr
== todo
->u
.a4
.addr
) &&
392 (addr
->u
.a4
.mask
== todo
->u
.a4
.mask
)) {
396 if ((addr
->proto
== QETH_PROT_IPV6
) &&
397 (todo
->proto
== QETH_PROT_IPV6
) &&
398 (addr
->type
== todo
->type
) &&
399 (addr
->u
.a6
.pfxlen
== todo
->u
.a6
.pfxlen
) &&
400 (memcmp(&addr
->u
.a6
.addr
, &todo
->u
.a6
.addr
,
401 sizeof(struct in6_addr
)) == 0)) {
407 addr
->users
+= todo
->users
;
408 if (addr
->users
<= 0) {
412 /* for VIPA and RXIP limit refcount to 1 */
413 if (addr
->type
!= QETH_IP_TYPE_NORMAL
)
418 if (todo
->users
> 0) {
419 /* for VIPA and RXIP limit refcount to 1 */
420 if (todo
->type
!= QETH_IP_TYPE_NORMAL
)
427 static void __qeth_l3_delete_all_mc(struct qeth_card
*card
,
428 unsigned long *flags
)
430 struct list_head fail_list
;
431 struct qeth_ipaddr
*addr
, *tmp
;
434 INIT_LIST_HEAD(&fail_list
);
436 list_for_each_entry_safe(addr
, tmp
, &card
->ip_list
, entry
) {
437 if (addr
->is_multicast
) {
438 list_del(&addr
->entry
);
439 spin_unlock_irqrestore(&card
->ip_lock
, *flags
);
440 rc
= qeth_l3_deregister_addr_entry(card
, addr
);
441 spin_lock_irqsave(&card
->ip_lock
, *flags
);
442 if (!rc
|| (rc
== IPA_RC_MC_ADDR_NOT_FOUND
))
445 list_add_tail(&addr
->entry
, &fail_list
);
449 list_splice(&fail_list
, &card
->ip_list
);
452 static void qeth_l3_set_ip_addr_list(struct qeth_card
*card
)
454 struct list_head
*tbd_list
;
455 struct qeth_ipaddr
*todo
, *addr
;
459 QETH_DBF_TEXT(TRACE
, 2, "sdiplist");
460 QETH_DBF_HEX(TRACE
, 2, &card
, sizeof(void *));
462 if (card
->options
.sniffer
)
464 spin_lock_irqsave(&card
->ip_lock
, flags
);
465 tbd_list
= card
->ip_tbd_list
;
466 card
->ip_tbd_list
= kmalloc(sizeof(struct list_head
), GFP_ATOMIC
);
467 if (!card
->ip_tbd_list
) {
468 QETH_DBF_TEXT(TRACE
, 0, "silnomem");
469 card
->ip_tbd_list
= tbd_list
;
470 spin_unlock_irqrestore(&card
->ip_lock
, flags
);
473 INIT_LIST_HEAD(card
->ip_tbd_list
);
475 while (!list_empty(tbd_list
)) {
476 todo
= list_entry(tbd_list
->next
, struct qeth_ipaddr
, entry
);
477 list_del(&todo
->entry
);
478 if (todo
->type
== QETH_IP_TYPE_DEL_ALL_MC
) {
479 __qeth_l3_delete_all_mc(card
, &flags
);
483 rc
= __qeth_l3_ref_ip_on_card(card
, todo
, &addr
);
485 /* nothing to be done; only adjusted refcount */
487 } else if (rc
== 1) {
488 /* new entry to be added to on-card list */
489 spin_unlock_irqrestore(&card
->ip_lock
, flags
);
490 rc
= qeth_l3_register_addr_entry(card
, todo
);
491 spin_lock_irqsave(&card
->ip_lock
, flags
);
492 if (!rc
|| (rc
== IPA_RC_LAN_OFFLINE
))
493 list_add_tail(&todo
->entry
, &card
->ip_list
);
496 } else if (rc
== -1) {
497 /* on-card entry to be removed */
498 list_del_init(&addr
->entry
);
499 spin_unlock_irqrestore(&card
->ip_lock
, flags
);
500 rc
= qeth_l3_deregister_addr_entry(card
, addr
);
501 spin_lock_irqsave(&card
->ip_lock
, flags
);
502 if (!rc
|| (rc
== IPA_RC_IP_ADDRESS_NOT_DEFINED
))
505 list_add_tail(&addr
->entry
, &card
->ip_list
);
509 spin_unlock_irqrestore(&card
->ip_lock
, flags
);
513 static void qeth_l3_clear_ip_list(struct qeth_card
*card
, int clean
,
516 struct qeth_ipaddr
*addr
, *tmp
;
519 QETH_DBF_TEXT(TRACE
, 4, "clearip");
520 if (recover
&& card
->options
.sniffer
)
522 spin_lock_irqsave(&card
->ip_lock
, flags
);
523 /* clear todo list */
524 list_for_each_entry_safe(addr
, tmp
, card
->ip_tbd_list
, entry
) {
525 list_del(&addr
->entry
);
529 while (!list_empty(&card
->ip_list
)) {
530 addr
= list_entry(card
->ip_list
.next
,
531 struct qeth_ipaddr
, entry
);
532 list_del_init(&addr
->entry
);
534 spin_unlock_irqrestore(&card
->ip_lock
, flags
);
535 qeth_l3_deregister_addr_entry(card
, addr
);
536 spin_lock_irqsave(&card
->ip_lock
, flags
);
538 if (!recover
|| addr
->is_multicast
) {
542 list_add_tail(&addr
->entry
, card
->ip_tbd_list
);
544 spin_unlock_irqrestore(&card
->ip_lock
, flags
);
547 static int qeth_l3_address_exists_in_list(struct list_head
*list
,
548 struct qeth_ipaddr
*addr
, int same_type
)
550 struct qeth_ipaddr
*tmp
;
552 list_for_each_entry(tmp
, list
, entry
) {
553 if ((tmp
->proto
== QETH_PROT_IPV4
) &&
554 (addr
->proto
== QETH_PROT_IPV4
) &&
555 ((same_type
&& (tmp
->type
== addr
->type
)) ||
556 (!same_type
&& (tmp
->type
!= addr
->type
))) &&
557 (tmp
->u
.a4
.addr
== addr
->u
.a4
.addr
))
560 if ((tmp
->proto
== QETH_PROT_IPV6
) &&
561 (addr
->proto
== QETH_PROT_IPV6
) &&
562 ((same_type
&& (tmp
->type
== addr
->type
)) ||
563 (!same_type
&& (tmp
->type
!= addr
->type
))) &&
564 (memcmp(&tmp
->u
.a6
.addr
, &addr
->u
.a6
.addr
,
565 sizeof(struct in6_addr
)) == 0))
572 static int qeth_l3_send_setdelmc(struct qeth_card
*card
,
573 struct qeth_ipaddr
*addr
, int ipacmd
)
576 struct qeth_cmd_buffer
*iob
;
577 struct qeth_ipa_cmd
*cmd
;
579 QETH_DBF_TEXT(TRACE
, 4, "setdelmc");
581 iob
= qeth_get_ipacmd_buffer(card
, ipacmd
, addr
->proto
);
582 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
583 memcpy(&cmd
->data
.setdelipm
.mac
, addr
->mac
, OSA_ADDR_LEN
);
584 if (addr
->proto
== QETH_PROT_IPV6
)
585 memcpy(cmd
->data
.setdelipm
.ip6
, &addr
->u
.a6
.addr
,
586 sizeof(struct in6_addr
));
588 memcpy(&cmd
->data
.setdelipm
.ip4
, &addr
->u
.a4
.addr
, 4);
590 rc
= qeth_send_ipa_cmd(card
, iob
, NULL
, NULL
);
595 static void qeth_l3_fill_netmask(u8
*netmask
, unsigned int len
)
598 for (i
= 0; i
< 16; i
++) {
603 netmask
[i
] = (u8
)(0xFF00 >> j
);
609 static int qeth_l3_send_setdelip(struct qeth_card
*card
,
610 struct qeth_ipaddr
*addr
, int ipacmd
, unsigned int flags
)
613 struct qeth_cmd_buffer
*iob
;
614 struct qeth_ipa_cmd
*cmd
;
617 QETH_DBF_TEXT(TRACE
, 4, "setdelip");
618 QETH_DBF_TEXT_(TRACE
, 4, "flags%02X", flags
);
620 iob
= qeth_get_ipacmd_buffer(card
, ipacmd
, addr
->proto
);
621 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
622 if (addr
->proto
== QETH_PROT_IPV6
) {
623 memcpy(cmd
->data
.setdelip6
.ip_addr
, &addr
->u
.a6
.addr
,
624 sizeof(struct in6_addr
));
625 qeth_l3_fill_netmask(netmask
, addr
->u
.a6
.pfxlen
);
626 memcpy(cmd
->data
.setdelip6
.mask
, netmask
,
627 sizeof(struct in6_addr
));
628 cmd
->data
.setdelip6
.flags
= flags
;
630 memcpy(cmd
->data
.setdelip4
.ip_addr
, &addr
->u
.a4
.addr
, 4);
631 memcpy(cmd
->data
.setdelip4
.mask
, &addr
->u
.a4
.mask
, 4);
632 cmd
->data
.setdelip4
.flags
= flags
;
635 rc
= qeth_send_ipa_cmd(card
, iob
, NULL
, NULL
);
640 static int qeth_l3_send_setrouting(struct qeth_card
*card
,
641 enum qeth_routing_types type
, enum qeth_prot_versions prot
)
644 struct qeth_ipa_cmd
*cmd
;
645 struct qeth_cmd_buffer
*iob
;
647 QETH_DBF_TEXT(TRACE
, 4, "setroutg");
648 iob
= qeth_get_ipacmd_buffer(card
, IPA_CMD_SETRTG
, prot
);
649 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
650 cmd
->data
.setrtg
.type
= (type
);
651 rc
= qeth_send_ipa_cmd(card
, iob
, NULL
, NULL
);
656 static void qeth_l3_correct_routing_type(struct qeth_card
*card
,
657 enum qeth_routing_types
*type
, enum qeth_prot_versions prot
)
659 if (card
->info
.type
== QETH_CARD_TYPE_IQD
) {
662 case PRIMARY_CONNECTOR
:
663 case SECONDARY_CONNECTOR
:
664 case MULTICAST_ROUTER
:
673 case SECONDARY_ROUTER
:
675 case MULTICAST_ROUTER
:
676 if (qeth_is_ipafunc_supported(card
, prot
,
687 int qeth_l3_setrouting_v4(struct qeth_card
*card
)
691 QETH_DBF_TEXT(TRACE
, 3, "setrtg4");
693 qeth_l3_correct_routing_type(card
, &card
->options
.route4
.type
,
696 rc
= qeth_l3_send_setrouting(card
, card
->options
.route4
.type
,
699 card
->options
.route4
.type
= NO_ROUTER
;
700 QETH_DBF_MESSAGE(2, "Error (0x%04x) while setting routing type"
701 " on %s. Type set to 'no router'.\n", rc
,
702 QETH_CARD_IFNAME(card
));
707 int qeth_l3_setrouting_v6(struct qeth_card
*card
)
711 QETH_DBF_TEXT(TRACE
, 3, "setrtg6");
712 #ifdef CONFIG_QETH_IPV6
714 if (!qeth_is_supported(card
, IPA_IPV6
))
716 qeth_l3_correct_routing_type(card
, &card
->options
.route6
.type
,
719 rc
= qeth_l3_send_setrouting(card
, card
->options
.route6
.type
,
722 card
->options
.route6
.type
= NO_ROUTER
;
723 QETH_DBF_MESSAGE(2, "Error (0x%04x) while setting routing type"
724 " on %s. Type set to 'no router'.\n", rc
,
725 QETH_CARD_IFNAME(card
));
732 * IP address takeover related functions
734 static void qeth_l3_clear_ipato_list(struct qeth_card
*card
)
737 struct qeth_ipato_entry
*ipatoe
, *tmp
;
740 spin_lock_irqsave(&card
->ip_lock
, flags
);
741 list_for_each_entry_safe(ipatoe
, tmp
, &card
->ipato
.entries
, entry
) {
742 list_del(&ipatoe
->entry
);
745 spin_unlock_irqrestore(&card
->ip_lock
, flags
);
748 int qeth_l3_add_ipato_entry(struct qeth_card
*card
,
749 struct qeth_ipato_entry
*new)
751 struct qeth_ipato_entry
*ipatoe
;
755 QETH_DBF_TEXT(TRACE
, 2, "addipato");
756 spin_lock_irqsave(&card
->ip_lock
, flags
);
757 list_for_each_entry(ipatoe
, &card
->ipato
.entries
, entry
) {
758 if (ipatoe
->proto
!= new->proto
)
760 if (!memcmp(ipatoe
->addr
, new->addr
,
761 (ipatoe
->proto
== QETH_PROT_IPV4
)? 4:16) &&
762 (ipatoe
->mask_bits
== new->mask_bits
)) {
768 list_add_tail(&new->entry
, &card
->ipato
.entries
);
770 spin_unlock_irqrestore(&card
->ip_lock
, flags
);
774 void qeth_l3_del_ipato_entry(struct qeth_card
*card
,
775 enum qeth_prot_versions proto
, u8
*addr
, int mask_bits
)
777 struct qeth_ipato_entry
*ipatoe
, *tmp
;
780 QETH_DBF_TEXT(TRACE
, 2, "delipato");
781 spin_lock_irqsave(&card
->ip_lock
, flags
);
782 list_for_each_entry_safe(ipatoe
, tmp
, &card
->ipato
.entries
, entry
) {
783 if (ipatoe
->proto
!= proto
)
785 if (!memcmp(ipatoe
->addr
, addr
,
786 (proto
== QETH_PROT_IPV4
)? 4:16) &&
787 (ipatoe
->mask_bits
== mask_bits
)) {
788 list_del(&ipatoe
->entry
);
792 spin_unlock_irqrestore(&card
->ip_lock
, flags
);
796 * VIPA related functions
798 int qeth_l3_add_vipa(struct qeth_card
*card
, enum qeth_prot_versions proto
,
801 struct qeth_ipaddr
*ipaddr
;
805 ipaddr
= qeth_l3_get_addr_buffer(proto
);
807 if (proto
== QETH_PROT_IPV4
) {
808 QETH_DBF_TEXT(TRACE
, 2, "addvipa4");
809 memcpy(&ipaddr
->u
.a4
.addr
, addr
, 4);
810 ipaddr
->u
.a4
.mask
= 0;
811 } else if (proto
== QETH_PROT_IPV6
) {
812 QETH_DBF_TEXT(TRACE
, 2, "addvipa6");
813 memcpy(&ipaddr
->u
.a6
.addr
, addr
, 16);
814 ipaddr
->u
.a6
.pfxlen
= 0;
816 ipaddr
->type
= QETH_IP_TYPE_VIPA
;
817 ipaddr
->set_flags
= QETH_IPA_SETIP_VIPA_FLAG
;
818 ipaddr
->del_flags
= QETH_IPA_DELIP_VIPA_FLAG
;
821 spin_lock_irqsave(&card
->ip_lock
, flags
);
822 if (qeth_l3_address_exists_in_list(&card
->ip_list
, ipaddr
, 0) ||
823 qeth_l3_address_exists_in_list(card
->ip_tbd_list
, ipaddr
, 0))
825 spin_unlock_irqrestore(&card
->ip_lock
, flags
);
829 if (!qeth_l3_add_ip(card
, ipaddr
))
831 qeth_l3_set_ip_addr_list(card
);
835 void qeth_l3_del_vipa(struct qeth_card
*card
, enum qeth_prot_versions proto
,
838 struct qeth_ipaddr
*ipaddr
;
840 ipaddr
= qeth_l3_get_addr_buffer(proto
);
842 if (proto
== QETH_PROT_IPV4
) {
843 QETH_DBF_TEXT(TRACE
, 2, "delvipa4");
844 memcpy(&ipaddr
->u
.a4
.addr
, addr
, 4);
845 ipaddr
->u
.a4
.mask
= 0;
846 } else if (proto
== QETH_PROT_IPV6
) {
847 QETH_DBF_TEXT(TRACE
, 2, "delvipa6");
848 memcpy(&ipaddr
->u
.a6
.addr
, addr
, 16);
849 ipaddr
->u
.a6
.pfxlen
= 0;
851 ipaddr
->type
= QETH_IP_TYPE_VIPA
;
854 if (!qeth_l3_delete_ip(card
, ipaddr
))
856 qeth_l3_set_ip_addr_list(card
);
860 * proxy ARP related functions
862 int qeth_l3_add_rxip(struct qeth_card
*card
, enum qeth_prot_versions proto
,
865 struct qeth_ipaddr
*ipaddr
;
869 ipaddr
= qeth_l3_get_addr_buffer(proto
);
871 if (proto
== QETH_PROT_IPV4
) {
872 QETH_DBF_TEXT(TRACE
, 2, "addrxip4");
873 memcpy(&ipaddr
->u
.a4
.addr
, addr
, 4);
874 ipaddr
->u
.a4
.mask
= 0;
875 } else if (proto
== QETH_PROT_IPV6
) {
876 QETH_DBF_TEXT(TRACE
, 2, "addrxip6");
877 memcpy(&ipaddr
->u
.a6
.addr
, addr
, 16);
878 ipaddr
->u
.a6
.pfxlen
= 0;
880 ipaddr
->type
= QETH_IP_TYPE_RXIP
;
881 ipaddr
->set_flags
= QETH_IPA_SETIP_TAKEOVER_FLAG
;
882 ipaddr
->del_flags
= 0;
885 spin_lock_irqsave(&card
->ip_lock
, flags
);
886 if (qeth_l3_address_exists_in_list(&card
->ip_list
, ipaddr
, 0) ||
887 qeth_l3_address_exists_in_list(card
->ip_tbd_list
, ipaddr
, 0))
889 spin_unlock_irqrestore(&card
->ip_lock
, flags
);
893 if (!qeth_l3_add_ip(card
, ipaddr
))
895 qeth_l3_set_ip_addr_list(card
);
899 void qeth_l3_del_rxip(struct qeth_card
*card
, enum qeth_prot_versions proto
,
902 struct qeth_ipaddr
*ipaddr
;
904 ipaddr
= qeth_l3_get_addr_buffer(proto
);
906 if (proto
== QETH_PROT_IPV4
) {
907 QETH_DBF_TEXT(TRACE
, 2, "addrxip4");
908 memcpy(&ipaddr
->u
.a4
.addr
, addr
, 4);
909 ipaddr
->u
.a4
.mask
= 0;
910 } else if (proto
== QETH_PROT_IPV6
) {
911 QETH_DBF_TEXT(TRACE
, 2, "addrxip6");
912 memcpy(&ipaddr
->u
.a6
.addr
, addr
, 16);
913 ipaddr
->u
.a6
.pfxlen
= 0;
915 ipaddr
->type
= QETH_IP_TYPE_RXIP
;
918 if (!qeth_l3_delete_ip(card
, ipaddr
))
920 qeth_l3_set_ip_addr_list(card
);
923 static int qeth_l3_register_addr_entry(struct qeth_card
*card
,
924 struct qeth_ipaddr
*addr
)
930 if (addr
->proto
== QETH_PROT_IPV4
) {
931 QETH_DBF_TEXT(TRACE
, 2, "setaddr4");
932 QETH_DBF_HEX(TRACE
, 3, &addr
->u
.a4
.addr
, sizeof(int));
933 } else if (addr
->proto
== QETH_PROT_IPV6
) {
934 QETH_DBF_TEXT(TRACE
, 2, "setaddr6");
935 QETH_DBF_HEX(TRACE
, 3, &addr
->u
.a6
.addr
, 8);
936 QETH_DBF_HEX(TRACE
, 3, ((char *)&addr
->u
.a6
.addr
) + 8, 8);
938 QETH_DBF_TEXT(TRACE
, 2, "setaddr?");
939 QETH_DBF_HEX(TRACE
, 3, addr
, sizeof(struct qeth_ipaddr
));
942 if (addr
->is_multicast
)
943 rc
= qeth_l3_send_setdelmc(card
, addr
, IPA_CMD_SETIPM
);
945 rc
= qeth_l3_send_setdelip(card
, addr
, IPA_CMD_SETIP
,
948 QETH_DBF_TEXT(TRACE
, 2, "failed");
949 } while ((--cnt
> 0) && rc
);
951 QETH_DBF_TEXT(TRACE
, 2, "FAILED");
952 qeth_l3_ipaddr_to_string(addr
->proto
, (u8
*)&addr
->u
, buf
);
953 dev_warn(&card
->gdev
->dev
,
954 "Registering IP address %s failed\n", buf
);
959 static int qeth_l3_deregister_addr_entry(struct qeth_card
*card
,
960 struct qeth_ipaddr
*addr
)
964 if (addr
->proto
== QETH_PROT_IPV4
) {
965 QETH_DBF_TEXT(TRACE
, 2, "deladdr4");
966 QETH_DBF_HEX(TRACE
, 3, &addr
->u
.a4
.addr
, sizeof(int));
967 } else if (addr
->proto
== QETH_PROT_IPV6
) {
968 QETH_DBF_TEXT(TRACE
, 2, "deladdr6");
969 QETH_DBF_HEX(TRACE
, 3, &addr
->u
.a6
.addr
, 8);
970 QETH_DBF_HEX(TRACE
, 3, ((char *)&addr
->u
.a6
.addr
) + 8, 8);
972 QETH_DBF_TEXT(TRACE
, 2, "deladdr?");
973 QETH_DBF_HEX(TRACE
, 3, addr
, sizeof(struct qeth_ipaddr
));
975 if (addr
->is_multicast
)
976 rc
= qeth_l3_send_setdelmc(card
, addr
, IPA_CMD_DELIPM
);
978 rc
= qeth_l3_send_setdelip(card
, addr
, IPA_CMD_DELIP
,
981 QETH_DBF_TEXT(TRACE
, 2, "failed");
986 static inline u8
qeth_l3_get_qeth_hdr_flags4(int cast_type
)
988 if (cast_type
== RTN_MULTICAST
)
989 return QETH_CAST_MULTICAST
;
990 if (cast_type
== RTN_BROADCAST
)
991 return QETH_CAST_BROADCAST
;
992 return QETH_CAST_UNICAST
;
995 static inline u8
qeth_l3_get_qeth_hdr_flags6(int cast_type
)
997 u8 ct
= QETH_HDR_PASSTHRU
| QETH_HDR_IPV6
;
998 if (cast_type
== RTN_MULTICAST
)
999 return ct
| QETH_CAST_MULTICAST
;
1000 if (cast_type
== RTN_ANYCAST
)
1001 return ct
| QETH_CAST_ANYCAST
;
1002 if (cast_type
== RTN_BROADCAST
)
1003 return ct
| QETH_CAST_BROADCAST
;
1004 return ct
| QETH_CAST_UNICAST
;
1007 static int qeth_l3_send_setadp_mode(struct qeth_card
*card
, __u32 command
,
1011 struct qeth_cmd_buffer
*iob
;
1012 struct qeth_ipa_cmd
*cmd
;
1014 QETH_DBF_TEXT(TRACE
, 4, "adpmode");
1016 iob
= qeth_get_adapter_cmd(card
, command
,
1017 sizeof(struct qeth_ipacmd_setadpparms
));
1018 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
1019 cmd
->data
.setadapterparms
.data
.mode
= mode
;
1020 rc
= qeth_send_ipa_cmd(card
, iob
, qeth_default_setadapterparms_cb
,
1025 static int qeth_l3_setadapter_hstr(struct qeth_card
*card
)
1029 QETH_DBF_TEXT(TRACE
, 4, "adphstr");
1031 if (qeth_adp_supported(card
, IPA_SETADP_SET_BROADCAST_MODE
)) {
1032 rc
= qeth_l3_send_setadp_mode(card
,
1033 IPA_SETADP_SET_BROADCAST_MODE
,
1034 card
->options
.broadcast_mode
);
1036 QETH_DBF_MESSAGE(2, "couldn't set broadcast mode on "
1038 CARD_BUS_ID(card
), rc
);
1039 rc
= qeth_l3_send_setadp_mode(card
,
1040 IPA_SETADP_ALTER_MAC_ADDRESS
,
1041 card
->options
.macaddr_mode
);
1043 QETH_DBF_MESSAGE(2, "couldn't set macaddr mode on "
1044 "device %s: x%x\n", CARD_BUS_ID(card
), rc
);
1047 if (card
->options
.broadcast_mode
== QETH_TR_BROADCAST_LOCAL
)
1048 QETH_DBF_MESSAGE(2, "set adapter parameters not available "
1049 "to set broadcast mode, using ALLRINGS "
1050 "on device %s:\n", CARD_BUS_ID(card
));
1051 if (card
->options
.macaddr_mode
== QETH_TR_MACADDR_CANONICAL
)
1052 QETH_DBF_MESSAGE(2, "set adapter parameters not available "
1053 "to set macaddr mode, using NONCANONICAL "
1054 "on device %s:\n", CARD_BUS_ID(card
));
1058 static int qeth_l3_setadapter_parms(struct qeth_card
*card
)
1062 QETH_DBF_TEXT(SETUP
, 2, "setadprm");
1064 if (!qeth_is_supported(card
, IPA_SETADAPTERPARMS
)) {
1065 dev_info(&card
->gdev
->dev
,
1066 "set adapter parameters not supported.\n");
1067 QETH_DBF_TEXT(SETUP
, 2, " notsupp");
1070 rc
= qeth_query_setadapterparms(card
);
1072 QETH_DBF_MESSAGE(2, "%s couldn't set adapter parameters: "
1073 "0x%x\n", dev_name(&card
->gdev
->dev
), rc
);
1076 if (qeth_adp_supported(card
, IPA_SETADP_ALTER_MAC_ADDRESS
)) {
1077 rc
= qeth_setadpparms_change_macaddr(card
);
1079 dev_warn(&card
->gdev
->dev
, "Reading the adapter MAC"
1080 " address failed\n");
1083 if ((card
->info
.link_type
== QETH_LINK_TYPE_HSTR
) ||
1084 (card
->info
.link_type
== QETH_LINK_TYPE_LANE_TR
))
1085 rc
= qeth_l3_setadapter_hstr(card
);
1090 static int qeth_l3_default_setassparms_cb(struct qeth_card
*card
,
1091 struct qeth_reply
*reply
, unsigned long data
)
1093 struct qeth_ipa_cmd
*cmd
;
1095 QETH_DBF_TEXT(TRACE
, 4, "defadpcb");
1097 cmd
= (struct qeth_ipa_cmd
*) data
;
1098 if (cmd
->hdr
.return_code
== 0) {
1099 cmd
->hdr
.return_code
= cmd
->data
.setassparms
.hdr
.return_code
;
1100 if (cmd
->hdr
.prot_version
== QETH_PROT_IPV4
)
1101 card
->options
.ipa4
.enabled_funcs
= cmd
->hdr
.ipa_enabled
;
1102 if (cmd
->hdr
.prot_version
== QETH_PROT_IPV6
)
1103 card
->options
.ipa6
.enabled_funcs
= cmd
->hdr
.ipa_enabled
;
1105 if (cmd
->data
.setassparms
.hdr
.assist_no
== IPA_INBOUND_CHECKSUM
&&
1106 cmd
->data
.setassparms
.hdr
.command_code
== IPA_CMD_ASS_START
) {
1107 card
->info
.csum_mask
= cmd
->data
.setassparms
.data
.flags_32bit
;
1108 QETH_DBF_TEXT_(TRACE
, 3, "csum:%d", card
->info
.csum_mask
);
1113 static struct qeth_cmd_buffer
*qeth_l3_get_setassparms_cmd(
1114 struct qeth_card
*card
, enum qeth_ipa_funcs ipa_func
, __u16 cmd_code
,
1115 __u16 len
, enum qeth_prot_versions prot
)
1117 struct qeth_cmd_buffer
*iob
;
1118 struct qeth_ipa_cmd
*cmd
;
1120 QETH_DBF_TEXT(TRACE
, 4, "getasscm");
1121 iob
= qeth_get_ipacmd_buffer(card
, IPA_CMD_SETASSPARMS
, prot
);
1123 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
1124 cmd
->data
.setassparms
.hdr
.assist_no
= ipa_func
;
1125 cmd
->data
.setassparms
.hdr
.length
= 8 + len
;
1126 cmd
->data
.setassparms
.hdr
.command_code
= cmd_code
;
1127 cmd
->data
.setassparms
.hdr
.return_code
= 0;
1128 cmd
->data
.setassparms
.hdr
.seq_no
= 0;
1133 static int qeth_l3_send_setassparms(struct qeth_card
*card
,
1134 struct qeth_cmd_buffer
*iob
, __u16 len
, long data
,
1135 int (*reply_cb
)(struct qeth_card
*, struct qeth_reply
*,
1140 struct qeth_ipa_cmd
*cmd
;
1142 QETH_DBF_TEXT(TRACE
, 4, "sendassp");
1144 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
1145 if (len
<= sizeof(__u32
))
1146 cmd
->data
.setassparms
.data
.flags_32bit
= (__u32
) data
;
1147 else /* (len > sizeof(__u32)) */
1148 memcpy(&cmd
->data
.setassparms
.data
, (void *) data
, len
);
1150 rc
= qeth_send_ipa_cmd(card
, iob
, reply_cb
, reply_param
);
1154 #ifdef CONFIG_QETH_IPV6
1155 static int qeth_l3_send_simple_setassparms_ipv6(struct qeth_card
*card
,
1156 enum qeth_ipa_funcs ipa_func
, __u16 cmd_code
)
1159 struct qeth_cmd_buffer
*iob
;
1161 QETH_DBF_TEXT(TRACE
, 4, "simassp6");
1162 iob
= qeth_l3_get_setassparms_cmd(card
, ipa_func
, cmd_code
,
1164 rc
= qeth_l3_send_setassparms(card
, iob
, 0, 0,
1165 qeth_l3_default_setassparms_cb
, NULL
);
1170 static int qeth_l3_send_simple_setassparms(struct qeth_card
*card
,
1171 enum qeth_ipa_funcs ipa_func
, __u16 cmd_code
, long data
)
1175 struct qeth_cmd_buffer
*iob
;
1177 QETH_DBF_TEXT(TRACE
, 4, "simassp4");
1179 length
= sizeof(__u32
);
1180 iob
= qeth_l3_get_setassparms_cmd(card
, ipa_func
, cmd_code
,
1181 length
, QETH_PROT_IPV4
);
1182 rc
= qeth_l3_send_setassparms(card
, iob
, length
, data
,
1183 qeth_l3_default_setassparms_cb
, NULL
);
1187 static int qeth_l3_start_ipa_arp_processing(struct qeth_card
*card
)
1191 QETH_DBF_TEXT(TRACE
, 3, "ipaarp");
1193 if (!qeth_is_supported(card
, IPA_ARP_PROCESSING
)) {
1194 dev_info(&card
->gdev
->dev
,
1195 "ARP processing not supported on %s!\n",
1196 QETH_CARD_IFNAME(card
));
1199 rc
= qeth_l3_send_simple_setassparms(card
, IPA_ARP_PROCESSING
,
1200 IPA_CMD_ASS_START
, 0);
1202 dev_warn(&card
->gdev
->dev
,
1203 "Starting ARP processing support for %s failed\n",
1204 QETH_CARD_IFNAME(card
));
1209 static int qeth_l3_start_ipa_ip_fragmentation(struct qeth_card
*card
)
1213 QETH_DBF_TEXT(TRACE
, 3, "ipaipfrg");
1215 if (!qeth_is_supported(card
, IPA_IP_FRAGMENTATION
)) {
1216 dev_info(&card
->gdev
->dev
,
1217 "Hardware IP fragmentation not supported on %s\n",
1218 QETH_CARD_IFNAME(card
));
1222 rc
= qeth_l3_send_simple_setassparms(card
, IPA_IP_FRAGMENTATION
,
1223 IPA_CMD_ASS_START
, 0);
1225 dev_warn(&card
->gdev
->dev
,
1226 "Starting IP fragmentation support for %s failed\n",
1227 QETH_CARD_IFNAME(card
));
1229 dev_info(&card
->gdev
->dev
,
1230 "Hardware IP fragmentation enabled \n");
1234 static int qeth_l3_start_ipa_source_mac(struct qeth_card
*card
)
1238 QETH_DBF_TEXT(TRACE
, 3, "stsrcmac");
1240 if (!qeth_is_supported(card
, IPA_SOURCE_MAC
)) {
1241 dev_info(&card
->gdev
->dev
,
1242 "Inbound source MAC-address not supported on %s\n",
1243 QETH_CARD_IFNAME(card
));
1247 rc
= qeth_l3_send_simple_setassparms(card
, IPA_SOURCE_MAC
,
1248 IPA_CMD_ASS_START
, 0);
1250 dev_warn(&card
->gdev
->dev
,
1251 "Starting source MAC-address support for %s failed\n",
1252 QETH_CARD_IFNAME(card
));
1256 static int qeth_l3_start_ipa_vlan(struct qeth_card
*card
)
1260 QETH_DBF_TEXT(TRACE
, 3, "strtvlan");
1262 if (!qeth_is_supported(card
, IPA_FULL_VLAN
)) {
1263 dev_info(&card
->gdev
->dev
,
1264 "VLAN not supported on %s\n", QETH_CARD_IFNAME(card
));
1268 rc
= qeth_l3_send_simple_setassparms(card
, IPA_VLAN_PRIO
,
1269 IPA_CMD_ASS_START
, 0);
1271 dev_warn(&card
->gdev
->dev
,
1272 "Starting VLAN support for %s failed\n",
1273 QETH_CARD_IFNAME(card
));
1275 dev_info(&card
->gdev
->dev
, "VLAN enabled\n");
1280 static int qeth_l3_start_ipa_multicast(struct qeth_card
*card
)
1284 QETH_DBF_TEXT(TRACE
, 3, "stmcast");
1286 if (!qeth_is_supported(card
, IPA_MULTICASTING
)) {
1287 dev_info(&card
->gdev
->dev
,
1288 "Multicast not supported on %s\n",
1289 QETH_CARD_IFNAME(card
));
1293 rc
= qeth_l3_send_simple_setassparms(card
, IPA_MULTICASTING
,
1294 IPA_CMD_ASS_START
, 0);
1296 dev_warn(&card
->gdev
->dev
,
1297 "Starting multicast support for %s failed\n",
1298 QETH_CARD_IFNAME(card
));
1300 dev_info(&card
->gdev
->dev
, "Multicast enabled\n");
1301 card
->dev
->flags
|= IFF_MULTICAST
;
1306 static int qeth_l3_query_ipassists_cb(struct qeth_card
*card
,
1307 struct qeth_reply
*reply
, unsigned long data
)
1309 struct qeth_ipa_cmd
*cmd
;
1311 QETH_DBF_TEXT(SETUP
, 2, "qipasscb");
1313 cmd
= (struct qeth_ipa_cmd
*) data
;
1314 if (cmd
->hdr
.prot_version
== QETH_PROT_IPV4
) {
1315 card
->options
.ipa4
.supported_funcs
= cmd
->hdr
.ipa_supported
;
1316 card
->options
.ipa4
.enabled_funcs
= cmd
->hdr
.ipa_enabled
;
1318 card
->options
.ipa6
.supported_funcs
= cmd
->hdr
.ipa_supported
;
1319 card
->options
.ipa6
.enabled_funcs
= cmd
->hdr
.ipa_enabled
;
1321 QETH_DBF_TEXT(SETUP
, 2, "suppenbl");
1322 QETH_DBF_TEXT_(SETUP
, 2, "%x", cmd
->hdr
.ipa_supported
);
1323 QETH_DBF_TEXT_(SETUP
, 2, "%x", cmd
->hdr
.ipa_enabled
);
1327 static int qeth_l3_query_ipassists(struct qeth_card
*card
,
1328 enum qeth_prot_versions prot
)
1331 struct qeth_cmd_buffer
*iob
;
1333 QETH_DBF_TEXT_(SETUP
, 2, "qipassi%i", prot
);
1334 iob
= qeth_get_ipacmd_buffer(card
, IPA_CMD_QIPASSIST
, prot
);
1335 rc
= qeth_send_ipa_cmd(card
, iob
, qeth_l3_query_ipassists_cb
, NULL
);
1339 #ifdef CONFIG_QETH_IPV6
1340 static int qeth_l3_softsetup_ipv6(struct qeth_card
*card
)
1344 QETH_DBF_TEXT(TRACE
, 3, "softipv6");
1346 if (card
->info
.type
== QETH_CARD_TYPE_IQD
)
1349 rc
= qeth_l3_query_ipassists(card
, QETH_PROT_IPV6
);
1351 dev_err(&card
->gdev
->dev
,
1352 "Activating IPv6 support for %s failed\n",
1353 QETH_CARD_IFNAME(card
));
1356 rc
= qeth_l3_send_simple_setassparms(card
, IPA_IPV6
,
1357 IPA_CMD_ASS_START
, 3);
1359 dev_err(&card
->gdev
->dev
,
1360 "Activating IPv6 support for %s failed\n",
1361 QETH_CARD_IFNAME(card
));
1364 rc
= qeth_l3_send_simple_setassparms_ipv6(card
, IPA_IPV6
,
1367 dev_err(&card
->gdev
->dev
,
1368 "Activating IPv6 support for %s failed\n",
1369 QETH_CARD_IFNAME(card
));
1372 rc
= qeth_l3_send_simple_setassparms_ipv6(card
, IPA_PASSTHRU
,
1375 dev_warn(&card
->gdev
->dev
,
1376 "Enabling the passthrough mode for %s failed\n",
1377 QETH_CARD_IFNAME(card
));
1381 dev_info(&card
->gdev
->dev
, "IPV6 enabled\n");
1386 static int qeth_l3_start_ipa_ipv6(struct qeth_card
*card
)
1390 QETH_DBF_TEXT(TRACE
, 3, "strtipv6");
1392 if (!qeth_is_supported(card
, IPA_IPV6
)) {
1393 dev_info(&card
->gdev
->dev
,
1394 "IPv6 not supported on %s\n", QETH_CARD_IFNAME(card
));
1397 #ifdef CONFIG_QETH_IPV6
1398 rc
= qeth_l3_softsetup_ipv6(card
);
1403 static int qeth_l3_start_ipa_broadcast(struct qeth_card
*card
)
1407 QETH_DBF_TEXT(TRACE
, 3, "stbrdcst");
1408 card
->info
.broadcast_capable
= 0;
1409 if (!qeth_is_supported(card
, IPA_FILTERING
)) {
1410 dev_info(&card
->gdev
->dev
,
1411 "Broadcast not supported on %s\n",
1412 QETH_CARD_IFNAME(card
));
1416 rc
= qeth_l3_send_simple_setassparms(card
, IPA_FILTERING
,
1417 IPA_CMD_ASS_START
, 0);
1419 dev_warn(&card
->gdev
->dev
, "Enabling broadcast filtering for "
1420 "%s failed\n", QETH_CARD_IFNAME(card
));
1424 rc
= qeth_l3_send_simple_setassparms(card
, IPA_FILTERING
,
1425 IPA_CMD_ASS_CONFIGURE
, 1);
1427 dev_warn(&card
->gdev
->dev
,
1428 "Setting up broadcast filtering for %s failed\n",
1429 QETH_CARD_IFNAME(card
));
1432 card
->info
.broadcast_capable
= QETH_BROADCAST_WITH_ECHO
;
1433 dev_info(&card
->gdev
->dev
, "Broadcast enabled\n");
1434 rc
= qeth_l3_send_simple_setassparms(card
, IPA_FILTERING
,
1435 IPA_CMD_ASS_ENABLE
, 1);
1437 dev_warn(&card
->gdev
->dev
, "Setting up broadcast echo "
1438 "filtering for %s failed\n", QETH_CARD_IFNAME(card
));
1441 card
->info
.broadcast_capable
= QETH_BROADCAST_WITHOUT_ECHO
;
1443 if (card
->info
.broadcast_capable
)
1444 card
->dev
->flags
|= IFF_BROADCAST
;
1446 card
->dev
->flags
&= ~IFF_BROADCAST
;
1450 static int qeth_l3_send_checksum_command(struct qeth_card
*card
)
1454 rc
= qeth_l3_send_simple_setassparms(card
, IPA_INBOUND_CHECKSUM
,
1455 IPA_CMD_ASS_START
, 0);
1457 dev_warn(&card
->gdev
->dev
, "Starting HW checksumming for %s "
1458 "failed, using SW checksumming\n",
1459 QETH_CARD_IFNAME(card
));
1462 rc
= qeth_l3_send_simple_setassparms(card
, IPA_INBOUND_CHECKSUM
,
1464 card
->info
.csum_mask
);
1466 dev_warn(&card
->gdev
->dev
, "Enabling HW checksumming for %s "
1467 "failed, using SW checksumming\n",
1468 QETH_CARD_IFNAME(card
));
1474 int qeth_l3_set_rx_csum(struct qeth_card
*card
,
1475 enum qeth_checksum_types csum_type
)
1479 if (card
->options
.checksum_type
== HW_CHECKSUMMING
) {
1480 if ((csum_type
!= HW_CHECKSUMMING
) &&
1481 (card
->state
!= CARD_STATE_DOWN
)) {
1482 rc
= qeth_l3_send_simple_setassparms(card
,
1483 IPA_INBOUND_CHECKSUM
, IPA_CMD_ASS_STOP
, 0);
1488 if (csum_type
== HW_CHECKSUMMING
) {
1489 if (card
->state
!= CARD_STATE_DOWN
) {
1490 if (!qeth_is_supported(card
,
1491 IPA_INBOUND_CHECKSUM
))
1493 rc
= qeth_l3_send_checksum_command(card
);
1499 card
->options
.checksum_type
= csum_type
;
1503 static int qeth_l3_start_ipa_checksum(struct qeth_card
*card
)
1507 QETH_DBF_TEXT(TRACE
, 3, "strtcsum");
1509 if (card
->options
.checksum_type
== NO_CHECKSUMMING
) {
1510 dev_info(&card
->gdev
->dev
,
1511 "Using no checksumming on %s.\n",
1512 QETH_CARD_IFNAME(card
));
1515 if (card
->options
.checksum_type
== SW_CHECKSUMMING
) {
1516 dev_info(&card
->gdev
->dev
,
1517 "Using SW checksumming on %s.\n",
1518 QETH_CARD_IFNAME(card
));
1521 if (!qeth_is_supported(card
, IPA_INBOUND_CHECKSUM
)) {
1522 dev_info(&card
->gdev
->dev
,
1523 "Inbound HW Checksumming not "
1524 "supported on %s,\ncontinuing "
1525 "using Inbound SW Checksumming\n",
1526 QETH_CARD_IFNAME(card
));
1527 card
->options
.checksum_type
= SW_CHECKSUMMING
;
1530 rc
= qeth_l3_send_checksum_command(card
);
1532 dev_info(&card
->gdev
->dev
,
1533 "HW Checksumming (inbound) enabled\n");
1538 static int qeth_l3_start_ipa_tso(struct qeth_card
*card
)
1542 QETH_DBF_TEXT(TRACE
, 3, "sttso");
1544 if (!qeth_is_supported(card
, IPA_OUTBOUND_TSO
)) {
1545 dev_info(&card
->gdev
->dev
,
1546 "Outbound TSO not supported on %s\n",
1547 QETH_CARD_IFNAME(card
));
1550 rc
= qeth_l3_send_simple_setassparms(card
, IPA_OUTBOUND_TSO
,
1551 IPA_CMD_ASS_START
, 0);
1553 dev_warn(&card
->gdev
->dev
, "Starting outbound TCP "
1554 "segmentation offload for %s failed\n",
1555 QETH_CARD_IFNAME(card
));
1557 dev_info(&card
->gdev
->dev
,
1558 "Outbound TSO enabled\n");
1560 if (rc
&& (card
->options
.large_send
== QETH_LARGE_SEND_TSO
)) {
1561 card
->options
.large_send
= QETH_LARGE_SEND_NO
;
1562 card
->dev
->features
&= ~(NETIF_F_TSO
| NETIF_F_SG
);
1567 static int qeth_l3_start_ipassists(struct qeth_card
*card
)
1569 QETH_DBF_TEXT(TRACE
, 3, "strtipas");
1571 qeth_set_access_ctrl_online(card
); /* go on*/
1572 qeth_l3_start_ipa_arp_processing(card
); /* go on*/
1573 qeth_l3_start_ipa_ip_fragmentation(card
); /* go on*/
1574 qeth_l3_start_ipa_source_mac(card
); /* go on*/
1575 qeth_l3_start_ipa_vlan(card
); /* go on*/
1576 qeth_l3_start_ipa_multicast(card
); /* go on*/
1577 qeth_l3_start_ipa_ipv6(card
); /* go on*/
1578 qeth_l3_start_ipa_broadcast(card
); /* go on*/
1579 qeth_l3_start_ipa_checksum(card
); /* go on*/
1580 qeth_l3_start_ipa_tso(card
); /* go on*/
1584 static int qeth_l3_put_unique_id(struct qeth_card
*card
)
1588 struct qeth_cmd_buffer
*iob
;
1589 struct qeth_ipa_cmd
*cmd
;
1591 QETH_DBF_TEXT(TRACE
, 2, "puniqeid");
1593 if ((card
->info
.unique_id
& UNIQUE_ID_NOT_BY_CARD
) ==
1594 UNIQUE_ID_NOT_BY_CARD
)
1596 iob
= qeth_get_ipacmd_buffer(card
, IPA_CMD_DESTROY_ADDR
,
1598 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
1599 *((__u16
*) &cmd
->data
.create_destroy_addr
.unique_id
[6]) =
1600 card
->info
.unique_id
;
1601 memcpy(&cmd
->data
.create_destroy_addr
.unique_id
[0],
1602 card
->dev
->dev_addr
, OSA_ADDR_LEN
);
1603 rc
= qeth_send_ipa_cmd(card
, iob
, NULL
, NULL
);
1607 static int qeth_l3_iqd_read_initial_mac_cb(struct qeth_card
*card
,
1608 struct qeth_reply
*reply
, unsigned long data
)
1610 struct qeth_ipa_cmd
*cmd
;
1612 cmd
= (struct qeth_ipa_cmd
*) data
;
1613 if (cmd
->hdr
.return_code
== 0)
1614 memcpy(card
->dev
->dev_addr
,
1615 cmd
->data
.create_destroy_addr
.unique_id
, ETH_ALEN
);
1617 random_ether_addr(card
->dev
->dev_addr
);
1622 static int qeth_l3_iqd_read_initial_mac(struct qeth_card
*card
)
1625 struct qeth_cmd_buffer
*iob
;
1626 struct qeth_ipa_cmd
*cmd
;
1628 QETH_DBF_TEXT(SETUP
, 2, "hsrmac");
1630 iob
= qeth_get_ipacmd_buffer(card
, IPA_CMD_CREATE_ADDR
,
1632 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
1633 *((__u16
*) &cmd
->data
.create_destroy_addr
.unique_id
[6]) =
1634 card
->info
.unique_id
;
1636 rc
= qeth_send_ipa_cmd(card
, iob
, qeth_l3_iqd_read_initial_mac_cb
,
1641 static int qeth_l3_get_unique_id_cb(struct qeth_card
*card
,
1642 struct qeth_reply
*reply
, unsigned long data
)
1644 struct qeth_ipa_cmd
*cmd
;
1646 cmd
= (struct qeth_ipa_cmd
*) data
;
1647 if (cmd
->hdr
.return_code
== 0)
1648 card
->info
.unique_id
= *((__u16
*)
1649 &cmd
->data
.create_destroy_addr
.unique_id
[6]);
1651 card
->info
.unique_id
= UNIQUE_ID_IF_CREATE_ADDR_FAILED
|
1652 UNIQUE_ID_NOT_BY_CARD
;
1653 dev_warn(&card
->gdev
->dev
, "The network adapter failed to "
1654 "generate a unique ID\n");
1659 static int qeth_l3_get_unique_id(struct qeth_card
*card
)
1662 struct qeth_cmd_buffer
*iob
;
1663 struct qeth_ipa_cmd
*cmd
;
1665 QETH_DBF_TEXT(SETUP
, 2, "guniqeid");
1667 if (!qeth_is_supported(card
, IPA_IPV6
)) {
1668 card
->info
.unique_id
= UNIQUE_ID_IF_CREATE_ADDR_FAILED
|
1669 UNIQUE_ID_NOT_BY_CARD
;
1673 iob
= qeth_get_ipacmd_buffer(card
, IPA_CMD_CREATE_ADDR
,
1675 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
1676 *((__u16
*) &cmd
->data
.create_destroy_addr
.unique_id
[6]) =
1677 card
->info
.unique_id
;
1679 rc
= qeth_send_ipa_cmd(card
, iob
, qeth_l3_get_unique_id_cb
, NULL
);
1684 qeth_diags_trace_cb(struct qeth_card
*card
, struct qeth_reply
*reply
,
1687 struct qeth_ipa_cmd
*cmd
;
1690 QETH_DBF_TEXT(SETUP
, 2, "diastrcb");
1692 cmd
= (struct qeth_ipa_cmd
*)data
;
1693 rc
= cmd
->hdr
.return_code
;
1695 QETH_DBF_TEXT_(TRACE
, 2, "dxter%x", rc
);
1696 switch (cmd
->data
.diagass
.action
) {
1697 case QETH_DIAGS_CMD_TRACE_QUERY
:
1699 case QETH_DIAGS_CMD_TRACE_DISABLE
:
1702 case IPA_RC_INVALID_SUBCMD
:
1703 card
->info
.promisc_mode
= SET_PROMISC_MODE_OFF
;
1704 dev_info(&card
->gdev
->dev
, "The HiperSockets network "
1705 "traffic analyzer is deactivated\n");
1711 case QETH_DIAGS_CMD_TRACE_ENABLE
:
1714 card
->info
.promisc_mode
= SET_PROMISC_MODE_ON
;
1715 dev_info(&card
->gdev
->dev
, "The HiperSockets network "
1716 "traffic analyzer is activated\n");
1718 case IPA_RC_HARDWARE_AUTH_ERROR
:
1719 dev_warn(&card
->gdev
->dev
, "The device is not "
1720 "authorized to run as a HiperSockets network "
1721 "traffic analyzer\n");
1723 case IPA_RC_TRACE_ALREADY_ACTIVE
:
1724 dev_warn(&card
->gdev
->dev
, "A HiperSockets "
1725 "network traffic analyzer is already "
1726 "active in the HiperSockets LAN\n");
1733 QETH_DBF_MESSAGE(2, "Unknown sniffer action (0x%04x) on %s\n",
1734 cmd
->data
.diagass
.action
, QETH_CARD_IFNAME(card
));
1741 qeth_diags_trace(struct qeth_card
*card
, enum qeth_diags_trace_cmds diags_cmd
)
1743 struct qeth_cmd_buffer
*iob
;
1744 struct qeth_ipa_cmd
*cmd
;
1746 QETH_DBF_TEXT(SETUP
, 2, "diagtrac");
1748 iob
= qeth_get_ipacmd_buffer(card
, IPA_CMD_SET_DIAG_ASS
, 0);
1749 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
1750 cmd
->data
.diagass
.subcmd_len
= 16;
1751 cmd
->data
.diagass
.subcmd
= QETH_DIAGS_CMD_TRACE
;
1752 cmd
->data
.diagass
.type
= QETH_DIAGS_TYPE_HIPERSOCKET
;
1753 cmd
->data
.diagass
.action
= diags_cmd
;
1754 return qeth_send_ipa_cmd(card
, iob
, qeth_diags_trace_cb
, NULL
);
1757 static void qeth_l3_get_mac_for_ipm(__u32 ipm
, char *mac
,
1758 struct net_device
*dev
)
1760 if (dev
->type
== ARPHRD_IEEE802_TR
)
1761 ip_tr_mc_map(ipm
, mac
);
1763 ip_eth_mc_map(ipm
, mac
);
1766 static void qeth_l3_add_mc(struct qeth_card
*card
, struct in_device
*in4_dev
)
1768 struct qeth_ipaddr
*ipm
;
1769 struct ip_mc_list
*im4
;
1770 char buf
[MAX_ADDR_LEN
];
1772 QETH_DBF_TEXT(TRACE
, 4, "addmc");
1773 for (im4
= in4_dev
->mc_list
; im4
; im4
= im4
->next
) {
1774 qeth_l3_get_mac_for_ipm(im4
->multiaddr
, buf
, in4_dev
->dev
);
1775 ipm
= qeth_l3_get_addr_buffer(QETH_PROT_IPV4
);
1778 ipm
->u
.a4
.addr
= im4
->multiaddr
;
1779 memcpy(ipm
->mac
, buf
, OSA_ADDR_LEN
);
1780 ipm
->is_multicast
= 1;
1781 if (!qeth_l3_add_ip(card
, ipm
))
1786 static void qeth_l3_add_vlan_mc(struct qeth_card
*card
)
1788 struct in_device
*in_dev
;
1789 struct vlan_group
*vg
;
1792 QETH_DBF_TEXT(TRACE
, 4, "addmcvl");
1793 if (!qeth_is_supported(card
, IPA_FULL_VLAN
) || (card
->vlangrp
== NULL
))
1797 for (i
= 0; i
< VLAN_GROUP_ARRAY_LEN
; i
++) {
1798 struct net_device
*netdev
= vlan_group_get_device(vg
, i
);
1799 if (netdev
== NULL
||
1800 !(netdev
->flags
& IFF_UP
))
1802 in_dev
= in_dev_get(netdev
);
1805 read_lock(&in_dev
->mc_list_lock
);
1806 qeth_l3_add_mc(card
, in_dev
);
1807 read_unlock(&in_dev
->mc_list_lock
);
1812 static void qeth_l3_add_multicast_ipv4(struct qeth_card
*card
)
1814 struct in_device
*in4_dev
;
1816 QETH_DBF_TEXT(TRACE
, 4, "chkmcv4");
1817 in4_dev
= in_dev_get(card
->dev
);
1818 if (in4_dev
== NULL
)
1820 read_lock(&in4_dev
->mc_list_lock
);
1821 qeth_l3_add_mc(card
, in4_dev
);
1822 qeth_l3_add_vlan_mc(card
);
1823 read_unlock(&in4_dev
->mc_list_lock
);
1824 in_dev_put(in4_dev
);
1827 #ifdef CONFIG_QETH_IPV6
1828 static void qeth_l3_add_mc6(struct qeth_card
*card
, struct inet6_dev
*in6_dev
)
1830 struct qeth_ipaddr
*ipm
;
1831 struct ifmcaddr6
*im6
;
1832 char buf
[MAX_ADDR_LEN
];
1834 QETH_DBF_TEXT(TRACE
, 4, "addmc6");
1835 for (im6
= in6_dev
->mc_list
; im6
!= NULL
; im6
= im6
->next
) {
1836 ndisc_mc_map(&im6
->mca_addr
, buf
, in6_dev
->dev
, 0);
1837 ipm
= qeth_l3_get_addr_buffer(QETH_PROT_IPV6
);
1840 ipm
->is_multicast
= 1;
1841 memcpy(ipm
->mac
, buf
, OSA_ADDR_LEN
);
1842 memcpy(&ipm
->u
.a6
.addr
, &im6
->mca_addr
.s6_addr
,
1843 sizeof(struct in6_addr
));
1844 if (!qeth_l3_add_ip(card
, ipm
))
1849 static void qeth_l3_add_vlan_mc6(struct qeth_card
*card
)
1851 struct inet6_dev
*in_dev
;
1852 struct vlan_group
*vg
;
1855 QETH_DBF_TEXT(TRACE
, 4, "admc6vl");
1856 if (!qeth_is_supported(card
, IPA_FULL_VLAN
) || (card
->vlangrp
== NULL
))
1860 for (i
= 0; i
< VLAN_GROUP_ARRAY_LEN
; i
++) {
1861 struct net_device
*netdev
= vlan_group_get_device(vg
, i
);
1862 if (netdev
== NULL
||
1863 !(netdev
->flags
& IFF_UP
))
1865 in_dev
= in6_dev_get(netdev
);
1868 read_lock_bh(&in_dev
->lock
);
1869 qeth_l3_add_mc6(card
, in_dev
);
1870 read_unlock_bh(&in_dev
->lock
);
1871 in6_dev_put(in_dev
);
1875 static void qeth_l3_add_multicast_ipv6(struct qeth_card
*card
)
1877 struct inet6_dev
*in6_dev
;
1879 QETH_DBF_TEXT(TRACE
, 4, "chkmcv6");
1880 if (!qeth_is_supported(card
, IPA_IPV6
))
1882 in6_dev
= in6_dev_get(card
->dev
);
1883 if (in6_dev
== NULL
)
1885 read_lock_bh(&in6_dev
->lock
);
1886 qeth_l3_add_mc6(card
, in6_dev
);
1887 qeth_l3_add_vlan_mc6(card
);
1888 read_unlock_bh(&in6_dev
->lock
);
1889 in6_dev_put(in6_dev
);
1891 #endif /* CONFIG_QETH_IPV6 */
1893 static void qeth_l3_free_vlan_addresses4(struct qeth_card
*card
,
1896 struct in_device
*in_dev
;
1897 struct in_ifaddr
*ifa
;
1898 struct qeth_ipaddr
*addr
;
1900 QETH_DBF_TEXT(TRACE
, 4, "frvaddr4");
1902 in_dev
= in_dev_get(vlan_group_get_device(card
->vlangrp
, vid
));
1905 for (ifa
= in_dev
->ifa_list
; ifa
; ifa
= ifa
->ifa_next
) {
1906 addr
= qeth_l3_get_addr_buffer(QETH_PROT_IPV4
);
1908 addr
->u
.a4
.addr
= ifa
->ifa_address
;
1909 addr
->u
.a4
.mask
= ifa
->ifa_mask
;
1910 addr
->type
= QETH_IP_TYPE_NORMAL
;
1911 if (!qeth_l3_delete_ip(card
, addr
))
1918 static void qeth_l3_free_vlan_addresses6(struct qeth_card
*card
,
1921 #ifdef CONFIG_QETH_IPV6
1922 struct inet6_dev
*in6_dev
;
1923 struct inet6_ifaddr
*ifa
;
1924 struct qeth_ipaddr
*addr
;
1926 QETH_DBF_TEXT(TRACE
, 4, "frvaddr6");
1928 in6_dev
= in6_dev_get(vlan_group_get_device(card
->vlangrp
, vid
));
1931 for (ifa
= in6_dev
->addr_list
; ifa
; ifa
= ifa
->lst_next
) {
1932 addr
= qeth_l3_get_addr_buffer(QETH_PROT_IPV6
);
1934 memcpy(&addr
->u
.a6
.addr
, &ifa
->addr
,
1935 sizeof(struct in6_addr
));
1936 addr
->u
.a6
.pfxlen
= ifa
->prefix_len
;
1937 addr
->type
= QETH_IP_TYPE_NORMAL
;
1938 if (!qeth_l3_delete_ip(card
, addr
))
1942 in6_dev_put(in6_dev
);
1943 #endif /* CONFIG_QETH_IPV6 */
1946 static void qeth_l3_free_vlan_addresses(struct qeth_card
*card
,
1951 qeth_l3_free_vlan_addresses4(card
, vid
);
1952 qeth_l3_free_vlan_addresses6(card
, vid
);
1955 static void qeth_l3_vlan_rx_register(struct net_device
*dev
,
1956 struct vlan_group
*grp
)
1958 struct qeth_card
*card
= dev
->ml_priv
;
1959 unsigned long flags
;
1961 QETH_DBF_TEXT(TRACE
, 4, "vlanreg");
1962 spin_lock_irqsave(&card
->vlanlock
, flags
);
1963 card
->vlangrp
= grp
;
1964 spin_unlock_irqrestore(&card
->vlanlock
, flags
);
1967 static void qeth_l3_vlan_rx_add_vid(struct net_device
*dev
, unsigned short vid
)
1972 static void qeth_l3_vlan_rx_kill_vid(struct net_device
*dev
, unsigned short vid
)
1974 struct qeth_card
*card
= dev
->ml_priv
;
1975 unsigned long flags
;
1977 QETH_DBF_TEXT_(TRACE
, 4, "kid:%d", vid
);
1978 if (qeth_wait_for_threads(card
, QETH_RECOVER_THREAD
)) {
1979 QETH_DBF_TEXT(TRACE
, 3, "kidREC");
1982 spin_lock_irqsave(&card
->vlanlock
, flags
);
1983 /* unregister IP addresses of vlan device */
1984 qeth_l3_free_vlan_addresses(card
, vid
);
1985 vlan_group_set_device(card
->vlangrp
, vid
, NULL
);
1986 spin_unlock_irqrestore(&card
->vlanlock
, flags
);
1987 qeth_l3_set_multicast_list(card
->dev
);
1990 static inline __u16
qeth_l3_rebuild_skb(struct qeth_card
*card
,
1991 struct sk_buff
*skb
, struct qeth_hdr
*hdr
)
1993 unsigned short vlan_id
= 0;
1995 struct iphdr
*ip_hdr
;
1996 unsigned char tg_addr
[MAX_ADDR_LEN
];
1998 if (!(hdr
->hdr
.l3
.flags
& QETH_HDR_PASSTHRU
)) {
1999 prot
= htons((hdr
->hdr
.l3
.flags
& QETH_HDR_IPV6
)? ETH_P_IPV6
:
2001 switch (hdr
->hdr
.l3
.flags
& QETH_HDR_CAST_MASK
) {
2002 case QETH_CAST_MULTICAST
:
2004 #ifdef CONFIG_QETH_IPV6
2005 case __constant_htons(ETH_P_IPV6
):
2006 ndisc_mc_map((struct in6_addr
*)
2008 tg_addr
, card
->dev
, 0);
2011 case __constant_htons(ETH_P_IP
):
2012 ip_hdr
= (struct iphdr
*)skb
->data
;
2013 (card
->dev
->type
== ARPHRD_IEEE802_TR
) ?
2014 ip_tr_mc_map(ip_hdr
->daddr
, tg_addr
):
2015 ip_eth_mc_map(ip_hdr
->daddr
, tg_addr
);
2018 memcpy(tg_addr
, card
->dev
->broadcast
,
2019 card
->dev
->addr_len
);
2021 card
->stats
.multicast
++;
2022 skb
->pkt_type
= PACKET_MULTICAST
;
2024 case QETH_CAST_BROADCAST
:
2025 memcpy(tg_addr
, card
->dev
->broadcast
,
2026 card
->dev
->addr_len
);
2027 card
->stats
.multicast
++;
2028 skb
->pkt_type
= PACKET_BROADCAST
;
2030 case QETH_CAST_UNICAST
:
2031 case QETH_CAST_ANYCAST
:
2032 case QETH_CAST_NOCAST
:
2034 if (card
->options
.sniffer
)
2035 skb
->pkt_type
= PACKET_OTHERHOST
;
2037 skb
->pkt_type
= PACKET_HOST
;
2038 memcpy(tg_addr
, card
->dev
->dev_addr
,
2039 card
->dev
->addr_len
);
2041 if (hdr
->hdr
.l3
.ext_flags
& QETH_HDR_EXT_SRC_MAC_ADDR
)
2042 card
->dev
->header_ops
->create(skb
, card
->dev
, prot
,
2043 tg_addr
, &hdr
->hdr
.l3
.dest_addr
[2],
2044 card
->dev
->addr_len
);
2046 card
->dev
->header_ops
->create(skb
, card
->dev
, prot
,
2047 tg_addr
, "FAKELL", card
->dev
->addr_len
);
2051 if (card
->dev
->type
== ARPHRD_IEEE802_TR
)
2052 skb
->protocol
= tr_type_trans(skb
, card
->dev
);
2055 skb
->protocol
= eth_type_trans(skb
, card
->dev
);
2057 if (hdr
->hdr
.l3
.ext_flags
&
2058 (QETH_HDR_EXT_VLAN_FRAME
| QETH_HDR_EXT_INCLUDE_VLAN_TAG
)) {
2059 vlan_id
= (hdr
->hdr
.l3
.ext_flags
& QETH_HDR_EXT_VLAN_FRAME
)?
2060 hdr
->hdr
.l3
.vlan_id
: *((u16
*)&hdr
->hdr
.l3
.dest_addr
[12]);
2063 switch (card
->options
.checksum_type
) {
2064 case SW_CHECKSUMMING
:
2065 skb
->ip_summed
= CHECKSUM_NONE
;
2067 case NO_CHECKSUMMING
:
2068 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
2070 case HW_CHECKSUMMING
:
2071 if ((hdr
->hdr
.l3
.ext_flags
&
2072 (QETH_HDR_EXT_CSUM_HDR_REQ
|
2073 QETH_HDR_EXT_CSUM_TRANSP_REQ
)) ==
2074 (QETH_HDR_EXT_CSUM_HDR_REQ
|
2075 QETH_HDR_EXT_CSUM_TRANSP_REQ
))
2076 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
2078 skb
->ip_summed
= CHECKSUM_NONE
;
2084 static void qeth_l3_process_inbound_buffer(struct qeth_card
*card
,
2085 struct qeth_qdio_buffer
*buf
, int index
)
2087 struct qdio_buffer_element
*element
;
2088 struct sk_buff
*skb
;
2089 struct qeth_hdr
*hdr
;
2093 /* get first element of current buffer */
2094 element
= (struct qdio_buffer_element
*)&buf
->buffer
->element
[0];
2096 if (card
->options
.performance_stats
)
2097 card
->perf_stats
.bufs_rec
++;
2098 while ((skb
= qeth_core_get_next_skb(card
, buf
->buffer
, &element
,
2100 skb
->dev
= card
->dev
;
2101 /* is device UP ? */
2102 if (!(card
->dev
->flags
& IFF_UP
)) {
2103 dev_kfree_skb_any(skb
);
2107 switch (hdr
->hdr
.l3
.id
) {
2108 case QETH_HEADER_TYPE_LAYER3
:
2109 vlan_tag
= qeth_l3_rebuild_skb(card
, skb
, hdr
);
2111 if (vlan_tag
&& !card
->options
.sniffer
)
2113 vlan_hwaccel_rx(skb
, card
->vlangrp
,
2116 dev_kfree_skb_any(skb
);
2122 case QETH_HEADER_TYPE_LAYER2
: /* for HiperSockets sniffer */
2123 skb
->pkt_type
= PACKET_HOST
;
2124 skb
->protocol
= eth_type_trans(skb
, skb
->dev
);
2125 if (card
->options
.checksum_type
== NO_CHECKSUMMING
)
2126 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
2128 skb
->ip_summed
= CHECKSUM_NONE
;
2130 netif_receive_skb(skb
);
2133 dev_kfree_skb_any(skb
);
2134 QETH_DBF_TEXT(TRACE
, 3, "inbunkno");
2135 QETH_DBF_HEX(CTRL
, 3, hdr
, QETH_DBF_CTRL_LEN
);
2139 card
->stats
.rx_packets
++;
2140 card
->stats
.rx_bytes
+= len
;
2144 static int qeth_l3_verify_vlan_dev(struct net_device
*dev
,
2145 struct qeth_card
*card
)
2148 struct vlan_group
*vg
;
2155 for (i
= 0; i
< VLAN_GROUP_ARRAY_LEN
; i
++) {
2156 if (vlan_group_get_device(vg
, i
) == dev
) {
2157 rc
= QETH_VLAN_CARD
;
2162 if (rc
&& !(vlan_dev_real_dev(dev
)->ml_priv
== (void *)card
))
2168 static int qeth_l3_verify_dev(struct net_device
*dev
)
2170 struct qeth_card
*card
;
2171 unsigned long flags
;
2174 read_lock_irqsave(&qeth_core_card_list
.rwlock
, flags
);
2175 list_for_each_entry(card
, &qeth_core_card_list
.list
, list
) {
2176 if (card
->dev
== dev
) {
2177 rc
= QETH_REAL_CARD
;
2180 rc
= qeth_l3_verify_vlan_dev(dev
, card
);
2184 read_unlock_irqrestore(&qeth_core_card_list
.rwlock
, flags
);
2189 static struct qeth_card
*qeth_l3_get_card_from_dev(struct net_device
*dev
)
2191 struct qeth_card
*card
= NULL
;
2194 rc
= qeth_l3_verify_dev(dev
);
2195 if (rc
== QETH_REAL_CARD
)
2196 card
= dev
->ml_priv
;
2197 else if (rc
== QETH_VLAN_CARD
)
2198 card
= vlan_dev_real_dev(dev
)->ml_priv
;
2199 if (card
&& card
->options
.layer2
)
2201 QETH_DBF_TEXT_(TRACE
, 4, "%d", rc
);
2205 static int qeth_l3_stop_card(struct qeth_card
*card
, int recovery_mode
)
2209 QETH_DBF_TEXT(SETUP
, 2, "stopcard");
2210 QETH_DBF_HEX(SETUP
, 2, &card
, sizeof(void *));
2212 qeth_set_allowed_threads(card
, 0, 1);
2213 if (card
->options
.sniffer
&&
2214 (card
->info
.promisc_mode
== SET_PROMISC_MODE_ON
))
2215 qeth_diags_trace(card
, QETH_DIAGS_CMD_TRACE_DISABLE
);
2216 if (card
->read
.state
== CH_STATE_UP
&&
2217 card
->write
.state
== CH_STATE_UP
&&
2218 (card
->state
== CARD_STATE_UP
)) {
2220 qeth_l3_stop(card
->dev
);
2223 dev_close(card
->dev
);
2226 if (!card
->use_hard_stop
) {
2227 rc
= qeth_send_stoplan(card
);
2229 QETH_DBF_TEXT_(SETUP
, 2, "1err%d", rc
);
2231 card
->state
= CARD_STATE_SOFTSETUP
;
2233 if (card
->state
== CARD_STATE_SOFTSETUP
) {
2234 qeth_l3_clear_ip_list(card
, !card
->use_hard_stop
, 1);
2235 qeth_clear_ipacmd_list(card
);
2236 card
->state
= CARD_STATE_HARDSETUP
;
2238 if (card
->state
== CARD_STATE_HARDSETUP
) {
2239 if (!card
->use_hard_stop
&&
2240 (card
->info
.type
!= QETH_CARD_TYPE_IQD
)) {
2241 rc
= qeth_l3_put_unique_id(card
);
2243 QETH_DBF_TEXT_(SETUP
, 2, "2err%d", rc
);
2245 qeth_qdio_clear_card(card
, 0);
2246 qeth_clear_qdio_buffers(card
);
2247 qeth_clear_working_pool_list(card
);
2248 card
->state
= CARD_STATE_DOWN
;
2250 if (card
->state
== CARD_STATE_DOWN
) {
2251 qeth_clear_cmd_buffers(&card
->read
);
2252 qeth_clear_cmd_buffers(&card
->write
);
2254 card
->use_hard_stop
= 0;
2259 * test for and Switch promiscuous mode (on or off)
2260 * either for guestlan or HiperSocket Sniffer
2263 qeth_l3_handle_promisc_mode(struct qeth_card
*card
)
2265 struct net_device
*dev
= card
->dev
;
2267 if (((dev
->flags
& IFF_PROMISC
) &&
2268 (card
->info
.promisc_mode
== SET_PROMISC_MODE_ON
)) ||
2269 (!(dev
->flags
& IFF_PROMISC
) &&
2270 (card
->info
.promisc_mode
== SET_PROMISC_MODE_OFF
)))
2273 if (card
->info
.guestlan
) { /* Guestlan trace */
2274 if (qeth_adp_supported(card
, IPA_SETADP_SET_PROMISC_MODE
))
2275 qeth_setadp_promisc_mode(card
);
2276 } else if (card
->options
.sniffer
&& /* HiperSockets trace */
2277 qeth_adp_supported(card
, IPA_SETADP_SET_DIAG_ASSIST
)) {
2278 if (dev
->flags
& IFF_PROMISC
) {
2279 QETH_DBF_TEXT(TRACE
, 3, "+promisc");
2280 qeth_diags_trace(card
, QETH_DIAGS_CMD_TRACE_ENABLE
);
2282 QETH_DBF_TEXT(TRACE
, 3, "-promisc");
2283 qeth_diags_trace(card
, QETH_DIAGS_CMD_TRACE_DISABLE
);
2288 static void qeth_l3_set_multicast_list(struct net_device
*dev
)
2290 struct qeth_card
*card
= dev
->ml_priv
;
2292 QETH_DBF_TEXT(TRACE
, 3, "setmulti");
2293 if (qeth_threads_running(card
, QETH_RECOVER_THREAD
) &&
2294 (card
->state
!= CARD_STATE_UP
))
2296 if (!card
->options
.sniffer
) {
2297 qeth_l3_delete_mc_addresses(card
);
2298 qeth_l3_add_multicast_ipv4(card
);
2299 #ifdef CONFIG_QETH_IPV6
2300 qeth_l3_add_multicast_ipv6(card
);
2302 qeth_l3_set_ip_addr_list(card
);
2303 if (!qeth_adp_supported(card
, IPA_SETADP_SET_PROMISC_MODE
))
2306 qeth_l3_handle_promisc_mode(card
);
2309 static const char *qeth_l3_arp_get_error_cause(int *rc
)
2312 case QETH_IPA_ARP_RC_FAILED
:
2314 return "operation failed";
2315 case QETH_IPA_ARP_RC_NOTSUPP
:
2317 return "operation not supported";
2318 case QETH_IPA_ARP_RC_OUT_OF_RANGE
:
2320 return "argument out of range";
2321 case QETH_IPA_ARP_RC_Q_NOTSUPP
:
2323 return "query operation not supported";
2324 case QETH_IPA_ARP_RC_Q_NO_DATA
:
2326 return "no query data available";
2328 return "unknown error";
2332 static int qeth_l3_arp_set_no_entries(struct qeth_card
*card
, int no_entries
)
2337 QETH_DBF_TEXT(TRACE
, 3, "arpstnoe");
2340 * currently GuestLAN only supports the ARP assist function
2341 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_SET_NO_ENTRIES;
2342 * thus we say EOPNOTSUPP for this ARP function
2344 if (card
->info
.guestlan
)
2346 if (!qeth_is_supported(card
, IPA_ARP_PROCESSING
)) {
2349 rc
= qeth_l3_send_simple_setassparms(card
, IPA_ARP_PROCESSING
,
2350 IPA_CMD_ASS_ARP_SET_NO_ENTRIES
,
2354 QETH_DBF_MESSAGE(2, "Could not set number of ARP entries on "
2355 "%s: %s (0x%x/%d)\n", QETH_CARD_IFNAME(card
),
2356 qeth_l3_arp_get_error_cause(&rc
), tmp
, tmp
);
2361 static void qeth_l3_copy_arp_entries_stripped(struct qeth_arp_query_info
*qinfo
,
2362 struct qeth_arp_query_data
*qdata
, int entry_size
,
2369 entry_ptr
= (char *)&qdata
->data
;
2370 uentry_ptr
= (char *)(qinfo
->udata
+ qinfo
->udata_offset
);
2371 for (i
= 0; i
< qdata
->no_entries
; ++i
) {
2372 /* strip off 32 bytes "media specific information" */
2373 memcpy(uentry_ptr
, (entry_ptr
+ 32), entry_size
- 32);
2374 entry_ptr
+= entry_size
;
2375 uentry_ptr
+= uentry_size
;
2379 static int qeth_l3_arp_query_cb(struct qeth_card
*card
,
2380 struct qeth_reply
*reply
, unsigned long data
)
2382 struct qeth_ipa_cmd
*cmd
;
2383 struct qeth_arp_query_data
*qdata
;
2384 struct qeth_arp_query_info
*qinfo
;
2389 QETH_DBF_TEXT(TRACE
, 4, "arpquecb");
2391 qinfo
= (struct qeth_arp_query_info
*) reply
->param
;
2392 cmd
= (struct qeth_ipa_cmd
*) data
;
2393 if (cmd
->hdr
.return_code
) {
2394 QETH_DBF_TEXT_(TRACE
, 4, "qaer1%i", cmd
->hdr
.return_code
);
2397 if (cmd
->data
.setassparms
.hdr
.return_code
) {
2398 cmd
->hdr
.return_code
= cmd
->data
.setassparms
.hdr
.return_code
;
2399 QETH_DBF_TEXT_(TRACE
, 4, "qaer2%i", cmd
->hdr
.return_code
);
2402 qdata
= &cmd
->data
.setassparms
.data
.query_arp
;
2403 switch (qdata
->reply_bits
) {
2405 uentry_size
= entry_size
= sizeof(struct qeth_arp_qi_entry5
);
2406 if (qinfo
->mask_bits
& QETH_QARP_STRIP_ENTRIES
)
2407 uentry_size
= sizeof(struct qeth_arp_qi_entry5_short
);
2410 /* fall through to default */
2412 /* tr is the same as eth -> entry7 */
2413 uentry_size
= entry_size
= sizeof(struct qeth_arp_qi_entry7
);
2414 if (qinfo
->mask_bits
& QETH_QARP_STRIP_ENTRIES
)
2415 uentry_size
= sizeof(struct qeth_arp_qi_entry7_short
);
2418 /* check if there is enough room in userspace */
2419 if ((qinfo
->udata_len
- qinfo
->udata_offset
) <
2420 qdata
->no_entries
* uentry_size
){
2421 QETH_DBF_TEXT_(TRACE
, 4, "qaer3%i", -ENOMEM
);
2422 cmd
->hdr
.return_code
= -ENOMEM
;
2425 QETH_DBF_TEXT_(TRACE
, 4, "anore%i",
2426 cmd
->data
.setassparms
.hdr
.number_of_replies
);
2427 QETH_DBF_TEXT_(TRACE
, 4, "aseqn%i", cmd
->data
.setassparms
.hdr
.seq_no
);
2428 QETH_DBF_TEXT_(TRACE
, 4, "anoen%i", qdata
->no_entries
);
2430 if (qinfo
->mask_bits
& QETH_QARP_STRIP_ENTRIES
) {
2431 /* strip off "media specific information" */
2432 qeth_l3_copy_arp_entries_stripped(qinfo
, qdata
, entry_size
,
2435 /*copy entries to user buffer*/
2436 memcpy(qinfo
->udata
+ qinfo
->udata_offset
,
2437 (char *)&qdata
->data
, qdata
->no_entries
*uentry_size
);
2439 qinfo
->no_entries
+= qdata
->no_entries
;
2440 qinfo
->udata_offset
+= (qdata
->no_entries
*uentry_size
);
2441 /* check if all replies received ... */
2442 if (cmd
->data
.setassparms
.hdr
.seq_no
<
2443 cmd
->data
.setassparms
.hdr
.number_of_replies
)
2445 memcpy(qinfo
->udata
, &qinfo
->no_entries
, 4);
2446 /* keep STRIP_ENTRIES flag so the user program can distinguish
2447 * stripped entries from normal ones */
2448 if (qinfo
->mask_bits
& QETH_QARP_STRIP_ENTRIES
)
2449 qdata
->reply_bits
|= QETH_QARP_STRIP_ENTRIES
;
2450 memcpy(qinfo
->udata
+ QETH_QARP_MASK_OFFSET
, &qdata
->reply_bits
, 2);
2454 memcpy(qinfo
->udata
, &i
, 4);
2458 static int qeth_l3_send_ipa_arp_cmd(struct qeth_card
*card
,
2459 struct qeth_cmd_buffer
*iob
, int len
,
2460 int (*reply_cb
)(struct qeth_card
*, struct qeth_reply
*,
2464 QETH_DBF_TEXT(TRACE
, 4, "sendarp");
2466 memcpy(iob
->data
, IPA_PDU_HEADER
, IPA_PDU_HEADER_SIZE
);
2467 memcpy(QETH_IPA_CMD_DEST_ADDR(iob
->data
),
2468 &card
->token
.ulp_connection_r
, QETH_MPC_TOKEN_LENGTH
);
2469 return qeth_send_control_data(card
, IPA_PDU_HEADER_SIZE
+ len
, iob
,
2470 reply_cb
, reply_param
);
2473 static int qeth_l3_arp_query(struct qeth_card
*card
, char __user
*udata
)
2475 struct qeth_cmd_buffer
*iob
;
2476 struct qeth_arp_query_info qinfo
= {0, };
2480 QETH_DBF_TEXT(TRACE
, 3, "arpquery");
2482 if (!qeth_is_supported(card
,/*IPA_QUERY_ARP_ADDR_INFO*/
2483 IPA_ARP_PROCESSING
)) {
2486 /* get size of userspace buffer and mask_bits -> 6 bytes */
2487 if (copy_from_user(&qinfo
, udata
, 6))
2489 qinfo
.udata
= kzalloc(qinfo
.udata_len
, GFP_KERNEL
);
2492 qinfo
.udata_offset
= QETH_QARP_ENTRIES_OFFSET
;
2493 iob
= qeth_l3_get_setassparms_cmd(card
, IPA_ARP_PROCESSING
,
2494 IPA_CMD_ASS_ARP_QUERY_INFO
,
2495 sizeof(int), QETH_PROT_IPV4
);
2497 rc
= qeth_l3_send_ipa_arp_cmd(card
, iob
,
2498 QETH_SETASS_BASE_LEN
+QETH_ARP_CMD_LEN
,
2499 qeth_l3_arp_query_cb
, (void *)&qinfo
);
2502 QETH_DBF_MESSAGE(2, "Error while querying ARP cache on %s: %s "
2503 "(0x%x/%d)\n", QETH_CARD_IFNAME(card
),
2504 qeth_l3_arp_get_error_cause(&rc
), tmp
, tmp
);
2505 if (copy_to_user(udata
, qinfo
.udata
, 4))
2508 if (copy_to_user(udata
, qinfo
.udata
, qinfo
.udata_len
))
2515 static int qeth_l3_arp_add_entry(struct qeth_card
*card
,
2516 struct qeth_arp_cache_entry
*entry
)
2518 struct qeth_cmd_buffer
*iob
;
2523 QETH_DBF_TEXT(TRACE
, 3, "arpadent");
2526 * currently GuestLAN only supports the ARP assist function
2527 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_ADD_ENTRY;
2528 * thus we say EOPNOTSUPP for this ARP function
2530 if (card
->info
.guestlan
)
2532 if (!qeth_is_supported(card
, IPA_ARP_PROCESSING
)) {
2536 iob
= qeth_l3_get_setassparms_cmd(card
, IPA_ARP_PROCESSING
,
2537 IPA_CMD_ASS_ARP_ADD_ENTRY
,
2538 sizeof(struct qeth_arp_cache_entry
),
2540 rc
= qeth_l3_send_setassparms(card
, iob
,
2541 sizeof(struct qeth_arp_cache_entry
),
2542 (unsigned long) entry
,
2543 qeth_l3_default_setassparms_cb
, NULL
);
2546 qeth_l3_ipaddr4_to_string((u8
*)entry
->ipaddr
, buf
);
2547 QETH_DBF_MESSAGE(2, "Could not add ARP entry for address %s "
2548 "on %s: %s (0x%x/%d)\n", buf
, QETH_CARD_IFNAME(card
),
2549 qeth_l3_arp_get_error_cause(&rc
), tmp
, tmp
);
2554 static int qeth_l3_arp_remove_entry(struct qeth_card
*card
,
2555 struct qeth_arp_cache_entry
*entry
)
2557 struct qeth_cmd_buffer
*iob
;
2558 char buf
[16] = {0, };
2562 QETH_DBF_TEXT(TRACE
, 3, "arprment");
2565 * currently GuestLAN only supports the ARP assist function
2566 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_REMOVE_ENTRY;
2567 * thus we say EOPNOTSUPP for this ARP function
2569 if (card
->info
.guestlan
)
2571 if (!qeth_is_supported(card
, IPA_ARP_PROCESSING
)) {
2574 memcpy(buf
, entry
, 12);
2575 iob
= qeth_l3_get_setassparms_cmd(card
, IPA_ARP_PROCESSING
,
2576 IPA_CMD_ASS_ARP_REMOVE_ENTRY
,
2579 rc
= qeth_l3_send_setassparms(card
, iob
,
2580 12, (unsigned long)buf
,
2581 qeth_l3_default_setassparms_cb
, NULL
);
2585 qeth_l3_ipaddr4_to_string((u8
*)entry
->ipaddr
, buf
);
2586 QETH_DBF_MESSAGE(2, "Could not delete ARP entry for address %s"
2587 " on %s: %s (0x%x/%d)\n", buf
, QETH_CARD_IFNAME(card
),
2588 qeth_l3_arp_get_error_cause(&rc
), tmp
, tmp
);
2593 static int qeth_l3_arp_flush_cache(struct qeth_card
*card
)
2598 QETH_DBF_TEXT(TRACE
, 3, "arpflush");
2601 * currently GuestLAN only supports the ARP assist function
2602 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_FLUSH_CACHE;
2603 * thus we say EOPNOTSUPP for this ARP function
2605 if (card
->info
.guestlan
|| (card
->info
.type
== QETH_CARD_TYPE_IQD
))
2607 if (!qeth_is_supported(card
, IPA_ARP_PROCESSING
)) {
2610 rc
= qeth_l3_send_simple_setassparms(card
, IPA_ARP_PROCESSING
,
2611 IPA_CMD_ASS_ARP_FLUSH_CACHE
, 0);
2614 QETH_DBF_MESSAGE(2, "Could not flush ARP cache on %s: %s "
2615 "(0x%x/%d)\n", QETH_CARD_IFNAME(card
),
2616 qeth_l3_arp_get_error_cause(&rc
), tmp
, tmp
);
2621 static int qeth_l3_do_ioctl(struct net_device
*dev
, struct ifreq
*rq
, int cmd
)
2623 struct qeth_card
*card
= dev
->ml_priv
;
2624 struct qeth_arp_cache_entry arp_entry
;
2625 struct mii_ioctl_data
*mii_data
;
2631 if ((card
->state
!= CARD_STATE_UP
) &&
2632 (card
->state
!= CARD_STATE_SOFTSETUP
))
2636 case SIOC_QETH_ARP_SET_NO_ENTRIES
:
2637 if (!capable(CAP_NET_ADMIN
)) {
2641 rc
= qeth_l3_arp_set_no_entries(card
, rq
->ifr_ifru
.ifru_ivalue
);
2643 case SIOC_QETH_ARP_QUERY_INFO
:
2644 if (!capable(CAP_NET_ADMIN
)) {
2648 rc
= qeth_l3_arp_query(card
, rq
->ifr_ifru
.ifru_data
);
2650 case SIOC_QETH_ARP_ADD_ENTRY
:
2651 if (!capable(CAP_NET_ADMIN
)) {
2655 if (copy_from_user(&arp_entry
, rq
->ifr_ifru
.ifru_data
,
2656 sizeof(struct qeth_arp_cache_entry
)))
2659 rc
= qeth_l3_arp_add_entry(card
, &arp_entry
);
2661 case SIOC_QETH_ARP_REMOVE_ENTRY
:
2662 if (!capable(CAP_NET_ADMIN
)) {
2666 if (copy_from_user(&arp_entry
, rq
->ifr_ifru
.ifru_data
,
2667 sizeof(struct qeth_arp_cache_entry
)))
2670 rc
= qeth_l3_arp_remove_entry(card
, &arp_entry
);
2672 case SIOC_QETH_ARP_FLUSH_CACHE
:
2673 if (!capable(CAP_NET_ADMIN
)) {
2677 rc
= qeth_l3_arp_flush_cache(card
);
2679 case SIOC_QETH_ADP_SET_SNMP_CONTROL
:
2680 rc
= qeth_snmp_command(card
, rq
->ifr_ifru
.ifru_data
);
2682 case SIOC_QETH_GET_CARD_TYPE
:
2683 if ((card
->info
.type
== QETH_CARD_TYPE_OSAE
) &&
2684 !card
->info
.guestlan
)
2689 mii_data
= if_mii(rq
);
2690 mii_data
->phy_id
= 0;
2693 mii_data
= if_mii(rq
);
2694 if (mii_data
->phy_id
!= 0)
2697 mii_data
->val_out
= qeth_mdio_read(dev
,
2705 QETH_DBF_TEXT_(TRACE
, 2, "ioce%d", rc
);
2709 int inline qeth_l3_get_cast_type(struct qeth_card
*card
, struct sk_buff
*skb
)
2711 int cast_type
= RTN_UNSPEC
;
2713 if (skb_dst(skb
) && skb_dst(skb
)->neighbour
) {
2714 cast_type
= skb_dst(skb
)->neighbour
->type
;
2715 if ((cast_type
== RTN_BROADCAST
) ||
2716 (cast_type
== RTN_MULTICAST
) ||
2717 (cast_type
== RTN_ANYCAST
))
2722 /* try something else */
2723 if (skb
->protocol
== ETH_P_IPV6
)
2724 return (skb_network_header(skb
)[24] == 0xff) ?
2726 else if (skb
->protocol
== ETH_P_IP
)
2727 return ((skb_network_header(skb
)[16] & 0xf0) == 0xe0) ?
2730 if (!memcmp(skb
->data
, skb
->dev
->broadcast
, 6))
2731 return RTN_BROADCAST
;
2735 hdr_mac
= *((u16
*)skb
->data
);
2737 switch (card
->info
.link_type
) {
2738 case QETH_LINK_TYPE_HSTR
:
2739 case QETH_LINK_TYPE_LANE_TR
:
2740 if ((hdr_mac
== QETH_TR_MAC_NC
) ||
2741 (hdr_mac
== QETH_TR_MAC_C
))
2742 return RTN_MULTICAST
;
2744 /* eth or so multicast? */
2746 if ((hdr_mac
== QETH_ETH_MAC_V4
) ||
2747 (hdr_mac
== QETH_ETH_MAC_V6
))
2748 return RTN_MULTICAST
;
2754 static void qeth_l3_fill_header(struct qeth_card
*card
, struct qeth_hdr
*hdr
,
2755 struct sk_buff
*skb
, int ipv
, int cast_type
)
2757 memset(hdr
, 0, sizeof(struct qeth_hdr
));
2758 hdr
->hdr
.l3
.id
= QETH_HEADER_TYPE_LAYER3
;
2759 hdr
->hdr
.l3
.ext_flags
= 0;
2762 * before we're going to overwrite this location with next hop ip.
2763 * v6 uses passthrough, v4 sets the tag in the QDIO header.
2765 if (card
->vlangrp
&& vlan_tx_tag_present(skb
)) {
2766 if ((ipv
== 4) || (card
->info
.type
== QETH_CARD_TYPE_IQD
))
2767 hdr
->hdr
.l3
.ext_flags
= QETH_HDR_EXT_VLAN_FRAME
;
2769 hdr
->hdr
.l3
.ext_flags
= QETH_HDR_EXT_INCLUDE_VLAN_TAG
;
2770 hdr
->hdr
.l3
.vlan_id
= vlan_tx_tag_get(skb
);
2773 hdr
->hdr
.l3
.length
= skb
->len
- sizeof(struct qeth_hdr
);
2776 hdr
->hdr
.l3
.flags
= qeth_l3_get_qeth_hdr_flags4(cast_type
);
2777 memset(hdr
->hdr
.l3
.dest_addr
, 0, 12);
2778 if ((skb_dst(skb
)) && (skb_dst(skb
)->neighbour
)) {
2779 *((u32
*) (&hdr
->hdr
.l3
.dest_addr
[12])) =
2780 *((u32
*) skb_dst(skb
)->neighbour
->primary_key
);
2782 /* fill in destination address used in ip header */
2783 *((u32
*) (&hdr
->hdr
.l3
.dest_addr
[12])) =
2786 } else if (ipv
== 6) {
2788 hdr
->hdr
.l3
.flags
= qeth_l3_get_qeth_hdr_flags6(cast_type
);
2789 if (card
->info
.type
== QETH_CARD_TYPE_IQD
)
2790 hdr
->hdr
.l3
.flags
&= ~QETH_HDR_PASSTHRU
;
2791 if ((skb_dst(skb
)) && (skb_dst(skb
)->neighbour
)) {
2792 memcpy(hdr
->hdr
.l3
.dest_addr
,
2793 skb_dst(skb
)->neighbour
->primary_key
, 16);
2795 /* fill in destination address used in ip header */
2796 memcpy(hdr
->hdr
.l3
.dest_addr
,
2797 &ipv6_hdr(skb
)->daddr
, 16);
2801 if ((skb
->dev
->type
== ARPHRD_IEEE802_TR
) &&
2802 !memcmp(skb
->data
+ sizeof(struct qeth_hdr
) +
2803 sizeof(__u16
), skb
->dev
->broadcast
, 6)) {
2804 hdr
->hdr
.l3
.flags
= QETH_CAST_BROADCAST
|
2806 } else if (!memcmp(skb
->data
+ sizeof(struct qeth_hdr
),
2807 skb
->dev
->broadcast
, 6)) {
2809 hdr
->hdr
.l3
.flags
= QETH_CAST_BROADCAST
|
2812 hdr
->hdr
.l3
.flags
= (cast_type
== RTN_MULTICAST
) ?
2813 QETH_CAST_MULTICAST
| QETH_HDR_PASSTHRU
:
2814 QETH_CAST_UNICAST
| QETH_HDR_PASSTHRU
;
2819 static void qeth_tso_fill_header(struct qeth_card
*card
,
2820 struct qeth_hdr
*qhdr
, struct sk_buff
*skb
)
2822 struct qeth_hdr_tso
*hdr
= (struct qeth_hdr_tso
*)qhdr
;
2823 struct tcphdr
*tcph
= tcp_hdr(skb
);
2824 struct iphdr
*iph
= ip_hdr(skb
);
2825 struct ipv6hdr
*ip6h
= ipv6_hdr(skb
);
2827 /*fix header to TSO values ...*/
2828 hdr
->hdr
.hdr
.l3
.id
= QETH_HEADER_TYPE_TSO
;
2829 /*set values which are fix for the first approach ...*/
2830 hdr
->ext
.hdr_tot_len
= (__u16
) sizeof(struct qeth_hdr_ext_tso
);
2831 hdr
->ext
.imb_hdr_no
= 1;
2832 hdr
->ext
.hdr_type
= 1;
2833 hdr
->ext
.hdr_version
= 1;
2834 hdr
->ext
.hdr_len
= 28;
2835 /*insert non-fix values */
2836 hdr
->ext
.mss
= skb_shinfo(skb
)->gso_size
;
2837 hdr
->ext
.dg_hdr_len
= (__u16
)(iph
->ihl
*4 + tcph
->doff
*4);
2838 hdr
->ext
.payload_len
= (__u16
)(skb
->len
- hdr
->ext
.dg_hdr_len
-
2839 sizeof(struct qeth_hdr_tso
));
2841 if (skb
->protocol
== ETH_P_IPV6
) {
2842 ip6h
->payload_len
= 0;
2843 tcph
->check
= ~csum_ipv6_magic(&ip6h
->saddr
, &ip6h
->daddr
,
2846 /*OSA want us to set these values ...*/
2847 tcph
->check
= ~csum_tcpudp_magic(iph
->saddr
, iph
->daddr
,
2854 static void qeth_tx_csum(struct sk_buff
*skb
)
2859 skb_set_transport_header(skb
, skb
->csum_start
- skb_headroom(skb
));
2860 offset
= skb
->csum_start
- skb_headroom(skb
);
2861 BUG_ON(offset
>= skb_headlen(skb
));
2862 csum
= skb_checksum(skb
, offset
, skb
->len
- offset
, 0);
2864 offset
+= skb
->csum_offset
;
2865 BUG_ON(offset
+ sizeof(__sum16
) > skb_headlen(skb
));
2866 *(__sum16
*)(skb
->data
+ offset
) = csum_fold(csum
);
2869 static inline int qeth_l3_tso_elements(struct sk_buff
*skb
)
2871 unsigned long tcpd
= (unsigned long)tcp_hdr(skb
) +
2872 tcp_hdr(skb
)->doff
* 4;
2873 int tcpd_len
= skb
->len
- (tcpd
- (unsigned long)skb
->data
);
2874 int elements
= PFN_UP(tcpd
+ tcpd_len
) - PFN_DOWN(tcpd
);
2875 elements
+= skb_shinfo(skb
)->nr_frags
;
2879 static inline int qeth_l3_tso_check(struct sk_buff
*skb
)
2881 int len
= ((unsigned long)tcp_hdr(skb
) + tcp_hdr(skb
)->doff
* 4) -
2882 (unsigned long)skb
->data
;
2883 return (((unsigned long)skb
->data
& PAGE_MASK
) !=
2884 (((unsigned long)skb
->data
+ len
) & PAGE_MASK
));
2887 static int qeth_l3_hard_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
2891 struct qeth_hdr
*hdr
= NULL
;
2892 int elements_needed
= 0;
2894 struct qeth_card
*card
= dev
->ml_priv
;
2895 struct sk_buff
*new_skb
= NULL
;
2896 int ipv
= qeth_get_ip_version(skb
);
2897 int cast_type
= qeth_l3_get_cast_type(card
, skb
);
2898 struct qeth_qdio_out_q
*queue
= card
->qdio
.out_qs
2899 [qeth_get_priority_queue(card
, skb
, ipv
, cast_type
)];
2900 int tx_bytes
= skb
->len
;
2901 enum qeth_large_send_types large_send
= QETH_LARGE_SEND_NO
;
2902 int data_offset
= -1;
2905 if (((card
->info
.type
== QETH_CARD_TYPE_IQD
) && (!ipv
)) ||
2906 card
->options
.sniffer
)
2909 if ((card
->state
!= CARD_STATE_UP
) || !card
->lan_online
) {
2910 card
->stats
.tx_carrier_errors
++;
2914 if ((cast_type
== RTN_BROADCAST
) &&
2915 (card
->info
.broadcast_capable
== 0))
2918 if (card
->options
.performance_stats
) {
2919 card
->perf_stats
.outbound_cnt
++;
2920 card
->perf_stats
.outbound_start_time
= qeth_get_micros();
2923 if (skb_is_gso(skb
))
2924 large_send
= card
->options
.large_send
;
2926 if (skb
->ip_summed
== CHECKSUM_PARTIAL
) {
2928 if (card
->options
.performance_stats
)
2929 card
->perf_stats
.tx_csum
++;
2932 if ((card
->info
.type
== QETH_CARD_TYPE_IQD
) && (!large_send
) &&
2933 (skb_shinfo(skb
)->nr_frags
== 0)) {
2935 data_offset
= ETH_HLEN
;
2936 hdr
= kmem_cache_alloc(qeth_core_header_cache
, GFP_ATOMIC
);
2941 /* create a clone with writeable headroom */
2942 new_skb
= skb_realloc_headroom(skb
, sizeof(struct qeth_hdr_tso
)
2948 if (card
->info
.type
== QETH_CARD_TYPE_IQD
) {
2949 if (data_offset
< 0)
2950 skb_pull(new_skb
, ETH_HLEN
);
2953 if (card
->dev
->type
== ARPHRD_IEEE802_TR
)
2954 skb_pull(new_skb
, TR_HLEN
);
2956 skb_pull(new_skb
, ETH_HLEN
);
2959 if (ipv
== 6 && card
->vlangrp
&&
2960 vlan_tx_tag_present(new_skb
)) {
2961 skb_push(new_skb
, VLAN_HLEN
);
2962 skb_copy_to_linear_data(new_skb
, new_skb
->data
+ 4, 4);
2963 skb_copy_to_linear_data_offset(new_skb
, 4,
2964 new_skb
->data
+ 8, 4);
2965 skb_copy_to_linear_data_offset(new_skb
, 8,
2966 new_skb
->data
+ 12, 4);
2967 tag
= (u16
*)(new_skb
->data
+ 12);
2968 *tag
= __constant_htons(ETH_P_8021Q
);
2969 *(tag
+ 1) = htons(vlan_tx_tag_get(new_skb
));
2970 new_skb
->vlan_tci
= 0;
2974 netif_stop_queue(dev
);
2976 /* fix hardware limitation: as long as we do not have sbal
2977 * chaining we can not send long frag lists
2979 if (large_send
== QETH_LARGE_SEND_TSO
) {
2980 if (qeth_l3_tso_elements(new_skb
) + 1 > 16) {
2981 if (skb_linearize(new_skb
))
2983 if (card
->options
.performance_stats
)
2984 card
->perf_stats
.tx_lin
++;
2988 if ((large_send
== QETH_LARGE_SEND_TSO
) &&
2989 (cast_type
== RTN_UNSPEC
)) {
2990 hdr
= (struct qeth_hdr
*)skb_push(new_skb
,
2991 sizeof(struct qeth_hdr_tso
));
2992 if (qeth_l3_tso_check(new_skb
))
2993 QETH_DBF_MESSAGE(2, "tso skb misaligned\n");
2994 memset(hdr
, 0, sizeof(struct qeth_hdr_tso
));
2995 qeth_l3_fill_header(card
, hdr
, new_skb
, ipv
, cast_type
);
2996 qeth_tso_fill_header(card
, hdr
, new_skb
);
2999 if (data_offset
< 0) {
3000 hdr
= (struct qeth_hdr
*)skb_push(new_skb
,
3001 sizeof(struct qeth_hdr
));
3002 qeth_l3_fill_header(card
, hdr
, new_skb
, ipv
,
3005 qeth_l3_fill_header(card
, hdr
, new_skb
, ipv
,
3007 hdr
->hdr
.l3
.length
= new_skb
->len
- data_offset
;
3011 elems
= qeth_get_elements_no(card
, (void *)hdr
, new_skb
,
3014 if (data_offset
>= 0)
3015 kmem_cache_free(qeth_core_header_cache
, hdr
);
3018 elements_needed
+= elems
;
3019 nr_frags
= skb_shinfo(new_skb
)->nr_frags
;
3021 if (card
->info
.type
!= QETH_CARD_TYPE_IQD
)
3022 rc
= qeth_do_send_packet(card
, queue
, new_skb
, hdr
,
3025 rc
= qeth_do_send_packet_fast(card
, queue
, new_skb
, hdr
,
3026 elements_needed
, data_offset
, 0);
3029 card
->stats
.tx_packets
++;
3030 card
->stats
.tx_bytes
+= tx_bytes
;
3032 dev_kfree_skb_any(skb
);
3033 if (card
->options
.performance_stats
) {
3034 if (large_send
!= QETH_LARGE_SEND_NO
) {
3035 card
->perf_stats
.large_send_bytes
+= tx_bytes
;
3036 card
->perf_stats
.large_send_cnt
++;
3039 card
->perf_stats
.sg_skbs_sent
++;
3040 /* nr_frags + skb->data */
3041 card
->perf_stats
.sg_frags_sent
+= nr_frags
+ 1;
3046 if (data_offset
>= 0)
3047 kmem_cache_free(qeth_core_header_cache
, hdr
);
3051 dev_kfree_skb_any(new_skb
);
3052 return NETDEV_TX_BUSY
;
3057 netif_wake_queue(dev
);
3058 if (card
->options
.performance_stats
)
3059 card
->perf_stats
.outbound_time
+= qeth_get_micros() -
3060 card
->perf_stats
.outbound_start_time
;
3064 card
->stats
.tx_dropped
++;
3065 card
->stats
.tx_errors
++;
3066 if ((new_skb
!= skb
) && new_skb
)
3067 dev_kfree_skb_any(new_skb
);
3068 dev_kfree_skb_any(skb
);
3069 netif_wake_queue(dev
);
3070 return NETDEV_TX_OK
;
3073 static int qeth_l3_open(struct net_device
*dev
)
3075 struct qeth_card
*card
= dev
->ml_priv
;
3077 QETH_DBF_TEXT(TRACE
, 4, "qethopen");
3078 if (card
->state
!= CARD_STATE_SOFTSETUP
)
3080 card
->data
.state
= CH_STATE_UP
;
3081 card
->state
= CARD_STATE_UP
;
3082 netif_start_queue(dev
);
3084 if (!card
->lan_online
&& netif_carrier_ok(dev
))
3085 netif_carrier_off(dev
);
3089 static int qeth_l3_stop(struct net_device
*dev
)
3091 struct qeth_card
*card
= dev
->ml_priv
;
3093 QETH_DBF_TEXT(TRACE
, 4, "qethstop");
3094 netif_tx_disable(dev
);
3095 if (card
->state
== CARD_STATE_UP
)
3096 card
->state
= CARD_STATE_SOFTSETUP
;
3100 static u32
qeth_l3_ethtool_get_rx_csum(struct net_device
*dev
)
3102 struct qeth_card
*card
= dev
->ml_priv
;
3104 return (card
->options
.checksum_type
== HW_CHECKSUMMING
);
3107 static int qeth_l3_ethtool_set_rx_csum(struct net_device
*dev
, u32 data
)
3109 struct qeth_card
*card
= dev
->ml_priv
;
3110 enum qeth_checksum_types csum_type
;
3113 csum_type
= HW_CHECKSUMMING
;
3115 csum_type
= SW_CHECKSUMMING
;
3117 return qeth_l3_set_rx_csum(card
, csum_type
);
3120 static int qeth_l3_ethtool_set_tso(struct net_device
*dev
, u32 data
)
3122 struct qeth_card
*card
= dev
->ml_priv
;
3126 rc
= qeth_l3_set_large_send(card
, QETH_LARGE_SEND_TSO
);
3128 dev
->features
&= ~NETIF_F_TSO
;
3129 card
->options
.large_send
= QETH_LARGE_SEND_NO
;
3134 static const struct ethtool_ops qeth_l3_ethtool_ops
= {
3135 .get_link
= ethtool_op_get_link
,
3136 .get_tx_csum
= ethtool_op_get_tx_csum
,
3137 .set_tx_csum
= ethtool_op_set_tx_hw_csum
,
3138 .get_rx_csum
= qeth_l3_ethtool_get_rx_csum
,
3139 .set_rx_csum
= qeth_l3_ethtool_set_rx_csum
,
3140 .get_sg
= ethtool_op_get_sg
,
3141 .set_sg
= ethtool_op_set_sg
,
3142 .get_tso
= ethtool_op_get_tso
,
3143 .set_tso
= qeth_l3_ethtool_set_tso
,
3144 .get_strings
= qeth_core_get_strings
,
3145 .get_ethtool_stats
= qeth_core_get_ethtool_stats
,
3146 .get_sset_count
= qeth_core_get_sset_count
,
3147 .get_drvinfo
= qeth_core_get_drvinfo
,
3148 .get_settings
= qeth_core_ethtool_get_settings
,
3152 * we need NOARP for IPv4 but we want neighbor solicitation for IPv6. Setting
3153 * NOARP on the netdevice is no option because it also turns off neighbor
3154 * solicitation. For IPv4 we install a neighbor_setup function. We don't want
3155 * arp resolution but we want the hard header (packet socket will work
3158 static int qeth_l3_neigh_setup_noarp(struct neighbour
*n
)
3160 n
->nud_state
= NUD_NOARP
;
3161 memcpy(n
->ha
, "FAKELL", 6);
3162 n
->output
= n
->ops
->connected_output
;
3167 qeth_l3_neigh_setup(struct net_device
*dev
, struct neigh_parms
*np
)
3169 if (np
->tbl
->family
== AF_INET
)
3170 np
->neigh_setup
= qeth_l3_neigh_setup_noarp
;
3175 static const struct net_device_ops qeth_l3_netdev_ops
= {
3176 .ndo_open
= qeth_l3_open
,
3177 .ndo_stop
= qeth_l3_stop
,
3178 .ndo_get_stats
= qeth_get_stats
,
3179 .ndo_start_xmit
= qeth_l3_hard_start_xmit
,
3180 .ndo_validate_addr
= eth_validate_addr
,
3181 .ndo_set_multicast_list
= qeth_l3_set_multicast_list
,
3182 .ndo_do_ioctl
= qeth_l3_do_ioctl
,
3183 .ndo_change_mtu
= qeth_change_mtu
,
3184 .ndo_vlan_rx_register
= qeth_l3_vlan_rx_register
,
3185 .ndo_vlan_rx_add_vid
= qeth_l3_vlan_rx_add_vid
,
3186 .ndo_vlan_rx_kill_vid
= qeth_l3_vlan_rx_kill_vid
,
3187 .ndo_tx_timeout
= qeth_tx_timeout
,
3190 static const struct net_device_ops qeth_l3_osa_netdev_ops
= {
3191 .ndo_open
= qeth_l3_open
,
3192 .ndo_stop
= qeth_l3_stop
,
3193 .ndo_get_stats
= qeth_get_stats
,
3194 .ndo_start_xmit
= qeth_l3_hard_start_xmit
,
3195 .ndo_validate_addr
= eth_validate_addr
,
3196 .ndo_set_multicast_list
= qeth_l3_set_multicast_list
,
3197 .ndo_do_ioctl
= qeth_l3_do_ioctl
,
3198 .ndo_change_mtu
= qeth_change_mtu
,
3199 .ndo_vlan_rx_register
= qeth_l3_vlan_rx_register
,
3200 .ndo_vlan_rx_add_vid
= qeth_l3_vlan_rx_add_vid
,
3201 .ndo_vlan_rx_kill_vid
= qeth_l3_vlan_rx_kill_vid
,
3202 .ndo_tx_timeout
= qeth_tx_timeout
,
3203 .ndo_neigh_setup
= qeth_l3_neigh_setup
,
3206 static int qeth_l3_setup_netdev(struct qeth_card
*card
)
3208 if (card
->info
.type
== QETH_CARD_TYPE_OSAE
) {
3209 if ((card
->info
.link_type
== QETH_LINK_TYPE_LANE_TR
) ||
3210 (card
->info
.link_type
== QETH_LINK_TYPE_HSTR
)) {
3212 card
->dev
= alloc_trdev(0);
3216 card
->dev
->netdev_ops
= &qeth_l3_netdev_ops
;
3218 card
->dev
= alloc_etherdev(0);
3221 card
->dev
->netdev_ops
= &qeth_l3_osa_netdev_ops
;
3223 /*IPv6 address autoconfiguration stuff*/
3224 qeth_l3_get_unique_id(card
);
3225 if (!(card
->info
.unique_id
& UNIQUE_ID_NOT_BY_CARD
))
3226 card
->dev
->dev_id
= card
->info
.unique_id
&
3229 } else if (card
->info
.type
== QETH_CARD_TYPE_IQD
) {
3230 card
->dev
= alloc_netdev(0, "hsi%d", ether_setup
);
3233 card
->dev
->flags
|= IFF_NOARP
;
3234 card
->dev
->netdev_ops
= &qeth_l3_netdev_ops
;
3235 qeth_l3_iqd_read_initial_mac(card
);
3239 card
->dev
->ml_priv
= card
;
3240 card
->dev
->watchdog_timeo
= QETH_TX_TIMEOUT
;
3241 card
->dev
->mtu
= card
->info
.initial_mtu
;
3242 SET_ETHTOOL_OPS(card
->dev
, &qeth_l3_ethtool_ops
);
3243 card
->dev
->features
|= NETIF_F_HW_VLAN_TX
|
3244 NETIF_F_HW_VLAN_RX
|
3245 NETIF_F_HW_VLAN_FILTER
;
3246 card
->dev
->priv_flags
&= ~IFF_XMIT_DST_RELEASE
;
3247 card
->dev
->gso_max_size
= 15 * PAGE_SIZE
;
3249 SET_NETDEV_DEV(card
->dev
, &card
->gdev
->dev
);
3250 return register_netdev(card
->dev
);
3253 static void qeth_l3_qdio_input_handler(struct ccw_device
*ccwdev
,
3254 unsigned int qdio_err
, unsigned int queue
, int first_element
,
3255 int count
, unsigned long card_ptr
)
3257 struct net_device
*net_dev
;
3258 struct qeth_card
*card
;
3259 struct qeth_qdio_buffer
*buffer
;
3263 card
= (struct qeth_card
*) card_ptr
;
3264 net_dev
= card
->dev
;
3265 if (card
->options
.performance_stats
) {
3266 card
->perf_stats
.inbound_cnt
++;
3267 card
->perf_stats
.inbound_start_time
= qeth_get_micros();
3269 if (qdio_err
& QDIO_ERROR_ACTIVATE_CHECK_CONDITION
) {
3270 QETH_DBF_TEXT(TRACE
, 1, "qdinchk");
3271 QETH_DBF_TEXT_(TRACE
, 1, "%s", CARD_BUS_ID(card
));
3272 QETH_DBF_TEXT_(TRACE
, 1, "%04X%04X",
3273 first_element
, count
);
3274 QETH_DBF_TEXT_(TRACE
, 1, "%04X", queue
);
3275 qeth_schedule_recovery(card
);
3278 for (i
= first_element
; i
< (first_element
+ count
); ++i
) {
3279 index
= i
% QDIO_MAX_BUFFERS_PER_Q
;
3280 buffer
= &card
->qdio
.in_q
->bufs
[index
];
3282 qeth_check_qdio_errors(card
, buffer
->buffer
,
3283 qdio_err
, "qinerr")))
3284 qeth_l3_process_inbound_buffer(card
, buffer
, index
);
3285 /* clear buffer and give back to hardware */
3286 qeth_put_buffer_pool_entry(card
, buffer
->pool_entry
);
3287 qeth_queue_input_buffer(card
, index
);
3289 if (card
->options
.performance_stats
)
3290 card
->perf_stats
.inbound_time
+= qeth_get_micros() -
3291 card
->perf_stats
.inbound_start_time
;
3294 static int qeth_l3_probe_device(struct ccwgroup_device
*gdev
)
3296 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
3298 qeth_l3_create_device_attributes(&gdev
->dev
);
3299 card
->options
.layer2
= 0;
3300 card
->discipline
.input_handler
= (qdio_handler_t
*)
3301 qeth_l3_qdio_input_handler
;
3302 card
->discipline
.output_handler
= (qdio_handler_t
*)
3303 qeth_qdio_output_handler
;
3304 card
->discipline
.recover
= qeth_l3_recover
;
3308 static void qeth_l3_remove_device(struct ccwgroup_device
*cgdev
)
3310 struct qeth_card
*card
= dev_get_drvdata(&cgdev
->dev
);
3312 qeth_set_allowed_threads(card
, 0, 1);
3313 wait_event(card
->wait_q
, qeth_threads_running(card
, 0xffffffff) == 0);
3315 if (cgdev
->state
== CCWGROUP_ONLINE
) {
3316 card
->use_hard_stop
= 1;
3317 qeth_l3_set_offline(cgdev
);
3321 unregister_netdev(card
->dev
);
3325 qeth_l3_remove_device_attributes(&cgdev
->dev
);
3326 qeth_l3_clear_ip_list(card
, 0, 0);
3327 qeth_l3_clear_ipato_list(card
);
3331 static int __qeth_l3_set_online(struct ccwgroup_device
*gdev
, int recovery_mode
)
3333 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
3335 enum qeth_card_states recover_flag
;
3338 QETH_DBF_TEXT(SETUP
, 2, "setonlin");
3339 QETH_DBF_HEX(SETUP
, 2, &card
, sizeof(void *));
3341 recover_flag
= card
->state
;
3342 rc
= qeth_core_hardsetup_card(card
);
3344 QETH_DBF_TEXT_(SETUP
, 2, "2err%d", rc
);
3349 qeth_l3_query_ipassists(card
, QETH_PROT_IPV4
);
3351 if (!card
->dev
&& qeth_l3_setup_netdev(card
)) {
3356 card
->state
= CARD_STATE_HARDSETUP
;
3357 qeth_print_status_message(card
);
3360 QETH_DBF_TEXT(SETUP
, 2, "softsetp");
3362 rc
= qeth_send_startlan(card
);
3364 QETH_DBF_TEXT_(SETUP
, 2, "1err%d", rc
);
3366 dev_warn(&card
->gdev
->dev
,
3367 "The LAN is offline\n");
3368 card
->lan_online
= 0;
3374 card
->lan_online
= 1;
3376 rc
= qeth_l3_setadapter_parms(card
);
3378 QETH_DBF_TEXT_(SETUP
, 2, "2err%d", rc
);
3379 if (!card
->options
.sniffer
) {
3380 rc
= qeth_l3_start_ipassists(card
);
3382 QETH_DBF_TEXT_(SETUP
, 2, "3err%d", rc
);
3383 qeth_l3_set_large_send(card
, card
->options
.large_send
);
3384 rc
= qeth_l3_setrouting_v4(card
);
3386 QETH_DBF_TEXT_(SETUP
, 2, "4err%d", rc
);
3387 rc
= qeth_l3_setrouting_v6(card
);
3389 QETH_DBF_TEXT_(SETUP
, 2, "5err%d", rc
);
3391 netif_tx_disable(card
->dev
);
3393 rc
= qeth_init_qdio_queues(card
);
3395 QETH_DBF_TEXT_(SETUP
, 2, "6err%d", rc
);
3399 card
->state
= CARD_STATE_SOFTSETUP
;
3400 netif_carrier_on(card
->dev
);
3402 qeth_set_allowed_threads(card
, 0xffffffff, 0);
3403 qeth_l3_set_ip_addr_list(card
);
3404 if (recover_flag
== CARD_STATE_RECOVER
) {
3406 qeth_l3_open(card
->dev
);
3409 dev_open(card
->dev
);
3412 qeth_l3_set_multicast_list(card
->dev
);
3414 /* let user_space know that device is online */
3415 kobject_uevent(&gdev
->dev
.kobj
, KOBJ_CHANGE
);
3418 card
->use_hard_stop
= 1;
3419 qeth_l3_stop_card(card
, 0);
3420 ccw_device_set_offline(CARD_DDEV(card
));
3421 ccw_device_set_offline(CARD_WDEV(card
));
3422 ccw_device_set_offline(CARD_RDEV(card
));
3423 if (recover_flag
== CARD_STATE_RECOVER
)
3424 card
->state
= CARD_STATE_RECOVER
;
3426 card
->state
= CARD_STATE_DOWN
;
3430 static int qeth_l3_set_online(struct ccwgroup_device
*gdev
)
3432 return __qeth_l3_set_online(gdev
, 0);
3435 static int __qeth_l3_set_offline(struct ccwgroup_device
*cgdev
,
3438 struct qeth_card
*card
= dev_get_drvdata(&cgdev
->dev
);
3439 int rc
= 0, rc2
= 0, rc3
= 0;
3440 enum qeth_card_states recover_flag
;
3442 QETH_DBF_TEXT(SETUP
, 3, "setoffl");
3443 QETH_DBF_HEX(SETUP
, 3, &card
, sizeof(void *));
3445 if (card
->dev
&& netif_carrier_ok(card
->dev
))
3446 netif_carrier_off(card
->dev
);
3447 recover_flag
= card
->state
;
3448 qeth_l3_stop_card(card
, recovery_mode
);
3449 rc
= ccw_device_set_offline(CARD_DDEV(card
));
3450 rc2
= ccw_device_set_offline(CARD_WDEV(card
));
3451 rc3
= ccw_device_set_offline(CARD_RDEV(card
));
3453 rc
= (rc2
) ? rc2
: rc3
;
3455 QETH_DBF_TEXT_(SETUP
, 2, "1err%d", rc
);
3456 if (recover_flag
== CARD_STATE_UP
)
3457 card
->state
= CARD_STATE_RECOVER
;
3458 /* let user_space know that device is offline */
3459 kobject_uevent(&cgdev
->dev
.kobj
, KOBJ_CHANGE
);
3463 static int qeth_l3_set_offline(struct ccwgroup_device
*cgdev
)
3465 return __qeth_l3_set_offline(cgdev
, 0);
3468 static int qeth_l3_recover(void *ptr
)
3470 struct qeth_card
*card
;
3473 card
= (struct qeth_card
*) ptr
;
3474 QETH_DBF_TEXT(TRACE
, 2, "recover1");
3475 QETH_DBF_HEX(TRACE
, 2, &card
, sizeof(void *));
3476 if (!qeth_do_run_thread(card
, QETH_RECOVER_THREAD
))
3478 QETH_DBF_TEXT(TRACE
, 2, "recover2");
3479 dev_warn(&card
->gdev
->dev
,
3480 "A recovery process has been started for the device\n");
3481 card
->use_hard_stop
= 1;
3482 __qeth_l3_set_offline(card
->gdev
, 1);
3483 rc
= __qeth_l3_set_online(card
->gdev
, 1);
3484 /* don't run another scheduled recovery */
3485 qeth_clear_thread_start_bit(card
, QETH_RECOVER_THREAD
);
3486 qeth_clear_thread_running_bit(card
, QETH_RECOVER_THREAD
);
3488 dev_info(&card
->gdev
->dev
,
3489 "Device successfully recovered!\n");
3492 dev_close(card
->dev
);
3494 dev_warn(&card
->gdev
->dev
, "The qeth device driver "
3495 "failed to recover an error on the device\n");
3500 static void qeth_l3_shutdown(struct ccwgroup_device
*gdev
)
3502 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
3503 qeth_l3_clear_ip_list(card
, 0, 0);
3504 qeth_qdio_clear_card(card
, 0);
3505 qeth_clear_qdio_buffers(card
);
3508 static int qeth_l3_pm_suspend(struct ccwgroup_device
*gdev
)
3510 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
3513 netif_device_detach(card
->dev
);
3514 qeth_set_allowed_threads(card
, 0, 1);
3515 wait_event(card
->wait_q
, qeth_threads_running(card
, 0xffffffff) == 0);
3516 if (gdev
->state
== CCWGROUP_OFFLINE
)
3518 if (card
->state
== CARD_STATE_UP
) {
3519 card
->use_hard_stop
= 1;
3520 __qeth_l3_set_offline(card
->gdev
, 1);
3522 __qeth_l3_set_offline(card
->gdev
, 0);
3526 static int qeth_l3_pm_resume(struct ccwgroup_device
*gdev
)
3528 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
3531 if (gdev
->state
== CCWGROUP_OFFLINE
)
3534 if (card
->state
== CARD_STATE_RECOVER
) {
3535 rc
= __qeth_l3_set_online(card
->gdev
, 1);
3538 dev_close(card
->dev
);
3542 rc
= __qeth_l3_set_online(card
->gdev
, 0);
3544 qeth_set_allowed_threads(card
, 0xffffffff, 0);
3546 netif_device_attach(card
->dev
);
3548 dev_warn(&card
->gdev
->dev
, "The qeth device driver "
3549 "failed to recover an error on the device\n");
3553 struct ccwgroup_driver qeth_l3_ccwgroup_driver
= {
3554 .probe
= qeth_l3_probe_device
,
3555 .remove
= qeth_l3_remove_device
,
3556 .set_online
= qeth_l3_set_online
,
3557 .set_offline
= qeth_l3_set_offline
,
3558 .shutdown
= qeth_l3_shutdown
,
3559 .freeze
= qeth_l3_pm_suspend
,
3560 .thaw
= qeth_l3_pm_resume
,
3561 .restore
= qeth_l3_pm_resume
,
3563 EXPORT_SYMBOL_GPL(qeth_l3_ccwgroup_driver
);
3565 static int qeth_l3_ip_event(struct notifier_block
*this,
3566 unsigned long event
, void *ptr
)
3568 struct in_ifaddr
*ifa
= (struct in_ifaddr
*)ptr
;
3569 struct net_device
*dev
= (struct net_device
*)ifa
->ifa_dev
->dev
;
3570 struct qeth_ipaddr
*addr
;
3571 struct qeth_card
*card
;
3573 if (dev_net(dev
) != &init_net
)
3576 QETH_DBF_TEXT(TRACE
, 3, "ipevent");
3577 card
= qeth_l3_get_card_from_dev(dev
);
3581 addr
= qeth_l3_get_addr_buffer(QETH_PROT_IPV4
);
3583 addr
->u
.a4
.addr
= ifa
->ifa_address
;
3584 addr
->u
.a4
.mask
= ifa
->ifa_mask
;
3585 addr
->type
= QETH_IP_TYPE_NORMAL
;
3591 if (!qeth_l3_add_ip(card
, addr
))
3595 if (!qeth_l3_delete_ip(card
, addr
))
3601 qeth_l3_set_ip_addr_list(card
);
3606 static struct notifier_block qeth_l3_ip_notifier
= {
3611 #ifdef CONFIG_QETH_IPV6
3613 * IPv6 event handler
3615 static int qeth_l3_ip6_event(struct notifier_block
*this,
3616 unsigned long event
, void *ptr
)
3618 struct inet6_ifaddr
*ifa
= (struct inet6_ifaddr
*)ptr
;
3619 struct net_device
*dev
= (struct net_device
*)ifa
->idev
->dev
;
3620 struct qeth_ipaddr
*addr
;
3621 struct qeth_card
*card
;
3623 QETH_DBF_TEXT(TRACE
, 3, "ip6event");
3625 card
= qeth_l3_get_card_from_dev(dev
);
3628 if (!qeth_is_supported(card
, IPA_IPV6
))
3631 addr
= qeth_l3_get_addr_buffer(QETH_PROT_IPV6
);
3633 memcpy(&addr
->u
.a6
.addr
, &ifa
->addr
, sizeof(struct in6_addr
));
3634 addr
->u
.a6
.pfxlen
= ifa
->prefix_len
;
3635 addr
->type
= QETH_IP_TYPE_NORMAL
;
3641 if (!qeth_l3_add_ip(card
, addr
))
3645 if (!qeth_l3_delete_ip(card
, addr
))
3651 qeth_l3_set_ip_addr_list(card
);
3656 static struct notifier_block qeth_l3_ip6_notifier
= {
3662 static int qeth_l3_register_notifiers(void)
3666 QETH_DBF_TEXT(TRACE
, 5, "regnotif");
3667 rc
= register_inetaddr_notifier(&qeth_l3_ip_notifier
);
3670 #ifdef CONFIG_QETH_IPV6
3671 rc
= register_inet6addr_notifier(&qeth_l3_ip6_notifier
);
3673 unregister_inetaddr_notifier(&qeth_l3_ip_notifier
);
3677 pr_warning("There is no IPv6 support for the layer 3 discipline\n");
3682 static void qeth_l3_unregister_notifiers(void)
3685 QETH_DBF_TEXT(TRACE
, 5, "unregnot");
3686 BUG_ON(unregister_inetaddr_notifier(&qeth_l3_ip_notifier
));
3687 #ifdef CONFIG_QETH_IPV6
3688 BUG_ON(unregister_inet6addr_notifier(&qeth_l3_ip6_notifier
));
3689 #endif /* QETH_IPV6 */
3692 static int __init
qeth_l3_init(void)
3696 pr_info("register layer 3 discipline\n");
3697 rc
= qeth_l3_register_notifiers();
3701 static void __exit
qeth_l3_exit(void)
3703 qeth_l3_unregister_notifiers();
3704 pr_info("unregister layer 3 discipline\n");
3707 module_init(qeth_l3_init
);
3708 module_exit(qeth_l3_exit
);
3709 MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
3710 MODULE_DESCRIPTION("qeth layer 3 discipline");
3711 MODULE_LICENSE("GPL");