Linux 2.6.34-rc3
[pohmelfs.git] / drivers / s390 / net / qeth_l3_main.c
blobb3b6e872d8066e640e6f9d7bea456625fae83760
1 /*
2 * drivers/s390/net/qeth_l3_main.c
4 * Copyright IBM Corp. 2007, 2009
5 * Author(s): Utz Bacher <utz.bacher@de.ibm.com>,
6 * Frank Pavlic <fpavlic@de.ibm.com>,
7 * Thomas Spatzier <tspat@de.ibm.com>,
8 * Frank Blaschka <frank.blaschka@de.ibm.com>
9 */
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>
21 #include <linux/ip.h>
22 #include <linux/ipv6.h>
23 #include <linux/inetdevice.h>
24 #include <linux/igmp.h>
26 #include <net/ip.h>
27 #include <net/arp.h>
28 #include <net/ip6_checksum.h>
30 #include "qeth_l3.h"
32 static int qeth_l3_set_offline(struct ccwgroup_device *);
33 static int qeth_l3_recover(void *);
34 static int qeth_l3_stop(struct net_device *);
35 static void qeth_l3_set_multicast_list(struct net_device *);
36 static int qeth_l3_neigh_setup(struct net_device *, struct neigh_parms *);
37 static int qeth_l3_register_addr_entry(struct qeth_card *,
38 struct qeth_ipaddr *);
39 static int qeth_l3_deregister_addr_entry(struct qeth_card *,
40 struct qeth_ipaddr *);
41 static int __qeth_l3_set_online(struct ccwgroup_device *, int);
42 static int __qeth_l3_set_offline(struct ccwgroup_device *, int);
44 int qeth_l3_set_large_send(struct qeth_card *card,
45 enum qeth_large_send_types type)
47 int rc = 0;
49 card->options.large_send = type;
50 if (card->dev == NULL)
51 return 0;
53 if (card->options.large_send == QETH_LARGE_SEND_TSO) {
54 if (qeth_is_supported(card, IPA_OUTBOUND_TSO)) {
55 card->dev->features |= NETIF_F_TSO | NETIF_F_SG |
56 NETIF_F_HW_CSUM;
57 } else {
58 card->dev->features &= ~(NETIF_F_TSO | NETIF_F_SG |
59 NETIF_F_HW_CSUM);
60 card->options.large_send = QETH_LARGE_SEND_NO;
61 rc = -EOPNOTSUPP;
63 } else {
64 card->dev->features &= ~(NETIF_F_TSO | NETIF_F_SG |
65 NETIF_F_HW_CSUM);
66 card->options.large_send = QETH_LARGE_SEND_NO;
68 return rc;
71 static int qeth_l3_isxdigit(char *buf)
73 while (*buf) {
74 if (!isxdigit(*buf++))
75 return 0;
77 return 1;
80 void qeth_l3_ipaddr4_to_string(const __u8 *addr, char *buf)
82 sprintf(buf, "%i.%i.%i.%i", addr[0], addr[1], addr[2], addr[3]);
85 int qeth_l3_string_to_ipaddr4(const char *buf, __u8 *addr)
87 int count = 0, rc = 0;
88 int in[4];
89 char c;
91 rc = sscanf(buf, "%u.%u.%u.%u%c",
92 &in[0], &in[1], &in[2], &in[3], &c);
93 if (rc != 4 && (rc != 5 || c != '\n'))
94 return -EINVAL;
95 for (count = 0; count < 4; count++) {
96 if (in[count] > 255)
97 return -EINVAL;
98 addr[count] = in[count];
100 return 0;
103 void qeth_l3_ipaddr6_to_string(const __u8 *addr, char *buf)
105 sprintf(buf, "%02x%02x:%02x%02x:%02x%02x:%02x%02x"
106 ":%02x%02x:%02x%02x:%02x%02x:%02x%02x",
107 addr[0], addr[1], addr[2], addr[3],
108 addr[4], addr[5], addr[6], addr[7],
109 addr[8], addr[9], addr[10], addr[11],
110 addr[12], addr[13], addr[14], addr[15]);
113 int qeth_l3_string_to_ipaddr6(const char *buf, __u8 *addr)
115 const char *end, *end_tmp, *start;
116 __u16 *in;
117 char num[5];
118 int num2, cnt, out, found, save_cnt;
119 unsigned short in_tmp[8] = {0, };
121 cnt = out = found = save_cnt = num2 = 0;
122 end = start = buf;
123 in = (__u16 *) addr;
124 memset(in, 0, 16);
125 while (*end) {
126 end = strchr(start, ':');
127 if (end == NULL) {
128 end = buf + strlen(buf);
129 end_tmp = strchr(start, '\n');
130 if (end_tmp != NULL)
131 end = end_tmp;
132 out = 1;
134 if ((end - start)) {
135 memset(num, 0, 5);
136 if ((end - start) > 4)
137 return -EINVAL;
138 memcpy(num, start, end - start);
139 if (!qeth_l3_isxdigit(num))
140 return -EINVAL;
141 sscanf(start, "%x", &num2);
142 if (found)
143 in_tmp[save_cnt++] = num2;
144 else
145 in[cnt++] = num2;
146 if (out)
147 break;
148 } else {
149 if (found)
150 return -EINVAL;
151 found = 1;
153 start = ++end;
155 if (cnt + save_cnt > 8)
156 return -EINVAL;
157 cnt = 7;
158 while (save_cnt)
159 in[cnt--] = in_tmp[--save_cnt];
160 return 0;
163 void qeth_l3_ipaddr_to_string(enum qeth_prot_versions proto, const __u8 *addr,
164 char *buf)
166 if (proto == QETH_PROT_IPV4)
167 qeth_l3_ipaddr4_to_string(addr, buf);
168 else if (proto == QETH_PROT_IPV6)
169 qeth_l3_ipaddr6_to_string(addr, buf);
172 int qeth_l3_string_to_ipaddr(const char *buf, enum qeth_prot_versions proto,
173 __u8 *addr)
175 if (proto == QETH_PROT_IPV4)
176 return qeth_l3_string_to_ipaddr4(buf, addr);
177 else if (proto == QETH_PROT_IPV6)
178 return qeth_l3_string_to_ipaddr6(buf, addr);
179 else
180 return -EINVAL;
183 static void qeth_l3_convert_addr_to_bits(u8 *addr, u8 *bits, int len)
185 int i, j;
186 u8 octet;
188 for (i = 0; i < len; ++i) {
189 octet = addr[i];
190 for (j = 7; j >= 0; --j) {
191 bits[i*8 + j] = octet & 1;
192 octet >>= 1;
197 static int qeth_l3_is_addr_covered_by_ipato(struct qeth_card *card,
198 struct qeth_ipaddr *addr)
200 struct qeth_ipato_entry *ipatoe;
201 u8 addr_bits[128] = {0, };
202 u8 ipatoe_bits[128] = {0, };
203 int rc = 0;
205 if (!card->ipato.enabled)
206 return 0;
208 qeth_l3_convert_addr_to_bits((u8 *) &addr->u, addr_bits,
209 (addr->proto == QETH_PROT_IPV4)? 4:16);
210 list_for_each_entry(ipatoe, &card->ipato.entries, entry) {
211 if (addr->proto != ipatoe->proto)
212 continue;
213 qeth_l3_convert_addr_to_bits(ipatoe->addr, ipatoe_bits,
214 (ipatoe->proto == QETH_PROT_IPV4) ?
215 4 : 16);
216 if (addr->proto == QETH_PROT_IPV4)
217 rc = !memcmp(addr_bits, ipatoe_bits,
218 min(32, ipatoe->mask_bits));
219 else
220 rc = !memcmp(addr_bits, ipatoe_bits,
221 min(128, ipatoe->mask_bits));
222 if (rc)
223 break;
225 /* invert? */
226 if ((addr->proto == QETH_PROT_IPV4) && card->ipato.invert4)
227 rc = !rc;
228 else if ((addr->proto == QETH_PROT_IPV6) && card->ipato.invert6)
229 rc = !rc;
231 return rc;
235 * Add IP to be added to todo list. If there is already an "add todo"
236 * in this list we just incremenent the reference count.
237 * Returns 0 if we just incremented reference count.
239 static int __qeth_l3_insert_ip_todo(struct qeth_card *card,
240 struct qeth_ipaddr *addr, int add)
242 struct qeth_ipaddr *tmp, *t;
243 int found = 0;
245 if (card->options.sniffer)
246 return 0;
247 list_for_each_entry_safe(tmp, t, card->ip_tbd_list, entry) {
248 if ((addr->type == QETH_IP_TYPE_DEL_ALL_MC) &&
249 (tmp->type == QETH_IP_TYPE_DEL_ALL_MC))
250 return 0;
251 if ((tmp->proto == QETH_PROT_IPV4) &&
252 (addr->proto == QETH_PROT_IPV4) &&
253 (tmp->type == addr->type) &&
254 (tmp->is_multicast == addr->is_multicast) &&
255 (tmp->u.a4.addr == addr->u.a4.addr) &&
256 (tmp->u.a4.mask == addr->u.a4.mask)) {
257 found = 1;
258 break;
260 if ((tmp->proto == QETH_PROT_IPV6) &&
261 (addr->proto == QETH_PROT_IPV6) &&
262 (tmp->type == addr->type) &&
263 (tmp->is_multicast == addr->is_multicast) &&
264 (tmp->u.a6.pfxlen == addr->u.a6.pfxlen) &&
265 (memcmp(&tmp->u.a6.addr, &addr->u.a6.addr,
266 sizeof(struct in6_addr)) == 0)) {
267 found = 1;
268 break;
271 if (found) {
272 if (addr->users != 0)
273 tmp->users += addr->users;
274 else
275 tmp->users += add ? 1 : -1;
276 if (tmp->users == 0) {
277 list_del(&tmp->entry);
278 kfree(tmp);
280 return 0;
281 } else {
282 if (addr->type == QETH_IP_TYPE_DEL_ALL_MC)
283 list_add(&addr->entry, card->ip_tbd_list);
284 else {
285 if (addr->users == 0)
286 addr->users += add ? 1 : -1;
287 if (add && (addr->type == QETH_IP_TYPE_NORMAL) &&
288 qeth_l3_is_addr_covered_by_ipato(card, addr)) {
289 QETH_DBF_TEXT(TRACE, 2, "tkovaddr");
290 addr->set_flags |= QETH_IPA_SETIP_TAKEOVER_FLAG;
292 list_add_tail(&addr->entry, card->ip_tbd_list);
294 return 1;
298 static int qeth_l3_delete_ip(struct qeth_card *card, struct qeth_ipaddr *addr)
300 unsigned long flags;
301 int rc = 0;
303 QETH_DBF_TEXT(TRACE, 4, "delip");
305 if (addr->proto == QETH_PROT_IPV4)
306 QETH_DBF_HEX(TRACE, 4, &addr->u.a4.addr, 4);
307 else {
308 QETH_DBF_HEX(TRACE, 4, &addr->u.a6.addr, 8);
309 QETH_DBF_HEX(TRACE, 4, ((char *)&addr->u.a6.addr) + 8, 8);
311 spin_lock_irqsave(&card->ip_lock, flags);
312 rc = __qeth_l3_insert_ip_todo(card, addr, 0);
313 spin_unlock_irqrestore(&card->ip_lock, flags);
314 return rc;
317 static int qeth_l3_add_ip(struct qeth_card *card, struct qeth_ipaddr *addr)
319 unsigned long flags;
320 int rc = 0;
322 QETH_DBF_TEXT(TRACE, 4, "addip");
323 if (addr->proto == QETH_PROT_IPV4)
324 QETH_DBF_HEX(TRACE, 4, &addr->u.a4.addr, 4);
325 else {
326 QETH_DBF_HEX(TRACE, 4, &addr->u.a6.addr, 8);
327 QETH_DBF_HEX(TRACE, 4, ((char *)&addr->u.a6.addr) + 8, 8);
329 spin_lock_irqsave(&card->ip_lock, flags);
330 rc = __qeth_l3_insert_ip_todo(card, addr, 1);
331 spin_unlock_irqrestore(&card->ip_lock, flags);
332 return rc;
336 static struct qeth_ipaddr *qeth_l3_get_addr_buffer(
337 enum qeth_prot_versions prot)
339 struct qeth_ipaddr *addr;
341 addr = kzalloc(sizeof(struct qeth_ipaddr), GFP_ATOMIC);
342 if (addr == NULL) {
343 return NULL;
345 addr->type = QETH_IP_TYPE_NORMAL;
346 addr->proto = prot;
347 return addr;
350 static void qeth_l3_delete_mc_addresses(struct qeth_card *card)
352 struct qeth_ipaddr *iptodo;
353 unsigned long flags;
355 QETH_DBF_TEXT(TRACE, 4, "delmc");
356 iptodo = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
357 if (!iptodo) {
358 QETH_DBF_TEXT(TRACE, 2, "dmcnomem");
359 return;
361 iptodo->type = QETH_IP_TYPE_DEL_ALL_MC;
362 spin_lock_irqsave(&card->ip_lock, flags);
363 if (!__qeth_l3_insert_ip_todo(card, iptodo, 0))
364 kfree(iptodo);
365 spin_unlock_irqrestore(&card->ip_lock, flags);
369 * Add/remove address to/from card's ip list, i.e. try to add or remove
370 * reference to/from an IP address that is already registered on the card.
371 * Returns:
372 * 0 address was on card and its reference count has been adjusted,
373 * but is still > 0, so nothing has to be done
374 * also returns 0 if card was not on card and the todo was to delete
375 * the address -> there is also nothing to be done
376 * 1 address was not on card and the todo is to add it to the card's ip
377 * list
378 * -1 address was on card and its reference count has been decremented
379 * to <= 0 by the todo -> address must be removed from card
381 static int __qeth_l3_ref_ip_on_card(struct qeth_card *card,
382 struct qeth_ipaddr *todo, struct qeth_ipaddr **__addr)
384 struct qeth_ipaddr *addr;
385 int found = 0;
387 list_for_each_entry(addr, &card->ip_list, entry) {
388 if ((addr->proto == QETH_PROT_IPV4) &&
389 (todo->proto == QETH_PROT_IPV4) &&
390 (addr->type == todo->type) &&
391 (addr->u.a4.addr == todo->u.a4.addr) &&
392 (addr->u.a4.mask == todo->u.a4.mask)) {
393 found = 1;
394 break;
396 if ((addr->proto == QETH_PROT_IPV6) &&
397 (todo->proto == QETH_PROT_IPV6) &&
398 (addr->type == todo->type) &&
399 (addr->u.a6.pfxlen == todo->u.a6.pfxlen) &&
400 (memcmp(&addr->u.a6.addr, &todo->u.a6.addr,
401 sizeof(struct in6_addr)) == 0)) {
402 found = 1;
403 break;
406 if (found) {
407 addr->users += todo->users;
408 if (addr->users <= 0) {
409 *__addr = addr;
410 return -1;
411 } else {
412 /* for VIPA and RXIP limit refcount to 1 */
413 if (addr->type != QETH_IP_TYPE_NORMAL)
414 addr->users = 1;
415 return 0;
418 if (todo->users > 0) {
419 /* for VIPA and RXIP limit refcount to 1 */
420 if (todo->type != QETH_IP_TYPE_NORMAL)
421 todo->users = 1;
422 return 1;
423 } else
424 return 0;
427 static void __qeth_l3_delete_all_mc(struct qeth_card *card,
428 unsigned long *flags)
430 struct list_head fail_list;
431 struct qeth_ipaddr *addr, *tmp;
432 int rc;
434 INIT_LIST_HEAD(&fail_list);
435 again:
436 list_for_each_entry_safe(addr, tmp, &card->ip_list, entry) {
437 if (addr->is_multicast) {
438 list_del(&addr->entry);
439 spin_unlock_irqrestore(&card->ip_lock, *flags);
440 rc = qeth_l3_deregister_addr_entry(card, addr);
441 spin_lock_irqsave(&card->ip_lock, *flags);
442 if (!rc || (rc == IPA_RC_MC_ADDR_NOT_FOUND))
443 kfree(addr);
444 else
445 list_add_tail(&addr->entry, &fail_list);
446 goto again;
449 list_splice(&fail_list, &card->ip_list);
452 static void qeth_l3_set_ip_addr_list(struct qeth_card *card)
454 struct list_head *tbd_list;
455 struct qeth_ipaddr *todo, *addr;
456 unsigned long flags;
457 int rc;
459 QETH_DBF_TEXT(TRACE, 2, "sdiplist");
460 QETH_DBF_HEX(TRACE, 2, &card, sizeof(void *));
462 if (card->options.sniffer)
463 return;
464 spin_lock_irqsave(&card->ip_lock, flags);
465 tbd_list = card->ip_tbd_list;
466 card->ip_tbd_list = kmalloc(sizeof(struct list_head), GFP_ATOMIC);
467 if (!card->ip_tbd_list) {
468 QETH_DBF_TEXT(TRACE, 0, "silnomem");
469 card->ip_tbd_list = tbd_list;
470 spin_unlock_irqrestore(&card->ip_lock, flags);
471 return;
472 } else
473 INIT_LIST_HEAD(card->ip_tbd_list);
475 while (!list_empty(tbd_list)) {
476 todo = list_entry(tbd_list->next, struct qeth_ipaddr, entry);
477 list_del(&todo->entry);
478 if (todo->type == QETH_IP_TYPE_DEL_ALL_MC) {
479 __qeth_l3_delete_all_mc(card, &flags);
480 kfree(todo);
481 continue;
483 rc = __qeth_l3_ref_ip_on_card(card, todo, &addr);
484 if (rc == 0) {
485 /* nothing to be done; only adjusted refcount */
486 kfree(todo);
487 } else if (rc == 1) {
488 /* new entry to be added to on-card list */
489 spin_unlock_irqrestore(&card->ip_lock, flags);
490 rc = qeth_l3_register_addr_entry(card, todo);
491 spin_lock_irqsave(&card->ip_lock, flags);
492 if (!rc || (rc == IPA_RC_LAN_OFFLINE))
493 list_add_tail(&todo->entry, &card->ip_list);
494 else
495 kfree(todo);
496 } else if (rc == -1) {
497 /* on-card entry to be removed */
498 list_del_init(&addr->entry);
499 spin_unlock_irqrestore(&card->ip_lock, flags);
500 rc = qeth_l3_deregister_addr_entry(card, addr);
501 spin_lock_irqsave(&card->ip_lock, flags);
502 if (!rc || (rc == IPA_RC_IP_ADDRESS_NOT_DEFINED))
503 kfree(addr);
504 else
505 list_add_tail(&addr->entry, &card->ip_list);
506 kfree(todo);
509 spin_unlock_irqrestore(&card->ip_lock, flags);
510 kfree(tbd_list);
513 static void qeth_l3_clear_ip_list(struct qeth_card *card, int clean,
514 int recover)
516 struct qeth_ipaddr *addr, *tmp;
517 unsigned long flags;
519 QETH_DBF_TEXT(TRACE, 4, "clearip");
520 if (recover && card->options.sniffer)
521 return;
522 spin_lock_irqsave(&card->ip_lock, flags);
523 /* clear todo list */
524 list_for_each_entry_safe(addr, tmp, card->ip_tbd_list, entry) {
525 list_del(&addr->entry);
526 kfree(addr);
529 while (!list_empty(&card->ip_list)) {
530 addr = list_entry(card->ip_list.next,
531 struct qeth_ipaddr, entry);
532 list_del_init(&addr->entry);
533 if (clean) {
534 spin_unlock_irqrestore(&card->ip_lock, flags);
535 qeth_l3_deregister_addr_entry(card, addr);
536 spin_lock_irqsave(&card->ip_lock, flags);
538 if (!recover || addr->is_multicast) {
539 kfree(addr);
540 continue;
542 list_add_tail(&addr->entry, card->ip_tbd_list);
544 spin_unlock_irqrestore(&card->ip_lock, flags);
547 static int qeth_l3_address_exists_in_list(struct list_head *list,
548 struct qeth_ipaddr *addr, int same_type)
550 struct qeth_ipaddr *tmp;
552 list_for_each_entry(tmp, list, entry) {
553 if ((tmp->proto == QETH_PROT_IPV4) &&
554 (addr->proto == QETH_PROT_IPV4) &&
555 ((same_type && (tmp->type == addr->type)) ||
556 (!same_type && (tmp->type != addr->type))) &&
557 (tmp->u.a4.addr == addr->u.a4.addr))
558 return 1;
560 if ((tmp->proto == QETH_PROT_IPV6) &&
561 (addr->proto == QETH_PROT_IPV6) &&
562 ((same_type && (tmp->type == addr->type)) ||
563 (!same_type && (tmp->type != addr->type))) &&
564 (memcmp(&tmp->u.a6.addr, &addr->u.a6.addr,
565 sizeof(struct in6_addr)) == 0))
566 return 1;
569 return 0;
572 static int qeth_l3_send_setdelmc(struct qeth_card *card,
573 struct qeth_ipaddr *addr, int ipacmd)
575 int rc;
576 struct qeth_cmd_buffer *iob;
577 struct qeth_ipa_cmd *cmd;
579 QETH_DBF_TEXT(TRACE, 4, "setdelmc");
581 iob = qeth_get_ipacmd_buffer(card, ipacmd, addr->proto);
582 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
583 memcpy(&cmd->data.setdelipm.mac, addr->mac, OSA_ADDR_LEN);
584 if (addr->proto == QETH_PROT_IPV6)
585 memcpy(cmd->data.setdelipm.ip6, &addr->u.a6.addr,
586 sizeof(struct in6_addr));
587 else
588 memcpy(&cmd->data.setdelipm.ip4, &addr->u.a4.addr, 4);
590 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
592 return rc;
595 static void qeth_l3_fill_netmask(u8 *netmask, unsigned int len)
597 int i, j;
598 for (i = 0; i < 16; i++) {
599 j = (len) - (i * 8);
600 if (j >= 8)
601 netmask[i] = 0xff;
602 else if (j > 0)
603 netmask[i] = (u8)(0xFF00 >> j);
604 else
605 netmask[i] = 0;
609 static int qeth_l3_send_setdelip(struct qeth_card *card,
610 struct qeth_ipaddr *addr, int ipacmd, unsigned int flags)
612 int rc;
613 struct qeth_cmd_buffer *iob;
614 struct qeth_ipa_cmd *cmd;
615 __u8 netmask[16];
617 QETH_DBF_TEXT(TRACE, 4, "setdelip");
618 QETH_DBF_TEXT_(TRACE, 4, "flags%02X", flags);
620 iob = qeth_get_ipacmd_buffer(card, ipacmd, addr->proto);
621 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
622 if (addr->proto == QETH_PROT_IPV6) {
623 memcpy(cmd->data.setdelip6.ip_addr, &addr->u.a6.addr,
624 sizeof(struct in6_addr));
625 qeth_l3_fill_netmask(netmask, addr->u.a6.pfxlen);
626 memcpy(cmd->data.setdelip6.mask, netmask,
627 sizeof(struct in6_addr));
628 cmd->data.setdelip6.flags = flags;
629 } else {
630 memcpy(cmd->data.setdelip4.ip_addr, &addr->u.a4.addr, 4);
631 memcpy(cmd->data.setdelip4.mask, &addr->u.a4.mask, 4);
632 cmd->data.setdelip4.flags = flags;
635 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
637 return rc;
640 static int qeth_l3_send_setrouting(struct qeth_card *card,
641 enum qeth_routing_types type, enum qeth_prot_versions prot)
643 int rc;
644 struct qeth_ipa_cmd *cmd;
645 struct qeth_cmd_buffer *iob;
647 QETH_DBF_TEXT(TRACE, 4, "setroutg");
648 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SETRTG, prot);
649 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
650 cmd->data.setrtg.type = (type);
651 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
653 return rc;
656 static void qeth_l3_correct_routing_type(struct qeth_card *card,
657 enum qeth_routing_types *type, enum qeth_prot_versions prot)
659 if (card->info.type == QETH_CARD_TYPE_IQD) {
660 switch (*type) {
661 case NO_ROUTER:
662 case PRIMARY_CONNECTOR:
663 case SECONDARY_CONNECTOR:
664 case MULTICAST_ROUTER:
665 return;
666 default:
667 goto out_inval;
669 } else {
670 switch (*type) {
671 case NO_ROUTER:
672 case PRIMARY_ROUTER:
673 case SECONDARY_ROUTER:
674 return;
675 case MULTICAST_ROUTER:
676 if (qeth_is_ipafunc_supported(card, prot,
677 IPA_OSA_MC_ROUTER))
678 return;
679 default:
680 goto out_inval;
683 out_inval:
684 *type = NO_ROUTER;
687 int qeth_l3_setrouting_v4(struct qeth_card *card)
689 int rc;
691 QETH_DBF_TEXT(TRACE, 3, "setrtg4");
693 qeth_l3_correct_routing_type(card, &card->options.route4.type,
694 QETH_PROT_IPV4);
696 rc = qeth_l3_send_setrouting(card, card->options.route4.type,
697 QETH_PROT_IPV4);
698 if (rc) {
699 card->options.route4.type = NO_ROUTER;
700 QETH_DBF_MESSAGE(2, "Error (0x%04x) while setting routing type"
701 " on %s. Type set to 'no router'.\n", rc,
702 QETH_CARD_IFNAME(card));
704 return rc;
707 int qeth_l3_setrouting_v6(struct qeth_card *card)
709 int rc = 0;
711 QETH_DBF_TEXT(TRACE, 3, "setrtg6");
712 #ifdef CONFIG_QETH_IPV6
714 if (!qeth_is_supported(card, IPA_IPV6))
715 return 0;
716 qeth_l3_correct_routing_type(card, &card->options.route6.type,
717 QETH_PROT_IPV6);
719 rc = qeth_l3_send_setrouting(card, card->options.route6.type,
720 QETH_PROT_IPV6);
721 if (rc) {
722 card->options.route6.type = NO_ROUTER;
723 QETH_DBF_MESSAGE(2, "Error (0x%04x) while setting routing type"
724 " on %s. Type set to 'no router'.\n", rc,
725 QETH_CARD_IFNAME(card));
727 #endif
728 return rc;
732 * IP address takeover related functions
734 static void qeth_l3_clear_ipato_list(struct qeth_card *card)
737 struct qeth_ipato_entry *ipatoe, *tmp;
738 unsigned long flags;
740 spin_lock_irqsave(&card->ip_lock, flags);
741 list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry) {
742 list_del(&ipatoe->entry);
743 kfree(ipatoe);
745 spin_unlock_irqrestore(&card->ip_lock, flags);
748 int qeth_l3_add_ipato_entry(struct qeth_card *card,
749 struct qeth_ipato_entry *new)
751 struct qeth_ipato_entry *ipatoe;
752 unsigned long flags;
753 int rc = 0;
755 QETH_DBF_TEXT(TRACE, 2, "addipato");
756 spin_lock_irqsave(&card->ip_lock, flags);
757 list_for_each_entry(ipatoe, &card->ipato.entries, entry) {
758 if (ipatoe->proto != new->proto)
759 continue;
760 if (!memcmp(ipatoe->addr, new->addr,
761 (ipatoe->proto == QETH_PROT_IPV4)? 4:16) &&
762 (ipatoe->mask_bits == new->mask_bits)) {
763 rc = -EEXIST;
764 break;
767 if (!rc)
768 list_add_tail(&new->entry, &card->ipato.entries);
770 spin_unlock_irqrestore(&card->ip_lock, flags);
771 return rc;
774 void qeth_l3_del_ipato_entry(struct qeth_card *card,
775 enum qeth_prot_versions proto, u8 *addr, int mask_bits)
777 struct qeth_ipato_entry *ipatoe, *tmp;
778 unsigned long flags;
780 QETH_DBF_TEXT(TRACE, 2, "delipato");
781 spin_lock_irqsave(&card->ip_lock, flags);
782 list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry) {
783 if (ipatoe->proto != proto)
784 continue;
785 if (!memcmp(ipatoe->addr, addr,
786 (proto == QETH_PROT_IPV4)? 4:16) &&
787 (ipatoe->mask_bits == mask_bits)) {
788 list_del(&ipatoe->entry);
789 kfree(ipatoe);
792 spin_unlock_irqrestore(&card->ip_lock, flags);
796 * VIPA related functions
798 int qeth_l3_add_vipa(struct qeth_card *card, enum qeth_prot_versions proto,
799 const u8 *addr)
801 struct qeth_ipaddr *ipaddr;
802 unsigned long flags;
803 int rc = 0;
805 ipaddr = qeth_l3_get_addr_buffer(proto);
806 if (ipaddr) {
807 if (proto == QETH_PROT_IPV4) {
808 QETH_DBF_TEXT(TRACE, 2, "addvipa4");
809 memcpy(&ipaddr->u.a4.addr, addr, 4);
810 ipaddr->u.a4.mask = 0;
811 } else if (proto == QETH_PROT_IPV6) {
812 QETH_DBF_TEXT(TRACE, 2, "addvipa6");
813 memcpy(&ipaddr->u.a6.addr, addr, 16);
814 ipaddr->u.a6.pfxlen = 0;
816 ipaddr->type = QETH_IP_TYPE_VIPA;
817 ipaddr->set_flags = QETH_IPA_SETIP_VIPA_FLAG;
818 ipaddr->del_flags = QETH_IPA_DELIP_VIPA_FLAG;
819 } else
820 return -ENOMEM;
821 spin_lock_irqsave(&card->ip_lock, flags);
822 if (qeth_l3_address_exists_in_list(&card->ip_list, ipaddr, 0) ||
823 qeth_l3_address_exists_in_list(card->ip_tbd_list, ipaddr, 0))
824 rc = -EEXIST;
825 spin_unlock_irqrestore(&card->ip_lock, flags);
826 if (rc) {
827 return rc;
829 if (!qeth_l3_add_ip(card, ipaddr))
830 kfree(ipaddr);
831 qeth_l3_set_ip_addr_list(card);
832 return rc;
835 void qeth_l3_del_vipa(struct qeth_card *card, enum qeth_prot_versions proto,
836 const u8 *addr)
838 struct qeth_ipaddr *ipaddr;
840 ipaddr = qeth_l3_get_addr_buffer(proto);
841 if (ipaddr) {
842 if (proto == QETH_PROT_IPV4) {
843 QETH_DBF_TEXT(TRACE, 2, "delvipa4");
844 memcpy(&ipaddr->u.a4.addr, addr, 4);
845 ipaddr->u.a4.mask = 0;
846 } else if (proto == QETH_PROT_IPV6) {
847 QETH_DBF_TEXT(TRACE, 2, "delvipa6");
848 memcpy(&ipaddr->u.a6.addr, addr, 16);
849 ipaddr->u.a6.pfxlen = 0;
851 ipaddr->type = QETH_IP_TYPE_VIPA;
852 } else
853 return;
854 if (!qeth_l3_delete_ip(card, ipaddr))
855 kfree(ipaddr);
856 qeth_l3_set_ip_addr_list(card);
860 * proxy ARP related functions
862 int qeth_l3_add_rxip(struct qeth_card *card, enum qeth_prot_versions proto,
863 const u8 *addr)
865 struct qeth_ipaddr *ipaddr;
866 unsigned long flags;
867 int rc = 0;
869 ipaddr = qeth_l3_get_addr_buffer(proto);
870 if (ipaddr) {
871 if (proto == QETH_PROT_IPV4) {
872 QETH_DBF_TEXT(TRACE, 2, "addrxip4");
873 memcpy(&ipaddr->u.a4.addr, addr, 4);
874 ipaddr->u.a4.mask = 0;
875 } else if (proto == QETH_PROT_IPV6) {
876 QETH_DBF_TEXT(TRACE, 2, "addrxip6");
877 memcpy(&ipaddr->u.a6.addr, addr, 16);
878 ipaddr->u.a6.pfxlen = 0;
880 ipaddr->type = QETH_IP_TYPE_RXIP;
881 ipaddr->set_flags = QETH_IPA_SETIP_TAKEOVER_FLAG;
882 ipaddr->del_flags = 0;
883 } else
884 return -ENOMEM;
885 spin_lock_irqsave(&card->ip_lock, flags);
886 if (qeth_l3_address_exists_in_list(&card->ip_list, ipaddr, 0) ||
887 qeth_l3_address_exists_in_list(card->ip_tbd_list, ipaddr, 0))
888 rc = -EEXIST;
889 spin_unlock_irqrestore(&card->ip_lock, flags);
890 if (rc) {
891 return rc;
893 if (!qeth_l3_add_ip(card, ipaddr))
894 kfree(ipaddr);
895 qeth_l3_set_ip_addr_list(card);
896 return 0;
899 void qeth_l3_del_rxip(struct qeth_card *card, enum qeth_prot_versions proto,
900 const u8 *addr)
902 struct qeth_ipaddr *ipaddr;
904 ipaddr = qeth_l3_get_addr_buffer(proto);
905 if (ipaddr) {
906 if (proto == QETH_PROT_IPV4) {
907 QETH_DBF_TEXT(TRACE, 2, "addrxip4");
908 memcpy(&ipaddr->u.a4.addr, addr, 4);
909 ipaddr->u.a4.mask = 0;
910 } else if (proto == QETH_PROT_IPV6) {
911 QETH_DBF_TEXT(TRACE, 2, "addrxip6");
912 memcpy(&ipaddr->u.a6.addr, addr, 16);
913 ipaddr->u.a6.pfxlen = 0;
915 ipaddr->type = QETH_IP_TYPE_RXIP;
916 } else
917 return;
918 if (!qeth_l3_delete_ip(card, ipaddr))
919 kfree(ipaddr);
920 qeth_l3_set_ip_addr_list(card);
923 static int qeth_l3_register_addr_entry(struct qeth_card *card,
924 struct qeth_ipaddr *addr)
926 char buf[50];
927 int rc = 0;
928 int cnt = 3;
930 if (addr->proto == QETH_PROT_IPV4) {
931 QETH_DBF_TEXT(TRACE, 2, "setaddr4");
932 QETH_DBF_HEX(TRACE, 3, &addr->u.a4.addr, sizeof(int));
933 } else if (addr->proto == QETH_PROT_IPV6) {
934 QETH_DBF_TEXT(TRACE, 2, "setaddr6");
935 QETH_DBF_HEX(TRACE, 3, &addr->u.a6.addr, 8);
936 QETH_DBF_HEX(TRACE, 3, ((char *)&addr->u.a6.addr) + 8, 8);
937 } else {
938 QETH_DBF_TEXT(TRACE, 2, "setaddr?");
939 QETH_DBF_HEX(TRACE, 3, addr, sizeof(struct qeth_ipaddr));
941 do {
942 if (addr->is_multicast)
943 rc = qeth_l3_send_setdelmc(card, addr, IPA_CMD_SETIPM);
944 else
945 rc = qeth_l3_send_setdelip(card, addr, IPA_CMD_SETIP,
946 addr->set_flags);
947 if (rc)
948 QETH_DBF_TEXT(TRACE, 2, "failed");
949 } while ((--cnt > 0) && rc);
950 if (rc) {
951 QETH_DBF_TEXT(TRACE, 2, "FAILED");
952 qeth_l3_ipaddr_to_string(addr->proto, (u8 *)&addr->u, buf);
953 dev_warn(&card->gdev->dev,
954 "Registering IP address %s failed\n", buf);
956 return rc;
959 static int qeth_l3_deregister_addr_entry(struct qeth_card *card,
960 struct qeth_ipaddr *addr)
962 int rc = 0;
964 if (addr->proto == QETH_PROT_IPV4) {
965 QETH_DBF_TEXT(TRACE, 2, "deladdr4");
966 QETH_DBF_HEX(TRACE, 3, &addr->u.a4.addr, sizeof(int));
967 } else if (addr->proto == QETH_PROT_IPV6) {
968 QETH_DBF_TEXT(TRACE, 2, "deladdr6");
969 QETH_DBF_HEX(TRACE, 3, &addr->u.a6.addr, 8);
970 QETH_DBF_HEX(TRACE, 3, ((char *)&addr->u.a6.addr) + 8, 8);
971 } else {
972 QETH_DBF_TEXT(TRACE, 2, "deladdr?");
973 QETH_DBF_HEX(TRACE, 3, addr, sizeof(struct qeth_ipaddr));
975 if (addr->is_multicast)
976 rc = qeth_l3_send_setdelmc(card, addr, IPA_CMD_DELIPM);
977 else
978 rc = qeth_l3_send_setdelip(card, addr, IPA_CMD_DELIP,
979 addr->del_flags);
980 if (rc)
981 QETH_DBF_TEXT(TRACE, 2, "failed");
983 return rc;
986 static inline u8 qeth_l3_get_qeth_hdr_flags4(int cast_type)
988 if (cast_type == RTN_MULTICAST)
989 return QETH_CAST_MULTICAST;
990 if (cast_type == RTN_BROADCAST)
991 return QETH_CAST_BROADCAST;
992 return QETH_CAST_UNICAST;
995 static inline u8 qeth_l3_get_qeth_hdr_flags6(int cast_type)
997 u8 ct = QETH_HDR_PASSTHRU | QETH_HDR_IPV6;
998 if (cast_type == RTN_MULTICAST)
999 return ct | QETH_CAST_MULTICAST;
1000 if (cast_type == RTN_ANYCAST)
1001 return ct | QETH_CAST_ANYCAST;
1002 if (cast_type == RTN_BROADCAST)
1003 return ct | QETH_CAST_BROADCAST;
1004 return ct | QETH_CAST_UNICAST;
1007 static int qeth_l3_send_setadp_mode(struct qeth_card *card, __u32 command,
1008 __u32 mode)
1010 int rc;
1011 struct qeth_cmd_buffer *iob;
1012 struct qeth_ipa_cmd *cmd;
1014 QETH_DBF_TEXT(TRACE, 4, "adpmode");
1016 iob = qeth_get_adapter_cmd(card, command,
1017 sizeof(struct qeth_ipacmd_setadpparms));
1018 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1019 cmd->data.setadapterparms.data.mode = mode;
1020 rc = qeth_send_ipa_cmd(card, iob, qeth_default_setadapterparms_cb,
1021 NULL);
1022 return rc;
1025 static int qeth_l3_setadapter_hstr(struct qeth_card *card)
1027 int rc;
1029 QETH_DBF_TEXT(TRACE, 4, "adphstr");
1031 if (qeth_adp_supported(card, IPA_SETADP_SET_BROADCAST_MODE)) {
1032 rc = qeth_l3_send_setadp_mode(card,
1033 IPA_SETADP_SET_BROADCAST_MODE,
1034 card->options.broadcast_mode);
1035 if (rc)
1036 QETH_DBF_MESSAGE(2, "couldn't set broadcast mode on "
1037 "device %s: x%x\n",
1038 CARD_BUS_ID(card), rc);
1039 rc = qeth_l3_send_setadp_mode(card,
1040 IPA_SETADP_ALTER_MAC_ADDRESS,
1041 card->options.macaddr_mode);
1042 if (rc)
1043 QETH_DBF_MESSAGE(2, "couldn't set macaddr mode on "
1044 "device %s: x%x\n", CARD_BUS_ID(card), rc);
1045 return rc;
1047 if (card->options.broadcast_mode == QETH_TR_BROADCAST_LOCAL)
1048 QETH_DBF_MESSAGE(2, "set adapter parameters not available "
1049 "to set broadcast mode, using ALLRINGS "
1050 "on device %s:\n", CARD_BUS_ID(card));
1051 if (card->options.macaddr_mode == QETH_TR_MACADDR_CANONICAL)
1052 QETH_DBF_MESSAGE(2, "set adapter parameters not available "
1053 "to set macaddr mode, using NONCANONICAL "
1054 "on device %s:\n", CARD_BUS_ID(card));
1055 return 0;
1058 static int qeth_l3_setadapter_parms(struct qeth_card *card)
1060 int rc;
1062 QETH_DBF_TEXT(SETUP, 2, "setadprm");
1064 if (!qeth_is_supported(card, IPA_SETADAPTERPARMS)) {
1065 dev_info(&card->gdev->dev,
1066 "set adapter parameters not supported.\n");
1067 QETH_DBF_TEXT(SETUP, 2, " notsupp");
1068 return 0;
1070 rc = qeth_query_setadapterparms(card);
1071 if (rc) {
1072 QETH_DBF_MESSAGE(2, "%s couldn't set adapter parameters: "
1073 "0x%x\n", dev_name(&card->gdev->dev), rc);
1074 return rc;
1076 if (qeth_adp_supported(card, IPA_SETADP_ALTER_MAC_ADDRESS)) {
1077 rc = qeth_setadpparms_change_macaddr(card);
1078 if (rc)
1079 dev_warn(&card->gdev->dev, "Reading the adapter MAC"
1080 " address failed\n");
1083 if ((card->info.link_type == QETH_LINK_TYPE_HSTR) ||
1084 (card->info.link_type == QETH_LINK_TYPE_LANE_TR))
1085 rc = qeth_l3_setadapter_hstr(card);
1087 return rc;
1090 static int qeth_l3_default_setassparms_cb(struct qeth_card *card,
1091 struct qeth_reply *reply, unsigned long data)
1093 struct qeth_ipa_cmd *cmd;
1095 QETH_DBF_TEXT(TRACE, 4, "defadpcb");
1097 cmd = (struct qeth_ipa_cmd *) data;
1098 if (cmd->hdr.return_code == 0) {
1099 cmd->hdr.return_code = cmd->data.setassparms.hdr.return_code;
1100 if (cmd->hdr.prot_version == QETH_PROT_IPV4)
1101 card->options.ipa4.enabled_funcs = cmd->hdr.ipa_enabled;
1102 if (cmd->hdr.prot_version == QETH_PROT_IPV6)
1103 card->options.ipa6.enabled_funcs = cmd->hdr.ipa_enabled;
1105 if (cmd->data.setassparms.hdr.assist_no == IPA_INBOUND_CHECKSUM &&
1106 cmd->data.setassparms.hdr.command_code == IPA_CMD_ASS_START) {
1107 card->info.csum_mask = cmd->data.setassparms.data.flags_32bit;
1108 QETH_DBF_TEXT_(TRACE, 3, "csum:%d", card->info.csum_mask);
1110 return 0;
1113 static struct qeth_cmd_buffer *qeth_l3_get_setassparms_cmd(
1114 struct qeth_card *card, enum qeth_ipa_funcs ipa_func, __u16 cmd_code,
1115 __u16 len, enum qeth_prot_versions prot)
1117 struct qeth_cmd_buffer *iob;
1118 struct qeth_ipa_cmd *cmd;
1120 QETH_DBF_TEXT(TRACE, 4, "getasscm");
1121 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SETASSPARMS, prot);
1123 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1124 cmd->data.setassparms.hdr.assist_no = ipa_func;
1125 cmd->data.setassparms.hdr.length = 8 + len;
1126 cmd->data.setassparms.hdr.command_code = cmd_code;
1127 cmd->data.setassparms.hdr.return_code = 0;
1128 cmd->data.setassparms.hdr.seq_no = 0;
1130 return iob;
1133 static int qeth_l3_send_setassparms(struct qeth_card *card,
1134 struct qeth_cmd_buffer *iob, __u16 len, long data,
1135 int (*reply_cb)(struct qeth_card *, struct qeth_reply *,
1136 unsigned long),
1137 void *reply_param)
1139 int rc;
1140 struct qeth_ipa_cmd *cmd;
1142 QETH_DBF_TEXT(TRACE, 4, "sendassp");
1144 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1145 if (len <= sizeof(__u32))
1146 cmd->data.setassparms.data.flags_32bit = (__u32) data;
1147 else /* (len > sizeof(__u32)) */
1148 memcpy(&cmd->data.setassparms.data, (void *) data, len);
1150 rc = qeth_send_ipa_cmd(card, iob, reply_cb, reply_param);
1151 return rc;
1154 #ifdef CONFIG_QETH_IPV6
1155 static int qeth_l3_send_simple_setassparms_ipv6(struct qeth_card *card,
1156 enum qeth_ipa_funcs ipa_func, __u16 cmd_code)
1158 int rc;
1159 struct qeth_cmd_buffer *iob;
1161 QETH_DBF_TEXT(TRACE, 4, "simassp6");
1162 iob = qeth_l3_get_setassparms_cmd(card, ipa_func, cmd_code,
1163 0, QETH_PROT_IPV6);
1164 rc = qeth_l3_send_setassparms(card, iob, 0, 0,
1165 qeth_l3_default_setassparms_cb, NULL);
1166 return rc;
1168 #endif
1170 static int qeth_l3_send_simple_setassparms(struct qeth_card *card,
1171 enum qeth_ipa_funcs ipa_func, __u16 cmd_code, long data)
1173 int rc;
1174 int length = 0;
1175 struct qeth_cmd_buffer *iob;
1177 QETH_DBF_TEXT(TRACE, 4, "simassp4");
1178 if (data)
1179 length = sizeof(__u32);
1180 iob = qeth_l3_get_setassparms_cmd(card, ipa_func, cmd_code,
1181 length, QETH_PROT_IPV4);
1182 rc = qeth_l3_send_setassparms(card, iob, length, data,
1183 qeth_l3_default_setassparms_cb, NULL);
1184 return rc;
1187 static int qeth_l3_start_ipa_arp_processing(struct qeth_card *card)
1189 int rc;
1191 QETH_DBF_TEXT(TRACE, 3, "ipaarp");
1193 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
1194 dev_info(&card->gdev->dev,
1195 "ARP processing not supported on %s!\n",
1196 QETH_CARD_IFNAME(card));
1197 return 0;
1199 rc = qeth_l3_send_simple_setassparms(card, IPA_ARP_PROCESSING,
1200 IPA_CMD_ASS_START, 0);
1201 if (rc) {
1202 dev_warn(&card->gdev->dev,
1203 "Starting ARP processing support for %s failed\n",
1204 QETH_CARD_IFNAME(card));
1206 return rc;
1209 static int qeth_l3_start_ipa_ip_fragmentation(struct qeth_card *card)
1211 int rc;
1213 QETH_DBF_TEXT(TRACE, 3, "ipaipfrg");
1215 if (!qeth_is_supported(card, IPA_IP_FRAGMENTATION)) {
1216 dev_info(&card->gdev->dev,
1217 "Hardware IP fragmentation not supported on %s\n",
1218 QETH_CARD_IFNAME(card));
1219 return -EOPNOTSUPP;
1222 rc = qeth_l3_send_simple_setassparms(card, IPA_IP_FRAGMENTATION,
1223 IPA_CMD_ASS_START, 0);
1224 if (rc) {
1225 dev_warn(&card->gdev->dev,
1226 "Starting IP fragmentation support for %s failed\n",
1227 QETH_CARD_IFNAME(card));
1228 } else
1229 dev_info(&card->gdev->dev,
1230 "Hardware IP fragmentation enabled \n");
1231 return rc;
1234 static int qeth_l3_start_ipa_source_mac(struct qeth_card *card)
1236 int rc;
1238 QETH_DBF_TEXT(TRACE, 3, "stsrcmac");
1240 if (!qeth_is_supported(card, IPA_SOURCE_MAC)) {
1241 dev_info(&card->gdev->dev,
1242 "Inbound source MAC-address not supported on %s\n",
1243 QETH_CARD_IFNAME(card));
1244 return -EOPNOTSUPP;
1247 rc = qeth_l3_send_simple_setassparms(card, IPA_SOURCE_MAC,
1248 IPA_CMD_ASS_START, 0);
1249 if (rc)
1250 dev_warn(&card->gdev->dev,
1251 "Starting source MAC-address support for %s failed\n",
1252 QETH_CARD_IFNAME(card));
1253 return rc;
1256 static int qeth_l3_start_ipa_vlan(struct qeth_card *card)
1258 int rc = 0;
1260 QETH_DBF_TEXT(TRACE, 3, "strtvlan");
1262 if (!qeth_is_supported(card, IPA_FULL_VLAN)) {
1263 dev_info(&card->gdev->dev,
1264 "VLAN not supported on %s\n", QETH_CARD_IFNAME(card));
1265 return -EOPNOTSUPP;
1268 rc = qeth_l3_send_simple_setassparms(card, IPA_VLAN_PRIO,
1269 IPA_CMD_ASS_START, 0);
1270 if (rc) {
1271 dev_warn(&card->gdev->dev,
1272 "Starting VLAN support for %s failed\n",
1273 QETH_CARD_IFNAME(card));
1274 } else {
1275 dev_info(&card->gdev->dev, "VLAN enabled\n");
1277 return rc;
1280 static int qeth_l3_start_ipa_multicast(struct qeth_card *card)
1282 int rc;
1284 QETH_DBF_TEXT(TRACE, 3, "stmcast");
1286 if (!qeth_is_supported(card, IPA_MULTICASTING)) {
1287 dev_info(&card->gdev->dev,
1288 "Multicast not supported on %s\n",
1289 QETH_CARD_IFNAME(card));
1290 return -EOPNOTSUPP;
1293 rc = qeth_l3_send_simple_setassparms(card, IPA_MULTICASTING,
1294 IPA_CMD_ASS_START, 0);
1295 if (rc) {
1296 dev_warn(&card->gdev->dev,
1297 "Starting multicast support for %s failed\n",
1298 QETH_CARD_IFNAME(card));
1299 } else {
1300 dev_info(&card->gdev->dev, "Multicast enabled\n");
1301 card->dev->flags |= IFF_MULTICAST;
1303 return rc;
1306 static int qeth_l3_query_ipassists_cb(struct qeth_card *card,
1307 struct qeth_reply *reply, unsigned long data)
1309 struct qeth_ipa_cmd *cmd;
1311 QETH_DBF_TEXT(SETUP, 2, "qipasscb");
1313 cmd = (struct qeth_ipa_cmd *) data;
1314 if (cmd->hdr.prot_version == QETH_PROT_IPV4) {
1315 card->options.ipa4.supported_funcs = cmd->hdr.ipa_supported;
1316 card->options.ipa4.enabled_funcs = cmd->hdr.ipa_enabled;
1317 } else {
1318 card->options.ipa6.supported_funcs = cmd->hdr.ipa_supported;
1319 card->options.ipa6.enabled_funcs = cmd->hdr.ipa_enabled;
1321 QETH_DBF_TEXT(SETUP, 2, "suppenbl");
1322 QETH_DBF_TEXT_(SETUP, 2, "%x", cmd->hdr.ipa_supported);
1323 QETH_DBF_TEXT_(SETUP, 2, "%x", cmd->hdr.ipa_enabled);
1324 return 0;
1327 static int qeth_l3_query_ipassists(struct qeth_card *card,
1328 enum qeth_prot_versions prot)
1330 int rc;
1331 struct qeth_cmd_buffer *iob;
1333 QETH_DBF_TEXT_(SETUP, 2, "qipassi%i", prot);
1334 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_QIPASSIST, prot);
1335 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_query_ipassists_cb, NULL);
1336 return rc;
1339 #ifdef CONFIG_QETH_IPV6
1340 static int qeth_l3_softsetup_ipv6(struct qeth_card *card)
1342 int rc;
1344 QETH_DBF_TEXT(TRACE, 3, "softipv6");
1346 if (card->info.type == QETH_CARD_TYPE_IQD)
1347 goto out;
1349 rc = qeth_l3_query_ipassists(card, QETH_PROT_IPV6);
1350 if (rc) {
1351 dev_err(&card->gdev->dev,
1352 "Activating IPv6 support for %s failed\n",
1353 QETH_CARD_IFNAME(card));
1354 return rc;
1356 rc = qeth_l3_send_simple_setassparms(card, IPA_IPV6,
1357 IPA_CMD_ASS_START, 3);
1358 if (rc) {
1359 dev_err(&card->gdev->dev,
1360 "Activating IPv6 support for %s failed\n",
1361 QETH_CARD_IFNAME(card));
1362 return rc;
1364 rc = qeth_l3_send_simple_setassparms_ipv6(card, IPA_IPV6,
1365 IPA_CMD_ASS_START);
1366 if (rc) {
1367 dev_err(&card->gdev->dev,
1368 "Activating IPv6 support for %s failed\n",
1369 QETH_CARD_IFNAME(card));
1370 return rc;
1372 rc = qeth_l3_send_simple_setassparms_ipv6(card, IPA_PASSTHRU,
1373 IPA_CMD_ASS_START);
1374 if (rc) {
1375 dev_warn(&card->gdev->dev,
1376 "Enabling the passthrough mode for %s failed\n",
1377 QETH_CARD_IFNAME(card));
1378 return rc;
1380 out:
1381 dev_info(&card->gdev->dev, "IPV6 enabled\n");
1382 return 0;
1384 #endif
1386 static int qeth_l3_start_ipa_ipv6(struct qeth_card *card)
1388 int rc = 0;
1390 QETH_DBF_TEXT(TRACE, 3, "strtipv6");
1392 if (!qeth_is_supported(card, IPA_IPV6)) {
1393 dev_info(&card->gdev->dev,
1394 "IPv6 not supported on %s\n", QETH_CARD_IFNAME(card));
1395 return 0;
1397 #ifdef CONFIG_QETH_IPV6
1398 rc = qeth_l3_softsetup_ipv6(card);
1399 #endif
1400 return rc ;
1403 static int qeth_l3_start_ipa_broadcast(struct qeth_card *card)
1405 int rc;
1407 QETH_DBF_TEXT(TRACE, 3, "stbrdcst");
1408 card->info.broadcast_capable = 0;
1409 if (!qeth_is_supported(card, IPA_FILTERING)) {
1410 dev_info(&card->gdev->dev,
1411 "Broadcast not supported on %s\n",
1412 QETH_CARD_IFNAME(card));
1413 rc = -EOPNOTSUPP;
1414 goto out;
1416 rc = qeth_l3_send_simple_setassparms(card, IPA_FILTERING,
1417 IPA_CMD_ASS_START, 0);
1418 if (rc) {
1419 dev_warn(&card->gdev->dev, "Enabling broadcast filtering for "
1420 "%s failed\n", QETH_CARD_IFNAME(card));
1421 goto out;
1424 rc = qeth_l3_send_simple_setassparms(card, IPA_FILTERING,
1425 IPA_CMD_ASS_CONFIGURE, 1);
1426 if (rc) {
1427 dev_warn(&card->gdev->dev,
1428 "Setting up broadcast filtering for %s failed\n",
1429 QETH_CARD_IFNAME(card));
1430 goto out;
1432 card->info.broadcast_capable = QETH_BROADCAST_WITH_ECHO;
1433 dev_info(&card->gdev->dev, "Broadcast enabled\n");
1434 rc = qeth_l3_send_simple_setassparms(card, IPA_FILTERING,
1435 IPA_CMD_ASS_ENABLE, 1);
1436 if (rc) {
1437 dev_warn(&card->gdev->dev, "Setting up broadcast echo "
1438 "filtering for %s failed\n", QETH_CARD_IFNAME(card));
1439 goto out;
1441 card->info.broadcast_capable = QETH_BROADCAST_WITHOUT_ECHO;
1442 out:
1443 if (card->info.broadcast_capable)
1444 card->dev->flags |= IFF_BROADCAST;
1445 else
1446 card->dev->flags &= ~IFF_BROADCAST;
1447 return rc;
1450 static int qeth_l3_send_checksum_command(struct qeth_card *card)
1452 int rc;
1454 rc = qeth_l3_send_simple_setassparms(card, IPA_INBOUND_CHECKSUM,
1455 IPA_CMD_ASS_START, 0);
1456 if (rc) {
1457 dev_warn(&card->gdev->dev, "Starting HW checksumming for %s "
1458 "failed, using SW checksumming\n",
1459 QETH_CARD_IFNAME(card));
1460 return rc;
1462 rc = qeth_l3_send_simple_setassparms(card, IPA_INBOUND_CHECKSUM,
1463 IPA_CMD_ASS_ENABLE,
1464 card->info.csum_mask);
1465 if (rc) {
1466 dev_warn(&card->gdev->dev, "Enabling HW checksumming for %s "
1467 "failed, using SW checksumming\n",
1468 QETH_CARD_IFNAME(card));
1469 return rc;
1471 return 0;
1474 int qeth_l3_set_rx_csum(struct qeth_card *card,
1475 enum qeth_checksum_types csum_type)
1477 int rc = 0;
1479 if (card->options.checksum_type == HW_CHECKSUMMING) {
1480 if ((csum_type != HW_CHECKSUMMING) &&
1481 (card->state != CARD_STATE_DOWN)) {
1482 rc = qeth_l3_send_simple_setassparms(card,
1483 IPA_INBOUND_CHECKSUM, IPA_CMD_ASS_STOP, 0);
1484 if (rc)
1485 return -EIO;
1487 } else {
1488 if (csum_type == HW_CHECKSUMMING) {
1489 if (card->state != CARD_STATE_DOWN) {
1490 if (!qeth_is_supported(card,
1491 IPA_INBOUND_CHECKSUM))
1492 return -EPERM;
1493 rc = qeth_l3_send_checksum_command(card);
1494 if (rc)
1495 return -EIO;
1499 card->options.checksum_type = csum_type;
1500 return rc;
1503 static int qeth_l3_start_ipa_checksum(struct qeth_card *card)
1505 int rc = 0;
1507 QETH_DBF_TEXT(TRACE, 3, "strtcsum");
1509 if (card->options.checksum_type == NO_CHECKSUMMING) {
1510 dev_info(&card->gdev->dev,
1511 "Using no checksumming on %s.\n",
1512 QETH_CARD_IFNAME(card));
1513 return 0;
1515 if (card->options.checksum_type == SW_CHECKSUMMING) {
1516 dev_info(&card->gdev->dev,
1517 "Using SW checksumming on %s.\n",
1518 QETH_CARD_IFNAME(card));
1519 return 0;
1521 if (!qeth_is_supported(card, IPA_INBOUND_CHECKSUM)) {
1522 dev_info(&card->gdev->dev,
1523 "Inbound HW Checksumming not "
1524 "supported on %s,\ncontinuing "
1525 "using Inbound SW Checksumming\n",
1526 QETH_CARD_IFNAME(card));
1527 card->options.checksum_type = SW_CHECKSUMMING;
1528 return 0;
1530 rc = qeth_l3_send_checksum_command(card);
1531 if (!rc)
1532 dev_info(&card->gdev->dev,
1533 "HW Checksumming (inbound) enabled\n");
1535 return rc;
1538 static int qeth_l3_start_ipa_tso(struct qeth_card *card)
1540 int rc;
1542 QETH_DBF_TEXT(TRACE, 3, "sttso");
1544 if (!qeth_is_supported(card, IPA_OUTBOUND_TSO)) {
1545 dev_info(&card->gdev->dev,
1546 "Outbound TSO not supported on %s\n",
1547 QETH_CARD_IFNAME(card));
1548 rc = -EOPNOTSUPP;
1549 } else {
1550 rc = qeth_l3_send_simple_setassparms(card, IPA_OUTBOUND_TSO,
1551 IPA_CMD_ASS_START, 0);
1552 if (rc)
1553 dev_warn(&card->gdev->dev, "Starting outbound TCP "
1554 "segmentation offload for %s failed\n",
1555 QETH_CARD_IFNAME(card));
1556 else
1557 dev_info(&card->gdev->dev,
1558 "Outbound TSO enabled\n");
1560 if (rc && (card->options.large_send == QETH_LARGE_SEND_TSO)) {
1561 card->options.large_send = QETH_LARGE_SEND_NO;
1562 card->dev->features &= ~(NETIF_F_TSO | NETIF_F_SG);
1564 return rc;
1567 static int qeth_l3_start_ipassists(struct qeth_card *card)
1569 QETH_DBF_TEXT(TRACE, 3, "strtipas");
1571 qeth_set_access_ctrl_online(card); /* go on*/
1572 qeth_l3_start_ipa_arp_processing(card); /* go on*/
1573 qeth_l3_start_ipa_ip_fragmentation(card); /* go on*/
1574 qeth_l3_start_ipa_source_mac(card); /* go on*/
1575 qeth_l3_start_ipa_vlan(card); /* go on*/
1576 qeth_l3_start_ipa_multicast(card); /* go on*/
1577 qeth_l3_start_ipa_ipv6(card); /* go on*/
1578 qeth_l3_start_ipa_broadcast(card); /* go on*/
1579 qeth_l3_start_ipa_checksum(card); /* go on*/
1580 qeth_l3_start_ipa_tso(card); /* go on*/
1581 return 0;
1584 static int qeth_l3_put_unique_id(struct qeth_card *card)
1587 int rc = 0;
1588 struct qeth_cmd_buffer *iob;
1589 struct qeth_ipa_cmd *cmd;
1591 QETH_DBF_TEXT(TRACE, 2, "puniqeid");
1593 if ((card->info.unique_id & UNIQUE_ID_NOT_BY_CARD) ==
1594 UNIQUE_ID_NOT_BY_CARD)
1595 return -1;
1596 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_DESTROY_ADDR,
1597 QETH_PROT_IPV6);
1598 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1599 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
1600 card->info.unique_id;
1601 memcpy(&cmd->data.create_destroy_addr.unique_id[0],
1602 card->dev->dev_addr, OSA_ADDR_LEN);
1603 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
1604 return rc;
1607 static int qeth_l3_iqd_read_initial_mac_cb(struct qeth_card *card,
1608 struct qeth_reply *reply, unsigned long data)
1610 struct qeth_ipa_cmd *cmd;
1612 cmd = (struct qeth_ipa_cmd *) data;
1613 if (cmd->hdr.return_code == 0)
1614 memcpy(card->dev->dev_addr,
1615 cmd->data.create_destroy_addr.unique_id, ETH_ALEN);
1616 else
1617 random_ether_addr(card->dev->dev_addr);
1619 return 0;
1622 static int qeth_l3_iqd_read_initial_mac(struct qeth_card *card)
1624 int rc = 0;
1625 struct qeth_cmd_buffer *iob;
1626 struct qeth_ipa_cmd *cmd;
1628 QETH_DBF_TEXT(SETUP, 2, "hsrmac");
1630 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_CREATE_ADDR,
1631 QETH_PROT_IPV6);
1632 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1633 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
1634 card->info.unique_id;
1636 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_iqd_read_initial_mac_cb,
1637 NULL);
1638 return rc;
1641 static int qeth_l3_get_unique_id_cb(struct qeth_card *card,
1642 struct qeth_reply *reply, unsigned long data)
1644 struct qeth_ipa_cmd *cmd;
1646 cmd = (struct qeth_ipa_cmd *) data;
1647 if (cmd->hdr.return_code == 0)
1648 card->info.unique_id = *((__u16 *)
1649 &cmd->data.create_destroy_addr.unique_id[6]);
1650 else {
1651 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
1652 UNIQUE_ID_NOT_BY_CARD;
1653 dev_warn(&card->gdev->dev, "The network adapter failed to "
1654 "generate a unique ID\n");
1656 return 0;
1659 static int qeth_l3_get_unique_id(struct qeth_card *card)
1661 int rc = 0;
1662 struct qeth_cmd_buffer *iob;
1663 struct qeth_ipa_cmd *cmd;
1665 QETH_DBF_TEXT(SETUP, 2, "guniqeid");
1667 if (!qeth_is_supported(card, IPA_IPV6)) {
1668 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
1669 UNIQUE_ID_NOT_BY_CARD;
1670 return 0;
1673 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_CREATE_ADDR,
1674 QETH_PROT_IPV6);
1675 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1676 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
1677 card->info.unique_id;
1679 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_get_unique_id_cb, NULL);
1680 return rc;
1683 static int
1684 qeth_diags_trace_cb(struct qeth_card *card, struct qeth_reply *reply,
1685 unsigned long data)
1687 struct qeth_ipa_cmd *cmd;
1688 __u16 rc;
1690 QETH_DBF_TEXT(SETUP, 2, "diastrcb");
1692 cmd = (struct qeth_ipa_cmd *)data;
1693 rc = cmd->hdr.return_code;
1694 if (rc)
1695 QETH_DBF_TEXT_(TRACE, 2, "dxter%x", rc);
1696 switch (cmd->data.diagass.action) {
1697 case QETH_DIAGS_CMD_TRACE_QUERY:
1698 break;
1699 case QETH_DIAGS_CMD_TRACE_DISABLE:
1700 switch (rc) {
1701 case 0:
1702 case IPA_RC_INVALID_SUBCMD:
1703 card->info.promisc_mode = SET_PROMISC_MODE_OFF;
1704 dev_info(&card->gdev->dev, "The HiperSockets network "
1705 "traffic analyzer is deactivated\n");
1706 break;
1707 default:
1708 break;
1710 break;
1711 case QETH_DIAGS_CMD_TRACE_ENABLE:
1712 switch (rc) {
1713 case 0:
1714 card->info.promisc_mode = SET_PROMISC_MODE_ON;
1715 dev_info(&card->gdev->dev, "The HiperSockets network "
1716 "traffic analyzer is activated\n");
1717 break;
1718 case IPA_RC_HARDWARE_AUTH_ERROR:
1719 dev_warn(&card->gdev->dev, "The device is not "
1720 "authorized to run as a HiperSockets network "
1721 "traffic analyzer\n");
1722 break;
1723 case IPA_RC_TRACE_ALREADY_ACTIVE:
1724 dev_warn(&card->gdev->dev, "A HiperSockets "
1725 "network traffic analyzer is already "
1726 "active in the HiperSockets LAN\n");
1727 break;
1728 default:
1729 break;
1731 break;
1732 default:
1733 QETH_DBF_MESSAGE(2, "Unknown sniffer action (0x%04x) on %s\n",
1734 cmd->data.diagass.action, QETH_CARD_IFNAME(card));
1737 return 0;
1740 static int
1741 qeth_diags_trace(struct qeth_card *card, enum qeth_diags_trace_cmds diags_cmd)
1743 struct qeth_cmd_buffer *iob;
1744 struct qeth_ipa_cmd *cmd;
1746 QETH_DBF_TEXT(SETUP, 2, "diagtrac");
1748 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SET_DIAG_ASS, 0);
1749 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1750 cmd->data.diagass.subcmd_len = 16;
1751 cmd->data.diagass.subcmd = QETH_DIAGS_CMD_TRACE;
1752 cmd->data.diagass.type = QETH_DIAGS_TYPE_HIPERSOCKET;
1753 cmd->data.diagass.action = diags_cmd;
1754 return qeth_send_ipa_cmd(card, iob, qeth_diags_trace_cb, NULL);
1757 static void qeth_l3_get_mac_for_ipm(__u32 ipm, char *mac,
1758 struct net_device *dev)
1760 if (dev->type == ARPHRD_IEEE802_TR)
1761 ip_tr_mc_map(ipm, mac);
1762 else
1763 ip_eth_mc_map(ipm, mac);
1766 static void qeth_l3_add_mc(struct qeth_card *card, struct in_device *in4_dev)
1768 struct qeth_ipaddr *ipm;
1769 struct ip_mc_list *im4;
1770 char buf[MAX_ADDR_LEN];
1772 QETH_DBF_TEXT(TRACE, 4, "addmc");
1773 for (im4 = in4_dev->mc_list; im4; im4 = im4->next) {
1774 qeth_l3_get_mac_for_ipm(im4->multiaddr, buf, in4_dev->dev);
1775 ipm = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
1776 if (!ipm)
1777 continue;
1778 ipm->u.a4.addr = im4->multiaddr;
1779 memcpy(ipm->mac, buf, OSA_ADDR_LEN);
1780 ipm->is_multicast = 1;
1781 if (!qeth_l3_add_ip(card, ipm))
1782 kfree(ipm);
1786 static void qeth_l3_add_vlan_mc(struct qeth_card *card)
1788 struct in_device *in_dev;
1789 struct vlan_group *vg;
1790 int i;
1792 QETH_DBF_TEXT(TRACE, 4, "addmcvl");
1793 if (!qeth_is_supported(card, IPA_FULL_VLAN) || (card->vlangrp == NULL))
1794 return;
1796 vg = card->vlangrp;
1797 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
1798 struct net_device *netdev = vlan_group_get_device(vg, i);
1799 if (netdev == NULL ||
1800 !(netdev->flags & IFF_UP))
1801 continue;
1802 in_dev = in_dev_get(netdev);
1803 if (!in_dev)
1804 continue;
1805 read_lock(&in_dev->mc_list_lock);
1806 qeth_l3_add_mc(card, in_dev);
1807 read_unlock(&in_dev->mc_list_lock);
1808 in_dev_put(in_dev);
1812 static void qeth_l3_add_multicast_ipv4(struct qeth_card *card)
1814 struct in_device *in4_dev;
1816 QETH_DBF_TEXT(TRACE, 4, "chkmcv4");
1817 in4_dev = in_dev_get(card->dev);
1818 if (in4_dev == NULL)
1819 return;
1820 read_lock(&in4_dev->mc_list_lock);
1821 qeth_l3_add_mc(card, in4_dev);
1822 qeth_l3_add_vlan_mc(card);
1823 read_unlock(&in4_dev->mc_list_lock);
1824 in_dev_put(in4_dev);
1827 #ifdef CONFIG_QETH_IPV6
1828 static void qeth_l3_add_mc6(struct qeth_card *card, struct inet6_dev *in6_dev)
1830 struct qeth_ipaddr *ipm;
1831 struct ifmcaddr6 *im6;
1832 char buf[MAX_ADDR_LEN];
1834 QETH_DBF_TEXT(TRACE, 4, "addmc6");
1835 for (im6 = in6_dev->mc_list; im6 != NULL; im6 = im6->next) {
1836 ndisc_mc_map(&im6->mca_addr, buf, in6_dev->dev, 0);
1837 ipm = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
1838 if (!ipm)
1839 continue;
1840 ipm->is_multicast = 1;
1841 memcpy(ipm->mac, buf, OSA_ADDR_LEN);
1842 memcpy(&ipm->u.a6.addr, &im6->mca_addr.s6_addr,
1843 sizeof(struct in6_addr));
1844 if (!qeth_l3_add_ip(card, ipm))
1845 kfree(ipm);
1849 static void qeth_l3_add_vlan_mc6(struct qeth_card *card)
1851 struct inet6_dev *in_dev;
1852 struct vlan_group *vg;
1853 int i;
1855 QETH_DBF_TEXT(TRACE, 4, "admc6vl");
1856 if (!qeth_is_supported(card, IPA_FULL_VLAN) || (card->vlangrp == NULL))
1857 return;
1859 vg = card->vlangrp;
1860 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
1861 struct net_device *netdev = vlan_group_get_device(vg, i);
1862 if (netdev == NULL ||
1863 !(netdev->flags & IFF_UP))
1864 continue;
1865 in_dev = in6_dev_get(netdev);
1866 if (!in_dev)
1867 continue;
1868 read_lock_bh(&in_dev->lock);
1869 qeth_l3_add_mc6(card, in_dev);
1870 read_unlock_bh(&in_dev->lock);
1871 in6_dev_put(in_dev);
1875 static void qeth_l3_add_multicast_ipv6(struct qeth_card *card)
1877 struct inet6_dev *in6_dev;
1879 QETH_DBF_TEXT(TRACE, 4, "chkmcv6");
1880 if (!qeth_is_supported(card, IPA_IPV6))
1881 return ;
1882 in6_dev = in6_dev_get(card->dev);
1883 if (in6_dev == NULL)
1884 return;
1885 read_lock_bh(&in6_dev->lock);
1886 qeth_l3_add_mc6(card, in6_dev);
1887 qeth_l3_add_vlan_mc6(card);
1888 read_unlock_bh(&in6_dev->lock);
1889 in6_dev_put(in6_dev);
1891 #endif /* CONFIG_QETH_IPV6 */
1893 static void qeth_l3_free_vlan_addresses4(struct qeth_card *card,
1894 unsigned short vid)
1896 struct in_device *in_dev;
1897 struct in_ifaddr *ifa;
1898 struct qeth_ipaddr *addr;
1900 QETH_DBF_TEXT(TRACE, 4, "frvaddr4");
1902 in_dev = in_dev_get(vlan_group_get_device(card->vlangrp, vid));
1903 if (!in_dev)
1904 return;
1905 for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
1906 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
1907 if (addr) {
1908 addr->u.a4.addr = ifa->ifa_address;
1909 addr->u.a4.mask = ifa->ifa_mask;
1910 addr->type = QETH_IP_TYPE_NORMAL;
1911 if (!qeth_l3_delete_ip(card, addr))
1912 kfree(addr);
1915 in_dev_put(in_dev);
1918 static void qeth_l3_free_vlan_addresses6(struct qeth_card *card,
1919 unsigned short vid)
1921 #ifdef CONFIG_QETH_IPV6
1922 struct inet6_dev *in6_dev;
1923 struct inet6_ifaddr *ifa;
1924 struct qeth_ipaddr *addr;
1926 QETH_DBF_TEXT(TRACE, 4, "frvaddr6");
1928 in6_dev = in6_dev_get(vlan_group_get_device(card->vlangrp, vid));
1929 if (!in6_dev)
1930 return;
1931 for (ifa = in6_dev->addr_list; ifa; ifa = ifa->lst_next) {
1932 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
1933 if (addr) {
1934 memcpy(&addr->u.a6.addr, &ifa->addr,
1935 sizeof(struct in6_addr));
1936 addr->u.a6.pfxlen = ifa->prefix_len;
1937 addr->type = QETH_IP_TYPE_NORMAL;
1938 if (!qeth_l3_delete_ip(card, addr))
1939 kfree(addr);
1942 in6_dev_put(in6_dev);
1943 #endif /* CONFIG_QETH_IPV6 */
1946 static void qeth_l3_free_vlan_addresses(struct qeth_card *card,
1947 unsigned short vid)
1949 if (!card->vlangrp)
1950 return;
1951 qeth_l3_free_vlan_addresses4(card, vid);
1952 qeth_l3_free_vlan_addresses6(card, vid);
1955 static void qeth_l3_vlan_rx_register(struct net_device *dev,
1956 struct vlan_group *grp)
1958 struct qeth_card *card = dev->ml_priv;
1959 unsigned long flags;
1961 QETH_DBF_TEXT(TRACE, 4, "vlanreg");
1962 spin_lock_irqsave(&card->vlanlock, flags);
1963 card->vlangrp = grp;
1964 spin_unlock_irqrestore(&card->vlanlock, flags);
1967 static void qeth_l3_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
1969 return;
1972 static void qeth_l3_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
1974 struct qeth_card *card = dev->ml_priv;
1975 unsigned long flags;
1977 QETH_DBF_TEXT_(TRACE, 4, "kid:%d", vid);
1978 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
1979 QETH_DBF_TEXT(TRACE, 3, "kidREC");
1980 return;
1982 spin_lock_irqsave(&card->vlanlock, flags);
1983 /* unregister IP addresses of vlan device */
1984 qeth_l3_free_vlan_addresses(card, vid);
1985 vlan_group_set_device(card->vlangrp, vid, NULL);
1986 spin_unlock_irqrestore(&card->vlanlock, flags);
1987 qeth_l3_set_multicast_list(card->dev);
1990 static inline __u16 qeth_l3_rebuild_skb(struct qeth_card *card,
1991 struct sk_buff *skb, struct qeth_hdr *hdr)
1993 unsigned short vlan_id = 0;
1994 __be16 prot;
1995 struct iphdr *ip_hdr;
1996 unsigned char tg_addr[MAX_ADDR_LEN];
1998 if (!(hdr->hdr.l3.flags & QETH_HDR_PASSTHRU)) {
1999 prot = htons((hdr->hdr.l3.flags & QETH_HDR_IPV6)? ETH_P_IPV6 :
2000 ETH_P_IP);
2001 switch (hdr->hdr.l3.flags & QETH_HDR_CAST_MASK) {
2002 case QETH_CAST_MULTICAST:
2003 switch (prot) {
2004 #ifdef CONFIG_QETH_IPV6
2005 case __constant_htons(ETH_P_IPV6):
2006 ndisc_mc_map((struct in6_addr *)
2007 skb->data + 24,
2008 tg_addr, card->dev, 0);
2009 break;
2010 #endif
2011 case __constant_htons(ETH_P_IP):
2012 ip_hdr = (struct iphdr *)skb->data;
2013 (card->dev->type == ARPHRD_IEEE802_TR) ?
2014 ip_tr_mc_map(ip_hdr->daddr, tg_addr):
2015 ip_eth_mc_map(ip_hdr->daddr, tg_addr);
2016 break;
2017 default:
2018 memcpy(tg_addr, card->dev->broadcast,
2019 card->dev->addr_len);
2021 card->stats.multicast++;
2022 skb->pkt_type = PACKET_MULTICAST;
2023 break;
2024 case QETH_CAST_BROADCAST:
2025 memcpy(tg_addr, card->dev->broadcast,
2026 card->dev->addr_len);
2027 card->stats.multicast++;
2028 skb->pkt_type = PACKET_BROADCAST;
2029 break;
2030 case QETH_CAST_UNICAST:
2031 case QETH_CAST_ANYCAST:
2032 case QETH_CAST_NOCAST:
2033 default:
2034 if (card->options.sniffer)
2035 skb->pkt_type = PACKET_OTHERHOST;
2036 else
2037 skb->pkt_type = PACKET_HOST;
2038 memcpy(tg_addr, card->dev->dev_addr,
2039 card->dev->addr_len);
2041 if (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_SRC_MAC_ADDR)
2042 card->dev->header_ops->create(skb, card->dev, prot,
2043 tg_addr, &hdr->hdr.l3.dest_addr[2],
2044 card->dev->addr_len);
2045 else
2046 card->dev->header_ops->create(skb, card->dev, prot,
2047 tg_addr, "FAKELL", card->dev->addr_len);
2050 #ifdef CONFIG_TR
2051 if (card->dev->type == ARPHRD_IEEE802_TR)
2052 skb->protocol = tr_type_trans(skb, card->dev);
2053 else
2054 #endif
2055 skb->protocol = eth_type_trans(skb, card->dev);
2057 if (hdr->hdr.l3.ext_flags &
2058 (QETH_HDR_EXT_VLAN_FRAME | QETH_HDR_EXT_INCLUDE_VLAN_TAG)) {
2059 vlan_id = (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_VLAN_FRAME)?
2060 hdr->hdr.l3.vlan_id : *((u16 *)&hdr->hdr.l3.dest_addr[12]);
2063 switch (card->options.checksum_type) {
2064 case SW_CHECKSUMMING:
2065 skb->ip_summed = CHECKSUM_NONE;
2066 break;
2067 case NO_CHECKSUMMING:
2068 skb->ip_summed = CHECKSUM_UNNECESSARY;
2069 break;
2070 case HW_CHECKSUMMING:
2071 if ((hdr->hdr.l3.ext_flags &
2072 (QETH_HDR_EXT_CSUM_HDR_REQ |
2073 QETH_HDR_EXT_CSUM_TRANSP_REQ)) ==
2074 (QETH_HDR_EXT_CSUM_HDR_REQ |
2075 QETH_HDR_EXT_CSUM_TRANSP_REQ))
2076 skb->ip_summed = CHECKSUM_UNNECESSARY;
2077 else
2078 skb->ip_summed = CHECKSUM_NONE;
2081 return vlan_id;
2084 static void qeth_l3_process_inbound_buffer(struct qeth_card *card,
2085 struct qeth_qdio_buffer *buf, int index)
2087 struct qdio_buffer_element *element;
2088 struct sk_buff *skb;
2089 struct qeth_hdr *hdr;
2090 int offset;
2091 __u16 vlan_tag = 0;
2092 unsigned int len;
2093 /* get first element of current buffer */
2094 element = (struct qdio_buffer_element *)&buf->buffer->element[0];
2095 offset = 0;
2096 if (card->options.performance_stats)
2097 card->perf_stats.bufs_rec++;
2098 while ((skb = qeth_core_get_next_skb(card, buf->buffer, &element,
2099 &offset, &hdr))) {
2100 skb->dev = card->dev;
2101 /* is device UP ? */
2102 if (!(card->dev->flags & IFF_UP)) {
2103 dev_kfree_skb_any(skb);
2104 continue;
2107 switch (hdr->hdr.l3.id) {
2108 case QETH_HEADER_TYPE_LAYER3:
2109 vlan_tag = qeth_l3_rebuild_skb(card, skb, hdr);
2110 len = skb->len;
2111 if (vlan_tag && !card->options.sniffer)
2112 if (card->vlangrp)
2113 vlan_hwaccel_rx(skb, card->vlangrp,
2114 vlan_tag);
2115 else {
2116 dev_kfree_skb_any(skb);
2117 continue;
2119 else
2120 netif_rx(skb);
2121 break;
2122 case QETH_HEADER_TYPE_LAYER2: /* for HiperSockets sniffer */
2123 skb->pkt_type = PACKET_HOST;
2124 skb->protocol = eth_type_trans(skb, skb->dev);
2125 if (card->options.checksum_type == NO_CHECKSUMMING)
2126 skb->ip_summed = CHECKSUM_UNNECESSARY;
2127 else
2128 skb->ip_summed = CHECKSUM_NONE;
2129 len = skb->len;
2130 netif_receive_skb(skb);
2131 break;
2132 default:
2133 dev_kfree_skb_any(skb);
2134 QETH_DBF_TEXT(TRACE, 3, "inbunkno");
2135 QETH_DBF_HEX(CTRL, 3, hdr, QETH_DBF_CTRL_LEN);
2136 continue;
2139 card->stats.rx_packets++;
2140 card->stats.rx_bytes += len;
2144 static int qeth_l3_verify_vlan_dev(struct net_device *dev,
2145 struct qeth_card *card)
2147 int rc = 0;
2148 struct vlan_group *vg;
2149 int i;
2151 vg = card->vlangrp;
2152 if (!vg)
2153 return rc;
2155 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
2156 if (vlan_group_get_device(vg, i) == dev) {
2157 rc = QETH_VLAN_CARD;
2158 break;
2162 if (rc && !(vlan_dev_real_dev(dev)->ml_priv == (void *)card))
2163 return 0;
2165 return rc;
2168 static int qeth_l3_verify_dev(struct net_device *dev)
2170 struct qeth_card *card;
2171 unsigned long flags;
2172 int rc = 0;
2174 read_lock_irqsave(&qeth_core_card_list.rwlock, flags);
2175 list_for_each_entry(card, &qeth_core_card_list.list, list) {
2176 if (card->dev == dev) {
2177 rc = QETH_REAL_CARD;
2178 break;
2180 rc = qeth_l3_verify_vlan_dev(dev, card);
2181 if (rc)
2182 break;
2184 read_unlock_irqrestore(&qeth_core_card_list.rwlock, flags);
2186 return rc;
2189 static struct qeth_card *qeth_l3_get_card_from_dev(struct net_device *dev)
2191 struct qeth_card *card = NULL;
2192 int rc;
2194 rc = qeth_l3_verify_dev(dev);
2195 if (rc == QETH_REAL_CARD)
2196 card = dev->ml_priv;
2197 else if (rc == QETH_VLAN_CARD)
2198 card = vlan_dev_real_dev(dev)->ml_priv;
2199 if (card && card->options.layer2)
2200 card = NULL;
2201 QETH_DBF_TEXT_(TRACE, 4, "%d", rc);
2202 return card ;
2205 static int qeth_l3_stop_card(struct qeth_card *card, int recovery_mode)
2207 int rc = 0;
2209 QETH_DBF_TEXT(SETUP, 2, "stopcard");
2210 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
2212 qeth_set_allowed_threads(card, 0, 1);
2213 if (card->options.sniffer &&
2214 (card->info.promisc_mode == SET_PROMISC_MODE_ON))
2215 qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_DISABLE);
2216 if (card->read.state == CH_STATE_UP &&
2217 card->write.state == CH_STATE_UP &&
2218 (card->state == CARD_STATE_UP)) {
2219 if (recovery_mode)
2220 qeth_l3_stop(card->dev);
2221 else {
2222 rtnl_lock();
2223 dev_close(card->dev);
2224 rtnl_unlock();
2226 if (!card->use_hard_stop) {
2227 rc = qeth_send_stoplan(card);
2228 if (rc)
2229 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
2231 card->state = CARD_STATE_SOFTSETUP;
2233 if (card->state == CARD_STATE_SOFTSETUP) {
2234 qeth_l3_clear_ip_list(card, !card->use_hard_stop, 1);
2235 qeth_clear_ipacmd_list(card);
2236 card->state = CARD_STATE_HARDSETUP;
2238 if (card->state == CARD_STATE_HARDSETUP) {
2239 if (!card->use_hard_stop &&
2240 (card->info.type != QETH_CARD_TYPE_IQD)) {
2241 rc = qeth_l3_put_unique_id(card);
2242 if (rc)
2243 QETH_DBF_TEXT_(SETUP, 2, "2err%d", rc);
2245 qeth_qdio_clear_card(card, 0);
2246 qeth_clear_qdio_buffers(card);
2247 qeth_clear_working_pool_list(card);
2248 card->state = CARD_STATE_DOWN;
2250 if (card->state == CARD_STATE_DOWN) {
2251 qeth_clear_cmd_buffers(&card->read);
2252 qeth_clear_cmd_buffers(&card->write);
2254 card->use_hard_stop = 0;
2255 return rc;
2259 * test for and Switch promiscuous mode (on or off)
2260 * either for guestlan or HiperSocket Sniffer
2262 static void
2263 qeth_l3_handle_promisc_mode(struct qeth_card *card)
2265 struct net_device *dev = card->dev;
2267 if (((dev->flags & IFF_PROMISC) &&
2268 (card->info.promisc_mode == SET_PROMISC_MODE_ON)) ||
2269 (!(dev->flags & IFF_PROMISC) &&
2270 (card->info.promisc_mode == SET_PROMISC_MODE_OFF)))
2271 return;
2273 if (card->info.guestlan) { /* Guestlan trace */
2274 if (qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
2275 qeth_setadp_promisc_mode(card);
2276 } else if (card->options.sniffer && /* HiperSockets trace */
2277 qeth_adp_supported(card, IPA_SETADP_SET_DIAG_ASSIST)) {
2278 if (dev->flags & IFF_PROMISC) {
2279 QETH_DBF_TEXT(TRACE, 3, "+promisc");
2280 qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_ENABLE);
2281 } else {
2282 QETH_DBF_TEXT(TRACE, 3, "-promisc");
2283 qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_DISABLE);
2288 static void qeth_l3_set_multicast_list(struct net_device *dev)
2290 struct qeth_card *card = dev->ml_priv;
2292 QETH_DBF_TEXT(TRACE, 3, "setmulti");
2293 if (qeth_threads_running(card, QETH_RECOVER_THREAD) &&
2294 (card->state != CARD_STATE_UP))
2295 return;
2296 if (!card->options.sniffer) {
2297 qeth_l3_delete_mc_addresses(card);
2298 qeth_l3_add_multicast_ipv4(card);
2299 #ifdef CONFIG_QETH_IPV6
2300 qeth_l3_add_multicast_ipv6(card);
2301 #endif
2302 qeth_l3_set_ip_addr_list(card);
2303 if (!qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
2304 return;
2306 qeth_l3_handle_promisc_mode(card);
2309 static const char *qeth_l3_arp_get_error_cause(int *rc)
2311 switch (*rc) {
2312 case QETH_IPA_ARP_RC_FAILED:
2313 *rc = -EIO;
2314 return "operation failed";
2315 case QETH_IPA_ARP_RC_NOTSUPP:
2316 *rc = -EOPNOTSUPP;
2317 return "operation not supported";
2318 case QETH_IPA_ARP_RC_OUT_OF_RANGE:
2319 *rc = -EINVAL;
2320 return "argument out of range";
2321 case QETH_IPA_ARP_RC_Q_NOTSUPP:
2322 *rc = -EOPNOTSUPP;
2323 return "query operation not supported";
2324 case QETH_IPA_ARP_RC_Q_NO_DATA:
2325 *rc = -ENOENT;
2326 return "no query data available";
2327 default:
2328 return "unknown error";
2332 static int qeth_l3_arp_set_no_entries(struct qeth_card *card, int no_entries)
2334 int tmp;
2335 int rc;
2337 QETH_DBF_TEXT(TRACE, 3, "arpstnoe");
2340 * currently GuestLAN only supports the ARP assist function
2341 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_SET_NO_ENTRIES;
2342 * thus we say EOPNOTSUPP for this ARP function
2344 if (card->info.guestlan)
2345 return -EOPNOTSUPP;
2346 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
2347 return -EOPNOTSUPP;
2349 rc = qeth_l3_send_simple_setassparms(card, IPA_ARP_PROCESSING,
2350 IPA_CMD_ASS_ARP_SET_NO_ENTRIES,
2351 no_entries);
2352 if (rc) {
2353 tmp = rc;
2354 QETH_DBF_MESSAGE(2, "Could not set number of ARP entries on "
2355 "%s: %s (0x%x/%d)\n", QETH_CARD_IFNAME(card),
2356 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
2358 return rc;
2361 static void qeth_l3_copy_arp_entries_stripped(struct qeth_arp_query_info *qinfo,
2362 struct qeth_arp_query_data *qdata, int entry_size,
2363 int uentry_size)
2365 char *entry_ptr;
2366 char *uentry_ptr;
2367 int i;
2369 entry_ptr = (char *)&qdata->data;
2370 uentry_ptr = (char *)(qinfo->udata + qinfo->udata_offset);
2371 for (i = 0; i < qdata->no_entries; ++i) {
2372 /* strip off 32 bytes "media specific information" */
2373 memcpy(uentry_ptr, (entry_ptr + 32), entry_size - 32);
2374 entry_ptr += entry_size;
2375 uentry_ptr += uentry_size;
2379 static int qeth_l3_arp_query_cb(struct qeth_card *card,
2380 struct qeth_reply *reply, unsigned long data)
2382 struct qeth_ipa_cmd *cmd;
2383 struct qeth_arp_query_data *qdata;
2384 struct qeth_arp_query_info *qinfo;
2385 int entry_size;
2386 int uentry_size;
2387 int i;
2389 QETH_DBF_TEXT(TRACE, 4, "arpquecb");
2391 qinfo = (struct qeth_arp_query_info *) reply->param;
2392 cmd = (struct qeth_ipa_cmd *) data;
2393 if (cmd->hdr.return_code) {
2394 QETH_DBF_TEXT_(TRACE, 4, "qaer1%i", cmd->hdr.return_code);
2395 return 0;
2397 if (cmd->data.setassparms.hdr.return_code) {
2398 cmd->hdr.return_code = cmd->data.setassparms.hdr.return_code;
2399 QETH_DBF_TEXT_(TRACE, 4, "qaer2%i", cmd->hdr.return_code);
2400 return 0;
2402 qdata = &cmd->data.setassparms.data.query_arp;
2403 switch (qdata->reply_bits) {
2404 case 5:
2405 uentry_size = entry_size = sizeof(struct qeth_arp_qi_entry5);
2406 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES)
2407 uentry_size = sizeof(struct qeth_arp_qi_entry5_short);
2408 break;
2409 case 7:
2410 /* fall through to default */
2411 default:
2412 /* tr is the same as eth -> entry7 */
2413 uentry_size = entry_size = sizeof(struct qeth_arp_qi_entry7);
2414 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES)
2415 uentry_size = sizeof(struct qeth_arp_qi_entry7_short);
2416 break;
2418 /* check if there is enough room in userspace */
2419 if ((qinfo->udata_len - qinfo->udata_offset) <
2420 qdata->no_entries * uentry_size){
2421 QETH_DBF_TEXT_(TRACE, 4, "qaer3%i", -ENOMEM);
2422 cmd->hdr.return_code = -ENOMEM;
2423 goto out_error;
2425 QETH_DBF_TEXT_(TRACE, 4, "anore%i",
2426 cmd->data.setassparms.hdr.number_of_replies);
2427 QETH_DBF_TEXT_(TRACE, 4, "aseqn%i", cmd->data.setassparms.hdr.seq_no);
2428 QETH_DBF_TEXT_(TRACE, 4, "anoen%i", qdata->no_entries);
2430 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES) {
2431 /* strip off "media specific information" */
2432 qeth_l3_copy_arp_entries_stripped(qinfo, qdata, entry_size,
2433 uentry_size);
2434 } else
2435 /*copy entries to user buffer*/
2436 memcpy(qinfo->udata + qinfo->udata_offset,
2437 (char *)&qdata->data, qdata->no_entries*uentry_size);
2439 qinfo->no_entries += qdata->no_entries;
2440 qinfo->udata_offset += (qdata->no_entries*uentry_size);
2441 /* check if all replies received ... */
2442 if (cmd->data.setassparms.hdr.seq_no <
2443 cmd->data.setassparms.hdr.number_of_replies)
2444 return 1;
2445 memcpy(qinfo->udata, &qinfo->no_entries, 4);
2446 /* keep STRIP_ENTRIES flag so the user program can distinguish
2447 * stripped entries from normal ones */
2448 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES)
2449 qdata->reply_bits |= QETH_QARP_STRIP_ENTRIES;
2450 memcpy(qinfo->udata + QETH_QARP_MASK_OFFSET, &qdata->reply_bits, 2);
2451 return 0;
2452 out_error:
2453 i = 0;
2454 memcpy(qinfo->udata, &i, 4);
2455 return 0;
2458 static int qeth_l3_send_ipa_arp_cmd(struct qeth_card *card,
2459 struct qeth_cmd_buffer *iob, int len,
2460 int (*reply_cb)(struct qeth_card *, struct qeth_reply *,
2461 unsigned long),
2462 void *reply_param)
2464 QETH_DBF_TEXT(TRACE, 4, "sendarp");
2466 memcpy(iob->data, IPA_PDU_HEADER, IPA_PDU_HEADER_SIZE);
2467 memcpy(QETH_IPA_CMD_DEST_ADDR(iob->data),
2468 &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
2469 return qeth_send_control_data(card, IPA_PDU_HEADER_SIZE + len, iob,
2470 reply_cb, reply_param);
2473 static int qeth_l3_arp_query(struct qeth_card *card, char __user *udata)
2475 struct qeth_cmd_buffer *iob;
2476 struct qeth_arp_query_info qinfo = {0, };
2477 int tmp;
2478 int rc;
2480 QETH_DBF_TEXT(TRACE, 3, "arpquery");
2482 if (!qeth_is_supported(card,/*IPA_QUERY_ARP_ADDR_INFO*/
2483 IPA_ARP_PROCESSING)) {
2484 return -EOPNOTSUPP;
2486 /* get size of userspace buffer and mask_bits -> 6 bytes */
2487 if (copy_from_user(&qinfo, udata, 6))
2488 return -EFAULT;
2489 qinfo.udata = kzalloc(qinfo.udata_len, GFP_KERNEL);
2490 if (!qinfo.udata)
2491 return -ENOMEM;
2492 qinfo.udata_offset = QETH_QARP_ENTRIES_OFFSET;
2493 iob = qeth_l3_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
2494 IPA_CMD_ASS_ARP_QUERY_INFO,
2495 sizeof(int), QETH_PROT_IPV4);
2497 rc = qeth_l3_send_ipa_arp_cmd(card, iob,
2498 QETH_SETASS_BASE_LEN+QETH_ARP_CMD_LEN,
2499 qeth_l3_arp_query_cb, (void *)&qinfo);
2500 if (rc) {
2501 tmp = rc;
2502 QETH_DBF_MESSAGE(2, "Error while querying ARP cache on %s: %s "
2503 "(0x%x/%d)\n", QETH_CARD_IFNAME(card),
2504 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
2505 if (copy_to_user(udata, qinfo.udata, 4))
2506 rc = -EFAULT;
2507 } else {
2508 if (copy_to_user(udata, qinfo.udata, qinfo.udata_len))
2509 rc = -EFAULT;
2511 kfree(qinfo.udata);
2512 return rc;
2515 static int qeth_l3_arp_add_entry(struct qeth_card *card,
2516 struct qeth_arp_cache_entry *entry)
2518 struct qeth_cmd_buffer *iob;
2519 char buf[16];
2520 int tmp;
2521 int rc;
2523 QETH_DBF_TEXT(TRACE, 3, "arpadent");
2526 * currently GuestLAN only supports the ARP assist function
2527 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_ADD_ENTRY;
2528 * thus we say EOPNOTSUPP for this ARP function
2530 if (card->info.guestlan)
2531 return -EOPNOTSUPP;
2532 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
2533 return -EOPNOTSUPP;
2536 iob = qeth_l3_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
2537 IPA_CMD_ASS_ARP_ADD_ENTRY,
2538 sizeof(struct qeth_arp_cache_entry),
2539 QETH_PROT_IPV4);
2540 rc = qeth_l3_send_setassparms(card, iob,
2541 sizeof(struct qeth_arp_cache_entry),
2542 (unsigned long) entry,
2543 qeth_l3_default_setassparms_cb, NULL);
2544 if (rc) {
2545 tmp = rc;
2546 qeth_l3_ipaddr4_to_string((u8 *)entry->ipaddr, buf);
2547 QETH_DBF_MESSAGE(2, "Could not add ARP entry for address %s "
2548 "on %s: %s (0x%x/%d)\n", buf, QETH_CARD_IFNAME(card),
2549 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
2551 return rc;
2554 static int qeth_l3_arp_remove_entry(struct qeth_card *card,
2555 struct qeth_arp_cache_entry *entry)
2557 struct qeth_cmd_buffer *iob;
2558 char buf[16] = {0, };
2559 int tmp;
2560 int rc;
2562 QETH_DBF_TEXT(TRACE, 3, "arprment");
2565 * currently GuestLAN only supports the ARP assist function
2566 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_REMOVE_ENTRY;
2567 * thus we say EOPNOTSUPP for this ARP function
2569 if (card->info.guestlan)
2570 return -EOPNOTSUPP;
2571 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
2572 return -EOPNOTSUPP;
2574 memcpy(buf, entry, 12);
2575 iob = qeth_l3_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
2576 IPA_CMD_ASS_ARP_REMOVE_ENTRY,
2578 QETH_PROT_IPV4);
2579 rc = qeth_l3_send_setassparms(card, iob,
2580 12, (unsigned long)buf,
2581 qeth_l3_default_setassparms_cb, NULL);
2582 if (rc) {
2583 tmp = rc;
2584 memset(buf, 0, 16);
2585 qeth_l3_ipaddr4_to_string((u8 *)entry->ipaddr, buf);
2586 QETH_DBF_MESSAGE(2, "Could not delete ARP entry for address %s"
2587 " on %s: %s (0x%x/%d)\n", buf, QETH_CARD_IFNAME(card),
2588 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
2590 return rc;
2593 static int qeth_l3_arp_flush_cache(struct qeth_card *card)
2595 int rc;
2596 int tmp;
2598 QETH_DBF_TEXT(TRACE, 3, "arpflush");
2601 * currently GuestLAN only supports the ARP assist function
2602 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_FLUSH_CACHE;
2603 * thus we say EOPNOTSUPP for this ARP function
2605 if (card->info.guestlan || (card->info.type == QETH_CARD_TYPE_IQD))
2606 return -EOPNOTSUPP;
2607 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
2608 return -EOPNOTSUPP;
2610 rc = qeth_l3_send_simple_setassparms(card, IPA_ARP_PROCESSING,
2611 IPA_CMD_ASS_ARP_FLUSH_CACHE, 0);
2612 if (rc) {
2613 tmp = rc;
2614 QETH_DBF_MESSAGE(2, "Could not flush ARP cache on %s: %s "
2615 "(0x%x/%d)\n", QETH_CARD_IFNAME(card),
2616 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
2618 return rc;
2621 static int qeth_l3_do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
2623 struct qeth_card *card = dev->ml_priv;
2624 struct qeth_arp_cache_entry arp_entry;
2625 struct mii_ioctl_data *mii_data;
2626 int rc = 0;
2628 if (!card)
2629 return -ENODEV;
2631 if ((card->state != CARD_STATE_UP) &&
2632 (card->state != CARD_STATE_SOFTSETUP))
2633 return -ENODEV;
2635 switch (cmd) {
2636 case SIOC_QETH_ARP_SET_NO_ENTRIES:
2637 if (!capable(CAP_NET_ADMIN)) {
2638 rc = -EPERM;
2639 break;
2641 rc = qeth_l3_arp_set_no_entries(card, rq->ifr_ifru.ifru_ivalue);
2642 break;
2643 case SIOC_QETH_ARP_QUERY_INFO:
2644 if (!capable(CAP_NET_ADMIN)) {
2645 rc = -EPERM;
2646 break;
2648 rc = qeth_l3_arp_query(card, rq->ifr_ifru.ifru_data);
2649 break;
2650 case SIOC_QETH_ARP_ADD_ENTRY:
2651 if (!capable(CAP_NET_ADMIN)) {
2652 rc = -EPERM;
2653 break;
2655 if (copy_from_user(&arp_entry, rq->ifr_ifru.ifru_data,
2656 sizeof(struct qeth_arp_cache_entry)))
2657 rc = -EFAULT;
2658 else
2659 rc = qeth_l3_arp_add_entry(card, &arp_entry);
2660 break;
2661 case SIOC_QETH_ARP_REMOVE_ENTRY:
2662 if (!capable(CAP_NET_ADMIN)) {
2663 rc = -EPERM;
2664 break;
2666 if (copy_from_user(&arp_entry, rq->ifr_ifru.ifru_data,
2667 sizeof(struct qeth_arp_cache_entry)))
2668 rc = -EFAULT;
2669 else
2670 rc = qeth_l3_arp_remove_entry(card, &arp_entry);
2671 break;
2672 case SIOC_QETH_ARP_FLUSH_CACHE:
2673 if (!capable(CAP_NET_ADMIN)) {
2674 rc = -EPERM;
2675 break;
2677 rc = qeth_l3_arp_flush_cache(card);
2678 break;
2679 case SIOC_QETH_ADP_SET_SNMP_CONTROL:
2680 rc = qeth_snmp_command(card, rq->ifr_ifru.ifru_data);
2681 break;
2682 case SIOC_QETH_GET_CARD_TYPE:
2683 if ((card->info.type == QETH_CARD_TYPE_OSAE) &&
2684 !card->info.guestlan)
2685 return 1;
2686 return 0;
2687 break;
2688 case SIOCGMIIPHY:
2689 mii_data = if_mii(rq);
2690 mii_data->phy_id = 0;
2691 break;
2692 case SIOCGMIIREG:
2693 mii_data = if_mii(rq);
2694 if (mii_data->phy_id != 0)
2695 rc = -EINVAL;
2696 else
2697 mii_data->val_out = qeth_mdio_read(dev,
2698 mii_data->phy_id,
2699 mii_data->reg_num);
2700 break;
2701 default:
2702 rc = -EOPNOTSUPP;
2704 if (rc)
2705 QETH_DBF_TEXT_(TRACE, 2, "ioce%d", rc);
2706 return rc;
2709 int inline qeth_l3_get_cast_type(struct qeth_card *card, struct sk_buff *skb)
2711 int cast_type = RTN_UNSPEC;
2713 if (skb_dst(skb) && skb_dst(skb)->neighbour) {
2714 cast_type = skb_dst(skb)->neighbour->type;
2715 if ((cast_type == RTN_BROADCAST) ||
2716 (cast_type == RTN_MULTICAST) ||
2717 (cast_type == RTN_ANYCAST))
2718 return cast_type;
2719 else
2720 return RTN_UNSPEC;
2722 /* try something else */
2723 if (skb->protocol == ETH_P_IPV6)
2724 return (skb_network_header(skb)[24] == 0xff) ?
2725 RTN_MULTICAST : 0;
2726 else if (skb->protocol == ETH_P_IP)
2727 return ((skb_network_header(skb)[16] & 0xf0) == 0xe0) ?
2728 RTN_MULTICAST : 0;
2729 /* ... */
2730 if (!memcmp(skb->data, skb->dev->broadcast, 6))
2731 return RTN_BROADCAST;
2732 else {
2733 u16 hdr_mac;
2735 hdr_mac = *((u16 *)skb->data);
2736 /* tr multicast? */
2737 switch (card->info.link_type) {
2738 case QETH_LINK_TYPE_HSTR:
2739 case QETH_LINK_TYPE_LANE_TR:
2740 if ((hdr_mac == QETH_TR_MAC_NC) ||
2741 (hdr_mac == QETH_TR_MAC_C))
2742 return RTN_MULTICAST;
2743 break;
2744 /* eth or so multicast? */
2745 default:
2746 if ((hdr_mac == QETH_ETH_MAC_V4) ||
2747 (hdr_mac == QETH_ETH_MAC_V6))
2748 return RTN_MULTICAST;
2751 return cast_type;
2754 static void qeth_l3_fill_header(struct qeth_card *card, struct qeth_hdr *hdr,
2755 struct sk_buff *skb, int ipv, int cast_type)
2757 memset(hdr, 0, sizeof(struct qeth_hdr));
2758 hdr->hdr.l3.id = QETH_HEADER_TYPE_LAYER3;
2759 hdr->hdr.l3.ext_flags = 0;
2762 * before we're going to overwrite this location with next hop ip.
2763 * v6 uses passthrough, v4 sets the tag in the QDIO header.
2765 if (card->vlangrp && vlan_tx_tag_present(skb)) {
2766 if ((ipv == 4) || (card->info.type == QETH_CARD_TYPE_IQD))
2767 hdr->hdr.l3.ext_flags = QETH_HDR_EXT_VLAN_FRAME;
2768 else
2769 hdr->hdr.l3.ext_flags = QETH_HDR_EXT_INCLUDE_VLAN_TAG;
2770 hdr->hdr.l3.vlan_id = vlan_tx_tag_get(skb);
2773 hdr->hdr.l3.length = skb->len - sizeof(struct qeth_hdr);
2774 if (ipv == 4) {
2775 /* IPv4 */
2776 hdr->hdr.l3.flags = qeth_l3_get_qeth_hdr_flags4(cast_type);
2777 memset(hdr->hdr.l3.dest_addr, 0, 12);
2778 if ((skb_dst(skb)) && (skb_dst(skb)->neighbour)) {
2779 *((u32 *) (&hdr->hdr.l3.dest_addr[12])) =
2780 *((u32 *) skb_dst(skb)->neighbour->primary_key);
2781 } else {
2782 /* fill in destination address used in ip header */
2783 *((u32 *) (&hdr->hdr.l3.dest_addr[12])) =
2784 ip_hdr(skb)->daddr;
2786 } else if (ipv == 6) {
2787 /* IPv6 */
2788 hdr->hdr.l3.flags = qeth_l3_get_qeth_hdr_flags6(cast_type);
2789 if (card->info.type == QETH_CARD_TYPE_IQD)
2790 hdr->hdr.l3.flags &= ~QETH_HDR_PASSTHRU;
2791 if ((skb_dst(skb)) && (skb_dst(skb)->neighbour)) {
2792 memcpy(hdr->hdr.l3.dest_addr,
2793 skb_dst(skb)->neighbour->primary_key, 16);
2794 } else {
2795 /* fill in destination address used in ip header */
2796 memcpy(hdr->hdr.l3.dest_addr,
2797 &ipv6_hdr(skb)->daddr, 16);
2799 } else {
2800 /* passthrough */
2801 if ((skb->dev->type == ARPHRD_IEEE802_TR) &&
2802 !memcmp(skb->data + sizeof(struct qeth_hdr) +
2803 sizeof(__u16), skb->dev->broadcast, 6)) {
2804 hdr->hdr.l3.flags = QETH_CAST_BROADCAST |
2805 QETH_HDR_PASSTHRU;
2806 } else if (!memcmp(skb->data + sizeof(struct qeth_hdr),
2807 skb->dev->broadcast, 6)) {
2808 /* broadcast? */
2809 hdr->hdr.l3.flags = QETH_CAST_BROADCAST |
2810 QETH_HDR_PASSTHRU;
2811 } else {
2812 hdr->hdr.l3.flags = (cast_type == RTN_MULTICAST) ?
2813 QETH_CAST_MULTICAST | QETH_HDR_PASSTHRU :
2814 QETH_CAST_UNICAST | QETH_HDR_PASSTHRU;
2819 static void qeth_tso_fill_header(struct qeth_card *card,
2820 struct qeth_hdr *qhdr, struct sk_buff *skb)
2822 struct qeth_hdr_tso *hdr = (struct qeth_hdr_tso *)qhdr;
2823 struct tcphdr *tcph = tcp_hdr(skb);
2824 struct iphdr *iph = ip_hdr(skb);
2825 struct ipv6hdr *ip6h = ipv6_hdr(skb);
2827 /*fix header to TSO values ...*/
2828 hdr->hdr.hdr.l3.id = QETH_HEADER_TYPE_TSO;
2829 /*set values which are fix for the first approach ...*/
2830 hdr->ext.hdr_tot_len = (__u16) sizeof(struct qeth_hdr_ext_tso);
2831 hdr->ext.imb_hdr_no = 1;
2832 hdr->ext.hdr_type = 1;
2833 hdr->ext.hdr_version = 1;
2834 hdr->ext.hdr_len = 28;
2835 /*insert non-fix values */
2836 hdr->ext.mss = skb_shinfo(skb)->gso_size;
2837 hdr->ext.dg_hdr_len = (__u16)(iph->ihl*4 + tcph->doff*4);
2838 hdr->ext.payload_len = (__u16)(skb->len - hdr->ext.dg_hdr_len -
2839 sizeof(struct qeth_hdr_tso));
2840 tcph->check = 0;
2841 if (skb->protocol == ETH_P_IPV6) {
2842 ip6h->payload_len = 0;
2843 tcph->check = ~csum_ipv6_magic(&ip6h->saddr, &ip6h->daddr,
2844 0, IPPROTO_TCP, 0);
2845 } else {
2846 /*OSA want us to set these values ...*/
2847 tcph->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr,
2848 0, IPPROTO_TCP, 0);
2849 iph->tot_len = 0;
2850 iph->check = 0;
2854 static void qeth_tx_csum(struct sk_buff *skb)
2856 __wsum csum;
2857 int offset;
2859 skb_set_transport_header(skb, skb->csum_start - skb_headroom(skb));
2860 offset = skb->csum_start - skb_headroom(skb);
2861 BUG_ON(offset >= skb_headlen(skb));
2862 csum = skb_checksum(skb, offset, skb->len - offset, 0);
2864 offset += skb->csum_offset;
2865 BUG_ON(offset + sizeof(__sum16) > skb_headlen(skb));
2866 *(__sum16 *)(skb->data + offset) = csum_fold(csum);
2869 static inline int qeth_l3_tso_elements(struct sk_buff *skb)
2871 unsigned long tcpd = (unsigned long)tcp_hdr(skb) +
2872 tcp_hdr(skb)->doff * 4;
2873 int tcpd_len = skb->len - (tcpd - (unsigned long)skb->data);
2874 int elements = PFN_UP(tcpd + tcpd_len) - PFN_DOWN(tcpd);
2875 elements += skb_shinfo(skb)->nr_frags;
2876 return elements;
2879 static inline int qeth_l3_tso_check(struct sk_buff *skb)
2881 int len = ((unsigned long)tcp_hdr(skb) + tcp_hdr(skb)->doff * 4) -
2882 (unsigned long)skb->data;
2883 return (((unsigned long)skb->data & PAGE_MASK) !=
2884 (((unsigned long)skb->data + len) & PAGE_MASK));
2887 static int qeth_l3_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
2889 int rc;
2890 u16 *tag;
2891 struct qeth_hdr *hdr = NULL;
2892 int elements_needed = 0;
2893 int elems;
2894 struct qeth_card *card = dev->ml_priv;
2895 struct sk_buff *new_skb = NULL;
2896 int ipv = qeth_get_ip_version(skb);
2897 int cast_type = qeth_l3_get_cast_type(card, skb);
2898 struct qeth_qdio_out_q *queue = card->qdio.out_qs
2899 [qeth_get_priority_queue(card, skb, ipv, cast_type)];
2900 int tx_bytes = skb->len;
2901 enum qeth_large_send_types large_send = QETH_LARGE_SEND_NO;
2902 int data_offset = -1;
2903 int nr_frags;
2905 if (((card->info.type == QETH_CARD_TYPE_IQD) && (!ipv)) ||
2906 card->options.sniffer)
2907 goto tx_drop;
2909 if ((card->state != CARD_STATE_UP) || !card->lan_online) {
2910 card->stats.tx_carrier_errors++;
2911 goto tx_drop;
2914 if ((cast_type == RTN_BROADCAST) &&
2915 (card->info.broadcast_capable == 0))
2916 goto tx_drop;
2918 if (card->options.performance_stats) {
2919 card->perf_stats.outbound_cnt++;
2920 card->perf_stats.outbound_start_time = qeth_get_micros();
2923 if (skb_is_gso(skb))
2924 large_send = card->options.large_send;
2925 else
2926 if (skb->ip_summed == CHECKSUM_PARTIAL) {
2927 qeth_tx_csum(skb);
2928 if (card->options.performance_stats)
2929 card->perf_stats.tx_csum++;
2932 if ((card->info.type == QETH_CARD_TYPE_IQD) && (!large_send) &&
2933 (skb_shinfo(skb)->nr_frags == 0)) {
2934 new_skb = skb;
2935 data_offset = ETH_HLEN;
2936 hdr = kmem_cache_alloc(qeth_core_header_cache, GFP_ATOMIC);
2937 if (!hdr)
2938 goto tx_drop;
2939 elements_needed++;
2940 } else {
2941 /* create a clone with writeable headroom */
2942 new_skb = skb_realloc_headroom(skb, sizeof(struct qeth_hdr_tso)
2943 + VLAN_HLEN);
2944 if (!new_skb)
2945 goto tx_drop;
2948 if (card->info.type == QETH_CARD_TYPE_IQD) {
2949 if (data_offset < 0)
2950 skb_pull(new_skb, ETH_HLEN);
2951 } else {
2952 if (ipv == 4) {
2953 if (card->dev->type == ARPHRD_IEEE802_TR)
2954 skb_pull(new_skb, TR_HLEN);
2955 else
2956 skb_pull(new_skb, ETH_HLEN);
2959 if (ipv == 6 && card->vlangrp &&
2960 vlan_tx_tag_present(new_skb)) {
2961 skb_push(new_skb, VLAN_HLEN);
2962 skb_copy_to_linear_data(new_skb, new_skb->data + 4, 4);
2963 skb_copy_to_linear_data_offset(new_skb, 4,
2964 new_skb->data + 8, 4);
2965 skb_copy_to_linear_data_offset(new_skb, 8,
2966 new_skb->data + 12, 4);
2967 tag = (u16 *)(new_skb->data + 12);
2968 *tag = __constant_htons(ETH_P_8021Q);
2969 *(tag + 1) = htons(vlan_tx_tag_get(new_skb));
2970 new_skb->vlan_tci = 0;
2974 netif_stop_queue(dev);
2976 /* fix hardware limitation: as long as we do not have sbal
2977 * chaining we can not send long frag lists
2979 if (large_send == QETH_LARGE_SEND_TSO) {
2980 if (qeth_l3_tso_elements(new_skb) + 1 > 16) {
2981 if (skb_linearize(new_skb))
2982 goto tx_drop;
2983 if (card->options.performance_stats)
2984 card->perf_stats.tx_lin++;
2988 if ((large_send == QETH_LARGE_SEND_TSO) &&
2989 (cast_type == RTN_UNSPEC)) {
2990 hdr = (struct qeth_hdr *)skb_push(new_skb,
2991 sizeof(struct qeth_hdr_tso));
2992 if (qeth_l3_tso_check(new_skb))
2993 QETH_DBF_MESSAGE(2, "tso skb misaligned\n");
2994 memset(hdr, 0, sizeof(struct qeth_hdr_tso));
2995 qeth_l3_fill_header(card, hdr, new_skb, ipv, cast_type);
2996 qeth_tso_fill_header(card, hdr, new_skb);
2997 elements_needed++;
2998 } else {
2999 if (data_offset < 0) {
3000 hdr = (struct qeth_hdr *)skb_push(new_skb,
3001 sizeof(struct qeth_hdr));
3002 qeth_l3_fill_header(card, hdr, new_skb, ipv,
3003 cast_type);
3004 } else {
3005 qeth_l3_fill_header(card, hdr, new_skb, ipv,
3006 cast_type);
3007 hdr->hdr.l3.length = new_skb->len - data_offset;
3011 elems = qeth_get_elements_no(card, (void *)hdr, new_skb,
3012 elements_needed);
3013 if (!elems) {
3014 if (data_offset >= 0)
3015 kmem_cache_free(qeth_core_header_cache, hdr);
3016 goto tx_drop;
3018 elements_needed += elems;
3019 nr_frags = skb_shinfo(new_skb)->nr_frags;
3021 if (card->info.type != QETH_CARD_TYPE_IQD)
3022 rc = qeth_do_send_packet(card, queue, new_skb, hdr,
3023 elements_needed);
3024 else
3025 rc = qeth_do_send_packet_fast(card, queue, new_skb, hdr,
3026 elements_needed, data_offset, 0);
3028 if (!rc) {
3029 card->stats.tx_packets++;
3030 card->stats.tx_bytes += tx_bytes;
3031 if (new_skb != skb)
3032 dev_kfree_skb_any(skb);
3033 if (card->options.performance_stats) {
3034 if (large_send != QETH_LARGE_SEND_NO) {
3035 card->perf_stats.large_send_bytes += tx_bytes;
3036 card->perf_stats.large_send_cnt++;
3038 if (nr_frags) {
3039 card->perf_stats.sg_skbs_sent++;
3040 /* nr_frags + skb->data */
3041 card->perf_stats.sg_frags_sent += nr_frags + 1;
3044 rc = NETDEV_TX_OK;
3045 } else {
3046 if (data_offset >= 0)
3047 kmem_cache_free(qeth_core_header_cache, hdr);
3049 if (rc == -EBUSY) {
3050 if (new_skb != skb)
3051 dev_kfree_skb_any(new_skb);
3052 return NETDEV_TX_BUSY;
3053 } else
3054 goto tx_drop;
3057 netif_wake_queue(dev);
3058 if (card->options.performance_stats)
3059 card->perf_stats.outbound_time += qeth_get_micros() -
3060 card->perf_stats.outbound_start_time;
3061 return rc;
3063 tx_drop:
3064 card->stats.tx_dropped++;
3065 card->stats.tx_errors++;
3066 if ((new_skb != skb) && new_skb)
3067 dev_kfree_skb_any(new_skb);
3068 dev_kfree_skb_any(skb);
3069 netif_wake_queue(dev);
3070 return NETDEV_TX_OK;
3073 static int qeth_l3_open(struct net_device *dev)
3075 struct qeth_card *card = dev->ml_priv;
3077 QETH_DBF_TEXT(TRACE, 4, "qethopen");
3078 if (card->state != CARD_STATE_SOFTSETUP)
3079 return -ENODEV;
3080 card->data.state = CH_STATE_UP;
3081 card->state = CARD_STATE_UP;
3082 netif_start_queue(dev);
3084 if (!card->lan_online && netif_carrier_ok(dev))
3085 netif_carrier_off(dev);
3086 return 0;
3089 static int qeth_l3_stop(struct net_device *dev)
3091 struct qeth_card *card = dev->ml_priv;
3093 QETH_DBF_TEXT(TRACE, 4, "qethstop");
3094 netif_tx_disable(dev);
3095 if (card->state == CARD_STATE_UP)
3096 card->state = CARD_STATE_SOFTSETUP;
3097 return 0;
3100 static u32 qeth_l3_ethtool_get_rx_csum(struct net_device *dev)
3102 struct qeth_card *card = dev->ml_priv;
3104 return (card->options.checksum_type == HW_CHECKSUMMING);
3107 static int qeth_l3_ethtool_set_rx_csum(struct net_device *dev, u32 data)
3109 struct qeth_card *card = dev->ml_priv;
3110 enum qeth_checksum_types csum_type;
3112 if (data)
3113 csum_type = HW_CHECKSUMMING;
3114 else
3115 csum_type = SW_CHECKSUMMING;
3117 return qeth_l3_set_rx_csum(card, csum_type);
3120 static int qeth_l3_ethtool_set_tso(struct net_device *dev, u32 data)
3122 struct qeth_card *card = dev->ml_priv;
3123 int rc = 0;
3125 if (data) {
3126 rc = qeth_l3_set_large_send(card, QETH_LARGE_SEND_TSO);
3127 } else {
3128 dev->features &= ~NETIF_F_TSO;
3129 card->options.large_send = QETH_LARGE_SEND_NO;
3131 return rc;
3134 static const struct ethtool_ops qeth_l3_ethtool_ops = {
3135 .get_link = ethtool_op_get_link,
3136 .get_tx_csum = ethtool_op_get_tx_csum,
3137 .set_tx_csum = ethtool_op_set_tx_hw_csum,
3138 .get_rx_csum = qeth_l3_ethtool_get_rx_csum,
3139 .set_rx_csum = qeth_l3_ethtool_set_rx_csum,
3140 .get_sg = ethtool_op_get_sg,
3141 .set_sg = ethtool_op_set_sg,
3142 .get_tso = ethtool_op_get_tso,
3143 .set_tso = qeth_l3_ethtool_set_tso,
3144 .get_strings = qeth_core_get_strings,
3145 .get_ethtool_stats = qeth_core_get_ethtool_stats,
3146 .get_sset_count = qeth_core_get_sset_count,
3147 .get_drvinfo = qeth_core_get_drvinfo,
3148 .get_settings = qeth_core_ethtool_get_settings,
3152 * we need NOARP for IPv4 but we want neighbor solicitation for IPv6. Setting
3153 * NOARP on the netdevice is no option because it also turns off neighbor
3154 * solicitation. For IPv4 we install a neighbor_setup function. We don't want
3155 * arp resolution but we want the hard header (packet socket will work
3156 * e.g. tcpdump)
3158 static int qeth_l3_neigh_setup_noarp(struct neighbour *n)
3160 n->nud_state = NUD_NOARP;
3161 memcpy(n->ha, "FAKELL", 6);
3162 n->output = n->ops->connected_output;
3163 return 0;
3166 static int
3167 qeth_l3_neigh_setup(struct net_device *dev, struct neigh_parms *np)
3169 if (np->tbl->family == AF_INET)
3170 np->neigh_setup = qeth_l3_neigh_setup_noarp;
3172 return 0;
3175 static const struct net_device_ops qeth_l3_netdev_ops = {
3176 .ndo_open = qeth_l3_open,
3177 .ndo_stop = qeth_l3_stop,
3178 .ndo_get_stats = qeth_get_stats,
3179 .ndo_start_xmit = qeth_l3_hard_start_xmit,
3180 .ndo_validate_addr = eth_validate_addr,
3181 .ndo_set_multicast_list = qeth_l3_set_multicast_list,
3182 .ndo_do_ioctl = qeth_l3_do_ioctl,
3183 .ndo_change_mtu = qeth_change_mtu,
3184 .ndo_vlan_rx_register = qeth_l3_vlan_rx_register,
3185 .ndo_vlan_rx_add_vid = qeth_l3_vlan_rx_add_vid,
3186 .ndo_vlan_rx_kill_vid = qeth_l3_vlan_rx_kill_vid,
3187 .ndo_tx_timeout = qeth_tx_timeout,
3190 static const struct net_device_ops qeth_l3_osa_netdev_ops = {
3191 .ndo_open = qeth_l3_open,
3192 .ndo_stop = qeth_l3_stop,
3193 .ndo_get_stats = qeth_get_stats,
3194 .ndo_start_xmit = qeth_l3_hard_start_xmit,
3195 .ndo_validate_addr = eth_validate_addr,
3196 .ndo_set_multicast_list = qeth_l3_set_multicast_list,
3197 .ndo_do_ioctl = qeth_l3_do_ioctl,
3198 .ndo_change_mtu = qeth_change_mtu,
3199 .ndo_vlan_rx_register = qeth_l3_vlan_rx_register,
3200 .ndo_vlan_rx_add_vid = qeth_l3_vlan_rx_add_vid,
3201 .ndo_vlan_rx_kill_vid = qeth_l3_vlan_rx_kill_vid,
3202 .ndo_tx_timeout = qeth_tx_timeout,
3203 .ndo_neigh_setup = qeth_l3_neigh_setup,
3206 static int qeth_l3_setup_netdev(struct qeth_card *card)
3208 if (card->info.type == QETH_CARD_TYPE_OSAE) {
3209 if ((card->info.link_type == QETH_LINK_TYPE_LANE_TR) ||
3210 (card->info.link_type == QETH_LINK_TYPE_HSTR)) {
3211 #ifdef CONFIG_TR
3212 card->dev = alloc_trdev(0);
3213 #endif
3214 if (!card->dev)
3215 return -ENODEV;
3216 card->dev->netdev_ops = &qeth_l3_netdev_ops;
3217 } else {
3218 card->dev = alloc_etherdev(0);
3219 if (!card->dev)
3220 return -ENODEV;
3221 card->dev->netdev_ops = &qeth_l3_osa_netdev_ops;
3223 /*IPv6 address autoconfiguration stuff*/
3224 qeth_l3_get_unique_id(card);
3225 if (!(card->info.unique_id & UNIQUE_ID_NOT_BY_CARD))
3226 card->dev->dev_id = card->info.unique_id &
3227 0xffff;
3229 } else if (card->info.type == QETH_CARD_TYPE_IQD) {
3230 card->dev = alloc_netdev(0, "hsi%d", ether_setup);
3231 if (!card->dev)
3232 return -ENODEV;
3233 card->dev->flags |= IFF_NOARP;
3234 card->dev->netdev_ops = &qeth_l3_netdev_ops;
3235 qeth_l3_iqd_read_initial_mac(card);
3236 } else
3237 return -ENODEV;
3239 card->dev->ml_priv = card;
3240 card->dev->watchdog_timeo = QETH_TX_TIMEOUT;
3241 card->dev->mtu = card->info.initial_mtu;
3242 SET_ETHTOOL_OPS(card->dev, &qeth_l3_ethtool_ops);
3243 card->dev->features |= NETIF_F_HW_VLAN_TX |
3244 NETIF_F_HW_VLAN_RX |
3245 NETIF_F_HW_VLAN_FILTER;
3246 card->dev->priv_flags &= ~IFF_XMIT_DST_RELEASE;
3247 card->dev->gso_max_size = 15 * PAGE_SIZE;
3249 SET_NETDEV_DEV(card->dev, &card->gdev->dev);
3250 return register_netdev(card->dev);
3253 static void qeth_l3_qdio_input_handler(struct ccw_device *ccwdev,
3254 unsigned int qdio_err, unsigned int queue, int first_element,
3255 int count, unsigned long card_ptr)
3257 struct net_device *net_dev;
3258 struct qeth_card *card;
3259 struct qeth_qdio_buffer *buffer;
3260 int index;
3261 int i;
3263 card = (struct qeth_card *) card_ptr;
3264 net_dev = card->dev;
3265 if (card->options.performance_stats) {
3266 card->perf_stats.inbound_cnt++;
3267 card->perf_stats.inbound_start_time = qeth_get_micros();
3269 if (qdio_err & QDIO_ERROR_ACTIVATE_CHECK_CONDITION) {
3270 QETH_DBF_TEXT(TRACE, 1, "qdinchk");
3271 QETH_DBF_TEXT_(TRACE, 1, "%s", CARD_BUS_ID(card));
3272 QETH_DBF_TEXT_(TRACE, 1, "%04X%04X",
3273 first_element, count);
3274 QETH_DBF_TEXT_(TRACE, 1, "%04X", queue);
3275 qeth_schedule_recovery(card);
3276 return;
3278 for (i = first_element; i < (first_element + count); ++i) {
3279 index = i % QDIO_MAX_BUFFERS_PER_Q;
3280 buffer = &card->qdio.in_q->bufs[index];
3281 if (!(qdio_err &&
3282 qeth_check_qdio_errors(card, buffer->buffer,
3283 qdio_err, "qinerr")))
3284 qeth_l3_process_inbound_buffer(card, buffer, index);
3285 /* clear buffer and give back to hardware */
3286 qeth_put_buffer_pool_entry(card, buffer->pool_entry);
3287 qeth_queue_input_buffer(card, index);
3289 if (card->options.performance_stats)
3290 card->perf_stats.inbound_time += qeth_get_micros() -
3291 card->perf_stats.inbound_start_time;
3294 static int qeth_l3_probe_device(struct ccwgroup_device *gdev)
3296 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3298 qeth_l3_create_device_attributes(&gdev->dev);
3299 card->options.layer2 = 0;
3300 card->discipline.input_handler = (qdio_handler_t *)
3301 qeth_l3_qdio_input_handler;
3302 card->discipline.output_handler = (qdio_handler_t *)
3303 qeth_qdio_output_handler;
3304 card->discipline.recover = qeth_l3_recover;
3305 return 0;
3308 static void qeth_l3_remove_device(struct ccwgroup_device *cgdev)
3310 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
3312 qeth_set_allowed_threads(card, 0, 1);
3313 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
3315 if (cgdev->state == CCWGROUP_ONLINE) {
3316 card->use_hard_stop = 1;
3317 qeth_l3_set_offline(cgdev);
3320 if (card->dev) {
3321 unregister_netdev(card->dev);
3322 card->dev = NULL;
3325 qeth_l3_remove_device_attributes(&cgdev->dev);
3326 qeth_l3_clear_ip_list(card, 0, 0);
3327 qeth_l3_clear_ipato_list(card);
3328 return;
3331 static int __qeth_l3_set_online(struct ccwgroup_device *gdev, int recovery_mode)
3333 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3334 int rc = 0;
3335 enum qeth_card_states recover_flag;
3337 BUG_ON(!card);
3338 QETH_DBF_TEXT(SETUP, 2, "setonlin");
3339 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
3341 recover_flag = card->state;
3342 rc = qeth_core_hardsetup_card(card);
3343 if (rc) {
3344 QETH_DBF_TEXT_(SETUP, 2, "2err%d", rc);
3345 rc = -ENODEV;
3346 goto out_remove;
3349 qeth_l3_query_ipassists(card, QETH_PROT_IPV4);
3351 if (!card->dev && qeth_l3_setup_netdev(card)) {
3352 rc = -ENODEV;
3353 goto out_remove;
3356 card->state = CARD_STATE_HARDSETUP;
3357 qeth_print_status_message(card);
3359 /* softsetup */
3360 QETH_DBF_TEXT(SETUP, 2, "softsetp");
3362 rc = qeth_send_startlan(card);
3363 if (rc) {
3364 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
3365 if (rc == 0xe080) {
3366 dev_warn(&card->gdev->dev,
3367 "The LAN is offline\n");
3368 card->lan_online = 0;
3369 return 0;
3371 rc = -ENODEV;
3372 goto out_remove;
3373 } else
3374 card->lan_online = 1;
3376 rc = qeth_l3_setadapter_parms(card);
3377 if (rc)
3378 QETH_DBF_TEXT_(SETUP, 2, "2err%d", rc);
3379 if (!card->options.sniffer) {
3380 rc = qeth_l3_start_ipassists(card);
3381 if (rc)
3382 QETH_DBF_TEXT_(SETUP, 2, "3err%d", rc);
3383 qeth_l3_set_large_send(card, card->options.large_send);
3384 rc = qeth_l3_setrouting_v4(card);
3385 if (rc)
3386 QETH_DBF_TEXT_(SETUP, 2, "4err%d", rc);
3387 rc = qeth_l3_setrouting_v6(card);
3388 if (rc)
3389 QETH_DBF_TEXT_(SETUP, 2, "5err%d", rc);
3391 netif_tx_disable(card->dev);
3393 rc = qeth_init_qdio_queues(card);
3394 if (rc) {
3395 QETH_DBF_TEXT_(SETUP, 2, "6err%d", rc);
3396 rc = -ENODEV;
3397 goto out_remove;
3399 card->state = CARD_STATE_SOFTSETUP;
3400 netif_carrier_on(card->dev);
3402 qeth_set_allowed_threads(card, 0xffffffff, 0);
3403 qeth_l3_set_ip_addr_list(card);
3404 if (recover_flag == CARD_STATE_RECOVER) {
3405 if (recovery_mode)
3406 qeth_l3_open(card->dev);
3407 else {
3408 rtnl_lock();
3409 dev_open(card->dev);
3410 rtnl_unlock();
3412 qeth_l3_set_multicast_list(card->dev);
3414 /* let user_space know that device is online */
3415 kobject_uevent(&gdev->dev.kobj, KOBJ_CHANGE);
3416 return 0;
3417 out_remove:
3418 card->use_hard_stop = 1;
3419 qeth_l3_stop_card(card, 0);
3420 ccw_device_set_offline(CARD_DDEV(card));
3421 ccw_device_set_offline(CARD_WDEV(card));
3422 ccw_device_set_offline(CARD_RDEV(card));
3423 if (recover_flag == CARD_STATE_RECOVER)
3424 card->state = CARD_STATE_RECOVER;
3425 else
3426 card->state = CARD_STATE_DOWN;
3427 return rc;
3430 static int qeth_l3_set_online(struct ccwgroup_device *gdev)
3432 return __qeth_l3_set_online(gdev, 0);
3435 static int __qeth_l3_set_offline(struct ccwgroup_device *cgdev,
3436 int recovery_mode)
3438 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
3439 int rc = 0, rc2 = 0, rc3 = 0;
3440 enum qeth_card_states recover_flag;
3442 QETH_DBF_TEXT(SETUP, 3, "setoffl");
3443 QETH_DBF_HEX(SETUP, 3, &card, sizeof(void *));
3445 if (card->dev && netif_carrier_ok(card->dev))
3446 netif_carrier_off(card->dev);
3447 recover_flag = card->state;
3448 qeth_l3_stop_card(card, recovery_mode);
3449 rc = ccw_device_set_offline(CARD_DDEV(card));
3450 rc2 = ccw_device_set_offline(CARD_WDEV(card));
3451 rc3 = ccw_device_set_offline(CARD_RDEV(card));
3452 if (!rc)
3453 rc = (rc2) ? rc2 : rc3;
3454 if (rc)
3455 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
3456 if (recover_flag == CARD_STATE_UP)
3457 card->state = CARD_STATE_RECOVER;
3458 /* let user_space know that device is offline */
3459 kobject_uevent(&cgdev->dev.kobj, KOBJ_CHANGE);
3460 return 0;
3463 static int qeth_l3_set_offline(struct ccwgroup_device *cgdev)
3465 return __qeth_l3_set_offline(cgdev, 0);
3468 static int qeth_l3_recover(void *ptr)
3470 struct qeth_card *card;
3471 int rc = 0;
3473 card = (struct qeth_card *) ptr;
3474 QETH_DBF_TEXT(TRACE, 2, "recover1");
3475 QETH_DBF_HEX(TRACE, 2, &card, sizeof(void *));
3476 if (!qeth_do_run_thread(card, QETH_RECOVER_THREAD))
3477 return 0;
3478 QETH_DBF_TEXT(TRACE, 2, "recover2");
3479 dev_warn(&card->gdev->dev,
3480 "A recovery process has been started for the device\n");
3481 card->use_hard_stop = 1;
3482 __qeth_l3_set_offline(card->gdev, 1);
3483 rc = __qeth_l3_set_online(card->gdev, 1);
3484 /* don't run another scheduled recovery */
3485 qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD);
3486 qeth_clear_thread_running_bit(card, QETH_RECOVER_THREAD);
3487 if (!rc)
3488 dev_info(&card->gdev->dev,
3489 "Device successfully recovered!\n");
3490 else {
3491 rtnl_lock();
3492 dev_close(card->dev);
3493 rtnl_unlock();
3494 dev_warn(&card->gdev->dev, "The qeth device driver "
3495 "failed to recover an error on the device\n");
3497 return 0;
3500 static void qeth_l3_shutdown(struct ccwgroup_device *gdev)
3502 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3503 qeth_l3_clear_ip_list(card, 0, 0);
3504 qeth_qdio_clear_card(card, 0);
3505 qeth_clear_qdio_buffers(card);
3508 static int qeth_l3_pm_suspend(struct ccwgroup_device *gdev)
3510 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3512 if (card->dev)
3513 netif_device_detach(card->dev);
3514 qeth_set_allowed_threads(card, 0, 1);
3515 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
3516 if (gdev->state == CCWGROUP_OFFLINE)
3517 return 0;
3518 if (card->state == CARD_STATE_UP) {
3519 card->use_hard_stop = 1;
3520 __qeth_l3_set_offline(card->gdev, 1);
3521 } else
3522 __qeth_l3_set_offline(card->gdev, 0);
3523 return 0;
3526 static int qeth_l3_pm_resume(struct ccwgroup_device *gdev)
3528 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3529 int rc = 0;
3531 if (gdev->state == CCWGROUP_OFFLINE)
3532 goto out;
3534 if (card->state == CARD_STATE_RECOVER) {
3535 rc = __qeth_l3_set_online(card->gdev, 1);
3536 if (rc) {
3537 rtnl_lock();
3538 dev_close(card->dev);
3539 rtnl_unlock();
3541 } else
3542 rc = __qeth_l3_set_online(card->gdev, 0);
3543 out:
3544 qeth_set_allowed_threads(card, 0xffffffff, 0);
3545 if (card->dev)
3546 netif_device_attach(card->dev);
3547 if (rc)
3548 dev_warn(&card->gdev->dev, "The qeth device driver "
3549 "failed to recover an error on the device\n");
3550 return rc;
3553 struct ccwgroup_driver qeth_l3_ccwgroup_driver = {
3554 .probe = qeth_l3_probe_device,
3555 .remove = qeth_l3_remove_device,
3556 .set_online = qeth_l3_set_online,
3557 .set_offline = qeth_l3_set_offline,
3558 .shutdown = qeth_l3_shutdown,
3559 .freeze = qeth_l3_pm_suspend,
3560 .thaw = qeth_l3_pm_resume,
3561 .restore = qeth_l3_pm_resume,
3563 EXPORT_SYMBOL_GPL(qeth_l3_ccwgroup_driver);
3565 static int qeth_l3_ip_event(struct notifier_block *this,
3566 unsigned long event, void *ptr)
3568 struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;
3569 struct net_device *dev = (struct net_device *)ifa->ifa_dev->dev;
3570 struct qeth_ipaddr *addr;
3571 struct qeth_card *card;
3573 if (dev_net(dev) != &init_net)
3574 return NOTIFY_DONE;
3576 QETH_DBF_TEXT(TRACE, 3, "ipevent");
3577 card = qeth_l3_get_card_from_dev(dev);
3578 if (!card)
3579 return NOTIFY_DONE;
3581 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
3582 if (addr != NULL) {
3583 addr->u.a4.addr = ifa->ifa_address;
3584 addr->u.a4.mask = ifa->ifa_mask;
3585 addr->type = QETH_IP_TYPE_NORMAL;
3586 } else
3587 goto out;
3589 switch (event) {
3590 case NETDEV_UP:
3591 if (!qeth_l3_add_ip(card, addr))
3592 kfree(addr);
3593 break;
3594 case NETDEV_DOWN:
3595 if (!qeth_l3_delete_ip(card, addr))
3596 kfree(addr);
3597 break;
3598 default:
3599 break;
3601 qeth_l3_set_ip_addr_list(card);
3602 out:
3603 return NOTIFY_DONE;
3606 static struct notifier_block qeth_l3_ip_notifier = {
3607 qeth_l3_ip_event,
3608 NULL,
3611 #ifdef CONFIG_QETH_IPV6
3613 * IPv6 event handler
3615 static int qeth_l3_ip6_event(struct notifier_block *this,
3616 unsigned long event, void *ptr)
3618 struct inet6_ifaddr *ifa = (struct inet6_ifaddr *)ptr;
3619 struct net_device *dev = (struct net_device *)ifa->idev->dev;
3620 struct qeth_ipaddr *addr;
3621 struct qeth_card *card;
3623 QETH_DBF_TEXT(TRACE, 3, "ip6event");
3625 card = qeth_l3_get_card_from_dev(dev);
3626 if (!card)
3627 return NOTIFY_DONE;
3628 if (!qeth_is_supported(card, IPA_IPV6))
3629 return NOTIFY_DONE;
3631 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
3632 if (addr != NULL) {
3633 memcpy(&addr->u.a6.addr, &ifa->addr, sizeof(struct in6_addr));
3634 addr->u.a6.pfxlen = ifa->prefix_len;
3635 addr->type = QETH_IP_TYPE_NORMAL;
3636 } else
3637 goto out;
3639 switch (event) {
3640 case NETDEV_UP:
3641 if (!qeth_l3_add_ip(card, addr))
3642 kfree(addr);
3643 break;
3644 case NETDEV_DOWN:
3645 if (!qeth_l3_delete_ip(card, addr))
3646 kfree(addr);
3647 break;
3648 default:
3649 break;
3651 qeth_l3_set_ip_addr_list(card);
3652 out:
3653 return NOTIFY_DONE;
3656 static struct notifier_block qeth_l3_ip6_notifier = {
3657 qeth_l3_ip6_event,
3658 NULL,
3660 #endif
3662 static int qeth_l3_register_notifiers(void)
3664 int rc;
3666 QETH_DBF_TEXT(TRACE, 5, "regnotif");
3667 rc = register_inetaddr_notifier(&qeth_l3_ip_notifier);
3668 if (rc)
3669 return rc;
3670 #ifdef CONFIG_QETH_IPV6
3671 rc = register_inet6addr_notifier(&qeth_l3_ip6_notifier);
3672 if (rc) {
3673 unregister_inetaddr_notifier(&qeth_l3_ip_notifier);
3674 return rc;
3676 #else
3677 pr_warning("There is no IPv6 support for the layer 3 discipline\n");
3678 #endif
3679 return 0;
3682 static void qeth_l3_unregister_notifiers(void)
3685 QETH_DBF_TEXT(TRACE, 5, "unregnot");
3686 BUG_ON(unregister_inetaddr_notifier(&qeth_l3_ip_notifier));
3687 #ifdef CONFIG_QETH_IPV6
3688 BUG_ON(unregister_inet6addr_notifier(&qeth_l3_ip6_notifier));
3689 #endif /* QETH_IPV6 */
3692 static int __init qeth_l3_init(void)
3694 int rc = 0;
3696 pr_info("register layer 3 discipline\n");
3697 rc = qeth_l3_register_notifiers();
3698 return rc;
3701 static void __exit qeth_l3_exit(void)
3703 qeth_l3_unregister_notifiers();
3704 pr_info("unregister layer 3 discipline\n");
3707 module_init(qeth_l3_init);
3708 module_exit(qeth_l3_exit);
3709 MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
3710 MODULE_DESCRIPTION("qeth layer 3 discipline");
3711 MODULE_LICENSE("GPL");