blob: cfda1ecffdf24db5e60122706f514c23c2ef2db0 [file] [log] [blame]
Frank Blaschka4a71df52008-02-15 09:19:42 +01001/*
2 * drivers/s390/net/qeth_l3_main.c
3 *
4 * Copyright IBM Corp. 2007
5 * Author(s): Utz Bacher <utz.bacher@de.ibm.com>,
6 * Frank Pavlic <fpavlic@de.ibm.com>,
7 * Thomas Spatzier <tspat@de.ibm.com>,
8 * Frank Blaschka <frank.blaschka@de.ibm.com>
9 */
10
Frank Blaschka74eacdb2008-12-25 13:39:49 +010011#define KMSG_COMPONENT "qeth"
12#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
13
Frank Blaschka4a71df52008-02-15 09:19:42 +010014#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/reboot.h>
23#include <linux/inetdevice.h>
24#include <linux/igmp.h>
25
26#include <net/ip.h>
27#include <net/arp.h>
28
29#include <asm/s390_rdev.h>
30
31#include "qeth_l3.h"
32#include "qeth_core_offl.h"
33
Frank Blaschka4a71df52008-02-15 09:19:42 +010034static int qeth_l3_set_offline(struct ccwgroup_device *);
35static int qeth_l3_recover(void *);
36static int qeth_l3_stop(struct net_device *);
37static void qeth_l3_set_multicast_list(struct net_device *);
38static int qeth_l3_neigh_setup(struct net_device *, struct neigh_parms *);
39static int qeth_l3_register_addr_entry(struct qeth_card *,
40 struct qeth_ipaddr *);
41static int qeth_l3_deregister_addr_entry(struct qeth_card *,
42 struct qeth_ipaddr *);
43static int __qeth_l3_set_online(struct ccwgroup_device *, int);
44static int __qeth_l3_set_offline(struct ccwgroup_device *, int);
45
46
47static int qeth_l3_isxdigit(char *buf)
48{
49 while (*buf) {
50 if (!isxdigit(*buf++))
51 return 0;
52 }
53 return 1;
54}
55
56void qeth_l3_ipaddr4_to_string(const __u8 *addr, char *buf)
57{
58 sprintf(buf, "%i.%i.%i.%i", addr[0], addr[1], addr[2], addr[3]);
59}
60
61int qeth_l3_string_to_ipaddr4(const char *buf, __u8 *addr)
62{
63 int count = 0, rc = 0;
64 int in[4];
65 char c;
66
67 rc = sscanf(buf, "%u.%u.%u.%u%c",
68 &in[0], &in[1], &in[2], &in[3], &c);
69 if (rc != 4 && (rc != 5 || c != '\n'))
70 return -EINVAL;
71 for (count = 0; count < 4; count++) {
72 if (in[count] > 255)
73 return -EINVAL;
74 addr[count] = in[count];
75 }
76 return 0;
77}
78
79void qeth_l3_ipaddr6_to_string(const __u8 *addr, char *buf)
80{
81 sprintf(buf, "%02x%02x:%02x%02x:%02x%02x:%02x%02x"
82 ":%02x%02x:%02x%02x:%02x%02x:%02x%02x",
83 addr[0], addr[1], addr[2], addr[3],
84 addr[4], addr[5], addr[6], addr[7],
85 addr[8], addr[9], addr[10], addr[11],
86 addr[12], addr[13], addr[14], addr[15]);
87}
88
89int qeth_l3_string_to_ipaddr6(const char *buf, __u8 *addr)
90{
91 const char *end, *end_tmp, *start;
92 __u16 *in;
93 char num[5];
94 int num2, cnt, out, found, save_cnt;
95 unsigned short in_tmp[8] = {0, };
96
97 cnt = out = found = save_cnt = num2 = 0;
98 end = start = buf;
99 in = (__u16 *) addr;
100 memset(in, 0, 16);
101 while (*end) {
102 end = strchr(start, ':');
103 if (end == NULL) {
104 end = buf + strlen(buf);
105 end_tmp = strchr(start, '\n');
106 if (end_tmp != NULL)
107 end = end_tmp;
108 out = 1;
109 }
110 if ((end - start)) {
111 memset(num, 0, 5);
112 if ((end - start) > 4)
113 return -EINVAL;
114 memcpy(num, start, end - start);
115 if (!qeth_l3_isxdigit(num))
116 return -EINVAL;
117 sscanf(start, "%x", &num2);
118 if (found)
119 in_tmp[save_cnt++] = num2;
120 else
121 in[cnt++] = num2;
122 if (out)
123 break;
124 } else {
125 if (found)
126 return -EINVAL;
127 found = 1;
128 }
129 start = ++end;
130 }
131 if (cnt + save_cnt > 8)
132 return -EINVAL;
133 cnt = 7;
134 while (save_cnt)
135 in[cnt--] = in_tmp[--save_cnt];
136 return 0;
137}
138
139void qeth_l3_ipaddr_to_string(enum qeth_prot_versions proto, const __u8 *addr,
140 char *buf)
141{
142 if (proto == QETH_PROT_IPV4)
143 qeth_l3_ipaddr4_to_string(addr, buf);
144 else if (proto == QETH_PROT_IPV6)
145 qeth_l3_ipaddr6_to_string(addr, buf);
146}
147
148int qeth_l3_string_to_ipaddr(const char *buf, enum qeth_prot_versions proto,
149 __u8 *addr)
150{
151 if (proto == QETH_PROT_IPV4)
152 return qeth_l3_string_to_ipaddr4(buf, addr);
153 else if (proto == QETH_PROT_IPV6)
154 return qeth_l3_string_to_ipaddr6(buf, addr);
155 else
156 return -EINVAL;
157}
158
159static void qeth_l3_convert_addr_to_bits(u8 *addr, u8 *bits, int len)
160{
161 int i, j;
162 u8 octet;
163
164 for (i = 0; i < len; ++i) {
165 octet = addr[i];
166 for (j = 7; j >= 0; --j) {
167 bits[i*8 + j] = octet & 1;
168 octet >>= 1;
169 }
170 }
171}
172
173static int qeth_l3_is_addr_covered_by_ipato(struct qeth_card *card,
174 struct qeth_ipaddr *addr)
175{
176 struct qeth_ipato_entry *ipatoe;
177 u8 addr_bits[128] = {0, };
178 u8 ipatoe_bits[128] = {0, };
179 int rc = 0;
180
181 if (!card->ipato.enabled)
182 return 0;
183
184 qeth_l3_convert_addr_to_bits((u8 *) &addr->u, addr_bits,
185 (addr->proto == QETH_PROT_IPV4)? 4:16);
186 list_for_each_entry(ipatoe, &card->ipato.entries, entry) {
187 if (addr->proto != ipatoe->proto)
188 continue;
189 qeth_l3_convert_addr_to_bits(ipatoe->addr, ipatoe_bits,
190 (ipatoe->proto == QETH_PROT_IPV4) ?
191 4 : 16);
192 if (addr->proto == QETH_PROT_IPV4)
193 rc = !memcmp(addr_bits, ipatoe_bits,
194 min(32, ipatoe->mask_bits));
195 else
196 rc = !memcmp(addr_bits, ipatoe_bits,
197 min(128, ipatoe->mask_bits));
198 if (rc)
199 break;
200 }
201 /* invert? */
202 if ((addr->proto == QETH_PROT_IPV4) && card->ipato.invert4)
203 rc = !rc;
204 else if ((addr->proto == QETH_PROT_IPV6) && card->ipato.invert6)
205 rc = !rc;
206
207 return rc;
208}
209
210/*
211 * Add IP to be added to todo list. If there is already an "add todo"
212 * in this list we just incremenent the reference count.
213 * Returns 0 if we just incremented reference count.
214 */
215static int __qeth_l3_insert_ip_todo(struct qeth_card *card,
216 struct qeth_ipaddr *addr, int add)
217{
218 struct qeth_ipaddr *tmp, *t;
219 int found = 0;
220
221 list_for_each_entry_safe(tmp, t, card->ip_tbd_list, entry) {
222 if ((addr->type == QETH_IP_TYPE_DEL_ALL_MC) &&
223 (tmp->type == QETH_IP_TYPE_DEL_ALL_MC))
224 return 0;
225 if ((tmp->proto == QETH_PROT_IPV4) &&
226 (addr->proto == QETH_PROT_IPV4) &&
227 (tmp->type == addr->type) &&
228 (tmp->is_multicast == addr->is_multicast) &&
229 (tmp->u.a4.addr == addr->u.a4.addr) &&
230 (tmp->u.a4.mask == addr->u.a4.mask)) {
231 found = 1;
232 break;
233 }
234 if ((tmp->proto == QETH_PROT_IPV6) &&
235 (addr->proto == QETH_PROT_IPV6) &&
236 (tmp->type == addr->type) &&
237 (tmp->is_multicast == addr->is_multicast) &&
238 (tmp->u.a6.pfxlen == addr->u.a6.pfxlen) &&
239 (memcmp(&tmp->u.a6.addr, &addr->u.a6.addr,
240 sizeof(struct in6_addr)) == 0)) {
241 found = 1;
242 break;
243 }
244 }
245 if (found) {
246 if (addr->users != 0)
247 tmp->users += addr->users;
248 else
249 tmp->users += add ? 1 : -1;
250 if (tmp->users == 0) {
251 list_del(&tmp->entry);
252 kfree(tmp);
253 }
254 return 0;
255 } else {
256 if (addr->type == QETH_IP_TYPE_DEL_ALL_MC)
257 list_add(&addr->entry, card->ip_tbd_list);
258 else {
259 if (addr->users == 0)
260 addr->users += add ? 1 : -1;
261 if (add && (addr->type == QETH_IP_TYPE_NORMAL) &&
262 qeth_l3_is_addr_covered_by_ipato(card, addr)) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200263 QETH_DBF_TEXT(TRACE, 2, "tkovaddr");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100264 addr->set_flags |= QETH_IPA_SETIP_TAKEOVER_FLAG;
265 }
266 list_add_tail(&addr->entry, card->ip_tbd_list);
267 }
268 return 1;
269 }
270}
271
272static int qeth_l3_delete_ip(struct qeth_card *card, struct qeth_ipaddr *addr)
273{
274 unsigned long flags;
275 int rc = 0;
276
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200277 QETH_DBF_TEXT(TRACE, 4, "delip");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100278
279 if (addr->proto == QETH_PROT_IPV4)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200280 QETH_DBF_HEX(TRACE, 4, &addr->u.a4.addr, 4);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100281 else {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200282 QETH_DBF_HEX(TRACE, 4, &addr->u.a6.addr, 8);
283 QETH_DBF_HEX(TRACE, 4, ((char *)&addr->u.a6.addr) + 8, 8);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100284 }
285 spin_lock_irqsave(&card->ip_lock, flags);
286 rc = __qeth_l3_insert_ip_todo(card, addr, 0);
287 spin_unlock_irqrestore(&card->ip_lock, flags);
288 return rc;
289}
290
291static int qeth_l3_add_ip(struct qeth_card *card, struct qeth_ipaddr *addr)
292{
293 unsigned long flags;
294 int rc = 0;
295
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200296 QETH_DBF_TEXT(TRACE, 4, "addip");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100297 if (addr->proto == QETH_PROT_IPV4)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200298 QETH_DBF_HEX(TRACE, 4, &addr->u.a4.addr, 4);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100299 else {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200300 QETH_DBF_HEX(TRACE, 4, &addr->u.a6.addr, 8);
301 QETH_DBF_HEX(TRACE, 4, ((char *)&addr->u.a6.addr) + 8, 8);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100302 }
303 spin_lock_irqsave(&card->ip_lock, flags);
304 rc = __qeth_l3_insert_ip_todo(card, addr, 1);
305 spin_unlock_irqrestore(&card->ip_lock, flags);
306 return rc;
307}
308
309
310static struct qeth_ipaddr *qeth_l3_get_addr_buffer(
311 enum qeth_prot_versions prot)
312{
313 struct qeth_ipaddr *addr;
314
315 addr = kzalloc(sizeof(struct qeth_ipaddr), GFP_ATOMIC);
316 if (addr == NULL) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100317 return NULL;
318 }
319 addr->type = QETH_IP_TYPE_NORMAL;
320 addr->proto = prot;
321 return addr;
322}
323
324static void qeth_l3_delete_mc_addresses(struct qeth_card *card)
325{
326 struct qeth_ipaddr *iptodo;
327 unsigned long flags;
328
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200329 QETH_DBF_TEXT(TRACE, 4, "delmc");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100330 iptodo = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
331 if (!iptodo) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200332 QETH_DBF_TEXT(TRACE, 2, "dmcnomem");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100333 return;
334 }
335 iptodo->type = QETH_IP_TYPE_DEL_ALL_MC;
336 spin_lock_irqsave(&card->ip_lock, flags);
337 if (!__qeth_l3_insert_ip_todo(card, iptodo, 0))
338 kfree(iptodo);
339 spin_unlock_irqrestore(&card->ip_lock, flags);
340}
341
342/*
343 * Add/remove address to/from card's ip list, i.e. try to add or remove
344 * reference to/from an IP address that is already registered on the card.
345 * Returns:
346 * 0 address was on card and its reference count has been adjusted,
347 * but is still > 0, so nothing has to be done
348 * also returns 0 if card was not on card and the todo was to delete
349 * the address -> there is also nothing to be done
350 * 1 address was not on card and the todo is to add it to the card's ip
351 * list
352 * -1 address was on card and its reference count has been decremented
353 * to <= 0 by the todo -> address must be removed from card
354 */
355static int __qeth_l3_ref_ip_on_card(struct qeth_card *card,
356 struct qeth_ipaddr *todo, struct qeth_ipaddr **__addr)
357{
358 struct qeth_ipaddr *addr;
359 int found = 0;
360
361 list_for_each_entry(addr, &card->ip_list, entry) {
362 if ((addr->proto == QETH_PROT_IPV4) &&
363 (todo->proto == QETH_PROT_IPV4) &&
364 (addr->type == todo->type) &&
365 (addr->u.a4.addr == todo->u.a4.addr) &&
366 (addr->u.a4.mask == todo->u.a4.mask)) {
367 found = 1;
368 break;
369 }
370 if ((addr->proto == QETH_PROT_IPV6) &&
371 (todo->proto == QETH_PROT_IPV6) &&
372 (addr->type == todo->type) &&
373 (addr->u.a6.pfxlen == todo->u.a6.pfxlen) &&
374 (memcmp(&addr->u.a6.addr, &todo->u.a6.addr,
375 sizeof(struct in6_addr)) == 0)) {
376 found = 1;
377 break;
378 }
379 }
380 if (found) {
381 addr->users += todo->users;
382 if (addr->users <= 0) {
383 *__addr = addr;
384 return -1;
385 } else {
386 /* for VIPA and RXIP limit refcount to 1 */
387 if (addr->type != QETH_IP_TYPE_NORMAL)
388 addr->users = 1;
389 return 0;
390 }
391 }
392 if (todo->users > 0) {
393 /* for VIPA and RXIP limit refcount to 1 */
394 if (todo->type != QETH_IP_TYPE_NORMAL)
395 todo->users = 1;
396 return 1;
397 } else
398 return 0;
399}
400
401static void __qeth_l3_delete_all_mc(struct qeth_card *card,
402 unsigned long *flags)
403{
Ursula Braun2d921c32008-04-01 10:26:53 +0200404 struct list_head fail_list;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100405 struct qeth_ipaddr *addr, *tmp;
406 int rc;
Ursula Braun2d921c32008-04-01 10:26:53 +0200407
408 INIT_LIST_HEAD(&fail_list);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100409again:
410 list_for_each_entry_safe(addr, tmp, &card->ip_list, entry) {
411 if (addr->is_multicast) {
412 list_del(&addr->entry);
413 spin_unlock_irqrestore(&card->ip_lock, *flags);
414 rc = qeth_l3_deregister_addr_entry(card, addr);
415 spin_lock_irqsave(&card->ip_lock, *flags);
Ursula Braun2d921c32008-04-01 10:26:53 +0200416 if (!rc || (rc == IPA_RC_MC_ADDR_NOT_FOUND))
Frank Blaschka4a71df52008-02-15 09:19:42 +0100417 kfree(addr);
Ursula Braun2d921c32008-04-01 10:26:53 +0200418 else
419 list_add_tail(&addr->entry, &fail_list);
420 goto again;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100421 }
422 }
Ursula Braun2d921c32008-04-01 10:26:53 +0200423 list_splice(&fail_list, &card->ip_list);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100424}
425
426static void qeth_l3_set_ip_addr_list(struct qeth_card *card)
427{
428 struct list_head *tbd_list;
429 struct qeth_ipaddr *todo, *addr;
430 unsigned long flags;
431 int rc;
432
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200433 QETH_DBF_TEXT(TRACE, 2, "sdiplist");
434 QETH_DBF_HEX(TRACE, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100435
436 spin_lock_irqsave(&card->ip_lock, flags);
437 tbd_list = card->ip_tbd_list;
438 card->ip_tbd_list = kmalloc(sizeof(struct list_head), GFP_ATOMIC);
439 if (!card->ip_tbd_list) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200440 QETH_DBF_TEXT(TRACE, 0, "silnomem");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100441 card->ip_tbd_list = tbd_list;
442 spin_unlock_irqrestore(&card->ip_lock, flags);
443 return;
444 } else
445 INIT_LIST_HEAD(card->ip_tbd_list);
446
447 while (!list_empty(tbd_list)) {
448 todo = list_entry(tbd_list->next, struct qeth_ipaddr, entry);
449 list_del(&todo->entry);
450 if (todo->type == QETH_IP_TYPE_DEL_ALL_MC) {
451 __qeth_l3_delete_all_mc(card, &flags);
452 kfree(todo);
453 continue;
454 }
455 rc = __qeth_l3_ref_ip_on_card(card, todo, &addr);
456 if (rc == 0) {
457 /* nothing to be done; only adjusted refcount */
458 kfree(todo);
459 } else if (rc == 1) {
460 /* new entry to be added to on-card list */
461 spin_unlock_irqrestore(&card->ip_lock, flags);
462 rc = qeth_l3_register_addr_entry(card, todo);
463 spin_lock_irqsave(&card->ip_lock, flags);
Ursula Braun3caa4af2008-04-01 10:27:00 +0200464 if (!rc || (rc == IPA_RC_LAN_OFFLINE))
Frank Blaschka4a71df52008-02-15 09:19:42 +0100465 list_add_tail(&todo->entry, &card->ip_list);
466 else
467 kfree(todo);
468 } else if (rc == -1) {
469 /* on-card entry to be removed */
470 list_del_init(&addr->entry);
471 spin_unlock_irqrestore(&card->ip_lock, flags);
472 rc = qeth_l3_deregister_addr_entry(card, addr);
473 spin_lock_irqsave(&card->ip_lock, flags);
Ursula Braun2d921c32008-04-01 10:26:53 +0200474 if (!rc || (rc == IPA_RC_PRIMARY_ALREADY_DEFINED))
Frank Blaschka4a71df52008-02-15 09:19:42 +0100475 kfree(addr);
476 else
477 list_add_tail(&addr->entry, &card->ip_list);
478 kfree(todo);
479 }
480 }
481 spin_unlock_irqrestore(&card->ip_lock, flags);
482 kfree(tbd_list);
483}
484
485static void qeth_l3_clear_ip_list(struct qeth_card *card, int clean,
486 int recover)
487{
488 struct qeth_ipaddr *addr, *tmp;
489 unsigned long flags;
490
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200491 QETH_DBF_TEXT(TRACE, 4, "clearip");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100492 spin_lock_irqsave(&card->ip_lock, flags);
493 /* clear todo list */
494 list_for_each_entry_safe(addr, tmp, card->ip_tbd_list, entry) {
495 list_del(&addr->entry);
496 kfree(addr);
497 }
498
499 while (!list_empty(&card->ip_list)) {
500 addr = list_entry(card->ip_list.next,
501 struct qeth_ipaddr, entry);
502 list_del_init(&addr->entry);
503 if (clean) {
504 spin_unlock_irqrestore(&card->ip_lock, flags);
505 qeth_l3_deregister_addr_entry(card, addr);
506 spin_lock_irqsave(&card->ip_lock, flags);
507 }
508 if (!recover || addr->is_multicast) {
509 kfree(addr);
510 continue;
511 }
512 list_add_tail(&addr->entry, card->ip_tbd_list);
513 }
514 spin_unlock_irqrestore(&card->ip_lock, flags);
515}
516
517static int qeth_l3_address_exists_in_list(struct list_head *list,
518 struct qeth_ipaddr *addr, int same_type)
519{
520 struct qeth_ipaddr *tmp;
521
522 list_for_each_entry(tmp, list, entry) {
523 if ((tmp->proto == QETH_PROT_IPV4) &&
524 (addr->proto == QETH_PROT_IPV4) &&
525 ((same_type && (tmp->type == addr->type)) ||
526 (!same_type && (tmp->type != addr->type))) &&
527 (tmp->u.a4.addr == addr->u.a4.addr))
528 return 1;
529
530 if ((tmp->proto == QETH_PROT_IPV6) &&
531 (addr->proto == QETH_PROT_IPV6) &&
532 ((same_type && (tmp->type == addr->type)) ||
533 (!same_type && (tmp->type != addr->type))) &&
534 (memcmp(&tmp->u.a6.addr, &addr->u.a6.addr,
535 sizeof(struct in6_addr)) == 0))
536 return 1;
537
538 }
539 return 0;
540}
541
542static int qeth_l3_send_setdelmc(struct qeth_card *card,
543 struct qeth_ipaddr *addr, int ipacmd)
544{
545 int rc;
546 struct qeth_cmd_buffer *iob;
547 struct qeth_ipa_cmd *cmd;
548
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200549 QETH_DBF_TEXT(TRACE, 4, "setdelmc");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100550
551 iob = qeth_get_ipacmd_buffer(card, ipacmd, addr->proto);
552 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
553 memcpy(&cmd->data.setdelipm.mac, addr->mac, OSA_ADDR_LEN);
554 if (addr->proto == QETH_PROT_IPV6)
555 memcpy(cmd->data.setdelipm.ip6, &addr->u.a6.addr,
556 sizeof(struct in6_addr));
557 else
558 memcpy(&cmd->data.setdelipm.ip4, &addr->u.a4.addr, 4);
559
560 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
561
562 return rc;
563}
564
565static void qeth_l3_fill_netmask(u8 *netmask, unsigned int len)
566{
567 int i, j;
568 for (i = 0; i < 16; i++) {
569 j = (len) - (i * 8);
570 if (j >= 8)
571 netmask[i] = 0xff;
572 else if (j > 0)
573 netmask[i] = (u8)(0xFF00 >> j);
574 else
575 netmask[i] = 0;
576 }
577}
578
579static int qeth_l3_send_setdelip(struct qeth_card *card,
580 struct qeth_ipaddr *addr, int ipacmd, unsigned int flags)
581{
582 int rc;
583 struct qeth_cmd_buffer *iob;
584 struct qeth_ipa_cmd *cmd;
585 __u8 netmask[16];
586
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200587 QETH_DBF_TEXT(TRACE, 4, "setdelip");
588 QETH_DBF_TEXT_(TRACE, 4, "flags%02X", flags);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100589
590 iob = qeth_get_ipacmd_buffer(card, ipacmd, addr->proto);
591 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
592 if (addr->proto == QETH_PROT_IPV6) {
593 memcpy(cmd->data.setdelip6.ip_addr, &addr->u.a6.addr,
594 sizeof(struct in6_addr));
595 qeth_l3_fill_netmask(netmask, addr->u.a6.pfxlen);
596 memcpy(cmd->data.setdelip6.mask, netmask,
597 sizeof(struct in6_addr));
598 cmd->data.setdelip6.flags = flags;
599 } else {
600 memcpy(cmd->data.setdelip4.ip_addr, &addr->u.a4.addr, 4);
601 memcpy(cmd->data.setdelip4.mask, &addr->u.a4.mask, 4);
602 cmd->data.setdelip4.flags = flags;
603 }
604
605 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
606
607 return rc;
608}
609
610static int qeth_l3_send_setrouting(struct qeth_card *card,
611 enum qeth_routing_types type, enum qeth_prot_versions prot)
612{
613 int rc;
614 struct qeth_ipa_cmd *cmd;
615 struct qeth_cmd_buffer *iob;
616
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200617 QETH_DBF_TEXT(TRACE, 4, "setroutg");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100618 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SETRTG, prot);
619 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
620 cmd->data.setrtg.type = (type);
621 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
622
623 return rc;
624}
625
626static void qeth_l3_correct_routing_type(struct qeth_card *card,
627 enum qeth_routing_types *type, enum qeth_prot_versions prot)
628{
629 if (card->info.type == QETH_CARD_TYPE_IQD) {
630 switch (*type) {
631 case NO_ROUTER:
632 case PRIMARY_CONNECTOR:
633 case SECONDARY_CONNECTOR:
634 case MULTICAST_ROUTER:
635 return;
636 default:
637 goto out_inval;
638 }
639 } else {
640 switch (*type) {
641 case NO_ROUTER:
642 case PRIMARY_ROUTER:
643 case SECONDARY_ROUTER:
644 return;
645 case MULTICAST_ROUTER:
646 if (qeth_is_ipafunc_supported(card, prot,
647 IPA_OSA_MC_ROUTER))
648 return;
649 default:
650 goto out_inval;
651 }
652 }
653out_inval:
Frank Blaschka4a71df52008-02-15 09:19:42 +0100654 *type = NO_ROUTER;
655}
656
657int qeth_l3_setrouting_v4(struct qeth_card *card)
658{
659 int rc;
660
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200661 QETH_DBF_TEXT(TRACE, 3, "setrtg4");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100662
663 qeth_l3_correct_routing_type(card, &card->options.route4.type,
664 QETH_PROT_IPV4);
665
666 rc = qeth_l3_send_setrouting(card, card->options.route4.type,
667 QETH_PROT_IPV4);
668 if (rc) {
669 card->options.route4.type = NO_ROUTER;
Frank Blaschka14cc21b2008-06-06 12:37:46 +0200670 QETH_DBF_MESSAGE(2, "Error (0x%04x) while setting routing type"
671 " on %s. Type set to 'no router'.\n", rc,
672 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100673 }
674 return rc;
675}
676
677int qeth_l3_setrouting_v6(struct qeth_card *card)
678{
679 int rc = 0;
680
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200681 QETH_DBF_TEXT(TRACE, 3, "setrtg6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100682#ifdef CONFIG_QETH_IPV6
683
684 if (!qeth_is_supported(card, IPA_IPV6))
685 return 0;
686 qeth_l3_correct_routing_type(card, &card->options.route6.type,
687 QETH_PROT_IPV6);
688
689 rc = qeth_l3_send_setrouting(card, card->options.route6.type,
690 QETH_PROT_IPV6);
691 if (rc) {
692 card->options.route6.type = NO_ROUTER;
Frank Blaschka14cc21b2008-06-06 12:37:46 +0200693 QETH_DBF_MESSAGE(2, "Error (0x%04x) while setting routing type"
694 " on %s. Type set to 'no router'.\n", rc,
695 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100696 }
697#endif
698 return rc;
699}
700
701/*
702 * IP address takeover related functions
703 */
704static void qeth_l3_clear_ipato_list(struct qeth_card *card)
705{
706
707 struct qeth_ipato_entry *ipatoe, *tmp;
708 unsigned long flags;
709
710 spin_lock_irqsave(&card->ip_lock, flags);
711 list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry) {
712 list_del(&ipatoe->entry);
713 kfree(ipatoe);
714 }
715 spin_unlock_irqrestore(&card->ip_lock, flags);
716}
717
718int qeth_l3_add_ipato_entry(struct qeth_card *card,
719 struct qeth_ipato_entry *new)
720{
721 struct qeth_ipato_entry *ipatoe;
722 unsigned long flags;
723 int rc = 0;
724
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200725 QETH_DBF_TEXT(TRACE, 2, "addipato");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100726 spin_lock_irqsave(&card->ip_lock, flags);
727 list_for_each_entry(ipatoe, &card->ipato.entries, entry) {
728 if (ipatoe->proto != new->proto)
729 continue;
730 if (!memcmp(ipatoe->addr, new->addr,
731 (ipatoe->proto == QETH_PROT_IPV4)? 4:16) &&
732 (ipatoe->mask_bits == new->mask_bits)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100733 rc = -EEXIST;
734 break;
735 }
736 }
737 if (!rc)
738 list_add_tail(&new->entry, &card->ipato.entries);
739
740 spin_unlock_irqrestore(&card->ip_lock, flags);
741 return rc;
742}
743
744void qeth_l3_del_ipato_entry(struct qeth_card *card,
745 enum qeth_prot_versions proto, u8 *addr, int mask_bits)
746{
747 struct qeth_ipato_entry *ipatoe, *tmp;
748 unsigned long flags;
749
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200750 QETH_DBF_TEXT(TRACE, 2, "delipato");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100751 spin_lock_irqsave(&card->ip_lock, flags);
752 list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry) {
753 if (ipatoe->proto != proto)
754 continue;
755 if (!memcmp(ipatoe->addr, addr,
756 (proto == QETH_PROT_IPV4)? 4:16) &&
757 (ipatoe->mask_bits == mask_bits)) {
758 list_del(&ipatoe->entry);
759 kfree(ipatoe);
760 }
761 }
762 spin_unlock_irqrestore(&card->ip_lock, flags);
763}
764
765/*
766 * VIPA related functions
767 */
768int qeth_l3_add_vipa(struct qeth_card *card, enum qeth_prot_versions proto,
769 const u8 *addr)
770{
771 struct qeth_ipaddr *ipaddr;
772 unsigned long flags;
773 int rc = 0;
774
775 ipaddr = qeth_l3_get_addr_buffer(proto);
776 if (ipaddr) {
777 if (proto == QETH_PROT_IPV4) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200778 QETH_DBF_TEXT(TRACE, 2, "addvipa4");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100779 memcpy(&ipaddr->u.a4.addr, addr, 4);
780 ipaddr->u.a4.mask = 0;
781 } else if (proto == QETH_PROT_IPV6) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200782 QETH_DBF_TEXT(TRACE, 2, "addvipa6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100783 memcpy(&ipaddr->u.a6.addr, addr, 16);
784 ipaddr->u.a6.pfxlen = 0;
785 }
786 ipaddr->type = QETH_IP_TYPE_VIPA;
787 ipaddr->set_flags = QETH_IPA_SETIP_VIPA_FLAG;
788 ipaddr->del_flags = QETH_IPA_DELIP_VIPA_FLAG;
789 } else
790 return -ENOMEM;
791 spin_lock_irqsave(&card->ip_lock, flags);
792 if (qeth_l3_address_exists_in_list(&card->ip_list, ipaddr, 0) ||
793 qeth_l3_address_exists_in_list(card->ip_tbd_list, ipaddr, 0))
794 rc = -EEXIST;
795 spin_unlock_irqrestore(&card->ip_lock, flags);
796 if (rc) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100797 return rc;
798 }
799 if (!qeth_l3_add_ip(card, ipaddr))
800 kfree(ipaddr);
801 qeth_l3_set_ip_addr_list(card);
802 return rc;
803}
804
805void qeth_l3_del_vipa(struct qeth_card *card, enum qeth_prot_versions proto,
806 const u8 *addr)
807{
808 struct qeth_ipaddr *ipaddr;
809
810 ipaddr = qeth_l3_get_addr_buffer(proto);
811 if (ipaddr) {
812 if (proto == QETH_PROT_IPV4) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200813 QETH_DBF_TEXT(TRACE, 2, "delvipa4");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100814 memcpy(&ipaddr->u.a4.addr, addr, 4);
815 ipaddr->u.a4.mask = 0;
816 } else if (proto == QETH_PROT_IPV6) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200817 QETH_DBF_TEXT(TRACE, 2, "delvipa6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100818 memcpy(&ipaddr->u.a6.addr, addr, 16);
819 ipaddr->u.a6.pfxlen = 0;
820 }
821 ipaddr->type = QETH_IP_TYPE_VIPA;
822 } else
823 return;
824 if (!qeth_l3_delete_ip(card, ipaddr))
825 kfree(ipaddr);
826 qeth_l3_set_ip_addr_list(card);
827}
828
829/*
830 * proxy ARP related functions
831 */
832int qeth_l3_add_rxip(struct qeth_card *card, enum qeth_prot_versions proto,
833 const u8 *addr)
834{
835 struct qeth_ipaddr *ipaddr;
836 unsigned long flags;
837 int rc = 0;
838
839 ipaddr = qeth_l3_get_addr_buffer(proto);
840 if (ipaddr) {
841 if (proto == QETH_PROT_IPV4) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200842 QETH_DBF_TEXT(TRACE, 2, "addrxip4");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100843 memcpy(&ipaddr->u.a4.addr, addr, 4);
844 ipaddr->u.a4.mask = 0;
845 } else if (proto == QETH_PROT_IPV6) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200846 QETH_DBF_TEXT(TRACE, 2, "addrxip6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100847 memcpy(&ipaddr->u.a6.addr, addr, 16);
848 ipaddr->u.a6.pfxlen = 0;
849 }
850 ipaddr->type = QETH_IP_TYPE_RXIP;
851 ipaddr->set_flags = QETH_IPA_SETIP_TAKEOVER_FLAG;
852 ipaddr->del_flags = 0;
853 } else
854 return -ENOMEM;
855 spin_lock_irqsave(&card->ip_lock, flags);
856 if (qeth_l3_address_exists_in_list(&card->ip_list, ipaddr, 0) ||
857 qeth_l3_address_exists_in_list(card->ip_tbd_list, ipaddr, 0))
858 rc = -EEXIST;
859 spin_unlock_irqrestore(&card->ip_lock, flags);
860 if (rc) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100861 return rc;
862 }
863 if (!qeth_l3_add_ip(card, ipaddr))
864 kfree(ipaddr);
865 qeth_l3_set_ip_addr_list(card);
866 return 0;
867}
868
869void qeth_l3_del_rxip(struct qeth_card *card, enum qeth_prot_versions proto,
870 const u8 *addr)
871{
872 struct qeth_ipaddr *ipaddr;
873
874 ipaddr = qeth_l3_get_addr_buffer(proto);
875 if (ipaddr) {
876 if (proto == QETH_PROT_IPV4) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200877 QETH_DBF_TEXT(TRACE, 2, "addrxip4");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100878 memcpy(&ipaddr->u.a4.addr, addr, 4);
879 ipaddr->u.a4.mask = 0;
880 } else if (proto == QETH_PROT_IPV6) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200881 QETH_DBF_TEXT(TRACE, 2, "addrxip6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100882 memcpy(&ipaddr->u.a6.addr, addr, 16);
883 ipaddr->u.a6.pfxlen = 0;
884 }
885 ipaddr->type = QETH_IP_TYPE_RXIP;
886 } else
887 return;
888 if (!qeth_l3_delete_ip(card, ipaddr))
889 kfree(ipaddr);
890 qeth_l3_set_ip_addr_list(card);
891}
892
893static int qeth_l3_register_addr_entry(struct qeth_card *card,
894 struct qeth_ipaddr *addr)
895{
896 char buf[50];
897 int rc = 0;
898 int cnt = 3;
899
900 if (addr->proto == QETH_PROT_IPV4) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200901 QETH_DBF_TEXT(TRACE, 2, "setaddr4");
902 QETH_DBF_HEX(TRACE, 3, &addr->u.a4.addr, sizeof(int));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100903 } else if (addr->proto == QETH_PROT_IPV6) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200904 QETH_DBF_TEXT(TRACE, 2, "setaddr6");
905 QETH_DBF_HEX(TRACE, 3, &addr->u.a6.addr, 8);
906 QETH_DBF_HEX(TRACE, 3, ((char *)&addr->u.a6.addr) + 8, 8);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100907 } else {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200908 QETH_DBF_TEXT(TRACE, 2, "setaddr?");
909 QETH_DBF_HEX(TRACE, 3, addr, sizeof(struct qeth_ipaddr));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100910 }
911 do {
912 if (addr->is_multicast)
913 rc = qeth_l3_send_setdelmc(card, addr, IPA_CMD_SETIPM);
914 else
915 rc = qeth_l3_send_setdelip(card, addr, IPA_CMD_SETIP,
916 addr->set_flags);
917 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200918 QETH_DBF_TEXT(TRACE, 2, "failed");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100919 } while ((--cnt > 0) && rc);
920 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200921 QETH_DBF_TEXT(TRACE, 2, "FAILED");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100922 qeth_l3_ipaddr_to_string(addr->proto, (u8 *)&addr->u, buf);
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100923 dev_warn(&card->gdev->dev,
924 "Registering IP address %s failed\n", buf);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100925 }
926 return rc;
927}
928
929static int qeth_l3_deregister_addr_entry(struct qeth_card *card,
930 struct qeth_ipaddr *addr)
931{
932 int rc = 0;
933
934 if (addr->proto == QETH_PROT_IPV4) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200935 QETH_DBF_TEXT(TRACE, 2, "deladdr4");
936 QETH_DBF_HEX(TRACE, 3, &addr->u.a4.addr, sizeof(int));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100937 } else if (addr->proto == QETH_PROT_IPV6) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200938 QETH_DBF_TEXT(TRACE, 2, "deladdr6");
939 QETH_DBF_HEX(TRACE, 3, &addr->u.a6.addr, 8);
940 QETH_DBF_HEX(TRACE, 3, ((char *)&addr->u.a6.addr) + 8, 8);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100941 } else {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200942 QETH_DBF_TEXT(TRACE, 2, "deladdr?");
943 QETH_DBF_HEX(TRACE, 3, addr, sizeof(struct qeth_ipaddr));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100944 }
945 if (addr->is_multicast)
946 rc = qeth_l3_send_setdelmc(card, addr, IPA_CMD_DELIPM);
947 else
948 rc = qeth_l3_send_setdelip(card, addr, IPA_CMD_DELIP,
949 addr->del_flags);
Frank Blaschkac4cef072008-07-14 09:59:31 +0200950 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200951 QETH_DBF_TEXT(TRACE, 2, "failed");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100952
953 return rc;
954}
955
956static inline u8 qeth_l3_get_qeth_hdr_flags4(int cast_type)
957{
958 if (cast_type == RTN_MULTICAST)
959 return QETH_CAST_MULTICAST;
960 if (cast_type == RTN_BROADCAST)
961 return QETH_CAST_BROADCAST;
962 return QETH_CAST_UNICAST;
963}
964
965static inline u8 qeth_l3_get_qeth_hdr_flags6(int cast_type)
966{
967 u8 ct = QETH_HDR_PASSTHRU | QETH_HDR_IPV6;
968 if (cast_type == RTN_MULTICAST)
969 return ct | QETH_CAST_MULTICAST;
970 if (cast_type == RTN_ANYCAST)
971 return ct | QETH_CAST_ANYCAST;
972 if (cast_type == RTN_BROADCAST)
973 return ct | QETH_CAST_BROADCAST;
974 return ct | QETH_CAST_UNICAST;
975}
976
977static int qeth_l3_send_setadp_mode(struct qeth_card *card, __u32 command,
978 __u32 mode)
979{
980 int rc;
981 struct qeth_cmd_buffer *iob;
982 struct qeth_ipa_cmd *cmd;
983
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200984 QETH_DBF_TEXT(TRACE, 4, "adpmode");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100985
986 iob = qeth_get_adapter_cmd(card, command,
987 sizeof(struct qeth_ipacmd_setadpparms));
988 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
989 cmd->data.setadapterparms.data.mode = mode;
990 rc = qeth_send_ipa_cmd(card, iob, qeth_default_setadapterparms_cb,
991 NULL);
992 return rc;
993}
994
995static int qeth_l3_setadapter_hstr(struct qeth_card *card)
996{
997 int rc;
998
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200999 QETH_DBF_TEXT(TRACE, 4, "adphstr");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001000
1001 if (qeth_adp_supported(card, IPA_SETADP_SET_BROADCAST_MODE)) {
1002 rc = qeth_l3_send_setadp_mode(card,
1003 IPA_SETADP_SET_BROADCAST_MODE,
1004 card->options.broadcast_mode);
1005 if (rc)
Frank Blaschka14cc21b2008-06-06 12:37:46 +02001006 QETH_DBF_MESSAGE(2, "couldn't set broadcast mode on "
Frank Blaschka4a71df52008-02-15 09:19:42 +01001007 "device %s: x%x\n",
1008 CARD_BUS_ID(card), rc);
1009 rc = qeth_l3_send_setadp_mode(card,
1010 IPA_SETADP_ALTER_MAC_ADDRESS,
1011 card->options.macaddr_mode);
1012 if (rc)
Frank Blaschka14cc21b2008-06-06 12:37:46 +02001013 QETH_DBF_MESSAGE(2, "couldn't set macaddr mode on "
Frank Blaschka4a71df52008-02-15 09:19:42 +01001014 "device %s: x%x\n", CARD_BUS_ID(card), rc);
1015 return rc;
1016 }
1017 if (card->options.broadcast_mode == QETH_TR_BROADCAST_LOCAL)
Frank Blaschka14cc21b2008-06-06 12:37:46 +02001018 QETH_DBF_MESSAGE(2, "set adapter parameters not available "
Frank Blaschka4a71df52008-02-15 09:19:42 +01001019 "to set broadcast mode, using ALLRINGS "
1020 "on device %s:\n", CARD_BUS_ID(card));
1021 if (card->options.macaddr_mode == QETH_TR_MACADDR_CANONICAL)
Frank Blaschka14cc21b2008-06-06 12:37:46 +02001022 QETH_DBF_MESSAGE(2, "set adapter parameters not available "
Frank Blaschka4a71df52008-02-15 09:19:42 +01001023 "to set macaddr mode, using NONCANONICAL "
1024 "on device %s:\n", CARD_BUS_ID(card));
1025 return 0;
1026}
1027
1028static int qeth_l3_setadapter_parms(struct qeth_card *card)
1029{
1030 int rc;
1031
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001032 QETH_DBF_TEXT(SETUP, 2, "setadprm");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001033
1034 if (!qeth_is_supported(card, IPA_SETADAPTERPARMS)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001035 dev_info(&card->gdev->dev,
1036 "set adapter parameters not supported.\n");
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001037 QETH_DBF_TEXT(SETUP, 2, " notsupp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001038 return 0;
1039 }
1040 rc = qeth_query_setadapterparms(card);
1041 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001042 QETH_DBF_MESSAGE(2, "%s couldn't set adapter parameters: "
1043 "0x%x\n", card->gdev->dev.bus_id, rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001044 return rc;
1045 }
1046 if (qeth_adp_supported(card, IPA_SETADP_ALTER_MAC_ADDRESS)) {
1047 rc = qeth_setadpparms_change_macaddr(card);
1048 if (rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001049 dev_warn(&card->gdev->dev, "Reading the adapter MAC"
Heiko Carstens6ea2fde2009-01-04 17:36:32 -08001050 " address failed\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001051 }
1052
1053 if ((card->info.link_type == QETH_LINK_TYPE_HSTR) ||
1054 (card->info.link_type == QETH_LINK_TYPE_LANE_TR))
1055 rc = qeth_l3_setadapter_hstr(card);
1056
1057 return rc;
1058}
1059
1060static int qeth_l3_default_setassparms_cb(struct qeth_card *card,
1061 struct qeth_reply *reply, unsigned long data)
1062{
1063 struct qeth_ipa_cmd *cmd;
1064
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001065 QETH_DBF_TEXT(TRACE, 4, "defadpcb");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001066
1067 cmd = (struct qeth_ipa_cmd *) data;
1068 if (cmd->hdr.return_code == 0) {
1069 cmd->hdr.return_code = cmd->data.setassparms.hdr.return_code;
1070 if (cmd->hdr.prot_version == QETH_PROT_IPV4)
1071 card->options.ipa4.enabled_funcs = cmd->hdr.ipa_enabled;
1072 if (cmd->hdr.prot_version == QETH_PROT_IPV6)
1073 card->options.ipa6.enabled_funcs = cmd->hdr.ipa_enabled;
1074 }
1075 if (cmd->data.setassparms.hdr.assist_no == IPA_INBOUND_CHECKSUM &&
1076 cmd->data.setassparms.hdr.command_code == IPA_CMD_ASS_START) {
1077 card->info.csum_mask = cmd->data.setassparms.data.flags_32bit;
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001078 QETH_DBF_TEXT_(TRACE, 3, "csum:%d", card->info.csum_mask);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001079 }
1080 return 0;
1081}
1082
1083static struct qeth_cmd_buffer *qeth_l3_get_setassparms_cmd(
1084 struct qeth_card *card, enum qeth_ipa_funcs ipa_func, __u16 cmd_code,
1085 __u16 len, enum qeth_prot_versions prot)
1086{
1087 struct qeth_cmd_buffer *iob;
1088 struct qeth_ipa_cmd *cmd;
1089
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001090 QETH_DBF_TEXT(TRACE, 4, "getasscm");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001091 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SETASSPARMS, prot);
1092
1093 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1094 cmd->data.setassparms.hdr.assist_no = ipa_func;
1095 cmd->data.setassparms.hdr.length = 8 + len;
1096 cmd->data.setassparms.hdr.command_code = cmd_code;
1097 cmd->data.setassparms.hdr.return_code = 0;
1098 cmd->data.setassparms.hdr.seq_no = 0;
1099
1100 return iob;
1101}
1102
1103static int qeth_l3_send_setassparms(struct qeth_card *card,
1104 struct qeth_cmd_buffer *iob, __u16 len, long data,
1105 int (*reply_cb)(struct qeth_card *, struct qeth_reply *,
1106 unsigned long),
1107 void *reply_param)
1108{
1109 int rc;
1110 struct qeth_ipa_cmd *cmd;
1111
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001112 QETH_DBF_TEXT(TRACE, 4, "sendassp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001113
1114 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1115 if (len <= sizeof(__u32))
1116 cmd->data.setassparms.data.flags_32bit = (__u32) data;
1117 else /* (len > sizeof(__u32)) */
1118 memcpy(&cmd->data.setassparms.data, (void *) data, len);
1119
1120 rc = qeth_send_ipa_cmd(card, iob, reply_cb, reply_param);
1121 return rc;
1122}
1123
1124#ifdef CONFIG_QETH_IPV6
1125static int qeth_l3_send_simple_setassparms_ipv6(struct qeth_card *card,
1126 enum qeth_ipa_funcs ipa_func, __u16 cmd_code)
1127{
1128 int rc;
1129 struct qeth_cmd_buffer *iob;
1130
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001131 QETH_DBF_TEXT(TRACE, 4, "simassp6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001132 iob = qeth_l3_get_setassparms_cmd(card, ipa_func, cmd_code,
1133 0, QETH_PROT_IPV6);
1134 rc = qeth_l3_send_setassparms(card, iob, 0, 0,
1135 qeth_l3_default_setassparms_cb, NULL);
1136 return rc;
1137}
1138#endif
1139
1140static int qeth_l3_send_simple_setassparms(struct qeth_card *card,
1141 enum qeth_ipa_funcs ipa_func, __u16 cmd_code, long data)
1142{
1143 int rc;
1144 int length = 0;
1145 struct qeth_cmd_buffer *iob;
1146
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001147 QETH_DBF_TEXT(TRACE, 4, "simassp4");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001148 if (data)
1149 length = sizeof(__u32);
1150 iob = qeth_l3_get_setassparms_cmd(card, ipa_func, cmd_code,
1151 length, QETH_PROT_IPV4);
1152 rc = qeth_l3_send_setassparms(card, iob, length, data,
1153 qeth_l3_default_setassparms_cb, NULL);
1154 return rc;
1155}
1156
1157static int qeth_l3_start_ipa_arp_processing(struct qeth_card *card)
1158{
1159 int rc;
1160
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001161 QETH_DBF_TEXT(TRACE, 3, "ipaarp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001162
1163 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001164 dev_info(&card->gdev->dev,
1165 "ARP processing not supported on %s!\n",
1166 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001167 return 0;
1168 }
1169 rc = qeth_l3_send_simple_setassparms(card, IPA_ARP_PROCESSING,
1170 IPA_CMD_ASS_START, 0);
1171 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001172 dev_warn(&card->gdev->dev,
1173 "Starting ARP processing support for %s failed\n",
1174 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001175 }
1176 return rc;
1177}
1178
1179static int qeth_l3_start_ipa_ip_fragmentation(struct qeth_card *card)
1180{
1181 int rc;
1182
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001183 QETH_DBF_TEXT(TRACE, 3, "ipaipfrg");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001184
1185 if (!qeth_is_supported(card, IPA_IP_FRAGMENTATION)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001186 dev_info(&card->gdev->dev,
1187 "Hardware IP fragmentation not supported on %s\n",
1188 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001189 return -EOPNOTSUPP;
1190 }
1191
1192 rc = qeth_l3_send_simple_setassparms(card, IPA_IP_FRAGMENTATION,
1193 IPA_CMD_ASS_START, 0);
1194 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001195 dev_warn(&card->gdev->dev,
1196 "Starting IP fragmentation support for %s failed\n",
1197 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001198 } else
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001199 dev_info(&card->gdev->dev,
1200 "Hardware IP fragmentation enabled \n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001201 return rc;
1202}
1203
1204static int qeth_l3_start_ipa_source_mac(struct qeth_card *card)
1205{
1206 int rc;
1207
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001208 QETH_DBF_TEXT(TRACE, 3, "stsrcmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001209
Frank Blaschka4a71df52008-02-15 09:19:42 +01001210 if (!qeth_is_supported(card, IPA_SOURCE_MAC)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001211 dev_info(&card->gdev->dev,
Ursula Braunfe94e2e2009-01-04 17:34:52 -08001212 "Inbound source MAC-address not supported on %s\n",
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001213 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001214 return -EOPNOTSUPP;
1215 }
1216
1217 rc = qeth_l3_send_simple_setassparms(card, IPA_SOURCE_MAC,
1218 IPA_CMD_ASS_START, 0);
1219 if (rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001220 dev_warn(&card->gdev->dev,
Ursula Braunfe94e2e2009-01-04 17:34:52 -08001221 "Starting source MAC-address support for %s failed\n",
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001222 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001223 return rc;
1224}
1225
1226static int qeth_l3_start_ipa_vlan(struct qeth_card *card)
1227{
1228 int rc = 0;
1229
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001230 QETH_DBF_TEXT(TRACE, 3, "strtvlan");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001231
1232 if (!qeth_is_supported(card, IPA_FULL_VLAN)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001233 dev_info(&card->gdev->dev,
1234 "VLAN not supported on %s\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001235 return -EOPNOTSUPP;
1236 }
1237
1238 rc = qeth_l3_send_simple_setassparms(card, IPA_VLAN_PRIO,
1239 IPA_CMD_ASS_START, 0);
1240 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001241 dev_warn(&card->gdev->dev,
1242 "Starting VLAN support for %s failed\n",
1243 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001244 } else {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001245 dev_info(&card->gdev->dev, "VLAN enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001246 }
1247 return rc;
1248}
1249
1250static int qeth_l3_start_ipa_multicast(struct qeth_card *card)
1251{
1252 int rc;
1253
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001254 QETH_DBF_TEXT(TRACE, 3, "stmcast");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001255
1256 if (!qeth_is_supported(card, IPA_MULTICASTING)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001257 dev_info(&card->gdev->dev,
1258 "Multicast not supported on %s\n",
1259 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001260 return -EOPNOTSUPP;
1261 }
1262
1263 rc = qeth_l3_send_simple_setassparms(card, IPA_MULTICASTING,
1264 IPA_CMD_ASS_START, 0);
1265 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001266 dev_warn(&card->gdev->dev,
1267 "Starting multicast support for %s failed\n",
1268 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001269 } else {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001270 dev_info(&card->gdev->dev, "Multicast enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001271 card->dev->flags |= IFF_MULTICAST;
1272 }
1273 return rc;
1274}
1275
1276static int qeth_l3_query_ipassists_cb(struct qeth_card *card,
1277 struct qeth_reply *reply, unsigned long data)
1278{
1279 struct qeth_ipa_cmd *cmd;
1280
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001281 QETH_DBF_TEXT(SETUP, 2, "qipasscb");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001282
1283 cmd = (struct qeth_ipa_cmd *) data;
1284 if (cmd->hdr.prot_version == QETH_PROT_IPV4) {
1285 card->options.ipa4.supported_funcs = cmd->hdr.ipa_supported;
1286 card->options.ipa4.enabled_funcs = cmd->hdr.ipa_enabled;
1287 } else {
1288 card->options.ipa6.supported_funcs = cmd->hdr.ipa_supported;
1289 card->options.ipa6.enabled_funcs = cmd->hdr.ipa_enabled;
1290 }
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001291 QETH_DBF_TEXT(SETUP, 2, "suppenbl");
1292 QETH_DBF_TEXT_(SETUP, 2, "%x", cmd->hdr.ipa_supported);
1293 QETH_DBF_TEXT_(SETUP, 2, "%x", cmd->hdr.ipa_enabled);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001294 return 0;
1295}
1296
1297static int qeth_l3_query_ipassists(struct qeth_card *card,
1298 enum qeth_prot_versions prot)
1299{
1300 int rc;
1301 struct qeth_cmd_buffer *iob;
1302
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001303 QETH_DBF_TEXT_(SETUP, 2, "qipassi%i", prot);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001304 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_QIPASSIST, prot);
1305 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_query_ipassists_cb, NULL);
1306 return rc;
1307}
1308
1309#ifdef CONFIG_QETH_IPV6
1310static int qeth_l3_softsetup_ipv6(struct qeth_card *card)
1311{
1312 int rc;
1313
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001314 QETH_DBF_TEXT(TRACE, 3, "softipv6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001315
1316 if (card->info.type == QETH_CARD_TYPE_IQD)
1317 goto out;
1318
1319 rc = qeth_l3_query_ipassists(card, QETH_PROT_IPV6);
1320 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001321 dev_err(&card->gdev->dev,
1322 "Activating IPv6 support for %s failed\n",
1323 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001324 return rc;
1325 }
1326 rc = qeth_l3_send_simple_setassparms(card, IPA_IPV6,
1327 IPA_CMD_ASS_START, 3);
1328 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001329 dev_err(&card->gdev->dev,
1330 "Activating IPv6 support for %s failed\n",
1331 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001332 return rc;
1333 }
1334 rc = qeth_l3_send_simple_setassparms_ipv6(card, IPA_IPV6,
1335 IPA_CMD_ASS_START);
1336 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001337 dev_err(&card->gdev->dev,
1338 "Activating IPv6 support for %s failed\n",
1339 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001340 return rc;
1341 }
1342 rc = qeth_l3_send_simple_setassparms_ipv6(card, IPA_PASSTHRU,
1343 IPA_CMD_ASS_START);
1344 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001345 dev_warn(&card->gdev->dev,
1346 "Enabling the passthrough mode for %s failed\n",
1347 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001348 return rc;
1349 }
1350out:
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001351 dev_info(&card->gdev->dev, "IPV6 enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001352 return 0;
1353}
1354#endif
1355
1356static int qeth_l3_start_ipa_ipv6(struct qeth_card *card)
1357{
1358 int rc = 0;
1359
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001360 QETH_DBF_TEXT(TRACE, 3, "strtipv6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001361
1362 if (!qeth_is_supported(card, IPA_IPV6)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001363 dev_info(&card->gdev->dev,
1364 "IPv6 not supported on %s\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001365 return 0;
1366 }
1367#ifdef CONFIG_QETH_IPV6
1368 rc = qeth_l3_softsetup_ipv6(card);
1369#endif
1370 return rc ;
1371}
1372
1373static int qeth_l3_start_ipa_broadcast(struct qeth_card *card)
1374{
1375 int rc;
1376
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001377 QETH_DBF_TEXT(TRACE, 3, "stbrdcst");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001378 card->info.broadcast_capable = 0;
1379 if (!qeth_is_supported(card, IPA_FILTERING)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001380 dev_info(&card->gdev->dev,
1381 "Broadcast not supported on %s\n",
1382 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001383 rc = -EOPNOTSUPP;
1384 goto out;
1385 }
1386 rc = qeth_l3_send_simple_setassparms(card, IPA_FILTERING,
1387 IPA_CMD_ASS_START, 0);
1388 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001389 dev_warn(&card->gdev->dev, "Enabling broadcast filtering for "
1390 "%s failed\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001391 goto out;
1392 }
1393
1394 rc = qeth_l3_send_simple_setassparms(card, IPA_FILTERING,
1395 IPA_CMD_ASS_CONFIGURE, 1);
1396 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001397 dev_warn(&card->gdev->dev,
1398 "Setting up broadcast filtering for %s failed\n",
1399 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001400 goto out;
1401 }
1402 card->info.broadcast_capable = QETH_BROADCAST_WITH_ECHO;
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001403 dev_info(&card->gdev->dev, "Broadcast enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001404 rc = qeth_l3_send_simple_setassparms(card, IPA_FILTERING,
1405 IPA_CMD_ASS_ENABLE, 1);
1406 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001407 dev_warn(&card->gdev->dev, "Setting up broadcast echo "
1408 "filtering for %s failed\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001409 goto out;
1410 }
1411 card->info.broadcast_capable = QETH_BROADCAST_WITHOUT_ECHO;
1412out:
1413 if (card->info.broadcast_capable)
1414 card->dev->flags |= IFF_BROADCAST;
1415 else
1416 card->dev->flags &= ~IFF_BROADCAST;
1417 return rc;
1418}
1419
1420static int qeth_l3_send_checksum_command(struct qeth_card *card)
1421{
1422 int rc;
1423
1424 rc = qeth_l3_send_simple_setassparms(card, IPA_INBOUND_CHECKSUM,
1425 IPA_CMD_ASS_START, 0);
1426 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001427 dev_warn(&card->gdev->dev, "Starting HW checksumming for %s "
1428 "failed, using SW checksumming\n",
1429 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001430 return rc;
1431 }
1432 rc = qeth_l3_send_simple_setassparms(card, IPA_INBOUND_CHECKSUM,
1433 IPA_CMD_ASS_ENABLE,
1434 card->info.csum_mask);
1435 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001436 dev_warn(&card->gdev->dev, "Enabling HW checksumming for %s "
1437 "failed, using SW checksumming\n",
1438 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001439 return rc;
1440 }
1441 return 0;
1442}
1443
1444static int qeth_l3_start_ipa_checksum(struct qeth_card *card)
1445{
1446 int rc = 0;
1447
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001448 QETH_DBF_TEXT(TRACE, 3, "strtcsum");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001449
1450 if (card->options.checksum_type == NO_CHECKSUMMING) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001451 dev_info(&card->gdev->dev,
1452 "Using no checksumming on %s.\n",
1453 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001454 return 0;
1455 }
1456 if (card->options.checksum_type == SW_CHECKSUMMING) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001457 dev_info(&card->gdev->dev,
1458 "Using SW checksumming on %s.\n",
1459 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001460 return 0;
1461 }
1462 if (!qeth_is_supported(card, IPA_INBOUND_CHECKSUM)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001463 dev_info(&card->gdev->dev,
1464 "Inbound HW Checksumming not "
1465 "supported on %s,\ncontinuing "
1466 "using Inbound SW Checksumming\n",
1467 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001468 card->options.checksum_type = SW_CHECKSUMMING;
1469 return 0;
1470 }
1471 rc = qeth_l3_send_checksum_command(card);
1472 if (!rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001473 dev_info(&card->gdev->dev,
1474 "HW Checksumming (inbound) enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001475
1476 return rc;
1477}
1478
1479static int qeth_l3_start_ipa_tso(struct qeth_card *card)
1480{
1481 int rc;
1482
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001483 QETH_DBF_TEXT(TRACE, 3, "sttso");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001484
1485 if (!qeth_is_supported(card, IPA_OUTBOUND_TSO)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001486 dev_info(&card->gdev->dev,
1487 "Outbound TSO not supported on %s\n",
1488 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001489 rc = -EOPNOTSUPP;
1490 } else {
1491 rc = qeth_l3_send_simple_setassparms(card, IPA_OUTBOUND_TSO,
1492 IPA_CMD_ASS_START, 0);
1493 if (rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001494 dev_warn(&card->gdev->dev, "Starting outbound TCP "
1495 "segmentation offload for %s failed\n",
1496 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001497 else
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001498 dev_info(&card->gdev->dev,
1499 "Outbound TSO enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001500 }
1501 if (rc && (card->options.large_send == QETH_LARGE_SEND_TSO)) {
1502 card->options.large_send = QETH_LARGE_SEND_NO;
1503 card->dev->features &= ~(NETIF_F_TSO | NETIF_F_SG);
1504 }
1505 return rc;
1506}
1507
1508static int qeth_l3_start_ipassists(struct qeth_card *card)
1509{
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001510 QETH_DBF_TEXT(TRACE, 3, "strtipas");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001511 qeth_l3_start_ipa_arp_processing(card); /* go on*/
1512 qeth_l3_start_ipa_ip_fragmentation(card); /* go on*/
1513 qeth_l3_start_ipa_source_mac(card); /* go on*/
1514 qeth_l3_start_ipa_vlan(card); /* go on*/
1515 qeth_l3_start_ipa_multicast(card); /* go on*/
1516 qeth_l3_start_ipa_ipv6(card); /* go on*/
1517 qeth_l3_start_ipa_broadcast(card); /* go on*/
1518 qeth_l3_start_ipa_checksum(card); /* go on*/
1519 qeth_l3_start_ipa_tso(card); /* go on*/
1520 return 0;
1521}
1522
1523static int qeth_l3_put_unique_id(struct qeth_card *card)
1524{
1525
1526 int rc = 0;
1527 struct qeth_cmd_buffer *iob;
1528 struct qeth_ipa_cmd *cmd;
1529
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001530 QETH_DBF_TEXT(TRACE, 2, "puniqeid");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001531
1532 if ((card->info.unique_id & UNIQUE_ID_NOT_BY_CARD) ==
1533 UNIQUE_ID_NOT_BY_CARD)
1534 return -1;
1535 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_DESTROY_ADDR,
1536 QETH_PROT_IPV6);
1537 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1538 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
1539 card->info.unique_id;
1540 memcpy(&cmd->data.create_destroy_addr.unique_id[0],
1541 card->dev->dev_addr, OSA_ADDR_LEN);
1542 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
1543 return rc;
1544}
1545
1546static int qeth_l3_iqd_read_initial_mac_cb(struct qeth_card *card,
1547 struct qeth_reply *reply, unsigned long data)
1548{
1549 struct qeth_ipa_cmd *cmd;
1550
1551 cmd = (struct qeth_ipa_cmd *) data;
1552 if (cmd->hdr.return_code == 0)
1553 memcpy(card->dev->dev_addr,
1554 cmd->data.create_destroy_addr.unique_id, ETH_ALEN);
1555 else
1556 random_ether_addr(card->dev->dev_addr);
1557
1558 return 0;
1559}
1560
1561static int qeth_l3_iqd_read_initial_mac(struct qeth_card *card)
1562{
1563 int rc = 0;
1564 struct qeth_cmd_buffer *iob;
1565 struct qeth_ipa_cmd *cmd;
1566
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001567 QETH_DBF_TEXT(SETUP, 2, "hsrmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001568
1569 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_CREATE_ADDR,
1570 QETH_PROT_IPV6);
1571 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1572 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
1573 card->info.unique_id;
1574
1575 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_iqd_read_initial_mac_cb,
1576 NULL);
1577 return rc;
1578}
1579
1580static int qeth_l3_get_unique_id_cb(struct qeth_card *card,
1581 struct qeth_reply *reply, unsigned long data)
1582{
1583 struct qeth_ipa_cmd *cmd;
1584
1585 cmd = (struct qeth_ipa_cmd *) data;
1586 if (cmd->hdr.return_code == 0)
1587 card->info.unique_id = *((__u16 *)
1588 &cmd->data.create_destroy_addr.unique_id[6]);
1589 else {
1590 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
1591 UNIQUE_ID_NOT_BY_CARD;
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001592 dev_warn(&card->gdev->dev, "The network adapter failed to "
1593 "generate a unique ID\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001594 }
1595 return 0;
1596}
1597
1598static int qeth_l3_get_unique_id(struct qeth_card *card)
1599{
1600 int rc = 0;
1601 struct qeth_cmd_buffer *iob;
1602 struct qeth_ipa_cmd *cmd;
1603
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001604 QETH_DBF_TEXT(SETUP, 2, "guniqeid");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001605
1606 if (!qeth_is_supported(card, IPA_IPV6)) {
1607 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
1608 UNIQUE_ID_NOT_BY_CARD;
1609 return 0;
1610 }
1611
1612 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_CREATE_ADDR,
1613 QETH_PROT_IPV6);
1614 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1615 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
1616 card->info.unique_id;
1617
1618 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_get_unique_id_cb, NULL);
1619 return rc;
1620}
1621
1622static void qeth_l3_get_mac_for_ipm(__u32 ipm, char *mac,
1623 struct net_device *dev)
1624{
1625 if (dev->type == ARPHRD_IEEE802_TR)
1626 ip_tr_mc_map(ipm, mac);
1627 else
1628 ip_eth_mc_map(ipm, mac);
1629}
1630
1631static void qeth_l3_add_mc(struct qeth_card *card, struct in_device *in4_dev)
1632{
1633 struct qeth_ipaddr *ipm;
1634 struct ip_mc_list *im4;
1635 char buf[MAX_ADDR_LEN];
1636
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001637 QETH_DBF_TEXT(TRACE, 4, "addmc");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001638 for (im4 = in4_dev->mc_list; im4; im4 = im4->next) {
1639 qeth_l3_get_mac_for_ipm(im4->multiaddr, buf, in4_dev->dev);
1640 ipm = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
1641 if (!ipm)
1642 continue;
1643 ipm->u.a4.addr = im4->multiaddr;
1644 memcpy(ipm->mac, buf, OSA_ADDR_LEN);
1645 ipm->is_multicast = 1;
1646 if (!qeth_l3_add_ip(card, ipm))
1647 kfree(ipm);
1648 }
1649}
1650
1651static void qeth_l3_add_vlan_mc(struct qeth_card *card)
1652{
1653 struct in_device *in_dev;
1654 struct vlan_group *vg;
1655 int i;
1656
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001657 QETH_DBF_TEXT(TRACE, 4, "addmcvl");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001658 if (!qeth_is_supported(card, IPA_FULL_VLAN) || (card->vlangrp == NULL))
1659 return;
1660
1661 vg = card->vlangrp;
1662 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
1663 struct net_device *netdev = vlan_group_get_device(vg, i);
1664 if (netdev == NULL ||
1665 !(netdev->flags & IFF_UP))
1666 continue;
1667 in_dev = in_dev_get(netdev);
1668 if (!in_dev)
1669 continue;
1670 read_lock(&in_dev->mc_list_lock);
1671 qeth_l3_add_mc(card, in_dev);
1672 read_unlock(&in_dev->mc_list_lock);
1673 in_dev_put(in_dev);
1674 }
1675}
1676
1677static void qeth_l3_add_multicast_ipv4(struct qeth_card *card)
1678{
1679 struct in_device *in4_dev;
1680
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001681 QETH_DBF_TEXT(TRACE, 4, "chkmcv4");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001682 in4_dev = in_dev_get(card->dev);
1683 if (in4_dev == NULL)
1684 return;
1685 read_lock(&in4_dev->mc_list_lock);
1686 qeth_l3_add_mc(card, in4_dev);
1687 qeth_l3_add_vlan_mc(card);
1688 read_unlock(&in4_dev->mc_list_lock);
1689 in_dev_put(in4_dev);
1690}
1691
1692#ifdef CONFIG_QETH_IPV6
1693static void qeth_l3_add_mc6(struct qeth_card *card, struct inet6_dev *in6_dev)
1694{
1695 struct qeth_ipaddr *ipm;
1696 struct ifmcaddr6 *im6;
1697 char buf[MAX_ADDR_LEN];
1698
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001699 QETH_DBF_TEXT(TRACE, 4, "addmc6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001700 for (im6 = in6_dev->mc_list; im6 != NULL; im6 = im6->next) {
1701 ndisc_mc_map(&im6->mca_addr, buf, in6_dev->dev, 0);
1702 ipm = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
1703 if (!ipm)
1704 continue;
1705 ipm->is_multicast = 1;
1706 memcpy(ipm->mac, buf, OSA_ADDR_LEN);
1707 memcpy(&ipm->u.a6.addr, &im6->mca_addr.s6_addr,
1708 sizeof(struct in6_addr));
1709 if (!qeth_l3_add_ip(card, ipm))
1710 kfree(ipm);
1711 }
1712}
1713
1714static void qeth_l3_add_vlan_mc6(struct qeth_card *card)
1715{
1716 struct inet6_dev *in_dev;
1717 struct vlan_group *vg;
1718 int i;
1719
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001720 QETH_DBF_TEXT(TRACE, 4, "admc6vl");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001721 if (!qeth_is_supported(card, IPA_FULL_VLAN) || (card->vlangrp == NULL))
1722 return;
1723
1724 vg = card->vlangrp;
1725 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
1726 struct net_device *netdev = vlan_group_get_device(vg, i);
1727 if (netdev == NULL ||
1728 !(netdev->flags & IFF_UP))
1729 continue;
1730 in_dev = in6_dev_get(netdev);
1731 if (!in_dev)
1732 continue;
1733 read_lock_bh(&in_dev->lock);
1734 qeth_l3_add_mc6(card, in_dev);
1735 read_unlock_bh(&in_dev->lock);
1736 in6_dev_put(in_dev);
1737 }
1738}
1739
1740static void qeth_l3_add_multicast_ipv6(struct qeth_card *card)
1741{
1742 struct inet6_dev *in6_dev;
1743
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001744 QETH_DBF_TEXT(TRACE, 4, "chkmcv6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001745 if (!qeth_is_supported(card, IPA_IPV6))
1746 return ;
1747 in6_dev = in6_dev_get(card->dev);
1748 if (in6_dev == NULL)
1749 return;
1750 read_lock_bh(&in6_dev->lock);
1751 qeth_l3_add_mc6(card, in6_dev);
1752 qeth_l3_add_vlan_mc6(card);
1753 read_unlock_bh(&in6_dev->lock);
1754 in6_dev_put(in6_dev);
1755}
1756#endif /* CONFIG_QETH_IPV6 */
1757
1758static void qeth_l3_free_vlan_addresses4(struct qeth_card *card,
1759 unsigned short vid)
1760{
1761 struct in_device *in_dev;
1762 struct in_ifaddr *ifa;
1763 struct qeth_ipaddr *addr;
1764
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001765 QETH_DBF_TEXT(TRACE, 4, "frvaddr4");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001766
1767 in_dev = in_dev_get(vlan_group_get_device(card->vlangrp, vid));
1768 if (!in_dev)
1769 return;
1770 for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
1771 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
1772 if (addr) {
1773 addr->u.a4.addr = ifa->ifa_address;
1774 addr->u.a4.mask = ifa->ifa_mask;
1775 addr->type = QETH_IP_TYPE_NORMAL;
1776 if (!qeth_l3_delete_ip(card, addr))
1777 kfree(addr);
1778 }
1779 }
1780 in_dev_put(in_dev);
1781}
1782
1783static void qeth_l3_free_vlan_addresses6(struct qeth_card *card,
1784 unsigned short vid)
1785{
1786#ifdef CONFIG_QETH_IPV6
1787 struct inet6_dev *in6_dev;
1788 struct inet6_ifaddr *ifa;
1789 struct qeth_ipaddr *addr;
1790
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001791 QETH_DBF_TEXT(TRACE, 4, "frvaddr6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001792
1793 in6_dev = in6_dev_get(vlan_group_get_device(card->vlangrp, vid));
1794 if (!in6_dev)
1795 return;
1796 for (ifa = in6_dev->addr_list; ifa; ifa = ifa->lst_next) {
1797 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
1798 if (addr) {
1799 memcpy(&addr->u.a6.addr, &ifa->addr,
1800 sizeof(struct in6_addr));
1801 addr->u.a6.pfxlen = ifa->prefix_len;
1802 addr->type = QETH_IP_TYPE_NORMAL;
1803 if (!qeth_l3_delete_ip(card, addr))
1804 kfree(addr);
1805 }
1806 }
1807 in6_dev_put(in6_dev);
1808#endif /* CONFIG_QETH_IPV6 */
1809}
1810
1811static void qeth_l3_free_vlan_addresses(struct qeth_card *card,
1812 unsigned short vid)
1813{
1814 if (!card->vlangrp)
1815 return;
1816 qeth_l3_free_vlan_addresses4(card, vid);
1817 qeth_l3_free_vlan_addresses6(card, vid);
1818}
1819
1820static void qeth_l3_vlan_rx_register(struct net_device *dev,
1821 struct vlan_group *grp)
1822{
Heiko Carstens509e2562008-07-26 02:24:10 -07001823 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001824 unsigned long flags;
1825
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001826 QETH_DBF_TEXT(TRACE, 4, "vlanreg");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001827 spin_lock_irqsave(&card->vlanlock, flags);
1828 card->vlangrp = grp;
1829 spin_unlock_irqrestore(&card->vlanlock, flags);
1830}
1831
1832static void qeth_l3_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
1833{
1834 struct net_device *vlandev;
Heiko Carstens509e2562008-07-26 02:24:10 -07001835 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001836 struct in_device *in_dev;
1837
1838 if (card->info.type == QETH_CARD_TYPE_IQD)
1839 return;
1840
1841 vlandev = vlan_group_get_device(card->vlangrp, vid);
1842 vlandev->neigh_setup = qeth_l3_neigh_setup;
1843
1844 in_dev = in_dev_get(vlandev);
1845#ifdef CONFIG_SYSCTL
1846 neigh_sysctl_unregister(in_dev->arp_parms);
1847#endif
1848 neigh_parms_release(&arp_tbl, in_dev->arp_parms);
1849
1850 in_dev->arp_parms = neigh_parms_alloc(vlandev, &arp_tbl);
1851#ifdef CONFIG_SYSCTL
1852 neigh_sysctl_register(vlandev, in_dev->arp_parms, NET_IPV4,
1853 NET_IPV4_NEIGH, "ipv4", NULL, NULL);
1854#endif
1855 in_dev_put(in_dev);
1856 return;
1857}
1858
1859static void qeth_l3_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
1860{
Heiko Carstens509e2562008-07-26 02:24:10 -07001861 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001862 unsigned long flags;
1863
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001864 QETH_DBF_TEXT_(TRACE, 4, "kid:%d", vid);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001865 spin_lock_irqsave(&card->vlanlock, flags);
1866 /* unregister IP addresses of vlan device */
1867 qeth_l3_free_vlan_addresses(card, vid);
1868 vlan_group_set_device(card->vlangrp, vid, NULL);
1869 spin_unlock_irqrestore(&card->vlanlock, flags);
1870 qeth_l3_set_multicast_list(card->dev);
1871}
1872
1873static inline __u16 qeth_l3_rebuild_skb(struct qeth_card *card,
1874 struct sk_buff *skb, struct qeth_hdr *hdr)
1875{
1876 unsigned short vlan_id = 0;
1877 __be16 prot;
1878 struct iphdr *ip_hdr;
1879 unsigned char tg_addr[MAX_ADDR_LEN];
1880
1881 if (!(hdr->hdr.l3.flags & QETH_HDR_PASSTHRU)) {
1882 prot = htons((hdr->hdr.l3.flags & QETH_HDR_IPV6)? ETH_P_IPV6 :
1883 ETH_P_IP);
1884 switch (hdr->hdr.l3.flags & QETH_HDR_CAST_MASK) {
1885 case QETH_CAST_MULTICAST:
1886 switch (prot) {
1887#ifdef CONFIG_QETH_IPV6
1888 case __constant_htons(ETH_P_IPV6):
1889 ndisc_mc_map((struct in6_addr *)
1890 skb->data + 24,
1891 tg_addr, card->dev, 0);
1892 break;
1893#endif
1894 case __constant_htons(ETH_P_IP):
1895 ip_hdr = (struct iphdr *)skb->data;
1896 (card->dev->type == ARPHRD_IEEE802_TR) ?
1897 ip_tr_mc_map(ip_hdr->daddr, tg_addr):
1898 ip_eth_mc_map(ip_hdr->daddr, tg_addr);
1899 break;
1900 default:
1901 memcpy(tg_addr, card->dev->broadcast,
1902 card->dev->addr_len);
1903 }
1904 card->stats.multicast++;
1905 skb->pkt_type = PACKET_MULTICAST;
1906 break;
1907 case QETH_CAST_BROADCAST:
1908 memcpy(tg_addr, card->dev->broadcast,
1909 card->dev->addr_len);
1910 card->stats.multicast++;
1911 skb->pkt_type = PACKET_BROADCAST;
1912 break;
1913 case QETH_CAST_UNICAST:
1914 case QETH_CAST_ANYCAST:
1915 case QETH_CAST_NOCAST:
1916 default:
1917 skb->pkt_type = PACKET_HOST;
1918 memcpy(tg_addr, card->dev->dev_addr,
1919 card->dev->addr_len);
1920 }
Ursula Braunfe94e2e2009-01-04 17:34:52 -08001921 if (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_SRC_MAC_ADDR)
1922 card->dev->header_ops->create(skb, card->dev, prot,
1923 tg_addr, &hdr->hdr.l3.dest_addr[2],
1924 card->dev->addr_len);
1925 else
1926 card->dev->header_ops->create(skb, card->dev, prot,
1927 tg_addr, "FAKELL", card->dev->addr_len);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001928 }
1929
1930#ifdef CONFIG_TR
1931 if (card->dev->type == ARPHRD_IEEE802_TR)
1932 skb->protocol = tr_type_trans(skb, card->dev);
1933 else
1934#endif
1935 skb->protocol = eth_type_trans(skb, card->dev);
1936
1937 if (hdr->hdr.l3.ext_flags &
1938 (QETH_HDR_EXT_VLAN_FRAME | QETH_HDR_EXT_INCLUDE_VLAN_TAG)) {
1939 vlan_id = (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_VLAN_FRAME)?
1940 hdr->hdr.l3.vlan_id : *((u16 *)&hdr->hdr.l3.dest_addr[12]);
1941 }
1942
1943 skb->ip_summed = card->options.checksum_type;
1944 if (card->options.checksum_type == HW_CHECKSUMMING) {
1945 if ((hdr->hdr.l3.ext_flags &
1946 (QETH_HDR_EXT_CSUM_HDR_REQ |
1947 QETH_HDR_EXT_CSUM_TRANSP_REQ)) ==
1948 (QETH_HDR_EXT_CSUM_HDR_REQ |
1949 QETH_HDR_EXT_CSUM_TRANSP_REQ))
1950 skb->ip_summed = CHECKSUM_UNNECESSARY;
1951 else
1952 skb->ip_summed = SW_CHECKSUMMING;
1953 }
1954
1955 return vlan_id;
1956}
1957
1958static void qeth_l3_process_inbound_buffer(struct qeth_card *card,
1959 struct qeth_qdio_buffer *buf, int index)
1960{
1961 struct qdio_buffer_element *element;
1962 struct sk_buff *skb;
1963 struct qeth_hdr *hdr;
1964 int offset;
1965 __u16 vlan_tag = 0;
1966 unsigned int len;
1967
1968 /* get first element of current buffer */
1969 element = (struct qdio_buffer_element *)&buf->buffer->element[0];
1970 offset = 0;
1971 if (card->options.performance_stats)
1972 card->perf_stats.bufs_rec++;
1973 while ((skb = qeth_core_get_next_skb(card, buf->buffer, &element,
1974 &offset, &hdr))) {
1975 skb->dev = card->dev;
1976 /* is device UP ? */
1977 if (!(card->dev->flags & IFF_UP)) {
1978 dev_kfree_skb_any(skb);
1979 continue;
1980 }
1981
1982 switch (hdr->hdr.l3.id) {
1983 case QETH_HEADER_TYPE_LAYER3:
1984 vlan_tag = qeth_l3_rebuild_skb(card, skb, hdr);
1985 len = skb->len;
1986 if (vlan_tag)
1987 if (card->vlangrp)
1988 vlan_hwaccel_rx(skb, card->vlangrp,
1989 vlan_tag);
1990 else {
1991 dev_kfree_skb_any(skb);
1992 continue;
1993 }
1994 else
1995 netif_rx(skb);
1996 break;
1997 default:
1998 dev_kfree_skb_any(skb);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001999 QETH_DBF_TEXT(TRACE, 3, "inbunkno");
2000 QETH_DBF_HEX(CTRL, 3, hdr, QETH_DBF_CTRL_LEN);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002001 continue;
2002 }
2003
2004 card->dev->last_rx = jiffies;
2005 card->stats.rx_packets++;
2006 card->stats.rx_bytes += len;
2007 }
2008}
2009
2010static int qeth_l3_verify_vlan_dev(struct net_device *dev,
2011 struct qeth_card *card)
2012{
2013 int rc = 0;
2014 struct vlan_group *vg;
2015 int i;
2016
2017 vg = card->vlangrp;
2018 if (!vg)
2019 return rc;
2020
2021 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
2022 if (vlan_group_get_device(vg, i) == dev) {
2023 rc = QETH_VLAN_CARD;
2024 break;
2025 }
2026 }
2027
Heiko Carstens509e2562008-07-26 02:24:10 -07002028 if (rc && !(vlan_dev_real_dev(dev)->ml_priv == (void *)card))
Frank Blaschka4a71df52008-02-15 09:19:42 +01002029 return 0;
2030
2031 return rc;
2032}
2033
2034static int qeth_l3_verify_dev(struct net_device *dev)
2035{
2036 struct qeth_card *card;
2037 unsigned long flags;
2038 int rc = 0;
2039
2040 read_lock_irqsave(&qeth_core_card_list.rwlock, flags);
2041 list_for_each_entry(card, &qeth_core_card_list.list, list) {
2042 if (card->dev == dev) {
2043 rc = QETH_REAL_CARD;
2044 break;
2045 }
2046 rc = qeth_l3_verify_vlan_dev(dev, card);
2047 if (rc)
2048 break;
2049 }
2050 read_unlock_irqrestore(&qeth_core_card_list.rwlock, flags);
2051
2052 return rc;
2053}
2054
2055static struct qeth_card *qeth_l3_get_card_from_dev(struct net_device *dev)
2056{
2057 struct qeth_card *card = NULL;
2058 int rc;
2059
2060 rc = qeth_l3_verify_dev(dev);
2061 if (rc == QETH_REAL_CARD)
Heiko Carstens509e2562008-07-26 02:24:10 -07002062 card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002063 else if (rc == QETH_VLAN_CARD)
Heiko Carstens509e2562008-07-26 02:24:10 -07002064 card = vlan_dev_real_dev(dev)->ml_priv;
Frank Blaschkae5bd7be2008-06-06 12:37:44 +02002065 if (card && card->options.layer2)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002066 card = NULL;
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002067 QETH_DBF_TEXT_(TRACE, 4, "%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002068 return card ;
2069}
2070
2071static int qeth_l3_stop_card(struct qeth_card *card, int recovery_mode)
2072{
2073 int rc = 0;
2074
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002075 QETH_DBF_TEXT(SETUP, 2, "stopcard");
2076 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01002077
2078 qeth_set_allowed_threads(card, 0, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002079 if (card->read.state == CH_STATE_UP &&
2080 card->write.state == CH_STATE_UP &&
2081 (card->state == CARD_STATE_UP)) {
2082 if (recovery_mode)
2083 qeth_l3_stop(card->dev);
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02002084 else {
Ursula Braunfc9c2462009-01-04 17:35:18 -08002085 if (card->dev) {
2086 rtnl_lock();
2087 dev_close(card->dev);
2088 rtnl_unlock();
2089 }
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02002090 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002091 if (!card->use_hard_stop) {
2092 rc = qeth_send_stoplan(card);
2093 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002094 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002095 }
2096 card->state = CARD_STATE_SOFTSETUP;
2097 }
2098 if (card->state == CARD_STATE_SOFTSETUP) {
2099 qeth_l3_clear_ip_list(card, !card->use_hard_stop, 1);
2100 qeth_clear_ipacmd_list(card);
2101 card->state = CARD_STATE_HARDSETUP;
2102 }
2103 if (card->state == CARD_STATE_HARDSETUP) {
2104 if (!card->use_hard_stop &&
2105 (card->info.type != QETH_CARD_TYPE_IQD)) {
2106 rc = qeth_l3_put_unique_id(card);
2107 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002108 QETH_DBF_TEXT_(SETUP, 2, "2err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002109 }
2110 qeth_qdio_clear_card(card, 0);
2111 qeth_clear_qdio_buffers(card);
2112 qeth_clear_working_pool_list(card);
2113 card->state = CARD_STATE_DOWN;
2114 }
2115 if (card->state == CARD_STATE_DOWN) {
2116 qeth_clear_cmd_buffers(&card->read);
2117 qeth_clear_cmd_buffers(&card->write);
2118 }
2119 card->use_hard_stop = 0;
2120 return rc;
2121}
2122
2123static void qeth_l3_set_multicast_list(struct net_device *dev)
2124{
Heiko Carstens509e2562008-07-26 02:24:10 -07002125 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002126
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002127 QETH_DBF_TEXT(TRACE, 3, "setmulti");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002128 qeth_l3_delete_mc_addresses(card);
2129 qeth_l3_add_multicast_ipv4(card);
2130#ifdef CONFIG_QETH_IPV6
2131 qeth_l3_add_multicast_ipv6(card);
2132#endif
2133 qeth_l3_set_ip_addr_list(card);
2134 if (!qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
2135 return;
2136 qeth_setadp_promisc_mode(card);
2137}
2138
2139static const char *qeth_l3_arp_get_error_cause(int *rc)
2140{
2141 switch (*rc) {
2142 case QETH_IPA_ARP_RC_FAILED:
2143 *rc = -EIO;
2144 return "operation failed";
2145 case QETH_IPA_ARP_RC_NOTSUPP:
2146 *rc = -EOPNOTSUPP;
2147 return "operation not supported";
2148 case QETH_IPA_ARP_RC_OUT_OF_RANGE:
2149 *rc = -EINVAL;
2150 return "argument out of range";
2151 case QETH_IPA_ARP_RC_Q_NOTSUPP:
2152 *rc = -EOPNOTSUPP;
2153 return "query operation not supported";
2154 case QETH_IPA_ARP_RC_Q_NO_DATA:
2155 *rc = -ENOENT;
2156 return "no query data available";
2157 default:
2158 return "unknown error";
2159 }
2160}
2161
2162static int qeth_l3_arp_set_no_entries(struct qeth_card *card, int no_entries)
2163{
2164 int tmp;
2165 int rc;
2166
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002167 QETH_DBF_TEXT(TRACE, 3, "arpstnoe");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002168
2169 /*
2170 * currently GuestLAN only supports the ARP assist function
2171 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_SET_NO_ENTRIES;
2172 * thus we say EOPNOTSUPP for this ARP function
2173 */
2174 if (card->info.guestlan)
2175 return -EOPNOTSUPP;
2176 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002177 return -EOPNOTSUPP;
2178 }
2179 rc = qeth_l3_send_simple_setassparms(card, IPA_ARP_PROCESSING,
2180 IPA_CMD_ASS_ARP_SET_NO_ENTRIES,
2181 no_entries);
2182 if (rc) {
2183 tmp = rc;
Frank Blaschka14cc21b2008-06-06 12:37:46 +02002184 QETH_DBF_MESSAGE(2, "Could not set number of ARP entries on "
2185 "%s: %s (0x%x/%d)\n", QETH_CARD_IFNAME(card),
Frank Blaschka4a71df52008-02-15 09:19:42 +01002186 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
2187 }
2188 return rc;
2189}
2190
2191static void qeth_l3_copy_arp_entries_stripped(struct qeth_arp_query_info *qinfo,
2192 struct qeth_arp_query_data *qdata, int entry_size,
2193 int uentry_size)
2194{
2195 char *entry_ptr;
2196 char *uentry_ptr;
2197 int i;
2198
2199 entry_ptr = (char *)&qdata->data;
2200 uentry_ptr = (char *)(qinfo->udata + qinfo->udata_offset);
2201 for (i = 0; i < qdata->no_entries; ++i) {
2202 /* strip off 32 bytes "media specific information" */
2203 memcpy(uentry_ptr, (entry_ptr + 32), entry_size - 32);
2204 entry_ptr += entry_size;
2205 uentry_ptr += uentry_size;
2206 }
2207}
2208
2209static int qeth_l3_arp_query_cb(struct qeth_card *card,
2210 struct qeth_reply *reply, unsigned long data)
2211{
2212 struct qeth_ipa_cmd *cmd;
2213 struct qeth_arp_query_data *qdata;
2214 struct qeth_arp_query_info *qinfo;
2215 int entry_size;
2216 int uentry_size;
2217 int i;
2218
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002219 QETH_DBF_TEXT(TRACE, 4, "arpquecb");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002220
2221 qinfo = (struct qeth_arp_query_info *) reply->param;
2222 cmd = (struct qeth_ipa_cmd *) data;
2223 if (cmd->hdr.return_code) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002224 QETH_DBF_TEXT_(TRACE, 4, "qaer1%i", cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002225 return 0;
2226 }
2227 if (cmd->data.setassparms.hdr.return_code) {
2228 cmd->hdr.return_code = cmd->data.setassparms.hdr.return_code;
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002229 QETH_DBF_TEXT_(TRACE, 4, "qaer2%i", cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002230 return 0;
2231 }
2232 qdata = &cmd->data.setassparms.data.query_arp;
2233 switch (qdata->reply_bits) {
2234 case 5:
2235 uentry_size = entry_size = sizeof(struct qeth_arp_qi_entry5);
2236 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES)
2237 uentry_size = sizeof(struct qeth_arp_qi_entry5_short);
2238 break;
2239 case 7:
2240 /* fall through to default */
2241 default:
2242 /* tr is the same as eth -> entry7 */
2243 uentry_size = entry_size = sizeof(struct qeth_arp_qi_entry7);
2244 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES)
2245 uentry_size = sizeof(struct qeth_arp_qi_entry7_short);
2246 break;
2247 }
2248 /* check if there is enough room in userspace */
2249 if ((qinfo->udata_len - qinfo->udata_offset) <
2250 qdata->no_entries * uentry_size){
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002251 QETH_DBF_TEXT_(TRACE, 4, "qaer3%i", -ENOMEM);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002252 cmd->hdr.return_code = -ENOMEM;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002253 goto out_error;
2254 }
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002255 QETH_DBF_TEXT_(TRACE, 4, "anore%i",
Frank Blaschka4a71df52008-02-15 09:19:42 +01002256 cmd->data.setassparms.hdr.number_of_replies);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002257 QETH_DBF_TEXT_(TRACE, 4, "aseqn%i", cmd->data.setassparms.hdr.seq_no);
2258 QETH_DBF_TEXT_(TRACE, 4, "anoen%i", qdata->no_entries);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002259
2260 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES) {
2261 /* strip off "media specific information" */
2262 qeth_l3_copy_arp_entries_stripped(qinfo, qdata, entry_size,
2263 uentry_size);
2264 } else
2265 /*copy entries to user buffer*/
2266 memcpy(qinfo->udata + qinfo->udata_offset,
2267 (char *)&qdata->data, qdata->no_entries*uentry_size);
2268
2269 qinfo->no_entries += qdata->no_entries;
2270 qinfo->udata_offset += (qdata->no_entries*uentry_size);
2271 /* check if all replies received ... */
2272 if (cmd->data.setassparms.hdr.seq_no <
2273 cmd->data.setassparms.hdr.number_of_replies)
2274 return 1;
2275 memcpy(qinfo->udata, &qinfo->no_entries, 4);
2276 /* keep STRIP_ENTRIES flag so the user program can distinguish
2277 * stripped entries from normal ones */
2278 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES)
2279 qdata->reply_bits |= QETH_QARP_STRIP_ENTRIES;
2280 memcpy(qinfo->udata + QETH_QARP_MASK_OFFSET, &qdata->reply_bits, 2);
2281 return 0;
2282out_error:
2283 i = 0;
2284 memcpy(qinfo->udata, &i, 4);
2285 return 0;
2286}
2287
2288static int qeth_l3_send_ipa_arp_cmd(struct qeth_card *card,
2289 struct qeth_cmd_buffer *iob, int len,
2290 int (*reply_cb)(struct qeth_card *, struct qeth_reply *,
2291 unsigned long),
2292 void *reply_param)
2293{
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002294 QETH_DBF_TEXT(TRACE, 4, "sendarp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002295
2296 memcpy(iob->data, IPA_PDU_HEADER, IPA_PDU_HEADER_SIZE);
2297 memcpy(QETH_IPA_CMD_DEST_ADDR(iob->data),
2298 &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
2299 return qeth_send_control_data(card, IPA_PDU_HEADER_SIZE + len, iob,
2300 reply_cb, reply_param);
2301}
2302
2303static int qeth_l3_arp_query(struct qeth_card *card, char __user *udata)
2304{
2305 struct qeth_cmd_buffer *iob;
2306 struct qeth_arp_query_info qinfo = {0, };
2307 int tmp;
2308 int rc;
2309
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002310 QETH_DBF_TEXT(TRACE, 3, "arpquery");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002311
2312 if (!qeth_is_supported(card,/*IPA_QUERY_ARP_ADDR_INFO*/
2313 IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002314 return -EOPNOTSUPP;
2315 }
2316 /* get size of userspace buffer and mask_bits -> 6 bytes */
2317 if (copy_from_user(&qinfo, udata, 6))
2318 return -EFAULT;
2319 qinfo.udata = kzalloc(qinfo.udata_len, GFP_KERNEL);
2320 if (!qinfo.udata)
2321 return -ENOMEM;
2322 qinfo.udata_offset = QETH_QARP_ENTRIES_OFFSET;
2323 iob = qeth_l3_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
2324 IPA_CMD_ASS_ARP_QUERY_INFO,
2325 sizeof(int), QETH_PROT_IPV4);
2326
2327 rc = qeth_l3_send_ipa_arp_cmd(card, iob,
2328 QETH_SETASS_BASE_LEN+QETH_ARP_CMD_LEN,
2329 qeth_l3_arp_query_cb, (void *)&qinfo);
2330 if (rc) {
2331 tmp = rc;
Frank Blaschka14cc21b2008-06-06 12:37:46 +02002332 QETH_DBF_MESSAGE(2, "Error while querying ARP cache on %s: %s "
Frank Blaschka4a71df52008-02-15 09:19:42 +01002333 "(0x%x/%d)\n", QETH_CARD_IFNAME(card),
2334 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
2335 if (copy_to_user(udata, qinfo.udata, 4))
2336 rc = -EFAULT;
2337 } else {
2338 if (copy_to_user(udata, qinfo.udata, qinfo.udata_len))
2339 rc = -EFAULT;
2340 }
2341 kfree(qinfo.udata);
2342 return rc;
2343}
2344
2345static int qeth_l3_arp_add_entry(struct qeth_card *card,
2346 struct qeth_arp_cache_entry *entry)
2347{
2348 struct qeth_cmd_buffer *iob;
2349 char buf[16];
2350 int tmp;
2351 int rc;
2352
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002353 QETH_DBF_TEXT(TRACE, 3, "arpadent");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002354
2355 /*
2356 * currently GuestLAN only supports the ARP assist function
2357 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_ADD_ENTRY;
2358 * thus we say EOPNOTSUPP for this ARP function
2359 */
2360 if (card->info.guestlan)
2361 return -EOPNOTSUPP;
2362 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002363 return -EOPNOTSUPP;
2364 }
2365
2366 iob = qeth_l3_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
2367 IPA_CMD_ASS_ARP_ADD_ENTRY,
2368 sizeof(struct qeth_arp_cache_entry),
2369 QETH_PROT_IPV4);
2370 rc = qeth_l3_send_setassparms(card, iob,
2371 sizeof(struct qeth_arp_cache_entry),
2372 (unsigned long) entry,
2373 qeth_l3_default_setassparms_cb, NULL);
2374 if (rc) {
2375 tmp = rc;
2376 qeth_l3_ipaddr4_to_string((u8 *)entry->ipaddr, buf);
Frank Blaschka14cc21b2008-06-06 12:37:46 +02002377 QETH_DBF_MESSAGE(2, "Could not add ARP entry for address %s "
2378 "on %s: %s (0x%x/%d)\n", buf, QETH_CARD_IFNAME(card),
2379 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002380 }
2381 return rc;
2382}
2383
2384static int qeth_l3_arp_remove_entry(struct qeth_card *card,
2385 struct qeth_arp_cache_entry *entry)
2386{
2387 struct qeth_cmd_buffer *iob;
2388 char buf[16] = {0, };
2389 int tmp;
2390 int rc;
2391
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002392 QETH_DBF_TEXT(TRACE, 3, "arprment");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002393
2394 /*
2395 * currently GuestLAN only supports the ARP assist function
2396 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_REMOVE_ENTRY;
2397 * thus we say EOPNOTSUPP for this ARP function
2398 */
2399 if (card->info.guestlan)
2400 return -EOPNOTSUPP;
2401 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002402 return -EOPNOTSUPP;
2403 }
2404 memcpy(buf, entry, 12);
2405 iob = qeth_l3_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
2406 IPA_CMD_ASS_ARP_REMOVE_ENTRY,
2407 12,
2408 QETH_PROT_IPV4);
2409 rc = qeth_l3_send_setassparms(card, iob,
2410 12, (unsigned long)buf,
2411 qeth_l3_default_setassparms_cb, NULL);
2412 if (rc) {
2413 tmp = rc;
2414 memset(buf, 0, 16);
2415 qeth_l3_ipaddr4_to_string((u8 *)entry->ipaddr, buf);
Frank Blaschka14cc21b2008-06-06 12:37:46 +02002416 QETH_DBF_MESSAGE(2, "Could not delete ARP entry for address %s"
2417 " on %s: %s (0x%x/%d)\n", buf, QETH_CARD_IFNAME(card),
2418 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002419 }
2420 return rc;
2421}
2422
2423static int qeth_l3_arp_flush_cache(struct qeth_card *card)
2424{
2425 int rc;
2426 int tmp;
2427
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002428 QETH_DBF_TEXT(TRACE, 3, "arpflush");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002429
2430 /*
2431 * currently GuestLAN only supports the ARP assist function
2432 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_FLUSH_CACHE;
2433 * thus we say EOPNOTSUPP for this ARP function
2434 */
2435 if (card->info.guestlan || (card->info.type == QETH_CARD_TYPE_IQD))
2436 return -EOPNOTSUPP;
2437 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002438 return -EOPNOTSUPP;
2439 }
2440 rc = qeth_l3_send_simple_setassparms(card, IPA_ARP_PROCESSING,
2441 IPA_CMD_ASS_ARP_FLUSH_CACHE, 0);
2442 if (rc) {
2443 tmp = rc;
Frank Blaschka14cc21b2008-06-06 12:37:46 +02002444 QETH_DBF_MESSAGE(2, "Could not flush ARP cache on %s: %s "
2445 "(0x%x/%d)\n", QETH_CARD_IFNAME(card),
Frank Blaschka4a71df52008-02-15 09:19:42 +01002446 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
2447 }
2448 return rc;
2449}
2450
2451static int qeth_l3_do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
2452{
Heiko Carstens509e2562008-07-26 02:24:10 -07002453 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002454 struct qeth_arp_cache_entry arp_entry;
2455 struct mii_ioctl_data *mii_data;
2456 int rc = 0;
2457
2458 if (!card)
2459 return -ENODEV;
2460
2461 if ((card->state != CARD_STATE_UP) &&
2462 (card->state != CARD_STATE_SOFTSETUP))
2463 return -ENODEV;
2464
2465 switch (cmd) {
2466 case SIOC_QETH_ARP_SET_NO_ENTRIES:
2467 if (!capable(CAP_NET_ADMIN)) {
2468 rc = -EPERM;
2469 break;
2470 }
2471 rc = qeth_l3_arp_set_no_entries(card, rq->ifr_ifru.ifru_ivalue);
2472 break;
2473 case SIOC_QETH_ARP_QUERY_INFO:
2474 if (!capable(CAP_NET_ADMIN)) {
2475 rc = -EPERM;
2476 break;
2477 }
2478 rc = qeth_l3_arp_query(card, rq->ifr_ifru.ifru_data);
2479 break;
2480 case SIOC_QETH_ARP_ADD_ENTRY:
2481 if (!capable(CAP_NET_ADMIN)) {
2482 rc = -EPERM;
2483 break;
2484 }
2485 if (copy_from_user(&arp_entry, rq->ifr_ifru.ifru_data,
2486 sizeof(struct qeth_arp_cache_entry)))
2487 rc = -EFAULT;
2488 else
2489 rc = qeth_l3_arp_add_entry(card, &arp_entry);
2490 break;
2491 case SIOC_QETH_ARP_REMOVE_ENTRY:
2492 if (!capable(CAP_NET_ADMIN)) {
2493 rc = -EPERM;
2494 break;
2495 }
2496 if (copy_from_user(&arp_entry, rq->ifr_ifru.ifru_data,
2497 sizeof(struct qeth_arp_cache_entry)))
2498 rc = -EFAULT;
2499 else
2500 rc = qeth_l3_arp_remove_entry(card, &arp_entry);
2501 break;
2502 case SIOC_QETH_ARP_FLUSH_CACHE:
2503 if (!capable(CAP_NET_ADMIN)) {
2504 rc = -EPERM;
2505 break;
2506 }
2507 rc = qeth_l3_arp_flush_cache(card);
2508 break;
2509 case SIOC_QETH_ADP_SET_SNMP_CONTROL:
2510 rc = qeth_snmp_command(card, rq->ifr_ifru.ifru_data);
2511 break;
2512 case SIOC_QETH_GET_CARD_TYPE:
2513 if ((card->info.type == QETH_CARD_TYPE_OSAE) &&
2514 !card->info.guestlan)
2515 return 1;
2516 return 0;
2517 break;
2518 case SIOCGMIIPHY:
2519 mii_data = if_mii(rq);
2520 mii_data->phy_id = 0;
2521 break;
2522 case SIOCGMIIREG:
2523 mii_data = if_mii(rq);
2524 if (mii_data->phy_id != 0)
2525 rc = -EINVAL;
2526 else
2527 mii_data->val_out = qeth_mdio_read(dev,
2528 mii_data->phy_id,
2529 mii_data->reg_num);
2530 break;
2531 default:
2532 rc = -EOPNOTSUPP;
2533 }
2534 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002535 QETH_DBF_TEXT_(TRACE, 2, "ioce%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002536 return rc;
2537}
2538
2539static void qeth_l3_fill_header(struct qeth_card *card, struct qeth_hdr *hdr,
2540 struct sk_buff *skb, int ipv, int cast_type)
2541{
Frank Blaschka4a71df52008-02-15 09:19:42 +01002542 memset(hdr, 0, sizeof(struct qeth_hdr));
2543 hdr->hdr.l3.id = QETH_HEADER_TYPE_LAYER3;
2544 hdr->hdr.l3.ext_flags = 0;
2545
2546 /*
2547 * before we're going to overwrite this location with next hop ip.
2548 * v6 uses passthrough, v4 sets the tag in the QDIO header.
2549 */
2550 if (card->vlangrp && vlan_tx_tag_present(skb)) {
Frank Blaschka213298f2008-04-24 10:15:22 +02002551 if ((ipv == 4) || (card->info.type == QETH_CARD_TYPE_IQD))
2552 hdr->hdr.l3.ext_flags = QETH_HDR_EXT_VLAN_FRAME;
2553 else
2554 hdr->hdr.l3.ext_flags = QETH_HDR_EXT_INCLUDE_VLAN_TAG;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002555 hdr->hdr.l3.vlan_id = vlan_tx_tag_get(skb);
2556 }
2557
2558 hdr->hdr.l3.length = skb->len - sizeof(struct qeth_hdr);
2559 if (ipv == 4) {
2560 /* IPv4 */
2561 hdr->hdr.l3.flags = qeth_l3_get_qeth_hdr_flags4(cast_type);
2562 memset(hdr->hdr.l3.dest_addr, 0, 12);
2563 if ((skb->dst) && (skb->dst->neighbour)) {
2564 *((u32 *) (&hdr->hdr.l3.dest_addr[12])) =
2565 *((u32 *) skb->dst->neighbour->primary_key);
2566 } else {
2567 /* fill in destination address used in ip header */
2568 *((u32 *) (&hdr->hdr.l3.dest_addr[12])) =
2569 ip_hdr(skb)->daddr;
2570 }
2571 } else if (ipv == 6) {
2572 /* IPv6 */
2573 hdr->hdr.l3.flags = qeth_l3_get_qeth_hdr_flags6(cast_type);
2574 if (card->info.type == QETH_CARD_TYPE_IQD)
2575 hdr->hdr.l3.flags &= ~QETH_HDR_PASSTHRU;
2576 if ((skb->dst) && (skb->dst->neighbour)) {
2577 memcpy(hdr->hdr.l3.dest_addr,
2578 skb->dst->neighbour->primary_key, 16);
2579 } else {
2580 /* fill in destination address used in ip header */
2581 memcpy(hdr->hdr.l3.dest_addr,
2582 &ipv6_hdr(skb)->daddr, 16);
2583 }
2584 } else {
2585 /* passthrough */
2586 if ((skb->dev->type == ARPHRD_IEEE802_TR) &&
2587 !memcmp(skb->data + sizeof(struct qeth_hdr) +
2588 sizeof(__u16), skb->dev->broadcast, 6)) {
2589 hdr->hdr.l3.flags = QETH_CAST_BROADCAST |
2590 QETH_HDR_PASSTHRU;
2591 } else if (!memcmp(skb->data + sizeof(struct qeth_hdr),
2592 skb->dev->broadcast, 6)) {
2593 /* broadcast? */
2594 hdr->hdr.l3.flags = QETH_CAST_BROADCAST |
2595 QETH_HDR_PASSTHRU;
2596 } else {
2597 hdr->hdr.l3.flags = (cast_type == RTN_MULTICAST) ?
2598 QETH_CAST_MULTICAST | QETH_HDR_PASSTHRU :
2599 QETH_CAST_UNICAST | QETH_HDR_PASSTHRU;
2600 }
2601 }
2602}
2603
2604static int qeth_l3_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
2605{
2606 int rc;
2607 u16 *tag;
2608 struct qeth_hdr *hdr = NULL;
2609 int elements_needed = 0;
Heiko Carstens509e2562008-07-26 02:24:10 -07002610 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002611 struct sk_buff *new_skb = NULL;
2612 int ipv = qeth_get_ip_version(skb);
2613 int cast_type = qeth_get_cast_type(card, skb);
2614 struct qeth_qdio_out_q *queue = card->qdio.out_qs
2615 [qeth_get_priority_queue(card, skb, ipv, cast_type)];
2616 int tx_bytes = skb->len;
2617 enum qeth_large_send_types large_send = QETH_LARGE_SEND_NO;
2618 struct qeth_eddp_context *ctx = NULL;
Frank Blaschka683d7182008-08-01 16:39:13 +02002619 int data_offset = -1;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002620
Frank Blaschka4a71df52008-02-15 09:19:42 +01002621 if ((card->info.type == QETH_CARD_TYPE_IQD) &&
2622 (skb->protocol != htons(ETH_P_IPV6)) &&
2623 (skb->protocol != htons(ETH_P_IP)))
2624 goto tx_drop;
2625
2626 if ((card->state != CARD_STATE_UP) || !card->lan_online) {
2627 card->stats.tx_carrier_errors++;
2628 goto tx_drop;
2629 }
2630
2631 if ((cast_type == RTN_BROADCAST) &&
2632 (card->info.broadcast_capable == 0))
2633 goto tx_drop;
2634
2635 if (card->options.performance_stats) {
2636 card->perf_stats.outbound_cnt++;
2637 card->perf_stats.outbound_start_time = qeth_get_micros();
2638 }
2639
Frank Blaschka683d7182008-08-01 16:39:13 +02002640 if (skb_is_gso(skb))
2641 large_send = card->options.large_send;
2642
2643 if ((card->info.type == QETH_CARD_TYPE_IQD) && (!large_send) &&
2644 (skb_shinfo(skb)->nr_frags == 0)) {
2645 new_skb = skb;
2646 data_offset = ETH_HLEN;
2647 hdr = kmem_cache_alloc(qeth_core_header_cache, GFP_ATOMIC);
2648 if (!hdr)
2649 goto tx_drop;
2650 elements_needed++;
2651 } else {
2652 /* create a clone with writeable headroom */
2653 new_skb = skb_realloc_headroom(skb, sizeof(struct qeth_hdr_tso)
2654 + VLAN_HLEN);
2655 if (!new_skb)
2656 goto tx_drop;
2657 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002658
2659 if (card->info.type == QETH_CARD_TYPE_IQD) {
Frank Blaschka683d7182008-08-01 16:39:13 +02002660 if (data_offset < 0)
2661 skb_pull(new_skb, ETH_HLEN);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002662 } else {
2663 if (new_skb->protocol == htons(ETH_P_IP)) {
2664 if (card->dev->type == ARPHRD_IEEE802_TR)
2665 skb_pull(new_skb, TR_HLEN);
2666 else
2667 skb_pull(new_skb, ETH_HLEN);
2668 }
2669
2670 if (new_skb->protocol == ETH_P_IPV6 && card->vlangrp &&
2671 vlan_tx_tag_present(new_skb)) {
2672 skb_push(new_skb, VLAN_HLEN);
2673 skb_copy_to_linear_data(new_skb, new_skb->data + 4, 4);
2674 skb_copy_to_linear_data_offset(new_skb, 4,
2675 new_skb->data + 8, 4);
2676 skb_copy_to_linear_data_offset(new_skb, 8,
2677 new_skb->data + 12, 4);
2678 tag = (u16 *)(new_skb->data + 12);
2679 *tag = __constant_htons(ETH_P_8021Q);
2680 *(tag + 1) = htons(vlan_tx_tag_get(new_skb));
frank.blaschka@de.ibm.com2b4ff112008-07-22 09:39:25 +02002681 new_skb->vlan_tci = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002682 }
2683 }
2684
2685 netif_stop_queue(dev);
2686
Frank Blaschka4a71df52008-02-15 09:19:42 +01002687 /* fix hardware limitation: as long as we do not have sbal
2688 * chaining we can not send long frag lists so we temporary
2689 * switch to EDDP
2690 */
2691 if ((large_send == QETH_LARGE_SEND_TSO) &&
2692 ((skb_shinfo(new_skb)->nr_frags + 2) > 16))
2693 large_send = QETH_LARGE_SEND_EDDP;
2694
2695 if ((large_send == QETH_LARGE_SEND_TSO) &&
2696 (cast_type == RTN_UNSPEC)) {
2697 hdr = (struct qeth_hdr *)skb_push(new_skb,
2698 sizeof(struct qeth_hdr_tso));
2699 memset(hdr, 0, sizeof(struct qeth_hdr_tso));
2700 qeth_l3_fill_header(card, hdr, new_skb, ipv, cast_type);
2701 qeth_tso_fill_header(card, hdr, new_skb);
2702 elements_needed++;
2703 } else {
Frank Blaschka683d7182008-08-01 16:39:13 +02002704 if (data_offset < 0) {
2705 hdr = (struct qeth_hdr *)skb_push(new_skb,
Frank Blaschka4a71df52008-02-15 09:19:42 +01002706 sizeof(struct qeth_hdr));
Frank Blaschka683d7182008-08-01 16:39:13 +02002707 qeth_l3_fill_header(card, hdr, new_skb, ipv,
2708 cast_type);
2709 } else {
2710 qeth_l3_fill_header(card, hdr, new_skb, ipv,
2711 cast_type);
2712 hdr->hdr.l3.length = new_skb->len - data_offset;
2713 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002714 }
2715
2716 if (large_send == QETH_LARGE_SEND_EDDP) {
2717 /* new_skb is not owned by a socket so we use skb to get
2718 * the protocol
2719 */
2720 ctx = qeth_eddp_create_context(card, new_skb, hdr,
2721 skb->sk->sk_protocol);
2722 if (ctx == NULL) {
Frank Blaschka14cc21b2008-06-06 12:37:46 +02002723 QETH_DBF_MESSAGE(2, "could not create eddp context\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002724 goto tx_drop;
2725 }
2726 } else {
2727 int elems = qeth_get_elements_no(card, (void *)hdr, new_skb,
2728 elements_needed);
Frank Blaschka683d7182008-08-01 16:39:13 +02002729 if (!elems) {
2730 if (data_offset >= 0)
2731 kmem_cache_free(qeth_core_header_cache, hdr);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002732 goto tx_drop;
Frank Blaschka683d7182008-08-01 16:39:13 +02002733 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002734 elements_needed += elems;
2735 }
2736
2737 if ((large_send == QETH_LARGE_SEND_NO) &&
2738 (new_skb->ip_summed == CHECKSUM_PARTIAL))
2739 qeth_tx_csum(new_skb);
2740
2741 if (card->info.type != QETH_CARD_TYPE_IQD)
2742 rc = qeth_do_send_packet(card, queue, new_skb, hdr,
2743 elements_needed, ctx);
2744 else
2745 rc = qeth_do_send_packet_fast(card, queue, new_skb, hdr,
Frank Blaschka683d7182008-08-01 16:39:13 +02002746 elements_needed, ctx, data_offset, 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002747
2748 if (!rc) {
2749 card->stats.tx_packets++;
2750 card->stats.tx_bytes += tx_bytes;
2751 if (new_skb != skb)
2752 dev_kfree_skb_any(skb);
2753 if (card->options.performance_stats) {
2754 if (large_send != QETH_LARGE_SEND_NO) {
2755 card->perf_stats.large_send_bytes += tx_bytes;
2756 card->perf_stats.large_send_cnt++;
2757 }
2758 if (skb_shinfo(new_skb)->nr_frags > 0) {
2759 card->perf_stats.sg_skbs_sent++;
2760 /* nr_frags + skb->data */
2761 card->perf_stats.sg_frags_sent +=
2762 skb_shinfo(new_skb)->nr_frags + 1;
2763 }
2764 }
2765
2766 if (ctx != NULL) {
2767 qeth_eddp_put_context(ctx);
2768 dev_kfree_skb_any(new_skb);
2769 }
2770 } else {
2771 if (ctx != NULL)
2772 qeth_eddp_put_context(ctx);
2773
Frank Blaschka683d7182008-08-01 16:39:13 +02002774 if (data_offset >= 0)
2775 kmem_cache_free(qeth_core_header_cache, hdr);
2776
Frank Blaschka4a71df52008-02-15 09:19:42 +01002777 if (rc == -EBUSY) {
2778 if (new_skb != skb)
2779 dev_kfree_skb_any(new_skb);
2780 return NETDEV_TX_BUSY;
2781 } else
2782 goto tx_drop;
2783 }
2784
2785 netif_wake_queue(dev);
2786 if (card->options.performance_stats)
2787 card->perf_stats.outbound_time += qeth_get_micros() -
2788 card->perf_stats.outbound_start_time;
2789 return rc;
2790
2791tx_drop:
2792 card->stats.tx_dropped++;
2793 card->stats.tx_errors++;
2794 if ((new_skb != skb) && new_skb)
2795 dev_kfree_skb_any(new_skb);
2796 dev_kfree_skb_any(skb);
Frank Blaschkad0ec0f52008-06-06 12:37:48 +02002797 netif_wake_queue(dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002798 return NETDEV_TX_OK;
2799}
2800
2801static int qeth_l3_open(struct net_device *dev)
2802{
Heiko Carstens509e2562008-07-26 02:24:10 -07002803 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002804
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002805 QETH_DBF_TEXT(TRACE, 4, "qethopen");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002806 if (card->state != CARD_STATE_SOFTSETUP)
2807 return -ENODEV;
2808 card->data.state = CH_STATE_UP;
2809 card->state = CARD_STATE_UP;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002810 netif_start_queue(dev);
2811
2812 if (!card->lan_online && netif_carrier_ok(dev))
2813 netif_carrier_off(dev);
2814 return 0;
2815}
2816
2817static int qeth_l3_stop(struct net_device *dev)
2818{
Heiko Carstens509e2562008-07-26 02:24:10 -07002819 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002820
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002821 QETH_DBF_TEXT(TRACE, 4, "qethstop");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002822 netif_tx_disable(dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002823 if (card->state == CARD_STATE_UP)
2824 card->state = CARD_STATE_SOFTSETUP;
2825 return 0;
2826}
2827
2828static u32 qeth_l3_ethtool_get_rx_csum(struct net_device *dev)
2829{
Heiko Carstens509e2562008-07-26 02:24:10 -07002830 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002831
2832 return (card->options.checksum_type == HW_CHECKSUMMING);
2833}
2834
2835static int qeth_l3_ethtool_set_rx_csum(struct net_device *dev, u32 data)
2836{
Heiko Carstens509e2562008-07-26 02:24:10 -07002837 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002838 enum qeth_card_states old_state;
2839 enum qeth_checksum_types csum_type;
2840
2841 if ((card->state != CARD_STATE_UP) &&
2842 (card->state != CARD_STATE_DOWN))
2843 return -EPERM;
2844
2845 if (data)
2846 csum_type = HW_CHECKSUMMING;
2847 else
2848 csum_type = SW_CHECKSUMMING;
2849
2850 if (card->options.checksum_type != csum_type) {
2851 old_state = card->state;
2852 if (card->state == CARD_STATE_UP)
2853 __qeth_l3_set_offline(card->gdev, 1);
2854 card->options.checksum_type = csum_type;
2855 if (old_state == CARD_STATE_UP)
2856 __qeth_l3_set_online(card->gdev, 1);
2857 }
2858 return 0;
2859}
2860
2861static int qeth_l3_ethtool_set_tso(struct net_device *dev, u32 data)
2862{
Heiko Carstens509e2562008-07-26 02:24:10 -07002863 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002864
2865 if (data) {
2866 if (card->options.large_send == QETH_LARGE_SEND_NO) {
2867 if (card->info.type == QETH_CARD_TYPE_IQD)
2868 card->options.large_send = QETH_LARGE_SEND_EDDP;
2869 else
2870 card->options.large_send = QETH_LARGE_SEND_TSO;
2871 dev->features |= NETIF_F_TSO;
2872 }
2873 } else {
2874 dev->features &= ~NETIF_F_TSO;
2875 card->options.large_send = QETH_LARGE_SEND_NO;
2876 }
2877 return 0;
2878}
2879
2880static struct ethtool_ops qeth_l3_ethtool_ops = {
2881 .get_link = ethtool_op_get_link,
2882 .get_tx_csum = ethtool_op_get_tx_csum,
2883 .set_tx_csum = ethtool_op_set_tx_hw_csum,
2884 .get_rx_csum = qeth_l3_ethtool_get_rx_csum,
2885 .set_rx_csum = qeth_l3_ethtool_set_rx_csum,
2886 .get_sg = ethtool_op_get_sg,
2887 .set_sg = ethtool_op_set_sg,
2888 .get_tso = ethtool_op_get_tso,
2889 .set_tso = qeth_l3_ethtool_set_tso,
2890 .get_strings = qeth_core_get_strings,
2891 .get_ethtool_stats = qeth_core_get_ethtool_stats,
2892 .get_stats_count = qeth_core_get_stats_count,
2893 .get_drvinfo = qeth_core_get_drvinfo,
Frank Blaschka3f9975a2008-04-24 10:15:23 +02002894 .get_settings = qeth_core_ethtool_get_settings,
Frank Blaschka4a71df52008-02-15 09:19:42 +01002895};
2896
2897/*
2898 * we need NOARP for IPv4 but we want neighbor solicitation for IPv6. Setting
2899 * NOARP on the netdevice is no option because it also turns off neighbor
2900 * solicitation. For IPv4 we install a neighbor_setup function. We don't want
2901 * arp resolution but we want the hard header (packet socket will work
2902 * e.g. tcpdump)
2903 */
2904static int qeth_l3_neigh_setup_noarp(struct neighbour *n)
2905{
2906 n->nud_state = NUD_NOARP;
2907 memcpy(n->ha, "FAKELL", 6);
2908 n->output = n->ops->connected_output;
2909 return 0;
2910}
2911
2912static int
2913qeth_l3_neigh_setup(struct net_device *dev, struct neigh_parms *np)
2914{
2915 if (np->tbl->family == AF_INET)
2916 np->neigh_setup = qeth_l3_neigh_setup_noarp;
2917
2918 return 0;
2919}
2920
2921static int qeth_l3_setup_netdev(struct qeth_card *card)
2922{
2923 if (card->info.type == QETH_CARD_TYPE_OSAE) {
2924 if ((card->info.link_type == QETH_LINK_TYPE_LANE_TR) ||
2925 (card->info.link_type == QETH_LINK_TYPE_HSTR)) {
2926#ifdef CONFIG_TR
2927 card->dev = alloc_trdev(0);
2928#endif
2929 if (!card->dev)
2930 return -ENODEV;
2931 } else {
2932 card->dev = alloc_etherdev(0);
2933 if (!card->dev)
2934 return -ENODEV;
2935 card->dev->neigh_setup = qeth_l3_neigh_setup;
2936
2937 /*IPv6 address autoconfiguration stuff*/
2938 qeth_l3_get_unique_id(card);
2939 if (!(card->info.unique_id & UNIQUE_ID_NOT_BY_CARD))
2940 card->dev->dev_id = card->info.unique_id &
2941 0xffff;
2942 }
2943 } else if (card->info.type == QETH_CARD_TYPE_IQD) {
2944 card->dev = alloc_netdev(0, "hsi%d", ether_setup);
2945 if (!card->dev)
2946 return -ENODEV;
2947 card->dev->flags |= IFF_NOARP;
2948 qeth_l3_iqd_read_initial_mac(card);
2949 } else
2950 return -ENODEV;
2951
2952 card->dev->hard_start_xmit = qeth_l3_hard_start_xmit;
Heiko Carstens509e2562008-07-26 02:24:10 -07002953 card->dev->ml_priv = card;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002954 card->dev->tx_timeout = &qeth_tx_timeout;
2955 card->dev->watchdog_timeo = QETH_TX_TIMEOUT;
2956 card->dev->open = qeth_l3_open;
2957 card->dev->stop = qeth_l3_stop;
2958 card->dev->do_ioctl = qeth_l3_do_ioctl;
2959 card->dev->get_stats = qeth_get_stats;
2960 card->dev->change_mtu = qeth_change_mtu;
2961 card->dev->set_multicast_list = qeth_l3_set_multicast_list;
2962 card->dev->vlan_rx_register = qeth_l3_vlan_rx_register;
2963 card->dev->vlan_rx_add_vid = qeth_l3_vlan_rx_add_vid;
2964 card->dev->vlan_rx_kill_vid = qeth_l3_vlan_rx_kill_vid;
2965 card->dev->mtu = card->info.initial_mtu;
Frank Blaschkab7624ec2008-04-01 10:26:57 +02002966 card->dev->set_mac_address = NULL;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002967 SET_ETHTOOL_OPS(card->dev, &qeth_l3_ethtool_ops);
2968 card->dev->features |= NETIF_F_HW_VLAN_TX |
2969 NETIF_F_HW_VLAN_RX |
2970 NETIF_F_HW_VLAN_FILTER;
2971
2972 SET_NETDEV_DEV(card->dev, &card->gdev->dev);
2973 return register_netdev(card->dev);
2974}
2975
2976static void qeth_l3_qdio_input_handler(struct ccw_device *ccwdev,
Jan Glauber779e6e12008-07-17 17:16:48 +02002977 unsigned int qdio_err, unsigned int queue, int first_element,
Frank Blaschka4a71df52008-02-15 09:19:42 +01002978 int count, unsigned long card_ptr)
2979{
2980 struct net_device *net_dev;
2981 struct qeth_card *card;
2982 struct qeth_qdio_buffer *buffer;
2983 int index;
2984 int i;
2985
Frank Blaschka4a71df52008-02-15 09:19:42 +01002986 card = (struct qeth_card *) card_ptr;
2987 net_dev = card->dev;
2988 if (card->options.performance_stats) {
2989 card->perf_stats.inbound_cnt++;
2990 card->perf_stats.inbound_start_time = qeth_get_micros();
2991 }
Jan Glauber779e6e12008-07-17 17:16:48 +02002992 if (qdio_err & QDIO_ERROR_ACTIVATE_CHECK_CONDITION) {
2993 QETH_DBF_TEXT(TRACE, 1, "qdinchk");
2994 QETH_DBF_TEXT_(TRACE, 1, "%s", CARD_BUS_ID(card));
2995 QETH_DBF_TEXT_(TRACE, 1, "%04X%04X",
2996 first_element, count);
2997 QETH_DBF_TEXT_(TRACE, 1, "%04X", queue);
2998 qeth_schedule_recovery(card);
2999 return;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003000 }
3001 for (i = first_element; i < (first_element + count); ++i) {
3002 index = i % QDIO_MAX_BUFFERS_PER_Q;
3003 buffer = &card->qdio.in_q->bufs[index];
Jan Glauber779e6e12008-07-17 17:16:48 +02003004 if (!(qdio_err &&
Frank Blaschka4a71df52008-02-15 09:19:42 +01003005 qeth_check_qdio_errors(buffer->buffer,
Jan Glauber779e6e12008-07-17 17:16:48 +02003006 qdio_err, "qinerr")))
Frank Blaschka4a71df52008-02-15 09:19:42 +01003007 qeth_l3_process_inbound_buffer(card, buffer, index);
3008 /* clear buffer and give back to hardware */
3009 qeth_put_buffer_pool_entry(card, buffer->pool_entry);
3010 qeth_queue_input_buffer(card, index);
3011 }
3012 if (card->options.performance_stats)
3013 card->perf_stats.inbound_time += qeth_get_micros() -
3014 card->perf_stats.inbound_start_time;
3015}
3016
3017static int qeth_l3_probe_device(struct ccwgroup_device *gdev)
3018{
3019 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3020
3021 qeth_l3_create_device_attributes(&gdev->dev);
3022 card->options.layer2 = 0;
3023 card->discipline.input_handler = (qdio_handler_t *)
3024 qeth_l3_qdio_input_handler;
3025 card->discipline.output_handler = (qdio_handler_t *)
3026 qeth_qdio_output_handler;
3027 card->discipline.recover = qeth_l3_recover;
3028 return 0;
3029}
3030
3031static void qeth_l3_remove_device(struct ccwgroup_device *cgdev)
3032{
3033 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
3034
3035 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
3036
3037 if (cgdev->state == CCWGROUP_ONLINE) {
3038 card->use_hard_stop = 1;
3039 qeth_l3_set_offline(cgdev);
3040 }
3041
3042 if (card->dev) {
3043 unregister_netdev(card->dev);
3044 card->dev = NULL;
3045 }
3046
3047 qeth_l3_remove_device_attributes(&cgdev->dev);
3048 qeth_l3_clear_ip_list(card, 0, 0);
3049 qeth_l3_clear_ipato_list(card);
3050 return;
3051}
3052
3053static int __qeth_l3_set_online(struct ccwgroup_device *gdev, int recovery_mode)
3054{
3055 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3056 int rc = 0;
3057 enum qeth_card_states recover_flag;
3058
3059 BUG_ON(!card);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003060 QETH_DBF_TEXT(SETUP, 2, "setonlin");
3061 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003062
3063 qeth_set_allowed_threads(card, QETH_RECOVER_THREAD, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003064
3065 recover_flag = card->state;
3066 rc = ccw_device_set_online(CARD_RDEV(card));
3067 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003068 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003069 return -EIO;
3070 }
3071 rc = ccw_device_set_online(CARD_WDEV(card));
3072 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003073 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003074 return -EIO;
3075 }
3076 rc = ccw_device_set_online(CARD_DDEV(card));
3077 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003078 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003079 return -EIO;
3080 }
3081
3082 rc = qeth_core_hardsetup_card(card);
3083 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003084 QETH_DBF_TEXT_(SETUP, 2, "2err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003085 goto out_remove;
3086 }
3087
3088 qeth_l3_query_ipassists(card, QETH_PROT_IPV4);
3089
3090 if (!card->dev && qeth_l3_setup_netdev(card))
3091 goto out_remove;
3092
3093 card->state = CARD_STATE_HARDSETUP;
3094 qeth_print_status_message(card);
3095
3096 /* softsetup */
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003097 QETH_DBF_TEXT(SETUP, 2, "softsetp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003098
3099 rc = qeth_send_startlan(card);
3100 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003101 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003102 if (rc == 0xe080) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003103 dev_warn(&card->gdev->dev,
3104 "The LAN is offline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003105 card->lan_online = 0;
3106 }
3107 return rc;
3108 } else
3109 card->lan_online = 1;
3110 qeth_set_large_send(card, card->options.large_send);
3111
3112 rc = qeth_l3_setadapter_parms(card);
3113 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003114 QETH_DBF_TEXT_(SETUP, 2, "2err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003115 rc = qeth_l3_start_ipassists(card);
3116 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003117 QETH_DBF_TEXT_(SETUP, 2, "3err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003118 rc = qeth_l3_setrouting_v4(card);
3119 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003120 QETH_DBF_TEXT_(SETUP, 2, "4err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003121 rc = qeth_l3_setrouting_v6(card);
3122 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003123 QETH_DBF_TEXT_(SETUP, 2, "5err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003124 netif_tx_disable(card->dev);
3125
3126 rc = qeth_init_qdio_queues(card);
3127 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003128 QETH_DBF_TEXT_(SETUP, 2, "6err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003129 goto out_remove;
3130 }
3131 card->state = CARD_STATE_SOFTSETUP;
3132 netif_carrier_on(card->dev);
3133
3134 qeth_set_allowed_threads(card, 0xffffffff, 0);
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02003135 if (recover_flag == CARD_STATE_RECOVER) {
3136 if (recovery_mode)
Frank Blaschka4a71df52008-02-15 09:19:42 +01003137 qeth_l3_open(card->dev);
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02003138 else {
3139 rtnl_lock();
3140 dev_open(card->dev);
3141 rtnl_unlock();
3142 }
3143 qeth_l3_set_multicast_list(card->dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003144 }
3145 /* let user_space know that device is online */
3146 kobject_uevent(&gdev->dev.kobj, KOBJ_CHANGE);
3147 return 0;
3148out_remove:
3149 card->use_hard_stop = 1;
3150 qeth_l3_stop_card(card, 0);
3151 ccw_device_set_offline(CARD_DDEV(card));
3152 ccw_device_set_offline(CARD_WDEV(card));
3153 ccw_device_set_offline(CARD_RDEV(card));
3154 if (recover_flag == CARD_STATE_RECOVER)
3155 card->state = CARD_STATE_RECOVER;
3156 else
3157 card->state = CARD_STATE_DOWN;
3158 return -ENODEV;
3159}
3160
3161static int qeth_l3_set_online(struct ccwgroup_device *gdev)
3162{
3163 return __qeth_l3_set_online(gdev, 0);
3164}
3165
3166static int __qeth_l3_set_offline(struct ccwgroup_device *cgdev,
3167 int recovery_mode)
3168{
3169 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
3170 int rc = 0, rc2 = 0, rc3 = 0;
3171 enum qeth_card_states recover_flag;
3172
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003173 QETH_DBF_TEXT(SETUP, 3, "setoffl");
3174 QETH_DBF_HEX(SETUP, 3, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003175
3176 if (card->dev && netif_carrier_ok(card->dev))
3177 netif_carrier_off(card->dev);
3178 recover_flag = card->state;
Ursula Braun0f5623c2008-10-24 11:16:52 +02003179 qeth_l3_stop_card(card, recovery_mode);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003180 rc = ccw_device_set_offline(CARD_DDEV(card));
3181 rc2 = ccw_device_set_offline(CARD_WDEV(card));
3182 rc3 = ccw_device_set_offline(CARD_RDEV(card));
3183 if (!rc)
3184 rc = (rc2) ? rc2 : rc3;
3185 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003186 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003187 if (recover_flag == CARD_STATE_UP)
3188 card->state = CARD_STATE_RECOVER;
3189 /* let user_space know that device is offline */
3190 kobject_uevent(&cgdev->dev.kobj, KOBJ_CHANGE);
3191 return 0;
3192}
3193
3194static int qeth_l3_set_offline(struct ccwgroup_device *cgdev)
3195{
3196 return __qeth_l3_set_offline(cgdev, 0);
3197}
3198
3199static int qeth_l3_recover(void *ptr)
3200{
3201 struct qeth_card *card;
3202 int rc = 0;
3203
3204 card = (struct qeth_card *) ptr;
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003205 QETH_DBF_TEXT(TRACE, 2, "recover1");
3206 QETH_DBF_HEX(TRACE, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003207 if (!qeth_do_run_thread(card, QETH_RECOVER_THREAD))
3208 return 0;
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003209 QETH_DBF_TEXT(TRACE, 2, "recover2");
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003210 dev_warn(&card->gdev->dev,
3211 "A recovery process has been started for the device\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003212 card->use_hard_stop = 1;
3213 __qeth_l3_set_offline(card->gdev, 1);
3214 rc = __qeth_l3_set_online(card->gdev, 1);
3215 /* don't run another scheduled recovery */
3216 qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD);
3217 qeth_clear_thread_running_bit(card, QETH_RECOVER_THREAD);
3218 if (!rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003219 dev_info(&card->gdev->dev,
3220 "Device successfully recovered!\n");
Ursula Braun28a7e4c2008-09-19 12:56:03 +02003221 else {
3222 rtnl_lock();
3223 dev_close(card->dev);
3224 rtnl_unlock();
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003225 dev_warn(&card->gdev->dev, "The qeth device driver "
3226 "failed to recover an error on the device\n");
Ursula Braun28a7e4c2008-09-19 12:56:03 +02003227 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01003228 return 0;
3229}
3230
3231static void qeth_l3_shutdown(struct ccwgroup_device *gdev)
3232{
3233 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3234 qeth_l3_clear_ip_list(card, 0, 0);
3235 qeth_qdio_clear_card(card, 0);
3236 qeth_clear_qdio_buffers(card);
3237}
3238
3239struct ccwgroup_driver qeth_l3_ccwgroup_driver = {
3240 .probe = qeth_l3_probe_device,
3241 .remove = qeth_l3_remove_device,
3242 .set_online = qeth_l3_set_online,
3243 .set_offline = qeth_l3_set_offline,
3244 .shutdown = qeth_l3_shutdown,
3245};
3246EXPORT_SYMBOL_GPL(qeth_l3_ccwgroup_driver);
3247
3248static int qeth_l3_ip_event(struct notifier_block *this,
David S. Miller76fef2b2008-03-22 18:22:42 -07003249 unsigned long event, void *ptr)
Frank Blaschka4a71df52008-02-15 09:19:42 +01003250{
3251 struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;
3252 struct net_device *dev = (struct net_device *)ifa->ifa_dev->dev;
3253 struct qeth_ipaddr *addr;
3254 struct qeth_card *card;
3255
YOSHIFUJI Hideakic346dca2008-03-25 21:47:49 +09003256 if (dev_net(dev) != &init_net)
David S. Miller76fef2b2008-03-22 18:22:42 -07003257 return NOTIFY_DONE;
3258
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003259 QETH_DBF_TEXT(TRACE, 3, "ipevent");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003260 card = qeth_l3_get_card_from_dev(dev);
3261 if (!card)
3262 return NOTIFY_DONE;
3263
3264 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
3265 if (addr != NULL) {
3266 addr->u.a4.addr = ifa->ifa_address;
3267 addr->u.a4.mask = ifa->ifa_mask;
3268 addr->type = QETH_IP_TYPE_NORMAL;
3269 } else
3270 goto out;
3271
3272 switch (event) {
3273 case NETDEV_UP:
3274 if (!qeth_l3_add_ip(card, addr))
3275 kfree(addr);
3276 break;
3277 case NETDEV_DOWN:
3278 if (!qeth_l3_delete_ip(card, addr))
3279 kfree(addr);
3280 break;
3281 default:
3282 break;
3283 }
3284 qeth_l3_set_ip_addr_list(card);
3285out:
3286 return NOTIFY_DONE;
3287}
3288
3289static struct notifier_block qeth_l3_ip_notifier = {
3290 qeth_l3_ip_event,
3291 NULL,
3292};
3293
3294#ifdef CONFIG_QETH_IPV6
3295/**
3296 * IPv6 event handler
3297 */
3298static int qeth_l3_ip6_event(struct notifier_block *this,
David S. Miller76fef2b2008-03-22 18:22:42 -07003299 unsigned long event, void *ptr)
Frank Blaschka4a71df52008-02-15 09:19:42 +01003300{
3301 struct inet6_ifaddr *ifa = (struct inet6_ifaddr *)ptr;
3302 struct net_device *dev = (struct net_device *)ifa->idev->dev;
3303 struct qeth_ipaddr *addr;
3304 struct qeth_card *card;
3305
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003306 QETH_DBF_TEXT(TRACE, 3, "ip6event");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003307
3308 card = qeth_l3_get_card_from_dev(dev);
3309 if (!card)
3310 return NOTIFY_DONE;
3311 if (!qeth_is_supported(card, IPA_IPV6))
3312 return NOTIFY_DONE;
3313
3314 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
3315 if (addr != NULL) {
3316 memcpy(&addr->u.a6.addr, &ifa->addr, sizeof(struct in6_addr));
3317 addr->u.a6.pfxlen = ifa->prefix_len;
3318 addr->type = QETH_IP_TYPE_NORMAL;
3319 } else
3320 goto out;
3321
3322 switch (event) {
3323 case NETDEV_UP:
3324 if (!qeth_l3_add_ip(card, addr))
3325 kfree(addr);
3326 break;
3327 case NETDEV_DOWN:
3328 if (!qeth_l3_delete_ip(card, addr))
3329 kfree(addr);
3330 break;
3331 default:
3332 break;
3333 }
3334 qeth_l3_set_ip_addr_list(card);
3335out:
3336 return NOTIFY_DONE;
3337}
3338
3339static struct notifier_block qeth_l3_ip6_notifier = {
3340 qeth_l3_ip6_event,
3341 NULL,
3342};
3343#endif
3344
3345static int qeth_l3_register_notifiers(void)
3346{
3347 int rc;
3348
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003349 QETH_DBF_TEXT(TRACE, 5, "regnotif");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003350 rc = register_inetaddr_notifier(&qeth_l3_ip_notifier);
3351 if (rc)
3352 return rc;
3353#ifdef CONFIG_QETH_IPV6
3354 rc = register_inet6addr_notifier(&qeth_l3_ip6_notifier);
3355 if (rc) {
3356 unregister_inetaddr_notifier(&qeth_l3_ip_notifier);
3357 return rc;
3358 }
3359#else
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003360 pr_warning("There is no IPv6 support for the layer 3 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003361#endif
3362 return 0;
3363}
3364
3365static void qeth_l3_unregister_notifiers(void)
3366{
3367
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003368 QETH_DBF_TEXT(TRACE, 5, "unregnot");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003369 BUG_ON(unregister_inetaddr_notifier(&qeth_l3_ip_notifier));
3370#ifdef CONFIG_QETH_IPV6
3371 BUG_ON(unregister_inet6addr_notifier(&qeth_l3_ip6_notifier));
3372#endif /* QETH_IPV6 */
3373}
3374
3375static int __init qeth_l3_init(void)
3376{
3377 int rc = 0;
3378
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003379 pr_info("register layer 3 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003380 rc = qeth_l3_register_notifiers();
3381 return rc;
3382}
3383
3384static void __exit qeth_l3_exit(void)
3385{
3386 qeth_l3_unregister_notifiers();
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003387 pr_info("unregister layer 3 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003388}
3389
3390module_init(qeth_l3_init);
3391module_exit(qeth_l3_exit);
3392MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
3393MODULE_DESCRIPTION("qeth layer 3 discipline");
3394MODULE_LICENSE("GPL");