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 #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/reboot.h>
23 #include <linux/inetdevice.h>
24 #include <linux/igmp.h>
29 #include <asm/s390_rdev.h>
32 #include "qeth_core_offl.h"
34 static int qeth_l3_set_offline(struct ccwgroup_device *);
35 static int qeth_l3_recover(void *);
36 static int qeth_l3_stop(struct net_device *);
37 static void qeth_l3_set_multicast_list(struct net_device *);
38 static int qeth_l3_neigh_setup(struct net_device *, struct neigh_parms *);
39 static int qeth_l3_register_addr_entry(struct qeth_card *,
40 struct qeth_ipaddr *);
41 static int qeth_l3_deregister_addr_entry(struct qeth_card *,
42 struct qeth_ipaddr *);
43 static int __qeth_l3_set_online(struct ccwgroup_device *, int);
44 static int __qeth_l3_set_offline(struct ccwgroup_device *, int);
47 static int qeth_l3_isxdigit(char *buf)
50 if (!isxdigit(*buf++))
56 void qeth_l3_ipaddr4_to_string(const __u8 *addr, char *buf)
58 sprintf(buf, "%i.%i.%i.%i", addr[0], addr[1], addr[2], addr[3]);
61 int qeth_l3_string_to_ipaddr4(const char *buf, __u8 *addr)
63 int count = 0, rc = 0;
67 rc = sscanf(buf, "%u.%u.%u.%u%c",
68 &in[0], &in[1], &in[2], &in[3], &c);
69 if (rc != 4 && (rc != 5 || c != '\n'))
71 for (count = 0; count < 4; count++) {
74 addr[count] = in[count];
79 void qeth_l3_ipaddr6_to_string(const __u8 *addr, char *buf)
81 sprintf(buf, "%02x%02x:%02x%02x:%02x%02x:%02x%02x"
82 ":%02x%02x:%02x%02x:%02x%02x:%02x%02x",
83 addr[0], addr[1], addr[2], addr[3],
84 addr[4], addr[5], addr[6], addr[7],
85 addr[8], addr[9], addr[10], addr[11],
86 addr[12], addr[13], addr[14], addr[15]);
89 int qeth_l3_string_to_ipaddr6(const char *buf, __u8 *addr)
91 const char *end, *end_tmp, *start;
94 int num2, cnt, out, found, save_cnt;
95 unsigned short in_tmp[8] = {0, };
97 cnt = out = found = save_cnt = num2 = 0;
102 end = strchr(start, ':');
104 end = buf + strlen(buf);
105 end_tmp = strchr(start, '\n');
112 if ((end - start) > 4)
114 memcpy(num, start, end - start);
115 if (!qeth_l3_isxdigit(num))
117 sscanf(start, "%x", &num2);
119 in_tmp[save_cnt++] = num2;
131 if (cnt + save_cnt > 8)
135 in[cnt--] = in_tmp[--save_cnt];
139 void qeth_l3_ipaddr_to_string(enum qeth_prot_versions proto, const __u8 *addr,
142 if (proto == QETH_PROT_IPV4)
143 qeth_l3_ipaddr4_to_string(addr, buf);
144 else if (proto == QETH_PROT_IPV6)
145 qeth_l3_ipaddr6_to_string(addr, buf);
148 int qeth_l3_string_to_ipaddr(const char *buf, enum qeth_prot_versions proto,
151 if (proto == QETH_PROT_IPV4)
152 return qeth_l3_string_to_ipaddr4(buf, addr);
153 else if (proto == QETH_PROT_IPV6)
154 return qeth_l3_string_to_ipaddr6(buf, addr);
159 static void qeth_l3_convert_addr_to_bits(u8 *addr, u8 *bits, int len)
164 for (i = 0; i < len; ++i) {
166 for (j = 7; j >= 0; --j) {
167 bits[i*8 + j] = octet & 1;
173 static int qeth_l3_is_addr_covered_by_ipato(struct qeth_card *card,
174 struct qeth_ipaddr *addr)
176 struct qeth_ipato_entry *ipatoe;
177 u8 addr_bits[128] = {0, };
178 u8 ipatoe_bits[128] = {0, };
181 if (!card->ipato.enabled)
184 qeth_l3_convert_addr_to_bits((u8 *) &addr->u, addr_bits,
185 (addr->proto == QETH_PROT_IPV4)? 4:16);
186 list_for_each_entry(ipatoe, &card->ipato.entries, entry) {
187 if (addr->proto != ipatoe->proto)
189 qeth_l3_convert_addr_to_bits(ipatoe->addr, ipatoe_bits,
190 (ipatoe->proto == QETH_PROT_IPV4) ?
192 if (addr->proto == QETH_PROT_IPV4)
193 rc = !memcmp(addr_bits, ipatoe_bits,
194 min(32, ipatoe->mask_bits));
196 rc = !memcmp(addr_bits, ipatoe_bits,
197 min(128, ipatoe->mask_bits));
202 if ((addr->proto == QETH_PROT_IPV4) && card->ipato.invert4)
204 else if ((addr->proto == QETH_PROT_IPV6) && card->ipato.invert6)
211 * Add IP to be added to todo list. If there is already an "add todo"
212 * in this list we just incremenent the reference count.
213 * Returns 0 if we just incremented reference count.
215 static int __qeth_l3_insert_ip_todo(struct qeth_card *card,
216 struct qeth_ipaddr *addr, int add)
218 struct qeth_ipaddr *tmp, *t;
221 list_for_each_entry_safe(tmp, t, card->ip_tbd_list, entry) {
222 if ((addr->type == QETH_IP_TYPE_DEL_ALL_MC) &&
223 (tmp->type == QETH_IP_TYPE_DEL_ALL_MC))
225 if ((tmp->proto == QETH_PROT_IPV4) &&
226 (addr->proto == QETH_PROT_IPV4) &&
227 (tmp->type == addr->type) &&
228 (tmp->is_multicast == addr->is_multicast) &&
229 (tmp->u.a4.addr == addr->u.a4.addr) &&
230 (tmp->u.a4.mask == addr->u.a4.mask)) {
234 if ((tmp->proto == QETH_PROT_IPV6) &&
235 (addr->proto == QETH_PROT_IPV6) &&
236 (tmp->type == addr->type) &&
237 (tmp->is_multicast == addr->is_multicast) &&
238 (tmp->u.a6.pfxlen == addr->u.a6.pfxlen) &&
239 (memcmp(&tmp->u.a6.addr, &addr->u.a6.addr,
240 sizeof(struct in6_addr)) == 0)) {
246 if (addr->users != 0)
247 tmp->users += addr->users;
249 tmp->users += add ? 1 : -1;
250 if (tmp->users == 0) {
251 list_del(&tmp->entry);
256 if (addr->type == QETH_IP_TYPE_DEL_ALL_MC)
257 list_add(&addr->entry, card->ip_tbd_list);
259 if (addr->users == 0)
260 addr->users += add ? 1 : -1;
261 if (add && (addr->type == QETH_IP_TYPE_NORMAL) &&
262 qeth_l3_is_addr_covered_by_ipato(card, addr)) {
263 QETH_DBF_TEXT(TRACE, 2, "tkovaddr");
264 addr->set_flags |= QETH_IPA_SETIP_TAKEOVER_FLAG;
266 list_add_tail(&addr->entry, card->ip_tbd_list);
272 static int qeth_l3_delete_ip(struct qeth_card *card, struct qeth_ipaddr *addr)
277 QETH_DBF_TEXT(TRACE, 4, "delip");
279 if (addr->proto == QETH_PROT_IPV4)
280 QETH_DBF_HEX(TRACE, 4, &addr->u.a4.addr, 4);
282 QETH_DBF_HEX(TRACE, 4, &addr->u.a6.addr, 8);
283 QETH_DBF_HEX(TRACE, 4, ((char *)&addr->u.a6.addr) + 8, 8);
285 spin_lock_irqsave(&card->ip_lock, flags);
286 rc = __qeth_l3_insert_ip_todo(card, addr, 0);
287 spin_unlock_irqrestore(&card->ip_lock, flags);
291 static int qeth_l3_add_ip(struct qeth_card *card, struct qeth_ipaddr *addr)
296 QETH_DBF_TEXT(TRACE, 4, "addip");
297 if (addr->proto == QETH_PROT_IPV4)
298 QETH_DBF_HEX(TRACE, 4, &addr->u.a4.addr, 4);
300 QETH_DBF_HEX(TRACE, 4, &addr->u.a6.addr, 8);
301 QETH_DBF_HEX(TRACE, 4, ((char *)&addr->u.a6.addr) + 8, 8);
303 spin_lock_irqsave(&card->ip_lock, flags);
304 rc = __qeth_l3_insert_ip_todo(card, addr, 1);
305 spin_unlock_irqrestore(&card->ip_lock, flags);
310 static struct qeth_ipaddr *qeth_l3_get_addr_buffer(
311 enum qeth_prot_versions prot)
313 struct qeth_ipaddr *addr;
315 addr = kzalloc(sizeof(struct qeth_ipaddr), GFP_ATOMIC);
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);
464 if (!rc || (rc == IPA_RC_LAN_OFFLINE))
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,
657 int qeth_l3_setrouting_v4(struct qeth_card *card)
661 QETH_DBF_TEXT(TRACE, 3, "setrtg4");
663 qeth_l3_correct_routing_type(card, &card->options.route4.type,
666 rc = qeth_l3_send_setrouting(card, card->options.route4.type,
669 card->options.route4.type = NO_ROUTER;
670 QETH_DBF_MESSAGE(2, "Error (0x%04x) while setting routing type"
671 " on %s. Type set to 'no router'.\n", rc,
672 QETH_CARD_IFNAME(card));
677 int qeth_l3_setrouting_v6(struct qeth_card *card)
681 QETH_DBF_TEXT(TRACE, 3, "setrtg6");
682 #ifdef CONFIG_QETH_IPV6
684 if (!qeth_is_supported(card, IPA_IPV6))
686 qeth_l3_correct_routing_type(card, &card->options.route6.type,
689 rc = qeth_l3_send_setrouting(card, card->options.route6.type,
692 card->options.route6.type = NO_ROUTER;
693 QETH_DBF_MESSAGE(2, "Error (0x%04x) while setting routing type"
694 " on %s. Type set to 'no router'.\n", rc,
695 QETH_CARD_IFNAME(card));
702 * IP address takeover related functions
704 static void qeth_l3_clear_ipato_list(struct qeth_card *card)
707 struct qeth_ipato_entry *ipatoe, *tmp;
710 spin_lock_irqsave(&card->ip_lock, flags);
711 list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry) {
712 list_del(&ipatoe->entry);
715 spin_unlock_irqrestore(&card->ip_lock, flags);
718 int qeth_l3_add_ipato_entry(struct qeth_card *card,
719 struct qeth_ipato_entry *new)
721 struct qeth_ipato_entry *ipatoe;
725 QETH_DBF_TEXT(TRACE, 2, "addipato");
726 spin_lock_irqsave(&card->ip_lock, flags);
727 list_for_each_entry(ipatoe, &card->ipato.entries, entry) {
728 if (ipatoe->proto != new->proto)
730 if (!memcmp(ipatoe->addr, new->addr,
731 (ipatoe->proto == QETH_PROT_IPV4)? 4:16) &&
732 (ipatoe->mask_bits == new->mask_bits)) {
738 list_add_tail(&new->entry, &card->ipato.entries);
740 spin_unlock_irqrestore(&card->ip_lock, flags);
744 void qeth_l3_del_ipato_entry(struct qeth_card *card,
745 enum qeth_prot_versions proto, u8 *addr, int mask_bits)
747 struct qeth_ipato_entry *ipatoe, *tmp;
750 QETH_DBF_TEXT(TRACE, 2, "delipato");
751 spin_lock_irqsave(&card->ip_lock, flags);
752 list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry) {
753 if (ipatoe->proto != proto)
755 if (!memcmp(ipatoe->addr, addr,
756 (proto == QETH_PROT_IPV4)? 4:16) &&
757 (ipatoe->mask_bits == mask_bits)) {
758 list_del(&ipatoe->entry);
762 spin_unlock_irqrestore(&card->ip_lock, flags);
766 * VIPA related functions
768 int qeth_l3_add_vipa(struct qeth_card *card, enum qeth_prot_versions proto,
771 struct qeth_ipaddr *ipaddr;
775 ipaddr = qeth_l3_get_addr_buffer(proto);
777 if (proto == QETH_PROT_IPV4) {
778 QETH_DBF_TEXT(TRACE, 2, "addvipa4");
779 memcpy(&ipaddr->u.a4.addr, addr, 4);
780 ipaddr->u.a4.mask = 0;
781 } else if (proto == QETH_PROT_IPV6) {
782 QETH_DBF_TEXT(TRACE, 2, "addvipa6");
783 memcpy(&ipaddr->u.a6.addr, addr, 16);
784 ipaddr->u.a6.pfxlen = 0;
786 ipaddr->type = QETH_IP_TYPE_VIPA;
787 ipaddr->set_flags = QETH_IPA_SETIP_VIPA_FLAG;
788 ipaddr->del_flags = QETH_IPA_DELIP_VIPA_FLAG;
791 spin_lock_irqsave(&card->ip_lock, flags);
792 if (qeth_l3_address_exists_in_list(&card->ip_list, ipaddr, 0) ||
793 qeth_l3_address_exists_in_list(card->ip_tbd_list, ipaddr, 0))
795 spin_unlock_irqrestore(&card->ip_lock, flags);
799 if (!qeth_l3_add_ip(card, ipaddr))
801 qeth_l3_set_ip_addr_list(card);
805 void qeth_l3_del_vipa(struct qeth_card *card, enum qeth_prot_versions proto,
808 struct qeth_ipaddr *ipaddr;
810 ipaddr = qeth_l3_get_addr_buffer(proto);
812 if (proto == QETH_PROT_IPV4) {
813 QETH_DBF_TEXT(TRACE, 2, "delvipa4");
814 memcpy(&ipaddr->u.a4.addr, addr, 4);
815 ipaddr->u.a4.mask = 0;
816 } else if (proto == QETH_PROT_IPV6) {
817 QETH_DBF_TEXT(TRACE, 2, "delvipa6");
818 memcpy(&ipaddr->u.a6.addr, addr, 16);
819 ipaddr->u.a6.pfxlen = 0;
821 ipaddr->type = QETH_IP_TYPE_VIPA;
824 if (!qeth_l3_delete_ip(card, ipaddr))
826 qeth_l3_set_ip_addr_list(card);
830 * proxy ARP related functions
832 int qeth_l3_add_rxip(struct qeth_card *card, enum qeth_prot_versions proto,
835 struct qeth_ipaddr *ipaddr;
839 ipaddr = qeth_l3_get_addr_buffer(proto);
841 if (proto == QETH_PROT_IPV4) {
842 QETH_DBF_TEXT(TRACE, 2, "addrxip4");
843 memcpy(&ipaddr->u.a4.addr, addr, 4);
844 ipaddr->u.a4.mask = 0;
845 } else if (proto == QETH_PROT_IPV6) {
846 QETH_DBF_TEXT(TRACE, 2, "addrxip6");
847 memcpy(&ipaddr->u.a6.addr, addr, 16);
848 ipaddr->u.a6.pfxlen = 0;
850 ipaddr->type = QETH_IP_TYPE_RXIP;
851 ipaddr->set_flags = QETH_IPA_SETIP_TAKEOVER_FLAG;
852 ipaddr->del_flags = 0;
855 spin_lock_irqsave(&card->ip_lock, flags);
856 if (qeth_l3_address_exists_in_list(&card->ip_list, ipaddr, 0) ||
857 qeth_l3_address_exists_in_list(card->ip_tbd_list, ipaddr, 0))
859 spin_unlock_irqrestore(&card->ip_lock, flags);
863 if (!qeth_l3_add_ip(card, ipaddr))
865 qeth_l3_set_ip_addr_list(card);
869 void qeth_l3_del_rxip(struct qeth_card *card, enum qeth_prot_versions proto,
872 struct qeth_ipaddr *ipaddr;
874 ipaddr = qeth_l3_get_addr_buffer(proto);
876 if (proto == QETH_PROT_IPV4) {
877 QETH_DBF_TEXT(TRACE, 2, "addrxip4");
878 memcpy(&ipaddr->u.a4.addr, addr, 4);
879 ipaddr->u.a4.mask = 0;
880 } else if (proto == QETH_PROT_IPV6) {
881 QETH_DBF_TEXT(TRACE, 2, "addrxip6");
882 memcpy(&ipaddr->u.a6.addr, addr, 16);
883 ipaddr->u.a6.pfxlen = 0;
885 ipaddr->type = QETH_IP_TYPE_RXIP;
888 if (!qeth_l3_delete_ip(card, ipaddr))
890 qeth_l3_set_ip_addr_list(card);
893 static int qeth_l3_register_addr_entry(struct qeth_card *card,
894 struct qeth_ipaddr *addr)
900 if (addr->proto == QETH_PROT_IPV4) {
901 QETH_DBF_TEXT(TRACE, 2, "setaddr4");
902 QETH_DBF_HEX(TRACE, 3, &addr->u.a4.addr, sizeof(int));
903 } else if (addr->proto == QETH_PROT_IPV6) {
904 QETH_DBF_TEXT(TRACE, 2, "setaddr6");
905 QETH_DBF_HEX(TRACE, 3, &addr->u.a6.addr, 8);
906 QETH_DBF_HEX(TRACE, 3, ((char *)&addr->u.a6.addr) + 8, 8);
908 QETH_DBF_TEXT(TRACE, 2, "setaddr?");
909 QETH_DBF_HEX(TRACE, 3, addr, sizeof(struct qeth_ipaddr));
912 if (addr->is_multicast)
913 rc = qeth_l3_send_setdelmc(card, addr, IPA_CMD_SETIPM);
915 rc = qeth_l3_send_setdelip(card, addr, IPA_CMD_SETIP,
918 QETH_DBF_TEXT(TRACE, 2, "failed");
919 } while ((--cnt > 0) && rc);
921 QETH_DBF_TEXT(TRACE, 2, "FAILED");
922 qeth_l3_ipaddr_to_string(addr->proto, (u8 *)&addr->u, buf);
923 dev_warn(&card->gdev->dev,
924 "Registering IP address %s failed\n", buf);
929 static int qeth_l3_deregister_addr_entry(struct qeth_card *card,
930 struct qeth_ipaddr *addr)
934 if (addr->proto == QETH_PROT_IPV4) {
935 QETH_DBF_TEXT(TRACE, 2, "deladdr4");
936 QETH_DBF_HEX(TRACE, 3, &addr->u.a4.addr, sizeof(int));
937 } else if (addr->proto == QETH_PROT_IPV6) {
938 QETH_DBF_TEXT(TRACE, 2, "deladdr6");
939 QETH_DBF_HEX(TRACE, 3, &addr->u.a6.addr, 8);
940 QETH_DBF_HEX(TRACE, 3, ((char *)&addr->u.a6.addr) + 8, 8);
942 QETH_DBF_TEXT(TRACE, 2, "deladdr?");
943 QETH_DBF_HEX(TRACE, 3, addr, sizeof(struct qeth_ipaddr));
945 if (addr->is_multicast)
946 rc = qeth_l3_send_setdelmc(card, addr, IPA_CMD_DELIPM);
948 rc = qeth_l3_send_setdelip(card, addr, IPA_CMD_DELIP,
951 QETH_DBF_TEXT(TRACE, 2, "failed");
956 static inline u8 qeth_l3_get_qeth_hdr_flags4(int cast_type)
958 if (cast_type == RTN_MULTICAST)
959 return QETH_CAST_MULTICAST;
960 if (cast_type == RTN_BROADCAST)
961 return QETH_CAST_BROADCAST;
962 return QETH_CAST_UNICAST;
965 static inline u8 qeth_l3_get_qeth_hdr_flags6(int cast_type)
967 u8 ct = QETH_HDR_PASSTHRU | QETH_HDR_IPV6;
968 if (cast_type == RTN_MULTICAST)
969 return ct | QETH_CAST_MULTICAST;
970 if (cast_type == RTN_ANYCAST)
971 return ct | QETH_CAST_ANYCAST;
972 if (cast_type == RTN_BROADCAST)
973 return ct | QETH_CAST_BROADCAST;
974 return ct | QETH_CAST_UNICAST;
977 static int qeth_l3_send_setadp_mode(struct qeth_card *card, __u32 command,
981 struct qeth_cmd_buffer *iob;
982 struct qeth_ipa_cmd *cmd;
984 QETH_DBF_TEXT(TRACE, 4, "adpmode");
986 iob = qeth_get_adapter_cmd(card, command,
987 sizeof(struct qeth_ipacmd_setadpparms));
988 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
989 cmd->data.setadapterparms.data.mode = mode;
990 rc = qeth_send_ipa_cmd(card, iob, qeth_default_setadapterparms_cb,
995 static int qeth_l3_setadapter_hstr(struct qeth_card *card)
999 QETH_DBF_TEXT(TRACE, 4, "adphstr");
1001 if (qeth_adp_supported(card, IPA_SETADP_SET_BROADCAST_MODE)) {
1002 rc = qeth_l3_send_setadp_mode(card,
1003 IPA_SETADP_SET_BROADCAST_MODE,
1004 card->options.broadcast_mode);
1006 QETH_DBF_MESSAGE(2, "couldn't set broadcast mode on "
1008 CARD_BUS_ID(card), rc);
1009 rc = qeth_l3_send_setadp_mode(card,
1010 IPA_SETADP_ALTER_MAC_ADDRESS,
1011 card->options.macaddr_mode);
1013 QETH_DBF_MESSAGE(2, "couldn't set macaddr mode on "
1014 "device %s: x%x\n", CARD_BUS_ID(card), rc);
1017 if (card->options.broadcast_mode == QETH_TR_BROADCAST_LOCAL)
1018 QETH_DBF_MESSAGE(2, "set adapter parameters not available "
1019 "to set broadcast mode, using ALLRINGS "
1020 "on device %s:\n", CARD_BUS_ID(card));
1021 if (card->options.macaddr_mode == QETH_TR_MACADDR_CANONICAL)
1022 QETH_DBF_MESSAGE(2, "set adapter parameters not available "
1023 "to set macaddr mode, using NONCANONICAL "
1024 "on device %s:\n", CARD_BUS_ID(card));
1028 static int qeth_l3_setadapter_parms(struct qeth_card *card)
1032 QETH_DBF_TEXT(SETUP, 2, "setadprm");
1034 if (!qeth_is_supported(card, IPA_SETADAPTERPARMS)) {
1035 dev_info(&card->gdev->dev,
1036 "set adapter parameters not supported.\n");
1037 QETH_DBF_TEXT(SETUP, 2, " notsupp");
1040 rc = qeth_query_setadapterparms(card);
1042 QETH_DBF_MESSAGE(2, "%s couldn't set adapter parameters: "
1043 "0x%x\n", card->gdev->dev.bus_id, rc);
1046 if (qeth_adp_supported(card, IPA_SETADP_ALTER_MAC_ADDRESS)) {
1047 rc = qeth_setadpparms_change_macaddr(card);
1049 dev_warn(&card->gdev->dev, "Reading the adapter MAC"
1050 " address failed\n", rc);
1053 if ((card->info.link_type == QETH_LINK_TYPE_HSTR) ||
1054 (card->info.link_type == QETH_LINK_TYPE_LANE_TR))
1055 rc = qeth_l3_setadapter_hstr(card);
1060 static int qeth_l3_default_setassparms_cb(struct qeth_card *card,
1061 struct qeth_reply *reply, unsigned long data)
1063 struct qeth_ipa_cmd *cmd;
1065 QETH_DBF_TEXT(TRACE, 4, "defadpcb");
1067 cmd = (struct qeth_ipa_cmd *) data;
1068 if (cmd->hdr.return_code == 0) {
1069 cmd->hdr.return_code = cmd->data.setassparms.hdr.return_code;
1070 if (cmd->hdr.prot_version == QETH_PROT_IPV4)
1071 card->options.ipa4.enabled_funcs = cmd->hdr.ipa_enabled;
1072 if (cmd->hdr.prot_version == QETH_PROT_IPV6)
1073 card->options.ipa6.enabled_funcs = cmd->hdr.ipa_enabled;
1075 if (cmd->data.setassparms.hdr.assist_no == IPA_INBOUND_CHECKSUM &&
1076 cmd->data.setassparms.hdr.command_code == IPA_CMD_ASS_START) {
1077 card->info.csum_mask = cmd->data.setassparms.data.flags_32bit;
1078 QETH_DBF_TEXT_(TRACE, 3, "csum:%d", card->info.csum_mask);
1083 static struct qeth_cmd_buffer *qeth_l3_get_setassparms_cmd(
1084 struct qeth_card *card, enum qeth_ipa_funcs ipa_func, __u16 cmd_code,
1085 __u16 len, enum qeth_prot_versions prot)
1087 struct qeth_cmd_buffer *iob;
1088 struct qeth_ipa_cmd *cmd;
1090 QETH_DBF_TEXT(TRACE, 4, "getasscm");
1091 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SETASSPARMS, prot);
1093 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1094 cmd->data.setassparms.hdr.assist_no = ipa_func;
1095 cmd->data.setassparms.hdr.length = 8 + len;
1096 cmd->data.setassparms.hdr.command_code = cmd_code;
1097 cmd->data.setassparms.hdr.return_code = 0;
1098 cmd->data.setassparms.hdr.seq_no = 0;
1103 static int qeth_l3_send_setassparms(struct qeth_card *card,
1104 struct qeth_cmd_buffer *iob, __u16 len, long data,
1105 int (*reply_cb)(struct qeth_card *, struct qeth_reply *,
1110 struct qeth_ipa_cmd *cmd;
1112 QETH_DBF_TEXT(TRACE, 4, "sendassp");
1114 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1115 if (len <= sizeof(__u32))
1116 cmd->data.setassparms.data.flags_32bit = (__u32) data;
1117 else /* (len > sizeof(__u32)) */
1118 memcpy(&cmd->data.setassparms.data, (void *) data, len);
1120 rc = qeth_send_ipa_cmd(card, iob, reply_cb, reply_param);
1124 #ifdef CONFIG_QETH_IPV6
1125 static int qeth_l3_send_simple_setassparms_ipv6(struct qeth_card *card,
1126 enum qeth_ipa_funcs ipa_func, __u16 cmd_code)
1129 struct qeth_cmd_buffer *iob;
1131 QETH_DBF_TEXT(TRACE, 4, "simassp6");
1132 iob = qeth_l3_get_setassparms_cmd(card, ipa_func, cmd_code,
1134 rc = qeth_l3_send_setassparms(card, iob, 0, 0,
1135 qeth_l3_default_setassparms_cb, NULL);
1140 static int qeth_l3_send_simple_setassparms(struct qeth_card *card,
1141 enum qeth_ipa_funcs ipa_func, __u16 cmd_code, long data)
1145 struct qeth_cmd_buffer *iob;
1147 QETH_DBF_TEXT(TRACE, 4, "simassp4");
1149 length = sizeof(__u32);
1150 iob = qeth_l3_get_setassparms_cmd(card, ipa_func, cmd_code,
1151 length, QETH_PROT_IPV4);
1152 rc = qeth_l3_send_setassparms(card, iob, length, data,
1153 qeth_l3_default_setassparms_cb, NULL);
1157 static int qeth_l3_start_ipa_arp_processing(struct qeth_card *card)
1161 QETH_DBF_TEXT(TRACE, 3, "ipaarp");
1163 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
1164 dev_info(&card->gdev->dev,
1165 "ARP processing not supported on %s!\n",
1166 QETH_CARD_IFNAME(card));
1169 rc = qeth_l3_send_simple_setassparms(card, IPA_ARP_PROCESSING,
1170 IPA_CMD_ASS_START, 0);
1172 dev_warn(&card->gdev->dev,
1173 "Starting ARP processing support for %s failed\n",
1174 QETH_CARD_IFNAME(card));
1179 static int qeth_l3_start_ipa_ip_fragmentation(struct qeth_card *card)
1183 QETH_DBF_TEXT(TRACE, 3, "ipaipfrg");
1185 if (!qeth_is_supported(card, IPA_IP_FRAGMENTATION)) {
1186 dev_info(&card->gdev->dev,
1187 "Hardware IP fragmentation not supported on %s\n",
1188 QETH_CARD_IFNAME(card));
1192 rc = qeth_l3_send_simple_setassparms(card, IPA_IP_FRAGMENTATION,
1193 IPA_CMD_ASS_START, 0);
1195 dev_warn(&card->gdev->dev,
1196 "Starting IP fragmentation support for %s failed\n",
1197 QETH_CARD_IFNAME(card));
1199 dev_info(&card->gdev->dev,
1200 "Hardware IP fragmentation enabled \n");
1204 static int qeth_l3_start_ipa_source_mac(struct qeth_card *card)
1208 QETH_DBF_TEXT(TRACE, 3, "stsrcmac");
1210 if (!card->options.fake_ll)
1213 if (!qeth_is_supported(card, IPA_SOURCE_MAC)) {
1214 dev_info(&card->gdev->dev,
1215 "Inbound source address not supported on %s\n",
1216 QETH_CARD_IFNAME(card));
1220 rc = qeth_l3_send_simple_setassparms(card, IPA_SOURCE_MAC,
1221 IPA_CMD_ASS_START, 0);
1223 dev_warn(&card->gdev->dev,
1224 "Starting proxy ARP support for %s failed\n",
1225 QETH_CARD_IFNAME(card));
1229 static int qeth_l3_start_ipa_vlan(struct qeth_card *card)
1233 QETH_DBF_TEXT(TRACE, 3, "strtvlan");
1235 if (!qeth_is_supported(card, IPA_FULL_VLAN)) {
1236 dev_info(&card->gdev->dev,
1237 "VLAN not supported on %s\n", QETH_CARD_IFNAME(card));
1241 rc = qeth_l3_send_simple_setassparms(card, IPA_VLAN_PRIO,
1242 IPA_CMD_ASS_START, 0);
1244 dev_warn(&card->gdev->dev,
1245 "Starting VLAN support for %s failed\n",
1246 QETH_CARD_IFNAME(card));
1248 dev_info(&card->gdev->dev, "VLAN enabled\n");
1253 static int qeth_l3_start_ipa_multicast(struct qeth_card *card)
1257 QETH_DBF_TEXT(TRACE, 3, "stmcast");
1259 if (!qeth_is_supported(card, IPA_MULTICASTING)) {
1260 dev_info(&card->gdev->dev,
1261 "Multicast not supported on %s\n",
1262 QETH_CARD_IFNAME(card));
1266 rc = qeth_l3_send_simple_setassparms(card, IPA_MULTICASTING,
1267 IPA_CMD_ASS_START, 0);
1269 dev_warn(&card->gdev->dev,
1270 "Starting multicast support for %s failed\n",
1271 QETH_CARD_IFNAME(card));
1273 dev_info(&card->gdev->dev, "Multicast enabled\n");
1274 card->dev->flags |= IFF_MULTICAST;
1279 static int qeth_l3_query_ipassists_cb(struct qeth_card *card,
1280 struct qeth_reply *reply, unsigned long data)
1282 struct qeth_ipa_cmd *cmd;
1284 QETH_DBF_TEXT(SETUP, 2, "qipasscb");
1286 cmd = (struct qeth_ipa_cmd *) data;
1287 if (cmd->hdr.prot_version == QETH_PROT_IPV4) {
1288 card->options.ipa4.supported_funcs = cmd->hdr.ipa_supported;
1289 card->options.ipa4.enabled_funcs = cmd->hdr.ipa_enabled;
1291 card->options.ipa6.supported_funcs = cmd->hdr.ipa_supported;
1292 card->options.ipa6.enabled_funcs = cmd->hdr.ipa_enabled;
1294 QETH_DBF_TEXT(SETUP, 2, "suppenbl");
1295 QETH_DBF_TEXT_(SETUP, 2, "%x", cmd->hdr.ipa_supported);
1296 QETH_DBF_TEXT_(SETUP, 2, "%x", cmd->hdr.ipa_enabled);
1300 static int qeth_l3_query_ipassists(struct qeth_card *card,
1301 enum qeth_prot_versions prot)
1304 struct qeth_cmd_buffer *iob;
1306 QETH_DBF_TEXT_(SETUP, 2, "qipassi%i", prot);
1307 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_QIPASSIST, prot);
1308 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_query_ipassists_cb, NULL);
1312 #ifdef CONFIG_QETH_IPV6
1313 static int qeth_l3_softsetup_ipv6(struct qeth_card *card)
1317 QETH_DBF_TEXT(TRACE, 3, "softipv6");
1319 if (card->info.type == QETH_CARD_TYPE_IQD)
1322 rc = qeth_l3_query_ipassists(card, QETH_PROT_IPV6);
1324 dev_err(&card->gdev->dev,
1325 "Activating IPv6 support for %s failed\n",
1326 QETH_CARD_IFNAME(card));
1329 rc = qeth_l3_send_simple_setassparms(card, IPA_IPV6,
1330 IPA_CMD_ASS_START, 3);
1332 dev_err(&card->gdev->dev,
1333 "Activating IPv6 support for %s failed\n",
1334 QETH_CARD_IFNAME(card));
1337 rc = qeth_l3_send_simple_setassparms_ipv6(card, IPA_IPV6,
1340 dev_err(&card->gdev->dev,
1341 "Activating IPv6 support for %s failed\n",
1342 QETH_CARD_IFNAME(card));
1345 rc = qeth_l3_send_simple_setassparms_ipv6(card, IPA_PASSTHRU,
1348 dev_warn(&card->gdev->dev,
1349 "Enabling the passthrough mode for %s failed\n",
1350 QETH_CARD_IFNAME(card));
1354 dev_info(&card->gdev->dev, "IPV6 enabled\n");
1359 static int qeth_l3_start_ipa_ipv6(struct qeth_card *card)
1363 QETH_DBF_TEXT(TRACE, 3, "strtipv6");
1365 if (!qeth_is_supported(card, IPA_IPV6)) {
1366 dev_info(&card->gdev->dev,
1367 "IPv6 not supported on %s\n", QETH_CARD_IFNAME(card));
1370 #ifdef CONFIG_QETH_IPV6
1371 rc = qeth_l3_softsetup_ipv6(card);
1376 static int qeth_l3_start_ipa_broadcast(struct qeth_card *card)
1380 QETH_DBF_TEXT(TRACE, 3, "stbrdcst");
1381 card->info.broadcast_capable = 0;
1382 if (!qeth_is_supported(card, IPA_FILTERING)) {
1383 dev_info(&card->gdev->dev,
1384 "Broadcast not supported on %s\n",
1385 QETH_CARD_IFNAME(card));
1389 rc = qeth_l3_send_simple_setassparms(card, IPA_FILTERING,
1390 IPA_CMD_ASS_START, 0);
1392 dev_warn(&card->gdev->dev, "Enabling broadcast filtering for "
1393 "%s failed\n", QETH_CARD_IFNAME(card));
1397 rc = qeth_l3_send_simple_setassparms(card, IPA_FILTERING,
1398 IPA_CMD_ASS_CONFIGURE, 1);
1400 dev_warn(&card->gdev->dev,
1401 "Setting up broadcast filtering for %s failed\n",
1402 QETH_CARD_IFNAME(card));
1405 card->info.broadcast_capable = QETH_BROADCAST_WITH_ECHO;
1406 dev_info(&card->gdev->dev, "Broadcast enabled\n");
1407 rc = qeth_l3_send_simple_setassparms(card, IPA_FILTERING,
1408 IPA_CMD_ASS_ENABLE, 1);
1410 dev_warn(&card->gdev->dev, "Setting up broadcast echo "
1411 "filtering for %s failed\n", QETH_CARD_IFNAME(card));
1414 card->info.broadcast_capable = QETH_BROADCAST_WITHOUT_ECHO;
1416 if (card->info.broadcast_capable)
1417 card->dev->flags |= IFF_BROADCAST;
1419 card->dev->flags &= ~IFF_BROADCAST;
1423 static int qeth_l3_send_checksum_command(struct qeth_card *card)
1427 rc = qeth_l3_send_simple_setassparms(card, IPA_INBOUND_CHECKSUM,
1428 IPA_CMD_ASS_START, 0);
1430 dev_warn(&card->gdev->dev, "Starting HW checksumming for %s "
1431 "failed, using SW checksumming\n",
1432 QETH_CARD_IFNAME(card));
1435 rc = qeth_l3_send_simple_setassparms(card, IPA_INBOUND_CHECKSUM,
1437 card->info.csum_mask);
1439 dev_warn(&card->gdev->dev, "Enabling HW checksumming for %s "
1440 "failed, using SW checksumming\n",
1441 QETH_CARD_IFNAME(card));
1447 static int qeth_l3_start_ipa_checksum(struct qeth_card *card)
1451 QETH_DBF_TEXT(TRACE, 3, "strtcsum");
1453 if (card->options.checksum_type == NO_CHECKSUMMING) {
1454 dev_info(&card->gdev->dev,
1455 "Using no checksumming on %s.\n",
1456 QETH_CARD_IFNAME(card));
1459 if (card->options.checksum_type == SW_CHECKSUMMING) {
1460 dev_info(&card->gdev->dev,
1461 "Using SW checksumming on %s.\n",
1462 QETH_CARD_IFNAME(card));
1465 if (!qeth_is_supported(card, IPA_INBOUND_CHECKSUM)) {
1466 dev_info(&card->gdev->dev,
1467 "Inbound HW Checksumming not "
1468 "supported on %s,\ncontinuing "
1469 "using Inbound SW Checksumming\n",
1470 QETH_CARD_IFNAME(card));
1471 card->options.checksum_type = SW_CHECKSUMMING;
1474 rc = qeth_l3_send_checksum_command(card);
1476 dev_info(&card->gdev->dev,
1477 "HW Checksumming (inbound) enabled\n");
1482 static int qeth_l3_start_ipa_tso(struct qeth_card *card)
1486 QETH_DBF_TEXT(TRACE, 3, "sttso");
1488 if (!qeth_is_supported(card, IPA_OUTBOUND_TSO)) {
1489 dev_info(&card->gdev->dev,
1490 "Outbound TSO not supported on %s\n",
1491 QETH_CARD_IFNAME(card));
1494 rc = qeth_l3_send_simple_setassparms(card, IPA_OUTBOUND_TSO,
1495 IPA_CMD_ASS_START, 0);
1497 dev_warn(&card->gdev->dev, "Starting outbound TCP "
1498 "segmentation offload for %s failed\n",
1499 QETH_CARD_IFNAME(card));
1501 dev_info(&card->gdev->dev,
1502 "Outbound TSO enabled\n");
1504 if (rc && (card->options.large_send == QETH_LARGE_SEND_TSO)) {
1505 card->options.large_send = QETH_LARGE_SEND_NO;
1506 card->dev->features &= ~(NETIF_F_TSO | NETIF_F_SG);
1511 static int qeth_l3_start_ipassists(struct qeth_card *card)
1513 QETH_DBF_TEXT(TRACE, 3, "strtipas");
1514 qeth_l3_start_ipa_arp_processing(card); /* go on*/
1515 qeth_l3_start_ipa_ip_fragmentation(card); /* go on*/
1516 qeth_l3_start_ipa_source_mac(card); /* go on*/
1517 qeth_l3_start_ipa_vlan(card); /* go on*/
1518 qeth_l3_start_ipa_multicast(card); /* go on*/
1519 qeth_l3_start_ipa_ipv6(card); /* go on*/
1520 qeth_l3_start_ipa_broadcast(card); /* go on*/
1521 qeth_l3_start_ipa_checksum(card); /* go on*/
1522 qeth_l3_start_ipa_tso(card); /* go on*/
1526 static int qeth_l3_put_unique_id(struct qeth_card *card)
1530 struct qeth_cmd_buffer *iob;
1531 struct qeth_ipa_cmd *cmd;
1533 QETH_DBF_TEXT(TRACE, 2, "puniqeid");
1535 if ((card->info.unique_id & UNIQUE_ID_NOT_BY_CARD) ==
1536 UNIQUE_ID_NOT_BY_CARD)
1538 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_DESTROY_ADDR,
1540 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1541 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
1542 card->info.unique_id;
1543 memcpy(&cmd->data.create_destroy_addr.unique_id[0],
1544 card->dev->dev_addr, OSA_ADDR_LEN);
1545 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
1549 static int qeth_l3_iqd_read_initial_mac_cb(struct qeth_card *card,
1550 struct qeth_reply *reply, unsigned long data)
1552 struct qeth_ipa_cmd *cmd;
1554 cmd = (struct qeth_ipa_cmd *) data;
1555 if (cmd->hdr.return_code == 0)
1556 memcpy(card->dev->dev_addr,
1557 cmd->data.create_destroy_addr.unique_id, ETH_ALEN);
1559 random_ether_addr(card->dev->dev_addr);
1564 static int qeth_l3_iqd_read_initial_mac(struct qeth_card *card)
1567 struct qeth_cmd_buffer *iob;
1568 struct qeth_ipa_cmd *cmd;
1570 QETH_DBF_TEXT(SETUP, 2, "hsrmac");
1572 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_CREATE_ADDR,
1574 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1575 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
1576 card->info.unique_id;
1578 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_iqd_read_initial_mac_cb,
1583 static int qeth_l3_get_unique_id_cb(struct qeth_card *card,
1584 struct qeth_reply *reply, unsigned long data)
1586 struct qeth_ipa_cmd *cmd;
1588 cmd = (struct qeth_ipa_cmd *) data;
1589 if (cmd->hdr.return_code == 0)
1590 card->info.unique_id = *((__u16 *)
1591 &cmd->data.create_destroy_addr.unique_id[6]);
1593 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
1594 UNIQUE_ID_NOT_BY_CARD;
1595 dev_warn(&card->gdev->dev, "The network adapter failed to "
1596 "generate a unique ID\n");
1601 static int qeth_l3_get_unique_id(struct qeth_card *card)
1604 struct qeth_cmd_buffer *iob;
1605 struct qeth_ipa_cmd *cmd;
1607 QETH_DBF_TEXT(SETUP, 2, "guniqeid");
1609 if (!qeth_is_supported(card, IPA_IPV6)) {
1610 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
1611 UNIQUE_ID_NOT_BY_CARD;
1615 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_CREATE_ADDR,
1617 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1618 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
1619 card->info.unique_id;
1621 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_get_unique_id_cb, NULL);
1625 static void qeth_l3_get_mac_for_ipm(__u32 ipm, char *mac,
1626 struct net_device *dev)
1628 if (dev->type == ARPHRD_IEEE802_TR)
1629 ip_tr_mc_map(ipm, mac);
1631 ip_eth_mc_map(ipm, mac);
1634 static void qeth_l3_add_mc(struct qeth_card *card, struct in_device *in4_dev)
1636 struct qeth_ipaddr *ipm;
1637 struct ip_mc_list *im4;
1638 char buf[MAX_ADDR_LEN];
1640 QETH_DBF_TEXT(TRACE, 4, "addmc");
1641 for (im4 = in4_dev->mc_list; im4; im4 = im4->next) {
1642 qeth_l3_get_mac_for_ipm(im4->multiaddr, buf, in4_dev->dev);
1643 ipm = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
1646 ipm->u.a4.addr = im4->multiaddr;
1647 memcpy(ipm->mac, buf, OSA_ADDR_LEN);
1648 ipm->is_multicast = 1;
1649 if (!qeth_l3_add_ip(card, ipm))
1654 static void qeth_l3_add_vlan_mc(struct qeth_card *card)
1656 struct in_device *in_dev;
1657 struct vlan_group *vg;
1660 QETH_DBF_TEXT(TRACE, 4, "addmcvl");
1661 if (!qeth_is_supported(card, IPA_FULL_VLAN) || (card->vlangrp == NULL))
1665 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
1666 struct net_device *netdev = vlan_group_get_device(vg, i);
1667 if (netdev == NULL ||
1668 !(netdev->flags & IFF_UP))
1670 in_dev = in_dev_get(netdev);
1673 read_lock(&in_dev->mc_list_lock);
1674 qeth_l3_add_mc(card, in_dev);
1675 read_unlock(&in_dev->mc_list_lock);
1680 static void qeth_l3_add_multicast_ipv4(struct qeth_card *card)
1682 struct in_device *in4_dev;
1684 QETH_DBF_TEXT(TRACE, 4, "chkmcv4");
1685 in4_dev = in_dev_get(card->dev);
1686 if (in4_dev == NULL)
1688 read_lock(&in4_dev->mc_list_lock);
1689 qeth_l3_add_mc(card, in4_dev);
1690 qeth_l3_add_vlan_mc(card);
1691 read_unlock(&in4_dev->mc_list_lock);
1692 in_dev_put(in4_dev);
1695 #ifdef CONFIG_QETH_IPV6
1696 static void qeth_l3_add_mc6(struct qeth_card *card, struct inet6_dev *in6_dev)
1698 struct qeth_ipaddr *ipm;
1699 struct ifmcaddr6 *im6;
1700 char buf[MAX_ADDR_LEN];
1702 QETH_DBF_TEXT(TRACE, 4, "addmc6");
1703 for (im6 = in6_dev->mc_list; im6 != NULL; im6 = im6->next) {
1704 ndisc_mc_map(&im6->mca_addr, buf, in6_dev->dev, 0);
1705 ipm = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
1708 ipm->is_multicast = 1;
1709 memcpy(ipm->mac, buf, OSA_ADDR_LEN);
1710 memcpy(&ipm->u.a6.addr, &im6->mca_addr.s6_addr,
1711 sizeof(struct in6_addr));
1712 if (!qeth_l3_add_ip(card, ipm))
1717 static void qeth_l3_add_vlan_mc6(struct qeth_card *card)
1719 struct inet6_dev *in_dev;
1720 struct vlan_group *vg;
1723 QETH_DBF_TEXT(TRACE, 4, "admc6vl");
1724 if (!qeth_is_supported(card, IPA_FULL_VLAN) || (card->vlangrp == NULL))
1728 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
1729 struct net_device *netdev = vlan_group_get_device(vg, i);
1730 if (netdev == NULL ||
1731 !(netdev->flags & IFF_UP))
1733 in_dev = in6_dev_get(netdev);
1736 read_lock_bh(&in_dev->lock);
1737 qeth_l3_add_mc6(card, in_dev);
1738 read_unlock_bh(&in_dev->lock);
1739 in6_dev_put(in_dev);
1743 static void qeth_l3_add_multicast_ipv6(struct qeth_card *card)
1745 struct inet6_dev *in6_dev;
1747 QETH_DBF_TEXT(TRACE, 4, "chkmcv6");
1748 if (!qeth_is_supported(card, IPA_IPV6))
1750 in6_dev = in6_dev_get(card->dev);
1751 if (in6_dev == NULL)
1753 read_lock_bh(&in6_dev->lock);
1754 qeth_l3_add_mc6(card, in6_dev);
1755 qeth_l3_add_vlan_mc6(card);
1756 read_unlock_bh(&in6_dev->lock);
1757 in6_dev_put(in6_dev);
1759 #endif /* CONFIG_QETH_IPV6 */
1761 static void qeth_l3_free_vlan_addresses4(struct qeth_card *card,
1764 struct in_device *in_dev;
1765 struct in_ifaddr *ifa;
1766 struct qeth_ipaddr *addr;
1768 QETH_DBF_TEXT(TRACE, 4, "frvaddr4");
1770 in_dev = in_dev_get(vlan_group_get_device(card->vlangrp, vid));
1773 for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
1774 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
1776 addr->u.a4.addr = ifa->ifa_address;
1777 addr->u.a4.mask = ifa->ifa_mask;
1778 addr->type = QETH_IP_TYPE_NORMAL;
1779 if (!qeth_l3_delete_ip(card, addr))
1786 static void qeth_l3_free_vlan_addresses6(struct qeth_card *card,
1789 #ifdef CONFIG_QETH_IPV6
1790 struct inet6_dev *in6_dev;
1791 struct inet6_ifaddr *ifa;
1792 struct qeth_ipaddr *addr;
1794 QETH_DBF_TEXT(TRACE, 4, "frvaddr6");
1796 in6_dev = in6_dev_get(vlan_group_get_device(card->vlangrp, vid));
1799 for (ifa = in6_dev->addr_list; ifa; ifa = ifa->lst_next) {
1800 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
1802 memcpy(&addr->u.a6.addr, &ifa->addr,
1803 sizeof(struct in6_addr));
1804 addr->u.a6.pfxlen = ifa->prefix_len;
1805 addr->type = QETH_IP_TYPE_NORMAL;
1806 if (!qeth_l3_delete_ip(card, addr))
1810 in6_dev_put(in6_dev);
1811 #endif /* CONFIG_QETH_IPV6 */
1814 static void qeth_l3_free_vlan_addresses(struct qeth_card *card,
1819 qeth_l3_free_vlan_addresses4(card, vid);
1820 qeth_l3_free_vlan_addresses6(card, vid);
1823 static void qeth_l3_vlan_rx_register(struct net_device *dev,
1824 struct vlan_group *grp)
1826 struct qeth_card *card = dev->ml_priv;
1827 unsigned long flags;
1829 QETH_DBF_TEXT(TRACE, 4, "vlanreg");
1830 spin_lock_irqsave(&card->vlanlock, flags);
1831 card->vlangrp = grp;
1832 spin_unlock_irqrestore(&card->vlanlock, flags);
1835 static void qeth_l3_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
1837 struct net_device *vlandev;
1838 struct qeth_card *card = dev->ml_priv;
1839 struct in_device *in_dev;
1841 if (card->info.type == QETH_CARD_TYPE_IQD)
1844 vlandev = vlan_group_get_device(card->vlangrp, vid);
1845 vlandev->neigh_setup = qeth_l3_neigh_setup;
1847 in_dev = in_dev_get(vlandev);
1848 #ifdef CONFIG_SYSCTL
1849 neigh_sysctl_unregister(in_dev->arp_parms);
1851 neigh_parms_release(&arp_tbl, in_dev->arp_parms);
1853 in_dev->arp_parms = neigh_parms_alloc(vlandev, &arp_tbl);
1854 #ifdef CONFIG_SYSCTL
1855 neigh_sysctl_register(vlandev, in_dev->arp_parms, NET_IPV4,
1856 NET_IPV4_NEIGH, "ipv4", NULL, NULL);
1862 static void qeth_l3_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
1864 struct qeth_card *card = dev->ml_priv;
1865 unsigned long flags;
1867 QETH_DBF_TEXT_(TRACE, 4, "kid:%d", vid);
1868 spin_lock_irqsave(&card->vlanlock, flags);
1869 /* unregister IP addresses of vlan device */
1870 qeth_l3_free_vlan_addresses(card, vid);
1871 vlan_group_set_device(card->vlangrp, vid, NULL);
1872 spin_unlock_irqrestore(&card->vlanlock, flags);
1873 qeth_l3_set_multicast_list(card->dev);
1876 static inline __u16 qeth_l3_rebuild_skb(struct qeth_card *card,
1877 struct sk_buff *skb, struct qeth_hdr *hdr)
1879 unsigned short vlan_id = 0;
1881 struct iphdr *ip_hdr;
1882 unsigned char tg_addr[MAX_ADDR_LEN];
1884 if (!(hdr->hdr.l3.flags & QETH_HDR_PASSTHRU)) {
1885 prot = htons((hdr->hdr.l3.flags & QETH_HDR_IPV6)? ETH_P_IPV6 :
1887 switch (hdr->hdr.l3.flags & QETH_HDR_CAST_MASK) {
1888 case QETH_CAST_MULTICAST:
1890 #ifdef CONFIG_QETH_IPV6
1891 case __constant_htons(ETH_P_IPV6):
1892 ndisc_mc_map((struct in6_addr *)
1894 tg_addr, card->dev, 0);
1897 case __constant_htons(ETH_P_IP):
1898 ip_hdr = (struct iphdr *)skb->data;
1899 (card->dev->type == ARPHRD_IEEE802_TR) ?
1900 ip_tr_mc_map(ip_hdr->daddr, tg_addr):
1901 ip_eth_mc_map(ip_hdr->daddr, tg_addr);
1904 memcpy(tg_addr, card->dev->broadcast,
1905 card->dev->addr_len);
1907 card->stats.multicast++;
1908 skb->pkt_type = PACKET_MULTICAST;
1910 case QETH_CAST_BROADCAST:
1911 memcpy(tg_addr, card->dev->broadcast,
1912 card->dev->addr_len);
1913 card->stats.multicast++;
1914 skb->pkt_type = PACKET_BROADCAST;
1916 case QETH_CAST_UNICAST:
1917 case QETH_CAST_ANYCAST:
1918 case QETH_CAST_NOCAST:
1920 skb->pkt_type = PACKET_HOST;
1921 memcpy(tg_addr, card->dev->dev_addr,
1922 card->dev->addr_len);
1924 card->dev->header_ops->create(skb, card->dev, prot, tg_addr,
1925 "FAKELL", card->dev->addr_len);
1929 if (card->dev->type == ARPHRD_IEEE802_TR)
1930 skb->protocol = tr_type_trans(skb, card->dev);
1933 skb->protocol = eth_type_trans(skb, card->dev);
1935 if (hdr->hdr.l3.ext_flags &
1936 (QETH_HDR_EXT_VLAN_FRAME | QETH_HDR_EXT_INCLUDE_VLAN_TAG)) {
1937 vlan_id = (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_VLAN_FRAME)?
1938 hdr->hdr.l3.vlan_id : *((u16 *)&hdr->hdr.l3.dest_addr[12]);
1941 skb->ip_summed = card->options.checksum_type;
1942 if (card->options.checksum_type == HW_CHECKSUMMING) {
1943 if ((hdr->hdr.l3.ext_flags &
1944 (QETH_HDR_EXT_CSUM_HDR_REQ |
1945 QETH_HDR_EXT_CSUM_TRANSP_REQ)) ==
1946 (QETH_HDR_EXT_CSUM_HDR_REQ |
1947 QETH_HDR_EXT_CSUM_TRANSP_REQ))
1948 skb->ip_summed = CHECKSUM_UNNECESSARY;
1950 skb->ip_summed = SW_CHECKSUMMING;
1956 static void qeth_l3_process_inbound_buffer(struct qeth_card *card,
1957 struct qeth_qdio_buffer *buf, int index)
1959 struct qdio_buffer_element *element;
1960 struct sk_buff *skb;
1961 struct qeth_hdr *hdr;
1966 /* get first element of current buffer */
1967 element = (struct qdio_buffer_element *)&buf->buffer->element[0];
1969 if (card->options.performance_stats)
1970 card->perf_stats.bufs_rec++;
1971 while ((skb = qeth_core_get_next_skb(card, buf->buffer, &element,
1973 skb->dev = card->dev;
1974 /* is device UP ? */
1975 if (!(card->dev->flags & IFF_UP)) {
1976 dev_kfree_skb_any(skb);
1980 switch (hdr->hdr.l3.id) {
1981 case QETH_HEADER_TYPE_LAYER3:
1982 vlan_tag = qeth_l3_rebuild_skb(card, skb, hdr);
1986 vlan_hwaccel_rx(skb, card->vlangrp,
1989 dev_kfree_skb_any(skb);
1996 dev_kfree_skb_any(skb);
1997 QETH_DBF_TEXT(TRACE, 3, "inbunkno");
1998 QETH_DBF_HEX(CTRL, 3, hdr, QETH_DBF_CTRL_LEN);
2002 card->dev->last_rx = jiffies;
2003 card->stats.rx_packets++;
2004 card->stats.rx_bytes += len;
2008 static int qeth_l3_verify_vlan_dev(struct net_device *dev,
2009 struct qeth_card *card)
2012 struct vlan_group *vg;
2019 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
2020 if (vlan_group_get_device(vg, i) == dev) {
2021 rc = QETH_VLAN_CARD;
2026 if (rc && !(vlan_dev_real_dev(dev)->ml_priv == (void *)card))
2032 static int qeth_l3_verify_dev(struct net_device *dev)
2034 struct qeth_card *card;
2035 unsigned long flags;
2038 read_lock_irqsave(&qeth_core_card_list.rwlock, flags);
2039 list_for_each_entry(card, &qeth_core_card_list.list, list) {
2040 if (card->dev == dev) {
2041 rc = QETH_REAL_CARD;
2044 rc = qeth_l3_verify_vlan_dev(dev, card);
2048 read_unlock_irqrestore(&qeth_core_card_list.rwlock, flags);
2053 static struct qeth_card *qeth_l3_get_card_from_dev(struct net_device *dev)
2055 struct qeth_card *card = NULL;
2058 rc = qeth_l3_verify_dev(dev);
2059 if (rc == QETH_REAL_CARD)
2060 card = dev->ml_priv;
2061 else if (rc == QETH_VLAN_CARD)
2062 card = vlan_dev_real_dev(dev)->ml_priv;
2063 if (card && card->options.layer2)
2065 QETH_DBF_TEXT_(TRACE, 4, "%d", rc);
2069 static int qeth_l3_stop_card(struct qeth_card *card, int recovery_mode)
2073 QETH_DBF_TEXT(SETUP, 2, "stopcard");
2074 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
2076 qeth_set_allowed_threads(card, 0, 1);
2077 if (card->read.state == CH_STATE_UP &&
2078 card->write.state == CH_STATE_UP &&
2079 (card->state == CARD_STATE_UP)) {
2081 qeth_l3_stop(card->dev);
2084 dev_close(card->dev);
2087 if (!card->use_hard_stop) {
2088 rc = qeth_send_stoplan(card);
2090 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
2092 card->state = CARD_STATE_SOFTSETUP;
2094 if (card->state == CARD_STATE_SOFTSETUP) {
2095 qeth_l3_clear_ip_list(card, !card->use_hard_stop, 1);
2096 qeth_clear_ipacmd_list(card);
2097 card->state = CARD_STATE_HARDSETUP;
2099 if (card->state == CARD_STATE_HARDSETUP) {
2100 if (!card->use_hard_stop &&
2101 (card->info.type != QETH_CARD_TYPE_IQD)) {
2102 rc = qeth_l3_put_unique_id(card);
2104 QETH_DBF_TEXT_(SETUP, 2, "2err%d", rc);
2106 qeth_qdio_clear_card(card, 0);
2107 qeth_clear_qdio_buffers(card);
2108 qeth_clear_working_pool_list(card);
2109 card->state = CARD_STATE_DOWN;
2111 if (card->state == CARD_STATE_DOWN) {
2112 qeth_clear_cmd_buffers(&card->read);
2113 qeth_clear_cmd_buffers(&card->write);
2115 card->use_hard_stop = 0;
2119 static void qeth_l3_set_multicast_list(struct net_device *dev)
2121 struct qeth_card *card = dev->ml_priv;
2123 QETH_DBF_TEXT(TRACE, 3, "setmulti");
2124 qeth_l3_delete_mc_addresses(card);
2125 qeth_l3_add_multicast_ipv4(card);
2126 #ifdef CONFIG_QETH_IPV6
2127 qeth_l3_add_multicast_ipv6(card);
2129 qeth_l3_set_ip_addr_list(card);
2130 if (!qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
2132 qeth_setadp_promisc_mode(card);
2135 static const char *qeth_l3_arp_get_error_cause(int *rc)
2138 case QETH_IPA_ARP_RC_FAILED:
2140 return "operation failed";
2141 case QETH_IPA_ARP_RC_NOTSUPP:
2143 return "operation not supported";
2144 case QETH_IPA_ARP_RC_OUT_OF_RANGE:
2146 return "argument out of range";
2147 case QETH_IPA_ARP_RC_Q_NOTSUPP:
2149 return "query operation not supported";
2150 case QETH_IPA_ARP_RC_Q_NO_DATA:
2152 return "no query data available";
2154 return "unknown error";
2158 static int qeth_l3_arp_set_no_entries(struct qeth_card *card, int no_entries)
2163 QETH_DBF_TEXT(TRACE, 3, "arpstnoe");
2166 * currently GuestLAN only supports the ARP assist function
2167 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_SET_NO_ENTRIES;
2168 * thus we say EOPNOTSUPP for this ARP function
2170 if (card->info.guestlan)
2172 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
2175 rc = qeth_l3_send_simple_setassparms(card, IPA_ARP_PROCESSING,
2176 IPA_CMD_ASS_ARP_SET_NO_ENTRIES,
2180 QETH_DBF_MESSAGE(2, "Could not set number of ARP entries on "
2181 "%s: %s (0x%x/%d)\n", QETH_CARD_IFNAME(card),
2182 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
2187 static void qeth_l3_copy_arp_entries_stripped(struct qeth_arp_query_info *qinfo,
2188 struct qeth_arp_query_data *qdata, int entry_size,
2195 entry_ptr = (char *)&qdata->data;
2196 uentry_ptr = (char *)(qinfo->udata + qinfo->udata_offset);
2197 for (i = 0; i < qdata->no_entries; ++i) {
2198 /* strip off 32 bytes "media specific information" */
2199 memcpy(uentry_ptr, (entry_ptr + 32), entry_size - 32);
2200 entry_ptr += entry_size;
2201 uentry_ptr += uentry_size;
2205 static int qeth_l3_arp_query_cb(struct qeth_card *card,
2206 struct qeth_reply *reply, unsigned long data)
2208 struct qeth_ipa_cmd *cmd;
2209 struct qeth_arp_query_data *qdata;
2210 struct qeth_arp_query_info *qinfo;
2215 QETH_DBF_TEXT(TRACE, 4, "arpquecb");
2217 qinfo = (struct qeth_arp_query_info *) reply->param;
2218 cmd = (struct qeth_ipa_cmd *) data;
2219 if (cmd->hdr.return_code) {
2220 QETH_DBF_TEXT_(TRACE, 4, "qaer1%i", cmd->hdr.return_code);
2223 if (cmd->data.setassparms.hdr.return_code) {
2224 cmd->hdr.return_code = cmd->data.setassparms.hdr.return_code;
2225 QETH_DBF_TEXT_(TRACE, 4, "qaer2%i", cmd->hdr.return_code);
2228 qdata = &cmd->data.setassparms.data.query_arp;
2229 switch (qdata->reply_bits) {
2231 uentry_size = entry_size = sizeof(struct qeth_arp_qi_entry5);
2232 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES)
2233 uentry_size = sizeof(struct qeth_arp_qi_entry5_short);
2236 /* fall through to default */
2238 /* tr is the same as eth -> entry7 */
2239 uentry_size = entry_size = sizeof(struct qeth_arp_qi_entry7);
2240 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES)
2241 uentry_size = sizeof(struct qeth_arp_qi_entry7_short);
2244 /* check if there is enough room in userspace */
2245 if ((qinfo->udata_len - qinfo->udata_offset) <
2246 qdata->no_entries * uentry_size){
2247 QETH_DBF_TEXT_(TRACE, 4, "qaer3%i", -ENOMEM);
2248 cmd->hdr.return_code = -ENOMEM;
2251 QETH_DBF_TEXT_(TRACE, 4, "anore%i",
2252 cmd->data.setassparms.hdr.number_of_replies);
2253 QETH_DBF_TEXT_(TRACE, 4, "aseqn%i", cmd->data.setassparms.hdr.seq_no);
2254 QETH_DBF_TEXT_(TRACE, 4, "anoen%i", qdata->no_entries);
2256 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES) {
2257 /* strip off "media specific information" */
2258 qeth_l3_copy_arp_entries_stripped(qinfo, qdata, entry_size,
2261 /*copy entries to user buffer*/
2262 memcpy(qinfo->udata + qinfo->udata_offset,
2263 (char *)&qdata->data, qdata->no_entries*uentry_size);
2265 qinfo->no_entries += qdata->no_entries;
2266 qinfo->udata_offset += (qdata->no_entries*uentry_size);
2267 /* check if all replies received ... */
2268 if (cmd->data.setassparms.hdr.seq_no <
2269 cmd->data.setassparms.hdr.number_of_replies)
2271 memcpy(qinfo->udata, &qinfo->no_entries, 4);
2272 /* keep STRIP_ENTRIES flag so the user program can distinguish
2273 * stripped entries from normal ones */
2274 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES)
2275 qdata->reply_bits |= QETH_QARP_STRIP_ENTRIES;
2276 memcpy(qinfo->udata + QETH_QARP_MASK_OFFSET, &qdata->reply_bits, 2);
2280 memcpy(qinfo->udata, &i, 4);
2284 static int qeth_l3_send_ipa_arp_cmd(struct qeth_card *card,
2285 struct qeth_cmd_buffer *iob, int len,
2286 int (*reply_cb)(struct qeth_card *, struct qeth_reply *,
2290 QETH_DBF_TEXT(TRACE, 4, "sendarp");
2292 memcpy(iob->data, IPA_PDU_HEADER, IPA_PDU_HEADER_SIZE);
2293 memcpy(QETH_IPA_CMD_DEST_ADDR(iob->data),
2294 &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
2295 return qeth_send_control_data(card, IPA_PDU_HEADER_SIZE + len, iob,
2296 reply_cb, reply_param);
2299 static int qeth_l3_arp_query(struct qeth_card *card, char __user *udata)
2301 struct qeth_cmd_buffer *iob;
2302 struct qeth_arp_query_info qinfo = {0, };
2306 QETH_DBF_TEXT(TRACE, 3, "arpquery");
2308 if (!qeth_is_supported(card,/*IPA_QUERY_ARP_ADDR_INFO*/
2309 IPA_ARP_PROCESSING)) {
2312 /* get size of userspace buffer and mask_bits -> 6 bytes */
2313 if (copy_from_user(&qinfo, udata, 6))
2315 qinfo.udata = kzalloc(qinfo.udata_len, GFP_KERNEL);
2318 qinfo.udata_offset = QETH_QARP_ENTRIES_OFFSET;
2319 iob = qeth_l3_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
2320 IPA_CMD_ASS_ARP_QUERY_INFO,
2321 sizeof(int), QETH_PROT_IPV4);
2323 rc = qeth_l3_send_ipa_arp_cmd(card, iob,
2324 QETH_SETASS_BASE_LEN+QETH_ARP_CMD_LEN,
2325 qeth_l3_arp_query_cb, (void *)&qinfo);
2328 QETH_DBF_MESSAGE(2, "Error while querying ARP cache on %s: %s "
2329 "(0x%x/%d)\n", QETH_CARD_IFNAME(card),
2330 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
2331 if (copy_to_user(udata, qinfo.udata, 4))
2334 if (copy_to_user(udata, qinfo.udata, qinfo.udata_len))
2341 static int qeth_l3_arp_add_entry(struct qeth_card *card,
2342 struct qeth_arp_cache_entry *entry)
2344 struct qeth_cmd_buffer *iob;
2349 QETH_DBF_TEXT(TRACE, 3, "arpadent");
2352 * currently GuestLAN only supports the ARP assist function
2353 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_ADD_ENTRY;
2354 * thus we say EOPNOTSUPP for this ARP function
2356 if (card->info.guestlan)
2358 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
2362 iob = qeth_l3_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
2363 IPA_CMD_ASS_ARP_ADD_ENTRY,
2364 sizeof(struct qeth_arp_cache_entry),
2366 rc = qeth_l3_send_setassparms(card, iob,
2367 sizeof(struct qeth_arp_cache_entry),
2368 (unsigned long) entry,
2369 qeth_l3_default_setassparms_cb, NULL);
2372 qeth_l3_ipaddr4_to_string((u8 *)entry->ipaddr, buf);
2373 QETH_DBF_MESSAGE(2, "Could not add ARP entry for address %s "
2374 "on %s: %s (0x%x/%d)\n", buf, QETH_CARD_IFNAME(card),
2375 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
2380 static int qeth_l3_arp_remove_entry(struct qeth_card *card,
2381 struct qeth_arp_cache_entry *entry)
2383 struct qeth_cmd_buffer *iob;
2384 char buf[16] = {0, };
2388 QETH_DBF_TEXT(TRACE, 3, "arprment");
2391 * currently GuestLAN only supports the ARP assist function
2392 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_REMOVE_ENTRY;
2393 * thus we say EOPNOTSUPP for this ARP function
2395 if (card->info.guestlan)
2397 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
2400 memcpy(buf, entry, 12);
2401 iob = qeth_l3_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
2402 IPA_CMD_ASS_ARP_REMOVE_ENTRY,
2405 rc = qeth_l3_send_setassparms(card, iob,
2406 12, (unsigned long)buf,
2407 qeth_l3_default_setassparms_cb, NULL);
2411 qeth_l3_ipaddr4_to_string((u8 *)entry->ipaddr, buf);
2412 QETH_DBF_MESSAGE(2, "Could not delete ARP entry for address %s"
2413 " on %s: %s (0x%x/%d)\n", buf, QETH_CARD_IFNAME(card),
2414 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
2419 static int qeth_l3_arp_flush_cache(struct qeth_card *card)
2424 QETH_DBF_TEXT(TRACE, 3, "arpflush");
2427 * currently GuestLAN only supports the ARP assist function
2428 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_FLUSH_CACHE;
2429 * thus we say EOPNOTSUPP for this ARP function
2431 if (card->info.guestlan || (card->info.type == QETH_CARD_TYPE_IQD))
2433 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
2436 rc = qeth_l3_send_simple_setassparms(card, IPA_ARP_PROCESSING,
2437 IPA_CMD_ASS_ARP_FLUSH_CACHE, 0);
2440 QETH_DBF_MESSAGE(2, "Could not flush ARP cache on %s: %s "
2441 "(0x%x/%d)\n", QETH_CARD_IFNAME(card),
2442 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
2447 static int qeth_l3_do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
2449 struct qeth_card *card = dev->ml_priv;
2450 struct qeth_arp_cache_entry arp_entry;
2451 struct mii_ioctl_data *mii_data;
2457 if ((card->state != CARD_STATE_UP) &&
2458 (card->state != CARD_STATE_SOFTSETUP))
2462 case SIOC_QETH_ARP_SET_NO_ENTRIES:
2463 if (!capable(CAP_NET_ADMIN)) {
2467 rc = qeth_l3_arp_set_no_entries(card, rq->ifr_ifru.ifru_ivalue);
2469 case SIOC_QETH_ARP_QUERY_INFO:
2470 if (!capable(CAP_NET_ADMIN)) {
2474 rc = qeth_l3_arp_query(card, rq->ifr_ifru.ifru_data);
2476 case SIOC_QETH_ARP_ADD_ENTRY:
2477 if (!capable(CAP_NET_ADMIN)) {
2481 if (copy_from_user(&arp_entry, rq->ifr_ifru.ifru_data,
2482 sizeof(struct qeth_arp_cache_entry)))
2485 rc = qeth_l3_arp_add_entry(card, &arp_entry);
2487 case SIOC_QETH_ARP_REMOVE_ENTRY:
2488 if (!capable(CAP_NET_ADMIN)) {
2492 if (copy_from_user(&arp_entry, rq->ifr_ifru.ifru_data,
2493 sizeof(struct qeth_arp_cache_entry)))
2496 rc = qeth_l3_arp_remove_entry(card, &arp_entry);
2498 case SIOC_QETH_ARP_FLUSH_CACHE:
2499 if (!capable(CAP_NET_ADMIN)) {
2503 rc = qeth_l3_arp_flush_cache(card);
2505 case SIOC_QETH_ADP_SET_SNMP_CONTROL:
2506 rc = qeth_snmp_command(card, rq->ifr_ifru.ifru_data);
2508 case SIOC_QETH_GET_CARD_TYPE:
2509 if ((card->info.type == QETH_CARD_TYPE_OSAE) &&
2510 !card->info.guestlan)
2515 mii_data = if_mii(rq);
2516 mii_data->phy_id = 0;
2519 mii_data = if_mii(rq);
2520 if (mii_data->phy_id != 0)
2523 mii_data->val_out = qeth_mdio_read(dev,
2531 QETH_DBF_TEXT_(TRACE, 2, "ioce%d", rc);
2535 static void qeth_l3_fill_header(struct qeth_card *card, struct qeth_hdr *hdr,
2536 struct sk_buff *skb, int ipv, int cast_type)
2538 memset(hdr, 0, sizeof(struct qeth_hdr));
2539 hdr->hdr.l3.id = QETH_HEADER_TYPE_LAYER3;
2540 hdr->hdr.l3.ext_flags = 0;
2543 * before we're going to overwrite this location with next hop ip.
2544 * v6 uses passthrough, v4 sets the tag in the QDIO header.
2546 if (card->vlangrp && vlan_tx_tag_present(skb)) {
2547 if ((ipv == 4) || (card->info.type == QETH_CARD_TYPE_IQD))
2548 hdr->hdr.l3.ext_flags = QETH_HDR_EXT_VLAN_FRAME;
2550 hdr->hdr.l3.ext_flags = QETH_HDR_EXT_INCLUDE_VLAN_TAG;
2551 hdr->hdr.l3.vlan_id = vlan_tx_tag_get(skb);
2554 hdr->hdr.l3.length = skb->len - sizeof(struct qeth_hdr);
2557 hdr->hdr.l3.flags = qeth_l3_get_qeth_hdr_flags4(cast_type);
2558 memset(hdr->hdr.l3.dest_addr, 0, 12);
2559 if ((skb->dst) && (skb->dst->neighbour)) {
2560 *((u32 *) (&hdr->hdr.l3.dest_addr[12])) =
2561 *((u32 *) skb->dst->neighbour->primary_key);
2563 /* fill in destination address used in ip header */
2564 *((u32 *) (&hdr->hdr.l3.dest_addr[12])) =
2567 } else if (ipv == 6) {
2569 hdr->hdr.l3.flags = qeth_l3_get_qeth_hdr_flags6(cast_type);
2570 if (card->info.type == QETH_CARD_TYPE_IQD)
2571 hdr->hdr.l3.flags &= ~QETH_HDR_PASSTHRU;
2572 if ((skb->dst) && (skb->dst->neighbour)) {
2573 memcpy(hdr->hdr.l3.dest_addr,
2574 skb->dst->neighbour->primary_key, 16);
2576 /* fill in destination address used in ip header */
2577 memcpy(hdr->hdr.l3.dest_addr,
2578 &ipv6_hdr(skb)->daddr, 16);
2582 if ((skb->dev->type == ARPHRD_IEEE802_TR) &&
2583 !memcmp(skb->data + sizeof(struct qeth_hdr) +
2584 sizeof(__u16), skb->dev->broadcast, 6)) {
2585 hdr->hdr.l3.flags = QETH_CAST_BROADCAST |
2587 } else if (!memcmp(skb->data + sizeof(struct qeth_hdr),
2588 skb->dev->broadcast, 6)) {
2590 hdr->hdr.l3.flags = QETH_CAST_BROADCAST |
2593 hdr->hdr.l3.flags = (cast_type == RTN_MULTICAST) ?
2594 QETH_CAST_MULTICAST | QETH_HDR_PASSTHRU :
2595 QETH_CAST_UNICAST | QETH_HDR_PASSTHRU;
2600 static int qeth_l3_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
2604 struct qeth_hdr *hdr = NULL;
2605 int elements_needed = 0;
2606 struct qeth_card *card = dev->ml_priv;
2607 struct sk_buff *new_skb = NULL;
2608 int ipv = qeth_get_ip_version(skb);
2609 int cast_type = qeth_get_cast_type(card, skb);
2610 struct qeth_qdio_out_q *queue = card->qdio.out_qs
2611 [qeth_get_priority_queue(card, skb, ipv, cast_type)];
2612 int tx_bytes = skb->len;
2613 enum qeth_large_send_types large_send = QETH_LARGE_SEND_NO;
2614 struct qeth_eddp_context *ctx = NULL;
2615 int data_offset = -1;
2617 if ((card->info.type == QETH_CARD_TYPE_IQD) &&
2618 (skb->protocol != htons(ETH_P_IPV6)) &&
2619 (skb->protocol != htons(ETH_P_IP)))
2622 if ((card->state != CARD_STATE_UP) || !card->lan_online) {
2623 card->stats.tx_carrier_errors++;
2627 if ((cast_type == RTN_BROADCAST) &&
2628 (card->info.broadcast_capable == 0))
2631 if (card->options.performance_stats) {
2632 card->perf_stats.outbound_cnt++;
2633 card->perf_stats.outbound_start_time = qeth_get_micros();
2636 if (skb_is_gso(skb))
2637 large_send = card->options.large_send;
2639 if ((card->info.type == QETH_CARD_TYPE_IQD) && (!large_send) &&
2640 (skb_shinfo(skb)->nr_frags == 0)) {
2642 data_offset = ETH_HLEN;
2643 hdr = kmem_cache_alloc(qeth_core_header_cache, GFP_ATOMIC);
2648 /* create a clone with writeable headroom */
2649 new_skb = skb_realloc_headroom(skb, sizeof(struct qeth_hdr_tso)
2655 if (card->info.type == QETH_CARD_TYPE_IQD) {
2656 if (data_offset < 0)
2657 skb_pull(new_skb, ETH_HLEN);
2659 if (new_skb->protocol == htons(ETH_P_IP)) {
2660 if (card->dev->type == ARPHRD_IEEE802_TR)
2661 skb_pull(new_skb, TR_HLEN);
2663 skb_pull(new_skb, ETH_HLEN);
2666 if (new_skb->protocol == ETH_P_IPV6 && card->vlangrp &&
2667 vlan_tx_tag_present(new_skb)) {
2668 skb_push(new_skb, VLAN_HLEN);
2669 skb_copy_to_linear_data(new_skb, new_skb->data + 4, 4);
2670 skb_copy_to_linear_data_offset(new_skb, 4,
2671 new_skb->data + 8, 4);
2672 skb_copy_to_linear_data_offset(new_skb, 8,
2673 new_skb->data + 12, 4);
2674 tag = (u16 *)(new_skb->data + 12);
2675 *tag = __constant_htons(ETH_P_8021Q);
2676 *(tag + 1) = htons(vlan_tx_tag_get(new_skb));
2677 new_skb->vlan_tci = 0;
2681 netif_stop_queue(dev);
2683 /* fix hardware limitation: as long as we do not have sbal
2684 * chaining we can not send long frag lists so we temporary
2687 if ((large_send == QETH_LARGE_SEND_TSO) &&
2688 ((skb_shinfo(new_skb)->nr_frags + 2) > 16))
2689 large_send = QETH_LARGE_SEND_EDDP;
2691 if ((large_send == QETH_LARGE_SEND_TSO) &&
2692 (cast_type == RTN_UNSPEC)) {
2693 hdr = (struct qeth_hdr *)skb_push(new_skb,
2694 sizeof(struct qeth_hdr_tso));
2695 memset(hdr, 0, sizeof(struct qeth_hdr_tso));
2696 qeth_l3_fill_header(card, hdr, new_skb, ipv, cast_type);
2697 qeth_tso_fill_header(card, hdr, new_skb);
2700 if (data_offset < 0) {
2701 hdr = (struct qeth_hdr *)skb_push(new_skb,
2702 sizeof(struct qeth_hdr));
2703 qeth_l3_fill_header(card, hdr, new_skb, ipv,
2706 qeth_l3_fill_header(card, hdr, new_skb, ipv,
2708 hdr->hdr.l3.length = new_skb->len - data_offset;
2712 if (large_send == QETH_LARGE_SEND_EDDP) {
2713 /* new_skb is not owned by a socket so we use skb to get
2716 ctx = qeth_eddp_create_context(card, new_skb, hdr,
2717 skb->sk->sk_protocol);
2719 QETH_DBF_MESSAGE(2, "could not create eddp context\n");
2723 int elems = qeth_get_elements_no(card, (void *)hdr, new_skb,
2726 if (data_offset >= 0)
2727 kmem_cache_free(qeth_core_header_cache, hdr);
2730 elements_needed += elems;
2733 if ((large_send == QETH_LARGE_SEND_NO) &&
2734 (new_skb->ip_summed == CHECKSUM_PARTIAL))
2735 qeth_tx_csum(new_skb);
2737 if (card->info.type != QETH_CARD_TYPE_IQD)
2738 rc = qeth_do_send_packet(card, queue, new_skb, hdr,
2739 elements_needed, ctx);
2741 rc = qeth_do_send_packet_fast(card, queue, new_skb, hdr,
2742 elements_needed, ctx, data_offset, 0);
2745 card->stats.tx_packets++;
2746 card->stats.tx_bytes += tx_bytes;
2748 dev_kfree_skb_any(skb);
2749 if (card->options.performance_stats) {
2750 if (large_send != QETH_LARGE_SEND_NO) {
2751 card->perf_stats.large_send_bytes += tx_bytes;
2752 card->perf_stats.large_send_cnt++;
2754 if (skb_shinfo(new_skb)->nr_frags > 0) {
2755 card->perf_stats.sg_skbs_sent++;
2756 /* nr_frags + skb->data */
2757 card->perf_stats.sg_frags_sent +=
2758 skb_shinfo(new_skb)->nr_frags + 1;
2763 qeth_eddp_put_context(ctx);
2764 dev_kfree_skb_any(new_skb);
2768 qeth_eddp_put_context(ctx);
2770 if (data_offset >= 0)
2771 kmem_cache_free(qeth_core_header_cache, hdr);
2775 dev_kfree_skb_any(new_skb);
2776 return NETDEV_TX_BUSY;
2781 netif_wake_queue(dev);
2782 if (card->options.performance_stats)
2783 card->perf_stats.outbound_time += qeth_get_micros() -
2784 card->perf_stats.outbound_start_time;
2788 card->stats.tx_dropped++;
2789 card->stats.tx_errors++;
2790 if ((new_skb != skb) && new_skb)
2791 dev_kfree_skb_any(new_skb);
2792 dev_kfree_skb_any(skb);
2793 netif_wake_queue(dev);
2794 return NETDEV_TX_OK;
2797 static int qeth_l3_open(struct net_device *dev)
2799 struct qeth_card *card = dev->ml_priv;
2801 QETH_DBF_TEXT(TRACE, 4, "qethopen");
2802 if (card->state != CARD_STATE_SOFTSETUP)
2804 card->data.state = CH_STATE_UP;
2805 card->state = CARD_STATE_UP;
2806 netif_start_queue(dev);
2808 if (!card->lan_online && netif_carrier_ok(dev))
2809 netif_carrier_off(dev);
2813 static int qeth_l3_stop(struct net_device *dev)
2815 struct qeth_card *card = dev->ml_priv;
2817 QETH_DBF_TEXT(TRACE, 4, "qethstop");
2818 netif_tx_disable(dev);
2819 if (card->state == CARD_STATE_UP)
2820 card->state = CARD_STATE_SOFTSETUP;
2824 static u32 qeth_l3_ethtool_get_rx_csum(struct net_device *dev)
2826 struct qeth_card *card = dev->ml_priv;
2828 return (card->options.checksum_type == HW_CHECKSUMMING);
2831 static int qeth_l3_ethtool_set_rx_csum(struct net_device *dev, u32 data)
2833 struct qeth_card *card = dev->ml_priv;
2834 enum qeth_card_states old_state;
2835 enum qeth_checksum_types csum_type;
2837 if ((card->state != CARD_STATE_UP) &&
2838 (card->state != CARD_STATE_DOWN))
2842 csum_type = HW_CHECKSUMMING;
2844 csum_type = SW_CHECKSUMMING;
2846 if (card->options.checksum_type != csum_type) {
2847 old_state = card->state;
2848 if (card->state == CARD_STATE_UP)
2849 __qeth_l3_set_offline(card->gdev, 1);
2850 card->options.checksum_type = csum_type;
2851 if (old_state == CARD_STATE_UP)
2852 __qeth_l3_set_online(card->gdev, 1);
2857 static int qeth_l3_ethtool_set_tso(struct net_device *dev, u32 data)
2859 struct qeth_card *card = dev->ml_priv;
2862 if (card->options.large_send == QETH_LARGE_SEND_NO) {
2863 if (card->info.type == QETH_CARD_TYPE_IQD)
2864 card->options.large_send = QETH_LARGE_SEND_EDDP;
2866 card->options.large_send = QETH_LARGE_SEND_TSO;
2867 dev->features |= NETIF_F_TSO;
2870 dev->features &= ~NETIF_F_TSO;
2871 card->options.large_send = QETH_LARGE_SEND_NO;
2876 static struct ethtool_ops qeth_l3_ethtool_ops = {
2877 .get_link = ethtool_op_get_link,
2878 .get_tx_csum = ethtool_op_get_tx_csum,
2879 .set_tx_csum = ethtool_op_set_tx_hw_csum,
2880 .get_rx_csum = qeth_l3_ethtool_get_rx_csum,
2881 .set_rx_csum = qeth_l3_ethtool_set_rx_csum,
2882 .get_sg = ethtool_op_get_sg,
2883 .set_sg = ethtool_op_set_sg,
2884 .get_tso = ethtool_op_get_tso,
2885 .set_tso = qeth_l3_ethtool_set_tso,
2886 .get_strings = qeth_core_get_strings,
2887 .get_ethtool_stats = qeth_core_get_ethtool_stats,
2888 .get_stats_count = qeth_core_get_stats_count,
2889 .get_drvinfo = qeth_core_get_drvinfo,
2890 .get_settings = qeth_core_ethtool_get_settings,
2894 * we need NOARP for IPv4 but we want neighbor solicitation for IPv6. Setting
2895 * NOARP on the netdevice is no option because it also turns off neighbor
2896 * solicitation. For IPv4 we install a neighbor_setup function. We don't want
2897 * arp resolution but we want the hard header (packet socket will work
2900 static int qeth_l3_neigh_setup_noarp(struct neighbour *n)
2902 n->nud_state = NUD_NOARP;
2903 memcpy(n->ha, "FAKELL", 6);
2904 n->output = n->ops->connected_output;
2909 qeth_l3_neigh_setup(struct net_device *dev, struct neigh_parms *np)
2911 if (np->tbl->family == AF_INET)
2912 np->neigh_setup = qeth_l3_neigh_setup_noarp;
2917 static int qeth_l3_setup_netdev(struct qeth_card *card)
2919 if (card->info.type == QETH_CARD_TYPE_OSAE) {
2920 if ((card->info.link_type == QETH_LINK_TYPE_LANE_TR) ||
2921 (card->info.link_type == QETH_LINK_TYPE_HSTR)) {
2923 card->dev = alloc_trdev(0);
2928 card->dev = alloc_etherdev(0);
2931 card->dev->neigh_setup = qeth_l3_neigh_setup;
2933 /*IPv6 address autoconfiguration stuff*/
2934 qeth_l3_get_unique_id(card);
2935 if (!(card->info.unique_id & UNIQUE_ID_NOT_BY_CARD))
2936 card->dev->dev_id = card->info.unique_id &
2939 } else if (card->info.type == QETH_CARD_TYPE_IQD) {
2940 card->dev = alloc_netdev(0, "hsi%d", ether_setup);
2943 card->dev->flags |= IFF_NOARP;
2944 qeth_l3_iqd_read_initial_mac(card);
2948 card->dev->hard_start_xmit = qeth_l3_hard_start_xmit;
2949 card->dev->ml_priv = card;
2950 card->dev->tx_timeout = &qeth_tx_timeout;
2951 card->dev->watchdog_timeo = QETH_TX_TIMEOUT;
2952 card->dev->open = qeth_l3_open;
2953 card->dev->stop = qeth_l3_stop;
2954 card->dev->do_ioctl = qeth_l3_do_ioctl;
2955 card->dev->get_stats = qeth_get_stats;
2956 card->dev->change_mtu = qeth_change_mtu;
2957 card->dev->set_multicast_list = qeth_l3_set_multicast_list;
2958 card->dev->vlan_rx_register = qeth_l3_vlan_rx_register;
2959 card->dev->vlan_rx_add_vid = qeth_l3_vlan_rx_add_vid;
2960 card->dev->vlan_rx_kill_vid = qeth_l3_vlan_rx_kill_vid;
2961 card->dev->mtu = card->info.initial_mtu;
2962 card->dev->set_mac_address = NULL;
2963 SET_ETHTOOL_OPS(card->dev, &qeth_l3_ethtool_ops);
2964 card->dev->features |= NETIF_F_HW_VLAN_TX |
2965 NETIF_F_HW_VLAN_RX |
2966 NETIF_F_HW_VLAN_FILTER;
2968 SET_NETDEV_DEV(card->dev, &card->gdev->dev);
2969 return register_netdev(card->dev);
2972 static void qeth_l3_qdio_input_handler(struct ccw_device *ccwdev,
2973 unsigned int qdio_err, unsigned int queue, int first_element,
2974 int count, unsigned long card_ptr)
2976 struct net_device *net_dev;
2977 struct qeth_card *card;
2978 struct qeth_qdio_buffer *buffer;
2982 card = (struct qeth_card *) card_ptr;
2983 net_dev = card->dev;
2984 if (card->options.performance_stats) {
2985 card->perf_stats.inbound_cnt++;
2986 card->perf_stats.inbound_start_time = qeth_get_micros();
2988 if (qdio_err & QDIO_ERROR_ACTIVATE_CHECK_CONDITION) {
2989 QETH_DBF_TEXT(TRACE, 1, "qdinchk");
2990 QETH_DBF_TEXT_(TRACE, 1, "%s", CARD_BUS_ID(card));
2991 QETH_DBF_TEXT_(TRACE, 1, "%04X%04X",
2992 first_element, count);
2993 QETH_DBF_TEXT_(TRACE, 1, "%04X", queue);
2994 qeth_schedule_recovery(card);
2997 for (i = first_element; i < (first_element + count); ++i) {
2998 index = i % QDIO_MAX_BUFFERS_PER_Q;
2999 buffer = &card->qdio.in_q->bufs[index];
3001 qeth_check_qdio_errors(buffer->buffer,
3002 qdio_err, "qinerr")))
3003 qeth_l3_process_inbound_buffer(card, buffer, index);
3004 /* clear buffer and give back to hardware */
3005 qeth_put_buffer_pool_entry(card, buffer->pool_entry);
3006 qeth_queue_input_buffer(card, index);
3008 if (card->options.performance_stats)
3009 card->perf_stats.inbound_time += qeth_get_micros() -
3010 card->perf_stats.inbound_start_time;
3013 static int qeth_l3_probe_device(struct ccwgroup_device *gdev)
3015 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3017 qeth_l3_create_device_attributes(&gdev->dev);
3018 card->options.layer2 = 0;
3019 card->discipline.input_handler = (qdio_handler_t *)
3020 qeth_l3_qdio_input_handler;
3021 card->discipline.output_handler = (qdio_handler_t *)
3022 qeth_qdio_output_handler;
3023 card->discipline.recover = qeth_l3_recover;
3027 static void qeth_l3_remove_device(struct ccwgroup_device *cgdev)
3029 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
3031 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
3033 if (cgdev->state == CCWGROUP_ONLINE) {
3034 card->use_hard_stop = 1;
3035 qeth_l3_set_offline(cgdev);
3039 unregister_netdev(card->dev);
3043 qeth_l3_remove_device_attributes(&cgdev->dev);
3044 qeth_l3_clear_ip_list(card, 0, 0);
3045 qeth_l3_clear_ipato_list(card);
3049 static int __qeth_l3_set_online(struct ccwgroup_device *gdev, int recovery_mode)
3051 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3053 enum qeth_card_states recover_flag;
3056 QETH_DBF_TEXT(SETUP, 2, "setonlin");
3057 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
3059 qeth_set_allowed_threads(card, QETH_RECOVER_THREAD, 1);
3061 recover_flag = card->state;
3062 rc = ccw_device_set_online(CARD_RDEV(card));
3064 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
3067 rc = ccw_device_set_online(CARD_WDEV(card));
3069 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
3072 rc = ccw_device_set_online(CARD_DDEV(card));
3074 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
3078 rc = qeth_core_hardsetup_card(card);
3080 QETH_DBF_TEXT_(SETUP, 2, "2err%d", rc);
3084 qeth_l3_query_ipassists(card, QETH_PROT_IPV4);
3086 if (!card->dev && qeth_l3_setup_netdev(card))
3089 card->state = CARD_STATE_HARDSETUP;
3090 qeth_print_status_message(card);
3093 QETH_DBF_TEXT(SETUP, 2, "softsetp");
3095 rc = qeth_send_startlan(card);
3097 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
3099 dev_warn(&card->gdev->dev,
3100 "The LAN is offline\n");
3101 card->lan_online = 0;
3105 card->lan_online = 1;
3106 qeth_set_large_send(card, card->options.large_send);
3108 rc = qeth_l3_setadapter_parms(card);
3110 QETH_DBF_TEXT_(SETUP, 2, "2err%d", rc);
3111 rc = qeth_l3_start_ipassists(card);
3113 QETH_DBF_TEXT_(SETUP, 2, "3err%d", rc);
3114 rc = qeth_l3_setrouting_v4(card);
3116 QETH_DBF_TEXT_(SETUP, 2, "4err%d", rc);
3117 rc = qeth_l3_setrouting_v6(card);
3119 QETH_DBF_TEXT_(SETUP, 2, "5err%d", rc);
3120 netif_tx_disable(card->dev);
3122 rc = qeth_init_qdio_queues(card);
3124 QETH_DBF_TEXT_(SETUP, 2, "6err%d", rc);
3127 card->state = CARD_STATE_SOFTSETUP;
3128 netif_carrier_on(card->dev);
3130 qeth_set_allowed_threads(card, 0xffffffff, 0);
3131 if (recover_flag == CARD_STATE_RECOVER) {
3133 qeth_l3_open(card->dev);
3136 dev_open(card->dev);
3139 qeth_l3_set_multicast_list(card->dev);
3141 /* let user_space know that device is online */
3142 kobject_uevent(&gdev->dev.kobj, KOBJ_CHANGE);
3145 card->use_hard_stop = 1;
3146 qeth_l3_stop_card(card, 0);
3147 ccw_device_set_offline(CARD_DDEV(card));
3148 ccw_device_set_offline(CARD_WDEV(card));
3149 ccw_device_set_offline(CARD_RDEV(card));
3150 if (recover_flag == CARD_STATE_RECOVER)
3151 card->state = CARD_STATE_RECOVER;
3153 card->state = CARD_STATE_DOWN;
3157 static int qeth_l3_set_online(struct ccwgroup_device *gdev)
3159 return __qeth_l3_set_online(gdev, 0);
3162 static int __qeth_l3_set_offline(struct ccwgroup_device *cgdev,
3165 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
3166 int rc = 0, rc2 = 0, rc3 = 0;
3167 enum qeth_card_states recover_flag;
3169 QETH_DBF_TEXT(SETUP, 3, "setoffl");
3170 QETH_DBF_HEX(SETUP, 3, &card, sizeof(void *));
3172 if (card->dev && netif_carrier_ok(card->dev))
3173 netif_carrier_off(card->dev);
3174 recover_flag = card->state;
3175 qeth_l3_stop_card(card, recovery_mode);
3176 rc = ccw_device_set_offline(CARD_DDEV(card));
3177 rc2 = ccw_device_set_offline(CARD_WDEV(card));
3178 rc3 = ccw_device_set_offline(CARD_RDEV(card));
3180 rc = (rc2) ? rc2 : rc3;
3182 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
3183 if (recover_flag == CARD_STATE_UP)
3184 card->state = CARD_STATE_RECOVER;
3185 /* let user_space know that device is offline */
3186 kobject_uevent(&cgdev->dev.kobj, KOBJ_CHANGE);
3190 static int qeth_l3_set_offline(struct ccwgroup_device *cgdev)
3192 return __qeth_l3_set_offline(cgdev, 0);
3195 static int qeth_l3_recover(void *ptr)
3197 struct qeth_card *card;
3200 card = (struct qeth_card *) ptr;
3201 QETH_DBF_TEXT(TRACE, 2, "recover1");
3202 QETH_DBF_HEX(TRACE, 2, &card, sizeof(void *));
3203 if (!qeth_do_run_thread(card, QETH_RECOVER_THREAD))
3205 QETH_DBF_TEXT(TRACE, 2, "recover2");
3206 dev_warn(&card->gdev->dev,
3207 "A recovery process has been started for the device\n");
3208 card->use_hard_stop = 1;
3209 __qeth_l3_set_offline(card->gdev, 1);
3210 rc = __qeth_l3_set_online(card->gdev, 1);
3211 /* don't run another scheduled recovery */
3212 qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD);
3213 qeth_clear_thread_running_bit(card, QETH_RECOVER_THREAD);
3215 dev_info(&card->gdev->dev,
3216 "Device successfully recovered!\n");
3219 dev_close(card->dev);
3221 dev_warn(&card->gdev->dev, "The qeth device driver "
3222 "failed to recover an error on the device\n");
3227 static void qeth_l3_shutdown(struct ccwgroup_device *gdev)
3229 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3230 qeth_l3_clear_ip_list(card, 0, 0);
3231 qeth_qdio_clear_card(card, 0);
3232 qeth_clear_qdio_buffers(card);
3235 struct ccwgroup_driver qeth_l3_ccwgroup_driver = {
3236 .probe = qeth_l3_probe_device,
3237 .remove = qeth_l3_remove_device,
3238 .set_online = qeth_l3_set_online,
3239 .set_offline = qeth_l3_set_offline,
3240 .shutdown = qeth_l3_shutdown,
3242 EXPORT_SYMBOL_GPL(qeth_l3_ccwgroup_driver);
3244 static int qeth_l3_ip_event(struct notifier_block *this,
3245 unsigned long event, void *ptr)
3247 struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;
3248 struct net_device *dev = (struct net_device *)ifa->ifa_dev->dev;
3249 struct qeth_ipaddr *addr;
3250 struct qeth_card *card;
3252 if (dev_net(dev) != &init_net)
3255 QETH_DBF_TEXT(TRACE, 3, "ipevent");
3256 card = qeth_l3_get_card_from_dev(dev);
3260 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
3262 addr->u.a4.addr = ifa->ifa_address;
3263 addr->u.a4.mask = ifa->ifa_mask;
3264 addr->type = QETH_IP_TYPE_NORMAL;
3270 if (!qeth_l3_add_ip(card, addr))
3274 if (!qeth_l3_delete_ip(card, addr))
3280 qeth_l3_set_ip_addr_list(card);
3285 static struct notifier_block qeth_l3_ip_notifier = {
3290 #ifdef CONFIG_QETH_IPV6
3292 * IPv6 event handler
3294 static int qeth_l3_ip6_event(struct notifier_block *this,
3295 unsigned long event, void *ptr)
3297 struct inet6_ifaddr *ifa = (struct inet6_ifaddr *)ptr;
3298 struct net_device *dev = (struct net_device *)ifa->idev->dev;
3299 struct qeth_ipaddr *addr;
3300 struct qeth_card *card;
3302 QETH_DBF_TEXT(TRACE, 3, "ip6event");
3304 card = qeth_l3_get_card_from_dev(dev);
3307 if (!qeth_is_supported(card, IPA_IPV6))
3310 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
3312 memcpy(&addr->u.a6.addr, &ifa->addr, sizeof(struct in6_addr));
3313 addr->u.a6.pfxlen = ifa->prefix_len;
3314 addr->type = QETH_IP_TYPE_NORMAL;
3320 if (!qeth_l3_add_ip(card, addr))
3324 if (!qeth_l3_delete_ip(card, addr))
3330 qeth_l3_set_ip_addr_list(card);
3335 static struct notifier_block qeth_l3_ip6_notifier = {
3341 static int qeth_l3_register_notifiers(void)
3345 QETH_DBF_TEXT(TRACE, 5, "regnotif");
3346 rc = register_inetaddr_notifier(&qeth_l3_ip_notifier);
3349 #ifdef CONFIG_QETH_IPV6
3350 rc = register_inet6addr_notifier(&qeth_l3_ip6_notifier);
3352 unregister_inetaddr_notifier(&qeth_l3_ip_notifier);
3356 pr_warning("There is no IPv6 support for the layer 3 discipline\n");
3361 static void qeth_l3_unregister_notifiers(void)
3364 QETH_DBF_TEXT(TRACE, 5, "unregnot");
3365 BUG_ON(unregister_inetaddr_notifier(&qeth_l3_ip_notifier));
3366 #ifdef CONFIG_QETH_IPV6
3367 BUG_ON(unregister_inet6addr_notifier(&qeth_l3_ip6_notifier));
3368 #endif /* QETH_IPV6 */
3371 static int __init qeth_l3_init(void)
3375 pr_info("register layer 3 discipline\n");
3376 rc = qeth_l3_register_notifiers();
3380 static void __exit qeth_l3_exit(void)
3382 qeth_l3_unregister_notifiers();
3383 pr_info("unregister layer 3 discipline\n");
3386 module_init(qeth_l3_init);
3387 module_exit(qeth_l3_exit);
3388 MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
3389 MODULE_DESCRIPTION("qeth layer 3 discipline");
3390 MODULE_LICENSE("GPL");