blob: 3d04920b9bb99cbc70f6eb1270e61c13bc628cd0 [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
Frank Blaschka4a71df52008-02-15 09:19:42 +010029#include "qeth_l3.h"
30#include "qeth_core_offl.h"
31
Frank Blaschka4a71df52008-02-15 09:19:42 +010032static int qeth_l3_set_offline(struct ccwgroup_device *);
33static int qeth_l3_recover(void *);
34static int qeth_l3_stop(struct net_device *);
35static void qeth_l3_set_multicast_list(struct net_device *);
36static int qeth_l3_neigh_setup(struct net_device *, struct neigh_parms *);
37static int qeth_l3_register_addr_entry(struct qeth_card *,
38 struct qeth_ipaddr *);
39static int qeth_l3_deregister_addr_entry(struct qeth_card *,
40 struct qeth_ipaddr *);
41static int __qeth_l3_set_online(struct ccwgroup_device *, int);
42static int __qeth_l3_set_offline(struct ccwgroup_device *, int);
43
44
45static int qeth_l3_isxdigit(char *buf)
46{
47 while (*buf) {
48 if (!isxdigit(*buf++))
49 return 0;
50 }
51 return 1;
52}
53
54void qeth_l3_ipaddr4_to_string(const __u8 *addr, char *buf)
55{
56 sprintf(buf, "%i.%i.%i.%i", addr[0], addr[1], addr[2], addr[3]);
57}
58
59int qeth_l3_string_to_ipaddr4(const char *buf, __u8 *addr)
60{
61 int count = 0, rc = 0;
62 int in[4];
63 char c;
64
65 rc = sscanf(buf, "%u.%u.%u.%u%c",
66 &in[0], &in[1], &in[2], &in[3], &c);
67 if (rc != 4 && (rc != 5 || c != '\n'))
68 return -EINVAL;
69 for (count = 0; count < 4; count++) {
70 if (in[count] > 255)
71 return -EINVAL;
72 addr[count] = in[count];
73 }
74 return 0;
75}
76
77void qeth_l3_ipaddr6_to_string(const __u8 *addr, char *buf)
78{
79 sprintf(buf, "%02x%02x:%02x%02x:%02x%02x:%02x%02x"
80 ":%02x%02x:%02x%02x:%02x%02x:%02x%02x",
81 addr[0], addr[1], addr[2], addr[3],
82 addr[4], addr[5], addr[6], addr[7],
83 addr[8], addr[9], addr[10], addr[11],
84 addr[12], addr[13], addr[14], addr[15]);
85}
86
87int qeth_l3_string_to_ipaddr6(const char *buf, __u8 *addr)
88{
89 const char *end, *end_tmp, *start;
90 __u16 *in;
91 char num[5];
92 int num2, cnt, out, found, save_cnt;
93 unsigned short in_tmp[8] = {0, };
94
95 cnt = out = found = save_cnt = num2 = 0;
96 end = start = buf;
97 in = (__u16 *) addr;
98 memset(in, 0, 16);
99 while (*end) {
100 end = strchr(start, ':');
101 if (end == NULL) {
102 end = buf + strlen(buf);
103 end_tmp = strchr(start, '\n');
104 if (end_tmp != NULL)
105 end = end_tmp;
106 out = 1;
107 }
108 if ((end - start)) {
109 memset(num, 0, 5);
110 if ((end - start) > 4)
111 return -EINVAL;
112 memcpy(num, start, end - start);
113 if (!qeth_l3_isxdigit(num))
114 return -EINVAL;
115 sscanf(start, "%x", &num2);
116 if (found)
117 in_tmp[save_cnt++] = num2;
118 else
119 in[cnt++] = num2;
120 if (out)
121 break;
122 } else {
123 if (found)
124 return -EINVAL;
125 found = 1;
126 }
127 start = ++end;
128 }
129 if (cnt + save_cnt > 8)
130 return -EINVAL;
131 cnt = 7;
132 while (save_cnt)
133 in[cnt--] = in_tmp[--save_cnt];
134 return 0;
135}
136
137void qeth_l3_ipaddr_to_string(enum qeth_prot_versions proto, const __u8 *addr,
138 char *buf)
139{
140 if (proto == QETH_PROT_IPV4)
141 qeth_l3_ipaddr4_to_string(addr, buf);
142 else if (proto == QETH_PROT_IPV6)
143 qeth_l3_ipaddr6_to_string(addr, buf);
144}
145
146int qeth_l3_string_to_ipaddr(const char *buf, enum qeth_prot_versions proto,
147 __u8 *addr)
148{
149 if (proto == QETH_PROT_IPV4)
150 return qeth_l3_string_to_ipaddr4(buf, addr);
151 else if (proto == QETH_PROT_IPV6)
152 return qeth_l3_string_to_ipaddr6(buf, addr);
153 else
154 return -EINVAL;
155}
156
157static void qeth_l3_convert_addr_to_bits(u8 *addr, u8 *bits, int len)
158{
159 int i, j;
160 u8 octet;
161
162 for (i = 0; i < len; ++i) {
163 octet = addr[i];
164 for (j = 7; j >= 0; --j) {
165 bits[i*8 + j] = octet & 1;
166 octet >>= 1;
167 }
168 }
169}
170
171static int qeth_l3_is_addr_covered_by_ipato(struct qeth_card *card,
172 struct qeth_ipaddr *addr)
173{
174 struct qeth_ipato_entry *ipatoe;
175 u8 addr_bits[128] = {0, };
176 u8 ipatoe_bits[128] = {0, };
177 int rc = 0;
178
179 if (!card->ipato.enabled)
180 return 0;
181
182 qeth_l3_convert_addr_to_bits((u8 *) &addr->u, addr_bits,
183 (addr->proto == QETH_PROT_IPV4)? 4:16);
184 list_for_each_entry(ipatoe, &card->ipato.entries, entry) {
185 if (addr->proto != ipatoe->proto)
186 continue;
187 qeth_l3_convert_addr_to_bits(ipatoe->addr, ipatoe_bits,
188 (ipatoe->proto == QETH_PROT_IPV4) ?
189 4 : 16);
190 if (addr->proto == QETH_PROT_IPV4)
191 rc = !memcmp(addr_bits, ipatoe_bits,
192 min(32, ipatoe->mask_bits));
193 else
194 rc = !memcmp(addr_bits, ipatoe_bits,
195 min(128, ipatoe->mask_bits));
196 if (rc)
197 break;
198 }
199 /* invert? */
200 if ((addr->proto == QETH_PROT_IPV4) && card->ipato.invert4)
201 rc = !rc;
202 else if ((addr->proto == QETH_PROT_IPV6) && card->ipato.invert6)
203 rc = !rc;
204
205 return rc;
206}
207
208/*
209 * Add IP to be added to todo list. If there is already an "add todo"
210 * in this list we just incremenent the reference count.
211 * Returns 0 if we just incremented reference count.
212 */
213static int __qeth_l3_insert_ip_todo(struct qeth_card *card,
214 struct qeth_ipaddr *addr, int add)
215{
216 struct qeth_ipaddr *tmp, *t;
217 int found = 0;
218
219 list_for_each_entry_safe(tmp, t, card->ip_tbd_list, entry) {
220 if ((addr->type == QETH_IP_TYPE_DEL_ALL_MC) &&
221 (tmp->type == QETH_IP_TYPE_DEL_ALL_MC))
222 return 0;
223 if ((tmp->proto == QETH_PROT_IPV4) &&
224 (addr->proto == QETH_PROT_IPV4) &&
225 (tmp->type == addr->type) &&
226 (tmp->is_multicast == addr->is_multicast) &&
227 (tmp->u.a4.addr == addr->u.a4.addr) &&
228 (tmp->u.a4.mask == addr->u.a4.mask)) {
229 found = 1;
230 break;
231 }
232 if ((tmp->proto == QETH_PROT_IPV6) &&
233 (addr->proto == QETH_PROT_IPV6) &&
234 (tmp->type == addr->type) &&
235 (tmp->is_multicast == addr->is_multicast) &&
236 (tmp->u.a6.pfxlen == addr->u.a6.pfxlen) &&
237 (memcmp(&tmp->u.a6.addr, &addr->u.a6.addr,
238 sizeof(struct in6_addr)) == 0)) {
239 found = 1;
240 break;
241 }
242 }
243 if (found) {
244 if (addr->users != 0)
245 tmp->users += addr->users;
246 else
247 tmp->users += add ? 1 : -1;
248 if (tmp->users == 0) {
249 list_del(&tmp->entry);
250 kfree(tmp);
251 }
252 return 0;
253 } else {
254 if (addr->type == QETH_IP_TYPE_DEL_ALL_MC)
255 list_add(&addr->entry, card->ip_tbd_list);
256 else {
257 if (addr->users == 0)
258 addr->users += add ? 1 : -1;
259 if (add && (addr->type == QETH_IP_TYPE_NORMAL) &&
260 qeth_l3_is_addr_covered_by_ipato(card, addr)) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200261 QETH_DBF_TEXT(TRACE, 2, "tkovaddr");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100262 addr->set_flags |= QETH_IPA_SETIP_TAKEOVER_FLAG;
263 }
264 list_add_tail(&addr->entry, card->ip_tbd_list);
265 }
266 return 1;
267 }
268}
269
270static int qeth_l3_delete_ip(struct qeth_card *card, struct qeth_ipaddr *addr)
271{
272 unsigned long flags;
273 int rc = 0;
274
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200275 QETH_DBF_TEXT(TRACE, 4, "delip");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100276
277 if (addr->proto == QETH_PROT_IPV4)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200278 QETH_DBF_HEX(TRACE, 4, &addr->u.a4.addr, 4);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100279 else {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200280 QETH_DBF_HEX(TRACE, 4, &addr->u.a6.addr, 8);
281 QETH_DBF_HEX(TRACE, 4, ((char *)&addr->u.a6.addr) + 8, 8);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100282 }
283 spin_lock_irqsave(&card->ip_lock, flags);
284 rc = __qeth_l3_insert_ip_todo(card, addr, 0);
285 spin_unlock_irqrestore(&card->ip_lock, flags);
286 return rc;
287}
288
289static int qeth_l3_add_ip(struct qeth_card *card, struct qeth_ipaddr *addr)
290{
291 unsigned long flags;
292 int rc = 0;
293
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200294 QETH_DBF_TEXT(TRACE, 4, "addip");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100295 if (addr->proto == QETH_PROT_IPV4)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200296 QETH_DBF_HEX(TRACE, 4, &addr->u.a4.addr, 4);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100297 else {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200298 QETH_DBF_HEX(TRACE, 4, &addr->u.a6.addr, 8);
299 QETH_DBF_HEX(TRACE, 4, ((char *)&addr->u.a6.addr) + 8, 8);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100300 }
301 spin_lock_irqsave(&card->ip_lock, flags);
302 rc = __qeth_l3_insert_ip_todo(card, addr, 1);
303 spin_unlock_irqrestore(&card->ip_lock, flags);
304 return rc;
305}
306
307
308static struct qeth_ipaddr *qeth_l3_get_addr_buffer(
309 enum qeth_prot_versions prot)
310{
311 struct qeth_ipaddr *addr;
312
313 addr = kzalloc(sizeof(struct qeth_ipaddr), GFP_ATOMIC);
314 if (addr == NULL) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100315 return NULL;
316 }
317 addr->type = QETH_IP_TYPE_NORMAL;
318 addr->proto = prot;
319 return addr;
320}
321
322static void qeth_l3_delete_mc_addresses(struct qeth_card *card)
323{
324 struct qeth_ipaddr *iptodo;
325 unsigned long flags;
326
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200327 QETH_DBF_TEXT(TRACE, 4, "delmc");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100328 iptodo = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
329 if (!iptodo) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200330 QETH_DBF_TEXT(TRACE, 2, "dmcnomem");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100331 return;
332 }
333 iptodo->type = QETH_IP_TYPE_DEL_ALL_MC;
334 spin_lock_irqsave(&card->ip_lock, flags);
335 if (!__qeth_l3_insert_ip_todo(card, iptodo, 0))
336 kfree(iptodo);
337 spin_unlock_irqrestore(&card->ip_lock, flags);
338}
339
340/*
341 * Add/remove address to/from card's ip list, i.e. try to add or remove
342 * reference to/from an IP address that is already registered on the card.
343 * Returns:
344 * 0 address was on card and its reference count has been adjusted,
345 * but is still > 0, so nothing has to be done
346 * also returns 0 if card was not on card and the todo was to delete
347 * the address -> there is also nothing to be done
348 * 1 address was not on card and the todo is to add it to the card's ip
349 * list
350 * -1 address was on card and its reference count has been decremented
351 * to <= 0 by the todo -> address must be removed from card
352 */
353static int __qeth_l3_ref_ip_on_card(struct qeth_card *card,
354 struct qeth_ipaddr *todo, struct qeth_ipaddr **__addr)
355{
356 struct qeth_ipaddr *addr;
357 int found = 0;
358
359 list_for_each_entry(addr, &card->ip_list, entry) {
360 if ((addr->proto == QETH_PROT_IPV4) &&
361 (todo->proto == QETH_PROT_IPV4) &&
362 (addr->type == todo->type) &&
363 (addr->u.a4.addr == todo->u.a4.addr) &&
364 (addr->u.a4.mask == todo->u.a4.mask)) {
365 found = 1;
366 break;
367 }
368 if ((addr->proto == QETH_PROT_IPV6) &&
369 (todo->proto == QETH_PROT_IPV6) &&
370 (addr->type == todo->type) &&
371 (addr->u.a6.pfxlen == todo->u.a6.pfxlen) &&
372 (memcmp(&addr->u.a6.addr, &todo->u.a6.addr,
373 sizeof(struct in6_addr)) == 0)) {
374 found = 1;
375 break;
376 }
377 }
378 if (found) {
379 addr->users += todo->users;
380 if (addr->users <= 0) {
381 *__addr = addr;
382 return -1;
383 } else {
384 /* for VIPA and RXIP limit refcount to 1 */
385 if (addr->type != QETH_IP_TYPE_NORMAL)
386 addr->users = 1;
387 return 0;
388 }
389 }
390 if (todo->users > 0) {
391 /* for VIPA and RXIP limit refcount to 1 */
392 if (todo->type != QETH_IP_TYPE_NORMAL)
393 todo->users = 1;
394 return 1;
395 } else
396 return 0;
397}
398
399static void __qeth_l3_delete_all_mc(struct qeth_card *card,
400 unsigned long *flags)
401{
Ursula Braun2d921c32008-04-01 10:26:53 +0200402 struct list_head fail_list;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100403 struct qeth_ipaddr *addr, *tmp;
404 int rc;
Ursula Braun2d921c32008-04-01 10:26:53 +0200405
406 INIT_LIST_HEAD(&fail_list);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100407again:
408 list_for_each_entry_safe(addr, tmp, &card->ip_list, entry) {
409 if (addr->is_multicast) {
410 list_del(&addr->entry);
411 spin_unlock_irqrestore(&card->ip_lock, *flags);
412 rc = qeth_l3_deregister_addr_entry(card, addr);
413 spin_lock_irqsave(&card->ip_lock, *flags);
Ursula Braun2d921c32008-04-01 10:26:53 +0200414 if (!rc || (rc == IPA_RC_MC_ADDR_NOT_FOUND))
Frank Blaschka4a71df52008-02-15 09:19:42 +0100415 kfree(addr);
Ursula Braun2d921c32008-04-01 10:26:53 +0200416 else
417 list_add_tail(&addr->entry, &fail_list);
418 goto again;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100419 }
420 }
Ursula Braun2d921c32008-04-01 10:26:53 +0200421 list_splice(&fail_list, &card->ip_list);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100422}
423
424static void qeth_l3_set_ip_addr_list(struct qeth_card *card)
425{
426 struct list_head *tbd_list;
427 struct qeth_ipaddr *todo, *addr;
428 unsigned long flags;
429 int rc;
430
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200431 QETH_DBF_TEXT(TRACE, 2, "sdiplist");
432 QETH_DBF_HEX(TRACE, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100433
434 spin_lock_irqsave(&card->ip_lock, flags);
435 tbd_list = card->ip_tbd_list;
436 card->ip_tbd_list = kmalloc(sizeof(struct list_head), GFP_ATOMIC);
437 if (!card->ip_tbd_list) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200438 QETH_DBF_TEXT(TRACE, 0, "silnomem");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100439 card->ip_tbd_list = tbd_list;
440 spin_unlock_irqrestore(&card->ip_lock, flags);
441 return;
442 } else
443 INIT_LIST_HEAD(card->ip_tbd_list);
444
445 while (!list_empty(tbd_list)) {
446 todo = list_entry(tbd_list->next, struct qeth_ipaddr, entry);
447 list_del(&todo->entry);
448 if (todo->type == QETH_IP_TYPE_DEL_ALL_MC) {
449 __qeth_l3_delete_all_mc(card, &flags);
450 kfree(todo);
451 continue;
452 }
453 rc = __qeth_l3_ref_ip_on_card(card, todo, &addr);
454 if (rc == 0) {
455 /* nothing to be done; only adjusted refcount */
456 kfree(todo);
457 } else if (rc == 1) {
458 /* new entry to be added to on-card list */
459 spin_unlock_irqrestore(&card->ip_lock, flags);
460 rc = qeth_l3_register_addr_entry(card, todo);
461 spin_lock_irqsave(&card->ip_lock, flags);
Ursula Braun3caa4af2008-04-01 10:27:00 +0200462 if (!rc || (rc == IPA_RC_LAN_OFFLINE))
Frank Blaschka4a71df52008-02-15 09:19:42 +0100463 list_add_tail(&todo->entry, &card->ip_list);
464 else
465 kfree(todo);
466 } else if (rc == -1) {
467 /* on-card entry to be removed */
468 list_del_init(&addr->entry);
469 spin_unlock_irqrestore(&card->ip_lock, flags);
470 rc = qeth_l3_deregister_addr_entry(card, addr);
471 spin_lock_irqsave(&card->ip_lock, flags);
Ursula Braun2d921c32008-04-01 10:26:53 +0200472 if (!rc || (rc == IPA_RC_PRIMARY_ALREADY_DEFINED))
Frank Blaschka4a71df52008-02-15 09:19:42 +0100473 kfree(addr);
474 else
475 list_add_tail(&addr->entry, &card->ip_list);
476 kfree(todo);
477 }
478 }
479 spin_unlock_irqrestore(&card->ip_lock, flags);
480 kfree(tbd_list);
481}
482
483static void qeth_l3_clear_ip_list(struct qeth_card *card, int clean,
484 int recover)
485{
486 struct qeth_ipaddr *addr, *tmp;
487 unsigned long flags;
488
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200489 QETH_DBF_TEXT(TRACE, 4, "clearip");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100490 spin_lock_irqsave(&card->ip_lock, flags);
491 /* clear todo list */
492 list_for_each_entry_safe(addr, tmp, card->ip_tbd_list, entry) {
493 list_del(&addr->entry);
494 kfree(addr);
495 }
496
497 while (!list_empty(&card->ip_list)) {
498 addr = list_entry(card->ip_list.next,
499 struct qeth_ipaddr, entry);
500 list_del_init(&addr->entry);
501 if (clean) {
502 spin_unlock_irqrestore(&card->ip_lock, flags);
503 qeth_l3_deregister_addr_entry(card, addr);
504 spin_lock_irqsave(&card->ip_lock, flags);
505 }
506 if (!recover || addr->is_multicast) {
507 kfree(addr);
508 continue;
509 }
510 list_add_tail(&addr->entry, card->ip_tbd_list);
511 }
512 spin_unlock_irqrestore(&card->ip_lock, flags);
513}
514
515static int qeth_l3_address_exists_in_list(struct list_head *list,
516 struct qeth_ipaddr *addr, int same_type)
517{
518 struct qeth_ipaddr *tmp;
519
520 list_for_each_entry(tmp, list, entry) {
521 if ((tmp->proto == QETH_PROT_IPV4) &&
522 (addr->proto == QETH_PROT_IPV4) &&
523 ((same_type && (tmp->type == addr->type)) ||
524 (!same_type && (tmp->type != addr->type))) &&
525 (tmp->u.a4.addr == addr->u.a4.addr))
526 return 1;
527
528 if ((tmp->proto == QETH_PROT_IPV6) &&
529 (addr->proto == QETH_PROT_IPV6) &&
530 ((same_type && (tmp->type == addr->type)) ||
531 (!same_type && (tmp->type != addr->type))) &&
532 (memcmp(&tmp->u.a6.addr, &addr->u.a6.addr,
533 sizeof(struct in6_addr)) == 0))
534 return 1;
535
536 }
537 return 0;
538}
539
540static int qeth_l3_send_setdelmc(struct qeth_card *card,
541 struct qeth_ipaddr *addr, int ipacmd)
542{
543 int rc;
544 struct qeth_cmd_buffer *iob;
545 struct qeth_ipa_cmd *cmd;
546
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200547 QETH_DBF_TEXT(TRACE, 4, "setdelmc");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100548
549 iob = qeth_get_ipacmd_buffer(card, ipacmd, addr->proto);
550 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
551 memcpy(&cmd->data.setdelipm.mac, addr->mac, OSA_ADDR_LEN);
552 if (addr->proto == QETH_PROT_IPV6)
553 memcpy(cmd->data.setdelipm.ip6, &addr->u.a6.addr,
554 sizeof(struct in6_addr));
555 else
556 memcpy(&cmd->data.setdelipm.ip4, &addr->u.a4.addr, 4);
557
558 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
559
560 return rc;
561}
562
563static void qeth_l3_fill_netmask(u8 *netmask, unsigned int len)
564{
565 int i, j;
566 for (i = 0; i < 16; i++) {
567 j = (len) - (i * 8);
568 if (j >= 8)
569 netmask[i] = 0xff;
570 else if (j > 0)
571 netmask[i] = (u8)(0xFF00 >> j);
572 else
573 netmask[i] = 0;
574 }
575}
576
577static int qeth_l3_send_setdelip(struct qeth_card *card,
578 struct qeth_ipaddr *addr, int ipacmd, unsigned int flags)
579{
580 int rc;
581 struct qeth_cmd_buffer *iob;
582 struct qeth_ipa_cmd *cmd;
583 __u8 netmask[16];
584
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200585 QETH_DBF_TEXT(TRACE, 4, "setdelip");
586 QETH_DBF_TEXT_(TRACE, 4, "flags%02X", flags);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100587
588 iob = qeth_get_ipacmd_buffer(card, ipacmd, addr->proto);
589 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
590 if (addr->proto == QETH_PROT_IPV6) {
591 memcpy(cmd->data.setdelip6.ip_addr, &addr->u.a6.addr,
592 sizeof(struct in6_addr));
593 qeth_l3_fill_netmask(netmask, addr->u.a6.pfxlen);
594 memcpy(cmd->data.setdelip6.mask, netmask,
595 sizeof(struct in6_addr));
596 cmd->data.setdelip6.flags = flags;
597 } else {
598 memcpy(cmd->data.setdelip4.ip_addr, &addr->u.a4.addr, 4);
599 memcpy(cmd->data.setdelip4.mask, &addr->u.a4.mask, 4);
600 cmd->data.setdelip4.flags = flags;
601 }
602
603 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
604
605 return rc;
606}
607
608static int qeth_l3_send_setrouting(struct qeth_card *card,
609 enum qeth_routing_types type, enum qeth_prot_versions prot)
610{
611 int rc;
612 struct qeth_ipa_cmd *cmd;
613 struct qeth_cmd_buffer *iob;
614
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200615 QETH_DBF_TEXT(TRACE, 4, "setroutg");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100616 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SETRTG, prot);
617 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
618 cmd->data.setrtg.type = (type);
619 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
620
621 return rc;
622}
623
624static void qeth_l3_correct_routing_type(struct qeth_card *card,
625 enum qeth_routing_types *type, enum qeth_prot_versions prot)
626{
627 if (card->info.type == QETH_CARD_TYPE_IQD) {
628 switch (*type) {
629 case NO_ROUTER:
630 case PRIMARY_CONNECTOR:
631 case SECONDARY_CONNECTOR:
632 case MULTICAST_ROUTER:
633 return;
634 default:
635 goto out_inval;
636 }
637 } else {
638 switch (*type) {
639 case NO_ROUTER:
640 case PRIMARY_ROUTER:
641 case SECONDARY_ROUTER:
642 return;
643 case MULTICAST_ROUTER:
644 if (qeth_is_ipafunc_supported(card, prot,
645 IPA_OSA_MC_ROUTER))
646 return;
647 default:
648 goto out_inval;
649 }
650 }
651out_inval:
Frank Blaschka4a71df52008-02-15 09:19:42 +0100652 *type = NO_ROUTER;
653}
654
655int qeth_l3_setrouting_v4(struct qeth_card *card)
656{
657 int rc;
658
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200659 QETH_DBF_TEXT(TRACE, 3, "setrtg4");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100660
661 qeth_l3_correct_routing_type(card, &card->options.route4.type,
662 QETH_PROT_IPV4);
663
664 rc = qeth_l3_send_setrouting(card, card->options.route4.type,
665 QETH_PROT_IPV4);
666 if (rc) {
667 card->options.route4.type = NO_ROUTER;
Frank Blaschka14cc21b2008-06-06 12:37:46 +0200668 QETH_DBF_MESSAGE(2, "Error (0x%04x) while setting routing type"
669 " on %s. Type set to 'no router'.\n", rc,
670 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100671 }
672 return rc;
673}
674
675int qeth_l3_setrouting_v6(struct qeth_card *card)
676{
677 int rc = 0;
678
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200679 QETH_DBF_TEXT(TRACE, 3, "setrtg6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100680#ifdef CONFIG_QETH_IPV6
681
682 if (!qeth_is_supported(card, IPA_IPV6))
683 return 0;
684 qeth_l3_correct_routing_type(card, &card->options.route6.type,
685 QETH_PROT_IPV6);
686
687 rc = qeth_l3_send_setrouting(card, card->options.route6.type,
688 QETH_PROT_IPV6);
689 if (rc) {
690 card->options.route6.type = NO_ROUTER;
Frank Blaschka14cc21b2008-06-06 12:37:46 +0200691 QETH_DBF_MESSAGE(2, "Error (0x%04x) while setting routing type"
692 " on %s. Type set to 'no router'.\n", rc,
693 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100694 }
695#endif
696 return rc;
697}
698
699/*
700 * IP address takeover related functions
701 */
702static void qeth_l3_clear_ipato_list(struct qeth_card *card)
703{
704
705 struct qeth_ipato_entry *ipatoe, *tmp;
706 unsigned long flags;
707
708 spin_lock_irqsave(&card->ip_lock, flags);
709 list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry) {
710 list_del(&ipatoe->entry);
711 kfree(ipatoe);
712 }
713 spin_unlock_irqrestore(&card->ip_lock, flags);
714}
715
716int qeth_l3_add_ipato_entry(struct qeth_card *card,
717 struct qeth_ipato_entry *new)
718{
719 struct qeth_ipato_entry *ipatoe;
720 unsigned long flags;
721 int rc = 0;
722
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200723 QETH_DBF_TEXT(TRACE, 2, "addipato");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100724 spin_lock_irqsave(&card->ip_lock, flags);
725 list_for_each_entry(ipatoe, &card->ipato.entries, entry) {
726 if (ipatoe->proto != new->proto)
727 continue;
728 if (!memcmp(ipatoe->addr, new->addr,
729 (ipatoe->proto == QETH_PROT_IPV4)? 4:16) &&
730 (ipatoe->mask_bits == new->mask_bits)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100731 rc = -EEXIST;
732 break;
733 }
734 }
735 if (!rc)
736 list_add_tail(&new->entry, &card->ipato.entries);
737
738 spin_unlock_irqrestore(&card->ip_lock, flags);
739 return rc;
740}
741
742void qeth_l3_del_ipato_entry(struct qeth_card *card,
743 enum qeth_prot_versions proto, u8 *addr, int mask_bits)
744{
745 struct qeth_ipato_entry *ipatoe, *tmp;
746 unsigned long flags;
747
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200748 QETH_DBF_TEXT(TRACE, 2, "delipato");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100749 spin_lock_irqsave(&card->ip_lock, flags);
750 list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry) {
751 if (ipatoe->proto != proto)
752 continue;
753 if (!memcmp(ipatoe->addr, addr,
754 (proto == QETH_PROT_IPV4)? 4:16) &&
755 (ipatoe->mask_bits == mask_bits)) {
756 list_del(&ipatoe->entry);
757 kfree(ipatoe);
758 }
759 }
760 spin_unlock_irqrestore(&card->ip_lock, flags);
761}
762
763/*
764 * VIPA related functions
765 */
766int qeth_l3_add_vipa(struct qeth_card *card, enum qeth_prot_versions proto,
767 const u8 *addr)
768{
769 struct qeth_ipaddr *ipaddr;
770 unsigned long flags;
771 int rc = 0;
772
773 ipaddr = qeth_l3_get_addr_buffer(proto);
774 if (ipaddr) {
775 if (proto == QETH_PROT_IPV4) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200776 QETH_DBF_TEXT(TRACE, 2, "addvipa4");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100777 memcpy(&ipaddr->u.a4.addr, addr, 4);
778 ipaddr->u.a4.mask = 0;
779 } else if (proto == QETH_PROT_IPV6) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200780 QETH_DBF_TEXT(TRACE, 2, "addvipa6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100781 memcpy(&ipaddr->u.a6.addr, addr, 16);
782 ipaddr->u.a6.pfxlen = 0;
783 }
784 ipaddr->type = QETH_IP_TYPE_VIPA;
785 ipaddr->set_flags = QETH_IPA_SETIP_VIPA_FLAG;
786 ipaddr->del_flags = QETH_IPA_DELIP_VIPA_FLAG;
787 } else
788 return -ENOMEM;
789 spin_lock_irqsave(&card->ip_lock, flags);
790 if (qeth_l3_address_exists_in_list(&card->ip_list, ipaddr, 0) ||
791 qeth_l3_address_exists_in_list(card->ip_tbd_list, ipaddr, 0))
792 rc = -EEXIST;
793 spin_unlock_irqrestore(&card->ip_lock, flags);
794 if (rc) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100795 return rc;
796 }
797 if (!qeth_l3_add_ip(card, ipaddr))
798 kfree(ipaddr);
799 qeth_l3_set_ip_addr_list(card);
800 return rc;
801}
802
803void qeth_l3_del_vipa(struct qeth_card *card, enum qeth_prot_versions proto,
804 const u8 *addr)
805{
806 struct qeth_ipaddr *ipaddr;
807
808 ipaddr = qeth_l3_get_addr_buffer(proto);
809 if (ipaddr) {
810 if (proto == QETH_PROT_IPV4) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200811 QETH_DBF_TEXT(TRACE, 2, "delvipa4");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100812 memcpy(&ipaddr->u.a4.addr, addr, 4);
813 ipaddr->u.a4.mask = 0;
814 } else if (proto == QETH_PROT_IPV6) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200815 QETH_DBF_TEXT(TRACE, 2, "delvipa6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100816 memcpy(&ipaddr->u.a6.addr, addr, 16);
817 ipaddr->u.a6.pfxlen = 0;
818 }
819 ipaddr->type = QETH_IP_TYPE_VIPA;
820 } else
821 return;
822 if (!qeth_l3_delete_ip(card, ipaddr))
823 kfree(ipaddr);
824 qeth_l3_set_ip_addr_list(card);
825}
826
827/*
828 * proxy ARP related functions
829 */
830int qeth_l3_add_rxip(struct qeth_card *card, enum qeth_prot_versions proto,
831 const u8 *addr)
832{
833 struct qeth_ipaddr *ipaddr;
834 unsigned long flags;
835 int rc = 0;
836
837 ipaddr = qeth_l3_get_addr_buffer(proto);
838 if (ipaddr) {
839 if (proto == QETH_PROT_IPV4) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200840 QETH_DBF_TEXT(TRACE, 2, "addrxip4");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100841 memcpy(&ipaddr->u.a4.addr, addr, 4);
842 ipaddr->u.a4.mask = 0;
843 } else if (proto == QETH_PROT_IPV6) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200844 QETH_DBF_TEXT(TRACE, 2, "addrxip6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100845 memcpy(&ipaddr->u.a6.addr, addr, 16);
846 ipaddr->u.a6.pfxlen = 0;
847 }
848 ipaddr->type = QETH_IP_TYPE_RXIP;
849 ipaddr->set_flags = QETH_IPA_SETIP_TAKEOVER_FLAG;
850 ipaddr->del_flags = 0;
851 } else
852 return -ENOMEM;
853 spin_lock_irqsave(&card->ip_lock, flags);
854 if (qeth_l3_address_exists_in_list(&card->ip_list, ipaddr, 0) ||
855 qeth_l3_address_exists_in_list(card->ip_tbd_list, ipaddr, 0))
856 rc = -EEXIST;
857 spin_unlock_irqrestore(&card->ip_lock, flags);
858 if (rc) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100859 return rc;
860 }
861 if (!qeth_l3_add_ip(card, ipaddr))
862 kfree(ipaddr);
863 qeth_l3_set_ip_addr_list(card);
864 return 0;
865}
866
867void qeth_l3_del_rxip(struct qeth_card *card, enum qeth_prot_versions proto,
868 const u8 *addr)
869{
870 struct qeth_ipaddr *ipaddr;
871
872 ipaddr = qeth_l3_get_addr_buffer(proto);
873 if (ipaddr) {
874 if (proto == QETH_PROT_IPV4) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200875 QETH_DBF_TEXT(TRACE, 2, "addrxip4");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100876 memcpy(&ipaddr->u.a4.addr, addr, 4);
877 ipaddr->u.a4.mask = 0;
878 } else if (proto == QETH_PROT_IPV6) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200879 QETH_DBF_TEXT(TRACE, 2, "addrxip6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100880 memcpy(&ipaddr->u.a6.addr, addr, 16);
881 ipaddr->u.a6.pfxlen = 0;
882 }
883 ipaddr->type = QETH_IP_TYPE_RXIP;
884 } else
885 return;
886 if (!qeth_l3_delete_ip(card, ipaddr))
887 kfree(ipaddr);
888 qeth_l3_set_ip_addr_list(card);
889}
890
891static int qeth_l3_register_addr_entry(struct qeth_card *card,
892 struct qeth_ipaddr *addr)
893{
894 char buf[50];
895 int rc = 0;
896 int cnt = 3;
897
898 if (addr->proto == QETH_PROT_IPV4) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200899 QETH_DBF_TEXT(TRACE, 2, "setaddr4");
900 QETH_DBF_HEX(TRACE, 3, &addr->u.a4.addr, sizeof(int));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100901 } else if (addr->proto == QETH_PROT_IPV6) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200902 QETH_DBF_TEXT(TRACE, 2, "setaddr6");
903 QETH_DBF_HEX(TRACE, 3, &addr->u.a6.addr, 8);
904 QETH_DBF_HEX(TRACE, 3, ((char *)&addr->u.a6.addr) + 8, 8);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100905 } else {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200906 QETH_DBF_TEXT(TRACE, 2, "setaddr?");
907 QETH_DBF_HEX(TRACE, 3, addr, sizeof(struct qeth_ipaddr));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100908 }
909 do {
910 if (addr->is_multicast)
911 rc = qeth_l3_send_setdelmc(card, addr, IPA_CMD_SETIPM);
912 else
913 rc = qeth_l3_send_setdelip(card, addr, IPA_CMD_SETIP,
914 addr->set_flags);
915 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200916 QETH_DBF_TEXT(TRACE, 2, "failed");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100917 } while ((--cnt > 0) && rc);
918 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200919 QETH_DBF_TEXT(TRACE, 2, "FAILED");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100920 qeth_l3_ipaddr_to_string(addr->proto, (u8 *)&addr->u, buf);
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100921 dev_warn(&card->gdev->dev,
922 "Registering IP address %s failed\n", buf);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100923 }
924 return rc;
925}
926
927static int qeth_l3_deregister_addr_entry(struct qeth_card *card,
928 struct qeth_ipaddr *addr)
929{
930 int rc = 0;
931
932 if (addr->proto == QETH_PROT_IPV4) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200933 QETH_DBF_TEXT(TRACE, 2, "deladdr4");
934 QETH_DBF_HEX(TRACE, 3, &addr->u.a4.addr, sizeof(int));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100935 } else if (addr->proto == QETH_PROT_IPV6) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200936 QETH_DBF_TEXT(TRACE, 2, "deladdr6");
937 QETH_DBF_HEX(TRACE, 3, &addr->u.a6.addr, 8);
938 QETH_DBF_HEX(TRACE, 3, ((char *)&addr->u.a6.addr) + 8, 8);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100939 } else {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200940 QETH_DBF_TEXT(TRACE, 2, "deladdr?");
941 QETH_DBF_HEX(TRACE, 3, addr, sizeof(struct qeth_ipaddr));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100942 }
943 if (addr->is_multicast)
944 rc = qeth_l3_send_setdelmc(card, addr, IPA_CMD_DELIPM);
945 else
946 rc = qeth_l3_send_setdelip(card, addr, IPA_CMD_DELIP,
947 addr->del_flags);
Frank Blaschkac4cef072008-07-14 09:59:31 +0200948 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200949 QETH_DBF_TEXT(TRACE, 2, "failed");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100950
951 return rc;
952}
953
954static inline u8 qeth_l3_get_qeth_hdr_flags4(int cast_type)
955{
956 if (cast_type == RTN_MULTICAST)
957 return QETH_CAST_MULTICAST;
958 if (cast_type == RTN_BROADCAST)
959 return QETH_CAST_BROADCAST;
960 return QETH_CAST_UNICAST;
961}
962
963static inline u8 qeth_l3_get_qeth_hdr_flags6(int cast_type)
964{
965 u8 ct = QETH_HDR_PASSTHRU | QETH_HDR_IPV6;
966 if (cast_type == RTN_MULTICAST)
967 return ct | QETH_CAST_MULTICAST;
968 if (cast_type == RTN_ANYCAST)
969 return ct | QETH_CAST_ANYCAST;
970 if (cast_type == RTN_BROADCAST)
971 return ct | QETH_CAST_BROADCAST;
972 return ct | QETH_CAST_UNICAST;
973}
974
975static int qeth_l3_send_setadp_mode(struct qeth_card *card, __u32 command,
976 __u32 mode)
977{
978 int rc;
979 struct qeth_cmd_buffer *iob;
980 struct qeth_ipa_cmd *cmd;
981
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200982 QETH_DBF_TEXT(TRACE, 4, "adpmode");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100983
984 iob = qeth_get_adapter_cmd(card, command,
985 sizeof(struct qeth_ipacmd_setadpparms));
986 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
987 cmd->data.setadapterparms.data.mode = mode;
988 rc = qeth_send_ipa_cmd(card, iob, qeth_default_setadapterparms_cb,
989 NULL);
990 return rc;
991}
992
993static int qeth_l3_setadapter_hstr(struct qeth_card *card)
994{
995 int rc;
996
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200997 QETH_DBF_TEXT(TRACE, 4, "adphstr");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100998
999 if (qeth_adp_supported(card, IPA_SETADP_SET_BROADCAST_MODE)) {
1000 rc = qeth_l3_send_setadp_mode(card,
1001 IPA_SETADP_SET_BROADCAST_MODE,
1002 card->options.broadcast_mode);
1003 if (rc)
Frank Blaschka14cc21b2008-06-06 12:37:46 +02001004 QETH_DBF_MESSAGE(2, "couldn't set broadcast mode on "
Frank Blaschka4a71df52008-02-15 09:19:42 +01001005 "device %s: x%x\n",
1006 CARD_BUS_ID(card), rc);
1007 rc = qeth_l3_send_setadp_mode(card,
1008 IPA_SETADP_ALTER_MAC_ADDRESS,
1009 card->options.macaddr_mode);
1010 if (rc)
Frank Blaschka14cc21b2008-06-06 12:37:46 +02001011 QETH_DBF_MESSAGE(2, "couldn't set macaddr mode on "
Frank Blaschka4a71df52008-02-15 09:19:42 +01001012 "device %s: x%x\n", CARD_BUS_ID(card), rc);
1013 return rc;
1014 }
1015 if (card->options.broadcast_mode == QETH_TR_BROADCAST_LOCAL)
Frank Blaschka14cc21b2008-06-06 12:37:46 +02001016 QETH_DBF_MESSAGE(2, "set adapter parameters not available "
Frank Blaschka4a71df52008-02-15 09:19:42 +01001017 "to set broadcast mode, using ALLRINGS "
1018 "on device %s:\n", CARD_BUS_ID(card));
1019 if (card->options.macaddr_mode == QETH_TR_MACADDR_CANONICAL)
Frank Blaschka14cc21b2008-06-06 12:37:46 +02001020 QETH_DBF_MESSAGE(2, "set adapter parameters not available "
Frank Blaschka4a71df52008-02-15 09:19:42 +01001021 "to set macaddr mode, using NONCANONICAL "
1022 "on device %s:\n", CARD_BUS_ID(card));
1023 return 0;
1024}
1025
1026static int qeth_l3_setadapter_parms(struct qeth_card *card)
1027{
1028 int rc;
1029
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001030 QETH_DBF_TEXT(SETUP, 2, "setadprm");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001031
1032 if (!qeth_is_supported(card, IPA_SETADAPTERPARMS)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001033 dev_info(&card->gdev->dev,
1034 "set adapter parameters not supported.\n");
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001035 QETH_DBF_TEXT(SETUP, 2, " notsupp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001036 return 0;
1037 }
1038 rc = qeth_query_setadapterparms(card);
1039 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001040 QETH_DBF_MESSAGE(2, "%s couldn't set adapter parameters: "
1041 "0x%x\n", card->gdev->dev.bus_id, rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001042 return rc;
1043 }
1044 if (qeth_adp_supported(card, IPA_SETADP_ALTER_MAC_ADDRESS)) {
1045 rc = qeth_setadpparms_change_macaddr(card);
1046 if (rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001047 dev_warn(&card->gdev->dev, "Reading the adapter MAC"
Heiko Carstens6ea2fde2009-01-04 17:36:32 -08001048 " address failed\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001049 }
1050
1051 if ((card->info.link_type == QETH_LINK_TYPE_HSTR) ||
1052 (card->info.link_type == QETH_LINK_TYPE_LANE_TR))
1053 rc = qeth_l3_setadapter_hstr(card);
1054
1055 return rc;
1056}
1057
1058static int qeth_l3_default_setassparms_cb(struct qeth_card *card,
1059 struct qeth_reply *reply, unsigned long data)
1060{
1061 struct qeth_ipa_cmd *cmd;
1062
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001063 QETH_DBF_TEXT(TRACE, 4, "defadpcb");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001064
1065 cmd = (struct qeth_ipa_cmd *) data;
1066 if (cmd->hdr.return_code == 0) {
1067 cmd->hdr.return_code = cmd->data.setassparms.hdr.return_code;
1068 if (cmd->hdr.prot_version == QETH_PROT_IPV4)
1069 card->options.ipa4.enabled_funcs = cmd->hdr.ipa_enabled;
1070 if (cmd->hdr.prot_version == QETH_PROT_IPV6)
1071 card->options.ipa6.enabled_funcs = cmd->hdr.ipa_enabled;
1072 }
1073 if (cmd->data.setassparms.hdr.assist_no == IPA_INBOUND_CHECKSUM &&
1074 cmd->data.setassparms.hdr.command_code == IPA_CMD_ASS_START) {
1075 card->info.csum_mask = cmd->data.setassparms.data.flags_32bit;
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001076 QETH_DBF_TEXT_(TRACE, 3, "csum:%d", card->info.csum_mask);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001077 }
1078 return 0;
1079}
1080
1081static struct qeth_cmd_buffer *qeth_l3_get_setassparms_cmd(
1082 struct qeth_card *card, enum qeth_ipa_funcs ipa_func, __u16 cmd_code,
1083 __u16 len, enum qeth_prot_versions prot)
1084{
1085 struct qeth_cmd_buffer *iob;
1086 struct qeth_ipa_cmd *cmd;
1087
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001088 QETH_DBF_TEXT(TRACE, 4, "getasscm");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001089 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SETASSPARMS, prot);
1090
1091 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1092 cmd->data.setassparms.hdr.assist_no = ipa_func;
1093 cmd->data.setassparms.hdr.length = 8 + len;
1094 cmd->data.setassparms.hdr.command_code = cmd_code;
1095 cmd->data.setassparms.hdr.return_code = 0;
1096 cmd->data.setassparms.hdr.seq_no = 0;
1097
1098 return iob;
1099}
1100
1101static int qeth_l3_send_setassparms(struct qeth_card *card,
1102 struct qeth_cmd_buffer *iob, __u16 len, long data,
1103 int (*reply_cb)(struct qeth_card *, struct qeth_reply *,
1104 unsigned long),
1105 void *reply_param)
1106{
1107 int rc;
1108 struct qeth_ipa_cmd *cmd;
1109
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001110 QETH_DBF_TEXT(TRACE, 4, "sendassp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001111
1112 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1113 if (len <= sizeof(__u32))
1114 cmd->data.setassparms.data.flags_32bit = (__u32) data;
1115 else /* (len > sizeof(__u32)) */
1116 memcpy(&cmd->data.setassparms.data, (void *) data, len);
1117
1118 rc = qeth_send_ipa_cmd(card, iob, reply_cb, reply_param);
1119 return rc;
1120}
1121
1122#ifdef CONFIG_QETH_IPV6
1123static int qeth_l3_send_simple_setassparms_ipv6(struct qeth_card *card,
1124 enum qeth_ipa_funcs ipa_func, __u16 cmd_code)
1125{
1126 int rc;
1127 struct qeth_cmd_buffer *iob;
1128
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001129 QETH_DBF_TEXT(TRACE, 4, "simassp6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001130 iob = qeth_l3_get_setassparms_cmd(card, ipa_func, cmd_code,
1131 0, QETH_PROT_IPV6);
1132 rc = qeth_l3_send_setassparms(card, iob, 0, 0,
1133 qeth_l3_default_setassparms_cb, NULL);
1134 return rc;
1135}
1136#endif
1137
1138static int qeth_l3_send_simple_setassparms(struct qeth_card *card,
1139 enum qeth_ipa_funcs ipa_func, __u16 cmd_code, long data)
1140{
1141 int rc;
1142 int length = 0;
1143 struct qeth_cmd_buffer *iob;
1144
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001145 QETH_DBF_TEXT(TRACE, 4, "simassp4");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001146 if (data)
1147 length = sizeof(__u32);
1148 iob = qeth_l3_get_setassparms_cmd(card, ipa_func, cmd_code,
1149 length, QETH_PROT_IPV4);
1150 rc = qeth_l3_send_setassparms(card, iob, length, data,
1151 qeth_l3_default_setassparms_cb, NULL);
1152 return rc;
1153}
1154
1155static int qeth_l3_start_ipa_arp_processing(struct qeth_card *card)
1156{
1157 int rc;
1158
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001159 QETH_DBF_TEXT(TRACE, 3, "ipaarp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001160
1161 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001162 dev_info(&card->gdev->dev,
1163 "ARP processing not supported on %s!\n",
1164 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001165 return 0;
1166 }
1167 rc = qeth_l3_send_simple_setassparms(card, IPA_ARP_PROCESSING,
1168 IPA_CMD_ASS_START, 0);
1169 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001170 dev_warn(&card->gdev->dev,
1171 "Starting ARP processing support for %s failed\n",
1172 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001173 }
1174 return rc;
1175}
1176
1177static int qeth_l3_start_ipa_ip_fragmentation(struct qeth_card *card)
1178{
1179 int rc;
1180
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001181 QETH_DBF_TEXT(TRACE, 3, "ipaipfrg");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001182
1183 if (!qeth_is_supported(card, IPA_IP_FRAGMENTATION)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001184 dev_info(&card->gdev->dev,
1185 "Hardware IP fragmentation not supported on %s\n",
1186 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001187 return -EOPNOTSUPP;
1188 }
1189
1190 rc = qeth_l3_send_simple_setassparms(card, IPA_IP_FRAGMENTATION,
1191 IPA_CMD_ASS_START, 0);
1192 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001193 dev_warn(&card->gdev->dev,
1194 "Starting IP fragmentation support for %s failed\n",
1195 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001196 } else
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001197 dev_info(&card->gdev->dev,
1198 "Hardware IP fragmentation enabled \n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001199 return rc;
1200}
1201
1202static int qeth_l3_start_ipa_source_mac(struct qeth_card *card)
1203{
1204 int rc;
1205
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001206 QETH_DBF_TEXT(TRACE, 3, "stsrcmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001207
Frank Blaschka4a71df52008-02-15 09:19:42 +01001208 if (!qeth_is_supported(card, IPA_SOURCE_MAC)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001209 dev_info(&card->gdev->dev,
Ursula Braunfe94e2e2009-01-04 17:34:52 -08001210 "Inbound source MAC-address not supported on %s\n",
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001211 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001212 return -EOPNOTSUPP;
1213 }
1214
1215 rc = qeth_l3_send_simple_setassparms(card, IPA_SOURCE_MAC,
1216 IPA_CMD_ASS_START, 0);
1217 if (rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001218 dev_warn(&card->gdev->dev,
Ursula Braunfe94e2e2009-01-04 17:34:52 -08001219 "Starting source MAC-address support for %s failed\n",
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001220 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001221 return rc;
1222}
1223
1224static int qeth_l3_start_ipa_vlan(struct qeth_card *card)
1225{
1226 int rc = 0;
1227
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001228 QETH_DBF_TEXT(TRACE, 3, "strtvlan");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001229
1230 if (!qeth_is_supported(card, IPA_FULL_VLAN)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001231 dev_info(&card->gdev->dev,
1232 "VLAN not supported on %s\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001233 return -EOPNOTSUPP;
1234 }
1235
1236 rc = qeth_l3_send_simple_setassparms(card, IPA_VLAN_PRIO,
1237 IPA_CMD_ASS_START, 0);
1238 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001239 dev_warn(&card->gdev->dev,
1240 "Starting VLAN support for %s failed\n",
1241 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001242 } else {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001243 dev_info(&card->gdev->dev, "VLAN enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001244 }
1245 return rc;
1246}
1247
1248static int qeth_l3_start_ipa_multicast(struct qeth_card *card)
1249{
1250 int rc;
1251
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001252 QETH_DBF_TEXT(TRACE, 3, "stmcast");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001253
1254 if (!qeth_is_supported(card, IPA_MULTICASTING)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001255 dev_info(&card->gdev->dev,
1256 "Multicast not supported on %s\n",
1257 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001258 return -EOPNOTSUPP;
1259 }
1260
1261 rc = qeth_l3_send_simple_setassparms(card, IPA_MULTICASTING,
1262 IPA_CMD_ASS_START, 0);
1263 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001264 dev_warn(&card->gdev->dev,
1265 "Starting multicast support for %s failed\n",
1266 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001267 } else {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001268 dev_info(&card->gdev->dev, "Multicast enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001269 card->dev->flags |= IFF_MULTICAST;
1270 }
1271 return rc;
1272}
1273
1274static int qeth_l3_query_ipassists_cb(struct qeth_card *card,
1275 struct qeth_reply *reply, unsigned long data)
1276{
1277 struct qeth_ipa_cmd *cmd;
1278
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001279 QETH_DBF_TEXT(SETUP, 2, "qipasscb");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001280
1281 cmd = (struct qeth_ipa_cmd *) data;
1282 if (cmd->hdr.prot_version == QETH_PROT_IPV4) {
1283 card->options.ipa4.supported_funcs = cmd->hdr.ipa_supported;
1284 card->options.ipa4.enabled_funcs = cmd->hdr.ipa_enabled;
1285 } else {
1286 card->options.ipa6.supported_funcs = cmd->hdr.ipa_supported;
1287 card->options.ipa6.enabled_funcs = cmd->hdr.ipa_enabled;
1288 }
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001289 QETH_DBF_TEXT(SETUP, 2, "suppenbl");
1290 QETH_DBF_TEXT_(SETUP, 2, "%x", cmd->hdr.ipa_supported);
1291 QETH_DBF_TEXT_(SETUP, 2, "%x", cmd->hdr.ipa_enabled);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001292 return 0;
1293}
1294
1295static int qeth_l3_query_ipassists(struct qeth_card *card,
1296 enum qeth_prot_versions prot)
1297{
1298 int rc;
1299 struct qeth_cmd_buffer *iob;
1300
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001301 QETH_DBF_TEXT_(SETUP, 2, "qipassi%i", prot);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001302 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_QIPASSIST, prot);
1303 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_query_ipassists_cb, NULL);
1304 return rc;
1305}
1306
1307#ifdef CONFIG_QETH_IPV6
1308static int qeth_l3_softsetup_ipv6(struct qeth_card *card)
1309{
1310 int rc;
1311
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001312 QETH_DBF_TEXT(TRACE, 3, "softipv6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001313
1314 if (card->info.type == QETH_CARD_TYPE_IQD)
1315 goto out;
1316
1317 rc = qeth_l3_query_ipassists(card, QETH_PROT_IPV6);
1318 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001319 dev_err(&card->gdev->dev,
1320 "Activating IPv6 support for %s failed\n",
1321 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001322 return rc;
1323 }
1324 rc = qeth_l3_send_simple_setassparms(card, IPA_IPV6,
1325 IPA_CMD_ASS_START, 3);
1326 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001327 dev_err(&card->gdev->dev,
1328 "Activating IPv6 support for %s failed\n",
1329 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001330 return rc;
1331 }
1332 rc = qeth_l3_send_simple_setassparms_ipv6(card, IPA_IPV6,
1333 IPA_CMD_ASS_START);
1334 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001335 dev_err(&card->gdev->dev,
1336 "Activating IPv6 support for %s failed\n",
1337 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001338 return rc;
1339 }
1340 rc = qeth_l3_send_simple_setassparms_ipv6(card, IPA_PASSTHRU,
1341 IPA_CMD_ASS_START);
1342 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001343 dev_warn(&card->gdev->dev,
1344 "Enabling the passthrough mode for %s failed\n",
1345 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001346 return rc;
1347 }
1348out:
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001349 dev_info(&card->gdev->dev, "IPV6 enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001350 return 0;
1351}
1352#endif
1353
1354static int qeth_l3_start_ipa_ipv6(struct qeth_card *card)
1355{
1356 int rc = 0;
1357
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001358 QETH_DBF_TEXT(TRACE, 3, "strtipv6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001359
1360 if (!qeth_is_supported(card, IPA_IPV6)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001361 dev_info(&card->gdev->dev,
1362 "IPv6 not supported on %s\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001363 return 0;
1364 }
1365#ifdef CONFIG_QETH_IPV6
1366 rc = qeth_l3_softsetup_ipv6(card);
1367#endif
1368 return rc ;
1369}
1370
1371static int qeth_l3_start_ipa_broadcast(struct qeth_card *card)
1372{
1373 int rc;
1374
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001375 QETH_DBF_TEXT(TRACE, 3, "stbrdcst");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001376 card->info.broadcast_capable = 0;
1377 if (!qeth_is_supported(card, IPA_FILTERING)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001378 dev_info(&card->gdev->dev,
1379 "Broadcast not supported on %s\n",
1380 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001381 rc = -EOPNOTSUPP;
1382 goto out;
1383 }
1384 rc = qeth_l3_send_simple_setassparms(card, IPA_FILTERING,
1385 IPA_CMD_ASS_START, 0);
1386 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001387 dev_warn(&card->gdev->dev, "Enabling broadcast filtering for "
1388 "%s failed\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001389 goto out;
1390 }
1391
1392 rc = qeth_l3_send_simple_setassparms(card, IPA_FILTERING,
1393 IPA_CMD_ASS_CONFIGURE, 1);
1394 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001395 dev_warn(&card->gdev->dev,
1396 "Setting up broadcast filtering for %s failed\n",
1397 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001398 goto out;
1399 }
1400 card->info.broadcast_capable = QETH_BROADCAST_WITH_ECHO;
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001401 dev_info(&card->gdev->dev, "Broadcast enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001402 rc = qeth_l3_send_simple_setassparms(card, IPA_FILTERING,
1403 IPA_CMD_ASS_ENABLE, 1);
1404 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001405 dev_warn(&card->gdev->dev, "Setting up broadcast echo "
1406 "filtering for %s failed\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001407 goto out;
1408 }
1409 card->info.broadcast_capable = QETH_BROADCAST_WITHOUT_ECHO;
1410out:
1411 if (card->info.broadcast_capable)
1412 card->dev->flags |= IFF_BROADCAST;
1413 else
1414 card->dev->flags &= ~IFF_BROADCAST;
1415 return rc;
1416}
1417
1418static int qeth_l3_send_checksum_command(struct qeth_card *card)
1419{
1420 int rc;
1421
1422 rc = qeth_l3_send_simple_setassparms(card, IPA_INBOUND_CHECKSUM,
1423 IPA_CMD_ASS_START, 0);
1424 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001425 dev_warn(&card->gdev->dev, "Starting HW checksumming for %s "
1426 "failed, using SW checksumming\n",
1427 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001428 return rc;
1429 }
1430 rc = qeth_l3_send_simple_setassparms(card, IPA_INBOUND_CHECKSUM,
1431 IPA_CMD_ASS_ENABLE,
1432 card->info.csum_mask);
1433 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001434 dev_warn(&card->gdev->dev, "Enabling HW checksumming for %s "
1435 "failed, using SW checksumming\n",
1436 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001437 return rc;
1438 }
1439 return 0;
1440}
1441
1442static int qeth_l3_start_ipa_checksum(struct qeth_card *card)
1443{
1444 int rc = 0;
1445
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001446 QETH_DBF_TEXT(TRACE, 3, "strtcsum");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001447
1448 if (card->options.checksum_type == NO_CHECKSUMMING) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001449 dev_info(&card->gdev->dev,
1450 "Using no checksumming on %s.\n",
1451 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001452 return 0;
1453 }
1454 if (card->options.checksum_type == SW_CHECKSUMMING) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001455 dev_info(&card->gdev->dev,
1456 "Using SW checksumming on %s.\n",
1457 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001458 return 0;
1459 }
1460 if (!qeth_is_supported(card, IPA_INBOUND_CHECKSUM)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001461 dev_info(&card->gdev->dev,
1462 "Inbound HW Checksumming not "
1463 "supported on %s,\ncontinuing "
1464 "using Inbound SW Checksumming\n",
1465 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001466 card->options.checksum_type = SW_CHECKSUMMING;
1467 return 0;
1468 }
1469 rc = qeth_l3_send_checksum_command(card);
1470 if (!rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001471 dev_info(&card->gdev->dev,
1472 "HW Checksumming (inbound) enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001473
1474 return rc;
1475}
1476
1477static int qeth_l3_start_ipa_tso(struct qeth_card *card)
1478{
1479 int rc;
1480
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001481 QETH_DBF_TEXT(TRACE, 3, "sttso");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001482
1483 if (!qeth_is_supported(card, IPA_OUTBOUND_TSO)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001484 dev_info(&card->gdev->dev,
1485 "Outbound TSO not supported on %s\n",
1486 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001487 rc = -EOPNOTSUPP;
1488 } else {
1489 rc = qeth_l3_send_simple_setassparms(card, IPA_OUTBOUND_TSO,
1490 IPA_CMD_ASS_START, 0);
1491 if (rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001492 dev_warn(&card->gdev->dev, "Starting outbound TCP "
1493 "segmentation offload for %s failed\n",
1494 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001495 else
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001496 dev_info(&card->gdev->dev,
1497 "Outbound TSO enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001498 }
1499 if (rc && (card->options.large_send == QETH_LARGE_SEND_TSO)) {
1500 card->options.large_send = QETH_LARGE_SEND_NO;
1501 card->dev->features &= ~(NETIF_F_TSO | NETIF_F_SG);
1502 }
1503 return rc;
1504}
1505
1506static int qeth_l3_start_ipassists(struct qeth_card *card)
1507{
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001508 QETH_DBF_TEXT(TRACE, 3, "strtipas");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001509 qeth_l3_start_ipa_arp_processing(card); /* go on*/
1510 qeth_l3_start_ipa_ip_fragmentation(card); /* go on*/
1511 qeth_l3_start_ipa_source_mac(card); /* go on*/
1512 qeth_l3_start_ipa_vlan(card); /* go on*/
1513 qeth_l3_start_ipa_multicast(card); /* go on*/
1514 qeth_l3_start_ipa_ipv6(card); /* go on*/
1515 qeth_l3_start_ipa_broadcast(card); /* go on*/
1516 qeth_l3_start_ipa_checksum(card); /* go on*/
1517 qeth_l3_start_ipa_tso(card); /* go on*/
1518 return 0;
1519}
1520
1521static int qeth_l3_put_unique_id(struct qeth_card *card)
1522{
1523
1524 int rc = 0;
1525 struct qeth_cmd_buffer *iob;
1526 struct qeth_ipa_cmd *cmd;
1527
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001528 QETH_DBF_TEXT(TRACE, 2, "puniqeid");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001529
1530 if ((card->info.unique_id & UNIQUE_ID_NOT_BY_CARD) ==
1531 UNIQUE_ID_NOT_BY_CARD)
1532 return -1;
1533 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_DESTROY_ADDR,
1534 QETH_PROT_IPV6);
1535 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1536 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
1537 card->info.unique_id;
1538 memcpy(&cmd->data.create_destroy_addr.unique_id[0],
1539 card->dev->dev_addr, OSA_ADDR_LEN);
1540 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
1541 return rc;
1542}
1543
1544static int qeth_l3_iqd_read_initial_mac_cb(struct qeth_card *card,
1545 struct qeth_reply *reply, unsigned long data)
1546{
1547 struct qeth_ipa_cmd *cmd;
1548
1549 cmd = (struct qeth_ipa_cmd *) data;
1550 if (cmd->hdr.return_code == 0)
1551 memcpy(card->dev->dev_addr,
1552 cmd->data.create_destroy_addr.unique_id, ETH_ALEN);
1553 else
1554 random_ether_addr(card->dev->dev_addr);
1555
1556 return 0;
1557}
1558
1559static int qeth_l3_iqd_read_initial_mac(struct qeth_card *card)
1560{
1561 int rc = 0;
1562 struct qeth_cmd_buffer *iob;
1563 struct qeth_ipa_cmd *cmd;
1564
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001565 QETH_DBF_TEXT(SETUP, 2, "hsrmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001566
1567 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_CREATE_ADDR,
1568 QETH_PROT_IPV6);
1569 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1570 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
1571 card->info.unique_id;
1572
1573 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_iqd_read_initial_mac_cb,
1574 NULL);
1575 return rc;
1576}
1577
1578static int qeth_l3_get_unique_id_cb(struct qeth_card *card,
1579 struct qeth_reply *reply, unsigned long data)
1580{
1581 struct qeth_ipa_cmd *cmd;
1582
1583 cmd = (struct qeth_ipa_cmd *) data;
1584 if (cmd->hdr.return_code == 0)
1585 card->info.unique_id = *((__u16 *)
1586 &cmd->data.create_destroy_addr.unique_id[6]);
1587 else {
1588 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
1589 UNIQUE_ID_NOT_BY_CARD;
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001590 dev_warn(&card->gdev->dev, "The network adapter failed to "
1591 "generate a unique ID\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001592 }
1593 return 0;
1594}
1595
1596static int qeth_l3_get_unique_id(struct qeth_card *card)
1597{
1598 int rc = 0;
1599 struct qeth_cmd_buffer *iob;
1600 struct qeth_ipa_cmd *cmd;
1601
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001602 QETH_DBF_TEXT(SETUP, 2, "guniqeid");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001603
1604 if (!qeth_is_supported(card, IPA_IPV6)) {
1605 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
1606 UNIQUE_ID_NOT_BY_CARD;
1607 return 0;
1608 }
1609
1610 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_CREATE_ADDR,
1611 QETH_PROT_IPV6);
1612 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1613 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
1614 card->info.unique_id;
1615
1616 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_get_unique_id_cb, NULL);
1617 return rc;
1618}
1619
1620static void qeth_l3_get_mac_for_ipm(__u32 ipm, char *mac,
1621 struct net_device *dev)
1622{
1623 if (dev->type == ARPHRD_IEEE802_TR)
1624 ip_tr_mc_map(ipm, mac);
1625 else
1626 ip_eth_mc_map(ipm, mac);
1627}
1628
1629static void qeth_l3_add_mc(struct qeth_card *card, struct in_device *in4_dev)
1630{
1631 struct qeth_ipaddr *ipm;
1632 struct ip_mc_list *im4;
1633 char buf[MAX_ADDR_LEN];
1634
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001635 QETH_DBF_TEXT(TRACE, 4, "addmc");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001636 for (im4 = in4_dev->mc_list; im4; im4 = im4->next) {
1637 qeth_l3_get_mac_for_ipm(im4->multiaddr, buf, in4_dev->dev);
1638 ipm = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
1639 if (!ipm)
1640 continue;
1641 ipm->u.a4.addr = im4->multiaddr;
1642 memcpy(ipm->mac, buf, OSA_ADDR_LEN);
1643 ipm->is_multicast = 1;
1644 if (!qeth_l3_add_ip(card, ipm))
1645 kfree(ipm);
1646 }
1647}
1648
1649static void qeth_l3_add_vlan_mc(struct qeth_card *card)
1650{
1651 struct in_device *in_dev;
1652 struct vlan_group *vg;
1653 int i;
1654
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001655 QETH_DBF_TEXT(TRACE, 4, "addmcvl");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001656 if (!qeth_is_supported(card, IPA_FULL_VLAN) || (card->vlangrp == NULL))
1657 return;
1658
1659 vg = card->vlangrp;
1660 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
1661 struct net_device *netdev = vlan_group_get_device(vg, i);
1662 if (netdev == NULL ||
1663 !(netdev->flags & IFF_UP))
1664 continue;
1665 in_dev = in_dev_get(netdev);
1666 if (!in_dev)
1667 continue;
1668 read_lock(&in_dev->mc_list_lock);
1669 qeth_l3_add_mc(card, in_dev);
1670 read_unlock(&in_dev->mc_list_lock);
1671 in_dev_put(in_dev);
1672 }
1673}
1674
1675static void qeth_l3_add_multicast_ipv4(struct qeth_card *card)
1676{
1677 struct in_device *in4_dev;
1678
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001679 QETH_DBF_TEXT(TRACE, 4, "chkmcv4");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001680 in4_dev = in_dev_get(card->dev);
1681 if (in4_dev == NULL)
1682 return;
1683 read_lock(&in4_dev->mc_list_lock);
1684 qeth_l3_add_mc(card, in4_dev);
1685 qeth_l3_add_vlan_mc(card);
1686 read_unlock(&in4_dev->mc_list_lock);
1687 in_dev_put(in4_dev);
1688}
1689
1690#ifdef CONFIG_QETH_IPV6
1691static void qeth_l3_add_mc6(struct qeth_card *card, struct inet6_dev *in6_dev)
1692{
1693 struct qeth_ipaddr *ipm;
1694 struct ifmcaddr6 *im6;
1695 char buf[MAX_ADDR_LEN];
1696
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001697 QETH_DBF_TEXT(TRACE, 4, "addmc6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001698 for (im6 = in6_dev->mc_list; im6 != NULL; im6 = im6->next) {
1699 ndisc_mc_map(&im6->mca_addr, buf, in6_dev->dev, 0);
1700 ipm = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
1701 if (!ipm)
1702 continue;
1703 ipm->is_multicast = 1;
1704 memcpy(ipm->mac, buf, OSA_ADDR_LEN);
1705 memcpy(&ipm->u.a6.addr, &im6->mca_addr.s6_addr,
1706 sizeof(struct in6_addr));
1707 if (!qeth_l3_add_ip(card, ipm))
1708 kfree(ipm);
1709 }
1710}
1711
1712static void qeth_l3_add_vlan_mc6(struct qeth_card *card)
1713{
1714 struct inet6_dev *in_dev;
1715 struct vlan_group *vg;
1716 int i;
1717
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001718 QETH_DBF_TEXT(TRACE, 4, "admc6vl");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001719 if (!qeth_is_supported(card, IPA_FULL_VLAN) || (card->vlangrp == NULL))
1720 return;
1721
1722 vg = card->vlangrp;
1723 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
1724 struct net_device *netdev = vlan_group_get_device(vg, i);
1725 if (netdev == NULL ||
1726 !(netdev->flags & IFF_UP))
1727 continue;
1728 in_dev = in6_dev_get(netdev);
1729 if (!in_dev)
1730 continue;
1731 read_lock_bh(&in_dev->lock);
1732 qeth_l3_add_mc6(card, in_dev);
1733 read_unlock_bh(&in_dev->lock);
1734 in6_dev_put(in_dev);
1735 }
1736}
1737
1738static void qeth_l3_add_multicast_ipv6(struct qeth_card *card)
1739{
1740 struct inet6_dev *in6_dev;
1741
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001742 QETH_DBF_TEXT(TRACE, 4, "chkmcv6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001743 if (!qeth_is_supported(card, IPA_IPV6))
1744 return ;
1745 in6_dev = in6_dev_get(card->dev);
1746 if (in6_dev == NULL)
1747 return;
1748 read_lock_bh(&in6_dev->lock);
1749 qeth_l3_add_mc6(card, in6_dev);
1750 qeth_l3_add_vlan_mc6(card);
1751 read_unlock_bh(&in6_dev->lock);
1752 in6_dev_put(in6_dev);
1753}
1754#endif /* CONFIG_QETH_IPV6 */
1755
1756static void qeth_l3_free_vlan_addresses4(struct qeth_card *card,
1757 unsigned short vid)
1758{
1759 struct in_device *in_dev;
1760 struct in_ifaddr *ifa;
1761 struct qeth_ipaddr *addr;
1762
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001763 QETH_DBF_TEXT(TRACE, 4, "frvaddr4");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001764
1765 in_dev = in_dev_get(vlan_group_get_device(card->vlangrp, vid));
1766 if (!in_dev)
1767 return;
1768 for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
1769 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
1770 if (addr) {
1771 addr->u.a4.addr = ifa->ifa_address;
1772 addr->u.a4.mask = ifa->ifa_mask;
1773 addr->type = QETH_IP_TYPE_NORMAL;
1774 if (!qeth_l3_delete_ip(card, addr))
1775 kfree(addr);
1776 }
1777 }
1778 in_dev_put(in_dev);
1779}
1780
1781static void qeth_l3_free_vlan_addresses6(struct qeth_card *card,
1782 unsigned short vid)
1783{
1784#ifdef CONFIG_QETH_IPV6
1785 struct inet6_dev *in6_dev;
1786 struct inet6_ifaddr *ifa;
1787 struct qeth_ipaddr *addr;
1788
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001789 QETH_DBF_TEXT(TRACE, 4, "frvaddr6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001790
1791 in6_dev = in6_dev_get(vlan_group_get_device(card->vlangrp, vid));
1792 if (!in6_dev)
1793 return;
1794 for (ifa = in6_dev->addr_list; ifa; ifa = ifa->lst_next) {
1795 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
1796 if (addr) {
1797 memcpy(&addr->u.a6.addr, &ifa->addr,
1798 sizeof(struct in6_addr));
1799 addr->u.a6.pfxlen = ifa->prefix_len;
1800 addr->type = QETH_IP_TYPE_NORMAL;
1801 if (!qeth_l3_delete_ip(card, addr))
1802 kfree(addr);
1803 }
1804 }
1805 in6_dev_put(in6_dev);
1806#endif /* CONFIG_QETH_IPV6 */
1807}
1808
1809static void qeth_l3_free_vlan_addresses(struct qeth_card *card,
1810 unsigned short vid)
1811{
1812 if (!card->vlangrp)
1813 return;
1814 qeth_l3_free_vlan_addresses4(card, vid);
1815 qeth_l3_free_vlan_addresses6(card, vid);
1816}
1817
1818static void qeth_l3_vlan_rx_register(struct net_device *dev,
1819 struct vlan_group *grp)
1820{
Heiko Carstens509e2562008-07-26 02:24:10 -07001821 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001822 unsigned long flags;
1823
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001824 QETH_DBF_TEXT(TRACE, 4, "vlanreg");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001825 spin_lock_irqsave(&card->vlanlock, flags);
1826 card->vlangrp = grp;
1827 spin_unlock_irqrestore(&card->vlanlock, flags);
1828}
1829
1830static void qeth_l3_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
1831{
Frank Blaschka4a71df52008-02-15 09:19:42 +01001832 return;
1833}
1834
1835static void qeth_l3_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
1836{
Heiko Carstens509e2562008-07-26 02:24:10 -07001837 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001838 unsigned long flags;
1839
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001840 QETH_DBF_TEXT_(TRACE, 4, "kid:%d", vid);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001841 spin_lock_irqsave(&card->vlanlock, flags);
1842 /* unregister IP addresses of vlan device */
1843 qeth_l3_free_vlan_addresses(card, vid);
1844 vlan_group_set_device(card->vlangrp, vid, NULL);
1845 spin_unlock_irqrestore(&card->vlanlock, flags);
1846 qeth_l3_set_multicast_list(card->dev);
1847}
1848
1849static inline __u16 qeth_l3_rebuild_skb(struct qeth_card *card,
1850 struct sk_buff *skb, struct qeth_hdr *hdr)
1851{
1852 unsigned short vlan_id = 0;
1853 __be16 prot;
1854 struct iphdr *ip_hdr;
1855 unsigned char tg_addr[MAX_ADDR_LEN];
1856
1857 if (!(hdr->hdr.l3.flags & QETH_HDR_PASSTHRU)) {
1858 prot = htons((hdr->hdr.l3.flags & QETH_HDR_IPV6)? ETH_P_IPV6 :
1859 ETH_P_IP);
1860 switch (hdr->hdr.l3.flags & QETH_HDR_CAST_MASK) {
1861 case QETH_CAST_MULTICAST:
1862 switch (prot) {
1863#ifdef CONFIG_QETH_IPV6
1864 case __constant_htons(ETH_P_IPV6):
1865 ndisc_mc_map((struct in6_addr *)
1866 skb->data + 24,
1867 tg_addr, card->dev, 0);
1868 break;
1869#endif
1870 case __constant_htons(ETH_P_IP):
1871 ip_hdr = (struct iphdr *)skb->data;
1872 (card->dev->type == ARPHRD_IEEE802_TR) ?
1873 ip_tr_mc_map(ip_hdr->daddr, tg_addr):
1874 ip_eth_mc_map(ip_hdr->daddr, tg_addr);
1875 break;
1876 default:
1877 memcpy(tg_addr, card->dev->broadcast,
1878 card->dev->addr_len);
1879 }
1880 card->stats.multicast++;
1881 skb->pkt_type = PACKET_MULTICAST;
1882 break;
1883 case QETH_CAST_BROADCAST:
1884 memcpy(tg_addr, card->dev->broadcast,
1885 card->dev->addr_len);
1886 card->stats.multicast++;
1887 skb->pkt_type = PACKET_BROADCAST;
1888 break;
1889 case QETH_CAST_UNICAST:
1890 case QETH_CAST_ANYCAST:
1891 case QETH_CAST_NOCAST:
1892 default:
1893 skb->pkt_type = PACKET_HOST;
1894 memcpy(tg_addr, card->dev->dev_addr,
1895 card->dev->addr_len);
1896 }
Ursula Braunfe94e2e2009-01-04 17:34:52 -08001897 if (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_SRC_MAC_ADDR)
1898 card->dev->header_ops->create(skb, card->dev, prot,
1899 tg_addr, &hdr->hdr.l3.dest_addr[2],
1900 card->dev->addr_len);
1901 else
1902 card->dev->header_ops->create(skb, card->dev, prot,
1903 tg_addr, "FAKELL", card->dev->addr_len);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001904 }
1905
1906#ifdef CONFIG_TR
1907 if (card->dev->type == ARPHRD_IEEE802_TR)
1908 skb->protocol = tr_type_trans(skb, card->dev);
1909 else
1910#endif
1911 skb->protocol = eth_type_trans(skb, card->dev);
1912
1913 if (hdr->hdr.l3.ext_flags &
1914 (QETH_HDR_EXT_VLAN_FRAME | QETH_HDR_EXT_INCLUDE_VLAN_TAG)) {
1915 vlan_id = (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_VLAN_FRAME)?
1916 hdr->hdr.l3.vlan_id : *((u16 *)&hdr->hdr.l3.dest_addr[12]);
1917 }
1918
1919 skb->ip_summed = card->options.checksum_type;
1920 if (card->options.checksum_type == HW_CHECKSUMMING) {
1921 if ((hdr->hdr.l3.ext_flags &
1922 (QETH_HDR_EXT_CSUM_HDR_REQ |
1923 QETH_HDR_EXT_CSUM_TRANSP_REQ)) ==
1924 (QETH_HDR_EXT_CSUM_HDR_REQ |
1925 QETH_HDR_EXT_CSUM_TRANSP_REQ))
1926 skb->ip_summed = CHECKSUM_UNNECESSARY;
1927 else
1928 skb->ip_summed = SW_CHECKSUMMING;
1929 }
1930
1931 return vlan_id;
1932}
1933
1934static void qeth_l3_process_inbound_buffer(struct qeth_card *card,
1935 struct qeth_qdio_buffer *buf, int index)
1936{
1937 struct qdio_buffer_element *element;
1938 struct sk_buff *skb;
1939 struct qeth_hdr *hdr;
1940 int offset;
1941 __u16 vlan_tag = 0;
1942 unsigned int len;
1943
1944 /* get first element of current buffer */
1945 element = (struct qdio_buffer_element *)&buf->buffer->element[0];
1946 offset = 0;
1947 if (card->options.performance_stats)
1948 card->perf_stats.bufs_rec++;
1949 while ((skb = qeth_core_get_next_skb(card, buf->buffer, &element,
1950 &offset, &hdr))) {
1951 skb->dev = card->dev;
1952 /* is device UP ? */
1953 if (!(card->dev->flags & IFF_UP)) {
1954 dev_kfree_skb_any(skb);
1955 continue;
1956 }
1957
1958 switch (hdr->hdr.l3.id) {
1959 case QETH_HEADER_TYPE_LAYER3:
1960 vlan_tag = qeth_l3_rebuild_skb(card, skb, hdr);
1961 len = skb->len;
1962 if (vlan_tag)
1963 if (card->vlangrp)
1964 vlan_hwaccel_rx(skb, card->vlangrp,
1965 vlan_tag);
1966 else {
1967 dev_kfree_skb_any(skb);
1968 continue;
1969 }
1970 else
1971 netif_rx(skb);
1972 break;
1973 default:
1974 dev_kfree_skb_any(skb);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001975 QETH_DBF_TEXT(TRACE, 3, "inbunkno");
1976 QETH_DBF_HEX(CTRL, 3, hdr, QETH_DBF_CTRL_LEN);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001977 continue;
1978 }
1979
1980 card->dev->last_rx = jiffies;
1981 card->stats.rx_packets++;
1982 card->stats.rx_bytes += len;
1983 }
1984}
1985
1986static int qeth_l3_verify_vlan_dev(struct net_device *dev,
1987 struct qeth_card *card)
1988{
1989 int rc = 0;
1990 struct vlan_group *vg;
1991 int i;
1992
1993 vg = card->vlangrp;
1994 if (!vg)
1995 return rc;
1996
1997 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
1998 if (vlan_group_get_device(vg, i) == dev) {
1999 rc = QETH_VLAN_CARD;
2000 break;
2001 }
2002 }
2003
Heiko Carstens509e2562008-07-26 02:24:10 -07002004 if (rc && !(vlan_dev_real_dev(dev)->ml_priv == (void *)card))
Frank Blaschka4a71df52008-02-15 09:19:42 +01002005 return 0;
2006
2007 return rc;
2008}
2009
2010static int qeth_l3_verify_dev(struct net_device *dev)
2011{
2012 struct qeth_card *card;
2013 unsigned long flags;
2014 int rc = 0;
2015
2016 read_lock_irqsave(&qeth_core_card_list.rwlock, flags);
2017 list_for_each_entry(card, &qeth_core_card_list.list, list) {
2018 if (card->dev == dev) {
2019 rc = QETH_REAL_CARD;
2020 break;
2021 }
2022 rc = qeth_l3_verify_vlan_dev(dev, card);
2023 if (rc)
2024 break;
2025 }
2026 read_unlock_irqrestore(&qeth_core_card_list.rwlock, flags);
2027
2028 return rc;
2029}
2030
2031static struct qeth_card *qeth_l3_get_card_from_dev(struct net_device *dev)
2032{
2033 struct qeth_card *card = NULL;
2034 int rc;
2035
2036 rc = qeth_l3_verify_dev(dev);
2037 if (rc == QETH_REAL_CARD)
Heiko Carstens509e2562008-07-26 02:24:10 -07002038 card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002039 else if (rc == QETH_VLAN_CARD)
Heiko Carstens509e2562008-07-26 02:24:10 -07002040 card = vlan_dev_real_dev(dev)->ml_priv;
Frank Blaschkae5bd7be2008-06-06 12:37:44 +02002041 if (card && card->options.layer2)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002042 card = NULL;
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002043 QETH_DBF_TEXT_(TRACE, 4, "%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002044 return card ;
2045}
2046
2047static int qeth_l3_stop_card(struct qeth_card *card, int recovery_mode)
2048{
2049 int rc = 0;
2050
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002051 QETH_DBF_TEXT(SETUP, 2, "stopcard");
2052 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01002053
2054 qeth_set_allowed_threads(card, 0, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002055 if (card->read.state == CH_STATE_UP &&
2056 card->write.state == CH_STATE_UP &&
2057 (card->state == CARD_STATE_UP)) {
2058 if (recovery_mode)
2059 qeth_l3_stop(card->dev);
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02002060 else {
Ursula Braunfc9c2462009-01-04 17:35:18 -08002061 if (card->dev) {
2062 rtnl_lock();
2063 dev_close(card->dev);
2064 rtnl_unlock();
2065 }
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02002066 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002067 if (!card->use_hard_stop) {
2068 rc = qeth_send_stoplan(card);
2069 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002070 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002071 }
2072 card->state = CARD_STATE_SOFTSETUP;
2073 }
2074 if (card->state == CARD_STATE_SOFTSETUP) {
2075 qeth_l3_clear_ip_list(card, !card->use_hard_stop, 1);
2076 qeth_clear_ipacmd_list(card);
2077 card->state = CARD_STATE_HARDSETUP;
2078 }
2079 if (card->state == CARD_STATE_HARDSETUP) {
2080 if (!card->use_hard_stop &&
2081 (card->info.type != QETH_CARD_TYPE_IQD)) {
2082 rc = qeth_l3_put_unique_id(card);
2083 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002084 QETH_DBF_TEXT_(SETUP, 2, "2err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002085 }
2086 qeth_qdio_clear_card(card, 0);
2087 qeth_clear_qdio_buffers(card);
2088 qeth_clear_working_pool_list(card);
2089 card->state = CARD_STATE_DOWN;
2090 }
2091 if (card->state == CARD_STATE_DOWN) {
2092 qeth_clear_cmd_buffers(&card->read);
2093 qeth_clear_cmd_buffers(&card->write);
2094 }
2095 card->use_hard_stop = 0;
2096 return rc;
2097}
2098
2099static void qeth_l3_set_multicast_list(struct net_device *dev)
2100{
Heiko Carstens509e2562008-07-26 02:24:10 -07002101 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002102
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002103 QETH_DBF_TEXT(TRACE, 3, "setmulti");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002104 qeth_l3_delete_mc_addresses(card);
2105 qeth_l3_add_multicast_ipv4(card);
2106#ifdef CONFIG_QETH_IPV6
2107 qeth_l3_add_multicast_ipv6(card);
2108#endif
2109 qeth_l3_set_ip_addr_list(card);
2110 if (!qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
2111 return;
2112 qeth_setadp_promisc_mode(card);
2113}
2114
2115static const char *qeth_l3_arp_get_error_cause(int *rc)
2116{
2117 switch (*rc) {
2118 case QETH_IPA_ARP_RC_FAILED:
2119 *rc = -EIO;
2120 return "operation failed";
2121 case QETH_IPA_ARP_RC_NOTSUPP:
2122 *rc = -EOPNOTSUPP;
2123 return "operation not supported";
2124 case QETH_IPA_ARP_RC_OUT_OF_RANGE:
2125 *rc = -EINVAL;
2126 return "argument out of range";
2127 case QETH_IPA_ARP_RC_Q_NOTSUPP:
2128 *rc = -EOPNOTSUPP;
2129 return "query operation not supported";
2130 case QETH_IPA_ARP_RC_Q_NO_DATA:
2131 *rc = -ENOENT;
2132 return "no query data available";
2133 default:
2134 return "unknown error";
2135 }
2136}
2137
2138static int qeth_l3_arp_set_no_entries(struct qeth_card *card, int no_entries)
2139{
2140 int tmp;
2141 int rc;
2142
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002143 QETH_DBF_TEXT(TRACE, 3, "arpstnoe");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002144
2145 /*
2146 * currently GuestLAN only supports the ARP assist function
2147 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_SET_NO_ENTRIES;
2148 * thus we say EOPNOTSUPP for this ARP function
2149 */
2150 if (card->info.guestlan)
2151 return -EOPNOTSUPP;
2152 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002153 return -EOPNOTSUPP;
2154 }
2155 rc = qeth_l3_send_simple_setassparms(card, IPA_ARP_PROCESSING,
2156 IPA_CMD_ASS_ARP_SET_NO_ENTRIES,
2157 no_entries);
2158 if (rc) {
2159 tmp = rc;
Frank Blaschka14cc21b2008-06-06 12:37:46 +02002160 QETH_DBF_MESSAGE(2, "Could not set number of ARP entries on "
2161 "%s: %s (0x%x/%d)\n", QETH_CARD_IFNAME(card),
Frank Blaschka4a71df52008-02-15 09:19:42 +01002162 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
2163 }
2164 return rc;
2165}
2166
2167static void qeth_l3_copy_arp_entries_stripped(struct qeth_arp_query_info *qinfo,
2168 struct qeth_arp_query_data *qdata, int entry_size,
2169 int uentry_size)
2170{
2171 char *entry_ptr;
2172 char *uentry_ptr;
2173 int i;
2174
2175 entry_ptr = (char *)&qdata->data;
2176 uentry_ptr = (char *)(qinfo->udata + qinfo->udata_offset);
2177 for (i = 0; i < qdata->no_entries; ++i) {
2178 /* strip off 32 bytes "media specific information" */
2179 memcpy(uentry_ptr, (entry_ptr + 32), entry_size - 32);
2180 entry_ptr += entry_size;
2181 uentry_ptr += uentry_size;
2182 }
2183}
2184
2185static int qeth_l3_arp_query_cb(struct qeth_card *card,
2186 struct qeth_reply *reply, unsigned long data)
2187{
2188 struct qeth_ipa_cmd *cmd;
2189 struct qeth_arp_query_data *qdata;
2190 struct qeth_arp_query_info *qinfo;
2191 int entry_size;
2192 int uentry_size;
2193 int i;
2194
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002195 QETH_DBF_TEXT(TRACE, 4, "arpquecb");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002196
2197 qinfo = (struct qeth_arp_query_info *) reply->param;
2198 cmd = (struct qeth_ipa_cmd *) data;
2199 if (cmd->hdr.return_code) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002200 QETH_DBF_TEXT_(TRACE, 4, "qaer1%i", cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002201 return 0;
2202 }
2203 if (cmd->data.setassparms.hdr.return_code) {
2204 cmd->hdr.return_code = cmd->data.setassparms.hdr.return_code;
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002205 QETH_DBF_TEXT_(TRACE, 4, "qaer2%i", cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002206 return 0;
2207 }
2208 qdata = &cmd->data.setassparms.data.query_arp;
2209 switch (qdata->reply_bits) {
2210 case 5:
2211 uentry_size = entry_size = sizeof(struct qeth_arp_qi_entry5);
2212 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES)
2213 uentry_size = sizeof(struct qeth_arp_qi_entry5_short);
2214 break;
2215 case 7:
2216 /* fall through to default */
2217 default:
2218 /* tr is the same as eth -> entry7 */
2219 uentry_size = entry_size = sizeof(struct qeth_arp_qi_entry7);
2220 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES)
2221 uentry_size = sizeof(struct qeth_arp_qi_entry7_short);
2222 break;
2223 }
2224 /* check if there is enough room in userspace */
2225 if ((qinfo->udata_len - qinfo->udata_offset) <
2226 qdata->no_entries * uentry_size){
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002227 QETH_DBF_TEXT_(TRACE, 4, "qaer3%i", -ENOMEM);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002228 cmd->hdr.return_code = -ENOMEM;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002229 goto out_error;
2230 }
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002231 QETH_DBF_TEXT_(TRACE, 4, "anore%i",
Frank Blaschka4a71df52008-02-15 09:19:42 +01002232 cmd->data.setassparms.hdr.number_of_replies);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002233 QETH_DBF_TEXT_(TRACE, 4, "aseqn%i", cmd->data.setassparms.hdr.seq_no);
2234 QETH_DBF_TEXT_(TRACE, 4, "anoen%i", qdata->no_entries);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002235
2236 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES) {
2237 /* strip off "media specific information" */
2238 qeth_l3_copy_arp_entries_stripped(qinfo, qdata, entry_size,
2239 uentry_size);
2240 } else
2241 /*copy entries to user buffer*/
2242 memcpy(qinfo->udata + qinfo->udata_offset,
2243 (char *)&qdata->data, qdata->no_entries*uentry_size);
2244
2245 qinfo->no_entries += qdata->no_entries;
2246 qinfo->udata_offset += (qdata->no_entries*uentry_size);
2247 /* check if all replies received ... */
2248 if (cmd->data.setassparms.hdr.seq_no <
2249 cmd->data.setassparms.hdr.number_of_replies)
2250 return 1;
2251 memcpy(qinfo->udata, &qinfo->no_entries, 4);
2252 /* keep STRIP_ENTRIES flag so the user program can distinguish
2253 * stripped entries from normal ones */
2254 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES)
2255 qdata->reply_bits |= QETH_QARP_STRIP_ENTRIES;
2256 memcpy(qinfo->udata + QETH_QARP_MASK_OFFSET, &qdata->reply_bits, 2);
2257 return 0;
2258out_error:
2259 i = 0;
2260 memcpy(qinfo->udata, &i, 4);
2261 return 0;
2262}
2263
2264static int qeth_l3_send_ipa_arp_cmd(struct qeth_card *card,
2265 struct qeth_cmd_buffer *iob, int len,
2266 int (*reply_cb)(struct qeth_card *, struct qeth_reply *,
2267 unsigned long),
2268 void *reply_param)
2269{
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002270 QETH_DBF_TEXT(TRACE, 4, "sendarp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002271
2272 memcpy(iob->data, IPA_PDU_HEADER, IPA_PDU_HEADER_SIZE);
2273 memcpy(QETH_IPA_CMD_DEST_ADDR(iob->data),
2274 &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
2275 return qeth_send_control_data(card, IPA_PDU_HEADER_SIZE + len, iob,
2276 reply_cb, reply_param);
2277}
2278
2279static int qeth_l3_arp_query(struct qeth_card *card, char __user *udata)
2280{
2281 struct qeth_cmd_buffer *iob;
2282 struct qeth_arp_query_info qinfo = {0, };
2283 int tmp;
2284 int rc;
2285
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002286 QETH_DBF_TEXT(TRACE, 3, "arpquery");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002287
2288 if (!qeth_is_supported(card,/*IPA_QUERY_ARP_ADDR_INFO*/
2289 IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002290 return -EOPNOTSUPP;
2291 }
2292 /* get size of userspace buffer and mask_bits -> 6 bytes */
2293 if (copy_from_user(&qinfo, udata, 6))
2294 return -EFAULT;
2295 qinfo.udata = kzalloc(qinfo.udata_len, GFP_KERNEL);
2296 if (!qinfo.udata)
2297 return -ENOMEM;
2298 qinfo.udata_offset = QETH_QARP_ENTRIES_OFFSET;
2299 iob = qeth_l3_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
2300 IPA_CMD_ASS_ARP_QUERY_INFO,
2301 sizeof(int), QETH_PROT_IPV4);
2302
2303 rc = qeth_l3_send_ipa_arp_cmd(card, iob,
2304 QETH_SETASS_BASE_LEN+QETH_ARP_CMD_LEN,
2305 qeth_l3_arp_query_cb, (void *)&qinfo);
2306 if (rc) {
2307 tmp = rc;
Frank Blaschka14cc21b2008-06-06 12:37:46 +02002308 QETH_DBF_MESSAGE(2, "Error while querying ARP cache on %s: %s "
Frank Blaschka4a71df52008-02-15 09:19:42 +01002309 "(0x%x/%d)\n", QETH_CARD_IFNAME(card),
2310 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
2311 if (copy_to_user(udata, qinfo.udata, 4))
2312 rc = -EFAULT;
2313 } else {
2314 if (copy_to_user(udata, qinfo.udata, qinfo.udata_len))
2315 rc = -EFAULT;
2316 }
2317 kfree(qinfo.udata);
2318 return rc;
2319}
2320
2321static int qeth_l3_arp_add_entry(struct qeth_card *card,
2322 struct qeth_arp_cache_entry *entry)
2323{
2324 struct qeth_cmd_buffer *iob;
2325 char buf[16];
2326 int tmp;
2327 int rc;
2328
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002329 QETH_DBF_TEXT(TRACE, 3, "arpadent");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002330
2331 /*
2332 * currently GuestLAN only supports the ARP assist function
2333 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_ADD_ENTRY;
2334 * thus we say EOPNOTSUPP for this ARP function
2335 */
2336 if (card->info.guestlan)
2337 return -EOPNOTSUPP;
2338 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002339 return -EOPNOTSUPP;
2340 }
2341
2342 iob = qeth_l3_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
2343 IPA_CMD_ASS_ARP_ADD_ENTRY,
2344 sizeof(struct qeth_arp_cache_entry),
2345 QETH_PROT_IPV4);
2346 rc = qeth_l3_send_setassparms(card, iob,
2347 sizeof(struct qeth_arp_cache_entry),
2348 (unsigned long) entry,
2349 qeth_l3_default_setassparms_cb, NULL);
2350 if (rc) {
2351 tmp = rc;
2352 qeth_l3_ipaddr4_to_string((u8 *)entry->ipaddr, buf);
Frank Blaschka14cc21b2008-06-06 12:37:46 +02002353 QETH_DBF_MESSAGE(2, "Could not add ARP entry for address %s "
2354 "on %s: %s (0x%x/%d)\n", buf, QETH_CARD_IFNAME(card),
2355 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002356 }
2357 return rc;
2358}
2359
2360static int qeth_l3_arp_remove_entry(struct qeth_card *card,
2361 struct qeth_arp_cache_entry *entry)
2362{
2363 struct qeth_cmd_buffer *iob;
2364 char buf[16] = {0, };
2365 int tmp;
2366 int rc;
2367
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002368 QETH_DBF_TEXT(TRACE, 3, "arprment");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002369
2370 /*
2371 * currently GuestLAN only supports the ARP assist function
2372 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_REMOVE_ENTRY;
2373 * thus we say EOPNOTSUPP for this ARP function
2374 */
2375 if (card->info.guestlan)
2376 return -EOPNOTSUPP;
2377 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002378 return -EOPNOTSUPP;
2379 }
2380 memcpy(buf, entry, 12);
2381 iob = qeth_l3_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
2382 IPA_CMD_ASS_ARP_REMOVE_ENTRY,
2383 12,
2384 QETH_PROT_IPV4);
2385 rc = qeth_l3_send_setassparms(card, iob,
2386 12, (unsigned long)buf,
2387 qeth_l3_default_setassparms_cb, NULL);
2388 if (rc) {
2389 tmp = rc;
2390 memset(buf, 0, 16);
2391 qeth_l3_ipaddr4_to_string((u8 *)entry->ipaddr, buf);
Frank Blaschka14cc21b2008-06-06 12:37:46 +02002392 QETH_DBF_MESSAGE(2, "Could not delete ARP entry for address %s"
2393 " on %s: %s (0x%x/%d)\n", buf, QETH_CARD_IFNAME(card),
2394 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002395 }
2396 return rc;
2397}
2398
2399static int qeth_l3_arp_flush_cache(struct qeth_card *card)
2400{
2401 int rc;
2402 int tmp;
2403
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002404 QETH_DBF_TEXT(TRACE, 3, "arpflush");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002405
2406 /*
2407 * currently GuestLAN only supports the ARP assist function
2408 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_FLUSH_CACHE;
2409 * thus we say EOPNOTSUPP for this ARP function
2410 */
2411 if (card->info.guestlan || (card->info.type == QETH_CARD_TYPE_IQD))
2412 return -EOPNOTSUPP;
2413 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002414 return -EOPNOTSUPP;
2415 }
2416 rc = qeth_l3_send_simple_setassparms(card, IPA_ARP_PROCESSING,
2417 IPA_CMD_ASS_ARP_FLUSH_CACHE, 0);
2418 if (rc) {
2419 tmp = rc;
Frank Blaschka14cc21b2008-06-06 12:37:46 +02002420 QETH_DBF_MESSAGE(2, "Could not flush ARP cache on %s: %s "
2421 "(0x%x/%d)\n", QETH_CARD_IFNAME(card),
Frank Blaschka4a71df52008-02-15 09:19:42 +01002422 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
2423 }
2424 return rc;
2425}
2426
2427static int qeth_l3_do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
2428{
Heiko Carstens509e2562008-07-26 02:24:10 -07002429 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002430 struct qeth_arp_cache_entry arp_entry;
2431 struct mii_ioctl_data *mii_data;
2432 int rc = 0;
2433
2434 if (!card)
2435 return -ENODEV;
2436
2437 if ((card->state != CARD_STATE_UP) &&
2438 (card->state != CARD_STATE_SOFTSETUP))
2439 return -ENODEV;
2440
2441 switch (cmd) {
2442 case SIOC_QETH_ARP_SET_NO_ENTRIES:
2443 if (!capable(CAP_NET_ADMIN)) {
2444 rc = -EPERM;
2445 break;
2446 }
2447 rc = qeth_l3_arp_set_no_entries(card, rq->ifr_ifru.ifru_ivalue);
2448 break;
2449 case SIOC_QETH_ARP_QUERY_INFO:
2450 if (!capable(CAP_NET_ADMIN)) {
2451 rc = -EPERM;
2452 break;
2453 }
2454 rc = qeth_l3_arp_query(card, rq->ifr_ifru.ifru_data);
2455 break;
2456 case SIOC_QETH_ARP_ADD_ENTRY:
2457 if (!capable(CAP_NET_ADMIN)) {
2458 rc = -EPERM;
2459 break;
2460 }
2461 if (copy_from_user(&arp_entry, rq->ifr_ifru.ifru_data,
2462 sizeof(struct qeth_arp_cache_entry)))
2463 rc = -EFAULT;
2464 else
2465 rc = qeth_l3_arp_add_entry(card, &arp_entry);
2466 break;
2467 case SIOC_QETH_ARP_REMOVE_ENTRY:
2468 if (!capable(CAP_NET_ADMIN)) {
2469 rc = -EPERM;
2470 break;
2471 }
2472 if (copy_from_user(&arp_entry, rq->ifr_ifru.ifru_data,
2473 sizeof(struct qeth_arp_cache_entry)))
2474 rc = -EFAULT;
2475 else
2476 rc = qeth_l3_arp_remove_entry(card, &arp_entry);
2477 break;
2478 case SIOC_QETH_ARP_FLUSH_CACHE:
2479 if (!capable(CAP_NET_ADMIN)) {
2480 rc = -EPERM;
2481 break;
2482 }
2483 rc = qeth_l3_arp_flush_cache(card);
2484 break;
2485 case SIOC_QETH_ADP_SET_SNMP_CONTROL:
2486 rc = qeth_snmp_command(card, rq->ifr_ifru.ifru_data);
2487 break;
2488 case SIOC_QETH_GET_CARD_TYPE:
2489 if ((card->info.type == QETH_CARD_TYPE_OSAE) &&
2490 !card->info.guestlan)
2491 return 1;
2492 return 0;
2493 break;
2494 case SIOCGMIIPHY:
2495 mii_data = if_mii(rq);
2496 mii_data->phy_id = 0;
2497 break;
2498 case SIOCGMIIREG:
2499 mii_data = if_mii(rq);
2500 if (mii_data->phy_id != 0)
2501 rc = -EINVAL;
2502 else
2503 mii_data->val_out = qeth_mdio_read(dev,
2504 mii_data->phy_id,
2505 mii_data->reg_num);
2506 break;
2507 default:
2508 rc = -EOPNOTSUPP;
2509 }
2510 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002511 QETH_DBF_TEXT_(TRACE, 2, "ioce%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002512 return rc;
2513}
2514
2515static void qeth_l3_fill_header(struct qeth_card *card, struct qeth_hdr *hdr,
2516 struct sk_buff *skb, int ipv, int cast_type)
2517{
Frank Blaschka4a71df52008-02-15 09:19:42 +01002518 memset(hdr, 0, sizeof(struct qeth_hdr));
2519 hdr->hdr.l3.id = QETH_HEADER_TYPE_LAYER3;
2520 hdr->hdr.l3.ext_flags = 0;
2521
2522 /*
2523 * before we're going to overwrite this location with next hop ip.
2524 * v6 uses passthrough, v4 sets the tag in the QDIO header.
2525 */
2526 if (card->vlangrp && vlan_tx_tag_present(skb)) {
Frank Blaschka213298f2008-04-24 10:15:22 +02002527 if ((ipv == 4) || (card->info.type == QETH_CARD_TYPE_IQD))
2528 hdr->hdr.l3.ext_flags = QETH_HDR_EXT_VLAN_FRAME;
2529 else
2530 hdr->hdr.l3.ext_flags = QETH_HDR_EXT_INCLUDE_VLAN_TAG;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002531 hdr->hdr.l3.vlan_id = vlan_tx_tag_get(skb);
2532 }
2533
2534 hdr->hdr.l3.length = skb->len - sizeof(struct qeth_hdr);
2535 if (ipv == 4) {
2536 /* IPv4 */
2537 hdr->hdr.l3.flags = qeth_l3_get_qeth_hdr_flags4(cast_type);
2538 memset(hdr->hdr.l3.dest_addr, 0, 12);
2539 if ((skb->dst) && (skb->dst->neighbour)) {
2540 *((u32 *) (&hdr->hdr.l3.dest_addr[12])) =
2541 *((u32 *) skb->dst->neighbour->primary_key);
2542 } else {
2543 /* fill in destination address used in ip header */
2544 *((u32 *) (&hdr->hdr.l3.dest_addr[12])) =
2545 ip_hdr(skb)->daddr;
2546 }
2547 } else if (ipv == 6) {
2548 /* IPv6 */
2549 hdr->hdr.l3.flags = qeth_l3_get_qeth_hdr_flags6(cast_type);
2550 if (card->info.type == QETH_CARD_TYPE_IQD)
2551 hdr->hdr.l3.flags &= ~QETH_HDR_PASSTHRU;
2552 if ((skb->dst) && (skb->dst->neighbour)) {
2553 memcpy(hdr->hdr.l3.dest_addr,
2554 skb->dst->neighbour->primary_key, 16);
2555 } else {
2556 /* fill in destination address used in ip header */
2557 memcpy(hdr->hdr.l3.dest_addr,
2558 &ipv6_hdr(skb)->daddr, 16);
2559 }
2560 } else {
2561 /* passthrough */
2562 if ((skb->dev->type == ARPHRD_IEEE802_TR) &&
2563 !memcmp(skb->data + sizeof(struct qeth_hdr) +
2564 sizeof(__u16), skb->dev->broadcast, 6)) {
2565 hdr->hdr.l3.flags = QETH_CAST_BROADCAST |
2566 QETH_HDR_PASSTHRU;
2567 } else if (!memcmp(skb->data + sizeof(struct qeth_hdr),
2568 skb->dev->broadcast, 6)) {
2569 /* broadcast? */
2570 hdr->hdr.l3.flags = QETH_CAST_BROADCAST |
2571 QETH_HDR_PASSTHRU;
2572 } else {
2573 hdr->hdr.l3.flags = (cast_type == RTN_MULTICAST) ?
2574 QETH_CAST_MULTICAST | QETH_HDR_PASSTHRU :
2575 QETH_CAST_UNICAST | QETH_HDR_PASSTHRU;
2576 }
2577 }
2578}
2579
2580static int qeth_l3_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
2581{
2582 int rc;
2583 u16 *tag;
2584 struct qeth_hdr *hdr = NULL;
2585 int elements_needed = 0;
Heiko Carstens509e2562008-07-26 02:24:10 -07002586 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002587 struct sk_buff *new_skb = NULL;
2588 int ipv = qeth_get_ip_version(skb);
2589 int cast_type = qeth_get_cast_type(card, skb);
2590 struct qeth_qdio_out_q *queue = card->qdio.out_qs
2591 [qeth_get_priority_queue(card, skb, ipv, cast_type)];
2592 int tx_bytes = skb->len;
2593 enum qeth_large_send_types large_send = QETH_LARGE_SEND_NO;
2594 struct qeth_eddp_context *ctx = NULL;
Frank Blaschka683d7182008-08-01 16:39:13 +02002595 int data_offset = -1;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002596
Frank Blaschka4a71df52008-02-15 09:19:42 +01002597 if ((card->info.type == QETH_CARD_TYPE_IQD) &&
2598 (skb->protocol != htons(ETH_P_IPV6)) &&
2599 (skb->protocol != htons(ETH_P_IP)))
2600 goto tx_drop;
2601
2602 if ((card->state != CARD_STATE_UP) || !card->lan_online) {
2603 card->stats.tx_carrier_errors++;
2604 goto tx_drop;
2605 }
2606
2607 if ((cast_type == RTN_BROADCAST) &&
2608 (card->info.broadcast_capable == 0))
2609 goto tx_drop;
2610
2611 if (card->options.performance_stats) {
2612 card->perf_stats.outbound_cnt++;
2613 card->perf_stats.outbound_start_time = qeth_get_micros();
2614 }
2615
Frank Blaschka683d7182008-08-01 16:39:13 +02002616 if (skb_is_gso(skb))
2617 large_send = card->options.large_send;
2618
2619 if ((card->info.type == QETH_CARD_TYPE_IQD) && (!large_send) &&
2620 (skb_shinfo(skb)->nr_frags == 0)) {
2621 new_skb = skb;
2622 data_offset = ETH_HLEN;
2623 hdr = kmem_cache_alloc(qeth_core_header_cache, GFP_ATOMIC);
2624 if (!hdr)
2625 goto tx_drop;
2626 elements_needed++;
2627 } else {
2628 /* create a clone with writeable headroom */
2629 new_skb = skb_realloc_headroom(skb, sizeof(struct qeth_hdr_tso)
2630 + VLAN_HLEN);
2631 if (!new_skb)
2632 goto tx_drop;
2633 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002634
2635 if (card->info.type == QETH_CARD_TYPE_IQD) {
Frank Blaschka683d7182008-08-01 16:39:13 +02002636 if (data_offset < 0)
2637 skb_pull(new_skb, ETH_HLEN);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002638 } else {
2639 if (new_skb->protocol == htons(ETH_P_IP)) {
2640 if (card->dev->type == ARPHRD_IEEE802_TR)
2641 skb_pull(new_skb, TR_HLEN);
2642 else
2643 skb_pull(new_skb, ETH_HLEN);
2644 }
2645
2646 if (new_skb->protocol == ETH_P_IPV6 && card->vlangrp &&
2647 vlan_tx_tag_present(new_skb)) {
2648 skb_push(new_skb, VLAN_HLEN);
2649 skb_copy_to_linear_data(new_skb, new_skb->data + 4, 4);
2650 skb_copy_to_linear_data_offset(new_skb, 4,
2651 new_skb->data + 8, 4);
2652 skb_copy_to_linear_data_offset(new_skb, 8,
2653 new_skb->data + 12, 4);
2654 tag = (u16 *)(new_skb->data + 12);
2655 *tag = __constant_htons(ETH_P_8021Q);
2656 *(tag + 1) = htons(vlan_tx_tag_get(new_skb));
frank.blaschka@de.ibm.com2b4ff112008-07-22 09:39:25 +02002657 new_skb->vlan_tci = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002658 }
2659 }
2660
2661 netif_stop_queue(dev);
2662
Frank Blaschka4a71df52008-02-15 09:19:42 +01002663 /* fix hardware limitation: as long as we do not have sbal
2664 * chaining we can not send long frag lists so we temporary
2665 * switch to EDDP
2666 */
2667 if ((large_send == QETH_LARGE_SEND_TSO) &&
2668 ((skb_shinfo(new_skb)->nr_frags + 2) > 16))
2669 large_send = QETH_LARGE_SEND_EDDP;
2670
2671 if ((large_send == QETH_LARGE_SEND_TSO) &&
2672 (cast_type == RTN_UNSPEC)) {
2673 hdr = (struct qeth_hdr *)skb_push(new_skb,
2674 sizeof(struct qeth_hdr_tso));
2675 memset(hdr, 0, sizeof(struct qeth_hdr_tso));
2676 qeth_l3_fill_header(card, hdr, new_skb, ipv, cast_type);
2677 qeth_tso_fill_header(card, hdr, new_skb);
2678 elements_needed++;
2679 } else {
Frank Blaschka683d7182008-08-01 16:39:13 +02002680 if (data_offset < 0) {
2681 hdr = (struct qeth_hdr *)skb_push(new_skb,
Frank Blaschka4a71df52008-02-15 09:19:42 +01002682 sizeof(struct qeth_hdr));
Frank Blaschka683d7182008-08-01 16:39:13 +02002683 qeth_l3_fill_header(card, hdr, new_skb, ipv,
2684 cast_type);
2685 } else {
2686 qeth_l3_fill_header(card, hdr, new_skb, ipv,
2687 cast_type);
2688 hdr->hdr.l3.length = new_skb->len - data_offset;
2689 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002690 }
2691
2692 if (large_send == QETH_LARGE_SEND_EDDP) {
2693 /* new_skb is not owned by a socket so we use skb to get
2694 * the protocol
2695 */
2696 ctx = qeth_eddp_create_context(card, new_skb, hdr,
2697 skb->sk->sk_protocol);
2698 if (ctx == NULL) {
Frank Blaschka14cc21b2008-06-06 12:37:46 +02002699 QETH_DBF_MESSAGE(2, "could not create eddp context\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002700 goto tx_drop;
2701 }
2702 } else {
2703 int elems = qeth_get_elements_no(card, (void *)hdr, new_skb,
2704 elements_needed);
Frank Blaschka683d7182008-08-01 16:39:13 +02002705 if (!elems) {
2706 if (data_offset >= 0)
2707 kmem_cache_free(qeth_core_header_cache, hdr);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002708 goto tx_drop;
Frank Blaschka683d7182008-08-01 16:39:13 +02002709 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002710 elements_needed += elems;
2711 }
2712
2713 if ((large_send == QETH_LARGE_SEND_NO) &&
2714 (new_skb->ip_summed == CHECKSUM_PARTIAL))
2715 qeth_tx_csum(new_skb);
2716
2717 if (card->info.type != QETH_CARD_TYPE_IQD)
2718 rc = qeth_do_send_packet(card, queue, new_skb, hdr,
2719 elements_needed, ctx);
2720 else
2721 rc = qeth_do_send_packet_fast(card, queue, new_skb, hdr,
Frank Blaschka683d7182008-08-01 16:39:13 +02002722 elements_needed, ctx, data_offset, 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002723
2724 if (!rc) {
2725 card->stats.tx_packets++;
2726 card->stats.tx_bytes += tx_bytes;
2727 if (new_skb != skb)
2728 dev_kfree_skb_any(skb);
2729 if (card->options.performance_stats) {
2730 if (large_send != QETH_LARGE_SEND_NO) {
2731 card->perf_stats.large_send_bytes += tx_bytes;
2732 card->perf_stats.large_send_cnt++;
2733 }
2734 if (skb_shinfo(new_skb)->nr_frags > 0) {
2735 card->perf_stats.sg_skbs_sent++;
2736 /* nr_frags + skb->data */
2737 card->perf_stats.sg_frags_sent +=
2738 skb_shinfo(new_skb)->nr_frags + 1;
2739 }
2740 }
2741
2742 if (ctx != NULL) {
2743 qeth_eddp_put_context(ctx);
2744 dev_kfree_skb_any(new_skb);
2745 }
2746 } else {
2747 if (ctx != NULL)
2748 qeth_eddp_put_context(ctx);
2749
Frank Blaschka683d7182008-08-01 16:39:13 +02002750 if (data_offset >= 0)
2751 kmem_cache_free(qeth_core_header_cache, hdr);
2752
Frank Blaschka4a71df52008-02-15 09:19:42 +01002753 if (rc == -EBUSY) {
2754 if (new_skb != skb)
2755 dev_kfree_skb_any(new_skb);
2756 return NETDEV_TX_BUSY;
2757 } else
2758 goto tx_drop;
2759 }
2760
2761 netif_wake_queue(dev);
2762 if (card->options.performance_stats)
2763 card->perf_stats.outbound_time += qeth_get_micros() -
2764 card->perf_stats.outbound_start_time;
2765 return rc;
2766
2767tx_drop:
2768 card->stats.tx_dropped++;
2769 card->stats.tx_errors++;
2770 if ((new_skb != skb) && new_skb)
2771 dev_kfree_skb_any(new_skb);
2772 dev_kfree_skb_any(skb);
Frank Blaschkad0ec0f52008-06-06 12:37:48 +02002773 netif_wake_queue(dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002774 return NETDEV_TX_OK;
2775}
2776
2777static int qeth_l3_open(struct net_device *dev)
2778{
Heiko Carstens509e2562008-07-26 02:24:10 -07002779 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002780
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002781 QETH_DBF_TEXT(TRACE, 4, "qethopen");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002782 if (card->state != CARD_STATE_SOFTSETUP)
2783 return -ENODEV;
2784 card->data.state = CH_STATE_UP;
2785 card->state = CARD_STATE_UP;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002786 netif_start_queue(dev);
2787
2788 if (!card->lan_online && netif_carrier_ok(dev))
2789 netif_carrier_off(dev);
2790 return 0;
2791}
2792
2793static int qeth_l3_stop(struct net_device *dev)
2794{
Heiko Carstens509e2562008-07-26 02:24:10 -07002795 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002796
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002797 QETH_DBF_TEXT(TRACE, 4, "qethstop");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002798 netif_tx_disable(dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002799 if (card->state == CARD_STATE_UP)
2800 card->state = CARD_STATE_SOFTSETUP;
2801 return 0;
2802}
2803
2804static u32 qeth_l3_ethtool_get_rx_csum(struct net_device *dev)
2805{
Heiko Carstens509e2562008-07-26 02:24:10 -07002806 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002807
2808 return (card->options.checksum_type == HW_CHECKSUMMING);
2809}
2810
2811static int qeth_l3_ethtool_set_rx_csum(struct net_device *dev, u32 data)
2812{
Heiko Carstens509e2562008-07-26 02:24:10 -07002813 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002814 enum qeth_card_states old_state;
2815 enum qeth_checksum_types csum_type;
2816
2817 if ((card->state != CARD_STATE_UP) &&
2818 (card->state != CARD_STATE_DOWN))
2819 return -EPERM;
2820
2821 if (data)
2822 csum_type = HW_CHECKSUMMING;
2823 else
2824 csum_type = SW_CHECKSUMMING;
2825
2826 if (card->options.checksum_type != csum_type) {
2827 old_state = card->state;
2828 if (card->state == CARD_STATE_UP)
2829 __qeth_l3_set_offline(card->gdev, 1);
2830 card->options.checksum_type = csum_type;
2831 if (old_state == CARD_STATE_UP)
2832 __qeth_l3_set_online(card->gdev, 1);
2833 }
2834 return 0;
2835}
2836
2837static int qeth_l3_ethtool_set_tso(struct net_device *dev, u32 data)
2838{
Heiko Carstens509e2562008-07-26 02:24:10 -07002839 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002840
2841 if (data) {
2842 if (card->options.large_send == QETH_LARGE_SEND_NO) {
2843 if (card->info.type == QETH_CARD_TYPE_IQD)
2844 card->options.large_send = QETH_LARGE_SEND_EDDP;
2845 else
2846 card->options.large_send = QETH_LARGE_SEND_TSO;
2847 dev->features |= NETIF_F_TSO;
2848 }
2849 } else {
2850 dev->features &= ~NETIF_F_TSO;
2851 card->options.large_send = QETH_LARGE_SEND_NO;
2852 }
2853 return 0;
2854}
2855
2856static struct ethtool_ops qeth_l3_ethtool_ops = {
2857 .get_link = ethtool_op_get_link,
2858 .get_tx_csum = ethtool_op_get_tx_csum,
2859 .set_tx_csum = ethtool_op_set_tx_hw_csum,
2860 .get_rx_csum = qeth_l3_ethtool_get_rx_csum,
2861 .set_rx_csum = qeth_l3_ethtool_set_rx_csum,
2862 .get_sg = ethtool_op_get_sg,
2863 .set_sg = ethtool_op_set_sg,
2864 .get_tso = ethtool_op_get_tso,
2865 .set_tso = qeth_l3_ethtool_set_tso,
2866 .get_strings = qeth_core_get_strings,
2867 .get_ethtool_stats = qeth_core_get_ethtool_stats,
2868 .get_stats_count = qeth_core_get_stats_count,
2869 .get_drvinfo = qeth_core_get_drvinfo,
Frank Blaschka3f9975a2008-04-24 10:15:23 +02002870 .get_settings = qeth_core_ethtool_get_settings,
Frank Blaschka4a71df52008-02-15 09:19:42 +01002871};
2872
2873/*
2874 * we need NOARP for IPv4 but we want neighbor solicitation for IPv6. Setting
2875 * NOARP on the netdevice is no option because it also turns off neighbor
2876 * solicitation. For IPv4 we install a neighbor_setup function. We don't want
2877 * arp resolution but we want the hard header (packet socket will work
2878 * e.g. tcpdump)
2879 */
2880static int qeth_l3_neigh_setup_noarp(struct neighbour *n)
2881{
2882 n->nud_state = NUD_NOARP;
2883 memcpy(n->ha, "FAKELL", 6);
2884 n->output = n->ops->connected_output;
2885 return 0;
2886}
2887
2888static int
2889qeth_l3_neigh_setup(struct net_device *dev, struct neigh_parms *np)
2890{
2891 if (np->tbl->family == AF_INET)
2892 np->neigh_setup = qeth_l3_neigh_setup_noarp;
2893
2894 return 0;
2895}
2896
Frank Blaschka3d58cef2009-01-09 03:44:00 +00002897static const struct net_device_ops qeth_l3_netdev_ops = {
Frank Blaschka8403b132009-01-08 10:50:55 -08002898 .ndo_open = qeth_l3_open,
2899 .ndo_stop = qeth_l3_stop,
2900 .ndo_get_stats = qeth_get_stats,
2901 .ndo_start_xmit = qeth_l3_hard_start_xmit,
2902 .ndo_validate_addr = eth_validate_addr,
2903 .ndo_set_multicast_list = qeth_l3_set_multicast_list,
2904 .ndo_do_ioctl = qeth_l3_do_ioctl,
2905 .ndo_change_mtu = qeth_change_mtu,
2906 .ndo_vlan_rx_register = qeth_l3_vlan_rx_register,
2907 .ndo_vlan_rx_add_vid = qeth_l3_vlan_rx_add_vid,
2908 .ndo_vlan_rx_kill_vid = qeth_l3_vlan_rx_kill_vid,
2909 .ndo_tx_timeout = qeth_tx_timeout,
2910};
2911
Frank Blaschka3d58cef2009-01-09 03:44:00 +00002912static const struct net_device_ops qeth_l3_osa_netdev_ops = {
2913 .ndo_open = qeth_l3_open,
2914 .ndo_stop = qeth_l3_stop,
2915 .ndo_get_stats = qeth_get_stats,
2916 .ndo_start_xmit = qeth_l3_hard_start_xmit,
2917 .ndo_validate_addr = eth_validate_addr,
2918 .ndo_set_multicast_list = qeth_l3_set_multicast_list,
2919 .ndo_do_ioctl = qeth_l3_do_ioctl,
2920 .ndo_change_mtu = qeth_change_mtu,
2921 .ndo_vlan_rx_register = qeth_l3_vlan_rx_register,
2922 .ndo_vlan_rx_add_vid = qeth_l3_vlan_rx_add_vid,
2923 .ndo_vlan_rx_kill_vid = qeth_l3_vlan_rx_kill_vid,
2924 .ndo_tx_timeout = qeth_tx_timeout,
2925 .ndo_neigh_setup = qeth_l3_neigh_setup,
2926};
2927
Frank Blaschka4a71df52008-02-15 09:19:42 +01002928static int qeth_l3_setup_netdev(struct qeth_card *card)
2929{
2930 if (card->info.type == QETH_CARD_TYPE_OSAE) {
2931 if ((card->info.link_type == QETH_LINK_TYPE_LANE_TR) ||
2932 (card->info.link_type == QETH_LINK_TYPE_HSTR)) {
2933#ifdef CONFIG_TR
2934 card->dev = alloc_trdev(0);
2935#endif
2936 if (!card->dev)
2937 return -ENODEV;
Frank Blaschka3d58cef2009-01-09 03:44:00 +00002938 card->dev->netdev_ops = &qeth_l3_netdev_ops;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002939 } else {
2940 card->dev = alloc_etherdev(0);
2941 if (!card->dev)
2942 return -ENODEV;
Frank Blaschka3d58cef2009-01-09 03:44:00 +00002943 card->dev->netdev_ops = &qeth_l3_osa_netdev_ops;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002944
2945 /*IPv6 address autoconfiguration stuff*/
2946 qeth_l3_get_unique_id(card);
2947 if (!(card->info.unique_id & UNIQUE_ID_NOT_BY_CARD))
2948 card->dev->dev_id = card->info.unique_id &
2949 0xffff;
2950 }
2951 } else if (card->info.type == QETH_CARD_TYPE_IQD) {
2952 card->dev = alloc_netdev(0, "hsi%d", ether_setup);
2953 if (!card->dev)
2954 return -ENODEV;
2955 card->dev->flags |= IFF_NOARP;
Frank Blaschka3d58cef2009-01-09 03:44:00 +00002956 card->dev->netdev_ops = &qeth_l3_netdev_ops;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002957 qeth_l3_iqd_read_initial_mac(card);
2958 } else
2959 return -ENODEV;
2960
Heiko Carstens509e2562008-07-26 02:24:10 -07002961 card->dev->ml_priv = card;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002962 card->dev->watchdog_timeo = QETH_TX_TIMEOUT;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002963 card->dev->mtu = card->info.initial_mtu;
2964 SET_ETHTOOL_OPS(card->dev, &qeth_l3_ethtool_ops);
2965 card->dev->features |= NETIF_F_HW_VLAN_TX |
2966 NETIF_F_HW_VLAN_RX |
2967 NETIF_F_HW_VLAN_FILTER;
2968
2969 SET_NETDEV_DEV(card->dev, &card->gdev->dev);
2970 return register_netdev(card->dev);
2971}
2972
2973static void qeth_l3_qdio_input_handler(struct ccw_device *ccwdev,
Jan Glauber779e6e12008-07-17 17:16:48 +02002974 unsigned int qdio_err, unsigned int queue, int first_element,
Frank Blaschka4a71df52008-02-15 09:19:42 +01002975 int count, unsigned long card_ptr)
2976{
2977 struct net_device *net_dev;
2978 struct qeth_card *card;
2979 struct qeth_qdio_buffer *buffer;
2980 int index;
2981 int i;
2982
Frank Blaschka4a71df52008-02-15 09:19:42 +01002983 card = (struct qeth_card *) card_ptr;
2984 net_dev = card->dev;
2985 if (card->options.performance_stats) {
2986 card->perf_stats.inbound_cnt++;
2987 card->perf_stats.inbound_start_time = qeth_get_micros();
2988 }
Jan Glauber779e6e12008-07-17 17:16:48 +02002989 if (qdio_err & QDIO_ERROR_ACTIVATE_CHECK_CONDITION) {
2990 QETH_DBF_TEXT(TRACE, 1, "qdinchk");
2991 QETH_DBF_TEXT_(TRACE, 1, "%s", CARD_BUS_ID(card));
2992 QETH_DBF_TEXT_(TRACE, 1, "%04X%04X",
2993 first_element, count);
2994 QETH_DBF_TEXT_(TRACE, 1, "%04X", queue);
2995 qeth_schedule_recovery(card);
2996 return;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002997 }
2998 for (i = first_element; i < (first_element + count); ++i) {
2999 index = i % QDIO_MAX_BUFFERS_PER_Q;
3000 buffer = &card->qdio.in_q->bufs[index];
Jan Glauber779e6e12008-07-17 17:16:48 +02003001 if (!(qdio_err &&
Frank Blaschka4a71df52008-02-15 09:19:42 +01003002 qeth_check_qdio_errors(buffer->buffer,
Jan Glauber779e6e12008-07-17 17:16:48 +02003003 qdio_err, "qinerr")))
Frank Blaschka4a71df52008-02-15 09:19:42 +01003004 qeth_l3_process_inbound_buffer(card, buffer, index);
3005 /* clear buffer and give back to hardware */
3006 qeth_put_buffer_pool_entry(card, buffer->pool_entry);
3007 qeth_queue_input_buffer(card, index);
3008 }
3009 if (card->options.performance_stats)
3010 card->perf_stats.inbound_time += qeth_get_micros() -
3011 card->perf_stats.inbound_start_time;
3012}
3013
3014static int qeth_l3_probe_device(struct ccwgroup_device *gdev)
3015{
3016 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3017
3018 qeth_l3_create_device_attributes(&gdev->dev);
3019 card->options.layer2 = 0;
3020 card->discipline.input_handler = (qdio_handler_t *)
3021 qeth_l3_qdio_input_handler;
3022 card->discipline.output_handler = (qdio_handler_t *)
3023 qeth_qdio_output_handler;
3024 card->discipline.recover = qeth_l3_recover;
3025 return 0;
3026}
3027
3028static void qeth_l3_remove_device(struct ccwgroup_device *cgdev)
3029{
3030 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
3031
3032 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
3033
3034 if (cgdev->state == CCWGROUP_ONLINE) {
3035 card->use_hard_stop = 1;
3036 qeth_l3_set_offline(cgdev);
3037 }
3038
3039 if (card->dev) {
3040 unregister_netdev(card->dev);
3041 card->dev = NULL;
3042 }
3043
3044 qeth_l3_remove_device_attributes(&cgdev->dev);
3045 qeth_l3_clear_ip_list(card, 0, 0);
3046 qeth_l3_clear_ipato_list(card);
3047 return;
3048}
3049
3050static int __qeth_l3_set_online(struct ccwgroup_device *gdev, int recovery_mode)
3051{
3052 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3053 int rc = 0;
3054 enum qeth_card_states recover_flag;
3055
3056 BUG_ON(!card);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003057 QETH_DBF_TEXT(SETUP, 2, "setonlin");
3058 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003059
3060 qeth_set_allowed_threads(card, QETH_RECOVER_THREAD, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003061
3062 recover_flag = card->state;
3063 rc = ccw_device_set_online(CARD_RDEV(card));
3064 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003065 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003066 return -EIO;
3067 }
3068 rc = ccw_device_set_online(CARD_WDEV(card));
3069 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003070 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003071 return -EIO;
3072 }
3073 rc = ccw_device_set_online(CARD_DDEV(card));
3074 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003075 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003076 return -EIO;
3077 }
3078
3079 rc = qeth_core_hardsetup_card(card);
3080 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003081 QETH_DBF_TEXT_(SETUP, 2, "2err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003082 goto out_remove;
3083 }
3084
3085 qeth_l3_query_ipassists(card, QETH_PROT_IPV4);
3086
3087 if (!card->dev && qeth_l3_setup_netdev(card))
3088 goto out_remove;
3089
3090 card->state = CARD_STATE_HARDSETUP;
3091 qeth_print_status_message(card);
3092
3093 /* softsetup */
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003094 QETH_DBF_TEXT(SETUP, 2, "softsetp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003095
3096 rc = qeth_send_startlan(card);
3097 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003098 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003099 if (rc == 0xe080) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003100 dev_warn(&card->gdev->dev,
3101 "The LAN is offline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003102 card->lan_online = 0;
3103 }
3104 return rc;
3105 } else
3106 card->lan_online = 1;
3107 qeth_set_large_send(card, card->options.large_send);
3108
3109 rc = qeth_l3_setadapter_parms(card);
3110 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003111 QETH_DBF_TEXT_(SETUP, 2, "2err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003112 rc = qeth_l3_start_ipassists(card);
3113 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003114 QETH_DBF_TEXT_(SETUP, 2, "3err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003115 rc = qeth_l3_setrouting_v4(card);
3116 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003117 QETH_DBF_TEXT_(SETUP, 2, "4err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003118 rc = qeth_l3_setrouting_v6(card);
3119 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003120 QETH_DBF_TEXT_(SETUP, 2, "5err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003121 netif_tx_disable(card->dev);
3122
3123 rc = qeth_init_qdio_queues(card);
3124 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003125 QETH_DBF_TEXT_(SETUP, 2, "6err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003126 goto out_remove;
3127 }
3128 card->state = CARD_STATE_SOFTSETUP;
3129 netif_carrier_on(card->dev);
3130
3131 qeth_set_allowed_threads(card, 0xffffffff, 0);
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02003132 if (recover_flag == CARD_STATE_RECOVER) {
3133 if (recovery_mode)
Frank Blaschka4a71df52008-02-15 09:19:42 +01003134 qeth_l3_open(card->dev);
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02003135 else {
3136 rtnl_lock();
3137 dev_open(card->dev);
3138 rtnl_unlock();
3139 }
3140 qeth_l3_set_multicast_list(card->dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003141 }
3142 /* let user_space know that device is online */
3143 kobject_uevent(&gdev->dev.kobj, KOBJ_CHANGE);
3144 return 0;
3145out_remove:
3146 card->use_hard_stop = 1;
3147 qeth_l3_stop_card(card, 0);
3148 ccw_device_set_offline(CARD_DDEV(card));
3149 ccw_device_set_offline(CARD_WDEV(card));
3150 ccw_device_set_offline(CARD_RDEV(card));
3151 if (recover_flag == CARD_STATE_RECOVER)
3152 card->state = CARD_STATE_RECOVER;
3153 else
3154 card->state = CARD_STATE_DOWN;
3155 return -ENODEV;
3156}
3157
3158static int qeth_l3_set_online(struct ccwgroup_device *gdev)
3159{
3160 return __qeth_l3_set_online(gdev, 0);
3161}
3162
3163static int __qeth_l3_set_offline(struct ccwgroup_device *cgdev,
3164 int recovery_mode)
3165{
3166 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
3167 int rc = 0, rc2 = 0, rc3 = 0;
3168 enum qeth_card_states recover_flag;
3169
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003170 QETH_DBF_TEXT(SETUP, 3, "setoffl");
3171 QETH_DBF_HEX(SETUP, 3, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003172
3173 if (card->dev && netif_carrier_ok(card->dev))
3174 netif_carrier_off(card->dev);
3175 recover_flag = card->state;
Ursula Braun0f5623c2008-10-24 11:16:52 +02003176 qeth_l3_stop_card(card, recovery_mode);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003177 rc = ccw_device_set_offline(CARD_DDEV(card));
3178 rc2 = ccw_device_set_offline(CARD_WDEV(card));
3179 rc3 = ccw_device_set_offline(CARD_RDEV(card));
3180 if (!rc)
3181 rc = (rc2) ? rc2 : rc3;
3182 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003183 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003184 if (recover_flag == CARD_STATE_UP)
3185 card->state = CARD_STATE_RECOVER;
3186 /* let user_space know that device is offline */
3187 kobject_uevent(&cgdev->dev.kobj, KOBJ_CHANGE);
3188 return 0;
3189}
3190
3191static int qeth_l3_set_offline(struct ccwgroup_device *cgdev)
3192{
3193 return __qeth_l3_set_offline(cgdev, 0);
3194}
3195
3196static int qeth_l3_recover(void *ptr)
3197{
3198 struct qeth_card *card;
3199 int rc = 0;
3200
3201 card = (struct qeth_card *) ptr;
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003202 QETH_DBF_TEXT(TRACE, 2, "recover1");
3203 QETH_DBF_HEX(TRACE, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003204 if (!qeth_do_run_thread(card, QETH_RECOVER_THREAD))
3205 return 0;
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003206 QETH_DBF_TEXT(TRACE, 2, "recover2");
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003207 dev_warn(&card->gdev->dev,
3208 "A recovery process has been started for the device\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003209 card->use_hard_stop = 1;
3210 __qeth_l3_set_offline(card->gdev, 1);
3211 rc = __qeth_l3_set_online(card->gdev, 1);
3212 /* don't run another scheduled recovery */
3213 qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD);
3214 qeth_clear_thread_running_bit(card, QETH_RECOVER_THREAD);
3215 if (!rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003216 dev_info(&card->gdev->dev,
3217 "Device successfully recovered!\n");
Ursula Braun28a7e4c2008-09-19 12:56:03 +02003218 else {
3219 rtnl_lock();
3220 dev_close(card->dev);
3221 rtnl_unlock();
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003222 dev_warn(&card->gdev->dev, "The qeth device driver "
3223 "failed to recover an error on the device\n");
Ursula Braun28a7e4c2008-09-19 12:56:03 +02003224 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01003225 return 0;
3226}
3227
3228static void qeth_l3_shutdown(struct ccwgroup_device *gdev)
3229{
3230 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3231 qeth_l3_clear_ip_list(card, 0, 0);
3232 qeth_qdio_clear_card(card, 0);
3233 qeth_clear_qdio_buffers(card);
3234}
3235
3236struct ccwgroup_driver qeth_l3_ccwgroup_driver = {
3237 .probe = qeth_l3_probe_device,
3238 .remove = qeth_l3_remove_device,
3239 .set_online = qeth_l3_set_online,
3240 .set_offline = qeth_l3_set_offline,
3241 .shutdown = qeth_l3_shutdown,
3242};
3243EXPORT_SYMBOL_GPL(qeth_l3_ccwgroup_driver);
3244
3245static int qeth_l3_ip_event(struct notifier_block *this,
David S. Miller76fef2b2008-03-22 18:22:42 -07003246 unsigned long event, void *ptr)
Frank Blaschka4a71df52008-02-15 09:19:42 +01003247{
3248 struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;
3249 struct net_device *dev = (struct net_device *)ifa->ifa_dev->dev;
3250 struct qeth_ipaddr *addr;
3251 struct qeth_card *card;
3252
YOSHIFUJI Hideakic346dca2008-03-25 21:47:49 +09003253 if (dev_net(dev) != &init_net)
David S. Miller76fef2b2008-03-22 18:22:42 -07003254 return NOTIFY_DONE;
3255
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003256 QETH_DBF_TEXT(TRACE, 3, "ipevent");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003257 card = qeth_l3_get_card_from_dev(dev);
3258 if (!card)
3259 return NOTIFY_DONE;
3260
3261 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
3262 if (addr != NULL) {
3263 addr->u.a4.addr = ifa->ifa_address;
3264 addr->u.a4.mask = ifa->ifa_mask;
3265 addr->type = QETH_IP_TYPE_NORMAL;
3266 } else
3267 goto out;
3268
3269 switch (event) {
3270 case NETDEV_UP:
3271 if (!qeth_l3_add_ip(card, addr))
3272 kfree(addr);
3273 break;
3274 case NETDEV_DOWN:
3275 if (!qeth_l3_delete_ip(card, addr))
3276 kfree(addr);
3277 break;
3278 default:
3279 break;
3280 }
3281 qeth_l3_set_ip_addr_list(card);
3282out:
3283 return NOTIFY_DONE;
3284}
3285
3286static struct notifier_block qeth_l3_ip_notifier = {
3287 qeth_l3_ip_event,
3288 NULL,
3289};
3290
3291#ifdef CONFIG_QETH_IPV6
3292/**
3293 * IPv6 event handler
3294 */
3295static int qeth_l3_ip6_event(struct notifier_block *this,
David S. Miller76fef2b2008-03-22 18:22:42 -07003296 unsigned long event, void *ptr)
Frank Blaschka4a71df52008-02-15 09:19:42 +01003297{
3298 struct inet6_ifaddr *ifa = (struct inet6_ifaddr *)ptr;
3299 struct net_device *dev = (struct net_device *)ifa->idev->dev;
3300 struct qeth_ipaddr *addr;
3301 struct qeth_card *card;
3302
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003303 QETH_DBF_TEXT(TRACE, 3, "ip6event");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003304
3305 card = qeth_l3_get_card_from_dev(dev);
3306 if (!card)
3307 return NOTIFY_DONE;
3308 if (!qeth_is_supported(card, IPA_IPV6))
3309 return NOTIFY_DONE;
3310
3311 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
3312 if (addr != NULL) {
3313 memcpy(&addr->u.a6.addr, &ifa->addr, sizeof(struct in6_addr));
3314 addr->u.a6.pfxlen = ifa->prefix_len;
3315 addr->type = QETH_IP_TYPE_NORMAL;
3316 } else
3317 goto out;
3318
3319 switch (event) {
3320 case NETDEV_UP:
3321 if (!qeth_l3_add_ip(card, addr))
3322 kfree(addr);
3323 break;
3324 case NETDEV_DOWN:
3325 if (!qeth_l3_delete_ip(card, addr))
3326 kfree(addr);
3327 break;
3328 default:
3329 break;
3330 }
3331 qeth_l3_set_ip_addr_list(card);
3332out:
3333 return NOTIFY_DONE;
3334}
3335
3336static struct notifier_block qeth_l3_ip6_notifier = {
3337 qeth_l3_ip6_event,
3338 NULL,
3339};
3340#endif
3341
3342static int qeth_l3_register_notifiers(void)
3343{
3344 int rc;
3345
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003346 QETH_DBF_TEXT(TRACE, 5, "regnotif");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003347 rc = register_inetaddr_notifier(&qeth_l3_ip_notifier);
3348 if (rc)
3349 return rc;
3350#ifdef CONFIG_QETH_IPV6
3351 rc = register_inet6addr_notifier(&qeth_l3_ip6_notifier);
3352 if (rc) {
3353 unregister_inetaddr_notifier(&qeth_l3_ip_notifier);
3354 return rc;
3355 }
3356#else
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003357 pr_warning("There is no IPv6 support for the layer 3 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003358#endif
3359 return 0;
3360}
3361
3362static void qeth_l3_unregister_notifiers(void)
3363{
3364
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003365 QETH_DBF_TEXT(TRACE, 5, "unregnot");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003366 BUG_ON(unregister_inetaddr_notifier(&qeth_l3_ip_notifier));
3367#ifdef CONFIG_QETH_IPV6
3368 BUG_ON(unregister_inet6addr_notifier(&qeth_l3_ip6_notifier));
3369#endif /* QETH_IPV6 */
3370}
3371
3372static int __init qeth_l3_init(void)
3373{
3374 int rc = 0;
3375
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003376 pr_info("register layer 3 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003377 rc = qeth_l3_register_notifiers();
3378 return rc;
3379}
3380
3381static void __exit qeth_l3_exit(void)
3382{
3383 qeth_l3_unregister_notifiers();
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003384 pr_info("unregister layer 3 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003385}
3386
3387module_init(qeth_l3_init);
3388module_exit(qeth_l3_exit);
3389MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
3390MODULE_DESCRIPTION("qeth layer 3 discipline");
3391MODULE_LICENSE("GPL");