2 * drivers/s390/net/qeth_l3_main.c
4 * Copyright IBM Corp. 2007
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 #include <linux/module.h>
12 #include <linux/moduleparam.h>
13 #include <linux/string.h>
14 #include <linux/errno.h>
15 #include <linux/kernel.h>
16 #include <linux/etherdevice.h>
17 #include <linux/mii.h>
19 #include <linux/reboot.h>
20 #include <linux/inetdevice.h>
21 #include <linux/igmp.h>
26 #include <asm/s390_rdev.h>
29 #include "qeth_core_offl.h"
31 DEFINE_PER_CPU(char[256], qeth_l3_dbf_txt_buf);
33 static int qeth_l3_set_offline(struct ccwgroup_device *);
34 static int qeth_l3_recover(void *);
35 static int qeth_l3_stop(struct net_device *);
36 static void qeth_l3_set_multicast_list(struct net_device *);
37 static int qeth_l3_neigh_setup(struct net_device *, struct neigh_parms *);
38 static int qeth_l3_register_addr_entry(struct qeth_card *,
39 struct qeth_ipaddr *);
40 static int qeth_l3_deregister_addr_entry(struct qeth_card *,
41 struct qeth_ipaddr *);
42 static int __qeth_l3_set_online(struct ccwgroup_device *, int);
43 static int __qeth_l3_set_offline(struct ccwgroup_device *, int);
46 static int qeth_l3_isxdigit(char *buf)
49 if (!isxdigit(*buf++))
55 void qeth_l3_ipaddr4_to_string(const __u8 *addr, char *buf)
57 sprintf(buf, "%i.%i.%i.%i", addr[0], addr[1], addr[2], addr[3]);
60 int qeth_l3_string_to_ipaddr4(const char *buf, __u8 *addr)
62 int count = 0, rc = 0;
66 rc = sscanf(buf, "%u.%u.%u.%u%c",
67 &in[0], &in[1], &in[2], &in[3], &c);
68 if (rc != 4 && (rc != 5 || c != '\n'))
70 for (count = 0; count < 4; count++) {
73 addr[count] = in[count];
78 void qeth_l3_ipaddr6_to_string(const __u8 *addr, char *buf)
80 sprintf(buf, "%02x%02x:%02x%02x:%02x%02x:%02x%02x"
81 ":%02x%02x:%02x%02x:%02x%02x:%02x%02x",
82 addr[0], addr[1], addr[2], addr[3],
83 addr[4], addr[5], addr[6], addr[7],
84 addr[8], addr[9], addr[10], addr[11],
85 addr[12], addr[13], addr[14], addr[15]);
88 int qeth_l3_string_to_ipaddr6(const char *buf, __u8 *addr)
90 const char *end, *end_tmp, *start;
93 int num2, cnt, out, found, save_cnt;
94 unsigned short in_tmp[8] = {0, };
96 cnt = out = found = save_cnt = num2 = 0;
101 end = strchr(start, ':');
103 end = buf + strlen(buf);
104 end_tmp = strchr(start, '\n');
111 if ((end - start) > 4)
113 memcpy(num, start, end - start);
114 if (!qeth_l3_isxdigit(num))
116 sscanf(start, "%x", &num2);
118 in_tmp[save_cnt++] = num2;
130 if (cnt + save_cnt > 8)
134 in[cnt--] = in_tmp[--save_cnt];
138 void qeth_l3_ipaddr_to_string(enum qeth_prot_versions proto, const __u8 *addr,
141 if (proto == QETH_PROT_IPV4)
142 qeth_l3_ipaddr4_to_string(addr, buf);
143 else if (proto == QETH_PROT_IPV6)
144 qeth_l3_ipaddr6_to_string(addr, buf);
147 int qeth_l3_string_to_ipaddr(const char *buf, enum qeth_prot_versions proto,
150 if (proto == QETH_PROT_IPV4)
151 return qeth_l3_string_to_ipaddr4(buf, addr);
152 else if (proto == QETH_PROT_IPV6)
153 return qeth_l3_string_to_ipaddr6(buf, addr);
158 static void qeth_l3_convert_addr_to_bits(u8 *addr, u8 *bits, int len)
163 for (i = 0; i < len; ++i) {
165 for (j = 7; j >= 0; --j) {
166 bits[i*8 + j] = octet & 1;
172 static int qeth_l3_is_addr_covered_by_ipato(struct qeth_card *card,
173 struct qeth_ipaddr *addr)
175 struct qeth_ipato_entry *ipatoe;
176 u8 addr_bits[128] = {0, };
177 u8 ipatoe_bits[128] = {0, };
180 if (!card->ipato.enabled)
183 qeth_l3_convert_addr_to_bits((u8 *) &addr->u, addr_bits,
184 (addr->proto == QETH_PROT_IPV4)? 4:16);
185 list_for_each_entry(ipatoe, &card->ipato.entries, entry) {
186 if (addr->proto != ipatoe->proto)
188 qeth_l3_convert_addr_to_bits(ipatoe->addr, ipatoe_bits,
189 (ipatoe->proto == QETH_PROT_IPV4) ?
191 if (addr->proto == QETH_PROT_IPV4)
192 rc = !memcmp(addr_bits, ipatoe_bits,
193 min(32, ipatoe->mask_bits));
195 rc = !memcmp(addr_bits, ipatoe_bits,
196 min(128, ipatoe->mask_bits));
201 if ((addr->proto == QETH_PROT_IPV4) && card->ipato.invert4)
203 else if ((addr->proto == QETH_PROT_IPV6) && card->ipato.invert6)
210 * Add IP to be added to todo list. If there is already an "add todo"
211 * in this list we just incremenent the reference count.
212 * Returns 0 if we just incremented reference count.
214 static int __qeth_l3_insert_ip_todo(struct qeth_card *card,
215 struct qeth_ipaddr *addr, int add)
217 struct qeth_ipaddr *tmp, *t;
220 list_for_each_entry_safe(tmp, t, card->ip_tbd_list, entry) {
221 if ((addr->type == QETH_IP_TYPE_DEL_ALL_MC) &&
222 (tmp->type == QETH_IP_TYPE_DEL_ALL_MC))
224 if ((tmp->proto == QETH_PROT_IPV4) &&
225 (addr->proto == QETH_PROT_IPV4) &&
226 (tmp->type == addr->type) &&
227 (tmp->is_multicast == addr->is_multicast) &&
228 (tmp->u.a4.addr == addr->u.a4.addr) &&
229 (tmp->u.a4.mask == addr->u.a4.mask)) {
233 if ((tmp->proto == QETH_PROT_IPV6) &&
234 (addr->proto == QETH_PROT_IPV6) &&
235 (tmp->type == addr->type) &&
236 (tmp->is_multicast == addr->is_multicast) &&
237 (tmp->u.a6.pfxlen == addr->u.a6.pfxlen) &&
238 (memcmp(&tmp->u.a6.addr, &addr->u.a6.addr,
239 sizeof(struct in6_addr)) == 0)) {
245 if (addr->users != 0)
246 tmp->users += addr->users;
248 tmp->users += add ? 1 : -1;
249 if (tmp->users == 0) {
250 list_del(&tmp->entry);
255 if (addr->type == QETH_IP_TYPE_DEL_ALL_MC)
256 list_add(&addr->entry, card->ip_tbd_list);
258 if (addr->users == 0)
259 addr->users += add ? 1 : -1;
260 if (add && (addr->type == QETH_IP_TYPE_NORMAL) &&
261 qeth_l3_is_addr_covered_by_ipato(card, addr)) {
262 QETH_DBF_TEXT(trace, 2, "tkovaddr");
263 addr->set_flags |= QETH_IPA_SETIP_TAKEOVER_FLAG;
265 list_add_tail(&addr->entry, card->ip_tbd_list);
271 static int qeth_l3_delete_ip(struct qeth_card *card, struct qeth_ipaddr *addr)
276 QETH_DBF_TEXT(trace, 4, "delip");
278 if (addr->proto == QETH_PROT_IPV4)
279 QETH_DBF_HEX(trace, 4, &addr->u.a4.addr, 4);
281 QETH_DBF_HEX(trace, 4, &addr->u.a6.addr, 8);
282 QETH_DBF_HEX(trace, 4, ((char *)&addr->u.a6.addr) + 8, 8);
284 spin_lock_irqsave(&card->ip_lock, flags);
285 rc = __qeth_l3_insert_ip_todo(card, addr, 0);
286 spin_unlock_irqrestore(&card->ip_lock, flags);
290 static int qeth_l3_add_ip(struct qeth_card *card, struct qeth_ipaddr *addr)
295 QETH_DBF_TEXT(trace, 4, "addip");
296 if (addr->proto == QETH_PROT_IPV4)
297 QETH_DBF_HEX(trace, 4, &addr->u.a4.addr, 4);
299 QETH_DBF_HEX(trace, 4, &addr->u.a6.addr, 8);
300 QETH_DBF_HEX(trace, 4, ((char *)&addr->u.a6.addr) + 8, 8);
302 spin_lock_irqsave(&card->ip_lock, flags);
303 rc = __qeth_l3_insert_ip_todo(card, addr, 1);
304 spin_unlock_irqrestore(&card->ip_lock, flags);
309 static struct qeth_ipaddr *qeth_l3_get_addr_buffer(
310 enum qeth_prot_versions prot)
312 struct qeth_ipaddr *addr;
314 addr = kzalloc(sizeof(struct qeth_ipaddr), GFP_ATOMIC);
316 PRINT_WARN("Not enough memory to add address\n");
319 addr->type = QETH_IP_TYPE_NORMAL;
324 static void qeth_l3_delete_mc_addresses(struct qeth_card *card)
326 struct qeth_ipaddr *iptodo;
329 QETH_DBF_TEXT(trace, 4, "delmc");
330 iptodo = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
332 QETH_DBF_TEXT(trace, 2, "dmcnomem");
335 iptodo->type = QETH_IP_TYPE_DEL_ALL_MC;
336 spin_lock_irqsave(&card->ip_lock, flags);
337 if (!__qeth_l3_insert_ip_todo(card, iptodo, 0))
339 spin_unlock_irqrestore(&card->ip_lock, flags);
343 * Add/remove address to/from card's ip list, i.e. try to add or remove
344 * reference to/from an IP address that is already registered on the card.
346 * 0 address was on card and its reference count has been adjusted,
347 * but is still > 0, so nothing has to be done
348 * also returns 0 if card was not on card and the todo was to delete
349 * the address -> there is also nothing to be done
350 * 1 address was not on card and the todo is to add it to the card's ip
352 * -1 address was on card and its reference count has been decremented
353 * to <= 0 by the todo -> address must be removed from card
355 static int __qeth_l3_ref_ip_on_card(struct qeth_card *card,
356 struct qeth_ipaddr *todo, struct qeth_ipaddr **__addr)
358 struct qeth_ipaddr *addr;
361 list_for_each_entry(addr, &card->ip_list, entry) {
362 if ((addr->proto == QETH_PROT_IPV4) &&
363 (todo->proto == QETH_PROT_IPV4) &&
364 (addr->type == todo->type) &&
365 (addr->u.a4.addr == todo->u.a4.addr) &&
366 (addr->u.a4.mask == todo->u.a4.mask)) {
370 if ((addr->proto == QETH_PROT_IPV6) &&
371 (todo->proto == QETH_PROT_IPV6) &&
372 (addr->type == todo->type) &&
373 (addr->u.a6.pfxlen == todo->u.a6.pfxlen) &&
374 (memcmp(&addr->u.a6.addr, &todo->u.a6.addr,
375 sizeof(struct in6_addr)) == 0)) {
381 addr->users += todo->users;
382 if (addr->users <= 0) {
386 /* for VIPA and RXIP limit refcount to 1 */
387 if (addr->type != QETH_IP_TYPE_NORMAL)
392 if (todo->users > 0) {
393 /* for VIPA and RXIP limit refcount to 1 */
394 if (todo->type != QETH_IP_TYPE_NORMAL)
401 static void __qeth_l3_delete_all_mc(struct qeth_card *card,
402 unsigned long *flags)
404 struct list_head fail_list;
405 struct qeth_ipaddr *addr, *tmp;
408 INIT_LIST_HEAD(&fail_list);
410 list_for_each_entry_safe(addr, tmp, &card->ip_list, entry) {
411 if (addr->is_multicast) {
412 list_del(&addr->entry);
413 spin_unlock_irqrestore(&card->ip_lock, *flags);
414 rc = qeth_l3_deregister_addr_entry(card, addr);
415 spin_lock_irqsave(&card->ip_lock, *flags);
416 if (!rc || (rc == IPA_RC_MC_ADDR_NOT_FOUND))
419 list_add_tail(&addr->entry, &fail_list);
423 list_splice(&fail_list, &card->ip_list);
426 static void qeth_l3_set_ip_addr_list(struct qeth_card *card)
428 struct list_head *tbd_list;
429 struct qeth_ipaddr *todo, *addr;
433 QETH_DBF_TEXT(trace, 2, "sdiplist");
434 QETH_DBF_HEX(trace, 2, &card, sizeof(void *));
436 spin_lock_irqsave(&card->ip_lock, flags);
437 tbd_list = card->ip_tbd_list;
438 card->ip_tbd_list = kmalloc(sizeof(struct list_head), GFP_ATOMIC);
439 if (!card->ip_tbd_list) {
440 QETH_DBF_TEXT(trace, 0, "silnomem");
441 card->ip_tbd_list = tbd_list;
442 spin_unlock_irqrestore(&card->ip_lock, flags);
445 INIT_LIST_HEAD(card->ip_tbd_list);
447 while (!list_empty(tbd_list)) {
448 todo = list_entry(tbd_list->next, struct qeth_ipaddr, entry);
449 list_del(&todo->entry);
450 if (todo->type == QETH_IP_TYPE_DEL_ALL_MC) {
451 __qeth_l3_delete_all_mc(card, &flags);
455 rc = __qeth_l3_ref_ip_on_card(card, todo, &addr);
457 /* nothing to be done; only adjusted refcount */
459 } else if (rc == 1) {
460 /* new entry to be added to on-card list */
461 spin_unlock_irqrestore(&card->ip_lock, flags);
462 rc = qeth_l3_register_addr_entry(card, todo);
463 spin_lock_irqsave(&card->ip_lock, flags);
465 list_add_tail(&todo->entry, &card->ip_list);
468 } else if (rc == -1) {
469 /* on-card entry to be removed */
470 list_del_init(&addr->entry);
471 spin_unlock_irqrestore(&card->ip_lock, flags);
472 rc = qeth_l3_deregister_addr_entry(card, addr);
473 spin_lock_irqsave(&card->ip_lock, flags);
474 if (!rc || (rc == IPA_RC_PRIMARY_ALREADY_DEFINED))
477 list_add_tail(&addr->entry, &card->ip_list);
481 spin_unlock_irqrestore(&card->ip_lock, flags);
485 static void qeth_l3_clear_ip_list(struct qeth_card *card, int clean,
488 struct qeth_ipaddr *addr, *tmp;
491 QETH_DBF_TEXT(trace, 4, "clearip");
492 spin_lock_irqsave(&card->ip_lock, flags);
493 /* clear todo list */
494 list_for_each_entry_safe(addr, tmp, card->ip_tbd_list, entry) {
495 list_del(&addr->entry);
499 while (!list_empty(&card->ip_list)) {
500 addr = list_entry(card->ip_list.next,
501 struct qeth_ipaddr, entry);
502 list_del_init(&addr->entry);
504 spin_unlock_irqrestore(&card->ip_lock, flags);
505 qeth_l3_deregister_addr_entry(card, addr);
506 spin_lock_irqsave(&card->ip_lock, flags);
508 if (!recover || addr->is_multicast) {
512 list_add_tail(&addr->entry, card->ip_tbd_list);
514 spin_unlock_irqrestore(&card->ip_lock, flags);
517 static int qeth_l3_address_exists_in_list(struct list_head *list,
518 struct qeth_ipaddr *addr, int same_type)
520 struct qeth_ipaddr *tmp;
522 list_for_each_entry(tmp, list, entry) {
523 if ((tmp->proto == QETH_PROT_IPV4) &&
524 (addr->proto == QETH_PROT_IPV4) &&
525 ((same_type && (tmp->type == addr->type)) ||
526 (!same_type && (tmp->type != addr->type))) &&
527 (tmp->u.a4.addr == addr->u.a4.addr))
530 if ((tmp->proto == QETH_PROT_IPV6) &&
531 (addr->proto == QETH_PROT_IPV6) &&
532 ((same_type && (tmp->type == addr->type)) ||
533 (!same_type && (tmp->type != addr->type))) &&
534 (memcmp(&tmp->u.a6.addr, &addr->u.a6.addr,
535 sizeof(struct in6_addr)) == 0))
542 static int qeth_l3_send_setdelmc(struct qeth_card *card,
543 struct qeth_ipaddr *addr, int ipacmd)
546 struct qeth_cmd_buffer *iob;
547 struct qeth_ipa_cmd *cmd;
549 QETH_DBF_TEXT(trace, 4, "setdelmc");
551 iob = qeth_get_ipacmd_buffer(card, ipacmd, addr->proto);
552 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
553 memcpy(&cmd->data.setdelipm.mac, addr->mac, OSA_ADDR_LEN);
554 if (addr->proto == QETH_PROT_IPV6)
555 memcpy(cmd->data.setdelipm.ip6, &addr->u.a6.addr,
556 sizeof(struct in6_addr));
558 memcpy(&cmd->data.setdelipm.ip4, &addr->u.a4.addr, 4);
560 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
565 static void qeth_l3_fill_netmask(u8 *netmask, unsigned int len)
568 for (i = 0; i < 16; i++) {
573 netmask[i] = (u8)(0xFF00 >> j);
579 static int qeth_l3_send_setdelip(struct qeth_card *card,
580 struct qeth_ipaddr *addr, int ipacmd, unsigned int flags)
583 struct qeth_cmd_buffer *iob;
584 struct qeth_ipa_cmd *cmd;
587 QETH_DBF_TEXT(trace, 4, "setdelip");
588 QETH_DBF_TEXT_(trace, 4, "flags%02X", flags);
590 iob = qeth_get_ipacmd_buffer(card, ipacmd, addr->proto);
591 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
592 if (addr->proto == QETH_PROT_IPV6) {
593 memcpy(cmd->data.setdelip6.ip_addr, &addr->u.a6.addr,
594 sizeof(struct in6_addr));
595 qeth_l3_fill_netmask(netmask, addr->u.a6.pfxlen);
596 memcpy(cmd->data.setdelip6.mask, netmask,
597 sizeof(struct in6_addr));
598 cmd->data.setdelip6.flags = flags;
600 memcpy(cmd->data.setdelip4.ip_addr, &addr->u.a4.addr, 4);
601 memcpy(cmd->data.setdelip4.mask, &addr->u.a4.mask, 4);
602 cmd->data.setdelip4.flags = flags;
605 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
610 static int qeth_l3_send_setrouting(struct qeth_card *card,
611 enum qeth_routing_types type, enum qeth_prot_versions prot)
614 struct qeth_ipa_cmd *cmd;
615 struct qeth_cmd_buffer *iob;
617 QETH_DBF_TEXT(trace, 4, "setroutg");
618 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SETRTG, prot);
619 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
620 cmd->data.setrtg.type = (type);
621 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
626 static void qeth_l3_correct_routing_type(struct qeth_card *card,
627 enum qeth_routing_types *type, enum qeth_prot_versions prot)
629 if (card->info.type == QETH_CARD_TYPE_IQD) {
632 case PRIMARY_CONNECTOR:
633 case SECONDARY_CONNECTOR:
634 case MULTICAST_ROUTER:
643 case SECONDARY_ROUTER:
645 case MULTICAST_ROUTER:
646 if (qeth_is_ipafunc_supported(card, prot,
654 PRINT_WARN("Routing type '%s' not supported for interface %s.\n"
655 "Router status set to 'no router'.\n",
656 ((*type == PRIMARY_ROUTER)? "primary router" :
657 (*type == SECONDARY_ROUTER)? "secondary router" :
658 (*type == PRIMARY_CONNECTOR)? "primary connector" :
659 (*type == SECONDARY_CONNECTOR)? "secondary connector" :
660 (*type == MULTICAST_ROUTER)? "multicast router" :
666 int qeth_l3_setrouting_v4(struct qeth_card *card)
670 QETH_DBF_TEXT(trace, 3, "setrtg4");
672 qeth_l3_correct_routing_type(card, &card->options.route4.type,
675 rc = qeth_l3_send_setrouting(card, card->options.route4.type,
678 card->options.route4.type = NO_ROUTER;
679 PRINT_WARN("Error (0x%04x) while setting routing type on %s. "
680 "Type set to 'no router'.\n",
681 rc, QETH_CARD_IFNAME(card));
686 int qeth_l3_setrouting_v6(struct qeth_card *card)
690 QETH_DBF_TEXT(trace, 3, "setrtg6");
691 #ifdef CONFIG_QETH_IPV6
693 if (!qeth_is_supported(card, IPA_IPV6))
695 qeth_l3_correct_routing_type(card, &card->options.route6.type,
698 rc = qeth_l3_send_setrouting(card, card->options.route6.type,
701 card->options.route6.type = NO_ROUTER;
702 PRINT_WARN("Error (0x%04x) while setting routing type on %s. "
703 "Type set to 'no router'.\n",
704 rc, QETH_CARD_IFNAME(card));
711 * IP address takeover related functions
713 static void qeth_l3_clear_ipato_list(struct qeth_card *card)
716 struct qeth_ipato_entry *ipatoe, *tmp;
719 spin_lock_irqsave(&card->ip_lock, flags);
720 list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry) {
721 list_del(&ipatoe->entry);
724 spin_unlock_irqrestore(&card->ip_lock, flags);
727 int qeth_l3_add_ipato_entry(struct qeth_card *card,
728 struct qeth_ipato_entry *new)
730 struct qeth_ipato_entry *ipatoe;
734 QETH_DBF_TEXT(trace, 2, "addipato");
735 spin_lock_irqsave(&card->ip_lock, flags);
736 list_for_each_entry(ipatoe, &card->ipato.entries, entry) {
737 if (ipatoe->proto != new->proto)
739 if (!memcmp(ipatoe->addr, new->addr,
740 (ipatoe->proto == QETH_PROT_IPV4)? 4:16) &&
741 (ipatoe->mask_bits == new->mask_bits)) {
742 PRINT_WARN("ipato entry already exists!\n");
748 list_add_tail(&new->entry, &card->ipato.entries);
750 spin_unlock_irqrestore(&card->ip_lock, flags);
754 void qeth_l3_del_ipato_entry(struct qeth_card *card,
755 enum qeth_prot_versions proto, u8 *addr, int mask_bits)
757 struct qeth_ipato_entry *ipatoe, *tmp;
760 QETH_DBF_TEXT(trace, 2, "delipato");
761 spin_lock_irqsave(&card->ip_lock, flags);
762 list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry) {
763 if (ipatoe->proto != proto)
765 if (!memcmp(ipatoe->addr, addr,
766 (proto == QETH_PROT_IPV4)? 4:16) &&
767 (ipatoe->mask_bits == mask_bits)) {
768 list_del(&ipatoe->entry);
772 spin_unlock_irqrestore(&card->ip_lock, flags);
776 * VIPA related functions
778 int qeth_l3_add_vipa(struct qeth_card *card, enum qeth_prot_versions proto,
781 struct qeth_ipaddr *ipaddr;
785 ipaddr = qeth_l3_get_addr_buffer(proto);
787 if (proto == QETH_PROT_IPV4) {
788 QETH_DBF_TEXT(trace, 2, "addvipa4");
789 memcpy(&ipaddr->u.a4.addr, addr, 4);
790 ipaddr->u.a4.mask = 0;
791 } else if (proto == QETH_PROT_IPV6) {
792 QETH_DBF_TEXT(trace, 2, "addvipa6");
793 memcpy(&ipaddr->u.a6.addr, addr, 16);
794 ipaddr->u.a6.pfxlen = 0;
796 ipaddr->type = QETH_IP_TYPE_VIPA;
797 ipaddr->set_flags = QETH_IPA_SETIP_VIPA_FLAG;
798 ipaddr->del_flags = QETH_IPA_DELIP_VIPA_FLAG;
801 spin_lock_irqsave(&card->ip_lock, flags);
802 if (qeth_l3_address_exists_in_list(&card->ip_list, ipaddr, 0) ||
803 qeth_l3_address_exists_in_list(card->ip_tbd_list, ipaddr, 0))
805 spin_unlock_irqrestore(&card->ip_lock, flags);
807 PRINT_WARN("Cannot add VIPA. Address already exists!\n");
810 if (!qeth_l3_add_ip(card, ipaddr))
812 qeth_l3_set_ip_addr_list(card);
816 void qeth_l3_del_vipa(struct qeth_card *card, enum qeth_prot_versions proto,
819 struct qeth_ipaddr *ipaddr;
821 ipaddr = qeth_l3_get_addr_buffer(proto);
823 if (proto == QETH_PROT_IPV4) {
824 QETH_DBF_TEXT(trace, 2, "delvipa4");
825 memcpy(&ipaddr->u.a4.addr, addr, 4);
826 ipaddr->u.a4.mask = 0;
827 } else if (proto == QETH_PROT_IPV6) {
828 QETH_DBF_TEXT(trace, 2, "delvipa6");
829 memcpy(&ipaddr->u.a6.addr, addr, 16);
830 ipaddr->u.a6.pfxlen = 0;
832 ipaddr->type = QETH_IP_TYPE_VIPA;
835 if (!qeth_l3_delete_ip(card, ipaddr))
837 qeth_l3_set_ip_addr_list(card);
841 * proxy ARP related functions
843 int qeth_l3_add_rxip(struct qeth_card *card, enum qeth_prot_versions proto,
846 struct qeth_ipaddr *ipaddr;
850 ipaddr = qeth_l3_get_addr_buffer(proto);
852 if (proto == QETH_PROT_IPV4) {
853 QETH_DBF_TEXT(trace, 2, "addrxip4");
854 memcpy(&ipaddr->u.a4.addr, addr, 4);
855 ipaddr->u.a4.mask = 0;
856 } else if (proto == QETH_PROT_IPV6) {
857 QETH_DBF_TEXT(trace, 2, "addrxip6");
858 memcpy(&ipaddr->u.a6.addr, addr, 16);
859 ipaddr->u.a6.pfxlen = 0;
861 ipaddr->type = QETH_IP_TYPE_RXIP;
862 ipaddr->set_flags = QETH_IPA_SETIP_TAKEOVER_FLAG;
863 ipaddr->del_flags = 0;
866 spin_lock_irqsave(&card->ip_lock, flags);
867 if (qeth_l3_address_exists_in_list(&card->ip_list, ipaddr, 0) ||
868 qeth_l3_address_exists_in_list(card->ip_tbd_list, ipaddr, 0))
870 spin_unlock_irqrestore(&card->ip_lock, flags);
872 PRINT_WARN("Cannot add RXIP. Address already exists!\n");
875 if (!qeth_l3_add_ip(card, ipaddr))
877 qeth_l3_set_ip_addr_list(card);
881 void qeth_l3_del_rxip(struct qeth_card *card, enum qeth_prot_versions proto,
884 struct qeth_ipaddr *ipaddr;
886 ipaddr = qeth_l3_get_addr_buffer(proto);
888 if (proto == QETH_PROT_IPV4) {
889 QETH_DBF_TEXT(trace, 2, "addrxip4");
890 memcpy(&ipaddr->u.a4.addr, addr, 4);
891 ipaddr->u.a4.mask = 0;
892 } else if (proto == QETH_PROT_IPV6) {
893 QETH_DBF_TEXT(trace, 2, "addrxip6");
894 memcpy(&ipaddr->u.a6.addr, addr, 16);
895 ipaddr->u.a6.pfxlen = 0;
897 ipaddr->type = QETH_IP_TYPE_RXIP;
900 if (!qeth_l3_delete_ip(card, ipaddr))
902 qeth_l3_set_ip_addr_list(card);
905 static int qeth_l3_register_addr_entry(struct qeth_card *card,
906 struct qeth_ipaddr *addr)
912 if (addr->proto == QETH_PROT_IPV4) {
913 QETH_DBF_TEXT(trace, 2, "setaddr4");
914 QETH_DBF_HEX(trace, 3, &addr->u.a4.addr, sizeof(int));
915 } else if (addr->proto == QETH_PROT_IPV6) {
916 QETH_DBF_TEXT(trace, 2, "setaddr6");
917 QETH_DBF_HEX(trace, 3, &addr->u.a6.addr, 8);
918 QETH_DBF_HEX(trace, 3, ((char *)&addr->u.a6.addr) + 8, 8);
920 QETH_DBF_TEXT(trace, 2, "setaddr?");
921 QETH_DBF_HEX(trace, 3, addr, sizeof(struct qeth_ipaddr));
924 if (addr->is_multicast)
925 rc = qeth_l3_send_setdelmc(card, addr, IPA_CMD_SETIPM);
927 rc = qeth_l3_send_setdelip(card, addr, IPA_CMD_SETIP,
930 QETH_DBF_TEXT(trace, 2, "failed");
931 } while ((--cnt > 0) && rc);
933 QETH_DBF_TEXT(trace, 2, "FAILED");
934 qeth_l3_ipaddr_to_string(addr->proto, (u8 *)&addr->u, buf);
935 PRINT_WARN("Could not register IP address %s (rc=0x%x/%d)\n",
941 static int qeth_l3_deregister_addr_entry(struct qeth_card *card,
942 struct qeth_ipaddr *addr)
946 if (addr->proto == QETH_PROT_IPV4) {
947 QETH_DBF_TEXT(trace, 2, "deladdr4");
948 QETH_DBF_HEX(trace, 3, &addr->u.a4.addr, sizeof(int));
949 } else if (addr->proto == QETH_PROT_IPV6) {
950 QETH_DBF_TEXT(trace, 2, "deladdr6");
951 QETH_DBF_HEX(trace, 3, &addr->u.a6.addr, 8);
952 QETH_DBF_HEX(trace, 3, ((char *)&addr->u.a6.addr) + 8, 8);
954 QETH_DBF_TEXT(trace, 2, "deladdr?");
955 QETH_DBF_HEX(trace, 3, addr, sizeof(struct qeth_ipaddr));
957 if (addr->is_multicast)
958 rc = qeth_l3_send_setdelmc(card, addr, IPA_CMD_DELIPM);
960 rc = qeth_l3_send_setdelip(card, addr, IPA_CMD_DELIP,
963 QETH_DBF_TEXT(trace, 2, "failed");
964 /* TODO: re-activate this warning as soon as we have a
966 qeth_ipaddr_to_string(addr->proto, (u8 *)&addr->u, buf);
967 PRINT_WARN("Could not deregister IP address %s (rc=%x)\n",
975 static inline u8 qeth_l3_get_qeth_hdr_flags4(int cast_type)
977 if (cast_type == RTN_MULTICAST)
978 return QETH_CAST_MULTICAST;
979 if (cast_type == RTN_BROADCAST)
980 return QETH_CAST_BROADCAST;
981 return QETH_CAST_UNICAST;
984 static inline u8 qeth_l3_get_qeth_hdr_flags6(int cast_type)
986 u8 ct = QETH_HDR_PASSTHRU | QETH_HDR_IPV6;
987 if (cast_type == RTN_MULTICAST)
988 return ct | QETH_CAST_MULTICAST;
989 if (cast_type == RTN_ANYCAST)
990 return ct | QETH_CAST_ANYCAST;
991 if (cast_type == RTN_BROADCAST)
992 return ct | QETH_CAST_BROADCAST;
993 return ct | QETH_CAST_UNICAST;
996 static int qeth_l3_send_setadp_mode(struct qeth_card *card, __u32 command,
1000 struct qeth_cmd_buffer *iob;
1001 struct qeth_ipa_cmd *cmd;
1003 QETH_DBF_TEXT(trace, 4, "adpmode");
1005 iob = qeth_get_adapter_cmd(card, command,
1006 sizeof(struct qeth_ipacmd_setadpparms));
1007 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1008 cmd->data.setadapterparms.data.mode = mode;
1009 rc = qeth_send_ipa_cmd(card, iob, qeth_default_setadapterparms_cb,
1014 static int qeth_l3_setadapter_hstr(struct qeth_card *card)
1018 QETH_DBF_TEXT(trace, 4, "adphstr");
1020 if (qeth_adp_supported(card, IPA_SETADP_SET_BROADCAST_MODE)) {
1021 rc = qeth_l3_send_setadp_mode(card,
1022 IPA_SETADP_SET_BROADCAST_MODE,
1023 card->options.broadcast_mode);
1025 PRINT_WARN("couldn't set broadcast mode on "
1027 CARD_BUS_ID(card), rc);
1028 rc = qeth_l3_send_setadp_mode(card,
1029 IPA_SETADP_ALTER_MAC_ADDRESS,
1030 card->options.macaddr_mode);
1032 PRINT_WARN("couldn't set macaddr mode on "
1033 "device %s: x%x\n", CARD_BUS_ID(card), rc);
1036 if (card->options.broadcast_mode == QETH_TR_BROADCAST_LOCAL)
1037 PRINT_WARN("set adapter parameters not available "
1038 "to set broadcast mode, using ALLRINGS "
1039 "on device %s:\n", CARD_BUS_ID(card));
1040 if (card->options.macaddr_mode == QETH_TR_MACADDR_CANONICAL)
1041 PRINT_WARN("set adapter parameters not available "
1042 "to set macaddr mode, using NONCANONICAL "
1043 "on device %s:\n", CARD_BUS_ID(card));
1047 static int qeth_l3_setadapter_parms(struct qeth_card *card)
1051 QETH_DBF_TEXT(setup, 2, "setadprm");
1053 if (!qeth_is_supported(card, IPA_SETADAPTERPARMS)) {
1054 PRINT_WARN("set adapter parameters not supported "
1057 QETH_DBF_TEXT(setup, 2, " notsupp");
1060 rc = qeth_query_setadapterparms(card);
1062 PRINT_WARN("couldn't set adapter parameters on device %s: "
1063 "x%x\n", CARD_BUS_ID(card), rc);
1066 if (qeth_adp_supported(card, IPA_SETADP_ALTER_MAC_ADDRESS)) {
1067 rc = qeth_setadpparms_change_macaddr(card);
1069 PRINT_WARN("couldn't get MAC address on "
1071 CARD_BUS_ID(card), rc);
1074 if ((card->info.link_type == QETH_LINK_TYPE_HSTR) ||
1075 (card->info.link_type == QETH_LINK_TYPE_LANE_TR))
1076 rc = qeth_l3_setadapter_hstr(card);
1081 static int qeth_l3_default_setassparms_cb(struct qeth_card *card,
1082 struct qeth_reply *reply, unsigned long data)
1084 struct qeth_ipa_cmd *cmd;
1086 QETH_DBF_TEXT(trace, 4, "defadpcb");
1088 cmd = (struct qeth_ipa_cmd *) data;
1089 if (cmd->hdr.return_code == 0) {
1090 cmd->hdr.return_code = cmd->data.setassparms.hdr.return_code;
1091 if (cmd->hdr.prot_version == QETH_PROT_IPV4)
1092 card->options.ipa4.enabled_funcs = cmd->hdr.ipa_enabled;
1093 if (cmd->hdr.prot_version == QETH_PROT_IPV6)
1094 card->options.ipa6.enabled_funcs = cmd->hdr.ipa_enabled;
1096 if (cmd->data.setassparms.hdr.assist_no == IPA_INBOUND_CHECKSUM &&
1097 cmd->data.setassparms.hdr.command_code == IPA_CMD_ASS_START) {
1098 card->info.csum_mask = cmd->data.setassparms.data.flags_32bit;
1099 QETH_DBF_TEXT_(trace, 3, "csum:%d", card->info.csum_mask);
1104 static struct qeth_cmd_buffer *qeth_l3_get_setassparms_cmd(
1105 struct qeth_card *card, enum qeth_ipa_funcs ipa_func, __u16 cmd_code,
1106 __u16 len, enum qeth_prot_versions prot)
1108 struct qeth_cmd_buffer *iob;
1109 struct qeth_ipa_cmd *cmd;
1111 QETH_DBF_TEXT(trace, 4, "getasscm");
1112 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SETASSPARMS, prot);
1114 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1115 cmd->data.setassparms.hdr.assist_no = ipa_func;
1116 cmd->data.setassparms.hdr.length = 8 + len;
1117 cmd->data.setassparms.hdr.command_code = cmd_code;
1118 cmd->data.setassparms.hdr.return_code = 0;
1119 cmd->data.setassparms.hdr.seq_no = 0;
1124 static int qeth_l3_send_setassparms(struct qeth_card *card,
1125 struct qeth_cmd_buffer *iob, __u16 len, long data,
1126 int (*reply_cb)(struct qeth_card *, struct qeth_reply *,
1131 struct qeth_ipa_cmd *cmd;
1133 QETH_DBF_TEXT(trace, 4, "sendassp");
1135 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1136 if (len <= sizeof(__u32))
1137 cmd->data.setassparms.data.flags_32bit = (__u32) data;
1138 else /* (len > sizeof(__u32)) */
1139 memcpy(&cmd->data.setassparms.data, (void *) data, len);
1141 rc = qeth_send_ipa_cmd(card, iob, reply_cb, reply_param);
1145 #ifdef CONFIG_QETH_IPV6
1146 static int qeth_l3_send_simple_setassparms_ipv6(struct qeth_card *card,
1147 enum qeth_ipa_funcs ipa_func, __u16 cmd_code)
1150 struct qeth_cmd_buffer *iob;
1152 QETH_DBF_TEXT(trace, 4, "simassp6");
1153 iob = qeth_l3_get_setassparms_cmd(card, ipa_func, cmd_code,
1155 rc = qeth_l3_send_setassparms(card, iob, 0, 0,
1156 qeth_l3_default_setassparms_cb, NULL);
1161 static int qeth_l3_send_simple_setassparms(struct qeth_card *card,
1162 enum qeth_ipa_funcs ipa_func, __u16 cmd_code, long data)
1166 struct qeth_cmd_buffer *iob;
1168 QETH_DBF_TEXT(trace, 4, "simassp4");
1170 length = sizeof(__u32);
1171 iob = qeth_l3_get_setassparms_cmd(card, ipa_func, cmd_code,
1172 length, QETH_PROT_IPV4);
1173 rc = qeth_l3_send_setassparms(card, iob, length, data,
1174 qeth_l3_default_setassparms_cb, NULL);
1178 static int qeth_l3_start_ipa_arp_processing(struct qeth_card *card)
1182 QETH_DBF_TEXT(trace, 3, "ipaarp");
1184 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
1185 PRINT_WARN("ARP processing not supported "
1186 "on %s!\n", QETH_CARD_IFNAME(card));
1189 rc = qeth_l3_send_simple_setassparms(card, IPA_ARP_PROCESSING,
1190 IPA_CMD_ASS_START, 0);
1192 PRINT_WARN("Could not start ARP processing "
1193 "assist on %s: 0x%x\n",
1194 QETH_CARD_IFNAME(card), rc);
1199 static int qeth_l3_start_ipa_ip_fragmentation(struct qeth_card *card)
1203 QETH_DBF_TEXT(trace, 3, "ipaipfrg");
1205 if (!qeth_is_supported(card, IPA_IP_FRAGMENTATION)) {
1206 PRINT_INFO("Hardware IP fragmentation not supported on %s\n",
1207 QETH_CARD_IFNAME(card));
1211 rc = qeth_l3_send_simple_setassparms(card, IPA_IP_FRAGMENTATION,
1212 IPA_CMD_ASS_START, 0);
1214 PRINT_WARN("Could not start Hardware IP fragmentation "
1215 "assist on %s: 0x%x\n",
1216 QETH_CARD_IFNAME(card), rc);
1218 PRINT_INFO("Hardware IP fragmentation enabled \n");
1222 static int qeth_l3_start_ipa_source_mac(struct qeth_card *card)
1226 QETH_DBF_TEXT(trace, 3, "stsrcmac");
1228 if (!card->options.fake_ll)
1231 if (!qeth_is_supported(card, IPA_SOURCE_MAC)) {
1232 PRINT_INFO("Inbound source address not "
1233 "supported on %s\n", QETH_CARD_IFNAME(card));
1237 rc = qeth_l3_send_simple_setassparms(card, IPA_SOURCE_MAC,
1238 IPA_CMD_ASS_START, 0);
1240 PRINT_WARN("Could not start inbound source "
1241 "assist on %s: 0x%x\n",
1242 QETH_CARD_IFNAME(card), rc);
1246 static int qeth_l3_start_ipa_vlan(struct qeth_card *card)
1250 QETH_DBF_TEXT(trace, 3, "strtvlan");
1252 if (!qeth_is_supported(card, IPA_FULL_VLAN)) {
1253 PRINT_WARN("VLAN not supported on %s\n",
1254 QETH_CARD_IFNAME(card));
1258 rc = qeth_l3_send_simple_setassparms(card, IPA_VLAN_PRIO,
1259 IPA_CMD_ASS_START, 0);
1261 PRINT_WARN("Could not start vlan "
1262 "assist on %s: 0x%x\n",
1263 QETH_CARD_IFNAME(card), rc);
1265 PRINT_INFO("VLAN enabled \n");
1270 static int qeth_l3_start_ipa_multicast(struct qeth_card *card)
1274 QETH_DBF_TEXT(trace, 3, "stmcast");
1276 if (!qeth_is_supported(card, IPA_MULTICASTING)) {
1277 PRINT_WARN("Multicast not supported on %s\n",
1278 QETH_CARD_IFNAME(card));
1282 rc = qeth_l3_send_simple_setassparms(card, IPA_MULTICASTING,
1283 IPA_CMD_ASS_START, 0);
1285 PRINT_WARN("Could not start multicast "
1286 "assist on %s: rc=%i\n",
1287 QETH_CARD_IFNAME(card), rc);
1289 PRINT_INFO("Multicast enabled\n");
1290 card->dev->flags |= IFF_MULTICAST;
1295 static int qeth_l3_query_ipassists_cb(struct qeth_card *card,
1296 struct qeth_reply *reply, unsigned long data)
1298 struct qeth_ipa_cmd *cmd;
1300 QETH_DBF_TEXT(setup, 2, "qipasscb");
1302 cmd = (struct qeth_ipa_cmd *) data;
1303 if (cmd->hdr.prot_version == QETH_PROT_IPV4) {
1304 card->options.ipa4.supported_funcs = cmd->hdr.ipa_supported;
1305 card->options.ipa4.enabled_funcs = cmd->hdr.ipa_enabled;
1307 card->options.ipa6.supported_funcs = cmd->hdr.ipa_supported;
1308 card->options.ipa6.enabled_funcs = cmd->hdr.ipa_enabled;
1310 QETH_DBF_TEXT(setup, 2, "suppenbl");
1311 QETH_DBF_TEXT_(setup, 2, "%x", cmd->hdr.ipa_supported);
1312 QETH_DBF_TEXT_(setup, 2, "%x", cmd->hdr.ipa_enabled);
1316 static int qeth_l3_query_ipassists(struct qeth_card *card,
1317 enum qeth_prot_versions prot)
1320 struct qeth_cmd_buffer *iob;
1322 QETH_DBF_TEXT_(setup, 2, "qipassi%i", prot);
1323 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_QIPASSIST, prot);
1324 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_query_ipassists_cb, NULL);
1328 #ifdef CONFIG_QETH_IPV6
1329 static int qeth_l3_softsetup_ipv6(struct qeth_card *card)
1333 QETH_DBF_TEXT(trace, 3, "softipv6");
1335 if (card->info.type == QETH_CARD_TYPE_IQD)
1338 rc = qeth_l3_query_ipassists(card, QETH_PROT_IPV6);
1340 PRINT_ERR("IPv6 query ipassist failed on %s\n",
1341 QETH_CARD_IFNAME(card));
1344 rc = qeth_l3_send_simple_setassparms(card, IPA_IPV6,
1345 IPA_CMD_ASS_START, 3);
1347 PRINT_WARN("IPv6 start assist (version 4) failed "
1349 QETH_CARD_IFNAME(card), rc);
1352 rc = qeth_l3_send_simple_setassparms_ipv6(card, IPA_IPV6,
1355 PRINT_WARN("IPV6 start assist (version 6) failed "
1357 QETH_CARD_IFNAME(card), rc);
1360 rc = qeth_l3_send_simple_setassparms_ipv6(card, IPA_PASSTHRU,
1363 PRINT_WARN("Could not enable passthrough "
1365 QETH_CARD_IFNAME(card), rc);
1369 PRINT_INFO("IPV6 enabled \n");
1374 static int qeth_l3_start_ipa_ipv6(struct qeth_card *card)
1378 QETH_DBF_TEXT(trace, 3, "strtipv6");
1380 if (!qeth_is_supported(card, IPA_IPV6)) {
1381 PRINT_WARN("IPv6 not supported on %s\n",
1382 QETH_CARD_IFNAME(card));
1385 #ifdef CONFIG_QETH_IPV6
1386 rc = qeth_l3_softsetup_ipv6(card);
1391 static int qeth_l3_start_ipa_broadcast(struct qeth_card *card)
1395 QETH_DBF_TEXT(trace, 3, "stbrdcst");
1396 card->info.broadcast_capable = 0;
1397 if (!qeth_is_supported(card, IPA_FILTERING)) {
1398 PRINT_WARN("Broadcast not supported on %s\n",
1399 QETH_CARD_IFNAME(card));
1403 rc = qeth_l3_send_simple_setassparms(card, IPA_FILTERING,
1404 IPA_CMD_ASS_START, 0);
1406 PRINT_WARN("Could not enable broadcasting filtering "
1408 QETH_CARD_IFNAME(card), rc);
1412 rc = qeth_l3_send_simple_setassparms(card, IPA_FILTERING,
1413 IPA_CMD_ASS_CONFIGURE, 1);
1415 PRINT_WARN("Could not set up broadcast filtering on %s: 0x%x\n",
1416 QETH_CARD_IFNAME(card), rc);
1419 card->info.broadcast_capable = QETH_BROADCAST_WITH_ECHO;
1420 PRINT_INFO("Broadcast enabled \n");
1421 rc = qeth_l3_send_simple_setassparms(card, IPA_FILTERING,
1422 IPA_CMD_ASS_ENABLE, 1);
1424 PRINT_WARN("Could not set up broadcast echo filtering on "
1425 "%s: 0x%x\n", QETH_CARD_IFNAME(card), rc);
1428 card->info.broadcast_capable = QETH_BROADCAST_WITHOUT_ECHO;
1430 if (card->info.broadcast_capable)
1431 card->dev->flags |= IFF_BROADCAST;
1433 card->dev->flags &= ~IFF_BROADCAST;
1437 static int qeth_l3_send_checksum_command(struct qeth_card *card)
1441 rc = qeth_l3_send_simple_setassparms(card, IPA_INBOUND_CHECKSUM,
1442 IPA_CMD_ASS_START, 0);
1444 PRINT_WARN("Starting Inbound HW Checksumming failed on %s: "
1445 "0x%x,\ncontinuing using Inbound SW Checksumming\n",
1446 QETH_CARD_IFNAME(card), rc);
1449 rc = qeth_l3_send_simple_setassparms(card, IPA_INBOUND_CHECKSUM,
1451 card->info.csum_mask);
1453 PRINT_WARN("Enabling Inbound HW Checksumming failed on %s: "
1454 "0x%x,\ncontinuing using Inbound SW Checksumming\n",
1455 QETH_CARD_IFNAME(card), rc);
1461 static int qeth_l3_start_ipa_checksum(struct qeth_card *card)
1465 QETH_DBF_TEXT(trace, 3, "strtcsum");
1467 if (card->options.checksum_type == NO_CHECKSUMMING) {
1468 PRINT_WARN("Using no checksumming on %s.\n",
1469 QETH_CARD_IFNAME(card));
1472 if (card->options.checksum_type == SW_CHECKSUMMING) {
1473 PRINT_WARN("Using SW checksumming on %s.\n",
1474 QETH_CARD_IFNAME(card));
1477 if (!qeth_is_supported(card, IPA_INBOUND_CHECKSUM)) {
1478 PRINT_WARN("Inbound HW Checksumming not "
1479 "supported on %s,\ncontinuing "
1480 "using Inbound SW Checksumming\n",
1481 QETH_CARD_IFNAME(card));
1482 card->options.checksum_type = SW_CHECKSUMMING;
1485 rc = qeth_l3_send_checksum_command(card);
1487 PRINT_INFO("HW Checksumming (inbound) enabled \n");
1492 static int qeth_l3_start_ipa_tso(struct qeth_card *card)
1496 QETH_DBF_TEXT(trace, 3, "sttso");
1498 if (!qeth_is_supported(card, IPA_OUTBOUND_TSO)) {
1499 PRINT_WARN("Outbound TSO not supported on %s\n",
1500 QETH_CARD_IFNAME(card));
1503 rc = qeth_l3_send_simple_setassparms(card, IPA_OUTBOUND_TSO,
1504 IPA_CMD_ASS_START, 0);
1506 PRINT_WARN("Could not start outbound TSO "
1507 "assist on %s: rc=%i\n",
1508 QETH_CARD_IFNAME(card), rc);
1510 PRINT_INFO("Outbound TSO enabled\n");
1512 if (rc && (card->options.large_send == QETH_LARGE_SEND_TSO)) {
1513 card->options.large_send = QETH_LARGE_SEND_NO;
1514 card->dev->features &= ~(NETIF_F_TSO | NETIF_F_SG);
1519 static int qeth_l3_start_ipassists(struct qeth_card *card)
1521 QETH_DBF_TEXT(trace, 3, "strtipas");
1522 qeth_l3_start_ipa_arp_processing(card); /* go on*/
1523 qeth_l3_start_ipa_ip_fragmentation(card); /* go on*/
1524 qeth_l3_start_ipa_source_mac(card); /* go on*/
1525 qeth_l3_start_ipa_vlan(card); /* go on*/
1526 qeth_l3_start_ipa_multicast(card); /* go on*/
1527 qeth_l3_start_ipa_ipv6(card); /* go on*/
1528 qeth_l3_start_ipa_broadcast(card); /* go on*/
1529 qeth_l3_start_ipa_checksum(card); /* go on*/
1530 qeth_l3_start_ipa_tso(card); /* go on*/
1534 static int qeth_l3_put_unique_id(struct qeth_card *card)
1538 struct qeth_cmd_buffer *iob;
1539 struct qeth_ipa_cmd *cmd;
1541 QETH_DBF_TEXT(trace, 2, "puniqeid");
1543 if ((card->info.unique_id & UNIQUE_ID_NOT_BY_CARD) ==
1544 UNIQUE_ID_NOT_BY_CARD)
1546 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_DESTROY_ADDR,
1548 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1549 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
1550 card->info.unique_id;
1551 memcpy(&cmd->data.create_destroy_addr.unique_id[0],
1552 card->dev->dev_addr, OSA_ADDR_LEN);
1553 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
1557 static int qeth_l3_iqd_read_initial_mac_cb(struct qeth_card *card,
1558 struct qeth_reply *reply, unsigned long data)
1560 struct qeth_ipa_cmd *cmd;
1562 cmd = (struct qeth_ipa_cmd *) data;
1563 if (cmd->hdr.return_code == 0)
1564 memcpy(card->dev->dev_addr,
1565 cmd->data.create_destroy_addr.unique_id, ETH_ALEN);
1567 random_ether_addr(card->dev->dev_addr);
1572 static int qeth_l3_iqd_read_initial_mac(struct qeth_card *card)
1575 struct qeth_cmd_buffer *iob;
1576 struct qeth_ipa_cmd *cmd;
1578 QETH_DBF_TEXT(setup, 2, "hsrmac");
1580 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_CREATE_ADDR,
1582 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1583 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
1584 card->info.unique_id;
1586 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_iqd_read_initial_mac_cb,
1591 static int qeth_l3_get_unique_id_cb(struct qeth_card *card,
1592 struct qeth_reply *reply, unsigned long data)
1594 struct qeth_ipa_cmd *cmd;
1596 cmd = (struct qeth_ipa_cmd *) data;
1597 if (cmd->hdr.return_code == 0)
1598 card->info.unique_id = *((__u16 *)
1599 &cmd->data.create_destroy_addr.unique_id[6]);
1601 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
1602 UNIQUE_ID_NOT_BY_CARD;
1603 PRINT_WARN("couldn't get a unique id from the card on device "
1604 "%s (result=x%x), using default id. ipv6 "
1605 "autoconfig on other lpars may lead to duplicate "
1606 "ip addresses. please use manually "
1607 "configured ones.\n",
1608 CARD_BUS_ID(card), cmd->hdr.return_code);
1613 static int qeth_l3_get_unique_id(struct qeth_card *card)
1616 struct qeth_cmd_buffer *iob;
1617 struct qeth_ipa_cmd *cmd;
1619 QETH_DBF_TEXT(setup, 2, "guniqeid");
1621 if (!qeth_is_supported(card, IPA_IPV6)) {
1622 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
1623 UNIQUE_ID_NOT_BY_CARD;
1627 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_CREATE_ADDR,
1629 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1630 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
1631 card->info.unique_id;
1633 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_get_unique_id_cb, NULL);
1637 static void qeth_l3_get_mac_for_ipm(__u32 ipm, char *mac,
1638 struct net_device *dev)
1640 if (dev->type == ARPHRD_IEEE802_TR)
1641 ip_tr_mc_map(ipm, mac);
1643 ip_eth_mc_map(ipm, mac);
1646 static void qeth_l3_add_mc(struct qeth_card *card, struct in_device *in4_dev)
1648 struct qeth_ipaddr *ipm;
1649 struct ip_mc_list *im4;
1650 char buf[MAX_ADDR_LEN];
1652 QETH_DBF_TEXT(trace, 4, "addmc");
1653 for (im4 = in4_dev->mc_list; im4; im4 = im4->next) {
1654 qeth_l3_get_mac_for_ipm(im4->multiaddr, buf, in4_dev->dev);
1655 ipm = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
1658 ipm->u.a4.addr = im4->multiaddr;
1659 memcpy(ipm->mac, buf, OSA_ADDR_LEN);
1660 ipm->is_multicast = 1;
1661 if (!qeth_l3_add_ip(card, ipm))
1666 static void qeth_l3_add_vlan_mc(struct qeth_card *card)
1668 struct in_device *in_dev;
1669 struct vlan_group *vg;
1672 QETH_DBF_TEXT(trace, 4, "addmcvl");
1673 if (!qeth_is_supported(card, IPA_FULL_VLAN) || (card->vlangrp == NULL))
1677 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
1678 struct net_device *netdev = vlan_group_get_device(vg, i);
1679 if (netdev == NULL ||
1680 !(netdev->flags & IFF_UP))
1682 in_dev = in_dev_get(netdev);
1685 read_lock(&in_dev->mc_list_lock);
1686 qeth_l3_add_mc(card, in_dev);
1687 read_unlock(&in_dev->mc_list_lock);
1692 static void qeth_l3_add_multicast_ipv4(struct qeth_card *card)
1694 struct in_device *in4_dev;
1696 QETH_DBF_TEXT(trace, 4, "chkmcv4");
1697 in4_dev = in_dev_get(card->dev);
1698 if (in4_dev == NULL)
1700 read_lock(&in4_dev->mc_list_lock);
1701 qeth_l3_add_mc(card, in4_dev);
1702 qeth_l3_add_vlan_mc(card);
1703 read_unlock(&in4_dev->mc_list_lock);
1704 in_dev_put(in4_dev);
1707 #ifdef CONFIG_QETH_IPV6
1708 static void qeth_l3_add_mc6(struct qeth_card *card, struct inet6_dev *in6_dev)
1710 struct qeth_ipaddr *ipm;
1711 struct ifmcaddr6 *im6;
1712 char buf[MAX_ADDR_LEN];
1714 QETH_DBF_TEXT(trace, 4, "addmc6");
1715 for (im6 = in6_dev->mc_list; im6 != NULL; im6 = im6->next) {
1716 ndisc_mc_map(&im6->mca_addr, buf, in6_dev->dev, 0);
1717 ipm = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
1720 ipm->is_multicast = 1;
1721 memcpy(ipm->mac, buf, OSA_ADDR_LEN);
1722 memcpy(&ipm->u.a6.addr, &im6->mca_addr.s6_addr,
1723 sizeof(struct in6_addr));
1724 if (!qeth_l3_add_ip(card, ipm))
1729 static void qeth_l3_add_vlan_mc6(struct qeth_card *card)
1731 struct inet6_dev *in_dev;
1732 struct vlan_group *vg;
1735 QETH_DBF_TEXT(trace, 4, "admc6vl");
1736 if (!qeth_is_supported(card, IPA_FULL_VLAN) || (card->vlangrp == NULL))
1740 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
1741 struct net_device *netdev = vlan_group_get_device(vg, i);
1742 if (netdev == NULL ||
1743 !(netdev->flags & IFF_UP))
1745 in_dev = in6_dev_get(netdev);
1748 read_lock_bh(&in_dev->lock);
1749 qeth_l3_add_mc6(card, in_dev);
1750 read_unlock_bh(&in_dev->lock);
1751 in6_dev_put(in_dev);
1755 static void qeth_l3_add_multicast_ipv6(struct qeth_card *card)
1757 struct inet6_dev *in6_dev;
1759 QETH_DBF_TEXT(trace, 4, "chkmcv6");
1760 if (!qeth_is_supported(card, IPA_IPV6))
1762 in6_dev = in6_dev_get(card->dev);
1763 if (in6_dev == NULL)
1765 read_lock_bh(&in6_dev->lock);
1766 qeth_l3_add_mc6(card, in6_dev);
1767 qeth_l3_add_vlan_mc6(card);
1768 read_unlock_bh(&in6_dev->lock);
1769 in6_dev_put(in6_dev);
1771 #endif /* CONFIG_QETH_IPV6 */
1773 static void qeth_l3_free_vlan_addresses4(struct qeth_card *card,
1776 struct in_device *in_dev;
1777 struct in_ifaddr *ifa;
1778 struct qeth_ipaddr *addr;
1780 QETH_DBF_TEXT(trace, 4, "frvaddr4");
1782 in_dev = in_dev_get(vlan_group_get_device(card->vlangrp, vid));
1785 for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
1786 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
1788 addr->u.a4.addr = ifa->ifa_address;
1789 addr->u.a4.mask = ifa->ifa_mask;
1790 addr->type = QETH_IP_TYPE_NORMAL;
1791 if (!qeth_l3_delete_ip(card, addr))
1798 static void qeth_l3_free_vlan_addresses6(struct qeth_card *card,
1801 #ifdef CONFIG_QETH_IPV6
1802 struct inet6_dev *in6_dev;
1803 struct inet6_ifaddr *ifa;
1804 struct qeth_ipaddr *addr;
1806 QETH_DBF_TEXT(trace, 4, "frvaddr6");
1808 in6_dev = in6_dev_get(vlan_group_get_device(card->vlangrp, vid));
1811 for (ifa = in6_dev->addr_list; ifa; ifa = ifa->lst_next) {
1812 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
1814 memcpy(&addr->u.a6.addr, &ifa->addr,
1815 sizeof(struct in6_addr));
1816 addr->u.a6.pfxlen = ifa->prefix_len;
1817 addr->type = QETH_IP_TYPE_NORMAL;
1818 if (!qeth_l3_delete_ip(card, addr))
1822 in6_dev_put(in6_dev);
1823 #endif /* CONFIG_QETH_IPV6 */
1826 static void qeth_l3_free_vlan_addresses(struct qeth_card *card,
1831 qeth_l3_free_vlan_addresses4(card, vid);
1832 qeth_l3_free_vlan_addresses6(card, vid);
1835 static void qeth_l3_vlan_rx_register(struct net_device *dev,
1836 struct vlan_group *grp)
1838 struct qeth_card *card = netdev_priv(dev);
1839 unsigned long flags;
1841 QETH_DBF_TEXT(trace, 4, "vlanreg");
1842 spin_lock_irqsave(&card->vlanlock, flags);
1843 card->vlangrp = grp;
1844 spin_unlock_irqrestore(&card->vlanlock, flags);
1847 static void qeth_l3_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
1849 struct net_device *vlandev;
1850 struct qeth_card *card = (struct qeth_card *) dev->priv;
1851 struct in_device *in_dev;
1853 if (card->info.type == QETH_CARD_TYPE_IQD)
1856 vlandev = vlan_group_get_device(card->vlangrp, vid);
1857 vlandev->neigh_setup = qeth_l3_neigh_setup;
1859 in_dev = in_dev_get(vlandev);
1860 #ifdef CONFIG_SYSCTL
1861 neigh_sysctl_unregister(in_dev->arp_parms);
1863 neigh_parms_release(&arp_tbl, in_dev->arp_parms);
1865 in_dev->arp_parms = neigh_parms_alloc(vlandev, &arp_tbl);
1866 #ifdef CONFIG_SYSCTL
1867 neigh_sysctl_register(vlandev, in_dev->arp_parms, NET_IPV4,
1868 NET_IPV4_NEIGH, "ipv4", NULL, NULL);
1874 static void qeth_l3_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
1876 struct qeth_card *card = netdev_priv(dev);
1877 unsigned long flags;
1879 QETH_DBF_TEXT_(trace, 4, "kid:%d", vid);
1880 spin_lock_irqsave(&card->vlanlock, flags);
1881 /* unregister IP addresses of vlan device */
1882 qeth_l3_free_vlan_addresses(card, vid);
1883 vlan_group_set_device(card->vlangrp, vid, NULL);
1884 spin_unlock_irqrestore(&card->vlanlock, flags);
1885 qeth_l3_set_multicast_list(card->dev);
1888 static inline __u16 qeth_l3_rebuild_skb(struct qeth_card *card,
1889 struct sk_buff *skb, struct qeth_hdr *hdr)
1891 unsigned short vlan_id = 0;
1893 struct iphdr *ip_hdr;
1894 unsigned char tg_addr[MAX_ADDR_LEN];
1896 if (!(hdr->hdr.l3.flags & QETH_HDR_PASSTHRU)) {
1897 prot = htons((hdr->hdr.l3.flags & QETH_HDR_IPV6)? ETH_P_IPV6 :
1899 switch (hdr->hdr.l3.flags & QETH_HDR_CAST_MASK) {
1900 case QETH_CAST_MULTICAST:
1902 #ifdef CONFIG_QETH_IPV6
1903 case __constant_htons(ETH_P_IPV6):
1904 ndisc_mc_map((struct in6_addr *)
1906 tg_addr, card->dev, 0);
1909 case __constant_htons(ETH_P_IP):
1910 ip_hdr = (struct iphdr *)skb->data;
1911 (card->dev->type == ARPHRD_IEEE802_TR) ?
1912 ip_tr_mc_map(ip_hdr->daddr, tg_addr):
1913 ip_eth_mc_map(ip_hdr->daddr, tg_addr);
1916 memcpy(tg_addr, card->dev->broadcast,
1917 card->dev->addr_len);
1919 card->stats.multicast++;
1920 skb->pkt_type = PACKET_MULTICAST;
1922 case QETH_CAST_BROADCAST:
1923 memcpy(tg_addr, card->dev->broadcast,
1924 card->dev->addr_len);
1925 card->stats.multicast++;
1926 skb->pkt_type = PACKET_BROADCAST;
1928 case QETH_CAST_UNICAST:
1929 case QETH_CAST_ANYCAST:
1930 case QETH_CAST_NOCAST:
1932 skb->pkt_type = PACKET_HOST;
1933 memcpy(tg_addr, card->dev->dev_addr,
1934 card->dev->addr_len);
1936 card->dev->header_ops->create(skb, card->dev, prot, tg_addr,
1937 "FAKELL", card->dev->addr_len);
1941 if (card->dev->type == ARPHRD_IEEE802_TR)
1942 skb->protocol = tr_type_trans(skb, card->dev);
1945 skb->protocol = eth_type_trans(skb, card->dev);
1947 if (hdr->hdr.l3.ext_flags &
1948 (QETH_HDR_EXT_VLAN_FRAME | QETH_HDR_EXT_INCLUDE_VLAN_TAG)) {
1949 vlan_id = (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_VLAN_FRAME)?
1950 hdr->hdr.l3.vlan_id : *((u16 *)&hdr->hdr.l3.dest_addr[12]);
1953 skb->ip_summed = card->options.checksum_type;
1954 if (card->options.checksum_type == HW_CHECKSUMMING) {
1955 if ((hdr->hdr.l3.ext_flags &
1956 (QETH_HDR_EXT_CSUM_HDR_REQ |
1957 QETH_HDR_EXT_CSUM_TRANSP_REQ)) ==
1958 (QETH_HDR_EXT_CSUM_HDR_REQ |
1959 QETH_HDR_EXT_CSUM_TRANSP_REQ))
1960 skb->ip_summed = CHECKSUM_UNNECESSARY;
1962 skb->ip_summed = SW_CHECKSUMMING;
1968 static void qeth_l3_process_inbound_buffer(struct qeth_card *card,
1969 struct qeth_qdio_buffer *buf, int index)
1971 struct qdio_buffer_element *element;
1972 struct sk_buff *skb;
1973 struct qeth_hdr *hdr;
1978 /* get first element of current buffer */
1979 element = (struct qdio_buffer_element *)&buf->buffer->element[0];
1981 if (card->options.performance_stats)
1982 card->perf_stats.bufs_rec++;
1983 while ((skb = qeth_core_get_next_skb(card, buf->buffer, &element,
1985 skb->dev = card->dev;
1986 /* is device UP ? */
1987 if (!(card->dev->flags & IFF_UP)) {
1988 dev_kfree_skb_any(skb);
1992 switch (hdr->hdr.l3.id) {
1993 case QETH_HEADER_TYPE_LAYER3:
1994 vlan_tag = qeth_l3_rebuild_skb(card, skb, hdr);
1998 vlan_hwaccel_rx(skb, card->vlangrp,
2001 dev_kfree_skb_any(skb);
2008 dev_kfree_skb_any(skb);
2009 QETH_DBF_TEXT(trace, 3, "inbunkno");
2010 QETH_DBF_HEX(control, 3, hdr, QETH_DBF_CONTROL_LEN);
2014 card->dev->last_rx = jiffies;
2015 card->stats.rx_packets++;
2016 card->stats.rx_bytes += len;
2020 static int qeth_l3_verify_vlan_dev(struct net_device *dev,
2021 struct qeth_card *card)
2024 struct vlan_group *vg;
2031 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
2032 if (vlan_group_get_device(vg, i) == dev) {
2033 rc = QETH_VLAN_CARD;
2038 if (rc && !(netdev_priv(vlan_dev_info(dev)->real_dev) == (void *)card))
2044 static int qeth_l3_verify_dev(struct net_device *dev)
2046 struct qeth_card *card;
2047 unsigned long flags;
2050 read_lock_irqsave(&qeth_core_card_list.rwlock, flags);
2051 list_for_each_entry(card, &qeth_core_card_list.list, list) {
2052 if (card->dev == dev) {
2053 rc = QETH_REAL_CARD;
2056 rc = qeth_l3_verify_vlan_dev(dev, card);
2060 read_unlock_irqrestore(&qeth_core_card_list.rwlock, flags);
2065 static struct qeth_card *qeth_l3_get_card_from_dev(struct net_device *dev)
2067 struct qeth_card *card = NULL;
2070 rc = qeth_l3_verify_dev(dev);
2071 if (rc == QETH_REAL_CARD)
2072 card = netdev_priv(dev);
2073 else if (rc == QETH_VLAN_CARD)
2074 card = netdev_priv(vlan_dev_info(dev)->real_dev);
2075 if (card->options.layer2)
2077 QETH_DBF_TEXT_(trace, 4, "%d", rc);
2081 static int qeth_l3_stop_card(struct qeth_card *card, int recovery_mode)
2085 QETH_DBF_TEXT(setup, 2, "stopcard");
2086 QETH_DBF_HEX(setup, 2, &card, sizeof(void *));
2088 qeth_set_allowed_threads(card, 0, 1);
2089 if (qeth_wait_for_threads(card, ~QETH_RECOVER_THREAD))
2090 return -ERESTARTSYS;
2091 if (card->read.state == CH_STATE_UP &&
2092 card->write.state == CH_STATE_UP &&
2093 (card->state == CARD_STATE_UP)) {
2095 qeth_l3_stop(card->dev);
2096 if (!card->use_hard_stop) {
2097 rc = qeth_send_stoplan(card);
2099 QETH_DBF_TEXT_(setup, 2, "1err%d", rc);
2101 card->state = CARD_STATE_SOFTSETUP;
2103 if (card->state == CARD_STATE_SOFTSETUP) {
2104 qeth_l3_clear_ip_list(card, !card->use_hard_stop, 1);
2105 qeth_clear_ipacmd_list(card);
2106 card->state = CARD_STATE_HARDSETUP;
2108 if (card->state == CARD_STATE_HARDSETUP) {
2109 if (!card->use_hard_stop &&
2110 (card->info.type != QETH_CARD_TYPE_IQD)) {
2111 rc = qeth_l3_put_unique_id(card);
2113 QETH_DBF_TEXT_(setup, 2, "2err%d", rc);
2115 qeth_qdio_clear_card(card, 0);
2116 qeth_clear_qdio_buffers(card);
2117 qeth_clear_working_pool_list(card);
2118 card->state = CARD_STATE_DOWN;
2120 if (card->state == CARD_STATE_DOWN) {
2121 qeth_clear_cmd_buffers(&card->read);
2122 qeth_clear_cmd_buffers(&card->write);
2124 card->use_hard_stop = 0;
2128 static void qeth_l3_set_multicast_list(struct net_device *dev)
2130 struct qeth_card *card = netdev_priv(dev);
2132 QETH_DBF_TEXT(trace, 3, "setmulti");
2133 qeth_l3_delete_mc_addresses(card);
2134 qeth_l3_add_multicast_ipv4(card);
2135 #ifdef CONFIG_QETH_IPV6
2136 qeth_l3_add_multicast_ipv6(card);
2138 qeth_l3_set_ip_addr_list(card);
2139 if (!qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
2141 qeth_setadp_promisc_mode(card);
2144 static const char *qeth_l3_arp_get_error_cause(int *rc)
2147 case QETH_IPA_ARP_RC_FAILED:
2149 return "operation failed";
2150 case QETH_IPA_ARP_RC_NOTSUPP:
2152 return "operation not supported";
2153 case QETH_IPA_ARP_RC_OUT_OF_RANGE:
2155 return "argument out of range";
2156 case QETH_IPA_ARP_RC_Q_NOTSUPP:
2158 return "query operation not supported";
2159 case QETH_IPA_ARP_RC_Q_NO_DATA:
2161 return "no query data available";
2163 return "unknown error";
2167 static int qeth_l3_arp_set_no_entries(struct qeth_card *card, int no_entries)
2172 QETH_DBF_TEXT(trace, 3, "arpstnoe");
2175 * currently GuestLAN only supports the ARP assist function
2176 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_SET_NO_ENTRIES;
2177 * thus we say EOPNOTSUPP for this ARP function
2179 if (card->info.guestlan)
2181 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
2182 PRINT_WARN("ARP processing not supported "
2183 "on %s!\n", QETH_CARD_IFNAME(card));
2186 rc = qeth_l3_send_simple_setassparms(card, IPA_ARP_PROCESSING,
2187 IPA_CMD_ASS_ARP_SET_NO_ENTRIES,
2191 PRINT_WARN("Could not set number of ARP entries on %s: "
2192 "%s (0x%x/%d)\n", QETH_CARD_IFNAME(card),
2193 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
2198 static void qeth_l3_copy_arp_entries_stripped(struct qeth_arp_query_info *qinfo,
2199 struct qeth_arp_query_data *qdata, int entry_size,
2206 entry_ptr = (char *)&qdata->data;
2207 uentry_ptr = (char *)(qinfo->udata + qinfo->udata_offset);
2208 for (i = 0; i < qdata->no_entries; ++i) {
2209 /* strip off 32 bytes "media specific information" */
2210 memcpy(uentry_ptr, (entry_ptr + 32), entry_size - 32);
2211 entry_ptr += entry_size;
2212 uentry_ptr += uentry_size;
2216 static int qeth_l3_arp_query_cb(struct qeth_card *card,
2217 struct qeth_reply *reply, unsigned long data)
2219 struct qeth_ipa_cmd *cmd;
2220 struct qeth_arp_query_data *qdata;
2221 struct qeth_arp_query_info *qinfo;
2226 QETH_DBF_TEXT(trace, 4, "arpquecb");
2228 qinfo = (struct qeth_arp_query_info *) reply->param;
2229 cmd = (struct qeth_ipa_cmd *) data;
2230 if (cmd->hdr.return_code) {
2231 QETH_DBF_TEXT_(trace, 4, "qaer1%i", cmd->hdr.return_code);
2234 if (cmd->data.setassparms.hdr.return_code) {
2235 cmd->hdr.return_code = cmd->data.setassparms.hdr.return_code;
2236 QETH_DBF_TEXT_(trace, 4, "qaer2%i", cmd->hdr.return_code);
2239 qdata = &cmd->data.setassparms.data.query_arp;
2240 switch (qdata->reply_bits) {
2242 uentry_size = entry_size = sizeof(struct qeth_arp_qi_entry5);
2243 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES)
2244 uentry_size = sizeof(struct qeth_arp_qi_entry5_short);
2247 /* fall through to default */
2249 /* tr is the same as eth -> entry7 */
2250 uentry_size = entry_size = sizeof(struct qeth_arp_qi_entry7);
2251 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES)
2252 uentry_size = sizeof(struct qeth_arp_qi_entry7_short);
2255 /* check if there is enough room in userspace */
2256 if ((qinfo->udata_len - qinfo->udata_offset) <
2257 qdata->no_entries * uentry_size){
2258 QETH_DBF_TEXT_(trace, 4, "qaer3%i", -ENOMEM);
2259 cmd->hdr.return_code = -ENOMEM;
2260 PRINT_WARN("query ARP user space buffer is too small for "
2261 "the returned number of ARP entries. "
2262 "Aborting query!\n");
2265 QETH_DBF_TEXT_(trace, 4, "anore%i",
2266 cmd->data.setassparms.hdr.number_of_replies);
2267 QETH_DBF_TEXT_(trace, 4, "aseqn%i", cmd->data.setassparms.hdr.seq_no);
2268 QETH_DBF_TEXT_(trace, 4, "anoen%i", qdata->no_entries);
2270 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES) {
2271 /* strip off "media specific information" */
2272 qeth_l3_copy_arp_entries_stripped(qinfo, qdata, entry_size,
2275 /*copy entries to user buffer*/
2276 memcpy(qinfo->udata + qinfo->udata_offset,
2277 (char *)&qdata->data, qdata->no_entries*uentry_size);
2279 qinfo->no_entries += qdata->no_entries;
2280 qinfo->udata_offset += (qdata->no_entries*uentry_size);
2281 /* check if all replies received ... */
2282 if (cmd->data.setassparms.hdr.seq_no <
2283 cmd->data.setassparms.hdr.number_of_replies)
2285 memcpy(qinfo->udata, &qinfo->no_entries, 4);
2286 /* keep STRIP_ENTRIES flag so the user program can distinguish
2287 * stripped entries from normal ones */
2288 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES)
2289 qdata->reply_bits |= QETH_QARP_STRIP_ENTRIES;
2290 memcpy(qinfo->udata + QETH_QARP_MASK_OFFSET, &qdata->reply_bits, 2);
2294 memcpy(qinfo->udata, &i, 4);
2298 static int qeth_l3_send_ipa_arp_cmd(struct qeth_card *card,
2299 struct qeth_cmd_buffer *iob, int len,
2300 int (*reply_cb)(struct qeth_card *, struct qeth_reply *,
2304 QETH_DBF_TEXT(trace, 4, "sendarp");
2306 memcpy(iob->data, IPA_PDU_HEADER, IPA_PDU_HEADER_SIZE);
2307 memcpy(QETH_IPA_CMD_DEST_ADDR(iob->data),
2308 &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
2309 return qeth_send_control_data(card, IPA_PDU_HEADER_SIZE + len, iob,
2310 reply_cb, reply_param);
2313 static int qeth_l3_arp_query(struct qeth_card *card, char __user *udata)
2315 struct qeth_cmd_buffer *iob;
2316 struct qeth_arp_query_info qinfo = {0, };
2320 QETH_DBF_TEXT(trace, 3, "arpquery");
2322 if (!qeth_is_supported(card,/*IPA_QUERY_ARP_ADDR_INFO*/
2323 IPA_ARP_PROCESSING)) {
2324 PRINT_WARN("ARP processing not supported "
2325 "on %s!\n", QETH_CARD_IFNAME(card));
2328 /* get size of userspace buffer and mask_bits -> 6 bytes */
2329 if (copy_from_user(&qinfo, udata, 6))
2331 qinfo.udata = kzalloc(qinfo.udata_len, GFP_KERNEL);
2334 qinfo.udata_offset = QETH_QARP_ENTRIES_OFFSET;
2335 iob = qeth_l3_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
2336 IPA_CMD_ASS_ARP_QUERY_INFO,
2337 sizeof(int), QETH_PROT_IPV4);
2339 rc = qeth_l3_send_ipa_arp_cmd(card, iob,
2340 QETH_SETASS_BASE_LEN+QETH_ARP_CMD_LEN,
2341 qeth_l3_arp_query_cb, (void *)&qinfo);
2344 PRINT_WARN("Error while querying ARP cache on %s: %s "
2345 "(0x%x/%d)\n", QETH_CARD_IFNAME(card),
2346 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
2347 if (copy_to_user(udata, qinfo.udata, 4))
2350 if (copy_to_user(udata, qinfo.udata, qinfo.udata_len))
2357 static int qeth_l3_arp_add_entry(struct qeth_card *card,
2358 struct qeth_arp_cache_entry *entry)
2360 struct qeth_cmd_buffer *iob;
2365 QETH_DBF_TEXT(trace, 3, "arpadent");
2368 * currently GuestLAN only supports the ARP assist function
2369 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_ADD_ENTRY;
2370 * thus we say EOPNOTSUPP for this ARP function
2372 if (card->info.guestlan)
2374 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
2375 PRINT_WARN("ARP processing not supported "
2376 "on %s!\n", QETH_CARD_IFNAME(card));
2380 iob = qeth_l3_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
2381 IPA_CMD_ASS_ARP_ADD_ENTRY,
2382 sizeof(struct qeth_arp_cache_entry),
2384 rc = qeth_l3_send_setassparms(card, iob,
2385 sizeof(struct qeth_arp_cache_entry),
2386 (unsigned long) entry,
2387 qeth_l3_default_setassparms_cb, NULL);
2390 qeth_l3_ipaddr4_to_string((u8 *)entry->ipaddr, buf);
2391 PRINT_WARN("Could not add ARP entry for address %s on %s: "
2393 buf, QETH_CARD_IFNAME(card),
2394 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
2399 static int qeth_l3_arp_remove_entry(struct qeth_card *card,
2400 struct qeth_arp_cache_entry *entry)
2402 struct qeth_cmd_buffer *iob;
2403 char buf[16] = {0, };
2407 QETH_DBF_TEXT(trace, 3, "arprment");
2410 * currently GuestLAN only supports the ARP assist function
2411 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_REMOVE_ENTRY;
2412 * thus we say EOPNOTSUPP for this ARP function
2414 if (card->info.guestlan)
2416 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
2417 PRINT_WARN("ARP processing not supported "
2418 "on %s!\n", QETH_CARD_IFNAME(card));
2421 memcpy(buf, entry, 12);
2422 iob = qeth_l3_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
2423 IPA_CMD_ASS_ARP_REMOVE_ENTRY,
2426 rc = qeth_l3_send_setassparms(card, iob,
2427 12, (unsigned long)buf,
2428 qeth_l3_default_setassparms_cb, NULL);
2432 qeth_l3_ipaddr4_to_string((u8 *)entry->ipaddr, buf);
2433 PRINT_WARN("Could not delete ARP entry for address %s on %s: "
2435 buf, QETH_CARD_IFNAME(card),
2436 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
2441 static int qeth_l3_arp_flush_cache(struct qeth_card *card)
2446 QETH_DBF_TEXT(trace, 3, "arpflush");
2449 * currently GuestLAN only supports the ARP assist function
2450 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_FLUSH_CACHE;
2451 * thus we say EOPNOTSUPP for this ARP function
2453 if (card->info.guestlan || (card->info.type == QETH_CARD_TYPE_IQD))
2455 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
2456 PRINT_WARN("ARP processing not supported "
2457 "on %s!\n", QETH_CARD_IFNAME(card));
2460 rc = qeth_l3_send_simple_setassparms(card, IPA_ARP_PROCESSING,
2461 IPA_CMD_ASS_ARP_FLUSH_CACHE, 0);
2464 PRINT_WARN("Could not flush ARP cache on %s: %s (0x%x/%d)\n",
2465 QETH_CARD_IFNAME(card),
2466 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
2471 static int qeth_l3_do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
2473 struct qeth_card *card = netdev_priv(dev);
2474 struct qeth_arp_cache_entry arp_entry;
2475 struct mii_ioctl_data *mii_data;
2481 if ((card->state != CARD_STATE_UP) &&
2482 (card->state != CARD_STATE_SOFTSETUP))
2486 case SIOC_QETH_ARP_SET_NO_ENTRIES:
2487 if (!capable(CAP_NET_ADMIN)) {
2491 rc = qeth_l3_arp_set_no_entries(card, rq->ifr_ifru.ifru_ivalue);
2493 case SIOC_QETH_ARP_QUERY_INFO:
2494 if (!capable(CAP_NET_ADMIN)) {
2498 rc = qeth_l3_arp_query(card, rq->ifr_ifru.ifru_data);
2500 case SIOC_QETH_ARP_ADD_ENTRY:
2501 if (!capable(CAP_NET_ADMIN)) {
2505 if (copy_from_user(&arp_entry, rq->ifr_ifru.ifru_data,
2506 sizeof(struct qeth_arp_cache_entry)))
2509 rc = qeth_l3_arp_add_entry(card, &arp_entry);
2511 case SIOC_QETH_ARP_REMOVE_ENTRY:
2512 if (!capable(CAP_NET_ADMIN)) {
2516 if (copy_from_user(&arp_entry, rq->ifr_ifru.ifru_data,
2517 sizeof(struct qeth_arp_cache_entry)))
2520 rc = qeth_l3_arp_remove_entry(card, &arp_entry);
2522 case SIOC_QETH_ARP_FLUSH_CACHE:
2523 if (!capable(CAP_NET_ADMIN)) {
2527 rc = qeth_l3_arp_flush_cache(card);
2529 case SIOC_QETH_ADP_SET_SNMP_CONTROL:
2530 rc = qeth_snmp_command(card, rq->ifr_ifru.ifru_data);
2532 case SIOC_QETH_GET_CARD_TYPE:
2533 if ((card->info.type == QETH_CARD_TYPE_OSAE) &&
2534 !card->info.guestlan)
2539 mii_data = if_mii(rq);
2540 mii_data->phy_id = 0;
2543 mii_data = if_mii(rq);
2544 if (mii_data->phy_id != 0)
2547 mii_data->val_out = qeth_mdio_read(dev,
2555 QETH_DBF_TEXT_(trace, 2, "ioce%d", rc);
2559 static void qeth_l3_fill_header(struct qeth_card *card, struct qeth_hdr *hdr,
2560 struct sk_buff *skb, int ipv, int cast_type)
2562 QETH_DBF_TEXT(trace, 6, "fillhdr");
2564 memset(hdr, 0, sizeof(struct qeth_hdr));
2565 hdr->hdr.l3.id = QETH_HEADER_TYPE_LAYER3;
2566 hdr->hdr.l3.ext_flags = 0;
2569 * before we're going to overwrite this location with next hop ip.
2570 * v6 uses passthrough, v4 sets the tag in the QDIO header.
2572 if (card->vlangrp && vlan_tx_tag_present(skb)) {
2573 hdr->hdr.l3.ext_flags = (ipv == 4) ?
2574 QETH_HDR_EXT_VLAN_FRAME :
2575 QETH_HDR_EXT_INCLUDE_VLAN_TAG;
2576 hdr->hdr.l3.vlan_id = vlan_tx_tag_get(skb);
2579 hdr->hdr.l3.length = skb->len - sizeof(struct qeth_hdr);
2582 hdr->hdr.l3.flags = qeth_l3_get_qeth_hdr_flags4(cast_type);
2583 memset(hdr->hdr.l3.dest_addr, 0, 12);
2584 if ((skb->dst) && (skb->dst->neighbour)) {
2585 *((u32 *) (&hdr->hdr.l3.dest_addr[12])) =
2586 *((u32 *) skb->dst->neighbour->primary_key);
2588 /* fill in destination address used in ip header */
2589 *((u32 *) (&hdr->hdr.l3.dest_addr[12])) =
2592 } else if (ipv == 6) {
2594 hdr->hdr.l3.flags = qeth_l3_get_qeth_hdr_flags6(cast_type);
2595 if (card->info.type == QETH_CARD_TYPE_IQD)
2596 hdr->hdr.l3.flags &= ~QETH_HDR_PASSTHRU;
2597 if ((skb->dst) && (skb->dst->neighbour)) {
2598 memcpy(hdr->hdr.l3.dest_addr,
2599 skb->dst->neighbour->primary_key, 16);
2601 /* fill in destination address used in ip header */
2602 memcpy(hdr->hdr.l3.dest_addr,
2603 &ipv6_hdr(skb)->daddr, 16);
2607 if ((skb->dev->type == ARPHRD_IEEE802_TR) &&
2608 !memcmp(skb->data + sizeof(struct qeth_hdr) +
2609 sizeof(__u16), skb->dev->broadcast, 6)) {
2610 hdr->hdr.l3.flags = QETH_CAST_BROADCAST |
2612 } else if (!memcmp(skb->data + sizeof(struct qeth_hdr),
2613 skb->dev->broadcast, 6)) {
2615 hdr->hdr.l3.flags = QETH_CAST_BROADCAST |
2618 hdr->hdr.l3.flags = (cast_type == RTN_MULTICAST) ?
2619 QETH_CAST_MULTICAST | QETH_HDR_PASSTHRU :
2620 QETH_CAST_UNICAST | QETH_HDR_PASSTHRU;
2625 static int qeth_l3_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
2629 struct qeth_hdr *hdr = NULL;
2630 int elements_needed = 0;
2631 struct qeth_card *card = netdev_priv(dev);
2632 struct sk_buff *new_skb = NULL;
2633 int ipv = qeth_get_ip_version(skb);
2634 int cast_type = qeth_get_cast_type(card, skb);
2635 struct qeth_qdio_out_q *queue = card->qdio.out_qs
2636 [qeth_get_priority_queue(card, skb, ipv, cast_type)];
2637 int tx_bytes = skb->len;
2638 enum qeth_large_send_types large_send = QETH_LARGE_SEND_NO;
2639 struct qeth_eddp_context *ctx = NULL;
2641 QETH_DBF_TEXT(trace, 6, "l3xmit");
2643 if ((card->info.type == QETH_CARD_TYPE_IQD) &&
2644 (skb->protocol != htons(ETH_P_IPV6)) &&
2645 (skb->protocol != htons(ETH_P_IP)))
2648 if ((card->state != CARD_STATE_UP) || !card->lan_online) {
2649 card->stats.tx_carrier_errors++;
2653 if ((cast_type == RTN_BROADCAST) &&
2654 (card->info.broadcast_capable == 0))
2657 if (card->options.performance_stats) {
2658 card->perf_stats.outbound_cnt++;
2659 card->perf_stats.outbound_start_time = qeth_get_micros();
2662 /* create a clone with writeable headroom */
2663 new_skb = skb_realloc_headroom(skb, sizeof(struct qeth_hdr_tso) +
2668 if (card->info.type == QETH_CARD_TYPE_IQD) {
2669 skb_pull(new_skb, ETH_HLEN);
2671 if (new_skb->protocol == htons(ETH_P_IP)) {
2672 if (card->dev->type == ARPHRD_IEEE802_TR)
2673 skb_pull(new_skb, TR_HLEN);
2675 skb_pull(new_skb, ETH_HLEN);
2678 if (new_skb->protocol == ETH_P_IPV6 && card->vlangrp &&
2679 vlan_tx_tag_present(new_skb)) {
2680 skb_push(new_skb, VLAN_HLEN);
2681 skb_copy_to_linear_data(new_skb, new_skb->data + 4, 4);
2682 skb_copy_to_linear_data_offset(new_skb, 4,
2683 new_skb->data + 8, 4);
2684 skb_copy_to_linear_data_offset(new_skb, 8,
2685 new_skb->data + 12, 4);
2686 tag = (u16 *)(new_skb->data + 12);
2687 *tag = __constant_htons(ETH_P_8021Q);
2688 *(tag + 1) = htons(vlan_tx_tag_get(new_skb));
2689 VLAN_TX_SKB_CB(new_skb)->magic = 0;
2693 netif_stop_queue(dev);
2695 if (skb_is_gso(new_skb))
2696 large_send = card->options.large_send;
2698 /* fix hardware limitation: as long as we do not have sbal
2699 * chaining we can not send long frag lists so we temporary
2702 if ((large_send == QETH_LARGE_SEND_TSO) &&
2703 ((skb_shinfo(new_skb)->nr_frags + 2) > 16))
2704 large_send = QETH_LARGE_SEND_EDDP;
2706 if ((large_send == QETH_LARGE_SEND_TSO) &&
2707 (cast_type == RTN_UNSPEC)) {
2708 hdr = (struct qeth_hdr *)skb_push(new_skb,
2709 sizeof(struct qeth_hdr_tso));
2710 memset(hdr, 0, sizeof(struct qeth_hdr_tso));
2711 qeth_l3_fill_header(card, hdr, new_skb, ipv, cast_type);
2712 qeth_tso_fill_header(card, hdr, new_skb);
2715 hdr = (struct qeth_hdr *)skb_push(new_skb,
2716 sizeof(struct qeth_hdr));
2717 qeth_l3_fill_header(card, hdr, new_skb, ipv, cast_type);
2720 if (large_send == QETH_LARGE_SEND_EDDP) {
2721 /* new_skb is not owned by a socket so we use skb to get
2724 ctx = qeth_eddp_create_context(card, new_skb, hdr,
2725 skb->sk->sk_protocol);
2727 PRINT_WARN("could not create eddp context\n");
2731 int elems = qeth_get_elements_no(card, (void *)hdr, new_skb,
2735 elements_needed += elems;
2738 if ((large_send == QETH_LARGE_SEND_NO) &&
2739 (new_skb->ip_summed == CHECKSUM_PARTIAL))
2740 qeth_tx_csum(new_skb);
2742 if (card->info.type != QETH_CARD_TYPE_IQD)
2743 rc = qeth_do_send_packet(card, queue, new_skb, hdr,
2744 elements_needed, ctx);
2746 rc = qeth_do_send_packet_fast(card, queue, new_skb, hdr,
2747 elements_needed, ctx);
2750 card->stats.tx_packets++;
2751 card->stats.tx_bytes += tx_bytes;
2753 dev_kfree_skb_any(skb);
2754 if (card->options.performance_stats) {
2755 if (large_send != QETH_LARGE_SEND_NO) {
2756 card->perf_stats.large_send_bytes += tx_bytes;
2757 card->perf_stats.large_send_cnt++;
2759 if (skb_shinfo(new_skb)->nr_frags > 0) {
2760 card->perf_stats.sg_skbs_sent++;
2761 /* nr_frags + skb->data */
2762 card->perf_stats.sg_frags_sent +=
2763 skb_shinfo(new_skb)->nr_frags + 1;
2768 qeth_eddp_put_context(ctx);
2769 dev_kfree_skb_any(new_skb);
2773 qeth_eddp_put_context(ctx);
2777 dev_kfree_skb_any(new_skb);
2778 return NETDEV_TX_BUSY;
2783 netif_wake_queue(dev);
2784 if (card->options.performance_stats)
2785 card->perf_stats.outbound_time += qeth_get_micros() -
2786 card->perf_stats.outbound_start_time;
2790 card->stats.tx_dropped++;
2791 card->stats.tx_errors++;
2792 if ((new_skb != skb) && new_skb)
2793 dev_kfree_skb_any(new_skb);
2794 dev_kfree_skb_any(skb);
2795 return NETDEV_TX_OK;
2798 static int qeth_l3_open(struct net_device *dev)
2800 struct qeth_card *card = netdev_priv(dev);
2802 QETH_DBF_TEXT(trace, 4, "qethopen");
2803 if (card->state != CARD_STATE_SOFTSETUP)
2805 card->data.state = CH_STATE_UP;
2806 card->state = CARD_STATE_UP;
2807 card->dev->flags |= IFF_UP;
2808 netif_start_queue(dev);
2810 if (!card->lan_online && netif_carrier_ok(dev))
2811 netif_carrier_off(dev);
2815 static int qeth_l3_stop(struct net_device *dev)
2817 struct qeth_card *card = netdev_priv(dev);
2819 QETH_DBF_TEXT(trace, 4, "qethstop");
2820 netif_tx_disable(dev);
2821 card->dev->flags &= ~IFF_UP;
2822 if (card->state == CARD_STATE_UP)
2823 card->state = CARD_STATE_SOFTSETUP;
2827 static u32 qeth_l3_ethtool_get_rx_csum(struct net_device *dev)
2829 struct qeth_card *card = netdev_priv(dev);
2831 return (card->options.checksum_type == HW_CHECKSUMMING);
2834 static int qeth_l3_ethtool_set_rx_csum(struct net_device *dev, u32 data)
2836 struct qeth_card *card = netdev_priv(dev);
2837 enum qeth_card_states old_state;
2838 enum qeth_checksum_types csum_type;
2840 if ((card->state != CARD_STATE_UP) &&
2841 (card->state != CARD_STATE_DOWN))
2845 csum_type = HW_CHECKSUMMING;
2847 csum_type = SW_CHECKSUMMING;
2849 if (card->options.checksum_type != csum_type) {
2850 old_state = card->state;
2851 if (card->state == CARD_STATE_UP)
2852 __qeth_l3_set_offline(card->gdev, 1);
2853 card->options.checksum_type = csum_type;
2854 if (old_state == CARD_STATE_UP)
2855 __qeth_l3_set_online(card->gdev, 1);
2860 static int qeth_l3_ethtool_set_tso(struct net_device *dev, u32 data)
2862 struct qeth_card *card = netdev_priv(dev);
2865 if (card->options.large_send == QETH_LARGE_SEND_NO) {
2866 if (card->info.type == QETH_CARD_TYPE_IQD)
2867 card->options.large_send = QETH_LARGE_SEND_EDDP;
2869 card->options.large_send = QETH_LARGE_SEND_TSO;
2870 dev->features |= NETIF_F_TSO;
2873 dev->features &= ~NETIF_F_TSO;
2874 card->options.large_send = QETH_LARGE_SEND_NO;
2879 static struct ethtool_ops qeth_l3_ethtool_ops = {
2880 .get_link = ethtool_op_get_link,
2881 .get_tx_csum = ethtool_op_get_tx_csum,
2882 .set_tx_csum = ethtool_op_set_tx_hw_csum,
2883 .get_rx_csum = qeth_l3_ethtool_get_rx_csum,
2884 .set_rx_csum = qeth_l3_ethtool_set_rx_csum,
2885 .get_sg = ethtool_op_get_sg,
2886 .set_sg = ethtool_op_set_sg,
2887 .get_tso = ethtool_op_get_tso,
2888 .set_tso = qeth_l3_ethtool_set_tso,
2889 .get_strings = qeth_core_get_strings,
2890 .get_ethtool_stats = qeth_core_get_ethtool_stats,
2891 .get_stats_count = qeth_core_get_stats_count,
2892 .get_drvinfo = qeth_core_get_drvinfo,
2896 * we need NOARP for IPv4 but we want neighbor solicitation for IPv6. Setting
2897 * NOARP on the netdevice is no option because it also turns off neighbor
2898 * solicitation. For IPv4 we install a neighbor_setup function. We don't want
2899 * arp resolution but we want the hard header (packet socket will work
2902 static int qeth_l3_neigh_setup_noarp(struct neighbour *n)
2904 n->nud_state = NUD_NOARP;
2905 memcpy(n->ha, "FAKELL", 6);
2906 n->output = n->ops->connected_output;
2911 qeth_l3_neigh_setup(struct net_device *dev, struct neigh_parms *np)
2913 if (np->tbl->family == AF_INET)
2914 np->neigh_setup = qeth_l3_neigh_setup_noarp;
2919 static int qeth_l3_setup_netdev(struct qeth_card *card)
2921 if (card->info.type == QETH_CARD_TYPE_OSAE) {
2922 if ((card->info.link_type == QETH_LINK_TYPE_LANE_TR) ||
2923 (card->info.link_type == QETH_LINK_TYPE_HSTR)) {
2925 card->dev = alloc_trdev(0);
2930 card->dev = alloc_etherdev(0);
2933 card->dev->neigh_setup = qeth_l3_neigh_setup;
2935 /*IPv6 address autoconfiguration stuff*/
2936 qeth_l3_get_unique_id(card);
2937 if (!(card->info.unique_id & UNIQUE_ID_NOT_BY_CARD))
2938 card->dev->dev_id = card->info.unique_id &
2941 } else if (card->info.type == QETH_CARD_TYPE_IQD) {
2942 card->dev = alloc_netdev(0, "hsi%d", ether_setup);
2945 card->dev->flags |= IFF_NOARP;
2946 qeth_l3_iqd_read_initial_mac(card);
2950 card->dev->hard_start_xmit = qeth_l3_hard_start_xmit;
2951 card->dev->priv = card;
2952 card->dev->tx_timeout = &qeth_tx_timeout;
2953 card->dev->watchdog_timeo = QETH_TX_TIMEOUT;
2954 card->dev->open = qeth_l3_open;
2955 card->dev->stop = qeth_l3_stop;
2956 card->dev->do_ioctl = qeth_l3_do_ioctl;
2957 card->dev->get_stats = qeth_get_stats;
2958 card->dev->change_mtu = qeth_change_mtu;
2959 card->dev->set_multicast_list = qeth_l3_set_multicast_list;
2960 card->dev->vlan_rx_register = qeth_l3_vlan_rx_register;
2961 card->dev->vlan_rx_add_vid = qeth_l3_vlan_rx_add_vid;
2962 card->dev->vlan_rx_kill_vid = qeth_l3_vlan_rx_kill_vid;
2963 card->dev->mtu = card->info.initial_mtu;
2964 card->dev->set_mac_address = NULL;
2965 SET_ETHTOOL_OPS(card->dev, &qeth_l3_ethtool_ops);
2966 card->dev->features |= NETIF_F_HW_VLAN_TX |
2967 NETIF_F_HW_VLAN_RX |
2968 NETIF_F_HW_VLAN_FILTER;
2970 SET_NETDEV_DEV(card->dev, &card->gdev->dev);
2971 return register_netdev(card->dev);
2974 static void qeth_l3_qdio_input_handler(struct ccw_device *ccwdev,
2975 unsigned int status, unsigned int qdio_err,
2976 unsigned int siga_err, unsigned int queue, int first_element,
2977 int count, unsigned long card_ptr)
2979 struct net_device *net_dev;
2980 struct qeth_card *card;
2981 struct qeth_qdio_buffer *buffer;
2985 QETH_DBF_TEXT(trace, 6, "qdinput");
2986 card = (struct qeth_card *) card_ptr;
2987 net_dev = card->dev;
2988 if (card->options.performance_stats) {
2989 card->perf_stats.inbound_cnt++;
2990 card->perf_stats.inbound_start_time = qeth_get_micros();
2992 if (status & QDIO_STATUS_LOOK_FOR_ERROR) {
2993 if (status & QDIO_STATUS_ACTIVATE_CHECK_CONDITION) {
2994 QETH_DBF_TEXT(trace, 1, "qdinchk");
2995 QETH_DBF_TEXT_(trace, 1, "%s", CARD_BUS_ID(card));
2996 QETH_DBF_TEXT_(trace, 1, "%04X%04X",
2997 first_element, count);
2998 QETH_DBF_TEXT_(trace, 1, "%04X%04X", queue, status);
2999 qeth_schedule_recovery(card);
3003 for (i = first_element; i < (first_element + count); ++i) {
3004 index = i % QDIO_MAX_BUFFERS_PER_Q;
3005 buffer = &card->qdio.in_q->bufs[index];
3006 if (!((status & QDIO_STATUS_LOOK_FOR_ERROR) &&
3007 qeth_check_qdio_errors(buffer->buffer,
3008 qdio_err, siga_err, "qinerr")))
3009 qeth_l3_process_inbound_buffer(card, buffer, index);
3010 /* clear buffer and give back to hardware */
3011 qeth_put_buffer_pool_entry(card, buffer->pool_entry);
3012 qeth_queue_input_buffer(card, index);
3014 if (card->options.performance_stats)
3015 card->perf_stats.inbound_time += qeth_get_micros() -
3016 card->perf_stats.inbound_start_time;
3019 static int qeth_l3_probe_device(struct ccwgroup_device *gdev)
3021 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3023 qeth_l3_create_device_attributes(&gdev->dev);
3024 card->options.layer2 = 0;
3025 card->discipline.input_handler = (qdio_handler_t *)
3026 qeth_l3_qdio_input_handler;
3027 card->discipline.output_handler = (qdio_handler_t *)
3028 qeth_qdio_output_handler;
3029 card->discipline.recover = qeth_l3_recover;
3033 static void qeth_l3_remove_device(struct ccwgroup_device *cgdev)
3035 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
3037 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
3039 if (cgdev->state == CCWGROUP_ONLINE) {
3040 card->use_hard_stop = 1;
3041 qeth_l3_set_offline(cgdev);
3045 unregister_netdev(card->dev);
3049 qeth_l3_remove_device_attributes(&cgdev->dev);
3050 qeth_l3_clear_ip_list(card, 0, 0);
3051 qeth_l3_clear_ipato_list(card);
3055 static int __qeth_l3_set_online(struct ccwgroup_device *gdev, int recovery_mode)
3057 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3059 enum qeth_card_states recover_flag;
3062 QETH_DBF_TEXT(setup, 2, "setonlin");
3063 QETH_DBF_HEX(setup, 2, &card, sizeof(void *));
3065 qeth_set_allowed_threads(card, QETH_RECOVER_THREAD, 1);
3066 if (qeth_wait_for_threads(card, ~QETH_RECOVER_THREAD)) {
3067 PRINT_WARN("set_online of card %s interrupted by user!\n",
3069 return -ERESTARTSYS;
3072 recover_flag = card->state;
3073 rc = ccw_device_set_online(CARD_RDEV(card));
3075 QETH_DBF_TEXT_(setup, 2, "1err%d", rc);
3078 rc = ccw_device_set_online(CARD_WDEV(card));
3080 QETH_DBF_TEXT_(setup, 2, "1err%d", rc);
3083 rc = ccw_device_set_online(CARD_DDEV(card));
3085 QETH_DBF_TEXT_(setup, 2, "1err%d", rc);
3089 rc = qeth_core_hardsetup_card(card);
3091 QETH_DBF_TEXT_(setup, 2, "2err%d", rc);
3095 qeth_l3_query_ipassists(card, QETH_PROT_IPV4);
3097 if (!card->dev && qeth_l3_setup_netdev(card))
3100 card->state = CARD_STATE_HARDSETUP;
3101 qeth_print_status_message(card);
3104 QETH_DBF_TEXT(setup, 2, "softsetp");
3106 rc = qeth_send_startlan(card);
3108 QETH_DBF_TEXT_(setup, 2, "1err%d", rc);
3110 PRINT_WARN("LAN on card %s if offline! "
3111 "Waiting for STARTLAN from card.\n",
3113 card->lan_online = 0;
3117 card->lan_online = 1;
3118 qeth_set_large_send(card, card->options.large_send);
3120 rc = qeth_l3_setadapter_parms(card);
3122 QETH_DBF_TEXT_(setup, 2, "2err%d", rc);
3123 rc = qeth_l3_start_ipassists(card);
3125 QETH_DBF_TEXT_(setup, 2, "3err%d", rc);
3126 rc = qeth_l3_setrouting_v4(card);
3128 QETH_DBF_TEXT_(setup, 2, "4err%d", rc);
3129 rc = qeth_l3_setrouting_v6(card);
3131 QETH_DBF_TEXT_(setup, 2, "5err%d", rc);
3132 netif_tx_disable(card->dev);
3134 rc = qeth_init_qdio_queues(card);
3136 QETH_DBF_TEXT_(setup, 2, "6err%d", rc);
3139 card->state = CARD_STATE_SOFTSETUP;
3140 netif_carrier_on(card->dev);
3142 qeth_set_allowed_threads(card, 0xffffffff, 0);
3143 if ((recover_flag == CARD_STATE_RECOVER) && recovery_mode) {
3144 qeth_l3_open(card->dev);
3145 qeth_l3_set_multicast_list(card->dev);
3147 /* let user_space know that device is online */
3148 kobject_uevent(&gdev->dev.kobj, KOBJ_CHANGE);
3151 card->use_hard_stop = 1;
3152 qeth_l3_stop_card(card, 0);
3153 ccw_device_set_offline(CARD_DDEV(card));
3154 ccw_device_set_offline(CARD_WDEV(card));
3155 ccw_device_set_offline(CARD_RDEV(card));
3156 if (recover_flag == CARD_STATE_RECOVER)
3157 card->state = CARD_STATE_RECOVER;
3159 card->state = CARD_STATE_DOWN;
3163 static int qeth_l3_set_online(struct ccwgroup_device *gdev)
3165 return __qeth_l3_set_online(gdev, 0);
3168 static int __qeth_l3_set_offline(struct ccwgroup_device *cgdev,
3171 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
3172 int rc = 0, rc2 = 0, rc3 = 0;
3173 enum qeth_card_states recover_flag;
3175 QETH_DBF_TEXT(setup, 3, "setoffl");
3176 QETH_DBF_HEX(setup, 3, &card, sizeof(void *));
3178 if (card->dev && netif_carrier_ok(card->dev))
3179 netif_carrier_off(card->dev);
3180 recover_flag = card->state;
3181 if (qeth_l3_stop_card(card, recovery_mode) == -ERESTARTSYS) {
3182 PRINT_WARN("Stopping card %s interrupted by user!\n",
3184 return -ERESTARTSYS;
3186 rc = ccw_device_set_offline(CARD_DDEV(card));
3187 rc2 = ccw_device_set_offline(CARD_WDEV(card));
3188 rc3 = ccw_device_set_offline(CARD_RDEV(card));
3190 rc = (rc2) ? rc2 : rc3;
3192 QETH_DBF_TEXT_(setup, 2, "1err%d", rc);
3193 if (recover_flag == CARD_STATE_UP)
3194 card->state = CARD_STATE_RECOVER;
3195 /* let user_space know that device is offline */
3196 kobject_uevent(&cgdev->dev.kobj, KOBJ_CHANGE);
3200 static int qeth_l3_set_offline(struct ccwgroup_device *cgdev)
3202 return __qeth_l3_set_offline(cgdev, 0);
3205 static int qeth_l3_recover(void *ptr)
3207 struct qeth_card *card;
3210 card = (struct qeth_card *) ptr;
3211 QETH_DBF_TEXT(trace, 2, "recover1");
3212 QETH_DBF_HEX(trace, 2, &card, sizeof(void *));
3213 if (!qeth_do_run_thread(card, QETH_RECOVER_THREAD))
3215 QETH_DBF_TEXT(trace, 2, "recover2");
3216 PRINT_WARN("Recovery of device %s started ...\n",
3218 card->use_hard_stop = 1;
3219 __qeth_l3_set_offline(card->gdev, 1);
3220 rc = __qeth_l3_set_online(card->gdev, 1);
3221 /* don't run another scheduled recovery */
3222 qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD);
3223 qeth_clear_thread_running_bit(card, QETH_RECOVER_THREAD);
3225 PRINT_INFO("Device %s successfully recovered!\n",
3228 PRINT_INFO("Device %s could not be recovered!\n",
3233 static void qeth_l3_shutdown(struct ccwgroup_device *gdev)
3235 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3236 qeth_l3_clear_ip_list(card, 0, 0);
3237 qeth_qdio_clear_card(card, 0);
3238 qeth_clear_qdio_buffers(card);
3241 struct ccwgroup_driver qeth_l3_ccwgroup_driver = {
3242 .probe = qeth_l3_probe_device,
3243 .remove = qeth_l3_remove_device,
3244 .set_online = qeth_l3_set_online,
3245 .set_offline = qeth_l3_set_offline,
3246 .shutdown = qeth_l3_shutdown,
3248 EXPORT_SYMBOL_GPL(qeth_l3_ccwgroup_driver);
3250 static int qeth_l3_ip_event(struct notifier_block *this,
3251 unsigned long event, void *ptr)
3253 struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;
3254 struct net_device *dev = (struct net_device *)ifa->ifa_dev->dev;
3255 struct qeth_ipaddr *addr;
3256 struct qeth_card *card;
3258 if (dev_net(dev) != &init_net)
3261 QETH_DBF_TEXT(trace, 3, "ipevent");
3262 card = qeth_l3_get_card_from_dev(dev);
3266 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
3268 addr->u.a4.addr = ifa->ifa_address;
3269 addr->u.a4.mask = ifa->ifa_mask;
3270 addr->type = QETH_IP_TYPE_NORMAL;
3276 if (!qeth_l3_add_ip(card, addr))
3280 if (!qeth_l3_delete_ip(card, addr))
3286 qeth_l3_set_ip_addr_list(card);
3291 static struct notifier_block qeth_l3_ip_notifier = {
3296 #ifdef CONFIG_QETH_IPV6
3298 * IPv6 event handler
3300 static int qeth_l3_ip6_event(struct notifier_block *this,
3301 unsigned long event, void *ptr)
3303 struct inet6_ifaddr *ifa = (struct inet6_ifaddr *)ptr;
3304 struct net_device *dev = (struct net_device *)ifa->idev->dev;
3305 struct qeth_ipaddr *addr;
3306 struct qeth_card *card;
3308 QETH_DBF_TEXT(trace, 3, "ip6event");
3310 card = qeth_l3_get_card_from_dev(dev);
3313 if (!qeth_is_supported(card, IPA_IPV6))
3316 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
3318 memcpy(&addr->u.a6.addr, &ifa->addr, sizeof(struct in6_addr));
3319 addr->u.a6.pfxlen = ifa->prefix_len;
3320 addr->type = QETH_IP_TYPE_NORMAL;
3326 if (!qeth_l3_add_ip(card, addr))
3330 if (!qeth_l3_delete_ip(card, addr))
3336 qeth_l3_set_ip_addr_list(card);
3341 static struct notifier_block qeth_l3_ip6_notifier = {
3347 static int qeth_l3_register_notifiers(void)
3351 QETH_DBF_TEXT(trace, 5, "regnotif");
3352 rc = register_inetaddr_notifier(&qeth_l3_ip_notifier);
3355 #ifdef CONFIG_QETH_IPV6
3356 rc = register_inet6addr_notifier(&qeth_l3_ip6_notifier);
3358 unregister_inetaddr_notifier(&qeth_l3_ip_notifier);
3362 PRINT_WARN("layer 3 discipline no IPv6 support\n");
3367 static void qeth_l3_unregister_notifiers(void)
3370 QETH_DBF_TEXT(trace, 5, "unregnot");
3371 BUG_ON(unregister_inetaddr_notifier(&qeth_l3_ip_notifier));
3372 #ifdef CONFIG_QETH_IPV6
3373 BUG_ON(unregister_inet6addr_notifier(&qeth_l3_ip6_notifier));
3374 #endif /* QETH_IPV6 */
3377 static int __init qeth_l3_init(void)
3381 PRINT_INFO("register layer 3 discipline\n");
3382 rc = qeth_l3_register_notifiers();
3386 static void __exit qeth_l3_exit(void)
3388 qeth_l3_unregister_notifiers();
3389 PRINT_INFO("unregister layer 3 discipline\n");
3392 module_init(qeth_l3_init);
3393 module_exit(qeth_l3_exit);
3394 MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
3395 MODULE_DESCRIPTION("qeth layer 3 discipline");
3396 MODULE_LICENSE("GPL");